14784e710SJonathan Neuschäfer============================ 24784e710SJonathan NeuschäferSubsystem drivers using GPIO 34784e710SJonathan Neuschäfer============================ 44784e710SJonathan Neuschäfer 54784e710SJonathan NeuschäferNote that standard kernel drivers exist for common GPIO tasks and will provide 64784e710SJonathan Neuschäferthe right in-kernel and userspace APIs/ABIs for the job, and that these 74784e710SJonathan Neuschäferdrivers can quite easily interconnect with other kernel subsystems using 84784e710SJonathan Neuschäferhardware descriptions such as device tree or ACPI: 94784e710SJonathan Neuschäfer 104784e710SJonathan Neuschäfer- leds-gpio: drivers/leds/leds-gpio.c will handle LEDs connected to GPIO 114784e710SJonathan Neuschäfer lines, giving you the LED sysfs interface 124784e710SJonathan Neuschäfer 134784e710SJonathan Neuschäfer- ledtrig-gpio: drivers/leds/trigger/ledtrig-gpio.c will provide a LED trigger, 144784e710SJonathan Neuschäfer i.e. a LED will turn on/off in response to a GPIO line going high or low 154784e710SJonathan Neuschäfer (and that LED may in turn use the leds-gpio as per above). 164784e710SJonathan Neuschäfer 174784e710SJonathan Neuschäfer- gpio-keys: drivers/input/keyboard/gpio_keys.c is used when your GPIO line 184784e710SJonathan Neuschäfer can generate interrupts in response to a key press. Also supports debounce. 194784e710SJonathan Neuschäfer 204784e710SJonathan Neuschäfer- gpio-keys-polled: drivers/input/keyboard/gpio_keys_polled.c is used when your 214784e710SJonathan Neuschäfer GPIO line cannot generate interrupts, so it needs to be periodically polled 224784e710SJonathan Neuschäfer by a timer. 234784e710SJonathan Neuschäfer 244784e710SJonathan Neuschäfer- gpio_mouse: drivers/input/mouse/gpio_mouse.c is used to provide a mouse with 254784e710SJonathan Neuschäfer up to three buttons by simply using GPIOs and no mouse port. You can cut the 264784e710SJonathan Neuschäfer mouse cable and connect the wires to GPIO lines or solder a mouse connector 274784e710SJonathan Neuschäfer to the lines for a more permanent solution of this type. 284784e710SJonathan Neuschäfer 294784e710SJonathan Neuschäfer- gpio-beeper: drivers/input/misc/gpio-beeper.c is used to provide a beep from 304784e710SJonathan Neuschäfer an external speaker connected to a GPIO line. 314784e710SJonathan Neuschäfer 324784e710SJonathan Neuschäfer- extcon-gpio: drivers/extcon/extcon-gpio.c is used when you need to read an 334784e710SJonathan Neuschäfer external connector status, such as a headset line for an audio driver or an 344784e710SJonathan Neuschäfer HDMI connector. It will provide a better userspace sysfs interface than GPIO. 354784e710SJonathan Neuschäfer 364784e710SJonathan Neuschäfer- restart-gpio: drivers/power/reset/gpio-restart.c is used to restart/reboot 374784e710SJonathan Neuschäfer the system by pulling a GPIO line and will register a restart handler so 384784e710SJonathan Neuschäfer userspace can issue the right system call to restart the system. 394784e710SJonathan Neuschäfer 404784e710SJonathan Neuschäfer- poweroff-gpio: drivers/power/reset/gpio-poweroff.c is used to power the 414784e710SJonathan Neuschäfer system down by pulling a GPIO line and will register a pm_power_off() 424784e710SJonathan Neuschäfer callback so that userspace can issue the right system call to power down the 434784e710SJonathan Neuschäfer system. 444784e710SJonathan Neuschäfer 454784e710SJonathan Neuschäfer- gpio-gate-clock: drivers/clk/clk-gpio.c is used to control a gated clock 464784e710SJonathan Neuschäfer (off/on) that uses a GPIO, and integrated with the clock subsystem. 474784e710SJonathan Neuschäfer 484784e710SJonathan Neuschäfer- i2c-gpio: drivers/i2c/busses/i2c-gpio.c is used to drive an I2C bus 494784e710SJonathan Neuschäfer (two wires, SDA and SCL lines) by hammering (bitbang) two GPIO lines. It will 504784e710SJonathan Neuschäfer appear as any other I2C bus to the system and makes it possible to connect 514784e710SJonathan Neuschäfer drivers for the I2C devices on the bus like any other I2C bus driver. 524784e710SJonathan Neuschäfer 534784e710SJonathan Neuschäfer- spi_gpio: drivers/spi/spi-gpio.c is used to drive an SPI bus (variable number 544784e710SJonathan Neuschäfer of wires, at least SCK and optionally MISO, MOSI and chip select lines) using 554784e710SJonathan Neuschäfer GPIO hammering (bitbang). It will appear as any other SPI bus on the system 564784e710SJonathan Neuschäfer and makes it possible to connect drivers for SPI devices on the bus like 574784e710SJonathan Neuschäfer any other SPI bus driver. For example any MMC/SD card can then be connected 584784e710SJonathan Neuschäfer to this SPI by using the mmc_spi host from the MMC/SD card subsystem. 594784e710SJonathan Neuschäfer 604784e710SJonathan Neuschäfer- w1-gpio: drivers/w1/masters/w1-gpio.c is used to drive a one-wire bus using 614784e710SJonathan Neuschäfer a GPIO line, integrating with the W1 subsystem and handling devices on 624784e710SJonathan Neuschäfer the bus like any other W1 device. 634784e710SJonathan Neuschäfer 644784e710SJonathan Neuschäfer- gpio-fan: drivers/hwmon/gpio-fan.c is used to control a fan for cooling the 654784e710SJonathan Neuschäfer system, connected to a GPIO line (and optionally a GPIO alarm line), 664784e710SJonathan Neuschäfer presenting all the right in-kernel and sysfs interfaces to make your system 674784e710SJonathan Neuschäfer not overheat. 684784e710SJonathan Neuschäfer 694784e710SJonathan Neuschäfer- gpio-regulator: drivers/regulator/gpio-regulator.c is used to control a 704784e710SJonathan Neuschäfer regulator providing a certain voltage by pulling a GPIO line, integrating 714784e710SJonathan Neuschäfer with the regulator subsystem and giving you all the right interfaces. 724784e710SJonathan Neuschäfer 734784e710SJonathan Neuschäfer- gpio-wdt: drivers/watchdog/gpio_wdt.c is used to provide a watchdog timer 744784e710SJonathan Neuschäfer that will periodically "ping" a hardware connected to a GPIO line by toggling 754784e710SJonathan Neuschäfer it from 1-to-0-to-1. If that hardware does not receive its "ping" 764784e710SJonathan Neuschäfer periodically, it will reset the system. 774784e710SJonathan Neuschäfer 783fd14cdcSLinus Torvalds- gpio-nand: drivers/mtd/nand/raw/gpio.c is used to connect a NAND flash chip 793fd14cdcSLinus Torvalds to a set of simple GPIO lines: RDY, NCE, ALE, CLE, NWP. It interacts with the 804784e710SJonathan Neuschäfer NAND flash MTD subsystem and provides chip access and partition parsing like 814784e710SJonathan Neuschäfer any other NAND driving hardware. 824784e710SJonathan Neuschäfer 834784e710SJonathan Neuschäfer- ps2-gpio: drivers/input/serio/ps2-gpio.c is used to drive a PS/2 (IBM) serio 844784e710SJonathan Neuschäfer bus, data and clock line, by bit banging two GPIO lines. It will appear as 854784e710SJonathan Neuschäfer any other serio bus to the system and makes it possible to connect drivers 864784e710SJonathan Neuschäfer for e.g. keyboards and other PS/2 protocol based devices. 874784e710SJonathan Neuschäfer 88df42a02dSLinus Walleij- cec-gpio: drivers/media/platform/cec-gpio/ is used to interact with a CEC 89df42a02dSLinus Walleij Consumer Electronics Control bus using only GPIO. It is used to communicate 90df42a02dSLinus Walleij with devices on the HDMI bus. 91df42a02dSLinus Walleij 928cbdc504SLinus Walleij- gpio-charger: drivers/power/supply/gpio-charger.c is used if you need to do 938cbdc504SLinus Walleij battery charging and all you have to go by to check the presence of the 948cbdc504SLinus Walleij AC charger or more complex tasks such as indicating charging status using 958cbdc504SLinus Walleij nothing but GPIO lines, this driver provides that and also a clearly defined 968cbdc504SLinus Walleij way to pass the charging parameters from hardware descriptions such as the 978cbdc504SLinus Walleij device tree. 988cbdc504SLinus Walleij 99*4a5c9da4SLinus Walleij- gpio-mux: drivers/mux/gpio.c is used for controlling a multiplexer using 100*4a5c9da4SLinus Walleij n GPIO lines such that you can mux in 2^n different devices by activating 101*4a5c9da4SLinus Walleij different GPIO lines. Often the GPIOs are on a SoC and the devices are 102*4a5c9da4SLinus Walleij some SoC-external entities, such as different components on a PCB that 103*4a5c9da4SLinus Walleij can be selectively enabled. 104*4a5c9da4SLinus Walleij 1054784e710SJonathan NeuschäferApart from this there are special GPIO drivers in subsystems like MMC/SD to 1064784e710SJonathan Neuschäferread card detect and write protect GPIO lines, and in the TTY serial subsystem 1074784e710SJonathan Neuschäferto emulate MCTRL (modem control) signals CTS/RTS by using two GPIO lines. The 1084784e710SJonathan NeuschäferMTD NOR flash has add-ons for extra GPIO lines too, though the address bus is 1094784e710SJonathan Neuschäferusually connected directly to the flash. 1104784e710SJonathan Neuschäfer 111ddb4e53fSLinus WalleijUse those instead of talking directly to the GPIOs from userspace; they 112ddb4e53fSLinus Walleijintegrate with kernel frameworks better than your userspace code could. 113ddb4e53fSLinus WalleijNeedless to say, just using the appropriate kernel drivers will simplify and 114ddb4e53fSLinus Walleijspeed up your embedded hacking in particular by providing ready-made components. 115