[ARM] corgi_lcd: use GPIO API for BACKLIGHT_ON and BACKLIGHT_CONT
authorEric Miao <eric.miao@marvell.com>
Sun, 7 Sep 2008 03:30:06 +0000 (11:30 +0800)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Thu, 25 Sep 2008 08:38:14 +0000 (09:38 +0100)
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/mach-pxa/corgi.c
arch/arm/mach-pxa/spitz.c
drivers/video/backlight/corgi_lcd.c
include/linux/spi/corgi_lcd.h

index f8fd1d872157df5966e837bb0604ec4906876929..5c08c4e9cd22fd3b13761fb5b3f9ba73f4f15496 100644 (file)
@@ -444,12 +444,6 @@ static struct pxa2xx_spi_chip corgi_ads7846_chip = {
        .cs_control     = corgi_ads7846_cs,
 };
 
-static void corgi_notify_intensity(int intensity)
-{
-       /* Bit 5 is via SCOOP */
-       gpio_set_value(CORGI_GPIO_BACKLIGHT_CONT, !!(intensity & 0x0020));
-}
-
 static void corgi_bl_kick_battery(void)
 {
        void (*kick_batt)(void);
@@ -466,7 +460,8 @@ static struct corgi_lcd_platform_data corgi_lcdcon_info = {
        .max_intensity          = 0x2f,
        .default_intensity      = 0x1f,
        .limit_mask             = 0x0b,
-       .notify                 = corgi_notify_intensity,
+       .gpio_backlight_cont    = CORGI_GPIO_BACKLIGHT_CONT,
+       .gpio_backlight_on      = -1,
        .kick_battery           = corgi_bl_kick_battery,
 };
 
index 1d8654d2fb96ed11eedc278521e046262b415474..245890d2b6b5d8c94c3a01d1a9ce3c91a0cf2254 100644 (file)
@@ -305,21 +305,6 @@ static struct pxa2xx_spi_chip spitz_ads7846_chip = {
        .cs_control             = spitz_ads7846_cs,
 };
 
-static void spitz_notify_intensity(int intensity)
-{
-       if (machine_is_spitz() || machine_is_borzoi()) {
-               gpio_set_value(SPITZ_GPIO_BACKLIGHT_CONT, !(intensity & 0x20));
-               gpio_set_value(SPITZ_GPIO_BACKLIGHT_ON, intensity);
-               return;
-       }
-
-       if (machine_is_akita()) {
-               gpio_set_value(AKITA_GPIO_BACKLIGHT_CONT, !(intensity & 0x20));
-               gpio_set_value(AKITA_GPIO_BACKLIGHT_ON, intensity);
-               return;
-       }
-}
-
 static void spitz_bl_kick_battery(void)
 {
        void (*kick_batt)(void);
@@ -336,7 +321,8 @@ static struct corgi_lcd_platform_data spitz_lcdcon_info = {
        .max_intensity          = 0x2f,
        .default_intensity      = 0x1f,
        .limit_mask             = 0x0b,
-       .notify                 = spitz_notify_intensity,
+       .gpio_backlight_cont    = SPITZ_GPIO_BACKLIGHT_CONT,
+       .gpio_backlight_on      = SPITZ_GPIO_BACKLIGHT_ON,
        .kick_battery           = spitz_bl_kick_battery,
 };
 
@@ -399,6 +385,11 @@ static void __init spitz_init_spi(void)
        if (err)
                goto err_free_2;
 
+       if (machine_is_akita()) {
+               spitz_lcdcon_info.gpio_backlight_cont = AKITA_GPIO_BACKLIGHT_CONT;
+               spitz_lcdcon_info.gpio_backlight_on = AKITA_GPIO_BACKLIGHT_ON;
+       }
+
        pxa2xx_set_spi_info(2, &spitz_spi_info);
        spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices));
        return;
index 068f14864099d99cfa8a81929e17f76971a07041..2afd47eefe74d4f33b3981de401df1f7465f73c2 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/gpio.h>
 #include <linux/fb.h>
 #include <linux/lcd.h>
 #include <linux/spi/spi.h>
@@ -92,7 +93,10 @@ struct corgi_lcd {
        int     mode;
        char    buf[2];
 
-       void (*notify)(int intensity);
+       int     gpio_backlight_on;
+       int     gpio_backlight_cont;
+       int     gpio_backlight_cont_inverted;
+
        void (*kick_battery)(void);
 };
 
@@ -393,18 +397,26 @@ static int corgi_bl_get_intensity(struct backlight_device *bd)
 
 static int corgi_bl_set_intensity(struct corgi_lcd *lcd, int intensity)
 {
+       int cont;
+
        if (intensity > 0x10)
                intensity += 0x10;
 
        corgi_ssp_lcdtg_send(lcd, DUTYCTRL_ADRS, intensity);
-       lcd->intensity = intensity;
 
-       if (lcd->notify)
-               lcd->notify(intensity);
+       /* Bit 5 via GPIO_BACKLIGHT_CONT */
+       cont = !!(intensity & 0x20) ^ lcd->gpio_backlight_cont_inverted;
+
+       if (gpio_is_valid(lcd->gpio_backlight_cont))
+               gpio_set_value(lcd->gpio_backlight_cont, cont);
+
+       if (gpio_is_valid(lcd->gpio_backlight_on))
+               gpio_set_value(lcd->gpio_backlight_on, intensity);
 
        if (lcd->kick_battery)
                lcd->kick_battery();
 
+       lcd->intensity = intensity;
        return 0;
 }
 
@@ -468,6 +480,56 @@ static int corgi_lcd_resume(struct spi_device *spi)
 #define corgi_lcd_resume       NULL
 #endif
 
+static int setup_gpio_backlight(struct corgi_lcd *lcd,
+                               struct corgi_lcd_platform_data *pdata)
+{
+       struct spi_device *spi = lcd->spi_dev;
+       int err;
+
+       lcd->gpio_backlight_on = -1;
+       lcd->gpio_backlight_cont = -1;
+
+       if (gpio_is_valid(pdata->gpio_backlight_on)) {
+               err = gpio_request(pdata->gpio_backlight_on, "BL_ON");
+               if (err) {
+                       dev_err(&spi->dev, "failed to request GPIO%d for "
+                               "backlight_on\n", pdata->gpio_backlight_on);
+                       return err;
+               }
+
+               lcd->gpio_backlight_on = pdata->gpio_backlight_on;
+               gpio_direction_output(lcd->gpio_backlight_on, 0);
+       }
+
+       if (gpio_is_valid(pdata->gpio_backlight_cont)) {
+               err = gpio_request(pdata->gpio_backlight_cont, "BL_CONT");
+               if (err) {
+                       dev_err(&spi->dev, "failed to request GPIO%d for "
+                               "backlight_cont\n", pdata->gpio_backlight_cont);
+                       goto err_free_backlight_on;
+               }
+
+               lcd->gpio_backlight_cont = pdata->gpio_backlight_cont;
+
+               /* spitz and akita use both GPIOs for backlight, and
+                * have inverted polarity of GPIO_BACKLIGHT_CONT
+                */
+               if (gpio_is_valid(lcd->gpio_backlight_on)) {
+                       lcd->gpio_backlight_cont_inverted = 1;
+                       gpio_direction_output(lcd->gpio_backlight_cont, 1);
+               } else {
+                       lcd->gpio_backlight_cont_inverted = 0;
+                       gpio_direction_output(lcd->gpio_backlight_cont, 0);
+               }
+       }
+       return 0;
+
+err_free_backlight_on:
+       if (gpio_is_valid(lcd->gpio_backlight_on))
+               gpio_free(lcd->gpio_backlight_on);
+       return err;
+}
+
 static int __devinit corgi_lcd_probe(struct spi_device *spi)
 {
        struct corgi_lcd_platform_data *pdata = spi->dev.platform_data;
@@ -506,7 +568,10 @@ static int __devinit corgi_lcd_probe(struct spi_device *spi)
        lcd->bl_dev->props.brightness = pdata->default_intensity;
        lcd->bl_dev->props.power = FB_BLANK_UNBLANK;
 
-       lcd->notify = pdata->notify;
+       ret = setup_gpio_backlight(lcd, pdata);
+       if (ret)
+               goto err_unregister_bl;
+
        lcd->kick_battery = pdata->kick_battery;
 
        dev_set_drvdata(&spi->dev, lcd);
@@ -517,6 +582,8 @@ static int __devinit corgi_lcd_probe(struct spi_device *spi)
        the_corgi_lcd = lcd;
        return 0;
 
+err_unregister_bl:
+       backlight_device_unregister(lcd->bl_dev);
 err_unregister_lcd:
        lcd_device_unregister(lcd->lcd_dev);
 err_free_lcd:
@@ -533,6 +600,12 @@ static int __devexit corgi_lcd_remove(struct spi_device *spi)
        backlight_update_status(lcd->bl_dev);
        backlight_device_unregister(lcd->bl_dev);
 
+       if (gpio_is_valid(lcd->gpio_backlight_on))
+               gpio_free(lcd->gpio_backlight_on);
+
+       if (gpio_is_valid(lcd->gpio_backlight_cont))
+               gpio_free(lcd->gpio_backlight_cont);
+
        corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_POWERDOWN);
        lcd_device_unregister(lcd->lcd_dev);
        kfree(lcd);
index b6161aae2752bb665f0d66412112e56034ec48a3..6692b3418ccfdd0e219cba62a04e2d482909a5e8 100644 (file)
@@ -10,6 +10,9 @@ struct corgi_lcd_platform_data {
        int     default_intensity;
        int     limit_mask;
 
+       int     gpio_backlight_on;      /* -1 if n/a */
+       int     gpio_backlight_cont;    /* -1 if n/a */
+
        void (*notify)(int intensity);
        void (*kick_battery)(void);
 };