]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/video/omap/lcd_2430sdp.c
Merge branch 'omap-fixes'
[linux-2.6-omap-h63xx.git] / drivers / video / omap / lcd_2430sdp.c
1 /*
2  * LCD panel support for the TI 2430SDP board
3  *
4  * Copyright (C) 2007 MontaVista
5  * Author: Hunyue Yau <hyau@mvista.com>
6  *
7  * Derived from drivers/video/omap/lcd-apollon.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/gpio.h>
28 #include <linux/i2c/twl4030.h>
29
30 #include <mach/mux.h>
31 #include <mach/omapfb.h>
32 #include <asm/mach-types.h>
33
34 #define SDP2430_LCD_PANEL_BACKLIGHT_GPIO        91
35 #define SDP2430_LCD_PANEL_ENABLE_GPIO           154
36 #define SDP3430_LCD_PANEL_BACKLIGHT_GPIO        24
37 #define SDP3430_LCD_PANEL_ENABLE_GPIO           28
38
39 static unsigned backlight_gpio;
40 static unsigned enable_gpio;
41
42 #define LCD_PIXCLOCK_MAX                5400 /* freq 5.4 MHz */
43 #define PM_RECEIVER             TWL4030_MODULE_PM_RECEIVER
44 #define ENABLE_VAUX2_DEDICATED  0x09
45 #define ENABLE_VAUX2_DEV_GRP    0x20
46 #define ENABLE_VAUX3_DEDICATED  0x03
47 #define ENABLE_VAUX3_DEV_GRP    0x20
48
49 #define ENABLE_VPLL2_DEDICATED          0x05
50 #define ENABLE_VPLL2_DEV_GRP            0xE0
51 #define TWL4030_VPLL2_DEV_GRP           0x33
52 #define TWL4030_VPLL2_DEDICATED         0x36
53
54 #define t2_out(c, r, v) twl4030_i2c_write_u8(c, r, v)
55
56
57 static int sdp2430_panel_init(struct lcd_panel *panel,
58                                 struct omapfb_device *fbdev)
59 {
60         if (machine_is_omap_3430sdp()) {
61                 enable_gpio    = SDP3430_LCD_PANEL_ENABLE_GPIO;
62                 backlight_gpio = SDP3430_LCD_PANEL_BACKLIGHT_GPIO;
63         } else {
64                 enable_gpio    = SDP2430_LCD_PANEL_ENABLE_GPIO;
65                 backlight_gpio = SDP2430_LCD_PANEL_BACKLIGHT_GPIO;
66         }
67
68         gpio_request(enable_gpio, "LCD enable");        /* LCD panel */
69         gpio_request(backlight_gpio, "LCD bl");         /* LCD backlight */
70         gpio_direction_output(enable_gpio, 0);
71         gpio_direction_output(backlight_gpio, 0);
72
73         return 0;
74 }
75
76 static void sdp2430_panel_cleanup(struct lcd_panel *panel)
77 {
78 }
79
80 static int sdp2430_panel_enable(struct lcd_panel *panel)
81 {
82         u8 ded_val, ded_reg;
83         u8 grp_val, grp_reg;
84
85         if (machine_is_omap_3430sdp()) {
86                 ded_reg = TWL4030_VAUX3_DEDICATED;
87                 ded_val = ENABLE_VAUX3_DEDICATED;
88                 grp_reg = TWL4030_VAUX3_DEV_GRP;
89                 grp_val = ENABLE_VAUX3_DEV_GRP;
90
91                 if (omap_rev() > OMAP3430_REV_ES1_0) {
92                         t2_out(PM_RECEIVER, ENABLE_VPLL2_DEDICATED,
93                                         TWL4030_VPLL2_DEDICATED);
94                         t2_out(PM_RECEIVER, ENABLE_VPLL2_DEV_GRP,
95                                         TWL4030_VPLL2_DEV_GRP);
96                 }
97         } else {
98                 ded_reg = TWL4030_VAUX2_DEDICATED;
99                 ded_val = ENABLE_VAUX2_DEDICATED;
100                 grp_reg = TWL4030_VAUX2_DEV_GRP;
101                 grp_val = ENABLE_VAUX2_DEV_GRP;
102         }
103                 
104         gpio_set_value(enable_gpio, 1);
105         gpio_set_value(backlight_gpio, 1);
106
107         if (0 != t2_out(PM_RECEIVER, ded_val, ded_reg))
108                 return -EIO;
109         if (0 != t2_out(PM_RECEIVER, grp_val, grp_reg))
110                 return -EIO;
111
112         return 0;
113 }
114
115 static void sdp2430_panel_disable(struct lcd_panel *panel)
116 {
117         gpio_set_value(enable_gpio, 0);
118         gpio_set_value(backlight_gpio, 0);
119         if (omap_rev() > OMAP3430_REV_ES1_0) {
120                 t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEDICATED);
121                 t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEV_GRP);
122                 mdelay(4);
123         }
124 }
125
126 static unsigned long sdp2430_panel_get_caps(struct lcd_panel *panel)
127 {
128         return 0;
129 }
130
131 struct lcd_panel sdp2430_panel = {
132         .name           = "sdp2430",
133         .config         = OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
134                           OMAP_LCDC_INV_HSYNC,
135
136         .bpp            = 16,
137         .data_lines     = 16,
138         .x_res          = 240,
139         .y_res          = 320,
140         .hsw            = 3,            /* hsync_len (4) - 1 */
141         .hfp            = 3,            /* right_margin (4) - 1 */
142         .hbp            = 39,           /* left_margin (40) - 1 */
143         .vsw            = 1,            /* vsync_len (2) - 1 */
144         .vfp            = 2,            /* lower_margin */
145         .vbp            = 7,            /* upper_margin (8) - 1 */
146
147         .pixel_clock    = LCD_PIXCLOCK_MAX,
148
149         .init           = sdp2430_panel_init,
150         .cleanup        = sdp2430_panel_cleanup,
151         .enable         = sdp2430_panel_enable,
152         .disable        = sdp2430_panel_disable,
153         .get_caps       = sdp2430_panel_get_caps,
154 };
155
156 static int sdp2430_panel_probe(struct platform_device *pdev)
157 {
158         omapfb_register_panel(&sdp2430_panel);
159         return 0;
160 }
161
162 static int sdp2430_panel_remove(struct platform_device *pdev)
163 {
164         return 0;
165 }
166
167 static int sdp2430_panel_suspend(struct platform_device *pdev, pm_message_t mesg)
168 {
169         return 0;
170 }
171
172 static int sdp2430_panel_resume(struct platform_device *pdev)
173 {
174         return 0;
175 }
176
177 struct platform_driver sdp2430_panel_driver = {
178         .probe          = sdp2430_panel_probe,
179         .remove         = sdp2430_panel_remove,
180         .suspend        = sdp2430_panel_suspend,
181         .resume         = sdp2430_panel_resume,
182         .driver         = {
183                 .name   = "sdp2430_lcd",
184                 .owner  = THIS_MODULE,
185         },
186 };
187
188 static int __init sdp2430_panel_drv_init(void)
189 {
190         return platform_driver_register(&sdp2430_panel_driver);
191 }
192
193 static void __exit sdp2430_panel_drv_exit(void)
194 {
195         platform_driver_unregister(&sdp2430_panel_driver);
196 }
197
198 module_init(sdp2430_panel_drv_init);
199 module_exit(sdp2430_panel_drv_exit);