1 From baf5f6c4f4ec0caf5240b452b75eeab2f96d8bd4 Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Sat, 24 Apr 2010 12:20:56 +0200
4 Subject: [PATCH] Add gpm940b0 lcd driver
7 drivers/video/backlight/Kconfig | 7 +
8 drivers/video/backlight/Makefile | 1 +
9 drivers/video/backlight/gpm940b0.c | 253 ++++++++++++++++++++++++++++++++++++
10 3 files changed, 261 insertions(+), 0 deletions(-)
11 create mode 100644 drivers/video/backlight/gpm940b0.c
13 diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
14 index c025c84..0a61f91 100644
15 --- a/drivers/video/backlight/Kconfig
16 +++ b/drivers/video/backlight/Kconfig
17 @@ -107,6 +107,13 @@ config LCD_HP700
18 If you have an HP Jornada 700 series handheld (710/720/728)
19 say Y to enable LCD control driver.
22 + tristate "Giantplus GPM940B0 LCD and backlight driver"
23 + depends on LCD_CLASS_DEVICE && SPI
26 + LCD and backlight driver for the Giantplus GPM940B0 LCD module.
31 diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
32 index 09d1f14..a03ec9c 100644
33 --- a/drivers/video/backlight/Makefile
34 +++ b/drivers/video/backlight/Makefile
35 @@ -11,6 +11,7 @@ obj-$(CONFIG_LCD_PLATFORM) += platform_lcd.o
36 obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o
37 obj-$(CONFIG_LCD_TDO24M) += tdo24m.o
38 obj-$(CONFIG_LCD_TOSA) += tosa_lcd.o
39 +obj-$(CONFIG_LCD_GPM940B0) += gpm940b0.o
41 obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
42 obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.o
43 diff --git a/drivers/video/backlight/gpm940b0.c b/drivers/video/backlight/gpm940b0.c
45 index 0000000..879e3ad
47 +++ b/drivers/video/backlight/gpm940b0.c
50 + * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
51 + * Driver for Giantplus GPM940B0 LCD
53 + * This program is free software; you can redistribute it and/or modify it
54 + * under the terms of the GNU General Public License as published by the
55 + * Free Software Foundation; either version 2 of the License, or (at your
56 + * option) any later version.
58 + * You should have received a copy of the GNU General Public License along
59 + * with this program; if not, write to the Free Software Foundation, Inc.,
60 + * 675 Mass Ave, Cambridge, MA 02139, USA.
64 +#include <linux/module.h>
65 +#include <linux/spi/spi.h>
66 +#include <linux/lcd.h>
67 +#include <linux/backlight.h>
68 +#include <linux/delay.h>
71 + struct spi_device *spi;
72 + struct lcd_device *lcd;
73 + struct backlight_device *bl;
77 +static int gpm940b0_write_reg(struct spi_device *spi, uint8_t reg,
81 + buf[0] = ((reg & 0x40) << 1) | (reg & 0x3f);
84 + return spi_write(spi, buf, sizeof(buf));
87 +static void gpm940b0_power_disable(struct spi_device *spi)
89 + int ret = gpm940b0_write_reg(spi, 0x5, 0xc6) ;
91 + dev_err(&spi->dev, "Failed to disable power: %d\n", ret);
94 +static void gpm940b0_power_enable(struct spi_device *spi)
96 + gpm940b0_write_reg(spi, 0x5, 0xc7);
100 +static int gpm940b0_set_power(struct lcd_device *lcd, int power)
102 + struct gpm940b0 *gpm940b0 = lcd_get_data(lcd);
105 + case FB_BLANK_UNBLANK:
107 + gpm940b0->enabled = 1;
108 + gpm940b0_power_enable(gpm940b0->spi);
111 + gpm940b0->enabled = 0;
112 + gpm940b0_power_disable(gpm940b0->spi);
119 +static int gpm940b0_set_contrast(struct lcd_device *lcd, int contrast)
121 + struct gpm940b0 *gpm940b0 = lcd_get_data(lcd);
122 + gpm940b0_write_reg(gpm940b0->spi, 0x0d, contrast);
126 +static int gpm940b0_set_mode(struct lcd_device *lcd, struct fb_videomode *mode)
128 + if (mode->xres != 320 && mode->yres != 240)
134 +static ssize_t reg_write(struct device *dev, struct device_attribute *attr,
135 + const char *buf, size_t count)
138 + uint32_t reg = simple_strtoul(buf, &buf2, 10);
139 + uint32_t val = simple_strtoul(buf2 + 1, NULL, 10);
140 + struct gpm940b0 *gpm940b0 = dev_get_drvdata(dev);
142 + if (reg < 0 || val < 0)
145 + gpm940b0_write_reg(gpm940b0->spi, reg, val);
149 +static DEVICE_ATTR(reg, 0644, NULL, reg_write);
151 +static ssize_t gpm940b0_show_brightness(struct device *dev,
152 + struct device_attribute *attr, char *buf)
159 +static ssize_t gpm940b0_store_brightness(struct device *dev,
160 + struct device_attribute *attr, const char *buf, size_t count)
163 + struct lcd_device *ld = to_lcd_device(dev);
164 + struct gpm940b0 *gpm940b0 = lcd_get_data(ld);
165 + int brightness = simple_strtoul(buf, &endp, 0);
167 + if (brightness > 255 || brightness < 0)
170 + gpm940b0_write_reg(gpm940b0->spi, 0x3, brightness);
176 +static DEVICE_ATTR(brightness, 0644, gpm940b0_show_brightness,
177 + gpm940b0_store_brightness);
179 +static struct lcd_ops gpm940b0_lcd_ops = {
180 + .set_power = gpm940b0_set_power,
181 + .set_contrast = gpm940b0_set_contrast,
182 + .set_mode = gpm940b0_set_mode,
185 +static int __devinit gpm940b0_probe(struct spi_device *spi)
188 + struct gpm940b0 *gpm940b0;
190 + gpm940b0 = kmalloc(sizeof(*gpm940b0), GFP_KERNEL);
192 + spi->bits_per_word = 8;
193 + spi->mode = SPI_MODE_3 | SPI_3WIRE;
195 + ret = spi_setup(spi);
197 + dev_err(&spi->dev, "Failed to setup spi\n");
198 + goto err_free_gpm940b0;
201 + gpm940b0->spi = spi;
203 + gpm940b0->lcd = lcd_device_register("gpm940b0-lcd", &spi->dev, gpm940b0,
204 + &gpm940b0_lcd_ops);
206 + if (IS_ERR(gpm940b0->lcd)) {
207 + ret = PTR_ERR(gpm940b0->lcd);
208 + dev_err(&spi->dev, "Failed to register lcd device: %d\n", ret);
209 + goto err_free_gpm940b0;
212 + gpm940b0->lcd->props.max_contrast = 255;
214 + ret = device_create_file(&spi->dev, &dev_attr_reg);
216 + goto err_unregister_lcd;
218 + ret = device_create_file(&gpm940b0->lcd->dev, &dev_attr_brightness);
220 + goto err_unregister_lcd;
222 + gpm940b0->enabled = 1;
223 + dev_set_drvdata(&spi->dev, gpm940b0);
225 + gpm940b0_write_reg(spi, 0x13, 0x01);
226 + gpm940b0_write_reg(spi, 0x5, 0xc7);
229 + lcd_device_unregister(gpm940b0->lcd);
235 +static int __devexit gpm940b0_remove(struct spi_device *spi)
237 + struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
240 + backlight_device_unregister(gpm940b0->bl);
243 + lcd_device_unregister(gpm940b0->lcd);
245 + spi_set_drvdata(spi, NULL);
252 +static int gpm940b0_suspend(struct spi_device *spi, pm_message_t state)
254 + struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
255 + if (gpm940b0->enabled) {
256 + gpm940b0_power_disable(spi);
262 +static int gpm940b0_resume(struct spi_device *spi)
264 + struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
265 + if (gpm940b0->enabled)
266 + gpm940b0_power_enable(spi);
271 +#define gpm940b0_suspend NULL
272 +#define gpm940b0_resume NULL
275 +static struct spi_driver gpm940b0_driver = {
277 + .name = "gpm940b0",
278 + .owner = THIS_MODULE,
280 + .probe = gpm940b0_probe,
281 + .remove = __devexit_p(gpm940b0_remove),
282 + .suspend = gpm940b0_suspend,
283 + .resume = gpm940b0_resume,
286 +static int __init gpm940b0_init(void)
288 + return spi_register_driver(&gpm940b0_driver);
290 +module_init(gpm940b0_init);
292 +static void __exit gpm940b0_exit(void)
294 + return spi_unregister_driver(&gpm940b0_driver);
296 +module_exit(gpm940b0_exit)
298 +MODULE_AUTHOR("Lars-Peter Clausen");
299 +MODULE_LICENSE("GPL v2");
300 +MODULE_DESCRIPTION("LCD and backlight controll for Giantplus GPM940B0");
301 +MODULE_ALIAS("spi:gpm940b0");