aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/xburst/patches-3.2/0007-Add-ili8960-lcd-driver.patch
blob: d31f5176a5565e0d58d64e9cb6dbab8f8dcf215b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
From 2248fb9c47fe7e72c735d6c16aba27bf92e1673a Mon Sep 17 00:00:00 2001
From: Lars-Peter Clausen <lars@metafoo.de>
Date: Sun, 1 Aug 2010 21:19:40 +0200
Subject: [PATCH 07/21] Add ili8960 lcd driver

---
 drivers/video/backlight/Kconfig   |    7 +
 drivers/video/backlight/Makefile  |    1 +
 drivers/video/backlight/ili8960.c |  263 +++++++++++++++++++++++++++++++++++++
 3 files changed, 271 insertions(+), 0 deletions(-)
 create mode 100644 drivers/video/backlight/ili8960.c

diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 278aeaa..f617883 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -59,6 +59,13 @@ config LCD_LTV350QV
 
 	  The LTV350QV panel is present on all ATSTK1000 boards.
 
+config LCD_ILI8960
+	tristate "Ilitek ili8960 LCD driver"
+	depends on LCD_CLASS_DEVICE && SPI
+	default n
+	help
+	  Driver for the Ilitek ili8960 LCD controller chip.
+
 config LCD_ILI9320
 	tristate
 	help
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index fdd1fc4..01ec378 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_LCD_HP700)		   += jornada720_lcd.o
 obj-$(CONFIG_LCD_L4F00242T03)	   += l4f00242t03.o
 obj-$(CONFIG_LCD_LMS283GF05)	   += lms283gf05.o
 obj-$(CONFIG_LCD_LTV350QV)	   += ltv350qv.o
+obj-$(CONFIG_LCD_ILI8960)	   += ili8960.o
 obj-$(CONFIG_LCD_ILI9320)	   += ili9320.o
 obj-$(CONFIG_LCD_PLATFORM)	   += platform_lcd.o
 obj-$(CONFIG_LCD_VGG2432A4)	   += vgg2432a4.o
diff --git a/drivers/video/backlight/ili8960.c b/drivers/video/backlight/ili8960.c
new file mode 100644
index 0000000..1438e92
--- /dev/null
+++ b/drivers/video/backlight/ili8960.c
@@ -0,0 +1,263 @@
+/*
+ *  Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
+ *  Driver for Ilitek ili8960 LCD
+ *
+ *  This program is free software; you can redistribute	 it and/or modify it
+ *  under  the terms of	 the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the	License, or (at your
+ *  option) any later version.
+ *
+ *  You should have received a copy of the  GNU General Public License along
+ *  with this program; if not, write  to the Free Software Foundation, Inc.,
+ *  675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/spi/spi.h>
+#include <linux/lcd.h>
+#include <linux/backlight.h>
+#include <linux/delay.h>
+
+struct ili8960 {
+	struct spi_device *spi;
+	struct lcd_device *lcd;
+	struct backlight_device *bl;
+	bool enabled;
+	unsigned int brightness;
+};
+
+#define ILI8960_REG_BRIGHTNESS	0x03
+#define ILI8960_REG_POWER	0x05
+#define ILI8960_REG_CONTRAST	0x0d
+
+static int ili8960_write_reg(struct spi_device *spi, uint8_t reg,
+				uint8_t data)
+{
+	uint8_t buf[2];
+	buf[0] = ((reg & 0x40) << 1) | (reg & 0x3f);
+	buf[1] = data;
+
+	return spi_write(spi, buf, sizeof(buf));
+}
+
+static int ili8960_programm_power(struct spi_device *spi, bool enabled)
+{
+	int ret;
+
+	if (enabled)
+		mdelay(20);
+
+	ret = ili8960_write_reg(spi, ILI8960_REG_POWER, enabled ? 0xc7 : 0xc6);
+
+	if (!enabled)
+		mdelay(20);
+
+	return ret;
+}
+
+static int ili8960_set_power(struct lcd_device *lcd, int power)
+{
+	struct ili8960 *ili8960 = lcd_get_data(lcd);
+
+	switch (power) {
+	case FB_BLANK_UNBLANK:
+		ili8960->enabled = true;
+		break;
+	default:
+		ili8960->enabled = false;
+		break;
+	}
+
+	return ili8960_programm_power(ili8960->spi, ili8960->enabled);
+}
+
+static int ili8960_get_power(struct lcd_device *lcd)
+{
+	struct ili8960 *ili8960 = lcd_get_data(lcd);
+	return ili8960->enabled ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
+}
+
+static int ili8960_set_contrast(struct lcd_device *lcd, int contrast)
+{
+	struct ili8960 *ili8960 = lcd_get_data(lcd);
+
+	return ili8960_write_reg(ili8960->spi, ILI8960_REG_CONTRAST, contrast);
+}
+
+static int ili8960_set_mode(struct lcd_device *lcd, struct fb_videomode *mode)
+{
+	if (mode->xres != 320 && mode->yres != 240)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int ili8960_set_brightness(struct ili8960 *ili8960, int brightness)
+{
+	int ret;
+
+	ret = ili8960_write_reg(ili8960->spi, ILI8960_REG_BRIGHTNESS, brightness);
+
+	if (ret == 0)
+		ili8960->brightness = brightness;
+
+	return ret;
+}
+
+static ssize_t ili8960_show_brightness(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct lcd_device *ld = to_lcd_device(dev);
+	struct ili8960 *ili8960 = lcd_get_data(ld);
+
+	return sprintf(buf, "%u\n", ili8960->brightness);
+}
+
+static ssize_t ili8960_store_brightness(struct device *dev,
+		struct device_attribute *attr, const char *buf, size_t count)
+{
+	struct lcd_device *ld = to_lcd_device(dev);
+	struct ili8960 *ili8960 = lcd_get_data(ld);
+	unsigned long brightness;
+	int ret;
+
+	ret = strict_strtoul(buf, 0, &brightness);
+	if (ret)
+		return ret;
+
+	if (brightness > 255)
+		return -EINVAL;
+
+	ili8960_set_brightness(ili8960, brightness);
+
+	return count;
+}
+
+
+static DEVICE_ATTR(brightness, 0644, ili8960_show_brightness,
+	ili8960_store_brightness);
+
+static struct lcd_ops ili8960_lcd_ops = {
+	.set_power = ili8960_set_power,
+	.get_power = ili8960_get_power,
+	.set_contrast = ili8960_set_contrast,
+	.set_mode = ili8960_set_mode,
+};
+
+static int __devinit ili8960_probe(struct spi_device *spi)
+{
+	int ret;
+	struct ili8960 *ili8960;
+
+	ili8960 = kmalloc(sizeof(*ili8960), GFP_KERNEL);
+	if (!ili8960)
+		return -ENOMEM;
+
+	spi->bits_per_word = 8;
+	spi->mode = SPI_MODE_3;
+
+	ret = spi_setup(spi);
+	if (ret) {
+		dev_err(&spi->dev, "Failed to setup spi\n");
+		goto err_free_ili8960;
+	}
+
+	ili8960->spi = spi;
+
+	ili8960->lcd = lcd_device_register("ili8960-lcd", &spi->dev, ili8960,
+						&ili8960_lcd_ops);
+
+	if (IS_ERR(ili8960->lcd)) {
+		ret = PTR_ERR(ili8960->lcd);
+		dev_err(&spi->dev, "Failed to register lcd device: %d\n", ret);
+		goto err_free_ili8960;
+	}
+
+	ili8960->lcd->props.max_contrast = 255;
+
+	ret = device_create_file(&ili8960->lcd->dev, &dev_attr_brightness);
+	if (ret)
+		goto err_unregister_lcd;
+
+	ili8960_programm_power(ili8960->spi, true);
+	ili8960->enabled = true;
+
+	spi_set_drvdata(spi, ili8960);
+
+	ili8960_write_reg(spi, 0x13, 0x01);
+
+	return 0;
+err_unregister_lcd:
+	lcd_device_unregister(ili8960->lcd);
+err_free_ili8960:
+	kfree(ili8960);
+	return ret;
+}
+
+static int __devexit ili8960_remove(struct spi_device *spi)
+{
+	struct ili8960 *ili8960 = spi_get_drvdata(spi);
+
+	device_remove_file(&ili8960->lcd->dev, &dev_attr_brightness);
+	lcd_device_unregister(ili8960->lcd);
+
+	spi_set_drvdata(spi, NULL);
+	kfree(ili8960);
+	return 0;
+}
+
+#ifdef CONFIG_PM
+
+static int ili8960_suspend(struct spi_device *spi, pm_message_t state)
+{
+	struct ili8960 *ili8960 = spi_get_drvdata(spi);
+
+	if (ili8960->enabled)
+		ili8960_programm_power(ili8960->spi, false);
+
+	return 0;
+}
+
+static int ili8960_resume(struct spi_device *spi)
+{
+	struct ili8960 *ili8960 = spi_get_drvdata(spi);
+
+	if (ili8960->enabled)
+		ili8960_programm_power(ili8960->spi, true);
+
+	return 0;
+}
+
+#else
+#define ili8960_suspend NULL
+#define ili8960_resume NULL
+#endif
+
+static struct spi_driver ili8960_driver = {
+	.driver = {
+		.name = "ili8960",
+		.owner = THIS_MODULE,
+	},
+	.probe = ili8960_probe,
+	.remove = __devexit_p(ili8960_remove),
+	.suspend = ili8960_suspend,
+	.resume = ili8960_resume,
+};
+
+static int __init ili8960_init(void)
+{
+	return spi_register_driver(&ili8960_driver);
+}
+module_init(ili8960_init);
+
+static void __exit ili8960_exit(void)
+{
+	spi_unregister_driver(&ili8960_driver);
+}
+module_exit(ili8960_exit)
+
+MODULE_AUTHOR("Lars-Peter Clausen");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("LCD driver for Ilitek ili8960");
+MODULE_ALIAS("spi:ili8960");
-- 
1.7.5.4