devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Ruppert <christian.ruppert@abilis.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Stephen Warren <swarren@wwwdotorg.org>,
	Patrice CHOTARD <patrice.chotard@st.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Grant Likely <grant.likely@secretlab.ca>,
	Rob Herring <rob.herring@calxeda.com>,
	Rob Landley <rob@landley.net>,
	Sascha Leuenberger <sascha.leuenberger@abilis.com>,
	Pierrick Hascoet <pierrick.hascoet@abilis.com>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	Alexandre Courbot <acourbot@nvidia.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>
Subject: Re: [PATCH 01/03] Make non-linear GPIO ranges accesible from gpiolib
Date: Wed, 9 Oct 2013 15:28:38 +0200	[thread overview]
Message-ID: <20131009132837.GA23021@ab42.lan> (raw)
In-Reply-To: <CACRpkdafaNE_fgiq8iW=_gT5gDVC_H8m-+0dfpunhAantLdJwQ@mail.gmail.com>

On Wed, Oct 09, 2013 at 01:58:35PM +0200, Linus Walleij wrote:
> On Tue, Oct 8, 2013 at 2:25 PM, Christian Ruppert
> <christian.ruppert@abilis.com> wrote:
> 
> > This patch adds the infrastructure required to register non-linear gpio
> > ranges through gpiolib and the standard GPIO device tree bindings.
> >
> > Signed-off-by: Christian Ruppert <christian.ruppert@abilis.com>
> 
> I understand the goal of this patch, and why you want it this way,
> but it needs some scrutiny, especially from the device tree people.
> 
> >  Here, a single GPIO controller has GPIOs 0..9 routed to pin controller
> >  pinctrl1's pins 20..29, and GPIOs 10..19 routed to pin controller pinctrl2's
> >  pins 50..59.
> 
> (Yes this is previous text)
> 
> This is quite straight-forward since it deals with a very definitive
> coupling of a physical pin and a GPIO line.
> 
> > +In addition, named groups of pins can be mapped to pin groups of a given
> > +pin controller using the gpio-ranges property as described below:
> > +
> > +       gpio-range-list ::= <single-gpio-range> [gpio-range-list]
> > +       single-gpio-range ::= <numeric-gpio-range> | <named-gpio-range>
> > +       numeric-gpio-range ::=
> > +                       <pinctrl-phandle> <gpio-base> <pinctrl-base> <count>
> > +       named-gpio-range ::= <pinctrl-phandle> <gpio-base> '<0 0>'
> > +       pinctrl-phanle : phandle to pin controller node.
> 
> phanle really?

Yes, this is actually identical to the numeric ranges. It specifies the
pin controller which is "responsible" for the pins/pin group in
question.

> > +       gpio-base : Base GPIO ID in the GPIO controller
> > +       pinctrl-base : Base pinctrl pin ID in the pin controller
> > +       count : The number of GPIOs/pins in this range
> (...)
> 
> You did not describe here that count can be 0 if a group is
> given and that 0 is a valid count for that case.

It is implicit in "named-gpio-range ::= <pinctrl-phandle> <gpio-base> '<0 0>'"
but you are probably right that this needs to be more explicit. When
rereading the whole section now (with all the changes that were made to
the documentation since the patch was originally written), I think I'll
rewrite this paragraph entirely, integrating it in the explanation of
numeric ranges.

> > +In this case, the property gpio-ranges-group-names contains one string for
> > +every single-gpio-range in gpio-ranges:
> > +       gpiorange-names-list ::= <gpiorange-name> [gpiorange-names-list]
> > +       gpiorange-name : Name of the pingroup associated to the GPIO range in
> > +                       the respective pin controller.
> (...)
> > +Example:
> > +
> > +       gpio_pio_i: gpio-controller@14B0 {
> > +               #gpio-cells = <2>;
> > +               compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
> > +               reg = <0x1480 0x18>;
> > +               gpio-controller;
> > +               gpio-ranges =                   <&pinctrl1 0 20 10>,
> > +                                               <&pinctrl2 10 0 0>,
> > +                                               <&pinctrl1 15 0 10>,
> > +                                               <&pinctrl2 25 0 0>;
> > +               gpio-ranges-group-names =       "",
> > +                                               "foo",
> > +                                               "",
> > +                                               "bar";
> > +       };
> 
> And here, I get a bit uneasy as I remember Stephen's stance that such
> groups must be a physical property of the controller. I am generally a
> bit soft on that, but that is from a driver point of view, and describing
> hardware in the devicetree must be reflecting an objective view of the
> hardware, not how the particular driver is written for Linux.

The named pin groups actually are a physical property of the pin
controller hardware (well, at least the pin groups are, the names are
not ;). Obviously, a driver (no matter for which OS) must be aware of
this hardware property so it can decide which value to write to which
register in order to control the pin mux. If we don't want to split (or
worse: duplicate) that information in the driver and device tree, I see
two alternatives.
1. Define register offsets, masks and register values and the list of
   pins controlled by those register/value pairs in the device tree.
2. Define register offsets, masks and register values and the list of
   pins controlled by those register/value pairs in the drivers. Define
   a portable high level interface for the device tree.

My personal preference is clearly 2.

> This is very questionable :-/
> 
> Are you sure this is useable on Windows and OpenBSD without
> first verbatim copying the structure of the Linux pinctrl driver?

Without knowing the pinctrl infrastructure in either Windows or OpenBSD,
I am actually convinced that this is _more_ portable than the numeric
ranges:
- The numeric ranges used today depend on a numbering scheme which
  is specific to the Linux pinctrl framework. One could very well
  imagine pinctrl frameworks without any numbering scheme at all.
- The actual numbers depend on the particulars of each individual Linux
  pinctrl driver implementation. There is no guarantee that such a
  numbering is compatible with pin numbering constraints of other OSses.
  Nobody would be surprised if any given OS didn't allow sparse pin
  numbering ranges, for example.

Adding the higher level concept of named pin groups (which accidentally
exists in Linux already) seems to be an elegant path to better
portability here.

> I am not 100% sure of this case but maybe I will come to realize
> as I read the rest of the patches...
> 
> Empty group names for "anonymous" groups (I guess these become
> linear then?) is really looking strange. They are empty strings with
> a semantic effect, that is quite disturbing. but I don't know a better
> way either.

The alternative would probably be to skip them altogether but I'm afraid
that that makes it even worse...

> Clarify that the number of ranges names must match the array of
> ranges, and that if you don't supply group names all ranges
> will be linear.

OK. Will be done when rewriting the documentation.

> > -               ret = gpiochip_add_pin_range(chip,
> > -                                            pinctrl_dev_get_devname( pctldev),
> > -                                            pinspec.args[0],
> > -                                            pinspec.args[1],
> > -                                            pinspec.args[2]);
> > -
> > -               if (ret)
> > -                       break;
> > +               if (pinspec.args[2]) {
> > +                       /* npins != 0: linear range */
> > +                       ret = gpiochip_add_pin_range(chip,
> > +                                       pinctrl_dev_get_devname(pctldev),
> > +                                       pinspec.args[0],
> > +                                       pinspec.args[1],
> > +                                       pinspec.args[2]);
> > +                       if (ret)
> > +                               break;
> > +               } else {
> > +                       /* npins == 0: special range */
> > +                       if (pinspec.args[1]) {
> > +                               pr_err("%s: Illegal gpio-range format.\n",
> > +                                       np->full_name);
> > +                               break;
> > +                       }
> > +                       ret = of_property_read_string_index(np,
> > +                                               "gpio-ranges-group-names",
> > +                                               index, &name);
> > +                       if (ret)
> > +                               break;
> > +
> > +                       ret = gpiochip_add_pingroup_range(chip, pctldev,
> > +                                               pinspec.args[0], name);
> > +                       if (ret)
> > +                               break;
> > +               }
> 
> Here you just alter the runpath if the count argument is zero.
> 
> Try to be more strict:
> 
> - If the count argument is zero, the
>   gpio-ranges-group-names index *must* also be set to a non-empty
>   string.
> 
> - If the count argument is non-zeo, the gpio-ranges-group-names
>   index *must* be an empty string, or the gpio-ranges-group-names
>   must be non-existant (you have to check for it's presence before
>   entering the iterating loop).
> 
> Both above checks need to be implemented and proper
> error messages printed on detected errors.

OK.

> > diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
> > index 2a00239..52e2e6f 100644
> > --- a/drivers/pinctrl/core.c
> > +++ b/drivers/pinctrl/core.c
> > @@ -456,6 +456,29 @@ struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname,
> >  }
> >  EXPORT_SYMBOL_GPL(pinctrl_find_and_add_gpio_range);
> >
> > +int pinctrl_add_gpio_pingrp_range(struct pinctrl_dev *pctldev,
> > +                               struct pinctrl_gpio_range *range,
> > +                               char *pin_group)
> > +{
> > +       const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
> > +       int group_selector, ret;
> > +
> > +       group_selector = pinctrl_get_group_selector(pctldev, pin_group);
> > +       if (group_selector < 0)
> > +               return group_selector;
> > +
> > +       ret = pctlops->get_group_pins(pctldev, group_selector,
> > +                               &range->pins,
> > +                               &range->npins);
> > +       if (ret < 0)
> > +               return ret;
> > +
> > +       pinctrl_add_gpio_range(pctldev, range);
> > +       return 0;
> > +
> > +}
> > +EXPORT_SYMBOL_GPL(pinctrl_add_gpio_pingrp_range);
> 
> I don't think this is very elegant. It's quite strange that the range partly
> populated from the GPIO side gets the corresponding pins filled
> in by this function. Can't we think about something more elegant?
> It reflects the strangeness I'm reacting to above I guess.

I don't see in which respect the existence of this function is different
from the existence of pinctrl_find_and_add_gpio_range (the sole purpose
of which is to be called from gpiochip_add_pin_range). I like the idea
of being strict about the gpio framework only managing GPIO related
things and the pinctrl framework only managing pinctrl related things.
Thus, I adopted this concept to gpiochip_add_pingroup_range (which calls
pinctrl_add_gpio_pingrp_range).

Tell me if you want me to migrate the get_group_pins call to
gpiochip_add_pingroup_range but IMHO this would be less elegant.

Greetings,
  Christian

  reply	other threads:[~2013-10-09 13:28 UTC|newest]

Thread overview: 138+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-10 15:45 [PATCH 1/2] pinmux: Add TB10x pinmux driver Christian Ruppert
2013-04-10 15:45 ` [PATCH 2/2] GPIO: Add TB10x GPIO driver Christian Ruppert
2013-04-17 15:13   ` Linus Walleij
2013-04-17 18:37   ` Stephen Warren
2013-04-17 14:48 ` [PATCH 1/2] pinmux: Add TB10x pinmux driver Linus Walleij
2013-04-17 18:32 ` Stephen Warren
2013-04-18  9:03   ` Christian Ruppert
2013-04-26  7:47     ` Linus Walleij
2013-04-29 16:17       ` Christian Ruppert
     [not found]         ` <20130429161725.GB30136-7oYq3qWSd+k@public.gmane.org>
2013-05-02 18:49           ` Stephen Warren
2013-05-03 18:03             ` Linus Walleij
2013-05-08 16:41               ` Christian Ruppert
2013-05-08 20:01                 ` Stephen Warren
2013-05-10  8:25                   ` Christian Ruppert
2013-05-14 12:29                     ` Linus Walleij
2013-05-15  9:41                       ` Christian Ruppert
2013-05-20  8:03                         ` Linus Walleij
2013-05-22  9:49                           ` Christian Ruppert
2013-06-12 16:44                             ` [RFC] Allow GPIO ranges based on pinctl pin groups Christian Ruppert
     [not found]                               ` <1371055449-15828-1-git-send-email-christian.ruppert-ux6zf3SgZrrQT0dZR+AlfA@public.gmane.org>
2013-06-13  9:00                                 ` Linus Walleij
2013-06-13 12:55                                   ` [PATCH 1/2] Add pin list based GPIO ranges Christian Ruppert
     [not found]                                     ` <1371128132-18266-1-git-send-email-christian.ruppert-ux6zf3SgZrrQT0dZR+AlfA@public.gmane.org>
2013-06-13 18:30                                       ` Linus Walleij
2013-06-14  7:17                                     ` Patrice CHOTARD
2013-06-14  8:24                                       ` [PATCH] Fix comment on pinctrl_gpio_range.pin_base Christian Ruppert
2013-06-16 10:19                                         ` Linus Walleij
2013-06-13 12:55                                   ` [PATCH 2/2] Make non-linear GPIO ranges accesible from gpiolib Christian Ruppert
2013-06-13 18:36                                     ` Linus Walleij
2013-06-13 21:38                                     ` Stephen Warren
2013-06-14  9:12                                       ` Christian Ruppert
2013-06-19 18:10                                         ` Stephen Warren
2013-06-19 18:27                                           ` Stephen Warren
2013-06-20 11:57                                             ` Christian Ruppert
2013-06-21 21:17                                               ` Stephen Warren
2013-06-25 11:59                                                 ` Christian Ruppert
2013-06-25 15:59                                                   ` Stephen Warren
2013-06-25 14:27                                                 ` Linus Walleij
2013-06-25 15:19                                                   ` Stephen Warren
2013-06-25 14:32                                                 ` Linus Walleij
2013-06-25 15:22                                                   ` Stephen Warren
2013-06-25 14:56                                                 ` Linus Walleij
2013-06-25 15:31                                                   ` Stephen Warren
2013-06-25 15:47                                                     ` Linus Walleij
2013-06-25 15:28                                                 ` Linus Walleij
2013-06-25 15:39                                                   ` Stephen Warren
2013-06-25 15:53                                                     ` Linus Walleij
2013-06-17 16:03                                       ` Christian Ruppert
2013-06-17 16:04                                         ` [PATCH 1/4] " Christian Ruppert
2013-06-18  8:09                                           ` Linus Walleij
2013-06-18  9:25                                             ` Christian Ruppert
2013-06-18  9:29                                               ` Christian Ruppert
2013-06-19 12:03                                                 ` Linus Walleij
2013-06-19 18:15                                                   ` Stephen Warren
2013-06-26 11:42                                                     ` Christian Ruppert
2013-06-26 17:33                                                       ` Stephen Warren
2013-06-19 22:27                                                 ` Stephen Warren
2013-06-26 11:46                                                   ` Christian Ruppert
2013-06-26 17:34                                                     ` Stephen Warren
2013-06-18  9:29                                               ` [PATCH 2/4] pinmux: Add TB10x pinmux driver Christian Ruppert
2013-06-19 22:35                                                 ` Stephen Warren
2013-06-26 11:50                                                   ` Christian Ruppert
2013-06-26 17:40                                                     ` Stephen Warren
2013-07-05  9:49                                                       ` Christian Ruppert
2013-07-05 18:40                                                         ` Stephen Warren
2013-07-08 13:02                                                           ` Christian Ruppert
2013-07-10 19:27                                                             ` Stephen Warren
2013-07-16  8:47                                                               ` Christian Ruppert
2013-07-16 16:04                                                                 ` Stephen Warren
2013-07-18 16:07                                                                   ` Christian Ruppert
2013-07-18 19:54                                                                     ` Stephen Warren
2013-07-26  9:42                                                                       ` Christian Ruppert
2013-07-26 16:05                                                                         ` Stephen Warren
2013-07-29 22:35                                                 ` Linus Walleij
2013-08-05 11:51                                                   ` Christian Ruppert
2013-08-14 16:53                                                     ` Linus Walleij
2013-08-21 15:57                                                       ` Christian Ruppert
2013-08-22 20:10                                                         ` Stephen Warren
2013-08-28 14:47                                                           ` Christian Ruppert
2013-10-08 12:21                                                             ` Christian Ruppert
2013-10-08 12:25                                                               ` [PATCH 01/03] Make non-linear GPIO ranges accesible from gpiolib Christian Ruppert
2013-10-09 11:58                                                                 ` Linus Walleij
2013-10-09 13:28                                                                   ` Christian Ruppert [this message]
2013-10-09 14:01                                                                     ` Linus Walleij
2013-10-10 20:49                                                                       ` Stephen Warren
2013-10-11  7:53                                                                         ` Linus Walleij
2013-10-15 13:36                                                                       ` Christian Ruppert
2013-10-15 13:37                                                                         ` [PATCH V2] " Christian Ruppert
2013-10-16 11:19                                                                           ` Linus Walleij
2013-10-16 12:56                                                                             ` [PATCH] Add a short note on pinctrl_get_group_pins to pinctrl.txt Christian Ruppert
2013-10-16 13:36                                                                               ` Linus Walleij
2013-10-10 20:47                                                                   ` [PATCH 01/03] Make non-linear GPIO ranges accesible from gpiolib Stephen Warren
2013-10-08 12:25                                                               ` [PATCH 02/03] pinmux: Add TB10x pinmux driver Christian Ruppert
2013-10-09 12:30                                                                 ` Linus Walleij
     [not found]                                                                   ` <CACRpkdZdELan7OyMjt4KOi=q-v1xkSaNZNyZ7AnOBY1R=SoW3w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-10-15 13:39                                                                     ` [PATCH V2] " Christian Ruppert
2013-10-16 11:25                                                                       ` Linus Walleij
2013-10-08 12:25                                                               ` [PATCH 03/03] GPIO: Add TB10x GPIO driver Christian Ruppert
2013-10-09 12:19                                                                 ` Linus Walleij
2013-10-15 13:45                                                                   ` Christian Ruppert
2013-10-16 11:29                                                                     ` Linus Walleij
2013-10-16 12:58                                                                       ` Christian Ruppert
2013-10-24 16:23                                                                         ` Christian Ruppert
2013-10-25 21:44                                                                           ` Linus Walleij
2013-10-25  3:27                                                                 ` Kumar Gala
2013-08-28 18:49                                                         ` [PATCH 2/4] pinmux: Add TB10x pinmux driver Linus Walleij
2013-08-29  7:35                                                           ` Christian Ruppert
2013-08-29  8:24                                                             ` Linus Walleij
2013-08-30  8:19                                                               ` Christian Ruppert
2013-06-18  9:29                                               ` [PATCH 3/4] GPIO: Add TB10x GPIO driver Christian Ruppert
2013-06-19 22:37                                                 ` Stephen Warren
2013-06-18  9:29                                               ` [PATCH 4/4] Add Abilis Systems Sarl to device tree vendor prefixes Christian Ruppert
2013-06-17 16:04                                         ` [PATCH 2/4] pinmux: Add TB10x pinmux driver Christian Ruppert
2013-06-17 16:04                                         ` [PATCH 3/4] GPIO: Add TB10x GPIO driver Christian Ruppert
2013-06-17 16:04                                         ` [PATCH 4/4] Add Abilis Systems Sarl to device tree vendor prefixes Christian Ruppert
2013-05-16  0:12                     ` [PATCH 1/2] pinmux: Add TB10x pinmux driver Stephen Warren
2013-05-20  8:10                       ` Linus Walleij
2013-05-22 14:28                         ` Christian Ruppert
2013-05-23  7:43                           ` Haojian Zhuang
2013-05-24 11:50                             ` Christian Ruppert
2013-05-26 15:49                               ` Haojian Zhuang
2013-06-03 12:30                                 ` Christian Ruppert
     [not found]                                   ` <20130603123001.GD31808-7oYq3qWSd+k@public.gmane.org>
2013-06-05  1:44                                     ` Haojian Zhuang
2013-06-06 14:11                                       ` Christian Ruppert
2013-06-06 14:32                                         ` Haojian Zhuang
2013-06-06 15:30                                           ` Christian Ruppert
2013-06-07  0:00                                             ` Haojian Zhuang
2013-06-07 11:32                                               ` Christian Ruppert
     [not found]                                                 ` <20130607113207.GE11875-7oYq3qWSd+k@public.gmane.org>
2013-06-07 14:57                                                   ` Haojian Zhuang
2013-06-07 19:18                                             ` Stephen Warren
2013-06-08  8:31                                               ` Haojian Zhuang
2013-06-09  2:47                                                 ` Stephen Warren
2013-06-11  7:27                                               ` Christian Ruppert
2013-06-16 11:11                                                 ` Linus Walleij
2013-05-29 12:21                               ` Linus Walleij
2013-06-03  9:42                                 ` Christian Ruppert
     [not found]                                   ` <20130603094204.GC31808-7oYq3qWSd+k@public.gmane.org>
2013-06-07 11:36                                     ` Linus Walleij
2013-06-07 13:34                                       ` Christian Ruppert
2013-05-24  9:20                           ` Linus Walleij
2013-05-24 12:03                             ` Christian Ruppert
     [not found]     ` <20130418090310.GA17636-7oYq3qWSd+k@public.gmane.org>
2013-05-02 18:52       ` Stephen Warren

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=20131009132837.GA23021@ab42.lan \
    --to=christian.ruppert@abilis.com \
    --cc=acourbot@nvidia.com \
    --cc=devicetree@vger.kernel.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linus.walleij@linaro.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patrice.chotard@st.com \
    --cc=pierrick.hascoet@abilis.com \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=sascha.leuenberger@abilis.com \
    --cc=swarren@wwwdotorg.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 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).