xref: /linux/drivers/gpio/TODO (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
1This is a place for planning the ongoing long-term work in the GPIO
2subsystem.
3
4===============================================================================
5
6GPIO descriptors
7
8Starting with commit 79a9becda894 the GPIO subsystem embarked on a journey
9to move away from the global GPIO numberspace and toward a descriptor-based
10approach. This means that GPIO consumers, drivers and machine descriptions
11ideally have no use or idea of the global GPIO numberspace that has/was
12used in the inception of the GPIO subsystem.
13
14The numberspace issue is the same as to why irq is moving away from irq
15numbers to IRQ descriptors.
16
17The underlying motivation for this is that the GPIO numberspace has become
18unmanageable: machine board files tend to become full of macros trying to
19establish the numberspace at compile-time, making it hard to add any numbers
20in the middle (such as if you missed a pin on a chip) without the numberspace
21breaking.
22
23Machine descriptions such as device tree or ACPI does not have a concept of the
24Linux GPIO number as those descriptions are external to the Linux kernel
25and treat GPIO lines as abstract entities.
26
27The runtime-assigned GPIO numberspace (what you get if you assign the GPIO
28base as -1 in struct gpio_chip) has also became unpredictable due to factors
29such as probe ordering and the introduction of -EPROBE_DEFER making probe
30ordering of independent GPIO chips essentially unpredictable, as their base
31number will be assigned on a first come first serve basis.
32
33The best way to get out of the problem is to make the global GPIO numbers
34unimportant by simply not using them. GPIO descriptors deal with this.
35
36Work items:
37
38- Convert all GPIO device drivers to only #include <linux/gpio/driver.h>
39
40- Convert all consumer drivers to only #include <linux/gpio/consumer.h>
41
42- Convert all machine descriptors in "boardfiles" to only
43  #include <linux/gpio/machine.h>, the other option being to convert it
44  to a machine description such as device tree, ACPI or fwnode that
45  implicitly does not use global GPIO numbers.
46
47- Fix drivers to not read back struct gpio_chip::base. Some drivers do
48  that and would be broken by attempts to poison it or make it dynamic.
49  Example in AT91 pinctrl driver:
50  https://lore.kernel.org/all/1d00c056-3d61-4c22-bedd-3bae0bf1ddc4@pengutronix.de/
51  This particular driver is also DT-only, so with the above fixed, the
52  base can be made dynamic (set to -1) if CONFIG_GPIO_SYSFS is disabled.
53
54- When this work is complete (will require some of the items in the
55  following ongoing work as well) we can delete the old global
56  numberspace accessors from <linux/gpio.h> and eventually delete
57  <linux/gpio.h> altogether.
58
59-------------------------------------------------------------------------------
60
61Get rid of <linux/of_gpio.h>
62
63This header and helpers appeared at one point when there was no proper
64driver infrastructure for doing simpler MMIO GPIO devices and there was
65no core support for parsing device tree GPIOs from the core library with
66the [devm_]gpiod_get() calls we have today that will implicitly go into
67the device tree back-end. It is legacy and should not be used in new code.
68
69Work items:
70
71- Change all consumer drivers that #include <linux/of_gpio.h> to
72  #include <linux/gpio/consumer.h> and stop doing custom parsing of the
73  GPIO lines from the device tree. This can be tricky and often involves
74  changing board files, etc.
75
76- Pull semantics for legacy device tree (OF) GPIO lookups into
77  gpiolib-of.c: in some cases subsystems are doing custom flags and
78  lookups for polarity inversion, open drain and what not. As we now
79  handle this with generic OF bindings, pull all legacy handling into
80  gpiolib so the library API becomes narrow and deep and handle all
81  legacy bindings internally. (See e.g. commits 6953c57ab172,
82  6a537d48461d etc)
83
84- Delete <linux/of_gpio.h> when all the above is complete and everything
85  uses <linux/gpio/consumer.h> or <linux/gpio/driver.h> instead.
86
87-------------------------------------------------------------------------------
88
89Get rid of <linux/gpio/legacy-of-mm-gpiochip.h>
90
91Work items:
92
93- Get rid of struct of_mm_gpio_chip altogether: use the generic  MMIO
94  GPIO for all current users (see below). Delete struct of_mm_gpio_chip,
95  to_of_mm_gpio_chip(), of_mm_gpiochip_add_data(), of_mm_gpiochip_remove(),
96  CONFIG_OF_GPIO_MM_GPIOCHIP from the kernel.
97
98-------------------------------------------------------------------------------
99
100Collect drivers
101
102Collect GPIO drivers from arch/* and other places that should be placed
103in drivers/gpio/gpio-*. Augment platforms to create platform devices or
104similar and probe a proper driver in the gpiolib subsystem.
105
106In some cases it makes sense to create a GPIO chip from the local driver
107for a few GPIOs. Those should stay where they are.
108
109At the same time it makes sense to get rid of code duplication in existing or
110new coming drivers. For example, gpio-ml-ioh should be incorporated into
111gpio-pch.
112
113-------------------------------------------------------------------------------
114
115Generic MMIO GPIO
116
117The GPIO drivers can utilize the generic MMIO helper library in many
118cases, and the helper library should be as helpful as possible for MMIO
119drivers. (drivers/gpio/gpio-mmio.c)
120
121Work items:
122
123- Look over and identify any remaining easily converted drivers and
124  dry-code conversions to MMIO GPIO for maintainers to test
125
126- Expand the MMIO GPIO or write a new library for regmap-based I/O
127  helpers for GPIO drivers on regmap that simply use offsets
128  0..n in some register to drive GPIO lines
129
130- Expand the MMIO GPIO or write a new library for port-mapped I/O
131  helpers (x86 inb()/outb()) and convert port-mapped I/O drivers to use
132  this with dry-coding and sending to maintainers to test
133
134- Move the MMIO GPIO specific fields out of struct gpio_chip into a
135  dedicated structure. Currently every GPIO chip has them if gpio-mmio is
136  enabled in Kconfig even if it itself doesn't register with the helper
137  library.
138
139-------------------------------------------------------------------------------
140
141Generic regmap GPIO
142
143In the very similar way to Generic MMIO GPIO convert the users which can
144take advantage of using regmap over direct IO accessors. Note, even in
145MMIO case the regmap MMIO with gpio-regmap.c is preferable over gpio-mmio.c.
146
147-------------------------------------------------------------------------------
148
149GPIOLIB irqchip
150
151The GPIOLIB irqchip is a helper irqchip for "simple cases" that should
152try to cover any generic kind of irqchip cascaded from a GPIO.
153
154- Look over and identify any remaining easily converted drivers and
155  dry-code conversions to gpiolib irqchip for maintainers to test
156
157-------------------------------------------------------------------------------
158
159Moving over to immutable irq_chip structures
160
161Most of the gpio chips implementing interrupt support rely on gpiolib
162intercepting some of the irq_chip callbacks, preventing the structures
163from being made read-only and forcing duplication of structures that
164should otherwise be unique.
165
166The solution is to call into the gpiolib code when needed (resource
167management, enable/disable or unmask/mask callbacks), and to let the
168core code know about that by exposing a flag (IRQCHIP_IMMUTABLE) in
169the irq_chip structure. The irq_chip structure can then be made unique
170and const.
171
172A small number of drivers have been converted (pl061, tegra186, msm,
173amd, apple), and can be used as examples of how to proceed with this
174conversion. Note that drivers using the generic irqchip framework
175cannot be converted yet, but watch this space!
176
177-------------------------------------------------------------------------------
178
179Convert all GPIO chips to using the new, value returning line setters
180
181struct gpio_chip's set() and set_multiple() callbacks are now deprecated. They
182return void and thus do not allow drivers to indicate failure to set the line
183value back to the caller.
184
185We've now added new variants - set_rv() and set_multiple_rv() that return an
186integer. Let's convert all GPIO drivers treewide to use the new callbacks,
187remove the old ones and finally rename the new ones back to the old names.
188
189-------------------------------------------------------------------------------
190
191Remove legacy sysfs features
192
193We have two parallel per-chip class devices and per-exported-line attribute
194groups in sysfs. One is using the obsolete global GPIO numberspace and the
195second relies on hardware offsets of pins within the chip. Remove the former
196once user-space has switched to using the latter.
197
198-------------------------------------------------------------------------------
199
200Remove GPIOD_FLAGS_BIT_NONEXCLUSIVE
201
202GPIOs in the linux kernel are meant to be an exclusive resource. This means
203that the GPIO descriptors (the software representation of the hardware concept)
204are not reference counted and - in general - only one user at a time can
205request a GPIO line and control its settings. The consumer API is designed
206around full control of the line's state as evidenced by the fact that, for
207instance, gpiod_set_value() does indeed drive the line as requested, instead
208of bumping an enable counter of some sort.
209
210A problematic use-case for GPIOs is when two consumers want to use the same
211descriptor independently. An example of such a user is the regulator subsystem
212which may instantiate several struct regulator_dev instances containing
213a struct device but using the same enable GPIO line.
214
215A workaround was introduced in the form of the GPIOD_FLAGS_BIT_NONEXCLUSIVE
216flag but its implementation is problematic: it does not provide any
217synchronization of usage nor did it introduce any enable count meaning the
218non-exclusive users of the same descriptor will in fact "fight" for the
219control over it. This flag should be removed and replaced with a better
220solution, possibly based on the new power sequencing subsystem.
221
222-------------------------------------------------------------------------------
223
224Remove devm_gpiod_unhinge()
225
226devm_gpiod_unhinge() is provided as a way to transfer the ownership of managed
227enable GPIOs to the regulator core. Rather than doing that however, we should
228make it possible for the regulator subsystem to deal with GPIO resources the
229lifetime of which it doesn't control as logically, a GPIO obtained by a caller
230should also be freed by it.
231