2 * linux/drivers/video/w100fb.c
4 * Corgi/Spitz LCD Specific Code
6 * Copyright (C) 2005 Richard Purdie
9 * Corgi - LCD to ATI Imageon w100 (Wallaby)
10 * Spitz - LCD to PXA Framebuffer
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
18 #include <linux/delay.h>
19 #include <linux/kernel.h>
20 #include <linux/device.h>
21 #include <linux/module.h>
22 #include <asm/arch/akita.h>
23 #include <asm/arch/corgi.h>
24 #include <asm/arch/hardware.h>
25 #include <asm/arch/pxa-regs.h>
26 #include <asm/arch/sharpsl.h>
27 #include <asm/arch/spitz.h>
28 #include <asm/hardware/scoop.h>
29 #include <asm/mach/sharpsl_param.h>
32 /* Register Addresses */
33 #define RESCTL_ADRS 0x00
34 #define PHACTRL_ADRS 0x01
35 #define DUTYCTRL_ADRS 0x02
36 #define POWERREG0_ADRS 0x03
37 #define POWERREG1_ADRS 0x04
38 #define GPOR3_ADRS 0x05
39 #define PICTRL_ADRS 0x06
40 #define POLCTRL_ADRS 0x07
42 /* Resgister Bit Definitions */
43 #define RESCTL_QVGA 0x01
44 #define RESCTL_VGA 0x00
46 #define POWER1_VW_ON 0x01 /* VW Supply FET ON */
47 #define POWER1_GVSS_ON 0x02 /* GVSS(-8V) Power Supply ON */
48 #define POWER1_VDD_ON 0x04 /* VDD(8V),SVSS(-4V) Power Supply ON */
50 #define POWER1_VW_OFF 0x00 /* VW Supply FET OFF */
51 #define POWER1_GVSS_OFF 0x00 /* GVSS(-8V) Power Supply OFF */
52 #define POWER1_VDD_OFF 0x00 /* VDD(8V),SVSS(-4V) Power Supply OFF */
54 #define POWER0_COM_DCLK 0x01 /* COM Voltage DC Bias DAC Serial Data Clock */
55 #define POWER0_COM_DOUT 0x02 /* COM Voltage DC Bias DAC Serial Data Out */
56 #define POWER0_DAC_ON 0x04 /* DAC Power Supply ON */
57 #define POWER0_COM_ON 0x08 /* COM Powewr Supply ON */
58 #define POWER0_VCC5_ON 0x10 /* VCC5 Power Supply ON */
60 #define POWER0_DAC_OFF 0x00 /* DAC Power Supply OFF */
61 #define POWER0_COM_OFF 0x00 /* COM Powewr Supply OFF */
62 #define POWER0_VCC5_OFF 0x00 /* VCC5 Power Supply OFF */
64 #define PICTRL_INIT_STATE 0x01
65 #define PICTRL_INIOFF 0x02
66 #define PICTRL_POWER_DOWN 0x04
67 #define PICTRL_COM_SIGNAL_OFF 0x08
68 #define PICTRL_DAC_SIGNAL_OFF 0x10
70 #define POLCTRL_SYNC_POL_FALL 0x01
71 #define POLCTRL_EN_POL_FALL 0x02
72 #define POLCTRL_DATA_POL_FALL 0x04
73 #define POLCTRL_SYNC_ACT_H 0x08
74 #define POLCTRL_EN_ACT_L 0x10
76 #define POLCTRL_SYNC_POL_RISE 0x00
77 #define POLCTRL_EN_POL_RISE 0x00
78 #define POLCTRL_DATA_POL_RISE 0x00
79 #define POLCTRL_SYNC_ACT_L 0x00
80 #define POLCTRL_EN_ACT_H 0x00
82 #define PHACTRL_PHASE_MANUAL 0x01
83 #define DEFAULT_PHAD_QVGA (9)
84 #define DEFAULT_COMADJ (125)
87 * This is only a psuedo I2C interface. We can't use the standard kernel
88 * routines as the interface is write only. We just assume the data is acked...
90 static void lcdtg_ssp_i2c_send(u8 data
)
92 corgi_ssp_lcdtg_send(POWERREG0_ADRS
, data
);
96 static void lcdtg_i2c_send_bit(u8 data
)
98 lcdtg_ssp_i2c_send(data
);
99 lcdtg_ssp_i2c_send(data
| POWER0_COM_DCLK
);
100 lcdtg_ssp_i2c_send(data
);
103 static void lcdtg_i2c_send_start(u8 base
)
105 lcdtg_ssp_i2c_send(base
| POWER0_COM_DCLK
| POWER0_COM_DOUT
);
106 lcdtg_ssp_i2c_send(base
| POWER0_COM_DCLK
);
107 lcdtg_ssp_i2c_send(base
);
110 static void lcdtg_i2c_send_stop(u8 base
)
112 lcdtg_ssp_i2c_send(base
);
113 lcdtg_ssp_i2c_send(base
| POWER0_COM_DCLK
);
114 lcdtg_ssp_i2c_send(base
| POWER0_COM_DCLK
| POWER0_COM_DOUT
);
117 static void lcdtg_i2c_send_byte(u8 base
, u8 data
)
120 for (i
= 0; i
< 8; i
++) {
122 lcdtg_i2c_send_bit(base
| POWER0_COM_DOUT
);
124 lcdtg_i2c_send_bit(base
);
129 static void lcdtg_i2c_wait_ack(u8 base
)
131 lcdtg_i2c_send_bit(base
);
134 static void lcdtg_set_common_voltage(u8 base_data
, u8 data
)
136 /* Set Common Voltage to M62332FP via I2C */
137 lcdtg_i2c_send_start(base_data
);
138 lcdtg_i2c_send_byte(base_data
, 0x9c);
139 lcdtg_i2c_wait_ack(base_data
);
140 lcdtg_i2c_send_byte(base_data
, 0x00);
141 lcdtg_i2c_wait_ack(base_data
);
142 lcdtg_i2c_send_byte(base_data
, data
);
143 lcdtg_i2c_wait_ack(base_data
);
144 lcdtg_i2c_send_stop(base_data
);
147 /* Set Phase Adjuct */
148 static void lcdtg_set_phadadj(int mode
)
154 /* Setting for VGA */
155 adj
= sharpsl_param
.phadadj
;
157 adj
= PHACTRL_PHASE_MANUAL
;
159 adj
= ((adj
& 0x0f) << 1) | PHACTRL_PHASE_MANUAL
;
165 /* Setting for QVGA */
166 adj
= (DEFAULT_PHAD_QVGA
<< 1) | PHACTRL_PHASE_MANUAL
;
170 corgi_ssp_lcdtg_send(PHACTRL_ADRS
, adj
);
173 static int lcd_inited
;
175 static void lcdtg_hw_init(int mode
)
180 /* Initialize Internal Logic & Port */
181 corgi_ssp_lcdtg_send(PICTRL_ADRS
, PICTRL_POWER_DOWN
| PICTRL_INIOFF
| PICTRL_INIT_STATE
182 | PICTRL_COM_SIGNAL_OFF
| PICTRL_DAC_SIGNAL_OFF
);
184 corgi_ssp_lcdtg_send(POWERREG0_ADRS
, POWER0_COM_DCLK
| POWER0_COM_DOUT
| POWER0_DAC_OFF
185 | POWER0_COM_OFF
| POWER0_VCC5_OFF
);
187 corgi_ssp_lcdtg_send(POWERREG1_ADRS
, POWER1_VW_OFF
| POWER1_GVSS_OFF
| POWER1_VDD_OFF
);
189 /* VDD(+8V), SVSS(-4V) ON */
190 corgi_ssp_lcdtg_send(POWERREG1_ADRS
, POWER1_VW_OFF
| POWER1_GVSS_OFF
| POWER1_VDD_ON
);
194 corgi_ssp_lcdtg_send(POWERREG0_ADRS
, POWER0_COM_DCLK
| POWER0_COM_DOUT
| POWER0_DAC_ON
195 | POWER0_COM_OFF
| POWER0_VCC5_OFF
);
197 /* INIB = H, INI = L */
198 /* PICTL[0] = H , PICTL[1] = PICTL[2] = PICTL[4] = L */
199 corgi_ssp_lcdtg_send(PICTRL_ADRS
, PICTRL_INIT_STATE
| PICTRL_COM_SIGNAL_OFF
);
201 /* Set Common Voltage */
202 comadj
= sharpsl_param
.comadj
;
204 comadj
= DEFAULT_COMADJ
;
205 lcdtg_set_common_voltage((POWER0_DAC_ON
| POWER0_COM_OFF
| POWER0_VCC5_OFF
), comadj
);
207 /* VCC5 ON, DAC ON */
208 corgi_ssp_lcdtg_send(POWERREG0_ADRS
, POWER0_COM_DCLK
| POWER0_COM_DOUT
| POWER0_DAC_ON
|
209 POWER0_COM_OFF
| POWER0_VCC5_ON
);
211 /* GVSS(-8V) ON, VDD ON */
212 corgi_ssp_lcdtg_send(POWERREG1_ADRS
, POWER1_VW_OFF
| POWER1_GVSS_ON
| POWER1_VDD_ON
);
215 /* COM SIGNAL ON (PICTL[3] = L) */
216 corgi_ssp_lcdtg_send(PICTRL_ADRS
, PICTRL_INIT_STATE
);
218 /* COM ON, DAC ON, VCC5_ON */
219 corgi_ssp_lcdtg_send(POWERREG0_ADRS
, POWER0_COM_DCLK
| POWER0_COM_DOUT
| POWER0_DAC_ON
220 | POWER0_COM_ON
| POWER0_VCC5_ON
);
222 /* VW ON, GVSS ON, VDD ON */
223 corgi_ssp_lcdtg_send(POWERREG1_ADRS
, POWER1_VW_ON
| POWER1_GVSS_ON
| POWER1_VDD_ON
);
225 /* Signals output enable */
226 corgi_ssp_lcdtg_send(PICTRL_ADRS
, 0);
228 /* Set Phase Adjuct */
229 lcdtg_set_phadadj(mode
);
231 /* Initialize for Input Signals from ATI */
232 corgi_ssp_lcdtg_send(POLCTRL_ADRS
, POLCTRL_SYNC_POL_RISE
| POLCTRL_EN_POL_RISE
233 | POLCTRL_DATA_POL_RISE
| POLCTRL_SYNC_ACT_L
| POLCTRL_EN_ACT_H
);
238 lcdtg_set_phadadj(mode
);
244 /* Set Lcd Resolution (VGA) */
245 corgi_ssp_lcdtg_send(RESCTL_ADRS
, RESCTL_VGA
);
250 /* Set Lcd Resolution (QVGA) */
251 corgi_ssp_lcdtg_send(RESCTL_ADRS
, RESCTL_QVGA
);
256 static void lcdtg_suspend(void)
258 /* 60Hz x 2 frame = 16.7msec x 2 = 33.4 msec */
262 corgi_ssp_lcdtg_send(POWERREG1_ADRS
, POWER1_VW_OFF
| POWER1_GVSS_ON
| POWER1_VDD_ON
);
265 corgi_ssp_lcdtg_send(PICTRL_ADRS
, PICTRL_COM_SIGNAL_OFF
);
266 corgi_ssp_lcdtg_send(POWERREG0_ADRS
, POWER0_DAC_ON
| POWER0_COM_OFF
| POWER0_VCC5_ON
);
268 /* (3)Set Common Voltage Bias 0V */
269 lcdtg_set_common_voltage(POWER0_DAC_ON
| POWER0_COM_OFF
| POWER0_VCC5_ON
, 0);
272 corgi_ssp_lcdtg_send(POWERREG1_ADRS
, POWER1_VW_OFF
| POWER1_GVSS_OFF
| POWER1_VDD_ON
);
275 corgi_ssp_lcdtg_send(POWERREG0_ADRS
, POWER0_DAC_ON
| POWER0_COM_OFF
| POWER0_VCC5_OFF
);
277 /* (6)Set PDWN, INIOFF, DACOFF */
278 corgi_ssp_lcdtg_send(PICTRL_ADRS
, PICTRL_INIOFF
| PICTRL_DAC_SIGNAL_OFF
|
279 PICTRL_POWER_DOWN
| PICTRL_COM_SIGNAL_OFF
);
282 corgi_ssp_lcdtg_send(POWERREG0_ADRS
, POWER0_DAC_OFF
| POWER0_COM_OFF
| POWER0_VCC5_OFF
);
285 corgi_ssp_lcdtg_send(POWERREG1_ADRS
, POWER1_VW_OFF
| POWER1_GVSS_OFF
| POWER1_VDD_OFF
);
292 * Corgi w100 Frame Buffer Device
294 #ifdef CONFIG_PXA_SHARP_C7xx
296 #include <video/w100fb.h>
298 static void w100_lcdtg_suspend(struct w100fb_par
*par
)
303 static void w100_lcdtg_init(struct w100fb_par
*par
)
305 lcdtg_hw_init(par
->xres
);
309 static struct w100_tg_info corgi_lcdtg_info
= {
310 .change
= w100_lcdtg_init
,
311 .suspend
= w100_lcdtg_suspend
,
312 .resume
= w100_lcdtg_init
,
315 static struct w100_mem_info corgi_fb_mem
= {
316 .ext_cntl
= 0x00040003,
317 .sdram_mode_reg
= 0x00650021,
318 .ext_timing_cntl
= 0x10002a4a,
319 .io_cntl
= 0x7ff87012,
323 static struct w100_gen_regs corgi_fb_regs
= {
324 .lcd_format
= 0x00000003,
325 .lcdd_cntl1
= 0x01CC0000,
326 .lcdd_cntl2
= 0x0003FFFF,
327 .genlcd_cntl1
= 0x00FFFF0D,
328 .genlcd_cntl2
= 0x003F3003,
329 .genlcd_cntl3
= 0x000102aa,
332 static struct w100_gpio_regs corgi_fb_gpio
= {
333 .init_data1
= 0x000000bf,
334 .init_data2
= 0x00000000,
335 .gpio_dir1
= 0x00000000,
336 .gpio_oe1
= 0x03c0feff,
337 .gpio_dir2
= 0x00000000,
338 .gpio_oe2
= 0x00000000,
341 static struct w100_mode corgi_fb_modes
[] = {
346 .right_margin
= 0x55,
347 .upper_margin
= 0x03,
348 .lower_margin
= 0x00,
349 .crtc_ss
= 0x82360056,
350 .crtc_ls
= 0xA0280000,
351 .crtc_gs
= 0x80280028,
352 .crtc_vpos_gs
= 0x02830002,
353 .crtc_rev
= 0x00400008,
354 .crtc_dclk
= 0xA0000000,
355 .crtc_gclk
= 0x8015010F,
356 .crtc_goe
= 0x80100110,
357 .crtc_ps1_active
= 0x41060010,
359 .fast_pll_freq
= 100,
360 .sysclk_src
= CLK_SRC_PLL
,
362 .pixclk_src
= CLK_SRC_PLL
,
364 .pixclk_divider_rotated
= 6,
369 .right_margin
= 0x2e,
370 .upper_margin
= 0x01,
371 .lower_margin
= 0x00,
372 .crtc_ss
= 0x81170027,
373 .crtc_ls
= 0xA0140000,
374 .crtc_gs
= 0xC0140014,
375 .crtc_vpos_gs
= 0x00010141,
376 .crtc_rev
= 0x00400008,
377 .crtc_dclk
= 0xA0000000,
378 .crtc_gclk
= 0x8015010F,
379 .crtc_goe
= 0x80100110,
380 .crtc_ps1_active
= 0x41060010,
383 .sysclk_src
= CLK_SRC_XTAL
,
385 .pixclk_src
= CLK_SRC_XTAL
,
387 .pixclk_divider_rotated
= 1,
392 static struct w100fb_mach_info corgi_fb_info
= {
393 .tg
= &corgi_lcdtg_info
,
394 .init_mode
= INIT_MODE_ROTATED
,
395 .mem
= &corgi_fb_mem
,
396 .regs
= &corgi_fb_regs
,
397 .modelist
= &corgi_fb_modes
[0],
399 .gpio
= &corgi_fb_gpio
,
400 .xtal_freq
= 12500000,
404 static struct resource corgi_fb_resources
[] = {
408 .flags
= IORESOURCE_MEM
,
412 struct platform_device corgifb_device
= {
415 .num_resources
= ARRAY_SIZE(corgi_fb_resources
),
416 .resource
= corgi_fb_resources
,
418 .platform_data
= &corgi_fb_info
,
419 .parent
= &corgissp_device
.dev
,
427 * Spitz PXA Frame Buffer Device
429 #ifdef CONFIG_PXA_SHARP_Cxx00
431 #include <asm/arch/pxafb.h>
433 void spitz_lcd_power(int on
)
445 * Corgi/Spitz Touchscreen to LCD interface
447 static unsigned long (*get_hsync_time
)(struct device
*dev
);
449 static void inline sharpsl_wait_sync(int gpio
)
451 while((GPLR(gpio
) & GPIO_bit(gpio
)) == 0);
452 while((GPLR(gpio
) & GPIO_bit(gpio
)) != 0);
455 #ifdef CONFIG_PXA_SHARP_C7xx
456 unsigned long corgi_get_hsync_len(void)
459 get_hsync_time
= symbol_get(w100fb_get_hsynclen
);
463 return get_hsync_time(&corgifb_device
.dev
);
466 void corgi_put_hsync(void)
469 symbol_put(w100fb_get_hsynclen
);
470 get_hsync_time
= NULL
;
473 void corgi_wait_hsync(void)
475 sharpsl_wait_sync(CORGI_GPIO_HSYNC
);
479 #ifdef CONFIG_PXA_SHARP_Cxx00
480 static struct device
*spitz_pxafb_dev
;
482 static int is_pxafb_device(struct device
* dev
, void * data
)
484 struct platform_device
*pdev
= container_of(dev
, struct platform_device
, dev
);
486 return (strncmp(pdev
->name
, "pxa2xx-fb", 9) == 0);
489 unsigned long spitz_get_hsync_len(void)
492 if (!spitz_pxafb_dev
) {
493 spitz_pxafb_dev
= bus_find_device(&platform_bus_type
, NULL
, NULL
, is_pxafb_device
);
494 if (!spitz_pxafb_dev
)
498 get_hsync_time
= symbol_get(pxafb_get_hsync_time
);
503 return pxafb_get_hsync_time(spitz_pxafb_dev
);
506 void spitz_put_hsync(void)
508 put_device(spitz_pxafb_dev
);
510 symbol_put(pxafb_get_hsync_time
);
511 spitz_pxafb_dev
= NULL
;
512 get_hsync_time
= NULL
;
515 void spitz_wait_hsync(void)
517 sharpsl_wait_sync(SPITZ_GPIO_HSYNC
);
522 * Corgi/Spitz Backlight Power
524 #ifdef CONFIG_PXA_SHARP_C7xx
525 void corgi_bl_set_intensity(int intensity
)
527 if (intensity
> 0x10)
530 /* Bits 0-4 are accessed via the SSP interface */
531 corgi_ssp_blduty_set(intensity
& 0x1f);
533 /* Bit 5 is via SCOOP */
534 if (intensity
& 0x0020)
535 set_scoop_gpio(&corgiscoop_device
.dev
, CORGI_SCP_BACKLIGHT_CONT
);
537 reset_scoop_gpio(&corgiscoop_device
.dev
, CORGI_SCP_BACKLIGHT_CONT
);
542 #if defined(CONFIG_MACH_SPITZ) || defined(CONFIG_MACH_BORZOI)
543 void spitz_bl_set_intensity(int intensity
)
545 if (intensity
> 0x10)
548 /* Bits 0-4 are accessed via the SSP interface */
549 corgi_ssp_blduty_set(intensity
& 0x1f);
551 /* Bit 5 is via SCOOP */
552 if (intensity
& 0x0020)
553 reset_scoop_gpio(&spitzscoop2_device
.dev
, SPITZ_SCP2_BACKLIGHT_CONT
);
555 set_scoop_gpio(&spitzscoop2_device
.dev
, SPITZ_SCP2_BACKLIGHT_CONT
);
558 set_scoop_gpio(&spitzscoop2_device
.dev
, SPITZ_SCP2_BACKLIGHT_ON
);
560 reset_scoop_gpio(&spitzscoop2_device
.dev
, SPITZ_SCP2_BACKLIGHT_ON
);
564 #ifdef CONFIG_MACH_AKITA
565 void akita_bl_set_intensity(int intensity
)
567 if (intensity
> 0x10)
570 /* Bits 0-4 are accessed via the SSP interface */
571 corgi_ssp_blduty_set(intensity
& 0x1f);
573 /* Bit 5 is via IO-Expander */
574 if (intensity
& 0x0020)
575 akita_reset_ioexp(&akitaioexp_device
.dev
, AKITA_IOEXP_BACKLIGHT_CONT
);
577 akita_set_ioexp(&akitaioexp_device
.dev
, AKITA_IOEXP_BACKLIGHT_CONT
);
580 akita_set_ioexp(&akitaioexp_device
.dev
, AKITA_IOEXP_BACKLIGHT_ON
);
582 akita_reset_ioexp(&akitaioexp_device
.dev
, AKITA_IOEXP_BACKLIGHT_ON
);