All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Russell King - ARM Linux admin <linux@armlinux.org.uk>
Cc: Linux ARM <linux-arm-kernel@lists.infradead.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>
Subject: Re: pinctrl states vs pinmux vs gpio (i2c bus recovery)
Date: Mon, 9 Dec 2019 01:20:15 +0100	[thread overview]
Message-ID: <CACRpkdZv2rzA8AbFZKq0XVBaXNJR8c5tsb+1KTZ7fNuWjm5cbQ@mail.gmail.com> (raw)
In-Reply-To: <20191206173343.GX25745@shell.armlinux.org.uk>

Hi Russell,

very nice description of this dual-mode problem.

I wish I had a simple and elegant way we could make it
unambiguous and simple to use ... but it beats me right
now.

On Fri, Dec 6, 2019 at 6:33 PM Russell King - ARM Linux admin
<linux@armlinux.org.uk> wrote:

> One may expect:
>
>         pinctrl_select_state(i2c_imx->pinctrl, i2c_imx->pinctrl_pins_default);
>
> to change them back to the default state, but that would be incorrect.
> The first thing that pinctrl_select_state() does is check whether
>
>         p->state == state
>
> which it will do, as the pinctrl layer hasn't been informed of the
> change that has happened behind its back at the pinmux level.

Some pin controllers have the .strict property set
in their struct pinmux_ops:

* @strict: do not allow simultaneous use of the same pin for GPIO and another
*      function. Check both gpio_owner and mux_owner strictly before approving
*      the pin request.

The non-strict pin controllers are those that actually allow GPIO
and device functions to be used on the same physical line at the
same time. In this case there is not special GPIO mode for the
line in some muxing registers, they are just physically connected
somehow.

One usecase is sort of like how tcpdump work for
ethernet interfaces: a GPIO register can "snoop" on a pin while
in used by another device.

But it would notably also allow you to drive the line and interfere
with the device. Which is exactly what this I2C recovery mechanism
does, just that its pin controller is actually strict, will not allow
the same line to be used for GPIO and some other function at the
same time, so I suppose i.MX should probably explore the
strict mode.

Enabling that will sadly make the problem MORE complex
for this I2C recovery, requiring a cycle of
gpiod_put()/gpiod_get() to get it released from GPIO mode, i.e.
we would need to just get the GPIO when this is strictly needed.
Using devm_gpiod_get() and keeping a reference descriptor
around would not work all of a sudden.

I am thinking whether we can handle the non-strict controllers
in a more elegant way, or add some API to explicitly hand over
between device function and GPIO function. But I can't really
see some obvious solution.

Yours,
Linus Walleij

WARNING: multiple messages have this Message-ID (diff)
From: Linus Walleij <linus.walleij@linaro.org>
To: Russell King - ARM Linux admin <linux@armlinux.org.uk>
Cc: "open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: pinctrl states vs pinmux vs gpio (i2c bus recovery)
Date: Mon, 9 Dec 2019 01:20:15 +0100	[thread overview]
Message-ID: <CACRpkdZv2rzA8AbFZKq0XVBaXNJR8c5tsb+1KTZ7fNuWjm5cbQ@mail.gmail.com> (raw)
In-Reply-To: <20191206173343.GX25745@shell.armlinux.org.uk>

Hi Russell,

very nice description of this dual-mode problem.

I wish I had a simple and elegant way we could make it
unambiguous and simple to use ... but it beats me right
now.

On Fri, Dec 6, 2019 at 6:33 PM Russell King - ARM Linux admin
<linux@armlinux.org.uk> wrote:

> One may expect:
>
>         pinctrl_select_state(i2c_imx->pinctrl, i2c_imx->pinctrl_pins_default);
>
> to change them back to the default state, but that would be incorrect.
> The first thing that pinctrl_select_state() does is check whether
>
>         p->state == state
>
> which it will do, as the pinctrl layer hasn't been informed of the
> change that has happened behind its back at the pinmux level.

Some pin controllers have the .strict property set
in their struct pinmux_ops:

* @strict: do not allow simultaneous use of the same pin for GPIO and another
*      function. Check both gpio_owner and mux_owner strictly before approving
*      the pin request.

The non-strict pin controllers are those that actually allow GPIO
and device functions to be used on the same physical line at the
same time. In this case there is not special GPIO mode for the
line in some muxing registers, they are just physically connected
somehow.

One usecase is sort of like how tcpdump work for
ethernet interfaces: a GPIO register can "snoop" on a pin while
in used by another device.

But it would notably also allow you to drive the line and interfere
with the device. Which is exactly what this I2C recovery mechanism
does, just that its pin controller is actually strict, will not allow
the same line to be used for GPIO and some other function at the
same time, so I suppose i.MX should probably explore the
strict mode.

Enabling that will sadly make the problem MORE complex
for this I2C recovery, requiring a cycle of
gpiod_put()/gpiod_get() to get it released from GPIO mode, i.e.
we would need to just get the GPIO when this is strictly needed.
Using devm_gpiod_get() and keeping a reference descriptor
around would not work all of a sudden.

I am thinking whether we can handle the non-strict controllers
in a more elegant way, or add some API to explicitly hand over
between device function and GPIO function. But I can't really
see some obvious solution.

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-12-09  0:20 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-06 17:33 pinctrl states vs pinmux vs gpio (i2c bus recovery) Russell King - ARM Linux admin
2019-12-06 17:33 ` Russell King - ARM Linux admin
2019-12-09  0:20 ` Linus Walleij [this message]
2019-12-09  0:20   ` Linus Walleij
2019-12-13  0:20   ` Russell King - ARM Linux admin
2019-12-13  0:20     ` Russell King - ARM Linux admin
2020-02-27 16:47     ` Alan Ott
2020-02-27 16:47       ` Alan Ott
2020-03-25 12:42       ` Alan Ott
2020-03-25 12:42         ` Alan Ott
2020-03-25 20:06         ` Ludovic.Desroches
2020-03-25 20:06           ` Ludovic.Desroches
2020-03-25 21:09           ` Alan Ott
2020-03-25 21:09             ` Alan Ott
2020-03-26  6:53             ` Ludovic.Desroches
2020-03-26  6:53               ` Ludovic.Desroches
2020-03-26 15:55               ` Alan Ott
2020-03-26 15:55                 ` Alan Ott
2020-03-26 20:39                 ` Ludovic.Desroches
2020-03-26 20:39                   ` Ludovic.Desroches
2020-03-27 16:24                   ` Alan Ott
2020-03-27 16:24                     ` Alan Ott
2020-03-27 21:43                     ` Ludovic.Desroches
2020-03-27 21:43                       ` Ludovic.Desroches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACRpkdZv2rzA8AbFZKq0XVBaXNJR8c5tsb+1KTZ7fNuWjm5cbQ@mail.gmail.com \
    --to=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.