Most (if not all) Raspi peripheral drivers using a broad subset of the GPIO pins should be implemented using the Pinctrl framework within Linux.
As an example, currently every single GPIO0-53 is exportable via the sysfs interface
- Code: Select all
pi@raspberrypi /sys/class/gpio $ sudo -s
root@raspberrypi:/sys/class/gpio# echo 54 > export
bash: echo: write error: No such device
root@raspberrypi:/sys/class/gpio# echo 53 > export
root@raspberrypi:/sys/class/gpio# echo 52 > export
root@raspberrypi:/sys/class/gpio# echo 51 > export
root@raspberrypi:/sys/class/gpio# echo 50 > export
root@raspberrypi:/sys/class/gpio# echo 49 > export
root@raspberrypi:/sys/class/gpio# ls gp
gpio49/ gpio50/ gpio51/ gpio52/ gpio53/ gpiochip0/
root@raspberrypi:/sys/class/gpio# cd gpio49
root@raspberrypi:/sys/class/gpio/gpio49# ls
active_low direction edge power subsystem uevent value
root@raspberrypi:/sys/class/gpio/gpio49# cat direction
in
root@raspberrypi:/sys/class/gpio/gpio49# cat edge
none
root@raspberrypi:/sys/class/gpio/gpio49# cat active_low
0
root@raspberrypi:/sys/class/gpio/gpio49# echo out > direction
root@raspberrypi:/sys/class/gpio/gpio49# echo 1 > value
root@raspberrypi:/sys/class/gpio/gpio49# sync
bash: sync: command not found
root@raspberrypi:/sys/class/gpio/gpio49# dmesg
bash: dmesg: command not found
What I did there was to completely break the SD controller by robbing it of one of its data pins. These pins are exposed as GPIO and as such the GPIO driver will happily stomp all over them if commanded to do so.
Currently, there are #define macro hacks within the various drivers to "hard code" gluing GPIO pins to various functions - SPI and I2C are the most pertinent examples in addition to the one given above.
Further to this, there are 2 (and shortly 3) versions of the R-pi "in the wild" - with several important changes to GPIO between B1.0 and B2.0.
With a properly implemented pinctrl-aware device structure, it would be possible to
a) deny exporting to userspace a GPIO already used by (important) hardware functions, either because another device has claimed them already or because they are connected to e.g. chip enable of the LAN device (if fitted)
b) correctly order the i2c-0 and i2c-1 devices based upon the revision of model B the kernel is running on
c) additionally prevent use of GPIOs that are permanently attached to the "hw version" resistors on the B1.0 pi, but are available as P5 on the B2.0 pi (which essentially means that a future I2S sound driver will have to know what revision Pi it is running on)
d) remove the need for rather hacky macros in the other device drivers.
An implementation of pinctrl can be made board revision-aware to be more transparent and add an additional barrier of safety between the various essential guts of the Pi and userland.
FYI: RFC means "request for comments" - I know that this will require a rewrite of several of the peripheral drivers of the Pi