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. Both
31 * documents are distributed with the AVR32 Linux BSP CD from Atmel.
33 * There's still some voodoo going on here, but it's a lot better than
34 * in the first incarnation of the driver where all we had was the raw
35 * numbers from the initialization sequence.
37 static int ltv350qv_write_reg(struct ltv350qv
*lcd
, u8 reg
, u16 val
)
39 struct spi_message msg
;
40 struct spi_transfer index_xfer
= {
44 struct spi_transfer value_xfer
= {
48 spi_message_init(&msg
);
51 lcd
->buffer
[0] = LTV_OPC_INDEX
;
52 lcd
->buffer
[1] = 0x00;
53 lcd
->buffer
[2] = reg
& 0x7f;
54 index_xfer
.tx_buf
= lcd
->buffer
;
55 spi_message_add_tail(&index_xfer
, &msg
);
58 lcd
->buffer
[4] = LTV_OPC_DATA
;
59 lcd
->buffer
[5] = val
>> 8;
61 value_xfer
.tx_buf
= lcd
->buffer
+ 4;
62 spi_message_add_tail(&value_xfer
, &msg
);
64 return spi_sync(lcd
->spi
, &msg
);
67 /* The comments are taken straight from the data sheet */
68 static int ltv350qv_power_on(struct ltv350qv
*lcd
)
72 /* Power On Reset Display off State */
73 if (ltv350qv_write_reg(lcd
, LTV_PWRCTL1
, 0x0000))
75 usleep_range(15000, 16000);
77 /* Power Setting Function 1 */
78 if (ltv350qv_write_reg(lcd
, LTV_PWRCTL1
, LTV_VCOM_DISABLE
))
80 if (ltv350qv_write_reg(lcd
, LTV_PWRCTL2
, LTV_VCOML_ENABLE
))
83 /* Power Setting Function 2 */
84 if (ltv350qv_write_reg(lcd
, LTV_PWRCTL1
,
85 LTV_VCOM_DISABLE
| LTV_DRIVE_CURRENT(5)
86 | LTV_SUPPLY_CURRENT(5)))
91 /* Instruction Setting */
92 ret
= ltv350qv_write_reg(lcd
, LTV_IFCTL
,
93 LTV_NMD
| LTV_REV
| LTV_NL(0x1d));
94 ret
|= ltv350qv_write_reg(lcd
, LTV_DATACTL
,
95 LTV_DS_SAME
| LTV_CHS_480
96 | LTV_DF_RGB
| LTV_RGB_BGR
);
97 ret
|= ltv350qv_write_reg(lcd
, LTV_ENTRY_MODE
,
100 | LTV_DPL_SAMPLE_RISING
102 | LTV_SS_RIGHT_TO_LEFT
);
103 ret
|= ltv350qv_write_reg(lcd
, LTV_GATECTL1
, LTV_CLW(3));
104 ret
|= ltv350qv_write_reg(lcd
, LTV_GATECTL2
,
105 LTV_NW_INV_1LINE
| LTV_FWI(3));
106 ret
|= ltv350qv_write_reg(lcd
, LTV_VBP
, 0x000a);
107 ret
|= ltv350qv_write_reg(lcd
, LTV_HBP
, 0x0021);
108 ret
|= ltv350qv_write_reg(lcd
, LTV_SOTCTL
, LTV_SDT(3) | LTV_EQ(0));
109 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(0), 0x0103);
110 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(1), 0x0301);
111 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(2), 0x1f0f);
112 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(3), 0x1f0f);
113 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(4), 0x0707);
114 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(5), 0x0307);
115 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(6), 0x0707);
116 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(7), 0x0000);
117 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(8), 0x0004);
118 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(9), 0x0000);
122 /* Wait more than 2 frames */
125 /* Display On Sequence */
126 ret
= ltv350qv_write_reg(lcd
, LTV_PWRCTL1
,
127 LTV_VCOM_DISABLE
| LTV_VCOMOUT_ENABLE
128 | LTV_POWER_ON
| LTV_DRIVE_CURRENT(5)
129 | LTV_SUPPLY_CURRENT(5));
130 ret
|= ltv350qv_write_reg(lcd
, LTV_GATECTL2
,
131 LTV_NW_INV_1LINE
| LTV_DSC
| LTV_FWI(3));
135 /* Display should now be ON. Phew. */
140 * Try to recover. Error handling probably isn't very useful
141 * at this point, just make a best effort to switch the panel
144 ltv350qv_write_reg(lcd
, LTV_PWRCTL1
,
145 LTV_VCOM_DISABLE
| LTV_DRIVE_CURRENT(5)
146 | LTV_SUPPLY_CURRENT(5));
147 ltv350qv_write_reg(lcd
, LTV_GATECTL2
,
148 LTV_NW_INV_1LINE
| LTV_FWI(3));
152 ltv350qv_write_reg(lcd
, LTV_PWRCTL2
, 0x0000);
153 usleep_range(1000, 1100);
155 ltv350qv_write_reg(lcd
, LTV_PWRCTL1
, LTV_VCOM_DISABLE
);
159 static int ltv350qv_power_off(struct ltv350qv
*lcd
)
163 /* Display Off Sequence */
164 ret
= ltv350qv_write_reg(lcd
, LTV_PWRCTL1
,
166 | LTV_DRIVE_CURRENT(5)
167 | LTV_SUPPLY_CURRENT(5));
168 ret
|= ltv350qv_write_reg(lcd
, LTV_GATECTL2
,
169 LTV_NW_INV_1LINE
| LTV_FWI(3));
171 /* Power down setting 1 */
172 ret
|= ltv350qv_write_reg(lcd
, LTV_PWRCTL2
, 0x0000);
174 /* Wait at least 1 ms */
175 usleep_range(1000, 1100);
177 /* Power down setting 2 */
178 ret
|= ltv350qv_write_reg(lcd
, LTV_PWRCTL1
, LTV_VCOM_DISABLE
);
181 * No point in trying to recover here. If we can't switch the
182 * panel off, what are we supposed to do other than inform the
183 * user about the failure?
188 /* Display power should now be OFF */
192 static int ltv350qv_power(struct ltv350qv
*lcd
, int power
)
196 if (POWER_IS_ON(power
) && !POWER_IS_ON(lcd
->power
))
197 ret
= ltv350qv_power_on(lcd
);
198 else if (!POWER_IS_ON(power
) && POWER_IS_ON(lcd
->power
))
199 ret
= ltv350qv_power_off(lcd
);
207 static int ltv350qv_set_power(struct lcd_device
*ld
, int power
)
209 struct ltv350qv
*lcd
= lcd_get_data(ld
);
211 return ltv350qv_power(lcd
, power
);
214 static int ltv350qv_get_power(struct lcd_device
*ld
)
216 struct ltv350qv
*lcd
= lcd_get_data(ld
);
221 static struct lcd_ops ltv_ops
= {
222 .get_power
= ltv350qv_get_power
,
223 .set_power
= ltv350qv_set_power
,
226 static int ltv350qv_probe(struct spi_device
*spi
)
228 struct ltv350qv
*lcd
;
229 struct lcd_device
*ld
;
232 lcd
= devm_kzalloc(&spi
->dev
, sizeof(struct ltv350qv
), GFP_KERNEL
);
237 lcd
->power
= FB_BLANK_POWERDOWN
;
238 lcd
->buffer
= devm_kzalloc(&spi
->dev
, 8, GFP_KERNEL
);
242 ld
= devm_lcd_device_register(&spi
->dev
, "ltv350qv", &spi
->dev
, lcd
,
249 ret
= ltv350qv_power(lcd
, FB_BLANK_UNBLANK
);
253 spi_set_drvdata(spi
, lcd
);
258 static int ltv350qv_remove(struct spi_device
*spi
)
260 struct ltv350qv
*lcd
= spi_get_drvdata(spi
);
262 ltv350qv_power(lcd
, FB_BLANK_POWERDOWN
);
266 #ifdef CONFIG_PM_SLEEP
267 static int ltv350qv_suspend(struct device
*dev
)
269 struct ltv350qv
*lcd
= dev_get_drvdata(dev
);
271 return ltv350qv_power(lcd
, FB_BLANK_POWERDOWN
);
274 static int ltv350qv_resume(struct device
*dev
)
276 struct ltv350qv
*lcd
= dev_get_drvdata(dev
);
278 return ltv350qv_power(lcd
, FB_BLANK_UNBLANK
);
282 static SIMPLE_DEV_PM_OPS(ltv350qv_pm_ops
, ltv350qv_suspend
, ltv350qv_resume
);
284 /* Power down all displays on reboot, poweroff or halt */
285 static void ltv350qv_shutdown(struct spi_device
*spi
)
287 struct ltv350qv
*lcd
= spi_get_drvdata(spi
);
289 ltv350qv_power(lcd
, FB_BLANK_POWERDOWN
);
292 static struct spi_driver ltv350qv_driver
= {
295 .pm
= <v350qv_pm_ops
,
298 .probe
= ltv350qv_probe
,
299 .remove
= ltv350qv_remove
,
300 .shutdown
= ltv350qv_shutdown
,
303 module_spi_driver(ltv350qv_driver
);
305 MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
306 MODULE_DESCRIPTION("Samsung LTV350QV LCD Driver");
307 MODULE_LICENSE("GPL");
308 MODULE_ALIAS("spi:ltv350qv");