요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
Device Tree와 sysfs
gpio-sim.rst:82-137`gpio-simulator` compatible의 DT 예와 각 가상 line의 `pull`, `value` attribute를 정리합니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0-or-later
Configfs GPIO Simulator
=======================
The configfs GPIO Simulator (gpio-sim) provides a way to create simulated GPIO
chips for testing purposes. The lines exposed by these chips can be accessed
using the standard GPIO character device interface as well as manipulated
using sysfs attributes.
Creating simulated chips
------------------------
The gpio-sim module registers a configfs subsystem called ``'gpio-sim'``. For
details of the configfs filesystem, please refer to the configfs documentation.
The user can create a hierarchy of configfs groups and items as well as modify
values of exposed attributes. Once the chip is instantiated, this hierarchy
will be translated to appropriate device properties. The general structure is:
**Group:** ``/config/gpio-sim``
This is the top directory of the gpio-sim configfs tree.
**Group:** ``/config/gpio-sim/gpio-device``
**Attribute:** ``/config/gpio-sim/gpio-device/dev_name``
**Attribute:** ``/config/gpio-sim/gpio-device/live``
This is a directory representing a GPIO platform device. The ``'dev_name'``
attribute is read-only and allows the user-space to read the platform device
name (e.g. ``'gpio-sim.0'``). The ``'live'`` attribute allows to trigger the
actual creation of the device once it's fully configured. The accepted values
are: ``'1'`` to enable the simulated device and ``'0'`` to disable and tear
it down.
**Group:** ``/config/gpio-sim/gpio-device/gpio-bankX``
**Attribute:** ``/config/gpio-sim/gpio-device/gpio-bankX/chip_name``
**Attribute:** ``/config/gpio-sim/gpio-device/gpio-bankX/num_lines``
This group represents a bank of GPIOs under the top platform device. The
``'chip_name'`` attribute is read-only and allows the user-space to read the
device name of the bank device. The ``'num_lines'`` attribute allows to specify
the number of lines exposed by this bank.
**Group:** ``/config/gpio-sim/gpio-device/gpio-bankX/lineY``
**Attribute:** ``/config/gpio-sim/gpio-device/gpio-bankX/lineY/name``
**Attribute:** ``/config/gpio-sim/gpio-device/gpio-bankX/lineY/valid``
This group represents a single line at the offset Y. The ``valid`` attribute
indicates whether the line can be used as GPIO. The ``name`` attribute allows
to set the line name as represented by the 'gpio-line-names' property.
**Item:** ``/config/gpio-sim/gpio-device/gpio-bankX/lineY/hog``
**Attribute:** ``/config/gpio-sim/gpio-device/gpio-bankX/lineY/hog/name``
**Attribute:** ``/config/gpio-sim/gpio-device/gpio-bankX/lineY/hog/direction``
This item makes the gpio-sim module hog the associated line. The ``'name'``
attribute specifies the in-kernel consumer name to use. The ``'direction'``
attribute specifies the hog direction and must be one of: ``'input'``,
``'output-high'`` and ``'output-low'``.
Inside each bank directory, there's a set of attributes that can be used to
configure the new chip. Additionally the user can ``mkdir()`` subdirectories
inside the chip's directory that allow to pass additional configuration for
specific lines. The name of those subdirectories must take the form of:
``'line<offset>'`` (e.g. ``'line0'``, ``'line20'``, etc.) as the name will be
used by the module to assign the config to the specific line at given offset.
Once the configuration is complete, the ``'live'`` attribute must be set to 1 in
order to instantiate the chip. It can be set back to 0 to destroy the simulated
chip. The module will synchronously wait for the new simulated device to be
successfully probed and if this doesn't happen, writing to ``'live'`` will
result in an error.
Simulated GPIO chips can also be defined in device-tree. The compatible string
must be: ``"gpio-simulator"``. Supported properties are:
``"gpio-sim,label"`` - chip label
Other standard GPIO properties (like ``"gpio-line-names"``, ``"ngpios"`` or
``"gpio-hog"``) are also supported. Please refer to the GPIO documentation for
details.
An example device-tree code defining a GPIO simulator:
.. code-block :: none
gpio-sim {
compatible = "gpio-simulator";
bank0 {
gpio-controller;
#gpio-cells = <2>;
ngpios = <16>;
gpio-sim,label = "dt-bank0";
gpio-line-names = "", "sim-foo", "", "sim-bar";
};
bank1 {
gpio-controller;
#gpio-cells = <2>;
ngpios = <8>;
gpio-sim,label = "dt-bank1";
line3 {
gpio-hog;
gpios = <3 0>;
output-high;
line-name = "sim-hog-from-dt";
};
};
};
Manipulating simulated lines
----------------------------
Each simulated GPIO chip creates a separate sysfs group under its device
directory for each exposed line
(e.g. ``/sys/devices/platform/gpio-sim.X/gpiochipY/``). The name of each group
is of the form: ``'sim_gpioX'`` where X is the offset of the line. Inside each
group there are two attributes:
``pull`` - allows to read and set the current simulated pull setting for
every line, when writing the value must be one of: ``'pull-up'``,
``'pull-down'``
``value`` - allows to read the current value of the line which may be
different from the pull if the line is being driven from
user-space
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Configfs GPIO Simulator 개요
1-10Configfs GPIO Simulator인 `gpio-sim`은 시험용 가상 GPIO chip을 만듭니다. 노출된 line은 표준 GPIO character device interface로 접근하고 sysfs attribute로 조작할 수 있습니다.
Configfs에서 가상 chip 구성
11-81`gpio-sim` 모듈은 `gpio-sim`이라는 configfs subsystem을 등록합니다. 사용자는 configfs group과 item의 계층을 만들고 공개 attribute 값을 수정할 수 있습니다. chip을 instantiate하면 이 계층이 알맞은 device property로 변환됩니다.
| configfs 경로 | 설명 |
|---|---|
| /config/gpio-sim | gpio-sim configfs tree의 최상위 디렉터리입니다. |
| /config/gpio-sim/gpio-device | GPIO platform device 하나를 나타내는 디렉터리입니다. |
| /config/gpio-sim/gpio-device/dev_name | 읽기 전용. `gpio-sim.0` 같은 platform device name을 보여 줍니다. |
| /config/gpio-sim/gpio-device/live | 구성이 끝난 device를 실제로 만들거나 제거합니다. 1은 활성화, 0은 비활성화와 제거입니다. |
| /config/gpio-sim/gpio-device/gpio-bankX | 최상위 platform device 아래의 GPIO bank를 나타냅니다. |
| /config/gpio-sim/gpio-device/gpio-bankX/chip_name | 읽기 전용. bank device name을 보여 줍니다. |
| /config/gpio-sim/gpio-device/gpio-bankX/num_lines | bank가 노출할 line 수를 지정합니다. |
| /config/gpio-sim/gpio-device/gpio-bankX/lineY | offset Y의 line 하나를 나타냅니다. |
| /config/gpio-sim/gpio-device/gpio-bankX/lineY/name | `gpio-line-names` property에 표시할 line name을 설정합니다. |
| /config/gpio-sim/gpio-device/gpio-bankX/lineY/valid | 해당 line을 GPIO로 사용할 수 있는지 표시합니다. |
| /config/gpio-sim/gpio-device/gpio-bankX/lineY/hog | gpio-sim 모듈이 해당 line을 hog하도록 하는 item입니다. |
| /config/gpio-sim/gpio-device/gpio-bankX/lineY/hog/name | 커널 안에서 사용할 consumer name을 지정합니다. |
| /config/gpio-sim/gpio-device/gpio-bankX/lineY/hog/direction | hog 방향을 `input`, `output-high`, `output-low` 중 하나로 지정합니다. |
각 bank 디렉터리에는 새 chip을 구성할 attribute가 있습니다. 특정 line의 추가 구성은 chip 디렉터리 아래에 `mkdir()`로 `line<offset>`, 예를 들어 `line0`이나 `line20` 이름의 하위 디렉터리를 만들어 전달합니다. 모듈은 이름의 offset으로 구성을 적용할 line을 고릅니다.
구성이 끝나면 `live`를 1로 설정해 chip을 만들고 0으로 되돌려 제거합니다. 모듈은 새 가상 장치 probe가 성공할 때까지 동기적으로 기다리며 실패하면 `live` 쓰기가 오류를 반환합니다.
Device Tree에서 GPIO simulator 정의
82-121가상 GPIO chip은 device tree에서도 정의할 수 있습니다. compatible 문자열은 반드시 `gpio-simulator`여야 합니다. `gpio-sim,label`은 chip label이며 `gpio-line-names`, `ngpios`, `gpio-hog` 같은 표준 GPIO property도 지원합니다.
GPIO simulator를 정의하는 device tree 예입니다.
gpio-sim {
compatible = "gpio-simulator";
bank0 {
gpio-controller;
#gpio-cells = <2>;
ngpios = <16>;
gpio-sim,label = "dt-bank0";
gpio-line-names = "", "sim-foo", "", "sim-bar";
};
bank1 {
gpio-controller;
#gpio-cells = <2>;
ngpios = <8>;
gpio-sim,label = "dt-bank1";
line3 {
gpio-hog;
gpios = <3 0>;
output-high;
line-name = "sim-hog-from-dt";
};
};
};
가상 line 조작
122-137각 가상 GPIO chip은 device 디렉터리, 예를 들어 `/sys/devices/platform/gpio-sim.X/gpiochipY/` 아래에 노출한 line마다 별도 sysfs group을 만듭니다. group 이름은 line offset X를 사용한 `sim_gpioX` 형식입니다.
| attribute | 설명 |
|---|---|
| pull | 각 line의 현재 가상 pull 설정을 읽고 바꿉니다. 쓸 수 있는 값은 `pull-up`과 `pull-down`입니다. |
| value | line의 현재 값을 읽습니다. 사용자 공간이 line을 구동하면 pull 값과 다를 수 있습니다. |
Configfs device와 bank
gpio-sim.rst:1-81platform device, GPIO bank, line, hog의 configfs group과 attribute를 구성하고 `live`로 수명주기를 제어합니다.