Commit ee0c8e49 authored by Linus Walleij's avatar Linus Walleij Committed by Lee Jones

backlight: corgi: Convert to use GPIO descriptors

The code in the Corgi backlight driver can be considerably
simplified by moving to GPIO descriptors and lookup tables
from the board files instead of passing GPIO numbers using
the old API.

Make sure to encode inversion semantics for the Akita and
Spitz platforms inside the GPIO lookup table and drop the
custom inversion semantics from the driver.

All in-tree users are converted in this patch.
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Acked-by: default avatarRobert Jarzmik <robert.jarzmik@free.fr>
Reviewed-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
parent 2644f912
...@@ -563,13 +563,20 @@ static void corgi_bl_kick_battery(void) ...@@ -563,13 +563,20 @@ static void corgi_bl_kick_battery(void)
} }
} }
static struct gpiod_lookup_table corgi_lcdcon_gpio_table = {
.dev_id = "spi1.1",
.table = {
GPIO_LOOKUP("gpio-pxa", CORGI_GPIO_BACKLIGHT_CONT,
"BL_CONT", GPIO_ACTIVE_HIGH),
{ },
},
};
static struct corgi_lcd_platform_data corgi_lcdcon_info = { static struct corgi_lcd_platform_data corgi_lcdcon_info = {
.init_mode = CORGI_LCD_MODE_VGA, .init_mode = CORGI_LCD_MODE_VGA,
.max_intensity = 0x2f, .max_intensity = 0x2f,
.default_intensity = 0x1f, .default_intensity = 0x1f,
.limit_mask = 0x0b, .limit_mask = 0x0b,
.gpio_backlight_cont = CORGI_GPIO_BACKLIGHT_CONT,
.gpio_backlight_on = -1,
.kick_battery = corgi_bl_kick_battery, .kick_battery = corgi_bl_kick_battery,
}; };
...@@ -609,6 +616,7 @@ static struct spi_board_info corgi_spi_devices[] = { ...@@ -609,6 +616,7 @@ static struct spi_board_info corgi_spi_devices[] = {
static void __init corgi_init_spi(void) static void __init corgi_init_spi(void)
{ {
pxa2xx_set_spi_info(1, &corgi_spi_info); pxa2xx_set_spi_info(1, &corgi_spi_info);
gpiod_add_lookup_table(&corgi_lcdcon_gpio_table);
spi_register_board_info(ARRAY_AND_SIZE(corgi_spi_devices)); spi_register_board_info(ARRAY_AND_SIZE(corgi_spi_devices));
} }
#else #else
......
...@@ -525,13 +525,33 @@ static void spitz_bl_kick_battery(void) ...@@ -525,13 +525,33 @@ static void spitz_bl_kick_battery(void)
} }
} }
static struct gpiod_lookup_table spitz_lcdcon_gpio_table = {
.dev_id = "spi2.1",
.table = {
GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_BACKLIGHT_CONT,
"BL_CONT", GPIO_ACTIVE_LOW),
GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_BACKLIGHT_ON,
"BL_ON", GPIO_ACTIVE_HIGH),
{ },
},
};
static struct gpiod_lookup_table akita_lcdcon_gpio_table = {
.dev_id = "spi2.1",
.table = {
GPIO_LOOKUP("gpio-pxa", AKITA_GPIO_BACKLIGHT_CONT,
"BL_CONT", GPIO_ACTIVE_LOW),
GPIO_LOOKUP("gpio-pxa", AKITA_GPIO_BACKLIGHT_ON,
"BL_ON", GPIO_ACTIVE_HIGH),
{ },
},
};
static struct corgi_lcd_platform_data spitz_lcdcon_info = { static struct corgi_lcd_platform_data spitz_lcdcon_info = {
.init_mode = CORGI_LCD_MODE_VGA, .init_mode = CORGI_LCD_MODE_VGA,
.max_intensity = 0x2f, .max_intensity = 0x2f,
.default_intensity = 0x1f, .default_intensity = 0x1f,
.limit_mask = 0x0b, .limit_mask = 0x0b,
.gpio_backlight_cont = SPITZ_GPIO_BACKLIGHT_CONT,
.gpio_backlight_on = SPITZ_GPIO_BACKLIGHT_ON,
.kick_battery = spitz_bl_kick_battery, .kick_battery = spitz_bl_kick_battery,
}; };
...@@ -574,12 +594,10 @@ static struct pxa2xx_spi_controller spitz_spi_info = { ...@@ -574,12 +594,10 @@ static struct pxa2xx_spi_controller spitz_spi_info = {
static void __init spitz_spi_init(void) static void __init spitz_spi_init(void)
{ {
struct corgi_lcd_platform_data *lcd_data = &spitz_lcdcon_info; if (machine_is_akita())
gpiod_add_lookup_table(&akita_lcdcon_gpio_table);
if (machine_is_akita()) { else
lcd_data->gpio_backlight_cont = AKITA_GPIO_BACKLIGHT_CONT; gpiod_add_lookup_table(&spitz_lcdcon_gpio_table);
lcd_data->gpio_backlight_on = AKITA_GPIO_BACKLIGHT_ON;
}
pxa2xx_set_spi_info(2, &spitz_spi_info); pxa2xx_set_spi_info(2, &spitz_spi_info);
spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices)); spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices));
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/gpio.h> #include <linux/gpio/consumer.h>
#include <linux/fb.h> #include <linux/fb.h>
#include <linux/lcd.h> #include <linux/lcd.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
...@@ -90,9 +90,8 @@ struct corgi_lcd { ...@@ -90,9 +90,8 @@ struct corgi_lcd {
int mode; int mode;
char buf[2]; char buf[2];
int gpio_backlight_on; struct gpio_desc *backlight_on;
int gpio_backlight_cont; struct gpio_desc *backlight_cont;
int gpio_backlight_cont_inverted;
void (*kick_battery)(void); void (*kick_battery)(void);
}; };
...@@ -403,13 +402,13 @@ static int corgi_bl_set_intensity(struct corgi_lcd *lcd, int intensity) ...@@ -403,13 +402,13 @@ static int corgi_bl_set_intensity(struct corgi_lcd *lcd, int intensity)
corgi_ssp_lcdtg_send(lcd, DUTYCTRL_ADRS, intensity); corgi_ssp_lcdtg_send(lcd, DUTYCTRL_ADRS, intensity);
/* Bit 5 via GPIO_BACKLIGHT_CONT */ /* Bit 5 via GPIO_BACKLIGHT_CONT */
cont = !!(intensity & 0x20) ^ lcd->gpio_backlight_cont_inverted; cont = !!(intensity & 0x20);
if (gpio_is_valid(lcd->gpio_backlight_cont)) if (lcd->backlight_cont)
gpio_set_value_cansleep(lcd->gpio_backlight_cont, cont); gpiod_set_value_cansleep(lcd->backlight_cont, cont);
if (gpio_is_valid(lcd->gpio_backlight_on)) if (lcd->backlight_on)
gpio_set_value_cansleep(lcd->gpio_backlight_on, intensity); gpiod_set_value_cansleep(lcd->backlight_on, intensity);
if (lcd->kick_battery) if (lcd->kick_battery)
lcd->kick_battery(); lcd->kick_battery();
...@@ -482,48 +481,17 @@ static int setup_gpio_backlight(struct corgi_lcd *lcd, ...@@ -482,48 +481,17 @@ static int setup_gpio_backlight(struct corgi_lcd *lcd,
struct corgi_lcd_platform_data *pdata) struct corgi_lcd_platform_data *pdata)
{ {
struct spi_device *spi = lcd->spi_dev; 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 = devm_gpio_request(&spi->dev, 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)) { lcd->backlight_on = devm_gpiod_get_optional(&spi->dev,
err = devm_gpio_request(&spi->dev, pdata->gpio_backlight_cont, "BL_ON", GPIOD_OUT_LOW);
"BL_CONT"); if (IS_ERR(lcd->backlight_on))
if (err) { return PTR_ERR(lcd->backlight_on);
dev_err(&spi->dev,
"failed to request GPIO%d for backlight_cont\n", lcd->backlight_cont = devm_gpiod_get_optional(&spi->dev, "BL_CONT",
pdata->gpio_backlight_cont); GPIOD_OUT_LOW);
return err; if (IS_ERR(lcd->backlight_cont))
} return PTR_ERR(lcd->backlight_cont);
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; return 0;
} }
......
...@@ -11,9 +11,6 @@ struct corgi_lcd_platform_data { ...@@ -11,9 +11,6 @@ struct corgi_lcd_platform_data {
int default_intensity; int default_intensity;
int limit_mask; int limit_mask;
int gpio_backlight_on; /* -1 if n/a */
int gpio_backlight_cont; /* -1 if n/a */
void (*notify)(int intensity); void (*notify)(int intensity);
void (*kick_battery)(void); void (*kick_battery)(void);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment