Skip to content

Instantly share code, notes, and snippets.

@amitn
Created February 4, 2014 07:17
Show Gist options
  • Save amitn/8799355 to your computer and use it in GitHub Desktop.
Save amitn/8799355 to your computer and use it in GitHub Desktop.
Yoga 2 Pro - Sensors
Hardware Perspective
--------------------
* It is look like that Lenovo has aggregated bunch of sensors into one USB HID Device, this will be `2047:0855 Texas Instruments`.
* This device has a big HID descriptor which report each sensor using `Usage Page 05 20 - Sensor Page (0x20)`
* There are 8 reports in the descriptor, for each report there is a bit map of the sensor properties:
```
Usage 0A 09 03 - Property: Sensor Connection Type
Usage 0A 16 03 - Property: Reporting State
Usage 0A 19 03 - Property: Power State
Usage 0A 01 02 - Event: Sensor State
Usage 0A 02 02 - Event: Sensor Event
Usage 0A 0E 03 - Property: Report Interval
```
* Report ID 1 - Accelerometer:
```
Usage 0A 53 04 - Data Field: Acceleration Axis X
Usage 0A 54 04 - Data Field: Acceleration Axis Y
Usage 0A 55 04 - Data Field: Acceleration Axis Z
```
* Report ID 2 - Angular Velocity:
```
Usage 0A 57 04 - Data Field: Angular Velocity about X Axis
Usage 0A 58 04 - Data Field: Angular Velocity about Y Axis
Usage 0A 59 04 - Data Field: Angular Velocity about Z Axis
```
* Report ID 3 - Magnetic Field:
```
Usage 0A 75 04 - Data Field: Heading Compensated Magnetic North
Usage 0A 85 04 - Data Field: Magnetic Flux X Axis
Usage 0A 86 04 - Data Field: Magnetic Flux Y Axis
Usage 0A 87 04 - Data Field: Magnetic Flux Z Axis
Usage 0A 44 05 - Data Field: Custom Value 1
```
* Report ID 4 - Rotation:
```
Usage 0A 7F 04 - Data Field: Tilt X Axis
Usage 0A 80 04 - Data Field: Tilt Y Axis
Usage 0A 81 04 - Data Field: Tilt Z Axis
```
* Report ID 5 - ???:
```
Usage 0A 83 04 - Data Field: Quaternion
```
* Report ID 6 - ???:
```
Usage 0A 44 05 - Data Field: Custom Value 1
Usage 0A 45 05 - Data Field: Custom Value 2
Usage 0A 46 05 - Data Field: Custom Value 3
Usage 0A 47 05 - Data Field: Custom Value 4
Usage 0A 48 05 - Data Field: Custom Value 5
Usage 0A 49 05 - Data Field: Custom Value 6
Usage 0A 4A 05 - Data Field: Custom Reserved
```
* Report ID 7 - ???:
```
Usage 0A 62 05 - Data Field: Generic Category GUID
Usage 0A 63 05 - Data Field: Generic Type GUID
Usage 0A 0F 03 - Property: Change Sensitivity Absolute
Usage 0A 66 05 - Data Field: Generic Data Field PROPERTYKEY
```
* Report ID 8 - Light Sensor:
```
Usage 0A D1 E4 -
Usage 0A 18 03 - Light sensors
Usage 0A D1 04 - Data Field: Illuminance
```
* Some of the reports has also input fields mainly for setting up sampling rate.
Software Side
-------------
* Workflow (I think):
1. The HID Sensor HUB is parsing the HID report descriptor and passing the reports to the `IIO subsystem`.
2. The `IIO` subsystem creates a sensor device for each valid report that the hub was able to parse.
* Relevent files:
```
include/linux/hid-sensor-ids.h
include/linux/hid-sensor-hub.h
drivers/hid/hid-sensor-hub.c
drivers/iio/common/hid-sensors/hid-sensor-trigger.c
drivers/iio/common/hid-sensors/hid-sensor-attributes.c
drivers/iio/common/hid-sensors/hid-sensor-trigger.h
drivers/iio/gyro/hid-sensor-gyro-3d.c
drivers/iio/accel/hid-sensor-accel-3d.c
drivers/iio/light/hid-sensor-als.c
drivers/iio/magnetometer/hid-sensor-magn-3d.c
Documentation/hid/hid-sensor.txt
```
Windows Dump
------------
Analazing the dump, it is look like that there are 3 reports reciving and sending 1 report.
* Reciving:
```
Report ID 1, Len 9 - Accelerometer
Report ID 6, Len 17 - ???
Report ID 8, Len 7 - Light Sensor
```
* Sending:
```
Set Report ID 1, Len 12
01 01 02 02 02 7D 00 00 00 02 00 03
Set Report ID 1, Len 12
01 01 02 02 02 20 00 00 00 02 00 03
```
* Decode the send report data:
It is look like the the driver is reseting the `Reporting State`, `Power State`, `Sensor State` and setting `Report Interval`
```
Byte Data Data
0A 09 03 - 8 Sensor Connection Type 00 01 01 PC Integrated
0A 16 03 - 8 Reporting State 01 02 02 Report All Events
0A 19 03 - 8 Power State 02 02 02 D0 Full Power
0A 01 02 - 8 Sensor State 03 02 02 Ready
0A 0E 03 - 32 Report Interval 04-07 0000007D 00000020
0A 52 14 - 16 ** Modifiers ** 08,09 0002 0002
52 04 Acceleration
00 10 Change Sensitivity Absolute
0A 52 44 - 8 ** Modifiers ** 10 03 03
52 04 Acceleration
00 40 Accuracy
Total Length 11 - Corresponds with 12 = ID + 11 Data
0A 01 02 - 8 (INPUT) Sensor State 11
0A 02 02 - 8 (INPUT) Sensor Event 12
0A 53 04 - 16 (INPUT) Acceleration Axis X 13,14
0A 54 04 - 16 (INPUT) Acceleration Axis Y 15,16
0A 55 04 - 16 (INPUT) Acceleration Axis Z 17,18
Total Length 8 - Corresponds with 9 = ID + 8 Data
```
Full Report 1
-------------
Report ID (1) 85 01
Usage Page 05 20
Usage 09 73
Collection (Physical) A1 00
Usage Page 05 20
Usage 0A 09 03
Logical Minimum (0) 15 00
Logical Maximum (2) 25 02
Report Size (8) 75 08
Report Count (1) 95 01
Collection (Logical) A1 02
Usage 0A 30 08
Usage 0A 31 08
Usage 0A 32 08
Feature (Data,Ary,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 00
End Collection C0
Usage 0A 16 03
Logical Minimum (0) 15 00
Logical Maximum (5) 25 05
Report Size (8) 75 08
Report Count (1) 95 01
Collection (Logical) A1 02
Usage 0A 40 08
Usage 0A 41 08
Usage 0A 42 08
Usage 0A 43 08
Usage 0A 44 08
Usage 0A 45 08
Feature (Data,Ary,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 00
End Collection C0
Usage 0A 19 03
Logical Minimum (0) 15 00
Logical Maximum (5) 25 05
Report Size (8) 75 08
Report Count (1) 95 01
Collection (Logical) A1 02
Usage 0A 50 08
Usage 0A 51 08
Usage 0A 52 08
Usage 0A 53 08
Usage 0A 54 08
Usage 0A 55 08
Feature (Data,Ary,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 00
End Collection C0
Usage 0A 01 02
Logical Minimum (0) 15 00
Logical Maximum (6) 25 06
Report Size (8) 75 08
Report Count (1) 95 01
Collection (Logical) A1 02
Usage 0A 00 08
Usage 0A 01 08
Usage 0A 02 08
Usage 0A 03 08
Usage 0A 04 08
Usage 0A 05 08
Usage 0A 06 08
Feature (Data,Ary,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 00
End Collection C0
Usage 0A 0E 03
Logical Minimum (0) 15 00
Logical Maximum (-1) 27 FF FF FF FF
Report Size (32) 75 20
Report Count (1) 95 01
Unit Exponent (0) 55 00
Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
Usage 0A 52 14
Logical Minimum (0) 15 00
Logical Maximum (-1) 26 FF FF
Report Size (16) 75 10
Report Count (1) 95 01
Unit Exponent (-2) 55 0E
Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
Usage 0A 52 44
Logical Minimum (0) 15 00
Logical Maximum (3) 25 03
Report Size (8) 75 08
Report Count (1) 95 01
Unit Exponent (0) 55 00
Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
Usage Page 05 20
Usage 0A 01 02
Logical Minimum (0) 15 00
Logical Maximum (6) 25 06
Report Size (8) 75 08
Report Count (1) 95 01
Collection (Logical) A1 02
Usage 0A 00 08
Usage 0A 01 08
Usage 0A 02 08
Usage 0A 03 08
Usage 0A 04 08
Usage 0A 05 08
Usage 0A 06 08
Input (Data,Ary,Abs) 81 00
End Collection C0
Usage 0A 02 02
Logical Minimum (0) 15 00
Logical Maximum (5) 25 05
Report Size (8) 75 08
Report Count (1) 95 01
Collection (Logical) A1 02
Usage 0A 10 08
Usage 0A 11 08
Usage 0A 12 08
Usage 0A 13 08
Usage 0A 14 08
Usage 0A 15 08
Input (Data,Ary,Abs) 81 00
End Collection C0
Usage 0A 53 04
Logical Minimum (-32767) 16 01 80
Logical Maximum (32767) 26 FF 7F
Report Size (16) 75 10
Report Count (1) 95 01
Unit Exponent (-3) 55 0D
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage 0A 54 04
Logical Minimum (-32767) 16 01 80
Logical Maximum (32767) 26 FF 7F
Report Size (16) 75 10
Report Count (1) 95 01
Unit Exponent (-3) 55 0D
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage 0A 55 04
Logical Minimum (-32767) 16 01 80
Logical Maximum (32767) 26 FF 7F
Report Size (16) 75 10
Report Count (1) 95 01
Unit Exponent (-3) 55 0D
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
End Collection C0
Decode Report 6
---------------
`Use 09 E1 - HID_USAGE_SENSOR_TYPE_OTHER_CUSTOM`
```
0A 09 03 - 8
0A 16 03 - 8
0A 19 03 - 8
0A 01 02 - 8
0A 0E 03 - 32
0A 43 15 - 16
0A 43 45 - 8
0A 04 03 - 32
Length 15
0A 01 02 - 8 (INPUT) Sensor State 02
0A 02 02 - 8 (INPUT) Sensor Event 04
0A 44 05 - 16 (INPUT) Custom Value 1 FFAF
0A 45 05 - 16 (INPUT) Custom Value 2 003A
0A 46 05 - 16 (INPUT) Custom Value 3 FBAC
0A 47 05 - 16 (INPUT) Custom Value 4 000A
0A 48 05 - 16 (INPUT) Custom Value 5 044C
0A 49 05 - 16 (INPUT) Custom Value 6 0442
0A 4A 05 - 16 (INPUT) Custom Reserved 0000
Length 16
```
Devode Report 8
---------------
```
0A 09 03 - 8 Sensor Connection Type
0A 16 03 - 8 Reporting State
0A 19 03 - 8 Power State
0A 01 02 - 8 Sensor State
0A 0E 03 - 32 Report Interval
0A D1 E4 - 16 ** Modifiers **
D1 04 Illuminance
00 E0 Change Sensitivity Percent Relative
0A 18 03 - 16x10 Response Curve
Length 30
0A 01 02 - 8 (INPUT)
0A 02 02 - 8 (INPUT)
0A D1 04 - 32 (INPUT)
Length 6
```
Enabling HIDRAW
---------------
* Get the Kernel source
* Edit file `drivers/hid/hid-sensor-hub.c` change `hid_hw_start(hdev, HID_CONNECT_HIDRAW)`
* Get confing file for build
```
$ cp /boot/config-`uname -r` .config
```
* Build the kernel module
```
$ make -C /lib/modules/`uname -r`/build M=`pwd`/drivers/hid hid-sensor-hub.ko
```
@rickr
Copy link

rickr commented Feb 7, 2014

@amitn Hello! I just picked up a yoga2 and have been looking to get a more functional tablet mode. It looks like you may have made some progress? Do you have any more details on how far you've come or what needs to be done?

@amitn
Copy link
Author

amitn commented Feb 17, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment