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