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 "default_panel.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
LCD_cfg_panel_info(struct panel_extend_para * info)21 static void LCD_cfg_panel_info(struct panel_extend_para *info)
22 {
23 u32 i = 0, j = 0;
24 u32 items;
25 u8 lcd_gamma_tbl[][2] = {
26 /* {input value, corrected value} */
27 {0, 0},
28 {15, 15},
29 {30, 30},
30 {45, 45},
31 {60, 60},
32 {75, 75},
33 {90, 90},
34 {105, 105},
35 {120, 120},
36 {135, 135},
37 {150, 150},
38 {165, 165},
39 {180, 180},
40 {195, 195},
41 {210, 210},
42 {225, 225},
43 {240, 240},
44 {255, 255},
45 };
46
47 u32 lcd_cmap_tbl[2][3][4] = {
48 {
49 {LCD_CMAP_G0, LCD_CMAP_B1, LCD_CMAP_G2, LCD_CMAP_B3},
50 {LCD_CMAP_B0, LCD_CMAP_R1, LCD_CMAP_B2, LCD_CMAP_R3},
51 {LCD_CMAP_R0, LCD_CMAP_G1, LCD_CMAP_R2, LCD_CMAP_G3},
52 },
53 {
54 {LCD_CMAP_B3, LCD_CMAP_G2, LCD_CMAP_B1, LCD_CMAP_G0},
55 {LCD_CMAP_R3, LCD_CMAP_B2, LCD_CMAP_R1, LCD_CMAP_B0},
56 {LCD_CMAP_G3, LCD_CMAP_R2, LCD_CMAP_G1, LCD_CMAP_R0},
57 },
58 };
59
60 items = sizeof(lcd_gamma_tbl) / 2;
61 for (i = 0; i < items - 1; i++) {
62 u32 num = lcd_gamma_tbl[i + 1][0] - lcd_gamma_tbl[i][0];
63
64 for (j = 0; j < num; j++) {
65 u32 value = 0;
66
67 value =
68 lcd_gamma_tbl[i][1] +
69 ((lcd_gamma_tbl[i + 1][1] -
70 lcd_gamma_tbl[i][1]) * j) / num;
71 info->lcd_gamma_tbl[lcd_gamma_tbl[i][0] + j] =
72 (value << 16) + (value << 8) + value;
73 }
74 }
75 info->lcd_gamma_tbl[255] =
76 (lcd_gamma_tbl[items - 1][1] << 16) +
77 (lcd_gamma_tbl[items - 1][1] << 8) + lcd_gamma_tbl[items - 1][1];
78
79 memcpy(info->lcd_cmap_tbl, lcd_cmap_tbl, sizeof(lcd_cmap_tbl));
80
81 }
82
LCD_open_flow(u32 sel)83 static s32 LCD_open_flow(u32 sel)
84 {
85 /* open lcd power, and delay 50ms */
86 LCD_OPEN_FUNC(sel, LCD_power_on, 30);
87 /* open lcd power, than delay 200ms */
88 LCD_OPEN_FUNC(sel, LCD_panel_init, 50);
89 /* open lcd controller, and delay 100ms */
90 LCD_OPEN_FUNC(sel, sunxi_lcd_tcon_enable, 100);
91 /* open lcd backlight, and delay 0ms */
92 LCD_OPEN_FUNC(sel, LCD_bl_open, 0);
93
94 return 0;
95 }
96
LCD_close_flow(u32 sel)97 static s32 LCD_close_flow(u32 sel)
98 {
99 /* close lcd backlight, and delay 0ms */
100 LCD_CLOSE_FUNC(sel, LCD_bl_close, 0);
101 /* close lcd controller, and delay 0ms */
102 LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 0);
103 /* open lcd power, than delay 200ms */
104 LCD_CLOSE_FUNC(sel, LCD_panel_exit, 200);
105 /* close lcd power, and delay 500ms */
106 LCD_CLOSE_FUNC(sel, LCD_power_off, 500);
107
108 return 0;
109 }
110
LCD_power_on(u32 sel)111 static void LCD_power_on(u32 sel)
112 {
113 /* config lcd_power pin to open lcd power0 */
114 sunxi_lcd_power_enable(sel, 0);
115 sunxi_lcd_pin_cfg(sel, 1);
116 }
117
LCD_power_off(u32 sel)118 static void LCD_power_off(u32 sel)
119 {
120 sunxi_lcd_pin_cfg(sel, 0);
121 /* config lcd_power pin to close lcd power0 */
122 sunxi_lcd_power_disable(sel, 0);
123 }
124
LCD_bl_open(u32 sel)125 static void LCD_bl_open(u32 sel)
126 {
127 sunxi_lcd_pwm_enable(sel);
128 sunxi_lcd_backlight_enable(sel);
129 }
130
LCD_bl_close(u32 sel)131 static void LCD_bl_close(u32 sel)
132 {
133 /* config lcd_bl_en pin to close lcd backlight */
134 sunxi_lcd_backlight_disable(sel);
135 sunxi_lcd_pwm_disable(sel);
136 }
137
LCD_panel_init(u32 sel)138 static void LCD_panel_init(u32 sel)
139 {
140 }
141
LCD_panel_exit(u32 sel)142 static void LCD_panel_exit(u32 sel)
143 {
144 }
145
146 /* sel: 0:lcd0; 1:lcd1 */
LCD_user_defined_func(u32 sel,u32 para1,u32 para2,u32 para3)147 static s32 LCD_user_defined_func(u32 sel, u32 para1, u32 para2, u32 para3)
148 {
149 return 0;
150 }
151
152 struct __lcd_panel default_panel = {
153 /* panel driver name, must mach the lcd_drv_name in sys_config.fex */
154 .name = "default_lcd",
155 .func = {
156 .cfg_panel_info = LCD_cfg_panel_info,
157 .cfg_open_flow = LCD_open_flow,
158 .cfg_close_flow = LCD_close_flow,
159 .lcd_user_defined_func = LCD_user_defined_func,
160 }
161 ,
162 };
163