Skip to content

Commit ff7a4c7

Browse files
Eric MiaoRussell King
authored andcommitted
[ARM] corgi_lcd: use GPIO API for BACKLIGHT_ON and BACKLIGHT_CONT
Signed-off-by: Eric Miao <eric.miao@marvell.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent f72de66 commit ff7a4c7

4 files changed

Lines changed: 90 additions & 28 deletions

File tree

‎arch/arm/mach-pxa/corgi.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,6 @@ static struct pxa2xx_spi_chip corgi_ads7846_chip = {
444444
.cs_control = corgi_ads7846_cs,
445445
};
446446

447-
static void corgi_notify_intensity(int intensity)
448-
{
449-
/* Bit 5 is via SCOOP */
450-
gpio_set_value(CORGI_GPIO_BACKLIGHT_CONT, !!(intensity & 0x0020));
451-
}
452-
453447
static void corgi_bl_kick_battery(void)
454448
{
455449
void (*kick_batt)(void);
@@ -466,7 +460,8 @@ static struct corgi_lcd_platform_data corgi_lcdcon_info = {
466460
.max_intensity = 0x2f,
467461
.default_intensity = 0x1f,
468462
.limit_mask = 0x0b,
469-
.notify = corgi_notify_intensity,
463+
.gpio_backlight_cont = CORGI_GPIO_BACKLIGHT_CONT,
464+
.gpio_backlight_on = -1,
470465
.kick_battery = corgi_bl_kick_battery,
471466
};
472467

‎arch/arm/mach-pxa/spitz.c‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -305,21 +305,6 @@ static struct pxa2xx_spi_chip spitz_ads7846_chip = {
305305
.cs_control = spitz_ads7846_cs,
306306
};
307307

308-
static void spitz_notify_intensity(int intensity)
309-
{
310-
if (machine_is_spitz() || machine_is_borzoi()) {
311-
gpio_set_value(SPITZ_GPIO_BACKLIGHT_CONT, !(intensity & 0x20));
312-
gpio_set_value(SPITZ_GPIO_BACKLIGHT_ON, intensity);
313-
return;
314-
}
315-
316-
if (machine_is_akita()) {
317-
gpio_set_value(AKITA_GPIO_BACKLIGHT_CONT, !(intensity & 0x20));
318-
gpio_set_value(AKITA_GPIO_BACKLIGHT_ON, intensity);
319-
return;
320-
}
321-
}
322-
323308
static void spitz_bl_kick_battery(void)
324309
{
325310
void (*kick_batt)(void);
@@ -336,7 +321,8 @@ static struct corgi_lcd_platform_data spitz_lcdcon_info = {
336321
.max_intensity = 0x2f,
337322
.default_intensity = 0x1f,
338323
.limit_mask = 0x0b,
339-
.notify = spitz_notify_intensity,
324+
.gpio_backlight_cont = SPITZ_GPIO_BACKLIGHT_CONT,
325+
.gpio_backlight_on = SPITZ_GPIO_BACKLIGHT_ON,
340326
.kick_battery = spitz_bl_kick_battery,
341327
};
342328

@@ -399,6 +385,11 @@ static void __init spitz_init_spi(void)
399385
if (err)
400386
goto err_free_2;
401387

388+
if (machine_is_akita()) {
389+
spitz_lcdcon_info.gpio_backlight_cont = AKITA_GPIO_BACKLIGHT_CONT;
390+
spitz_lcdcon_info.gpio_backlight_on = AKITA_GPIO_BACKLIGHT_ON;
391+
}
392+
402393
pxa2xx_set_spi_info(2, &spitz_spi_info);
403394
spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices));
404395
return;

‎drivers/video/backlight/corgi_lcd.c‎

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/kernel.h>
2020
#include <linux/init.h>
2121
#include <linux/delay.h>
22+
#include <linux/gpio.h>
2223
#include <linux/fb.h>
2324
#include <linux/lcd.h>
2425
#include <linux/spi/spi.h>
@@ -92,7 +93,10 @@ struct corgi_lcd {
9293
int mode;
9394
char buf[2];
9495

95-
void (*notify)(int intensity);
96+
int gpio_backlight_on;
97+
int gpio_backlight_cont;
98+
int gpio_backlight_cont_inverted;
99+
96100
void (*kick_battery)(void);
97101
};
98102

@@ -393,18 +397,26 @@ static int corgi_bl_get_intensity(struct backlight_device *bd)
393397

394398
static int corgi_bl_set_intensity(struct corgi_lcd *lcd, int intensity)
395399
{
400+
int cont;
401+
396402
if (intensity > 0x10)
397403
intensity += 0x10;
398404

399405
corgi_ssp_lcdtg_send(lcd, DUTYCTRL_ADRS, intensity);
400-
lcd->intensity = intensity;
401406

402-
if (lcd->notify)
403-
lcd->notify(intensity);
407+
/* Bit 5 via GPIO_BACKLIGHT_CONT */
408+
cont = !!(intensity & 0x20) ^ lcd->gpio_backlight_cont_inverted;
409+
410+
if (gpio_is_valid(lcd->gpio_backlight_cont))
411+
gpio_set_value(lcd->gpio_backlight_cont, cont);
412+
413+
if (gpio_is_valid(lcd->gpio_backlight_on))
414+
gpio_set_value(lcd->gpio_backlight_on, intensity);
404415

405416
if (lcd->kick_battery)
406417
lcd->kick_battery();
407418

419+
lcd->intensity = intensity;
408420
return 0;
409421
}
410422

@@ -468,6 +480,56 @@ static int corgi_lcd_resume(struct spi_device *spi)
468480
#define corgi_lcd_resume NULL
469481
#endif
470482

483+
static int setup_gpio_backlight(struct corgi_lcd *lcd,
484+
struct corgi_lcd_platform_data *pdata)
485+
{
486+
struct spi_device *spi = lcd->spi_dev;
487+
int err;
488+
489+
lcd->gpio_backlight_on = -1;
490+
lcd->gpio_backlight_cont = -1;
491+
492+
if (gpio_is_valid(pdata->gpio_backlight_on)) {
493+
err = gpio_request(pdata->gpio_backlight_on, "BL_ON");
494+
if (err) {
495+
dev_err(&spi->dev, "failed to request GPIO%d for "
496+
"backlight_on\n", 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+
}
503+
504+
if (gpio_is_valid(pdata->gpio_backlight_cont)) {
505+
err = gpio_request(pdata->gpio_backlight_cont, "BL_CONT");
506+
if (err) {
507+
dev_err(&spi->dev, "failed to request GPIO%d for "
508+
"backlight_cont\n", pdata->gpio_backlight_cont);
509+
goto err_free_backlight_on;
510+
}
511+
512+
lcd->gpio_backlight_cont = pdata->gpio_backlight_cont;
513+
514+
/* spitz and akita use both GPIOs for backlight, and
515+
* have inverted polarity of GPIO_BACKLIGHT_CONT
516+
*/
517+
if (gpio_is_valid(lcd->gpio_backlight_on)) {
518+
lcd->gpio_backlight_cont_inverted = 1;
519+
gpio_direction_output(lcd->gpio_backlight_cont, 1);
520+
} else {
521+
lcd->gpio_backlight_cont_inverted = 0;
522+
gpio_direction_output(lcd->gpio_backlight_cont, 0);
523+
}
524+
}
525+
return 0;
526+
527+
err_free_backlight_on:
528+
if (gpio_is_valid(lcd->gpio_backlight_on))
529+
gpio_free(lcd->gpio_backlight_on);
530+
return err;
531+
}
532+
471533
static int __devinit corgi_lcd_probe(struct spi_device *spi)
472534
{
473535
struct corgi_lcd_platform_data *pdata = spi->dev.platform_data;
@@ -506,7 +568,10 @@ static int __devinit corgi_lcd_probe(struct spi_device *spi)
506568
lcd->bl_dev->props.brightness = pdata->default_intensity;
507569
lcd->bl_dev->props.power = FB_BLANK_UNBLANK;
508570

509-
lcd->notify = pdata->notify;
571+
ret = setup_gpio_backlight(lcd, pdata);
572+
if (ret)
573+
goto err_unregister_bl;
574+
510575
lcd->kick_battery = pdata->kick_battery;
511576

512577
dev_set_drvdata(&spi->dev, lcd);
@@ -517,6 +582,8 @@ static int __devinit corgi_lcd_probe(struct spi_device *spi)
517582
the_corgi_lcd = lcd;
518583
return 0;
519584

585+
err_unregister_bl:
586+
backlight_device_unregister(lcd->bl_dev);
520587
err_unregister_lcd:
521588
lcd_device_unregister(lcd->lcd_dev);
522589
err_free_lcd:
@@ -533,6 +600,12 @@ static int __devexit corgi_lcd_remove(struct spi_device *spi)
533600
backlight_update_status(lcd->bl_dev);
534601
backlight_device_unregister(lcd->bl_dev);
535602

603+
if (gpio_is_valid(lcd->gpio_backlight_on))
604+
gpio_free(lcd->gpio_backlight_on);
605+
606+
if (gpio_is_valid(lcd->gpio_backlight_cont))
607+
gpio_free(lcd->gpio_backlight_cont);
608+
536609
corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_POWERDOWN);
537610
lcd_device_unregister(lcd->lcd_dev);
538611
kfree(lcd);

‎include/linux/spi/corgi_lcd.h‎

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

13+
int gpio_backlight_on; /* -1 if n/a */
14+
int gpio_backlight_cont; /* -1 if n/a */
15+
1316
void (*notify)(int intensity);
1417
void (*kick_battery)(void);
1518
};

0 commit comments

Comments
 (0)