← Documents Documentation/w1/masters/w1-gpio.rst GitHub 원문 ↗

Linux 6.18.37 · 1-Wire / Master

Kernel driver w1-gpio

GPIO descriptor와 platform device를 사용한 1-Wire master 구성을 설명합니다.

Source pathDocumentation/w1/masters/w1-gpio.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약·해설

w1-gpio.rst:1-47

GPIO descriptor와 platform device를 사용한 1-Wire master 구성을 설명합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 =====================
2 Kernel driver w1-gpio
3 =====================
4
5 Author: Ville Syrjala <syrjala@sci.fi>
6
7
8 Description
9 -----------
10
11 GPIO 1-wire bus master driver. The driver uses the GPIO API to control the
12 wire and the GPIO pin can be specified using GPIO machine descriptor tables.
13 It is also possible to define the master using device tree, see
14 Documentation/devicetree/bindings/w1/w1-gpio.yaml
15
16
17 Example (mach-at91)
18 -------------------
19
20 ::
21
22 #include <linux/gpio/machine.h>
23 #include <linux/w1-gpio.h>
24
25 static struct gpiod_lookup_table foo_w1_gpiod_table = {
26 .dev_id = "w1-gpio",
27 .table = {
28 GPIO_LOOKUP_IDX("at91-gpio", AT91_PIN_PB20, NULL, 0,
29 GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN),
30 },
31 };
32
33 static struct w1_gpio_platform_data foo_w1_gpio_pdata = {
34 .ext_pullup_enable_pin = -EINVAL,
35 };
36
37 static struct platform_device foo_w1_device = {
38 .name = "w1-gpio",
39 .id = -1,
40 .dev.platform_data = &foo_w1_gpio_pdata,
41 };
42
43 ...
44 at91_set_GPIO_periph(foo_w1_gpio_pdata.pin, 1);
45 at91_set_multi_drive(foo_w1_gpio_pdata.pin, 1);
46 gpiod_add_lookup_table(&foo_w1_gpiod_table);
47 platform_device_register(&foo_w1_device);
48

3. 한국어 전문 번역

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

GPIO 1-Wire master

1-15

`w1-gpio`는 GPIO API로 single wire를 제어하는 1-Wire bus master driver이며 원 저자는 Ville Syrjala입니다.

GPIO pin은 machine descriptor table로 지정할 수 있고 device tree로도 master를 정의할 수 있습니다.

Device tree binding은 `Documentation/devicetree/bindings/w1/w1-gpio.yaml`을 참조합니다.

w1-gpio 구성
방식설정 위치참조
Machine descriptorgpiod_lookup_tablelinux/gpio/machine.h
Platform dataw1_gpio_platform_datalinux/w1-gpio.h
Device treew1-gpio nodew1-gpio.yaml

GPIO lookup과 DT 두 방식입니다.

=====================
Kernel driver w1-gpio
=====================

Author: Ville Syrjala <syrjala@sci.fi>


Description
-----------

GPIO 1-wire bus master driver. The driver uses the GPIO API to control the
wire and the GPIO pin can be specified using GPIO machine descriptor tables.
It is also possible to define the master using device tree, see
Documentation/devicetree/bindings/w1/w1-gpio.yaml

mach-at91 descriptor 예제

16-47

예제는 `foo_w1_gpiod_table`의 device ID를 `w1-gpio`로 두고 AT91 GPIO controller의 `AT91_PIN_PB20`을 index 0에 매핑합니다.

GPIO flag는 `GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN`으로 1-Wire에 필요한 open-drain 동작을 지정합니다.

`foo_w1_gpio_platform_data`는 external pull-up enable pin을 `-EINVAL`로 둡니다.

Platform device 이름은 `w1-gpio`, ID는 -1이며 platform data를 연결합니다.

초기화는 GPIO peripheral과 multi-drive를 활성화하고 lookup table을 등록한 뒤 platform device를 등록합니다. 원문 C code와 symbol은 해당 줄에 그대로 보존됩니다.

AT91 w1-gpio symbol
Symbol역할
foo_w1_gpiod_tablePB20 GPIO descriptor lookup
GPIO_OPEN_DRAIN1-Wire open-drain line
foo_w1_gpio_pdataExternal pull-up data
foo_w1_devicew1-gpio platform device
gpiod_add_lookup_tableDescriptor table 등록
platform_device_registerMaster driver probe 유도

예제 구조체와 호출 책임입니다.

AT91 master 등록
PB20을 GPIO peripheral로 설정Multi-drive/open-drain 활성화gpiod lookup table 등록w1-gpio platform device 등록W1 master bus 생성

GPIO electrical mode부터 platform device까지의 순서입니다.


Example (mach-at91)
-------------------

::

  #include <linux/gpio/machine.h>
  #include <linux/w1-gpio.h>

  static struct gpiod_lookup_table foo_w1_gpiod_table = {
        .dev_id = "w1-gpio",
        .table = {
                GPIO_LOOKUP_IDX("at91-gpio", AT91_PIN_PB20, NULL, 0,
                        GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN),
        },
  };

  static struct w1_gpio_platform_data foo_w1_gpio_pdata = {
        .ext_pullup_enable_pin        = -EINVAL,
  };

  static struct platform_device foo_w1_device = {
        .name                        = "w1-gpio",
        .id                        = -1,
        .dev.platform_data        = &foo_w1_gpio_pdata,
  };

  ...
        at91_set_GPIO_periph(foo_w1_gpio_pdata.pin, 1);
        at91_set_multi_drive(foo_w1_gpio_pdata.pin, 1);
        gpiod_add_lookup_table(&foo_w1_gpiod_table);
        platform_device_register(&foo_w1_device);