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

Linux 6.18.37 · 1-Wire / Core

Introduction to the 1-wire (w1) subsystem

W1 master·slave 모델, 검색 트랜잭션, family와 공통 sysfs 인터페이스를 설명합니다.

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

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

1. 요약·해설

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

요약·해설

w1-generic.rst:1-133

W1 master·slave 모델, 검색 트랜잭션, family와 공통 sysfs 인터페이스를 설명합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 =========================================
2 Introduction to the 1-wire (w1) subsystem
3 =========================================
4
5 The 1-wire bus is a simple master-slave bus that communicates via a single
6 signal wire (plus ground, so two wires).
7
8 Devices communicate on the bus by pulling the signal to ground via an open
9 drain output and by sampling the logic level of the signal line.
10
11 The w1 subsystem provides the framework for managing w1 masters and
12 communication with slaves.
13
14 All w1 slave devices must be connected to a w1 bus master device.
15
16 Example w1 master devices:
17
18 - DS9490 usb device
19 - W1-over-GPIO
20 - DS2482 (i2c to w1 bridge)
21 - Emulated devices, such as a RS232 converter, parallel port adapter, etc
22
23
24 What does the w1 subsystem do?
25 ------------------------------
26
27 When a w1 master driver registers with the w1 subsystem, the following occurs:
28
29 - sysfs entries for that w1 master are created
30 - the w1 bus is periodically searched for new slave devices
31
32 When a device is found on the bus, w1 core tries to load the driver for its family
33 and check if it is loaded. If so, the family driver is attached to the slave.
34 If there is no driver for the family, default one is assigned, which allows to perform
35 almost any kind of operations. Each logical operation is a transaction
36 in nature, which can contain several (two or one) low-level operations.
37 Let's see how one can read EEPROM context:
38 1. one must write control buffer, i.e. buffer containing command byte
39 and two byte address. At this step bus is reset and appropriate device
40 is selected using either W1_SKIP_ROM or W1_MATCH_ROM command.
41 Then provided control buffer is being written to the wire.
42 2. reading. This will issue reading eeprom response.
43
44 It is possible that between 1. and 2. w1 master thread will reset bus for searching
45 and slave device will be even removed, but in this case 0xff will
46 be read, since no device was selected.
47
48
49 W1 device families
50 ------------------
51
52 Slave devices are handled by a driver written for a family of w1 devices.
53
54 A family driver populates a struct w1_family_ops (see w1_family.h) and
55 registers with the w1 subsystem.
56
57 Current family drivers:
58
59 w1_therm
60 - (ds18?20 thermal sensor family driver)
61 provides temperature reading function which is bound to ->rbin() method
62 of the above w1_family_ops structure.
63
64 w1_smem
65 - driver for simple 64bit memory cell provides ID reading method.
66
67 You can call above methods by reading appropriate sysfs files.
68
69
70 What does a w1 master driver need to implement?
71 -----------------------------------------------
72
73 The driver for w1 bus master must provide at minimum two functions.
74
75 Emulated devices must provide the ability to set the output signal level
76 (write_bit) and sample the signal level (read_bit).
77
78 Devices that support the 1-wire natively must provide the ability to write and
79 sample a bit (touch_bit) and reset the bus (reset_bus).
80
81 Most hardware provides higher-level functions that offload w1 handling.
82 See struct w1_bus_master definition in w1.h for details.
83
84
85 w1 master sysfs interface
86 -------------------------
87
88 ========================= =====================================================
89 <xx-xxxxxxxxxxxx> A directory for a found device. The format is
90 family-serial
91 bus (standard) symlink to the w1 bus
92 driver (standard) symlink to the w1 driver
93 w1_master_add (rw) manually register a slave device
94 w1_master_attempts (ro) the number of times a search was attempted
95 w1_master_max_slave_count (rw) maximum number of slaves to search for at a time
96 w1_master_name (ro) the name of the device (w1_bus_masterX)
97 w1_master_pullup (rw) 5V strong pullup 0 enabled, 1 disabled
98 w1_master_remove (rw) manually remove a slave device
99 w1_master_search (rw) the number of searches left to do,
100 -1=continual (default)
101 w1_master_slave_count (ro) the number of slaves found
102 w1_master_slaves (ro) the names of the slaves, one per line
103 w1_master_timeout (ro) the delay in seconds between searches
104 w1_master_timeout_us (ro) the delay in microseconds between searches
105 ========================= =====================================================
106
107 If you have a w1 bus that never changes (you don't add or remove devices),
108 you can set the module parameter search_count to a small positive number
109 for an initially small number of bus searches. Alternatively it could be
110 set to zero, then manually add the slave device serial numbers by
111 w1_master_add device file. The w1_master_add and w1_master_remove files
112 generally only make sense when searching is disabled, as a search will
113 redetect manually removed devices that are present and timeout manually
114 added devices that aren't on the bus.
115
116 Bus searches occur at an interval, specified as a sum of timeout and
117 timeout_us module parameters (either of which may be 0) for as long as
118 w1_master_search remains greater than 0 or is -1. Each search attempt
119 decrements w1_master_search by 1 (down to 0) and increments
120 w1_master_attempts by 1.
121
122 w1 slave sysfs interface
123 ------------------------
124
125 =================== ============================================================
126 bus (standard) symlink to the w1 bus
127 driver (standard) symlink to the w1 driver
128 name the device name, usually the same as the directory name
129 w1_slave (optional) a binary file whose meaning depends on the
130 family driver
131 rw (optional) created for slave devices which do not have
132 appropriate family driver. Allows to read/write binary data.
133 =================== ============================================================
134

3. 한국어 전문 번역

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

단일 신호선의 master-slave 버스

1-23

1-Wire 버스는 신호선 하나와 접지, 총 두 선으로 통신하는 단순한 master-slave 버스입니다. 장치는 오픈 드레인 출력으로 신호선을 접지에 끌어내리고 신호선의 논리 레벨을 샘플링해 통신합니다.

Linux `w1` 서브시스템은 W1 master를 관리하고 slave와 통신하기 위한 공통 프레임워크를 제공합니다. 모든 W1 slave는 반드시 W1 bus master 장치에 연결되어야 합니다.

대표 master는 DS9490 USB 장치, GPIO 기반 W1, I2C-to-W1 브리지 DS2482, RS232 변환기나 병렬 포트 어댑터 같은 에뮬레이션 장치입니다.

W1 master 예
유형연결 방식
DS9490USB
W1-over-GPIOGPIO bit-bang
DS2482I2C-to-W1
RS232 converter에뮬레이션
Parallel port adapter에뮬레이션

원문에 제시된 물리·에뮬레이션 master 유형입니다.

=========================================
Introduction to the 1-wire (w1) subsystem
=========================================

The 1-wire bus is a simple master-slave bus that communicates via a single
signal wire (plus ground, so two wires).

Devices communicate on the bus by pulling the signal to ground via an open
drain output and by sampling the logic level of the signal line.

The w1 subsystem provides the framework for managing w1 masters and
communication with slaves.

All w1 slave devices must be connected to a w1 bus master device.

Example w1 master devices:

    - DS9490 usb device
    - W1-over-GPIO
    - DS2482 (i2c to w1 bridge)
    - Emulated devices, such as a RS232 converter, parallel port adapter, etc

master 등록·검색과 논리 트랜잭션

24-48

W1 master 드라이버가 서브시스템에 등록되면 해당 master의 sysfs 항목을 만들고 새 slave를 찾기 위해 버스를 주기적으로 검색합니다.

장치를 찾으면 W1 core는 family 드라이버를 불러와 로드 여부를 확인한 뒤 slave에 연결합니다. family 드라이버가 없으면 거의 모든 종류의 작업을 수행할 수 있는 기본 드라이버를 배정합니다.

논리 작업 하나는 하나 또는 두 개 이상의 저수준 동작으로 이루어진 트랜잭션입니다. EEPROM 읽기는 먼저 명령 바이트와 2바이트 주소를 담은 제어 버퍼를 씁니다. 이때 버스를 reset하고 `W1_SKIP_ROM` 또는 `W1_MATCH_ROM`으로 장치를 선택한 다음 버퍼를 전송합니다. 이어서 EEPROM 응답을 읽습니다.

두 단계 사이에 master 검색 스레드가 버스를 reset하거나 slave가 제거될 수 있습니다. 그러면 선택된 장치가 없으므로 읽기 결과는 `0xff`가 됩니다.

EEPROM 읽기 트랜잭션
버스 resetW1_SKIP_ROM 또는 W1_MATCH_ROM으로 장치 선택명령 바이트 + 2바이트 주소 쓰기EEPROM 응답 읽기중간 reset·제거 시 0xff 읽기

장치 선택과 응답 읽기가 분리되어 생기는 경쟁 조건을 보여 줍니다.

What does the w1 subsystem do?
------------------------------

When a w1 master driver registers with the w1 subsystem, the following occurs:

 - sysfs entries for that w1 master are created
 - the w1 bus is periodically searched for new slave devices

When a device is found on the bus, w1 core tries to load the driver for its family
and check if it is loaded. If so, the family driver is attached to the slave.
If there is no driver for the family, default one is assigned, which allows to perform
almost any kind of operations. Each logical operation is a transaction
in nature, which can contain several (two or one) low-level operations.
Let's see how one can read EEPROM context:
1. one must write control buffer, i.e. buffer containing command byte
and two byte address. At this step bus is reset and appropriate device
is selected using either W1_SKIP_ROM or W1_MATCH_ROM command.
Then provided control buffer is being written to the wire.
2. reading. This will issue reading eeprom response.

It is possible that between 1. and 2. w1 master thread will reset bus for searching
and slave device will be even removed, but in this case 0xff will
be read, since no device was selected.

W1 family 드라이버

49-69

Slave는 W1 장치 family별 드라이버가 처리합니다. family 드라이버는 `w1_family.h`의 `struct w1_family_ops`를 채워 W1 서브시스템에 등록합니다.

`w1_therm`은 DS18x20 온도 센서 family 드라이버이며 온도 읽기 기능을 `w1_family_ops`의 `rbin()` 메서드에 연결합니다. `w1_smem`은 단순한 64비트 메모리 셀을 위한 드라이버로 ID 읽기 메서드를 제공합니다.

사용자 공간은 해당 sysfs 파일을 읽어 family 메서드를 호출합니다.

현재 family 예
드라이버장치기능
w1_thermDS18x20 온도 센서온도 읽기 / rbin()
w1_smem64비트 메모리 셀ID 읽기

문서가 설명하는 family 드라이버와 메서드입니다.

W1 device families
------------------

Slave devices are handled by a driver written for a family of w1 devices.

A family driver populates a struct w1_family_ops (see w1_family.h) and
registers with the w1 subsystem.

Current family drivers:

w1_therm
  - (ds18?20 thermal sensor family driver)
    provides temperature reading function which is bound to ->rbin() method
    of the above w1_family_ops structure.

w1_smem
  - driver for simple 64bit memory cell provides ID reading method.

You can call above methods by reading appropriate sysfs files.

master 드라이버의 최소 구현

70-84

W1 bus master 드라이버는 최소 두 함수를 제공해야 합니다. 에뮬레이션 장치는 출력 신호 레벨을 설정하는 `write_bit`와 신호 레벨을 샘플링하는 `read_bit`를 구현합니다.

1-Wire를 네이티브로 지원하는 장치는 비트를 쓰고 샘플링하는 `touch_bit`와 버스를 reset하는 `reset_bus`를 구현합니다.

대부분의 하드웨어는 W1 처리를 덜어 주는 상위 수준 함수도 제공합니다. 자세한 콜백은 `w1.h`의 `struct w1_bus_master` 정의를 참조합니다.

master 구현 방식
master 유형필수 콜백
에뮬레이션write_bit, read_bit
네이티브 1-Wiretouch_bit, reset_bus

하드웨어 유형별 최소 콜백입니다.

What does a w1 master driver need to implement?
-----------------------------------------------

The driver for w1 bus master must provide at minimum two functions.

Emulated devices must provide the ability to set the output signal level
(write_bit) and sample the signal level (read_bit).

Devices that support the 1-wire natively must provide the ability to write and
sample a bit (touch_bit) and reset the bus (reset_bus).

Most hardware provides higher-level functions that offload w1 handling.
See struct w1_bus_master definition in w1.h for details.

W1 master sysfs

85-121

발견한 slave는 `family-serial` 형식의 `<xx-xxxxxxxxxxxx>` 디렉터리로 나타납니다. 표준 `bus`와 `driver` 심볼릭 링크도 제공합니다.

`w1_master_add`와 `w1_master_remove`는 slave를 수동으로 등록·제거합니다. `w1_master_attempts`는 검색 시도 횟수, `w1_master_max_slave_count`는 한 번에 찾을 최대 slave 수, `w1_master_slave_count`는 발견한 수, `w1_master_slaves`는 이름 목록입니다.

`w1_master_search`는 남은 검색 횟수이며 `-1`은 계속 검색하는 기본값입니다. `w1_master_timeout`과 `w1_master_timeout_us`는 각각 초와 마이크로초 검색 간격이고 `w1_master_pullup`은 5V strong pull-up 상태를 다룹니다. 원문 표의 값 정의는 0이 활성화, 1이 비활성화입니다.

버스 구성이 고정되어 있으면 `search_count`를 작은 양수로 두어 초기 검색만 하거나 0으로 두고 `w1_master_add`에 slave serial을 직접 쓸 수 있습니다. 검색이 켜져 있으면 수동 제거 장치를 다시 찾고 실제로 없는 수동 추가 장치는 timeout되므로 add/remove는 보통 검색을 끈 상태에서만 의미가 있습니다.

검색 간격은 `timeout + timeout_us`이고 두 값 중 하나는 0이어도 됩니다. `w1_master_search`가 0보다 크거나 -1인 동안 검색하며 각 시도는 search를 1 줄이고 attempts를 1 늘립니다.

W1 master 주요 sysfs
항목접근의미
w1_master_addrwslave 수동 등록
w1_master_removerwslave 수동 제거
w1_master_searchrw남은 검색 횟수, -1은 계속
w1_master_attemptsro검색 시도 누계
w1_master_max_slave_countrw검색당 최대 slave
w1_master_slave_countro발견한 slave 수
w1_master_slavesroslave 이름 목록
w1_master_timeoutro초 단위 검색 지연
w1_master_timeout_usro마이크로초 단위 검색 지연

검색·수동 관리·상태 조회 항목입니다.

w1 master sysfs interface
-------------------------

========================= =====================================================
<xx-xxxxxxxxxxxx>         A directory for a found device. The format is
                          family-serial
bus                       (standard) symlink to the w1 bus
driver                    (standard) symlink to the w1 driver
w1_master_add             (rw) manually register a slave device
w1_master_attempts        (ro) the number of times a search was attempted
w1_master_max_slave_count (rw) maximum number of slaves to search for at a time
w1_master_name            (ro) the name of the device (w1_bus_masterX)
w1_master_pullup          (rw) 5V strong pullup 0 enabled, 1 disabled
w1_master_remove          (rw) manually remove a slave device
w1_master_search          (rw) the number of searches left to do,
                          -1=continual (default)
w1_master_slave_count     (ro) the number of slaves found
w1_master_slaves          (ro) the names of the slaves, one per line
w1_master_timeout         (ro) the delay in seconds between searches
w1_master_timeout_us      (ro) the delay in microseconds between searches
========================= =====================================================

If you have a w1 bus that never changes (you don't add or remove devices),
you can set the module parameter search_count to a small positive number
for an initially small number of bus searches.  Alternatively it could be
set to zero, then manually add the slave device serial numbers by
w1_master_add device file.  The w1_master_add and w1_master_remove files
generally only make sense when searching is disabled, as a search will
redetect manually removed devices that are present and timeout manually
added devices that aren't on the bus.

Bus searches occur at an interval, specified as a sum of timeout and
timeout_us module parameters (either of which may be 0) for as long as
w1_master_search remains greater than 0 or is -1.  Each search attempt
decrements w1_master_search by 1 (down to 0) and increments
w1_master_attempts by 1.

W1 slave sysfs

122-133

Slave에는 표준 `bus`·`driver` 심볼릭 링크와 보통 디렉터리 이름과 같은 `name`이 있습니다.

선택적인 `w1_slave`는 family 드라이버가 의미를 정하는 바이너리 파일입니다. 적절한 family 드라이버가 없는 slave에는 선택적인 `rw` 파일을 만들어 바이너리 데이터를 읽고 쓸 수 있게 합니다.

W1 slave sysfs
항목종류설명
bus표준W1 bus 링크
driver표준W1 driver 링크
name공통장치 이름
w1_slave선택family별 바이너리 파일
rw선택family 드라이버가 없을 때 바이너리 I/O

slave 공통·선택 항목입니다.

w1 slave sysfs interface
------------------------

=================== ============================================================
bus                 (standard) symlink to the w1 bus
driver              (standard) symlink to the w1 driver
name                the device name, usually the same as the directory name
w1_slave            (optional) a binary file whose meaning depends on the
                    family driver
rw                    (optional) created for slave devices which do not have
                    appropriate family driver. Allows to read/write binary data.
=================== ============================================================