1 /*
2 * Allwinner SoCs display driver.
3 *
4 * Copyright (C) 2016 Allwinner.
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
10
11 #include "dx0960be40a1.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 #define panel_reset(val) sunxi_lcd_gpio_set_value(sel, 1, val)
22
LCD_cfg_panel_info(struct panel_extend_para * info)23 static void LCD_cfg_panel_info(struct panel_extend_para *info)
24 {
25 u32 i = 0, j = 0;
26 u32 items;
27 u8 lcd_gamma_tbl[][2] = {
28 /* {input value, corrected value} */
29 {0, 0},
30 {15, 15},
31 {30, 30},
32 {45, 45},
33 {60, 60},
34 {75, 75},
35 {90, 90},
36 {105, 105},
37 {120, 120},
38 {135, 135},
39 {150, 150},
40 {165, 165},
41 {180, 180},
42 {195, 195},
43 {210, 210},
44 {225, 225},
45 {240, 240},
46 {255, 255},
47 };
48
49 u32 lcd_cmap_tbl[2][3][4] = {
50 {
51 {LCD_CMAP_G0, LCD_CMAP_B1, LCD_CMAP_G2, LCD_CMAP_B3},
52 {LCD_CMAP_B0, LCD_CMAP_R1, LCD_CMAP_B2, LCD_CMAP_R3},
53 {LCD_CMAP_R0, LCD_CMAP_G1, LCD_CMAP_R2, LCD_CMAP_G3},
54 },
55 {
56 {LCD_CMAP_B3, LCD_CMAP_G2, LCD_CMAP_B1, LCD_CMAP_G0},
57 {LCD_CMAP_R3, LCD_CMAP_B2, LCD_CMAP_R1, LCD_CMAP_B0},
58 {LCD_CMAP_G3, LCD_CMAP_R2, LCD_CMAP_G1, LCD_CMAP_R0},
59 },
60 };
61
62 items = sizeof(lcd_gamma_tbl) / 2;
63 for (i = 0; i < items - 1; i++) {
64 u32 num = lcd_gamma_tbl[i + 1][0] - lcd_gamma_tbl[i][0];
65
66 for (j = 0; j < num; j++) {
67 u32 value = 0;
68
69 value =
70 lcd_gamma_tbl[i][1] +
71 ((lcd_gamma_tbl[i + 1][1] -
72 lcd_gamma_tbl[i][1]) * j) / num;
73 info->lcd_gamma_tbl[lcd_gamma_tbl[i][0] + j] =
74 (value << 16) + (value << 8) + value;
75 }
76 }
77 info->lcd_gamma_tbl[255] =
78 (lcd_gamma_tbl[items - 1][1] << 16) +
79 (lcd_gamma_tbl[items - 1][1] << 8) + lcd_gamma_tbl[items - 1][1];
80
81 memcpy(info->lcd_cmap_tbl, lcd_cmap_tbl, sizeof(lcd_cmap_tbl));
82
83 }
84
LCD_open_flow(u32 sel)85 static s32 LCD_open_flow(u32 sel)
86 {
87 /* open lcd power, and delay 50ms */
88 LCD_OPEN_FUNC(sel, LCD_power_on, 50);
89 /* open lcd power, than delay 200ms */
90 LCD_OPEN_FUNC(sel, LCD_panel_init, 10);
91 /* open lcd controller, and delay 100ms */
92 LCD_OPEN_FUNC(sel, sunxi_lcd_tcon_enable, 20);
93 /* open lcd backlight, and delay 0ms */
94 LCD_OPEN_FUNC(sel, LCD_bl_open, 0);
95
96 return 0;
97 }
98
LCD_close_flow(u32 sel)99 static s32 LCD_close_flow(u32 sel)
100 {
101 /* close lcd backlight, and delay 0ms */
102 LCD_CLOSE_FUNC(sel, LCD_bl_close, 0);
103 /* close lcd controller, and delay 0ms */
104 LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 0);
105 /* open lcd power, than delay 200ms */
106 LCD_CLOSE_FUNC(sel, LCD_panel_exit, 10);
107 /* close lcd power, and delay 500ms */
108 LCD_CLOSE_FUNC(sel, LCD_power_off, 100);
109
110 return 0;
111 }
112
LCD_power_on(u32 sel)113 static void LCD_power_on(u32 sel)
114 {
115 /* config lcd_power pin to open lcd power */
116 sunxi_lcd_power_enable(sel, 0);
117 sunxi_lcd_pin_cfg(sel, 1);
118 sunxi_lcd_delay_ms(20);
119 panel_reset(1);
120 sunxi_lcd_delay_ms(10);
121 panel_reset(0);
122 sunxi_lcd_delay_ms(10);
123 panel_reset(1);
124 }
125
LCD_power_off(u32 sel)126 static void LCD_power_off(u32 sel)
127 {
128 sunxi_lcd_pin_cfg(sel, 0);
129 /* config lcd_power pin to open lcd power */
130 sunxi_lcd_power_disable(sel, 0);
131 sunxi_lcd_dsi_clk_disable(sel);
132 }
133
LCD_bl_open(u32 sel)134 static void LCD_bl_open(u32 sel)
135 {
136 sunxi_lcd_pwm_enable(sel);
137 /* config lcd_bl_en pin to open lcd backlight */
138 sunxi_lcd_backlight_enable(sel);
139 }
140
LCD_bl_close(u32 sel)141 static void LCD_bl_close(u32 sel)
142 {
143 /* config lcd_bl_en pin to close lcd backlight */
144 sunxi_lcd_backlight_disable(sel);
145 sunxi_lcd_pwm_disable(sel);
146 }
147
LCD_panel_init(u32 sel)148 static void LCD_panel_init(u32 sel)
149 {
150 sunxi_lcd_dsi_clk_enable(sel);
151 sunxi_lcd_delay_ms(50);
152 sunxi_lcd_dsi_dcs_write_0para(sel, 0x11);
153 sunxi_lcd_delay_ms(50);
154 sunxi_lcd_dsi_dcs_write_0para(sel, 0x29);
155 sunxi_lcd_delay_ms(50);
156 }
157
LCD_panel_exit(u32 sel)158 static void LCD_panel_exit(u32 sel)
159 {
160 sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_SET_DISPLAY_OFF);
161 sunxi_lcd_delay_ms(50);
162 sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_ENTER_SLEEP_MODE);
163 sunxi_lcd_delay_ms(20);
164 panel_reset(0);
165 }
166
167 /* sel: 0:lcd0; 1:lcd1 */
LCD_user_defined_func(u32 sel,u32 para1,u32 para2,u32 para3)168 static s32 LCD_user_defined_func(u32 sel, u32 para1, u32 para2, u32 para3)
169 {
170 return 0;
171 }
172
173 struct __lcd_panel dx0960be40a1_panel = {
174 /* panel driver name, must mach the lcd_drv_name in sys_config.fex */
175 .name = "dx0960be40a1",
176 .func = {
177 .cfg_panel_info = LCD_cfg_panel_info,
178 .cfg_open_flow = LCD_open_flow,
179 .cfg_close_flow = LCD_close_flow,
180 .lcd_user_defined_func = LCD_user_defined_func,
181 }
182 ,
183 };
184