12646b90dSLinus WalleijThis is a place for planning the ongoing long-term work in the GPIO 22646b90dSLinus Walleijsubsystem. 32646b90dSLinus Walleij 45ceb3536SBartosz Golaszewski=============================================================================== 52646b90dSLinus Walleij 62646b90dSLinus WalleijGPIO descriptors 72646b90dSLinus Walleij 82646b90dSLinus WalleijStarting with commit 79a9becda894 the GPIO subsystem embarked on a journey 93abda79aSKieran Binghamto move away from the global GPIO numberspace and toward a descriptor-based 102646b90dSLinus Walleijapproach. This means that GPIO consumers, drivers and machine descriptions 112646b90dSLinus Walleijideally have no use or idea of the global GPIO numberspace that has/was 122646b90dSLinus Walleijused in the inception of the GPIO subsystem. 132646b90dSLinus Walleij 1497082890SLinus WalleijThe numberspace issue is the same as to why irq is moving away from irq 1597082890SLinus Walleijnumbers to IRQ descriptors. 1697082890SLinus Walleij 1797082890SLinus WalleijThe underlying motivation for this is that the GPIO numberspace has become 1897082890SLinus Walleijunmanageable: machine board files tend to become full of macros trying to 1997082890SLinus Walleijestablish the numberspace at compile-time, making it hard to add any numbers 2097082890SLinus Walleijin the middle (such as if you missed a pin on a chip) without the numberspace 2197082890SLinus Walleijbreaking. 2297082890SLinus Walleij 2397082890SLinus WalleijMachine descriptions such as device tree or ACPI does not have a concept of the 2497082890SLinus WalleijLinux GPIO number as those descriptions are external to the Linux kernel 2597082890SLinus Walleijand treat GPIO lines as abstract entities. 2697082890SLinus Walleij 2797082890SLinus WalleijThe runtime-assigned GPIO numberspace (what you get if you assign the GPIO 2897082890SLinus Walleijbase as -1 in struct gpio_chip) has also became unpredictable due to factors 2997082890SLinus Walleijsuch as probe ordering and the introduction of -EPROBE_DEFER making probe 3097082890SLinus Walleijordering of independent GPIO chips essentially unpredictable, as their base 3197082890SLinus Walleijnumber will be assigned on a first come first serve basis. 3297082890SLinus Walleij 3397082890SLinus WalleijThe best way to get out of the problem is to make the global GPIO numbers 3497082890SLinus Walleijunimportant by simply not using them. GPIO descriptors deal with this. 3597082890SLinus Walleij 362646b90dSLinus WalleijWork items: 372646b90dSLinus Walleij 382646b90dSLinus Walleij- Convert all GPIO device drivers to only #include <linux/gpio/driver.h> 392646b90dSLinus Walleij 402646b90dSLinus Walleij- Convert all consumer drivers to only #include <linux/gpio/consumer.h> 412646b90dSLinus Walleij 422646b90dSLinus Walleij- Convert all machine descriptors in "boardfiles" to only 432646b90dSLinus Walleij #include <linux/gpio/machine.h>, the other option being to convert it 442646b90dSLinus Walleij to a machine description such as device tree, ACPI or fwnode that 452646b90dSLinus Walleij implicitly does not use global GPIO numbers. 462646b90dSLinus Walleij 47833c086fSAhmad Fatoum- Fix drivers to not read back struct gpio_chip::base. Some drivers do 48833c086fSAhmad Fatoum that and would be broken by attempts to poison it or make it dynamic. 49833c086fSAhmad Fatoum Example in AT91 pinctrl driver: 50833c086fSAhmad Fatoum https://lore.kernel.org/all/1d00c056-3d61-4c22-bedd-3bae0bf1ddc4@pengutronix.de/ 51833c086fSAhmad Fatoum This particular driver is also DT-only, so with the above fixed, the 52833c086fSAhmad Fatoum base can be made dynamic (set to -1) if CONFIG_GPIO_SYSFS is disabled. 53833c086fSAhmad Fatoum 542646b90dSLinus Walleij- When this work is complete (will require some of the items in the 552646b90dSLinus Walleij following ongoing work as well) we can delete the old global 562646b90dSLinus Walleij numberspace accessors from <linux/gpio.h> and eventually delete 572646b90dSLinus Walleij <linux/gpio.h> altogether. 582646b90dSLinus Walleij 595ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 602646b90dSLinus Walleij 612646b90dSLinus WalleijGet rid of <linux/of_gpio.h> 622646b90dSLinus Walleij 632646b90dSLinus WalleijThis header and helpers appeared at one point when there was no proper 642646b90dSLinus Walleijdriver infrastructure for doing simpler MMIO GPIO devices and there was 652646b90dSLinus Walleijno core support for parsing device tree GPIOs from the core library with 662646b90dSLinus Walleijthe [devm_]gpiod_get() calls we have today that will implicitly go into 6797082890SLinus Walleijthe device tree back-end. It is legacy and should not be used in new code. 682646b90dSLinus Walleij 692646b90dSLinus WalleijWork items: 702646b90dSLinus Walleij 712646b90dSLinus Walleij- Change all consumer drivers that #include <linux/of_gpio.h> to 722646b90dSLinus Walleij #include <linux/gpio/consumer.h> and stop doing custom parsing of the 73f53ab435SShivam Chaudhary GPIO lines from the device tree. This can be tricky and often involves 742646b90dSLinus Walleij changing board files, etc. 752646b90dSLinus Walleij 762646b90dSLinus Walleij- Pull semantics for legacy device tree (OF) GPIO lookups into 772646b90dSLinus Walleij gpiolib-of.c: in some cases subsystems are doing custom flags and 782646b90dSLinus Walleij lookups for polarity inversion, open drain and what not. As we now 792646b90dSLinus Walleij handle this with generic OF bindings, pull all legacy handling into 802646b90dSLinus Walleij gpiolib so the library API becomes narrow and deep and handle all 812646b90dSLinus Walleij legacy bindings internally. (See e.g. commits 6953c57ab172, 822646b90dSLinus Walleij 6a537d48461d etc) 832646b90dSLinus Walleij 842646b90dSLinus Walleij- Delete <linux/of_gpio.h> when all the above is complete and everything 852646b90dSLinus Walleij uses <linux/gpio/consumer.h> or <linux/gpio/driver.h> instead. 862646b90dSLinus Walleij 875ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 882646b90dSLinus Walleij 89a99cc668SArnd BergmannGet rid of <linux/gpio/legacy-of-mm-gpiochip.h> 90a99cc668SArnd Bergmann 91a99cc668SArnd BergmannWork items: 92a99cc668SArnd Bergmann 93a99cc668SArnd Bergmann- Get rid of struct of_mm_gpio_chip altogether: use the generic MMIO 94a99cc668SArnd Bergmann GPIO for all current users (see below). Delete struct of_mm_gpio_chip, 95a99cc668SArnd Bergmann to_of_mm_gpio_chip(), of_mm_gpiochip_add_data(), of_mm_gpiochip_remove(), 96a99cc668SArnd Bergmann CONFIG_OF_GPIO_MM_GPIOCHIP from the kernel. 97a99cc668SArnd Bergmann 985ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 99a99cc668SArnd Bergmann 1002646b90dSLinus WalleijCollect drivers 1012646b90dSLinus Walleij 1022646b90dSLinus WalleijCollect GPIO drivers from arch/* and other places that should be placed 1032646b90dSLinus Walleijin drivers/gpio/gpio-*. Augment platforms to create platform devices or 1042646b90dSLinus Walleijsimilar and probe a proper driver in the gpiolib subsystem. 1052646b90dSLinus Walleij 1062646b90dSLinus WalleijIn some cases it makes sense to create a GPIO chip from the local driver 1072646b90dSLinus Walleijfor a few GPIOs. Those should stay where they are. 1082646b90dSLinus Walleij 10985a94ff8SAndy ShevchenkoAt the same time it makes sense to get rid of code duplication in existing or 11085a94ff8SAndy Shevchenkonew coming drivers. For example, gpio-ml-ioh should be incorporated into 1115f7582aaSAndy Shevchenkogpio-pch. 11285a94ff8SAndy Shevchenko 1135ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 1142646b90dSLinus Walleij 1152646b90dSLinus WalleijGeneric MMIO GPIO 1162646b90dSLinus Walleij 1172646b90dSLinus WalleijThe GPIO drivers can utilize the generic MMIO helper library in many 1182646b90dSLinus Walleijcases, and the helper library should be as helpful as possible for MMIO 1192646b90dSLinus Walleijdrivers. (drivers/gpio/gpio-mmio.c) 1202646b90dSLinus Walleij 1212646b90dSLinus WalleijWork items: 1222646b90dSLinus Walleij 1232646b90dSLinus Walleij- Look over and identify any remaining easily converted drivers and 1242646b90dSLinus Walleij dry-code conversions to MMIO GPIO for maintainers to test 1252646b90dSLinus Walleij 12641c4616bSLinus Walleij- Expand the MMIO GPIO or write a new library for regmap-based I/O 12741c4616bSLinus Walleij helpers for GPIO drivers on regmap that simply use offsets 12841c4616bSLinus Walleij 0..n in some register to drive GPIO lines 12941c4616bSLinus Walleij 1302646b90dSLinus Walleij- Expand the MMIO GPIO or write a new library for port-mapped I/O 1312646b90dSLinus Walleij helpers (x86 inb()/outb()) and convert port-mapped I/O drivers to use 1322646b90dSLinus Walleij this with dry-coding and sending to maintainers to test 1332646b90dSLinus Walleij 1345ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 1352646b90dSLinus Walleij 136c8a51f03SAndy ShevchenkoGeneric regmap GPIO 137c8a51f03SAndy Shevchenko 138c8a51f03SAndy ShevchenkoIn the very similar way to Generic MMIO GPIO convert the users which can 139c8a51f03SAndy Shevchenkotake advantage of using regmap over direct IO accessors. Note, even in 140c8a51f03SAndy ShevchenkoMMIO case the regmap MMIO with gpio-regmap.c is preferable over gpio-mmio.c. 141c8a51f03SAndy Shevchenko 1425ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 143c8a51f03SAndy Shevchenko 1442646b90dSLinus WalleijGPIOLIB irqchip 1452646b90dSLinus Walleij 1462646b90dSLinus WalleijThe GPIOLIB irqchip is a helper irqchip for "simple cases" that should 1472646b90dSLinus Walleijtry to cover any generic kind of irqchip cascaded from a GPIO. 1482646b90dSLinus Walleij 1492646b90dSLinus Walleij- Look over and identify any remaining easily converted drivers and 1502646b90dSLinus Walleij dry-code conversions to gpiolib irqchip for maintainers to test 1512646b90dSLinus Walleij 1525ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 1532646b90dSLinus Walleij 154afefc326SMarc ZyngierMoving over to immutable irq_chip structures 155afefc326SMarc Zyngier 156afefc326SMarc ZyngierMost of the gpio chips implementing interrupt support rely on gpiolib 157afefc326SMarc Zyngierintercepting some of the irq_chip callbacks, preventing the structures 158afefc326SMarc Zyngierfrom being made read-only and forcing duplication of structures that 159afefc326SMarc Zyngiershould otherwise be unique. 160afefc326SMarc Zyngier 161afefc326SMarc ZyngierThe solution is to call into the gpiolib code when needed (resource 162afefc326SMarc Zyngiermanagement, enable/disable or unmask/mask callbacks), and to let the 163afefc326SMarc Zyngiercore code know about that by exposing a flag (IRQCHIP_IMMUTABLE) in 164afefc326SMarc Zyngierthe irq_chip structure. The irq_chip structure can then be made unique 165afefc326SMarc Zyngierand const. 166afefc326SMarc Zyngier 167afefc326SMarc ZyngierA small number of drivers have been converted (pl061, tegra186, msm, 168afefc326SMarc Zyngieramd, apple), and can be used as examples of how to proceed with this 169afefc326SMarc Zyngierconversion. Note that drivers using the generic irqchip framework 170afefc326SMarc Zyngiercannot be converted yet, but watch this space! 1719ff2443bSBartosz Golaszewski 1729ff2443bSBartosz Golaszewski------------------------------------------------------------------------------- 1739ff2443bSBartosz Golaszewski 174*0c0438d4SBartosz GolaszewskiRemove legacy sysfs features 175af54a2fbSBartosz Golaszewski 176*0c0438d4SBartosz GolaszewskiWe have two parallel per-chip class devices and per-exported-line attribute 177*0c0438d4SBartosz Golaszewskigroups in sysfs. One is using the obsolete global GPIO numberspace and the 178*0c0438d4SBartosz Golaszewskisecond relies on hardware offsets of pins within the chip. Remove the former 179*0c0438d4SBartosz Golaszewskionce user-space has switched to using the latter. 1802de1cf17SBartosz Golaszewski 1812de1cf17SBartosz Golaszewski------------------------------------------------------------------------------- 1822de1cf17SBartosz Golaszewski 1832de1cf17SBartosz GolaszewskiRemove GPIOD_FLAGS_BIT_NONEXCLUSIVE 1842de1cf17SBartosz Golaszewski 1852de1cf17SBartosz GolaszewskiGPIOs in the linux kernel are meant to be an exclusive resource. This means 1862de1cf17SBartosz Golaszewskithat the GPIO descriptors (the software representation of the hardware concept) 1872de1cf17SBartosz Golaszewskiare not reference counted and - in general - only one user at a time can 1882de1cf17SBartosz Golaszewskirequest a GPIO line and control its settings. The consumer API is designed 1892de1cf17SBartosz Golaszewskiaround full control of the line's state as evidenced by the fact that, for 1902de1cf17SBartosz Golaszewskiinstance, gpiod_set_value() does indeed drive the line as requested, instead 1912de1cf17SBartosz Golaszewskiof bumping an enable counter of some sort. 1922de1cf17SBartosz Golaszewski 1932de1cf17SBartosz GolaszewskiA problematic use-case for GPIOs is when two consumers want to use the same 1942de1cf17SBartosz Golaszewskidescriptor independently. An example of such a user is the regulator subsystem 1952de1cf17SBartosz Golaszewskiwhich may instantiate several struct regulator_dev instances containing 1962de1cf17SBartosz Golaszewskia struct device but using the same enable GPIO line. 1972de1cf17SBartosz Golaszewski 1982de1cf17SBartosz GolaszewskiA workaround was introduced in the form of the GPIOD_FLAGS_BIT_NONEXCLUSIVE 1992de1cf17SBartosz Golaszewskiflag but its implementation is problematic: it does not provide any 2002de1cf17SBartosz Golaszewskisynchronization of usage nor did it introduce any enable count meaning the 2012de1cf17SBartosz Golaszewskinon-exclusive users of the same descriptor will in fact "fight" for the 2022de1cf17SBartosz Golaszewskicontrol over it. This flag should be removed and replaced with a better 2032de1cf17SBartosz Golaszewskisolution, possibly based on the new power sequencing subsystem. 2042de1cf17SBartosz Golaszewski 2052de1cf17SBartosz Golaszewski------------------------------------------------------------------------------- 2062de1cf17SBartosz Golaszewski 2072de1cf17SBartosz GolaszewskiRemove devm_gpiod_unhinge() 2082de1cf17SBartosz Golaszewski 2092de1cf17SBartosz Golaszewskidevm_gpiod_unhinge() is provided as a way to transfer the ownership of managed 2102de1cf17SBartosz Golaszewskienable GPIOs to the regulator core. Rather than doing that however, we should 2112de1cf17SBartosz Golaszewskimake it possible for the regulator subsystem to deal with GPIO resources the 2122de1cf17SBartosz Golaszewskilifetime of which it doesn't control as logically, a GPIO obtained by a caller 2132de1cf17SBartosz Golaszewskishould also be freed by it. 214