blob: 000942ed0108710df30de725aa3f18011141bc7e [file] [log] [blame]
Googler5e15fb12022-06-11 12:44:13 +08001/* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */
2/*
3 * board/amlogic/g12a_u212_v1/lcd.c
4 *
5 * Copyright (C) 2020 Amlogic, Inc. All rights reserved.
6 *
7 */
8
9#include <common.h>
10#include <amlogic/aml_lcd.h>
11#include <asm/arch/gpio.h>
12
13static char lcd_cpu_gpio[LCD_CPU_GPIO_NUM_MAX][LCD_CPU_GPIO_NAME_MAX] = {
14 "GPIOZ_9", /* panel rst */
15 "GPIOZ_8", /* panel power */
16 "invalid", /* ending flag */
17};
18
19static struct lcd_power_step_s lcd_power_on_step[] = {
20 {LCD_POWER_TYPE_CPU, 1,0,100,}, /* lcd power */
21 {LCD_POWER_TYPE_CPU, 0,0,10,}, /* lcd_reset */
22 {LCD_POWER_TYPE_CPU, 0,1,20,}, /* lcd_reset */
23 {LCD_POWER_TYPE_SIGNAL,0,0,0,}, /* signal */
24 {LCD_POWER_TYPE_MAX, 0,0,0,}, /* ending flag */
25};
26static struct lcd_power_step_s lcd_power_off_step[] = {
27 {LCD_POWER_TYPE_SIGNAL,0,0,50,}, /* signal */
28 {LCD_POWER_TYPE_CPU, 0,0,10,}, /* lcd_reset */
29 {LCD_POWER_TYPE_CPU, 1,1,100,}, /* power off */
30 {LCD_POWER_TYPE_MAX, 0,0,0,}, /* ending flag */
31};
32
33static struct lcd_power_step_s lcd_power_on_step_TV070WSM[] = {
34 {LCD_POWER_TYPE_CPU, 1,0,200,}, /* lcd power */
35#if 1
36 {LCD_POWER_TYPE_CPU, 0,1,30,}, /* lcd_reset */
37 {LCD_POWER_TYPE_CPU, 0,0,10,}, /* lcd_reset */
38 {LCD_POWER_TYPE_CPU, 0,1,30,}, /* lcd_reset */
39#endif
40 {LCD_POWER_TYPE_SIGNAL,0,0,0,}, /* signal */
41 {LCD_POWER_TYPE_MAX, 0,0,0,}, /* ending flag */
42};
43static struct lcd_power_step_s lcd_power_off_step_TV070WSM[] = {
44 {LCD_POWER_TYPE_SIGNAL,0,0,0,}, /* signal */
45 {LCD_POWER_TYPE_CPU, 0,0,20,}, /* lcd_reset */
46 {LCD_POWER_TYPE_CPU, 1,1,100,}, /* power off */
47 {LCD_POWER_TYPE_MAX, 0,0,0,}, /* ending flag */
48};
49
50static struct lcd_power_step_s lcd_power_on_step_P070ACB[] = {
51 {LCD_POWER_TYPE_CPU, 1,0,200,}, /* lcd power */
52 {LCD_POWER_TYPE_CPU, 0,1,30,}, /* lcd_reset */
53 {LCD_POWER_TYPE_CPU, 0,0,10,}, /* lcd_reset */
54 {LCD_POWER_TYPE_CPU, 0,1,30,}, /* lcd_reset */
55 {LCD_POWER_TYPE_SIGNAL,0,0,0,}, /* signal */
56 {LCD_POWER_TYPE_MAX, 0,0,0,}, /* ending flag */
57};
58static struct lcd_power_step_s lcd_power_off_step_P070ACB[] = {
59 {LCD_POWER_TYPE_SIGNAL,0,0,0,}, /* signal */
60 {LCD_POWER_TYPE_CPU, 0,0,20,}, /* lcd_reset */
61 {LCD_POWER_TYPE_CPU, 1,1,100,}, /* power off */
62 {LCD_POWER_TYPE_MAX, 0,0,0,}, /* ending flag */
63};
64
65static char lcd_bl_gpio[BL_GPIO_NUM_MAX][LCD_CPU_GPIO_NAME_MAX] = {
66 "GPIOH_4", /* BL_EN */
67 "GPIOH_5", /* BL_PWM */
68 "invalid", /* ending flag */
69};
70
71struct ext_lcd_config_s ext_lcd_config[LCD_NUM_MAX] = {
72 {/* B080XAN01*/
73 "lcd_0",LCD_MIPI,8,
74 /* basic timing */
75 768,1024,948,1140,64,56,0,50,30,0,
76 /* clk_attr */
77 0,0,1,64843200,Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,
78 /* mipi_attr */
79 4,550,0,1,0,2,1,0,Rsv_val,Rsv_val,
80 /* power step */
81 lcd_power_on_step, lcd_power_off_step,
82 /* backlight */
83 100,255,10,128,128,
84 BL_CTRL_PWM,0,1,0,200,200,
85 BL_PWM_NEGATIVE,BL_PWM_F,180,100,25,1,1,
86 Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,
87 Rsv_val,Rsv_val,Rsv_val,Rsv_val,
88 10,10,Rsv_val},
89
90 {/* TV070WSM*/
91 "lcd_1",LCD_MIPI,8,
92 /* basic timing */
93 600,1024,700,1053,24,36,0,2,8,0,
94 /* clk_attr */
95 0,0,1,44250000,Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,
96 /* mipi_attr */
97 4,360,0,1,0,2,0,0,Rsv_val,1,
98 /* power step */
99 lcd_power_on_step_TV070WSM, lcd_power_off_step_TV070WSM,
100 /* backlight */
101 100,255,10,128,128,
102 BL_CTRL_PWM,0,1,0,200,200,
103 BL_PWM_NEGATIVE,BL_PWM_F,180,100,25,1,1,
104 Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,
105 Rsv_val,Rsv_val,Rsv_val,Rsv_val,
106 10,10,Rsv_val},
107
108 {/* P070ACB*/
109 "lcd_2",LCD_MIPI,8,
110 /* basic timing */
111 600,1024,680,1194,24,36,0,10,80,0,
112 /* clk_attr */
113 0,0,1,48715200,Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,
114 /* mipi_attr */
115 4,400,0,1,0,2,0,0,Rsv_val,2,
116 /* power step */
117 lcd_power_on_step_P070ACB, lcd_power_off_step_P070ACB,
118 /* backlight */
119 100,255,10,128,128,
120 BL_CTRL_PWM,0,1,0,200,200,
121 BL_PWM_NEGATIVE,BL_PWM_F,180,100,25,1,1,
122 Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,Rsv_val,
123 Rsv_val,Rsv_val,Rsv_val,Rsv_val,
124 10,10,Rsv_val},
125
126 {.panel_type = "invalid"},
127};
128
129static struct lcd_pinmux_ctrl_s lcd_pinmux_ctrl[LCD_PINMX_MAX] = {
130 {
131 .name = "lcd_pin",
132 .pinmux_set = {{LCD_PINMUX_END, 0x0}},
133 .pinmux_clr = {{LCD_PINMUX_END, 0x0}},
134 },
135 {
136 .name = "invalid",
137 },
138};
139
140static struct lcd_pinmux_ctrl_s bl_pinmux_ctrl[BL_PINMUX_MAX] = {
141 {
142 .name = "bl_pwm_on_pin", //GPIOH_5
143 .pinmux_set = {{11, 0x00400000}, {LCD_PINMUX_END, 0x0}},
144 .pinmux_clr = {{11, 0x00f00000}, {LCD_PINMUX_END, 0x0}},
145 },
146 {
147 .name = "invalid",
148 },
149};
150
151static unsigned char mipi_init_on_table[DSI_INIT_ON_MAX] = {//table size < 100
152 0x05, 1, 0x11,
153 0xfd, 1, 20,
154 0x05, 1, 0x29,
155 0xfd, 1, 20,
156 0xff, 0, //ending
157};
158static unsigned char mipi_init_off_table[DSI_INIT_OFF_MAX] = {//table size < 50
159 0x05, 1, 0x28,
160 0xfd, 1, 10,
161 0x05, 1, 0x10,
162 0xfd, 1, 10,
163 0xff, 0, //ending
164};
165
166static unsigned char mipi_init_on_table_TV070WSM[DSI_INIT_ON_MAX] = {//table size < 100
167 0xff, 0, //ending
168};
169static unsigned char mipi_init_off_table_TV070WSM[DSI_INIT_OFF_MAX] = {//table size < 50
170 0xff, 0, //ending
171};
172
173static unsigned char mipi_init_on_table_P070ACB[DSI_INIT_ON_MAX] = {//table size < 100
174 0xff, 0, //ending
175};
176static unsigned char mipi_init_off_table_P070ACB[DSI_INIT_OFF_MAX] = {//table size < 50
177 0xff, 0, //ending
178};
179
180static struct dsi_config_s lcd_mipi_config = {
181 .lane_num = 4,
182 .bit_rate_max = 550, /* MHz */
183 .factor_numerator = 0,
184 .factor_denominator = 100,
185 .operation_mode_init = 1, /* 0=video mode, 1=command mode */
186 .operation_mode_display = 0, /* 0=video mode, 1=command mode */
187 .video_mode_type = 2, /* 0=sync_pulse, 1=sync_event, 2=burst */
188 .clk_always_hs = 1, /* 0=disable, 1=enable */
189 .phy_switch = 0, /* 0=auto, 1=standard, 2=slow */
190
191 .dsi_init_on = &mipi_init_on_table[0],
192 .dsi_init_off = &mipi_init_off_table[0],
193 .extern_init = 0xff, /* ext_index if needed, 0xff for invalid */
194 .check_en = 0,
195 .check_state = 0,
196};
197
198static struct lcd_power_ctrl_s lcd_power_ctrl = {
199 .power_on_step = {
200 {
201 .type = LCD_POWER_TYPE_CPU,
202 .index = 0, /* point to cpu_gpio[] struct */
203 .value = 1, /* 0=output_low, 1=output_high, 2=input */
204 .delay = 10, /* unit: ms */
205 },
206 {
207 .type = LCD_POWER_TYPE_CPU,
208 .index = 0, /* point to cpu_gpio[] struct */
209 .value = 0, /* 0=output_low, 1=output_high, 2=input */
210 .delay = 20, /* unit: ms */
211 },
212 {
213 .type = LCD_POWER_TYPE_CPU,
214 .index = 0, /* point to cpu_gpio[] struct */
215 .value = 1, /* 0=output_low, 1=output_high, 2=input */
216 .delay = 20, /* unit: ms */
217 },
218 {
219 .type = LCD_POWER_TYPE_SIGNAL,
220 .index = 0, /* point to cpu_gpio[] struct */
221 .value = 1, /* 0=output_low, 1=output_high, 2=input */
222 .delay = 0, /* unit: ms */
223 },
224 {
225 .type = LCD_POWER_TYPE_MAX, /* ending flag */
226 },
227 },
228 .power_off_step = {
229 {
230 .type = LCD_POWER_TYPE_SIGNAL,
231 .index = 0, /* point to cpu_gpio[] struct */
232 .value = 0, /* 0=output_low, 1=output_high, 2=input */
233 .delay = 100, /* unit: ms */
234 },
235 {
236 .type = LCD_POWER_TYPE_CPU,
237 .index = 0, /* point to cpu_gpio[] struct */
238 .value = 0, /* 0=output_low, 1=output_high, 2=input */
239 .delay = 100, /* unit: ms */
240 },
241 {
242 .type = LCD_POWER_TYPE_MAX, /* ending flag */
243 },
244 },
245};
246
247struct lcd_config_s lcd_config_dft = {
248 .lcd_mode = LCD_MODE_TABLET,
249 .lcd_key_valid = 0,
250 .lcd_clk_path = 0,
251 .lcd_basic = {
252 .model_name = "default",
253 .lcd_type = LCD_TYPE_MAX,
254 .lcd_bits = 8,
255 .h_active = 768,
256 .v_active = 1024,
257 .h_period = 948,
258 .v_period = 1140,
259
260 .screen_width = 119,
261 .screen_height = 159,
262 },
263
264 .lcd_timing = {
265 .clk_auto = 1,
266 .lcd_clk = 64843200,
267 .ss_level = 0,
268 .fr_adjust_type = 0,
269
270 .hsync_width = 64,
271 .hsync_bp = 56,
272 .hsync_pol = 0,
273 .vsync_width = 50,
274 .vsync_bp = 30,
275 .vsync_pol = 0,
276 },
277
278 .lcd_control = {
279 .mipi_config= &lcd_mipi_config,
280 },
281 .lcd_power = &lcd_power_ctrl,
282
283 .pinctrl_ver = 2,
284 .lcd_pinmux = lcd_pinmux_ctrl,
285 .pinmux_set = {{LCD_PINMUX_END, 0x0}},
286 .pinmux_clr = {{LCD_PINMUX_END, 0x0}},
287};
288
289#ifdef CONFIG_AML_LCD_EXTERN
290static char lcd_ext_gpio[LCD_EXTERN_GPIO_NUM_MAX][LCD_EXTERN_GPIO_LEN_MAX] = {
291 "invalid", /* ending flag */
292};
293
294static unsigned char ext_init_on_table[LCD_EXTERN_INIT_ON_MAX] = {
295 0xff, 0, //ending flag
296};
297
298static unsigned char ext_init_off_table[LCD_EXTERN_INIT_OFF_MAX] = {
299 0xff, 0, //ending flag
300};
301
302struct lcd_extern_common_s ext_common_dft = {
303 .lcd_ext_key_valid = 0,
304 .lcd_ext_num = 3,
305 .i2c_bus = LCD_EXTERN_I2C_BUS_0, /* LCD_EXTERN_I2C_BUS_0/1/2/3/4 */
306 .pinmux_set = {{LCD_PINMUX_END, 0x0}},
307 .pinmux_clr = {{LCD_PINMUX_END, 0x0}},
308};
309
310struct lcd_extern_config_s ext_config_dtf[LCD_EXTERN_NUM_MAX] = {
311 {
312 .index = 0,
313 .name = "ext_default",
314 .type = LCD_EXTERN_I2C, /* LCD_EXTERN_I2C, LCD_EXTERN_SPI, LCD_EXTERN_MIPI, LCD_EXTERN_MAX */
315 .status = 0, /* 0=disable, 1=enable */
316 .i2c_addr = 0x1c, /* 7bit i2c address */
317 .i2c_addr2 = 0xff, /* 7bit i2c address, 0xff for none */
318 .cmd_size = LCD_EXT_CMD_SIZE_DYNAMIC,
319 .table_init_on = ext_init_on_table,
320 .table_init_on_cnt = sizeof(ext_init_on_table),
321 .table_init_off = ext_init_off_table,
322 .table_init_off_cnt = sizeof(ext_init_off_table),
323 },
324 {
325 .index = 1,
326 .name = "mipi_TV070WSM",
327 .type = LCD_EXTERN_MIPI, /* LCD_EXTERN_I2C, LCD_EXTERN_SPI, LCD_EXTERN_MIPI, LCD_EXTERN_MAX */
328 .status = 1, /* 0=disable, 1=enable */
329 .cmd_size = LCD_EXT_CMD_SIZE_DYNAMIC,
330 .table_init_on = ext_init_on_table,
331 .table_init_on_cnt = sizeof(ext_init_on_table),
332 .table_init_off = ext_init_off_table,
333 .table_init_off_cnt = sizeof(ext_init_off_table),
334 },
335 {
336 .index = 2,
337 .name = "mipi_P070ACB",
338 .type = LCD_EXTERN_MIPI, /* LCD_EXTERN_I2C, LCD_EXTERN_SPI, LCD_EXTERN_MIPI, LCD_EXTERN_MAX */
339 .status = 1, /* 0=disable, 1=enable */
340 .cmd_size = LCD_EXT_CMD_SIZE_DYNAMIC,
341 .table_init_on = ext_init_on_table,
342 .table_init_on_cnt = sizeof(ext_init_on_table),
343 .table_init_off = ext_init_off_table,
344 .table_init_off_cnt = sizeof(ext_init_off_table),
345 },
346 {
347 .index = LCD_EXTERN_INDEX_INVALID,
348 },
349};
350#endif
351
352struct bl_config_s bl_config_dft = {
353 .name = "default",
354 .bl_key_valid = 0,
355
356 .level_default = 100,
357 .level_min = 10,
358 .level_max = 255,
359 .level_mid = 128,
360 .level_mid_mapping = 128,
361 .level = 0,
362
363 .method = BL_CTRL_MAX,
364 .power_on_delay = 200,
365 .power_off_delay = 200,
366
367 .en_gpio = 0xff,
368 .en_gpio_on = 1,
369 .en_gpio_off = 0,
370
371 .bl_pwm = NULL,
372 .bl_pwm_combo0 = NULL,
373 .bl_pwm_combo1 = NULL,
374 .pwm_on_delay = 10,
375 .pwm_off_delay = 10,
376
377 .bl_extern_index = 0xff,
378
379 .pinctrl_ver = 2,
380 .bl_pinmux = bl_pinmux_ctrl,
381 .pinmux_set = {{11, 0x00400000}, {LCD_PINMUX_END, 0x0}},
382 .pinmux_clr = {{11, 0x00f00000}, {LCD_PINMUX_END, 0x0}},
383};
384
385#ifdef CONFIG_AML_BL_EXTERN
386static unsigned char bl_ext_init_on[BL_EXTERN_INIT_ON_MAX];
387static unsigned char bl_ext_init_off[BL_EXTERN_INIT_OFF_MAX];
388struct bl_extern_config_s bl_extern_config_dtf = {
389 .index = BL_EXTERN_INDEX_INVALID,
390 .name = "none",
391 .type = BL_EXTERN_MAX,
392 .i2c_addr = 0xff,
393 .i2c_bus = BL_EXTERN_I2C_BUS_MAX,
394 .dim_min = 10,
395 .dim_max = 255,
396
397 .init_loaded = 0,
398 .cmd_size = 0xff,
399 .init_on = bl_ext_init_on,
400 .init_off = bl_ext_init_off,
401 .init_on_cnt = sizeof(bl_ext_init_on),
402 .init_off_cnt = sizeof(bl_ext_init_off),
403};
404#endif
405
406void lcd_config_bsp_init(void)
407{
408 int i, j;
409 char *str;
410 struct ext_lcd_config_s *ext_lcd = NULL;
411
412 str = getenv("panel_type");
413 if (str) {
414 for (i = 0 ; i < LCD_NUM_MAX ; i++) {
415 ext_lcd = &ext_lcd_config[i];
416 if (strcmp(ext_lcd->panel_type, str) == 0) {
417 switch (i) {
418 case 1:
419 lcd_mipi_config.dsi_init_on = mipi_init_on_table_TV070WSM;
420 lcd_mipi_config.dsi_init_off = mipi_init_off_table_TV070WSM;
421 break;
422 case 2:
423 lcd_mipi_config.dsi_init_on = mipi_init_on_table_P070ACB;
424 lcd_mipi_config.dsi_init_off = mipi_init_off_table_P070ACB;
425 break;
426 case 0:
427 default:
428 lcd_mipi_config.dsi_init_on = mipi_init_on_table;
429 lcd_mipi_config.dsi_init_off = mipi_init_off_table;
430 break;
431 }
432 break;
433 }
434 }
435 }
436
437 for (i = 0; i < LCD_CPU_GPIO_NUM_MAX; i++) {
438 if (strcmp(lcd_cpu_gpio[i], "invalid") == 0)
439 break;
440 strcpy(lcd_power_ctrl.cpu_gpio[i], lcd_cpu_gpio[i]);
441 }
442 for (j = i; j < LCD_CPU_GPIO_NUM_MAX; j++)
443 strcpy(lcd_power_ctrl.cpu_gpio[j], "invalid");
444 for (i = 0; i < BL_GPIO_NUM_MAX; i++) {
445 if (strcmp(lcd_bl_gpio[i], "invalid") == 0)
446 break;
447 strcpy(bl_config_dft.gpio_name[i], lcd_bl_gpio[i]);
448 }
449 for (j = i; j < BL_GPIO_NUM_MAX; j++)
450 strcpy(bl_config_dft.gpio_name[j], "invalid");
451
452#ifdef CONFIG_AML_LCD_EXTERN
453 for (i = 0; i < LCD_EXTERN_NUM_MAX; i++) {
454 if (ext_config_dtf[i].index == LCD_EXTERN_INDEX_INVALID)
455 break;
456 }
457 ext_common_dft.lcd_ext_num = i;
458
459 for (i = 0; i < LCD_EXTERN_GPIO_NUM_MAX; i++) {
460 if (strcmp(lcd_ext_gpio[i], "invalid") == 0)
461 break;
462 strcpy(ext_common_dft.gpio_name[i], lcd_ext_gpio[i]);
463 }
464 for (j = i; j < LCD_EXTERN_GPIO_NUM_MAX; j++)
465 strcpy(ext_common_dft.gpio_name[j], "invalid");
466
467#endif
468}