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/gpio.h>
19 #include <linux/delay.h>
20 #include <linux/lcd.h>
23 #include <asm/mach/sharpsl_param.h>
25 #include <mach/tosa.h>
27 #define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
29 #define TG_REG0_VQV 0x0001
30 #define TG_REG0_COLOR 0x0002
31 #define TG_REG0_UD 0x0004
32 #define TG_REG0_LR 0x0008
36 struct tosa_lcd_data {
37 struct spi_device *spi;
38 struct lcd_device *lcd;
39 struct i2c_client *i2c;
44 static int tosa_tg_send(struct spi_device *spi, int adrs, uint8_t data)
47 struct spi_message msg;
48 struct spi_transfer xfer = {
54 buf[0] = ((adrs & 0x07) << 5) | (data & 0x1f);
55 spi_message_init(&msg);
56 spi_message_add_tail(&xfer, &msg);
58 return spi_sync(spi, &msg);
61 int tosa_bl_enable(struct spi_device *spi, int enable)
63 /* bl_enable GP04=1 otherwise GP04=0*/
64 return tosa_tg_send(spi, TG_GPODR2, enable? 0x01 : 0x00);
66 EXPORT_SYMBOL(tosa_bl_enable);
68 static void tosa_lcd_tg_init(struct tosa_lcd_data *data)
71 gpio_set_value(TOSA_GPIO_TG_ON, 0);
75 /* delayed 0clk TCTL signal for VGA */
76 tosa_tg_send(data->spi, TG_TPOSCTL, 0x00);
77 /* GPOS0=powercontrol, GPOS1=GPIO, GPOS2=TCTL */
78 tosa_tg_send(data->spi, TG_GPOSR, 0x02);
81 static void tosa_lcd_tg_on(struct tosa_lcd_data *data)
83 struct spi_device *spi = data->spi;
84 const int value = TG_REG0_COLOR | TG_REG0_UD | TG_REG0_LR;
85 tosa_tg_send(spi, TG_PNLCTL, value | TG_REG0_VQV); /* this depends on mode */
87 /* TG LCD pannel power up */
88 tosa_tg_send(spi, TG_PINICTL,0x4);
92 tosa_tg_send(spi, TG_PINICTL,0x0);
95 /* after the pannel is powered up the first time, we can access the i2c bus */
96 /* so probe for the DAC */
97 struct i2c_adapter *adap = i2c_get_adapter(0);
98 struct i2c_board_info info = {
101 .platform_data = data->spi,
103 data->i2c = i2c_new_device(adap, &info);
107 static void tosa_lcd_tg_off(struct tosa_lcd_data *data)
109 struct spi_device *spi = data->spi;
111 /* TG LCD VHSA off */
112 tosa_tg_send(spi, TG_PINICTL,0x4);
115 /* TG LCD signal off */
116 tosa_tg_send(spi, TG_PINICTL,0x6);
120 gpio_set_value(TOSA_GPIO_TG_ON, 1);
124 int tosa_lcd_set_power(struct lcd_device *lcd, int power)
126 struct tosa_lcd_data *data = lcd_get_data(lcd);
128 if (POWER_IS_ON(power) && !POWER_IS_ON(data->lcd_power))
129 tosa_lcd_tg_on(data);
131 if (!POWER_IS_ON(power) && POWER_IS_ON(data->lcd_power))
132 tosa_lcd_tg_off(data);
134 data->lcd_power = power;
138 static int tosa_lcd_get_power(struct lcd_device *lcd)
140 struct tosa_lcd_data *data = lcd_get_data(lcd);
142 return data->lcd_power;
145 static struct lcd_ops tosa_lcd_ops = {
146 .set_power = tosa_lcd_set_power,
147 .get_power = tosa_lcd_get_power,
150 static int __devinit tosa_lcd_probe(struct spi_device *spi)
153 struct tosa_lcd_data *data;
155 data = kzalloc(sizeof(struct tosa_lcd_data), GFP_KERNEL);
160 * bits_per_word cannot be configured in platform data
162 spi->bits_per_word = 8;
164 ret = spi_setup(spi);
169 dev_set_drvdata(&spi->dev, data);
171 ret = gpio_request(TOSA_GPIO_TG_ON, "tg #pwr");
177 ret = gpio_direction_output(TOSA_GPIO_TG_ON, 0);
182 tosa_lcd_tg_init(data);
184 tosa_lcd_tg_on(data);
186 data->lcd = lcd_device_register("tosa-lcd", &spi->dev, data,
189 if (IS_ERR(data->lcd)) {
190 ret = PTR_ERR(data->lcd);
198 tosa_lcd_tg_off(data);
200 gpio_free(TOSA_GPIO_TG_ON);
202 dev_set_drvdata(&spi->dev, NULL);
208 static int __devexit tosa_lcd_remove(struct spi_device *spi)
210 struct tosa_lcd_data *data = dev_get_drvdata(&spi->dev);
212 lcd_device_unregister(data->lcd);
215 i2c_unregister_device(data->i2c);
217 tosa_lcd_tg_off(data);
219 gpio_free(TOSA_GPIO_TG_ON);
220 dev_set_drvdata(&spi->dev, NULL);
227 static int tosa_lcd_suspend(struct spi_device *spi, pm_message_t state)
229 struct tosa_lcd_data *data = dev_get_drvdata(&spi->dev);
231 tosa_lcd_tg_off(data);
236 static int tosa_lcd_resume(struct spi_device *spi)
238 struct tosa_lcd_data *data = dev_get_drvdata(&spi->dev);
240 tosa_lcd_tg_init(data);
241 if (POWER_IS_ON(data->lcd_power))
242 tosa_lcd_tg_on(data);
244 tosa_lcd_tg_off(data);
249 #define tosa_lcd_suspend NULL
250 #define tosa_lcd_reume NULL
253 static struct spi_driver tosa_lcd_driver = {
256 .owner = THIS_MODULE,
258 .probe = tosa_lcd_probe,
259 .remove = __devexit_p(tosa_lcd_remove),
260 .suspend = tosa_lcd_suspend,
261 .resume = tosa_lcd_resume,
264 static int __init tosa_lcd_init(void)
266 return spi_register_driver(&tosa_lcd_driver);
269 static void __exit tosa_lcd_exit(void)
271 spi_unregister_driver(&tosa_lcd_driver);
274 module_init(tosa_lcd_init);
275 module_exit(tosa_lcd_exit);
277 MODULE_AUTHOR("Dmitry Baryshkov");
278 MODULE_LICENSE("GPL v2");
279 MODULE_DESCRIPTION("LCD/Backlight control for Sharp SL-6000 PDA");