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>
9 #include <linux/init.h>
10 #include <linux/lcd.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/spi/spi.h>
17 #define POWER_IS_ON(pwr) ((pwr) <= LCD_POWER_REDUCED)
20 struct spi_device
*spi
;
23 struct lcd_device
*ld
;
27 * The power-on and power-off sequences are taken from the
28 * LTV350QV-F04 data sheet from Samsung. The register definitions are
29 * taken from the S6F2002 command list also from Samsung.
31 * There's still some voodoo going on here, but it's a lot better than
32 * in the first incarnation of the driver where all we had was the raw
33 * numbers from the initialization sequence.
35 static int ltv350qv_write_reg(struct ltv350qv
*lcd
, u8 reg
, u16 val
)
37 struct spi_message msg
;
38 struct spi_transfer index_xfer
= {
42 struct spi_transfer value_xfer
= {
46 spi_message_init(&msg
);
49 lcd
->buffer
[0] = LTV_OPC_INDEX
;
50 lcd
->buffer
[1] = 0x00;
51 lcd
->buffer
[2] = reg
& 0x7f;
52 index_xfer
.tx_buf
= lcd
->buffer
;
53 spi_message_add_tail(&index_xfer
, &msg
);
56 lcd
->buffer
[4] = LTV_OPC_DATA
;
57 lcd
->buffer
[5] = val
>> 8;
59 value_xfer
.tx_buf
= lcd
->buffer
+ 4;
60 spi_message_add_tail(&value_xfer
, &msg
);
62 return spi_sync(lcd
->spi
, &msg
);
65 /* The comments are taken straight from the data sheet */
66 static int ltv350qv_power_on(struct ltv350qv
*lcd
)
70 /* Power On Reset Display off State */
71 if (ltv350qv_write_reg(lcd
, LTV_PWRCTL1
, 0x0000))
73 usleep_range(15000, 16000);
75 /* Power Setting Function 1 */
76 if (ltv350qv_write_reg(lcd
, LTV_PWRCTL1
, LTV_VCOM_DISABLE
))
78 if (ltv350qv_write_reg(lcd
, LTV_PWRCTL2
, LTV_VCOML_ENABLE
))
81 /* Power Setting Function 2 */
82 if (ltv350qv_write_reg(lcd
, LTV_PWRCTL1
,
83 LTV_VCOM_DISABLE
| LTV_DRIVE_CURRENT(5)
84 | LTV_SUPPLY_CURRENT(5)))
89 /* Instruction Setting */
90 ret
= ltv350qv_write_reg(lcd
, LTV_IFCTL
,
91 LTV_NMD
| LTV_REV
| LTV_NL(0x1d));
92 ret
|= ltv350qv_write_reg(lcd
, LTV_DATACTL
,
93 LTV_DS_SAME
| LTV_CHS_480
94 | LTV_DF_RGB
| LTV_RGB_BGR
);
95 ret
|= ltv350qv_write_reg(lcd
, LTV_ENTRY_MODE
,
98 | LTV_DPL_SAMPLE_RISING
100 | LTV_SS_RIGHT_TO_LEFT
);
101 ret
|= ltv350qv_write_reg(lcd
, LTV_GATECTL1
, LTV_CLW(3));
102 ret
|= ltv350qv_write_reg(lcd
, LTV_GATECTL2
,
103 LTV_NW_INV_1LINE
| LTV_FWI(3));
104 ret
|= ltv350qv_write_reg(lcd
, LTV_VBP
, 0x000a);
105 ret
|= ltv350qv_write_reg(lcd
, LTV_HBP
, 0x0021);
106 ret
|= ltv350qv_write_reg(lcd
, LTV_SOTCTL
, LTV_SDT(3) | LTV_EQ(0));
107 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(0), 0x0103);
108 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(1), 0x0301);
109 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(2), 0x1f0f);
110 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(3), 0x1f0f);
111 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(4), 0x0707);
112 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(5), 0x0307);
113 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(6), 0x0707);
114 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(7), 0x0000);
115 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(8), 0x0004);
116 ret
|= ltv350qv_write_reg(lcd
, LTV_GAMMA(9), 0x0000);
120 /* Wait more than 2 frames */
123 /* Display On Sequence */
124 ret
= ltv350qv_write_reg(lcd
, LTV_PWRCTL1
,
125 LTV_VCOM_DISABLE
| LTV_VCOMOUT_ENABLE
126 | LTV_POWER_ON
| LTV_DRIVE_CURRENT(5)
127 | LTV_SUPPLY_CURRENT(5));
128 ret
|= ltv350qv_write_reg(lcd
, LTV_GATECTL2
,
129 LTV_NW_INV_1LINE
| LTV_DSC
| LTV_FWI(3));
133 /* Display should now be ON. Phew. */
138 * Try to recover. Error handling probably isn't very useful
139 * at this point, just make a best effort to switch the panel
142 ltv350qv_write_reg(lcd
, LTV_PWRCTL1
,
143 LTV_VCOM_DISABLE
| LTV_DRIVE_CURRENT(5)
144 | LTV_SUPPLY_CURRENT(5));
145 ltv350qv_write_reg(lcd
, LTV_GATECTL2
,
146 LTV_NW_INV_1LINE
| LTV_FWI(3));
150 ltv350qv_write_reg(lcd
, LTV_PWRCTL2
, 0x0000);
151 usleep_range(1000, 1100);
153 ltv350qv_write_reg(lcd
, LTV_PWRCTL1
, LTV_VCOM_DISABLE
);
157 static int ltv350qv_power_off(struct ltv350qv
*lcd
)
161 /* Display Off Sequence */
162 ret
= ltv350qv_write_reg(lcd
, LTV_PWRCTL1
,
164 | LTV_DRIVE_CURRENT(5)
165 | LTV_SUPPLY_CURRENT(5));
166 ret
|= ltv350qv_write_reg(lcd
, LTV_GATECTL2
,
167 LTV_NW_INV_1LINE
| LTV_FWI(3));
169 /* Power down setting 1 */
170 ret
|= ltv350qv_write_reg(lcd
, LTV_PWRCTL2
, 0x0000);
172 /* Wait at least 1 ms */
173 usleep_range(1000, 1100);
175 /* Power down setting 2 */
176 ret
|= ltv350qv_write_reg(lcd
, LTV_PWRCTL1
, LTV_VCOM_DISABLE
);
179 * No point in trying to recover here. If we can't switch the
180 * panel off, what are we supposed to do other than inform the
181 * user about the failure?
186 /* Display power should now be OFF */
190 static int ltv350qv_power(struct ltv350qv
*lcd
, int power
)
194 if (POWER_IS_ON(power
) && !POWER_IS_ON(lcd
->power
))
195 ret
= ltv350qv_power_on(lcd
);
196 else if (!POWER_IS_ON(power
) && POWER_IS_ON(lcd
->power
))
197 ret
= ltv350qv_power_off(lcd
);
205 static int ltv350qv_set_power(struct lcd_device
*ld
, int power
)
207 struct ltv350qv
*lcd
= lcd_get_data(ld
);
209 return ltv350qv_power(lcd
, power
);
212 static int ltv350qv_get_power(struct lcd_device
*ld
)
214 struct ltv350qv
*lcd
= lcd_get_data(ld
);
219 static const struct lcd_ops ltv_ops
= {
220 .get_power
= ltv350qv_get_power
,
221 .set_power
= ltv350qv_set_power
,
224 static int ltv350qv_probe(struct spi_device
*spi
)
226 struct ltv350qv
*lcd
;
227 struct lcd_device
*ld
;
230 lcd
= devm_kzalloc(&spi
->dev
, sizeof(struct ltv350qv
), GFP_KERNEL
);
235 lcd
->power
= LCD_POWER_OFF
;
236 lcd
->buffer
= devm_kzalloc(&spi
->dev
, 8, GFP_KERNEL
);
240 ld
= devm_lcd_device_register(&spi
->dev
, "ltv350qv", &spi
->dev
, lcd
,
247 ret
= ltv350qv_power(lcd
, LCD_POWER_ON
);
251 spi_set_drvdata(spi
, lcd
);
256 static void ltv350qv_remove(struct spi_device
*spi
)
258 struct ltv350qv
*lcd
= spi_get_drvdata(spi
);
260 ltv350qv_power(lcd
, LCD_POWER_OFF
);
263 #ifdef CONFIG_PM_SLEEP
264 static int ltv350qv_suspend(struct device
*dev
)
266 struct ltv350qv
*lcd
= dev_get_drvdata(dev
);
268 return ltv350qv_power(lcd
, LCD_POWER_OFF
);
271 static int ltv350qv_resume(struct device
*dev
)
273 struct ltv350qv
*lcd
= dev_get_drvdata(dev
);
275 return ltv350qv_power(lcd
, LCD_POWER_ON
);
279 static SIMPLE_DEV_PM_OPS(ltv350qv_pm_ops
, ltv350qv_suspend
, ltv350qv_resume
);
281 /* Power down all displays on reboot, poweroff or halt */
282 static void ltv350qv_shutdown(struct spi_device
*spi
)
284 struct ltv350qv
*lcd
= spi_get_drvdata(spi
);
286 ltv350qv_power(lcd
, LCD_POWER_OFF
);
289 static struct spi_driver ltv350qv_driver
= {
292 .pm
= <v350qv_pm_ops
,
295 .probe
= ltv350qv_probe
,
296 .remove
= ltv350qv_remove
,
297 .shutdown
= ltv350qv_shutdown
,
300 module_spi_driver(ltv350qv_driver
);
302 MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
303 MODULE_DESCRIPTION("Samsung LTV350QV LCD Driver");
304 MODULE_LICENSE("GPL");
305 MODULE_ALIAS("spi:ltv350qv");