[v5,07/17] gpiolib: Extract gpio_set_config_with_argument_optional() helper

Message ID 20201109205332.19592-8-andriy.shevchenko@linux.intel.com
State New
Headers show
Series
  • gpiolib: acpi: pin configuration fixes
Related show

Commit Message

Andy Shevchenko Nov. 9, 2020, 8:53 p.m.
This function is useful for internal use in GPIO library.
There will be new user coming, prepare a helper for the new comer
and the existing ones.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpiolib.c | 50 ++++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 24 deletions(-)

Comments

Mika Westerberg Nov. 11, 2020, 3:35 p.m. | #1
On Mon, Nov 09, 2020 at 10:53:22PM +0200, Andy Shevchenko wrote:
> This function is useful for internal use in GPIO library.

> There will be new user coming, prepare a helper for the new comer

> and the existing ones.

> 

> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Andy Shevchenko Nov. 11, 2020, 3:42 p.m. | #2
On Mon, Nov 9, 2020 at 10:55 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>

> This function is useful for internal use in GPIO library.

> There will be new user coming, prepare a helper for the new comer

> and the existing ones.


Just to show how temporary variable is re-used here

>         enum pin_config_param mode = PIN_CONFIG_PERSIST_STATE;


> +       return gpio_set_config_with_argument_optional(desc, mode, !transitory);


Leaving constant in the parameter line will make it either long or ugly split.

-- 
With Best Regards,
Andy Shevchenko

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 0691ecbd9a16..4558af08df23 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2105,6 +2105,30 @@  static int gpio_set_config_with_argument(struct gpio_desc *desc,
 	return gpio_do_set_config(gc, gpio_chip_hwgpio(desc), config);
 }
 
+static int gpio_set_config_with_argument_optional(struct gpio_desc *desc,
+						  enum pin_config_param mode,
+						  u32 argument)
+{
+	struct device *dev = &desc->gdev->dev;
+	int gpio = gpio_chip_hwgpio(desc);
+	int ret;
+
+	ret = gpio_set_config_with_argument(desc, mode, argument);
+	if (ret != -ENOTSUPP)
+		return ret;
+
+	switch (mode) {
+	case PIN_CONFIG_PERSIST_STATE:
+		if (ret)
+			dev_dbg(dev, "Persistence not supported for GPIO %d\n", gpio);
+		break;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
 static int gpio_set_config(struct gpio_desc *desc, enum pin_config_param mode)
 {
 	return gpio_set_config_with_argument(desc, mode, 0);
@@ -2114,7 +2138,6 @@  static int gpio_set_bias(struct gpio_desc *desc)
 {
 	enum pin_config_param bias;
 	unsigned int arg;
-	int ret;
 
 	if (test_bit(FLAG_BIAS_DISABLE, &desc->flags))
 		bias = PIN_CONFIG_BIAS_DISABLE;
@@ -2136,11 +2159,7 @@  static int gpio_set_bias(struct gpio_desc *desc)
 		break;
 	}
 
-	ret = gpio_set_config_with_argument(desc, bias, arg);
-	if (ret != -ENOTSUPP)
-		return ret;
-
-	return 0;
+	return gpio_set_config_with_argument_optional(desc, bias, arg);
 }
 
 /**
@@ -2382,10 +2401,6 @@  EXPORT_SYMBOL_GPL(gpiod_set_debounce);
 int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
 {
 	enum pin_config_param mode = PIN_CONFIG_PERSIST_STATE;
-	struct gpio_chip *gc;
-	unsigned long packed;
-	int gpio;
-	int rc;
 
 	VALIDATE_DESC(desc);
 	/*
@@ -2395,20 +2410,7 @@  int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
 	assign_bit(FLAG_TRANSITORY, &desc->flags, transitory);
 
 	/* If the driver supports it, set the persistence state now */
-	gc = desc->gdev->chip;
-	if (!gc->set_config)
-		return 0;
-
-	packed = pinconf_to_config_packed(mode, !transitory);
-	gpio = gpio_chip_hwgpio(desc);
-	rc = gpio_do_set_config(gc, gpio, packed);
-	if (rc == -ENOTSUPP) {
-		dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",
-				gpio);
-		return 0;
-	}
-
-	return rc;
+	return gpio_set_config_with_argument_optional(desc, mode, !transitory);
 }
 EXPORT_SYMBOL_GPL(gpiod_set_transitory);