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

Merge tag 'iio-for-6.13b' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-next

Jonathan writes:

IIO: 2nd set of new device support, features and cleanup for 6.13

Alongside new drivers and device support there are several large
cleanups going on across the IIO tree and we see part of some of those
in this pull request.

Merged char-misc-next at point of 6.12-rc6 merge to avoid a
conflict with a fix for the ad7380 merged earlier this cycle.
Note that I previously messed this merge up and had to reconstruct
it this morning so a coherent pull request was possible. The new
stuff is all the same as has been in linux-next for some time with
the exception of the kernel-doc related __private ordering fix
that went in yesterday.

New device support
==================

adi,ad7380
- Support for adaq4370-4 and adaq4370 quad channel ADCs.
adi,ad7606
- Various cleanups preceeding support of AD7607, AD7608 and AD7609 ADCs.
adi,ad7779
- New driver supproting AD7770, AD7771 and AD7779 ADCs.
allegro,als31300
- New driver for this 3D Linear Hall Effect sensor.
bosch,bmi270
- Add support BMI260 which is similar but requires a different firmware image.
bosch,smi240
- New driver for this IMU.
ti,opt3001
- Add support opt3002 light sensor which has a wider spectral range than
the opt3001.
vishay,veml3235
- New driver for this ambient light sensor.

Features
========

hid-sensors
- Add support Human Proximity Range and Attention detection (requiring
a new classification style channel type)
adi,ad3552r
- Add backend support and related platform driver to support use
with an FPGA IP to allow QSPI + DDR bus operation and much higher
data aquisition rates. (various rework preceeded this feature)
adi,ad7606
- Various cleanup prior to enabling use with an IIO Backend and PWM trigger
enabling much higher speed data capture.
bosch,bme680
- Support control of preheat current
- Support triggered buffer capture
- Add SCALE and RAW channels (needed to enable the buffered capture).
bosch,bmp280
- Enable sleeping to save power.
- Add interrupt support for bmp3xx and bmp5xx devices. Also update bmp085
to new approach.
- Enable data ready trigger.
bosch,bmi270
- Add triggered buffer support
- Add scale and sampling frequency control.
vishay,veml6070
- Support integration time via DT binding for an external resistor value.

Cleanup and minor fixes
=======================

core
- Fix a longstanding issue with event codes for differential channels.
Note that not all drivers are yet fixed, but macros have been added
to avoid potential repeats of this in future.
- Tidy up handling in iio_read_acpi_mount matrix.
- Mark iio_dev::priv with __private. Later move the marking before the
field name to avoid a kernel-doc issue.
treewide
- Drop some pointless default n entries in Kconfig.
- Add an iio_get_acpi_device_name_and_data() handler to replace some
commonly repeated code.
- simplify use of 'state' in write_event_config() callback as it is
effectively a boolean. Once done make it a boolean (lots of drivers
were updated to enable this)
- some more use of devm_regulator_get_enable_read_voltage( to replace
open coded versions. Where this enables it convert all of remove
handling to devm based and drop the remove callback.
- check returns from devm_mutex_init()
accel drivers
- Use aligned_s64 instead of s64 __aligned(8)
adi,ad5791
- Add some missing GPIOs and power supplies that presumably were always
hard wired on previous boards.
- Refactor to use chip_info in device id tables.
- Convert probe entirely to devm based simplify code and allowing remove()
callback to be dropped.
adi,ad7192
- Check return from spi_get_device_match_data()
adi,ad74413r
- Don't keep an unnecessary copy of the gpio after probe.
- Use devm_regulator_get_enable_read_voltage() instead of open coding.
- Apply cleanup.h approach to reduce complexity.
adi,dac8460
- Fix a wrong compaitble ID due to a stray space.
- Add an spi_device_id table.
bosch,bmc150
- Drop some likely false ACPI IDs.
- Drop left over unused ACPI specific code.
bosch,bme680
- Add mising regmap.h include.
- Reduce excessive sleep on startup.
- Drop some cammelcase usage.
- Use fsleep
- Generalize read functions to allow for reuse.
- Use s16 variable to avoid some incorrect casting
bosch,bmg150
- Drop some likely false ACPI IDs.
bosch,bmi270
- Drop unused FREQUENCY and SCALE attributes that always returned an
error (they wil be back impelmented correctly).
- Factor out the chip specific data into a structure to enable simple
support for additional devices.
isil,isl29018
- Drop ACPI_PTR() and CONFIG_ACPI guards as not worth the trouble for very
minor saving.
invensense,mpu6050
- Use much simpler test for ACPI firmware.
kionix,kxcjk-1013
- Drop unnecessary ACPI entry in the i2c_device_id table.
- Drop support KX022-1020 to fix a bug that was introduced with that change.
Hopefully a fixed version will replace it soon.
- Drop CONFIG guards for PM in favor of pm_ptr() and the compiler removing
dead code.
- Switch from enum to chip_info structure and add ODR times to that structure.
- Deduplicate one of those ODR structures
- Drop ACPI_PTR() and move ID table out of config guards.
- Minor additional cleanup.
liteon,ltr401
- Drop some likely false ACPI Ids and add LTER0303 which is know to be in use.
microchip,pac1934
- Use much simpler test for ACPI firmware.
vishay,veml6070
- Use unsigned int instead of just unsigned.
- Use FIELD_PREP to make setting of field value explicit.

Various other minor fixes to documentation

* tag 'iio-for-6.13b' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (153 commits)
iio: Move __private marking before struct element priv in struct iio_dev
docs: iio: ad7380: add adaq4370-4 and adaq4380-4
iio: adc: ad7380: add support for adaq4370-4 and adaq4380-4
iio: adc: ad7380: use local dev variable to shorten long lines
iio: adc: ad7380: fix oversampling formula
dt-bindings: iio: adc: ad7380: add adaq4370-4 and adaq4380-4 compatible parts
iio: chemical: bme680: Add support for preheat current
iio: chemical: bme680: Add triggered buffer support
iio: chemical: bme680: Add SCALE and RAW channels
iio: chemical: bme680: refactorize set_mode() mode
iio: events: make IIO_EVENT_CODE macro private
iio: accel: mma9553: use specialized event code macros
iio: dummy: use specialized event code macros
iio: adc: ad7280a: use IIO_DIFF_EVENT_CODE macro helper
iio: events.h: add event identifier macros for differential channel
iio: magnetometer: add Allegro MicroSystems ALS31300 3-D Linear Hall Effect driver
dt-bindings: iio: magnetometer: document the Allegro MicroSystems ALS31300 3-D Linear Hall Effect Sensor
dt-bindings: vendor-prefixes: Add Allegro MicroSystems, Inc
iio: light: apds9960: remove useless return
iio: light: apds9960: convert als_int and pxs_int to bool
...

+8322 -2216
+32
Documentation/ABI/testing/sysfs-bus-iio
··· 2268 2268 An example format is 16-bytes, 2-digits-per-byte, HEX-string 2269 2269 representing the sensor unique ID number. 2270 2270 2271 + What: /sys/bus/iio/devices/iio:deviceX/filter_type_available 2272 + What: /sys/bus/iio/devices/iio:deviceX/in_voltage-voltage_filter_mode_available 2273 + KernelVersion: 6.1 2274 + Contact: linux-iio@vger.kernel.org 2275 + Description: 2276 + Reading returns a list with the possible filter modes. Options 2277 + for the attribute: 2278 + 2279 + * "sinc3" - The digital sinc3 filter. Moderate 1st 2280 + conversion time. Good noise performance. 2281 + * "sinc4" - Sinc 4. Excellent noise performance. Long 2282 + 1st conversion time. 2283 + * "sinc5" - The digital sinc5 filter. Excellent noise 2284 + performance 2285 + * "sinc4+sinc1" - Sinc4 + averaging by 8. Low 1st conversion 2286 + time. 2287 + * "sinc3+rej60" - Sinc3 + 60Hz rejection. 2288 + * "sinc3+sinc1" - Sinc3 + averaging by 8. Low 1st conversion 2289 + time. 2290 + * "sinc3+pf1" - Sinc3 + device specific Post Filter 1. 2291 + * "sinc3+pf2" - Sinc3 + device specific Post Filter 2. 2292 + * "sinc3+pf3" - Sinc3 + device specific Post Filter 3. 2293 + * "sinc3+pf4" - Sinc3 + device specific Post Filter 4. 2294 + 2271 2295 What: /sys/.../events/in_proximity_thresh_either_runningperiod 2272 2296 KernelVersion: 6.6 2273 2297 Contact: linux-iio@vger.kernel.org ··· 2363 2339 Contact: linux-iio@vger.kernel.org 2364 2340 Description: 2365 2341 The value of current sense resistor in Ohms. 2342 + 2343 + What: /sys/.../iio:deviceX/in_attention_input 2344 + KernelVersion: 6.13 2345 + Contact: linux-iio@vger.kernel.org 2346 + Description: 2347 + Value representing the user's attention to the system expressed 2348 + in units as percentage. This usually means if the user is 2349 + looking at the screen or not.
-46
Documentation/ABI/testing/sysfs-bus-iio-adc-ad4130
··· 1 - What: /sys/bus/iio/devices/iio:deviceX/in_voltage-voltage_filter_mode_available 2 - KernelVersion: 6.2 3 - Contact: linux-iio@vger.kernel.org 4 - Description: 5 - Reading returns a list with the possible filter modes. 6 - 7 - * "sinc4" - Sinc 4. Excellent noise performance. Long 8 - 1st conversion time. No natural 50/60Hz rejection. 9 - 10 - * "sinc4+sinc1" - Sinc4 + averaging by 8. Low 1st conversion 11 - time. 12 - 13 - * "sinc3" - Sinc3. Moderate 1st conversion time. 14 - Good noise performance. 15 - 16 - * "sinc3+rej60" - Sinc3 + 60Hz rejection. At a sampling 17 - frequency of 50Hz, achieves simultaneous 50Hz and 60Hz 18 - rejection. 19 - 20 - * "sinc3+sinc1" - Sinc3 + averaging by 8. Low 1st conversion 21 - time. Best used with a sampling frequency of at least 22 - 216.19Hz. 23 - 24 - * "sinc3+pf1" - Sinc3 + Post Filter 1. 53dB rejection @ 25 - 50Hz, 58dB rejection @ 60Hz. 26 - 27 - * "sinc3+pf2" - Sinc3 + Post Filter 2. 70dB rejection @ 28 - 50Hz, 70dB rejection @ 60Hz. 29 - 30 - * "sinc3+pf3" - Sinc3 + Post Filter 3. 99dB rejection @ 31 - 50Hz, 103dB rejection @ 60Hz. 32 - 33 - * "sinc3+pf4" - Sinc3 + Post Filter 4. 103dB rejection @ 34 - 50Hz, 109dB rejection @ 60Hz. 35 - 36 - What: /sys/bus/iio/devices/iio:deviceX/in_voltageY-voltageZ_filter_mode 37 - KernelVersion: 6.2 38 - Contact: linux-iio@vger.kernel.org 39 - Description: 40 - Set the filter mode of the differential channel. When the filter 41 - mode changes, the in_voltageY-voltageZ_sampling_frequency and 42 - in_voltageY-voltageZ_sampling_frequency_available attributes 43 - might also change to accommodate the new filter mode. 44 - If the current sampling frequency is out of range for the new 45 - filter mode, the sampling frequency will be changed to the 46 - closest valid one.
+120
Documentation/devicetree/bindings/iio/adc/adi,ad7380.yaml
··· 25 25 * https://www.analog.com/en/products/ad7386-4.html 26 26 * https://www.analog.com/en/products/ad7387-4.html 27 27 * https://www.analog.com/en/products/ad7388-4.html 28 + * https://www.analog.com/en/products/adaq4370-4.html 29 + * https://www.analog.com/en/products/adaq4380-4.html 28 30 29 31 30 32 $ref: /schemas/spi/spi-peripheral-props.yaml# ··· 48 46 - adi,ad7386-4 49 47 - adi,ad7387-4 50 48 - adi,ad7388-4 49 + - adi,adaq4370-4 50 + - adi,adaq4380-4 51 51 52 52 reg: 53 53 maxItems: 1 ··· 74 70 refin-supply: 75 71 description: 76 72 A 2.5V to 3.3V supply for external reference voltage, for ad7380-4 only. 73 + For adaq devices, a 5V supply voltage. A 3.3V internal reference is 74 + derived from it. Connect to vs-p-supply for normal operation. 75 + 76 + vs-p-supply: 77 + description: 78 + Amplifiers positive supply. 79 + 80 + vs-n-supply: 81 + description: 82 + Amplifiers negative supply. 83 + 84 + ldo-supply: 85 + description: 86 + LDO supply. Connect to vs-p-supply or a 3.6 to 5.5 V supply. 77 87 78 88 aina-supply: 79 89 description: ··· 115 97 specify the ALERT interrupt. 116 98 maxItems: 1 117 99 100 + "#address-cells": 101 + const: 1 102 + 103 + "#size-cells": 104 + const: 0 105 + 118 106 required: 119 107 - compatible 120 108 - reg 121 109 - vcc-supply 122 110 - vlogic-supply 111 + 112 + patternProperties: 113 + "^channel@[0-3]$": 114 + $ref: adc.yaml 115 + type: object 116 + 117 + properties: 118 + reg: 119 + description: 120 + The channel number. From 0 to 3 corresponding to channels A,B,C,D 121 + minimum: 0 122 + maximum: 3 123 + 124 + adi,gain-milli: 125 + description: 126 + The hardware gain applied to the ADC input (in milli units). 127 + If not present, default to 1000 (no actual gain applied). 128 + Refer to the typical connection diagrams section of the datasheet for 129 + pin wiring. 130 + $ref: /schemas/types.yaml#/definitions/uint16 131 + enum: [300, 600, 1000, 1600] 132 + default: 1000 133 + 134 + required: 135 + - reg 136 + 137 + additionalProperties: false 123 138 124 139 unevaluatedProperties: false 125 140 ··· 191 140 aind-supply: false 192 141 193 142 # ad7380-4 uses refin-supply as external reference. 143 + # adaq devices use internal reference only, derived from refin-supply 194 144 # All other chips from ad738x family use refio as optional external reference. 195 145 # When refio-supply is omitted, internal reference is used. 196 146 - if: ··· 199 147 compatible: 200 148 enum: 201 149 - adi,ad7380-4 150 + - adi,adaq4370-4 151 + - adi,adaq4380-4 202 152 then: 203 153 properties: 204 154 refio-supply: false ··· 209 155 else: 210 156 properties: 211 157 refin-supply: false 158 + 159 + # adaq devices need more supplies and using channel to declare gain property 160 + # only applies to adaq devices 161 + - if: 162 + properties: 163 + compatible: 164 + enum: 165 + - adi,adaq4370-4 166 + - adi,adaq4380-4 167 + then: 168 + required: 169 + - vs-p-supply 170 + - vs-n-supply 171 + - ldo-supply 172 + else: 173 + properties: 174 + vs-p-supply: false 175 + vs-n-supply: false 176 + ldo-supply: false 177 + patternProperties: 178 + "^channel@[0-3]$": false 212 179 213 180 examples: 214 181 - | ··· 253 178 vcc-supply = <&supply_3_3V>; 254 179 vlogic-supply = <&supply_3_3V>; 255 180 refio-supply = <&supply_2_5V>; 181 + }; 182 + }; 183 + 184 + - | 185 + #include <dt-bindings/interrupt-controller/irq.h> 186 + 187 + spi { 188 + #address-cells = <1>; 189 + #size-cells = <0>; 190 + 191 + adc@0 { 192 + compatible = "adi,adaq4380-4"; 193 + reg = <0>; 194 + 195 + spi-cpol; 196 + spi-cpha; 197 + spi-max-frequency = <80000000>; 198 + 199 + interrupts = <27 IRQ_TYPE_EDGE_FALLING>; 200 + interrupt-parent = <&gpio0>; 201 + 202 + vcc-supply = <&supply_3_3V>; 203 + vlogic-supply = <&supply_3_3V>; 204 + refin-supply = <&supply_5V>; 205 + vs-p-supply = <&supply_5V>; 206 + vs-n-supply = <&supply_0V>; 207 + ldo-supply = <&supply_5V>; 208 + 209 + #address-cells = <1>; 210 + #size-cells = <0>; 211 + 212 + channel@0 { 213 + reg = <0>; 214 + adi,gain-milli = /bits/ 16 <300>; 215 + }; 216 + 217 + channel@2 { 218 + reg = <2>; 219 + adi,gain-milli = /bits/ 16 <600>; 220 + }; 221 + 222 + channel@3 { 223 + reg = <3>; 224 + adi,gain-milli = /bits/ 16 <1000>; 225 + }; 256 226 }; 257 227 };
+76 -5
Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
··· 16 16 https://www.analog.com/media/en/technical-documentation/data-sheets/AD7606B.pdf 17 17 https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606c-16.pdf 18 18 https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606c-18.pdf 19 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7607.pdf 20 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7608.pdf 21 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7609.pdf 19 22 https://www.analog.com/media/en/technical-documentation/data-sheets/AD7616.pdf 20 23 21 24 properties: ··· 31 28 - adi,ad7606b 32 29 - adi,ad7606c-16 33 30 - adi,ad7606c-18 31 + - adi,ad7607 32 + - adi,ad7608 33 + - adi,ad7609 34 34 - adi,ad7616 35 35 36 36 reg: ··· 45 39 "#size-cells": 46 40 const: 0 47 41 42 + # According to the datasheet, "Data is clocked in from SDI on the falling 43 + # edge of SCLK, while data is clocked out on DOUTA on the rising edge of 44 + # SCLK". Also, even if not stated textually in the datasheet, it is made 45 + # clear on the diagrams that sclk idles at high. Subsequently, in case SPI 46 + # interface is used, the correct way is to only set spi-cpol. 48 47 spi-cpha: true 49 48 50 49 spi-cpol: true ··· 135 124 assumed that the pins are hardwired to VDD. 136 125 type: boolean 137 126 127 + pwms: 128 + description: 129 + In case the conversion is triggered by a PWM instead of a GPIO plugged to 130 + the CONVST pin, the PWM must be referenced. 131 + The first is the PWM connected to CONVST or CONVST1 for the chips with the 132 + 2nd PWM connected to CONVST2, if CONVST2 is available and not shorted to 133 + CONVST1. 134 + minItems: 1 135 + maxItems: 2 136 + 137 + pwm-names: 138 + items: 139 + - const: convst1 140 + - const: convst2 141 + 142 + io-backends: 143 + description: 144 + A reference to the iio-backend, which is responsible handling the BUSY 145 + pin's falling edge and communication. 146 + An example of backend can be found at 147 + http://analogdevicesinc.github.io/hdl/library/axi_ad7606x/index.html 148 + 149 + 138 150 patternProperties: 139 151 "^channel@[1-8]$": 140 152 type: object ··· 202 168 required: 203 169 - compatible 204 170 - reg 205 - - spi-cpha 206 171 - avcc-supply 207 172 - vdrive-supply 208 - - interrupts 209 - - adi,conversion-start-gpios 210 173 211 174 allOf: 212 175 - $ref: /schemas/spi/spi-peripheral-props.yaml# 176 + 177 + - oneOf: 178 + - required: 179 + - adi,conversion-start-gpios 180 + - required: 181 + - pwms 182 + 183 + - oneOf: 184 + - required: 185 + - interrupts 186 + - required: 187 + - io-backends 213 188 214 189 - if: 215 190 properties: ··· 256 213 - adi,ad7606-4 257 214 - adi,ad7606-6 258 215 - adi,ad7606-8 216 + - adi,ad7607 217 + - adi,ad7608 218 + - adi,ad7609 259 219 then: 260 220 properties: 261 221 adi,sw-mode: false 262 222 else: 263 223 properties: 224 + pwms: 225 + maxItems: 1 226 + pwm-names: 227 + maxItems: 1 264 228 adi,conversion-start-gpios: 265 229 maxItems: 1 266 230 ··· 295 245 examples: 296 246 - | 297 247 #include <dt-bindings/gpio/gpio.h> 248 + iio-backend { 249 + #address-cells = <1>; 250 + #size-cells = <0>; 251 + adi_adc@0 { 252 + compatible = "adi,ad7606b"; 253 + reg = <0>; 254 + pwms = <&axi_pwm_gen 0 0>; 255 + 256 + avcc-supply = <&adc_vref>; 257 + vdrive-supply = <&vdd_supply>; 258 + 259 + reset-gpios = <&gpio0 91 GPIO_ACTIVE_HIGH>; 260 + standby-gpios = <&gpio0 90 GPIO_ACTIVE_LOW>; 261 + adi,range-gpios = <&gpio0 89 GPIO_ACTIVE_HIGH>; 262 + adi,oversampling-ratio-gpios = <&gpio0 88 GPIO_ACTIVE_HIGH 263 + &gpio0 87 GPIO_ACTIVE_HIGH 264 + &gpio0 86 GPIO_ACTIVE_HIGH>; 265 + io-backends = <&iio_backend>; 266 + }; 267 + }; 268 + 269 + - | 270 + #include <dt-bindings/gpio/gpio.h> 298 271 #include <dt-bindings/interrupt-controller/irq.h> 299 272 spi { 300 273 #address-cells = <1>; ··· 328 255 reg = <0>; 329 256 spi-max-frequency = <1000000>; 330 257 spi-cpol; 331 - spi-cpha; 332 258 333 259 avcc-supply = <&adc_vref>; 334 260 vdrive-supply = <&vdd_supply>; ··· 360 288 361 289 spi-max-frequency = <1000000>; 362 290 spi-cpol; 363 - spi-cpha; 364 291 365 292 avcc-supply = <&adc_vref>; 366 293 vdrive-supply = <&vdd_supply>;
+110
Documentation/devicetree/bindings/iio/adc/adi,ad7779.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/adc/adi,ad7779.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD777X family 8-Channel, 24-Bit, Simultaneous Sampling ADCs 8 + 9 + maintainers: 10 + - Ramona Nechita <ramona.nechita@analog.com> 11 + 12 + description: | 13 + The AD777X family consist of 8-channel, simultaneous sampling analog-to- 14 + digital converter (ADC). Eight full Σ-Δ ADCs are on-chip. The 15 + AD7771 provides an ultralow input current to allow direct sensor 16 + connection. Each input channel has a programmable gain stage 17 + allowing gains of 1, 2, 4, and 8 to map lower amplitude sensor 18 + outputs into the full-scale ADC input range, maximizing the 19 + dynamic range of the signal chain. 20 + 21 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7770.pdf 22 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7771.pdf 23 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7779.pdf 24 + 25 + $ref: /schemas/spi/spi-peripheral-props.yaml# 26 + 27 + properties: 28 + compatible: 29 + enum: 30 + - adi,ad7770 31 + - adi,ad7771 32 + - adi,ad7779 33 + 34 + reg: 35 + maxItems: 1 36 + 37 + '#address-cells': 38 + const: 1 39 + 40 + '#size-cells': 41 + const: 0 42 + 43 + clocks: 44 + maxItems: 1 45 + 46 + avdd1-supply: 47 + description: Front-End analog supply AVDD1. Can be used as conversion ref. 48 + 49 + avdd2-supply: 50 + description: AVDD2 Analog Supply from 2.2 V to 3.6 V. 51 + 52 + avdd4-supply: 53 + description: AVDD4 SAR Analog Supply and Reference Source. 54 + 55 + interrupts: 56 + minItems: 1 57 + items: 58 + - description: | 59 + adc_rdy: Interrupt line for DRDY signal which indicates the end of 60 + conversion independently of the interface selected to read back the 61 + Σ-∆ conversion. 62 + - description: | 63 + Alert: The chip includes self diagnostic features to guarantee the 64 + correct operation. If an error is detected, the ALERT pin is pulled 65 + high to generate an external interruption to the controller. 66 + 67 + interrupt-names: 68 + minItems: 1 69 + maxItems: 2 70 + items: 71 + enum: 72 + - adc_rdy 73 + - alert 74 + 75 + start-gpios: 76 + description: 77 + Pin that controls start synchronization pulse. 78 + maxItems: 1 79 + 80 + reset-gpios: 81 + maxItems: 1 82 + 83 + required: 84 + - compatible 85 + - reg 86 + - clocks 87 + - interrupts 88 + 89 + unevaluatedProperties: false 90 + 91 + examples: 92 + - | 93 + #include <dt-bindings/gpio/gpio.h> 94 + #include <dt-bindings/interrupt-controller/irq.h> 95 + spi { 96 + #address-cells = <1>; 97 + #size-cells = <0>; 98 + 99 + adc@0 { 100 + compatible = "adi,ad7779"; 101 + reg = <0>; 102 + start-gpios = <&gpio0 87 GPIO_ACTIVE_LOW>; 103 + reset-gpios = <&gpio0 93 GPIO_ACTIVE_LOW>; 104 + interrupt-parent = <&intc>; 105 + interrupts = <0 56 IRQ_TYPE_LEVEL_HIGH>; 106 + interrupt-names = "adc_rdy"; 107 + clocks = <&adc_clk>; 108 + }; 109 + }; 110 + ...
+7
Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml
··· 60 60 $ref: /schemas/types.yaml#/definitions/uint32 61 61 enum: [0, 1, 2, 3] 62 62 63 + io-backends: 64 + description: The iio backend reference. 65 + Device can be optionally connected to the "axi-ad3552r IP" fpga-based 66 + QSPI + DDR (Double Data Rate) controller to reach high speed transfers. 67 + maxItems: 1 68 + 63 69 '#address-cells': 64 70 const: 1 65 71 ··· 134 128 - custom-output-range-config 135 129 136 130 allOf: 131 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 137 132 - if: 138 133 properties: 139 134 compatible:
+39
Documentation/devicetree/bindings/iio/dac/adi,ad5791.yaml
··· 26 26 vdd-supply: true 27 27 vss-supply: true 28 28 29 + vcc-supply: 30 + description: 31 + Supply that powers the chip. 32 + 33 + iovcc-supply: 34 + description: 35 + Supply for the digital interface. 36 + 37 + vrefp-supply: 38 + description: 39 + Positive referance input voltage range. From 5v to (vdd - 2.5) 40 + 41 + vrefn-supply: 42 + description: 43 + Negative referance input voltage range. From (vss + 2.5) to 0. 44 + 29 45 adi,rbuf-gain2-en: 30 46 description: Specify to allow an external amplifier to be connected in a 31 47 gain of two configuration. 32 48 type: boolean 49 + 50 + reset-gpios: 51 + maxItems: 1 52 + 53 + clear-gpios: 54 + maxItems: 1 55 + 56 + ldac-gpios: 57 + description: 58 + LDAC pin to be used as a hardware trigger to update the DAC channels. 59 + maxItems: 1 33 60 34 61 required: 35 62 - compatible 36 63 - reg 37 64 - vdd-supply 38 65 - vss-supply 66 + - vcc-supply 67 + - iovcc-supply 68 + - vrefp-supply 69 + - vrefn-supply 39 70 40 71 allOf: 41 72 - $ref: /schemas/spi/spi-peripheral-props.yaml# ··· 75 44 76 45 examples: 77 46 - | 47 + #include <dt-bindings/gpio/gpio.h> 78 48 spi { 79 49 #address-cells = <1>; 80 50 #size-cells = <0>; ··· 85 53 reg = <0>; 86 54 vss-supply = <&dac_vss>; 87 55 vdd-supply = <&dac_vdd>; 56 + vcc-supply = <&dac_vcc>; 57 + iovcc-supply = <&dac_iovcc>; 58 + vrefp-supply = <&dac_vrefp>; 59 + vrefn-supply = <&dac_vrefn>; 60 + reset-gpios = <&gpio_bd 16 GPIO_ACTIVE_LOW>; 61 + clear-gpios = <&gpio_bd 17 GPIO_ACTIVE_LOW>; 62 + ldac-gpios = <&gpio_bd 18 GPIO_ACTIVE_HIGH>; 88 63 }; 89 64 }; 90 65 ...
+66 -3
Documentation/devicetree/bindings/iio/dac/adi,axi-dac.yaml
··· 19 19 memory via DMA into the DAC. 20 20 21 21 https://wiki.analog.com/resources/fpga/docs/axi_dac_ip 22 + https://analogdevicesinc.github.io/hdl/library/axi_ad3552r/index.html 22 23 23 24 properties: 24 25 compatible: 25 26 enum: 26 27 - adi,axi-dac-9.1.b 28 + - adi,axi-ad3552r 27 29 28 30 reg: 29 31 maxItems: 1 ··· 38 36 - const: tx 39 37 40 38 clocks: 41 - maxItems: 1 39 + minItems: 1 40 + maxItems: 2 41 + 42 + clock-names: 43 + items: 44 + - const: s_axi_aclk 45 + - const: dac_clk 46 + minItems: 1 42 47 43 48 '#io-backend-cells': 44 49 const: 0 ··· 56 47 - reg 57 48 - clocks 58 49 59 - additionalProperties: false 50 + allOf: 51 + - if: 52 + properties: 53 + compatible: 54 + contains: 55 + const: adi,axi-ad3552r 56 + then: 57 + $ref: /schemas/spi/spi-controller.yaml# 58 + properties: 59 + clocks: 60 + minItems: 2 61 + clock-names: 62 + minItems: 2 63 + required: 64 + - clock-names 65 + else: 66 + properties: 67 + clocks: 68 + maxItems: 1 69 + clock-names: 70 + maxItems: 1 71 + 72 + unevaluatedProperties: false 60 73 61 74 examples: 62 75 - | ··· 88 57 dmas = <&tx_dma 0>; 89 58 dma-names = "tx"; 90 59 #io-backend-cells = <0>; 91 - clocks = <&axi_clk>; 60 + clocks = <&clkc 15>; 61 + clock-names = "s_axi_aclk"; 62 + }; 63 + 64 + - | 65 + #include <dt-bindings/gpio/gpio.h> 66 + axi_dac: spi@44a70000 { 67 + compatible = "adi,axi-ad3552r"; 68 + reg = <0x44a70000 0x1000>; 69 + dmas = <&dac_tx_dma 0>; 70 + dma-names = "tx"; 71 + #io-backend-cells = <0>; 72 + clocks = <&clkc 15>, <&ref_clk>; 73 + clock-names = "s_axi_aclk", "dac_clk"; 74 + 75 + #address-cells = <1>; 76 + #size-cells = <0>; 77 + 78 + dac@0 { 79 + compatible = "adi,ad3552r"; 80 + reg = <0>; 81 + reset-gpios = <&gpio0 92 GPIO_ACTIVE_HIGH>; 82 + io-backends = <&axi_dac>; 83 + spi-max-frequency = <20000000>; 84 + 85 + #address-cells = <1>; 86 + #size-cells = <0>; 87 + 88 + channel@0 { 89 + reg = <0>; 90 + adi,output-range-microvolt = <(-10000000) (10000000)>; 91 + }; 92 + }; 92 93 }; 93 94 ...
+3 -1
Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml
··· 18 18 19 19 properties: 20 20 compatible: 21 - const: bosch,bmi270 21 + enum: 22 + - bosch,bmi260 23 + - bosch,bmi270 22 24 23 25 reg: 24 26 maxItems: 1
+51
Documentation/devicetree/bindings/iio/imu/bosch,smi240.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/imu/bosch,smi240.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Bosch smi240 imu 8 + 9 + maintainers: 10 + - Jianping Shen <Jianping.Shen@de.bosch.com> 11 + 12 + description: 13 + Inertial Measurement Unit with Accelerometer and Gyroscope 14 + with a measurement range of +/-300°/s and up to 16g. 15 + https://www.bosch-semiconductors.com/mems-sensors/highly-automated-driving/smi240/ 16 + 17 + properties: 18 + compatible: 19 + const: bosch,smi240 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + vdd-supply: true 25 + vddio-supply: true 26 + 27 + required: 28 + - compatible 29 + - reg 30 + - vdd-supply 31 + - vddio-supply 32 + 33 + allOf: 34 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 35 + 36 + unevaluatedProperties: false 37 + 38 + examples: 39 + - | 40 + spi { 41 + #address-cells = <1>; 42 + #size-cells = <0>; 43 + 44 + imu@0 { 45 + compatible = "bosch,smi240"; 46 + reg = <0>; 47 + vdd-supply = <&vdd>; 48 + vddio-supply = <&vddio>; 49 + spi-max-frequency = <10000000>; 50 + }; 51 + };
+3 -1
Documentation/devicetree/bindings/iio/light/ti,opt3001.yaml
··· 15 15 16 16 properties: 17 17 compatible: 18 - const: ti,opt3001 18 + enum: 19 + - ti,opt3001 20 + - ti,opt3002 19 21 20 22 reg: 21 23 maxItems: 1
+4 -1
Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml
··· 4 4 $id: http://devicetree.org/schemas/iio/light/vishay,veml6030.yaml# 5 5 $schema: http://devicetree.org/meta-schemas/core.yaml# 6 6 7 - title: VEML6030, VEML6035 and VEML7700 Ambient Light Sensors (ALS) 7 + title: VEML3235, VEML6030, VEML6035 and VEML7700 Ambient Light Sensors (ALS) 8 8 9 9 maintainers: 10 10 - Rishi Gupta <gupt21@gmail.com> ··· 20 20 whenever configured threshold is crossed. 21 21 22 22 Specifications about the sensors can be found at: 23 + https://www.vishay.com/docs/80131/veml3235.pdf 23 24 https://www.vishay.com/docs/84366/veml6030.pdf 24 25 https://www.vishay.com/docs/84889/veml6035.pdf 25 26 https://www.vishay.com/docs/84286/veml7700.pdf ··· 28 27 properties: 29 28 compatible: 30 29 enum: 30 + - vishay,veml3235 31 31 - vishay,veml6030 32 32 - vishay,veml6035 33 33 - vishay,veml7700 ··· 78 76 properties: 79 77 compatible: 80 78 enum: 79 + - vishay,veml3235 81 80 - vishay,veml7700 82 81 then: 83 82 properties:
+18
Documentation/devicetree/bindings/iio/light/vishay,veml6075.yaml
··· 22 22 reg: 23 23 maxItems: 1 24 24 25 + vishay,rset-ohms: 26 + description: 27 + Resistor used to select the integration time. 28 + default: 270000 29 + minimum: 75000 30 + maximum: 1200000 31 + 25 32 vdd-supply: true 26 33 27 34 required: 28 35 - compatible 29 36 - reg 30 37 - vdd-supply 38 + 39 + allOf: 40 + - if: 41 + properties: 42 + compatible: 43 + enum: 44 + - vishay,veml6040 45 + - vishay,veml6075 46 + then: 47 + properties: 48 + vishay,rset-ohms: false 31 49 32 50 additionalProperties: false 33 51
+46
Documentation/devicetree/bindings/iio/magnetometer/allegromicro,als31300.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/magnetometer/allegromicro,als31300.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Allegro MicroSystems ALS31300 3-D Linear Hall Effect sensor 8 + 9 + maintainers: 10 + - Neil Armstrong <neil.armstrong@linaro.org> 11 + 12 + properties: 13 + $nodename: 14 + pattern: '^magnetometer@[0-9a-f]+$' 15 + 16 + compatible: 17 + enum: 18 + - allegromicro,als31300-500 # Factory configured at 500 Gauss input range 19 + - allegromicro,als31300-1000 # Factory configured at 1000 Gauss input range 20 + - allegromicro,als31300-2000 # Factory configured at 2000 Gauss input range 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + vcc-supply: 26 + description: 5.5V supply 27 + 28 + interrupts: 29 + maxItems: 1 30 + 31 + required: 32 + - compatible 33 + 34 + additionalProperties: false 35 + 36 + examples: 37 + - | 38 + i2c { 39 + #address-cells = <1>; 40 + #size-cells = <0>; 41 + magnetometer@61 { 42 + compatible = "allegromicro,als31300-500"; 43 + reg = <0x61>; 44 + vcc-supply = <&hall_vcc>; 45 + }; 46 + };
+20 -2
Documentation/devicetree/bindings/iio/pressure/bmp085.yaml
··· 47 47 maxItems: 1 48 48 49 49 interrupts: 50 - description: 51 - interrupt mapping for IRQ (BMP085 only) 52 50 maxItems: 1 51 + 52 + drive-open-drain: 53 + description: 54 + set if the interrupt pin should be configured as open drain. 55 + If not set, defaults to push-pull configuration. 56 + type: boolean 53 57 54 58 required: 55 59 - compatible 56 60 - vddd-supply 57 61 - vdda-supply 62 + 63 + allOf: 64 + - if: 65 + properties: 66 + compatible: 67 + not: 68 + contains: 69 + enum: 70 + - bosch,bmp085 71 + - bosch,bmp380 72 + - bosch,bmp580 73 + then: 74 + properties: 75 + interrupts: false 58 76 59 77 additionalProperties: false 60 78
+2
Documentation/devicetree/bindings/vendor-prefixes.yaml
··· 83 83 description: ALFA Network Inc. 84 84 "^allegro,.*": 85 85 description: Allegro DVT 86 + "^allegromicro,.*": 87 + description: Allegro MicroSystems, Inc. 86 88 "^alliedvision,.*": 87 89 description: Allied Vision Technologies GmbH 88 90 "^allo,.*":
+16
Documentation/iio/ad7380.rst
··· 27 27 * `AD7386-4 <https://www.analog.com/en/products/ad7386-4.html>`_ 28 28 * `AD7387-4 <https://www.analog.com/en/products/ad7387-4.html>`_ 29 29 * `AD7388-4 <https://www.analog.com/en/products/ad7388-4.html>`_ 30 + * `ADAQ4370-4 <https://www.analog.com/en/products/adaq4370-4.html>`_ 31 + * `ADAQ4380-4 <https://www.analog.com/en/products/adaq4380-4.html>`_ 30 32 31 33 32 34 Supported features ··· 48 46 49 47 ad7380-4 supports only an external reference voltage (2.5V to 3.3V). It must be 50 48 declared in the device tree as ``refin-supply``. 49 + 50 + ADAQ devices 51 + ~~~~~~~~~~~~ 52 + 53 + adaq4370-4 and adaq4380-4 don't have an external reference, but use a 3.3V 54 + internal reference derived from one of its supplies (``refin-supply``) 51 55 52 56 All other devices from ad738x family 53 57 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ··· 128 120 129 121 130 122 When enabling sequencer mode, the effective sampling rate is divided by two. 123 + 124 + Gain (ADAQ devices only) 125 + ~~~~~~~~~~~~~~~~~~~~~~~~ 126 + 127 + ADAQ devices have a pin selectable gain in front of each ADC. The appropriate 128 + gain is selectable from device tree using the ``adi,gain-milli`` property. 129 + Refer to the typical connection diagrams section of the datasheet for pin 130 + wiring. 131 131 132 132 Unimplemented features 133 133 ----------------------
+144
Documentation/iio/ad7606.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0-only 2 + 3 + ============= 4 + AD7606 driver 5 + ============= 6 + 7 + ADC driver for Analog Devices Inc. AD7606 and similar devices. The module name 8 + is ``ad7606``. 9 + 10 + Supported devices 11 + ================= 12 + 13 + The following chips are supported by this driver: 14 + 15 + * `AD7605 <https://www.analog.com/en/products/ad7605.html>`_ 16 + * `AD7606 <https://www.analog.com/en/products/ad7606.html>`_ 17 + * `AD7606B <https://www.analog.com/en/products/ad7606b.html>`_ 18 + * `AD7616 <https://www.analog.com/en/products/ad7616.html>`_ 19 + 20 + Supported features 21 + ================== 22 + 23 + SPI wiring modes 24 + ---------------- 25 + 26 + These ADCs can output data on several SDO lines (1/2/4/8). The driver 27 + currently supports only 1 SDO line. 28 + 29 + Parallel wiring mode 30 + -------------------- 31 + 32 + There is also a parallel interface, with 16 lines (that can be reduced to 8 in 33 + byte mode). The parallel interface is selected by declaring the device as 34 + platform in the device tree (with no io-backends node defined, see below). 35 + 36 + IIO-backend mode 37 + ---------------- 38 + 39 + This mode allows to reach the best sample rates, but it requires an external 40 + hardware (eg HDL or APU) to handle the low level communication. 41 + The backend mode is enabled when through the definition of the "io-backends" 42 + property in the device tree. 43 + 44 + The reference configuration for the current implementation of IIO-backend mode 45 + is the HDL reference provided by ADI: 46 + https://wiki.analog.com/resources/eval/user-guides/ad7606x-fmc/hdl 47 + 48 + This implementation embeds an IIO-backend compatible IP (adi-axi-adc) and a PWM 49 + connected to the conversion trigger pin. 50 + 51 + .. code-block:: 52 + 53 + +---+ +---------------------------- 54 + | | +-------+ |AD76xx 55 + | A | controls | | | 56 + | D |-------------->| PWM |-------------->| cnvst 57 + | 7 | | | | 58 + | 6 | +-------+ | 59 + | 0 | controls +-----------+-----------+ | 60 + | 6 |---------->| | |<--| frstdata 61 + | | | Backend | Backend |<--| busy 62 + | D | | Driver | | | 63 + | R | | | |-->| clk 64 + | I | requests |+---------+| DMA | | 65 + | V |----------->| Buffer ||<---- |<=>| DATA 66 + | E | |+---------+| | | 67 + | R | +-----------+-----------+ | 68 + | |-------------------------------------->| reset/configuration gpios 69 + +---+ +----------------------------- 70 + 71 + 72 + Software and hardware modes 73 + --------------------------- 74 + 75 + While all the AD7606/AD7616 series parts can be configured using GPIOs, some of 76 + them can be configured using register. 77 + 78 + The chips that support software mode have more values available for configuring 79 + the device, as well as more settings, and allow to control the range and 80 + calibration per channel. 81 + 82 + The following settings are available per channel in software mode: 83 + - Scale 84 + 85 + Also, there is a broader choice of oversampling ratios in software mode. 86 + 87 + Conversion triggering 88 + --------------------- 89 + 90 + The conversion can be triggered by two distinct ways: 91 + 92 + - A GPIO is connected to the conversion trigger pin, and this GPIO is controlled 93 + by the driver directly. In this configuration, the driver sets back the 94 + conversion trigger pin to high as soon as it has read all the conversions. 95 + 96 + - An external source is connected to the conversion trigger pin. In the 97 + current implementation, it must be a PWM. In this configuration, the driver 98 + does not control directly the conversion trigger pin. Instead, it can 99 + control the PWM's frequency. This trigger is enabled only for iio-backend. 100 + 101 + Reference voltage 102 + ----------------- 103 + 104 + 2 possible reference voltage sources are supported: 105 + 106 + - Internal reference (2.5V) 107 + - External reference (2.5V) 108 + 109 + The source is determined by the device tree. If ``refin-supply`` is present, 110 + then the external reference is used, otherwise the internal reference is used. 111 + 112 + Oversampling 113 + ------------ 114 + 115 + This family supports oversampling to improve SNR. 116 + In software mode, the following ratios are available: 117 + 1 (oversampling disabled)/2/4/8/16/32/64/128/256. 118 + 119 + Unimplemented features 120 + ---------------------- 121 + 122 + - 2/4/8 SDO lines 123 + - CRC indication 124 + - Calibration 125 + 126 + Device buffers 127 + ============== 128 + 129 + IIO triggered buffer 130 + -------------------- 131 + 132 + This driver supports IIO triggered buffers, with a "built in" trigger, i.e the 133 + trigger is allocated and linked by the driver, and a new conversion is triggered 134 + as soon as the samples are transferred, and a timestamp channel is added to make 135 + up for the potential jitter induced by the delays in the interrupt handling. 136 + 137 + IIO backend buffer 138 + ------------------ 139 + 140 + When IIO backend is used, the trigger is not needed, and the sample rate is 141 + considered as stable. There is no timestamp channel. The communication is 142 + delegated to an external logic, called a backend, and the backend's driver 143 + handles the buffer. When this mode is enabled, the driver cannot control the 144 + conversion pin, because the busy pin is bound to the backend.
+1
Documentation/iio/index.rst
··· 21 21 ad4000 22 22 ad4695 23 23 ad7380 24 + ad7606 24 25 ad7625 25 26 ad7944 26 27 adis16475
+7 -1
MAINTAINERS
··· 1255 1255 L: linux-iio@vger.kernel.org 1256 1256 S: Supported 1257 1257 W: https://ez.analog.com/linux-software-drivers 1258 - F: Documentation/ABI/testing/sysfs-bus-iio-adc-ad4130 1259 1258 F: Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml 1260 1259 F: drivers/iio/adc/ad4130.c 1261 1260 ··· 1564 1565 F: Documentation/devicetree/bindings/iio/*/adi,* 1565 1566 F: Documentation/devicetree/bindings/iio/adc/lltc,ltc2496.yaml 1566 1567 F: Documentation/devicetree/bindings/iio/adc/lltc,ltc2497.yaml 1568 + F: Documentation/iio/ad7606.rst 1567 1569 F: drivers/iio/*/ad* 1568 1570 F: drivers/iio/adc/ltc249* 1569 1571 F: drivers/iio/amplifiers/hmc425a.c ··· 24651 24651 S: Maintained 24652 24652 F: drivers/input/serio/userio.c 24653 24653 F: include/uapi/linux/userio.h 24654 + 24655 + VISHAY VEML3235 AMBIENT LIGHT SENSOR DRIVER 24656 + M: Javier Carrasco <javier.carrasco.cruz@gmail.com> 24657 + S: Maintained 24658 + F: Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml 24659 + F: drivers/iio/light/veml3235.c 24654 24660 24655 24661 VISHAY VEML6030 AMBIENT LIGHT SENSOR DRIVER 24656 24662 M: Javier Carrasco <javier.carrasco.cruz@gmail.com>
+1 -1
drivers/iio/accel/adxl355_core.c
··· 643 643 * The acceleration data is 24 bits and big endian. It has to be saved 644 644 * in 32 bits, hence, it is saved in the 2nd byte of the 4 byte buffer. 645 645 * The buf array is 14 bytes as it includes 3x4=12 bytes for 646 - * accelaration data of x, y, and z axis. It also includes 2 bytes for 646 + * acceleration data of x, y, and z axis. It also includes 2 bytes for 647 647 * temperature data. 648 648 */ 649 649 ret = regmap_bulk_read(data->regmap, ADXL355_XDATA3_REG,
+1 -1
drivers/iio/accel/adxl367.c
··· 1073 1073 const struct iio_chan_spec *chan, 1074 1074 enum iio_event_type type, 1075 1075 enum iio_event_direction dir, 1076 - int state) 1076 + bool state) 1077 1077 { 1078 1078 enum adxl367_activity_type act; 1079 1079
+1 -1
drivers/iio/accel/adxl372.c
··· 940 940 941 941 static int adxl372_write_event_config(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, 942 942 enum iio_event_type type, enum iio_event_direction dir, 943 - int state) 943 + bool state) 944 944 { 945 945 struct adxl372_state *st = iio_priv(indio_dev); 946 946
+1 -1
drivers/iio/accel/adxl380.c
··· 1386 1386 const struct iio_chan_spec *chan, 1387 1387 enum iio_event_type type, 1388 1388 enum iio_event_direction dir, 1389 - int state) 1389 + bool state) 1390 1390 { 1391 1391 struct adxl380_state *st = iio_priv(indio_dev); 1392 1392 enum adxl380_axis axis;
+2 -1
drivers/iio/accel/bma180.c
··· 21 21 #include <linux/regulator/consumer.h> 22 22 #include <linux/slab.h> 23 23 #include <linux/string.h> 24 + #include <linux/types.h> 24 25 #include <linux/iio/iio.h> 25 26 #include <linux/iio/sysfs.h> 26 27 #include <linux/iio/buffer.h> ··· 145 144 /* Ensure timestamp is naturally aligned */ 146 145 struct { 147 146 s16 chan[4]; 148 - s64 timestamp __aligned(8); 147 + aligned_s64 timestamp; 149 148 } scan; 150 149 }; 151 150
+1
drivers/iio/accel/bma220_spi.c
··· 9 9 #include <linux/kernel.h> 10 10 #include <linux/mod_devicetable.h> 11 11 #include <linux/module.h> 12 + #include <linux/types.h> 12 13 #include <linux/spi/spi.h> 13 14 14 15 #include <linux/iio/buffer.h>
+2 -2
drivers/iio/accel/bma400_core.c
··· 115 115 struct { 116 116 __le16 buff[3]; 117 117 u8 temperature; 118 - s64 ts __aligned(8); 118 + aligned_s64 ts; 119 119 } buffer __aligned(IIO_DMA_MINALIGN); 120 120 __le16 status; 121 121 __be16 duration; ··· 1293 1293 static int bma400_write_event_config(struct iio_dev *indio_dev, 1294 1294 const struct iio_chan_spec *chan, 1295 1295 enum iio_event_type type, 1296 - enum iio_event_direction dir, int state) 1296 + enum iio_event_direction dir, bool state) 1297 1297 { 1298 1298 struct bma400_data *data = iio_priv(indio_dev); 1299 1299 int ret;
+1 -1
drivers/iio/accel/bmc150-accel-core.c
··· 804 804 const struct iio_chan_spec *chan, 805 805 enum iio_event_type type, 806 806 enum iio_event_direction dir, 807 - int state) 807 + bool state) 808 808 { 809 809 struct bmc150_accel_data *data = iio_priv(indio_dev); 810 810 int ret;
+2 -1
drivers/iio/accel/bmc150-accel.h
··· 6 6 #include <linux/iio/iio.h> 7 7 #include <linux/mutex.h> 8 8 #include <linux/regulator/consumer.h> 9 + #include <linux/types.h> 9 10 #include <linux/workqueue.h> 10 11 11 12 struct regmap; ··· 70 69 */ 71 70 struct { 72 71 __le16 channels[3]; 73 - s64 ts __aligned(8); 72 + aligned_s64 ts; 74 73 } scan; 75 74 u8 bw_bits; 76 75 u32 slope_dur;
+3 -2
drivers/iio/accel/fxls8962af-core.c
··· 22 22 #include <linux/property.h> 23 23 #include <linux/regulator/consumer.h> 24 24 #include <linux/regmap.h> 25 + #include <linux/types.h> 25 26 26 27 #include <linux/iio/buffer.h> 27 28 #include <linux/iio/events.h> ··· 164 163 const struct fxls8962af_chip_info *chip_info; 165 164 struct { 166 165 __le16 channels[3]; 167 - s64 ts __aligned(8); 166 + aligned_s64 ts; 168 167 } scan; 169 168 int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */ 170 169 struct iio_mount_matrix orientation; ··· 617 616 fxls8962af_write_event_config(struct iio_dev *indio_dev, 618 617 const struct iio_chan_spec *chan, 619 618 enum iio_event_type type, 620 - enum iio_event_direction dir, int state) 619 + enum iio_event_direction dir, bool state) 621 620 { 622 621 struct fxls8962af_data *data = iio_priv(indio_dev); 623 622 u8 enable_event, enable_bits;
+2 -1
drivers/iio/accel/kionix-kx022a.c
··· 16 16 #include <linux/regulator/consumer.h> 17 17 #include <linux/slab.h> 18 18 #include <linux/string_choices.h> 19 + #include <linux/types.h> 19 20 #include <linux/units.h> 20 21 21 22 #include <linux/iio/iio.h> ··· 293 292 __le16 buffer[8] __aligned(IIO_DMA_MINALIGN); 294 293 struct { 295 294 __le16 channels[3]; 296 - s64 ts __aligned(8); 295 + aligned_s64 ts; 297 296 } scan; 298 297 }; 299 298
+217 -225
drivers/iio/accel/kxcjk-1013.c
··· 4 4 * Copyright (c) 2014, Intel Corporation. 5 5 */ 6 6 7 - #include <linux/module.h> 8 7 #include <linux/i2c.h> 9 8 #include <linux/interrupt.h> 10 9 #include <linux/delay.h> 11 10 #include <linux/bitops.h> 11 + #include <linux/mod_devicetable.h> 12 + #include <linux/module.h> 12 13 #include <linux/slab.h> 13 14 #include <linux/string.h> 15 + #include <linux/types.h> 14 16 #include <linux/acpi.h> 15 17 #include <linux/pm.h> 16 18 #include <linux/pm_runtime.h> ··· 170 168 171 169 #define KXCJK1013_DEFAULT_WAKE_THRES 1 172 170 173 - enum kx_chipset { 174 - KXCJK1013, 175 - KXCJ91008, 176 - KXTJ21009, 177 - KXTF9, 178 - KX0221020, 179 - KX0231025, 180 - KX_MAX_CHIPS /* this must be last */ 171 + /* Refer to section 4 of the specification */ 172 + struct kx_odr_start_up_time { 173 + int odr_bits; 174 + int usec; 175 + }; 176 + 177 + /* KXCJK-1013 */ 178 + static const struct kx_odr_start_up_time kxcjk1013_odr_start_up_times[] = { 179 + { 0x08, 100000 }, 180 + { 0x09, 100000 }, 181 + { 0x0A, 100000 }, 182 + { 0x0B, 100000 }, 183 + { 0x00, 80000 }, 184 + { 0x01, 41000 }, 185 + { 0x02, 21000 }, 186 + { 0x03, 11000 }, 187 + { 0x04, 6400 }, 188 + { 0x05, 3900 }, 189 + { 0x06, 2700 }, 190 + { 0x07, 2100 }, 191 + { } 192 + }; 193 + 194 + /* KXCTJ2-1009 */ 195 + static const struct kx_odr_start_up_time kxtj21009_odr_start_up_times[] = { 196 + { 0x08, 1240000 }, 197 + { 0x09, 621000 }, 198 + { 0x0A, 309000 }, 199 + { 0x0B, 151000 }, 200 + { 0x00, 80000 }, 201 + { 0x01, 41000 }, 202 + { 0x02, 21000 }, 203 + { 0x03, 11000 }, 204 + { 0x04, 6000 }, 205 + { 0x05, 4000 }, 206 + { 0x06, 3000 }, 207 + { 0x07, 2000 }, 208 + { } 209 + }; 210 + 211 + /* KXTF9 */ 212 + static const struct kx_odr_start_up_time kxtf9_odr_start_up_times[] = { 213 + { 0x01, 81000 }, 214 + { 0x02, 41000 }, 215 + { 0x03, 21000 }, 216 + { 0x04, 11000 }, 217 + { 0x05, 5100 }, 218 + { 0x06, 2700 }, 219 + { } 220 + }; 221 + 222 + /* KX023-1025 */ 223 + static const struct kx_odr_start_up_time kx0231025_odr_start_up_times[] = { 224 + /* First 4 are not in datasheet, taken from KXCTJ2-1009 */ 225 + { 0x08, 1240000 }, 226 + { 0x09, 621000 }, 227 + { 0x0A, 309000 }, 228 + { 0x0B, 151000 }, 229 + { 0x00, 81000 }, 230 + { 0x01, 40000 }, 231 + { 0x02, 22000 }, 232 + { 0x03, 12000 }, 233 + { 0x04, 7000 }, 234 + { 0x05, 4400 }, 235 + { 0x06, 3000 }, 236 + { 0x07, 3000 }, 237 + { } 181 238 }; 182 239 183 240 enum kx_acpi_type { ··· 295 234 .wake_thres = KX023_REG_ATH, 296 235 }; 297 236 237 + struct kx_chipset_info { 238 + const struct kx_chipset_regs *regs; 239 + const struct kx_odr_start_up_time *times; 240 + enum kx_acpi_type acpi_type; 241 + }; 242 + 243 + static const struct kx_chipset_info kxcjk1013_info = { 244 + .regs = &kxcjk1013_regs, 245 + .times = pm_ptr(kxcjk1013_odr_start_up_times), 246 + }; 247 + 248 + static const struct kx_chipset_info kxcj91008_info = { 249 + .regs = &kxcjk1013_regs, 250 + .times = pm_ptr(kxcjk1013_odr_start_up_times), 251 + }; 252 + 253 + static const struct kx_chipset_info kxcj91008_kiox010a_info = { 254 + .regs = &kxcjk1013_regs, 255 + .times = pm_ptr(kxcjk1013_odr_start_up_times), 256 + .acpi_type = ACPI_KIOX010A, 257 + }; 258 + 259 + static const struct kx_chipset_info kxcj91008_kiox020a_info = { 260 + .regs = &kxcjk1013_regs, 261 + .times = pm_ptr(kxcjk1013_odr_start_up_times), 262 + .acpi_type = ACPI_GENERIC, 263 + }; 264 + 265 + static const struct kx_chipset_info kxcj91008_smo8500_info = { 266 + .regs = &kxcjk1013_regs, 267 + .times = pm_ptr(kxcjk1013_odr_start_up_times), 268 + .acpi_type = ACPI_SMO8500, 269 + }; 270 + 271 + static const struct kx_chipset_info kxtj21009_info = { 272 + .regs = &kxcjk1013_regs, 273 + .times = pm_ptr(kxtj21009_odr_start_up_times), 274 + }; 275 + 276 + static const struct kx_chipset_info kxtf9_info = { 277 + .regs = &kxtf9_regs, 278 + .times = pm_ptr(kxtf9_odr_start_up_times), 279 + }; 280 + 281 + static const struct kx_chipset_info kx0231025_info = { 282 + .regs = &kx0231025_regs, 283 + .times = pm_ptr(kx0231025_odr_start_up_times), 284 + }; 285 + 298 286 enum kxcjk1013_axis { 299 287 AXIS_X, 300 288 AXIS_Y, ··· 360 250 /* Ensure timestamp naturally aligned */ 361 251 struct { 362 252 s16 chans[AXIS_MAX]; 363 - s64 timestamp __aligned(8); 253 + aligned_s64 timestamp; 364 254 } scan; 365 255 u8 odr_bits; 366 256 u8 range; ··· 371 261 int ev_enable_state; 372 262 bool motion_trigger_on; 373 263 int64_t timestamp; 374 - enum kx_chipset chipset; 375 - enum kx_acpi_type acpi_type; 376 - const struct kx_chipset_regs *regs; 264 + const struct kx_chipset_info *info; 377 265 }; 378 266 379 267 enum kxcjk1013_mode { ··· 422 314 static const char *const kxtf9_samp_freq_avail = 423 315 "25 50 100 200 400 800"; 424 316 425 - /* Refer to section 4 of the specification */ 426 - static __maybe_unused const struct { 427 - int odr_bits; 428 - int usec; 429 - } odr_start_up_times[KX_MAX_CHIPS][12] = { 430 - /* KXCJK-1013 */ 431 - { 432 - {0x08, 100000}, 433 - {0x09, 100000}, 434 - {0x0A, 100000}, 435 - {0x0B, 100000}, 436 - {0, 80000}, 437 - {0x01, 41000}, 438 - {0x02, 21000}, 439 - {0x03, 11000}, 440 - {0x04, 6400}, 441 - {0x05, 3900}, 442 - {0x06, 2700}, 443 - {0x07, 2100}, 444 - }, 445 - /* KXCJ9-1008 */ 446 - { 447 - {0x08, 100000}, 448 - {0x09, 100000}, 449 - {0x0A, 100000}, 450 - {0x0B, 100000}, 451 - {0, 80000}, 452 - {0x01, 41000}, 453 - {0x02, 21000}, 454 - {0x03, 11000}, 455 - {0x04, 6400}, 456 - {0x05, 3900}, 457 - {0x06, 2700}, 458 - {0x07, 2100}, 459 - }, 460 - /* KXCTJ2-1009 */ 461 - { 462 - {0x08, 1240000}, 463 - {0x09, 621000}, 464 - {0x0A, 309000}, 465 - {0x0B, 151000}, 466 - {0, 80000}, 467 - {0x01, 41000}, 468 - {0x02, 21000}, 469 - {0x03, 11000}, 470 - {0x04, 6000}, 471 - {0x05, 4000}, 472 - {0x06, 3000}, 473 - {0x07, 2000}, 474 - }, 475 - /* KXTF9 */ 476 - { 477 - {0x01, 81000}, 478 - {0x02, 41000}, 479 - {0x03, 21000}, 480 - {0x04, 11000}, 481 - {0x05, 5100}, 482 - {0x06, 2700}, 483 - }, 484 - /* KX023-1025 */ 485 - { 486 - /* First 4 are not in datasheet, taken from KXCTJ2-1009 */ 487 - {0x08, 1240000}, 488 - {0x09, 621000}, 489 - {0x0A, 309000}, 490 - {0x0B, 151000}, 491 - {0, 81000}, 492 - {0x01, 40000}, 493 - {0x02, 22000}, 494 - {0x03, 12000}, 495 - {0x04, 7000}, 496 - {0x05, 4400}, 497 - {0x06, 3000}, 498 - {0x07, 3000}, 499 - }, 500 - }; 501 - 502 317 static const struct { 503 318 u16 scale; 504 319 u8 gsel_0; ··· 455 424 return 0; 456 425 } 457 426 458 - static const struct acpi_device_id kx_acpi_match[] = { 459 - {"KXCJ1013", KXCJK1013}, 460 - {"KXCJ1008", KXCJ91008}, 461 - {"KXCJ9000", KXCJ91008}, 462 - {"KIOX0008", KXCJ91008}, 463 - {"KIOX0009", KXTJ21009}, 464 - {"KIOX000A", KXCJ91008}, 465 - {"KIOX010A", KXCJ91008}, /* KXCJ91008 in the display of a yoga 2-in-1 */ 466 - {"KIOX020A", KXCJ91008}, /* KXCJ91008 in the base of a yoga 2-in-1 */ 467 - {"KXTJ1009", KXTJ21009}, 468 - {"KXJ2109", KXTJ21009}, 469 - {"SMO8500", KXCJ91008}, 470 - { } 471 - }; 472 - MODULE_DEVICE_TABLE(acpi, kx_acpi_match); 473 - 474 427 #endif 475 428 476 429 static int kxcjk1013_set_mode(struct kxcjk1013_data *data, 477 430 enum kxcjk1013_mode mode) 478 431 { 432 + const struct kx_chipset_regs *regs = data->info->regs; 479 433 int ret; 480 434 481 - ret = i2c_smbus_read_byte_data(data->client, data->regs->ctrl1); 435 + ret = i2c_smbus_read_byte_data(data->client, regs->ctrl1); 482 436 if (ret < 0) { 483 437 dev_err(&data->client->dev, "Error reading reg_ctrl1\n"); 484 438 return ret; ··· 474 458 else 475 459 ret |= KXCJK1013_REG_CTRL1_BIT_PC1; 476 460 477 - ret = i2c_smbus_write_byte_data(data->client, data->regs->ctrl1, ret); 461 + ret = i2c_smbus_write_byte_data(data->client, regs->ctrl1, ret); 478 462 if (ret < 0) { 479 463 dev_err(&data->client->dev, "Error writing reg_ctrl1\n"); 480 464 return ret; ··· 486 470 static int kxcjk1013_get_mode(struct kxcjk1013_data *data, 487 471 enum kxcjk1013_mode *mode) 488 472 { 473 + const struct kx_chipset_regs *regs = data->info->regs; 489 474 int ret; 490 475 491 - ret = i2c_smbus_read_byte_data(data->client, data->regs->ctrl1); 476 + ret = i2c_smbus_read_byte_data(data->client, regs->ctrl1); 492 477 if (ret < 0) { 493 478 dev_err(&data->client->dev, "Error reading reg_ctrl1\n"); 494 479 return ret; ··· 505 488 506 489 static int kxcjk1013_set_range(struct kxcjk1013_data *data, int range_index) 507 490 { 491 + const struct kx_chipset_regs *regs = data->info->regs; 508 492 int ret; 509 493 510 - ret = i2c_smbus_read_byte_data(data->client, data->regs->ctrl1); 494 + ret = i2c_smbus_read_byte_data(data->client, regs->ctrl1); 511 495 if (ret < 0) { 512 496 dev_err(&data->client->dev, "Error reading reg_ctrl1\n"); 513 497 return ret; ··· 519 501 ret |= (KXCJK1013_scale_table[range_index].gsel_0 << 3); 520 502 ret |= (KXCJK1013_scale_table[range_index].gsel_1 << 4); 521 503 522 - ret = i2c_smbus_write_byte_data(data->client, data->regs->ctrl1, ret); 504 + ret = i2c_smbus_write_byte_data(data->client, regs->ctrl1, ret); 523 505 if (ret < 0) { 524 506 dev_err(&data->client->dev, "Error writing reg_ctrl1\n"); 525 507 return ret; ··· 532 514 533 515 static int kxcjk1013_chip_init(struct kxcjk1013_data *data) 534 516 { 517 + const struct kx_chipset_regs *regs = data->info->regs; 535 518 int ret; 536 519 537 520 #ifdef CONFIG_ACPI 538 - if (data->acpi_type == ACPI_KIOX010A) { 521 + if (data->info->acpi_type == ACPI_KIOX010A) { 539 522 /* Make sure the kbd and touchpad on 2-in-1s using 2 KXCJ91008-s work */ 540 523 kiox010a_dsm(&data->client->dev, KIOX010A_SET_LAPTOP_MODE); 541 524 } ··· 554 535 if (ret < 0) 555 536 return ret; 556 537 557 - ret = i2c_smbus_read_byte_data(data->client, data->regs->ctrl1); 538 + ret = i2c_smbus_read_byte_data(data->client, regs->ctrl1); 558 539 if (ret < 0) { 559 540 dev_err(&data->client->dev, "Error reading reg_ctrl1\n"); 560 541 return ret; ··· 563 544 /* Set 12 bit mode */ 564 545 ret |= KXCJK1013_REG_CTRL1_BIT_RES; 565 546 566 - ret = i2c_smbus_write_byte_data(data->client, data->regs->ctrl1, ret); 547 + ret = i2c_smbus_write_byte_data(data->client, regs->ctrl1, ret); 567 548 if (ret < 0) { 568 549 dev_err(&data->client->dev, "Error reading reg_ctrl\n"); 569 550 return ret; ··· 574 555 if (ret < 0) 575 556 return ret; 576 557 577 - ret = i2c_smbus_read_byte_data(data->client, data->regs->data_ctrl); 558 + ret = i2c_smbus_read_byte_data(data->client, regs->data_ctrl); 578 559 if (ret < 0) { 579 560 dev_err(&data->client->dev, "Error reading reg_data_ctrl\n"); 580 561 return ret; ··· 583 564 data->odr_bits = ret; 584 565 585 566 /* Set up INT polarity */ 586 - ret = i2c_smbus_read_byte_data(data->client, data->regs->int_ctrl1); 567 + ret = i2c_smbus_read_byte_data(data->client, regs->int_ctrl1); 587 568 if (ret < 0) { 588 569 dev_err(&data->client->dev, "Error reading reg_int_ctrl1\n"); 589 570 return ret; ··· 594 575 else 595 576 ret &= ~KXCJK1013_REG_INT_CTRL1_BIT_IEA; 596 577 597 - ret = i2c_smbus_write_byte_data(data->client, data->regs->int_ctrl1, ret); 578 + ret = i2c_smbus_write_byte_data(data->client, regs->int_ctrl1, ret); 598 579 if (ret < 0) { 599 580 dev_err(&data->client->dev, "Error writing reg_int_ctrl1\n"); 600 581 return ret; 601 582 } 602 583 603 - /* On KX023 and KX022, route all used interrupts to INT1 for now */ 604 - if ((data->chipset == KX0231025 || data->chipset == KX0221020) && data->client->irq > 0) { 584 + /* On KX023, route all used interrupts to INT1 for now */ 585 + if (data->info == &kx0231025_info && data->client->irq > 0) { 605 586 ret = i2c_smbus_write_byte_data(data->client, KX023_REG_INC4, 606 587 KX023_REG_INC4_DRDY1 | 607 588 KX023_REG_INC4_WUFI1); ··· 620 601 return 0; 621 602 } 622 603 623 - #ifdef CONFIG_PM 624 604 static int kxcjk1013_get_startup_times(struct kxcjk1013_data *data) 625 605 { 626 - int i; 627 - int idx = data->chipset; 606 + const struct kx_odr_start_up_time *times; 628 607 629 - for (i = 0; i < ARRAY_SIZE(odr_start_up_times[idx]); ++i) { 630 - if (odr_start_up_times[idx][i].odr_bits == data->odr_bits) 631 - return odr_start_up_times[idx][i].usec; 608 + for (times = data->info->times; times->usec; times++) { 609 + if (times->odr_bits == data->odr_bits) 610 + return times->usec; 632 611 } 633 612 634 613 return KXCJK1013_MAX_STARTUP_TIME_US; 635 614 } 636 - #endif 637 615 638 616 static int kxcjk1013_set_power_state(struct kxcjk1013_data *data, bool on) 639 617 { ··· 655 639 656 640 static int kxcjk1013_chip_update_thresholds(struct kxcjk1013_data *data) 657 641 { 642 + const struct kx_chipset_regs *regs = data->info->regs; 658 643 int ret; 659 644 660 - ret = i2c_smbus_write_byte_data(data->client, data->regs->wake_timer, 661 - data->wake_dur); 645 + ret = i2c_smbus_write_byte_data(data->client, regs->wake_timer, data->wake_dur); 662 646 if (ret < 0) { 663 647 dev_err(&data->client->dev, 664 648 "Error writing reg_wake_timer\n"); 665 649 return ret; 666 650 } 667 651 668 - ret = i2c_smbus_write_byte_data(data->client, data->regs->wake_thres, 669 - data->wake_thres); 652 + ret = i2c_smbus_write_byte_data(data->client, regs->wake_thres, data->wake_thres); 670 653 if (ret < 0) { 671 654 dev_err(&data->client->dev, "Error writing reg_wake_thres\n"); 672 655 return ret; ··· 677 662 static int kxcjk1013_setup_any_motion_interrupt(struct kxcjk1013_data *data, 678 663 bool status) 679 664 { 665 + const struct kx_chipset_regs *regs = data->info->regs; 680 666 int ret; 681 667 enum kxcjk1013_mode store_mode; 682 668 ··· 694 678 if (ret < 0) 695 679 return ret; 696 680 697 - ret = i2c_smbus_read_byte_data(data->client, data->regs->int_ctrl1); 681 + ret = i2c_smbus_read_byte_data(data->client, regs->int_ctrl1); 698 682 if (ret < 0) { 699 683 dev_err(&data->client->dev, "Error reading reg_int_ctrl1\n"); 700 684 return ret; ··· 705 689 else 706 690 ret &= ~KXCJK1013_REG_INT_CTRL1_BIT_IEN; 707 691 708 - ret = i2c_smbus_write_byte_data(data->client, data->regs->int_ctrl1, ret); 692 + ret = i2c_smbus_write_byte_data(data->client, regs->int_ctrl1, ret); 709 693 if (ret < 0) { 710 694 dev_err(&data->client->dev, "Error writing reg_int_ctrl1\n"); 711 695 return ret; 712 696 } 713 697 714 - ret = i2c_smbus_read_byte_data(data->client, data->regs->ctrl1); 698 + ret = i2c_smbus_read_byte_data(data->client, regs->ctrl1); 715 699 if (ret < 0) { 716 700 dev_err(&data->client->dev, "Error reading reg_ctrl1\n"); 717 701 return ret; ··· 722 706 else 723 707 ret &= ~KXCJK1013_REG_CTRL1_BIT_WUFE; 724 708 725 - ret = i2c_smbus_write_byte_data(data->client, data->regs->ctrl1, ret); 709 + ret = i2c_smbus_write_byte_data(data->client, regs->ctrl1, ret); 726 710 if (ret < 0) { 727 711 dev_err(&data->client->dev, "Error writing reg_ctrl1\n"); 728 712 return ret; ··· 740 724 static int kxcjk1013_setup_new_data_interrupt(struct kxcjk1013_data *data, 741 725 bool status) 742 726 { 727 + const struct kx_chipset_regs *regs = data->info->regs; 743 728 int ret; 744 729 enum kxcjk1013_mode store_mode; 745 730 ··· 753 736 if (ret < 0) 754 737 return ret; 755 738 756 - ret = i2c_smbus_read_byte_data(data->client, data->regs->int_ctrl1); 739 + ret = i2c_smbus_read_byte_data(data->client, regs->int_ctrl1); 757 740 if (ret < 0) { 758 741 dev_err(&data->client->dev, "Error reading reg_int_ctrl1\n"); 759 742 return ret; ··· 764 747 else 765 748 ret &= ~KXCJK1013_REG_INT_CTRL1_BIT_IEN; 766 749 767 - ret = i2c_smbus_write_byte_data(data->client, data->regs->int_ctrl1, ret); 750 + ret = i2c_smbus_write_byte_data(data->client, regs->int_ctrl1, ret); 768 751 if (ret < 0) { 769 752 dev_err(&data->client->dev, "Error writing reg_int_ctrl1\n"); 770 753 return ret; 771 754 } 772 755 773 - ret = i2c_smbus_read_byte_data(data->client, data->regs->ctrl1); 756 + ret = i2c_smbus_read_byte_data(data->client, regs->ctrl1); 774 757 if (ret < 0) { 775 758 dev_err(&data->client->dev, "Error reading reg_ctrl1\n"); 776 759 return ret; ··· 781 764 else 782 765 ret &= ~KXCJK1013_REG_CTRL1_BIT_DRDY; 783 766 784 - ret = i2c_smbus_write_byte_data(data->client, data->regs->ctrl1, ret); 767 + ret = i2c_smbus_write_byte_data(data->client, regs->ctrl1, ret); 785 768 if (ret < 0) { 786 769 dev_err(&data->client->dev, "Error writing reg_ctrl1\n"); 787 770 return ret; ··· 828 811 829 812 static int kxcjk1013_set_odr(struct kxcjk1013_data *data, int val, int val2) 830 813 { 814 + const struct kx_chipset_regs *regs = data->info->regs; 831 815 int ret; 832 816 enum kxcjk1013_mode store_mode; 833 817 const struct kx_odr_map *odr_setting; ··· 837 819 if (ret < 0) 838 820 return ret; 839 821 840 - if (data->chipset == KXTF9) 822 + if (data->info == &kxtf9_info) 841 823 odr_setting = kxcjk1013_find_odr_value(kxtf9_samp_freq_table, 842 824 ARRAY_SIZE(kxtf9_samp_freq_table), 843 825 val, val2); ··· 854 836 if (ret < 0) 855 837 return ret; 856 838 857 - ret = i2c_smbus_write_byte_data(data->client, data->regs->data_ctrl, 839 + ret = i2c_smbus_write_byte_data(data->client, regs->data_ctrl, 858 840 odr_setting->odr_bits); 859 841 if (ret < 0) { 860 842 dev_err(&data->client->dev, "Error writing data_ctrl\n"); ··· 863 845 864 846 data->odr_bits = odr_setting->odr_bits; 865 847 866 - ret = i2c_smbus_write_byte_data(data->client, data->regs->wuf_ctrl, 848 + ret = i2c_smbus_write_byte_data(data->client, regs->wuf_ctrl, 867 849 odr_setting->wuf_bits); 868 850 if (ret < 0) { 869 851 dev_err(&data->client->dev, "Error writing reg_ctrl2\n"); ··· 881 863 882 864 static int kxcjk1013_get_odr(struct kxcjk1013_data *data, int *val, int *val2) 883 865 { 884 - if (data->chipset == KXTF9) 866 + if (data->info == &kxtf9_info) 885 867 return kxcjk1013_convert_odr_value(kxtf9_samp_freq_table, 886 868 ARRAY_SIZE(kxtf9_samp_freq_table), 887 869 data->odr_bits, val, val2); ··· 1081 1063 const struct iio_chan_spec *chan, 1082 1064 enum iio_event_type type, 1083 1065 enum iio_event_direction dir, 1084 - int state) 1066 + bool state) 1085 1067 { 1086 1068 struct kxcjk1013_data *data = iio_priv(indio_dev); 1087 1069 int ret; ··· 1148 1130 struct kxcjk1013_data *data = iio_priv(indio_dev); 1149 1131 const char *str; 1150 1132 1151 - if (data->chipset == KXTF9) 1133 + if (data->info == &kxtf9_info) 1152 1134 str = kxtf9_samp_freq_avail; 1153 1135 else 1154 1136 str = kxcjk1013_samp_freq_avail; ··· 1225 1207 .postdisable = kxcjk1013_buffer_postdisable, 1226 1208 }; 1227 1209 1228 - static const struct iio_info kxcjk1013_info = { 1210 + static const struct iio_info kxcjk1013_iio_info = { 1229 1211 .attrs = &kxcjk1013_attrs_group, 1230 1212 .read_raw = kxcjk1013_read_raw, 1231 1213 .write_raw = kxcjk1013_write_raw, ··· 1265 1247 { 1266 1248 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 1267 1249 struct kxcjk1013_data *data = iio_priv(indio_dev); 1250 + const struct kx_chipset_regs *regs = data->info->regs; 1268 1251 int ret; 1269 1252 1270 - ret = i2c_smbus_read_byte_data(data->client, data->regs->int_rel); 1253 + ret = i2c_smbus_read_byte_data(data->client, regs->int_rel); 1271 1254 if (ret < 0) 1272 1255 dev_err(&data->client->dev, "Error reading reg_int_rel\n"); 1273 1256 } ··· 1320 1301 static void kxcjk1013_report_motion_event(struct iio_dev *indio_dev) 1321 1302 { 1322 1303 struct kxcjk1013_data *data = iio_priv(indio_dev); 1304 + const struct kx_chipset_regs *regs = data->info->regs; 1323 1305 1324 - int ret = i2c_smbus_read_byte_data(data->client, data->regs->int_src2); 1306 + int ret = i2c_smbus_read_byte_data(data->client, regs->int_src2); 1325 1307 if (ret < 0) { 1326 1308 dev_err(&data->client->dev, "Error reading reg_int_src2\n"); 1327 1309 return; ··· 1387 1367 { 1388 1368 struct iio_dev *indio_dev = private; 1389 1369 struct kxcjk1013_data *data = iio_priv(indio_dev); 1370 + const struct kx_chipset_regs *regs = data->info->regs; 1390 1371 int ret; 1391 1372 1392 - ret = i2c_smbus_read_byte_data(data->client, data->regs->int_src1); 1373 + ret = i2c_smbus_read_byte_data(data->client, regs->int_src1); 1393 1374 if (ret < 0) { 1394 1375 dev_err(&data->client->dev, "Error reading reg_int_src1\n"); 1395 1376 goto ack_intr; 1396 1377 } 1397 1378 1398 1379 if (ret & KXCJK1013_REG_INT_SRC1_BIT_WUFS) { 1399 - if (data->chipset == KXTF9) 1380 + if (data->info == &kxtf9_info) 1400 1381 iio_push_event(indio_dev, 1401 1382 IIO_MOD_EVENT_CODE(IIO_ACCEL, 1402 1383 0, ··· 1413 1392 if (data->dready_trigger_on) 1414 1393 return IRQ_HANDLED; 1415 1394 1416 - ret = i2c_smbus_read_byte_data(data->client, data->regs->int_rel); 1395 + ret = i2c_smbus_read_byte_data(data->client, regs->int_rel); 1417 1396 if (ret < 0) 1418 1397 dev_err(&data->client->dev, "Error reading reg_int_rel\n"); 1419 1398 ··· 1438 1417 return IRQ_HANDLED; 1439 1418 } 1440 1419 1441 - static const char *kxcjk1013_match_acpi_device(struct device *dev, 1442 - enum kx_chipset *chipset, 1443 - enum kx_acpi_type *acpi_type, 1444 - const char **label) 1445 - { 1446 - const struct acpi_device_id *id; 1447 - 1448 - id = acpi_match_device(dev->driver->acpi_match_table, dev); 1449 - if (!id) 1450 - return NULL; 1451 - 1452 - if (strcmp(id->id, "SMO8500") == 0) { 1453 - *acpi_type = ACPI_SMO8500; 1454 - } else if (strcmp(id->id, "KIOX010A") == 0) { 1455 - *acpi_type = ACPI_KIOX010A; 1456 - *label = "accel-display"; 1457 - } else if (strcmp(id->id, "KIOX020A") == 0) { 1458 - *label = "accel-base"; 1459 - } 1460 - 1461 - *chipset = (enum kx_chipset)id->driver_data; 1462 - 1463 - return dev_name(dev); 1464 - } 1465 - 1466 1420 static int kxcjk1013_probe(struct i2c_client *client) 1467 1421 { 1468 1422 const struct i2c_device_id *id = i2c_client_get_device_id(client); ··· 1445 1449 struct kxcjk1013_data *data; 1446 1450 struct iio_dev *indio_dev; 1447 1451 struct kxcjk_1013_platform_data *pdata; 1452 + const void *ddata = NULL; 1448 1453 const char *name; 1449 1454 int ret; 1450 1455 ··· 1486 1489 msleep(20); 1487 1490 1488 1491 if (id) { 1489 - data->chipset = (enum kx_chipset)(id->driver_data); 1490 1492 name = id->name; 1491 - } else if (ACPI_HANDLE(&client->dev)) { 1492 - name = kxcjk1013_match_acpi_device(&client->dev, 1493 - &data->chipset, 1494 - &data->acpi_type, 1495 - &indio_dev->label); 1496 - } else 1497 - return -ENODEV; 1498 - 1499 - switch (data->chipset) { 1500 - case KXCJK1013: 1501 - case KXCJ91008: 1502 - case KXTJ21009: 1503 - data->regs = &kxcjk1013_regs; 1504 - break; 1505 - case KXTF9: 1506 - data->regs = &kxtf9_regs; 1507 - break; 1508 - case KX0221020: 1509 - case KX0231025: 1510 - data->regs = &kx0231025_regs; 1511 - break; 1512 - default: 1513 - return -EINVAL; 1493 + data->info = (const struct kx_chipset_info *)(id->driver_data); 1494 + } else { 1495 + name = iio_get_acpi_device_name_and_data(&client->dev, &ddata); 1496 + data->info = ddata; 1497 + if (data->info == &kxcj91008_kiox010a_info) 1498 + indio_dev->label = "accel-display"; 1499 + else if (data->info == &kxcj91008_kiox020a_info) 1500 + indio_dev->label = "accel-base"; 1514 1501 } 1502 + if (!name) 1503 + return -ENODEV; 1515 1504 1516 1505 ret = kxcjk1013_chip_init(data); 1517 1506 if (ret < 0) ··· 1510 1527 indio_dev->available_scan_masks = kxcjk1013_scan_masks; 1511 1528 indio_dev->name = name; 1512 1529 indio_dev->modes = INDIO_DIRECT_MODE; 1513 - indio_dev->info = &kxcjk1013_info; 1530 + indio_dev->info = &kxcjk1013_iio_info; 1514 1531 1515 - if (client->irq > 0 && data->acpi_type != ACPI_SMO8500) { 1532 + if (client->irq > 0 && data->info->acpi_type != ACPI_SMO8500) { 1516 1533 ret = devm_request_threaded_irq(&client->dev, client->irq, 1517 1534 kxcjk1013_data_rdy_trig_poll, 1518 1535 kxcjk1013_event_handler, ··· 1620 1637 mutex_unlock(&data->mutex); 1621 1638 } 1622 1639 1623 - #ifdef CONFIG_PM_SLEEP 1624 1640 static int kxcjk1013_suspend(struct device *dev) 1625 1641 { 1626 1642 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); ··· 1647 1665 1648 1666 return ret; 1649 1667 } 1650 - #endif 1651 1668 1652 - #ifdef CONFIG_PM 1653 1669 static int kxcjk1013_runtime_suspend(struct device *dev) 1654 1670 { 1655 1671 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); ··· 1681 1701 1682 1702 return 0; 1683 1703 } 1684 - #endif 1685 1704 1686 1705 static const struct dev_pm_ops kxcjk1013_pm_ops = { 1687 - SET_SYSTEM_SLEEP_PM_OPS(kxcjk1013_suspend, kxcjk1013_resume) 1688 - SET_RUNTIME_PM_OPS(kxcjk1013_runtime_suspend, 1689 - kxcjk1013_runtime_resume, NULL) 1706 + SYSTEM_SLEEP_PM_OPS(kxcjk1013_suspend, kxcjk1013_resume) 1707 + RUNTIME_PM_OPS(kxcjk1013_runtime_suspend, kxcjk1013_runtime_resume, NULL) 1690 1708 }; 1691 1709 1692 1710 static const struct i2c_device_id kxcjk1013_id[] = { 1693 - {"kxcjk1013", KXCJK1013}, 1694 - {"kxcj91008", KXCJ91008}, 1695 - {"kxtj21009", KXTJ21009}, 1696 - {"kxtf9", KXTF9}, 1697 - {"kx022-1020", KX0221020}, 1698 - {"kx023-1025", KX0231025}, 1699 - {"SMO8500", KXCJ91008}, 1700 - {} 1711 + { "kxcjk1013", (kernel_ulong_t)&kxcjk1013_info }, 1712 + { "kxcj91008", (kernel_ulong_t)&kxcj91008_info }, 1713 + { "kxtj21009", (kernel_ulong_t)&kxtj21009_info }, 1714 + { "kxtf9", (kernel_ulong_t)&kxtf9_info }, 1715 + { "kx023-1025", (kernel_ulong_t)&kx0231025_info }, 1716 + { } 1701 1717 }; 1702 - 1703 1718 MODULE_DEVICE_TABLE(i2c, kxcjk1013_id); 1704 1719 1705 1720 static const struct of_device_id kxcjk1013_of_match[] = { 1706 - { .compatible = "kionix,kxcjk1013", }, 1707 - { .compatible = "kionix,kxcj91008", }, 1708 - { .compatible = "kionix,kxtj21009", }, 1709 - { .compatible = "kionix,kxtf9", }, 1710 - { .compatible = "kionix,kx022-1020", }, 1711 - { .compatible = "kionix,kx023-1025", }, 1721 + { .compatible = "kionix,kxcjk1013", &kxcjk1013_info }, 1722 + { .compatible = "kionix,kxcj91008", &kxcj91008_info }, 1723 + { .compatible = "kionix,kxtj21009", &kxtj21009_info }, 1724 + { .compatible = "kionix,kxtf9", &kxtf9_info }, 1725 + { .compatible = "kionix,kx023-1025", &kx0231025_info }, 1712 1726 { } 1713 1727 }; 1714 1728 MODULE_DEVICE_TABLE(of, kxcjk1013_of_match); 1715 1729 1730 + static const struct acpi_device_id kx_acpi_match[] = { 1731 + { "KIOX0008", (kernel_ulong_t)&kxcj91008_info }, 1732 + { "KIOX0009", (kernel_ulong_t)&kxtj21009_info }, 1733 + { "KIOX000A", (kernel_ulong_t)&kxcj91008_info }, 1734 + /* KXCJ91008 in the display of a yoga 2-in-1 */ 1735 + { "KIOX010A", (kernel_ulong_t)&kxcj91008_kiox010a_info }, 1736 + /* KXCJ91008 in the base of a yoga 2-in-1 */ 1737 + { "KIOX020A", (kernel_ulong_t)&kxcj91008_kiox020a_info }, 1738 + { "KXCJ1008", (kernel_ulong_t)&kxcj91008_info }, 1739 + { "KXCJ1013", (kernel_ulong_t)&kxcjk1013_info }, 1740 + { "KXCJ9000", (kernel_ulong_t)&kxcj91008_info }, 1741 + { "KXJ2109", (kernel_ulong_t)&kxtj21009_info }, 1742 + { "KXTJ1009", (kernel_ulong_t)&kxtj21009_info }, 1743 + { "SMO8500", (kernel_ulong_t)&kxcj91008_smo8500_info }, 1744 + { } 1745 + }; 1746 + MODULE_DEVICE_TABLE(acpi, kx_acpi_match); 1747 + 1716 1748 static struct i2c_driver kxcjk1013_driver = { 1717 1749 .driver = { 1718 1750 .name = KXCJK1013_DRV_NAME, 1719 - .acpi_match_table = ACPI_PTR(kx_acpi_match), 1751 + .acpi_match_table = kx_acpi_match, 1720 1752 .of_match_table = kxcjk1013_of_match, 1721 - .pm = &kxcjk1013_pm_ops, 1753 + .pm = pm_ptr(&kxcjk1013_pm_ops), 1722 1754 }, 1723 1755 .probe = kxcjk1013_probe, 1724 1756 .remove = kxcjk1013_remove,
+2 -1
drivers/iio/accel/kxsd9.c
··· 15 15 #include <linux/kernel.h> 16 16 #include <linux/sysfs.h> 17 17 #include <linux/slab.h> 18 + #include <linux/types.h> 18 19 #include <linux/module.h> 19 20 #include <linux/regmap.h> 20 21 #include <linux/bitops.h> ··· 216 215 */ 217 216 struct { 218 217 __be16 chan[4]; 219 - s64 ts __aligned(8); 218 + aligned_s64 ts; 220 219 } hw_values; 221 220 int ret; 222 221
+2 -1
drivers/iio/accel/mma7455_core.c
··· 19 19 #include <linux/iio/triggered_buffer.h> 20 20 #include <linux/module.h> 21 21 #include <linux/regmap.h> 22 + #include <linux/types.h> 22 23 23 24 #include "mma7455.h" 24 25 ··· 59 58 */ 60 59 struct { 61 60 __le16 channels[3]; 62 - s64 ts __aligned(8); 61 + aligned_s64 ts; 63 62 } scan; 64 63 }; 65 64
+3 -2
drivers/iio/accel/mma8452.c
··· 32 32 #include <linux/delay.h> 33 33 #include <linux/pm_runtime.h> 34 34 #include <linux/regulator/consumer.h> 35 + #include <linux/types.h> 35 36 36 37 #define MMA8452_STATUS 0x00 37 38 #define MMA8452_STATUS_DRDY (BIT(2) | BIT(1) | BIT(0)) ··· 116 115 /* Ensure correct alignment of time stamp when present */ 117 116 struct { 118 117 __be16 channels[3]; 119 - s64 ts __aligned(8); 118 + aligned_s64 ts; 120 119 } buffer; 121 120 }; 122 121 ··· 974 973 const struct iio_chan_spec *chan, 975 974 enum iio_event_type type, 976 975 enum iio_event_direction dir, 977 - int state) 976 + bool state) 978 977 { 979 978 struct mma8452_data *data = iio_priv(indio_dev); 980 979 int val, ret;
+8 -19
drivers/iio/accel/mma9551.c
··· 4 4 * Copyright (c) 2014, Intel Corporation. 5 5 */ 6 6 7 - #include <linux/module.h> 8 7 #include <linux/i2c.h> 9 8 #include <linux/interrupt.h> 9 + #include <linux/mod_devicetable.h> 10 + #include <linux/module.h> 10 11 #include <linux/slab.h> 11 - #include <linux/acpi.h> 12 12 #include <linux/delay.h> 13 13 #include <linux/gpio/consumer.h> 14 14 #include <linux/iio/iio.h> ··· 45 45 struct mma9551_data { 46 46 struct i2c_client *client; 47 47 struct mutex mutex; 48 - int event_enabled[3]; 48 + bool event_enabled[3]; 49 49 int irqs[MMA9551_GPIO_COUNT]; 50 50 }; 51 51 ··· 162 162 163 163 static int mma9551_config_incli_event(struct iio_dev *indio_dev, 164 164 enum iio_modifier axis, 165 - int state) 165 + bool state) 166 166 { 167 167 struct mma9551_data *data = iio_priv(indio_dev); 168 168 enum mma9551_tilt_axis mma_axis; ··· 174 174 if (data->event_enabled[mma_axis] == state) 175 175 return 0; 176 176 177 - if (state == 0) { 177 + if (!state) { 178 178 ret = mma9551_gpio_config(data->client, 179 179 (enum mma9551_gpio_pin)mma_axis, 180 180 MMA9551_APPID_NONE, 0, 0); ··· 225 225 const struct iio_chan_spec *chan, 226 226 enum iio_event_type type, 227 227 enum iio_event_direction dir, 228 - int state) 228 + bool state) 229 229 { 230 230 struct mma9551_data *data = iio_priv(indio_dev); 231 231 int ret; ··· 435 435 return 0; 436 436 } 437 437 438 - static const char *mma9551_match_acpi_device(struct device *dev) 439 - { 440 - const struct acpi_device_id *id; 441 - 442 - id = acpi_match_device(dev->driver->acpi_match_table, dev); 443 - if (!id) 444 - return NULL; 445 - 446 - return dev_name(dev); 447 - } 448 - 449 438 static int mma9551_probe(struct i2c_client *client) 450 439 { 451 440 const struct i2c_device_id *id = i2c_client_get_device_id(client); ··· 453 464 454 465 if (id) 455 466 name = id->name; 456 - else if (ACPI_HANDLE(&client->dev)) 457 - name = mma9551_match_acpi_device(&client->dev); 467 + else 468 + name = iio_get_acpi_device_name(&client->dev); 458 469 459 470 ret = mma9551_init(data); 460 471 if (ret < 0)
+17 -29
drivers/iio/accel/mma9553.c
··· 4 4 * Copyright (c) 2014, Intel Corporation. 5 5 */ 6 6 7 - #include <linux/module.h> 8 7 #include <linux/i2c.h> 9 8 #include <linux/interrupt.h> 9 + #include <linux/mod_devicetable.h> 10 + #include <linux/module.h> 10 11 #include <linux/slab.h> 11 - #include <linux/acpi.h> 12 12 #include <linux/iio/iio.h> 13 13 #include <linux/iio/sysfs.h> 14 14 #include <linux/iio/events.h> ··· 725 725 static int mma9553_write_event_config(struct iio_dev *indio_dev, 726 726 const struct iio_chan_spec *chan, 727 727 enum iio_event_type type, 728 - enum iio_event_direction dir, int state) 728 + enum iio_event_direction dir, 729 + bool state) 729 730 { 730 731 struct mma9553_data *data = iio_priv(indio_dev); 731 732 struct mma9553_event *event; ··· 1031 1030 if (ev_step_detect->enabled && (stepcnt != data->stepcnt)) { 1032 1031 data->stepcnt = stepcnt; 1033 1032 iio_push_event(indio_dev, 1034 - IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD, 1035 - IIO_EV_DIR_NONE, 1036 - IIO_EV_TYPE_CHANGE, 0, 0, 0), 1033 + IIO_UNMOD_EVENT_CODE(IIO_STEPS, 0, 1034 + IIO_EV_TYPE_CHANGE, 1035 + IIO_EV_DIR_NONE), 1037 1036 data->timestamp); 1038 1037 } 1039 1038 ··· 1042 1041 /* ev_activity can be NULL if activity == ACTIVITY_UNKNOWN */ 1043 1042 if (ev_prev_activity && ev_prev_activity->enabled) 1044 1043 iio_push_event(indio_dev, 1045 - IIO_EVENT_CODE(IIO_ACTIVITY, 0, 1046 - ev_prev_activity->info->mod, 1047 - IIO_EV_DIR_FALLING, 1048 - IIO_EV_TYPE_THRESH, 0, 0, 1049 - 0), 1044 + IIO_MOD_EVENT_CODE(IIO_ACTIVITY, 0, 1045 + ev_prev_activity->info->mod, 1046 + IIO_EV_TYPE_THRESH, 1047 + IIO_EV_DIR_FALLING), 1050 1048 data->timestamp); 1051 1049 1052 1050 if (ev_activity && ev_activity->enabled) 1053 1051 iio_push_event(indio_dev, 1054 - IIO_EVENT_CODE(IIO_ACTIVITY, 0, 1055 - ev_activity->info->mod, 1056 - IIO_EV_DIR_RISING, 1057 - IIO_EV_TYPE_THRESH, 0, 0, 1058 - 0), 1052 + IIO_MOD_EVENT_CODE(IIO_ACTIVITY, 0, 1053 + ev_activity->info->mod, 1054 + IIO_EV_TYPE_THRESH, 1055 + IIO_EV_DIR_RISING), 1059 1056 data->timestamp); 1060 1057 } 1061 1058 mutex_unlock(&data->mutex); 1062 1059 1063 1060 return IRQ_HANDLED; 1064 - } 1065 - 1066 - static const char *mma9553_match_acpi_device(struct device *dev) 1067 - { 1068 - const struct acpi_device_id *id; 1069 - 1070 - id = acpi_match_device(dev->driver->acpi_match_table, dev); 1071 - if (!id) 1072 - return NULL; 1073 - 1074 - return dev_name(dev); 1075 1061 } 1076 1062 1077 1063 static int mma9553_probe(struct i2c_client *client) ··· 1079 1091 1080 1092 if (id) 1081 1093 name = id->name; 1082 - else if (ACPI_HANDLE(&client->dev)) 1083 - name = mma9553_match_acpi_device(&client->dev); 1084 1094 else 1095 + name = iio_get_acpi_device_name(&client->dev); 1096 + if (!name) 1085 1097 return -ENOSYS; 1086 1098 1087 1099 mutex_init(&data->mutex);
+2 -1
drivers/iio/accel/msa311.c
··· 34 34 #include <linux/pm_runtime.h> 35 35 #include <linux/regmap.h> 36 36 #include <linux/string_choices.h> 37 + #include <linux/types.h> 37 38 #include <linux/units.h> 38 39 39 40 #include <linux/iio/buffer.h> ··· 894 893 __le16 axis; 895 894 struct { 896 895 __le16 channels[MSA311_SI_Z + 1]; 897 - s64 ts __aligned(8); 896 + aligned_s64 ts; 898 897 } buf; 899 898 900 899 memset(&buf, 0, sizeof(buf));
+2 -1
drivers/iio/accel/mxc4005.c
··· 11 11 #include <linux/iio/iio.h> 12 12 #include <linux/mod_devicetable.h> 13 13 #include <linux/regmap.h> 14 + #include <linux/types.h> 14 15 #include <linux/iio/sysfs.h> 15 16 #include <linux/iio/trigger.h> 16 17 #include <linux/iio/buffer.h> ··· 70 69 /* Ensure timestamp is naturally aligned */ 71 70 struct { 72 71 __be16 chans[3]; 73 - s64 timestamp __aligned(8); 72 + aligned_s64 timestamp; 74 73 } scan; 75 74 bool trigger_enabled; 76 75 unsigned int control;
+3 -3
drivers/iio/accel/sca3000.c
··· 1158 1158 return ret; 1159 1159 } 1160 1160 1161 - static int sca3000_freefall_set_state(struct iio_dev *indio_dev, int state) 1161 + static int sca3000_freefall_set_state(struct iio_dev *indio_dev, bool state) 1162 1162 { 1163 1163 struct sca3000_state *st = iio_priv(indio_dev); 1164 1164 int ret; ··· 1181 1181 } 1182 1182 1183 1183 static int sca3000_motion_detect_set_state(struct iio_dev *indio_dev, int axis, 1184 - int state) 1184 + bool state) 1185 1185 { 1186 1186 struct sca3000_state *st = iio_priv(indio_dev); 1187 1187 int ret, ctrlval; ··· 1253 1253 const struct iio_chan_spec *chan, 1254 1254 enum iio_event_type type, 1255 1255 enum iio_event_direction dir, 1256 - int state) 1256 + bool state) 1257 1257 { 1258 1258 struct sca3000_state *st = iio_priv(indio_dev); 1259 1259 int ret;
+2 -1
drivers/iio/accel/stk8312.c
··· 12 12 #include <linux/kernel.h> 13 13 #include <linux/module.h> 14 14 #include <linux/delay.h> 15 + #include <linux/types.h> 15 16 #include <linux/iio/buffer.h> 16 17 #include <linux/iio/iio.h> 17 18 #include <linux/iio/sysfs.h> ··· 106 105 /* Ensure timestamp is naturally aligned */ 107 106 struct { 108 107 s8 chans[3]; 109 - s64 timestamp __aligned(8); 108 + aligned_s64 timestamp; 110 109 } scan; 111 110 }; 112 111
+2 -1
drivers/iio/accel/stk8ba50.c
··· 12 12 #include <linux/kernel.h> 13 13 #include <linux/module.h> 14 14 #include <linux/mod_devicetable.h> 15 + #include <linux/types.h> 15 16 #include <linux/iio/buffer.h> 16 17 #include <linux/iio/iio.h> 17 18 #include <linux/iio/sysfs.h> ··· 95 94 /* Ensure timestamp is naturally aligned */ 96 95 struct { 97 96 s16 chans[3]; 98 - s64 timetamp __aligned(8); 97 + aligned_s64 timetamp; 99 98 } scan; 100 99 }; 101 100
+14 -1
drivers/iio/adc/Kconfig
··· 226 226 tristate "Analog Devices AD7606 ADC driver with parallel interface support" 227 227 depends on HAS_IOPORT 228 228 select AD7606 229 + select IIO_BACKEND 229 230 help 230 231 Say yes here to build parallel interface support for Analog Devices: 231 232 ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC). 233 + It also support iio_backended devices for AD7606B. 232 234 233 235 To compile this driver as a module, choose M here: the 234 236 module will be called ad7606_par. ··· 286 284 287 285 To compile this driver as a module, choose M here: the module will be 288 286 called ad7768-1. 287 + 288 + config AD7779 289 + tristate "Analog Devices AD7779 ADC driver" 290 + depends on SPI 291 + select CRC8 292 + select IIO_BUFFER 293 + help 294 + Say yes here to build support for Analog Devices AD777X family 295 + (AD7770, AD7771, AD7779) analog to digital converter (ADC). 296 + 297 + To compile this driver as a module, choose M here: the module will be 298 + called ad7779. 289 299 290 300 config AD7780 291 301 tristate "Analog Devices AD7780 and similar ADCs driver" ··· 1620 1606 config TWL6030_GPADC 1621 1607 tristate "TWL6030 GPADC (General Purpose A/D Converter) Support" 1622 1608 depends on TWL4030_CORE 1623 - default n 1624 1609 help 1625 1610 Say yes here if you want support for the TWL6030/TWL6032 General 1626 1611 Purpose A/D Converter. This will add support for battery type
+1
drivers/iio/adc/Makefile
··· 28 28 obj-$(CONFIG_AD7625) += ad7625.o 29 29 obj-$(CONFIG_AD7766) += ad7766.o 30 30 obj-$(CONFIG_AD7768_1) += ad7768-1.o 31 + obj-$(CONFIG_AD7779) += ad7779.o 31 32 obj-$(CONFIG_AD7780) += ad7780.o 32 33 obj-$(CONFIG_AD7791) += ad7791.o 33 34 obj-$(CONFIG_AD7793) += ad7793.o
+3 -1
drivers/iio/adc/ad4000.c
··· 639 639 indio_dev->name = chip->dev_name; 640 640 indio_dev->num_channels = 1; 641 641 642 - devm_mutex_init(dev, &st->lock); 642 + ret = devm_mutex_init(dev, &st->lock); 643 + if (ret) 644 + return ret; 643 645 644 646 st->gain_milli = 1000; 645 647 if (chip->has_hardware_gain) {
+2 -1
drivers/iio/adc/ad7091r-base.c
··· 150 150 static int ad7091r_write_event_config(struct iio_dev *indio_dev, 151 151 const struct iio_chan_spec *chan, 152 152 enum iio_event_type type, 153 - enum iio_event_direction dir, int state) 153 + enum iio_event_direction dir, 154 + bool state) 154 155 { 155 156 struct ad7091r_state *st = iio_priv(indio_dev); 156 157
+3
drivers/iio/adc/ad7192.c
··· 1394 1394 st->int_vref_mv = ret == -ENODEV ? avdd_mv : ret / MILLI; 1395 1395 1396 1396 st->chip_info = spi_get_device_match_data(spi); 1397 + if (!st->chip_info) 1398 + return -ENODEV; 1399 + 1397 1400 indio_dev->name = st->chip_info->name; 1398 1401 indio_dev->modes = INDIO_DIRECT_MODE; 1399 1402 indio_dev->info = st->chip_info->info;
+6 -8
drivers/iio/adc/ad7280a.c
··· 822 822 if (FIELD_GET(AD7280A_TRANS_READ_CONV_CHANADDR_MSK, channels[i]) <= 823 823 AD7280A_CELL_VOLTAGE_6_REG) { 824 824 if (val >= st->cell_threshhigh) { 825 - u64 tmp = IIO_EVENT_CODE(IIO_VOLTAGE, 1, 0, 826 - IIO_EV_DIR_RISING, 827 - IIO_EV_TYPE_THRESH, 828 - 0, 0, 0); 825 + u64 tmp = IIO_DIFF_EVENT_CODE(IIO_VOLTAGE, 0, 0, 826 + IIO_EV_TYPE_THRESH, 827 + IIO_EV_DIR_RISING); 829 828 iio_push_event(indio_dev, tmp, 830 829 iio_get_time_ns(indio_dev)); 831 830 } else if (val <= st->cell_threshlow) { 832 - u64 tmp = IIO_EVENT_CODE(IIO_VOLTAGE, 1, 0, 833 - IIO_EV_DIR_FALLING, 834 - IIO_EV_TYPE_THRESH, 835 - 0, 0, 0); 831 + u64 tmp = IIO_DIFF_EVENT_CODE(IIO_VOLTAGE, 0, 0, 832 + IIO_EV_TYPE_THRESH, 833 + IIO_EV_DIR_FALLING); 836 834 iio_push_event(indio_dev, tmp, 837 835 iio_get_time_ns(indio_dev)); 838 836 }
+1 -1
drivers/iio/adc/ad7291.c
··· 269 269 const struct iio_chan_spec *chan, 270 270 enum iio_event_type type, 271 271 enum iio_event_direction dir, 272 - int state) 272 + bool state) 273 273 { 274 274 int ret = 0; 275 275 struct ad7291_chip_info *chip = iio_priv(indio_dev);
+154 -24
drivers/iio/adc/ad7380.c
··· 13 13 * ad7381-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7381-4.pdf 14 14 * ad7383/4-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7383-4-ad7384-4.pdf 15 15 * ad7386/7/8-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7386-4-7387-4-7388-4.pdf 16 + * adaq4370-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/adaq4370-4.pdf 17 + * adaq4380-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/adaq4380-4.pdf 16 18 */ 17 19 18 20 #include <linux/align.h> ··· 24 22 #include <linux/device.h> 25 23 #include <linux/err.h> 26 24 #include <linux/kernel.h> 25 + #include <linux/math.h> 27 26 #include <linux/module.h> 28 27 #include <linux/regmap.h> 29 28 #include <linux/regulator/consumer.h> 30 29 #include <linux/slab.h> 31 30 #include <linux/spi/spi.h> 31 + #include <linux/units.h> 32 + #include <linux/util_macros.h> 32 33 33 34 #include <linux/iio/buffer.h> 34 35 #include <linux/iio/iio.h> ··· 41 36 #define MAX_NUM_CHANNELS 8 42 37 /* 2.5V internal reference voltage */ 43 38 #define AD7380_INTERNAL_REF_MV 2500 39 + /* 3.3V internal reference voltage for ADAQ */ 40 + #define ADAQ4380_INTERNAL_REF_MV 3300 44 41 45 42 /* reading and writing registers is more reliable at lower than max speed */ 46 43 #define AD7380_REG_WR_SPEED_HZ 10000000 ··· 84 77 #define T_CONVERT_X_NS 500 /* xth conversion start time (oversampling) */ 85 78 #define T_POWERUP_US 5000 /* Power up */ 86 79 80 + /* 81 + * AD738x support several SDO lines to increase throughput, but driver currently 82 + * supports only 1 SDO line (standard SPI transaction) 83 + */ 84 + #define AD7380_NUM_SDO_LINES 1 85 + #define AD7380_DEFAULT_GAIN_MILLI 1000 86 + 87 87 struct ad7380_timing_specs { 88 88 const unsigned int t_csh_ns; /* CS minimum high time */ 89 89 }; ··· 100 86 const struct iio_chan_spec *channels; 101 87 unsigned int num_channels; 102 88 unsigned int num_simult_channels; 89 + bool has_hardware_gain; 103 90 bool has_mux; 104 91 const char * const *supplies; 105 92 unsigned int num_supplies; 106 93 bool external_ref_only; 94 + bool adaq_internal_ref_only; 107 95 const char * const *vcm_supplies; 108 96 unsigned int num_vcm_supplies; 109 97 const unsigned long *available_scan_masks; ··· 197 181 }, 198 182 }; 199 183 200 - #define AD7380_CHANNEL(index, bits, diff, sign) { \ 184 + #define _AD7380_CHANNEL(index, bits, diff, sign, gain) { \ 201 185 .type = IIO_VOLTAGE, \ 202 186 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 187 + ((gain) ? BIT(IIO_CHAN_INFO_SCALE) : 0) | \ 203 188 ((diff) ? 0 : BIT(IIO_CHAN_INFO_OFFSET)), \ 204 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 189 + .info_mask_shared_by_type = ((gain) ? 0 : BIT(IIO_CHAN_INFO_SCALE)) | \ 205 190 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 206 191 .info_mask_shared_by_type_available = \ 207 192 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ ··· 215 198 .ext_scan_type = ad7380_scan_type_##bits##_##sign, \ 216 199 .num_ext_scan_type = ARRAY_SIZE(ad7380_scan_type_##bits##_##sign), \ 217 200 } 201 + 202 + #define AD7380_CHANNEL(index, bits, diff, sign) \ 203 + _AD7380_CHANNEL(index, bits, diff, sign, false) 204 + 205 + #define ADAQ4380_CHANNEL(index, bits, diff, sign) \ 206 + _AD7380_CHANNEL(index, bits, diff, sign, true) 218 207 219 208 #define DEFINE_AD7380_2_CHANNEL(name, bits, diff, sign) \ 220 209 static const struct iio_chan_spec name[] = { \ ··· 236 213 AD7380_CHANNEL(2, bits, diff, sign), \ 237 214 AD7380_CHANNEL(3, bits, diff, sign), \ 238 215 IIO_CHAN_SOFT_TIMESTAMP(4), \ 216 + } 217 + 218 + #define DEFINE_ADAQ4380_4_CHANNEL(name, bits, diff, sign) \ 219 + static const struct iio_chan_spec name[] = { \ 220 + ADAQ4380_CHANNEL(0, bits, diff, sign), \ 221 + ADAQ4380_CHANNEL(1, bits, diff, sign), \ 222 + ADAQ4380_CHANNEL(2, bits, diff, sign), \ 223 + ADAQ4380_CHANNEL(3, bits, diff, sign), \ 224 + IIO_CHAN_SOFT_TIMESTAMP(4), \ 239 225 } 240 226 241 227 #define DEFINE_AD7380_8_CHANNEL(name, bits, diff, sign) \ ··· 265 233 DEFINE_AD7380_2_CHANNEL(ad7381_channels, 14, 1, s); 266 234 DEFINE_AD7380_4_CHANNEL(ad7380_4_channels, 16, 1, s); 267 235 DEFINE_AD7380_4_CHANNEL(ad7381_4_channels, 14, 1, s); 236 + DEFINE_ADAQ4380_4_CHANNEL(adaq4380_4_channels, 16, 1, s); 268 237 /* pseudo differential */ 269 238 DEFINE_AD7380_2_CHANNEL(ad7383_channels, 16, 0, s); 270 239 DEFINE_AD7380_2_CHANNEL(ad7384_channels, 14, 0, s); ··· 282 249 283 250 static const char * const ad7380_supplies[] = { 284 251 "vcc", "vlogic", 252 + }; 253 + 254 + static const char * const adaq4380_supplies[] = { 255 + "ldo", "vcc", "vlogic", "vs-p", "vs-n", "refin", 285 256 }; 286 257 287 258 static const char * const ad7380_2_channel_vcm_supplies[] = { ··· 376 339 */ 377 340 static const int ad7380_oversampling_ratios[] = { 378 341 1, 2, 4, 8, 16, 32, 342 + }; 343 + 344 + /* Gains stored as fractions of 1000 so they can be expressed by integers. */ 345 + static const int ad7380_gains[] = { 346 + 300, 600, 1000, 1600, 379 347 }; 380 348 381 349 static const struct ad7380_chip_info ad7380_chip_info = { ··· 552 510 .timing_specs = &ad7380_4_timing, 553 511 }; 554 512 513 + static const struct ad7380_chip_info adaq4370_4_chip_info = { 514 + .name = "adaq4370-4", 515 + .channels = adaq4380_4_channels, 516 + .num_channels = ARRAY_SIZE(adaq4380_4_channels), 517 + .num_simult_channels = 4, 518 + .supplies = adaq4380_supplies, 519 + .num_supplies = ARRAY_SIZE(adaq4380_supplies), 520 + .adaq_internal_ref_only = true, 521 + .has_hardware_gain = true, 522 + .available_scan_masks = ad7380_4_channel_scan_masks, 523 + .timing_specs = &ad7380_4_timing, 524 + }; 525 + 526 + static const struct ad7380_chip_info adaq4380_4_chip_info = { 527 + .name = "adaq4380-4", 528 + .channels = adaq4380_4_channels, 529 + .num_channels = ARRAY_SIZE(adaq4380_4_channels), 530 + .num_simult_channels = 4, 531 + .supplies = adaq4380_supplies, 532 + .num_supplies = ARRAY_SIZE(adaq4380_supplies), 533 + .adaq_internal_ref_only = true, 534 + .has_hardware_gain = true, 535 + .available_scan_masks = ad7380_4_channel_scan_masks, 536 + .timing_specs = &ad7380_4_timing, 537 + }; 538 + 555 539 struct ad7380_state { 556 540 const struct ad7380_chip_info *chip_info; 557 541 struct spi_device *spi; ··· 588 520 bool seq; 589 521 unsigned int vref_mv; 590 522 unsigned int vcm_mv[MAX_NUM_CHANNELS]; 523 + unsigned int gain_milli[MAX_NUM_CHANNELS]; 591 524 /* xfers, message an buffer for reading sample data */ 592 525 struct spi_transfer normal_xfer[2]; 593 526 struct spi_message normal_msg; ··· 718 649 719 650 if (st->oversampling_ratio > 1) 720 651 xfer.delay.value = T_CONVERT_0_NS + 721 - T_CONVERT_X_NS * (st->oversampling_ratio - 1); 652 + T_CONVERT_X_NS * (st->oversampling_ratio - 1) * 653 + st->chip_info->num_simult_channels / AD7380_NUM_SDO_LINES; 722 654 723 655 return spi_sync_transfer(st->spi, &xfer, 1); 724 656 } ··· 742 672 */ 743 673 if (st->oversampling_ratio > 1) 744 674 t_convert = T_CONVERT_0_NS + T_CONVERT_X_NS * 745 - (st->oversampling_ratio - 1); 675 + (st->oversampling_ratio - 1) * 676 + st->chip_info->num_simult_channels / AD7380_NUM_SDO_LINES; 746 677 747 678 if (st->seq) { 748 679 xfer[0].delay.value = xfer[1].delay.value = t_convert; ··· 939 868 * * (2 × VREF) / 2^N, for differential chips 940 869 * * VREF / 2^N, for pseudo-differential chips 941 870 * where N is the ADC resolution (i.e realbits) 871 + * 872 + * The gain is stored as a fraction of 1000 and, as we need to 873 + * divide vref_mv by the gain, we invert the gain/1000 fraction. 942 874 */ 943 - *val = st->vref_mv; 875 + if (st->chip_info->has_hardware_gain) 876 + *val = mult_frac(st->vref_mv, MILLI, 877 + st->gain_milli[chan->scan_index]); 878 + else 879 + *val = st->vref_mv; 944 880 *val2 = scan_type->realbits - chan->differential; 945 881 946 882 return IIO_VAL_FRACTIONAL_LOG2; ··· 1099 1021 /* SPI 1-wire mode */ 1100 1022 return regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2, 1101 1023 AD7380_CONFIG2_SDO, 1102 - FIELD_PREP(AD7380_CONFIG2_SDO, 1)); 1024 + FIELD_PREP(AD7380_CONFIG2_SDO, 1025 + AD7380_NUM_SDO_LINES)); 1103 1026 } 1104 1027 1105 1028 static int ad7380_probe(struct spi_device *spi) 1106 1029 { 1030 + struct device *dev = &spi->dev; 1107 1031 struct iio_dev *indio_dev; 1108 1032 struct ad7380_state *st; 1109 1033 bool external_ref_en; 1110 1034 int ret, i; 1111 1035 1112 - indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 1036 + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 1113 1037 if (!indio_dev) 1114 1038 return -ENOMEM; 1115 1039 ··· 1119 1039 st->spi = spi; 1120 1040 st->chip_info = spi_get_device_match_data(spi); 1121 1041 if (!st->chip_info) 1122 - return dev_err_probe(&spi->dev, -EINVAL, "missing match data\n"); 1042 + return dev_err_probe(dev, -EINVAL, "missing match data\n"); 1123 1043 1124 - ret = devm_regulator_bulk_get_enable(&spi->dev, st->chip_info->num_supplies, 1044 + ret = devm_regulator_bulk_get_enable(dev, st->chip_info->num_supplies, 1125 1045 st->chip_info->supplies); 1126 1046 1127 1047 if (ret) 1128 - return dev_err_probe(&spi->dev, ret, 1048 + return dev_err_probe(dev, ret, 1129 1049 "Failed to enable power supplies\n"); 1130 1050 fsleep(T_POWERUP_US); 1131 1051 1132 - if (st->chip_info->external_ref_only) { 1133 - ret = devm_regulator_get_enable_read_voltage(&spi->dev, 1134 - "refin"); 1052 + if (st->chip_info->adaq_internal_ref_only) { 1053 + /* 1054 + * ADAQ chips use fixed internal reference but still 1055 + * require a specific reference supply to power it. 1056 + * "refin" is already enabled with other power supplies 1057 + * in bulk_get_enable(). 1058 + */ 1059 + 1060 + st->vref_mv = ADAQ4380_INTERNAL_REF_MV; 1061 + 1062 + /* these chips don't have a register bit for this */ 1063 + external_ref_en = false; 1064 + } else if (st->chip_info->external_ref_only) { 1065 + ret = devm_regulator_get_enable_read_voltage(dev, "refin"); 1135 1066 if (ret < 0) 1136 - return dev_err_probe(&spi->dev, ret, 1067 + return dev_err_probe(dev, ret, 1137 1068 "Failed to get refin regulator\n"); 1138 1069 1139 1070 st->vref_mv = ret / 1000; ··· 1156 1065 * If there is no REFIO supply, then it means that we are using 1157 1066 * the internal reference, otherwise REFIO is reference voltage. 1158 1067 */ 1159 - ret = devm_regulator_get_enable_read_voltage(&spi->dev, 1160 - "refio"); 1068 + ret = devm_regulator_get_enable_read_voltage(dev, "refio"); 1161 1069 if (ret < 0 && ret != -ENODEV) 1162 - return dev_err_probe(&spi->dev, ret, 1070 + return dev_err_probe(dev, ret, 1163 1071 "Failed to get refio regulator\n"); 1164 1072 1165 1073 external_ref_en = ret != -ENODEV; ··· 1166 1076 } 1167 1077 1168 1078 if (st->chip_info->num_vcm_supplies > ARRAY_SIZE(st->vcm_mv)) 1169 - return dev_err_probe(&spi->dev, -EINVAL, 1079 + return dev_err_probe(dev, -EINVAL, 1170 1080 "invalid number of VCM supplies\n"); 1171 1081 1172 1082 /* ··· 1176 1086 for (i = 0; i < st->chip_info->num_vcm_supplies; i++) { 1177 1087 const char *vcm = st->chip_info->vcm_supplies[i]; 1178 1088 1179 - ret = devm_regulator_get_enable_read_voltage(&spi->dev, vcm); 1089 + ret = devm_regulator_get_enable_read_voltage(dev, vcm); 1180 1090 if (ret < 0) 1181 - return dev_err_probe(&spi->dev, ret, 1091 + return dev_err_probe(dev, ret, 1182 1092 "Failed to get %s regulator\n", 1183 1093 vcm); 1184 1094 1185 1095 st->vcm_mv[i] = ret / 1000; 1186 1096 } 1187 1097 1188 - st->regmap = devm_regmap_init(&spi->dev, NULL, st, &ad7380_regmap_config); 1098 + for (i = 0; i < MAX_NUM_CHANNELS; i++) 1099 + st->gain_milli[i] = AD7380_DEFAULT_GAIN_MILLI; 1100 + 1101 + if (st->chip_info->has_hardware_gain) { 1102 + device_for_each_child_node_scoped(dev, node) { 1103 + unsigned int channel, gain; 1104 + int gain_idx; 1105 + 1106 + ret = fwnode_property_read_u32(node, "reg", &channel); 1107 + if (ret) 1108 + return dev_err_probe(dev, ret, 1109 + "Failed to read reg property\n"); 1110 + 1111 + if (channel >= st->chip_info->num_channels - 1) 1112 + return dev_err_probe(dev, -EINVAL, 1113 + "Invalid channel number %i\n", 1114 + channel); 1115 + 1116 + ret = fwnode_property_read_u32(node, "adi,gain-milli", 1117 + &gain); 1118 + if (ret && ret != -EINVAL) 1119 + return dev_err_probe(dev, ret, 1120 + "Failed to read gain for channel %i\n", 1121 + channel); 1122 + if (ret != -EINVAL) { 1123 + /* 1124 + * Match gain value from dt to one of supported 1125 + * gains 1126 + */ 1127 + gain_idx = find_closest(gain, ad7380_gains, 1128 + ARRAY_SIZE(ad7380_gains)); 1129 + st->gain_milli[channel] = ad7380_gains[gain_idx]; 1130 + } 1131 + } 1132 + } 1133 + 1134 + st->regmap = devm_regmap_init(dev, NULL, st, &ad7380_regmap_config); 1189 1135 if (IS_ERR(st->regmap)) 1190 - return dev_err_probe(&spi->dev, PTR_ERR(st->regmap), 1136 + return dev_err_probe(dev, PTR_ERR(st->regmap), 1191 1137 "failed to allocate register map\n"); 1192 1138 1193 1139 /* ··· 1274 1148 indio_dev->modes = INDIO_DIRECT_MODE; 1275 1149 indio_dev->available_scan_masks = st->chip_info->available_scan_masks; 1276 1150 1277 - ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, 1151 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 1278 1152 iio_pollfunc_store_time, 1279 1153 ad7380_trigger_handler, 1280 1154 &ad7380_buffer_setup_ops); ··· 1285 1159 if (ret) 1286 1160 return ret; 1287 1161 1288 - return devm_iio_device_register(&spi->dev, indio_dev); 1162 + return devm_iio_device_register(dev, indio_dev); 1289 1163 } 1290 1164 1291 1165 static const struct of_device_id ad7380_of_match_table[] = { ··· 1303 1177 { .compatible = "adi,ad7386-4", .data = &ad7386_4_chip_info }, 1304 1178 { .compatible = "adi,ad7387-4", .data = &ad7387_4_chip_info }, 1305 1179 { .compatible = "adi,ad7388-4", .data = &ad7388_4_chip_info }, 1180 + { .compatible = "adi,adaq4370-4", .data = &adaq4370_4_chip_info }, 1181 + { .compatible = "adi,adaq4380-4", .data = &adaq4380_4_chip_info }, 1306 1182 { } 1307 1183 }; 1308 1184 ··· 1323 1195 { "ad7386-4", (kernel_ulong_t)&ad7386_4_chip_info }, 1324 1196 { "ad7387-4", (kernel_ulong_t)&ad7387_4_chip_info }, 1325 1197 { "ad7388-4", (kernel_ulong_t)&ad7388_4_chip_info }, 1198 + { "adaq4370-4", (kernel_ulong_t)&adaq4370_4_chip_info }, 1199 + { "adaq4380-4", (kernel_ulong_t)&adaq4380_4_chip_info }, 1326 1200 { } 1327 1201 }; 1328 1202 MODULE_DEVICE_TABLE(spi, ad7380_id_table);
+572 -225
drivers/iio/adc/ad7606.c
··· 13 13 #include <linux/kernel.h> 14 14 #include <linux/module.h> 15 15 #include <linux/property.h> 16 + #include <linux/pwm.h> 16 17 #include <linux/regulator/consumer.h> 17 18 #include <linux/sched.h> 18 19 #include <linux/slab.h> 19 20 #include <linux/sysfs.h> 21 + #include <linux/units.h> 20 22 #include <linux/util_macros.h> 21 23 24 + #include <linux/iio/backend.h> 22 25 #include <linux/iio/buffer.h> 23 26 #include <linux/iio/iio.h> 24 27 #include <linux/iio/sysfs.h> ··· 33 30 34 31 /* 35 32 * Scales are computed as 5000/32768 and 10000/32768 respectively, 36 - * so that when applied to the raw values they provide mV values 33 + * so that when applied to the raw values they provide mV values. 34 + * The scale arrays are kept as IIO_VAL_INT_PLUS_MICRO, so index 35 + * X is the integer part and X + 1 is the fractional part. 37 36 */ 38 - static const unsigned int ad7606_16bit_hw_scale_avail[2] = { 39 - 152588, 305176 37 + static const unsigned int ad7606_16bit_hw_scale_avail[2][2] = { 38 + { 0, 152588 }, { 0, 305176 } 40 39 }; 41 40 42 - static const unsigned int ad7606_18bit_hw_scale_avail[2] = { 43 - 38147, 76294 41 + static const unsigned int ad7606_18bit_hw_scale_avail[2][2] = { 42 + { 0, 38147 }, { 0, 76294 } 44 43 }; 45 44 46 - static const unsigned int ad7606c_16bit_single_ended_unipolar_scale_avail[3] = { 47 - 76294, 152588, 190735, 45 + static const unsigned int ad7606c_16bit_single_ended_unipolar_scale_avail[3][2] = { 46 + { 0, 76294 }, { 0, 152588 }, { 0, 190735 } 48 47 }; 49 48 50 - static const unsigned int ad7606c_16bit_single_ended_bipolar_scale_avail[5] = { 51 - 76294, 152588, 190735, 305176, 381470 49 + static const unsigned int ad7606c_16bit_single_ended_bipolar_scale_avail[5][2] = { 50 + { 0, 76294 }, { 0, 152588 }, { 0, 190735 }, { 0, 305176 }, { 0, 381470 } 52 51 }; 53 52 54 - static const unsigned int ad7606c_16bit_differential_bipolar_scale_avail[4] = { 55 - 152588, 305176, 381470, 610352 53 + static const unsigned int ad7606c_16bit_differential_bipolar_scale_avail[4][2] = { 54 + { 0, 152588 }, { 0, 305176 }, { 0, 381470 }, { 0, 610352 } 56 55 }; 57 56 58 - static const unsigned int ad7606c_18bit_single_ended_unipolar_scale_avail[3] = { 59 - 19073, 38147, 47684 57 + static const unsigned int ad7606c_18bit_single_ended_unipolar_scale_avail[3][2] = { 58 + { 0, 19073 }, { 0, 38147 }, { 0, 47684 } 60 59 }; 61 60 62 - static const unsigned int ad7606c_18bit_single_ended_bipolar_scale_avail[5] = { 63 - 19073, 38147, 47684, 76294, 95367 61 + static const unsigned int ad7606c_18bit_single_ended_bipolar_scale_avail[5][2] = { 62 + { 0, 19073 }, { 0, 38147 }, { 0, 47684 }, { 0, 76294 }, { 0, 95367 } 64 63 }; 65 64 66 - static const unsigned int ad7606c_18bit_differential_bipolar_scale_avail[4] = { 67 - 38147, 76294, 95367, 152588 65 + static const unsigned int ad7606c_18bit_differential_bipolar_scale_avail[4][2] = { 66 + { 0, 38147 }, { 0, 76294 }, { 0, 95367 }, { 0, 152588 } 68 67 }; 69 68 70 - static const unsigned int ad7606_16bit_sw_scale_avail[3] = { 71 - 76293, 152588, 305176 69 + static const unsigned int ad7606_16bit_sw_scale_avail[3][2] = { 70 + { 0, 76293 }, { 0, 152588 }, { 0, 305176 } 71 + }; 72 + 73 + static const unsigned int ad7607_hw_scale_avail[2][2] = { 74 + { 0, 610352 }, { 1, 220703 } 75 + }; 76 + 77 + static const unsigned int ad7609_hw_scale_avail[2][2] = { 78 + { 0, 152588 }, { 0, 305176 } 72 79 }; 73 80 74 81 static const unsigned int ad7606_oversampling_avail[7] = { ··· 88 75 static const unsigned int ad7616_oversampling_avail[8] = { 89 76 1, 2, 4, 8, 16, 32, 64, 128, 90 77 }; 78 + 79 + static const struct iio_chan_spec ad7605_channels[] = { 80 + IIO_CHAN_SOFT_TIMESTAMP(4), 81 + AD7605_CHANNEL(0), 82 + AD7605_CHANNEL(1), 83 + AD7605_CHANNEL(2), 84 + AD7605_CHANNEL(3), 85 + }; 86 + 87 + static const struct iio_chan_spec ad7606_channels_16bit[] = { 88 + IIO_CHAN_SOFT_TIMESTAMP(8), 89 + AD7606_CHANNEL(0, 16), 90 + AD7606_CHANNEL(1, 16), 91 + AD7606_CHANNEL(2, 16), 92 + AD7606_CHANNEL(3, 16), 93 + AD7606_CHANNEL(4, 16), 94 + AD7606_CHANNEL(5, 16), 95 + AD7606_CHANNEL(6, 16), 96 + AD7606_CHANNEL(7, 16), 97 + }; 98 + 99 + static const struct iio_chan_spec ad7606_channels_18bit[] = { 100 + IIO_CHAN_SOFT_TIMESTAMP(8), 101 + AD7606_CHANNEL(0, 18), 102 + AD7606_CHANNEL(1, 18), 103 + AD7606_CHANNEL(2, 18), 104 + AD7606_CHANNEL(3, 18), 105 + AD7606_CHANNEL(4, 18), 106 + AD7606_CHANNEL(5, 18), 107 + AD7606_CHANNEL(6, 18), 108 + AD7606_CHANNEL(7, 18), 109 + }; 110 + 111 + static const struct iio_chan_spec ad7607_channels[] = { 112 + IIO_CHAN_SOFT_TIMESTAMP(8), 113 + AD7606_CHANNEL(0, 14), 114 + AD7606_CHANNEL(1, 14), 115 + AD7606_CHANNEL(2, 14), 116 + AD7606_CHANNEL(3, 14), 117 + AD7606_CHANNEL(4, 14), 118 + AD7606_CHANNEL(5, 14), 119 + AD7606_CHANNEL(6, 14), 120 + AD7606_CHANNEL(7, 14), 121 + }; 122 + 123 + static const struct iio_chan_spec ad7608_channels[] = { 124 + IIO_CHAN_SOFT_TIMESTAMP(8), 125 + AD7606_CHANNEL(0, 18), 126 + AD7606_CHANNEL(1, 18), 127 + AD7606_CHANNEL(2, 18), 128 + AD7606_CHANNEL(3, 18), 129 + AD7606_CHANNEL(4, 18), 130 + AD7606_CHANNEL(5, 18), 131 + AD7606_CHANNEL(6, 18), 132 + AD7606_CHANNEL(7, 18), 133 + }; 134 + 135 + /* 136 + * The current assumption that this driver makes for AD7616, is that it's 137 + * working in Hardware Mode with Serial, Burst and Sequencer modes activated. 138 + * To activate them, following pins must be pulled high: 139 + * -SER/PAR 140 + * -SEQEN 141 + * And following pins must be pulled low: 142 + * -WR/BURST 143 + * -DB4/SER1W 144 + */ 145 + static const struct iio_chan_spec ad7616_channels[] = { 146 + IIO_CHAN_SOFT_TIMESTAMP(16), 147 + AD7606_CHANNEL(0, 16), 148 + AD7606_CHANNEL(1, 16), 149 + AD7606_CHANNEL(2, 16), 150 + AD7606_CHANNEL(3, 16), 151 + AD7606_CHANNEL(4, 16), 152 + AD7606_CHANNEL(5, 16), 153 + AD7606_CHANNEL(6, 16), 154 + AD7606_CHANNEL(7, 16), 155 + AD7606_CHANNEL(8, 16), 156 + AD7606_CHANNEL(9, 16), 157 + AD7606_CHANNEL(10, 16), 158 + AD7606_CHANNEL(11, 16), 159 + AD7606_CHANNEL(12, 16), 160 + AD7606_CHANNEL(13, 16), 161 + AD7606_CHANNEL(14, 16), 162 + AD7606_CHANNEL(15, 16), 163 + }; 164 + 165 + static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st, 166 + struct iio_chan_spec *chan, int ch); 167 + static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st, 168 + struct iio_chan_spec *chan, int ch); 169 + static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st, 170 + struct iio_chan_spec *chan, int ch); 171 + static int ad7607_chan_scale_setup(struct ad7606_state *st, 172 + struct iio_chan_spec *chan, int ch); 173 + static int ad7608_chan_scale_setup(struct ad7606_state *st, 174 + struct iio_chan_spec *chan, int ch); 175 + static int ad7609_chan_scale_setup(struct ad7606_state *st, 176 + struct iio_chan_spec *chan, int ch); 177 + 178 + const struct ad7606_chip_info ad7605_4_info = { 179 + .channels = ad7605_channels, 180 + .name = "ad7605-4", 181 + .num_adc_channels = 4, 182 + .num_channels = 5, 183 + .scale_setup_cb = ad7606_16bit_chan_scale_setup, 184 + }; 185 + EXPORT_SYMBOL_NS_GPL(ad7605_4_info, IIO_AD7606); 186 + 187 + const struct ad7606_chip_info ad7606_8_info = { 188 + .channels = ad7606_channels_16bit, 189 + .name = "ad7606-8", 190 + .num_adc_channels = 8, 191 + .num_channels = 9, 192 + .oversampling_avail = ad7606_oversampling_avail, 193 + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 194 + .scale_setup_cb = ad7606_16bit_chan_scale_setup, 195 + }; 196 + EXPORT_SYMBOL_NS_GPL(ad7606_8_info, IIO_AD7606); 197 + 198 + const struct ad7606_chip_info ad7606_6_info = { 199 + .channels = ad7606_channels_16bit, 200 + .name = "ad7606-6", 201 + .num_adc_channels = 6, 202 + .num_channels = 7, 203 + .oversampling_avail = ad7606_oversampling_avail, 204 + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 205 + .scale_setup_cb = ad7606_16bit_chan_scale_setup, 206 + }; 207 + EXPORT_SYMBOL_NS_GPL(ad7606_6_info, IIO_AD7606); 208 + 209 + const struct ad7606_chip_info ad7606_4_info = { 210 + .channels = ad7606_channels_16bit, 211 + .name = "ad7606-4", 212 + .num_adc_channels = 4, 213 + .num_channels = 5, 214 + .oversampling_avail = ad7606_oversampling_avail, 215 + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 216 + .scale_setup_cb = ad7606_16bit_chan_scale_setup, 217 + }; 218 + EXPORT_SYMBOL_NS_GPL(ad7606_4_info, IIO_AD7606); 219 + 220 + const struct ad7606_chip_info ad7606b_info = { 221 + .channels = ad7606_channels_16bit, 222 + .max_samplerate = 800 * KILO, 223 + .name = "ad7606b", 224 + .num_adc_channels = 8, 225 + .num_channels = 9, 226 + .oversampling_avail = ad7606_oversampling_avail, 227 + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 228 + .scale_setup_cb = ad7606_16bit_chan_scale_setup, 229 + }; 230 + EXPORT_SYMBOL_NS_GPL(ad7606b_info, IIO_AD7606); 231 + 232 + const struct ad7606_chip_info ad7606c_16_info = { 233 + .channels = ad7606_channels_16bit, 234 + .name = "ad7606c16", 235 + .num_adc_channels = 8, 236 + .num_channels = 9, 237 + .oversampling_avail = ad7606_oversampling_avail, 238 + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 239 + .scale_setup_cb = ad7606c_16bit_chan_scale_setup, 240 + }; 241 + EXPORT_SYMBOL_NS_GPL(ad7606c_16_info, IIO_AD7606); 242 + 243 + const struct ad7606_chip_info ad7607_info = { 244 + .channels = ad7607_channels, 245 + .name = "ad7607", 246 + .num_adc_channels = 8, 247 + .num_channels = 9, 248 + .oversampling_avail = ad7606_oversampling_avail, 249 + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 250 + .scale_setup_cb = ad7607_chan_scale_setup, 251 + }; 252 + EXPORT_SYMBOL_NS_GPL(ad7607_info, IIO_AD7606); 253 + 254 + const struct ad7606_chip_info ad7608_info = { 255 + .channels = ad7608_channels, 256 + .name = "ad7608", 257 + .num_adc_channels = 8, 258 + .num_channels = 9, 259 + .oversampling_avail = ad7606_oversampling_avail, 260 + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 261 + .scale_setup_cb = ad7608_chan_scale_setup, 262 + }; 263 + EXPORT_SYMBOL_NS_GPL(ad7608_info, IIO_AD7606); 264 + 265 + const struct ad7606_chip_info ad7609_info = { 266 + .channels = ad7608_channels, 267 + .name = "ad7609", 268 + .num_adc_channels = 8, 269 + .num_channels = 9, 270 + .oversampling_avail = ad7606_oversampling_avail, 271 + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 272 + .scale_setup_cb = ad7609_chan_scale_setup, 273 + }; 274 + EXPORT_SYMBOL_NS_GPL(ad7609_info, IIO_AD7606); 275 + 276 + const struct ad7606_chip_info ad7606c_18_info = { 277 + .channels = ad7606_channels_18bit, 278 + .name = "ad7606c18", 279 + .num_adc_channels = 8, 280 + .num_channels = 9, 281 + .oversampling_avail = ad7606_oversampling_avail, 282 + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 283 + .scale_setup_cb = ad7606c_18bit_chan_scale_setup, 284 + }; 285 + EXPORT_SYMBOL_NS_GPL(ad7606c_18_info, IIO_AD7606); 286 + 287 + const struct ad7606_chip_info ad7616_info = { 288 + .channels = ad7616_channels, 289 + .init_delay_ms = 15, 290 + .name = "ad7616", 291 + .num_adc_channels = 16, 292 + .num_channels = 17, 293 + .oversampling_avail = ad7616_oversampling_avail, 294 + .oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail), 295 + .os_req_reset = true, 296 + .scale_setup_cb = ad7606_16bit_chan_scale_setup, 297 + }; 298 + EXPORT_SYMBOL_NS_GPL(ad7616_info, IIO_AD7606); 91 299 92 300 int ad7606_reset(struct ad7606_state *st) 93 301 { ··· 512 278 return 0; 513 279 } 514 280 281 + static int ad7607_chan_scale_setup(struct ad7606_state *st, 282 + struct iio_chan_spec *chan, int ch) 283 + { 284 + struct ad7606_chan_scale *cs = &st->chan_scales[ch]; 285 + 286 + cs->range = 0; 287 + cs->scale_avail = ad7607_hw_scale_avail; 288 + cs->num_scales = ARRAY_SIZE(ad7607_hw_scale_avail); 289 + return 0; 290 + } 291 + 292 + static int ad7608_chan_scale_setup(struct ad7606_state *st, 293 + struct iio_chan_spec *chan, int ch) 294 + { 295 + struct ad7606_chan_scale *cs = &st->chan_scales[ch]; 296 + 297 + cs->range = 0; 298 + cs->scale_avail = ad7606_18bit_hw_scale_avail; 299 + cs->num_scales = ARRAY_SIZE(ad7606_18bit_hw_scale_avail); 300 + return 0; 301 + } 302 + 303 + static int ad7609_chan_scale_setup(struct ad7606_state *st, 304 + struct iio_chan_spec *chan, int ch) 305 + { 306 + struct ad7606_chan_scale *cs = &st->chan_scales[ch]; 307 + 308 + cs->range = 0; 309 + cs->scale_avail = ad7609_hw_scale_avail; 310 + cs->num_scales = ARRAY_SIZE(ad7609_hw_scale_avail); 311 + return 0; 312 + } 313 + 515 314 static int ad7606_reg_access(struct iio_dev *indio_dev, 516 315 unsigned int reg, 517 316 unsigned int writeval, ··· 566 299 } 567 300 } 568 301 302 + static int ad7606_pwm_set_high(struct ad7606_state *st) 303 + { 304 + struct pwm_state cnvst_pwm_state; 305 + int ret; 306 + 307 + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state); 308 + cnvst_pwm_state.enabled = true; 309 + cnvst_pwm_state.duty_cycle = cnvst_pwm_state.period; 310 + 311 + ret = pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state); 312 + 313 + return ret; 314 + } 315 + 316 + static int ad7606_pwm_set_low(struct ad7606_state *st) 317 + { 318 + struct pwm_state cnvst_pwm_state; 319 + int ret; 320 + 321 + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state); 322 + cnvst_pwm_state.enabled = true; 323 + cnvst_pwm_state.duty_cycle = 0; 324 + 325 + ret = pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state); 326 + 327 + return ret; 328 + } 329 + 330 + static int ad7606_pwm_set_swing(struct ad7606_state *st) 331 + { 332 + struct pwm_state cnvst_pwm_state; 333 + 334 + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state); 335 + cnvst_pwm_state.enabled = true; 336 + cnvst_pwm_state.duty_cycle = cnvst_pwm_state.period / 2; 337 + 338 + return pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state); 339 + } 340 + 341 + static bool ad7606_pwm_is_swinging(struct ad7606_state *st) 342 + { 343 + struct pwm_state cnvst_pwm_state; 344 + 345 + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state); 346 + 347 + return cnvst_pwm_state.duty_cycle != cnvst_pwm_state.period && 348 + cnvst_pwm_state.duty_cycle != 0; 349 + } 350 + 351 + static int ad7606_set_sampling_freq(struct ad7606_state *st, unsigned long freq) 352 + { 353 + struct pwm_state cnvst_pwm_state; 354 + bool is_swinging = ad7606_pwm_is_swinging(st); 355 + bool is_high; 356 + 357 + if (freq == 0) 358 + return -EINVAL; 359 + 360 + /* Retrieve the previous state. */ 361 + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state); 362 + is_high = cnvst_pwm_state.duty_cycle == cnvst_pwm_state.period; 363 + 364 + cnvst_pwm_state.period = DIV_ROUND_UP_ULL(NSEC_PER_SEC, freq); 365 + cnvst_pwm_state.polarity = PWM_POLARITY_NORMAL; 366 + if (is_high) 367 + cnvst_pwm_state.duty_cycle = cnvst_pwm_state.period; 368 + else if (is_swinging) 369 + cnvst_pwm_state.duty_cycle = cnvst_pwm_state.period / 2; 370 + else 371 + cnvst_pwm_state.duty_cycle = 0; 372 + 373 + return pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state); 374 + } 375 + 569 376 static int ad7606_read_samples(struct ad7606_state *st) 570 377 { 571 - unsigned int num = st->chip_info->num_channels - 1; 378 + unsigned int num = st->chip_info->num_adc_channels; 572 379 573 380 return st->bops->read_block(st->dev, num, &st->data); 574 381 } ··· 674 333 int *val) 675 334 { 676 335 struct ad7606_state *st = iio_priv(indio_dev); 677 - unsigned int storagebits = st->chip_info->channels[1].scan_type.storagebits; 336 + unsigned int realbits = st->chip_info->channels[1].scan_type.realbits; 678 337 const struct iio_chan_spec *chan; 679 338 int ret; 680 339 681 - gpiod_set_value(st->gpio_convst, 1); 682 - ret = wait_for_completion_timeout(&st->completion, 683 - msecs_to_jiffies(1000)); 684 - if (!ret) { 685 - ret = -ETIMEDOUT; 686 - goto error_ret; 340 + if (st->gpio_convst) { 341 + gpiod_set_value(st->gpio_convst, 1); 342 + } else { 343 + ret = ad7606_pwm_set_high(st); 344 + if (ret < 0) 345 + return ret; 346 + } 347 + 348 + /* 349 + * If no backend, wait for the interruption on busy pin, otherwise just add 350 + * a delay to leave time for the data to be available. For now, the latter 351 + * will not happen because IIO_CHAN_INFO_RAW is not supported for the backend. 352 + * TODO: Add support for reading a single value when the backend is used. 353 + */ 354 + if (!st->back) { 355 + ret = wait_for_completion_timeout(&st->completion, 356 + msecs_to_jiffies(1000)); 357 + if (!ret) { 358 + ret = -ETIMEDOUT; 359 + goto error_ret; 360 + } 361 + } else { 362 + fsleep(1); 687 363 } 688 364 689 365 ret = ad7606_read_samples(st); ··· 709 351 710 352 chan = &indio_dev->channels[ch + 1]; 711 353 if (chan->scan_type.sign == 'u') { 712 - if (storagebits > 16) 354 + if (realbits > 16) 713 355 *val = st->data.buf32[ch]; 714 356 else 715 357 *val = st->data.buf16[ch]; 716 358 } else { 717 - if (storagebits > 16) 718 - *val = sign_extend32(st->data.buf32[ch], 17); 359 + if (realbits > 16) 360 + *val = sign_extend32(st->data.buf32[ch], realbits - 1); 719 361 else 720 - *val = sign_extend32(st->data.buf16[ch], 15); 362 + *val = sign_extend32(st->data.buf16[ch], realbits - 1); 721 363 } 722 364 723 365 error_ret: 366 + if (!st->gpio_convst) { 367 + ret = ad7606_pwm_set_low(st); 368 + if (ret < 0) 369 + return ret; 370 + } 724 371 gpiod_set_value(st->gpio_convst, 0); 725 372 726 373 return ret; ··· 740 377 int ret, ch = 0; 741 378 struct ad7606_state *st = iio_priv(indio_dev); 742 379 struct ad7606_chan_scale *cs; 380 + struct pwm_state cnvst_pwm_state; 743 381 744 382 switch (m) { 745 383 case IIO_CHAN_INFO_RAW: ··· 755 391 if (st->sw_mode_en) 756 392 ch = chan->address; 757 393 cs = &st->chan_scales[ch]; 758 - *val = 0; 759 - *val2 = cs->scale_avail[cs->range]; 394 + *val = cs->scale_avail[cs->range][0]; 395 + *val2 = cs->scale_avail[cs->range][1]; 760 396 return IIO_VAL_INT_PLUS_MICRO; 761 397 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 762 398 *val = st->oversampling; 763 399 return IIO_VAL_INT; 400 + case IIO_CHAN_INFO_SAMP_FREQ: 401 + /* 402 + * TODO: return the real frequency intead of the requested one once 403 + * pwm_get_state_hw comes upstream. 404 + */ 405 + pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state); 406 + *val = DIV_ROUND_CLOSEST_ULL(NSEC_PER_SEC, cnvst_pwm_state.period); 407 + return IIO_VAL_INT; 764 408 } 765 409 return -EINVAL; 766 - } 767 - 768 - static ssize_t ad7606_show_avail(char *buf, const unsigned int *vals, 769 - unsigned int n, bool micros) 770 - { 771 - size_t len = 0; 772 - int i; 773 - 774 - for (i = 0; i < n; i++) { 775 - len += scnprintf(buf + len, PAGE_SIZE - len, 776 - micros ? "0.%06u " : "%u ", vals[i]); 777 - } 778 - buf[len - 1] = '\n'; 779 - 780 - return len; 781 410 } 782 411 783 412 static ssize_t in_voltage_scale_available_show(struct device *dev, ··· 780 423 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 781 424 struct ad7606_state *st = iio_priv(indio_dev); 782 425 struct ad7606_chan_scale *cs = &st->chan_scales[0]; 426 + const unsigned int (*vals)[2] = cs->scale_avail; 427 + unsigned int i; 428 + size_t len = 0; 783 429 784 - return ad7606_show_avail(buf, cs->scale_avail, cs->num_scales, true); 430 + for (i = 0; i < cs->num_scales; i++) 431 + len += scnprintf(buf + len, PAGE_SIZE - len, "%u.%06u ", 432 + vals[i][0], vals[i][1]); 433 + buf[len - 1] = '\n'; 434 + 435 + return len; 785 436 } 786 437 787 438 static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0); ··· 827 462 long mask) 828 463 { 829 464 struct ad7606_state *st = iio_priv(indio_dev); 465 + unsigned int scale_avail_uv[AD760X_MAX_SCALES]; 830 466 struct ad7606_chan_scale *cs; 831 467 int i, ret, ch = 0; 832 468 ··· 838 472 if (st->sw_mode_en) 839 473 ch = chan->address; 840 474 cs = &st->chan_scales[ch]; 841 - i = find_closest(val2, cs->scale_avail, cs->num_scales); 475 + for (i = 0; i < cs->num_scales; i++) { 476 + scale_avail_uv[i] = cs->scale_avail[i][0] * MICRO + 477 + cs->scale_avail[i][1]; 478 + } 479 + val = (val * MICRO) + val2; 480 + i = find_closest(val, scale_avail_uv, cs->num_scales); 842 481 ret = st->write_scale(indio_dev, ch, i + cs->reg_offset); 843 482 if (ret < 0) 844 483 return ret; ··· 858 487 ret = st->write_os(indio_dev, i); 859 488 if (ret < 0) 860 489 return ret; 490 + st->oversampling = st->oversampling_avail[i]; 861 491 862 492 return 0; 493 + case IIO_CHAN_INFO_SAMP_FREQ: 494 + if (val < 0 && val2 != 0) 495 + return -EINVAL; 496 + return ad7606_set_sampling_freq(st, val); 863 497 default: 864 498 return -EINVAL; 865 499 } ··· 876 500 { 877 501 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 878 502 struct ad7606_state *st = iio_priv(indio_dev); 503 + const unsigned int *vals = st->oversampling_avail; 504 + unsigned int i; 505 + size_t len = 0; 879 506 880 - return ad7606_show_avail(buf, st->oversampling_avail, 881 - st->num_os_ratios, false); 507 + for (i = 0; i < st->num_os_ratios; i++) 508 + len += scnprintf(buf + len, PAGE_SIZE - len, "%u ", vals[i]); 509 + buf[len - 1] = '\n'; 510 + 511 + return len; 882 512 } 883 513 884 514 static IIO_DEVICE_ATTR(oversampling_ratio_available, 0444, ··· 918 536 .attrs = ad7606_attributes_range, 919 537 }; 920 538 921 - static const struct iio_chan_spec ad7605_channels[] = { 922 - IIO_CHAN_SOFT_TIMESTAMP(4), 923 - AD7605_CHANNEL(0), 924 - AD7605_CHANNEL(1), 925 - AD7605_CHANNEL(2), 926 - AD7605_CHANNEL(3), 927 - }; 928 - 929 - static const struct iio_chan_spec ad7606_channels_16bit[] = { 930 - IIO_CHAN_SOFT_TIMESTAMP(8), 931 - AD7606_CHANNEL(0, 16), 932 - AD7606_CHANNEL(1, 16), 933 - AD7606_CHANNEL(2, 16), 934 - AD7606_CHANNEL(3, 16), 935 - AD7606_CHANNEL(4, 16), 936 - AD7606_CHANNEL(5, 16), 937 - AD7606_CHANNEL(6, 16), 938 - AD7606_CHANNEL(7, 16), 939 - }; 940 - 941 - static const struct iio_chan_spec ad7606_channels_18bit[] = { 942 - IIO_CHAN_SOFT_TIMESTAMP(8), 943 - AD7606_CHANNEL(0, 18), 944 - AD7606_CHANNEL(1, 18), 945 - AD7606_CHANNEL(2, 18), 946 - AD7606_CHANNEL(3, 18), 947 - AD7606_CHANNEL(4, 18), 948 - AD7606_CHANNEL(5, 18), 949 - AD7606_CHANNEL(6, 18), 950 - AD7606_CHANNEL(7, 18), 951 - }; 952 - 953 - /* 954 - * The current assumption that this driver makes for AD7616, is that it's 955 - * working in Hardware Mode with Serial, Burst and Sequencer modes activated. 956 - * To activate them, following pins must be pulled high: 957 - * -SER/PAR 958 - * -SEQEN 959 - * And following pins must be pulled low: 960 - * -WR/BURST 961 - * -DB4/SER1W 962 - */ 963 - static const struct iio_chan_spec ad7616_channels[] = { 964 - IIO_CHAN_SOFT_TIMESTAMP(16), 965 - AD7606_CHANNEL(0, 16), 966 - AD7606_CHANNEL(1, 16), 967 - AD7606_CHANNEL(2, 16), 968 - AD7606_CHANNEL(3, 16), 969 - AD7606_CHANNEL(4, 16), 970 - AD7606_CHANNEL(5, 16), 971 - AD7606_CHANNEL(6, 16), 972 - AD7606_CHANNEL(7, 16), 973 - AD7606_CHANNEL(8, 16), 974 - AD7606_CHANNEL(9, 16), 975 - AD7606_CHANNEL(10, 16), 976 - AD7606_CHANNEL(11, 16), 977 - AD7606_CHANNEL(12, 16), 978 - AD7606_CHANNEL(13, 16), 979 - AD7606_CHANNEL(14, 16), 980 - AD7606_CHANNEL(15, 16), 981 - }; 982 - 983 - static const struct ad7606_chip_info ad7606_chip_info_tbl[] = { 984 - /* More devices added in future */ 985 - [ID_AD7605_4] = { 986 - .channels = ad7605_channels, 987 - .num_channels = 5, 988 - .scale_setup_cb = ad7606_16bit_chan_scale_setup, 989 - }, 990 - [ID_AD7606_8] = { 991 - .channels = ad7606_channels_16bit, 992 - .num_channels = 9, 993 - .scale_setup_cb = ad7606_16bit_chan_scale_setup, 994 - .oversampling_avail = ad7606_oversampling_avail, 995 - .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 996 - }, 997 - [ID_AD7606_6] = { 998 - .channels = ad7606_channels_16bit, 999 - .num_channels = 7, 1000 - .scale_setup_cb = ad7606_16bit_chan_scale_setup, 1001 - .oversampling_avail = ad7606_oversampling_avail, 1002 - .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 1003 - }, 1004 - [ID_AD7606_4] = { 1005 - .channels = ad7606_channels_16bit, 1006 - .num_channels = 5, 1007 - .scale_setup_cb = ad7606_16bit_chan_scale_setup, 1008 - .oversampling_avail = ad7606_oversampling_avail, 1009 - .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 1010 - }, 1011 - [ID_AD7606B] = { 1012 - .channels = ad7606_channels_16bit, 1013 - .num_channels = 9, 1014 - .scale_setup_cb = ad7606_16bit_chan_scale_setup, 1015 - .oversampling_avail = ad7606_oversampling_avail, 1016 - .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 1017 - }, 1018 - [ID_AD7606C_16] = { 1019 - .channels = ad7606_channels_16bit, 1020 - .num_channels = 9, 1021 - .scale_setup_cb = ad7606c_16bit_chan_scale_setup, 1022 - .oversampling_avail = ad7606_oversampling_avail, 1023 - .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 1024 - }, 1025 - [ID_AD7606C_18] = { 1026 - .channels = ad7606_channels_18bit, 1027 - .num_channels = 9, 1028 - .scale_setup_cb = ad7606c_18bit_chan_scale_setup, 1029 - .oversampling_avail = ad7606_oversampling_avail, 1030 - .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 1031 - }, 1032 - [ID_AD7616] = { 1033 - .channels = ad7616_channels, 1034 - .num_channels = 17, 1035 - .scale_setup_cb = ad7606_16bit_chan_scale_setup, 1036 - .oversampling_avail = ad7616_oversampling_avail, 1037 - .oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail), 1038 - .os_req_reset = true, 1039 - .init_delay_ms = 15, 1040 - }, 1041 - }; 1042 - 1043 539 static int ad7606_request_gpios(struct ad7606_state *st) 1044 540 { 1045 541 struct device *dev = st->dev; 1046 542 1047 - st->gpio_convst = devm_gpiod_get(dev, "adi,conversion-start", 1048 - GPIOD_OUT_LOW); 543 + st->gpio_convst = devm_gpiod_get_optional(dev, "adi,conversion-start", 544 + GPIOD_OUT_LOW); 545 + 1049 546 if (IS_ERR(st->gpio_convst)) 1050 547 return PTR_ERR(st->gpio_convst); 1051 548 ··· 966 705 { 967 706 struct iio_dev *indio_dev = dev_id; 968 707 struct ad7606_state *st = iio_priv(indio_dev); 708 + int ret; 969 709 970 710 if (iio_buffer_enabled(indio_dev)) { 971 - gpiod_set_value(st->gpio_convst, 0); 711 + if (st->gpio_convst) { 712 + gpiod_set_value(st->gpio_convst, 0); 713 + } else { 714 + ret = ad7606_pwm_set_low(st); 715 + if (ret < 0) { 716 + dev_err(st->dev, "PWM set low failed"); 717 + goto done; 718 + } 719 + } 972 720 iio_trigger_poll_nested(st->trig); 973 721 } else { 974 722 complete(&st->completion); 975 723 } 976 724 725 + done: 977 726 return IRQ_HANDLED; 978 727 }; 979 728 ··· 1038 767 ch = chan->address; 1039 768 1040 769 cs = &st->chan_scales[ch]; 1041 - *vals = cs->scale_avail_show; 1042 - *length = cs->num_scales * 2; 770 + *vals = (int *)cs->scale_avail; 771 + *length = cs->num_scales; 1043 772 *type = IIO_VAL_INT_PLUS_MICRO; 1044 773 1045 774 return IIO_AVAIL_LIST; ··· 1047 776 return -EINVAL; 1048 777 } 1049 778 779 + static int ad7606_backend_buffer_postenable(struct iio_dev *indio_dev) 780 + { 781 + struct ad7606_state *st = iio_priv(indio_dev); 782 + 783 + return ad7606_pwm_set_swing(st); 784 + } 785 + 786 + static int ad7606_backend_buffer_predisable(struct iio_dev *indio_dev) 787 + { 788 + struct ad7606_state *st = iio_priv(indio_dev); 789 + 790 + return ad7606_pwm_set_low(st); 791 + } 792 + 793 + static int ad7606_update_scan_mode(struct iio_dev *indio_dev, 794 + const unsigned long *scan_mask) 795 + { 796 + struct ad7606_state *st = iio_priv(indio_dev); 797 + 798 + /* 799 + * The update scan mode is only for iio backend compatible drivers. 800 + * If the specific update_scan_mode is not defined in the bus ops, 801 + * just do nothing and return 0. 802 + */ 803 + if (!st->bops->update_scan_mode) 804 + return 0; 805 + 806 + return st->bops->update_scan_mode(indio_dev, scan_mask); 807 + } 808 + 1050 809 static const struct iio_buffer_setup_ops ad7606_buffer_ops = { 1051 810 .postenable = &ad7606_buffer_postenable, 1052 811 .predisable = &ad7606_buffer_predisable, 1053 812 }; 1054 813 814 + static const struct iio_buffer_setup_ops ad7606_backend_buffer_ops = { 815 + .postenable = &ad7606_backend_buffer_postenable, 816 + .predisable = &ad7606_backend_buffer_predisable, 817 + }; 818 + 1055 819 static const struct iio_info ad7606_info_no_os_or_range = { 1056 820 .read_raw = &ad7606_read_raw, 1057 821 .validate_trigger = &ad7606_validate_trigger, 822 + .update_scan_mode = &ad7606_update_scan_mode, 1058 823 }; 1059 824 1060 825 static const struct iio_info ad7606_info_os_and_range = { ··· 1098 791 .write_raw = &ad7606_write_raw, 1099 792 .attrs = &ad7606_attribute_group_os_and_range, 1100 793 .validate_trigger = &ad7606_validate_trigger, 794 + .update_scan_mode = &ad7606_update_scan_mode, 1101 795 }; 1102 796 1103 797 static const struct iio_info ad7606_info_sw_mode = { ··· 1107 799 .read_avail = &ad7606_read_avail, 1108 800 .debugfs_reg_access = &ad7606_reg_access, 1109 801 .validate_trigger = &ad7606_validate_trigger, 802 + .update_scan_mode = &ad7606_update_scan_mode, 1110 803 }; 1111 804 1112 805 static const struct iio_info ad7606_info_os = { ··· 1115 806 .write_raw = &ad7606_write_raw, 1116 807 .attrs = &ad7606_attribute_group_os, 1117 808 .validate_trigger = &ad7606_validate_trigger, 809 + .update_scan_mode = &ad7606_update_scan_mode, 1118 810 }; 1119 811 1120 812 static const struct iio_info ad7606_info_range = { ··· 1123 813 .write_raw = &ad7606_write_raw, 1124 814 .attrs = &ad7606_attribute_group_range, 1125 815 .validate_trigger = &ad7606_validate_trigger, 816 + .update_scan_mode = &ad7606_update_scan_mode, 1126 817 }; 1127 818 1128 819 static const struct iio_trigger_ops ad7606_trigger_ops = { 1129 820 .validate_device = iio_trigger_validate_own_device, 1130 821 }; 1131 822 1132 - static int ad7606_sw_mode_setup(struct iio_dev *indio_dev, unsigned int id) 823 + static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) 1133 824 { 1134 825 struct ad7606_state *st = iio_priv(indio_dev); 1135 826 ··· 1162 851 indio_dev->channels = chans; 1163 852 1164 853 for (ch = 0; ch < num_channels; ch++) { 1165 - struct ad7606_chan_scale *cs; 1166 - int i; 1167 - 1168 854 ret = st->chip_info->scale_setup_cb(st, &chans[ch + 1], ch); 1169 855 if (ret) 1170 856 return ret; 1171 - 1172 - cs = &st->chan_scales[ch]; 1173 - 1174 - if (cs->num_scales * 2 > AD760X_MAX_SCALE_SHOW) 1175 - return dev_err_probe(st->dev, -ERANGE, 1176 - "Driver error: scale range too big"); 1177 - 1178 - /* Generate a scale_avail list for showing to userspace */ 1179 - for (i = 0; i < cs->num_scales; i++) { 1180 - cs->scale_avail_show[i * 2] = 0; 1181 - cs->scale_avail_show[i * 2 + 1] = cs->scale_avail[i]; 1182 - } 1183 857 } 1184 858 1185 859 return 0; 1186 860 } 1187 861 862 + static void ad7606_pwm_disable(void *data) 863 + { 864 + pwm_disable(data); 865 + } 866 + 1188 867 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, 1189 - const char *name, unsigned int id, 868 + const struct ad7606_chip_info *chip_info, 1190 869 const struct ad7606_bus_ops *bops) 1191 870 { 1192 871 struct ad7606_state *st; ··· 1201 900 return dev_err_probe(dev, ret, 1202 901 "Failed to enable specified AVcc supply\n"); 1203 902 1204 - st->chip_info = &ad7606_chip_info_tbl[id]; 903 + st->chip_info = chip_info; 1205 904 1206 905 if (st->chip_info->oversampling_num) { 1207 906 st->oversampling_avail = st->chip_info->oversampling_avail; ··· 1224 923 indio_dev->info = &ad7606_info_no_os_or_range; 1225 924 } 1226 925 indio_dev->modes = INDIO_DIRECT_MODE; 1227 - indio_dev->name = name; 926 + indio_dev->name = chip_info->name; 1228 927 indio_dev->channels = st->chip_info->channels; 1229 928 indio_dev->num_channels = st->chip_info->num_channels; 1230 - 1231 - init_completion(&st->completion); 1232 929 1233 930 ret = ad7606_reset(st); 1234 931 if (ret) ··· 1241 942 st->write_scale = ad7606_write_scale_hw; 1242 943 st->write_os = ad7606_write_os_hw; 1243 944 1244 - ret = ad7606_sw_mode_setup(indio_dev, id); 945 + ret = ad7606_sw_mode_setup(indio_dev); 1245 946 if (ret) 1246 947 return ret; 1247 948 ··· 1249 950 if (ret) 1250 951 return ret; 1251 952 1252 - st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", 1253 - indio_dev->name, 1254 - iio_device_id(indio_dev)); 1255 - if (!st->trig) 1256 - return -ENOMEM; 953 + /* If convst pin is not defined, setup PWM. */ 954 + if (!st->gpio_convst) { 955 + st->cnvst_pwm = devm_pwm_get(dev, NULL); 956 + if (IS_ERR(st->cnvst_pwm)) 957 + return PTR_ERR(st->cnvst_pwm); 1257 958 1258 - st->trig->ops = &ad7606_trigger_ops; 1259 - iio_trigger_set_drvdata(st->trig, indio_dev); 1260 - ret = devm_iio_trigger_register(dev, st->trig); 1261 - if (ret) 1262 - return ret; 959 + /* The PWM is initialized at 1MHz to have a fast enough GPIO emulation. */ 960 + ret = ad7606_set_sampling_freq(st, 1 * MEGA); 961 + if (ret) 962 + return ret; 1263 963 1264 - indio_dev->trig = iio_trigger_get(st->trig); 964 + ret = ad7606_pwm_set_low(st); 965 + if (ret) 966 + return ret; 1265 967 1266 - ret = devm_request_threaded_irq(dev, irq, 1267 - NULL, 1268 - &ad7606_interrupt, 1269 - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 1270 - name, indio_dev); 1271 - if (ret) 1272 - return ret; 968 + /* 969 + * PWM is not disabled when sampling stops, but instead its duty cycle is set 970 + * to 0% to be sure we have a "low" state. After we unload the driver, let's 971 + * disable the PWM. 972 + */ 973 + ret = devm_add_action_or_reset(dev, ad7606_pwm_disable, 974 + st->cnvst_pwm); 975 + if (ret) 976 + return ret; 977 + } 1273 978 1274 - ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 1275 - &iio_pollfunc_store_time, 1276 - &ad7606_trigger_handler, 1277 - &ad7606_buffer_ops); 1278 - if (ret) 1279 - return ret; 979 + if (st->bops->iio_backend_config) { 980 + /* 981 + * If there is a backend, the PWM should not overpass the maximum sampling 982 + * frequency the chip supports. 983 + */ 984 + ret = ad7606_set_sampling_freq(st, 985 + chip_info->max_samplerate ? : 2 * KILO); 986 + if (ret) 987 + return ret; 988 + 989 + ret = st->bops->iio_backend_config(dev, indio_dev); 990 + if (ret) 991 + return ret; 992 + 993 + indio_dev->setup_ops = &ad7606_backend_buffer_ops; 994 + } else { 995 + 996 + /* Reserve the PWM use only for backend (force gpio_convst definition) */ 997 + if (!st->gpio_convst) 998 + return dev_err_probe(dev, -EINVAL, 999 + "No backend, connect convst to a GPIO"); 1000 + 1001 + init_completion(&st->completion); 1002 + st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", 1003 + indio_dev->name, 1004 + iio_device_id(indio_dev)); 1005 + if (!st->trig) 1006 + return -ENOMEM; 1007 + 1008 + st->trig->ops = &ad7606_trigger_ops; 1009 + iio_trigger_set_drvdata(st->trig, indio_dev); 1010 + ret = devm_iio_trigger_register(dev, st->trig); 1011 + if (ret) 1012 + return ret; 1013 + 1014 + indio_dev->trig = iio_trigger_get(st->trig); 1015 + 1016 + ret = devm_request_threaded_irq(dev, irq, NULL, &ad7606_interrupt, 1017 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 1018 + chip_info->name, indio_dev); 1019 + if (ret) 1020 + return ret; 1021 + 1022 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 1023 + &iio_pollfunc_store_time, 1024 + &ad7606_trigger_handler, 1025 + &ad7606_buffer_ops); 1026 + if (ret) 1027 + return ret; 1028 + } 1280 1029 1281 1030 return devm_iio_device_register(dev, indio_dev); 1282 1031 }
+44 -16
drivers/iio/adc/ad7606.h
··· 61 61 62 62 #define AD7616_CHANNEL(num) AD7606_SW_CHANNEL(num, 16) 63 63 64 + #define AD7606_BI_CHANNEL(num) \ 65 + AD760X_CHANNEL(num, 0, \ 66 + BIT(IIO_CHAN_INFO_SCALE), \ 67 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ 68 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 16) 69 + 64 70 struct ad7606_state; 65 71 66 72 typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st, ··· 75 69 /** 76 70 * struct ad7606_chip_info - chip specific information 77 71 * @channels: channel specification 72 + * @max_samplerate: maximum supported samplerate 73 + * @name device name 78 74 * @num_channels: number of channels 75 + * @num_adc_channels the number of channels the ADC actually inputs. 79 76 * @scale_setup_cb: callback to setup the scales for each channel 80 77 * @oversampling_avail pointer to the array which stores the available 81 78 * oversampling ratios. ··· 89 80 */ 90 81 struct ad7606_chip_info { 91 82 const struct iio_chan_spec *channels; 83 + unsigned int max_samplerate; 84 + const char *name; 85 + unsigned int num_adc_channels; 92 86 unsigned int num_channels; 93 87 ad7606_scale_setup_cb_t scale_setup_cb; 94 88 const unsigned int *oversampling_avail; ··· 103 91 /** 104 92 * struct ad7606_chan_scale - channel scale configuration 105 93 * @scale_avail pointer to the array which stores the available scales 106 - * @scale_avail_show a duplicate of 'scale_avail' which is readily formatted 107 - * such that it can be read via the 'read_avail' hook 108 94 * @num_scales number of elements stored in the scale_avail array 109 95 * @range voltage range selection, selects which scale to apply 110 96 * @reg_offset offset for the register value, to be applied when ··· 110 100 */ 111 101 struct ad7606_chan_scale { 112 102 #define AD760X_MAX_SCALES 16 113 - #define AD760X_MAX_SCALE_SHOW (AD760X_MAX_SCALES * 2) 114 - const unsigned int *scale_avail; 115 - int scale_avail_show[AD760X_MAX_SCALE_SHOW]; 103 + const unsigned int (*scale_avail)[2]; 116 104 unsigned int num_scales; 117 105 unsigned int range; 118 106 unsigned int reg_offset; ··· 123 115 * @bops bus operations (SPI or parallel) 124 116 * @chan_scales scale configuration for channels 125 117 * @oversampling oversampling selection 118 + * @cnvst_pwm pointer to the PWM device connected to the cnvst pin 126 119 * @base_address address from where to read data in parallel operation 127 120 * @sw_mode_en software mode enabled 128 121 * @oversampling_avail pointer to the array which stores the available ··· 151 142 const struct ad7606_bus_ops *bops; 152 143 struct ad7606_chan_scale chan_scales[AD760X_MAX_CHANNELS]; 153 144 unsigned int oversampling; 145 + struct pwm_device *cnvst_pwm; 154 146 void __iomem *base_address; 155 147 bool sw_mode_en; 156 148 const unsigned int *oversampling_avail; 157 149 unsigned int num_os_ratios; 150 + struct iio_backend *back; 158 151 int (*write_scale)(struct iio_dev *indio_dev, int ch, int val); 159 152 int (*write_os)(struct iio_dev *indio_dev, int val); 160 153 ··· 185 174 186 175 /** 187 176 * struct ad7606_bus_ops - driver bus operations 177 + * @iio_backend_config function pointer for configuring the iio_backend for 178 + * the compatibles that use it 188 179 * @read_block function pointer for reading blocks of data 189 180 * @sw_mode_config: pointer to a function which configured the device 190 181 * for software mode 191 182 * @reg_read function pointer for reading spi register 192 183 * @reg_write function pointer for writing spi register 193 184 * @write_mask function pointer for write spi register with mask 185 + * @update_scan_mode function pointer for handling the calls to iio_info's update_scan 186 + * mode when enabling/disabling channels. 194 187 * @rd_wr_cmd pointer to the function which calculates the spi address 195 188 */ 196 189 struct ad7606_bus_ops { 197 190 /* more methods added in future? */ 191 + int (*iio_backend_config)(struct device *dev, struct iio_dev *indio_dev); 198 192 int (*read_block)(struct device *dev, int num, void *data); 199 193 int (*sw_mode_config)(struct iio_dev *indio_dev); 200 194 int (*reg_read)(struct ad7606_state *st, unsigned int addr); ··· 210 194 unsigned int addr, 211 195 unsigned long mask, 212 196 unsigned int val); 197 + int (*update_scan_mode)(struct iio_dev *indio_dev, const unsigned long *scan_mask); 213 198 u16 (*rd_wr_cmd)(int addr, char isWriteOp); 214 199 }; 215 200 201 + /** 202 + * struct ad7606_bus_info - agregate ad7606_chip_info and ad7606_bus_ops 203 + * @chip_info entry in the table of chips that describes this device 204 + * @bops bus operations (SPI or parallel) 205 + */ 206 + struct ad7606_bus_info { 207 + const struct ad7606_chip_info *chip_info; 208 + const struct ad7606_bus_ops *bops; 209 + }; 210 + 216 211 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, 217 - const char *name, unsigned int id, 212 + const struct ad7606_chip_info *info, 218 213 const struct ad7606_bus_ops *bops); 219 214 220 215 int ad7606_reset(struct ad7606_state *st); 221 216 222 - enum ad7606_supported_device_ids { 223 - ID_AD7605_4, 224 - ID_AD7606_8, 225 - ID_AD7606_6, 226 - ID_AD7606_4, 227 - ID_AD7606B, 228 - ID_AD7606C_16, 229 - ID_AD7606C_18, 230 - ID_AD7616, 231 - }; 217 + extern const struct ad7606_chip_info ad7605_4_info; 218 + extern const struct ad7606_chip_info ad7606_8_info; 219 + extern const struct ad7606_chip_info ad7606_6_info; 220 + extern const struct ad7606_chip_info ad7606_4_info; 221 + extern const struct ad7606_chip_info ad7606b_info; 222 + extern const struct ad7606_chip_info ad7606c_16_info; 223 + extern const struct ad7606_chip_info ad7606c_18_info; 224 + extern const struct ad7606_chip_info ad7607_info; 225 + extern const struct ad7606_chip_info ad7608_info; 226 + extern const struct ad7606_chip_info ad7609_info; 227 + extern const struct ad7606_chip_info ad7616_info; 232 228 233 229 #ifdef CONFIG_PM_SLEEP 234 230 extern const struct dev_pm_ops ad7606_pm_ops;
+115 -12
drivers/iio/adc/ad7606_par.c
··· 2 2 /* 3 3 * AD7606 Parallel Interface ADC driver 4 4 * 5 - * Copyright 2011 Analog Devices Inc. 5 + * Copyright 2011 - 2024 Analog Devices Inc. 6 + * Copyright 2024 BayLibre SAS. 6 7 */ 7 8 8 9 #include <linux/err.h> ··· 12 11 #include <linux/mod_devicetable.h> 13 12 #include <linux/module.h> 14 13 #include <linux/platform_device.h> 14 + #include <linux/property.h> 15 15 #include <linux/types.h> 16 16 17 + #include <linux/iio/backend.h> 17 18 #include <linux/iio/iio.h> 19 + 18 20 #include "ad7606.h" 21 + 22 + static const struct iio_chan_spec ad7606b_bi_channels[] = { 23 + AD7606_BI_CHANNEL(0), 24 + AD7606_BI_CHANNEL(1), 25 + AD7606_BI_CHANNEL(2), 26 + AD7606_BI_CHANNEL(3), 27 + AD7606_BI_CHANNEL(4), 28 + AD7606_BI_CHANNEL(5), 29 + AD7606_BI_CHANNEL(6), 30 + AD7606_BI_CHANNEL(7), 31 + }; 32 + 33 + static int ad7606_bi_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask) 34 + { 35 + struct ad7606_state *st = iio_priv(indio_dev); 36 + unsigned int c, ret; 37 + 38 + for (c = 0; c < indio_dev->num_channels; c++) { 39 + if (test_bit(c, scan_mask)) 40 + ret = iio_backend_chan_enable(st->back, c); 41 + else 42 + ret = iio_backend_chan_disable(st->back, c); 43 + if (ret) 44 + return ret; 45 + } 46 + 47 + return 0; 48 + } 49 + 50 + static int ad7606_bi_setup_iio_backend(struct device *dev, struct iio_dev *indio_dev) 51 + { 52 + struct ad7606_state *st = iio_priv(indio_dev); 53 + unsigned int ret, c; 54 + struct iio_backend_data_fmt data = { 55 + .sign_extend = true, 56 + .enable = true, 57 + }; 58 + 59 + st->back = devm_iio_backend_get(dev, NULL); 60 + if (IS_ERR(st->back)) 61 + return PTR_ERR(st->back); 62 + 63 + /* If the device is iio_backend powered the PWM is mandatory */ 64 + if (!st->cnvst_pwm) 65 + return dev_err_probe(st->dev, -EINVAL, 66 + "A PWM is mandatory when using backend.\n"); 67 + 68 + ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev); 69 + if (ret) 70 + return ret; 71 + 72 + ret = devm_iio_backend_enable(dev, st->back); 73 + if (ret) 74 + return ret; 75 + 76 + for (c = 0; c < indio_dev->num_channels; c++) { 77 + ret = iio_backend_data_format_set(st->back, c, &data); 78 + if (ret) 79 + return ret; 80 + } 81 + 82 + indio_dev->channels = ad7606b_bi_channels; 83 + indio_dev->num_channels = 8; 84 + 85 + return 0; 86 + } 87 + 88 + static const struct ad7606_bus_ops ad7606_bi_bops = { 89 + .iio_backend_config = ad7606_bi_setup_iio_backend, 90 + .update_scan_mode = ad7606_bi_update_scan_mode, 91 + }; 19 92 20 93 static int ad7606_par16_read_block(struct device *dev, 21 94 int count, void *buf) ··· 164 89 165 90 static int ad7606_par_probe(struct platform_device *pdev) 166 91 { 167 - const struct platform_device_id *id = platform_get_device_id(pdev); 92 + const struct ad7606_chip_info *chip_info; 93 + const struct platform_device_id *id; 168 94 struct resource *res; 169 95 void __iomem *addr; 170 96 resource_size_t remap_size; 171 97 int irq; 98 + 99 + /* 100 + * If a firmware node is available (ACPI or DT), platform_device_id is null 101 + * and we must use get_match_data. 102 + */ 103 + if (dev_fwnode(&pdev->dev)) { 104 + chip_info = device_get_match_data(&pdev->dev); 105 + if (device_property_present(&pdev->dev, "io-backends")) 106 + /* 107 + * If a backend is available ,call the core probe with backend 108 + * bops, otherwise use the former bops. 109 + */ 110 + return ad7606_probe(&pdev->dev, 0, NULL, 111 + chip_info, 112 + &ad7606_bi_bops); 113 + } else { 114 + id = platform_get_device_id(pdev); 115 + chip_info = (const struct ad7606_chip_info *)id->driver_data; 116 + } 172 117 173 118 irq = platform_get_irq(pdev, 0); 174 119 if (irq < 0) ··· 200 105 201 106 remap_size = resource_size(res); 202 107 203 - return ad7606_probe(&pdev->dev, irq, addr, 204 - id->name, id->driver_data, 108 + return ad7606_probe(&pdev->dev, irq, addr, chip_info, 205 109 remap_size > 1 ? &ad7606_par16_bops : 206 110 &ad7606_par8_bops); 207 111 } 208 112 209 113 static const struct platform_device_id ad7606_driver_ids[] = { 210 - { .name = "ad7605-4", .driver_data = ID_AD7605_4, }, 211 - { .name = "ad7606-4", .driver_data = ID_AD7606_4, }, 212 - { .name = "ad7606-6", .driver_data = ID_AD7606_6, }, 213 - { .name = "ad7606-8", .driver_data = ID_AD7606_8, }, 114 + { .name = "ad7605-4", .driver_data = (kernel_ulong_t)&ad7605_4_info, }, 115 + { .name = "ad7606-4", .driver_data = (kernel_ulong_t)&ad7606_4_info, }, 116 + { .name = "ad7606-6", .driver_data = (kernel_ulong_t)&ad7606_6_info, }, 117 + { .name = "ad7606-8", .driver_data = (kernel_ulong_t)&ad7606_8_info, }, 118 + { .name = "ad7606b", .driver_data = (kernel_ulong_t)&ad7606b_info, }, 119 + { .name = "ad7607", .driver_data = (kernel_ulong_t)&ad7607_info, }, 120 + { .name = "ad7608", .driver_data = (kernel_ulong_t)&ad7608_info, }, 121 + { .name = "ad7609", .driver_data = (kernel_ulong_t)&ad7609_info, }, 214 122 { } 215 123 }; 216 124 MODULE_DEVICE_TABLE(platform, ad7606_driver_ids); 217 125 218 126 static const struct of_device_id ad7606_of_match[] = { 219 - { .compatible = "adi,ad7605-4" }, 220 - { .compatible = "adi,ad7606-4" }, 221 - { .compatible = "adi,ad7606-6" }, 222 - { .compatible = "adi,ad7606-8" }, 127 + { .compatible = "adi,ad7605-4", .data = &ad7605_4_info }, 128 + { .compatible = "adi,ad7606-4", .data = &ad7606_4_info }, 129 + { .compatible = "adi,ad7606-6", .data = &ad7606_6_info }, 130 + { .compatible = "adi,ad7606-8", .data = &ad7606_8_info }, 131 + { .compatible = "adi,ad7606b", .data = &ad7606b_info }, 132 + { .compatible = "adi,ad7607", .data = &ad7607_info }, 133 + { .compatible = "adi,ad7608", .data = &ad7608_info }, 134 + { .compatible = "adi,ad7609", .data = &ad7609_info }, 223 135 { } 224 136 }; 225 137 MODULE_DEVICE_TABLE(of, ad7606_of_match); ··· 246 144 MODULE_DESCRIPTION("Analog Devices AD7606 ADC"); 247 145 MODULE_LICENSE("GPL v2"); 248 146 MODULE_IMPORT_NS(IIO_AD7606); 147 + MODULE_IMPORT_NS(IIO_BACKEND);
+101 -37
drivers/iio/adc/ad7606_spi.c
··· 132 132 return 0; 133 133 } 134 134 135 + static int ad7606_spi_read_block14to16(struct device *dev, 136 + int count, void *buf) 137 + { 138 + struct spi_device *spi = to_spi_device(dev); 139 + struct spi_transfer xfer = { 140 + .bits_per_word = 14, 141 + .len = count * sizeof(u16), 142 + .rx_buf = buf, 143 + }; 144 + 145 + return spi_sync_transfer(spi, &xfer, 1); 146 + } 147 + 135 148 static int ad7606_spi_read_block18to32(struct device *dev, 136 149 int count, void *buf) 137 150 { ··· 338 325 .read_block = ad7606_spi_read_block, 339 326 }; 340 327 328 + static const struct ad7606_bus_ops ad7607_spi_bops = { 329 + .read_block = ad7606_spi_read_block14to16, 330 + }; 331 + 332 + static const struct ad7606_bus_ops ad7608_spi_bops = { 333 + .read_block = ad7606_spi_read_block18to32, 334 + }; 335 + 341 336 static const struct ad7606_bus_ops ad7616_spi_bops = { 342 337 .read_block = ad7606_spi_read_block, 343 338 .reg_read = ad7606_spi_reg_read, ··· 355 334 .sw_mode_config = ad7616_sw_mode_config, 356 335 }; 357 336 358 - static const struct ad7606_bus_ops ad7606B_spi_bops = { 337 + static const struct ad7606_bus_ops ad7606b_spi_bops = { 359 338 .read_block = ad7606_spi_read_block, 360 339 .reg_read = ad7606_spi_reg_read, 361 340 .reg_write = ad7606_spi_reg_write, ··· 373 352 .sw_mode_config = ad7606c_18_sw_mode_config, 374 353 }; 375 354 355 + static const struct ad7606_bus_info ad7605_4_bus_info = { 356 + .chip_info = &ad7605_4_info, 357 + .bops = &ad7606_spi_bops, 358 + }; 359 + 360 + static const struct ad7606_bus_info ad7606_8_bus_info = { 361 + .chip_info = &ad7606_8_info, 362 + .bops = &ad7606_spi_bops, 363 + }; 364 + 365 + static const struct ad7606_bus_info ad7606_6_bus_info = { 366 + .chip_info = &ad7606_6_info, 367 + .bops = &ad7606_spi_bops, 368 + }; 369 + 370 + static const struct ad7606_bus_info ad7606_4_bus_info = { 371 + .chip_info = &ad7606_4_info, 372 + .bops = &ad7606_spi_bops, 373 + }; 374 + 375 + static const struct ad7606_bus_info ad7606b_bus_info = { 376 + .chip_info = &ad7606b_info, 377 + .bops = &ad7606b_spi_bops, 378 + }; 379 + 380 + static const struct ad7606_bus_info ad7606c_16_bus_info = { 381 + .chip_info = &ad7606c_16_info, 382 + .bops = &ad7606b_spi_bops, 383 + }; 384 + 385 + static const struct ad7606_bus_info ad7606c_18_bus_info = { 386 + .chip_info = &ad7606c_18_info, 387 + .bops = &ad7606c_18_spi_bops, 388 + }; 389 + 390 + static const struct ad7606_bus_info ad7607_bus_info = { 391 + .chip_info = &ad7607_info, 392 + .bops = &ad7607_spi_bops, 393 + }; 394 + 395 + static const struct ad7606_bus_info ad7608_bus_info = { 396 + .chip_info = &ad7608_info, 397 + .bops = &ad7608_spi_bops, 398 + }; 399 + 400 + static const struct ad7606_bus_info ad7609_bus_info = { 401 + .chip_info = &ad7609_info, 402 + .bops = &ad7608_spi_bops, 403 + }; 404 + 405 + static const struct ad7606_bus_info ad7616_bus_info = { 406 + .chip_info = &ad7616_info, 407 + .bops = &ad7616_spi_bops, 408 + }; 409 + 376 410 static int ad7606_spi_probe(struct spi_device *spi) 377 411 { 378 - const struct spi_device_id *id = spi_get_device_id(spi); 379 - const struct ad7606_bus_ops *bops; 380 - 381 - switch (id->driver_data) { 382 - case ID_AD7616: 383 - bops = &ad7616_spi_bops; 384 - break; 385 - case ID_AD7606B: 386 - case ID_AD7606C_16: 387 - bops = &ad7606B_spi_bops; 388 - break; 389 - case ID_AD7606C_18: 390 - bops = &ad7606c_18_spi_bops; 391 - break; 392 - default: 393 - bops = &ad7606_spi_bops; 394 - break; 395 - } 412 + const struct ad7606_bus_info *bus_info = spi_get_device_match_data(spi); 396 413 397 414 return ad7606_probe(&spi->dev, spi->irq, NULL, 398 - id->name, id->driver_data, 399 - bops); 415 + bus_info->chip_info, bus_info->bops); 400 416 } 401 417 402 418 static const struct spi_device_id ad7606_id_table[] = { 403 - { "ad7605-4", ID_AD7605_4 }, 404 - { "ad7606-4", ID_AD7606_4 }, 405 - { "ad7606-6", ID_AD7606_6 }, 406 - { "ad7606-8", ID_AD7606_8 }, 407 - { "ad7606b", ID_AD7606B }, 408 - { "ad7606c-16", ID_AD7606C_16 }, 409 - { "ad7606c-18", ID_AD7606C_18 }, 410 - { "ad7616", ID_AD7616 }, 419 + { "ad7605-4", (kernel_ulong_t)&ad7605_4_bus_info }, 420 + { "ad7606-4", (kernel_ulong_t)&ad7606_4_bus_info }, 421 + { "ad7606-6", (kernel_ulong_t)&ad7606_6_bus_info }, 422 + { "ad7606-8", (kernel_ulong_t)&ad7606_8_bus_info }, 423 + { "ad7606b", (kernel_ulong_t)&ad7606b_bus_info }, 424 + { "ad7606c-16", (kernel_ulong_t)&ad7606c_16_bus_info }, 425 + { "ad7606c-18", (kernel_ulong_t)&ad7606c_18_bus_info }, 426 + { "ad7607", (kernel_ulong_t)&ad7607_bus_info }, 427 + { "ad7608", (kernel_ulong_t)&ad7608_bus_info }, 428 + { "ad7609", (kernel_ulong_t)&ad7609_bus_info }, 429 + { "ad7616", (kernel_ulong_t)&ad7616_bus_info }, 411 430 { } 412 431 }; 413 432 MODULE_DEVICE_TABLE(spi, ad7606_id_table); 414 433 415 434 static const struct of_device_id ad7606_of_match[] = { 416 - { .compatible = "adi,ad7605-4" }, 417 - { .compatible = "adi,ad7606-4" }, 418 - { .compatible = "adi,ad7606-6" }, 419 - { .compatible = "adi,ad7606-8" }, 420 - { .compatible = "adi,ad7606b" }, 421 - { .compatible = "adi,ad7606c-16" }, 422 - { .compatible = "adi,ad7606c-18" }, 423 - { .compatible = "adi,ad7616" }, 435 + { .compatible = "adi,ad7605-4", .data = &ad7605_4_bus_info }, 436 + { .compatible = "adi,ad7606-4", .data = &ad7606_4_bus_info }, 437 + { .compatible = "adi,ad7606-6", .data = &ad7606_6_bus_info }, 438 + { .compatible = "adi,ad7606-8", .data = &ad7606_8_bus_info }, 439 + { .compatible = "adi,ad7606b", .data = &ad7606b_bus_info }, 440 + { .compatible = "adi,ad7606c-16", .data = &ad7606c_16_bus_info }, 441 + { .compatible = "adi,ad7606c-18", .data = &ad7606c_18_bus_info }, 442 + { .compatible = "adi,ad7607", .data = &ad7607_bus_info }, 443 + { .compatible = "adi,ad7608", .data = &ad7608_bus_info }, 444 + { .compatible = "adi,ad7609", .data = &ad7609_bus_info }, 445 + { .compatible = "adi,ad7616", .data = &ad7616_bus_info }, 424 446 { } 425 447 }; 426 448 MODULE_DEVICE_TABLE(of, ad7606_of_match);
+914
drivers/iio/adc/ad7779.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * AD7770, AD7771, AD7779 ADC 4 + * 5 + * Copyright 2023-2024 Analog Devices Inc. 6 + */ 7 + 8 + #include <linux/bitfield.h> 9 + #include <linux/bitmap.h> 10 + #include <linux/clk.h> 11 + #include <linux/crc8.h> 12 + #include <linux/delay.h> 13 + #include <linux/err.h> 14 + #include <linux/gpio/consumer.h> 15 + #include <linux/interrupt.h> 16 + #include <linux/irq.h> 17 + #include <linux/math.h> 18 + #include <linux/module.h> 19 + #include <linux/mod_devicetable.h> 20 + #include <linux/regulator/consumer.h> 21 + #include <linux/spi/spi.h> 22 + #include <linux/string.h> 23 + #include <linux/types.h> 24 + #include <linux/unaligned.h> 25 + #include <linux/units.h> 26 + 27 + #include <linux/iio/iio.h> 28 + #include <linux/iio/buffer.h> 29 + #include <linux/iio/sysfs.h> 30 + #include <linux/iio/trigger.h> 31 + #include <linux/iio/triggered_buffer.h> 32 + #include <linux/iio/trigger_consumer.h> 33 + 34 + #define AD7779_SPI_READ_CMD BIT(7) 35 + 36 + #define AD7779_DISABLE_SD BIT(7) 37 + 38 + #define AD7779_REG_CH_DISABLE 0x08 39 + #define AD7779_REG_CH_SYNC_OFFSET(ch) (0x09 + (ch)) 40 + #define AD7779_REG_CH_CONFIG(ch) (0x00 + (ch)) 41 + #define AD7779_REG_GENERAL_USER_CONFIG_1 0x11 42 + #define AD7779_REG_GENERAL_USER_CONFIG_2 0x12 43 + #define AD7779_REG_GENERAL_USER_CONFIG_3 0x13 44 + #define AD7779_REG_DOUT_FORMAT 0x14 45 + #define AD7779_REG_ADC_MUX_CONFIG 0x15 46 + #define AD7779_REG_GPIO_CONFIG 0x17 47 + #define AD7779_REG_BUFFER_CONFIG_1 0x19 48 + #define AD7779_REG_GLOBAL_MUX_CONFIG 0x16 49 + #define AD7779_REG_BUFFER_CONFIG_2 0x1A 50 + #define AD7779_REG_GPIO_DATA 0x18 51 + #define AD7779_REG_CH_OFFSET_UPPER_BYTE(ch) (0x1C + (ch) * 6) 52 + #define AD7779_REG_CH_OFFSET_LOWER_BYTE(ch) (0x1E + (ch) * 6) 53 + #define AD7779_REG_CH_GAIN_UPPER_BYTE(ch) (0x1F + (ch) * 6) 54 + #define AD7779_REG_CH_OFFSET_MID_BYTE(ch) (0x1D + (ch) * 6) 55 + #define AD7779_REG_CH_GAIN_MID_BYTE(ch) (0x20 + (ch) * 6) 56 + #define AD7779_REG_CH_ERR_REG(ch) (0x4C + (ch)) 57 + #define AD7779_REG_CH0_1_SAT_ERR 0x54 58 + #define AD7779_REG_CH_GAIN_LOWER_BYTE(ch) (0x21 + (ch) * 6) 59 + #define AD7779_REG_CH2_3_SAT_ERR 0x55 60 + #define AD7779_REG_CH4_5_SAT_ERR 0x56 61 + #define AD7779_REG_CH6_7_SAT_ERR 0x57 62 + #define AD7779_REG_CHX_ERR_REG_EN 0x58 63 + #define AD7779_REG_GEN_ERR_REG_1 0x59 64 + #define AD7779_REG_GEN_ERR_REG_1_EN 0x5A 65 + #define AD7779_REG_GEN_ERR_REG_2 0x5B 66 + #define AD7779_REG_GEN_ERR_REG_2_EN 0x5C 67 + #define AD7779_REG_STATUS_REG_1 0x5D 68 + #define AD7779_REG_STATUS_REG_2 0x5E 69 + #define AD7779_REG_STATUS_REG_3 0x5F 70 + #define AD7779_REG_SRC_N_MSB 0x60 71 + #define AD7779_REG_SRC_N_LSB 0x61 72 + #define AD7779_REG_SRC_IF_MSB 0x62 73 + #define AD7779_REG_SRC_IF_LSB 0x63 74 + #define AD7779_REG_SRC_UPDATE 0x64 75 + 76 + #define AD7779_FILTER_MSK BIT(6) 77 + #define AD7779_MOD_POWERMODE_MSK BIT(6) 78 + #define AD7779_MOD_PDB_REFOUT_MSK BIT(4) 79 + #define AD7779_MOD_SPI_EN_MSK BIT(4) 80 + #define AD7779_USRMOD_INIT_MSK GENMASK(6, 4) 81 + 82 + /* AD7779_REG_DOUT_FORMAT */ 83 + #define AD7779_DOUT_FORMAT_MSK GENMASK(7, 6) 84 + #define AD7779_DOUT_HEADER_FORMAT BIT(5) 85 + #define AD7779_DCLK_CLK_DIV_MSK GENMASK(3, 1) 86 + 87 + #define AD7779_REFMUX_CTRL_MSK GENMASK(7, 6) 88 + #define AD7779_SPI_CRC_EN_MSK BIT(0) 89 + 90 + #define AD7779_MAXCLK_LOWPOWER (4096 * HZ_PER_KHZ) 91 + #define AD7779_NUM_CHANNELS 8 92 + #define AD7779_RESET_BUF_SIZE 8 93 + #define AD7779_CHAN_DATA_SIZE 4 94 + 95 + #define AD7779_LOWPOWER_DIV 512 96 + #define AD7779_HIGHPOWER_DIV 2048 97 + 98 + #define AD7779_SINC3_MAXFREQ (16 * HZ_PER_KHZ) 99 + #define AD7779_SINC5_MAXFREQ (128 * HZ_PER_KHZ) 100 + 101 + #define AD7779_DEFAULT_SAMPLING_FREQ (8 * HZ_PER_KHZ) 102 + #define AD7779_DEFAULT_SAMPLING_2LINE (4 * HZ_PER_KHZ) 103 + #define AD7779_DEFAULT_SAMPLING_1LINE (2 * HZ_PER_KHZ) 104 + 105 + #define AD7779_SPIMODE_MAX_SAMP_FREQ (16 * HZ_PER_KHZ) 106 + 107 + #define GAIN_REL 0x555555 108 + #define AD7779_FREQ_MSB_MSK GENMASK(15, 8) 109 + #define AD7779_FREQ_LSB_MSK GENMASK(7, 0) 110 + #define AD7779_UPPER GENMASK(23, 16) 111 + #define AD7779_MID GENMASK(15, 8) 112 + #define AD7779_LOWER GENMASK(7, 0) 113 + 114 + #define AD7779_REG_MSK GENMASK(6, 0) 115 + 116 + #define AD7779_CRC8_POLY 0x07 117 + DECLARE_CRC8_TABLE(ad7779_crc8_table); 118 + 119 + enum ad7779_filter { 120 + AD7779_SINC3, 121 + AD7779_SINC5, 122 + }; 123 + 124 + enum ad7779_variant { 125 + ad7770, 126 + ad7771, 127 + ad7779, 128 + }; 129 + 130 + enum ad7779_power_mode { 131 + AD7779_LOW_POWER, 132 + AD7779_HIGH_POWER, 133 + }; 134 + 135 + struct ad7779_chip_info { 136 + const char *name; 137 + struct iio_chan_spec const *channels; 138 + }; 139 + 140 + struct ad7779_state { 141 + struct spi_device *spi; 142 + const struct ad7779_chip_info *chip_info; 143 + struct clk *mclk; 144 + struct iio_trigger *trig; 145 + struct completion completion; 146 + unsigned int sampling_freq; 147 + enum ad7779_filter filter_enabled; 148 + /* 149 + * DMA (thus cache coherency maintenance) requires the 150 + * transfer buffers to live in their own cache lines. 151 + */ 152 + struct { 153 + u32 chans[8]; 154 + aligned_s64 timestamp; 155 + } data __aligned(IIO_DMA_MINALIGN); 156 + u32 spidata_tx[8]; 157 + u8 reg_rx_buf[3]; 158 + u8 reg_tx_buf[3]; 159 + u8 reset_buf[8]; 160 + }; 161 + 162 + static const char * const ad7779_filter_type[] = { 163 + [AD7779_SINC3] = "sinc3", 164 + [AD7779_SINC5] = "sinc5", 165 + }; 166 + 167 + static const char * const ad7779_power_supplies[] = { 168 + "avdd1", "avdd2", "avdd4", 169 + }; 170 + 171 + static int ad7779_spi_read(struct ad7779_state *st, u8 reg, u8 *rbuf) 172 + { 173 + int ret; 174 + u8 crc_buf[2]; 175 + u8 exp_crc; 176 + struct spi_transfer t = { 177 + .tx_buf = st->reg_tx_buf, 178 + .rx_buf = st->reg_rx_buf, 179 + }; 180 + 181 + st->reg_tx_buf[0] = AD7779_SPI_READ_CMD | FIELD_GET(AD7779_REG_MSK, reg); 182 + st->reg_tx_buf[1] = 0; 183 + 184 + if (reg == AD7779_REG_GEN_ERR_REG_1_EN) { 185 + t.len = 2; 186 + } else { 187 + t.len = 3; 188 + st->reg_tx_buf[2] = crc8(ad7779_crc8_table, st->reg_tx_buf, 189 + t.len - 1, 0); 190 + } 191 + 192 + ret = spi_sync_transfer(st->spi, &t, 1); 193 + if (ret) 194 + return ret; 195 + 196 + crc_buf[0] = AD7779_SPI_READ_CMD | FIELD_GET(AD7779_REG_MSK, reg); 197 + crc_buf[1] = st->reg_rx_buf[1]; 198 + exp_crc = crc8(ad7779_crc8_table, crc_buf, ARRAY_SIZE(crc_buf), 0); 199 + if (reg != AD7779_REG_GEN_ERR_REG_1_EN && exp_crc != st->reg_rx_buf[2]) { 200 + dev_err(&st->spi->dev, "Bad CRC %x, expected %x", 201 + st->reg_rx_buf[2], exp_crc); 202 + return -EINVAL; 203 + } 204 + *rbuf = st->reg_rx_buf[1]; 205 + 206 + return 0; 207 + } 208 + 209 + static int ad7779_spi_write(struct ad7779_state *st, u8 reg, u8 val) 210 + { 211 + u8 length = 3; 212 + 213 + st->reg_tx_buf[0] = FIELD_GET(AD7779_REG_MSK, reg); 214 + st->reg_tx_buf[1] = val; 215 + if (reg == AD7779_REG_GEN_ERR_REG_1_EN) 216 + length = 2; 217 + else 218 + st->reg_tx_buf[2] = crc8(ad7779_crc8_table, st->reg_tx_buf, 219 + length - 1, 0); 220 + 221 + return spi_write(st->spi, st->reg_tx_buf, length); 222 + } 223 + 224 + static int ad7779_spi_write_mask(struct ad7779_state *st, u8 reg, u8 mask, 225 + u8 val) 226 + { 227 + int ret; 228 + u8 regval, data; 229 + 230 + ret = ad7779_spi_read(st, reg, &data); 231 + if (ret) 232 + return ret; 233 + 234 + regval = (data & ~mask) | (val & mask); 235 + 236 + if (regval == data) 237 + return 0; 238 + 239 + return ad7779_spi_write(st, reg, regval); 240 + } 241 + 242 + static int ad7779_reg_access(struct iio_dev *indio_dev, 243 + unsigned int reg, 244 + unsigned int writeval, 245 + unsigned int *readval) 246 + { 247 + struct ad7779_state *st = iio_priv(indio_dev); 248 + u8 rval; 249 + int ret; 250 + 251 + if (readval) { 252 + ret = ad7779_spi_read(st, reg, &rval); 253 + *readval = rval; 254 + return ret; 255 + } 256 + 257 + return ad7779_spi_write(st, reg, writeval); 258 + } 259 + 260 + static int ad7779_set_sampling_frequency(struct ad7779_state *st, 261 + unsigned int sampling_freq) 262 + { 263 + int ret; 264 + unsigned int dec; 265 + unsigned int frac; 266 + unsigned int div; 267 + unsigned int decimal; 268 + unsigned int freq_khz; 269 + 270 + if (st->filter_enabled == AD7779_SINC3 && 271 + sampling_freq > AD7779_SINC3_MAXFREQ) 272 + return -EINVAL; 273 + 274 + if (st->filter_enabled == AD7779_SINC5 && 275 + sampling_freq > AD7779_SINC5_MAXFREQ) 276 + return -EINVAL; 277 + 278 + if (sampling_freq > AD7779_SPIMODE_MAX_SAMP_FREQ) 279 + return -EINVAL; 280 + 281 + div = AD7779_HIGHPOWER_DIV; 282 + 283 + freq_khz = sampling_freq / HZ_PER_KHZ; 284 + dec = div / freq_khz; 285 + frac = div % freq_khz; 286 + 287 + ret = ad7779_spi_write(st, AD7779_REG_SRC_N_MSB, 288 + FIELD_GET(AD7779_FREQ_MSB_MSK, dec)); 289 + if (ret) 290 + return ret; 291 + ret = ad7779_spi_write(st, AD7779_REG_SRC_N_LSB, 292 + FIELD_GET(AD7779_FREQ_LSB_MSK, dec)); 293 + if (ret) 294 + return ret; 295 + 296 + if (frac) { 297 + /* 298 + * In order to obtain the first three decimals of the decimation 299 + * the initial number is multiplied with 10^3 prior to the 300 + * division, then the original division result is subtracted and 301 + * the number is divided by 10^3. 302 + */ 303 + decimal = ((mult_frac(div, KILO, freq_khz) - dec * KILO) << 16) 304 + / KILO; 305 + ret = ad7779_spi_write(st, AD7779_REG_SRC_N_MSB, 306 + FIELD_GET(AD7779_FREQ_MSB_MSK, decimal)); 307 + if (ret) 308 + return ret; 309 + ret = ad7779_spi_write(st, AD7779_REG_SRC_N_LSB, 310 + FIELD_GET(AD7779_FREQ_LSB_MSK, decimal)); 311 + if (ret) 312 + return ret; 313 + } else { 314 + ret = ad7779_spi_write(st, AD7779_REG_SRC_N_MSB, 315 + FIELD_GET(AD7779_FREQ_MSB_MSK, 0x0)); 316 + if (ret) 317 + return ret; 318 + ret = ad7779_spi_write(st, AD7779_REG_SRC_N_LSB, 319 + FIELD_GET(AD7779_FREQ_LSB_MSK, 0x0)); 320 + if (ret) 321 + return ret; 322 + } 323 + ret = ad7779_spi_write(st, AD7779_REG_SRC_UPDATE, BIT(0)); 324 + if (ret) 325 + return ret; 326 + 327 + /* SRC update settling time */ 328 + fsleep(15); 329 + 330 + ret = ad7779_spi_write(st, AD7779_REG_SRC_UPDATE, 0x0); 331 + if (ret) 332 + return ret; 333 + 334 + /* SRC update settling time */ 335 + fsleep(15); 336 + 337 + st->sampling_freq = sampling_freq; 338 + 339 + return 0; 340 + } 341 + 342 + static int ad7779_get_filter(struct iio_dev *indio_dev, 343 + struct iio_chan_spec const *chan) 344 + { 345 + struct ad7779_state *st = iio_priv(indio_dev); 346 + u8 temp; 347 + int ret; 348 + 349 + ret = ad7779_spi_read(st, AD7779_REG_GENERAL_USER_CONFIG_2, &temp); 350 + if (ret) 351 + return ret; 352 + 353 + return FIELD_GET(AD7779_FILTER_MSK, temp); 354 + } 355 + 356 + static int ad7779_set_filter(struct iio_dev *indio_dev, 357 + struct iio_chan_spec const *chan, 358 + unsigned int mode) 359 + { 360 + struct ad7779_state *st = iio_priv(indio_dev); 361 + int ret; 362 + 363 + ret = ad7779_spi_write_mask(st, 364 + AD7779_REG_GENERAL_USER_CONFIG_2, 365 + AD7779_FILTER_MSK, 366 + FIELD_PREP(AD7779_FILTER_MSK, mode)); 367 + if (ret) 368 + return ret; 369 + 370 + ret = ad7779_set_sampling_frequency(st, st->sampling_freq); 371 + if (ret) 372 + return ret; 373 + 374 + st->filter_enabled = mode; 375 + 376 + return 0; 377 + } 378 + 379 + static int ad7779_get_calibscale(struct ad7779_state *st, int channel) 380 + { 381 + int ret; 382 + u8 calibscale[3]; 383 + 384 + ret = ad7779_spi_read(st, AD7779_REG_CH_GAIN_LOWER_BYTE(channel), 385 + &calibscale[0]); 386 + if (ret) 387 + return ret; 388 + 389 + ret = ad7779_spi_read(st, AD7779_REG_CH_GAIN_MID_BYTE(channel), 390 + &calibscale[1]); 391 + if (ret) 392 + return ret; 393 + 394 + ret = ad7779_spi_read(st, AD7779_REG_CH_GAIN_UPPER_BYTE(channel), 395 + &calibscale[2]); 396 + if (ret) 397 + return ret; 398 + 399 + return get_unaligned_be24(calibscale); 400 + } 401 + 402 + static int ad7779_set_calibscale(struct ad7779_state *st, int channel, int val) 403 + { 404 + int ret; 405 + unsigned int gain; 406 + u8 gain_bytes[3]; 407 + 408 + /* 409 + * The gain value is relative to 0x555555, which represents a gain of 1 410 + */ 411 + gain = DIV_ROUND_CLOSEST_ULL((u64)val * 5592405LL, MEGA); 412 + put_unaligned_be24(gain, gain_bytes); 413 + ret = ad7779_spi_write(st, AD7779_REG_CH_GAIN_UPPER_BYTE(channel), 414 + gain_bytes[0]); 415 + if (ret) 416 + return ret; 417 + 418 + ret = ad7779_spi_write(st, AD7779_REG_CH_GAIN_MID_BYTE(channel), 419 + gain_bytes[1]); 420 + if (ret) 421 + return ret; 422 + 423 + return ad7779_spi_write(st, AD7779_REG_CH_GAIN_LOWER_BYTE(channel), 424 + gain_bytes[2]); 425 + } 426 + 427 + static int ad7779_get_calibbias(struct ad7779_state *st, int channel) 428 + { 429 + int ret; 430 + u8 calibbias[3]; 431 + 432 + ret = ad7779_spi_read(st, AD7779_REG_CH_OFFSET_LOWER_BYTE(channel), 433 + &calibbias[0]); 434 + if (ret) 435 + return ret; 436 + 437 + ret = ad7779_spi_read(st, AD7779_REG_CH_OFFSET_MID_BYTE(channel), 438 + &calibbias[1]); 439 + if (ret) 440 + return ret; 441 + 442 + ret = ad7779_spi_read(st, AD7779_REG_CH_OFFSET_UPPER_BYTE(channel), 443 + &calibbias[2]); 444 + if (ret) 445 + return ret; 446 + 447 + return get_unaligned_be24(calibbias); 448 + } 449 + 450 + static int ad7779_set_calibbias(struct ad7779_state *st, int channel, int val) 451 + { 452 + int ret; 453 + u8 calibbias[3]; 454 + 455 + put_unaligned_be24(val, calibbias); 456 + ret = ad7779_spi_write(st, AD7779_REG_CH_OFFSET_UPPER_BYTE(channel), 457 + calibbias[0]); 458 + if (ret) 459 + return ret; 460 + 461 + ret = ad7779_spi_write(st, AD7779_REG_CH_OFFSET_MID_BYTE(channel), 462 + calibbias[1]); 463 + if (ret) 464 + return ret; 465 + 466 + return ad7779_spi_write(st, AD7779_REG_CH_OFFSET_LOWER_BYTE(channel), 467 + calibbias[2]); 468 + } 469 + 470 + static int ad7779_read_raw(struct iio_dev *indio_dev, 471 + struct iio_chan_spec const *chan, int *val, 472 + int *val2, long mask) 473 + { 474 + struct ad7779_state *st = iio_priv(indio_dev); 475 + int ret; 476 + 477 + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 478 + switch (mask) { 479 + case IIO_CHAN_INFO_CALIBSCALE: 480 + ret = ad7779_get_calibscale(st, chan->channel); 481 + if (ret < 0) 482 + return ret; 483 + *val = ret; 484 + *val2 = GAIN_REL; 485 + return IIO_VAL_FRACTIONAL; 486 + case IIO_CHAN_INFO_CALIBBIAS: 487 + ret = ad7779_get_calibbias(st, chan->channel); 488 + if (ret < 0) 489 + return ret; 490 + *val = ret; 491 + return IIO_VAL_INT; 492 + case IIO_CHAN_INFO_SAMP_FREQ: 493 + *val = st->sampling_freq; 494 + if (*val < 0) 495 + return -EINVAL; 496 + return IIO_VAL_INT; 497 + default: 498 + return -EINVAL; 499 + } 500 + } 501 + unreachable(); 502 + } 503 + 504 + static int ad7779_write_raw(struct iio_dev *indio_dev, 505 + struct iio_chan_spec const *chan, int val, int val2, 506 + long mask) 507 + { 508 + struct ad7779_state *st = iio_priv(indio_dev); 509 + 510 + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 511 + switch (mask) { 512 + case IIO_CHAN_INFO_CALIBSCALE: 513 + return ad7779_set_calibscale(st, chan->channel, val2); 514 + case IIO_CHAN_INFO_CALIBBIAS: 515 + return ad7779_set_calibbias(st, chan->channel, val); 516 + case IIO_CHAN_INFO_SAMP_FREQ: 517 + return ad7779_set_sampling_frequency(st, val); 518 + default: 519 + return -EINVAL; 520 + } 521 + } 522 + unreachable(); 523 + } 524 + 525 + static int ad7779_buffer_preenable(struct iio_dev *indio_dev) 526 + { 527 + int ret; 528 + struct ad7779_state *st = iio_priv(indio_dev); 529 + 530 + ret = ad7779_spi_write_mask(st, 531 + AD7779_REG_GENERAL_USER_CONFIG_3, 532 + AD7779_MOD_SPI_EN_MSK, 533 + FIELD_PREP(AD7779_MOD_SPI_EN_MSK, 1)); 534 + if (ret) 535 + return ret; 536 + 537 + /* 538 + * DRDY output cannot be disabled at device level therefore we mask 539 + * the irq at host end. 540 + */ 541 + enable_irq(st->spi->irq); 542 + 543 + return 0; 544 + } 545 + 546 + static int ad7779_buffer_postdisable(struct iio_dev *indio_dev) 547 + { 548 + struct ad7779_state *st = iio_priv(indio_dev); 549 + 550 + disable_irq(st->spi->irq); 551 + 552 + return ad7779_spi_write(st, AD7779_REG_GENERAL_USER_CONFIG_3, 553 + AD7779_DISABLE_SD); 554 + } 555 + 556 + static irqreturn_t ad7779_trigger_handler(int irq, void *p) 557 + { 558 + struct iio_poll_func *pf = p; 559 + struct iio_dev *indio_dev = pf->indio_dev; 560 + struct ad7779_state *st = iio_priv(indio_dev); 561 + int ret; 562 + struct spi_transfer t = { 563 + .rx_buf = st->data.chans, 564 + .tx_buf = st->spidata_tx, 565 + .len = AD7779_NUM_CHANNELS * AD7779_CHAN_DATA_SIZE, 566 + }; 567 + 568 + st->spidata_tx[0] = AD7779_SPI_READ_CMD; 569 + ret = spi_sync_transfer(st->spi, &t, 1); 570 + if (ret) { 571 + dev_err(&st->spi->dev, "SPI transfer error in IRQ handler"); 572 + goto exit_handler; 573 + } 574 + 575 + iio_push_to_buffers_with_timestamp(indio_dev, &st->data, pf->timestamp); 576 + 577 + exit_handler: 578 + iio_trigger_notify_done(indio_dev->trig); 579 + return IRQ_HANDLED; 580 + } 581 + 582 + static int ad7779_reset(struct iio_dev *indio_dev, struct gpio_desc *reset_gpio) 583 + { 584 + struct ad7779_state *st = iio_priv(indio_dev); 585 + int ret; 586 + struct spi_transfer t = { 587 + .tx_buf = st->reset_buf, 588 + .len = 8, 589 + }; 590 + 591 + if (reset_gpio) { 592 + gpiod_set_value(reset_gpio, 1); 593 + /* Delay for reset to occur is 225 microseconds */ 594 + fsleep(230); 595 + ret = 0; 596 + } else { 597 + memset(st->reset_buf, 0xff, sizeof(st->reset_buf)); 598 + ret = spi_sync_transfer(st->spi, &t, 1); 599 + if (ret) 600 + return ret; 601 + } 602 + 603 + /* Delay for reset to occur is 225 microseconds */ 604 + fsleep(230); 605 + 606 + return ret; 607 + } 608 + 609 + static const struct iio_info ad7779_info = { 610 + .read_raw = ad7779_read_raw, 611 + .write_raw = ad7779_write_raw, 612 + .debugfs_reg_access = &ad7779_reg_access, 613 + }; 614 + 615 + static const struct iio_enum ad7779_filter_enum = { 616 + .items = ad7779_filter_type, 617 + .num_items = ARRAY_SIZE(ad7779_filter_type), 618 + .get = ad7779_get_filter, 619 + .set = ad7779_set_filter, 620 + }; 621 + 622 + static const struct iio_chan_spec_ext_info ad7779_ext_filter[] = { 623 + IIO_ENUM("filter_type", IIO_SHARED_BY_ALL, &ad7779_filter_enum), 624 + IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_ALL, 625 + &ad7779_filter_enum), 626 + { } 627 + }; 628 + 629 + #define AD777x_CHAN_S(index, _ext_info) \ 630 + { \ 631 + .type = IIO_VOLTAGE, \ 632 + .info_mask_separate = BIT(IIO_CHAN_INFO_CALIBSCALE) | \ 633 + BIT(IIO_CHAN_INFO_CALIBBIAS), \ 634 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\ 635 + .address = (index), \ 636 + .indexed = 1, \ 637 + .channel = (index), \ 638 + .scan_index = (index), \ 639 + .ext_info = (_ext_info), \ 640 + .scan_type = { \ 641 + .sign = 's', \ 642 + .realbits = 24, \ 643 + .storagebits = 32, \ 644 + .endianness = IIO_BE, \ 645 + }, \ 646 + } 647 + 648 + #define AD777x_CHAN_NO_FILTER_S(index) \ 649 + AD777x_CHAN_S(index, NULL) 650 + 651 + #define AD777x_CHAN_FILTER_S(index) \ 652 + AD777x_CHAN_S(index, ad7779_ext_filter) 653 + static const struct iio_chan_spec ad7779_channels[] = { 654 + AD777x_CHAN_NO_FILTER_S(0), 655 + AD777x_CHAN_NO_FILTER_S(1), 656 + AD777x_CHAN_NO_FILTER_S(2), 657 + AD777x_CHAN_NO_FILTER_S(3), 658 + AD777x_CHAN_NO_FILTER_S(4), 659 + AD777x_CHAN_NO_FILTER_S(5), 660 + AD777x_CHAN_NO_FILTER_S(6), 661 + AD777x_CHAN_NO_FILTER_S(7), 662 + IIO_CHAN_SOFT_TIMESTAMP(8), 663 + }; 664 + 665 + static const struct iio_chan_spec ad7779_channels_filter[] = { 666 + AD777x_CHAN_FILTER_S(0), 667 + AD777x_CHAN_FILTER_S(1), 668 + AD777x_CHAN_FILTER_S(2), 669 + AD777x_CHAN_FILTER_S(3), 670 + AD777x_CHAN_FILTER_S(4), 671 + AD777x_CHAN_FILTER_S(5), 672 + AD777x_CHAN_FILTER_S(6), 673 + AD777x_CHAN_FILTER_S(7), 674 + IIO_CHAN_SOFT_TIMESTAMP(8), 675 + }; 676 + 677 + static const struct iio_buffer_setup_ops ad7779_buffer_setup_ops = { 678 + .preenable = ad7779_buffer_preenable, 679 + .postdisable = ad7779_buffer_postdisable, 680 + }; 681 + 682 + static const struct iio_trigger_ops ad7779_trigger_ops = { 683 + .validate_device = iio_trigger_validate_own_device, 684 + }; 685 + 686 + static int ad7779_conf(struct ad7779_state *st, struct gpio_desc *start_gpio) 687 + { 688 + int ret; 689 + 690 + ret = ad7779_spi_write_mask(st, AD7779_REG_GEN_ERR_REG_1_EN, 691 + AD7779_SPI_CRC_EN_MSK, 692 + FIELD_PREP(AD7779_SPI_CRC_EN_MSK, 1)); 693 + if (ret) 694 + return ret; 695 + 696 + ret = ad7779_spi_write_mask(st, AD7779_REG_GENERAL_USER_CONFIG_1, 697 + AD7779_USRMOD_INIT_MSK, 698 + FIELD_PREP(AD7779_USRMOD_INIT_MSK, 5)); 699 + if (ret) 700 + return ret; 701 + 702 + ret = ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT, 703 + AD7779_DCLK_CLK_DIV_MSK, 704 + FIELD_PREP(AD7779_DCLK_CLK_DIV_MSK, 1)); 705 + if (ret) 706 + return ret; 707 + 708 + ret = ad7779_spi_write_mask(st, AD7779_REG_ADC_MUX_CONFIG, 709 + AD7779_REFMUX_CTRL_MSK, 710 + FIELD_PREP(AD7779_REFMUX_CTRL_MSK, 1)); 711 + if (ret) 712 + return ret; 713 + 714 + ret = ad7779_set_sampling_frequency(st, AD7779_DEFAULT_SAMPLING_FREQ); 715 + if (ret) 716 + return ret; 717 + 718 + gpiod_set_value(start_gpio, 0); 719 + /* Start setup time */ 720 + fsleep(15); 721 + gpiod_set_value(start_gpio, 1); 722 + /* Start setup time */ 723 + fsleep(15); 724 + gpiod_set_value(start_gpio, 0); 725 + /* Start setup time */ 726 + fsleep(15); 727 + 728 + return 0; 729 + } 730 + 731 + static int ad7779_probe(struct spi_device *spi) 732 + { 733 + struct iio_dev *indio_dev; 734 + struct ad7779_state *st; 735 + struct gpio_desc *reset_gpio, *start_gpio; 736 + struct device *dev = &spi->dev; 737 + int ret = -EINVAL; 738 + 739 + if (!spi->irq) 740 + return dev_err_probe(dev, ret, "DRDY irq not present\n"); 741 + 742 + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 743 + if (!indio_dev) 744 + return -ENOMEM; 745 + 746 + st = iio_priv(indio_dev); 747 + 748 + ret = devm_regulator_bulk_get_enable(dev, 749 + ARRAY_SIZE(ad7779_power_supplies), 750 + ad7779_power_supplies); 751 + if (ret) 752 + return dev_err_probe(dev, ret, 753 + "failed to get and enable supplies\n"); 754 + 755 + st->mclk = devm_clk_get_enabled(dev, "mclk"); 756 + if (IS_ERR(st->mclk)) 757 + return PTR_ERR(st->mclk); 758 + 759 + reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); 760 + if (IS_ERR(reset_gpio)) 761 + return PTR_ERR(reset_gpio); 762 + 763 + start_gpio = devm_gpiod_get(dev, "start", GPIOD_OUT_HIGH); 764 + if (IS_ERR(start_gpio)) 765 + return PTR_ERR(start_gpio); 766 + 767 + crc8_populate_msb(ad7779_crc8_table, AD7779_CRC8_POLY); 768 + st->spi = spi; 769 + 770 + st->chip_info = spi_get_device_match_data(spi); 771 + if (!st->chip_info) 772 + return -ENODEV; 773 + 774 + ret = ad7779_reset(indio_dev, reset_gpio); 775 + if (ret) 776 + return ret; 777 + 778 + ret = ad7779_conf(st, start_gpio); 779 + if (ret) 780 + return ret; 781 + 782 + indio_dev->name = st->chip_info->name; 783 + indio_dev->info = &ad7779_info; 784 + indio_dev->modes = INDIO_DIRECT_MODE; 785 + indio_dev->channels = st->chip_info->channels; 786 + indio_dev->num_channels = ARRAY_SIZE(ad7779_channels); 787 + 788 + st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, 789 + iio_device_id(indio_dev)); 790 + if (!st->trig) 791 + return -ENOMEM; 792 + 793 + st->trig->ops = &ad7779_trigger_ops; 794 + 795 + iio_trigger_set_drvdata(st->trig, st); 796 + 797 + ret = devm_request_irq(dev, spi->irq, iio_trigger_generic_data_rdy_poll, 798 + IRQF_ONESHOT | IRQF_NO_AUTOEN, indio_dev->name, 799 + st->trig); 800 + if (ret) 801 + return dev_err_probe(dev, ret, "request IRQ %d failed\n", 802 + st->spi->irq); 803 + 804 + ret = devm_iio_trigger_register(dev, st->trig); 805 + if (ret) 806 + return ret; 807 + 808 + indio_dev->trig = iio_trigger_get(st->trig); 809 + 810 + init_completion(&st->completion); 811 + 812 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 813 + &iio_pollfunc_store_time, 814 + &ad7779_trigger_handler, 815 + &ad7779_buffer_setup_ops); 816 + if (ret) 817 + return ret; 818 + 819 + ret = ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT, 820 + AD7779_DCLK_CLK_DIV_MSK, 821 + FIELD_PREP(AD7779_DCLK_CLK_DIV_MSK, 7)); 822 + if (ret) 823 + return ret; 824 + 825 + return devm_iio_device_register(dev, indio_dev); 826 + } 827 + 828 + static int ad7779_suspend(struct device *dev) 829 + { 830 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 831 + struct ad7779_state *st = iio_priv(indio_dev); 832 + 833 + return ad7779_spi_write_mask(st, AD7779_REG_GENERAL_USER_CONFIG_1, 834 + AD7779_MOD_POWERMODE_MSK, 835 + FIELD_PREP(AD7779_MOD_POWERMODE_MSK, 836 + AD7779_LOW_POWER)); 837 + } 838 + 839 + static int ad7779_resume(struct device *dev) 840 + { 841 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 842 + struct ad7779_state *st = iio_priv(indio_dev); 843 + 844 + return ad7779_spi_write_mask(st, AD7779_REG_GENERAL_USER_CONFIG_1, 845 + AD7779_MOD_POWERMODE_MSK, 846 + FIELD_PREP(AD7779_MOD_POWERMODE_MSK, 847 + AD7779_HIGH_POWER)); 848 + } 849 + 850 + static DEFINE_SIMPLE_DEV_PM_OPS(ad7779_pm_ops, ad7779_suspend, ad7779_resume); 851 + 852 + static const struct ad7779_chip_info ad7770_chip_info = { 853 + .name = "ad7770", 854 + .channels = ad7779_channels, 855 + }; 856 + 857 + static const struct ad7779_chip_info ad7771_chip_info = { 858 + .name = "ad7771", 859 + .channels = ad7779_channels_filter, 860 + }; 861 + 862 + static const struct ad7779_chip_info ad7779_chip_info = { 863 + .name = "ad7779", 864 + .channels = ad7779_channels, 865 + }; 866 + 867 + static const struct spi_device_id ad7779_id[] = { 868 + { 869 + .name = "ad7770", 870 + .driver_data = (kernel_ulong_t)&ad7770_chip_info, 871 + }, 872 + { 873 + .name = "ad7771", 874 + .driver_data = (kernel_ulong_t)&ad7771_chip_info, 875 + }, 876 + { 877 + .name = "ad7779", 878 + .driver_data = (kernel_ulong_t)&ad7779_chip_info, 879 + }, 880 + { } 881 + }; 882 + MODULE_DEVICE_TABLE(spi, ad7779_id); 883 + 884 + static const struct of_device_id ad7779_of_table[] = { 885 + { 886 + .compatible = "adi,ad7770", 887 + .data = &ad7770_chip_info, 888 + }, 889 + { 890 + .compatible = "adi,ad7771", 891 + .data = &ad7771_chip_info, 892 + }, 893 + { 894 + .compatible = "adi,ad7779", 895 + .data = &ad7779_chip_info, 896 + }, 897 + { } 898 + }; 899 + MODULE_DEVICE_TABLE(of, ad7779_of_table); 900 + 901 + static struct spi_driver ad7779_driver = { 902 + .driver = { 903 + .name = "ad7779", 904 + .pm = pm_sleep_ptr(&ad7779_pm_ops), 905 + .of_match_table = ad7779_of_table, 906 + }, 907 + .probe = ad7779_probe, 908 + .id_table = ad7779_id, 909 + }; 910 + module_spi_driver(ad7779_driver); 911 + 912 + MODULE_AUTHOR("Ramona Alexandra Nechita <ramona.nechita@analog.com>"); 913 + MODULE_DESCRIPTION("Analog Devices AD7779 ADC"); 914 + MODULE_LICENSE("GPL");
+1 -1
drivers/iio/adc/ad799x.c
··· 406 406 const struct iio_chan_spec *chan, 407 407 enum iio_event_type type, 408 408 enum iio_event_direction dir, 409 - int state) 409 + bool state) 410 410 { 411 411 struct ad799x_state *st = iio_priv(indio_dev); 412 412 int ret;
+1 -1
drivers/iio/adc/hi8435.c
··· 132 132 static int hi8435_write_event_config(struct iio_dev *idev, 133 133 const struct iio_chan_spec *chan, 134 134 enum iio_event_type type, 135 - enum iio_event_direction dir, int state) 135 + enum iio_event_direction dir, bool state) 136 136 { 137 137 struct hi8435_priv *priv = iio_priv(idev); 138 138 int ret;
+1 -1
drivers/iio/adc/max1363.c
··· 944 944 945 945 static int max1363_write_event_config(struct iio_dev *indio_dev, 946 946 const struct iio_chan_spec *chan, enum iio_event_type type, 947 - enum iio_event_direction dir, int state) 947 + enum iio_event_direction dir, bool state) 948 948 { 949 949 struct max1363_state *st = iio_priv(indio_dev); 950 950
+5 -2
drivers/iio/adc/pac1921.c
··· 699 699 static int pac1921_write_event_config(struct iio_dev *indio_dev, 700 700 const struct iio_chan_spec *chan, 701 701 enum iio_event_type type, 702 - enum iio_event_direction dir, int state) 702 + enum iio_event_direction dir, 703 + bool state) 703 704 { 704 705 struct pac1921_priv *priv = iio_priv(indio_dev); 705 706 u8 ovf_bit; ··· 1171 1170 return dev_err_probe(dev, PTR_ERR(priv->regmap), 1172 1171 "Cannot initialize register map\n"); 1173 1172 1174 - devm_mutex_init(dev, &priv->lock); 1173 + ret = devm_mutex_init(dev, &priv->lock); 1174 + if (ret) 1175 + return ret; 1175 1176 1176 1177 priv->dv_gain = PAC1921_DEFAULT_DV_GAIN; 1177 1178 priv->di_gain = PAC1921_DEFAULT_DI_GAIN;
+1 -1
drivers/iio/adc/pac1934.c
··· 1507 1507 indio_dev->name = pac1934_chip_config[ret].name; 1508 1508 } 1509 1509 1510 - if (acpi_match_device(dev->driver->acpi_match_table, dev)) 1510 + if (is_acpi_device_node(dev_fwnode(dev))) 1511 1511 ret = pac1934_acpi_parse_channel_config(client, info); 1512 1512 else 1513 1513 /*
+1 -1
drivers/iio/adc/palmas_gpadc.c
··· 676 676 const struct iio_chan_spec *chan, 677 677 enum iio_event_type type, 678 678 enum iio_event_direction dir, 679 - int state) 679 + bool state) 680 680 { 681 681 struct palmas_gpadc *adc = iio_priv(indio_dev); 682 682 int adc_chan = chan->channel;
+1 -1
drivers/iio/adc/ti-ads1015.c
··· 806 806 807 807 static int ads1015_write_event_config(struct iio_dev *indio_dev, 808 808 const struct iio_chan_spec *chan, enum iio_event_type type, 809 - enum iio_event_direction dir, int state) 809 + enum iio_event_direction dir, bool state) 810 810 { 811 811 struct ads1015_data *data = iio_priv(indio_dev); 812 812 int ret;
+1 -1
drivers/iio/adc/xilinx-ams.c
··· 905 905 const struct iio_chan_spec *chan, 906 906 enum iio_event_type type, 907 907 enum iio_event_direction dir, 908 - int state) 908 + bool state) 909 909 { 910 910 struct ams *ams = iio_priv(indio_dev); 911 911 unsigned int alarm;
+1 -1
drivers/iio/adc/xilinx-xadc-events.c
··· 121 121 122 122 int xadc_write_event_config(struct iio_dev *indio_dev, 123 123 const struct iio_chan_spec *chan, enum iio_event_type type, 124 - enum iio_event_direction dir, int state) 124 + enum iio_event_direction dir, bool state) 125 125 { 126 126 unsigned int alarm = xadc_get_alarm_mask(chan); 127 127 struct xadc *xadc = iio_priv(indio_dev);
+1 -1
drivers/iio/adc/xilinx-xadc.h
··· 25 25 enum iio_event_direction dir); 26 26 int xadc_write_event_config(struct iio_dev *indio_dev, 27 27 const struct iio_chan_spec *chan, enum iio_event_type type, 28 - enum iio_event_direction dir, int state); 28 + enum iio_event_direction dir, bool state); 29 29 int xadc_read_event_value(struct iio_dev *indio_dev, 30 30 const struct iio_chan_spec *chan, enum iio_event_type type, 31 31 enum iio_event_direction dir, enum iio_event_info info,
+30 -51
drivers/iio/addac/ad74413r.c
··· 6 6 7 7 #include <linux/unaligned.h> 8 8 #include <linux/bitfield.h> 9 + #include <linux/cleanup.h> 9 10 #include <linux/crc8.h> 10 11 #include <linux/device.h> 11 12 #include <linux/err.h> 13 + #include <linux/gpio/consumer.h> 12 14 #include <linux/gpio/driver.h> 13 15 #include <linux/iio/buffer.h> 14 16 #include <linux/iio/iio.h> ··· 61 59 unsigned int num_gpo_gpios; 62 60 unsigned int num_comparator_gpios; 63 61 u32 sense_resistor_ohms; 64 - 62 + int refin_reg_uv; 65 63 /* 66 64 * Synchronize consecutive operations when doing a one-shot 67 65 * conversion and when updating the ADC samples SPI message. ··· 70 68 71 69 const struct ad74413r_chip_info *chip_info; 72 70 struct spi_device *spi; 73 - struct regulator *refin_reg; 74 71 struct regmap *regmap; 75 72 struct device *dev; 76 73 struct iio_trigger *trig; 77 - struct gpio_desc *reset_gpio; 78 74 79 75 size_t adc_active_channels; 80 76 struct spi_message adc_samples_msg; ··· 407 407 408 408 static int ad74413r_reset(struct ad74413r_state *st) 409 409 { 410 + struct gpio_desc *reset_gpio; 410 411 int ret; 411 412 412 - if (st->reset_gpio) { 413 - gpiod_set_value_cansleep(st->reset_gpio, 1); 413 + reset_gpio = devm_gpiod_get_optional(st->dev, "reset", GPIOD_OUT_HIGH); 414 + if (IS_ERR(reset_gpio)) 415 + return PTR_ERR(reset_gpio); 416 + 417 + if (reset_gpio) { 414 418 fsleep(50); 415 - gpiod_set_value_cansleep(st->reset_gpio, 0); 419 + gpiod_set_value_cansleep(reset_gpio, 0); 416 420 return 0; 417 421 } 418 422 ··· 664 660 static int ad74413r_get_output_current_scale(struct ad74413r_state *st, 665 661 int *val, int *val2) 666 662 { 667 - *val = regulator_get_voltage(st->refin_reg); 663 + *val = st->refin_reg_uv; 668 664 *val2 = st->sense_resistor_ohms * AD74413R_DAC_CODE_MAX * 1000; 669 665 670 666 return IIO_VAL_FRACTIONAL; ··· 865 861 unsigned int channel, int *val) 866 862 { 867 863 struct ad74413r_state *st = iio_priv(indio_dev); 868 - int ret; 869 864 870 - ret = iio_device_claim_direct_mode(indio_dev); 871 - if (ret) 872 - return ret; 873 - 874 - mutex_lock(&st->lock); 875 - ret = _ad74413r_get_single_adc_result(st, channel, val); 876 - mutex_unlock(&st->lock); 877 - 878 - iio_device_release_direct_mode(indio_dev); 879 - 880 - return ret; 865 + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 866 + guard(mutex)(&st->lock); 867 + return _ad74413r_get_single_adc_result(st, channel, val); 868 + } 869 + unreachable(); 881 870 } 882 871 883 872 static void ad74413r_adc_to_resistance_result(int adc_result, int *val) ··· 892 895 unsigned int channel; 893 896 int ret = -EINVAL; 894 897 895 - mutex_lock(&st->lock); 898 + guard(mutex)(&st->lock); 896 899 897 900 spi_message_init(&st->adc_samples_msg); 898 901 st->adc_active_channels = 0; ··· 900 903 for_each_clear_bit(channel, active_scan_mask, AD74413R_CHANNEL_MAX) { 901 904 ret = ad74413r_set_adc_channel_enable(st, channel, false); 902 905 if (ret) 903 - goto out; 906 + return ret; 904 907 } 905 908 906 909 if (*active_scan_mask == 0) 907 - goto out; 910 + return ret; 908 911 909 912 /* 910 913 * The read select register is used to select which register's value ··· 922 925 for_each_set_bit(channel, active_scan_mask, AD74413R_CHANNEL_MAX) { 923 926 ret = ad74413r_set_adc_channel_enable(st, channel, true); 924 927 if (ret) 925 - goto out; 928 + return ret; 926 929 927 930 st->adc_active_channels++; 928 931 ··· 953 956 xfer->cs_change = 0; 954 957 955 958 spi_message_add_tail(xfer, &st->adc_samples_msg); 956 - 957 - out: 958 - mutex_unlock(&st->lock); 959 - 960 - return ret; 959 + return 0; 961 960 } 962 961 963 962 static int ad74413r_buffer_postenable(struct iio_dev *indio_dev) ··· 1340 1347 return 0; 1341 1348 } 1342 1349 1343 - static void ad74413r_regulator_disable(void *regulator) 1344 - { 1345 - regulator_disable(regulator); 1346 - } 1347 - 1348 1350 static int ad74413r_probe(struct spi_device *spi) 1349 1351 { 1350 1352 struct ad74413r_state *st; ··· 1358 1370 if (!st->chip_info) 1359 1371 return -EINVAL; 1360 1372 1361 - mutex_init(&st->lock); 1373 + ret = devm_mutex_init(st->dev, &st->lock); 1374 + if (ret) 1375 + return ret; 1376 + 1362 1377 init_completion(&st->adc_data_completion); 1363 1378 1364 1379 st->regmap = devm_regmap_init(st->dev, NULL, st, ··· 1369 1378 if (IS_ERR(st->regmap)) 1370 1379 return PTR_ERR(st->regmap); 1371 1380 1372 - st->reset_gpio = devm_gpiod_get_optional(st->dev, "reset", GPIOD_OUT_LOW); 1373 - if (IS_ERR(st->reset_gpio)) 1374 - return PTR_ERR(st->reset_gpio); 1375 - 1376 - st->refin_reg = devm_regulator_get(st->dev, "refin"); 1377 - if (IS_ERR(st->refin_reg)) 1378 - return dev_err_probe(st->dev, PTR_ERR(st->refin_reg), 1379 - "Failed to get refin regulator\n"); 1380 - 1381 - ret = regulator_enable(st->refin_reg); 1382 - if (ret) 1383 - return ret; 1384 - 1385 - ret = devm_add_action_or_reset(st->dev, ad74413r_regulator_disable, 1386 - st->refin_reg); 1387 - if (ret) 1388 - return ret; 1381 + ret = devm_regulator_get_enable_read_voltage(st->dev, "refin"); 1382 + if (ret < 0) 1383 + return dev_err_probe(st->dev, ret, 1384 + "Failed to get refin regulator voltage\n"); 1385 + st->refin_reg_uv = ret; 1389 1386 1390 1387 st->sense_resistor_ohms = 100000000; 1391 1388 device_property_read_u32(st->dev, "shunt-resistor-micro-ohms",
+1 -1
drivers/iio/cdc/ad7150.c
··· 232 232 static int ad7150_write_event_config(struct iio_dev *indio_dev, 233 233 const struct iio_chan_spec *chan, 234 234 enum iio_event_type type, 235 - enum iio_event_direction dir, int state) 235 + enum iio_event_direction dir, bool state) 236 236 { 237 237 struct ad7150_chip_info *chip = iio_priv(indio_dev); 238 238 int ret = 0;
+2
drivers/iio/chemical/Kconfig
··· 50 50 select REGMAP 51 51 select BME680_I2C if I2C 52 52 select BME680_SPI if SPI 53 + select IIO_BUFFER 54 + select IIO_TRIGGERED_BUFFER 53 55 help 54 56 Say yes here to build support for Bosch Sensortec BME680 sensor with 55 57 temperature, pressure, humidity and gas sensing capability.
+8 -3
drivers/iio/chemical/bme680.h
··· 2 2 #ifndef BME680_H_ 3 3 #define BME680_H_ 4 4 5 + #include <linux/regmap.h> 6 + 5 7 #define BME680_REG_CHIP_ID 0xD0 6 8 #define BME680_CHIP_ID_VAL 0x61 7 9 #define BME680_REG_SOFT_RESET 0xE0 ··· 27 25 #define BME680_OSRS_TEMP_MASK GENMASK(7, 5) 28 26 #define BME680_OSRS_PRESS_MASK GENMASK(4, 2) 29 27 #define BME680_MODE_MASK GENMASK(1, 0) 30 - #define BME680_MODE_FORCED 1 31 - #define BME680_MODE_SLEEP 0 32 28 33 29 #define BME680_REG_CONFIG 0x75 34 30 #define BME680_FILTER_MASK GENMASK(4, 2) ··· 42 42 #define BME680_RHRANGE_MASK GENMASK(5, 4) 43 43 #define BME680_REG_RES_HEAT_VAL 0x00 44 44 #define BME680_RSERROR_MASK GENMASK(7, 4) 45 + #define BME680_REG_IDAC_HEAT_0 0x50 45 46 #define BME680_REG_RES_HEAT_0 0x5A 46 47 #define BME680_REG_GAS_WAIT_0 0x64 47 48 #define BME680_ADC_GAS_RES GENMASK(15, 6) ··· 64 63 65 64 #define BME680_MEAS_TRIM_MASK GENMASK(24, 4) 66 65 67 - #define BME680_STARTUP_TIME_US 5000 66 + /* Datasheet Section 1.1, Table 1 */ 67 + #define BME680_STARTUP_TIME_US 2000 68 + 69 + #define BME680_NUM_CHANNELS 4 70 + #define BME680_NUM_BULK_READ_REGS 15 68 71 69 72 /* Calibration Parameters */ 70 73 #define BME680_T2_LSB_REG 0x8A
+298 -66
drivers/iio/chemical/bme680_core.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/regmap.h> 18 18 19 + #include <linux/iio/buffer.h> 19 20 #include <linux/iio/iio.h> 20 21 #include <linux/iio/sysfs.h> 22 + #include <linux/iio/trigger_consumer.h> 23 + #include <linux/iio/triggered_buffer.h> 21 24 22 25 #include <linux/unaligned.h> 23 26 ··· 98 95 s8 range_sw_err; 99 96 }; 100 97 98 + /* values of CTRL_MEAS register */ 99 + enum bme680_op_mode { 100 + BME680_MODE_SLEEP = 0, 101 + BME680_MODE_FORCED = 1, 102 + }; 103 + 104 + enum bme680_scan { 105 + BME680_TEMP, 106 + BME680_PRESS, 107 + BME680_HUMID, 108 + BME680_GAS, 109 + }; 110 + 101 111 struct bme680_data { 102 112 struct regmap *regmap; 103 113 struct bme680_calib bme680; ··· 118 102 u8 oversampling_temp; 119 103 u8 oversampling_press; 120 104 u8 oversampling_humid; 105 + u8 preheat_curr_mA; 121 106 u16 heater_dur; 122 107 u16 heater_temp; 123 108 109 + struct { 110 + s32 chan[4]; 111 + aligned_s64 ts; 112 + } scan; 113 + 124 114 union { 125 - u8 buf[3]; 115 + u8 buf[BME680_NUM_BULK_READ_REGS]; 126 116 unsigned int check; 127 117 __be16 be16; 128 118 u8 bme680_cal_buf_1[BME680_CALIB_RANGE_1_LEN]; ··· 160 138 static const struct iio_chan_spec bme680_channels[] = { 161 139 { 162 140 .type = IIO_TEMP, 141 + /* PROCESSED maintained for ABI backwards compatibility */ 163 142 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 143 + BIT(IIO_CHAN_INFO_RAW) | 144 + BIT(IIO_CHAN_INFO_SCALE) | 164 145 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 146 + .scan_index = 0, 147 + .scan_type = { 148 + .sign = 's', 149 + .realbits = 16, 150 + .storagebits = 16, 151 + .endianness = IIO_CPU, 152 + }, 165 153 }, 166 154 { 167 155 .type = IIO_PRESSURE, 156 + /* PROCESSED maintained for ABI backwards compatibility */ 168 157 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 158 + BIT(IIO_CHAN_INFO_RAW) | 159 + BIT(IIO_CHAN_INFO_SCALE) | 169 160 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 161 + .scan_index = 1, 162 + .scan_type = { 163 + .sign = 'u', 164 + .realbits = 32, 165 + .storagebits = 32, 166 + .endianness = IIO_CPU, 167 + }, 170 168 }, 171 169 { 172 170 .type = IIO_HUMIDITYRELATIVE, 171 + /* PROCESSED maintained for ABI backwards compatibility */ 173 172 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 173 + BIT(IIO_CHAN_INFO_RAW) | 174 + BIT(IIO_CHAN_INFO_SCALE) | 174 175 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 176 + .scan_index = 2, 177 + .scan_type = { 178 + .sign = 'u', 179 + .realbits = 32, 180 + .storagebits = 32, 181 + .endianness = IIO_CPU, 182 + }, 175 183 }, 176 184 { 177 185 .type = IIO_RESISTANCE, 178 186 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 187 + .scan_index = 3, 188 + .scan_type = { 189 + .sign = 'u', 190 + .realbits = 32, 191 + .storagebits = 32, 192 + .endianness = IIO_CPU, 193 + }, 194 + }, 195 + IIO_CHAN_SOFT_TIMESTAMP(4), 196 + { 197 + .type = IIO_CURRENT, 198 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 199 + .output = 1, 200 + .scan_index = -1, 179 201 }, 180 202 }; 181 203 ··· 290 224 calib->res_heat_val = data->bme680_cal_buf_3[RES_HEAT_VAL]; 291 225 292 226 calib->res_heat_range = FIELD_GET(BME680_RHRANGE_MASK, 293 - data->bme680_cal_buf_3[RES_HEAT_RANGE]); 227 + data->bme680_cal_buf_3[RES_HEAT_RANGE]); 294 228 295 229 calib->range_sw_err = FIELD_GET(BME680_RSERROR_MASK, 296 230 data->bme680_cal_buf_3[RANGE_SW_ERR]); ··· 504 438 u32 calc_gas_res; 505 439 506 440 /* Look up table for the possible gas range values */ 507 - static const u32 lookupTable[16] = {2147483647u, 2147483647u, 508 - 2147483647u, 2147483647u, 2147483647u, 509 - 2126008810u, 2147483647u, 2130303777u, 510 - 2147483647u, 2147483647u, 2143188679u, 511 - 2136746228u, 2147483647u, 2126008810u, 512 - 2147483647u, 2147483647u}; 441 + static const u32 lookup_table[16] = { 442 + 2147483647u, 2147483647u, 2147483647u, 2147483647u, 443 + 2147483647u, 2126008810u, 2147483647u, 2130303777u, 444 + 2147483647u, 2147483647u, 2143188679u, 2136746228u, 445 + 2147483647u, 2126008810u, 2147483647u, 2147483647u 446 + }; 513 447 514 - var1 = ((1340 + (5 * (s64) calib->range_sw_err)) * 515 - ((s64) lookupTable[gas_range])) >> 16; 448 + var1 = ((1340LL + (5 * calib->range_sw_err)) * 449 + (lookup_table[gas_range])) >> 16; 516 450 var2 = ((gas_res_adc << 15) - 16777216) + var1; 517 451 var3 = ((125000 << (15 - gas_range)) * var1) >> 9; 518 452 var3 += (var2 >> 1); 519 - calc_gas_res = div64_s64(var3, (s64) var2); 453 + calc_gas_res = div64_s64(var3, (s64)var2); 520 454 521 455 return calc_gas_res; 522 456 } ··· 534 468 if (temp > 400) /* Cap temperature */ 535 469 temp = 400; 536 470 537 - var1 = (((s32) BME680_AMB_TEMP * calib->par_gh3) / 1000) * 256; 471 + var1 = (((s32)BME680_AMB_TEMP * calib->par_gh3) / 1000) * 256; 538 472 var2 = (calib->par_gh1 + 784) * (((((calib->par_gh2 + 154009) * 539 473 temp * 5) / 100) 540 474 + 3276800) / 10); ··· 568 502 return durval; 569 503 } 570 504 571 - static int bme680_set_mode(struct bme680_data *data, bool mode) 505 + /* Taken from datasheet, section 5.3.3 */ 506 + static u8 bme680_calc_heater_preheat_current(u8 curr) 507 + { 508 + return 8 * curr - 1; 509 + } 510 + 511 + static int bme680_set_mode(struct bme680_data *data, enum bme680_op_mode mode) 572 512 { 573 513 struct device *dev = regmap_get_device(data->regmap); 574 514 int ret; 575 515 576 - if (mode) { 577 - ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS, 578 - BME680_MODE_MASK, BME680_MODE_FORCED); 579 - if (ret < 0) 580 - dev_err(dev, "failed to set forced mode\n"); 581 - 582 - } else { 583 - ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS, 584 - BME680_MODE_MASK, BME680_MODE_SLEEP); 585 - if (ret < 0) 586 - dev_err(dev, "failed to set sleep mode\n"); 587 - 516 + ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS, 517 + BME680_MODE_MASK, mode); 518 + if (ret < 0) { 519 + dev_err(dev, "failed to set ctrl_meas register\n"); 520 + return ret; 588 521 } 589 522 590 523 return ret; ··· 611 546 data->oversampling_humid) * 1936) + (477 * 4) + 612 547 (477 * 5) + 1000 + (data->heater_dur * 1000); 613 548 614 - usleep_range(wait_eoc_us, wait_eoc_us + 100); 549 + fsleep(wait_eoc_us); 615 550 616 551 ret = regmap_read(data->regmap, BME680_REG_MEAS_STAT_0, &data->check); 617 552 if (ret) { ··· 636 571 int ret; 637 572 u8 osrs; 638 573 639 - osrs = FIELD_PREP( 640 - BME680_OSRS_HUMIDITY_MASK, 641 - bme680_oversampling_to_reg(data->oversampling_humid)); 574 + osrs = FIELD_PREP(BME680_OSRS_HUMIDITY_MASK, 575 + bme680_oversampling_to_reg(data->oversampling_humid)); 642 576 /* 643 577 * Highly recommended to set oversampling of humidity before 644 578 * temperature/pressure oversampling. ··· 651 587 652 588 /* IIR filter settings */ 653 589 ret = regmap_update_bits(data->regmap, BME680_REG_CONFIG, 654 - BME680_FILTER_MASK, 655 - BME680_FILTER_COEFF_VAL); 590 + BME680_FILTER_MASK, BME680_FILTER_COEFF_VAL); 656 591 if (ret < 0) { 657 592 dev_err(dev, "failed to write config register\n"); 658 593 return ret; ··· 672 609 return 0; 673 610 } 674 611 612 + static int bme680_preheat_curr_config(struct bme680_data *data, u8 val) 613 + { 614 + struct device *dev = regmap_get_device(data->regmap); 615 + u8 heatr_curr; 616 + int ret; 617 + 618 + heatr_curr = bme680_calc_heater_preheat_current(val); 619 + ret = regmap_write(data->regmap, BME680_REG_IDAC_HEAT_0, heatr_curr); 620 + if (ret < 0) 621 + dev_err(dev, "failed to write idac_heat_0 register\n"); 622 + 623 + return ret; 624 + } 625 + 675 626 static int bme680_gas_config(struct bme680_data *data) 676 627 { 677 628 struct device *dev = regmap_get_device(data->regmap); 678 629 int ret; 679 630 u8 heatr_res, heatr_dur; 680 631 681 - /* Go to sleep */ 682 - ret = bme680_set_mode(data, false); 632 + ret = bme680_set_mode(data, BME680_MODE_SLEEP); 683 633 if (ret < 0) 684 634 return ret; 685 635 ··· 714 638 return ret; 715 639 } 716 640 641 + ret = bme680_preheat_curr_config(data, data->preheat_curr_mA); 642 + if (ret) 643 + return ret; 644 + 717 645 /* Enable the gas sensor and select heater profile set-point 0 */ 718 646 ret = regmap_update_bits(data->regmap, BME680_REG_CTRL_GAS_1, 719 647 BME680_RUN_GAS_MASK | BME680_NB_CONV_MASK, ··· 729 649 return ret; 730 650 } 731 651 732 - static int bme680_read_temp(struct bme680_data *data, int *val) 652 + static int bme680_read_temp(struct bme680_data *data, s16 *comp_temp) 733 653 { 734 654 int ret; 735 655 u32 adc_temp; 736 - s16 comp_temp; 737 656 738 657 ret = bme680_read_temp_adc(data, &adc_temp); 739 658 if (ret) 740 659 return ret; 741 660 742 - comp_temp = bme680_compensate_temp(data, adc_temp); 743 - *val = comp_temp * 10; /* Centidegrees to millidegrees */ 744 - return IIO_VAL_INT; 661 + *comp_temp = bme680_compensate_temp(data, adc_temp); 662 + return 0; 745 663 } 746 664 747 - static int bme680_read_press(struct bme680_data *data, 748 - int *val, int *val2) 665 + static int bme680_read_press(struct bme680_data *data, u32 *comp_press) 749 666 { 750 667 int ret; 751 668 u32 adc_press; ··· 756 679 if (ret) 757 680 return ret; 758 681 759 - *val = bme680_compensate_press(data, adc_press, t_fine); 760 - *val2 = 1000; 761 - return IIO_VAL_FRACTIONAL; 682 + *comp_press = bme680_compensate_press(data, adc_press, t_fine); 683 + return 0; 762 684 } 763 685 764 - static int bme680_read_humid(struct bme680_data *data, 765 - int *val, int *val2) 686 + static int bme680_read_humid(struct bme680_data *data, u32 *comp_humidity) 766 687 { 767 688 int ret; 768 - u32 adc_humidity, comp_humidity; 689 + u32 adc_humidity; 769 690 s32 t_fine; 770 691 771 692 ret = bme680_get_t_fine(data, &t_fine); ··· 774 699 if (ret) 775 700 return ret; 776 701 777 - comp_humidity = bme680_compensate_humid(data, adc_humidity, t_fine); 778 - 779 - *val = comp_humidity; 780 - *val2 = 1000; 781 - return IIO_VAL_FRACTIONAL; 702 + *comp_humidity = bme680_compensate_humid(data, adc_humidity, t_fine); 703 + return 0; 782 704 } 783 705 784 - static int bme680_read_gas(struct bme680_data *data, 785 - int *val) 706 + static int bme680_read_gas(struct bme680_data *data, int *comp_gas_res) 786 707 { 787 708 struct device *dev = regmap_get_device(data->regmap); 788 709 int ret; ··· 813 742 } 814 743 815 744 gas_range = FIELD_GET(BME680_GAS_RANGE_MASK, gas_regs_val); 816 - 817 - *val = bme680_compensate_gas(data, adc_gas_res, gas_range); 818 - return IIO_VAL_INT; 745 + *comp_gas_res = bme680_compensate_gas(data, adc_gas_res, gas_range); 746 + return 0; 819 747 } 820 748 821 749 static int bme680_read_raw(struct iio_dev *indio_dev, ··· 822 752 int *val, int *val2, long mask) 823 753 { 824 754 struct bme680_data *data = iio_priv(indio_dev); 825 - int ret; 755 + int chan_val, ret; 756 + s16 temp_chan_val; 826 757 827 758 guard(mutex)(&data->lock); 828 759 829 - /* set forced mode to trigger measurement */ 830 - ret = bme680_set_mode(data, true); 760 + ret = bme680_set_mode(data, BME680_MODE_FORCED); 831 761 if (ret < 0) 832 762 return ret; 833 763 ··· 839 769 case IIO_CHAN_INFO_PROCESSED: 840 770 switch (chan->type) { 841 771 case IIO_TEMP: 842 - return bme680_read_temp(data, val); 772 + ret = bme680_read_temp(data, &temp_chan_val); 773 + if (ret) 774 + return ret; 775 + 776 + *val = temp_chan_val * 10; 777 + return IIO_VAL_INT; 843 778 case IIO_PRESSURE: 844 - return bme680_read_press(data, val, val2); 779 + ret = bme680_read_press(data, &chan_val); 780 + if (ret) 781 + return ret; 782 + 783 + *val = chan_val; 784 + *val2 = 1000; 785 + return IIO_VAL_FRACTIONAL; 845 786 case IIO_HUMIDITYRELATIVE: 846 - return bme680_read_humid(data, val, val2); 787 + ret = bme680_read_humid(data, &chan_val); 788 + if (ret) 789 + return ret; 790 + 791 + *val = chan_val; 792 + *val2 = 1000; 793 + return IIO_VAL_FRACTIONAL; 847 794 case IIO_RESISTANCE: 848 - return bme680_read_gas(data, val); 795 + ret = bme680_read_gas(data, &chan_val); 796 + if (ret) 797 + return ret; 798 + 799 + *val = chan_val; 800 + return IIO_VAL_INT; 801 + default: 802 + return -EINVAL; 803 + } 804 + case IIO_CHAN_INFO_RAW: 805 + switch (chan->type) { 806 + case IIO_TEMP: 807 + ret = bme680_read_temp(data, (s16 *)&chan_val); 808 + if (ret) 809 + return ret; 810 + 811 + *val = chan_val; 812 + return IIO_VAL_INT; 813 + case IIO_PRESSURE: 814 + ret = bme680_read_press(data, &chan_val); 815 + if (ret) 816 + return ret; 817 + 818 + *val = chan_val; 819 + return IIO_VAL_INT; 820 + case IIO_HUMIDITYRELATIVE: 821 + ret = bme680_read_humid(data, &chan_val); 822 + if (ret) 823 + return ret; 824 + 825 + *val = chan_val; 826 + return IIO_VAL_INT; 827 + default: 828 + return -EINVAL; 829 + } 830 + case IIO_CHAN_INFO_SCALE: 831 + switch (chan->type) { 832 + case IIO_TEMP: 833 + *val = 10; 834 + return IIO_VAL_INT; 835 + case IIO_PRESSURE: 836 + *val = 1; 837 + *val2 = 1000; 838 + return IIO_VAL_FRACTIONAL; 839 + case IIO_HUMIDITYRELATIVE: 840 + *val = 1; 841 + *val2 = 1000; 842 + return IIO_VAL_FRACTIONAL; 849 843 default: 850 844 return -EINVAL; 851 845 } ··· 970 836 971 837 return bme680_chip_config(data); 972 838 } 839 + case IIO_CHAN_INFO_PROCESSED: 840 + { 841 + switch (chan->type) { 842 + case IIO_CURRENT: 843 + return bme680_preheat_curr_config(data, (u8)val); 844 + default: 845 + return -EINVAL; 846 + } 847 + } 973 848 default: 974 849 return -EINVAL; 975 850 } ··· 1004 861 .attrs = &bme680_attribute_group, 1005 862 }; 1006 863 864 + static const unsigned long bme680_avail_scan_masks[] = { 865 + BIT(BME680_GAS) | BIT(BME680_HUMID) | BIT(BME680_PRESS) | BIT(BME680_TEMP), 866 + 0 867 + }; 868 + 869 + static irqreturn_t bme680_trigger_handler(int irq, void *p) 870 + { 871 + struct iio_poll_func *pf = p; 872 + struct iio_dev *indio_dev = pf->indio_dev; 873 + struct bme680_data *data = iio_priv(indio_dev); 874 + struct device *dev = regmap_get_device(data->regmap); 875 + u32 adc_temp, adc_press, adc_humid; 876 + u16 adc_gas_res, gas_regs_val; 877 + u8 gas_range; 878 + s32 t_fine; 879 + int ret; 880 + 881 + guard(mutex)(&data->lock); 882 + 883 + ret = bme680_set_mode(data, BME680_MODE_FORCED); 884 + if (ret < 0) 885 + goto out; 886 + 887 + ret = bme680_wait_for_eoc(data); 888 + if (ret) 889 + goto out; 890 + 891 + ret = regmap_bulk_read(data->regmap, BME680_REG_MEAS_STAT_0, 892 + data->buf, sizeof(data->buf)); 893 + if (ret) { 894 + dev_err(dev, "failed to burst read sensor data\n"); 895 + goto out; 896 + } 897 + if (data->buf[0] & BME680_GAS_MEAS_BIT) { 898 + dev_err(dev, "gas measurement incomplete\n"); 899 + goto out; 900 + } 901 + 902 + /* Temperature calculations */ 903 + adc_temp = FIELD_GET(BME680_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[5])); 904 + if (adc_temp == BME680_MEAS_SKIPPED) { 905 + dev_err(dev, "reading temperature skipped\n"); 906 + goto out; 907 + } 908 + data->scan.chan[0] = bme680_compensate_temp(data, adc_temp); 909 + t_fine = bme680_calc_t_fine(data, adc_temp); 910 + 911 + /* Pressure calculations */ 912 + adc_press = FIELD_GET(BME680_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[2])); 913 + if (adc_press == BME680_MEAS_SKIPPED) { 914 + dev_err(dev, "reading pressure skipped\n"); 915 + goto out; 916 + } 917 + data->scan.chan[1] = bme680_compensate_press(data, adc_press, t_fine); 918 + 919 + /* Humidity calculations */ 920 + adc_humid = get_unaligned_be16(&data->buf[8]); 921 + if (adc_humid == BME680_MEAS_SKIPPED) { 922 + dev_err(dev, "reading humidity skipped\n"); 923 + goto out; 924 + } 925 + data->scan.chan[2] = bme680_compensate_humid(data, adc_humid, t_fine); 926 + 927 + /* Gas calculations */ 928 + gas_regs_val = get_unaligned_be16(&data->buf[13]); 929 + adc_gas_res = FIELD_GET(BME680_ADC_GAS_RES, gas_regs_val); 930 + if ((gas_regs_val & BME680_GAS_STAB_BIT) == 0) { 931 + dev_err(dev, "heater failed to reach the target temperature\n"); 932 + goto out; 933 + } 934 + gas_range = FIELD_GET(BME680_GAS_RANGE_MASK, gas_regs_val); 935 + data->scan.chan[3] = bme680_compensate_gas(data, adc_gas_res, gas_range); 936 + 937 + iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, 938 + iio_get_time_ns(indio_dev)); 939 + out: 940 + iio_trigger_notify_done(indio_dev->trig); 941 + return IRQ_HANDLED; 942 + } 943 + 1007 944 int bme680_core_probe(struct device *dev, struct regmap *regmap, 1008 945 const char *name) 1009 946 { ··· 1102 879 indio_dev->name = name; 1103 880 indio_dev->channels = bme680_channels; 1104 881 indio_dev->num_channels = ARRAY_SIZE(bme680_channels); 882 + indio_dev->available_scan_masks = bme680_avail_scan_masks; 1105 883 indio_dev->info = &bme680_info; 1106 884 indio_dev->modes = INDIO_DIRECT_MODE; 1107 885 ··· 1112 888 data->oversampling_temp = 8; /* 8X oversampling rate */ 1113 889 data->heater_temp = 320; /* degree Celsius */ 1114 890 data->heater_dur = 150; /* milliseconds */ 891 + data->preheat_curr_mA = 0; 1115 892 1116 - ret = regmap_write(regmap, BME680_REG_SOFT_RESET, 1117 - BME680_CMD_SOFTRESET); 893 + ret = regmap_write(regmap, BME680_REG_SOFT_RESET, BME680_CMD_SOFTRESET); 1118 894 if (ret < 0) 1119 895 return dev_err_probe(dev, ret, "Failed to reset chip\n"); 1120 896 1121 - usleep_range(BME680_STARTUP_TIME_US, BME680_STARTUP_TIME_US + 1000); 897 + fsleep(BME680_STARTUP_TIME_US); 1122 898 1123 899 ret = regmap_read(regmap, BME680_REG_CHIP_ID, &data->check); 1124 900 if (ret < 0) ··· 1145 921 if (ret < 0) 1146 922 return dev_err_probe(dev, ret, 1147 923 "failed to set gas config data\n"); 924 + 925 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 926 + iio_pollfunc_store_time, 927 + bme680_trigger_handler, 928 + NULL); 929 + if (ret) 930 + return dev_err_probe(dev, ret, 931 + "iio triggered buffer setup failed\n"); 1148 932 1149 933 return devm_iio_device_register(dev, indio_dev); 1150 934 }
+19
drivers/iio/dac/Kconfig
··· 6 6 7 7 menu "Digital to analog converters" 8 8 9 + config AD3552R_HS 10 + tristate "Analog Devices AD3552R DAC High Speed driver" 11 + select AD3552R_LIB 12 + select IIO_BACKEND 13 + help 14 + Say yes here to build support for Analog Devices AD3552R 15 + Digital to Analog Converter High Speed driver. 16 + 17 + The driver requires the assistance of an IP core to operate, 18 + since data is streamed into target device via DMA, sent over a 19 + QSPI + DDR (Double Data Rate) bus. 20 + 21 + To compile this driver as a module, choose M here: the 22 + module will be called ad3552r-hs. 23 + 24 + config AD3552R_LIB 25 + tristate 26 + 9 27 config AD3552R 10 28 tristate "Analog Devices AD3552R DAC driver" 11 29 depends on SPI_MASTER 30 + select AD3552R_LIB 12 31 select IIO_BUFFER 13 32 select IIO_TRIGGERED_BUFFER 14 33 help
+2
drivers/iio/dac/Makefile
··· 4 4 # 5 5 6 6 # When adding new entries keep the list in alphabetical order 7 + obj-$(CONFIG_AD3552R_HS) += ad3552r-hs.o 8 + obj-$(CONFIG_AD3552R_LIB) += ad3552r-common.o 7 9 obj-$(CONFIG_AD3552R) += ad3552r.o 8 10 obj-$(CONFIG_AD5360) += ad5360.o 9 11 obj-$(CONFIG_AD5380) += ad5380.o
+249
drivers/iio/dac/ad3552r-common.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + // 3 + // Copyright (c) 2010-2024 Analog Devices Inc. 4 + // Copyright (c) 2024 Baylibre, SAS 5 + 6 + #include <linux/bitfield.h> 7 + #include <linux/device.h> 8 + #include <linux/module.h> 9 + #include <linux/property.h> 10 + #include <linux/regulator/consumer.h> 11 + 12 + #include "ad3552r.h" 13 + 14 + const s32 ad3552r_ch_ranges[AD3552R_MAX_RANGES][2] = { 15 + [AD3552R_CH_OUTPUT_RANGE_0__2P5V] = { 0, 2500 }, 16 + [AD3552R_CH_OUTPUT_RANGE_0__5V] = { 0, 5000 }, 17 + [AD3552R_CH_OUTPUT_RANGE_0__10V] = { 0, 10000 }, 18 + [AD3552R_CH_OUTPUT_RANGE_NEG_5__5V] = { -5000, 5000 }, 19 + [AD3552R_CH_OUTPUT_RANGE_NEG_10__10V] = { -10000, 10000 } 20 + }; 21 + EXPORT_SYMBOL_NS_GPL(ad3552r_ch_ranges, IIO_AD3552R); 22 + 23 + const s32 ad3542r_ch_ranges[AD3542R_MAX_RANGES][2] = { 24 + [AD3542R_CH_OUTPUT_RANGE_0__2P5V] = { 0, 2500 }, 25 + [AD3542R_CH_OUTPUT_RANGE_0__3V] = { 0, 3000 }, 26 + [AD3542R_CH_OUTPUT_RANGE_0__5V] = { 0, 5000 }, 27 + [AD3542R_CH_OUTPUT_RANGE_0__10V] = { 0, 10000 }, 28 + [AD3542R_CH_OUTPUT_RANGE_NEG_2P5__7P5V] = { -2500, 7500 }, 29 + [AD3542R_CH_OUTPUT_RANGE_NEG_5__5V] = { -5000, 5000 } 30 + }; 31 + EXPORT_SYMBOL_NS_GPL(ad3542r_ch_ranges, IIO_AD3552R); 32 + 33 + /* Gain * AD3552R_GAIN_SCALE */ 34 + static const s32 gains_scaling_table[] = { 35 + [AD3552R_CH_GAIN_SCALING_1] = 1000, 36 + [AD3552R_CH_GAIN_SCALING_0_5] = 500, 37 + [AD3552R_CH_GAIN_SCALING_0_25] = 250, 38 + [AD3552R_CH_GAIN_SCALING_0_125] = 125 39 + }; 40 + 41 + u16 ad3552r_calc_custom_gain(u8 p, u8 n, s16 goffs) 42 + { 43 + return FIELD_PREP(AD3552R_MASK_CH_RANGE_OVERRIDE, 1) | 44 + FIELD_PREP(AD3552R_MASK_CH_GAIN_SCALING_P, p) | 45 + FIELD_PREP(AD3552R_MASK_CH_GAIN_SCALING_N, n) | 46 + FIELD_PREP(AD3552R_MASK_CH_OFFSET_BIT_8, abs(goffs)) | 47 + FIELD_PREP(AD3552R_MASK_CH_OFFSET_POLARITY, goffs < 0); 48 + } 49 + EXPORT_SYMBOL_NS_GPL(ad3552r_calc_custom_gain, IIO_AD3552R); 50 + 51 + static void ad3552r_get_custom_range(struct ad3552r_ch_data *ch_data, 52 + s32 *v_min, s32 *v_max) 53 + { 54 + s64 vref, tmp, common, offset, gn, gp; 55 + /* 56 + * From datasheet formula (In Volts): 57 + * Vmin = 2.5 + [(GainN + Offset / 1024) * 2.5 * Rfb * 1.03] 58 + * Vmax = 2.5 - [(GainP + Offset / 1024) * 2.5 * Rfb * 1.03] 59 + * Calculus are converted to milivolts 60 + */ 61 + vref = 2500; 62 + /* 2.5 * 1.03 * 1000 (To mV) */ 63 + common = 2575 * ch_data->rfb; 64 + offset = ch_data->gain_offset; 65 + 66 + gn = gains_scaling_table[ch_data->n]; 67 + tmp = (1024 * gn + AD3552R_GAIN_SCALE * offset) * common; 68 + tmp = div_s64(tmp, 1024 * AD3552R_GAIN_SCALE); 69 + *v_max = vref + tmp; 70 + 71 + gp = gains_scaling_table[ch_data->p]; 72 + tmp = (1024 * gp - AD3552R_GAIN_SCALE * offset) * common; 73 + tmp = div_s64(tmp, 1024 * AD3552R_GAIN_SCALE); 74 + *v_min = vref - tmp; 75 + } 76 + 77 + void ad3552r_calc_gain_and_offset(struct ad3552r_ch_data *ch_data, 78 + const struct ad3552r_model_data *model_data) 79 + { 80 + s32 idx, v_max, v_min, span, rem; 81 + s64 tmp; 82 + 83 + if (ch_data->range_override) { 84 + ad3552r_get_custom_range(ch_data, &v_min, &v_max); 85 + } else { 86 + /* Normal range */ 87 + idx = ch_data->range; 88 + v_min = model_data->ranges_table[idx][0]; 89 + v_max = model_data->ranges_table[idx][1]; 90 + } 91 + 92 + /* 93 + * From datasheet formula: 94 + * Vout = Span * (D / 65536) + Vmin 95 + * Converted to scale and offset: 96 + * Scale = Span / 65536 97 + * Offset = 65536 * Vmin / Span 98 + * 99 + * Reminders are in micros in order to be printed as 100 + * IIO_VAL_INT_PLUS_MICRO 101 + */ 102 + span = v_max - v_min; 103 + ch_data->scale_int = div_s64_rem(span, 65536, &rem); 104 + /* Do operations in microvolts */ 105 + ch_data->scale_dec = DIV_ROUND_CLOSEST((s64)rem * 1000000, 65536); 106 + 107 + ch_data->offset_int = div_s64_rem(v_min * 65536, span, &rem); 108 + tmp = (s64)rem * 1000000; 109 + ch_data->offset_dec = div_s64(tmp, span); 110 + } 111 + EXPORT_SYMBOL_NS_GPL(ad3552r_calc_gain_and_offset, IIO_AD3552R); 112 + 113 + int ad3552r_get_ref_voltage(struct device *dev, u32 *val) 114 + { 115 + int voltage; 116 + int delta = 100000; 117 + 118 + voltage = devm_regulator_get_enable_read_voltage(dev, "vref"); 119 + if (voltage < 0 && voltage != -ENODEV) 120 + return dev_err_probe(dev, voltage, 121 + "Error getting vref voltage\n"); 122 + 123 + if (voltage == -ENODEV) { 124 + if (device_property_read_bool(dev, "adi,vref-out-en")) 125 + *val = AD3552R_INTERNAL_VREF_PIN_2P5V; 126 + else 127 + *val = AD3552R_INTERNAL_VREF_PIN_FLOATING; 128 + 129 + return 0; 130 + } 131 + 132 + if (voltage > 2500000 + delta || voltage < 2500000 - delta) { 133 + dev_warn(dev, "vref-supply must be 2.5V"); 134 + return -EINVAL; 135 + } 136 + 137 + *val = AD3552R_EXTERNAL_VREF_PIN_INPUT; 138 + 139 + return 0; 140 + } 141 + EXPORT_SYMBOL_NS_GPL(ad3552r_get_ref_voltage, IIO_AD3552R); 142 + 143 + int ad3552r_get_drive_strength(struct device *dev, u32 *val) 144 + { 145 + int err; 146 + u32 drive_strength; 147 + 148 + err = device_property_read_u32(dev, "adi,sdo-drive-strength", 149 + &drive_strength); 150 + if (err) 151 + return err; 152 + 153 + if (drive_strength > 3) { 154 + dev_err_probe(dev, -EINVAL, 155 + "adi,sdo-drive-strength must be less than 4\n"); 156 + return -EINVAL; 157 + } 158 + 159 + *val = drive_strength; 160 + 161 + return 0; 162 + } 163 + EXPORT_SYMBOL_NS_GPL(ad3552r_get_drive_strength, IIO_AD3552R); 164 + 165 + int ad3552r_get_custom_gain(struct device *dev, struct fwnode_handle *child, 166 + u8 *gs_p, u8 *gs_n, u16 *rfb, s16 *goffs) 167 + { 168 + int err; 169 + u32 val; 170 + struct fwnode_handle *gain_child __free(fwnode_handle) = 171 + fwnode_get_named_child_node(child, 172 + "custom-output-range-config"); 173 + 174 + if (!gain_child) 175 + return dev_err_probe(dev, -EINVAL, 176 + "custom-output-range-config mandatory\n"); 177 + 178 + err = fwnode_property_read_u32(gain_child, "adi,gain-scaling-p", &val); 179 + if (err) 180 + return dev_err_probe(dev, err, 181 + "adi,gain-scaling-p mandatory\n"); 182 + *gs_p = val; 183 + 184 + err = fwnode_property_read_u32(gain_child, "adi,gain-scaling-n", &val); 185 + if (err) 186 + return dev_err_probe(dev, err, 187 + "adi,gain-scaling-n property mandatory\n"); 188 + *gs_n = val; 189 + 190 + err = fwnode_property_read_u32(gain_child, "adi,rfb-ohms", &val); 191 + if (err) 192 + return dev_err_probe(dev, err, 193 + "adi,rfb-ohms mandatory\n"); 194 + *rfb = val; 195 + 196 + err = fwnode_property_read_u32(gain_child, "adi,gain-offset", &val); 197 + if (err) 198 + return dev_err_probe(dev, err, 199 + "adi,gain-offset mandatory\n"); 200 + *goffs = val; 201 + 202 + return 0; 203 + } 204 + EXPORT_SYMBOL_NS_GPL(ad3552r_get_custom_gain, IIO_AD3552R); 205 + 206 + static int ad3552r_find_range(const struct ad3552r_model_data *model_info, 207 + s32 *vals) 208 + { 209 + int i; 210 + 211 + for (i = 0; i < model_info->num_ranges; i++) 212 + if (vals[0] == model_info->ranges_table[i][0] * 1000 && 213 + vals[1] == model_info->ranges_table[i][1] * 1000) 214 + return i; 215 + 216 + return -EINVAL; 217 + } 218 + 219 + int ad3552r_get_output_range(struct device *dev, 220 + const struct ad3552r_model_data *model_info, 221 + struct fwnode_handle *child, u32 *val) 222 + { 223 + int ret; 224 + s32 vals[2]; 225 + 226 + /* This property is optional, so returning -ENOENT if missing */ 227 + if (!fwnode_property_present(child, "adi,output-range-microvolt")) 228 + return -ENOENT; 229 + 230 + ret = fwnode_property_read_u32_array(child, 231 + "adi,output-range-microvolt", 232 + vals, 2); 233 + if (ret) 234 + return dev_err_probe(dev, ret, 235 + "invalid adi,output-range-microvolt\n"); 236 + 237 + ret = ad3552r_find_range(model_info, vals); 238 + if (ret < 0) 239 + return dev_err_probe(dev, ret, 240 + "invalid adi,output-range-microvolt value\n"); 241 + 242 + *val = ret; 243 + 244 + return 0; 245 + } 246 + EXPORT_SYMBOL_NS_GPL(ad3552r_get_output_range, IIO_AD3552R); 247 + 248 + MODULE_DESCRIPTION("ad3552r common functions"); 249 + MODULE_LICENSE("GPL");
+529
drivers/iio/dac/ad3552r-hs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Analog Devices AD3552R 4 + * Digital to Analog converter driver, High Speed version 5 + * 6 + * Copyright 2024 Analog Devices Inc. 7 + */ 8 + 9 + #include <linux/bitfield.h> 10 + #include <linux/delay.h> 11 + #include <linux/gpio/consumer.h> 12 + #include <linux/iio/backend.h> 13 + #include <linux/iio/buffer.h> 14 + #include <linux/mod_devicetable.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/property.h> 17 + #include <linux/units.h> 18 + 19 + #include "ad3552r.h" 20 + #include "ad3552r-hs.h" 21 + 22 + struct ad3552r_hs_state { 23 + const struct ad3552r_model_data *model_data; 24 + struct gpio_desc *reset_gpio; 25 + struct device *dev; 26 + struct iio_backend *back; 27 + bool single_channel; 28 + struct ad3552r_ch_data ch_data[AD3552R_MAX_CH]; 29 + struct ad3552r_hs_platform_data *data; 30 + }; 31 + 32 + static int ad3552r_qspi_update_reg_bits(struct ad3552r_hs_state *st, 33 + u32 reg, u32 mask, u32 val, 34 + size_t xfer_size) 35 + { 36 + u32 rval; 37 + int ret; 38 + 39 + ret = st->data->bus_reg_read(st->back, reg, &rval, xfer_size); 40 + if (ret) 41 + return ret; 42 + 43 + rval = (rval & ~mask) | val; 44 + 45 + return st->data->bus_reg_write(st->back, reg, rval, xfer_size); 46 + } 47 + 48 + static int ad3552r_hs_read_raw(struct iio_dev *indio_dev, 49 + struct iio_chan_spec const *chan, 50 + int *val, int *val2, long mask) 51 + { 52 + struct ad3552r_hs_state *st = iio_priv(indio_dev); 53 + int ret; 54 + int ch = chan->channel; 55 + 56 + switch (mask) { 57 + case IIO_CHAN_INFO_SAMP_FREQ: 58 + /* 59 + * Using 4 lanes (QSPI), then using 2 as DDR mode is 60 + * considered always on (considering buffering mode always). 61 + */ 62 + *val = DIV_ROUND_CLOSEST(st->data->bus_sample_data_clock_hz * 63 + 4 * 2, chan->scan_type.realbits); 64 + 65 + return IIO_VAL_INT; 66 + 67 + case IIO_CHAN_INFO_RAW: 68 + ret = st->data->bus_reg_read(st->back, 69 + AD3552R_REG_ADDR_CH_DAC_16B(chan->channel), 70 + val, 2); 71 + if (ret) 72 + return ret; 73 + 74 + return IIO_VAL_INT; 75 + case IIO_CHAN_INFO_SCALE: 76 + *val = st->ch_data[ch].scale_int; 77 + *val2 = st->ch_data[ch].scale_dec; 78 + return IIO_VAL_INT_PLUS_MICRO; 79 + case IIO_CHAN_INFO_OFFSET: 80 + *val = st->ch_data[ch].offset_int; 81 + *val2 = st->ch_data[ch].offset_dec; 82 + return IIO_VAL_INT_PLUS_MICRO; 83 + default: 84 + return -EINVAL; 85 + } 86 + } 87 + 88 + static int ad3552r_hs_write_raw(struct iio_dev *indio_dev, 89 + struct iio_chan_spec const *chan, 90 + int val, int val2, long mask) 91 + { 92 + struct ad3552r_hs_state *st = iio_priv(indio_dev); 93 + 94 + switch (mask) { 95 + case IIO_CHAN_INFO_RAW: 96 + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 97 + return st->data->bus_reg_write(st->back, 98 + AD3552R_REG_ADDR_CH_DAC_16B(chan->channel), 99 + val, 2); 100 + } 101 + unreachable(); 102 + default: 103 + return -EINVAL; 104 + } 105 + } 106 + 107 + static int ad3552r_hs_buffer_postenable(struct iio_dev *indio_dev) 108 + { 109 + struct ad3552r_hs_state *st = iio_priv(indio_dev); 110 + struct iio_backend_data_fmt fmt = { 111 + .type = IIO_BACKEND_DATA_UNSIGNED 112 + }; 113 + int loop_len, val, ret; 114 + 115 + switch (*indio_dev->active_scan_mask) { 116 + case AD3552R_CH0_ACTIVE: 117 + st->single_channel = true; 118 + loop_len = 2; 119 + val = AD3552R_REG_ADDR_CH_DAC_16B(0); 120 + break; 121 + case AD3552R_CH1_ACTIVE: 122 + st->single_channel = true; 123 + loop_len = 2; 124 + val = AD3552R_REG_ADDR_CH_DAC_16B(1); 125 + break; 126 + case AD3552R_CH0_ACTIVE | AD3552R_CH1_ACTIVE: 127 + st->single_channel = false; 128 + loop_len = 4; 129 + val = AD3552R_REG_ADDR_CH_DAC_16B(1); 130 + break; 131 + default: 132 + return -EINVAL; 133 + } 134 + 135 + ret = st->data->bus_reg_write(st->back, AD3552R_REG_ADDR_STREAM_MODE, 136 + loop_len, 1); 137 + if (ret) 138 + return ret; 139 + 140 + /* Inform DAC chip to switch into DDR mode */ 141 + ret = ad3552r_qspi_update_reg_bits(st, 142 + AD3552R_REG_ADDR_INTERFACE_CONFIG_D, 143 + AD3552R_MASK_SPI_CONFIG_DDR, 144 + AD3552R_MASK_SPI_CONFIG_DDR, 1); 145 + if (ret) 146 + return ret; 147 + 148 + /* Inform DAC IP to go for DDR mode from now on */ 149 + ret = iio_backend_ddr_enable(st->back); 150 + if (ret) { 151 + dev_err(st->dev, "could not set DDR mode, not streaming"); 152 + goto exit_err; 153 + } 154 + 155 + ret = iio_backend_data_transfer_addr(st->back, val); 156 + if (ret) 157 + goto exit_err; 158 + 159 + ret = iio_backend_data_format_set(st->back, 0, &fmt); 160 + if (ret) 161 + goto exit_err; 162 + 163 + ret = iio_backend_data_stream_enable(st->back); 164 + if (ret) 165 + goto exit_err; 166 + 167 + return 0; 168 + 169 + exit_err: 170 + ad3552r_qspi_update_reg_bits(st, 171 + AD3552R_REG_ADDR_INTERFACE_CONFIG_D, 172 + AD3552R_MASK_SPI_CONFIG_DDR, 173 + 0, 1); 174 + 175 + iio_backend_ddr_disable(st->back); 176 + 177 + return ret; 178 + } 179 + 180 + static int ad3552r_hs_buffer_predisable(struct iio_dev *indio_dev) 181 + { 182 + struct ad3552r_hs_state *st = iio_priv(indio_dev); 183 + int ret; 184 + 185 + ret = iio_backend_data_stream_disable(st->back); 186 + if (ret) 187 + return ret; 188 + 189 + /* Inform DAC to set in SDR mode */ 190 + ret = ad3552r_qspi_update_reg_bits(st, 191 + AD3552R_REG_ADDR_INTERFACE_CONFIG_D, 192 + AD3552R_MASK_SPI_CONFIG_DDR, 193 + 0, 1); 194 + if (ret) 195 + return ret; 196 + 197 + ret = iio_backend_ddr_disable(st->back); 198 + if (ret) 199 + return ret; 200 + 201 + return 0; 202 + } 203 + 204 + static inline int ad3552r_hs_set_output_range(struct ad3552r_hs_state *st, 205 + int ch, unsigned int mode) 206 + { 207 + int val; 208 + 209 + if (ch == 0) 210 + val = FIELD_PREP(AD3552R_MASK_CH0_RANGE, mode); 211 + else 212 + val = FIELD_PREP(AD3552R_MASK_CH1_RANGE, mode); 213 + 214 + return ad3552r_qspi_update_reg_bits(st, 215 + AD3552R_REG_ADDR_CH0_CH1_OUTPUT_RANGE, 216 + AD3552R_MASK_CH_OUTPUT_RANGE_SEL(ch), 217 + val, 1); 218 + } 219 + 220 + static int ad3552r_hs_reset(struct ad3552r_hs_state *st) 221 + { 222 + int ret; 223 + 224 + st->reset_gpio = devm_gpiod_get_optional(st->dev, 225 + "reset", GPIOD_OUT_HIGH); 226 + if (IS_ERR(st->reset_gpio)) 227 + return PTR_ERR(st->reset_gpio); 228 + 229 + if (st->reset_gpio) { 230 + fsleep(10); 231 + gpiod_set_value_cansleep(st->reset_gpio, 0); 232 + } else { 233 + ret = ad3552r_qspi_update_reg_bits(st, 234 + AD3552R_REG_ADDR_INTERFACE_CONFIG_A, 235 + AD3552R_MASK_SOFTWARE_RESET, 236 + AD3552R_MASK_SOFTWARE_RESET, 1); 237 + if (ret) 238 + return ret; 239 + } 240 + msleep(100); 241 + 242 + return 0; 243 + } 244 + 245 + static int ad3552r_hs_scratch_pad_test(struct ad3552r_hs_state *st) 246 + { 247 + int ret, val; 248 + 249 + ret = st->data->bus_reg_write(st->back, AD3552R_REG_ADDR_SCRATCH_PAD, 250 + AD3552R_SCRATCH_PAD_TEST_VAL1, 1); 251 + if (ret) 252 + return ret; 253 + 254 + ret = st->data->bus_reg_read(st->back, AD3552R_REG_ADDR_SCRATCH_PAD, 255 + &val, 1); 256 + if (ret) 257 + return ret; 258 + 259 + if (val != AD3552R_SCRATCH_PAD_TEST_VAL1) 260 + return dev_err_probe(st->dev, -EIO, 261 + "SCRATCH_PAD_TEST mismatch. Expected 0x%x, Read 0x%x\n", 262 + AD3552R_SCRATCH_PAD_TEST_VAL1, val); 263 + 264 + ret = st->data->bus_reg_write(st->back, AD3552R_REG_ADDR_SCRATCH_PAD, 265 + AD3552R_SCRATCH_PAD_TEST_VAL2, 1); 266 + if (ret) 267 + return ret; 268 + 269 + ret = st->data->bus_reg_read(st->back, AD3552R_REG_ADDR_SCRATCH_PAD, 270 + &val, 1); 271 + if (ret) 272 + return ret; 273 + 274 + if (val != AD3552R_SCRATCH_PAD_TEST_VAL2) 275 + return dev_err_probe(st->dev, -EIO, 276 + "SCRATCH_PAD_TEST mismatch. Expected 0x%x, Read 0x%x\n", 277 + AD3552R_SCRATCH_PAD_TEST_VAL2, val); 278 + 279 + return 0; 280 + } 281 + 282 + static int ad3552r_hs_setup_custom_gain(struct ad3552r_hs_state *st, 283 + int ch, u16 gain, u16 offset) 284 + { 285 + int ret; 286 + 287 + ret = st->data->bus_reg_write(st->back, AD3552R_REG_ADDR_CH_OFFSET(ch), 288 + offset, 1); 289 + if (ret) 290 + return ret; 291 + 292 + return st->data->bus_reg_write(st->back, AD3552R_REG_ADDR_CH_GAIN(ch), 293 + gain, 1); 294 + } 295 + 296 + static int ad3552r_hs_setup(struct ad3552r_hs_state *st) 297 + { 298 + u16 id; 299 + u16 gain = 0, offset = 0; 300 + u32 ch, val, range; 301 + int ret; 302 + 303 + ret = ad3552r_hs_reset(st); 304 + if (ret) 305 + return ret; 306 + 307 + ret = iio_backend_ddr_disable(st->back); 308 + if (ret) 309 + return ret; 310 + 311 + ret = ad3552r_hs_scratch_pad_test(st); 312 + if (ret) 313 + return ret; 314 + 315 + ret = st->data->bus_reg_read(st->back, AD3552R_REG_ADDR_PRODUCT_ID_L, 316 + &val, 1); 317 + if (ret) 318 + return ret; 319 + 320 + id = val; 321 + 322 + ret = st->data->bus_reg_read(st->back, AD3552R_REG_ADDR_PRODUCT_ID_H, 323 + &val, 1); 324 + if (ret) 325 + return ret; 326 + 327 + id |= val << 8; 328 + if (id != st->model_data->chip_id) 329 + dev_info(st->dev, "Chip ID error. Expected 0x%x, Read 0x%x\n", 330 + AD3552R_ID, id); 331 + 332 + ret = st->data->bus_reg_write(st->back, 333 + AD3552R_REG_ADDR_SH_REFERENCE_CONFIG, 334 + 0, 1); 335 + if (ret) 336 + return ret; 337 + 338 + ret = st->data->bus_reg_write(st->back, 339 + AD3552R_REG_ADDR_TRANSFER_REGISTER, 340 + FIELD_PREP(AD3552R_MASK_MULTI_IO_MODE, 341 + AD3552R_QUAD_SPI) | 342 + AD3552R_MASK_STREAM_LENGTH_KEEP_VALUE, 1); 343 + if (ret) 344 + return ret; 345 + 346 + ret = iio_backend_data_source_set(st->back, 0, IIO_BACKEND_EXTERNAL); 347 + if (ret) 348 + return ret; 349 + 350 + ret = iio_backend_data_source_set(st->back, 1, IIO_BACKEND_EXTERNAL); 351 + if (ret) 352 + return ret; 353 + 354 + ret = ad3552r_get_ref_voltage(st->dev, &val); 355 + if (ret < 0) 356 + return ret; 357 + 358 + val = ret; 359 + 360 + ret = ad3552r_qspi_update_reg_bits(st, 361 + AD3552R_REG_ADDR_SH_REFERENCE_CONFIG, 362 + AD3552R_MASK_REFERENCE_VOLTAGE_SEL, 363 + val, 1); 364 + if (ret) 365 + return ret; 366 + 367 + ret = ad3552r_get_drive_strength(st->dev, &val); 368 + if (!ret) { 369 + ret = ad3552r_qspi_update_reg_bits(st, 370 + AD3552R_REG_ADDR_INTERFACE_CONFIG_D, 371 + AD3552R_MASK_SDO_DRIVE_STRENGTH, 372 + val, 1); 373 + if (ret) 374 + return ret; 375 + } 376 + 377 + device_for_each_child_node_scoped(st->dev, child) { 378 + ret = fwnode_property_read_u32(child, "reg", &ch); 379 + if (ret) 380 + return dev_err_probe(st->dev, ret, 381 + "reg property missing\n"); 382 + 383 + ret = ad3552r_get_output_range(st->dev, st->model_data, child, 384 + &range); 385 + if (ret && ret != -ENOENT) 386 + return ret; 387 + if (ret == -ENOENT) { 388 + ret = ad3552r_get_custom_gain(st->dev, child, 389 + &st->ch_data[ch].p, 390 + &st->ch_data[ch].n, 391 + &st->ch_data[ch].rfb, 392 + &st->ch_data[ch].gain_offset); 393 + if (ret) 394 + return ret; 395 + 396 + gain = ad3552r_calc_custom_gain(st->ch_data[ch].p, 397 + st->ch_data[ch].n, 398 + st->ch_data[ch].gain_offset); 399 + offset = abs(st->ch_data[ch].gain_offset); 400 + 401 + st->ch_data[ch].range_override = 1; 402 + 403 + ret = ad3552r_hs_setup_custom_gain(st, ch, gain, 404 + offset); 405 + if (ret) 406 + return ret; 407 + } else { 408 + st->ch_data[ch].range = range; 409 + 410 + ret = ad3552r_hs_set_output_range(st, ch, range); 411 + if (ret) 412 + return ret; 413 + } 414 + 415 + ad3552r_calc_gain_and_offset(&st->ch_data[ch], st->model_data); 416 + } 417 + 418 + return 0; 419 + } 420 + 421 + static const struct iio_buffer_setup_ops ad3552r_hs_buffer_setup_ops = { 422 + .postenable = ad3552r_hs_buffer_postenable, 423 + .predisable = ad3552r_hs_buffer_predisable, 424 + }; 425 + 426 + #define AD3552R_CHANNEL(ch) { \ 427 + .type = IIO_VOLTAGE, \ 428 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 429 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ 430 + BIT(IIO_CHAN_INFO_SCALE) | \ 431 + BIT(IIO_CHAN_INFO_OFFSET), \ 432 + .output = 1, \ 433 + .indexed = 1, \ 434 + .channel = (ch), \ 435 + .scan_index = (ch), \ 436 + .scan_type = { \ 437 + .sign = 'u', \ 438 + .realbits = 16, \ 439 + .storagebits = 16, \ 440 + .endianness = IIO_BE, \ 441 + } \ 442 + } 443 + 444 + static const struct iio_chan_spec ad3552r_hs_channels[] = { 445 + AD3552R_CHANNEL(0), 446 + AD3552R_CHANNEL(1), 447 + }; 448 + 449 + static const struct iio_info ad3552r_hs_info = { 450 + .read_raw = &ad3552r_hs_read_raw, 451 + .write_raw = &ad3552r_hs_write_raw, 452 + }; 453 + 454 + static int ad3552r_hs_probe(struct platform_device *pdev) 455 + { 456 + struct ad3552r_hs_state *st; 457 + struct iio_dev *indio_dev; 458 + int ret; 459 + 460 + indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); 461 + if (!indio_dev) 462 + return -ENOMEM; 463 + 464 + st = iio_priv(indio_dev); 465 + st->dev = &pdev->dev; 466 + 467 + st->data = dev_get_platdata(st->dev); 468 + if (!st->data) 469 + return dev_err_probe(st->dev, -ENODEV, "No platform data !"); 470 + 471 + st->back = devm_iio_backend_get(&pdev->dev, NULL); 472 + if (IS_ERR(st->back)) 473 + return PTR_ERR(st->back); 474 + 475 + ret = devm_iio_backend_enable(&pdev->dev, st->back); 476 + if (ret) 477 + return ret; 478 + 479 + st->model_data = device_get_match_data(&pdev->dev); 480 + if (!st->model_data) 481 + return -ENODEV; 482 + 483 + indio_dev->name = "ad3552r"; 484 + indio_dev->modes = INDIO_DIRECT_MODE; 485 + indio_dev->setup_ops = &ad3552r_hs_buffer_setup_ops; 486 + indio_dev->channels = ad3552r_hs_channels; 487 + indio_dev->num_channels = ARRAY_SIZE(ad3552r_hs_channels); 488 + indio_dev->info = &ad3552r_hs_info; 489 + 490 + ret = devm_iio_backend_request_buffer(&pdev->dev, st->back, indio_dev); 491 + if (ret) 492 + return ret; 493 + 494 + ret = ad3552r_hs_setup(st); 495 + if (ret) 496 + return ret; 497 + 498 + return devm_iio_device_register(&pdev->dev, indio_dev); 499 + } 500 + 501 + static const struct ad3552r_model_data ad3552r_model_data = { 502 + .model_name = "ad3552r", 503 + .chip_id = AD3552R_ID, 504 + .num_hw_channels = 2, 505 + .ranges_table = ad3552r_ch_ranges, 506 + .num_ranges = ARRAY_SIZE(ad3552r_ch_ranges), 507 + }; 508 + 509 + static const struct of_device_id ad3552r_hs_of_id[] = { 510 + { .compatible = "adi,ad3552r", .data = &ad3552r_model_data }, 511 + { } 512 + }; 513 + MODULE_DEVICE_TABLE(of, ad3552r_hs_of_id); 514 + 515 + static struct platform_driver ad3552r_hs_driver = { 516 + .driver = { 517 + .name = "ad3552r-hs", 518 + .of_match_table = ad3552r_hs_of_id, 519 + }, 520 + .probe = ad3552r_hs_probe, 521 + }; 522 + module_platform_driver(ad3552r_hs_driver); 523 + 524 + MODULE_AUTHOR("Dragos Bogdan <dragos.bogdan@analog.com>"); 525 + MODULE_AUTHOR("Angelo Dureghello <adueghello@baylibre.com>"); 526 + MODULE_DESCRIPTION("AD3552R Driver - High Speed version"); 527 + MODULE_LICENSE("GPL"); 528 + MODULE_IMPORT_NS(IIO_BACKEND); 529 + MODULE_IMPORT_NS(IIO_AD3552R);
+19
drivers/iio/dac/ad3552r-hs.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + /* 3 + * Copyright (c) 2024 Analog Devices Inc. 4 + * Copyright (c) 2024 Baylibre, SAS 5 + */ 6 + #ifndef __LINUX_PLATFORM_DATA_AD3552R_HS_H__ 7 + #define __LINUX_PLATFORM_DATA_AD3552R_HS_H__ 8 + 9 + struct iio_backend; 10 + 11 + struct ad3552r_hs_platform_data { 12 + int (*bus_reg_read)(struct iio_backend *back, u32 reg, u32 *val, 13 + size_t data_size); 14 + int (*bus_reg_write)(struct iio_backend *back, u32 reg, u32 val, 15 + size_t data_size); 16 + u32 bus_sample_data_clock_hz; 17 + }; 18 + 19 + #endif /* __LINUX_PLATFORM_DATA_AD3552R_HS_H__ */
+71 -482
drivers/iio/dac/ad3552r.c
··· 6 6 * Copyright 2021 Analog Devices Inc. 7 7 */ 8 8 #include <linux/unaligned.h> 9 + #include <linux/bitfield.h> 9 10 #include <linux/device.h> 10 11 #include <linux/iio/triggered_buffer.h> 11 12 #include <linux/iio/trigger_consumer.h> 12 13 #include <linux/iopoll.h> 13 14 #include <linux/kernel.h> 14 - #include <linux/regulator/consumer.h> 15 15 #include <linux/spi/spi.h> 16 16 17 - /* Register addresses */ 18 - /* Primary address space */ 19 - #define AD3552R_REG_ADDR_INTERFACE_CONFIG_A 0x00 20 - #define AD3552R_MASK_SOFTWARE_RESET (BIT(7) | BIT(0)) 21 - #define AD3552R_MASK_ADDR_ASCENSION BIT(5) 22 - #define AD3552R_MASK_SDO_ACTIVE BIT(4) 23 - #define AD3552R_REG_ADDR_INTERFACE_CONFIG_B 0x01 24 - #define AD3552R_MASK_SINGLE_INST BIT(7) 25 - #define AD3552R_MASK_SHORT_INSTRUCTION BIT(3) 26 - #define AD3552R_REG_ADDR_DEVICE_CONFIG 0x02 27 - #define AD3552R_MASK_DEVICE_STATUS(n) BIT(4 + (n)) 28 - #define AD3552R_MASK_CUSTOM_MODES GENMASK(3, 2) 29 - #define AD3552R_MASK_OPERATING_MODES GENMASK(1, 0) 30 - #define AD3552R_REG_ADDR_CHIP_TYPE 0x03 31 - #define AD3552R_MASK_CLASS GENMASK(7, 0) 32 - #define AD3552R_REG_ADDR_PRODUCT_ID_L 0x04 33 - #define AD3552R_REG_ADDR_PRODUCT_ID_H 0x05 34 - #define AD3552R_REG_ADDR_CHIP_GRADE 0x06 35 - #define AD3552R_MASK_GRADE GENMASK(7, 4) 36 - #define AD3552R_MASK_DEVICE_REVISION GENMASK(3, 0) 37 - #define AD3552R_REG_ADDR_SCRATCH_PAD 0x0A 38 - #define AD3552R_REG_ADDR_SPI_REVISION 0x0B 39 - #define AD3552R_REG_ADDR_VENDOR_L 0x0C 40 - #define AD3552R_REG_ADDR_VENDOR_H 0x0D 41 - #define AD3552R_REG_ADDR_STREAM_MODE 0x0E 42 - #define AD3552R_MASK_LENGTH GENMASK(7, 0) 43 - #define AD3552R_REG_ADDR_TRANSFER_REGISTER 0x0F 44 - #define AD3552R_MASK_MULTI_IO_MODE GENMASK(7, 6) 45 - #define AD3552R_MASK_STREAM_LENGTH_KEEP_VALUE BIT(2) 46 - #define AD3552R_REG_ADDR_INTERFACE_CONFIG_C 0x10 47 - #define AD3552R_MASK_CRC_ENABLE (GENMASK(7, 6) |\ 48 - GENMASK(1, 0)) 49 - #define AD3552R_MASK_STRICT_REGISTER_ACCESS BIT(5) 50 - #define AD3552R_REG_ADDR_INTERFACE_STATUS_A 0x11 51 - #define AD3552R_MASK_INTERFACE_NOT_READY BIT(7) 52 - #define AD3552R_MASK_CLOCK_COUNTING_ERROR BIT(5) 53 - #define AD3552R_MASK_INVALID_OR_NO_CRC BIT(3) 54 - #define AD3552R_MASK_WRITE_TO_READ_ONLY_REGISTER BIT(2) 55 - #define AD3552R_MASK_PARTIAL_REGISTER_ACCESS BIT(1) 56 - #define AD3552R_MASK_REGISTER_ADDRESS_INVALID BIT(0) 57 - #define AD3552R_REG_ADDR_INTERFACE_CONFIG_D 0x14 58 - #define AD3552R_MASK_ALERT_ENABLE_PULLUP BIT(6) 59 - #define AD3552R_MASK_MEM_CRC_EN BIT(4) 60 - #define AD3552R_MASK_SDO_DRIVE_STRENGTH GENMASK(3, 2) 61 - #define AD3552R_MASK_DUAL_SPI_SYNCHROUNOUS_EN BIT(1) 62 - #define AD3552R_MASK_SPI_CONFIG_DDR BIT(0) 63 - #define AD3552R_REG_ADDR_SH_REFERENCE_CONFIG 0x15 64 - #define AD3552R_MASK_IDUMP_FAST_MODE BIT(6) 65 - #define AD3552R_MASK_SAMPLE_HOLD_DIFFERENTIAL_USER_EN BIT(5) 66 - #define AD3552R_MASK_SAMPLE_HOLD_USER_TRIM GENMASK(4, 3) 67 - #define AD3552R_MASK_SAMPLE_HOLD_USER_ENABLE BIT(2) 68 - #define AD3552R_MASK_REFERENCE_VOLTAGE_SEL GENMASK(1, 0) 69 - #define AD3552R_REG_ADDR_ERR_ALARM_MASK 0x16 70 - #define AD3552R_MASK_REF_RANGE_ALARM BIT(6) 71 - #define AD3552R_MASK_CLOCK_COUNT_ERR_ALARM BIT(5) 72 - #define AD3552R_MASK_MEM_CRC_ERR_ALARM BIT(4) 73 - #define AD3552R_MASK_SPI_CRC_ERR_ALARM BIT(3) 74 - #define AD3552R_MASK_WRITE_TO_READ_ONLY_ALARM BIT(2) 75 - #define AD3552R_MASK_PARTIAL_REGISTER_ACCESS_ALARM BIT(1) 76 - #define AD3552R_MASK_REGISTER_ADDRESS_INVALID_ALARM BIT(0) 77 - #define AD3552R_REG_ADDR_ERR_STATUS 0x17 78 - #define AD3552R_MASK_REF_RANGE_ERR_STATUS BIT(6) 79 - #define AD3552R_MASK_DUAL_SPI_STREAM_EXCEEDS_DAC_ERR_STATUS BIT(5) 80 - #define AD3552R_MASK_MEM_CRC_ERR_STATUS BIT(4) 81 - #define AD3552R_MASK_RESET_STATUS BIT(0) 82 - #define AD3552R_REG_ADDR_POWERDOWN_CONFIG 0x18 83 - #define AD3552R_MASK_CH_DAC_POWERDOWN(ch) BIT(4 + (ch)) 84 - #define AD3552R_MASK_CH_AMPLIFIER_POWERDOWN(ch) BIT(ch) 85 - #define AD3552R_REG_ADDR_CH0_CH1_OUTPUT_RANGE 0x19 86 - #define AD3552R_MASK_CH_OUTPUT_RANGE_SEL(ch) ((ch) ? GENMASK(7, 4) :\ 87 - GENMASK(3, 0)) 88 - #define AD3552R_REG_ADDR_CH_OFFSET(ch) (0x1B + (ch) * 2) 89 - #define AD3552R_MASK_CH_OFFSET_BITS_0_7 GENMASK(7, 0) 90 - #define AD3552R_REG_ADDR_CH_GAIN(ch) (0x1C + (ch) * 2) 91 - #define AD3552R_MASK_CH_RANGE_OVERRIDE BIT(7) 92 - #define AD3552R_MASK_CH_GAIN_SCALING_N GENMASK(6, 5) 93 - #define AD3552R_MASK_CH_GAIN_SCALING_P GENMASK(4, 3) 94 - #define AD3552R_MASK_CH_OFFSET_POLARITY BIT(2) 95 - #define AD3552R_MASK_CH_OFFSET_BIT_8 BIT(0) 96 - /* 97 - * Secondary region 98 - * For multibyte registers specify the highest address because the access is 99 - * done in descending order 100 - */ 101 - #define AD3552R_SECONDARY_REGION_START 0x28 102 - #define AD3552R_REG_ADDR_HW_LDAC_16B 0x28 103 - #define AD3552R_REG_ADDR_CH_DAC_16B(ch) (0x2C - (1 - ch) * 2) 104 - #define AD3552R_REG_ADDR_DAC_PAGE_MASK_16B 0x2E 105 - #define AD3552R_REG_ADDR_CH_SELECT_16B 0x2F 106 - #define AD3552R_REG_ADDR_INPUT_PAGE_MASK_16B 0x31 107 - #define AD3552R_REG_ADDR_SW_LDAC_16B 0x32 108 - #define AD3552R_REG_ADDR_CH_INPUT_16B(ch) (0x36 - (1 - ch) * 2) 109 - /* 3 bytes registers */ 110 - #define AD3552R_REG_START_24B 0x37 111 - #define AD3552R_REG_ADDR_HW_LDAC_24B 0x37 112 - #define AD3552R_REG_ADDR_CH_DAC_24B(ch) (0x3D - (1 - ch) * 3) 113 - #define AD3552R_REG_ADDR_DAC_PAGE_MASK_24B 0x40 114 - #define AD3552R_REG_ADDR_CH_SELECT_24B 0x41 115 - #define AD3552R_REG_ADDR_INPUT_PAGE_MASK_24B 0x44 116 - #define AD3552R_REG_ADDR_SW_LDAC_24B 0x45 117 - #define AD3552R_REG_ADDR_CH_INPUT_24B(ch) (0x4B - (1 - ch) * 3) 118 - 119 - /* Useful defines */ 120 - #define AD3552R_MAX_CH 2 121 - #define AD3552R_MASK_CH(ch) BIT(ch) 122 - #define AD3552R_MASK_ALL_CH GENMASK(1, 0) 123 - #define AD3552R_MAX_REG_SIZE 3 124 - #define AD3552R_READ_BIT BIT(7) 125 - #define AD3552R_ADDR_MASK GENMASK(6, 0) 126 - #define AD3552R_MASK_DAC_12B 0xFFF0 127 - #define AD3552R_DEFAULT_CONFIG_B_VALUE 0x8 128 - #define AD3552R_SCRATCH_PAD_TEST_VAL1 0x34 129 - #define AD3552R_SCRATCH_PAD_TEST_VAL2 0xB2 130 - #define AD3552R_GAIN_SCALE 1000 131 - #define AD3552R_LDAC_PULSE_US 100 132 - 133 - enum ad3552r_ch_vref_select { 134 - /* Internal source with Vref I/O floating */ 135 - AD3552R_INTERNAL_VREF_PIN_FLOATING, 136 - /* Internal source with Vref I/O at 2.5V */ 137 - AD3552R_INTERNAL_VREF_PIN_2P5V, 138 - /* External source with Vref I/O as input */ 139 - AD3552R_EXTERNAL_VREF_PIN_INPUT 140 - }; 141 - 142 - enum ad3552r_id { 143 - AD3541R_ID = 0x400b, 144 - AD3542R_ID = 0x4009, 145 - AD3551R_ID = 0x400a, 146 - AD3552R_ID = 0x4008, 147 - }; 148 - 149 - enum ad3552r_ch_output_range { 150 - /* Range from 0 V to 2.5 V. Requires Rfb1x connection */ 151 - AD3552R_CH_OUTPUT_RANGE_0__2P5V, 152 - /* Range from 0 V to 5 V. Requires Rfb1x connection */ 153 - AD3552R_CH_OUTPUT_RANGE_0__5V, 154 - /* Range from 0 V to 10 V. Requires Rfb2x connection */ 155 - AD3552R_CH_OUTPUT_RANGE_0__10V, 156 - /* Range from -5 V to 5 V. Requires Rfb2x connection */ 157 - AD3552R_CH_OUTPUT_RANGE_NEG_5__5V, 158 - /* Range from -10 V to 10 V. Requires Rfb4x connection */ 159 - AD3552R_CH_OUTPUT_RANGE_NEG_10__10V, 160 - }; 161 - 162 - static const s32 ad3552r_ch_ranges[][2] = { 163 - [AD3552R_CH_OUTPUT_RANGE_0__2P5V] = {0, 2500}, 164 - [AD3552R_CH_OUTPUT_RANGE_0__5V] = {0, 5000}, 165 - [AD3552R_CH_OUTPUT_RANGE_0__10V] = {0, 10000}, 166 - [AD3552R_CH_OUTPUT_RANGE_NEG_5__5V] = {-5000, 5000}, 167 - [AD3552R_CH_OUTPUT_RANGE_NEG_10__10V] = {-10000, 10000} 168 - }; 169 - 170 - enum ad3542r_ch_output_range { 171 - /* Range from 0 V to 2.5 V. Requires Rfb1x connection */ 172 - AD3542R_CH_OUTPUT_RANGE_0__2P5V, 173 - /* Range from 0 V to 3 V. Requires Rfb1x connection */ 174 - AD3542R_CH_OUTPUT_RANGE_0__3V, 175 - /* Range from 0 V to 5 V. Requires Rfb1x connection */ 176 - AD3542R_CH_OUTPUT_RANGE_0__5V, 177 - /* Range from 0 V to 10 V. Requires Rfb2x connection */ 178 - AD3542R_CH_OUTPUT_RANGE_0__10V, 179 - /* Range from -2.5 V to 7.5 V. Requires Rfb2x connection */ 180 - AD3542R_CH_OUTPUT_RANGE_NEG_2P5__7P5V, 181 - /* Range from -5 V to 5 V. Requires Rfb2x connection */ 182 - AD3542R_CH_OUTPUT_RANGE_NEG_5__5V, 183 - }; 184 - 185 - static const s32 ad3542r_ch_ranges[][2] = { 186 - [AD3542R_CH_OUTPUT_RANGE_0__2P5V] = {0, 2500}, 187 - [AD3542R_CH_OUTPUT_RANGE_0__3V] = {0, 3000}, 188 - [AD3542R_CH_OUTPUT_RANGE_0__5V] = {0, 5000}, 189 - [AD3542R_CH_OUTPUT_RANGE_0__10V] = {0, 10000}, 190 - [AD3542R_CH_OUTPUT_RANGE_NEG_2P5__7P5V] = {-2500, 7500}, 191 - [AD3542R_CH_OUTPUT_RANGE_NEG_5__5V] = {-5000, 5000} 192 - }; 193 - 194 - enum ad3552r_ch_gain_scaling { 195 - /* Gain scaling of 1 */ 196 - AD3552R_CH_GAIN_SCALING_1, 197 - /* Gain scaling of 0.5 */ 198 - AD3552R_CH_GAIN_SCALING_0_5, 199 - /* Gain scaling of 0.25 */ 200 - AD3552R_CH_GAIN_SCALING_0_25, 201 - /* Gain scaling of 0.125 */ 202 - AD3552R_CH_GAIN_SCALING_0_125, 203 - }; 204 - 205 - /* Gain * AD3552R_GAIN_SCALE */ 206 - static const s32 gains_scaling_table[] = { 207 - [AD3552R_CH_GAIN_SCALING_1] = 1000, 208 - [AD3552R_CH_GAIN_SCALING_0_5] = 500, 209 - [AD3552R_CH_GAIN_SCALING_0_25] = 250, 210 - [AD3552R_CH_GAIN_SCALING_0_125] = 125 211 - }; 212 - 213 - enum ad3552r_dev_attributes { 214 - /* - Direct register values */ 215 - /* From 0-3 */ 216 - AD3552R_SDO_DRIVE_STRENGTH, 217 - /* 218 - * 0 -> Internal Vref, vref_io pin floating (default) 219 - * 1 -> Internal Vref, vref_io driven by internal vref 220 - * 2 or 3 -> External Vref 221 - */ 222 - AD3552R_VREF_SELECT, 223 - /* Read registers in ascending order if set. Else descending */ 224 - AD3552R_ADDR_ASCENSION, 225 - }; 226 - 227 - enum ad3552r_ch_attributes { 228 - /* DAC powerdown */ 229 - AD3552R_CH_DAC_POWERDOWN, 230 - /* DAC amplifier powerdown */ 231 - AD3552R_CH_AMPLIFIER_POWERDOWN, 232 - /* Select the output range. Select from enum ad3552r_ch_output_range */ 233 - AD3552R_CH_OUTPUT_RANGE_SEL, 234 - /* 235 - * Over-rider the range selector in order to manually set the output 236 - * voltage range 237 - */ 238 - AD3552R_CH_RANGE_OVERRIDE, 239 - /* Manually set the offset voltage */ 240 - AD3552R_CH_GAIN_OFFSET, 241 - /* Sets the polarity of the offset. */ 242 - AD3552R_CH_GAIN_OFFSET_POLARITY, 243 - /* PDAC gain scaling */ 244 - AD3552R_CH_GAIN_SCALING_P, 245 - /* NDAC gain scaling */ 246 - AD3552R_CH_GAIN_SCALING_N, 247 - /* Rfb value */ 248 - AD3552R_CH_RFB, 249 - /* Channel select. When set allow Input -> DAC and Mask -> DAC */ 250 - AD3552R_CH_SELECT, 251 - }; 252 - 253 - struct ad3552r_ch_data { 254 - s32 scale_int; 255 - s32 scale_dec; 256 - s32 offset_int; 257 - s32 offset_dec; 258 - s16 gain_offset; 259 - u16 rfb; 260 - u8 n; 261 - u8 p; 262 - u8 range; 263 - bool range_override; 264 - }; 265 - 266 - struct ad3552r_model_data { 267 - const char *model_name; 268 - enum ad3552r_id chip_id; 269 - unsigned int num_hw_channels; 270 - const s32 (*ranges_table)[2]; 271 - int num_ranges; 272 - bool requires_output_range; 273 - }; 17 + #include "ad3552r.h" 274 18 275 19 struct ad3552r_desc { 276 20 const struct ad3552r_model_data *model_data; ··· 27 283 struct iio_chan_spec channels[AD3552R_MAX_CH + 1]; 28 284 unsigned long enabled_ch; 29 285 unsigned int num_ch; 30 - }; 31 - 32 - static const u16 addr_mask_map[][2] = { 33 - [AD3552R_ADDR_ASCENSION] = { 34 - AD3552R_REG_ADDR_INTERFACE_CONFIG_A, 35 - AD3552R_MASK_ADDR_ASCENSION 36 - }, 37 - [AD3552R_SDO_DRIVE_STRENGTH] = { 38 - AD3552R_REG_ADDR_INTERFACE_CONFIG_D, 39 - AD3552R_MASK_SDO_DRIVE_STRENGTH 40 - }, 41 - [AD3552R_VREF_SELECT] = { 42 - AD3552R_REG_ADDR_SH_REFERENCE_CONFIG, 43 - AD3552R_MASK_REFERENCE_VOLTAGE_SEL 44 - }, 45 - }; 46 - 47 - /* 0 -> reg addr, 1->ch0 mask, 2->ch1 mask */ 48 - static const u16 addr_mask_map_ch[][3] = { 49 - [AD3552R_CH_DAC_POWERDOWN] = { 50 - AD3552R_REG_ADDR_POWERDOWN_CONFIG, 51 - AD3552R_MASK_CH_DAC_POWERDOWN(0), 52 - AD3552R_MASK_CH_DAC_POWERDOWN(1) 53 - }, 54 - [AD3552R_CH_AMPLIFIER_POWERDOWN] = { 55 - AD3552R_REG_ADDR_POWERDOWN_CONFIG, 56 - AD3552R_MASK_CH_AMPLIFIER_POWERDOWN(0), 57 - AD3552R_MASK_CH_AMPLIFIER_POWERDOWN(1) 58 - }, 59 - [AD3552R_CH_OUTPUT_RANGE_SEL] = { 60 - AD3552R_REG_ADDR_CH0_CH1_OUTPUT_RANGE, 61 - AD3552R_MASK_CH_OUTPUT_RANGE_SEL(0), 62 - AD3552R_MASK_CH_OUTPUT_RANGE_SEL(1) 63 - }, 64 - [AD3552R_CH_SELECT] = { 65 - AD3552R_REG_ADDR_CH_SELECT_16B, 66 - AD3552R_MASK_CH(0), 67 - AD3552R_MASK_CH(1) 68 - } 69 286 }; 70 287 71 288 static u8 _ad3552r_reg_len(u8 addr) ··· 104 399 return 0; 105 400 } 106 401 107 - static u16 ad3552r_field_prep(u16 val, u16 mask) 108 - { 109 - return (val << __ffs(mask)) & mask; 110 - } 111 - 112 402 /* Update field of a register, shift val if needed */ 113 403 static int ad3552r_update_reg_field(struct ad3552r_desc *dac, u8 addr, u16 mask, 114 404 u16 val) ··· 116 416 return ret; 117 417 118 418 reg &= ~mask; 119 - reg |= ad3552r_field_prep(val, mask); 419 + reg |= val; 120 420 121 421 return ad3552r_write_reg(dac, addr, reg); 122 - } 123 - 124 - static int ad3552r_set_ch_value(struct ad3552r_desc *dac, 125 - enum ad3552r_ch_attributes attr, 126 - u8 ch, 127 - u16 val) 128 - { 129 - /* Update register related to attributes in chip */ 130 - return ad3552r_update_reg_field(dac, addr_mask_map_ch[attr][0], 131 - addr_mask_map_ch[attr][ch + 1], val); 132 422 } 133 423 134 424 #define AD3552R_CH_DAC(_idx) ((struct iio_chan_spec) { \ ··· 200 510 val); 201 511 break; 202 512 case IIO_CHAN_INFO_ENABLE: 203 - err = ad3552r_set_ch_value(dac, AD3552R_CH_DAC_POWERDOWN, 204 - chan->channel, !val); 513 + if (chan->channel == 0) 514 + val = FIELD_PREP(AD3552R_MASK_CH_DAC_POWERDOWN(0), !val); 515 + else 516 + val = FIELD_PREP(AD3552R_MASK_CH_DAC_POWERDOWN(1), !val); 517 + 518 + err = ad3552r_update_reg_field(dac, AD3552R_REG_ADDR_POWERDOWN_CONFIG, 519 + AD3552R_MASK_CH_DAC_POWERDOWN(chan->channel), 520 + val); 205 521 break; 206 522 default: 207 523 err = -EINVAL; ··· 411 715 } 412 716 413 717 return ad3552r_update_reg_field(dac, 414 - addr_mask_map[AD3552R_ADDR_ASCENSION][0], 415 - addr_mask_map[AD3552R_ADDR_ASCENSION][1], 416 - val); 417 - } 418 - 419 - static void ad3552r_get_custom_range(struct ad3552r_desc *dac, s32 i, s32 *v_min, 420 - s32 *v_max) 421 - { 422 - s64 vref, tmp, common, offset, gn, gp; 423 - /* 424 - * From datasheet formula (In Volts): 425 - * Vmin = 2.5 + [(GainN + Offset / 1024) * 2.5 * Rfb * 1.03] 426 - * Vmax = 2.5 - [(GainP + Offset / 1024) * 2.5 * Rfb * 1.03] 427 - * Calculus are converted to milivolts 428 - */ 429 - vref = 2500; 430 - /* 2.5 * 1.03 * 1000 (To mV) */ 431 - common = 2575 * dac->ch_data[i].rfb; 432 - offset = dac->ch_data[i].gain_offset; 433 - 434 - gn = gains_scaling_table[dac->ch_data[i].n]; 435 - tmp = (1024 * gn + AD3552R_GAIN_SCALE * offset) * common; 436 - tmp = div_s64(tmp, 1024 * AD3552R_GAIN_SCALE); 437 - *v_max = vref + tmp; 438 - 439 - gp = gains_scaling_table[dac->ch_data[i].p]; 440 - tmp = (1024 * gp - AD3552R_GAIN_SCALE * offset) * common; 441 - tmp = div_s64(tmp, 1024 * AD3552R_GAIN_SCALE); 442 - *v_min = vref - tmp; 443 - } 444 - 445 - static void ad3552r_calc_gain_and_offset(struct ad3552r_desc *dac, s32 ch) 446 - { 447 - s32 idx, v_max, v_min, span, rem; 448 - s64 tmp; 449 - 450 - if (dac->ch_data[ch].range_override) { 451 - ad3552r_get_custom_range(dac, ch, &v_min, &v_max); 452 - } else { 453 - /* Normal range */ 454 - idx = dac->ch_data[ch].range; 455 - v_min = dac->model_data->ranges_table[idx][0]; 456 - v_max = dac->model_data->ranges_table[idx][1]; 457 - } 458 - 459 - /* 460 - * From datasheet formula: 461 - * Vout = Span * (D / 65536) + Vmin 462 - * Converted to scale and offset: 463 - * Scale = Span / 65536 464 - * Offset = 65536 * Vmin / Span 465 - * 466 - * Reminders are in micros in order to be printed as 467 - * IIO_VAL_INT_PLUS_MICRO 468 - */ 469 - span = v_max - v_min; 470 - dac->ch_data[ch].scale_int = div_s64_rem(span, 65536, &rem); 471 - /* Do operations in microvolts */ 472 - dac->ch_data[ch].scale_dec = DIV_ROUND_CLOSEST((s64)rem * 1000000, 473 - 65536); 474 - 475 - dac->ch_data[ch].offset_int = div_s64_rem(v_min * 65536, span, &rem); 476 - tmp = (s64)rem * 1000000; 477 - dac->ch_data[ch].offset_dec = div_s64(tmp, span); 478 - } 479 - 480 - static int ad3552r_find_range(const struct ad3552r_model_data *model_data, 481 - s32 *vals) 482 - { 483 - int i; 484 - 485 - for (i = 0; i < model_data->num_ranges; i++) 486 - if (vals[0] == model_data->ranges_table[i][0] * 1000 && 487 - vals[1] == model_data->ranges_table[i][1] * 1000) 488 - return i; 489 - 490 - return -EINVAL; 718 + AD3552R_REG_ADDR_INTERFACE_CONFIG_A, 719 + AD3552R_MASK_ADDR_ASCENSION, 720 + FIELD_PREP(AD3552R_MASK_ADDR_ASCENSION, val)); 491 721 } 492 722 493 723 static int ad3552r_configure_custom_gain(struct ad3552r_desc *dac, ··· 421 799 u32 ch) 422 800 { 423 801 struct device *dev = &dac->spi->dev; 424 - u32 val; 425 802 int err; 426 803 u8 addr; 427 - u16 reg = 0, offset; 804 + u16 reg; 428 805 429 - struct fwnode_handle *gain_child __free(fwnode_handle) 430 - = fwnode_get_named_child_node(child, 431 - "custom-output-range-config"); 432 - if (!gain_child) 433 - return dev_err_probe(dev, -EINVAL, 434 - "mandatory custom-output-range-config property missing\n"); 806 + err = ad3552r_get_custom_gain(dev, child, 807 + &dac->ch_data[ch].p, 808 + &dac->ch_data[ch].n, 809 + &dac->ch_data[ch].rfb, 810 + &dac->ch_data[ch].gain_offset); 811 + if (err) 812 + return err; 435 813 436 814 dac->ch_data[ch].range_override = 1; 437 - reg |= ad3552r_field_prep(1, AD3552R_MASK_CH_RANGE_OVERRIDE); 438 815 439 - err = fwnode_property_read_u32(gain_child, "adi,gain-scaling-p", &val); 440 - if (err) 441 - return dev_err_probe(dev, err, 442 - "mandatory adi,gain-scaling-p property missing\n"); 443 - reg |= ad3552r_field_prep(val, AD3552R_MASK_CH_GAIN_SCALING_P); 444 - dac->ch_data[ch].p = val; 445 - 446 - err = fwnode_property_read_u32(gain_child, "adi,gain-scaling-n", &val); 447 - if (err) 448 - return dev_err_probe(dev, err, 449 - "mandatory adi,gain-scaling-n property missing\n"); 450 - reg |= ad3552r_field_prep(val, AD3552R_MASK_CH_GAIN_SCALING_N); 451 - dac->ch_data[ch].n = val; 452 - 453 - err = fwnode_property_read_u32(gain_child, "adi,rfb-ohms", &val); 454 - if (err) 455 - return dev_err_probe(dev, err, 456 - "mandatory adi,rfb-ohms property missing\n"); 457 - dac->ch_data[ch].rfb = val; 458 - 459 - err = fwnode_property_read_u32(gain_child, "adi,gain-offset", &val); 460 - if (err) 461 - return dev_err_probe(dev, err, 462 - "mandatory adi,gain-offset property missing\n"); 463 - dac->ch_data[ch].gain_offset = val; 464 - 465 - offset = abs((s32)val); 466 - reg |= ad3552r_field_prep((offset >> 8), AD3552R_MASK_CH_OFFSET_BIT_8); 467 - 468 - reg |= ad3552r_field_prep((s32)val < 0, AD3552R_MASK_CH_OFFSET_POLARITY); 469 816 addr = AD3552R_REG_ADDR_CH_GAIN(ch); 470 817 err = ad3552r_write_reg(dac, addr, 471 - offset & AD3552R_MASK_CH_OFFSET_BITS_0_7); 818 + abs((s32)dac->ch_data[ch].gain_offset) & 819 + AD3552R_MASK_CH_OFFSET_BITS_0_7); 472 820 if (err) 473 821 return dev_err_probe(dev, err, "Error writing register\n"); 822 + 823 + reg = ad3552r_calc_custom_gain(dac->ch_data[ch].p, dac->ch_data[ch].n, 824 + dac->ch_data[ch].gain_offset); 474 825 475 826 err = ad3552r_write_reg(dac, addr, reg); 476 827 if (err) ··· 455 860 static int ad3552r_configure_device(struct ad3552r_desc *dac) 456 861 { 457 862 struct device *dev = &dac->spi->dev; 458 - int err, cnt = 0, voltage, delta = 100000; 459 - u32 vals[2], val, ch; 863 + int err, cnt = 0; 864 + u32 val, ch; 460 865 461 866 dac->gpio_ldac = devm_gpiod_get_optional(dev, "ldac", GPIOD_OUT_HIGH); 462 867 if (IS_ERR(dac->gpio_ldac)) 463 868 return dev_err_probe(dev, PTR_ERR(dac->gpio_ldac), 464 869 "Error getting gpio ldac"); 465 870 466 - voltage = devm_regulator_get_enable_read_voltage(dev, "vref"); 467 - if (voltage < 0 && voltage != -ENODEV) 468 - return dev_err_probe(dev, voltage, "Error getting vref voltage\n"); 469 - 470 - if (voltage == -ENODEV) { 471 - if (device_property_read_bool(dev, "adi,vref-out-en")) 472 - val = AD3552R_INTERNAL_VREF_PIN_2P5V; 473 - else 474 - val = AD3552R_INTERNAL_VREF_PIN_FLOATING; 475 - } else { 476 - if (voltage > 2500000 + delta || voltage < 2500000 - delta) { 477 - dev_warn(dev, "vref-supply must be 2.5V"); 478 - return -EINVAL; 479 - } 480 - val = AD3552R_EXTERNAL_VREF_PIN_INPUT; 481 - } 871 + err = ad3552r_get_ref_voltage(dev, &val); 872 + if (err < 0) 873 + return err; 482 874 483 875 err = ad3552r_update_reg_field(dac, 484 - addr_mask_map[AD3552R_VREF_SELECT][0], 485 - addr_mask_map[AD3552R_VREF_SELECT][1], 486 - val); 876 + AD3552R_REG_ADDR_SH_REFERENCE_CONFIG, 877 + AD3552R_MASK_REFERENCE_VOLTAGE_SEL, 878 + FIELD_PREP(AD3552R_MASK_REFERENCE_VOLTAGE_SEL, val)); 487 879 if (err) 488 880 return err; 489 881 490 - err = device_property_read_u32(dev, "adi,sdo-drive-strength", &val); 882 + err = ad3552r_get_drive_strength(dev, &val); 491 883 if (!err) { 492 - if (val > 3) { 493 - dev_err(dev, "adi,sdo-drive-strength must be less than 4\n"); 494 - return -EINVAL; 495 - } 496 - 497 884 err = ad3552r_update_reg_field(dac, 498 - addr_mask_map[AD3552R_SDO_DRIVE_STRENGTH][0], 499 - addr_mask_map[AD3552R_SDO_DRIVE_STRENGTH][1], 500 - val); 885 + AD3552R_REG_ADDR_INTERFACE_CONFIG_D, 886 + AD3552R_MASK_SDO_DRIVE_STRENGTH, 887 + FIELD_PREP(AD3552R_MASK_SDO_DRIVE_STRENGTH, val)); 501 888 if (err) 502 889 return err; 503 890 } ··· 500 923 "reg must be less than %d\n", 501 924 dac->model_data->num_hw_channels); 502 925 503 - if (fwnode_property_present(child, "adi,output-range-microvolt")) { 504 - err = fwnode_property_read_u32_array(child, 505 - "adi,output-range-microvolt", 506 - vals, 507 - 2); 508 - if (err) 509 - return dev_err_probe(dev, err, 510 - "adi,output-range-microvolt property could not be parsed\n"); 926 + err = ad3552r_get_output_range(dev, dac->model_data, 927 + child, &val); 928 + if (err && err != -ENOENT) 929 + return err; 511 930 512 - err = ad3552r_find_range(dac->model_data, vals); 513 - if (err < 0) 514 - return dev_err_probe(dev, err, 515 - "Invalid adi,output-range-microvolt value\n"); 931 + if (!err) { 932 + if (ch == 0) 933 + val = FIELD_PREP(AD3552R_MASK_CH_OUTPUT_RANGE_SEL(0), val); 934 + else 935 + val = FIELD_PREP(AD3552R_MASK_CH_OUTPUT_RANGE_SEL(1), val); 516 936 517 - val = err; 518 - err = ad3552r_set_ch_value(dac, 519 - AD3552R_CH_OUTPUT_RANGE_SEL, 520 - ch, val); 937 + err = ad3552r_update_reg_field(dac, 938 + AD3552R_REG_ADDR_CH0_CH1_OUTPUT_RANGE, 939 + AD3552R_MASK_CH_OUTPUT_RANGE_SEL(ch), 940 + val); 521 941 if (err) 522 942 return err; 523 943 ··· 529 955 return err; 530 956 } 531 957 532 - ad3552r_calc_gain_and_offset(dac, ch); 958 + ad3552r_calc_gain_and_offset(&dac->ch_data[ch], dac->model_data); 533 959 dac->enabled_ch |= BIT(ch); 534 960 535 - err = ad3552r_set_ch_value(dac, AD3552R_CH_SELECT, ch, 1); 961 + if (ch == 0) 962 + val = FIELD_PREP(AD3552R_MASK_CH(0), 1); 963 + else 964 + val = FIELD_PREP(AD3552R_MASK_CH(1), 1); 965 + 966 + err = ad3552r_update_reg_field(dac, 967 + AD3552R_REG_ADDR_CH_SELECT_16B, 968 + AD3552R_MASK_CH(ch), val); 536 969 if (err < 0) 537 970 return err; 538 971 ··· 551 970 /* Disable unused channels */ 552 971 for_each_clear_bit(ch, &dac->enabled_ch, 553 972 dac->model_data->num_hw_channels) { 554 - err = ad3552r_set_ch_value(dac, AD3552R_CH_AMPLIFIER_POWERDOWN, 555 - ch, 1); 973 + if (ch == 0) 974 + val = FIELD_PREP(AD3552R_MASK_CH_AMPLIFIER_POWERDOWN(0), 1); 975 + else 976 + val = FIELD_PREP(AD3552R_MASK_CH_AMPLIFIER_POWERDOWN(1), 1); 977 + 978 + err = ad3552r_update_reg_field(dac, 979 + AD3552R_REG_ADDR_POWERDOWN_CONFIG, 980 + AD3552R_MASK_CH_AMPLIFIER_POWERDOWN(ch), 981 + val); 556 982 if (err) 557 983 return err; 558 984 } ··· 728 1140 MODULE_AUTHOR("Mihail Chindris <mihail.chindris@analog.com>"); 729 1141 MODULE_DESCRIPTION("Analog Device AD3552R DAC"); 730 1142 MODULE_LICENSE("GPL v2"); 1143 + MODULE_IMPORT_NS(IIO_AD3552R);
+228
drivers/iio/dac/ad3552r.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * AD3552R Digital <-> Analog converters common header 4 + * 5 + * Copyright 2021-2024 Analog Devices Inc. 6 + * Author: Angelo Dureghello <adureghello@baylibre.com> 7 + */ 8 + 9 + #ifndef __DRIVERS_IIO_DAC_AD3552R_H__ 10 + #define __DRIVERS_IIO_DAC_AD3552R_H__ 11 + 12 + /* Register addresses */ 13 + /* Primary address space */ 14 + #define AD3552R_REG_ADDR_INTERFACE_CONFIG_A 0x00 15 + #define AD3552R_MASK_SOFTWARE_RESET (BIT(7) | BIT(0)) 16 + #define AD3552R_MASK_ADDR_ASCENSION BIT(5) 17 + #define AD3552R_MASK_SDO_ACTIVE BIT(4) 18 + #define AD3552R_REG_ADDR_INTERFACE_CONFIG_B 0x01 19 + #define AD3552R_MASK_SINGLE_INST BIT(7) 20 + #define AD3552R_MASK_SHORT_INSTRUCTION BIT(3) 21 + #define AD3552R_REG_ADDR_DEVICE_CONFIG 0x02 22 + #define AD3552R_MASK_DEVICE_STATUS(n) BIT(4 + (n)) 23 + #define AD3552R_MASK_CUSTOM_MODES GENMASK(3, 2) 24 + #define AD3552R_MASK_OPERATING_MODES GENMASK(1, 0) 25 + #define AD3552R_REG_ADDR_CHIP_TYPE 0x03 26 + #define AD3552R_MASK_CLASS GENMASK(7, 0) 27 + #define AD3552R_REG_ADDR_PRODUCT_ID_L 0x04 28 + #define AD3552R_REG_ADDR_PRODUCT_ID_H 0x05 29 + #define AD3552R_REG_ADDR_CHIP_GRADE 0x06 30 + #define AD3552R_MASK_GRADE GENMASK(7, 4) 31 + #define AD3552R_MASK_DEVICE_REVISION GENMASK(3, 0) 32 + #define AD3552R_REG_ADDR_SCRATCH_PAD 0x0A 33 + #define AD3552R_REG_ADDR_SPI_REVISION 0x0B 34 + #define AD3552R_REG_ADDR_VENDOR_L 0x0C 35 + #define AD3552R_REG_ADDR_VENDOR_H 0x0D 36 + #define AD3552R_REG_ADDR_STREAM_MODE 0x0E 37 + #define AD3552R_MASK_LENGTH GENMASK(7, 0) 38 + #define AD3552R_REG_ADDR_TRANSFER_REGISTER 0x0F 39 + #define AD3552R_MASK_MULTI_IO_MODE GENMASK(7, 6) 40 + #define AD3552R_MASK_STREAM_LENGTH_KEEP_VALUE BIT(2) 41 + #define AD3552R_REG_ADDR_INTERFACE_CONFIG_C 0x10 42 + #define AD3552R_MASK_CRC_ENABLE \ 43 + (GENMASK(7, 6) | GENMASK(1, 0)) 44 + #define AD3552R_MASK_STRICT_REGISTER_ACCESS BIT(5) 45 + #define AD3552R_REG_ADDR_INTERFACE_STATUS_A 0x11 46 + #define AD3552R_MASK_INTERFACE_NOT_READY BIT(7) 47 + #define AD3552R_MASK_CLOCK_COUNTING_ERROR BIT(5) 48 + #define AD3552R_MASK_INVALID_OR_NO_CRC BIT(3) 49 + #define AD3552R_MASK_WRITE_TO_READ_ONLY_REGISTER BIT(2) 50 + #define AD3552R_MASK_PARTIAL_REGISTER_ACCESS BIT(1) 51 + #define AD3552R_MASK_REGISTER_ADDRESS_INVALID BIT(0) 52 + #define AD3552R_REG_ADDR_INTERFACE_CONFIG_D 0x14 53 + #define AD3552R_MASK_ALERT_ENABLE_PULLUP BIT(6) 54 + #define AD3552R_MASK_MEM_CRC_EN BIT(4) 55 + #define AD3552R_MASK_SDO_DRIVE_STRENGTH GENMASK(3, 2) 56 + #define AD3552R_MASK_DUAL_SPI_SYNCHROUNOUS_EN BIT(1) 57 + #define AD3552R_MASK_SPI_CONFIG_DDR BIT(0) 58 + #define AD3552R_REG_ADDR_SH_REFERENCE_CONFIG 0x15 59 + #define AD3552R_MASK_IDUMP_FAST_MODE BIT(6) 60 + #define AD3552R_MASK_SAMPLE_HOLD_DIFF_USER_EN BIT(5) 61 + #define AD3552R_MASK_SAMPLE_HOLD_USER_TRIM GENMASK(4, 3) 62 + #define AD3552R_MASK_SAMPLE_HOLD_USER_ENABLE BIT(2) 63 + #define AD3552R_MASK_REFERENCE_VOLTAGE_SEL GENMASK(1, 0) 64 + #define AD3552R_REG_ADDR_ERR_ALARM_MASK 0x16 65 + #define AD3552R_MASK_REF_RANGE_ALARM BIT(6) 66 + #define AD3552R_MASK_CLOCK_COUNT_ERR_ALARM BIT(5) 67 + #define AD3552R_MASK_MEM_CRC_ERR_ALARM BIT(4) 68 + #define AD3552R_MASK_SPI_CRC_ERR_ALARM BIT(3) 69 + #define AD3552R_MASK_WRITE_TO_READ_ONLY_ALARM BIT(2) 70 + #define AD3552R_MASK_PARTIAL_REGISTER_ACCESS_ALARM BIT(1) 71 + #define AD3552R_MASK_REGISTER_ADDRESS_INVALID_ALARM BIT(0) 72 + #define AD3552R_REG_ADDR_ERR_STATUS 0x17 73 + #define AD3552R_MASK_REF_RANGE_ERR_STATUS BIT(6) 74 + #define AD3552R_MASK_STREAM_EXCEEDS_DAC_ERR_STATUS BIT(5) 75 + #define AD3552R_MASK_MEM_CRC_ERR_STATUS BIT(4) 76 + #define AD3552R_MASK_RESET_STATUS BIT(0) 77 + #define AD3552R_REG_ADDR_POWERDOWN_CONFIG 0x18 78 + #define AD3552R_MASK_CH_DAC_POWERDOWN(ch) BIT(4 + (ch)) 79 + #define AD3552R_MASK_CH_AMPLIFIER_POWERDOWN(ch) BIT(ch) 80 + #define AD3552R_REG_ADDR_CH0_CH1_OUTPUT_RANGE 0x19 81 + #define AD3552R_MASK_CH0_RANGE GENMASK(2, 0) 82 + #define AD3552R_MASK_CH1_RANGE GENMASK(6, 4) 83 + #define AD3552R_MASK_CH_OUTPUT_RANGE GENMASK(7, 0) 84 + #define AD3552R_MASK_CH_OUTPUT_RANGE_SEL(ch) \ 85 + ((ch) ? GENMASK(7, 4) : GENMASK(3, 0)) 86 + #define AD3552R_REG_ADDR_CH_OFFSET(ch) (0x1B + (ch) * 2) 87 + #define AD3552R_MASK_CH_OFFSET_BITS_0_7 GENMASK(7, 0) 88 + #define AD3552R_REG_ADDR_CH_GAIN(ch) (0x1C + (ch) * 2) 89 + #define AD3552R_MASK_CH_RANGE_OVERRIDE BIT(7) 90 + #define AD3552R_MASK_CH_GAIN_SCALING_N GENMASK(6, 5) 91 + #define AD3552R_MASK_CH_GAIN_SCALING_P GENMASK(4, 3) 92 + #define AD3552R_MASK_CH_OFFSET_POLARITY BIT(2) 93 + #define AD3552R_MASK_CH_OFFSET_BIT_8 BIT(8) 94 + /* 95 + * Secondary region 96 + * For multibyte registers specify the highest address because the access is 97 + * done in descending order 98 + */ 99 + #define AD3552R_SECONDARY_REGION_START 0x28 100 + #define AD3552R_REG_ADDR_HW_LDAC_16B 0x28 101 + #define AD3552R_REG_ADDR_CH_DAC_16B(ch) (0x2C - (1 - (ch)) * 2) 102 + #define AD3552R_REG_ADDR_DAC_PAGE_MASK_16B 0x2E 103 + #define AD3552R_REG_ADDR_CH_SELECT_16B 0x2F 104 + #define AD3552R_REG_ADDR_INPUT_PAGE_MASK_16B 0x31 105 + #define AD3552R_REG_ADDR_SW_LDAC_16B 0x32 106 + #define AD3552R_REG_ADDR_CH_INPUT_16B(ch) (0x36 - (1 - (ch)) * 2) 107 + /* 3 bytes registers */ 108 + #define AD3552R_REG_START_24B 0x37 109 + #define AD3552R_REG_ADDR_HW_LDAC_24B 0x37 110 + #define AD3552R_REG_ADDR_CH_DAC_24B(ch) (0x3D - (1 - (ch)) * 3) 111 + #define AD3552R_REG_ADDR_DAC_PAGE_MASK_24B 0x40 112 + #define AD3552R_REG_ADDR_CH_SELECT_24B 0x41 113 + #define AD3552R_REG_ADDR_INPUT_PAGE_MASK_24B 0x44 114 + #define AD3552R_REG_ADDR_SW_LDAC_24B 0x45 115 + #define AD3552R_REG_ADDR_CH_INPUT_24B(ch) (0x4B - (1 - (ch)) * 3) 116 + 117 + #define AD3552R_MAX_CH 2 118 + #define AD3552R_MASK_CH(ch) BIT(ch) 119 + #define AD3552R_MASK_ALL_CH GENMASK(1, 0) 120 + #define AD3552R_MAX_REG_SIZE 3 121 + #define AD3552R_READ_BIT BIT(7) 122 + #define AD3552R_ADDR_MASK GENMASK(6, 0) 123 + #define AD3552R_MASK_DAC_12B GENMASK(15, 4) 124 + #define AD3552R_DEFAULT_CONFIG_B_VALUE 0x8 125 + #define AD3552R_SCRATCH_PAD_TEST_VAL1 0x34 126 + #define AD3552R_SCRATCH_PAD_TEST_VAL2 0xB2 127 + #define AD3552R_GAIN_SCALE 1000 128 + #define AD3552R_LDAC_PULSE_US 100 129 + 130 + #define AD3552R_CH0_ACTIVE BIT(0) 131 + #define AD3552R_CH1_ACTIVE BIT(1) 132 + 133 + #define AD3552R_MAX_RANGES 5 134 + #define AD3542R_MAX_RANGES 6 135 + #define AD3552R_QUAD_SPI 2 136 + 137 + extern const s32 ad3552r_ch_ranges[AD3552R_MAX_RANGES][2]; 138 + extern const s32 ad3542r_ch_ranges[AD3542R_MAX_RANGES][2]; 139 + 140 + enum ad3552r_id { 141 + AD3541R_ID = 0x400b, 142 + AD3542R_ID = 0x4009, 143 + AD3551R_ID = 0x400a, 144 + AD3552R_ID = 0x4008, 145 + }; 146 + 147 + struct ad3552r_model_data { 148 + const char *model_name; 149 + enum ad3552r_id chip_id; 150 + unsigned int num_hw_channels; 151 + const s32 (*ranges_table)[2]; 152 + int num_ranges; 153 + bool requires_output_range; 154 + }; 155 + 156 + struct ad3552r_ch_data { 157 + s32 scale_int; 158 + s32 scale_dec; 159 + s32 offset_int; 160 + s32 offset_dec; 161 + s16 gain_offset; 162 + u16 rfb; 163 + u8 n; 164 + u8 p; 165 + u8 range; 166 + bool range_override; 167 + }; 168 + 169 + enum ad3552r_ch_gain_scaling { 170 + /* Gain scaling of 1 */ 171 + AD3552R_CH_GAIN_SCALING_1, 172 + /* Gain scaling of 0.5 */ 173 + AD3552R_CH_GAIN_SCALING_0_5, 174 + /* Gain scaling of 0.25 */ 175 + AD3552R_CH_GAIN_SCALING_0_25, 176 + /* Gain scaling of 0.125 */ 177 + AD3552R_CH_GAIN_SCALING_0_125, 178 + }; 179 + 180 + enum ad3552r_ch_vref_select { 181 + /* Internal source with Vref I/O floating */ 182 + AD3552R_INTERNAL_VREF_PIN_FLOATING, 183 + /* Internal source with Vref I/O at 2.5V */ 184 + AD3552R_INTERNAL_VREF_PIN_2P5V, 185 + /* External source with Vref I/O as input */ 186 + AD3552R_EXTERNAL_VREF_PIN_INPUT 187 + }; 188 + 189 + enum ad3542r_ch_output_range { 190 + /* Range from 0 V to 2.5 V. Requires Rfb1x connection */ 191 + AD3542R_CH_OUTPUT_RANGE_0__2P5V, 192 + /* Range from 0 V to 3 V. Requires Rfb1x connection */ 193 + AD3542R_CH_OUTPUT_RANGE_0__3V, 194 + /* Range from 0 V to 5 V. Requires Rfb1x connection */ 195 + AD3542R_CH_OUTPUT_RANGE_0__5V, 196 + /* Range from 0 V to 10 V. Requires Rfb2x connection */ 197 + AD3542R_CH_OUTPUT_RANGE_0__10V, 198 + /* Range from -2.5 V to 7.5 V. Requires Rfb2x connection */ 199 + AD3542R_CH_OUTPUT_RANGE_NEG_2P5__7P5V, 200 + /* Range from -5 V to 5 V. Requires Rfb2x connection */ 201 + AD3542R_CH_OUTPUT_RANGE_NEG_5__5V, 202 + }; 203 + 204 + enum ad3552r_ch_output_range { 205 + /* Range from 0 V to 2.5 V. Requires Rfb1x connection */ 206 + AD3552R_CH_OUTPUT_RANGE_0__2P5V, 207 + /* Range from 0 V to 5 V. Requires Rfb1x connection */ 208 + AD3552R_CH_OUTPUT_RANGE_0__5V, 209 + /* Range from 0 V to 10 V. Requires Rfb2x connection */ 210 + AD3552R_CH_OUTPUT_RANGE_0__10V, 211 + /* Range from -5 V to 5 V. Requires Rfb2x connection */ 212 + AD3552R_CH_OUTPUT_RANGE_NEG_5__5V, 213 + /* Range from -10 V to 10 V. Requires Rfb4x connection */ 214 + AD3552R_CH_OUTPUT_RANGE_NEG_10__10V, 215 + }; 216 + 217 + int ad3552r_get_output_range(struct device *dev, 218 + const struct ad3552r_model_data *model_info, 219 + struct fwnode_handle *child, u32 *val); 220 + int ad3552r_get_custom_gain(struct device *dev, struct fwnode_handle *child, 221 + u8 *gs_p, u8 *gs_n, u16 *rfb, s16 *goffs); 222 + u16 ad3552r_calc_custom_gain(u8 p, u8 n, s16 goffs); 223 + int ad3552r_get_ref_voltage(struct device *dev, u32 *val); 224 + int ad3552r_get_drive_strength(struct device *dev, u32 *val); 225 + void ad3552r_calc_gain_and_offset(struct ad3552r_ch_data *ch_data, 226 + const struct ad3552r_model_data *model_data); 227 + 228 + #endif /* __DRIVERS_IIO_DAC_AD3552R_H__ */
+17 -68
drivers/iio/dac/ad5380.c
··· 47 47 * struct ad5380_state - driver instance specific data 48 48 * @regmap: regmap instance used by the device 49 49 * @chip_info: chip model specific constants, available modes etc 50 - * @vref_reg: vref supply regulator 51 50 * @vref: actual reference voltage used in uA 52 51 * @pwr_down: whether the chip is currently in power down mode 53 52 * @lock: lock to protect the data buffer during regmap ops ··· 54 55 struct ad5380_state { 55 56 struct regmap *regmap; 56 57 const struct ad5380_chip_info *chip_info; 57 - struct regulator *vref_reg; 58 58 int vref; 59 59 bool pwr_down; 60 60 struct mutex lock; ··· 339 341 }, 340 342 }; 341 343 342 - static int ad5380_alloc_channels(struct iio_dev *indio_dev) 344 + static int ad5380_alloc_channels(struct device *dev, struct iio_dev *indio_dev) 343 345 { 344 346 struct ad5380_state *st = iio_priv(indio_dev); 345 347 struct iio_chan_spec *channels; 346 348 unsigned int i; 347 349 348 - channels = kcalloc(st->chip_info->num_channels, 349 - sizeof(struct iio_chan_spec), GFP_KERNEL); 350 + channels = devm_kcalloc(dev, st->chip_info->num_channels, 351 + sizeof(struct iio_chan_spec), GFP_KERNEL); 350 352 351 353 if (!channels) 352 354 return -ENOMEM; ··· 377 379 } 378 380 379 381 st = iio_priv(indio_dev); 380 - dev_set_drvdata(dev, indio_dev); 381 382 382 383 st->chip_info = &ad5380_chip_info_tbl[type]; 383 384 st->regmap = regmap; ··· 388 391 389 392 mutex_init(&st->lock); 390 393 391 - ret = ad5380_alloc_channels(indio_dev); 392 - if (ret) { 393 - dev_err(dev, "Failed to allocate channel spec: %d\n", ret); 394 - return ret; 395 - } 394 + ret = ad5380_alloc_channels(dev, indio_dev); 395 + if (ret) 396 + return dev_err_probe(dev, ret, "Failed to allocate channel spec\n"); 396 397 397 398 if (st->chip_info->int_vref == 2500) 398 399 ctrl |= AD5380_CTRL_INT_VREF_2V5; 399 400 400 - st->vref_reg = devm_regulator_get(dev, "vref"); 401 - if (!IS_ERR(st->vref_reg)) { 402 - ret = regulator_enable(st->vref_reg); 403 - if (ret) { 404 - dev_err(dev, "Failed to enable vref regulators: %d\n", 405 - ret); 406 - goto error_free_reg; 407 - } 408 - 409 - ret = regulator_get_voltage(st->vref_reg); 410 - if (ret < 0) 411 - goto error_disable_reg; 412 - 413 - st->vref = ret / 1000; 414 - } else { 401 + ret = devm_regulator_get_enable_read_voltage(dev, "vref"); 402 + if (ret < 0 && ret != -ENODEV) 403 + return dev_err_probe(dev, ret, "Failed to get vref voltage\n"); 404 + if (ret == -ENODEV) { 415 405 st->vref = st->chip_info->int_vref; 416 406 ctrl |= AD5380_CTRL_INT_VREF_EN; 407 + } else { 408 + st->vref = ret / 1000; 417 409 } 418 410 419 411 ret = regmap_write(st->regmap, AD5380_REG_SF_CTRL, ctrl); 420 - if (ret) { 421 - dev_err(dev, "Failed to write to device: %d\n", ret); 422 - goto error_disable_reg; 423 - } 412 + if (ret) 413 + return dev_err_probe(dev, ret, "Failed to write to device\n"); 424 414 425 - ret = iio_device_register(indio_dev); 426 - if (ret) { 427 - dev_err(dev, "Failed to register iio device: %d\n", ret); 428 - goto error_disable_reg; 429 - } 415 + ret = devm_iio_device_register(dev, indio_dev); 416 + if (ret) 417 + return dev_err_probe(dev, ret, "Failed to register iio device\n"); 430 418 431 419 return 0; 432 - 433 - error_disable_reg: 434 - if (!IS_ERR(st->vref_reg)) 435 - regulator_disable(st->vref_reg); 436 - error_free_reg: 437 - kfree(indio_dev->channels); 438 - 439 - return ret; 440 - } 441 - 442 - static void ad5380_remove(struct device *dev) 443 - { 444 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 445 - struct ad5380_state *st = iio_priv(indio_dev); 446 - 447 - iio_device_unregister(indio_dev); 448 - 449 - kfree(indio_dev->channels); 450 - 451 - if (!IS_ERR(st->vref_reg)) 452 - regulator_disable(st->vref_reg); 453 420 } 454 421 455 422 static bool ad5380_reg_false(struct device *dev, unsigned int reg) ··· 447 486 return ad5380_probe(&spi->dev, regmap, id->driver_data, id->name); 448 487 } 449 488 450 - static void ad5380_spi_remove(struct spi_device *spi) 451 - { 452 - ad5380_remove(&spi->dev); 453 - } 454 - 455 489 static const struct spi_device_id ad5380_spi_ids[] = { 456 490 { "ad5380-3", ID_AD5380_3 }, 457 491 { "ad5380-5", ID_AD5380_5 }, ··· 473 517 .name = "ad5380", 474 518 }, 475 519 .probe = ad5380_spi_probe, 476 - .remove = ad5380_spi_remove, 477 520 .id_table = ad5380_spi_ids, 478 521 }; 479 522 ··· 514 559 return ad5380_probe(&i2c->dev, regmap, id->driver_data, id->name); 515 560 } 516 561 517 - static void ad5380_i2c_remove(struct i2c_client *i2c) 518 - { 519 - ad5380_remove(&i2c->dev); 520 - } 521 - 522 562 static const struct i2c_device_id ad5380_i2c_ids[] = { 523 563 { "ad5380-3", ID_AD5380_3 }, 524 564 { "ad5380-5", ID_AD5380_5 }, ··· 540 590 .name = "ad5380", 541 591 }, 542 592 .probe = ad5380_i2c_probe, 543 - .remove = ad5380_i2c_remove, 544 593 .id_table = ad5380_i2c_ids, 545 594 }; 546 595
+1 -1
drivers/iio/dac/ad5421.c
··· 384 384 385 385 static int ad5421_write_event_config(struct iio_dev *indio_dev, 386 386 const struct iio_chan_spec *chan, enum iio_event_type type, 387 - enum iio_event_direction dir, int state) 387 + enum iio_event_direction dir, bool state) 388 388 { 389 389 struct ad5421_state *st = iio_priv(indio_dev); 390 390 unsigned int mask;
+16 -61
drivers/iio/dac/ad5446.c
··· 32 32 * struct ad5446_state - driver instance specific data 33 33 * @dev: this device 34 34 * @chip_info: chip model specific constants, available modes etc 35 - * @reg: supply regulator 36 35 * @vref_mv: actual reference voltage used 37 36 * @cached_val: store/retrieve values during power down 38 37 * @pwr_down_mode: power down mode (1k, 100k or tristate) ··· 42 43 struct ad5446_state { 43 44 struct device *dev; 44 45 const struct ad5446_chip_info *chip_info; 45 - struct regulator *reg; 46 46 unsigned short vref_mv; 47 47 unsigned cached_val; 48 48 unsigned pwr_down_mode; ··· 224 226 { 225 227 struct ad5446_state *st; 226 228 struct iio_dev *indio_dev; 227 - struct regulator *reg; 228 - int ret, voltage_uv = 0; 229 - 230 - reg = devm_regulator_get(dev, "vcc"); 231 - if (!IS_ERR(reg)) { 232 - ret = regulator_enable(reg); 233 - if (ret) 234 - return ret; 235 - 236 - ret = regulator_get_voltage(reg); 237 - if (ret < 0) 238 - goto error_disable_reg; 239 - 240 - voltage_uv = ret; 241 - } 229 + int ret; 242 230 243 231 indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 244 - if (indio_dev == NULL) { 245 - ret = -ENOMEM; 246 - goto error_disable_reg; 247 - } 232 + if (!indio_dev) 233 + return -ENOMEM; 234 + 248 235 st = iio_priv(indio_dev); 249 236 st->chip_info = chip_info; 250 237 251 - dev_set_drvdata(dev, indio_dev); 252 - st->reg = reg; 253 238 st->dev = dev; 254 239 255 240 indio_dev->name = name; ··· 245 264 246 265 st->pwr_down_mode = MODE_PWRDWN_1k; 247 266 248 - if (st->chip_info->int_vref_mv) 249 - st->vref_mv = st->chip_info->int_vref_mv; 250 - else if (voltage_uv) 251 - st->vref_mv = voltage_uv / 1000; 252 - else 253 - dev_warn(dev, "reference voltage unspecified\n"); 267 + ret = devm_regulator_get_enable_read_voltage(dev, "vcc"); 268 + if (ret < 0 && ret != -ENODEV) 269 + return ret; 270 + if (ret == -ENODEV) { 271 + if (chip_info->int_vref_mv) 272 + st->vref_mv = chip_info->int_vref_mv; 273 + else 274 + dev_warn(dev, "reference voltage unspecified\n"); 275 + } else { 276 + st->vref_mv = ret / 1000; 277 + } 254 278 255 - ret = iio_device_register(indio_dev); 256 - if (ret) 257 - goto error_disable_reg; 258 - 259 - return 0; 260 - 261 - error_disable_reg: 262 - if (!IS_ERR(reg)) 263 - regulator_disable(reg); 264 - return ret; 265 - } 266 - 267 - static void ad5446_remove(struct device *dev) 268 - { 269 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 270 - struct ad5446_state *st = iio_priv(indio_dev); 271 - 272 - iio_device_unregister(indio_dev); 273 - if (!IS_ERR(st->reg)) 274 - regulator_disable(st->reg); 279 + return devm_iio_device_register(dev, indio_dev); 275 280 } 276 281 277 282 #if IS_ENABLED(CONFIG_SPI_MASTER) ··· 458 491 &ad5446_spi_chip_info[id->driver_data]); 459 492 } 460 493 461 - static void ad5446_spi_remove(struct spi_device *spi) 462 - { 463 - ad5446_remove(&spi->dev); 464 - } 465 - 466 494 static struct spi_driver ad5446_spi_driver = { 467 495 .driver = { 468 496 .name = "ad5446", 469 497 .of_match_table = ad5446_of_ids, 470 498 }, 471 499 .probe = ad5446_spi_probe, 472 - .remove = ad5446_spi_remove, 473 500 .id_table = ad5446_spi_ids, 474 501 }; 475 502 ··· 536 575 &ad5446_i2c_chip_info[id->driver_data]); 537 576 } 538 577 539 - static void ad5446_i2c_remove(struct i2c_client *i2c) 540 - { 541 - ad5446_remove(&i2c->dev); 542 - } 543 - 544 578 static const struct i2c_device_id ad5446_i2c_ids[] = { 545 579 {"ad5301", ID_AD5602}, 546 580 {"ad5311", ID_AD5612}, ··· 552 596 .name = "ad5446", 553 597 }, 554 598 .probe = ad5446_i2c_probe, 555 - .remove = ad5446_i2c_remove, 556 599 .id_table = ad5446_i2c_ids, 557 600 }; 558 601
+14 -45
drivers/iio/dac/ad5504.c
··· 273 273 const struct ad5504_platform_data *pdata = dev_get_platdata(&spi->dev); 274 274 struct iio_dev *indio_dev; 275 275 struct ad5504_state *st; 276 - struct regulator *reg; 277 - int ret, voltage_uv = 0; 276 + int ret; 278 277 279 278 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 280 279 if (!indio_dev) 281 280 return -ENOMEM; 282 - reg = devm_regulator_get(&spi->dev, "vcc"); 283 - if (!IS_ERR(reg)) { 284 - ret = regulator_enable(reg); 285 - if (ret) 286 - return ret; 287 281 288 - ret = regulator_get_voltage(reg); 289 - if (ret < 0) 290 - goto error_disable_reg; 282 + st = iio_priv(indio_dev); 291 283 292 - voltage_uv = ret; 284 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vcc"); 285 + if (ret < 0 && ret != -ENODEV) 286 + return ret; 287 + if (ret == -ENODEV) { 288 + if (pdata->vref_mv) 289 + st->vref_mv = pdata->vref_mv; 290 + else 291 + dev_warn(&spi->dev, "reference voltage unspecified\n"); 292 + } else { 293 + st->vref_mv = ret / 1000; 293 294 } 294 295 295 - spi_set_drvdata(spi, indio_dev); 296 - st = iio_priv(indio_dev); 297 - if (voltage_uv) 298 - st->vref_mv = voltage_uv / 1000; 299 - else if (pdata) 300 - st->vref_mv = pdata->vref_mv; 301 - else 302 - dev_warn(&spi->dev, "reference voltage unspecified\n"); 303 - 304 - st->reg = reg; 305 296 st->spi = spi; 306 297 indio_dev->name = spi_get_device_id(st->spi)->name; 307 298 indio_dev->info = &ad5504_info; ··· 311 320 spi_get_device_id(st->spi)->name, 312 321 indio_dev); 313 322 if (ret) 314 - goto error_disable_reg; 323 + return ret; 315 324 } 316 325 317 - ret = iio_device_register(indio_dev); 318 - if (ret) 319 - goto error_disable_reg; 320 - 321 - return 0; 322 - 323 - error_disable_reg: 324 - if (!IS_ERR(reg)) 325 - regulator_disable(reg); 326 - 327 - return ret; 328 - } 329 - 330 - static void ad5504_remove(struct spi_device *spi) 331 - { 332 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 333 - struct ad5504_state *st = iio_priv(indio_dev); 334 - 335 - iio_device_unregister(indio_dev); 336 - 337 - if (!IS_ERR(st->reg)) 338 - regulator_disable(st->reg); 326 + return devm_iio_device_register(&spi->dev, indio_dev); 339 327 } 340 328 341 329 static const struct spi_device_id ad5504_id[] = { ··· 329 359 .name = "ad5504", 330 360 }, 331 361 .probe = ad5504_probe, 332 - .remove = ad5504_remove, 333 362 .id_table = ad5504_id, 334 363 }; 335 364 module_spi_driver(ad5504_driver);
-1
drivers/iio/dac/ad5624r.h
··· 54 54 struct ad5624r_state { 55 55 struct spi_device *us; 56 56 const struct ad5624r_chip_info *chip_info; 57 - struct regulator *reg; 58 57 unsigned short vref_mv; 59 58 unsigned pwr_down_mask; 60 59 unsigned pwr_down_mode;
+12 -57
drivers/iio/dac/ad5624r_spi.c
··· 223 223 { 224 224 struct ad5624r_state *st; 225 225 struct iio_dev *indio_dev; 226 - int ret, voltage_uv = 0; 226 + bool external_vref; 227 + int ret; 227 228 228 229 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 229 230 if (!indio_dev) 230 231 return -ENOMEM; 231 232 st = iio_priv(indio_dev); 232 - st->reg = devm_regulator_get_optional(&spi->dev, "vref"); 233 - if (!IS_ERR(st->reg)) { 234 - ret = regulator_enable(st->reg); 235 - if (ret) 236 - return ret; 237 - 238 - ret = regulator_get_voltage(st->reg); 239 - if (ret < 0) 240 - goto error_disable_reg; 241 - 242 - voltage_uv = ret; 243 - } else { 244 - if (PTR_ERR(st->reg) != -ENODEV) 245 - return PTR_ERR(st->reg); 233 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); 234 + if (ret == -ENODEV) 246 235 /* 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; 236 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vcc"); 237 + if (ret < 0 && ret != -ENODEV) 238 + return ret; 252 239 253 - ret = regulator_get_voltage(st->reg); 254 - if (ret < 0) 255 - goto error_disable_reg; 240 + external_vref = ret != -ENODEV; 241 + st->vref_mv = external_vref ? ret / 1000 : st->chip_info->int_vref_mv; 256 242 257 - voltage_uv = ret; 258 - } 259 - } 260 - 261 - spi_set_drvdata(spi, indio_dev); 262 243 st->chip_info = 263 244 &ad5624r_chip_info_tbl[spi_get_device_id(spi)->driver_data]; 264 - 265 - if (voltage_uv) 266 - st->vref_mv = voltage_uv / 1000; 267 - else 268 - st->vref_mv = st->chip_info->int_vref_mv; 269 245 270 246 st->us = spi; 271 247 ··· 252 276 indio_dev->num_channels = AD5624R_DAC_CHANNELS; 253 277 254 278 ret = ad5624r_spi_write(spi, AD5624R_CMD_INTERNAL_REFER_SETUP, 0, 255 - !!voltage_uv, 16); 279 + external_vref, 16); 256 280 if (ret) 257 - goto error_disable_reg; 281 + return ret; 258 282 259 - ret = iio_device_register(indio_dev); 260 - if (ret) 261 - goto error_disable_reg; 262 - 263 - return 0; 264 - 265 - error_disable_reg: 266 - if (!IS_ERR(st->reg)) 267 - regulator_disable(st->reg); 268 - 269 - return ret; 270 - } 271 - 272 - static void ad5624r_remove(struct spi_device *spi) 273 - { 274 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 275 - struct ad5624r_state *st = iio_priv(indio_dev); 276 - 277 - iio_device_unregister(indio_dev); 278 - if (!IS_ERR(st->reg)) 279 - regulator_disable(st->reg); 283 + return devm_iio_device_register(&spi->dev, indio_dev); 280 284 } 281 285 282 286 static const struct spi_device_id ad5624r_id[] = { ··· 275 319 .name = "ad5624r", 276 320 }, 277 321 .probe = ad5624r_probe, 278 - .remove = ad5624r_remove, 279 322 .id_table = ad5624r_id, 280 323 }; 281 324 module_spi_driver(ad5624r_driver);
+23 -86
drivers/iio/dac/ad5761.c
··· 53 53 /** 54 54 * struct ad5761_state - driver instance specific data 55 55 * @spi: spi_device 56 - * @vref_reg: reference voltage regulator 57 56 * @use_intref: true when the internal voltage reference is used 58 57 * @vref: actual voltage reference in mVolts 59 58 * @range: output range mode used ··· 61 62 */ 62 63 struct ad5761_state { 63 64 struct spi_device *spi; 64 - struct regulator *vref_reg; 65 65 struct mutex lock; 66 66 67 67 bool use_intref; ··· 285 287 }, 286 288 }; 287 289 288 - static int ad5761_get_vref(struct ad5761_state *st, 289 - const struct ad5761_chip_info *chip_info) 290 - { 291 - int ret; 292 - 293 - st->vref_reg = devm_regulator_get_optional(&st->spi->dev, "vref"); 294 - if (PTR_ERR(st->vref_reg) == -ENODEV) { 295 - /* Use Internal regulator */ 296 - if (!chip_info->int_vref) { 297 - dev_err(&st->spi->dev, 298 - "Voltage reference not found\n"); 299 - return -EIO; 300 - } 301 - 302 - st->use_intref = true; 303 - st->vref = chip_info->int_vref; 304 - return 0; 305 - } 306 - 307 - if (IS_ERR(st->vref_reg)) { 308 - dev_err(&st->spi->dev, 309 - "Error getting voltage reference regulator\n"); 310 - return PTR_ERR(st->vref_reg); 311 - } 312 - 313 - ret = regulator_enable(st->vref_reg); 314 - if (ret) { 315 - dev_err(&st->spi->dev, 316 - "Failed to enable voltage reference\n"); 317 - return ret; 318 - } 319 - 320 - ret = regulator_get_voltage(st->vref_reg); 321 - if (ret < 0) { 322 - dev_err(&st->spi->dev, 323 - "Failed to get voltage reference value\n"); 324 - goto disable_regulator_vref; 325 - } 326 - 327 - if (ret < 2000000 || ret > 3000000) { 328 - dev_warn(&st->spi->dev, 329 - "Invalid external voltage ref. value %d uV\n", ret); 330 - ret = -EIO; 331 - goto disable_regulator_vref; 332 - } 333 - 334 - st->vref = ret / 1000; 335 - st->use_intref = false; 336 - 337 - return 0; 338 - 339 - disable_regulator_vref: 340 - regulator_disable(st->vref_reg); 341 - st->vref_reg = NULL; 342 - return ret; 343 - } 344 - 345 290 static int ad5761_probe(struct spi_device *spi) 346 291 { 347 292 struct iio_dev *iio_dev; ··· 302 361 st = iio_priv(iio_dev); 303 362 304 363 st->spi = spi; 305 - spi_set_drvdata(spi, iio_dev); 306 364 307 - ret = ad5761_get_vref(st, chip_info); 308 - if (ret) 309 - return ret; 365 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); 366 + if (ret < 0 && ret != -ENODEV) 367 + return dev_err_probe(&spi->dev, ret, 368 + "Failed to get voltage reference value\n"); 369 + if (ret == -ENODEV) { 370 + /* Use Internal regulator */ 371 + if (!chip_info->int_vref) 372 + return dev_err_probe(&spi->dev, -EIO, 373 + "Voltage reference not found\n"); 374 + 375 + st->use_intref = true; 376 + st->vref = chip_info->int_vref; 377 + } else { 378 + if (ret < 2000000 || ret > 3000000) 379 + return dev_err_probe(&spi->dev, -EIO, 380 + "Invalid external voltage ref. value %d uV\n", 381 + ret); 382 + 383 + st->use_intref = false; 384 + st->vref = ret / 1000; 385 + } 310 386 311 387 if (pdata) 312 388 voltage_range = pdata->voltage_range; ··· 332 374 333 375 ret = ad5761_spi_set_range(st, voltage_range); 334 376 if (ret) 335 - goto disable_regulator_err; 377 + return ret; 336 378 337 379 iio_dev->info = &ad5761_info; 338 380 iio_dev->modes = INDIO_DIRECT_MODE; 339 381 iio_dev->channels = &chip_info->channel; 340 382 iio_dev->num_channels = 1; 341 383 iio_dev->name = spi_get_device_id(st->spi)->name; 342 - ret = iio_device_register(iio_dev); 343 - if (ret) 344 - goto disable_regulator_err; 345 384 346 - return 0; 347 - 348 - disable_regulator_err: 349 - if (!IS_ERR_OR_NULL(st->vref_reg)) 350 - regulator_disable(st->vref_reg); 351 - 352 - return ret; 353 - } 354 - 355 - static void ad5761_remove(struct spi_device *spi) 356 - { 357 - struct iio_dev *iio_dev = spi_get_drvdata(spi); 358 - struct ad5761_state *st = iio_priv(iio_dev); 359 - 360 - iio_device_unregister(iio_dev); 361 - 362 - if (!IS_ERR_OR_NULL(st->vref_reg)) 363 - regulator_disable(st->vref_reg); 385 + return devm_iio_device_register(&spi->dev, iio_dev); 364 386 } 365 387 366 388 static const struct spi_device_id ad5761_id[] = { ··· 357 419 .name = "ad5761", 358 420 }, 359 421 .probe = ad5761_probe, 360 - .remove = ad5761_remove, 361 422 .id_table = ad5761_id, 362 423 }; 363 424 module_spi_driver(ad5761_driver);
+5 -36
drivers/iio/dac/ad5770r.c
··· 122 122 * struct ad5770r_state - driver instance specific data 123 123 * @spi: spi_device 124 124 * @regmap: regmap 125 - * @vref_reg: fixed regulator for reference configuration 126 125 * @gpio_reset: gpio descriptor 127 126 * @output_mode: array contains channels output ranges 128 127 * @vref: reference value ··· 133 134 struct ad5770r_state { 134 135 struct spi_device *spi; 135 136 struct regmap *regmap; 136 - struct regulator *vref_reg; 137 137 struct gpio_desc *gpio_reset; 138 138 struct ad5770r_out_range output_mode[AD5770R_MAX_CHANNELS]; 139 139 int vref; ··· 589 591 return ret; 590 592 } 591 593 592 - static void ad5770r_disable_regulator(void *data) 593 - { 594 - struct ad5770r_state *st = data; 595 - 596 - regulator_disable(st->vref_reg); 597 - } 598 - 599 594 static int ad5770r_probe(struct spi_device *spi) 600 595 { 601 596 struct ad5770r_state *st; ··· 613 622 } 614 623 st->regmap = regmap; 615 624 616 - st->vref_reg = devm_regulator_get_optional(&spi->dev, "vref"); 617 - if (!IS_ERR(st->vref_reg)) { 618 - ret = regulator_enable(st->vref_reg); 619 - if (ret) { 620 - dev_err(&spi->dev, 621 - "Failed to enable vref regulators: %d\n", ret); 622 - return ret; 623 - } 625 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); 626 + if (ret < 0 && ret != -ENODEV) 627 + return dev_err_probe(&spi->dev, ret, "Failed to get vref voltage\n"); 624 628 625 - ret = devm_add_action_or_reset(&spi->dev, 626 - ad5770r_disable_regulator, 627 - st); 628 - if (ret < 0) 629 - return ret; 630 - 631 - ret = regulator_get_voltage(st->vref_reg); 632 - if (ret < 0) 633 - return ret; 634 - 635 - st->vref = ret / 1000; 636 - } else { 637 - if (PTR_ERR(st->vref_reg) == -ENODEV) { 638 - st->vref = AD5770R_LOW_VREF_mV; 639 - st->internal_ref = true; 640 - } else { 641 - return PTR_ERR(st->vref_reg); 642 - } 643 - } 629 + st->internal_ref = ret == -ENODEV; 630 + st->vref = st->internal_ref ? AD5770R_LOW_VREF_mV : ret / 1000; 644 631 645 632 indio_dev->name = spi_get_device_id(spi)->name; 646 633 indio_dev->info = &ad5770r_info;
+92 -111
drivers/iio/dac/ad5791.c
··· 9 9 #include <linux/interrupt.h> 10 10 #include <linux/fs.h> 11 11 #include <linux/device.h> 12 + #include <linux/delay.h> 12 13 #include <linux/kernel.h> 13 14 #include <linux/spi/spi.h> 14 15 #include <linux/slab.h> ··· 62 61 63 62 /** 64 63 * struct ad5791_chip_info - chip specific information 64 + * @name: name of the dac chip 65 + * @channel: channel specification 65 66 * @get_lin_comp: function pointer to the device specific function 66 67 */ 67 - 68 68 struct ad5791_chip_info { 69 - int (*get_lin_comp) (unsigned int span); 69 + const char *name; 70 + const struct iio_chan_spec channel; 71 + int (*get_lin_comp)(unsigned int span); 70 72 }; 71 73 72 74 /** ··· 77 73 * @spi: spi_device 78 74 * @reg_vdd: positive supply regulator 79 75 * @reg_vss: negative supply regulator 76 + * @gpio_reset: reset gpio 77 + * @gpio_clear: clear gpio 78 + * @gpio_ldac: load dac gpio 80 79 * @chip_info: chip model specific constants 81 80 * @vref_mv: actual reference voltage used 82 81 * @vref_neg_mv: voltage of the negative supply ··· 92 85 struct spi_device *spi; 93 86 struct regulator *reg_vdd; 94 87 struct regulator *reg_vss; 88 + struct gpio_desc *gpio_reset; 89 + struct gpio_desc *gpio_clear; 90 + struct gpio_desc *gpio_ldac; 95 91 const struct ad5791_chip_info *chip_info; 96 92 unsigned short vref_mv; 97 93 unsigned int vref_neg_mv; ··· 106 96 __be32 d32; 107 97 u8 d8[4]; 108 98 } data[3] __aligned(IIO_DMA_MINALIGN); 109 - }; 110 - 111 - enum ad5791_supported_device_ids { 112 - ID_AD5760, 113 - ID_AD5780, 114 - ID_AD5781, 115 - ID_AD5791, 116 99 }; 117 100 118 101 static int ad5791_spi_write(struct ad5791_state *st, u8 addr, u32 val) ··· 231 228 else 232 229 return AD5780_LINCOMP_10_20; 233 230 } 234 - static const struct ad5791_chip_info ad5791_chip_info_tbl[] = { 235 - [ID_AD5760] = { 236 - .get_lin_comp = ad5780_get_lin_comp, 237 - }, 238 - [ID_AD5780] = { 239 - .get_lin_comp = ad5780_get_lin_comp, 240 - }, 241 - [ID_AD5781] = { 242 - .get_lin_comp = ad5791_get_lin_comp, 243 - }, 244 - [ID_AD5791] = { 245 - .get_lin_comp = ad5791_get_lin_comp, 246 - }, 247 - }; 248 231 249 232 static int ad5791_read_raw(struct iio_dev *indio_dev, 250 233 struct iio_chan_spec const *chan, ··· 278 289 { }, 279 290 }; 280 291 281 - #define AD5791_CHAN(bits, _shift) { \ 282 - .type = IIO_VOLTAGE, \ 283 - .output = 1, \ 284 - .indexed = 1, \ 285 - .address = AD5791_ADDR_DAC0, \ 286 - .channel = 0, \ 287 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 288 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 289 - BIT(IIO_CHAN_INFO_OFFSET), \ 290 - .scan_type = { \ 291 - .sign = 'u', \ 292 - .realbits = (bits), \ 293 - .storagebits = 24, \ 294 - .shift = (_shift), \ 295 - }, \ 296 - .ext_info = ad5791_ext_info, \ 292 + #define AD5791_DEFINE_CHIP_INFO(_name, bits, _shift, _lin_comp) \ 293 + static const struct ad5791_chip_info _name##_chip_info = { \ 294 + .name = #_name, \ 295 + .get_lin_comp = &(_lin_comp), \ 296 + .channel = { \ 297 + .type = IIO_VOLTAGE, \ 298 + .output = 1, \ 299 + .indexed = 1, \ 300 + .address = AD5791_ADDR_DAC0, \ 301 + .channel = 0, \ 302 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 303 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 304 + BIT(IIO_CHAN_INFO_OFFSET), \ 305 + .scan_type = { \ 306 + .sign = 'u', \ 307 + .realbits = (bits), \ 308 + .storagebits = 24, \ 309 + .shift = (_shift), \ 310 + }, \ 311 + .ext_info = ad5791_ext_info, \ 312 + }, \ 297 313 } 298 314 299 - static const struct iio_chan_spec ad5791_channels[] = { 300 - [ID_AD5760] = AD5791_CHAN(16, 4), 301 - [ID_AD5780] = AD5791_CHAN(18, 2), 302 - [ID_AD5781] = AD5791_CHAN(18, 2), 303 - [ID_AD5791] = AD5791_CHAN(20, 0) 304 - }; 315 + AD5791_DEFINE_CHIP_INFO(ad5760, 16, 4, ad5780_get_lin_comp); 316 + AD5791_DEFINE_CHIP_INFO(ad5780, 18, 2, ad5780_get_lin_comp); 317 + AD5791_DEFINE_CHIP_INFO(ad5781, 18, 2, ad5791_get_lin_comp); 318 + AD5791_DEFINE_CHIP_INFO(ad5790, 20, 0, ad5791_get_lin_comp); 319 + AD5791_DEFINE_CHIP_INFO(ad5791, 20, 0, ad5791_get_lin_comp); 305 320 306 321 static int ad5791_write_raw(struct iio_dev *indio_dev, 307 322 struct iio_chan_spec const *chan, ··· 344 351 if (!indio_dev) 345 352 return -ENOMEM; 346 353 st = iio_priv(indio_dev); 347 - st->reg_vdd = devm_regulator_get(&spi->dev, "vdd"); 348 - if (!IS_ERR(st->reg_vdd)) { 349 - ret = regulator_enable(st->reg_vdd); 350 - if (ret) 351 - return ret; 352 354 353 - ret = regulator_get_voltage(st->reg_vdd); 354 - if (ret < 0) 355 - goto error_disable_reg_pos; 355 + st->gpio_reset = devm_gpiod_get_optional(&spi->dev, "reset", 356 + GPIOD_OUT_HIGH); 357 + if (IS_ERR(st->gpio_reset)) 358 + return PTR_ERR(st->gpio_reset); 356 359 357 - pos_voltage_uv = ret; 358 - } 360 + st->gpio_clear = devm_gpiod_get_optional(&spi->dev, "clear", 361 + GPIOD_OUT_LOW); 362 + if (IS_ERR(st->gpio_clear)) 363 + return PTR_ERR(st->gpio_clear); 359 364 360 - st->reg_vss = devm_regulator_get(&spi->dev, "vss"); 361 - if (!IS_ERR(st->reg_vss)) { 362 - ret = regulator_enable(st->reg_vss); 363 - if (ret) 364 - goto error_disable_reg_pos; 365 - 366 - ret = regulator_get_voltage(st->reg_vss); 367 - if (ret < 0) 368 - goto error_disable_reg_neg; 369 - 370 - neg_voltage_uv = ret; 371 - } 365 + st->gpio_ldac = devm_gpiod_get_optional(&spi->dev, "ldac", 366 + GPIOD_OUT_HIGH); 367 + if (IS_ERR(st->gpio_ldac)) 368 + return PTR_ERR(st->gpio_ldac); 372 369 373 370 st->pwr_down = true; 374 371 st->spi = spi; ··· 369 386 use_rbuf_gain2 = device_property_read_bool(&spi->dev, 370 387 "adi,rbuf-gain2-en"); 371 388 372 - if (!IS_ERR(st->reg_vss) && !IS_ERR(st->reg_vdd)) { 389 + pos_voltage_uv = devm_regulator_get_enable_read_voltage(&spi->dev, "vdd"); 390 + if (pos_voltage_uv < 0 && pos_voltage_uv != -ENODEV) 391 + return dev_err_probe(&spi->dev, pos_voltage_uv, 392 + "failed to get vdd voltage\n"); 393 + 394 + neg_voltage_uv = devm_regulator_get_enable_read_voltage(&spi->dev, "vss"); 395 + if (neg_voltage_uv < 0 && neg_voltage_uv != -ENODEV) 396 + return dev_err_probe(&spi->dev, neg_voltage_uv, 397 + "failed to get vss voltage\n"); 398 + 399 + if (neg_voltage_uv >= 0 && pos_voltage_uv >= 0) { 373 400 st->vref_mv = (pos_voltage_uv + neg_voltage_uv) / 1000; 374 401 st->vref_neg_mv = neg_voltage_uv / 1000; 375 402 } else if (pdata) { ··· 389 396 dev_warn(&spi->dev, "reference voltage unspecified\n"); 390 397 } 391 398 392 - ret = ad5791_spi_write(st, AD5791_ADDR_SW_CTRL, AD5791_SWCTRL_RESET); 393 - if (ret) 394 - goto error_disable_reg_neg; 399 + if (st->gpio_reset) { 400 + fsleep(20); 401 + gpiod_set_value_cansleep(st->gpio_reset, 0); 402 + } else { 403 + ret = ad5791_spi_write(st, AD5791_ADDR_SW_CTRL, AD5791_SWCTRL_RESET); 404 + if (ret) 405 + return dev_err_probe(&spi->dev, ret, "fail to reset\n"); 406 + } 395 407 396 - st->chip_info = &ad5791_chip_info_tbl[spi_get_device_id(spi) 397 - ->driver_data]; 398 - 408 + st->chip_info = spi_get_device_match_data(spi); 409 + if (!st->chip_info) 410 + return dev_err_probe(&spi->dev, -EINVAL, "no chip info\n"); 399 411 400 412 st->ctrl = AD5761_CTRL_LINCOMP(st->chip_info->get_lin_comp(st->vref_mv)) 401 413 | (use_rbuf_gain2 ? 0 : AD5791_CTRL_RBUF) | ··· 409 411 ret = ad5791_spi_write(st, AD5791_ADDR_CTRL, st->ctrl | 410 412 AD5791_CTRL_OPGND | AD5791_CTRL_DACTRI); 411 413 if (ret) 412 - goto error_disable_reg_neg; 414 + return dev_err_probe(&spi->dev, ret, "fail to write ctrl register\n"); 413 415 414 - spi_set_drvdata(spi, indio_dev); 415 416 indio_dev->info = &ad5791_info; 416 417 indio_dev->modes = INDIO_DIRECT_MODE; 417 - indio_dev->channels 418 - = &ad5791_channels[spi_get_device_id(spi)->driver_data]; 418 + indio_dev->channels = &st->chip_info->channel; 419 419 indio_dev->num_channels = 1; 420 - indio_dev->name = spi_get_device_id(st->spi)->name; 421 - ret = iio_device_register(indio_dev); 422 - if (ret) 423 - goto error_disable_reg_neg; 424 - 425 - return 0; 426 - 427 - error_disable_reg_neg: 428 - if (!IS_ERR(st->reg_vss)) 429 - regulator_disable(st->reg_vss); 430 - error_disable_reg_pos: 431 - if (!IS_ERR(st->reg_vdd)) 432 - regulator_disable(st->reg_vdd); 433 - return ret; 420 + indio_dev->name = st->chip_info->name; 421 + return devm_iio_device_register(&spi->dev, indio_dev); 434 422 } 435 423 436 - static void ad5791_remove(struct spi_device *spi) 437 - { 438 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 439 - struct ad5791_state *st = iio_priv(indio_dev); 440 - 441 - iio_device_unregister(indio_dev); 442 - if (!IS_ERR(st->reg_vdd)) 443 - regulator_disable(st->reg_vdd); 444 - 445 - if (!IS_ERR(st->reg_vss)) 446 - regulator_disable(st->reg_vss); 447 - } 424 + static const struct of_device_id ad5791_of_match[] = { 425 + { .compatible = "adi,ad5760", .data = &ad5760_chip_info }, 426 + { .compatible = "adi,ad5780", .data = &ad5780_chip_info }, 427 + { .compatible = "adi,ad5781", .data = &ad5781_chip_info }, 428 + { .compatible = "adi,ad5790", .data = &ad5790_chip_info }, 429 + { .compatible = "adi,ad5791", .data = &ad5791_chip_info }, 430 + { } 431 + }; 432 + MODULE_DEVICE_TABLE(of, ad5791_of_match); 448 433 449 434 static const struct spi_device_id ad5791_id[] = { 450 - {"ad5760", ID_AD5760}, 451 - {"ad5780", ID_AD5780}, 452 - {"ad5781", ID_AD5781}, 453 - {"ad5790", ID_AD5791}, 454 - {"ad5791", ID_AD5791}, 455 - {} 435 + { "ad5760", (kernel_ulong_t)&ad5760_chip_info }, 436 + { "ad5780", (kernel_ulong_t)&ad5780_chip_info }, 437 + { "ad5781", (kernel_ulong_t)&ad5781_chip_info }, 438 + { "ad5790", (kernel_ulong_t)&ad5790_chip_info }, 439 + { "ad5791", (kernel_ulong_t)&ad5791_chip_info }, 440 + { } 456 441 }; 457 442 MODULE_DEVICE_TABLE(spi, ad5791_id); 458 443 459 444 static struct spi_driver ad5791_driver = { 460 445 .driver = { 461 446 .name = "ad5791", 447 + .of_match_table = ad5791_of_match, 462 448 }, 463 449 .probe = ad5791_probe, 464 - .remove = ad5791_remove, 465 450 .id_table = ad5791_id, 466 451 }; 467 452 module_spi_driver(ad5791_driver);
+9 -2
drivers/iio/dac/ad8460.c
··· 573 573 static int ad8460_write_event_config(struct iio_dev *indio_dev, 574 574 const struct iio_chan_spec *chan, 575 575 enum iio_event_type type, 576 - enum iio_event_direction dir, int val) 576 + enum iio_event_direction dir, bool val) 577 577 { 578 578 struct ad8460_state *state = iio_priv(indio_dev); 579 579 int fault; ··· 924 924 } 925 925 926 926 static const struct of_device_id ad8460_of_match[] = { 927 - { .compatible = "adi, ad8460" }, 927 + { .compatible = "adi,ad8460" }, 928 928 { } 929 929 }; 930 930 MODULE_DEVICE_TABLE(of, ad8460_of_match); 931 + 932 + static const struct spi_device_id ad8460_spi_match[] = { 933 + { .name = "ad8460" }, 934 + { } 935 + }; 936 + MODULE_DEVICE_TABLE(spi, ad8460_spi_match); 931 937 932 938 static struct spi_driver ad8460_driver = { 933 939 .driver = { ··· 941 935 .of_match_table = ad8460_of_match, 942 936 }, 943 937 .probe = ad8460_probe, 938 + .id_table = ad8460_spi_match, 944 939 }; 945 940 module_spi_driver(ad8460_driver); 946 941
+298 -14
drivers/iio/dac/adi-axi-dac.c
··· 29 29 #include <linux/iio/buffer.h> 30 30 #include <linux/iio/iio.h> 31 31 32 + #include "ad3552r-hs.h" 33 + 32 34 /* 33 35 * Register definitions: 34 36 * https://wiki.analog.com/resources/fpga/docs/axi_dac_ip#register_map ··· 48 46 #define AXI_DAC_CNTRL_1_REG 0x0044 49 47 #define AXI_DAC_CNTRL_1_SYNC BIT(0) 50 48 #define AXI_DAC_CNTRL_2_REG 0x0048 49 + #define AXI_DAC_CNTRL_2_SDR_DDR_N BIT(16) 50 + #define AXI_DAC_CNTRL_2_SYMB_8B BIT(14) 51 51 #define ADI_DAC_CNTRL_2_R1_MODE BIT(5) 52 + #define AXI_DAC_CNTRL_2_UNSIGNED_DATA BIT(4) 53 + #define AXI_DAC_STATUS_1_REG 0x0054 54 + #define AXI_DAC_STATUS_2_REG 0x0058 52 55 #define AXI_DAC_DRP_STATUS_REG 0x0074 53 56 #define AXI_DAC_DRP_STATUS_DRP_LOCKED BIT(17) 57 + #define AXI_DAC_CUSTOM_RD_REG 0x0080 58 + #define AXI_DAC_CUSTOM_WR_REG 0x0084 59 + #define AXI_DAC_CUSTOM_WR_DATA_8 GENMASK(23, 16) 60 + #define AXI_DAC_CUSTOM_WR_DATA_16 GENMASK(23, 8) 61 + #define AXI_DAC_UI_STATUS_REG 0x0088 62 + #define AXI_DAC_UI_STATUS_IF_BUSY BIT(4) 63 + #define AXI_DAC_CUSTOM_CTRL_REG 0x008C 64 + #define AXI_DAC_CUSTOM_CTRL_ADDRESS GENMASK(31, 24) 65 + #define AXI_DAC_CUSTOM_CTRL_SYNCED_TRANSFER BIT(2) 66 + #define AXI_DAC_CUSTOM_CTRL_STREAM BIT(1) 67 + #define AXI_DAC_CUSTOM_CTRL_TRANSFER_DATA BIT(0) 68 + 69 + #define AXI_DAC_CUSTOM_CTRL_STREAM_ENABLE (AXI_DAC_CUSTOM_CTRL_TRANSFER_DATA | \ 70 + AXI_DAC_CUSTOM_CTRL_STREAM) 54 71 55 72 /* DAC Channel controls */ 56 73 #define AXI_DAC_CHAN_CNTRL_1_REG(c) (0x0400 + (c) * 0x40) ··· 84 63 #define AXI_DAC_CHAN_CNTRL_7_REG(c) (0x0418 + (c) * 0x40) 85 64 #define AXI_DAC_CHAN_CNTRL_7_DATA_SEL GENMASK(3, 0) 86 65 66 + #define AXI_DAC_RD_ADDR(x) (BIT(7) | (x)) 67 + 87 68 /* 360 degrees in rad */ 88 69 #define AXI_DAC_2_PI_MEGA 6283190 89 70 90 71 enum { 91 72 AXI_DAC_DATA_INTERNAL_TONE, 92 73 AXI_DAC_DATA_DMA = 2, 74 + AXI_DAC_DATA_INTERNAL_RAMP_16BIT = 11, 75 + }; 76 + 77 + struct axi_dac_info { 78 + unsigned int version; 79 + const struct iio_backend_info *backend_info; 80 + bool has_dac_clk; 81 + bool has_child_nodes; 93 82 }; 94 83 95 84 struct axi_dac_state { ··· 110 79 * data/variables. 111 80 */ 112 81 struct mutex lock; 82 + const struct axi_dac_info *info; 113 83 u64 dac_clk; 114 84 u32 reg_config; 115 85 bool int_tone; 86 + int dac_clk_rate; 116 87 }; 117 88 118 89 static int axi_dac_enable(struct iio_backend *back) ··· 504 471 AXI_DAC_CHAN_CNTRL_7_REG(chan), 505 472 AXI_DAC_CHAN_CNTRL_7_DATA_SEL, 506 473 AXI_DAC_DATA_DMA); 474 + case IIO_BACKEND_INTERNAL_RAMP_16BIT: 475 + return regmap_update_bits(st->regmap, 476 + AXI_DAC_CHAN_CNTRL_7_REG(chan), 477 + AXI_DAC_CHAN_CNTRL_7_DATA_SEL, 478 + AXI_DAC_DATA_INTERNAL_RAMP_16BIT); 507 479 default: 508 480 return -EINVAL; 509 481 } ··· 566 528 return regmap_write(st->regmap, reg, writeval); 567 529 } 568 530 531 + static int axi_dac_ddr_enable(struct iio_backend *back) 532 + { 533 + struct axi_dac_state *st = iio_backend_get_priv(back); 534 + 535 + return regmap_clear_bits(st->regmap, AXI_DAC_CNTRL_2_REG, 536 + AXI_DAC_CNTRL_2_SDR_DDR_N); 537 + } 538 + 539 + static int axi_dac_ddr_disable(struct iio_backend *back) 540 + { 541 + struct axi_dac_state *st = iio_backend_get_priv(back); 542 + 543 + return regmap_set_bits(st->regmap, AXI_DAC_CNTRL_2_REG, 544 + AXI_DAC_CNTRL_2_SDR_DDR_N); 545 + } 546 + 547 + static int axi_dac_data_stream_enable(struct iio_backend *back) 548 + { 549 + struct axi_dac_state *st = iio_backend_get_priv(back); 550 + 551 + return regmap_set_bits(st->regmap, AXI_DAC_CUSTOM_CTRL_REG, 552 + AXI_DAC_CUSTOM_CTRL_STREAM_ENABLE); 553 + } 554 + 555 + static int axi_dac_data_stream_disable(struct iio_backend *back) 556 + { 557 + struct axi_dac_state *st = iio_backend_get_priv(back); 558 + 559 + return regmap_clear_bits(st->regmap, AXI_DAC_CUSTOM_CTRL_REG, 560 + AXI_DAC_CUSTOM_CTRL_STREAM_ENABLE); 561 + } 562 + 563 + static int axi_dac_data_transfer_addr(struct iio_backend *back, u32 address) 564 + { 565 + struct axi_dac_state *st = iio_backend_get_priv(back); 566 + 567 + if (address > FIELD_MAX(AXI_DAC_CUSTOM_CTRL_ADDRESS)) 568 + return -EINVAL; 569 + 570 + /* 571 + * Sample register address, when the DAC is configured, or stream 572 + * start address when the FSM is in stream state. 573 + */ 574 + return regmap_update_bits(st->regmap, AXI_DAC_CUSTOM_CTRL_REG, 575 + AXI_DAC_CUSTOM_CTRL_ADDRESS, 576 + FIELD_PREP(AXI_DAC_CUSTOM_CTRL_ADDRESS, 577 + address)); 578 + } 579 + 580 + static int axi_dac_data_format_set(struct iio_backend *back, unsigned int ch, 581 + const struct iio_backend_data_fmt *data) 582 + { 583 + struct axi_dac_state *st = iio_backend_get_priv(back); 584 + 585 + switch (data->type) { 586 + case IIO_BACKEND_DATA_UNSIGNED: 587 + return regmap_clear_bits(st->regmap, AXI_DAC_CNTRL_2_REG, 588 + AXI_DAC_CNTRL_2_UNSIGNED_DATA); 589 + default: 590 + return -EINVAL; 591 + } 592 + } 593 + 594 + static int __axi_dac_bus_reg_write(struct iio_backend *back, u32 reg, 595 + u32 val, size_t data_size) 596 + { 597 + struct axi_dac_state *st = iio_backend_get_priv(back); 598 + int ret; 599 + u32 ival; 600 + 601 + /* 602 + * Both AXI_DAC_CNTRL_2_REG and AXI_DAC_CUSTOM_WR_REG need to know 603 + * the data size. So keeping data size control here only, 604 + * since data size is mandatory for the current transfer. 605 + * DDR state handled separately by specific backend calls, 606 + * generally all raw register writes are SDR. 607 + */ 608 + if (data_size == sizeof(u16)) 609 + ival = FIELD_PREP(AXI_DAC_CUSTOM_WR_DATA_16, val); 610 + else 611 + ival = FIELD_PREP(AXI_DAC_CUSTOM_WR_DATA_8, val); 612 + 613 + ret = regmap_write(st->regmap, AXI_DAC_CUSTOM_WR_REG, ival); 614 + if (ret) 615 + return ret; 616 + 617 + if (data_size == sizeof(u8)) 618 + ret = regmap_set_bits(st->regmap, AXI_DAC_CNTRL_2_REG, 619 + AXI_DAC_CNTRL_2_SYMB_8B); 620 + else 621 + ret = regmap_clear_bits(st->regmap, AXI_DAC_CNTRL_2_REG, 622 + AXI_DAC_CNTRL_2_SYMB_8B); 623 + if (ret) 624 + return ret; 625 + 626 + ret = regmap_update_bits(st->regmap, AXI_DAC_CUSTOM_CTRL_REG, 627 + AXI_DAC_CUSTOM_CTRL_ADDRESS, 628 + FIELD_PREP(AXI_DAC_CUSTOM_CTRL_ADDRESS, reg)); 629 + if (ret) 630 + return ret; 631 + 632 + ret = regmap_update_bits(st->regmap, AXI_DAC_CUSTOM_CTRL_REG, 633 + AXI_DAC_CUSTOM_CTRL_TRANSFER_DATA, 634 + AXI_DAC_CUSTOM_CTRL_TRANSFER_DATA); 635 + if (ret) 636 + return ret; 637 + 638 + ret = regmap_read_poll_timeout(st->regmap, 639 + AXI_DAC_UI_STATUS_REG, ival, 640 + FIELD_GET(AXI_DAC_UI_STATUS_IF_BUSY, ival) == 0, 641 + 10, 100 * KILO); 642 + if (ret == -ETIMEDOUT) 643 + dev_err(st->dev, "AXI read timeout\n"); 644 + 645 + /* Cleaning always AXI_DAC_CUSTOM_CTRL_TRANSFER_DATA */ 646 + return regmap_clear_bits(st->regmap, AXI_DAC_CUSTOM_CTRL_REG, 647 + AXI_DAC_CUSTOM_CTRL_TRANSFER_DATA); 648 + } 649 + 650 + static int axi_dac_bus_reg_write(struct iio_backend *back, u32 reg, 651 + u32 val, size_t data_size) 652 + { 653 + struct axi_dac_state *st = iio_backend_get_priv(back); 654 + 655 + guard(mutex)(&st->lock); 656 + return __axi_dac_bus_reg_write(back, reg, val, data_size); 657 + } 658 + 659 + static int axi_dac_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val, 660 + size_t data_size) 661 + { 662 + struct axi_dac_state *st = iio_backend_get_priv(back); 663 + int ret; 664 + 665 + guard(mutex)(&st->lock); 666 + 667 + /* 668 + * SPI, we write with read flag, then we read just at the AXI 669 + * io address space to get data read. 670 + */ 671 + ret = __axi_dac_bus_reg_write(back, AXI_DAC_RD_ADDR(reg), 0, 672 + data_size); 673 + if (ret) 674 + return ret; 675 + 676 + return regmap_read(st->regmap, AXI_DAC_CUSTOM_RD_REG, val); 677 + } 678 + 679 + static void axi_dac_child_remove(void *data) 680 + { 681 + platform_device_unregister(data); 682 + } 683 + 684 + static int axi_dac_create_platform_device(struct axi_dac_state *st, 685 + struct fwnode_handle *child) 686 + { 687 + struct ad3552r_hs_platform_data pdata = { 688 + .bus_reg_read = axi_dac_bus_reg_read, 689 + .bus_reg_write = axi_dac_bus_reg_write, 690 + .bus_sample_data_clock_hz = st->dac_clk_rate, 691 + }; 692 + struct platform_device_info pi = { 693 + .parent = st->dev, 694 + .name = fwnode_get_name(child), 695 + .id = PLATFORM_DEVID_AUTO, 696 + .fwnode = child, 697 + .data = &pdata, 698 + .size_data = sizeof(pdata), 699 + }; 700 + struct platform_device *pdev; 701 + 702 + pdev = platform_device_register_full(&pi); 703 + if (IS_ERR(pdev)) 704 + return PTR_ERR(pdev); 705 + 706 + return devm_add_action_or_reset(st->dev, axi_dac_child_remove, pdev); 707 + } 708 + 569 709 static const struct iio_backend_ops axi_dac_generic_ops = { 570 710 .enable = axi_dac_enable, 571 711 .disable = axi_dac_disable, ··· 757 541 .debugfs_reg_access = iio_backend_debugfs_ptr(axi_dac_reg_access), 758 542 }; 759 543 544 + static const struct iio_backend_ops axi_ad3552r_ops = { 545 + .enable = axi_dac_enable, 546 + .disable = axi_dac_disable, 547 + .request_buffer = axi_dac_request_buffer, 548 + .free_buffer = axi_dac_free_buffer, 549 + .data_source_set = axi_dac_data_source_set, 550 + .ddr_enable = axi_dac_ddr_enable, 551 + .ddr_disable = axi_dac_ddr_disable, 552 + .data_stream_enable = axi_dac_data_stream_enable, 553 + .data_stream_disable = axi_dac_data_stream_disable, 554 + .data_format_set = axi_dac_data_format_set, 555 + .data_transfer_addr = axi_dac_data_transfer_addr, 556 + }; 557 + 760 558 static const struct iio_backend_info axi_dac_generic = { 761 559 .name = "axi-dac", 762 560 .ops = &axi_dac_generic_ops, 561 + }; 562 + 563 + static const struct iio_backend_info axi_ad3552r = { 564 + .name = "axi-ad3552r", 565 + .ops = &axi_ad3552r_ops, 763 566 }; 764 567 765 568 static const struct regmap_config axi_dac_regmap_config = { ··· 790 555 791 556 static int axi_dac_probe(struct platform_device *pdev) 792 557 { 793 - const unsigned int *expected_ver; 794 558 struct axi_dac_state *st; 795 559 void __iomem *base; 796 560 unsigned int ver; ··· 800 566 if (!st) 801 567 return -ENOMEM; 802 568 803 - expected_ver = device_get_match_data(&pdev->dev); 804 - if (!expected_ver) 569 + st->info = device_get_match_data(&pdev->dev); 570 + if (!st->info) 805 571 return -ENODEV; 572 + clk = devm_clk_get_enabled(&pdev->dev, "s_axi_aclk"); 573 + if (IS_ERR(clk)) { 574 + /* Backward compat., old fdt versions without clock-names. */ 575 + clk = devm_clk_get_enabled(&pdev->dev, NULL); 576 + if (IS_ERR(clk)) 577 + return dev_err_probe(&pdev->dev, PTR_ERR(clk), 578 + "failed to get clock\n"); 579 + } 806 580 807 - clk = devm_clk_get_enabled(&pdev->dev, NULL); 808 - if (IS_ERR(clk)) 809 - return dev_err_probe(&pdev->dev, PTR_ERR(clk), 810 - "failed to get clock\n"); 581 + if (st->info->has_dac_clk) { 582 + struct clk *dac_clk; 583 + 584 + dac_clk = devm_clk_get_enabled(&pdev->dev, "dac_clk"); 585 + if (IS_ERR(dac_clk)) 586 + return dev_err_probe(&pdev->dev, PTR_ERR(dac_clk), 587 + "failed to get dac_clk clock\n"); 588 + 589 + /* We only care about the streaming mode rate */ 590 + st->dac_clk_rate = clk_get_rate(dac_clk) / 2; 591 + } 811 592 812 593 base = devm_platform_ioremap_resource(pdev, 0); 813 594 if (IS_ERR(base)) ··· 847 598 if (ret) 848 599 return ret; 849 600 850 - if (ADI_AXI_PCORE_VER_MAJOR(ver) != ADI_AXI_PCORE_VER_MAJOR(*expected_ver)) { 601 + if (ADI_AXI_PCORE_VER_MAJOR(ver) != 602 + ADI_AXI_PCORE_VER_MAJOR(st->info->version)) { 851 603 dev_err(&pdev->dev, 852 604 "Major version mismatch. Expected %d.%.2d.%c, Reported %d.%.2d.%c\n", 853 - ADI_AXI_PCORE_VER_MAJOR(*expected_ver), 854 - ADI_AXI_PCORE_VER_MINOR(*expected_ver), 855 - ADI_AXI_PCORE_VER_PATCH(*expected_ver), 605 + ADI_AXI_PCORE_VER_MAJOR(st->info->version), 606 + ADI_AXI_PCORE_VER_MINOR(st->info->version), 607 + ADI_AXI_PCORE_VER_PATCH(st->info->version), 856 608 ADI_AXI_PCORE_VER_MAJOR(ver), 857 609 ADI_AXI_PCORE_VER_MINOR(ver), 858 610 ADI_AXI_PCORE_VER_PATCH(ver)); ··· 879 629 return ret; 880 630 881 631 mutex_init(&st->lock); 882 - ret = devm_iio_backend_register(&pdev->dev, &axi_dac_generic, st); 632 + 633 + ret = devm_iio_backend_register(&pdev->dev, st->info->backend_info, st); 883 634 if (ret) 884 635 return dev_err_probe(&pdev->dev, ret, 885 636 "failed to register iio backend\n"); 637 + 638 + device_for_each_child_node_scoped(&pdev->dev, child) { 639 + int val; 640 + 641 + if (!st->info->has_child_nodes) 642 + return dev_err_probe(&pdev->dev, -EINVAL, 643 + "invalid fdt axi-dac compatible."); 644 + 645 + /* Processing only reg 0 node */ 646 + ret = fwnode_property_read_u32(child, "reg", &val); 647 + if (ret) 648 + return dev_err_probe(&pdev->dev, ret, 649 + "invalid reg property."); 650 + if (val != 0) 651 + return dev_err_probe(&pdev->dev, -EINVAL, 652 + "invalid node address."); 653 + 654 + ret = axi_dac_create_platform_device(st, child); 655 + if (ret) 656 + return dev_err_probe(&pdev->dev, -EINVAL, 657 + "cannot create device."); 658 + } 886 659 887 660 dev_info(&pdev->dev, "AXI DAC IP core (%d.%.2d.%c) probed\n", 888 661 ADI_AXI_PCORE_VER_MAJOR(ver), ··· 915 642 return 0; 916 643 } 917 644 918 - static unsigned int axi_dac_9_1_b_info = ADI_AXI_PCORE_VER(9, 1, 'b'); 645 + static const struct axi_dac_info dac_generic = { 646 + .version = ADI_AXI_PCORE_VER(9, 1, 'b'), 647 + .backend_info = &axi_dac_generic, 648 + }; 649 + 650 + static const struct axi_dac_info dac_ad3552r = { 651 + .version = ADI_AXI_PCORE_VER(9, 1, 'b'), 652 + .backend_info = &axi_ad3552r, 653 + .has_dac_clk = true, 654 + .has_child_nodes = true, 655 + }; 919 656 920 657 static const struct of_device_id axi_dac_of_match[] = { 921 - { .compatible = "adi,axi-dac-9.1.b", .data = &axi_dac_9_1_b_info }, 658 + { .compatible = "adi,axi-dac-9.1.b", .data = &dac_generic }, 659 + { .compatible = "adi,axi-ad3552r", .data = &dac_ad3552r }, 922 660 {} 923 661 }; 924 662 MODULE_DEVICE_TABLE(of, axi_dac_of_match);
+1 -1
drivers/iio/dummy/iio_simple_dummy.h
··· 60 60 const struct iio_chan_spec *chan, 61 61 enum iio_event_type type, 62 62 enum iio_event_direction dir, 63 - int state); 63 + bool state); 64 64 65 65 int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev, 66 66 const struct iio_chan_spec *chan,
+15 -17
drivers/iio/dummy/iio_simple_dummy_events.c
··· 53 53 const struct iio_chan_spec *chan, 54 54 enum iio_event_type type, 55 55 enum iio_event_direction dir, 56 - int state) 56 + bool state) 57 57 { 58 58 struct iio_dummy_state *st = iio_priv(indio_dev); 59 59 ··· 183 183 switch (st->regs->reg_data) { 184 184 case 0: 185 185 iio_push_event(indio_dev, 186 - IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0, 187 - IIO_EV_DIR_RISING, 188 - IIO_EV_TYPE_THRESH, 0, 0, 0), 186 + IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 0, 187 + IIO_EV_TYPE_THRESH, 188 + IIO_EV_DIR_RISING), 189 189 st->event_timestamp); 190 190 break; 191 191 case 1: 192 192 if (st->activity_running > st->event_val) 193 193 iio_push_event(indio_dev, 194 - IIO_EVENT_CODE(IIO_ACTIVITY, 0, 195 - IIO_MOD_RUNNING, 196 - IIO_EV_DIR_RISING, 197 - IIO_EV_TYPE_THRESH, 198 - 0, 0, 0), 194 + IIO_MOD_EVENT_CODE(IIO_ACTIVITY, 0, 195 + IIO_MOD_RUNNING, 196 + IIO_EV_TYPE_THRESH, 197 + IIO_EV_DIR_RISING), 199 198 st->event_timestamp); 200 199 break; 201 200 case 2: 202 201 if (st->activity_walking < st->event_val) 203 202 iio_push_event(indio_dev, 204 - IIO_EVENT_CODE(IIO_ACTIVITY, 0, 205 - IIO_MOD_WALKING, 206 - IIO_EV_DIR_FALLING, 207 - IIO_EV_TYPE_THRESH, 208 - 0, 0, 0), 203 + IIO_MOD_EVENT_CODE(IIO_ACTIVITY, 0, 204 + IIO_MOD_WALKING, 205 + IIO_EV_TYPE_THRESH, 206 + IIO_EV_DIR_FALLING), 209 207 st->event_timestamp); 210 208 break; 211 209 case 3: 212 210 iio_push_event(indio_dev, 213 - IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD, 214 - IIO_EV_DIR_NONE, 215 - IIO_EV_TYPE_CHANGE, 0, 0, 0), 211 + IIO_UNMOD_EVENT_CODE(IIO_STEPS, 0, 212 + IIO_EV_TYPE_CHANGE, 213 + IIO_EV_DIR_NONE), 216 214 st->event_timestamp); 217 215 break; 218 216 default:
+1 -1
drivers/iio/gyro/Kconfig
··· 27 27 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER 28 28 help 29 29 Say yes here to build support for the Analog Devices ADIS16133, ADIS16135, 30 - ADIS16136 gyroscope devices. 30 + ADIS16136, ADIS16137 gyroscope devices. 31 31 32 32 config ADIS16260 33 33 tristate "Analog Devices ADIS16260 Digital Gyroscope Sensor SPI driver"
+2 -17
drivers/iio/gyro/bmg160_core.c
··· 8 8 #include <linux/interrupt.h> 9 9 #include <linux/delay.h> 10 10 #include <linux/slab.h> 11 - #include <linux/acpi.h> 12 11 #include <linux/pm.h> 13 12 #include <linux/pm_runtime.h> 14 13 #include <linux/iio/iio.h> ··· 443 444 444 445 static int bmg160_get_bw(struct bmg160_data *data, int *val) 445 446 { 446 - struct device *dev = regmap_get_device(data->regmap); 447 + struct device *dev = regmap_get_device(data->regmap); 447 448 int i; 448 449 unsigned int bw_bits; 449 450 int ret; ··· 748 749 const struct iio_chan_spec *chan, 749 750 enum iio_event_type type, 750 751 enum iio_event_direction dir, 751 - int state) 752 + bool state) 752 753 { 753 754 struct bmg160_data *data = iio_priv(indio_dev); 754 755 int ret; ··· 1054 1055 .postdisable = bmg160_buffer_postdisable, 1055 1056 }; 1056 1057 1057 - static const char *bmg160_match_acpi_device(struct device *dev) 1058 - { 1059 - const struct acpi_device_id *id; 1060 - 1061 - id = acpi_match_device(dev->driver->acpi_match_table, dev); 1062 - if (!id) 1063 - return NULL; 1064 - 1065 - return dev_name(dev); 1066 - } 1067 - 1068 1058 int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, 1069 1059 const char *name) 1070 1060 { ··· 1085 1097 return ret; 1086 1098 1087 1099 mutex_init(&data->mutex); 1088 - 1089 - if (ACPI_HANDLE(dev)) 1090 - name = bmg160_match_acpi_device(dev); 1091 1100 1092 1101 indio_dev->channels = bmg160_channels; 1093 1102 indio_dev->num_channels = ARRAY_SIZE(bmg160_channels);
+3 -3
drivers/iio/gyro/bmg160_i2c.c
··· 17 17 { 18 18 const struct i2c_device_id *id = i2c_client_get_device_id(client); 19 19 struct regmap *regmap; 20 - const char *name = NULL; 20 + const char *name; 21 21 22 22 regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf); 23 23 if (IS_ERR(regmap)) { ··· 28 28 29 29 if (id) 30 30 name = id->name; 31 + else 32 + name = iio_get_acpi_device_name(&client->dev); 31 33 32 34 return bmg160_core_probe(&client->dev, regmap, client->irq, name); 33 35 } ··· 41 39 42 40 static const struct acpi_device_id bmg160_acpi_match[] = { 43 41 {"BMG0160", 0}, 44 - {"BMI055B", 0}, 45 - {"BMI088B", 0}, 46 42 {}, 47 43 }; 48 44
+14
drivers/iio/imu/Kconfig
··· 97 97 98 98 source "drivers/iio/imu/inv_icm42600/Kconfig" 99 99 source "drivers/iio/imu/inv_mpu6050/Kconfig" 100 + 101 + config SMI240 102 + tristate "Bosch Sensor SMI240 Inertial Measurement Unit" 103 + depends on SPI 104 + select REGMAP_SPI 105 + select IIO_BUFFER 106 + select IIO_TRIGGERED_BUFFER 107 + help 108 + If you say yes here you get support for SMI240 IMU on SPI with 109 + accelerometer and gyroscope. 110 + 111 + This driver can also be built as a module. If so, the module will be 112 + called smi240. 113 + 100 114 source "drivers/iio/imu/st_lsm6dsx/Kconfig" 101 115 source "drivers/iio/imu/st_lsm9ds0/Kconfig" 102 116
+2
drivers/iio/imu/Makefile
··· 28 28 29 29 obj-$(CONFIG_KMX61) += kmx61.o 30 30 31 + obj-$(CONFIG_SMI240) += smi240.o 32 + 31 33 obj-y += st_lsm6dsx/ 32 34 obj-y += st_lsm9ds0/
+1
drivers/iio/imu/bmi270/Kconfig
··· 6 6 config BMI270 7 7 tristate 8 8 select IIO_BUFFER 9 + select IIO_TRIGGERED_BUFFER 9 10 10 11 config BMI270_I2C 11 12 tristate "Bosch BMI270 I2C driver"
+20 -1
drivers/iio/imu/bmi270/bmi270.h
··· 10 10 struct bmi270_data { 11 11 struct device *dev; 12 12 struct regmap *regmap; 13 + const struct bmi270_chip_info *chip_info; 14 + 15 + /* 16 + * Where IIO_DMA_MINALIGN may be larger than 8 bytes, align to 17 + * that to ensure a DMA safe buffer. 18 + */ 19 + struct { 20 + __le16 channels[6]; 21 + aligned_s64 timestamp; 22 + } data __aligned(IIO_DMA_MINALIGN); 23 + }; 24 + 25 + struct bmi270_chip_info { 26 + const char *name; 27 + int chip_id; 28 + const char *fw_name; 13 29 }; 14 30 15 31 extern const struct regmap_config bmi270_regmap_config; 32 + extern const struct bmi270_chip_info bmi260_chip_info; 33 + extern const struct bmi270_chip_info bmi270_chip_info; 16 34 17 - int bmi270_core_probe(struct device *dev, struct regmap *regmap); 35 + int bmi270_core_probe(struct device *dev, struct regmap *regmap, 36 + const struct bmi270_chip_info *chip_info); 18 37 19 38 #endif /* BMI270_H_ */
+434 -7
drivers/iio/imu/bmi270/bmi270_core.c
··· 7 7 #include <linux/regmap.h> 8 8 9 9 #include <linux/iio/iio.h> 10 + #include <linux/iio/sysfs.h> 11 + #include <linux/iio/triggered_buffer.h> 12 + #include <linux/iio/trigger_consumer.h> 10 13 11 14 #include "bmi270.h" 12 15 13 16 #define BMI270_CHIP_ID_REG 0x00 17 + 18 + /* Checked to prevent sending incompatible firmware to BMI160 devices */ 19 + #define BMI160_CHIP_ID_VAL 0xD1 20 + 21 + #define BMI260_CHIP_ID_VAL 0x27 14 22 #define BMI270_CHIP_ID_VAL 0x24 15 23 #define BMI270_CHIP_ID_MSK GENMASK(7, 0) 16 24 ··· 39 31 #define BMI270_ACC_CONF_BWP_NORMAL_MODE 0x02 40 32 #define BMI270_ACC_CONF_FILTER_PERF_MSK BIT(7) 41 33 34 + #define BMI270_ACC_CONF_RANGE_REG 0x41 35 + #define BMI270_ACC_CONF_RANGE_MSK GENMASK(1, 0) 36 + 42 37 #define BMI270_GYR_CONF_REG 0x42 43 38 #define BMI270_GYR_CONF_ODR_MSK GENMASK(3, 0) 44 39 #define BMI270_GYR_CONF_ODR_200HZ 0x09 ··· 49 38 #define BMI270_GYR_CONF_BWP_NORMAL_MODE 0x02 50 39 #define BMI270_GYR_CONF_NOISE_PERF_MSK BIT(6) 51 40 #define BMI270_GYR_CONF_FILTER_PERF_MSK BIT(7) 41 + 42 + #define BMI270_GYR_CONF_RANGE_REG 0x43 43 + #define BMI270_GYR_CONF_RANGE_MSK GENMASK(2, 0) 52 44 53 45 #define BMI270_INIT_CTRL_REG 0x59 54 46 #define BMI270_INIT_CTRL_LOAD_DONE_MSK BIT(0) ··· 69 55 #define BMI270_PWR_CTRL_ACCEL_EN_MSK BIT(2) 70 56 #define BMI270_PWR_CTRL_TEMP_EN_MSK BIT(3) 71 57 58 + #define BMI260_INIT_DATA_FILE "bmi260-init-data.fw" 72 59 #define BMI270_INIT_DATA_FILE "bmi270-init-data.fw" 73 60 74 61 enum bmi270_scan { ··· 79 64 BMI270_SCAN_GYRO_X, 80 65 BMI270_SCAN_GYRO_Y, 81 66 BMI270_SCAN_GYRO_Z, 67 + BMI270_SCAN_TIMESTAMP, 82 68 }; 69 + 70 + static const unsigned long bmi270_avail_scan_masks[] = { 71 + (BIT(BMI270_SCAN_ACCEL_X) | 72 + BIT(BMI270_SCAN_ACCEL_Y) | 73 + BIT(BMI270_SCAN_ACCEL_Z) | 74 + BIT(BMI270_SCAN_GYRO_X) | 75 + BIT(BMI270_SCAN_GYRO_Y) | 76 + BIT(BMI270_SCAN_GYRO_Z)), 77 + 0 78 + }; 79 + 80 + const struct bmi270_chip_info bmi260_chip_info = { 81 + .name = "bmi260", 82 + .chip_id = BMI260_CHIP_ID_VAL, 83 + .fw_name = BMI260_INIT_DATA_FILE, 84 + }; 85 + EXPORT_SYMBOL_NS_GPL(bmi260_chip_info, IIO_BMI270); 86 + 87 + const struct bmi270_chip_info bmi270_chip_info = { 88 + .name = "bmi270", 89 + .chip_id = BMI270_CHIP_ID_VAL, 90 + .fw_name = BMI270_INIT_DATA_FILE, 91 + }; 92 + EXPORT_SYMBOL_NS_GPL(bmi270_chip_info, IIO_BMI270); 93 + 94 + enum bmi270_sensor_type { 95 + BMI270_ACCEL = 0, 96 + BMI270_GYRO, 97 + }; 98 + 99 + struct bmi270_scale { 100 + int scale; 101 + int uscale; 102 + }; 103 + 104 + struct bmi270_odr { 105 + int odr; 106 + int uodr; 107 + }; 108 + 109 + static const struct bmi270_scale bmi270_accel_scale[] = { 110 + { 0, 598 }, 111 + { 0, 1197 }, 112 + { 0, 2394 }, 113 + { 0, 4788 }, 114 + }; 115 + 116 + static const struct bmi270_scale bmi270_gyro_scale[] = { 117 + { 0, 1065 }, 118 + { 0, 532 }, 119 + { 0, 266 }, 120 + { 0, 133 }, 121 + { 0, 66 }, 122 + }; 123 + 124 + struct bmi270_scale_item { 125 + const struct bmi270_scale *tbl; 126 + int num; 127 + }; 128 + 129 + static const struct bmi270_scale_item bmi270_scale_table[] = { 130 + [BMI270_ACCEL] = { 131 + .tbl = bmi270_accel_scale, 132 + .num = ARRAY_SIZE(bmi270_accel_scale), 133 + }, 134 + [BMI270_GYRO] = { 135 + .tbl = bmi270_gyro_scale, 136 + .num = ARRAY_SIZE(bmi270_gyro_scale), 137 + }, 138 + }; 139 + 140 + static const struct bmi270_odr bmi270_accel_odr[] = { 141 + { 0, 781250 }, 142 + { 1, 562500 }, 143 + { 3, 125000 }, 144 + { 6, 250000 }, 145 + { 12, 500000 }, 146 + { 25, 0 }, 147 + { 50, 0 }, 148 + { 100, 0 }, 149 + { 200, 0 }, 150 + { 400, 0 }, 151 + { 800, 0 }, 152 + { 1600, 0 }, 153 + }; 154 + 155 + static const u8 bmi270_accel_odr_vals[] = { 156 + 0x01, 157 + 0x02, 158 + 0x03, 159 + 0x04, 160 + 0x05, 161 + 0x06, 162 + 0x07, 163 + 0x08, 164 + 0x09, 165 + 0x0A, 166 + 0x0B, 167 + 0x0C, 168 + }; 169 + 170 + static const struct bmi270_odr bmi270_gyro_odr[] = { 171 + { 25, 0 }, 172 + { 50, 0 }, 173 + { 100, 0 }, 174 + { 200, 0 }, 175 + { 400, 0 }, 176 + { 800, 0 }, 177 + { 1600, 0 }, 178 + { 3200, 0 }, 179 + }; 180 + 181 + static const u8 bmi270_gyro_odr_vals[] = { 182 + 0x06, 183 + 0x07, 184 + 0x08, 185 + 0x09, 186 + 0x0A, 187 + 0x0B, 188 + 0x0C, 189 + 0x0D, 190 + }; 191 + 192 + struct bmi270_odr_item { 193 + const struct bmi270_odr *tbl; 194 + const u8 *vals; 195 + int num; 196 + }; 197 + 198 + static const struct bmi270_odr_item bmi270_odr_table[] = { 199 + [BMI270_ACCEL] = { 200 + .tbl = bmi270_accel_odr, 201 + .vals = bmi270_accel_odr_vals, 202 + .num = ARRAY_SIZE(bmi270_accel_odr), 203 + }, 204 + [BMI270_GYRO] = { 205 + .tbl = bmi270_gyro_odr, 206 + .vals = bmi270_gyro_odr_vals, 207 + .num = ARRAY_SIZE(bmi270_gyro_odr), 208 + }, 209 + }; 210 + 211 + static int bmi270_set_scale(struct bmi270_data *data, int chan_type, int uscale) 212 + { 213 + int i; 214 + int reg, mask; 215 + struct bmi270_scale_item bmi270_scale_item; 216 + 217 + switch (chan_type) { 218 + case IIO_ACCEL: 219 + reg = BMI270_ACC_CONF_RANGE_REG; 220 + mask = BMI270_ACC_CONF_RANGE_MSK; 221 + bmi270_scale_item = bmi270_scale_table[BMI270_ACCEL]; 222 + break; 223 + case IIO_ANGL_VEL: 224 + reg = BMI270_GYR_CONF_RANGE_REG; 225 + mask = BMI270_GYR_CONF_RANGE_MSK; 226 + bmi270_scale_item = bmi270_scale_table[BMI270_GYRO]; 227 + break; 228 + default: 229 + return -EINVAL; 230 + } 231 + 232 + for (i = 0; i < bmi270_scale_item.num; i++) { 233 + if (bmi270_scale_item.tbl[i].uscale != uscale) 234 + continue; 235 + 236 + return regmap_update_bits(data->regmap, reg, mask, i); 237 + } 238 + 239 + return -EINVAL; 240 + } 241 + 242 + static int bmi270_get_scale(struct bmi270_data *bmi270_device, int chan_type, 243 + int *uscale) 244 + { 245 + int ret; 246 + unsigned int val; 247 + struct bmi270_scale_item bmi270_scale_item; 248 + 249 + switch (chan_type) { 250 + case IIO_ACCEL: 251 + ret = regmap_read(bmi270_device->regmap, 252 + BMI270_ACC_CONF_RANGE_REG, &val); 253 + if (ret) 254 + return ret; 255 + 256 + val = FIELD_GET(BMI270_ACC_CONF_RANGE_MSK, val); 257 + bmi270_scale_item = bmi270_scale_table[BMI270_ACCEL]; 258 + break; 259 + case IIO_ANGL_VEL: 260 + ret = regmap_read(bmi270_device->regmap, 261 + BMI270_GYR_CONF_RANGE_REG, &val); 262 + if (ret) 263 + return ret; 264 + 265 + val = FIELD_GET(BMI270_GYR_CONF_RANGE_MSK, val); 266 + bmi270_scale_item = bmi270_scale_table[BMI270_GYRO]; 267 + break; 268 + default: 269 + return -EINVAL; 270 + } 271 + 272 + if (val >= bmi270_scale_item.num) 273 + return -EINVAL; 274 + 275 + *uscale = bmi270_scale_item.tbl[val].uscale; 276 + return 0; 277 + } 278 + 279 + static int bmi270_set_odr(struct bmi270_data *data, int chan_type, int odr, 280 + int uodr) 281 + { 282 + int i; 283 + int reg, mask; 284 + struct bmi270_odr_item bmi270_odr_item; 285 + 286 + switch (chan_type) { 287 + case IIO_ACCEL: 288 + reg = BMI270_ACC_CONF_REG; 289 + mask = BMI270_ACC_CONF_ODR_MSK; 290 + bmi270_odr_item = bmi270_odr_table[BMI270_ACCEL]; 291 + break; 292 + case IIO_ANGL_VEL: 293 + reg = BMI270_GYR_CONF_REG; 294 + mask = BMI270_GYR_CONF_ODR_MSK; 295 + bmi270_odr_item = bmi270_odr_table[BMI270_GYRO]; 296 + break; 297 + default: 298 + return -EINVAL; 299 + } 300 + 301 + for (i = 0; i < bmi270_odr_item.num; i++) { 302 + if (bmi270_odr_item.tbl[i].odr != odr || 303 + bmi270_odr_item.tbl[i].uodr != uodr) 304 + continue; 305 + 306 + return regmap_update_bits(data->regmap, reg, mask, 307 + bmi270_odr_item.vals[i]); 308 + } 309 + 310 + return -EINVAL; 311 + } 312 + 313 + static int bmi270_get_odr(struct bmi270_data *data, int chan_type, int *odr, 314 + int *uodr) 315 + { 316 + int i, val, ret; 317 + struct bmi270_odr_item bmi270_odr_item; 318 + 319 + switch (chan_type) { 320 + case IIO_ACCEL: 321 + ret = regmap_read(data->regmap, BMI270_ACC_CONF_REG, &val); 322 + if (ret) 323 + return ret; 324 + 325 + val = FIELD_GET(BMI270_ACC_CONF_ODR_MSK, val); 326 + bmi270_odr_item = bmi270_odr_table[BMI270_ACCEL]; 327 + break; 328 + case IIO_ANGL_VEL: 329 + ret = regmap_read(data->regmap, BMI270_GYR_CONF_REG, &val); 330 + if (ret) 331 + return ret; 332 + 333 + val = FIELD_GET(BMI270_GYR_CONF_ODR_MSK, val); 334 + bmi270_odr_item = bmi270_odr_table[BMI270_GYRO]; 335 + break; 336 + default: 337 + return -EINVAL; 338 + } 339 + 340 + for (i = 0; i < bmi270_odr_item.num; i++) { 341 + if (val != bmi270_odr_item.vals[i]) 342 + continue; 343 + 344 + *odr = bmi270_odr_item.tbl[i].odr; 345 + *uodr = bmi270_odr_item.tbl[i].uodr; 346 + return 0; 347 + } 348 + 349 + return -EINVAL; 350 + } 351 + 352 + static irqreturn_t bmi270_trigger_handler(int irq, void *p) 353 + { 354 + struct iio_poll_func *pf = p; 355 + struct iio_dev *indio_dev = pf->indio_dev; 356 + struct bmi270_data *bmi270_device = iio_priv(indio_dev); 357 + int ret; 358 + 359 + ret = regmap_bulk_read(bmi270_device->regmap, BMI270_ACCEL_X_REG, 360 + &bmi270_device->data.channels, 361 + sizeof(bmi270_device->data.channels)); 362 + 363 + if (ret) 364 + goto done; 365 + 366 + iio_push_to_buffers_with_timestamp(indio_dev, &bmi270_device->data, 367 + pf->timestamp); 368 + done: 369 + iio_trigger_notify_done(indio_dev->trig); 370 + return IRQ_HANDLED; 371 + } 83 372 84 373 static int bmi270_get_data(struct bmi270_data *bmi270_device, 85 374 int chan_type, int axis, int *val) ··· 426 107 return ret; 427 108 428 109 return IIO_VAL_INT; 110 + case IIO_CHAN_INFO_SCALE: 111 + *val = 0; 112 + ret = bmi270_get_scale(bmi270_device, chan->type, val2); 113 + return ret ? ret : IIO_VAL_INT_PLUS_MICRO; 114 + case IIO_CHAN_INFO_SAMP_FREQ: 115 + ret = bmi270_get_odr(bmi270_device, chan->type, val, val2); 116 + return ret ? ret : IIO_VAL_INT_PLUS_MICRO; 117 + default: 118 + return -EINVAL; 119 + } 120 + } 121 + 122 + static int bmi270_write_raw(struct iio_dev *indio_dev, 123 + struct iio_chan_spec const *chan, 124 + int val, int val2, long mask) 125 + { 126 + struct bmi270_data *data = iio_priv(indio_dev); 127 + 128 + switch (mask) { 129 + case IIO_CHAN_INFO_SCALE: 130 + return bmi270_set_scale(data, chan->type, val2); 131 + case IIO_CHAN_INFO_SAMP_FREQ: 132 + return bmi270_set_odr(data, chan->type, val, val2); 133 + default: 134 + return -EINVAL; 135 + } 136 + } 137 + 138 + static int bmi270_read_avail(struct iio_dev *indio_dev, 139 + struct iio_chan_spec const *chan, 140 + const int **vals, int *type, int *length, 141 + long mask) 142 + { 143 + switch (mask) { 144 + case IIO_CHAN_INFO_SCALE: 145 + *type = IIO_VAL_INT_PLUS_MICRO; 146 + switch (chan->type) { 147 + case IIO_ANGL_VEL: 148 + *vals = (const int *)bmi270_gyro_scale; 149 + *length = ARRAY_SIZE(bmi270_gyro_scale) * 2; 150 + return IIO_AVAIL_LIST; 151 + case IIO_ACCEL: 152 + *vals = (const int *)bmi270_accel_scale; 153 + *length = ARRAY_SIZE(bmi270_accel_scale) * 2; 154 + return IIO_AVAIL_LIST; 155 + default: 156 + return -EINVAL; 157 + } 158 + case IIO_CHAN_INFO_SAMP_FREQ: 159 + *type = IIO_VAL_INT_PLUS_MICRO; 160 + switch (chan->type) { 161 + case IIO_ANGL_VEL: 162 + *vals = (const int *)bmi270_gyro_odr; 163 + *length = ARRAY_SIZE(bmi270_gyro_odr) * 2; 164 + return IIO_AVAIL_LIST; 165 + case IIO_ACCEL: 166 + *vals = (const int *)bmi270_accel_odr; 167 + *length = ARRAY_SIZE(bmi270_accel_odr) * 2; 168 + return IIO_AVAIL_LIST; 169 + default: 170 + return -EINVAL; 171 + } 429 172 default: 430 173 return -EINVAL; 431 174 } ··· 495 114 496 115 static const struct iio_info bmi270_info = { 497 116 .read_raw = bmi270_read_raw, 117 + .write_raw = bmi270_write_raw, 118 + .read_avail = bmi270_read_avail, 498 119 }; 499 120 500 121 #define BMI270_ACCEL_CHANNEL(_axis) { \ ··· 505 122 .channel2 = IIO_MOD_##_axis, \ 506 123 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 507 124 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 508 - BIT(IIO_CHAN_INFO_FREQUENCY), \ 125 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 126 + .info_mask_shared_by_type_available = \ 127 + BIT(IIO_CHAN_INFO_SCALE) | \ 128 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 129 + .scan_index = BMI270_SCAN_ACCEL_##_axis, \ 130 + .scan_type = { \ 131 + .sign = 's', \ 132 + .realbits = 16, \ 133 + .storagebits = 16, \ 134 + .endianness = IIO_LE, \ 135 + }, \ 509 136 } 510 137 511 138 #define BMI270_ANG_VEL_CHANNEL(_axis) { \ ··· 524 131 .channel2 = IIO_MOD_##_axis, \ 525 132 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 526 133 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 527 - BIT(IIO_CHAN_INFO_FREQUENCY), \ 134 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 135 + .info_mask_shared_by_type_available = \ 136 + BIT(IIO_CHAN_INFO_SCALE) | \ 137 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 138 + .scan_index = BMI270_SCAN_GYRO_##_axis, \ 139 + .scan_type = { \ 140 + .sign = 's', \ 141 + .realbits = 16, \ 142 + .storagebits = 16, \ 143 + .endianness = IIO_LE, \ 144 + }, \ 528 145 } 529 146 530 147 static const struct iio_chan_spec bmi270_channels[] = { ··· 544 141 BMI270_ANG_VEL_CHANNEL(X), 545 142 BMI270_ANG_VEL_CHANNEL(Y), 546 143 BMI270_ANG_VEL_CHANNEL(Z), 144 + IIO_CHAN_SOFT_TIMESTAMP(BMI270_SCAN_TIMESTAMP), 547 145 }; 548 146 549 147 static int bmi270_validate_chip_id(struct bmi270_data *bmi270_device) ··· 558 154 if (ret) 559 155 return dev_err_probe(dev, ret, "Failed to read chip id"); 560 156 561 - if (chip_id != BMI270_CHIP_ID_VAL) 562 - dev_info(dev, "Unknown chip id 0x%x", chip_id); 157 + /* 158 + * Some manufacturers use "BMI0160" for both the BMI160 and 159 + * BMI260. If the device is actually a BMI160, the bmi160 160 + * driver should handle it and this driver should not. 161 + */ 162 + if (chip_id == BMI160_CHIP_ID_VAL) 163 + return -ENODEV; 164 + 165 + if (chip_id != bmi270_device->chip_info->chip_id) 166 + dev_info(dev, "Unexpected chip id 0x%x", chip_id); 167 + 168 + if (chip_id == bmi260_chip_info.chip_id) 169 + bmi270_device->chip_info = &bmi260_chip_info; 170 + else if (chip_id == bmi270_chip_info.chip_id) 171 + bmi270_device->chip_info = &bmi270_chip_info; 563 172 564 173 return 0; 565 174 } ··· 604 187 return dev_err_probe(dev, ret, 605 188 "Failed to prepare device to load init data"); 606 189 607 - ret = request_firmware(&init_data, BMI270_INIT_DATA_FILE, dev); 190 + ret = request_firmware(&init_data, 191 + bmi270_device->chip_info->fw_name, dev); 608 192 if (ret) 609 193 return dev_err_probe(dev, ret, "Failed to load init data file"); 610 194 ··· 692 274 return bmi270_configure_imu(bmi270_device); 693 275 } 694 276 695 - int bmi270_core_probe(struct device *dev, struct regmap *regmap) 277 + int bmi270_core_probe(struct device *dev, struct regmap *regmap, 278 + const struct bmi270_chip_info *chip_info) 696 279 { 697 280 int ret; 698 281 struct bmi270_data *bmi270_device; ··· 706 287 bmi270_device = iio_priv(indio_dev); 707 288 bmi270_device->dev = dev; 708 289 bmi270_device->regmap = regmap; 290 + bmi270_device->chip_info = chip_info; 709 291 710 292 ret = bmi270_chip_init(bmi270_device); 711 293 if (ret) ··· 714 294 715 295 indio_dev->channels = bmi270_channels; 716 296 indio_dev->num_channels = ARRAY_SIZE(bmi270_channels); 717 - indio_dev->name = "bmi270"; 297 + indio_dev->name = chip_info->name; 298 + indio_dev->available_scan_masks = bmi270_avail_scan_masks; 718 299 indio_dev->modes = INDIO_DIRECT_MODE; 719 300 indio_dev->info = &bmi270_info; 301 + 302 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 303 + iio_pollfunc_store_time, 304 + bmi270_trigger_handler, NULL); 305 + if (ret) 306 + return ret; 720 307 721 308 return devm_iio_device_register(dev, indio_dev); 722 309 }
+17 -3
drivers/iio/imu/bmi270/bmi270_i2c.c
··· 17 17 { 18 18 struct regmap *regmap; 19 19 struct device *dev = &client->dev; 20 + const struct bmi270_chip_info *chip_info; 21 + 22 + chip_info = i2c_get_match_data(client); 23 + if (!chip_info) 24 + return -ENODEV; 20 25 21 26 regmap = devm_regmap_init_i2c(client, &bmi270_i2c_regmap_config); 22 27 if (IS_ERR(regmap)) 23 28 return dev_err_probe(dev, PTR_ERR(regmap), 24 29 "Failed to init i2c regmap"); 25 30 26 - return bmi270_core_probe(dev, regmap); 31 + return bmi270_core_probe(dev, regmap, chip_info); 27 32 } 28 33 29 34 static const struct i2c_device_id bmi270_i2c_id[] = { 30 - { "bmi270", 0 }, 35 + { "bmi260", (kernel_ulong_t)&bmi260_chip_info }, 36 + { "bmi270", (kernel_ulong_t)&bmi270_chip_info }, 37 + { } 38 + }; 39 + 40 + static const struct acpi_device_id bmi270_acpi_match[] = { 41 + /* GPD Win Mini, Aya Neo AIR Pro, OXP Mini Pro, etc. */ 42 + { "BMI0160", (kernel_ulong_t)&bmi260_chip_info }, 31 43 { } 32 44 }; 33 45 34 46 static const struct of_device_id bmi270_of_match[] = { 35 - { .compatible = "bosch,bmi270" }, 47 + { .compatible = "bosch,bmi260", .data = &bmi260_chip_info }, 48 + { .compatible = "bosch,bmi270", .data = &bmi270_chip_info }, 36 49 { } 37 50 }; 38 51 39 52 static struct i2c_driver bmi270_i2c_driver = { 40 53 .driver = { 41 54 .name = "bmi270_i2c", 55 + .acpi_match_table = bmi270_acpi_match, 42 56 .of_match_table = bmi270_of_match, 43 57 }, 44 58 .probe = bmi270_i2c_probe,
+10 -3
drivers/iio/imu/bmi270/bmi270_spi.c
··· 49 49 { 50 50 struct regmap *regmap; 51 51 struct device *dev = &spi->dev; 52 + const struct bmi270_chip_info *chip_info; 53 + 54 + chip_info = spi_get_device_match_data(spi); 55 + if (!chip_info) 56 + return -ENODEV; 52 57 53 58 regmap = devm_regmap_init(dev, &bmi270_regmap_bus, dev, 54 59 &bmi270_spi_regmap_config); ··· 61 56 return dev_err_probe(dev, PTR_ERR(regmap), 62 57 "Failed to init i2c regmap"); 63 58 64 - return bmi270_core_probe(dev, regmap); 59 + return bmi270_core_probe(dev, regmap, chip_info); 65 60 } 66 61 67 62 static const struct spi_device_id bmi270_spi_id[] = { 68 - { "bmi270" }, 63 + { "bmi260", (kernel_ulong_t)&bmi260_chip_info }, 64 + { "bmi270", (kernel_ulong_t)&bmi270_chip_info }, 69 65 { } 70 66 }; 71 67 72 68 static const struct of_device_id bmi270_of_match[] = { 73 - { .compatible = "bosch,bmi270" }, 69 + { .compatible = "bosch,bmi260", .data = &bmi260_chip_info }, 70 + { .compatible = "bosch,bmi270", .data = &bmi270_chip_info }, 74 71 { } 75 72 }; 76 73
+5 -5
drivers/iio/imu/bmi323/bmi323_core.c
··· 467 467 BMI323_FEAT_IO_STATUS_MSK); 468 468 } 469 469 470 - static int bmi323_step_wtrmrk_en(struct bmi323_data *data, int state) 470 + static int bmi323_step_wtrmrk_en(struct bmi323_data *data, bool state) 471 471 { 472 472 enum bmi323_irq_pin step_irq; 473 473 int ret; ··· 484 484 ret = bmi323_update_ext_reg(data, BMI323_STEP_SC1_REG, 485 485 BMI323_STEP_SC1_WTRMRK_MSK, 486 486 FIELD_PREP(BMI323_STEP_SC1_WTRMRK_MSK, 487 - state ? 1 : 0)); 487 + state)); 488 488 if (ret) 489 489 return ret; 490 490 ··· 506 506 } 507 507 508 508 static int bmi323_motion_event_en(struct bmi323_data *data, 509 - enum iio_event_direction dir, int state) 509 + enum iio_event_direction dir, bool state) 510 510 { 511 511 unsigned int state_value = state ? BMI323_FEAT_XYZ_MSK : 0; 512 512 int config, ret, msk, raw, field_value; ··· 570 570 } 571 571 572 572 static int bmi323_tap_event_en(struct bmi323_data *data, 573 - enum iio_event_direction dir, int state) 573 + enum iio_event_direction dir, bool state) 574 574 { 575 575 enum bmi323_irq_pin tap_irq; 576 576 int ret, tap_enabled; ··· 785 785 static int bmi323_write_event_config(struct iio_dev *indio_dev, 786 786 const struct iio_chan_spec *chan, 787 787 enum iio_event_type type, 788 - enum iio_event_direction dir, int state) 788 + enum iio_event_direction dir, bool state) 789 789 { 790 790 struct bmi323_data *data = iio_priv(indio_dev); 791 791
+1 -4
drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
··· 104 104 unsigned short *secondary_addr) 105 105 { 106 106 struct acpi_device *adev = ACPI_COMPANION(&client->dev); 107 - const struct acpi_device_id *id; 108 107 u32 i2c_addr = 0; 109 108 LIST_HEAD(resources); 110 109 int ret; 111 110 112 - id = acpi_match_device(client->dev.driver->acpi_match_table, 113 - &client->dev); 114 - if (!id) 111 + if (!is_acpi_device_node(dev_fwnode(&client->dev))) 115 112 return -ENODEV; 116 113 117 114 ret = acpi_dev_get_resources(adev, &resources,
+3 -6
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 1173 1173 const struct iio_chan_spec *chan, 1174 1174 enum iio_event_type type, 1175 1175 enum iio_event_direction dir, 1176 - int state) 1176 + bool state) 1177 1177 { 1178 1178 struct inv_mpu6050_state *st = iio_priv(indio_dev); 1179 - int enable; 1180 1179 1181 1180 /* support only WoM (accel roc rising) event */ 1182 1181 if (chan->type != IIO_ACCEL || type != IIO_EV_TYPE_ROC || 1183 1182 dir != IIO_EV_DIR_RISING) 1184 1183 return -EINVAL; 1185 1184 1186 - enable = !!state; 1187 - 1188 1185 guard(mutex)(&st->lock); 1189 1186 1190 - if (st->chip_config.wom_en == enable) 1187 + if (st->chip_config.wom_en == state) 1191 1188 return 0; 1192 1189 1193 - return inv_mpu6050_enable_wom(st, enable); 1190 + return inv_mpu6050_enable_wom(st, state); 1194 1191 } 1195 1192 1196 1193 static int inv_mpu6050_read_event_value(struct iio_dev *indio_dev,
+1 -1
drivers/iio/imu/kmx61.c
··· 942 942 const struct iio_chan_spec *chan, 943 943 enum iio_event_type type, 944 944 enum iio_event_direction dir, 945 - int state) 945 + bool state) 946 946 { 947 947 struct kmx61_data *data = kmx61_get_data(indio_dev); 948 948 int ret = 0;
+621
drivers/iio/imu/smi240.c
··· 1 + // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 2 + /* 3 + * Copyright (c) 2024 Robert Bosch GmbH. 4 + */ 5 + #include <linux/bitfield.h> 6 + #include <linux/bits.h> 7 + #include <linux/delay.h> 8 + #include <linux/device.h> 9 + #include <linux/module.h> 10 + #include <linux/regmap.h> 11 + #include <linux/spi/spi.h> 12 + #include <linux/unaligned.h> 13 + #include <linux/units.h> 14 + 15 + #include <linux/iio/buffer.h> 16 + #include <linux/iio/iio.h> 17 + #include <linux/iio/trigger.h> 18 + #include <linux/iio/trigger_consumer.h> 19 + #include <linux/iio/triggered_buffer.h> 20 + 21 + #define SMI240_CHIP_ID 0x0024 22 + 23 + #define SMI240_SOFT_CONFIG_EOC_MASK BIT(0) 24 + #define SMI240_SOFT_CONFIG_GYR_BW_MASK BIT(1) 25 + #define SMI240_SOFT_CONFIG_ACC_BW_MASK BIT(2) 26 + #define SMI240_SOFT_CONFIG_BITE_AUTO_MASK BIT(3) 27 + #define SMI240_SOFT_CONFIG_BITE_REP_MASK GENMASK(6, 4) 28 + 29 + #define SMI240_CHIP_ID_REG 0x00 30 + #define SMI240_SOFT_CONFIG_REG 0x0A 31 + #define SMI240_TEMP_CUR_REG 0x10 32 + #define SMI240_ACCEL_X_CUR_REG 0x11 33 + #define SMI240_GYRO_X_CUR_REG 0x14 34 + #define SMI240_DATA_CAP_FIRST_REG 0x17 35 + #define SMI240_CMD_REG 0x2F 36 + 37 + #define SMI240_SOFT_RESET_CMD 0xB6 38 + 39 + #define SMI240_BITE_SEQUENCE_DELAY_US 140000 40 + #define SMI240_FILTER_FLUSH_DELAY_US 60000 41 + #define SMI240_DIGITAL_STARTUP_DELAY_US 120000 42 + #define SMI240_MECH_STARTUP_DELAY_US 100000 43 + 44 + #define SMI240_BUS_ID 0x00 45 + #define SMI240_CRC_INIT 0x05 46 + #define SMI240_CRC_POLY 0x0B 47 + #define SMI240_CRC_MASK GENMASK(2, 0) 48 + 49 + #define SMI240_READ_SD_BIT_MASK BIT(31) 50 + #define SMI240_READ_DATA_MASK GENMASK(19, 4) 51 + #define SMI240_READ_CS_BIT_MASK BIT(3) 52 + 53 + #define SMI240_WRITE_BUS_ID_MASK GENMASK(31, 30) 54 + #define SMI240_WRITE_ADDR_MASK GENMASK(29, 22) 55 + #define SMI240_WRITE_BIT_MASK BIT(21) 56 + #define SMI240_WRITE_CAP_BIT_MASK BIT(20) 57 + #define SMI240_WRITE_DATA_MASK GENMASK(18, 3) 58 + 59 + /* T°C = (temp / 256) + 25 */ 60 + #define SMI240_TEMP_OFFSET 6400 /* 25 * 256 */ 61 + #define SMI240_TEMP_SCALE 3906250 /* (1 / 256) * 1e9 */ 62 + 63 + #define SMI240_ACCEL_SCALE 500 /* (1 / 2000) * 1e6 */ 64 + #define SMI240_GYRO_SCALE 10000 /* (1 / 100) * 1e6 */ 65 + 66 + #define SMI240_LOW_BANDWIDTH_HZ 50 67 + #define SMI240_HIGH_BANDWIDTH_HZ 400 68 + 69 + #define SMI240_BUILT_IN_SELF_TEST_COUNT 3 70 + 71 + #define SMI240_DATA_CHANNEL(_type, _axis, _index) { \ 72 + .type = _type, \ 73 + .modified = 1, \ 74 + .channel2 = IIO_MOD_##_axis, \ 75 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 76 + .info_mask_shared_by_type = \ 77 + BIT(IIO_CHAN_INFO_SCALE) | \ 78 + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ 79 + .info_mask_shared_by_type_available = \ 80 + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ 81 + .scan_index = _index, \ 82 + .scan_type = { \ 83 + .sign = 's', \ 84 + .realbits = 16, \ 85 + .storagebits = 16, \ 86 + .endianness = IIO_CPU, \ 87 + }, \ 88 + } 89 + 90 + #define SMI240_TEMP_CHANNEL(_index) { \ 91 + .type = IIO_TEMP, \ 92 + .modified = 1, \ 93 + .channel2 = IIO_MOD_TEMP_OBJECT, \ 94 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 95 + BIT(IIO_CHAN_INFO_OFFSET) | \ 96 + BIT(IIO_CHAN_INFO_SCALE), \ 97 + .scan_index = _index, \ 98 + .scan_type = { \ 99 + .sign = 's', \ 100 + .realbits = 16, \ 101 + .storagebits = 16, \ 102 + .endianness = IIO_CPU, \ 103 + }, \ 104 + } 105 + 106 + enum capture_mode { SMI240_CAPTURE_OFF = 0, SMI240_CAPTURE_ON = 1 }; 107 + 108 + struct smi240_data { 109 + struct regmap *regmap; 110 + u16 accel_filter_freq; 111 + u16 anglvel_filter_freq; 112 + u8 built_in_self_test_count; 113 + enum capture_mode capture; 114 + /* 115 + * Ensure natural alignment for timestamp if present. 116 + * Channel size: 2 bytes. 117 + * Max length needed: 2 * 3 channels + temp channel + 2 bytes padding + 8 byte ts. 118 + * If fewer channels are enabled, less space may be needed, as 119 + * long as the timestamp is still aligned to 8 bytes. 120 + */ 121 + s16 buf[12] __aligned(8); 122 + 123 + __be32 spi_buf __aligned(IIO_DMA_MINALIGN); 124 + }; 125 + 126 + enum { 127 + SMI240_TEMP_OBJECT, 128 + SMI240_SCAN_ACCEL_X, 129 + SMI240_SCAN_ACCEL_Y, 130 + SMI240_SCAN_ACCEL_Z, 131 + SMI240_SCAN_GYRO_X, 132 + SMI240_SCAN_GYRO_Y, 133 + SMI240_SCAN_GYRO_Z, 134 + SMI240_SCAN_TIMESTAMP, 135 + }; 136 + 137 + static const struct iio_chan_spec smi240_channels[] = { 138 + SMI240_TEMP_CHANNEL(SMI240_TEMP_OBJECT), 139 + SMI240_DATA_CHANNEL(IIO_ACCEL, X, SMI240_SCAN_ACCEL_X), 140 + SMI240_DATA_CHANNEL(IIO_ACCEL, Y, SMI240_SCAN_ACCEL_Y), 141 + SMI240_DATA_CHANNEL(IIO_ACCEL, Z, SMI240_SCAN_ACCEL_Z), 142 + SMI240_DATA_CHANNEL(IIO_ANGL_VEL, X, SMI240_SCAN_GYRO_X), 143 + SMI240_DATA_CHANNEL(IIO_ANGL_VEL, Y, SMI240_SCAN_GYRO_Y), 144 + SMI240_DATA_CHANNEL(IIO_ANGL_VEL, Z, SMI240_SCAN_GYRO_Z), 145 + IIO_CHAN_SOFT_TIMESTAMP(SMI240_SCAN_TIMESTAMP), 146 + }; 147 + 148 + static const int smi240_low_pass_freqs[] = { SMI240_LOW_BANDWIDTH_HZ, 149 + SMI240_HIGH_BANDWIDTH_HZ }; 150 + 151 + static u8 smi240_crc3(u32 data, u8 init, u8 poly) 152 + { 153 + u8 crc = init; 154 + u8 do_xor; 155 + s8 i = 31; 156 + 157 + do { 158 + do_xor = crc & 0x04; 159 + crc <<= 1; 160 + crc |= 0x01 & (data >> i); 161 + if (do_xor) 162 + crc ^= poly; 163 + 164 + crc &= SMI240_CRC_MASK; 165 + } while (--i >= 0); 166 + 167 + return crc; 168 + } 169 + 170 + static bool smi240_sensor_data_is_valid(u32 data) 171 + { 172 + if (smi240_crc3(data, SMI240_CRC_INIT, SMI240_CRC_POLY) != 0) 173 + return false; 174 + 175 + if (FIELD_GET(SMI240_READ_SD_BIT_MASK, data) & 176 + FIELD_GET(SMI240_READ_CS_BIT_MASK, data)) 177 + return false; 178 + 179 + return true; 180 + } 181 + 182 + static int smi240_regmap_spi_read(void *context, const void *reg_buf, 183 + size_t reg_size, void *val_buf, 184 + size_t val_size) 185 + { 186 + int ret; 187 + u32 request, response; 188 + u16 *val = val_buf; 189 + struct spi_device *spi = context; 190 + struct iio_dev *indio_dev = dev_get_drvdata(&spi->dev); 191 + struct smi240_data *iio_priv_data = iio_priv(indio_dev); 192 + 193 + if (reg_size != 1 || val_size != 2) 194 + return -EINVAL; 195 + 196 + request = FIELD_PREP(SMI240_WRITE_BUS_ID_MASK, SMI240_BUS_ID); 197 + request |= FIELD_PREP(SMI240_WRITE_CAP_BIT_MASK, iio_priv_data->capture); 198 + request |= FIELD_PREP(SMI240_WRITE_ADDR_MASK, *(u8 *)reg_buf); 199 + request |= smi240_crc3(request, SMI240_CRC_INIT, SMI240_CRC_POLY); 200 + 201 + iio_priv_data->spi_buf = cpu_to_be32(request); 202 + 203 + /* 204 + * SMI240 module consists of a 32Bit Out Of Frame (OOF) 205 + * SPI protocol, where the slave interface responds to 206 + * the Master request in the next frame. 207 + * CS signal must toggle (> 700 ns) between the frames. 208 + */ 209 + ret = spi_write(spi, &iio_priv_data->spi_buf, sizeof(request)); 210 + if (ret) 211 + return ret; 212 + 213 + ret = spi_read(spi, &iio_priv_data->spi_buf, sizeof(response)); 214 + if (ret) 215 + return ret; 216 + 217 + response = be32_to_cpu(iio_priv_data->spi_buf); 218 + 219 + if (!smi240_sensor_data_is_valid(response)) 220 + return -EIO; 221 + 222 + *val = FIELD_GET(SMI240_READ_DATA_MASK, response); 223 + 224 + return 0; 225 + } 226 + 227 + static int smi240_regmap_spi_write(void *context, const void *data, 228 + size_t count) 229 + { 230 + u8 reg_addr; 231 + u16 reg_data; 232 + u32 request; 233 + const u8 *data_ptr = data; 234 + struct spi_device *spi = context; 235 + struct iio_dev *indio_dev = dev_get_drvdata(&spi->dev); 236 + struct smi240_data *iio_priv_data = iio_priv(indio_dev); 237 + 238 + if (count < 2) 239 + return -EINVAL; 240 + 241 + reg_addr = data_ptr[0]; 242 + memcpy(&reg_data, &data_ptr[1], sizeof(reg_data)); 243 + 244 + request = FIELD_PREP(SMI240_WRITE_BUS_ID_MASK, SMI240_BUS_ID); 245 + request |= FIELD_PREP(SMI240_WRITE_BIT_MASK, 1); 246 + request |= FIELD_PREP(SMI240_WRITE_ADDR_MASK, reg_addr); 247 + request |= FIELD_PREP(SMI240_WRITE_DATA_MASK, reg_data); 248 + request |= smi240_crc3(request, SMI240_CRC_INIT, SMI240_CRC_POLY); 249 + 250 + iio_priv_data->spi_buf = cpu_to_be32(request); 251 + 252 + return spi_write(spi, &iio_priv_data->spi_buf, sizeof(request)); 253 + } 254 + 255 + static const struct regmap_bus smi240_regmap_bus = { 256 + .read = smi240_regmap_spi_read, 257 + .write = smi240_regmap_spi_write, 258 + }; 259 + 260 + static const struct regmap_config smi240_regmap_config = { 261 + .reg_bits = 8, 262 + .val_bits = 16, 263 + .val_format_endian = REGMAP_ENDIAN_NATIVE, 264 + }; 265 + 266 + static int smi240_soft_reset(struct smi240_data *data) 267 + { 268 + int ret; 269 + 270 + ret = regmap_write(data->regmap, SMI240_CMD_REG, SMI240_SOFT_RESET_CMD); 271 + if (ret) 272 + return ret; 273 + fsleep(SMI240_DIGITAL_STARTUP_DELAY_US); 274 + 275 + return 0; 276 + } 277 + 278 + static int smi240_soft_config(struct smi240_data *data) 279 + { 280 + int ret; 281 + u8 acc_bw, gyr_bw; 282 + u16 request; 283 + 284 + switch (data->accel_filter_freq) { 285 + case SMI240_LOW_BANDWIDTH_HZ: 286 + acc_bw = 0x1; 287 + break; 288 + case SMI240_HIGH_BANDWIDTH_HZ: 289 + acc_bw = 0x0; 290 + break; 291 + default: 292 + return -EINVAL; 293 + } 294 + 295 + switch (data->anglvel_filter_freq) { 296 + case SMI240_LOW_BANDWIDTH_HZ: 297 + gyr_bw = 0x1; 298 + break; 299 + case SMI240_HIGH_BANDWIDTH_HZ: 300 + gyr_bw = 0x0; 301 + break; 302 + default: 303 + return -EINVAL; 304 + } 305 + 306 + request = FIELD_PREP(SMI240_SOFT_CONFIG_EOC_MASK, 1); 307 + request |= FIELD_PREP(SMI240_SOFT_CONFIG_GYR_BW_MASK, gyr_bw); 308 + request |= FIELD_PREP(SMI240_SOFT_CONFIG_ACC_BW_MASK, acc_bw); 309 + request |= FIELD_PREP(SMI240_SOFT_CONFIG_BITE_AUTO_MASK, 1); 310 + request |= FIELD_PREP(SMI240_SOFT_CONFIG_BITE_REP_MASK, 311 + data->built_in_self_test_count - 1); 312 + 313 + ret = regmap_write(data->regmap, SMI240_SOFT_CONFIG_REG, request); 314 + if (ret) 315 + return ret; 316 + 317 + fsleep(SMI240_MECH_STARTUP_DELAY_US + 318 + data->built_in_self_test_count * SMI240_BITE_SEQUENCE_DELAY_US + 319 + SMI240_FILTER_FLUSH_DELAY_US); 320 + 321 + return 0; 322 + } 323 + 324 + static int smi240_get_low_pass_filter_freq(struct smi240_data *data, 325 + int chan_type, int *val) 326 + { 327 + switch (chan_type) { 328 + case IIO_ACCEL: 329 + *val = data->accel_filter_freq; 330 + return 0; 331 + case IIO_ANGL_VEL: 332 + *val = data->anglvel_filter_freq; 333 + return 0; 334 + default: 335 + return -EINVAL; 336 + } 337 + } 338 + 339 + static int smi240_get_data(struct smi240_data *data, int chan_type, int axis, 340 + int *val) 341 + { 342 + u8 reg; 343 + int ret, sample; 344 + 345 + switch (chan_type) { 346 + case IIO_TEMP: 347 + reg = SMI240_TEMP_CUR_REG; 348 + break; 349 + case IIO_ACCEL: 350 + reg = SMI240_ACCEL_X_CUR_REG + (axis - IIO_MOD_X); 351 + break; 352 + case IIO_ANGL_VEL: 353 + reg = SMI240_GYRO_X_CUR_REG + (axis - IIO_MOD_X); 354 + break; 355 + default: 356 + return -EINVAL; 357 + } 358 + 359 + ret = regmap_read(data->regmap, reg, &sample); 360 + if (ret) 361 + return ret; 362 + 363 + *val = sign_extend32(sample, 15); 364 + 365 + return 0; 366 + } 367 + 368 + static irqreturn_t smi240_trigger_handler(int irq, void *p) 369 + { 370 + struct iio_poll_func *pf = p; 371 + struct iio_dev *indio_dev = pf->indio_dev; 372 + struct smi240_data *data = iio_priv(indio_dev); 373 + int base = SMI240_DATA_CAP_FIRST_REG, i = 0; 374 + int ret, chan, sample; 375 + 376 + data->capture = SMI240_CAPTURE_ON; 377 + 378 + iio_for_each_active_channel(indio_dev, chan) { 379 + ret = regmap_read(data->regmap, base + chan, &sample); 380 + data->capture = SMI240_CAPTURE_OFF; 381 + if (ret) 382 + goto out; 383 + data->buf[i++] = sample; 384 + } 385 + 386 + iio_push_to_buffers_with_timestamp(indio_dev, data->buf, pf->timestamp); 387 + 388 + out: 389 + iio_trigger_notify_done(indio_dev->trig); 390 + return IRQ_HANDLED; 391 + } 392 + 393 + static int smi240_read_avail(struct iio_dev *indio_dev, 394 + struct iio_chan_spec const *chan, const int **vals, 395 + int *type, int *length, long mask) 396 + { 397 + switch (mask) { 398 + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 399 + *vals = smi240_low_pass_freqs; 400 + *length = ARRAY_SIZE(smi240_low_pass_freqs); 401 + *type = IIO_VAL_INT; 402 + return IIO_AVAIL_LIST; 403 + default: 404 + return -EINVAL; 405 + } 406 + } 407 + 408 + static int smi240_read_raw(struct iio_dev *indio_dev, 409 + struct iio_chan_spec const *chan, int *val, 410 + int *val2, long mask) 411 + { 412 + int ret; 413 + struct smi240_data *data = iio_priv(indio_dev); 414 + 415 + switch (mask) { 416 + case IIO_CHAN_INFO_RAW: 417 + ret = iio_device_claim_direct_mode(indio_dev); 418 + if (ret) 419 + return ret; 420 + ret = smi240_get_data(data, chan->type, chan->channel2, val); 421 + iio_device_release_direct_mode(indio_dev); 422 + if (ret) 423 + return ret; 424 + return IIO_VAL_INT; 425 + 426 + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 427 + ret = smi240_get_low_pass_filter_freq(data, chan->type, val); 428 + if (ret) 429 + return ret; 430 + return IIO_VAL_INT; 431 + 432 + case IIO_CHAN_INFO_SCALE: 433 + switch (chan->type) { 434 + case IIO_TEMP: 435 + *val = SMI240_TEMP_SCALE / GIGA; 436 + *val2 = SMI240_TEMP_SCALE % GIGA; 437 + return IIO_VAL_INT_PLUS_NANO; 438 + case IIO_ACCEL: 439 + *val = 0; 440 + *val2 = SMI240_ACCEL_SCALE; 441 + return IIO_VAL_INT_PLUS_MICRO; 442 + case IIO_ANGL_VEL: 443 + *val = 0; 444 + *val2 = SMI240_GYRO_SCALE; 445 + return IIO_VAL_INT_PLUS_MICRO; 446 + default: 447 + return -EINVAL; 448 + } 449 + 450 + case IIO_CHAN_INFO_OFFSET: 451 + if (chan->type == IIO_TEMP) { 452 + *val = SMI240_TEMP_OFFSET; 453 + return IIO_VAL_INT; 454 + } else { 455 + return -EINVAL; 456 + } 457 + 458 + default: 459 + return -EINVAL; 460 + } 461 + } 462 + 463 + static int smi240_write_raw(struct iio_dev *indio_dev, 464 + struct iio_chan_spec const *chan, int val, int val2, 465 + long mask) 466 + { 467 + int ret, i; 468 + struct smi240_data *data = iio_priv(indio_dev); 469 + 470 + switch (mask) { 471 + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 472 + for (i = 0; i < ARRAY_SIZE(smi240_low_pass_freqs); i++) { 473 + if (val == smi240_low_pass_freqs[i]) 474 + break; 475 + } 476 + 477 + if (i == ARRAY_SIZE(smi240_low_pass_freqs)) 478 + return -EINVAL; 479 + 480 + switch (chan->type) { 481 + case IIO_ACCEL: 482 + data->accel_filter_freq = val; 483 + break; 484 + case IIO_ANGL_VEL: 485 + data->anglvel_filter_freq = val; 486 + break; 487 + default: 488 + return -EINVAL; 489 + } 490 + break; 491 + default: 492 + return -EINVAL; 493 + } 494 + 495 + /* Write access to soft config is locked until hard/soft reset */ 496 + ret = smi240_soft_reset(data); 497 + if (ret) 498 + return ret; 499 + 500 + return smi240_soft_config(data); 501 + } 502 + 503 + static int smi240_write_raw_get_fmt(struct iio_dev *indio_dev, 504 + struct iio_chan_spec const *chan, long info) 505 + { 506 + switch (info) { 507 + case IIO_CHAN_INFO_SCALE: 508 + switch (chan->type) { 509 + case IIO_TEMP: 510 + return IIO_VAL_INT_PLUS_NANO; 511 + default: 512 + return IIO_VAL_INT_PLUS_MICRO; 513 + } 514 + default: 515 + return IIO_VAL_INT_PLUS_MICRO; 516 + } 517 + } 518 + 519 + static int smi240_init(struct smi240_data *data) 520 + { 521 + int ret; 522 + 523 + data->accel_filter_freq = SMI240_HIGH_BANDWIDTH_HZ; 524 + data->anglvel_filter_freq = SMI240_HIGH_BANDWIDTH_HZ; 525 + data->built_in_self_test_count = SMI240_BUILT_IN_SELF_TEST_COUNT; 526 + 527 + ret = smi240_soft_reset(data); 528 + if (ret) 529 + return ret; 530 + 531 + return smi240_soft_config(data); 532 + } 533 + 534 + static const struct iio_info smi240_info = { 535 + .read_avail = smi240_read_avail, 536 + .read_raw = smi240_read_raw, 537 + .write_raw = smi240_write_raw, 538 + .write_raw_get_fmt = smi240_write_raw_get_fmt, 539 + }; 540 + 541 + static int smi240_probe(struct spi_device *spi) 542 + { 543 + struct device *dev = &spi->dev; 544 + struct iio_dev *indio_dev; 545 + struct regmap *regmap; 546 + struct smi240_data *data; 547 + int ret, response; 548 + 549 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 550 + if (!indio_dev) 551 + return -ENOMEM; 552 + 553 + regmap = devm_regmap_init(dev, &smi240_regmap_bus, dev, 554 + &smi240_regmap_config); 555 + if (IS_ERR(regmap)) 556 + return dev_err_probe(dev, PTR_ERR(regmap), 557 + "Failed to initialize SPI Regmap\n"); 558 + 559 + data = iio_priv(indio_dev); 560 + dev_set_drvdata(dev, indio_dev); 561 + data->regmap = regmap; 562 + data->capture = SMI240_CAPTURE_OFF; 563 + 564 + ret = regmap_read(data->regmap, SMI240_CHIP_ID_REG, &response); 565 + if (ret) 566 + return dev_err_probe(dev, ret, "Read chip id failed\n"); 567 + 568 + if (response != SMI240_CHIP_ID) 569 + dev_info(dev, "Unknown chip id: 0x%04x\n", response); 570 + 571 + ret = smi240_init(data); 572 + if (ret) 573 + return dev_err_probe(dev, ret, 574 + "Device initialization failed\n"); 575 + 576 + indio_dev->channels = smi240_channels; 577 + indio_dev->num_channels = ARRAY_SIZE(smi240_channels); 578 + indio_dev->name = "smi240"; 579 + indio_dev->modes = INDIO_DIRECT_MODE; 580 + indio_dev->info = &smi240_info; 581 + 582 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 583 + iio_pollfunc_store_time, 584 + smi240_trigger_handler, NULL); 585 + if (ret) 586 + return dev_err_probe(dev, ret, 587 + "Setup triggered buffer failed\n"); 588 + 589 + ret = devm_iio_device_register(dev, indio_dev); 590 + if (ret) 591 + return dev_err_probe(dev, ret, "Register IIO device failed\n"); 592 + 593 + return 0; 594 + } 595 + 596 + static const struct spi_device_id smi240_spi_id[] = { 597 + { "smi240" }, 598 + { } 599 + }; 600 + MODULE_DEVICE_TABLE(spi, smi240_spi_id); 601 + 602 + static const struct of_device_id smi240_of_match[] = { 603 + { .compatible = "bosch,smi240" }, 604 + { } 605 + }; 606 + MODULE_DEVICE_TABLE(of, smi240_of_match); 607 + 608 + static struct spi_driver smi240_spi_driver = { 609 + .probe = smi240_probe, 610 + .id_table = smi240_spi_id, 611 + .driver = { 612 + .of_match_table = smi240_of_match, 613 + .name = "smi240", 614 + }, 615 + }; 616 + module_spi_driver(smi240_spi_driver); 617 + 618 + MODULE_AUTHOR("Markus Lochmann <markus.lochmann@de.bosch.com>"); 619 + MODULE_AUTHOR("Stefan Gutmann <stefan.gutmann@de.bosch.com>"); 620 + MODULE_DESCRIPTION("Bosch SMI240 SPI driver"); 621 + MODULE_LICENSE("Dual BSD/GPL");
+2 -2
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 1865 1865 return err; 1866 1866 } 1867 1867 1868 - static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state) 1868 + static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, bool state) 1869 1869 { 1870 1870 const struct st_lsm6dsx_reg *reg; 1871 1871 unsigned int data; ··· 1959 1959 st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, 1960 1960 const struct iio_chan_spec *chan, 1961 1961 enum iio_event_type type, 1962 - enum iio_event_direction dir, int state) 1962 + enum iio_event_direction dir, bool state) 1963 1963 { 1964 1964 struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 1965 1965 struct st_lsm6dsx_hw *hw = sensor->hw;
+44 -4
drivers/iio/industrialio-acpi.c
··· 2 2 /* IIO ACPI helper functions */ 3 3 4 4 #include <linux/acpi.h> 5 - #include <linux/dev_printk.h> 5 + #include <linux/device.h> 6 + #include <linux/export.h> 6 7 #include <linux/iio/iio.h> 7 8 #include <linux/sprintf.h> 8 9 ··· 29 28 char *acpi_method) 30 29 { 31 30 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 32 - struct acpi_device *adev = ACPI_COMPANION(dev); 33 31 char *str; 34 32 union acpi_object *obj, *elements; 33 + acpi_handle handle; 35 34 acpi_status status; 36 35 int i, j, val[3]; 37 36 bool ret = false; 38 37 39 - if (!adev || !acpi_has_method(adev->handle, acpi_method)) 38 + handle = ACPI_HANDLE(dev); 39 + if (!handle) 40 40 return false; 41 41 42 - status = acpi_evaluate_object(adev->handle, acpi_method, NULL, &buffer); 42 + if (!acpi_has_method(handle, acpi_method)) 43 + return false; 44 + 45 + status = acpi_evaluate_object(handle, acpi_method, NULL, &buffer); 43 46 if (ACPI_FAILURE(status)) { 44 47 dev_err(dev, "Failed to get ACPI mount matrix: %d\n", status); 45 48 return false; ··· 88 83 return ret; 89 84 } 90 85 EXPORT_SYMBOL_GPL(iio_read_acpi_mount_matrix); 86 + 87 + /** 88 + * iio_get_acpi_device_name_and_data() - Return ACPI device instance name and driver data 89 + * @dev: Device structure 90 + * @data: Optional pointer to return driver data 91 + * 92 + * When device was enumerated by ACPI ID matching, the user might 93 + * want to set description for the physical chip. In such cases 94 + * the ACPI device instance name might be used. This call may be 95 + * performed to retrieve this information. 96 + * 97 + * NOTE: This helper function exists only for backward compatibility, 98 + * do not use in a new code! 99 + * 100 + * Returns: ACPI device instance name or %NULL. 101 + */ 102 + const char *iio_get_acpi_device_name_and_data(struct device *dev, const void **data) 103 + { 104 + const struct acpi_device_id *id; 105 + acpi_handle handle; 106 + 107 + handle = ACPI_HANDLE(dev); 108 + if (!handle) 109 + return NULL; 110 + 111 + id = acpi_match_device(dev->driver->acpi_match_table, dev); 112 + if (!id) 113 + return NULL; 114 + 115 + if (data) 116 + *data = (const void *)id->driver_data; 117 + 118 + return dev_name(dev); 119 + } 120 + EXPORT_SYMBOL_GPL(iio_get_acpi_device_name_and_data);
+78
drivers/iio/industrialio-backend.c
··· 718 718 return 0; 719 719 } 720 720 721 + /** 722 + * iio_backend_ddr_enable - Enable interface DDR (Double Data Rate) mode 723 + * @back: Backend device 724 + * 725 + * Enable DDR, data is generated by the IP at each front (raising and falling) 726 + * of the bus clock signal. 727 + * 728 + * RETURNS: 729 + * 0 on success, negative error number on failure. 730 + */ 731 + int iio_backend_ddr_enable(struct iio_backend *back) 732 + { 733 + return iio_backend_op_call(back, ddr_enable); 734 + } 735 + EXPORT_SYMBOL_NS_GPL(iio_backend_ddr_enable, IIO_BACKEND); 736 + 737 + /** 738 + * iio_backend_ddr_disable - Disable interface DDR (Double Data Rate) mode 739 + * @back: Backend device 740 + * 741 + * Disable DDR, setting into SDR mode (Single Data Rate). 742 + * 743 + * RETURNS: 744 + * 0 on success, negative error number on failure. 745 + */ 746 + int iio_backend_ddr_disable(struct iio_backend *back) 747 + { 748 + return iio_backend_op_call(back, ddr_disable); 749 + } 750 + EXPORT_SYMBOL_NS_GPL(iio_backend_ddr_disable, IIO_BACKEND); 751 + 752 + /** 753 + * iio_backend_data_stream_enable - Enable data stream 754 + * @back: Backend device 755 + * 756 + * Enable data stream over the bus interface. 757 + * 758 + * RETURNS: 759 + * 0 on success, negative error number on failure. 760 + */ 761 + int iio_backend_data_stream_enable(struct iio_backend *back) 762 + { 763 + return iio_backend_op_call(back, data_stream_enable); 764 + } 765 + EXPORT_SYMBOL_NS_GPL(iio_backend_data_stream_enable, IIO_BACKEND); 766 + 767 + /** 768 + * iio_backend_data_stream_disable - Disable data stream 769 + * @back: Backend device 770 + * 771 + * Disable data stream over the bus interface. 772 + * 773 + * RETURNS: 774 + * 0 on success, negative error number on failure. 775 + */ 776 + int iio_backend_data_stream_disable(struct iio_backend *back) 777 + { 778 + return iio_backend_op_call(back, data_stream_disable); 779 + } 780 + EXPORT_SYMBOL_NS_GPL(iio_backend_data_stream_disable, IIO_BACKEND); 781 + 782 + /** 783 + * iio_backend_data_transfer_addr - Set data address. 784 + * @back: Backend device 785 + * @address: Data register address 786 + * 787 + * Some devices may need to inform the backend about an address 788 + * where to read or write the data. 789 + * 790 + * RETURNS: 791 + * 0 on success, negative error number on failure. 792 + */ 793 + int iio_backend_data_transfer_addr(struct iio_backend *back, u32 address) 794 + { 795 + return iio_backend_op_call(back, data_transfer_addr, address); 796 + } 797 + EXPORT_SYMBOL_NS_GPL(iio_backend_data_transfer_addr, IIO_BACKEND); 798 + 721 799 static struct iio_backend *__devm_iio_backend_fwnode_get(struct device *dev, const char *name, 722 800 struct fwnode_handle *fwnode) 723 801 {
+2 -1
drivers/iio/industrialio-core.c
··· 95 95 [IIO_DELTA_VELOCITY] = "deltavelocity", 96 96 [IIO_COLORTEMP] = "colortemp", 97 97 [IIO_CHROMATICITY] = "chromaticity", 98 + [IIO_ATTENTION] = "attention", 98 99 }; 99 100 100 101 static const char * const iio_modifier_names[] = { ··· 1666 1665 indio_dev = &iio_dev_opaque->indio_dev; 1667 1666 1668 1667 if (sizeof_priv) 1669 - indio_dev->priv = (char *)iio_dev_opaque + 1668 + ACCESS_PRIVATE(indio_dev, priv) = (char *)iio_dev_opaque + 1670 1669 ALIGN(sizeof(*iio_dev_opaque), IIO_DMA_MINALIGN); 1671 1670 1672 1671 indio_dev->dev.parent = parent;
+12 -2
drivers/iio/light/Kconfig
··· 248 248 tristate "Intersil 29018 light and proximity sensor" 249 249 depends on I2C 250 250 select REGMAP_I2C 251 - default n 252 251 help 253 252 If you say yes here you get support for ambient light sensing and 254 253 proximity infrared sensing from Intersil ISL29018. ··· 475 476 depends on I2C 476 477 help 477 478 If you say Y or M here, you get support for Texas Instruments 478 - OPT3001 Ambient Light Sensor. 479 + OPT3001 Ambient Light Sensor, OPT3002 Light-to-Digital Sensor. 479 480 480 481 If built as a dynamically linked module, it will be called 481 482 opt3001. ··· 668 669 669 670 To compile this driver as a module, choose M here: the 670 671 module will be called vcnl4035. 672 + 673 + config VEML3235 674 + tristate "VEML3235 ambient light sensor" 675 + select REGMAP_I2C 676 + depends on I2C 677 + help 678 + Say Y here if you want to build a driver for the Vishay VEML3235 679 + ambient light sensor. 680 + 681 + To compile this driver as a module, choose M here: the 682 + module will be called veml3235. 671 683 672 684 config VEML6030 673 685 tristate "VEML6030 and VEML6035 ambient light sensors"
+1
drivers/iio/light/Makefile
··· 62 62 obj-$(CONFIG_US5182D) += us5182d.o 63 63 obj-$(CONFIG_VCNL4000) += vcnl4000.o 64 64 obj-$(CONFIG_VCNL4035) += vcnl4035.o 65 + obj-$(CONFIG_VEML3235) += veml3235.o 65 66 obj-$(CONFIG_VEML6030) += veml6030.o 66 67 obj-$(CONFIG_VEML6040) += veml6040.o 67 68 obj-$(CONFIG_VEML6070) += veml6070.o
+6 -6
drivers/iio/light/adux1020.c
··· 502 502 static int adux1020_write_event_config(struct iio_dev *indio_dev, 503 503 const struct iio_chan_spec *chan, 504 504 enum iio_event_type type, 505 - enum iio_event_direction dir, int state) 505 + enum iio_event_direction dir, 506 + bool state) 506 507 { 507 508 struct adux1020_data *data = iio_priv(indio_dev); 508 509 int ret, mask; ··· 527 526 mask = ADUX1020_PROX_OFF1_INT; 528 527 529 528 if (state) 530 - state = 0; 529 + ret = regmap_clear_bits(data->regmap, 530 + ADUX1020_REG_INT_MASK, mask); 531 531 else 532 - state = mask; 533 - 534 - ret = regmap_update_bits(data->regmap, ADUX1020_REG_INT_MASK, 535 - mask, state); 532 + ret = regmap_set_bits(data->regmap, 533 + ADUX1020_REG_INT_MASK, mask); 536 534 if (ret < 0) 537 535 goto fail; 538 536
+10 -10
drivers/iio/light/apds9300.c
··· 46 46 struct apds9300_data { 47 47 struct i2c_client *client; 48 48 struct mutex mutex; 49 - int power_state; 49 + bool power_state; 50 50 int thresh_low; 51 51 int thresh_hi; 52 - int intr_en; 52 + bool intr_en; 53 53 }; 54 54 55 55 /* Lux calculation */ ··· 148 148 return 0; 149 149 } 150 150 151 - static int apds9300_set_intr_state(struct apds9300_data *data, int state) 151 + static int apds9300_set_intr_state(struct apds9300_data *data, bool state) 152 152 { 153 153 int ret; 154 154 u8 cmd; ··· 169 169 return 0; 170 170 } 171 171 172 - static int apds9300_set_power_state(struct apds9300_data *data, int state) 172 + static int apds9300_set_power_state(struct apds9300_data *data, bool state) 173 173 { 174 174 int ret; 175 175 u8 cmd; ··· 221 221 * Disable interrupt to ensure thai it is doesn't enable 222 222 * i.e. after device soft reset 223 223 */ 224 - ret = apds9300_set_intr_state(data, 0); 224 + ret = apds9300_set_intr_state(data, false); 225 225 if (ret < 0) 226 226 goto err; 227 227 ··· 321 321 322 322 static int apds9300_write_interrupt_config(struct iio_dev *indio_dev, 323 323 const struct iio_chan_spec *chan, enum iio_event_type type, 324 - enum iio_event_direction dir, int state) 324 + enum iio_event_direction dir, bool state) 325 325 { 326 326 struct apds9300_data *data = iio_priv(indio_dev); 327 327 int ret; ··· 459 459 iio_device_unregister(indio_dev); 460 460 461 461 /* Ensure that power off and interrupts are disabled */ 462 - apds9300_set_intr_state(data, 0); 463 - apds9300_set_power_state(data, 0); 462 + apds9300_set_intr_state(data, false); 463 + apds9300_set_power_state(data, false); 464 464 } 465 465 466 466 static int apds9300_suspend(struct device *dev) ··· 470 470 int ret; 471 471 472 472 mutex_lock(&data->mutex); 473 - ret = apds9300_set_power_state(data, 0); 473 + ret = apds9300_set_power_state(data, false); 474 474 mutex_unlock(&data->mutex); 475 475 476 476 return ret; ··· 483 483 int ret; 484 484 485 485 mutex_lock(&data->mutex); 486 - ret = apds9300_set_power_state(data, 1); 486 + ret = apds9300_set_power_state(data, true); 487 487 mutex_unlock(&data->mutex); 488 488 489 489 return ret;
+2 -5
drivers/iio/light/apds9306.c
··· 1071 1071 const struct iio_chan_spec *chan, 1072 1072 enum iio_event_type type, 1073 1073 enum iio_event_direction dir, 1074 - int state) 1074 + bool state) 1075 1075 { 1076 1076 struct apds9306_data *data = iio_priv(indio_dev); 1077 1077 struct apds9306_regfields *rf = &data->rf; ··· 1125 1125 } 1126 1126 } 1127 1127 case IIO_EV_TYPE_THRESH_ADAPTIVE: 1128 - if (state) 1129 - return regmap_field_write(rf->int_thresh_var_en, 1); 1130 - else 1131 - return regmap_field_write(rf->int_thresh_var_en, 0); 1128 + return regmap_field_write(rf->int_thresh_var_en, state); 1132 1129 default: 1133 1130 return -EINVAL; 1134 1131 }
+3 -7
drivers/iio/light/apds9960.c
··· 133 133 struct regmap_field *reg_enable_pxs; 134 134 135 135 /* state */ 136 - int als_int; 137 - int pxs_int; 136 + bool als_int; 137 + bool pxs_int; 138 138 int gesture_mode_running; 139 139 140 140 /* gain values */ ··· 749 749 default: 750 750 return -EINVAL; 751 751 } 752 - 753 - return 0; 754 752 } 755 753 756 754 static int apds9960_write_event_config(struct iio_dev *indio_dev, 757 755 const struct iio_chan_spec *chan, 758 756 enum iio_event_type type, 759 757 enum iio_event_direction dir, 760 - int state) 758 + bool state) 761 759 { 762 760 struct apds9960_data *data = iio_priv(indio_dev); 763 761 int ret; 764 - 765 - state = !!state; 766 762 767 763 switch (chan->type) { 768 764 case IIO_PROXIMITY:
+23 -27
drivers/iio/light/bh1745.c
··· 638 638 static int bh1745_write_event_config(struct iio_dev *indio_dev, 639 639 const struct iio_chan_spec *chan, 640 640 enum iio_event_type type, 641 - enum iio_event_direction dir, int state) 641 + enum iio_event_direction dir, bool state) 642 642 { 643 643 struct bh1745_data *data = iio_priv(indio_dev); 644 644 int value; 645 645 646 - if (state == 0) 646 + if (!state) 647 647 return regmap_clear_bits(data->regmap, 648 648 BH1745_INTR, BH1745_INTR_ENABLE); 649 649 650 - if (state == 1) { 651 - /* Latch is always enabled when enabling interrupt */ 652 - value = BH1745_INTR_ENABLE; 650 + /* Latch is always enabled when enabling interrupt */ 651 + value = BH1745_INTR_ENABLE; 653 652 654 - switch (chan->channel2) { 655 - case IIO_MOD_LIGHT_RED: 656 - return regmap_write(data->regmap, BH1745_INTR, 657 - value | FIELD_PREP(BH1745_INTR_SOURCE_MASK, 658 - BH1745_INTR_SOURCE_RED)); 653 + switch (chan->channel2) { 654 + case IIO_MOD_LIGHT_RED: 655 + return regmap_write(data->regmap, BH1745_INTR, 656 + value | FIELD_PREP(BH1745_INTR_SOURCE_MASK, 657 + BH1745_INTR_SOURCE_RED)); 659 658 660 - case IIO_MOD_LIGHT_GREEN: 661 - return regmap_write(data->regmap, BH1745_INTR, 662 - value | FIELD_PREP(BH1745_INTR_SOURCE_MASK, 663 - BH1745_INTR_SOURCE_GREEN)); 659 + case IIO_MOD_LIGHT_GREEN: 660 + return regmap_write(data->regmap, BH1745_INTR, 661 + value | FIELD_PREP(BH1745_INTR_SOURCE_MASK, 662 + BH1745_INTR_SOURCE_GREEN)); 664 663 665 - case IIO_MOD_LIGHT_BLUE: 666 - return regmap_write(data->regmap, BH1745_INTR, 667 - value | FIELD_PREP(BH1745_INTR_SOURCE_MASK, 668 - BH1745_INTR_SOURCE_BLUE)); 664 + case IIO_MOD_LIGHT_BLUE: 665 + return regmap_write(data->regmap, BH1745_INTR, 666 + value | FIELD_PREP(BH1745_INTR_SOURCE_MASK, 667 + BH1745_INTR_SOURCE_BLUE)); 669 668 670 - case IIO_MOD_LIGHT_CLEAR: 671 - return regmap_write(data->regmap, BH1745_INTR, 672 - value | FIELD_PREP(BH1745_INTR_SOURCE_MASK, 673 - BH1745_INTR_SOURCE_CLEAR)); 669 + case IIO_MOD_LIGHT_CLEAR: 670 + return regmap_write(data->regmap, BH1745_INTR, 671 + value | FIELD_PREP(BH1745_INTR_SOURCE_MASK, 672 + BH1745_INTR_SOURCE_CLEAR)); 674 673 675 - default: 676 - return -EINVAL; 677 - } 674 + default: 675 + return -EINVAL; 678 676 } 679 - 680 - return -EINVAL; 681 677 } 682 678 683 679 static int bh1745_read_avail(struct iio_dev *indio_dev,
+1 -1
drivers/iio/light/cm36651.c
··· 529 529 const struct iio_chan_spec *chan, 530 530 enum iio_event_type type, 531 531 enum iio_event_direction dir, 532 - int state) 532 + bool state) 533 533 { 534 534 struct cm36651_data *cm36651 = iio_priv(indio_dev); 535 535 int cmd, ret;
+1 -1
drivers/iio/light/gp2ap002.c
··· 340 340 const struct iio_chan_spec *chan, 341 341 enum iio_event_type type, 342 342 enum iio_event_direction dir, 343 - int state) 343 + bool state) 344 344 { 345 345 struct gp2ap002 *gp2ap002 = iio_priv(indio_dev); 346 346
+1 -1
drivers/iio/light/gp2ap020a00f.c
··· 1159 1159 const struct iio_chan_spec *chan, 1160 1160 enum iio_event_type type, 1161 1161 enum iio_event_direction dir, 1162 - int state) 1162 + bool state) 1163 1163 { 1164 1164 struct gp2ap020a00f_data *data = iio_priv(indio_dev); 1165 1165 enum gp2ap020a00f_cmd cmd;
+107 -86
drivers/iio/light/hid-sensor-prox.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_PRESENCE 0 16 + static const u32 prox_usage_ids[] = { 17 + HID_USAGE_SENSOR_HUMAN_PRESENCE, 18 + HID_USAGE_SENSOR_HUMAN_PROXIMITY, 19 + HID_USAGE_SENSOR_HUMAN_ATTENTION, 20 + }; 21 + 22 + #define MAX_CHANNELS ARRAY_SIZE(prox_usage_ids) 23 + 24 + enum { 25 + HID_HUMAN_PRESENCE, 26 + HID_HUMAN_PROXIMITY, 27 + HID_HUMAN_ATTENTION, 28 + }; 17 29 18 30 struct prox_state { 19 31 struct hid_sensor_hub_callbacks callbacks; 20 32 struct hid_sensor_common common_attributes; 21 - struct hid_sensor_hub_attribute_info prox_attr; 22 - u32 human_presence; 33 + struct hid_sensor_hub_attribute_info prox_attr[MAX_CHANNELS]; 34 + struct iio_chan_spec channels[MAX_CHANNELS]; 35 + u32 channel2usage[MAX_CHANNELS]; 36 + u32 human_presence[MAX_CHANNELS]; 23 37 int scale_pre_decml; 24 38 int scale_post_decml; 25 39 int scale_precision; 40 + unsigned long scan_mask[2]; /* One entry plus one terminator. */ 41 + int num_channels; 26 42 }; 27 43 28 44 static const u32 prox_sensitivity_addresses[] = { ··· 46 30 HID_USAGE_SENSOR_DATA_PRESENCE, 47 31 }; 48 32 49 - /* Channel definitions */ 50 - static const struct iio_chan_spec prox_channels[] = { 51 - { 52 - .type = IIO_PROXIMITY, 53 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 54 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | 55 - BIT(IIO_CHAN_INFO_SCALE) | 56 - BIT(IIO_CHAN_INFO_SAMP_FREQ) | 57 - BIT(IIO_CHAN_INFO_HYSTERESIS), 58 - .scan_index = CHANNEL_SCAN_INDEX_PRESENCE, 33 + #define PROX_CHANNEL(_is_proximity, _channel) \ 34 + {\ 35 + .type = _is_proximity ? IIO_PROXIMITY : IIO_ATTENTION,\ 36 + .info_mask_separate = _is_proximity ? BIT(IIO_CHAN_INFO_RAW) :\ 37 + BIT(IIO_CHAN_INFO_PROCESSED),\ 38 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |\ 39 + BIT(IIO_CHAN_INFO_SCALE) |\ 40 + BIT(IIO_CHAN_INFO_SAMP_FREQ) |\ 41 + BIT(IIO_CHAN_INFO_HYSTERESIS),\ 42 + .indexed = _is_proximity,\ 43 + .channel = _channel,\ 59 44 } 45 + 46 + /* Channel definitions (same order as prox_usage_ids) */ 47 + static const struct iio_chan_spec prox_channels[] = { 48 + PROX_CHANNEL(true, HID_HUMAN_PRESENCE), 49 + PROX_CHANNEL(true, HID_HUMAN_PROXIMITY), 50 + PROX_CHANNEL(false, 0), 60 51 }; 61 52 62 53 /* Adjust channel real bits based on report descriptor */ ··· 85 62 { 86 63 struct prox_state *prox_state = iio_priv(indio_dev); 87 64 struct hid_sensor_hub_device *hsdev; 88 - int report_id = -1; 65 + int report_id; 89 66 u32 address; 90 67 int ret_type; 91 68 s32 min; ··· 94 71 *val2 = 0; 95 72 switch (mask) { 96 73 case IIO_CHAN_INFO_RAW: 97 - switch (chan->scan_index) { 98 - case CHANNEL_SCAN_INDEX_PRESENCE: 99 - report_id = prox_state->prox_attr.report_id; 100 - min = prox_state->prox_attr.logical_minimum; 101 - address = HID_USAGE_SENSOR_HUMAN_PRESENCE; 102 - hsdev = prox_state->common_attributes.hsdev; 103 - break; 104 - default: 105 - report_id = -1; 106 - break; 107 - } 108 - if (report_id >= 0) { 109 - hid_sensor_power_state(&prox_state->common_attributes, 110 - true); 111 - *val = sensor_hub_input_attr_get_raw_value( 112 - hsdev, hsdev->usage, address, report_id, 113 - SENSOR_HUB_SYNC, min < 0); 114 - hid_sensor_power_state(&prox_state->common_attributes, 115 - false); 116 - } else { 117 - *val = 0; 74 + if (chan->scan_index >= prox_state->num_channels) 118 75 return -EINVAL; 119 - } 76 + address = prox_state->channel2usage[chan->scan_index]; 77 + report_id = prox_state->prox_attr[chan->scan_index].report_id; 78 + hsdev = prox_state->common_attributes.hsdev; 79 + min = prox_state->prox_attr[chan->scan_index].logical_minimum; 80 + hid_sensor_power_state(&prox_state->common_attributes, true); 81 + *val = sensor_hub_input_attr_get_raw_value(hsdev, 82 + hsdev->usage, 83 + address, 84 + report_id, 85 + SENSOR_HUB_SYNC, 86 + min < 0); 87 + if (prox_state->channel2usage[chan->scan_index] == 88 + HID_USAGE_SENSOR_HUMAN_ATTENTION) 89 + *val *= 100; 90 + hid_sensor_power_state(&prox_state->common_attributes, false); 120 91 ret_type = IIO_VAL_INT; 121 92 break; 122 93 case IIO_CHAN_INFO_SCALE: ··· 120 103 break; 121 104 case IIO_CHAN_INFO_OFFSET: 122 105 *val = hid_sensor_convert_exponent( 123 - prox_state->prox_attr.unit_expo); 106 + prox_state->prox_attr[chan->scan_index].unit_expo); 124 107 ret_type = IIO_VAL_INT; 125 108 break; 126 109 case IIO_CHAN_INFO_SAMP_FREQ: ··· 170 153 .write_raw = &prox_write_raw, 171 154 }; 172 155 173 - /* Function to push data to buffer */ 174 - static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *data, 175 - int len) 176 - { 177 - dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); 178 - iio_push_to_buffers(indio_dev, data); 179 - } 180 - 181 156 /* Callback handler to send event after all samples are received and captured */ 182 157 static int prox_proc_event(struct hid_sensor_hub_device *hsdev, 183 158 unsigned usage_id, ··· 179 170 struct prox_state *prox_state = iio_priv(indio_dev); 180 171 181 172 dev_dbg(&indio_dev->dev, "prox_proc_event\n"); 182 - if (atomic_read(&prox_state->common_attributes.data_ready)) 183 - hid_sensor_push_data(indio_dev, 184 - &prox_state->human_presence, 185 - sizeof(prox_state->human_presence)); 173 + if (atomic_read(&prox_state->common_attributes.data_ready)) { 174 + dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); 175 + iio_push_to_buffers(indio_dev, &prox_state->human_presence); 176 + } 186 177 187 178 return 0; 188 179 } ··· 195 186 { 196 187 struct iio_dev *indio_dev = platform_get_drvdata(priv); 197 188 struct prox_state *prox_state = iio_priv(indio_dev); 198 - int ret = -EINVAL; 189 + int multiplier = 1; 190 + int chan; 199 191 200 - switch (usage_id) { 201 - case HID_USAGE_SENSOR_HUMAN_PRESENCE: 202 - switch (raw_len) { 203 - case 1: 204 - prox_state->human_presence = *(u8 *)raw_data; 205 - return 0; 206 - case 4: 207 - prox_state->human_presence = *(u32 *)raw_data; 208 - return 0; 209 - default: 192 + for (chan = 0; chan < prox_state->num_channels; chan++) 193 + if (prox_state->channel2usage[chan] == usage_id) 210 194 break; 211 - } 212 - break; 195 + if (chan == prox_state->num_channels) 196 + return -EINVAL; 197 + 198 + if (usage_id == HID_USAGE_SENSOR_HUMAN_ATTENTION) 199 + multiplier = 100; 200 + 201 + switch (raw_len) { 202 + case 1: 203 + prox_state->human_presence[chan] = *(u8 *)raw_data * multiplier; 204 + return 0; 205 + case 4: 206 + prox_state->human_presence[chan] = *(u32 *)raw_data * multiplier; 207 + return 0; 213 208 } 214 209 215 - return ret; 210 + return -EINVAL; 216 211 } 217 212 218 213 /* Parse report which is specific to an usage id*/ 219 214 static int prox_parse_report(struct platform_device *pdev, 220 215 struct hid_sensor_hub_device *hsdev, 221 - struct iio_chan_spec *channels, 222 - unsigned usage_id, 223 216 struct prox_state *st) 224 217 { 218 + struct iio_chan_spec *channels = st->channels; 219 + int index = 0; 225 220 int ret; 221 + int i; 226 222 227 - ret = sensor_hub_input_get_attribute_info(hsdev, HID_INPUT_REPORT, 228 - usage_id, 229 - HID_USAGE_SENSOR_HUMAN_PRESENCE, 230 - &st->prox_attr); 231 - if (ret < 0) 223 + for (i = 0; i < MAX_CHANNELS; i++) { 224 + u32 usage_id = prox_usage_ids[i]; 225 + 226 + ret = sensor_hub_input_get_attribute_info(hsdev, 227 + HID_INPUT_REPORT, 228 + hsdev->usage, 229 + usage_id, 230 + &st->prox_attr[index]); 231 + if (ret < 0) 232 + continue; 233 + st->channel2usage[index] = usage_id; 234 + st->scan_mask[0] |= BIT(index); 235 + channels[index] = prox_channels[i]; 236 + channels[index].scan_index = index; 237 + prox_adjust_channel_bit_mask(channels, index, 238 + st->prox_attr[index].size); 239 + dev_dbg(&pdev->dev, "prox %x:%x\n", st->prox_attr[index].index, 240 + st->prox_attr[index].report_id); 241 + index++; 242 + } 243 + 244 + if (!index) 232 245 return ret; 233 - prox_adjust_channel_bit_mask(channels, CHANNEL_SCAN_INDEX_PRESENCE, 234 - st->prox_attr.size); 235 246 236 - dev_dbg(&pdev->dev, "prox %x:%x\n", st->prox_attr.index, 237 - st->prox_attr.report_id); 247 + st->num_channels = index; 238 248 239 - return ret; 249 + return 0; 240 250 } 241 251 242 252 /* Function to initialize the processing for usage id */ ··· 286 258 return ret; 287 259 } 288 260 289 - indio_dev->channels = devm_kmemdup(&pdev->dev, prox_channels, 290 - sizeof(prox_channels), GFP_KERNEL); 291 - if (!indio_dev->channels) { 292 - dev_err(&pdev->dev, "failed to duplicate channels\n"); 293 - return -ENOMEM; 294 - } 295 - 296 - ret = prox_parse_report(pdev, hsdev, 297 - (struct iio_chan_spec *)indio_dev->channels, 298 - hsdev->usage, prox_state); 261 + ret = prox_parse_report(pdev, hsdev, prox_state); 299 262 if (ret) { 300 263 dev_err(&pdev->dev, "failed to setup attributes\n"); 301 264 return ret; 302 265 } 303 266 304 - indio_dev->num_channels = ARRAY_SIZE(prox_channels); 267 + indio_dev->num_channels = prox_state->num_channels; 268 + indio_dev->channels = prox_state->channels; 269 + indio_dev->available_scan_masks = prox_state->scan_mask; 305 270 indio_dev->info = &prox_info; 306 271 indio_dev->name = name; 307 272 indio_dev->modes = INDIO_DIRECT_MODE;
+1 -1
drivers/iio/light/iqs621-als.c
··· 271 271 const struct iio_chan_spec *chan, 272 272 enum iio_event_type type, 273 273 enum iio_event_direction dir, 274 - int state) 274 + bool state) 275 275 { 276 276 struct iqs621_als_private *iqs621_als = iio_priv(indio_dev); 277 277 struct iqs62x_core *iqs62x = iqs621_als->iqs62x;
+12 -26
drivers/iio/light/isl29018.c
··· 8 8 * Copyright (c) 2010, NVIDIA Corporation. 9 9 */ 10 10 11 - #include <linux/module.h> 12 11 #include <linux/i2c.h> 13 12 #include <linux/err.h> 13 + #include <linux/mod_devicetable.h> 14 + #include <linux/module.h> 14 15 #include <linux/mutex.h> 15 16 #include <linux/delay.h> 16 17 #include <linux/regmap.h> 17 18 #include <linux/regulator/consumer.h> 18 19 #include <linux/slab.h> 20 + 19 21 #include <linux/iio/iio.h> 20 22 #include <linux/iio/sysfs.h> 21 - #include <linux/acpi.h> 22 23 23 24 #define ISL29018_CONV_TIME_MS 100 24 25 ··· 688 687 }, 689 688 }; 690 689 691 - static const char *isl29018_match_acpi_device(struct device *dev, int *data) 692 - { 693 - const struct acpi_device_id *id; 694 - 695 - id = acpi_match_device(dev->driver->acpi_match_table, dev); 696 - 697 - if (!id) 698 - return NULL; 699 - 700 - *data = (int)id->driver_data; 701 - 702 - return dev_name(dev); 703 - } 704 - 705 690 static void isl29018_disable_regulator_action(void *_data) 706 691 { 707 692 struct isl29018_chip *chip = _data; ··· 703 716 const struct i2c_device_id *id = i2c_client_get_device_id(client); 704 717 struct isl29018_chip *chip; 705 718 struct iio_dev *indio_dev; 719 + const void *ddata = NULL; 720 + const char *name; 721 + int dev_id; 706 722 int err; 707 - const char *name = NULL; 708 - int dev_id = 0; 709 723 710 724 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); 711 725 if (!indio_dev) ··· 719 731 if (id) { 720 732 name = id->name; 721 733 dev_id = id->driver_data; 734 + } else { 735 + name = iio_get_acpi_device_name_and_data(&client->dev, &ddata); 736 + dev_id = (intptr_t)ddata; 722 737 } 723 - 724 - if (ACPI_HANDLE(&client->dev)) 725 - name = isl29018_match_acpi_device(&client->dev, &dev_id); 726 738 727 739 mutex_init(&chip->lock); 728 740 ··· 820 832 static DEFINE_SIMPLE_DEV_PM_OPS(isl29018_pm_ops, isl29018_suspend, 821 833 isl29018_resume); 822 834 823 - #ifdef CONFIG_ACPI 824 835 static const struct acpi_device_id isl29018_acpi_match[] = { 825 836 {"ISL29018", isl29018}, 826 837 {"ISL29023", isl29023}, 827 838 {"ISL29035", isl29035}, 828 - {}, 839 + {} 829 840 }; 830 841 MODULE_DEVICE_TABLE(acpi, isl29018_acpi_match); 831 - #endif 832 842 833 843 static const struct i2c_device_id isl29018_id[] = { 834 844 {"isl29018", isl29018}, ··· 840 854 { .compatible = "isil,isl29018", }, 841 855 { .compatible = "isil,isl29023", }, 842 856 { .compatible = "isil,isl29035", }, 843 - { }, 857 + { } 844 858 }; 845 859 MODULE_DEVICE_TABLE(of, isl29018_of_match); 846 860 847 861 static struct i2c_driver isl29018_driver = { 848 862 .driver = { 849 863 .name = "isl29018", 850 - .acpi_match_table = ACPI_PTR(isl29018_acpi_match), 864 + .acpi_match_table = isl29018_acpi_match, 851 865 .pm = pm_sleep_ptr(&isl29018_pm_ops), 852 866 .of_match_table = isl29018_of_match, 853 867 },
+2 -5
drivers/iio/light/ltr390.c
··· 553 553 const struct iio_chan_spec *chan, 554 554 enum iio_event_type type, 555 555 enum iio_event_direction dir, 556 - int state) 556 + bool state) 557 557 { 558 558 struct ltr390_data *data = iio_priv(indio_dev); 559 559 int ret; 560 560 561 - if (state != 1 && state != 0) 562 - return -EINVAL; 563 - 564 - if (state == 0) 561 + if (!state) 565 562 return regmap_clear_bits(data->regmap, LTR390_INT_CFG, LTR390_LS_INT_EN); 566 563 567 564 guard(mutex)(&data->lock);
+11 -24
drivers/iio/light/ltr501.c
··· 15 15 #include <linux/err.h> 16 16 #include <linux/delay.h> 17 17 #include <linux/regmap.h> 18 - #include <linux/acpi.h> 19 18 #include <linux/regulator/consumer.h> 20 19 21 20 #include <linux/iio/iio.h> ··· 1077 1078 static int ltr501_write_event_config(struct iio_dev *indio_dev, 1078 1079 const struct iio_chan_spec *chan, 1079 1080 enum iio_event_type type, 1080 - enum iio_event_direction dir, int state) 1081 + enum iio_event_direction dir, bool state) 1081 1082 { 1082 1083 struct ltr501_data *data = iio_priv(indio_dev); 1083 1084 int ret; 1084 - 1085 - /* only 1 and 0 are valid inputs */ 1086 - if (state != 1 && state != 0) 1087 - return -EINVAL; 1088 1085 1089 1086 switch (chan->type) { 1090 1087 case IIO_INTENSITY: ··· 1417 1422 data->ps_contr & ~LTR501_CONTR_ACTIVE); 1418 1423 } 1419 1424 1420 - static const char *ltr501_match_acpi_device(struct device *dev, int *chip_idx) 1421 - { 1422 - const struct acpi_device_id *id; 1423 - 1424 - id = acpi_match_device(dev->driver->acpi_match_table, dev); 1425 - if (!id) 1426 - return NULL; 1427 - *chip_idx = id->driver_data; 1428 - return dev_name(dev); 1429 - } 1430 - 1431 1425 static int ltr501_probe(struct i2c_client *client) 1432 1426 { 1433 1427 const struct i2c_device_id *id = i2c_client_get_device_id(client); ··· 1424 1440 struct ltr501_data *data; 1425 1441 struct iio_dev *indio_dev; 1426 1442 struct regmap *regmap; 1427 - int ret, partid, chip_idx = 0; 1428 - const char *name = NULL; 1443 + const void *ddata = NULL; 1444 + int partid, chip_idx; 1445 + const char *name; 1446 + int ret; 1429 1447 1430 1448 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 1431 1449 if (!indio_dev) ··· 1509 1523 if (id) { 1510 1524 name = id->name; 1511 1525 chip_idx = id->driver_data; 1512 - } else if (ACPI_HANDLE(&client->dev)) { 1513 - name = ltr501_match_acpi_device(&client->dev, &chip_idx); 1514 1526 } else { 1515 - return -ENODEV; 1527 + name = iio_get_acpi_device_name_and_data(&client->dev, &ddata); 1528 + chip_idx = (intptr_t)ddata; 1516 1529 } 1530 + if (!name) 1531 + return -ENODEV; 1517 1532 1518 1533 data->chip_info = &ltr501_chip_info_tbl[chip_idx]; 1519 1534 ··· 1597 1610 static DEFINE_SIMPLE_DEV_PM_OPS(ltr501_pm_ops, ltr501_suspend, ltr501_resume); 1598 1611 1599 1612 static const struct acpi_device_id ltr_acpi_match[] = { 1600 - { "LTER0501", ltr501 }, 1601 - { "LTER0559", ltr559 }, 1602 1613 { "LTER0301", ltr301 }, 1614 + /* https://www.catalog.update.microsoft.com/Search.aspx?q=lter0303 */ 1615 + { "LTER0303", ltr303 }, 1603 1616 { }, 1604 1617 }; 1605 1618 MODULE_DEVICE_TABLE(acpi, ltr_acpi_match);
+1 -1
drivers/iio/light/max44009.c
··· 422 422 const struct iio_chan_spec *chan, 423 423 enum iio_event_type type, 424 424 enum iio_event_direction dir, 425 - int state) 425 + bool state) 426 426 { 427 427 struct max44009_data *data = iio_priv(indio_dev); 428 428 int ret;
+157 -34
drivers/iio/light/opt3001.c
··· 70 70 #define OPT3001_RESULT_READY_SHORT 150 71 71 #define OPT3001_RESULT_READY_LONG 1000 72 72 73 + struct opt3001_scale { 74 + int val; 75 + int val2; 76 + }; 77 + 78 + struct opt3001_chip_info { 79 + const struct iio_chan_spec (*channels)[2]; 80 + enum iio_chan_type chan_type; 81 + int num_channels; 82 + 83 + const struct opt3001_scale (*scales)[12]; 84 + /* 85 + * Factor as specified by conversion equation in datasheet. 86 + * eg. 0.01 (scaled to integer 10) for opt3001. 87 + */ 88 + int factor_whole; 89 + /* 90 + * Factor to compensate for potentially scaled factor_whole. 91 + */ 92 + int factor_integer; 93 + /* 94 + * Factor used to align decimal part of proccessed value to six decimal 95 + * places. 96 + */ 97 + int factor_decimal; 98 + 99 + bool has_id; 100 + }; 101 + 73 102 struct opt3001 { 74 103 struct i2c_client *client; 75 104 struct device *dev; ··· 108 79 bool result_ready; 109 80 wait_queue_head_t result_ready_queue; 110 81 u16 result; 82 + const struct opt3001_chip_info *chip_info; 111 83 112 84 u32 int_time; 113 85 u32 mode; ··· 120 90 u8 low_thresh_exp; 121 91 122 92 bool use_irq; 123 - }; 124 - 125 - struct opt3001_scale { 126 - int val; 127 - int val2; 128 93 }; 129 94 130 95 static const struct opt3001_scale opt3001_scales[] = { ··· 173 148 }, 174 149 }; 175 150 151 + static const struct opt3001_scale opt3002_scales[] = { 152 + { 153 + .val = 4914, 154 + .val2 = 0, 155 + }, 156 + { 157 + .val = 9828, 158 + .val2 = 0, 159 + }, 160 + { 161 + .val = 19656, 162 + .val2 = 0, 163 + }, 164 + { 165 + .val = 39312, 166 + .val2 = 0, 167 + }, 168 + { 169 + .val = 78624, 170 + .val2 = 0, 171 + }, 172 + { 173 + .val = 157248, 174 + .val2 = 0, 175 + }, 176 + { 177 + .val = 314496, 178 + .val2 = 0, 179 + }, 180 + { 181 + .val = 628992, 182 + .val2 = 0, 183 + }, 184 + { 185 + .val = 1257984, 186 + .val2 = 0, 187 + }, 188 + { 189 + .val = 2515968, 190 + .val2 = 0, 191 + }, 192 + { 193 + .val = 5031936, 194 + .val2 = 0, 195 + }, 196 + { 197 + .val = 10063872, 198 + .val2 = 0, 199 + }, 200 + }; 201 + 176 202 static int opt3001_find_scale(const struct opt3001 *opt, int val, 177 203 int val2, u8 *exponent) 178 204 { 179 205 int i; 180 - 181 - for (i = 0; i < ARRAY_SIZE(opt3001_scales); i++) { 182 - const struct opt3001_scale *scale = &opt3001_scales[i]; 183 - 206 + for (i = 0; i < ARRAY_SIZE(*opt->chip_info->scales); i++) { 207 + const struct opt3001_scale *scale = &(*opt->chip_info->scales)[i]; 184 208 /* 185 - * Combine the integer and micro parts for comparison 186 - * purposes. Use milli lux precision to avoid 32-bit integer 187 - * overflows. 209 + * Compare the integer and micro parts to determine value scale. 188 210 */ 189 - if ((val * 1000 + val2 / 1000) <= 190 - (scale->val * 1000 + scale->val2 / 1000)) { 211 + if (val < scale->val || 212 + (val == scale->val && val2 <= scale->val2)) { 191 213 *exponent = i; 192 214 return 0; 193 215 } ··· 246 174 static void opt3001_to_iio_ret(struct opt3001 *opt, u8 exponent, 247 175 u16 mantissa, int *val, int *val2) 248 176 { 249 - int lux; 177 + int ret; 178 + int whole = opt->chip_info->factor_whole; 179 + int integer = opt->chip_info->factor_integer; 180 + int decimal = opt->chip_info->factor_decimal; 250 181 251 - lux = 10 * (mantissa << exponent); 252 - *val = lux / 1000; 253 - *val2 = (lux - (*val * 1000)) * 1000; 182 + ret = whole * (mantissa << exponent); 183 + *val = ret / integer; 184 + *val2 = (ret - (*val * integer)) * decimal; 254 185 } 255 186 256 187 static void opt3001_set_mode(struct opt3001 *opt, u16 *reg, u16 mode) ··· 300 225 IIO_CHAN_SOFT_TIMESTAMP(1), 301 226 }; 302 227 303 - static int opt3001_get_lux(struct opt3001 *opt, int *val, int *val2) 228 + static const struct iio_chan_spec opt3002_channels[] = { 229 + { 230 + .type = IIO_INTENSITY, 231 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 232 + BIT(IIO_CHAN_INFO_INT_TIME), 233 + .event_spec = opt3001_event_spec, 234 + .num_event_specs = ARRAY_SIZE(opt3001_event_spec), 235 + }, 236 + IIO_CHAN_SOFT_TIMESTAMP(1), 237 + }; 238 + 239 + static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2) 304 240 { 305 241 int ret; 306 242 u16 mantissa; ··· 483 397 if (opt->mode == OPT3001_CONFIGURATION_M_CONTINUOUS) 484 398 return -EBUSY; 485 399 486 - if (chan->type != IIO_LIGHT) 400 + if (chan->type != opt->chip_info->chan_type) 487 401 return -EINVAL; 488 402 489 403 mutex_lock(&opt->lock); 490 404 491 405 switch (mask) { 406 + case IIO_CHAN_INFO_RAW: 492 407 case IIO_CHAN_INFO_PROCESSED: 493 - ret = opt3001_get_lux(opt, val, val2); 408 + ret = opt3001_get_processed(opt, val, val2); 494 409 break; 495 410 case IIO_CHAN_INFO_INT_TIME: 496 411 ret = opt3001_get_int_time(opt, val, val2); ··· 515 428 if (opt->mode == OPT3001_CONFIGURATION_M_CONTINUOUS) 516 429 return -EBUSY; 517 430 518 - if (chan->type != IIO_LIGHT) 431 + if (chan->type != opt->chip_info->chan_type) 519 432 return -EINVAL; 520 433 521 434 if (mask != IIO_CHAN_INFO_INT_TIME) ··· 566 479 { 567 480 struct opt3001 *opt = iio_priv(iio); 568 481 int ret; 482 + int whole; 483 + int integer; 484 + int decimal; 569 485 570 486 u16 mantissa; 571 487 u16 value; ··· 587 497 goto err; 588 498 } 589 499 590 - mantissa = (((val * 1000) + (val2 / 1000)) / 10) >> exponent; 500 + whole = opt->chip_info->factor_whole; 501 + integer = opt->chip_info->factor_integer; 502 + decimal = opt->chip_info->factor_decimal; 503 + 504 + mantissa = (((val * integer) + (val2 / decimal)) / whole) >> exponent; 505 + 591 506 value = (exponent << 12) | mantissa; 592 507 593 508 switch (dir) { ··· 634 539 635 540 static int opt3001_write_event_config(struct iio_dev *iio, 636 541 const struct iio_chan_spec *chan, enum iio_event_type type, 637 - enum iio_event_direction dir, int state) 542 + enum iio_event_direction dir, bool state) 638 543 { 639 544 struct opt3001 *opt = iio_priv(iio); 640 545 int ret; ··· 705 610 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_DEVICE_ID); 706 611 if (ret < 0) { 707 612 dev_err(opt->dev, "failed to read register %02x\n", 708 - OPT3001_DEVICE_ID); 613 + OPT3001_DEVICE_ID); 709 614 return ret; 710 615 } 711 616 ··· 787 692 struct opt3001 *opt = iio_priv(iio); 788 693 int ret; 789 694 bool wake_result_ready_queue = false; 695 + enum iio_chan_type chan_type = opt->chip_info->chan_type; 790 696 791 697 if (!opt->ok_to_ignore_lock) 792 698 mutex_lock(&opt->lock); ··· 803 707 OPT3001_CONFIGURATION_M_CONTINUOUS) { 804 708 if (ret & OPT3001_CONFIGURATION_FH) 805 709 iio_push_event(iio, 806 - IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0, 710 + IIO_UNMOD_EVENT_CODE(chan_type, 0, 807 711 IIO_EV_TYPE_THRESH, 808 712 IIO_EV_DIR_RISING), 809 713 iio_get_time_ns(iio)); 810 714 if (ret & OPT3001_CONFIGURATION_FL) 811 715 iio_push_event(iio, 812 - IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0, 716 + IIO_UNMOD_EVENT_CODE(chan_type, 0, 813 717 IIO_EV_TYPE_THRESH, 814 718 IIO_EV_DIR_FALLING), 815 719 iio_get_time_ns(iio)); ··· 851 755 opt = iio_priv(iio); 852 756 opt->client = client; 853 757 opt->dev = dev; 758 + opt->chip_info = i2c_get_match_data(client); 854 759 855 760 mutex_init(&opt->lock); 856 761 init_waitqueue_head(&opt->result_ready_queue); 857 762 i2c_set_clientdata(client, iio); 858 763 859 - ret = opt3001_read_id(opt); 860 - if (ret) 861 - return ret; 764 + if (opt->chip_info->has_id) { 765 + ret = opt3001_read_id(opt); 766 + if (ret) 767 + return ret; 768 + } 862 769 863 770 ret = opt3001_configure(opt); 864 771 if (ret) 865 772 return ret; 866 773 867 774 iio->name = client->name; 868 - iio->channels = opt3001_channels; 869 - iio->num_channels = ARRAY_SIZE(opt3001_channels); 775 + iio->channels = *opt->chip_info->channels; 776 + iio->num_channels = opt->chip_info->num_channels; 870 777 iio->modes = INDIO_DIRECT_MODE; 871 778 iio->info = &opt3001_info; 872 779 ··· 924 825 } 925 826 } 926 827 828 + static const struct opt3001_chip_info opt3001_chip_information = { 829 + .channels = &opt3001_channels, 830 + .chan_type = IIO_LIGHT, 831 + .num_channels = ARRAY_SIZE(opt3001_channels), 832 + .scales = &opt3001_scales, 833 + .factor_whole = 10, 834 + .factor_integer = 1000, 835 + .factor_decimal = 1000, 836 + .has_id = true, 837 + }; 838 + 839 + static const struct opt3001_chip_info opt3002_chip_information = { 840 + .channels = &opt3002_channels, 841 + .chan_type = IIO_INTENSITY, 842 + .num_channels = ARRAY_SIZE(opt3002_channels), 843 + .scales = &opt3002_scales, 844 + .factor_whole = 12, 845 + .factor_integer = 10, 846 + .factor_decimal = 100000, 847 + .has_id = false, 848 + }; 849 + 927 850 static const struct i2c_device_id opt3001_id[] = { 928 - { "opt3001" }, 851 + { "opt3001", (kernel_ulong_t)&opt3001_chip_information }, 852 + { "opt3002", (kernel_ulong_t)&opt3002_chip_information }, 929 853 { } /* Terminating Entry */ 930 854 }; 931 855 MODULE_DEVICE_TABLE(i2c, opt3001_id); 932 856 933 857 static const struct of_device_id opt3001_of_match[] = { 934 - { .compatible = "ti,opt3001" }, 858 + { .compatible = "ti,opt3001", .data = &opt3001_chip_information }, 859 + { .compatible = "ti,opt3002", .data = &opt3002_chip_information }, 935 860 { } 936 861 }; 937 862 MODULE_DEVICE_TABLE(of, opt3001_of_match);
+1 -4
drivers/iio/light/stk3310.c
··· 324 324 const struct iio_chan_spec *chan, 325 325 enum iio_event_type type, 326 326 enum iio_event_direction dir, 327 - int state) 327 + bool state) 328 328 { 329 329 int ret; 330 330 struct stk3310_data *data = iio_priv(indio_dev); 331 331 struct i2c_client *client = data->client; 332 - 333 - if (state < 0 || state > 7) 334 - return -EINVAL; 335 332 336 333 /* Set INT_PS value */ 337 334 mutex_lock(&data->lock);
+1 -1
drivers/iio/light/tcs3472.c
··· 327 327 328 328 static int tcs3472_write_event_config(struct iio_dev *indio_dev, 329 329 const struct iio_chan_spec *chan, enum iio_event_type type, 330 - enum iio_event_direction dir, int state) 330 + enum iio_event_direction dir, bool state) 331 331 { 332 332 struct tcs3472_data *data = iio_priv(indio_dev); 333 333 int ret = 0;
+1 -1
drivers/iio/light/tsl2563.c
··· 630 630 631 631 static int tsl2563_write_interrupt_config(struct iio_dev *indio_dev, 632 632 const struct iio_chan_spec *chan, enum iio_event_type type, 633 - enum iio_event_direction dir, int state) 633 + enum iio_event_direction dir, bool state) 634 634 { 635 635 struct tsl2563_chip *chip = iio_priv(indio_dev); 636 636 int ret = 0;
+1 -1
drivers/iio/light/tsl2591.c
··· 985 985 const struct iio_chan_spec *chan, 986 986 enum iio_event_type type, 987 987 enum iio_event_direction dir, 988 - int state) 988 + bool state) 989 989 { 990 990 struct tsl2591_chip *chip = iio_priv(indio_dev); 991 991 struct i2c_client *client = chip->client;
+3 -3
drivers/iio/light/tsl2772.c
··· 1081 1081 const struct iio_chan_spec *chan, 1082 1082 enum iio_event_type type, 1083 1083 enum iio_event_direction dir, 1084 - int val) 1084 + bool val) 1085 1085 { 1086 1086 struct tsl2772_chip *chip = iio_priv(indio_dev); 1087 1087 1088 1088 if (chan->type == IIO_INTENSITY) 1089 - chip->settings.als_interrupt_en = val ? true : false; 1089 + chip->settings.als_interrupt_en = val; 1090 1090 else 1091 - chip->settings.prox_interrupt_en = val ? true : false; 1091 + chip->settings.prox_interrupt_en = val; 1092 1092 1093 1093 return tsl2772_invoke_change(indio_dev); 1094 1094 }
+1 -1
drivers/iio/light/us5182d.c
··· 627 627 628 628 static int us5182d_write_event_config(struct iio_dev *indio_dev, 629 629 const struct iio_chan_spec *chan, enum iio_event_type type, 630 - enum iio_event_direction dir, int state) 630 + enum iio_event_direction dir, bool state) 631 631 { 632 632 struct us5182d_data *data = iio_priv(indio_dev); 633 633 int ret;
+3 -2
drivers/iio/light/vcnl4000.c
··· 1456 1456 const struct iio_chan_spec *chan, 1457 1457 enum iio_event_type type, 1458 1458 enum iio_event_direction dir, 1459 - int state) 1459 + bool state) 1460 1460 { 1461 1461 switch (chan->type) { 1462 1462 case IIO_PROXIMITY: ··· 1501 1501 static int vcnl4040_write_event_config(struct iio_dev *indio_dev, 1502 1502 const struct iio_chan_spec *chan, 1503 1503 enum iio_event_type type, 1504 - enum iio_event_direction dir, int state) 1504 + enum iio_event_direction dir, 1505 + bool state) 1505 1506 { 1506 1507 int ret = -EINVAL; 1507 1508 u16 val, mask;
+495
drivers/iio/light/veml3235.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * VEML3235 Ambient Light Sensor 4 + * 5 + * Copyright (c) 2024, Javier Carrasco <javier.carrasco.cruz@gmail.com> 6 + * 7 + * Datasheet: https://www.vishay.com/docs/80131/veml3235.pdf 8 + * Appnote-80222: https://www.vishay.com/docs/80222/designingveml3235.pdf 9 + */ 10 + 11 + #include <linux/err.h> 12 + #include <linux/i2c.h> 13 + #include <linux/iio/iio.h> 14 + #include <linux/module.h> 15 + #include <linux/pm_runtime.h> 16 + #include <linux/regmap.h> 17 + #include <linux/regulator/consumer.h> 18 + 19 + #define VEML3235_REG_CONF 0x00 20 + #define VEML3235_REG_WH_DATA 0x04 21 + #define VEML3235_REG_ALS_DATA 0x05 22 + #define VEML3235_REG_ID 0x09 23 + 24 + #define VEML3235_CONF_SD BIT(0) 25 + #define VEML3235_CONF_SD0 BIT(15) 26 + 27 + struct veml3235_rf { 28 + struct regmap_field *it; 29 + struct regmap_field *gain; 30 + struct regmap_field *id; 31 + }; 32 + 33 + struct veml3235_data { 34 + struct i2c_client *client; 35 + struct device *dev; 36 + struct regmap *regmap; 37 + struct veml3235_rf rf; 38 + }; 39 + 40 + static const int veml3235_it_times[][2] = { 41 + { 0, 50000 }, 42 + { 0, 100000 }, 43 + { 0, 200000 }, 44 + { 0, 400000 }, 45 + { 0, 800000 }, 46 + }; 47 + 48 + static const int veml3235_scale_vals[] = { 1, 2, 4, 8 }; 49 + 50 + static int veml3235_power_on(struct veml3235_data *data) 51 + { 52 + int ret; 53 + 54 + ret = regmap_clear_bits(data->regmap, VEML3235_REG_CONF, 55 + VEML3235_CONF_SD | VEML3235_CONF_SD0); 56 + if (ret) 57 + return ret; 58 + 59 + /* Wait 4 ms to let processor & oscillator start correctly */ 60 + fsleep(4000); 61 + 62 + return 0; 63 + } 64 + 65 + static int veml3235_shut_down(struct veml3235_data *data) 66 + { 67 + return regmap_set_bits(data->regmap, VEML3235_REG_CONF, 68 + VEML3235_CONF_SD | VEML3235_CONF_SD0); 69 + } 70 + 71 + static void veml3235_shut_down_action(void *data) 72 + { 73 + veml3235_shut_down(data); 74 + } 75 + 76 + enum veml3235_chan { 77 + CH_ALS, 78 + CH_WHITE, 79 + }; 80 + 81 + static const struct iio_chan_spec veml3235_channels[] = { 82 + { 83 + .type = IIO_LIGHT, 84 + .channel = CH_ALS, 85 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 86 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME) | 87 + BIT(IIO_CHAN_INFO_SCALE), 88 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 89 + BIT(IIO_CHAN_INFO_SCALE), 90 + }, 91 + { 92 + .type = IIO_INTENSITY, 93 + .channel = CH_WHITE, 94 + .modified = 1, 95 + .channel2 = IIO_MOD_LIGHT_BOTH, 96 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 97 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME) | 98 + BIT(IIO_CHAN_INFO_SCALE), 99 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 100 + BIT(IIO_CHAN_INFO_SCALE), 101 + }, 102 + }; 103 + 104 + static const struct regmap_config veml3235_regmap_config = { 105 + .name = "veml3235_regmap", 106 + .reg_bits = 8, 107 + .val_bits = 16, 108 + .max_register = VEML3235_REG_ID, 109 + .val_format_endian = REGMAP_ENDIAN_LITTLE, 110 + }; 111 + 112 + static int veml3235_get_it(struct veml3235_data *data, int *val, int *val2) 113 + { 114 + int ret, reg; 115 + 116 + ret = regmap_field_read(data->rf.it, &reg); 117 + if (ret) 118 + return ret; 119 + 120 + switch (reg) { 121 + case 0: 122 + *val2 = 50000; 123 + break; 124 + case 1: 125 + *val2 = 100000; 126 + break; 127 + case 2: 128 + *val2 = 200000; 129 + break; 130 + case 3: 131 + *val2 = 400000; 132 + break; 133 + case 4: 134 + *val2 = 800000; 135 + break; 136 + default: 137 + return -EINVAL; 138 + } 139 + 140 + *val = 0; 141 + 142 + return IIO_VAL_INT_PLUS_MICRO; 143 + } 144 + 145 + static int veml3235_set_it(struct iio_dev *indio_dev, int val, int val2) 146 + { 147 + struct veml3235_data *data = iio_priv(indio_dev); 148 + int ret, new_it; 149 + 150 + if (val) 151 + return -EINVAL; 152 + 153 + switch (val2) { 154 + case 50000: 155 + new_it = 0x00; 156 + break; 157 + case 100000: 158 + new_it = 0x01; 159 + break; 160 + case 200000: 161 + new_it = 0x02; 162 + break; 163 + case 400000: 164 + new_it = 0x03; 165 + break; 166 + case 800000: 167 + new_it = 0x04; 168 + break; 169 + default: 170 + return -EINVAL; 171 + } 172 + 173 + ret = regmap_field_write(data->rf.it, new_it); 174 + if (ret) { 175 + dev_err(data->dev, 176 + "failed to update integration time: %d\n", ret); 177 + return ret; 178 + } 179 + 180 + return 0; 181 + } 182 + 183 + static int veml3235_set_gain(struct iio_dev *indio_dev, int val, int val2) 184 + { 185 + struct veml3235_data *data = iio_priv(indio_dev); 186 + int ret, new_gain; 187 + 188 + if (val2 != 0) 189 + return -EINVAL; 190 + 191 + switch (val) { 192 + case 1: 193 + new_gain = 0x00; 194 + break; 195 + case 2: 196 + new_gain = 0x01; 197 + break; 198 + case 4: 199 + new_gain = 0x03; 200 + break; 201 + case 8: 202 + new_gain = 0x07; 203 + break; 204 + default: 205 + return -EINVAL; 206 + } 207 + 208 + ret = regmap_field_write(data->rf.gain, new_gain); 209 + if (ret) { 210 + dev_err(data->dev, "failed to set gain: %d\n", ret); 211 + return ret; 212 + } 213 + 214 + return 0; 215 + } 216 + 217 + static int veml3235_get_gain(struct veml3235_data *data, int *val) 218 + { 219 + int ret, reg; 220 + 221 + ret = regmap_field_read(data->rf.gain, &reg); 222 + if (ret) { 223 + dev_err(data->dev, "failed to read gain %d\n", ret); 224 + return ret; 225 + } 226 + 227 + switch (reg & 0x03) { 228 + case 0: 229 + *val = 1; 230 + break; 231 + case 1: 232 + *val = 2; 233 + break; 234 + case 3: 235 + *val = 4; 236 + break; 237 + default: 238 + return -EINVAL; 239 + } 240 + 241 + /* Double gain */ 242 + if (reg & 0x04) 243 + *val *= 2; 244 + 245 + return IIO_VAL_INT; 246 + } 247 + 248 + static int veml3235_read_raw(struct iio_dev *indio_dev, 249 + struct iio_chan_spec const *chan, int *val, 250 + int *val2, long mask) 251 + { 252 + struct veml3235_data *data = iio_priv(indio_dev); 253 + struct regmap *regmap = data->regmap; 254 + int ret, reg; 255 + 256 + switch (mask) { 257 + case IIO_CHAN_INFO_RAW: 258 + switch (chan->type) { 259 + case IIO_LIGHT: 260 + ret = regmap_read(regmap, VEML3235_REG_ALS_DATA, &reg); 261 + if (ret < 0) 262 + return ret; 263 + 264 + *val = reg; 265 + return IIO_VAL_INT; 266 + case IIO_INTENSITY: 267 + ret = regmap_read(regmap, VEML3235_REG_WH_DATA, &reg); 268 + if (ret < 0) 269 + return ret; 270 + 271 + *val = reg; 272 + return IIO_VAL_INT; 273 + default: 274 + return -EINVAL; 275 + } 276 + case IIO_CHAN_INFO_INT_TIME: 277 + return veml3235_get_it(data, val, val2); 278 + case IIO_CHAN_INFO_SCALE: 279 + return veml3235_get_gain(data, val); 280 + default: 281 + return -EINVAL; 282 + } 283 + } 284 + 285 + static int veml3235_read_avail(struct iio_dev *indio_dev, 286 + struct iio_chan_spec const *chan, 287 + const int **vals, int *type, int *length, 288 + long mask) 289 + { 290 + switch (mask) { 291 + case IIO_CHAN_INFO_INT_TIME: 292 + *vals = (int *)&veml3235_it_times; 293 + *length = 2 * ARRAY_SIZE(veml3235_it_times); 294 + *type = IIO_VAL_INT_PLUS_MICRO; 295 + return IIO_AVAIL_LIST; 296 + case IIO_CHAN_INFO_SCALE: 297 + *vals = (int *)&veml3235_scale_vals; 298 + *length = ARRAY_SIZE(veml3235_scale_vals); 299 + *type = IIO_VAL_INT; 300 + return IIO_AVAIL_LIST; 301 + default: 302 + return -EINVAL; 303 + } 304 + } 305 + 306 + static int veml3235_write_raw(struct iio_dev *indio_dev, 307 + struct iio_chan_spec const *chan, 308 + int val, int val2, long mask) 309 + { 310 + switch (mask) { 311 + case IIO_CHAN_INFO_INT_TIME: 312 + return veml3235_set_it(indio_dev, val, val2); 313 + case IIO_CHAN_INFO_SCALE: 314 + return veml3235_set_gain(indio_dev, val, val2); 315 + } 316 + 317 + return -EINVAL; 318 + } 319 + 320 + static void veml3235_read_id(struct veml3235_data *data) 321 + { 322 + int ret, reg; 323 + 324 + ret = regmap_field_read(data->rf.id, &reg); 325 + if (ret) { 326 + dev_info(data->dev, "failed to read ID\n"); 327 + return; 328 + } 329 + 330 + if (reg != 0x35) 331 + dev_info(data->dev, "Unknown ID %d\n", reg); 332 + } 333 + 334 + static const struct reg_field veml3235_rf_it = 335 + REG_FIELD(VEML3235_REG_CONF, 4, 6); 336 + 337 + static const struct reg_field veml3235_rf_gain = 338 + REG_FIELD(VEML3235_REG_CONF, 11, 13); 339 + 340 + static const struct reg_field veml3235_rf_id = 341 + REG_FIELD(VEML3235_REG_ID, 0, 7); 342 + 343 + static int veml3235_regfield_init(struct veml3235_data *data) 344 + { 345 + struct regmap *regmap = data->regmap; 346 + struct device *dev = data->dev; 347 + struct regmap_field *rm_field; 348 + struct veml3235_rf *rf = &data->rf; 349 + 350 + rm_field = devm_regmap_field_alloc(dev, regmap, veml3235_rf_it); 351 + if (IS_ERR(rm_field)) 352 + return PTR_ERR(rm_field); 353 + rf->it = rm_field; 354 + 355 + rm_field = devm_regmap_field_alloc(dev, regmap, veml3235_rf_gain); 356 + if (IS_ERR(rm_field)) 357 + return PTR_ERR(rm_field); 358 + rf->gain = rm_field; 359 + 360 + rm_field = devm_regmap_field_alloc(dev, regmap, veml3235_rf_id); 361 + if (IS_ERR(rm_field)) 362 + return PTR_ERR(rm_field); 363 + rf->id = rm_field; 364 + 365 + return 0; 366 + } 367 + 368 + static int veml3235_hw_init(struct iio_dev *indio_dev) 369 + { 370 + struct veml3235_data *data = iio_priv(indio_dev); 371 + struct device *dev = data->dev; 372 + int ret; 373 + 374 + /* Set gain to 1 and integration time to 100 ms */ 375 + ret = regmap_field_write(data->rf.gain, 0x00); 376 + if (ret) 377 + return dev_err_probe(data->dev, ret, "failed to set gain\n"); 378 + 379 + ret = regmap_field_write(data->rf.it, 0x01); 380 + if (ret) 381 + return dev_err_probe(data->dev, ret, 382 + "failed to set integration time\n"); 383 + 384 + ret = veml3235_power_on(data); 385 + if (ret) 386 + return dev_err_probe(dev, ret, "failed to power on\n"); 387 + 388 + return devm_add_action_or_reset(dev, veml3235_shut_down_action, data); 389 + } 390 + 391 + static const struct iio_info veml3235_info = { 392 + .read_raw = veml3235_read_raw, 393 + .read_avail = veml3235_read_avail, 394 + .write_raw = veml3235_write_raw, 395 + }; 396 + 397 + static int veml3235_probe(struct i2c_client *client) 398 + { 399 + struct device *dev = &client->dev; 400 + struct veml3235_data *data; 401 + struct iio_dev *indio_dev; 402 + struct regmap *regmap; 403 + int ret; 404 + 405 + regmap = devm_regmap_init_i2c(client, &veml3235_regmap_config); 406 + if (IS_ERR(regmap)) 407 + return dev_err_probe(dev, PTR_ERR(regmap), 408 + "failed to setup regmap\n"); 409 + 410 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 411 + if (!indio_dev) 412 + return -ENOMEM; 413 + 414 + data = iio_priv(indio_dev); 415 + i2c_set_clientdata(client, indio_dev); 416 + data->client = client; 417 + data->dev = dev; 418 + data->regmap = regmap; 419 + 420 + ret = veml3235_regfield_init(data); 421 + if (ret) 422 + return dev_err_probe(dev, ret, "failed to init regfield\n"); 423 + 424 + ret = devm_regulator_get_enable(dev, "vdd"); 425 + if (ret) 426 + return dev_err_probe(dev, ret, "failed to enable regulator\n"); 427 + 428 + indio_dev->name = "veml3235"; 429 + indio_dev->channels = veml3235_channels; 430 + indio_dev->num_channels = ARRAY_SIZE(veml3235_channels); 431 + indio_dev->modes = INDIO_DIRECT_MODE; 432 + indio_dev->info = &veml3235_info; 433 + 434 + veml3235_read_id(data); 435 + 436 + ret = veml3235_hw_init(indio_dev); 437 + if (ret < 0) 438 + return ret; 439 + 440 + return devm_iio_device_register(dev, indio_dev); 441 + } 442 + 443 + static int veml3235_runtime_suspend(struct device *dev) 444 + { 445 + struct veml3235_data *data = iio_priv(dev_get_drvdata(dev)); 446 + int ret; 447 + 448 + ret = veml3235_shut_down(data); 449 + if (ret < 0) 450 + dev_err(data->dev, "failed to suspend: %d\n", ret); 451 + 452 + return ret; 453 + } 454 + 455 + static int veml3235_runtime_resume(struct device *dev) 456 + { 457 + struct veml3235_data *data = iio_priv(dev_get_drvdata(dev)); 458 + int ret; 459 + 460 + ret = veml3235_power_on(data); 461 + if (ret < 0) 462 + dev_err(data->dev, "failed to resume: %d\n", ret); 463 + 464 + return ret; 465 + } 466 + 467 + static DEFINE_RUNTIME_DEV_PM_OPS(veml3235_pm_ops, veml3235_runtime_suspend, 468 + veml3235_runtime_resume, NULL); 469 + 470 + static const struct of_device_id veml3235_of_match[] = { 471 + { .compatible = "vishay,veml3235" }, 472 + { } 473 + }; 474 + MODULE_DEVICE_TABLE(of, veml3235_of_match); 475 + 476 + static const struct i2c_device_id veml3235_id[] = { 477 + { "veml3235" }, 478 + { } 479 + }; 480 + MODULE_DEVICE_TABLE(i2c, veml3235_id); 481 + 482 + static struct i2c_driver veml3235_driver = { 483 + .driver = { 484 + .name = "veml3235", 485 + .of_match_table = veml3235_of_match, 486 + .pm = pm_ptr(&veml3235_pm_ops), 487 + }, 488 + .probe = veml3235_probe, 489 + .id_table = veml3235_id, 490 + }; 491 + module_i2c_driver(veml3235_driver); 492 + 493 + MODULE_AUTHOR("Javier Carrasco <javier.carrasco.cruz@gmail.com>"); 494 + MODULE_DESCRIPTION("VEML3235 Ambient Light Sensor"); 495 + MODULE_LICENSE("GPL");
+1 -4
drivers/iio/light/veml6030.c
··· 821 821 */ 822 822 static int veml6030_write_interrupt_config(struct iio_dev *indio_dev, 823 823 const struct iio_chan_spec *chan, enum iio_event_type type, 824 - enum iio_event_direction dir, int state) 824 + enum iio_event_direction dir, bool state) 825 825 { 826 826 int ret; 827 827 struct veml6030_data *data = iio_priv(indio_dev); 828 - 829 - if (state < 0 || state > 1) 830 - return -EINVAL; 831 828 832 829 ret = veml6030_als_shut_down(data); 833 830 if (ret < 0) {
+127 -11
drivers/iio/light/veml6070.c
··· 6 6 * 7 7 * IIO driver for VEML6070 (7-bit I2C slave addresses 0x38 and 0x39) 8 8 * 9 - * TODO: integration time, ACK signal 9 + * TODO: ACK signal 10 10 */ 11 11 12 + #include <linux/bitfield.h> 12 13 #include <linux/module.h> 13 14 #include <linux/i2c.h> 14 15 #include <linux/mutex.h> 15 16 #include <linux/err.h> 16 17 #include <linux/delay.h> 18 + #include <linux/units.h> 17 19 18 20 #include <linux/iio/iio.h> 19 21 #include <linux/iio/sysfs.h> ··· 30 28 #define VEML6070_COMMAND_RSRVD BIT(1) /* reserved, set to 1 */ 31 29 #define VEML6070_COMMAND_SD BIT(0) /* shutdown mode when set */ 32 30 33 - #define VEML6070_IT_10 0x04 /* integration time 1x */ 31 + #define VEML6070_IT_05 0x00 32 + #define VEML6070_IT_10 0x01 33 + #define VEML6070_IT_20 0x02 34 + #define VEML6070_IT_40 0x03 35 + 36 + #define VEML6070_MIN_RSET_KOHM 75 37 + #define VEML6070_MIN_IT_US 15625 /* Rset = 75 kohm, IT = 1/2 */ 34 38 35 39 struct veml6070_data { 36 40 struct i2c_client *client1; 37 41 struct i2c_client *client2; 38 42 u8 config; 39 43 struct mutex lock; 44 + u32 rset; 45 + int it[4][2]; 40 46 }; 47 + 48 + static int veml6070_calc_it(struct device *dev, struct veml6070_data *data) 49 + { 50 + int i, tmp_it; 51 + 52 + data->rset = 270000; 53 + device_property_read_u32(dev, "vishay,rset-ohms", &data->rset); 54 + 55 + if (data->rset < 75000 || data->rset > 1200000) 56 + return dev_err_probe(dev, -EINVAL, "Rset out of range\n"); 57 + 58 + /* 59 + * convert to kohm to avoid overflows and work with the same units as 60 + * in the datasheet and simplify UVI operations. 61 + */ 62 + data->rset /= KILO; 63 + 64 + tmp_it = VEML6070_MIN_IT_US * data->rset / VEML6070_MIN_RSET_KOHM; 65 + for (i = 0; i < ARRAY_SIZE(data->it); i++) { 66 + data->it[i][0] = (tmp_it << i) / MICRO; 67 + data->it[i][1] = (tmp_it << i) % MICRO; 68 + } 69 + 70 + return 0; 71 + } 72 + 73 + static int veml6070_get_it(struct veml6070_data *data, int *val, int *val2) 74 + { 75 + int it_idx = FIELD_GET(VEML6070_COMMAND_IT, data->config); 76 + 77 + *val = data->it[it_idx][0]; 78 + *val2 = data->it[it_idx][1]; 79 + 80 + return IIO_VAL_INT_PLUS_MICRO; 81 + } 82 + 83 + static int veml6070_set_it(struct veml6070_data *data, int val, int val2) 84 + { 85 + int it_idx; 86 + 87 + for (it_idx = 0; it_idx < ARRAY_SIZE(data->it); it_idx++) { 88 + if (data->it[it_idx][0] == val && data->it[it_idx][1] == val2) 89 + break; 90 + } 91 + 92 + if (it_idx >= ARRAY_SIZE(data->it)) 93 + return -EINVAL; 94 + 95 + data->config = (data->config & ~VEML6070_COMMAND_IT) | 96 + FIELD_PREP(VEML6070_COMMAND_IT, it_idx); 97 + 98 + return i2c_smbus_write_byte(data->client1, data->config); 99 + } 41 100 42 101 static int veml6070_read(struct veml6070_data *data) 43 102 { 44 - int ret; 103 + int ret, it_ms, val, val2; 45 104 u8 msb, lsb; 46 105 47 106 guard(mutex)(&data->lock); ··· 113 50 if (ret < 0) 114 51 return ret; 115 52 116 - msleep(125 + 10); /* measurement takes up to 125 ms for IT 1x */ 53 + veml6070_get_it(data, &val, &val2); 54 + it_ms = val * MILLI + val2 / (MICRO / MILLI); 55 + msleep(it_ms + 10); 117 56 118 57 ret = i2c_smbus_read_byte(data->client2); /* read MSB, address 0x39 */ 119 58 if (ret < 0) ··· 145 80 .modified = 1, 146 81 .channel2 = IIO_MOD_LIGHT_UV, 147 82 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 83 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), 84 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME), 148 85 }, 149 86 { 150 87 .type = IIO_UVINDEX, 151 88 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 89 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), 90 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME), 152 91 } 153 92 }; 154 93 155 - static int veml6070_to_uv_index(unsigned val) 94 + static int veml6070_to_uv_index(struct veml6070_data *data, unsigned int val) 156 95 { 157 96 /* 158 97 * conversion of raw UV intensity values to UV index depends on 159 98 * integration time (IT) and value of the resistor connected to 160 - * the RSET pin (default: 270 KOhm) 99 + * the RSET pin. 161 100 */ 162 - unsigned uvi[11] = { 101 + unsigned int uvi[11] = { 163 102 187, 373, 560, /* low */ 164 103 746, 933, 1120, /* moderate */ 165 104 1308, 1494, /* high */ 166 105 1681, 1868, 2054}; /* very high */ 167 - int i; 106 + int i, it_idx; 107 + 108 + it_idx = FIELD_GET(VEML6070_COMMAND_IT, data->config); 109 + 110 + if (!it_idx) 111 + val = (val * 270 / data->rset) << 1; 112 + else 113 + val = (val * 270 / data->rset) >> (it_idx - 1); 168 114 169 115 for (i = 0; i < ARRAY_SIZE(uvi); i++) 170 116 if (val <= uvi[i]) ··· 198 122 if (ret < 0) 199 123 return ret; 200 124 if (mask == IIO_CHAN_INFO_PROCESSED) 201 - *val = veml6070_to_uv_index(ret); 125 + *val = veml6070_to_uv_index(data, ret); 202 126 else 203 127 *val = ret; 204 128 return IIO_VAL_INT; 129 + case IIO_CHAN_INFO_INT_TIME: 130 + return veml6070_get_it(data, val, val2); 131 + default: 132 + return -EINVAL; 133 + } 134 + } 135 + 136 + static int veml6070_read_avail(struct iio_dev *indio_dev, 137 + struct iio_chan_spec const *chan, 138 + const int **vals, int *type, int *length, 139 + long mask) 140 + { 141 + struct veml6070_data *data = iio_priv(indio_dev); 142 + 143 + switch (mask) { 144 + case IIO_CHAN_INFO_INT_TIME: 145 + *vals = (int *)data->it; 146 + *length = 2 * ARRAY_SIZE(data->it); 147 + *type = IIO_VAL_INT_PLUS_MICRO; 148 + return IIO_AVAIL_LIST; 149 + default: 150 + return -EINVAL; 151 + } 152 + } 153 + 154 + static int veml6070_write_raw(struct iio_dev *indio_dev, 155 + struct iio_chan_spec const *chan, 156 + int val, int val2, long mask) 157 + { 158 + struct veml6070_data *data = iio_priv(indio_dev); 159 + 160 + switch (mask) { 161 + case IIO_CHAN_INFO_INT_TIME: 162 + return veml6070_set_it(data, val, val2); 205 163 default: 206 164 return -EINVAL; 207 165 } ··· 243 133 244 134 static const struct iio_info veml6070_info = { 245 135 .read_raw = veml6070_read_raw, 136 + .read_avail = veml6070_read_avail, 137 + .write_raw = veml6070_write_raw, 246 138 }; 247 139 248 140 static void veml6070_i2c_unreg(void *p) ··· 275 163 indio_dev->name = VEML6070_DRV_NAME; 276 164 indio_dev->modes = INDIO_DIRECT_MODE; 277 165 166 + ret = veml6070_calc_it(&client->dev, data); 167 + if (ret < 0) 168 + return ret; 169 + 278 170 ret = devm_regulator_get_enable(&client->dev, "vdd"); 279 171 if (ret < 0) 280 172 return ret; ··· 288 172 return dev_err_probe(&client->dev, PTR_ERR(data->client2), 289 173 "i2c device for second chip address failed\n"); 290 174 291 - data->config = VEML6070_IT_10 | VEML6070_COMMAND_RSRVD | 292 - VEML6070_COMMAND_SD; 175 + data->config = FIELD_PREP(VEML6070_COMMAND_IT, VEML6070_IT_10) | 176 + VEML6070_COMMAND_RSRVD | VEML6070_COMMAND_SD; 293 177 ret = i2c_smbus_write_byte(data->client1, data->config); 294 178 if (ret < 0) 295 179 return ret;
+13
drivers/iio/magnetometer/Kconfig
··· 54 54 help 55 55 Deprecated: AK09911 is now supported by AK8975 driver. 56 56 57 + config ALS31300 58 + tristate "Allegro MicroSystems ALS31300 3-D Linear Hall Effect Sensor" 59 + depends on I2C 60 + select REGMAP_I2C 61 + select IIO_BUFFER 62 + select IIO_TRIGGERED_BUFFER 63 + help 64 + Say yes here to build support for the Allegro MicroSystems 65 + ALS31300 Hall Effect Sensor through its I2C interface. 66 + 67 + To compile this driver as a module, choose M here: the 68 + module will be called als31300. 69 + 57 70 config BMC150_MAGN 58 71 tristate 59 72 select IIO_BUFFER
+1
drivers/iio/magnetometer/Makefile
··· 7 7 obj-$(CONFIG_AF8133J) += af8133j.o 8 8 obj-$(CONFIG_AK8974) += ak8974.o 9 9 obj-$(CONFIG_AK8975) += ak8975.o 10 + obj-$(CONFIG_ALS31300) += als31300.o 10 11 obj-$(CONFIG_BMC150_MAGN) += bmc150_magn.o 11 12 obj-$(CONFIG_BMC150_MAGN_I2C) += bmc150_magn_i2c.o 12 13 obj-$(CONFIG_BMC150_MAGN_SPI) += bmc150_magn_spi.o
+494
drivers/iio/magnetometer/als31300.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Driver for the Allegro MicroSystems ALS31300 3-D Linear Hall Effect Sensor 4 + * 5 + * Copyright (c) 2024 Linaro Limited 6 + */ 7 + 8 + #include <linux/bits.h> 9 + #include <linux/bitfield.h> 10 + #include <linux/delay.h> 11 + #include <linux/module.h> 12 + #include <linux/i2c.h> 13 + #include <linux/regmap.h> 14 + #include <linux/pm.h> 15 + #include <linux/pm_runtime.h> 16 + #include <linux/regulator/consumer.h> 17 + #include <linux/types.h> 18 + #include <linux/units.h> 19 + 20 + #include <linux/iio/buffer.h> 21 + #include <linux/iio/iio.h> 22 + #include <linux/iio/trigger_consumer.h> 23 + #include <linux/iio/triggered_buffer.h> 24 + 25 + /* 26 + * The Allegro MicroSystems ALS31300 has an EEPROM space to configure how 27 + * the device works and how the interrupt line behaves. 28 + * Only the default setup with external trigger is supported. 29 + * 30 + * While the bindings supports declaring an interrupt line, those 31 + * events are not supported. 32 + * 33 + * It should be possible to adapt the driver to the current 34 + * device EEPROM setup at runtime. 35 + */ 36 + 37 + #define ALS31300_EEPROM_CONFIG 0x02 38 + #define ALS31300_EEPROM_INTERRUPT 0x03 39 + #define ALS31300_EEPROM_CUSTOMER_1 0x0d 40 + #define ALS31300_EEPROM_CUSTOMER_2 0x0e 41 + #define ALS31300_EEPROM_CUSTOMER_3 0x0f 42 + #define ALS31300_VOL_MODE 0x27 43 + #define ALS31300_VOL_MODE_LPDCM GENMASK(6, 4) 44 + #define ALS31300_LPDCM_INACTIVE_0_5_MS 0 45 + #define ALS31300_LPDCM_INACTIVE_1_0_MS 1 46 + #define ALS31300_LPDCM_INACTIVE_5_0_MS 2 47 + #define ALS31300_LPDCM_INACTIVE_10_0_MS 3 48 + #define ALS31300_LPDCM_INACTIVE_50_0_MS 4 49 + #define ALS31300_LPDCM_INACTIVE_100_0_MS 5 50 + #define ALS31300_LPDCM_INACTIVE_500_0_MS 6 51 + #define ALS31300_LPDCM_INACTIVE_1000_0_MS 7 52 + #define ALS31300_VOL_MODE_SLEEP GENMASK(1, 0) 53 + #define ALS31300_VOL_MODE_ACTIVE_MODE 0 54 + #define ALS31300_VOL_MODE_SLEEP_MODE 1 55 + #define ALS31300_VOL_MODE_LPDCM_MODE 2 56 + #define ALS31300_VOL_MSB 0x28 57 + #define ALS31300_VOL_MSB_TEMPERATURE GENMASK(5, 0) 58 + #define ALS31300_VOL_MSB_INTERRUPT BIT(6) 59 + #define ALS31300_VOL_MSB_NEW_DATA BIT(7) 60 + #define ALS31300_VOL_MSB_Z_AXIS GENMASK(15, 8) 61 + #define ALS31300_VOL_MSB_Y_AXIS GENMASK(23, 16) 62 + #define ALS31300_VOL_MSB_X_AXIS GENMASK(31, 24) 63 + #define ALS31300_VOL_LSB 0x29 64 + #define ALS31300_VOL_LSB_TEMPERATURE GENMASK(5, 0) 65 + #define ALS31300_VOL_LSB_HALL_STATUS GENMASK(7, 7) 66 + #define ALS31300_VOL_LSB_Z_AXIS GENMASK(11, 8) 67 + #define ALS31300_VOL_LSB_Y_AXIS GENMASK(15, 12) 68 + #define ALS31300_VOL_LSB_X_AXIS GENMASK(19, 16) 69 + #define ALS31300_VOL_LSB_INTERRUPT_WRITE BIT(20) 70 + #define ALS31300_CUSTOMER_ACCESS 0x35 71 + 72 + #define ALS31300_DATA_X_GET(b) \ 73 + sign_extend32(FIELD_GET(ALS31300_VOL_MSB_X_AXIS, b[0]) << 4 | \ 74 + FIELD_GET(ALS31300_VOL_LSB_X_AXIS, b[1]), 11) 75 + #define ALS31300_DATA_Y_GET(b) \ 76 + sign_extend32(FIELD_GET(ALS31300_VOL_MSB_Y_AXIS, b[0]) << 4 | \ 77 + FIELD_GET(ALS31300_VOL_LSB_Y_AXIS, b[1]), 11) 78 + #define ALS31300_DATA_Z_GET(b) \ 79 + sign_extend32(FIELD_GET(ALS31300_VOL_MSB_Z_AXIS, b[0]) << 4 | \ 80 + FIELD_GET(ALS31300_VOL_LSB_Z_AXIS, b[1]), 11) 81 + #define ALS31300_TEMPERATURE_GET(b) \ 82 + (FIELD_GET(ALS31300_VOL_MSB_TEMPERATURE, b[0]) << 6 | \ 83 + FIELD_GET(ALS31300_VOL_LSB_TEMPERATURE, b[1])) 84 + 85 + enum als31300_channels { 86 + TEMPERATURE = 0, 87 + AXIS_X, 88 + AXIS_Y, 89 + AXIS_Z, 90 + }; 91 + 92 + struct als31300_variant_info { 93 + u8 sensitivity; 94 + }; 95 + 96 + struct als31300_data { 97 + struct device *dev; 98 + /* protects power on/off the device and access HW */ 99 + struct mutex mutex; 100 + const struct als31300_variant_info *variant_info; 101 + struct regmap *map; 102 + }; 103 + 104 + /* The whole measure is split into 2x32-bit registers, we need to read them both at once */ 105 + static int als31300_get_measure(struct als31300_data *data, 106 + u16 *t, s16 *x, s16 *y, s16 *z) 107 + { 108 + u32 buf[2]; 109 + int ret, err; 110 + 111 + guard(mutex)(&data->mutex); 112 + 113 + ret = pm_runtime_resume_and_get(data->dev); 114 + if (ret) 115 + return ret; 116 + 117 + /* 118 + * Loop until data is valid, new data should have the 119 + * ALS31300_VOL_MSB_NEW_DATA bit set to 1. 120 + * Max update rate is 2KHz, wait up to 1ms. 121 + */ 122 + ret = read_poll_timeout(regmap_bulk_read, err, 123 + err || FIELD_GET(ALS31300_VOL_MSB_NEW_DATA, buf[0]), 124 + 20, USEC_PER_MSEC, false, 125 + data->map, ALS31300_VOL_MSB, buf, ARRAY_SIZE(buf)); 126 + /* Bail out on read_poll_timeout() error */ 127 + if (ret) 128 + goto out; 129 + 130 + /* Bail out on regmap_bulk_read() error */ 131 + if (err) { 132 + dev_err(data->dev, "read data failed, error %d\n", ret); 133 + ret = err; 134 + goto out; 135 + } 136 + 137 + *t = ALS31300_TEMPERATURE_GET(buf); 138 + *x = ALS31300_DATA_X_GET(buf); 139 + *y = ALS31300_DATA_Y_GET(buf); 140 + *z = ALS31300_DATA_Z_GET(buf); 141 + 142 + out: 143 + pm_runtime_mark_last_busy(data->dev); 144 + pm_runtime_put_autosuspend(data->dev); 145 + 146 + return ret; 147 + } 148 + 149 + static int als31300_read_raw(struct iio_dev *indio_dev, 150 + const struct iio_chan_spec *chan, int *val, 151 + int *val2, long mask) 152 + { 153 + struct als31300_data *data = iio_priv(indio_dev); 154 + s16 x, y, z; 155 + u16 t; 156 + int ret; 157 + 158 + switch (mask) { 159 + case IIO_CHAN_INFO_PROCESSED: 160 + case IIO_CHAN_INFO_RAW: 161 + ret = als31300_get_measure(data, &t, &x, &y, &z); 162 + if (ret) 163 + return ret; 164 + 165 + switch (chan->address) { 166 + case TEMPERATURE: 167 + *val = t; 168 + return IIO_VAL_INT; 169 + case AXIS_X: 170 + *val = x; 171 + return IIO_VAL_INT; 172 + case AXIS_Y: 173 + *val = y; 174 + return IIO_VAL_INT; 175 + case AXIS_Z: 176 + *val = z; 177 + return IIO_VAL_INT; 178 + default: 179 + return -EINVAL; 180 + } 181 + case IIO_CHAN_INFO_SCALE: 182 + switch (chan->type) { 183 + case IIO_TEMP: 184 + /* 185 + * Fractional part of: 186 + * 1000 * 302 * (value - 1708) 187 + * temp = ---------------------------- 188 + * 4096 189 + * to convert temperature in millicelcius. 190 + */ 191 + *val = MILLI * 302; 192 + *val2 = 4096; 193 + return IIO_VAL_FRACTIONAL; 194 + case IIO_MAGN: 195 + /* 196 + * Devices are configured in factory 197 + * with different sensitivities: 198 + * - 500 GAUSS <-> 4 LSB/Gauss 199 + * - 1000 GAUSS <-> 2 LSB/Gauss 200 + * - 2000 GAUSS <-> 1 LSB/Gauss 201 + * with translates by a division of the returned 202 + * value to get Gauss value. 203 + * The sensitivity cannot be read at runtime 204 + * so the value depends on the model compatible 205 + * or device id. 206 + */ 207 + *val = 1; 208 + *val2 = data->variant_info->sensitivity; 209 + return IIO_VAL_FRACTIONAL; 210 + default: 211 + return -EINVAL; 212 + } 213 + case IIO_CHAN_INFO_OFFSET: 214 + switch (chan->type) { 215 + case IIO_TEMP: 216 + *val = -1708; 217 + return IIO_VAL_INT; 218 + default: 219 + return -EINVAL; 220 + } 221 + default: 222 + return -EINVAL; 223 + } 224 + } 225 + 226 + static irqreturn_t als31300_trigger_handler(int irq, void *p) 227 + { 228 + struct iio_poll_func *pf = p; 229 + struct iio_dev *indio_dev = pf->indio_dev; 230 + struct als31300_data *data = iio_priv(indio_dev); 231 + struct { 232 + u16 temperature; 233 + s16 channels[3]; 234 + aligned_s64 timestamp; 235 + } scan; 236 + s16 x, y, z; 237 + int ret; 238 + u16 t; 239 + 240 + ret = als31300_get_measure(data, &t, &x, &y, &z); 241 + if (ret) 242 + goto trigger_out; 243 + 244 + scan.temperature = t; 245 + scan.channels[0] = x; 246 + scan.channels[1] = y; 247 + scan.channels[2] = z; 248 + iio_push_to_buffers_with_timestamp(indio_dev, &scan, 249 + pf->timestamp); 250 + 251 + trigger_out: 252 + iio_trigger_notify_done(indio_dev->trig); 253 + 254 + return IRQ_HANDLED; 255 + } 256 + 257 + #define ALS31300_AXIS_CHANNEL(axis, index) \ 258 + { \ 259 + .type = IIO_MAGN, \ 260 + .modified = 1, \ 261 + .channel2 = IIO_MOD_##axis, \ 262 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 263 + BIT(IIO_CHAN_INFO_SCALE), \ 264 + .address = index, \ 265 + .scan_index = index, \ 266 + .scan_type = { \ 267 + .sign = 's', \ 268 + .realbits = 12, \ 269 + .storagebits = 16, \ 270 + .endianness = IIO_CPU, \ 271 + }, \ 272 + } 273 + 274 + static const struct iio_chan_spec als31300_channels[] = { 275 + { 276 + .type = IIO_TEMP, 277 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 278 + BIT(IIO_CHAN_INFO_SCALE) | 279 + BIT(IIO_CHAN_INFO_OFFSET), 280 + .address = TEMPERATURE, 281 + .scan_index = TEMPERATURE, 282 + .scan_type = { 283 + .sign = 'u', 284 + .realbits = 16, 285 + .storagebits = 16, 286 + .endianness = IIO_CPU, 287 + }, 288 + }, 289 + ALS31300_AXIS_CHANNEL(X, AXIS_X), 290 + ALS31300_AXIS_CHANNEL(Y, AXIS_Y), 291 + ALS31300_AXIS_CHANNEL(Z, AXIS_Z), 292 + IIO_CHAN_SOFT_TIMESTAMP(4), 293 + }; 294 + 295 + static const struct iio_info als31300_info = { 296 + .read_raw = als31300_read_raw, 297 + }; 298 + 299 + static int als31300_set_operating_mode(struct als31300_data *data, 300 + unsigned int val) 301 + { 302 + int ret; 303 + 304 + ret = regmap_update_bits(data->map, ALS31300_VOL_MODE, 305 + ALS31300_VOL_MODE_SLEEP, val); 306 + if (ret) { 307 + dev_err(data->dev, "failed to set operating mode (%pe)\n", ERR_PTR(ret)); 308 + return ret; 309 + } 310 + 311 + /* The time it takes to exit sleep mode is equivalent to Power-On Delay Time */ 312 + if (val == ALS31300_VOL_MODE_ACTIVE_MODE) 313 + fsleep(600); 314 + 315 + return 0; 316 + } 317 + 318 + static void als31300_power_down(void *data) 319 + { 320 + als31300_set_operating_mode(data, ALS31300_VOL_MODE_SLEEP_MODE); 321 + } 322 + 323 + static const struct iio_buffer_setup_ops als31300_setup_ops = {}; 324 + 325 + static const unsigned long als31300_scan_masks[] = { GENMASK(3, 0), 0 }; 326 + 327 + static bool als31300_volatile_reg(struct device *dev, unsigned int reg) 328 + { 329 + return reg == ALS31300_VOL_MSB || reg == ALS31300_VOL_LSB; 330 + } 331 + 332 + static const struct regmap_config als31300_regmap_config = { 333 + .reg_bits = 8, 334 + .val_bits = 32, 335 + .max_register = ALS31300_CUSTOMER_ACCESS, 336 + .volatile_reg = als31300_volatile_reg, 337 + }; 338 + 339 + static int als31300_probe(struct i2c_client *i2c) 340 + { 341 + struct device *dev = &i2c->dev; 342 + struct als31300_data *data; 343 + struct iio_dev *indio_dev; 344 + int ret; 345 + 346 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 347 + if (!indio_dev) 348 + return -ENOMEM; 349 + 350 + data = iio_priv(indio_dev); 351 + data->dev = dev; 352 + i2c_set_clientdata(i2c, indio_dev); 353 + 354 + ret = devm_mutex_init(dev, &data->mutex); 355 + if (ret) 356 + return ret; 357 + 358 + data->variant_info = i2c_get_match_data(i2c); 359 + if (!data->variant_info) 360 + return -EINVAL; 361 + 362 + data->map = devm_regmap_init_i2c(i2c, &als31300_regmap_config); 363 + if (IS_ERR(data->map)) 364 + return dev_err_probe(dev, PTR_ERR(data->map), 365 + "failed to allocate register map\n"); 366 + 367 + ret = devm_regulator_get_enable(dev, "vcc"); 368 + if (ret) 369 + return dev_err_probe(dev, ret, "failed to enable regulator\n"); 370 + 371 + ret = als31300_set_operating_mode(data, ALS31300_VOL_MODE_ACTIVE_MODE); 372 + if (ret) 373 + return dev_err_probe(dev, ret, "failed to power on device\n"); 374 + 375 + ret = devm_add_action_or_reset(dev, als31300_power_down, data); 376 + if (ret) 377 + return dev_err_probe(dev, ret, "failed to add powerdown action\n"); 378 + 379 + indio_dev->info = &als31300_info; 380 + indio_dev->modes = INDIO_DIRECT_MODE; 381 + indio_dev->name = i2c->name; 382 + indio_dev->channels = als31300_channels; 383 + indio_dev->num_channels = ARRAY_SIZE(als31300_channels); 384 + indio_dev->available_scan_masks = als31300_scan_masks; 385 + 386 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 387 + iio_pollfunc_store_time, 388 + als31300_trigger_handler, 389 + &als31300_setup_ops); 390 + if (ret < 0) 391 + return dev_err_probe(dev, ret, "iio triggered buffer setup failed\n"); 392 + 393 + ret = pm_runtime_set_active(dev); 394 + if (ret < 0) 395 + return ret; 396 + 397 + ret = devm_pm_runtime_enable(dev); 398 + if (ret) 399 + return ret; 400 + 401 + pm_runtime_get_noresume(dev); 402 + pm_runtime_set_autosuspend_delay(dev, 200); 403 + pm_runtime_use_autosuspend(dev); 404 + 405 + pm_runtime_mark_last_busy(dev); 406 + pm_runtime_put_autosuspend(dev); 407 + 408 + ret = devm_iio_device_register(dev, indio_dev); 409 + if (ret) 410 + return dev_err_probe(dev, ret, "device register failed\n"); 411 + 412 + return 0; 413 + } 414 + 415 + static int als31300_runtime_suspend(struct device *dev) 416 + { 417 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 418 + struct als31300_data *data = iio_priv(indio_dev); 419 + 420 + return als31300_set_operating_mode(data, ALS31300_VOL_MODE_SLEEP_MODE); 421 + } 422 + 423 + static int als31300_runtime_resume(struct device *dev) 424 + { 425 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 426 + struct als31300_data *data = iio_priv(indio_dev); 427 + 428 + return als31300_set_operating_mode(data, ALS31300_VOL_MODE_ACTIVE_MODE); 429 + } 430 + 431 + static DEFINE_RUNTIME_DEV_PM_OPS(als31300_pm_ops, 432 + als31300_runtime_suspend, als31300_runtime_resume, 433 + NULL); 434 + 435 + static const struct als31300_variant_info al31300_variant_500 = { 436 + .sensitivity = 4, 437 + }; 438 + 439 + static const struct als31300_variant_info al31300_variant_1000 = { 440 + .sensitivity = 2, 441 + }; 442 + 443 + static const struct als31300_variant_info al31300_variant_2000 = { 444 + .sensitivity = 1, 445 + }; 446 + 447 + static const struct i2c_device_id als31300_id[] = { 448 + { 449 + .name = "als31300-500", 450 + .driver_data = (kernel_ulong_t)&al31300_variant_500, 451 + }, 452 + { 453 + .name = "als31300-1000", 454 + .driver_data = (kernel_ulong_t)&al31300_variant_1000, 455 + }, 456 + { 457 + .name = "als31300-2000", 458 + .driver_data = (kernel_ulong_t)&al31300_variant_2000, 459 + }, 460 + { /* sentinel */ } 461 + }; 462 + MODULE_DEVICE_TABLE(i2c, als31300_id); 463 + 464 + static const struct of_device_id als31300_of_match[] = { 465 + { 466 + .compatible = "allegromicro,als31300-500", 467 + .data = &al31300_variant_500, 468 + }, 469 + { 470 + .compatible = "allegromicro,als31300-1000", 471 + .data = &al31300_variant_1000, 472 + }, 473 + { 474 + .compatible = "allegromicro,als31300-2000", 475 + .data = &al31300_variant_2000, 476 + }, 477 + { /* sentinel */ } 478 + }; 479 + MODULE_DEVICE_TABLE(of, als31300_of_match); 480 + 481 + static struct i2c_driver als31300_driver = { 482 + .driver = { 483 + .name = "als31300", 484 + .of_match_table = als31300_of_match, 485 + .pm = pm_ptr(&als31300_pm_ops), 486 + }, 487 + .probe = als31300_probe, 488 + .id_table = als31300_id, 489 + }; 490 + module_i2c_driver(als31300_driver); 491 + 492 + MODULE_LICENSE("GPL"); 493 + MODULE_DESCRIPTION("ALS31300 3-D Linear Hall Effect Driver"); 494 + MODULE_AUTHOR("Neil Armstrong <neil.armstrong@linaro.org>");
-15
drivers/iio/magnetometer/bmc150_magn.c
··· 14 14 #include <linux/interrupt.h> 15 15 #include <linux/delay.h> 16 16 #include <linux/slab.h> 17 - #include <linux/acpi.h> 18 17 #include <linux/pm.h> 19 18 #include <linux/pm_runtime.h> 20 19 #include <linux/iio/iio.h> ··· 854 855 .postdisable = bmc150_magn_buffer_postdisable, 855 856 }; 856 857 857 - static const char *bmc150_magn_match_acpi_device(struct device *dev) 858 - { 859 - const struct acpi_device_id *id; 860 - 861 - id = acpi_match_device(dev->driver->acpi_match_table, dev); 862 - if (!id) 863 - return NULL; 864 - 865 - return dev_name(dev); 866 - } 867 - 868 858 int bmc150_magn_probe(struct device *dev, struct regmap *regmap, 869 859 int irq, const char *name) 870 860 { ··· 881 893 ret = iio_read_mount_matrix(dev, &data->orientation); 882 894 if (ret) 883 895 return ret; 884 - 885 - if (!name && ACPI_HANDLE(dev)) 886 - name = bmc150_magn_match_acpi_device(dev); 887 896 888 897 mutex_init(&data->mutex); 889 898
-9
drivers/iio/magnetometer/bmc150_magn_i2c.c
··· 38 38 bmc150_magn_remove(&client->dev); 39 39 } 40 40 41 - static const struct acpi_device_id bmc150_magn_acpi_match[] = { 42 - {"BMC150B", 0}, 43 - {"BMC156B", 0}, 44 - {"BMM150B", 0}, 45 - {}, 46 - }; 47 - MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match); 48 - 49 41 static const struct i2c_device_id bmc150_magn_i2c_id[] = { 50 42 { "bmc150_magn" }, 51 43 { "bmc156_magn" }, ··· 59 67 .driver = { 60 68 .name = "bmc150_magn_i2c", 61 69 .of_match_table = bmc150_magn_of_match, 62 - .acpi_match_table = bmc150_magn_acpi_match, 63 70 .pm = &bmc150_magn_pm_ops, 64 71 }, 65 72 .probe = bmc150_magn_i2c_probe,
-9
drivers/iio/magnetometer/bmc150_magn_spi.c
··· 41 41 }; 42 42 MODULE_DEVICE_TABLE(spi, bmc150_magn_spi_id); 43 43 44 - static const struct acpi_device_id bmc150_magn_acpi_match[] = { 45 - {"BMC150B", 0}, 46 - {"BMC156B", 0}, 47 - {"BMM150B", 0}, 48 - {}, 49 - }; 50 - MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match); 51 - 52 44 static struct spi_driver bmc150_magn_spi_driver = { 53 45 .probe = bmc150_magn_spi_probe, 54 46 .remove = bmc150_magn_spi_remove, 55 47 .id_table = bmc150_magn_spi_id, 56 48 .driver = { 57 - .acpi_match_table = bmc150_magn_acpi_match, 58 49 .name = "bmc150_magn_spi", 59 50 }, 60 51 };
+1 -1
drivers/iio/position/iqs624-pos.c
··· 181 181 const struct iio_chan_spec *chan, 182 182 enum iio_event_type type, 183 183 enum iio_event_direction dir, 184 - int state) 184 + bool state) 185 185 { 186 186 struct iqs624_pos_private *iqs624_pos = iio_priv(indio_dev); 187 187 struct iqs62x_core *iqs62x = iqs624_pos->iqs62x;
+501 -35
drivers/iio/pressure/bmp280-core.c
··· 16 16 * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp390-ds002.pdf 17 17 * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp581-ds004.pdf 18 18 * 19 + * Sensor API: 20 + * https://github.com/boschsensortec/BME280_SensorAPI 21 + * https://github.com/boschsensortec/BMP3_SensorAPI 22 + * https://github.com/boschsensortec/BMP5_SensorAPI 23 + * 19 24 * Notice: 20 25 * The link to the bmp180 datasheet points to an outdated version missing these changes: 21 26 * - Changed document referral from ANP015 to BST-MPS-AN004-00 on page 26 ··· 42 37 #include <linux/module.h> 43 38 #include <linux/nvmem-provider.h> 44 39 #include <linux/pm_runtime.h> 40 + #include <linux/property.h> 45 41 #include <linux/random.h> 46 42 #include <linux/regmap.h> 47 43 #include <linux/regulator/consumer.h> 48 44 49 45 #include <linux/iio/buffer.h> 50 46 #include <linux/iio/iio.h> 47 + #include <linux/iio/trigger.h> 51 48 #include <linux/iio/trigger_consumer.h> 52 49 #include <linux/iio/triggered_buffer.h> 53 50 ··· 623 616 624 617 switch (mask) { 625 618 case IIO_CHAN_INFO_PROCESSED: 619 + ret = data->chip_info->set_mode(data, BMP280_FORCED); 620 + if (ret) 621 + return ret; 622 + 623 + ret = data->chip_info->wait_conv(data); 624 + if (ret) 625 + return ret; 626 + 626 627 switch (chan->type) { 627 628 case IIO_HUMIDITYRELATIVE: 628 629 ret = data->chip_info->read_humid(data, &chan_value); ··· 660 645 return -EINVAL; 661 646 } 662 647 case IIO_CHAN_INFO_RAW: 648 + ret = data->chip_info->set_mode(data, BMP280_FORCED); 649 + if (ret) 650 + return ret; 651 + 652 + ret = data->chip_info->wait_conv(data); 653 + if (ret) 654 + return ret; 655 + 663 656 switch (chan->type) { 664 657 case IIO_HUMIDITYRELATIVE: 665 658 ret = data->chip_info->read_humid(data, &chan_value); ··· 1014 991 return 0; 1015 992 } 1016 993 994 + static const u8 bmp280_operation_mode[] = { 995 + [BMP280_SLEEP] = BMP280_MODE_SLEEP, 996 + [BMP280_FORCED] = BMP280_MODE_FORCED, 997 + [BMP280_NORMAL] = BMP280_MODE_NORMAL, 998 + }; 999 + 1000 + static int bmp280_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode) 1001 + { 1002 + int ret; 1003 + 1004 + ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, 1005 + BMP280_MODE_MASK, bmp280_operation_mode[mode]); 1006 + if (ret) { 1007 + dev_err(data->dev, "failed to write ctrl_meas register.\n"); 1008 + return ret; 1009 + } 1010 + 1011 + data->op_mode = mode; 1012 + 1013 + return 0; 1014 + } 1015 + 1016 + static int bmp280_wait_conv(struct bmp280_data *data) 1017 + { 1018 + unsigned int reg, meas_time_us; 1019 + int ret; 1020 + 1021 + /* Check if we are using a BME280 device */ 1022 + if (data->oversampling_humid) 1023 + meas_time_us = BMP280_PRESS_HUMID_MEAS_OFFSET + 1024 + BIT(data->oversampling_humid) * BMP280_MEAS_DUR; 1025 + 1026 + else 1027 + meas_time_us = 0; 1028 + 1029 + /* Pressure measurement time */ 1030 + meas_time_us += BMP280_PRESS_HUMID_MEAS_OFFSET + 1031 + BIT(data->oversampling_press) * BMP280_MEAS_DUR; 1032 + 1033 + /* Temperature measurement time */ 1034 + meas_time_us += BIT(data->oversampling_temp) * BMP280_MEAS_DUR; 1035 + 1036 + /* Waiting time according to the BM(P/E)2 Sensor API */ 1037 + fsleep(meas_time_us); 1038 + 1039 + ret = regmap_read(data->regmap, BMP280_REG_STATUS, &reg); 1040 + if (ret) { 1041 + dev_err(data->dev, "failed to read status register.\n"); 1042 + return ret; 1043 + } 1044 + 1045 + if (reg & BMP280_REG_STATUS_MEAS_BIT) { 1046 + dev_err(data->dev, "Measurement cycle didn't complete.\n"); 1047 + return -EBUSY; 1048 + } 1049 + 1050 + return 0; 1051 + } 1052 + 1017 1053 static int bmp280_chip_config(struct bmp280_data *data) 1018 1054 { 1019 1055 u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | ··· 1083 1001 BMP280_OSRS_TEMP_MASK | 1084 1002 BMP280_OSRS_PRESS_MASK | 1085 1003 BMP280_MODE_MASK, 1086 - osrs | BMP280_MODE_NORMAL); 1004 + osrs | BMP280_MODE_SLEEP); 1087 1005 if (ret) { 1088 1006 dev_err(data->dev, "failed to write ctrl_meas register\n"); 1089 1007 return ret; ··· 1193 1111 .read_temp = bmp280_read_temp, 1194 1112 .read_press = bmp280_read_press, 1195 1113 .read_calib = bmp280_read_calib, 1114 + .set_mode = bmp280_set_mode, 1115 + .wait_conv = bmp280_wait_conv, 1196 1116 .preinit = bmp280_preinit, 1197 1117 1198 1118 .trigger_handler = bmp280_trigger_handler, ··· 1282 1198 return IRQ_HANDLED; 1283 1199 } 1284 1200 1201 + static int __bmp280_trigger_probe(struct iio_dev *indio_dev, 1202 + const struct iio_trigger_ops *trigger_ops, 1203 + int (*int_pin_config)(struct bmp280_data *data), 1204 + irq_handler_t irq_thread_handler) 1205 + { 1206 + struct bmp280_data *data = iio_priv(indio_dev); 1207 + struct device *dev = data->dev; 1208 + u32 irq_type; 1209 + int ret, irq; 1210 + 1211 + irq = fwnode_irq_get(dev_fwnode(dev), 0); 1212 + if (irq < 0) 1213 + return dev_err_probe(dev, irq, "No interrupt found.\n"); 1214 + 1215 + irq_type = irq_get_trigger_type(irq); 1216 + switch (irq_type) { 1217 + case IRQF_TRIGGER_RISING: 1218 + data->trig_active_high = true; 1219 + break; 1220 + case IRQF_TRIGGER_FALLING: 1221 + data->trig_active_high = false; 1222 + break; 1223 + default: 1224 + return dev_err_probe(dev, -EINVAL, "Invalid interrupt type specified.\n"); 1225 + } 1226 + 1227 + data->trig_open_drain = 1228 + fwnode_property_read_bool(dev_fwnode(dev), "int-open-drain"); 1229 + 1230 + ret = int_pin_config(data); 1231 + if (ret) 1232 + return ret; 1233 + 1234 + data->trig = devm_iio_trigger_alloc(data->dev, "%s-dev%d", 1235 + indio_dev->name, 1236 + iio_device_id(indio_dev)); 1237 + if (!data->trig) 1238 + return -ENOMEM; 1239 + 1240 + data->trig->ops = trigger_ops; 1241 + iio_trigger_set_drvdata(data->trig, data); 1242 + 1243 + ret = devm_request_threaded_irq(data->dev, irq, NULL, 1244 + irq_thread_handler, IRQF_ONESHOT, 1245 + indio_dev->name, indio_dev); 1246 + if (ret) 1247 + return dev_err_probe(dev, ret, "request IRQ failed.\n"); 1248 + 1249 + ret = devm_iio_trigger_register(data->dev, data->trig); 1250 + if (ret) 1251 + return dev_err_probe(dev, ret, "iio trigger register failed.\n"); 1252 + 1253 + indio_dev->trig = iio_trigger_get(data->trig); 1254 + 1255 + return 0; 1256 + } 1257 + 1285 1258 static const u8 bme280_chip_ids[] = { BME280_CHIP_ID }; 1286 1259 static const int bme280_humid_coeffs[] = { 1000, 1024 }; 1287 1260 ··· 1376 1235 .read_press = bmp280_read_press, 1377 1236 .read_humid = bme280_read_humid, 1378 1237 .read_calib = bme280_read_calib, 1238 + .set_mode = bmp280_set_mode, 1239 + .wait_conv = bmp280_wait_conv, 1379 1240 .preinit = bmp280_preinit, 1380 1241 1381 1242 .trigger_handler = bme280_trigger_handler, ··· 1665 1522 return bmp380_cmd(data, BMP380_CMD_SOFT_RESET); 1666 1523 } 1667 1524 1525 + static const u8 bmp380_operation_mode[] = { 1526 + [BMP280_SLEEP] = BMP380_MODE_SLEEP, 1527 + [BMP280_FORCED] = BMP380_MODE_FORCED, 1528 + [BMP280_NORMAL] = BMP380_MODE_NORMAL, 1529 + }; 1530 + 1531 + static int bmp380_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode) 1532 + { 1533 + int ret; 1534 + 1535 + ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, 1536 + BMP380_MODE_MASK, 1537 + FIELD_PREP(BMP380_MODE_MASK, 1538 + bmp380_operation_mode[mode])); 1539 + if (ret) { 1540 + dev_err(data->dev, "failed to write power control register.\n"); 1541 + return ret; 1542 + } 1543 + 1544 + data->op_mode = mode; 1545 + 1546 + return 0; 1547 + } 1548 + 1549 + static int bmp380_wait_conv(struct bmp280_data *data) 1550 + { 1551 + unsigned int reg; 1552 + int ret, meas_time_us; 1553 + 1554 + /* Offset measurement time */ 1555 + meas_time_us = BMP380_MEAS_OFFSET; 1556 + 1557 + /* Pressure measurement time */ 1558 + meas_time_us += BMP380_PRESS_MEAS_OFFSET + 1559 + BIT(data->oversampling_press) * BMP380_MEAS_DUR; 1560 + 1561 + /* Temperature measurement time */ 1562 + meas_time_us += BMP380_TEMP_MEAS_OFFSET + 1563 + BIT(data->oversampling_temp) * BMP380_MEAS_DUR; 1564 + 1565 + /* Measurement time defined in Datasheet Section 3.9.2 */ 1566 + fsleep(meas_time_us); 1567 + 1568 + ret = regmap_read(data->regmap, BMP380_REG_STATUS, &reg); 1569 + if (ret) { 1570 + dev_err(data->dev, "failed to read status register.\n"); 1571 + return ret; 1572 + } 1573 + 1574 + if (!((reg & BMP380_STATUS_DRDY_PRESS_MASK) && 1575 + (reg & BMP380_STATUS_DRDY_TEMP_MASK))) { 1576 + dev_err(data->dev, "Measurement cycle didn't complete.\n"); 1577 + return -EBUSY; 1578 + } 1579 + 1580 + return 0; 1581 + } 1582 + 1668 1583 static int bmp380_chip_config(struct bmp280_data *data) 1669 1584 { 1670 1585 bool change = false, aux; ··· 1783 1582 * Resets sensor measurement loop toggling between sleep and 1784 1583 * normal operating modes. 1785 1584 */ 1786 - ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, 1787 - BMP380_MODE_MASK, 1788 - FIELD_PREP(BMP380_MODE_MASK, BMP380_MODE_SLEEP)); 1585 + ret = bmp380_set_mode(data, BMP280_SLEEP); 1789 1586 if (ret) { 1790 1587 dev_err(data->dev, "failed to set sleep mode\n"); 1791 1588 return ret; 1792 1589 } 1793 - usleep_range(2000, 2500); 1794 - ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, 1795 - BMP380_MODE_MASK, 1796 - FIELD_PREP(BMP380_MODE_MASK, BMP380_MODE_NORMAL)); 1590 + 1591 + /* 1592 + * According to the BMP3 Sensor API, the sensor needs 5ms 1593 + * in order to go to the sleep mode. 1594 + */ 1595 + fsleep(5 * USEC_PER_MSEC); 1596 + 1597 + ret = bmp380_set_mode(data, BMP280_NORMAL); 1797 1598 if (ret) { 1798 1599 dev_err(data->dev, "failed to set normal mode\n"); 1799 1600 return ret; ··· 1821 1618 } 1822 1619 } 1823 1620 1824 - return 0; 1621 + /* Dummy read to empty data registers. */ 1622 + ret = bmp380_read_press(data, &tmp); 1623 + if (ret) 1624 + return ret; 1625 + 1626 + ret = bmp380_set_mode(data, BMP280_SLEEP); 1627 + if (ret) 1628 + dev_err(data->dev, "failed to set sleep mode.\n"); 1629 + 1630 + return ret; 1631 + } 1632 + 1633 + static int bmp380_data_rdy_trigger_set_state(struct iio_trigger *trig, 1634 + bool state) 1635 + { 1636 + struct bmp280_data *data = iio_trigger_get_drvdata(trig); 1637 + int ret; 1638 + 1639 + guard(mutex)(&data->lock); 1640 + 1641 + ret = regmap_update_bits(data->regmap, BMP380_REG_INT_CONTROL, 1642 + BMP380_INT_CTRL_DRDY_EN, 1643 + FIELD_PREP(BMP380_INT_CTRL_DRDY_EN, !!state)); 1644 + if (ret) 1645 + dev_err(data->dev, 1646 + "Could not %s interrupt.\n", str_enable_disable(state)); 1647 + return ret; 1648 + } 1649 + 1650 + static const struct iio_trigger_ops bmp380_trigger_ops = { 1651 + .set_trigger_state = &bmp380_data_rdy_trigger_set_state, 1652 + }; 1653 + 1654 + static int bmp380_int_pin_config(struct bmp280_data *data) 1655 + { 1656 + int pin_drive_cfg = FIELD_PREP(BMP380_INT_CTRL_OPEN_DRAIN, 1657 + data->trig_open_drain); 1658 + int pin_level_cfg = FIELD_PREP(BMP380_INT_CTRL_LEVEL, 1659 + data->trig_active_high); 1660 + int ret, int_pin_cfg = pin_drive_cfg | pin_level_cfg; 1661 + 1662 + ret = regmap_update_bits(data->regmap, BMP380_REG_INT_CONTROL, 1663 + BMP380_INT_CTRL_SETTINGS_MASK, int_pin_cfg); 1664 + if (ret) 1665 + dev_err(data->dev, "Could not set interrupt settings.\n"); 1666 + 1667 + return ret; 1668 + } 1669 + 1670 + static irqreturn_t bmp380_irq_thread_handler(int irq, void *p) 1671 + { 1672 + struct iio_dev *indio_dev = p; 1673 + struct bmp280_data *data = iio_priv(indio_dev); 1674 + unsigned int int_ctrl; 1675 + int ret; 1676 + 1677 + ret = regmap_read(data->regmap, BMP380_REG_INT_STATUS, &int_ctrl); 1678 + if (ret) 1679 + return IRQ_NONE; 1680 + 1681 + if (FIELD_GET(BMP380_INT_STATUS_DRDY, int_ctrl)) 1682 + iio_trigger_poll_nested(data->trig); 1683 + 1684 + return IRQ_HANDLED; 1685 + } 1686 + 1687 + static int bmp380_trigger_probe(struct iio_dev *indio_dev) 1688 + { 1689 + return __bmp280_trigger_probe(indio_dev, &bmp380_trigger_ops, 1690 + bmp380_int_pin_config, 1691 + bmp380_irq_thread_handler); 1825 1692 } 1826 1693 1827 1694 static irqreturn_t bmp380_trigger_handler(int irq, void *p) ··· 1987 1714 .read_temp = bmp380_read_temp, 1988 1715 .read_press = bmp380_read_press, 1989 1716 .read_calib = bmp380_read_calib, 1717 + .set_mode = bmp380_set_mode, 1718 + .wait_conv = bmp380_wait_conv, 1990 1719 .preinit = bmp380_preinit, 1991 1720 1721 + .trigger_probe = bmp380_trigger_probe, 1992 1722 .trigger_handler = bmp380_trigger_handler, 1993 1723 }; 1994 1724 EXPORT_SYMBOL_NS(bmp380_chip_info, IIO_BMP280); ··· 2377 2101 return PTR_ERR_OR_ZERO(devm_nvmem_register(config.dev, &config)); 2378 2102 } 2379 2103 2104 + static const u8 bmp580_operation_mode[] = { 2105 + [BMP280_SLEEP] = BMP580_MODE_SLEEP, 2106 + [BMP280_FORCED] = BMP580_MODE_FORCED, 2107 + [BMP280_NORMAL] = BMP580_MODE_NORMAL, 2108 + }; 2109 + 2110 + static int bmp580_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode) 2111 + { 2112 + struct device *dev = data->dev; 2113 + int ret; 2114 + 2115 + if (mode == BMP280_FORCED) { 2116 + ret = regmap_set_bits(data->regmap, BMP580_REG_DSP_CONFIG, 2117 + BMP580_DSP_IIR_FORCED_FLUSH); 2118 + if (ret) { 2119 + dev_err(dev, "Could not flush IIR filter constants.\n"); 2120 + return ret; 2121 + } 2122 + } 2123 + 2124 + ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, 2125 + BMP580_MODE_MASK, 2126 + FIELD_PREP(BMP580_MODE_MASK, 2127 + bmp580_operation_mode[mode])); 2128 + if (ret) { 2129 + dev_err(dev, "failed to write power control register.\n"); 2130 + return ret; 2131 + } 2132 + 2133 + data->op_mode = mode; 2134 + 2135 + return 0; 2136 + } 2137 + 2138 + static int bmp580_wait_conv(struct bmp280_data *data) 2139 + { 2140 + /* 2141 + * Taken from datasheet, Section 2 "Specification, Table 3 "Electrical 2142 + * characteristics. 2143 + */ 2144 + static const int time_conv_press[] = { 2145 + 0, 1050, 1785, 3045, 5670, 10920, 21420, 42420, 2146 + 84420, 2147 + }; 2148 + static const int time_conv_temp[] = { 2149 + 0, 1050, 1105, 1575, 2205, 3465, 6090, 11340, 2150 + 21840, 2151 + }; 2152 + int meas_time_us; 2153 + 2154 + meas_time_us = 4 * USEC_PER_MSEC + 2155 + time_conv_temp[data->oversampling_temp] + 2156 + time_conv_press[data->oversampling_press]; 2157 + 2158 + /* 2159 + * Measurement time mentioned in Chapter 2, Table 4 of the datasheet. 2160 + * The extra 4ms is the required mode change to start of measurement 2161 + * time. 2162 + */ 2163 + fsleep(meas_time_us); 2164 + 2165 + return 0; 2166 + } 2167 + 2380 2168 static int bmp580_chip_config(struct bmp280_data *data) 2381 2169 { 2382 2170 bool change = false, aux; ··· 2511 2171 return ret; 2512 2172 } 2513 2173 2514 - /* Restore sensor to normal operation mode */ 2515 - ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, 2516 - BMP580_MODE_MASK, 2517 - FIELD_PREP(BMP580_MODE_MASK, BMP580_MODE_NORMAL)); 2518 - if (ret) { 2519 - dev_err(data->dev, "failed to set normal mode\n"); 2520 - return ret; 2521 - } 2522 - /* From datasheet's table 4: electrical characteristics */ 2523 - usleep_range(3000, 3500); 2524 - 2525 2174 if (change) { 2526 2175 /* 2527 2176 * Check if ODR and OSR settings are valid or we are ··· 2532 2203 } 2533 2204 2534 2205 return 0; 2206 + } 2207 + 2208 + static int bmp580_data_rdy_trigger_set_state(struct iio_trigger *trig, 2209 + bool state) 2210 + { 2211 + struct bmp280_data *data = iio_trigger_get_drvdata(trig); 2212 + int ret; 2213 + 2214 + guard(mutex)(&data->lock); 2215 + 2216 + ret = regmap_update_bits(data->regmap, BMP580_REG_INT_CONFIG, 2217 + BMP580_INT_CONFIG_INT_EN, 2218 + FIELD_PREP(BMP580_INT_CONFIG_INT_EN, !!state)); 2219 + if (ret) 2220 + dev_err(data->dev, 2221 + "Could not %s interrupt.\n", str_enable_disable(state)); 2222 + return ret; 2223 + } 2224 + 2225 + static const struct iio_trigger_ops bmp580_trigger_ops = { 2226 + .set_trigger_state = &bmp580_data_rdy_trigger_set_state, 2227 + }; 2228 + 2229 + static int bmp580_int_pin_config(struct bmp280_data *data) 2230 + { 2231 + int pin_drive_cfg = FIELD_PREP(BMP580_INT_CONFIG_OPEN_DRAIN, 2232 + data->trig_open_drain); 2233 + int pin_level_cfg = FIELD_PREP(BMP580_INT_CONFIG_LEVEL, 2234 + data->trig_active_high); 2235 + int ret, int_pin_cfg = pin_drive_cfg | pin_level_cfg; 2236 + 2237 + ret = regmap_update_bits(data->regmap, BMP580_REG_INT_CONFIG, 2238 + BMP580_INT_CONFIG_MASK, int_pin_cfg); 2239 + if (ret) { 2240 + dev_err(data->dev, "Could not set interrupt settings.\n"); 2241 + return ret; 2242 + } 2243 + 2244 + ret = regmap_set_bits(data->regmap, BMP580_REG_INT_SOURCE, 2245 + BMP580_INT_SOURCE_DRDY); 2246 + if (ret) 2247 + dev_err(data->dev, "Could not set interrupt source.\n"); 2248 + 2249 + return ret; 2250 + } 2251 + 2252 + static irqreturn_t bmp580_irq_thread_handler(int irq, void *p) 2253 + { 2254 + struct iio_dev *indio_dev = p; 2255 + struct bmp280_data *data = iio_priv(indio_dev); 2256 + unsigned int int_ctrl; 2257 + int ret; 2258 + 2259 + ret = regmap_read(data->regmap, BMP580_REG_INT_STATUS, &int_ctrl); 2260 + if (ret) 2261 + return IRQ_NONE; 2262 + 2263 + if (FIELD_GET(BMP580_INT_STATUS_DRDY_MASK, int_ctrl)) 2264 + iio_trigger_poll_nested(data->trig); 2265 + 2266 + return IRQ_HANDLED; 2267 + } 2268 + 2269 + static int bmp580_trigger_probe(struct iio_dev *indio_dev) 2270 + { 2271 + return __bmp280_trigger_probe(indio_dev, &bmp580_trigger_ops, 2272 + bmp580_int_pin_config, 2273 + bmp580_irq_thread_handler); 2535 2274 } 2536 2275 2537 2276 static irqreturn_t bmp580_trigger_handler(int irq, void *p) ··· 2678 2281 .chip_config = bmp580_chip_config, 2679 2282 .read_temp = bmp580_read_temp, 2680 2283 .read_press = bmp580_read_press, 2284 + .set_mode = bmp580_set_mode, 2285 + .wait_conv = bmp580_wait_conv, 2681 2286 .preinit = bmp580_preinit, 2682 2287 2288 + .trigger_probe = bmp580_trigger_probe, 2683 2289 .trigger_handler = bmp580_trigger_handler, 2684 2290 }; 2685 2291 EXPORT_SYMBOL_NS(bmp580_chip_info, IIO_BMP280); ··· 2928 2528 return 0; 2929 2529 } 2930 2530 2531 + /* Keep compatibility with newer generations of the sensor */ 2532 + static int bmp180_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode) 2533 + { 2534 + return 0; 2535 + } 2536 + 2537 + /* Keep compatibility with newer generations of the sensor */ 2538 + static int bmp180_wait_conv(struct bmp280_data *data) 2539 + { 2540 + return 0; 2541 + } 2542 + 2543 + /* Keep compatibility with newer generations of the sensor */ 2931 2544 static int bmp180_chip_config(struct bmp280_data *data) 2932 2545 { 2933 2546 return 0; ··· 3012 2599 .read_temp = bmp180_read_temp, 3013 2600 .read_press = bmp180_read_press, 3014 2601 .read_calib = bmp180_read_calib, 2602 + .set_mode = bmp180_set_mode, 2603 + .wait_conv = bmp180_wait_conv, 3015 2604 3016 2605 .trigger_handler = bmp180_trigger_handler, 3017 2606 }; ··· 3028 2613 return IRQ_HANDLED; 3029 2614 } 3030 2615 3031 - static int bmp085_fetch_eoc_irq(struct device *dev, 3032 - const char *name, 3033 - int irq, 3034 - struct bmp280_data *data) 2616 + static int bmp085_trigger_probe(struct iio_dev *indio_dev) 3035 2617 { 2618 + struct bmp280_data *data = iio_priv(indio_dev); 2619 + struct device *dev = data->dev; 3036 2620 unsigned long irq_trig; 3037 - int ret; 2621 + int ret, irq; 2622 + 2623 + irq = fwnode_irq_get(dev_fwnode(dev), 0); 2624 + if (irq < 0) 2625 + return dev_err_probe(dev, irq, "No interrupt found.\n"); 3038 2626 3039 2627 irq_trig = irq_get_trigger_type(irq); 3040 2628 if (irq_trig != IRQF_TRIGGER_RISING) { ··· 3047 2629 3048 2630 init_completion(&data->done); 3049 2631 3050 - ret = devm_request_threaded_irq(dev, 3051 - irq, 3052 - bmp085_eoc_irq, 3053 - NULL, 3054 - irq_trig, 3055 - name, 3056 - data); 2632 + ret = devm_request_irq(dev, irq, bmp085_eoc_irq, irq_trig, 2633 + indio_dev->name, data); 3057 2634 if (ret) { 3058 2635 /* Bail out without IRQ but keep the driver in place */ 3059 2636 dev_err(dev, "unable to request DRDY IRQ\n"); ··· 3056 2643 } 3057 2644 3058 2645 data->use_eoc = true; 2646 + 3059 2647 return 0; 3060 2648 } 2649 + 2650 + /* Identical to bmp180_chip_info + bmp085_trigger_probe */ 2651 + const struct bmp280_chip_info bmp085_chip_info = { 2652 + .id_reg = BMP280_REG_ID, 2653 + .chip_id = bmp180_chip_ids, 2654 + .num_chip_id = ARRAY_SIZE(bmp180_chip_ids), 2655 + .regmap_config = &bmp180_regmap_config, 2656 + .start_up_time = 2000, 2657 + .channels = bmp280_channels, 2658 + .num_channels = ARRAY_SIZE(bmp280_channels), 2659 + .avail_scan_masks = bmp280_avail_scan_masks, 2660 + 2661 + .oversampling_temp_avail = bmp180_oversampling_temp_avail, 2662 + .num_oversampling_temp_avail = 2663 + ARRAY_SIZE(bmp180_oversampling_temp_avail), 2664 + .oversampling_temp_default = 0, 2665 + 2666 + .oversampling_press_avail = bmp180_oversampling_press_avail, 2667 + .num_oversampling_press_avail = 2668 + ARRAY_SIZE(bmp180_oversampling_press_avail), 2669 + .oversampling_press_default = BMP180_MEAS_PRESS_8X, 2670 + 2671 + .temp_coeffs = bmp180_temp_coeffs, 2672 + .temp_coeffs_type = IIO_VAL_FRACTIONAL, 2673 + .press_coeffs = bmp180_press_coeffs, 2674 + .press_coeffs_type = IIO_VAL_FRACTIONAL, 2675 + 2676 + .chip_config = bmp180_chip_config, 2677 + .read_temp = bmp180_read_temp, 2678 + .read_press = bmp180_read_press, 2679 + .read_calib = bmp180_read_calib, 2680 + .set_mode = bmp180_set_mode, 2681 + .wait_conv = bmp180_wait_conv, 2682 + 2683 + .trigger_probe = bmp085_trigger_probe, 2684 + .trigger_handler = bmp180_trigger_handler, 2685 + }; 2686 + EXPORT_SYMBOL_NS(bmp085_chip_info, IIO_BMP280); 3061 2687 3062 2688 static int bmp280_buffer_preenable(struct iio_dev *indio_dev) 3063 2689 { 3064 2690 struct bmp280_data *data = iio_priv(indio_dev); 3065 2691 3066 2692 pm_runtime_get_sync(data->dev); 2693 + data->chip_info->set_mode(data, BMP280_NORMAL); 3067 2694 3068 2695 return 0; 3069 2696 } ··· 3268 2815 * however as it happens, the BMP085 shares the chip ID of BMP180 3269 2816 * so we look for an IRQ if we have that. 3270 2817 */ 3271 - if (irq > 0 && (chip_id == BMP180_CHIP_ID)) { 3272 - ret = bmp085_fetch_eoc_irq(dev, name, irq, data); 2818 + if (irq > 0) { 2819 + if (data->chip_info->trigger_probe) 2820 + ret = data->chip_info->trigger_probe(indio_dev); 3273 2821 if (ret) 3274 2822 return ret; 3275 2823 } 2824 + 2825 + ret = data->chip_info->set_mode(data, BMP280_SLEEP); 2826 + if (ret) 2827 + return dev_err_probe(dev, ret, "Failed to set sleep mode\n"); 3276 2828 3277 2829 /* Enable runtime PM */ 3278 2830 pm_runtime_get_noresume(dev); ··· 3304 2846 struct iio_dev *indio_dev = dev_get_drvdata(dev); 3305 2847 struct bmp280_data *data = iio_priv(indio_dev); 3306 2848 2849 + data->chip_info->set_mode(data, BMP280_SLEEP); 2850 + 2851 + fsleep(data->start_up_time); 3307 2852 return regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies); 3308 2853 } 3309 2854 ··· 3321 2860 return ret; 3322 2861 3323 2862 usleep_range(data->start_up_time, data->start_up_time + 100); 3324 - return data->chip_info->chip_config(data); 2863 + 2864 + ret = data->chip_info->chip_config(data); 2865 + if (ret) 2866 + return ret; 2867 + 2868 + return data->chip_info->set_mode(data, data->op_mode); 3325 2869 } 3326 2870 3327 2871 EXPORT_RUNTIME_DEV_PM_OPS(bmp280_dev_pm_ops, bmp280_runtime_suspend,
+2 -2
drivers/iio/pressure/bmp280-i2c.c
··· 27 27 } 28 28 29 29 static const struct of_device_id bmp280_of_i2c_match[] = { 30 - { .compatible = "bosch,bmp085", .data = &bmp180_chip_info }, 30 + { .compatible = "bosch,bmp085", .data = &bmp085_chip_info }, 31 31 { .compatible = "bosch,bmp180", .data = &bmp180_chip_info }, 32 32 { .compatible = "bosch,bmp280", .data = &bmp280_chip_info }, 33 33 { .compatible = "bosch,bme280", .data = &bme280_chip_info }, ··· 38 38 MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match); 39 39 40 40 static const struct i2c_device_id bmp280_i2c_id[] = { 41 - {"bmp085", (kernel_ulong_t)&bmp180_chip_info }, 41 + {"bmp085", (kernel_ulong_t)&bmp085_chip_info }, 42 42 {"bmp180", (kernel_ulong_t)&bmp180_chip_info }, 43 43 {"bmp280", (kernel_ulong_t)&bmp280_chip_info }, 44 44 {"bme280", (kernel_ulong_t)&bme280_chip_info },
+2 -2
drivers/iio/pressure/bmp280-spi.c
··· 114 114 } 115 115 116 116 static const struct of_device_id bmp280_of_spi_match[] = { 117 - { .compatible = "bosch,bmp085", .data = &bmp180_chip_info }, 117 + { .compatible = "bosch,bmp085", .data = &bmp085_chip_info }, 118 118 { .compatible = "bosch,bmp180", .data = &bmp180_chip_info }, 119 119 { .compatible = "bosch,bmp181", .data = &bmp180_chip_info }, 120 120 { .compatible = "bosch,bmp280", .data = &bmp280_chip_info }, ··· 126 126 MODULE_DEVICE_TABLE(of, bmp280_of_spi_match); 127 127 128 128 static const struct spi_device_id bmp280_spi_id[] = { 129 - { "bmp085", (kernel_ulong_t)&bmp180_chip_info }, 129 + { "bmp085", (kernel_ulong_t)&bmp085_chip_info }, 130 130 { "bmp180", (kernel_ulong_t)&bmp180_chip_info }, 131 131 { "bmp181", (kernel_ulong_t)&bmp180_chip_info }, 132 132 { "bmp280", (kernel_ulong_t)&bmp280_chip_info },
+43
drivers/iio/pressure/bmp280.h
··· 55 55 #define BMP580_CMD_NVM_WRITE_SEQ_1 0xA0 56 56 #define BMP580_CMD_SOFT_RESET 0xB6 57 57 58 + #define BMP580_INT_STATUS_DRDY_MASK BIT(0) 58 59 #define BMP580_INT_STATUS_POR_MASK BIT(4) 60 + 61 + #define BMP580_INT_SOURCE_DRDY BIT(0) 62 + 63 + #define BMP580_INT_CONFIG_MASK GENMASK(3, 0) 64 + #define BMP580_INT_CONFIG_LATCH BIT(0) 65 + #define BMP580_INT_CONFIG_LEVEL BIT(1) 66 + #define BMP580_INT_CONFIG_OPEN_DRAIN BIT(2) 67 + #define BMP580_INT_CONFIG_INT_EN BIT(3) 59 68 60 69 #define BMP580_STATUS_CORE_RDY_MASK BIT(0) 61 70 #define BMP580_STATUS_NVM_RDY_MASK BIT(1) ··· 179 170 #define BMP380_MODE_FORCED 1 180 171 #define BMP380_MODE_NORMAL 3 181 172 173 + #define BMP380_MEAS_OFFSET 234 174 + #define BMP380_MEAS_DUR 2020 175 + #define BMP380_TEMP_MEAS_OFFSET 163 176 + #define BMP380_PRESS_MEAS_OFFSET 392 177 + 178 + #define BMP380_INT_STATUS_DRDY BIT(3) 179 + 180 + #define BMP380_INT_CTRL_SETTINGS_MASK GENMASK(2, 0) 181 + #define BMP380_INT_CTRL_OPEN_DRAIN BIT(0) 182 + #define BMP380_INT_CTRL_LEVEL BIT(1) 183 + #define BMP380_INT_CTRL_LATCH BIT(2) 184 + #define BMP380_INT_CTRL_DRDY_EN BIT(6) 185 + 182 186 #define BMP380_MIN_TEMP -4000 183 187 #define BMP380_MAX_TEMP 8500 184 188 #define BMP380_MIN_PRES 3000000 ··· 228 206 #define BMP280_REG_CTRL_MEAS 0xF4 229 207 #define BMP280_REG_STATUS 0xF3 230 208 #define BMP280_REG_STATUS_IM_UPDATE BIT(0) 209 + #define BMP280_REG_STATUS_MEAS_BIT BIT(3) 231 210 #define BMP280_REG_RESET 0xE0 232 211 #define BMP280_RST_SOFT_CMD 0xB6 233 212 ··· 268 245 #define BMP280_MODE_SLEEP 0 269 246 #define BMP280_MODE_FORCED 1 270 247 #define BMP280_MODE_NORMAL 3 248 + 249 + #define BMP280_MEAS_OFFSET 1250 250 + #define BMP280_MEAS_DUR 2300 251 + #define BMP280_PRESS_HUMID_MEAS_OFFSET 575 271 252 272 253 /* BME280 specific registers */ 273 254 #define BME280_REG_HUMIDITY_LSB 0xFE ··· 412 385 s8 P11; 413 386 }; 414 387 388 + enum bmp280_op_mode { 389 + BMP280_SLEEP, 390 + BMP280_FORCED, 391 + BMP280_NORMAL, 392 + }; 393 + 415 394 struct bmp280_data { 416 395 struct device *dev; 417 396 struct mutex lock; 418 397 struct regmap *regmap; 419 398 struct completion done; 420 399 bool use_eoc; 400 + bool trig_open_drain; 401 + bool trig_active_high; 402 + struct iio_trigger *trig; 421 403 const struct bmp280_chip_info *chip_info; 422 404 union { 423 405 struct bmp180_calib bmp180; ··· 458 422 */ 459 423 u8 sensor_data[ALIGN(sizeof(s32) * BME280_NUM_MAX_CHANNELS, sizeof(s64)) 460 424 + sizeof(s64)] __aligned(sizeof(s64)); 425 + 426 + /* Value to hold the current operation mode of the device */ 427 + enum bmp280_op_mode op_mode; 461 428 462 429 /* 463 430 * DMA (thus cache coherency maintenance) may require the ··· 526 487 int (*read_humid)(struct bmp280_data *data, u32 *adc_humidity); 527 488 int (*read_calib)(struct bmp280_data *data); 528 489 int (*preinit)(struct bmp280_data *data); 490 + int (*set_mode)(struct bmp280_data *data, enum bmp280_op_mode mode); 491 + int (*wait_conv)(struct bmp280_data *data); 529 492 493 + int (*trigger_probe)(struct iio_dev *indio_dev); 530 494 irqreturn_t (*trigger_handler)(int irq, void *p); 531 495 }; 532 496 533 497 /* Chip infos for each variant */ 498 + extern const struct bmp280_chip_info bmp085_chip_info; 534 499 extern const struct bmp280_chip_info bmp180_chip_info; 535 500 extern const struct bmp280_chip_info bmp280_chip_info; 536 501 extern const struct bmp280_chip_info bme280_chip_info;
+1 -1
drivers/iio/proximity/aw96103.c
··· 422 422 static int aw96103_write_event_config(struct iio_dev *indio_dev, 423 423 const struct iio_chan_spec *chan, 424 424 enum iio_event_type type, 425 - enum iio_event_direction dir, int state) 425 + enum iio_event_direction dir, bool state) 426 426 { 427 427 struct aw96103 *aw96103 = iio_priv(indio_dev); 428 428
+1 -1
drivers/iio/proximity/cros_ec_mkbp_proximity.c
··· 167 167 static int cros_ec_mkbp_proximity_write_event_config(struct iio_dev *indio_dev, 168 168 const struct iio_chan_spec *chan, 169 169 enum iio_event_type type, 170 - enum iio_event_direction dir, int state) 170 + enum iio_event_direction dir, bool state) 171 171 { 172 172 struct cros_ec_mkbp_proximity_data *data = iio_priv(indio_dev); 173 173
+2 -2
drivers/iio/proximity/hx9023s.c
··· 874 874 const struct iio_chan_spec *chan, 875 875 enum iio_event_type type, 876 876 enum iio_event_direction dir, 877 - int state) 877 + bool state) 878 878 { 879 879 struct hx9023s_data *data = iio_priv(indio_dev); 880 880 881 881 if (test_bit(chan->channel, &data->chan_in_use)) { 882 - hx9023s_ch_en(data, chan->channel, !!state); 882 + hx9023s_ch_en(data, chan->channel, state); 883 883 __assign_bit(chan->channel, &data->chan_event, 884 884 data->ch_data[chan->channel].enable); 885 885 }
+3 -2
drivers/iio/proximity/irsd200.c
··· 648 648 static int irsd200_write_event_config(struct iio_dev *indio_dev, 649 649 const struct iio_chan_spec *chan, 650 650 enum iio_event_type type, 651 - enum iio_event_direction dir, int state) 651 + enum iio_event_direction dir, 652 + bool state) 652 653 { 653 654 struct irsd200_data *data = iio_priv(indio_dev); 654 655 unsigned int tmp; ··· 663 662 return ret; 664 663 665 664 return regmap_field_write( 666 - data->regfields[IRS_REGF_INTR_COUNT_THR_OR], !!state); 665 + data->regfields[IRS_REGF_INTR_COUNT_THR_OR], state); 667 666 default: 668 667 return -EINVAL; 669 668 }
+3 -3
drivers/iio/proximity/sx9500.c
··· 540 540 const struct iio_chan_spec *chan, 541 541 enum iio_event_type type, 542 542 enum iio_event_direction dir, 543 - int state) 543 + bool state) 544 544 { 545 545 struct sx9500_data *data = iio_priv(indio_dev); 546 546 int ret; ··· 551 551 552 552 mutex_lock(&data->mutex); 553 553 554 - if (state == 1) { 554 + if (state) { 555 555 ret = sx9500_inc_chan_users(data, chan->channel); 556 556 if (ret < 0) 557 557 goto out_unlock; ··· 571 571 goto out_unlock; 572 572 573 573 out_undo_chan: 574 - if (state == 1) 574 + if (state) 575 575 sx9500_dec_chan_users(data, chan->channel); 576 576 else 577 577 sx9500_inc_chan_users(data, chan->channel);
+1 -1
drivers/iio/proximity/sx_common.c
··· 268 268 int sx_common_write_event_config(struct iio_dev *indio_dev, 269 269 const struct iio_chan_spec *chan, 270 270 enum iio_event_type type, 271 - enum iio_event_direction dir, int state) 271 + enum iio_event_direction dir, bool state) 272 272 { 273 273 struct sx_common_data *data = iio_priv(indio_dev); 274 274 unsigned int eventirq = SX_COMMON_FAR_IRQ | SX_COMMON_CLOSE_IRQ;
+1 -1
drivers/iio/proximity/sx_common.h
··· 143 143 int sx_common_write_event_config(struct iio_dev *indio_dev, 144 144 const struct iio_chan_spec *chan, 145 145 enum iio_event_type type, 146 - enum iio_event_direction dir, int state); 146 + enum iio_event_direction dir, bool state); 147 147 148 148 int sx_common_probe(struct i2c_client *client, 149 149 const struct sx_common_chip_info *chip_info,
+1 -1
drivers/iio/proximity/vcnl3020.c
··· 449 449 const struct iio_chan_spec *chan, 450 450 enum iio_event_type type, 451 451 enum iio_event_direction dir, 452 - int state) 452 + bool state) 453 453 { 454 454 switch (chan->type) { 455 455 case IIO_PROXIMITY:
+1 -1
drivers/iio/temperature/mcp9600.c
··· 200 200 const struct iio_chan_spec *chan, 201 201 enum iio_event_type type, 202 202 enum iio_event_direction dir, 203 - int state) 203 + bool state) 204 204 { 205 205 struct mcp9600_data *data = iio_priv(indio_dev); 206 206 struct i2c_client *client = data->client;
+1 -1
drivers/iio/temperature/tmp007.c
··· 216 216 217 217 static int tmp007_write_event_config(struct iio_dev *indio_dev, 218 218 const struct iio_chan_spec *chan, enum iio_event_type type, 219 - enum iio_event_direction dir, int state) 219 + enum iio_event_direction dir, bool state) 220 220 { 221 221 struct tmp007_data *data = iio_priv(indio_dev); 222 222 unsigned int status_mask;
+2
include/linux/hid-sensor-ids.h
··· 30 30 #define HID_USAGE_SENSOR_PROX 0x200011 31 31 #define HID_USAGE_SENSOR_DATA_PRESENCE 0x2004b0 32 32 #define HID_USAGE_SENSOR_HUMAN_PRESENCE 0x2004b1 33 + #define HID_USAGE_SENSOR_HUMAN_PROXIMITY 0x2004b2 34 + #define HID_USAGE_SENSOR_HUMAN_ATTENTION 0x2004bd 33 35 34 36 /* Pressure (200031) */ 35 37 #define HID_USAGE_SENSOR_PRESSURE 0x200031
+17
include/linux/iio/backend.h
··· 14 14 enum iio_backend_data_type { 15 15 IIO_BACKEND_TWOS_COMPLEMENT, 16 16 IIO_BACKEND_OFFSET_BINARY, 17 + IIO_BACKEND_DATA_UNSIGNED, 17 18 IIO_BACKEND_DATA_TYPE_MAX 18 19 }; 19 20 20 21 enum iio_backend_data_source { 21 22 IIO_BACKEND_INTERNAL_CONTINUOUS_WAVE, 22 23 IIO_BACKEND_EXTERNAL, 24 + IIO_BACKEND_INTERNAL_RAMP_16BIT, 23 25 IIO_BACKEND_DATA_SOURCE_MAX 24 26 }; 25 27 ··· 91 89 * @read_raw: Read a channel attribute from a backend device 92 90 * @debugfs_print_chan_status: Print channel status into a buffer. 93 91 * @debugfs_reg_access: Read or write register value of backend. 92 + * @ddr_enable: Enable interface DDR (Double Data Rate) mode. 93 + * @ddr_disable: Disable interface DDR (Double Data Rate) mode. 94 + * @data_stream_enable: Enable data stream. 95 + * @data_stream_disable: Disable data stream. 96 + * @data_transfer_addr: Set data address. 94 97 **/ 95 98 struct iio_backend_ops { 96 99 int (*enable)(struct iio_backend *back); ··· 136 129 size_t len); 137 130 int (*debugfs_reg_access)(struct iio_backend *back, unsigned int reg, 138 131 unsigned int writeval, unsigned int *readval); 132 + int (*ddr_enable)(struct iio_backend *back); 133 + int (*ddr_disable)(struct iio_backend *back); 134 + int (*data_stream_enable)(struct iio_backend *back); 135 + int (*data_stream_disable)(struct iio_backend *back); 136 + int (*data_transfer_addr)(struct iio_backend *back, u32 address); 139 137 }; 140 138 141 139 /** ··· 176 164 int devm_iio_backend_request_buffer(struct device *dev, 177 165 struct iio_backend *back, 178 166 struct iio_dev *indio_dev); 167 + int iio_backend_ddr_enable(struct iio_backend *back); 168 + int iio_backend_ddr_disable(struct iio_backend *back); 169 + int iio_backend_data_stream_enable(struct iio_backend *back); 170 + int iio_backend_data_stream_disable(struct iio_backend *back); 171 + int iio_backend_data_transfer_addr(struct iio_backend *back, u32 address); 179 172 ssize_t iio_backend_ext_info_set(struct iio_dev *indio_dev, uintptr_t private, 180 173 const struct iio_chan_spec *chan, 181 174 const char *buf, size_t len);
+24 -7
include/linux/iio/events.h
··· 10 10 #include <uapi/linux/iio/events.h> 11 11 12 12 /** 13 - * IIO_EVENT_CODE() - create event identifier 13 + * _IIO_EVENT_CODE() - create event identifier 14 14 * @chan_type: Type of the channel. Should be one of enum iio_chan_type. 15 15 * @diff: Whether the event is for an differential channel or not. 16 16 * @modifier: Modifier for the channel. Should be one of enum iio_modifier. ··· 19 19 * @chan: Channel number for non-differential channels. 20 20 * @chan1: First channel number for differential channels. 21 21 * @chan2: Second channel number for differential channels. 22 + * 23 + * Drivers should use the specialized macros below instead of using this one 24 + * directly. 22 25 */ 23 26 24 - #define IIO_EVENT_CODE(chan_type, diff, modifier, direction, \ 25 - type, chan, chan1, chan2) \ 27 + #define _IIO_EVENT_CODE(chan_type, diff, modifier, direction, \ 28 + type, chan, chan1, chan2) \ 26 29 (((u64)type << 56) | ((u64)diff << 55) | \ 27 30 ((u64)direction << 48) | ((u64)modifier << 40) | \ 28 31 ((u64)chan_type << 32) | (((u16)chan2) << 16) | ((u16)chan1) | \ ··· 33 30 34 31 35 32 /** 36 - * IIO_MOD_EVENT_CODE() - create event identifier for modified channels 33 + * IIO_MOD_EVENT_CODE() - create event identifier for modified (non 34 + * differential) channels 37 35 * @chan_type: Type of the channel. Should be one of enum iio_chan_type. 38 36 * @number: Channel number. 39 37 * @modifier: Modifier for the channel. Should be one of enum iio_modifier. ··· 44 40 45 41 #define IIO_MOD_EVENT_CODE(chan_type, number, modifier, \ 46 42 type, direction) \ 47 - IIO_EVENT_CODE(chan_type, 0, modifier, direction, type, number, 0, 0) 43 + _IIO_EVENT_CODE(chan_type, 0, modifier, direction, type, number, 0, 0) 48 44 49 45 /** 50 - * IIO_UNMOD_EVENT_CODE() - create event identifier for unmodified channels 46 + * IIO_UNMOD_EVENT_CODE() - create event identifier for unmodified (non 47 + * differential) channels 51 48 * @chan_type: Type of the channel. Should be one of enum iio_chan_type. 52 49 * @number: Channel number. 53 50 * @type: Type of the event. Should be one of enum iio_event_type. ··· 56 51 */ 57 52 58 53 #define IIO_UNMOD_EVENT_CODE(chan_type, number, type, direction) \ 59 - IIO_EVENT_CODE(chan_type, 0, 0, direction, type, number, 0, 0) 54 + _IIO_EVENT_CODE(chan_type, 0, 0, direction, type, number, 0, 0) 55 + 56 + /** 57 + * IIO_DIFF_EVENT_CODE() - create event identifier for differential channels 58 + * @chan_type: Type of the channel. Should be one of enum iio_chan_type. 59 + * @chan1: First channel number for differential channels. 60 + * @chan2: Second channel number for differential channels. 61 + * @type: Type of the event. Should be one of enum iio_event_type. 62 + * @direction: Direction of the event. One of enum iio_event_direction. 63 + */ 64 + 65 + #define IIO_DIFF_EVENT_CODE(chan_type, chan1, chan2, type, direction) \ 66 + _IIO_EVENT_CODE(chan_type, 1, 0, direction, type, 0, chan1, chan2) 60 67 61 68 #endif
+13 -3
include/linux/iio/iio.h
··· 514 514 const struct iio_chan_spec *chan, 515 515 enum iio_event_type type, 516 516 enum iio_event_direction dir, 517 - int state); 517 + bool state); 518 518 519 519 int (*read_event_value)(struct iio_dev *indio_dev, 520 520 const struct iio_chan_spec *chan, ··· 624 624 const struct iio_info *info; 625 625 const struct iio_buffer_setup_ops *setup_ops; 626 626 627 - void *priv; 627 + void *__private priv; 628 628 }; 629 629 630 630 int iio_device_id(struct iio_dev *indio_dev); ··· 785 785 /* The information at the returned address is guaranteed to be cacheline aligned */ 786 786 static inline void *iio_priv(const struct iio_dev *indio_dev) 787 787 { 788 - return indio_dev->priv; 788 + return ACCESS_PRIVATE(indio_dev, priv); 789 789 } 790 790 791 791 void iio_device_free(struct iio_dev *indio_dev); ··· 831 831 bool iio_read_acpi_mount_matrix(struct device *dev, 832 832 struct iio_mount_matrix *orientation, 833 833 char *acpi_method); 834 + const char *iio_get_acpi_device_name_and_data(struct device *dev, const void **data); 834 835 #else 835 836 static inline bool iio_read_acpi_mount_matrix(struct device *dev, 836 837 struct iio_mount_matrix *orientation, ··· 839 838 { 840 839 return false; 841 840 } 841 + static inline const char * 842 + iio_get_acpi_device_name_and_data(struct device *dev, const void **data) 843 + { 844 + return NULL; 845 + } 842 846 #endif 847 + static inline const char *iio_get_acpi_device_name(struct device *dev) 848 + { 849 + return iio_get_acpi_device_name_and_data(dev, NULL); 850 + } 843 851 844 852 /** 845 853 * iio_get_current_scan_type - Get the current scan type for a channel
+1
include/uapi/linux/iio/types.h
··· 51 51 IIO_DELTA_VELOCITY, 52 52 IIO_COLORTEMP, 53 53 IIO_CHROMATICITY, 54 + IIO_ATTENTION, 54 55 }; 55 56 56 57 enum iio_modifier {
+2
tools/iio/iio_event_monitor.c
··· 63 63 [IIO_DELTA_VELOCITY] = "deltavelocity", 64 64 [IIO_COLORTEMP] = "colortemp", 65 65 [IIO_CHROMATICITY] = "chromaticity", 66 + [IIO_ATTENTION] = "attention", 66 67 }; 67 68 68 69 static const char * const iio_ev_type_text[] = { ··· 184 183 case IIO_DELTA_VELOCITY: 185 184 case IIO_COLORTEMP: 186 185 case IIO_CHROMATICITY: 186 + case IIO_ATTENTION: 187 187 break; 188 188 default: 189 189 return false;