요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
=========================
Using GPIO Lines in Linux
=========================
The Linux kernel exists to abstract and present hardware to users. GPIO lines
as such are normally not user facing abstractions. The most obvious, natural
and preferred way to use GPIO lines is to let kernel hardware drivers deal
with them.
For examples of already existing generic drivers that will also be good
examples for any other kernel drivers you want to author, refer to
Documentation/driver-api/gpio/drivers-on-gpio.rst
For any kind of mass produced system you want to support, such as servers,
laptops, phones, tablets, routers, and any consumer or office or business goods
using appropriate kernel drivers is paramount. Submit your code for inclusion
in the upstream Linux kernel when you feel it is mature enough and you will get
help to refine it, see Documentation/process/submitting-patches.rst.
In Linux GPIO lines also have a userspace ABI.
The userspace ABI is intended for one-off deployments. Examples are prototypes,
factory lines, maker community projects, workshop specimen, production tools,
industrial automation, PLC-type use cases, door controllers, in short a piece
of specialized equipment that is not produced by the numbers, requiring
operators to have a deep knowledge of the equipment and knows about the
software-hardware interface to be set up. They should not have a natural fit
to any existing kernel subsystem and not be a good fit for an operating system,
because of not being reusable or abstract enough, or involving a lot of non
computer hardware related policy.
Applications that have a good reason to use the industrial I/O (IIO) subsystem
from userspace will likely be a good fit for using GPIO lines from userspace as
well.
Do not under any circumstances abuse the GPIO userspace ABI to cut corners in
any product development projects. If you use it for prototyping, then do not
productify the prototype: rewrite it using proper kernel drivers. Do not under
any circumstances deploy any uniform products using GPIO from userspace.
The userspace ABI is a character device for each GPIO hardware unit (GPIO chip).
These devices will appear on the system as ``/dev/gpiochip0`` thru
``/dev/gpiochipN``. Examples of how to directly use the userspace ABI can be
found in the kernel tree ``tools/gpio`` subdirectory.
For structured and managed applications, we recommend that you make use of the
libgpiod_ library. This provides helper abstractions, command line utilities
and arbitration for multiple simultaneous consumers on the same GPIO chip.
.. _libgpiod: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/
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`를 참조합니다.
Prototype에서 재사용 가능한 upstream driver로 발전시키는 흐름입니다.
Userspace ABI의 제한된 용도
20-40Linux 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로 배포해서는 안 됩니다.
일회성 전문 장비와 대량 생산 제품의 선택 기준입니다.
GPIO character device와 libgpiod
41-50Userspace 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/
GPIO chip character device와 libgpiod의 관계입니다.
요약과 해설
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를 사용하는 것이 좋습니다.