linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Elwell <phil@raspberrypi.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Rob Herring <robh+dt@kernel.org>,
	Nicolas Saenz Julienne <nsaenz@kernel.org>,
	Florian Fainelli <f.fainelli@gmail.com>,
	"bcm-kernel-feedback-list@broadcom.com" 
	<bcm-kernel-feedback-list@broadcom.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Thierry Reding <treding@nvidia.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-rpi-kernel@lists.infradead.org" 
	<linux-rpi-kernel@lists.infradead.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>
Subject: Re: [PATCH 1/2] pinctrl: bcm2835: Change init order for gpio hogs
Date: Wed, 1 Dec 2021 15:18:51 +0000	[thread overview]
Message-ID: <06345f5a-c8e7-848b-d25f-3f3e32ab5418@raspberrypi.com> (raw)
In-Reply-To: <CAHp75Vei9FUY0gGD99gVv_FZzcpN1y_i65BB-auyAFUwqsQxNA@mail.gmail.com>

Hi Andy,

On 01/12/2021 12:06, Andy Shevchenko wrote:
> On Monday, November 29, 2021, Phil Elwell <phil@raspberrypi.com 
> <mailto:phil@raspberrypi.com>> wrote:
> 
>     ...and gpio-ranges
> 
>     pinctrl-bcm2835 is a combined pinctrl/gpio driver. Currently the gpio
>     side is registered first, but this breaks gpio hogs (which are
>     configured during gpiochip_add_data). Part of the hog initialisation
>     is a call to pinctrl_gpio_request, and since the pinctrl driver hasn't
>     yet been registered this results in an -EPROBE_DEFER from which it can
>     never recover.
> 
>     Change the initialisation sequence to register the pinctrl driver
>     first.
> 
>     This also solves a similar problem with the gpio-ranges property, which
>     is required in order for released pins to be returned to inputs.
> 
> 
> We have a callback in GPIO chip to register pin ranges, why driver does it 
> separately?

A few experiments (this is not my driver) appear to show that the call to 
pinctrl_add_gpio_range can be removed, but only once the gpio-ranges DT property 
has been added if we want to remain functionality throughout a bisect. That tidy 
up might be better done with a followup commit once the DT patch has also
been accepted, unless it's possible to guarantee the sequencing between
the pinctrl/gpio tree and the DT tree.

>     Fixes: 73345a18d464b ("pinctrl: bcm2835: Pass irqchip when adding
>                             gpiochip")
>     Signed-off-by: Phil Elwell <phil@raspberrypi.com <mailto:phil@raspberrypi.com>>
> 
> 
> 
> Is it originally so strange indentation or is it only on my side?

The "g" is below the "p" in the patch.

Thanks,

Phil

>     ---
>       drivers/pinctrl/bcm/pinctrl-bcm2835.c | 29 +++++++++++++++------------
>       1 file changed, 16 insertions(+), 13 deletions(-)
> 
>     diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
>     b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
>     index 2abcc6ce4eba..b607d10e4cbd 100644
>     --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
>     +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
>     @@ -1244,6 +1244,18 @@ static int bcm2835_pinctrl_probe(struct
>     platform_device *pdev)
>                      raw_spin_lock_init(&pc->irq_lock[i]);
>              }
> 
>     +       pc->pctl_desc = *pdata->pctl_desc;
>     +       pc->pctl_dev = devm_pinctrl_register(dev, &pc->pctl_desc, pc);
>     +       if (IS_ERR(pc->pctl_dev)) {
>     +               gpiochip_remove(&pc->gpio_chip);
>     +               return PTR_ERR(pc->pctl_dev);
>     +       }
>     +
>     +       pc->gpio_range = *pdata->gpio_range;
>     +       pc->gpio_range.base = pc->gpio_chip.base;
>     +       pc->gpio_range.gc = &pc->gpio_chip;
>     +       pinctrl_add_gpio_range(pc->pctl_dev, &pc->gpio_range);
>     +
>              girq = &pc->gpio_chip.irq;
>              girq->chip = &bcm2835_gpio_irq_chip;
>              girq->parent_handler = bcm2835_gpio_irq_handler;
>     @@ -1251,8 +1263,10 @@ static int bcm2835_pinctrl_probe(struct
>     platform_device *pdev)
>              girq->parents = devm_kcalloc(dev, BCM2835_NUM_IRQS,
>                                           sizeof(*girq->parents),
>                                           GFP_KERNEL);
>     -       if (!girq->parents)
>     +       if (!girq->parents) {
>     +               pinctrl_remove_gpio_range(pc->pctl_dev, &pc->gpio_range);
>                      return -ENOMEM;
>     +       }
> 
>              if (is_7211) {
>                      pc->wake_irq = devm_kcalloc(dev, BCM2835_NUM_IRQS,
>     @@ -1307,21 +1321,10 @@ static int bcm2835_pinctrl_probe(struct
>     platform_device *pdev)
>              err = gpiochip_add_data(&pc->gpio_chip, pc);
>              if (err) {
>                      dev_err(dev, "could not add GPIO chip\n");
>     +               pinctrl_remove_gpio_range(pc->pctl_dev, &pc->gpio_range);
>                      return err;
>              }
> 
>     -       pc->pctl_desc = *pdata->pctl_desc;
>     -       pc->pctl_dev = devm_pinctrl_register(dev, &pc->pctl_desc, pc);
>     -       if (IS_ERR(pc->pctl_dev)) {
>     -               gpiochip_remove(&pc->gpio_chip);
>     -               return PTR_ERR(pc->pctl_dev);
>     -       }
>     -
>     -       pc->gpio_range = *pdata->gpio_range;
>     -       pc->gpio_range.base = pc->gpio_chip.base;
>     -       pc->gpio_range.gc = &pc->gpio_chip;
>     -       pinctrl_add_gpio_range(pc->pctl_dev, &pc->gpio_range);
>     -
>              return 0;
>       }
> 
>     -- 
>     2.25.1
> 
> 
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
> 

  parent reply	other threads:[~2021-12-01 15:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 10:55 [PATCH 0/2] pinctrl: bcm2835: Fix gpio hogs and pin reinitialisation Phil Elwell
2021-11-29 10:55 ` [PATCH 1/2] pinctrl: bcm2835: Change init order for gpio hogs Phil Elwell
     [not found]   ` <CAHp75Vei9FUY0gGD99gVv_FZzcpN1y_i65BB-auyAFUwqsQxNA@mail.gmail.com>
2021-12-01 15:18     ` Phil Elwell [this message]
2021-12-01 15:38       ` Andy Shevchenko
2021-12-01 16:08         ` Phil Elwell
2021-12-01 16:25           ` Andy Shevchenko
2021-12-01 16:34             ` Phil Elwell
2021-11-29 10:55 ` [PATCH 2/2] ARM: dts: gpio-ranges property is now required Phil Elwell
2021-12-02  1:39   ` Linus Walleij

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=06345f5a-c8e7-848b-d25f-3f3e32ab5418@raspberrypi.com \
    --to=phil@raspberrypi.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=nsaenz@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=treding@nvidia.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).