1 // SPDX-License-Identifier: GPL-2.0-only
3 * lms283gf05.c -- support for Samsung LMS283GF05 LCD
5 * Copyright (c) 2009 Marek Vasut <marek.vasut@gmail.com>
8 #include <linux/device.h>
9 #include <linux/kernel.h>
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <linux/gpio.h>
13 #include <linux/lcd.h>
15 #include <linux/spi/spi.h>
16 #include <linux/spi/lms283gf05.h>
17 #include <linux/module.h>
19 struct lms283gf05_state
{
20 struct spi_device
*spi
;
21 struct lcd_device
*ld
;
24 struct lms283gf05_seq
{
30 /* Magic sequences supplied by manufacturer, for details refer to datasheet */
31 static const struct lms283gf05_seq disp_initseq
[] = {
32 /* REG, VALUE, DELAY */
42 { 0x13, 0x0070, 200 },
78 static const struct lms283gf05_seq disp_pdwnseq
[] = {
93 static void lms283gf05_reset(unsigned long gpio
, bool inverted
)
95 gpio_set_value(gpio
, !inverted
);
97 gpio_set_value(gpio
, inverted
);
99 gpio_set_value(gpio
, !inverted
);
103 static void lms283gf05_toggle(struct spi_device
*spi
,
104 const struct lms283gf05_seq
*seq
, int sz
)
109 for (i
= 0; i
< sz
; i
++) {
113 spi_write(spi
, buf
, 3);
116 buf
[1] = seq
[i
].value
>> 8;
117 buf
[2] = seq
[i
].value
& 0xff;
118 spi_write(spi
, buf
, 3);
120 mdelay(seq
[i
].delay
);
124 static int lms283gf05_power_set(struct lcd_device
*ld
, int power
)
126 struct lms283gf05_state
*st
= lcd_get_data(ld
);
127 struct spi_device
*spi
= st
->spi
;
128 struct lms283gf05_pdata
*pdata
= dev_get_platdata(&spi
->dev
);
130 if (power
<= FB_BLANK_NORMAL
) {
132 lms283gf05_reset(pdata
->reset_gpio
,
133 pdata
->reset_inverted
);
134 lms283gf05_toggle(spi
, disp_initseq
, ARRAY_SIZE(disp_initseq
));
136 lms283gf05_toggle(spi
, disp_pdwnseq
, ARRAY_SIZE(disp_pdwnseq
));
138 gpio_set_value(pdata
->reset_gpio
,
139 pdata
->reset_inverted
);
145 static struct lcd_ops lms_ops
= {
146 .set_power
= lms283gf05_power_set
,
150 static int lms283gf05_probe(struct spi_device
*spi
)
152 struct lms283gf05_state
*st
;
153 struct lms283gf05_pdata
*pdata
= dev_get_platdata(&spi
->dev
);
154 struct lcd_device
*ld
;
158 ret
= devm_gpio_request_one(&spi
->dev
, pdata
->reset_gpio
,
159 GPIOF_DIR_OUT
| (!pdata
->reset_inverted
?
160 GPIOF_INIT_HIGH
: GPIOF_INIT_LOW
),
166 st
= devm_kzalloc(&spi
->dev
, sizeof(struct lms283gf05_state
),
171 ld
= devm_lcd_device_register(&spi
->dev
, "lms283gf05", &spi
->dev
, st
,
179 spi_set_drvdata(spi
, st
);
181 /* kick in the LCD */
183 lms283gf05_reset(pdata
->reset_gpio
, pdata
->reset_inverted
);
184 lms283gf05_toggle(spi
, disp_initseq
, ARRAY_SIZE(disp_initseq
));
189 static struct spi_driver lms283gf05_driver
= {
191 .name
= "lms283gf05",
193 .probe
= lms283gf05_probe
,
196 module_spi_driver(lms283gf05_driver
);
198 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
199 MODULE_DESCRIPTION("LCD283GF05 LCD");
200 MODULE_LICENSE("GPL v2");