gpio: omap: handle pin config bias flags
Subsystems (2)
PATCH v3 1/1 gpio: omap: handle pin config bias flags
Modify omap_gpio_set_config() to handle pin config bias flags by calling gpiochip_generic_config().
The pin group for the gpio line must have the corresponding pinconf properties:
PIN_CONFIG_BIAS_PULL_UP requires "pinctrl-single,bias-pullup" PIN_CONFIG_BIAS_PULL_DOWN requires "pinctrl-single,bias-pulldown"
This is necessary for pcs_pinconf_set() to find the requested bias parameter in the PIN_MAP_TYPE_CONFIGS_GROUP pinctrl map.
--- drivers/gpio/gpio-omap.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
v3 changes:
- adjust the braces to match the correct coding style
- note: I originally re-submitted this as v2 by accident when it should have been v3. Sorry for the noise.
v2 changes:
- simplify handling of -ENOTSUPP return value per Grygorii's suggestion
drivers/gpio/gpio-omap.c +11 -5
@@ -896,12 +896,18 @@ static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset, unsigned long config) {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 )) { + ret =gpiochip_generic_config (chip, offset, config); + }else if (pinconf_to_config_param (config) ==PIN_CONFIG_INPUT_DEBOUNCE ) { + debounce =pinconf_to_config_argument (config); + ret =omap_gpio_debounce (chip, offset, debounce); + } -if (pinconf_to_config_param (config) !=PIN_CONFIG_INPUT_DEBOUNCE ) -return -ENOTSUPP ; - - debounce =pinconf_to_config_argument (config); -return omap_gpio_debounce (chip, offset, debounce); +return ret; }static void omap_gpio_set (struct gpio_chip *chip,unsigned offset,int value)
Signature · 1 line
2.25.1
Hi Drew,
Somehow I ran into this patch in Linus' tree:
Please, see some comments below...
Quoted 48 lines · Drew Fustini
Modify
omap_gpio_set_config()to handle pin config bias flags by callinggpiochip_generic_config().The pin group for the gpio line must have the corresponding pinconf properties:
PIN_CONFIG_BIAS_PULL_UPrequires "pinctrl-single,bias-pullup"PIN_CONFIG_BIAS_PULL_DOWNrequires "pinctrl-single,bias-pulldown"This is necessary for
pcs_pinconf_set()to find the requested bias parameter in thePIN_MAP_TYPE_CONFIGS_GROUPpinctrl map.Signed-off-by Drew Fustini <[email protected]>Acked-by Tony Lindgren <[email protected]>Signed-off-by Linus Walleij <[email protected]>--- drivers/gpio/gpio-omap.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)v3 changes:
- adjust the braces to match the correct coding style
- note: I originally re-submitted this as v2 by accident when it should have been v3. Sorry for the noise.v2 changes:
- simplify handling of-ENOTSUPPreturn value per Grygorii's suggestiondrivers/gpio/gpio-omap.c +10
-0@@ -896,12 +896,18 @@ static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset, unsigned long config) {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 )) { + ret =gpiochip_generic_config (chip, offset, config); + }else if (pinconf_to_config_param (config) ==PIN_CONFIG_INPUT_DEBOUNCE ) { + debounce =pinconf_to_config_argument (config); + ret =omap_gpio_debounce (chip, offset, debounce); + }
drivers/gpio/gpio-omap.c static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset, · line 913
Quoted 10 lines
drivers/gpio/gpio-omap.c +1
-5-if (pinconf_to_config_param (config) !=PIN_CONFIG_INPUT_DEBOUNCE ) -return -ENOTSUPP ; - - debounce =pinconf_to_config_argument (config); -return omap_gpio_debounce (chip, offset, debounce); +return ret; }static void omap_gpio_set (struct gpio_chip *chip,unsigned offset,int value)
Maybe next time you could consider coding something like this, instead:
drivers/gpio/gpio-omap.c +9 -7
@@ -899,16 +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;
It looks a bit more readable and cleaner. :)
Thanks
--
Gustavo
Quoted 101 lines · Gustavo A. R. Silva
Hi Drew,
Somehow I ran into this patch in Linus' tree:
Please, see some comments below...
Quoted 48 lines · Drew Fustini
Modify
omap_gpio_set_config()to handle pin config bias flags by callinggpiochip_generic_config().The pin group for the gpio line must have the corresponding pinconf properties:
PIN_CONFIG_BIAS_PULL_UPrequires "pinctrl-single,bias-pullup"PIN_CONFIG_BIAS_PULL_DOWNrequires "pinctrl-single,bias-pulldown"This is necessary for
pcs_pinconf_set()to find the requested bias parameter in thePIN_MAP_TYPE_CONFIGS_GROUPpinctrl map.Signed-off-by Drew Fustini <[email protected]>Acked-by Tony Lindgren <[email protected]>Signed-off-by Linus Walleij <[email protected]>--- drivers/gpio/gpio-omap.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)v3 changes:
- adjust the braces to match the correct coding style
- note: I originally re-submitted this as v2 by accident when it should have been v3. Sorry for the noise.v2 changes:
- simplify handling of-ENOTSUPPreturn value per Grygorii's suggestiondrivers/gpio/gpio-omap.c +10
-0@@ -896,12 +896,18 @@ static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset, unsigned long config) {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 )) { + ret =gpiochip_generic_config (chip, offset, config); + }else if (pinconf_to_config_param (config) ==PIN_CONFIG_INPUT_DEBOUNCE ) { + debounce =pinconf_to_config_argument (config); + ret =omap_gpio_debounce (chip, offset, debounce); + }drivers/gpio/gpio-omap.c static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset, · line 913
Quoted 10 lines
drivers/gpio/gpio-omap.c +1
-5-if (pinconf_to_config_param (config) !=PIN_CONFIG_INPUT_DEBOUNCE ) -return -ENOTSUPP ; - - debounce =pinconf_to_config_argument (config); -return omap_gpio_debounce (chip, offset, debounce); +return ret; }static void omap_gpio_set (struct gpio_chip *chip,unsigned offset,int value)Maybe next time you could consider coding something like this, instead:
drivers/gpio/gpio-omap.c +9
-7@@ -899,16 +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;
Quoted 5 lines
It looks a bit more readable and cleaner. :)
Thanks
--
Gustavo
Gustavo - thanks very much for the feedback. I appreciate getting these insights into best practices.
Linus - should I submit a patch?
I'm not sure if it is better to limit churn, or make sure the code is structured as best is possible.
Thanks,
Drew
Quoted 1 line · Drew Fustini
Linus - should I submit a patch?
Yeps, normally always submit a patch to fix something that is applied already.
Yours,
Linus Walleij