devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Haojian Zhuang <haojian.zhuang@linaro.org>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Grygorii Strashko <grygorii.strashko@ti.com>,
	Nishanth Menon <nm@ti.com>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-omap@vger.kernel.org" <linux-omap@vger.kernel.org>,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>
Subject: Re: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
Date: Tue, 10 Jan 2017 07:30:46 -0800	[thread overview]
Message-ID: <20170110153045.GS2630@atomide.com> (raw)
In-Reply-To: <CAMuHMdVLbNXx23-wgLHcvktyHxWf6t75ggU3rM5A-DhtU9hn5w@mail.gmail.com>

* Geert Uytterhoeven <geert@linux-m68k.org> [170110 06:09]:
> Hi Tony,
> 
> On Tue, Dec 27, 2016 at 6:19 PM, Tony Lindgren <tony@atomide.com> wrote:
> > Having the pin control framework call pin controller functions
> > before it's probe has finished is not nice as the pin controller
> > device driver does not yet have struct pinctrl_dev handle.
> >
> > Let's fix this issue by adding deferred work for late init. This is
> > needed to be able to add pinctrl generic helper functions that expect
> > to know struct pinctrl_dev handle. Note that we now need to call
> > create_pinctrl() directly as we don't want to add the pin controller
> > to the list of controllers until the hogs are claimed. We also need
> > to pass the pinctrl_dev to the device tree parser functions as they
> > otherwise won't find the right controller at this point.
> >
> > Signed-off-by: Tony Lindgren <tony@atomide.com>
> 
> I believe this patch causes a regression on r8a7740/armadillo, where the
> pin controller is also a GPIO controller, and lcd0 needs a hog
> (cfr. arch/arm/boot/dts/r8a7740-armadillo800eva.dts):
> 
> -GPIO line 176 (lcd0) hogged as output/high
> -sh-pfc e6050000.pfc: r8a7740_pfc handling gpio 0 -> 211
> +gpiochip_add_data: GPIOs 0..211 (r8a7740_pfc) failed to register
> +sh-pfc e6050000.pfc: failed to init GPIO chip, ignoring...
>  sh-pfc e6050000.pfc: r8a7740_pfc support registered
> 
> Hence all drivers using GPIOs fail to initialize because their GPIOs never
> become available.
> 
> Adding debug prints to the failure paths shows that the call to
> of_pinctrl_get() in of_gpiochip_add_pin_range() fails with -EPROBE_DEFER.
> Adding a debug print to the top of gpiochip_add_data() makes the problem go
> away, presumably because it introduces a delay that allows the delayed work
> to kick in...

OK. What if we added also an optional pinctrl function that the pin
controller driver could call to initialize hogs? Then the pin controller
driver could call it during or after probe as needed. That is after
there's a valid struct pinctrl_dev handle.

> Jon's fix ("pinctrl: core: Fix panic when pinctrl devices with hogs are
> unregistered") doesn't help, as it affects unregistration only.
> 
> > --- a/drivers/pinctrl/core.c
> > +++ b/drivers/pinctrl/core.c
> 
> > @@ -1800,32 +1847,10 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
> >                 goto out_err;
> >         }
> >
> > -       mutex_lock(&pinctrldev_list_mutex);
> > -       list_add_tail(&pctldev->node, &pinctrldev_list);
> > -       mutex_unlock(&pinctrldev_list_mutex);
> > -
> > -       pctldev->p = pinctrl_get(pctldev->dev);
> > -
> > -       if (!IS_ERR(pctldev->p)) {
> > -               pctldev->hog_default =
> > -                       pinctrl_lookup_state(pctldev->p, PINCTRL_STATE_DEFAULT);
> > -               if (IS_ERR(pctldev->hog_default)) {
> > -                       dev_dbg(dev, "failed to lookup the default state\n");
> > -               } else {
> > -                       if (pinctrl_select_state(pctldev->p,
> > -                                               pctldev->hog_default))
> > -                               dev_err(dev,
> > -                                       "failed to select default state\n");
> > -               }
> > -
> > -               pctldev->hog_sleep =
> > -                       pinctrl_lookup_state(pctldev->p,
> > -                                                   PINCTRL_STATE_SLEEP);
> > -               if (IS_ERR(pctldev->hog_sleep))
> > -                       dev_dbg(dev, "failed to lookup the sleep state\n");
> > -       }
> > -
> > -       pinctrl_init_device_debugfs(pctldev);
> > +       if (pinctrl_dt_has_hogs(pctldev))
> 
> Changing the above line to "if (0 && pinctrl_dt_has_hogs(pctldev))"
> fixes the issue for me.
> 
> > +               schedule_delayed_work(&pctldev->late_init, 0);
> > +       else
> > +               pinctrl_late_init(&pctldev->late_init.work);
> >
> >         return pctldev;

We could also pass some flag if should always call pinctrl_late_init()
directly. But that does not remove the problem of struct pinctrl_dev handle
being uninitialized when the pin controller driver functionas are called.

Regards,

Tony

  reply	other threads:[~2017-01-10 15:30 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-27 17:19 [PATCHv2 0/5] Add generic pinctrl helpers for managing groups and function Tony Lindgren
2016-12-27 17:19 ` [PATCH 1/5] pinctrl: core: Use delayed work for hogs Tony Lindgren
2016-12-30 13:46   ` Linus Walleij
2017-01-10 14:08   ` Geert Uytterhoeven
2017-01-10 15:30     ` Tony Lindgren [this message]
2017-01-10 19:19       ` Tony Lindgren
2017-01-11 15:33         ` Linus Walleij
2017-01-11 16:28           ` Tony Lindgren
2017-01-11 18:31             ` Tony Lindgren
     [not found] ` <20161227172003.6517-1-tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-12-27 17:20   ` [PATCH 2/5] pinctrl: core: Add generic pinctrl functions for managing groups Tony Lindgren
     [not found]     ` <20161227172003.6517-3-tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-12-30 14:12       ` Linus Walleij
2016-12-30 15:57         ` Tony Lindgren
2016-12-30 14:39   ` [PATCHv2 0/5] Add generic pinctrl helpers for managing groups and function Linus Walleij
2016-12-30 15:43     ` Gary Bisson
2016-12-30 15:59       ` Tony Lindgren
2017-01-02 16:14         ` Gary Bisson
2016-12-27 17:20 ` [PATCH 3/5] pinctrl: core: Add generic pinctrl functions for managing groups Tony Lindgren
2016-12-30 14:09   ` Linus Walleij
     [not found]   ` <20161227172003.6517-4-tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-12-30 14:28     ` Linus Walleij
2017-01-02 16:21   ` [3/5] " Gary Bisson
2017-01-02 17:08     ` Tony Lindgren
2016-12-27 17:20 ` [PATCH 4/5] pinctrl: single: Use generic pinctrl helpers " Tony Lindgren
2016-12-30 14:32   ` Linus Walleij
2016-12-27 17:20 ` [PATCH 5/5] pinctrl: single: Use generic pinmux helpers for managing functions Tony Lindgren
     [not found]   ` <20161227172003.6517-6-tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-12-30 14:35     ` Linus Walleij
  -- strict thread matches above, loose matches on Subject: below --
2016-10-25 21:02 [PATCH 0/5] Add generic pinctrl helpers for managing groups and functions Tony Lindgren
2016-10-25 21:02 ` [PATCH 1/5] pinctrl: core: Use delayed work for hogs Tony Lindgren
2016-11-11 20:17   ` Linus Walleij
2016-11-11 20:26     ` Tony Lindgren
2016-11-11 20:32       ` Tony Lindgren
     [not found]         ` <20161111203210.GJ7138-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-11 20:56           ` Tony Lindgren
2016-11-14 20:52       ` Tony Lindgren
     [not found]         ` <20161114205243.GU7138-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-14 22:08           ` Tony Lindgren
2016-11-15  0:47             ` Tony Lindgren
     [not found]               ` <20161115004703.GG4082-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-15  6:52                 ` Linus Walleij
     [not found]                   ` <CACRpkdZ=pifhHrH_-466f2x3Ev4GKW0CCnTj1hL5Hfpdj5p-1A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-11-15 15:41                     ` Tony Lindgren
2016-11-15 17:08                       ` Tony Lindgren
2016-12-02 13:08                         ` Linus Walleij
2016-12-02 16:44                           ` Tony Lindgren

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=20170110153045.GS2630@atomide.com \
    --to=tony@atomide.com \
    --cc=devicetree@vger.kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=grygorii.strashko@ti.com \
    --cc=haojian.zhuang@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=yamada.masahiro@socionext.com \
    /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 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).