2008-07-23 22:31:37 -06:00
|
|
|
/* 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 cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2008-07-23 22:31:37 -06:00
|
|
|
|
|
|
|
#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;
|
2012-12-17 17:00:19 -07:00
|
|
|
data[1] = value >> 8;
|
2008-07-23 22:31:37 -06:00
|
|
|
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,
|
2012-12-17 17:00:54 -07:00
|
|
|
const struct ili9320_reg *values,
|
2008-07-23 22:31:37 -06:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2012-11-19 11:21:46 -07:00
|
|
|
static void ili9320_setup_spi(struct ili9320 *ili,
|
2008-07-23 22:31:37 -06:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-11-19 11:21:46 -07:00
|
|
|
int ili9320_probe_spi(struct spi_device *spi,
|
2008-07-23 22:31:37 -06:00
|
|
|
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 */
|
|
|
|
|
2012-05-29 16:07:22 -06:00
|
|
|
ili = devm_kzalloc(&spi->dev, sizeof(struct ili9320), GFP_KERNEL);
|
2008-07-23 22:31:37 -06:00
|
|
|
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");
|
2012-05-29 16:07:22 -06:00
|
|
|
return PTR_ERR(lcd);
|
2008-07-23 22:31:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(ili9320_probe_spi);
|
|
|
|
|
2012-05-15 15:02:58 -06:00
|
|
|
int ili9320_remove(struct ili9320 *ili)
|
2008-07-23 22:31:37 -06:00
|
|
|
{
|
|
|
|
ili9320_power(ili, FB_BLANK_POWERDOWN);
|
|
|
|
|
|
|
|
lcd_device_unregister(ili->lcd);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-12-17 17:00:19 -07:00
|
|
|
if (lcd->platdata->suspend == ILI9320_SUSPEND_DEEP)
|
2008-07-23 22:31:37 -06:00
|
|
|
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");
|