Skip to contentSkip to conversation

GPIO - marking individual pins (not) available in device tree

DISCUSSION Konstantinos Margaritis 6 participants 6 messages Oct 28, 2008 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Pardon my intrusion in the conversation, but I just couldn't not comment on this:

Quoted 6 lines · David Gibson
Quoted 3 lines

So now my qualm is back to the beginning of the discussion. How do we encode the purpose of those pins reliably and within some standard framework, without getting *driver* specific?

Um.. I fail to see how the purpose of a pin can be not driver specific.

GPIO stands for _General_ Purpose IO. The driver should just expose that info to user space and it should be up to the userspace application to decide what to do with that. The programmer should require absolutely no other intervention to the driver whatsoever.
Anyone that has worked on data mining scientific equipment -eg. particle/photon scanners on VME boards with lots of GPIO pins- will tell you that meddling with kernel coding is totally unneeded, in fact it's stupid to require the student to do so. Usually some Windows API is given and the students write the programs on Windows to collect the data and control the device. I guess GPIOLIB and the new framework would have similar application in Linux -ie, requiring the programmer to write only a userspace to access the GPIO pins. From my understanding of the conversation, there are some people who fail to see the necessity of doing extra work to abstract this information away from the driver. A walk to a nearby experimental physicists lab with students working on such devices will convince you of the right way to do it actually.

PS. I am of physics background myself, though a theoritical one and not experimental. But I did have many friends experimentalists, in particular I remember two that did exactly what I described. Neither did have any particular kernel/driver knowledge and neither did have to do anything extremely low-level to acquire the data. Both used windows user-level programming, though that was ~8years ago so don't expect me to remember the exact VME boards or APIs used...

Konstantinos Margaritis
Codex
http://www.codex.gr

#1 lore raw
Quoted 13 lines · Konstantinos Margaritis

Pardon my intrusion in the conversation, but I just couldn't not comment on this:

Quoted 6 lines · David Gibson
Quoted 3 lines

So now my qualm is back to the beginning of the discussion. How do we encode the purpose of those pins reliably and within some standard framework, without getting *driver* specific?

Um.. I fail to see how the purpose of a pin can be not driver specific.

Quoted 14 lines

GPIO stands for _General_ Purpose IO. The driver should just expose that info to user space and it should be up to the userspace application to decide what to do with that. The programmer should require absolutely no other intervention to the driver whatsoever.
Anyone that has worked on data mining scientific equipment -eg. particle/photon scanners on VME boards with lots of GPIO pins- will tell you that meddling with kernel coding is totally unneeded, in fact it's stupid to require the student to do so. Usually some Windows API is given and the students write the programs on Windows to collect the data and control the device. I guess GPIOLIB and the new framework would have similar application in Linux -ie, requiring the programmer to write only a userspace to access the GPIO pins. From my understanding of the conversation, there are some people who fail to see the necessity of doing extra work to abstract this information away from the driver.

Heh. You _have_ the API to work with the GPIOs. In-kernel and userland APIs. What you don't have in the _device tree_ is:

1. The mapping of invalid GPIOs. Though again, this can be easily implemented, just nobody bothers with it since there are million of other ways to do bad things with the hardware resources.

2. The mapping of board's external pins to gpio-controller's GPIOs. This is also can be trivially implemented. Sometimes this mapping could make some sense, and could be useful. You just need describe the board's headers in the device tree. You don't even need the driver for this, your userspace application can just look into the /proc/device-tree directly, and find out which GPIOs are wired to the board's headers.

See? You _can_ use the GPIOs. If you don't believe me, just find some PPC board for which we support some GPIO controller, and compile the kernel with CONFIG_GPIO_SYSFS=y, then look into the /sys/class/gpio/. ;-)

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#2 lore raw
In reply to Konstantinos Margaritis
Quoted 13 lines · Konstantinos Margaritis

Pardon my intrusion in the conversation, but I just couldn't not comment on this:

Quoted 6 lines · David Gibson
Quoted 3 lines

So now my qualm is back to the beginning of the discussion. How do we encode the purpose of those pins reliably and within some standard framework, without getting *driver* specific?

Um.. I fail to see how the purpose of a pin can be not driver specific.

Quoted 16 lines

GPIO stands for _General_ Purpose IO. The driver should just expose that info to user space and it should be up to the userspace application to decide what to do with that. The programmer should require absolutely no other intervention to the driver whatsoever.
Anyone that has worked on data mining scientific equipment -eg. particle/photon scanners on VME boards with lots of GPIO pins- will tell you that meddling with kernel coding is totally unneeded, in fact it's stupid to require the student to do so. Usually some Windows API is given and the students write the programs on Windows to collect the data and control the device. I guess GPIOLIB and the new framework would have similar application in Linux -ie, requiring the programmer to write only a userspace to access the GPIO pins. From my understanding of the conversation, there are some people who fail to see the necessity of doing extra work to abstract this information away from the driver. A walk to a nearby experimental physicists lab with students working on such devices will convince you of the right way to do it actually.

All this already exists. All GPIO pins using GPIOLIB are exportable
and usable from userspace with no kernel coding whatsoever. However, some of those GPIO pins are also used by in-kernel driver to implement things like i2c, spi, mdio and jtag which use in-kernel infrastructure, so it is critical to support both kernel and user space users.

As far as David's comment about pins being driver specific; that really is true. Once a GPIO pin is wired to something it becomes specific purpose which is device/board/connection specific, regardless of if the driver is in kernel or a user space application (Just because it is user space code doesn't mean it isn't a device driver). If the driver willfully uses the wrong GPIO pins then things simply won't work and it is critical for the device tree to contain valid data about GPIO connections.

For Matt's purposes, I think he wants to describe which GPIO pins are available to be used, but are not yet connected to anything. In such a case I think it does make sense to add a node for available GPIO pins and give it a gpios property with a list of the pins wired to the header.

Thanks for the comments.

g.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#4 lore raw
In reply to a message not in the archive
Quoted 6 lines · Grant Likely

For Matt's purposes, I think he wants to describe which GPIO pins are available to be used, but are not yet connected to anything. In such a case I think it does make sense to add a node for available GPIO pins and give it a gpios property with a list of the pins wired to the header.

Yes, the two problems I saw were there is only an implicit definition of which gpios are available for use (GPIOLIB will happily give you an unavailable pin if you ask for it, because there is no definition except for "gpios" property as hooked up to a device).

I liked Mitch's idea about the available property and re-using already existing standards and parsing to get it done.

(this allows some syntax/lint checking of a device tree too since if you put a pin in a gpios property which you marked as unavailable, you can flag it :)

The other problem was defining pins which most definitely ARE connected to something (as GPIO) but could well be in an ill-defined order or for no defined purpose with regards to the peripheral. A lot of GPIO drivers right now (bitbang SPI, I2C) will just allocate one pin as one thing and the other as another - if you say pin 15 and 16 for bitbang-i2c, then it may assumes pin 15 is clock and 16 is data. For SPI, you get another pin, which order is it (the middle one may be correct but the outer ones could be swapped).

Is this even defined? Shouldn't it be? And therein lies the question :)

Exposing it to userspace is a good idea. While grouping them up would break the existing sysfs ABI there's no reason you can't have all of the GPIOs dumped into sysfs as it is now, and then new directories named after the gpio-group, which symlink back to the sysfs pins in the parent directory? That would really rock as it's bringing the abstraction and description of the device tree back into userspace, where let's be honest, they do not give a crap about device tree bindings, only what pin does what action :D

Signature · 2 lines
Matt Sealey <[email protected]>
Genesi, Manager, Developer Relations
#5 lore raw
Quoted 8 lines · Matt Sealey

The other problem was defining pins which most definitely ARE connected to something (as GPIO) but could well be in an ill-defined order or for no defined purpose with regards to the peripheral. A lot of GPIO drivers right now (bitbang SPI, I2C) will just allocate one pin as one thing and the other as another - if you say pin 15 and 16 for bitbang-i2c, then it may assumes pin 15 is clock and 16 is data. For SPI, you get another pin, which order is it (the middle one may be correct but the outer ones could be swapped).

Yes, order is important, and yes it should be defined. That is what the binding documentation must specify. It is no different from the ordering of multiple ranges in the reg property or multiple interrupts.

Quoted 2 lines

Is this even defined? Shouldn't it be? And therein lies the question :)

Yes and yes. It all hangs off the value of compatible and the documentation of what the compatible value means.

g.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#6 lore raw
In reply to Konstantinos Margaritis
Quoted 10 lines · Konstantinos Margaritis

Pardon my intrusion in the conversation, but I just couldn't not comment on this:

Quoted 4 lines · David Gibson
Quoted 3 lines

So now my qualm is back to the beginning of the discussion. How do we encode the purpose of those pins reliably and within some standard framework, without getting *driver* specific?

Quoted 7 lines
Quoted 2 lines

Um.. I fail to see how the purpose of a pin can be not driver specific.

GPIO stands for _General_ Purpose IO. The driver should just expose that info to user space and it should be up to the userspace application to decide what to do with that. The programmer should require absolutely no other intervention to the driver whatsoever.

Yes, which is exactly why the purpose of the pin is driver specific. That's the driver for the user of the pin, not the gpio controller. In some cases that's another kernel driver, where some device needs gpio access, in your case it's the userspace application. But in either case it's this driver that must know what gpio line to use, and how to use it.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson