hc
2024-08-19 a51341d8c7882adfad4f167bc7c3ca616908b53d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * core.h -- core define for mfd display arch
 *
 * Copyright (c) 2023-2028 Rockchip Electronics Co. Ltd.
 *
 * Author: luowei <lw@rock-chips.com>
 *
 */
#include <common.h>
#include <dm.h>
#include <i2c.h>
#include <errno.h>
#include <drm/drm_mipi_dsi.h>
#include <video_bridge.h>
#include <asm/unaligned.h>
#include <linux/media-bus-format.h>
#include <linux/bitfield.h>
#include <linux/iopoll.h>
#include <power/regulator.h>
#include <config.h>
#include <backlight.h>
#include <malloc.h>
#include <video.h>
 
#include <asm/gpio.h>
#include <dm/device.h>
#include <dm/read.h>
#include <dm/pinctrl.h>
#include <dm/uclass-id.h>
#include <dm/lists.h>
 
#include <dm/device-internal.h>
#include <dm/root.h>
#include <fdtdec.h>
#include <regmap.h>
#include <asm/gpio.h>
#include <asm/system.h>
#include <asm/io.h>
 
#include <serdes-display-gpio.h>
 
#include "../drivers/video/drm/rockchip_bridge.h"
#include "../drivers/video/drm/rockchip_display.h"
#include "../drivers/video/drm/rockchip_panel.h"
 
#ifndef __SERDES_DISPLAY_CORE_H__
#define __SERDES_DISPLAY_CORE_H__
 
//#define SERDES_DEBUG_MFD
//#define SERDES_DEBUG_I2C
//#define SERDES_DEBUG_CHIP
 
#ifdef SERDES_DEBUG_MFD
#define  SERDES_DBG_MFD(x...) printf(x)
#else
#define  SERDES_DBG_MFD(x...)
#endif
 
#ifdef SERDES_DEBUG_I2C
#define  SERDES_DBG_I2C(x...) printf(x)
#else
#define  SERDES_DBG_I2C(x...)
#endif
 
#ifdef SERDES_DEBUG_CHIP
#define  SERDES_DBG_CHIP(x...) printf(x)
#else
#define  SERDES_DBG_CHIP(x...)
#endif
 
#define SERDES_UBOOT_DISPLAY_VERSION "serdes-uboot-displaly-v10-230920"
 
struct serdes;
 
/* Convenience macro to define a single named or anonymous pin descriptor */
#define PINCTRL_PIN(a, b) { .number = a, .name = b }
 
/**
 * struct pinctrl_pin_desc - boards/machines provide information on their
 * pins, pads or other muxable units in this struct
 * @number: unique pin number from the global pin number space
 * @name: a name for this pin
 * @drv_data: driver-defined per-pin data. pinctrl core does not touch this
 */
struct pinctrl_pin_desc {
   unsigned int number;
   const char *name;
   void *drv_data;
};
 
/**
 * struct group_desc - generic pin group descriptor
 * @name: name of the pin group
 * @pins: array of pins that belong to the group
 * @num_pins: number of pins in the group
 * @data: pin controller driver specific data
 */
struct group_desc {
   const char *name;
   int *pins;
   int num_pins;
   void *data;
};
 
/**
 * struct function_desc - generic function descriptor
 * @name: name of the function
 * @group_names: array of pin group names
 * @num_group_names: number of pin group names
 * @data: pin controller driver specific data
 */
struct function_desc {
   const char *name;
   const char **group_names;
   int num_group_names;
   void *data;
};
 
struct serdes_chip_pinctrl_info {
   struct pinctrl_pin_desc *pins;
   unsigned int num_pins;
   struct group_desc *groups;
   unsigned int num_groups;
   struct function_desc *functions;
   unsigned int num_functions;
};
 
struct serdes_chip_bridge_ops {
   /*serdes chip function for bridge*/
   int (*power_on)(struct serdes *serdes);
   int (*init)(struct serdes *serdes);
   int (*attach)(struct serdes *serdes);
   bool (*detect)(struct serdes *serdes);
   int (*get_modes)(struct serdes *serdes);
   int (*pre_enable)(struct serdes *serdes);
   int (*enable)(struct serdes *serdes);
   int (*disable)(struct serdes *serdes);
   int (*post_disable)(struct serdes *serdes);
};
 
struct serdes_chip_panel_ops {
   /*serdes chip function for bridge*/
   int (*power_on)(struct serdes *serdes);
   int (*init)(struct serdes *serdes);
   int (*disable)(struct serdes *serdes);
   int (*unprepare)(struct serdes *serdes);
   int (*prepare)(struct serdes *serdes);
   int (*enable)(struct serdes *serdes);
   int (*get_modes)(struct serdes *serdes);
   int (*mode_set)(struct serdes *serdes);
   int (*backlight_enable)(struct serdes *serdes);
   int (*backlight_disable)(struct serdes *serdes);
};
 
struct serdes_chip_pinctrl_ops {
   int (*pinmux_set)(struct serdes *serdes, unsigned int pin_selector,
             unsigned int func_selector);
   int (*pinmux_group_set)(struct serdes *serdes,
               unsigned int group_selector,
               unsigned int func_selector);
   int (*pinconf_set)(struct serdes *serdes,
              unsigned int pin_selector,
              unsigned int param, unsigned int argument);
   int (*pinconf_group_set)(struct serdes *serdes,
                unsigned int group_selector,
                unsigned int param, unsigned int argument);
};
 
struct serdes_chip_gpio_ops {
   /*serdes chip gpio function*/
   int (*direction_input)(struct serdes *serdes, int gpio);
   int (*direction_output)(struct serdes *serdes, int gpio, int value);
   int (*get_level)(struct serdes *serdes, int gpio);
   int (*set_level)(struct serdes *serdes, int gpio, int value);
   int (*set_config)(struct serdes *serdes,
             int gpio, unsigned long config);
   int (*to_irq)(struct serdes *serdes, int gpio);
};
 
struct serdes_chip_irq_ops {
   /*serdes chip function for lock and err irq*/
   int (*lock_handle)(struct serdes *serdes);
   int (*err_handle)(struct serdes *serdes);
};
 
struct serdes_chip_data {
   const char *name;
   enum serdes_type serdes_type;
   enum serdes_id serdes_id;
   enum reg_val_type reg_val_type;
   int sequence_init;
   int connector_type;
   int reg_id;
   int id_data;
   int int_status_reg;
   int int_trig;
   int num_gpio;
   int gpio_base;
   int same_chip_count;
   u8 bank_num;
 
   struct serdes_chip_pinctrl_info *pinctrl_info;
   struct serdes_chip_bridge_ops *bridge_ops;
   struct serdes_chip_panel_ops *panel_ops;
   struct serdes_chip_pinctrl_ops *pinctrl_ops;
   struct serdes_chip_gpio_ops *gpio_ops;
   struct serdes_chip_irq_ops *irq_ops;
};
 
struct reg_sequence {
   unsigned int reg;
   unsigned int def;
   unsigned int delay_us;
};
 
struct serdes_init_seq {
   struct reg_sequence *reg_sequence;
   unsigned int reg_seq_cnt;
};
 
struct serdes_gpio {
   struct udevice *dev;
   struct serdes_pinctrl *parent;
};
 
struct serdes_pinctrl {
   struct udevice *dev;
   struct serdes *parent;
   struct serdes_gpio *serdes_gpio;
   struct pinctrl_pin_desc *pdesc;
   struct regmap *regmap;
   struct pinctrl_desc *pinctrl_desc;
   int pin_base;
};
 
struct serdes_panel {
   struct rockchip_panel *panel;
   struct serdes *parent;
   struct udevice *backlight;
   struct rockchip_panel_funcs *panel_ops;
};
 
struct serdes_bridge {
   bool sel_mipi;
   struct mipi_dsi_device *dsi;
   struct serdes *parent;
   struct drm_display_mode mode;
   struct rockchip_bridge *bridge;
   struct rockchip_bridge_funcs *bridge_ops;
};
 
struct serdes {
   struct udevice *dev;
   struct udevice *vpower_supply;
   struct serdes_init_seq *serdes_init_seq;
   enum serdes_type type;
 
   /*serdes power and reset pin*/
   struct gpio_desc reset_gpio;
   struct gpio_desc enable_gpio;
 
   /*serdes irq pin*/
   struct gpio_desc lock_gpio;
   struct gpio_desc err_gpio;
   int lock_irq;
   int err_irq;
   int lock_irq_trig;
   int err_irq_trig;
 
   bool sel_mipi;
   struct mipi_dsi_device *dsi;
 
   struct serdes_bridge *serdes_bridge;
   struct serdes_panel *serdes_panel;
   struct serdes_pinctrl *serdes_pinctrl;
   struct serdes_chip_data *chip_data;
};
 
/* Device I/O API */
int serdes_reg_read(struct serdes *serdes, unsigned int reg, unsigned int *val);
int serdes_reg_write(struct serdes *serdes, unsigned int reg, unsigned int val);
int serdes_set_bits(struct serdes *serdes, unsigned int reg,
           unsigned int mask, unsigned int val);
int serdes_i2c_set_sequence(struct serdes *serdes);
int serdes_parse_init_seq(struct udevice *dev, const u16 *data,
             int length, struct serdes_init_seq *seq);
int serdes_get_init_seq(struct serdes *serdes);
int serdes_gpio_register(struct udevice *dev, struct serdes *serdes);
int serdes_pinctrl_register(struct udevice *dev, struct serdes *serdes);
int serdes_power_init(void);
 
extern struct serdes_chip_data serdes_bu18tl82_data;
extern struct serdes_chip_data serdes_bu18rl82_data;
extern struct serdes_chip_data serdes_max96745_data;
extern struct serdes_chip_data serdes_max96752_data;
extern struct serdes_chip_data serdes_max96755_data;
extern struct serdes_chip_data serdes_max96772_data;
extern struct serdes_chip_data serdes_max96789_data;
extern struct serdes_chip_data serdes_rkx111_data;
extern struct serdes_chip_data serdes_rkx121_data;
extern struct serdes_chip_data serdes_nca9539_data;
 
#endif