drivers-on-gpio.rst 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ============================
  2. Subsystem drivers using GPIO
  3. ============================
  4. Note that standard kernel drivers exist for common GPIO tasks and will provide
  5. the right in-kernel and userspace APIs/ABIs for the job, and that these
  6. drivers can quite easily interconnect with other kernel subsystems using
  7. hardware descriptions such as device tree or ACPI:
  8. - leds-gpio: drivers/leds/leds-gpio.c will handle LEDs connected to GPIO
  9. lines, giving you the LED sysfs interface
  10. - ledtrig-gpio: drivers/leds/trigger/ledtrig-gpio.c will provide a LED trigger,
  11. i.e. a LED will turn on/off in response to a GPIO line going high or low
  12. (and that LED may in turn use the leds-gpio as per above).
  13. - gpio-keys: drivers/input/keyboard/gpio_keys.c is used when your GPIO line
  14. can generate interrupts in response to a key press. Also supports debounce.
  15. - gpio-keys-polled: drivers/input/keyboard/gpio_keys_polled.c is used when your
  16. GPIO line cannot generate interrupts, so it needs to be periodically polled
  17. by a timer.
  18. - gpio_mouse: drivers/input/mouse/gpio_mouse.c is used to provide a mouse with
  19. up to three buttons by simply using GPIOs and no mouse port. You can cut the
  20. mouse cable and connect the wires to GPIO lines or solder a mouse connector
  21. to the lines for a more permanent solution of this type.
  22. - gpio-beeper: drivers/input/misc/gpio-beeper.c is used to provide a beep from
  23. an external speaker connected to a GPIO line. (If the beep is controlled by
  24. off/on, for an actual PWM waveform, see pwm-gpio below.)
  25. - pwm-gpio: drivers/pwm/pwm-gpio.c is used to toggle a GPIO with a high
  26. resolution timer producing a PWM waveform on the GPIO line, as well as
  27. Linux high resolution timers can do.
  28. - extcon-gpio: drivers/extcon/extcon-gpio.c is used when you need to read an
  29. external connector status, such as a headset line for an audio driver or an
  30. HDMI connector. It will provide a better userspace sysfs interface than GPIO.
  31. - restart-gpio: drivers/power/reset/gpio-restart.c is used to restart/reboot
  32. the system by pulling a GPIO line and will register a restart handler so
  33. userspace can issue the right system call to restart the system.
  34. - poweroff-gpio: drivers/power/reset/gpio-poweroff.c is used to power the
  35. system down by pulling a GPIO line and will register a pm_power_off()
  36. callback so that userspace can issue the right system call to power down the
  37. system.
  38. - gpio-gate-clock: drivers/clk/clk-gpio.c is used to control a gated clock
  39. (off/on) that uses a GPIO, and integrated with the clock subsystem.
  40. - i2c-gpio: drivers/i2c/busses/i2c-gpio.c is used to drive an I2C bus
  41. (two wires, SDA and SCL lines) by hammering (bitbang) two GPIO lines. It will
  42. appear as any other I2C bus to the system and makes it possible to connect
  43. drivers for the I2C devices on the bus like any other I2C bus driver.
  44. - spi_gpio: drivers/spi/spi-gpio.c is used to drive an SPI bus (variable number
  45. of wires, at least SCK and optionally MISO, MOSI and chip select lines) using
  46. GPIO hammering (bitbang). It will appear as any other SPI bus on the system
  47. and makes it possible to connect drivers for SPI devices on the bus like
  48. any other SPI bus driver. For example any MMC/SD card can then be connected
  49. to this SPI by using the mmc_spi host from the MMC/SD card subsystem.
  50. - w1-gpio: drivers/w1/masters/w1-gpio.c is used to drive a one-wire bus using
  51. a GPIO line, integrating with the W1 subsystem and handling devices on
  52. the bus like any other W1 device.
  53. - gpio-fan: drivers/hwmon/gpio-fan.c is used to control a fan for cooling the
  54. system, connected to a GPIO line (and optionally a GPIO alarm line),
  55. presenting all the right in-kernel and sysfs interfaces to make your system
  56. not overheat.
  57. - gpio-regulator: drivers/regulator/gpio-regulator.c is used to control a
  58. regulator providing a certain voltage by pulling a GPIO line, integrating
  59. with the regulator subsystem and giving you all the right interfaces.
  60. - gpio-wdt: drivers/watchdog/gpio_wdt.c is used to provide a watchdog timer
  61. that will periodically "ping" a hardware connected to a GPIO line by toggling
  62. it from 1-to-0-to-1. If that hardware does not receive its "ping"
  63. periodically, it will reset the system.
  64. - gpio-nand: drivers/mtd/nand/raw/gpio.c is used to connect a NAND flash chip
  65. to a set of simple GPIO lines: RDY, NCE, ALE, CLE, NWP. It interacts with the
  66. NAND flash MTD subsystem and provides chip access and partition parsing like
  67. any other NAND driving hardware.
  68. - ps2-gpio: drivers/input/serio/ps2-gpio.c is used to drive a PS/2 (IBM) serio
  69. bus, data and clock line, by bit banging two GPIO lines. It will appear as
  70. any other serio bus to the system and makes it possible to connect drivers
  71. for e.g. keyboards and other PS/2 protocol based devices.
  72. - cec-gpio: drivers/media/platform/cec-gpio/ is used to interact with a CEC
  73. Consumer Electronics Control bus using only GPIO. It is used to communicate
  74. with devices on the HDMI bus.
  75. - gpio-charger: drivers/power/supply/gpio-charger.c is used if you need to do
  76. battery charging and all you have to go by to check the presence of the
  77. AC charger or more complex tasks such as indicating charging status using
  78. nothing but GPIO lines, this driver provides that and also a clearly defined
  79. way to pass the charging parameters from hardware descriptions such as the
  80. device tree.
  81. - gpio-mux: drivers/mux/gpio.c is used for controlling a multiplexer using
  82. n GPIO lines such that you can mux in 2^n different devices by activating
  83. different GPIO lines. Often the GPIOs are on a SoC and the devices are
  84. some SoC-external entities, such as different components on a PCB that
  85. can be selectively enabled.
  86. Apart from this there are special GPIO drivers in subsystems like MMC/SD to
  87. read card detect and write protect GPIO lines, and in the TTY serial subsystem
  88. to emulate MCTRL (modem control) signals CTS/RTS by using two GPIO lines. The
  89. MTD NOR flash has add-ons for extra GPIO lines too, though the address bus is
  90. usually connected directly to the flash.
  91. Use those instead of talking directly to the GPIOs from userspace; they
  92. integrate with kernel frameworks better than your userspace code could.
  93. Needless to say, just using the appropriate kernel drivers will simplify and
  94. speed up your embedded hacking in particular by providing ready-made components.