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

Linux 6.18.37 · Driver API

Using GPIO Lines in Linux

제품에는 kernel driver를 사용하고 one-off 장비에서만 GPIO character-device ABI를 쓰도록 안내합니다.

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

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

1. 요약·해설

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

요약과 해설

using-gpio.rst:1-50

대량 생산 제품의 GPIO 기능은 kernel subsystem driver로 구현해야 합니다. Userspace ABI는 prototype·factory tool·산업 자동화처럼 operator가 hardware를 깊이 이해하는 일회성 전문 장비를 위한 예외적 interface입니다.

Userspace에서는 `/dev/gpiochipN`을 직접 다루기보다 abstraction과 multi-consumer arbitration을 제공하는 libgpiod를 사용하는 것이 좋습니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 =========================
2 Using GPIO Lines in Linux
3 =========================
4
5 The Linux kernel exists to abstract and present hardware to users. GPIO lines
6 as such are normally not user facing abstractions. The most obvious, natural
7 and preferred way to use GPIO lines is to let kernel hardware drivers deal
8 with them.
9
10 For examples of already existing generic drivers that will also be good
11 examples for any other kernel drivers you want to author, refer to
12 Documentation/driver-api/gpio/drivers-on-gpio.rst
13
14 For any kind of mass produced system you want to support, such as servers,
15 laptops, phones, tablets, routers, and any consumer or office or business goods
16 using appropriate kernel drivers is paramount. Submit your code for inclusion
17 in the upstream Linux kernel when you feel it is mature enough and you will get
18 help to refine it, see Documentation/process/submitting-patches.rst.
19
20 In Linux GPIO lines also have a userspace ABI.
21
22 The userspace ABI is intended for one-off deployments. Examples are prototypes,
23 factory lines, maker community projects, workshop specimen, production tools,
24 industrial automation, PLC-type use cases, door controllers, in short a piece
25 of specialized equipment that is not produced by the numbers, requiring
26 operators to have a deep knowledge of the equipment and knows about the
27 software-hardware interface to be set up. They should not have a natural fit
28 to any existing kernel subsystem and not be a good fit for an operating system,
29 because of not being reusable or abstract enough, or involving a lot of non
30 computer hardware related policy.
31
32 Applications that have a good reason to use the industrial I/O (IIO) subsystem
33 from userspace will likely be a good fit for using GPIO lines from userspace as
34 well.
35
36 Do not under any circumstances abuse the GPIO userspace ABI to cut corners in
37 any product development projects. If you use it for prototyping, then do not
38 productify the prototype: rewrite it using proper kernel drivers. Do not under
39 any circumstances deploy any uniform products using GPIO from userspace.
40
41 The userspace ABI is a character device for each GPIO hardware unit (GPIO chip).
42 These devices will appear on the system as ``/dev/gpiochip0`` thru
43 ``/dev/gpiochipN``. Examples of how to directly use the userspace ABI can be
44 found in the kernel tree ``tools/gpio`` subdirectory.
45
46 For structured and managed applications, we recommend that you make use of the
47 libgpiod_ library. This provides helper abstractions, command line utilities
48 and arbitration for multiple simultaneous consumers on the same GPIO chip.
49
50 .. _libgpiod: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/
51

3. 한국어 전문 번역

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

제품에서는 kernel driver로 GPIO 사용

1-19

문서 제목은 `Using GPIO Lines in Linux`입니다. Linux kernel은 hardware를 추상화해 user에게 제공하므로 GPIO line 자체는 보통 user-facing abstraction이 아닙니다. 가장 자연스럽고 선호되는 사용법은 kernel hardware driver가 GPIO를 처리하도록 하는 것입니다.

기존 generic driver 예제와 새 kernel driver 작성 참고 자료는 source path `Documentation/driver-api/gpio/drivers-on-gpio.rst`에 있습니다.

Server, laptop, phone, tablet, router와 각종 consumer·office·business product처럼 대량 생산 system을 지원할 때는 적절한 kernel driver 사용이 핵심입니다. Code가 충분히 성숙하면 upstream Linux kernel inclusion을 위해 제출해 refinement 도움을 받습니다. 절차는 `Documentation/process/submitting-patches.rst`를 참조합니다.

제품 GPIO 기능의 권장 경로
GPIO 기능 요구 식별기존 subsystem driver 우선없으면 proper kernel driver 작성제품 hardware description 연결성숙한 code를 upstream 제출

Prototype에서 재사용 가능한 upstream driver로 발전시키는 흐름입니다.

Userspace ABI의 제한된 용도

20-40

Linux GPIO line에는 userspace ABI도 있지만 one-off deployment를 위한 것입니다.

적합한 예는 prototype, factory line, maker-community project, workshop specimen, production tool, industrial automation, PLC, door controller처럼 대량 생산하지 않는 specialized equipment입니다. Operator가 equipment와 software-hardware interface를 깊이 이해해야 하며, 기존 kernel subsystem에 자연스럽게 맞지 않고 재사용·추상화가 부족하거나 non-computer hardware policy가 많은 경우입니다.

Userspace에서 Industrial I/O(IIO) subsystem을 사용할 타당한 이유가 있는 application은 userspace GPIO 사용에도 잘 맞을 가능성이 큽니다.

Product development에서 편의를 위해 GPIO userspace ABI를 남용하면 안 됩니다. Prototyping에 사용했다면 prototype을 그대로 product로 만들지 말고 proper kernel driver로 다시 작성해야 합니다. Uniform product를 userspace GPIO로 배포해서는 안 됩니다.

Userspace GPIO 적합성
상황Userspace GPIO권장
Prototype·maker·workshop적합할 수 있음Operator가 hardware interface 관리
Factory tool·PLC·industrial automation적합할 수 있음기존 subsystem 부적합 여부 확인
IIO userspace application함께 적합할 가능성Managed userspace design
Server·phone·router 등 uniform product금지Proper kernel driver
Prototype의 제품화그대로 배포 금지Kernel driver로 재작성

일회성 전문 장비와 대량 생산 제품의 선택 기준입니다.

GPIO character device와 libgpiod

41-50

Userspace ABI는 GPIO hardware unit, 즉 GPIO chip마다 하나의 character device입니다. System에는 `/dev/gpiochip0`부터 `/dev/gpiochipN`으로 나타납니다. 직접 사용하는 예제는 kernel tree의 `tools/gpio` subdirectory에 있습니다.

구조화되고 관리되는 application에는 `libgpiod` library 사용을 권장합니다. Helper abstraction, command-line utility와 같은 GPIO chip을 동시에 사용하는 여러 consumer 사이의 arbitration을 제공합니다.

.. _libgpiod: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/
Userspace GPIO access stack
GPIO hardware unitKernel gpio_chip/dev/gpiochipN character devicelibgpiod abstraction·arbitrationCommand-line utility 또는 managed application

GPIO chip character device와 libgpiod의 관계입니다.