xref: /linux/drivers/gpio/TODO (revision aacc73ceeb8bf664426f0e53db2778a59325bd9f)
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-------------------------------------------------------------------------------
135
136Generic regmap GPIO
137
138In the very similar way to Generic MMIO GPIO convert the users which can
139take advantage of using regmap over direct IO accessors. Note, even in
140MMIO case the regmap MMIO with gpio-regmap.c is preferable over gpio-mmio.c.
141
142-------------------------------------------------------------------------------
143
144GPIOLIB irqchip
145
146The GPIOLIB irqchip is a helper irqchip for "simple cases" that should
147try to cover any generic kind of irqchip cascaded from a GPIO.
148
149- Look over and identify any remaining easily converted drivers and
150  dry-code conversions to gpiolib irqchip for maintainers to test
151
152-------------------------------------------------------------------------------
153
154Moving over to immutable irq_chip structures
155
156Most of the gpio chips implementing interrupt support rely on gpiolib
157intercepting some of the irq_chip callbacks, preventing the structures
158from being made read-only and forcing duplication of structures that
159should otherwise be unique.
160
161The solution is to call into the gpiolib code when needed (resource
162management, enable/disable or unmask/mask callbacks), and to let the
163core code know about that by exposing a flag (IRQCHIP_IMMUTABLE) in
164the irq_chip structure. The irq_chip structure can then be made unique
165and const.
166
167A small number of drivers have been converted (pl061, tegra186, msm,
168amd, apple), and can be used as examples of how to proceed with this
169conversion. Note that drivers using the generic irqchip framework
170cannot be converted yet, but watch this space!
171
172-------------------------------------------------------------------------------
173
174Convert all GPIO chips to using the new, value returning line setters
175
176struct gpio_chip's set() and set_multiple() callbacks are now deprecated. They
177return void and thus do not allow drivers to indicate failure to set the line
178value back to the caller.
179
180We've now added new variants - set_rv() and set_multiple_rv() that return an
181integer. Let's convert all GPIO drivers treewide to use the new callbacks,
182remove the old ones and finally rename the new ones back to the old names.
183
184-------------------------------------------------------------------------------
185
186Extend the sysfs ABI to allow exporting lines by their HW offsets
187
188The need to support the sysfs GPIO class is one of the main obstacles to
189removing the global GPIO numberspace from the kernel. In order to wean users
190off using global numbers from user-space, extend the existing interface with
191new per-gpiochip export/unexport attributes that allow to refer to GPIOs using
192their hardware offsets within the chip.
193
194Encourage users to switch to using them and eventually remove the existing
195global export/unexport attribues.
196
197-------------------------------------------------------------------------------
198
199Remove GPIOD_FLAGS_BIT_NONEXCLUSIVE
200
201GPIOs in the linux kernel are meant to be an exclusive resource. This means
202that the GPIO descriptors (the software representation of the hardware concept)
203are not reference counted and - in general - only one user at a time can
204request a GPIO line and control its settings. The consumer API is designed
205around full control of the line's state as evidenced by the fact that, for
206instance, gpiod_set_value() does indeed drive the line as requested, instead
207of bumping an enable counter of some sort.
208
209A problematic use-case for GPIOs is when two consumers want to use the same
210descriptor independently. An example of such a user is the regulator subsystem
211which may instantiate several struct regulator_dev instances containing
212a struct device but using the same enable GPIO line.
213
214A workaround was introduced in the form of the GPIOD_FLAGS_BIT_NONEXCLUSIVE
215flag but its implementation is problematic: it does not provide any
216synchronization of usage nor did it introduce any enable count meaning the
217non-exclusive users of the same descriptor will in fact "fight" for the
218control over it. This flag should be removed and replaced with a better
219solution, possibly based on the new power sequencing subsystem.
220
221-------------------------------------------------------------------------------
222
223Remove devm_gpiod_unhinge()
224
225devm_gpiod_unhinge() is provided as a way to transfer the ownership of managed
226enable GPIOs to the regulator core. Rather than doing that however, we should
227make it possible for the regulator subsystem to deal with GPIO resources the
228lifetime of which it doesn't control as logically, a GPIO obtained by a caller
229should also be freed by it.
230