diff options
Diffstat (limited to 'drivers/video/backlight')
-rw-r--r-- | drivers/video/backlight/Kconfig | 15 | ||||
-rw-r--r-- | drivers/video/backlight/Makefile | 2 | ||||
-rw-r--r-- | drivers/video/backlight/corgi_lcd.c | 641 | ||||
-rw-r--r-- | drivers/video/backlight/lcd.c | 18 | ||||
-rw-r--r-- | drivers/video/backlight/tdo24m.c | 396 |
5 files changed, 1069 insertions, 3 deletions
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 | ||
27 | config 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 | |||
27 | config LCD_LTV350QV | 34 | config 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 | ||
54 | config 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 | |||
47 | config LCD_VGG2432A4 | 62 | config 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 | ||
3 | obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o | 3 | obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o |
4 | obj-$(CONFIG_LCD_CORGI) += corgi_lcd.o | ||
4 | obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o | 5 | obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o |
5 | obj-$(CONFIG_LCD_ILI9320) += ili9320.o | 6 | obj-$(CONFIG_LCD_ILI9320) += ili9320.o |
6 | obj-$(CONFIG_LCD_PLATFORM) += platform_lcd.o | 7 | obj-$(CONFIG_LCD_PLATFORM) += platform_lcd.o |
7 | obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o | 8 | obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o |
9 | obj-$(CONFIG_LCD_TDO24M) += tdo24m.o | ||
8 | 10 | ||
9 | obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o | 11 | obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o |
10 | obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.o | 12 | obj-$(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 | |||
85 | struct 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 | |||
103 | static int corgi_ssp_lcdtg_send(struct corgi_lcd *lcd, int reg, uint8_t val); | ||
104 | |||
105 | static struct corgi_lcd *the_corgi_lcd; | ||
106 | static 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 | */ | ||
114 | static 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 | |||
120 | static 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 | |||
127 | static 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 | |||
134 | static 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 | |||
141 | static 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 | |||
154 | static void lcdtg_i2c_wait_ack(struct corgi_lcd *lcd, uint8_t base) | ||
155 | { | ||
156 | lcdtg_i2c_send_bit(lcd, base); | ||
157 | } | ||
158 | |||
159 | static 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 | |||
173 | static 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 */ | ||
190 | static 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 | |||
211 | static 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 | |||
297 | static 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 | |||
337 | static 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 | |||
364 | static 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 | |||
378 | static 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 | |||
385 | static 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 | |||
391 | static 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 | |||
398 | static 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 | |||
423 | static 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 | |||
442 | void 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 | } | ||
451 | EXPORT_SYMBOL(corgibl_limit_intensity); | ||
452 | |||
453 | static 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 | ||
459 | static 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 | |||
469 | static 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 | |||
483 | static 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 | |||
527 | err_free_backlight_on: | ||
528 | if (gpio_is_valid(lcd->gpio_backlight_on)) | ||
529 | gpio_free(lcd->gpio_backlight_on); | ||
530 | return err; | ||
531 | } | ||
532 | |||
533 | static 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 | |||
585 | err_unregister_bl: | ||
586 | backlight_device_unregister(lcd->bl_dev); | ||
587 | err_unregister_lcd: | ||
588 | lcd_device_unregister(lcd->lcd_dev); | ||
589 | err_free_lcd: | ||
590 | kfree(lcd); | ||
591 | return ret; | ||
592 | } | ||
593 | |||
594 | static 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 | |||
616 | static 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 | |||
627 | static int __init corgi_lcd_init(void) | ||
628 | { | ||
629 | return spi_register_driver(&corgi_lcd_driver); | ||
630 | } | ||
631 | module_init(corgi_lcd_init); | ||
632 | |||
633 | static void __exit corgi_lcd_exit(void) | ||
634 | { | ||
635 | spi_unregister_driver(&corgi_lcd_driver); | ||
636 | } | ||
637 | module_exit(corgi_lcd_exit); | ||
638 | |||
639 | MODULE_DESCRIPTION("LCD and backlight driver for SHARP C7x0/Cxx00"); | ||
640 | MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"); | ||
641 | MODULE_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 | |||
26 | struct 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 | |||
45 | static 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 | |||
53 | static 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 | |||
61 | static 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 | |||
69 | static 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 | |||
78 | static 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 | |||
87 | static 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 | |||
100 | static 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 | |||
113 | static 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 | |||
144 | static 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 | |||
183 | static 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 | |||
204 | static 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); | ||
217 | out: | ||
218 | return err; | ||
219 | } | ||
220 | |||
221 | static int tdo24m_power_off(struct tdo24m *lcd) | ||
222 | { | ||
223 | return tdo24m_writes(lcd, lcd_panel_off); | ||
224 | } | ||
225 | |||
226 | static 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 | |||
242 | static 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 | |||
248 | static int tdo24m_get_power(struct lcd_device *ld) | ||
249 | { | ||
250 | struct tdo24m *lcd = lcd_get_data(ld); | ||
251 | return lcd->power; | ||
252 | } | ||
253 | |||
254 | static 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 | |||
268 | static 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 | |||
274 | static 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 | |||
323 | out_unregister: | ||
324 | lcd_device_unregister(lcd->lcd_dev); | ||
325 | out_free: | ||
326 | kfree(lcd->buf); | ||
327 | kfree(lcd); | ||
328 | return err; | ||
329 | } | ||
330 | |||
331 | static 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 | ||
344 | static 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 | |||
351 | static 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 */ | ||
363 | static 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 | |||
370 | static 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 | |||
382 | static int __init tdo24m_init(void) | ||
383 | { | ||
384 | return spi_register_driver(&tdo24m_driver); | ||
385 | } | ||
386 | module_init(tdo24m_init); | ||
387 | |||
388 | static void __exit tdo24m_exit(void) | ||
389 | { | ||
390 | spi_unregister_driver(&tdo24m_driver); | ||
391 | } | ||
392 | module_exit(tdo24m_exit); | ||
393 | |||
394 | MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"); | ||
395 | MODULE_DESCRIPTION("Driver for Toppoly TDO24M LCD Panel"); | ||
396 | MODULE_LICENSE("GPL"); | ||