• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * drivers/video/fbdev/sunxi/disp2/disp/lcd/fx070/fx070.c
3  *
4  * Copyright (c) 2007-2018 Allwinnertech Co., Ltd.
5  * Author: zhengxiaobin <zhengxiaobin@allwinnertech.com>
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  */
17 #include "fx070.h"
18 
19 static void LCD_power_on(u32 sel);
20 static void LCD_power_off(u32 sel);
21 static void LCD_bl_open(u32 sel);
22 static void LCD_bl_close(u32 sel);
23 
24 static void LCD_panel_init(u32 sel);
25 static void LCD_panel_exit(u32 sel);
26 
LCD_cfg_panel_info(struct panel_extend_para * info)27 static void LCD_cfg_panel_info(struct panel_extend_para *info)
28 {
29 	u32 i = 0, j = 0;
30 	u32 items;
31 	u8 lcd_gamma_tbl[][2] = {
32 	    /*{input value, corrected value} */
33 	    {0, 0},     {15, 15},   {30, 30},   {45, 45},   {60, 60},
34 	    {75, 75},   {90, 90},   {105, 105}, {120, 120}, {135, 135},
35 	    {150, 150}, {165, 165}, {180, 180}, {195, 195}, {210, 210},
36 	    {225, 225}, {240, 240}, {255, 255},
37 	};
38 
39 	u32 lcd_cmap_tbl[2][3][4] = {
40 	    {
41 		{LCD_CMAP_G0, LCD_CMAP_B1, LCD_CMAP_G2, LCD_CMAP_B3},
42 		{LCD_CMAP_B0, LCD_CMAP_R1, LCD_CMAP_B2, LCD_CMAP_R3},
43 		{LCD_CMAP_R0, LCD_CMAP_G1, LCD_CMAP_R2, LCD_CMAP_G3},
44 	    },
45 	    {
46 		{LCD_CMAP_B3, LCD_CMAP_G2, LCD_CMAP_B1, LCD_CMAP_G0},
47 		{LCD_CMAP_R3, LCD_CMAP_B2, LCD_CMAP_R1, LCD_CMAP_B0},
48 		{LCD_CMAP_G3, LCD_CMAP_R2, LCD_CMAP_G1, LCD_CMAP_R0},
49 	    },
50 	};
51 
52 	items = sizeof(lcd_gamma_tbl) / 2;
53 	for (i = 0; i < items - 1; i++) {
54 		u32 num = lcd_gamma_tbl[i + 1][0] - lcd_gamma_tbl[i][0];
55 
56 		for (j = 0; j < num; j++) {
57 			u32 value = 0;
58 
59 			value =
60 			    lcd_gamma_tbl[i][1] +
61 			    ((lcd_gamma_tbl[i + 1][1] - lcd_gamma_tbl[i][1]) *
62 			     j) /
63 				num;
64 			info->lcd_gamma_tbl[lcd_gamma_tbl[i][0] + j] =
65 			    (value << 16) + (value << 8) + value;
66 		}
67 	}
68 	info->lcd_gamma_tbl[255] = (lcd_gamma_tbl[items - 1][1] << 16) +
69 				   (lcd_gamma_tbl[items - 1][1] << 8) +
70 				   lcd_gamma_tbl[items - 1][1];
71 
72 	memcpy(info->lcd_cmap_tbl, lcd_cmap_tbl, sizeof(lcd_cmap_tbl));
73 }
74 
LCD_open_flow(u32 sel)75 static s32 LCD_open_flow(u32 sel)
76 {
77 	/* open lcd power, and delay 50ms */
78 	LCD_OPEN_FUNC(sel, LCD_power_on, 40);
79 	/* open lcd power, than delay 200ms */
80 	LCD_OPEN_FUNC(sel, LCD_panel_init, 0);
81 	/* open lcd controller, and delay 100ms */
82 	LCD_OPEN_FUNC(sel, sunxi_lcd_tcon_enable, 200);
83 	/* open lcd backlight, and delay 0ms */
84 	LCD_OPEN_FUNC(sel, LCD_bl_open, 0);
85 
86 	return 0;
87 }
88 
LCD_close_flow(u32 sel)89 static s32 LCD_close_flow(u32 sel)
90 {
91 	/*close lcd backlight, and delay 0ms */
92 	LCD_CLOSE_FUNC(sel, LCD_bl_close, 200);
93 	/*close lcd controller, and delay 0ms */
94 	LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 10);
95 	/*open lcd power, than delay 200ms */
96 	LCD_CLOSE_FUNC(sel, LCD_panel_exit, 0);
97 	/*close lcd power, and delay 500ms */
98 	LCD_CLOSE_FUNC(sel, LCD_power_off, 0);
99 
100 	return 0;
101 }
102 
LCD_power_on(u32 sel)103 static void LCD_power_on(u32 sel)
104 {
105 	/*config lcd_power pin to open lcd power0 */
106 	sunxi_lcd_power_enable(sel, 0);
107 	sunxi_lcd_pin_cfg(sel, 1);
108 }
109 
LCD_power_off(u32 sel)110 static void LCD_power_off(u32 sel)
111 {
112 	sunxi_lcd_pin_cfg(sel, 0);
113 	/*config lcd_power pin to close lcd power0 */
114 	sunxi_lcd_power_disable(sel, 0);
115 }
116 
LCD_bl_open(u32 sel)117 static void LCD_bl_open(u32 sel)
118 {
119 	sunxi_lcd_pwm_enable(sel);
120 	/*config lcd_bl_en pin to open lcd backlight */
121 	sunxi_lcd_backlight_enable(sel);
122 }
123 
LCD_bl_close(u32 sel)124 static void LCD_bl_close(u32 sel)
125 {
126 	/*config lcd_bl_en pin to close lcd backlight */
127 	sunxi_lcd_backlight_disable(sel);
128 	sunxi_lcd_pwm_disable(sel);
129 }
130 
LCD_panel_init(u32 sel)131 static void LCD_panel_init(u32 sel)
132 {
133 	return;
134 }
135 
LCD_panel_exit(u32 sel)136 static void LCD_panel_exit(u32 sel)
137 {
138 	return ;
139 }
140 
141 /*sel: 0:lcd0; 1:lcd1 */
LCD_user_defined_func(u32 sel,u32 para1,u32 para2,u32 para3)142 static s32 LCD_user_defined_func(u32 sel, u32 para1, u32 para2, u32 para3)
143 {
144 	return 0;
145 }
146 
147 struct __lcd_panel fx070_panel = {
148 	/* panel driver name, must mach the name of lcd_drv_name
149 	 * in sys_config.fex */
150 	.name = "fx070",
151 	.func = {
152 		.cfg_panel_info = LCD_cfg_panel_info,
153 		.cfg_open_flow = LCD_open_flow,
154 		.cfg_close_flow = LCD_close_flow,
155 		.lcd_user_defined_func = LCD_user_defined_func,
156 	},
157 };
158