]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpio: twl4030: use new GPIO line value setter callbacks
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 7 Jul 2025 07:50:20 +0000 (09:50 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Sun, 13 Jul 2025 08:45:04 +0000 (10:45 +0200)
struct gpio_chip now has callbacks for setting line values that return
an integer, allowing to indicate failures. Convert the driver to using
them.

Link: https://lore.kernel.org/r/20250707-gpiochip-set-rv-gpio-round4-v1-7-35668aaaf6d2@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpio-twl4030.c

index c5d7825f19c18bfa84083aa5a46e48d174b8fce6..e39e39e3ef85b7c60c1f29f78c11d6eeccec6206 100644 (file)
@@ -120,7 +120,7 @@ static u8 cached_leden;
  * external pullup is needed.  We could also expose the integrated PWM
  * as a LED brightness control; we initialize it as "always on".
  */
-static void twl4030_led_set_value(int led, int value)
+static int twl4030_led_set_value(int led, int value)
 {
        u8 mask = LEDEN_LEDAON | LEDEN_LEDAPWM;
 
@@ -132,8 +132,8 @@ static void twl4030_led_set_value(int led, int value)
        else
                cached_leden |= mask;
 
-       WARN_ON_ONCE(twl_i2c_write_u8(TWL4030_MODULE_LED, cached_leden,
-                                     TWL4030_LED_LEDEN_REG));
+       return twl_i2c_write_u8(TWL4030_MODULE_LED, cached_leden,
+                               TWL4030_LED_LEDEN_REG);
 }
 
 static int twl4030_set_gpio_direction(int gpio, int is_input)
@@ -278,7 +278,7 @@ static void twl_free(struct gpio_chip *chip, unsigned offset)
 
        mutex_lock(&priv->mutex);
        if (offset >= TWL4030_GPIO_MAX) {
-               twl4030_led_set_value(offset - TWL4030_GPIO_MAX, 1);
+               WARN_ON_ONCE(twl4030_led_set_value(offset - TWL4030_GPIO_MAX, 1));
                goto out;
        }
 
@@ -334,15 +334,16 @@ out:
        return ret;
 }
 
-static void twl_set(struct gpio_chip *chip, unsigned offset, int value)
+static int twl_set(struct gpio_chip *chip, unsigned int offset, int value)
 {
        struct gpio_twl4030_priv *priv = gpiochip_get_data(chip);
+       int ret;
 
        mutex_lock(&priv->mutex);
        if (offset < TWL4030_GPIO_MAX)
-               twl4030_set_gpio_dataout(offset, value);
+               ret = twl4030_set_gpio_dataout(offset, value);
        else
-               twl4030_led_set_value(offset - TWL4030_GPIO_MAX, value);
+               ret = twl4030_led_set_value(offset - TWL4030_GPIO_MAX, value);
 
        if (value)
                priv->out_state |= BIT(offset);
@@ -350,6 +351,8 @@ static void twl_set(struct gpio_chip *chip, unsigned offset, int value)
                priv->out_state &= ~BIT(offset);
 
        mutex_unlock(&priv->mutex);
+
+       return ret;
 }
 
 static int twl_direction_out(struct gpio_chip *chip, unsigned offset, int value)
@@ -373,9 +376,7 @@ static int twl_direction_out(struct gpio_chip *chip, unsigned offset, int value)
        priv->direction |= BIT(offset);
        mutex_unlock(&priv->mutex);
 
-       twl_set(chip, offset, value);
-
-       return ret;
+       return twl_set(chip, offset, value);
 }
 
 static int twl_get_direction(struct gpio_chip *chip, unsigned offset)
@@ -418,7 +419,7 @@ static const struct gpio_chip template_chip = {
        .direction_output       = twl_direction_out,
        .get_direction          = twl_get_direction,
        .get                    = twl_get,
-       .set                    = twl_set,
+       .set_rv                 = twl_set,
        .to_irq                 = twl_to_irq,
        .can_sleep              = true,
 };