diff options
| author | Jiri Kosina <jkosina@suse.cz> | 2015-04-13 17:43:34 -0400 |
|---|---|---|
| committer | Jiri Kosina <jkosina@suse.cz> | 2015-04-13 17:43:34 -0400 |
| commit | 2e455c27bddbf8cf6d1039daea40de8e6865c453 (patch) | |
| tree | 3fd892aeae61b105e3c5c979550aabf54109a656 | |
| parent | 05f6d02521d4c7a656c5135d6d81c345ce531ac0 (diff) | |
| parent | b2eafd7282fdfd148fc09032540b0ff42bfedfbf (diff) | |
Merge branch 'for-4.1/sensor-hub' into for-linus
Conflicts:
drivers/iio/common/hid-sensors/hid-sensor-trigger.c
include/linux/hid-sensor-hub.h
| -rw-r--r-- | Documentation/hid/hid-sensor.txt | 84 | ||||
| -rw-r--r-- | drivers/hid/Kconfig | 15 | ||||
| -rw-r--r-- | drivers/hid/Makefile | 1 | ||||
| -rw-r--r-- | drivers/hid/hid-sensor-custom.c | 849 | ||||
| -rw-r--r-- | drivers/hid/hid-sensor-hub.c | 198 | ||||
| -rw-r--r-- | drivers/iio/accel/hid-sensor-accel-3d.c | 3 | ||||
| -rw-r--r-- | drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 24 | ||||
| -rw-r--r-- | drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 13 | ||||
| -rw-r--r-- | drivers/iio/gyro/hid-sensor-gyro-3d.c | 3 | ||||
| -rw-r--r-- | drivers/iio/light/hid-sensor-als.c | 3 | ||||
| -rw-r--r-- | drivers/iio/light/hid-sensor-prox.c | 3 | ||||
| -rw-r--r-- | drivers/iio/magnetometer/hid-sensor-magn-3d.c | 3 | ||||
| -rw-r--r-- | drivers/iio/orientation/hid-sensor-incl-3d.c | 3 | ||||
| -rw-r--r-- | drivers/iio/pressure/hid-sensor-press.c | 3 | ||||
| -rw-r--r-- | drivers/rtc/rtc-hid-sensor-time.c | 2 | ||||
| -rw-r--r-- | include/linux/hid-sensor-hub.h | 55 | ||||
| -rw-r--r-- | include/linux/hid-sensor-ids.h | 2 |
17 files changed, 1154 insertions, 110 deletions
diff --git a/Documentation/hid/hid-sensor.txt b/Documentation/hid/hid-sensor.txt index 948b0989c433..b287752a31cd 100644 --- a/Documentation/hid/hid-sensor.txt +++ b/Documentation/hid/hid-sensor.txt | |||
| @@ -138,3 +138,87 @@ accelerometer wants to poll X axis value, then it can call this function with | |||
| 138 | the usage id of X axis. HID sensors can provide events, so this is not necessary | 138 | the usage id of X axis. HID sensors can provide events, so this is not necessary |
| 139 | to poll for any field. If there is some new sample, the core driver will call | 139 | to poll for any field. If there is some new sample, the core driver will call |
| 140 | registered callback function to process the sample. | 140 | registered callback function to process the sample. |
| 141 | |||
| 142 | |||
| 143 | ---------- | ||
| 144 | |||
| 145 | HID Custom and generic Sensors | ||
| 146 | |||
| 147 | HID Sensor specification defines two special sensor usage types. Since they | ||
| 148 | don't represent a standard sensor, it is not possible to define using Linux IIO | ||
| 149 | type interfaces. | ||
| 150 | The purpose of these sensors is to extend the functionality or provide a | ||
| 151 | way to obfuscate the data being communicated by a sensor. Without knowing the | ||
| 152 | mapping between the data and its encapsulated form, it is difficult for | ||
| 153 | an application/driver to determine what data is being communicated by the sensor. | ||
| 154 | This allows some differentiating use cases, where vendor can provide applications. | ||
| 155 | Some common use cases are debug other sensors or to provide some events like | ||
| 156 | keyboard attached/detached or lid open/close. | ||
| 157 | |||
| 158 | To allow application to utilize these sensors, here they are exported uses sysfs | ||
| 159 | attribute groups, attributes and misc device interface. | ||
| 160 | |||
| 161 | An example of this representation on sysfs: | ||
| 162 | /sys/devices/pci0000:00/INT33C2:00/i2c-0/i2c-INT33D1:00/0018:8086:09FA.0001/HID-SENSOR-2000e1.6.auto$ tree -R | ||
| 163 | . | ||
| 164 | ????????? enable_sensor | ||
| 165 | ????????? feature-0-200316 | ||
| 166 | ??????? ????????? feature-0-200316-maximum | ||
| 167 | ??????? ????????? feature-0-200316-minimum | ||
| 168 | ??????? ????????? feature-0-200316-name | ||
| 169 | ??????? ????????? feature-0-200316-size | ||
| 170 | ??????? ????????? feature-0-200316-unit-expo | ||
| 171 | ??????? ????????? feature-0-200316-units | ||
| 172 | ??????? ????????? feature-0-200316-value | ||
| 173 | ????????? feature-1-200201 | ||
| 174 | ??????? ????????? feature-1-200201-maximum | ||
| 175 | ??????? ????????? feature-1-200201-minimum | ||
| 176 | ??????? ????????? feature-1-200201-name | ||
| 177 | ??????? ????????? feature-1-200201-size | ||
| 178 | ??????? ????????? feature-1-200201-unit-expo | ||
| 179 | ??????? ????????? feature-1-200201-units | ||
| 180 | ??????? ????????? feature-1-200201-value | ||
| 181 | ????????? input-0-200201 | ||
| 182 | ??????? ????????? input-0-200201-maximum | ||
| 183 | ??????? ????????? input-0-200201-minimum | ||
| 184 | ??????? ????????? input-0-200201-name | ||
| 185 | ??????? ????????? input-0-200201-size | ||
| 186 | ??????? ????????? input-0-200201-unit-expo | ||
| 187 | ??????? ????????? input-0-200201-units | ||
| 188 | ??????? ????????? input-0-200201-value | ||
| 189 | ????????? input-1-200202 | ||
| 190 | ??????? ????????? input-1-200202-maximum | ||
| 191 | ??????? ????????? input-1-200202-minimum | ||
| 192 | ??????? ????????? input-1-200202-name | ||
| 193 | ??????? ????????? input-1-200202-size | ||
| 194 | ??????? ????????? input-1-200202-unit-expo | ||
| 195 | ??????? ????????? input-1-200202-units | ||
| 196 | ??????? ????????? input-1-200202-value | ||
| 197 | |||
| 198 | Here there is a custom sensors with four fields, two feature and two inputs. | ||
| 199 | Each field is represented by a set of attributes. All fields except the "value" | ||
| 200 | are read only. The value field is a RW field. | ||
| 201 | Example | ||
| 202 | /sys/bus/platform/devices/HID-SENSOR-2000e1.6.auto/feature-0-200316$ grep -r . * | ||
| 203 | feature-0-200316-maximum:6 | ||
| 204 | feature-0-200316-minimum:0 | ||
| 205 | feature-0-200316-name:property-reporting-state | ||
| 206 | feature-0-200316-size:1 | ||
| 207 | feature-0-200316-unit-expo:0 | ||
| 208 | feature-0-200316-units:25 | ||
| 209 | feature-0-200316-value:1 | ||
| 210 | |||
| 211 | How to enable such sensor? | ||
| 212 | By default sensor can be power gated. To enable sysfs attribute "enable" can be | ||
| 213 | used. | ||
| 214 | $ echo 1 > enable_sensor | ||
| 215 | |||
| 216 | Once enabled and powered on, sensor can report value using HID reports. | ||
| 217 | These reports are pushed using misc device interface in a FIFO order. | ||
| 218 | /dev$ tree | grep HID-SENSOR-2000e1.6.auto | ||
| 219 | ??????? ????????? 10:53 -> ../HID-SENSOR-2000e1.6.auto | ||
| 220 | ????????? HID-SENSOR-2000e1.6.auto | ||
| 221 | |||
| 222 | Each reports can be of variable length preceded by a header. This header | ||
| 223 | consist of a 32 bit usage id, 64 bit time stamp and 32 bit length field of raw | ||
| 224 | data. | ||
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 15901065727f..15338afdf7f9 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig | |||
| @@ -878,6 +878,21 @@ config HID_SENSOR_HUB | |||
| 878 | for events and handle data streams. Each sensor driver can format | 878 | for events and handle data streams. Each sensor driver can format |
| 879 | data and present to user mode using input or IIO interface. | 879 | data and present to user mode using input or IIO interface. |
| 880 | 880 | ||
| 881 | config HID_SENSOR_CUSTOM_SENSOR | ||
| 882 | tristate "HID Sensors hub custom sensor support" | ||
| 883 | depends on HID_SENSOR_HUB | ||
| 884 | default n | ||
| 885 | ---help--- | ||
| 886 | HID Sensor hub specification allows definition of some custom and | ||
| 887 | generic sensors. Unlike other HID sensors, they can't be exported | ||
| 888 | via Linux IIO because of custom fields. This is up to the manufacturer | ||
| 889 | to decide how to interpret these special sensor ids and process in | ||
| 890 | the user space. Currently some manufacturers are using these ids for | ||
| 891 | sensor calibration and debugging other sensors. Manufacturers | ||
| 892 | should't use these special custom sensor ids to export any of the | ||
| 893 | standard sensors. | ||
| 894 | Select this config option for custom/generic sensor support. | ||
| 895 | |||
| 881 | endmenu | 896 | endmenu |
| 882 | 897 | ||
| 883 | endif # HID | 898 | endif # HID |
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 9c399fe394fa..e4a21dfd7ef3 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile | |||
| @@ -100,6 +100,7 @@ obj-$(CONFIG_HID_WACOM) += wacom.o | |||
| 100 | obj-$(CONFIG_HID_WALTOP) += hid-waltop.o | 100 | obj-$(CONFIG_HID_WALTOP) += hid-waltop.o |
| 101 | obj-$(CONFIG_HID_WIIMOTE) += hid-wiimote.o | 101 | obj-$(CONFIG_HID_WIIMOTE) += hid-wiimote.o |
| 102 | obj-$(CONFIG_HID_SENSOR_HUB) += hid-sensor-hub.o | 102 | obj-$(CONFIG_HID_SENSOR_HUB) += hid-sensor-hub.o |
| 103 | obj-$(CONFIG_HID_SENSOR_CUSTOM_SENSOR) += hid-sensor-custom.o | ||
| 103 | 104 | ||
| 104 | obj-$(CONFIG_USB_HID) += usbhid/ | 105 | obj-$(CONFIG_USB_HID) += usbhid/ |
| 105 | obj-$(CONFIG_USB_MOUSE) += usbhid/ | 106 | obj-$(CONFIG_USB_MOUSE) += usbhid/ |
diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c new file mode 100644 index 000000000000..5614fee82347 --- /dev/null +++ b/drivers/hid/hid-sensor-custom.c | |||
| @@ -0,0 +1,849 @@ | |||
| 1 | /* | ||
| 2 | * hid-sensor-custom.c | ||
| 3 | * Copyright (c) 2015, Intel Corporation. | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms and conditions of the GNU General Public License, | ||
| 7 | * version 2, as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 12 | * more details. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #include <linux/kernel.h> | ||
| 16 | #include <linux/module.h> | ||
| 17 | #include <linux/init.h> | ||
| 18 | #include <linux/miscdevice.h> | ||
| 19 | #include <linux/kfifo.h> | ||
| 20 | #include <linux/sched.h> | ||
| 21 | #include <linux/wait.h> | ||
| 22 | #include <linux/poll.h> | ||
| 23 | #include <linux/bsearch.h> | ||
| 24 | #include <linux/platform_device.h> | ||
| 25 | #include <linux/hid-sensor-hub.h> | ||
| 26 | |||
| 27 | #define HID_CUSTOM_NAME_LENGTH 64 | ||
| 28 | #define HID_CUSTOM_MAX_CORE_ATTRS 10 | ||
| 29 | #define HID_CUSTOM_TOTAL_ATTRS (HID_CUSTOM_MAX_CORE_ATTRS + 1) | ||
| 30 | #define HID_CUSTOM_FIFO_SIZE 4096 | ||
| 31 | #define HID_CUSTOM_MAX_FEATURE_BYTES 64 | ||
| 32 | |||
| 33 | struct hid_sensor_custom_field { | ||
| 34 | int report_id; | ||
| 35 | char group_name[HID_CUSTOM_NAME_LENGTH]; | ||
| 36 | struct hid_sensor_hub_attribute_info attribute; | ||
| 37 | struct device_attribute sd_attrs[HID_CUSTOM_MAX_CORE_ATTRS]; | ||
| 38 | char attr_name[HID_CUSTOM_TOTAL_ATTRS][HID_CUSTOM_NAME_LENGTH]; | ||
| 39 | struct attribute *attrs[HID_CUSTOM_TOTAL_ATTRS]; | ||
| 40 | struct attribute_group hid_custom_attribute_group; | ||
| 41 | }; | ||
| 42 | |||
| 43 | struct hid_sensor_custom { | ||
| 44 | struct mutex mutex; | ||
| 45 | struct platform_device *pdev; | ||
| 46 | struct hid_sensor_hub_device *hsdev; | ||
| 47 | struct hid_sen | ||
