linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: when claiming hog, skip maps not served by same device
@ 2017-05-11 20:02 Nikita Yushchenko
  2017-05-11 21:44 ` Tony Lindgren
  2017-05-22 15:07 ` Linus Walleij
  0 siblings, 2 replies; 5+ messages in thread
From: Nikita Yushchenko @ 2017-05-11 20:02 UTC (permalink / raw)
  To: Linus Walleij, Tony Lindgren, Andy Shevchenko, Jon Hunter,
	Masahiro Yamada, Bjorn Andersson, Mika Westerberg
  Cc: linux-gpio, linux-kernel, Chris Healy, Jeff.White, Nikita Yushchenko

When pinctrl device registers, it automatically claims hogs, that is,
maps that pinctrl device serves for itself.

It is possible that in addition to SoC's pinctrl device, other pinctrl
devices get registered. E.g. some gpio expander devies are registered
as pinctrl devices. For such devices, pinctrl maps could be defined
that set up SoC's pins (e.g. interrupt pin for gpio expander). Such
a map will have target device set to gpio expander.

Here is device tree snippet that causes this scenario:

&i2c0 {
	sx1503@20 {
		compatible = "semtech,sx1503q";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_sx1503_20>;
		...
	};
};
...
&iomuxc {
	pinctrl_sx1503_20: pinctrl-sx1503-20 {
		fsl,pins = <
			VF610_PAD_PTB1__GPIO_23         0x219d
		>;
	};
};

Such a map will have target device set to gpio expander. However is not
a hog, it is a regular map that is claimed by core before gpio expander
device is probed.

Thus when looking for hogs, it is not enough to check that map's target
device is set to pinctrl device being registered. Need also check that
map's control device is also set to the same.

Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
---
 drivers/pinctrl/core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 1653cbda6a82..682ebd360030 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1038,6 +1038,16 @@ static struct pinctrl *create_pinctrl(struct device *dev,
 		/* Map must be for this device */
 		if (strcmp(map->dev_name, devname))
 			continue;
+		/*
+		 * If pctldev is not null, we are claiming hog for it,
+		 * that means, setting that is served by pctldev by itself.
+		 *
+		 * Thus we must skip map that is for this device but is served
+		 * by other device.
+		 */
+		if (pctldev &&
+		    strcmp(dev_name(pctldev->dev), map->ctrl_dev_name))
+			continue;
 
 		ret = add_setting(p, pctldev, map);
 		/*
-- 
2.11.0

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

* Re: [PATCH] pinctrl: when claiming hog, skip maps not served by same device
  2017-05-11 20:02 [PATCH] pinctrl: when claiming hog, skip maps not served by same device Nikita Yushchenko
@ 2017-05-11 21:44 ` Tony Lindgren
  2017-05-12  8:19   ` Nikita Yushchenko
  2017-05-22 15:07 ` Linus Walleij
  1 sibling, 1 reply; 5+ messages in thread
From: Tony Lindgren @ 2017-05-11 21:44 UTC (permalink / raw)
  To: Nikita Yushchenko
  Cc: Linus Walleij, Andy Shevchenko, Jon Hunter, Masahiro Yamada,
	Bjorn Andersson, Mika Westerberg, linux-gpio, linux-kernel,
	Chris Healy, Jeff.White

* Nikita Yushchenko <nikita.yoush@cogentembedded.com> [170511 13:05]:
> When pinctrl device registers, it automatically claims hogs, that is,
> maps that pinctrl device serves for itself.
> 
> It is possible that in addition to SoC's pinctrl device, other pinctrl
> devices get registered. E.g. some gpio expander devies are registered
> as pinctrl devices. For such devices, pinctrl maps could be defined
> that set up SoC's pins (e.g. interrupt pin for gpio expander). Such
> a map will have target device set to gpio expander.
> 
> Here is device tree snippet that causes this scenario:
> 
> &i2c0 {
> 	sx1503@20 {
> 		compatible = "semtech,sx1503q";
> 		pinctrl-names = "default";
> 		pinctrl-0 = <&pinctrl_sx1503_20>;
> 		...
> 	};
> };
> ...
> &iomuxc {
> 	pinctrl_sx1503_20: pinctrl-sx1503-20 {
> 		fsl,pins = <
> 			VF610_PAD_PTB1__GPIO_23         0x219d
> 		>;
> 	};
> };
> 
> Such a map will have target device set to gpio expander. However is not
> a hog, it is a regular map that is claimed by core before gpio expander
> device is probed.
> 
> Thus when looking for hogs, it is not enough to check that map's target
> device is set to pinctrl device being registered. Need also check that
> map's control device is also set to the same.
> 
> Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
> ---
>  drivers/pinctrl/core.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
> index 1653cbda6a82..682ebd360030 100644
> --- a/drivers/pinctrl/core.c
> +++ b/drivers/pinctrl/core.c
> @@ -1038,6 +1038,16 @@ static struct pinctrl *create_pinctrl(struct device *dev,
>  		/* Map must be for this device */
>  		if (strcmp(map->dev_name, devname))
>  			continue;
> +		/*
> +		 * If pctldev is not null, we are claiming hog for it,
> +		 * that means, setting that is served by pctldev by itself.
> +		 *
> +		 * Thus we must skip map that is for this device but is served
> +		 * by other device.
> +		 */
> +		if (pctldev &&
> +		    strcmp(dev_name(pctldev->dev), map->ctrl_dev_name))
> +			continue;
>  
>  		ret = add_setting(p, pctldev, map);
>  		/*
> -- 

Maybe add a comment saying pctldev is NULL in the regular case
and only exists in the hog case?

Other than that:

Acked-by: Tony Lindgren <tony@atomide.com>

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

* Re: [PATCH] pinctrl: when claiming hog, skip maps not served by same device
  2017-05-11 21:44 ` Tony Lindgren
@ 2017-05-12  8:19   ` Nikita Yushchenko
  2017-05-12 14:03     ` Tony Lindgren
  0 siblings, 1 reply; 5+ messages in thread
From: Nikita Yushchenko @ 2017-05-12  8:19 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Linus Walleij, Andy Shevchenko, Jon Hunter, Masahiro Yamada,
	Bjorn Andersson, Mika Westerberg, linux-gpio, linux-kernel,
	Chris Healy, Jeff.White

>> +		/*
>> +		 * If pctldev is not null, we are claiming hog for it,
>> +		 * that means, setting that is served by pctldev by itself.
>> +		 *
>> +		 * Thus we must skip map that is for this device but is served
>> +		 * by other device.
>> +		 */
>> +		if (pctldev &&
>> +		    strcmp(dev_name(pctldev->dev), map->ctrl_dev_name))
>> +			continue;
>>  
>>  		ret = add_setting(p, pctldev, map);
>>  		/*
>> -- 
> 
> Maybe add a comment saying pctldev is NULL in the regular case
> and only exists in the hog case?

Isn't comment above saying exactly that?

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

* Re: [PATCH] pinctrl: when claiming hog, skip maps not served by same device
  2017-05-12  8:19   ` Nikita Yushchenko
@ 2017-05-12 14:03     ` Tony Lindgren
  0 siblings, 0 replies; 5+ messages in thread
From: Tony Lindgren @ 2017-05-12 14:03 UTC (permalink / raw)
  To: Nikita Yushchenko
  Cc: Linus Walleij, Andy Shevchenko, Jon Hunter, Masahiro Yamada,
	Bjorn Andersson, Mika Westerberg, linux-gpio, linux-kernel,
	Chris Healy, Jeff.White

* Nikita Yushchenko <nikita.yoush@cogentembedded.com> [170512 01:22]:
> >> +		/*
> >> +		 * If pctldev is not null, we are claiming hog for it,
> >> +		 * that means, setting that is served by pctldev by itself.
> >> +		 *
> >> +		 * Thus we must skip map that is for this device but is served
> >> +		 * by other device.
> >> +		 */
> >> +		if (pctldev &&
> >> +		    strcmp(dev_name(pctldev->dev), map->ctrl_dev_name))
> >> +			continue;
> >>  
> >>  		ret = add_setting(p, pctldev, map);
> >>  		/*
> >> -- 
> > 
> > Maybe add a comment saying pctldev is NULL in the regular case
> > and only exists in the hog case?
> 
> Isn't comment above saying exactly that?

Yes it is, you're right :)

Tony

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

* Re: [PATCH] pinctrl: when claiming hog, skip maps not served by same device
  2017-05-11 20:02 [PATCH] pinctrl: when claiming hog, skip maps not served by same device Nikita Yushchenko
  2017-05-11 21:44 ` Tony Lindgren
@ 2017-05-22 15:07 ` Linus Walleij
  1 sibling, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2017-05-22 15:07 UTC (permalink / raw)
  To: Nikita Yushchenko
  Cc: Tony Lindgren, Andy Shevchenko, Jon Hunter, Masahiro Yamada,
	Bjorn Andersson, Mika Westerberg, linux-gpio, linux-kernel,
	Chris Healy, Jeff White

On Thu, May 11, 2017 at 10:02 PM, Nikita Yushchenko
<nikita.yoush@cogentembedded.com> wrote:

> When pinctrl device registers, it automatically claims hogs, that is,
> maps that pinctrl device serves for itself.
>
> It is possible that in addition to SoC's pinctrl device, other pinctrl
> devices get registered. E.g. some gpio expander devies are registered
> as pinctrl devices. For such devices, pinctrl maps could be defined
> that set up SoC's pins (e.g. interrupt pin for gpio expander). Such
> a map will have target device set to gpio expander.
>
> Here is device tree snippet that causes this scenario:
>
> &i2c0 {
>         sx1503@20 {
>                 compatible = "semtech,sx1503q";
>                 pinctrl-names = "default";
>                 pinctrl-0 = <&pinctrl_sx1503_20>;
>                 ...
>         };
> };
> ...
> &iomuxc {
>         pinctrl_sx1503_20: pinctrl-sx1503-20 {
>                 fsl,pins = <
>                         VF610_PAD_PTB1__GPIO_23         0x219d
>                 >;
>         };
> };
>
> Such a map will have target device set to gpio expander. However is not
> a hog, it is a regular map that is claimed by core before gpio expander
> device is probed.
>
> Thus when looking for hogs, it is not enough to check that map's target
> device is set to pinctrl device being registered. Need also check that
> map's control device is also set to the same.
>
> Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>

Oh that looks logically correct, good find.

I guess I tested multiple pin control devices on a system but
not with also using hogs on them...

Patch applied with Tony's ACK.

Yours,
Linus Walleij

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

end of thread, other threads:[~2017-05-22 15:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-11 20:02 [PATCH] pinctrl: when claiming hog, skip maps not served by same device Nikita Yushchenko
2017-05-11 21:44 ` Tony Lindgren
2017-05-12  8:19   ` Nikita Yushchenko
2017-05-12 14:03     ` Tony Lindgren
2017-05-22 15:07 ` 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).