Skip to contentSkip to conversation

Make AUX gpio pin optional for ktd2692

PATCH Applied Markuss Broks 3 participants 9 messages May 5, 2022 – May 8, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v8 cover Make AUX gpio pin optional for ktd2692

Some appliances of ktd2692 don't have the AUX pin connected to a GPIO. Specifically, Samsung Galaxy J5 (2015), which uses ktd2692 for driving the front flash LED, has the pin not connected anywhere on schematics. Make specifying the AUX pin optional, since it is additional functionality and only affects the amount of current going through the LED.

Also convert the txt device-tree bindings to yaml.

v2:
- fix the dt_binding_check
v3:
- set the aux_gpio to NULL to avoid passing ERR_PTR as a gpio v4:
- maintainership -> maintenance (description)
- remove the if (led->aux_gpio)
- use devm_gpiod_get_optional for aux gpio
v5:
- use ret to pass a correct error return code (Christophe) v6:
- use PTR_ERR properly (when IS_ERR is true) (Christophe) v6-a:
- ended up being a mess, corrected-v2 should have proper tags now v7:
- drop the MAINTAINERS part
v8:
- introduce a patch changing dev_err in gpio access to dev_err_probe

Markuss Broks (2):
dt-bindings: leds: convert ktd2692 bindings to yaml
leds: ktd2692: Make aux-gpios optional

 .../bindings/leds/kinetic,ktd2692.yaml        | 87 +++++++++++++++++++
 .../devicetree/bindings/leds/leds-ktd2692.txt | 50 -----------
 MAINTAINERS                                   |  6 ++
 drivers/leds/flash/leds-ktd2692.c             | 18 ++--
 4 files changed, 103 insertions(+), 58 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/leds/kinetic,ktd2692.yaml
 delete mode 100644 Documentation/devicetree/bindings/leds/leds-ktd2692.txt
Signature · 1 line
2.35.1
#1 lore raw

PATCH v8 1/3 leds: ktd2692: Avoid duplicate error messages on probe deferral

Use dev_err_probe instead of dev_err to avoid duplicate error messages if the GPIO allocation makes the probe defer.

---
 drivers/leds/flash/leds-ktd2692.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/leds/flash/leds-ktd2692.c +4 -8
index ed1f20a58bf6..8b99742cb68a 100644
@@ -279,17 +279,13 @@ static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev,
 
 	led->ctrl_gpio = devm_gpiod_get(dev, "ctrl", GPIOD_ASIS);
 	ret = PTR_ERR_OR_ZERO(led->ctrl_gpio);
-	if (ret) {
-		dev_err(dev, "cannot get ctrl-gpios %d\n", ret);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "cannot get ctrl-gpios\n");
 
 	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)
+		return dev_err_probe(dev, PTR_ERR(led->aux_gpio), "cannot get aux-gpios\n");
 
 	led->regulator = devm_regulator_get(dev, "vin");
 	if (IS_ERR(led->regulator))
Signature · 1 line
2.35.1
#2 lore raw

Re: [PATCH v8 1/3] leds: ktd2692: Avoid duplicate error messages on probe deferral

Quoted 3 lines · Markuss Broks

Use dev_err_probe instead of dev_err to avoid duplicate error messages if the GPIO allocation makes the probe defer.

Thanks!

There are two improvements we can make here.
1) adding a Fixes tag, so it can be backported to stable kernels;
2) see below.

...

drivers/leds/flash/leds-ktd2692.c static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev, · line 283

Quoted 8 lines
        led->ctrl_gpio = devm_gpiod_get(dev, "ctrl", GPIOD_ASIS);
        ret = PTR_ERR_OR_ZERO(led->ctrl_gpio);
drivers/leds/flash/leds-ktd2692.c +2 -4
-       if (ret) {
-               dev_err(dev, "cannot get ctrl-gpios %d\n", ret);
-               return ret;
-       }
+       if (ret)
+               return dev_err_probe(dev, ret, "cannot get ctrl-gpios\n");

You may improve this and simultaneously prepare for the next change to be smaller

       led->ctrl_gpio = devm_gpiod_get(dev, "ctrl", GPIOD_ASIS);
       if (IS_ERR(led->ctrl_gpio))
               return dev_err_probe(dev, PTR_ERR(led->ctrl_gpio),

"cannot get ctrl-gpios\n");

All the same for the other case.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Re: [PATCH v8 1/3] leds: ktd2692: Avoid duplicate error messages on probe deferral

Quoted 1 line · Andy Shevchenko

On Thu, May 5, 2022 at 5:25 PM Markuss Broks <[email protected]> wrote:

...

Quoted 1 line

1) adding a Fixes tag, so it can be backported to stable kernels;

To avoid additional versions in case you don't know how Fixes tag should look like:

Fixes b7da8c5c725c ("leds: Add ktd2692 flash LED driver")

Just add this before other tags, like SoB or Reviewed-by (no blank lines in the tag block).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v8 1/3] leds: ktd2692: Avoid duplicate error messages on probe deferral

In reply to Andy Shevchenko

Hi!

Quoted 8 lines
Quoted 2 lines

Use dev_err_probe instead of dev_err to avoid duplicate error messages if the GPIO allocation makes the probe defer.

Thanks!

There are two improvements we can make here.
1) adding a Fixes tag, so it can be backported to stable kernels;
2) see below.

I don't believe this is severe-enough error to be worth stable.

Best regards,
Pavel

Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.
#5 lore raw

Re: [PATCH v8 1/3] leds: ktd2692: Avoid duplicate error messages on probe deferral

Quoted 6 lines · Pavel Machek

Hi!

Quoted 3 lines
Quoted 2 lines

Use dev_err_probe instead of dev_err to avoid duplicate error messages if the GPIO allocation makes the probe defer.

Quoted 7 lines
Quoted 5 lines

Thanks!

There are two improvements we can make here.
1) adding a Fixes tag, so it can be backported to stable kernels;
2) see below.

I don't believe this is severe-enough error to be worth stable.

Fixes tag is good to have in either case, but I agree that is not so critical.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

PATCH v8 2/3 dt-bindings: leds: convert ktd2692 bindings to yaml

In reply to Markuss Broks

This patch converts the leds-ktd2692.txt bindings to modern yaml style device-tree bindings.

---
 .../bindings/leds/kinetic,ktd2692.yaml        | 87 +++++++++++++++++++
 .../devicetree/bindings/leds/leds-ktd2692.txt | 50 -----------
 2 files changed, 87 insertions(+), 50 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/leds/kinetic,ktd2692.yaml
 delete mode 100644 Documentation/devicetree/bindings/leds/leds-ktd2692.txt
Documentation/devicetree/bindings/leds/kinetic,ktd2692.yaml new file +87 -0
new file mode 100644
index 000000000000..bac95a51afa1
@@ -0,0 +1,87 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/kinetic,ktd2692.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: KTD2692 Flash LED Driver from Kinetic Technologies
+
+maintainers:
+  - Markuss Broks <[email protected]>
+
+description: |
+  KTD2692 is the ideal power solution for high-power flash LEDs.
+  It uses ExpressWire single-wire programming for maximum flexibility.
+
+  The ExpressWire interface through CTRL pin can control LED on/off and
+  enable/disable the IC, Movie(max 1/3 of Flash current) / Flash mode current,
+  Flash timeout, LVP(low voltage protection).
+
+  Also, When the AUX pin is pulled high while CTRL pin is high,
+  LED current will be ramped up to the flash-mode current level.
+
+properties:
+  compatible:
+    const: kinetic,ktd2692
+
+  ctrl-gpios:
+    maxItems: 1
+    description: Specifier of the GPIO connected to CTRL pin.
+
+  aux-gpios:
+    maxItems: 1
+    description: Specifier of the GPIO connected to CTRL pin.
+
+  vin-supply:
+    description: LED supply (2.7V to 5.5V).
+
+  led:
+    type: object
+    $ref: common.yaml#
+    description: Properties for the LED.
+    properties:
+      function: true
+      color: true
+      flash-max-timeout-us:
+        description: Flash LED maximum timeout.
+
+      led-max-microamp:
+        maximum: 300000
+        description: Minimum Threshold for Timer protection
+          is defined internally (Maximum 300mA).
+
+      flash-max-microamp:
+        maximum: 300000
+        description: Flash LED maximum current
+          Formula - I(uA) = 15000000 / Rset.
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - ctrl-gpios
+  - led
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/leds/common.h>
+
+    ktd2692 {
+      compatible = "kinetic,ktd2692";
+      ctrl-gpios = <&gpc0 1 0>;
+      aux-gpios = <&gpc0 2 0>;
+      vin-supply = <&vbat>;
+
+      led {
+        function = LED_FUNCTION_FLASH;
+        color = <LED_COLOR_ID_WHITE>;
+        flash-max-timeout-us = <250000>;
+        flash-max-microamp = <150000>;
+        led-max-microamp = <25000>;
+      };
+    };
+
+...
Documentation/devicetree/bindings/leds/leds-ktd2692.txt deleted +0 -50

50 lines not on this page · raw message

Signature · 1 line
2.35.1
#7 lore raw

PATCH v8 3/3 leds: ktd2692: Make aux-gpios optional

In reply to Markuss Broks

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.

---
 drivers/leds/flash/leds-ktd2692.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/leds/flash/leds-ktd2692.c +2 -3
index 8b99742cb68a..670f3bf2e906 100644
@@ -282,9 +282,8 @@ static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev,
 	if (ret)
 		return dev_err_probe(dev, ret, "cannot get ctrl-gpios\n");
 
-	led->aux_gpio = devm_gpiod_get(dev, "aux", GPIOD_ASIS);
-	ret = PTR_ERR_OR_ZERO(led->aux_gpio);
-	if (ret)
+	led->aux_gpio = devm_gpiod_get_optional(dev, "aux", GPIOD_ASIS);
+	if (IS_ERR(led->aux_gpio))
 		return dev_err_probe(dev, PTR_ERR(led->aux_gpio), "cannot get aux-gpios\n");
 
 	led->regulator = devm_regulator_get(dev, "vin");
Signature · 1 line
2.35.1
Applied
#8 lore raw
In reply to Markuss Broks

Hi!

Quoted 7 lines

Some appliances of ktd2692 don't have the AUX pin connected to a GPIO. Specifically, Samsung Galaxy J5 (2015), which uses ktd2692 for driving the front flash LED, has the pin not connected anywhere on schematics. Make specifying the AUX pin optional, since it is additional functionality and only affects the amount of current going through the LED.

Also convert the txt device-tree bindings to yaml.

Thank you, applied.

Best regards,
Pavel

Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.