Skip to content

Commit ee0c8e4

Browse files
linuswLee Jones
authored andcommitted
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: Linus Walleij <[email protected]> Acked-by: Robert Jarzmik <[email protected]> Reviewed-by: Daniel Thompson <[email protected]> Signed-off-by: Lee Jones <[email protected]>
1 parent 2644f91 commit ee0c8e4

File tree

4 files changed

+54
-63
lines changed

4 files changed

+54
-63
lines changed

arch/arm/mach-pxa/corgi.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,13 +563,20 @@ static void corgi_bl_kick_battery(void)
563563
}
564564
}
565565

566+
static struct gpiod_lookup_table corgi_lcdcon_gpio_table = {
567+
.dev_id = "spi1.1",
568+
.table = {
569+
GPIO_LOOKUP("gpio-pxa", CORGI_GPIO_BACKLIGHT_CONT,
570+
"BL_CONT", GPIO_ACTIVE_HIGH),
571+
{ },
572+
},
573+
};
574+
566575
static struct corgi_lcd_platform_data corgi_lcdcon_info = {
567576
.init_mode = CORGI_LCD_MODE_VGA,
568577
.max_intensity = 0x2f,
569578
.default_intensity = 0x1f,
570579
.limit_mask = 0x0b,
571-
.gpio_backlight_cont = CORGI_GPIO_BACKLIGHT_CONT,
572-
.gpio_backlight_on = -1,
573580
.kick_battery = corgi_bl_kick_battery,
574581
};
575582

@@ -609,6 +616,7 @@ static struct spi_board_info corgi_spi_devices[] = {
609616
static void __init corgi_init_spi(void)
610617
{
611618
pxa2xx_set_spi_info(1, &corgi_spi_info);
619+
gpiod_add_lookup_table(&corgi_lcdcon_gpio_table);
612620
spi_register_board_info(ARRAY_AND_SIZE(corgi_spi_devices));
613621
}
614622
#else

arch/arm/mach-pxa/spitz.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,33 @@ static void spitz_bl_kick_battery(void)
525525
}
526526
}
527527

528+
static struct gpiod_lookup_table spitz_lcdcon_gpio_table = {
529+
.dev_id = "spi2.1",
530+
.table = {
531+
GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_BACKLIGHT_CONT,
532+
"BL_CONT", GPIO_ACTIVE_LOW),
533+
GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_BACKLIGHT_ON,
534+
"BL_ON", GPIO_ACTIVE_HIGH),
535+
{ },
536+
},
537+
};
538+
539+
static struct gpiod_lookup_table akita_lcdcon_gpio_table = {
540+
.dev_id = "spi2.1",
541+
.table = {
542+
GPIO_LOOKUP("gpio-pxa", AKITA_GPIO_BACKLIGHT_CONT,
543+
"BL_CONT", GPIO_ACTIVE_LOW),
544+
GPIO_LOOKUP("gpio-pxa", AKITA_GPIO_BACKLIGHT_ON,
545+
"BL_ON", GPIO_ACTIVE_HIGH),
546+
{ },
547+
},
548+
};
549+
528550
static struct corgi_lcd_platform_data spitz_lcdcon_info = {
529551
.init_mode = CORGI_LCD_MODE_VGA,
530552
.max_intensity = 0x2f,
531553
.default_intensity = 0x1f,
532554
.limit_mask = 0x0b,
533-
.gpio_backlight_cont = SPITZ_GPIO_BACKLIGHT_CONT,
534-
.gpio_backlight_on = SPITZ_GPIO_BACKLIGHT_ON,
535555
.kick_battery = spitz_bl_kick_battery,
536556
};
537557

@@ -574,12 +594,10 @@ static struct pxa2xx_spi_controller spitz_spi_info = {
574594

575595
static void __init spitz_spi_init(void)
576596
{
577-
struct corgi_lcd_platform_data *lcd_data = &spitz_lcdcon_info;
578-
579-
if (machine_is_akita()) {
580-
lcd_data->gpio_backlight_cont = AKITA_GPIO_BACKLIGHT_CONT;
581-
lcd_data->gpio_backlight_on = AKITA_GPIO_BACKLIGHT_ON;
582-
}
597+
if (machine_is_akita())
598+
gpiod_add_lookup_table(&akita_lcdcon_gpio_table);
599+
else
600+
gpiod_add_lookup_table(&spitz_lcdcon_gpio_table);
583601

584602
pxa2xx_set_spi_info(2, &spitz_spi_info);
585603
spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices));

drivers/video/backlight/corgi_lcd.c

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <linux/kernel.h>
1616
#include <linux/init.h>
1717
#include <linux/delay.h>
18-
#include <linux/gpio.h>
18+
#include <linux/gpio/consumer.h>
1919
#include <linux/fb.h>
2020
#include <linux/lcd.h>
2121
#include <linux/spi/spi.h>
@@ -90,9 +90,8 @@ struct corgi_lcd {
9090
int mode;
9191
char buf[2];
9292

93-
int gpio_backlight_on;
94-
int gpio_backlight_cont;
95-
int gpio_backlight_cont_inverted;
93+
struct gpio_desc *backlight_on;
94+
struct gpio_desc *backlight_cont;
9695

9796
void (*kick_battery)(void);
9897
};
@@ -403,13 +402,13 @@ static int corgi_bl_set_intensity(struct corgi_lcd *lcd, int intensity)
403402
corgi_ssp_lcdtg_send(lcd, DUTYCTRL_ADRS, intensity);
404403

405404
/* Bit 5 via GPIO_BACKLIGHT_CONT */
406-
cont = !!(intensity & 0x20) ^ lcd->gpio_backlight_cont_inverted;
405+
cont = !!(intensity & 0x20);
407406

408-
if (gpio_is_valid(lcd->gpio_backlight_cont))
409-
gpio_set_value_cansleep(lcd->gpio_backlight_cont, cont);
407+
if (lcd->backlight_cont)
408+
gpiod_set_value_cansleep(lcd->backlight_cont, cont);
410409

411-
if (gpio_is_valid(lcd->gpio_backlight_on))
412-
gpio_set_value_cansleep(lcd->gpio_backlight_on, intensity);
410+
if (lcd->backlight_on)
411+
gpiod_set_value_cansleep(lcd->backlight_on, intensity);
413412

414413
if (lcd->kick_battery)
415414
lcd->kick_battery();
@@ -482,48 +481,17 @@ static int setup_gpio_backlight(struct corgi_lcd *lcd,
482481
struct corgi_lcd_platform_data *pdata)
483482
{
484483
struct spi_device *spi = lcd->spi_dev;
485-
int err;
486-
487-
lcd->gpio_backlight_on = -1;
488-
lcd->gpio_backlight_cont = -1;
489-
490-
if (gpio_is_valid(pdata->gpio_backlight_on)) {
491-
err = devm_gpio_request(&spi->dev, pdata->gpio_backlight_on,
492-
"BL_ON");
493-
if (err) {
494-
dev_err(&spi->dev,
495-
"failed to request GPIO%d for backlight_on\n",
496-
pdata->gpio_backlight_on);
497-
return err;
498-
}
499-
500-
lcd->gpio_backlight_on = pdata->gpio_backlight_on;
501-
gpio_direction_output(lcd->gpio_backlight_on, 0);
502-
}
503484

504-
if (gpio_is_valid(pdata->gpio_backlight_cont)) {
505-
err = devm_gpio_request(&spi->dev, pdata->gpio_backlight_cont,
506-
"BL_CONT");
507-
if (err) {
508-
dev_err(&spi->dev,
509-
"failed to request GPIO%d for backlight_cont\n",
510-
pdata->gpio_backlight_cont);
511-
return err;
512-
}
513-
514-
lcd->gpio_backlight_cont = pdata->gpio_backlight_cont;
515-
516-
/* spitz and akita use both GPIOs for backlight, and
517-
* have inverted polarity of GPIO_BACKLIGHT_CONT
518-
*/
519-
if (gpio_is_valid(lcd->gpio_backlight_on)) {
520-
lcd->gpio_backlight_cont_inverted = 1;
521-
gpio_direction_output(lcd->gpio_backlight_cont, 1);
522-
} else {
523-
lcd->gpio_backlight_cont_inverted = 0;
524-
gpio_direction_output(lcd->gpio_backlight_cont, 0);
525-
}
526-
}
485+
lcd->backlight_on = devm_gpiod_get_optional(&spi->dev,
486+
"BL_ON", GPIOD_OUT_LOW);
487+
if (IS_ERR(lcd->backlight_on))
488+
return PTR_ERR(lcd->backlight_on);
489+
490+
lcd->backlight_cont = devm_gpiod_get_optional(&spi->dev, "BL_CONT",
491+
GPIOD_OUT_LOW);
492+
if (IS_ERR(lcd->backlight_cont))
493+
return PTR_ERR(lcd->backlight_cont);
494+
527495
return 0;
528496
}
529497

include/linux/spi/corgi_lcd.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ struct corgi_lcd_platform_data {
1111
int default_intensity;
1212
int limit_mask;
1313

14-
int gpio_backlight_on; /* -1 if n/a */
15-
int gpio_backlight_cont; /* -1 if n/a */
16-
1714
void (*notify)(int intensity);
1815
void (*kick_battery)(void);
1916
};

0 commit comments

Comments
 (0)