omap: headers: Move remaining headers from include/mach to include/plat
[linux-2.6.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 <plat/mux.h>
31 #include <plat/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         gpio_free(backlight_gpio);
79         gpio_free(enable_gpio);
80 }
81
82 static int sdp2430_panel_enable(struct lcd_panel *panel)
83 {
84         u8 ded_val, ded_reg;
85         u8 grp_val, grp_reg;
86
87         if (machine_is_omap_3430sdp()) {
88                 ded_reg = TWL4030_VAUX3_DEDICATED;
89                 ded_val = ENABLE_VAUX3_DEDICATED;
90                 grp_reg = TWL4030_VAUX3_DEV_GRP;
91                 grp_val = ENABLE_VAUX3_DEV_GRP;
92
93                 if (omap_rev() > OMAP3430_REV_ES1_0) {
94                         t2_out(PM_RECEIVER, ENABLE_VPLL2_DEDICATED,
95                                         TWL4030_VPLL2_DEDICATED);
96                         t2_out(PM_RECEIVER, ENABLE_VPLL2_DEV_GRP,
97                                         TWL4030_VPLL2_DEV_GRP);
98                 }
99         } else {
100                 ded_reg = TWL4030_VAUX2_DEDICATED;
101                 ded_val = ENABLE_VAUX2_DEDICATED;
102                 grp_reg = TWL4030_VAUX2_DEV_GRP;
103                 grp_val = ENABLE_VAUX2_DEV_GRP;
104         }
105
106         gpio_set_value(enable_gpio, 1);
107         gpio_set_value(backlight_gpio, 1);
108
109         if (0 != t2_out(PM_RECEIVER, ded_val, ded_reg))
110                 return -EIO;
111         if (0 != t2_out(PM_RECEIVER, grp_val, grp_reg))
112                 return -EIO;
113
114         return 0;
115 }
116
117 static void sdp2430_panel_disable(struct lcd_panel *panel)
118 {
119         gpio_set_value(enable_gpio, 0);
120         gpio_set_value(backlight_gpio, 0);
121         if (omap_rev() > OMAP3430_REV_ES1_0) {
122                 t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEDICATED);
123                 t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEV_GRP);
124                 msleep(4);
125         }
126 }
127
128 static unsigned long sdp2430_panel_get_caps(struct lcd_panel *panel)
129 {
130         return 0;
131 }
132
133 struct lcd_panel sdp2430_panel = {
134         .name           = "sdp2430",
135         .config         = OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
136                           OMAP_LCDC_INV_HSYNC,
137
138         .bpp            = 16,
139         .data_lines     = 16,
140         .x_res          = 240,
141         .y_res          = 320,
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           = sdp2430_panel_init,
152         .cleanup        = sdp2430_panel_cleanup,
153         .enable         = sdp2430_panel_enable,
154         .disable        = sdp2430_panel_disable,
155         .get_caps       = sdp2430_panel_get_caps,
156 };
157
158 static int sdp2430_panel_probe(struct platform_device *pdev)
159 {
160         omapfb_register_panel(&sdp2430_panel);
161         return 0;
162 }
163
164 static int sdp2430_panel_remove(struct platform_device *pdev)
165 {
166         return 0;
167 }
168
169 static int sdp2430_panel_suspend(struct platform_device *pdev,
170                                         pm_message_t mesg)
171 {
172         return 0;
173 }
174
175 static int sdp2430_panel_resume(struct platform_device *pdev)
176 {
177         return 0;
178 }
179
180 struct platform_driver sdp2430_panel_driver = {
181         .probe          = sdp2430_panel_probe,
182         .remove         = sdp2430_panel_remove,
183         .suspend        = sdp2430_panel_suspend,
184         .resume         = sdp2430_panel_resume,
185         .driver         = {
186                 .name   = "sdp2430_lcd",
187                 .owner  = THIS_MODULE,
188         },
189 };
190
191 static int __init sdp2430_panel_drv_init(void)
192 {
193         return platform_driver_register(&sdp2430_panel_driver);
194 }
195
196 static void __exit sdp2430_panel_drv_exit(void)
197 {
198         platform_driver_unregister(&sdp2430_panel_driver);
199 }
200
201 module_init(sdp2430_panel_drv_init);
202 module_exit(sdp2430_panel_drv_exit);