Debian Codegraph @

drivers/gpio/TODO

raw
1 This is a place for planning the ongoing long-term work in the GPIO
2 subsystem.
3
4 ===============================================================================
5
6 GPIO descriptors
7
8 Starting with commit 79a9becda894 the GPIO subsystem embarked on a journey
9 to move away from the global GPIO numberspace and toward a descriptor-based
10 approach. This means that GPIO consumers, drivers and machine descriptions
11 ideally have no use or idea of the global GPIO numberspace that has/was
12 used in the inception of the GPIO subsystem.
13
14 The numberspace issue is the same as to why irq is moving away from irq
15 numbers to IRQ descriptors.
16
17 The underlying motivation for this is that the GPIO numberspace has become
18 unmanageable: machine board files tend to become full of macros trying to
19 establish the numberspace at compile-time, making it hard to add any numbers
20 in the middle (such as if you missed a pin on a chip) without the numberspace
21 breaking.
22
23 Machine descriptions such as device tree or ACPI does not have a concept of the
24 Linux GPIO number as those descriptions are external to the Linux kernel
25 and treat GPIO lines as abstract entities.
26
27 The runtime-assigned GPIO numberspace (what you get if you assign the GPIO
28 base as -1 in struct gpio_chip) has also became unpredictable due to factors
29 such as probe ordering and the introduction of -EPROBE_DEFER making probe
30 ordering of independent GPIO chips essentially unpredictable, as their base
31 number will be assigned on a first come first serve basis.
32
33 The best way to get out of the problem is to make the global GPIO numbers
34 unimportant by simply not using them. GPIO descriptors deal with this.
35
36 Work 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/[email protected]/
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
61 Get rid of <linux/of_gpio.h>
62
63 This header and helpers appeared at one point when there was no proper
64 driver infrastructure for doing simpler MMIO GPIO devices and there was
65 no core support for parsing device tree GPIOs from the core library with
66 the [devm_]gpiod_get() calls we have today that will implicitly go into
67 the device tree back-end. It is legacy and should not be used in new code.
68
69 Work 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
89 Collect drivers
90
91 Collect GPIO drivers from arch/* and other places that should be placed
92 in drivers/gpio/gpio-*. Augment platforms to create platform devices or
93 similar and probe a proper driver in the gpiolib subsystem.
94
95 In some cases it makes sense to create a GPIO chip from the local driver
96 for a few GPIOs. Those should stay where they are.
97
98 At the same time it makes sense to get rid of code duplication in existing or
99 new coming drivers. For example, gpio-ml-ioh should be incorporated into
100 gpio-pch.
101
102 -------------------------------------------------------------------------------
103
104 Generic MMIO GPIO
105
106 The GPIO drivers can utilize the generic MMIO helper library in many
107 cases, and the helper library should be as helpful as possible for MMIO
108 drivers. (drivers/gpio/gpio-mmio.c)
109
110 Work items:
111
112 - Look over and identify any remaining easily converted drivers and
113 dry-code conversions to MMIO GPIO for maintainers to test
114
115 - Expand the MMIO GPIO or write a new library for regmap-based I/O
116 helpers for GPIO drivers on regmap that simply use offsets
117 0..n in some register to drive GPIO lines
118
119 - Expand the MMIO GPIO or write a new library for port-mapped I/O
120 helpers (x86 inb()/outb()) and convert port-mapped I/O drivers to use
121 this with dry-coding and sending to maintainers to test
122
123 -------------------------------------------------------------------------------
124
125 Generic regmap GPIO
126
127 In the very similar way to Generic MMIO GPIO convert the users which can
128 take advantage of using regmap over direct IO accessors. Note, even in
129 MMIO case the regmap MMIO with gpio-regmap.c is preferable over gpio-mmio.c.
130
131 -------------------------------------------------------------------------------
132
133 GPIOLIB irqchip
134
135 The GPIOLIB irqchip is a helper irqchip for "simple cases" that should
136 try to cover any generic kind of irqchip cascaded from a GPIO.
137
138 - Look over and identify any remaining easily converted drivers and
139 dry-code conversions to gpiolib irqchip for maintainers to test
140
141 -------------------------------------------------------------------------------
142
143 Moving over to immutable irq_chip structures
144
145 Most of the gpio chips implementing interrupt support rely on gpiolib
146 intercepting some of the irq_chip callbacks, preventing the structures
147 from being made read-only and forcing duplication of structures that
148 should otherwise be unique.
149
150 The solution is to call into the gpiolib code when needed (resource
151 management, enable/disable or unmask/mask callbacks), and to let the
152 core code know about that by exposing a flag (IRQCHIP_IMMUTABLE) in
153 the irq_chip structure. The irq_chip structure can then be made unique
154 and const.
155
156 A small number of drivers have been converted (pl061, tegra186, msm,
157 amd, apple), and can be used as examples of how to proceed with this
158 conversion. Note that drivers using the generic irqchip framework
159 cannot be converted yet, but watch this space!
160
161 -------------------------------------------------------------------------------
162
163 Remove legacy sysfs features
164
165 We have two parallel per-chip class devices and per-exported-line attribute
166 groups in sysfs. One is using the obsolete global GPIO numberspace and the
167 second relies on hardware offsets of pins within the chip. Remove the former
168 once user-space has switched to using the latter.
169
170 -------------------------------------------------------------------------------
171
172 Remove GPIOD_FLAGS_BIT_NONEXCLUSIVE
173
174 GPIOs in the linux kernel are meant to be an exclusive resource. This means
175 that the GPIO descriptors (the software representation of the hardware concept)
176 are not reference counted and - in general - only one user at a time can
177 request a GPIO line and control its settings. The consumer API is designed
178 around full control of the line's state as evidenced by the fact that, for
179 instance, gpiod_set_value() does indeed drive the line as requested, instead
180 of bumping an enable counter of some sort.
181
182 A problematic use-case for GPIOs is when two consumers want to use the same
183 descriptor independently. An example of such a user is the regulator subsystem
184 which may instantiate several struct regulator_dev instances containing
185 a struct device but using the same enable GPIO line.
186
187 A workaround was introduced in the form of the GPIOD_FLAGS_BIT_NONEXCLUSIVE
188 flag but its implementation is problematic: it does not provide any
189 synchronization of usage nor did it introduce any enable count meaning the
190 non-exclusive users of the same descriptor will in fact "fight" for the
191 control over it. This flag should be removed and replaced with a better
192 solution, possibly based on the new power sequencing subsystem.
193
194 -------------------------------------------------------------------------------
195
196 Remove devm_gpiod_unhinge()
197
198 devm_gpiod_unhinge() is provided as a way to transfer the ownership of managed
199 enable GPIOs to the regulator core. Rather than doing that however, we should
200 make it possible for the regulator subsystem to deal with GPIO resources the
201 lifetime of which it doesn't control as logically, a GPIO obtained by a caller
202 should also be freed by it.