2 * Power control for Samsung LTV350QV Quarter VGA LCD Panel
4 * Copyright (C) 2006, 2007 Atmel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #include <linux/delay.h>
11 #include <linux/err.h>
13 #include <linux/init.h>
14 #include <linux/lcd.h>
15 #include <linux/module.h>
16 #include <linux/spi/spi.h>
20 #define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
23 struct spi_device *spi;
26 struct lcd_device *ld;
30 * The power-on and power-off sequences are taken from the
31 * LTV350QV-F04 data sheet from Samsung. The register definitions are
32 * taken from the S6F2002 command list also from Samsung. Both
33 * documents are distributed with the AVR32 Linux BSP CD from Atmel.
35 * There's still some voodoo going on here, but it's a lot better than
36 * in the first incarnation of the driver where all we had was the raw
37 * numbers from the initialization sequence.
39 static int ltv350qv_write_reg(struct ltv350qv *lcd, u8 reg, u16 val)
41 struct spi_message msg;
42 struct spi_transfer index_xfer = {
46 struct spi_transfer value_xfer = {
50 spi_message_init(&msg);
53 lcd->buffer[0] = LTV_OPC_INDEX;
54 lcd->buffer[1] = 0x00;
55 lcd->buffer[2] = reg & 0x7f;
56 index_xfer.tx_buf = lcd->buffer;
57 spi_message_add_tail(&index_xfer, &msg);
60 lcd->buffer[4] = LTV_OPC_DATA;
61 lcd->buffer[5] = val >> 8;
63 value_xfer.tx_buf = lcd->buffer + 4;
64 spi_message_add_tail(&value_xfer, &msg);
66 return spi_sync(lcd->spi, &msg);
69 /* The comments are taken straight from the data sheet */
70 static int ltv350qv_power_on(struct ltv350qv *lcd)
74 /* Power On Reset Display off State */
75 if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, 0x0000))
79 /* Power Setting Function 1 */
80 if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE))
82 if (ltv350qv_write_reg(lcd, LTV_PWRCTL2, LTV_VCOML_ENABLE))
85 /* Power Setting Function 2 */
86 if (ltv350qv_write_reg(lcd, LTV_PWRCTL1,
87 LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
88 | LTV_SUPPLY_CURRENT(5)))
93 /* Instruction Setting */
94 ret = ltv350qv_write_reg(lcd, LTV_IFCTL,
95 LTV_NMD | LTV_REV | LTV_NL(0x1d));
96 ret |= ltv350qv_write_reg(lcd, LTV_DATACTL,
97 LTV_DS_SAME | LTV_CHS_480
98 | LTV_DF_RGB | LTV_RGB_BGR);
99 ret |= ltv350qv_write_reg(lcd, LTV_ENTRY_MODE,
101 | LTV_HSPL_ACTIVE_LOW
102 | LTV_DPL_SAMPLE_RISING
104 | LTV_SS_RIGHT_TO_LEFT);
105 ret |= ltv350qv_write_reg(lcd, LTV_GATECTL1, LTV_CLW(3));
106 ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
107 LTV_NW_INV_1LINE | LTV_FWI(3));
108 ret |= ltv350qv_write_reg(lcd, LTV_VBP, 0x000a);
109 ret |= ltv350qv_write_reg(lcd, LTV_HBP, 0x0021);
110 ret |= ltv350qv_write_reg(lcd, LTV_SOTCTL, LTV_SDT(3) | LTV_EQ(0));
111 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(0), 0x0103);
112 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(1), 0x0301);
113 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(2), 0x1f0f);
114 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(3), 0x1f0f);
115 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(4), 0x0707);
116 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(5), 0x0307);
117 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(6), 0x0707);
118 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(7), 0x0000);
119 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(8), 0x0004);
120 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(9), 0x0000);
124 /* Wait more than 2 frames */
127 /* Display On Sequence */
128 ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
129 LTV_VCOM_DISABLE | LTV_VCOMOUT_ENABLE
130 | LTV_POWER_ON | LTV_DRIVE_CURRENT(5)
131 | LTV_SUPPLY_CURRENT(5));
132 ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
133 LTV_NW_INV_1LINE | LTV_DSC | LTV_FWI(3));
137 /* Display should now be ON. Phew. */
142 * Try to recover. Error handling probably isn't very useful
143 * at this point, just make a best effort to switch the panel
146 ltv350qv_write_reg(lcd, LTV_PWRCTL1,
147 LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
148 | LTV_SUPPLY_CURRENT(5));
149 ltv350qv_write_reg(lcd, LTV_GATECTL2,
150 LTV_NW_INV_1LINE | LTV_FWI(3));
154 ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
157 ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
161 static int ltv350qv_power_off(struct ltv350qv *lcd)
165 /* Display Off Sequence */
166 ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
168 | LTV_DRIVE_CURRENT(5)
169 | LTV_SUPPLY_CURRENT(5));
170 ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
171 LTV_NW_INV_1LINE | LTV_FWI(3));
173 /* Power down setting 1 */
174 ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
176 /* Wait at least 1 ms */
179 /* Power down setting 2 */
180 ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
183 * No point in trying to recover here. If we can't switch the
184 * panel off, what are we supposed to do other than inform the
185 * user about the failure?
190 /* Display power should now be OFF */
194 static int ltv350qv_power(struct ltv350qv *lcd, int power)
198 if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
199 ret = ltv350qv_power_on(lcd);
200 else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
201 ret = ltv350qv_power_off(lcd);
209 static int ltv350qv_set_power(struct lcd_device *ld, int power)
211 struct ltv350qv *lcd = lcd_get_data(ld);
213 return ltv350qv_power(lcd, power);
216 static int ltv350qv_get_power(struct lcd_device *ld)
218 struct ltv350qv *lcd = lcd_get_data(ld);
223 static struct lcd_ops ltv_ops = {
224 .get_power = ltv350qv_get_power,
225 .set_power = ltv350qv_set_power,
228 static int __devinit ltv350qv_probe(struct spi_device *spi)
230 struct ltv350qv *lcd;
231 struct lcd_device *ld;
234 lcd = kzalloc(sizeof(struct ltv350qv), GFP_KERNEL);
239 lcd->power = FB_BLANK_POWERDOWN;
240 lcd->buffer = kzalloc(8, GFP_KERNEL);
242 ld = lcd_device_register("ltv350qv", &spi->dev, lcd, <v_ops);
249 ret = ltv350qv_power(lcd, FB_BLANK_UNBLANK);
253 dev_set_drvdata(&spi->dev, lcd);
258 lcd_device_unregister(ld);
264 static int __devexit ltv350qv_remove(struct spi_device *spi)
266 struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
268 ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
269 lcd_device_unregister(lcd->ld);
276 static int ltv350qv_suspend(struct spi_device *spi, pm_message_t state)
278 struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
280 return ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
283 static int ltv350qv_resume(struct spi_device *spi)
285 struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
287 return ltv350qv_power(lcd, FB_BLANK_UNBLANK);
290 #define ltv350qv_suspend NULL
291 #define ltv350qv_resume NULL
294 /* Power down all displays on reboot, poweroff or halt */
295 static void ltv350qv_shutdown(struct spi_device *spi)
297 struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
299 ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
302 static struct spi_driver ltv350qv_driver = {
305 .bus = &spi_bus_type,
306 .owner = THIS_MODULE,
309 .probe = ltv350qv_probe,
310 .remove = __devexit_p(ltv350qv_remove),
311 .shutdown = ltv350qv_shutdown,
312 .suspend = ltv350qv_suspend,
313 .resume = ltv350qv_resume,
316 static int __init ltv350qv_init(void)
318 return spi_register_driver(<v350qv_driver);
321 static void __exit ltv350qv_exit(void)
323 spi_unregister_driver(<v350qv_driver);
325 module_init(ltv350qv_init);
326 module_exit(ltv350qv_exit);
328 MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
329 MODULE_DESCRIPTION("Samsung LTV350QV LCD Driver");
330 MODULE_LICENSE("GPL");