2024-03-27 09:14:05

by Chen-Yu Tsai

[permalink] [raw]
Subject: [PATCH 0/2] pinctrl: mediatek: paris: More pin config cleanups

Hi,

Here are a couple more pin config cleanups for the MediaTek paris
pinctrl driver library.

Patch 1 fixes readback of PIN_CONFIG_INPUT_SCHMITT_ENABLE. The function
was passing back the disabled state incorrectly.

Patch 2 reworks support for PIN_CONFIG_{INPUT,OUTPUT}_ENABLE, following
discussions on the bcm2835/bcm2711 pinctrl drivers [1]. The driver is
made to follow the definitions of each option as described in the DT
bindings and pinctrl core.

Please have a look and merge if possible.


Thanks
ChenYu

[1] https://lore.kernel.org/linux-arm-kernel/CAGb2v66XpjvDnTpi2=SPbeAPf844FLCai6YFwvVqvmF9z4Mj=A@mail.gmail.com/

Chen-Yu Tsai (2):
pinctrl: mediatek: paris: Fix PIN_CONFIG_INPUT_SCHMITT_ENABLE readback
pinctrl: mediatek: paris: Rework support for
PIN_CONFIG_{INPUT,OUTPUT}_ENABLE

drivers/pinctrl/mediatek/pinctrl-paris.c | 40 ++++++++----------------
1 file changed, 13 insertions(+), 27 deletions(-)

--
2.44.0.396.g6e790dbe36-goog



2024-03-27 09:14:16

by Chen-Yu Tsai

[permalink] [raw]
Subject: [PATCH 2/2] pinctrl: mediatek: paris: Rework support for PIN_CONFIG_{INPUT,OUTPUT}_ENABLE

There is a misinterpretation of some of the PIN_CONFIG_* options in this
driver library. PIN_CONFIG_OUTPUT_ENABLE should refer to a buffer or
switch in the output direction of the electrical path. The MediaTek
hardware does not have such a thing. The driver incorrectly maps this
option to the GPIO function's direction.

Likewise, PIN_CONFIG_INPUT_ENABLE should refer to a buffer or switch in
the input direction. The hardware does have such a mechanism, and is
mapped to the IES bit. The driver however sets the direction in addition
to the IES bit, which is incorrect. On readback, the IES bit isn't even
considered.

Ironically, the driver does not support readback for PIN_CONFIG_OUTPUT,
while its readback of PIN_CONFIG_{INPUT,OUTPUT}_ENABLE is what it should
be doing for PIN_CONFIG_OUTPUT.

Rework support for these three options, so that PIN_CONFIG_OUTPUT_ENABLE
is completely removed, PIN_CONFIG_INPUT_ENABLE is only linked to the IES
bit, and PIN_CONFIG_OUTPUT is linked to the GPIO function's direction
and output level.

Fixes: 805250982bb5 ("pinctrl: mediatek: add pinctrl-paris that implements the vendor dt-bindings")
Signed-off-by: Chen-Yu Tsai <[email protected]>
---
drivers/pinctrl/mediatek/pinctrl-paris.c | 38 +++++++-----------------
1 file changed, 11 insertions(+), 27 deletions(-)

diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c
index 9353f78a52f0..b19bc391705e 100644
--- a/drivers/pinctrl/mediatek/pinctrl-paris.c
+++ b/drivers/pinctrl/mediatek/pinctrl-paris.c
@@ -165,20 +165,21 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SR, &ret);
break;
case PIN_CONFIG_INPUT_ENABLE:
- case PIN_CONFIG_OUTPUT_ENABLE:
+ err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_IES, &ret);
+ if (!ret)
+ err = -EINVAL;
+ break;
+ case PIN_CONFIG_OUTPUT:
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &ret);
if (err)
break;
- /* CONFIG Current direction return value
- * ------------- ----------------- ----------------------
- * OUTPUT_ENABLE output 1 (= HW value)
- * input 0 (= HW value)
- * INPUT_ENABLE output 0 (= reverse HW value)
- * input 1 (= reverse HW value)
- */
- if (param == PIN_CONFIG_INPUT_ENABLE)
- ret = !ret;

+ if (!ret) {
+ err = -EINVAL;
+ break;
+ }
+
+ err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DO, &ret);
break;
case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &ret);
@@ -283,26 +284,9 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
break;
err = hw->soc->bias_set_combo(hw, desc, 0, arg);
break;
- case PIN_CONFIG_OUTPUT_ENABLE:
- err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
- MTK_DISABLE);
- /* Keep set direction to consider the case that a GPIO pin
- * does not have SMT control
- */
- if (err != -ENOTSUPP)
- break;
-
- err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
- MTK_OUTPUT);
- break;
case PIN_CONFIG_INPUT_ENABLE:
/* regard all non-zero value as enable */
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES, !!arg);
- if (err)
- break;
-
- err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
- MTK_INPUT);
break;
case PIN_CONFIG_SLEW_RATE:
/* regard all non-zero value as enable */
--
2.44.0.396.g6e790dbe36-goog


2024-03-27 09:16:17

by Chen-Yu Tsai

[permalink] [raw]
Subject: [PATCH 1/2] pinctrl: mediatek: paris: Fix PIN_CONFIG_INPUT_SCHMITT_ENABLE readback

In the generic pin config library, readback of some options are handled
differently compared to the setting of those options: the argument value
is used to convey enable/disable of an option in the set path, but
success or -EINVAL is used to convey if an option is enabled or disabled
in the debugfs readback path.

PIN_CONFIG_INPUT_SCHMITT_ENABLE is one such option. Fix the readback of
the option in the mediatek-paris library, so that the debugfs dump is
not showing "input schmitt enabled" for pins that don't have it enabled.

Fixes: 1bea6afbc842 ("pinctrl: mediatek: Refine mtk_pinconf_get()")
Signed-off-by: Chen-Yu Tsai <[email protected]>
---
drivers/pinctrl/mediatek/pinctrl-paris.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c
index b6bc31abd2b0..9353f78a52f0 100644
--- a/drivers/pinctrl/mediatek/pinctrl-paris.c
+++ b/drivers/pinctrl/mediatek/pinctrl-paris.c
@@ -193,6 +193,8 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
}

err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SMT, &ret);
+ if (!ret)
+ err = -EINVAL;
break;
case PIN_CONFIG_DRIVE_STRENGTH:
if (!hw->soc->drive_get)
--
2.44.0.396.g6e790dbe36-goog


2024-04-02 10:10:59

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 1/2] pinctrl: mediatek: paris: Fix PIN_CONFIG_INPUT_SCHMITT_ENABLE readback

On Wed, Mar 27, 2024 at 05:13:33PM +0800, Chen-Yu Tsai wrote:
> In the generic pin config library, readback of some options are handled
> differently compared to the setting of those options: the argument value
> is used to convey enable/disable of an option in the set path, but
> success or -EINVAL is used to convey if an option is enabled or disabled
> in the debugfs readback path.
>
> PIN_CONFIG_INPUT_SCHMITT_ENABLE is one such option. Fix the readback of
> the option in the mediatek-paris library, so that the debugfs dump is
> not showing "input schmitt enabled" for pins that don't have it enabled.
>
> Fixes: 1bea6afbc842 ("pinctrl: mediatek: Refine mtk_pinconf_get()")
> Signed-off-by: Chen-Yu Tsai <[email protected]>
> ---
> drivers/pinctrl/mediatek/pinctrl-paris.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c
> index b6bc31abd2b0..9353f78a52f0 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-paris.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-paris.c
> @@ -193,6 +193,8 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
> }
>
> err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SMT, &ret);
> + if (!ret)
> + err = -EINVAL;

In this function "ret" contains a mix of different data depending on
what the param is. It's not always clear what "ret" means from one
line to the next. I think it would be more clear to say
if (ret == MTK_DISABLE) in this case...

(I'm sorry to the list for sending so many nit picks today).

regards,
dan carpenter

2024-04-04 08:23:34

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 0/2] pinctrl: mediatek: paris: More pin config cleanups

On Wed, Mar 27, 2024 at 10:13 AM Chen-Yu Tsai <[email protected]> wrote:

> Here are a couple more pin config cleanups for the MediaTek paris
> pinctrl driver library.
>
> Patch 1 fixes readback of PIN_CONFIG_INPUT_SCHMITT_ENABLE. The function
> was passing back the disabled state incorrectly.
>
> Patch 2 reworks support for PIN_CONFIG_{INPUT,OUTPUT}_ENABLE, following
> discussions on the bcm2835/bcm2711 pinctrl drivers [1]. The driver is
> made to follow the definitions of each option as described in the DT
> bindings and pinctrl core.
>
> Please have a look and merge if possible.

Patches applied for fixes, it looks like pretty urgent stuff, yet no feedback
from maintainers for a week so I applied it.

Yours,
Linus Walleij

Subject: Re: [PATCH 0/2] pinctrl: mediatek: paris: More pin config cleanups

Il 04/04/24 10:23, Linus Walleij ha scritto:
> On Wed, Mar 27, 2024 at 10:13 AM Chen-Yu Tsai <[email protected]> wrote:
>
>> Here are a couple more pin config cleanups for the MediaTek paris
>> pinctrl driver library.
>>
>> Patch 1 fixes readback of PIN_CONFIG_INPUT_SCHMITT_ENABLE. The function
>> was passing back the disabled state incorrectly.
>>
>> Patch 2 reworks support for PIN_CONFIG_{INPUT,OUTPUT}_ENABLE, following
>> discussions on the bcm2835/bcm2711 pinctrl drivers [1]. The driver is
>> made to follow the definitions of each option as described in the DT
>> bindings and pinctrl core.
>>
>> Please have a look and merge if possible.
>
> Patches applied for fixes, it looks like pretty urgent stuff, yet no feedback
> from maintainers for a week so I applied it.
>
> Yours,
> Linus Walleij

Yeah - sorry about that, but this one went out of my radar for whatever
reason....
Just had a look at it and - even if it's too late - I can give my approval.

Please feel free to ping me if this happens again: when done for a good reason,
pings are helpful and appreciated on my side, no worries!

Btw, Linus, thanks for swiftly applying this as - yes - those are good and
high priority fixes.


*Anyway* - whole series is

Reviewed-by: AngeloGioacchino Del Regno <[email protected]>

Cheers,
Angelo