Date: | 2010-08-01 21:19:40 (13 years 7 months ago) |
---|---|
Author: | Lars C. |
Commit: | 4cd81eef1d0039e57778850c25f0ff68f2761d94 |
Message: | Add ili8960 lcd driver Includes the following changes from the jz-3.5 branch: - Use module_spi_driver - Use devm_kzalloc - Use kstrtoul Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> |
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 "ILI Technology ILI9320 controller support" |
64 | 71 | depends on SPI |
drivers/video/backlight/Makefile | ||
---|---|---|
5 | 5 | obj-$(CONFIG_LCD_CORGI) += corgi_lcd.o |
6 | 6 | obj-$(CONFIG_LCD_HP700) += jornada720_lcd.o |
7 | 7 | obj-$(CONFIG_LCD_HX8357) += hx8357.o |
8 | obj-$(CONFIG_LCD_LCD_ILI8960) += ili8960.o | |
8 | 9 | obj-$(CONFIG_LCD_ILI9320) += ili9320.o |
9 | 10 | obj-$(CONFIG_LCD_L4F00242T03) += l4f00242t03.o |
10 | 11 | obj-$(CONFIG_LCD_LD9040) += ld9040.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 = kstrtoul(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 = devm_kzalloc(&spi->dev, 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 | return ret; | |
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 | return ret; | |
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 | return ret; | |
194 | } | |
195 | ||
196 | static int __devexit ili8960_remove(struct spi_device *spi) | |
197 | { | |
198 | struct ili8960 *ili8960 = spi_get_drvdata(spi); | |
199 | ||
200 | device_remove_file(&ili8960->lcd->dev, &dev_attr_brightness); | |
201 | lcd_device_unregister(ili8960->lcd); | |
202 | ||
203 | spi_set_drvdata(spi, NULL); | |
204 | return 0; | |
205 | } | |
206 | ||
207 | #ifdef CONFIG_PM | |
208 | ||
209 | static int ili8960_suspend(struct spi_device *spi, pm_message_t state) | |
210 | { | |
211 | struct ili8960 *ili8960 = spi_get_drvdata(spi); | |
212 | ||
213 | if (ili8960->enabled) | |
214 | ili8960_programm_power(ili8960->spi, false); | |
215 | ||
216 | return 0; | |
217 | } | |
218 | ||
219 | static int ili8960_resume(struct spi_device *spi) | |
220 | { | |
221 | struct ili8960 *ili8960 = spi_get_drvdata(spi); | |
222 | ||
223 | if (ili8960->enabled) | |
224 | ili8960_programm_power(ili8960->spi, true); | |
225 | ||
226 | return 0; | |
227 | } | |
228 | ||
229 | #else | |
230 | #define ili8960_suspend NULL | |
231 | #define ili8960_resume NULL | |
232 | #endif | |
233 | ||
234 | static struct spi_driver ili8960_driver = { | |
235 | .driver = { | |
236 | .name = "ili8960", | |
237 | .owner = THIS_MODULE, | |
238 | }, | |
239 | .probe = ili8960_probe, | |
240 | .remove = __devexit_p(ili8960_remove), | |
241 | .suspend = ili8960_suspend, | |
242 | .resume = ili8960_resume, | |
243 | }; | |
244 | module_spi_driver(ili8960_driver); | |
245 | ||
246 | MODULE_AUTHOR("Lars-Peter Clausen"); | |
247 | MODULE_LICENSE("GPL"); | |
248 | MODULE_DESCRIPTION("LCD driver for Ilitek ili8960"); | |
249 | 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