TODO 8.1 KB

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