← Documents Documentation/hid/hid-sensor.rst GitHub 원문 ↗

Linux 6.18.37 · HID

HID Sensors Framework

HID sensor hub의 descriptor parsing, sensor별 driver, core API와 custom sensor userspace interface를 설명합니다.

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

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

1. 요약·해설

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

요약·해설

hid-sensor.rst:1-242

HID Sensors Framework는 sensor hub의 report descriptor에서 usage와 field layout을 읽고, usage별 MFD device와 processing driver를 연결합니다. 표준 sensor는 IIO ABI를 활용하고 custom·generic sensor는 sysfs와 misc FIFO로 userspace에 공개됩니다.

문서 위치
항목
SourceDocumentation/hid/hid-sensor.rst
분량242 source lines
Core driverhid-sensor-hub
Device namingHID-SENSOR-xxxx
UserspaceIIO 또는 sysfs · misc device

Source와 핵심 interface입니다.

Framework 전체 경로
Sensor hub report descriptor parseUsage별 HID-SENSOR-xxxx MFD device 생성개별 processing driver probeField index cache·callback 등록IIO event 또는 custom sensor FIFO 공개

Descriptor에서 userspace sample까지의 큰 흐름입니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 =====================
2 HID Sensors Framework
3 =====================
4 HID sensor framework provides necessary interfaces to implement sensor drivers,
5 which are connected to a sensor hub. The sensor hub is a HID device and it provides
6 a report descriptor conforming to HID 1.12 sensor usage tables.
7
8 Description from the HID 1.12 "HID Sensor Usages" specification:
9 "Standardization of HID usages for sensors would allow (but not require) sensor
10 hardware vendors to provide a consistent Plug And Play interface at the USB boundary,
11 thereby enabling some operating systems to incorporate common device drivers that
12 could be reused between vendors, alleviating any need for the vendors to provide
13 the drivers themselves."
14
15 This specification describes many usage IDs, which describe the type of sensor
16 and also the individual data fields. Each sensor can have variable number of
17 data fields. The length and order is specified in the report descriptor. For
18 example a part of report descriptor can look like::
19
20 INPUT(1)[INPUT]
21 ..
22 Field(2)
23 Physical(0020.0073)
24 Usage(1)
25 0020.045f
26 Logical Minimum(-32767)
27 Logical Maximum(32767)
28 Report Size(8)
29 Report Count(1)
30 Report Offset(16)
31 Flags(Variable Absolute)
32 ..
33 ..
34
35 The report is indicating "sensor page (0x20)" contains an accelerometer-3D (0x73).
36 This accelerometer-3D has some fields. Here for example field 2 is motion intensity
37 (0x045f) with a logical minimum value of -32767 and logical maximum of 32767. The
38 order of fields and length of each field is important as the input event raw
39 data will use this format.
40
41
42 Implementation
43 ==============
44
45 This specification defines many different types of sensors with different sets of
46 data fields. It is difficult to have a common input event to user space applications,
47 for different sensors. For example an accelerometer can send X,Y and Z data, whereas
48 an ambient light sensor can send illumination data.
49 So the implementation has two parts:
50
51 - Core HID driver
52 - Individual sensor processing part (sensor drivers)
53
54 Core driver
55 -----------
56 The core driver (hid-sensor-hub) registers as a HID driver. It parses
57 report descriptors and identifies all the sensors present. It adds an MFD device
58 with name HID-SENSOR-xxxx (where xxxx is usage id from the specification).
59
60 For example:
61
62 HID-SENSOR-200073 is registered for an Accelerometer 3D driver.
63
64 So if any driver with this name is inserted, then the probe routine for that
65 function will be called. So an accelerometer processing driver can register
66 with this name and will be probed if there is an accelerometer-3D detected.
67
68 The core driver provides a set of APIs which can be used by the processing
69 drivers to register and get events for that usage id. Also it provides parsing
70 functions, which get and set each input/feature/output report.
71
72 Individual sensor processing part (sensor drivers)
73 --------------------------------------------------
74
75 The processing driver will use an interface provided by the core driver to parse
76 the report and get the indexes of the fields and also can get events. This driver
77 can use IIO interface to use the standard ABI defined for a type of sensor.
78
79
80 Core driver Interface
81 =====================
82
83 Callback structure::
84
85 Each processing driver can use this structure to set some callbacks.
86 int (*suspend)(..): Callback when HID suspend is received
87 int (*resume)(..): Callback when HID resume is received
88 int (*capture_sample)(..): Capture a sample for one of its data fields
89 int (*send_event)(..): One complete event is received which can have
90 multiple data fields.
91
92 Registration functions::
93
94 int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
95 u32 usage_id,
96 struct hid_sensor_hub_callbacks *usage_callback):
97
98 Registers callbacks for a usage id. The callback functions are not allowed
99 to sleep::
100
101
102 int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
103 u32 usage_id):
104
105 Removes callbacks for a usage id.
106
107
108 Parsing function::
109
110 int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
111 u8 type,
112 u32 usage_id, u32 attr_usage_id,
113 struct hid_sensor_hub_attribute_info *info);
114
115 A processing driver can look for some field of interest and check if it exists
116 in a report descriptor. If it exists it will store necessary information
117 so that fields can be set or get individually.
118 These indexes avoid searching every time and getting field index to get or set.
119
120
121 Set Feature report::
122
123 int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
124 u32 field_index, s32 value);
125
126 This interface is used to set a value for a field in feature report. For example
127 if there is a field report_interval, which is parsed by a call to
128 sensor_hub_input_get_attribute_info before, then it can directly set that
129 individual field::
130
131
132 int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
133 u32 field_index, s32 *value);
134
135 This interface is used to get a value for a field in input report. For example
136 if there is a field report_interval, which is parsed by a call to
137 sensor_hub_input_get_attribute_info before, then it can directly get that
138 individual field value::
139
140
141 int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
142 u32 usage_id,
143 u32 attr_usage_id, u32 report_id);
144
145 This is used to get a particular field value through input reports. For example
146 accelerometer wants to poll X axis value, then it can call this function with
147 the usage id of X axis. HID sensors can provide events, so this is not necessary
148 to poll for any field. If there is some new sample, the core driver will call
149 registered callback function to process the sample.
150
151
152 ----------
153
154 HID Custom and generic Sensors
155 ------------------------------
156
157
158 HID Sensor specification defines two special sensor usage types. Since they
159 don't represent a standard sensor, it is not possible to define using Linux IIO
160 type interfaces.
161 The purpose of these sensors is to extend the functionality or provide a
162 way to obfuscate the data being communicated by a sensor. Without knowing the
163 mapping between the data and its encapsulated form, it is difficult for
164 an application/driver to determine what data is being communicated by the sensor.
165 This allows some differentiating use cases, where vendor can provide applications.
166 Some common use cases are debug other sensors or to provide some events like
167 keyboard attached/detached or lid open/close.
168
169 To allow application to utilize these sensors, here they are exported using sysfs
170 attribute groups, attributes and misc device interface.
171
172 An example of this representation on sysfs::
173
174 /sys/devices/pci0000:00/INT33C2:00/i2c-0/i2c-INT33D1:00/0018:8086:09FA.0001/HID-SENSOR-2000e1.6.auto$ tree -R
175 .
176 │   ├── enable_sensor
177 │   │   ├── feature-0-200316
178 │   │   │   ├── feature-0-200316-maximum
179 │   │   │   ├── feature-0-200316-minimum
180 │   │   │   ├── feature-0-200316-name
181 │   │   │   ├── feature-0-200316-size
182 │   │   │   ├── feature-0-200316-unit-expo
183 │   │   │   ├── feature-0-200316-units
184 │   │   │   ├── feature-0-200316-value
185 │   │   ├── feature-1-200201
186 │   │   │   ├── feature-1-200201-maximum
187 │   │   │   ├── feature-1-200201-minimum
188 │   │   │   ├── feature-1-200201-name
189 │   │   │   ├── feature-1-200201-size
190 │   │   │   ├── feature-1-200201-unit-expo
191 │   │   │   ├── feature-1-200201-units
192 │   │   │   ├── feature-1-200201-value
193 │   │   ├── input-0-200201
194 │   │   │   ├── input-0-200201-maximum
195 │   │   │   ├── input-0-200201-minimum
196 │   │   │   ├── input-0-200201-name
197 │   │   │   ├── input-0-200201-size
198 │   │   │   ├── input-0-200201-unit-expo
199 │   │   │   ├── input-0-200201-units
200 │   │   │   ├── input-0-200201-value
201 │   │   ├── input-1-200202
202 │   │   │   ├── input-1-200202-maximum
203 │   │   │   ├── input-1-200202-minimum
204 │   │   │   ├── input-1-200202-name
205 │   │   │   ├── input-1-200202-size
206 │   │   │   ├── input-1-200202-unit-expo
207 │   │   │   ├── input-1-200202-units
208 │   │   │   ├── input-1-200202-value
209
210 Here there is a custom sensor with four fields: two feature and two inputs.
211 Each field is represented by a set of attributes. All fields except the "value"
212 are read only. The value field is a read-write field.
213
214 Example::
215
216 /sys/bus/platform/devices/HID-SENSOR-2000e1.6.auto/feature-0-200316$ grep -r . *
217 feature-0-200316-maximum:6
218 feature-0-200316-minimum:0
219 feature-0-200316-name:property-reporting-state
220 feature-0-200316-size:1
221 feature-0-200316-unit-expo:0
222 feature-0-200316-units:25
223 feature-0-200316-value:1
224
225 How to enable such sensor?
226 ^^^^^^^^^^^^^^^^^^^^^^^^^^
227
228 By default sensor can be power gated. To enable sysfs attribute "enable" can be
229 used::
230
231 $ echo 1 > enable_sensor
232
233 Once enabled and powered on, sensor can report value using HID reports.
234 These reports are pushed using misc device interface in a FIFO order::
235
236 /dev$ tree | grep HID-SENSOR-2000e1.6.auto
237 │   │   │   ├── 10:53 -> ../HID-SENSOR-2000e1.6.auto
238 │   ├── HID-SENSOR-2000e1.6.auto
239
240 Each report can be of variable length preceded by a header. This header
241 consists of a 32-bit usage id, 64-bit time stamp and 32-bit length field of raw
242 data.
243

3. 한국어 전문 번역

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

HID 센서 framework와 report descriptor

1-39

HID 센서 framework는 sensor hub에 연결된 sensor driver를 구현하는 데 필요한 interface를 제공합니다. Sensor hub 자체는 HID device이며 HID 1.12 sensor usage table을 따르는 report descriptor를 제공합니다.

HID 1.12의 "HID Sensor Usages" 명세는 sensor usage를 표준화하면 hardware vendor가 USB 경계에서 일관된 Plug And Play interface를 제공할 수 있다고 설명합니다. 표준화가 의무는 아니지만, 운영체제는 vendor 사이에서 재사용할 수 있는 공통 device driver를 포함할 수 있으므로 vendor가 driver를 직접 제공해야 할 필요를 줄일 수 있습니다.

명세의 여러 usage ID는 sensor 종류뿐 아니라 개별 data field도 나타냅니다. Sensor마다 field 수가 달라질 수 있고 각 field의 길이와 순서는 report descriptor에 기록됩니다. 원문의 descriptor 일부는 다음과 같습니다.

     INPUT(1)[INPUT]
   ..
      Field(2)
        Physical(0020.0073)
        Usage(1)
          0020.045f
        Logical Minimum(-32767)
        Logical Maximum(32767)
        Report Size(8)
        Report Count(1)
        Report Offset(16)
        Flags(Variable Absolute)
  ..
  ..

이 report는 sensor page `0x20`에 3축 accelerometer `0x73`가 있음을 나타냅니다. 예시의 field 2는 motion intensity `0x045f`이며 logical minimum은 `-32767`, logical maximum은 `32767`입니다.

Input event의 raw data가 이 형식을 그대로 사용하므로 field 순서와 각 field 길이가 중요합니다. `Report Size(8)`, `Report Count(1)`, `Report Offset(16)`은 해당 값의 bit 배치를 결정합니다.

Descriptor field 해석
항목의미
Sensor page0x20HID sensor usage page
Physical usage0020.0073Accelerometer 3D
Field usage0020.045fMotion intensity
Logical range-32767..32767Field value 범위
Report layout8 bits · count 1 · offset 16Raw input 안의 위치

예제 descriptor의 sensor와 field 식별자를 구조화했습니다.

HID sensor data 해석
Sensor hub가 report descriptor 제공Sensor page와 physical usage 식별Field usage·size·count·offset 해석Raw input report에서 field 추출Sensor processing driver에 sample 전달

Descriptor가 raw event를 sensor sample로 바꾸는 순서입니다.

=====================
HID Sensors Framework
=====================
HID sensor framework provides necessary interfaces to implement sensor drivers,
which are connected to a sensor hub. The sensor hub is a HID device and it provides
a report descriptor conforming to HID 1.12 sensor usage tables.

Description from the HID 1.12 "HID Sensor Usages" specification:
"Standardization of HID usages for sensors would allow (but not require) sensor
hardware vendors to provide a consistent Plug And Play interface at the USB boundary,
thereby enabling some operating systems to incorporate common device drivers that
could be reused between vendors, alleviating any need for the vendors to provide
the drivers themselves."

This specification describes many usage IDs, which describe the type of sensor
and also the individual data fields. Each sensor can have variable number of
data fields. The length and order is specified in the report descriptor. For
example a part of report descriptor can look like::

     INPUT(1)[INPUT]
   ..
      Field(2)
        Physical(0020.0073)
        Usage(1)
          0020.045f
        Logical Minimum(-32767)
        Logical Maximum(32767)
        Report Size(8)
        Report Count(1)
        Report Offset(16)
        Flags(Variable Absolute)
  ..
  ..

The report is indicating "sensor page (0x20)" contains an accelerometer-3D (0x73).
This accelerometer-3D has some fields. Here for example field 2 is motion intensity
(0x045f) with a logical minimum value of -32767 and logical maximum of 32767. The
order of fields and length of each field is important as the input event raw
data will use this format.

Core driver와 개별 sensor processing

40-77

HID sensor 명세에는 서로 다른 data field 집합을 가진 많은 sensor 종류가 정의되어 있습니다. Accelerometer는 X, Y, Z data를 보내지만 ambient light sensor는 illumination data를 보내므로, 모든 sensor에 공통인 userspace input event 하나를 만들기 어렵습니다.

따라서 구현은 core HID driver와 개별 sensor processing 부분, 즉 sensor driver의 두 부분으로 나뉩니다.

Core driver인 `hid-sensor-hub`는 HID driver로 등록됩니다. Report descriptor를 parse하여 존재하는 모든 sensor를 식별하고, 명세의 usage ID를 `xxxx`로 사용한 `HID-SENSOR-xxxx` 이름의 MFD device를 추가합니다.

예를 들어 3축 accelerometer에는 `HID-SENSOR-200073`이 등록됩니다. 이 이름의 driver가 삽입되면 해당 기능의 probe routine이 호출됩니다. Accelerometer processing driver가 같은 이름으로 등록되어 있으면 3축 accelerometer가 감지될 때 probe됩니다.

Core driver는 processing driver가 특정 usage ID에 callback을 등록하고 event를 받을 수 있는 API를 제공합니다. 또한 input, feature, output report 각각을 가져오고 설정하는 parsing 함수도 제공합니다.

개별 processing driver는 core interface로 report를 parse하고 필요한 field index를 얻으며 event를 받습니다. Sensor 종류에 대해 정의된 표준 ABI를 사용하려면 IIO interface를 이용할 수 있습니다.

HID sensor 구현 계층
계층책임
hid-sensor-hubDescriptor parse · sensor 발견 · MFD device 등록
HID-SENSOR-xxxxUsage ID를 device 이름에 반영
Processing driverField index 보관 · sample/event 처리
IIOSensor 종류별 표준 userspace ABI 제공

Core와 sensor별 processing driver의 책임을 구분합니다.

Sensor driver probe
hid-sensor-hub가 HID device에 bindReport descriptor에서 usage ID 탐색HID-SENSOR-xxxx MFD device 생성같은 이름의 processing driver와 matchSensor별 probe routine 호출필요하면 IIO device 등록

Descriptor 발견에서 개별 driver의 probe까지 이어지는 경로입니다.



Implementation
==============

This specification defines many different types of sensors with different sets of
data fields. It is difficult to have a common input event to user space applications,
for different sensors. For example an accelerometer can send X,Y and Z data, whereas
an ambient light sensor can send illumination data.
So the implementation has two parts:

- Core HID driver
- Individual sensor processing part (sensor drivers)

Core driver
-----------
The core driver (hid-sensor-hub) registers as a HID driver. It parses
report descriptors and identifies all the sensors present. It adds an MFD device
with name HID-SENSOR-xxxx (where xxxx is usage id from the specification).

For example:

HID-SENSOR-200073 is registered for an Accelerometer 3D driver.

So if any driver with this name is inserted, then the probe routine for that
function will be called. So an accelerometer processing driver can register
with this name and will be probed if there is an accelerometer-3D detected.

The core driver provides a set of APIs which can be used by the processing
drivers to register and get events for that usage id. Also it provides parsing
functions, which get and set each input/feature/output report.

Individual sensor processing part (sensor drivers)
--------------------------------------------------

The processing driver will use an interface provided by the core driver to parse
the report and get the indexes of the fields and also can get events. This driver
can use IIO interface to use the standard ABI defined for a type of sensor.

Callback 구조와 등록 interface

78-105

각 processing driver는 callback 구조체에 `suspend`, `resume`, `capture_sample`, `send_event`를 설정할 수 있습니다.

`suspend`는 HID suspend를 받을 때, `resume`은 HID resume를 받을 때 호출됩니다. `capture_sample`은 sensor의 data field 하나에 대한 sample을 수집하며, `send_event`는 여러 data field를 포함할 수 있는 완전한 event 하나를 받았을 때 호출됩니다.

int (*suspend)(..)
int (*resume)(..)
int (*capture_sample)(..)
int (*send_event)(..)

`sensor_hub_register_callback()`은 `struct hid_sensor_hub_device *hsdev`, `u32 usage_id`, `struct hid_sensor_hub_callbacks *usage_callback`을 받아 usage ID에 callback을 등록합니다. 이 callback 함수들은 sleep하면 안 됩니다.

int sensor_hub_register_callback(
        struct hid_sensor_hub_device *hsdev,
        u32 usage_id,
        struct hid_sensor_hub_callbacks *usage_callback);

`sensor_hub_remove_callback()`은 `hsdev`와 `usage_id`를 받아 해당 usage ID의 callback을 제거합니다.

Processing callback contract
Callback호출 조건
suspendHID suspend 수신
resumeHID resume 수신
capture_sample개별 data field sample 수집
send_event여러 field를 포함할 수 있는 완전한 event 수신
공통 제약Callback 안에서 sleep 금지

Callback의 호출 조건과 제약입니다.

Callback 수명 주기
Processing driver probehid_sensor_hub_callbacks 구성sensor_hub_register_callback 호출Core가 sample·event callback 호출Driver 제거 시 sensor_hub_remove_callback 호출

Processing driver가 usage별 event를 구독하고 해제합니다.



Core driver Interface
=====================

Callback structure::

  Each processing driver can use this structure to set some callbacks.
        int (*suspend)(..): Callback when HID suspend is received
        int (*resume)(..): Callback when HID resume is received
        int (*capture_sample)(..): Capture a sample for one of its data fields
        int (*send_event)(..): One complete event is received which can have
                               multiple data fields.

Registration functions::

  int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
                        u32 usage_id,
                        struct hid_sensor_hub_callbacks *usage_callback):

Registers callbacks for a usage id. The callback functions are not allowed
to sleep::


  int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
                        u32 usage_id):

Removes callbacks for a usage id.

Field parsing, feature report와 raw input

106-149

`sensor_hub_input_get_attribute_info()`는 `hsdev`, report `type`, sensor `usage_id`, field `attr_usage_id`, 결과를 받을 `struct hid_sensor_hub_attribute_info *info`를 인자로 받습니다.

int sensor_hub_input_get_attribute_info(
        struct hid_sensor_hub_device *hsdev,
        u8 type,
        u32 usage_id,
        u32 attr_usage_id,
        struct hid_sensor_hub_attribute_info *info);

Processing driver는 관심 있는 field가 report descriptor에 존재하는지 찾을 수 있습니다. 존재하면 field를 개별적으로 get 또는 set하는 데 필요한 정보를 저장합니다. 이렇게 보관한 index를 사용하면 get/set 때마다 descriptor를 다시 검색해 field index를 찾지 않아도 됩니다.

`sensor_hub_set_feature()`는 `report_id`, `field_index`, `value`를 받아 feature report의 field 값을 설정합니다. 예를 들어 `sensor_hub_input_get_attribute_info()`로 미리 parse한 `report_interval` field를 직접 설정할 수 있습니다.

int sensor_hub_set_feature(
        struct hid_sensor_hub_device *hsdev,
        u32 report_id,
        u32 field_index,
        s32 value);

`sensor_hub_get_feature()`는 `report_id`, `field_index`, `s32 *value`를 받아 field 값을 가져옵니다. 원문은 이를 input report의 field 값을 읽는 interface라고 설명하며, 같은 `report_interval` 예에서 미리 얻은 index로 개별 값을 직접 가져옵니다.

int sensor_hub_get_feature(
        struct hid_sensor_hub_device *hsdev,
        u32 report_id,
        u32 field_index,
        s32 *value);

`sensor_hub_input_attr_get_raw_value()`는 sensor `usage_id`, field `attr_usage_id`, `report_id`를 사용해 input report에서 특정 field의 raw 값을 가져옵니다. Accelerometer가 X axis 값을 poll하려면 X axis의 usage ID로 이 함수를 호출할 수 있습니다.

하지만 HID sensor는 event를 제공할 수 있으므로 모든 field를 poll할 필요는 없습니다. 새 sample이 생기면 core driver가 등록된 callback을 호출하여 sample을 처리하게 합니다.

Core sensor API
API역할
sensor_hub_input_get_attribute_infoField 존재 확인과 index·metadata 획득
sensor_hub_set_featureFeature report의 개별 field 설정
sensor_hub_get_feature미리 parse한 field 값 획득
sensor_hub_input_attr_get_raw_valueInput report의 특정 raw field poll

Descriptor 정보 cache와 report 접근 API를 정리했습니다.

Field 접근 경로
Usage ID와 attr usage ID 선택Attribute info를 한 번 parseReport ID와 field index 저장Feature 값을 get/set하거나 raw input pollEvent 지원 시 callback으로 새 sample 처리

Descriptor parse 결과를 재사용해 sample에 접근합니다.



Parsing function::

  int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
                        u8 type,
                        u32 usage_id, u32 attr_usage_id,
                        struct hid_sensor_hub_attribute_info *info);

A processing driver can look for some field of interest and check if it exists
in a report descriptor. If it exists it will store necessary information
so that fields can be set or get individually.
These indexes avoid searching every time and getting field index to get or set.


Set Feature report::

  int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
                        u32 field_index, s32 value);

This interface is used to set a value for a field in feature report. For example
if there is a field report_interval, which is parsed by a call to
sensor_hub_input_get_attribute_info before, then it can directly set that
individual field::


  int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
                        u32 field_index, s32 *value);

This interface is used to get a value for a field in input report. For example
if there is a field report_interval, which is parsed by a call to
sensor_hub_input_get_attribute_info before, then it can directly get that
individual field value::


  int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
                        u32 usage_id,
                        u32 attr_usage_id, u32 report_id);

This is used to get a particular field value through input reports. For example
accelerometer wants to poll X axis value, then it can call this function with
the usage id of X axis. HID sensors can provide events, so this is not necessary
to poll for any field. If there is some new sample, the core driver will call
registered callback function to process the sample.

Custom·generic sensor의 목적과 공개 방식

150-170

HID Sensor 명세는 두 가지 특별한 sensor usage type을 정의합니다. 이들은 표준 sensor를 나타내지 않으므로 Linux IIO type interface로 정의할 수 없습니다.

이 sensor들은 기능을 확장하거나 sensor가 전달하는 data를 난독화하는 데 사용됩니다. Data와 encapsulated form의 mapping을 모르면 application이나 driver가 어떤 data가 전달되는지 판단하기 어렵습니다.

이 특성은 vendor가 전용 application을 제공하는 차별화된 use case를 가능하게 합니다. 흔한 예는 다른 sensor를 debug하거나 keyboard attach/detach, lid open/close 같은 event를 제공하는 것입니다.

Application이 이러한 sensor를 사용할 수 있도록 kernel은 sysfs attribute group과 attribute, misc device interface로 공개합니다.

Custom·generic sensor 용도
용도설명
기능 확장표준 sensor type 밖의 vendor 기능
Data encapsulationMapping을 알아야 payload 의미 해석 가능
Debug다른 sensor 상태나 진단 data 전달
Platform eventKeyboard 연결·해제, lid 열림·닫힘

표준 IIO sensor와 구분되는 목적을 보여 줍니다.

Application 공개 경로
Custom 또는 generic usage 발견HID-SENSOR-xxxx platform device 생성Sysfs attribute group으로 field metadata 공개Value attribute로 field 접근Misc device FIFO로 HID report 전달

비표준 sensor data를 userspace에 제공하는 계층입니다.



----------

HID Custom and generic Sensors
------------------------------


HID Sensor specification defines two special sensor usage types. Since they
don't represent a standard sensor, it is not possible to define using Linux IIO
type interfaces.
The purpose of these sensors is to extend the functionality or provide a
way to obfuscate the data being communicated by a sensor. Without knowing the
mapping between the data and its encapsulated form, it is difficult for
an application/driver to determine what data is being communicated by the sensor.
This allows some differentiating use cases, where vendor can provide applications.
Some common use cases are debug other sensors or to provide some events like
keyboard attached/detached or lid open/close.

To allow application to utilize these sensors, here they are exported using sysfs
attribute groups, attributes and misc device interface.

Sysfs field 표현과 접근 속성

171-223

다음 sysfs 예시는 `HID-SENSOR-2000e1.6.auto` custom sensor의 field 구조를 보여 줍니다. Sensor에는 feature field 두 개와 input field 두 개가 있습니다.

/sys/devices/pci0000:00/INT33C2:00/i2c-0/i2c-INT33D1:00/0018:8086:09FA.0001/HID-SENSOR-2000e1.6.auto
├── enable_sensor
├── feature-0-200316
│   ├── feature-0-200316-maximum
│   ├── feature-0-200316-minimum
│   ├── feature-0-200316-name
│   ├── feature-0-200316-size
│   ├── feature-0-200316-unit-expo
│   ├── feature-0-200316-units
│   └── feature-0-200316-value
├── feature-1-200201
├── input-0-200201
└── input-1-200202

각 field는 `maximum`, `minimum`, `name`, `size`, `unit-expo`, `units`, `value` 속성 집합으로 표현됩니다. `value`를 제외한 모든 field 속성은 read-only이고 `value` field는 read-write입니다.

예제 `feature-0-200316`은 `property-reporting-state`라는 이름을 가지며 minimum `0`, maximum `6`, size `1`, unit exponent `0`, units `25`, 현재 value `1`을 보고합니다.

/sys/bus/platform/devices/HID-SENSOR-2000e1.6.auto/feature-0-200316$ grep -r . *
feature-0-200316-maximum:6
feature-0-200316-minimum:0
feature-0-200316-name:property-reporting-state
feature-0-200316-size:1
feature-0-200316-unit-expo:0
feature-0-200316-units:25
feature-0-200316-value:1
Custom sensor sysfs 구조
NodeUsage하위 속성
enable_sensor-Sensor power·reporting 활성화
feature-0-2003160x200316maximum · minimum · name · size · unit-expo · units · value
feature-1-2002010x200201maximum · minimum · name · size · unit-expo · units · value
input-0-2002010x200201maximum · minimum · name · size · unit-expo · units · value
input-1-2002020x200202maximum · minimum · name · size · unit-expo · units · value

원문의 directory tree를 field 단위로 정리했습니다.

Sysfs field 읽기·쓰기
HID usage별 feature/input directory 선택Name·range·size·unit metadata 읽기Read-only 속성으로 field 형식 확인value 속성에서 현재 값 읽기필요하면 read-write value에 새 값 쓰기

Field metadata와 value의 access 차이를 나타냅니다.


An example of this representation on sysfs::

  /sys/devices/pci0000:00/INT33C2:00/i2c-0/i2c-INT33D1:00/0018:8086:09FA.0001/HID-SENSOR-2000e1.6.auto$ tree -R
  .
  │   ├──  enable_sensor
  │   │   ├── feature-0-200316
  │   │   │   ├── feature-0-200316-maximum
  │   │   │   ├── feature-0-200316-minimum
  │   │   │   ├── feature-0-200316-name
  │   │   │   ├── feature-0-200316-size
  │   │   │   ├── feature-0-200316-unit-expo
  │   │   │   ├── feature-0-200316-units
  │   │   │   ├── feature-0-200316-value
  │   │   ├── feature-1-200201
  │   │   │   ├── feature-1-200201-maximum
  │   │   │   ├── feature-1-200201-minimum
  │   │   │   ├── feature-1-200201-name
  │   │   │   ├── feature-1-200201-size
  │   │   │   ├── feature-1-200201-unit-expo
  │   │   │   ├── feature-1-200201-units
  │   │   │   ├── feature-1-200201-value
  │   │   ├── input-0-200201
  │   │   │   ├── input-0-200201-maximum
  │   │   │   ├── input-0-200201-minimum
  │   │   │   ├── input-0-200201-name
  │   │   │   ├── input-0-200201-size
  │   │   │   ├── input-0-200201-unit-expo
  │   │   │   ├── input-0-200201-units
  │   │   │   ├── input-0-200201-value
  │   │   ├── input-1-200202
  │   │   │   ├── input-1-200202-maximum
  │   │   │   ├── input-1-200202-minimum
  │   │   │   ├── input-1-200202-name
  │   │   │   ├── input-1-200202-size
  │   │   │   ├── input-1-200202-unit-expo
  │   │   │   ├── input-1-200202-units
  │   │   │   ├── input-1-200202-value

Here there is a custom sensor with four fields: two feature and two inputs.
Each field is represented by a set of attributes. All fields except the "value"
are read only. The value field is a read-write field.

Example::

  /sys/bus/platform/devices/HID-SENSOR-2000e1.6.auto/feature-0-200316$ grep -r . *
  feature-0-200316-maximum:6
  feature-0-200316-minimum:0
  feature-0-200316-name:property-reporting-state
  feature-0-200316-size:1
  feature-0-200316-unit-expo:0
  feature-0-200316-units:25
  feature-0-200316-value:1

Sensor 활성화와 misc FIFO report

224-242

Custom sensor는 기본적으로 power-gated 상태일 수 있습니다. 활성화하려면 sysfs의 `enable_sensor` attribute에 `1`을 씁니다.

$ echo 1 > enable_sensor

Sensor가 활성화되고 전원이 켜지면 HID report로 값을 보고할 수 있습니다. 이 report들은 misc device interface를 통해 FIFO 순서로 전달됩니다.

/dev$ tree | grep HID-SENSOR-2000e1.6.auto
│   │   │   ├── 10:53 -> ../HID-SENSOR-2000e1.6.auto
│   ├── HID-SENSOR-2000e1.6.auto

각 report의 길이는 가변이며 앞에 header가 붙습니다. Header는 32-bit usage ID, 64-bit timestamp, 32-bit raw data length field로 구성됩니다.

Misc report header
Field크기내용
usage ID32 bitsReport를 생성한 sensor usage
timestamp64 bitsSample 시각
raw data length32 bits뒤따르는 payload byte 길이
raw datavariableHID report payload

가변 길이 payload 앞의 고정 header field입니다.

Custom sensor report 전달
echo 1 > enable_sensorSensor power on·reporting 시작HID report 생성Kernel이 고정 header 추가Misc device FIFO에 가변 길이 record enqueueApplication이 순서대로 record read

Power gate 해제부터 application read까지의 순서입니다.


How to enable such sensor?
^^^^^^^^^^^^^^^^^^^^^^^^^^

By default sensor can be power gated. To enable sysfs attribute "enable" can be
used::

        $ echo 1 > enable_sensor

Once enabled and powered on, sensor can report value using HID reports.
These reports are pushed using misc device interface in a FIFO order::

        /dev$ tree | grep HID-SENSOR-2000e1.6.auto
        │   │   │   ├── 10:53 -> ../HID-SENSOR-2000e1.6.auto
        │   ├──  HID-SENSOR-2000e1.6.auto

Each report can be of variable length preceded by a header. This header
consists of a 32-bit usage id, 64-bit time stamp and 32-bit length field of raw
data.