[ar71xx] tune rtl8366s default config, make vlan 1 cpu port tagged and use eth0.1...
[openwrt.git] / target / linux / xburst / patches-2.6.35 / 101-lcm.patch
1 From 2e27414748a56d8583c151d926da54e7e9d2c23f Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Sun, 1 Aug 2010 21:19:40 +0200
4 Subject: [PATCH] Add ili8960 lcd driver
5
6 ---
7 drivers/video/backlight/Kconfig | 7 +
8 drivers/video/backlight/Makefile | 1 +
9 drivers/video/backlight/ili8960.c | 254 +++++++++++++++++++++++++++++++++++++
10 3 files changed, 262 insertions(+), 0 deletions(-)
11 create mode 100644 drivers/video/backlight/ili8960.c
12
13 --- a/drivers/video/backlight/Kconfig
14 +++ b/drivers/video/backlight/Kconfig
15 @@ -59,6 +59,13 @@ config LCD_LTV350QV
16
17 The LTV350QV panel is present on all ATSTK1000 boards.
18
19 +config LCD_ILI8960
20 + tristate "Ilitek ili8960 LCD driver"
21 + depends on LCD_CLASS_DEVICE && SPI
22 + default n
23 + help
24 + Driver for the Ilitek ili8960 LCD controller chip.
25 +
26 config LCD_ILI9320
27 tristate
28 help
29 --- a/drivers/video/backlight/Makefile
30 +++ b/drivers/video/backlight/Makefile
31 @@ -6,6 +6,7 @@ obj-$(CONFIG_LCD_HP700) += jornada72
32 obj-$(CONFIG_LCD_L4F00242T03) += l4f00242t03.o
33 obj-$(CONFIG_LCD_LMS283GF05) += lms283gf05.o
34 obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o
35 +obj-$(CONFIG_LCD_ILI8960) += ili8960.o
36 obj-$(CONFIG_LCD_ILI9320) += ili9320.o
37 obj-$(CONFIG_LCD_PLATFORM) += platform_lcd.o
38 obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o
39 --- /dev/null
40 +++ b/drivers/video/backlight/ili8960.c
41 @@ -0,0 +1,254 @@
42 +/*
43 + * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
44 + * Driver for Ilitek ili8960 LCD
45 + *
46 + * This program is free software; you can redistribute it and/or modify it
47 + * under the terms of the GNU General Public License as published by the
48 + * Free Software Foundation; either version 2 of the License, or (at your
49 + * option) any later version.
50 + *
51 + * You should have received a copy of the GNU General Public License along
52 + * with this program; if not, write to the Free Software Foundation, Inc.,
53 + * 675 Mass Ave, Cambridge, MA 02139, USA.
54 + *
55 + */
56 +
57 +#include <linux/module.h>
58 +#include <linux/spi/spi.h>
59 +#include <linux/lcd.h>
60 +#include <linux/backlight.h>
61 +#include <linux/delay.h>
62 +
63 +struct ili8960 {
64 + struct spi_device *spi;
65 + struct lcd_device *lcd;
66 + struct backlight_device *bl;
67 + unsigned enabled:1;
68 +};
69 +
70 +static int ili8960_write_reg(struct spi_device *spi, uint8_t reg,
71 + uint8_t data)
72 +{
73 + uint8_t buf[2];
74 + buf[0] = ((reg & 0x40) << 1) | (reg & 0x3f);
75 + buf[1] = data;
76 +
77 + return spi_write(spi, buf, sizeof(buf));
78 +}
79 +
80 +static void ili8960_power_disable(struct spi_device *spi)
81 +{
82 + int ret = ili8960_write_reg(spi, 0x5, 0xc6) ;
83 + if (ret < 0)
84 + dev_err(&spi->dev, "Failed to disable power: %d\n", ret);
85 +}
86 +
87 +static void ili8960_power_enable(struct spi_device *spi)
88 +{
89 + ili8960_write_reg(spi, 0x5, 0xc7);
90 +}
91 +
92 +
93 +static int ili8960_set_power(struct lcd_device *lcd, int power)
94 +{
95 + struct ili8960 *ili8960 = lcd_get_data(lcd);
96 +
97 + switch (power) {
98 + case FB_BLANK_UNBLANK:
99 + mdelay(20);
100 + ili8960->enabled = 1;
101 + ili8960_power_enable(ili8960->spi);
102 + break;
103 + default:
104 + ili8960->enabled = 0;
105 + ili8960_power_disable(ili8960->spi);
106 + mdelay(20);
107 + break;
108 + }
109 + return 0;
110 +}
111 +
112 +static int ili8960_set_contrast(struct lcd_device *lcd, int contrast)
113 +{
114 + struct ili8960 *ili8960 = lcd_get_data(lcd);
115 + ili8960_write_reg(ili8960->spi, 0x0d, contrast);
116 + return 0;
117 +}
118 +
119 +static int ili8960_set_mode(struct lcd_device *lcd, struct fb_videomode *mode)
120 +{
121 + if (mode->xres != 320 && mode->yres != 240)
122 + return -EINVAL;
123 +
124 + return 0;
125 +}
126 +
127 +static ssize_t reg_write(struct device *dev, struct device_attribute *attr,
128 + const char *buf, size_t count)
129 +{
130 + char *buf2;
131 + uint32_t reg = simple_strtoul(buf, &buf2, 10);
132 + uint32_t val = simple_strtoul(buf2 + 1, NULL, 10);
133 + struct ili8960 *ili8960 = dev_get_drvdata(dev);
134 +
135 + if (reg < 0 || val < 0)
136 + return -EINVAL;
137 +
138 + ili8960_write_reg(ili8960->spi, reg, val);
139 + return count;
140 +}
141 +
142 +static DEVICE_ATTR(reg, 0644, NULL, reg_write);
143 +
144 +static ssize_t ili8960_show_brightness(struct device *dev,
145 + struct device_attribute *attr, char *buf)
146 +{
147 + int rc = -ENXIO;
148 +
149 + return rc;
150 +}
151 +
152 +static ssize_t ili8960_store_brightness(struct device *dev,
153 + struct device_attribute *attr, const char *buf, size_t count)
154 +{
155 + char *endp;
156 + struct lcd_device *ld = to_lcd_device(dev);
157 + struct ili8960 *ili8960 = lcd_get_data(ld);
158 + int brightness = simple_strtoul(buf, &endp, 0);
159 +
160 + if (brightness > 255 || brightness < 0)
161 + return -EINVAL;
162 +
163 + ili8960_write_reg(ili8960->spi, 0x3, brightness);
164 +
165 + return count;
166 +}
167 +
168 +
169 +static DEVICE_ATTR(brightness, 0644, ili8960_show_brightness,
170 + ili8960_store_brightness);
171 +
172 +static struct lcd_ops ili8960_lcd_ops = {
173 + .set_power = ili8960_set_power,
174 + .set_contrast = ili8960_set_contrast,
175 + .set_mode = ili8960_set_mode,
176 +};
177 +
178 +static int __devinit ili8960_probe(struct spi_device *spi)
179 +{
180 + int ret;
181 + struct ili8960 *ili8960;
182 +
183 + ili8960 = kmalloc(sizeof(*ili8960), GFP_KERNEL);
184 +
185 + spi->bits_per_word = 8;
186 + spi->mode = SPI_MODE_3 | SPI_3WIRE;
187 +
188 + ret = spi_setup(spi);
189 + if (ret) {
190 + dev_err(&spi->dev, "Failed to setup spi\n");
191 + goto err_free_ili8960;
192 + }
193 +
194 + ili8960->spi = spi;
195 +
196 + ili8960->lcd = lcd_device_register("ili8960-lcd", &spi->dev, ili8960,
197 + &ili8960_lcd_ops);
198 +
199 + if (IS_ERR(ili8960->lcd)) {
200 + ret = PTR_ERR(ili8960->lcd);
201 + dev_err(&spi->dev, "Failed to register lcd device: %d\n", ret);
202 + goto err_free_ili8960;
203 + }
204 +
205 + ili8960->lcd->props.max_contrast = 255;
206 +
207 + ret = device_create_file(&spi->dev, &dev_attr_reg);
208 + if (ret)
209 + goto err_unregister_lcd;
210 +
211 + ret = device_create_file(&ili8960->lcd->dev, &dev_attr_brightness);
212 + if (ret)
213 + goto err_unregister_lcd;
214 +
215 + ili8960->enabled = 1;
216 + dev_set_drvdata(&spi->dev, ili8960);
217 +
218 + ili8960_write_reg(spi, 0x13, 0x01);
219 + ili8960_write_reg(spi, 0x5, 0xc7);
220 +
221 + return 0;
222 +err_unregister_lcd:
223 + lcd_device_unregister(ili8960->lcd);
224 +err_free_ili8960:
225 + kfree(ili8960);
226 + return ret;
227 +}
228 +
229 +static int __devexit ili8960_remove(struct spi_device *spi)
230 +{
231 + struct ili8960 *ili8960 = spi_get_drvdata(spi);
232 +#if 0
233 + if (ili8960->bl)
234 + backlight_device_unregister(ili8960->bl);
235 +#endif
236 +
237 + lcd_device_unregister(ili8960->lcd);
238 +
239 + spi_set_drvdata(spi, NULL);
240 + kfree(ili8960);
241 + return 0;
242 +}
243 +
244 +#ifdef CONFIG_PM
245 +
246 +static int ili8960_suspend(struct spi_device *spi, pm_message_t state)
247 +{
248 + struct ili8960 *ili8960 = spi_get_drvdata(spi);
249 + if (ili8960->enabled) {
250 + ili8960_power_disable(spi);
251 + mdelay(10);
252 + }
253 + return 0;
254 +}
255 +
256 +static int ili8960_resume(struct spi_device *spi)
257 +{
258 + struct ili8960 *ili8960 = spi_get_drvdata(spi);
259 + if (ili8960->enabled)
260 + ili8960_power_enable(spi);
261 + return 0;
262 +}
263 +
264 +#else
265 +#define ili8960_suspend NULL
266 +#define ili8960_resume NULL
267 +#endif
268 +
269 +static struct spi_driver ili8960_driver = {
270 + .driver = {
271 + .name = "ili8960",
272 + .owner = THIS_MODULE,
273 + },
274 + .probe = ili8960_probe,
275 + .remove = __devexit_p(ili8960_remove),
276 + .suspend = ili8960_suspend,
277 + .resume = ili8960_resume,
278 +};
279 +
280 +static int __init ili8960_init(void)
281 +{
282 + return spi_register_driver(&ili8960_driver);
283 +}
284 +module_init(ili8960_init);
285 +
286 +static void __exit ili8960_exit(void)
287 +{
288 + return spi_unregister_driver(&ili8960_driver);
289 +}
290 +module_exit(ili8960_exit)
291 +
292 +MODULE_AUTHOR("Lars-Peter Clausen");
293 +MODULE_LICENSE("GPL v2");
294 +MODULE_DESCRIPTION("LCD driver for Ilitek ili8960");
295 +MODULE_ALIAS("spi:ili8960");
This page took 0.051792 seconds and 5 git commands to generate.