Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'iio-for-5.15a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next

Jonathan writes:

First set of new IIO and counter device support, cleanups and features for 5.15

Usual mix of cleanups and new device support.

Counter
======

Cleanups and refactoring:
* treewide
- Ensure attempts to set invalid modes result in -EINVAL return.
- Rename counter_count_function to counter_function as the middle count
is redundant.
- Standardize error returns when limits are exceeded.
* 104-quad:
- Document the lock.
- Return an error if attempt to set the ceiling value in a mode that
doesn't support it.
* intel-qep
- Drop unused bitops.h include

IIO
===

New device support
* bma255
- Add support fo the bosch,bmc156_accel which oddly only exposes the INT2
interrupt pin and not INT1. Patch set includes enabling use of INT2.
* ingenic_adc
- Add support for JZ4760 and similar and update bindings
- Add support for JZ4760B and update bindings
* rockchip_saradc
- Add support for rk3568 ADC (separate channel array as more channels)
* sgp40 gas sensor used to measure air quality
- New driver including binding and ABI documentation.

Bindings
--------

* Add missing bindings for many DACs where the binding was effectively
implicit due to fallback probe methods in I2C and SPI.
adi,ad5064
adi,ad5360
adi,ad5380
adi,ad5421
adi,ad5449
adi,ad5504
adi,ad5624r
adi,ad5686 / adi,ad5696
adi,ad5761
adi,ad5764
adi,ad5791
adi,ad8801
capella,cm3323 (also add explicit of_device_id table)
microchip,mcp4922
* bosch,bma255
- Interrupt type in example was opposite of what the device expects.
It's possible that a particular board had an inverter, but we
definitely don't want the example to suggest this would be normal.
- Add interrupt-names to allow for cases where only INT2 is connected.
- Sort compatibles
- Merge in very similar bosch,bma180 binding.

New feature
-----------

* Devices only allowed to provide either extended_name or a label for given
channel. If extend_name is used (generally discouraged but can't be
removed as it would be a userspaece ABI change), then the label sysfs
attribute will provide the extended_name. This allows some userspace
parser simplications and hardening.
* hid-sensors-pres
- Add a timestamp channel (either from hardware, or locally filled).
* vcnl3020
- Add periodic sensor mode used to provide IIO events.

Cleanups / minor fixes
----------------------

* core/buffers
- Avoid unnecessary zeroing of bitmaps that are immediately overwritten.
- Move a sanity check earlier to simplify error path.
* Quite a few cases of refactors to use devm_* for all of probe and drop
remove
- adjd_s311
- adxl345
- bma220
- da280
- dmard10
- ds311
- max5481
- max5821
- rfd77402
- tcs3414
- tmp006
* ad5624r
- Fix incorrect handling of a regulator that was preventing use of
internal regulators.
* adjd_s311
- Allocate a buffer as part of iio_priv() structure as maximum size
is small enough, no significant advantage in making it flexible sized.
* bma220
- Make handling of suspend and resume closer to the probe() wrt to the
rather odd interface, that suspend mode is entered by reading a register.
* ep93xx
- Prepare clock before using (part of conversion to CCF)
* fsl-imx25-gcq
- Use local device pointer.
- Adjust handling of platform_get_irq() to not check for 0 as an error.
The function is documented as never returning it.
* hid-sensors
- Use devm_kmemdup() consistently across all drivers to simplify channel
structure allocation management.
* meson-saradc
- Drop BL30 integration on G12A and newer SoCs as not used.
- Whitespace fixes.
* mpu6050
- Add per device type startup times. This avoids an issue with having
to dsicard initial data from gyroscopes when they were still stabilizing.
* rfd77402
- Change from passing private data, to passing i2c_client where only
that is needed, reducing back and forth in pm functions.
* si1145
- Drop pointless continue
* st-sensors
- Cleanup of includes to remove unused and add missing headers that are used.
- Use some devm functions to simplify probe() and remove() - gets us part way
towards a fully device managed driver.
* sx9310
- Switch from of to generic properties to enable ACPI bindings.
* vcnl3020
- Add DMA safe buffer for bulk transfers.
- Drop use of iio_claim_direct() in a driver that has no mode changes.
A local lock is more appropriate.

* tag 'iio-for-5.15a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (77 commits)
counter: 104-quad-8: Describe member 'lock' in 'quad8'
iio: hid-sensor-press: Add timestamp channel
counter: Rename counter_count_function to counter_function
counter: Rename counter_signal_value to counter_signal_level
counter: Standardize to ERANGE for limit exceeded errors
counter: Return error code on invalid modes
counter: 104-quad-8: Return error when invalid mode during ceiling_write
iio: accel: bmc150: Add support for BMC156
iio: accel: bmc150: Make it possible to configure INT2 instead of INT1
dt-bindings: iio: accel: bma255: Add bosch,bmc156_accel
dt-bindings: iio: accel: bma255: Add interrupt-names
iio: light: cm3323: Add of_device_id table
dt-bindings: Add bindings for Capella cm3323 Ambient Light Sensor
iio: chemical: Add driver support for sgp40
dt-bindings: iio: chemical: Add trivial DT binding for sgp40
iio: ep93xx: Prepare clock before using it
iio: adc: fsl-imx25-gcq: adjust irq check to match docs and simplify code
iio: dac: max5821: convert device register to device managed function
dt-bindings: iio/adc: ingenic: add the JZ4760(B) socs to the sadc Documentation
iio/adc: ingenic: add JZ4760B support to the sadc driver
...

+2613 -809
+31
Documentation/ABI/testing/sysfs-bus-iio-chemical-sgp40
··· 1 + What: /sys/bus/iio/devices/iio:deviceX/out_temp_raw 2 + Date: August 2021 3 + KernelVersion: 5.15 4 + Contact: Andreas Klinger <ak@it-klinger.de> 5 + Description: 6 + Set the temperature. This value is sent to the sensor for 7 + temperature compensation. 8 + Default value: 25000 (25 °C) 9 + 10 + What: /sys/bus/iio/devices/iio:deviceX/out_humidityrelative_raw 11 + Date: August 2021 12 + KernelVersion: 5.15 13 + Contact: Andreas Klinger <ak@it-klinger.de> 14 + Description: 15 + Set the relative humidity. This value is sent to the sensor for 16 + humidity compensation. 17 + Default value: 50000 (50 % relative humidity) 18 + 19 + What: /sys/bus/iio/devices/iio:deviceX/in_resistance_calibbias 20 + Date: August 2021 21 + KernelVersion: 5.15 22 + Contact: Andreas Klinger <ak@it-klinger.de> 23 + Description: 24 + Set the bias value for the resistance which is used for 25 + calculation of in_concentration_input as follows: 26 + 27 + x = (in_resistance_raw - in_resistance_calibbias) * 0.65 28 + 29 + in_concentration_input = 500 / (1 + e^x) 30 + 31 + Default value: 30000
-61
Documentation/devicetree/bindings/iio/accel/bosch,bma180.yaml
··· 1 - # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 - %YAML 1.2 3 - --- 4 - $id: http://devicetree.org/schemas/iio/accel/bosch,bma180.yaml# 5 - $schema: http://devicetree.org/meta-schemas/core.yaml# 6 - 7 - title: Bosch BMA023 / BMA150/ BMA180 / BMA250 / SMB380 triaxial accelerometers 8 - 9 - maintainers: 10 - - Jonathan Cameron <jic23@kernel.org> 11 - 12 - description: | 13 - https://media.digikey.com/pdf/Data%20Sheets/Bosch/BMA150.pdf 14 - http://omapworld.com/BMA180_111_1002839.pdf 15 - http://ae-bst.resource.bosch.com/media/products/dokumente/bma250/bst-bma250-ds002-05.pdf 16 - 17 - properties: 18 - compatible: 19 - enum: 20 - - bosch,bma023 21 - - bosch,bma150 22 - - bosch,bma180 23 - - bosch,bma250 24 - - bosch,smb380 25 - 26 - reg: 27 - maxItems: 1 28 - 29 - vdd-supply: true 30 - 31 - vddio-supply: true 32 - 33 - interrupts: 34 - minItems: 1 35 - maxItems: 2 36 - description: | 37 - Type should be either IRQ_TYPE_LEVEL_HIGH or IRQ_TYPE_EDGE_RISING. 38 - For the bma250 the first interrupt listed must be the one 39 - connected to the INT1 pin, the second (optional) interrupt 40 - listed must be the one connected to the INT2 pin. 41 - 42 - required: 43 - - compatible 44 - - reg 45 - 46 - additionalProperties: false 47 - 48 - examples: 49 - - | 50 - #include <dt-bindings/interrupt-controller/irq.h> 51 - i2c { 52 - #address-cells = <1>; 53 - #size-cells = <0>; 54 - accel@40 { 55 - compatible = "bosch,bma180"; 56 - reg = <0x40>; 57 - interrupt-parent = <&gpio6>; 58 - interrupts = <18 (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_EDGE_RISING)>; 59 - }; 60 - }; 61 - ...
+46 -9
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml
··· 8 8 9 9 maintainers: 10 10 - Linus Walleij <linus.walleij@linaro.org> 11 + - Stephan Gerhold <stephan@gerhold.net> 11 12 12 13 description: 13 14 3 axis accelerometers with varying range and I2C or SPI ··· 17 16 properties: 18 17 compatible: 19 18 enum: 20 - - bosch,bmc150_accel 21 - - bosch,bmi055_accel 19 + # bmc150-accel driver in Linux 20 + - bosch,bma222 21 + - bosch,bma222e 22 + - bosch,bma250e 22 23 - bosch,bma253 23 24 - bosch,bma254 24 25 - bosch,bma255 25 - - bosch,bma250e 26 - - bosch,bma222 27 - - bosch,bma222e 28 26 - bosch,bma280 27 + - bosch,bmc150_accel 28 + - bosch,bmc156_accel 29 + - bosch,bmi055_accel 30 + 31 + # bma180 driver in Linux 32 + - bosch,bma023 33 + - bosch,bma150 34 + - bosch,bma180 35 + - bosch,bma250 36 + - bosch,smb380 29 37 30 38 reg: 31 39 maxItems: 1 ··· 46 36 minItems: 1 47 37 maxItems: 2 48 38 description: | 49 - The first interrupt listed must be the one connected to the INT1 pin, 50 - the second (optional) interrupt listed must be the one connected to the 51 - INT2 pin (if available). 39 + Without interrupt-names, the first interrupt listed must be the one 40 + connected to the INT1 pin, the second (optional) interrupt listed must be 41 + the one connected to the INT2 pin (if available). The type should be 42 + IRQ_TYPE_EDGE_RISING. 43 + 44 + BMC156 does not have an INT1 pin, therefore the first interrupt pin is 45 + always treated as INT2. 46 + 47 + interrupt-names: 48 + minItems: 1 49 + maxItems: 2 50 + items: 51 + enum: 52 + - INT1 53 + - INT2 52 54 53 55 mount-matrix: 54 56 description: an optional 3x3 mounting rotation matrix. ··· 85 63 reg = <0x08>; 86 64 vddio-supply = <&vddio>; 87 65 vdd-supply = <&vdd>; 88 - interrupts = <57 IRQ_TYPE_EDGE_FALLING>; 66 + interrupts = <57 IRQ_TYPE_EDGE_RISING>; 67 + interrupt-names = "INT1"; 68 + }; 69 + }; 70 + - | 71 + #include <dt-bindings/interrupt-controller/irq.h> 72 + i2c { 73 + #address-cells = <1>; 74 + #size-cells = <0>; 75 + accelerometer@10 { 76 + compatible = "bosch,bmc156_accel"; 77 + reg = <0x10>; 78 + vddio-supply = <&vddio>; 79 + vdd-supply = <&vdd>; 80 + interrupts = <116 IRQ_TYPE_EDGE_RISING>; 81 + interrupt-names = "INT2"; 89 82 }; 90 83 }; 91 84 - |
+19
Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
··· 23 23 enum: 24 24 - ingenic,jz4725b-adc 25 25 - ingenic,jz4740-adc 26 + - ingenic,jz4760-adc 27 + - ingenic,jz4760b-adc 26 28 - ingenic,jz4770-adc 27 29 28 30 '#io-channel-cells': ··· 44 42 45 43 interrupts: 46 44 maxItems: 1 45 + 46 + ingenic,use-internal-divider: 47 + description: 48 + If present, battery voltage is read from the VBAT_IR pin, which has an 49 + internal 1/4 divider. If absent, it is read through the VBAT_ER pin, 50 + which does not have such a divider. 51 + type: boolean 52 + 53 + if: 54 + not: 55 + properties: 56 + compatible: 57 + contains: 58 + const: ingenic,jz4760b-adc 59 + then: 60 + properties: 61 + ingenic,use-internal-divider: false 47 62 48 63 required: 49 64 - compatible
+1
Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml
··· 20 20 - rockchip,px30-saradc 21 21 - rockchip,rk3308-saradc 22 22 - rockchip,rk3328-saradc 23 + - rockchip,rk3568-saradc 23 24 - rockchip,rv1108-saradc 24 25 - const: rockchip,rk3399-saradc 25 26
+268
Documentation/devicetree/bindings/iio/dac/adi,ad5064.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/adi,ad5064.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD5064 and similar DACs 8 + 9 + maintainers: 10 + - Lars-Peter Clausen <lars@metafoo.de> 11 + - Jonathan Cameron <jic23@kernel.org> 12 + 13 + description: | 14 + A range of similar DAC devices with between 1 and 12 channels. Some parts 15 + have internal references, others require a single shared external reference 16 + and the remainder have a separate reference pin for each DAC. 17 + 18 + properties: 19 + compatible: 20 + oneOf: 21 + - description: I2C devics 22 + enum: 23 + - adi,ad5024 24 + - adi,ad5025 25 + - adi,ad5044 26 + - adi,ad5045 27 + - adi,ad5064 28 + - adi,ad5064-1 29 + - adi,ad5065 30 + - adi,ad5628-1 31 + - adi,ad5628-2 32 + - adi,ad5648-1 33 + - adi,ad5648-2 34 + - adi,ad5666-1 35 + - adi,ad5666-2 36 + - adi,ad5668-1 37 + - adi,ad5668-2 38 + - adi,ad5668-3 39 + - description: SPI devices 40 + enum: 41 + - adi,ad5625 42 + - adi,ad5625r-1v25 43 + - adi,ad5625r-2v5 44 + - adi,ad5627 45 + - adi,ad5627r-1v25 46 + - adi,ad5627r-2v5 47 + - adi,ad5629-1 48 + - adi,ad5629-2 49 + - adi,ad5629-3 50 + - adi,ad5645r-1v25 51 + - adi,ad5645r-2v5 52 + - adi,ad5665 53 + - adi,ad5665r-1v25 54 + - adi,ad5665r-2v5 55 + - adi,ad5667 56 + - adi,ad5667r-1v25 57 + - adi,ad5667r-2v5 58 + - adi,ad5669-1 59 + - adi,ad5669-2 60 + - adi,ad5669-3 61 + - lltc,ltc2606 62 + - lltc,ltc2607 63 + - lltc,ltc2609 64 + - lltc,ltc2616 65 + - lltc,ltc2617 66 + - lltc,ltc2619 67 + - lltc,ltc2626 68 + - lltc,ltc2627 69 + - lltc,ltc2629 70 + - lltc,ltc2631-l12 71 + - lltc,ltc2631-h12 72 + - lltc,ltc2631-l10 73 + - lltc,ltc2631-h10 74 + - lltc,ltc2631-l8 75 + - lltc,ltc2631-h8 76 + - lltc,ltc2633-l12 77 + - lltc,ltc2633-h12 78 + - lltc,ltc2633-l10 79 + - lltc,ltc2633-h10 80 + - lltc,ltc2633-l8 81 + - lltc,ltc2633-h8 82 + - lltc,ltc2635-l12 83 + - lltc,ltc2635-h12 84 + - lltc,ltc2635-l10 85 + - lltc,ltc2635-h10 86 + - lltc,ltc2635-l8 87 + - lltc,ltc2635-h8 88 + 89 + reg: 90 + maxItems: 1 91 + 92 + vrefA-supply: true 93 + vrefB-supply: true 94 + vrefC-supply: true 95 + vrefD-supply: true 96 + vref-supply: true 97 + 98 + spi-max-frequency: true 99 + 100 + additionalProperties: false 101 + 102 + required: 103 + - compatible 104 + - reg 105 + 106 + allOf: 107 + - # Shared external vref, no internal reference 108 + if: 109 + properties: 110 + compatible: 111 + contains: 112 + enum: 113 + - adi,ad5064-1 114 + - adi,ad5625 115 + - adi,ad5627 116 + - adi,ad5665 117 + - adi,ad5667 118 + - lltc,ltc2606 119 + - lltc,ltc2607 120 + - lltc,ltc2616 121 + - lltc,ltc2617 122 + - lltc,ltc2626 123 + - lltc,ltc2627 124 + then: 125 + properties: 126 + vref-supply: true 127 + vrefA-supply: false 128 + vrefB-supply: false 129 + vrefC-supply: false 130 + vrefD-supply: false 131 + required: 132 + - vref-supply 133 + - # Shared external vref, internal reference available 134 + if: 135 + properties: 136 + compatible: 137 + contains: 138 + enum: 139 + - adi,ad5625r-1v25 140 + - adi,ad5625r-2v5 141 + - adi,ad5627r-1v25 142 + - adi,ad5627r-2v5 143 + - adi,ad5628-1 144 + - adi,ad5628-2 145 + - adi,ad5629-1 146 + - adi,ad5629-2 147 + - adi,ad5629-3 148 + - adi,ad5645r-1v25 149 + - adi,ad5645r-2v5 150 + - adi,ad5647r-1v25 151 + - adi,ad5647r-2v5 152 + - adi,ad5648-1 153 + - adi,ad5648-2 154 + - adi,ad5665r-1v25 155 + - adi,ad5665r-2v5 156 + - adi,ad5666-1 157 + - adi,ad5666-2 158 + - adi,ad5667r-1v25 159 + - adi,ad5667r-2v5 160 + - adi,ad5668-1 161 + - adi,ad5668-2 162 + - adi,ad5668-3 163 + - adi,ad5669-1 164 + - adi,ad5669-2 165 + - adi,ad5669-3 166 + - lltc,ltc2631-l12 167 + - lltc,ltc2631-h12 168 + - lltc,ltc2631-l10 169 + - lltc,ltc2631-h10 170 + - lltc,ltc2631-l8 171 + - lltc,ltc2631-h8 172 + - lltc,ltc2633-l12 173 + - lltc,ltc2633-h12 174 + - lltc,ltc2633-l10 175 + - lltc,ltc2633-h10 176 + - lltc,ltc2633-l8 177 + - lltc,ltc2633-h8 178 + - lltc,ltc2635-l12 179 + - lltc,ltc2635-h12 180 + - lltc,ltc2635-l10 181 + - lltc,ltc2635-h10 182 + - lltc,ltc2635-l8 183 + - lltc,ltc2635-h8 184 + then: 185 + properties: 186 + vref-supply: true 187 + vrefA-supply: false 188 + vrefB-supply: false 189 + vrefC-supply: false 190 + vrefD-supply: false 191 + - # 4 input devices, separate vrefs, no internal reference 192 + if: 193 + properties: 194 + compatible: 195 + contains: 196 + enum: 197 + - adi,ad5024 198 + - adi,ad5044 199 + - adi,ad5064 200 + - lltc,ltc2609 201 + - lltc,ltc2619 202 + - lltc,ltc2629 203 + then: 204 + properties: 205 + vrefA-supply: true 206 + vrefB-supply: true 207 + vrefC-supply: true 208 + vrefD-supply: true 209 + vref-supply: false 210 + required: 211 + - vrefA-supply 212 + - vrefB-supply 213 + - vrefC-supply 214 + - vrefD-supply 215 + - # 2 input devices, separate vrefs, no internal reference 216 + if: 217 + properties: 218 + compatible: 219 + contains: 220 + enum: 221 + - adi,ad5025 222 + - adi,ad5045 223 + - adi,ad5065 224 + then: 225 + properties: 226 + vrefA-supply: true 227 + vrefB-supply: true 228 + vrefC-supply: false 229 + vrefD-supply: false 230 + vref-supply: false 231 + required: 232 + - vrefA-supply 233 + - vrefB-supply 234 + 235 + examples: 236 + - | 237 + spi { 238 + #address-cells = <1>; 239 + #size-cells = <0>; 240 + dac@0 { 241 + reg = <0>; 242 + compatible = "adi,ad5625"; 243 + vref-supply = <&dac_vref>; 244 + }; 245 + }; 246 + - | 247 + spi { 248 + #address-cells = <1>; 249 + #size-cells = <0>; 250 + dac@0 { 251 + reg = <0>; 252 + compatible = "adi,ad5625r-1v25"; 253 + }; 254 + }; 255 + - | 256 + i2c { 257 + #address-cells = <1>; 258 + #size-cells = <0>; 259 + dac@42 { 260 + reg = <0x42>; 261 + compatible = "adi,ad5024"; 262 + vrefA-supply = <&dac_vref>; 263 + vrefB-supply = <&dac_vref>; 264 + vrefC-supply = <&dac_vref2>; 265 + vrefD-supply = <&dac_vref2>; 266 + }; 267 + }; 268 + ...
+79
Documentation/devicetree/bindings/iio/dac/adi,ad5360.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/adi,ad5360.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD5360 and similar DACs 8 + 9 + maintainers: 10 + - Lars-Peter Clausen <lars@metafoo.de> 11 + - Jonathan Cameron <jic23@kernel.org> 12 + 13 + properties: 14 + compatible: 15 + enum: 16 + - adi,ad5360 17 + - adi,ad5361 18 + - adi,ad5363 19 + - adi,ad5370 20 + - adi,ad5371 21 + - adi,ad5372 22 + - adi,ad5373 23 + 24 + reg: 25 + maxItems: 1 26 + 27 + vref0-supply: true 28 + vref1-supply: true 29 + vref2-supply: true 30 + 31 + spi-max-frequency: true 32 + 33 + additionalProperties: false 34 + 35 + required: 36 + - compatible 37 + - reg 38 + - vref0-supply 39 + - vref1-supply 40 + 41 + allOf: 42 + - if: 43 + properties: 44 + compatible: 45 + contains: 46 + enum: 47 + - adi,ad5360 48 + - adi,ad5361 49 + - adi,ad5363 50 + - adi,ad5370 51 + - adi,ad5372 52 + - adi,ad5373 53 + then: 54 + properties: 55 + vref2-supply: false 56 + - if: 57 + properties: 58 + compatible: 59 + contains: 60 + enum: 61 + - adi,ad5371 62 + then: 63 + required: 64 + - vref2-supply 65 + 66 + examples: 67 + - | 68 + spi { 69 + #address-cells = <1>; 70 + #size-cells = <0>; 71 + dac@0 { 72 + reg = <0>; 73 + compatible = "adi,ad5371"; 74 + vref0-supply = <&dac_vref0>; 75 + vref1-supply = <&dac_vref1>; 76 + vref2-supply = <&dac_vref2>; 77 + }; 78 + }; 79 + ...
+70
Documentation/devicetree/bindings/iio/dac/adi,ad5380.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/adi,ad5380.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD5380 and similar DACs 8 + 9 + maintainers: 10 + - Lars-Peter Clausen <lars@metafoo.de> 11 + - Jonathan Cameron <jic23@kernel.org> 12 + 13 + description: | 14 + DAC devices supporting both SPI and I2C interfaces. 15 + properties: 16 + compatible: 17 + enum: 18 + - adi,ad5380-3 19 + - adi,ad5380-5 20 + - adi,ad5381-3 21 + - adi,ad5381-5 22 + - adi,ad5382-3 23 + - adi,ad5382-5 24 + - adi,ad5383-3 25 + - adi,ad5383-5 26 + - adi,ad5384-3 27 + - adi,ad5384-5 28 + - adi,ad5390-3 29 + - adi,ad5390-5 30 + - adi,ad5391-3 31 + - adi,ad5391-5 32 + - adi,ad5392-3 33 + - adi,ad5392-5 34 + 35 + reg: 36 + maxItems: 1 37 + 38 + vref-supply: 39 + description: 40 + If not supplied devices will use internal regulators. 41 + 42 + spi-max-frequency: true 43 + 44 + additionalProperties: false 45 + 46 + required: 47 + - compatible 48 + - reg 49 + 50 + examples: 51 + - | 52 + spi { 53 + #address-cells = <1>; 54 + #size-cells = <0>; 55 + dac@0 { 56 + reg = <0>; 57 + compatible = "adi,ad5390-5"; 58 + vref-supply = <&dacvref>; 59 + }; 60 + }; 61 + - | 62 + i2c { 63 + #address-cells = <1>; 64 + #size-cells = <0>; 65 + dac@42 { 66 + reg = <0x42>; 67 + compatible = "adi,ad5380-3"; 68 + }; 69 + }; 70 + ...
+51
Documentation/devicetree/bindings/iio/dac/adi,ad5421.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/adi,ad5421.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD5421 DAC 8 + 9 + maintainers: 10 + - Lars-Peter Clausen <lars@metafoo.de> 11 + - Jonathan Cameron <jic23@kernel.org> 12 + 13 + description: | 14 + AD5421 is designed for us in loop-powered, 4 mA to 20 mA smart transmitter 15 + applications. It provides a 16-bit DAC, current amplifier, voltage regulator 16 + to drive the loop and a voltage reference. 17 + 18 + properties: 19 + compatible: 20 + const: adi,ad5421 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + interrupts: 26 + maxItems: 1 27 + description: Fault signal. 28 + 29 + spi-max-frequency: true 30 + 31 + required: 32 + - compatible 33 + - reg 34 + 35 + additionalProperties: false 36 + 37 + examples: 38 + - | 39 + #include <dt-bindings/interrupt-controller/irq.h> 40 + spi { 41 + #address-cells = <1>; 42 + #size-cells = <0>; 43 + 44 + dac@0 { 45 + compatible = "adi,ad5421"; 46 + reg = <0>; 47 + spi-max-frequency = <30000000>; 48 + interrupts = <55 IRQ_TYPE_LEVEL_HIGH>; 49 + }; 50 + }; 51 + ...
+97
Documentation/devicetree/bindings/iio/dac/adi,ad5449.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/adi,ad5449.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD5449 and similar DACs 8 + 9 + maintainers: 10 + - Lars-Peter Clausen <lars@metafoo.de> 11 + - Jonathan Cameron <jic23@kernel.org> 12 + 13 + description: 14 + Family of multiplying DACs from Analog Devices 15 + 16 + properties: 17 + compatible: 18 + enum: 19 + - adi,ad5415 20 + - adi,ad5426 21 + - adi,ad5429 22 + - adi,ad5432 23 + - adi,ad5439 24 + - adi,ad5443 25 + - adi,ad5449 26 + 27 + reg: 28 + maxItems: 1 29 + 30 + spi-max-frequency: true 31 + 32 + VREF-supply: true 33 + VREFA-supply: true 34 + VREFB-supply: true 35 + 36 + additionalProperties: false 37 + 38 + required: 39 + - compatible 40 + - reg 41 + 42 + allOf: 43 + - if: 44 + properties: 45 + compatible: 46 + contains: 47 + enum: 48 + - adi,ad5415 49 + - adi,ad5426 50 + - adi,ad5432 51 + then: 52 + properties: 53 + VREF-supply: true 54 + VREFA-supply: false 55 + VREFB-supply: false 56 + required: 57 + - VREF-supply 58 + - if: 59 + properties: 60 + compatible: 61 + contains: 62 + enum: 63 + - adi,ad5429 64 + - adi,ad5439 65 + - adi,ad5449 66 + then: 67 + properties: 68 + VREF-supply: false 69 + VREFA-supply: true 70 + VREFB-supply: true 71 + required: 72 + - VREFA-supply 73 + - VREFB-supply 74 + 75 + examples: 76 + - | 77 + spi { 78 + #address-cells = <1>; 79 + #size-cells = <0>; 80 + dac@0 { 81 + reg = <0>; 82 + compatible = "adi,ad5415"; 83 + VREF-supply = <&dac_ref>; 84 + }; 85 + }; 86 + - | 87 + spi { 88 + #address-cells = <1>; 89 + #size-cells = <0>; 90 + dac@0 { 91 + reg = <0>; 92 + compatible = "adi,ad5429"; 93 + VREFA-supply = <&dac_refA>; 94 + VREFB-supply = <&dac_refB>; 95 + }; 96 + }; 97 + ...
+50
Documentation/devicetree/bindings/iio/dac/adi,ad5504.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/adi,ad5504.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD5501 and AD5504 DACs 8 + 9 + maintainers: 10 + - Lars-Peter Clausen <lars@metafoo.de> 11 + - Jonathan Cameron <jic23@kernel.org> 12 + 13 + description: 14 + High voltage (up to 60V) DACs with temperature sensor alarm function 15 + 16 + properties: 17 + compatible: 18 + enum: 19 + - adi,ad5501 20 + - adi,ad5504 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + interrupts: 26 + description: Used for temperature alarm. 27 + maxItems: 1 28 + 29 + vcc-supply: true 30 + 31 + additionalProperties: false 32 + 33 + required: 34 + - compatible 35 + - reg 36 + 37 + examples: 38 + - | 39 + #include <dt-bindings/interrupt-controller/irq.h> 40 + spi { 41 + #address-cells = <1>; 42 + #size-cells = <0>; 43 + dac@0 { 44 + reg = <0>; 45 + compatible = "adi,ad5504"; 46 + vcc-supply = <&dac_vcc>; 47 + interrupts = <55 IRQ_TYPE_EDGE_FALLING>; 48 + }; 49 + }; 50 + ...
+47
Documentation/devicetree/bindings/iio/dac/adi,ad5624r.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/adi,ad5624r.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD5624r and similar DACs 8 + 9 + maintainers: 10 + - Jonathan Cameron <jic23@kernel.org> 11 + 12 + properties: 13 + compatible: 14 + enum: 15 + - adi,ad5624r3 16 + - adi,ad5644r3 17 + - adi,ad5664r3 18 + - adi,ad5624r5 19 + - adi,ad5644r5 20 + - adi,ad5664r5 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + spi-max-frequency: true 26 + 27 + vref-supply: 28 + description: If not present, internal reference will be used. 29 + 30 + additionalProperties: false 31 + 32 + required: 33 + - compatible 34 + - reg 35 + 36 + examples: 37 + - | 38 + spi { 39 + #address-cells = <1>; 40 + #size-cells = <0>; 41 + dac@0 { 42 + reg = <0>; 43 + compatible = "adi,ad5624r3"; 44 + vref-supply = <&vref>; 45 + }; 46 + }; 47 + ...
+75
Documentation/devicetree/bindings/iio/dac/adi,ad5686.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/adi,ad5686.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD5360 and similar DACs 8 + 9 + maintainers: 10 + - Michael Hennerich <michael.hennerich@analog.com> 11 + - Jonathan Cameron <jic23@kernel.org> 12 + 13 + properties: 14 + compatible: 15 + oneOf: 16 + - description: SPI devices 17 + enum: 18 + - adi,ad5310r 19 + - adi,ad5672r 20 + - adi,ad5674r 21 + - adi,ad5676 22 + - adi,ad5676r 23 + - adi,ad5679r 24 + - adi,ad5681r 25 + - adi,ad5682r 26 + - adi,ad5683 27 + - adi,ad5683r 28 + - adi,ad5684 29 + - adi,ad5684r 30 + - adi,ad5685r 31 + - adi,ad5686 32 + - adi,ad5686r 33 + - description: I2C devices 34 + enum: 35 + - adi,ad5311r 36 + - adi,ad5338r 37 + - adi,ad5671r 38 + - adi,ad5675r 39 + - adi,ad5691r 40 + - adi,ad5692r 41 + - adi,ad5693 42 + - adi,ad5693r 43 + - adi,ad5694 44 + - adi,ad5694r 45 + - adi,ad5695r 46 + - adi,ad5696 47 + - adi,ad5696r 48 + 49 + 50 + reg: 51 + maxItems: 1 52 + 53 + vcc-supply: 54 + description: If not supplied the internal reference is used. 55 + 56 + spi-max-frequency: true 57 + 58 + additionalProperties: false 59 + 60 + required: 61 + - compatible 62 + - reg 63 + 64 + examples: 65 + - | 66 + spi { 67 + #address-cells = <1>; 68 + #size-cells = <0>; 69 + dac@0 { 70 + reg = <0>; 71 + compatible = "adi,ad5310r"; 72 + vcc-supply = <&dac_vref0>; 73 + }; 74 + }; 75 + ...
+60
Documentation/devicetree/bindings/iio/dac/adi,ad5761.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/adi,ad5761.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD5761 and similar DACs 8 + 9 + maintainers: 10 + - Ricardo Ribalda <ribalda@kernel.org> 11 + - Jonathan Cameron <jic23@kernel.org> 12 + 13 + properties: 14 + 15 + compatible: 16 + enum: 17 + - adi,ad5721 18 + - adi,ad5721r 19 + - adi,ad5761 20 + - adi,ad5761r 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + spi-max-frequency: true 26 + 27 + vref-supply: 28 + description: If not supplied, internal reference will be used. 29 + 30 + additionalProperties: false 31 + 32 + required: 33 + - compatible 34 + - reg 35 + 36 + allOf: 37 + - if: 38 + properties: 39 + compatible: 40 + contains: 41 + enum: 42 + - adi,ad5721 43 + - adi,ad5761 44 + then: 45 + required: 46 + - vref-supply 47 + 48 + examples: 49 + - | 50 + spi { 51 + #address-cells = <1>; 52 + #size-cells = <0>; 53 + 54 + dac@0 { 55 + compatible = "adi,ad5721"; 56 + reg = <0>; 57 + vref-supply = <&dac_vref>; 58 + }; 59 + }; 60 + ...
+62
Documentation/devicetree/bindings/iio/dac/adi,ad5764.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/adi,ad5764.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD5744 and AD5764 DAC families 8 + 9 + maintainers: 10 + - Lars-Peter Clausen <lars@metafoo.de> 11 + - Jonathan Cameron <jic23@kernel.org> 12 + 13 + properties: 14 + 15 + compatible: 16 + enum: 17 + - adi,ad5744 18 + - adi,ad5744r 19 + - adi,ad5764 20 + - adi,ad5764r 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + spi-max-frequency: true 26 + 27 + vrefAB-supply: true 28 + vrefCD-supply: true 29 + 30 + additionalProperties: false 31 + 32 + required: 33 + - compatible 34 + - reg 35 + 36 + allOf: 37 + - if: 38 + properties: 39 + compatible: 40 + contains: 41 + enum: 42 + - adi,ad5744 43 + - adi,ad5764 44 + then: 45 + required: 46 + - vrefAB-supply 47 + - vrefCD-supply 48 + 49 + examples: 50 + - | 51 + spi { 52 + #address-cells = <1>; 53 + #size-cells = <0>; 54 + 55 + dac@0 { 56 + compatible = "adi,ad5744"; 57 + reg = <0>; 58 + vrefAB-supply = <&dac_vref>; 59 + vrefCD-supply = <&dac_vref>; 60 + }; 61 + }; 62 + ...
+52
Documentation/devicetree/bindings/iio/dac/adi,ad5791.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/adi,ad5791.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD5791 and similar DACs 8 + 9 + maintainers: 10 + - Michael Hennerich <michael.hennerich@analog.com> 11 + - Jonathan Cameron <jic23@kernel.org> 12 + 13 + properties: 14 + 15 + compatible: 16 + enum: 17 + - adi,ad5760 18 + - adi,ad5780 19 + - adi,ad5781 20 + - adi,ad5790 21 + - adi,ad5791 22 + 23 + reg: 24 + maxItems: 1 25 + 26 + spi-max-frequency: true 27 + 28 + vdd-supply: true 29 + vss-supply: true 30 + 31 + additionalProperties: false 32 + 33 + required: 34 + - compatible 35 + - reg 36 + - vdd-supply 37 + - vss-supply 38 + 39 + examples: 40 + - | 41 + spi { 42 + #address-cells = <1>; 43 + #size-cells = <0>; 44 + 45 + dac@0 { 46 + compatible = "adi,ad5791"; 47 + reg = <0>; 48 + vss-supply = <&dac_vss>; 49 + vdd-supply = <&dac_vdd>; 50 + }; 51 + }; 52 + ...
+60
Documentation/devicetree/bindings/iio/dac/adi,ad8801.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/adi,ad8801.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD8801 and AD8803 DACs 8 + 9 + maintainers: 10 + - Jonathan Cameron <jic23@kernel.org> 11 + 12 + properties: 13 + 14 + compatible: 15 + enum: 16 + - adi,ad8801 17 + - adi,ad8803 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + spi-max-frequency: true 23 + 24 + vrefh-supply: true 25 + vrefl-supply: true 26 + 27 + additionalProperties: false 28 + 29 + required: 30 + - compatible 31 + - reg 32 + - vrefh-supply 33 + 34 + allOf: 35 + - if: 36 + properties: 37 + compatible: 38 + contains: 39 + const: adi,ad8803 40 + then: 41 + required: 42 + - vrefl-supply 43 + else: 44 + properties: 45 + vrefl-supply: false 46 + 47 + examples: 48 + - | 49 + spi { 50 + #address-cells = <1>; 51 + #size-cells = <0>; 52 + 53 + dac@0 { 54 + compatible = "adi,ad8803"; 55 + reg = <0>; 56 + vrefl-supply = <&dac_vrefl>; 57 + vrefh-supply = <&dac_vrefh>; 58 + }; 59 + }; 60 + ...
+46
Documentation/devicetree/bindings/iio/dac/microchip,mcp4922.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/dac/microchip,mcp4922.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Microchip MCP4902, MCP4912 and MPC4922 dual output SPI DACs 8 + 9 + maintainers: 10 + - Jonathan Cameron <jic23@kernel.org> 11 + - Michael Welling <mwelling@ieee.org> 12 + 13 + properties: 14 + compatible: 15 + enum: 16 + - microchip,mcp4902 17 + - microchip,mcp4912 18 + - microchip,mcp4922 19 + 20 + reg: 21 + maxItems: 1 22 + 23 + spi-max-frequency: true 24 + 25 + vref-supply: true 26 + 27 + additionalProperties: false 28 + 29 + required: 30 + - compatible 31 + - reg 32 + - vref-supply 33 + 34 + examples: 35 + - | 36 + spi { 37 + #address-cells = <1>; 38 + #size-cells = <0>; 39 + 40 + dac@0 { 41 + compatible = "microchip,mcp4912"; 42 + reg = <0>; 43 + vref-supply = <&dac_vref>; 44 + }; 45 + }; 46 + ...
+4
Documentation/devicetree/bindings/trivial-devices.yaml
··· 61 61 - capella,cm32181 62 62 # CM3232: Ambient Light Sensor 63 63 - capella,cm3232 64 + # CM3323: Ambient Light Sensor 65 + - capella,cm3323 64 66 # High-Precision Digital Thermometer 65 67 - dallas,ds1631 66 68 # Total-Elapsed-Time Recorder with Alarm ··· 271 269 - sensirion,sgpc3 272 270 # Sensirion multi-pixel gas sensor with I2C interface 273 271 - sensirion,sgp30 272 + # Sensirion gas sensor with I2C interface 273 + - sensirion,sgp40 274 274 # Sensortek 3 axis accelerometer 275 275 - sensortek,stk8312 276 276 # Sensortek 3 axis accelerometer
+6
MAINTAINERS
··· 16717 16717 F: drivers/iio/chemical/scd30_i2c.c 16718 16718 F: drivers/iio/chemical/scd30_serial.c 16719 16719 16720 + SENSIRION SGP40 GAS SENSOR DRIVER 16721 + M: Andreas Klinger <ak@it-klinger.de> 16722 + S: Maintained 16723 + F: Documentation/ABI/testing/sysfs-bus-iio-chemical-sgp40 16724 + F: drivers/iio/chemical/sgp40.c 16725 + 16720 16726 SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER 16721 16727 M: Tomasz Duszynski <tduszyns@gmail.com> 16722 16728 S: Maintained
+29 -18
drivers/counter/104-quad-8.c
··· 28 28 29 29 /** 30 30 * struct quad8 - device private data structure 31 + * @lock: lock to prevent clobbering device states during R/W ops 31 32 * @counter: instance of the counter_device 32 33 * @fck_prescaler: array of filter clock prescaler configurations 33 34 * @preset: array of preset values ··· 98 97 #define QUAD8_CMR_QUADRATURE_X4 0x18 99 98 100 99 static int quad8_signal_read(struct counter_device *counter, 101 - struct counter_signal *signal, enum counter_signal_value *val) 100 + struct counter_signal *signal, 101 + enum counter_signal_level *level) 102 102 { 103 103 const struct quad8 *const priv = counter->priv; 104 104 unsigned int state; ··· 111 109 state = inb(priv->base + QUAD8_REG_INDEX_INPUT_LEVELS) 112 110 & BIT(signal->id - 16); 113 111 114 - *val = (state) ? COUNTER_SIGNAL_HIGH : COUNTER_SIGNAL_LOW; 112 + *level = (state) ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW; 115 113 116 114 return 0; 117 115 } ··· 156 154 157 155 /* Only 24-bit values are supported */ 158 156 if (val > 0xFFFFFF) 159 - return -EINVAL; 157 + return -ERANGE; 160 158 161 159 mutex_lock(&priv->lock); 162 160 ··· 195 193 QUAD8_COUNT_FUNCTION_QUADRATURE_X4 196 194 }; 197 195 198 - static const enum counter_count_function quad8_count_functions_list[] = { 199 - [QUAD8_COUNT_FUNCTION_PULSE_DIRECTION] = COUNTER_COUNT_FUNCTION_PULSE_DIRECTION, 200 - [QUAD8_COUNT_FUNCTION_QUADRATURE_X1] = COUNTER_COUNT_FUNCTION_QUADRATURE_X1_A, 201 - [QUAD8_COUNT_FUNCTION_QUADRATURE_X2] = COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A, 202 - [QUAD8_COUNT_FUNCTION_QUADRATURE_X4] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4 196 + static const enum counter_function quad8_count_functions_list[] = { 197 + [QUAD8_COUNT_FUNCTION_PULSE_DIRECTION] = COUNTER_FUNCTION_PULSE_DIRECTION, 198 + [QUAD8_COUNT_FUNCTION_QUADRATURE_X1] = COUNTER_FUNCTION_QUADRATURE_X1_A, 199 + [QUAD8_COUNT_FUNCTION_QUADRATURE_X2] = COUNTER_FUNCTION_QUADRATURE_X2_A, 200 + [QUAD8_COUNT_FUNCTION_QUADRATURE_X4] = COUNTER_FUNCTION_QUADRATURE_X4 203 201 }; 204 202 205 203 static int quad8_function_get(struct counter_device *counter, ··· 275 273 *scale = 2; 276 274 mode_cfg |= QUAD8_CMR_QUADRATURE_X4; 277 275 break; 276 + default: 277 + /* should never reach this path */ 278 + mutex_unlock(&priv->lock); 279 + return -EINVAL; 278 280 } 279 281 } 280 282 ··· 355 349 case QUAD8_COUNT_FUNCTION_PULSE_DIRECTION: 356 350 if (synapse->signal->id == signal_a_id) 357 351 *action = QUAD8_SYNAPSE_ACTION_RISING_EDGE; 358 - break; 352 + return 0; 359 353 case QUAD8_COUNT_FUNCTION_QUADRATURE_X1: 360 354 if (synapse->signal->id == signal_a_id) { 361 355 quad8_direction_get(counter, count, &direction); ··· 365 359 else 366 360 *action = QUAD8_SYNAPSE_ACTION_FALLING_EDGE; 367 361 } 368 - break; 362 + return 0; 369 363 case QUAD8_COUNT_FUNCTION_QUADRATURE_X2: 370 364 if (synapse->signal->id == signal_a_id) 371 365 *action = QUAD8_SYNAPSE_ACTION_BOTH_EDGES; 372 - break; 366 + return 0; 373 367 case QUAD8_COUNT_FUNCTION_QUADRATURE_X4: 374 368 *action = QUAD8_SYNAPSE_ACTION_BOTH_EDGES; 375 - break; 369 + return 0; 370 + default: 371 + /* should never reach this path */ 372 + return -EINVAL; 376 373 } 377 - 378 - return 0; 379 374 } 380 375 381 376 static const struct counter_ops quad8_ops = { ··· 536 529 case COUNTER_COUNT_MODE_MODULO_N: 537 530 cnt_mode = 3; 538 531 break; 532 + default: 533 + /* should never reach this path */ 534 + return -EINVAL; 539 535 } 540 536 541 537 mutex_lock(&priv->lock); ··· 671 661 672 662 /* Only 24-bit values are supported */ 673 663 if (preset > 0xFFFFFF) 674 - return -EINVAL; 664 + return -ERANGE; 675 665 676 666 mutex_lock(&priv->lock); 677 667 ··· 716 706 717 707 /* Only 24-bit values are supported */ 718 708 if (ceiling > 0xFFFFFF) 719 - return -EINVAL; 709 + return -ERANGE; 720 710 721 711 mutex_lock(&priv->lock); 722 712 ··· 725 715 case 1: 726 716 case 3: 727 717 quad8_preset_register_set(priv, count->id, ceiling); 728 - break; 718 + mutex_unlock(&priv->lock); 719 + return len; 729 720 } 730 721 731 722 mutex_unlock(&priv->lock); 732 723 733 - return len; 724 + return -EINVAL; 734 725 } 735 726 736 727 static ssize_t quad8_count_preset_enable_read(struct counter_device *counter,
+25 -25
drivers/counter/counter.c
··· 289 289 struct counter_signal *signal; 290 290 }; 291 291 292 - static const char *const counter_signal_value_str[] = { 293 - [COUNTER_SIGNAL_LOW] = "low", 294 - [COUNTER_SIGNAL_HIGH] = "high" 292 + static const char *const counter_signal_level_str[] = { 293 + [COUNTER_SIGNAL_LEVEL_LOW] = "low", 294 + [COUNTER_SIGNAL_LEVEL_HIGH] = "high" 295 295 }; 296 296 297 297 static ssize_t counter_signal_show(struct device *dev, ··· 302 302 const struct counter_signal_unit *const component = devattr->component; 303 303 struct counter_signal *const signal = component->signal; 304 304 int err; 305 - enum counter_signal_value val; 305 + enum counter_signal_level level; 306 306 307 - err = counter->ops->signal_read(counter, signal, &val); 307 + err = counter->ops->signal_read(counter, signal, &level); 308 308 if (err) 309 309 return err; 310 310 311 - return sprintf(buf, "%s\n", counter_signal_value_str[val]); 311 + return sprintf(buf, "%s\n", counter_signal_level_str[level]); 312 312 } 313 313 314 314 struct counter_name_unit { ··· 744 744 return len; 745 745 } 746 746 747 - static const char *const counter_count_function_str[] = { 748 - [COUNTER_COUNT_FUNCTION_INCREASE] = "increase", 749 - [COUNTER_COUNT_FUNCTION_DECREASE] = "decrease", 750 - [COUNTER_COUNT_FUNCTION_PULSE_DIRECTION] = "pulse-direction", 751 - [COUNTER_COUNT_FUNCTION_QUADRATURE_X1_A] = "quadrature x1 a", 752 - [COUNTER_COUNT_FUNCTION_QUADRATURE_X1_B] = "quadrature x1 b", 753 - [COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A] = "quadrature x2 a", 754 - [COUNTER_COUNT_FUNCTION_QUADRATURE_X2_B] = "quadrature x2 b", 755 - [COUNTER_COUNT_FUNCTION_QUADRATURE_X4] = "quadrature x4" 747 + static const char *const counter_function_str[] = { 748 + [COUNTER_FUNCTION_INCREASE] = "increase", 749 + [COUNTER_FUNCTION_DECREASE] = "decrease", 750 + [COUNTER_FUNCTION_PULSE_DIRECTION] = "pulse-direction", 751 + [COUNTER_FUNCTION_QUADRATURE_X1_A] = "quadrature x1 a", 752 + [COUNTER_FUNCTION_QUADRATURE_X1_B] = "quadrature x1 b", 753 + [COUNTER_FUNCTION_QUADRATURE_X2_A] = "quadrature x2 a", 754 + [COUNTER_FUNCTION_QUADRATURE_X2_B] = "quadrature x2 b", 755 + [COUNTER_FUNCTION_QUADRATURE_X4] = "quadrature x4" 756 756 }; 757 757 758 758 static ssize_t counter_function_show(struct device *dev, ··· 764 764 const struct counter_count_unit *const component = devattr->component; 765 765 struct counter_count *const count = component->count; 766 766 size_t func_index; 767 - enum counter_count_function function; 767 + enum counter_function function; 768 768 769 769 err = counter->ops->function_get(counter, count, &func_index); 770 770 if (err) ··· 773 773 count->function = func_index; 774 774 775 775 function = count->functions_list[func_index]; 776 - return sprintf(buf, "%s\n", counter_count_function_str[function]); 776 + return sprintf(buf, "%s\n", counter_function_str[function]); 777 777 } 778 778 779 779 static ssize_t counter_function_store(struct device *dev, ··· 785 785 struct counter_count *const count = component->count; 786 786 const size_t num_functions = count->num_functions; 787 787 size_t func_index; 788 - enum counter_count_function function; 788 + enum counter_function function; 789 789 int err; 790 790 struct counter_device *const counter = dev_get_drvdata(dev); 791 791 792 792 /* Find requested Count function mode */ 793 793 for (func_index = 0; func_index < num_functions; func_index++) { 794 794 function = count->functions_list[func_index]; 795 - if (sysfs_streq(buf, counter_count_function_str[function])) 795 + if (sysfs_streq(buf, counter_function_str[function])) 796 796 break; 797 797 } 798 798 /* Return error if requested Count function mode not found */ ··· 880 880 } 881 881 882 882 struct counter_func_avail_unit { 883 - const enum counter_count_function *functions_list; 883 + const enum counter_function *functions_list; 884 884 size_t num_functions; 885 885 }; 886 886 887 - static ssize_t counter_count_function_available_show(struct device *dev, 887 + static ssize_t counter_function_available_show(struct device *dev, 888 888 struct device_attribute *attr, char *buf) 889 889 { 890 890 const struct counter_device_attr *const devattr = to_counter_attr(attr); 891 891 const struct counter_func_avail_unit *const component = devattr->component; 892 - const enum counter_count_function *const func_list = component->functions_list; 892 + const enum counter_function *const func_list = component->functions_list; 893 893 const size_t num_functions = component->num_functions; 894 894 size_t i; 895 - enum counter_count_function function; 895 + enum counter_function function; 896 896 ssize_t len = 0; 897 897 898 898 for (i = 0; i < num_functions; i++) { 899 899 function = func_list[i]; 900 900 len += sprintf(buf + len, "%s\n", 901 - counter_count_function_str[function]); 901 + counter_function_str[function]); 902 902 } 903 903 904 904 return len; ··· 968 968 parm.group = group; 969 969 parm.prefix = ""; 970 970 parm.name = "function_available"; 971 - parm.show = counter_count_function_available_show; 971 + parm.show = counter_function_available_show; 972 972 parm.store = NULL; 973 973 parm.component = avail_comp; 974 974 err = counter_attribute_create(&parm);
+2 -3
drivers/counter/ftm-quaddec.c
··· 171 171 FTM_QUADDEC_COUNT_ENCODER_MODE_1, 172 172 }; 173 173 174 - static const enum counter_count_function ftm_quaddec_count_functions[] = { 175 - [FTM_QUADDEC_COUNT_ENCODER_MODE_1] = 176 - COUNTER_COUNT_FUNCTION_QUADRATURE_X4 174 + static const enum counter_function ftm_quaddec_count_functions[] = { 175 + [FTM_QUADDEC_COUNT_ENCODER_MODE_1] = COUNTER_FUNCTION_QUADRATURE_X4 177 176 }; 178 177 179 178 static int ftm_quaddec_count_read(struct counter_device *counter,
+3 -4
drivers/counter/intel-qep.c
··· 8 8 * Author: Jarkko Nikula <jarkko.nikula@linux.intel.com> 9 9 * Author: Raymond Tan <raymond.tan@intel.com> 10 10 */ 11 - #include <linux/bitops.h> 12 11 #include <linux/counter.h> 13 12 #include <linux/kernel.h> 14 13 #include <linux/module.h> ··· 126 127 return 0; 127 128 } 128 129 129 - static const enum counter_count_function intel_qep_count_functions[] = { 130 - COUNTER_COUNT_FUNCTION_QUADRATURE_X4, 130 + static const enum counter_function intel_qep_count_functions[] = { 131 + COUNTER_FUNCTION_QUADRATURE_X4, 131 132 }; 132 133 133 134 static int intel_qep_function_get(struct counter_device *counter, ··· 319 320 } 320 321 321 322 if (length > INTEL_QEPFLT_MAX_COUNT(length)) 322 - return -EINVAL; 323 + return -ERANGE; 323 324 324 325 mutex_lock(&qep->lock); 325 326 if (qep->enabled) {
+7 -4
drivers/counter/interrupt-cnt.c
··· 107 107 { 108 108 struct interrupt_cnt_priv *priv = counter->priv; 109 109 110 + if (val != (typeof(priv->count.counter))val) 111 + return -ERANGE; 112 + 110 113 atomic_set(&priv->count, val); 111 114 112 115 return 0; 113 116 } 114 117 115 - static const enum counter_count_function interrupt_cnt_functions[] = { 116 - COUNTER_COUNT_FUNCTION_INCREASE, 118 + static const enum counter_function interrupt_cnt_functions[] = { 119 + COUNTER_FUNCTION_INCREASE, 117 120 }; 118 121 119 122 static int interrupt_cnt_function_get(struct counter_device *counter, ··· 130 127 131 128 static int interrupt_cnt_signal_read(struct counter_device *counter, 132 129 struct counter_signal *signal, 133 - enum counter_signal_value *val) 130 + enum counter_signal_level *level) 134 131 { 135 132 struct interrupt_cnt_priv *priv = counter->priv; 136 133 int ret; ··· 142 139 if (ret < 0) 143 140 return ret; 144 141 145 - *val = ret ? COUNTER_SIGNAL_HIGH : COUNTER_SIGNAL_LOW; 142 + *level = ret ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW; 146 143 147 144 return 0; 148 145 }
+11 -5
drivers/counter/microchip-tcb-capture.c
··· 37 37 MCHP_TC_FUNCTION_QUADRATURE, 38 38 }; 39 39 40 - static const enum counter_count_function mchp_tc_count_functions[] = { 41 - [MCHP_TC_FUNCTION_INCREASE] = COUNTER_COUNT_FUNCTION_INCREASE, 42 - [MCHP_TC_FUNCTION_QUADRATURE] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4, 40 + static const enum counter_function mchp_tc_count_functions[] = { 41 + [MCHP_TC_FUNCTION_INCREASE] = COUNTER_FUNCTION_INCREASE, 42 + [MCHP_TC_FUNCTION_QUADRATURE] = COUNTER_FUNCTION_QUADRATURE_X4, 43 43 }; 44 44 45 45 enum mchp_tc_synapse_action { ··· 133 133 bmr |= ATMEL_TC_QDEN | ATMEL_TC_POSEN; 134 134 cmr |= ATMEL_TC_ETRGEDG_RISING | ATMEL_TC_ABETRG | ATMEL_TC_XC0; 135 135 break; 136 + default: 137 + /* should never reach this path */ 138 + return -EINVAL; 136 139 } 137 140 138 141 regmap_write(priv->regmap, ATMEL_TC_BMR, bmr); ··· 158 155 159 156 static int mchp_tc_count_signal_read(struct counter_device *counter, 160 157 struct counter_signal *signal, 161 - enum counter_signal_value *val) 158 + enum counter_signal_level *lvl) 162 159 { 163 160 struct mchp_tc_data *const priv = counter->priv; 164 161 bool sigstatus; ··· 171 168 else 172 169 sigstatus = (sr & ATMEL_TC_MTIOA); 173 170 174 - *val = sigstatus ? COUNTER_SIGNAL_HIGH : COUNTER_SIGNAL_LOW; 171 + *lvl = sigstatus ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW; 175 172 176 173 return 0; 177 174 } ··· 229 226 case MCHP_TC_SYNAPSE_ACTION_BOTH_EDGE: 230 227 edge = ATMEL_TC_ETRGEDG_BOTH; 231 228 break; 229 + default: 230 + /* should never reach this path */ 231 + return -EINVAL; 232 232 } 233 233 234 234 return regmap_write_bits(priv->regmap,
+10 -8
drivers/counter/stm32-lptimer-cnt.c
··· 134 134 STM32_LPTIM_ENCODER_BOTH_EDGE, 135 135 }; 136 136 137 - static const enum counter_count_function stm32_lptim_cnt_functions[] = { 138 - [STM32_LPTIM_COUNTER_INCREASE] = COUNTER_COUNT_FUNCTION_INCREASE, 139 - [STM32_LPTIM_ENCODER_BOTH_EDGE] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4, 137 + static const enum counter_function stm32_lptim_cnt_functions[] = { 138 + [STM32_LPTIM_COUNTER_INCREASE] = COUNTER_FUNCTION_INCREASE, 139 + [STM32_LPTIM_ENCODER_BOTH_EDGE] = COUNTER_FUNCTION_QUADRATURE_X4, 140 140 }; 141 141 142 142 enum stm32_lptim_synapse_action { ··· 206 206 priv->quadrature_mode = 1; 207 207 priv->polarity = STM32_LPTIM_SYNAPSE_ACTION_BOTH_EDGES; 208 208 return 0; 209 + default: 210 + /* should never reach this path */ 211 + return -EINVAL; 209 212 } 210 - 211 - return -EINVAL; 212 213 } 213 214 214 215 static ssize_t stm32_lptim_cnt_enable_read(struct counter_device *counter, ··· 283 282 return ret; 284 283 285 284 if (ceiling > STM32_LPTIM_MAX_ARR) 286 - return -EINVAL; 285 + return -ERANGE; 287 286 288 287 priv->ceiling = ceiling; 289 288 ··· 327 326 case STM32_LPTIM_ENCODER_BOTH_EDGE: 328 327 *action = priv->polarity; 329 328 return 0; 329 + default: 330 + /* should never reach this path */ 331 + return -EINVAL; 330 332 } 331 - 332 - return -EINVAL; 333 333 } 334 334 335 335 static int stm32_lptim_cnt_action_set(struct counter_device *counter,
+5 -5
drivers/counter/stm32-timer-cnt.c
··· 50 50 STM32_COUNT_ENCODER_MODE_3, 51 51 }; 52 52 53 - static const enum counter_count_function stm32_count_functions[] = { 54 - [STM32_COUNT_SLAVE_MODE_DISABLED] = COUNTER_COUNT_FUNCTION_INCREASE, 55 - [STM32_COUNT_ENCODER_MODE_1] = COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A, 56 - [STM32_COUNT_ENCODER_MODE_2] = COUNTER_COUNT_FUNCTION_QUADRATURE_X2_B, 57 - [STM32_COUNT_ENCODER_MODE_3] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4, 53 + static const enum counter_function stm32_count_functions[] = { 54 + [STM32_COUNT_SLAVE_MODE_DISABLED] = COUNTER_FUNCTION_INCREASE, 55 + [STM32_COUNT_ENCODER_MODE_1] = COUNTER_FUNCTION_QUADRATURE_X2_A, 56 + [STM32_COUNT_ENCODER_MODE_2] = COUNTER_FUNCTION_QUADRATURE_X2_B, 57 + [STM32_COUNT_ENCODER_MODE_3] = COUNTER_FUNCTION_QUADRATURE_X4, 58 58 }; 59 59 60 60 static int stm32_count_read(struct counter_device *counter,
+21 -16
drivers/counter/ti-eqep.c
··· 157 157 * QEPA and QEPB trigger QCLK. 158 158 */ 159 159 *action = TI_EQEP_SYNAPSE_ACTION_BOTH_EDGES; 160 - break; 160 + return 0; 161 161 case TI_EQEP_COUNT_FUNC_DIR_COUNT: 162 162 /* In direction-count mode only rising edge of QEPA is counted 163 163 * and QEPB gives direction. ··· 165 165 switch (synapse->signal->id) { 166 166 case TI_EQEP_SIGNAL_QEPA: 167 167 *action = TI_EQEP_SYNAPSE_ACTION_RISING_EDGE; 168 - break; 169 - default: 168 + return 0; 169 + case TI_EQEP_SIGNAL_QEPB: 170 170 *action = TI_EQEP_SYNAPSE_ACTION_NONE; 171 - break; 171 + return 0; 172 + default: 173 + /* should never reach this path */ 174 + return -EINVAL; 172 175 } 173 - break; 174 176 case TI_EQEP_COUNT_FUNC_UP_COUNT: 175 177 case TI_EQEP_COUNT_FUNC_DOWN_COUNT: 176 178 /* In up/down-count modes only QEPA is counted and QEPB is not ··· 188 186 *action = TI_EQEP_SYNAPSE_ACTION_BOTH_EDGES; 189 187 else 190 188 *action = TI_EQEP_SYNAPSE_ACTION_RISING_EDGE; 191 - break; 192 - default: 189 + return 0; 190 + case TI_EQEP_SIGNAL_QEPB: 193 191 *action = TI_EQEP_SYNAPSE_ACTION_NONE; 194 - break; 192 + return 0; 193 + default: 194 + /* should never reach this path */ 195 + return -EINVAL; 195 196 } 196 - break; 197 + default: 198 + /* should never reach this path */ 199 + return -EINVAL; 197 200 } 198 - 199 - return 0; 200 201 } 201 202 202 203 static const struct counter_ops ti_eqep_counter_ops = { ··· 294 289 }, 295 290 }; 296 291 297 - static const enum counter_count_function ti_eqep_position_functions[] = { 298 - [TI_EQEP_COUNT_FUNC_QUAD_COUNT] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4, 299 - [TI_EQEP_COUNT_FUNC_DIR_COUNT] = COUNTER_COUNT_FUNCTION_PULSE_DIRECTION, 300 - [TI_EQEP_COUNT_FUNC_UP_COUNT] = COUNTER_COUNT_FUNCTION_INCREASE, 301 - [TI_EQEP_COUNT_FUNC_DOWN_COUNT] = COUNTER_COUNT_FUNCTION_DECREASE, 292 + static const enum counter_function ti_eqep_position_functions[] = { 293 + [TI_EQEP_COUNT_FUNC_QUAD_COUNT] = COUNTER_FUNCTION_QUADRATURE_X4, 294 + [TI_EQEP_COUNT_FUNC_DIR_COUNT] = COUNTER_FUNCTION_PULSE_DIRECTION, 295 + [TI_EQEP_COUNT_FUNC_UP_COUNT] = COUNTER_FUNCTION_INCREASE, 296 + [TI_EQEP_COUNT_FUNC_DOWN_COUNT] = COUNTER_FUNCTION_DECREASE, 302 297 }; 303 298 304 299 static const enum counter_synapse_action ti_eqep_position_synapse_actions[] = {
+3 -2
drivers/iio/accel/Kconfig
··· 143 143 select BMC150_ACCEL_SPI if SPI 144 144 help 145 145 Say yes here to build support for the following Bosch accelerometers: 146 - BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMI055. 146 + BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMC156 147 + BMI055. 147 148 148 149 Note that some of these are combo modules: 149 - - BMC150: accelerometer and magnetometer 150 + - BMC150/BMC156: accelerometer and magnetometer 150 151 - BMI055: accelerometer and gyroscope 151 152 152 153 This driver is only implementing accelerometer part, which has
-1
drivers/iio/accel/adxl345.h
··· 15 15 16 16 int adxl345_core_probe(struct device *dev, struct regmap *regmap, 17 17 enum adxl345_device_type type, const char *name); 18 - int adxl345_core_remove(struct device *dev); 19 18 20 19 #endif /* _ADXL345_H_ */
+9 -20
drivers/iio/accel/adxl345_core.c
··· 208 208 .write_raw_get_fmt = adxl345_write_raw_get_fmt, 209 209 }; 210 210 211 + static void adxl345_powerdown(void *regmap) 212 + { 213 + regmap_write(regmap, ADXL345_REG_POWER_CTL, ADXL345_POWER_CTL_STANDBY); 214 + } 215 + 211 216 int adxl345_core_probe(struct device *dev, struct regmap *regmap, 212 217 enum adxl345_device_type type, const char *name) 213 218 { ··· 238 233 return -ENOMEM; 239 234 240 235 data = iio_priv(indio_dev); 241 - dev_set_drvdata(dev, indio_dev); 242 236 data->regmap = regmap; 243 237 data->type = type; 244 238 /* Enable full-resolution mode */ ··· 264 260 return ret; 265 261 } 266 262 267 - ret = iio_device_register(indio_dev); 268 - if (ret < 0) { 269 - dev_err(dev, "iio_device_register failed: %d\n", ret); 270 - regmap_write(data->regmap, ADXL345_REG_POWER_CTL, 271 - ADXL345_POWER_CTL_STANDBY); 272 - } 263 + ret = devm_add_action_or_reset(dev, adxl345_powerdown, data->regmap); 264 + if (ret < 0) 265 + return ret; 273 266 274 - return ret; 267 + return devm_iio_device_register(dev, indio_dev); 275 268 } 276 269 EXPORT_SYMBOL_GPL(adxl345_core_probe); 277 - 278 - int adxl345_core_remove(struct device *dev) 279 - { 280 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 281 - struct adxl345_data *data = iio_priv(indio_dev); 282 - 283 - iio_device_unregister(indio_dev); 284 - 285 - return regmap_write(data->regmap, ADXL345_REG_POWER_CTL, 286 - ADXL345_POWER_CTL_STANDBY); 287 - } 288 - EXPORT_SYMBOL_GPL(adxl345_core_remove); 289 270 290 271 MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>"); 291 272 MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer core driver");
-6
drivers/iio/accel/adxl345_i2c.c
··· 38 38 id->name); 39 39 } 40 40 41 - static int adxl345_i2c_remove(struct i2c_client *client) 42 - { 43 - return adxl345_core_remove(&client->dev); 44 - } 45 - 46 41 static const struct i2c_device_id adxl345_i2c_id[] = { 47 42 { "adxl345", ADXL345 }, 48 43 { "adxl375", ADXL375 }, ··· 60 65 .of_match_table = adxl345_of_match, 61 66 }, 62 67 .probe = adxl345_i2c_probe, 63 - .remove = adxl345_i2c_remove, 64 68 .id_table = adxl345_i2c_id, 65 69 }; 66 70
-6
drivers/iio/accel/adxl345_spi.c
··· 42 42 return adxl345_core_probe(&spi->dev, regmap, id->driver_data, id->name); 43 43 } 44 44 45 - static int adxl345_spi_remove(struct spi_device *spi) 46 - { 47 - return adxl345_core_remove(&spi->dev); 48 - } 49 - 50 45 static const struct spi_device_id adxl345_spi_id[] = { 51 46 { "adxl345", ADXL345 }, 52 47 { "adxl375", ADXL375 }, ··· 64 69 .of_match_table = adxl345_of_match, 65 70 }, 66 71 .probe = adxl345_spi_probe, 67 - .remove = adxl345_spi_remove, 68 72 .id_table = adxl345_spi_id, 69 73 }; 70 74
+36 -41
drivers/iio/accel/bma220_spi.c
··· 218 218 return 0; 219 219 } 220 220 221 - static int bma220_deinit(struct spi_device *spi) 221 + static int bma220_power(struct spi_device *spi, bool up) 222 222 { 223 - int ret; 223 + int i, ret; 224 224 225 - /* Make sure the chip is powered off */ 226 - ret = bma220_read_reg(spi, BMA220_REG_SUSPEND); 227 - if (ret == BMA220_SUSPEND_SLEEP) 225 + /** 226 + * The chip can be suspended/woken up by a simple register read. 227 + * So, we need up to 2 register reads of the suspend register 228 + * to make sure that the device is in the desired state. 229 + */ 230 + for (i = 0; i < 2; i++) { 228 231 ret = bma220_read_reg(spi, BMA220_REG_SUSPEND); 229 - if (ret < 0) 230 - return ret; 231 - if (ret == BMA220_SUSPEND_SLEEP) 232 - return -EBUSY; 232 + if (ret < 0) 233 + return ret; 233 234 234 - return 0; 235 + if (up && ret == BMA220_SUSPEND_SLEEP) 236 + return 0; 237 + 238 + if (!up && ret == BMA220_SUSPEND_WAKE) 239 + return 0; 240 + } 241 + 242 + return -EBUSY; 243 + } 244 + 245 + static void bma220_deinit(void *spi) 246 + { 247 + bma220_power(spi, false); 235 248 } 236 249 237 250 static int bma220_probe(struct spi_device *spi) ··· 261 248 262 249 data = iio_priv(indio_dev); 263 250 data->spi_device = spi; 264 - spi_set_drvdata(spi, indio_dev); 265 251 mutex_init(&data->lock); 266 252 267 253 indio_dev->info = &bma220_info; ··· 274 262 if (ret) 275 263 return ret; 276 264 277 - ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time, 278 - bma220_trigger_handler, NULL); 265 + ret = devm_add_action_or_reset(&spi->dev, bma220_deinit, spi); 266 + if (ret) 267 + return ret; 268 + 269 + ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, 270 + iio_pollfunc_store_time, 271 + bma220_trigger_handler, NULL); 279 272 if (ret < 0) { 280 273 dev_err(&spi->dev, "iio triggered buffer setup failed\n"); 281 - goto err_suspend; 274 + return ret; 282 275 } 283 276 284 - ret = iio_device_register(indio_dev); 285 - if (ret < 0) { 286 - dev_err(&spi->dev, "iio_device_register failed\n"); 287 - iio_triggered_buffer_cleanup(indio_dev); 288 - goto err_suspend; 289 - } 290 - 291 - return 0; 292 - 293 - err_suspend: 294 - return bma220_deinit(spi); 295 - } 296 - 297 - static int bma220_remove(struct spi_device *spi) 298 - { 299 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 300 - 301 - iio_device_unregister(indio_dev); 302 - iio_triggered_buffer_cleanup(indio_dev); 303 - 304 - return bma220_deinit(spi); 277 + return devm_iio_device_register(&spi->dev, indio_dev); 305 278 } 306 279 307 280 static __maybe_unused int bma220_suspend(struct device *dev) 308 281 { 309 - struct bma220_data *data = iio_priv(dev_get_drvdata(dev)); 282 + struct spi_device *spi = to_spi_device(dev); 310 283 311 - /* The chip can be suspended/woken up by a simple register read. */ 312 - return bma220_read_reg(data->spi_device, BMA220_REG_SUSPEND); 284 + return bma220_power(spi, false); 313 285 } 314 286 315 287 static __maybe_unused int bma220_resume(struct device *dev) 316 288 { 317 - struct bma220_data *data = iio_priv(dev_get_drvdata(dev)); 289 + struct spi_device *spi = to_spi_device(dev); 318 290 319 - return bma220_read_reg(data->spi_device, BMA220_REG_SUSPEND); 291 + return bma220_power(spi, true); 320 292 } 321 293 static SIMPLE_DEV_PM_OPS(bma220_pm_ops, bma220_suspend, bma220_resume); 322 294 ··· 322 326 .acpi_match_table = bma220_acpi_id, 323 327 }, 324 328 .probe = bma220_probe, 325 - .remove = bma220_remove, 326 329 .id_table = bma220_spi_id, 327 330 }; 328 331 module_spi_driver(bma220_driver);
+64 -14
drivers/iio/accel/bmc150-accel-core.c
··· 10 10 #include <linux/delay.h> 11 11 #include <linux/slab.h> 12 12 #include <linux/acpi.h> 13 + #include <linux/of_irq.h> 13 14 #include <linux/pm.h> 14 15 #include <linux/pm_runtime.h> 15 16 #include <linux/iio/iio.h> ··· 58 57 #define BMC150_ACCEL_RESET_VAL 0xB6 59 58 60 59 #define BMC150_ACCEL_REG_INT_MAP_0 0x19 61 - #define BMC150_ACCEL_INT_MAP_0_BIT_SLOPE BIT(2) 60 + #define BMC150_ACCEL_INT_MAP_0_BIT_INT1_SLOPE BIT(2) 62 61 63 62 #define BMC150_ACCEL_REG_INT_MAP_1 0x1A 64 - #define BMC150_ACCEL_INT_MAP_1_BIT_DATA BIT(0) 65 - #define BMC150_ACCEL_INT_MAP_1_BIT_FWM BIT(1) 66 - #define BMC150_ACCEL_INT_MAP_1_BIT_FFULL BIT(2) 63 + #define BMC150_ACCEL_INT_MAP_1_BIT_INT1_DATA BIT(0) 64 + #define BMC150_ACCEL_INT_MAP_1_BIT_INT1_FWM BIT(1) 65 + #define BMC150_ACCEL_INT_MAP_1_BIT_INT1_FFULL BIT(2) 66 + #define BMC150_ACCEL_INT_MAP_1_BIT_INT2_FFULL BIT(5) 67 + #define BMC150_ACCEL_INT_MAP_1_BIT_INT2_FWM BIT(6) 68 + #define BMC150_ACCEL_INT_MAP_1_BIT_INT2_DATA BIT(7) 69 + 70 + #define BMC150_ACCEL_REG_INT_MAP_2 0x1B 71 + #define BMC150_ACCEL_INT_MAP_2_BIT_INT2_SLOPE BIT(2) 67 72 68 73 #define BMC150_ACCEL_REG_INT_RST_LATCH 0x21 69 74 #define BMC150_ACCEL_INT_MODE_LATCH_RESET 0x80 ··· 88 81 89 82 #define BMC150_ACCEL_REG_INT_OUT_CTRL 0x20 90 83 #define BMC150_ACCEL_INT_OUT_CTRL_INT1_LVL BIT(0) 84 + #define BMC150_ACCEL_INT_OUT_CTRL_INT2_LVL BIT(2) 91 85 92 86 #define BMC150_ACCEL_REG_INT_5 0x27 93 87 #define BMC150_ACCEL_SLOPE_DUR_MASK 0x03 ··· 484 476 } 485 477 #endif 486 478 487 - static const struct bmc150_accel_interrupt_info { 479 + struct bmc150_accel_interrupt_info { 488 480 u8 map_reg; 489 481 u8 map_bitmask; 490 482 u8 en_reg; 491 483 u8 en_bitmask; 492 - } bmc150_accel_interrupts[BMC150_ACCEL_INTERRUPTS] = { 484 + }; 485 + 486 + static const struct bmc150_accel_interrupt_info 487 + bmc150_accel_interrupts_int1[BMC150_ACCEL_INTERRUPTS] = { 493 488 { /* data ready interrupt */ 494 489 .map_reg = BMC150_ACCEL_REG_INT_MAP_1, 495 - .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_DATA, 490 + .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT1_DATA, 496 491 .en_reg = BMC150_ACCEL_REG_INT_EN_1, 497 492 .en_bitmask = BMC150_ACCEL_INT_EN_BIT_DATA_EN, 498 493 }, 499 494 { /* motion interrupt */ 500 495 .map_reg = BMC150_ACCEL_REG_INT_MAP_0, 501 - .map_bitmask = BMC150_ACCEL_INT_MAP_0_BIT_SLOPE, 496 + .map_bitmask = BMC150_ACCEL_INT_MAP_0_BIT_INT1_SLOPE, 502 497 .en_reg = BMC150_ACCEL_REG_INT_EN_0, 503 498 .en_bitmask = BMC150_ACCEL_INT_EN_BIT_SLP_X | 504 499 BMC150_ACCEL_INT_EN_BIT_SLP_Y | ··· 509 498 }, 510 499 { /* fifo watermark interrupt */ 511 500 .map_reg = BMC150_ACCEL_REG_INT_MAP_1, 512 - .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_FWM, 501 + .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT1_FWM, 502 + .en_reg = BMC150_ACCEL_REG_INT_EN_1, 503 + .en_bitmask = BMC150_ACCEL_INT_EN_BIT_FWM_EN, 504 + }, 505 + }; 506 + 507 + static const struct bmc150_accel_interrupt_info 508 + bmc150_accel_interrupts_int2[BMC150_ACCEL_INTERRUPTS] = { 509 + { /* data ready interrupt */ 510 + .map_reg = BMC150_ACCEL_REG_INT_MAP_1, 511 + .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT2_DATA, 512 + .en_reg = BMC150_ACCEL_REG_INT_EN_1, 513 + .en_bitmask = BMC150_ACCEL_INT_EN_BIT_DATA_EN, 514 + }, 515 + { /* motion interrupt */ 516 + .map_reg = BMC150_ACCEL_REG_INT_MAP_2, 517 + .map_bitmask = BMC150_ACCEL_INT_MAP_2_BIT_INT2_SLOPE, 518 + .en_reg = BMC150_ACCEL_REG_INT_EN_0, 519 + .en_bitmask = BMC150_ACCEL_INT_EN_BIT_SLP_X | 520 + BMC150_ACCEL_INT_EN_BIT_SLP_Y | 521 + BMC150_ACCEL_INT_EN_BIT_SLP_Z 522 + }, 523 + { /* fifo watermark interrupt */ 524 + .map_reg = BMC150_ACCEL_REG_INT_MAP_1, 525 + .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT2_FWM, 513 526 .en_reg = BMC150_ACCEL_REG_INT_EN_1, 514 527 .en_bitmask = BMC150_ACCEL_INT_EN_BIT_FWM_EN, 515 528 }, 516 529 }; 517 530 518 531 static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev, 519 - struct bmc150_accel_data *data) 532 + struct bmc150_accel_data *data, int irq) 520 533 { 534 + const struct bmc150_accel_interrupt_info *irq_info = NULL; 535 + struct device *dev = regmap_get_device(data->regmap); 521 536 int i; 522 537 538 + /* 539 + * For now we map all interrupts to the same output pin. 540 + * However, some boards may have just INT2 (and not INT1) connected, 541 + * so we try to detect which IRQ it is based on the interrupt-names. 542 + * Without interrupt-names, we assume the irq belongs to INT1. 543 + */ 544 + irq_info = bmc150_accel_interrupts_int1; 545 + if (data->type == BOSCH_BMC156 || 546 + irq == of_irq_get_byname(dev->of_node, "INT2")) 547 + irq_info = bmc150_accel_interrupts_int2; 548 + 523 549 for (i = 0; i < BMC150_ACCEL_INTERRUPTS; i++) 524 - data->interrupts[i].info = &bmc150_accel_interrupts[i]; 550 + data->interrupts[i].info = &irq_info[i]; 525 551 } 526 552 527 553 static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i, ··· 1175 1127 {306458, BMC150_ACCEL_DEF_RANGE_16G} }, 1176 1128 }, 1177 1129 { 1178 - .name = "BMA253/BMA254/BMA255/BMC150/BMI055", 1130 + .name = "BMA253/BMA254/BMA255/BMC150/BMC156/BMI055", 1179 1131 .chip_id = 0xFA, 1180 1132 .channels = bmc150_accel_channels, 1181 1133 .num_channels = ARRAY_SIZE(bmc150_accel_channels), ··· 1662 1614 } 1663 1615 1664 1616 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, 1665 - const char *name, bool block_supported) 1617 + enum bmc150_type type, const char *name, 1618 + bool block_supported) 1666 1619 { 1667 1620 const struct attribute **fifo_attrs; 1668 1621 struct bmc150_accel_data *data; ··· 1678 1629 dev_set_drvdata(dev, indio_dev); 1679 1630 1680 1631 data->regmap = regmap; 1632 + data->type = type; 1681 1633 1682 1634 if (!bmc150_apply_acpi_orientation(dev, &data->orientation)) { 1683 1635 ret = iio_read_mount_matrix(dev, &data->orientation); ··· 1764 1714 goto err_buffer_cleanup; 1765 1715 } 1766 1716 1767 - bmc150_accel_interrupts_setup(indio_dev, data); 1717 + bmc150_accel_interrupts_setup(indio_dev, data, irq); 1768 1718 1769 1719 ret = bmc150_accel_triggers_setup(indio_dev, data); 1770 1720 if (ret)
+8 -2
drivers/iio/accel/bmc150-accel-i2c.c
··· 176 176 { 177 177 struct regmap *regmap; 178 178 const char *name = NULL; 179 + enum bmc150_type type = BOSCH_UNKNOWN; 179 180 bool block_supported = 180 181 i2c_check_functionality(client->adapter, I2C_FUNC_I2C) || 181 182 i2c_check_functionality(client->adapter, ··· 189 188 return PTR_ERR(regmap); 190 189 } 191 190 192 - if (id) 191 + if (id) { 193 192 name = id->name; 193 + type = id->driver_data; 194 + } 194 195 195 - ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq, name, block_supported); 196 + ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq, 197 + type, name, block_supported); 196 198 if (ret) 197 199 return ret; 198 200 ··· 240 236 {"bma255"}, 241 237 {"bma280"}, 242 238 {"bmc150_accel"}, 239 + {"bmc156_accel", BOSCH_BMC156}, 243 240 {"bmi055_accel"}, 244 241 {} 245 242 }; ··· 256 251 { .compatible = "bosch,bma255" }, 257 252 { .compatible = "bosch,bma280" }, 258 253 { .compatible = "bosch,bmc150_accel" }, 254 + { .compatible = "bosch,bmc156_accel" }, 259 255 { .compatible = "bosch,bmi055_accel" }, 260 256 { }, 261 257 };
+9 -1
drivers/iio/accel/bmc150-accel-spi.c
··· 16 16 static int bmc150_accel_probe(struct spi_device *spi) 17 17 { 18 18 struct regmap *regmap; 19 + const char *name = NULL; 20 + enum bmc150_type type = BOSCH_UNKNOWN; 19 21 const struct spi_device_id *id = spi_get_device_id(spi); 20 22 21 23 regmap = devm_regmap_init_spi(spi, &bmc150_regmap_conf); ··· 26 24 return PTR_ERR(regmap); 27 25 } 28 26 29 - return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, id->name, 27 + if (id) { 28 + name = id->name; 29 + type = id->driver_data; 30 + } 31 + 32 + return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, type, name, 30 33 true); 31 34 } 32 35 ··· 61 54 {"bma255"}, 62 55 {"bma280"}, 63 56 {"bmc150_accel"}, 57 + {"bmc156_accel", BOSCH_BMC156}, 64 58 {"bmi055_accel"}, 65 59 {} 66 60 };
+19 -1
drivers/iio/accel/bmc150-accel.h
··· 13 13 struct bmc150_accel_chip_info; 14 14 struct bmc150_accel_interrupt_info; 15 15 16 + /* 17 + * We can often guess better than "UNKNOWN" based on the device IDs 18 + * but unfortunately this information is not always accurate. There are some 19 + * devices where ACPI firmware specifies an ID like "BMA250E" when the device 20 + * actually has a BMA222E. The driver attempts to detect those by reading the 21 + * chip ID from the registers but this information is not always enough either. 22 + * 23 + * Therefore, this enum should be only used when the chip ID detection is not 24 + * enough and we can be reasonably sure that the device IDs are reliable 25 + * in practice (e.g. for device tree platforms). 26 + */ 27 + enum bmc150_type { 28 + BOSCH_UNKNOWN, 29 + BOSCH_BMC156, 30 + }; 31 + 16 32 struct bmc150_accel_interrupt { 17 33 const struct bmc150_accel_interrupt_info *info; 18 34 atomic_t users; ··· 78 62 int ev_enable_state; 79 63 int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */ 80 64 const struct bmc150_accel_chip_info *chip_info; 65 + enum bmc150_type type; 81 66 struct i2c_client *second_device; 82 67 void (*resume_callback)(struct device *dev); 83 68 struct delayed_work resume_work; ··· 86 69 }; 87 70 88 71 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, 89 - const char *name, bool block_supported); 72 + enum bmc150_type type, const char *name, 73 + bool block_supported); 90 74 int bmc150_accel_core_remove(struct device *dev); 91 75 extern const struct dev_pm_ops bmc150_accel_pm_ops; 92 76 extern const struct regmap_config bmc150_regmap_conf;
+9 -17
drivers/iio/accel/da280.c
··· 100 100 return (enum da280_chipset) id->driver_data; 101 101 } 102 102 103 + static void da280_disable(void *client) 104 + { 105 + da280_enable(client, false); 106 + } 107 + 103 108 static int da280_probe(struct i2c_client *client, 104 109 const struct i2c_device_id *id) 105 110 { ··· 123 118 124 119 data = iio_priv(indio_dev); 125 120 data->client = client; 126 - i2c_set_clientdata(client, indio_dev); 127 121 128 122 indio_dev->info = &da280_info; 129 123 indio_dev->modes = INDIO_DIRECT_MODE; ··· 146 142 if (ret < 0) 147 143 return ret; 148 144 149 - ret = iio_device_register(indio_dev); 150 - if (ret < 0) { 151 - dev_err(&client->dev, "device_register failed\n"); 152 - da280_enable(client, false); 153 - } 145 + ret = devm_add_action_or_reset(&client->dev, da280_disable, client); 146 + if (ret) 147 + return ret; 154 148 155 - return ret; 156 - } 157 - 158 - static int da280_remove(struct i2c_client *client) 159 - { 160 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 161 - 162 - iio_device_unregister(indio_dev); 163 - 164 - return da280_enable(client, false); 149 + return devm_iio_device_register(&client->dev, indio_dev); 165 150 } 166 151 167 152 #ifdef CONFIG_PM_SLEEP ··· 187 194 .pm = &da280_pm_ops, 188 195 }, 189 196 .probe = da280_probe, 190 - .remove = da280_remove, 191 197 .id_table = da280_i2c_id, 192 198 }; 193 199
+9 -17
drivers/iio/accel/da311.c
··· 212 212 .read_raw = da311_read_raw, 213 213 }; 214 214 215 + static void da311_disable(void *client) 216 + { 217 + da311_enable(client, false); 218 + } 219 + 215 220 static int da311_probe(struct i2c_client *client, 216 221 const struct i2c_device_id *id) 217 222 { ··· 234 229 235 230 data = iio_priv(indio_dev); 236 231 data->client = client; 237 - i2c_set_clientdata(client, indio_dev); 238 232 239 233 indio_dev->info = &da311_info; 240 234 indio_dev->name = "da311"; ··· 249 245 if (ret < 0) 250 246 return ret; 251 247 252 - ret = iio_device_register(indio_dev); 253 - if (ret < 0) { 254 - dev_err(&client->dev, "device_register failed\n"); 255 - da311_enable(client, false); 256 - } 248 + ret = devm_add_action_or_reset(&client->dev, da311_disable, client); 249 + if (ret) 250 + return ret; 257 251 258 - return ret; 259 - } 260 - 261 - static int da311_remove(struct i2c_client *client) 262 - { 263 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 264 - 265 - iio_device_unregister(indio_dev); 266 - 267 - return da311_enable(client, false); 252 + return devm_iio_device_register(&client->dev, indio_dev); 268 253 } 269 254 270 255 #ifdef CONFIG_PM_SLEEP ··· 282 289 .pm = &da311_pm_ops, 283 290 }, 284 291 .probe = da311_probe, 285 - .remove = da311_remove, 286 292 .id_table = da311_i2c_id, 287 293 }; 288 294
+10 -17
drivers/iio/accel/dmard10.c
··· 170 170 .read_raw = dmard10_read_raw, 171 171 }; 172 172 173 + static void dmard10_shutdown_cleanup(void *client) 174 + { 175 + dmard10_shutdown(client); 176 + } 177 + 173 178 static int dmard10_probe(struct i2c_client *client, 174 179 const struct i2c_device_id *id) 175 180 { ··· 199 194 200 195 data = iio_priv(indio_dev); 201 196 data->client = client; 202 - i2c_set_clientdata(client, indio_dev); 203 197 204 198 indio_dev->info = &dmard10_info; 205 199 indio_dev->name = "dmard10"; ··· 210 206 if (ret < 0) 211 207 return ret; 212 208 213 - ret = iio_device_register(indio_dev); 214 - if (ret < 0) { 215 - dev_err(&client->dev, "device_register failed\n"); 216 - dmard10_shutdown(client); 217 - } 209 + ret = devm_add_action_or_reset(&client->dev, dmard10_shutdown_cleanup, 210 + client); 211 + if (ret) 212 + return ret; 218 213 219 - return ret; 220 - } 221 - 222 - static int dmard10_remove(struct i2c_client *client) 223 - { 224 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 225 - 226 - iio_device_unregister(indio_dev); 227 - 228 - return dmard10_shutdown(client); 214 + return devm_iio_device_register(&client->dev, indio_dev); 229 215 } 230 216 231 217 #ifdef CONFIG_PM_SLEEP ··· 244 250 .pm = &dmard10_pm_ops, 245 251 }, 246 252 .probe = dmard10_probe, 247 - .remove = dmard10_remove, 248 253 .id_table = dmard10_i2c_id, 249 254 }; 250 255
+4 -6
drivers/iio/accel/hid-sensor-accel-3d.c
··· 367 367 dev_err(&pdev->dev, "failed to setup common attributes\n"); 368 368 return ret; 369 369 } 370 - indio_dev->channels = kmemdup(channel_spec, channel_size, GFP_KERNEL); 370 + indio_dev->channels = devm_kmemdup(&pdev->dev, channel_spec, 371 + channel_size, GFP_KERNEL); 371 372 372 373 if (!indio_dev->channels) { 373 374 dev_err(&pdev->dev, "failed to duplicate channels\n"); ··· 379 378 hsdev->usage, accel_state); 380 379 if (ret) { 381 380 dev_err(&pdev->dev, "failed to setup attributes\n"); 382 - goto error_free_dev_mem; 381 + return ret; 383 382 } 384 383 385 384 indio_dev->info = &accel_3d_info; ··· 392 391 &accel_state->common_attributes); 393 392 if (ret < 0) { 394 393 dev_err(&pdev->dev, "trigger setup failed\n"); 395 - goto error_free_dev_mem; 394 + return ret; 396 395 } 397 396 398 397 ret = iio_device_register(indio_dev); ··· 417 416 iio_device_unregister(indio_dev); 418 417 error_remove_trigger: 419 418 hid_sensor_remove_trigger(indio_dev, &accel_state->common_attributes); 420 - error_free_dev_mem: 421 - kfree(indio_dev->channels); 422 419 return ret; 423 420 } 424 421 ··· 430 431 sensor_hub_remove_callback(hsdev, hsdev->usage); 431 432 iio_device_unregister(indio_dev); 432 433 hid_sensor_remove_trigger(indio_dev, &accel_state->common_attributes); 433 - kfree(indio_dev->channels); 434 434 435 435 return 0; 436 436 }
-4
drivers/iio/accel/st_accel.h
··· 64 64 65 65 #ifdef CONFIG_IIO_BUFFER 66 66 int st_accel_allocate_ring(struct iio_dev *indio_dev); 67 - void st_accel_deallocate_ring(struct iio_dev *indio_dev); 68 67 int st_accel_trig_set_state(struct iio_trigger *trig, bool state); 69 68 #define ST_ACCEL_TRIGGER_SET_STATE (&st_accel_trig_set_state) 70 69 #else /* CONFIG_IIO_BUFFER */ 71 70 static inline int st_accel_allocate_ring(struct iio_dev *indio_dev) 72 71 { 73 72 return 0; 74 - } 75 - static inline void st_accel_deallocate_ring(struct iio_dev *indio_dev) 76 - { 77 73 } 78 74 #define ST_ACCEL_TRIGGER_SET_STATE NULL 79 75 #endif /* CONFIG_IIO_BUFFER */
+3 -13
drivers/iio/accel/st_accel_buffer.c
··· 9 9 10 10 #include <linux/module.h> 11 11 #include <linux/kernel.h> 12 - #include <linux/slab.h> 13 - #include <linux/stat.h> 14 - #include <linux/interrupt.h> 15 - #include <linux/i2c.h> 16 - #include <linux/delay.h> 17 12 #include <linux/iio/iio.h> 18 13 #include <linux/iio/buffer.h> 19 - #include <linux/iio/trigger_consumer.h> 14 + #include <linux/iio/trigger.h> 20 15 #include <linux/iio/triggered_buffer.h> 21 16 22 17 #include <linux/iio/common/st_sensors.h> ··· 62 67 63 68 int st_accel_allocate_ring(struct iio_dev *indio_dev) 64 69 { 65 - return iio_triggered_buffer_setup(indio_dev, NULL, 66 - &st_sensors_trigger_handler, &st_accel_buffer_setup_ops); 67 - } 68 - 69 - void st_accel_deallocate_ring(struct iio_dev *indio_dev) 70 - { 71 - iio_triggered_buffer_cleanup(indio_dev); 70 + return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev, 71 + NULL, &st_sensors_trigger_handler, &st_accel_buffer_setup_ops); 72 72 } 73 73 74 74 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+3 -11
drivers/iio/accel/st_accel_core.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 + #include <linux/mutex.h> 13 + #include <linux/sysfs.h> 12 14 #include <linux/slab.h> 13 15 #include <linux/acpi.h> 14 - #include <linux/errno.h> 15 - #include <linux/types.h> 16 - #include <linux/interrupt.h> 17 - #include <linux/i2c.h> 18 - #include <linux/irq.h> 19 16 #include <linux/iio/iio.h> 20 17 #include <linux/iio/sysfs.h> 21 18 #include <linux/iio/trigger.h> 22 - #include <linux/iio/buffer.h> 23 19 24 20 #include <linux/iio/common/st_sensors.h> 25 21 #include "st_accel.h" ··· 1377 1381 err = st_sensors_allocate_trigger(indio_dev, 1378 1382 ST_ACCEL_TRIGGER_OPS); 1379 1383 if (err < 0) 1380 - goto st_accel_probe_trigger_error; 1384 + return err; 1381 1385 } 1382 1386 1383 1387 err = iio_device_register(indio_dev); ··· 1392 1396 st_accel_device_register_error: 1393 1397 if (adata->irq > 0) 1394 1398 st_sensors_deallocate_trigger(indio_dev); 1395 - st_accel_probe_trigger_error: 1396 - st_accel_deallocate_ring(indio_dev); 1397 1399 return err; 1398 1400 } 1399 1401 EXPORT_SYMBOL(st_accel_common_probe); ··· 1403 1409 iio_device_unregister(indio_dev); 1404 1410 if (adata->irq > 0) 1405 1411 st_sensors_deallocate_trigger(indio_dev); 1406 - 1407 - st_accel_deallocate_ring(indio_dev); 1408 1412 } 1409 1413 EXPORT_SYMBOL(st_accel_common_remove); 1410 1414
+1 -2
drivers/iio/accel/st_accel_i2c.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 12 + #include <linux/mod_devicetable.h> 13 13 #include <linux/acpi.h> 14 14 #include <linux/i2c.h> 15 15 #include <linux/iio/iio.h> 16 - #include <linux/property.h> 17 16 18 17 #include <linux/iio/common/st_sensors_i2c.h> 19 18 #include "st_accel.h"
+1 -1
drivers/iio/accel/st_accel_spi.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 12 + #include <linux/mod_devicetable.h> 13 13 #include <linux/spi/spi.h> 14 14 #include <linux/iio/iio.h> 15 15
+3 -3
drivers/iio/adc/ep93xx_adc.c
··· 205 205 */ 206 206 } 207 207 208 - ret = clk_enable(priv->clk); 208 + ret = clk_prepare_enable(priv->clk); 209 209 if (ret) { 210 210 dev_err(&pdev->dev, "Cannot enable clock\n"); 211 211 return ret; ··· 213 213 214 214 ret = iio_device_register(iiodev); 215 215 if (ret) 216 - clk_disable(priv->clk); 216 + clk_disable_unprepare(priv->clk); 217 217 218 218 return ret; 219 219 } ··· 224 224 struct ep93xx_adc_priv *priv = iio_priv(iiodev); 225 225 226 226 iio_device_unregister(iiodev); 227 - clk_disable(priv->clk); 227 + clk_disable_unprepare(priv->clk); 228 228 229 229 return 0; 230 230 }
+7 -10
drivers/iio/adc/fsl-imx25-gcq.c
··· 201 201 */ 202 202 priv->vref[MX25_ADC_REFP_INT] = NULL; 203 203 priv->vref[MX25_ADC_REFP_EXT] = 204 - devm_regulator_get_optional(&pdev->dev, "vref-ext"); 204 + devm_regulator_get_optional(dev, "vref-ext"); 205 205 priv->vref[MX25_ADC_REFP_XP] = 206 - devm_regulator_get_optional(&pdev->dev, "vref-xp"); 206 + devm_regulator_get_optional(dev, "vref-xp"); 207 207 priv->vref[MX25_ADC_REFP_YP] = 208 - devm_regulator_get_optional(&pdev->dev, "vref-yp"); 208 + devm_regulator_get_optional(dev, "vref-yp"); 209 209 210 210 for_each_child_of_node(np, child) { 211 211 u32 reg; ··· 307 307 int ret; 308 308 int i; 309 309 310 - indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv)); 310 + indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); 311 311 if (!indio_dev) 312 312 return -ENOMEM; 313 313 ··· 347 347 goto err_vref_disable; 348 348 } 349 349 350 - priv->irq = platform_get_irq(pdev, 0); 351 - if (priv->irq <= 0) { 352 - ret = priv->irq; 353 - if (!ret) 354 - ret = -ENXIO; 350 + ret = platform_get_irq(pdev, 0); 351 + if (ret < 0) 355 352 goto err_clk_unprepare; 356 - } 357 353 354 + priv->irq = ret; 358 355 ret = request_irq(priv->irq, mx25_gcq_irq, 0, pdev->name, priv); 359 356 if (ret) { 360 357 dev_err(dev, "Failed requesting IRQ\n");
+93 -9
drivers/iio/adc/ingenic-adc.c
··· 37 37 #define JZ_ADC_REG_CFG_SAMPLE_NUM(n) ((n) << 10) 38 38 #define JZ_ADC_REG_CFG_PULL_UP(n) ((n) << 16) 39 39 #define JZ_ADC_REG_CFG_CMD_SEL BIT(22) 40 + #define JZ_ADC_REG_CFG_VBAT_SEL BIT(30) 40 41 #define JZ_ADC_REG_CFG_TOUCH_OPS_MASK (BIT(31) | GENMASK(23, 10)) 41 42 #define JZ_ADC_REG_ADCLK_CLKDIV_LSB 0 42 43 #define JZ4725B_ADC_REG_ADCLK_CLKDIV10US_LSB 16 ··· 72 71 #define JZ4725B_ADC_BATTERY_HIGH_VREF_BITS 10 73 72 #define JZ4740_ADC_BATTERY_HIGH_VREF (7500 * 0.986) 74 73 #define JZ4740_ADC_BATTERY_HIGH_VREF_BITS 12 74 + #define JZ4760_ADC_BATTERY_VREF 2500 75 75 #define JZ4770_ADC_BATTERY_VREF 1200 76 76 #define JZ4770_ADC_BATTERY_VREF_BITS 12 77 77 ··· 94 92 const int *battery_scale_avail; 95 93 size_t battery_scale_avail_size; 96 94 unsigned int battery_vref_mode: 1; 97 - unsigned int has_aux2: 1; 95 + unsigned int has_aux_md: 1; 98 96 const struct iio_chan_spec *channels; 99 97 unsigned int num_channels; 100 98 int (*init_clk_div)(struct device *dev, struct ingenic_adc *adc); ··· 297 295 JZ_ADC_BATTERY_LOW_VREF, JZ_ADC_BATTERY_LOW_VREF_BITS, 298 296 }; 299 297 298 + static const int jz4760_adc_battery_scale_avail[] = { 299 + JZ4760_ADC_BATTERY_VREF, JZ4770_ADC_BATTERY_VREF_BITS, 300 + }; 301 + 300 302 static const int jz4770_adc_battery_raw_avail[] = { 301 303 0, 1, (1 << JZ4770_ADC_BATTERY_VREF_BITS) - 1, 302 304 }; ··· 391 385 BIT(IIO_CHAN_INFO_SCALE), 392 386 .indexed = 1, 393 387 .channel = INGENIC_ADC_AUX, 388 + .scan_index = -1, 389 + }, 390 + { 391 + .extend_name = "battery", 392 + .type = IIO_VOLTAGE, 393 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 394 + BIT(IIO_CHAN_INFO_SCALE), 395 + .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW) | 396 + BIT(IIO_CHAN_INFO_SCALE), 397 + .indexed = 1, 398 + .channel = INGENIC_ADC_BATTERY, 399 + .scan_index = -1, 400 + }, 401 + }; 402 + 403 + static const struct iio_chan_spec jz4760_channels[] = { 404 + { 405 + .extend_name = "aux", 406 + .type = IIO_VOLTAGE, 407 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 408 + BIT(IIO_CHAN_INFO_SCALE), 409 + .indexed = 1, 410 + .channel = INGENIC_ADC_AUX0, 411 + .scan_index = -1, 412 + }, 413 + { 414 + .extend_name = "aux1", 415 + .type = IIO_VOLTAGE, 416 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 417 + BIT(IIO_CHAN_INFO_SCALE), 418 + .indexed = 1, 419 + .channel = INGENIC_ADC_AUX, 420 + .scan_index = -1, 421 + }, 422 + { 423 + .extend_name = "aux2", 424 + .type = IIO_VOLTAGE, 425 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 426 + BIT(IIO_CHAN_INFO_SCALE), 427 + .indexed = 1, 428 + .channel = INGENIC_ADC_AUX2, 394 429 .scan_index = -1, 395 430 }, 396 431 { ··· 553 506 .battery_scale_avail = jz4725b_adc_battery_scale_avail, 554 507 .battery_scale_avail_size = ARRAY_SIZE(jz4725b_adc_battery_scale_avail), 555 508 .battery_vref_mode = true, 556 - .has_aux2 = false, 509 + .has_aux_md = false, 557 510 .channels = jz4740_channels, 558 511 .num_channels = ARRAY_SIZE(jz4740_channels), 559 512 .init_clk_div = jz4725b_adc_init_clk_div, ··· 567 520 .battery_scale_avail = jz4740_adc_battery_scale_avail, 568 521 .battery_scale_avail_size = ARRAY_SIZE(jz4740_adc_battery_scale_avail), 569 522 .battery_vref_mode = true, 570 - .has_aux2 = false, 523 + .has_aux_md = false, 571 524 .channels = jz4740_channels, 572 525 .num_channels = ARRAY_SIZE(jz4740_channels), 573 526 .init_clk_div = NULL, /* no ADCLK register on JZ4740 */ 527 + }; 528 + 529 + static const struct ingenic_adc_soc_data jz4760_adc_soc_data = { 530 + .battery_high_vref = JZ4760_ADC_BATTERY_VREF, 531 + .battery_high_vref_bits = JZ4770_ADC_BATTERY_VREF_BITS, 532 + .battery_raw_avail = jz4770_adc_battery_raw_avail, 533 + .battery_raw_avail_size = ARRAY_SIZE(jz4770_adc_battery_raw_avail), 534 + .battery_scale_avail = jz4760_adc_battery_scale_avail, 535 + .battery_scale_avail_size = ARRAY_SIZE(jz4760_adc_battery_scale_avail), 536 + .battery_vref_mode = false, 537 + .has_aux_md = true, 538 + .channels = jz4760_channels, 539 + .num_channels = ARRAY_SIZE(jz4760_channels), 540 + .init_clk_div = jz4770_adc_init_clk_div, 574 541 }; 575 542 576 543 static const struct ingenic_adc_soc_data jz4770_adc_soc_data = { ··· 595 534 .battery_scale_avail = jz4770_adc_battery_scale_avail, 596 535 .battery_scale_avail_size = ARRAY_SIZE(jz4770_adc_battery_scale_avail), 597 536 .battery_vref_mode = false, 598 - .has_aux2 = true, 537 + .has_aux_md = true, 599 538 .channels = jz4770_channels, 600 539 .num_channels = ARRAY_SIZE(jz4770_channels), 601 540 .init_clk_div = jz4770_adc_init_clk_div, ··· 630 569 struct iio_chan_spec const *chan, 631 570 int *val) 632 571 { 633 - int bit, ret, engine = (chan->channel == INGENIC_ADC_BATTERY); 572 + int cmd, ret, engine = (chan->channel == INGENIC_ADC_BATTERY); 634 573 struct ingenic_adc *adc = iio_priv(iio_dev); 635 574 636 575 ret = clk_enable(adc->clk); ··· 640 579 return ret; 641 580 } 642 581 643 - /* We cannot sample AUX/AUX2 in parallel. */ 582 + /* We cannot sample the aux channels in parallel. */ 644 583 mutex_lock(&adc->aux_lock); 645 - if (adc->soc_data->has_aux2 && engine == 0) { 646 - bit = BIT(chan->channel == INGENIC_ADC_AUX2); 647 - ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, bit); 584 + if (adc->soc_data->has_aux_md && engine == 0) { 585 + switch (chan->channel) { 586 + case INGENIC_ADC_AUX0: 587 + cmd = 0; 588 + break; 589 + case INGENIC_ADC_AUX: 590 + cmd = 1; 591 + break; 592 + case INGENIC_ADC_AUX2: 593 + cmd = 2; 594 + break; 595 + } 596 + 597 + ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, cmd); 648 598 } 649 599 650 600 ret = ingenic_adc_capture(adc, engine); ··· 663 591 goto out; 664 592 665 593 switch (chan->channel) { 594 + case INGENIC_ADC_AUX0: 666 595 case INGENIC_ADC_AUX: 667 596 case INGENIC_ADC_AUX2: 668 597 *val = readw(adc->base + JZ_ADC_REG_ADSDAT); ··· 694 621 return ingenic_adc_read_chan_info_raw(iio_dev, chan, val); 695 622 case IIO_CHAN_INFO_SCALE: 696 623 switch (chan->channel) { 624 + case INGENIC_ADC_AUX0: 697 625 case INGENIC_ADC_AUX: 698 626 case INGENIC_ADC_AUX2: 699 627 *val = JZ_ADC_AUX_VREF; ··· 880 806 /* Put hardware in a known passive state. */ 881 807 writeb(0x00, adc->base + JZ_ADC_REG_ENABLE); 882 808 writeb(0xff, adc->base + JZ_ADC_REG_CTRL); 809 + 810 + /* JZ4760B specific */ 811 + if (device_property_present(dev, "ingenic,use-internal-divider")) 812 + ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_VBAT_SEL, 813 + JZ_ADC_REG_CFG_VBAT_SEL); 814 + else 815 + ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_VBAT_SEL, 0); 816 + 883 817 usleep_range(2000, 3000); /* Must wait at least 2ms. */ 884 818 clk_disable(adc->clk); 885 819 ··· 914 832 static const struct of_device_id ingenic_adc_of_match[] = { 915 833 { .compatible = "ingenic,jz4725b-adc", .data = &jz4725b_adc_soc_data, }, 916 834 { .compatible = "ingenic,jz4740-adc", .data = &jz4740_adc_soc_data, }, 835 + { .compatible = "ingenic,jz4760-adc", .data = &jz4760_adc_soc_data, }, 836 + { .compatible = "ingenic,jz4760b-adc", .data = &jz4760_adc_soc_data, }, 917 837 { .compatible = "ingenic,jz4770-adc", .data = &jz4770_adc_soc_data, }, 918 838 { }, 919 839 };
+14 -6
drivers/iio/adc/meson_saradc.c
··· 347 347 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 348 348 int regval, fifo_chan, fifo_val, count; 349 349 350 - if(!wait_for_completion_timeout(&priv->done, 350 + if (!wait_for_completion_timeout(&priv->done, 351 351 msecs_to_jiffies(MESON_SAR_ADC_TIMEOUT))) 352 352 return -ETIMEDOUT; 353 353 ··· 497 497 if (priv->param->has_bl30_integration) { 498 498 /* prevent BL30 from using the SAR ADC while we are using it */ 499 499 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY, 500 - MESON_SAR_ADC_DELAY_KERNEL_BUSY, 501 - MESON_SAR_ADC_DELAY_KERNEL_BUSY); 500 + MESON_SAR_ADC_DELAY_KERNEL_BUSY, 501 + MESON_SAR_ADC_DELAY_KERNEL_BUSY); 502 502 503 503 /* 504 504 * wait until BL30 releases it's lock (so we can use the SAR ··· 525 525 if (priv->param->has_bl30_integration) 526 526 /* allow BL30 to use the SAR ADC again */ 527 527 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY, 528 - MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0); 528 + MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0); 529 529 530 530 mutex_unlock(&indio_dev->mlock); 531 531 } ··· 791 791 * on the vendor driver), which we don't support at the moment. 792 792 */ 793 793 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0, 794 - MESON_SAR_ADC_REG0_ADC_TEMP_SEN_SEL, 0); 794 + MESON_SAR_ADC_REG0_ADC_TEMP_SEN_SEL, 0); 795 795 796 796 /* disable all channels by default */ 797 797 regmap_write(priv->regmap, MESON_SAR_ADC_CHAN_LIST, 0x0); ··· 1104 1104 .resolution = 12, 1105 1105 }; 1106 1106 1107 + static const struct meson_sar_adc_param meson_sar_adc_g12a_param = { 1108 + .has_bl30_integration = false, 1109 + .clock_rate = 1200000, 1110 + .bandgap_reg = MESON_SAR_ADC_REG11, 1111 + .regmap_config = &meson_sar_adc_regmap_config_gxbb, 1112 + .resolution = 12, 1113 + }; 1114 + 1107 1115 static const struct meson_sar_adc_data meson_sar_adc_meson8_data = { 1108 1116 .param = &meson_sar_adc_meson8_param, 1109 1117 .name = "meson-meson8-saradc", ··· 1148 1140 }; 1149 1141 1150 1142 static const struct meson_sar_adc_data meson_sar_adc_g12a_data = { 1151 - .param = &meson_sar_adc_gxl_param, 1143 + .param = &meson_sar_adc_g12a_param, 1152 1144 .name = "meson-g12a-saradc", 1153 1145 }; 1154 1146
+21 -1
drivers/iio/adc/rockchip_saradc.c
··· 35 35 #define SARADC_DLY_PU_SOC_MASK 0x3f 36 36 37 37 #define SARADC_TIMEOUT msecs_to_jiffies(100) 38 - #define SARADC_MAX_CHANNELS 6 38 + #define SARADC_MAX_CHANNELS 8 39 39 40 40 struct rockchip_saradc_data { 41 41 const struct iio_chan_spec *channels; ··· 192 192 .clk_rate = 1000000, 193 193 }; 194 194 195 + static const struct iio_chan_spec rockchip_rk3568_saradc_iio_channels[] = { 196 + SARADC_CHANNEL(0, "adc0", 10), 197 + SARADC_CHANNEL(1, "adc1", 10), 198 + SARADC_CHANNEL(2, "adc2", 10), 199 + SARADC_CHANNEL(3, "adc3", 10), 200 + SARADC_CHANNEL(4, "adc4", 10), 201 + SARADC_CHANNEL(5, "adc5", 10), 202 + SARADC_CHANNEL(6, "adc6", 10), 203 + SARADC_CHANNEL(7, "adc7", 10), 204 + }; 205 + 206 + static const struct rockchip_saradc_data rk3568_saradc_data = { 207 + .channels = rockchip_rk3568_saradc_iio_channels, 208 + .num_channels = ARRAY_SIZE(rockchip_rk3568_saradc_iio_channels), 209 + .clk_rate = 1000000, 210 + }; 211 + 195 212 static const struct of_device_id rockchip_saradc_match[] = { 196 213 { 197 214 .compatible = "rockchip,saradc", ··· 219 202 }, { 220 203 .compatible = "rockchip,rk3399-saradc", 221 204 .data = &rk3399_saradc_data, 205 + }, { 206 + .compatible = "rockchip,rk3568-saradc", 207 + .data = &rk3568_saradc_data, 222 208 }, 223 209 {}, 224 210 };
+11
drivers/iio/chemical/Kconfig
··· 131 131 To compile this driver as module, choose M here: the 132 132 module will be called sgp30. 133 133 134 + config SENSIRION_SGP40 135 + tristate "Sensirion SGP40 gas sensor" 136 + depends on I2C 137 + select CRC8 138 + help 139 + Say Y here to build I2C interface to support Sensirion SGP40 gas 140 + sensor 141 + 142 + To compile this driver as module, choose M here: the 143 + module will be called sgp40. 144 + 134 145 config SPS30 135 146 tristate 136 147 select IIO_BUFFER
+1
drivers/iio/chemical/Makefile
··· 16 16 obj-$(CONFIG_SCD30_I2C) += scd30_i2c.o 17 17 obj-$(CONFIG_SCD30_SERIAL) += scd30_serial.o 18 18 obj-$(CONFIG_SENSIRION_SGP30) += sgp30.o 19 + obj-$(CONFIG_SENSIRION_SGP40) += sgp40.o 19 20 obj-$(CONFIG_SPS30) += sps30.o 20 21 obj-$(CONFIG_SPS30_I2C) += sps30_i2c.o 21 22 obj-$(CONFIG_SPS30_SERIAL) += sps30_serial.o
+378
drivers/iio/chemical/sgp40.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * sgp40.c - Support for Sensirion SGP40 Gas Sensor 4 + * 5 + * Copyright (C) 2021 Andreas Klinger <ak@it-klinger.de> 6 + * 7 + * I2C slave address: 0x59 8 + * 9 + * Datasheet can be found here: 10 + * https://www.sensirion.com/file/datasheet_sgp40 11 + * 12 + * There are two functionalities supported: 13 + * 14 + * 1) read raw logarithmic resistance value from sensor 15 + * --> useful to pass it to the algorithm of the sensor vendor for 16 + * measuring deteriorations and improvements of air quality. 17 + * 18 + * 2) calculate an estimated absolute voc index (0 - 500 index points) for 19 + * measuring the air quality. 20 + * For this purpose the value of the resistance for which the voc index 21 + * will be 250 can be set up using calibbias. 22 + * 23 + * Compensation values of relative humidity and temperature can be set up 24 + * by writing to the out values of temp and humidityrelative. 25 + */ 26 + 27 + #include <linux/delay.h> 28 + #include <linux/crc8.h> 29 + #include <linux/module.h> 30 + #include <linux/mutex.h> 31 + #include <linux/i2c.h> 32 + #include <linux/iio/iio.h> 33 + 34 + /* 35 + * floating point calculation of voc is done as integer 36 + * where numbers are multiplied by 1 << SGP40_CALC_POWER 37 + */ 38 + #define SGP40_CALC_POWER 14 39 + 40 + #define SGP40_CRC8_POLYNOMIAL 0x31 41 + #define SGP40_CRC8_INIT 0xff 42 + 43 + DECLARE_CRC8_TABLE(sgp40_crc8_table); 44 + 45 + struct sgp40_data { 46 + struct device *dev; 47 + struct i2c_client *client; 48 + int rht; 49 + int temp; 50 + int res_calibbias; 51 + /* Prevent concurrent access to rht, tmp, calibbias */ 52 + struct mutex lock; 53 + }; 54 + 55 + struct sgp40_tg_measure { 56 + u8 command[2]; 57 + __be16 rht_ticks; 58 + u8 rht_crc; 59 + __be16 temp_ticks; 60 + u8 temp_crc; 61 + } __packed; 62 + 63 + struct sgp40_tg_result { 64 + __be16 res_ticks; 65 + u8 res_crc; 66 + } __packed; 67 + 68 + static const struct iio_chan_spec sgp40_channels[] = { 69 + { 70 + .type = IIO_CONCENTRATION, 71 + .channel2 = IIO_MOD_VOC, 72 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 73 + }, 74 + { 75 + .type = IIO_RESISTANCE, 76 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 77 + BIT(IIO_CHAN_INFO_CALIBBIAS), 78 + }, 79 + { 80 + .type = IIO_TEMP, 81 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 82 + .output = 1, 83 + }, 84 + { 85 + .type = IIO_HUMIDITYRELATIVE, 86 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 87 + .output = 1, 88 + }, 89 + }; 90 + 91 + /* 92 + * taylor approximation of e^x: 93 + * y = 1 + x + x^2 / 2 + x^3 / 6 + x^4 / 24 + ... + x^n / n! 94 + * 95 + * Because we are calculating x real value multiplied by 2^power we get 96 + * an additional 2^power^n to divide for every element. For a reasonable 97 + * precision this would overflow after a few iterations. Therefore we 98 + * divide the x^n part whenever its about to overflow (xmax). 99 + */ 100 + 101 + static u32 sgp40_exp(int exp, u32 power, u32 rounds) 102 + { 103 + u32 x, y, xp; 104 + u32 factorial, divider, xmax; 105 + int sign = 1; 106 + int i; 107 + 108 + if (exp == 0) 109 + return 1 << power; 110 + else if (exp < 0) { 111 + sign = -1; 112 + exp *= -1; 113 + } 114 + 115 + xmax = 0x7FFFFFFF / exp; 116 + x = exp; 117 + xp = 1; 118 + factorial = 1; 119 + y = 1 << power; 120 + divider = 0; 121 + 122 + for (i = 1; i <= rounds; i++) { 123 + xp *= x; 124 + factorial *= i; 125 + y += (xp >> divider) / factorial; 126 + divider += power; 127 + /* divide when next multiplication would overflow */ 128 + if (xp >= xmax) { 129 + xp >>= power; 130 + divider -= power; 131 + } 132 + } 133 + 134 + if (sign == -1) 135 + return (1 << (power * 2)) / y; 136 + else 137 + return y; 138 + } 139 + 140 + static int sgp40_calc_voc(struct sgp40_data *data, u16 resistance_raw, int *voc) 141 + { 142 + int x; 143 + u32 exp = 0; 144 + 145 + /* we calculate as a multiple of 16384 (2^14) */ 146 + mutex_lock(&data->lock); 147 + x = ((int)resistance_raw - data->res_calibbias) * 106; 148 + mutex_unlock(&data->lock); 149 + 150 + /* voc = 500 / (1 + e^x) */ 151 + exp = sgp40_exp(x, SGP40_CALC_POWER, 18); 152 + *voc = 500 * ((1 << (SGP40_CALC_POWER * 2)) / ((1<<SGP40_CALC_POWER) + exp)); 153 + 154 + dev_dbg(data->dev, "raw: %d res_calibbias: %d x: %d exp: %d voc: %d\n", 155 + resistance_raw, data->res_calibbias, x, exp, *voc); 156 + 157 + return 0; 158 + } 159 + 160 + static int sgp40_measure_resistance_raw(struct sgp40_data *data, u16 *resistance_raw) 161 + { 162 + int ret; 163 + struct i2c_client *client = data->client; 164 + u32 ticks; 165 + u16 ticks16; 166 + u8 crc; 167 + struct sgp40_tg_measure tg = {.command = {0x26, 0x0F}}; 168 + struct sgp40_tg_result tgres; 169 + 170 + mutex_lock(&data->lock); 171 + 172 + ticks = (data->rht / 10) * 65535 / 10000; 173 + ticks16 = (u16)clamp(ticks, 0u, 65535u); /* clamp between 0 .. 100 %rH */ 174 + tg.rht_ticks = cpu_to_be16(ticks16); 175 + tg.rht_crc = crc8(sgp40_crc8_table, (u8 *)&tg.rht_ticks, 2, SGP40_CRC8_INIT); 176 + 177 + ticks = ((data->temp + 45000) / 10 ) * 65535 / 17500; 178 + ticks16 = (u16)clamp(ticks, 0u, 65535u); /* clamp between -45 .. +130 °C */ 179 + tg.temp_ticks = cpu_to_be16(ticks16); 180 + tg.temp_crc = crc8(sgp40_crc8_table, (u8 *)&tg.temp_ticks, 2, SGP40_CRC8_INIT); 181 + 182 + mutex_unlock(&data->lock); 183 + 184 + ret = i2c_master_send(client, (const char *)&tg, sizeof(tg)); 185 + if (ret != sizeof(tg)) { 186 + dev_warn(data->dev, "i2c_master_send ret: %d sizeof: %zu\n", ret, sizeof(tg)); 187 + return -EIO; 188 + } 189 + msleep(30); 190 + 191 + ret = i2c_master_recv(client, (u8 *)&tgres, sizeof(tgres)); 192 + if (ret < 0) 193 + return ret; 194 + if (ret != sizeof(tgres)) { 195 + dev_warn(data->dev, "i2c_master_recv ret: %d sizeof: %zu\n", ret, sizeof(tgres)); 196 + return -EIO; 197 + } 198 + 199 + crc = crc8(sgp40_crc8_table, (u8 *)&tgres.res_ticks, 2, SGP40_CRC8_INIT); 200 + if (crc != tgres.res_crc) { 201 + dev_err(data->dev, "CRC error while measure-raw\n"); 202 + return -EIO; 203 + } 204 + 205 + *resistance_raw = be16_to_cpu(tgres.res_ticks); 206 + 207 + return 0; 208 + } 209 + 210 + static int sgp40_read_raw(struct iio_dev *indio_dev, 211 + struct iio_chan_spec const *chan, int *val, 212 + int *val2, long mask) 213 + { 214 + struct sgp40_data *data = iio_priv(indio_dev); 215 + int ret, voc; 216 + u16 resistance_raw; 217 + 218 + switch (mask) { 219 + case IIO_CHAN_INFO_RAW: 220 + switch (chan->type) { 221 + case IIO_RESISTANCE: 222 + ret = sgp40_measure_resistance_raw(data, &resistance_raw); 223 + if (ret) 224 + return ret; 225 + 226 + *val = resistance_raw; 227 + return IIO_VAL_INT; 228 + case IIO_TEMP: 229 + mutex_lock(&data->lock); 230 + *val = data->temp; 231 + mutex_unlock(&data->lock); 232 + return IIO_VAL_INT; 233 + case IIO_HUMIDITYRELATIVE: 234 + mutex_lock(&data->lock); 235 + *val = data->rht; 236 + mutex_unlock(&data->lock); 237 + return IIO_VAL_INT; 238 + default: 239 + return -EINVAL; 240 + } 241 + case IIO_CHAN_INFO_PROCESSED: 242 + ret = sgp40_measure_resistance_raw(data, &resistance_raw); 243 + if (ret) 244 + return ret; 245 + 246 + ret = sgp40_calc_voc(data, resistance_raw, &voc); 247 + if (ret) 248 + return ret; 249 + 250 + *val = voc / (1 << SGP40_CALC_POWER); 251 + /* 252 + * calculation should fit into integer, where: 253 + * voc <= (500 * 2^SGP40_CALC_POWER) = 8192000 254 + * (with SGP40_CALC_POWER = 14) 255 + */ 256 + *val2 = ((voc % (1 << SGP40_CALC_POWER)) * 244) / (1 << (SGP40_CALC_POWER - 12)); 257 + dev_dbg(data->dev, "voc: %d val: %d.%06d\n", voc, *val, *val2); 258 + return IIO_VAL_INT_PLUS_MICRO; 259 + case IIO_CHAN_INFO_CALIBBIAS: 260 + mutex_lock(&data->lock); 261 + *val = data->res_calibbias; 262 + mutex_unlock(&data->lock); 263 + return IIO_VAL_INT; 264 + default: 265 + return -EINVAL; 266 + } 267 + } 268 + 269 + static int sgp40_write_raw(struct iio_dev *indio_dev, 270 + struct iio_chan_spec const *chan, int val, 271 + int val2, long mask) 272 + { 273 + struct sgp40_data *data = iio_priv(indio_dev); 274 + 275 + switch (mask) { 276 + case IIO_CHAN_INFO_RAW: 277 + switch (chan->type) { 278 + case IIO_TEMP: 279 + if ((val < -45000) || (val > 130000)) 280 + return -EINVAL; 281 + 282 + mutex_lock(&data->lock); 283 + data->temp = val; 284 + mutex_unlock(&data->lock); 285 + return 0; 286 + case IIO_HUMIDITYRELATIVE: 287 + if ((val < 0) || (val > 100000)) 288 + return -EINVAL; 289 + 290 + mutex_lock(&data->lock); 291 + data->rht = val; 292 + mutex_unlock(&data->lock); 293 + return 0; 294 + default: 295 + return -EINVAL; 296 + } 297 + case IIO_CHAN_INFO_CALIBBIAS: 298 + if ((val < 20000) || (val > 52768)) 299 + return -EINVAL; 300 + 301 + mutex_lock(&data->lock); 302 + data->res_calibbias = val; 303 + mutex_unlock(&data->lock); 304 + return 0; 305 + } 306 + return -EINVAL; 307 + } 308 + 309 + static const struct iio_info sgp40_info = { 310 + .read_raw = sgp40_read_raw, 311 + .write_raw = sgp40_write_raw, 312 + }; 313 + 314 + static int sgp40_probe(struct i2c_client *client, 315 + const struct i2c_device_id *id) 316 + { 317 + struct device *dev = &client->dev; 318 + struct iio_dev *indio_dev; 319 + struct sgp40_data *data; 320 + int ret; 321 + 322 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 323 + if (!indio_dev) 324 + return -ENOMEM; 325 + 326 + data = iio_priv(indio_dev); 327 + data->client = client; 328 + data->dev = dev; 329 + 330 + crc8_populate_msb(sgp40_crc8_table, SGP40_CRC8_POLYNOMIAL); 331 + 332 + mutex_init(&data->lock); 333 + 334 + /* set default values */ 335 + data->rht = 50000; /* 50 % */ 336 + data->temp = 25000; /* 25 °C */ 337 + data->res_calibbias = 30000; /* resistance raw value for voc index of 250 */ 338 + 339 + indio_dev->info = &sgp40_info; 340 + indio_dev->name = id->name; 341 + indio_dev->modes = INDIO_DIRECT_MODE; 342 + indio_dev->channels = sgp40_channels; 343 + indio_dev->num_channels = ARRAY_SIZE(sgp40_channels); 344 + 345 + ret = devm_iio_device_register(dev, indio_dev); 346 + if (ret) 347 + dev_err(dev, "failed to register iio device\n"); 348 + 349 + return ret; 350 + } 351 + 352 + static const struct i2c_device_id sgp40_id[] = { 353 + { "sgp40" }, 354 + { } 355 + }; 356 + 357 + MODULE_DEVICE_TABLE(i2c, sgp40_id); 358 + 359 + static const struct of_device_id sgp40_dt_ids[] = { 360 + { .compatible = "sensirion,sgp40" }, 361 + { } 362 + }; 363 + 364 + MODULE_DEVICE_TABLE(of, sgp40_dt_ids); 365 + 366 + static struct i2c_driver sgp40_driver = { 367 + .driver = { 368 + .name = "sgp40", 369 + .of_match_table = sgp40_dt_ids, 370 + }, 371 + .probe = sgp40_probe, 372 + .id_table = sgp40_id, 373 + }; 374 + module_i2c_driver(sgp40_driver); 375 + 376 + MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>"); 377 + MODULE_DESCRIPTION("Sensirion SGP40 gas sensor"); 378 + MODULE_LICENSE("GPL v2");
-2
drivers/iio/common/st_sensors/st_sensors_buffer.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 13 12 #include <linux/iio/iio.h> 14 13 #include <linux/iio/trigger.h> 15 14 #include <linux/interrupt.h> 16 15 #include <linux/iio/buffer.h> 17 16 #include <linux/iio/trigger_consumer.h> 18 - #include <linux/iio/triggered_buffer.h> 19 17 #include <linux/irqreturn.h> 20 18 #include <linux/regmap.h> 21 19
+1
drivers/iio/common/st_sensors/st_sensors_core.c
··· 12 12 #include <linux/slab.h> 13 13 #include <linux/delay.h> 14 14 #include <linux/iio/iio.h> 15 + #include <linux/mutex.h> 15 16 #include <linux/property.h> 16 17 #include <linux/regulator/consumer.h> 17 18 #include <linux/regmap.h>
+1
drivers/iio/common/st_sensors/st_sensors_core.h
··· 4 4 */ 5 5 #ifndef __ST_SENSORS_CORE_H 6 6 #define __ST_SENSORS_CORE_H 7 + struct iio_dev; 7 8 int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, 8 9 u8 reg_addr, u8 mask, u8 data); 9 10 #endif
+1 -2
drivers/iio/common/st_sensors/st_sensors_i2c.c
··· 7 7 * Denis Ciocca <denis.ciocca@st.com> 8 8 */ 9 9 10 + #include <linux/i2c.h> 10 11 #include <linux/kernel.h> 11 12 #include <linux/module.h> 12 - #include <linux/slab.h> 13 13 #include <linux/iio/iio.h> 14 14 #include <linux/regmap.h> 15 15 16 16 #include <linux/iio/common/st_sensors_i2c.h> 17 - 18 17 19 18 #define ST_SENSORS_I2C_MULTIREAD 0x80 20 19
+1 -2
drivers/iio/common/st_sensors/st_sensors_spi.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 13 12 #include <linux/iio/iio.h> 14 13 #include <linux/property.h> 15 14 #include <linux/regmap.h> 15 + #include <linux/spi/spi.h> 16 16 17 17 #include <linux/iio/common/st_sensors_spi.h> 18 - #include "st_sensors_core.h" 19 18 20 19 #define ST_SENSORS_SPI_MULTIREAD 0xc0 21 20
-1
drivers/iio/common/st_sensors/st_sensors_trigger.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 13 12 #include <linux/iio/iio.h> 14 13 #include <linux/iio/trigger.h> 15 14 #include <linux/interrupt.h>
+17 -1
drivers/iio/dac/ad5624r_spi.c
··· 229 229 if (!indio_dev) 230 230 return -ENOMEM; 231 231 st = iio_priv(indio_dev); 232 - st->reg = devm_regulator_get(&spi->dev, "vcc"); 232 + st->reg = devm_regulator_get_optional(&spi->dev, "vref"); 233 233 if (!IS_ERR(st->reg)) { 234 234 ret = regulator_enable(st->reg); 235 235 if (ret) ··· 240 240 goto error_disable_reg; 241 241 242 242 voltage_uv = ret; 243 + } else { 244 + if (PTR_ERR(st->reg) != -ENODEV) 245 + return PTR_ERR(st->reg); 246 + /* Backwards compatibility. This naming is not correct */ 247 + st->reg = devm_regulator_get_optional(&spi->dev, "vcc"); 248 + if (!IS_ERR(st->reg)) { 249 + ret = regulator_enable(st->reg); 250 + if (ret) 251 + return ret; 252 + 253 + ret = regulator_get_voltage(st->reg); 254 + if (ret < 0) 255 + goto error_disable_reg; 256 + 257 + voltage_uv = ret; 258 + } 243 259 } 244 260 245 261 spi_set_drvdata(spi, indio_dev);
+17 -24
drivers/iio/dac/max5821.c
··· 294 294 .write_raw = max5821_write_raw, 295 295 }; 296 296 297 + static void max5821_regulator_disable(void *reg) 298 + { 299 + regulator_disable(reg); 300 + } 301 + 297 302 static int max5821_probe(struct i2c_client *client, 298 303 const struct i2c_device_id *id) 299 304 { ··· 311 306 if (!indio_dev) 312 307 return -ENOMEM; 313 308 data = iio_priv(indio_dev); 314 - i2c_set_clientdata(client, indio_dev); 315 309 data->client = client; 316 310 mutex_init(&data->lock); 317 311 ··· 325 321 ret = PTR_ERR(data->vref_reg); 326 322 dev_err(&client->dev, 327 323 "Failed to get vref regulator: %d\n", ret); 328 - goto error_free_reg; 324 + return ret; 329 325 } 330 326 331 327 ret = regulator_enable(data->vref_reg); 332 328 if (ret) { 333 329 dev_err(&client->dev, 334 330 "Failed to enable vref regulator: %d\n", ret); 335 - goto error_free_reg; 331 + return ret; 332 + } 333 + 334 + ret = devm_add_action_or_reset(&client->dev, max5821_regulator_disable, 335 + data->vref_reg); 336 + if (ret) { 337 + dev_err(&client->dev, 338 + "Failed to add action to managed regulator: %d\n", ret); 339 + return ret; 336 340 } 337 341 338 342 ret = regulator_get_voltage(data->vref_reg); 339 343 if (ret < 0) { 340 344 dev_err(&client->dev, 341 345 "Failed to get voltage on regulator: %d\n", ret); 342 - goto error_disable_reg; 346 + return ret; 343 347 } 344 348 345 349 data->vref_mv = ret / 1000; ··· 358 346 indio_dev->modes = INDIO_DIRECT_MODE; 359 347 indio_dev->info = &max5821_info; 360 348 361 - return iio_device_register(indio_dev); 362 - 363 - error_disable_reg: 364 - regulator_disable(data->vref_reg); 365 - 366 - error_free_reg: 367 - 368 - return ret; 369 - } 370 - 371 - static int max5821_remove(struct i2c_client *client) 372 - { 373 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 374 - struct max5821_data *data = iio_priv(indio_dev); 375 - 376 - iio_device_unregister(indio_dev); 377 - regulator_disable(data->vref_reg); 378 - 379 - return 0; 349 + return devm_iio_device_register(&client->dev, indio_dev); 380 350 } 381 351 382 352 static const struct i2c_device_id max5821_id[] = { ··· 380 386 .pm = &max5821_pm_ops, 381 387 }, 382 388 .probe = max5821_probe, 383 - .remove = max5821_remove, 384 389 .id_table = max5821_id, 385 390 }; 386 391 module_i2c_driver(max5821_driver);
+4 -7
drivers/iio/gyro/hid-sensor-gyro-3d.c
··· 303 303 return ret; 304 304 } 305 305 306 - indio_dev->channels = kmemdup(gyro_3d_channels, 307 - sizeof(gyro_3d_channels), GFP_KERNEL); 306 + indio_dev->channels = devm_kmemdup(&pdev->dev, gyro_3d_channels, 307 + sizeof(gyro_3d_channels), GFP_KERNEL); 308 308 if (!indio_dev->channels) { 309 309 dev_err(&pdev->dev, "failed to duplicate channels\n"); 310 310 return -ENOMEM; ··· 315 315 HID_USAGE_SENSOR_GYRO_3D, gyro_state); 316 316 if (ret) { 317 317 dev_err(&pdev->dev, "failed to setup attributes\n"); 318 - goto error_free_dev_mem; 318 + return ret; 319 319 } 320 320 321 321 indio_dev->num_channels = ARRAY_SIZE(gyro_3d_channels); ··· 329 329 &gyro_state->common_attributes); 330 330 if (ret < 0) { 331 331 dev_err(&pdev->dev, "trigger setup failed\n"); 332 - goto error_free_dev_mem; 332 + return ret; 333 333 } 334 334 335 335 ret = iio_device_register(indio_dev); ··· 354 354 iio_device_unregister(indio_dev); 355 355 error_remove_trigger: 356 356 hid_sensor_remove_trigger(indio_dev, &gyro_state->common_attributes); 357 - error_free_dev_mem: 358 - kfree(indio_dev->channels); 359 357 return ret; 360 358 } 361 359 ··· 367 369 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_GYRO_3D); 368 370 iio_device_unregister(indio_dev); 369 371 hid_sensor_remove_trigger(indio_dev, &gyro_state->common_attributes); 370 - kfree(indio_dev->channels); 371 372 372 373 return 0; 373 374 }
-4
drivers/iio/gyro/st_gyro.h
··· 26 26 27 27 #ifdef CONFIG_IIO_BUFFER 28 28 int st_gyro_allocate_ring(struct iio_dev *indio_dev); 29 - void st_gyro_deallocate_ring(struct iio_dev *indio_dev); 30 29 int st_gyro_trig_set_state(struct iio_trigger *trig, bool state); 31 30 #define ST_GYRO_TRIGGER_SET_STATE (&st_gyro_trig_set_state) 32 31 #else /* CONFIG_IIO_BUFFER */ 33 32 static inline int st_gyro_allocate_ring(struct iio_dev *indio_dev) 34 33 { 35 34 return 0; 36 - } 37 - static inline void st_gyro_deallocate_ring(struct iio_dev *indio_dev) 38 - { 39 35 } 40 36 #define ST_GYRO_TRIGGER_SET_STATE NULL 41 37 #endif /* CONFIG_IIO_BUFFER */
+3 -13
drivers/iio/gyro/st_gyro_buffer.c
··· 9 9 10 10 #include <linux/module.h> 11 11 #include <linux/kernel.h> 12 - #include <linux/slab.h> 13 - #include <linux/stat.h> 14 - #include <linux/interrupt.h> 15 - #include <linux/i2c.h> 16 - #include <linux/delay.h> 17 12 #include <linux/iio/iio.h> 18 13 #include <linux/iio/buffer.h> 19 - #include <linux/iio/trigger_consumer.h> 14 + #include <linux/iio/trigger.h> 20 15 #include <linux/iio/triggered_buffer.h> 21 16 22 17 #include <linux/iio/common/st_sensors.h> ··· 61 66 62 67 int st_gyro_allocate_ring(struct iio_dev *indio_dev) 63 68 { 64 - return iio_triggered_buffer_setup(indio_dev, NULL, 65 - &st_sensors_trigger_handler, &st_gyro_buffer_setup_ops); 66 - } 67 - 68 - void st_gyro_deallocate_ring(struct iio_dev *indio_dev) 69 - { 70 - iio_triggered_buffer_cleanup(indio_dev); 69 + return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev, 70 + NULL, &st_sensors_trigger_handler, &st_gyro_buffer_setup_ops); 71 71 } 72 72 73 73 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+3 -12
drivers/iio/gyro/st_gyro_core.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 13 - #include <linux/errno.h> 14 - #include <linux/types.h> 12 + #include <linux/mutex.h> 15 13 #include <linux/interrupt.h> 16 - #include <linux/i2c.h> 17 - #include <linux/irq.h> 18 - #include <linux/delay.h> 14 + #include <linux/sysfs.h> 19 15 #include <linux/iio/iio.h> 20 16 #include <linux/iio/sysfs.h> 21 17 #include <linux/iio/trigger.h> 22 - #include <linux/iio/buffer.h> 23 18 24 19 #include <linux/iio/common/st_sensors.h> 25 20 #include "st_gyro.h" ··· 512 517 err = st_sensors_allocate_trigger(indio_dev, 513 518 ST_GYRO_TRIGGER_OPS); 514 519 if (err < 0) 515 - goto st_gyro_probe_trigger_error; 520 + return err; 516 521 } 517 522 518 523 err = iio_device_register(indio_dev); ··· 527 532 st_gyro_device_register_error: 528 533 if (gdata->irq > 0) 529 534 st_sensors_deallocate_trigger(indio_dev); 530 - st_gyro_probe_trigger_error: 531 - st_gyro_deallocate_ring(indio_dev); 532 535 return err; 533 536 } 534 537 EXPORT_SYMBOL(st_gyro_common_probe); ··· 538 545 iio_device_unregister(indio_dev); 539 546 if (gdata->irq > 0) 540 547 st_sensors_deallocate_trigger(indio_dev); 541 - 542 - st_gyro_deallocate_ring(indio_dev); 543 548 } 544 549 EXPORT_SYMBOL(st_gyro_common_remove); 545 550
+1 -1
drivers/iio/gyro/st_gyro_i2c.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 12 + #include <linux/mod_devicetable.h> 13 13 #include <linux/i2c.h> 14 14 #include <linux/iio/iio.h> 15 15
+1 -1
drivers/iio/gyro/st_gyro_spi.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 12 + #include <linux/mod_devicetable.h> 13 13 #include <linux/spi/spi.h> 14 14 #include <linux/iio/iio.h> 15 15
+18 -4
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 143 143 .config = &chip_config_6050, 144 144 .fifo_size = 1024, 145 145 .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE}, 146 + .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME}, 146 147 }, 147 148 { 148 149 .whoami = INV_MPU6500_WHOAMI_VALUE, ··· 152 151 .config = &chip_config_6500, 153 152 .fifo_size = 512, 154 153 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, 154 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 155 155 }, 156 156 { 157 157 .whoami = INV_MPU6515_WHOAMI_VALUE, ··· 161 159 .config = &chip_config_6500, 162 160 .fifo_size = 512, 163 161 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, 162 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 164 163 }, 165 164 { 166 165 .whoami = INV_MPU6880_WHOAMI_VALUE, ··· 170 167 .config = &chip_config_6500, 171 168 .fifo_size = 4096, 172 169 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, 170 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 173 171 }, 174 172 { 175 173 .whoami = INV_MPU6000_WHOAMI_VALUE, ··· 179 175 .config = &chip_config_6050, 180 176 .fifo_size = 1024, 181 177 .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE}, 178 + .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME}, 182 179 }, 183 180 { 184 181 .whoami = INV_MPU9150_WHOAMI_VALUE, ··· 188 183 .config = &chip_config_6050, 189 184 .fifo_size = 1024, 190 185 .temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE}, 186 + .startup_time = {INV_MPU6050_GYRO_STARTUP_TIME, INV_MPU6050_ACCEL_STARTUP_TIME}, 191 187 }, 192 188 { 193 189 .whoami = INV_MPU9250_WHOAMI_VALUE, ··· 197 191 .config = &chip_config_6500, 198 192 .fifo_size = 512, 199 193 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, 194 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 200 195 }, 201 196 { 202 197 .whoami = INV_MPU9255_WHOAMI_VALUE, ··· 206 199 .config = &chip_config_6500, 207 200 .fifo_size = 512, 208 201 .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, 202 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 209 203 }, 210 204 { 211 205 .whoami = INV_ICM20608_WHOAMI_VALUE, ··· 215 207 .config = &chip_config_6500, 216 208 .fifo_size = 512, 217 209 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, 210 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 218 211 }, 219 212 { 220 213 .whoami = INV_ICM20609_WHOAMI_VALUE, ··· 224 215 .config = &chip_config_6500, 225 216 .fifo_size = 4 * 1024, 226 217 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, 218 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 227 219 }, 228 220 { 229 221 .whoami = INV_ICM20689_WHOAMI_VALUE, ··· 233 223 .config = &chip_config_6500, 234 224 .fifo_size = 4 * 1024, 235 225 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, 226 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 236 227 }, 237 228 { 238 229 .whoami = INV_ICM20602_WHOAMI_VALUE, ··· 242 231 .config = &chip_config_6500, 243 232 .fifo_size = 1008, 244 233 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, 234 + .startup_time = {INV_ICM20602_GYRO_STARTUP_TIME, INV_ICM20602_ACCEL_STARTUP_TIME}, 245 235 }, 246 236 { 247 237 .whoami = INV_ICM20690_WHOAMI_VALUE, ··· 251 239 .config = &chip_config_6500, 252 240 .fifo_size = 1024, 253 241 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, 242 + .startup_time = {INV_ICM20690_GYRO_STARTUP_TIME, INV_ICM20690_ACCEL_STARTUP_TIME}, 254 243 }, 255 244 { 256 245 .whoami = INV_IAM20680_WHOAMI_VALUE, ··· 260 247 .config = &chip_config_6500, 261 248 .fifo_size = 512, 262 249 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, 250 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 263 251 }, 264 252 }; 265 253 ··· 393 379 sleep = 0; 394 380 if (en) { 395 381 if (mask & INV_MPU6050_SENSOR_ACCL) { 396 - if (sleep < INV_MPU6050_ACCEL_UP_TIME) 397 - sleep = INV_MPU6050_ACCEL_UP_TIME; 382 + if (sleep < st->hw->startup_time.accel) 383 + sleep = st->hw->startup_time.accel; 398 384 } 399 385 if (mask & INV_MPU6050_SENSOR_GYRO) { 400 - if (sleep < INV_MPU6050_GYRO_UP_TIME) 401 - sleep = INV_MPU6050_GYRO_UP_TIME; 386 + if (sleep < st->hw->startup_time.gyro) 387 + sleep = st->hw->startup_time.gyro; 402 388 } 403 389 } else { 404 390 if (mask & INV_MPU6050_SENSOR_GYRO) {
+16 -2
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
··· 149 149 int offset; 150 150 int scale; 151 151 } temp; 152 + struct { 153 + unsigned int accel; 154 + unsigned int gyro; 155 + } startup_time; 152 156 }; 153 157 154 158 /* ··· 324 320 /* delay time in milliseconds */ 325 321 #define INV_MPU6050_POWER_UP_TIME 100 326 322 #define INV_MPU6050_TEMP_UP_TIME 100 327 - #define INV_MPU6050_ACCEL_UP_TIME 20 328 - #define INV_MPU6050_GYRO_UP_TIME 35 323 + #define INV_MPU6050_ACCEL_STARTUP_TIME 20 324 + #define INV_MPU6050_GYRO_STARTUP_TIME 60 329 325 #define INV_MPU6050_GYRO_DOWN_TIME 150 330 326 #define INV_MPU6050_SUSPEND_DELAY_MS 2000 327 + 328 + #define INV_MPU6500_GYRO_STARTUP_TIME 70 329 + #define INV_MPU6500_ACCEL_STARTUP_TIME 30 330 + 331 + #define INV_ICM20602_GYRO_STARTUP_TIME 100 332 + #define INV_ICM20602_ACCEL_STARTUP_TIME 20 333 + 334 + #define INV_ICM20690_GYRO_STARTUP_TIME 80 335 + #define INV_ICM20690_ACCEL_STARTUP_TIME 10 336 + 331 337 332 338 /* delay time in microseconds */ 333 339 #define INV_MPU6050_REG_UP_TIME_MIN 5000
+2 -13
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
··· 91 91 92 92 static unsigned int inv_compute_skip_samples(const struct inv_mpu6050_state *st) 93 93 { 94 - unsigned int gyro_skip = 0; 95 - unsigned int magn_skip = 0; 96 - unsigned int skip_samples; 97 - 98 - /* gyro first sample is out of specs, skip it */ 99 - if (st->chip_config.gyro_fifo_enable) 100 - gyro_skip = 1; 94 + unsigned int skip_samples = 0; 101 95 102 96 /* mag first sample is always not ready, skip it */ 103 97 if (st->chip_config.magn_fifo_enable) 104 - magn_skip = 1; 105 - 106 - /* compute first samples to skip */ 107 - skip_samples = gyro_skip; 108 - if (magn_skip > skip_samples) 109 - skip_samples = magn_skip; 98 + skip_samples = 1; 110 99 111 100 return skip_samples; 112 101 }
+1
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c
··· 10 10 #include <linux/device.h> 11 11 #include <linux/err.h> 12 12 #include <linux/module.h> 13 + #include <linux/regmap.h> 13 14 #include <linux/regulator/consumer.h> 14 15 15 16 #include <linux/iio/common/st_sensors.h>
+2 -1
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c
··· 10 10 #include <linux/i2c.h> 11 11 #include <linux/kernel.h> 12 12 #include <linux/module.h> 13 - #include <linux/slab.h> 13 + #include <linux/mod_devicetable.h> 14 + #include <linux/regmap.h> 14 15 15 16 #include <linux/iio/common/st_sensors_i2c.h> 16 17
+2 -1
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 12 + #include <linux/mod_devicetable.h> 13 + #include <linux/regmap.h> 13 14 #include <linux/spi/spi.h> 14 15 15 16 #include <linux/iio/common/st_sensors_spi.h>
+5 -4
drivers/iio/industrialio-buffer.c
··· 354 354 const unsigned long *mask; 355 355 unsigned long *trialmask; 356 356 357 - trialmask = bitmap_zalloc(indio_dev->masklength, GFP_KERNEL); 358 - if (trialmask == NULL) 359 - return -ENOMEM; 360 357 if (!indio_dev->masklength) { 361 358 WARN(1, "Trying to set scanmask prior to registering buffer\n"); 362 - goto err_invalid_mask; 359 + return -EINVAL; 363 360 } 361 + 362 + trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL); 363 + if (!trialmask) 364 + return -ENOMEM; 364 365 bitmap_copy(trialmask, buffer->scan_mask, indio_dev->masklength); 365 366 set_bit(bit, trialmask); 366 367
+29 -4
drivers/iio/industrialio-core.c
··· 740 740 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 741 741 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 742 742 743 - if (!indio_dev->info->read_label) 744 - return -EINVAL; 743 + if (indio_dev->info->read_label) 744 + return indio_dev->info->read_label(indio_dev, this_attr->c, buf); 745 745 746 - return indio_dev->info->read_label(indio_dev, this_attr->c, buf); 746 + if (this_attr->c->extend_name) 747 + return sprintf(buf, "%s\n", this_attr->c->extend_name); 748 + 749 + return -EINVAL; 747 750 } 748 751 749 752 static ssize_t iio_read_channel_info(struct device *dev, ··· 1186 1183 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 1187 1184 int ret; 1188 1185 1189 - if (!indio_dev->info->read_label) 1186 + if (!indio_dev->info->read_label && !chan->extend_name) 1190 1187 return 0; 1191 1188 1192 1189 ret = __iio_add_chan_devattr("label", ··· 1861 1858 return 0; 1862 1859 } 1863 1860 1861 + static int iio_check_extended_name(const struct iio_dev *indio_dev) 1862 + { 1863 + unsigned int i; 1864 + 1865 + if (!indio_dev->info->read_label) 1866 + return 0; 1867 + 1868 + for (i = 0; i < indio_dev->num_channels; i++) { 1869 + if (indio_dev->channels[i].extend_name) { 1870 + dev_err(&indio_dev->dev, 1871 + "Cannot use labels and extend_name at the same time\n"); 1872 + return -EINVAL; 1873 + } 1874 + } 1875 + 1876 + return 0; 1877 + } 1878 + 1864 1879 static const struct iio_buffer_setup_ops noop_ring_setup_ops; 1865 1880 1866 1881 int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) ··· 1900 1879 indio_dev->label = label; 1901 1880 1902 1881 ret = iio_check_unique_scan_index(indio_dev); 1882 + if (ret < 0) 1883 + return ret; 1884 + 1885 + ret = iio_check_extended_name(indio_dev); 1903 1886 if (ret < 0) 1904 1887 return ret; 1905 1888
+9 -44
drivers/iio/light/adjd_s311.c
··· 54 54 55 55 struct adjd_s311_data { 56 56 struct i2c_client *client; 57 - u16 *buffer; 57 + struct { 58 + s16 chans[4]; 59 + s64 ts __aligned(8); 60 + } scan; 58 61 }; 59 62 60 63 enum adjd_s311_channel_idx { ··· 132 129 if (ret < 0) 133 130 goto done; 134 131 135 - data->buffer[j++] = ret & ADJD_S311_DATA_MASK; 132 + data->scan.chans[j++] = ret & ADJD_S311_DATA_MASK; 136 133 } 137 134 138 - iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, time_ns); 135 + iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, time_ns); 139 136 140 137 done: 141 138 iio_trigger_notify_done(indio_dev->trig); ··· 228 225 return -EINVAL; 229 226 } 230 227 231 - static int adjd_s311_update_scan_mode(struct iio_dev *indio_dev, 232 - const unsigned long *scan_mask) 233 - { 234 - struct adjd_s311_data *data = iio_priv(indio_dev); 235 - 236 - kfree(data->buffer); 237 - data->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); 238 - if (data->buffer == NULL) 239 - return -ENOMEM; 240 - 241 - return 0; 242 - } 243 - 244 228 static const struct iio_info adjd_s311_info = { 245 229 .read_raw = adjd_s311_read_raw, 246 230 .write_raw = adjd_s311_write_raw, 247 - .update_scan_mode = adjd_s311_update_scan_mode, 248 231 }; 249 232 250 233 static int adjd_s311_probe(struct i2c_client *client, ··· 245 256 return -ENOMEM; 246 257 247 258 data = iio_priv(indio_dev); 248 - i2c_set_clientdata(client, indio_dev); 249 259 data->client = client; 250 260 251 261 indio_dev->info = &adjd_s311_info; ··· 253 265 indio_dev->num_channels = ARRAY_SIZE(adjd_s311_channels); 254 266 indio_dev->modes = INDIO_DIRECT_MODE; 255 267 256 - err = iio_triggered_buffer_setup(indio_dev, NULL, 257 - adjd_s311_trigger_handler, NULL); 268 + err = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, 269 + adjd_s311_trigger_handler, NULL); 258 270 if (err < 0) 259 271 return err; 260 272 261 - err = iio_device_register(indio_dev); 262 - if (err) 263 - goto exit_unreg_buffer; 264 - 265 - dev_info(&client->dev, "ADJD-S311 color sensor registered\n"); 266 - 267 - return 0; 268 - 269 - exit_unreg_buffer: 270 - iio_triggered_buffer_cleanup(indio_dev); 271 - return err; 272 - } 273 - 274 - static int adjd_s311_remove(struct i2c_client *client) 275 - { 276 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 277 - struct adjd_s311_data *data = iio_priv(indio_dev); 278 - 279 - iio_device_unregister(indio_dev); 280 - iio_triggered_buffer_cleanup(indio_dev); 281 - kfree(data->buffer); 282 - 283 - return 0; 273 + return devm_iio_device_register(&client->dev, indio_dev); 284 274 } 285 275 286 276 static const struct i2c_device_id adjd_s311_id[] = { ··· 272 306 .name = ADJD_S311_DRV_NAME, 273 307 }, 274 308 .probe = adjd_s311_probe, 275 - .remove = adjd_s311_remove, 276 309 .id_table = adjd_s311_id, 277 310 }; 278 311 module_i2c_driver(adjd_s311_driver);
+7
drivers/iio/light/cm3323.c
··· 256 256 }; 257 257 MODULE_DEVICE_TABLE(i2c, cm3323_id); 258 258 259 + static const struct of_device_id cm3323_of_match[] = { 260 + { .compatible = "capella,cm3323", }, 261 + { /* sentinel */ } 262 + }; 263 + MODULE_DEVICE_TABLE(of, cm3323_of_match); 264 + 259 265 static struct i2c_driver cm3323_driver = { 260 266 .driver = { 261 267 .name = CM3323_DRV_NAME, 268 + .of_match_table = cm3323_of_match, 262 269 }, 263 270 .probe = cm3323_probe, 264 271 .id_table = cm3323_id,
+4 -7
drivers/iio/light/hid-sensor-als.c
··· 294 294 return ret; 295 295 } 296 296 297 - indio_dev->channels = kmemdup(als_channels, 298 - sizeof(als_channels), GFP_KERNEL); 297 + indio_dev->channels = devm_kmemdup(&pdev->dev, als_channels, 298 + sizeof(als_channels), GFP_KERNEL); 299 299 if (!indio_dev->channels) { 300 300 dev_err(&pdev->dev, "failed to duplicate channels\n"); 301 301 return -ENOMEM; ··· 306 306 HID_USAGE_SENSOR_ALS, als_state); 307 307 if (ret) { 308 308 dev_err(&pdev->dev, "failed to setup attributes\n"); 309 - goto error_free_dev_mem; 309 + return ret; 310 310 } 311 311 312 312 indio_dev->num_channels = ··· 321 321 &als_state->common_attributes); 322 322 if (ret < 0) { 323 323 dev_err(&pdev->dev, "trigger setup failed\n"); 324 - goto error_free_dev_mem; 324 + return ret; 325 325 } 326 326 327 327 ret = iio_device_register(indio_dev); ··· 346 346 iio_device_unregister(indio_dev); 347 347 error_remove_trigger: 348 348 hid_sensor_remove_trigger(indio_dev, &als_state->common_attributes); 349 - error_free_dev_mem: 350 - kfree(indio_dev->channels); 351 349 return ret; 352 350 } 353 351 ··· 359 361 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ALS); 360 362 iio_device_unregister(indio_dev); 361 363 hid_sensor_remove_trigger(indio_dev, &als_state->common_attributes); 362 - kfree(indio_dev->channels); 363 364 364 365 return 0; 365 366 }
+4 -7
drivers/iio/light/hid-sensor-prox.c
··· 253 253 return ret; 254 254 } 255 255 256 - indio_dev->channels = kmemdup(prox_channels, sizeof(prox_channels), 257 - GFP_KERNEL); 256 + indio_dev->channels = devm_kmemdup(&pdev->dev, prox_channels, 257 + sizeof(prox_channels), GFP_KERNEL); 258 258 if (!indio_dev->channels) { 259 259 dev_err(&pdev->dev, "failed to duplicate channels\n"); 260 260 return -ENOMEM; ··· 265 265 HID_USAGE_SENSOR_PROX, prox_state); 266 266 if (ret) { 267 267 dev_err(&pdev->dev, "failed to setup attributes\n"); 268 - goto error_free_dev_mem; 268 + return ret; 269 269 } 270 270 271 271 indio_dev->num_channels = ARRAY_SIZE(prox_channels); ··· 279 279 &prox_state->common_attributes); 280 280 if (ret) { 281 281 dev_err(&pdev->dev, "trigger setup failed\n"); 282 - goto error_free_dev_mem; 282 + return ret; 283 283 } 284 284 285 285 ret = iio_device_register(indio_dev); ··· 304 304 iio_device_unregister(indio_dev); 305 305 error_remove_trigger: 306 306 hid_sensor_remove_trigger(indio_dev, &prox_state->common_attributes); 307 - error_free_dev_mem: 308 - kfree(indio_dev->channels); 309 307 return ret; 310 308 } 311 309 ··· 317 319 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_PROX); 318 320 iio_device_unregister(indio_dev); 319 321 hid_sensor_remove_trigger(indio_dev, &prox_state->common_attributes); 320 - kfree(indio_dev->channels); 321 322 322 323 return 0; 323 324 }
-1
drivers/iio/light/si1145.c
··· 220 220 return -ETIMEDOUT; 221 221 } 222 222 msleep(SI1145_COMMAND_MINSLEEP_MS); 223 - continue; 224 223 } 225 224 } 226 225
+19 -29
drivers/iio/light/tcs3414.c
··· 267 267 .predisable = tcs3414_buffer_predisable, 268 268 }; 269 269 270 + static int tcs3414_powerdown(struct tcs3414_data *data) 271 + { 272 + return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL, 273 + data->control & ~(TCS3414_CONTROL_POWER | 274 + TCS3414_CONTROL_ADC_EN)); 275 + } 276 + 277 + static void tcs3414_powerdown_cleanup(void *data) 278 + { 279 + tcs3414_powerdown(data); 280 + } 281 + 270 282 static int tcs3414_probe(struct i2c_client *client, 271 283 const struct i2c_device_id *id) 272 284 { ··· 321 309 if (ret < 0) 322 310 return ret; 323 311 312 + ret = devm_add_action_or_reset(&client->dev, tcs3414_powerdown_cleanup, 313 + data); 314 + if (ret < 0) 315 + return ret; 316 + 324 317 data->timing = TCS3414_INTEG_12MS; /* free running */ 325 318 ret = i2c_smbus_write_byte_data(data->client, TCS3414_TIMING, 326 319 data->timing); ··· 337 320 return ret; 338 321 data->gain = ret; 339 322 340 - ret = iio_triggered_buffer_setup(indio_dev, NULL, 323 + ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, 341 324 tcs3414_trigger_handler, &tcs3414_buffer_setup_ops); 342 325 if (ret < 0) 343 326 return ret; 344 327 345 - ret = iio_device_register(indio_dev); 346 - if (ret < 0) 347 - goto buffer_cleanup; 348 - 349 - return 0; 350 - 351 - buffer_cleanup: 352 - iio_triggered_buffer_cleanup(indio_dev); 353 - return ret; 354 - } 355 - 356 - static int tcs3414_powerdown(struct tcs3414_data *data) 357 - { 358 - return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL, 359 - data->control & ~(TCS3414_CONTROL_POWER | 360 - TCS3414_CONTROL_ADC_EN)); 361 - } 362 - 363 - static int tcs3414_remove(struct i2c_client *client) 364 - { 365 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 366 - 367 - iio_device_unregister(indio_dev); 368 - iio_triggered_buffer_cleanup(indio_dev); 369 - tcs3414_powerdown(iio_priv(indio_dev)); 370 - 371 - return 0; 328 + return devm_iio_device_register(&client->dev, indio_dev); 372 329 } 373 330 374 331 #ifdef CONFIG_PM_SLEEP ··· 376 385 .pm = &tcs3414_pm_ops, 377 386 }, 378 387 .probe = tcs3414_probe, 379 - .remove = tcs3414_remove, 380 388 .id_table = tcs3414_id, 381 389 }; 382 390 module_i2c_driver(tcs3414_driver);
-12
drivers/iio/magnetometer/st_magn.h
··· 25 25 26 26 #ifdef CONFIG_IIO_BUFFER 27 27 int st_magn_allocate_ring(struct iio_dev *indio_dev); 28 - void st_magn_deallocate_ring(struct iio_dev *indio_dev); 29 28 int st_magn_trig_set_state(struct iio_trigger *trig, bool state); 30 29 #define ST_MAGN_TRIGGER_SET_STATE (&st_magn_trig_set_state) 31 30 #else /* CONFIG_IIO_BUFFER */ 32 - static inline int st_magn_probe_trigger(struct iio_dev *indio_dev, int irq) 33 - { 34 - return 0; 35 - } 36 - static inline void st_magn_remove_trigger(struct iio_dev *indio_dev, int irq) 37 - { 38 - return; 39 - } 40 31 static inline int st_magn_allocate_ring(struct iio_dev *indio_dev) 41 32 { 42 33 return 0; 43 - } 44 - static inline void st_magn_deallocate_ring(struct iio_dev *indio_dev) 45 - { 46 34 } 47 35 #define ST_MAGN_TRIGGER_SET_STATE NULL 48 36 #endif /* CONFIG_IIO_BUFFER */
+3 -13
drivers/iio/magnetometer/st_magn_buffer.c
··· 9 9 10 10 #include <linux/module.h> 11 11 #include <linux/kernel.h> 12 - #include <linux/slab.h> 13 - #include <linux/stat.h> 14 - #include <linux/interrupt.h> 15 - #include <linux/i2c.h> 16 - #include <linux/delay.h> 17 12 #include <linux/iio/iio.h> 18 13 #include <linux/iio/buffer.h> 19 - #include <linux/iio/trigger_consumer.h> 14 + #include <linux/iio/trigger.h> 20 15 #include <linux/iio/triggered_buffer.h> 21 16 22 17 #include <linux/iio/common/st_sensors.h> ··· 41 46 42 47 int st_magn_allocate_ring(struct iio_dev *indio_dev) 43 48 { 44 - return iio_triggered_buffer_setup(indio_dev, NULL, 45 - &st_sensors_trigger_handler, &st_magn_buffer_setup_ops); 46 - } 47 - 48 - void st_magn_deallocate_ring(struct iio_dev *indio_dev) 49 - { 50 - iio_triggered_buffer_cleanup(indio_dev); 49 + return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev, 50 + NULL, &st_sensors_trigger_handler, &st_magn_buffer_setup_ops); 51 51 } 52 52 53 53 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+4 -13
drivers/iio/magnetometer/st_magn_core.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 13 - #include <linux/errno.h> 14 - #include <linux/types.h> 15 - #include <linux/interrupt.h> 16 - #include <linux/i2c.h> 17 - #include <linux/irq.h> 18 - #include <linux/delay.h> 12 + #include <linux/mutex.h> 13 + #include <linux/sysfs.h> 19 14 #include <linux/iio/iio.h> 20 15 #include <linux/iio/sysfs.h> 21 - #include <linux/iio/buffer.h> 16 + #include <linux/iio/trigger.h> 22 17 23 18 #include <linux/iio/common/st_sensors.h> 24 19 #include "st_magn.h" ··· 647 652 err = st_sensors_allocate_trigger(indio_dev, 648 653 ST_MAGN_TRIGGER_OPS); 649 654 if (err < 0) 650 - goto st_magn_probe_trigger_error; 655 + return err; 651 656 } 652 657 653 658 err = iio_device_register(indio_dev); ··· 662 667 st_magn_device_register_error: 663 668 if (mdata->irq > 0) 664 669 st_sensors_deallocate_trigger(indio_dev); 665 - st_magn_probe_trigger_error: 666 - st_magn_deallocate_ring(indio_dev); 667 670 return err; 668 671 } 669 672 EXPORT_SYMBOL(st_magn_common_probe); ··· 673 680 iio_device_unregister(indio_dev); 674 681 if (mdata->irq > 0) 675 682 st_sensors_deallocate_trigger(indio_dev); 676 - 677 - st_magn_deallocate_ring(indio_dev); 678 683 } 679 684 EXPORT_SYMBOL(st_magn_common_remove); 680 685
+1 -1
drivers/iio/magnetometer/st_magn_i2c.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 12 + #include <linux/mod_devicetable.h> 13 13 #include <linux/i2c.h> 14 14 #include <linux/iio/iio.h> 15 15
+1 -1
drivers/iio/magnetometer/st_magn_spi.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 12 + #include <linux/mod_devicetable.h> 13 13 #include <linux/spi/spi.h> 14 14 #include <linux/iio/iio.h> 15 15
+4 -7
drivers/iio/orientation/hid-sensor-incl-3d.c
··· 326 326 return ret; 327 327 } 328 328 329 - indio_dev->channels = kmemdup(incl_3d_channels, 330 - sizeof(incl_3d_channels), GFP_KERNEL); 329 + indio_dev->channels = devm_kmemdup(&pdev->dev, incl_3d_channels, 330 + sizeof(incl_3d_channels), GFP_KERNEL); 331 331 if (!indio_dev->channels) { 332 332 dev_err(&pdev->dev, "failed to duplicate channels\n"); 333 333 return -ENOMEM; ··· 339 339 incl_state); 340 340 if (ret) { 341 341 dev_err(&pdev->dev, "failed to setup attributes\n"); 342 - goto error_free_dev_mem; 342 + return ret; 343 343 } 344 344 345 345 indio_dev->num_channels = ARRAY_SIZE(incl_3d_channels); ··· 353 353 &incl_state->common_attributes); 354 354 if (ret) { 355 355 dev_err(&pdev->dev, "trigger setup failed\n"); 356 - goto error_free_dev_mem; 356 + return ret; 357 357 } 358 358 359 359 ret = iio_device_register(indio_dev); ··· 379 379 iio_device_unregister(indio_dev); 380 380 error_remove_trigger: 381 381 hid_sensor_remove_trigger(indio_dev, &incl_state->common_attributes); 382 - error_free_dev_mem: 383 - kfree(indio_dev->channels); 384 382 return ret; 385 383 } 386 384 ··· 392 394 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_INCLINOMETER_3D); 393 395 iio_device_unregister(indio_dev); 394 396 hid_sensor_remove_trigger(indio_dev, &incl_state->common_attributes); 395 - kfree(indio_dev->channels); 396 397 397 398 return 0; 398 399 }
+9 -13
drivers/iio/potentiometer/max5481.c
··· 125 125 }; 126 126 MODULE_DEVICE_TABLE(of, max5481_match); 127 127 128 + static void max5481_wiper_save(void *data) 129 + { 130 + max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0); 131 + } 132 + 128 133 static int max5481_probe(struct spi_device *spi) 129 134 { 130 135 struct iio_dev *indio_dev; ··· 141 136 if (!indio_dev) 142 137 return -ENOMEM; 143 138 144 - spi_set_drvdata(spi, indio_dev); 145 139 data = iio_priv(indio_dev); 146 140 147 141 data->spi = spi; ··· 162 158 if (ret < 0) 163 159 return ret; 164 160 165 - return iio_device_register(indio_dev); 166 - } 161 + ret = devm_add_action(&spi->dev, max5481_wiper_save, data); 162 + if (ret < 0) 163 + return ret; 167 164 168 - static int max5481_remove(struct spi_device *spi) 169 - { 170 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 171 - struct max5481_data *data = iio_priv(indio_dev); 172 - 173 - iio_device_unregister(indio_dev); 174 - 175 - /* save wiper reg to NV reg */ 176 - return max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0); 165 + return devm_iio_device_register(&spi->dev, indio_dev); 177 166 } 178 167 179 168 static const struct spi_device_id max5481_id_table[] = { ··· 184 187 .of_match_table = max5481_match, 185 188 }, 186 189 .probe = max5481_probe, 187 - .remove = max5481_remove, 188 190 .id_table = max5481_id_table, 189 191 }; 190 192
+28 -23
drivers/iio/pressure/hid-sensor-press.c
··· 13 13 #include <linux/iio/buffer.h> 14 14 #include "../common/hid-sensors/hid-sensor-trigger.h" 15 15 16 - #define CHANNEL_SCAN_INDEX_PRESSURE 0 16 + enum { 17 + CHANNEL_SCAN_INDEX_PRESSURE, 18 + CHANNEL_SCAN_INDEX_TIMESTAMP, 19 + }; 17 20 18 21 struct press_state { 19 22 struct hid_sensor_hub_callbacks callbacks; 20 23 struct hid_sensor_common common_attributes; 21 24 struct hid_sensor_hub_attribute_info press_attr; 22 - u32 press_data; 25 + struct { 26 + u32 press_data; 27 + u64 timestamp __aligned(8); 28 + } scan; 23 29 int scale_pre_decml; 24 30 int scale_post_decml; 25 31 int scale_precision; 26 32 int value_offset; 33 + s64 timestamp; 27 34 }; 28 35 29 36 static const u32 press_sensitivity_addresses[] = { ··· 48 41 BIT(IIO_CHAN_INFO_SAMP_FREQ) | 49 42 BIT(IIO_CHAN_INFO_HYSTERESIS), 50 43 .scan_index = CHANNEL_SCAN_INDEX_PRESSURE, 51 - } 44 + }, 45 + IIO_CHAN_SOFT_TIMESTAMP(CHANNEL_SCAN_INDEX_TIMESTAMP) 46 + 52 47 }; 53 48 54 49 /* Adjust channel real bits based on report descriptor */ ··· 163 154 .write_raw = &press_write_raw, 164 155 }; 165 156 166 - /* Function to push data to buffer */ 167 - static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *data, 168 - int len) 169 - { 170 - dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); 171 - iio_push_to_buffers(indio_dev, data); 172 - } 173 - 174 157 /* Callback handler to send event after all samples are received and captured */ 175 158 static int press_proc_event(struct hid_sensor_hub_device *hsdev, 176 159 unsigned usage_id, ··· 172 171 struct press_state *press_state = iio_priv(indio_dev); 173 172 174 173 dev_dbg(&indio_dev->dev, "press_proc_event\n"); 175 - if (atomic_read(&press_state->common_attributes.data_ready)) 176 - hid_sensor_push_data(indio_dev, 177 - &press_state->press_data, 178 - sizeof(press_state->press_data)); 174 + if (atomic_read(&press_state->common_attributes.data_ready)) { 175 + if (!press_state->timestamp) 176 + press_state->timestamp = iio_get_time_ns(indio_dev); 177 + 178 + iio_push_to_buffers_with_timestamp( 179 + indio_dev, &press_state->scan, press_state->timestamp); 180 + } 179 181 180 182 return 0; 181 183 } ··· 195 191 196 192 switch (usage_id) { 197 193 case HID_USAGE_SENSOR_ATMOSPHERIC_PRESSURE: 198 - press_state->press_data = *(u32 *)raw_data; 194 + press_state->scan.press_data = *(u32 *)raw_data; 199 195 ret = 0; 196 + break; 197 + case HID_USAGE_SENSOR_TIME_TIMESTAMP: 198 + press_state->timestamp = hid_sensor_convert_timestamp( 199 + &press_state->common_attributes, *(s64 *)raw_data); 200 200 break; 201 201 default: 202 202 break; ··· 267 259 return ret; 268 260 } 269 261 270 - indio_dev->channels = kmemdup(press_channels, sizeof(press_channels), 271 - GFP_KERNEL); 262 + indio_dev->channels = devm_kmemdup(&pdev->dev, press_channels, 263 + sizeof(press_channels), GFP_KERNEL); 272 264 if (!indio_dev->channels) { 273 265 dev_err(&pdev->dev, "failed to duplicate channels\n"); 274 266 return -ENOMEM; ··· 279 271 HID_USAGE_SENSOR_PRESSURE, press_state); 280 272 if (ret) { 281 273 dev_err(&pdev->dev, "failed to setup attributes\n"); 282 - goto error_free_dev_mem; 274 + return ret; 283 275 } 284 276 285 277 indio_dev->num_channels = ··· 294 286 &press_state->common_attributes); 295 287 if (ret) { 296 288 dev_err(&pdev->dev, "trigger setup failed\n"); 297 - goto error_free_dev_mem; 289 + return ret; 298 290 } 299 291 300 292 ret = iio_device_register(indio_dev); ··· 319 311 iio_device_unregister(indio_dev); 320 312 error_remove_trigger: 321 313 hid_sensor_remove_trigger(indio_dev, &press_state->common_attributes); 322 - error_free_dev_mem: 323 - kfree(indio_dev->channels); 324 314 return ret; 325 315 } 326 316 ··· 332 326 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_PRESSURE); 333 327 iio_device_unregister(indio_dev); 334 328 hid_sensor_remove_trigger(indio_dev, &press_state->common_attributes); 335 - kfree(indio_dev->channels); 336 329 337 330 return 0; 338 331 }
-5
drivers/iio/pressure/st_pressure.h
··· 43 43 44 44 #ifdef CONFIG_IIO_BUFFER 45 45 int st_press_allocate_ring(struct iio_dev *indio_dev); 46 - void st_press_deallocate_ring(struct iio_dev *indio_dev); 47 46 int st_press_trig_set_state(struct iio_trigger *trig, bool state); 48 47 #define ST_PRESS_TRIGGER_SET_STATE (&st_press_trig_set_state) 49 48 #else /* CONFIG_IIO_BUFFER */ 50 49 static inline int st_press_allocate_ring(struct iio_dev *indio_dev) 51 50 { 52 51 return 0; 53 - } 54 - 55 - static inline void st_press_deallocate_ring(struct iio_dev *indio_dev) 56 - { 57 52 } 58 53 #define ST_PRESS_TRIGGER_SET_STATE NULL 59 54 #endif /* CONFIG_IIO_BUFFER */
+3 -13
drivers/iio/pressure/st_pressure_buffer.c
··· 9 9 10 10 #include <linux/module.h> 11 11 #include <linux/kernel.h> 12 - #include <linux/slab.h> 13 - #include <linux/stat.h> 14 - #include <linux/interrupt.h> 15 - #include <linux/i2c.h> 16 - #include <linux/delay.h> 17 12 #include <linux/iio/iio.h> 18 13 #include <linux/iio/buffer.h> 19 - #include <linux/iio/trigger_consumer.h> 14 + #include <linux/iio/trigger.h> 20 15 #include <linux/iio/triggered_buffer.h> 21 16 22 17 #include <linux/iio/common/st_sensors.h> ··· 41 46 42 47 int st_press_allocate_ring(struct iio_dev *indio_dev) 43 48 { 44 - return iio_triggered_buffer_setup(indio_dev, NULL, 45 - &st_sensors_trigger_handler, &st_press_buffer_setup_ops); 46 - } 47 - 48 - void st_press_deallocate_ring(struct iio_dev *indio_dev) 49 - { 50 - iio_triggered_buffer_cleanup(indio_dev); 49 + return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev, 50 + NULL, &st_sensors_trigger_handler, &st_press_buffer_setup_ops); 51 51 } 52 52 53 53 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+3 -13
drivers/iio/pressure/st_pressure_core.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 13 - #include <linux/errno.h> 14 - #include <linux/types.h> 15 - #include <linux/interrupt.h> 16 - #include <linux/i2c.h> 17 - #include <linux/irq.h> 18 - #include <linux/delay.h> 12 + #include <linux/mutex.h> 13 + #include <linux/sysfs.h> 19 14 #include <linux/iio/iio.h> 20 15 #include <linux/iio/sysfs.h> 21 16 #include <linux/iio/trigger.h> 22 - #include <linux/iio/buffer.h> 23 17 #include <asm/unaligned.h> 24 18 25 19 #include <linux/iio/common/st_sensors.h> ··· 718 724 err = st_sensors_allocate_trigger(indio_dev, 719 725 ST_PRESS_TRIGGER_OPS); 720 726 if (err < 0) 721 - goto st_press_probe_trigger_error; 727 + return err; 722 728 } 723 729 724 730 err = iio_device_register(indio_dev); ··· 733 739 st_press_device_register_error: 734 740 if (press_data->irq > 0) 735 741 st_sensors_deallocate_trigger(indio_dev); 736 - st_press_probe_trigger_error: 737 - st_press_deallocate_ring(indio_dev); 738 742 return err; 739 743 } 740 744 EXPORT_SYMBOL(st_press_common_probe); ··· 744 752 iio_device_unregister(indio_dev); 745 753 if (press_data->irq > 0) 746 754 st_sensors_deallocate_trigger(indio_dev); 747 - 748 - st_press_deallocate_ring(indio_dev); 749 755 } 750 756 EXPORT_SYMBOL(st_press_common_remove); 751 757
+2 -1
drivers/iio/pressure/st_pressure_i2c.c
··· 7 7 * Denis Ciocca <denis.ciocca@st.com> 8 8 */ 9 9 10 + #include <linux/acpi.h> 10 11 #include <linux/kernel.h> 11 12 #include <linux/module.h> 12 - #include <linux/slab.h> 13 + #include <linux/mod_devicetable.h> 13 14 #include <linux/i2c.h> 14 15 #include <linux/iio/iio.h> 15 16
+1 -1
drivers/iio/pressure/st_pressure_spi.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 - #include <linux/slab.h> 12 + #include <linux/mod_devicetable.h> 13 13 #include <linux/spi/spi.h> 14 14 #include <linux/iio/iio.h> 15 15
+33 -50
drivers/iio/proximity/rfd77402.c
··· 90 90 }, 91 91 }; 92 92 93 - static int rfd77402_set_state(struct rfd77402_data *data, u8 state, u16 check) 93 + static int rfd77402_set_state(struct i2c_client *client, u8 state, u16 check) 94 94 { 95 95 int ret; 96 96 97 - ret = i2c_smbus_write_byte_data(data->client, RFD77402_CMD_R, 97 + ret = i2c_smbus_write_byte_data(client, RFD77402_CMD_R, 98 98 state | RFD77402_CMD_VALID); 99 99 if (ret < 0) 100 100 return ret; 101 101 102 102 usleep_range(10000, 20000); 103 103 104 - ret = i2c_smbus_read_word_data(data->client, RFD77402_STATUS_R); 104 + ret = i2c_smbus_read_word_data(client, RFD77402_STATUS_R); 105 105 if (ret < 0) 106 106 return ret; 107 107 if ((ret & RFD77402_STATUS_PM_MASK) != check) ··· 110 110 return 0; 111 111 } 112 112 113 - static int rfd77402_measure(struct rfd77402_data *data) 113 + static int rfd77402_measure(struct i2c_client *client) 114 114 { 115 115 int ret; 116 116 int tries = 10; 117 117 118 - ret = rfd77402_set_state(data, RFD77402_CMD_MCPU_ON, 118 + ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_ON, 119 119 RFD77402_STATUS_MCPU_ON); 120 120 if (ret < 0) 121 121 return ret; 122 122 123 - ret = i2c_smbus_write_byte_data(data->client, RFD77402_CMD_R, 123 + ret = i2c_smbus_write_byte_data(client, RFD77402_CMD_R, 124 124 RFD77402_CMD_SINGLE | 125 125 RFD77402_CMD_VALID); 126 126 if (ret < 0) 127 127 goto err; 128 128 129 129 while (tries-- > 0) { 130 - ret = i2c_smbus_read_byte_data(data->client, RFD77402_ICSR); 130 + ret = i2c_smbus_read_byte_data(client, RFD77402_ICSR); 131 131 if (ret < 0) 132 132 goto err; 133 133 if (ret & RFD77402_ICSR_RESULT) ··· 140 140 goto err; 141 141 } 142 142 143 - ret = i2c_smbus_read_word_data(data->client, RFD77402_RESULT_R); 143 + ret = i2c_smbus_read_word_data(client, RFD77402_RESULT_R); 144 144 if (ret < 0) 145 145 goto err; 146 146 ··· 153 153 return (ret & RFD77402_RESULT_DIST_MASK) >> 2; 154 154 155 155 err: 156 - rfd77402_set_state(data, RFD77402_CMD_MCPU_OFF, 156 + rfd77402_set_state(client, RFD77402_CMD_MCPU_OFF, 157 157 RFD77402_STATUS_MCPU_OFF); 158 158 return ret; 159 159 } ··· 168 168 switch (mask) { 169 169 case IIO_CHAN_INFO_RAW: 170 170 mutex_lock(&data->lock); 171 - ret = rfd77402_measure(data); 171 + ret = rfd77402_measure(data->client); 172 172 mutex_unlock(&data->lock); 173 173 if (ret < 0) 174 174 return ret; ··· 188 188 .read_raw = rfd77402_read_raw, 189 189 }; 190 190 191 - static int rfd77402_init(struct rfd77402_data *data) 191 + static int rfd77402_init(struct i2c_client *client) 192 192 { 193 193 int ret, i; 194 194 195 - ret = rfd77402_set_state(data, RFD77402_CMD_STANDBY, 195 + ret = rfd77402_set_state(client, RFD77402_CMD_STANDBY, 196 196 RFD77402_STATUS_STANDBY); 197 197 if (ret < 0) 198 198 return ret; 199 199 200 200 /* configure INT pad as push-pull, active low */ 201 - ret = i2c_smbus_write_byte_data(data->client, RFD77402_ICSR, 201 + ret = i2c_smbus_write_byte_data(client, RFD77402_ICSR, 202 202 RFD77402_ICSR_INT_MODE); 203 203 if (ret < 0) 204 204 return ret; 205 205 206 206 /* I2C configuration */ 207 - ret = i2c_smbus_write_word_data(data->client, RFD77402_I2C_INIT_CFG, 207 + ret = i2c_smbus_write_word_data(client, RFD77402_I2C_INIT_CFG, 208 208 RFD77402_I2C_ADDR_INCR | 209 209 RFD77402_I2C_DATA_INCR | 210 210 RFD77402_I2C_HOST_DEBUG | ··· 213 213 return ret; 214 214 215 215 /* set initialization */ 216 - ret = i2c_smbus_write_word_data(data->client, RFD77402_PMU_CFG, 0x0500); 216 + ret = i2c_smbus_write_word_data(client, RFD77402_PMU_CFG, 0x0500); 217 217 if (ret < 0) 218 218 return ret; 219 219 220 - ret = rfd77402_set_state(data, RFD77402_CMD_MCPU_OFF, 220 + ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_OFF, 221 221 RFD77402_STATUS_MCPU_OFF); 222 222 if (ret < 0) 223 223 return ret; 224 224 225 225 /* set initialization */ 226 - ret = i2c_smbus_write_word_data(data->client, RFD77402_PMU_CFG, 0x0600); 226 + ret = i2c_smbus_write_word_data(client, RFD77402_PMU_CFG, 0x0600); 227 227 if (ret < 0) 228 228 return ret; 229 229 230 - ret = rfd77402_set_state(data, RFD77402_CMD_MCPU_ON, 230 + ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_ON, 231 231 RFD77402_STATUS_MCPU_ON); 232 232 if (ret < 0) 233 233 return ret; 234 234 235 235 for (i = 0; i < ARRAY_SIZE(rf77402_tof_config); i++) { 236 - ret = i2c_smbus_write_word_data(data->client, 236 + ret = i2c_smbus_write_word_data(client, 237 237 rf77402_tof_config[i].reg, 238 238 rf77402_tof_config[i].val); 239 239 if (ret < 0) 240 240 return ret; 241 241 } 242 242 243 - ret = rfd77402_set_state(data, RFD77402_CMD_STANDBY, 243 + ret = rfd77402_set_state(client, RFD77402_CMD_STANDBY, 244 244 RFD77402_STATUS_STANDBY); 245 245 246 246 return ret; 247 247 } 248 248 249 - static int rfd77402_powerdown(struct rfd77402_data *data) 249 + static int rfd77402_powerdown(struct i2c_client *client) 250 250 { 251 - return rfd77402_set_state(data, RFD77402_CMD_STANDBY, 251 + return rfd77402_set_state(client, RFD77402_CMD_STANDBY, 252 252 RFD77402_STATUS_STANDBY); 253 + } 254 + 255 + static void rfd77402_disable(void *client) 256 + { 257 + rfd77402_powerdown(client); 253 258 } 254 259 255 260 static int rfd77402_probe(struct i2c_client *client, ··· 275 270 return -ENOMEM; 276 271 277 272 data = iio_priv(indio_dev); 278 - i2c_set_clientdata(client, indio_dev); 279 273 data->client = client; 280 274 mutex_init(&data->lock); 281 275 ··· 284 280 indio_dev->name = RFD77402_DRV_NAME; 285 281 indio_dev->modes = INDIO_DIRECT_MODE; 286 282 287 - ret = rfd77402_init(data); 283 + ret = rfd77402_init(client); 288 284 if (ret < 0) 289 285 return ret; 290 286 291 - ret = iio_device_register(indio_dev); 287 + ret = devm_add_action_or_reset(&client->dev, rfd77402_disable, client); 292 288 if (ret) 293 - goto err_powerdown; 289 + return ret; 294 290 295 - return 0; 296 - 297 - err_powerdown: 298 - rfd77402_powerdown(data); 299 - return ret; 300 - } 301 - 302 - static int rfd77402_remove(struct i2c_client *client) 303 - { 304 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 305 - 306 - iio_device_unregister(indio_dev); 307 - rfd77402_powerdown(iio_priv(indio_dev)); 308 - 309 - return 0; 291 + return devm_iio_device_register(&client->dev, indio_dev); 310 292 } 311 293 312 294 #ifdef CONFIG_PM_SLEEP 313 295 static int rfd77402_suspend(struct device *dev) 314 296 { 315 - struct rfd77402_data *data = iio_priv(i2c_get_clientdata( 316 - to_i2c_client(dev))); 317 - 318 - return rfd77402_powerdown(data); 297 + return rfd77402_powerdown(to_i2c_client(dev)); 319 298 } 320 299 321 300 static int rfd77402_resume(struct device *dev) 322 301 { 323 - struct rfd77402_data *data = iio_priv(i2c_get_clientdata( 324 - to_i2c_client(dev))); 325 - 326 - return rfd77402_init(data); 302 + return rfd77402_init(to_i2c_client(dev)); 327 303 } 328 304 #endif 329 305 ··· 321 337 .pm = &rfd77402_pm_ops, 322 338 }, 323 339 .probe = rfd77402_probe, 324 - .remove = rfd77402_remove, 325 340 .id_table = rfd77402_id, 326 341 }; 327 342
+16 -32
drivers/iio/proximity/sx9310.c
··· 20 20 #include <linux/mod_devicetable.h> 21 21 #include <linux/module.h> 22 22 #include <linux/pm.h> 23 + #include <linux/property.h> 23 24 #include <linux/regmap.h> 24 25 #include <linux/regulator/consumer.h> 25 26 #include <linux/slab.h> ··· 1222 1221 } 1223 1222 1224 1223 static const struct sx9310_reg_default * 1225 - sx9310_get_default_reg(struct sx9310_data *data, int idx, 1224 + sx9310_get_default_reg(struct device *dev, int idx, 1226 1225 struct sx9310_reg_default *reg_def) 1227 1226 { 1228 - const struct device_node *np = data->client->dev.of_node; 1229 1227 u32 combined[SX9310_NUM_CHANNELS]; 1230 1228 u32 start = 0, raw = 0, pos = 0; 1231 1229 unsigned long comb_mask = 0; ··· 1232 1232 const char *res; 1233 1233 1234 1234 memcpy(reg_def, &sx9310_default_regs[idx], sizeof(*reg_def)); 1235 - if (!np) 1236 - return reg_def; 1237 - 1238 1235 switch (reg_def->reg) { 1239 1236 case SX9310_REG_PROX_CTRL2: 1240 - if (of_property_read_bool(np, "semtech,cs0-ground")) { 1237 + if (device_property_read_bool(dev, "semtech,cs0-ground")) { 1241 1238 reg_def->def &= ~SX9310_REG_PROX_CTRL2_SHIELDEN_MASK; 1242 1239 reg_def->def |= SX9310_REG_PROX_CTRL2_SHIELDEN_GROUND; 1243 1240 } 1244 1241 1245 - count = of_property_count_elems_of_size(np, "semtech,combined-sensors", 1246 - sizeof(u32)); 1247 - if (count > 0 && count <= ARRAY_SIZE(combined)) { 1248 - ret = of_property_read_u32_array(np, "semtech,combined-sensors", 1249 - combined, count); 1250 - if (ret) 1251 - break; 1252 - } else { 1253 - /* 1254 - * Either the property does not exist in the DT or the 1255 - * number of entries is incorrect. 1256 - */ 1242 + count = device_property_count_u32(dev, "semtech,combined-sensors"); 1243 + if (count < 0 || count > ARRAY_SIZE(combined)) 1257 1244 break; 1258 - } 1259 - for (i = 0; i < count; i++) { 1260 - if (combined[i] >= SX9310_NUM_CHANNELS) { 1261 - /* Invalid sensor (invalid DT). */ 1262 - break; 1263 - } 1245 + ret = device_property_read_u32_array(dev, "semtech,combined-sensors", 1246 + combined, count); 1247 + if (ret) 1248 + break; 1249 + 1250 + for (i = 0; i < count; i++) 1264 1251 comb_mask |= BIT(combined[i]); 1265 - } 1266 - if (i < count) 1267 - break; 1268 1252 1269 1253 reg_def->def &= ~SX9310_REG_PROX_CTRL2_COMBMODE_MASK; 1270 1254 if (comb_mask == (BIT(3) | BIT(2) | BIT(1) | BIT(0))) ··· 1262 1278 1263 1279 break; 1264 1280 case SX9310_REG_PROX_CTRL4: 1265 - ret = of_property_read_string(np, "semtech,resolution", &res); 1281 + ret = device_property_read_string(dev, "semtech,resolution", &res); 1266 1282 if (ret) 1267 1283 break; 1268 1284 ··· 1286 1302 1287 1303 break; 1288 1304 case SX9310_REG_PROX_CTRL5: 1289 - ret = of_property_read_u32(np, "semtech,startup-sensor", &start); 1305 + ret = device_property_read_u32(dev, "semtech,startup-sensor", &start); 1290 1306 if (ret) { 1291 1307 start = FIELD_GET(SX9310_REG_PROX_CTRL5_STARTUPSENS_MASK, 1292 1308 reg_def->def); ··· 1296 1312 reg_def->def |= FIELD_PREP(SX9310_REG_PROX_CTRL5_STARTUPSENS_MASK, 1297 1313 start); 1298 1314 1299 - ret = of_property_read_u32(np, "semtech,proxraw-strength", &raw); 1315 + ret = device_property_read_u32(dev, "semtech,proxraw-strength", &raw); 1300 1316 if (ret) { 1301 1317 raw = FIELD_GET(SX9310_REG_PROX_CTRL5_RAWFILT_MASK, 1302 1318 reg_def->def); ··· 1309 1325 raw); 1310 1326 break; 1311 1327 case SX9310_REG_PROX_CTRL7: 1312 - ret = of_property_read_u32(np, "semtech,avg-pos-strength", &pos); 1328 + ret = device_property_read_u32(dev, "semtech,avg-pos-strength", &pos); 1313 1329 if (ret) 1314 1330 break; 1315 1331 ··· 1345 1361 1346 1362 /* Program some sane defaults. */ 1347 1363 for (i = 0; i < ARRAY_SIZE(sx9310_default_regs); i++) { 1348 - initval = sx9310_get_default_reg(data, i, &tmp); 1364 + initval = sx9310_get_default_reg(&indio_dev->dev, i, &tmp); 1349 1365 ret = regmap_write(data->regmap, initval->reg, initval->def); 1350 1366 if (ret) 1351 1367 return ret;
+336 -17
drivers/iio/proximity/vcnl3020.c
··· 2 2 /* 3 3 * Support for Vishay VCNL3020 proximity sensor on i2c bus. 4 4 * Based on Vishay VCNL4000 driver code. 5 - * 6 - * TODO: interrupts. 7 5 */ 8 6 9 7 #include <linux/module.h> ··· 9 11 #include <linux/err.h> 10 12 #include <linux/delay.h> 11 13 #include <linux/regmap.h> 14 + #include <linux/interrupt.h> 12 15 13 16 #include <linux/iio/iio.h> 14 - #include <linux/iio/sysfs.h> 17 + #include <linux/iio/events.h> 15 18 16 19 #define VCNL3020_PROD_ID 0x21 17 20 ··· 36 37 * measurement 37 38 */ 38 39 40 + /* Enables periodic proximity measurement */ 41 + #define VCNL_PS_EN BIT(1) 42 + 43 + /* Enables state machine and LP oscillator for self timed measurements */ 44 + #define VCNL_PS_SELFTIMED_EN BIT(0) 45 + 46 + /* Bit masks for ICR */ 47 + 48 + /* Enable interrupts on low or high thresholds */ 49 + #define VCNL_ICR_THRES_EN BIT(1) 50 + 51 + /* Bit masks for ISR */ 52 + #define VCNL_INT_TH_HI BIT(0) /* High threshold hit */ 53 + #define VCNL_INT_TH_LOW BIT(1) /* Low threshold hit */ 54 + 39 55 #define VCNL_ON_DEMAND_TIMEOUT_US 100000 40 56 #define VCNL_POLL_US 20000 41 57 ··· 71 57 * @dev: vcnl3020 device. 72 58 * @rev: revision id. 73 59 * @lock: lock for protecting access to device hardware registers. 60 + * @buf: DMA safe __be16 buffer. 74 61 */ 75 62 struct vcnl3020_data { 76 63 struct regmap *regmap; 77 64 struct device *dev; 78 65 u8 rev; 79 66 struct mutex lock; 67 + __be16 buf ____cacheline_aligned; 80 68 }; 81 69 82 70 /** ··· 156 140 vcnl3020_led_current_property); 157 141 }; 158 142 143 + static bool vcnl3020_is_in_periodic_mode(struct vcnl3020_data *data) 144 + { 145 + int rc; 146 + unsigned int cmd; 147 + 148 + rc = regmap_read(data->regmap, VCNL_COMMAND, &cmd); 149 + if (rc) { 150 + dev_err(data->dev, 151 + "Error (%d) reading command register\n", rc); 152 + return false; 153 + } 154 + 155 + return !!(cmd & VCNL_PS_SELFTIMED_EN); 156 + } 157 + 159 158 static int vcnl3020_measure_proximity(struct vcnl3020_data *data, int *val) 160 159 { 161 160 int rc; 162 161 unsigned int reg; 163 - __be16 res; 164 162 165 163 mutex_lock(&data->lock); 164 + 165 + /* Protect against event capture. */ 166 + if (vcnl3020_is_in_periodic_mode(data)) { 167 + rc = -EBUSY; 168 + goto err_unlock; 169 + } 166 170 167 171 rc = regmap_write(data->regmap, VCNL_COMMAND, VCNL_PS_OD); 168 172 if (rc) ··· 199 163 } 200 164 201 165 /* high & low result bytes read */ 202 - rc = regmap_bulk_read(data->regmap, VCNL_PS_RESULT_HI, &res, 203 - sizeof(res)); 166 + rc = regmap_bulk_read(data->regmap, VCNL_PS_RESULT_HI, &data->buf, 167 + sizeof(data->buf)); 204 168 if (rc) 205 169 goto err_unlock; 206 170 207 - *val = be16_to_cpu(res); 171 + *val = be16_to_cpu(data->buf); 208 172 209 173 err_unlock: 210 174 mutex_unlock(&data->lock); ··· 236 200 { 237 201 unsigned int i; 238 202 int index = -1; 203 + int rc; 204 + 205 + mutex_lock(&data->lock); 206 + 207 + /* Protect against event capture. */ 208 + if (vcnl3020_is_in_periodic_mode(data)) { 209 + rc = -EBUSY; 210 + goto err_unlock; 211 + } 239 212 240 213 for (i = 0; i < ARRAY_SIZE(vcnl3020_prox_sampling_frequency); i++) { 241 214 if (val == vcnl3020_prox_sampling_frequency[i][0] && ··· 254 209 } 255 210 } 256 211 257 - if (index < 0) 258 - return -EINVAL; 212 + if (index < 0) { 213 + rc = -EINVAL; 214 + goto err_unlock; 215 + } 259 216 260 - return regmap_write(data->regmap, VCNL_PROXIMITY_RATE, index); 217 + rc = regmap_write(data->regmap, VCNL_PROXIMITY_RATE, index); 218 + if (rc) 219 + dev_err(data->dev, 220 + "Error (%d) writing proximity rate register\n", rc); 221 + 222 + err_unlock: 223 + mutex_unlock(&data->lock); 224 + 225 + return rc; 261 226 } 227 + 228 + static bool vcnl3020_is_thr_enabled(struct vcnl3020_data *data) 229 + { 230 + int rc; 231 + unsigned int icr; 232 + 233 + rc = regmap_read(data->regmap, VCNL_PS_ICR, &icr); 234 + if (rc) { 235 + dev_err(data->dev, 236 + "Error (%d) reading ICR register\n", rc); 237 + return false; 238 + } 239 + 240 + return !!(icr & VCNL_ICR_THRES_EN); 241 + } 242 + 243 + static int vcnl3020_read_event(struct iio_dev *indio_dev, 244 + const struct iio_chan_spec *chan, 245 + enum iio_event_type type, 246 + enum iio_event_direction dir, 247 + enum iio_event_info info, 248 + int *val, int *val2) 249 + { 250 + int rc; 251 + struct vcnl3020_data *data = iio_priv(indio_dev); 252 + 253 + switch (info) { 254 + case IIO_EV_INFO_VALUE: 255 + switch (dir) { 256 + case IIO_EV_DIR_RISING: 257 + rc = regmap_bulk_read(data->regmap, VCNL_PS_HI_THR_HI, 258 + &data->buf, sizeof(data->buf)); 259 + if (rc < 0) 260 + return rc; 261 + *val = be16_to_cpu(data->buf); 262 + return IIO_VAL_INT; 263 + case IIO_EV_DIR_FALLING: 264 + rc = regmap_bulk_read(data->regmap, VCNL_PS_LO_THR_HI, 265 + &data->buf, sizeof(data->buf)); 266 + if (rc < 0) 267 + return rc; 268 + *val = be16_to_cpu(data->buf); 269 + return IIO_VAL_INT; 270 + default: 271 + return -EINVAL; 272 + } 273 + default: 274 + return -EINVAL; 275 + } 276 + } 277 + 278 + static int vcnl3020_write_event(struct iio_dev *indio_dev, 279 + const struct iio_chan_spec *chan, 280 + enum iio_event_type type, 281 + enum iio_event_direction dir, 282 + enum iio_event_info info, 283 + int val, int val2) 284 + { 285 + int rc; 286 + struct vcnl3020_data *data = iio_priv(indio_dev); 287 + 288 + mutex_lock(&data->lock); 289 + 290 + switch (info) { 291 + case IIO_EV_INFO_VALUE: 292 + switch (dir) { 293 + case IIO_EV_DIR_RISING: 294 + /* 16 bit word/ low * high */ 295 + data->buf = cpu_to_be16(val); 296 + rc = regmap_bulk_write(data->regmap, VCNL_PS_HI_THR_HI, 297 + &data->buf, sizeof(data->buf)); 298 + if (rc < 0) 299 + goto err_unlock; 300 + rc = IIO_VAL_INT; 301 + goto err_unlock; 302 + case IIO_EV_DIR_FALLING: 303 + data->buf = cpu_to_be16(val); 304 + rc = regmap_bulk_write(data->regmap, VCNL_PS_LO_THR_HI, 305 + &data->buf, sizeof(data->buf)); 306 + if (rc < 0) 307 + goto err_unlock; 308 + rc = IIO_VAL_INT; 309 + goto err_unlock; 310 + default: 311 + rc = -EINVAL; 312 + goto err_unlock; 313 + } 314 + default: 315 + rc = -EINVAL; 316 + goto err_unlock; 317 + } 318 + err_unlock: 319 + mutex_unlock(&data->lock); 320 + 321 + return rc; 322 + } 323 + 324 + static int vcnl3020_enable_periodic(struct iio_dev *indio_dev, 325 + struct vcnl3020_data *data) 326 + { 327 + int rc; 328 + int cmd; 329 + 330 + mutex_lock(&data->lock); 331 + 332 + /* Enable periodic measurement of proximity data. */ 333 + cmd = VCNL_PS_EN | VCNL_PS_SELFTIMED_EN; 334 + 335 + rc = regmap_write(data->regmap, VCNL_COMMAND, cmd); 336 + if (rc) { 337 + dev_err(data->dev, 338 + "Error (%d) writing command register\n", rc); 339 + goto err_unlock; 340 + } 341 + 342 + /* 343 + * Enable interrupts on threshold, for proximity data by 344 + * default. 345 + */ 346 + rc = regmap_write(data->regmap, VCNL_PS_ICR, VCNL_ICR_THRES_EN); 347 + if (rc) 348 + dev_err(data->dev, 349 + "Error (%d) reading ICR register\n", rc); 350 + 351 + err_unlock: 352 + mutex_unlock(&data->lock); 353 + 354 + return rc; 355 + } 356 + 357 + static int vcnl3020_disable_periodic(struct iio_dev *indio_dev, 358 + struct vcnl3020_data *data) 359 + { 360 + int rc; 361 + 362 + mutex_lock(&data->lock); 363 + 364 + rc = regmap_write(data->regmap, VCNL_COMMAND, 0); 365 + if (rc) { 366 + dev_err(data->dev, 367 + "Error (%d) writing command register\n", rc); 368 + goto err_unlock; 369 + } 370 + 371 + rc = regmap_write(data->regmap, VCNL_PS_ICR, 0); 372 + if (rc) { 373 + dev_err(data->dev, 374 + "Error (%d) writing ICR register\n", rc); 375 + goto err_unlock; 376 + } 377 + 378 + /* Clear interrupt flag bit */ 379 + rc = regmap_write(data->regmap, VCNL_ISR, 0); 380 + if (rc) 381 + dev_err(data->dev, 382 + "Error (%d) writing ISR register\n", rc); 383 + 384 + err_unlock: 385 + mutex_unlock(&data->lock); 386 + 387 + return rc; 388 + } 389 + 390 + static int vcnl3020_config_threshold(struct iio_dev *indio_dev, bool state) 391 + { 392 + struct vcnl3020_data *data = iio_priv(indio_dev); 393 + 394 + if (state) { 395 + return vcnl3020_enable_periodic(indio_dev, data); 396 + } else { 397 + if (!vcnl3020_is_thr_enabled(data)) 398 + return 0; 399 + return vcnl3020_disable_periodic(indio_dev, data); 400 + } 401 + } 402 + 403 + static int vcnl3020_write_event_config(struct iio_dev *indio_dev, 404 + const struct iio_chan_spec *chan, 405 + enum iio_event_type type, 406 + enum iio_event_direction dir, 407 + int state) 408 + { 409 + switch (chan->type) { 410 + case IIO_PROXIMITY: 411 + return vcnl3020_config_threshold(indio_dev, state); 412 + default: 413 + return -EINVAL; 414 + } 415 + } 416 + 417 + static int vcnl3020_read_event_config(struct iio_dev *indio_dev, 418 + const struct iio_chan_spec *chan, 419 + enum iio_event_type type, 420 + enum iio_event_direction dir) 421 + { 422 + struct vcnl3020_data *data = iio_priv(indio_dev); 423 + 424 + switch (chan->type) { 425 + case IIO_PROXIMITY: 426 + return vcnl3020_is_thr_enabled(data); 427 + default: 428 + return -EINVAL; 429 + } 430 + } 431 + 432 + static const struct iio_event_spec vcnl3020_event_spec[] = { 433 + { 434 + .type = IIO_EV_TYPE_THRESH, 435 + .dir = IIO_EV_DIR_RISING, 436 + .mask_separate = BIT(IIO_EV_INFO_VALUE), 437 + }, { 438 + .type = IIO_EV_TYPE_THRESH, 439 + .dir = IIO_EV_DIR_FALLING, 440 + .mask_separate = BIT(IIO_EV_INFO_VALUE), 441 + }, { 442 + .type = IIO_EV_TYPE_THRESH, 443 + .dir = IIO_EV_DIR_EITHER, 444 + .mask_separate = BIT(IIO_EV_INFO_ENABLE), 445 + }, 446 + }; 262 447 263 448 static const struct iio_chan_spec vcnl3020_channels[] = { 264 449 { ··· 496 221 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 497 222 BIT(IIO_CHAN_INFO_SAMP_FREQ), 498 223 .info_mask_separate_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 224 + .event_spec = vcnl3020_event_spec, 225 + .num_event_specs = ARRAY_SIZE(vcnl3020_event_spec), 499 226 }, 500 227 }; 501 228 ··· 528 251 struct iio_chan_spec const *chan, 529 252 int val, int val2, long mask) 530 253 { 531 - int rc; 532 254 struct vcnl3020_data *data = iio_priv(indio_dev); 533 255 534 256 switch (mask) { 535 257 case IIO_CHAN_INFO_SAMP_FREQ: 536 - rc = iio_device_claim_direct_mode(indio_dev); 537 - if (rc) 538 - return rc; 539 - rc = vcnl3020_write_proxy_samp_freq(data, val, val2); 540 - iio_device_release_direct_mode(indio_dev); 541 - return rc; 258 + return vcnl3020_write_proxy_samp_freq(data, val, val2); 542 259 default: 543 260 return -EINVAL; 544 261 } ··· 558 287 .read_raw = vcnl3020_read_raw, 559 288 .write_raw = vcnl3020_write_raw, 560 289 .read_avail = vcnl3020_read_avail, 290 + .read_event_value = vcnl3020_read_event, 291 + .write_event_value = vcnl3020_write_event, 292 + .read_event_config = vcnl3020_read_event_config, 293 + .write_event_config = vcnl3020_write_event_config, 561 294 }; 562 295 563 296 static const struct regmap_config vcnl3020_regmap_config = { ··· 569 294 .val_bits = 8, 570 295 .max_register = VCNL_PS_MOD_ADJ, 571 296 }; 297 + 298 + static irqreturn_t vcnl3020_handle_irq_thread(int irq, void *p) 299 + { 300 + struct iio_dev *indio_dev = p; 301 + struct vcnl3020_data *data = iio_priv(indio_dev); 302 + unsigned int isr; 303 + int rc; 304 + 305 + rc = regmap_read(data->regmap, VCNL_ISR, &isr); 306 + if (rc) { 307 + dev_err(data->dev, "Error (%d) reading reg (0x%x)\n", 308 + rc, VCNL_ISR); 309 + return IRQ_HANDLED; 310 + } 311 + 312 + if (!(isr & VCNL_ICR_THRES_EN)) 313 + return IRQ_NONE; 314 + 315 + iio_push_event(indio_dev, 316 + IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 1, 317 + IIO_EV_TYPE_THRESH, 318 + IIO_EV_DIR_RISING), 319 + iio_get_time_ns(indio_dev)); 320 + 321 + rc = regmap_write(data->regmap, VCNL_ISR, isr & VCNL_ICR_THRES_EN); 322 + if (rc) 323 + dev_err(data->dev, "Error (%d) writing in reg (0x%x)\n", 324 + rc, VCNL_ISR); 325 + 326 + return IRQ_HANDLED; 327 + } 572 328 573 329 static int vcnl3020_probe(struct i2c_client *client) 574 330 { ··· 632 326 indio_dev->num_channels = ARRAY_SIZE(vcnl3020_channels); 633 327 indio_dev->name = "vcnl3020"; 634 328 indio_dev->modes = INDIO_DIRECT_MODE; 329 + 330 + if (client->irq) { 331 + rc = devm_request_threaded_irq(&client->dev, client->irq, 332 + NULL, vcnl3020_handle_irq_thread, 333 + IRQF_ONESHOT, indio_dev->name, 334 + indio_dev); 335 + if (rc) { 336 + dev_err(&client->dev, 337 + "Error (%d) irq request failed (%u)\n", rc, 338 + client->irq); 339 + return rc; 340 + } 341 + } 635 342 636 343 return devm_iio_device_register(&client->dev, indio_dev); 637 344 }
+31 -22
drivers/iio/temperature/tmp006.c
··· 193 193 return mid == TMP006_MANUFACTURER_MAGIC && did == TMP006_DEVICE_MAGIC; 194 194 } 195 195 196 + static int tmp006_power(struct device *dev, bool up) 197 + { 198 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 199 + struct tmp006_data *data = iio_priv(indio_dev); 200 + 201 + if (up) 202 + data->config |= TMP006_CONFIG_MOD_MASK; 203 + else 204 + data->config &= ~TMP006_CONFIG_MOD_MASK; 205 + 206 + return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, 207 + data->config); 208 + } 209 + 210 + static void tmp006_powerdown_cleanup(void *dev) 211 + { 212 + tmp006_power(dev, false); 213 + } 214 + 196 215 static int tmp006_probe(struct i2c_client *client, 197 216 const struct i2c_device_id *id) 198 217 { ··· 247 228 return ret; 248 229 data->config = ret; 249 230 250 - return iio_device_register(indio_dev); 251 - } 231 + if ((ret & TMP006_CONFIG_MOD_MASK) != TMP006_CONFIG_MOD_MASK) { 232 + ret = tmp006_power(&client->dev, true); 233 + if (ret < 0) 234 + return ret; 235 + } 252 236 253 - static int tmp006_powerdown(struct tmp006_data *data) 254 - { 255 - return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, 256 - data->config & ~TMP006_CONFIG_MOD_MASK); 257 - } 237 + ret = devm_add_action_or_reset(&client->dev, tmp006_powerdown_cleanup, 238 + &client->dev); 239 + if (ret < 0) 240 + return ret; 258 241 259 - static int tmp006_remove(struct i2c_client *client) 260 - { 261 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 262 - 263 - iio_device_unregister(indio_dev); 264 - tmp006_powerdown(iio_priv(indio_dev)); 265 - 266 - return 0; 242 + return devm_iio_device_register(&client->dev, indio_dev); 267 243 } 268 244 269 245 #ifdef CONFIG_PM_SLEEP 270 246 static int tmp006_suspend(struct device *dev) 271 247 { 272 - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 273 - return tmp006_powerdown(iio_priv(indio_dev)); 248 + return tmp006_power(dev, false); 274 249 } 275 250 276 251 static int tmp006_resume(struct device *dev) 277 252 { 278 - struct tmp006_data *data = iio_priv(i2c_get_clientdata( 279 - to_i2c_client(dev))); 280 - return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, 281 - data->config | TMP006_CONFIG_MOD_MASK); 253 + return tmp006_power(dev, true); 282 254 } 283 255 #endif 284 256 ··· 287 277 .pm = &tmp006_pm_ops, 288 278 }, 289 279 .probe = tmp006_probe, 290 - .remove = tmp006_remove, 291 280 .id_table = tmp006_id, 292 281 }; 293 282 module_i2c_driver(tmp006_driver);
+1
include/dt-bindings/iio/adc/ingenic,adc.h
··· 13 13 #define INGENIC_ADC_TOUCH_YN 6 14 14 #define INGENIC_ADC_TOUCH_XD 7 15 15 #define INGENIC_ADC_TOUCH_YD 8 16 + #define INGENIC_ADC_AUX0 9 16 17 17 18 #endif
+16 -16
include/linux/counter.h
··· 162 162 void *priv; 163 163 }; 164 164 165 - enum counter_count_function { 166 - COUNTER_COUNT_FUNCTION_INCREASE = 0, 167 - COUNTER_COUNT_FUNCTION_DECREASE, 168 - COUNTER_COUNT_FUNCTION_PULSE_DIRECTION, 169 - COUNTER_COUNT_FUNCTION_QUADRATURE_X1_A, 170 - COUNTER_COUNT_FUNCTION_QUADRATURE_X1_B, 171 - COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A, 172 - COUNTER_COUNT_FUNCTION_QUADRATURE_X2_B, 173 - COUNTER_COUNT_FUNCTION_QUADRATURE_X4 165 + enum counter_function { 166 + COUNTER_FUNCTION_INCREASE = 0, 167 + COUNTER_FUNCTION_DECREASE, 168 + COUNTER_FUNCTION_PULSE_DIRECTION, 169 + COUNTER_FUNCTION_QUADRATURE_X1_A, 170 + COUNTER_FUNCTION_QUADRATURE_X1_B, 171 + COUNTER_FUNCTION_QUADRATURE_X2_A, 172 + COUNTER_FUNCTION_QUADRATURE_X2_B, 173 + COUNTER_FUNCTION_QUADRATURE_X4 174 174 }; 175 175 176 176 /** ··· 192 192 const char *name; 193 193 194 194 size_t function; 195 - const enum counter_count_function *functions_list; 195 + const enum counter_function *functions_list; 196 196 size_t num_functions; 197 197 198 198 struct counter_synapse *synapses; ··· 290 290 const struct attribute_group **groups; 291 291 }; 292 292 293 - enum counter_signal_value { 294 - COUNTER_SIGNAL_LOW = 0, 295 - COUNTER_SIGNAL_HIGH 293 + enum counter_signal_level { 294 + COUNTER_SIGNAL_LEVEL_LOW, 295 + COUNTER_SIGNAL_LEVEL_HIGH, 296 296 }; 297 297 298 298 /** 299 299 * struct counter_ops - Callbacks from driver 300 300 * @signal_read: optional read callback for Signal attribute. The read 301 - * value of the respective Signal should be passed back via 302 - * the val parameter. 301 + * level of the respective Signal should be passed back via 302 + * the level parameter. 303 303 * @count_read: optional read callback for Count attribute. The read 304 304 * value of the respective Count should be passed back via 305 305 * the val parameter. ··· 324 324 struct counter_ops { 325 325 int (*signal_read)(struct counter_device *counter, 326 326 struct counter_signal *signal, 327 - enum counter_signal_value *val); 327 + enum counter_signal_level *level); 328 328 int (*count_read)(struct counter_device *counter, 329 329 struct counter_count *count, unsigned long *val); 330 330 int (*count_write)(struct counter_device *counter,