linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Menzel <pmenzel@molgen.mpg.de>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-gpio@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	linux-pci@vger.kernel.org, regressions@lists.linux.dev
Subject: Re: Linux logs new warning `gpio gpiochip0: gpiochip_add_data_with_key: get_direction failed: -22`
Date: Tue, 25 Feb 2025 21:43:47 +0100	[thread overview]
Message-ID: <d1661817-1036-420a-9f76-a7124e6550a7@molgen.mpg.de> (raw)
In-Reply-To: <CAMRc=MdNnJZBd=eCa5ggATmqH4EwsGW3K6OgcF=oQrkEj_5S_g@mail.gmail.com>

Dear Bartosz,


Thank you for your support.

Am 24.02.25 um 09:51 schrieb brgl@bgdev.pl:
> On Sun, 23 Feb 2025 23:04:05 +0100, Paul Menzel <pmenzel@molgen.mpg.de> said:

>> Am 23.02.25 um 21:54 schrieb Bartosz Golaszewski:
>>> On Fri, Feb 21, 2025 at 10:02 PM Paul Menzel <pmenzel@molgen.mpg.de> wrote:
>>>>
>>>>> What GPIO driver is it using? It's likely that it's not using the
>>>>> provider API correctly and this change uncovered it, I'd like to take
>>>>> a look at it and fix it.
>>>>
>>>> How do I find out? The commands below do not return anything.
>>>>
>>>>        $ lsmod | grep gpio
>>>>        $ lspci -nn | grep -i gpio
>>>>        $ sudo dmesg | grep gpio
>>>>        [    5.150955] gpio gpiochip0: gpiochip_add_data_with_key: get_direction failed: -22
>>>>        [Just these lines match.]
>>
>>> If you have libgpiod-tools installed, you can post the output of
>>> gpiodetect here.
>>
>>       $ sudo gpiodetect
>>       gpiochip0 [INT344B:00] (152 lines)
> 
> So it's pinctrl-intel, specifically this function in
> drivers/pinctrl/intel/pinctrl-intel.c:
> 
> static int intel_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
> {
> 	struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
> 	void __iomem *reg;
> 	u32 padcfg0;
> 	int pin;
> 
> 	pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL);
> 	if (pin < 0)
> 		return -EINVAL;
> 
> 	reg = intel_get_padcfg(pctrl, pin, PADCFG0);
> 	if (!reg)
> 		return -EINVAL;
> 
> 	scoped_guard(raw_spinlock_irqsave, &pctrl->lock)
> 		padcfg0 = readl(reg);
> 
> 	if (padcfg0 & PADCFG0_PMODE_MASK)
> 		return -EINVAL;
> 
> 	if (__intel_gpio_get_direction(padcfg0) & PAD_CONNECT_OUTPUT)
> 		return GPIO_LINE_DIRECTION_OUT;
> 
> 	return GPIO_LINE_DIRECTION_IN;
> }
> 
> Can you add some logs and see which -EINVAL is returned here specifically?

Sure. I used the diff below, and added `dyndbg="file pinctrl-intel.c 
+p"` added to `/boot/grub/grub.cfg`.

```
diff --git a/drivers/pinctrl/intel/pinctrl-intel.c 
b/drivers/pinctrl/intel/pinctrl-intel.c
index 527e4b87ae52..f0922d9e64ee 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -1067,18 +1067,24 @@ static int intel_gpio_get_direction(struct 
gpio_chip *chip, unsigned int offset)
         int pin;

         pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL);
-       if (pin < 0)
+       if (pin < 0) {
+               dev_dbg(pctrl->dev, "pin < 0");
                 return -EINVAL;
+       }

         reg = intel_get_padcfg(pctrl, pin, PADCFG0);
-       if (!reg)
+       if (!reg) {
+               dev_dbg(pctrl->dev, "not reg");
                 return -EINVAL;
+       }

         scoped_guard(raw_spinlock_irqsave, &pctrl->lock)
                 padcfg0 = readl(reg);

-       if (padcfg0 & PADCFG0_PMODE_MASK)
+       if (padcfg0 & PADCFG0_PMODE_MASK) {
+               dev_dbg(pctrl->dev, "padcfg0 = %x", padcfg0);
                 return -EINVAL;
+       }

         if (__intel_gpio_get_direction(padcfg0) & PAD_CONNECT_OUTPUT)
                 return GPIO_LINE_DIRECTION_OUT;
```

These are the logs:

```
[    0.198584] sunrisepoint-pinctrl INT344B:00: Community0 features: 
0x000000
[    0.198613] sunrisepoint-pinctrl INT344B:00: Community1 features: 
0x00000c
[    0.198629] sunrisepoint-pinctrl INT344B:00: Community2 features: 
0x000000
[    0.198687] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198688] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198693] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198694] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198699] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198700] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198704] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198705] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198709] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198710] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198715] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198715] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198720] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198721] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198730] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198731] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198735] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198736] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198741] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198741] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198746] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198747] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198756] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198757] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198766] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198767] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198812] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198812] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198817] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198818] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198822] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198823] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198837] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198838] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198843] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198843] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198848] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198849] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198853] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198854] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198863] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198864] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198874] sunrisepoint-pinctrl INT344B:00: padcfg0 = 4000700
[    0.198875] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198879] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198880] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198884] sunrisepoint-pinctrl INT344B:00: padcfg0 = 4000700
[    0.198885] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198938] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198939] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198944] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198945] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198950] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198951] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198972] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198973] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198978] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.198979] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.198989] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.198990] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199006] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199007] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199011] sunrisepoint-pinctrl INT344B:00: padcfg0 = 84000700
[    0.199012] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199028] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199029] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199034] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199035] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199040] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199041] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199045] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199046] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199211] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199211] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199217] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199217] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199239] sunrisepoint-pinctrl INT344B:00: padcfg0 = 4000700
[    0.199240] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199255] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199256] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199261] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199262] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199267] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199268] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199273] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000702
[    0.199274] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199278] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.199279] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199284] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.199285] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199301] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000502
[    0.199302] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199307] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.199308] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199312] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.199313] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199318] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.199319] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199324] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000700
[    0.199325] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199382] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000600
[    0.199383] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
[    0.199387] sunrisepoint-pinctrl INT344B:00: padcfg0 = 44000600
[    0.199388] gpio gpiochip0: gpiochip_add_data_with_key: get_direction 
failed: -22
```

With

     #define PADCFG0_PMODE_MASK              GENMASK(13, 10)

indeed one bit is always set in this range.

> In any case: Linus: what should be our policy here? There are some pinctrl
> drivers which return EINVAL if the pin in question is not in GPIO mode. I don't
> think this is an error. Returning errors should be reserved for read failures
> and so on. Are you fine with changing the logic here to explicitly default to
> INPUT as until recently all errors would be interpreted as such anyway?


Kind regards,

Paul

  reply	other threads:[~2025-02-25 20:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-21 20:40 Linux logs new warning `gpio gpiochip0: gpiochip_add_data_with_key: get_direction failed: -22` Paul Menzel
2025-02-21 20:53 ` Bartosz Golaszewski
2025-02-21 21:02   ` Paul Menzel
2025-02-23 20:54     ` Bartosz Golaszewski
2025-02-23 22:04       ` Paul Menzel
2025-02-24  8:51         ` brgl
2025-02-25 20:43           ` Paul Menzel [this message]
2025-02-25 21:25           ` Linus Walleij
2025-02-26 13:37             ` Andy Shevchenko
2025-02-26 13:46               ` Andy Shevchenko
2025-02-26 14:14                 ` Bartosz Golaszewski
2025-02-26 14:22                   ` Andy Shevchenko
2025-03-14 11:54                     ` Paul Menzel
2025-03-14 12:19                       ` Bartosz Golaszewski
2025-03-14 12:25                         ` Paul Menzel

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=d1661817-1036-420a-9f76-a7124e6550a7@molgen.mpg.de \
    --to=pmenzel@molgen.mpg.de \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=regressions@lists.linux.dev \
    /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).