1 /*
2  * LCD panel support for the TI LDP board
3  *
4  * Copyright (C) 2007 WindRiver
5  * Author: Stanley Miao <stanley.miao@windriver.com>
6  *
7  * Derived from drivers/video/omap/lcd-2430sdp.c
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; either version 2 of the License, or (at your
12  * option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  */
23 
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/delay.h>
27 #include <linux/i2c/twl.h>
28 
29 #include <mach/gpio.h>
30 #include <plat/mux.h>
31 #include <asm/mach-types.h>
32 
33 #include "omapfb.h"
34 
35 #define LCD_PANEL_BACKLIGHT_GPIO	(15 + OMAP_MAX_GPIO_LINES)
36 #define LCD_PANEL_ENABLE_GPIO		(7 + OMAP_MAX_GPIO_LINES)
37 
38 #define LCD_PANEL_RESET_GPIO		55
39 #define LCD_PANEL_QVGA_GPIO		56
40 
41 #ifdef CONFIG_FB_OMAP_LCD_VGA
42 #define LCD_XRES		480
43 #define LCD_YRES		640
44 #define LCD_PIXCLOCK_MAX	41700
45 #else
46 #define LCD_XRES		240
47 #define LCD_YRES		320
48 #define LCD_PIXCLOCK_MAX	185186
49 #endif
50 
51 #define PM_RECEIVER             TWL4030_MODULE_PM_RECEIVER
52 #define ENABLE_VAUX2_DEDICATED  0x09
53 #define ENABLE_VAUX2_DEV_GRP    0x20
54 #define ENABLE_VAUX3_DEDICATED	0x03
55 #define ENABLE_VAUX3_DEV_GRP	0x20
56 
57 #define ENABLE_VPLL2_DEDICATED          0x05
58 #define ENABLE_VPLL2_DEV_GRP            0xE0
59 #define TWL4030_VPLL2_DEV_GRP           0x33
60 #define TWL4030_VPLL2_DEDICATED         0x36
61 
62 #define t2_out(c, r, v) twl_i2c_write_u8(c, r, v)
63 
64 
ldp_panel_init(struct lcd_panel * panel,struct omapfb_device * fbdev)65 static int ldp_panel_init(struct lcd_panel *panel,
66 				struct omapfb_device *fbdev)
67 {
68 	gpio_request(LCD_PANEL_RESET_GPIO, "lcd reset");
69 	gpio_request(LCD_PANEL_QVGA_GPIO, "lcd qvga");
70 	gpio_request(LCD_PANEL_ENABLE_GPIO, "lcd panel");
71 	gpio_request(LCD_PANEL_BACKLIGHT_GPIO, "lcd backlight");
72 
73 	gpio_direction_output(LCD_PANEL_QVGA_GPIO, 0);
74 	gpio_direction_output(LCD_PANEL_RESET_GPIO, 0);
75 	gpio_direction_output(LCD_PANEL_ENABLE_GPIO, 0);
76 	gpio_direction_output(LCD_PANEL_BACKLIGHT_GPIO, 0);
77 
78 #ifdef CONFIG_FB_OMAP_LCD_VGA
79 	gpio_set_value(LCD_PANEL_QVGA_GPIO, 0);
80 #else
81 	gpio_set_value(LCD_PANEL_QVGA_GPIO, 1);
82 #endif
83 	gpio_set_value(LCD_PANEL_RESET_GPIO, 1);
84 
85 	return 0;
86 }
87 
ldp_panel_cleanup(struct lcd_panel * panel)88 static void ldp_panel_cleanup(struct lcd_panel *panel)
89 {
90 	gpio_free(LCD_PANEL_BACKLIGHT_GPIO);
91 	gpio_free(LCD_PANEL_ENABLE_GPIO);
92 	gpio_free(LCD_PANEL_QVGA_GPIO);
93 	gpio_free(LCD_PANEL_RESET_GPIO);
94 }
95 
ldp_panel_enable(struct lcd_panel * panel)96 static int ldp_panel_enable(struct lcd_panel *panel)
97 {
98 	if (0 != t2_out(PM_RECEIVER, ENABLE_VPLL2_DEDICATED,
99 			TWL4030_VPLL2_DEDICATED))
100 		return -EIO;
101 	if (0 != t2_out(PM_RECEIVER, ENABLE_VPLL2_DEV_GRP,
102 			TWL4030_VPLL2_DEV_GRP))
103 		return -EIO;
104 
105 	gpio_direction_output(LCD_PANEL_ENABLE_GPIO, 1);
106 	gpio_direction_output(LCD_PANEL_BACKLIGHT_GPIO, 1);
107 
108 	if (0 != t2_out(PM_RECEIVER, ENABLE_VAUX3_DEDICATED,
109 				TWL4030_VAUX3_DEDICATED))
110 		return -EIO;
111 	if (0 != t2_out(PM_RECEIVER, ENABLE_VAUX3_DEV_GRP,
112 				TWL4030_VAUX3_DEV_GRP))
113 		return -EIO;
114 
115 	return 0;
116 }
117 
ldp_panel_disable(struct lcd_panel * panel)118 static void ldp_panel_disable(struct lcd_panel *panel)
119 {
120 	gpio_direction_output(LCD_PANEL_ENABLE_GPIO, 0);
121 	gpio_direction_output(LCD_PANEL_BACKLIGHT_GPIO, 0);
122 
123 	t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEDICATED);
124 	t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEV_GRP);
125 	msleep(4);
126 }
127 
ldp_panel_get_caps(struct lcd_panel * panel)128 static unsigned long ldp_panel_get_caps(struct lcd_panel *panel)
129 {
130 	return 0;
131 }
132 
133 struct lcd_panel ldp_panel = {
134 	.name		= "ldp",
135 	.config		= OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
136 			  OMAP_LCDC_INV_HSYNC,
137 
138 	.bpp		= 16,
139 	.data_lines	= 18,
140 	.x_res		= LCD_XRES,
141 	.y_res		= LCD_YRES,
142 	.hsw		= 3,		/* hsync_len (4) - 1 */
143 	.hfp		= 3,		/* right_margin (4) - 1 */
144 	.hbp		= 39,		/* left_margin (40) - 1 */
145 	.vsw		= 1,		/* vsync_len (2) - 1 */
146 	.vfp		= 2,		/* lower_margin */
147 	.vbp		= 7,		/* upper_margin (8) - 1 */
148 
149 	.pixel_clock	= LCD_PIXCLOCK_MAX,
150 
151 	.init		= ldp_panel_init,
152 	.cleanup	= ldp_panel_cleanup,
153 	.enable		= ldp_panel_enable,
154 	.disable	= ldp_panel_disable,
155 	.get_caps	= ldp_panel_get_caps,
156 };
157 
ldp_panel_probe(struct platform_device * pdev)158 static int ldp_panel_probe(struct platform_device *pdev)
159 {
160 	omapfb_register_panel(&ldp_panel);
161 	return 0;
162 }
163 
ldp_panel_remove(struct platform_device * pdev)164 static int ldp_panel_remove(struct platform_device *pdev)
165 {
166 	return 0;
167 }
168 
ldp_panel_suspend(struct platform_device * pdev,pm_message_t mesg)169 static int ldp_panel_suspend(struct platform_device *pdev, pm_message_t mesg)
170 {
171 	return 0;
172 }
173 
ldp_panel_resume(struct platform_device * pdev)174 static int ldp_panel_resume(struct platform_device *pdev)
175 {
176 	return 0;
177 }
178 
179 struct platform_driver ldp_panel_driver = {
180 	.probe		= ldp_panel_probe,
181 	.remove		= ldp_panel_remove,
182 	.suspend	= ldp_panel_suspend,
183 	.resume		= ldp_panel_resume,
184 	.driver		= {
185 		.name	= "ldp_lcd",
186 		.owner	= THIS_MODULE,
187 	},
188 };
189 
ldp_panel_drv_init(void)190 static int __init ldp_panel_drv_init(void)
191 {
192 	return platform_driver_register(&ldp_panel_driver);
193 }
194 
ldp_panel_drv_exit(void)195 static void __exit ldp_panel_drv_exit(void)
196 {
197 	platform_driver_unregister(&ldp_panel_driver);
198 }
199 
200 module_init(ldp_panel_drv_init);
201 module_exit(ldp_panel_drv_exit);
202