blob: 3065132517135c231d28d4a9d3be87fd3c81f27b [file] [log] [blame]
Linus Walleijc21cde62015-07-21 11:36:57 +02001Subsystem drivers using GPIO
2============================
3
4Note that standard kernel drivers exist for common GPIO tasks and will provide
5the right in-kernel and userspace APIs/ABIs for the job, and that these
6drivers can quite easily interconnect with other kernel subsystems using
7hardware descriptions such as device tree or ACPI:
8
9- leds-gpio: drivers/leds/leds-gpio.c will handle LEDs connected to GPIO
10 lines, giving you the LED sysfs interface
11
12- ledtrig-gpio: drivers/leds/trigger/ledtrig-gpio.c will provide a LED trigger,
13 i.e. a LED will turn on/off in response to a GPIO line going high or low
14 (and that LED may in turn use the leds-gpio as per above).
15
16- gpio-keys: drivers/input/keyboard/gpio_keys.c is used when your GPIO line
17 can generate interrupts in response to a key press. Also supports debounce.
18
19- gpio-keys-polled: drivers/input/keyboard/gpio_keys_polled.c is used when your
20 GPIO line cannot generate interrupts, so it needs to be periodically polled
21 by a timer.
22
23- gpio_mouse: drivers/input/mouse/gpio_mouse.c is used to provide a mouse with
24 up to three buttons by simply using GPIOs and no mouse port. You can cut the
25 mouse cable and connect the wires to GPIO lines or solder a mouse connector
26 to the lines for a more permanent solution of this type.
27
28- gpio-beeper: drivers/input/misc/gpio-beeper.c is used to provide a beep from
29 an external speaker connected to a GPIO line.
30
31- gpio-tilt-polled: drivers/input/misc/gpio_tilt_polled.c provides tilt
32 detection switches using GPIO, which is useful for your homebrewn pinball
33 machine if for nothing else. It can detect different tilt angles of the
34 monitored object.
35
36- extcon-gpio: drivers/extcon/extcon-gpio.c is used when you need to read an
37 external connector status, such as a headset line for an audio driver or an
38 HDMI connector. It will provide a better userspace sysfs interface than GPIO.
39
Andrew Jeffery3a0000f2016-06-10 16:46:33 +093040- restart-gpio: drivers/power/reset/gpio-restart.c is used to restart/reboot
41 the system by pulling a GPIO line and will register a restart handler so
Linus Walleijc21cde62015-07-21 11:36:57 +020042 userspace can issue the right system call to restart the system.
43
Andrew Jeffery3a0000f2016-06-10 16:46:33 +093044- poweroff-gpio: drivers/power/reset/gpio-poweroff.c is used to power the
45 system down by pulling a GPIO line and will register a pm_power_off()
46 callback so that userspace can issue the right system call to power down the
47 system.
Linus Walleijc21cde62015-07-21 11:36:57 +020048
Andrew Jeffery3a0000f2016-06-10 16:46:33 +093049- gpio-gate-clock: drivers/clk/clk-gpio.c is used to control a gated clock
Linus Walleijc21cde62015-07-21 11:36:57 +020050 (off/on) that uses a GPIO, and integrated with the clock subsystem.
51
52- i2c-gpio: drivers/i2c/busses/i2c-gpio.c is used to drive an I2C bus
53 (two wires, SDA and SCL lines) by hammering (bitbang) two GPIO lines. It will
54 appear as any other I2C bus to the system and makes it possible to connect
55 drivers for the I2C devices on the bus like any other I2C bus driver.
56
57- spi_gpio: drivers/spi/spi-gpio.c is used to drive an SPI bus (variable number
Masanari Iida547d4c12015-11-16 20:00:35 +090058 of wires, at least SCK and optionally MISO, MOSI and chip select lines) using
Linus Walleijc21cde62015-07-21 11:36:57 +020059 GPIO hammering (bitbang). It will appear as any other SPI bus on the system
60 and makes it possible to connect drivers for SPI devices on the bus like
61 any other SPI bus driver. For example any MMC/SD card can then be connected
62 to this SPI by using the mmc_spi host from the MMC/SD card subsystem.
63
64- w1-gpio: drivers/w1/masters/w1-gpio.c is used to drive a one-wire bus using
65 a GPIO line, integrating with the W1 subsystem and handling devices on
66 the bus like any other W1 device.
67
68- gpio-fan: drivers/hwmon/gpio-fan.c is used to control a fan for cooling the
69 system, connected to a GPIO line (and optionally a GPIO alarm line),
70 presenting all the right in-kernel and sysfs interfaces to make your system
71 not overheat.
72
73- gpio-regulator: drivers/regulator/gpio-regulator.c is used to control a
74 regulator providing a certain voltage by pulling a GPIO line, integrating
75 with the regulator subsystem and giving you all the right interfaces.
76
77- gpio-wdt: drivers/watchdog/gpio_wdt.c is used to provide a watchdog timer
78 that will periodically "ping" a hardware connected to a GPIO line by toggling
Masanari Iida547d4c12015-11-16 20:00:35 +090079 it from 1-to-0-to-1. If that hardware does not receive its "ping"
Linus Walleijc21cde62015-07-21 11:36:57 +020080 periodically, it will reset the system.
81
82- gpio-nand: drivers/mtd/nand/gpio.c is used to connect a NAND flash chip to
83 a set of simple GPIO lines: RDY, NCE, ALE, CLE, NWP. It interacts with the
84 NAND flash MTD subsystem and provides chip access and partition parsing like
85 any other NAND driving hardware.
86
87Apart from this there are special GPIO drivers in subsystems like MMC/SD to
88read card detect and write protect GPIO lines, and in the TTY serial subsystem
89to emulate MCTRL (modem control) signals CTS/RTS by using two GPIO lines. The
90MTD NOR flash has add-ons for extra GPIO lines too, though the address bus is
91usually connected directly to the flash.
92
93Use those instead of talking directly to the GPIOs using sysfs; they integrate
94with kernel frameworks better than your userspace code could. Needless to say,
Masanari Iida547d4c12015-11-16 20:00:35 +090095just using the appropriate kernel drivers will simplify and speed up your
Linus Walleijc21cde62015-07-21 11:36:57 +020096embedded hacking in particular by providing ready-made components.