162306a36Sopenharmony_ciThis is a place for planning the ongoing long-term work in the GPIO 262306a36Sopenharmony_cisubsystem. 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci 562306a36Sopenharmony_ciGPIO descriptors 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciStarting with commit 79a9becda894 the GPIO subsystem embarked on a journey 862306a36Sopenharmony_cito move away from the global GPIO numberspace and toward a descriptor-based 962306a36Sopenharmony_ciapproach. This means that GPIO consumers, drivers and machine descriptions 1062306a36Sopenharmony_ciideally have no use or idea of the global GPIO numberspace that has/was 1162306a36Sopenharmony_ciused in the inception of the GPIO subsystem. 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciThe numberspace issue is the same as to why irq is moving away from irq 1462306a36Sopenharmony_cinumbers to IRQ descriptors. 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ciThe underlying motivation for this is that the GPIO numberspace has become 1762306a36Sopenharmony_ciunmanageable: machine board files tend to become full of macros trying to 1862306a36Sopenharmony_ciestablish the numberspace at compile-time, making it hard to add any numbers 1962306a36Sopenharmony_ciin the middle (such as if you missed a pin on a chip) without the numberspace 2062306a36Sopenharmony_cibreaking. 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciMachine descriptions such as device tree or ACPI does not have a concept of the 2362306a36Sopenharmony_ciLinux GPIO number as those descriptions are external to the Linux kernel 2462306a36Sopenharmony_ciand treat GPIO lines as abstract entities. 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciThe runtime-assigned GPIO numberspace (what you get if you assign the GPIO 2762306a36Sopenharmony_cibase as -1 in struct gpio_chip) has also became unpredictable due to factors 2862306a36Sopenharmony_cisuch as probe ordering and the introduction of -EPROBE_DEFER making probe 2962306a36Sopenharmony_ciordering of independent GPIO chips essentially unpredictable, as their base 3062306a36Sopenharmony_cinumber will be assigned on a first come first serve basis. 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ciThe best way to get out of the problem is to make the global GPIO numbers 3362306a36Sopenharmony_ciunimportant by simply not using them. GPIO descriptors deal with this. 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciWork items: 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci- Convert all GPIO device drivers to only #include <linux/gpio/driver.h> 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci- Convert all consumer drivers to only #include <linux/gpio/consumer.h> 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci- Convert all machine descriptors in "boardfiles" to only 4262306a36Sopenharmony_ci #include <linux/gpio/machine.h>, the other option being to convert it 4362306a36Sopenharmony_ci to a machine description such as device tree, ACPI or fwnode that 4462306a36Sopenharmony_ci implicitly does not use global GPIO numbers. 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci- When this work is complete (will require some of the items in the 4762306a36Sopenharmony_ci following ongoing work as well) we can delete the old global 4862306a36Sopenharmony_ci numberspace accessors from <linux/gpio.h> and eventually delete 4962306a36Sopenharmony_ci <linux/gpio.h> altogether. 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ciGet rid of <linux/of_gpio.h> 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ciThis header and helpers appeared at one point when there was no proper 5562306a36Sopenharmony_cidriver infrastructure for doing simpler MMIO GPIO devices and there was 5662306a36Sopenharmony_cino core support for parsing device tree GPIOs from the core library with 5762306a36Sopenharmony_cithe [devm_]gpiod_get() calls we have today that will implicitly go into 5862306a36Sopenharmony_cithe device tree back-end. It is legacy and should not be used in new code. 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ciWork items: 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci- Change all consumer drivers that #include <linux/of_gpio.h> to 6362306a36Sopenharmony_ci #include <linux/gpio/consumer.h> and stop doing custom parsing of the 6462306a36Sopenharmony_ci GPIO lines from the device tree. This can be tricky and often ivolves 6562306a36Sopenharmony_ci changing boardfiles, etc. 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci- Pull semantics for legacy device tree (OF) GPIO lookups into 6862306a36Sopenharmony_ci gpiolib-of.c: in some cases subsystems are doing custom flags and 6962306a36Sopenharmony_ci lookups for polarity inversion, open drain and what not. As we now 7062306a36Sopenharmony_ci handle this with generic OF bindings, pull all legacy handling into 7162306a36Sopenharmony_ci gpiolib so the library API becomes narrow and deep and handle all 7262306a36Sopenharmony_ci legacy bindings internally. (See e.g. commits 6953c57ab172, 7362306a36Sopenharmony_ci 6a537d48461d etc) 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci- Delete <linux/of_gpio.h> when all the above is complete and everything 7662306a36Sopenharmony_ci uses <linux/gpio/consumer.h> or <linux/gpio/driver.h> instead. 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ciGet rid of <linux/gpio/legacy-of-mm-gpiochip.h> 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ciWork items: 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci- Get rid of struct of_mm_gpio_chip altogether: use the generic MMIO 8462306a36Sopenharmony_ci GPIO for all current users (see below). Delete struct of_mm_gpio_chip, 8562306a36Sopenharmony_ci to_of_mm_gpio_chip(), of_mm_gpiochip_add_data(), of_mm_gpiochip_remove(), 8662306a36Sopenharmony_ci CONFIG_OF_GPIO_MM_GPIOCHIP from the kernel. 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciGet rid of <linux/gpio.h> 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ciThis legacy header is a one stop shop for anything GPIO is closely tied 9262306a36Sopenharmony_cito the global GPIO numberspace. The endgame of the above refactorings will 9362306a36Sopenharmony_cibe the removal of <linux/gpio.h> and from that point only the specialized 9462306a36Sopenharmony_ciheaders under <linux/gpio/*.h> will be used. This requires all the above to 9562306a36Sopenharmony_cibe completed and is expected to take a long time. 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ciCollect drivers 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ciCollect GPIO drivers from arch/* and other places that should be placed 10162306a36Sopenharmony_ciin drivers/gpio/gpio-*. Augment platforms to create platform devices or 10262306a36Sopenharmony_cisimilar and probe a proper driver in the gpiolib subsystem. 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ciIn some cases it makes sense to create a GPIO chip from the local driver 10562306a36Sopenharmony_cifor a few GPIOs. Those should stay where they are. 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ciAt the same time it makes sense to get rid of code duplication in existing or 10862306a36Sopenharmony_cinew coming drivers. For example, gpio-ml-ioh should be incorporated into 10962306a36Sopenharmony_cigpio-pch. 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ciGeneric MMIO GPIO 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ciThe GPIO drivers can utilize the generic MMIO helper library in many 11562306a36Sopenharmony_cicases, and the helper library should be as helpful as possible for MMIO 11662306a36Sopenharmony_cidrivers. (drivers/gpio/gpio-mmio.c) 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ciWork items: 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci- Look over and identify any remaining easily converted drivers and 12162306a36Sopenharmony_ci dry-code conversions to MMIO GPIO for maintainers to test 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci- Expand the MMIO GPIO or write a new library for regmap-based I/O 12462306a36Sopenharmony_ci helpers for GPIO drivers on regmap that simply use offsets 12562306a36Sopenharmony_ci 0..n in some register to drive GPIO lines 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci- Expand the MMIO GPIO or write a new library for port-mapped I/O 12862306a36Sopenharmony_ci helpers (x86 inb()/outb()) and convert port-mapped I/O drivers to use 12962306a36Sopenharmony_ci this with dry-coding and sending to maintainers to test 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ciGeneric regmap GPIO 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ciIn the very similar way to Generic MMIO GPIO convert the users which can 13562306a36Sopenharmony_citake advantage of using regmap over direct IO accessors. Note, even in 13662306a36Sopenharmony_ciMMIO case the regmap MMIO with gpio-regmap.c is preferable over gpio-mmio.c. 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ciGPIOLIB irqchip 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ciThe GPIOLIB irqchip is a helper irqchip for "simple cases" that should 14262306a36Sopenharmony_citry to cover any generic kind of irqchip cascaded from a GPIO. 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci- Look over and identify any remaining easily converted drivers and 14562306a36Sopenharmony_ci dry-code conversions to gpiolib irqchip for maintainers to test 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ciIncrease integration with pin control 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ciThere are already ways to use pin control as back-end for GPIO and 15162306a36Sopenharmony_ciit may make sense to bring these subsystems closer. One reason for 15262306a36Sopenharmony_cicreating pin control as its own subsystem was that we could avoid any 15362306a36Sopenharmony_ciuse of the global GPIO numbers. Once the above is complete, it may 15462306a36Sopenharmony_cimake sense to simply join the subsystems into one and make pin 15562306a36Sopenharmony_cimultiplexing, pin configuration, GPIO, etc selectable options in one 15662306a36Sopenharmony_ciand the same pin control and GPIO subsystem. 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ciDebugfs in place of sysfs 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ciThe old sysfs code that enables simple uses of GPIOs from the 16262306a36Sopenharmony_cicommand line is still popular despite the existance of the proper 16362306a36Sopenharmony_cicharacter device. The reason is that it is simple to use on 16462306a36Sopenharmony_ciroot filesystems where you only have a minimal set of tools such 16562306a36Sopenharmony_cias "cat", "echo" etc. 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ciThe old sysfs still need to be strongly deprecated and removed 16862306a36Sopenharmony_cias it relies on the global GPIO numberspace that assume a strict 16962306a36Sopenharmony_ciorder of global GPIO numbers that do not change between boots 17062306a36Sopenharmony_ciand is independent of probe order. 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ciTo solve this and provide an ABI that people can use for hacks 17362306a36Sopenharmony_ciand development, implement a debugfs interface to manipulate 17462306a36Sopenharmony_ciGPIO lines that can do everything that sysfs can do today: one 17562306a36Sopenharmony_cidirectory per gpiochip and one file entry per line: 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci/sys/kernel/debug/gpiochip/gpiochip0 17862306a36Sopenharmony_ci/sys/kernel/debug/gpiochip/gpiochip0/gpio0 17962306a36Sopenharmony_ci/sys/kernel/debug/gpiochip/gpiochip0/gpio1 18062306a36Sopenharmony_ci/sys/kernel/debug/gpiochip/gpiochip0/gpio2 18162306a36Sopenharmony_ci/sys/kernel/debug/gpiochip/gpiochip0/gpio3 18262306a36Sopenharmony_ci... 18362306a36Sopenharmony_ci/sys/kernel/debug/gpiochip/gpiochip1 18462306a36Sopenharmony_ci/sys/kernel/debug/gpiochip/gpiochip1/gpio0 18562306a36Sopenharmony_ci/sys/kernel/debug/gpiochip/gpiochip1/gpio1 18662306a36Sopenharmony_ci... 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ciThe exact files and design of the debugfs interface can be 18962306a36Sopenharmony_cidiscussed but the idea is to provide a low-level access point 19062306a36Sopenharmony_cifor debugging and hacking and to expose all lines without the 19162306a36Sopenharmony_cineed of any exporting. Also provide ample ammunition to shoot 19262306a36Sopenharmony_cioneself in the foot, because this is debugfs after all. 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ciMoving over to immutable irq_chip structures 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ciMost of the gpio chips implementing interrupt support rely on gpiolib 19862306a36Sopenharmony_ciintercepting some of the irq_chip callbacks, preventing the structures 19962306a36Sopenharmony_cifrom being made read-only and forcing duplication of structures that 20062306a36Sopenharmony_cishould otherwise be unique. 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_ciThe solution is to call into the gpiolib code when needed (resource 20362306a36Sopenharmony_cimanagement, enable/disable or unmask/mask callbacks), and to let the 20462306a36Sopenharmony_cicore code know about that by exposing a flag (IRQCHIP_IMMUTABLE) in 20562306a36Sopenharmony_cithe irq_chip structure. The irq_chip structure can then be made unique 20662306a36Sopenharmony_ciand const. 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ciA small number of drivers have been converted (pl061, tegra186, msm, 20962306a36Sopenharmony_ciamd, apple), and can be used as examples of how to proceed with this 21062306a36Sopenharmony_ciconversion. Note that drivers using the generic irqchip framework 21162306a36Sopenharmony_cicannot be converted yet, but watch this space! 212