1This is a place for planning the ongoing long-term work in the GPIO 2subsystem. 3 4 5GPIO descriptors 6 7Starting with commit 79a9becda894 the GPIO subsystem embarked on a journey 8to move away from the global GPIO numberspace and toward a descriptor-based 9approach. This means that GPIO consumers, drivers and machine descriptions 10ideally have no use or idea of the global GPIO numberspace that has/was 11used in the inception of the GPIO subsystem. 12 13The numberspace issue is the same as to why irq is moving away from irq 14numbers to IRQ descriptors. 15 16The underlying motivation for this is that the GPIO numberspace has become 17unmanageable: machine board files tend to become full of macros trying to 18establish the numberspace at compile-time, making it hard to add any numbers 19in the middle (such as if you missed a pin on a chip) without the numberspace 20breaking. 21 22Machine descriptions such as device tree or ACPI does not have a concept of the 23Linux GPIO number as those descriptions are external to the Linux kernel 24and treat GPIO lines as abstract entities. 25 26The runtime-assigned GPIO numberspace (what you get if you assign the GPIO 27base as -1 in struct gpio_chip) has also became unpredictable due to factors 28such as probe ordering and the introduction of -EPROBE_DEFER making probe 29ordering of independent GPIO chips essentially unpredictable, as their base 30number will be assigned on a first come first serve basis. 31 32The best way to get out of the problem is to make the global GPIO numbers 33unimportant by simply not using them. GPIO descriptors deal with this. 34 35Work items: 36 37- Convert all GPIO device drivers to only #include <linux/gpio/driver.h> 38 39- Convert all consumer drivers to only #include <linux/gpio/consumer.h> 40 41- Convert all machine descriptors in "boardfiles" to only 42 #include <linux/gpio/machine.h>, the other option being to convert it 43 to a machine description such as device tree, ACPI or fwnode that 44 implicitly does not use global GPIO numbers. 45 46- When this work is complete (will require some of the items in the 47 following ongoing work as well) we can delete the old global 48 numberspace accessors from <linux/gpio.h> and eventually delete 49 <linux/gpio.h> altogether. 50 51 52Get rid of <linux/of_gpio.h> 53 54This header and helpers appeared at one point when there was no proper 55driver infrastructure for doing simpler MMIO GPIO devices and there was 56no core support for parsing device tree GPIOs from the core library with 57the [devm_]gpiod_get() calls we have today that will implicitly go into 58the device tree back-end. It is legacy and should not be used in new code. 59 60Work items: 61 62- Change all consumer drivers that #include <linux/of_gpio.h> to 63 #include <linux/gpio/consumer.h> and stop doing custom parsing of the 64 GPIO lines from the device tree. This can be tricky and often involves 65 changing board files, etc. 66 67- Pull semantics for legacy device tree (OF) GPIO lookups into 68 gpiolib-of.c: in some cases subsystems are doing custom flags and 69 lookups for polarity inversion, open drain and what not. As we now 70 handle this with generic OF bindings, pull all legacy handling into 71 gpiolib so the library API becomes narrow and deep and handle all 72 legacy bindings internally. (See e.g. commits 6953c57ab172, 73 6a537d48461d etc) 74 75- Delete <linux/of_gpio.h> when all the above is complete and everything 76 uses <linux/gpio/consumer.h> or <linux/gpio/driver.h> instead. 77 78 79Get rid of <linux/gpio/legacy-of-mm-gpiochip.h> 80 81Work items: 82 83- Get rid of struct of_mm_gpio_chip altogether: use the generic MMIO 84 GPIO for all current users (see below). Delete struct of_mm_gpio_chip, 85 to_of_mm_gpio_chip(), of_mm_gpiochip_add_data(), of_mm_gpiochip_remove(), 86 CONFIG_OF_GPIO_MM_GPIOCHIP from the kernel. 87 88 89Collect drivers 90 91Collect GPIO drivers from arch/* and other places that should be placed 92in drivers/gpio/gpio-*. Augment platforms to create platform devices or 93similar and probe a proper driver in the gpiolib subsystem. 94 95In some cases it makes sense to create a GPIO chip from the local driver 96for a few GPIOs. Those should stay where they are. 97 98At the same time it makes sense to get rid of code duplication in existing or 99new coming drivers. For example, gpio-ml-ioh should be incorporated into 100gpio-pch. 101 102 103Generic MMIO GPIO 104 105The GPIO drivers can utilize the generic MMIO helper library in many 106cases, and the helper library should be as helpful as possible for MMIO 107drivers. (drivers/gpio/gpio-mmio.c) 108 109Work items: 110 111- Look over and identify any remaining easily converted drivers and 112 dry-code conversions to MMIO GPIO for maintainers to test 113 114- Expand the MMIO GPIO or write a new library for regmap-based I/O 115 helpers for GPIO drivers on regmap that simply use offsets 116 0..n in some register to drive GPIO lines 117 118- Expand the MMIO GPIO or write a new library for port-mapped I/O 119 helpers (x86 inb()/outb()) and convert port-mapped I/O drivers to use 120 this with dry-coding and sending to maintainers to test 121 122 123Generic regmap GPIO 124 125In the very similar way to Generic MMIO GPIO convert the users which can 126take advantage of using regmap over direct IO accessors. Note, even in 127MMIO case the regmap MMIO with gpio-regmap.c is preferable over gpio-mmio.c. 128 129 130GPIOLIB irqchip 131 132The GPIOLIB irqchip is a helper irqchip for "simple cases" that should 133try to cover any generic kind of irqchip cascaded from a GPIO. 134 135- Look over and identify any remaining easily converted drivers and 136 dry-code conversions to gpiolib irqchip for maintainers to test 137 138 139Increase integration with pin control 140 141There are already ways to use pin control as back-end for GPIO and 142it may make sense to bring these subsystems closer. One reason for 143creating pin control as its own subsystem was that we could avoid any 144use of the global GPIO numbers. Once the above is complete, it may 145make sense to simply join the subsystems into one and make pin 146multiplexing, pin configuration, GPIO, etc selectable options in one 147and the same pin control and GPIO subsystem. 148 149 150Moving over to immutable irq_chip structures 151 152Most of the gpio chips implementing interrupt support rely on gpiolib 153intercepting some of the irq_chip callbacks, preventing the structures 154from being made read-only and forcing duplication of structures that 155should otherwise be unique. 156 157The solution is to call into the gpiolib code when needed (resource 158management, enable/disable or unmask/mask callbacks), and to let the 159core code know about that by exposing a flag (IRQCHIP_IMMUTABLE) in 160the irq_chip structure. The irq_chip structure can then be made unique 161and const. 162 163A small number of drivers have been converted (pl061, tegra186, msm, 164amd, apple), and can be used as examples of how to proceed with this 165conversion. Note that drivers using the generic irqchip framework 166cannot be converted yet, but watch this space! 167