All of lore.kernel.org
 help / color / mirror / Atom feed
* DT GPIO numbering?
@ 2012-08-01 15:22 Johannes Stezenbach
  2012-08-05 10:06   ` Linus Walleij
  0 siblings, 1 reply; 11+ messages in thread
From: Johannes Stezenbach @ 2012-08-01 15:22 UTC (permalink / raw)
  To: devicetree-discuss; +Cc: linux-kernel, Grant Likely, Linus Walleij

Hi,

I'm currently learning how Linux devicetree support works,
here is one question I couldn't find an answer for.

I understand that within the devicetree GPIOs are referenced by phandle,
thus the numbers are irrelevant.  However, in sysfs the number is
what is used to access the GPIO, e.g. for debugging or
blinkenlight apps.  How does this fit together?

In the old days platform data was used, e.g.

	struct pl061_platform_data {
		/* number of the first GPIO */
		unsigned	gpio_base;
		...
	};

Now, when DT is used gpio-pl061.c sets gc.base = -1 (dynamic numbering).

Should there be a DT property to assign the number base?

Or is there some better way, e.g. in gpio-mxs.c the code derives
the gc.base from of_alias_get_id(np, "gpio").
Should gpio-pl061.c do the same?

And how about assigning gpio names?  When a name is assigned to
the GPIO, is shows up in sysfs instead of gpio%d, however the
number is still needed for /sys/class/gpio/export, right?


Thanks,
Johannes

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DT GPIO numbering?
@ 2012-08-05 10:06   ` Linus Walleij
  0 siblings, 0 replies; 11+ messages in thread
From: Linus Walleij @ 2012-08-05 10:06 UTC (permalink / raw)
  To: Johannes Stezenbach; +Cc: devicetree-discuss, linux-kernel, Grant Likely

On Wed, Aug 1, 2012 at 5:22 PM, Johannes Stezenbach <js@sig21.net> wrote:

> I'm currently learning how Linux devicetree support works,
> here is one question I couldn't find an answer for.
>
> I understand that within the devicetree GPIOs are referenced by phandle,
> thus the numbers are irrelevant.  However, in sysfs the number is
> what is used to access the GPIO, e.g. for debugging or
> blinkenlight apps.  How does this fit together?

I think it simply does not fit together.

Grant & me has been claiming the GPIO sysfs interface is a bit
crazy from time to time.

My long-term plan would be to replace it with /dev/gpio/gpioN
device nodes per-gpiochip and use ioctl etc to control these
beasts instead. However one does not do that overnight,
and my life is too busy, and other refactorings also need to
happen :-/

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DT GPIO numbering?
@ 2012-08-05 10:06   ` Linus Walleij
  0 siblings, 0 replies; 11+ messages in thread
From: Linus Walleij @ 2012-08-05 10:06 UTC (permalink / raw)
  To: Johannes Stezenbach
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Wed, Aug 1, 2012 at 5:22 PM, Johannes Stezenbach <js-FF7aIK3TAVNeoWH0uzbU5w@public.gmane.org> wrote:

> I'm currently learning how Linux devicetree support works,
> here is one question I couldn't find an answer for.
>
> I understand that within the devicetree GPIOs are referenced by phandle,
> thus the numbers are irrelevant.  However, in sysfs the number is
> what is used to access the GPIO, e.g. for debugging or
> blinkenlight apps.  How does this fit together?

I think it simply does not fit together.

Grant & me has been claiming the GPIO sysfs interface is a bit
crazy from time to time.

My long-term plan would be to replace it with /dev/gpio/gpioN
device nodes per-gpiochip and use ioctl etc to control these
beasts instead. However one does not do that overnight,
and my life is too busy, and other refactorings also need to
happen :-/

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DT GPIO numbering?
  2012-08-05 10:06   ` Linus Walleij
  (?)
@ 2012-08-06  2:18   ` Stephen Warren
  2012-08-06  6:35     ` Linus Walleij
  -1 siblings, 1 reply; 11+ messages in thread
From: Stephen Warren @ 2012-08-06  2:18 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Johannes Stezenbach, devicetree-discuss, linux-kernel

On 08/05/2012 04:06 AM, Linus Walleij wrote:
> On Wed, Aug 1, 2012 at 5:22 PM, Johannes Stezenbach <js@sig21.net> wrote:
> 
>> I'm currently learning how Linux devicetree support works,
>> here is one question I couldn't find an answer for.
>>
>> I understand that within the devicetree GPIOs are referenced by phandle,
>> thus the numbers are irrelevant.  However, in sysfs the number is
>> what is used to access the GPIO, e.g. for debugging or
>> blinkenlight apps.  How does this fit together?
> 
> I think it simply does not fit together.
> 
> Grant & me has been claiming the GPIO sysfs interface is a bit
> crazy from time to time.
> 
> My long-term plan would be to replace it with /dev/gpio/gpioN
> device nodes per-gpiochip and use ioctl etc to control these
> beasts instead. However one does not do that overnight,
> and my life is too busy, and other refactorings also need to
> happen :-/

I can't comment on the sysfs-vs-dev interface location, but I don't
think it addresses Johannes' issue; finding out which GPIO IDs are
provided by which devices.

Perhaps in each device's sysfs node, there should be some information
re: which GPIO range it provides. Right now, perhaps a text file with
the GPIO base it it. With the new /dev interface you mention above,
perhaps a symlink to the /dev file, or a file containing the /dev file's
major/minor number. Or, is there such a thing already (other than
debugfs's gpio file).

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DT GPIO numbering?
  2012-08-06  2:18   ` Stephen Warren
@ 2012-08-06  6:35     ` Linus Walleij
  2012-08-06  9:58       ` Johannes Stezenbach
  0 siblings, 1 reply; 11+ messages in thread
From: Linus Walleij @ 2012-08-06  6:35 UTC (permalink / raw)
  To: Stephen Warren; +Cc: Johannes Stezenbach, devicetree-discuss, linux-kernel

On Mon, Aug 6, 2012 at 4:18 AM, Stephen Warren <swarren@wwwdotorg.org> wrote:

> I can't comment on the sysfs-vs-dev interface location, but I don't
> think it addresses Johannes' issue; finding out which GPIO IDs are
> provided by which devices.
>
> Perhaps in each device's sysfs node, there should be some information
> re: which GPIO range it provides. Right now, perhaps a text file with
> the GPIO base it it.

Yes that could work ...

> With the new /dev interface you mention above,
> perhaps a symlink to the /dev file, or a file containing the /dev file's
> major/minor number. Or, is there such a thing already (other than
> debugfs's gpio file).

Nothing I know of, but yes the day we come up with something,
it needs to be backward-compatible some way.

The problem is that there is really no reference userspace
like "lsgpio" or so. Maybe the first step could be to create that.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DT GPIO numbering?
  2012-08-06  6:35     ` Linus Walleij
@ 2012-08-06  9:58       ` Johannes Stezenbach
  2012-08-06 11:10           ` Mitch Bradley
  0 siblings, 1 reply; 11+ messages in thread
From: Johannes Stezenbach @ 2012-08-06  9:58 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Stephen Warren, devicetree-discuss, linux-kernel

On Mon, Aug 06, 2012 at 08:35:51AM +0200, Linus Walleij wrote:
> On Mon, Aug 6, 2012 at 4:18 AM, Stephen Warren <swarren@wwwdotorg.org> wrote:
> 
> > I can't comment on the sysfs-vs-dev interface location, but I don't
> > think it addresses Johannes' issue; finding out which GPIO IDs are
> > provided by which devices.
> >
> > Perhaps in each device's sysfs node, there should be some information
> > re: which GPIO range it provides. Right now, perhaps a text file with
> > the GPIO base it it.
> 
> Yes that could work ...

The method used by the gpio-mxs.c driver (of_alias_get_id)
would also work.  The question is which method is preferable.

Ideally I would like to use DT attributes to identify my GPIOs
in the same way as they appear in the schematics.  E.g.
one device may have GPIOs called PORT_A.0 to PORT_A.7,
another one may be EXT.0 to EXT.15.  But a single integer ID
is good enough since GPIO usage is platform specific anyway.
However, the mapping must be static and not depend e.g. on
module load order like now if you use pl061 and some i2c GPIO.
Software must be able to rely on that e.g. GPIO ID 11
always refers to EXT.3.


> > With the new /dev interface you mention above,
> > perhaps a symlink to the /dev file, or a file containing the /dev file's
> > major/minor number. Or, is there such a thing already (other than
> > debugfs's gpio file).
> 
> Nothing I know of, but yes the day we come up with something,
> it needs to be backward-compatible some way.
> 
> The problem is that there is really no reference userspace
> like "lsgpio" or so. Maybe the first step could be to create that.

I don't know much about OpenWrt, but I've seen they have
something:
https://dev.openwrt.org/browser/trunk/target/linux/generic/files/drivers/char/gpio_dev.c
https://dev.openwrt.org/browser/trunk/target/linux/generic/files/include/linux/gpio_dev.h
https://dev.openwrt.org/browser/trunk/package/gpioctl/src/main.c


Johannes

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DT GPIO numbering?
@ 2012-08-06 11:10           ` Mitch Bradley
  0 siblings, 0 replies; 11+ messages in thread
From: Mitch Bradley @ 2012-08-06 11:10 UTC (permalink / raw)
  To: Johannes Stezenbach; +Cc: Linus Walleij, devicetree-discuss, linux-kernel

On 8/6/2012 5:58 PM, Johannes Stezenbach wrote:
> On Mon, Aug 06, 2012 at 08:35:51AM +0200, Linus Walleij wrote:
>> On Mon, Aug 6, 2012 at 4:18 AM, Stephen Warren <swarren@wwwdotorg.org> wrote:
>>
>>> I can't comment on the sysfs-vs-dev interface location, but I don't
>>> think it addresses Johannes' issue; finding out which GPIO IDs are
>>> provided by which devices.
>>>
>>> Perhaps in each device's sysfs node, there should be some information
>>> re: which GPIO range it provides. Right now, perhaps a text file with
>>> the GPIO base it it.
>>
>> Yes that could work ...
> 
> The method used by the gpio-mxs.c driver (of_alias_get_id)
> would also work.  The question is which method is preferable.
> 
> Ideally I would like to use DT attributes to identify my GPIOs
> in the same way as they appear in the schematics.  E.g.
> one device may have GPIOs called PORT_A.0 to PORT_A.7,
> another one may be EXT.0 to EXT.15.  But a single integer ID
> is good enough since GPIO usage is platform specific anyway.
> However, the mapping must be static and not depend e.g. on
> module load order like now if you use pl061 and some i2c GPIO.
> Software must be able to rely on that e.g. GPIO ID 11
> always refers to EXT.3.

There is precedence for a "slot-names" property that correlates specific
hardware entities with physical labels.  It has been applied to PCI
plug-in slots and to other devices.  See, for example,
http://www.openfirmware.org/1275/proposals/Closed/Accepted/381-it.txt


> 
> 
>>> With the new /dev interface you mention above,
>>> perhaps a symlink to the /dev file, or a file containing the /dev file's
>>> major/minor number. Or, is there such a thing already (other than
>>> debugfs's gpio file).
>>
>> Nothing I know of, but yes the day we come up with something,
>> it needs to be backward-compatible some way.
>>
>> The problem is that there is really no reference userspace
>> like "lsgpio" or so. Maybe the first step could be to create that.
> 
> I don't know much about OpenWrt, but I've seen they have
> something:
> https://dev.openwrt.org/browser/trunk/target/linux/generic/files/drivers/char/gpio_dev.c
> https://dev.openwrt.org/browser/trunk/target/linux/generic/files/include/linux/gpio_dev.h
> https://dev.openwrt.org/browser/trunk/package/gpioctl/src/main.c
> 
> 
> Johannes
> _______________________________________________
> devicetree-discuss mailing list
> devicetree-discuss@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/devicetree-discuss
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DT GPIO numbering?
@ 2012-08-06 11:10           ` Mitch Bradley
  0 siblings, 0 replies; 11+ messages in thread
From: Mitch Bradley @ 2012-08-06 11:10 UTC (permalink / raw)
  To: Johannes Stezenbach
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On 8/6/2012 5:58 PM, Johannes Stezenbach wrote:
> On Mon, Aug 06, 2012 at 08:35:51AM +0200, Linus Walleij wrote:
>> On Mon, Aug 6, 2012 at 4:18 AM, Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org> wrote:
>>
>>> I can't comment on the sysfs-vs-dev interface location, but I don't
>>> think it addresses Johannes' issue; finding out which GPIO IDs are
>>> provided by which devices.
>>>
>>> Perhaps in each device's sysfs node, there should be some information
>>> re: which GPIO range it provides. Right now, perhaps a text file with
>>> the GPIO base it it.
>>
>> Yes that could work ...
> 
> The method used by the gpio-mxs.c driver (of_alias_get_id)
> would also work.  The question is which method is preferable.
> 
> Ideally I would like to use DT attributes to identify my GPIOs
> in the same way as they appear in the schematics.  E.g.
> one device may have GPIOs called PORT_A.0 to PORT_A.7,
> another one may be EXT.0 to EXT.15.  But a single integer ID
> is good enough since GPIO usage is platform specific anyway.
> However, the mapping must be static and not depend e.g. on
> module load order like now if you use pl061 and some i2c GPIO.
> Software must be able to rely on that e.g. GPIO ID 11
> always refers to EXT.3.

There is precedence for a "slot-names" property that correlates specific
hardware entities with physical labels.  It has been applied to PCI
plug-in slots and to other devices.  See, for example,
http://www.openfirmware.org/1275/proposals/Closed/Accepted/381-it.txt


> 
> 
>>> With the new /dev interface you mention above,
>>> perhaps a symlink to the /dev file, or a file containing the /dev file's
>>> major/minor number. Or, is there such a thing already (other than
>>> debugfs's gpio file).
>>
>> Nothing I know of, but yes the day we come up with something,
>> it needs to be backward-compatible some way.
>>
>> The problem is that there is really no reference userspace
>> like "lsgpio" or so. Maybe the first step could be to create that.
> 
> I don't know much about OpenWrt, but I've seen they have
> something:
> https://dev.openwrt.org/browser/trunk/target/linux/generic/files/drivers/char/gpio_dev.c
> https://dev.openwrt.org/browser/trunk/target/linux/generic/files/include/linux/gpio_dev.h
> https://dev.openwrt.org/browser/trunk/package/gpioctl/src/main.c
> 
> 
> Johannes
> _______________________________________________
> devicetree-discuss mailing list
> devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> https://lists.ozlabs.org/listinfo/devicetree-discuss
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DT GPIO numbering?
  2012-08-06 11:10           ` Mitch Bradley
  (?)
@ 2012-08-10  9:34           ` Johannes Stezenbach
  2012-08-14 10:00             ` Linus Walleij
  -1 siblings, 1 reply; 11+ messages in thread
From: Johannes Stezenbach @ 2012-08-10  9:34 UTC (permalink / raw)
  To: Mitch Bradley; +Cc: Linus Walleij, devicetree-discuss, linux-kernel

On Mon, Aug 06, 2012 at 07:10:00PM +0800, Mitch Bradley wrote:
> On 8/6/2012 5:58 PM, Johannes Stezenbach wrote:
> > On Mon, Aug 06, 2012 at 08:35:51AM +0200, Linus Walleij wrote:
> >> On Mon, Aug 6, 2012 at 4:18 AM, Stephen Warren <swarren@wwwdotorg.org> wrote:
> >>
> >>> I can't comment on the sysfs-vs-dev interface location, but I don't
> >>> think it addresses Johannes' issue; finding out which GPIO IDs are
> >>> provided by which devices.
> >>>
> >>> Perhaps in each device's sysfs node, there should be some information
> >>> re: which GPIO range it provides. Right now, perhaps a text file with
> >>> the GPIO base it it.
> >>
> >> Yes that could work ...
> > 
> > The method used by the gpio-mxs.c driver (of_alias_get_id)
> > would also work.  The question is which method is preferable.
> > 
> > Ideally I would like to use DT attributes to identify my GPIOs
> > in the same way as they appear in the schematics.  E.g.
> > one device may have GPIOs called PORT_A.0 to PORT_A.7,
> > another one may be EXT.0 to EXT.15.  But a single integer ID
> > is good enough since GPIO usage is platform specific anyway.
> > However, the mapping must be static and not depend e.g. on
> > module load order like now if you use pl061 and some i2c GPIO.
> > Software must be able to rely on that e.g. GPIO ID 11
> > always refers to EXT.3.
> 
> There is precedence for a "slot-names" property that correlates specific
> hardware entities with physical labels.  It has been applied to PCI
> plug-in slots and to other devices.  See, for example,
> http://www.openfirmware.org/1275/proposals/Closed/Accepted/381-it.txt

Sorry about the slow response.  After thinking it through I decided
that a) adding ad-hoc DT bindings isn't good, and b) doing
it properly is above my head atm (I have too many other tasks to
take care of).  So I decided to use platform data to get stable
GPIO numbers and names for now.

Actually I think the kernel internal GPIO numbers shouldn't be in the
sysfs API, instead userspace should use the names.  Probably it's
best to not use /sys/class/gpio/export but instead let the board
init code export the GPIOs available to userspace with proper names.
Not sure yet...


Thanks,
Johannes

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DT GPIO numbering?
  2012-08-10  9:34           ` Johannes Stezenbach
@ 2012-08-14 10:00             ` Linus Walleij
  2012-08-14 13:05               ` Johannes Stezenbach
  0 siblings, 1 reply; 11+ messages in thread
From: Linus Walleij @ 2012-08-14 10:00 UTC (permalink / raw)
  To: Johannes Stezenbach, Grant Likely
  Cc: Mitch Bradley, devicetree-discuss, linux-kernel

On Fri, Aug 10, 2012 at 11:34 AM, Johannes Stezenbach <js@sig21.net> wrote:

> Actually I think the kernel internal GPIO numbers shouldn't be in the
> sysfs API, instead userspace should use the names.

This is true, but we cannot remove these numbers because they
are now in Documentation/ABI/testing/sysfs-gpio

And while the "testing" ABI is, well for testing, it would probably
break a lot of stuff it we removed it.

But we can sure add names. However these would still sit under
/sys/class/gpio/gpioN/name

Or do you suggest we simply duplicate all GPIOs which have
names under /sys/class/gpio/named/<name>
or something like that?

I know Grant may have opinions on this...

>  Probably it's
> best to not use /sys/class/gpio/export but instead let the board
> init code export the GPIOs available to userspace with proper names.

This sounds true.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DT GPIO numbering?
  2012-08-14 10:00             ` Linus Walleij
@ 2012-08-14 13:05               ` Johannes Stezenbach
  0 siblings, 0 replies; 11+ messages in thread
From: Johannes Stezenbach @ 2012-08-14 13:05 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Grant Likely, Mitch Bradley, devicetree-discuss, linux-kernel

On Tue, Aug 14, 2012 at 12:00:23PM +0200, Linus Walleij wrote:
> On Fri, Aug 10, 2012 at 11:34 AM, Johannes Stezenbach <js@sig21.net> wrote:
> 
> > Actually I think the kernel internal GPIO numbers shouldn't be in the
> > sysfs API, instead userspace should use the names.
> 
> This is true, but we cannot remove these numbers because they
> are now in Documentation/ABI/testing/sysfs-gpio
> 
> And while the "testing" ABI is, well for testing, it would probably
> break a lot of stuff it we removed it.
> 
> But we can sure add names. However these would still sit under
> /sys/class/gpio/gpioN/name
> 
> Or do you suggest we simply duplicate all GPIOs which have
> names under /sys/class/gpio/named/<name>
> or something like that?

I'm still not sure.  One idea was to add /proc/gpios which maps
names to numbers, then userspace can look up the number and use that.
But the more I think about it /sys/class/gpio/export is just
a debug hack and shouldn't be used.  Board code should export
the available gpio according to pinctrl setup and schematics.
The only catch here is that board code then needs to know which gpio are
for userspace and which are used by in-kernel drivers.
E.g. a LED could be set by LED Triggers or by userspace
Blinkenlight app.


Johannes

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-08-14 13:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-01 15:22 DT GPIO numbering? Johannes Stezenbach
2012-08-05 10:06 ` Linus Walleij
2012-08-05 10:06   ` Linus Walleij
2012-08-06  2:18   ` Stephen Warren
2012-08-06  6:35     ` Linus Walleij
2012-08-06  9:58       ` Johannes Stezenbach
2012-08-06 11:10         ` Mitch Bradley
2012-08-06 11:10           ` Mitch Bradley
2012-08-10  9:34           ` Johannes Stezenbach
2012-08-14 10:00             ` Linus Walleij
2012-08-14 13:05               ` Johannes Stezenbach

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.