2 * LCD / Backlight control code for Sharp SL-6000x (tosa)
4 * Copyright (c) 2005 Dirk Opfer
5 * Copyright (c) 2007,2008 Dmitry Baryshkov
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 * published by the Free Software Foundation.
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/device.h>
16 #include <linux/spi/spi.h>
17 #include <linux/i2c.h>
18 #include <linux/slab.h>
19 #include <linux/gpio.h>
20 #include <linux/delay.h>
21 #include <linux/lcd.h>
24 #include <asm/mach/sharpsl_param.h>
26 #include <mach/tosa.h>
28 #define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
30 #define TG_REG0_VQV 0x0001
31 #define TG_REG0_COLOR 0x0002
32 #define TG_REG0_UD 0x0004
33 #define TG_REG0_LR 0x0008
37 struct tosa_lcd_data
{
38 struct spi_device
*spi
;
39 struct lcd_device
*lcd
;
40 struct i2c_client
*i2c
;
46 static int tosa_tg_send(struct spi_device
*spi
, int adrs
, uint8_t data
)
49 struct spi_message msg
;
50 struct spi_transfer xfer
= {
56 buf
[0] = ((adrs
& 0x07) << 5) | (data
& 0x1f);
57 spi_message_init(&msg
);
58 spi_message_add_tail(&xfer
, &msg
);
60 return spi_sync(spi
, &msg
);
63 int tosa_bl_enable(struct spi_device
*spi
, int enable
)
65 /* bl_enable GP04=1 otherwise GP04=0*/
66 return tosa_tg_send(spi
, TG_GPODR2
, enable
? 0x01 : 0x00);
68 EXPORT_SYMBOL(tosa_bl_enable
);
70 static void tosa_lcd_tg_init(struct tosa_lcd_data
*data
)
73 gpio_set_value(TOSA_GPIO_TG_ON
, 0);
77 /* delayed 0clk TCTL signal for VGA */
78 tosa_tg_send(data
->spi
, TG_TPOSCTL
, 0x00);
79 /* GPOS0=powercontrol, GPOS1=GPIO, GPOS2=TCTL */
80 tosa_tg_send(data
->spi
, TG_GPOSR
, 0x02);
83 static void tosa_lcd_tg_on(struct tosa_lcd_data
*data
)
85 struct spi_device
*spi
= data
->spi
;
86 int value
= TG_REG0_COLOR
| TG_REG0_UD
| TG_REG0_LR
;
91 tosa_tg_send(spi
, TG_PNLCTL
, value
);
93 /* TG LCD pannel power up */
94 tosa_tg_send(spi
, TG_PINICTL
,0x4);
98 tosa_tg_send(spi
, TG_PINICTL
,0x0);
101 /* after the pannel is powered up the first time, we can access the i2c bus */
102 /* so probe for the DAC */
103 struct i2c_adapter
*adap
= i2c_get_adapter(0);
104 struct i2c_board_info info
= {
107 .platform_data
= data
->spi
,
109 data
->i2c
= i2c_new_device(adap
, &info
);
113 static void tosa_lcd_tg_off(struct tosa_lcd_data
*data
)
115 struct spi_device
*spi
= data
->spi
;
117 /* TG LCD VHSA off */
118 tosa_tg_send(spi
, TG_PINICTL
,0x4);
121 /* TG LCD signal off */
122 tosa_tg_send(spi
, TG_PINICTL
,0x6);
126 gpio_set_value(TOSA_GPIO_TG_ON
, 1);
130 int tosa_lcd_set_power(struct lcd_device
*lcd
, int power
)
132 struct tosa_lcd_data
*data
= lcd_get_data(lcd
);
134 if (POWER_IS_ON(power
) && !POWER_IS_ON(data
->lcd_power
))
135 tosa_lcd_tg_on(data
);
137 if (!POWER_IS_ON(power
) && POWER_IS_ON(data
->lcd_power
))
138 tosa_lcd_tg_off(data
);
140 data
->lcd_power
= power
;
144 static int tosa_lcd_get_power(struct lcd_device
*lcd
)
146 struct tosa_lcd_data
*data
= lcd_get_data(lcd
);
148 return data
->lcd_power
;
151 static int tosa_lcd_set_mode(struct lcd_device
*lcd
, struct fb_videomode
*mode
)
153 struct tosa_lcd_data
*data
= lcd_get_data(lcd
);
155 if (mode
->xres
== 320 || mode
->yres
== 320)
156 data
->is_vga
= false;
160 if (POWER_IS_ON(data
->lcd_power
))
161 tosa_lcd_tg_on(data
);
166 static struct lcd_ops tosa_lcd_ops
= {
167 .set_power
= tosa_lcd_set_power
,
168 .get_power
= tosa_lcd_get_power
,
169 .set_mode
= tosa_lcd_set_mode
,
172 static int __devinit
tosa_lcd_probe(struct spi_device
*spi
)
175 struct tosa_lcd_data
*data
;
177 data
= kzalloc(sizeof(struct tosa_lcd_data
), GFP_KERNEL
);
181 data
->is_vga
= true; /* default to VGA mode */
184 * bits_per_word cannot be configured in platform data
186 spi
->bits_per_word
= 8;
188 ret
= spi_setup(spi
);
193 dev_set_drvdata(&spi
->dev
, data
);
195 ret
= gpio_request(TOSA_GPIO_TG_ON
, "tg #pwr");
201 ret
= gpio_direction_output(TOSA_GPIO_TG_ON
, 0);
206 tosa_lcd_tg_init(data
);
208 tosa_lcd_tg_on(data
);
210 data
->lcd
= lcd_device_register("tosa-lcd", &spi
->dev
, data
,
213 if (IS_ERR(data
->lcd
)) {
214 ret
= PTR_ERR(data
->lcd
);
222 tosa_lcd_tg_off(data
);
224 gpio_free(TOSA_GPIO_TG_ON
);
226 dev_set_drvdata(&spi
->dev
, NULL
);
232 static int __devexit
tosa_lcd_remove(struct spi_device
*spi
)
234 struct tosa_lcd_data
*data
= dev_get_drvdata(&spi
->dev
);
236 lcd_device_unregister(data
->lcd
);
239 i2c_unregister_device(data
->i2c
);
241 tosa_lcd_tg_off(data
);
243 gpio_free(TOSA_GPIO_TG_ON
);
244 dev_set_drvdata(&spi
->dev
, NULL
);
251 static int tosa_lcd_suspend(struct spi_device
*spi
, pm_message_t state
)
253 struct tosa_lcd_data
*data
= dev_get_drvdata(&spi
->dev
);
255 tosa_lcd_tg_off(data
);
260 static int tosa_lcd_resume(struct spi_device
*spi
)
262 struct tosa_lcd_data
*data
= dev_get_drvdata(&spi
->dev
);
264 tosa_lcd_tg_init(data
);
265 if (POWER_IS_ON(data
->lcd_power
))
266 tosa_lcd_tg_on(data
);
268 tosa_lcd_tg_off(data
);
273 #define tosa_lcd_suspend NULL
274 #define tosa_lcd_resume NULL
277 static struct spi_driver tosa_lcd_driver
= {
280 .owner
= THIS_MODULE
,
282 .probe
= tosa_lcd_probe
,
283 .remove
= __devexit_p(tosa_lcd_remove
),
284 .suspend
= tosa_lcd_suspend
,
285 .resume
= tosa_lcd_resume
,
288 static int __init
tosa_lcd_init(void)
290 return spi_register_driver(&tosa_lcd_driver
);
293 static void __exit
tosa_lcd_exit(void)
295 spi_unregister_driver(&tosa_lcd_driver
);
298 module_init(tosa_lcd_init
);
299 module_exit(tosa_lcd_exit
);
301 MODULE_AUTHOR("Dmitry Baryshkov");
302 MODULE_LICENSE("GPL v2");
303 MODULE_DESCRIPTION("LCD/Backlight control for Sharp SL-6000 PDA");
304 MODULE_ALIAS("spi:tosa-lcd");