]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/video/omap/lcd_sx1.c
FB: Add support for OMAP framebuffer
[linux-2.6-omap-h63xx.git] / drivers / video / omap / lcd_sx1.c
1 /*
2  * File: drivers/video/omap/lcd_sx1.c
3  *
4  * LCD panel support for the Siemens SX1 mobile phone
5  *
6  * Current version : Vovan888 at gmail com, great help from FCA00000
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation; either version 2 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  */
22
23 #include <linux/module.h>
24 #include <linux/platform_device.h>
25 #include <linux/delay.h>
26 #include <asm/io.h>
27 #include <asm/arch/gpio.h>
28 #include <asm/arch/omapfb.h>
29 #include <asm/arch/mcbsp.h>
30 #include <asm/arch/mux.h>
31
32 /*
33  * OMAP310 GPIO registers
34  */
35 #define GPIO_DATA_INPUT         0xfffce000
36 #define GPIO_DATA_OUTPUT        0xfffce004
37 #define GPIO_DIR_CONTROL        0xfffce008
38 #define GPIO_INT_CONTROL        0xfffce00c
39 #define GPIO_INT_MASK           0xfffce010
40 #define GPIO_INT_STATUS         0xfffce014
41 #define GPIO_PIN_CONTROL        0xfffce018
42
43
44 #define A_LCD_SSC_RD    3
45 #define A_LCD_SSC_SD    7
46 #define _A_LCD_RESET    9
47 #define _A_LCD_SSC_CS   12
48 #define _A_LCD_SSC_A0   13
49
50 #define DSP_REG         0xE1017024
51
52 const unsigned char INIT_1[12] = {
53         0x1C, 0x02, 0x88, 0x00, 0x1E, 0xE0, 0x00, 0xDC, 0x00, 0x02, 0x00
54 };
55
56 const unsigned char INIT_2[127] = {
57         0x15, 0x00, 0x29, 0x00, 0x3E, 0x00, 0x51, 0x00, 0x65, 0x00, 0x7A, 0x00, 0x8D, 0x00, 0xA1, 0x00,
58         0xB6, 0x00, 0xC7, 0x00, 0xD8, 0x00, 0xEB, 0x00, 0xFB, 0x00, 0x0B, 0x01, 0x1B, 0x01, 0x27, 0x01,
59         0x34, 0x01, 0x41, 0x01, 0x4C, 0x01, 0x55, 0x01, 0x5F, 0x01, 0x68, 0x01, 0x70, 0x01, 0x78, 0x01,
60         0x7E, 0x01, 0x86, 0x01, 0x8C, 0x01, 0x94, 0x01, 0x9B, 0x01, 0xA1, 0x01, 0xA4, 0x01, 0xA9, 0x01,
61         0xAD, 0x01, 0xB2, 0x01, 0xB7, 0x01, 0xBC, 0x01, 0xC0, 0x01, 0xC4, 0x01, 0xC8, 0x01, 0xCB, 0x01,
62         0xCF, 0x01, 0xD2, 0x01, 0xD5, 0x01, 0xD8, 0x01, 0xDB, 0x01, 0xE0, 0x01, 0xE3, 0x01, 0xE6, 0x01,
63         0xE8, 0x01, 0xEB, 0x01, 0xEE, 0x01, 0xF1, 0x01, 0xF3, 0x01, 0xF8, 0x01, 0xF9, 0x01, 0xFC, 0x01,
64         0x00, 0x02, 0x03, 0x02, 0x07, 0x02, 0x09, 0x02, 0x0E, 0x02, 0x13, 0x02, 0x1C, 0x02, 0x00
65 };
66
67 const unsigned char INIT_3[15] = {
68         0x14, 0x26, 0x33, 0x3D, 0x45, 0x4D, 0x53, 0x59,
69         0x5E, 0x63, 0x67, 0x6D, 0x71, 0x78, 0xFF
70 };
71
72 static void epson_sendbyte(int flag, unsigned char byte)
73 {
74         int i, shifter = 0x80;
75
76         if (!flag)
77                 omap_set_gpio_dataout(_A_LCD_SSC_A0, 0);
78         mdelay(2);
79         omap_set_gpio_dataout(A_LCD_SSC_RD, 1);
80
81         omap_set_gpio_dataout(A_LCD_SSC_SD, flag);
82
83         OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2200);
84         OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2202);
85         for (i = 0; i < 8; i++) {
86                 OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2200);
87                 omap_set_gpio_dataout(A_LCD_SSC_SD, shifter & byte);
88                 OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2202);
89                 shifter >>= 1;
90         }
91         omap_set_gpio_dataout(_A_LCD_SSC_A0, 1);
92 }
93
94 static void init_system(void)
95 {
96         omap_mcbsp_request(OMAP_MCBSP3);
97         omap_mcbsp_stop(OMAP_MCBSP3);
98 }
99
100 static void setup_GPIO(void)
101 {
102         /* new wave */
103         omap_request_gpio(A_LCD_SSC_RD);
104         omap_request_gpio(A_LCD_SSC_SD);
105         omap_request_gpio(_A_LCD_RESET);
106         omap_request_gpio(_A_LCD_SSC_CS);
107         omap_request_gpio(_A_LCD_SSC_A0);
108
109         /* set all GPIOs to output */
110         omap_set_gpio_direction(A_LCD_SSC_RD, 0);
111         omap_set_gpio_direction(A_LCD_SSC_SD, 0);
112         omap_set_gpio_direction(_A_LCD_RESET, 0);
113         omap_set_gpio_direction(_A_LCD_SSC_CS, 0);
114         omap_set_gpio_direction(_A_LCD_SSC_A0, 0);
115
116         /* set GPIO data */
117         omap_set_gpio_dataout(A_LCD_SSC_RD, 1);
118         omap_set_gpio_dataout(A_LCD_SSC_SD, 0);
119         omap_set_gpio_dataout(_A_LCD_RESET, 0);
120         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
121         omap_set_gpio_dataout(_A_LCD_SSC_A0, 1);
122 }
123
124 static void display_init(void)
125 {
126         int i;
127
128         omap_cfg_reg(MCBSP3_CLKX);
129
130         mdelay(2);
131         setup_GPIO();
132         mdelay(2);
133
134         /* reset LCD */
135         omap_set_gpio_dataout(A_LCD_SSC_SD, 1);
136         epson_sendbyte(0, 0x25);
137
138         omap_set_gpio_dataout(_A_LCD_RESET, 0);
139         mdelay(10);
140         omap_set_gpio_dataout(_A_LCD_RESET, 1);
141
142         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
143         mdelay(2);
144         omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
145
146         /* init LCD, phase 1 */
147         epson_sendbyte(0, 0xCA);
148         for (i = 0; i < 10; i++)
149                 epson_sendbyte(1, INIT_1[i]);
150         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
151         omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
152
153         /* init LCD phase 2 */
154         epson_sendbyte(0, 0xCB);
155         for( i = 0; i < 125; i++)
156                 epson_sendbyte(1, INIT_2[i]);
157         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
158         omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
159
160         /* init LCD phase 2a */
161         epson_sendbyte(0, 0xCC);
162         for( i = 0; i < 14; i++)
163                 epson_sendbyte(1, INIT_3[i]);
164         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
165         omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
166
167         /* init LCD phase 3 */
168         epson_sendbyte(0, 0xBC);
169         epson_sendbyte(1, 0x08);
170         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
171         omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
172
173         /* init LCD phase 4 */
174         epson_sendbyte(0, 0x07);
175         epson_sendbyte(1, 0x05);
176         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
177         omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
178
179         /* init LCD phase 5 */
180         epson_sendbyte(0, 0x94);
181         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
182         omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
183
184         /* init LCD phase 6 */
185         epson_sendbyte(0, 0xC6);
186         epson_sendbyte(1, 0x80);
187         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
188         mdelay(100); /* used to be 1000 */
189         omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
190
191         /* init LCD phase 7 */
192         epson_sendbyte(0, 0x16);
193         epson_sendbyte(1, 0x02);
194         epson_sendbyte(1, 0x00);
195         epson_sendbyte(1, 0xB1);
196         epson_sendbyte(1, 0x00);
197         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
198         omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
199
200         /* init LCD phase 8 */
201         epson_sendbyte(0, 0x76);
202         epson_sendbyte(1, 0x00);
203         epson_sendbyte(1, 0x00);
204         epson_sendbyte(1, 0xDB);
205         epson_sendbyte(1, 0x00);
206         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
207         omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
208
209         /* init LCD phase 9 */
210         epson_sendbyte(0, 0xAF);
211         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
212 }
213
214 static int sx1_panel_init(struct lcd_panel *panel, struct omapfb_device *fbdev)
215 {
216         return 0;
217 }
218
219 static void sx1_panel_cleanup(struct lcd_panel *panel)
220 {
221 }
222
223 static void sx1_panel_disable(struct lcd_panel *panel)
224 {
225         printk(KERN_INFO "SX1: LCD panel disable\n");
226         sx1_setmmipower(0);
227         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
228
229         epson_sendbyte(0, 0x25);
230         omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
231
232         epson_sendbyte(0, 0xAE);
233         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
234         mdelay(100);
235         omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
236
237         epson_sendbyte(0, 0x95);
238         omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
239 }
240
241 static int sx1_panel_enable(struct lcd_panel *panel)
242 {
243 #if 0
244         sx1_panel_disable(); /* try to disable panel first, if we boot from Symbian */
245 #endif
246
247         printk(KERN_INFO "lcd_sx1: LCD panel enable\n");
248         init_system();
249         display_init();
250
251         sx1_setmmipower(1);
252         sx1_setbacklight(0x18);
253         sx1_setkeylight (0x06);
254         return 0;
255 }
256
257
258 static unsigned long sx1_panel_get_caps(struct lcd_panel *panel)
259 {
260         return 0;
261 }
262
263 struct lcd_panel sx1_panel = {
264         .name           = "sx1",
265         .config         = OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
266                           OMAP_LCDC_INV_HSYNC | OMAP_LCDC_INV_PIX_CLOCK |
267                           OMAP_LCDC_INV_OUTPUT_EN,
268
269         .x_res          = 176,
270         .y_res          = 220,
271         .data_lines     = 16,
272         .bpp            = 16,
273         .hsw            = 5,
274         .hfp            = 5,
275         .hbp            = 5,
276         .vsw            = 2,
277         .vfp            = 1,
278         .vbp            = 1,
279         .pixel_clock    = 1500,
280
281         .init           = sx1_panel_init,
282         .cleanup        = sx1_panel_cleanup,
283         .enable         = sx1_panel_enable,
284         .disable        = sx1_panel_disable,
285         .get_caps       = sx1_panel_get_caps,
286 };
287
288 static int sx1_panel_probe(struct platform_device *pdev)
289 {
290         omapfb_register_panel(&sx1_panel);
291         return 0;
292 }
293
294 static int sx1_panel_remove(struct platform_device *pdev)
295 {
296         return 0;
297 }
298
299 static int sx1_panel_suspend(struct platform_device *pdev, pm_message_t mesg)
300 {
301         return 0;
302 }
303
304 static int sx1_panel_resume(struct platform_device *pdev)
305 {
306         return 0;
307 }
308
309 struct platform_driver sx1_panel_driver = {
310         .probe          = sx1_panel_probe,
311         .remove         = sx1_panel_remove,
312         .suspend        = sx1_panel_suspend,
313         .resume         = sx1_panel_resume,
314         .driver = {
315                 .name   = "lcd_sx1",
316                 .owner  = THIS_MODULE,
317         },
318 };
319
320 static int sx1_panel_drv_init(void)
321 {
322         return platform_driver_register(&sx1_panel_driver);
323 }
324
325 static void sx1_panel_drv_cleanup(void)
326 {
327         platform_driver_unregister(&sx1_panel_driver);
328 }
329
330 module_init(sx1_panel_drv_init);
331 module_exit(sx1_panel_drv_cleanup);