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

Linux 6.18.37 · Driver API

Introduction

GPIO의 정의, provider 유형, direction·IRQ capability와 active/open-drain semantics를 설명합니다.

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

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

1. 요약·해설

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

요약과 해설

intro.rst:1-112

GPIO는 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 구동을 감지할 수 있습니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 ============
2 Introduction
3 ============
4
5
6 GPIO Interfaces
7 ===============
8
9 The documents in this directory give detailed instructions on how to access
10 GPIOs in drivers, and how to write a driver for a device that provides GPIOs
11 itself.
12
13
14 What is a GPIO?
15 ===============
16
17 A "General Purpose Input/Output" (GPIO) is a flexible software-controlled
18 digital signal. They are provided from many kinds of chips, and are familiar
19 to Linux developers working with embedded and custom hardware. Each GPIO
20 represents a bit connected to a particular pin, or "ball" on Ball Grid Array
21 (BGA) packages. Board schematics show which external hardware connects to
22 which GPIOs. Drivers can be written generically, so that board setup code
23 passes such pin configuration data to drivers.
24
25 System-on-Chip (SOC) processors heavily rely on GPIOs. In some cases, every
26 non-dedicated pin can be configured as a GPIO; and most chips have at least
27 several dozen of them. Programmable logic devices (like FPGAs) can easily
28 provide GPIOs; multifunction chips like power managers, and audio codecs
29 often have a few such pins to help with pin scarcity on SOCs; and there are
30 also "GPIO Expander" chips that connect using the I2C or SPI serial buses.
31 Most PC southbridges have a few dozen GPIO-capable pins (with only the BIOS
32 firmware knowing how they're used).
33
34 The exact capabilities of GPIOs vary between systems. Common options:
35
36 - Output values are writable (high=1, low=0). Some chips also have
37 options about how that value is driven, so that for example only one
38 value might be driven, supporting "wire-OR" and similar schemes for the
39 other value (notably, "open drain" signaling).
40
41 - Input values are likewise readable (1, 0). Some chips support readback
42 of pins configured as "output", which is very useful in such "wire-OR"
43 cases (to support bidirectional signaling). GPIO controllers may have
44 input de-glitch/debounce logic, sometimes with software controls.
45
46 - Inputs can often be used as IRQ signals, often edge triggered but
47 sometimes level triggered. Such IRQs may be configurable as system
48 wakeup events, to wake the system from a low power state.
49
50 - Usually a GPIO will be configurable as either input or output, as needed
51 by different product boards; single direction ones exist too.
52
53 - Most GPIOs can be accessed while holding spinlocks, but those accessed
54 through a serial bus normally can't. Some systems support both types.
55
56 On a given board each GPIO is used for one specific purpose like monitoring
57 MMC/SD card insertion/removal, detecting card write-protect status, driving
58 a LED, configuring a transceiver, bit-banging a serial bus, poking a hardware
59 watchdog, sensing a switch, and so on.
60
61
62 Common GPIO Properties
63 ======================
64
65 These properties are met through all the other documents of the GPIO interface
66 and it is useful to understand them, especially if you need to define GPIO
67 mappings.
68
69 Active-High and Active-Low
70 --------------------------
71 It is natural to assume that a GPIO is "active" when its output signal is 1
72 ("high"), and inactive when it is 0 ("low"). However in practice the signal of a
73 GPIO may be inverted before is reaches its destination, or a device could decide
74 to have different conventions about what "active" means. Such decisions should
75 be transparent to device drivers, therefore it is possible to define a GPIO as
76 being either active-high ("1" means "active", the default) or active-low ("0"
77 means "active") so that drivers only need to worry about the logical signal and
78 not about what happens at the line level.
79
80 Open Drain and Open Source
81 --------------------------
82 Sometimes shared signals need to use "open drain" (where only the low signal
83 level is actually driven), or "open source" (where only the high signal level is
84 driven) signaling. That term applies to CMOS transistors; "open collector" is
85 used for TTL. A pullup or pulldown resistor causes the high or low signal level.
86 This is sometimes called a "wire-AND"; or more practically, from the negative
87 logic (low=true) perspective this is a "wire-OR".
88
89 One common example of an open drain signal is a shared active-low IRQ line.
90 Also, bidirectional data bus signals sometimes use open drain signals.
91
92 Some GPIO controllers directly support open drain and open source outputs; many
93 don't. When you need open drain signaling but your hardware doesn't directly
94 support it, there's a common idiom you can use to emulate it with any GPIO pin
95 that can be used as either an input or an output:
96
97 **LOW**: ``gpiod_direction_output(gpio, 0)`` ... this drives the signal and
98 overrides the pullup.
99
100 **HIGH**: ``gpiod_direction_input(gpio)`` ... this turns off the output, so
101 the pullup (or some other device) controls the signal.
102
103 The same logic can be applied to emulate open source signaling, by driving the
104 high signal and configuring the GPIO as input for low. This open drain/open
105 source emulation can be handled transparently by the GPIO framework.
106
107 If you are "driving" the signal high but gpiod_get_value(gpio) reports a low
108 value (after the appropriate rise time passes), you know some other component is
109 driving the shared signal low. That's not necessarily an error. As one common
110 example, that's how I2C clocks are stretched: a slave that needs a slower clock
111 delays the rising edge of SCK, and the I2C master adjusts its signaling rate
112 accordingly.
113

3. 한국어 전문 번역

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

GPIO interface 문서의 범위

1-13

문서 제목은 `Introduction`입니다. 이 디렉터리의 문서는 driver에서 GPIO에 접근하는 방법과 자체적으로 GPIO를 제공하는 device의 driver를 작성하는 방법을 자세히 설명합니다.

GPIO interface의 두 관점
Consumer device driverGPIO descriptor를 획득·사용gpiolib coregpio_chip provider driverHardware GPIO controller

GPIO를 사용하는 consumer와 제공하는 controller driver를 구분합니다.

GPIO의 정의와 제공 hardware

14-33

General 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 provider 유형
Provider특성
SoC수십 개 이상, non-dedicated pin을 GPIO로 mux 가능
FPGAProgrammable logic으로 GPIO 구현
PMIC·audio codecSoC pin 부족을 보완하는 소수 line
GPIO expanderI2C·SPI bus를 통해 추가 line 제공
PC southbridge수십 개 capable pin, BIOS가 용도 결정

GPIO를 제공하는 대표 hardware와 특성입니다.

GPIO capability와 board별 용도

34-60

GPIO의 정확한 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 감지 등 하나의 구체적인 용도로 사용됩니다.

일반 GPIO capability
Capability가능한 동작변형
OutputHigh·low writeOpen drain·wire-OR
Input0·1 readOutput readback·debounce
IRQEdge 또는 level triggerSystem wakeup
DirectionInput·output 전환Single-direction line 존재
ContextSpinlock-safe accessSerial-bus GPIO는 sleep 필요

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만 다룹니다.

Logical active와 physical level
PropertyLogical activeLogical inactive
Active-highPhysical high(1)Physical low(0)
Active-lowPhysical low(0)Physical high(1)

Active-high·active-low mapping을 구조화했습니다.

Open drain·open source와 emulation

80-112

Shared 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를 조정합니다.

Open drain·open source 동작
Mode적극 구동High impedance에서 levelResistor
Open drainLowHighPull-up
Open sourceHighLowPull-down

적극 구동하는 level과 resistor가 만드는 level입니다.

Open-drain emulation과 충돌 감지
Low 요청: output-lowHigh 요청: input으로 전환Pull-up의 rise time 대기gpiod_get_value() readbackLow이면 다른 participant가 low 구동Protocol 규칙에 따라 대기·속도 조정

Direction 전환으로 shared signal을 구동하고 readback합니다.