Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Eric Miao and committed by
Russell King
ff7a4c71 f72de663

+90 -28
+2 -7
arch/arm/mach-pxa/corgi.c
··· 444 444 .cs_control = corgi_ads7846_cs, 445 445 }; 446 446 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 - 453 447 static void corgi_bl_kick_battery(void) 454 448 { 455 449 void (*kick_batt)(void); ··· 460 466 .max_intensity = 0x2f, 461 467 .default_intensity = 0x1f, 462 468 .limit_mask = 0x0b, 463 - .notify = corgi_notify_intensity, 469 + .gpio_backlight_cont = CORGI_GPIO_BACKLIGHT_CONT, 470 + .gpio_backlight_on = -1, 464 471 .kick_battery = corgi_bl_kick_battery, 465 472 }; 466 473
+7 -16
arch/arm/mach-pxa/spitz.c
··· 305 305 .cs_control = spitz_ads7846_cs, 306 306 }; 307 307 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 - 323 308 static void spitz_bl_kick_battery(void) 324 309 { 325 310 void (*kick_batt)(void); ··· 321 336 .max_intensity = 0x2f, 322 337 .default_intensity = 0x1f, 323 338 .limit_mask = 0x0b, 324 - .notify = spitz_notify_intensity, 339 + .gpio_backlight_cont = SPITZ_GPIO_BACKLIGHT_CONT, 340 + .gpio_backlight_on = SPITZ_GPIO_BACKLIGHT_ON, 325 341 .kick_battery = spitz_bl_kick_battery, 326 342 }; 327 343 ··· 384 398 err = gpio_request(SPITZ_GPIO_MAX1111_CS, "MAX1111_CS"); 385 399 if (err) 386 400 goto err_free_2; 401 + 402 + if (machine_is_akita()) { 403 + spitz_lcdcon_info.gpio_backlight_cont = AKITA_GPIO_BACKLIGHT_CONT; 404 + spitz_lcdcon_info.gpio_backlight_on = AKITA_GPIO_BACKLIGHT_ON; 405 + } 387 406 388 407 pxa2xx_set_spi_info(2, &spitz_spi_info); 389 408 spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices));
+78 -5
drivers/video/backlight/corgi_lcd.c
··· 19 19 #include <linux/kernel.h> 20 20 #include <linux/init.h> 21 21 #include <linux/delay.h> 22 + #include <linux/gpio.h> 22 23 #include <linux/fb.h> 23 24 #include <linux/lcd.h> 24 25 #include <linux/spi/spi.h> ··· 93 92 int mode; 94 93 char buf[2]; 95 94 96 - void (*notify)(int intensity); 95 + int gpio_backlight_on; 96 + int gpio_backlight_cont; 97 + int gpio_backlight_cont_inverted; 98 + 97 99 void (*kick_battery)(void); 98 100 }; 99 101 ··· 397 393 398 394 static int corgi_bl_set_intensity(struct corgi_lcd *lcd, int intensity) 399 395 { 396 + int cont; 397 + 400 398 if (intensity > 0x10) 401 399 intensity += 0x10; 402 400 403 401 corgi_ssp_lcdtg_send(lcd, DUTYCTRL_ADRS, intensity); 404 - lcd->intensity = intensity; 405 402 406 - if (lcd->notify) 407 - lcd->notify(intensity); 403 + /* Bit 5 via GPIO_BACKLIGHT_CONT */ 404 + cont = !!(intensity & 0x20) ^ lcd->gpio_backlight_cont_inverted; 405 + 406 + if (gpio_is_valid(lcd->gpio_backlight_cont)) 407 + gpio_set_value(lcd->gpio_backlight_cont, cont); 408 + 409 + if (gpio_is_valid(lcd->gpio_backlight_on)) 410 + gpio_set_value(lcd->gpio_backlight_on, intensity); 408 411 409 412 if (lcd->kick_battery) 410 413 lcd->kick_battery(); 411 414 415 + lcd->intensity = intensity; 412 416 return 0; 413 417 } 414 418 ··· 480 468 #define corgi_lcd_resume NULL 481 469 #endif 482 470 471 + static int setup_gpio_backlight(struct corgi_lcd *lcd, 472 + struct corgi_lcd_platform_data *pdata) 473 + { 474 + struct spi_device *spi = lcd->spi_dev; 475 + int err; 476 + 477 + lcd->gpio_backlight_on = -1; 478 + lcd->gpio_backlight_cont = -1; 479 + 480 + if (gpio_is_valid(pdata->gpio_backlight_on)) { 481 + err = gpio_request(pdata->gpio_backlight_on, "BL_ON"); 482 + if (err) { 483 + dev_err(&spi->dev, "failed to request GPIO%d for " 484 + "backlight_on\n", pdata->gpio_backlight_on); 485 + return err; 486 + } 487 + 488 + lcd->gpio_backlight_on = pdata->gpio_backlight_on; 489 + gpio_direction_output(lcd->gpio_backlight_on, 0); 490 + } 491 + 492 + if (gpio_is_valid(pdata->gpio_backlight_cont)) { 493 + err = gpio_request(pdata->gpio_backlight_cont, "BL_CONT"); 494 + if (err) { 495 + dev_err(&spi->dev, "failed to request GPIO%d for " 496 + "backlight_cont\n", pdata->gpio_backlight_cont); 497 + goto err_free_backlight_on; 498 + } 499 + 500 + lcd->gpio_backlight_cont = pdata->gpio_backlight_cont; 501 + 502 + /* spitz and akita use both GPIOs for backlight, and 503 + * have inverted polarity of GPIO_BACKLIGHT_CONT 504 + */ 505 + if (gpio_is_valid(lcd->gpio_backlight_on)) { 506 + lcd->gpio_backlight_cont_inverted = 1; 507 + gpio_direction_output(lcd->gpio_backlight_cont, 1); 508 + } else { 509 + lcd->gpio_backlight_cont_inverted = 0; 510 + gpio_direction_output(lcd->gpio_backlight_cont, 0); 511 + } 512 + } 513 + return 0; 514 + 515 + err_free_backlight_on: 516 + if (gpio_is_valid(lcd->gpio_backlight_on)) 517 + gpio_free(lcd->gpio_backlight_on); 518 + return err; 519 + } 520 + 483 521 static int __devinit corgi_lcd_probe(struct spi_device *spi) 484 522 { 485 523 struct corgi_lcd_platform_data *pdata = spi->dev.platform_data; ··· 568 506 lcd->bl_dev->props.brightness = pdata->default_intensity; 569 507 lcd->bl_dev->props.power = FB_BLANK_UNBLANK; 570 508 571 - lcd->notify = pdata->notify; 509 + ret = setup_gpio_backlight(lcd, pdata); 510 + if (ret) 511 + goto err_unregister_bl; 512 + 572 513 lcd->kick_battery = pdata->kick_battery; 573 514 574 515 dev_set_drvdata(&spi->dev, lcd); ··· 582 517 the_corgi_lcd = lcd; 583 518 return 0; 584 519 520 + err_unregister_bl: 521 + backlight_device_unregister(lcd->bl_dev); 585 522 err_unregister_lcd: 586 523 lcd_device_unregister(lcd->lcd_dev); 587 524 err_free_lcd: ··· 599 532 lcd->bl_dev->props.brightness = 0; 600 533 backlight_update_status(lcd->bl_dev); 601 534 backlight_device_unregister(lcd->bl_dev); 535 + 536 + if (gpio_is_valid(lcd->gpio_backlight_on)) 537 + gpio_free(lcd->gpio_backlight_on); 538 + 539 + if (gpio_is_valid(lcd->gpio_backlight_cont)) 540 + gpio_free(lcd->gpio_backlight_cont); 602 541 603 542 corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_POWERDOWN); 604 543 lcd_device_unregister(lcd->lcd_dev);
+3
include/linux/spi/corgi_lcd.h
··· 10 10 int default_intensity; 11 11 int limit_mask; 12 12 13 + int gpio_backlight_on; /* -1 if n/a */ 14 + int gpio_backlight_cont; /* -1 if n/a */ 15 + 13 16 void (*notify)(int intensity); 14 17 void (*kick_battery)(void); 15 18 };