aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/video')
-rw-r--r--drivers/video/Kconfig31
-rw-r--r--drivers/video/Makefile1
-rw-r--r--drivers/video/am200epd.c295
-rw-r--r--drivers/video/atmel_lcdfb.c4
-rw-r--r--drivers/video/backlight/Kconfig15
-rw-r--r--drivers/video/backlight/Makefile2
-rw-r--r--drivers/video/backlight/corgi_lcd.c641
-rw-r--r--drivers/video/backlight/lcd.c18
-rw-r--r--drivers/video/backlight/tdo24m.c396
-rw-r--r--drivers/video/fbmem.c1
-rw-r--r--drivers/video/metronomefb.c288
11 files changed, 1241 insertions, 451 deletions
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 70d135e0cc47..d85a74c64b54 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -172,11 +172,6 @@ config FB_DEFERRED_IO
172 bool 172 bool
173 depends on FB 173 depends on FB
174 174
175config FB_METRONOME
176 tristate
177 depends on FB
178 depends on FB_DEFERRED_IO
179
180config FB_HECUBA 175config FB_HECUBA
181 tristate 176 tristate
182 depends on FB 177 depends on FB
@@ -1974,19 +1969,6 @@ config FB_XILINX
1974 framebuffer. ML300 carries a 640*480 LCD display on the board, 1969 framebuffer. ML300 carries a 640*480 LCD display on the board,
1975 ML403 uses a standard DB15 VGA connector. 1970 ML403 uses a standard DB15 VGA connector.
1976 1971
1977config FB_AM200EPD
1978 tristate "AM-200 E-Ink EPD devkit support"
1979 depends on FB && ARCH_PXA && MMU
1980 select FB_SYS_FILLRECT
1981 select FB_SYS_COPYAREA
1982 select FB_SYS_IMAGEBLIT
1983 select FB_SYS_FOPS
1984 select FB_DEFERRED_IO
1985 select FB_METRONOME
1986 help
1987 This enables support for the Metronome display controller used on
1988 the E-Ink AM-200 EPD devkit.
1989
1990config FB_COBALT 1972config FB_COBALT
1991 tristate "Cobalt server LCD frame buffer support" 1973 tristate "Cobalt server LCD frame buffer support"
1992 depends on FB && MIPS_COBALT 1974 depends on FB && MIPS_COBALT
@@ -2041,6 +2023,19 @@ config XEN_FBDEV_FRONTEND
2041 frame buffer driver. It communicates with a back-end 2023 frame buffer driver. It communicates with a back-end
2042 in another domain. 2024 in another domain.
2043 2025
2026config FB_METRONOME
2027 tristate "E-Ink Metronome/8track controller support"
2028 depends on FB
2029 select FB_SYS_FILLRECT
2030 select FB_SYS_COPYAREA
2031 select FB_SYS_IMAGEBLIT
2032 select FB_SYS_FOPS
2033 select FB_DEFERRED_IO
2034 help
2035 This driver implements support for the E-Ink Metronome
2036 controller. The pre-release name for this device was 8track
2037 and could also have been called by some vendors as PVI-nnnn.
2038
2044source "drivers/video/omap/Kconfig" 2039source "drivers/video/omap/Kconfig"
2045 2040
2046source "drivers/video/backlight/Kconfig" 2041source "drivers/video/backlight/Kconfig"
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index a6b55297a7fb..ad0330bf9be3 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -29,7 +29,6 @@ obj-$(CONFIG_FB_DEFERRED_IO) += fb_defio.o
29 29
30# Hardware specific drivers go first 30# Hardware specific drivers go first
31obj-$(CONFIG_FB_AMIGA) += amifb.o c2p.o 31obj-$(CONFIG_FB_AMIGA) += amifb.o c2p.o
32obj-$(CONFIG_FB_AM200EPD) += am200epd.o
33obj-$(CONFIG_FB_ARC) += arcfb.o 32obj-$(CONFIG_FB_ARC) += arcfb.o
34obj-$(CONFIG_FB_CLPS711X) += clps711xfb.o 33obj-$(CONFIG_FB_CLPS711X) += clps711xfb.o
35obj-$(CONFIG_FB_CYBER2000) += cyber2000fb.o 34obj-$(CONFIG_FB_CYBER2000) += cyber2000fb.o
diff --git a/drivers/video/am200epd.c b/drivers/video/am200epd.c
deleted file mode 100644
index 0c35b8b0160e..000000000000
--- a/drivers/video/am200epd.c
+++ /dev/null
@@ -1,295 +0,0 @@
1/*
2 * linux/drivers/video/am200epd.c -- Platform device for AM200 EPD kit
3 *
4 * Copyright (C) 2008, Jaya Kumar
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive for
8 * more details.
9 *
10 * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
11 *
12 * This work was made possible by help and equipment support from E-Ink
13 * Corporation. http://support.eink.com/community
14 *
15 * This driver is written to be used with the Metronome display controller.
16 * on the AM200 EPD prototype kit/development kit with an E-Ink 800x600
17 * Vizplex EPD on a Gumstix board using the Lyre interface board.
18 *
19 */
20
21#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/errno.h>
24#include <linux/string.h>
25#include <linux/delay.h>
26#include <linux/interrupt.h>
27#include <linux/fb.h>
28#include <linux/init.h>
29#include <linux/platform_device.h>
30#include <linux/list.h>
31#include <linux/uaccess.h>
32#include <linux/irq.h>
33
34#include <video/metronomefb.h>
35
36#include <mach/pxa-regs.h>
37
38/* register offsets for gpio control */
39#define LED_GPIO_PIN 51
40#define STDBY_GPIO_PIN 48
41#define RST_GPIO_PIN 49
42#define RDY_GPIO_PIN 32
43#define ERR_GPIO_PIN 17
44#define PCBPWR_GPIO_PIN 16
45
46#define AF_SEL_GPIO_N 0x3
47#define GAFR0_U_OFFSET(pin) ((pin - 16) * 2)
48#define GAFR1_L_OFFSET(pin) ((pin - 32) * 2)
49#define GAFR1_U_OFFSET(pin) ((pin - 48) * 2)
50#define GPDR1_OFFSET(pin) (pin - 32)
51#define GPCR1_OFFSET(pin) (pin - 32)
52#define GPSR1_OFFSET(pin) (pin - 32)
53#define GPCR0_OFFSET(pin) (pin)
54#define GPSR0_OFFSET(pin) (pin)
55
56static void am200_set_gpio_output(int pin, int val)
57{
58 u8 index;
59
60 index = pin >> 4;
61
62 switch (index) {
63 case 1:
64 if (val)
65 GPSR0 |= (1 << GPSR0_OFFSET(pin));
66 else
67 GPCR0 |= (1 << GPCR0_OFFSET(pin));
68 break;
69 case 2:
70 break;
71 case 3:
72 if (val)
73 GPSR1 |= (1 << GPSR1_OFFSET(pin));
74 else
75 GPCR1 |= (1 << GPCR1_OFFSET(pin));
76 break;
77 default:
78 printk(KERN_ERR "unimplemented\n");
79 }
80}
81
82static void __devinit am200_init_gpio_pin(int pin, int dir)
83{
84 u8 index;
85 /* dir 0 is output, 1 is input
86 - do 2 things here:
87 - set gpio alternate function to standard gpio
88 - set gpio direction to input or output */
89
90 index = pin >> 4;
91 switch (index) {
92 case 1:
93 GAFR0_U &= ~(AF_SEL_GPIO_N << GAFR0_U_OFFSET(pin));
94
95 if (dir)
96 GPDR0 &= ~(1 << pin);
97 else
98 GPDR0 |= (1 << pin);
99 break;
100 case 2:
101 GAFR1_L &= ~(AF_SEL_GPIO_N << GAFR1_L_OFFSET(pin));
102
103 if (dir)
104 GPDR1 &= ~(1 << GPDR1_OFFSET(pin));
105 else
106 GPDR1 |= (1 << GPDR1_OFFSET(pin));
107 break;
108 case 3:
109 GAFR1_U &= ~(AF_SEL_GPIO_N << GAFR1_U_OFFSET(pin));
110
111 if (dir)
112 GPDR1 &= ~(1 << GPDR1_OFFSET(pin));
113 else
114 GPDR1 |= (1 << GPDR1_OFFSET(pin));
115 break;
116 default:
117 printk(KERN_ERR "unimplemented\n");
118 }
119}
120
121static void am200_init_gpio_regs(struct metronomefb_par *par)
122{
123 am200_init_gpio_pin(LED_GPIO_PIN, 0);
124 am200_set_gpio_output(LED_GPIO_PIN, 0);
125
126 am200_init_gpio_pin(STDBY_GPIO_PIN, 0);
127 am200_set_gpio_output(STDBY_GPIO_PIN, 0);
128
129 am200_init_gpio_pin(RST_GPIO_PIN, 0);
130 am200_set_gpio_output(RST_GPIO_PIN, 0);
131
132 am200_init_gpio_pin(RDY_GPIO_PIN, 1);
133
134 am200_init_gpio_pin(ERR_GPIO_PIN, 1);
135
136 am200_init_gpio_pin(PCBPWR_GPIO_PIN, 0);
137 am200_set_gpio_output(PCBPWR_GPIO_PIN, 0);
138}
139
140static void am200_disable_lcd_controller(struct metronomefb_par *par)
141{
142 LCSR = 0xffffffff; /* Clear LCD Status Register */
143 LCCR0 |= LCCR0_DIS; /* Disable LCD Controller */
144
145 /* we reset and just wait for things to settle */
146 msleep(200);
147}
148
149static void am200_enable_lcd_controller(struct metronomefb_par *par)
150{
151 LCSR = 0xffffffff;
152 FDADR0 = par->metromem_desc_dma;
153 LCCR0 |= LCCR0_ENB;
154}
155
156static void am200_init_lcdc_regs(struct metronomefb_par *par)
157{
158 /* here we do:
159 - disable the lcd controller
160 - setup lcd control registers
161 - setup dma descriptor
162 - reenable lcd controller
163 */
164
165 /* disable the lcd controller */
166 am200_disable_lcd_controller(par);
167
168 /* setup lcd control registers */
169 LCCR0 = LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM | LCCR0_PAS
170 | LCCR0_QDM | LCCR0_BM | LCCR0_OUM;
171
172 LCCR1 = (par->info->var.xres/2 - 1) /* pixels per line */
173 | (27 << 10) /* hsync pulse width - 1 */
174 | (33 << 16) /* eol pixel count */
175 | (33 << 24); /* bol pixel count */
176
177 LCCR2 = (par->info->var.yres - 1) /* lines per panel */
178 | (24 << 10) /* vsync pulse width - 1 */
179 | (2 << 16) /* eof pixel count */
180 | (0 << 24); /* bof pixel count */
181
182 LCCR3 = 2 /* pixel clock divisor */
183 | (24 << 8) /* AC Bias pin freq */
184 | LCCR3_16BPP /* BPP */
185 | LCCR3_PCP; /* PCP falling edge */
186
187}
188
189static void am200_post_dma_setup(struct metronomefb_par *par)
190{
191 par->metromem_desc->mFDADR0 = par->metromem_desc_dma;
192 par->metromem_desc->mFSADR0 = par->metromem_dma;
193 par->metromem_desc->mFIDR0 = 0;
194 par->metromem_desc->mLDCMD0 = par->info->var.xres
195 * par->info->var.yres;
196 am200_enable_lcd_controller(par);
197}
198
199static void am200_free_irq(struct fb_info *info)
200{
201 free_irq(IRQ_GPIO(RDY_GPIO_PIN), info);
202}
203
204static irqreturn_t am200_handle_irq(int irq, void *dev_id)
205{
206 struct fb_info *info = dev_id;
207 struct metronomefb_par *par = info->par;
208
209 wake_up_interruptible(&par->waitq);
210 return IRQ_HANDLED;
211}
212
213static int am200_setup_irq(struct fb_info *info)
214{
215 int retval;
216
217 retval = request_irq(IRQ_GPIO(RDY_GPIO_PIN), am200_handle_irq,
218 IRQF_DISABLED, "AM200", info);
219 if (retval) {
220 printk(KERN_ERR "am200epd: request_irq failed: %d\n", retval);
221 return retval;
222 }
223
224 return set_irq_type(IRQ_GPIO(RDY_GPIO_PIN), IRQ_TYPE_EDGE_FALLING);
225}
226
227static void am200_set_rst(struct metronomefb_par *par, int state)
228{
229 am200_set_gpio_output(RST_GPIO_PIN, state);
230}
231
232static void am200_set_stdby(struct metronomefb_par *par, int state)
233{
234 am200_set_gpio_output(STDBY_GPIO_PIN, state);
235}
236
237static int am200_wait_event(struct metronomefb_par *par)
238{
239 return wait_event_timeout(par->waitq, (GPLR1 & 0x01), HZ);
240}
241
242static int am200_wait_event_intr(struct metronomefb_par *par)
243{
244 return wait_event_interruptible_timeout(par->waitq, (GPLR1 & 0x01), HZ);
245}
246
247static struct metronome_board am200_board = {
248 .owner = THIS_MODULE,
249 .free_irq = am200_free_irq,
250 .setup_irq = am200_setup_irq,
251 .init_gpio_regs = am200_init_gpio_regs,
252 .init_lcdc_regs = am200_init_lcdc_regs,
253 .post_dma_setup = am200_post_dma_setup,
254 .set_rst = am200_set_rst,
255 .set_stdby = am200_set_stdby,
256 .met_wait_event = am200_wait_event,
257 .met_wait_event_intr = am200_wait_event_intr,
258};
259
260static struct platform_device *am200_device;
261
262static int __init am200_init(void)
263{
264 int ret;
265
266 /* request our platform independent driver */
267 request_module("metronomefb");
268
269 am200_device = platform_device_alloc("metronomefb", -1);
270 if (!am200_device)
271 return -ENOMEM;
272
273 platform_device_add_data(am200_device, &am200_board,
274 sizeof(am200_board));
275
276 /* this _add binds metronomefb to am200. metronomefb refcounts am200 */
277 ret = platform_device_add(am200_device);
278
279 if (ret)
280 platform_device_put(am200_device);
281
282 return ret;
283}
284
285static void __exit am200_exit(void)
286{
287 platform_device_unregister(am200_device);
288}
289
290module_init(am200_init);
291module_exit(am200_exit);
292
293MODULE_DESCRIPTION("board driver for am200 metronome epd kit");
294MODULE_AUTHOR("Jaya Kumar");
295MODULE_LICENSE("GPL");
diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
index 75dac578104f..d38fd5217422 100644
--- a/drivers/video/atmel_lcdfb.c
+++ b/drivers/video/atmel_lcdfb.c
@@ -408,6 +408,10 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
408 var->red.offset = 11; 408 var->red.offset = 11;
409 var->blue.offset = 0; 409 var->blue.offset = 0;
410 var->green.length = 6; 410 var->green.length = 6;
411 } else if (sinfo->lcd_wiring_mode == ATMEL_LCDC_WIRING_RGB555) {
412 var->red.offset = 10;
413 var->blue.offset = 0;
414 var->green.length = 5;
411 } else { 415 } else {
412 /* BGR:555 mode */ 416 /* BGR:555 mode */
413 var->red.offset = 0; 417 var->red.offset = 0;
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 452b770d8cc9..c72a13562954 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -24,6 +24,13 @@ config LCD_CLASS_DEVICE
24 To have support for your specific LCD panel you will have to 24 To have support for your specific LCD panel you will have to
25 select the proper drivers which depend on this option. 25 select the proper drivers which depend on this option.
26 26
27config LCD_CORGI
28 tristate "LCD Panel support for SHARP corgi/spitz model"
29 depends on LCD_CLASS_DEVICE && SPI_MASTER && PXA_SHARPSL
30 help
31 Say y here to support the LCD panels usually found on SHARP
32 corgi (C7x0) and spitz (Cxx00) models.
33
27config LCD_LTV350QV 34config LCD_LTV350QV
28 tristate "Samsung LTV350QV LCD Panel" 35 tristate "Samsung LTV350QV LCD Panel"
29 depends on LCD_CLASS_DEVICE && SPI_MASTER 36 depends on LCD_CLASS_DEVICE && SPI_MASTER
@@ -44,6 +51,14 @@ config LCD_ILI9320
44 If you have a panel based on the ILI9320 controller chip 51 If you have a panel based on the ILI9320 controller chip
45 then say y to include a power driver for it. 52 then say y to include a power driver for it.
46 53
54config LCD_TDO24M
55 tristate "Toppoly TDO24M LCD Panels support"
56 depends on LCD_CLASS_DEVICE && SPI_MASTER
57 default n
58 help
59 If you have a Toppoly TDO24M series LCD panel, say y here to
60 include the support for it.
61
47config LCD_VGG2432A4 62config LCD_VGG2432A4
48 tristate "VGG2432A4 LCM device support" 63 tristate "VGG2432A4 LCM device support"
49 depends on BACKLIGHT_LCD_SUPPORT && LCD_CLASS_DEVICE && SPI_MASTER 64 depends on BACKLIGHT_LCD_SUPPORT && LCD_CLASS_DEVICE && SPI_MASTER
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index b405aace803f..3ec551eb472c 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -1,10 +1,12 @@
1# Backlight & LCD drivers 1# Backlight & LCD drivers
2 2
3obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o 3obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o
4obj-$(CONFIG_LCD_CORGI) += corgi_lcd.o
4obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o 5obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o
5obj-$(CONFIG_LCD_ILI9320) += ili9320.o 6obj-$(CONFIG_LCD_ILI9320) += ili9320.o
6obj-$(CONFIG_LCD_PLATFORM) += platform_lcd.o 7obj-$(CONFIG_LCD_PLATFORM) += platform_lcd.o
7obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o 8obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o
9obj-$(CONFIG_LCD_TDO24M) += tdo24m.o
8 10
9obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o 11obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
10obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.o 12obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.o
diff --git a/drivers/video/backlight/corgi_lcd.c b/drivers/video/backlight/corgi_lcd.c
new file mode 100644
index 000000000000..2afd47eefe74
--- /dev/null
+++ b/drivers/video/backlight/corgi_lcd.c
@@ -0,0 +1,641 @@
1/*
2 * LCD/Backlight Driver for Sharp Zaurus Handhelds (various models)
3 *
4 * Copyright (c) 2004-2006 Richard Purdie
5 *
6 * Based on Sharp's 2.4 Backlight Driver
7 *
8 * Copyright (c) 2008 Marvell International Ltd.
9 * Converted to SPI device based LCD/Backlight device driver
10 * by Eric Miao <eric.miao@marvell.com>
11 *
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.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/delay.h>
22#include <linux/gpio.h>
23#include <linux/fb.h>
24#include <linux/lcd.h>
25#include <linux/spi/spi.h>
26#include <linux/spi/corgi_lcd.h>
27#include <asm/mach/sharpsl_param.h>
28
29#define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
30
31/* Register Addresses */
32#define RESCTL_ADRS 0x00
33#define PHACTRL_ADRS 0x01
34#define DUTYCTRL_ADRS 0x02
35#define POWERREG0_ADRS 0x03
36#define POWERREG1_ADRS 0x04
37#define GPOR3_ADRS 0x05
38#define PICTRL_ADRS 0x06
39#define POLCTRL_ADRS 0x07
40
41/* Register Bit Definitions */
42#define RESCTL_QVGA 0x01
43#define RESCTL_VGA 0x00
44
45#define POWER1_VW_ON 0x01 /* VW Supply FET ON */
46#define POWER1_GVSS_ON 0x02 /* GVSS(-8V) Power Supply ON */
47#define POWER1_VDD_ON 0x04 /* VDD(8V),SVSS(-4V) Power Supply ON */
48
49#define POWER1_VW_OFF 0x00 /* VW Supply FET OFF */
50#define POWER1_GVSS_OFF 0x00 /* GVSS(-8V) Power Supply OFF */
51#define POWER1_VDD_OFF 0x00 /* VDD(8V),SVSS(-4V) Power Supply OFF */
52
53#define POWER0_COM_DCLK 0x01 /* COM Voltage DC Bias DAC Serial Data Clock */
54#define POWER0_COM_DOUT 0x02 /* COM Voltage DC Bias DAC Serial Data Out */
55#define POWER0_DAC_ON 0x04 /* DAC Power Supply ON */
56#define POWER0_COM_ON 0x08 /* COM Power Supply ON */
57#define POWER0_VCC5_ON 0x10 /* VCC5 Power Supply ON */
58
59#define POWER0_DAC_OFF 0x00 /* DAC Power Supply OFF */
60#define POWER0_COM_OFF 0x00 /* COM Power Supply OFF */
61#define POWER0_VCC5_OFF 0x00 /* VCC5 Power Supply OFF */
62
63#define PICTRL_INIT_STATE 0x01
64#define PICTRL_INIOFF 0x02
65#define PICTRL_POWER_DOWN 0x04
66#define PICTRL_COM_SIGNAL_OFF 0x08
67#define PICTRL_DAC_SIGNAL_OFF 0x10
68
69#define POLCTRL_SYNC_POL_FALL 0x01
70#define POLCTRL_EN_POL_FALL 0x02
71#define POLCTRL_DATA_POL_FALL 0x04
72#define POLCTRL_SYNC_ACT_H 0x08
73#define POLCTRL_EN_ACT_L 0x10
74
75#define POLCTRL_SYNC_POL_RISE 0x00
76#define POLCTRL_EN_POL_RISE 0x00
77#define POLCTRL_DATA_POL_RISE 0x00
78#define POLCTRL_SYNC_ACT_L 0x00
79#define POLCTRL_EN_ACT_H 0x00
80
81#define PHACTRL_PHASE_MANUAL 0x01
82#define DEFAULT_PHAD_QVGA (9)
83#define DEFAULT_COMADJ (125)
84
85struct corgi_lcd {
86 struct spi_device *spi_dev;
87 struct lcd_device *lcd_dev;
88 struct backlight_device *bl_dev;
89
90 int limit_mask;
91 int intensity;
92 int power;
93 int mode;
94 char buf[2];
95
96 int gpio_backlight_on;
97 int gpio_backlight_cont;
98 int gpio_backlight_cont_inverted;
99
100 void (*kick_battery)(void);
101};
102
103static int corgi_ssp_lcdtg_send(struct corgi_lcd *lcd, int reg, uint8_t val);
104
105static struct corgi_lcd *the_corgi_lcd;
106static unsigned long corgibl_flags;
107#define CORGIBL_SUSPENDED 0x01
108#define CORGIBL_BATTLOW 0x02
109
110/*
111 * This is only a psuedo I2C interface. We can't use the standard kernel
112 * routines as the interface is write only. We just assume the data is acked...
113 */
114static void lcdtg_ssp_i2c_send(struct corgi_lcd *lcd, uint8_t data)
115{
116 corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS, data);
117 udelay(10);
118}
119
120static void lcdtg_i2c_send_bit(struct corgi_lcd *lcd, uint8_t data)
121{
122 lcdtg_ssp_i2c_send(lcd, data);
123 lcdtg_ssp_i2c_send(lcd, data | POWER0_COM_DCLK);
124 lcdtg_ssp_i2c_send(lcd, data);
125}
126
127static void lcdtg_i2c_send_start(struct corgi_lcd *lcd, uint8_t base)
128{
129 lcdtg_ssp_i2c_send(lcd, base | POWER0_COM_DCLK | POWER0_COM_DOUT);
130 lcdtg_ssp_i2c_send(lcd, base | POWER0_COM_DCLK);
131 lcdtg_ssp_i2c_send(lcd, base);
132}
133
134static void lcdtg_i2c_send_stop(struct corgi_lcd *lcd, uint8_t base)
135{
136 lcdtg_ssp_i2c_send(lcd, base);
137 lcdtg_ssp_i2c_send(lcd, base | POWER0_COM_DCLK);
138 lcdtg_ssp_i2c_send(lcd, base | POWER0_COM_DCLK | POWER0_COM_DOUT);
139}
140
141static void lcdtg_i2c_send_byte(struct corgi_lcd *lcd,
142 uint8_t base, uint8_t data)
143{
144 int i;
145 for (i = 0; i < 8; i++) {
146 if (data & 0x80)
147 lcdtg_i2c_send_bit(lcd, base | POWER0_COM_DOUT);
148 else
149 lcdtg_i2c_send_bit(lcd, base);
150 data <<= 1;
151 }
152}
153
154static void lcdtg_i2c_wait_ack(struct corgi_lcd *lcd, uint8_t base)
155{
156 lcdtg_i2c_send_bit(lcd, base);
157}
158
159static void lcdtg_set_common_voltage(struct corgi_lcd *lcd,
160 uint8_t base_data, uint8_t data)
161{
162 /* Set Common Voltage to M62332FP via I2C */
163 lcdtg_i2c_send_start(lcd, base_data);
164 lcdtg_i2c_send_byte(lcd, base_data, 0x9c);
165 lcdtg_i2c_wait_ack(lcd, base_data);
166 lcdtg_i2c_send_byte(lcd, base_data, 0x00);
167 lcdtg_i2c_wait_ack(lcd, base_data);
168 lcdtg_i2c_send_byte(lcd, base_data, data);
169 lcdtg_i2c_wait_ack(lcd, base_data);
170 lcdtg_i2c_send_stop(lcd, base_data);
171}
172
173static int corgi_ssp_lcdtg_send(struct corgi_lcd *lcd, int adrs, uint8_t data)
174{
175 struct spi_message msg;
176 struct spi_transfer xfer = {
177 .len = 1,
178 .cs_change = 1,
179 .tx_buf = lcd->buf,
180 };
181
182 lcd->buf[0] = ((adrs & 0x07) << 5) | (data & 0x1f);
183 spi_message_init(&msg);
184 spi_message_add_tail(&xfer, &msg);
185
186 return spi_sync(lcd->spi_dev, &msg);
187}
188
189/* Set Phase Adjust */
190static void lcdtg_set_phadadj(struct corgi_lcd *lcd, int mode)
191{
192 int adj;
193
194 switch(mode) {
195 case CORGI_LCD_MODE_VGA:
196 /* Setting for VGA */
197 adj = sharpsl_param.phadadj;
198 adj = (adj < 0) ? PHACTRL_PHASE_MANUAL :
199 PHACTRL_PHASE_MANUAL | ((adj & 0xf) << 1);
200 break;
201 case CORGI_LCD_MODE_QVGA:
202 default:
203 /* Setting for QVGA */
204 adj = (DEFAULT_PHAD_QVGA << 1) | PHACTRL_PHASE_MANUAL;
205 break;
206 }
207
208 corgi_ssp_lcdtg_send(lcd, PHACTRL_ADRS, adj);
209}
210
211static void corgi_lcd_power_on(struct corgi_lcd *lcd)
212{
213 int comadj;
214
215 /* Initialize Internal Logic & Port */
216 corgi_ssp_lcdtg_send(lcd, PICTRL_ADRS,
217 PICTRL_POWER_DOWN | PICTRL_INIOFF |
218 PICTRL_INIT_STATE | PICTRL_COM_SIGNAL_OFF |
219 PICTRL_DAC_SIGNAL_OFF);
220
221 corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS,
222 POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_OFF |
223 POWER0_COM_OFF | POWER0_VCC5_OFF);
224
225 corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS,
226 POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_OFF);
227
228 /* VDD(+8V), SVSS(-4V) ON */
229 corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS,
230 POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_ON);
231 mdelay(3);
232
233 /* DAC ON */
234 corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS,
235 POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON |
236 POWER0_COM_OFF | POWER0_VCC5_OFF);
237
238 /* INIB = H, INI = L */
239 /* PICTL[0] = H , PICTL[1] = PICTL[2] = PICTL[4] = L */
240 corgi_ssp_lcdtg_send(lcd, PICTRL_ADRS,
241 PICTRL_INIT_STATE | PICTRL_COM_SIGNAL_OFF);
242
243 /* Set Common Voltage */
244 comadj = sharpsl_param.comadj;
245 if (comadj < 0)
246 comadj = DEFAULT_COMADJ;
247
248 lcdtg_set_common_voltage(lcd, POWER0_DAC_ON | POWER0_COM_OFF |
249 POWER0_VCC5_OFF, comadj);
250
251 /* VCC5 ON, DAC ON */
252 corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS,
253 POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON |
254 POWER0_COM_OFF | POWER0_VCC5_ON);
255
256 /* GVSS(-8V) ON, VDD ON */
257 corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS,
258 POWER1_VW_OFF | POWER1_GVSS_ON | POWER1_VDD_ON);
259 mdelay(2);
260
261 /* COM SIGNAL ON (PICTL[3] = L) */
262 corgi_ssp_lcdtg_send(lcd, PICTRL_ADRS, PICTRL_INIT_STATE);
263
264 /* COM ON, DAC ON, VCC5_ON */
265 corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS,
266 POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON |
267 POWER0_COM_ON | POWER0_VCC5_ON);
268
269 /* VW ON, GVSS ON, VDD ON */
270 corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS,
271 POWER1_VW_ON | POWER1_GVSS_ON | POWER1_VDD_ON);
272
273 /* Signals output enable */
274 corgi_ssp_lcdtg_send(lcd, PICTRL_ADRS, 0);
275
276 /* Set Phase Adjust */
277 lcdtg_set_phadadj(lcd, lcd->mode);
278
279 /* Initialize for Input Signals from ATI */
280 corgi_ssp_lcdtg_send(lcd, POLCTRL_ADRS,
281 POLCTRL_SYNC_POL_RISE | POLCTRL_EN_POL_RISE |
282 POLCTRL_DATA_POL_RISE | POLCTRL_SYNC_ACT_L |
283 POLCTRL_EN_ACT_H);
284 udelay(1000);
285
286 switch (lcd->mode) {
287 case CORGI_LCD_MODE_VGA:
288 corgi_ssp_lcdtg_send(lcd, RESCTL_ADRS, RESCTL_VGA);
289 break;
290 case CORGI_LCD_MODE_QVGA:
291 default:
292 corgi_ssp_lcdtg_send(lcd, RESCTL_ADRS, RESCTL_QVGA);
293 break;
294 }
295}
296
297static void corgi_lcd_power_off(struct corgi_lcd *lcd)
298{
299 /* 60Hz x 2 frame = 16.7msec x 2 = 33.4 msec */
300 msleep(34);
301
302 /* (1)VW OFF */
303 corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS,
304 POWER1_VW_OFF | POWER1_GVSS_ON | POWER1_VDD_ON);
305
306 /* (2)COM OFF */
307 corgi_ssp_lcdtg_send(lcd, PICTRL_ADRS, PICTRL_COM_SIGNAL_OFF);
308 corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS,
309 POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_ON);
310
311 /* (3)Set Common Voltage Bias 0V */
312 lcdtg_set_common_voltage(lcd, POWER0_DAC_ON | POWER0_COM_OFF |
313 POWER0_VCC5_ON, 0);
314
315 /* (4)GVSS OFF */
316 corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS,
317 POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_ON);
318
319 /* (5)VCC5 OFF */
320 corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS,
321 POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_OFF);
322
323 /* (6)Set PDWN, INIOFF, DACOFF */
324 corgi_ssp_lcdtg_send(lcd, PICTRL_ADRS,
325 PICTRL_INIOFF | PICTRL_DAC_SIGNAL_OFF |
326 PICTRL_POWER_DOWN | PICTRL_COM_SIGNAL_OFF);
327
328 /* (7)DAC OFF */
329 corgi_ssp_lcdtg_send(lcd, POWERREG0_ADRS,
330 POWER0_DAC_OFF | POWER0_COM_OFF | POWER0_VCC5_OFF);
331
332 /* (8)VDD OFF */
333 corgi_ssp_lcdtg_send(lcd, POWERREG1_ADRS,
334 POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_OFF);
335}
336
337static int corgi_lcd_set_mode(struct lcd_device *ld, struct fb_videomode *m)
338{
339 struct corgi_lcd *lcd = dev_get_drvdata(&ld->dev);
340 int mode = CORGI_LCD_MODE_QVGA;
341
342 if (m->xres == 640 || m->xres == 480)
343 mode = CORGI_LCD_MODE_VGA;
344
345 if (lcd->mode == mode)
346 return 0;
347
348 lcdtg_set_phadadj(lcd, mode);
349
350 switch (mode) {
351 case CORGI_LCD_MODE_VGA:
352 corgi_ssp_lcdtg_send(lcd, RESCTL_ADRS, RESCTL_VGA);
353 break;
354 case CORGI_LCD_MODE_QVGA:
355 default:
356 corgi_ssp_lcdtg_send(lcd, RESCTL_ADRS, RESCTL_QVGA);
357 break;
358 }
359
360 lcd->mode = mode;
361 return 0;
362}
363
364static int corgi_lcd_set_power(struct lcd_device *ld, int power)
365{
366 struct corgi_lcd *lcd = dev_get_drvdata(&ld->dev);
367
368 if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
369 corgi_lcd_power_on(lcd);
370
371 if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
372 corgi_lcd_power_off(lcd);
373
374 lcd->power = power;
375 return 0;
376}
377
378static int corgi_lcd_get_power(struct lcd_device *ld)
379{
380 struct corgi_lcd *lcd = dev_get_drvdata(&ld->dev);
381
382 return lcd->power;
383}
384
385static struct lcd_ops corgi_lcd_ops = {
386 .get_power = corgi_lcd_get_power,
387 .set_power = corgi_lcd_set_power,
388 .set_mode = corgi_lcd_set_mode,
389};
390
391static int corgi_bl_get_intensity(struct backlight_device *bd)
392{
393 struct corgi_lcd *lcd = dev_get_drvdata(&bd->dev);
394
395 return lcd->intensity;
396}
397
398static int corgi_bl_set_intensity(struct corgi_lcd *lcd, int intensity)
399{
400 int cont;
401
402 if (intensity > 0x10)
403 intensity += 0x10;
404
405 corgi_ssp_lcdtg_send(lcd, DUTYCTRL_ADRS, intensity);
406
407 /* Bit 5 via GPIO_BACKLIGHT_CONT */
408 cont = !!(intensity & 0x20) ^ lcd->gpio_backlight_cont_inverted;
409
410 if (gpio_is_valid(lcd->gpio_backlight_cont))
411 gpio_set_value(lcd->gpio_backlight_cont, cont);
412
413 if (gpio_is_valid(lcd->gpio_backlight_on))
414 gpio_set_value(lcd->gpio_backlight_on, intensity);
415
416 if (lcd->kick_battery)
417 lcd->kick_battery();
418
419 lcd->intensity = intensity;
420 return 0;
421}
422
423static int corgi_bl_update_status(struct backlight_device *bd)
424{
425 struct corgi_lcd *lcd = dev_get_drvdata(&bd->dev);
426 int intensity = bd->props.brightness;
427
428 if (bd->props.power != FB_BLANK_UNBLANK)
429 intensity = 0;
430
431 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
432 intensity = 0;
433
434 if (corgibl_flags & CORGIBL_SUSPENDED)
435 intensity = 0;
436 if (corgibl_flags & CORGIBL_BATTLOW)
437 intensity &= lcd->limit_mask;
438
439 return corgi_bl_set_intensity(lcd, intensity);
440}
441
442void corgibl_limit_intensity(int limit)
443{
444 if (limit)
445 corgibl_flags |= CORGIBL_BATTLOW;
446 else
447 corgibl_flags &= ~CORGIBL_BATTLOW;
448
449 backlight_update_status(the_corgi_lcd->bl_dev);
450}
451EXPORT_SYMBOL(corgibl_limit_intensity);
452
453static struct backlight_ops corgi_bl_ops = {
454 .get_brightness = corgi_bl_get_intensity,
455 .update_status = corgi_bl_update_status,
456};
457
458#ifdef CONFIG_PM
459static int corgi_lcd_suspend(struct spi_device *spi, pm_message_t state)
460{
461 struct corgi_lcd *lcd = dev_get_drvdata(&spi->dev);
462
463 corgibl_flags |= CORGIBL_SUSPENDED;
464 corgi_bl_set_intensity(lcd, 0);
465 corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_POWERDOWN);
466 return 0;
467}
468
469static int corgi_lcd_resume(struct spi_device *spi)
470{
471 struct corgi_lcd *lcd = dev_get_drvdata(&spi->dev);
472
473 corgibl_flags &= ~CORGIBL_SUSPENDED;
474 corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_UNBLANK);
475 backlight_update_status(lcd->bl_dev);
476 return 0;
477}
478#else
479#define corgi_lcd_suspend NULL
480#define corgi_lcd_resume NULL
481#endif
482
483static int setup_gpio_backlight(struct corgi_lcd *lcd,
484 struct corgi_lcd_platform_data *pdata)
485{
486 struct spi_device *spi = lcd->spi_dev;
487 int err;
488
489 lcd->gpio_backlight_on = -1;
490 lcd->gpio_backlight_cont = -1;
491
492 if (gpio_is_valid(pdata->gpio_backlight_on)) {
493 err = gpio_request(pdata->gpio_backlight_on, "BL_ON");
494 if (err) {
495 dev_err(&spi->dev, "failed to request GPIO%d for "
496 "backlight_on\n", pdata->gpio_backlight_on);
497 return err;
498 }
499
500 lcd->gpio_backlight_on = pdata->gpio_backlight_on;
501 gpio_direction_output(lcd->gpio_backlight_on, 0);
502 }
503
504 if (gpio_is_valid(pdata->gpio_backlight_cont)) {
505 err = gpio_request(pdata->gpio_backlight_cont, "BL_CONT");
506 if (err) {
507 dev_err(&spi->dev, "failed to request GPIO%d for "
508 "backlight_cont\n", pdata->gpio_backlight_cont);
509 goto err_free_backlight_on;
510 }
511
512 lcd->gpio_backlight_cont = pdata->gpio_backlight_cont;
513
514 /* spitz and akita use both GPIOs for backlight, and
515 * have inverted polarity of GPIO_BACKLIGHT_CONT
516 */
517 if (gpio_is_valid(lcd->gpio_backlight_on)) {
518 lcd->gpio_backlight_cont_inverted = 1;
519 gpio_direction_output(lcd->gpio_backlight_cont, 1);
520 } else {
521 lcd->gpio_backlight_cont_inverted = 0;
522 gpio_direction_output(lcd->gpio_backlight_cont, 0);
523 }
524 }
525 return 0;
526
527err_free_backlight_on:
528 if (gpio_is_valid(lcd->gpio_backlight_on))
529 gpio_free(lcd->gpio_backlight_on);
530 return err;
531}
532
533static int __devinit corgi_lcd_probe(struct spi_device *spi)
534{
535 struct corgi_lcd_platform_data *pdata = spi->dev.platform_data;
536 struct corgi_lcd *lcd;
537 int ret = 0;
538
539 if (pdata == NULL) {
540 dev_err(&spi->dev, "platform data not available\n");
541 return -EINVAL;
542 }
543
544 lcd = kzalloc(sizeof(struct corgi_lcd), GFP_KERNEL);
545 if (!lcd) {
546 dev_err(&spi->dev, "failed to allocate memory\n");
547 return -ENOMEM;
548 }
549
550 lcd->spi_dev = spi;
551
552 lcd->lcd_dev = lcd_device_register("corgi_lcd", &spi->dev,
553 lcd, &corgi_lcd_ops);
554 if (IS_ERR(lcd->lcd_dev)) {
555 ret = PTR_ERR(lcd->lcd_dev);
556 goto err_free_lcd;
557 }
558 lcd->power = FB_BLANK_POWERDOWN;
559 lcd->mode = (pdata) ? pdata->init_mode : CORGI_LCD_MODE_VGA;
560
561 lcd->bl_dev = backlight_device_register("corgi_bl", &spi->dev,
562 lcd, &corgi_bl_ops);
563 if (IS_ERR(lcd->bl_dev)) {
564 ret = PTR_ERR(lcd->bl_dev);
565 goto err_unregister_lcd;
566 }
567 lcd->bl_dev->props.max_brightness = pdata->max_intensity;
568 lcd->bl_dev->props.brightness = pdata->default_intensity;
569 lcd->bl_dev->props.power = FB_BLANK_UNBLANK;
570
571 ret = setup_gpio_backlight(lcd, pdata);
572 if (ret)
573 goto err_unregister_bl;
574
575 lcd->kick_battery = pdata->kick_battery;
576
577 dev_set_drvdata(&spi->dev, lcd);
578 corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_UNBLANK);
579 backlight_update_status(lcd->bl_dev);
580
581 lcd->limit_mask = pdata->limit_mask;
582 the_corgi_lcd = lcd;
583 return 0;
584
585err_unregister_bl:
586 backlight_device_unregister(lcd->bl_dev);
587err_unregister_lcd:
588 lcd_device_unregister(lcd->lcd_dev);
589err_free_lcd:
590 kfree(lcd);
591 return ret;
592}
593
594static int __devexit corgi_lcd_remove(struct spi_device *spi)
595{
596 struct corgi_lcd *lcd = dev_get_drvdata(&spi->dev);
597
598 lcd->bl_dev->props.power = FB_BLANK_UNBLANK;
599 lcd->bl_dev->props.brightness = 0;
600 backlight_update_status(lcd->bl_dev);
601 backlight_device_unregister(lcd->bl_dev);
602
603 if (gpio_is_valid(lcd->gpio_backlight_on))
604 gpio_free(lcd->gpio_backlight_on);
605
606 if (gpio_is_valid(lcd->gpio_backlight_cont))
607 gpio_free(lcd->gpio_backlight_cont);
608
609 corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_POWERDOWN);
610 lcd_device_unregister(lcd->lcd_dev);
611 kfree(lcd);
612
613 return 0;
614}
615
616static struct spi_driver corgi_lcd_driver = {
617 .driver = {
618 .name = "corgi-lcd",
619 .owner = THIS_MODULE,
620 },
621 .probe = corgi_lcd_probe,
622 .remove = __devexit_p(corgi_lcd_remove),
623 .suspend = corgi_lcd_suspend,
624 .resume = corgi_lcd_resume,
625};
626
627static int __init corgi_lcd_init(void)
628{
629 return spi_register_driver(&corgi_lcd_driver);
630}
631module_init(corgi_lcd_init);
632
633static void __exit corgi_lcd_exit(void)
634{
635 spi_unregister_driver(&corgi_lcd_driver);
636}
637module_exit(corgi_lcd_exit);
638
639MODULE_DESCRIPTION("LCD and backlight driver for SHARP C7x0/Cxx00");
640MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>");
641MODULE_LICENSE("GPL");
diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
index b15b2b84a6f7..8e1731d3b228 100644
--- a/drivers/video/backlight/lcd.c
+++ b/drivers/video/backlight/lcd.c
@@ -27,14 +27,26 @@ static int fb_notifier_callback(struct notifier_block *self,
27 struct fb_event *evdata = data; 27 struct fb_event *evdata = data;
28 28
29 /* If we aren't interested in this event, skip it immediately ... */ 29 /* If we aren't interested in this event, skip it immediately ... */
30 if (event != FB_EVENT_BLANK) 30 switch (event) {
31 case FB_EVENT_BLANK:
32 case FB_EVENT_MODE_CHANGE:
33 case FB_EVENT_MODE_CHANGE_ALL:
34 break;
35 default:
31 return 0; 36 return 0;
37 }
32 38
33 ld = container_of(self, struct lcd_device, fb_notif); 39 ld = container_of(self, struct lcd_device, fb_notif);
40 if (!ld->ops)
41 return 0;
42
34 mutex_lock(&ld->ops_lock); 43 mutex_lock(&ld->ops_lock);
35 if (ld->ops) 44 if (!ld->ops->check_fb || ld->ops->check_fb(ld, evdata->info)) {
36 if (!ld->ops->check_fb || ld->ops->check_fb(ld, evdata->info)) 45 if (event == FB_EVENT_BLANK)
37 ld->ops->set_power(ld, *(int *)evdata->data); 46 ld->ops->set_power(ld, *(int *)evdata->data);
47 else
48 ld->ops->set_mode(ld, evdata->data);
49 }
38 mutex_unlock(&ld->ops_lock); 50 mutex_unlock(&ld->ops_lock);
39 return 0; 51 return 0;
40} 52}
diff --git a/drivers/video/backlight/tdo24m.c b/drivers/video/backlight/tdo24m.c
new file mode 100644
index 000000000000..8427669162ea
--- /dev/null
+++ b/drivers/video/backlight/tdo24m.c
@@ -0,0 +1,396 @@
1/*
2 * tdo24m - SPI-based drivers for Toppoly TDO24M series LCD panels
3 *
4 * Copyright (C) 2008 Marvell International Ltd.
5 * Eric Miao <eric.miao@marvell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * publishhed by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/device.h>
16#include <linux/spi/spi.h>
17#include <linux/fb.h>
18#include <linux/lcd.h>
19
20#define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
21
22#define TDO24M_SPI_BUFF_SIZE (4)
23#define MODE_QVGA 0
24#define MODE_VGA 1
25
26struct tdo24m {
27 struct spi_device *spi_dev;
28 struct lcd_device *lcd_dev;
29
30 struct spi_message msg;
31 struct spi_transfer xfer;
32 uint8_t *buf;
33
34 int power;
35 int mode;
36};
37
38/* use bit 30, 31 as the indicator of command parameter number */
39#define CMD0(x) ((0 << 30) | (x))
40#define CMD1(x, x1) ((1 << 30) | ((x) << 9) | 0x100 | (x1))
41#define CMD2(x, x1, x2) ((2 << 30) | ((x) << 18) | 0x20000 |\
42 ((x1) << 9) | 0x100 | (x2))
43#define CMD_NULL (-1)
44
45static uint32_t lcd_panel_reset[] = {
46 CMD0(0x1), /* reset */
47 CMD0(0x0), /* nop */
48 CMD0(0x0), /* nop */
49 CMD0(0x0), /* nop */
50 CMD_NULL,
51};
52
53static uint32_t lcd_panel_on[] = {
54 CMD0(0x29), /* Display ON */
55 CMD2(0xB8, 0xFF, 0xF9), /* Output Control */
56 CMD0(0x11), /* Sleep out */
57 CMD1(0xB0, 0x16), /* Wake */
58 CMD_NULL,
59};
60
61static uint32_t lcd_panel_off[] = {
62 CMD0(0x28), /* Display OFF */
63 CMD2(0xB8, 0x80, 0x02), /* Output Control */
64 CMD0(0x10), /* Sleep in */
65 CMD1(0xB0, 0x00), /* Deep stand by in */
66 CMD_NULL,
67};
68
69static uint32_t lcd_vga_pass_through[] = {
70 CMD1(0xB0, 0x16),
71 CMD1(0xBC, 0x80),
72 CMD1(0xE1, 0x00),
73 CMD1(0x36, 0x50),
74 CMD1(0x3B, 0x00),
75 CMD_NULL,
76};
77
78static uint32_t lcd_qvga_pass_through[] = {
79 CMD1(0xB0, 0x16),
80 CMD1(0xBC, 0x81),
81 CMD1(0xE1, 0x00),
82 CMD1(0x36, 0x50),
83 CMD1(0x3B, 0x22),
84 CMD_NULL,
85};
86
87static uint32_t lcd_vga_transfer[] = {
88 CMD1(0xcf, 0x02), /* Blanking period control (1) */
89 CMD2(0xd0, 0x08, 0x04), /* Blanking period control (2) */
90 CMD1(0xd1, 0x01), /* CKV timing control on/off */
91 CMD2(0xd2, 0x14, 0x00), /* CKV 1,2 timing control */
92 CMD2(0xd3, 0x1a, 0x0f), /* OEV timing control */
93 CMD2(0xd4, 0x1f, 0xaf), /* ASW timing control (1) */
94 CMD1(0xd5, 0x14), /* ASW timing control (2) */
95 CMD0(0x21), /* Invert for normally black display */
96 CMD0(0x29), /* Display on */
97 CMD_NULL,
98};
99
100static uint32_t lcd_qvga_transfer[] = {
101 CMD1(0xd6, 0x02), /* Blanking period control (1) */
102 CMD2(0xd7, 0x08, 0x04), /* Blanking period control (2) */
103 CMD1(0xd8, 0x01), /* CKV timing control on/off */
104 CMD2(0xd9, 0x00, 0x08), /* CKV 1,2 timing control */
105 CMD2(0xde, 0x05, 0x0a), /* OEV timing control */
106 CMD2(0xdf, 0x0a, 0x19), /* ASW timing control (1) */
107 CMD1(0xe0, 0x0a), /* ASW timing control (2) */
108 CMD0(0x21), /* Invert for normally black display */
109 CMD0(0x29), /* Display on */
110 CMD_NULL,
111};
112
113static uint32_t lcd_panel_config[] = {
114 CMD2(0xb8, 0xff, 0xf9), /* Output control */
115 CMD0(0x11), /* sleep out */
116 CMD1(0xba, 0x01), /* Display mode (1) */
117 CMD1(0xbb, 0x00), /* Display mode (2) */
118 CMD1(0x3a, 0x60), /* Display mode 18-bit RGB */
119 CMD1(0xbf, 0x10), /* Drive system change control */
120 CMD1(0xb1, 0x56), /* Booster operation setup */
121 CMD1(0xb2, 0x33), /* Booster mode setup */
122 CMD1(0xb3, 0x11), /* Booster frequency setup */
123 CMD1(0xb4, 0x02), /* Op amp/system clock */
124 CMD1(0xb5, 0x35), /* VCS voltage */
125 CMD1(0xb6, 0x40), /* VCOM voltage */
126 CMD1(0xb7, 0x03), /* External display signal */
127 CMD1(0xbd, 0x00), /* ASW slew rate */
128 CMD1(0xbe, 0x00), /* Dummy data for QuadData operation */
129 CMD1(0xc0, 0x11), /* Sleep out FR count (A) */
130 CMD1(0xc1, 0x11), /* Sleep out FR count (B) */
131 CMD1(0xc2, 0x11), /* Sleep out FR count (C) */
132 CMD2(0xc3, 0x20, 0x40), /* Sleep out FR count (D) */
133 CMD2(0xc4, 0x60, 0xc0), /* Sleep out FR count (E) */
134 CMD2(0xc5, 0x10, 0x20), /* Sleep out FR count (F) */
135 CMD1(0xc6, 0xc0), /* Sleep out FR count (G) */
136 CMD2(0xc7, 0x33, 0x43), /* Gamma 1 fine tuning (1) */
137 CMD1(0xc8, 0x44), /* Gamma 1 fine tuning (2) */
138 CMD1(0xc9, 0x33), /* Gamma 1 inclination adjustment */
139 CMD1(0xca, 0x00), /* Gamma 1 blue offset adjustment */
140 CMD2(0xec, 0x01, 0xf0), /* Horizontal clock cycles */
141 CMD_NULL,
142};
143
144static int tdo24m_writes(struct tdo24m *lcd, uint32_t *array)
145{
146 struct spi_transfer *x = &lcd->xfer;
147 uint32_t data, *p = array;
148 int nparams, err = 0;
149
150 for (; *p != CMD_NULL; p++) {
151
152 nparams = (*p >> 30) & 0x3;
153
154 data = *p << (7 - nparams);
155 switch (nparams) {
156 case 0:
157 lcd->buf[0] = (data >> 8) & 0xff;
158 lcd->buf[1] = data & 0xff;
159 break;
160 case 1:
161 lcd->buf[0] = (data >> 16) & 0xff;
162 lcd->buf[1] = (data >> 8) & 0xff;
163 lcd->buf[2] = data & 0xff;
164 break;
165 case 2:
166 lcd->buf[0] = (data >> 24) & 0xff;
167 lcd->buf[1] = (data >> 16) & 0xff;
168 lcd->buf[2] = (data >> 8) & 0xff;
169 lcd->buf[3] = data & 0xff;
170 break;
171 default:
172 continue;
173 }
174 x->len = nparams + 2;
175 err = spi_sync(lcd->spi_dev, &lcd->msg);
176 if (err)
177 break;
178 }
179
180 return err;
181}
182
183static int tdo24m_adj_mode(struct tdo24m *lcd, int mode)
184{
185 switch (mode) {
186 case MODE_VGA:
187 tdo24m_writes(lcd, lcd_vga_pass_through);
188 tdo24m_writes(lcd, lcd_panel_config);
189 tdo24m_writes(lcd, lcd_vga_transfer);
190 break;
191 case MODE_QVGA:
192 tdo24m_writes(lcd, lcd_qvga_pass_through);
193 tdo24m_writes(lcd, lcd_panel_config);
194 tdo24m_writes(lcd, lcd_qvga_transfer);
195 break;
196 default:
197 return -EINVAL;
198 }
199
200 lcd->mode = mode;
201 return 0;
202}
203
204static int tdo24m_power_on(struct tdo24m *lcd)
205{
206 int err;
207
208 err = tdo24m_writes(lcd, lcd_panel_on);
209 if (err)
210 goto out;
211
212 err = tdo24m_writes(lcd, lcd_panel_reset);
213 if (err)
214 goto out;
215
216 err = tdo24m_adj_mode(lcd, lcd->mode);
217out:
218 return err;
219}
220
221static int tdo24m_power_off(struct tdo24m *lcd)
222{
223 return tdo24m_writes(lcd, lcd_panel_off);
224}
225
226static int tdo24m_power(struct tdo24m *lcd, int power)
227{
228 int ret = 0;
229
230 if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
231 ret = tdo24m_power_on(lcd);
232 else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
233 ret = tdo24m_power_off(lcd);
234
235 if (!ret)
236 lcd->power = power;
237
238 return ret;
239}
240
241
242static int tdo24m_set_power(struct lcd_device *ld, int power)
243{
244 struct tdo24m *lcd = lcd_get_data(ld);
245 return tdo24m_power(lcd, power);
246}
247
248static int tdo24m_get_power(struct lcd_device *ld)
249{
250 struct tdo24m *lcd = lcd_get_data(ld);
251 return lcd->power;
252}
253
254static int tdo24m_set_mode(struct lcd_device *ld, struct fb_videomode *m)
255{
256 struct tdo24m *lcd = lcd_get_data(ld);
257 int mode = MODE_QVGA;
258
259 if (m->xres == 640 || m->xres == 480)
260 mode = MODE_VGA;
261
262 if (lcd->mode == mode)
263 return 0;
264
265 return tdo24m_adj_mode(lcd, mode);
266}
267
268static struct lcd_ops tdo24m_ops = {
269 .get_power = tdo24m_get_power,
270 .set_power = tdo24m_set_power,
271 .set_mode = tdo24m_set_mode,
272};
273
274static int __devinit tdo24m_probe(struct spi_device *spi)
275{
276 struct tdo24m *lcd;
277 struct spi_message *m;
278 struct spi_transfer *x;
279 int err;
280
281 spi->bits_per_word = 8;
282 spi->mode = SPI_MODE_3;
283 err = spi_setup(spi);
284 if (err)
285 return err;
286
287 lcd = kzalloc(sizeof(struct tdo24m), GFP_KERNEL);
288 if (!lcd)
289 return -ENOMEM;
290
291 lcd->spi_dev = spi;
292 lcd->power = FB_BLANK_POWERDOWN;
293 lcd->mode = MODE_VGA; /* default to VGA */
294
295 lcd->buf = kmalloc(TDO24M_SPI_BUFF_SIZE, sizeof(GFP_KERNEL));
296 if (lcd->buf == NULL) {
297 kfree(lcd);
298 return -ENOMEM;
299 }
300
301 m = &lcd->msg;
302 x = &lcd->xfer;
303
304 spi_message_init(m);
305
306 x->tx_buf = &lcd->buf[0];
307 spi_message_add_tail(x, m);
308
309 lcd->lcd_dev = lcd_device_register("tdo24m", &spi->dev,
310 lcd, &tdo24m_ops);
311 if (IS_ERR(lcd->lcd_dev)) {
312 err = PTR_ERR(lcd->lcd_dev);
313 goto out_free;
314 }
315
316 dev_set_drvdata(&spi->dev, lcd);
317 err = tdo24m_power(lcd, FB_BLANK_UNBLANK);
318 if (err)
319 goto out_unregister;
320
321 return 0;
322
323out_unregister:
324 lcd_device_unregister(lcd->lcd_dev);
325out_free:
326 kfree(lcd->buf);
327 kfree(lcd);
328 return err;
329}
330
331static int __devexit tdo24m_remove(struct spi_device *spi)
332{
333 struct tdo24m *lcd = dev_get_drvdata(&spi->dev);
334
335 tdo24m_power(lcd, FB_BLANK_POWERDOWN);
336 lcd_device_unregister(lcd->lcd_dev);
337 kfree(lcd->buf);
338 kfree(lcd);
339
340 return 0;
341}
342
343#ifdef CONFIG_PM
344static int tdo24m_suspend(struct spi_device *spi, pm_message_t state)
345{
346 struct tdo24m *lcd = dev_get_drvdata(&spi->dev);
347
348 return tdo24m_power(lcd, FB_BLANK_POWERDOWN);
349}
350
351static int tdo24m_resume(struct spi_device *spi)
352{
353 struct tdo24m *lcd = dev_get_drvdata(&spi->dev);
354
355 return tdo24m_power(lcd, FB_BLANK_UNBLANK);
356}
357#else
358#define tdo24m_suspend NULL
359#define tdo24m_resume NULL
360#endif
361
362/* Power down all displays on reboot, poweroff or halt */
363static void tdo24m_shutdown(struct spi_device *spi)
364{
365 struct tdo24m *lcd = dev_get_drvdata(&spi->dev);
366
367 tdo24m_power(lcd, FB_BLANK_POWERDOWN);
368}
369
370static struct spi_driver tdo24m_driver = {
371 .driver = {
372 .name = "tdo24m",
373 .owner = THIS_MODULE,
374 },
375 .probe = tdo24m_probe,
376 .remove = __devexit_p(tdo24m_remove),
377 .shutdown = tdo24m_shutdown,
378 .suspend = tdo24m_suspend,
379 .resume = tdo24m_resume,
380};
381
382static int __init tdo24m_init(void)
383{
384 return spi_register_driver(&tdo24m_driver);
385}
386module_init(tdo24m_init);
387
388static void __exit tdo24m_exit(void)
389{
390 spi_unregister_driver(&tdo24m_driver);
391}
392module_exit(tdo24m_exit);
393
394MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>");
395MODULE_DESCRIPTION("Driver for Toppoly TDO24M LCD Panel");
396MODULE_LICENSE("GPL");
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 98843c2ecf73..0737570030f5 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -979,6 +979,7 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
979 979
980 info->flags &= ~FBINFO_MISC_USEREVENT; 980 info->flags &= ~FBINFO_MISC_USEREVENT;
981 event.info = info; 981 event.info = info;
982 event.data = &mode;
982 fb_notifier_call_chain(evnt, &event); 983 fb_notifier_call_chain(evnt, &event);
983 } 984 }
984 } 985 }
diff --git a/drivers/video/metronomefb.c b/drivers/video/metronomefb.c
index cc4c038a1b3f..afeed0611e3e 100644
--- a/drivers/video/metronomefb.c
+++ b/drivers/video/metronomefb.c
@@ -40,29 +40,63 @@
40 40
41#include <asm/unaligned.h> 41#include <asm/unaligned.h>
42 42
43
44#define DEBUG 1
45#ifdef DEBUG
46#define DPRINTK(f, a...) printk(KERN_DEBUG "%s: " f, __func__ , ## a)
47#else
48#define DPRINTK(f, a...)
49#endif
50
51
52/* Display specific information */ 43/* Display specific information */
53#define DPY_W 832 44#define DPY_W 832
54#define DPY_H 622 45#define DPY_H 622
55 46
47static int user_wfm_size;
48
56/* frame differs from image. frame includes non-visible pixels */ 49/* frame differs from image. frame includes non-visible pixels */
57struct epd_frame { 50struct epd_frame {
58 int fw; /* frame width */ 51 int fw; /* frame width */
59 int fh; /* frame height */ 52 int fh; /* frame height */
53 u16 config[4];
54 int wfm_size;
60}; 55};
61 56
62static struct epd_frame epd_frame_table[] = { 57static struct epd_frame epd_frame_table[] = {
63 { 58 {
64 .fw = 832, 59 .fw = 832,
65 .fh = 622 60 .fh = 622,
61 .config = {
62 15 /* sdlew */
63 | 2 << 8 /* sdosz */
64 | 0 << 11 /* sdor */
65 | 0 << 12 /* sdces */
66 | 0 << 15, /* sdcer */
67 42 /* gdspl */
68 | 1 << 8 /* gdr1 */
69 | 1 << 9 /* sdshr */
70 | 0 << 15, /* gdspp */
71 18 /* gdspw */
72 | 0 << 15, /* dispc */
73 599 /* vdlc */
74 | 0 << 11 /* dsi */
75 | 0 << 12, /* dsic */
76 },
77 .wfm_size = 47001,
78 },
79 {
80 .fw = 1088,
81 .fh = 791,
82 .config = {
83 0x0104,
84 0x031f,
85 0x0088,
86 0x02ff,
87 },
88 .wfm_size = 46770,
89 },
90 {
91 .fw = 1200,
92 .fh = 842,
93 .config = {
94 0x0101,
95 0x030e,
96 0x0012,
97 0x0280,
98 },
99 .wfm_size = 46770,
66 }, 100 },
67}; 101};
68 102
@@ -134,9 +168,8 @@ static u16 calc_img_cksum(u16 *start, int length)
134} 168}
135 169
136/* here we decode the incoming waveform file and populate metromem */ 170/* here we decode the incoming waveform file and populate metromem */
137#define EXP_WFORM_SIZE 47001 171static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
138static int load_waveform(u8 *mem, size_t size, u8 *metromem, int m, int t, 172 struct metronomefb_par *par)
139 u8 *frame_count)
140{ 173{
141 int tta; 174 int tta;
142 int wmta; 175 int wmta;
@@ -148,26 +181,31 @@ static int load_waveform(u8 *mem, size_t size, u8 *metromem, int m, int t,
148 int wfm_idx, owfm_idx; 181 int wfm_idx, owfm_idx;
149 int mem_idx = 0; 182 int mem_idx = 0;
150 struct waveform_hdr *wfm_hdr; 183 struct waveform_hdr *wfm_hdr;
184 u8 *metromem = par->metromem_wfm;
185 struct device *dev = par->info->dev;
151 186
152 if (size != EXP_WFORM_SIZE) { 187 if (user_wfm_size)
153 printk(KERN_ERR "Error: unexpected size %d != %d\n", size, 188 epd_frame_table[par->dt].wfm_size = user_wfm_size;
154 EXP_WFORM_SIZE); 189
190 if (size != epd_frame_table[par->dt].wfm_size) {
191 dev_err(dev, "Error: unexpected size %d != %d\n", size,
192 epd_frame_table[par->dt].wfm_size);
155 return -EINVAL; 193 return -EINVAL;
156 } 194 }
157 195
158 wfm_hdr = (struct waveform_hdr *) mem; 196 wfm_hdr = (struct waveform_hdr *) mem;
159 197
160 if (wfm_hdr->fvsn != 1) { 198 if (wfm_hdr->fvsn != 1) {
161 printk(KERN_ERR "Error: bad fvsn %x\n", wfm_hdr->fvsn); 199 dev_err(dev, "Error: bad fvsn %x\n", wfm_hdr->fvsn);
162 return -EINVAL; 200 return -EINVAL;
163 } 201 }
164 if (wfm_hdr->luts != 0) { 202 if (wfm_hdr->luts != 0) {
165 printk(KERN_ERR "Error: bad luts %x\n", wfm_hdr->luts); 203 dev_err(dev, "Error: bad luts %x\n", wfm_hdr->luts);
166 return -EINVAL; 204 return -EINVAL;
167 } 205 }
168 cksum = calc_cksum(32, 47, mem); 206 cksum = calc_cksum(32, 47, mem);
169 if (cksum != wfm_hdr->wfm_cs) { 207 if (cksum != wfm_hdr->wfm_cs) {
170 printk(KERN_ERR "Error: bad cksum %x != %x\n", cksum, 208 dev_err(dev, "Error: bad cksum %x != %x\n", cksum,
171 wfm_hdr->wfm_cs); 209 wfm_hdr->wfm_cs);
172 return -EINVAL; 210 return -EINVAL;
173 } 211 }
@@ -175,7 +213,7 @@ static int load_waveform(u8 *mem, size_t size, u8 *metromem, int m, int t,
175 wfm_hdr->trc += 1; 213 wfm_hdr->trc += 1;
176 for (i = 0; i < 5; i++) { 214 for (i = 0; i < 5; i++) {
177 if (*(wfm_hdr->stuff2a + i) != 0) { 215 if (*(wfm_hdr->stuff2a + i) != 0) {
178 printk(KERN_ERR "Error: unexpected value in padding\n"); 216 dev_err(dev, "Error: unexpected value in padding\n");
179 return -EINVAL; 217 return -EINVAL;
180 } 218 }
181 } 219 }
@@ -200,7 +238,7 @@ static int load_waveform(u8 *mem, size_t size, u8 *metromem, int m, int t,
200 return -EINVAL; 238 return -EINVAL;
201 cksum = calc_cksum(sizeof(*wfm_hdr), cksum_idx, mem); 239 cksum = calc_cksum(sizeof(*wfm_hdr), cksum_idx, mem);
202 if (cksum != mem[cksum_idx]) { 240 if (cksum != mem[cksum_idx]) {
203 printk(KERN_ERR "Error: bad temperature range table cksum" 241 dev_err(dev, "Error: bad temperature range table cksum"
204 " %x != %x\n", cksum, mem[cksum_idx]); 242 " %x != %x\n", cksum, mem[cksum_idx]);
205 return -EINVAL; 243 return -EINVAL;
206 } 244 }
@@ -212,7 +250,7 @@ static int load_waveform(u8 *mem, size_t size, u8 *metromem, int m, int t,
212 return -EINVAL; 250 return -EINVAL;
213 cksum = calc_cksum(cksum_idx - 3, cksum_idx, mem); 251 cksum = calc_cksum(cksum_idx - 3, cksum_idx, mem);
214 if (cksum != mem[cksum_idx]) { 252 if (cksum != mem[cksum_idx]) {
215 printk(KERN_ERR "Error: bad mode table address cksum" 253 dev_err(dev, "Error: bad mode table address cksum"
216 " %x != %x\n", cksum, mem[cksum_idx]); 254 " %x != %x\n", cksum, mem[cksum_idx]);
217 return -EINVAL; 255 return -EINVAL;
218 } 256 }
@@ -224,7 +262,7 @@ static int load_waveform(u8 *mem, size_t size, u8 *metromem, int m, int t,
224 return -EINVAL; 262 return -EINVAL;
225 cksum = calc_cksum(cksum_idx - 3, cksum_idx, mem); 263 cksum = calc_cksum(cksum_idx - 3, cksum_idx, mem);
226 if (cksum != mem[cksum_idx]) { 264 if (cksum != mem[cksum_idx]) {
227 printk(KERN_ERR "Error: bad temperature table address cksum" 265 dev_err(dev, "Error: bad temperature table address cksum"
228 " %x != %x\n", cksum, mem[cksum_idx]); 266 " %x != %x\n", cksum, mem[cksum_idx]);
229 return -EINVAL; 267 return -EINVAL;
230 } 268 }
@@ -259,11 +297,11 @@ static int load_waveform(u8 *mem, size_t size, u8 *metromem, int m, int t,
259 return -EINVAL; 297 return -EINVAL;
260 cksum = calc_cksum(owfm_idx, cksum_idx, mem); 298 cksum = calc_cksum(owfm_idx, cksum_idx, mem);
261 if (cksum != mem[cksum_idx]) { 299 if (cksum != mem[cksum_idx]) {
262 printk(KERN_ERR "Error: bad waveform data cksum" 300 dev_err(dev, "Error: bad waveform data cksum"
263 " %x != %x\n", cksum, mem[cksum_idx]); 301 " %x != %x\n", cksum, mem[cksum_idx]);
264 return -EINVAL; 302 return -EINVAL;
265 } 303 }
266 *frame_count = (mem_idx/64); 304 par->frame_count = (mem_idx/64);
267 305
268 return 0; 306 return 0;
269} 307}
@@ -274,15 +312,12 @@ static int metronome_display_cmd(struct metronomefb_par *par)
274 u16 cs; 312 u16 cs;
275 u16 opcode; 313 u16 opcode;
276 static u8 borderval; 314 static u8 borderval;
277 u8 *ptr;
278 315
279 /* setup display command 316 /* setup display command
280 we can't immediately set the opcode since the controller 317 we can't immediately set the opcode since the controller
281 will try parse the command before we've set it all up 318 will try parse the command before we've set it all up
282 so we just set cs here and set the opcode at the end */ 319 so we just set cs here and set the opcode at the end */
283 320
284 ptr = par->metromem;
285
286 if (par->metromem_cmd->opcode == 0xCC40) 321 if (par->metromem_cmd->opcode == 0xCC40)
287 opcode = cs = 0xCC41; 322 opcode = cs = 0xCC41;
288 else 323 else
@@ -335,44 +370,17 @@ static int __devinit metronome_powerup_cmd(struct metronomefb_par *par)
335 370
336static int __devinit metronome_config_cmd(struct metronomefb_par *par) 371static int __devinit metronome_config_cmd(struct metronomefb_par *par)
337{ 372{
338 int i;
339 u16 cs;
340
341 /* setup config command 373 /* setup config command
342 we can't immediately set the opcode since the controller 374 we can't immediately set the opcode since the controller
343 will try parse the command before we've set it all up 375 will try parse the command before we've set it all up */
344 so we just set cs here and set the opcode at the end */
345
346 cs = 0xCC10;
347
348 /* set the 12 args ( 8 bytes ) for config. see spec for meanings */
349 i = 0;
350 par->metromem_cmd->args[i] = 15 /* sdlew */
351 | 2 << 8 /* sdosz */
352 | 0 << 11 /* sdor */
353 | 0 << 12 /* sdces */
354 | 0 << 15; /* sdcer */
355 cs += par->metromem_cmd->args[i++];
356
357 par->metromem_cmd->args[i] = 42 /* gdspl */
358 | 1 << 8 /* gdr1 */
359 | 1 << 9 /* sdshr */
360 | 0 << 15; /* gdspp */
361 cs += par->metromem_cmd->args[i++];
362
363 par->metromem_cmd->args[i] = 18 /* gdspw */
364 | 0 << 15; /* dispc */
365 cs += par->metromem_cmd->args[i++];
366
367 par->metromem_cmd->args[i] = 599 /* vdlc */
368 | 0 << 11 /* dsi */
369 | 0 << 12; /* dsic */
370 cs += par->metromem_cmd->args[i++];
371 376
377 memcpy(par->metromem_cmd->args, epd_frame_table[par->dt].config,
378 sizeof(epd_frame_table[par->dt].config));
372 /* the rest are 0 */ 379 /* the rest are 0 */
373 memset((u8 *) (par->metromem_cmd->args + i), 0, (32-i)*2); 380 memset((u8 *) (par->metromem_cmd->args + 4), 0, (32-4)*2);
374 381
375 par->metromem_cmd->csum = cs; 382 par->metromem_cmd->csum = 0xCC10;
383 par->metromem_cmd->csum += calc_img_cksum(par->metromem_cmd->args, 4);
376 par->metromem_cmd->opcode = 0xCC10; /* config cmd */ 384 par->metromem_cmd->opcode = 0xCC10; /* config cmd */
377 385
378 return par->board->met_wait_event(par); 386 return par->board->met_wait_event(par);
@@ -408,12 +416,9 @@ static int __devinit metronome_init_regs(struct metronomefb_par *par)
408{ 416{
409 int res; 417 int res;
410 418
411 par->board->init_gpio_regs(par); 419 res = par->board->setup_io(par);
412 420 if (res)
413 par->board->init_lcdc_regs(par); 421 return res;
414
415 /* now that lcd is setup, setup dma descriptor */
416 par->board->post_dma_setup(par);
417 422
418 res = metronome_powerup_cmd(par); 423 res = metronome_powerup_cmd(par);
419 if (res) 424 if (res)
@@ -430,16 +435,16 @@ static int __devinit metronome_init_regs(struct metronomefb_par *par)
430 435
431static void metronomefb_dpy_update(struct metronomefb_par *par) 436static void metronomefb_dpy_update(struct metronomefb_par *par)
432{ 437{
438 int fbsize;
433 u16 cksum; 439 u16 cksum;
434 unsigned char *buf = (unsigned char __force *)par->info->screen_base; 440 unsigned char *buf = (unsigned char __force *)par->info->screen_base;
435 441
442 fbsize = par->info->fix.smem_len;
436 /* copy from vm to metromem */ 443 /* copy from vm to metromem */
437 memcpy(par->metromem_img, buf, DPY_W*DPY_H); 444 memcpy(par->metromem_img, buf, fbsize);
438 445
439 cksum = calc_img_cksum((u16 *) par->metromem_img, 446 cksum = calc_img_cksum((u16 *) par->metromem_img, fbsize/2);
440 (epd_frame_table[0].fw * DPY_H)/2); 447 *((u16 *)(par->metromem_img) + fbsize/2) = cksum;
441 *((u16 *)(par->metromem_img) +
442 (epd_frame_table[0].fw * DPY_H)/2) = cksum;
443 metronome_display_cmd(par); 448 metronome_display_cmd(par);
444} 449}
445 450
@@ -574,8 +579,10 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
574 unsigned char *videomemory; 579 unsigned char *videomemory;
575 struct metronomefb_par *par; 580 struct metronomefb_par *par;
576 const struct firmware *fw_entry; 581 const struct firmware *fw_entry;
577 int cmd_size, wfm_size, img_size, padding_size, totalsize;
578 int i; 582 int i;
583 int panel_type;
584 int fw, fh;
585 int epd_dt_index;
579 586
580 /* pick up board specific routines */ 587 /* pick up board specific routines */
581 board = dev->dev.platform_data; 588 board = dev->dev.platform_data;
@@ -586,96 +593,108 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
586 if (!try_module_get(board->owner)) 593 if (!try_module_get(board->owner))
587 return -ENODEV; 594 return -ENODEV;
588 595
596 info = framebuffer_alloc(sizeof(struct metronomefb_par), &dev->dev);
597 if (!info)
598 goto err;
599
589 /* we have two blocks of memory. 600 /* we have two blocks of memory.
590 info->screen_base which is vm, and is the fb used by apps. 601 info->screen_base which is vm, and is the fb used by apps.
591 par->metromem which is physically contiguous memory and 602 par->metromem which is physically contiguous memory and
592 contains the display controller commands, waveform, 603 contains the display controller commands, waveform,
593 processed image data and padding. this is the data pulled 604 processed image data and padding. this is the data pulled
594 by the device's LCD controller and pushed to Metronome */ 605 by the device's LCD controller and pushed to Metronome.
606 the metromem memory is allocated by the board driver and
607 is provided to us */
608
609 panel_type = board->get_panel_type();
610 switch (panel_type) {
611 case 6:
612 epd_dt_index = 0;
613 break;
614 case 8:
615 epd_dt_index = 1;
616 break;
617 case 97:
618 epd_dt_index = 2;
619 break;
620 default:
621 dev_err(&dev->dev, "Unexpected panel type. Defaulting to 6\n");
622 epd_dt_index = 0;
623 break;
624 }
625
626 fw = epd_frame_table[epd_dt_index].fw;
627 fh = epd_frame_table[epd_dt_index].fh;
595 628
596 videomemorysize = (DPY_W*DPY_H); 629 /* we need to add a spare page because our csum caching scheme walks
630 * to the end of the page */
631 videomemorysize = PAGE_SIZE + (fw * fh);
597 videomemory = vmalloc(videomemorysize); 632 videomemory = vmalloc(videomemorysize);
598 if (!videomemory) 633 if (!videomemory)
599 return -ENOMEM; 634 goto err_fb_rel;
600 635
601 memset(videomemory, 0, videomemorysize); 636 memset(videomemory, 0, videomemorysize);
602 637
603 info = framebuffer_alloc(sizeof(struct metronomefb_par), &dev->dev);
604 if (!info)
605 goto err_vfree;
606
607 info->screen_base = (char __force __iomem *)videomemory; 638 info->screen_base = (char __force __iomem *)videomemory;
608 info->fbops = &metronomefb_ops; 639 info->fbops = &metronomefb_ops;
609 640
641 metronomefb_fix.line_length = fw;
642 metronomefb_var.xres = fw;
643 metronomefb_var.yres = fh;
644 metronomefb_var.xres_virtual = fw;
645 metronomefb_var.yres_virtual = fh;
610 info->var = metronomefb_var; 646 info->var = metronomefb_var;
611 info->fix = metronomefb_fix; 647 info->fix = metronomefb_fix;
612 info->fix.smem_len = videomemorysize; 648 info->fix.smem_len = videomemorysize;
613 par = info->par; 649 par = info->par;
614 par->info = info; 650 par->info = info;
615 par->board = board; 651 par->board = board;
652 par->dt = epd_dt_index;
616 init_waitqueue_head(&par->waitq); 653 init_waitqueue_head(&par->waitq);
617 654
618 /* this table caches per page csum values. */ 655 /* this table caches per page csum values. */
619 par->csum_table = vmalloc(videomemorysize/PAGE_SIZE); 656 par->csum_table = vmalloc(videomemorysize/PAGE_SIZE);
620 if (!par->csum_table) 657 if (!par->csum_table)
658 goto err_vfree;
659
660 /* the physical framebuffer that we use is setup by
661 * the platform device driver. It will provide us
662 * with cmd, wfm and image memory in a contiguous area. */
663 retval = board->setup_fb(par);
664 if (retval) {
665 dev_err(&dev->dev, "Failed to setup fb\n");
621 goto err_csum_table; 666 goto err_csum_table;
667 }
622 668
623 /* the metromem buffer is divided as follows: 669 /* after this point we should have a framebuffer */
624 command | CRC | padding 670 if ((!par->metromem_wfm) || (!par->metromem_img) ||
625 16kb waveform data | CRC | padding 671 (!par->metromem_dma)) {
626 image data | CRC 672 dev_err(&dev->dev, "fb access failure\n");
627 and an extra 256 bytes for dma descriptors 673 retval = -EINVAL;
628 eg: IW=832 IH=622 WS=128 674 goto err_csum_table;
629 */
630
631 cmd_size = 1 * epd_frame_table[0].fw;
632 wfm_size = ((16*1024 + 2 + epd_frame_table[0].fw - 1)
633 / epd_frame_table[0].fw) * epd_frame_table[0].fw;
634 img_size = epd_frame_table[0].fh * epd_frame_table[0].fw;
635 padding_size = 4 * epd_frame_table[0].fw;
636 totalsize = cmd_size + wfm_size + img_size + padding_size;
637 par->metromemsize = PAGE_ALIGN(totalsize + 256);
638 DPRINTK("desired memory size = %d\n", par->metromemsize);
639 dev->dev.coherent_dma_mask = 0xffffffffull;
640 par->metromem = dma_alloc_writecombine(&dev->dev, par->metromemsize,
641 &par->metromem_dma, GFP_KERNEL);
642 if (!par->metromem) {
643 printk(KERN_ERR
644 "metronomefb: unable to allocate dma buffer\n");
645 goto err_vfree;
646 } 675 }
647 676
648 info->fix.smem_start = par->metromem_dma; 677 info->fix.smem_start = par->metromem_dma;
649 par->metromem_cmd = (struct metromem_cmd *) par->metromem;
650 par->metromem_wfm = par->metromem + cmd_size;
651 par->metromem_img = par->metromem + cmd_size + wfm_size;
652 par->metromem_img_csum = (u16 *) (par->metromem_img +
653 (epd_frame_table[0].fw * DPY_H));
654 DPRINTK("img offset=0x%x\n", cmd_size + wfm_size);
655 par->metromem_desc = (struct metromem_desc *) (par->metromem + cmd_size
656 + wfm_size + img_size + padding_size);
657 par->metromem_desc_dma = par->metromem_dma + cmd_size + wfm_size
658 + img_size + padding_size;
659 678
660 /* load the waveform in. assume mode 3, temp 31 for now 679 /* load the waveform in. assume mode 3, temp 31 for now
661 a) request the waveform file from userspace 680 a) request the waveform file from userspace
662 b) process waveform and decode into metromem */ 681 b) process waveform and decode into metromem */
663 retval = request_firmware(&fw_entry, "metronome.wbf", &dev->dev); 682 retval = request_firmware(&fw_entry, "metronome.wbf", &dev->dev);
664 if (retval < 0) { 683 if (retval < 0) {
665 printk(KERN_ERR "metronomefb: couldn't get waveform\n"); 684 dev_err(&dev->dev, "Failed to get waveform\n");
666 goto err_dma_free; 685 goto err_csum_table;
667 } 686 }
668 687
669 retval = load_waveform((u8 *) fw_entry->data, fw_entry->size, 688 retval = load_waveform((u8 *) fw_entry->data, fw_entry->size, 3, 31,
670 par->metromem_wfm, 3, 31, &par->frame_count); 689 par);
671 release_firmware(fw_entry); 690 release_firmware(fw_entry);
672 if (retval < 0) { 691 if (retval < 0) {
673 printk(KERN_ERR "metronomefb: couldn't process waveform\n"); 692 dev_err(&dev->dev, "Failed processing waveform\n");
674 goto err_dma_free; 693 goto err_csum_table;
675 } 694 }
676 695
677 if (board->setup_irq(info)) 696 if (board->setup_irq(info))
678 goto err_dma_free; 697 goto err_csum_table;
679 698
680 retval = metronome_init_regs(par); 699 retval = metronome_init_regs(par);
681 if (retval < 0) 700 if (retval < 0)
@@ -688,8 +707,8 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
688 707
689 retval = fb_alloc_cmap(&info->cmap, 8, 0); 708 retval = fb_alloc_cmap(&info->cmap, 8, 0);
690 if (retval < 0) { 709 if (retval < 0) {
691 printk(KERN_ERR "Failed to allocate colormap\n"); 710 dev_err(&dev->dev, "Failed to allocate colormap\n");
692 goto err_fb_rel; 711 goto err_free_irq;
693 } 712 }
694 713
695 /* set cmap */ 714 /* set cmap */
@@ -704,7 +723,7 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
704 723
705 platform_set_drvdata(dev, info); 724 platform_set_drvdata(dev, info);
706 725
707 printk(KERN_INFO 726 dev_dbg(&dev->dev,
708 "fb%d: Metronome frame buffer device, using %dK of video" 727 "fb%d: Metronome frame buffer device, using %dK of video"
709 " memory\n", info->node, videomemorysize >> 10); 728 " memory\n", info->node, videomemorysize >> 10);
710 729
@@ -712,17 +731,15 @@ static int __devinit metronomefb_probe(struct platform_device *dev)
712 731
713err_cmap: 732err_cmap:
714 fb_dealloc_cmap(&info->cmap); 733 fb_dealloc_cmap(&info->cmap);
715err_fb_rel:
716 framebuffer_release(info);
717err_free_irq: 734err_free_irq:
718 board->free_irq(info); 735 board->cleanup(par);
719err_dma_free:
720 dma_free_writecombine(&dev->dev, par->metromemsize, par->metromem,
721 par->metromem_dma);
722err_csum_table: 736err_csum_table:
723 vfree(par->csum_table); 737 vfree(par->csum_table);
724err_vfree: 738err_vfree:
725 vfree(videomemory); 739 vfree(videomemory);
740err_fb_rel:
741 framebuffer_release(info);
742err:
726 module_put(board->owner); 743 module_put(board->owner);
727 return retval; 744 return retval;
728} 745}
@@ -733,15 +750,15 @@ static int __devexit metronomefb_remove(struct platform_device *dev)
733 750
734 if (info) { 751 if (info) {
735 struct metronomefb_par *par = info->par; 752 struct metronomefb_par *par = info->par;
753
754 unregister_framebuffer(info);
736 fb_deferred_io_cleanup(info); 755 fb_deferred_io_cleanup(info);
737 dma_free_writecombine(&dev->dev, par->metromemsize,
738 par->metromem, par->metromem_dma);
739 fb_dealloc_cmap(&info->cmap); 756 fb_dealloc_cmap(&info->cmap);
757 par->board->cleanup(par);
740 vfree(par->csum_table); 758 vfree(par->csum_table);
741 unregister_framebuffer(info);
742 vfree((void __force *)info->screen_base); 759 vfree((void __force *)info->screen_base);
743 par->board->free_irq(info);
744 module_put(par->board->owner); 760 module_put(par->board->owner);
761 dev_dbg(&dev->dev, "calling release\n");
745 framebuffer_release(info); 762 framebuffer_release(info);
746 } 763 }
747 return 0; 764 return 0;
@@ -766,6 +783,9 @@ static void __exit metronomefb_exit(void)
766 platform_driver_unregister(&metronomefb_driver); 783 platform_driver_unregister(&metronomefb_driver);
767} 784}
768 785
786module_param(user_wfm_size, uint, 0);
787MODULE_PARM_DESC(user_wfm_size, "Set custom waveform size");
788
769module_init(metronomefb_init); 789module_init(metronomefb_init);
770module_exit(metronomefb_exit); 790module_exit(metronomefb_exit);
771 791