1*4882a593SmuzhiyunThis is a place for planning the ongoing long-term work in the GPIO 2*4882a593Smuzhiyunsubsystem. 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunGPIO descriptors 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunStarting with commit 79a9becda894 the GPIO subsystem embarked on a journey 8*4882a593Smuzhiyunto move away from the global GPIO numberspace and toward a descriptor-based 9*4882a593Smuzhiyunapproach. This means that GPIO consumers, drivers and machine descriptions 10*4882a593Smuzhiyunideally have no use or idea of the global GPIO numberspace that has/was 11*4882a593Smuzhiyunused in the inception of the GPIO subsystem. 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunThe numberspace issue is the same as to why irq is moving away from irq 14*4882a593Smuzhiyunnumbers to IRQ descriptors. 15*4882a593Smuzhiyun 16*4882a593SmuzhiyunThe underlying motivation for this is that the GPIO numberspace has become 17*4882a593Smuzhiyununmanageable: machine board files tend to become full of macros trying to 18*4882a593Smuzhiyunestablish the numberspace at compile-time, making it hard to add any numbers 19*4882a593Smuzhiyunin the middle (such as if you missed a pin on a chip) without the numberspace 20*4882a593Smuzhiyunbreaking. 21*4882a593Smuzhiyun 22*4882a593SmuzhiyunMachine descriptions such as device tree or ACPI does not have a concept of the 23*4882a593SmuzhiyunLinux GPIO number as those descriptions are external to the Linux kernel 24*4882a593Smuzhiyunand treat GPIO lines as abstract entities. 25*4882a593Smuzhiyun 26*4882a593SmuzhiyunThe runtime-assigned GPIO numberspace (what you get if you assign the GPIO 27*4882a593Smuzhiyunbase as -1 in struct gpio_chip) has also became unpredictable due to factors 28*4882a593Smuzhiyunsuch as probe ordering and the introduction of -EPROBE_DEFER making probe 29*4882a593Smuzhiyunordering of independent GPIO chips essentially unpredictable, as their base 30*4882a593Smuzhiyunnumber will be assigned on a first come first serve basis. 31*4882a593Smuzhiyun 32*4882a593SmuzhiyunThe best way to get out of the problem is to make the global GPIO numbers 33*4882a593Smuzhiyununimportant by simply not using them. GPIO descriptors deal with this. 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunWork items: 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun- Convert all GPIO device drivers to only #include <linux/gpio/driver.h> 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun- Convert all consumer drivers to only #include <linux/gpio/consumer.h> 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun- Convert all machine descriptors in "boardfiles" to only 42*4882a593Smuzhiyun #include <linux/gpio/machine.h>, the other option being to convert it 43*4882a593Smuzhiyun to a machine description such as device tree, ACPI or fwnode that 44*4882a593Smuzhiyun implicitly does not use global GPIO numbers. 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun- When this work is complete (will require some of the items in the 47*4882a593Smuzhiyun following ongoing work as well) we can delete the old global 48*4882a593Smuzhiyun numberspace accessors from <linux/gpio.h> and eventually delete 49*4882a593Smuzhiyun <linux/gpio.h> altogether. 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun 52*4882a593SmuzhiyunGet rid of <linux/of_gpio.h> 53*4882a593Smuzhiyun 54*4882a593SmuzhiyunThis header and helpers appeared at one point when there was no proper 55*4882a593Smuzhiyundriver infrastructure for doing simpler MMIO GPIO devices and there was 56*4882a593Smuzhiyunno core support for parsing device tree GPIOs from the core library with 57*4882a593Smuzhiyunthe [devm_]gpiod_get() calls we have today that will implicitly go into 58*4882a593Smuzhiyunthe device tree back-end. It is legacy and should not be used in new code. 59*4882a593Smuzhiyun 60*4882a593SmuzhiyunWork items: 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun- Get rid of struct of_mm_gpio_chip altogether: use the generic MMIO 63*4882a593Smuzhiyun GPIO for all current users (see below). Delete struct of_mm_gpio_chip, 64*4882a593Smuzhiyun to_of_mm_gpio_chip(), of_mm_gpiochip_add_data(), of_mm_gpiochip_add() 65*4882a593Smuzhiyun of_mm_gpiochip_remove() from the kernel. 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun- Change all consumer drivers that #include <linux/of_gpio.h> to 68*4882a593Smuzhiyun #include <linux/gpio/consumer.h> and stop doing custom parsing of the 69*4882a593Smuzhiyun GPIO lines from the device tree. This can be tricky and often ivolves 70*4882a593Smuzhiyun changing boardfiles, etc. 71*4882a593Smuzhiyun 72*4882a593Smuzhiyun- Pull semantics for legacy device tree (OF) GPIO lookups into 73*4882a593Smuzhiyun gpiolib-of.c: in some cases subsystems are doing custom flags and 74*4882a593Smuzhiyun lookups for polarity inversion, open drain and what not. As we now 75*4882a593Smuzhiyun handle this with generic OF bindings, pull all legacy handling into 76*4882a593Smuzhiyun gpiolib so the library API becomes narrow and deep and handle all 77*4882a593Smuzhiyun legacy bindings internally. (See e.g. commits 6953c57ab172, 78*4882a593Smuzhiyun 6a537d48461d etc) 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun- Delete <linux/of_gpio.h> when all the above is complete and everything 81*4882a593Smuzhiyun uses <linux/gpio/consumer.h> or <linux/gpio/driver.h> instead. 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun 84*4882a593SmuzhiyunGet rid of <linux/gpio.h> 85*4882a593Smuzhiyun 86*4882a593SmuzhiyunThis legacy header is a one stop shop for anything GPIO is closely tied 87*4882a593Smuzhiyunto the global GPIO numberspace. The endgame of the above refactorings will 88*4882a593Smuzhiyunbe the removal of <linux/gpio.h> and from that point only the specialized 89*4882a593Smuzhiyunheaders under <linux/gpio/*.h> will be used. This requires all the above to 90*4882a593Smuzhiyunbe completed and is expected to take a long time. 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun 93*4882a593SmuzhiyunCollect drivers 94*4882a593Smuzhiyun 95*4882a593SmuzhiyunCollect GPIO drivers from arch/* and other places that should be placed 96*4882a593Smuzhiyunin drivers/gpio/gpio-*. Augment platforms to create platform devices or 97*4882a593Smuzhiyunsimilar and probe a proper driver in the gpiolib subsystem. 98*4882a593Smuzhiyun 99*4882a593SmuzhiyunIn some cases it makes sense to create a GPIO chip from the local driver 100*4882a593Smuzhiyunfor a few GPIOs. Those should stay where they are. 101*4882a593Smuzhiyun 102*4882a593SmuzhiyunAt the same time it makes sense to get rid of code duplication in existing or 103*4882a593Smuzhiyunnew coming drivers. For example, gpio-ml-ioh should be incorporated into 104*4882a593Smuzhiyungpio-pch. In similar way gpio-intel-mid into gpio-pxa. 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun 107*4882a593SmuzhiyunGeneric MMIO GPIO 108*4882a593Smuzhiyun 109*4882a593SmuzhiyunThe GPIO drivers can utilize the generic MMIO helper library in many 110*4882a593Smuzhiyuncases, and the helper library should be as helpful as possible for MMIO 111*4882a593Smuzhiyundrivers. (drivers/gpio/gpio-mmio.c) 112*4882a593Smuzhiyun 113*4882a593SmuzhiyunWork items: 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun- Look over and identify any remaining easily converted drivers and 116*4882a593Smuzhiyun dry-code conversions to MMIO GPIO for maintainers to test 117*4882a593Smuzhiyun 118*4882a593Smuzhiyun- Expand the MMIO GPIO or write a new library for regmap-based I/O 119*4882a593Smuzhiyun helpers for GPIO drivers on regmap that simply use offsets 120*4882a593Smuzhiyun 0..n in some register to drive GPIO lines 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun- Expand the MMIO GPIO or write a new library for port-mapped I/O 123*4882a593Smuzhiyun helpers (x86 inb()/outb()) and convert port-mapped I/O drivers to use 124*4882a593Smuzhiyun this with dry-coding and sending to maintainers to test 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun 127*4882a593SmuzhiyunGPIOLIB irqchip 128*4882a593Smuzhiyun 129*4882a593SmuzhiyunThe GPIOLIB irqchip is a helper irqchip for "simple cases" that should 130*4882a593Smuzhiyuntry to cover any generic kind of irqchip cascaded from a GPIO. 131*4882a593Smuzhiyun 132*4882a593Smuzhiyun- Convert all the GPIOLIB_IRQCHIP users to pass an irqchip template, 133*4882a593Smuzhiyun parent and flags before calling [devm_]gpiochip_add[_data](). 134*4882a593Smuzhiyun Currently we set up the irqchip after setting up the gpiochip 135*4882a593Smuzhiyun using gpiochip_irqchip_add() and gpiochip_set_[chained|nested]_irqchip(). 136*4882a593Smuzhiyun This is too complex, so convert all users over to just set up 137*4882a593Smuzhiyun the irqchip before registering the gpio_chip, typical example: 138*4882a593Smuzhiyun 139*4882a593Smuzhiyun /* Typical state container with dynamic irqchip */ 140*4882a593Smuzhiyun struct my_gpio { 141*4882a593Smuzhiyun struct gpio_chip gc; 142*4882a593Smuzhiyun struct irq_chip irq; 143*4882a593Smuzhiyun }; 144*4882a593Smuzhiyun 145*4882a593Smuzhiyun int irq; /* from platform etc */ 146*4882a593Smuzhiyun struct my_gpio *g; 147*4882a593Smuzhiyun struct gpio_irq_chip *girq; 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun /* Set up the irqchip dynamically */ 150*4882a593Smuzhiyun g->irq.name = "my_gpio_irq"; 151*4882a593Smuzhiyun g->irq.irq_ack = my_gpio_ack_irq; 152*4882a593Smuzhiyun g->irq.irq_mask = my_gpio_mask_irq; 153*4882a593Smuzhiyun g->irq.irq_unmask = my_gpio_unmask_irq; 154*4882a593Smuzhiyun g->irq.irq_set_type = my_gpio_set_irq_type; 155*4882a593Smuzhiyun 156*4882a593Smuzhiyun /* Get a pointer to the gpio_irq_chip */ 157*4882a593Smuzhiyun girq = &g->gc.irq; 158*4882a593Smuzhiyun girq->chip = &g->irq; 159*4882a593Smuzhiyun girq->parent_handler = ftgpio_gpio_irq_handler; 160*4882a593Smuzhiyun girq->num_parents = 1; 161*4882a593Smuzhiyun girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), 162*4882a593Smuzhiyun GFP_KERNEL); 163*4882a593Smuzhiyun if (!girq->parents) 164*4882a593Smuzhiyun return -ENOMEM; 165*4882a593Smuzhiyun girq->default_type = IRQ_TYPE_NONE; 166*4882a593Smuzhiyun girq->handler = handle_bad_irq; 167*4882a593Smuzhiyun girq->parents[0] = irq; 168*4882a593Smuzhiyun 169*4882a593Smuzhiyun When this is done, we will delete the old APIs for instatiating 170*4882a593Smuzhiyun GPIOLIB_IRQCHIP and simplify the code. 171*4882a593Smuzhiyun 172*4882a593Smuzhiyun- Look over and identify any remaining easily converted drivers and 173*4882a593Smuzhiyun dry-code conversions to gpiolib irqchip for maintainers to test 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun- Drop gpiochip_set_chained_irqchip() when all the chained irqchips 176*4882a593Smuzhiyun have been converted to the above infrastructure. 177*4882a593Smuzhiyun 178*4882a593Smuzhiyun- Add more infrastructure to make it possible to also pass a threaded 179*4882a593Smuzhiyun irqchip in struct gpio_irq_chip. 180*4882a593Smuzhiyun 181*4882a593Smuzhiyun- Drop gpiochip_irqchip_add_nested() when all the chained irqchips 182*4882a593Smuzhiyun have been converted to the above infrastructure. 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun 185*4882a593SmuzhiyunIncrease integration with pin control 186*4882a593Smuzhiyun 187*4882a593SmuzhiyunThere are already ways to use pin control as back-end for GPIO and 188*4882a593Smuzhiyunit may make sense to bring these subsystems closer. One reason for 189*4882a593Smuzhiyuncreating pin control as its own subsystem was that we could avoid any 190*4882a593Smuzhiyunuse of the global GPIO numbers. Once the above is complete, it may 191*4882a593Smuzhiyunmake sense to simply join the subsystems into one and make pin 192*4882a593Smuzhiyunmultiplexing, pin configuration, GPIO, etc selectable options in one 193*4882a593Smuzhiyunand the same pin control and GPIO subsystem. 194