GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / staging / msm / lcdc_toshiba_wvga_pt.c
blob864d7c18913d5cec88df5d0b64ffcab846850b6d
1 /* Copyright (c) 2009, Code Aurora Forum. All rights reserved.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
18 #include <linux/delay.h>
19 #include <linux/module.h>
20 #include <mach/gpio.h>
21 #include <mach/pmic.h>
22 #include "msm_fb.h"
24 #ifdef CONFIG_FB_MSM_TRY_MDDI_CATCH_LCDC_PRISM
25 #include "mddihosti.h"
26 #endif
28 static int spi_cs;
29 static int spi_sclk;
30 static int spi_mosi;
31 static int spi_miso;
33 struct toshiba_state_type{
34 boolean disp_initialized;
35 boolean display_on;
36 boolean disp_powered_up;
39 static struct toshiba_state_type toshiba_state = { 0 };
40 static struct msm_panel_common_pdata *lcdc_toshiba_pdata;
42 static void toshiba_spi_write_byte(char dc, uint8 data)
44 uint32 bit;
45 int bnum;
47 gpio_set_value(spi_sclk, 0); /* clk low */
48 /* dc: 0 for command, 1 for parameter */
49 gpio_set_value(spi_mosi, dc);
50 udelay(1); /* at least 20 ns */
51 gpio_set_value(spi_sclk, 1); /* clk high */
52 udelay(1); /* at least 20 ns */
53 bnum = 8; /* 8 data bits */
54 bit = 0x80;
55 while (bnum) {
56 gpio_set_value(spi_sclk, 0); /* clk low */
57 if (data & bit)
58 gpio_set_value(spi_mosi, 1);
59 else
60 gpio_set_value(spi_mosi, 0);
61 udelay(1);
62 gpio_set_value(spi_sclk, 1); /* clk high */
63 udelay(1);
64 bit >>= 1;
65 bnum--;
69 static void toshiba_spi_write(char cmd, uint32 data, int num)
71 char *bp;
73 gpio_set_value(spi_cs, 1); /* cs high */
75 /* command byte first */
76 toshiba_spi_write_byte(0, cmd);
78 /* followed by parameter bytes */
79 if (num) {
80 bp = (char *)&data;;
81 bp += (num - 1);
82 while (num) {
83 toshiba_spi_write_byte(1, *bp);
84 num--;
85 bp--;
89 gpio_set_value(spi_cs, 0); /* cs low */
90 udelay(1);
93 void toshiba_spi_read_bytes(char cmd, uint32 *data, int num)
95 uint32 dbit, bits;
96 int bnum;
98 gpio_set_value(spi_cs, 1); /* cs high */
100 /* command byte first */
101 toshiba_spi_write_byte(0, cmd);
103 if (num > 1) {
104 /* extra dc bit */
105 gpio_set_value(spi_sclk, 0); /* clk low */
106 udelay(1);
107 dbit = gpio_get_value(spi_miso);/* dc bit */
108 udelay(1);
109 gpio_set_value(spi_sclk, 1); /* clk high */
112 /* followed by data bytes */
113 bnum = num * 8; /* number of bits */
114 bits = 0;
115 while (bnum) {
116 bits <<= 1;
117 gpio_set_value(spi_sclk, 0); /* clk low */
118 udelay(1);
119 dbit = gpio_get_value(spi_miso);
120 udelay(1);
121 gpio_set_value(spi_sclk, 1); /* clk high */
122 bits |= dbit;
123 bnum--;
126 *data = bits;
128 udelay(1);
129 gpio_set_value(spi_cs, 0); /* cs low */
130 udelay(1);
133 static void spi_pin_assign(void)
135 /* Setting the Default GPIO's */
136 spi_sclk = *(lcdc_toshiba_pdata->gpio_num);
137 spi_cs = *(lcdc_toshiba_pdata->gpio_num + 1);
138 spi_mosi = *(lcdc_toshiba_pdata->gpio_num + 2);
139 spi_miso = *(lcdc_toshiba_pdata->gpio_num + 3);
142 static void toshiba_disp_powerup(void)
144 if (!toshiba_state.disp_powered_up && !toshiba_state.display_on) {
145 /* Reset the hardware first */
146 /* Include DAC power up implementation here */
147 toshiba_state.disp_powered_up = TRUE;
151 static void toshiba_disp_on(void)
153 uint32 data;
155 gpio_set_value(spi_cs, 0); /* low */
156 gpio_set_value(spi_sclk, 1); /* high */
157 gpio_set_value(spi_mosi, 0);
158 gpio_set_value(spi_miso, 0);
160 if (toshiba_state.disp_powered_up && !toshiba_state.display_on) {
161 toshiba_spi_write(0, 0, 0);
162 mdelay(7);
163 toshiba_spi_write(0, 0, 0);
164 mdelay(7);
165 toshiba_spi_write(0, 0, 0);
166 mdelay(7);
167 toshiba_spi_write(0xba, 0x11, 1);
168 toshiba_spi_write(0x36, 0x00, 1);
169 mdelay(1);
170 toshiba_spi_write(0x3a, 0x60, 1);
171 toshiba_spi_write(0xb1, 0x5d, 1);
172 mdelay(1);
173 toshiba_spi_write(0xb2, 0x33, 1);
174 toshiba_spi_write(0xb3, 0x22, 1);
175 mdelay(1);
176 toshiba_spi_write(0xb4, 0x02, 1);
177 toshiba_spi_write(0xb5, 0x1e, 1); /* vcs -- adjust brightness */
178 mdelay(1);
179 toshiba_spi_write(0xb6, 0x27, 1);
180 toshiba_spi_write(0xb7, 0x03, 1);
181 mdelay(1);
182 toshiba_spi_write(0xb9, 0x24, 1);
183 toshiba_spi_write(0xbd, 0xa1, 1);
184 mdelay(1);
185 toshiba_spi_write(0xbb, 0x00, 1);
186 toshiba_spi_write(0xbf, 0x01, 1);
187 mdelay(1);
188 toshiba_spi_write(0xbe, 0x00, 1);
189 toshiba_spi_write(0xc0, 0x11, 1);
190 mdelay(1);
191 toshiba_spi_write(0xc1, 0x11, 1);
192 toshiba_spi_write(0xc2, 0x11, 1);
193 mdelay(1);
194 toshiba_spi_write(0xc3, 0x3232, 2);
195 mdelay(1);
196 toshiba_spi_write(0xc4, 0x3232, 2);
197 mdelay(1);
198 toshiba_spi_write(0xc5, 0x3232, 2);
199 mdelay(1);
200 toshiba_spi_write(0xc6, 0x3232, 2);
201 mdelay(1);
202 toshiba_spi_write(0xc7, 0x6445, 2);
203 mdelay(1);
204 toshiba_spi_write(0xc8, 0x44, 1);
205 toshiba_spi_write(0xc9, 0x52, 1);
206 mdelay(1);
207 toshiba_spi_write(0xca, 0x00, 1);
208 mdelay(1);
209 toshiba_spi_write(0xec, 0x02a4, 2); /* 0x02a4 */
210 mdelay(1);
211 toshiba_spi_write(0xcf, 0x01, 1);
212 mdelay(1);
213 toshiba_spi_write(0xd0, 0xc003, 2); /* c003 */
214 mdelay(1);
215 toshiba_spi_write(0xd1, 0x01, 1);
216 mdelay(1);
217 toshiba_spi_write(0xd2, 0x0028, 2);
218 mdelay(1);
219 toshiba_spi_write(0xd3, 0x0028, 2);
220 mdelay(1);
221 toshiba_spi_write(0xd4, 0x26a4, 2);
222 mdelay(1);
223 toshiba_spi_write(0xd5, 0x20, 1);
224 mdelay(1);
225 toshiba_spi_write(0xef, 0x3200, 2);
226 mdelay(32);
227 toshiba_spi_write(0xbc, 0x80, 1); /* wvga pass through */
228 toshiba_spi_write(0x3b, 0x00, 1);
229 mdelay(1);
230 toshiba_spi_write(0xb0, 0x16, 1);
231 mdelay(1);
232 toshiba_spi_write(0xb8, 0xfff5, 2);
233 mdelay(1);
234 toshiba_spi_write(0x11, 0, 0);
235 mdelay(5);
236 toshiba_spi_write(0x29, 0, 0);
237 mdelay(5);
238 toshiba_state.display_on = TRUE;
241 data = 0;
242 toshiba_spi_read_bytes(0x04, &data, 3);
243 printk(KERN_INFO "toshiba_disp_on: id=%x\n", data);
247 static int lcdc_toshiba_panel_on(struct platform_device *pdev)
249 if (!toshiba_state.disp_initialized) {
250 /* Configure reset GPIO that drives DAC */
251 if (lcdc_toshiba_pdata->panel_config_gpio)
252 lcdc_toshiba_pdata->panel_config_gpio(1);
253 toshiba_disp_powerup();
254 toshiba_disp_on();
255 toshiba_state.disp_initialized = TRUE;
257 return 0;
260 static int lcdc_toshiba_panel_off(struct platform_device *pdev)
262 if (toshiba_state.disp_powered_up && toshiba_state.display_on) {
263 /* Main panel power off (Deep standby in) */
265 toshiba_spi_write(0x28, 0, 0); /* display off */
266 mdelay(1);
267 toshiba_spi_write(0xb8, 0x8002, 2); /* output control */
268 mdelay(1);
269 toshiba_spi_write(0x10, 0x00, 1); /* sleep mode in */
270 mdelay(85); /* wait 85 msec */
271 toshiba_spi_write(0xb0, 0x00, 1); /* deep standby in */
272 mdelay(1);
273 if (lcdc_toshiba_pdata->panel_config_gpio)
274 lcdc_toshiba_pdata->panel_config_gpio(0);
275 toshiba_state.display_on = FALSE;
276 toshiba_state.disp_initialized = FALSE;
278 return 0;
281 static void lcdc_toshiba_set_backlight(struct msm_fb_data_type *mfd)
283 int bl_level;
284 int ret = -EPERM;
286 bl_level = mfd->bl_level;
287 ret = pmic_set_led_intensity(LED_LCD, bl_level);
289 if (ret)
290 printk(KERN_WARNING "%s: can't set lcd backlight!\n",
291 __func__);
294 static int __init toshiba_probe(struct platform_device *pdev)
296 if (pdev->id == 0) {
297 lcdc_toshiba_pdata = pdev->dev.platform_data;
298 spi_pin_assign();
299 return 0;
301 msm_fb_add_device(pdev);
302 return 0;
305 static struct platform_driver this_driver = {
306 .probe = toshiba_probe,
307 .driver = {
308 .name = "lcdc_toshiba_wvga",
312 static struct msm_fb_panel_data toshiba_panel_data = {
313 .on = lcdc_toshiba_panel_on,
314 .off = lcdc_toshiba_panel_off,
315 .set_backlight = lcdc_toshiba_set_backlight,
318 static struct platform_device this_device = {
319 .name = "lcdc_toshiba_wvga",
320 .id = 1,
321 .dev = {
322 .platform_data = &toshiba_panel_data,
326 static int __init lcdc_toshiba_panel_init(void)
328 int ret;
329 struct msm_panel_info *pinfo;
330 #ifdef CONFIG_FB_MSM_TRY_MDDI_CATCH_LCDC_PRISM
331 if (mddi_get_client_id() != 0)
332 return 0;
334 ret = msm_fb_detect_client("lcdc_toshiba_wvga_pt");
335 if (ret)
336 return 0;
338 #endif
340 ret = platform_driver_register(&this_driver);
341 if (ret)
342 return ret;
344 pinfo = &toshiba_panel_data.panel_info;
345 pinfo->xres = 480;
346 pinfo->yres = 800;
347 pinfo->type = LCDC_PANEL;
348 pinfo->pdest = DISPLAY_1;
349 pinfo->wait_cycle = 0;
350 pinfo->bpp = 18;
351 pinfo->fb_num = 2;
352 /* 30Mhz mdp_lcdc_pclk and mdp_lcdc_pad_pcl */
353 pinfo->clk_rate = 27648000;
354 pinfo->bl_max = 15;
355 pinfo->bl_min = 1;
357 pinfo->lcdc.h_back_porch = 184; /* hsw = 8 + hbp=184 */
358 pinfo->lcdc.h_front_porch = 4;
359 pinfo->lcdc.h_pulse_width = 8;
360 pinfo->lcdc.v_back_porch = 2; /* vsw=1 + vbp = 2 */
361 pinfo->lcdc.v_front_porch = 3;
362 pinfo->lcdc.v_pulse_width = 1;
363 pinfo->lcdc.border_clr = 0; /* blk */
364 pinfo->lcdc.underflow_clr = 0xff; /* blue */
365 pinfo->lcdc.hsync_skew = 0;
367 ret = platform_device_register(&this_device);
368 if (ret)
369 platform_driver_unregister(&this_driver);
371 return ret;
374 device_initcall(lcdc_toshiba_panel_init);