forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/video/backlight/corgi_lcd.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * LCD/Backlight Driver for Sharp Zaurus Handhelds (various models)
34 *
....@@ -8,18 +9,13 @@
89 * Copyright (c) 2008 Marvell International Ltd.
910 * Converted to SPI device based LCD/Backlight device driver
1011 * by Eric Miao <eric.miao@marvell.com>
11
- *
12
- * This program is free software; you can redistribute it and/or modify
13
- * it under the terms of the GNU General Public License version 2 as
14
- * published by the Free Software Foundation.
15
- *
1612 */
1713
1814 #include <linux/module.h>
1915 #include <linux/kernel.h>
2016 #include <linux/init.h>
2117 #include <linux/delay.h>
22
-#include <linux/gpio.h>
18
+#include <linux/gpio/consumer.h>
2319 #include <linux/fb.h>
2420 #include <linux/lcd.h>
2521 #include <linux/spi/spi.h>
....@@ -94,9 +90,8 @@
9490 int mode;
9591 char buf[2];
9692
97
- int gpio_backlight_on;
98
- int gpio_backlight_cont;
99
- int gpio_backlight_cont_inverted;
93
+ struct gpio_desc *backlight_on;
94
+ struct gpio_desc *backlight_cont;
10095
10196 void (*kick_battery)(void);
10297 };
....@@ -407,13 +402,13 @@
407402 corgi_ssp_lcdtg_send(lcd, DUTYCTRL_ADRS, intensity);
408403
409404 /* Bit 5 via GPIO_BACKLIGHT_CONT */
410
- cont = !!(intensity & 0x20) ^ lcd->gpio_backlight_cont_inverted;
405
+ cont = !!(intensity & 0x20);
411406
412
- if (gpio_is_valid(lcd->gpio_backlight_cont))
413
- gpio_set_value_cansleep(lcd->gpio_backlight_cont, cont);
407
+ if (lcd->backlight_cont)
408
+ gpiod_set_value_cansleep(lcd->backlight_cont, cont);
414409
415
- if (gpio_is_valid(lcd->gpio_backlight_on))
416
- gpio_set_value_cansleep(lcd->gpio_backlight_on, intensity);
410
+ if (lcd->backlight_on)
411
+ gpiod_set_value_cansleep(lcd->backlight_on, intensity);
417412
418413 if (lcd->kick_battery)
419414 lcd->kick_battery();
....@@ -425,13 +420,7 @@
425420 static int corgi_bl_update_status(struct backlight_device *bd)
426421 {
427422 struct corgi_lcd *lcd = bl_get_data(bd);
428
- int intensity = bd->props.brightness;
429
-
430
- if (bd->props.power != FB_BLANK_UNBLANK)
431
- intensity = 0;
432
-
433
- if (bd->props.fb_blank != FB_BLANK_UNBLANK)
434
- intensity = 0;
423
+ int intensity = backlight_get_brightness(bd);
435424
436425 if (corgibl_flags & CORGIBL_SUSPENDED)
437426 intensity = 0;
....@@ -486,48 +475,17 @@
486475 struct corgi_lcd_platform_data *pdata)
487476 {
488477 struct spi_device *spi = lcd->spi_dev;
489
- int err;
490478
491
- lcd->gpio_backlight_on = -1;
492
- lcd->gpio_backlight_cont = -1;
479
+ lcd->backlight_on = devm_gpiod_get_optional(&spi->dev,
480
+ "BL_ON", GPIOD_OUT_LOW);
481
+ if (IS_ERR(lcd->backlight_on))
482
+ return PTR_ERR(lcd->backlight_on);
493483
494
- if (gpio_is_valid(pdata->gpio_backlight_on)) {
495
- err = devm_gpio_request(&spi->dev, pdata->gpio_backlight_on,
496
- "BL_ON");
497
- if (err) {
498
- dev_err(&spi->dev,
499
- "failed to request GPIO%d for backlight_on\n",
500
- pdata->gpio_backlight_on);
501
- return err;
502
- }
484
+ lcd->backlight_cont = devm_gpiod_get_optional(&spi->dev, "BL_CONT",
485
+ GPIOD_OUT_LOW);
486
+ if (IS_ERR(lcd->backlight_cont))
487
+ return PTR_ERR(lcd->backlight_cont);
503488
504
- lcd->gpio_backlight_on = pdata->gpio_backlight_on;
505
- gpio_direction_output(lcd->gpio_backlight_on, 0);
506
- }
507
-
508
- if (gpio_is_valid(pdata->gpio_backlight_cont)) {
509
- err = devm_gpio_request(&spi->dev, pdata->gpio_backlight_cont,
510
- "BL_CONT");
511
- if (err) {
512
- dev_err(&spi->dev,
513
- "failed to request GPIO%d for backlight_cont\n",
514
- pdata->gpio_backlight_cont);
515
- return err;
516
- }
517
-
518
- lcd->gpio_backlight_cont = pdata->gpio_backlight_cont;
519
-
520
- /* spitz and akita use both GPIOs for backlight, and
521
- * have inverted polarity of GPIO_BACKLIGHT_CONT
522
- */
523
- if (gpio_is_valid(lcd->gpio_backlight_on)) {
524
- lcd->gpio_backlight_cont_inverted = 1;
525
- gpio_direction_output(lcd->gpio_backlight_cont, 1);
526
- } else {
527
- lcd->gpio_backlight_cont_inverted = 0;
528
- gpio_direction_output(lcd->gpio_backlight_cont, 0);
529
- }
530
- }
531489 return 0;
532490 }
533491