xref: /linux/drivers/gpio/TODO (revision 97a7ea2b8f4a9aec1f43435658343e046c2a4983)
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
134*97a7ea2bSBartosz Golaszewski- Move the MMIO GPIO specific fields out of struct gpio_chip into a
135*97a7ea2bSBartosz Golaszewski  dedicated structure. Currently every GPIO chip has them if gpio-mmio is
136*97a7ea2bSBartosz Golaszewski  enabled in Kconfig even if it itself doesn't register with the helper
137*97a7ea2bSBartosz Golaszewski  library.
138*97a7ea2bSBartosz Golaszewski
1395ceb3536SBartosz Golaszewski-------------------------------------------------------------------------------
1402646b90dSLinus Walleij
141c8a51f03SAndy ShevchenkoGeneric regmap GPIO
142c8a51f03SAndy Shevchenko
143c8a51f03SAndy ShevchenkoIn the very similar way to Generic MMIO GPIO convert the users which can
144c8a51f03SAndy Shevchenkotake advantage of using regmap over direct IO accessors. Note, even in
145c8a51f03SAndy ShevchenkoMMIO case the regmap MMIO with gpio-regmap.c is preferable over gpio-mmio.c.
146c8a51f03SAndy Shevchenko
1475ceb3536SBartosz Golaszewski-------------------------------------------------------------------------------
148c8a51f03SAndy Shevchenko
1492646b90dSLinus WalleijGPIOLIB irqchip
1502646b90dSLinus Walleij
1512646b90dSLinus WalleijThe GPIOLIB irqchip is a helper irqchip for "simple cases" that should
1522646b90dSLinus Walleijtry to cover any generic kind of irqchip cascaded from a GPIO.
1532646b90dSLinus Walleij
1542646b90dSLinus Walleij- Look over and identify any remaining easily converted drivers and
1552646b90dSLinus Walleij  dry-code conversions to gpiolib irqchip for maintainers to test
1562646b90dSLinus Walleij
1575ceb3536SBartosz Golaszewski-------------------------------------------------------------------------------
1582646b90dSLinus Walleij
159afefc326SMarc ZyngierMoving over to immutable irq_chip structures
160afefc326SMarc Zyngier
161afefc326SMarc ZyngierMost of the gpio chips implementing interrupt support rely on gpiolib
162afefc326SMarc Zyngierintercepting some of the irq_chip callbacks, preventing the structures
163afefc326SMarc Zyngierfrom being made read-only and forcing duplication of structures that
164afefc326SMarc Zyngiershould otherwise be unique.
165afefc326SMarc Zyngier
166afefc326SMarc ZyngierThe solution is to call into the gpiolib code when needed (resource
167afefc326SMarc Zyngiermanagement, enable/disable or unmask/mask callbacks), and to let the
168afefc326SMarc Zyngiercore code know about that by exposing a flag (IRQCHIP_IMMUTABLE) in
169afefc326SMarc Zyngierthe irq_chip structure. The irq_chip structure can then be made unique
170afefc326SMarc Zyngierand const.
171afefc326SMarc Zyngier
172afefc326SMarc ZyngierA small number of drivers have been converted (pl061, tegra186, msm,
173afefc326SMarc Zyngieramd, apple), and can be used as examples of how to proceed with this
174afefc326SMarc Zyngierconversion. Note that drivers using the generic irqchip framework
175afefc326SMarc Zyngiercannot be converted yet, but watch this space!
1769ff2443bSBartosz Golaszewski
1779ff2443bSBartosz Golaszewski-------------------------------------------------------------------------------
1789ff2443bSBartosz Golaszewski
1799ff2443bSBartosz GolaszewskiConvert all GPIO chips to using the new, value returning line setters
1809ff2443bSBartosz Golaszewski
1819ff2443bSBartosz Golaszewskistruct gpio_chip's set() and set_multiple() callbacks are now deprecated. They
1829ff2443bSBartosz Golaszewskireturn void and thus do not allow drivers to indicate failure to set the line
1839ff2443bSBartosz Golaszewskivalue back to the caller.
1849ff2443bSBartosz Golaszewski
1859ff2443bSBartosz GolaszewskiWe've now added new variants - set_rv() and set_multiple_rv() that return an
1869ff2443bSBartosz Golaszewskiinteger. Let's convert all GPIO drivers treewide to use the new callbacks,
1879ff2443bSBartosz Golaszewskiremove the old ones and finally rename the new ones back to the old names.
188af54a2fbSBartosz Golaszewski
189af54a2fbSBartosz Golaszewski-------------------------------------------------------------------------------
190af54a2fbSBartosz Golaszewski
191af54a2fbSBartosz GolaszewskiExtend the sysfs ABI to allow exporting lines by their HW offsets
192af54a2fbSBartosz Golaszewski
193af54a2fbSBartosz GolaszewskiThe need to support the sysfs GPIO class is one of the main obstacles to
194af54a2fbSBartosz Golaszewskiremoving the global GPIO numberspace from the kernel. In order to wean users
195af54a2fbSBartosz Golaszewskioff using global numbers from user-space, extend the existing interface with
196af54a2fbSBartosz Golaszewskinew per-gpiochip export/unexport attributes that allow to refer to GPIOs using
197af54a2fbSBartosz Golaszewskitheir hardware offsets within the chip.
198af54a2fbSBartosz Golaszewski
199af54a2fbSBartosz GolaszewskiEncourage users to switch to using them and eventually remove the existing
200af54a2fbSBartosz Golaszewskiglobal export/unexport attribues.
2012de1cf17SBartosz Golaszewski
2022de1cf17SBartosz Golaszewski-------------------------------------------------------------------------------
2032de1cf17SBartosz Golaszewski
2042de1cf17SBartosz GolaszewskiRemove GPIOD_FLAGS_BIT_NONEXCLUSIVE
2052de1cf17SBartosz Golaszewski
2062de1cf17SBartosz GolaszewskiGPIOs in the linux kernel are meant to be an exclusive resource. This means
2072de1cf17SBartosz Golaszewskithat the GPIO descriptors (the software representation of the hardware concept)
2082de1cf17SBartosz Golaszewskiare not reference counted and - in general - only one user at a time can
2092de1cf17SBartosz Golaszewskirequest a GPIO line and control its settings. The consumer API is designed
2102de1cf17SBartosz Golaszewskiaround full control of the line's state as evidenced by the fact that, for
2112de1cf17SBartosz Golaszewskiinstance, gpiod_set_value() does indeed drive the line as requested, instead
2122de1cf17SBartosz Golaszewskiof bumping an enable counter of some sort.
2132de1cf17SBartosz Golaszewski
2142de1cf17SBartosz GolaszewskiA problematic use-case for GPIOs is when two consumers want to use the same
2152de1cf17SBartosz Golaszewskidescriptor independently. An example of such a user is the regulator subsystem
2162de1cf17SBartosz Golaszewskiwhich may instantiate several struct regulator_dev instances containing
2172de1cf17SBartosz Golaszewskia struct device but using the same enable GPIO line.
2182de1cf17SBartosz Golaszewski
2192de1cf17SBartosz GolaszewskiA workaround was introduced in the form of the GPIOD_FLAGS_BIT_NONEXCLUSIVE
2202de1cf17SBartosz Golaszewskiflag but its implementation is problematic: it does not provide any
2212de1cf17SBartosz Golaszewskisynchronization of usage nor did it introduce any enable count meaning the
2222de1cf17SBartosz Golaszewskinon-exclusive users of the same descriptor will in fact "fight" for the
2232de1cf17SBartosz Golaszewskicontrol over it. This flag should be removed and replaced with a better
2242de1cf17SBartosz Golaszewskisolution, possibly based on the new power sequencing subsystem.
2252de1cf17SBartosz Golaszewski
2262de1cf17SBartosz Golaszewski-------------------------------------------------------------------------------
2272de1cf17SBartosz Golaszewski
2282de1cf17SBartosz GolaszewskiRemove devm_gpiod_unhinge()
2292de1cf17SBartosz Golaszewski
2302de1cf17SBartosz Golaszewskidevm_gpiod_unhinge() is provided as a way to transfer the ownership of managed
2312de1cf17SBartosz Golaszewskienable GPIOs to the regulator core. Rather than doing that however, we should
2322de1cf17SBartosz Golaszewskimake it possible for the regulator subsystem to deal with GPIO resources the
2332de1cf17SBartosz Golaszewskilifetime of which it doesn't control as logically, a GPIO obtained by a caller
2342de1cf17SBartosz Golaszewskishould also be freed by it.
235