2 * lms283gf05.c -- support for Samsung LMS283GF05 LCD
4 * Copyright (c) 2009 Marek Vasut <marek.vasut@gmail.com>
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.
11 #include <linux/device.h>
12 #include <linux/kernel.h>
13 #include <linux/delay.h>
14 #include <linux/slab.h>
15 #include <linux/gpio.h>
16 #include <linux/lcd.h>
18 #include <linux/spi/spi.h>
19 #include <linux/spi/lms283gf05.h>
20 #include <linux/module.h>
22 struct lms283gf05_state
{
23 struct spi_device
*spi
;
24 struct lcd_device
*ld
;
27 struct lms283gf05_seq
{
33 /* Magic sequences supplied by manufacturer, for details refer to datasheet */
34 static const struct lms283gf05_seq disp_initseq
[] = {
35 /* REG, VALUE, DELAY */
45 { 0x13, 0x0070, 200 },
81 static const struct lms283gf05_seq disp_pdwnseq
[] = {
96 static void lms283gf05_reset(unsigned long gpio
, bool inverted
)
98 gpio_set_value(gpio
, !inverted
);
100 gpio_set_value(gpio
, inverted
);
102 gpio_set_value(gpio
, !inverted
);
106 static void lms283gf05_toggle(struct spi_device
*spi
,
107 const struct lms283gf05_seq
*seq
, int sz
)
112 for (i
= 0; i
< sz
; i
++) {
116 spi_write(spi
, buf
, 3);
119 buf
[1] = seq
[i
].value
>> 8;
120 buf
[2] = seq
[i
].value
& 0xff;
121 spi_write(spi
, buf
, 3);
123 mdelay(seq
[i
].delay
);
127 static int lms283gf05_power_set(struct lcd_device
*ld
, int power
)
129 struct lms283gf05_state
*st
= lcd_get_data(ld
);
130 struct spi_device
*spi
= st
->spi
;
131 struct lms283gf05_pdata
*pdata
= dev_get_platdata(&spi
->dev
);
133 if (power
<= FB_BLANK_NORMAL
) {
135 lms283gf05_reset(pdata
->reset_gpio
,
136 pdata
->reset_inverted
);
137 lms283gf05_toggle(spi
, disp_initseq
, ARRAY_SIZE(disp_initseq
));
139 lms283gf05_toggle(spi
, disp_pdwnseq
, ARRAY_SIZE(disp_pdwnseq
));
141 gpio_set_value(pdata
->reset_gpio
,
142 pdata
->reset_inverted
);
148 static struct lcd_ops lms_ops
= {
149 .set_power
= lms283gf05_power_set
,
153 static int lms283gf05_probe(struct spi_device
*spi
)
155 struct lms283gf05_state
*st
;
156 struct lms283gf05_pdata
*pdata
= dev_get_platdata(&spi
->dev
);
157 struct lcd_device
*ld
;
161 ret
= devm_gpio_request_one(&spi
->dev
, pdata
->reset_gpio
,
162 GPIOF_DIR_OUT
| (!pdata
->reset_inverted
?
163 GPIOF_INIT_HIGH
: GPIOF_INIT_LOW
),
169 st
= devm_kzalloc(&spi
->dev
, sizeof(struct lms283gf05_state
),
174 ld
= devm_lcd_device_register(&spi
->dev
, "lms283gf05", &spi
->dev
, st
,
182 spi_set_drvdata(spi
, st
);
184 /* kick in the LCD */
186 lms283gf05_reset(pdata
->reset_gpio
, pdata
->reset_inverted
);
187 lms283gf05_toggle(spi
, disp_initseq
, ARRAY_SIZE(disp_initseq
));
192 static struct spi_driver lms283gf05_driver
= {
194 .name
= "lms283gf05",
195 .owner
= THIS_MODULE
,
197 .probe
= lms283gf05_probe
,
200 module_spi_driver(lms283gf05_driver
);
202 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
203 MODULE_DESCRIPTION("LCD283GF05 LCD");
204 MODULE_LICENSE("GPL v2");