[ar7] rework multi_probe patch to be cleaner
[openwrt.git] / target / linux / xburst / patches-2.6.34 / 101-lcm.patch
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
5
6 ---
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
12
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.
20
21 +config LCD_GPM940B0
22 + tristate "Giantplus GPM940B0 LCD and backlight driver"
23 + depends on LCD_CLASS_DEVICE && SPI
24 + default n
25 + help
26 + LCD and backlight driver for the Giantplus GPM940B0 LCD module.
27 +
28 #
29 # Backlight
30 #
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
40
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
44 new file mode 100644
45 index 0000000..879e3ad
46 --- /dev/null
47 +++ b/drivers/video/backlight/gpm940b0.c
48 @@ -0,0 +1,253 @@
49 +/*
50 + * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
51 + * Driver for Giantplus GPM940B0 LCD
52 + *
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.
57 + *
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.
61 + *
62 + */
63 +
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>
69 +
70 +struct gpm940b0 {
71 + struct spi_device *spi;
72 + struct lcd_device *lcd;
73 + struct backlight_device *bl;
74 + unsigned enabled:1;
75 +};
76 +
77 +static int gpm940b0_write_reg(struct spi_device *spi, uint8_t reg,
78 + uint8_t data)
79 +{
80 + uint8_t buf[2];
81 + buf[0] = ((reg & 0x40) << 1) | (reg & 0x3f);
82 + buf[1] = data;
83 +
84 + return spi_write(spi, buf, sizeof(buf));
85 +}
86 +
87 +static void gpm940b0_power_disable(struct spi_device *spi)
88 +{
89 + int ret = gpm940b0_write_reg(spi, 0x5, 0xc6) ;
90 + if (ret < 0)
91 + dev_err(&spi->dev, "Failed to disable power: %d\n", ret);
92 +}
93 +
94 +static void gpm940b0_power_enable(struct spi_device *spi)
95 +{
96 + gpm940b0_write_reg(spi, 0x5, 0xc7);
97 +}
98 +
99 +
100 +static int gpm940b0_set_power(struct lcd_device *lcd, int power)
101 +{
102 + struct gpm940b0 *gpm940b0 = lcd_get_data(lcd);
103 +
104 + switch (power) {
105 + case FB_BLANK_UNBLANK:
106 + mdelay(20);
107 + gpm940b0->enabled = 1;
108 + gpm940b0_power_enable(gpm940b0->spi);
109 + break;
110 + default:
111 + gpm940b0->enabled = 0;
112 + gpm940b0_power_disable(gpm940b0->spi);
113 + mdelay(20);
114 + break;
115 + }
116 + return 0;
117 +}
118 +
119 +static int gpm940b0_set_contrast(struct lcd_device *lcd, int contrast)
120 +{
121 + struct gpm940b0 *gpm940b0 = lcd_get_data(lcd);
122 + gpm940b0_write_reg(gpm940b0->spi, 0x0d, contrast);
123 + return 0;
124 +}
125 +
126 +static int gpm940b0_set_mode(struct lcd_device *lcd, struct fb_videomode *mode)
127 +{
128 + if (mode->xres != 320 && mode->yres != 240)
129 + return -EINVAL;
130 +
131 + return 0;
132 +}
133 +
134 +static ssize_t reg_write(struct device *dev, struct device_attribute *attr,
135 + const char *buf, size_t count)
136 +{
137 + char *buf2;
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);
141 +
142 + if (reg < 0 || val < 0)
143 + return -EINVAL;
144 +
145 + gpm940b0_write_reg(gpm940b0->spi, reg, val);
146 + return count;
147 +}
148 +
149 +static DEVICE_ATTR(reg, 0644, NULL, reg_write);
150 +
151 +static ssize_t gpm940b0_show_brightness(struct device *dev,
152 + struct device_attribute *attr, char *buf)
153 +{
154 + int rc = -ENXIO;
155 +
156 + return rc;
157 +}
158 +
159 +static ssize_t gpm940b0_store_brightness(struct device *dev,
160 + struct device_attribute *attr, const char *buf, size_t count)
161 +{
162 + char *endp;
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);
166 +
167 + if (brightness > 255 || brightness < 0)
168 + return -EINVAL;
169 +
170 + gpm940b0_write_reg(gpm940b0->spi, 0x3, brightness);
171 +
172 + return count;
173 +}
174 +
175 +
176 +static DEVICE_ATTR(brightness, 0644, gpm940b0_show_brightness,
177 + gpm940b0_store_brightness);
178 +
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,
183 +};
184 +
185 +static int __devinit gpm940b0_probe(struct spi_device *spi)
186 +{
187 + int ret;
188 + struct gpm940b0 *gpm940b0;
189 +
190 + gpm940b0 = kmalloc(sizeof(*gpm940b0), GFP_KERNEL);
191 +
192 + spi->bits_per_word = 8;
193 + spi->mode = SPI_MODE_3 | SPI_3WIRE;
194 +
195 + ret = spi_setup(spi);
196 + if (ret) {
197 + dev_err(&spi->dev, "Failed to setup spi\n");
198 + goto err_free_gpm940b0;
199 + }
200 +
201 + gpm940b0->spi = spi;
202 +
203 + gpm940b0->lcd = lcd_device_register("gpm940b0-lcd", &spi->dev, gpm940b0,
204 + &gpm940b0_lcd_ops);
205 +
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;
210 + }
211 +
212 + gpm940b0->lcd->props.max_contrast = 255;
213 +
214 + ret = device_create_file(&spi->dev, &dev_attr_reg);
215 + if (ret)
216 + goto err_unregister_lcd;
217 +
218 + ret = device_create_file(&gpm940b0->lcd->dev, &dev_attr_brightness);
219 + if (ret)
220 + goto err_unregister_lcd;
221 +
222 + gpm940b0->enabled = 1;
223 + dev_set_drvdata(&spi->dev, gpm940b0);
224 +
225 + gpm940b0_write_reg(spi, 0x13, 0x01);
226 + gpm940b0_write_reg(spi, 0x5, 0xc7);
227 + return 0;
228 +err_unregister_lcd:
229 + lcd_device_unregister(gpm940b0->lcd);
230 +err_free_gpm940b0:
231 + kfree(gpm940b0);
232 + return ret;
233 +}
234 +
235 +static int __devexit gpm940b0_remove(struct spi_device *spi)
236 +{
237 + struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
238 +#if 0
239 + if (gpm940b0->bl)
240 + backlight_device_unregister(gpm940b0->bl);
241 +#endif
242 +
243 + lcd_device_unregister(gpm940b0->lcd);
244 +
245 + spi_set_drvdata(spi, NULL);
246 + kfree(gpm940b0);
247 + return 0;
248 +}
249 +
250 +#ifdef CONFIG_PM
251 +
252 +static int gpm940b0_suspend(struct spi_device *spi, pm_message_t state)
253 +{
254 + struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
255 + if (gpm940b0->enabled) {
256 + gpm940b0_power_disable(spi);
257 + mdelay(10);
258 + }
259 + return 0;
260 +}
261 +
262 +static int gpm940b0_resume(struct spi_device *spi)
263 +{
264 + struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
265 + if (gpm940b0->enabled)
266 + gpm940b0_power_enable(spi);
267 + return 0;
268 +}
269 +
270 +#else
271 +#define gpm940b0_suspend NULL
272 +#define gpm940b0_resume NULL
273 +#endif
274 +
275 +static struct spi_driver gpm940b0_driver = {
276 + .driver = {
277 + .name = "gpm940b0",
278 + .owner = THIS_MODULE,
279 + },
280 + .probe = gpm940b0_probe,
281 + .remove = __devexit_p(gpm940b0_remove),
282 + .suspend = gpm940b0_suspend,
283 + .resume = gpm940b0_resume,
284 +};
285 +
286 +static int __init gpm940b0_init(void)
287 +{
288 + return spi_register_driver(&gpm940b0_driver);
289 +}
290 +module_init(gpm940b0_init);
291 +
292 +static void __exit gpm940b0_exit(void)
293 +{
294 + return spi_unregister_driver(&gpm940b0_driver);
295 +}
296 +module_exit(gpm940b0_exit)
297 +
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");
302 --
303 1.5.6.5
304
This page took 0.051226 seconds and 5 git commands to generate.