12646b90dSLinus WalleijThis is a place for planning the ongoing long-term work in the GPIO 22646b90dSLinus Walleijsubsystem. 32646b90dSLinus Walleij 42646b90dSLinus Walleij 52646b90dSLinus WalleijGPIO descriptors 62646b90dSLinus Walleij 72646b90dSLinus WalleijStarting with commit 79a9becda894 the GPIO subsystem embarked on a journey 83abda79aSKieran Binghamto move away from the global GPIO numberspace and toward a descriptor-based 92646b90dSLinus Walleijapproach. This means that GPIO consumers, drivers and machine descriptions 102646b90dSLinus Walleijideally have no use or idea of the global GPIO numberspace that has/was 112646b90dSLinus Walleijused in the inception of the GPIO subsystem. 122646b90dSLinus Walleij 1397082890SLinus WalleijThe numberspace issue is the same as to why irq is moving away from irq 1497082890SLinus Walleijnumbers to IRQ descriptors. 1597082890SLinus Walleij 1697082890SLinus WalleijThe underlying motivation for this is that the GPIO numberspace has become 1797082890SLinus Walleijunmanageable: machine board files tend to become full of macros trying to 1897082890SLinus Walleijestablish the numberspace at compile-time, making it hard to add any numbers 1997082890SLinus Walleijin the middle (such as if you missed a pin on a chip) without the numberspace 2097082890SLinus Walleijbreaking. 2197082890SLinus Walleij 2297082890SLinus WalleijMachine descriptions such as device tree or ACPI does not have a concept of the 2397082890SLinus WalleijLinux GPIO number as those descriptions are external to the Linux kernel 2497082890SLinus Walleijand treat GPIO lines as abstract entities. 2597082890SLinus Walleij 2697082890SLinus WalleijThe runtime-assigned GPIO numberspace (what you get if you assign the GPIO 2797082890SLinus Walleijbase as -1 in struct gpio_chip) has also became unpredictable due to factors 2897082890SLinus Walleijsuch as probe ordering and the introduction of -EPROBE_DEFER making probe 2997082890SLinus Walleijordering of independent GPIO chips essentially unpredictable, as their base 3097082890SLinus Walleijnumber will be assigned on a first come first serve basis. 3197082890SLinus Walleij 3297082890SLinus WalleijThe best way to get out of the problem is to make the global GPIO numbers 3397082890SLinus Walleijunimportant by simply not using them. GPIO descriptors deal with this. 3497082890SLinus Walleij 352646b90dSLinus WalleijWork items: 362646b90dSLinus Walleij 372646b90dSLinus Walleij- Convert all GPIO device drivers to only #include <linux/gpio/driver.h> 382646b90dSLinus Walleij 392646b90dSLinus Walleij- Convert all consumer drivers to only #include <linux/gpio/consumer.h> 402646b90dSLinus Walleij 412646b90dSLinus Walleij- Convert all machine descriptors in "boardfiles" to only 422646b90dSLinus Walleij #include <linux/gpio/machine.h>, the other option being to convert it 432646b90dSLinus Walleij to a machine description such as device tree, ACPI or fwnode that 442646b90dSLinus Walleij implicitly does not use global GPIO numbers. 452646b90dSLinus Walleij 462646b90dSLinus Walleij- When this work is complete (will require some of the items in the 472646b90dSLinus Walleij following ongoing work as well) we can delete the old global 482646b90dSLinus Walleij numberspace accessors from <linux/gpio.h> and eventually delete 492646b90dSLinus Walleij <linux/gpio.h> altogether. 502646b90dSLinus Walleij 512646b90dSLinus Walleij 522646b90dSLinus WalleijGet rid of <linux/of_gpio.h> 532646b90dSLinus Walleij 542646b90dSLinus WalleijThis header and helpers appeared at one point when there was no proper 552646b90dSLinus Walleijdriver infrastructure for doing simpler MMIO GPIO devices and there was 562646b90dSLinus Walleijno core support for parsing device tree GPIOs from the core library with 572646b90dSLinus Walleijthe [devm_]gpiod_get() calls we have today that will implicitly go into 5897082890SLinus Walleijthe device tree back-end. It is legacy and should not be used in new code. 592646b90dSLinus Walleij 602646b90dSLinus WalleijWork items: 612646b90dSLinus Walleij 622646b90dSLinus Walleij- Change all consumer drivers that #include <linux/of_gpio.h> to 632646b90dSLinus Walleij #include <linux/gpio/consumer.h> and stop doing custom parsing of the 64*f53ab435SShivam Chaudhary GPIO lines from the device tree. This can be tricky and often involves 652646b90dSLinus Walleij changing board files, etc. 662646b90dSLinus Walleij 672646b90dSLinus Walleij- Pull semantics for legacy device tree (OF) GPIO lookups into 682646b90dSLinus Walleij gpiolib-of.c: in some cases subsystems are doing custom flags and 692646b90dSLinus Walleij lookups for polarity inversion, open drain and what not. As we now 702646b90dSLinus Walleij handle this with generic OF bindings, pull all legacy handling into 712646b90dSLinus Walleij gpiolib so the library API becomes narrow and deep and handle all 722646b90dSLinus Walleij legacy bindings internally. (See e.g. commits 6953c57ab172, 732646b90dSLinus Walleij 6a537d48461d etc) 742646b90dSLinus Walleij 752646b90dSLinus Walleij- Delete <linux/of_gpio.h> when all the above is complete and everything 762646b90dSLinus Walleij uses <linux/gpio/consumer.h> or <linux/gpio/driver.h> instead. 772646b90dSLinus Walleij 782646b90dSLinus Walleij 79a99cc668SArnd BergmannGet rid of <linux/gpio/legacy-of-mm-gpiochip.h> 80a99cc668SArnd Bergmann 81a99cc668SArnd BergmannWork items: 82a99cc668SArnd Bergmann 83a99cc668SArnd Bergmann- Get rid of struct of_mm_gpio_chip altogether: use the generic MMIO 84a99cc668SArnd Bergmann GPIO for all current users (see below). Delete struct of_mm_gpio_chip, 85a99cc668SArnd Bergmann to_of_mm_gpio_chip(), of_mm_gpiochip_add_data(), of_mm_gpiochip_remove(), 86a99cc668SArnd Bergmann CONFIG_OF_GPIO_MM_GPIOCHIP from the kernel. 87a99cc668SArnd Bergmann 88a99cc668SArnd Bergmann 8997082890SLinus WalleijGet rid of <linux/gpio.h> 9097082890SLinus Walleij 9197082890SLinus WalleijThis legacy header is a one stop shop for anything GPIO is closely tied 9297082890SLinus Walleijto the global GPIO numberspace. The endgame of the above refactorings will 9397082890SLinus Walleijbe the removal of <linux/gpio.h> and from that point only the specialized 9497082890SLinus Walleijheaders under <linux/gpio/*.h> will be used. This requires all the above to 9597082890SLinus Walleijbe completed and is expected to take a long time. 9697082890SLinus Walleij 9797082890SLinus Walleij 982646b90dSLinus WalleijCollect drivers 992646b90dSLinus Walleij 1002646b90dSLinus WalleijCollect GPIO drivers from arch/* and other places that should be placed 1012646b90dSLinus Walleijin drivers/gpio/gpio-*. Augment platforms to create platform devices or 1022646b90dSLinus Walleijsimilar and probe a proper driver in the gpiolib subsystem. 1032646b90dSLinus Walleij 1042646b90dSLinus WalleijIn some cases it makes sense to create a GPIO chip from the local driver 1052646b90dSLinus Walleijfor a few GPIOs. Those should stay where they are. 1062646b90dSLinus Walleij 10785a94ff8SAndy ShevchenkoAt the same time it makes sense to get rid of code duplication in existing or 10885a94ff8SAndy Shevchenkonew coming drivers. For example, gpio-ml-ioh should be incorporated into 1095f7582aaSAndy Shevchenkogpio-pch. 11085a94ff8SAndy Shevchenko 1112646b90dSLinus Walleij 1122646b90dSLinus WalleijGeneric MMIO GPIO 1132646b90dSLinus Walleij 1142646b90dSLinus WalleijThe GPIO drivers can utilize the generic MMIO helper library in many 1152646b90dSLinus Walleijcases, and the helper library should be as helpful as possible for MMIO 1162646b90dSLinus Walleijdrivers. (drivers/gpio/gpio-mmio.c) 1172646b90dSLinus Walleij 1182646b90dSLinus WalleijWork items: 1192646b90dSLinus Walleij 1202646b90dSLinus Walleij- Look over and identify any remaining easily converted drivers and 1212646b90dSLinus Walleij dry-code conversions to MMIO GPIO for maintainers to test 1222646b90dSLinus Walleij 12341c4616bSLinus Walleij- Expand the MMIO GPIO or write a new library for regmap-based I/O 12441c4616bSLinus Walleij helpers for GPIO drivers on regmap that simply use offsets 12541c4616bSLinus Walleij 0..n in some register to drive GPIO lines 12641c4616bSLinus Walleij 1272646b90dSLinus Walleij- Expand the MMIO GPIO or write a new library for port-mapped I/O 1282646b90dSLinus Walleij helpers (x86 inb()/outb()) and convert port-mapped I/O drivers to use 1292646b90dSLinus Walleij this with dry-coding and sending to maintainers to test 1302646b90dSLinus Walleij 1312646b90dSLinus Walleij 132c8a51f03SAndy ShevchenkoGeneric regmap GPIO 133c8a51f03SAndy Shevchenko 134c8a51f03SAndy ShevchenkoIn the very similar way to Generic MMIO GPIO convert the users which can 135c8a51f03SAndy Shevchenkotake advantage of using regmap over direct IO accessors. Note, even in 136c8a51f03SAndy ShevchenkoMMIO case the regmap MMIO with gpio-regmap.c is preferable over gpio-mmio.c. 137c8a51f03SAndy Shevchenko 138c8a51f03SAndy Shevchenko 1392646b90dSLinus WalleijGPIOLIB irqchip 1402646b90dSLinus Walleij 1412646b90dSLinus WalleijThe GPIOLIB irqchip is a helper irqchip for "simple cases" that should 1422646b90dSLinus Walleijtry to cover any generic kind of irqchip cascaded from a GPIO. 1432646b90dSLinus Walleij 1442646b90dSLinus Walleij- Look over and identify any remaining easily converted drivers and 1452646b90dSLinus Walleij dry-code conversions to gpiolib irqchip for maintainers to test 1462646b90dSLinus Walleij 1472646b90dSLinus Walleij 1482646b90dSLinus WalleijIncrease integration with pin control 1492646b90dSLinus Walleij 1502646b90dSLinus WalleijThere are already ways to use pin control as back-end for GPIO and 1512646b90dSLinus Walleijit may make sense to bring these subsystems closer. One reason for 1522646b90dSLinus Walleijcreating pin control as its own subsystem was that we could avoid any 1532646b90dSLinus Walleijuse of the global GPIO numbers. Once the above is complete, it may 1542646b90dSLinus Walleijmake sense to simply join the subsystems into one and make pin 1552646b90dSLinus Walleijmultiplexing, pin configuration, GPIO, etc selectable options in one 1562646b90dSLinus Walleijand the same pin control and GPIO subsystem. 157dd0fa811SLinus Walleij 158dd0fa811SLinus Walleij 159dd0fa811SLinus WalleijDebugfs in place of sysfs 160dd0fa811SLinus Walleij 161dd0fa811SLinus WalleijThe old sysfs code that enables simple uses of GPIOs from the 162dd0fa811SLinus Walleijcommand line is still popular despite the existance of the proper 163dd0fa811SLinus Walleijcharacter device. The reason is that it is simple to use on 164dd0fa811SLinus Walleijroot filesystems where you only have a minimal set of tools such 165dd0fa811SLinus Walleijas "cat", "echo" etc. 166dd0fa811SLinus Walleij 167dd0fa811SLinus WalleijThe old sysfs still need to be strongly deprecated and removed 168dd0fa811SLinus Walleijas it relies on the global GPIO numberspace that assume a strict 169dd0fa811SLinus Walleijorder of global GPIO numbers that do not change between boots 170dd0fa811SLinus Walleijand is independent of probe order. 171dd0fa811SLinus Walleij 172dd0fa811SLinus WalleijTo solve this and provide an ABI that people can use for hacks 173dd0fa811SLinus Walleijand development, implement a debugfs interface to manipulate 174dd0fa811SLinus WalleijGPIO lines that can do everything that sysfs can do today: one 175dd0fa811SLinus Walleijdirectory per gpiochip and one file entry per line: 176dd0fa811SLinus Walleij 177dd0fa811SLinus Walleij/sys/kernel/debug/gpiochip/gpiochip0 178dd0fa811SLinus Walleij/sys/kernel/debug/gpiochip/gpiochip0/gpio0 179dd0fa811SLinus Walleij/sys/kernel/debug/gpiochip/gpiochip0/gpio1 180dd0fa811SLinus Walleij/sys/kernel/debug/gpiochip/gpiochip0/gpio2 181dd0fa811SLinus Walleij/sys/kernel/debug/gpiochip/gpiochip0/gpio3 182dd0fa811SLinus Walleij... 183dd0fa811SLinus Walleij/sys/kernel/debug/gpiochip/gpiochip1 184dd0fa811SLinus Walleij/sys/kernel/debug/gpiochip/gpiochip1/gpio0 185dd0fa811SLinus Walleij/sys/kernel/debug/gpiochip/gpiochip1/gpio1 186dd0fa811SLinus Walleij... 187dd0fa811SLinus Walleij 188dd0fa811SLinus WalleijThe exact files and design of the debugfs interface can be 189dd0fa811SLinus Walleijdiscussed but the idea is to provide a low-level access point 190dd0fa811SLinus Walleijfor debugging and hacking and to expose all lines without the 191dd0fa811SLinus Walleijneed of any exporting. Also provide ample ammunition to shoot 192dd0fa811SLinus Walleijoneself in the foot, because this is debugfs after all. 193afefc326SMarc Zyngier 194afefc326SMarc Zyngier 195afefc326SMarc ZyngierMoving over to immutable irq_chip structures 196afefc326SMarc Zyngier 197afefc326SMarc ZyngierMost of the gpio chips implementing interrupt support rely on gpiolib 198afefc326SMarc Zyngierintercepting some of the irq_chip callbacks, preventing the structures 199afefc326SMarc Zyngierfrom being made read-only and forcing duplication of structures that 200afefc326SMarc Zyngiershould otherwise be unique. 201afefc326SMarc Zyngier 202afefc326SMarc ZyngierThe solution is to call into the gpiolib code when needed (resource 203afefc326SMarc Zyngiermanagement, enable/disable or unmask/mask callbacks), and to let the 204afefc326SMarc Zyngiercore code know about that by exposing a flag (IRQCHIP_IMMUTABLE) in 205afefc326SMarc Zyngierthe irq_chip structure. The irq_chip structure can then be made unique 206afefc326SMarc Zyngierand const. 207afefc326SMarc Zyngier 208afefc326SMarc ZyngierA small number of drivers have been converted (pl061, tegra186, msm, 209afefc326SMarc Zyngieramd, apple), and can be used as examples of how to proceed with this 210afefc326SMarc Zyngierconversion. Note that drivers using the generic irqchip framework 211afefc326SMarc Zyngiercannot be converted yet, but watch this space! 212