linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] pinctrl: Document pin_config_group_get() return codes like pin_config_get()
@ 2018-07-02 22:59 Douglas Anderson
  2018-07-02 22:59 ` [PATCH 2/3] pinctrl: msm: Fix msm_config_group_get() to be compliant Douglas Anderson
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Douglas Anderson @ 2018-07-02 22:59 UTC (permalink / raw)
  To: Bjorn Andersson, Linus Walleij
  Cc: iivanov, swboyd, Douglas Anderson, linux-gpio, linux-kernel

The pinconf_generic_dump_one() function makes the assumption that
pin_config_group_get() should return -EINVAL and -ENOTSUPP just like
pin_config_get() does.  Document that so it's more obvious.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

 include/linux/pinctrl/pinconf.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/pinctrl/pinconf.h b/include/linux/pinctrl/pinconf.h
index 09eb80f2574a..8dd85d302b90 100644
--- a/include/linux/pinctrl/pinconf.h
+++ b/include/linux/pinctrl/pinconf.h
@@ -28,7 +28,8 @@ struct seq_file;
  *	is not available on this controller this should return -ENOTSUPP
  *	and if it is available but disabled it should return -EINVAL
  * @pin_config_set: configure an individual pin
- * @pin_config_group_get: get configurations for an entire pin group
+ * @pin_config_group_get: get configurations for an entire pin group; should
+ *	return -ENOTSUPP and -EINVAL using the same rules as pin_config_get.
  * @pin_config_group_set: configure all pins in a group
  * @pin_config_dbg_parse_modify: optional debugfs to modify a pin configuration
  * @pin_config_dbg_show: optional debugfs display hook that will provide
-- 
2.18.0.399.gad0ab374a1-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] pinctrl: msm: Fix msm_config_group_get() to be compliant
  2018-07-02 22:59 [PATCH 1/3] pinctrl: Document pin_config_group_get() return codes like pin_config_get() Douglas Anderson
@ 2018-07-02 22:59 ` Douglas Anderson
  2018-07-09 11:15   ` Linus Walleij
  2018-07-02 22:59 ` [PATCH 3/3] pinctrl: qcom: spmi-gpio: Fix pmic_gpio_config_get() " Douglas Anderson
  2018-07-09 11:09 ` [PATCH 1/3] pinctrl: Document pin_config_group_get() return codes like pin_config_get() Linus Walleij
  2 siblings, 1 reply; 9+ messages in thread
From: Douglas Anderson @ 2018-07-02 22:59 UTC (permalink / raw)
  To: Bjorn Andersson, Linus Walleij
  Cc: iivanov, swboyd, Douglas Anderson, linux-gpio, linux-kernel,
	linux-arm-msm

If you do this on an sdm845 board:
  cat /sys/kernel/debug/pinctrl/3400000.pinctrl/pinconf-groups

...it looks like nonsense.  For every pin you see listed:
  input bias bus hold, input bias disabled, input bias pull down, input bias pull up

That's because msm_config_group_get() isn't complying with the rules
that pinconf_generic_dump_one() expects.  Specifically for boolean
parameters (anything with a "struct pin_config_item" where has_arg is
false) the function expects that the function should return its value
not through the "config" parameter but should return "0" if the value
is set and "-EINVAL" if the value isn't set.

Let's fix this.

From a quick sample of other pinctrl drivers, it appears to be
tradition to also return 1 through the config parameter for these
boolean parameters when they exist.  I'm not one to knock tradition,
so I'll follow tradition and return 1 in these cases.  While I'm at
it, I'll also continue searching for four leaf clovers, kocking on
wood three times, and trying not to break mirrors.

Fixes: f365be092572 ("pinctrl: Add Qualcomm TLMM driver")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

 drivers/pinctrl/qcom/pinctrl-msm.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c
index 0e22f52b2a19..2155a30c282b 100644
--- a/drivers/pinctrl/qcom/pinctrl-msm.c
+++ b/drivers/pinctrl/qcom/pinctrl-msm.c
@@ -250,22 +250,30 @@ static int msm_config_group_get(struct pinctrl_dev *pctldev,
 	/* Convert register value to pinconf value */
 	switch (param) {
 	case PIN_CONFIG_BIAS_DISABLE:
-		arg = arg == MSM_NO_PULL;
+		if (arg != MSM_NO_PULL)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_BIAS_PULL_DOWN:
-		arg = arg == MSM_PULL_DOWN;
+		if (arg != MSM_PULL_DOWN)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_BIAS_BUS_HOLD:
 		if (pctrl->soc->pull_no_keeper)
 			return -ENOTSUPP;
 
-		arg = arg == MSM_KEEPER;
+		if (arg != MSM_KEEPER)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_BIAS_PULL_UP:
 		if (pctrl->soc->pull_no_keeper)
 			arg = arg == MSM_PULL_UP_NO_KEEPER;
 		else
 			arg = arg == MSM_PULL_UP;
+		if (!arg)
+			return -EINVAL;
 		break;
 	case PIN_CONFIG_DRIVE_STRENGTH:
 		arg = msm_regval_to_drive(arg);
-- 
2.18.0.399.gad0ab374a1-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] pinctrl: qcom: spmi-gpio: Fix pmic_gpio_config_get() to be compliant
  2018-07-02 22:59 [PATCH 1/3] pinctrl: Document pin_config_group_get() return codes like pin_config_get() Douglas Anderson
  2018-07-02 22:59 ` [PATCH 2/3] pinctrl: msm: Fix msm_config_group_get() to be compliant Douglas Anderson
@ 2018-07-02 22:59 ` Douglas Anderson
  2018-07-03  6:09   ` Stephen Boyd
  2018-07-09 11:17   ` Linus Walleij
  2018-07-09 11:09 ` [PATCH 1/3] pinctrl: Document pin_config_group_get() return codes like pin_config_get() Linus Walleij
  2 siblings, 2 replies; 9+ messages in thread
From: Douglas Anderson @ 2018-07-02 22:59 UTC (permalink / raw)
  To: Bjorn Andersson, Linus Walleij
  Cc: iivanov, swboyd, Douglas Anderson, linux-gpio, linux-kernel,
	linux-arm-msm

If you do this on an sdm845 board:
  grep "" /sys/kernel/debug/pinctrl/*spmi:pmic*/pinconf-groups

...it looks like nonsense.  For every pin you see listed:
  input bias disabled, input bias high impedance, input bias pull down, input bias pull up, ...

That's because pmic_gpio_config_get() isn't complying with the rules
that pinconf_generic_dump_one() expects.  Specifically for boolean
parameters (anything with a "struct pin_config_item" where has_arg is
false) the function expects that the function should return its value
not through the "config" parameter but should return "0" if the value
is set and "-EINVAL" if the value isn't set.

Let's fix this.

From a quick sample of other pinctrl drivers, it appears to be
tradition to also return 1 through the config parameter for these
boolean parameters when they exist.  I'm not one to knock tradition,
so I'll follow tradition and return 1 in these cases.  While I'm at
it, I'll also continue searching for four leaf clovers, kocking on
wood three times, and trying not to break mirrors.

NOTE: This also fixes an apparent typo for reading
PIN_CONFIG_BIAS_DISABLE where the old driver was accidentally
using "=" instead of "==" and thus was setting some internal
state when you tried to query PIN_CONFIG_BIAS_DISABLE.  Oops.

Fixes: eadff3024472 ("pinctrl: Qualcomm SPMI PMIC GPIO pin controller driver")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

 drivers/pinctrl/qcom/pinctrl-spmi-gpio.c | 32 ++++++++++++++++++------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
index 3e66e0d10010..cf82db78e69e 100644
--- a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
+++ b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
@@ -390,31 +390,47 @@ static int pmic_gpio_config_get(struct pinctrl_dev *pctldev,
 
 	switch (param) {
 	case PIN_CONFIG_DRIVE_PUSH_PULL:
-		arg = pad->buffer_type == PMIC_GPIO_OUT_BUF_CMOS;
+		if (pad->buffer_type != PMIC_GPIO_OUT_BUF_CMOS)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_DRIVE_OPEN_DRAIN:
-		arg = pad->buffer_type == PMIC_GPIO_OUT_BUF_OPEN_DRAIN_NMOS;
+		if (pad->buffer_type != PMIC_GPIO_OUT_BUF_OPEN_DRAIN_NMOS)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_DRIVE_OPEN_SOURCE:
-		arg = pad->buffer_type == PMIC_GPIO_OUT_BUF_OPEN_DRAIN_PMOS;
+		if (pad->buffer_type != PMIC_GPIO_OUT_BUF_OPEN_DRAIN_PMOS)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_BIAS_PULL_DOWN:
-		arg = pad->pullup == PMIC_GPIO_PULL_DOWN;
+		if (pad->pullup != PMIC_GPIO_PULL_DOWN)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_BIAS_DISABLE:
-		arg = pad->pullup = PMIC_GPIO_PULL_DISABLE;
+		if (pad->pullup != PMIC_GPIO_PULL_DISABLE)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_BIAS_PULL_UP:
-		arg = pad->pullup == PMIC_GPIO_PULL_UP_30;
+		if (pad->pullup != PMIC_GPIO_PULL_UP_30)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
-		arg = !pad->is_enabled;
+		if (pad->is_enabled)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_POWER_SOURCE:
 		arg = pad->power_source;
 		break;
 	case PIN_CONFIG_INPUT_ENABLE:
-		arg = pad->input_enabled;
+		if (!pad->input_enabled)
+			return -EINVAL;
+		arg = 1;
 		break;
 	case PIN_CONFIG_OUTPUT:
 		arg = pad->out_value;
-- 
2.18.0.399.gad0ab374a1-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] pinctrl: qcom: spmi-gpio: Fix pmic_gpio_config_get() to be compliant
  2018-07-02 22:59 ` [PATCH 3/3] pinctrl: qcom: spmi-gpio: Fix pmic_gpio_config_get() " Douglas Anderson
@ 2018-07-03  6:09   ` Stephen Boyd
  2018-07-09 11:17     ` Linus Walleij
  2018-07-09 11:17   ` Linus Walleij
  1 sibling, 1 reply; 9+ messages in thread
From: Stephen Boyd @ 2018-07-03  6:09 UTC (permalink / raw)
  To: Bjorn Andersson, Douglas Anderson, Linus Walleij
  Cc: iivanov, Douglas Anderson, linux-gpio, linux-kernel, linux-arm-msm

Quoting Douglas Anderson (2018-07-02 15:59:39)
> If you do this on an sdm845 board:
>   grep "" /sys/kernel/debug/pinctrl/*spmi:pmic*/pinconf-groups
> 
> ...it looks like nonsense.  For every pin you see listed:
>   input bias disabled, input bias high impedance, input bias pull down, input bias pull up, ...
> 
> That's because pmic_gpio_config_get() isn't complying with the rules
> that pinconf_generic_dump_one() expects.  Specifically for boolean
> parameters (anything with a "struct pin_config_item" where has_arg is
> false) the function expects that the function should return its value
> not through the "config" parameter but should return "0" if the value
> is set and "-EINVAL" if the value isn't set.
> 
> Let's fix this.
> 
> From a quick sample of other pinctrl drivers, it appears to be
> tradition to also return 1 through the config parameter for these
> boolean parameters when they exist.  I'm not one to knock tradition,
> so I'll follow tradition and return 1 in these cases.  While I'm at
> it, I'll also continue searching for four leaf clovers, kocking on

Small typo here.

> wood three times, and trying not to break mirrors.
> 
> NOTE: This also fixes an apparent typo for reading
> PIN_CONFIG_BIAS_DISABLE where the old driver was accidentally
> using "=" instead of "==" and thus was setting some internal
> state when you tried to query PIN_CONFIG_BIAS_DISABLE.  Oops.

Awesome!

> 
> Fixes: eadff3024472 ("pinctrl: Qualcomm SPMI PMIC GPIO pin controller driver")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>

We should fix the ssbi-gpio/mpp and spmi-mpp drivers too. All those
drivers are designed on the same buggy original driver.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] pinctrl: Document pin_config_group_get() return codes like pin_config_get()
  2018-07-02 22:59 [PATCH 1/3] pinctrl: Document pin_config_group_get() return codes like pin_config_get() Douglas Anderson
  2018-07-02 22:59 ` [PATCH 2/3] pinctrl: msm: Fix msm_config_group_get() to be compliant Douglas Anderson
  2018-07-02 22:59 ` [PATCH 3/3] pinctrl: qcom: spmi-gpio: Fix pmic_gpio_config_get() " Douglas Anderson
@ 2018-07-09 11:09 ` Linus Walleij
  2 siblings, 0 replies; 9+ messages in thread
From: Linus Walleij @ 2018-07-09 11:09 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Bjorn Andersson, Ivan T. Ivanov, Stephen Boyd,
	open list:GPIO SUBSYSTEM, linux-kernel

On Tue, Jul 3, 2018 at 1:00 AM Douglas Anderson <dianders@chromium.org> wrote:

> The pinconf_generic_dump_one() function makes the assumption that
> pin_config_group_get() should return -EINVAL and -ENOTSUPP just like
> pin_config_get() does.  Document that so it's more obvious.
>
> Signed-off-by: Douglas Anderson <dianders@chromium.org>

Patch applied!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] pinctrl: msm: Fix msm_config_group_get() to be compliant
  2018-07-02 22:59 ` [PATCH 2/3] pinctrl: msm: Fix msm_config_group_get() to be compliant Douglas Anderson
@ 2018-07-09 11:15   ` Linus Walleij
  0 siblings, 0 replies; 9+ messages in thread
From: Linus Walleij @ 2018-07-09 11:15 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Bjorn Andersson, Ivan T. Ivanov, Stephen Boyd,
	open list:GPIO SUBSYSTEM, linux-kernel, linux-arm-msm

On Tue, Jul 3, 2018 at 1:00 AM Douglas Anderson <dianders@chromium.org> wrote:

> If you do this on an sdm845 board:
>   cat /sys/kernel/debug/pinctrl/3400000.pinctrl/pinconf-groups
>
> ...it looks like nonsense.  For every pin you see listed:
>   input bias bus hold, input bias disabled, input bias pull down, input bias pull up
>
> That's because msm_config_group_get() isn't complying with the rules
> that pinconf_generic_dump_one() expects.  Specifically for boolean
> parameters (anything with a "struct pin_config_item" where has_arg is
> false) the function expects that the function should return its value
> not through the "config" parameter but should return "0" if the value
> is set and "-EINVAL" if the value isn't set.
>
> Let's fix this.
>
> From a quick sample of other pinctrl drivers, it appears to be
> tradition to also return 1 through the config parameter for these
> boolean parameters when they exist.  I'm not one to knock tradition,
> so I'll follow tradition and return 1 in these cases.  While I'm at
> it, I'll also continue searching for four leaf clovers, kocking on
> wood three times, and trying not to break mirrors.
>
> Fixes: f365be092572 ("pinctrl: Add Qualcomm TLMM driver")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>

Looks solid to me so patch applied, unless Bjorn has objections
it stays in.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] pinctrl: qcom: spmi-gpio: Fix pmic_gpio_config_get() to be compliant
  2018-07-02 22:59 ` [PATCH 3/3] pinctrl: qcom: spmi-gpio: Fix pmic_gpio_config_get() " Douglas Anderson
  2018-07-03  6:09   ` Stephen Boyd
@ 2018-07-09 11:17   ` Linus Walleij
  1 sibling, 0 replies; 9+ messages in thread
From: Linus Walleij @ 2018-07-09 11:17 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Bjorn Andersson, Ivan T. Ivanov, Stephen Boyd,
	open list:GPIO SUBSYSTEM, linux-kernel, linux-arm-msm

On Tue, Jul 3, 2018 at 1:00 AM Douglas Anderson <dianders@chromium.org> wrote:

> If you do this on an sdm845 board:
>   grep "" /sys/kernel/debug/pinctrl/*spmi:pmic*/pinconf-groups
>
> ...it looks like nonsense.  For every pin you see listed:
>   input bias disabled, input bias high impedance, input bias pull down, input bias pull up, ...
>
> That's because pmic_gpio_config_get() isn't complying with the rules
> that pinconf_generic_dump_one() expects.  Specifically for boolean
> parameters (anything with a "struct pin_config_item" where has_arg is
> false) the function expects that the function should return its value
> not through the "config" parameter but should return "0" if the value
> is set and "-EINVAL" if the value isn't set.
>
> Let's fix this.
>
> From a quick sample of other pinctrl drivers, it appears to be
> tradition to also return 1 through the config parameter for these
> boolean parameters when they exist.  I'm not one to knock tradition,
> so I'll follow tradition and return 1 in these cases.  While I'm at
> it, I'll also continue searching for four leaf clovers, kocking on
> wood three times, and trying not to break mirrors.
>
> NOTE: This also fixes an apparent typo for reading
> PIN_CONFIG_BIAS_DISABLE where the old driver was accidentally
> using "=" instead of "==" and thus was setting some internal
> state when you tried to query PIN_CONFIG_BIAS_DISABLE.  Oops.
>
> Fixes: eadff3024472 ("pinctrl: Qualcomm SPMI PMIC GPIO pin controller driver")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>

Patch applied, same thing. Stays in unless Bjorn has some
objections.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] pinctrl: qcom: spmi-gpio: Fix pmic_gpio_config_get() to be compliant
  2018-07-03  6:09   ` Stephen Boyd
@ 2018-07-09 11:17     ` Linus Walleij
  2018-08-30 15:28       ` Doug Anderson
  0 siblings, 1 reply; 9+ messages in thread
From: Linus Walleij @ 2018-07-09 11:17 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Bjorn Andersson, Doug Anderson, Ivan T. Ivanov,
	open list:GPIO SUBSYSTEM, linux-kernel, linux-arm-msm

On Tue, Jul 3, 2018 at 8:09 AM Stephen Boyd <swboyd@chromium.org> wrote:

> > Fixes: eadff3024472 ("pinctrl: Qualcomm SPMI PMIC GPIO pin controller driver")
> > Signed-off-by: Douglas Anderson <dianders@chromium.org>
>
> We should fix the ssbi-gpio/mpp and spmi-mpp drivers too. All those
> drivers are designed on the same buggy original driver.

Agreed. Looking forward to the patches :D

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] pinctrl: qcom: spmi-gpio: Fix pmic_gpio_config_get() to be compliant
  2018-07-09 11:17     ` Linus Walleij
@ 2018-08-30 15:28       ` Doug Anderson
  0 siblings, 0 replies; 9+ messages in thread
From: Doug Anderson @ 2018-08-30 15:28 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Stephen Boyd, Bjorn Andersson, Ivan T. Ivanov,
	open list:GPIO SUBSYSTEM, linux-kernel, linux-arm-msm

Hi,

On Mon, Jul 9, 2018 at 4:17 AM, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Tue, Jul 3, 2018 at 8:09 AM Stephen Boyd <swboyd@chromium.org> wrote:
>
>> > Fixes: eadff3024472 ("pinctrl: Qualcomm SPMI PMIC GPIO pin controller driver")
>> > Signed-off-by: Douglas Anderson <dianders@chromium.org>
>>
>> We should fix the ssbi-gpio/mpp and spmi-mpp drivers too. All those
>> drivers are designed on the same buggy original driver.
>
> Agreed. Looking forward to the patches :D

Well, it took a little while for me to get to it, but patches are
available at <http://lore.kernel.org/r/20180830152340.242249-1-dianders@chromium.org>.
I personally have no way to test them so I prefixed them with RFT.
Enjoy!

-Doug

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-08-30 15:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-02 22:59 [PATCH 1/3] pinctrl: Document pin_config_group_get() return codes like pin_config_get() Douglas Anderson
2018-07-02 22:59 ` [PATCH 2/3] pinctrl: msm: Fix msm_config_group_get() to be compliant Douglas Anderson
2018-07-09 11:15   ` Linus Walleij
2018-07-02 22:59 ` [PATCH 3/3] pinctrl: qcom: spmi-gpio: Fix pmic_gpio_config_get() " Douglas Anderson
2018-07-03  6:09   ` Stephen Boyd
2018-07-09 11:17     ` Linus Walleij
2018-08-30 15:28       ` Doug Anderson
2018-07-09 11:17   ` Linus Walleij
2018-07-09 11:09 ` [PATCH 1/3] pinctrl: Document pin_config_group_get() return codes like pin_config_get() Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).