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/gpio.h>
15 #include <linux/lcd.h>
17 #include <linux/spi/spi.h>
18 #include <linux/spi/lms283gf05.h>
20 struct lms283gf05_state
{
21 struct spi_device
*spi
;
22 struct lcd_device
*ld
;
25 struct lms283gf05_seq
{
31 /* Magic sequences supplied by manufacturer, for details refer to datasheet */
32 static struct lms283gf05_seq disp_initseq
[] = {
33 /* REG, VALUE, DELAY */
43 { 0x13, 0x0070, 200 },
79 static struct lms283gf05_seq disp_pdwnseq
[] = {
94 static void lms283gf05_reset(unsigned long gpio
, bool inverted
)
96 gpio_set_value(gpio
, !inverted
);
98 gpio_set_value(gpio
, inverted
);
100 gpio_set_value(gpio
, !inverted
);
104 static void lms283gf05_toggle(struct spi_device
*spi
,
105 struct lms283gf05_seq
*seq
, int sz
)
110 for (i
= 0; i
< sz
; i
++) {
114 spi_write(spi
, buf
, 3);
117 buf
[1] = seq
[i
].value
>> 8;
118 buf
[2] = seq
[i
].value
& 0xff;
119 spi_write(spi
, buf
, 3);
121 mdelay(seq
[i
].delay
);
125 static int lms283gf05_power_set(struct lcd_device
*ld
, int power
)
127 struct lms283gf05_state
*st
= lcd_get_data(ld
);
128 struct spi_device
*spi
= st
->spi
;
129 struct lms283gf05_pdata
*pdata
= spi
->dev
.platform_data
;
133 lms283gf05_reset(pdata
->reset_gpio
,
134 pdata
->reset_inverted
);
135 lms283gf05_toggle(spi
, disp_initseq
, ARRAY_SIZE(disp_initseq
));
137 lms283gf05_toggle(spi
, disp_pdwnseq
, ARRAY_SIZE(disp_pdwnseq
));
139 gpio_set_value(pdata
->reset_gpio
,
140 pdata
->reset_inverted
);
146 static struct lcd_ops lms_ops
= {
147 .set_power
= lms283gf05_power_set
,
151 static int __devinit
lms283gf05_probe(struct spi_device
*spi
)
153 struct lms283gf05_state
*st
;
154 struct lms283gf05_pdata
*pdata
= spi
->dev
.platform_data
;
155 struct lcd_device
*ld
;
159 ret
= gpio_request(pdata
->reset_gpio
, "LMS285GF05 RESET");
163 ret
= gpio_direction_output(pdata
->reset_gpio
,
164 !pdata
->reset_inverted
);
169 st
= kzalloc(sizeof(struct lms283gf05_state
), GFP_KERNEL
);
171 dev_err(&spi
->dev
, "No memory for device state\n");
176 ld
= lcd_device_register("lms283gf05", &spi
->dev
, st
, &lms_ops
);
185 dev_set_drvdata(&spi
->dev
, st
);
187 /* kick in the LCD */
189 lms283gf05_reset(pdata
->reset_gpio
, pdata
->reset_inverted
);
190 lms283gf05_toggle(spi
, disp_initseq
, ARRAY_SIZE(disp_initseq
));
198 gpio_free(pdata
->reset_gpio
);
203 static int __devexit
lms283gf05_remove(struct spi_device
*spi
)
205 struct lms283gf05_state
*st
= dev_get_drvdata(&spi
->dev
);
206 struct lms283gf05_pdata
*pdata
= st
->spi
->dev
.platform_data
;
208 lcd_device_unregister(st
->ld
);
211 gpio_free(pdata
->reset_gpio
);
218 static struct spi_driver lms283gf05_driver
= {
220 .name
= "lms283gf05",
221 .owner
= THIS_MODULE
,
223 .probe
= lms283gf05_probe
,
224 .remove
= __devexit_p(lms283gf05_remove
),
227 static __init
int lms283gf05_init(void)
229 return spi_register_driver(&lms283gf05_driver
);
232 static __exit
void lms283gf05_exit(void)
234 spi_unregister_driver(&lms283gf05_driver
);
237 module_init(lms283gf05_init
);
238 module_exit(lms283gf05_exit
);
240 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
241 MODULE_DESCRIPTION("LCD283GF05 LCD");
242 MODULE_LICENSE("GPL v2");