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