Documentation/driver-api/gpio/drivers-on-gpio.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API

Subsystem drivers using GPIO

일반적인 GPIO 작업에 직접 제어 대신 사용할 표준 kernel subsystem driver를 안내합니다.

Source pathDocumentation/driver-api/gpio/drivers-on-gpio.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

drivers-on-gpio.rst:1-119

GPIO로 LED·key·bus·power·watchdog 등을 구현할 때는 userspace에서 line을 직접 조작하기보다 해당 kernel subsystem driver를 사용해야 합니다. 표준 driver는 Device Tree·ACPI 연결과 안정된 kernel·userspace interface를 함께 제공합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ============================
2 Subsystem drivers using GPIO
3 ============================
4
5 Note that standard kernel drivers exist for common GPIO tasks and will provide
6 the right in-kernel and userspace APIs/ABIs for the job, and that these
7 drivers can quite easily interconnect with other kernel subsystems using
8 hardware 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. (If the beep is controlled by
31 off/on, for an actual PWM waveform, see pwm-gpio below.)
32
33 - pwm-gpio: drivers/pwm/pwm-gpio.c is used to toggle a GPIO with a high
34 resolution timer producing a PWM waveform on the GPIO line, as well as
35 Linux high resolution timers can do.
36
37 - extcon-gpio: drivers/extcon/extcon-gpio.c is used when you need to read an
38 external connector status, such as a headset line for an audio driver or an
39 HDMI connector. It will provide a better userspace sysfs interface than GPIO.
40
41 - restart-gpio: drivers/power/reset/gpio-restart.c is used to restart/reboot
42 the system by pulling a GPIO line and will register a restart handler so
43 userspace can issue the right system call to restart the system.
44
45 - poweroff-gpio: drivers/power/reset/gpio-poweroff.c is used to power the
46 system down by pulling a GPIO line and will register a pm_power_off()
47 callback so that userspace can issue the right system call to power down the
48 system.
49
50 - gpio-gate-clock: drivers/clk/clk-gpio.c is used to control a gated clock
51 (off/on) that uses a GPIO, and integrated with the clock subsystem.
52
53 - i2c-gpio: drivers/i2c/busses/i2c-gpio.c is used to drive an I2C bus
54 (two wires, SDA and SCL lines) by hammering (bitbang) two GPIO lines. It will
55 appear as any other I2C bus to the system and makes it possible to connect
56 drivers for the I2C devices on the bus like any other I2C bus driver.
57
58 - spi_gpio: drivers/spi/spi-gpio.c is used to drive an SPI bus (variable number
59 of wires, at least SCK and optionally MISO, MOSI and chip select lines) using
60 GPIO hammering (bitbang). It will appear as any other SPI bus on the system
61 and makes it possible to connect drivers for SPI devices on the bus like
62 any other SPI bus driver. For example any MMC/SD card can then be connected
63 to this SPI by using the mmc_spi host from the MMC/SD card subsystem.
64
65 - w1-gpio: drivers/w1/masters/w1-gpio.c is used to drive a one-wire bus using
66 a GPIO line, integrating with the W1 subsystem and handling devices on
67 the bus like any other W1 device.
68
69 - gpio-fan: drivers/hwmon/gpio-fan.c is used to control a fan for cooling the
70 system, connected to a GPIO line (and optionally a GPIO alarm line),
71 presenting all the right in-kernel and sysfs interfaces to make your system
72 not overheat.
73
74 - gpio-regulator: drivers/regulator/gpio-regulator.c is used to control a
75 regulator providing a certain voltage by pulling a GPIO line, integrating
76 with the regulator subsystem and giving you all the right interfaces.
77
78 - gpio-wdt: drivers/watchdog/gpio_wdt.c is used to provide a watchdog timer
79 that will periodically "ping" a hardware connected to a GPIO line by toggling
80 it from 1-to-0-to-1. If that hardware does not receive its "ping"
81 periodically, it will reset the system.
82
83 - gpio-nand: drivers/mtd/nand/raw/gpio.c is used to connect a NAND flash chip
84 to a set of simple GPIO lines: RDY, NCE, ALE, CLE, NWP. It interacts with the
85 NAND flash MTD subsystem and provides chip access and partition parsing like
86 any other NAND driving hardware.
87
88 - ps2-gpio: drivers/input/serio/ps2-gpio.c is used to drive a PS/2 (IBM) serio
89 bus, data and clock line, by bit banging two GPIO lines. It will appear as
90 any other serio bus to the system and makes it possible to connect drivers
91 for e.g. keyboards and other PS/2 protocol based devices.
92
93 - cec-gpio: drivers/media/platform/cec-gpio/ is used to interact with a CEC
94 Consumer Electronics Control bus using only GPIO. It is used to communicate
95 with devices on the HDMI bus.
96
97 - gpio-charger: drivers/power/supply/gpio-charger.c is used if you need to do
98 battery charging and all you have to go by to check the presence of the
99 AC charger or more complex tasks such as indicating charging status using
100 nothing but GPIO lines, this driver provides that and also a clearly defined
101 way to pass the charging parameters from hardware descriptions such as the
102 device tree.
103
104 - gpio-mux: drivers/mux/gpio.c is used for controlling a multiplexer using
105 n GPIO lines such that you can mux in 2^n different devices by activating
106 different GPIO lines. Often the GPIOs are on a SoC and the devices are
107 some SoC-external entities, such as different components on a PCB that
108 can be selectively enabled.
109
110 Apart from this there are special GPIO drivers in subsystems like MMC/SD to
111 read card detect and write protect GPIO lines, and in the TTY serial subsystem
112 to emulate MCTRL (modem control) signals CTS/RTS by using two GPIO lines. The
113 MTD NOR flash has add-ons for extra GPIO lines too, though the address bus is
114 usually connected directly to the flash.
115
116 Use those instead of talking directly to the GPIOs from userspace; they
117 integrate with kernel frameworks better than your userspace code could.
118 Needless to say, just using the appropriate kernel drivers will simplify and
119 speed up your embedded hacking in particular by providing ready-made components.
120

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

GPIO 작업에는 표준 subsystem driver 사용

1-9

문서 제목은 `Subsystem drivers using GPIO`입니다. 일반적인 GPIO 작업에는 표준 kernel driver가 이미 존재하며, 각 작업에 맞는 in-kernel API와 userspace API/ABI를 제공합니다.

이 driver들은 Device Tree나 ACPI 같은 hardware description을 통해 다른 kernel subsystem과 쉽게 연결됩니다. 따라서 userspace에서 GPIO를 직접 제어하기 전에 해당 subsystem driver를 선택해야 합니다.

GPIO 기능 구현 선택
필요한 hardware 기능 식별기존 GPIO 기반 kernel driver 검색Device Tree·ACPI로 연결 기술해당 subsystem API/ABI 사용Userspace는 안정된 subsystem interface 이용

직접 GPIO 제어보다 표준 subsystem driver를 우선하는 흐름입니다.

LED·입력·전원 관련 GPIO driver

10-48

LED, key, mouse, beeper, PWM, connector, restart와 poweroff에는 다음 표준 driver를 사용합니다.

GPIO 기반 UI·입력·전원 driver
DriverSource path역할
leds-gpiodrivers/leds/leds-gpio.cGPIO 연결 LED를 제어하고 LED sysfs interface 제공
ledtrig-gpiodrivers/leds/trigger/ledtrig-gpio.cGPIO high/low에 따라 LED를 켜고 끄는 LED trigger 제공. LED는 leds-gpio를 사용할 수 있음
gpio-keysdrivers/input/keyboard/gpio_keys.cKey press에 대한 IRQ를 생성하는 GPIO 입력과 debounce 지원
gpio-keys-polleddrivers/input/keyboard/gpio_keys_polled.cIRQ를 만들 수 없는 GPIO를 timer로 주기적 polling
gpio_mousedrivers/input/mouse/gpio_mouse.cMouse port 없이 GPIO로 최대 세 button을 제공. Cable wire 직접 연결 또는 connector 장착 가능
gpio-beeperdrivers/input/misc/gpio-beeper.cGPIO에 연결된 external speaker의 on/off beep 제공. 실제 PWM waveform은 pwm-gpio 사용
pwm-gpiodrivers/pwm/pwm-gpio.cLinux high-resolution timer로 GPIO를 toggle해 PWM waveform 생성
extcon-gpiodrivers/extcon/extcon-gpio.cHeadset·HDMI 같은 external connector 상태를 읽고 GPIO보다 적합한 userspace sysfs 제공
restart-gpiodrivers/power/reset/gpio-restart.cGPIO를 구동해 system restart/reboot하고 restart handler 등록
poweroff-gpiodrivers/power/reset/gpio-poweroff.cGPIO를 구동해 system power down하고 pm_power_off() callback 등록

원문 driver 이름, source path, 제공 interface와 동작을 보존했습니다.

Clock·bus·냉각·watchdog·media driver

49-95

Clock, serial bus, fan, regulator, watchdog, NAND, PS/2와 HDMI CEC에도 GPIO 기반 표준 driver가 있습니다.

GPIO 기반 infrastructure·bus driver
DriverSource path역할
gpio-gate-clockdrivers/clk/clk-gpio.cGPIO로 gated clock을 on/off하고 clock subsystem과 통합
i2c-gpiodrivers/i2c/busses/i2c-gpio.cSDA·SCL 두 GPIO를 bitbang해 일반 I2C bus처럼 제공하고 I2C device driver 연결
spi_gpiodrivers/spi/spi-gpio.cSCK와 optional MISO·MOSI·chip-select GPIO를 bitbang해 일반 SPI bus 제공. mmc_spi host로 MMC/SD 연결 가능
w1-gpiodrivers/w1/masters/w1-gpio.cGPIO 하나로 one-wire bus를 구동하고 W1 subsystem과 device 통합
gpio-fandrivers/hwmon/gpio-fan.cGPIO fan과 optional alarm line을 제어하고 kernel·sysfs thermal interface 제공
gpio-regulatordrivers/regulator/gpio-regulator.cGPIO로 특정 voltage regulator를 제어하고 regulator subsystem과 통합
gpio-wdtdrivers/watchdog/gpio_wdt.cGPIO를 1-0-1로 주기적 ping하며 hardware가 ping을 못 받으면 system reset
gpio-nanddrivers/mtd/nand/raw/gpio.cRDY·NCE·ALE·CLE·NWP GPIO로 NAND flash를 연결하고 MTD access·partition parsing 제공
ps2-gpiodrivers/input/serio/ps2-gpio.cData·clock GPIO 두 개를 bitbang해 PS/2 serio bus와 keyboard 등 device 연결
cec-gpiodrivers/media/platform/cec-gpio/GPIO만으로 HDMI device와 통신하는 CEC bus 제공

GPIO bitbang과 subsystem 통합 방식을 정리했습니다.

GPIO bitbang bus 통합
Hardware description에 GPIO line 지정I2C·SPI·W1·PS/2용 driver probeTimer 또는 GPIO access로 protocol bitbangKernel bus controller로 등록기존 bus device driver가 그대로 bind

GPIO line으로 만든 bus가 기존 subsystem에 연결되는 공통 구조입니다.

Charger·mux와 subsystem별 전용 helper

96-119

`gpio-charger`의 source path는 `drivers/power/supply/gpio-charger.c`입니다. AC charger 존재 여부나 charging status를 GPIO만으로 판단해야 할 때 battery charging 기능을 제공하며, Device Tree 같은 hardware description에서 charging parameter를 전달하는 명확한 방식을 정의합니다.

`gpio-mux`의 source path는 `drivers/mux/gpio.c`입니다. n개 GPIO line의 조합으로 2^n개 device 가운데 하나를 선택하는 multiplexer를 제어합니다. GPIO는 흔히 SoC에 있고 선택 대상은 PCB의 여러 component처럼 SoC 외부 entity입니다.

이 밖에도 MMC/SD subsystem에는 card-detect와 write-protect GPIO를 읽는 전용 driver가 있고, TTY serial subsystem에는 두 GPIO line으로 CTS/RTS MCTRL modem-control signal을 흉내 내는 지원이 있습니다. MTD NOR flash에도 추가 GPIO line용 add-on이 있지만 address bus는 보통 flash에 직접 연결됩니다.

Userspace에서 GPIO를 직접 다루지 말고 이런 driver를 사용해야 합니다. Kernel framework와의 통합은 userspace code보다 낫고, 준비된 component를 이용하면 특히 embedded system 개발이 더 단순하고 빨라집니다.

추가 GPIO 통합
기능구현·경로통합 대상
Battery chargergpio-charger · drivers/power/supply/gpio-charger.cPower supply subsystem·hardware description
Multiplexergpio-mux · drivers/mux/gpio.cn GPIO로 2^n device 선택
Card detect/write protectMMC/SD 전용 driverMMC/SD subsystem
CTS/RTS MCTRLTTY serial GPIO helperSerial subsystem
Extra NOR GPIOMTD NOR add-onMTD subsystem

Charger, mux와 subsystem 전용 GPIO 기능입니다.