2007-09-03 05:15:49 +07:00
|
|
|
/*
|
|
|
|
* Power control for Samsung LTV350QV Quarter VGA LCD Panel
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, 2007 Atmel Corporation
|
|
|
|
*
|
|
|
|
* 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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2007-09-03 05:15:49 +07:00
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
|
|
|
|
#include "ltv350qv.h"
|
|
|
|
|
|
|
|
#define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
|
|
|
|
|
|
|
|
struct ltv350qv {
|
|
|
|
struct spi_device *spi;
|
|
|
|
u8 *buffer;
|
|
|
|
int power;
|
|
|
|
struct lcd_device *ld;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The power-on and power-off sequences are taken from the
|
|
|
|
* LTV350QV-F04 data sheet from Samsung. The register definitions are
|
|
|
|
* taken from the S6F2002 command list also from Samsung. Both
|
|
|
|
* documents are distributed with the AVR32 Linux BSP CD from Atmel.
|
|
|
|
*
|
|
|
|
* There's still some voodoo going on here, but it's a lot better than
|
|
|
|
* in the first incarnation of the driver where all we had was the raw
|
|
|
|
* numbers from the initialization sequence.
|
|
|
|
*/
|
|
|
|
static int ltv350qv_write_reg(struct ltv350qv *lcd, u8 reg, u16 val)
|
|
|
|
{
|
|
|
|
struct spi_message msg;
|
|
|
|
struct spi_transfer index_xfer = {
|
|
|
|
.len = 3,
|
|
|
|
.cs_change = 1,
|
|
|
|
};
|
|
|
|
struct spi_transfer value_xfer = {
|
|
|
|
.len = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
spi_message_init(&msg);
|
|
|
|
|
|
|
|
/* register index */
|
|
|
|
lcd->buffer[0] = LTV_OPC_INDEX;
|
|
|
|
lcd->buffer[1] = 0x00;
|
|
|
|
lcd->buffer[2] = reg & 0x7f;
|
|
|
|
index_xfer.tx_buf = lcd->buffer;
|
|
|
|
spi_message_add_tail(&index_xfer, &msg);
|
|
|
|
|
|
|
|
/* register value */
|
|
|
|
lcd->buffer[4] = LTV_OPC_DATA;
|
|
|
|
lcd->buffer[5] = val >> 8;
|
|
|
|
lcd->buffer[6] = val;
|
|
|
|
value_xfer.tx_buf = lcd->buffer + 4;
|
|
|
|
spi_message_add_tail(&value_xfer, &msg);
|
|
|
|
|
|
|
|
return spi_sync(lcd->spi, &msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The comments are taken straight from the data sheet */
|
|
|
|
static int ltv350qv_power_on(struct ltv350qv *lcd)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Power On Reset Display off State */
|
|
|
|
if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, 0x0000))
|
|
|
|
goto err;
|
2012-10-05 07:12:44 +07:00
|
|
|
usleep_range(15000, 16000);
|
2007-09-03 05:15:49 +07:00
|
|
|
|
|
|
|
/* Power Setting Function 1 */
|
|
|
|
if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE))
|
|
|
|
goto err;
|
|
|
|
if (ltv350qv_write_reg(lcd, LTV_PWRCTL2, LTV_VCOML_ENABLE))
|
|
|
|
goto err_power1;
|
|
|
|
|
|
|
|
/* Power Setting Function 2 */
|
|
|
|
if (ltv350qv_write_reg(lcd, LTV_PWRCTL1,
|
|
|
|
LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
|
|
|
|
| LTV_SUPPLY_CURRENT(5)))
|
|
|
|
goto err_power2;
|
|
|
|
|
|
|
|
msleep(55);
|
|
|
|
|
|
|
|
/* Instruction Setting */
|
|
|
|
ret = ltv350qv_write_reg(lcd, LTV_IFCTL,
|
|
|
|
LTV_NMD | LTV_REV | LTV_NL(0x1d));
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_DATACTL,
|
|
|
|
LTV_DS_SAME | LTV_CHS_480
|
|
|
|
| LTV_DF_RGB | LTV_RGB_BGR);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_ENTRY_MODE,
|
|
|
|
LTV_VSPL_ACTIVE_LOW
|
|
|
|
| LTV_HSPL_ACTIVE_LOW
|
|
|
|
| LTV_DPL_SAMPLE_RISING
|
|
|
|
| LTV_EPL_ACTIVE_LOW
|
|
|
|
| LTV_SS_RIGHT_TO_LEFT);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GATECTL1, LTV_CLW(3));
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
|
|
|
|
LTV_NW_INV_1LINE | LTV_FWI(3));
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_VBP, 0x000a);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_HBP, 0x0021);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_SOTCTL, LTV_SDT(3) | LTV_EQ(0));
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(0), 0x0103);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(1), 0x0301);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(2), 0x1f0f);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(3), 0x1f0f);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(4), 0x0707);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(5), 0x0307);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(6), 0x0707);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(7), 0x0000);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(8), 0x0004);
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(9), 0x0000);
|
|
|
|
if (ret)
|
|
|
|
goto err_settings;
|
|
|
|
|
|
|
|
/* Wait more than 2 frames */
|
|
|
|
msleep(20);
|
|
|
|
|
|
|
|
/* Display On Sequence */
|
|
|
|
ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
|
|
|
|
LTV_VCOM_DISABLE | LTV_VCOMOUT_ENABLE
|
|
|
|
| LTV_POWER_ON | LTV_DRIVE_CURRENT(5)
|
|
|
|
| LTV_SUPPLY_CURRENT(5));
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
|
|
|
|
LTV_NW_INV_1LINE | LTV_DSC | LTV_FWI(3));
|
|
|
|
if (ret)
|
|
|
|
goto err_disp_on;
|
|
|
|
|
|
|
|
/* Display should now be ON. Phew. */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_disp_on:
|
|
|
|
/*
|
|
|
|
* Try to recover. Error handling probably isn't very useful
|
|
|
|
* at this point, just make a best effort to switch the panel
|
|
|
|
* off.
|
|
|
|
*/
|
|
|
|
ltv350qv_write_reg(lcd, LTV_PWRCTL1,
|
|
|
|
LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
|
|
|
|
| LTV_SUPPLY_CURRENT(5));
|
|
|
|
ltv350qv_write_reg(lcd, LTV_GATECTL2,
|
|
|
|
LTV_NW_INV_1LINE | LTV_FWI(3));
|
|
|
|
err_settings:
|
|
|
|
err_power2:
|
|
|
|
err_power1:
|
|
|
|
ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
|
2012-10-05 07:12:44 +07:00
|
|
|
usleep_range(1000, 1100);
|
2007-09-03 05:15:49 +07:00
|
|
|
err:
|
|
|
|
ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ltv350qv_power_off(struct ltv350qv *lcd)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Display Off Sequence */
|
|
|
|
ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
|
|
|
|
LTV_VCOM_DISABLE
|
|
|
|
| LTV_DRIVE_CURRENT(5)
|
|
|
|
| LTV_SUPPLY_CURRENT(5));
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
|
|
|
|
LTV_NW_INV_1LINE | LTV_FWI(3));
|
|
|
|
|
|
|
|
/* Power down setting 1 */
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
|
|
|
|
|
|
|
|
/* Wait at least 1 ms */
|
2012-10-05 07:12:44 +07:00
|
|
|
usleep_range(1000, 1100);
|
2007-09-03 05:15:49 +07:00
|
|
|
|
|
|
|
/* Power down setting 2 */
|
|
|
|
ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No point in trying to recover here. If we can't switch the
|
|
|
|
* panel off, what are we supposed to do other than inform the
|
|
|
|
* user about the failure?
|
|
|
|
*/
|
|
|
|
if (ret)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
/* Display power should now be OFF */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ltv350qv_power(struct ltv350qv *lcd, int power)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
|
|
|
|
ret = ltv350qv_power_on(lcd);
|
|
|
|
else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
|
|
|
|
ret = ltv350qv_power_off(lcd);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
lcd->power = power;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ltv350qv_set_power(struct lcd_device *ld, int power)
|
|
|
|
{
|
|
|
|
struct ltv350qv *lcd = lcd_get_data(ld);
|
|
|
|
|
|
|
|
return ltv350qv_power(lcd, power);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ltv350qv_get_power(struct lcd_device *ld)
|
|
|
|
{
|
|
|
|
struct ltv350qv *lcd = lcd_get_data(ld);
|
|
|
|
|
|
|
|
return lcd->power;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct lcd_ops ltv_ops = {
|
|
|
|
.get_power = ltv350qv_get_power,
|
|
|
|
.set_power = ltv350qv_set_power,
|
|
|
|
};
|
|
|
|
|
2012-11-20 01:21:46 +07:00
|
|
|
static int ltv350qv_probe(struct spi_device *spi)
|
2007-09-03 05:15:49 +07:00
|
|
|
{
|
|
|
|
struct ltv350qv *lcd;
|
|
|
|
struct lcd_device *ld;
|
|
|
|
int ret;
|
|
|
|
|
2012-05-30 05:07:24 +07:00
|
|
|
lcd = devm_kzalloc(&spi->dev, sizeof(struct ltv350qv), GFP_KERNEL);
|
2007-09-03 05:15:49 +07:00
|
|
|
if (!lcd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
lcd->spi = spi;
|
|
|
|
lcd->power = FB_BLANK_POWERDOWN;
|
2012-05-30 05:07:24 +07:00
|
|
|
lcd->buffer = devm_kzalloc(&spi->dev, 8, GFP_KERNEL);
|
|
|
|
if (!lcd->buffer)
|
|
|
|
return -ENOMEM;
|
2007-09-03 05:15:49 +07:00
|
|
|
|
|
|
|
ld = lcd_device_register("ltv350qv", &spi->dev, lcd, <v_ops);
|
2012-05-30 05:07:24 +07:00
|
|
|
if (IS_ERR(ld))
|
|
|
|
return PTR_ERR(ld);
|
|
|
|
|
2007-09-03 05:15:49 +07:00
|
|
|
lcd->ld = ld;
|
|
|
|
|
|
|
|
ret = ltv350qv_power(lcd, FB_BLANK_UNBLANK);
|
|
|
|
if (ret)
|
|
|
|
goto out_unregister;
|
|
|
|
|
2013-02-22 07:43:36 +07:00
|
|
|
spi_set_drvdata(spi, lcd);
|
2007-09-03 05:15:49 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_unregister:
|
|
|
|
lcd_device_unregister(ld);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-20 01:26:34 +07:00
|
|
|
static int ltv350qv_remove(struct spi_device *spi)
|
2007-09-03 05:15:49 +07:00
|
|
|
{
|
2013-02-22 07:43:36 +07:00
|
|
|
struct ltv350qv *lcd = spi_get_drvdata(spi);
|
2007-09-03 05:15:49 +07:00
|
|
|
|
|
|
|
ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
|
|
|
|
lcd_device_unregister(lcd->ld);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int ltv350qv_suspend(struct spi_device *spi, pm_message_t state)
|
|
|
|
{
|
2013-02-22 07:43:36 +07:00
|
|
|
struct ltv350qv *lcd = spi_get_drvdata(spi);
|
2007-09-03 05:15:49 +07:00
|
|
|
|
|
|
|
return ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ltv350qv_resume(struct spi_device *spi)
|
|
|
|
{
|
2013-02-22 07:43:36 +07:00
|
|
|
struct ltv350qv *lcd = spi_get_drvdata(spi);
|
2007-09-03 05:15:49 +07:00
|
|
|
|
|
|
|
return ltv350qv_power(lcd, FB_BLANK_UNBLANK);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define ltv350qv_suspend NULL
|
|
|
|
#define ltv350qv_resume NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Power down all displays on reboot, poweroff or halt */
|
|
|
|
static void ltv350qv_shutdown(struct spi_device *spi)
|
|
|
|
{
|
2013-02-22 07:43:36 +07:00
|
|
|
struct ltv350qv *lcd = spi_get_drvdata(spi);
|
2007-09-03 05:15:49 +07:00
|
|
|
|
|
|
|
ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct spi_driver ltv350qv_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ltv350qv",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
|
|
|
|
.probe = ltv350qv_probe,
|
2012-11-20 01:21:09 +07:00
|
|
|
.remove = ltv350qv_remove,
|
2007-09-03 05:15:49 +07:00
|
|
|
.shutdown = ltv350qv_shutdown,
|
|
|
|
.suspend = ltv350qv_suspend,
|
|
|
|
.resume = ltv350qv_resume,
|
|
|
|
};
|
|
|
|
|
2012-03-24 05:01:59 +07:00
|
|
|
module_spi_driver(ltv350qv_driver);
|
2007-09-03 05:15:49 +07:00
|
|
|
|
2011-05-18 21:49:24 +07:00
|
|
|
MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
|
2007-09-03 05:15:49 +07:00
|
|
|
MODULE_DESCRIPTION("Samsung LTV350QV LCD Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2009-09-23 06:46:08 +07:00
|
|
|
MODULE_ALIAS("spi:ltv350qv");
|