1 From 8741ead92bc93e66740237e51b88b8690ebcbba3 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 6/7] Add ili8960 lcd driver
6 Includes the following changes from the jz-3.5 branch:
7 - Use module_spi_driver
11 Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
13 drivers/video/backlight/Kconfig | 7 +
14 drivers/video/backlight/Makefile | 1 +
15 drivers/video/backlight/ili8960.c | 262 +++++++++++++++++++++++++++++++++++++
16 3 files changed, 270 insertions(+)
17 create mode 100644 drivers/video/backlight/ili8960.c
19 diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
20 index 8d03924..14adcc6 100644
21 --- a/drivers/video/backlight/Kconfig
22 +++ b/drivers/video/backlight/Kconfig
23 @@ -59,6 +59,13 @@ config LCD_LTV350QV
25 The LTV350QV panel is present on all ATSTK1000 boards.
28 + tristate "Ilitek ili8960 LCD driver"
29 + depends on LCD_CLASS_DEVICE && SPI
32 + Driver for the Ilitek ili8960 LCD controller chip.
35 tristate "ILI Technology ILI9221/ILI9222 support"
37 diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
38 index fcd50b73..1f89974 100644
39 --- a/drivers/video/backlight/Makefile
40 +++ b/drivers/video/backlight/Makefile
41 @@ -5,6 +5,7 @@ obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o
42 obj-$(CONFIG_LCD_CORGI) += corgi_lcd.o
43 obj-$(CONFIG_LCD_HP700) += jornada720_lcd.o
44 obj-$(CONFIG_LCD_HX8357) += hx8357.o
45 +obj-$(CONFIG_LCD_ILI8960) += ili8960.o
46 obj-$(CONFIG_LCD_ILI922X) += ili922x.o
47 obj-$(CONFIG_LCD_ILI9320) += ili9320.o
48 obj-$(CONFIG_LCD_L4F00242T03) += l4f00242t03.o
49 diff --git a/drivers/video/backlight/ili8960.c b/drivers/video/backlight/ili8960.c
51 index 0000000..61eb815
53 +++ b/drivers/video/backlight/ili8960.c
56 + * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
57 + * Driver for Ilitek ili8960 LCD
59 + * This program is free software; you can redistribute it and/or modify it
60 + * under the terms of the GNU General Public License as published by the
61 + * Free Software Foundation; either version 2 of the License, or (at your
62 + * option) any later version.
64 + * You should have received a copy of the GNU General Public License along
65 + * with this program; if not, write to the Free Software Foundation, Inc.,
66 + * 675 Mass Ave, Cambridge, MA 02139, USA.
70 +#include <linux/module.h>
71 +#include <linux/spi/spi.h>
72 +#include <linux/lcd.h>
73 +#include <linux/delay.h>
76 + struct spi_device *spi;
77 + struct lcd_device *lcd;
79 + unsigned int brightness;
82 +#define ILI8960_REG_BRIGHTNESS 0x03
83 +#define ILI8960_REG_POWER 0x05
84 +#define ILI8960_REG_CONTRAST 0x0d
86 +static int ili8960_write_reg(struct spi_device *spi, uint8_t reg,
90 + buf[0] = ((reg & 0x40) << 1) | (reg & 0x3f);
93 + return spi_write(spi, buf, sizeof(buf));
96 +static int ili8960_programm_power(struct spi_device *spi, bool enabled)
103 + ret = ili8960_write_reg(spi, ILI8960_REG_POWER, enabled ? 0xc7 : 0xc6);
111 +static int ili8960_set_power(struct lcd_device *lcd, int power)
113 + struct ili8960 *ili8960 = lcd_get_data(lcd);
116 + case FB_BLANK_UNBLANK:
117 + ili8960->enabled = true;
123 + return ili8960_programm_power(ili8960->spi, ili8960->enabled);
126 +static int ili8960_early_set_power(struct lcd_device *lcd, int power)
128 + struct ili8960 *ili8960 = lcd_get_data(lcd);
131 + case FB_BLANK_UNBLANK:
134 + ili8960->enabled = false;
138 + return ili8960_programm_power(ili8960->spi, ili8960->enabled);
141 +static int ili8960_get_power(struct lcd_device *lcd)
143 + struct ili8960 *ili8960 = lcd_get_data(lcd);
144 + return ili8960->enabled ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
147 +static int ili8960_set_contrast(struct lcd_device *lcd, int contrast)
149 + struct ili8960 *ili8960 = lcd_get_data(lcd);
151 + return ili8960_write_reg(ili8960->spi, ILI8960_REG_CONTRAST, contrast);
154 +static int ili8960_set_mode(struct lcd_device *lcd, struct fb_videomode *mode)
156 + if (mode->xres != 320 && mode->yres != 240)
162 +static int ili8960_set_brightness(struct ili8960 *ili8960, int brightness)
166 + ret = ili8960_write_reg(ili8960->spi, ILI8960_REG_BRIGHTNESS, brightness);
169 + ili8960->brightness = brightness;
174 +static ssize_t ili8960_show_brightness(struct device *dev,
175 + struct device_attribute *attr, char *buf)
177 + struct lcd_device *ld = to_lcd_device(dev);
178 + struct ili8960 *ili8960 = lcd_get_data(ld);
180 + return sprintf(buf, "%u\n", ili8960->brightness);
183 +static ssize_t ili8960_store_brightness(struct device *dev,
184 + struct device_attribute *attr, const char *buf, size_t count)
186 + struct lcd_device *ld = to_lcd_device(dev);
187 + struct ili8960 *ili8960 = lcd_get_data(ld);
188 + unsigned long brightness;
191 + ret = kstrtoul(buf, 0, &brightness);
195 + if (brightness > 255)
198 + ili8960_set_brightness(ili8960, brightness);
204 +static DEVICE_ATTR(brightness, 0644, ili8960_show_brightness,
205 + ili8960_store_brightness);
207 +static struct lcd_ops ili8960_lcd_ops = {
208 + .set_power = ili8960_set_power,
209 + .early_set_power = ili8960_early_set_power,
210 + .get_power = ili8960_get_power,
211 + .set_contrast = ili8960_set_contrast,
212 + .set_mode = ili8960_set_mode,
215 +static int ili8960_probe(struct spi_device *spi)
218 + struct ili8960 *ili8960;
220 + ili8960 = devm_kzalloc(&spi->dev, sizeof(*ili8960), GFP_KERNEL);
224 + spi->bits_per_word = 8;
225 + spi->mode = SPI_MODE_3;
227 + ret = spi_setup(spi);
229 + dev_err(&spi->dev, "Failed to setup spi\n");
233 + ili8960->spi = spi;
235 + ili8960->lcd = lcd_device_register("ili8960-lcd", &spi->dev, ili8960,
238 + if (IS_ERR(ili8960->lcd)) {
239 + ret = PTR_ERR(ili8960->lcd);
240 + dev_err(&spi->dev, "Failed to register lcd device: %d\n", ret);
244 + ili8960->lcd->props.max_contrast = 255;
246 + ret = device_create_file(&ili8960->lcd->dev, &dev_attr_brightness);
248 + goto err_unregister_lcd;
250 + ili8960_programm_power(ili8960->spi, true);
251 + ili8960->enabled = true;
253 + spi_set_drvdata(spi, ili8960);
255 + ili8960_write_reg(spi, 0x13, 0x01);
259 + lcd_device_unregister(ili8960->lcd);
263 +static int ili8960_remove(struct spi_device *spi)
265 + struct ili8960 *ili8960 = spi_get_drvdata(spi);
267 + device_remove_file(&ili8960->lcd->dev, &dev_attr_brightness);
268 + lcd_device_unregister(ili8960->lcd);
270 + spi_set_drvdata(spi, NULL);
276 +static int ili8960_suspend(struct spi_device *spi, pm_message_t state)
278 + struct ili8960 *ili8960 = spi_get_drvdata(spi);
280 + if (ili8960->enabled)
281 + ili8960_programm_power(ili8960->spi, false);
286 +static int ili8960_resume(struct spi_device *spi)
288 + struct ili8960 *ili8960 = spi_get_drvdata(spi);
290 + if (ili8960->enabled)
291 + ili8960_programm_power(ili8960->spi, true);
297 +#define ili8960_suspend NULL
298 +#define ili8960_resume NULL
301 +static struct spi_driver ili8960_driver = {
304 + .owner = THIS_MODULE,
306 + .probe = ili8960_probe,
307 + .remove = ili8960_remove,
308 + .suspend = ili8960_suspend,
309 + .resume = ili8960_resume,
311 +module_spi_driver(ili8960_driver);
313 +MODULE_AUTHOR("Lars-Peter Clausen");
314 +MODULE_LICENSE("GPL");
315 +MODULE_DESCRIPTION("LCD driver for Ilitek ili8960");
316 +MODULE_ALIAS("spi:ili8960");