요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
============
Introduction
============
GPIO Interfaces
===============
The documents in this directory give detailed instructions on how to access
GPIOs in drivers, and how to write a driver for a device that provides GPIOs
itself.
What is a GPIO?
===============
A "General Purpose Input/Output" (GPIO) is a flexible software-controlled
digital signal. They are provided from many kinds of chips, and are familiar
to Linux developers working with embedded and custom hardware. Each GPIO
represents a bit connected to a particular pin, or "ball" on Ball Grid Array
(BGA) packages. Board schematics show which external hardware connects to
which GPIOs. Drivers can be written generically, so that board setup code
passes such pin configuration data to drivers.
System-on-Chip (SOC) processors heavily rely on GPIOs. In some cases, every
non-dedicated pin can be configured as a GPIO; and most chips have at least
several dozen of them. Programmable logic devices (like FPGAs) can easily
provide GPIOs; multifunction chips like power managers, and audio codecs
often have a few such pins to help with pin scarcity on SOCs; and there are
also "GPIO Expander" chips that connect using the I2C or SPI serial buses.
Most PC southbridges have a few dozen GPIO-capable pins (with only the BIOS
firmware knowing how they're used).
The exact capabilities of GPIOs vary between systems. Common options:
- Output values are writable (high=1, low=0). Some chips also have
options about how that value is driven, so that for example only one
value might be driven, supporting "wire-OR" and similar schemes for the
other value (notably, "open drain" signaling).
- Input values are likewise readable (1, 0). Some chips support readback
of pins configured as "output", which is very useful in such "wire-OR"
cases (to support bidirectional signaling). GPIO controllers may have
input de-glitch/debounce logic, sometimes with software controls.
- Inputs can often be used as IRQ signals, often edge triggered but
sometimes level triggered. Such IRQs may be configurable as system
wakeup events, to wake the system from a low power state.
- Usually a GPIO will be configurable as either input or output, as needed
by different product boards; single direction ones exist too.
- Most GPIOs can be accessed while holding spinlocks, but those accessed
through a serial bus normally can't. Some systems support both types.
On a given board each GPIO is used for one specific purpose like monitoring
MMC/SD card insertion/removal, detecting card write-protect status, driving
a LED, configuring a transceiver, bit-banging a serial bus, poking a hardware
watchdog, sensing a switch, and so on.
Common GPIO Properties
======================
These properties are met through all the other documents of the GPIO interface
and it is useful to understand them, especially if you need to define GPIO
mappings.
Active-High and Active-Low
--------------------------
It is natural to assume that a GPIO is "active" when its output signal is 1
("high"), and inactive when it is 0 ("low"). However in practice the signal of a
GPIO may be inverted before is reaches its destination, or a device could decide
to have different conventions about what "active" means. Such decisions should
be transparent to device drivers, therefore it is possible to define a GPIO as
being either active-high ("1" means "active", the default) or active-low ("0"
means "active") so that drivers only need to worry about the logical signal and
not about what happens at the line level.
Open Drain and Open Source
--------------------------
Sometimes shared signals need to use "open drain" (where only the low signal
level is actually driven), or "open source" (where only the high signal level is
driven) signaling. That term applies to CMOS transistors; "open collector" is
used for TTL. A pullup or pulldown resistor causes the high or low signal level.
This is sometimes called a "wire-AND"; or more practically, from the negative
logic (low=true) perspective this is a "wire-OR".
One common example of an open drain signal is a shared active-low IRQ line.
Also, bidirectional data bus signals sometimes use open drain signals.
Some GPIO controllers directly support open drain and open source outputs; many
don't. When you need open drain signaling but your hardware doesn't directly
support it, there's a common idiom you can use to emulate it with any GPIO pin
that can be used as either an input or an output:
**LOW**: ``gpiod_direction_output(gpio, 0)`` ... this drives the signal and
overrides the pullup.
**HIGH**: ``gpiod_direction_input(gpio)`` ... this turns off the output, so
the pullup (or some other device) controls the signal.
The same logic can be applied to emulate open source signaling, by driving the
high signal and configuring the GPIO as input for low. This open drain/open
source emulation can be handled transparently by the GPIO framework.
If you are "driving" the signal high but gpiod_get_value(gpio) reports a low
value (after the appropriate rise time passes), you know some other component is
driving the shared signal low. That's not necessarily an error. As one common
example, that's how I2C clocks are stretched: a slave that needs a slower clock
delays the rising edge of SCK, and the I2C master adjusts its signaling rate
accordingly.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
GPIO interface 문서의 범위
1-13문서 제목은 `Introduction`입니다. 이 디렉터리의 문서는 driver에서 GPIO에 접근하는 방법과 자체적으로 GPIO를 제공하는 device의 driver를 작성하는 방법을 자세히 설명합니다.
GPIO를 사용하는 consumer와 제공하는 controller driver를 구분합니다.
GPIO의 정의와 제공 hardware
14-33General Purpose Input/Output(GPIO)는 software로 유연하게 제어하는 digital signal입니다. 여러 종류의 chip이 제공하며 embedded·custom hardware를 다루는 Linux developer에게 익숙합니다.
각 GPIO는 특정 pin 또는 Ball Grid Array(BGA) package의 `ball`에 연결된 bit 하나를 나타냅니다. Board schematic은 어느 external hardware가 어느 GPIO와 연결되는지 보여 줍니다. Driver는 generic하게 작성하고 board setup code가 pin configuration data를 전달할 수 있습니다.
System-on-Chip(SoC) processor는 GPIO에 크게 의존합니다. 어떤 SoC는 전용 기능이 없는 모든 pin을 GPIO로 설정할 수 있고 대부분 수십 개 이상을 제공합니다. FPGA 같은 programmable logic device도 쉽게 GPIO를 제공합니다.
Power manager·audio codec 같은 multifunction chip은 SoC의 pin 부족을 보완하는 GPIO pin 몇 개를 제공하기도 합니다. I2C나 SPI serial bus로 연결되는 `GPIO Expander`도 있으며, 대부분의 PC southbridge에도 수십 개 GPIO-capable pin이 있지만 사용 방식은 BIOS firmware만 아는 경우가 많습니다.
GPIO를 제공하는 대표 hardware와 특성입니다.
GPIO capability와 board별 용도
34-60GPIO의 정확한 capability는 system마다 다릅니다. 일반적인 option은 다음과 같습니다.
- Output value는 high=1, low=0으로 쓸 수 있습니다. 일부 chip은 한쪽 level만 적극 구동해 wire-OR나 open-drain signaling을 지원합니다.
- Input value도 1 또는 0으로 읽습니다. 일부 chip은 output으로 구성한 pin도 readback해 bidirectional wire-OR에 유용합니다. Controller에 software-controlled de-glitch·debounce logic이 있을 수 있습니다.
- Input은 흔히 edge-triggered, 때로는 level-triggered IRQ signal로 쓸 수 있습니다. System wakeup event로 구성해 low-power state에서 깨울 수도 있습니다.
- 대부분 GPIO는 board 요구에 따라 input 또는 output으로 구성할 수 있지만 한 direction만 지원하는 line도 있습니다.
- 대부분 GPIO는 spinlock을 잡은 상태에서 접근할 수 있지만 serial bus 뒤의 GPIO는 보통 불가능합니다. 한 system에 두 유형이 함께 있을 수 있습니다.
특정 board에서 GPIO 하나는 MMC/SD card 삽입·제거 감시, write-protect 감지, LED 구동, transceiver 구성, serial bus bitbang, hardware watchdog 자극, switch 감지 등 하나의 구체적인 용도로 사용됩니다.
Direction, electrical mode, IRQ, execution context를 비교합니다.
Active-high와 active-low
61-79이 property는 GPIO interface의 다른 모든 문서에 나타나므로 GPIO mapping을 정의할 때 특히 이해해야 합니다.
GPIO output signal이 1(high)이면 active이고 0(low)이면 inactive라고 생각하기 쉽습니다. 그러나 destination에 도달하기 전에 signal이 invert되거나 device가 active의 의미를 다르게 정할 수 있습니다.
이 결정은 device driver에 투명해야 합니다. GPIO를 active-high, 즉 1이 active인 기본값으로 정의하거나 active-low, 즉 0이 active인 것으로 정의할 수 있습니다. Driver는 line level에서 일어나는 일을 신경 쓰지 않고 logical signal만 다룹니다.
Active-high·active-low mapping을 구조화했습니다.
Open drain·open source와 emulation
80-112Shared signal에는 low level만 적극 구동하는 open drain 또는 high level만 적극 구동하는 open source signaling이 필요할 수 있습니다. 이 용어는 CMOS transistor에 쓰며 TTL에서는 open collector라고 합니다. Pull-up 또는 pull-down resistor가 반대쪽 signal level을 만듭니다.
이 구성은 `wire-AND`라고도 하며 negative logic, 즉 low=true 관점에서는 실질적으로 `wire-OR`입니다. Shared active-low IRQ line이 흔한 open-drain 예이며 bidirectional data bus signal도 open drain을 사용할 수 있습니다.
일부 GPIO controller는 open drain·open source output을 직접 지원하지만 많은 controller는 그렇지 않습니다. Hardware 지원이 없고 pin을 input과 output으로 모두 쓸 수 있다면 다음 idiom으로 open drain을 흉내 냅니다.
**LOW**: ``gpiod_direction_output(gpio, 0)`` ... this drives the signal and
overrides the pullup.
**HIGH**: ``gpiod_direction_input(gpio)`` ... this turns off the output, so
the pullup (or some other device) controls the signal.
LOW에서는 `gpiod_direction_output(gpio, 0)`으로 signal을 구동해 pull-up을 이깁니다. HIGH에서는 `gpiod_direction_input(gpio)`으로 output을 끄고 pull-up 또는 다른 device가 signal을 제어하게 합니다.
Open-source emulation도 같은 logic을 반대로 적용합니다. High는 적극 구동하고 low에서는 GPIO를 input으로 구성합니다. GPIO framework가 이 open drain/source emulation을 consumer에게 투명하게 처리할 수 있습니다.
Signal을 high로 구동 중이라고 생각했는데 적절한 rise time 뒤 `gpiod_get_value(gpio)`가 low를 반환하면 다른 component가 shared signal을 low로 끌어내리고 있음을 뜻합니다. 반드시 error는 아닙니다. I2C clock stretching에서는 느린 clock이 필요한 slave가 SCK rising edge를 늦추고 master가 signaling rate를 조정합니다.
적극 구동하는 level과 resistor가 만드는 level입니다.
Direction 전환으로 shared signal을 구동하고 readback합니다.
요약과 해설
intro.rst:1-112GPIO는 board의 pin에 연결된 software-controlled digital bit입니다. Consumer driver는 logical active value를 사용하고 framework가 active-low와 open-drain/source 같은 physical semantics를 처리하도록 해야 합니다.
Serial-bus expander의 GPIO는 sleep할 수 있고, shared open-drain line은 input 전환으로 high impedance를 흉내 내며 readback으로 다른 participant의 low 구동을 감지할 수 있습니다.