← Documents Documentation/userspace-api/gpio/chardev.rst GitHub 원문 ↗

Linux 6.18.37 · Userspace API

GPIO 문자 장치 사용자 공간 API(v2)

최신 GPIO character-device ABI v2의 사용 원칙, chip과 line request 객체, 연산 및 UAPI 자료형을 설명합니다.

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

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

1. 요약·해설

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

요약·해설

chardev.rst:1-116

최신 GPIO character-device ABI v2의 사용 원칙, chip과 line request 객체, 연산 및 UAPI 자료형을 설명합니다.

원문의 문단, symbol, source path, ioctl 이름, 자료형, 표와 줄 좌표를 보존해 전문 번역했습니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ===================================
4 GPIO Character Device Userspace API
5 ===================================
6
7 This is latest version (v2) of the character device API, as defined in
8 ``include/uapi/linux/gpio.h.``
9
10 First added in 5.10.
11
12 .. note::
13 Do NOT abuse userspace APIs to control hardware that has proper kernel
14 drivers. There may already be a driver for your use case, and an existing
15 kernel driver is sure to provide a superior solution to bitbashing
16 from userspace.
17
18 Read Documentation/driver-api/gpio/drivers-on-gpio.rst to avoid reinventing
19 kernel wheels in userspace.
20
21 Similarly, for multi-function lines there may be other subsystems, such as
22 Documentation/spi/index.rst, Documentation/i2c/index.rst,
23 Documentation/driver-api/pwm.rst, Documentation/w1/index.rst etc, that
24 provide suitable drivers and APIs for your hardware.
25
26 Basic examples using the character device API can be found in ``tools/gpio/*``.
27
28 The API is based around two major objects, the :ref:`gpio-v2-chip` and the
29 :ref:`gpio-v2-line-request`.
30
31 .. _gpio-v2-chip:
32
33 Chip
34 ====
35
36 The Chip represents a single GPIO chip and is exposed to userspace using device
37 files of the form ``/dev/gpiochipX``.
38
39 Each chip supports a number of GPIO lines,
40 :c:type:`chip.lines<gpiochip_info>`. Lines on the chip are identified by an
41 ``offset`` in the range from 0 to ``chip.lines - 1``, i.e. `[0,chip.lines)`.
42
43 Lines are requested from the chip using gpio-v2-get-line-ioctl.rst
44 and the resulting line request is used to access the GPIO chip's lines or
45 monitor the lines for edge events.
46
47 Within this documentation, the file descriptor returned by calling `open()`
48 on the GPIO device file is referred to as ``chip_fd``.
49
50 Operations
51 ----------
52
53 The following operations may be performed on the chip:
54
55 .. toctree::
56 :titlesonly:
57
58 Get Line <gpio-v2-get-line-ioctl>
59 Get Chip Info <gpio-get-chipinfo-ioctl>
60 Get Line Info <gpio-v2-get-lineinfo-ioctl>
61 Watch Line Info <gpio-v2-get-lineinfo-watch-ioctl>
62 Unwatch Line Info <gpio-get-lineinfo-unwatch-ioctl>
63 Read Line Info Changed Events <gpio-v2-lineinfo-changed-read>
64
65 .. _gpio-v2-line-request:
66
67 Line Request
68 ============
69
70 Line requests are created by gpio-v2-get-line-ioctl.rst and provide
71 access to a set of requested lines. The line request is exposed to userspace
72 via the anonymous file descriptor returned in
73 :c:type:`request.fd<gpio_v2_line_request>` by gpio-v2-get-line-ioctl.rst.
74
75 Within this documentation, the line request file descriptor is referred to
76 as ``req_fd``.
77
78 Operations
79 ----------
80
81 The following operations may be performed on the line request:
82
83 .. toctree::
84 :titlesonly:
85
86 Get Line Values <gpio-v2-line-get-values-ioctl>
87 Set Line Values <gpio-v2-line-set-values-ioctl>
88 Read Line Edge Events <gpio-v2-line-event-read>
89 Reconfigure Lines <gpio-v2-line-set-config-ioctl>
90
91 Types
92 =====
93
94 This section contains the structs and enums that are referenced by the API v2,
95 as defined in ``include/uapi/linux/gpio.h``.
96
97 .. kernel-doc:: include/uapi/linux/gpio.h
98 :identifiers:
99 gpio_v2_line_attr_id
100 gpio_v2_line_attribute
101 gpio_v2_line_changed_type
102 gpio_v2_line_config
103 gpio_v2_line_config_attribute
104 gpio_v2_line_event
105 gpio_v2_line_event_id
106 gpio_v2_line_flag
107 gpio_v2_line_info
108 gpio_v2_line_info_changed
109 gpio_v2_line_request
110 gpio_v2_line_values
111 gpiochip_info
112
113 .. toctree::
114 :hidden:
115
116 error-codes
117

3. 한국어 전문 번역

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

최신 ABI와 사용 원칙

1-30

이 문서는 `include/uapi/linux/gpio.h`에 정의된 최신 GPIO character device API인 v2를 설명합니다. v2는 Linux 5.10에서 처음 추가되었습니다.

적절한 kernel driver가 있는 하드웨어를 제어하기 위해 userspace API를 남용해서는 안 됩니다. 이미 해당 용도의 driver가 있을 수 있으며, 기존 kernel driver는 사용자 공간에서 bitbanging하는 방식보다 확실히 우수한 해법을 제공합니다. `Documentation/driver-api/gpio/drivers-on-gpio.rst`를 읽어 사용자 공간에서 kernel 기능을 다시 구현하지 않도록 해야 합니다.

다기능 line은 SPI, I2C, PWM, W1 같은 다른 subsystem이 적합한 driver와 API를 제공할 수 있습니다. 관련 문서는 `Documentation/spi/index.rst`, `Documentation/i2c/index.rst`, `Documentation/driver-api/pwm.rst`, `Documentation/w1/index.rst`입니다. Character device API의 기본 예제는 `tools/gpio/*`에 있습니다.

v2 API의 핵심 객체는 `gpio-v2-chip`과 `gpio-v2-line-request` 두 가지입니다.

API 선택 원칙
하드웨어 기능 확인전용 kernel driver 또는 SPI/I2C/PWM/W1 subsystem 확인기존 driver가 있으면 해당 API 사용직접 GPIO line 제어가 필요하면 v2 character device API 사용tools/gpio/* 예제로 동작 확인

전용 kernel subsystem이 있는지 먼저 확인한 뒤 GPIO character device API를 선택합니다.

.. SPDX-License-Identifier: GPL-2.0

===================================
GPIO Character Device Userspace API
===================================

This is latest version (v2) of the character device API, as defined in
``include/uapi/linux/gpio.h.``

First added in 5.10.

.. note::
   Do NOT abuse userspace APIs to control hardware that has proper kernel
   drivers. There may already be a driver for your use case, and an existing
   kernel driver is sure to provide a superior solution to bitbashing
   from userspace.

   Read Documentation/driver-api/gpio/drivers-on-gpio.rst to avoid reinventing
   kernel wheels in userspace.

   Similarly, for multi-function lines there may be other subsystems, such as
   Documentation/spi/index.rst, Documentation/i2c/index.rst,
   Documentation/driver-api/pwm.rst, Documentation/w1/index.rst etc, that
   provide suitable drivers and APIs for your hardware.

Basic examples using the character device API can be found in ``tools/gpio/*``.

The API is based around two major objects, the :ref:`gpio-v2-chip` and the
:ref:`gpio-v2-line-request`.

Chip과 line 요청

31-64

Chip은 하나의 GPIO chip을 나타내며 `/dev/gpiochipX` 형식의 장치 파일로 사용자 공간에 노출됩니다. Chip이 제공하는 line 수는 `gpiochip_info`의 `chip.lines`이고, 각 line은 `[0, chip.lines)` 범위의 `offset`으로 식별됩니다.

`gpio-v2-get-line-ioctl.rst`로 chip의 line을 요청하면 line request가 만들어집니다. 이 요청 객체로 GPIO line에 접근하거나 여러 line의 edge event를 감시합니다. GPIO 장치 파일을 `open()`해 얻은 파일 디스크립터는 `chip_fd`라고 부릅니다.

Chip에서는 line 요청, chip 정보 조회, v2 line 정보 조회, line 정보 변경 감시 시작과 해제, line 정보 변경 이벤트 읽기 연산을 수행할 수 있습니다.

v2 Chip 연산
항목설명
Get Linegpio-v2-get-line-ioctl
Get Chip Infogpio-get-chipinfo-ioctl
Get Line Infogpio-v2-get-lineinfo-ioctl
Watch Line Infogpio-v2-get-lineinfo-watch-ioctl
Unwatch Line Infogpio-get-lineinfo-unwatch-ioctl
Read Line Info Changed Eventsgpio-v2-lineinfo-changed-read

chip_fd에서 시작하는 세부 ABI 문서입니다.

.. _gpio-v2-chip:

Chip
====

The Chip represents a single GPIO chip and is exposed to userspace using device
files of the form ``/dev/gpiochipX``.

Each chip supports a number of GPIO lines,
:c:type:`chip.lines<gpiochip_info>`. Lines on the chip are identified by an
``offset`` in the range from 0 to ``chip.lines - 1``, i.e. `[0,chip.lines)`.

Lines are requested from the chip using gpio-v2-get-line-ioctl.rst
and the resulting line request is used to access the GPIO chip's lines or
monitor the lines for edge events.

Within this documentation, the file descriptor returned by calling `open()`
on the GPIO device file is referred to as ``chip_fd``.

Operations
----------

The following operations may be performed on the chip:

.. toctree::
   :titlesonly:

   Get Line <gpio-v2-get-line-ioctl>
   Get Chip Info <gpio-get-chipinfo-ioctl>
   Get Line Info <gpio-v2-get-lineinfo-ioctl>
   Watch Line Info <gpio-v2-get-lineinfo-watch-ioctl>
   Unwatch Line Info <gpio-get-lineinfo-unwatch-ioctl>
   Read Line Info Changed Events <gpio-v2-lineinfo-changed-read>

Line Request와 req_fd

65-90

Line request는 `gpio-v2-get-line-ioctl.rst`로 만들며 요청한 line 집합에 접근합니다. ioctl이 `gpio_v2_line_request`의 `request.fd`에 반환하는 익명 파일 디스크립터로 사용자 공간에 노출되고, 이 문서에서는 이를 `req_fd`라고 부릅니다.

Line request에서는 line 값 읽기, line 값 쓰기, line edge event 읽기, line 재구성 연산을 수행할 수 있습니다.

v2 Line Request 연산
항목설명
Get Line Valuesgpio-v2-line-get-values-ioctl
Set Line Valuesgpio-v2-line-set-values-ioctl
Read Line Edge Eventsgpio-v2-line-event-read
Reconfigure Linesgpio-v2-line-set-config-ioctl

req_fd에 적용되는 세부 요청입니다.

.. _gpio-v2-line-request:

Line Request
============

Line requests are created by gpio-v2-get-line-ioctl.rst and provide
access to a set of requested lines.  The line request is exposed to userspace
via the anonymous file descriptor returned in
:c:type:`request.fd<gpio_v2_line_request>` by gpio-v2-get-line-ioctl.rst.

Within this documentation, the line request file descriptor is referred to
as ``req_fd``.

Operations
----------

The following operations may be performed on the line request:

.. toctree::
   :titlesonly:

   Get Line Values <gpio-v2-line-get-values-ioctl>
   Set Line Values <gpio-v2-line-set-values-ioctl>
   Read Line Edge Events <gpio-v2-line-event-read>
   Reconfigure Lines <gpio-v2-line-set-config-ioctl>

ABI v2 자료형

91-116

이 절은 `include/uapi/linux/gpio.h`에 정의되고 API v2가 참조하는 구조체와 열거형을 kernel-doc에서 가져옵니다. 공통 오류 코드는 숨은 toctree의 `error-codes` 문서에서 설명합니다.

ABI v2 kernel-doc 식별자
항목설명
gpio_v2_line_attr_idline attribute 종류
gpio_v2_line_attributeline attribute 값
gpio_v2_line_changed_typeline 정보 변경 종류
gpio_v2_line_config요청 전체 line 구성
gpio_v2_line_config_attribute일부 line에 적용할 구성 attribute
gpio_v2_line_eventedge event 데이터
gpio_v2_line_event_idedge event 종류
gpio_v2_line_flagline 설정 flag
gpio_v2_line_infoline 정보
gpio_v2_line_info_changedline 정보 변경 이벤트
gpio_v2_line_requestline 집합 요청
gpio_v2_line_valuesline 값과 bit mask
gpiochip_infochip 정보

v2 ABI의 설정, 정보, 이벤트, 값 자료형입니다.

Types
=====

This section contains the structs and enums that are referenced by the API v2,
as defined in ``include/uapi/linux/gpio.h``.

.. kernel-doc:: include/uapi/linux/gpio.h
   :identifiers:
    gpio_v2_line_attr_id
    gpio_v2_line_attribute
    gpio_v2_line_changed_type
    gpio_v2_line_config
    gpio_v2_line_config_attribute
    gpio_v2_line_event
    gpio_v2_line_event_id
    gpio_v2_line_flag
    gpio_v2_line_info
    gpio_v2_line_info_changed
    gpio_v2_line_request
    gpio_v2_line_values
    gpiochip_info

.. toctree::
   :hidden:

   error-codes