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 472646b90dSLinus Walleij- When this work is complete (will require some of the items in the 482646b90dSLinus Walleij following ongoing work as well) we can delete the old global 492646b90dSLinus Walleij numberspace accessors from <linux/gpio.h> and eventually delete 502646b90dSLinus Walleij <linux/gpio.h> altogether. 512646b90dSLinus Walleij 525ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 532646b90dSLinus Walleij 542646b90dSLinus WalleijGet rid of <linux/of_gpio.h> 552646b90dSLinus Walleij 562646b90dSLinus WalleijThis header and helpers appeared at one point when there was no proper 572646b90dSLinus Walleijdriver infrastructure for doing simpler MMIO GPIO devices and there was 582646b90dSLinus Walleijno core support for parsing device tree GPIOs from the core library with 592646b90dSLinus Walleijthe [devm_]gpiod_get() calls we have today that will implicitly go into 6097082890SLinus Walleijthe device tree back-end. It is legacy and should not be used in new code. 612646b90dSLinus Walleij 622646b90dSLinus WalleijWork items: 632646b90dSLinus Walleij 642646b90dSLinus Walleij- Change all consumer drivers that #include <linux/of_gpio.h> to 652646b90dSLinus Walleij #include <linux/gpio/consumer.h> and stop doing custom parsing of the 66f53ab435SShivam Chaudhary GPIO lines from the device tree. This can be tricky and often involves 672646b90dSLinus Walleij changing board files, etc. 682646b90dSLinus Walleij 692646b90dSLinus Walleij- Pull semantics for legacy device tree (OF) GPIO lookups into 702646b90dSLinus Walleij gpiolib-of.c: in some cases subsystems are doing custom flags and 712646b90dSLinus Walleij lookups for polarity inversion, open drain and what not. As we now 722646b90dSLinus Walleij handle this with generic OF bindings, pull all legacy handling into 732646b90dSLinus Walleij gpiolib so the library API becomes narrow and deep and handle all 742646b90dSLinus Walleij legacy bindings internally. (See e.g. commits 6953c57ab172, 752646b90dSLinus Walleij 6a537d48461d etc) 762646b90dSLinus Walleij 772646b90dSLinus Walleij- Delete <linux/of_gpio.h> when all the above is complete and everything 782646b90dSLinus Walleij uses <linux/gpio/consumer.h> or <linux/gpio/driver.h> instead. 792646b90dSLinus Walleij 805ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 812646b90dSLinus Walleij 82a99cc668SArnd BergmannGet rid of <linux/gpio/legacy-of-mm-gpiochip.h> 83a99cc668SArnd Bergmann 84a99cc668SArnd BergmannWork items: 85a99cc668SArnd Bergmann 86a99cc668SArnd Bergmann- Get rid of struct of_mm_gpio_chip altogether: use the generic MMIO 87a99cc668SArnd Bergmann GPIO for all current users (see below). Delete struct of_mm_gpio_chip, 88a99cc668SArnd Bergmann to_of_mm_gpio_chip(), of_mm_gpiochip_add_data(), of_mm_gpiochip_remove(), 89a99cc668SArnd Bergmann CONFIG_OF_GPIO_MM_GPIOCHIP from the kernel. 90a99cc668SArnd Bergmann 915ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 92a99cc668SArnd Bergmann 932646b90dSLinus WalleijCollect drivers 942646b90dSLinus Walleij 952646b90dSLinus WalleijCollect GPIO drivers from arch/* and other places that should be placed 962646b90dSLinus Walleijin drivers/gpio/gpio-*. Augment platforms to create platform devices or 972646b90dSLinus Walleijsimilar and probe a proper driver in the gpiolib subsystem. 982646b90dSLinus Walleij 992646b90dSLinus WalleijIn some cases it makes sense to create a GPIO chip from the local driver 1002646b90dSLinus Walleijfor a few GPIOs. Those should stay where they are. 1012646b90dSLinus Walleij 10285a94ff8SAndy ShevchenkoAt the same time it makes sense to get rid of code duplication in existing or 10385a94ff8SAndy Shevchenkonew coming drivers. For example, gpio-ml-ioh should be incorporated into 1045f7582aaSAndy Shevchenkogpio-pch. 10585a94ff8SAndy Shevchenko 1065ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 1072646b90dSLinus Walleij 1082646b90dSLinus WalleijGeneric MMIO GPIO 1092646b90dSLinus Walleij 1102646b90dSLinus WalleijThe GPIO drivers can utilize the generic MMIO helper library in many 1112646b90dSLinus Walleijcases, and the helper library should be as helpful as possible for MMIO 1122646b90dSLinus Walleijdrivers. (drivers/gpio/gpio-mmio.c) 1132646b90dSLinus Walleij 1142646b90dSLinus WalleijWork items: 1152646b90dSLinus Walleij 1162646b90dSLinus Walleij- Look over and identify any remaining easily converted drivers and 1172646b90dSLinus Walleij dry-code conversions to MMIO GPIO for maintainers to test 1182646b90dSLinus Walleij 11941c4616bSLinus Walleij- Expand the MMIO GPIO or write a new library for regmap-based I/O 12041c4616bSLinus Walleij helpers for GPIO drivers on regmap that simply use offsets 12141c4616bSLinus Walleij 0..n in some register to drive GPIO lines 12241c4616bSLinus Walleij 1232646b90dSLinus Walleij- Expand the MMIO GPIO or write a new library for port-mapped I/O 1242646b90dSLinus Walleij helpers (x86 inb()/outb()) and convert port-mapped I/O drivers to use 1252646b90dSLinus Walleij this with dry-coding and sending to maintainers to test 1262646b90dSLinus Walleij 1275ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 1282646b90dSLinus Walleij 129c8a51f03SAndy ShevchenkoGeneric regmap GPIO 130c8a51f03SAndy Shevchenko 131c8a51f03SAndy ShevchenkoIn the very similar way to Generic MMIO GPIO convert the users which can 132c8a51f03SAndy Shevchenkotake advantage of using regmap over direct IO accessors. Note, even in 133c8a51f03SAndy ShevchenkoMMIO case the regmap MMIO with gpio-regmap.c is preferable over gpio-mmio.c. 134c8a51f03SAndy Shevchenko 1355ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 136c8a51f03SAndy Shevchenko 1372646b90dSLinus WalleijGPIOLIB irqchip 1382646b90dSLinus Walleij 1392646b90dSLinus WalleijThe GPIOLIB irqchip is a helper irqchip for "simple cases" that should 1402646b90dSLinus Walleijtry to cover any generic kind of irqchip cascaded from a GPIO. 1412646b90dSLinus Walleij 1422646b90dSLinus Walleij- Look over and identify any remaining easily converted drivers and 1432646b90dSLinus Walleij dry-code conversions to gpiolib irqchip for maintainers to test 1442646b90dSLinus Walleij 1455ceb3536SBartosz Golaszewski------------------------------------------------------------------------------- 1462646b90dSLinus Walleij 147afefc326SMarc ZyngierMoving over to immutable irq_chip structures 148afefc326SMarc Zyngier 149afefc326SMarc ZyngierMost of the gpio chips implementing interrupt support rely on gpiolib 150afefc326SMarc Zyngierintercepting some of the irq_chip callbacks, preventing the structures 151afefc326SMarc Zyngierfrom being made read-only and forcing duplication of structures that 152afefc326SMarc Zyngiershould otherwise be unique. 153afefc326SMarc Zyngier 154afefc326SMarc ZyngierThe solution is to call into the gpiolib code when needed (resource 155afefc326SMarc Zyngiermanagement, enable/disable or unmask/mask callbacks), and to let the 156afefc326SMarc Zyngiercore code know about that by exposing a flag (IRQCHIP_IMMUTABLE) in 157afefc326SMarc Zyngierthe irq_chip structure. The irq_chip structure can then be made unique 158afefc326SMarc Zyngierand const. 159afefc326SMarc Zyngier 160afefc326SMarc ZyngierA small number of drivers have been converted (pl061, tegra186, msm, 161afefc326SMarc Zyngieramd, apple), and can be used as examples of how to proceed with this 162afefc326SMarc Zyngierconversion. Note that drivers using the generic irqchip framework 163afefc326SMarc Zyngiercannot be converted yet, but watch this space! 1649ff2443bSBartosz Golaszewski 1659ff2443bSBartosz Golaszewski------------------------------------------------------------------------------- 1669ff2443bSBartosz Golaszewski 1679ff2443bSBartosz GolaszewskiConvert all GPIO chips to using the new, value returning line setters 1689ff2443bSBartosz Golaszewski 1699ff2443bSBartosz Golaszewskistruct gpio_chip's set() and set_multiple() callbacks are now deprecated. They 1709ff2443bSBartosz Golaszewskireturn void and thus do not allow drivers to indicate failure to set the line 1719ff2443bSBartosz Golaszewskivalue back to the caller. 1729ff2443bSBartosz Golaszewski 1739ff2443bSBartosz GolaszewskiWe've now added new variants - set_rv() and set_multiple_rv() that return an 1749ff2443bSBartosz Golaszewskiinteger. Let's convert all GPIO drivers treewide to use the new callbacks, 1759ff2443bSBartosz Golaszewskiremove the old ones and finally rename the new ones back to the old names. 176*af54a2fbSBartosz Golaszewski 177*af54a2fbSBartosz Golaszewski------------------------------------------------------------------------------- 178*af54a2fbSBartosz Golaszewski 179*af54a2fbSBartosz GolaszewskiExtend the sysfs ABI to allow exporting lines by their HW offsets 180*af54a2fbSBartosz Golaszewski 181*af54a2fbSBartosz GolaszewskiThe need to support the sysfs GPIO class is one of the main obstacles to 182*af54a2fbSBartosz Golaszewskiremoving the global GPIO numberspace from the kernel. In order to wean users 183*af54a2fbSBartosz Golaszewskioff using global numbers from user-space, extend the existing interface with 184*af54a2fbSBartosz Golaszewskinew per-gpiochip export/unexport attributes that allow to refer to GPIOs using 185*af54a2fbSBartosz Golaszewskitheir hardware offsets within the chip. 186*af54a2fbSBartosz Golaszewski 187*af54a2fbSBartosz GolaszewskiEncourage users to switch to using them and eventually remove the existing 188*af54a2fbSBartosz Golaszewskiglobal export/unexport attribues. 189