All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Timur Tabi <timur@codeaurora.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	andy.gross@linaro.org, david.brown@linaro.org,
	anjiandi@codeaurora.org,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH 1/2] [v5] pinctrl: qcom: disable GPIO groups with no pins
Date: Mon, 16 Oct 2017 10:01:17 +0200	[thread overview]
Message-ID: <20171016080117.GA17369@ulmo> (raw)
In-Reply-To: <1504798409-32041-2-git-send-email-timur@codeaurora.org>

[-- Attachment #1: Type: text/plain, Size: 2846 bytes --]

On Thu, Sep 07, 2017 at 10:33:28AM -0500, Timur Tabi wrote:
[...]
>  	ret = gpiochip_add_data(&pctrl->chip, pctrl);
>  	if (ret) {
>  		dev_err(pctrl->dev, "Failed register gpiochip\n");
>  		return ret;
>  	}
>  
> -	ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev), 0, 0, chip->ngpio);
> +	/*
> +	 * If irq_need_valid_mask is true, then gpiochip_add_data() will
> +	 * initialize irq_valid_mask to all 1s.  We need to clear all the
> +	 * GPIOs that are unavailable, and we need to find each block
> +	 * of consecutive available GPIOs are add them as pin ranges.
> +	 */
> +	if (chip->irq_need_valid_mask) {
> +		for (i = 0; i < ngpio; i++)
> +			if (!groups[i].npins)
> +				clear_bit(i, pctrl->chip.irq_valid_mask);
> +
> +		while ((count = msm_gpio_get_next_range(pctrl, &start))) {
> +			ret = gpiochip_add_pin_range(&pctrl->chip,
> +						     dev_name(pctrl->dev),
> +						     start, start, count);
> +			if (ret)
> +				break;
> +			start += count;
> +		}
> +	} else {
> +		ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev),
> +					     0, 0, ngpio);
> +	}

This is the bit that I don't understand. If you only tell gpiolib about
the GPIOs that exist, then it won't be initializing the .irq_valid_mask
in a wrong way.

In other words, what I'm trying to say is that in your case, ngpio isn't
equal to the sum of .npins over all groups. If instead you make the chip
register only the lines that actually exist, .irq_valid_mask will only
contain bits that do exist.

The reason I'm bringing this up is because we had the same discussion
back in November last year (yes, that driver still isn't upstream...):

	https://lkml.org/lkml/2016/11/22/543

In a nutshell: the Tegra driver was assuming that each port had a fixed
number (8) of lines, but when gpiolib changed to query the direction of
GPIOs at driver probe time this broke badly because on of the instances
of the GPIO controller is very strict about what it allows access to.

This seems to be similar to what you're experiencing. In our case we'd
run into a hard hang trying to access a register for a non-existing
GPIO. One of the possibilities discussed in the thread was to introduce
something akin to what's being proposed here.

In the end it turned out to be easiest to just don't tell gpiolib about
any non-existing GPIOs, because then you don't get to deal with any of
these workarounds. The downside is that you need a little more code to
find out exactly what GPIO you're talking about, or to determine how
many you have. In the end I think it's all worth it by making it a lot
easier in general to deal with. I think it's really confusing if you
expose, say, 200 pins, and for 50 of them users will get -EACCES, or
-ENOENT or whatever if they try to use them.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: thierry.reding@gmail.com (Thierry Reding)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] [v5] pinctrl: qcom: disable GPIO groups with no pins
Date: Mon, 16 Oct 2017 10:01:17 +0200	[thread overview]
Message-ID: <20171016080117.GA17369@ulmo> (raw)
In-Reply-To: <1504798409-32041-2-git-send-email-timur@codeaurora.org>

On Thu, Sep 07, 2017 at 10:33:28AM -0500, Timur Tabi wrote:
[...]
>  	ret = gpiochip_add_data(&pctrl->chip, pctrl);
>  	if (ret) {
>  		dev_err(pctrl->dev, "Failed register gpiochip\n");
>  		return ret;
>  	}
>  
> -	ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev), 0, 0, chip->ngpio);
> +	/*
> +	 * If irq_need_valid_mask is true, then gpiochip_add_data() will
> +	 * initialize irq_valid_mask to all 1s.  We need to clear all the
> +	 * GPIOs that are unavailable, and we need to find each block
> +	 * of consecutive available GPIOs are add them as pin ranges.
> +	 */
> +	if (chip->irq_need_valid_mask) {
> +		for (i = 0; i < ngpio; i++)
> +			if (!groups[i].npins)
> +				clear_bit(i, pctrl->chip.irq_valid_mask);
> +
> +		while ((count = msm_gpio_get_next_range(pctrl, &start))) {
> +			ret = gpiochip_add_pin_range(&pctrl->chip,
> +						     dev_name(pctrl->dev),
> +						     start, start, count);
> +			if (ret)
> +				break;
> +			start += count;
> +		}
> +	} else {
> +		ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev),
> +					     0, 0, ngpio);
> +	}

This is the bit that I don't understand. If you only tell gpiolib about
the GPIOs that exist, then it won't be initializing the .irq_valid_mask
in a wrong way.

In other words, what I'm trying to say is that in your case, ngpio isn't
equal to the sum of .npins over all groups. If instead you make the chip
register only the lines that actually exist, .irq_valid_mask will only
contain bits that do exist.

The reason I'm bringing this up is because we had the same discussion
back in November last year (yes, that driver still isn't upstream...):

	https://lkml.org/lkml/2016/11/22/543

In a nutshell: the Tegra driver was assuming that each port had a fixed
number (8) of lines, but when gpiolib changed to query the direction of
GPIOs at driver probe time this broke badly because on of the instances
of the GPIO controller is very strict about what it allows access to.

This seems to be similar to what you're experiencing. In our case we'd
run into a hard hang trying to access a register for a non-existing
GPIO. One of the possibilities discussed in the thread was to introduce
something akin to what's being proposed here.

In the end it turned out to be easiest to just don't tell gpiolib about
any non-existing GPIOs, because then you don't get to deal with any of
these workarounds. The downside is that you need a little more code to
find out exactly what GPIO you're talking about, or to determine how
many you have. In the end I think it's all worth it by making it a lot
easier in general to deal with. I think it's really confusing if you
expose, say, 200 pins, and for 50 of them users will get -EACCES, or
-ENOENT or whatever if they try to use them.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20171016/2a2bf792/attachment.sig>

  parent reply	other threads:[~2017-10-16  8:01 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-07 15:33 [PATCH 0/2] [v5] pinctrl: qcom: add support for sparse GPIOs Timur Tabi
2017-09-07 15:33 ` Timur Tabi
2017-09-07 15:33 ` [PATCH 1/2] [v5] pinctrl: qcom: disable GPIO groups with no pins Timur Tabi
2017-09-07 15:33   ` Timur Tabi
2017-10-02 17:44   ` Bjorn Andersson
2017-10-02 17:44     ` Bjorn Andersson
2017-10-02 20:47     ` Timur Tabi
2017-10-02 20:47       ` Timur Tabi
2017-10-07 11:07       ` Linus Walleij
2017-10-07 11:07         ` Linus Walleij
2017-10-13 23:35         ` Timur Tabi
2017-10-13 23:35           ` Timur Tabi
2017-10-19 22:44         ` Timur Tabi
2017-10-19 22:44           ` Timur Tabi
2017-10-16  8:01   ` Thierry Reding [this message]
2017-10-16  8:01     ` Thierry Reding
2017-10-16 13:52     ` Timur Tabi
2017-10-16 13:52       ` Timur Tabi
2017-09-07 15:33 ` [PATCH 2/2] [v3] pinctrl: qcom: qdf2xxx: add support for new ACPI HID QCOM8002 Timur Tabi
2017-09-07 15:33   ` Timur Tabi
2017-09-08 12:50 ` [PATCH 0/2] [v5] pinctrl: qcom: add support for sparse GPIOs Linus Walleij
2017-09-08 12:50   ` Linus Walleij
2017-09-13 17:09   ` Timur Tabi
2017-09-13 17:09     ` Timur Tabi
2017-09-19  7:04 ` Stephen Boyd
2017-09-19  7:04   ` Stephen Boyd
2017-09-19  8:15   ` Linus Walleij
2017-09-19  8:15     ` Linus Walleij
2017-09-19 12:32     ` Timur Tabi
2017-09-19 12:32       ` Timur Tabi
2017-09-20 11:43       ` Linus Walleij
2017-09-20 11:43         ` Linus Walleij
2017-09-20 13:04         ` Timur Tabi
2017-09-20 13:04           ` Timur Tabi
2017-09-21 12:08           ` Linus Walleij
2017-09-21 12:08             ` Linus Walleij
2017-09-21 12:12             ` Timur Tabi
2017-09-21 12:12               ` Timur Tabi
2017-09-22 13:29               ` Linus Walleij
2017-09-22 13:29                 ` Linus Walleij
2017-09-22 13:37                 ` Timur Tabi
2017-09-22 13:37                   ` Timur Tabi
2017-10-03 22:03                   ` Stephen Boyd
2017-10-03 22:03                     ` Stephen Boyd
2017-10-03 22:12                     ` Timur Tabi
2017-10-03 22:12                       ` Timur Tabi
2017-10-04 21:50                       ` Stephen Boyd
2017-10-04 21:50                         ` Stephen Boyd
2017-10-04 22:41                         ` Timur Tabi
2017-10-04 22:41                           ` Timur Tabi
2017-10-05 21:30                           ` Stephen Boyd
2017-10-05 21:30                             ` Stephen Boyd
2017-10-11  7:51                     ` Linus Walleij
2017-10-11  7:51                       ` Linus Walleij
2017-10-12  7:39                       ` Stephen Boyd
2017-10-12  7:39                         ` Stephen Boyd
2017-10-14 22:43                         ` Linus Walleij
2017-10-14 22:43                           ` Linus Walleij
2017-10-16 13:42                           ` Timur Tabi
2017-10-16 13:42                             ` Timur Tabi
2017-10-13 23:26                     ` Timur Tabi
2017-10-13 23:26                       ` Timur Tabi
2017-10-15 20:18                       ` Thierry Reding
2017-10-15 20:18                         ` Thierry Reding
2017-10-15 21:09                         ` Timur Tabi
2017-10-15 21:09                           ` Timur Tabi
2017-10-02 16:02                 ` Timur Tabi
2017-10-02 16:02                   ` Timur Tabi

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=20171016080117.GA17369@ulmo \
    --to=thierry.reding@gmail.com \
    --cc=andy.gross@linaro.org \
    --cc=anjiandi@codeaurora.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=david.brown@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=timur@codeaurora.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.