[PATCH 2/2] pinctrl: cirrus: cs42l43: use new GPIO line value setter callbacks

Bartosz Golaszewski posted 2 patches 4 months ago
[PATCH 2/2] pinctrl: cirrus: cs42l43: use new GPIO line value setter callbacks
Posted by Bartosz Golaszewski 4 months ago
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

struct gpio_chip now has callbacks for setting line values that return
an integer, allowing to indicate failures. Convert the driver to using
them.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/pinctrl/cirrus/pinctrl-cs42l43.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/pinctrl/cirrus/pinctrl-cs42l43.c b/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
index 628b60ccc2b07dc77e36da8919436fa348749e0c..29ed985273eb47d06f6cf5e6e41078deae4cc2bb 100644
--- a/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
+++ b/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
@@ -483,7 +483,8 @@ static int cs42l43_gpio_get(struct gpio_chip *chip, unsigned int offset)
 	return ret;
 }
 
-static void cs42l43_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
+static int cs42l43_gpio_set(struct gpio_chip *chip, unsigned int offset,
+			    int value)
 {
 	struct cs42l43_pin *priv = gpiochip_get_data(chip);
 	unsigned int shift = offset + CS42L43_GPIO1_LVL_SHIFT;
@@ -493,23 +494,27 @@ static void cs42l43_gpio_set(struct gpio_chip *chip, unsigned int offset, int va
 		offset + 1, str_high_low(value));
 
 	ret = pm_runtime_resume_and_get(priv->dev);
-	if (ret) {
-		dev_err(priv->dev, "Failed to resume for set: %d\n", ret);
-		return;
-	}
+	if (ret)
+		return ret;
 
 	ret = regmap_update_bits(priv->regmap, CS42L43_GPIO_CTRL1,
 				 BIT(shift), value << shift);
 	if (ret)
-		dev_err(priv->dev, "Failed to set gpio%d: %d\n", offset + 1, ret);
+		return ret;
 
 	pm_runtime_put(priv->dev);
+
+	return 0;
 }
 
 static int cs42l43_gpio_direction_out(struct gpio_chip *chip,
 				      unsigned int offset, int value)
 {
-	cs42l43_gpio_set(chip, offset, value);
+	int ret;
+
+	ret = cs42l43_gpio_set(chip, offset, value);
+	if (ret)
+		return ret;
 
 	return pinctrl_gpio_direction_output(chip, offset);
 }
@@ -550,7 +555,7 @@ static int cs42l43_pin_probe(struct platform_device *pdev)
 	priv->gpio_chip.direction_output = cs42l43_gpio_direction_out;
 	priv->gpio_chip.add_pin_ranges = cs42l43_gpio_add_pin_ranges;
 	priv->gpio_chip.get = cs42l43_gpio_get;
-	priv->gpio_chip.set = cs42l43_gpio_set;
+	priv->gpio_chip.set_rv = cs42l43_gpio_set;
 	priv->gpio_chip.label = dev_name(priv->dev);
 	priv->gpio_chip.parent = priv->dev;
 	priv->gpio_chip.can_sleep = true;

-- 
2.48.1
Re: [PATCH 2/2] pinctrl: cirrus: cs42l43: use new GPIO line value setter callbacks
Posted by Charles Keepax 4 months ago
On Thu, Jun 12, 2025 at 02:19:54PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> struct gpio_chip now has callbacks for setting line values that return
> an integer, allowing to indicate failures. Convert the driver to using
> them.
> 
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
> +static int cs42l43_gpio_set(struct gpio_chip *chip, unsigned int offset,
> +			    int value)
>  {
>  	struct cs42l43_pin *priv = gpiochip_get_data(chip);
>  	unsigned int shift = offset + CS42L43_GPIO1_LVL_SHIFT;
> @@ -493,23 +494,27 @@ static void cs42l43_gpio_set(struct gpio_chip *chip, unsigned int offset, int va
>  		offset + 1, str_high_low(value));
>  
>  	ret = pm_runtime_resume_and_get(priv->dev);
> -	if (ret) {
> -		dev_err(priv->dev, "Failed to resume for set: %d\n", ret);
> -		return;
> -	}
> +	if (ret)
> +		return ret;

Is there a reason to lose the error message here? Always nice to
know which of the two paths failed when things go bad.

Thanks,
Charles
>  
>  	ret = regmap_update_bits(priv->regmap, CS42L43_GPIO_CTRL1,
>  				 BIT(shift), value << shift);
>  	if (ret)
> -		dev_err(priv->dev, "Failed to set gpio%d: %d\n", offset + 1, ret);
> +		return ret;
>  
>  	pm_runtime_put(priv->dev);
> +
> +	return 0;
>  }
Re: [PATCH 2/2] pinctrl: cirrus: cs42l43: use new GPIO line value setter callbacks
Posted by Bartosz Golaszewski 4 months ago
On Thu, Jun 12, 2025 at 2:36 PM Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:
>
> On Thu, Jun 12, 2025 at 02:19:54PM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
> > struct gpio_chip now has callbacks for setting line values that return
> > an integer, allowing to indicate failures. Convert the driver to using
> > them.
> >
> > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > ---
> > +static int cs42l43_gpio_set(struct gpio_chip *chip, unsigned int offset,
> > +                         int value)
> >  {
> >       struct cs42l43_pin *priv = gpiochip_get_data(chip);
> >       unsigned int shift = offset + CS42L43_GPIO1_LVL_SHIFT;
> > @@ -493,23 +494,27 @@ static void cs42l43_gpio_set(struct gpio_chip *chip, unsigned int offset, int va
> >               offset + 1, str_high_low(value));
> >
> >       ret = pm_runtime_resume_and_get(priv->dev);
> > -     if (ret) {
> > -             dev_err(priv->dev, "Failed to resume for set: %d\n", ret);
> > -             return;
> > -     }
> > +     if (ret)
> > +             return ret;
>
> Is there a reason to lose the error message here? Always nice to
> know which of the two paths failed when things go bad.
>

No reason other than being in line with most other drivers which
typically just return a value without a message. I don't care much, we
can restore it.

Bart

> Thanks,
> Charles
> >
> >       ret = regmap_update_bits(priv->regmap, CS42L43_GPIO_CTRL1,
> >                                BIT(shift), value << shift);
> >       if (ret)
> > -             dev_err(priv->dev, "Failed to set gpio%d: %d\n", offset + 1, ret);
> > +             return ret;
> >
> >       pm_runtime_put(priv->dev);
> > +
> > +     return 0;
> >  }
Re: [PATCH 2/2] pinctrl: cirrus: cs42l43: use new GPIO line value setter callbacks
Posted by Charles Keepax 4 months ago
On Thu, Jun 12, 2025 at 02:45:45PM +0200, Bartosz Golaszewski wrote:
> On Thu, Jun 12, 2025 at 2:36 PM Charles Keepax
> <ckeepax@opensource.cirrus.com> wrote:
> >
> > On Thu, Jun 12, 2025 at 02:19:54PM +0200, Bartosz Golaszewski wrote:
> > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > >
> > > struct gpio_chip now has callbacks for setting line values that return
> > > an integer, allowing to indicate failures. Convert the driver to using
> > > them.
> > >
> > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > > ---
> > > +static int cs42l43_gpio_set(struct gpio_chip *chip, unsigned int offset,
> > > +                         int value)
> > >  {
> > >       struct cs42l43_pin *priv = gpiochip_get_data(chip);
> > >       unsigned int shift = offset + CS42L43_GPIO1_LVL_SHIFT;
> > > @@ -493,23 +494,27 @@ static void cs42l43_gpio_set(struct gpio_chip *chip, unsigned int offset, int va
> > >               offset + 1, str_high_low(value));
> > >
> > >       ret = pm_runtime_resume_and_get(priv->dev);
> > > -     if (ret) {
> > > -             dev_err(priv->dev, "Failed to resume for set: %d\n", ret);
> > > -             return;
> > > -     }
> > > +     if (ret)
> > > +             return ret;
> >
> > Is there a reason to lose the error message here? Always nice to
> > know which of the two paths failed when things go bad.
> >
> 
> No reason other than being in line with most other drivers which
> typically just return a value without a message. I don't care much, we
> can restore it.
> 

I guess it doesn't generally fail, but I am probably more
comfortable leaving it. So lets go with that if you are easy
either way. With that:

Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>

Thanks,
Charles