Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 105555
b: refs/heads/master
c: cccb6d3
h: refs/heads/master
i:
  105553: f09d355
  105551: f8b98a6
v: v3
  • Loading branch information
Ben Dooks authored and Linus Torvalds committed Jul 24, 2008
1 parent ebb7a67 commit 2469aa3
Show file tree
Hide file tree
Showing 7 changed files with 916 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d05254190dd1a4751284f4a51efb70fcc16c45a4
refs/heads/master: cccb6d3c149603b9c15d3c460dff317455df1766
17 changes: 17 additions & 0 deletions trunk/drivers/video/backlight/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ config LCD_LTV350QV

The LTV350QV panel is present on all ATSTK1000 boards.

config LCD_ILI9320
tristate
depends on LCD_CLASS_DEVICE && BACKLIGHT_LCD_SUPPORT
default n
help
If you have a panel based on the ILI9320 controller chip
then say y to include a power driver for it.

config LCD_VGG2432A4
tristate "VGG2432A4 LCM device support"
depends on BACKLIGHT_LCD_SUPPORT && LCD_CLASS_DEVICE && SPI_MASTER
select LCD_ILI9320
default n
help
If you have a VGG2432A4 panel based on the ILI9320 controller chip
then say y to include a power driver for it.

#
# Backlight
#
Expand Down
4 changes: 3 additions & 1 deletion trunk/drivers/video/backlight/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Backlight & LCD drivers

obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o
obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o
obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o
obj-$(CONFIG_LCD_ILI9320) += ili9320.o
obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o

obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o
Expand Down
330 changes: 330 additions & 0 deletions trunk/drivers/video/backlight/ili9320.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,330 @@
/* drivers/video/backlight/ili9320.c
*
* ILI9320 LCD controller driver core.
*
* Copyright 2007 Simtec Electronics
* http://armlinux.simtec.co.uk/
* Ben Dooks <ben@simtec.co.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

#include <linux/delay.h>
#include <linux/err.h>
#include <linux/fb.h>
#include <linux/init.h>
#include <linux/lcd.h>
#include <linux/module.h>

#include <linux/spi/spi.h>

#include <video/ili9320.h>

#include "ili9320.h"


static inline int ili9320_write_spi(struct ili9320 *ili,
unsigned int reg,
unsigned int value)
{
struct ili9320_spi *spi = &ili->access.spi;
unsigned char *addr = spi->buffer_addr;
unsigned char *data = spi->buffer_data;

/* spi message consits of:
* first byte: ID and operation
*/

addr[0] = spi->id | ILI9320_SPI_INDEX | ILI9320_SPI_WRITE;
addr[1] = reg >> 8;
addr[2] = reg;

/* second message is the data to transfer */

data[0] = spi->id | ILI9320_SPI_DATA | ILI9320_SPI_WRITE;
data[1] = value >> 8;
data[2] = value;

return spi_sync(spi->dev, &spi->message);
}

int ili9320_write(struct ili9320 *ili, unsigned int reg, unsigned int value)
{
dev_dbg(ili->dev, "write: reg=%02x, val=%04x\n", reg, value);
return ili->write(ili, reg, value);
}

EXPORT_SYMBOL_GPL(ili9320_write);

int ili9320_write_regs(struct ili9320 *ili,
struct ili9320_reg *values,
int nr_values)
{
int index;
int ret;

for (index = 0; index < nr_values; index++, values++) {
ret = ili9320_write(ili, values->address, values->value);
if (ret != 0)
return ret;
}

return 0;
}

EXPORT_SYMBOL_GPL(ili9320_write_regs);

static void ili9320_reset(struct ili9320 *lcd)
{
struct ili9320_platdata *cfg = lcd->platdata;

cfg->reset(1);
mdelay(50);

cfg->reset(0);
mdelay(50);

cfg->reset(1);
mdelay(100);
}

static inline int ili9320_init_chip(struct ili9320 *lcd)
{
int ret;

ili9320_reset(lcd);

ret = lcd->client->init(lcd, lcd->platdata);
if (ret != 0) {
dev_err(lcd->dev, "failed to initialise display\n");
return ret;
}

lcd->initialised = 1;
return 0;
}

static inline int ili9320_power_on(struct ili9320 *lcd)
{
if (!lcd->initialised)
ili9320_init_chip(lcd);

lcd->display1 |= (ILI9320_DISPLAY1_D(3) | ILI9320_DISPLAY1_BASEE);
ili9320_write(lcd, ILI9320_DISPLAY1, lcd->display1);

return 0;
}

static inline int ili9320_power_off(struct ili9320 *lcd)
{
lcd->display1 &= ~(ILI9320_DISPLAY1_D(3) | ILI9320_DISPLAY1_BASEE);
ili9320_write(lcd, ILI9320_DISPLAY1, lcd->display1);

return 0;
}

#define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)

static int ili9320_power(struct ili9320 *lcd, int power)
{
int ret = 0;

dev_dbg(lcd->dev, "power %d => %d\n", lcd->power, power);

if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
ret = ili9320_power_on(lcd);
else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
ret = ili9320_power_off(lcd);

if (ret == 0)
lcd->power = power;
else
dev_warn(lcd->dev, "failed to set power mode %d\n", power);

return ret;
}

static inline struct ili9320 *to_our_lcd(struct lcd_device *lcd)
{
return lcd_get_data(lcd);
}

static int ili9320_set_power(struct lcd_device *ld, int power)
{
struct ili9320 *lcd = to_our_lcd(ld);

return ili9320_power(lcd, power);
}

static int ili9320_get_power(struct lcd_device *ld)
{
struct ili9320 *lcd = to_our_lcd(ld);

return lcd->power;
}

static struct lcd_ops ili9320_ops = {
.get_power = ili9320_get_power,
.set_power = ili9320_set_power,
};

static void __devinit ili9320_setup_spi(struct ili9320 *ili,
struct spi_device *dev)
{
struct ili9320_spi *spi = &ili->access.spi;

ili->write = ili9320_write_spi;
spi->dev = dev;

/* fill the two messages we are going to use to send the data
* with, the first the address followed by the data. The datasheet
* says they should be done as two distinct cycles of the SPI CS line.
*/

spi->xfer[0].tx_buf = spi->buffer_addr;
spi->xfer[1].tx_buf = spi->buffer_data;
spi->xfer[0].len = 3;
spi->xfer[1].len = 3;
spi->xfer[0].bits_per_word = 8;
spi->xfer[1].bits_per_word = 8;
spi->xfer[0].cs_change = 1;

spi_message_init(&spi->message);
spi_message_add_tail(&spi->xfer[0], &spi->message);
spi_message_add_tail(&spi->xfer[1], &spi->message);
}

int __devinit ili9320_probe_spi(struct spi_device *spi,
struct ili9320_client *client)
{
struct ili9320_platdata *cfg = spi->dev.platform_data;
struct device *dev = &spi->dev;
struct ili9320 *ili;
struct lcd_device *lcd;
int ret = 0;

/* verify we where given some information */

if (cfg == NULL) {
dev_err(dev, "no platform data supplied\n");
return -EINVAL;
}

if (cfg->hsize <= 0 || cfg->vsize <= 0 || cfg->reset == NULL) {
dev_err(dev, "invalid platform data supplied\n");
return -EINVAL;
}

/* allocate and initialse our state */

ili = kzalloc(sizeof(struct ili9320), GFP_KERNEL);
if (ili == NULL) {
dev_err(dev, "no memory for device\n");
return -ENOMEM;
}

ili->access.spi.id = ILI9320_SPI_IDCODE | ILI9320_SPI_ID(1);

ili->dev = dev;
ili->client = client;
ili->power = FB_BLANK_POWERDOWN;
ili->platdata = cfg;

dev_set_drvdata(&spi->dev, ili);

ili9320_setup_spi(ili, spi);

lcd = lcd_device_register("ili9320", dev, ili, &ili9320_ops);
if (IS_ERR(lcd)) {
dev_err(dev, "failed to register lcd device\n");
ret = PTR_ERR(lcd);
goto err_free;
}

ili->lcd = lcd;

dev_info(dev, "initialising %s\n", client->name);

ret = ili9320_power(ili, FB_BLANK_UNBLANK);
if (ret != 0) {
dev_err(dev, "failed to set lcd power state\n");
goto err_unregister;
}

return 0;

err_unregister:
lcd_device_unregister(lcd);

err_free:
kfree(ili);

return ret;
}

EXPORT_SYMBOL_GPL(ili9320_probe_spi);

int __devexit ili9320_remove(struct ili9320 *ili)
{
ili9320_power(ili, FB_BLANK_POWERDOWN);

lcd_device_unregister(ili->lcd);
kfree(ili);

return 0;
}

EXPORT_SYMBOL_GPL(ili9320_remove);

#ifdef CONFIG_PM
int ili9320_suspend(struct ili9320 *lcd, pm_message_t state)
{
int ret;

dev_dbg(lcd->dev, "%s: event %d\n", __func__, state.event);

if (state.event == PM_EVENT_SUSPEND) {
ret = ili9320_power(lcd, FB_BLANK_POWERDOWN);

if (lcd->platdata->suspend == ILI9320_SUSPEND_DEEP) {
ili9320_write(lcd, ILI9320_POWER1, lcd->power1 |
ILI9320_POWER1_SLP |
ILI9320_POWER1_DSTB);
lcd->initialised = 0;
}

return ret;
}

return 0;
}

EXPORT_SYMBOL_GPL(ili9320_suspend);

int ili9320_resume(struct ili9320 *lcd)
{
dev_info(lcd->dev, "resuming from power state %d\n", lcd->power);

if (lcd->platdata->suspend == ILI9320_SUSPEND_DEEP) {
ili9320_write(lcd, ILI9320_POWER1, 0x00);
}

return ili9320_power(lcd, FB_BLANK_UNBLANK);
}

EXPORT_SYMBOL_GPL(ili9320_resume);
#endif

/* Power down all displays on reboot, poweroff or halt */
void ili9320_shutdown(struct ili9320 *lcd)
{
ili9320_power(lcd, FB_BLANK_POWERDOWN);
}

EXPORT_SYMBOL_GPL(ili9320_shutdown);

MODULE_AUTHOR("Ben Dooks <ben-linux@fluff.org>");
MODULE_DESCRIPTION("ILI9320 LCD Driver");
MODULE_LICENSE("GPL v2");
Loading

0 comments on commit 2469aa3

Please sign in to comment.