diff mbox

[v4,4/4] ARM: pinctrl: sunxi-pinctrl: fix pin funtion can not be match correctly.

Message ID 20171213144748.GA18267@arx-s1 (mailing list archive)
State Not Applicable
Headers show

Commit Message

Hao Zhang Dec. 13, 2017, 2:47 p.m. UTC
Pin function can not be match correctly when SUNXI_PIN describe with
mutiple variant and same function.

such as:
on pinctrl-sun4i-a10.c

SUNXI_PIN(SUNXI_PINCTRL_PIN(B, 2),
		SUNXI_FUNCTION(0x0, "gpio_in"),
		SUNXI_FUNCTION(0x1, "gpio_out"),
		SUNXI_FUNCTION_VARIANT(0x2, "pwm",    /* PWM0 */
			PINCTRL_SUN4I_A10 |
			PINCTRL_SUN7I_A20),
		SUNXI_FUNCTION_VARIANT(0x3, "pwm",    /* PWM0 */
			PINCTRL_SUN8I_R40)),

it would always match to the first variant function
(PINCTRL_SUN4I_A10, PINCTRL_SUN7I_A20)

so we should add variant compare on it.

Signed-off-by: hao_zhang <hao5781286@gmail.com>
---
 drivers/pinctrl/sunxi/pinctrl-sunxi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Maxime Ripard Dec. 13, 2017, 3:45 p.m. UTC | #1
Hi,

Thanks for your patch!

On Wed, Dec 13, 2017 at 10:47:48PM +0800, hao_zhang wrote:
> Pin function can not be match correctly when SUNXI_PIN describe with
> mutiple variant and same function.
> 
> such as:
> on pinctrl-sun4i-a10.c
> 
> SUNXI_PIN(SUNXI_PINCTRL_PIN(B, 2),
> 		SUNXI_FUNCTION(0x0, "gpio_in"),
> 		SUNXI_FUNCTION(0x1, "gpio_out"),
> 		SUNXI_FUNCTION_VARIANT(0x2, "pwm",    /* PWM0 */
> 			PINCTRL_SUN4I_A10 |
> 			PINCTRL_SUN7I_A20),
> 		SUNXI_FUNCTION_VARIANT(0x3, "pwm",    /* PWM0 */
> 			PINCTRL_SUN8I_R40)),
> 
> it would always match to the first variant function
> (PINCTRL_SUN4I_A10, PINCTRL_SUN7I_A20)
> 
> so we should add variant compare on it.
> 
> Signed-off-by: hao_zhang <hao5781286@gmail.com>
> ---
>  drivers/pinctrl/sunxi/pinctrl-sunxi.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> index 4b6cb25..f23e74e 100644
> --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> @@ -83,9 +83,11 @@ sunxi_pinctrl_desc_find_function_by_name(struct sunxi_pinctrl *pctl,
>  			struct sunxi_desc_function *func = pin->functions;
>  
>  			while (func->name) {
> -				if (!strcmp(func->name, func_name))
> +				if (!strcmp(func->name, func_name)) {
> +					if (!(func->variant) ||
> +					   (func->variant & pctl->variant))

I guess it would be better to have:
	if (!strcmp(func->name, func_name) &&
	    (!func->variant || (func->variant & pctl->variant)))

Once fixed,
Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks!
Maxime
Linus Walleij Dec. 20, 2017, 8:05 a.m. UTC | #2
On Wed, Dec 13, 2017 at 3:47 PM, hao_zhang <hao5781286@gmail.com> wrote:
> Pin function can not be match correctly when SUNXI_PIN describe with
> mutiple variant and same function.
>
> such as:
> on pinctrl-sun4i-a10.c
>
> SUNXI_PIN(SUNXI_PINCTRL_PIN(B, 2),
>                 SUNXI_FUNCTION(0x0, "gpio_in"),
>                 SUNXI_FUNCTION(0x1, "gpio_out"),
>                 SUNXI_FUNCTION_VARIANT(0x2, "pwm",    /* PWM0 */
>                         PINCTRL_SUN4I_A10 |
>                         PINCTRL_SUN7I_A20),
>                 SUNXI_FUNCTION_VARIANT(0x3, "pwm",    /* PWM0 */
>                         PINCTRL_SUN8I_R40)),
>
> it would always match to the first variant function
> (PINCTRL_SUN4I_A10, PINCTRL_SUN7I_A20)
>
> so we should add variant compare on it.
>
> Signed-off-by: hao_zhang <hao5781286@gmail.com>

Please resend patch with Maxime's suggestions fixed and his
ACK added so I can apply it.

I can take this patch separatelt, it does not need to be part of
the PWM series.

Yours,
Linus Walleij
diff mbox

Patch

diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index 4b6cb25..f23e74e 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -83,9 +83,11 @@  sunxi_pinctrl_desc_find_function_by_name(struct sunxi_pinctrl *pctl,
 			struct sunxi_desc_function *func = pin->functions;
 
 			while (func->name) {
-				if (!strcmp(func->name, func_name))
+				if (!strcmp(func->name, func_name)) {
+					if (!(func->variant) ||
+					   (func->variant & pctl->variant))
 					return func;
-
+				}
 				func++;
 			}
 		}