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/slab.h>
17 #include <linux/spi/spi.h>
21 #define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
24 struct spi_device *spi;
27 struct lcd_device *ld;
31 * The power-on and power-off sequences are taken from the
32 * LTV350QV-F04 data sheet from Samsung. The register definitions are
33 * taken from the S6F2002 command list also from Samsung. Both
34 * documents are distributed with the AVR32 Linux BSP CD from Atmel.
36 * There's still some voodoo going on here, but it's a lot better than
37 * in the first incarnation of the driver where all we had was the raw
38 * numbers from the initialization sequence.
40 static int ltv350qv_write_reg(struct ltv350qv *lcd, u8 reg, u16 val)
42 struct spi_message msg;
43 struct spi_transfer index_xfer = {
47 struct spi_transfer value_xfer = {
51 spi_message_init(&msg);
54 lcd->buffer[0] = LTV_OPC_INDEX;
55 lcd->buffer[1] = 0x00;
56 lcd->buffer[2] = reg & 0x7f;
57 index_xfer.tx_buf = lcd->buffer;
58 spi_message_add_tail(&index_xfer, &msg);
61 lcd->buffer[4] = LTV_OPC_DATA;
62 lcd->buffer[5] = val >> 8;
64 value_xfer.tx_buf = lcd->buffer + 4;
65 spi_message_add_tail(&value_xfer, &msg);
67 return spi_sync(lcd->spi, &msg);
70 /* The comments are taken straight from the data sheet */
71 static int ltv350qv_power_on(struct ltv350qv *lcd)
75 /* Power On Reset Display off State */
76 if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, 0x0000))
80 /* Power Setting Function 1 */
81 if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE))
83 if (ltv350qv_write_reg(lcd, LTV_PWRCTL2, LTV_VCOML_ENABLE))
86 /* Power Setting Function 2 */
87 if (ltv350qv_write_reg(lcd, LTV_PWRCTL1,
88 LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
89 | LTV_SUPPLY_CURRENT(5)))
94 /* Instruction Setting */
95 ret = ltv350qv_write_reg(lcd, LTV_IFCTL,
96 LTV_NMD | LTV_REV | LTV_NL(0x1d));
97 ret |= ltv350qv_write_reg(lcd, LTV_DATACTL,
98 LTV_DS_SAME | LTV_CHS_480
99 | LTV_DF_RGB | LTV_RGB_BGR);
100 ret |= ltv350qv_write_reg(lcd, LTV_ENTRY_MODE,
102 | LTV_HSPL_ACTIVE_LOW
103 | LTV_DPL_SAMPLE_RISING
105 | LTV_SS_RIGHT_TO_LEFT);
106 ret |= ltv350qv_write_reg(lcd, LTV_GATECTL1, LTV_CLW(3));
107 ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
108 LTV_NW_INV_1LINE | LTV_FWI(3));
109 ret |= ltv350qv_write_reg(lcd, LTV_VBP, 0x000a);
110 ret |= ltv350qv_write_reg(lcd, LTV_HBP, 0x0021);
111 ret |= ltv350qv_write_reg(lcd, LTV_SOTCTL, LTV_SDT(3) | LTV_EQ(0));
112 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(0), 0x0103);
113 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(1), 0x0301);
114 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(2), 0x1f0f);
115 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(3), 0x1f0f);
116 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(4), 0x0707);
117 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(5), 0x0307);
118 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(6), 0x0707);
119 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(7), 0x0000);
120 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(8), 0x0004);
121 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(9), 0x0000);
125 /* Wait more than 2 frames */
128 /* Display On Sequence */
129 ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
130 LTV_VCOM_DISABLE | LTV_VCOMOUT_ENABLE
131 | LTV_POWER_ON | LTV_DRIVE_CURRENT(5)
132 | LTV_SUPPLY_CURRENT(5));
133 ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
134 LTV_NW_INV_1LINE | LTV_DSC | LTV_FWI(3));
138 /* Display should now be ON. Phew. */
143 * Try to recover. Error handling probably isn't very useful
144 * at this point, just make a best effort to switch the panel
147 ltv350qv_write_reg(lcd, LTV_PWRCTL1,
148 LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
149 | LTV_SUPPLY_CURRENT(5));
150 ltv350qv_write_reg(lcd, LTV_GATECTL2,
151 LTV_NW_INV_1LINE | LTV_FWI(3));
155 ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
158 ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
162 static int ltv350qv_power_off(struct ltv350qv *lcd)
166 /* Display Off Sequence */
167 ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
169 | LTV_DRIVE_CURRENT(5)
170 | LTV_SUPPLY_CURRENT(5));
171 ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
172 LTV_NW_INV_1LINE | LTV_FWI(3));
174 /* Power down setting 1 */
175 ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
177 /* Wait at least 1 ms */
180 /* Power down setting 2 */
181 ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
184 * No point in trying to recover here. If we can't switch the
185 * panel off, what are we supposed to do other than inform the
186 * user about the failure?
191 /* Display power should now be OFF */
195 static int ltv350qv_power(struct ltv350qv *lcd, int power)
199 if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
200 ret = ltv350qv_power_on(lcd);
201 else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
202 ret = ltv350qv_power_off(lcd);
210 static int ltv350qv_set_power(struct lcd_device *ld, int power)
212 struct ltv350qv *lcd = lcd_get_data(ld);
214 return ltv350qv_power(lcd, power);
217 static int ltv350qv_get_power(struct lcd_device *ld)
219 struct ltv350qv *lcd = lcd_get_data(ld);
224 static struct lcd_ops ltv_ops = {
225 .get_power = ltv350qv_get_power,
226 .set_power = ltv350qv_set_power,
229 static int __devinit ltv350qv_probe(struct spi_device *spi)
231 struct ltv350qv *lcd;
232 struct lcd_device *ld;
235 lcd = kzalloc(sizeof(struct ltv350qv), GFP_KERNEL);
240 lcd->power = FB_BLANK_POWERDOWN;
241 lcd->buffer = kzalloc(8, GFP_KERNEL);
247 ld = lcd_device_register("ltv350qv", &spi->dev, lcd, <v_ops);
250 goto out_free_buffer;
254 ret = ltv350qv_power(lcd, FB_BLANK_UNBLANK);
258 dev_set_drvdata(&spi->dev, lcd);
263 lcd_device_unregister(ld);
271 static int __devexit ltv350qv_remove(struct spi_device *spi)
273 struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
275 ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
276 lcd_device_unregister(lcd->ld);
284 static int ltv350qv_suspend(struct spi_device *spi, pm_message_t state)
286 struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
288 return ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
291 static int ltv350qv_resume(struct spi_device *spi)
293 struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
295 return ltv350qv_power(lcd, FB_BLANK_UNBLANK);
298 #define ltv350qv_suspend NULL
299 #define ltv350qv_resume NULL
302 /* Power down all displays on reboot, poweroff or halt */
303 static void ltv350qv_shutdown(struct spi_device *spi)
305 struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
307 ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
310 static struct spi_driver ltv350qv_driver = {
313 .bus = &spi_bus_type,
314 .owner = THIS_MODULE,
317 .probe = ltv350qv_probe,
318 .remove = __devexit_p(ltv350qv_remove),
319 .shutdown = ltv350qv_shutdown,
320 .suspend = ltv350qv_suspend,
321 .resume = ltv350qv_resume,
324 module_spi_driver(ltv350qv_driver);
326 MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
327 MODULE_DESCRIPTION("Samsung LTV350QV LCD Driver");
328 MODULE_LICENSE("GPL");
329 MODULE_ALIAS("spi:ltv350qv");