Merge current mainline tree into linux-omap tree
[pandora-kernel.git] / drivers / video / omap / lcd_omap2evm.c
1 /*
2  * LCD panel support for the MISTRAL OMAP2EVM board
3  *
4  * Author: Arun C <arunedarath@mistralsolutions.com>
5  *
6  * Derived from drivers/video/omap/lcd_omap3evm.c
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/i2c/twl4030.h>
27
28 #include <mach/gpio.h>
29 #include <mach/mux.h>
30 #include <mach/omapfb.h>
31 #include <asm/mach-types.h>
32
33 #define LCD_PANEL_ENABLE_GPIO   154
34 #define LCD_PANEL_LR            128
35 #define LCD_PANEL_UD            129
36 #define LCD_PANEL_INI           152
37 #define LCD_PANEL_QVGA          148
38 #define LCD_PANEL_RESB          153
39
40 #define LCD_XRES                480
41 #define LCD_YRES                640
42 #define LCD_PIXCLOCK_MAX        20000 /* in kHz */
43
44 #define TWL_LED_LEDEN           0x00
45 #define TWL_PWMA_PWMAON         0x00
46 #define TWL_PWMA_PWMAOFF        0x01
47
48 static unsigned int bklight_level;
49
50 static int omap2evm_panel_init(struct lcd_panel *panel,
51                                 struct omapfb_device *fbdev)
52 {
53         omap_request_gpio(LCD_PANEL_ENABLE_GPIO);
54         omap_request_gpio(LCD_PANEL_LR);
55         omap_request_gpio(LCD_PANEL_UD);
56         omap_request_gpio(LCD_PANEL_INI);
57         omap_request_gpio(LCD_PANEL_QVGA);
58         omap_request_gpio(LCD_PANEL_RESB);
59
60         omap_set_gpio_direction(LCD_PANEL_ENABLE_GPIO, 0);
61         omap_set_gpio_direction(LCD_PANEL_LR, 0);
62         omap_set_gpio_direction(LCD_PANEL_UD, 0);
63         omap_set_gpio_direction(LCD_PANEL_INI, 0);
64         omap_set_gpio_direction(LCD_PANEL_QVGA, 0);
65         omap_set_gpio_direction(LCD_PANEL_RESB, 0);
66
67         omap_set_gpio_dataout(LCD_PANEL_RESB, 1);
68         omap_set_gpio_dataout(LCD_PANEL_INI, 1);
69         omap_set_gpio_dataout(LCD_PANEL_QVGA, 0);
70         omap_set_gpio_dataout(LCD_PANEL_LR, 1);
71         omap_set_gpio_dataout(LCD_PANEL_UD, 1);
72
73         twl4030_i2c_write_u8(TWL4030_MODULE_LED, 0x11, TWL_LED_LEDEN);
74         twl4030_i2c_write_u8(TWL4030_MODULE_PWMA, 0x01, TWL_PWMA_PWMAON);
75         twl4030_i2c_write_u8(TWL4030_MODULE_PWMA, 0x02, TWL_PWMA_PWMAOFF);
76         bklight_level = 100;
77
78         return 0;
79 }
80
81 static void omap2evm_panel_cleanup(struct lcd_panel *panel)
82 {
83 }
84
85 static int omap2evm_panel_enable(struct lcd_panel *panel)
86 {
87         omap_set_gpio_dataout(LCD_PANEL_ENABLE_GPIO, 0);
88         return 0;
89 }
90
91 static void omap2evm_panel_disable(struct lcd_panel *panel)
92 {
93         omap_set_gpio_dataout(LCD_PANEL_ENABLE_GPIO, 1);
94 }
95
96 static unsigned long omap2evm_panel_get_caps(struct lcd_panel *panel)
97 {
98         return 0;
99 }
100
101 static int omap2evm_bklight_setlevel(struct lcd_panel *panel,
102                                                 unsigned int level)
103 {
104         u8 c;
105         if ((level >= 0) && (level <= 100)) {
106                 c = (125 * (100 - level)) / 100 + 2;
107                 twl4030_i2c_write_u8(TWL4030_MODULE_PWMA, c, TWL_PWMA_PWMAOFF);
108                 bklight_level = level;
109         }
110         return 0;
111 }
112
113 static unsigned int omap2evm_bklight_getlevel(struct lcd_panel *panel)
114 {
115         return bklight_level;
116 }
117
118 static unsigned int omap2evm_bklight_getmaxlevel(struct lcd_panel *panel)
119 {
120         return 100;
121 }
122
123 struct lcd_panel omap2evm_panel = {
124         .name           = "omap2evm",
125         .config         = OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
126                           OMAP_LCDC_INV_HSYNC,
127
128         .bpp            = 16,
129         .data_lines     = 18,
130         .x_res          = LCD_XRES,
131         .y_res          = LCD_YRES,
132         .hsw            = 3,
133         .hfp            = 0,
134         .hbp            = 28,
135         .vsw            = 2,
136         .vfp            = 1,
137         .vbp            = 0,
138
139         .pixel_clock    = LCD_PIXCLOCK_MAX,
140
141         .init           = omap2evm_panel_init,
142         .cleanup        = omap2evm_panel_cleanup,
143         .enable         = omap2evm_panel_enable,
144         .disable        = omap2evm_panel_disable,
145         .get_caps       = omap2evm_panel_get_caps,
146         .set_bklight_level      = omap2evm_bklight_setlevel,
147         .get_bklight_level      = omap2evm_bklight_getlevel,
148         .get_bklight_max        = omap2evm_bklight_getmaxlevel,
149 };
150
151 static int omap2evm_panel_probe(struct platform_device *pdev)
152 {
153         omapfb_register_panel(&omap2evm_panel);
154         return 0;
155 }
156
157 static int omap2evm_panel_remove(struct platform_device *pdev)
158 {
159         return 0;
160 }
161
162 static int omap2evm_panel_suspend(struct platform_device *pdev,
163                                    pm_message_t mesg)
164 {
165         return 0;
166 }
167
168 static int omap2evm_panel_resume(struct platform_device *pdev)
169 {
170         return 0;
171 }
172
173 struct platform_driver omap2evm_panel_driver = {
174         .probe          = omap2evm_panel_probe,
175         .remove         = omap2evm_panel_remove,
176         .suspend        = omap2evm_panel_suspend,
177         .resume         = omap2evm_panel_resume,
178         .driver         = {
179                 .name   = "omap2evm_lcd",
180                 .owner  = THIS_MODULE,
181         },
182 };
183
184 static int __init omap2evm_panel_drv_init(void)
185 {
186         return platform_driver_register(&omap2evm_panel_driver);
187 }
188
189 static void __exit omap2evm_panel_drv_exit(void)
190 {
191         platform_driver_unregister(&omap2evm_panel_driver);
192 }
193
194 module_init(omap2evm_panel_drv_init);
195 module_exit(omap2evm_panel_drv_exit);