diff mbox series

platform: cznic: use new GPIO line value setter callbacks

Message ID 20250408-gpiochip-set-rv-platform-cznic-v1-1-c3d4e724433f@linaro.org
State New
Headers show
Series platform: cznic: use new GPIO line value setter callbacks | expand

Commit Message

Bartosz Golaszewski April 8, 2025, 7:19 a.m. UTC
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>
---
Commit 98ce1eb1fd87e ("gpiolib: introduce gpio_chip setters that return
values") added new line setter callbacks to struct gpio_chip. They allow
to indicate failures to callers. We're in the process of converting all
GPIO controllers to using them before removing the old ones.
---
 drivers/platform/cznic/turris-omnia-mcu-gpio.c | 35 ++++++++++++++++----------
 1 file changed, 22 insertions(+), 13 deletions(-)


---
base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
change-id: 20250401-gpiochip-set-rv-platform-cznic-1a136bd47a5b

Best regards,

Comments

Marek Behún April 9, 2025, 9:17 a.m. UTC | #1
On Tue, Apr 08, 2025 at 09:19:19AM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

...

> -static void omnia_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
> -				    unsigned long *bits)
> +static int omnia_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
> +				   unsigned long *bits)
>  {
>  	unsigned long ctl = 0, ctl_mask = 0, ext_ctl = 0, ext_ctl_mask = 0;
>  	struct omnia_mcu *mcu = gpiochip_get_data(gc);
>  	unsigned int i;
> +	int ret;

In this driver the name `err' is used everywhere for this kind of
variable (when it contains error code or zero for success).
`ret' is only used if the variable can also contain positive return
value.

Bartosz, I will send updated version, if that is okay with you?

Marek
Bartosz Golaszewski April 9, 2025, 11:03 a.m. UTC | #2
On Wed, Apr 9, 2025 at 11:17 AM Marek Behún <marek.behun@nic.cz> wrote:
>
> On Tue, Apr 08, 2025 at 09:19:19AM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> ...
>
> > -static void omnia_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
> > -                                 unsigned long *bits)
> > +static int omnia_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
> > +                                unsigned long *bits)
> >  {
> >       unsigned long ctl = 0, ctl_mask = 0, ext_ctl = 0, ext_ctl_mask = 0;
> >       struct omnia_mcu *mcu = gpiochip_get_data(gc);
> >       unsigned int i;
> > +     int ret;
>
> In this driver the name `err' is used everywhere for this kind of
> variable (when it contains error code or zero for success).
> `ret' is only used if the variable can also contain positive return
> value.
>
> Bartosz, I will send updated version, if that is okay with you?
>
> Marek

Sure, I can also do it myself if you prefer.

Bart
diff mbox series

Patch

diff --git a/drivers/platform/cznic/turris-omnia-mcu-gpio.c b/drivers/platform/cznic/turris-omnia-mcu-gpio.c
index 5f35f7c5d5d7..df9e4b2c6aaa 100644
--- a/drivers/platform/cznic/turris-omnia-mcu-gpio.c
+++ b/drivers/platform/cznic/turris-omnia-mcu-gpio.c
@@ -438,27 +438,28 @@  static int omnia_gpio_get_multiple(struct gpio_chip *gc, unsigned long *mask,
 	return 0;
 }
 
-static void omnia_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
+static int omnia_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
 {
 	const struct omnia_gpio *gpio = &omnia_gpios[offset];
 	struct omnia_mcu *mcu = gpiochip_get_data(gc);
 	u16 val, mask;
 
 	if (!gpio->ctl_cmd)
-		return;
+		return -EINVAL;
 
 	mask = BIT(gpio->ctl_bit);
 	val = value ? mask : 0;
 
-	omnia_ctl_cmd(mcu, gpio->ctl_cmd, val, mask);
+	return omnia_ctl_cmd(mcu, gpio->ctl_cmd, val, mask);
 }
 
-static void omnia_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
-				    unsigned long *bits)
+static int omnia_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
+				   unsigned long *bits)
 {
 	unsigned long ctl = 0, ctl_mask = 0, ext_ctl = 0, ext_ctl_mask = 0;
 	struct omnia_mcu *mcu = gpiochip_get_data(gc);
 	unsigned int i;
+	int ret;
 
 	for_each_set_bit(i, mask, ARRAY_SIZE(omnia_gpios)) {
 		unsigned long *field, *field_mask;
@@ -487,13 +488,21 @@  static void omnia_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
 
 	guard(mutex)(&mcu->lock);
 
-	if (ctl_mask)
-		omnia_ctl_cmd_locked(mcu, OMNIA_CMD_GENERAL_CONTROL,
-				     ctl, ctl_mask);
+	if (ctl_mask) {
+		ret = omnia_ctl_cmd_locked(mcu, OMNIA_CMD_GENERAL_CONTROL,
+					   ctl, ctl_mask);
+		if (ret)
+			return ret;
+	}
 
-	if (ext_ctl_mask)
-		omnia_ctl_cmd_locked(mcu, OMNIA_CMD_EXT_CONTROL,
-				     ext_ctl, ext_ctl_mask);
+	if (ext_ctl_mask) {
+		ret = omnia_ctl_cmd_locked(mcu, OMNIA_CMD_EXT_CONTROL,
+					   ext_ctl, ext_ctl_mask);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
 }
 
 static bool omnia_gpio_available(struct omnia_mcu *mcu,
@@ -1014,8 +1023,8 @@  int omnia_mcu_register_gpiochip(struct omnia_mcu *mcu)
 	mcu->gc.direction_output = omnia_gpio_direction_output;
 	mcu->gc.get = omnia_gpio_get;
 	mcu->gc.get_multiple = omnia_gpio_get_multiple;
-	mcu->gc.set = omnia_gpio_set;
-	mcu->gc.set_multiple = omnia_gpio_set_multiple;
+	mcu->gc.set_rv = omnia_gpio_set;
+	mcu->gc.set_multiple_rv = omnia_gpio_set_multiple;
 	mcu->gc.init_valid_mask = omnia_gpio_init_valid_mask;
 	mcu->gc.can_sleep = true;
 	mcu->gc.names = omnia_mcu_gpio_names;