All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Rob Herring <robh@kernel.org>,
	Florian Fainelli <f.fainelli@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	devicetree@vger.kernel.org,
	Jeffy Chen <jeffy.chen@rock-chips.com>,
	Enric Balletbo i Serra <enric.balletbo@collabora.com>,
	Joseph Lo <josephl@nvidia.com>, Doug Berger <opendmb@gmail.com>
Subject: Re: Lack of suspend/resume/shutdown ordering between GPIO providers and consumers
Date: Wed, 25 Apr 2018 23:32:18 +0200	[thread overview]
Message-ID: <1902993.fzUevIZMfq@aspire.rjw.lan> (raw)
In-Reply-To: <20180425181435.GA200812@dtor-ws>

On Wednesday, April 25, 2018 8:14:35 PM CEST Dmitry Torokhov wrote:
> On Wed, Apr 25, 2018 at 10:00:31AM -0500, Rob Herring wrote:
> > On Tue, Apr 24, 2018 at 5:58 PM, Florian Fainelli <f.fainelli@gmail.com> wrote:
> > > Hi Linus, Rafael, all
> > >
> > > Our GPIO controller driver: gpio-brcmstb.c has a shutdown callback which
> > > gets invoked when the system is brought into poweroff aka S5. So far so
> > > good, except that we also wish to use gpio_keys.c as a possible wake-up
> > > source, so we may have a number of GPIO pins declared as gpio-keys that
> > > allow the system to wake-up from deep slumber.
> > >
> > > Recently we noticed that we could easily get into a state where
> > > gpio-brcmstb.c::brcmstb_gpio_shutdown() gets called first, and then
> > > gpio_keys.c::gpio_keys_suspend() gets called later, which is too late to
> > > have the enable_irq_wake() call do anything sensible since we have
> > > suspend its parent interrupt controller before. This is completely
> > > expected unfortunately because these two drivers are both platform
> > > device instances with no connection to one another except via Device
> > > Tree and the use of the GPIOLIB APIs.
> > >
> > > First solution is to make sure that gpio-keys nodes are declared in
> > > Device Tree *before* the GPIO controller. This works because Device Tree
> > > nodes are probed in the order in which they are declared in Device Tree
> > > and that directly influences the order in which platform devices are
> > > created. Problem with that is that this is easy to miss and it may not
> > > work with overlays, kexec reconstructing DT etc. etc.
> > 
> > I'm going to make of_platform_populate randomize the order it creates devices...
> > 
> > > Another possible solution would be have the GPIO controller nodes have
> > > the GPIO consumers nodes such as gpio-keys, gpio-leds etc., and that
> > > would allow the Linux device driver model to create an appropriate
> > > child/parent relationship. This would unfortunately require Device Tree
> > > changes everywhere to make that consistent, and it would be a special
> > > case, because not all GPIO consumers are eligible as child nodes of
> > > their parent GPIO controller, there are plenty of other consumers that
> > > are not suitable for being moved under a parent GPIO controller node.
> > > This would also mean that we need to "probe" GPIO controller nodes to
> > > populate their child nodes (e.g: of_platform_bus_populate).
> > >
> > > I am thinking a more generic solution might involve some more complex
> > > tracking of the provider <-> consumer, but there is room for breakage.
> > 
> > That's what device connections are for. It probably just needs the
> > GPIO core to create the links. (but I've not looked into it at all).
> 
> Not all APIs accept device as parameter to easily create links. But I
> wonder, for cases like this, if we could not simply move the device to
> the end of the dpm list after successful binding it to a driver. The
> assumption that when GOPIs or other resources are not ready they'll
> return -EPROBE_DEFER and probing would fail.

Not just to the end of dpm_list if shutdown is involved.

Also if you need runtime PM to follow the dependencies, this isn't
sufficient.

Thanks,
Rafael

  reply	other threads:[~2018-04-25 21:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-24 22:58 Lack of suspend/resume/shutdown ordering between GPIO providers and consumers Florian Fainelli
2018-04-25 15:00 ` Rob Herring
2018-04-25 18:14   ` Dmitry Torokhov
2018-04-25 21:32     ` Rafael J. Wysocki [this message]
2018-05-14 23:46     ` Florian Fainelli
2018-05-15  0:26       ` Dmitry Torokhov
2018-04-25 18:06 ` Grygorii Strashko
2018-04-25 18:06   ` Grygorii Strashko
2018-04-25 18:29   ` Florian Fainelli
2018-04-25 18:47     ` Grygorii Strashko
2018-04-25 18:47       ` Grygorii Strashko
2018-04-25 18:57       ` Florian Fainelli
2018-04-25 19:10         ` Grygorii Strashko
2018-04-25 19:10           ` Grygorii Strashko
2018-04-25 19:29           ` Grygorii Strashko
2018-04-25 19:29             ` Grygorii Strashko
2018-04-25 21:35             ` Rafael J. Wysocki

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=1902993.fzUevIZMfq@aspire.rjw.lan \
    --to=rjw@rjwysocki.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=enric.balletbo@collabora.com \
    --cc=f.fainelli@gmail.com \
    --cc=jeffy.chen@rock-chips.com \
    --cc=josephl@nvidia.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=opendmb@gmail.com \
    --cc=robh@kernel.org \
    /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.