1 /* drivers/video/fbdev/sunxi/disp2/disp/lcd/frd450h40014.c
2 *
3 * Copyright (c) 2017 Allwinnertech Co., Ltd.
4 * Author: zhengxiaobin <zhengxiaobin@allwinnertech.com>
5 *
6 * frd450h40014 panel driver
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * [lcd0]
13 * lcd_used = 1
14
15 * lcd_driver_name = "frd450h40014"
16 * lcd_backlight = 100
17
18 * lcd_if = 4
19 * lcd_x = 480
20 * lcd_y = 854
21 * lcd_width = 55
22 * lcd_height = 99
23 * lcd_dclk_freq = 34
24
25 * lcd_pwm_used = 1
26 * lcd_pwm_ch = 8
27 * lcd_pwm_freq = 50000
28 * lcd_pwm_pol = 1
29 * lcd_pwm_max_limit = 255
30
31 * lcd_hbp = 112
32 * lcd_ht = 640
33 * lcd_hspw = 32
34 * lcd_vbp = 20
35 * lcd_vt = 879
36 * lcd_vspw = 2
37
38 * lcd_dsi_if = 0
39 * lcd_dsi_lane = 2
40 * lcd_dsi_format = 0
41 * lcd_dsi_te = 0
42 * lcd_dsi_eotp = 0
43
44 * lcd_frm = 1
45 * lcd_io_phase = 0x0000
46 * lcd_hv_clk_phase = 0
47 * lcd_hv_sync_polarity= 0
48 * lcd_gamma_en = 0
49 * lcd_bright_curve_en = 0
50 * lcd_cmap_en = 0
51
52 * lcdgamma4iep = 22
53
54 * lcd_bl_en = port:PB07<1><0><default><1>
55 * lcd_pin_power = "vcc18-dsi"
56 * lcd_pin_power1 = "vcc-pd"
57 * lcd_power = "vcc-lcd"
58 * lcd_gpio_0 = port:PB06<1><0><default><1>
59 */
60 #include "frd450h40014.h"
61
62 static void lcd_power_on(u32 sel);
63 static void lcd_power_off(u32 sel);
64 static void lcd_bl_open(u32 sel);
65 static void lcd_bl_close(u32 sel);
66
67 static void lcd_panel_init(u32 sel);
68 static void lcd_panel_exit(u32 sel);
69
70 #define panel_reset(sel, val) sunxi_lcd_gpio_set_value(sel, 0, val)
71
lcd_cfg_panel_info(struct panel_extend_para * info)72 static void lcd_cfg_panel_info(struct panel_extend_para *info)
73 {
74 u32 i = 0, j = 0;
75 u32 items;
76 u8 lcd_gamma_tbl[][2] = {
77 {0, 0},
78 {15, 15},
79 {30, 30},
80 {45, 45},
81 {60, 60},
82 {75, 75},
83 {90, 90},
84 {105, 105},
85 {120, 120},
86 {135, 135},
87 {150, 150},
88 {165, 165},
89 {180, 180},
90 {195, 195},
91 {210, 210},
92 {225, 225},
93 {240, 240},
94 {255, 255},
95 };
96
97 u32 lcd_cmap_tbl[2][3][4] = {
98 {
99 {LCD_CMAP_G0, LCD_CMAP_B1, LCD_CMAP_G2, LCD_CMAP_B3},
100 {LCD_CMAP_B0, LCD_CMAP_R1, LCD_CMAP_B2, LCD_CMAP_R3},
101 {LCD_CMAP_R0, LCD_CMAP_G1, LCD_CMAP_R2, LCD_CMAP_G3},
102 },
103 {
104 {LCD_CMAP_B3, LCD_CMAP_G2, LCD_CMAP_B1, LCD_CMAP_G0},
105 {LCD_CMAP_R3, LCD_CMAP_B2, LCD_CMAP_R1, LCD_CMAP_B0},
106 {LCD_CMAP_G3, LCD_CMAP_R2, LCD_CMAP_G1, LCD_CMAP_R0},
107 },
108 };
109
110 items = sizeof(lcd_gamma_tbl) / 2;
111 for (i = 0; i < items - 1; i++) {
112 u32 num = lcd_gamma_tbl[i+1][0] - lcd_gamma_tbl[i][0];
113
114 for (j = 0; j < num; j++) {
115 u32 value = 0;
116
117 value = lcd_gamma_tbl[i][1] +
118 ((lcd_gamma_tbl[i+1][1] - lcd_gamma_tbl[i][1])
119 * j) / num;
120 info->lcd_gamma_tbl[lcd_gamma_tbl[i][0] + j] =
121 (value<<16)
122 + (value<<8) + value;
123 }
124 }
125 info->lcd_gamma_tbl[255] = (lcd_gamma_tbl[items-1][1]<<16) +
126 (lcd_gamma_tbl[items-1][1]<<8)
127 + lcd_gamma_tbl[items-1][1];
128
129 memcpy(info->lcd_cmap_tbl, lcd_cmap_tbl, sizeof(lcd_cmap_tbl));
130
131 }
132
lcd_open_flow(u32 sel)133 static s32 lcd_open_flow(u32 sel)
134 {
135 LCD_OPEN_FUNC(sel, lcd_power_on, 120);
136 LCD_OPEN_FUNC(sel, lcd_panel_init, 10);
137 LCD_OPEN_FUNC(sel, sunxi_lcd_tcon_enable, 10);
138 LCD_OPEN_FUNC(sel, lcd_bl_open, 0);
139 return 0;
140 }
141
lcd_close_flow(u32 sel)142 static s32 lcd_close_flow(u32 sel)
143 {
144 LCD_CLOSE_FUNC(sel, lcd_bl_close, 0);
145 LCD_CLOSE_FUNC(sel, lcd_panel_exit, 10);
146 LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 10);
147 LCD_CLOSE_FUNC(sel, lcd_power_off, 10);
148
149 return 0;
150 }
151
lcd_power_on(u32 sel)152 static void lcd_power_on(u32 sel)
153 {
154 sunxi_lcd_pin_cfg(sel, 1);
155 sunxi_lcd_power_enable(sel, 0);
156 sunxi_lcd_delay_ms(2);
157 panel_reset(sel, 1);
158 sunxi_lcd_delay_ms(2);
159 panel_reset(sel, 0);
160 sunxi_lcd_delay_ms(2);
161 panel_reset(sel, 1);
162 }
163
lcd_power_off(u32 sel)164 static void lcd_power_off(u32 sel)
165 {
166 panel_reset(sel, 0);
167 sunxi_lcd_pin_cfg(sel, 0);
168 sunxi_lcd_delay_ms(5);
169 sunxi_lcd_power_disable(sel, 0);
170 }
171
lcd_bl_open(u32 sel)172 static void lcd_bl_open(u32 sel)
173 {
174 sunxi_lcd_pwm_enable(sel);
175 sunxi_lcd_backlight_enable(sel);
176 }
177
lcd_bl_close(u32 sel)178 static void lcd_bl_close(u32 sel)
179 {
180 sunxi_lcd_backlight_disable(sel);
181 sunxi_lcd_pwm_disable(sel);
182 }
183
184 struct LCM_setting_table {
185 u8 cmd;
186 u32 count;
187 u8 para_list[64];
188 };
189
190 #define REGFLAG_DELAY 0x00
191 #define REGFLAG_END_OF_TABLE 0xFE /* END OF REGISTERS MARKER */
192
193 static struct LCM_setting_table lcm_initialization_setting[] = {
194 { 0x11, 1, {0x00} },
195 { REGFLAG_DELAY, 120, {} },
196 { 0xFF, 5, {0x77, 0x01, 0x00, 0x00, 0x10} },
197 { 0xC0, 2, {0xe9, 0x03} },
198 { 0xC1, 2, {0x11, 0x02} },
199 { 0xC2, 2, {0x31, 0x08} },
200 { 0xCC, 1, {0x10} },
201 { 0xB0, 16, {0x00, 0x03, 0x8A, 0x10, 0x15, 0x09, 0x05, 0x0A,
202 0x0A, 0x1A, 0x07, 0x13, 0x0F, 0x0D, 0x10, 0x19} },
203 { 0xB1, 16, {0x00, 0x03, 0x08, 0x0F, 0x14, 0x0A, 0x04, 0x09,
204 0x09, 0x1E, 0x0A, 0x17, 0x15, 0x14, 0x1A, 0x19} },
205 { 0xFF, 5, {0x77, 0x01, 0x00, 0x00, 0x11} },
206 { 0xB0, 1, {0x50} },
207 { 0xB1, 1, {0x49} },
208 { 0xB2, 1, {0x07} },
209 { 0xB3, 1, {0x80} },
210 { 0xB5, 1, {0x47} },
211 { 0xB7, 1, {0x85} },
212 { 0xB8, 1, {0x21} },
213 { 0xB9, 1, {0x10} },
214 { 0xC1, 1, {0x78} },
215 { 0xC2, 1, {0x78} },
216 { 0xD0, 1, {0x88} },
217 { REGFLAG_DELAY, 100, {} },
218 { 0xE0, 3, {0x00, 0x00, 0x02} },
219 { 0xE1, 11, {0x08, 0x00, 0x0A, 0x00, 0x07, 0x00, 0x09, 0x00,
220 0x00, 0x33, 0x33} },
221 { 0xE2, 11, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
222 0x00, 0x00, 0x00} },
223 { 0xE3, 4, {0x00, 0x00, 0x33, 0x33} },
224 { 0xE4, 2, {0x44, 0x44} },
225 { 0xE5, 16, {0x0E, 0x60, 0xA0, 0xA0, 0x10, 0x60, 0xA0, 0xA0,
226 0x0A, 0x60, 0xA0, 0xA0, 0x0C, 0x60, 0xA0, 0xA0} },
227 { 0xE6, 4, {0x00, 0x00, 0x33, 0x33} },
228 { 0xE7, 2, {0x44, 0x44} },
229 { 0xE8, 16, {0x0D, 0x60, 0xA0, 0xA0, 0x0F, 0x60, 0xA0, 0xA0,
230 0x09, 0x60, 0xA0, 0xA0, 0x0B, 0x60, 0xA0, 0xA0} },
231 { 0xEB, 7, {0x02, 0x01, 0xE4, 0xE4, 0x44, 0x00, 0x40} },
232 { 0xEC, 2, {0x02, 0x01} },
233 { 0xED, 16, {0xAB, 0x89, 0x76, 0x54, 0x01, 0xFF, 0xFF, 0xFF,
234 0xFF, 0xFF, 0xFF, 0x10, 0x45, 0x67, 0x98, 0xBA} },
235 { 0xFF, 5, {0x77, 0x01, 0x00, 0x00, 0x00} },
236 { 0x29, 1, {0x00} },
237 { REGFLAG_DELAY, 5, {} },
238 { REGFLAG_END_OF_TABLE, 0x00, {} }
239 };
240
lcd_panel_init(u32 sel)241 static void lcd_panel_init(u32 sel)
242 {
243 u32 i;
244
245 sunxi_lcd_dsi_clk_enable(sel);
246
247
248 for (i = 0; ; i++) {
249 if (lcm_initialization_setting[i].cmd == REGFLAG_END_OF_TABLE)
250 break;
251 else if (lcm_initialization_setting[i].cmd == REGFLAG_DELAY)
252 sunxi_lcd_delay_ms(lcm_initialization_setting[i].count);
253 else {
254 dsi_dcs_wr(0, lcm_initialization_setting[i].cmd,
255 lcm_initialization_setting[i].para_list,
256 lcm_initialization_setting[i].count);
257 }
258 }
259 }
260
lcd_panel_exit(u32 sel)261 static void lcd_panel_exit(u32 sel)
262 {
263 sunxi_lcd_dsi_dcs_write_0para(sel, 0x28);
264 sunxi_lcd_delay_ms(5);
265 sunxi_lcd_dsi_dcs_write_0para(sel, 0x10);
266 }
267
268 /*sel: 0:lcd0; 1:lcd1*/
lcd_user_defined_func(u32 sel,u32 para1,u32 para2,u32 para3)269 static s32 lcd_user_defined_func(u32 sel, u32 para1, u32 para2, u32 para3)
270 {
271 return 0;
272 }
273
274 struct __lcd_panel frd450h40014_panel = {
275 /* panel driver name, must mach the name of
276 * lcd_drv_name in sys_config.fex
277 */
278 .name = "frd450h40014",
279 .func = {
280 .cfg_panel_info = lcd_cfg_panel_info,
281 .cfg_open_flow = lcd_open_flow,
282 .cfg_close_flow = lcd_close_flow,
283 .lcd_user_defined_func = lcd_user_defined_func,
284 },
285 };
286