1 // SPDX-License-Identifier: GPL-2.0-only
3 * Power control for Samsung LTV350QV Quarter VGA LCD Panel
5 * Copyright (C) 2006, 2007 Atmel Corporation
7 #include <linux/delay.h>
10 #include <linux/init.h>
11 #include <linux/lcd.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/spi/spi.h>
18 #define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
21 struct spi_device *spi;
24 struct lcd_device *ld;
28 * The power-on and power-off sequences are taken from the
29 * LTV350QV-F04 data sheet from Samsung. The register definitions are
30 * taken from the S6F2002 command list also from Samsung.
32 * There's still some voodoo going on here, but it's a lot better than
33 * in the first incarnation of the driver where all we had was the raw
34 * numbers from the initialization sequence.
36 static int ltv350qv_write_reg(struct ltv350qv *lcd, u8 reg, u16 val)
38 struct spi_message msg;
39 struct spi_transfer index_xfer = {
43 struct spi_transfer value_xfer = {
47 spi_message_init(&msg);
50 lcd->buffer[0] = LTV_OPC_INDEX;
51 lcd->buffer[1] = 0x00;
52 lcd->buffer[2] = reg & 0x7f;
53 index_xfer.tx_buf = lcd->buffer;
54 spi_message_add_tail(&index_xfer, &msg);
57 lcd->buffer[4] = LTV_OPC_DATA;
58 lcd->buffer[5] = val >> 8;
60 value_xfer.tx_buf = lcd->buffer + 4;
61 spi_message_add_tail(&value_xfer, &msg);
63 return spi_sync(lcd->spi, &msg);
66 /* The comments are taken straight from the data sheet */
67 static int ltv350qv_power_on(struct ltv350qv *lcd)
71 /* Power On Reset Display off State */
72 if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, 0x0000))
74 usleep_range(15000, 16000);
76 /* Power Setting Function 1 */
77 if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE))
79 if (ltv350qv_write_reg(lcd, LTV_PWRCTL2, LTV_VCOML_ENABLE))
82 /* Power Setting Function 2 */
83 if (ltv350qv_write_reg(lcd, LTV_PWRCTL1,
84 LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
85 | LTV_SUPPLY_CURRENT(5)))
90 /* Instruction Setting */
91 ret = ltv350qv_write_reg(lcd, LTV_IFCTL,
92 LTV_NMD | LTV_REV | LTV_NL(0x1d));
93 ret |= ltv350qv_write_reg(lcd, LTV_DATACTL,
94 LTV_DS_SAME | LTV_CHS_480
95 | LTV_DF_RGB | LTV_RGB_BGR);
96 ret |= ltv350qv_write_reg(lcd, LTV_ENTRY_MODE,
99 | LTV_DPL_SAMPLE_RISING
101 | LTV_SS_RIGHT_TO_LEFT);
102 ret |= ltv350qv_write_reg(lcd, LTV_GATECTL1, LTV_CLW(3));
103 ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
104 LTV_NW_INV_1LINE | LTV_FWI(3));
105 ret |= ltv350qv_write_reg(lcd, LTV_VBP, 0x000a);
106 ret |= ltv350qv_write_reg(lcd, LTV_HBP, 0x0021);
107 ret |= ltv350qv_write_reg(lcd, LTV_SOTCTL, LTV_SDT(3) | LTV_EQ(0));
108 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(0), 0x0103);
109 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(1), 0x0301);
110 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(2), 0x1f0f);
111 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(3), 0x1f0f);
112 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(4), 0x0707);
113 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(5), 0x0307);
114 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(6), 0x0707);
115 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(7), 0x0000);
116 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(8), 0x0004);
117 ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(9), 0x0000);
121 /* Wait more than 2 frames */
124 /* Display On Sequence */
125 ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
126 LTV_VCOM_DISABLE | LTV_VCOMOUT_ENABLE
127 | LTV_POWER_ON | LTV_DRIVE_CURRENT(5)
128 | LTV_SUPPLY_CURRENT(5));
129 ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
130 LTV_NW_INV_1LINE | LTV_DSC | LTV_FWI(3));
134 /* Display should now be ON. Phew. */
139 * Try to recover. Error handling probably isn't very useful
140 * at this point, just make a best effort to switch the panel
143 ltv350qv_write_reg(lcd, LTV_PWRCTL1,
144 LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
145 | LTV_SUPPLY_CURRENT(5));
146 ltv350qv_write_reg(lcd, LTV_GATECTL2,
147 LTV_NW_INV_1LINE | LTV_FWI(3));
151 ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
152 usleep_range(1000, 1100);
154 ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
158 static int ltv350qv_power_off(struct ltv350qv *lcd)
162 /* Display Off Sequence */
163 ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
165 | LTV_DRIVE_CURRENT(5)
166 | LTV_SUPPLY_CURRENT(5));
167 ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
168 LTV_NW_INV_1LINE | LTV_FWI(3));
170 /* Power down setting 1 */
171 ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
173 /* Wait at least 1 ms */
174 usleep_range(1000, 1100);
176 /* Power down setting 2 */
177 ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
180 * No point in trying to recover here. If we can't switch the
181 * panel off, what are we supposed to do other than inform the
182 * user about the failure?
187 /* Display power should now be OFF */
191 static int ltv350qv_power(struct ltv350qv *lcd, int power)
195 if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
196 ret = ltv350qv_power_on(lcd);
197 else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
198 ret = ltv350qv_power_off(lcd);
206 static int ltv350qv_set_power(struct lcd_device *ld, int power)
208 struct ltv350qv *lcd = lcd_get_data(ld);
210 return ltv350qv_power(lcd, power);
213 static int ltv350qv_get_power(struct lcd_device *ld)
215 struct ltv350qv *lcd = lcd_get_data(ld);
220 static struct lcd_ops ltv_ops = {
221 .get_power = ltv350qv_get_power,
222 .set_power = ltv350qv_set_power,
225 static int ltv350qv_probe(struct spi_device *spi)
227 struct ltv350qv *lcd;
228 struct lcd_device *ld;
231 lcd = devm_kzalloc(&spi->dev, sizeof(struct ltv350qv), GFP_KERNEL);
236 lcd->power = FB_BLANK_POWERDOWN;
237 lcd->buffer = devm_kzalloc(&spi->dev, 8, GFP_KERNEL);
241 ld = devm_lcd_device_register(&spi->dev, "ltv350qv", &spi->dev, lcd,
248 ret = ltv350qv_power(lcd, FB_BLANK_UNBLANK);
252 spi_set_drvdata(spi, lcd);
257 static void ltv350qv_remove(struct spi_device *spi)
259 struct ltv350qv *lcd = spi_get_drvdata(spi);
261 ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
264 #ifdef CONFIG_PM_SLEEP
265 static int ltv350qv_suspend(struct device *dev)
267 struct ltv350qv *lcd = dev_get_drvdata(dev);
269 return ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
272 static int ltv350qv_resume(struct device *dev)
274 struct ltv350qv *lcd = dev_get_drvdata(dev);
276 return ltv350qv_power(lcd, FB_BLANK_UNBLANK);
280 static SIMPLE_DEV_PM_OPS(ltv350qv_pm_ops, ltv350qv_suspend, ltv350qv_resume);
282 /* Power down all displays on reboot, poweroff or halt */
283 static void ltv350qv_shutdown(struct spi_device *spi)
285 struct ltv350qv *lcd = spi_get_drvdata(spi);
287 ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
290 static struct spi_driver ltv350qv_driver = {
293 .pm = <v350qv_pm_ops,
296 .probe = ltv350qv_probe,
297 .remove = ltv350qv_remove,
298 .shutdown = ltv350qv_shutdown,
301 module_spi_driver(ltv350qv_driver);
303 MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
304 MODULE_DESCRIPTION("Samsung LTV350QV LCD Driver");
305 MODULE_LICENSE("GPL");
306 MODULE_ALIAS("spi:ltv350qv");