gpio.txt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. Specifying GPIO information for devices
  2. ============================================
  3. 1) gpios property
  4. -----------------
  5. Nodes that makes use of GPIOs should specify them using one or more
  6. properties, each containing a 'gpio-list':
  7. gpio-list ::= <single-gpio> [gpio-list]
  8. single-gpio ::= <gpio-phandle> <gpio-specifier>
  9. gpio-phandle : phandle to gpio controller node
  10. gpio-specifier : Array of #gpio-cells specifying specific gpio
  11. (controller specific)
  12. GPIO properties should be named "[<name>-]gpios". Exact
  13. meaning of each gpios property must be documented in the device tree
  14. binding for each device.
  15. For example, the following could be used to describe gpios pins to use
  16. as chip select lines; with chip selects 0, 1 and 3 populated, and chip
  17. select 2 left empty:
  18. gpio1: gpio1 {
  19. gpio-controller
  20. #gpio-cells = <2>;
  21. };
  22. gpio2: gpio2 {
  23. gpio-controller
  24. #gpio-cells = <1>;
  25. };
  26. [...]
  27. chipsel-gpios = <&gpio1 12 0>,
  28. <&gpio1 13 0>,
  29. <0>, /* holes are permitted, means no GPIO 2 */
  30. <&gpio2 2>;
  31. Note that gpio-specifier length is controller dependent. In the
  32. above example, &gpio1 uses 2 cells to specify a gpio, while &gpio2
  33. only uses one.
  34. gpio-specifier may encode: bank, pin position inside the bank,
  35. whether pin is open-drain and whether pin is logically inverted.
  36. Exact meaning of each specifier cell is controller specific, and must
  37. be documented in the device tree binding for the device.
  38. Example of the node using GPIOs:
  39. node {
  40. gpios = <&qe_pio_e 18 0>;
  41. };
  42. In this example gpio-specifier is "18 0" and encodes GPIO pin number,
  43. and empty GPIO flags as accepted by the "qe_pio_e" gpio-controller.
  44. 2) gpio-controller nodes
  45. ------------------------
  46. Every GPIO controller node must both an empty "gpio-controller"
  47. property, and have #gpio-cells contain the size of the gpio-specifier.
  48. Example of two SOC GPIO banks defined as gpio-controller nodes:
  49. qe_pio_a: gpio-controller@1400 {
  50. #gpio-cells = <2>;
  51. compatible = "fsl,qe-pario-bank-a", "fsl,qe-pario-bank";
  52. reg = <0x1400 0x18>;
  53. gpio-controller;
  54. };
  55. qe_pio_e: gpio-controller@1460 {
  56. #gpio-cells = <2>;
  57. compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
  58. reg = <0x1460 0x18>;
  59. gpio-controller;
  60. };
  61. 2.1) gpio-controller and pinctrl subsystem
  62. ------------------------------------------
  63. gpio-controller on a SOC might be tightly coupled with the pinctrl
  64. subsystem, in the sense that the pins can be used by other functions
  65. together with optional gpio feature.
  66. While the pin allocation is totally managed by the pin ctrl subsystem,
  67. gpio (under gpiolib) is still maintained by gpio drivers. It may happen
  68. that different pin ranges in a SoC is managed by different gpio drivers.
  69. This makes it logical to let gpio drivers announce their pin ranges to
  70. the pin ctrl subsystem and call 'pinctrl_request_gpio' in order to
  71. request the corresponding pin before any gpio usage.
  72. For this, the gpio controller can use a pinctrl phandle and pins to
  73. announce the pinrange to the pin ctrl subsystem. For example,
  74. qe_pio_e: gpio-controller@1460 {
  75. #gpio-cells = <2>;
  76. compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
  77. reg = <0x1460 0x18>;
  78. gpio-controller;
  79. gpio-ranges = <&pinctrl1 20 10>, <&pinctrl2 50 20>;
  80. }
  81. where,
  82. &pinctrl1 and &pinctrl2 is the phandle to the pinctrl DT node.
  83. Next values specify the base pin and number of pins for the range
  84. handled by 'qe_pio_e' gpio. In the given example from base pin 20 to
  85. pin 29 under pinctrl1 and pin 50 to pin 69 under pinctrl2 is handled
  86. by this gpio controller.
  87. The pinctrl node must have "#gpio-range-cells" property to show number of
  88. arguments to pass with phandle from gpio controllers node.