Skip to contentSkip to conversation

gpio: omap: improve coding style for pin config flags

PATCH In review Drew Fustini 5 participants 6 messages Jul 22, 2020 – Aug 20, 2020

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

PATCH 1/1 gpio: omap: improve coding style for pin config flags

Change the handling of pin config flags from if/else to switch statement to make the code more readable and cleaner.

---
 drivers/gpio/gpio-omap.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpio/gpio-omap.c +9 -4
index e0eada82178c..7fbe0c9e1fc1 100644
@@ -899,13 +899,18 @@ static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset,
 	u32 debounce;
 	int ret = -ENOTSUPP;
 
-	if ((pinconf_to_config_param(config) == PIN_CONFIG_BIAS_DISABLE) ||
-	    (pinconf_to_config_param(config) == PIN_CONFIG_BIAS_PULL_UP) ||
-	    (pinconf_to_config_param(config) == PIN_CONFIG_BIAS_PULL_DOWN)) {
+	switch (pinconf_to_config_param(config)) {
+	case PIN_CONFIG_BIAS_DISABLE:
+	case PIN_CONFIG_BIAS_PULL_UP:
+	case PIN_CONFIG_BIAS_PULL_DOWN:
 		ret = gpiochip_generic_config(chip, offset, config);
-	} else if (pinconf_to_config_param(config) == PIN_CONFIG_INPUT_DEBOUNCE) {
+		break;
+	case PIN_CONFIG_INPUT_DEBOUNCE:
 		debounce = pinconf_to_config_argument(config);
 		ret = omap_gpio_debounce(chip, offset, debounce);
+		break;
+	default:
+		break;
 	}
 
 	return ret;
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Drew Fustini

Change the handling of pin config flags from if/else to switch statement to make the code more readable and cleaner.

Thanks, Drew.
--
Gustavo

Quoted 34 lines
---
 drivers/gpio/gpio-omap.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpio/gpio-omap.c +9 -4
index e0eada82178c..7fbe0c9e1fc1 100644
@@ -899,13 +899,18 @@ static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset,
 	u32 debounce;
 	int ret = -ENOTSUPP;
 
-	if ((pinconf_to_config_param(config) == PIN_CONFIG_BIAS_DISABLE) ||
-	    (pinconf_to_config_param(config) == PIN_CONFIG_BIAS_PULL_UP) ||
-	    (pinconf_to_config_param(config) == PIN_CONFIG_BIAS_PULL_DOWN)) {
+	switch (pinconf_to_config_param(config)) {
+	case PIN_CONFIG_BIAS_DISABLE:
+	case PIN_CONFIG_BIAS_PULL_UP:
+	case PIN_CONFIG_BIAS_PULL_DOWN:
 		ret = gpiochip_generic_config(chip, offset, config);
-	} else if (pinconf_to_config_param(config) == PIN_CONFIG_INPUT_DEBOUNCE) {
+		break;
+	case PIN_CONFIG_INPUT_DEBOUNCE:
 		debounce = pinconf_to_config_argument(config);
 		ret = omap_gpio_debounce(chip, offset, debounce);
+		break;
+	default:
+		break;
 	}
 
 	return ret;
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#3 lore raw
In reply to Drew Fustini

Hi,

Quoted 5 lines · Drew Fustini

Change the handling of pin config flags from if/else to switch statement to make the code more readable and cleaner.

This looks OK to me:

I've lost track of the pending pinctrl/gpio/dts patches you've posted :) Care to also summarized the pending ones and repost them now that v5.9-rc1 is out?

Regards,

Tony

Quoted 34 lines
---
 drivers/gpio/gpio-omap.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpio/gpio-omap.c +9 -4
index e0eada82178c..7fbe0c9e1fc1 100644
@@ -899,13 +899,18 @@ static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset,
 	u32 debounce;
 	int ret = -ENOTSUPP;
 
-	if ((pinconf_to_config_param(config) == PIN_CONFIG_BIAS_DISABLE) ||
-	    (pinconf_to_config_param(config) == PIN_CONFIG_BIAS_PULL_UP) ||
-	    (pinconf_to_config_param(config) == PIN_CONFIG_BIAS_PULL_DOWN)) {
+	switch (pinconf_to_config_param(config)) {
+	case PIN_CONFIG_BIAS_DISABLE:
+	case PIN_CONFIG_BIAS_PULL_UP:
+	case PIN_CONFIG_BIAS_PULL_DOWN:
 		ret = gpiochip_generic_config(chip, offset, config);
-	} else if (pinconf_to_config_param(config) == PIN_CONFIG_INPUT_DEBOUNCE) {
+		break;
+	case PIN_CONFIG_INPUT_DEBOUNCE:
 		debounce = pinconf_to_config_argument(config);
 		ret = omap_gpio_debounce(chip, offset, debounce);
+		break;
+	default:
+		break;
 	}
 
 	return ret;
Signature · 1 line
2.25.1
#4 lore raw
Quoted 9 lines · Tony Lindgren

Hi,

Quoted 5 lines · Drew Fustini

Change the handling of pin config flags from if/else to switch statement to make the code more readable and cleaner.

Quoted 7 lines

This looks OK to me:

I've lost track of the pending pinctrl/gpio/dts patches you've posted :) Care to also summarized the pending ones and repost them now that v5.9-rc1 is out?

Everything appears to be in mainline already:

commit f1b206cf7c57561ea156798f323b0541a783bd2f

Author: Drew Fustini <[email protected]>
Date:   Wed Jul 22 14:27:52 2020 +0200

pinctrl: core: print gpio in pins debugfs file

commit bde8c0e64c78633612aaf283692f72bef0bbc549

Author: Drew Fustini <[email protected]>
Date:   Wed Jul 22 14:07:56 2020 +0200

gpio: omap: improve coding style for pin config flags

commit 75dec56710dfafd37daa95e756c5d1840932ba90

Author: Drew Fustini <[email protected]>
Date:   Fri Jul 17 21:40:43 2020 +0200

gpio: omap: handle pin config bias flags

commit 40e30d26d909af89de2dcd0b4abdd27c47ac2235

Author: Drew Fustini <[email protected]>
Date:   Wed Jul 15 23:37:38 2020 +0200

gpio: omap: handle pin config bias flags

commit abe4e4675dfc62b7f2328e2c4bce8b5bdcdff7c0

Author: Drew Fustini <[email protected]>
Date:   Sun Jul 12 12:37:19 2020 +0200

ARM: dts: am335x-pocketbeagle: set default mux for gpio pins

commit bc6d201591344aa21d616179ee9ad406a7336267

Author: Drew Fustini <[email protected]>
Date:   Wed Jun 17 20:05:43 2020 +0200

pinctrl: single: fix function name in documentation

commit 27c90e5e48d008bfda1cf6108eb699697317c67b

Author: Drew Fustini <[email protected]>
Date:   Wed Jul 1 03:33:20 2020 +0200

ARM: dts: am33xx-l4: change #pinctrl-cells from 1 to 2

commit a133954188887a830b5ce438a287a5e4e234b1be

Author: Drew Fustini <[email protected]>
Date:   Wed Jul 1 03:33:19 2020 +0200

pinctrl: single: parse #pinctrl-cells = 2

commit e14d2c766392ff1f226017fd62f0b6283a53bd0c

Author: Drew Fustini <[email protected]>
Date:   Thu Jun 18 20:29:21 2020 +0200

ARM: dts: am335x-pocketbeagle: add gpio-line-names

commit aafd897a5ac4cb7f9b4f99acc5365a7df1f77aa0

Author: Drew Fustini <[email protected]>
Date:   Thu May 21 22:09:26 2020 +0200

ARM: dts: am335x-boneblack: add gpio-line-names

commit ff82009fcc6ace774570107750f5af91c9081b0a

Author: Drew Fustini <[email protected]>
Date:   Wed Jun 10 13:02:58 2020 +0200

ARM: dts: am33xx-l4: add gpio-ranges

commit 25fae752156db7253471347df08a2700501eafde

Author: Drew Fustini <[email protected]>
Date:   Fri Jun 12 13:27:58 2020 +0200

pinctrl: single: fix function name in documentation

commit 80bf72598663496d08b3c0231377db6a99d7fd68

Author: Drew Fustini <[email protected]>
Date:   Mon Jun 15 17:57:01 2020 +0200

ARM: dts: am5729: beaglebone-ai: fix rgmii phy-mode

commit d7af722344e6dc52d87649100516515263e15c75

Author: Drew Fustini <[email protected]>
Date:   Tue Jun 9 23:45:21 2020 +0200

ARM: dts: am335x-pocketbeagle: Fix mmc0 Write Protect

commit f46fe79ff1b65692a65266a5bec6dbe2bf7fc70f

Author: Drew Fustini <[email protected]>
Date:   Mon Jun 8 14:51:43 2020 +0200

pinctrl-single: fix pcs_parse_pinconf() return value

Author: Drew Fustini <[email protected]>
Date:   Fri Apr 3 21:19:31 2020 +0200

dt-bindings: Add vendor prefix for BeagleBoard.org

The only thing that isn't would be "ARM: dts: am33xx: add ocp label" which you applied to omap-for-v5.9/dt.

thanks,
drew

maintainer Acked-by on v1 1/1
#5 lore raw
In reply to Drew Fustini
Quoted 27 lines · Drew Fustini

Change the handling of pin config flags from if/else to switch statement to make the code more readable and cleaner.

---
  drivers/gpio/gpio-omap.c | 13 +++++++++----
  1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpio/gpio-omap.c +4 -4
index e0eada82178c..7fbe0c9e1fc1 100644
@@ -899,13 +899,18 @@ static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset,
  	u32 debounce;
  	int ret = -ENOTSUPP;
 
-	if ((pinconf_to_config_param(config) == PIN_CONFIG_BIAS_DISABLE) ||
-	    (pinconf_to_config_param(config) == PIN_CONFIG_BIAS_PULL_UP) ||
-	    (pinconf_to_config_param(config) == PIN_CONFIG_BIAS_PULL_DOWN)) {
+	switch (pinconf_to_config_param(config)) {
+	case PIN_CONFIG_BIAS_DISABLE:
+	case PIN_CONFIG_BIAS_PULL_UP:
+	case PIN_CONFIG_BIAS_PULL_DOWN:
  		ret = gpiochip_generic_config(chip, offset, config);
-	} else if (pinconf_to_config_param(config) == PIN_CONFIG_INPUT_DEBOUNCE) {

drivers/gpio/gpio-omap.c static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset, · line 916

Quoted 10 lines
drivers/gpio/gpio-omap.c +5 -0
+		break;
+	case PIN_CONFIG_INPUT_DEBOUNCE:
  		debounce = pinconf_to_config_argument(config);
  		ret = omap_gpio_debounce(chip, offset, debounce);
+		break;
+	default:
+		break;
  	}
 
  	return ret;

Thank you.

Signature · 2 lines
Best regards,
grygorii