Re: [PATCH V2] backlight: add ams369fg06 amoled driver

From: anish singh
Date: Wed Jun 29 2011 - 08:22:02 EST


On Wed, Jun 29, 2011 at 3:37 PM, Jingoo Han <jg1.han@xxxxxxxxxxx> wrote:
> This patch adds ams369fg06 amoled panel driver. The ams369fg06
> amoled panel (480 x 800) driver uses 3-wired SPI inteface.
> The brightness can be controlled by gamma setting of amoled panel.
>
> Signed-off-by: Jingoo Han <jg1.han@xxxxxxxxxxx>
> ---
> Âdrivers/video/backlight/Kconfig   Â|  Â8 +
> Âdrivers/video/backlight/Makefile   |  Â1 +
> Âdrivers/video/backlight/ams369fg06.c | Â642 ++++++++++++++++++++++++++++++++++
> Â3 files changed, 651 insertions(+), 0 deletions(-)
> Âcreate mode 100644 drivers/video/backlight/ams369fg06.c
>
> diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
> index 2d93c8d..1e54b8b 100644
> --- a/drivers/video/backlight/Kconfig
> +++ b/drivers/video/backlight/Kconfig
> @@ -117,6 +117,14 @@ config LCD_LD9040
> Â Â Â Â ÂIf you have an LD9040 Panel, say Y to enable its
> Â Â Â Â Âcontrol driver.
>
> +config LCD_AMS369FG06
> + Â Â Â tristate "AMS369FG06 AMOLED LCD Driver"
> + Â Â Â depends on SPI && BACKLIGHT_CLASS_DEVICE
> + Â Â Â default n
> + Â Â Â help
> + Â Â Â Â If you have an AMS369FG06 AMOLED Panel, say Y to enable its
> + Â Â Â Â LCD control driver.
> +
> Âendif # LCD_CLASS_DEVICE
>
> Â#
> diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
> index ee72adb..bf1dd92 100644
> --- a/drivers/video/backlight/Makefile
> +++ b/drivers/video/backlight/Makefile
> @@ -13,6 +13,7 @@ obj-$(CONFIG_LCD_TDO24M) Â Â Â Â += tdo24m.o
> Âobj-$(CONFIG_LCD_TOSA) Â Â Â Â Â Â+= tosa_lcd.o
> Âobj-$(CONFIG_LCD_S6E63M0) Â Â Â+= s6e63m0.o
> Âobj-$(CONFIG_LCD_LD9040) Â Â Â += ld9040.o
> +obj-$(CONFIG_LCD_AMS369FG06) Â += ams369fg06.o
>
> Âobj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
> Âobj-$(CONFIG_BACKLIGHT_ATMEL_PWM) Â Â+= atmel-pwm-bl.o
> diff --git a/drivers/video/backlight/ams369fg06.c b/drivers/video/backlight/ams369fg06.c
> new file mode 100644
> index 0000000..86a7daf
> --- /dev/null
> +++ b/drivers/video/backlight/ams369fg06.c
> @@ -0,0 +1,642 @@
> +/*
> + * ams369fg06 AMOLED LCD panel driver.
> + *
> + * Copyright (c) 2011 Samsung Electronics Co., Ltd.
> + * Author: Jingoo Han Â<jg1.han@xxxxxxxxxxx>
> + *
> + * Derived from drivers/video/s6e63m0.c
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by the
> + * Free Software Foundation; either version 2 of the License, or (at your
> + * option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ÂSee the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write to the Free Software Foundation, Inc.,
> + * 59 Temple Place - Suite 330, Boston, MA Â02111-1307, USA.
> + */
> +
> +#include <linux/wait.h>
> +#include <linux/fb.h>
> +#include <linux/delay.h>
> +#include <linux/gpio.h>
> +#include <linux/spi/spi.h>
> +#include <linux/lcd.h>
> +#include <linux/backlight.h>
> +
> +#define SLEEPMSEC Â Â Â Â Â Â Â0x1000
> +#define ENDDEF Â Â Â Â Â Â Â Â 0x2000
> +#define    ÂDEFMASK         0xFF00
> +#define COMMAND_ONLY Â Â Â Â Â 0xFE
> +#define DATA_ONLY Â Â Â Â Â Â Â0xFF
> +
> +#define MAX_GAMMA_LEVEL Â Â Â Â Â Â Â Â5
> +#define GAMMA_TABLE_COUNT Â Â Â21
> +
> +#define MIN_BRIGHTNESS Â Â Â Â 0
> +#define MAX_BRIGHTNESS Â Â Â Â 255
> +#define DEFAULT_BRIGHTNESS Â Â 150
> +
> +struct ams369fg06 {
> +    struct device          *dev;
> +    struct spi_device        *spi;
> +    unsigned int          Âpower;
> +    struct lcd_device        *ld;
> +    struct backlight_device     *bd;
> +    struct lcd_platform_data    Â*lcd_pd;
> +};
> +
> +static const unsigned short seq_display_on[] = {
> + Â Â Â 0x14, 0x03,
> + Â Â Â ENDDEF, 0x0000
> +};
> +
> +static const unsigned short seq_display_off[] = {
> + Â Â Â 0x14, 0x00,
> + Â Â Â ENDDEF, 0x0000
> +};
> +
> +static const unsigned short seq_stand_by_on[] = {
> + Â Â Â 0x1D, 0xA1,
> + Â Â Â SLEEPMSEC, 200,
> + Â Â Â ENDDEF, 0x0000
> +};
> +
> +static const unsigned short seq_stand_by_off[] = {
> + Â Â Â 0x1D, 0xA0,
> + Â Â Â SLEEPMSEC, 250,
> + Â Â Â ENDDEF, 0x0000
> +};
> +
> +static const unsigned short seq_setting[] = {
> + Â Â Â 0x31, 0x08,
> + Â Â Â 0x32, 0x14,
> + Â Â Â 0x30, 0x02,
> + Â Â Â 0x27, 0x01,
> + Â Â Â 0x12, 0x08,
> + Â Â Â 0x13, 0x08,
> + Â Â Â 0x15, 0x00,
> + Â Â Â 0x16, 0x00,
> +
> + Â Â Â 0xef, 0xd0,
> + Â Â Â DATA_ONLY, 0xe8,
> +
> + Â Â Â 0x39, 0x44,
> + Â Â Â 0x40, 0x00,
> + Â Â Â 0x41, 0x3f,
> + Â Â Â 0x42, 0x2a,
> + Â Â Â 0x43, 0x27,
> + Â Â Â 0x44, 0x27,
> + Â Â Â 0x45, 0x1f,
> + Â Â Â 0x46, 0x44,
> + Â Â Â 0x50, 0x00,
> + Â Â Â 0x51, 0x00,
> + Â Â Â 0x52, 0x17,
> + Â Â Â 0x53, 0x24,
> + Â Â Â 0x54, 0x26,
> + Â Â Â 0x55, 0x1f,
> + Â Â Â 0x56, 0x43,
> + Â Â Â 0x60, 0x00,
> + Â Â Â 0x61, 0x3f,
> + Â Â Â 0x62, 0x2a,
> + Â Â Â 0x63, 0x25,
> + Â Â Â 0x64, 0x24,
> + Â Â Â 0x65, 0x1b,
> + Â Â Â 0x66, 0x5c,
> +
> + Â Â Â 0x17, 0x22,
> + Â Â Â 0x18, 0x33,
> + Â Â Â 0x19, 0x03,
> + Â Â Â 0x1a, 0x01,
> + Â Â Â 0x22, 0xa4,
> + Â Â Â 0x23, 0x00,
> + Â Â Â 0x26, 0xa0,
> +
> + Â Â Â 0x1d, 0xa0,
> + Â Â Â SLEEPMSEC, 300,
> +
> + Â Â Â 0x14, 0x03,
> +
> + Â Â Â ENDDEF, 0x0000
> +};
> +
> +/* gamma value: 2.2 */
> +static const unsigned int ams369fg06_22_250[] = {
> + Â Â Â 0x00, 0x3f, 0x2a, 0x27, 0x27, 0x1f, 0x44,
> + Â Â Â 0x00, 0x00, 0x17, 0x24, 0x26, 0x1f, 0x43,
> + Â Â Â 0x00, 0x3f, 0x2a, 0x25, 0x24, 0x1b, 0x5c,
> +};
> +
> +static const unsigned int ams369fg06_22_200[] = {
> + Â Â Â 0x00, 0x3f, 0x28, 0x29, 0x27, 0x21, 0x3e,
> + Â Â Â 0x00, 0x00, 0x10, 0x25, 0x27, 0x20, 0x3d,
> + Â Â Â 0x00, 0x3f, 0x28, 0x27, 0x25, 0x1d, 0x53,
> +};
> +
> +static const unsigned int ams369fg06_22_150[] = {
> + Â Â Â 0x00, 0x3f, 0x2d, 0x29, 0x28, 0x23, 0x37,
> + Â Â Â 0x00, 0x00, 0x0b, 0x25, 0x28, 0x22, 0x36,
> + Â Â Â 0x00, 0x3f, 0x2b, 0x28, 0x26, 0x1f, 0x4a,
> +};
> +
> +static const unsigned int ams369fg06_22_100[] = {
> + Â Â Â 0x00, 0x3f, 0x30, 0x2a, 0x2b, 0x24, 0x2f,
> + Â Â Â 0x00, 0x00, 0x00, 0x25, 0x29, 0x24, 0x2e,
> + Â Â Â 0x00, 0x3f, 0x2f, 0x29, 0x29, 0x21, 0x3f,
> +};
> +
> +static const unsigned int ams369fg06_22_50[] = {
> + Â Â Â 0x00, 0x3f, 0x3c, 0x2c, 0x2d, 0x27, 0x24,
> + Â Â Â 0x00, 0x00, 0x00, 0x22, 0x2a, 0x27, 0x23,
> + Â Â Â 0x00, 0x3f, 0x3b, 0x2c, 0x2b, 0x24, 0x31,
> +};
> +
> +struct ams369fg06_gamma {
> + Â Â Â unsigned int *gamma_22_table[MAX_GAMMA_LEVEL];
> +};
> +
> +static struct ams369fg06_gamma gamma_table = {
> + Â Â Â .gamma_22_table[0] = (unsigned int *)&ams369fg06_22_50,
> + Â Â Â .gamma_22_table[1] = (unsigned int *)&ams369fg06_22_100,
> + Â Â Â .gamma_22_table[2] = (unsigned int *)&ams369fg06_22_150,
> + Â Â Â .gamma_22_table[3] = (unsigned int *)&ams369fg06_22_200,
> + Â Â Â .gamma_22_table[4] = (unsigned int *)&ams369fg06_22_250,
> +};
> +
> +static int ams369fg06_spi_write_byte(struct ams369fg06 *lcd, int addr, int data)
> +{
> + Â Â Â u16 buf[1];
> + Â Â Â struct spi_message msg;
> +
> + Â Â Â struct spi_transfer xfer = {
> +        .len      Â= 2,
> +        .tx_buf     = buf,
> + Â Â Â };
> +
> + Â Â Â buf[0] = (addr << 8) | data;
Does this hardware allow transferring data from the stack?
Quoting Greg here:"SPI data, like USB data, has to come from kmalloced data,
not from the stack, or bad things can, and will, happen"
> +
> + Â Â Â spi_message_init(&msg);
> + Â Â Â spi_message_add_tail(&xfer, &msg);
> +
> + Â Â Â return spi_sync(lcd->spi, &msg);
> +}
> +
> +static int ams369fg06_spi_write(struct ams369fg06 *lcd, unsigned char address,
> + Â Â Â unsigned char command)
> +{
> + Â Â Â int ret = 0;
> +
> + Â Â Â if (address != DATA_ONLY)
> + Â Â Â Â Â Â Â ret = ams369fg06_spi_write_byte(lcd, 0x70, address);
> + Â Â Â if (command != COMMAND_ONLY)
> + Â Â Â Â Â Â Â ret = ams369fg06_spi_write_byte(lcd, 0x72, command);
> +
> + Â Â Â return ret;
> +}
> +
> +static int ams369fg06_panel_send_sequence(struct ams369fg06 *lcd,
> + Â Â Â const unsigned short *wbuf)
> +{
> + Â Â Â int ret = 0, i = 0;
> +
> + Â Â Â while ((wbuf[i] & DEFMASK) != ENDDEF) {
> + Â Â Â Â Â Â Â if ((wbuf[i] & DEFMASK) != SLEEPMSEC) {
> + Â Â Â Â Â Â Â Â Â Â Â ret = ams369fg06_spi_write(lcd, wbuf[i], wbuf[i+1]);
> + Â Â Â Â Â Â Â Â Â Â Â if (ret)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â } else
> + Â Â Â Â Â Â Â Â Â Â Â mdelay(wbuf[i+1]);
> + Â Â Â Â Â Â Â i += 2;
> + Â Â Â }
> +
> + Â Â Â return ret;
> +}
> +
> +static int _ams369fg06_gamma_ctl(struct ams369fg06 *lcd,
> + Â Â Â const unsigned int *gamma)
> +{
> + Â Â Â unsigned int i = 0;
> + Â Â Â int ret = 0;
> +
> + Â Â Â for (i = 0 ; i < GAMMA_TABLE_COUNT / 3; i++) {
> + Â Â Â Â Â Â Â ret = ams369fg06_spi_write(lcd, 0x40 + i, gamma[i]);
> + Â Â Â Â Â Â Â ret = ams369fg06_spi_write(lcd, 0x50 + i, gamma[i+7*1]);
> + Â Â Â Â Â Â Â ret = ams369fg06_spi_write(lcd, 0x60 + i, gamma[i+7*2]);
> + Â Â Â Â Â Â Â if (ret) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(lcd->dev, "failed to set gamma table.\n");
> + Â Â Â Â Â Â Â Â Â Â Â goto gamma_err;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> +
> +gamma_err:
> + Â Â Â return ret;
> +}
> +
> +static int ams369fg06_gamma_ctl(struct ams369fg06 *lcd, int brightness)
> +{
> + Â Â Â int ret = 0;
> + Â Â Â int gamma = 0;
> +
> + Â Â Â if ((brightness >= 0) && (brightness <= 50))
> + Â Â Â Â Â Â Â gamma = 0;
> + Â Â Â else if ((brightness > 50) && (brightness <= 100))
> + Â Â Â Â Â Â Â gamma = 1;
> + Â Â Â else if ((brightness > 100) && (brightness <= 150))
> + Â Â Â Â Â Â Â gamma = 2;
> + Â Â Â else if ((brightness > 150) && (brightness <= 200))
> + Â Â Â Â Â Â Â gamma = 3;
> + Â Â Â else if ((brightness > 200) && (brightness <= 255))
> + Â Â Â Â Â Â Â gamma = 4;
> +
> + Â Â Â ret = _ams369fg06_gamma_ctl(lcd, gamma_table.gamma_22_table[gamma]);
> +
> + Â Â Â return ret;
> +}
> +
> +static int ams369fg06_ldi_init(struct ams369fg06 *lcd)
> +{
> + Â Â Â int ret, i;
> + Â Â Â static const unsigned short *init_seq[] = {
> + Â Â Â Â Â Â Â seq_setting,
> + Â Â Â Â Â Â Â seq_stand_by_off,
> + Â Â Â };
> +
> + Â Â Â for (i = 0; i < ARRAY_SIZE(init_seq); i++) {
> + Â Â Â Â Â Â Â ret = ams369fg06_panel_send_sequence(lcd, init_seq[i]);
> + Â Â Â Â Â Â Â if (ret)
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â }
> +
> + Â Â Â return ret;
> +}
> +
> +static int ams369fg06_ldi_enable(struct ams369fg06 *lcd)
> +{
> + Â Â Â int ret, i;
> + Â Â Â static const unsigned short *init_seq[] = {
> + Â Â Â Â Â Â Â seq_stand_by_off,
> + Â Â Â Â Â Â Â seq_display_on,
> + Â Â Â };
> +
> + Â Â Â for (i = 0; i < ARRAY_SIZE(init_seq); i++) {
> + Â Â Â Â Â Â Â ret = ams369fg06_panel_send_sequence(lcd, init_seq[i]);
> + Â Â Â Â Â Â Â if (ret)
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â }
> +
> + Â Â Â return ret;
> +}
> +
> +static int ams369fg06_ldi_disable(struct ams369fg06 *lcd)
> +{
> + Â Â Â int ret, i;
> +
> + Â Â Â static const unsigned short *init_seq[] = {
> + Â Â Â Â Â Â Â seq_display_off,
> + Â Â Â Â Â Â Â seq_stand_by_on,
> + Â Â Â };
> +
> + Â Â Â for (i = 0; i < ARRAY_SIZE(init_seq); i++) {
> + Â Â Â Â Â Â Â ret = ams369fg06_panel_send_sequence(lcd, init_seq[i]);
> + Â Â Â Â Â Â Â if (ret)
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â }
> +
> + Â Â Â return ret;
> +}
> +
> +static int ams369fg06_power_is_on(int power)
> +{
> + Â Â Â return ((power) <= FB_BLANK_NORMAL);
> +}
Don't you think this should be inline ?
> +
> +static int ams369fg06_power_on(struct ams369fg06 *lcd)
> +{
> + Â Â Â int ret = 0;
> + Â Â Â struct lcd_platform_data *pd = NULL;
> + Â Â Â struct backlight_device *bd = NULL;
> +
> + Â Â Â pd = lcd->lcd_pd;
> + Â Â Â if (!pd) {
> + Â Â Â Â Â Â Â dev_err(lcd->dev, "platform data is NULL.\n");
> + Â Â Â Â Â Â Â return -EFAULT;
> + Â Â Â }
> +
> + Â Â Â bd = lcd->bd;
> + Â Â Â if (!bd) {
> + Â Â Â Â Â Â Â dev_err(lcd->dev, "backlight device is NULL.\n");
> + Â Â Â Â Â Â Â return -EFAULT;
> + Â Â Â }
> +
> + Â Â Â if (!pd->power_on) {
> + Â Â Â Â Â Â Â dev_err(lcd->dev, "power_on is NULL.\n");
> + Â Â Â Â Â Â Â return -EFAULT;
> + Â Â Â } else {
> + Â Â Â Â Â Â Â pd->power_on(lcd->ld, 1);
> + Â Â Â Â Â Â Â mdelay(pd->power_on_delay);
> + Â Â Â }
> +
> + Â Â Â if (!pd->reset) {
> + Â Â Â Â Â Â Â dev_err(lcd->dev, "reset is NULL.\n");
> + Â Â Â Â Â Â Â return -EFAULT;
> + Â Â Â } else {
> + Â Â Â Â Â Â Â pd->reset(lcd->ld);
> + Â Â Â Â Â Â Â mdelay(pd->reset_delay);
> + Â Â Â }
> +
> + Â Â Â ret = ams369fg06_ldi_init(lcd);
> + Â Â Â if (ret) {
> + Â Â Â Â Â Â Â dev_err(lcd->dev, "failed to initialize ldi.\n");
> + Â Â Â Â Â Â Â return ret;
> + Â Â Â }
> +
> + Â Â Â ret = ams369fg06_ldi_enable(lcd);
> + Â Â Â if (ret) {
> + Â Â Â Â Â Â Â dev_err(lcd->dev, "failed to enable ldi.\n");
> + Â Â Â Â Â Â Â return ret;
> + Â Â Â }
> +
> + Â Â Â /* set brightness to current value after power on or resume. */
> + Â Â Â ret = ams369fg06_gamma_ctl(lcd, bd->props.brightness);
> + Â Â Â if (ret) {
> + Â Â Â Â Â Â Â dev_err(lcd->dev, "lcd gamma setting failed.\n");
> + Â Â Â Â Â Â Â return ret;
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +static int ams369fg06_power_off(struct ams369fg06 *lcd)
> +{
> + Â Â Â int ret = 0;
> + Â Â Â struct lcd_platform_data *pd = NULL;
> +
> + Â Â Â pd = lcd->lcd_pd;
> + Â Â Â if (!pd) {
> + Â Â Â Â Â Â Â dev_err(lcd->dev, "platform data is NULL\n");
> + Â Â Â Â Â Â Â return -EFAULT;
> + Â Â Â }
> +
> + Â Â Â ret = ams369fg06_ldi_disable(lcd);
> + Â Â Â if (ret) {
> + Â Â Â Â Â Â Â dev_err(lcd->dev, "lcd setting failed.\n");
> + Â Â Â Â Â Â Â return -EIO;
> + Â Â Â }
> +
> + Â Â Â mdelay(pd->power_off_delay);
> +
> + Â Â Â if (!pd->power_on) {
> + Â Â Â Â Â Â Â dev_err(lcd->dev, "power_on is NULL.\n");
> + Â Â Â Â Â Â Â return -EFAULT;
> + Â Â Â } else
> + Â Â Â Â Â Â Â pd->power_on(lcd->ld, 0);
> +
> + Â Â Â return 0;
> +}
> +
> +static int ams369fg06_power(struct ams369fg06 *lcd, int power)
> +{
> + Â Â Â int ret = 0;
> +
> + Â Â Â if (ams369fg06_power_is_on(power) &&
> + Â Â Â Â Â Â Â !ams369fg06_power_is_on(lcd->power))
> + Â Â Â Â Â Â Â ret = ams369fg06_power_on(lcd);
> + Â Â Â else if (!ams369fg06_power_is_on(power) &&
> + Â Â Â Â Â Â Â ams369fg06_power_is_on(lcd->power))
> + Â Â Â Â Â Â Â ret = ams369fg06_power_off(lcd);
> +
> + Â Â Â if (!ret)
> + Â Â Â Â Â Â Â lcd->power = power;
> +
> + Â Â Â return ret;
> +}
> +
> +static int ams369fg06_get_power(struct lcd_device *ld)
> +{
> + Â Â Â struct ams369fg06 *lcd = lcd_get_data(ld);
> +
> + Â Â Â return lcd->power;
> +}
Inline ?
> +
> +static int ams369fg06_set_power(struct lcd_device *ld, int power)
> +{
> + Â Â Â struct ams369fg06 *lcd = lcd_get_data(ld);
> +
> + Â Â Â if (power != FB_BLANK_UNBLANK && power != FB_BLANK_POWERDOWN &&
> + Â Â Â Â Â Â Â power != FB_BLANK_NORMAL) {
> + Â Â Â Â Â Â Â dev_err(lcd->dev, "power value should be 0, 1 or 4.\n");
> + Â Â Â Â Â Â Â return -EINVAL;
> + Â Â Â }
> +
> + Â Â Â return ams369fg06_power(lcd, power);
> +}
> +
> +static int ams369fg06_get_brightness(struct backlight_device *bd)
> +{
> + Â Â Â return bd->props.brightness;
> +}
inline?
> +
> +static int ams369fg06_set_brightness(struct backlight_device *bd)
> +{
> + Â Â Â int ret = 0;
> + Â Â Â int brightness = bd->props.brightness;
> + Â Â Â struct ams369fg06 *lcd = dev_get_drvdata(&bd->dev);
> +
> + Â Â Â if (brightness < MIN_BRIGHTNESS ||
> + Â Â Â Â Â Â Â brightness > bd->props.max_brightness) {
> + Â Â Â Â Â Â Â dev_err(&bd->dev, "lcd brightness should be %d to %d.\n",
> + Â Â Â Â Â Â Â Â Â Â Â MIN_BRIGHTNESS, MAX_BRIGHTNESS);
> + Â Â Â Â Â Â Â return -EINVAL;
> + Â Â Â }
> +
> + Â Â Â ret = ams369fg06_gamma_ctl(lcd, bd->props.brightness);
> + Â Â Â if (ret) {
> + Â Â Â Â Â Â Â dev_err(&bd->dev, "lcd brightness setting failed.\n");
> + Â Â Â Â Â Â Â return -EIO;
> + Â Â Â }
> +
> + Â Â Â return ret;
> +}
> +
> +static struct lcd_ops ams369fg06_lcd_ops = {
> + Â Â Â .get_power = ams369fg06_get_power,
> + Â Â Â .set_power = ams369fg06_set_power,
> +};
> +
> +static const struct backlight_ops ams369fg06_backlight_ops = {
> + Â Â Â .get_brightness = ams369fg06_get_brightness,
> + Â Â Â .update_status = ams369fg06_set_brightness,
> +};
> +
> +static int __init ams369fg06_probe(struct spi_device *spi)
> +{
> + Â Â Â int ret = 0;
> + Â Â Â struct ams369fg06 *lcd = NULL;
> + Â Â Â struct lcd_device *ld = NULL;
> + Â Â Â struct backlight_device *bd = NULL;
> +
> + Â Â Â lcd = kzalloc(sizeof(struct ams369fg06), GFP_KERNEL);
> + Â Â Â if (!lcd)
> + Â Â Â Â Â Â Â return -ENOMEM;
> +
> + Â Â Â /* ams369fg06 lcd panel uses 3-wire 16bits SPI Mode. */
> + Â Â Â spi->bits_per_word = 16;
> +
> + Â Â Â ret = spi_setup(spi);
> + Â Â Â if (ret < 0) {
> + Â Â Â Â Â Â Â dev_err(&spi->dev, "spi setup failed.\n");
> + Â Â Â Â Â Â Â goto out_free_lcd;
> + Â Â Â }
> +
> + Â Â Â lcd->spi = spi;
> + Â Â Â lcd->dev = &spi->dev;
> +
> + Â Â Â lcd->lcd_pd = spi->dev.platform_data;
> + Â Â Â if (!lcd->lcd_pd) {
> + Â Â Â Â Â Â Â dev_err(&spi->dev, "platform data is NULL\n");
> + Â Â Â Â Â Â Â goto out_free_lcd;
> + Â Â Â }
> +
> + Â Â Â ld = lcd_device_register("ams369fg06", &spi->dev, lcd,
> + Â Â Â Â Â Â Â &ams369fg06_lcd_ops);
> + Â Â Â if (IS_ERR(ld)) {
> + Â Â Â Â Â Â Â ret = PTR_ERR(ld);
> + Â Â Â Â Â Â Â goto out_free_lcd;
> + Â Â Â }
> +
> + Â Â Â lcd->ld = ld;
> +
> + Â Â Â bd = backlight_device_register("ams369fg06-bl", &spi->dev, lcd,
> + Â Â Â Â Â Â Â &ams369fg06_backlight_ops, NULL);
> + Â Â Â if (IS_ERR(bd)) {
> + Â Â Â Â Â Â Â ret = ÂPTR_ERR(bd);
> + Â Â Â Â Â Â Â goto out_lcd_unregister;
> + Â Â Â }
> +
> + Â Â Â bd->props.max_brightness = MAX_BRIGHTNESS;
> + Â Â Â bd->props.brightness = DEFAULT_BRIGHTNESS;
> + Â Â Â bd->props.type = BACKLIGHT_RAW;
> + Â Â Â lcd->bd = bd;
> +
> + Â Â Â if (!lcd->lcd_pd->lcd_enabled) {
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* if lcd panel was off from bootloader then
> + Â Â Â Â Â Â Â Â* current lcd status is powerdown and then
> + Â Â Â Â Â Â Â Â* it enables lcd panel.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â lcd->power = FB_BLANK_POWERDOWN;
> +
> + Â Â Â Â Â Â Â ams369fg06_power(lcd, FB_BLANK_UNBLANK);
> + Â Â Â } else
> + Â Â Â Â Â Â Â lcd->power = FB_BLANK_UNBLANK;
> +
> + Â Â Â dev_set_drvdata(&spi->dev, lcd);
> +
> + Â Â Â dev_info(&spi->dev, "ams369fg06 panel driver has been probed.\n");
> +
> + Â Â Â return 0;
> +
> +out_lcd_unregister:
> + Â Â Â lcd_device_unregister(ld);
> +out_free_lcd:
> + Â Â Â kfree(lcd);
> + Â Â Â return ret;
> +}
> +
> +static int __devexit ams369fg06_remove(struct spi_device *spi)
> +{
> + Â Â Â struct ams369fg06 *lcd = dev_get_drvdata(&spi->dev);
> +
> + Â Â Â ams369fg06_power(lcd, FB_BLANK_POWERDOWN);
> + Â Â Â lcd_device_unregister(lcd->ld);
> + Â Â Â kfree(lcd);
> +
> + Â Â Â return 0;
> +}
> +
> +#if defined(CONFIG_PM)
> +unsigned int before_power;
> +
> +static int ams369fg06_suspend(struct spi_device *spi, pm_message_t mesg)
> +{
> + Â Â Â int ret = 0;
> + Â Â Â struct ams369fg06 *lcd = dev_get_drvdata(&spi->dev);
> +
> + Â Â Â dev_dbg(&spi->dev, "lcd->power = %d\n", lcd->power);
> +
> + Â Â Â before_power = lcd->power;
> +
> + Â Â Â /*
> + Â Â Â Â* when lcd panel is suspend, lcd panel becomes off
> + Â Â Â Â* regardless of status.
> + Â Â Â Â*/
> + Â Â Â ret = ams369fg06_power(lcd, FB_BLANK_POWERDOWN);
> +
> + Â Â Â return ret;
> +}
> +
> +static int ams369fg06_resume(struct spi_device *spi)
> +{
> + Â Â Â int ret = 0;
> + Â Â Â struct ams369fg06 *lcd = dev_get_drvdata(&spi->dev);
> +
> + Â Â Â /*
> + Â Â Â Â* after suspended, if lcd panel status is FB_BLANK_UNBLANK
> + Â Â Â Â* (at that time, before_power is FB_BLANK_UNBLANK) then
> + Â Â Â Â* it changes that status to FB_BLANK_POWERDOWN to get lcd on.
> + Â Â Â Â*/
> + Â Â Â if (before_power == FB_BLANK_UNBLANK)
> + Â Â Â Â Â Â Â lcd->power = FB_BLANK_POWERDOWN;
> +
> + Â Â Â dev_dbg(&spi->dev, "before_power = %d\n", before_power);
> +
> + Â Â Â ret = ams369fg06_power(lcd, before_power);
> +
> + Â Â Â return ret;
> +}
> +#else
> +#define ams369fg06_suspend   NULL
> +#define ams369fg06_resume   ÂNULL
> +#endif
> +
> +void ams369fg06_shutdown(struct spi_device *spi)
> +{
> + Â Â Â struct ams369fg06 *lcd = dev_get_drvdata(&spi->dev);
> +
> + Â Â Â ams369fg06_power(lcd, FB_BLANK_POWERDOWN);
> +}
> +
> +static struct spi_driver ams369fg06_driver = {
> + Â Â Â .driver = {
> +        .name  = "ams369fg06",
> +        .bus  Â= &spi_bus_type,
> + Â Â Â Â Â Â Â .owner Â= THIS_MODULE,
> + Â Â Â },
> +    .probe     Â= ams369fg06_probe,
> +    .remove     = __devexit_p(ams369fg06_remove),
> +    .shutdown    = ams369fg06_shutdown,
> +    .suspend    Â= ams369fg06_suspend,
> +    .resume     = ams369fg06_resume,
> +};
> +
> +static int __init ams369fg06_init(void)
> +{
> + Â Â Â return spi_register_driver(&ams369fg06_driver);
> +}
> +
> +static void __exit ams369fg06_exit(void)
> +{
> + Â Â Â spi_unregister_driver(&ams369fg06_driver);
> +}
> +
> +module_init(ams369fg06_init);
> +module_exit(ams369fg06_exit);
> +
> +MODULE_AUTHOR("Jingoo Han <jg1.han@xxxxxxxxxxx>");
> +MODULE_DESCRIPTION("ams369fg06 LCD Driver");
> +MODULE_LICENSE("GPL");
> --
> 1.7.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/