drivers: ld9040 amoled driver support
Subsystems (2)
PATCH 1/1 drivers: ld9040 amoled driver support
This patch is ld9040 amoled panel driver.
I resend because there was no comment.
It is similar to s6e63m0 panel driver and use spi gpio to send panel information.
--- drivers/video/backlight/Kconfig | 8 + drivers/video/backlight/Makefile | 1 + drivers/video/backlight/ld9040.c | 927 ++++++++++++++++++++++++++++++++ drivers/video/backlight/ld9040_gamma.h | 203 +++++++ 4 files changed, 1139 insertions(+), 0 deletions(-) create mode 100644 drivers/video/backlight/ld9040.c create mode 100644 drivers/video/backlight/ld9040_gamma.h
drivers/video/backlight/Kconfig +8 -0
@@ -109,6 +109,14 @@ config LCD_S6E63M0 If you have an S6E63M0 LCD Panel, say Y to enable its LCD control driver. +config LCD_LD9040 + tristate "LD9040 AMOLED LCD Driver" + depends on SPI && BACKLIGHT_CLASS_DEVICE + default n + help + If you have an LD9040 Panel, say Y to enable its + control driver. + endif # LCD_CLASS_DEVICE #
drivers/video/backlight/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o 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_BACKLIGHT_CLASS_DEVICE) += backlight.o obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.o
drivers/video/backlight/ld9040.c new file +914 -0
914 lines not on this page · raw message
drivers/video/backlight/ld9040_gamma.h new file +203 -0
203 lines not on this page · raw message
Signature · 1 line
1.6.0.4
PATCH 1/1 drivers: ld9040 amoled driver support
Dear Richard Purdie,
I had sent ld9040 amoled driver patch file for several times with expectation for your comment. But, there was no comment about that. I was somewhat disappointed.
That patch is working well on my board and it is very smilar framework as s6e63m0 that already included mainline. Please reply with any comment.
I'm looking forward to your reply.
Thanks,
Donghwa Lee
Quoted 1,179 lines · Donghwa Lee
This patch is ld9040 amoled panel driver.
I resend because there was no comment.It is similar to s6e63m0 panel driver and use spi gpio to send panel information.
Signed-off-by Donghwa Lee <[email protected]>Signed-off-by Kyungmin Park <[email protected]>Signed-off-by Inki Dae <[email protected]>--- drivers/video/backlight/Kconfig | 8 + drivers/video/backlight/Makefile | 1 + drivers/video/backlight/ld9040.c | 927 ++++++++++++++++++++++++++++++++ drivers/video/backlight/ld9040_gamma.h | 203 +++++++ 4 files changed, 1139 insertions(+), 0 deletions(-) create mode 100644 drivers/video/backlight/ld9040.c create mode 100644 drivers/video/backlight/ld9040_gamma.hdrivers/video/backlight/Kconfig +8
-0@@ -109,6 +109,14 @@ config LCD_S6E63M0 If you have an S6E63M0 LCD Panel, say Y to enable its LCD control driver. +config LCD_LD9040 + tristate "LD9040 AMOLED LCD Driver" + depends on SPI && BACKLIGHT_CLASS_DEVICE + default n + help + If you have an LD9040 Panel, say Y to enable its + control driver. + endif # LCD_CLASS_DEVICE #drivers/video/backlight/Makefile +1
-0@@ -12,6 +12,7 @@ obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o 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_BACKLIGHT_CLASS_DEVICE) += backlight.o obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.odrivers/video/backlight/ld9040.c new file +914
-0@@ -0,0 +1,927 @@ +/* +* ld9040 AMOLED LCD panel driver. +* +* Author: Donghwa Lee <[email protected]> +* +* Derived from drivers/video/backlight/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/irq.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/lcd.h> +#include <linux/backlight.h> + +#include "ld9040_gamma.h" + +#define SLEEPMSEC 0x1000 +#define ENDDEF 0x2000 +#define DEFMASK 0xFF00 +#define COMMAND_ONLY 0xFE +#define DATA_ONLY 0xFF + +#define MIN_BRIGHTNESS 0 +#define MAX_BRIGHTNESS 24 +#define POWER_IS_ON (pwr) ((pwr) <= FB_BLANK_NORMAL) + +struct ld9040 { +struct device *dev; +struct spi_device *spi; +unsigned int power; +unsigned int gamma_mode; +unsigned int current_brightness; +unsigned int gamma_table_count; + +struct lcd_device *ld; +struct backlight_device *bd; +struct lcd_platform_data *lcd_pd; +}; + +static const unsigned short SEQ_SWRESET [] = { +0x01 ,COMMAND_ONLY , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_USER_SETTING [] = { +0xF0 ,0x5A , + +DATA_ONLY ,0x5A , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_ELVSS_ON [] = { +0xB1 ,0x0D , + +DATA_ONLY ,0x00 , +DATA_ONLY ,0x16 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_GTCON [] = { +0xF7 ,0x09 , + +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_PANEL_CONDITION [] = { +0xF8 ,0x05 , + +DATA_ONLY ,0x65 , +DATA_ONLY ,0x96 , +DATA_ONLY ,0x71 , +DATA_ONLY ,0x7D , +DATA_ONLY ,0x19 , +DATA_ONLY ,0x3B , +DATA_ONLY ,0x0D , +DATA_ONLY ,0x19 , +DATA_ONLY ,0x7E , +DATA_ONLY ,0x0D , +DATA_ONLY ,0xE2 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x7E , +DATA_ONLY ,0x7D , +DATA_ONLY ,0x07 , +DATA_ONLY ,0x07 , +DATA_ONLY ,0x20 , +DATA_ONLY ,0x20 , +DATA_ONLY ,0x20 , +DATA_ONLY ,0x02 , +DATA_ONLY ,0x02 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_GAMMA_SET1 [] = { +0xF9 ,0x00 , + +DATA_ONLY ,0xA7 , +DATA_ONLY ,0xB4 , +DATA_ONLY ,0xAE , +DATA_ONLY ,0xBF , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x91 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0xB2 , +DATA_ONLY ,0xB4 , +DATA_ONLY ,0xAA , +DATA_ONLY ,0xBB , +DATA_ONLY ,0x00 , +DATA_ONLY ,0xAC , +DATA_ONLY ,0x00 , +DATA_ONLY ,0xB3 , +DATA_ONLY ,0xB1 , +DATA_ONLY ,0xAA , +DATA_ONLY ,0xBC , +DATA_ONLY ,0x00 , +DATA_ONLY ,0xB3 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_GAMMA_CTRL [] = { +0xFB ,0x02 , + +DATA_ONLY ,0x5A , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_GAMMA_START [] = { +0xF9 ,COMMAND_ONLY , + +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_APON [] = { +0xF3 ,0x00 , + +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x0A , +DATA_ONLY ,0x02 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_DISPCTL [] = { +0xF2 ,0x02 , + +DATA_ONLY ,0x08 , +DATA_ONLY ,0x08 , +DATA_ONLY ,0x10 , +DATA_ONLY ,0x10 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_MANPWR [] = { +0xB0 ,0x04 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_PWR_CTRL [] = { +0xF4 ,0x0A , + +DATA_ONLY ,0x87 , +DATA_ONLY ,0x25 , +DATA_ONLY ,0x6A , +DATA_ONLY ,0x44 , +DATA_ONLY ,0x02 , +DATA_ONLY ,0x88 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_SLPOUT [] = { +0x11 ,COMMAND_ONLY , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_SLPIN [] = { +0x10 ,COMMAND_ONLY , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_DISPON [] = { +0x29 ,COMMAND_ONLY , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_DISPOFF [] = { +0x28 ,COMMAND_ONLY , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_VCI1_1ST_EN [] = { +0xF3 ,0x10 , + +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x02 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_VL1_EN [] = { +0xF3 ,0x11 , + +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x02 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_VL2_EN [] = { +0xF3 ,0x13 , + +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x02 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_VCI1_2ND_EN [] = { +0xF3 ,0x33 , + +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x02 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_VL3_EN [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x02 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_VREG1_AMP_EN [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0x01 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x02 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_VGH_AMP_EN [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0x11 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x02 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_VGL_AMP_EN [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0x31 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x02 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_VMOS_AMP_EN [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0xB1 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x03 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_VINT_AMP_EN [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0xF1 , +/* DATA_ONLY, 0x71, VMOS/VBL/VBH not used */ +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x03 , +/* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */ +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_VBH_AMP_EN [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0xF9 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x03 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_VBL_AMP_EN [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0xFD , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x03 , +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_GAM_AMP_EN [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0xFF , +/* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */ +DATA_ONLY ,0x00 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x03 , +/* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */ +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_SD_AMP_EN [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0xFF , +/* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */ +DATA_ONLY ,0x80 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x03 , +/* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */ +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_GLS_EN [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0xFF , +/* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */ +DATA_ONLY ,0x81 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x03 , +/* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */ +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_ELS_EN [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0xFF , +/* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */ +DATA_ONLY ,0x83 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x03 , +/* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */ +ENDDEF ,0x00 +}; + +static const unsigned short SEQ_EL_ON [] = { +0xF3 ,0x37 , + +DATA_ONLY ,0xFF , +/* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */ +DATA_ONLY ,0x87 , +DATA_ONLY ,0x00 , +DATA_ONLY ,0x03 , +/* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */ +ENDDEF ,0x00 +}; + +static int ld9040_spi_write_byte (struct ld9040 *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; + +spi_message_init (&msg); +spi_message_add_tail (&xfer, &msg); + +return spi_sync (lcd->spi, &msg); +} + +static int ld9040_spi_write (struct ld9040 *lcd,unsigned char address, +unsigned char command) +{ +int ret =0 ; + +if (address !=DATA_ONLY ) + ret =ld9040_spi_write_byte (lcd,0x0 , address); +if (command !=COMMAND_ONLY ) + ret =ld9040_spi_write_byte (lcd,0x1 , command); + +return ret; +} + +static int ld9040_panel_send_sequence (struct ld9040 *lcd, +const unsigned short *wbuf) +{ +int ret =0 , i =0 ; + +while ((wbuf[i] &DEFMASK ) !=ENDDEF ) { +if ((wbuf[i] &DEFMASK ) !=SLEEPMSEC ) { + ret =ld9040_spi_write (lcd, wbuf[i], wbuf[i+1 ]); +if (ret) +break ; + }else +udelay (wbuf[i+1 ]*1000 ); + i +=2 ; + } + +return ret; +} + +static int _ld9040_gamma_ctl (struct ld9040 *lcd,const unsigned int *gamma) +{ +unsigned int i =0 ; +int ret =0 ; + +/* start gamma table updating. */ + ret =ld9040_panel_send_sequence (lcd,SEQ_GAMMA_START ); +if (ret) { +dev_err (lcd->dev,"failed to disable gamma table updating.\n" ); + goto gamma_err; + } + +for (i =0 ; i <GAMMA_TABLE_COUNT ; i++) { + ret =ld9040_spi_write (lcd,DATA_ONLY , gamma[i]); +if (ret) { +dev_err (lcd->dev,"failed to set gamma table.\n" ); + goto gamma_err; + } + } + +/* update gamma table. */ + ret =ld9040_panel_send_sequence (lcd,SEQ_GAMMA_CTRL ); +if (ret) +dev_err (lcd->dev,"failed to update gamma table.\n" ); + +gamma_err: +return ret; +} + +static int ld9040_gamma_ctl (struct ld9040 *lcd,int gamma) +{ +int ret =0 ; + + ret =_ld9040_gamma_ctl (lcd, gamma_table.gamma_22_table[gamma]); + +return ret; +} + + +static int ld9040_ldi_init (struct ld9040 *lcd) +{ +int ret, i; +const unsigned short *init_seq[] = { +SEQ_USER_SETTING , +SEQ_PANEL_CONDITION , +SEQ_DISPCTL , +SEQ_MANPWR , +SEQ_PWR_CTRL , +SEQ_ELVSS_ON , +SEQ_GTCON , +SEQ_GAMMA_SET1 , +SEQ_GAMMA_CTRL , +SEQ_SLPOUT , + }; + +for (i =0 ; i <ARRAY_SIZE (init_seq); i++) { + ret =ld9040_panel_send_sequence (lcd, init_seq[i]); +/* workaround: minimum delay time for transferring CMD */ +udelay (300 ); +if (ret) +break ; + } + +return ret; +} + +static int ld9040_ldi_enable (struct ld9040 *lcd) +{ +int ret =0 ; + + ret =ld9040_panel_send_sequence (lcd,SEQ_DISPON ); + +return ret; +} + +static int ld9040_ldi_disable (struct ld9040 *lcd) +{ +int ret; + + ret =ld9040_panel_send_sequence (lcd,SEQ_DISPOFF ); + ret =ld9040_panel_send_sequence (lcd,SEQ_SLPIN ); + +return ret; +} + +static int ld9040_power_on (struct ld9040 *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 ; + } + +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 =ld9040_ldi_init (lcd); +if (ret) { +dev_err (lcd->dev,"failed to initialize ldi.\n" ); +return ret; + } + + ret =ld9040_ldi_enable (lcd); +if (ret) { +dev_err (lcd->dev,"failed to enable ldi.\n" ); +return ret; + } + +return 0 ; +} + +static int ld9040_power_off (struct ld9040 *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 =ld9040_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 ld9040_power (struct ld9040 *lcd,int power) +{ +int ret =0 ; + +if (POWER_IS_ON (power) && !POWER_IS_ON (lcd->power)) + ret =ld9040_power_on (lcd); +else if (!POWER_IS_ON (power) &&POWER_IS_ON (lcd->power)) + ret =ld9040_power_off (lcd); + +if (!ret) + lcd->power = power; + +return ret; +} + +static int ld9040_set_power (struct lcd_device *ld,int power) +{ +struct ld9040 *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 ld9040_power (lcd, power); +} + +static int ld9040_get_power (struct lcd_device *ld) +{ +struct ld9040 *lcd =lcd_get_data (ld); + +return lcd->power; +} + +static int ld9040_get_brightness (struct backlight_device *bd) +{ +return bd->props.brightness; +} + +static int ld9040_set_brightness (struct backlight_device *bd) +{ +int ret =0 , brightness = bd->props.brightness; +struct ld9040 *lcd =bl_get_data (bd); + +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 =ld9040_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 ld9040_lcd_ops = { + .set_power = ld9040_set_power, + .get_power = ld9040_get_power, +}; + +static const struct backlight_ops ld9040_backlight_ops = { + .get_brightness = ld9040_get_brightness, + .update_status = ld9040_set_brightness, +}; + +static ssize_t ld9040_sysfs_show_gamma_mode (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct ld9040 *lcd =dev_get_drvdata (dev); +char temp[10 ]; + +switch (lcd->gamma_mode) { +case 0 : +sprintf (temp,"2.2 mode\n" ); +strcat (buf, temp); +break ; +default : +dev_info (dev,"gamma mode could be 0:2.2\n" ); +break ; + } + +return strlen (buf); +} + +static ssize_t ld9040_sysfs_store_gamma_mode (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct ld9040 *lcd =dev_get_drvdata (dev); +struct backlight_device *bd =NULL ; +int brightness, rc; + + rc =strict_strtoul (buf,0 , (unsigned long *)&lcd->gamma_mode); +if (rc <0 ) +return rc; + + bd = lcd->bd; + + brightness = bd->props.brightness; + +switch (lcd->gamma_mode) { +case 0 : +_ld9040_gamma_ctl (lcd, gamma_table.gamma_22_table[brightness]); +break ; +default : +dev_info (dev,"gamma mode could be 0:2.2\n" ); +_ld9040_gamma_ctl (lcd, gamma_table.gamma_22_table[brightness]); +break ; + } +return len; +} + +static DEVICE_ATTR(gamma_mode, 0644, + ld9040_sysfs_show_gamma_mode, ld9040_sysfs_store_gamma_mode); + +static ssize_t ld9040_sysfs_show_gamma_table (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct ld9040 *lcd =dev_get_drvdata (dev); +char temp[3 ]; + +sprintf (temp,"%d\n" , lcd->gamma_table_count); +strcpy (buf, temp); + +return strlen (buf); +} + +static DEVICE_ATTR(gamma_table, 0644, + ld9040_sysfs_show_gamma_table, NULL); + +static int ld9040_probe (struct spi_device *spi) +{ +int ret =0 ; +struct ld9040 *lcd =NULL ; +struct lcd_device *ld =NULL ; +struct backlight_device *bd =NULL ; + + lcd =kzalloc (sizeof (struct ld9040 ),GFP_KERNEL ); +if (!lcd) +return -ENOMEM ; + +/* ld9040 lcd panel uses 3-wire 9bits SPI Mode. */ + spi->bits_per_word =9 ; + + 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 = (struct lcd_platform_data *)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 ("ld9040" , &spi->dev, lcd, &ld9040_lcd_ops); +if (IS_ERR (ld)) { + ret =PTR_ERR (ld); + goto out_free_lcd; + } + + lcd->ld = ld; + + bd =backlight_device_register ("ld9040-bl" , &spi->dev, + lcd, &ld9040_backlight_ops,NULL ); +if (IS_ERR (ld)) { + ret =PTR_ERR (ld); + goto out_free_lcd; + } + + bd->props.max_brightness =MAX_BRIGHTNESS ; + bd->props.brightness =MAX_BRIGHTNESS ; + lcd->bd = bd; + +/* +* it gets gamma table count available so it gets user +* know that. +*/ + lcd->gamma_table_count = +sizeof (gamma_table) / (MAX_GAMMA_LEVEL *sizeof (int )); + + ret =device_create_file (&(spi->dev), &dev_attr_gamma_mode); +if (ret <0 ) +dev_err (&(spi->dev),"failed to add sysfs entries\n" ); + + ret =device_create_file (&(spi->dev), &dev_attr_gamma_table); +if (ret <0 ) +dev_err (&(spi->dev),"failed to add sysfs entries\n" ); + +/* +* if lcd panel was on from bootloader like u-boot then +* do not lcd on. +*/ +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 ; + +ld9040_power (lcd,FB_BLANK_UNBLANK ); + }else + lcd->power =FB_BLANK_UNBLANK ; + +dev_set_drvdata (&spi->dev, lcd); + +dev_info (&spi->dev,"ld9040 panel driver has been probed.\n" ); +return 0 ; + +out_free_lcd: +kfree (lcd); +return ret; +} + +static int __devexit ld9040_remove(struct spi_device *spi) +{ +struct ld9040 *lcd =dev_get_drvdata (&spi->dev); + +ld9040_power (lcd,FB_BLANK_POWERDOWN ); +lcd_device_unregister (lcd->ld); +kfree (lcd); + +return 0 ; +} + +#if defined(CONFIG_PM ) +unsigned int beforepower; + +static int ld9040_suspend (struct spi_device *spi,pm_message_t mesg) +{ +int ret =0 ; +struct ld9040 *lcd =dev_get_drvdata (&spi->dev); + +dev_dbg (&spi->dev,"lcd->power = %d\n" , lcd->power); + + beforepower = lcd->power; + +/* +* when lcd panel is suspend, lcd panel becomes off +* regardless of status. +*/ + ret =ld9040_power (lcd,FB_BLANK_POWERDOWN ); + +return ret; +} + +static int ld9040_resume (struct spi_device *spi) +{ +int ret =0 ; +struct ld9040 *lcd =dev_get_drvdata (&spi->dev); + +/* +* after suspended, if lcd panel status is FB_BLANK_UNBLANK +* (at that time, power is FB_BLANK_UNBLANK) then +* it changes that status to FB_BLANK_POWERDOWN to get lcd on. +*/ +if (beforepower ==FB_BLANK_UNBLANK ) + lcd->power =FB_BLANK_POWERDOWN ; + +dev_dbg (&spi->dev,"power = %d\n" , beforepower); + + ret =ld9040_power (lcd, beforepower); + +return ret; +} +#else +#define ld9040_suspend NULL +#define ld9040_resume NULL +#endif + +/* Power down all displays on reboot, poweroff or halt. */ +static void ld9040_shutdown (struct spi_device *spi) +{ +struct ld9040 *lcd =dev_get_drvdata (&spi->dev); + +ld9040_power (lcd,FB_BLANK_POWERDOWN ); +} + +static struct spi_driver ld9040_driver = { + .driver = { + .name ="ld9040" , + .bus = &spi_bus_type, + .owner =THIS_MODULE , + }, + .probe = ld9040_probe, + .remove =__devexit_p (ld9040_remove), + .shutdown = ld9040_shutdown, + .suspend = ld9040_suspend, + .resume = ld9040_resume, +}; + +static int __init ld9040_init (void ) +{ +return spi_register_driver (&ld9040_driver); +} + +static void __exit ld9040_exit(void) +{ +spi_unregister_driver (&ld9040_driver); +} + +module_init (ld9040_init); +module_exit (ld9040_exit); + +MODULE_AUTHOR ("Donghwa Lee <[email protected]>" ); +MODULE_DESCRIPTION ("ld9040 LCD Driver" ); +MODULE_LICENSE ("GPL" ); +drivers/video/backlight/ld9040_gamma.h new file +203
-0@@ -0,0 +1,203 @@ +/* linux/drivers/video/samsung/ld9040_brightness.h +* +* Gamma level definitions. +* +* Copyright (c) 2009 Samsung Electronics +* InKi Dae <[email protected]> +* +* 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. +*/ + +#ifndef _ld9040_BRIGHTNESS_H +#define _ld9040_BRIGHTNESS_H + +#define MAX_GAMMA_LEVEL 25 +#define GAMMA_TABLE_COUNT 21 + +/* gamma value: 2.2 */ +static const unsigned int ld9040_22_300[] = { +0x00 ,0xa7 ,0xb4 ,0xae ,0xbf ,0x00 ,0x91 , +0x00 ,0xb2 ,0xb4 ,0xaa ,0xbb ,0x00 ,0xac , +0x00 ,0xb3 ,0xb1 ,0xaa ,0xbc ,0x00 ,0xb3 +}; + +static const unsigned int ld9040_22_290[] = { +0x00 ,0xa9 ,0xb7 ,0xae ,0xbd ,0x00 ,0x89 , +0x00 ,0xb7 ,0xb6 ,0xa8 ,0xba ,0x00 ,0xa4 , +0x00 ,0xb1 ,0xb4 ,0xaa ,0xbb ,0x00 ,0xaa +}; + +static const unsigned int ld9040_22_280[] = { +0x00 ,0xa9 ,0xb6 ,0xad ,0xbf ,0x00 ,0x86 , +0x00 ,0xb8 ,0xb5 ,0xa8 ,0xbc ,0x00 ,0xa0 , +0x00 ,0xb3 ,0xb3 ,0xa9 ,0xbc ,0x00 ,0xa7 +}; + +static const unsigned int ld9040_22_270[] = { +0x00 ,0xa8 ,0xb8 ,0xae ,0xbe ,0x00 ,0x84 , +0x00 ,0xb9 ,0xb7 ,0xa8 ,0xbc ,0x00 ,0x9d , +0x00 ,0xb2 ,0xb5 ,0xaa ,0xbc ,0x00 ,0xa4 + +}; +static const unsigned int ld9040_22_260[] = { +0x00 ,0xa4 ,0xb8 ,0xb0 ,0xbf ,0x00 ,0x80 , +0x00 ,0xb8 ,0xb6 ,0xaa ,0xbc ,0x00 ,0x9a , +0x00 ,0xb0 ,0xb5 ,0xab ,0xbd ,0x00 ,0xa0 +}; + +static const unsigned int ld9040_22_250[] = { +0x00 ,0xa4 ,0xb9 ,0xaf ,0xc1 ,0x00 ,0x7d , +0x00 ,0xb9 ,0xb6 ,0xaa ,0xbb ,0x00 ,0x97 , +0x00 ,0xb1 ,0xb5 ,0xaa ,0xbf ,0x00 ,0x9d +}; + +static const unsigned int ld9040_22_240[] = { +0x00 ,0xa2 ,0xb9 ,0xaf ,0xc2 ,0x00 ,0x7a , +0x00 ,0xb9 ,0xb7 ,0xaa ,0xbd ,0x00 ,0x94 , +0x00 ,0xb0 ,0xb5 ,0xab ,0xbf ,0x00 ,0x9a +}; + +static const unsigned int ld9040_22_230[] = { +0x00 ,0xa0 ,0xb9 ,0xaf ,0xc3 ,0x00 ,0x77 , +0x00 ,0xb9 ,0xb7 ,0xab ,0xbe ,0x00 ,0x90 , +0x00 ,0xb0 ,0xb6 ,0xab ,0xbf ,0x00 ,0x97 +}; + +static const unsigned int ld9040_22_220[] = { +0x00 ,0x9e ,0xba ,0xb0 ,0xc2 ,0x00 ,0x75 , +0x00 ,0xb9 ,0xb8 ,0xab ,0xbe ,0x00 ,0x8e , +0x00 ,0xb0 ,0xb6 ,0xac ,0xbf ,0x00 ,0x94 +}; + +static const unsigned int ld9040_22_210[] = { +0x00 ,0x9c ,0xb9 ,0xb0 ,0xc4 ,0x00 ,0x72 , +0x00 ,0xb8 ,0xb8 ,0xac ,0xbf ,0x00 ,0x8a , +0x00 ,0xb0 ,0xb6 ,0xac ,0xc0 ,0x00 ,0x91 +}; + +static const unsigned int ld9040_22_200[] = { +0x00 ,0x9a ,0xba ,0xb1 ,0xc4 ,0x00 ,0x6f , +0x00 ,0xb8 ,0xb8 ,0xad ,0xc0 ,0x00 ,0x86 , +0x00 ,0xb0 ,0xb7 ,0xad ,0xc0 ,0x00 ,0x8d +}; + +static const unsigned int ld9040_22_190[] = { +0x00 ,0x97 ,0xba ,0xb2 ,0xc5 ,0x00 ,0x6c , +0x00 ,0xb8 ,0xb8 ,0xae ,0xc1 ,0x00 ,0x82 , +0x00 ,0xb0 ,0xb6 ,0xae ,0xc2 ,0x00 ,0x89 +}; + +static const unsigned int ld9040_22_180[] = { +0x00 ,0x93 ,0xba ,0xb3 ,0xc5 ,0x00 ,0x69 , +0x00 ,0xb8 ,0xb9 ,0xae ,0xc1 ,0x00 ,0x7f , +0x00 ,0xb0 ,0xb6 ,0xae ,0xc3 ,0x00 ,0x85 +}; + +static const unsigned int ld9040_22_170[] = { +0x00 ,0x8b ,0xb9 ,0xb3 ,0xc7 ,0x00 ,0x65 , +0x00 ,0xb7 ,0xb8 ,0xaf ,0xc3 ,0x00 ,0x7a , +0x00 ,0x80 ,0xb6 ,0xae ,0xc4 ,0x00 ,0x81 +}; + +static const unsigned int ld9040_22_160[] = { +0x00 ,0x89 ,0xba ,0xb3 ,0xc8 ,0x00 ,0x62 , +0x00 ,0xb6 ,0xba ,0xaf ,0xc3 ,0x00 ,0x76 , +0x00 ,0xaf ,0xb7 ,0xae ,0xc4 ,0x00 ,0x7e +}; + +static const unsigned int ld9040_22_150[] = { +0x00 ,0x82 ,0xba ,0xb4 ,0xc7 ,0x00 ,0x5f , +0x00 ,0xb5 ,0xba ,0xb0 ,0xc3 ,0x00 ,0x72 , +0x00 ,0xae ,0xb8 ,0xb0 ,0xc3 ,0x00 ,0x7a +}; + +static const unsigned int ld9040_22_140[] = { +0x00 ,0x7b ,0xbb ,0xb4 ,0xc8 ,0x00 ,0x5b , +0x00 ,0xb5 ,0xba ,0xb1 ,0xc4 ,0x00 ,0x6e , +0x00 ,0xae ,0xb9 ,0xb0 ,0xc5 ,0x00 ,0x75 +}; + +static const unsigned int ld9040_22_130[] = { +0x00 ,0x71 ,0xbb ,0xb5 ,0xc8 ,0x00 ,0x57 , +0x00 ,0xb5 ,0xbb ,0xb0 ,0xc5 ,0x00 ,0x6a , +0x00 ,0xae ,0xb9 ,0xb1 ,0xc6 ,0x00 ,0x70 +}; + +static const unsigned int ld9040_22_120[] = { +0x00 ,0x47 ,0xba ,0xb6 ,0xca ,0x00 ,0x53 , +0x00 ,0xb5 ,0xbb ,0xb3 ,0xc6 ,0x00 ,0x65 , +0x00 ,0xae ,0xb8 ,0xb3 ,0xc7 ,0x00 ,0x6c +}; + +static const unsigned int ld9040_22_110[] = { +0x00 ,0x13 ,0xbb ,0xb7 ,0xca ,0x00 ,0x4f , +0x00 ,0xb4 ,0xbb ,0xb3 ,0xc7 ,0x00 ,0x60 , +0x00 ,0xad ,0xb8 ,0xb4 ,0xc7 ,0x00 ,0x67 +}; + +static const unsigned int ld9040_22_100[] = { +0x00 ,0x13 ,0xba ,0xb8 ,0xcb ,0x00 ,0x4b , +0x00 ,0xb3 ,0xbc ,0xb4 ,0xc7 ,0x00 ,0x5c , +0x00 ,0xac ,0xb8 ,0xb4 ,0xc8 ,0x00 ,0x62 +}; + +static const unsigned int ld9040_22_90[] = { +0x00 ,0x13 ,0xb9 ,0xb8 ,0xcd ,0x00 ,0x46 , +0x00 ,0xb1 ,0xbc ,0xb5 ,0xc8 ,0x00 ,0x56 , +0x00 ,0xaa ,0xb8 ,0xb4 ,0xc9 ,0x00 ,0x5d +}; + +static const unsigned int ld9040_22_80[] = { +0x00 ,0x13 ,0xba ,0xb9 ,0xcd ,0x00 ,0x41 , +0x00 ,0xb0 ,0xbe ,0xb5 ,0xc9 ,0x00 ,0x51 , +0x00 ,0xa9 ,0xb9 ,0xb5 ,0xca ,0x00 ,0x57 +}; + +static const unsigned int ld9040_22_70[] = { +0x00 ,0x13 ,0xb9 ,0xb9 ,0xd0 ,0x00 ,0x3c , +0x00 ,0xaf ,0xbf ,0xb6 ,0xcb ,0x00 ,0x4b , +0x00 ,0xa8 ,0xb9 ,0xb5 ,0xcc ,0x00 ,0x52 +}; + +static const unsigned int ld9040_22_50[] = { +0x00 ,0x13 ,0xb2 ,0xba ,0xd2 ,0x00 ,0x30 , +0x00 ,0xaf ,0xc0 ,0xb8 ,0xcd ,0x00 ,0x3d , +0x00 ,0xa8 ,0xb8 ,0xb7 ,0xcd ,0x00 ,0x44 +}; + +struct ld9040_gamma { +unsigned int *gamma_22_table[MAX_GAMMA_LEVEL ]; +}; + +static struct ld9040_gamma gamma_table = { + .gamma_22_table[0 ] = (unsigned int *)&ld9040_22_50, + .gamma_22_table[1 ] = (unsigned int *)&ld9040_22_70, + .gamma_22_table[2 ] = (unsigned int *)&ld9040_22_80, + .gamma_22_table[3 ] = (unsigned int *)&ld9040_22_90, + .gamma_22_table[4 ] = (unsigned int *)&ld9040_22_100, + .gamma_22_table[5 ] = (unsigned int *)&ld9040_22_110, + .gamma_22_table[6 ] = (unsigned int *)&ld9040_22_120, + .gamma_22_table[7 ] = (unsigned int *)&ld9040_22_130, + .gamma_22_table[8 ] = (unsigned int *)&ld9040_22_140, + .gamma_22_table[9 ] = (unsigned int *)&ld9040_22_150, + .gamma_22_table[10 ] = (unsigned int *)&ld9040_22_160, + .gamma_22_table[11 ] = (unsigned int *)&ld9040_22_170, + .gamma_22_table[12 ] = (unsigned int *)&ld9040_22_180, + .gamma_22_table[13 ] = (unsigned int *)&ld9040_22_190, + .gamma_22_table[14 ] = (unsigned int *)&ld9040_22_200, + .gamma_22_table[15 ] = (unsigned int *)&ld9040_22_210, + .gamma_22_table[16 ] = (unsigned int *)&ld9040_22_220, + .gamma_22_table[17 ] = (unsigned int *)&ld9040_22_230, + .gamma_22_table[18 ] = (unsigned int *)&ld9040_22_240, + .gamma_22_table[19 ] = (unsigned int *)&ld9040_22_250, + .gamma_22_table[20 ] = (unsigned int *)&ld9040_22_260, + .gamma_22_table[21 ] = (unsigned int *)&ld9040_22_270, + .gamma_22_table[22 ] = (unsigned int *)&ld9040_22_280, + .gamma_22_table[23 ] = (unsigned int *)&ld9040_22_290, + .gamma_22_table[24 ] = (unsigned int *)&ld9040_22_300, +}; + +#endif +
PATCH 1/1 drivers: ld9040 amoled driver support
Quoted 8 lines · Donghwa Lee
Dear Richard Purdie,
I had sent ld9040 amoled driver patch file for several times with expectation for your comment. But, there was no comment about that. I was somewhat disappointed.
That patch is working well on my board and it is very smilar framework as s6e63m0 that already included mainline. Please reply with any comment.
I'm looking forward to your reply.
The backlight stuff seems to be effectively abandoned at this point, and it's not clear if there is anyone else willing to maintain it. For these sorts of situations patches are generally best fed through -mm, which provides some time for review from unresponsive maintainers as well as leading towards a merge path.
I'm not sure what the best way to handle the backlight stuff is however, in that much of it keeps popping up on the fbdev list and each time we either need to poke Richard multiple times or shuffle it off to Andrew. This also understandably leads to frustration for people submitting new drivers in that the submission path they are directed towards via MAINTAINERS ends up largely being a black hole.
For now the easiest option is still likely to be just making Andrew aware of it, while gradually leaning towards -mm as the primary path for backlight patches.
PATCH 1/1 drivers: ld9040 amoled driver support
Quoted 3 lines · On Wed, 19 Jan 2011 12:25:18 +0900 Paul Mundt <[email protected]> wrote:
For now the easiest option is still likely to be just making Andrew aware of it, while gradually leaning towards -mm as the primary path for backlight patches.
The current status of backlight (and drivers/leds/) it that I review (lol) and merge the patches and send them upstream. I cc Richard on them all and he reviews them if he has the time available.
PATCH 1/1 drivers: ld9040 amoled driver support
Hi, Andrew and Paul
A month had elapsed since my patch was posted in mainline, but, there is no review about it. So I make a request again to review it.
As I explained before, ld9040 driver is very simple driver to control amoled lcd panel. And it is very similar with s6e63m0 amoled driver, the difference is nothing but each specific registers value.
Please review it.
Thank you,
Donghwa Lee
PATCH 1/1 drivers: ld9040 amoled driver support
In reply to Donghwa LeeQuoted 10 lines · On Thu, 13 Jan 2011 13:40:28 +0900 Donghwa Lee <[email protected]> wrote:
This patch is ld9040 amoled panel driver.
I resend because there was no comment.It is similar to s6e63m0 panel driver and use spi gpio to send panel information.
...
+#define
POWER_IS_ON(pwr)((pwr) <=FB_BLANK_NORMAL)
This could and should be implemented as a regular lower-case C function.
Quoted 7 lines
drivers/video/backlight/ld9040.c new file +7
-0+struct ld9040 { +struct device *dev; +struct spi_device *spi; +unsigned int power; +unsigned int gamma_mode; +unsigned int current_brightness; +unsigned int gamma_table_count;
drivers/video/backlight/ld9040.c line 62
Quoted 10 lines
drivers/video/backlight/ld9040.c new file +10
-0+ +struct lcd_device *ld; +struct backlight_device *bd; +struct lcd_platform_data *lcd_pd; +}; + +static const unsigned short SEQ_SWRESET [] = { +0x01 ,COMMAND_ONLY , +ENDDEF ,0x00 +};
It's strange that all these tables have upper-case names. Unless there's some special reason for doing it this way, please make them regular lower-case identifiers.
Quoted 8 lines
...
drivers/video/backlight/ld9040.c new file +5
-0+static int ld9040_ldi_init (struct ld9040 *lcd) +{ +int ret, i; +const unsigned short *init_seq[] = { +SEQ_USER_SETTING ,
drivers/video/backlight/ld9040.c line 495
Quoted 10 lines
drivers/video/backlight/ld9040.c new file +10
-0+SEQ_PANEL_CONDITION , +SEQ_DISPCTL , +SEQ_MANPWR , +SEQ_PWR_CTRL , +SEQ_ELVSS_ON , +SEQ_GTCON , +SEQ_GAMMA_SET1 , +SEQ_GAMMA_CTRL , + SEQ_SLPOUT, + };
Make this table static so the compiler doesn't rebuild it on the stack each time the function is called. The compiler probably already performs that optimisation, but it doesn't hurt to be explicit.
Quoted 14 lines
drivers/video/backlight/ld9040.c new file +11
-0+for (i =0 ; i <ARRAY_SIZE (init_seq); i++) { + ret =ld9040_panel_send_sequence (lcd, init_seq[i]); +/* workaround: minimum delay time for transferring CMD */ +udelay (300 ); +if (ret) +break ; + } + +return ret; +} +
drivers/video/backlight/ld9040.c
Quoted 10 lines
drivers/video/backlight/ld9040.c new file +10
-0+static ssize_t ld9040_sysfs_show_gamma_mode (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct ld9040 *lcd =dev_get_drvdata (dev); +char temp[10 ]; + +switch (lcd->gamma_mode) { +case 0 : +sprintf (temp,"2.2 mode\n" ); +strcat (buf, temp);
Could do sprintf(buf + strlen(buf)) and eliminate temp[].
Quoted 8 lines
drivers/video/backlight/ld9040.c new file +8
-0+break ; +default : +dev_info (dev,"gamma mode could be 0:2.2\n" ); +break ; + } + +return strlen (buf); +}
drivers/video/backlight/ld9040.c line 694
Quoted 10 lines
drivers/video/backlight/ld9040.c new file +10
-0+ +static ssize_t ld9040_sysfs_store_gamma_mode (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct ld9040 *lcd =dev_get_drvdata (dev); +struct backlight_device *bd =NULL ; +int brightness, rc; + + rc =strict_strtoul (buf,0 , (unsigned long *)&lcd->gamma_mode);
That's a bug. gamma_mode has type int, which is 4 bytes, but you're telling strict_strtoul() to write eight bytes - it will corrupt *lcd on a 64-bit machine. Use a temporary.
Quoted 20 lines
drivers/video/backlight/ld9040.c new file +20
-0+if (rc <0 ) +return rc; + + bd = lcd->bd; + + brightness = bd->props.brightness; + +switch (lcd->gamma_mode) { +case 0 : +_ld9040_gamma_ctl (lcd, gamma_table.gamma_22_table[brightness]); +break ; +default : +dev_info (dev,"gamma mode could be 0:2.2\n" ); +_ld9040_gamma_ctl (lcd, gamma_table.gamma_22_table[brightness]); +break ; + } +return len; +} + +static DEVICE_ATTR(gamma_mode, 0644,
drivers/video/backlight/ld9040.c line 724
Quoted 10 lines
drivers/video/backlight/ld9040.c new file +10
-0+ ld9040_sysfs_show_gamma_mode, ld9040_sysfs_store_gamma_mode); + +static ssize_t ld9040_sysfs_show_gamma_table (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct ld9040 *lcd =dev_get_drvdata (dev); +char temp[3 ]; + +sprintf (temp,"%d\n" , lcd->gamma_table_count); +strcpy (buf, temp);
sprintf(buf + strlen(buf), remove temp[].
Quoted 20 lines
drivers/video/backlight/ld9040.c new file +20
-0+return strlen (buf); +} + +static DEVICE_ATTR(gamma_table, 0644, + ld9040_sysfs_show_gamma_table, NULL); + +static int ld9040_probe (struct spi_device *spi) +{ +int ret =0 ; +struct ld9040 *lcd =NULL ; +struct lcd_device *ld =NULL ; +struct backlight_device *bd =NULL ; + + lcd =kzalloc (sizeof (struct ld9040 ),GFP_KERNEL ); +if (!lcd) +return -ENOMEM ; + +/* ld9040 lcd panel uses 3-wire 9bits SPI Mode. */ + spi->bits_per_word =9 ; +
drivers/video/backlight/ld9040.c line 755
Quoted 10 lines
drivers/video/backlight/ld9040.c new file +10
-0+ 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 = (struct lcd_platform_data *)spi->dev.platform_data;
Unneeded and undesirable typecast.
Quoted 28 lines
drivers/video/backlight/ld9040.c new file +28
-0+if (!lcd->lcd_pd) { +dev_err (&spi->dev,"platform data is NULL.\n" ); + goto out_free_lcd; + } + + ld =lcd_device_register ("ld9040" , &spi->dev, lcd, &ld9040_lcd_ops); +if (IS_ERR (ld)) { + ret =PTR_ERR (ld); + goto out_free_lcd; + } + + lcd->ld = ld; + + bd =backlight_device_register ("ld9040-bl" , &spi->dev, + lcd, &ld9040_backlight_ops,NULL ); +if (IS_ERR (ld)) { + ret =PTR_ERR (ld); + goto out_free_lcd; + } + + bd->props.max_brightness =MAX_BRIGHTNESS ; + bd->props.brightness =MAX_BRIGHTNESS ; + lcd->bd = bd; + +/* +* it gets gamma table count available so it gets user +* know that. +*/
drivers/video/backlight/ld9040.c line 793
Quoted 10 lines
drivers/video/backlight/ld9040.c new file +10
-0+ lcd->gamma_table_count = +sizeof (gamma_table) / (MAX_GAMMA_LEVEL *sizeof (int )); + + ret =device_create_file (&(spi->dev), &dev_attr_gamma_mode); +if (ret <0 ) +dev_err (&(spi->dev),"failed to add sysfs entries\n" ); + + ret =device_create_file (&(spi->dev), &dev_attr_gamma_table); +if (ret <0 ) +dev_err (&(spi->dev),"failed to add sysfs entries\n" );
These errors are just ignored. It would be better to perform cleanup and to then return the correct errno.
Quoted 29 lines
drivers/video/backlight/ld9040.c new file +29
-0+/* +* if lcd panel was on from bootloader like u-boot then +* do not lcd on. +*/ +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 ; + +ld9040_power (lcd,FB_BLANK_UNBLANK ); + }else + lcd->power =FB_BLANK_UNBLANK ; + +dev_set_drvdata (&spi->dev, lcd); + +dev_info (&spi->dev,"ld9040 panel driver has been probed.\n" ); +return 0 ; + +out_free_lcd: +kfree (lcd); +return ret; +} + +static int __devexit ld9040_remove(struct spi_device *spi) +{ +struct ld9040 *lcd =dev_get_drvdata (&spi->dev);
drivers/video/backlight/ld9040.c line 833
Quoted 10 lines
drivers/video/backlight/ld9040.c new file +10
-0+ +ld9040_power (lcd,FB_BLANK_POWERDOWN ); +lcd_device_unregister (lcd->ld); +kfree (lcd); + +return 0 ; +} + +#if defined(CONFIG_PM ) +unsigned int beforepower;
This should be static.
Also, it shouldn't exist. Its presence assumes that there will only be one device controlled by this driver. It should be moved into the per-device data area.
drivers/video/backlight/ld9040_gamma.h line 174
Quoted 8 lines
...
drivers/video/backlight/ld9040_gamma.h new file +5
-0+struct ld9040_gamma { +unsigned int *gamma_22_table[MAX_GAMMA_LEVEL ]; +}; + +static struct ld9040_gamma gamma_table = {
Could do
static struct ld9040_gamma {
unsigned int *gamma_22_table[MAX_GAMMA_LEVEL];
} gamma_table = {here.
Quoted 18 lines
drivers/video/backlight/ld9040_gamma.h new file +18
-0+ .gamma_22_table[0] = (unsigned int *)&ld9040_22_50, + .gamma_22_table[1] = (unsigned int *)&ld9040_22_70, + .gamma_22_table[2] = (unsigned int *)&ld9040_22_80, + .gamma_22_table[3] = (unsigned int *)&ld9040_22_90, + .gamma_22_table[4] = (unsigned int *)&ld9040_22_100, + .gamma_22_table[5] = (unsigned int *)&ld9040_22_110, + .gamma_22_table[6] = (unsigned int *)&ld9040_22_120, + .gamma_22_table[7] = (unsigned int *)&ld9040_22_130, + .gamma_22_table[8] = (unsigned int *)&ld9040_22_140, + .gamma_22_table[9] = (unsigned int *)&ld9040_22_150, + .gamma_22_table[10] = (unsigned int *)&ld9040_22_160, + .gamma_22_table[11] = (unsigned int *)&ld9040_22_170, + .gamma_22_table[12] = (unsigned int *)&ld9040_22_180, + .gamma_22_table[13] = (unsigned int *)&ld9040_22_190, + .gamma_22_table[14] = (unsigned int *)&ld9040_22_200, + .gamma_22_table[15] = (unsigned int *)&ld9040_22_210, + .gamma_22_table[16] = (unsigned int *)&ld9040_22_220, + .gamma_22_table[17] = (unsigned int *)&ld9040_22_230,
drivers/video/backlight/ld9040_gamma.h line 202
Quoted 10 lines
drivers/video/backlight/ld9040_gamma.h new file +10
-0+ .gamma_22_table[18] = (unsigned int *)&ld9040_22_240, + .gamma_22_table[19] = (unsigned int *)&ld9040_22_250, + .gamma_22_table[20] = (unsigned int *)&ld9040_22_260, + .gamma_22_table[21] = (unsigned int *)&ld9040_22_270, + .gamma_22_table[22] = (unsigned int *)&ld9040_22_280, + .gamma_22_table[23] = (unsigned int *)&ld9040_22_290, + .gamma_22_table[24] = (unsigned int *)&ld9040_22_300, +}; + +#endif
Defining static tables in a header file is strange. It would be very wrong if that header was ever included by more than a single .c file, so why not just eliminate this file and move its contents into that .c file?
PATCH 1/1 drivers: ld9040 amoled driver support
Quoted 6 lines · Andrew Morton
Quoted 1 line · On Thu, 13 Jan 2011 13:40:28 +0900 Donghwa Lee <[email protected]> wrote:
+#define
POWER_IS_ON(pwr)((pwr) <=FB_BLANK_NORMAL)This could and should be implemented as a regular lower-case C function.
Ok, I will change to lower-case.
Quoted 9 lines
drivers/video/backlight/ld9040.c line 62
Quoted 5 lines
drivers/video/backlight/ld9040.c new file +5
-0+ +static const unsigned short SEQ_SWRESET [] = { +0x01 ,COMMAND_ONLY , +ENDDEF ,0x00 +};It's strange that all these tables have upper-case names. Unless there's some special reason for doing it this way, please make them regular lower-case identifiers.
It means specific register setting tables, but, on second thoughts, it is meaningless. I will change it.
Quoted 12 lines
Quoted 12 lines
...
drivers/video/backlight/ld9040.c new file +10
-0+static int ld9040_ldi_init (struct ld9040 *lcd) +{ +int ret, i; +const unsigned short *init_seq[] = { +SEQ_USER_SETTING , +SEQ_PANEL_CONDITION , +SEQ_DISPCTL , +SEQ_MANPWR , +SEQ_PWR_CTRL , +SEQ_ELVSS_ON ,
Quoted 9 lines
drivers/video/backlight/ld9040.c line 495
Quoted 5 lines
drivers/video/backlight/ld9040.c new file +5
-0+SEQ_GTCON , +SEQ_GAMMA_SET1 , +SEQ_GAMMA_CTRL , + SEQ_SLPOUT, + };Make this table static so the compiler doesn't rebuild it on the stack each time the function is called. The compiler probably already performs that optimisation, but it doesn't hurt to be explicit.
Ok, I will modify it.
Quoted 11 lines
+static
ssize_tld9040_sysfs_show_gamma_mode(struct device *dev,drivers/video/backlight/ld9040.c new file +9
-0+ struct device_attribute *attr, char *buf) +{ + struct ld9040 *lcd = dev_get_drvdata(dev); +char temp[10 ]; + +switch (lcd->gamma_mode) { +case 0 : +sprintf (temp,"2.2 mode\n" ); +strcat (buf, temp);Could do sprintf(buf + strlen(buf)) and eliminate temp[].
Current gamma table is only one, so I remove all about gamma mode.
Quoted 4 lines
Quoted 4 lines
drivers/video/backlight/ld9040.c new file +4
-0+static ssize_t ld9040_sysfs_store_gamma_mode (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{
Quoted 9 lines
drivers/video/backlight/ld9040.c line 694
Quoted 5 lines
drivers/video/backlight/ld9040.c new file +5
-0+struct ld9040 *lcd =dev_get_drvdata (dev); +struct backlight_device *bd =NULL ; +int brightness, rc; + + rc =strict_strtoul (buf,0 , (unsigned long *)&lcd->gamma_mode);That's a bug.
gamma_modehas type int, which is 4 bytes, but you're tellingstrict_strtoul()to write eight bytes - it will corrupt *lcd on a 64-bit machine. Use a temporary.
Current gamma table is only one, so I remove all about gamma mode.
Quoted 5 lines
Quoted 5 lines
drivers/video/backlight/ld9040.c new file +5
-0+ +static DEVICE_ATTR(gamma_mode, 0644, + ld9040_sysfs_show_gamma_mode, ld9040_sysfs_store_gamma_mode); + +static ssize_t ld9040_sysfs_show_gamma_table(struct device *dev,
Quoted 9 lines
drivers/video/backlight/ld9040.c line 724
Quoted 7 lines
drivers/video/backlight/ld9040.c new file +7
-0+ struct device_attribute *attr, char *buf) +{ + struct ld9040 *lcd = dev_get_drvdata(dev); +char temp[3 ]; + +sprintf (temp,"%d\n" , lcd->gamma_table_count); +strcpy (buf, temp);sprintf(buf + strlen(buf), remove temp[].
Current gamma table is only one, so I remove all about gamma mode.
Quoted 23 lines
Quoted 23 lines
drivers/video/backlight/ld9040.c new file +23
-0+return strlen (buf); +} + +static DEVICE_ATTR(gamma_table, 0644, + ld9040_sysfs_show_gamma_table, NULL); + +static int ld9040_probe (struct spi_device *spi) +{ +int ret =0 ; +struct ld9040 *lcd =NULL ; +struct lcd_device *ld =NULL ; +struct backlight_device *bd =NULL ; + + lcd =kzalloc (sizeof (struct ld9040 ),GFP_KERNEL ); +if (!lcd) +return -ENOMEM ; + +/* ld9040 lcd panel uses 3-wire 9bits SPI Mode. */ + spi->bits_per_word =9 ; + + ret =spi_setup (spi); +if (ret <0 ) { +dev_err (&spi->dev,"spi setup failed.\n" );
Quoted 9 lines
drivers/video/backlight/ld9040.c line 755
Quoted 7 lines
drivers/video/backlight/ld9040.c new file +7
-0+ goto out_free_lcd; + } + + lcd->spi = spi; + lcd->dev = &spi->dev; + + lcd->lcd_pd = (struct lcd_platform_data *)spi->dev.platform_data;Unneeded and undesirable typecast.
Ok, I will modify it.
Quoted 8 lines
Quoted 8 lines
drivers/video/backlight/ld9040.c new file +8
-0+/* +* it gets gamma table count available so it gets user +* know that. +*/ + lcd->gamma_table_count = +sizeof (gamma_table) / (MAX_GAMMA_LEVEL *sizeof (int )); + + ret =device_create_file (&(spi->dev), &dev_attr_gamma_mode);
Quoted 9 lines
drivers/video/backlight/ld9040.c line 793
Quoted 6 lines
drivers/video/backlight/ld9040.c new file +6
-0+if (ret <0 ) +dev_err (&(spi->dev),"failed to add sysfs entries\n" ); + + ret =device_create_file (&(spi->dev), &dev_attr_gamma_table); +if (ret <0 ) +dev_err (&(spi->dev),"failed to add sysfs entries\n" );These errors are just ignored. It would be better to perform cleanup and to then return the correct errno.
Above, creating sysfs node is unneeded. I will remove it.
Quoted 9 lines
drivers/video/backlight/ld9040.c line 833
Quoted 3 lines
drivers/video/backlight/ld9040.c new file +3
-0+ +#if defined(CONFIG_PM ) +unsigned int beforepower;This should be static.
Also, it shouldn't exist. Its presence assumes that there will only be one device controlled by this driver. It should be moved into the per-device data area.
Yes, you're right. beforepower variable is unneeded, I will remove it.
Quoted 9 lines
drivers/video/backlight/ld9040_gamma.h line 174
Quoted 7 lines
...
drivers/video/backlight/ld9040_gamma.h new file +5
-0+struct ld9040_gamma { +unsigned int *gamma_22_table[MAX_GAMMA_LEVEL ]; +}; + +static struct ld9040_gamma gamma_table = {Could do
Quoted 6 lines
static struct ld9040_gamma { unsigned int *gamma_22_table[MAX_GAMMA_LEVEL]; } gamma_table = {here.
Ok, I will move it.
Quoted 24 lines
Quoted 24 lines
drivers/video/backlight/ld9040_gamma.h new file +24
-0+ .gamma_22_table[0] = (unsigned int *)&ld9040_22_50, + .gamma_22_table[1] = (unsigned int *)&ld9040_22_70, + .gamma_22_table[2] = (unsigned int *)&ld9040_22_80, + .gamma_22_table[3] = (unsigned int *)&ld9040_22_90, + .gamma_22_table[4] = (unsigned int *)&ld9040_22_100, + .gamma_22_table[5] = (unsigned int *)&ld9040_22_110, + .gamma_22_table[6] = (unsigned int *)&ld9040_22_120, + .gamma_22_table[7] = (unsigned int *)&ld9040_22_130, + .gamma_22_table[8] = (unsigned int *)&ld9040_22_140, + .gamma_22_table[9] = (unsigned int *)&ld9040_22_150, + .gamma_22_table[10] = (unsigned int *)&ld9040_22_160, + .gamma_22_table[11] = (unsigned int *)&ld9040_22_170, + .gamma_22_table[12] = (unsigned int *)&ld9040_22_180, + .gamma_22_table[13] = (unsigned int *)&ld9040_22_190, + .gamma_22_table[14] = (unsigned int *)&ld9040_22_200, + .gamma_22_table[15] = (unsigned int *)&ld9040_22_210, + .gamma_22_table[16] = (unsigned int *)&ld9040_22_220, + .gamma_22_table[17] = (unsigned int *)&ld9040_22_230, + .gamma_22_table[18] = (unsigned int *)&ld9040_22_240, + .gamma_22_table[19] = (unsigned int *)&ld9040_22_250, + .gamma_22_table[20] = (unsigned int *)&ld9040_22_260, + .gamma_22_table[21] = (unsigned int *)&ld9040_22_270, + .gamma_22_table[22] = (unsigned int *)&ld9040_22_280, + .gamma_22_table[23] = (unsigned int *)&ld9040_22_290,
Quoted 9 lines
drivers/video/backlight/ld9040_gamma.h line 202
Quoted 4 lines
drivers/video/backlight/ld9040_gamma.h new file +4
-0+ .gamma_22_table[24] = (unsigned int *)&ld9040_22_300, +}; + +#endif Defining static tables in a header file is strange. It would be very wrong if that header was ever included by more than a single .c file, so why not just eliminate this file and move its contents into that .c file?
But, if its contents moved into that .c file, ld9040.c becomes very long file. Ld9040.c file already had many register set data variable, I think readability is less than before.
I'm very grateful to you for your review.
Thank you.
Donghwa Lee