Date: | 2010-08-01 21:19:40 (13 years 7 months ago) |
---|---|
Author: | Lars C. |
Commit: | 4e77325b83c616eea16d173b6c206e225540bf3d |
Message: | Add ili8960 lcd driver |
Files: |
drivers/video/backlight/Kconfig (1 diff) drivers/video/backlight/Makefile (1 diff) drivers/video/backlight/ili8960.c (1 diff) |
Change Details
drivers/video/backlight/Kconfig | ||
---|---|---|
59 | 59 | |
60 | 60 | The LTV350QV panel is present on all ATSTK1000 boards. |
61 | 61 | |
62 | config LCD_ILI8960 | |
63 | tristate "Ilitek ili8960 LCD driver" | |
64 | depends on LCD_CLASS_DEVICE && SPI | |
65 | default n | |
66 | help | |
67 | Driver for the Ilitek ili8960 LCD controller chip. | |
68 | ||
62 | 69 | config LCD_ILI9320 |
63 | 70 | tristate |
64 | 71 | help |
drivers/video/backlight/Makefile | ||
---|---|---|
6 | 6 | obj-$(CONFIG_LCD_L4F00242T03) += l4f00242t03.o |
7 | 7 | obj-$(CONFIG_LCD_LMS283GF05) += lms283gf05.o |
8 | 8 | obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o |
9 | obj-$(CONFIG_LCD_ILI8960) += ili8960.o | |
9 | 10 | obj-$(CONFIG_LCD_ILI9320) += ili9320.o |
10 | 11 | obj-$(CONFIG_LCD_PLATFORM) += platform_lcd.o |
11 | 12 | obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o |
drivers/video/backlight/ili8960.c | ||
---|---|---|
1 | /* | |
2 | * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de> | |
3 | * Driver for Ilitek ili8960 LCD | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the | |
7 | * Free Software Foundation; either version 2 of the License, or (at your | |
8 | * option) any later version. | |
9 | * | |
10 | * You should have received a copy of the GNU General Public License along | |
11 | * with this program; if not, write to the Free Software Foundation, Inc., | |
12 | * 675 Mass Ave, Cambridge, MA 02139, USA. | |
13 | * | |
14 | */ | |
15 | ||
16 | #include <linux/module.h> | |
17 | #include <linux/spi/spi.h> | |
18 | #include <linux/lcd.h> | |
19 | #include <linux/backlight.h> | |
20 | #include <linux/delay.h> | |
21 | ||
22 | struct ili8960 { | |
23 | struct spi_device *spi; | |
24 | struct lcd_device *lcd; | |
25 | struct backlight_device *bl; | |
26 | bool enabled; | |
27 | unsigned int brightness; | |
28 | }; | |
29 | ||
30 | #define ILI8960_REG_BRIGHTNESS 0x03 | |
31 | #define ILI8960_REG_POWER 0x05 | |
32 | #define ILI8960_REG_CONTRAST 0x0d | |
33 | ||
34 | static int ili8960_write_reg(struct spi_device *spi, uint8_t reg, | |
35 | uint8_t data) | |
36 | { | |
37 | uint8_t buf[2]; | |
38 | buf[0] = ((reg & 0x40) << 1) | (reg & 0x3f); | |
39 | buf[1] = data; | |
40 | ||
41 | return spi_write(spi, buf, sizeof(buf)); | |
42 | } | |
43 | ||
44 | static int ili8960_programm_power(struct spi_device *spi, bool enabled) | |
45 | { | |
46 | int ret; | |
47 | ||
48 | if (enabled) | |
49 | mdelay(20); | |
50 | ||
51 | ret = ili8960_write_reg(spi, ILI8960_REG_POWER, enabled ? 0xc7 : 0xc6); | |
52 | ||
53 | if (!enabled) | |
54 | mdelay(20); | |
55 | ||
56 | return ret; | |
57 | } | |
58 | ||
59 | static int ili8960_set_power(struct lcd_device *lcd, int power) | |
60 | { | |
61 | struct ili8960 *ili8960 = lcd_get_data(lcd); | |
62 | ||
63 | switch (power) { | |
64 | case FB_BLANK_UNBLANK: | |
65 | ili8960->enabled = true; | |
66 | break; | |
67 | default: | |
68 | ili8960->enabled = false; | |
69 | break; | |
70 | } | |
71 | ||
72 | return ili8960_programm_power(ili8960->spi, ili8960->enabled); | |
73 | } | |
74 | ||
75 | static int ili8960_get_power(struct lcd_device *lcd) | |
76 | { | |
77 | struct ili8960 *ili8960 = lcd_get_data(lcd); | |
78 | return ili8960->enabled ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; | |
79 | } | |
80 | ||
81 | static int ili8960_set_contrast(struct lcd_device *lcd, int contrast) | |
82 | { | |
83 | struct ili8960 *ili8960 = lcd_get_data(lcd); | |
84 | ||
85 | return ili8960_write_reg(ili8960->spi, ILI8960_REG_CONTRAST, contrast); | |
86 | } | |
87 | ||
88 | static int ili8960_set_mode(struct lcd_device *lcd, struct fb_videomode *mode) | |
89 | { | |
90 | if (mode->xres != 320 && mode->yres != 240) | |
91 | return -EINVAL; | |
92 | ||
93 | return 0; | |
94 | } | |
95 | ||
96 | static int ili8960_set_brightness(struct ili8960 *ili8960, int brightness) | |
97 | { | |
98 | int ret; | |
99 | ||
100 | ret = ili8960_write_reg(ili8960->spi, ILI8960_REG_BRIGHTNESS, brightness); | |
101 | ||
102 | if (ret == 0) | |
103 | ili8960->brightness = brightness; | |
104 | ||
105 | return ret; | |
106 | } | |
107 | ||
108 | static ssize_t ili8960_show_brightness(struct device *dev, | |
109 | struct device_attribute *attr, char *buf) | |
110 | { | |
111 | struct lcd_device *ld = to_lcd_device(dev); | |
112 | struct ili8960 *ili8960 = lcd_get_data(ld); | |
113 | ||
114 | return sprintf(buf, "%u\n", ili8960->brightness); | |
115 | } | |
116 | ||
117 | static ssize_t ili8960_store_brightness(struct device *dev, | |
118 | struct device_attribute *attr, const char *buf, size_t count) | |
119 | { | |
120 | struct lcd_device *ld = to_lcd_device(dev); | |
121 | struct ili8960 *ili8960 = lcd_get_data(ld); | |
122 | unsigned long brightness; | |
123 | int ret; | |
124 | ||
125 | ret = strict_strtoul(buf, 0, &brightness); | |
126 | if (ret) | |
127 | return ret; | |
128 | ||
129 | if (brightness > 255) | |
130 | return -EINVAL; | |
131 | ||
132 | ili8960_set_brightness(ili8960, brightness); | |
133 | ||
134 | return count; | |
135 | } | |
136 | ||
137 | ||
138 | static DEVICE_ATTR(brightness, 0644, ili8960_show_brightness, | |
139 | ili8960_store_brightness); | |
140 | ||
141 | static struct lcd_ops ili8960_lcd_ops = { | |
142 | .set_power = ili8960_set_power, | |
143 | .get_power = ili8960_get_power, | |
144 | .set_contrast = ili8960_set_contrast, | |
145 | .set_mode = ili8960_set_mode, | |
146 | }; | |
147 | ||
148 | static int __devinit ili8960_probe(struct spi_device *spi) | |
149 | { | |
150 | int ret; | |
151 | struct ili8960 *ili8960; | |
152 | ||
153 | ili8960 = kmalloc(sizeof(*ili8960), GFP_KERNEL); | |
154 | if (!ili8960) | |
155 | return -ENOMEM; | |
156 | ||
157 | spi->bits_per_word = 8; | |
158 | spi->mode = SPI_MODE_3; | |
159 | ||
160 | ret = spi_setup(spi); | |
161 | if (ret) { | |
162 | dev_err(&spi->dev, "Failed to setup spi\n"); | |
163 | goto err_free_ili8960; | |
164 | } | |
165 | ||
166 | ili8960->spi = spi; | |
167 | ||
168 | ili8960->lcd = lcd_device_register("ili8960-lcd", &spi->dev, ili8960, | |
169 | &ili8960_lcd_ops); | |
170 | ||
171 | if (IS_ERR(ili8960->lcd)) { | |
172 | ret = PTR_ERR(ili8960->lcd); | |
173 | dev_err(&spi->dev, "Failed to register lcd device: %d\n", ret); | |
174 | goto err_free_ili8960; | |
175 | } | |
176 | ||
177 | ili8960->lcd->props.max_contrast = 255; | |
178 | ||
179 | ret = device_create_file(&ili8960->lcd->dev, &dev_attr_brightness); | |
180 | if (ret) | |
181 | goto err_unregister_lcd; | |
182 | ||
183 | ili8960_programm_power(ili8960->spi, true); | |
184 | ili8960->enabled = true; | |
185 | ||
186 | spi_set_drvdata(spi, ili8960); | |
187 | ||
188 | ili8960_write_reg(spi, 0x13, 0x01); | |
189 | ||
190 | return 0; | |
191 | err_unregister_lcd: | |
192 | lcd_device_unregister(ili8960->lcd); | |
193 | err_free_ili8960: | |
194 | kfree(ili8960); | |
195 | return ret; | |
196 | } | |
197 | ||
198 | static int __devexit ili8960_remove(struct spi_device *spi) | |
199 | { | |
200 | struct ili8960 *ili8960 = spi_get_drvdata(spi); | |
201 | ||
202 | device_remove_file(&ili8960->lcd->dev, &dev_attr_brightness); | |
203 | lcd_device_unregister(ili8960->lcd); | |
204 | ||
205 | spi_set_drvdata(spi, NULL); | |
206 | kfree(ili8960); | |
207 | return 0; | |
208 | } | |
209 | ||
210 | #ifdef CONFIG_PM | |
211 | ||
212 | static int ili8960_suspend(struct spi_device *spi, pm_message_t state) | |
213 | { | |
214 | struct ili8960 *ili8960 = spi_get_drvdata(spi); | |
215 | ||
216 | if (ili8960->enabled) | |
217 | ili8960_programm_power(ili8960->spi, false); | |
218 | ||
219 | return 0; | |
220 | } | |
221 | ||
222 | static int ili8960_resume(struct spi_device *spi) | |
223 | { | |
224 | struct ili8960 *ili8960 = spi_get_drvdata(spi); | |
225 | ||
226 | if (ili8960->enabled) | |
227 | ili8960_programm_power(ili8960->spi, true); | |
228 | ||
229 | return 0; | |
230 | } | |
231 | ||
232 | #else | |
233 | #define ili8960_suspend NULL | |
234 | #define ili8960_resume NULL | |
235 | #endif | |
236 | ||
237 | static struct spi_driver ili8960_driver = { | |
238 | .driver = { | |
239 | .name = "ili8960", | |
240 | .owner = THIS_MODULE, | |
241 | }, | |
242 | .probe = ili8960_probe, | |
243 | .remove = __devexit_p(ili8960_remove), | |
244 | .suspend = ili8960_suspend, | |
245 | .resume = ili8960_resume, | |
246 | }; | |
247 | ||
248 | static int __init ili8960_init(void) | |
249 | { | |
250 | return spi_register_driver(&ili8960_driver); | |
251 | } | |
252 | module_init(ili8960_init); | |
253 | ||
254 | static void __exit ili8960_exit(void) | |
255 | { | |
256 | spi_unregister_driver(&ili8960_driver); | |
257 | } | |
258 | module_exit(ili8960_exit) | |
259 | ||
260 | MODULE_AUTHOR("Lars-Peter Clausen"); | |
261 | MODULE_LICENSE("GPL"); | |
262 | MODULE_DESCRIPTION("LCD driver for Ilitek ili8960"); | |
263 | MODULE_ALIAS("spi:ili8960"); |
Branches:
ben-wpan
ben-wpan-stefan
5396a9238205f20f811ea57898980d3ca82df0b6
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9