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