Date:2010-08-01 21:19:40 (9 years 9 months ago)
Author:Lars C.
Commit:4fcfa80f141b5e32ac93fdb7ba26fcc22c771ddc
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
5959
6060      The LTV350QV panel is present on all ATSTK1000 boards.
6161
62config 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
6269config LCD_ILI922X
6370    tristate "ILI Technology ILI9221/ILI9222 support"
6471    depends on SPI
drivers/video/backlight/Makefile
55obj-$(CONFIG_LCD_CORGI) += corgi_lcd.o
66obj-$(CONFIG_LCD_HP700) += jornada720_lcd.o
77obj-$(CONFIG_LCD_HX8357) += hx8357.o
8obj-$(CONFIG_LCD_ILI8960) += ili8960.o
89obj-$(CONFIG_LCD_ILI922X) += ili922x.o
910obj-$(CONFIG_LCD_ILI9320) += ili9320.o
1011obj-$(CONFIG_LCD_L4F00242T03) += l4f00242t03.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/delay.h>
20
21struct ili8960 {
22    struct spi_device *spi;
23    struct lcd_device *lcd;
24    bool enabled;
25    unsigned int brightness;
26};
27
28#define ILI8960_REG_BRIGHTNESS 0x03
29#define ILI8960_REG_POWER 0x05
30#define ILI8960_REG_CONTRAST 0x0d
31
32static int ili8960_write_reg(struct spi_device *spi, uint8_t reg,
33                uint8_t data)
34{
35    uint8_t buf[2];
36    buf[0] = ((reg & 0x40) << 1) | (reg & 0x3f);
37    buf[1] = data;
38
39    return spi_write(spi, buf, sizeof(buf));
40}
41
42static int ili8960_programm_power(struct spi_device *spi, bool enabled)
43{
44    int ret;
45
46    if (enabled)
47        mdelay(20);
48
49    ret = ili8960_write_reg(spi, ILI8960_REG_POWER, enabled ? 0xc7 : 0xc6);
50
51    if (!enabled)
52        mdelay(20);
53
54    return ret;
55}
56
57static int ili8960_set_power(struct lcd_device *lcd, int power)
58{
59    struct ili8960 *ili8960 = lcd_get_data(lcd);
60
61    switch (power) {
62    case FB_BLANK_UNBLANK:
63        ili8960->enabled = true;
64        break;
65    default:
66        return 0;
67    }
68
69    return ili8960_programm_power(ili8960->spi, ili8960->enabled);
70}
71
72static int ili8960_early_set_power(struct lcd_device *lcd, int power)
73{
74    struct ili8960 *ili8960 = lcd_get_data(lcd);
75
76    switch (power) {
77    case FB_BLANK_UNBLANK:
78        return 0;
79    default:
80        ili8960->enabled = false;
81        break;
82    }
83
84    return ili8960_programm_power(ili8960->spi, ili8960->enabled);
85}
86
87static int ili8960_get_power(struct lcd_device *lcd)
88{
89    struct ili8960 *ili8960 = lcd_get_data(lcd);
90    return ili8960->enabled ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
91}
92
93static int ili8960_set_contrast(struct lcd_device *lcd, int contrast)
94{
95    struct ili8960 *ili8960 = lcd_get_data(lcd);
96
97    return ili8960_write_reg(ili8960->spi, ILI8960_REG_CONTRAST, contrast);
98}
99
100static int ili8960_set_mode(struct lcd_device *lcd, struct fb_videomode *mode)
101{
102    if (mode->xres != 320 && mode->yres != 240)
103        return -EINVAL;
104
105    return 0;
106}
107
108static int ili8960_set_brightness(struct ili8960 *ili8960, int brightness)
109{
110    int ret;
111
112    ret = ili8960_write_reg(ili8960->spi, ILI8960_REG_BRIGHTNESS, brightness);
113
114    if (ret == 0)
115        ili8960->brightness = brightness;
116
117    return ret;
118}
119
120static ssize_t ili8960_show_brightness(struct device *dev,
121        struct device_attribute *attr, char *buf)
122{
123    struct lcd_device *ld = to_lcd_device(dev);
124    struct ili8960 *ili8960 = lcd_get_data(ld);
125
126    return sprintf(buf, "%u\n", ili8960->brightness);
127}
128
129static ssize_t ili8960_store_brightness(struct device *dev,
130        struct device_attribute *attr, const char *buf, size_t count)
131{
132    struct lcd_device *ld = to_lcd_device(dev);
133    struct ili8960 *ili8960 = lcd_get_data(ld);
134    unsigned long brightness;
135    int ret;
136
137    ret = kstrtoul(buf, 0, &brightness);
138    if (ret)
139        return ret;
140
141    if (brightness > 255)
142        return -EINVAL;
143
144    ili8960_set_brightness(ili8960, brightness);
145
146    return count;
147}
148
149
150static DEVICE_ATTR(brightness, 0644, ili8960_show_brightness,
151    ili8960_store_brightness);
152
153static struct lcd_ops ili8960_lcd_ops = {
154    .set_power = ili8960_set_power,
155    .early_set_power = ili8960_early_set_power,
156    .get_power = ili8960_get_power,
157    .set_contrast = ili8960_set_contrast,
158    .set_mode = ili8960_set_mode,
159};
160
161static int ili8960_probe(struct spi_device *spi)
162{
163    int ret;
164    struct ili8960 *ili8960;
165
166    ili8960 = devm_kzalloc(&spi->dev, sizeof(*ili8960), GFP_KERNEL);
167    if (!ili8960)
168        return -ENOMEM;
169
170    spi->bits_per_word = 8;
171    spi->mode = SPI_MODE_3;
172
173    ret = spi_setup(spi);
174    if (ret) {
175        dev_err(&spi->dev, "Failed to setup spi\n");
176        return ret;
177    }
178
179    ili8960->spi = spi;
180
181    ili8960->lcd = lcd_device_register("ili8960-lcd", &spi->dev, ili8960,
182                        &ili8960_lcd_ops);
183
184    if (IS_ERR(ili8960->lcd)) {
185        ret = PTR_ERR(ili8960->lcd);
186        dev_err(&spi->dev, "Failed to register lcd device: %d\n", ret);
187        return ret;
188    }
189
190    ili8960->lcd->props.max_contrast = 255;
191
192    ret = device_create_file(&ili8960->lcd->dev, &dev_attr_brightness);
193    if (ret)
194        goto err_unregister_lcd;
195
196    ili8960_programm_power(ili8960->spi, true);
197    ili8960->enabled = true;
198
199    spi_set_drvdata(spi, ili8960);
200
201    ili8960_write_reg(spi, 0x13, 0x01);
202
203    return 0;
204err_unregister_lcd:
205    lcd_device_unregister(ili8960->lcd);
206    return ret;
207}
208
209static int ili8960_remove(struct spi_device *spi)
210{
211    struct ili8960 *ili8960 = spi_get_drvdata(spi);
212
213    device_remove_file(&ili8960->lcd->dev, &dev_attr_brightness);
214    lcd_device_unregister(ili8960->lcd);
215
216    spi_set_drvdata(spi, NULL);
217    return 0;
218}
219
220#ifdef CONFIG_PM
221
222static int ili8960_suspend(struct spi_device *spi, pm_message_t state)
223{
224    struct ili8960 *ili8960 = spi_get_drvdata(spi);
225
226    if (ili8960->enabled)
227        ili8960_programm_power(ili8960->spi, false);
228
229    return 0;
230}
231
232static int ili8960_resume(struct spi_device *spi)
233{
234    struct ili8960 *ili8960 = spi_get_drvdata(spi);
235
236    if (ili8960->enabled)
237        ili8960_programm_power(ili8960->spi, true);
238
239    return 0;
240}
241
242#else
243#define ili8960_suspend NULL
244#define ili8960_resume NULL
245#endif
246
247static struct spi_driver ili8960_driver = {
248    .driver = {
249        .name = "ili8960",
250        .owner = THIS_MODULE,
251    },
252    .probe = ili8960_probe,
253    .remove = ili8960_remove,
254    .suspend = ili8960_suspend,
255    .resume = ili8960_resume,
256};
257module_spi_driver(ili8960_driver);
258
259MODULE_AUTHOR("Lars-Peter Clausen");
260MODULE_LICENSE("GPL");
261MODULE_DESCRIPTION("LCD driver for Ilitek ili8960");
262MODULE_ALIAS("spi:ili8960");

Archive Download the corresponding diff file



interactive