summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-07-28 00:29:49 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-07-28 00:29:49 -0400
commit98c2f10d2366ec7128c254c775d4e6969a705ecd (patch)
treeace44ad28a52a3bd615ced288baf91be003ca38b
parenta29e24907208a7e05e9bd3f990d3fc5ea49667de (diff)
parentf3f0ae16f0ce2a11067b958c7cf2a48c32ea6d60 (diff)
Merge tag 'iio-for-4.14a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes: First round of IIO new device support, features and cleanups for the 4.14 cycle. 4 completely new drivers in this set and plenty of other stuff. One ABI change due to a silly mistake a long time back. Hopefully no one will notice. It effects the numerical order of consumer device channels which was the reverse of the obvious. It's going the slow way to allow us some margin to spot if we have broken userspace or not (seems unlikely) New Device Support * ccs811 - new driver for the Volatile Organic Compounds (VOC) sensor. * dln2 adc - new driver for the ADC on this flexible usb board. * EP93xx - new driver for this Cirrus logic SoC ADC. * ltc2471 - new ADC driver support the ltc2471 and ltc2473 * st_accel - add trivial table entries to support H3LIS331DL, LIS331DL, LIS3LV02DL. * st_gyro - add L3GD20H support (again) having fixed the various things that were broken in the first try. Includes devicetree binding. * stm32 dac - add support for the DACs in the STM32F4 series Features * Documentation - add missing power attribute documentation to the ABI docs. * at91-sama5d2 - add hardware trigger and buffered capture support with bindings. - suspend and resume functionality. * bmc150 - support for the BOSC0200 ACPI device id seen on some tablets. * hdc100x - devicetree bindings - document supported devices - match table and device ids. * hts221 - support active low interrupts (with bindings) - open drain mode with bindings. * htu21 - OF match table and bindings. * lsm6dsx - open drain mode with bindings * ltc2497 - add support for board file based consumer mapping. * ms5367 - OF match table and bindings. * mt7622 - binding document and OF match table. - suspend and resume support. * rpr0521 - triggered buffer support. * tsys01 - OF match table and bindings. Cleanups and minor fixes * core - fix ordering of IIO channels to entry numbers when using iio_map_array_register rather than reversing them. - use the new %pOF format specifier rather than full name for the device tree nodes. * ad7280a - fix potential issue with macro argument reuse. * ad7766 - drop a pointless NULL value check as it's done in the gpiod code. * adis16400 - unsigned -> unsigned int. * at91 adc - make some init data static to reduce code size. * at91-sama5d2 ADC - make some init data static to reduce code size. * da311 - make some init data static to reduce code size. * hid-sensor-rotation - drop an unnecessary static. * hts221 - refactor the write_with_mask code. - move the BDU configuration to probe time as there is no reason for it to change. - avoid overwriting reserved data during power-down. This is a fix, but the infrastructure need was too invasive to send it to mainline except in a merge window. It's not a regression as it was always wrong. - avoid reconfigure the sampling frequency multiple times by just doing it in the write_raw function directly. - refactor the power_on/off calls into a set_enable. - move the dry-enable logic into trig_set_state as that is the only place it was used. * ina219 - fix polling of ina226 conversion ready flag. * imx7d - add vendor name in kconfig for consistency with similar parts. * mcp3422 - Change initial channel to 0 as it feels more logical. - Check for some errors in probe. * meson-saradc - add a check of of_match_device return value. * mpu3050 - allow open drain for any interrupt type. * rockchip adc - add check on of_match_device return value. * sca3000 - drop a trailing whitespace. * stm32 adc - make array stm32h7_adc_ckmodes_spec static. * stm32 dac - fix an error message. * stm32 timers - fix clock name in docs to match reality after changes. * st_accel - explicit OF table (spi). - add missing entries to OF table (i2c). - rename of_device_id table to drop the part name. - adding missing lis3l02dq entry to bindings. - rename H3LIS331DL_DRIVER_NAME to line up with similar entries in driver. * st_gyro - explicit OF table (spi). * st_magn - explicit OF table (spi). - enable multiread for lis3mdl. * st_pressure - explicit OF table (spi). * st_sensors common. - move st_sensors_of_i2c_probe and rename to make it available for spi drivers. * tsc3472 - don't write an extra byte when writing the ATIME register. - add a link to the datasheet. * tsl2x7x - continued staging cleanups - add of_match_table. - drop redundant power_state sysfs attribute. - drop wrapper tsl2x7x_i2c_read. - clean up i2c calls made in tsl2x7x_als_calibrate. - refactor the read and write _event_value callbacks to handle additional elements. - use usleep_range instead of mdelay. - check return value from tsl2x7x_invoke_change. * zpa2326 - add some newline to the end of logging macros.
-rw-r--r--Documentation/ABI/testing/sysfs-bus-iio9
-rw-r--r--Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt6
-rw-r--r--Documentation/devicetree/bindings/iio/adc/mt6577_auxadc.txt1
-rw-r--r--Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt4
-rw-r--r--Documentation/devicetree/bindings/iio/humidity/hdc100x.txt17
-rw-r--r--Documentation/devicetree/bindings/iio/humidity/hts221.txt11
-rw-r--r--Documentation/devicetree/bindings/iio/humidity/htu21.txt13
-rw-r--r--Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt8
-rw-r--r--Documentation/devicetree/bindings/iio/pressure/ms5637.txt17
-rw-r--r--Documentation/devicetree/bindings/iio/st-sensors.txt2
-rw-r--r--Documentation/devicetree/bindings/iio/temperature/tsys01.txt19
-rw-r--r--Documentation/devicetree/bindings/iio/timer/stm32-timer-trigger.txt2
-rw-r--r--Documentation/iio/ep93xx_adc.txt29
-rw-r--r--drivers/iio/accel/bmc150-accel-i2c.c1
-rw-r--r--drivers/iio/accel/da311.c2
-rw-r--r--drivers/iio/accel/sca3000.c6
-rw-r--r--drivers/iio/accel/st_accel.h5
-rw-r--r--drivers/iio/accel/st_accel_core.c2
-rw-r--r--drivers/iio/accel/st_accel_i2c.c8
-rw-r--r--drivers/iio/accel/st_accel_spi.c86
-rw-r--r--drivers/iio/adc/Kconfig32
-rw-r--r--drivers/iio/adc/Makefile3
-rw-r--r--drivers/iio/adc/ad7766.c6
-rw-r--r--drivers/iio/adc/at91-sama5d2_adc.c329
-rw-r--r--drivers/iio/adc/at91_adc.c2
-rw-r--r--drivers/iio/adc/dln2-adc.c722
-rw-r--r--drivers/iio/adc/ep93xx_adc.c255
-rw-r--r--drivers/iio/adc/ina2xx-adc.c36
-rw-r--r--drivers/iio/adc/ltc2471.c160
-rw-r--r--drivers/iio/adc/ltc2497.c54
-rw-r--r--drivers/iio/adc/max9611.c4
-rw-r--r--drivers/iio/adc/mcp3422.c6
-rw-r--r--drivers/iio/adc/meson_saradc.c13
-rw-r--r--drivers/iio/adc/mt6577_auxadc.c37
-rw-r--r--drivers/iio/adc/rockchip_saradc.c5
-rw-r--r--drivers/iio/adc/stm32-adc-core.c2
-rw-r--r--drivers/iio/adc/ti-ads1015.c16
-rw-r--r--drivers/iio/chemical/Kconfig7
-rw-r--r--drivers/iio/chemical/Makefile1
-rw-r--r--drivers/iio/chemical/ccs811.c339
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c31
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_i2c.c29
-rw-r--r--drivers/iio/dac/stm32-dac-core.c38
-rw-r--r--drivers/iio/dac/stm32-dac.c2
-rw-r--r--drivers/iio/gyro/mpu3050-core.c10
-rw-r--r--drivers/iio/gyro/st_gyro.h1
-rw-r--r--drivers/iio/gyro/st_gyro_core.c13
-rw-r--r--drivers/iio/gyro/st_gyro_i2c.c8
-rw-r--r--drivers/iio/gyro/st_gyro_spi.c54
-rw-r--r--drivers/iio/humidity/Kconfig3
-rw-r--r--drivers/iio/humidity/hdc100x.c22
-rw-r--r--drivers/iio/humidity/hts221.h11
-rw-r--r--drivers/iio/humidity/hts221_buffer.c43
-rw-r--r--drivers/iio/humidity/hts221_core.c144
-rw-r--r--drivers/iio/humidity/htu21.c8
-rw-r--r--drivers/iio/imu/adis16400_core.c4
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c17
-rw-r--r--drivers/iio/inkern.c6
-rw-r--r--drivers/iio/light/rpr0521.c336
-rw-r--r--drivers/iio/light/tcs3472.c4
-rw-r--r--drivers/iio/magnetometer/ak8975.c2
-rw-r--r--drivers/iio/magnetometer/st_magn_core.c2
-rw-r--r--drivers/iio/magnetometer/st_magn_i2c.c3
-rw-r--r--drivers/iio/magnetometer/st_magn_spi.c25
-rw-r--r--drivers/iio/orientation/hid-sensor-rotation.c2
-rw-r--r--drivers/iio/pressure/ms5637.c12
-rw-r--r--drivers/iio/pressure/st_pressure_i2c.c3
-rw-r--r--drivers/iio/pressure/st_pressure_spi.c33
-rw-r--r--drivers/iio/pressure/zpa2326.c12
-rw-r--r--drivers/iio/temperature/tsys01.c7
-rw-r--r--drivers/staging/iio/adc/ad7280a.c21
-rw-r--r--drivers/staging/iio/light/tsl2x7x.c372
-rw-r--r--include/linux/iio/common/st_sensors.h12
-rw-r--r--include/linux/iio/common/st_sensors_i2c.h10
74 files changed, 3098 insertions, 479 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index 2db2cdf42d54..7eead5f97e02 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -119,6 +119,15 @@ Description:
119 unique to allow association with event codes. Units after 119 unique to allow association with event codes. Units after
120 application of scale and offset are milliamps. 120 application of scale and offset are milliamps.
121 121
122What: /sys/bus/iio/devices/iio:deviceX/in_powerY_raw
123KernelVersion: 4.5
124Contact: linux-iio@vger.kernel.org
125Description:
126 Raw (unscaled no bias removal etc.) power measurement from
127 channel Y. The number must always be specified and
128 unique to allow association with event codes. Units after
129 application of scale and offset are milliwatts.
130
122What: /sys/bus/iio/devices/iio:deviceX/in_capacitanceY_raw 131What: /sys/bus/iio/devices/iio:deviceX/in_capacitanceY_raw
123KernelVersion: 3.2 132KernelVersion: 3.2
124Contact: linux-iio@vger.kernel.org 133Contact: linux-iio@vger.kernel.org
diff --git a/Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt b/Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt
index 3223684a643b..552e7a83951d 100644
--- a/Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt
@@ -11,6 +11,11 @@ Required properties:
11 - atmel,min-sample-rate-hz: Minimum sampling rate, it depends on SoC. 11 - atmel,min-sample-rate-hz: Minimum sampling rate, it depends on SoC.
12 - atmel,max-sample-rate-hz: Maximum sampling rate, it depends on SoC. 12 - atmel,max-sample-rate-hz: Maximum sampling rate, it depends on SoC.
13 - atmel,startup-time-ms: Startup time expressed in ms, it depends on SoC. 13 - atmel,startup-time-ms: Startup time expressed in ms, it depends on SoC.
14 - atmel,trigger-edge-type: One of possible edge types for the ADTRG hardware
15 trigger pin. When the specific edge type is detected, the conversion will
16 start. Possible values are rising, falling, or both.
17 This property uses the IRQ edge types values: IRQ_TYPE_EDGE_RISING ,
18 IRQ_TYPE_EDGE_FALLING or IRQ_TYPE_EDGE_BOTH
14 19
15Example: 20Example:
16 21
@@ -25,4 +30,5 @@ adc: adc@fc030000 {
25 atmel,startup-time-ms = <4>; 30 atmel,startup-time-ms = <4>;
26 vddana-supply = <&vdd_3v3_lp_reg>; 31 vddana-supply = <&vdd_3v3_lp_reg>;
27 vref-supply = <&vdd_3v3_lp_reg>; 32 vref-supply = <&vdd_3v3_lp_reg>;
33 atmel,trigger-edge-type = <IRQ_TYPE_EDGE_BOTH>;
28} 34}
diff --git a/Documentation/devicetree/bindings/iio/adc/mt6577_auxadc.txt b/Documentation/devicetree/bindings/iio/adc/mt6577_auxadc.txt
index 68c45cbbe3d9..64dc4843c180 100644
--- a/Documentation/devicetree/bindings/iio/adc/mt6577_auxadc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/mt6577_auxadc.txt
@@ -12,6 +12,7 @@ for the Thermal Controller which holds a phandle to the AUXADC.
12Required properties: 12Required properties:
13 - compatible: Should be one of: 13 - compatible: Should be one of:
14 - "mediatek,mt2701-auxadc": For MT2701 family of SoCs 14 - "mediatek,mt2701-auxadc": For MT2701 family of SoCs
15 - "mediatek,mt7622-auxadc": For MT7622 family of SoCs
15 - "mediatek,mt8173-auxadc": For MT8173 family of SoCs 16 - "mediatek,mt8173-auxadc": For MT8173 family of SoCs
16 - reg: Address range of the AUXADC unit. 17 - reg: Address range of the AUXADC unit.
17 - clocks: Should contain a clock specifier for each entry in clock-names 18 - clocks: Should contain a clock specifier for each entry in clock-names
diff --git a/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt b/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt
index bcee71f808d0..bf2925c671c6 100644
--- a/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt
+++ b/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt
@@ -10,7 +10,9 @@ current.
10Contents of a stm32 dac root node: 10Contents of a stm32 dac root node:
11----------------------------------- 11-----------------------------------
12Required properties: 12Required properties:
13- compatible: Must be "st,stm32h7-dac-core". 13- compatible: Should be one of:
14 "st,stm32f4-dac-core"
15 "st,stm32h7-dac-core"
14- reg: Offset and length of the device's register set. 16- reg: Offset and length of the device's register set.
15- clocks: Must contain an entry for pclk (which feeds the peripheral bus 17- clocks: Must contain an entry for pclk (which feeds the peripheral bus
16 interface) 18 interface)
diff --git a/Documentation/devicetree/bindings/iio/humidity/hdc100x.txt b/Documentation/devicetree/bindings/iio/humidity/hdc100x.txt
new file mode 100644
index 000000000000..c52333bdfd19
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/humidity/hdc100x.txt
@@ -0,0 +1,17 @@
1* HDC100x temperature + humidity sensors
2
3Required properties:
4 - compatible: Should contain one of the following:
5 ti,hdc1000
6 ti,hdc1008
7 ti,hdc1010
8 ti,hdc1050
9 ti,hdc1080
10 - reg: i2c address of the sensor
11
12Example:
13
14hdc100x@40 {
15 compatible = "ti,hdc1000";
16 reg = <0x40>;
17};
diff --git a/Documentation/devicetree/bindings/iio/humidity/hts221.txt b/Documentation/devicetree/bindings/iio/humidity/hts221.txt
index b20ab9c12080..10adeb0d703d 100644
--- a/Documentation/devicetree/bindings/iio/humidity/hts221.txt
+++ b/Documentation/devicetree/bindings/iio/humidity/hts221.txt
@@ -5,9 +5,18 @@ Required properties:
5- reg: i2c address of the sensor / spi cs line 5- reg: i2c address of the sensor / spi cs line
6 6
7Optional properties: 7Optional properties:
8- drive-open-drain: the interrupt/data ready line will be configured
9 as open drain, which is useful if several sensors share the same
10 interrupt line. This is a boolean property.
11 If the requested interrupt is configured as IRQ_TYPE_LEVEL_HIGH or
12 IRQ_TYPE_EDGE_RISING a pull-down resistor is needed to drive the line
13 when it is not active, whereas a pull-up one is needed when interrupt
14 line is configured as IRQ_TYPE_LEVEL_LOW or IRQ_TYPE_EDGE_FALLING.
15 Refer to pinctrl/pinctrl-bindings.txt for the property description.
8- interrupt-parent: should be the phandle for the interrupt controller 16- interrupt-parent: should be the phandle for the interrupt controller
9- interrupts: interrupt mapping for IRQ. It should be configured with 17- interrupts: interrupt mapping for IRQ. It should be configured with
10 flags IRQ_TYPE_LEVEL_HIGH or IRQ_TYPE_EDGE_RISING. 18 flags IRQ_TYPE_LEVEL_HIGH, IRQ_TYPE_EDGE_RISING, IRQ_TYPE_LEVEL_LOW or
19 IRQ_TYPE_EDGE_FALLING.
11 20
12 Refer to interrupt-controller/interrupts.txt for generic interrupt 21 Refer to interrupt-controller/interrupts.txt for generic interrupt
13 client node bindings. 22 client node bindings.
diff --git a/Documentation/devicetree/bindings/iio/humidity/htu21.txt b/Documentation/devicetree/bindings/iio/humidity/htu21.txt
new file mode 100644
index 000000000000..97d79636f7ae
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/humidity/htu21.txt
@@ -0,0 +1,13 @@
1*HTU21 - Measurement-Specialties htu21 temperature & humidity sensor and humidity part of MS8607 sensor
2
3Required properties:
4
5 - compatible: should be "meas,htu21" or "meas,ms8607-humidity"
6 - reg: I2C address of the sensor
7
8Example:
9
10htu21@40 {
11 compatible = "meas,htu21";
12 reg = <0x40>;
13};
diff --git a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
index 6f28ff55f3ec..1ff1af799c76 100644
--- a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
+++ b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
@@ -11,6 +11,14 @@ Required properties:
11Optional properties: 11Optional properties:
12- st,drdy-int-pin: the pin on the package that will be used to signal 12- st,drdy-int-pin: the pin on the package that will be used to signal
13 "data ready" (valid values: 1 or 2). 13 "data ready" (valid values: 1 or 2).
14- drive-open-drain: the interrupt/data ready line will be configured
15 as open drain, which is useful if several sensors share the same
16 interrupt line. This is a boolean property.
17 (This binding is taken from pinctrl/pinctrl-bindings.txt)
18 If the requested interrupt is configured as IRQ_TYPE_LEVEL_HIGH or
19 IRQ_TYPE_EDGE_RISING a pull-down resistor is needed to drive the line
20 when it is not active, whereas a pull-up one is needed when interrupt
21 line is configured as IRQ_TYPE_LEVEL_LOW or IRQ_TYPE_EDGE_FALLING.
14- interrupt-parent: should be the phandle for the interrupt controller 22- interrupt-parent: should be the phandle for the interrupt controller
15- interrupts: interrupt mapping for IRQ. It should be configured with 23- interrupts: interrupt mapping for IRQ. It should be configured with
16 flags IRQ_TYPE_LEVEL_HIGH, IRQ_TYPE_EDGE_RISING, IRQ_TYPE_LEVEL_LOW or 24 flags IRQ_TYPE_LEVEL_HIGH, IRQ_TYPE_EDGE_RISING, IRQ_TYPE_LEVEL_LOW or
diff --git a/Documentation/devicetree/bindings/iio/pressure/ms5637.txt b/Documentation/devicetree/bindings/iio/pressure/ms5637.txt
new file mode 100644
index 000000000000..1f43ffa068ac
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/pressure/ms5637.txt
@@ -0,0 +1,17 @@
1* MS5637 - Measurement-Specialties MS5637, MS5805, MS5837 and MS8607 pressure & temperature sensor
2
3Required properties:
4
5 -compatible: should be one of the following
6 meas,ms5637
7 meas,ms5805
8 meas,ms5837
9 meas,ms8607-temppressure
10 -reg: I2C address of the sensor
11
12Example:
13
14ms5637@76 {
15 compatible = "meas,ms5637";
16 reg = <0x76>;
17};
diff --git a/Documentation/devicetree/bindings/iio/st-sensors.txt b/Documentation/devicetree/bindings/iio/st-sensors.txt
index eaa8fbba34e2..1e305f61f3df 100644
--- a/Documentation/devicetree/bindings/iio/st-sensors.txt
+++ b/Documentation/devicetree/bindings/iio/st-sensors.txt
@@ -45,6 +45,7 @@ Accelerometers:
45- st,lis2dh12-accel 45- st,lis2dh12-accel
46- st,h3lis331dl-accel 46- st,h3lis331dl-accel
47- st,lng2dm-accel 47- st,lng2dm-accel
48- st,lis3l02dq
48 49
49Gyroscopes: 50Gyroscopes:
50- st,l3g4200d-gyro 51- st,l3g4200d-gyro
@@ -52,6 +53,7 @@ Gyroscopes:
52- st,lsm330dl-gyro 53- st,lsm330dl-gyro
53- st,lsm330dlc-gyro 54- st,lsm330dlc-gyro
54- st,l3gd20-gyro 55- st,l3gd20-gyro
56- st,l3gd20h-gyro
55- st,l3g4is-gyro 57- st,l3g4is-gyro
56- st,lsm330-gyro 58- st,lsm330-gyro
57- st,lsm9ds0-gyro 59- st,lsm9ds0-gyro
diff --git a/Documentation/devicetree/bindings/iio/temperature/tsys01.txt b/Documentation/devicetree/bindings/iio/temperature/tsys01.txt
new file mode 100644
index 000000000000..0d5cc5595d0c
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/temperature/tsys01.txt
@@ -0,0 +1,19 @@
1* TSYS01 - Measurement Specialties temperature sensor
2
3Required properties:
4
5 - compatible: should be "meas,tsys01"
6 - reg: I2C address of the sensor (changeable via CSB pin)
7
8 ------------------------
9 | CSB | Device Address |
10 ------------------------
11 1 0x76
12 0 0x77
13
14Example:
15
16tsys01@76 {
17 compatible = "meas,tsys01";
18 reg = <0x76>;
19};
diff --git a/Documentation/devicetree/bindings/iio/timer/stm32-timer-trigger.txt b/Documentation/devicetree/bindings/iio/timer/stm32-timer-trigger.txt
index 55a653d15303..6abc755dbf94 100644
--- a/Documentation/devicetree/bindings/iio/timer/stm32-timer-trigger.txt
+++ b/Documentation/devicetree/bindings/iio/timer/stm32-timer-trigger.txt
@@ -14,7 +14,7 @@ Example:
14 compatible = "st,stm32-timers"; 14 compatible = "st,stm32-timers";
15 reg = <0x40010000 0x400>; 15 reg = <0x40010000 0x400>;
16 clocks = <&rcc 0 160>; 16 clocks = <&rcc 0 160>;
17 clock-names = "clk_int"; 17 clock-names = "int";
18 18
19 timer@0 { 19 timer@0 {
20 compatible = "st,stm32-timer-trigger"; 20 compatible = "st,stm32-timer-trigger";
diff --git a/Documentation/iio/ep93xx_adc.txt b/Documentation/iio/ep93xx_adc.txt
new file mode 100644
index 000000000000..23053e7817bd
--- /dev/null
+++ b/Documentation/iio/ep93xx_adc.txt
@@ -0,0 +1,29 @@
1Cirrus Logic EP93xx ADC driver.
2
31. Overview
4
5The driver is intended to work on both low-end (EP9301, EP9302) devices with
65-channel ADC and high-end (EP9307, EP9312, EP9315) devices with 10-channel
7touchscreen/ADC module.
8
92. Channel numbering
10
11Numbering scheme for channels 0..4 is defined in EP9301 and EP9302 datasheets.
12EP9307, EP9312 and EP9312 have 3 channels more (total 8), but the numbering is
13not defined. So the last three are numbered randomly, let's say.
14
15Assuming ep93xx_adc is IIO device0, you'd find the following entries under
16/sys/bus/iio/devices/iio:device0/:
17
18 +-----------------+---------------+
19 | sysfs entry | ball/pin name |
20 +-----------------+---------------+
21 | in_voltage0_raw | YM |
22 | in_voltage1_raw | SXP |
23 | in_voltage2_raw | SXM |
24 | in_voltage3_raw | SYP |
25 | in_voltage4_raw | SYM |
26 | in_voltage5_raw | XP |
27 | in_voltage6_raw | XM |
28 | in_voltage7_raw | YP |
29 +-----------------+---------------+
diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c
index 8ca8041267ef..f85014fbaa12 100644
--- a/drivers/iio/accel/bmc150-accel-i2c.c
+++ b/drivers/iio/accel/bmc150-accel-i2c.c
@@ -64,6 +64,7 @@ static const struct acpi_device_id bmc150_accel_acpi_match[] = {
64 {"BMA250E", bma250e}, 64 {"BMA250E", bma250e},
65 {"BMA222E", bma222e}, 65 {"BMA222E", bma222e},
66 {"BMA0280", bma280}, 66 {"BMA0280", bma280},
67 {"BOSC0200"},
67 { }, 68 { },
68}; 69};
69MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match); 70MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match);
diff --git a/drivers/iio/accel/da311.c b/drivers/iio/accel/da311.c
index 537cfa8b6edf..c0c1620d2a2f 100644
--- a/drivers/iio/accel/da311.c
+++ b/drivers/iio/accel/da311.c
@@ -139,7 +139,7 @@ static int da311_register_mask_write(struct i2c_client *client, u16 addr,
139/* Init sequence taken from the android driver */ 139/* Init sequence taken from the android driver */
140static int da311_reset(struct i2c_client *client) 140static int da311_reset(struct i2c_client *client)
141{ 141{
142 const struct { 142 static const struct {
143 u16 addr; 143 u16 addr;
144 u8 mask; 144 u8 mask;
145 u8 data; 145 u8 data;
diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
index cb1d83fa19a0..39ab210c44f6 100644
--- a/drivers/iio/accel/sca3000.c
+++ b/drivers/iio/accel/sca3000.c
@@ -36,7 +36,7 @@
36#define SCA3000_LOCKED BIT(5) 36#define SCA3000_LOCKED BIT(5)
37#define SCA3000_EEPROM_CS_ERROR BIT(1) 37#define SCA3000_EEPROM_CS_ERROR BIT(1)
38#define SCA3000_SPI_FRAME_ERROR BIT(0) 38#define SCA3000_SPI_FRAME_ERROR BIT(0)
39 39
40/* All reads done using register decrement so no need to directly access LSBs */ 40/* All reads done using register decrement so no need to directly access LSBs */
41#define SCA3000_REG_X_MSB_ADDR 0x05 41#define SCA3000_REG_X_MSB_ADDR 0x05
42#define SCA3000_REG_Y_MSB_ADDR 0x07 42#define SCA3000_REG_Y_MSB_ADDR 0x07
@@ -74,7 +74,7 @@
74#define SCA3000_REG_INT_STATUS_ADDR 0x16 74#define SCA3000_REG_INT_STATUS_ADDR 0x16
75#define SCA3000_REG_INT_STATUS_THREE_QUARTERS BIT(7) 75#define SCA3000_REG_INT_STATUS_THREE_QUARTERS BIT(7)
76#define SCA3000_REG_INT_STATUS_HALF BIT(6) 76#define SCA3000_REG_INT_STATUS_HALF BIT(6)
77 77
78#define SCA3000_INT_STATUS_FREE_FALL BIT(3) 78#define SCA3000_INT_STATUS_FREE_FALL BIT(3)
79#define SCA3000_INT_STATUS_Y_TRIGGER BIT(2) 79#define SCA3000_INT_STATUS_Y_TRIGGER BIT(2)
80#define SCA3000_INT_STATUS_X_TRIGGER BIT(1) 80#define SCA3000_INT_STATUS_X_TRIGGER BIT(1)
@@ -124,7 +124,7 @@
124 124
125#define SCA3000_REG_INT_MASK_ADDR 0x21 125#define SCA3000_REG_INT_MASK_ADDR 0x21
126#define SCA3000_REG_INT_MASK_PROT_MASK 0x1C 126#define SCA3000_REG_INT_MASK_PROT_MASK 0x1C
127 127
128#define SCA3000_REG_INT_MASK_RING_THREE_QUARTER BIT(7) 128#define SCA3000_REG_INT_MASK_RING_THREE_QUARTER BIT(7)
129#define SCA3000_REG_INT_MASK_RING_HALF BIT(6) 129#define SCA3000_REG_INT_MASK_RING_HALF BIT(6)
130 130
diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h
index 3ad44ce7ae82..0fe521609a3a 100644
--- a/drivers/iio/accel/st_accel.h
+++ b/drivers/iio/accel/st_accel.h
@@ -29,10 +29,13 @@ enum st_accel_type {
29 LIS2DH12, 29 LIS2DH12,
30 LIS3L02DQ, 30 LIS3L02DQ,
31 LNG2DM, 31 LNG2DM,
32 H3LIS331DL,
33 LIS331DL,
34 LIS3LV02DL,
32 ST_ACCEL_MAX, 35 ST_ACCEL_MAX,
33}; 36};
34 37
35#define H3LIS331DL_DRIVER_NAME "h3lis331dl_accel" 38#define H3LIS331DL_ACCEL_DEV_NAME "h3lis331dl_accel"
36#define LIS3LV02DL_ACCEL_DEV_NAME "lis3lv02dl_accel" 39#define LIS3LV02DL_ACCEL_DEV_NAME "lis3lv02dl_accel"
37#define LSM303DLHC_ACCEL_DEV_NAME "lsm303dlhc_accel" 40#define LSM303DLHC_ACCEL_DEV_NAME "lsm303dlhc_accel"
38#define LIS3DH_ACCEL_DEV_NAME "lis3dh" 41#define LIS3DH_ACCEL_DEV_NAME "lis3dh"
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 07d1489cd457..c7709494bed3 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -444,7 +444,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
444 .wai = 0x32, 444 .wai = 0x32,
445 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, 445 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
446 .sensors_supported = { 446 .sensors_supported = {
447 [0] = H3LIS331DL_DRIVER_NAME, 447 [0] = H3LIS331DL_ACCEL_DEV_NAME,
448 }, 448 },
449 .ch = (struct iio_chan_spec *)st_accel_12bit_channels, 449 .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
450 .odr = { 450 .odr = {
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index 543f0ad7fd7e..18cafb9f2468 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -84,7 +84,7 @@ static const struct of_device_id st_accel_of_match[] = {
84 }, 84 },
85 { 85 {
86 .compatible = "st,h3lis331dl-accel", 86 .compatible = "st,h3lis331dl-accel",
87 .data = H3LIS331DL_DRIVER_NAME, 87 .data = H3LIS331DL_ACCEL_DEV_NAME,
88 }, 88 },
89 { 89 {
90 .compatible = "st,lis3l02dq", 90 .compatible = "st,lis3l02dq",
@@ -126,6 +126,9 @@ static const struct i2c_device_id st_accel_id_table[] = {
126 { LIS2DH12_ACCEL_DEV_NAME, LIS2DH12 }, 126 { LIS2DH12_ACCEL_DEV_NAME, LIS2DH12 },
127 { LIS3L02DQ_ACCEL_DEV_NAME, LIS3L02DQ }, 127 { LIS3L02DQ_ACCEL_DEV_NAME, LIS3L02DQ },
128 { LNG2DM_ACCEL_DEV_NAME, LNG2DM }, 128 { LNG2DM_ACCEL_DEV_NAME, LNG2DM },
129 { H3LIS331DL_ACCEL_DEV_NAME, H3LIS331DL },
130 { LIS331DL_ACCEL_DEV_NAME, LIS331DL },
131 { LIS3LV02DL_ACCEL_DEV_NAME, LIS3LV02DL },
129 {}, 132 {},
130}; 133};
131MODULE_DEVICE_TABLE(i2c, st_accel_id_table); 134MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
@@ -144,7 +147,8 @@ static int st_accel_i2c_probe(struct i2c_client *client,
144 adata = iio_priv(indio_dev); 147 adata = iio_priv(indio_dev);
145 148
146 if (client->dev.of_node) { 149 if (client->dev.of_node) {
147 st_sensors_of_i2c_probe(client, st_accel_of_match); 150 st_sensors_of_name_probe(&client->dev, st_accel_of_match,
151 client->name, sizeof(client->name));
148 } else if (ACPI_HANDLE(&client->dev)) { 152 } else if (ACPI_HANDLE(&client->dev)) {
149 ret = st_sensors_match_acpi_device(&client->dev); 153 ret = st_sensors_match_acpi_device(&client->dev);
150 if ((ret < 0) || (ret >= ST_ACCEL_MAX)) 154 if ((ret < 0) || (ret >= ST_ACCEL_MAX))
diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c
index 1a867f5563a4..915fa49085f7 100644
--- a/drivers/iio/accel/st_accel_spi.c
+++ b/drivers/iio/accel/st_accel_spi.c
@@ -18,6 +18,77 @@
18#include <linux/iio/common/st_sensors_spi.h> 18#include <linux/iio/common/st_sensors_spi.h>
19#include "st_accel.h" 19#include "st_accel.h"
20 20
21#ifdef CONFIG_OF
22/*
23 * For new single-chip sensors use <device_name> as compatible string.
24 * For old single-chip devices keep <device_name>-accel to maintain
25 * compatibility
26 */
27static const struct of_device_id st_accel_of_match[] = {
28 {
29 /* An older compatible */
30 .compatible = "st,lis302dl-spi",
31 .data = LIS3LV02DL_ACCEL_DEV_NAME,
32 },
33 {
34 .compatible = "st,lis3lv02dl-accel",
35 .data = LIS3LV02DL_ACCEL_DEV_NAME,
36 },
37 {
38 .compatible = "st,lis3dh-accel",
39 .data = LIS3DH_ACCEL_DEV_NAME,
40 },
41 {
42 .compatible = "st,lsm330d-accel",
43 .data = LSM330D_ACCEL_DEV_NAME,
44 },
45 {
46 .compatible = "st,lsm330dl-accel",
47 .data = LSM330DL_ACCEL_DEV_NAME,
48 },
49 {
50 .compatible = "st,lsm330dlc-accel",
51 .data = LSM330DLC_ACCEL_DEV_NAME,
52 },
53 {
54 .compatible = "st,lis331dlh-accel",
55 .data = LIS331DLH_ACCEL_DEV_NAME,
56 },
57 {
58 .compatible = "st,lsm330-accel",
59 .data = LSM330_ACCEL_DEV_NAME,
60 },
61 {
62 .compatible = "st,lsm303agr-accel",
63 .data = LSM303AGR_ACCEL_DEV_NAME,
64 },
65 {
66 .compatible = "st,lis2dh12-accel",
67 .data = LIS2DH12_ACCEL_DEV_NAME,
68 },
69 {
70 .compatible = "st,lis3l02dq",
71 .data = LIS3L02DQ_ACCEL_DEV_NAME,
72 },
73 {
74 .compatible = "st,lng2dm-accel",
75 .data = LNG2DM_ACCEL_DEV_NAME,
76 },
77 {
78 .compatible = "st,h3lis331dl-accel",
79 .data = H3LIS331DL_ACCEL_DEV_NAME,
80 },
81 {
82 .compatible = "st,lis331dl-accel",
83 .data = LIS331DL_ACCEL_DEV_NAME,
84 },
85 {}
86};
87MODULE_DEVICE_TABLE(of, st_accel_of_match);
88#else
89#define st_accel_of_match NULL
90#endif
91
21static int st_accel_spi_probe(struct spi_device *spi) 92static int st_accel_spi_probe(struct spi_device *spi)
22{ 93{
23 struct iio_dev *indio_dev; 94 struct iio_dev *indio_dev;
@@ -30,6 +101,8 @@ static int st_accel_spi_probe(struct spi_device *spi)
30 101
31 adata = iio_priv(indio_dev); 102 adata = iio_priv(indio_dev);
32 103
104 st_sensors_of_name_probe(&spi->dev, st_accel_of_match,
105 spi->modalias, sizeof(spi->modalias));
33 st_sensors_spi_configure(indio_dev, spi, adata); 106 st_sensors_spi_configure(indio_dev, spi, adata);
34 107
35 err = st_accel_common_probe(indio_dev); 108 err = st_accel_common_probe(indio_dev);
@@ -57,22 +130,17 @@ static const struct spi_device_id st_accel_id_table[] = {
57 { LIS2DH12_ACCEL_DEV_NAME }, 130 { LIS2DH12_ACCEL_DEV_NAME },
58 { LIS3L02DQ_ACCEL_DEV_NAME }, 131 { LIS3L02DQ_ACCEL_DEV_NAME },
59 { LNG2DM_ACCEL_DEV_NAME }, 132 { LNG2DM_ACCEL_DEV_NAME },
133 { H3LIS331DL_ACCEL_DEV_NAME },
134 { LIS331DL_ACCEL_DEV_NAME },
135 { LIS3LV02DL_ACCEL_DEV_NAME },
60 {}, 136 {},
61}; 137};
62MODULE_DEVICE_TABLE(spi, st_accel_id_table); 138MODULE_DEVICE_TABLE(spi, st_accel_id_table);
63 139
64#ifdef CONFIG_OF
65static const struct of_device_id lis302dl_spi_dt_ids[] = {
66 { .compatible = "st,lis302dl-spi" },
67 {}
68};
69MODULE_DEVICE_TABLE(of, lis302dl_spi_dt_ids);
70#endif
71
72static struct spi_driver st_accel_driver = { 140static struct spi_driver st_accel_driver = {
73 .driver = { 141 .driver = {
74 .name = "st-accel-spi", 142 .name = "st-accel-spi",
75 .of_match_table = of_match_ptr(lis302dl_spi_dt_ids), 143 .of_match_table = of_match_ptr(st_accel_of_match),
76 }, 144 },
77 .probe = st_accel_spi_probe, 145 .probe = st_accel_spi_probe,
78 .remove = st_accel_spi_remove, 146 .remove = st_accel_spi_remove,
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 614fa41559b1..e4eeebac5297 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -239,6 +239,15 @@ config DA9150_GPADC
239 To compile this driver as a module, choose M here: the module will be 239 To compile this driver as a module, choose M here: the module will be
240 called berlin2-adc. 240 called berlin2-adc.
241 241
242config DLN2_ADC
243 tristate "Diolan DLN-2 ADC driver support"
244 depends on MFD_DLN2
245 help
246 Say yes here to build support for Diolan DLN-2 ADC.
247
248 This driver can also be built as a module. If so, the module will be
249 called adc_dln2.
250
242config ENVELOPE_DETECTOR 251config ENVELOPE_DETECTOR
243 tristate "Envelope detector using a DAC and a comparator" 252 tristate "Envelope detector using a DAC and a comparator"
244 depends on OF 253 depends on OF
@@ -249,6 +258,17 @@ config ENVELOPE_DETECTOR
249 To compile this driver as a module, choose M here: the module will be 258 To compile this driver as a module, choose M here: the module will be
250 called envelope-detector. 259 called envelope-detector.
251 260
261config EP93XX_ADC
262 tristate "Cirrus Logic EP93XX ADC driver"
263 depends on ARCH_EP93XX
264 help
265 Driver for the ADC module on the EP93XX series of SoC from Cirrus Logic.
266 It's recommended to switch on CONFIG_HIGH_RES_TIMERS option, in this
267 case driver will reduce its CPU usage by 90% in some use cases.
268
269 To compile this driver as a module, choose M here: the module will be
270 called ep93xx_adc.
271
252config EXYNOS_ADC 272config EXYNOS_ADC
253 tristate "Exynos ADC driver support" 273 tristate "Exynos ADC driver support"
254 depends on ARCH_EXYNOS || ARCH_S3C24XX || ARCH_S3C64XX || (OF && COMPILE_TEST) 274 depends on ARCH_EXYNOS || ARCH_S3C24XX || ARCH_S3C64XX || (OF && COMPILE_TEST)
@@ -322,7 +342,7 @@ config INA2XX_ADC
322 This driver is mutually exclusive with the HWMON version. 342 This driver is mutually exclusive with the HWMON version.
323 343
324config IMX7D_ADC 344config IMX7D_ADC
325 tristate "IMX7D ADC driver" 345 tristate "Freescale IMX7D ADC driver"
326 depends on ARCH_MXC || COMPILE_TEST 346 depends on ARCH_MXC || COMPILE_TEST
327 depends on HAS_IOMEM 347 depends on HAS_IOMEM
328 help 348 help
@@ -362,6 +382,16 @@ config LPC32XX_ADC
362 activate only one via device tree selection. Provides direct access 382 activate only one via device tree selection. Provides direct access
363 via sysfs. 383 via sysfs.
364 384
385config LTC2471
386 tristate "Linear Technology LTC2471 and LTC2473 ADC driver"
387 depends on I2C
388 help
389 Say yes here to build support for Linear Technology LTC2471 and
390 LTC2473 16-bit I2C ADC.
391
392 This driver can also be built as a module. If so, the module will
393 be called ltc2471.
394
365config LTC2485 395config LTC2485
366 tristate "Linear Technology LTC2485 ADC driver" 396 tristate "Linear Technology LTC2485 ADC driver"
367 depends on I2C 397 depends on I2C
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index b546736a5541..9874e05f52d7 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -24,7 +24,9 @@ obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o
24obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o 24obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
25obj-$(CONFIG_CPCAP_ADC) += cpcap-adc.o 25obj-$(CONFIG_CPCAP_ADC) += cpcap-adc.o
26obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o 26obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
27obj-$(CONFIG_DLN2_ADC) += dln2-adc.o
27obj-$(CONFIG_ENVELOPE_DETECTOR) += envelope-detector.o 28obj-$(CONFIG_ENVELOPE_DETECTOR) += envelope-detector.o
29obj-$(CONFIG_EP93XX_ADC) += ep93xx_adc.o
28obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o 30obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
29obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o 31obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o
30obj-$(CONFIG_HI8435) += hi8435.o 32obj-$(CONFIG_HI8435) += hi8435.o
@@ -34,6 +36,7 @@ obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o
34obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o 36obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
35obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o 37obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o
36obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o 38obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
39obj-$(CONFIG_LTC2471) += ltc2471.o
37obj-$(CONFIG_LTC2485) += ltc2485.o 40obj-$(CONFIG_LTC2485) += ltc2485.o
38obj-$(CONFIG_LTC2497) += ltc2497.o 41obj-$(CONFIG_LTC2497) += ltc2497.o
39obj-$(CONFIG_MAX1027) += max1027.o 42obj-$(CONFIG_MAX1027) += max1027.o
diff --git a/drivers/iio/adc/ad7766.c b/drivers/iio/adc/ad7766.c
index 75cca42b6e70..ce45037295d8 100644
--- a/drivers/iio/adc/ad7766.c
+++ b/drivers/iio/adc/ad7766.c
@@ -103,8 +103,7 @@ static int ad7766_preenable(struct iio_dev *indio_dev)
103 return ret; 103 return ret;
104 } 104 }
105 105
106 if (ad7766->pd_gpio) 106 gpiod_set_value(ad7766->pd_gpio, 0);
107 gpiod_set_value(ad7766->pd_gpio, 0);
108 107
109 return 0; 108 return 0;
110} 109}
@@ -113,8 +112,7 @@ static int ad7766_postdisable(struct iio_dev *indio_dev)
113{ 112{
114 struct ad7766 *ad7766 = iio_priv(indio_dev); 113 struct ad7766 *ad7766 = iio_priv(indio_dev);
115 114
116 if (ad7766->pd_gpio) 115 gpiod_set_value(ad7766->pd_gpio, 1);
117 gpiod_set_value(ad7766->pd_gpio, 1);
118 116
119 /* 117 /*
120 * The PD pin is synchronous to the clock, so give it some time to 118 * The PD pin is synchronous to the clock, so give it some time to
diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
index e10dca3ed74b..bc5b38e3a147 100644
--- a/drivers/iio/adc/at91-sama5d2_adc.c
+++ b/drivers/iio/adc/at91-sama5d2_adc.c
@@ -25,6 +25,11 @@
25#include <linux/wait.h> 25#include <linux/wait.h>
26#include <linux/iio/iio.h> 26#include <linux/iio/iio.h>
27#include <linux/iio/sysfs.h> 27#include <linux/iio/sysfs.h>
28#include <linux/iio/buffer.h>
29#include <linux/iio/trigger.h>
30#include <linux/iio/trigger_consumer.h>
31#include <linux/iio/triggered_buffer.h>
32#include <linux/pinctrl/consumer.h>
28#include <linux/regulator/consumer.h> 33#include <linux/regulator/consumer.h>
29 34
30/* Control Register */ 35/* Control Register */
@@ -132,6 +137,17 @@
132#define AT91_SAMA5D2_PRESSR 0xbc 137#define AT91_SAMA5D2_PRESSR 0xbc
133/* Trigger Register */ 138/* Trigger Register */
134#define AT91_SAMA5D2_TRGR 0xc0 139#define AT91_SAMA5D2_TRGR 0xc0
140/* Mask for TRGMOD field of TRGR register */
141#define AT91_SAMA5D2_TRGR_TRGMOD_MASK GENMASK(2, 0)
142/* No trigger, only software trigger can start conversions */
143#define AT91_SAMA5D2_TRGR_TRGMOD_NO_TRIGGER 0
144/* Trigger Mode external trigger rising edge */
145#define AT91_SAMA5D2_TRGR_TRGMOD_EXT_TRIG_RISE 1
146/* Trigger Mode external trigger falling edge */
147#define AT91_SAMA5D2_TRGR_TRGMOD_EXT_TRIG_FALL 2
148/* Trigger Mode external trigger any edge */
149#define AT91_SAMA5D2_TRGR_TRGMOD_EXT_TRIG_ANY 3
150
135/* Correction Select Register */ 151/* Correction Select Register */
136#define AT91_SAMA5D2_COSR 0xd0 152#define AT91_SAMA5D2_COSR 0xd0
137/* Correction Value Register */ 153/* Correction Value Register */
@@ -145,14 +161,29 @@
145/* Version Register */ 161/* Version Register */
146#define AT91_SAMA5D2_VERSION 0xfc 162#define AT91_SAMA5D2_VERSION 0xfc
147 163
164#define AT91_SAMA5D2_HW_TRIG_CNT 3
165#define AT91_SAMA5D2_SINGLE_CHAN_CNT 12
166#define AT91_SAMA5D2_DIFF_CHAN_CNT 6
167
168/*
169 * Maximum number of bytes to hold conversion from all channels
170 * plus the timestamp
171 */
172#define AT91_BUFFER_MAX_BYTES ((AT91_SAMA5D2_SINGLE_CHAN_CNT + \
173 AT91_SAMA5D2_DIFF_CHAN_CNT) * 2 + 8)
174
175#define AT91_BUFFER_MAX_HWORDS (AT91_BUFFER_MAX_BYTES / 2)
176
148#define AT91_SAMA5D2_CHAN_SINGLE(num, addr) \ 177#define AT91_SAMA5D2_CHAN_SINGLE(num, addr) \
149 { \ 178 { \
150 .type = IIO_VOLTAGE, \ 179 .type = IIO_VOLTAGE, \
151 .channel = num, \ 180 .channel = num, \
152 .address = addr, \ 181 .address = addr, \
182 .scan_index = num, \
153 .scan_type = { \ 183 .scan_type = { \
154 .sign = 'u', \ 184 .sign = 'u', \
155 .realbits = 12, \ 185 .realbits = 12, \
186 .storagebits = 16, \
156 }, \ 187 }, \
157 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 188 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
158 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 189 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
@@ -168,9 +199,11 @@
168 .channel = num, \ 199 .channel = num, \
169 .channel2 = num2, \ 200 .channel2 = num2, \
170 .address = addr, \ 201 .address = addr, \
202 .scan_index = num + AT91_SAMA5D2_SINGLE_CHAN_CNT, \
171 .scan_type = { \ 203 .scan_type = { \
172 .sign = 's', \ 204 .sign = 's', \
173 .realbits = 12, \ 205 .realbits = 12, \
206 .storagebits = 16, \
174 }, \ 207 }, \
175 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 208 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
176 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 209 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
@@ -188,6 +221,12 @@ struct at91_adc_soc_info {
188 unsigned max_sample_rate; 221 unsigned max_sample_rate;
189}; 222};
190 223
224struct at91_adc_trigger {
225 char *name;
226 unsigned int trgmod_value;
227 unsigned int edge_type;
228};
229
191struct at91_adc_state { 230struct at91_adc_state {
192 void __iomem *base; 231 void __iomem *base;
193 int irq; 232 int irq;
@@ -195,11 +234,14 @@ struct at91_adc_state {
195 struct regulator *reg; 234 struct regulator *reg;
196 struct regulator *vref; 235 struct regulator *vref;
197 int vref_uv; 236 int vref_uv;
237 struct iio_trigger *trig;
238 const struct at91_adc_trigger *selected_trig;
198 const struct iio_chan_spec *chan; 239 const struct iio_chan_spec *chan;
199 bool conversion_done; 240 bool conversion_done;
200 u32 conversion_value; 241 u32 conversion_value;
201 struct at91_adc_soc_info soc_info; 242 struct at91_adc_soc_info soc_info;
202 wait_queue_head_t wq_data_available; 243 wait_queue_head_t wq_data_available;
244 u16 buffer[AT91_BUFFER_MAX_HWORDS];
203 /* 245 /*
204 * lock to prevent concurrent 'single conversion' requests through 246 * lock to prevent concurrent 'single conversion' requests through
205 * sysfs. 247 * sysfs.
@@ -207,6 +249,24 @@ struct at91_adc_state {
207 struct mutex lock; 249 struct mutex lock;
208}; 250};
209 251
252static const struct at91_adc_trigger at91_adc_trigger_list[] = {
253 {
254 .name = "external_rising",
255 .trgmod_value = AT91_SAMA5D2_TRGR_TRGMOD_EXT_TRIG_RISE,
256 .edge_type = IRQ_TYPE_EDGE_RISING,
257 },
258 {
259 .name = "external_falling",
260 .trgmod_value = AT91_SAMA5D2_TRGR_TRGMOD_EXT_TRIG_FALL,
261 .edge_type = IRQ_TYPE_EDGE_FALLING,
262 },
263 {
264 .name = "external_any",
265 .trgmod_value = AT91_SAMA5D2_TRGR_TRGMOD_EXT_TRIG_ANY,
266 .edge_type = IRQ_TYPE_EDGE_BOTH,
267 },
268};
269
210static const struct iio_chan_spec at91_adc_channels[] = { 270static const struct iio_chan_spec at91_adc_channels[] = {
211 AT91_SAMA5D2_CHAN_SINGLE(0, 0x50), 271 AT91_SAMA5D2_CHAN_SINGLE(0, 0x50),
212 AT91_SAMA5D2_CHAN_SINGLE(1, 0x54), 272 AT91_SAMA5D2_CHAN_SINGLE(1, 0x54),
@@ -226,12 +286,132 @@ static const struct iio_chan_spec at91_adc_channels[] = {
226 AT91_SAMA5D2_CHAN_DIFF(6, 7, 0x68), 286 AT91_SAMA5D2_CHAN_DIFF(6, 7, 0x68),
227 AT91_SAMA5D2_CHAN_DIFF(8, 9, 0x70), 287 AT91_SAMA5D2_CHAN_DIFF(8, 9, 0x70),
228 AT91_SAMA5D2_CHAN_DIFF(10, 11, 0x78), 288 AT91_SAMA5D2_CHAN_DIFF(10, 11, 0x78),
289 IIO_CHAN_SOFT_TIMESTAMP(AT91_SAMA5D2_SINGLE_CHAN_CNT
290 + AT91_SAMA5D2_DIFF_CHAN_CNT + 1),
291};
292
293static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state)
294{
295 struct iio_dev *indio = iio_trigger_get_drvdata(trig);
296 struct at91_adc_state *st = iio_priv(indio);
297 u32 status = at91_adc_readl(st, AT91_SAMA5D2_TRGR);
298 u8 bit;
299
300 /* clear TRGMOD */
301 status &= ~AT91_SAMA5D2_TRGR_TRGMOD_MASK;
302
303 if (state)
304 status |= st->selected_trig->trgmod_value;
305
306 /* set/unset hw trigger */
307 at91_adc_writel(st, AT91_SAMA5D2_TRGR, status);
308
309 for_each_set_bit(bit, indio->active_scan_mask, indio->num_channels) {
310 struct iio_chan_spec const *chan = indio->channels + bit;
311
312 if (state) {
313 at91_adc_writel(st, AT91_SAMA5D2_CHER,
314 BIT(chan->channel));
315 at91_adc_writel(st, AT91_SAMA5D2_IER,
316 BIT(chan->channel));
317 } else {
318 at91_adc_writel(st, AT91_SAMA5D2_IDR,
319 BIT(chan->channel));
320 at91_adc_writel(st, AT91_SAMA5D2_CHDR,
321 BIT(chan->channel));
322 }
323 }
324
325 return 0;
326}
327
328static int at91_adc_reenable_trigger(struct iio_trigger *trig)
329{
330 struct iio_dev *indio = iio_trigger_get_drvdata(trig);
331 struct at91_adc_state *st = iio_priv(indio);
332
333 enable_irq(st->irq);
334
335 /* Needed to ACK the DRDY interruption */
336 at91_adc_readl(st, AT91_SAMA5D2_LCDR);
337 return 0;
338}
339
340static const struct iio_trigger_ops at91_adc_trigger_ops = {
341 .owner = THIS_MODULE,
342 .set_trigger_state = &at91_adc_configure_trigger,
343 .try_reenable = &at91_adc_reenable_trigger,
229}; 344};
230 345
346static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *indio,
347 char *trigger_name)
348{
349 struct iio_trigger *trig;
350 int ret;
351
352 trig = devm_iio_trigger_alloc(&indio->dev, "%s-dev%d-%s", indio->name,
353 indio->id, trigger_name);
354 if (!trig)
355 return NULL;
356
357 trig->dev.parent = indio->dev.parent;
358 iio_trigger_set_drvdata(trig, indio);
359 trig->ops = &at91_adc_trigger_ops;
360
361 ret = devm_iio_trigger_register(&indio->dev, trig);
362 if (ret)
363 return ERR_PTR(ret);
364
365 return trig;
366}
367
368static int at91_adc_trigger_init(struct iio_dev *indio)
369{
370 struct at91_adc_state *st = iio_priv(indio);
371
372 st->trig = at91_adc_allocate_trigger(indio, st->selected_trig->name);
373 if (IS_ERR(st->trig)) {
374 dev_err(&indio->dev,
375 "could not allocate trigger\n");
376 return PTR_ERR(st->trig);
377 }
378
379 return 0;
380}
381
382static irqreturn_t at91_adc_trigger_handler(int irq, void *p)
383{
384 struct iio_poll_func *pf = p;
385 struct iio_dev *indio = pf->indio_dev;
386 struct at91_adc_state *st = iio_priv(indio);
387 int i = 0;
388 u8 bit;
389
390 for_each_set_bit(bit, indio->active_scan_mask, indio->num_channels) {
391 struct iio_chan_spec const *chan = indio->channels + bit;
392
393 st->buffer[i] = at91_adc_readl(st, chan->address);
394 i++;
395 }
396
397 iio_push_to_buffers_with_timestamp(indio, st->buffer, pf->timestamp);
398
399 iio_trigger_notify_done(indio->trig);
400
401 return IRQ_HANDLED;
402}
403
404static int at91_adc_buffer_init(struct iio_dev *indio)
405{
406 return devm_iio_triggered_buffer_setup(&indio->dev, indio,
407 &iio_pollfunc_store_time,
408 &at91_adc_trigger_handler, NULL);
409}
410
231static unsigned at91_adc_startup_time(unsigned startup_time_min, 411static unsigned at91_adc_startup_time(unsigned startup_time_min,
232 unsigned adc_clk_khz) 412 unsigned adc_clk_khz)
233{ 413{
234 const unsigned startup_lookup[] = { 414 static const unsigned int startup_lookup[] = {
235 0, 8, 16, 24, 415 0, 8, 16, 24,
236 64, 80, 96, 112, 416 64, 80, 96, 112,
237 512, 576, 640, 704, 417 512, 576, 640, 704,
@@ -293,14 +473,18 @@ static irqreturn_t at91_adc_interrupt(int irq, void *private)
293 u32 status = at91_adc_readl(st, AT91_SAMA5D2_ISR); 473 u32 status = at91_adc_readl(st, AT91_SAMA5D2_ISR);
294 u32 imr = at91_adc_readl(st, AT91_SAMA5D2_IMR); 474 u32 imr = at91_adc_readl(st, AT91_SAMA5D2_IMR);
295 475
296 if (status & imr) { 476 if (!(status & imr))
477 return IRQ_NONE;
478
479 if (iio_buffer_enabled(indio)) {
480 disable_irq_nosync(irq);
481 iio_trigger_poll(indio->trig);
482 } else {
297 st->conversion_value = at91_adc_readl(st, st->chan->address); 483 st->conversion_value = at91_adc_readl(st, st->chan->address);
298 st->conversion_done = true; 484 st->conversion_done = true;
299 wake_up_interruptible(&st->wq_data_available); 485 wake_up_interruptible(&st->wq_data_available);
300 return IRQ_HANDLED;
301 } 486 }
302 487 return IRQ_HANDLED;
303 return IRQ_NONE;
304} 488}
305 489
306static int at91_adc_read_raw(struct iio_dev *indio_dev, 490static int at91_adc_read_raw(struct iio_dev *indio_dev,
@@ -313,6 +497,11 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev,
313 497
314 switch (mask) { 498 switch (mask) {
315 case IIO_CHAN_INFO_RAW: 499 case IIO_CHAN_INFO_RAW:
500 /* we cannot use software trigger if hw trigger enabled */
501 ret = iio_device_claim_direct_mode(indio_dev);
502 if (ret)
503 return ret;
504
316 mutex_lock(&st->lock); 505 mutex_lock(&st->lock);
317 506
318 st->chan = chan; 507 st->chan = chan;
@@ -344,6 +533,8 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev,
344 at91_adc_writel(st, AT91_SAMA5D2_CHDR, BIT(chan->channel)); 533 at91_adc_writel(st, AT91_SAMA5D2_CHDR, BIT(chan->channel));
345 534
346 mutex_unlock(&st->lock); 535 mutex_unlock(&st->lock);
536
537 iio_device_release_direct_mode(indio_dev);
347 return ret; 538 return ret;
348 539
349 case IIO_CHAN_INFO_SCALE: 540 case IIO_CHAN_INFO_SCALE:
@@ -386,12 +577,27 @@ static const struct iio_info at91_adc_info = {
386 .driver_module = THIS_MODULE, 577 .driver_module = THIS_MODULE,
387}; 578};
388 579
580static void at91_adc_hw_init(struct at91_adc_state *st)
581{
582 at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST);
583 at91_adc_writel(st, AT91_SAMA5D2_IDR, 0xffffffff);
584 /*
585 * Transfer field must be set to 2 according to the datasheet and
586 * allows different analog settings for each channel.
587 */
588 at91_adc_writel(st, AT91_SAMA5D2_MR,
589 AT91_SAMA5D2_MR_TRANSFER(2) | AT91_SAMA5D2_MR_ANACH);
590
591 at91_adc_setup_samp_freq(st, st->soc_info.min_sample_rate);
592}
593
389static int at91_adc_probe(struct platform_device *pdev) 594static int at91_adc_probe(struct platform_device *pdev)
390{ 595{
391 struct iio_dev *indio_dev; 596 struct iio_dev *indio_dev;
392 struct at91_adc_state *st; 597 struct at91_adc_state *st;
393 struct resource *res; 598 struct resource *res;
394 int ret; 599 int ret, i;
600 u32 edge_type;
395 601
396 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); 602 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st));
397 if (!indio_dev) 603 if (!indio_dev)
@@ -432,6 +638,27 @@ static int at91_adc_probe(struct platform_device *pdev)
432 return ret; 638 return ret;
433 } 639 }
434 640
641 ret = of_property_read_u32(pdev->dev.of_node,
642 "atmel,trigger-edge-type", &edge_type);
643 if (ret) {
644 dev_err(&pdev->dev,
645 "invalid or missing value for atmel,trigger-edge-type\n");
646 return ret;
647 }
648
649 st->selected_trig = NULL;
650
651 for (i = 0; i < AT91_SAMA5D2_HW_TRIG_CNT; i++)
652 if (at91_adc_trigger_list[i].edge_type == edge_type) {
653 st->selected_trig = &at91_adc_trigger_list[i];
654 break;
655 }
656
657 if (!st->selected_trig) {
658 dev_err(&pdev->dev, "invalid external trigger edge value\n");
659 return -EINVAL;
660 }
661
435 init_waitqueue_head(&st->wq_data_available); 662 init_waitqueue_head(&st->wq_data_available);
436 mutex_init(&st->lock); 663 mutex_init(&st->lock);
437 664
@@ -482,16 +709,7 @@ static int at91_adc_probe(struct platform_device *pdev)
482 goto vref_disable; 709 goto vref_disable;
483 } 710 }
484 711
485 at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST); 712 at91_adc_hw_init(st);
486 at91_adc_writel(st, AT91_SAMA5D2_IDR, 0xffffffff);
487 /*
488 * Transfer field must be set to 2 according to the datasheet and
489 * allows different analog settings for each channel.
490 */
491 at91_adc_writel(st, AT91_SAMA5D2_MR,
492 AT91_SAMA5D2_MR_TRANSFER(2) | AT91_SAMA5D2_MR_ANACH);
493
494 at91_adc_setup_samp_freq(st, st->soc_info.min_sample_rate);
495 713
496 ret = clk_prepare_enable(st->per_clk); 714 ret = clk_prepare_enable(st->per_clk);
497 if (ret) 715 if (ret)
@@ -499,10 +717,25 @@ static int at91_adc_probe(struct platform_device *pdev)
499 717
500 platform_set_drvdata(pdev, indio_dev); 718 platform_set_drvdata(pdev, indio_dev);
501 719
720 ret = at91_adc_buffer_init(indio_dev);
721 if (ret < 0) {
722 dev_err(&pdev->dev, "couldn't initialize the buffer.\n");
723 goto per_clk_disable_unprepare;
724 }
725
726 ret = at91_adc_trigger_init(indio_dev);
727 if (ret < 0) {
728 dev_err(&pdev->dev, "couldn't setup the triggers.\n");
729 goto per_clk_disable_unprepare;
730 }
731
502 ret = iio_device_register(indio_dev); 732 ret = iio_device_register(indio_dev);
503 if (ret < 0) 733 if (ret < 0)
504 goto per_clk_disable_unprepare; 734 goto per_clk_disable_unprepare;
505 735
736 dev_info(&pdev->dev, "setting up trigger as %s\n",
737 st->selected_trig->name);
738
506 dev_info(&pdev->dev, "version: %x\n", 739 dev_info(&pdev->dev, "version: %x\n",
507 readl_relaxed(st->base + AT91_SAMA5D2_VERSION)); 740 readl_relaxed(st->base + AT91_SAMA5D2_VERSION));
508 741
@@ -532,6 +765,69 @@ static int at91_adc_remove(struct platform_device *pdev)
532 return 0; 765 return 0;
533} 766}
534 767
768static __maybe_unused int at91_adc_suspend(struct device *dev)
769{
770 struct iio_dev *indio_dev =
771 platform_get_drvdata(to_platform_device(dev));
772 struct at91_adc_state *st = iio_priv(indio_dev);
773
774 /*
775 * Do a sofware reset of the ADC before we go to suspend.
776 * this will ensure that all pins are free from being muxed by the ADC
777 * and can be used by for other devices.
778 * Otherwise, ADC will hog them and we can't go to suspend mode.
779 */
780 at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST);
781
782 clk_disable_unprepare(st->per_clk);
783 regulator_disable(st->vref);
784 regulator_disable(st->reg);
785
786 return pinctrl_pm_select_sleep_state(dev);
787}
788
789static __maybe_unused int at91_adc_resume(struct device *dev)
790{
791 struct iio_dev *indio_dev =
792 platform_get_drvdata(to_platform_device(dev));
793 struct at91_adc_state *st = iio_priv(indio_dev);
794 int ret;
795
796 ret = pinctrl_pm_select_default_state(dev);
797 if (ret)
798 goto resume_failed;
799
800 ret = regulator_enable(st->reg);
801 if (ret)
802 goto resume_failed;
803
804 ret = regulator_enable(st->vref);
805 if (ret)
806 goto reg_disable_resume;
807
808 ret = clk_prepare_enable(st->per_clk);
809 if (ret)
810 goto vref_disable_resume;
811
812 at91_adc_hw_init(st);
813
814 /* reconfiguring trigger hardware state */
815 if (iio_buffer_enabled(indio_dev))
816 at91_adc_configure_trigger(st->trig, true);
817
818 return 0;
819
820vref_disable_resume:
821 regulator_disable(st->vref);
822reg_disable_resume:
823 regulator_disable(st->reg);
824resume_failed:
825 dev_err(&indio_dev->dev, "failed to resume\n");
826 return ret;
827}
828
829static SIMPLE_DEV_PM_OPS(at91_adc_pm_ops, at91_adc_suspend, at91_adc_resume);
830
535static const struct of_device_id at91_adc_dt_match[] = { 831static const struct of_device_id at91_adc_dt_match[] = {
536 { 832 {
537 .compatible = "atmel,sama5d2-adc", 833 .compatible = "atmel,sama5d2-adc",
@@ -547,6 +843,7 @@ static struct platform_driver at91_adc_driver = {
547 .driver = { 843 .driver = {
548 .name = "at91-sama5d2_adc", 844 .name = "at91-sama5d2_adc",
549 .of_match_table = at91_adc_dt_match, 845 .of_match_table = at91_adc_dt_match,
846 .pm = &at91_adc_pm_ops,
550 }, 847 },
551}; 848};
552module_platform_driver(at91_adc_driver) 849module_platform_driver(at91_adc_driver)
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 34b928cefeed..15109728cae7 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -799,7 +799,7 @@ static u32 calc_startup_ticks_9x5(u32 startup_time, u32 adc_clk_khz)
799 * For sama5d3x and at91sam9x5, the formula changes to: 799 * For sama5d3x and at91sam9x5, the formula changes to:
800 * Startup Time = <lookup_table_value> / ADC Clock 800 * Startup Time = <lookup_table_value> / ADC Clock
801 */ 801 */
802 const int startup_lookup[] = { 802 static const int startup_lookup[] = {
803 0, 8, 16, 24, 803 0, 8, 16, 24,
804 64, 80, 96, 112, 804 64, 80, 96, 112,
805 512, 576, 640, 704, 805 512, 576, 640, 704,
diff --git a/drivers/iio/adc/dln2-adc.c b/drivers/iio/adc/dln2-adc.c
new file mode 100644
index 000000000000..ab8d6aed5085
--- /dev/null
+++ b/drivers/iio/adc/dln2-adc.c
@@ -0,0 +1,722 @@
1/*
2 * Driver for the Diolan DLN-2 USB-ADC adapter
3 *
4 * Copyright (c) 2017 Jack Andersen
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/types.h>
14#include <linux/platform_device.h>
15#include <linux/mfd/dln2.h>
16
17#include <linux/iio/iio.h>
18#include <linux/iio/sysfs.h>
19#include <linux/iio/trigger.h>
20#include <linux/iio/trigger_consumer.h>
21#include <linux/iio/triggered_buffer.h>
22#include <linux/iio/buffer.h>
23#include <linux/iio/kfifo_buf.h>
24
25#define DLN2_ADC_MOD_NAME "dln2-adc"
26
27#define DLN2_ADC_ID 0x06
28
29#define DLN2_ADC_GET_CHANNEL_COUNT DLN2_CMD(0x01, DLN2_ADC_ID)
30#define DLN2_ADC_ENABLE DLN2_CMD(0x02, DLN2_ADC_ID)
31#define DLN2_ADC_DISABLE DLN2_CMD(0x03, DLN2_ADC_ID)
32#define DLN2_ADC_CHANNEL_ENABLE DLN2_CMD(0x05, DLN2_ADC_ID)
33#define DLN2_ADC_CHANNEL_DISABLE DLN2_CMD(0x06, DLN2_ADC_ID)
34#define DLN2_ADC_SET_RESOLUTION DLN2_CMD(0x08, DLN2_ADC_ID)
35#define DLN2_ADC_CHANNEL_GET_VAL DLN2_CMD(0x0A, DLN2_ADC_ID)
36#define DLN2_ADC_CHANNEL_GET_ALL_VAL DLN2_CMD(0x0B, DLN2_ADC_ID)
37#define DLN2_ADC_CHANNEL_SET_CFG DLN2_CMD(0x0C, DLN2_ADC_ID)
38#define DLN2_ADC_CHANNEL_GET_CFG DLN2_CMD(0x0D, DLN2_ADC_ID)
39#define DLN2_ADC_CONDITION_MET_EV DLN2_CMD(0x10, DLN2_ADC_ID)
40
41#define DLN2_ADC_EVENT_NONE 0
42#define DLN2_ADC_EVENT_BELOW 1
43#define DLN2_ADC_EVENT_LEVEL_ABOVE 2
44#define DLN2_ADC_EVENT_OUTSIDE 3
45#define DLN2_ADC_EVENT_INSIDE 4
46#define DLN2_ADC_EVENT_ALWAYS 5
47
48#define DLN2_ADC_MAX_CHANNELS 8
49#define DLN2_ADC_DATA_BITS 10
50
51/*
52 * Plays similar role to iio_demux_table in subsystem core; except allocated
53 * in a fixed 8-element array.
54 */
55struct dln2_adc_demux_table {
56 unsigned int from;
57 unsigned int to;
58 unsigned int length;
59};
60
61struct dln2_adc {
62 struct platform_device *pdev;
63 struct iio_chan_spec iio_channels[DLN2_ADC_MAX_CHANNELS + 1];
64 int port, trigger_chan;
65 struct iio_trigger *trig;
66 struct mutex mutex;
67 /* Cached sample period in milliseconds */
68 unsigned int sample_period;
69 /* Demux table */
70 unsigned int demux_count;
71 struct dln2_adc_demux_table demux[DLN2_ADC_MAX_CHANNELS];
72 /* Precomputed timestamp padding offset and length */
73 unsigned int ts_pad_offset, ts_pad_length;
74};
75
76struct dln2_adc_port_chan {
77 u8 port;
78 u8 chan;
79};
80
81struct dln2_adc_get_all_vals {
82 __le16 channel_mask;
83 __le16 values[DLN2_ADC_MAX_CHANNELS];
84};
85
86static void dln2_adc_add_demux(struct dln2_adc *dln2,
87 unsigned int in_loc, unsigned int out_loc,
88 unsigned int length)
89{
90 struct dln2_adc_demux_table *p = dln2->demux_count ?
91 &dln2->demux[dln2->demux_count - 1] : NULL;
92
93 if (p && p->from + p->length == in_loc &&
94 p->to + p->length == out_loc) {
95 p->length += length;
96 } else if (dln2->demux_count < DLN2_ADC_MAX_CHANNELS) {
97 p = &dln2->demux[dln2->demux_count++];
98 p->from = in_loc;
99 p->to = out_loc;
100 p->length = length;
101 }
102}
103
104static void dln2_adc_update_demux(struct dln2_adc *dln2)
105{
106 int in_ind = -1, out_ind;
107 unsigned int in_loc = 0, out_loc = 0;
108 struct iio_dev *indio_dev = platform_get_drvdata(dln2->pdev);
109
110 /* Clear out any old demux */
111 dln2->demux_count = 0;
112
113 /* Optimize all 8-channels case */
114 if (indio_dev->masklength &&
115 (*indio_dev->active_scan_mask & 0xff) == 0xff) {
116 dln2_adc_add_demux(dln2, 0, 0, 16);
117 dln2->ts_pad_offset = 0;
118 dln2->ts_pad_length = 0;
119 return;
120 }
121
122 /* Build demux table from fixed 8-channels to active_scan_mask */
123 for_each_set_bit(out_ind,
124 indio_dev->active_scan_mask,
125 indio_dev->masklength) {
126 /* Handle timestamp separately */
127 if (out_ind == DLN2_ADC_MAX_CHANNELS)
128 break;
129 for (++in_ind; in_ind != out_ind; ++in_ind)
130 in_loc += 2;
131 dln2_adc_add_demux(dln2, in_loc, out_loc, 2);
132 out_loc += 2;
133 in_loc += 2;
134 }
135
136 if (indio_dev->scan_timestamp) {
137 size_t ts_offset = indio_dev->scan_bytes / sizeof(int64_t) - 1;
138
139 dln2->ts_pad_offset = out_loc;
140 dln2->ts_pad_length = ts_offset * sizeof(int64_t) - out_loc;
141 } else {
142 dln2->ts_pad_offset = 0;
143 dln2->ts_pad_length = 0;
144 }
145}
146
147static int dln2_adc_get_chan_count(struct dln2_adc *dln2)
148{
149 int ret;
150 u8 port = dln2->port;
151 u8 count;
152 int olen = sizeof(count);
153
154 ret = dln2_transfer(dln2->pdev, DLN2_ADC_GET_CHANNEL_COUNT,
155 &port, sizeof(port), &count, &olen);
156 if (ret < 0) {
157 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
158 return ret;
159 }
160 if (olen < sizeof(count))
161 return -EPROTO;
162
163 return count;
164}
165
166static int dln2_adc_set_port_resolution(struct dln2_adc *dln2)
167{
168 int ret;
169 struct dln2_adc_port_chan port_chan = {
170 .port = dln2->port,
171 .chan = DLN2_ADC_DATA_BITS,
172 };
173
174 ret = dln2_transfer_tx(dln2->pdev, DLN2_ADC_SET_RESOLUTION,
175 &port_chan, sizeof(port_chan));
176 if (ret < 0)
177 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
178
179 return ret;
180}
181
182static int dln2_adc_set_chan_enabled(struct dln2_adc *dln2,
183 int channel, bool enable)
184{
185 int ret;
186 struct dln2_adc_port_chan port_chan = {
187 .port = dln2->port,
188 .chan = channel,
189 };
190 u16 cmd = enable ? DLN2_ADC_CHANNEL_ENABLE : DLN2_ADC_CHANNEL_DISABLE;
191
192 ret = dln2_transfer_tx(dln2->pdev, cmd, &port_chan, sizeof(port_chan));
193 if (ret < 0)
194 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
195
196 return ret;
197}
198
199static int dln2_adc_set_port_enabled(struct dln2_adc *dln2, bool enable,
200 u16 *conflict_out)
201{
202 int ret;
203 u8 port = dln2->port;
204 __le16 conflict;
205 int olen = sizeof(conflict);
206 u16 cmd = enable ? DLN2_ADC_ENABLE : DLN2_ADC_DISABLE;
207
208 if (conflict_out)
209 *conflict_out = 0;
210
211 ret = dln2_transfer(dln2->pdev, cmd, &port, sizeof(port),
212 &conflict, &olen);
213 if (ret < 0) {
214 dev_dbg(&dln2->pdev->dev, "Problem in %s(%d)\n",
215 __func__, (int)enable);
216 if (conflict_out && enable && olen >= sizeof(conflict))
217 *conflict_out = le16_to_cpu(conflict);
218 return ret;
219 }
220 if (enable && olen < sizeof(conflict))
221 return -EPROTO;
222
223 return ret;
224}
225
226static int dln2_adc_set_chan_period(struct dln2_adc *dln2,
227 unsigned int channel, unsigned int period)
228{
229 int ret;
230 struct {
231 struct dln2_adc_port_chan port_chan;
232 __u8 type;
233 __le16 period;
234 __le16 low;
235 __le16 high;
236 } __packed set_cfg = {
237 .port_chan.port = dln2->port,
238 .port_chan.chan = channel,
239 .type = period ? DLN2_ADC_EVENT_ALWAYS : DLN2_ADC_EVENT_NONE,
240 .period = cpu_to_le16(period)
241 };
242
243 ret = dln2_transfer_tx(dln2->pdev, DLN2_ADC_CHANNEL_SET_CFG,
244 &set_cfg, sizeof(set_cfg));
245 if (ret < 0)
246 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
247
248 return ret;
249}
250
251static int dln2_adc_read(struct dln2_adc *dln2, unsigned int channel)
252{
253 int ret, i;
254 struct iio_dev *indio_dev = platform_get_drvdata(dln2->pdev);
255 u16 conflict;
256 __le16 value;
257 int olen = sizeof(value);
258 struct dln2_adc_port_chan port_chan = {
259 .port = dln2->port,
260 .chan = channel,
261 };
262
263 ret = iio_device_claim_direct_mode(indio_dev);
264 if (ret < 0)
265 return ret;
266
267 ret = dln2_adc_set_chan_enabled(dln2, channel, true);
268 if (ret < 0)
269 goto release_direct;
270
271 ret = dln2_adc_set_port_enabled(dln2, true, &conflict);
272 if (ret < 0) {
273 if (conflict) {
274 dev_err(&dln2->pdev->dev,
275 "ADC pins conflict with mask %04X\n",
276 (int)conflict);
277 ret = -EBUSY;
278 }
279 goto disable_chan;
280 }
281
282 /*
283 * Call GET_VAL twice due to initial zero-return immediately after
284 * enabling channel.
285 */
286 for (i = 0; i < 2; ++i) {
287 ret = dln2_transfer(dln2->pdev, DLN2_ADC_CHANNEL_GET_VAL,
288 &port_chan, sizeof(port_chan),
289 &value, &olen);
290 if (ret < 0) {
291 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
292 goto disable_port;
293 }
294 if (olen < sizeof(value)) {
295 ret = -EPROTO;
296 goto disable_port;
297 }
298 }
299
300 ret = le16_to_cpu(value);
301
302disable_port:
303 dln2_adc_set_port_enabled(dln2, false, NULL);
304disable_chan:
305 dln2_adc_set_chan_enabled(dln2, channel, false);
306release_direct:
307 iio_device_release_direct_mode(indio_dev);
308
309 return ret;
310}
311
312static int dln2_adc_read_all(struct dln2_adc *dln2,
313 struct dln2_adc_get_all_vals *get_all_vals)
314{
315 int ret;
316 __u8 port = dln2->port;
317 int olen = sizeof(*get_all_vals);
318
319 ret = dln2_transfer(dln2->pdev, DLN2_ADC_CHANNEL_GET_ALL_VAL,
320 &port, sizeof(port), get_all_vals, &olen);
321 if (ret < 0) {
322 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
323 return ret;
324 }
325 if (olen < sizeof(*get_all_vals))
326 return -EPROTO;
327
328 return ret;
329}
330
331static int dln2_adc_read_raw(struct iio_dev *indio_dev,
332 struct iio_chan_spec const *chan,
333 int *val,
334 int *val2,
335 long mask)
336{
337 int ret;
338 unsigned int microhertz;
339 struct dln2_adc *dln2 = iio_priv(indio_dev);
340
341 switch (mask) {
342 case IIO_CHAN_INFO_RAW:
343 mutex_lock(&dln2->mutex);
344 ret = dln2_adc_read(dln2, chan->channel);
345 mutex_unlock(&dln2->mutex);
346
347 if (ret < 0)
348 return ret;
349
350 *val = ret;
351 return IIO_VAL_INT;
352
353 case IIO_CHAN_INFO_SCALE:
354 /*
355 * Voltage reference is fixed at 3.3v
356 * 3.3 / (1 << 10) * 1000000000
357 */
358 *val = 0;
359 *val2 = 3222656;
360 return IIO_VAL_INT_PLUS_NANO;
361
362 case IIO_CHAN_INFO_SAMP_FREQ:
363 if (dln2->sample_period) {
364 microhertz = 1000000000 / dln2->sample_period;
365 *val = microhertz / 1000000;
366 *val2 = microhertz % 1000000;
367 } else {
368 *val = 0;
369 *val2 = 0;
370 }
371
372 return IIO_VAL_INT_PLUS_MICRO;
373
374 default:
375 return -EINVAL;
376 }
377}
378
379static int dln2_adc_write_raw(struct iio_dev *indio_dev,
380 struct iio_chan_spec const *chan,
381 int val,
382 int val2,
383 long mask)
384{
385 int ret;
386 unsigned int microhertz;
387 struct dln2_adc *dln2 = iio_priv(indio_dev);
388
389 switch (mask) {
390 case IIO_CHAN_INFO_SAMP_FREQ:
391 microhertz = 1000000 * val + val2;
392
393 mutex_lock(&dln2->mutex);
394
395 dln2->sample_period =
396 microhertz ? 1000000000 / microhertz : UINT_MAX;
397 if (dln2->sample_period > 65535) {
398 dln2->sample_period = 65535;
399 dev_warn(&dln2->pdev->dev,
400 "clamping period to 65535ms\n");
401 }
402
403 /*
404 * The first requested channel is arbitrated as a shared
405 * trigger source, so only one event is registered with the
406 * DLN. The event handler will then read all enabled channel
407 * values using DLN2_ADC_CHANNEL_GET_ALL_VAL to maintain
408 * synchronization between ADC readings.
409 */
410 if (dln2->trigger_chan != -1)
411 ret = dln2_adc_set_chan_period(dln2,
412 dln2->trigger_chan, dln2->sample_period);
413 else
414 ret = 0;
415
416 mutex_unlock(&dln2->mutex);
417
418 return ret;
419
420 default:
421 return -EINVAL;
422 }
423}
424
425static int dln2_update_scan_mode(struct iio_dev *indio_dev,
426 const unsigned long *scan_mask)
427{
428 struct dln2_adc *dln2 = iio_priv(indio_dev);
429 int chan_count = indio_dev->num_channels - 1;
430 int ret, i, j;
431
432 mutex_lock(&dln2->mutex);
433
434 for (i = 0; i < chan_count; ++i) {
435 ret = dln2_adc_set_chan_enabled(dln2, i,
436 test_bit(i, scan_mask));
437 if (ret < 0) {
438 for (j = 0; j < i; ++j)
439 dln2_adc_set_chan_enabled(dln2, j, false);
440 mutex_unlock(&dln2->mutex);
441 dev_err(&dln2->pdev->dev,
442 "Unable to enable ADC channel %d\n", i);
443 return -EBUSY;
444 }
445 }
446
447 dln2_adc_update_demux(dln2);
448
449 mutex_unlock(&dln2->mutex);
450
451 return 0;
452}
453
454#define DLN2_ADC_CHAN(lval, idx) { \
455 lval.type = IIO_VOLTAGE; \
456 lval.channel = idx; \
457 lval.indexed = 1; \
458 lval.info_mask_separate = BIT(IIO_CHAN_INFO_RAW); \
459 lval.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE) | \
460 BIT(IIO_CHAN_INFO_SAMP_FREQ); \
461 lval.scan_index = idx; \
462 lval.scan_type.sign = 'u'; \
463 lval.scan_type.realbits = DLN2_ADC_DATA_BITS; \
464 lval.scan_type.storagebits = 16; \
465 lval.scan_type.endianness = IIO_LE; \
466}
467
468/* Assignment version of IIO_CHAN_SOFT_TIMESTAMP */
469#define IIO_CHAN_SOFT_TIMESTAMP_ASSIGN(lval, _si) { \
470 lval.type = IIO_TIMESTAMP; \
471 lval.channel = -1; \
472 lval.scan_index = _si; \
473 lval.scan_type.sign = 's'; \
474 lval.scan_type.realbits = 64; \
475 lval.scan_type.storagebits = 64; \
476}
477
478static const struct iio_info dln2_adc_info = {
479 .read_raw = dln2_adc_read_raw,
480 .write_raw = dln2_adc_write_raw,
481 .update_scan_mode = dln2_update_scan_mode,
482 .driver_module = THIS_MODULE,
483};
484
485static irqreturn_t dln2_adc_trigger_h(int irq, void *p)
486{
487 struct iio_poll_func *pf = p;
488 struct iio_dev *indio_dev = pf->indio_dev;
489 struct {
490 __le16 values[DLN2_ADC_MAX_CHANNELS];
491 int64_t timestamp_space;
492 } data;
493 struct dln2_adc_get_all_vals dev_data;
494 struct dln2_adc *dln2 = iio_priv(indio_dev);
495 const struct dln2_adc_demux_table *t;
496 int ret, i;
497
498 mutex_lock(&dln2->mutex);
499 ret = dln2_adc_read_all(dln2, &dev_data);
500 mutex_unlock(&dln2->mutex);
501 if (ret < 0)
502 goto done;
503
504 /* Demux operation */
505 for (i = 0; i < dln2->demux_count; ++i) {
506 t = &dln2->demux[i];
507 memcpy((void *)data.values + t->to,
508 (void *)dev_data.values + t->from, t->length);
509 }
510
511 /* Zero padding space between values and timestamp */
512 if (dln2->ts_pad_length)
513 memset((void *)data.values + dln2->ts_pad_offset,
514 0, dln2->ts_pad_length);
515
516 iio_push_to_buffers_with_timestamp(indio_dev, &data,
517 iio_get_time_ns(indio_dev));
518
519done:
520 iio_trigger_notify_done(indio_dev->trig);
521 return IRQ_HANDLED;
522}
523
524static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
525{
526 int ret;
527 struct dln2_adc *dln2 = iio_priv(indio_dev);
528 u16 conflict;
529 unsigned int trigger_chan;
530
531 mutex_lock(&dln2->mutex);
532
533 /* Enable ADC */
534 ret = dln2_adc_set_port_enabled(dln2, true, &conflict);
535 if (ret < 0) {
536 mutex_unlock(&dln2->mutex);
537 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
538 if (conflict) {
539 dev_err(&dln2->pdev->dev,
540 "ADC pins conflict with mask %04X\n",
541 (int)conflict);
542 ret = -EBUSY;
543 }
544 return ret;
545 }
546
547 /* Assign trigger channel based on first enabled channel */
548 trigger_chan = find_first_bit(indio_dev->active_scan_mask,
549 indio_dev->masklength);
550 if (trigger_chan < DLN2_ADC_MAX_CHANNELS) {
551 dln2->trigger_chan = trigger_chan;
552 ret = dln2_adc_set_chan_period(dln2, dln2->trigger_chan,
553 dln2->sample_period);
554 mutex_unlock(&dln2->mutex);
555 if (ret < 0) {
556 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
557 return ret;
558 }
559 } else {
560 dln2->trigger_chan = -1;
561 mutex_unlock(&dln2->mutex);
562 }
563
564 return iio_triggered_buffer_postenable(indio_dev);
565}
566
567static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev)
568{
569 int ret;
570 struct dln2_adc *dln2 = iio_priv(indio_dev);
571
572 mutex_lock(&dln2->mutex);
573
574 /* Disable trigger channel */
575 if (dln2->trigger_chan != -1) {
576 dln2_adc_set_chan_period(dln2, dln2->trigger_chan, 0);
577 dln2->trigger_chan = -1;
578 }
579
580 /* Disable ADC */
581 ret = dln2_adc_set_port_enabled(dln2, false, NULL);
582
583 mutex_unlock(&dln2->mutex);
584 if (ret < 0) {
585 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
586 return ret;
587 }
588
589 return iio_triggered_buffer_predisable(indio_dev);
590}
591
592static const struct iio_buffer_setup_ops dln2_adc_buffer_setup_ops = {
593 .postenable = dln2_adc_triggered_buffer_postenable,
594 .predisable = dln2_adc_triggered_buffer_predisable,
595};
596
597static void dln2_adc_event(struct platform_device *pdev, u16 echo,
598 const void *data, int len)
599{
600 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
601 struct dln2_adc *dln2 = iio_priv(indio_dev);
602
603 /* Called via URB completion handler */
604 iio_trigger_poll(dln2->trig);
605}
606
607static const struct iio_trigger_ops dln2_adc_trigger_ops = {
608 .owner = THIS_MODULE,
609};
610
611static int dln2_adc_probe(struct platform_device *pdev)
612{
613 struct device *dev = &pdev->dev;
614 struct dln2_adc *dln2;
615 struct dln2_platform_data *pdata = dev_get_platdata(&pdev->dev);
616 struct iio_dev *indio_dev;
617 int i, ret, chans;
618
619 indio_dev = devm_iio_device_alloc(dev, sizeof(*dln2));
620 if (!indio_dev) {
621 dev_err(dev, "failed allocating iio device\n");
622 return -ENOMEM;
623 }
624
625 dln2 = iio_priv(indio_dev);
626 dln2->pdev = pdev;
627 dln2->port = pdata->port;
628 dln2->trigger_chan = -1;
629 mutex_init(&dln2->mutex);
630
631 platform_set_drvdata(pdev, indio_dev);
632
633 ret = dln2_adc_set_port_resolution(dln2);
634 if (ret < 0) {
635 dev_err(dev, "failed to set ADC resolution to 10 bits\n");
636 return ret;
637 }
638
639 chans = dln2_adc_get_chan_count(dln2);
640 if (chans < 0) {
641 dev_err(dev, "failed to get channel count: %d\n", chans);
642 return chans;
643 }
644 if (chans > DLN2_ADC_MAX_CHANNELS) {
645 chans = DLN2_ADC_MAX_CHANNELS;
646 dev_warn(dev, "clamping channels to %d\n",
647 DLN2_ADC_MAX_CHANNELS);
648 }
649
650 for (i = 0; i < chans; ++i)
651 DLN2_ADC_CHAN(dln2->iio_channels[i], i)
652 IIO_CHAN_SOFT_TIMESTAMP_ASSIGN(dln2->iio_channels[i], i);
653
654 indio_dev->name = DLN2_ADC_MOD_NAME;
655 indio_dev->dev.parent = dev;
656 indio_dev->info = &dln2_adc_info;
657 indio_dev->modes = INDIO_DIRECT_MODE;
658 indio_dev->channels = dln2->iio_channels;
659 indio_dev->num_channels = chans + 1;
660 indio_dev->setup_ops = &dln2_adc_buffer_setup_ops;
661
662 dln2->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
663 indio_dev->name, indio_dev->id);
664 if (!dln2->trig) {
665 dev_err(dev, "failed to allocate trigger\n");
666 return -ENOMEM;
667 }
668 dln2->trig->ops = &dln2_adc_trigger_ops;
669 iio_trigger_set_drvdata(dln2->trig, dln2);
670 devm_iio_trigger_register(dev, dln2->trig);
671 iio_trigger_set_immutable(indio_dev, dln2->trig);
672
673 ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
674 dln2_adc_trigger_h,
675 &dln2_adc_buffer_setup_ops);
676 if (ret) {
677 dev_err(dev, "failed to allocate triggered buffer: %d\n", ret);
678 return ret;
679 }
680
681 ret = dln2_register_event_cb(pdev, DLN2_ADC_CONDITION_MET_EV,
682 dln2_adc_event);
683 if (ret) {
684 dev_err(dev, "failed to setup DLN2 periodic event: %d\n", ret);
685 return ret;
686 }
687
688 ret = iio_device_register(indio_dev);
689 if (ret) {
690 dev_err(dev, "failed to register iio device: %d\n", ret);
691 goto unregister_event;
692 }
693
694 return ret;
695
696unregister_event:
697 dln2_unregister_event_cb(pdev, DLN2_ADC_CONDITION_MET_EV);
698
699 return ret;
700}
701
702static int dln2_adc_remove(struct platform_device *pdev)
703{
704 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
705
706 iio_device_unregister(indio_dev);
707 dln2_unregister_event_cb(pdev, DLN2_ADC_CONDITION_MET_EV);
708 return 0;
709}
710
711static struct platform_driver dln2_adc_driver = {
712 .driver.name = DLN2_ADC_MOD_NAME,
713 .probe = dln2_adc_probe,
714 .remove = dln2_adc_remove,
715};
716
717module_platform_driver(dln2_adc_driver);
718
719MODULE_AUTHOR("Jack Andersen <jackoalan@gmail.com");
720MODULE_DESCRIPTION("Driver for the Diolan DLN2 ADC interface");
721MODULE_LICENSE("GPL v2");
722MODULE_ALIAS("platform:dln2-adc");
diff --git a/drivers/iio/adc/ep93xx_adc.c b/drivers/iio/adc/ep93xx_adc.c
new file mode 100644
index 000000000000..a179ac476c6d
--- /dev/null
+++ b/drivers/iio/adc/ep93xx_adc.c
@@ -0,0 +1,255 @@
1/*
2 * Driver for ADC module on the Cirrus Logic EP93xx series of SoCs
3 *
4 * Copyright (C) 2015 Alexander Sverdlin
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * The driver uses polling to get the conversion status. According to EP93xx
11 * datasheets, reading ADCResult register starts the conversion, but user is also
12 * responsible for ensuring that delay between adjacent conversion triggers is
13 * long enough so that maximum allowed conversion rate is not exceeded. This
14 * basically renders IRQ mode unusable.
15 */
16
17#include <linux/clk.h>
18#include <linux/delay.h>
19#include <linux/device.h>
20#include <linux/err.h>
21#include <linux/iio/iio.h>
22#include <linux/io.h>
23#include <linux/irqflags.h>
24#include <linux/module.h>
25#include <linux/mutex.h>
26#include <linux/platform_device.h>
27
28/*
29 * This code could benefit from real HR Timers, but jiffy granularity would
30 * lower ADC conversion rate down to CONFIG_HZ, so we fallback to busy wait
31 * in such case.
32 *
33 * HR Timers-based version loads CPU only up to 10% during back to back ADC
34 * conversion, while busy wait-based version consumes whole CPU power.
35 */
36#ifdef CONFIG_HIGH_RES_TIMERS
37#define ep93xx_adc_delay(usmin, usmax) usleep_range(usmin, usmax)
38#else
39#define ep93xx_adc_delay(usmin, usmax) udelay(usmin)
40#endif
41
42#define EP93XX_ADC_RESULT 0x08
43#define EP93XX_ADC_SDR BIT(31)
44#define EP93XX_ADC_SWITCH 0x18
45#define EP93XX_ADC_SW_LOCK 0x20
46
47struct ep93xx_adc_priv {
48 struct clk *clk;
49 void __iomem *base;
50 int lastch;
51 struct mutex lock;
52};
53
54#define EP93XX_ADC_CH(index, dname, swcfg) { \
55 .type = IIO_VOLTAGE, \
56 .indexed = 1, \
57 .channel = index, \
58 .address = swcfg, \
59 .datasheet_name = dname, \
60 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
61 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE) | \
62 BIT(IIO_CHAN_INFO_OFFSET), \
63}
64
65/*
66 * Numbering scheme for channels 0..4 is defined in EP9301 and EP9302 datasheets.
67 * EP9307, EP9312 and EP9312 have 3 channels more (total 8), but the numbering is
68 * not defined. So the last three are numbered randomly, let's say.
69 */
70static const struct iio_chan_spec ep93xx_adc_channels[8] = {
71 EP93XX_ADC_CH(0, "YM", 0x608),
72 EP93XX_ADC_CH(1, "SXP", 0x680),
73 EP93XX_ADC_CH(2, "SXM", 0x640),
74 EP93XX_ADC_CH(3, "SYP", 0x620),
75 EP93XX_ADC_CH(4, "SYM", 0x610),
76 EP93XX_ADC_CH(5, "XP", 0x601),
77 EP93XX_ADC_CH(6, "XM", 0x602),
78 EP93XX_ADC_CH(7, "YP", 0x604),
79};
80
81static int ep93xx_read_raw(struct iio_dev *iiodev,
82 struct iio_chan_spec const *channel, int *value,
83 int *shift, long mask)
84{
85 struct ep93xx_adc_priv *priv = iio_priv(iiodev);
86 unsigned long timeout;
87 int ret;
88
89 switch (mask) {
90 case IIO_CHAN_INFO_RAW:
91 mutex_lock(&priv->lock);
92 if (priv->lastch != channel->channel) {
93 priv->lastch = channel->channel;
94 /*
95 * Switch register is software-locked, unlocking must be
96 * immediately followed by write
97 */
98 local_irq_disable();
99 writel_relaxed(0xAA, priv->base + EP93XX_ADC_SW_LOCK);
100 writel_relaxed(channel->address,
101 priv->base + EP93XX_ADC_SWITCH);
102 local_irq_enable();
103 /*
104 * Settling delay depends on module clock and could be
105 * 2ms or 500us
106 */
107 ep93xx_adc_delay(2000, 2000);
108 }
109 /* Start the conversion, eventually discarding old result */
110 readl_relaxed(priv->base + EP93XX_ADC_RESULT);
111 /* Ensure maximum conversion rate is not exceeded */
112 ep93xx_adc_delay(DIV_ROUND_UP(1000000, 925),
113 DIV_ROUND_UP(1000000, 925));
114 /* At this point conversion must be completed, but anyway... */
115 ret = IIO_VAL_INT;
116 timeout = jiffies + msecs_to_jiffies(1) + 1;
117 while (1) {
118 u32 t;
119
120 t = readl_relaxed(priv->base + EP93XX_ADC_RESULT);
121 if (t & EP93XX_ADC_SDR) {
122 *value = sign_extend32(t, 15);
123 break;
124 }
125
126 if (time_after(jiffies, timeout)) {
127 dev_err(&iiodev->dev, "Conversion timeout\n");
128 ret = -ETIMEDOUT;
129 break;
130 }
131
132 cpu_relax();
133 }
134 mutex_unlock(&priv->lock);
135 return ret;
136
137 case IIO_CHAN_INFO_OFFSET:
138 /* According to datasheet, range is -25000..25000 */
139 *value = 25000;
140 return IIO_VAL_INT;
141
142 case IIO_CHAN_INFO_SCALE:
143 /* Typical supply voltage is 3.3v */
144 *value = (1ULL << 32) * 3300 / 50000;
145 *shift = 32;
146 return IIO_VAL_FRACTIONAL_LOG2;
147 }
148
149 return -EINVAL;
150}
151
152static const struct iio_info ep93xx_adc_info = {
153 .driver_module = THIS_MODULE,
154 .read_raw = ep93xx_read_raw,
155};
156
157static int ep93xx_adc_probe(struct platform_device *pdev)
158{
159 int ret;
160 struct iio_dev *iiodev;
161 struct ep93xx_adc_priv *priv;
162 struct clk *pclk;
163 struct resource *res;
164
165 iiodev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv));
166 if (!iiodev)
167 return -ENOMEM;
168 priv = iio_priv(iiodev);
169
170 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
171 if (!res) {
172 dev_err(&pdev->dev, "Cannot obtain memory resource\n");
173 return -ENXIO;
174 }
175 priv->base = devm_ioremap_resource(&pdev->dev, res);
176 if (IS_ERR(priv->base)) {
177 dev_err(&pdev->dev, "Cannot map memory resource\n");
178 return PTR_ERR(priv->base);
179 }
180
181 iiodev->dev.parent = &pdev->dev;
182 iiodev->name = dev_name(&pdev->dev);
183 iiodev->modes = INDIO_DIRECT_MODE;
184 iiodev->info = &ep93xx_adc_info;
185 iiodev->num_channels = ARRAY_SIZE(ep93xx_adc_channels);
186 iiodev->channels = ep93xx_adc_channels;
187
188 priv->lastch = -1;
189 mutex_init(&priv->lock);
190
191 platform_set_drvdata(pdev, iiodev);
192
193 priv->clk = devm_clk_get(&pdev->dev, NULL);
194 if (IS_ERR(priv->clk)) {
195 dev_err(&pdev->dev, "Cannot obtain clock\n");
196 return PTR_ERR(priv->clk);
197 }
198
199 pclk = clk_get_parent(priv->clk);
200 if (!pclk) {
201 dev_warn(&pdev->dev, "Cannot obtain parent clock\n");
202 } else {
203 /*
204 * This is actually a place for improvement:
205 * EP93xx ADC supports two clock divisors -- 4 and 16,
206 * resulting in conversion rates 3750 and 925 samples per second
207 * with 500us or 2ms settling time respectively.
208 * One might find this interesting enough to be configurable.
209 */
210 ret = clk_set_rate(priv->clk, clk_get_rate(pclk) / 16);
211 if (ret)
212 dev_warn(&pdev->dev, "Cannot set clock rate\n");
213 /*
214 * We can tolerate rate setting failure because the module should
215 * work in any case.
216 */
217 }
218
219 ret = clk_enable(priv->clk);
220 if (ret) {
221 dev_err(&pdev->dev, "Cannot enable clock\n");
222 return ret;
223 }
224
225 ret = iio_device_register(iiodev);
226 if (ret)
227 clk_disable(priv->clk);
228
229 return ret;
230}
231
232static int ep93xx_adc_remove(struct platform_device *pdev)
233{
234 struct iio_dev *iiodev = platform_get_drvdata(pdev);
235 struct ep93xx_adc_priv *priv = iio_priv(iiodev);
236
237 iio_device_unregister(iiodev);
238 clk_disable(priv->clk);
239
240 return 0;
241}
242
243static struct platform_driver ep93xx_adc_driver = {
244 .driver = {
245 .name = "ep93xx-adc",
246 },
247 .probe = ep93xx_adc_probe,
248 .remove = ep93xx_adc_remove,
249};
250module_platform_driver(ep93xx_adc_driver);
251
252MODULE_AUTHOR("Alexander Sverdlin <alexander.sverdlin@gmail.com>");
253MODULE_DESCRIPTION("Cirrus Logic EP93XX ADC driver");
254MODULE_LICENSE("GPL");
255MODULE_ALIAS("platform:ep93xx-adc");
diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
index 232c0b80d658..68884d26b50c 100644
--- a/drivers/iio/adc/ina2xx-adc.c
+++ b/drivers/iio/adc/ina2xx-adc.c
@@ -44,6 +44,7 @@
44 44
45#define INA226_MASK_ENABLE 0x06 45#define INA226_MASK_ENABLE 0x06
46#define INA226_CVRF BIT(3) 46#define INA226_CVRF BIT(3)
47#define INA219_CNVR BIT(1)
47 48
48#define INA2XX_MAX_REGISTERS 8 49#define INA2XX_MAX_REGISTERS 8
49 50
@@ -592,6 +593,7 @@ static int ina2xx_work_buffer(struct iio_dev *indio_dev)
592 int bit, ret, i = 0; 593 int bit, ret, i = 0;
593 s64 time_a, time_b; 594 s64 time_a, time_b;
594 unsigned int alert; 595 unsigned int alert;
596 int cnvr_need_clear = 0;
595 597
596 time_a = iio_get_time_ns(indio_dev); 598 time_a = iio_get_time_ns(indio_dev);
597 599
@@ -603,22 +605,30 @@ static int ina2xx_work_buffer(struct iio_dev *indio_dev)
603 * we check the ConVersionReadyFlag. 605 * we check the ConVersionReadyFlag.
604 * On hardware that supports using the ALERT pin to toggle a 606 * On hardware that supports using the ALERT pin to toggle a
605 * GPIO a triggered buffer could be used instead. 607 * GPIO a triggered buffer could be used instead.
606 * For now, we pay for that extra read of the ALERT register 608 * For now, we do an extra read of the MASK_ENABLE register (INA226)
609 * resp. the BUS_VOLTAGE register (INA219).
607 */ 610 */
608 if (!chip->allow_async_readout) 611 if (!chip->allow_async_readout)
609 do { 612 do {
610 ret = regmap_read(chip->regmap, INA226_MASK_ENABLE, 613 if (chip->config->chip_id == ina226) {
611 &alert); 614 ret = regmap_read(chip->regmap,
615 INA226_MASK_ENABLE, &alert);
616 alert &= INA226_CVRF;
617 } else {
618 ret = regmap_read(chip->regmap,
619 INA2XX_BUS_VOLTAGE, &alert);
620 alert &= INA219_CNVR;
621 cnvr_need_clear = alert;
622 }
623
612 if (ret < 0) 624 if (ret < 0)
613 return ret; 625 return ret;
614 626
615 alert &= INA226_CVRF;
616 } while (!alert); 627 } while (!alert);
617 628
618 /* 629 /*
619 * Single register reads: bulk_read will not work with ina226 630 * Single register reads: bulk_read will not work with ina226/219
620 * as there is no auto-increment of the address register for 631 * as there is no auto-increment of the register pointer.
621 * data length longer than 16bits.
622 */ 632 */
623 for_each_set_bit(bit, indio_dev->active_scan_mask, 633 for_each_set_bit(bit, indio_dev->active_scan_mask,
624 indio_dev->masklength) { 634 indio_dev->masklength) {
@@ -630,6 +640,18 @@ static int ina2xx_work_buffer(struct iio_dev *indio_dev)
630 return ret; 640 return ret;
631 641
632 data[i++] = val; 642 data[i++] = val;
643
644 if (INA2XX_SHUNT_VOLTAGE + bit == INA2XX_POWER)
645 cnvr_need_clear = 0;
646 }
647
648 /* Dummy read on INA219 power register to clear CNVR flag */
649 if (cnvr_need_clear && chip->config->chip_id == ina219) {
650 unsigned int val;
651
652 ret = regmap_read(chip->regmap, INA2XX_POWER, &val);
653 if (ret < 0)
654 return ret;
633 } 655 }
634 656
635 time_b = iio_get_time_ns(indio_dev); 657 time_b = iio_get_time_ns(indio_dev);
diff --git a/drivers/iio/adc/ltc2471.c b/drivers/iio/adc/ltc2471.c
new file mode 100644
index 000000000000..29b7ed60cdb0
--- /dev/null
+++ b/drivers/iio/adc/ltc2471.c
@@ -0,0 +1,160 @@
1/*
2 * Driver for Linear Technology LTC2471 and LTC2473 voltage monitors
3 * The LTC2473 is identical to the 2471, but reports a differential signal.
4 *
5 * Copyright (C) 2017 Topic Embedded Products
6 * Author: Mike Looijmans <mike.looijmans@topic.nl>
7 *
8 * License: GPLv2
9 */
10
11#include <linux/err.h>
12#include <linux/i2c.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/iio/iio.h>
16#include <linux/iio/sysfs.h>
17
18enum ltc2471_chips {
19 ltc2471,
20 ltc2473,
21};
22
23struct ltc2471_data {
24 struct i2c_client *client;
25};
26
27/* Reference voltage is 1.25V */
28#define LTC2471_VREF 1250
29
30/* Read two bytes from the I2C bus to obtain the ADC result */
31static int ltc2471_get_value(struct i2c_client *client)
32{
33 int ret;
34 __be16 buf;
35
36 ret = i2c_master_recv(client, (char *)&buf, sizeof(buf));
37 if (ret < 0)
38 return ret;
39 if (ret != sizeof(buf))
40 return -EIO;
41
42 /* MSB first */
43 return be16_to_cpu(buf);
44}
45
46static int ltc2471_read_raw(struct iio_dev *indio_dev,
47 struct iio_chan_spec const *chan,
48 int *val, int *val2, long info)
49{
50 struct ltc2471_data *data = iio_priv(indio_dev);
51 int ret;
52
53 switch (info) {
54 case IIO_CHAN_INFO_RAW:
55 ret = ltc2471_get_value(data->client);
56 if (ret < 0)
57 return ret;
58 *val = ret;
59 return IIO_VAL_INT;
60
61 case IIO_CHAN_INFO_SCALE:
62 if (chan->differential)
63 /* Output ranges from -VREF to +VREF */
64 *val = 2 * LTC2471_VREF;
65 else
66 /* Output ranges from 0 to VREF */
67 *val = LTC2471_VREF;
68 *val2 = 16; /* 16 data bits */
69 return IIO_VAL_FRACTIONAL_LOG2;
70
71 case IIO_CHAN_INFO_OFFSET:
72 /* Only differential chip has this property */
73 *val = -LTC2471_VREF;
74 return IIO_VAL_INT;
75
76 default:
77 return -EINVAL;
78 }
79}
80
81static const struct iio_chan_spec ltc2471_channel[] = {
82 {
83 .type = IIO_VOLTAGE,
84 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
85 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
86 },
87};
88
89static const struct iio_chan_spec ltc2473_channel[] = {
90 {
91 .type = IIO_VOLTAGE,
92 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
93 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |
94 BIT(IIO_CHAN_INFO_OFFSET),
95 .differential = 1,
96 },
97};
98
99static const struct iio_info ltc2471_info = {
100 .read_raw = ltc2471_read_raw,
101 .driver_module = THIS_MODULE,
102};
103
104static int ltc2471_i2c_probe(struct i2c_client *client,
105 const struct i2c_device_id *id)
106{
107 struct iio_dev *indio_dev;
108 struct ltc2471_data *data;
109 int ret;
110
111 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
112 return -EOPNOTSUPP;
113
114 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
115 if (!indio_dev)
116 return -ENOMEM;
117
118 data = iio_priv(indio_dev);
119 data->client = client;
120
121 indio_dev->dev.parent = &client->dev;
122 indio_dev->name = id->name;
123 indio_dev->info = &ltc2471_info;
124 indio_dev->modes = INDIO_DIRECT_MODE;
125 if (id->driver_data == ltc2473)
126 indio_dev->channels = ltc2473_channel;
127 else
128 indio_dev->channels = ltc2471_channel;
129 indio_dev->num_channels = 1;
130
131 /* Trigger once to start conversion and check if chip is there */
132 ret = ltc2471_get_value(client);
133 if (ret < 0) {
134 dev_err(&client->dev, "Cannot read from device.\n");
135 return ret;
136 }
137
138 return devm_iio_device_register(&client->dev, indio_dev);
139}
140
141static const struct i2c_device_id ltc2471_i2c_id[] = {
142 { "ltc2471", ltc2471 },
143 { "ltc2473", ltc2473 },
144 {}
145};
146MODULE_DEVICE_TABLE(i2c, ltc2471_i2c_id);
147
148static struct i2c_driver ltc2471_i2c_driver = {
149 .driver = {
150 .name = "ltc2471",
151 },
152 .probe = ltc2471_i2c_probe,
153 .id_table = ltc2471_i2c_id,
154};
155
156module_i2c_driver(ltc2471_i2c_driver);
157
158MODULE_DESCRIPTION("LTC2471/LTC2473 ADC driver");
159MODULE_AUTHOR("Topic Embedded Products");
160MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/ltc2497.c b/drivers/iio/adc/ltc2497.c
index 2691b10023f5..5bf8011dcde9 100644
--- a/drivers/iio/adc/ltc2497.c
+++ b/drivers/iio/adc/ltc2497.c
@@ -11,6 +11,7 @@
11#include <linux/delay.h> 11#include <linux/delay.h>
12#include <linux/i2c.h> 12#include <linux/i2c.h>
13#include <linux/iio/iio.h> 13#include <linux/iio/iio.h>
14#include <linux/iio/driver.h>
14#include <linux/iio/sysfs.h> 15#include <linux/iio/sysfs.h>
15#include <linux/module.h> 16#include <linux/module.h>
16#include <linux/of.h> 17#include <linux/of.h>
@@ -127,13 +128,14 @@ static int ltc2497_read_raw(struct iio_dev *indio_dev,
127 } 128 }
128} 129}
129 130
130#define LTC2497_CHAN(_chan, _addr) { \ 131#define LTC2497_CHAN(_chan, _addr, _ds_name) { \
131 .type = IIO_VOLTAGE, \ 132 .type = IIO_VOLTAGE, \
132 .indexed = 1, \ 133 .indexed = 1, \
133 .channel = (_chan), \ 134 .channel = (_chan), \
134 .address = (_addr | (_chan / 2) | ((_chan & 1) ? LTC2497_SIGN : 0)), \ 135 .address = (_addr | (_chan / 2) | ((_chan & 1) ? LTC2497_SIGN : 0)), \
135 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 136 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
136 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 137 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
138 .datasheet_name = (_ds_name), \
137} 139}
138 140
139#define LTC2497_CHAN_DIFF(_chan, _addr) { \ 141#define LTC2497_CHAN_DIFF(_chan, _addr) { \
@@ -148,22 +150,22 @@ static int ltc2497_read_raw(struct iio_dev *indio_dev,
148} 150}
149 151
150static const struct iio_chan_spec ltc2497_channel[] = { 152static const struct iio_chan_spec ltc2497_channel[] = {
151 LTC2497_CHAN(0, LTC2497_SGL), 153 LTC2497_CHAN(0, LTC2497_SGL, "CH0"),
152 LTC2497_CHAN(1, LTC2497_SGL), 154 LTC2497_CHAN(1, LTC2497_SGL, "CH1"),
153 LTC2497_CHAN(2, LTC2497_SGL), 155 LTC2497_CHAN(2, LTC2497_SGL, "CH2"),
154 LTC2497_CHAN(3, LTC2497_SGL), 156 LTC2497_CHAN(3, LTC2497_SGL, "CH3"),
155 LTC2497_CHAN(4, LTC2497_SGL), 157 LTC2497_CHAN(4, LTC2497_SGL, "CH4"),
156 LTC2497_CHAN(5, LTC2497_SGL), 158 LTC2497_CHAN(5, LTC2497_SGL, "CH5"),
157 LTC2497_CHAN(6, LTC2497_SGL), 159 LTC2497_CHAN(6, LTC2497_SGL, "CH6"),
158 LTC2497_CHAN(7, LTC2497_SGL), 160 LTC2497_CHAN(7, LTC2497_SGL, "CH7"),
159 LTC2497_CHAN(8, LTC2497_SGL), 161 LTC2497_CHAN(8, LTC2497_SGL, "CH8"),
160 LTC2497_CHAN(9, LTC2497_SGL), 162 LTC2497_CHAN(9, LTC2497_SGL, "CH9"),
161 LTC2497_CHAN(10, LTC2497_SGL), 163 LTC2497_CHAN(10, LTC2497_SGL, "CH10"),
162 LTC2497_CHAN(11, LTC2497_SGL), 164 LTC2497_CHAN(11, LTC2497_SGL, "CH11"),
163 LTC2497_CHAN(12, LTC2497_SGL), 165 LTC2497_CHAN(12, LTC2497_SGL, "CH12"),
164 LTC2497_CHAN(13, LTC2497_SGL), 166 LTC2497_CHAN(13, LTC2497_SGL, "CH13"),
165 LTC2497_CHAN(14, LTC2497_SGL), 167 LTC2497_CHAN(14, LTC2497_SGL, "CH14"),
166 LTC2497_CHAN(15, LTC2497_SGL), 168 LTC2497_CHAN(15, LTC2497_SGL, "CH15"),
167 LTC2497_CHAN_DIFF(0, LTC2497_DIFF), 169 LTC2497_CHAN_DIFF(0, LTC2497_DIFF),
168 LTC2497_CHAN_DIFF(1, LTC2497_DIFF), 170 LTC2497_CHAN_DIFF(1, LTC2497_DIFF),
169 LTC2497_CHAN_DIFF(2, LTC2497_DIFF), 171 LTC2497_CHAN_DIFF(2, LTC2497_DIFF),
@@ -192,6 +194,7 @@ static int ltc2497_probe(struct i2c_client *client,
192{ 194{
193 struct iio_dev *indio_dev; 195 struct iio_dev *indio_dev;
194 struct ltc2497_st *st; 196 struct ltc2497_st *st;
197 struct iio_map *plat_data;
195 int ret; 198 int ret;
196 199
197 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | 200 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
@@ -221,19 +224,31 @@ static int ltc2497_probe(struct i2c_client *client,
221 if (ret < 0) 224 if (ret < 0)
222 return ret; 225 return ret;
223 226
227 if (client->dev.platform_data) {
228 plat_data = ((struct iio_map *)client->dev.platform_data);
229 ret = iio_map_array_register(indio_dev, plat_data);
230 if (ret) {
231 dev_err(&indio_dev->dev, "iio map err: %d\n", ret);
232 goto err_regulator_disable;
233 }
234 }
235
224 ret = i2c_smbus_write_byte(st->client, LTC2497_CONFIG_DEFAULT); 236 ret = i2c_smbus_write_byte(st->client, LTC2497_CONFIG_DEFAULT);
225 if (ret < 0) 237 if (ret < 0)
226 goto err_regulator_disable; 238 goto err_array_unregister;
227 239
228 st->addr_prev = LTC2497_CONFIG_DEFAULT; 240 st->addr_prev = LTC2497_CONFIG_DEFAULT;
229 st->time_prev = ktime_get(); 241 st->time_prev = ktime_get();
230 242
231 ret = iio_device_register(indio_dev); 243 ret = iio_device_register(indio_dev);
232 if (ret < 0) 244 if (ret < 0)
233 goto err_regulator_disable; 245 goto err_array_unregister;
234 246
235 return 0; 247 return 0;
236 248
249err_array_unregister:
250 iio_map_array_unregister(indio_dev);
251
237err_regulator_disable: 252err_regulator_disable:
238 regulator_disable(st->ref); 253 regulator_disable(st->ref);
239 254
@@ -245,6 +260,7 @@ static int ltc2497_remove(struct i2c_client *client)
245 struct iio_dev *indio_dev = i2c_get_clientdata(client); 260 struct iio_dev *indio_dev = i2c_get_clientdata(client);
246 struct ltc2497_st *st = iio_priv(indio_dev); 261 struct ltc2497_st *st = iio_priv(indio_dev);
247 262
263 iio_map_array_unregister(indio_dev);
248 iio_device_unregister(indio_dev); 264 iio_device_unregister(indio_dev);
249 regulator_disable(st->ref); 265 regulator_disable(st->ref);
250 266
diff --git a/drivers/iio/adc/max9611.c b/drivers/iio/adc/max9611.c
index b0526e4b9530..b1dd17cbce58 100644
--- a/drivers/iio/adc/max9611.c
+++ b/drivers/iio/adc/max9611.c
@@ -549,8 +549,8 @@ static int max9611_probe(struct i2c_client *client,
549 ret = of_property_read_u32(of_node, shunt_res_prop, &of_shunt); 549 ret = of_property_read_u32(of_node, shunt_res_prop, &of_shunt);
550 if (ret) { 550 if (ret) {
551 dev_err(&client->dev, 551 dev_err(&client->dev,
552 "Missing %s property for %s node\n", 552 "Missing %s property for %pOF node\n",
553 shunt_res_prop, of_node->full_name); 553 shunt_res_prop, of_node);
554 return ret; 554 return ret;
555 } 555 }
556 max9611->shunt_resistor_uohm = of_shunt; 556 max9611->shunt_resistor_uohm = of_shunt;
diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c
index 254135e07792..63de705086ed 100644
--- a/drivers/iio/adc/mcp3422.c
+++ b/drivers/iio/adc/mcp3422.c
@@ -379,10 +379,12 @@ static int mcp3422_probe(struct i2c_client *client,
379 379
380 /* meaningful default configuration */ 380 /* meaningful default configuration */
381 config = (MCP3422_CONT_SAMPLING 381 config = (MCP3422_CONT_SAMPLING
382 | MCP3422_CHANNEL_VALUE(1) 382 | MCP3422_CHANNEL_VALUE(0)
383 | MCP3422_PGA_VALUE(MCP3422_PGA_1) 383 | MCP3422_PGA_VALUE(MCP3422_PGA_1)
384 | MCP3422_SAMPLE_RATE_VALUE(MCP3422_SRATE_240)); 384 | MCP3422_SAMPLE_RATE_VALUE(MCP3422_SRATE_240));
385 mcp3422_update_config(adc, config); 385 err = mcp3422_update_config(adc, config);
386 if (err < 0)
387 return err;
386 388
387 err = devm_iio_device_register(&client->dev, indio_dev); 389 err = devm_iio_device_register(&client->dev, indio_dev);
388 if (err < 0) 390 if (err < 0)
diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index 83da50ed73ab..2e8dbb89c8c9 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -572,8 +572,8 @@ static int meson_sar_adc_clk_init(struct iio_dev *indio_dev,
572 struct clk_init_data init; 572 struct clk_init_data init;
573 const char *clk_parents[1]; 573 const char *clk_parents[1];
574 574
575 init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%s#adc_div", 575 init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%pOF#adc_div",
576 of_node_full_name(indio_dev->dev.of_node)); 576 indio_dev->dev.of_node);
577 init.flags = 0; 577 init.flags = 0;
578 init.ops = &clk_divider_ops; 578 init.ops = &clk_divider_ops;
579 clk_parents[0] = __clk_get_name(priv->clkin); 579 clk_parents[0] = __clk_get_name(priv->clkin);
@@ -591,8 +591,8 @@ static int meson_sar_adc_clk_init(struct iio_dev *indio_dev,
591 if (WARN_ON(IS_ERR(priv->adc_div_clk))) 591 if (WARN_ON(IS_ERR(priv->adc_div_clk)))
592 return PTR_ERR(priv->adc_div_clk); 592 return PTR_ERR(priv->adc_div_clk);
593 593
594 init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%s#adc_en", 594 init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%pOF#adc_en",
595 of_node_full_name(indio_dev->dev.of_node)); 595 indio_dev->dev.of_node);
596 init.flags = CLK_SET_RATE_PARENT; 596 init.flags = CLK_SET_RATE_PARENT;
597 init.ops = &clk_gate_ops; 597 init.ops = &clk_gate_ops;
598 clk_parents[0] = __clk_get_name(priv->adc_div_clk); 598 clk_parents[0] = __clk_get_name(priv->adc_div_clk);
@@ -915,6 +915,11 @@ static int meson_sar_adc_probe(struct platform_device *pdev)
915 init_completion(&priv->done); 915 init_completion(&priv->done);
916 916
917 match = of_match_device(meson_sar_adc_of_match, &pdev->dev); 917 match = of_match_device(meson_sar_adc_of_match, &pdev->dev);
918 if (!match) {
919 dev_err(&pdev->dev, "failed to match device\n");
920 return -ENODEV;
921 }
922
918 priv->data = match->data; 923 priv->data = match->data;
919 924
920 indio_dev->name = priv->data->name; 925 indio_dev->name = priv->data->name;
diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c
index 2d104c828041..414cf44bf19d 100644
--- a/drivers/iio/adc/mt6577_auxadc.c
+++ b/drivers/iio/adc/mt6577_auxadc.c
@@ -184,6 +184,37 @@ static const struct iio_info mt6577_auxadc_info = {
184 .read_raw = &mt6577_auxadc_read_raw, 184 .read_raw = &mt6577_auxadc_read_raw,
185}; 185};
186 186
187static int __maybe_unused mt6577_auxadc_resume(struct device *dev)
188{
189 struct iio_dev *indio_dev = dev_get_drvdata(dev);
190 struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev);
191 int ret;
192
193 ret = clk_prepare_enable(adc_dev->adc_clk);
194 if (ret) {
195 pr_err("failed to enable auxadc clock\n");
196 return ret;
197 }
198
199 mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC,
200 MT6577_AUXADC_PDN_EN, 0);
201 mdelay(MT6577_AUXADC_POWER_READY_MS);
202
203 return 0;
204}
205
206static int __maybe_unused mt6577_auxadc_suspend(struct device *dev)
207{
208 struct iio_dev *indio_dev = dev_get_drvdata(dev);
209 struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev);
210
211 mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC,
212 0, MT6577_AUXADC_PDN_EN);
213 clk_disable_unprepare(adc_dev->adc_clk);
214
215 return 0;
216}
217
187static int mt6577_auxadc_probe(struct platform_device *pdev) 218static int mt6577_auxadc_probe(struct platform_device *pdev)
188{ 219{
189 struct mt6577_auxadc_device *adc_dev; 220 struct mt6577_auxadc_device *adc_dev;
@@ -269,8 +300,13 @@ static int mt6577_auxadc_remove(struct platform_device *pdev)
269 return 0; 300 return 0;
270} 301}
271 302
303static SIMPLE_DEV_PM_OPS(mt6577_auxadc_pm_ops,
304 mt6577_auxadc_suspend,
305 mt6577_auxadc_resume);
306
272static const struct of_device_id mt6577_auxadc_of_match[] = { 307static const struct of_device_id mt6577_auxadc_of_match[] = {
273 { .compatible = "mediatek,mt2701-auxadc", }, 308 { .compatible = "mediatek,mt2701-auxadc", },
309 { .compatible = "mediatek,mt7622-auxadc", },
274 { .compatible = "mediatek,mt8173-auxadc", }, 310 { .compatible = "mediatek,mt8173-auxadc", },
275 { } 311 { }
276}; 312};
@@ -280,6 +316,7 @@ static struct platform_driver mt6577_auxadc_driver = {
280 .driver = { 316 .driver = {
281 .name = "mt6577-auxadc", 317 .name = "mt6577-auxadc",
282 .of_match_table = mt6577_auxadc_of_match, 318 .of_match_table = mt6577_auxadc_of_match,
319 .pm = &mt6577_auxadc_pm_ops,
283 }, 320 },
284 .probe = mt6577_auxadc_probe, 321 .probe = mt6577_auxadc_probe,
285 .remove = mt6577_auxadc_remove, 322 .remove = mt6577_auxadc_remove,
diff --git a/drivers/iio/adc/rockchip_saradc.c b/drivers/iio/adc/rockchip_saradc.c
index ae6d3324f518..2bf2ed15a870 100644
--- a/drivers/iio/adc/rockchip_saradc.c
+++ b/drivers/iio/adc/rockchip_saradc.c
@@ -224,6 +224,11 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
224 info = iio_priv(indio_dev); 224 info = iio_priv(indio_dev);
225 225
226 match = of_match_device(rockchip_saradc_match, &pdev->dev); 226 match = of_match_device(rockchip_saradc_match, &pdev->dev);
227 if (!match) {
228 dev_err(&pdev->dev, "failed to match device\n");
229 return -ENODEV;
230 }
231
227 info->data = match->data; 232 info->data = match->data;
228 233
229 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 234 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
index e09233b03c05..9d083c2338f9 100644
--- a/drivers/iio/adc/stm32-adc-core.c
+++ b/drivers/iio/adc/stm32-adc-core.c
@@ -172,7 +172,7 @@ struct stm32h7_adc_ck_spec {
172 int div; 172 int div;
173}; 173};
174 174
175const struct stm32h7_adc_ck_spec stm32h7_adc_ckmodes_spec[] = { 175static const struct stm32h7_adc_ck_spec stm32h7_adc_ckmodes_spec[] = {
176 /* 00: CK_ADC[1..3]: Asynchronous clock modes */ 176 /* 00: CK_ADC[1..3]: Asynchronous clock modes */
177 { 0, 0, 1 }, 177 { 0, 0, 1 },
178 { 0, 1, 2 }, 178 { 0, 1, 2 },
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 884b8e461b17..7972845b3823 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -505,24 +505,24 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)
505 unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE; 505 unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE;
506 506
507 if (of_property_read_u32(node, "reg", &pval)) { 507 if (of_property_read_u32(node, "reg", &pval)) {
508 dev_err(&client->dev, "invalid reg on %s\n", 508 dev_err(&client->dev, "invalid reg on %pOF\n",
509 node->full_name); 509 node);
510 continue; 510 continue;
511 } 511 }
512 512
513 channel = pval; 513 channel = pval;
514 if (channel >= ADS1015_CHANNELS) { 514 if (channel >= ADS1015_CHANNELS) {
515 dev_err(&client->dev, 515 dev_err(&client->dev,
516 "invalid channel index %d on %s\n", 516 "invalid channel index %d on %pOF\n",
517 channel, node->full_name); 517 channel, node);
518 continue; 518 continue;
519 } 519 }
520 520
521 if (!of_property_read_u32(node, "ti,gain", &pval)) { 521 if (!of_property_read_u32(node, "ti,gain", &pval)) {
522 pga = pval; 522 pga = pval;
523 if (pga > 6) { 523 if (pga > 6) {
524 dev_err(&client->dev, "invalid gain on %s\n", 524 dev_err(&client->dev, "invalid gain on %pOF\n",
525 node->full_name); 525 node);
526 of_node_put(node); 526 of_node_put(node);
527 return -EINVAL; 527 return -EINVAL;
528 } 528 }
@@ -532,8 +532,8 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)
532 data_rate = pval; 532 data_rate = pval;
533 if (data_rate > 7) { 533 if (data_rate > 7) {
534 dev_err(&client->dev, 534 dev_err(&client->dev,
535 "invalid data_rate on %s\n", 535 "invalid data_rate on %pOF\n",
536 node->full_name); 536 node);
537 of_node_put(node); 537 of_node_put(node);
538 return -EINVAL; 538 return -EINVAL;
539 } 539 }
diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
index cea7f9857a1f..4d799b5cceac 100644
--- a/drivers/iio/chemical/Kconfig
+++ b/drivers/iio/chemical/Kconfig
@@ -21,6 +21,13 @@ config ATLAS_PH_SENSOR
21 To compile this driver as module, choose M here: the 21 To compile this driver as module, choose M here: the
22 module will be called atlas-ph-sensor. 22 module will be called atlas-ph-sensor.
23 23
24config CCS811
25 tristate "AMS CCS811 VOC sensor"
26 depends on I2C
27 help
28 Say Y here to build I2C interface support for the AMS
29 CCS811 VOC (Volatile Organic Compounds) sensor
30
24config IAQCORE 31config IAQCORE
25 tristate "AMS iAQ-Core VOC sensors" 32 tristate "AMS iAQ-Core VOC sensors"
26 depends on I2C 33 depends on I2C
diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile
index b02202b41289..a629b29d1e0b 100644
--- a/drivers/iio/chemical/Makefile
+++ b/drivers/iio/chemical/Makefile
@@ -4,5 +4,6 @@
4 4
5# When adding new entries keep the list in alphabetical order 5# When adding new entries keep the list in alphabetical order
6obj-$(CONFIG_ATLAS_PH_SENSOR) += atlas-ph-sensor.o 6obj-$(CONFIG_ATLAS_PH_SENSOR) += atlas-ph-sensor.o
7obj-$(CONFIG_CCS811) += ccs811.o
7obj-$(CONFIG_IAQCORE) += ams-iaq-core.o 8obj-$(CONFIG_IAQCORE) += ams-iaq-core.o
8obj-$(CONFIG_VZ89X) += vz89x.o 9obj-$(CONFIG_VZ89X) += vz89x.o
diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c
new file mode 100644
index 000000000000..8dbb5eddeb1f
--- /dev/null
+++ b/drivers/iio/chemical/ccs811.c
@@ -0,0 +1,339 @@
1/*
2 * ccs811.c - Support for AMS CCS811 VOC Sensor
3 *
4 * Copyright (C) 2017 Narcisa Vasile <narcisaanamaria12@gmail.com>
5 *
6 * Datasheet: ams.com/content/download/951091/2269479/CCS811_DS000459_3-00.pdf
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * IIO driver for AMS CCS811 (I2C address 0x5A/0x5B set by ADDR Low/High)
13 *
14 * TODO:
15 * 1. Make the drive mode selectable form userspace
16 * 2. Add support for interrupts
17 * 3. Adjust time to wait for data to be ready based on selected operation mode
18 * 4. Read error register and put the information in logs
19 */
20
21#include <linux/delay.h>
22#include <linux/i2c.h>
23#include <linux/iio/iio.h>
24#include <linux/module.h>
25
26#define CCS811_STATUS 0x00
27#define CCS811_MEAS_MODE 0x01
28#define CCS811_ALG_RESULT_DATA 0x02
29#define CCS811_RAW_DATA 0x03
30#define CCS811_HW_ID 0x20
31#define CCS881_HW_ID_VALUE 0x81
32#define CCS811_HW_VERSION 0x21
33#define CCS811_HW_VERSION_VALUE 0x10
34#define CCS811_HW_VERSION_MASK 0xF0
35#define CCS811_ERR 0xE0
36/* Used to transition from boot to application mode */
37#define CCS811_APP_START 0xF4
38
39/* Status register flags */
40#define CCS811_STATUS_ERROR BIT(0)
41#define CCS811_STATUS_DATA_READY BIT(3)
42#define CCS811_STATUS_APP_VALID_MASK BIT(4)
43#define CCS811_STATUS_APP_VALID_LOADED BIT(4)
44/*
45 * Value of FW_MODE bit of STATUS register describes the sensor's state:
46 * 0: Firmware is in boot mode, this allows new firmware to be loaded
47 * 1: Firmware is in application mode. CCS811 is ready to take ADC measurements
48 */
49#define CCS811_STATUS_FW_MODE_MASK BIT(7)
50#define CCS811_STATUS_FW_MODE_APPLICATION BIT(7)
51
52/* Measurement modes */
53#define CCS811_MODE_IDLE 0x00
54#define CCS811_MODE_IAQ_1SEC 0x10
55#define CCS811_MODE_IAQ_10SEC 0x20
56#define CCS811_MODE_IAQ_60SEC 0x30
57#define CCS811_MODE_RAW_DATA 0x40
58
59#define CCS811_VOLTAGE_MASK 0x3FF
60
61struct ccs811_reading {
62 __be16 co2;
63 __be16 voc;
64 u8 status;
65 u8 error;
66 __be16 resistance;
67} __attribute__((__packed__));
68
69struct ccs811_data {
70 struct i2c_client *client;
71 struct mutex lock; /* Protect readings */
72 struct ccs811_reading buffer;
73};
74
75static const struct iio_chan_spec ccs811_channels[] = {
76 {
77 .type = IIO_CURRENT,
78 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
79 BIT(IIO_CHAN_INFO_SCALE)
80 }, {
81 .type = IIO_VOLTAGE,
82 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
83 BIT(IIO_CHAN_INFO_SCALE)
84 }, {
85 .type = IIO_CONCENTRATION,
86 .channel2 = IIO_MOD_CO2,
87 .modified = 1,
88 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
89 BIT(IIO_CHAN_INFO_OFFSET) |
90 BIT(IIO_CHAN_INFO_SCALE)
91 }, {
92 .type = IIO_CONCENTRATION,
93 .channel2 = IIO_MOD_VOC,
94 .modified = 1,
95 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
96 BIT(IIO_CHAN_INFO_SCALE)
97 },
98};
99
100/*
101 * The CCS811 powers-up in boot mode. A setup write to CCS811_APP_START will
102 * transition the sensor to application mode.
103 */
104static int ccs811_start_sensor_application(struct i2c_client *client)
105{
106 int ret;
107
108 ret = i2c_smbus_read_byte_data(client, CCS811_STATUS);
109 if (ret < 0)
110 return ret;
111
112 if ((ret & CCS811_STATUS_APP_VALID_MASK) !=
113 CCS811_STATUS_APP_VALID_LOADED)
114 return -EIO;
115
116 ret = i2c_smbus_write_byte(client, CCS811_APP_START);
117 if (ret < 0)
118 return ret;
119
120 ret = i2c_smbus_read_byte_data(client, CCS811_STATUS);
121 if (ret < 0)
122 return ret;
123
124 if ((ret & CCS811_STATUS_FW_MODE_MASK) !=
125 CCS811_STATUS_FW_MODE_APPLICATION) {
126 dev_err(&client->dev, "Application failed to start. Sensor is still in boot mode.\n");
127 return -EIO;
128 }
129
130 return 0;
131}
132
133static int ccs811_setup(struct i2c_client *client)
134{
135 int ret;
136
137 ret = ccs811_start_sensor_application(client);
138 if (ret < 0)
139 return ret;
140
141 return i2c_smbus_write_byte_data(client, CCS811_MEAS_MODE,
142 CCS811_MODE_IAQ_1SEC);
143}
144
145static int ccs811_get_measurement(struct ccs811_data *data)
146{
147 int ret, tries = 11;
148
149 /* Maximum waiting time: 1s, as measurements are made every second */
150 while (tries-- > 0) {
151 ret = i2c_smbus_read_byte_data(data->client, CCS811_STATUS);
152 if (ret < 0)
153 return ret;
154
155 if ((ret & CCS811_STATUS_DATA_READY) || tries == 0)
156 break;
157 msleep(100);
158 }
159 if (!(ret & CCS811_STATUS_DATA_READY))
160 return -EIO;
161
162 return i2c_smbus_read_i2c_block_data(data->client,
163 CCS811_ALG_RESULT_DATA, 8,
164 (char *)&data->buffer);
165}
166
167static int ccs811_read_raw(struct iio_dev *indio_dev,
168 struct iio_chan_spec const *chan,
169 int *val, int *val2, long mask)
170{
171 struct ccs811_data *data = iio_priv(indio_dev);
172 int ret;
173
174 switch (mask) {
175 case IIO_CHAN_INFO_RAW:
176 mutex_lock(&data->lock);
177 ret = ccs811_get_measurement(data);
178 if (ret < 0) {
179 mutex_unlock(&data->lock);
180 return ret;
181 }
182
183 switch (chan->type) {
184 case IIO_VOLTAGE:
185 *val = be16_to_cpu(data->buffer.resistance) &
186 CCS811_VOLTAGE_MASK;
187 ret = IIO_VAL_INT;
188 break;
189 case IIO_CURRENT:
190 *val = be16_to_cpu(data->buffer.resistance) >> 10;
191 ret = IIO_VAL_INT;
192 break;
193 case IIO_CONCENTRATION:
194 switch (chan->channel2) {
195 case IIO_MOD_CO2:
196 *val = be16_to_cpu(data->buffer.co2);
197 ret = IIO_VAL_INT;
198 break;
199 case IIO_MOD_VOC:
200 *val = be16_to_cpu(data->buffer.voc);
201 ret = IIO_VAL_INT;
202 break;
203 default:
204 ret = -EINVAL;
205 }
206 break;
207 default:
208 ret = -EINVAL;
209 }
210 mutex_unlock(&data->lock);
211
212 return ret;
213
214 case IIO_CHAN_INFO_SCALE:
215 switch (chan->type) {
216 case IIO_VOLTAGE:
217 *val = 1;
218 *val2 = 612903;
219 return IIO_VAL_INT_PLUS_MICRO;
220 case IIO_CURRENT:
221 *val = 0;
222 *val2 = 1000;
223 return IIO_VAL_INT_PLUS_MICRO;
224 case IIO_CONCENTRATION:
225 switch (chan->channel2) {
226 case IIO_MOD_CO2:
227 *val = 0;
228 *val2 = 12834;
229 return IIO_VAL_INT_PLUS_MICRO;
230 case IIO_MOD_VOC:
231 *val = 0;
232 *val2 = 84246;
233 return IIO_VAL_INT_PLUS_MICRO;
234 default:
235 return -EINVAL;
236 }
237 default:
238 return -EINVAL;
239 }
240 case IIO_CHAN_INFO_OFFSET:
241 if (!(chan->type == IIO_CONCENTRATION &&
242 chan->channel2 == IIO_MOD_CO2))
243 return -EINVAL;
244 *val = -400;
245 return IIO_VAL_INT;
246 default:
247 return -EINVAL;
248 }
249}
250
251static const struct iio_info ccs811_info = {
252 .read_raw = ccs811_read_raw,
253 .driver_module = THIS_MODULE,
254};
255
256static int ccs811_probe(struct i2c_client *client,
257 const struct i2c_device_id *id)
258{
259 struct iio_dev *indio_dev;
260 struct ccs811_data *data;
261 int ret;
262
263 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_BYTE
264 | I2C_FUNC_SMBUS_BYTE_DATA
265 | I2C_FUNC_SMBUS_READ_I2C_BLOCK))
266 return -EOPNOTSUPP;
267
268 /* Check hardware id (should be 0x81 for this family of devices) */
269 ret = i2c_smbus_read_byte_data(client, CCS811_HW_ID);
270 if (ret < 0)
271 return ret;
272
273 if (ret != CCS881_HW_ID_VALUE) {
274 dev_err(&client->dev, "hardware id doesn't match CCS81x\n");
275 return -ENODEV;
276 }
277
278 ret = i2c_smbus_read_byte_data(client, CCS811_HW_VERSION);
279 if (ret < 0)
280 return ret;
281
282 if ((ret & CCS811_HW_VERSION_MASK) != CCS811_HW_VERSION_VALUE) {
283 dev_err(&client->dev, "no CCS811 sensor\n");
284 return -ENODEV;
285 }
286
287 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
288 if (!indio_dev)
289 return -ENOMEM;
290
291 ret = ccs811_setup(client);
292 if (ret < 0)
293 return ret;
294
295 data = iio_priv(indio_dev);
296 i2c_set_clientdata(client, indio_dev);
297 data->client = client;
298
299 mutex_init(&data->lock);
300
301 indio_dev->dev.parent = &client->dev;
302 indio_dev->name = id->name;
303 indio_dev->info = &ccs811_info;
304
305 indio_dev->channels = ccs811_channels;
306 indio_dev->num_channels = ARRAY_SIZE(ccs811_channels);
307
308 return iio_device_register(indio_dev);
309}
310
311static int ccs811_remove(struct i2c_client *client)
312{
313 struct iio_dev *indio_dev = i2c_get_clientdata(client);
314
315 iio_device_unregister(indio_dev);
316
317 return i2c_smbus_write_byte_data(client, CCS811_MEAS_MODE,
318 CCS811_MODE_IDLE);
319}
320
321static const struct i2c_device_id ccs811_id[] = {
322 {"ccs811", 0},
323 { }
324};
325MODULE_DEVICE_TABLE(i2c, ccs811_id);
326
327static struct i2c_driver ccs811_driver = {
328 .driver = {
329 .name = "ccs811",
330 },
331 .probe = ccs811_probe,
332 .remove = ccs811_remove,
333 .id_table = ccs811_id,
334};
335module_i2c_driver(ccs811_driver);
336
337MODULE_AUTHOR("Narcisa Vasile <narcisaanamaria12@gmail.com>");
338MODULE_DESCRIPTION("CCS811 volatile organic compounds sensor");
339MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 79c8c7cd70d5..274868100fd0 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -15,6 +15,7 @@
15#include <linux/iio/iio.h> 15#include <linux/iio/iio.h>
16#include <linux/regulator/consumer.h> 16#include <linux/regulator/consumer.h>
17#include <linux/of.h> 17#include <linux/of.h>
18#include <linux/of_device.h>
18#include <asm/unaligned.h> 19#include <asm/unaligned.h>
19#include <linux/iio/common/st_sensors.h> 20#include <linux/iio/common/st_sensors.h>
20 21
@@ -345,6 +346,36 @@ static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev,
345 346
346 return pdata; 347 return pdata;
347} 348}
349
350/**
351 * st_sensors_of_name_probe() - device tree probe for ST sensor name
352 * @dev: driver model representation of the device.
353 * @match: the OF match table for the device, containing compatible strings
354 * but also a .data field with the corresponding internal kernel name
355 * used by this sensor.
356 * @name: device name buffer reference.
357 * @len: device name buffer length.
358 *
359 * In effect this function matches a compatible string to an internal kernel
360 * name for a certain sensor device, so that the rest of the autodetection can
361 * rely on that name from this point on. I2C/SPI devices will be renamed
362 * to match the internal kernel convention.
363 */
364void st_sensors_of_name_probe(struct device *dev,
365 const struct of_device_id *match,
366 char *name, int len)
367{
368 const struct of_device_id *of_id;
369
370 of_id = of_match_device(match, dev);
371 if (!of_id || !of_id->data)
372 return;
373
374 /* The name from the OF match takes precedence if present */
375 strncpy(name, of_id->data, len);
376 name[len - 1] = '\0';
377}
378EXPORT_SYMBOL(st_sensors_of_name_probe);
348#else 379#else
349static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev, 380static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev,
350 struct st_sensors_platform_data *defdata) 381 struct st_sensors_platform_data *defdata)
diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c
index c83df4dbfcd7..b81e48e9f27e 100644
--- a/drivers/iio/common/st_sensors/st_sensors_i2c.c
+++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c
@@ -79,35 +79,6 @@ void st_sensors_i2c_configure(struct iio_dev *indio_dev,
79} 79}
80EXPORT_SYMBOL(st_sensors_i2c_configure); 80EXPORT_SYMBOL(st_sensors_i2c_configure);
81 81
82#ifdef CONFIG_OF
83/**
84 * st_sensors_of_i2c_probe() - device tree probe for ST I2C sensors
85 * @client: the I2C client device for the sensor
86 * @match: the OF match table for the device, containing compatible strings
87 * but also a .data field with the corresponding internal kernel name
88 * used by this sensor.
89 *
90 * In effect this function matches a compatible string to an internal kernel
91 * name for a certain sensor device, so that the rest of the autodetection can
92 * rely on that name from this point on. I2C client devices will be renamed
93 * to match the internal kernel convention.
94 */
95void st_sensors_of_i2c_probe(struct i2c_client *client,
96 const struct of_device_id *match)
97{
98 const struct of_device_id *of_id;
99
100 of_id = of_match_device(match, &client->dev);
101 if (!of_id)
102 return;
103
104 /* The name from the OF match takes precedence if present */
105 strncpy(client->name, of_id->data, sizeof(client->name));
106 client->name[sizeof(client->name) - 1] = '\0';
107}
108EXPORT_SYMBOL(st_sensors_of_i2c_probe);
109#endif
110
111#ifdef CONFIG_ACPI 82#ifdef CONFIG_ACPI
112int st_sensors_match_acpi_device(struct device *dev) 83int st_sensors_match_acpi_device(struct device *dev)
113{ 84{
diff --git a/drivers/iio/dac/stm32-dac-core.c b/drivers/iio/dac/stm32-dac-core.c
index 75e48788c7ea..32701be71cf7 100644
--- a/drivers/iio/dac/stm32-dac-core.c
+++ b/drivers/iio/dac/stm32-dac-core.c
@@ -42,6 +42,14 @@ struct stm32_dac_priv {
42 struct stm32_dac_common common; 42 struct stm32_dac_common common;
43}; 43};
44 44
45/**
46 * struct stm32_dac_cfg - DAC configuration
47 * @has_hfsel: DAC has high frequency control
48 */
49struct stm32_dac_cfg {
50 bool has_hfsel;
51};
52
45static struct stm32_dac_priv *to_stm32_dac_priv(struct stm32_dac_common *com) 53static struct stm32_dac_priv *to_stm32_dac_priv(struct stm32_dac_common *com)
46{ 54{
47 return container_of(com, struct stm32_dac_priv, common); 55 return container_of(com, struct stm32_dac_priv, common);
@@ -57,6 +65,7 @@ static const struct regmap_config stm32_dac_regmap_cfg = {
57static int stm32_dac_probe(struct platform_device *pdev) 65static int stm32_dac_probe(struct platform_device *pdev)
58{ 66{
59 struct device *dev = &pdev->dev; 67 struct device *dev = &pdev->dev;
68 const struct stm32_dac_cfg *cfg;
60 struct stm32_dac_priv *priv; 69 struct stm32_dac_priv *priv;
61 struct regmap *regmap; 70 struct regmap *regmap;
62 struct resource *res; 71 struct resource *res;
@@ -69,6 +78,8 @@ static int stm32_dac_probe(struct platform_device *pdev)
69 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 78 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
70 if (!priv) 79 if (!priv)
71 return -ENOMEM; 80 return -ENOMEM;
81 cfg = (const struct stm32_dac_cfg *)
82 of_match_device(dev->driver->of_match_table, dev)->data;
72 83
73 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 84 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
74 mmio = devm_ioremap_resource(dev, res); 85 mmio = devm_ioremap_resource(dev, res);
@@ -121,12 +132,16 @@ static int stm32_dac_probe(struct platform_device *pdev)
121 reset_control_deassert(priv->rst); 132 reset_control_deassert(priv->rst);
122 } 133 }
123 134
124 /* When clock speed is higher than 80MHz, set HFSEL */ 135 if (cfg && cfg->has_hfsel) {
125 priv->common.hfsel = (clk_get_rate(priv->pclk) > 80000000UL); 136 /* When clock speed is higher than 80MHz, set HFSEL */
126 ret = regmap_update_bits(regmap, STM32_DAC_CR, STM32H7_DAC_CR_HFSEL, 137 priv->common.hfsel = (clk_get_rate(priv->pclk) > 80000000UL);
127 priv->common.hfsel ? STM32H7_DAC_CR_HFSEL : 0); 138 ret = regmap_update_bits(regmap, STM32_DAC_CR,
128 if (ret) 139 STM32H7_DAC_CR_HFSEL,
129 goto err_pclk; 140 priv->common.hfsel ?
141 STM32H7_DAC_CR_HFSEL : 0);
142 if (ret)
143 goto err_pclk;
144 }
130 145
131 platform_set_drvdata(pdev, &priv->common); 146 platform_set_drvdata(pdev, &priv->common);
132 147
@@ -158,8 +173,17 @@ static int stm32_dac_remove(struct platform_device *pdev)
158 return 0; 173 return 0;
159} 174}
160 175
176static const struct stm32_dac_cfg stm32h7_dac_cfg = {
177 .has_hfsel = true,
178};
179
161static const struct of_device_id stm32_dac_of_match[] = { 180static const struct of_device_id stm32_dac_of_match[] = {
162 { .compatible = "st,stm32h7-dac-core", }, 181 {
182 .compatible = "st,stm32f4-dac-core",
183 }, {
184 .compatible = "st,stm32h7-dac-core",
185 .data = (void *)&stm32h7_dac_cfg,
186 },
163 {}, 187 {},
164}; 188};
165MODULE_DEVICE_TABLE(of, stm32_dac_of_match); 189MODULE_DEVICE_TABLE(of, stm32_dac_of_match);
diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
index 50f8ec091058..c1864e8aa851 100644
--- a/drivers/iio/dac/stm32-dac.c
+++ b/drivers/iio/dac/stm32-dac.c
@@ -268,7 +268,7 @@ static int stm32_dac_chan_of_init(struct iio_dev *indio_dev)
268 break; 268 break;
269 } 269 }
270 if (i >= ARRAY_SIZE(stm32_dac_channels)) { 270 if (i >= ARRAY_SIZE(stm32_dac_channels)) {
271 dev_err(&indio_dev->dev, "Invalid st,dac-channel\n"); 271 dev_err(&indio_dev->dev, "Invalid reg property\n");
272 return -EINVAL; 272 return -EINVAL;
273 } 273 }
274 274
diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
index 2be2a5d287e6..e0d241a9aa30 100644
--- a/drivers/iio/gyro/mpu3050-core.c
+++ b/drivers/iio/gyro/mpu3050-core.c
@@ -1063,11 +1063,6 @@ static int mpu3050_trigger_probe(struct iio_dev *indio_dev, int irq)
1063 case IRQF_TRIGGER_RISING: 1063 case IRQF_TRIGGER_RISING:
1064 dev_info(&indio_dev->dev, 1064 dev_info(&indio_dev->dev,
1065 "pulse interrupts on the rising edge\n"); 1065 "pulse interrupts on the rising edge\n");
1066 if (mpu3050->irq_opendrain) {
1067 dev_info(&indio_dev->dev,
1068 "rising edge incompatible with open drain\n");
1069 mpu3050->irq_opendrain = false;
1070 }
1071 break; 1066 break;
1072 case IRQF_TRIGGER_FALLING: 1067 case IRQF_TRIGGER_FALLING:
1073 mpu3050->irq_actl = true; 1068 mpu3050->irq_actl = true;
@@ -1078,11 +1073,6 @@ static int mpu3050_trigger_probe(struct iio_dev *indio_dev, int irq)
1078 mpu3050->irq_latch = true; 1073 mpu3050->irq_latch = true;
1079 dev_info(&indio_dev->dev, 1074 dev_info(&indio_dev->dev,
1080 "interrupts active high level\n"); 1075 "interrupts active high level\n");
1081 if (mpu3050->irq_opendrain) {
1082 dev_info(&indio_dev->dev,
1083 "active high incompatible with open drain\n");
1084 mpu3050->irq_opendrain = false;
1085 }
1086 /* 1076 /*
1087 * With level IRQs, we mask the IRQ until it is processed, 1077 * With level IRQs, we mask the IRQ until it is processed,
1088 * but with edge IRQs (pulses) we can queue several interrupts 1078 * but with edge IRQs (pulses) we can queue several interrupts
diff --git a/drivers/iio/gyro/st_gyro.h b/drivers/iio/gyro/st_gyro.h
index a5c5c4e29add..48923ae6ac3b 100644
--- a/drivers/iio/gyro/st_gyro.h
+++ b/drivers/iio/gyro/st_gyro.h
@@ -19,6 +19,7 @@
19#define LSM330DL_GYRO_DEV_NAME "lsm330dl_gyro" 19#define LSM330DL_GYRO_DEV_NAME "lsm330dl_gyro"
20#define LSM330DLC_GYRO_DEV_NAME "lsm330dlc_gyro" 20#define LSM330DLC_GYRO_DEV_NAME "lsm330dlc_gyro"
21#define L3GD20_GYRO_DEV_NAME "l3gd20" 21#define L3GD20_GYRO_DEV_NAME "l3gd20"
22#define L3GD20H_GYRO_DEV_NAME "l3gd20h"
22#define L3G4IS_GYRO_DEV_NAME "l3g4is_ui" 23#define L3G4IS_GYRO_DEV_NAME "l3g4is_ui"
23#define LSM330_GYRO_DEV_NAME "lsm330_gyro" 24#define LSM330_GYRO_DEV_NAME "lsm330_gyro"
24#define LSM9DS0_GYRO_DEV_NAME "lsm9ds0_gyro" 25#define LSM9DS0_GYRO_DEV_NAME "lsm9ds0_gyro"
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index 2a42b3d583e8..e366422e8512 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -35,6 +35,7 @@
35#define ST_GYRO_DEFAULT_OUT_Z_L_ADDR 0x2c 35#define ST_GYRO_DEFAULT_OUT_Z_L_ADDR 0x2c
36 36
37/* FULLSCALE */ 37/* FULLSCALE */
38#define ST_GYRO_FS_AVL_245DPS 245
38#define ST_GYRO_FS_AVL_250DPS 250 39#define ST_GYRO_FS_AVL_250DPS 250
39#define ST_GYRO_FS_AVL_500DPS 500 40#define ST_GYRO_FS_AVL_500DPS 500
40#define ST_GYRO_FS_AVL_2000DPS 2000 41#define ST_GYRO_FS_AVL_2000DPS 2000
@@ -196,17 +197,17 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
196 .wai = 0xd7, 197 .wai = 0xd7,
197 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, 198 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
198 .sensors_supported = { 199 .sensors_supported = {
199 [0] = L3GD20_GYRO_DEV_NAME, 200 [0] = L3GD20H_GYRO_DEV_NAME,
200 }, 201 },
201 .ch = (struct iio_chan_spec *)st_gyro_16bit_channels, 202 .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
202 .odr = { 203 .odr = {
203 .addr = 0x20, 204 .addr = 0x20,
204 .mask = 0xc0, 205 .mask = 0xc0,
205 .odr_avl = { 206 .odr_avl = {
206 { .hz = 95, .value = 0x00, }, 207 { .hz = 100, .value = 0x00, },
207 { .hz = 190, .value = 0x01, }, 208 { .hz = 200, .value = 0x01, },
208 { .hz = 380, .value = 0x02, }, 209 { .hz = 400, .value = 0x02, },
209 { .hz = 760, .value = 0x03, }, 210 { .hz = 800, .value = 0x03, },
210 }, 211 },
211 }, 212 },
212 .pw = { 213 .pw = {
@@ -224,7 +225,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
224 .mask = 0x30, 225 .mask = 0x30,
225 .fs_avl = { 226 .fs_avl = {
226 [0] = { 227 [0] = {
227 .num = ST_GYRO_FS_AVL_250DPS, 228 .num = ST_GYRO_FS_AVL_245DPS,
228 .value = 0x00, 229 .value = 0x00,
229 .gain = IIO_DEGREE_TO_RAD(8750), 230 .gain = IIO_DEGREE_TO_RAD(8750),
230 }, 231 },
diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
index 40056b821036..b405b82b9177 100644
--- a/drivers/iio/gyro/st_gyro_i2c.c
+++ b/drivers/iio/gyro/st_gyro_i2c.c
@@ -41,6 +41,10 @@ static const struct of_device_id st_gyro_of_match[] = {
41 .data = L3GD20_GYRO_DEV_NAME, 41 .data = L3GD20_GYRO_DEV_NAME,
42 }, 42 },
43 { 43 {
44 .compatible = "st,l3gd20h-gyro",
45 .data = L3GD20H_GYRO_DEV_NAME,
46 },
47 {
44 .compatible = "st,l3g4is-gyro", 48 .compatible = "st,l3g4is-gyro",
45 .data = L3G4IS_GYRO_DEV_NAME, 49 .data = L3G4IS_GYRO_DEV_NAME,
46 }, 50 },
@@ -71,7 +75,8 @@ static int st_gyro_i2c_probe(struct i2c_client *client,
71 return -ENOMEM; 75 return -ENOMEM;
72 76
73 gdata = iio_priv(indio_dev); 77 gdata = iio_priv(indio_dev);
74 st_sensors_of_i2c_probe(client, st_gyro_of_match); 78 st_sensors_of_name_probe(&client->dev, st_gyro_of_match,
79 client->name, sizeof(client->name));
75 80
76 st_sensors_i2c_configure(indio_dev, client, gdata); 81 st_sensors_i2c_configure(indio_dev, client, gdata);
77 82
@@ -95,6 +100,7 @@ static const struct i2c_device_id st_gyro_id_table[] = {
95 { LSM330DL_GYRO_DEV_NAME }, 100 { LSM330DL_GYRO_DEV_NAME },
96 { LSM330DLC_GYRO_DEV_NAME }, 101 { LSM330DLC_GYRO_DEV_NAME },
97 { L3GD20_GYRO_DEV_NAME }, 102 { L3GD20_GYRO_DEV_NAME },
103 { L3GD20H_GYRO_DEV_NAME },
98 { L3G4IS_GYRO_DEV_NAME }, 104 { L3G4IS_GYRO_DEV_NAME },
99 { LSM330_GYRO_DEV_NAME }, 105 { LSM330_GYRO_DEV_NAME },
100 { LSM9DS0_GYRO_DEV_NAME }, 106 { LSM9DS0_GYRO_DEV_NAME },
diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c
index fbf2faed501c..0b52ed577dc2 100644
--- a/drivers/iio/gyro/st_gyro_spi.c
+++ b/drivers/iio/gyro/st_gyro_spi.c
@@ -18,6 +18,56 @@
18#include <linux/iio/common/st_sensors_spi.h> 18#include <linux/iio/common/st_sensors_spi.h>
19#include "st_gyro.h" 19#include "st_gyro.h"
20 20
21#ifdef CONFIG_OF
22/*
23 * For new single-chip sensors use <device_name> as compatible string.
24 * For old single-chip devices keep <device_name>-gyro to maintain
25 * compatibility
26 */
27static const struct of_device_id st_gyro_of_match[] = {
28 {
29 .compatible = "st,l3g4200d-gyro",
30 .data = L3G4200D_GYRO_DEV_NAME,
31 },
32 {
33 .compatible = "st,lsm330d-gyro",
34 .data = LSM330D_GYRO_DEV_NAME,
35 },
36 {
37 .compatible = "st,lsm330dl-gyro",
38 .data = LSM330DL_GYRO_DEV_NAME,
39 },
40 {
41 .compatible = "st,lsm330dlc-gyro",
42 .data = LSM330DLC_GYRO_DEV_NAME,
43 },
44 {
45 .compatible = "st,l3gd20-gyro",
46 .data = L3GD20_GYRO_DEV_NAME,
47 },
48 {
49 .compatible = "st,l3gd20h-gyro",
50 .data = L3GD20H_GYRO_DEV_NAME,
51 },
52 {
53 .compatible = "st,l3g4is-gyro",
54 .data = L3G4IS_GYRO_DEV_NAME,
55 },
56 {
57 .compatible = "st,lsm330-gyro",
58 .data = LSM330_GYRO_DEV_NAME,
59 },
60 {
61 .compatible = "st,lsm9ds0-gyro",
62 .data = LSM9DS0_GYRO_DEV_NAME,
63 },
64 {},
65};
66MODULE_DEVICE_TABLE(of, st_gyro_of_match);
67#else
68#define st_gyro_of_match NULL
69#endif
70
21static int st_gyro_spi_probe(struct spi_device *spi) 71static int st_gyro_spi_probe(struct spi_device *spi)
22{ 72{
23 struct iio_dev *indio_dev; 73 struct iio_dev *indio_dev;
@@ -30,6 +80,8 @@ static int st_gyro_spi_probe(struct spi_device *spi)
30 80
31 gdata = iio_priv(indio_dev); 81 gdata = iio_priv(indio_dev);
32 82
83 st_sensors_of_name_probe(&spi->dev, st_gyro_of_match,
84 spi->modalias, sizeof(spi->modalias));
33 st_sensors_spi_configure(indio_dev, spi, gdata); 85 st_sensors_spi_configure(indio_dev, spi, gdata);
34 86
35 err = st_gyro_common_probe(indio_dev); 87 err = st_gyro_common_probe(indio_dev);
@@ -52,6 +104,7 @@ static const struct spi_device_id st_gyro_id_table[] = {
52 { LSM330DL_GYRO_DEV_NAME }, 104 { LSM330DL_GYRO_DEV_NAME },
53 { LSM330DLC_GYRO_DEV_NAME }, 105 { LSM330DLC_GYRO_DEV_NAME },
54 { L3GD20_GYRO_DEV_NAME }, 106 { L3GD20_GYRO_DEV_NAME },
107 { L3GD20H_GYRO_DEV_NAME },
55 { L3G4IS_GYRO_DEV_NAME }, 108 { L3G4IS_GYRO_DEV_NAME },
56 { LSM330_GYRO_DEV_NAME }, 109 { LSM330_GYRO_DEV_NAME },
57 { LSM9DS0_GYRO_DEV_NAME }, 110 { LSM9DS0_GYRO_DEV_NAME },
@@ -62,6 +115,7 @@ MODULE_DEVICE_TABLE(spi, st_gyro_id_table);
62static struct spi_driver st_gyro_driver = { 115static struct spi_driver st_gyro_driver = {
63 .driver = { 116 .driver = {
64 .name = "st-gyro-spi", 117 .name = "st-gyro-spi",
118 .of_match_table = of_match_ptr(st_gyro_of_match),
65 }, 119 },
66 .probe = st_gyro_spi_probe, 120 .probe = st_gyro_spi_probe,
67 .remove = st_gyro_spi_remove, 121 .remove = st_gyro_spi_remove,
diff --git a/drivers/iio/humidity/Kconfig b/drivers/iio/humidity/Kconfig
index 14b9ce453d9d..2c0fc9a400b8 100644
--- a/drivers/iio/humidity/Kconfig
+++ b/drivers/iio/humidity/Kconfig
@@ -31,7 +31,8 @@ config HDC100X
31 select IIO_TRIGGERED_BUFFER 31 select IIO_TRIGGERED_BUFFER
32 help 32 help
33 Say yes here to build support for the Texas Instruments 33 Say yes here to build support for the Texas Instruments
34 HDC1000 and HDC1008 relative humidity and temperature sensors. 34 HDC1000, HDC1008, HDC1010, HDC1050, and HDC1080 relative
35 humidity and temperature sensors.
35 36
36 To compile this driver as a module, choose M here: the module 37 To compile this driver as a module, choose M here: the module
37 will be called hdc100x. 38 will be called hdc100x.
diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
index aa17115f54c9..7851bd90ef64 100644
--- a/drivers/iio/humidity/hdc100x.c
+++ b/drivers/iio/humidity/hdc100x.c
@@ -13,6 +13,12 @@
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * Datasheets:
17 * http://www.ti.com/product/HDC1000/datasheet
18 * http://www.ti.com/product/HDC1008/datasheet
19 * http://www.ti.com/product/HDC1010/datasheet
20 * http://www.ti.com/product/HDC1050/datasheet
21 * http://www.ti.com/product/HDC1080/datasheet
16 */ 22 */
17 23
18#include <linux/delay.h> 24#include <linux/delay.h>
@@ -414,13 +420,29 @@ static int hdc100x_remove(struct i2c_client *client)
414 420
415static const struct i2c_device_id hdc100x_id[] = { 421static const struct i2c_device_id hdc100x_id[] = {
416 { "hdc100x", 0 }, 422 { "hdc100x", 0 },
423 { "hdc1000", 0 },
424 { "hdc1008", 0 },
425 { "hdc1010", 0 },
426 { "hdc1050", 0 },
427 { "hdc1080", 0 },
417 { } 428 { }
418}; 429};
419MODULE_DEVICE_TABLE(i2c, hdc100x_id); 430MODULE_DEVICE_TABLE(i2c, hdc100x_id);
420 431
432static const struct of_device_id hdc100x_dt_ids[] = {
433 { .compatible = "ti,hdc1000" },
434 { .compatible = "ti,hdc1008" },
435 { .compatible = "ti,hdc1010" },
436 { .compatible = "ti,hdc1050" },
437 { .compatible = "ti,hdc1080" },
438 { }
439};
440MODULE_DEVICE_TABLE(of, hdc100x_dt_ids);
441
421static struct i2c_driver hdc100x_driver = { 442static struct i2c_driver hdc100x_driver = {
422 .driver = { 443 .driver = {
423 .name = "hdc100x", 444 .name = "hdc100x",
445 .of_match_table = of_match_ptr(hdc100x_dt_ids),
424 }, 446 },
425 .probe = hdc100x_probe, 447 .probe = hdc100x_probe,
426 .remove = hdc100x_remove, 448 .remove = hdc100x_remove,
diff --git a/drivers/iio/humidity/hts221.h b/drivers/iio/humidity/hts221.h
index 94510266e0a5..51d021966222 100644
--- a/drivers/iio/humidity/hts221.h
+++ b/drivers/iio/humidity/hts221.h
@@ -30,12 +30,6 @@ struct hts221_transfer_function {
30 int (*write)(struct device *dev, u8 addr, int len, u8 *data); 30 int (*write)(struct device *dev, u8 addr, int len, u8 *data);
31}; 31};
32 32
33#define HTS221_AVG_DEPTH 8
34struct hts221_avg_avl {
35 u16 avg;
36 u8 val;
37};
38
39enum hts221_sensor_type { 33enum hts221_sensor_type {
40 HTS221_SENSOR_H, 34 HTS221_SENSOR_H,
41 HTS221_SENSOR_T, 35 HTS221_SENSOR_T,
@@ -66,10 +60,9 @@ struct hts221_hw {
66 60
67extern const struct dev_pm_ops hts221_pm_ops; 61extern const struct dev_pm_ops hts221_pm_ops;
68 62
69int hts221_config_drdy(struct hts221_hw *hw, bool enable); 63int hts221_write_with_mask(struct hts221_hw *hw, u8 addr, u8 mask, u8 val);
70int hts221_probe(struct iio_dev *iio_dev); 64int hts221_probe(struct iio_dev *iio_dev);
71int hts221_power_on(struct hts221_hw *hw); 65int hts221_set_enable(struct hts221_hw *hw, bool enable);
72int hts221_power_off(struct hts221_hw *hw);
73int hts221_allocate_buffers(struct hts221_hw *hw); 66int hts221_allocate_buffers(struct hts221_hw *hw);
74int hts221_allocate_trigger(struct hts221_hw *hw); 67int hts221_allocate_trigger(struct hts221_hw *hw);
75 68
diff --git a/drivers/iio/humidity/hts221_buffer.c b/drivers/iio/humidity/hts221_buffer.c
index 7d19a3da7ab7..9690dfe9a844 100644
--- a/drivers/iio/humidity/hts221_buffer.c
+++ b/drivers/iio/humidity/hts221_buffer.c
@@ -20,8 +20,16 @@
20#include <linux/iio/triggered_buffer.h> 20#include <linux/iio/triggered_buffer.h>
21#include <linux/iio/buffer.h> 21#include <linux/iio/buffer.h>
22 22
23#include <linux/platform_data/st_sensors_pdata.h>
24
23#include "hts221.h" 25#include "hts221.h"
24 26
27#define HTS221_REG_DRDY_HL_ADDR 0x22
28#define HTS221_REG_DRDY_HL_MASK BIT(7)
29#define HTS221_REG_DRDY_PP_OD_ADDR 0x22
30#define HTS221_REG_DRDY_PP_OD_MASK BIT(6)
31#define HTS221_REG_DRDY_EN_ADDR 0x22
32#define HTS221_REG_DRDY_EN_MASK BIT(2)
25#define HTS221_REG_STATUS_ADDR 0x27 33#define HTS221_REG_STATUS_ADDR 0x27
26#define HTS221_RH_DRDY_MASK BIT(1) 34#define HTS221_RH_DRDY_MASK BIT(1)
27#define HTS221_TEMP_DRDY_MASK BIT(0) 35#define HTS221_TEMP_DRDY_MASK BIT(0)
@@ -30,8 +38,12 @@ static int hts221_trig_set_state(struct iio_trigger *trig, bool state)
30{ 38{
31 struct iio_dev *iio_dev = iio_trigger_get_drvdata(trig); 39 struct iio_dev *iio_dev = iio_trigger_get_drvdata(trig);
32 struct hts221_hw *hw = iio_priv(iio_dev); 40 struct hts221_hw *hw = iio_priv(iio_dev);
41 int err;
42
43 err = hts221_write_with_mask(hw, HTS221_REG_DRDY_EN_ADDR,
44 HTS221_REG_DRDY_EN_MASK, state);
33 45
34 return hts221_config_drdy(hw, state); 46 return err < 0 ? err : 0;
35} 47}
36 48
37static const struct iio_trigger_ops hts221_trigger_ops = { 49static const struct iio_trigger_ops hts221_trigger_ops = {
@@ -67,6 +79,9 @@ static irqreturn_t hts221_trigger_handler_thread(int irq, void *private)
67int hts221_allocate_trigger(struct hts221_hw *hw) 79int hts221_allocate_trigger(struct hts221_hw *hw)
68{ 80{
69 struct iio_dev *iio_dev = iio_priv_to_dev(hw); 81 struct iio_dev *iio_dev = iio_priv_to_dev(hw);
82 bool irq_active_low = false, open_drain = false;
83 struct device_node *np = hw->dev->of_node;
84 struct st_sensors_platform_data *pdata;
70 unsigned long irq_type; 85 unsigned long irq_type;
71 int err; 86 int err;
72 87
@@ -76,6 +91,10 @@ int hts221_allocate_trigger(struct hts221_hw *hw)
76 case IRQF_TRIGGER_HIGH: 91 case IRQF_TRIGGER_HIGH:
77 case IRQF_TRIGGER_RISING: 92 case IRQF_TRIGGER_RISING:
78 break; 93 break;
94 case IRQF_TRIGGER_LOW:
95 case IRQF_TRIGGER_FALLING:
96 irq_active_low = true;
97 break;
79 default: 98 default:
80 dev_info(hw->dev, 99 dev_info(hw->dev,
81 "mode %lx unsupported, using IRQF_TRIGGER_RISING\n", 100 "mode %lx unsupported, using IRQF_TRIGGER_RISING\n",
@@ -84,6 +103,24 @@ int hts221_allocate_trigger(struct hts221_hw *hw)
84 break; 103 break;
85 } 104 }
86 105
106 err = hts221_write_with_mask(hw, HTS221_REG_DRDY_HL_ADDR,
107 HTS221_REG_DRDY_HL_MASK, irq_active_low);
108 if (err < 0)
109 return err;
110
111 pdata = (struct st_sensors_platform_data *)hw->dev->platform_data;
112 if ((np && of_property_read_bool(np, "drive-open-drain")) ||
113 (pdata && pdata->open_drain)) {
114 irq_type |= IRQF_SHARED;
115 open_drain = true;
116 }
117
118 err = hts221_write_with_mask(hw, HTS221_REG_DRDY_PP_OD_ADDR,
119 HTS221_REG_DRDY_PP_OD_MASK,
120 open_drain);
121 if (err < 0)
122 return err;
123
87 err = devm_request_threaded_irq(hw->dev, hw->irq, NULL, 124 err = devm_request_threaded_irq(hw->dev, hw->irq, NULL,
88 hts221_trigger_handler_thread, 125 hts221_trigger_handler_thread,
89 irq_type | IRQF_ONESHOT, 126 irq_type | IRQF_ONESHOT,
@@ -109,12 +146,12 @@ int hts221_allocate_trigger(struct hts221_hw *hw)
109 146
110static int hts221_buffer_preenable(struct iio_dev *iio_dev) 147static int hts221_buffer_preenable(struct iio_dev *iio_dev)
111{ 148{
112 return hts221_power_on(iio_priv(iio_dev)); 149 return hts221_set_enable(iio_priv(iio_dev), true);
113} 150}
114 151
115static int hts221_buffer_postdisable(struct iio_dev *iio_dev) 152static int hts221_buffer_postdisable(struct iio_dev *iio_dev)
116{ 153{
117 return hts221_power_off(iio_priv(iio_dev)); 154 return hts221_set_enable(iio_priv(iio_dev), false);
118} 155}
119 156
120static const struct iio_buffer_setup_ops hts221_buffer_ops = { 157static const struct iio_buffer_setup_ops hts221_buffer_ops = {
diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c
index a56da3999e00..32524a8dc66f 100644
--- a/drivers/iio/humidity/hts221_core.c
+++ b/drivers/iio/humidity/hts221_core.c
@@ -23,7 +23,6 @@
23 23
24#define HTS221_REG_CNTRL1_ADDR 0x20 24#define HTS221_REG_CNTRL1_ADDR 0x20
25#define HTS221_REG_CNTRL2_ADDR 0x21 25#define HTS221_REG_CNTRL2_ADDR 0x21
26#define HTS221_REG_CNTRL3_ADDR 0x22
27 26
28#define HTS221_REG_AVG_ADDR 0x10 27#define HTS221_REG_AVG_ADDR 0x10
29#define HTS221_REG_H_OUT_L 0x28 28#define HTS221_REG_H_OUT_L 0x28
@@ -32,30 +31,9 @@
32#define HTS221_HUMIDITY_AVG_MASK 0x07 31#define HTS221_HUMIDITY_AVG_MASK 0x07
33#define HTS221_TEMP_AVG_MASK 0x38 32#define HTS221_TEMP_AVG_MASK 0x38
34 33
35#define HTS221_ODR_MASK 0x87 34#define HTS221_ODR_MASK 0x03
36#define HTS221_BDU_MASK BIT(2) 35#define HTS221_BDU_MASK BIT(2)
37 36#define HTS221_ENABLE_MASK BIT(7)
38#define HTS221_DRDY_MASK BIT(2)
39
40#define HTS221_ENABLE_SENSOR BIT(7)
41
42#define HTS221_HUMIDITY_AVG_4 0x00 /* 0.4 %RH */
43#define HTS221_HUMIDITY_AVG_8 0x01 /* 0.3 %RH */
44#define HTS221_HUMIDITY_AVG_16 0x02 /* 0.2 %RH */
45#define HTS221_HUMIDITY_AVG_32 0x03 /* 0.15 %RH */
46#define HTS221_HUMIDITY_AVG_64 0x04 /* 0.1 %RH */
47#define HTS221_HUMIDITY_AVG_128 0x05 /* 0.07 %RH */
48#define HTS221_HUMIDITY_AVG_256 0x06 /* 0.05 %RH */
49#define HTS221_HUMIDITY_AVG_512 0x07 /* 0.03 %RH */
50
51#define HTS221_TEMP_AVG_2 0x00 /* 0.08 degC */
52#define HTS221_TEMP_AVG_4 0x08 /* 0.05 degC */
53#define HTS221_TEMP_AVG_8 0x10 /* 0.04 degC */
54#define HTS221_TEMP_AVG_16 0x18 /* 0.03 degC */
55#define HTS221_TEMP_AVG_32 0x20 /* 0.02 degC */
56#define HTS221_TEMP_AVG_64 0x28 /* 0.015 degC */
57#define HTS221_TEMP_AVG_128 0x30 /* 0.01 degC */
58#define HTS221_TEMP_AVG_256 0x38 /* 0.007 degC */
59 37
60/* calibration registers */ 38/* calibration registers */
61#define HTS221_REG_0RH_CAL_X_H 0x36 39#define HTS221_REG_0RH_CAL_X_H 0x36
@@ -73,10 +51,11 @@ struct hts221_odr {
73 u8 val; 51 u8 val;
74}; 52};
75 53
54#define HTS221_AVG_DEPTH 8
76struct hts221_avg { 55struct hts221_avg {
77 u8 addr; 56 u8 addr;
78 u8 mask; 57 u8 mask;
79 struct hts221_avg_avl avg_avl[HTS221_AVG_DEPTH]; 58 u16 avg_avl[HTS221_AVG_DEPTH];
80}; 59};
81 60
82static const struct hts221_odr hts221_odr_table[] = { 61static const struct hts221_odr hts221_odr_table[] = {
@@ -90,28 +69,28 @@ static const struct hts221_avg hts221_avg_list[] = {
90 .addr = HTS221_REG_AVG_ADDR, 69 .addr = HTS221_REG_AVG_ADDR,
91 .mask = HTS221_HUMIDITY_AVG_MASK, 70 .mask = HTS221_HUMIDITY_AVG_MASK,
92 .avg_avl = { 71 .avg_avl = {
93 { 4, HTS221_HUMIDITY_AVG_4 }, 72 4, /* 0.4 %RH */
94 { 8, HTS221_HUMIDITY_AVG_8 }, 73 8, /* 0.3 %RH */
95 { 16, HTS221_HUMIDITY_AVG_16 }, 74 16, /* 0.2 %RH */
96 { 32, HTS221_HUMIDITY_AVG_32 }, 75 32, /* 0.15 %RH */
97 { 64, HTS221_HUMIDITY_AVG_64 }, 76 64, /* 0.1 %RH */
98 { 128, HTS221_HUMIDITY_AVG_128 }, 77 128, /* 0.07 %RH */
99 { 256, HTS221_HUMIDITY_AVG_256 }, 78 256, /* 0.05 %RH */
100 { 512, HTS221_HUMIDITY_AVG_512 }, 79 512, /* 0.03 %RH */
101 }, 80 },
102 }, 81 },
103 { 82 {
104 .addr = HTS221_REG_AVG_ADDR, 83 .addr = HTS221_REG_AVG_ADDR,
105 .mask = HTS221_TEMP_AVG_MASK, 84 .mask = HTS221_TEMP_AVG_MASK,
106 .avg_avl = { 85 .avg_avl = {
107 { 2, HTS221_TEMP_AVG_2 }, 86 2, /* 0.08 degC */
108 { 4, HTS221_TEMP_AVG_4 }, 87 4, /* 0.05 degC */
109 { 8, HTS221_TEMP_AVG_8 }, 88 8, /* 0.04 degC */
110 { 16, HTS221_TEMP_AVG_16 }, 89 16, /* 0.03 degC */
111 { 32, HTS221_TEMP_AVG_32 }, 90 32, /* 0.02 degC */
112 { 64, HTS221_TEMP_AVG_64 }, 91 64, /* 0.015 degC */
113 { 128, HTS221_TEMP_AVG_128 }, 92 128, /* 0.01 degC */
114 { 256, HTS221_TEMP_AVG_256 }, 93 256, /* 0.007 degC */
115 }, 94 },
116 }, 95 },
117}; 96};
@@ -152,8 +131,7 @@ static const struct iio_chan_spec hts221_channels[] = {
152 IIO_CHAN_SOFT_TIMESTAMP(2), 131 IIO_CHAN_SOFT_TIMESTAMP(2),
153}; 132};
154 133
155static int hts221_write_with_mask(struct hts221_hw *hw, u8 addr, u8 mask, 134int hts221_write_with_mask(struct hts221_hw *hw, u8 addr, u8 mask, u8 val)
156 u8 val)
157{ 135{
158 u8 data; 136 u8 data;
159 int err; 137 int err;
@@ -166,7 +144,7 @@ static int hts221_write_with_mask(struct hts221_hw *hw, u8 addr, u8 mask,
166 goto unlock; 144 goto unlock;
167 } 145 }
168 146
169 data = (data & ~mask) | (val & mask); 147 data = (data & ~mask) | ((val << __ffs(mask)) & mask);
170 148
171 err = hw->tf->write(hw->dev, addr, sizeof(data), &data); 149 err = hw->tf->write(hw->dev, addr, sizeof(data), &data);
172 if (err < 0) 150 if (err < 0)
@@ -199,21 +177,9 @@ static int hts221_check_whoami(struct hts221_hw *hw)
199 return 0; 177 return 0;
200} 178}
201 179
202int hts221_config_drdy(struct hts221_hw *hw, bool enable)
203{
204 u8 val = enable ? BIT(2) : 0;
205 int err;
206
207 err = hts221_write_with_mask(hw, HTS221_REG_CNTRL3_ADDR,
208 HTS221_DRDY_MASK, val);
209
210 return err < 0 ? err : 0;
211}
212
213static int hts221_update_odr(struct hts221_hw *hw, u8 odr) 180static int hts221_update_odr(struct hts221_hw *hw, u8 odr)
214{ 181{
215 int i, err; 182 int i, err;
216 u8 val;
217 183
218 for (i = 0; i < ARRAY_SIZE(hts221_odr_table); i++) 184 for (i = 0; i < ARRAY_SIZE(hts221_odr_table); i++)
219 if (hts221_odr_table[i].hz == odr) 185 if (hts221_odr_table[i].hz == odr)
@@ -222,9 +188,8 @@ static int hts221_update_odr(struct hts221_hw *hw, u8 odr)
222 if (i == ARRAY_SIZE(hts221_odr_table)) 188 if (i == ARRAY_SIZE(hts221_odr_table))
223 return -EINVAL; 189 return -EINVAL;
224 190
225 val = HTS221_ENABLE_SENSOR | HTS221_BDU_MASK | hts221_odr_table[i].val;
226 err = hts221_write_with_mask(hw, HTS221_REG_CNTRL1_ADDR, 191 err = hts221_write_with_mask(hw, HTS221_REG_CNTRL1_ADDR,
227 HTS221_ODR_MASK, val); 192 HTS221_ODR_MASK, hts221_odr_table[i].val);
228 if (err < 0) 193 if (err < 0)
229 return err; 194 return err;
230 195
@@ -241,14 +206,13 @@ static int hts221_update_avg(struct hts221_hw *hw,
241 const struct hts221_avg *avg = &hts221_avg_list[type]; 206 const struct hts221_avg *avg = &hts221_avg_list[type];
242 207
243 for (i = 0; i < HTS221_AVG_DEPTH; i++) 208 for (i = 0; i < HTS221_AVG_DEPTH; i++)
244 if (avg->avg_avl[i].avg == val) 209 if (avg->avg_avl[i] == val)
245 break; 210 break;
246 211
247 if (i == HTS221_AVG_DEPTH) 212 if (i == HTS221_AVG_DEPTH)
248 return -EINVAL; 213 return -EINVAL;
249 214
250 err = hts221_write_with_mask(hw, avg->addr, avg->mask, 215 err = hts221_write_with_mask(hw, avg->addr, avg->mask, i);
251 avg->avg_avl[i].val);
252 if (err < 0) 216 if (err < 0)
253 return err; 217 return err;
254 218
@@ -283,7 +247,7 @@ hts221_sysfs_rh_oversampling_avail(struct device *dev,
283 247
284 for (i = 0; i < ARRAY_SIZE(avg->avg_avl); i++) 248 for (i = 0; i < ARRAY_SIZE(avg->avg_avl); i++)
285 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", 249 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
286 avg->avg_avl[i].avg); 250 avg->avg_avl[i]);
287 buf[len - 1] = '\n'; 251 buf[len - 1] = '\n';
288 252
289 return len; 253 return len;
@@ -300,36 +264,22 @@ hts221_sysfs_temp_oversampling_avail(struct device *dev,
300 264
301 for (i = 0; i < ARRAY_SIZE(avg->avg_avl); i++) 265 for (i = 0; i < ARRAY_SIZE(avg->avg_avl); i++)
302 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", 266 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
303 avg->avg_avl[i].avg); 267 avg->avg_avl[i]);
304 buf[len - 1] = '\n'; 268 buf[len - 1] = '\n';
305 269
306 return len; 270 return len;
307} 271}
308 272
309int hts221_power_on(struct hts221_hw *hw) 273int hts221_set_enable(struct hts221_hw *hw, bool enable)
310{
311 int err;
312
313 err = hts221_update_odr(hw, hw->odr);
314 if (err < 0)
315 return err;
316
317 hw->enabled = true;
318
319 return 0;
320}
321
322int hts221_power_off(struct hts221_hw *hw)
323{ 274{
324 __le16 data = 0;
325 int err; 275 int err;
326 276
327 err = hw->tf->write(hw->dev, HTS221_REG_CNTRL1_ADDR, sizeof(data), 277 err = hts221_write_with_mask(hw, HTS221_REG_CNTRL1_ADDR,
328 (u8 *)&data); 278 HTS221_ENABLE_MASK, enable);
329 if (err < 0) 279 if (err < 0)
330 return err; 280 return err;
331 281
332 hw->enabled = false; 282 hw->enabled = enable;
333 283
334 return 0; 284 return 0;
335} 285}
@@ -484,7 +434,7 @@ static int hts221_read_oneshot(struct hts221_hw *hw, u8 addr, int *val)
484 u8 data[HTS221_DATA_SIZE]; 434 u8 data[HTS221_DATA_SIZE];
485 int err; 435 int err;
486 436
487 err = hts221_power_on(hw); 437 err = hts221_set_enable(hw, true);
488 if (err < 0) 438 if (err < 0)
489 return err; 439 return err;
490 440
@@ -494,7 +444,7 @@ static int hts221_read_oneshot(struct hts221_hw *hw, u8 addr, int *val)
494 if (err < 0) 444 if (err < 0)
495 return err; 445 return err;
496 446
497 hts221_power_off(hw); 447 hts221_set_enable(hw, false);
498 448
499 *val = (s16)get_unaligned_le16(data); 449 *val = (s16)get_unaligned_le16(data);
500 450
@@ -534,13 +484,13 @@ static int hts221_read_raw(struct iio_dev *iio_dev,
534 case IIO_HUMIDITYRELATIVE: 484 case IIO_HUMIDITYRELATIVE:
535 avg = &hts221_avg_list[HTS221_SENSOR_H]; 485 avg = &hts221_avg_list[HTS221_SENSOR_H];
536 idx = hw->sensors[HTS221_SENSOR_H].cur_avg_idx; 486 idx = hw->sensors[HTS221_SENSOR_H].cur_avg_idx;
537 *val = avg->avg_avl[idx].avg; 487 *val = avg->avg_avl[idx];
538 ret = IIO_VAL_INT; 488 ret = IIO_VAL_INT;
539 break; 489 break;
540 case IIO_TEMP: 490 case IIO_TEMP:
541 avg = &hts221_avg_list[HTS221_SENSOR_T]; 491 avg = &hts221_avg_list[HTS221_SENSOR_T];
542 idx = hw->sensors[HTS221_SENSOR_T].cur_avg_idx; 492 idx = hw->sensors[HTS221_SENSOR_T].cur_avg_idx;
543 *val = avg->avg_avl[idx].avg; 493 *val = avg->avg_avl[idx];
544 ret = IIO_VAL_INT; 494 ret = IIO_VAL_INT;
545 break; 495 break;
546 default: 496 default:
@@ -644,8 +594,6 @@ int hts221_probe(struct iio_dev *iio_dev)
644 if (err < 0) 594 if (err < 0)
645 return err; 595 return err;
646 596
647 hw->odr = hts221_odr_table[0].hz;
648
649 iio_dev->modes = INDIO_DIRECT_MODE; 597 iio_dev->modes = INDIO_DIRECT_MODE;
650 iio_dev->dev.parent = hw->dev; 598 iio_dev->dev.parent = hw->dev;
651 iio_dev->available_scan_masks = hts221_scan_masks; 599 iio_dev->available_scan_masks = hts221_scan_masks;
@@ -654,6 +602,16 @@ int hts221_probe(struct iio_dev *iio_dev)
654 iio_dev->name = HTS221_DEV_NAME; 602 iio_dev->name = HTS221_DEV_NAME;
655 iio_dev->info = &hts221_info; 603 iio_dev->info = &hts221_info;
656 604
605 /* enable Block Data Update */
606 err = hts221_write_with_mask(hw, HTS221_REG_CNTRL1_ADDR,
607 HTS221_BDU_MASK, 1);
608 if (err < 0)
609 return err;
610
611 err = hts221_update_odr(hw, hts221_odr_table[0].hz);
612 if (err < 0)
613 return err;
614
657 /* configure humidity sensor */ 615 /* configure humidity sensor */
658 err = hts221_parse_rh_caldata(hw); 616 err = hts221_parse_rh_caldata(hw);
659 if (err < 0) { 617 if (err < 0) {
@@ -661,7 +619,7 @@ int hts221_probe(struct iio_dev *iio_dev)
661 return err; 619 return err;
662 } 620 }
663 621
664 data = hts221_avg_list[HTS221_SENSOR_H].avg_avl[3].avg; 622 data = hts221_avg_list[HTS221_SENSOR_H].avg_avl[3];
665 err = hts221_update_avg(hw, HTS221_SENSOR_H, data); 623 err = hts221_update_avg(hw, HTS221_SENSOR_H, data);
666 if (err < 0) { 624 if (err < 0) {
667 dev_err(hw->dev, "failed to set rh oversampling ratio\n"); 625 dev_err(hw->dev, "failed to set rh oversampling ratio\n");
@@ -676,7 +634,7 @@ int hts221_probe(struct iio_dev *iio_dev)
676 return err; 634 return err;
677 } 635 }
678 636
679 data = hts221_avg_list[HTS221_SENSOR_T].avg_avl[3].avg; 637 data = hts221_avg_list[HTS221_SENSOR_T].avg_avl[3];
680 err = hts221_update_avg(hw, HTS221_SENSOR_T, data); 638 err = hts221_update_avg(hw, HTS221_SENSOR_T, data);
681 if (err < 0) { 639 if (err < 0) {
682 dev_err(hw->dev, 640 dev_err(hw->dev,
@@ -702,11 +660,10 @@ static int __maybe_unused hts221_suspend(struct device *dev)
702{ 660{
703 struct iio_dev *iio_dev = dev_get_drvdata(dev); 661 struct iio_dev *iio_dev = dev_get_drvdata(dev);
704 struct hts221_hw *hw = iio_priv(iio_dev); 662 struct hts221_hw *hw = iio_priv(iio_dev);
705 __le16 data = 0;
706 int err; 663 int err;
707 664
708 err = hw->tf->write(hw->dev, HTS221_REG_CNTRL1_ADDR, sizeof(data), 665 err = hts221_write_with_mask(hw, HTS221_REG_CNTRL1_ADDR,
709 (u8 *)&data); 666 HTS221_ENABLE_MASK, false);
710 667
711 return err < 0 ? err : 0; 668 return err < 0 ? err : 0;
712} 669}
@@ -718,7 +675,8 @@ static int __maybe_unused hts221_resume(struct device *dev)
718 int err = 0; 675 int err = 0;
719 676
720 if (hw->enabled) 677 if (hw->enabled)
721 err = hts221_update_odr(hw, hw->odr); 678 err = hts221_write_with_mask(hw, HTS221_REG_CNTRL1_ADDR,
679 HTS221_ENABLE_MASK, true);
722 680
723 return err; 681 return err;
724} 682}
diff --git a/drivers/iio/humidity/htu21.c b/drivers/iio/humidity/htu21.c
index 0fbbd8c40894..2c4b9be85a05 100644
--- a/drivers/iio/humidity/htu21.c
+++ b/drivers/iio/humidity/htu21.c
@@ -238,11 +238,19 @@ static const struct i2c_device_id htu21_id[] = {
238}; 238};
239MODULE_DEVICE_TABLE(i2c, htu21_id); 239MODULE_DEVICE_TABLE(i2c, htu21_id);
240 240
241static const struct of_device_id htu21_of_match[] = {
242 { .compatible = "meas,htu21", },
243 { .compatible = "meas,ms8607-humidity", },
244 { },
245};
246MODULE_DEVICE_TABLE(of, htu21_of_match);
247
241static struct i2c_driver htu21_driver = { 248static struct i2c_driver htu21_driver = {
242 .probe = htu21_probe, 249 .probe = htu21_probe,
243 .id_table = htu21_id, 250 .id_table = htu21_id,
244 .driver = { 251 .driver = {
245 .name = "htu21", 252 .name = "htu21",
253 .of_match_table = of_match_ptr(htu21_of_match),
246 }, 254 },
247}; 255};
248 256
diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
index fb7c0dbed51c..9b697d35dbef 100644
--- a/drivers/iio/imu/adis16400_core.c
+++ b/drivers/iio/imu/adis16400_core.c
@@ -217,7 +217,7 @@ static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq)
217 return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, val); 217 return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, val);
218} 218}
219 219
220static const unsigned adis16400_3db_divisors[] = { 220static const unsigned int adis16400_3db_divisors[] = {
221 [0] = 2, /* Special case */ 221 [0] = 2, /* Special case */
222 [1] = 6, 222 [1] = 6,
223 [2] = 12, 223 [2] = 12,
@@ -890,7 +890,7 @@ static const struct adis_data adis16400_data = {
890static void adis16400_setup_chan_mask(struct adis16400_state *st) 890static void adis16400_setup_chan_mask(struct adis16400_state *st)
891{ 891{
892 const struct adis16400_chip_info *chip_info = st->variant; 892 const struct adis16400_chip_info *chip_info = st->variant;
893 unsigned i; 893 unsigned int i;
894 894
895 for (i = 0; i < chip_info->num_channels; i++) { 895 for (i = 0; i < chip_info->num_channels; i++) {
896 const struct iio_chan_spec *ch = &chip_info->channels[i]; 896 const struct iio_chan_spec *ch = &chip_info->channels[i];
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
index 2a72acc6e049..e2737dc71b67 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
@@ -31,6 +31,8 @@
31#include <linux/iio/iio.h> 31#include <linux/iio/iio.h>
32#include <linux/iio/buffer.h> 32#include <linux/iio/buffer.h>
33 33
34#include <linux/platform_data/st_sensors_pdata.h>
35
34#include "st_lsm6dsx.h" 36#include "st_lsm6dsx.h"
35 37
36#define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06 38#define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06
@@ -39,6 +41,8 @@
39#define ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR 0x08 41#define ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR 0x08
40#define ST_LSM6DSX_REG_HLACTIVE_ADDR 0x12 42#define ST_LSM6DSX_REG_HLACTIVE_ADDR 0x12
41#define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5) 43#define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5)
44#define ST_LSM6DSX_REG_PP_OD_ADDR 0x12
45#define ST_LSM6DSX_REG_PP_OD_MASK BIT(4)
42#define ST_LSM6DSX_REG_FIFO_MODE_ADDR 0x0a 46#define ST_LSM6DSX_REG_FIFO_MODE_ADDR 0x0a
43#define ST_LSM6DSX_FIFO_MODE_MASK GENMASK(2, 0) 47#define ST_LSM6DSX_FIFO_MODE_MASK GENMASK(2, 0)
44#define ST_LSM6DSX_FIFO_ODR_MASK GENMASK(6, 3) 48#define ST_LSM6DSX_FIFO_ODR_MASK GENMASK(6, 3)
@@ -417,6 +421,8 @@ static const struct iio_buffer_setup_ops st_lsm6dsx_buffer_ops = {
417 421
418int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw) 422int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw)
419{ 423{
424 struct device_node *np = hw->dev->of_node;
425 struct st_sensors_platform_data *pdata;
420 struct iio_buffer *buffer; 426 struct iio_buffer *buffer;
421 unsigned long irq_type; 427 unsigned long irq_type;
422 bool irq_active_low; 428 bool irq_active_low;
@@ -444,6 +450,17 @@ int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw)
444 if (err < 0) 450 if (err < 0)
445 return err; 451 return err;
446 452
453 pdata = (struct st_sensors_platform_data *)hw->dev->platform_data;
454 if ((np && of_property_read_bool(np, "drive-open-drain")) ||
455 (pdata && pdata->open_drain)) {
456 err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_PP_OD_ADDR,
457 ST_LSM6DSX_REG_PP_OD_MASK, 1);
458 if (err < 0)
459 return err;
460
461 irq_type |= IRQF_SHARED;
462 }
463
447 err = devm_request_threaded_irq(hw->dev, hw->irq, 464 err = devm_request_threaded_irq(hw->dev, hw->irq,
448 st_lsm6dsx_handler_irq, 465 st_lsm6dsx_handler_irq,
449 st_lsm6dsx_handler_thread, 466 st_lsm6dsx_handler_thread,
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index da3d06b073bb..069defcc6d9b 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -44,7 +44,7 @@ int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps)
44 } 44 }
45 mapi->map = &maps[i]; 45 mapi->map = &maps[i];
46 mapi->indio_dev = indio_dev; 46 mapi->indio_dev = indio_dev;
47 list_add(&mapi->l, &iio_map_list); 47 list_add_tail(&mapi->l, &iio_map_list);
48 i++; 48 i++;
49 } 49 }
50error_ret: 50error_ret:
@@ -205,8 +205,8 @@ static struct iio_channel *of_iio_channel_get_by_name(struct device_node *np,
205 if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER) 205 if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER)
206 break; 206 break;
207 else if (name && index >= 0) { 207 else if (name && index >= 0) {
208 pr_err("ERROR: could not get IIO channel %s:%s(%i)\n", 208 pr_err("ERROR: could not get IIO channel %pOF:%s(%i)\n",
209 np->full_name, name ? name : "", index); 209 np, name ? name : "", index);
210 return NULL; 210 return NULL;
211 } 211 }
212 212
diff --git a/drivers/iio/light/rpr0521.c b/drivers/iio/light/rpr0521.c
index 9d0c2e859bb2..a6efa12613a2 100644
--- a/drivers/iio/light/rpr0521.c
+++ b/drivers/iio/light/rpr0521.c
@@ -9,7 +9,7 @@
9 * 9 *
10 * IIO driver for RPR-0521RS (7-bit I2C slave address 0x38). 10 * IIO driver for RPR-0521RS (7-bit I2C slave address 0x38).
11 * 11 *
12 * TODO: illuminance channel, buffer 12 * TODO: illuminance channel
13 */ 13 */
14 14
15#include <linux/module.h> 15#include <linux/module.h>
@@ -20,6 +20,10 @@
20#include <linux/acpi.h> 20#include <linux/acpi.h>
21 21
22#include <linux/iio/iio.h> 22#include <linux/iio/iio.h>
23#include <linux/iio/buffer.h>
24#include <linux/iio/trigger.h>
25#include <linux/iio/trigger_consumer.h>
26#include <linux/iio/triggered_buffer.h>
23#include <linux/iio/sysfs.h> 27#include <linux/iio/sysfs.h>
24#include <linux/pm_runtime.h> 28#include <linux/pm_runtime.h>
25 29
@@ -30,6 +34,7 @@
30#define RPR0521_REG_PXS_DATA 0x44 /* 16-bit, little endian */ 34#define RPR0521_REG_PXS_DATA 0x44 /* 16-bit, little endian */
31#define RPR0521_REG_ALS_DATA0 0x46 /* 16-bit, little endian */ 35#define RPR0521_REG_ALS_DATA0 0x46 /* 16-bit, little endian */
32#define RPR0521_REG_ALS_DATA1 0x48 /* 16-bit, little endian */ 36#define RPR0521_REG_ALS_DATA1 0x48 /* 16-bit, little endian */
37#define RPR0521_REG_INTERRUPT 0x4A
33#define RPR0521_REG_PS_OFFSET_LSB 0x53 38#define RPR0521_REG_PS_OFFSET_LSB 0x53
34#define RPR0521_REG_ID 0x92 39#define RPR0521_REG_ID 0x92
35 40
@@ -42,16 +47,31 @@
42#define RPR0521_ALS_DATA1_GAIN_SHIFT 2 47#define RPR0521_ALS_DATA1_GAIN_SHIFT 2
43#define RPR0521_PXS_GAIN_MASK GENMASK(5, 4) 48#define RPR0521_PXS_GAIN_MASK GENMASK(5, 4)
44#define RPR0521_PXS_GAIN_SHIFT 4 49#define RPR0521_PXS_GAIN_SHIFT 4
50#define RPR0521_PXS_PERSISTENCE_MASK GENMASK(3, 0)
51#define RPR0521_INTERRUPT_INT_TRIG_PS_MASK BIT(0)
52#define RPR0521_INTERRUPT_INT_TRIG_ALS_MASK BIT(1)
53#define RPR0521_INTERRUPT_INT_REASSERT_MASK BIT(3)
54#define RPR0521_INTERRUPT_ALS_INT_STATUS_MASK BIT(6)
55#define RPR0521_INTERRUPT_PS_INT_STATUS_MASK BIT(7)
45 56
46#define RPR0521_MODE_ALS_ENABLE BIT(7) 57#define RPR0521_MODE_ALS_ENABLE BIT(7)
47#define RPR0521_MODE_ALS_DISABLE 0x00 58#define RPR0521_MODE_ALS_DISABLE 0x00
48#define RPR0521_MODE_PXS_ENABLE BIT(6) 59#define RPR0521_MODE_PXS_ENABLE BIT(6)
49#define RPR0521_MODE_PXS_DISABLE 0x00 60#define RPR0521_MODE_PXS_DISABLE 0x00
61#define RPR0521_PXS_PERSISTENCE_DRDY 0x00
62
63#define RPR0521_INTERRUPT_INT_TRIG_PS_ENABLE BIT(0)
64#define RPR0521_INTERRUPT_INT_TRIG_PS_DISABLE 0x00
65#define RPR0521_INTERRUPT_INT_TRIG_ALS_ENABLE BIT(1)
66#define RPR0521_INTERRUPT_INT_TRIG_ALS_DISABLE 0x00
67#define RPR0521_INTERRUPT_INT_REASSERT_ENABLE BIT(3)
68#define RPR0521_INTERRUPT_INT_REASSERT_DISABLE 0x00
50 69
51#define RPR0521_MANUFACT_ID 0xE0 70#define RPR0521_MANUFACT_ID 0xE0
52#define RPR0521_DEFAULT_MEAS_TIME 0x06 /* ALS - 100ms, PXS - 100ms */ 71#define RPR0521_DEFAULT_MEAS_TIME 0x06 /* ALS - 100ms, PXS - 100ms */
53 72
54#define RPR0521_DRV_NAME "RPR0521" 73#define RPR0521_DRV_NAME "RPR0521"
74#define RPR0521_IRQ_NAME "rpr0521_event"
55#define RPR0521_REGMAP_NAME "rpr0521_regmap" 75#define RPR0521_REGMAP_NAME "rpr0521_regmap"
56 76
57#define RPR0521_SLEEP_DELAY_MS 2000 77#define RPR0521_SLEEP_DELAY_MS 2000
@@ -167,6 +187,9 @@ struct rpr0521_data {
167 bool als_dev_en; 187 bool als_dev_en;
168 bool pxs_dev_en; 188 bool pxs_dev_en;
169 189
190 struct iio_trigger *drdy_trigger0;
191 s64 irq_timestamp;
192
170 /* optimize runtime pm ops - enable/disable device only if needed */ 193 /* optimize runtime pm ops - enable/disable device only if needed */
171 bool als_ps_need_en; 194 bool als_ps_need_en;
172 bool pxs_ps_need_en; 195 bool pxs_ps_need_en;
@@ -196,6 +219,19 @@ static const struct attribute_group rpr0521_attribute_group = {
196 .attrs = rpr0521_attributes, 219 .attrs = rpr0521_attributes,
197}; 220};
198 221
222/* Order of the channel data in buffer */
223enum rpr0521_scan_index_order {
224 RPR0521_CHAN_INDEX_PXS,
225 RPR0521_CHAN_INDEX_BOTH,
226 RPR0521_CHAN_INDEX_IR,
227};
228
229static const unsigned long rpr0521_available_scan_masks[] = {
230 BIT(RPR0521_CHAN_INDEX_PXS) | BIT(RPR0521_CHAN_INDEX_BOTH) |
231 BIT(RPR0521_CHAN_INDEX_IR),
232 0
233};
234
199static const struct iio_chan_spec rpr0521_channels[] = { 235static const struct iio_chan_spec rpr0521_channels[] = {
200 { 236 {
201 .type = IIO_PROXIMITY, 237 .type = IIO_PROXIMITY,
@@ -204,6 +240,13 @@ static const struct iio_chan_spec rpr0521_channels[] = {
204 BIT(IIO_CHAN_INFO_OFFSET) | 240 BIT(IIO_CHAN_INFO_OFFSET) |
205 BIT(IIO_CHAN_INFO_SCALE), 241 BIT(IIO_CHAN_INFO_SCALE),
206 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 242 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
243 .scan_index = RPR0521_CHAN_INDEX_PXS,
244 .scan_type = {
245 .sign = 'u',
246 .realbits = 16,
247 .storagebits = 16,
248 .endianness = IIO_LE,
249 },
207 }, 250 },
208 { 251 {
209 .type = IIO_INTENSITY, 252 .type = IIO_INTENSITY,
@@ -213,6 +256,13 @@ static const struct iio_chan_spec rpr0521_channels[] = {
213 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 256 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
214 BIT(IIO_CHAN_INFO_SCALE), 257 BIT(IIO_CHAN_INFO_SCALE),
215 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 258 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
259 .scan_index = RPR0521_CHAN_INDEX_BOTH,
260 .scan_type = {
261 .sign = 'u',
262 .realbits = 16,
263 .storagebits = 16,
264 .endianness = IIO_LE,
265 },
216 }, 266 },
217 { 267 {
218 .type = IIO_INTENSITY, 268 .type = IIO_INTENSITY,
@@ -222,6 +272,13 @@ static const struct iio_chan_spec rpr0521_channels[] = {
222 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 272 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
223 BIT(IIO_CHAN_INFO_SCALE), 273 BIT(IIO_CHAN_INFO_SCALE),
224 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 274 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
275 .scan_index = RPR0521_CHAN_INDEX_IR,
276 .scan_type = {
277 .sign = 'u',
278 .realbits = 16,
279 .storagebits = 16,
280 .endianness = IIO_LE,
281 },
225 }, 282 },
226}; 283};
227 284
@@ -330,6 +387,198 @@ static int rpr0521_set_power_state(struct rpr0521_data *data, bool on,
330 return 0; 387 return 0;
331} 388}
332 389
390/* Interrupt register tells if this sensor caused the interrupt or not. */
391static inline bool rpr0521_is_triggered(struct rpr0521_data *data)
392{
393 int ret;
394 int reg;
395
396 ret = regmap_read(data->regmap, RPR0521_REG_INTERRUPT, &reg);
397 if (ret < 0)
398 return false; /* Reg read failed. */
399 if (reg &
400 (RPR0521_INTERRUPT_ALS_INT_STATUS_MASK |
401 RPR0521_INTERRUPT_PS_INT_STATUS_MASK))
402 return true;
403 else
404 return false; /* Int not from this sensor. */
405}
406
407/* IRQ to trigger handler */
408static irqreturn_t rpr0521_drdy_irq_handler(int irq, void *private)
409{
410 struct iio_dev *indio_dev = private;
411 struct rpr0521_data *data = iio_priv(indio_dev);
412
413 data->irq_timestamp = iio_get_time_ns(indio_dev);
414 /*
415 * We need to wake the thread to read the interrupt reg. It
416 * is not possible to do that here because regmap_read takes a
417 * mutex.
418 */
419
420 return IRQ_WAKE_THREAD;
421}
422
423static irqreturn_t rpr0521_drdy_irq_thread(int irq, void *private)
424{
425 struct iio_dev *indio_dev = private;
426 struct rpr0521_data *data = iio_priv(indio_dev);
427
428 if (rpr0521_is_triggered(data)) {
429 iio_trigger_poll_chained(data->drdy_trigger0);
430 return IRQ_HANDLED;
431 }
432
433 return IRQ_NONE;
434}
435
436static irqreturn_t rpr0521_trigger_consumer_store_time(int irq, void *p)
437{
438 struct iio_poll_func *pf = p;
439 struct iio_dev *indio_dev = pf->indio_dev;
440
441 /* Other trigger polls store time here. */
442 if (!iio_trigger_using_own(indio_dev))
443 pf->timestamp = iio_get_time_ns(indio_dev);
444
445 return IRQ_WAKE_THREAD;
446}
447
448static irqreturn_t rpr0521_trigger_consumer_handler(int irq, void *p)
449{
450 struct iio_poll_func *pf = p;
451 struct iio_dev *indio_dev = pf->indio_dev;
452 struct rpr0521_data *data = iio_priv(indio_dev);
453 int err;
454
455 u8 buffer[16]; /* 3 16-bit channels + padding + ts */
456
457 /* Use irq timestamp when reasonable. */
458 if (iio_trigger_using_own(indio_dev) && data->irq_timestamp) {
459 pf->timestamp = data->irq_timestamp;
460 data->irq_timestamp = 0;
461 }
462 /* Other chained trigger polls get timestamp only here. */
463 if (!pf->timestamp)
464 pf->timestamp = iio_get_time_ns(indio_dev);
465
466 err = regmap_bulk_read(data->regmap, RPR0521_REG_PXS_DATA,
467 &buffer,
468 (3 * 2) + 1); /* 3 * 16-bit + (discarded) int clear reg. */
469 if (!err)
470 iio_push_to_buffers_with_timestamp(indio_dev,
471 buffer, pf->timestamp);
472 else
473 dev_err(&data->client->dev,
474 "Trigger consumer can't read from sensor.\n");
475 pf->timestamp = 0;
476
477 iio_trigger_notify_done(indio_dev->trig);
478
479 return IRQ_HANDLED;
480}
481
482static int rpr0521_write_int_enable(struct rpr0521_data *data)
483{
484 int err;
485
486 /* Interrupt after each measurement */
487 err = regmap_update_bits(data->regmap, RPR0521_REG_PXS_CTRL,
488 RPR0521_PXS_PERSISTENCE_MASK,
489 RPR0521_PXS_PERSISTENCE_DRDY);
490 if (err) {
491 dev_err(&data->client->dev, "PS control reg write fail.\n");
492 return -EBUSY;
493 }
494
495 /* Ignore latch and mode because of drdy */
496 err = regmap_write(data->regmap, RPR0521_REG_INTERRUPT,
497 RPR0521_INTERRUPT_INT_REASSERT_DISABLE |
498 RPR0521_INTERRUPT_INT_TRIG_ALS_DISABLE |
499 RPR0521_INTERRUPT_INT_TRIG_PS_ENABLE
500 );
501 if (err) {
502 dev_err(&data->client->dev, "Interrupt setup write fail.\n");
503 return -EBUSY;
504 }
505
506 return 0;
507}
508
509static int rpr0521_write_int_disable(struct rpr0521_data *data)
510{
511 /* Don't care of clearing mode, assert and latch. */
512 return regmap_write(data->regmap, RPR0521_REG_INTERRUPT,
513 RPR0521_INTERRUPT_INT_TRIG_ALS_DISABLE |
514 RPR0521_INTERRUPT_INT_TRIG_PS_DISABLE
515 );
516}
517
518/*
519 * Trigger producer enable / disable. Note that there will be trigs only when
520 * measurement data is ready to be read.
521 */
522static int rpr0521_pxs_drdy_set_state(struct iio_trigger *trigger,
523 bool enable_drdy)
524{
525 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trigger);
526 struct rpr0521_data *data = iio_priv(indio_dev);
527 int err;
528
529 if (enable_drdy)
530 err = rpr0521_write_int_enable(data);
531 else
532 err = rpr0521_write_int_disable(data);
533 if (err)
534 dev_err(&data->client->dev, "rpr0521_pxs_drdy_set_state failed\n");
535
536 return err;
537}
538
539static const struct iio_trigger_ops rpr0521_trigger_ops = {
540 .set_trigger_state = rpr0521_pxs_drdy_set_state,
541 .owner = THIS_MODULE,
542 };
543
544
545static int rpr0521_buffer_preenable(struct iio_dev *indio_dev)
546{
547 int err;
548 struct rpr0521_data *data = iio_priv(indio_dev);
549
550 mutex_lock(&data->lock);
551 err = rpr0521_set_power_state(data, true,
552 (RPR0521_MODE_PXS_MASK | RPR0521_MODE_ALS_MASK));
553 mutex_unlock(&data->lock);
554 if (err)
555 dev_err(&data->client->dev, "_buffer_preenable fail\n");
556
557 return err;
558}
559
560static int rpr0521_buffer_postdisable(struct iio_dev *indio_dev)
561{
562 int err;
563 struct rpr0521_data *data = iio_priv(indio_dev);
564
565 mutex_lock(&data->lock);
566 err = rpr0521_set_power_state(data, false,
567 (RPR0521_MODE_PXS_MASK | RPR0521_MODE_ALS_MASK));
568 mutex_unlock(&data->lock);
569 if (err)
570 dev_err(&data->client->dev, "_buffer_postdisable fail\n");
571
572 return err;
573}
574
575static const struct iio_buffer_setup_ops rpr0521_buffer_setup_ops = {
576 .preenable = rpr0521_buffer_preenable,
577 .postenable = iio_triggered_buffer_postenable,
578 .predisable = iio_triggered_buffer_predisable,
579 .postdisable = rpr0521_buffer_postdisable,
580};
581
333static int rpr0521_get_gain(struct rpr0521_data *data, int chan, 582static int rpr0521_get_gain(struct rpr0521_data *data, int chan,
334 int *val, int *val2) 583 int *val, int *val2)
335{ 584{
@@ -473,6 +722,7 @@ static int rpr0521_read_raw(struct iio_dev *indio_dev,
473{ 722{
474 struct rpr0521_data *data = iio_priv(indio_dev); 723 struct rpr0521_data *data = iio_priv(indio_dev);
475 int ret; 724 int ret;
725 int busy;
476 u8 device_mask; 726 u8 device_mask;
477 __le16 raw_data; 727 __le16 raw_data;
478 728
@@ -481,26 +731,30 @@ static int rpr0521_read_raw(struct iio_dev *indio_dev,
481 if (chan->type != IIO_INTENSITY && chan->type != IIO_PROXIMITY) 731 if (chan->type != IIO_INTENSITY && chan->type != IIO_PROXIMITY)
482 return -EINVAL; 732 return -EINVAL;
483 733
734 busy = iio_device_claim_direct_mode(indio_dev);
735 if (busy)
736 return -EBUSY;
737
484 device_mask = rpr0521_data_reg[chan->address].device_mask; 738 device_mask = rpr0521_data_reg[chan->address].device_mask;
485 739
486 mutex_lock(&data->lock); 740 mutex_lock(&data->lock);
487 ret = rpr0521_set_power_state(data, true, device_mask); 741 ret = rpr0521_set_power_state(data, true, device_mask);
488 if (ret < 0) { 742 if (ret < 0)
489 mutex_unlock(&data->lock); 743 goto rpr0521_read_raw_out;
490 return ret;
491 }
492 744
493 ret = regmap_bulk_read(data->regmap, 745 ret = regmap_bulk_read(data->regmap,
494 rpr0521_data_reg[chan->address].address, 746 rpr0521_data_reg[chan->address].address,
495 &raw_data, sizeof(raw_data)); 747 &raw_data, sizeof(raw_data));
496 if (ret < 0) { 748 if (ret < 0) {
497 rpr0521_set_power_state(data, false, device_mask); 749 rpr0521_set_power_state(data, false, device_mask);
498 mutex_unlock(&data->lock); 750 goto rpr0521_read_raw_out;
499 return ret;
500 } 751 }
501 752
502 ret = rpr0521_set_power_state(data, false, device_mask); 753 ret = rpr0521_set_power_state(data, false, device_mask);
754
755rpr0521_read_raw_out:
503 mutex_unlock(&data->lock); 756 mutex_unlock(&data->lock);
757 iio_device_release_direct_mode(indio_dev);
504 if (ret < 0) 758 if (ret < 0)
505 return ret; 759 return ret;
506 760
@@ -617,12 +871,15 @@ static int rpr0521_init(struct rpr0521_data *data)
617 return ret; 871 return ret;
618#endif 872#endif
619 873
874 data->irq_timestamp = 0;
875
620 return 0; 876 return 0;
621} 877}
622 878
623static int rpr0521_poweroff(struct rpr0521_data *data) 879static int rpr0521_poweroff(struct rpr0521_data *data)
624{ 880{
625 int ret; 881 int ret;
882 int tmp;
626 883
627 ret = regmap_update_bits(data->regmap, RPR0521_REG_MODE_CTRL, 884 ret = regmap_update_bits(data->regmap, RPR0521_REG_MODE_CTRL,
628 RPR0521_MODE_ALS_MASK | 885 RPR0521_MODE_ALS_MASK |
@@ -635,6 +892,16 @@ static int rpr0521_poweroff(struct rpr0521_data *data)
635 data->als_dev_en = false; 892 data->als_dev_en = false;
636 data->pxs_dev_en = false; 893 data->pxs_dev_en = false;
637 894
895 /*
896 * Int pin keeps state after power off. Set pin to high impedance
897 * mode to prevent power drain.
898 */
899 ret = regmap_read(data->regmap, RPR0521_REG_INTERRUPT, &tmp);
900 if (ret) {
901 dev_err(&data->client->dev, "Failed to reset int pin.\n");
902 return ret;
903 }
904
638 return 0; 905 return 0;
639} 906}
640 907
@@ -707,6 +974,61 @@ static int rpr0521_probe(struct i2c_client *client,
707 pm_runtime_set_autosuspend_delay(&client->dev, RPR0521_SLEEP_DELAY_MS); 974 pm_runtime_set_autosuspend_delay(&client->dev, RPR0521_SLEEP_DELAY_MS);
708 pm_runtime_use_autosuspend(&client->dev); 975 pm_runtime_use_autosuspend(&client->dev);
709 976
977 /*
978 * If sensor write/read is needed in _probe after _use_autosuspend,
979 * sensor needs to be _resumed first using rpr0521_set_power_state().
980 */
981
982 /* IRQ to trigger setup */
983 if (client->irq) {
984 /* Trigger0 producer setup */
985 data->drdy_trigger0 = devm_iio_trigger_alloc(
986 indio_dev->dev.parent,
987 "%s-dev%d", indio_dev->name, indio_dev->id);
988 if (!data->drdy_trigger0) {
989 ret = -ENOMEM;
990 goto err_pm_disable;
991 }
992 data->drdy_trigger0->dev.parent = indio_dev->dev.parent;
993 data->drdy_trigger0->ops = &rpr0521_trigger_ops;
994 indio_dev->available_scan_masks = rpr0521_available_scan_masks;
995 iio_trigger_set_drvdata(data->drdy_trigger0, indio_dev);
996
997 /* Ties irq to trigger producer handler. */
998 ret = devm_request_threaded_irq(&client->dev, client->irq,
999 rpr0521_drdy_irq_handler, rpr0521_drdy_irq_thread,
1000 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
1001 RPR0521_IRQ_NAME, indio_dev);
1002 if (ret < 0) {
1003 dev_err(&client->dev, "request irq %d for trigger0 failed\n",
1004 client->irq);
1005 goto err_pm_disable;
1006 }
1007
1008 ret = devm_iio_trigger_register(indio_dev->dev.parent,
1009 data->drdy_trigger0);
1010 if (ret) {
1011 dev_err(&client->dev, "iio trigger register failed\n");
1012 goto err_pm_disable;
1013 }
1014
1015 /*
1016 * Now whole pipe from physical interrupt (irq defined by
1017 * devicetree to device) to trigger0 output is set up.
1018 */
1019
1020 /* Trigger consumer setup */
1021 ret = devm_iio_triggered_buffer_setup(indio_dev->dev.parent,
1022 indio_dev,
1023 rpr0521_trigger_consumer_store_time,
1024 rpr0521_trigger_consumer_handler,
1025 &rpr0521_buffer_setup_ops);
1026 if (ret < 0) {
1027 dev_err(&client->dev, "iio triggered buffer setup failed\n");
1028 goto err_pm_disable;
1029 }
1030 }
1031
710 ret = iio_device_register(indio_dev); 1032 ret = iio_device_register(indio_dev);
711 if (ret) 1033 if (ret)
712 goto err_pm_disable; 1034 goto err_pm_disable;
diff --git a/drivers/iio/light/tcs3472.c b/drivers/iio/light/tcs3472.c
index 3aa71e34ae28..09e6ca5e332e 100644
--- a/drivers/iio/light/tcs3472.c
+++ b/drivers/iio/light/tcs3472.c
@@ -11,6 +11,8 @@
11 * 7-bit I2C slave address 0x39 (TCS34721, TCS34723) or 0x29 (TCS34725, 11 * 7-bit I2C slave address 0x39 (TCS34721, TCS34723) or 0x29 (TCS34725,
12 * TCS34727) 12 * TCS34727)
13 * 13 *
14 * Datasheet: http://ams.com/eng/content/download/319364/1117183/file/TCS3472_Datasheet_EN_v2.pdf
15 *
14 * TODO: interrupt support, thresholds, wait time 16 * TODO: interrupt support, thresholds, wait time
15 */ 17 */
16 18
@@ -169,7 +171,7 @@ static int tcs3472_write_raw(struct iio_dev *indio_dev,
169 for (i = 0; i < 256; i++) { 171 for (i = 0; i < 256; i++) {
170 if (val2 == (256 - i) * 2400) { 172 if (val2 == (256 - i) * 2400) {
171 data->atime = i; 173 data->atime = i;
172 return i2c_smbus_write_word_data( 174 return i2c_smbus_write_byte_data(
173 data->client, TCS3472_ATIME, 175 data->client, TCS3472_ATIME,
174 data->atime); 176 data->atime);
175 } 177 }
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index 825369fb1c57..4ff883942f7b 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -784,6 +784,7 @@ static const struct iio_info ak8975_info = {
784 .driver_module = THIS_MODULE, 784 .driver_module = THIS_MODULE,
785}; 785};
786 786
787#ifdef CONFIG_ACPI
787static const struct acpi_device_id ak_acpi_match[] = { 788static const struct acpi_device_id ak_acpi_match[] = {
788 {"AK8975", AK8975}, 789 {"AK8975", AK8975},
789 {"AK8963", AK8963}, 790 {"AK8963", AK8963},
@@ -793,6 +794,7 @@ static const struct acpi_device_id ak_acpi_match[] = {
793 { }, 794 { },
794}; 795};
795MODULE_DEVICE_TABLE(acpi, ak_acpi_match); 796MODULE_DEVICE_TABLE(acpi, ak_acpi_match);
797#endif
796 798
797static const char *ak8975_match_acpi_device(struct device *dev, 799static const char *ak8975_match_acpi_device(struct device *dev,
798 enum asahi_compass_chipset *chipset) 800 enum asahi_compass_chipset *chipset)
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 8e1b0861fbe4..3573636bad8e 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -315,7 +315,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
315 }, 315 },
316 }, 316 },
317 }, 317 },
318 .multi_read_bit = false, 318 .multi_read_bit = true,
319 .bootime = 2, 319 .bootime = 2,
320 }, 320 },
321 { 321 {
diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
index 8aa37af306ed..6a6c8121ac2c 100644
--- a/drivers/iio/magnetometer/st_magn_i2c.c
+++ b/drivers/iio/magnetometer/st_magn_i2c.c
@@ -59,7 +59,8 @@ static int st_magn_i2c_probe(struct i2c_client *client,
59 return -ENOMEM; 59 return -ENOMEM;
60 60
61 mdata = iio_priv(indio_dev); 61 mdata = iio_priv(indio_dev);
62 st_sensors_of_i2c_probe(client, st_magn_of_match); 62 st_sensors_of_name_probe(&client->dev, st_magn_of_match,
63 client->name, sizeof(client->name));
63 64
64 st_sensors_i2c_configure(indio_dev, client, mdata); 65 st_sensors_i2c_configure(indio_dev, client, mdata);
65 66
diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c
index f3cb4dc05391..1ea64dd318aa 100644
--- a/drivers/iio/magnetometer/st_magn_spi.c
+++ b/drivers/iio/magnetometer/st_magn_spi.c
@@ -18,6 +18,28 @@
18#include <linux/iio/common/st_sensors_spi.h> 18#include <linux/iio/common/st_sensors_spi.h>
19#include "st_magn.h" 19#include "st_magn.h"
20 20
21#ifdef CONFIG_OF
22/*
23 * For new single-chip sensors use <device_name> as compatible string.
24 * For old single-chip devices keep <device_name>-magn to maintain
25 * compatibility
26 */
27static const struct of_device_id st_magn_of_match[] = {
28 {
29 .compatible = "st,lis3mdl-magn",
30 .data = LIS3MDL_MAGN_DEV_NAME,
31 },
32 {
33 .compatible = "st,lsm303agr-magn",
34 .data = LSM303AGR_MAGN_DEV_NAME,
35 },
36 {}
37};
38MODULE_DEVICE_TABLE(of, st_magn_of_match);
39#else
40#define st_magn_of_match NULL
41#endif
42
21static int st_magn_spi_probe(struct spi_device *spi) 43static int st_magn_spi_probe(struct spi_device *spi)
22{ 44{
23 struct iio_dev *indio_dev; 45 struct iio_dev *indio_dev;
@@ -30,6 +52,8 @@ static int st_magn_spi_probe(struct spi_device *spi)
30 52
31 mdata = iio_priv(indio_dev); 53 mdata = iio_priv(indio_dev);
32 54
55 st_sensors_of_name_probe(&spi->dev, st_magn_of_match,
56 spi->modalias, sizeof(spi->modalias));
33 st_sensors_spi_configure(indio_dev, spi, mdata); 57 st_sensors_spi_configure(indio_dev, spi, mdata);
34 58
35 err = st_magn_common_probe(indio_dev); 59 err = st_magn_common_probe(indio_dev);
@@ -57,6 +81,7 @@ MODULE_DEVICE_TABLE(spi, st_magn_id_table);
57static struct spi_driver st_magn_driver = { 81static struct spi_driver st_magn_driver = {
58 .driver = { 82 .driver = {
59 .name = "st-magn-spi", 83 .name = "st-magn-spi",
84 .of_match_table = of_match_ptr(st_magn_of_match),
60 }, 85 },
61 .probe = st_magn_spi_probe, 86 .probe = st_magn_spi_probe,
62 .remove = st_magn_spi_remove, 87 .remove = st_magn_spi_remove,
diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
index e9fa86c87db5..98fe0c5df380 100644
--- a/drivers/iio/orientation/hid-sensor-rotation.c
+++ b/drivers/iio/orientation/hid-sensor-rotation.c
@@ -238,7 +238,7 @@ static int dev_rot_parse_report(struct platform_device *pdev,
238static int hid_dev_rot_probe(struct platform_device *pdev) 238static int hid_dev_rot_probe(struct platform_device *pdev)
239{ 239{
240 int ret; 240 int ret;
241 static char *name; 241 char *name;
242 struct iio_dev *indio_dev; 242 struct iio_dev *indio_dev;
243 struct dev_rot_state *rot_state; 243 struct dev_rot_state *rot_state;
244 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 244 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
diff --git a/drivers/iio/pressure/ms5637.c b/drivers/iio/pressure/ms5637.c
index 953ffbc0ef96..c413f8a84a63 100644
--- a/drivers/iio/pressure/ms5637.c
+++ b/drivers/iio/pressure/ms5637.c
@@ -181,11 +181,21 @@ static const struct i2c_device_id ms5637_id[] = {
181}; 181};
182MODULE_DEVICE_TABLE(i2c, ms5637_id); 182MODULE_DEVICE_TABLE(i2c, ms5637_id);
183 183
184static const struct of_device_id ms5637_of_match[] = {
185 { .compatible = "meas,ms5637", },
186 { .compatible = "meas,ms5805", },
187 { .compatible = "meas,ms5837", },
188 { .compatible = "meas,ms8607-temppressure", },
189 { },
190};
191MODULE_DEVICE_TABLE(of, ms5637_of_match);
192
184static struct i2c_driver ms5637_driver = { 193static struct i2c_driver ms5637_driver = {
185 .probe = ms5637_probe, 194 .probe = ms5637_probe,
186 .id_table = ms5637_id, 195 .id_table = ms5637_id,
187 .driver = { 196 .driver = {
188 .name = "ms5637" 197 .name = "ms5637",
198 .of_match_table = of_match_ptr(ms5637_of_match),
189 }, 199 },
190}; 200};
191 201
diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c
index 17417a4d5a5f..7f15e927fa2b 100644
--- a/drivers/iio/pressure/st_pressure_i2c.c
+++ b/drivers/iio/pressure/st_pressure_i2c.c
@@ -77,7 +77,8 @@ static int st_press_i2c_probe(struct i2c_client *client,
77 press_data = iio_priv(indio_dev); 77 press_data = iio_priv(indio_dev);
78 78
79 if (client->dev.of_node) { 79 if (client->dev.of_node) {
80 st_sensors_of_i2c_probe(client, st_press_of_match); 80 st_sensors_of_name_probe(&client->dev, st_press_of_match,
81 client->name, sizeof(client->name));
81 } else if (ACPI_HANDLE(&client->dev)) { 82 } else if (ACPI_HANDLE(&client->dev)) {
82 ret = st_sensors_match_acpi_device(&client->dev); 83 ret = st_sensors_match_acpi_device(&client->dev);
83 if ((ret < 0) || (ret >= ST_PRESS_MAX)) 84 if ((ret < 0) || (ret >= ST_PRESS_MAX))
diff --git a/drivers/iio/pressure/st_pressure_spi.c b/drivers/iio/pressure/st_pressure_spi.c
index 550508025af1..f5ebd36bb4bf 100644
--- a/drivers/iio/pressure/st_pressure_spi.c
+++ b/drivers/iio/pressure/st_pressure_spi.c
@@ -18,6 +18,36 @@
18#include <linux/iio/common/st_sensors_spi.h> 18#include <linux/iio/common/st_sensors_spi.h>
19#include "st_pressure.h" 19#include "st_pressure.h"
20 20
21#ifdef CONFIG_OF
22/*
23 * For new single-chip sensors use <device_name> as compatible string.
24 * For old single-chip devices keep <device_name>-press to maintain
25 * compatibility
26 */
27static const struct of_device_id st_press_of_match[] = {
28 {
29 .compatible = "st,lps001wp-press",
30 .data = LPS001WP_PRESS_DEV_NAME,
31 },
32 {
33 .compatible = "st,lps25h-press",
34 .data = LPS25H_PRESS_DEV_NAME,
35 },
36 {
37 .compatible = "st,lps331ap-press",
38 .data = LPS331AP_PRESS_DEV_NAME,
39 },
40 {
41 .compatible = "st,lps22hb-press",
42 .data = LPS22HB_PRESS_DEV_NAME,
43 },
44 {},
45};
46MODULE_DEVICE_TABLE(of, st_press_of_match);
47#else
48#define st_press_of_match NULL
49#endif
50
21static int st_press_spi_probe(struct spi_device *spi) 51static int st_press_spi_probe(struct spi_device *spi)
22{ 52{
23 struct iio_dev *indio_dev; 53 struct iio_dev *indio_dev;
@@ -30,6 +60,8 @@ static int st_press_spi_probe(struct spi_device *spi)
30 60
31 press_data = iio_priv(indio_dev); 61 press_data = iio_priv(indio_dev);
32 62
63 st_sensors_of_name_probe(&spi->dev, st_press_of_match,
64 spi->modalias, sizeof(spi->modalias));
33 st_sensors_spi_configure(indio_dev, spi, press_data); 65 st_sensors_spi_configure(indio_dev, spi, press_data);
34 66
35 err = st_press_common_probe(indio_dev); 67 err = st_press_common_probe(indio_dev);
@@ -58,6 +90,7 @@ MODULE_DEVICE_TABLE(spi, st_press_id_table);
58static struct spi_driver st_press_driver = { 90static struct spi_driver st_press_driver = {
59 .driver = { 91 .driver = {
60 .name = "st-press-spi", 92 .name = "st-press-spi",
93 .of_match_table = of_match_ptr(st_press_of_match),
61 }, 94 },
62 .probe = st_press_spi_probe, 95 .probe = st_press_spi_probe,
63 .remove = st_press_spi_remove, 96 .remove = st_press_spi_remove,
diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
index c92a95f9f52c..ebfb1de7377f 100644
--- a/drivers/iio/pressure/zpa2326.c
+++ b/drivers/iio/pressure/zpa2326.c
@@ -141,14 +141,14 @@ struct zpa2326_private {
141 struct regulator *vdd; 141 struct regulator *vdd;
142}; 142};
143 143
144#define zpa2326_err(_idev, _format, _arg...) \ 144#define zpa2326_err(idev, fmt, ...) \
145 dev_err(_idev->dev.parent, _format, ##_arg) 145 dev_err(idev->dev.parent, fmt "\n", ##__VA_ARGS__)
146 146
147#define zpa2326_warn(_idev, _format, _arg...) \ 147#define zpa2326_warn(idev, fmt, ...) \
148 dev_warn(_idev->dev.parent, _format, ##_arg) 148 dev_warn(idev->dev.parent, fmt "\n", ##__VA_ARGS__)
149 149
150#define zpa2326_dbg(_idev, _format, _arg...) \ 150#define zpa2326_dbg(idev, fmt, ...) \
151 dev_dbg(_idev->dev.parent, _format, ##_arg) 151 dev_dbg(idev->dev.parent, fmt "\n", ##__VA_ARGS__)
152 152
153bool zpa2326_isreg_writeable(struct device *dev, unsigned int reg) 153bool zpa2326_isreg_writeable(struct device *dev, unsigned int reg)
154{ 154{
diff --git a/drivers/iio/temperature/tsys01.c b/drivers/iio/temperature/tsys01.c
index 3e60c6189d98..d8aa211d76e4 100644
--- a/drivers/iio/temperature/tsys01.c
+++ b/drivers/iio/temperature/tsys01.c
@@ -214,11 +214,18 @@ static const struct i2c_device_id tsys01_id[] = {
214}; 214};
215MODULE_DEVICE_TABLE(i2c, tsys01_id); 215MODULE_DEVICE_TABLE(i2c, tsys01_id);
216 216
217static const struct of_device_id tsys01_of_match[] = {
218 { .compatible = "meas,tsys01", },
219 { },
220};
221MODULE_DEVICE_TABLE(of, tsys01_of_match);
222
217static struct i2c_driver tsys01_driver = { 223static struct i2c_driver tsys01_driver = {
218 .probe = tsys01_i2c_probe, 224 .probe = tsys01_i2c_probe,
219 .id_table = tsys01_id, 225 .id_table = tsys01_id,
220 .driver = { 226 .driver = {
221 .name = "tsys01", 227 .name = "tsys01",
228 .of_match_table = of_match_ptr(tsys01_of_match),
222 }, 229 },
223}; 230};
224 231
diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
index d5ab83f0236d..f85dde9805e0 100644
--- a/drivers/staging/iio/adc/ad7280a.c
+++ b/drivers/staging/iio/adc/ad7280a.c
@@ -99,9 +99,14 @@
99#define AD7280A_DEVADDR_MASTER 0 99#define AD7280A_DEVADDR_MASTER 0
100#define AD7280A_DEVADDR_ALL 0x1F 100#define AD7280A_DEVADDR_ALL 0x1F
101/* 5-bit device address is sent LSB first */ 101/* 5-bit device address is sent LSB first */
102#define AD7280A_DEVADDR(addr) (((addr & 0x1) << 4) | ((addr & 0x2) << 3) | \ 102static unsigned int ad7280a_devaddr(unsigned int addr)
103 (addr & 0x4) | ((addr & 0x8) >> 3) | \ 103{
104 ((addr & 0x10) >> 4)) 104 return ((addr & 0x1) << 4) |
105 ((addr & 0x2) << 3) |
106 (addr & 0x4) |
107 ((addr & 0x8) >> 3) |
108 ((addr & 0x10) >> 4);
109}
105 110
106/* During a read a valid write is mandatory. 111/* During a read a valid write is mandatory.
107 * So writing to the highest available address (Address 0x1F) 112 * So writing to the highest available address (Address 0x1F)
@@ -372,7 +377,7 @@ static int ad7280_chain_setup(struct ad7280_state *st)
372 if (ad7280_check_crc(st, val)) 377 if (ad7280_check_crc(st, val))
373 return -EIO; 378 return -EIO;
374 379
375 if (n != AD7280A_DEVADDR(val >> 27)) 380 if (n != ad7280a_devaddr(val >> 27))
376 return -EIO; 381 return -EIO;
377 } 382 }
378 383
@@ -511,7 +516,7 @@ static int ad7280_channel_init(struct ad7280_state *st)
511 st->channels[cnt].info_mask_shared_by_type = 516 st->channels[cnt].info_mask_shared_by_type =
512 BIT(IIO_CHAN_INFO_SCALE); 517 BIT(IIO_CHAN_INFO_SCALE);
513 st->channels[cnt].address = 518 st->channels[cnt].address =
514 AD7280A_DEVADDR(dev) << 8 | ch; 519 ad7280a_devaddr(dev) << 8 | ch;
515 st->channels[cnt].scan_index = cnt; 520 st->channels[cnt].scan_index = cnt;
516 st->channels[cnt].scan_type.sign = 'u'; 521 st->channels[cnt].scan_type.sign = 'u';
517 st->channels[cnt].scan_type.realbits = 12; 522 st->channels[cnt].scan_type.realbits = 12;
@@ -558,7 +563,7 @@ static int ad7280_attr_init(struct ad7280_state *st)
558 for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_CELL_VOLTAGE_6; 563 for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_CELL_VOLTAGE_6;
559 ch++, cnt++) { 564 ch++, cnt++) {
560 st->iio_attr[cnt].address = 565 st->iio_attr[cnt].address =
561 AD7280A_DEVADDR(dev) << 8 | ch; 566 ad7280a_devaddr(dev) << 8 | ch;
562 st->iio_attr[cnt].dev_attr.attr.mode = 567 st->iio_attr[cnt].dev_attr.attr.mode =
563 0644; 568 0644;
564 st->iio_attr[cnt].dev_attr.show = 569 st->iio_attr[cnt].dev_attr.show =
@@ -574,7 +579,7 @@ static int ad7280_attr_init(struct ad7280_state *st)
574 &st->iio_attr[cnt].dev_attr.attr; 579 &st->iio_attr[cnt].dev_attr.attr;
575 cnt++; 580 cnt++;
576 st->iio_attr[cnt].address = 581 st->iio_attr[cnt].address =
577 AD7280A_DEVADDR(dev) << 8 | 582 ad7280a_devaddr(dev) << 8 |
578 (AD7280A_CB1_TIMER + ch); 583 (AD7280A_CB1_TIMER + ch);
579 st->iio_attr[cnt].dev_attr.attr.mode = 584 st->iio_attr[cnt].dev_attr.attr.mode =
580 0644; 585 0644;
@@ -918,7 +923,7 @@ static int ad7280_probe(struct spi_device *spi)
918 if (ret) 923 if (ret)
919 goto error_unregister; 924 goto error_unregister;
920 925
921 ret = ad7280_write(st, AD7280A_DEVADDR(st->slave_num), 926 ret = ad7280_write(st, ad7280a_devaddr(st->slave_num),
922 AD7280A_ALERT, 0, 927 AD7280A_ALERT, 0,
923 AD7280A_ALERT_GEN_STATIC_HIGH | 928 AD7280A_ALERT_GEN_STATIC_HIGH |
924 (pdata->chain_last_alert_ignore & 0xF)); 929 (pdata->chain_last_alert_ignore & 0xF));
diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index 146719928fb3..786e93f16ce9 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -285,35 +285,6 @@ static const u8 device_channel_config[] = {
285}; 285};
286 286
287/** 287/**
288 * tsl2x7x_i2c_read() - Read a byte from a register.
289 * @client: i2c client
290 * @reg: device register to read from
291 * @*val: pointer to location to store register contents.
292 *
293 */
294static int
295tsl2x7x_i2c_read(struct i2c_client *client, u8 reg, u8 *val)
296{
297 int ret;
298
299 /* select register to write */
300 ret = i2c_smbus_write_byte(client, (TSL2X7X_CMD_REG | reg));
301 if (ret < 0) {
302 dev_err(&client->dev, "failed to write register %x\n", reg);
303 return ret;
304 }
305
306 /* read the data */
307 ret = i2c_smbus_read_byte(client);
308 if (ret >= 0)
309 *val = (u8)ret;
310 else
311 dev_err(&client->dev, "failed to read register %x\n", reg);
312
313 return ret;
314}
315
316/**
317 * tsl2x7x_get_lux() - Reads and calculates current lux value. 288 * tsl2x7x_get_lux() - Reads and calculates current lux value.
318 * @indio_dev: pointer to IIO device 289 * @indio_dev: pointer to IIO device
319 * 290 *
@@ -352,15 +323,15 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
352 goto out_unlock; 323 goto out_unlock;
353 } 324 }
354 325
355 ret = tsl2x7x_i2c_read(chip->client, 326 ret = i2c_smbus_read_byte_data(chip->client,
356 (TSL2X7X_CMD_REG | TSL2X7X_STATUS), &buf[0]); 327 TSL2X7X_CMD_REG | TSL2X7X_STATUS);
357 if (ret < 0) { 328 if (ret < 0) {
358 dev_err(&chip->client->dev, 329 dev_err(&chip->client->dev,
359 "%s: Failed to read STATUS Reg\n", __func__); 330 "%s: Failed to read STATUS Reg\n", __func__);
360 goto out_unlock; 331 goto out_unlock;
361 } 332 }
362 /* is data new & valid */ 333 /* is data new & valid */
363 if (!(buf[0] & TSL2X7X_STA_ADC_VALID)) { 334 if (!(ret & TSL2X7X_STA_ADC_VALID)) {
364 dev_err(&chip->client->dev, 335 dev_err(&chip->client->dev,
365 "%s: data not valid yet\n", __func__); 336 "%s: data not valid yet\n", __func__);
366 ret = chip->als_cur_info.lux; /* return LAST VALUE */ 337 ret = chip->als_cur_info.lux; /* return LAST VALUE */
@@ -368,14 +339,16 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
368 } 339 }
369 340
370 for (i = 0; i < 4; i++) { 341 for (i = 0; i < 4; i++) {
371 ret = tsl2x7x_i2c_read(chip->client, 342 int reg = TSL2X7X_CMD_REG | (TSL2X7X_ALS_CHAN0LO + i);
372 (TSL2X7X_CMD_REG | 343
373 (TSL2X7X_ALS_CHAN0LO + i)), &buf[i]); 344 ret = i2c_smbus_read_byte_data(chip->client, reg);
374 if (ret < 0) { 345 if (ret < 0) {
375 dev_err(&chip->client->dev, 346 dev_err(&chip->client->dev,
376 "failed to read. err=%x\n", ret); 347 "failed to read. err=%x\n", ret);
377 goto out_unlock; 348 goto out_unlock;
378 } 349 }
350
351 buf[i] = ret;
379 } 352 }
380 353
381 /* clear any existing interrupt status */ 354 /* clear any existing interrupt status */
@@ -475,7 +448,6 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
475{ 448{
476 int i; 449 int i;
477 int ret; 450 int ret;
478 u8 status;
479 u8 chdata[2]; 451 u8 chdata[2];
480 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 452 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
481 453
@@ -485,8 +457,8 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
485 return -EBUSY; 457 return -EBUSY;
486 } 458 }
487 459
488 ret = tsl2x7x_i2c_read(chip->client, 460 ret = i2c_smbus_read_byte_data(chip->client,
489 (TSL2X7X_CMD_REG | TSL2X7X_STATUS), &status); 461 TSL2X7X_CMD_REG | TSL2X7X_STATUS);
490 if (ret < 0) { 462 if (ret < 0) {
491 dev_err(&chip->client->dev, "i2c err=%d\n", ret); 463 dev_err(&chip->client->dev, "i2c err=%d\n", ret);
492 goto prox_poll_err; 464 goto prox_poll_err;
@@ -498,7 +470,7 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
498 case tmd2671: 470 case tmd2671:
499 case tsl2771: 471 case tsl2771:
500 case tmd2771: 472 case tmd2771:
501 if (!(status & TSL2X7X_STA_ADC_VALID)) 473 if (!(ret & TSL2X7X_STA_ADC_VALID))
502 goto prox_poll_err; 474 goto prox_poll_err;
503 break; 475 break;
504 case tsl2572: 476 case tsl2572:
@@ -506,17 +478,19 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
506 case tmd2672: 478 case tmd2672:
507 case tsl2772: 479 case tsl2772:
508 case tmd2772: 480 case tmd2772:
509 if (!(status & TSL2X7X_STA_PRX_VALID)) 481 if (!(ret & TSL2X7X_STA_PRX_VALID))
510 goto prox_poll_err; 482 goto prox_poll_err;
511 break; 483 break;
512 } 484 }
513 485
514 for (i = 0; i < 2; i++) { 486 for (i = 0; i < 2; i++) {
515 ret = tsl2x7x_i2c_read(chip->client, 487 int reg = TSL2X7X_CMD_REG | (TSL2X7X_PRX_LO + i);
516 (TSL2X7X_CMD_REG | 488
517 (TSL2X7X_PRX_LO + i)), &chdata[i]); 489 ret = i2c_smbus_read_byte_data(chip->client, reg);
518 if (ret < 0) 490 if (ret < 0)
519 goto prox_poll_err; 491 goto prox_poll_err;
492
493 chdata[i] = ret;
520 } 494 }
521 495
522 chip->prox_data = 496 chip->prox_data =
@@ -568,39 +542,29 @@ static void tsl2x7x_defaults(struct tsl2X7X_chip *chip)
568static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev) 542static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
569{ 543{
570 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 544 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
571 u8 reg_val;
572 int gain_trim_val; 545 int gain_trim_val;
573 int ret; 546 int ret;
574 int lux_val; 547 int lux_val;
575 548
576 ret = i2c_smbus_write_byte(chip->client, 549 ret = i2c_smbus_read_byte_data(chip->client,
577 (TSL2X7X_CMD_REG | TSL2X7X_CNTRL)); 550 TSL2X7X_CMD_REG | TSL2X7X_CNTRL);
578 if (ret < 0) { 551 if (ret < 0) {
579 dev_err(&chip->client->dev, 552 dev_err(&chip->client->dev,
580 "failed to write CNTRL register, ret=%d\n", ret); 553 "%s: failed to read from the CNTRL register\n",
554 __func__);
581 return ret; 555 return ret;
582 } 556 }
583 557
584 reg_val = i2c_smbus_read_byte(chip->client); 558 if ((ret & (TSL2X7X_CNTL_ADC_ENBL | TSL2X7X_CNTL_PWR_ON))
585 if ((reg_val & (TSL2X7X_CNTL_ADC_ENBL | TSL2X7X_CNTL_PWR_ON)) 559 != (TSL2X7X_CNTL_ADC_ENBL | TSL2X7X_CNTL_PWR_ON)) {
586 != (TSL2X7X_CNTL_ADC_ENBL | TSL2X7X_CNTL_PWR_ON)) {
587 dev_err(&chip->client->dev,
588 "%s: failed: ADC not enabled\n", __func__);
589 return -1;
590 }
591
592 ret = i2c_smbus_write_byte(chip->client,
593 (TSL2X7X_CMD_REG | TSL2X7X_CNTRL));
594 if (ret < 0) {
595 dev_err(&chip->client->dev, 560 dev_err(&chip->client->dev,
596 "failed to write ctrl reg: ret=%d\n", ret); 561 "%s: Device is not powered on and/or ADC is not enabled\n",
597 return ret; 562 __func__);
598 } 563 return -EINVAL;
599 564 } else if ((ret & TSL2X7X_STA_ADC_VALID) != TSL2X7X_STA_ADC_VALID) {
600 reg_val = i2c_smbus_read_byte(chip->client);
601 if ((reg_val & TSL2X7X_STA_ADC_VALID) != TSL2X7X_STA_ADC_VALID) {
602 dev_err(&chip->client->dev, 565 dev_err(&chip->client->dev,
603 "%s: failed: STATUS - ADC not valid.\n", __func__); 566 "%s: The two ADC channels have not completed an integration cycle\n",
567 __func__);
604 return -ENODATA; 568 return -ENODATA;
605 } 569 }
606 570
@@ -722,7 +686,8 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
722 } 686 }
723 } 687 }
724 688
725 mdelay(3); /* Power-on settling time */ 689 /* Power-on settling time */
690 usleep_range(3000, 3500);
726 691
727 /* 692 /*
728 * NOW enable the ADC 693 * NOW enable the ADC
@@ -806,22 +771,24 @@ int tsl2x7x_invoke_change(struct iio_dev *indio_dev)
806{ 771{
807 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 772 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
808 int device_status = chip->tsl2x7x_chip_status; 773 int device_status = chip->tsl2x7x_chip_status;
774 int ret;
809 775
810 mutex_lock(&chip->als_mutex); 776 mutex_lock(&chip->als_mutex);
811 mutex_lock(&chip->prox_mutex); 777 mutex_lock(&chip->prox_mutex);
812 778
813 if (device_status == TSL2X7X_CHIP_WORKING) 779 if (device_status == TSL2X7X_CHIP_WORKING) {
814 tsl2x7x_chip_off(indio_dev); 780 ret = tsl2x7x_chip_off(indio_dev);
815 781 if (ret < 0)
816 tsl2x7x_chip_on(indio_dev); 782 goto unlock;
783 }
817 784
818 if (device_status != TSL2X7X_CHIP_WORKING) 785 ret = tsl2x7x_chip_on(indio_dev);
819 tsl2x7x_chip_off(indio_dev);
820 786
787unlock:
821 mutex_unlock(&chip->prox_mutex); 788 mutex_unlock(&chip->prox_mutex);
822 mutex_unlock(&chip->als_mutex); 789 mutex_unlock(&chip->als_mutex);
823 790
824 return 0; 791 return ret;
825} 792}
826 793
827static 794static
@@ -889,7 +856,7 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev)
889 856
890 /*gather the samples*/ 857 /*gather the samples*/
891 for (i = 0; i < chip->tsl2x7x_settings.prox_max_samples_cal; i++) { 858 for (i = 0; i < chip->tsl2x7x_settings.prox_max_samples_cal; i++) {
892 mdelay(15); 859 usleep_range(15000, 17500);
893 tsl2x7x_get_prox(indio_dev); 860 tsl2x7x_get_prox(indio_dev);
894 prox_history[i] = chip->prox_data; 861 prox_history[i] = chip->prox_data;
895 dev_info(&chip->client->dev, "2 i=%d prox data= %d\n", 862 dev_info(&chip->client->dev, "2 i=%d prox data= %d\n",
@@ -915,33 +882,6 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev)
915 tsl2x7x_chip_on(indio_dev); 882 tsl2x7x_chip_on(indio_dev);
916} 883}
917 884
918static ssize_t power_state_show(struct device *dev,
919 struct device_attribute *attr,
920 char *buf)
921{
922 struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
923
924 return snprintf(buf, PAGE_SIZE, "%d\n", chip->tsl2x7x_chip_status);
925}
926
927static ssize_t power_state_store(struct device *dev,
928 struct device_attribute *attr,
929 const char *buf, size_t len)
930{
931 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
932 bool value;
933
934 if (strtobool(buf, &value))
935 return -EINVAL;
936
937 if (value)
938 tsl2x7x_chip_on(indio_dev);
939 else
940 tsl2x7x_chip_off(indio_dev);
941
942 return len;
943}
944
945static ssize_t in_illuminance0_calibscale_available_show(struct device *dev, 885static ssize_t in_illuminance0_calibscale_available_show(struct device *dev,
946 struct device_attribute *attr, 886 struct device_attribute *attr,
947 char *buf) 887 char *buf)
@@ -1027,6 +967,7 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
1027 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 967 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1028 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 968 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1029 unsigned long value; 969 unsigned long value;
970 int ret;
1030 971
1031 if (kstrtoul(buf, 0, &value)) 972 if (kstrtoul(buf, 0, &value))
1032 return -EINVAL; 973 return -EINVAL;
@@ -1034,7 +975,9 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
1034 if (value) 975 if (value)
1035 chip->tsl2x7x_settings.als_cal_target = value; 976 chip->tsl2x7x_settings.als_cal_target = value;
1036 977
1037 tsl2x7x_invoke_change(indio_dev); 978 ret = tsl2x7x_invoke_change(indio_dev);
979 if (ret < 0)
980 return ret;
1038 981
1039 return len; 982 return len;
1040} 983}
@@ -1083,7 +1026,9 @@ static ssize_t in_intensity0_thresh_period_store(struct device *dev,
1083 dev_info(&chip->client->dev, "%s: als persistence = %d", 1026 dev_info(&chip->client->dev, "%s: als persistence = %d",
1084 __func__, filter_delay); 1027 __func__, filter_delay);
1085 1028
1086 tsl2x7x_invoke_change(indio_dev); 1029 ret = tsl2x7x_invoke_change(indio_dev);
1030 if (ret < 0)
1031 return ret;
1087 1032
1088 return IIO_VAL_INT_PLUS_MICRO; 1033 return IIO_VAL_INT_PLUS_MICRO;
1089} 1034}
@@ -1131,7 +1076,10 @@ static ssize_t in_proximity0_thresh_period_store(struct device *dev,
1131 dev_info(&chip->client->dev, "%s: prox persistence = %d", 1076 dev_info(&chip->client->dev, "%s: prox persistence = %d",
1132 __func__, filter_delay); 1077 __func__, filter_delay);
1133 1078
1134 tsl2x7x_invoke_change(indio_dev); 1079 ret = tsl2x7x_invoke_change(indio_dev);
1080 if (ret < 0)
1081 return ret;
1082
1135 1083
1136 return IIO_VAL_INT_PLUS_MICRO; 1084 return IIO_VAL_INT_PLUS_MICRO;
1137} 1085}
@@ -1142,6 +1090,7 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev,
1142{ 1090{
1143 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1091 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1144 bool value; 1092 bool value;
1093 int ret;
1145 1094
1146 if (strtobool(buf, &value)) 1095 if (strtobool(buf, &value))
1147 return -EINVAL; 1096 return -EINVAL;
@@ -1149,7 +1098,9 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev,
1149 if (value) 1098 if (value)
1150 tsl2x7x_als_calibrate(indio_dev); 1099 tsl2x7x_als_calibrate(indio_dev);
1151 1100
1152 tsl2x7x_invoke_change(indio_dev); 1101 ret = tsl2x7x_invoke_change(indio_dev);
1102 if (ret < 0)
1103 return ret;
1153 1104
1154 return len; 1105 return len;
1155} 1106}
@@ -1189,7 +1140,7 @@ static ssize_t in_illuminance0_lux_table_store(struct device *dev,
1189 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1140 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1190 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 1141 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1191 int value[ARRAY_SIZE(chip->tsl2x7x_device_lux) * 3 + 1]; 1142 int value[ARRAY_SIZE(chip->tsl2x7x_device_lux) * 3 + 1];
1192 int n; 1143 int n, ret;
1193 1144
1194 get_options(buf, ARRAY_SIZE(value), value); 1145 get_options(buf, ARRAY_SIZE(value), value);
1195 1146
@@ -1217,7 +1168,9 @@ static ssize_t in_illuminance0_lux_table_store(struct device *dev,
1217 memset(chip->tsl2x7x_device_lux, 0, sizeof(chip->tsl2x7x_device_lux)); 1168 memset(chip->tsl2x7x_device_lux, 0, sizeof(chip->tsl2x7x_device_lux));
1218 memcpy(chip->tsl2x7x_device_lux, &value[1], (value[0] * 4)); 1169 memcpy(chip->tsl2x7x_device_lux, &value[1], (value[0] * 4));
1219 1170
1220 tsl2x7x_invoke_change(indio_dev); 1171 ret = tsl2x7x_invoke_change(indio_dev);
1172 if (ret < 0)
1173 return ret;
1221 1174
1222 return len; 1175 return len;
1223} 1176}
@@ -1228,6 +1181,7 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev,
1228{ 1181{
1229 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1182 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1230 bool value; 1183 bool value;
1184 int ret;
1231 1185
1232 if (strtobool(buf, &value)) 1186 if (strtobool(buf, &value))
1233 return -EINVAL; 1187 return -EINVAL;
@@ -1235,7 +1189,9 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev,
1235 if (value) 1189 if (value)
1236 tsl2x7x_prox_cal(indio_dev); 1190 tsl2x7x_prox_cal(indio_dev);
1237 1191
1238 tsl2x7x_invoke_change(indio_dev); 1192 ret = tsl2x7x_invoke_change(indio_dev);
1193 if (ret < 0)
1194 return ret;
1239 1195
1240 return len; 1196 return len;
1241} 1197}
@@ -1263,6 +1219,7 @@ static int tsl2x7x_write_interrupt_config(struct iio_dev *indio_dev,
1263 int val) 1219 int val)
1264{ 1220{
1265 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 1221 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1222 int ret;
1266 1223
1267 if (chan->type == IIO_INTENSITY) { 1224 if (chan->type == IIO_INTENSITY) {
1268 if (val) 1225 if (val)
@@ -1276,83 +1233,108 @@ static int tsl2x7x_write_interrupt_config(struct iio_dev *indio_dev,
1276 chip->tsl2x7x_settings.interrupts_en &= 0x10; 1233 chip->tsl2x7x_settings.interrupts_en &= 0x10;
1277 } 1234 }
1278 1235
1279 tsl2x7x_invoke_change(indio_dev); 1236 ret = tsl2x7x_invoke_change(indio_dev);
1237 if (ret < 0)
1238 return ret;
1280 1239
1281 return 0; 1240 return 0;
1282} 1241}
1283 1242
1284static int tsl2x7x_write_thresh(struct iio_dev *indio_dev, 1243static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
1285 const struct iio_chan_spec *chan, 1244 const struct iio_chan_spec *chan,
1286 enum iio_event_type type, 1245 enum iio_event_type type,
1287 enum iio_event_direction dir, 1246 enum iio_event_direction dir,
1288 enum iio_event_info info, 1247 enum iio_event_info info,
1289 int val, int val2) 1248 int val, int val2)
1290{ 1249{
1291 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 1250 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1251 int ret = -EINVAL;
1292 1252
1293 if (chan->type == IIO_INTENSITY) { 1253 switch (info) {
1294 switch (dir) { 1254 case IIO_EV_INFO_VALUE:
1295 case IIO_EV_DIR_RISING: 1255 if (chan->type == IIO_INTENSITY) {
1296 chip->tsl2x7x_settings.als_thresh_high = val; 1256 switch (dir) {
1297 break; 1257 case IIO_EV_DIR_RISING:
1298 case IIO_EV_DIR_FALLING: 1258 chip->tsl2x7x_settings.als_thresh_high = val;
1299 chip->tsl2x7x_settings.als_thresh_low = val; 1259 ret = 0;
1300 break; 1260 break;
1301 default: 1261 case IIO_EV_DIR_FALLING:
1302 return -EINVAL; 1262 chip->tsl2x7x_settings.als_thresh_low = val;
1303 } 1263 ret = 0;
1304 } else { 1264 break;
1305 switch (dir) { 1265 default:
1306 case IIO_EV_DIR_RISING: 1266 break;
1307 chip->tsl2x7x_settings.prox_thres_high = val; 1267 }
1308 break; 1268 } else {
1309 case IIO_EV_DIR_FALLING: 1269 switch (dir) {
1310 chip->tsl2x7x_settings.prox_thres_low = val; 1270 case IIO_EV_DIR_RISING:
1311 break; 1271 chip->tsl2x7x_settings.prox_thres_high = val;
1312 default: 1272 ret = 0;
1313 return -EINVAL; 1273 break;
1274 case IIO_EV_DIR_FALLING:
1275 chip->tsl2x7x_settings.prox_thres_low = val;
1276 ret = 0;
1277 break;
1278 default:
1279 break;
1280 }
1314 } 1281 }
1282 break;
1283 default:
1284 break;
1315 } 1285 }
1316 1286
1317 tsl2x7x_invoke_change(indio_dev); 1287 if (ret < 0)
1288 return ret;
1318 1289
1319 return 0; 1290 return tsl2x7x_invoke_change(indio_dev);
1320} 1291}
1321 1292
1322static int tsl2x7x_read_thresh(struct iio_dev *indio_dev, 1293static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
1323 const struct iio_chan_spec *chan, 1294 const struct iio_chan_spec *chan,
1324 enum iio_event_type type, 1295 enum iio_event_type type,
1325 enum iio_event_direction dir, 1296 enum iio_event_direction dir,
1326 enum iio_event_info info, 1297 enum iio_event_info info,
1327 int *val, int *val2) 1298 int *val, int *val2)
1328{ 1299{
1329 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 1300 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1301 int ret = -EINVAL;
1330 1302
1331 if (chan->type == IIO_INTENSITY) { 1303 switch (info) {
1332 switch (dir) { 1304 case IIO_EV_INFO_VALUE:
1333 case IIO_EV_DIR_RISING: 1305 if (chan->type == IIO_INTENSITY) {
1334 *val = chip->tsl2x7x_settings.als_thresh_high; 1306 switch (dir) {
1335 break; 1307 case IIO_EV_DIR_RISING:
1336 case IIO_EV_DIR_FALLING: 1308 *val = chip->tsl2x7x_settings.als_thresh_high;
1337 *val = chip->tsl2x7x_settings.als_thresh_low; 1309 ret = IIO_VAL_INT;
1338 break; 1310 break;
1339 default: 1311 case IIO_EV_DIR_FALLING:
1340 return -EINVAL; 1312 *val = chip->tsl2x7x_settings.als_thresh_low;
1341 } 1313 ret = IIO_VAL_INT;
1342 } else { 1314 break;
1343 switch (dir) { 1315 default:
1344 case IIO_EV_DIR_RISING: 1316 break;
1345 *val = chip->tsl2x7x_settings.prox_thres_high; 1317 }
1346 break; 1318 } else {
1347 case IIO_EV_DIR_FALLING: 1319 switch (dir) {
1348 *val = chip->tsl2x7x_settings.prox_thres_low; 1320 case IIO_EV_DIR_RISING:
1349 break; 1321 *val = chip->tsl2x7x_settings.prox_thres_high;
1350 default: 1322 ret = IIO_VAL_INT;
1351 return -EINVAL; 1323 break;
1324 case IIO_EV_DIR_FALLING:
1325 *val = chip->tsl2x7x_settings.prox_thres_low;
1326 ret = IIO_VAL_INT;
1327 break;
1328 default:
1329 break;
1330 }
1352 } 1331 }
1332 break;
1333 default:
1334 break;
1353 } 1335 }
1354 1336
1355 return IIO_VAL_INT; 1337 return ret;
1356} 1338}
1357 1339
1358static int tsl2x7x_read_raw(struct iio_dev *indio_dev, 1340static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
@@ -1489,13 +1471,9 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
1489 return -EINVAL; 1471 return -EINVAL;
1490 } 1472 }
1491 1473
1492 tsl2x7x_invoke_change(indio_dev); 1474 return tsl2x7x_invoke_change(indio_dev);
1493
1494 return 0;
1495} 1475}
1496 1476
1497static DEVICE_ATTR_RW(power_state);
1498
1499static DEVICE_ATTR_RO(in_proximity0_calibscale_available); 1477static DEVICE_ATTR_RO(in_proximity0_calibscale_available);
1500 1478
1501static DEVICE_ATTR_RO(in_illuminance0_calibscale_available); 1479static DEVICE_ATTR_RO(in_illuminance0_calibscale_available);
@@ -1515,7 +1493,7 @@ static DEVICE_ATTR_RW(in_intensity0_thresh_period);
1515static DEVICE_ATTR_RW(in_proximity0_thresh_period); 1493static DEVICE_ATTR_RW(in_proximity0_thresh_period);
1516 1494
1517/* Use the default register values to identify the Taos device */ 1495/* Use the default register values to identify the Taos device */
1518static int tsl2x7x_device_id(unsigned char *id, int target) 1496static int tsl2x7x_device_id(int *id, int target)
1519{ 1497{
1520 switch (target) { 1498 switch (target) {
1521 case tsl2571: 1499 case tsl2571:
@@ -1580,7 +1558,6 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
1580} 1558}
1581 1559
1582static struct attribute *tsl2x7x_ALS_device_attrs[] = { 1560static struct attribute *tsl2x7x_ALS_device_attrs[] = {
1583 &dev_attr_power_state.attr,
1584 &dev_attr_in_illuminance0_calibscale_available.attr, 1561 &dev_attr_in_illuminance0_calibscale_available.attr,
1585 &dev_attr_in_illuminance0_integration_time.attr, 1562 &dev_attr_in_illuminance0_integration_time.attr,
1586 &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr, 1563 &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr,
@@ -1591,13 +1568,11 @@ static struct attribute *tsl2x7x_ALS_device_attrs[] = {
1591}; 1568};
1592 1569
1593static struct attribute *tsl2x7x_PRX_device_attrs[] = { 1570static struct attribute *tsl2x7x_PRX_device_attrs[] = {
1594 &dev_attr_power_state.attr,
1595 &dev_attr_in_proximity0_calibrate.attr, 1571 &dev_attr_in_proximity0_calibrate.attr,
1596 NULL 1572 NULL
1597}; 1573};
1598 1574
1599static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = { 1575static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
1600 &dev_attr_power_state.attr,
1601 &dev_attr_in_illuminance0_calibscale_available.attr, 1576 &dev_attr_in_illuminance0_calibscale_available.attr,
1602 &dev_attr_in_illuminance0_integration_time.attr, 1577 &dev_attr_in_illuminance0_integration_time.attr,
1603 &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr, 1578 &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr,
@@ -1609,14 +1584,12 @@ static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
1609}; 1584};
1610 1585
1611static struct attribute *tsl2x7x_PRX2_device_attrs[] = { 1586static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
1612 &dev_attr_power_state.attr,
1613 &dev_attr_in_proximity0_calibrate.attr, 1587 &dev_attr_in_proximity0_calibrate.attr,
1614 &dev_attr_in_proximity0_calibscale_available.attr, 1588 &dev_attr_in_proximity0_calibscale_available.attr,
1615 NULL 1589 NULL
1616}; 1590};
1617 1591
1618static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = { 1592static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
1619 &dev_attr_power_state.attr,
1620 &dev_attr_in_illuminance0_calibscale_available.attr, 1593 &dev_attr_in_illuminance0_calibscale_available.attr,
1621 &dev_attr_in_illuminance0_integration_time.attr, 1594 &dev_attr_in_illuminance0_integration_time.attr,
1622 &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr, 1595 &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr,
@@ -1684,8 +1657,8 @@ static const struct iio_info tsl2X7X_device_info[] = {
1684 .driver_module = THIS_MODULE, 1657 .driver_module = THIS_MODULE,
1685 .read_raw = &tsl2x7x_read_raw, 1658 .read_raw = &tsl2x7x_read_raw,
1686 .write_raw = &tsl2x7x_write_raw, 1659 .write_raw = &tsl2x7x_write_raw,
1687 .read_event_value = &tsl2x7x_read_thresh, 1660 .read_event_value = &tsl2x7x_read_event_value,
1688 .write_event_value = &tsl2x7x_write_thresh, 1661 .write_event_value = &tsl2x7x_write_event_value,
1689 .read_event_config = &tsl2x7x_read_interrupt_config, 1662 .read_event_config = &tsl2x7x_read_interrupt_config,
1690 .write_event_config = &tsl2x7x_write_interrupt_config, 1663 .write_event_config = &tsl2x7x_write_interrupt_config,
1691 }, 1664 },
@@ -1695,8 +1668,8 @@ static const struct iio_info tsl2X7X_device_info[] = {
1695 .driver_module = THIS_MODULE, 1668 .driver_module = THIS_MODULE,
1696 .read_raw = &tsl2x7x_read_raw, 1669 .read_raw = &tsl2x7x_read_raw,
1697 .write_raw = &tsl2x7x_write_raw, 1670 .write_raw = &tsl2x7x_write_raw,
1698 .read_event_value = &tsl2x7x_read_thresh, 1671 .read_event_value = &tsl2x7x_read_event_value,
1699 .write_event_value = &tsl2x7x_write_thresh, 1672 .write_event_value = &tsl2x7x_write_event_value,
1700 .read_event_config = &tsl2x7x_read_interrupt_config, 1673 .read_event_config = &tsl2x7x_read_interrupt_config,
1701 .write_event_config = &tsl2x7x_write_interrupt_config, 1674 .write_event_config = &tsl2x7x_write_interrupt_config,
1702 }, 1675 },
@@ -1706,8 +1679,8 @@ static const struct iio_info tsl2X7X_device_info[] = {
1706 .driver_module = THIS_MODULE, 1679 .driver_module = THIS_MODULE,
1707 .read_raw = &tsl2x7x_read_raw, 1680 .read_raw = &tsl2x7x_read_raw,
1708 .write_raw = &tsl2x7x_write_raw, 1681 .write_raw = &tsl2x7x_write_raw,
1709 .read_event_value = &tsl2x7x_read_thresh, 1682 .read_event_value = &tsl2x7x_read_event_value,
1710 .write_event_value = &tsl2x7x_write_thresh, 1683 .write_event_value = &tsl2x7x_write_event_value,
1711 .read_event_config = &tsl2x7x_read_interrupt_config, 1684 .read_event_config = &tsl2x7x_read_interrupt_config,
1712 .write_event_config = &tsl2x7x_write_interrupt_config, 1685 .write_event_config = &tsl2x7x_write_interrupt_config,
1713 }, 1686 },
@@ -1717,8 +1690,8 @@ static const struct iio_info tsl2X7X_device_info[] = {
1717 .driver_module = THIS_MODULE, 1690 .driver_module = THIS_MODULE,
1718 .read_raw = &tsl2x7x_read_raw, 1691 .read_raw = &tsl2x7x_read_raw,
1719 .write_raw = &tsl2x7x_write_raw, 1692 .write_raw = &tsl2x7x_write_raw,
1720 .read_event_value = &tsl2x7x_read_thresh, 1693 .read_event_value = &tsl2x7x_read_event_value,
1721 .write_event_value = &tsl2x7x_write_thresh, 1694 .write_event_value = &tsl2x7x_write_event_value,
1722 .read_event_config = &tsl2x7x_read_interrupt_config, 1695 .read_event_config = &tsl2x7x_read_interrupt_config,
1723 .write_event_config = &tsl2x7x_write_interrupt_config, 1696 .write_event_config = &tsl2x7x_write_interrupt_config,
1724 }, 1697 },
@@ -1728,8 +1701,8 @@ static const struct iio_info tsl2X7X_device_info[] = {
1728 .driver_module = THIS_MODULE, 1701 .driver_module = THIS_MODULE,
1729 .read_raw = &tsl2x7x_read_raw, 1702 .read_raw = &tsl2x7x_read_raw,
1730 .write_raw = &tsl2x7x_write_raw, 1703 .write_raw = &tsl2x7x_write_raw,
1731 .read_event_value = &tsl2x7x_read_thresh, 1704 .read_event_value = &tsl2x7x_read_event_value,
1732 .write_event_value = &tsl2x7x_write_thresh, 1705 .write_event_value = &tsl2x7x_write_event_value,
1733 .read_event_config = &tsl2x7x_read_interrupt_config, 1706 .read_event_config = &tsl2x7x_read_interrupt_config,
1734 .write_event_config = &tsl2x7x_write_interrupt_config, 1707 .write_event_config = &tsl2x7x_write_interrupt_config,
1735 }, 1708 },
@@ -1877,7 +1850,6 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
1877 const struct i2c_device_id *id) 1850 const struct i2c_device_id *id)
1878{ 1851{
1879 int ret; 1852 int ret;
1880 unsigned char device_id;
1881 struct iio_dev *indio_dev; 1853 struct iio_dev *indio_dev;
1882 struct tsl2X7X_chip *chip; 1854 struct tsl2X7X_chip *chip;
1883 1855
@@ -1889,13 +1861,13 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
1889 chip->client = clientp; 1861 chip->client = clientp;
1890 i2c_set_clientdata(clientp, indio_dev); 1862 i2c_set_clientdata(clientp, indio_dev);
1891 1863
1892 ret = tsl2x7x_i2c_read(chip->client, 1864 ret = i2c_smbus_read_byte_data(chip->client,
1893 TSL2X7X_CHIPID, &device_id); 1865 TSL2X7X_CMD_REG | TSL2X7X_CHIPID);
1894 if (ret < 0) 1866 if (ret < 0)
1895 return ret; 1867 return ret;
1896 1868
1897 if ((!tsl2x7x_device_id(&device_id, id->driver_data)) || 1869 if ((!tsl2x7x_device_id(&ret, id->driver_data)) ||
1898 (tsl2x7x_device_id(&device_id, id->driver_data) == -EINVAL)) { 1870 (tsl2x7x_device_id(&ret, id->driver_data) == -EINVAL)) {
1899 dev_info(&chip->client->dev, 1871 dev_info(&chip->client->dev,
1900 "%s: i2c device found does not match expected id\n", 1872 "%s: i2c device found does not match expected id\n",
1901 __func__); 1873 __func__);
@@ -2026,6 +1998,21 @@ static struct i2c_device_id tsl2x7x_idtable[] = {
2026 1998
2027MODULE_DEVICE_TABLE(i2c, tsl2x7x_idtable); 1999MODULE_DEVICE_TABLE(i2c, tsl2x7x_idtable);
2028 2000
2001static const struct of_device_id tsl2x7x_of_match[] = {
2002 { .compatible = "amstaos,tsl2571" },
2003 { .compatible = "amstaos,tsl2671" },
2004 { .compatible = "amstaos,tmd2671" },
2005 { .compatible = "amstaos,tsl2771" },
2006 { .compatible = "amstaos,tmd2771" },
2007 { .compatible = "amstaos,tsl2572" },
2008 { .compatible = "amstaos,tsl2672" },
2009 { .compatible = "amstaos,tmd2672" },
2010 { .compatible = "amstaos,tsl2772" },
2011 { .compatible = "amstaos,tmd2772" },
2012 {}
2013};
2014MODULE_DEVICE_TABLE(of, tsl2x7x_of_match);
2015
2029static const struct dev_pm_ops tsl2x7x_pm_ops = { 2016static const struct dev_pm_ops tsl2x7x_pm_ops = {
2030 .suspend = tsl2x7x_suspend, 2017 .suspend = tsl2x7x_suspend,
2031 .resume = tsl2x7x_resume, 2018 .resume = tsl2x7x_resume,
@@ -2035,6 +2022,7 @@ static const struct dev_pm_ops tsl2x7x_pm_ops = {
2035static struct i2c_driver tsl2x7x_driver = { 2022static struct i2c_driver tsl2x7x_driver = {
2036 .driver = { 2023 .driver = {
2037 .name = "tsl2x7x", 2024 .name = "tsl2x7x",
2025 .of_match_table = tsl2x7x_of_match,
2038 .pm = &tsl2x7x_pm_ops, 2026 .pm = &tsl2x7x_pm_ops,
2039 }, 2027 },
2040 .id_table = tsl2x7x_idtable, 2028 .id_table = tsl2x7x_idtable,
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 497f2b3a5a62..1f8211b6438b 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -325,4 +325,16 @@ ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
325ssize_t st_sensors_sysfs_scale_avail(struct device *dev, 325ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
326 struct device_attribute *attr, char *buf); 326 struct device_attribute *attr, char *buf);
327 327
328#ifdef CONFIG_OF
329void st_sensors_of_name_probe(struct device *dev,
330 const struct of_device_id *match,
331 char *name, int len);
332#else
333static inline void st_sensors_of_name_probe(struct device *dev,
334 const struct of_device_id *match,
335 char *name, int len)
336{
337}
338#endif
339
328#endif /* ST_SENSORS_H */ 340#endif /* ST_SENSORS_H */
diff --git a/include/linux/iio/common/st_sensors_i2c.h b/include/linux/iio/common/st_sensors_i2c.h
index 254de3c7dde8..0a2c25e06d1f 100644
--- a/include/linux/iio/common/st_sensors_i2c.h
+++ b/include/linux/iio/common/st_sensors_i2c.h
@@ -18,16 +18,6 @@
18void st_sensors_i2c_configure(struct iio_dev *indio_dev, 18void st_sensors_i2c_configure(struct iio_dev *indio_dev,
19 struct i2c_client *client, struct st_sensor_data *sdata); 19 struct i2c_client *client, struct st_sensor_data *sdata);
20 20
21#ifdef CONFIG_OF
22void st_sensors_of_i2c_probe(struct i2c_client *client,
23 const struct of_device_id *match);
24#else
25static inline void st_sensors_of_i2c_probe(struct i2c_client *client,
26 const struct of_device_id *match)
27{
28}
29#endif
30
31#ifdef CONFIG_ACPI 21#ifdef CONFIG_ACPI
32int st_sensors_match_acpi_device(struct device *dev); 22int st_sensors_match_acpi_device(struct device *dev);
33#else 23#else