diff mbox series

[2/2] leds: ktd2692: Make aux-gpios optional

Message ID 20220407101034.13122-3-markuss.broks@gmail.com
State Superseded
Headers show
Series Make AUX gpio pin optional for ktd2692 | expand

Commit Message

Markuss Broks April 7, 2022, 10:10 a.m. UTC
Make the AUX pin optional, since it isn't a core part of functionality,
and the device is designed to be operational with only one CTRL pin.

Also pick up maintainership for the LED driver and the yaml bindings.

Signed-off-by: Markuss Broks <markuss.broks@gmail.com>
---
 MAINTAINERS                       |  6 ++++++
 drivers/leds/flash/leds-ktd2692.c | 18 ++++++++++--------
 2 files changed, 16 insertions(+), 8 deletions(-)

Comments

Andy Shevchenko April 8, 2022, 11:04 a.m. UTC | #1
On Thu, Apr 7, 2022 at 1:33 PM Markuss Broks <markuss.broks@gmail.com> wrote:
>
> Make the AUX pin optional, since it isn't a core part of functionality,
> and the device is designed to be operational with only one CTRL pin.
>
> Also pick up maintainership for the LED driver and the yaml bindings.

maintenance?

...

> -               gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
> +               if (led->aux_gpio)
> +                       gpiod_direction_output(led->aux_gpio, KTD2692_LOW);

Redundant change.

...

> -               gpiod_direction_output(led->aux_gpio, KTD2692_HIGH);
> +               if (led->aux_gpio)
> +                       gpiod_direction_output(led->aux_gpio, KTD2692_HIGH);

Ditto.

...

> -               gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
> +               if (led->aux_gpio)
> +                       gpiod_direction_output(led->aux_gpio, KTD2692_LOW);

Ditto.

...

> -       gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
> +       if (led->aux_gpio)
> +               gpiod_direction_output(led->aux_gpio, KTD2692_LOW);

Ditto.

...

>         ret = PTR_ERR_OR_ZERO(led->aux_gpio);
> -       if (ret) {
> -               dev_err(dev, "cannot get aux-gpios %d\n", ret);
> -               return ret;
> -       }
> +       if (ret)
> +               dev_info(dev, "aux-gpios not available, flash mode current might be reduced\n");

dev_warn()?

After this change the use of PTR_ERR_OR_ZERO() becomes unjustified, what about
        if (IS_ERR(led->aux_gpio))
?

But the problem here is the ignorance of important error codes, such a
deferred probe.

What you need is to switch to devm_gpiod_get_optional().
diff mbox series

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index 2db49ea7ae55..8ef5667a1d98 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10479,6 +10479,12 @@  S:	Maintained
 F:	Documentation/devicetree/bindings/leds/backlight/kinetic,ktd253.yaml
 F:	drivers/video/backlight/ktd253-backlight.c
 
+KTD2692 FLASH LED DRIVER
+M:	Markuss Broks <markuss.broks@gmail.com>
+S:	Maintained
+F:	Documentation/devicetree/bindings/leds/backlight/kinetic,ktd2692.yaml
+F:	drivers/leds/flash/leds-ktd2692.yaml
+
 KTEST
 M:	Steven Rostedt <rostedt@goodmis.org>
 M:	John Hawley <warthog9@eaglescrag.net>
diff --git a/drivers/leds/flash/leds-ktd2692.c b/drivers/leds/flash/leds-ktd2692.c
index f341da1503a4..f30c4b11c84b 100644
--- a/drivers/leds/flash/leds-ktd2692.c
+++ b/drivers/leds/flash/leds-ktd2692.c
@@ -163,7 +163,8 @@  static int ktd2692_led_brightness_set(struct led_classdev *led_cdev,
 
 	if (brightness == LED_OFF) {
 		led->mode = KTD2692_MODE_DISABLE;
-		gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
+		if (led->aux_gpio)
+			gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
 	} else {
 		ktd2692_expresswire_write(led, brightness |
 					KTD2692_REG_MOVIE_CURRENT_BASE);
@@ -191,10 +192,12 @@  static int ktd2692_led_flash_strobe_set(struct led_classdev_flash *fled_cdev,
 				| KTD2692_REG_FLASH_TIMEOUT_BASE);
 
 		led->mode = KTD2692_MODE_FLASH;
-		gpiod_direction_output(led->aux_gpio, KTD2692_HIGH);
+		if (led->aux_gpio)
+			gpiod_direction_output(led->aux_gpio, KTD2692_HIGH);
 	} else {
 		led->mode = KTD2692_MODE_DISABLE;
-		gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
+		if (led->aux_gpio)
+			gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
 	}
 
 	ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE);
@@ -248,7 +251,8 @@  static void ktd2692_setup(struct ktd2692_context *led)
 {
 	led->mode = KTD2692_MODE_DISABLE;
 	ktd2692_expresswire_reset(led);
-	gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
+	if (led->aux_gpio)
+		gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
 
 	ktd2692_expresswire_write(led, (KTD2692_MM_MIN_CURR_THRESHOLD_SCALE - 1)
 				 | KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE);
@@ -286,10 +290,8 @@  static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev,
 
 	led->aux_gpio = devm_gpiod_get(dev, "aux", GPIOD_ASIS);
 	ret = PTR_ERR_OR_ZERO(led->aux_gpio);
-	if (ret) {
-		dev_err(dev, "cannot get aux-gpios %d\n", ret);
-		return ret;
-	}
+	if (ret)
+		dev_info(dev, "aux-gpios not available, flash mode current might be reduced\n");
 
 	led->regulator = devm_regulator_get(dev, "vin");
 	if (IS_ERR(led->regulator))