1 /* u-boot-2014.07/drivers/video/sunxi/disp2/disp/lcd/lq101r1sx03.c
2 *
3 * Copyright (c) 2017 Allwinnertech Co., Ltd.
4 *
5 * lq101r1sx03 panel driver
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11 #include "lq101r1sx03.h"
12
13 static void lcd_power_on(u32 sel);
14 static void lcd_power_off(u32 sel);
15 static void lcd_bl_open(u32 sel);
16 static void lcd_bl_close(u32 sel);
17
18 static void lcd_panel_init(u32 sel);
19 static void lcd_panel_exit(u32 sel);
20
21 static u8 const mipi_dcs_pixel_format[4] = { 0x77, 0x66, 0x66, 0x55 };
22
23 #define panel_reset(val) sunxi_lcd_gpio_set_value(sel, 0, val)
24 #define power_en(val) sunxi_lcd_gpio_set_value(sel, 1, val)
25
lcd_cfg_panel_info(struct panel_extend_para * info)26 static void lcd_cfg_panel_info(struct panel_extend_para *info)
27 {
28 u32 i = 0, j = 0;
29 u32 items;
30 u8 lcd_gamma_tbl[][2] = {
31 /* {input value, corrected value} */
32 {0, 0},
33 {15, 15},
34 {30, 30},
35 {45, 45},
36 {60, 60},
37 {75, 75},
38 {90, 90},
39 {105, 105},
40 {120, 120},
41 {135, 135},
42 {150, 150},
43 {165, 165},
44 {180, 180},
45 {195, 195},
46 {210, 210},
47 {225, 225},
48 {240, 240},
49 {255, 255},
50 };
51
52 u32 lcd_cmap_tbl[2][3][4] = {
53 {
54 {LCD_CMAP_G0, LCD_CMAP_B1, LCD_CMAP_G2, LCD_CMAP_B3},
55 {LCD_CMAP_B0, LCD_CMAP_R1, LCD_CMAP_B2, LCD_CMAP_R3},
56 {LCD_CMAP_R0, LCD_CMAP_G1, LCD_CMAP_R2, LCD_CMAP_G3},
57 },
58 {
59 {LCD_CMAP_B3, LCD_CMAP_G2, LCD_CMAP_B1, LCD_CMAP_G0},
60 {LCD_CMAP_R3, LCD_CMAP_B2, LCD_CMAP_R1, LCD_CMAP_B0},
61 {LCD_CMAP_G3, LCD_CMAP_R2, LCD_CMAP_G1, LCD_CMAP_R0},
62 },
63 };
64
65 items = sizeof(lcd_gamma_tbl) / 2;
66 for (i = 0; i < items - 1; i++) {
67 u32 num = lcd_gamma_tbl[i + 1][0] - lcd_gamma_tbl[i][0];
68
69 for (j = 0; j < num; j++) {
70 u32 value = 0;
71
72 value = lcd_gamma_tbl[i][1] +
73 ((lcd_gamma_tbl[i + 1][1] - lcd_gamma_tbl[i][1]) * j) / num;
74 info->lcd_gamma_tbl[lcd_gamma_tbl[i][0] + j] =
75 (value << 16) + (value << 8) + value;
76 }
77 }
78 info->lcd_gamma_tbl[255] =
79 (lcd_gamma_tbl[items - 1][1] << 16) +
80 (lcd_gamma_tbl[items - 1][1] << 8) + lcd_gamma_tbl[items - 1][1];
81
82 memcpy(info->lcd_cmap_tbl, lcd_cmap_tbl, sizeof(lcd_cmap_tbl));
83
84 }
85
lcd_open_flow(u32 sel)86 static s32 lcd_open_flow(u32 sel)
87 {
88 LCD_OPEN_FUNC(sel, lcd_power_on, 250);
89 LCD_OPEN_FUNC(sel, lcd_panel_init, 10);
90 LCD_OPEN_FUNC(sel, sunxi_lcd_tcon_enable, 50);
91 LCD_OPEN_FUNC(sel, lcd_bl_open, 0);
92
93 return 0;
94 }
95
lcd_close_flow(u32 sel)96 static s32 lcd_close_flow(u32 sel)
97 {
98 LCD_CLOSE_FUNC(sel, lcd_bl_close, 0);
99 LCD_CLOSE_FUNC(sel, lcd_panel_exit, 20);
100 LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 0);
101 LCD_CLOSE_FUNC(sel, lcd_power_off, 50);
102
103 return 0;
104 }
105
lcd_power_on(u32 sel)106 static void lcd_power_on(u32 sel)
107 {
108 /* set lcd-rst to 0 */
109 panel_reset(0);
110 /* vcc-dsi */
111 sunxi_lcd_power_enable(sel, 0);
112 sunxi_lcd_delay_ms(10);
113 /* vcc18-lcd */
114 sunxi_lcd_power_enable(sel, 1);
115 sunxi_lcd_delay_ms(10);
116 /* vcc33-lcd */
117 sunxi_lcd_power_enable(sel, 2);
118 sunxi_lcd_delay_ms(10);
119 power_en(1);
120 sunxi_lcd_delay_ms(50);
121
122 panel_reset(1);
123 sunxi_lcd_delay_ms(10);
124 panel_reset(0);
125 sunxi_lcd_delay_ms(50);
126 panel_reset(1);
127 sunxi_lcd_delay_ms(10);
128
129 sunxi_lcd_pin_cfg(sel, 1);
130 }
131
lcd_power_off(u32 sel)132 static void lcd_power_off(u32 sel)
133 {
134 sunxi_lcd_pin_cfg(sel, 0);
135 sunxi_lcd_delay_ms(20);
136 panel_reset(0);
137 sunxi_lcd_delay_ms(5);
138 power_en(0);
139 sunxi_lcd_delay_ms(10);
140 sunxi_lcd_power_disable(sel, 2);
141 sunxi_lcd_delay_ms(5);
142 sunxi_lcd_power_disable(sel, 1);
143 sunxi_lcd_delay_ms(5);
144 sunxi_lcd_power_disable(sel, 0);
145 }
146
lcd_bl_open(u32 sel)147 static void lcd_bl_open(u32 sel)
148 {
149 sunxi_lcd_backlight_enable(sel);
150 sunxi_lcd_pwm_enable(sel);
151 }
152
lcd_bl_close(u32 sel)153 static void lcd_bl_close(u32 sel)
154 {
155 sunxi_lcd_backlight_disable(sel);
156 sunxi_lcd_pwm_disable(sel);
157 }
158
lcd_panel_init(u32 sel)159 static void lcd_panel_init(u32 sel)
160 {
161
162
163 sunxi_lcd_dsi_clk_enable(sel);
164 sunxi_lcd_delay_ms(10);
165
166 sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_EXIT_SLEEP_MODE);
167 sunxi_lcd_delay_ms(40);
168 sunxi_lcd_dsi_dcs_write_0para(sel+1, DSI_DCS_EXIT_SLEEP_MODE);
169 sunxi_lcd_delay_ms(40);
170 sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_SET_DISPLAY_ON);
171
172 return;
173 }
174
lcd_panel_exit(u32 sel)175 static void lcd_panel_exit(u32 sel)
176 {
177 sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_SET_DISPLAY_OFF);
178 sunxi_lcd_delay_ms(20);
179 sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_ENTER_SLEEP_MODE);
180 sunxi_lcd_delay_ms(80);
181
182 return;
183 }
184
185 /*sel: 0:lcd0; 1:lcd1*/
lcd_user_defined_func(u32 sel,u32 para1,u32 para2,u32 para3)186 static s32 lcd_user_defined_func(u32 sel, u32 para1, u32 para2, u32 para3)
187 {
188 return 0;
189 }
190
191 /*sel: 0:lcd0; 1:lcd1*/
lcd_set_bright(u32 sel,u32 bright)192 static s32 lcd_set_bright(u32 sel, u32 bright)
193 {
194 return 0;
195 }
196
lcd_set_esd_info(struct disp_lcd_esd_info * p_info)197 static int lcd_set_esd_info(struct disp_lcd_esd_info *p_info)
198 {
199 if (!p_info)
200 return -1;
201 p_info->level = 1;
202 p_info->freq = 60;
203 p_info->esd_check_func_pos = 1;
204 return 0;
205 }
206
207 /**
208 * @name :lcd_esd_check
209 * @brief :check if panel is ok
210 * @param[IN] :sel:index of dsi
211 * @param[OUT] :none
212 * @return :0 if ok, else not ok
213 */
lcd_esd_check(u32 sel)214 static s32 lcd_esd_check(u32 sel)
215 {
216 s32 ret = 0;
217 u8 result[16] = {0};
218
219 ret = sunxi_lcd_dsi_gen_short_read2p(0, 0x10, 0x0, result);
220 if (result[0] != 0x3f)
221 ret = -1;
222 else
223 ret = 0;
224 return ret;
225 }
226
227 /**
228 * @name :lcd_reset_panel
229 * @brief :reset panel step
230 * @param[IN] :sel:index of dsi
231 * @param[OUT] :none
232 * @return :0
233 */
lcd_reset_panel(u32 sel)234 static s32 lcd_reset_panel(u32 sel)
235 {
236 sunxi_lcd_dsi_dcs_write_0para(sel, 0x28);
237 sunxi_lcd_delay_ms(50);
238 sunxi_lcd_dsi_dcs_write_0para(sel, 0x10);
239 sunxi_lcd_delay_ms(200);
240
241 sunxi_lcd_power_disable(sel, 1);
242 sunxi_lcd_delay_ms(100);
243 sunxi_lcd_power_enable(sel, 1);
244 sunxi_lcd_delay_ms(260);
245
246 lcd_panel_init(sel);
247 sunxi_lcd_delay_ms(20);
248
249 return 0;
250 }
251
252 struct __lcd_panel lq101r1sx03_panel = {
253 /* panel driver name, must mach the name of lcd_drv_name in
254 sys_config.fex */
255 .name = "lq101r1sx03",
256 .func = {
257 .cfg_panel_info = lcd_cfg_panel_info,
258 .cfg_open_flow = lcd_open_flow,
259 .cfg_close_flow = lcd_close_flow,
260 .lcd_user_defined_func = lcd_user_defined_func,
261 .set_bright = lcd_set_bright,
262 .esd_check = lcd_esd_check,
263 .reset_panel = lcd_reset_panel,
264 .set_esd_info = lcd_set_esd_info,
265 }
266 ,
267 };
268