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

Merge tag 'iio-for-6.2a-take2' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-next

Jonathan writes:

1st set of IIO new device support, feature and cleanup for 6.2 (take2)

We have finally managed to take the mlock mutex entirely private so as
to avoid it being used for multiple purposes. Now it is just used to
protect device mode transitions (typically to and from buffered capture).

Includes merge of an immutable i2c branch to get the new
i2c_client_get_device_id() (thanks to Wolfram for providing the branch).

Based on rc3 to pick up some precursor fixes from early in the cycle and
avoid an unnecessarily messy history.

New device support
* adi,ad4310
- New driver to support this very flexible measurement device including
a 24 bit ADC. Later fix for documentation build issue.
* adi,adxl355
- Add support of the ADXL359 accelerometer.
* adi,ltc2983
- Support additional variants of the temperatures sensor:
LTC2984 with an EEPROM
LTC2985, LTC2986 with only 10 channels.
* invensense,icm42600
- Add support for icm42631 (needed only ID and WHOAMI)
* kionix,kx022a
- New driver for this 3 axis accelerometer.
* maxim,max11401
- New driver to support this 24-bit 10 channel ADC.
Includes some new ABI to support configuration of notch filters.
* mediatek,mt6370
- Add new driver to support the ADC part of the mt6370.
* st,lsm6dsx
- Add support for LSM6DSV accelerometer and gyroscope. Simple additional
of chip specific data and IDs.
- Add support for LSM6DSV16X accelerometer and gyroscope. Compatible with
features currently implemented for the LSM6DSV.
* st,stm32-adc
- Add support for stm32pm13x SoCs.

core / subsystem wide:
- Add new IIO_STATIC_CONST_DEVICE_ATTR() which is a dance necessary to
allow for the wrapping of attributes in the code that duplicates them
for multiple buffers.
- Harden against future issues with expectation that all buffer attributes
are iio_dev_attrs by changing the code to take an array of pointers
of the correct type.
- Last transitions of drivers to local locks rather than missuses of mlock.
- Add an iio_device_claim_buffer_mode() callback to avoid a race in the
max30100 driver without directly using mlock.
- Move mlock to the opaque IIO device structure to prevent misuse.
- Add missing spi_device_id tables to support auto loading of modules.
- Update some ADI maintainers in DT bindings.
- A few more moves of bus drivers and core module sets to export
name spaces.
- Extensive use of new devm_regulator_get_enable() and friends.
- Switch a bunch of i2c drivers to probe_new() including the bmp280
which makes use of the new i2c_client_get_device_id() helper to
simplify this change.

dt-bindings:
- More use of spi-peripheral-props.yaml.

Features
* freescale,mpl115
- Use runtime PM to implement shutdown GPIO support.
* melexis,mlx90632
- More sophisticated runtime power management
- Provide access to sampling frequency.
- Trivial follow up fixes.
* microchip,mcp3911
- Support control of PGA.
* st,lsm6dsx
- Add support for software triggers for cases where the IRQ lines
are not wired up.
* vishay,vcnl4000
- Add control of integration time.

Minor cleanups and fixes
* adi,ad4130
- Improve ABI documentation formatting.
- Kconfig dependency fixup.
* adi,ad5758
- Minor dt binding fix.
* adi,ad9834
- Tidy up line breaks.
* adi,ade7854
- Minor improvement in code clarity by replacing a ternary.
* adi,admv8818
- Harden code against hardware returning wrong values.
* adi,adxl355
- Warn only if unknown device ID detected to allow for fall back
device tree compatibles on future devices.
* adi,ltc2983
- dt-bindings clarifications and general improvements.
- Ensure DMA safe buffer for bulk writes without relying on current
regmap implementation choices.
* avago,adps9960
- Fix up a disconnect between event enable attributes and what was
enabled.
* bosch,bma400
- Switch to dev_err_probe() from open coded EPROBE_DEFER handling.
* cosmic,cc10001
- Fully devm managed probe() and related tidying up.
* meas,ms5611
- Add an example of spi-max-frequency.
* meleixs,mlx90632
- Tidy up confusing error return value.
- Style improvements.
* multiplexer
- Switch to dev_err_probe() from open coded EPROBE_DEFER handling.
* qcom,spmi-vadc
- Minor dt binding improvements.
* rockchip,saradc
- Add ID for rv1126.
* semtech,sx9360
- Add SAMM0208 ACPI ID. Doesn't appear to be a valid vendor prefix
but is in the wild.
* st,lsm6dsx
- Factor out common code as _device_set_enable().
- Fix up wrong docs after LSM6DSV addition.
* st,stm32-adc
- Manage the min sampling time on all internal channels.
* trig,sysfs
- Improve error labels.

* tag 'iio-for-6.2a-take2' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (146 commits)
iio: pressure: bmp280: convert to i2c's .probe_new()
iio: imu: st_lsm6dsx: fix LSM6DSV sensor description
iio: adc: ad4130: depend on GPIOLIB
staging: iio: meter: replace ternary operator by if condition
iio: light: apds9960: Fix iio_event_spec structures
dt-bindings: iio: imu: Add inv_icm42600 documentation
iio: imu: inv_icm42600: Add support for icm42631
dt-bindings: iio: adc: rockchip-saradc: Add saradc for rv1126
dt-bindings: iio: dac: adi,ad5758: Drop 'contains' from 'adi,dc-dc-mode'
dt-bindings: iio: imu: st_lsm6dsx: add lsm6dsv16x
iio: imu: st_lsm6dsx: add support to LSM6DSV16X
iio: proximity: sx9360: Add a new ACPI hardware ID
iio: temperature: mlx90632: Add missing static marking on devm_pm_ops
iio: temperature: mlx90632: Add error handling for devm_pm_runtime_enable()
iio: temperature: ltc2983: support more parts
dt-bindings: iio: temperature: ltc2983: support more parts
dt-bindings: iio: temperature: ltc2983: use generic node name in example
dt-bindings: iio: temperature: ltc2983: describe broken mux delay property
dt-bindings: iio: temperature: ltc2983: refine descriptions
dt-bindings: iio: temperature: ltc2983: change default excitation for custom thermistors
...

+8081 -1305
+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.
+13
Documentation/ABI/testing/sysfs-bus-iio-adc-max11410
··· 1 + What: /sys/bus/iio/devices/iio:deviceX/in_voltage_filterY_notch_en 2 + Date: September 2022 3 + KernelVersion: 6.0 4 + Contact: linux-iio@vger.kernel.org 5 + Description: 6 + Enable or disable a notch filter. 7 + 8 + What: /sys/bus/iio/devices/iio:deviceX/in_voltage_filterY_notch_center 9 + Date: September 2022 10 + KernelVersion: 6.0 11 + Contact: linux-iio@vger.kernel.org 12 + Description: 13 + Center frequency of the notch filter in Hz.
+5 -3
Documentation/devicetree/bindings/iio/accel/adi,adxl355.yaml
··· 4 4 $id: http://devicetree.org/schemas/iio/accel/adi,adxl355.yaml# 5 5 $schema: http://devicetree.org/meta-schemas/core.yaml# 6 6 7 - title: Analog Devices ADXL355 3-Axis, Low noise MEMS Accelerometer 7 + title: Analog Devices ADXL355 and ADXL359 3-Axis, Low noise MEMS Accelerometers 8 8 9 9 maintainers: 10 10 - Puranjay Mohan <puranjay12@gmail.com> 11 11 12 12 description: | 13 - Analog Devices ADXL355 3-Axis, Low noise MEMS Accelerometer that supports 14 - both I2C & SPI interfaces 13 + Analog Devices ADXL355 and ADXL359 3-Axis, Low noise MEMS Accelerometers that 14 + support both I2C & SPI interfaces 15 15 https://www.analog.com/en/products/adxl355.html 16 + https://www.analog.com/en/products/adxl359.html 16 17 17 18 properties: 18 19 compatible: 19 20 enum: 20 21 - adi,adxl355 22 + - adi,adxl359 21 23 22 24 reg: 23 25 maxItems: 1
+65
Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/accel/kionix,kx022a.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: ROHM/Kionix KX022A Accelerometer 8 + 9 + maintainers: 10 + - Matti Vaittinen <mazziesaccount@gmail.com> 11 + 12 + description: | 13 + KX022A is a 3-axis accelerometer supporting +/- 2G, 4G, 8G and 16G ranges, 14 + output data-rates from 0.78Hz to 1600Hz and a hardware-fifo buffering. 15 + KX022A can be accessed either via I2C or SPI. 16 + 17 + properties: 18 + compatible: 19 + const: kionix,kx022a 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + interrupts: 25 + minItems: 1 26 + maxItems: 2 27 + 28 + interrupt-names: 29 + minItems: 1 30 + items: 31 + - enum: [INT1, INT2] 32 + - const: INT2 33 + 34 + vdd-supply: true 35 + io-vdd-supply: true 36 + 37 + mount-matrix: 38 + description: | 39 + an optional 3x3 mounting rotation matrix. 40 + 41 + required: 42 + - compatible 43 + - reg 44 + - interrupts 45 + 46 + additionalProperties: false 47 + 48 + examples: 49 + - | 50 + #include <dt-bindings/interrupt-controller/irq.h> 51 + i2c { 52 + #address-cells = <1>; 53 + #size-cells = <0>; 54 + accel@1f { 55 + compatible = "kionix,kx022a"; 56 + reg = <0x1f>; 57 + 58 + interrupt-parent = <&gpio1>; 59 + interrupts = <29 IRQ_TYPE_LEVEL_LOW>; 60 + interrupt-names = "INT1"; 61 + 62 + io-vdd-supply = <&iovdd>; 63 + vdd-supply = <&vdd>; 64 + }; 65 + };
+259
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + # Copyright 2022 Analog Devices Inc. 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/iio/adc/adi,ad4130.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: Analog Devices AD4130 ADC device driver 9 + 10 + maintainers: 11 + - Cosmin Tanislav <cosmin.tanislav@analog.com> 12 + 13 + description: | 14 + Bindings for the Analog Devices AD4130 ADC. Datasheet can be found here: 15 + https://www.analog.com/media/en/technical-documentation/data-sheets/AD4130-8.pdf 16 + 17 + properties: 18 + compatible: 19 + enum: 20 + - adi,ad4130 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + clocks: 26 + maxItems: 1 27 + description: phandle to the master clock (mclk) 28 + 29 + clock-names: 30 + items: 31 + - const: mclk 32 + 33 + interrupts: 34 + maxItems: 1 35 + 36 + interrupt-names: 37 + description: | 38 + Specify which interrupt pin should be configured as Data Ready / FIFO 39 + interrupt. 40 + Default if not supplied is int. 41 + enum: 42 + - int 43 + - clk 44 + - p2 45 + - dout 46 + 47 + '#address-cells': 48 + const: 1 49 + 50 + '#size-cells': 51 + const: 0 52 + 53 + '#clock-cells': 54 + const: 0 55 + 56 + clock-output-names: 57 + maxItems: 1 58 + 59 + refin1-supply: 60 + description: refin1 supply. Can be used as reference for conversion. 61 + 62 + refin2-supply: 63 + description: refin2 supply. Can be used as reference for conversion. 64 + 65 + avdd-supply: 66 + description: AVDD voltage supply. Can be used as reference for conversion. 67 + 68 + iovdd-supply: 69 + description: IOVDD voltage supply. Used for the chip interface. 70 + 71 + spi-max-frequency: 72 + maximum: 5000000 73 + 74 + adi,ext-clk-freq-hz: 75 + description: Specify the frequency of the external clock. 76 + enum: [76800, 153600] 77 + default: 76800 78 + 79 + adi,bipolar: 80 + description: Specify if the device should be used in bipolar mode. 81 + type: boolean 82 + 83 + adi,vbias-pins: 84 + description: Analog inputs to apply a voltage bias of (AVDD − AVSS) / 2 to. 85 + $ref: /schemas/types.yaml#/definitions/uint32-array 86 + minItems: 1 87 + maxItems: 16 88 + items: 89 + minimum: 0 90 + maximum: 15 91 + 92 + required: 93 + - compatible 94 + - reg 95 + - interrupts 96 + 97 + patternProperties: 98 + "^channel@([0-9a-f])$": 99 + type: object 100 + $ref: adc.yaml 101 + unevaluatedProperties: false 102 + 103 + properties: 104 + reg: 105 + description: The channel number. 106 + minimum: 0 107 + maximum: 15 108 + 109 + diff-channels: 110 + description: | 111 + Besides the analog inputs available, internal inputs can be used. 112 + 16: Internal temperature sensor. 113 + 17: AVSS 114 + 18: Internal reference 115 + 19: DGND 116 + 20: (AVDD − AVSS)/6+ 117 + 21: (AVDD − AVSS)/6- 118 + 22: (IOVDD − DGND)/6+ 119 + 23: (IOVDD − DGND)/6- 120 + 24: (ALDO − AVSS)/6+ 121 + 25: (ALDO − AVSS)/6- 122 + 26: (DLDO − DGND)/6+ 123 + 27: (DLDO − DGND)/6- 124 + 28: V_MV_P 125 + 29: V_MV_M 126 + items: 127 + minimum: 0 128 + maximum: 29 129 + 130 + adi,reference-select: 131 + description: | 132 + Select the reference source to use when converting on the 133 + specific channel. Valid values are: 134 + 0: REFIN1(+)/REFIN1(−) 135 + 1: REFIN2(+)/REFIN2(−) 136 + 2: REFOUT/AVSS (Internal reference) 137 + 3: AVDD/AVSS 138 + If not specified, REFIN1 is used. 139 + $ref: /schemas/types.yaml#/definitions/uint32 140 + enum: [0, 1, 2, 3] 141 + default: 0 142 + 143 + adi,excitation-pin-0: 144 + description: | 145 + Analog input to apply excitation current to while the channel 146 + is active. 147 + $ref: /schemas/types.yaml#/definitions/uint32 148 + minimum: 0 149 + maximum: 15 150 + default: 0 151 + 152 + adi,excitation-pin-1: 153 + description: | 154 + Analog input to apply excitation current to while this channel 155 + is active. 156 + $ref: /schemas/types.yaml#/definitions/uint32 157 + minimum: 0 158 + maximum: 15 159 + default: 0 160 + 161 + adi,excitation-current-0-nanoamp: 162 + description: | 163 + Excitation current in nanoamps to be applied to pin specified in 164 + adi,excitation-pin-0 while this channel is active. 165 + enum: [0, 100, 10000, 20000, 50000, 100000, 150000, 200000] 166 + default: 0 167 + 168 + adi,excitation-current-1-nanoamp: 169 + description: | 170 + Excitation current in nanoamps to be applied to pin specified in 171 + adi,excitation-pin-1 while this channel is active. 172 + enum: [0, 100, 10000, 20000, 50000, 100000, 150000, 200000] 173 + default: 0 174 + 175 + adi,burnout-current-nanoamp: 176 + description: | 177 + Burnout current in nanoamps to be applied for this channel. 178 + enum: [0, 500, 2000, 4000] 179 + default: 0 180 + 181 + adi,buffered-positive: 182 + description: Enable buffered mode for positive input. 183 + type: boolean 184 + 185 + adi,buffered-negative: 186 + description: Enable buffered mode for negative input. 187 + type: boolean 188 + 189 + required: 190 + - reg 191 + - diff-channels 192 + 193 + additionalProperties: false 194 + 195 + examples: 196 + - | 197 + #include <dt-bindings/interrupt-controller/irq.h> 198 + 199 + spi { 200 + #address-cells = <1>; 201 + #size-cells = <0>; 202 + 203 + adc@0 { 204 + compatible = "adi,ad4130"; 205 + reg = <0>; 206 + 207 + #address-cells = <1>; 208 + #size-cells = <0>; 209 + 210 + spi-max-frequency = <5000000>; 211 + interrupts = <27 IRQ_TYPE_EDGE_FALLING>; 212 + interrupt-parent = <&gpio>; 213 + 214 + channel@0 { 215 + reg = <0>; 216 + 217 + adi,reference-select = <2>; 218 + 219 + /* AIN8, AIN9 */ 220 + diff-channels = <8 9>; 221 + }; 222 + 223 + channel@1 { 224 + reg = <1>; 225 + 226 + adi,reference-select = <2>; 227 + 228 + /* AIN10, AIN11 */ 229 + diff-channels = <10 11>; 230 + }; 231 + 232 + channel@2 { 233 + reg = <2>; 234 + 235 + adi,reference-select = <2>; 236 + 237 + /* Temperature Sensor, DGND */ 238 + diff-channels = <16 19>; 239 + }; 240 + 241 + channel@3 { 242 + reg = <3>; 243 + 244 + adi,reference-select = <2>; 245 + 246 + /* Internal reference, DGND */ 247 + diff-channels = <18 19>; 248 + }; 249 + 250 + channel@4 { 251 + reg = <4>; 252 + 253 + adi,reference-select = <2>; 254 + 255 + /* DGND, DGND */ 256 + diff-channels = <19 19>; 257 + }; 258 + }; 259 + };
+177
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + # Copyright 2022 Analog Devices Inc. 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/iio/adc/adi,max11410.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: Analog Devices MAX11410 ADC device driver 9 + 10 + maintainers: 11 + - Ibrahim Tilki <Ibrahim.Tilki@analog.com> 12 + 13 + description: | 14 + Bindings for the Analog Devices MAX11410 ADC device. Datasheet can be 15 + found here: 16 + https://datasheets.maximintegrated.com/en/ds/MAX11410.pdf 17 + 18 + properties: 19 + compatible: 20 + enum: 21 + - adi,max11410 22 + 23 + reg: 24 + maxItems: 1 25 + 26 + interrupts: 27 + minItems: 1 28 + maxItems: 2 29 + 30 + interrupt-names: 31 + description: Name of the gpio pin of max11410 used for IRQ 32 + minItems: 1 33 + items: 34 + - enum: [gpio0, gpio1] 35 + - const: gpio1 36 + 37 + '#address-cells': 38 + const: 1 39 + 40 + '#size-cells': 41 + const: 0 42 + 43 + avdd-supply: 44 + description: Optional avdd supply. Used as reference when no explicit reference supplied. 45 + 46 + vref0p-supply: 47 + description: vref0p supply can be used as reference for conversion. 48 + 49 + vref1p-supply: 50 + description: vref1p supply can be used as reference for conversion. 51 + 52 + vref2p-supply: 53 + description: vref2p supply can be used as reference for conversion. 54 + 55 + vref0n-supply: 56 + description: vref0n supply can be used as reference for conversion. 57 + 58 + vref1n-supply: 59 + description: vref1n supply can be used as reference for conversion. 60 + 61 + vref2n-supply: 62 + description: vref2n supply can be used as reference for conversion. 63 + 64 + spi-max-frequency: 65 + maximum: 8000000 66 + 67 + patternProperties: 68 + "^channel(@[0-9])?$": 69 + $ref: adc.yaml 70 + type: object 71 + description: Represents the external channels which are connected to the ADC. 72 + 73 + properties: 74 + reg: 75 + description: The channel number in single-ended mode. 76 + minimum: 0 77 + maximum: 9 78 + 79 + adi,reference: 80 + description: | 81 + Select the reference source to use when converting on 82 + the specific channel. Valid values are: 83 + 0: VREF0P/VREF0N 84 + 1: VREF1P/VREF1N 85 + 2: VREF2P/VREF2N 86 + 3: AVDD/AGND 87 + 4: VREF0P/AGND 88 + 5: VREF1P/AGND 89 + 6: VREF2P/AGND 90 + If this field is left empty, AVDD/AGND is selected. 91 + $ref: /schemas/types.yaml#/definitions/uint32 92 + enum: [0, 1, 2, 3, 4, 5, 6] 93 + default: 3 94 + 95 + adi,input-mode: 96 + description: | 97 + Select signal path of input channels. Valid values are: 98 + 0: Buffered, low-power, unity-gain path (default) 99 + 1: Bypass path 100 + 2: PGA path 101 + $ref: /schemas/types.yaml#/definitions/uint32 102 + enum: [0, 1, 2] 103 + default: 0 104 + 105 + diff-channels: true 106 + 107 + bipolar: true 108 + 109 + settling-time-us: true 110 + 111 + adi,buffered-vrefp: 112 + description: Enable buffered mode for positive reference. 113 + type: boolean 114 + 115 + adi,buffered-vrefn: 116 + description: Enable buffered mode for negative reference. 117 + type: boolean 118 + 119 + required: 120 + - reg 121 + 122 + additionalProperties: false 123 + 124 + required: 125 + - compatible 126 + - reg 127 + 128 + allOf: 129 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 130 + 131 + unevaluatedProperties: false 132 + 133 + examples: 134 + - | 135 + #include <dt-bindings/interrupt-controller/irq.h> 136 + spi { 137 + #address-cells = <1>; 138 + #size-cells = <0>; 139 + 140 + adc@0 { 141 + reg = <0>; 142 + compatible = "adi,max11410"; 143 + spi-max-frequency = <8000000>; 144 + 145 + interrupt-parent = <&gpio>; 146 + interrupts = <25 IRQ_TYPE_EDGE_FALLING>; 147 + interrupt-names = "gpio1"; 148 + 149 + avdd-supply = <&adc_avdd>; 150 + 151 + vref1p-supply = <&adc_vref1p>; 152 + vref1n-supply = <&adc_vref1n>; 153 + 154 + #address-cells = <1>; 155 + #size-cells = <0>; 156 + 157 + channel@0 { 158 + reg = <0>; 159 + }; 160 + 161 + channel@1 { 162 + reg = <1>; 163 + diff-channels = <2 3>; 164 + adi,reference = <1>; 165 + bipolar; 166 + settling-time-us = <100000>; 167 + }; 168 + 169 + channel@2 { 170 + reg = <2>; 171 + diff-channels = <7 9>; 172 + adi,reference = <5>; 173 + adi,input-mode = <2>; 174 + settling-time-us = <50000>; 175 + }; 176 + }; 177 + };
+65 -37
Documentation/devicetree/bindings/iio/adc/qcom,spmi-vadc.yaml
··· 22 22 - items: 23 23 - const: qcom,pms405-adc 24 24 - const: qcom,spmi-adc-rev2 25 - 26 - - items: 27 - - enum: 28 - - qcom,spmi-vadc 29 - - qcom,spmi-adc5 30 - - qcom,spmi-adc-rev2 31 - - qcom,spmi-adc7 25 + - enum: 26 + - qcom,spmi-vadc 27 + - qcom,spmi-adc5 28 + - qcom,spmi-adc-rev2 29 + - qcom,spmi-adc7 32 30 33 31 reg: 34 32 description: VADC base address in the SPMI PMIC register map ··· 236 238 237 239 examples: 238 240 - | 239 - spmi_bus { 240 - #address-cells = <1>; 241 - #size-cells = <0>; 242 - /* VADC node */ 243 - pmic_vadc: adc@3100 { 244 - compatible = "qcom,spmi-vadc"; 245 - reg = <0x3100>; 246 - interrupts = <0x0 0x31 0x0 0x1>; 241 + spmi { 247 242 #address-cells = <1>; 248 243 #size-cells = <0>; 249 - #io-channel-cells = <1>; 244 + /* VADC node */ 245 + pmic_vadc: adc@3100 { 246 + compatible = "qcom,spmi-vadc"; 247 + reg = <0x3100>; 248 + interrupts = <0x0 0x31 0x0 0x1>; 249 + #address-cells = <1>; 250 + #size-cells = <0>; 251 + #io-channel-cells = <1>; 250 252 251 - /* Channel node */ 252 - adc-chan@39 { 253 - reg = <0x39>; 254 - qcom,decimation = <512>; 255 - qcom,ratiometric; 256 - qcom,hw-settle-time = <200>; 257 - qcom,avg-samples = <1>; 258 - qcom,pre-scaling = <1 3>; 259 - }; 253 + /* Channel node */ 254 + adc-chan@39 { 255 + reg = <0x39>; 256 + qcom,decimation = <512>; 257 + qcom,ratiometric; 258 + qcom,hw-settle-time = <200>; 259 + qcom,avg-samples = <1>; 260 + qcom,pre-scaling = <1 3>; 261 + }; 260 262 261 - adc-chan@9 { 262 - reg = <0x9>; 263 - }; 263 + adc-chan@9 { 264 + reg = <0x9>; 265 + }; 264 266 265 - adc-chan@a { 266 - reg = <0xa>; 267 - }; 267 + adc-chan@a { 268 + reg = <0xa>; 269 + }; 268 270 269 - adc-chan@e { 270 - reg = <0xe>; 271 - }; 271 + adc-chan@e { 272 + reg = <0xe>; 273 + }; 272 274 273 - adc-chan@f { 274 - reg = <0xf>; 275 + adc-chan@f { 276 + reg = <0xf>; 277 + }; 275 278 }; 276 - }; 279 + }; 280 + 281 + - | 282 + #include <dt-bindings/iio/qcom,spmi-adc7-pmk8350.h> 283 + #include <dt-bindings/iio/qcom,spmi-adc7-pm8350.h> 284 + #include <dt-bindings/interrupt-controller/irq.h> 285 + 286 + spmi { 287 + #address-cells = <1>; 288 + #size-cells = <0>; 289 + adc@3100 { 290 + reg = <0x3100>; 291 + compatible = "qcom,spmi-adc7"; 292 + #address-cells = <1>; 293 + #size-cells = <0>; 294 + #io-channel-cells = <1>; 295 + 296 + /* Other properties are omitted */ 297 + xo-therm@44 { 298 + reg = <PMK8350_ADC7_AMUX_THM1_100K_PU>; 299 + qcom,ratiometric; 300 + qcom,hw-settle-time = <200>; 301 + }; 302 + 303 + conn-therm@47 { 304 + reg = <PM8350_ADC7_AMUX_THM4_100K_PU>; 305 + qcom,ratiometric; 306 + qcom,hw-settle-time = <200>; 307 + }; 308 + }; 277 309 };
+1
Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml
··· 22 22 - rockchip,rk3328-saradc 23 23 - rockchip,rk3568-saradc 24 24 - rockchip,rv1108-saradc 25 + - rockchip,rv1126-saradc 25 26 - const: rockchip,rk3399-saradc 26 27 27 28 reg:
+65 -3
Documentation/devicetree/bindings/iio/adc/st,stm32-adc.yaml
··· 27 27 - st,stm32f4-adc-core 28 28 - st,stm32h7-adc-core 29 29 - st,stm32mp1-adc-core 30 + - st,stm32mp13-adc-core 30 31 31 32 reg: 32 33 maxItems: 1 ··· 38 37 - stm32f4 and stm32h7 share a common ADC interrupt line. 39 38 - stm32mp1 has two separate interrupt lines, one for each ADC within 40 39 ADC block. 40 + - stm32mp13 has an interrupt line per ADC block. 41 41 minItems: 1 42 42 maxItems: 2 43 43 ··· 182 180 maximum: 36000000 183 181 default: 36000000 184 182 183 + - if: 184 + properties: 185 + compatible: 186 + contains: 187 + const: st,stm32mp13-adc-core 188 + 189 + then: 190 + properties: 191 + clocks: 192 + minItems: 1 193 + maxItems: 2 194 + 195 + clock-names: 196 + items: 197 + - const: bus 198 + - const: adc 199 + minItems: 1 200 + 201 + interrupts: 202 + items: 203 + - description: ADC interrupt line 204 + 205 + st,max-clk-rate-hz: 206 + minimum: 150000 207 + maximum: 75000000 208 + default: 75000000 209 + 185 210 additionalProperties: false 186 211 187 212 required: ··· 237 208 - st,stm32f4-adc 238 209 - st,stm32h7-adc 239 210 - st,stm32mp1-adc 211 + - st,stm32mp13-adc 240 212 241 213 reg: 242 214 description: | ··· 259 229 interrupts: 260 230 description: | 261 231 IRQ Line for the ADC instance. Valid values are: 262 - - 0 for adc@0 232 + - 0 for adc@0 (single adc for stm32mp13) 263 233 - 1 for adc@100 264 234 - 2 for adc@200 (stm32f4 only) 265 235 maxItems: 1 ··· 280 250 assigned-resolution-bits: 281 251 description: | 282 252 Resolution (bits) to use for conversions: 283 - - can be 6, 8, 10 or 12 on stm32f4 253 + - can be 6, 8, 10 or 12 on stm32f4 and stm32mp13 284 254 - can be 8, 10, 12, 14 or 16 on stm32h7 and stm32mp1 285 255 286 256 st,adc-channels: 287 257 description: | 288 258 List of single-ended channels muxed for this ADC. It can have up to: 289 259 - 16 channels, numbered from 0 to 15 (for in0..in15) on stm32f4 260 + - 19 channels, numbered from 0 to 18 (for in0..in18) on stm32mp13. 290 261 - 20 channels, numbered from 0 to 19 (for in0..in19) on stm32h7 and 291 262 stm32mp1. 292 263 $ref: /schemas/types.yaml#/definitions/uint32-array ··· 353 322 label: 354 323 description: | 355 324 Unique name to identify which channel this is. 356 - Reserved label names "vddcore", "vrefint" and "vbat" 325 + Reserved label names "vddcore", "vddcpu", "vddq_ddr", "vrefint" and "vbat" 357 326 are used to identify internal channels with matching names. 358 327 359 328 diff-channels: ··· 450 419 items: 451 420 minimum: 40 452 421 422 + 423 + - if: 424 + properties: 425 + compatible: 426 + contains: 427 + const: st,stm32mp13-adc 428 + 429 + then: 430 + properties: 431 + reg: 432 + const: 0x0 433 + 434 + interrupts: 435 + const: 0 436 + 437 + assigned-resolution-bits: 438 + enum: [6, 8, 10, 12] 439 + default: 12 440 + 441 + st,adc-channels: 442 + minItems: 1 443 + maxItems: 19 444 + items: 445 + minimum: 0 446 + maximum: 18 447 + 448 + st,min-sample-time-nsecs: 449 + minItems: 1 450 + maxItems: 19 451 + items: 452 + minimum: 40 453 453 additionalProperties: false 454 454 455 455 required:
+6 -6
Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml
··· 58 58 - spi-cpol 59 59 - refin-supply 60 60 61 - additionalProperties: false 62 - 63 61 patternProperties: 64 62 "^channel@[0-3]$": 65 63 type: object ··· 101 103 required: 102 104 - reg 103 105 106 + allOf: 107 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 108 + 109 + unevaluatedProperties: false 110 + 104 111 examples: 105 112 - | 106 113 #include <dt-bindings/gpio/gpio.h> ··· 116 113 #address-cells = <1>; 117 114 #size-cells = <0>; 118 115 119 - cs-gpios = <&gpio 17 GPIO_ACTIVE_LOW>; 120 - status = "okay"; 121 - 122 - ad74413r@0 { 116 + addac@0 { 123 117 compatible = "adi,ad74413r"; 124 118 reg = <0>; 125 119 spi-max-frequency = <1000000>;
+1 -2
Documentation/devicetree/bindings/iio/dac/adi,ad5758.yaml
··· 102 102 - if: 103 103 properties: 104 104 adi,dc-dc-mode: 105 - contains: 106 - enum: [1, 3] 105 + enum: [1, 3] 107 106 then: 108 107 properties: 109 108 adi,range-microvolt: false
+1 -1
Documentation/devicetree/bindings/iio/dac/adi,ad5766.yaml
··· 8 8 title: Analog Devices AD5766 DAC device driver 9 9 10 10 maintainers: 11 - - Cristian Pop <cristian.pop@analog.com> 11 + - Nuno Sá <nuno.sa@analog.com> 12 12 13 13 description: | 14 14 Bindings for the Analog Devices AD5766 current DAC device. Datasheet can be
+5 -2
Documentation/devicetree/bindings/iio/frequency/adi,adf4350.yaml
··· 160 160 2: +2dBm 161 161 3: +5dBm 162 162 163 - additionalProperties: false 164 - 165 163 required: 166 164 - compatible 167 165 - reg 168 166 - clocks 167 + 168 + allOf: 169 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 170 + 171 + unevaluatedProperties: false 169 172 170 173 examples: 171 174 - |
+4 -1
Documentation/devicetree/bindings/iio/frequency/adi,admv1013.yaml
··· 70 70 - clock-names 71 71 - vcm-supply 72 72 73 - additionalProperties: false 73 + allOf: 74 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 75 + 76 + unevaluatedProperties: false 74 77 75 78 examples: 76 79 - |
+4 -1
Documentation/devicetree/bindings/iio/frequency/adi,admv1014.yaml
··· 104 104 - clock-names 105 105 - vcm-supply 106 106 107 - additionalProperties: false 107 + allOf: 108 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 109 + 110 + unevaluatedProperties: false 108 111 109 112 examples: 110 113 - |
+6 -2
Documentation/devicetree/bindings/iio/frequency/adi,admv4420.yaml
··· 7 7 title: ADMV4420 K Band Downconverter 8 8 9 9 maintainers: 10 - - Cristian Pop <cristian.pop@analog.com> 10 + - Nuno Sá <nuno.sa@analog.com> 11 11 12 12 description: 13 13 The ADMV4420 is a highly integrated, double balanced, active ··· 37 37 - compatible 38 38 - reg 39 39 40 - additionalProperties: false 40 + 41 + allOf: 42 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 43 + 44 + unevaluatedProperties: false 41 45 42 46 examples: 43 47 - |
+4 -1
Documentation/devicetree/bindings/iio/frequency/adi,adrf6780.yaml
··· 113 113 - clocks 114 114 - clock-names 115 115 116 - additionalProperties: false 116 + allOf: 117 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 118 + 119 + unevaluatedProperties: false 117 120 118 121 examples: 119 122 - |
+4 -1
Documentation/devicetree/bindings/iio/gyroscope/adi,adxrs290.yaml
··· 38 38 - spi-cpol 39 39 - spi-cpha 40 40 41 - additionalProperties: false 41 + allOf: 42 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 43 + 44 + unevaluatedProperties: false 42 45 43 46 examples: 44 47 - |
+4 -1
Documentation/devicetree/bindings/iio/gyroscope/nxp,fxas21002c.yaml
··· 56 56 - compatible 57 57 - reg 58 58 59 - additionalProperties: false 59 + allOf: 60 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 61 + 62 + unevaluatedProperties: false 60 63 61 64 examples: 62 65 - |
+2 -1
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml
··· 79 79 - spi-cpol 80 80 81 81 allOf: 82 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 82 83 - if: 83 84 properties: 84 85 compatible: ··· 108 107 dependencies: 109 108 adi,sync-mode: [ clocks ] 110 109 111 - additionalProperties: false 110 + unevaluatedProperties: false 112 111 113 112 examples: 114 113 - |
+1
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml
··· 31 31 - invensense,icm42602 32 32 - invensense,icm42605 33 33 - invensense,icm42622 34 + - invensense,icm42631 34 35 35 36 reg: 36 37 maxItems: 1
+4
Documentation/devicetree/bindings/iio/imu/st,lsm6dsx.yaml
··· 32 32 - st,lsm6dsrx 33 33 - st,lsm6dst 34 34 - st,lsm6dsop 35 + - st,lsm6dsv 35 36 - items: 36 37 - const: st,asm330lhhx 37 38 - const: st,lsm6dsr 38 39 - items: 39 40 - const: st,lsm6dstx 40 41 - const: st,lsm6dst 42 + - items: 43 + - const: st,lsm6dsv16x 44 + - const: st,lsm6dsv 41 45 42 46 reg: 43 47 maxItems: 1
+5 -1
Documentation/devicetree/bindings/iio/pressure/meas,ms5611.yaml
··· 30 30 - compatible 31 31 - reg 32 32 33 - additionalProperties: false 33 + allOf: 34 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 35 + 36 + unevaluatedProperties: false 34 37 35 38 examples: 36 39 - | ··· 55 52 compatible = "meas,ms5611"; 56 53 reg = <0>; 57 54 vdd-supply = <&ldo_3v3_gnss>; 55 + spi-max-frequency = <20000000>; 58 56 }; 59 57 }; 60 58 ...
+4 -1
Documentation/devicetree/bindings/iio/pressure/murata,zpa2326.yaml
··· 33 33 - compatible 34 34 - reg 35 35 36 - additionalProperties: false 36 + allOf: 37 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 38 + 39 + unevaluatedProperties: false 37 40 38 41 examples: 39 42 - |
+4 -1
Documentation/devicetree/bindings/iio/proximity/ams,as3935.yaml
··· 49 49 - spi-cpha 50 50 - interrupts 51 51 52 - additionalProperties: false 52 + allOf: 53 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 54 + 55 + unevaluatedProperties: false 53 56 54 57 examples: 55 58 - |
+5 -2
Documentation/devicetree/bindings/iio/resolver/adi,ad2s90.yaml
··· 33 33 34 34 spi-cpha: true 35 35 36 - additionalProperties: false 37 - 38 36 required: 39 37 - compatible 40 38 - reg ··· 40 42 dependencies: 41 43 spi-cpol: [ spi-cpha ] 42 44 spi-cpha: [ spi-cpol ] 45 + 46 + allOf: 47 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 48 + 49 + unevaluatedProperties: false 43 50 44 51 examples: 45 52 - |
+208 -127
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml
··· 4 4 $id: http://devicetree.org/schemas/iio/temperature/adi,ltc2983.yaml# 5 5 $schema: http://devicetree.org/meta-schemas/core.yaml# 6 6 7 - title: Analog Devices LTC2983 Multi-sensor Temperature system 7 + title: Analog Devices LTC2983, LTC2986, LTM2985 Multi-sensor Temperature system 8 8 9 9 maintainers: 10 10 - Nuno Sá <nuno.sa@analog.com> 11 11 12 12 description: | 13 - Analog Devices LTC2983 Multi-Sensor Digital Temperature Measurement System 13 + Analog Devices LTC2983, LTC2984, LTC2986, LTM2985 Multi-Sensor Digital 14 + Temperature Measurement Systems 15 + 14 16 https://www.analog.com/media/en/technical-documentation/data-sheets/2983fc.pdf 17 + https://www.analog.com/media/en/technical-documentation/data-sheets/2984fb.pdf 18 + https://www.analog.com/media/en/technical-documentation/data-sheets/29861fa.pdf 19 + https://www.analog.com/media/en/technical-documentation/data-sheets/ltm2985.pdf 15 20 16 21 properties: 17 22 compatible: 18 - enum: 19 - - adi,ltc2983 23 + oneOf: 24 + - enum: 25 + - adi,ltc2983 26 + - adi,ltc2986 27 + - adi,ltm2985 28 + - items: 29 + - const: adi,ltc2984 30 + - const: adi,ltc2983 20 31 21 32 reg: 22 33 maxItems: 1 ··· 36 25 maxItems: 1 37 26 38 27 adi,mux-delay-config-us: 39 - description: 40 - The LTC2983 performs 2 or 3 internal conversion cycles per temperature 41 - result. Each conversion cycle is performed with different excitation and 42 - input multiplexer configurations. Prior to each conversion, these 43 - excitation circuits and input switch configurations are changed and an 44 - internal 1ms delay ensures settling prior to the conversion cycle in most 45 - cases. An extra delay can be configured using this property. The value is 46 - rounded to nearest 100us. 28 + description: | 29 + Extra delay prior to each conversion, in addition to the internal 1ms 30 + delay, for the multiplexer to switch input configurations and 31 + excitation values. 32 + 33 + This property is supposed to be in microseconds, but to maintain 34 + compatibility, this value will be multiplied by 100 before usage. 47 35 maximum: 255 36 + default: 0 48 37 49 38 adi,filter-notch-freq: 50 39 description: 51 - Set's the default setting of the digital filter. The default is 52 - simultaneous 50/60Hz rejection. 40 + Notch frequency of the digital filter. 53 41 0 - 50/60Hz rejection 54 42 1 - 60Hz rejection 55 43 2 - 50Hz rejection 56 44 $ref: /schemas/types.yaml#/definitions/uint32 57 45 minimum: 0 58 46 maximum: 2 47 + default: 0 59 48 60 49 '#address-cells': 61 50 const: 1 ··· 64 53 const: 0 65 54 66 55 patternProperties: 67 - "@([1-9]|1[0-9]|20)$": 56 + "@([0-9a-f]+)$": 68 57 type: object 58 + description: Sensor. 69 59 70 60 properties: 71 61 reg: 72 62 description: 73 - The channel number. It can be connected to one of the 20 channels of 74 - the device. 63 + Channel number. Connects the sensor to the channel with this number 64 + of the device. 75 65 minimum: 1 76 66 maximum: 20 77 67 78 68 adi,sensor-type: 79 - description: Identifies the type of sensor connected to the device. 69 + description: Type of sensor connected to the device. 80 70 $ref: /schemas/types.yaml#/definitions/uint32 81 71 82 72 required: ··· 86 74 87 75 "^thermocouple@": 88 76 type: object 89 - description: 90 - Represents a thermocouple sensor which is connected to one of the device 91 - channels. 77 + description: Thermocouple sensor. 92 78 93 79 properties: 94 80 adi,sensor-type: ··· 105 95 maximum: 9 106 96 107 97 adi,single-ended: 108 - description: 109 - Boolean property which set's the thermocouple as single-ended. 98 + description: Whether the sensor is single-ended. 110 99 type: boolean 111 100 112 101 adi,sensor-oc-current-microamp: 113 - description: 114 - This property set's the pulsed current value applied during 115 - open-circuit detect. 102 + description: Pulsed current value applied during open-circuit detect. 116 103 enum: [10, 100, 500, 1000] 104 + default: 10 117 105 118 106 adi,cold-junction-handle: 119 107 description: 120 - Phandle which points to a sensor object responsible for measuring 121 - the thermocouple cold junction temperature. 122 - $ref: "/schemas/types.yaml#/definitions/phandle" 108 + Sensor responsible for measuring the thermocouple cold junction 109 + temperature. 110 + $ref: /schemas/types.yaml#/definitions/phandle 123 111 124 112 adi,custom-thermocouple: 125 113 description: 126 - This is a table, where each entry should be a pair of 127 - voltage(mv)-temperature(K). The entries must be given in nv and uK 128 - so that, the original values must be multiplied by 1000000. For 129 - more details look at table 69 and 70. 130 - Note should be signed, but dtc doesn't currently maintain the 131 - sign. 114 + Used for digitizing custom thermocouples. 115 + See Page 59 of the datasheet. 132 116 $ref: /schemas/types.yaml#/definitions/uint64-matrix 133 117 minItems: 3 134 118 maxItems: 64 135 119 items: 136 - minItems: 2 137 - maxItems: 2 120 + items: 121 + - description: Voltage point in nV, signed. 122 + - description: Temperature point in uK. 123 + 124 + allOf: 125 + - if: 126 + properties: 127 + adi,sensor-type: 128 + const: 9 129 + then: 130 + required: 131 + - adi,custom-thermocouple 138 132 139 133 "^diode@": 140 134 type: object 141 - description: 142 - Represents a diode sensor which is connected to one of the device 143 - channels. 135 + description: Diode sensor. 144 136 145 137 properties: 146 138 adi,sensor-type: 147 - description: Identifies the sensor as a diode. 139 + description: Sensor type for diodes. 148 140 $ref: /schemas/types.yaml#/definitions/uint32 149 141 const: 28 150 142 151 143 adi,single-ended: 152 - description: Boolean property which set's the diode as single-ended. 144 + description: Whether the sensor is single-ended. 153 145 type: boolean 154 146 155 147 adi,three-conversion-cycles: 156 148 description: 157 - Boolean property which set's three conversion cycles removing 158 - parasitic resistance effects between the LTC2983 and the diode. 149 + Whether to use three conversion cycles to remove parasitic 150 + resistance between the device and the diode. 159 151 type: boolean 160 152 161 153 adi,average-on: 162 154 description: 163 - Boolean property which enables a running average of the diode 164 - temperature reading. This reduces the noise when the diode is used 165 - as a cold junction temperature element on an isothermal block 166 - where temperatures change slowly. 155 + Whether to use a running average of the diode temperature 156 + reading to reduce the noise when the diode is used as a cold 157 + junction temperature element on an isothermal block where 158 + temperatures change slowly. 167 159 type: boolean 168 160 169 161 adi,excitation-current-microamp: 170 162 description: 171 - This property controls the magnitude of the excitation current 172 - applied to the diode. Depending on the number of conversions 173 - cycles, this property will assume different predefined values on 174 - each cycle. Just set the value of the first cycle (1l). 163 + Magnitude of the 1l excitation current applied to the diode. 164 + 4l excitation current will be 4 times this value, and 8l 165 + excitation current will be 8 times value. 175 166 enum: [10, 20, 40, 80] 167 + default: 10 176 168 177 169 adi,ideal-factor-value: 178 170 description: 179 - This property sets the diode ideality factor. The real value must 180 - be multiplied by 1000000 to remove the fractional part. For more 181 - information look at table 20 of the datasheet. 171 + Diode ideality factor. 172 + Set this property to 1000000 times the real value. 182 173 $ref: /schemas/types.yaml#/definitions/uint32 174 + default: 0 183 175 184 176 "^rtd@": 185 177 type: object 186 - description: 187 - Represents a rtd sensor which is connected to one of the device channels. 178 + description: RTD sensor. 188 179 189 180 properties: 190 181 reg: ··· 208 197 maximum: 18 209 198 210 199 adi,rsense-handle: 211 - description: 212 - Phandle pointing to a rsense object associated with this RTD. 213 - $ref: "/schemas/types.yaml#/definitions/phandle" 200 + description: Associated sense resistor sensor. 201 + $ref: /schemas/types.yaml#/definitions/phandle 214 202 215 203 adi,number-of-wires: 216 204 description: 217 - Identifies the number of wires used by the RTD. Setting this 218 - property to 5 means 4 wires with Kelvin Rsense. 205 + Number of wires used by the RTD. 206 + 5 means 4 wires with Kelvin sense resistor. 219 207 $ref: /schemas/types.yaml#/definitions/uint32 220 208 enum: [2, 3, 4, 5] 209 + default: 2 221 210 222 211 adi,rsense-share: 223 212 description: 224 - Boolean property which enables Rsense sharing, where one sense 225 - resistor is used for multiple 2-, 3-, and/or 4-wire RTDs. 226 - type: boolean 227 - 228 - adi,current-rotate: 229 - description: 230 - Boolean property which enables excitation current rotation to 231 - automatically remove parasitic thermocouple effects. Note that 232 - this property is not allowed for 2- and 3-wire RTDs. 213 + Whether to enable sense resistor sharing, where one sense 214 + resistor is used by multiple sensors. 233 215 type: boolean 234 216 235 217 adi,excitation-current-microamp: 236 - description: 237 - This property controls the magnitude of the excitation current 238 - applied to the RTD. 218 + description: Excitation current applied to the RTD. 239 219 enum: [5, 10, 25, 50, 100, 250, 500, 1000] 220 + default: 5 240 221 241 222 adi,rtd-curve: 242 - description: 243 - This property set the RTD curve used and the corresponding 244 - Callendar-VanDusen constants. Look at table 30 of the datasheet. 223 + description: | 224 + RTD curve and the corresponding Callendar-VanDusen constants. 225 + 0 - European 226 + 1 - American 227 + 2 - Japanese 228 + 3 - ITS-90 245 229 $ref: /schemas/types.yaml#/definitions/uint32 246 230 minimum: 0 247 231 maximum: 3 232 + default: 0 248 233 249 234 adi,custom-rtd: 250 235 description: 251 - This is a table, where each entry should be a pair of 252 - resistance(ohm)-temperature(K). The entries added here are in uohm 253 - and uK. For more details values look at table 74 and 75. 236 + Used for digitizing custom RTDs. 237 + See Page 62 of the datasheet. 254 238 $ref: /schemas/types.yaml#/definitions/uint64-matrix 239 + minItems: 3 240 + maxItems: 64 255 241 items: 256 - minItems: 3 257 - maxItems: 64 258 242 items: 259 - minItems: 2 260 - maxItems: 2 243 + - description: Resistance point in uOhms. 244 + - description: Temperature point in uK. 261 245 262 246 required: 263 247 - adi,rsense-handle 264 248 265 - dependencies: 266 - adi,current-rotate: [ "adi,rsense-share" ] 249 + allOf: 250 + - if: 251 + properties: 252 + adi,number-of-wires: 253 + const: 4 254 + then: 255 + properties: 256 + adi,current-rotate: 257 + description: 258 + Whether to enable excitation current rotation to automatically 259 + remove parasitic thermocouple effects. 260 + type: boolean 261 + 262 + dependencies: 263 + adi,current-rotate: [ "adi,rsense-share" ] 264 + 265 + - if: 266 + properties: 267 + adi,sensor-type: 268 + const: 18 269 + then: 270 + required: 271 + - adi,custom-rtd 267 272 268 273 "^thermistor@": 269 274 type: object 270 - description: 271 - Represents a thermistor sensor which is connected to one of the device 272 - channels. 275 + description: Thermistor sensor. 273 276 274 277 properties: 275 278 adi,sensor-type: ··· 302 277 maximum: 27 303 278 304 279 adi,rsense-handle: 305 - description: 306 - Phandle pointing to a rsense object associated with this 307 - thermistor. 308 - $ref: "/schemas/types.yaml#/definitions/phandle" 280 + description: Associated sense resistor sensor. 281 + $ref: /schemas/types.yaml#/definitions/phandle 309 282 310 283 adi,single-ended: 311 - description: 312 - Boolean property which set's the thermistor as single-ended. 284 + description: Whether the sensor is single-ended. 313 285 type: boolean 314 286 315 287 adi,rsense-share: 316 288 description: 317 - Boolean property which enables Rsense sharing, where one sense 318 - resistor is used for multiple thermistors. Note that this property 319 - is ignored if adi,single-ended is set. 289 + Whether to enable sense resistor sharing, where one sense 290 + resistor is used by multiple sensors. 320 291 type: boolean 321 292 322 293 adi,current-rotate: 323 294 description: 324 - Boolean property which enables excitation current rotation to 325 - automatically remove parasitic thermocouple effects. 295 + Whether to enable excitation current rotation to automatically 296 + remove parasitic thermocouple effects. 326 297 type: boolean 327 298 328 299 adi,excitation-current-nanoamp: 329 300 description: 330 - This property controls the magnitude of the excitation current 331 - applied to the thermistor. Value 0 set's the sensor in auto-range 332 - mode. 301 + Excitation current applied to the thermistor. 302 + 0 sets the sensor in auto-range mode. 333 303 $ref: /schemas/types.yaml#/definitions/uint32 334 304 enum: [0, 250, 500, 1000, 5000, 10000, 25000, 50000, 100000, 250000, 335 305 500000, 1000000] 306 + default: 0 336 307 337 308 adi,custom-thermistor: 338 309 description: 339 - This is a table, where each entry should be a pair of 340 - resistance(ohm)-temperature(K). The entries added here are in uohm 341 - and uK only for custom thermistors. For more details look at table 342 - 78 and 79. 310 + Used for digitizing custom thermistors. 311 + See Page 65 of the datasheet. 343 312 $ref: /schemas/types.yaml#/definitions/uint64-matrix 344 313 minItems: 3 345 314 maxItems: 64 346 315 items: 347 - minItems: 2 348 - maxItems: 2 316 + items: 317 + - description: Resistance point in uOhms. 318 + - description: Temperature point in uK. 349 319 350 320 adi,custom-steinhart: 351 321 description: 352 - Steinhart-Hart coefficients are also supported and can 353 - be programmed into the device memory using this property. For 354 - Steinhart sensors the coefficients are given in the raw 355 - format. Look at table 82 for more information. 322 + Steinhart-Hart coefficients in raw format, used for digitizing 323 + custom thermistors. 324 + See Page 68 of the datasheet. 356 325 $ref: /schemas/types.yaml#/definitions/uint32-array 357 - items: 358 - minItems: 6 359 - maxItems: 6 326 + minItems: 6 327 + maxItems: 6 360 328 361 329 required: 362 330 - adi,rsense-handle ··· 357 339 dependencies: 358 340 adi,current-rotate: [ "adi,rsense-share" ] 359 341 342 + allOf: 343 + - if: 344 + properties: 345 + adi,sensor-type: 346 + const: 26 347 + then: 348 + properties: 349 + adi,excitation-current-nanoamp: 350 + enum: [250, 500, 1000, 5000, 10000, 25000, 50000, 100000, 351 + 250000, 500000, 1000000] 352 + default: 1000 353 + required: 354 + - adi,custom-steinhart 355 + - if: 356 + properties: 357 + adi,sensor-type: 358 + const: 27 359 + then: 360 + properties: 361 + adi,excitation-current-nanoamp: 362 + enum: [250, 500, 1000, 5000, 10000, 25000, 50000, 100000, 363 + 250000, 500000, 1000000] 364 + default: 1000 365 + required: 366 + - adi,custom-thermistor 367 + 360 368 "^adc@": 361 369 type: object 362 - description: Represents a channel which is being used as a direct adc. 370 + description: Direct ADC sensor. 363 371 364 372 properties: 365 373 adi,sensor-type: 366 - description: Identifies the sensor as a direct adc. 374 + description: Sensor type for direct ADC sensors. 367 375 $ref: /schemas/types.yaml#/definitions/uint32 368 376 const: 30 369 377 370 378 adi,single-ended: 371 - description: Boolean property which set's the adc as single-ended. 379 + description: Whether the sensor is single-ended. 372 380 type: boolean 381 + 382 + "^temp@": 383 + type: object 384 + description: Active analog temperature sensor. 385 + 386 + properties: 387 + adi,sensor-type: 388 + description: Sensor type for active analog temperature sensors. 389 + $ref: /schemas/types.yaml#/definitions/uint32 390 + const: 31 391 + 392 + adi,single-ended: 393 + description: Whether the sensor is single-ended. 394 + type: boolean 395 + 396 + adi,custom-temp: 397 + description: 398 + Used for digitizing active analog temperature sensors. 399 + See Page 67 of the LTM2985 datasheet. 400 + $ref: /schemas/types.yaml#/definitions/uint64-matrix 401 + minItems: 3 402 + maxItems: 64 403 + items: 404 + items: 405 + - description: Voltage point in nV, signed. 406 + - description: Temperature point in uK. 407 + 408 + required: 409 + - adi,custom-temp 373 410 374 411 "^rsense@": 375 412 type: object 376 - description: 377 - Represents a rsense which is connected to one of the device channels. 378 - Rsense are used by thermistors and RTD's. 413 + description: Sense resistor sensor. 379 414 380 415 properties: 381 416 reg: ··· 436 365 maximum: 20 437 366 438 367 adi,sensor-type: 439 - description: Identifies the sensor as a rsense. 368 + description: Sensor type sense resistor sensors. 440 369 $ref: /schemas/types.yaml#/definitions/uint32 441 370 const: 29 442 371 443 372 adi,rsense-val-milli-ohms: 444 - description: 445 - Sets the value of the sense resistor. Look at table 20 of the 446 - datasheet for information. 373 + description: Value of the sense resistor. 447 374 448 375 required: 449 376 - adi,rsense-val-milli-ohms ··· 453 384 454 385 additionalProperties: false 455 386 387 + allOf: 388 + - if: 389 + properties: 390 + compatible: 391 + contains: 392 + enum: 393 + - adi,ltc2983 394 + - adi,ltc2984 395 + then: 396 + patternProperties: 397 + "^temp@": false 398 + 456 399 examples: 457 400 - | 458 401 #include <dt-bindings/interrupt-controller/irq.h> ··· 472 391 #address-cells = <1>; 473 392 #size-cells = <0>; 474 393 475 - sensor_ltc2983: ltc2983@0 { 394 + temperature-sensor@0 { 476 395 compatible = "adi,ltc2983"; 477 396 reg = <0>; 478 397
+15
MAINTAINERS
··· 1117 1117 T: git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git 1118 1118 F: drivers/net/amt.c 1119 1119 1120 + ANALOG DEVICES INC AD4130 DRIVER 1121 + M: Cosmin Tanislav <cosmin.tanislav@analog.com> 1122 + L: linux-iio@vger.kernel.org 1123 + S: Supported 1124 + W: http://ez.analog.com/community/linux-device-drivers 1125 + F: Documentation/ABI/testing/sysfs-bus-iio-adc-ad4130 1126 + F: Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml 1127 + F: drivers/iio/adc/ad4130.c 1128 + 1120 1129 ANALOG DEVICES INC AD7192 DRIVER 1121 1130 M: Alexandru Tachici <alexandru.tachici@analog.com> 1122 1131 L: linux-iio@vger.kernel.org ··· 11454 11445 F: drivers/mfd/khadas-mcu.c 11455 11446 F: include/linux/mfd/khadas-mcu.h 11456 11447 F: drivers/thermal/khadas_mcu_fan.c 11448 + 11449 + KIONIX/ROHM KX022A ACCELEROMETER 11450 + M: Matti Vaittinen <mazziesaccount@gmail.com> 11451 + L: linux-iio@vger.kernel.org 11452 + S: Supported 11453 + F: drivers/iio/accel/kionix-kx022a* 11457 11454 11458 11455 KMEMLEAK 11459 11456 M: Catalin Marinas <catalin.marinas@arm.com>
+14
drivers/i2c/i2c-core-base.c
··· 2236 2236 } 2237 2237 EXPORT_SYMBOL_GPL(i2c_get_device_id); 2238 2238 2239 + /** 2240 + * i2c_client_get_device_id - get the driver match table entry of a device 2241 + * @client: the device to query. The device must be bound to a driver 2242 + * 2243 + * Returns a pointer to the matching entry if found, NULL otherwise. 2244 + */ 2245 + const struct i2c_device_id *i2c_client_get_device_id(const struct i2c_client *client) 2246 + { 2247 + const struct i2c_driver *drv = to_i2c_driver(client->dev.driver); 2248 + 2249 + return i2c_match_id(drv->id_table, client); 2250 + } 2251 + EXPORT_SYMBOL_GPL(i2c_client_get_device_id); 2252 + 2239 2253 /* ---------------------------------------------------- 2240 2254 * the i2c address scanning function 2241 2255 * Will not work for 10-bit addresses!
-3
drivers/iio/TODO
··· 7 7 - ABI Documentation 8 8 - Audit driviers/iio/staging/Documentation 9 9 10 - - Replace iio_dev->mlock by either a local lock or use 11 - iio_claim_direct.(Requires analysis of the purpose of the lock.) 12 - 13 10 - Converting drivers from device tree centric to more generic 14 11 property handlers. 15 12
+21
drivers/iio/accel/Kconfig
··· 409 409 To compile this driver as a module, choose M here. The module 410 410 will be called st_accel_spi. 411 411 412 + config IIO_KX022A 413 + tristate 414 + 415 + config IIO_KX022A_SPI 416 + tristate "Kionix KX022A tri-axis digital accelerometer SPI interface" 417 + depends on SPI 418 + select IIO_KX022A 419 + select REGMAP_SPI 420 + help 421 + Enable support for the Kionix KX022A digital tri-axis 422 + accelerometer connected to I2C interface. 423 + 424 + config IIO_KX022A_I2C 425 + tristate "Kionix KX022A tri-axis digital accelerometer I2C interface" 426 + depends on I2C 427 + select IIO_KX022A 428 + select REGMAP_I2C 429 + help 430 + Enable support for the Kionix KX022A digital tri-axis 431 + accelerometer connected to I2C interface. 432 + 412 433 config KXSD9 413 434 tristate "Kionix KXSD9 Accelerometer Driver" 414 435 select IIO_BUFFER
+3
drivers/iio/accel/Makefile
··· 40 40 obj-$(CONFIG_FXLS8962AF_I2C) += fxls8962af-i2c.o 41 41 obj-$(CONFIG_FXLS8962AF_SPI) += fxls8962af-spi.o 42 42 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o 43 + obj-$(CONFIG_IIO_KX022A) += kionix-kx022a.o 44 + obj-$(CONFIG_IIO_KX022A_I2C) += kionix-kx022a-i2c.o 45 + obj-$(CONFIG_IIO_KX022A_SPI) += kionix-kx022a-spi.o 43 46 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o 44 47 obj-$(CONFIG_KXSD9) += kxsd9.o 45 48 obj-$(CONFIG_KXSD9_SPI) += kxsd9-spi.o
+19 -1
drivers/iio/accel/adxl355.h
··· 10 10 11 11 #include <linux/regmap.h> 12 12 13 + enum adxl355_device_type { 14 + ADXL355, 15 + ADXL359, 16 + }; 17 + 18 + struct adxl355_fractional_type { 19 + int integer; 20 + int decimal; 21 + }; 22 + 13 23 struct device; 24 + 25 + struct adxl355_chip_info { 26 + const char *name; 27 + u8 part_id; 28 + struct adxl355_fractional_type accel_scale; 29 + struct adxl355_fractional_type temp_offset; 30 + }; 14 31 15 32 extern const struct regmap_access_table adxl355_readable_regs_tbl; 16 33 extern const struct regmap_access_table adxl355_writeable_regs_tbl; 34 + extern const struct adxl355_chip_info adxl35x_chip_info[]; 17 35 18 36 int adxl355_core_probe(struct device *dev, struct regmap *regmap, 19 - const char *name); 37 + const struct adxl355_chip_info *chip_info); 20 38 21 39 #endif /* _ADXL355_H_ */
+70 -23
drivers/iio/accel/adxl355_core.c
··· 60 60 #define ADXL355_DEVID_AD_VAL 0xAD 61 61 #define ADXL355_DEVID_MST_VAL 0x1D 62 62 #define ADXL355_PARTID_VAL 0xED 63 + #define ADXL359_PARTID_VAL 0xE9 63 64 #define ADXL355_RESET_CODE 0x52 64 65 65 66 static const struct regmap_range adxl355_read_reg_range[] = { ··· 83 82 .n_yes_ranges = ARRAY_SIZE(adxl355_write_reg_range), 84 83 }; 85 84 EXPORT_SYMBOL_NS_GPL(adxl355_writeable_regs_tbl, IIO_ADXL355); 85 + 86 + const struct adxl355_chip_info adxl35x_chip_info[] = { 87 + [ADXL355] = { 88 + .name = "adxl355", 89 + .part_id = ADXL355_PARTID_VAL, 90 + /* 91 + * At +/- 2g with 20-bit resolution, scale is given in datasheet 92 + * as 3.9ug/LSB = 0.0000039 * 9.80665 = 0.00003824593 m/s^2. 93 + */ 94 + .accel_scale = { 95 + .integer = 0, 96 + .decimal = 38245, 97 + }, 98 + /* 99 + * The datasheet defines an intercept of 1885 LSB at 25 degC 100 + * and a slope of -9.05 LSB/C. The following formula can be used 101 + * to find the temperature: 102 + * Temp = ((RAW - 1885)/(-9.05)) + 25 but this doesn't follow 103 + * the format of the IIO which is Temp = (RAW + OFFSET) * SCALE. 104 + * Hence using some rearranging we get the scale as -110.497238 105 + * and offset as -2111.25. 106 + */ 107 + .temp_offset = { 108 + .integer = -2111, 109 + .decimal = 250000, 110 + }, 111 + }, 112 + [ADXL359] = { 113 + .name = "adxl359", 114 + .part_id = ADXL359_PARTID_VAL, 115 + /* 116 + * At +/- 10g with 20-bit resolution, scale is given in datasheet 117 + * as 19.5ug/LSB = 0.0000195 * 9.80665 = 0.0.00019122967 m/s^2. 118 + */ 119 + .accel_scale = { 120 + .integer = 0, 121 + .decimal = 191229, 122 + }, 123 + /* 124 + * The datasheet defines an intercept of 1852 LSB at 25 degC 125 + * and a slope of -9.05 LSB/C. The following formula can be used 126 + * to find the temperature: 127 + * Temp = ((RAW - 1852)/(-9.05)) + 25 but this doesn't follow 128 + * the format of the IIO which is Temp = (RAW + OFFSET) * SCALE. 129 + * Hence using some rearranging we get the scale as -110.497238 130 + * and offset as -2079.25. 131 + */ 132 + .temp_offset = { 133 + .integer = -2079, 134 + .decimal = 250000, 135 + }, 136 + }, 137 + }; 138 + EXPORT_SYMBOL_NS_GPL(adxl35x_chip_info, IIO_ADXL355); 86 139 87 140 enum adxl355_op_mode { 88 141 ADXL355_MEASUREMENT, ··· 217 162 }; 218 163 219 164 struct adxl355_data { 165 + const struct adxl355_chip_info *chip_info; 220 166 struct regmap *regmap; 221 167 struct device *dev; 222 168 struct mutex lock; /* lock to protect op_mode */ ··· 318 262 if (ret) 319 263 return ret; 320 264 321 - if (regval != ADXL355_PARTID_VAL) { 322 - dev_err(data->dev, "Invalid DEV ID 0x%02x\n", regval); 323 - return -ENODEV; 324 - } 265 + if (regval != ADXL355_PARTID_VAL) 266 + dev_warn(data->dev, "Invalid DEV ID 0x%02x\n", regval); 325 267 326 268 /* 327 269 * Perform a software reset to make sure the device is in a consistent ··· 512 458 513 459 case IIO_CHAN_INFO_SCALE: 514 460 switch (chan->type) { 515 - /* 516 - * The datasheet defines an intercept of 1885 LSB at 25 degC 517 - * and a slope of -9.05 LSB/C. The following formula can be used 518 - * to find the temperature: 519 - * Temp = ((RAW - 1885)/(-9.05)) + 25 but this doesn't follow 520 - * the format of the IIO which is Temp = (RAW + OFFSET) * SCALE. 521 - * Hence using some rearranging we get the scale as -110.497238 522 - * and offset as -2111.25. 523 - */ 524 461 case IIO_TEMP: 462 + /* 463 + * Temperature scale is -110.497238. 464 + * See the detailed explanation in adxl35x_chip_info 465 + * definition above. 466 + */ 525 467 *val = -110; 526 468 *val2 = 497238; 527 469 return IIO_VAL_INT_PLUS_MICRO; 528 - /* 529 - * At +/- 2g with 20-bit resolution, scale is given in datasheet 530 - * as 3.9ug/LSB = 0.0000039 * 9.80665 = 0.00003824593 m/s^2. 531 - */ 532 470 case IIO_ACCEL: 533 - *val = 0; 534 - *val2 = 38245; 471 + *val = data->chip_info->accel_scale.integer; 472 + *val2 = data->chip_info->accel_scale.decimal; 535 473 return IIO_VAL_INT_PLUS_NANO; 536 474 default: 537 475 return -EINVAL; 538 476 } 539 477 case IIO_CHAN_INFO_OFFSET: 540 - *val = -2111; 541 - *val2 = 250000; 478 + *val = data->chip_info->temp_offset.integer; 479 + *val2 = data->chip_info->temp_offset.decimal; 542 480 return IIO_VAL_INT_PLUS_MICRO; 543 481 case IIO_CHAN_INFO_CALIBBIAS: 544 482 *val = sign_extend32(data->calibbias[chan->address], 15); ··· 753 707 } 754 708 755 709 int adxl355_core_probe(struct device *dev, struct regmap *regmap, 756 - const char *name) 710 + const struct adxl355_chip_info *chip_info) 757 711 { 758 712 struct adxl355_data *data; 759 713 struct iio_dev *indio_dev; ··· 768 722 data->regmap = regmap; 769 723 data->dev = dev; 770 724 data->op_mode = ADXL355_STANDBY; 725 + data->chip_info = chip_info; 771 726 mutex_init(&data->lock); 772 727 773 - indio_dev->name = name; 728 + indio_dev->name = chip_info->name; 774 729 indio_dev->info = &adxl355_info; 775 730 indio_dev->modes = INDIO_DIRECT_MODE; 776 731 indio_dev->channels = adxl355_channels;
+19 -3
drivers/iio/accel/adxl355_i2c.c
··· 23 23 static int adxl355_i2c_probe(struct i2c_client *client) 24 24 { 25 25 struct regmap *regmap; 26 + const struct adxl355_chip_info *chip_data; 27 + const struct i2c_device_id *adxl355; 28 + 29 + chip_data = device_get_match_data(&client->dev); 30 + if (!chip_data) { 31 + adxl355 = to_i2c_driver(client->dev.driver)->id_table; 32 + if (!adxl355) 33 + return -EINVAL; 34 + 35 + chip_data = (void *)i2c_match_id(adxl355, client)->driver_data; 36 + 37 + if (!chip_data) 38 + return -EINVAL; 39 + } 26 40 27 41 regmap = devm_regmap_init_i2c(client, &adxl355_i2c_regmap_config); 28 42 if (IS_ERR(regmap)) { ··· 46 32 return PTR_ERR(regmap); 47 33 } 48 34 49 - return adxl355_core_probe(&client->dev, regmap, client->name); 35 + return adxl355_core_probe(&client->dev, regmap, chip_data); 50 36 } 51 37 52 38 static const struct i2c_device_id adxl355_i2c_id[] = { 53 - { "adxl355", 0 }, 39 + { "adxl355", (kernel_ulong_t)&adxl35x_chip_info[ADXL355] }, 40 + { "adxl359", (kernel_ulong_t)&adxl35x_chip_info[ADXL359] }, 54 41 { } 55 42 }; 56 43 MODULE_DEVICE_TABLE(i2c, adxl355_i2c_id); 57 44 58 45 static const struct of_device_id adxl355_of_match[] = { 59 - { .compatible = "adi,adxl355" }, 46 + { .compatible = "adi,adxl355", .data = &adxl35x_chip_info[ADXL355] }, 47 + { .compatible = "adi,adxl359", .data = &adxl35x_chip_info[ADXL359] }, 60 48 { } 61 49 }; 62 50 MODULE_DEVICE_TABLE(of, adxl355_of_match);
+15 -4
drivers/iio/accel/adxl355_spi.c
··· 9 9 #include <linux/mod_devicetable.h> 10 10 #include <linux/regmap.h> 11 11 #include <linux/spi/spi.h> 12 + #include <linux/property.h> 12 13 13 14 #include "adxl355.h" 14 15 ··· 25 24 26 25 static int adxl355_spi_probe(struct spi_device *spi) 27 26 { 28 - const struct spi_device_id *id = spi_get_device_id(spi); 27 + const struct adxl355_chip_info *chip_data; 29 28 struct regmap *regmap; 29 + 30 + chip_data = device_get_match_data(&spi->dev); 31 + if (!chip_data) { 32 + chip_data = (void *)spi_get_device_id(spi)->driver_data; 33 + 34 + if (!chip_data) 35 + return -EINVAL; 36 + } 30 37 31 38 regmap = devm_regmap_init_spi(spi, &adxl355_spi_regmap_config); 32 39 if (IS_ERR(regmap)) { ··· 44 35 return PTR_ERR(regmap); 45 36 } 46 37 47 - return adxl355_core_probe(&spi->dev, regmap, id->name); 38 + return adxl355_core_probe(&spi->dev, regmap, chip_data); 48 39 } 49 40 50 41 static const struct spi_device_id adxl355_spi_id[] = { 51 - { "adxl355", 0 }, 42 + { "adxl355", (kernel_ulong_t)&adxl35x_chip_info[ADXL355] }, 43 + { "adxl359", (kernel_ulong_t)&adxl35x_chip_info[ADXL359] }, 52 44 { } 53 45 }; 54 46 MODULE_DEVICE_TABLE(spi, adxl355_spi_id); 55 47 56 48 static const struct of_device_id adxl355_of_match[] = { 57 - { .compatible = "adi,adxl355" }, 49 + { .compatible = "adi,adxl355", .data = &adxl35x_chip_info[ADXL355] }, 50 + { .compatible = "adi,adxl359", .data = &adxl35x_chip_info[ADXL359] }, 58 51 { } 59 52 }; 60 53 MODULE_DEVICE_TABLE(of, adxl355_of_match);
+12 -45
drivers/iio/accel/adxl367.c
··· 160 160 struct device *dev; 161 161 struct regmap *regmap; 162 162 163 - struct regulator_bulk_data regulators[2]; 164 - 165 163 /* 166 164 * Synchronize access to members of driver state, and ensure atomicity 167 165 * of consecutive regmap operations. ··· 1183 1185 return sysfs_emit(buf, "%d\n", fifo_watermark); 1184 1186 } 1185 1187 1186 - static ssize_t hwfifo_watermark_min_show(struct device *dev, 1187 - struct device_attribute *attr, 1188 - char *buf) 1189 - { 1190 - return sysfs_emit(buf, "%s\n", "1"); 1191 - } 1192 - 1193 - static ssize_t hwfifo_watermark_max_show(struct device *dev, 1194 - struct device_attribute *attr, 1195 - char *buf) 1196 - { 1197 - return sysfs_emit(buf, "%s\n", __stringify(ADXL367_FIFO_MAX_WATERMARK)); 1198 - } 1199 - 1200 - static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0); 1201 - static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0); 1188 + IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_min, "1"); 1189 + IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_max, 1190 + __stringify(ADXL367_FIFO_MAX_WATERMARK)); 1202 1191 static IIO_DEVICE_ATTR(hwfifo_watermark, 0444, 1203 1192 adxl367_get_fifo_watermark, NULL, 0); 1204 1193 static IIO_DEVICE_ATTR(hwfifo_enabled, 0444, 1205 1194 adxl367_get_fifo_enabled, NULL, 0); 1206 1195 1207 - static const struct attribute *adxl367_fifo_attributes[] = { 1208 - &iio_dev_attr_hwfifo_watermark_min.dev_attr.attr, 1209 - &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr, 1210 - &iio_dev_attr_hwfifo_watermark.dev_attr.attr, 1211 - &iio_dev_attr_hwfifo_enabled.dev_attr.attr, 1196 + static const struct iio_dev_attr *adxl367_fifo_attributes[] = { 1197 + &iio_dev_attr_hwfifo_watermark_min, 1198 + &iio_dev_attr_hwfifo_watermark_max, 1199 + &iio_dev_attr_hwfifo_watermark, 1200 + &iio_dev_attr_hwfifo_enabled, 1212 1201 NULL, 1213 1202 }; 1214 1203 ··· 1472 1487 return adxl367_set_measure_en(st, true); 1473 1488 } 1474 1489 1475 - static void adxl367_disable_regulators(void *data) 1476 - { 1477 - struct adxl367_state *st = data; 1478 - 1479 - regulator_bulk_disable(ARRAY_SIZE(st->regulators), st->regulators); 1480 - } 1481 - 1482 1490 int adxl367_probe(struct device *dev, const struct adxl367_ops *ops, 1483 1491 void *context, struct regmap *regmap, int irq) 1484 1492 { 1493 + static const char * const regulator_names[] = { "vdd", "vddio" }; 1485 1494 struct iio_dev *indio_dev; 1486 1495 struct adxl367_state *st; 1487 1496 int ret; ··· 1499 1520 indio_dev->info = &adxl367_info; 1500 1521 indio_dev->modes = INDIO_DIRECT_MODE; 1501 1522 1502 - st->regulators[0].supply = "vdd"; 1503 - st->regulators[1].supply = "vddio"; 1504 - 1505 - ret = devm_regulator_bulk_get(st->dev, ARRAY_SIZE(st->regulators), 1506 - st->regulators); 1523 + ret = devm_regulator_bulk_get_enable(st->dev, 1524 + ARRAY_SIZE(regulator_names), 1525 + regulator_names); 1507 1526 if (ret) 1508 1527 return dev_err_probe(st->dev, ret, 1509 1528 "Failed to get regulators\n"); 1510 - 1511 - ret = regulator_bulk_enable(ARRAY_SIZE(st->regulators), st->regulators); 1512 - if (ret) 1513 - return dev_err_probe(st->dev, ret, 1514 - "Failed to enable regulators\n"); 1515 - 1516 - ret = devm_add_action_or_reset(st->dev, adxl367_disable_regulators, st); 1517 - if (ret) 1518 - return dev_err_probe(st->dev, ret, 1519 - "Failed to add regulators disable action\n"); 1520 1529 1521 1530 ret = regmap_write(st->regmap, ADXL367_REG_RESET, ADXL367_RESET_CODE); 1522 1531 if (ret)
+2 -3
drivers/iio/accel/adxl367_i2c.c
··· 41 41 .read_fifo = adxl367_i2c_read_fifo, 42 42 }; 43 43 44 - static int adxl367_i2c_probe(struct i2c_client *client, 45 - const struct i2c_device_id *id) 44 + static int adxl367_i2c_probe(struct i2c_client *client) 46 45 { 47 46 struct adxl367_i2c_state *st; 48 47 struct regmap *regmap; ··· 77 78 .name = "adxl367_i2c", 78 79 .of_match_table = adxl367_of_match, 79 80 }, 80 - .probe = adxl367_i2c_probe, 81 + .probe_new = adxl367_i2c_probe, 81 82 .id_table = adxl367_i2c_id, 82 83 }; 83 84
+8 -21
drivers/iio/accel/adxl372.c
··· 998 998 return sprintf(buf, "%d\n", st->watermark); 999 999 } 1000 1000 1001 - static ssize_t hwfifo_watermark_min_show(struct device *dev, 1002 - struct device_attribute *attr, 1003 - char *buf) 1004 - { 1005 - return sysfs_emit(buf, "%s\n", "1"); 1006 - } 1007 - 1008 - static ssize_t hwfifo_watermark_max_show(struct device *dev, 1009 - struct device_attribute *attr, 1010 - char *buf) 1011 - { 1012 - return sysfs_emit(buf, "%s\n", __stringify(ADXL372_FIFO_SIZE)); 1013 - } 1014 - 1015 - static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0); 1016 - static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0); 1001 + IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_min, "1"); 1002 + IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_max, 1003 + __stringify(ADXL372_FIFO_SIZE)); 1017 1004 static IIO_DEVICE_ATTR(hwfifo_watermark, 0444, 1018 1005 adxl372_get_fifo_watermark, NULL, 0); 1019 1006 static IIO_DEVICE_ATTR(hwfifo_enabled, 0444, 1020 1007 adxl372_get_fifo_enabled, NULL, 0); 1021 1008 1022 - static const struct attribute *adxl372_fifo_attributes[] = { 1023 - &iio_dev_attr_hwfifo_watermark_min.dev_attr.attr, 1024 - &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr, 1025 - &iio_dev_attr_hwfifo_watermark.dev_attr.attr, 1026 - &iio_dev_attr_hwfifo_enabled.dev_attr.attr, 1009 + static const struct iio_dev_attr *adxl372_fifo_attributes[] = { 1010 + &iio_dev_attr_hwfifo_watermark_min, 1011 + &iio_dev_attr_hwfifo_watermark_max, 1012 + &iio_dev_attr_hwfifo_watermark, 1013 + &iio_dev_attr_hwfifo_enabled, 1027 1014 NULL, 1028 1015 }; 1029 1016
+3 -7
drivers/iio/accel/bma400_core.c
··· 874 874 ret = devm_regulator_bulk_get(data->dev, 875 875 ARRAY_SIZE(data->regulators), 876 876 data->regulators); 877 - if (ret) { 878 - if (ret != -EPROBE_DEFER) 879 - dev_err(data->dev, 880 - "Failed to get regulators: %d\n", 881 - ret); 877 + if (ret) 878 + return dev_err_probe(data->dev, ret, "Failed to get regulators: %d\n", 879 + ret); 882 880 883 - return ret; 884 - } 885 881 ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators), 886 882 data->regulators); 887 883 if (ret) {
+9 -22
drivers/iio/accel/bmc150-accel-core.c
··· 925 925 { } 926 926 }; 927 927 928 - static ssize_t hwfifo_watermark_min_show(struct device *dev, 929 - struct device_attribute *attr, 930 - char *buf) 931 - { 932 - return sysfs_emit(buf, "%s\n", "1"); 933 - } 934 - 935 - static ssize_t hwfifo_watermark_max_show(struct device *dev, 936 - struct device_attribute *attr, 937 - char *buf) 938 - { 939 - return sysfs_emit(buf, "%s\n", __stringify(BMC150_ACCEL_FIFO_LENGTH)); 940 - } 941 - 942 - static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0); 943 - static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0); 928 + IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_min, "1"); 929 + IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_max, 930 + __stringify(BMC150_ACCEL_FIFO_LENGTH)); 944 931 static IIO_DEVICE_ATTR(hwfifo_enabled, S_IRUGO, 945 932 bmc150_accel_get_fifo_state, NULL, 0); 946 933 static IIO_DEVICE_ATTR(hwfifo_watermark, S_IRUGO, 947 934 bmc150_accel_get_fifo_watermark, NULL, 0); 948 935 949 - static const struct attribute *bmc150_accel_fifo_attributes[] = { 950 - &iio_dev_attr_hwfifo_watermark_min.dev_attr.attr, 951 - &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr, 952 - &iio_dev_attr_hwfifo_watermark.dev_attr.attr, 953 - &iio_dev_attr_hwfifo_enabled.dev_attr.attr, 936 + static const struct iio_dev_attr *bmc150_accel_fifo_attributes[] = { 937 + &iio_dev_attr_hwfifo_watermark_min, 938 + &iio_dev_attr_hwfifo_watermark_max, 939 + &iio_dev_attr_hwfifo_watermark, 940 + &iio_dev_attr_hwfifo_enabled, 954 941 NULL, 955 942 }; 956 943 ··· 1665 1678 enum bmc150_type type, const char *name, 1666 1679 bool block_supported) 1667 1680 { 1668 - const struct attribute **fifo_attrs; 1681 + const struct iio_dev_attr **fifo_attrs; 1669 1682 struct bmc150_accel_data *data; 1670 1683 struct iio_dev *indio_dev; 1671 1684 int ret;
+2 -3
drivers/iio/accel/da311.c
··· 217 217 da311_enable(client, false); 218 218 } 219 219 220 - static int da311_probe(struct i2c_client *client, 221 - const struct i2c_device_id *id) 220 + static int da311_probe(struct i2c_client *client) 222 221 { 223 222 int ret; 224 223 struct iio_dev *indio_dev; ··· 278 279 .name = "da311", 279 280 .pm = pm_sleep_ptr(&da311_pm_ops), 280 281 }, 281 - .probe = da311_probe, 282 + .probe_new = da311_probe, 282 283 .id_table = da311_i2c_id, 283 284 }; 284 285
+2 -3
drivers/iio/accel/dmard06.c
··· 125 125 .read_raw = dmard06_read_raw, 126 126 }; 127 127 128 - static int dmard06_probe(struct i2c_client *client, 129 - const struct i2c_device_id *id) 128 + static int dmard06_probe(struct i2c_client *client) 130 129 { 131 130 int ret; 132 131 struct iio_dev *indio_dev; ··· 217 218 MODULE_DEVICE_TABLE(of, dmard06_of_match); 218 219 219 220 static struct i2c_driver dmard06_driver = { 220 - .probe = dmard06_probe, 221 + .probe_new = dmard06_probe, 221 222 .id_table = dmard06_id, 222 223 .driver = { 223 224 .name = DMARD06_DRV_NAME,
+2 -3
drivers/iio/accel/dmard09.c
··· 88 88 .read_raw = dmard09_read_raw, 89 89 }; 90 90 91 - static int dmard09_probe(struct i2c_client *client, 92 - const struct i2c_device_id *id) 91 + static int dmard09_probe(struct i2c_client *client) 93 92 { 94 93 int ret; 95 94 struct iio_dev *indio_dev; ··· 135 136 .driver = { 136 137 .name = DMARD09_DRV_NAME 137 138 }, 138 - .probe = dmard09_probe, 139 + .probe_new = dmard09_probe, 139 140 .id_table = dmard09_id, 140 141 }; 141 142
+2 -3
drivers/iio/accel/dmard10.c
··· 175 175 dmard10_shutdown(client); 176 176 } 177 177 178 - static int dmard10_probe(struct i2c_client *client, 179 - const struct i2c_device_id *id) 178 + static int dmard10_probe(struct i2c_client *client) 180 179 { 181 180 int ret; 182 181 struct iio_dev *indio_dev; ··· 241 242 .name = "dmard10", 242 243 .pm = pm_sleep_ptr(&dmard10_pm_ops), 243 244 }, 244 - .probe = dmard10_probe, 245 + .probe_new = dmard10_probe, 245 246 .id_table = dmard10_i2c_id, 246 247 }; 247 248
+10 -30
drivers/iio/accel/fxls8962af-core.c
··· 159 159 struct fxls8962af_data { 160 160 struct regmap *regmap; 161 161 const struct fxls8962af_chip_info *chip_info; 162 - struct regulator *vdd_reg; 163 162 struct { 164 163 __le16 channels[3]; 165 164 s64 ts __aligned(8); ··· 1050 1051 return IRQ_NONE; 1051 1052 } 1052 1053 1053 - static void fxls8962af_regulator_disable(void *data_ptr) 1054 - { 1055 - struct fxls8962af_data *data = data_ptr; 1056 - 1057 - regulator_disable(data->vdd_reg); 1058 - } 1059 - 1060 1054 static void fxls8962af_pm_disable(void *dev_ptr) 1061 1055 { 1062 1056 struct device *dev = dev_ptr; ··· 1163 1171 if (ret) 1164 1172 return ret; 1165 1173 1166 - data->vdd_reg = devm_regulator_get(dev, "vdd"); 1167 - if (IS_ERR(data->vdd_reg)) 1168 - return dev_err_probe(dev, PTR_ERR(data->vdd_reg), 1169 - "Failed to get vdd regulator\n"); 1170 - 1171 - ret = regulator_enable(data->vdd_reg); 1172 - if (ret) { 1173 - dev_err(dev, "Failed to enable vdd regulator: %d\n", ret); 1174 - return ret; 1175 - } 1176 - 1177 - ret = devm_add_action_or_reset(dev, fxls8962af_regulator_disable, data); 1174 + ret = devm_regulator_get_enable(dev, "vdd"); 1178 1175 if (ret) 1179 - return ret; 1176 + return dev_err_probe(dev, ret, 1177 + "Failed to get vdd regulator\n"); 1180 1178 1181 1179 ret = regmap_read(data->regmap, FXLS8962AF_WHO_AM_I, &reg); 1182 1180 if (ret) ··· 1223 1241 } 1224 1242 EXPORT_SYMBOL_NS_GPL(fxls8962af_core_probe, IIO_FXLS8962AF); 1225 1243 1226 - static int __maybe_unused fxls8962af_runtime_suspend(struct device *dev) 1244 + static int fxls8962af_runtime_suspend(struct device *dev) 1227 1245 { 1228 1246 struct fxls8962af_data *data = iio_priv(dev_get_drvdata(dev)); 1229 1247 int ret; ··· 1237 1255 return 0; 1238 1256 } 1239 1257 1240 - static int __maybe_unused fxls8962af_runtime_resume(struct device *dev) 1258 + static int fxls8962af_runtime_resume(struct device *dev) 1241 1259 { 1242 1260 struct fxls8962af_data *data = iio_priv(dev_get_drvdata(dev)); 1243 1261 1244 1262 return fxls8962af_active(data); 1245 1263 } 1246 1264 1247 - static int __maybe_unused fxls8962af_suspend(struct device *dev) 1265 + static int fxls8962af_suspend(struct device *dev) 1248 1266 { 1249 1267 struct iio_dev *indio_dev = dev_get_drvdata(dev); 1250 1268 struct fxls8962af_data *data = iio_priv(indio_dev); ··· 1265 1283 return 0; 1266 1284 } 1267 1285 1268 - static int __maybe_unused fxls8962af_resume(struct device *dev) 1286 + static int fxls8962af_resume(struct device *dev) 1269 1287 { 1270 1288 struct iio_dev *indio_dev = dev_get_drvdata(dev); 1271 1289 struct fxls8962af_data *data = iio_priv(indio_dev); ··· 1282 1300 return 0; 1283 1301 } 1284 1302 1285 - const struct dev_pm_ops fxls8962af_pm_ops = { 1286 - SET_SYSTEM_SLEEP_PM_OPS(fxls8962af_suspend, fxls8962af_resume) 1287 - SET_RUNTIME_PM_OPS(fxls8962af_runtime_suspend, 1288 - fxls8962af_runtime_resume, NULL) 1303 + EXPORT_NS_GPL_DEV_PM_OPS(fxls8962af_pm_ops, IIO_FXLS8962AF) = { 1304 + SYSTEM_SLEEP_PM_OPS(fxls8962af_suspend, fxls8962af_resume) 1305 + RUNTIME_PM_OPS(fxls8962af_runtime_suspend, fxls8962af_runtime_resume, NULL) 1289 1306 }; 1290 - EXPORT_SYMBOL_NS_GPL(fxls8962af_pm_ops, IIO_FXLS8962AF); 1291 1307 1292 1308 MODULE_AUTHOR("Sean Nyekjaer <sean@geanix.com>"); 1293 1309 MODULE_DESCRIPTION("NXP FXLS8962AF/FXLS8964AF accelerometer driver");
+1 -1
drivers/iio/accel/fxls8962af-i2c.c
··· 45 45 .driver = { 46 46 .name = "fxls8962af_i2c", 47 47 .of_match_table = fxls8962af_of_match, 48 - .pm = &fxls8962af_pm_ops, 48 + .pm = pm_ptr(&fxls8962af_pm_ops), 49 49 }, 50 50 .probe_new = fxls8962af_probe, 51 51 .id_table = fxls8962af_id,
+1 -1
drivers/iio/accel/fxls8962af-spi.c
··· 44 44 static struct spi_driver fxls8962af_driver = { 45 45 .driver = { 46 46 .name = "fxls8962af_spi", 47 - .pm = &fxls8962af_pm_ops, 47 + .pm = pm_ptr(&fxls8962af_pm_ops), 48 48 .of_match_table = fxls8962af_spi_of_match, 49 49 }, 50 50 .probe = fxls8962af_probe,
+51
drivers/iio/accel/kionix-kx022a-i2c.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2022 ROHM Semiconductors 4 + * 5 + * ROHM/KIONIX KX022A accelerometer driver 6 + */ 7 + 8 + #include <linux/i2c.h> 9 + #include <linux/interrupt.h> 10 + #include <linux/module.h> 11 + #include <linux/regmap.h> 12 + 13 + #include "kionix-kx022a.h" 14 + 15 + static int kx022a_i2c_probe(struct i2c_client *i2c) 16 + { 17 + struct device *dev = &i2c->dev; 18 + struct regmap *regmap; 19 + 20 + if (!i2c->irq) { 21 + dev_err(dev, "No IRQ configured\n"); 22 + return -EINVAL; 23 + } 24 + 25 + regmap = devm_regmap_init_i2c(i2c, &kx022a_regmap); 26 + if (IS_ERR(regmap)) 27 + return dev_err_probe(dev, PTR_ERR(regmap), 28 + "Failed to initialize Regmap\n"); 29 + 30 + return kx022a_probe_internal(dev); 31 + } 32 + 33 + static const struct of_device_id kx022a_of_match[] = { 34 + { .compatible = "kionix,kx022a", }, 35 + { } 36 + }; 37 + MODULE_DEVICE_TABLE(of, kx022a_of_match); 38 + 39 + static struct i2c_driver kx022a_i2c_driver = { 40 + .driver = { 41 + .name = "kx022a-i2c", 42 + .of_match_table = kx022a_of_match, 43 + }, 44 + .probe_new = kx022a_i2c_probe, 45 + }; 46 + module_i2c_driver(kx022a_i2c_driver); 47 + 48 + MODULE_DESCRIPTION("ROHM/Kionix KX022A accelerometer driver"); 49 + MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>"); 50 + MODULE_LICENSE("GPL"); 51 + MODULE_IMPORT_NS(IIO_KX022A);
+58
drivers/iio/accel/kionix-kx022a-spi.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2022 ROHM Semiconductors 4 + * 5 + * ROHM/KIONIX KX022A accelerometer driver 6 + */ 7 + 8 + #include <linux/interrupt.h> 9 + #include <linux/module.h> 10 + #include <linux/regmap.h> 11 + #include <linux/spi/spi.h> 12 + 13 + #include "kionix-kx022a.h" 14 + 15 + static int kx022a_spi_probe(struct spi_device *spi) 16 + { 17 + struct device *dev = &spi->dev; 18 + struct regmap *regmap; 19 + 20 + if (!spi->irq) { 21 + dev_err(dev, "No IRQ configured\n"); 22 + return -EINVAL; 23 + } 24 + 25 + regmap = devm_regmap_init_spi(spi, &kx022a_regmap); 26 + if (IS_ERR(regmap)) 27 + return dev_err_probe(dev, PTR_ERR(regmap), 28 + "Failed to initialize Regmap\n"); 29 + 30 + return kx022a_probe_internal(dev); 31 + } 32 + 33 + static const struct spi_device_id kx022a_id[] = { 34 + { "kx022a" }, 35 + { } 36 + }; 37 + MODULE_DEVICE_TABLE(spi, kx022a_id); 38 + 39 + static const struct of_device_id kx022a_of_match[] = { 40 + { .compatible = "kionix,kx022a", }, 41 + { } 42 + }; 43 + MODULE_DEVICE_TABLE(of, kx022a_of_match); 44 + 45 + static struct spi_driver kx022a_spi_driver = { 46 + .driver = { 47 + .name = "kx022a-spi", 48 + .of_match_table = kx022a_of_match, 49 + }, 50 + .probe = kx022a_spi_probe, 51 + .id_table = kx022a_id, 52 + }; 53 + module_spi_driver(kx022a_spi_driver); 54 + 55 + MODULE_DESCRIPTION("ROHM/Kionix kx022A accelerometer driver"); 56 + MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>"); 57 + MODULE_LICENSE("GPL"); 58 + MODULE_IMPORT_NS(IIO_KX022A);
+1142
drivers/iio/accel/kionix-kx022a.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2022 ROHM Semiconductors 4 + * 5 + * ROHM/KIONIX KX022A accelerometer driver 6 + */ 7 + 8 + #include <linux/delay.h> 9 + #include <linux/device.h> 10 + #include <linux/interrupt.h> 11 + #include <linux/module.h> 12 + #include <linux/moduleparam.h> 13 + #include <linux/mutex.h> 14 + #include <linux/property.h> 15 + #include <linux/regmap.h> 16 + #include <linux/regulator/consumer.h> 17 + #include <linux/slab.h> 18 + #include <linux/string_helpers.h> 19 + #include <linux/units.h> 20 + 21 + #include <linux/iio/iio.h> 22 + #include <linux/iio/sysfs.h> 23 + #include <linux/iio/trigger.h> 24 + #include <linux/iio/trigger_consumer.h> 25 + #include <linux/iio/triggered_buffer.h> 26 + 27 + #include "kionix-kx022a.h" 28 + 29 + /* 30 + * The KX022A has FIFO which can store 43 samples of HiRes data from 2 31 + * channels. This equals to 43 (samples) * 3 (channels) * 2 (bytes/sample) to 32 + * 258 bytes of sample data. The quirk to know is that the amount of bytes in 33 + * the FIFO is advertised via 8 bit register (max value 255). The thing to note 34 + * is that full 258 bytes of data is indicated using the max value 255. 35 + */ 36 + #define KX022A_FIFO_LENGTH 43 37 + #define KX022A_FIFO_FULL_VALUE 255 38 + #define KX022A_SOFT_RESET_WAIT_TIME_US (5 * USEC_PER_MSEC) 39 + #define KX022A_SOFT_RESET_TOTAL_WAIT_TIME_US (500 * USEC_PER_MSEC) 40 + 41 + /* 3 axis, 2 bytes of data for each of the axis */ 42 + #define KX022A_FIFO_SAMPLES_SIZE_BYTES 6 43 + #define KX022A_FIFO_MAX_BYTES \ 44 + (KX022A_FIFO_LENGTH * KX022A_FIFO_SAMPLES_SIZE_BYTES) 45 + 46 + enum { 47 + KX022A_STATE_SAMPLE, 48 + KX022A_STATE_FIFO, 49 + }; 50 + 51 + /* Regmap configs */ 52 + static const struct regmap_range kx022a_volatile_ranges[] = { 53 + { 54 + .range_min = KX022A_REG_XHP_L, 55 + .range_max = KX022A_REG_COTR, 56 + }, { 57 + .range_min = KX022A_REG_TSCP, 58 + .range_max = KX022A_REG_INT_REL, 59 + }, { 60 + /* The reset bit will be cleared by sensor */ 61 + .range_min = KX022A_REG_CNTL2, 62 + .range_max = KX022A_REG_CNTL2, 63 + }, { 64 + .range_min = KX022A_REG_BUF_STATUS_1, 65 + .range_max = KX022A_REG_BUF_READ, 66 + }, 67 + }; 68 + 69 + static const struct regmap_access_table kx022a_volatile_regs = { 70 + .yes_ranges = &kx022a_volatile_ranges[0], 71 + .n_yes_ranges = ARRAY_SIZE(kx022a_volatile_ranges), 72 + }; 73 + 74 + static const struct regmap_range kx022a_precious_ranges[] = { 75 + { 76 + .range_min = KX022A_REG_INT_REL, 77 + .range_max = KX022A_REG_INT_REL, 78 + }, 79 + }; 80 + 81 + static const struct regmap_access_table kx022a_precious_regs = { 82 + .yes_ranges = &kx022a_precious_ranges[0], 83 + .n_yes_ranges = ARRAY_SIZE(kx022a_precious_ranges), 84 + }; 85 + 86 + /* 87 + * The HW does not set WHO_AM_I reg as read-only but we don't want to write it 88 + * so we still include it in the read-only ranges. 89 + */ 90 + static const struct regmap_range kx022a_read_only_ranges[] = { 91 + { 92 + .range_min = KX022A_REG_XHP_L, 93 + .range_max = KX022A_REG_INT_REL, 94 + }, { 95 + .range_min = KX022A_REG_BUF_STATUS_1, 96 + .range_max = KX022A_REG_BUF_STATUS_2, 97 + }, { 98 + .range_min = KX022A_REG_BUF_READ, 99 + .range_max = KX022A_REG_BUF_READ, 100 + }, 101 + }; 102 + 103 + static const struct regmap_access_table kx022a_ro_regs = { 104 + .no_ranges = &kx022a_read_only_ranges[0], 105 + .n_no_ranges = ARRAY_SIZE(kx022a_read_only_ranges), 106 + }; 107 + 108 + static const struct regmap_range kx022a_write_only_ranges[] = { 109 + { 110 + .range_min = KX022A_REG_BTS_WUF_TH, 111 + .range_max = KX022A_REG_BTS_WUF_TH, 112 + }, { 113 + .range_min = KX022A_REG_MAN_WAKE, 114 + .range_max = KX022A_REG_MAN_WAKE, 115 + }, { 116 + .range_min = KX022A_REG_SELF_TEST, 117 + .range_max = KX022A_REG_SELF_TEST, 118 + }, { 119 + .range_min = KX022A_REG_BUF_CLEAR, 120 + .range_max = KX022A_REG_BUF_CLEAR, 121 + }, 122 + }; 123 + 124 + static const struct regmap_access_table kx022a_wo_regs = { 125 + .no_ranges = &kx022a_write_only_ranges[0], 126 + .n_no_ranges = ARRAY_SIZE(kx022a_write_only_ranges), 127 + }; 128 + 129 + static const struct regmap_range kx022a_noinc_read_ranges[] = { 130 + { 131 + .range_min = KX022A_REG_BUF_READ, 132 + .range_max = KX022A_REG_BUF_READ, 133 + }, 134 + }; 135 + 136 + static const struct regmap_access_table kx022a_nir_regs = { 137 + .yes_ranges = &kx022a_noinc_read_ranges[0], 138 + .n_yes_ranges = ARRAY_SIZE(kx022a_noinc_read_ranges), 139 + }; 140 + 141 + const struct regmap_config kx022a_regmap = { 142 + .reg_bits = 8, 143 + .val_bits = 8, 144 + .volatile_table = &kx022a_volatile_regs, 145 + .rd_table = &kx022a_wo_regs, 146 + .wr_table = &kx022a_ro_regs, 147 + .rd_noinc_table = &kx022a_nir_regs, 148 + .precious_table = &kx022a_precious_regs, 149 + .max_register = KX022A_MAX_REGISTER, 150 + .cache_type = REGCACHE_RBTREE, 151 + }; 152 + EXPORT_SYMBOL_NS_GPL(kx022a_regmap, IIO_KX022A); 153 + 154 + struct kx022a_data { 155 + struct regmap *regmap; 156 + struct iio_trigger *trig; 157 + struct device *dev; 158 + struct iio_mount_matrix orientation; 159 + int64_t timestamp, old_timestamp; 160 + 161 + int irq; 162 + int inc_reg; 163 + int ien_reg; 164 + 165 + unsigned int g_range; 166 + unsigned int state; 167 + unsigned int odr_ns; 168 + 169 + bool trigger_enabled; 170 + /* 171 + * Prevent toggling the sensor stby/active state (PC1 bit) in the 172 + * middle of a configuration, or when the fifo is enabled. Also, 173 + * protect the data stored/retrieved from this structure from 174 + * concurrent accesses. 175 + */ 176 + struct mutex mutex; 177 + u8 watermark; 178 + 179 + /* 3 x 16bit accel data + timestamp */ 180 + __le16 buffer[8] __aligned(IIO_DMA_MINALIGN); 181 + struct { 182 + __le16 channels[3]; 183 + s64 ts __aligned(8); 184 + } scan; 185 + }; 186 + 187 + static const struct iio_mount_matrix * 188 + kx022a_get_mount_matrix(const struct iio_dev *idev, 189 + const struct iio_chan_spec *chan) 190 + { 191 + struct kx022a_data *data = iio_priv(idev); 192 + 193 + return &data->orientation; 194 + } 195 + 196 + enum { 197 + AXIS_X, 198 + AXIS_Y, 199 + AXIS_Z, 200 + AXIS_MAX 201 + }; 202 + 203 + static const unsigned long kx022a_scan_masks[] = { 204 + BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z), 0 205 + }; 206 + 207 + static const struct iio_chan_spec_ext_info kx022a_ext_info[] = { 208 + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, kx022a_get_mount_matrix), 209 + { } 210 + }; 211 + 212 + #define KX022A_ACCEL_CHAN(axis, index) \ 213 + { \ 214 + .type = IIO_ACCEL, \ 215 + .modified = 1, \ 216 + .channel2 = IIO_MOD_##axis, \ 217 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 218 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 219 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 220 + .info_mask_shared_by_type_available = \ 221 + BIT(IIO_CHAN_INFO_SCALE) | \ 222 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 223 + .ext_info = kx022a_ext_info, \ 224 + .address = KX022A_REG_##axis##OUT_L, \ 225 + .scan_index = index, \ 226 + .scan_type = { \ 227 + .sign = 's', \ 228 + .realbits = 16, \ 229 + .storagebits = 16, \ 230 + .endianness = IIO_LE, \ 231 + }, \ 232 + } 233 + 234 + static const struct iio_chan_spec kx022a_channels[] = { 235 + KX022A_ACCEL_CHAN(X, 0), 236 + KX022A_ACCEL_CHAN(Y, 1), 237 + KX022A_ACCEL_CHAN(Z, 2), 238 + IIO_CHAN_SOFT_TIMESTAMP(3), 239 + }; 240 + 241 + /* 242 + * The sensor HW can support ODR up to 1600 Hz, which is beyond what most of the 243 + * Linux CPUs can handle without dropping samples. Also, the low power mode is 244 + * not available for higher sample rates. Thus, the driver only supports 200 Hz 245 + * and slower ODRs. The slowest is 0.78 Hz. 246 + */ 247 + static const int kx022a_accel_samp_freq_table[][2] = { 248 + { 0, 780000 }, 249 + { 1, 563000 }, 250 + { 3, 125000 }, 251 + { 6, 250000 }, 252 + { 12, 500000 }, 253 + { 25, 0 }, 254 + { 50, 0 }, 255 + { 100, 0 }, 256 + { 200, 0 }, 257 + }; 258 + 259 + static const unsigned int kx022a_odrs[] = { 260 + 1282051282, 261 + 639795266, 262 + 320 * MEGA, 263 + 160 * MEGA, 264 + 80 * MEGA, 265 + 40 * MEGA, 266 + 20 * MEGA, 267 + 10 * MEGA, 268 + 5 * MEGA, 269 + }; 270 + 271 + /* 272 + * range is typically +-2G/4G/8G/16G, distributed over the amount of bits. 273 + * The scale table can be calculated using 274 + * (range / 2^bits) * g = (range / 2^bits) * 9.80665 m/s^2 275 + * => KX022A uses 16 bit (HiRes mode - assume the low 8 bits are zeroed 276 + * in low-power mode(?) ) 277 + * => +/-2G => 4 / 2^16 * 9,80665 * 10^6 (to scale to micro) 278 + * => +/-2G - 598.550415 279 + * +/-4G - 1197.10083 280 + * +/-8G - 2394.20166 281 + * +/-16G - 4788.40332 282 + */ 283 + static const int kx022a_scale_table[][2] = { 284 + { 598, 550415 }, 285 + { 1197, 100830 }, 286 + { 2394, 201660 }, 287 + { 4788, 403320 }, 288 + }; 289 + 290 + static int kx022a_read_avail(struct iio_dev *indio_dev, 291 + struct iio_chan_spec const *chan, 292 + const int **vals, int *type, int *length, 293 + long mask) 294 + { 295 + switch (mask) { 296 + case IIO_CHAN_INFO_SAMP_FREQ: 297 + *vals = (const int *)kx022a_accel_samp_freq_table; 298 + *length = ARRAY_SIZE(kx022a_accel_samp_freq_table) * 299 + ARRAY_SIZE(kx022a_accel_samp_freq_table[0]); 300 + *type = IIO_VAL_INT_PLUS_MICRO; 301 + return IIO_AVAIL_LIST; 302 + case IIO_CHAN_INFO_SCALE: 303 + *vals = (const int *)kx022a_scale_table; 304 + *length = ARRAY_SIZE(kx022a_scale_table) * 305 + ARRAY_SIZE(kx022a_scale_table[0]); 306 + *type = IIO_VAL_INT_PLUS_MICRO; 307 + return IIO_AVAIL_LIST; 308 + default: 309 + return -EINVAL; 310 + } 311 + } 312 + 313 + #define KX022A_DEFAULT_PERIOD_NS (20 * NSEC_PER_MSEC) 314 + 315 + static void kx022a_reg2freq(unsigned int val, int *val1, int *val2) 316 + { 317 + *val1 = kx022a_accel_samp_freq_table[val & KX022A_MASK_ODR][0]; 318 + *val2 = kx022a_accel_samp_freq_table[val & KX022A_MASK_ODR][1]; 319 + } 320 + 321 + static void kx022a_reg2scale(unsigned int val, unsigned int *val1, 322 + unsigned int *val2) 323 + { 324 + val &= KX022A_MASK_GSEL; 325 + val >>= KX022A_GSEL_SHIFT; 326 + 327 + *val1 = kx022a_scale_table[val][0]; 328 + *val2 = kx022a_scale_table[val][1]; 329 + } 330 + 331 + static int kx022a_turn_on_off_unlocked(struct kx022a_data *data, bool on) 332 + { 333 + int ret; 334 + 335 + if (on) 336 + ret = regmap_set_bits(data->regmap, KX022A_REG_CNTL, 337 + KX022A_MASK_PC1); 338 + else 339 + ret = regmap_clear_bits(data->regmap, KX022A_REG_CNTL, 340 + KX022A_MASK_PC1); 341 + if (ret) 342 + dev_err(data->dev, "Turn %s fail %d\n", str_on_off(on), ret); 343 + 344 + return ret; 345 + 346 + } 347 + 348 + static int kx022a_turn_off_lock(struct kx022a_data *data) 349 + { 350 + int ret; 351 + 352 + mutex_lock(&data->mutex); 353 + ret = kx022a_turn_on_off_unlocked(data, false); 354 + if (ret) 355 + mutex_unlock(&data->mutex); 356 + 357 + return ret; 358 + } 359 + 360 + static int kx022a_turn_on_unlock(struct kx022a_data *data) 361 + { 362 + int ret; 363 + 364 + ret = kx022a_turn_on_off_unlocked(data, true); 365 + mutex_unlock(&data->mutex); 366 + 367 + return ret; 368 + } 369 + 370 + static int kx022a_write_raw(struct iio_dev *idev, 371 + struct iio_chan_spec const *chan, 372 + int val, int val2, long mask) 373 + { 374 + struct kx022a_data *data = iio_priv(idev); 375 + int ret, n; 376 + 377 + /* 378 + * We should not allow changing scale or frequency when FIFO is running 379 + * as it will mess the timestamp/scale for samples existing in the 380 + * buffer. If this turns out to be an issue we can later change logic 381 + * to internally flush the fifo before reconfiguring so the samples in 382 + * fifo keep matching the freq/scale settings. (Such setup could cause 383 + * issues if users trust the watermark to be reached within known 384 + * time-limit). 385 + */ 386 + ret = iio_device_claim_direct_mode(idev); 387 + if (ret) 388 + return ret; 389 + 390 + switch (mask) { 391 + case IIO_CHAN_INFO_SAMP_FREQ: 392 + n = ARRAY_SIZE(kx022a_accel_samp_freq_table); 393 + 394 + while (n--) 395 + if (val == kx022a_accel_samp_freq_table[n][0] && 396 + val2 == kx022a_accel_samp_freq_table[n][1]) 397 + break; 398 + if (n < 0) { 399 + ret = -EINVAL; 400 + goto unlock_out; 401 + } 402 + ret = kx022a_turn_off_lock(data); 403 + if (ret) 404 + break; 405 + 406 + ret = regmap_update_bits(data->regmap, 407 + KX022A_REG_ODCNTL, 408 + KX022A_MASK_ODR, n); 409 + data->odr_ns = kx022a_odrs[n]; 410 + kx022a_turn_on_unlock(data); 411 + break; 412 + case IIO_CHAN_INFO_SCALE: 413 + n = ARRAY_SIZE(kx022a_scale_table); 414 + 415 + while (n-- > 0) 416 + if (val == kx022a_scale_table[n][0] && 417 + val2 == kx022a_scale_table[n][1]) 418 + break; 419 + if (n < 0) { 420 + ret = -EINVAL; 421 + goto unlock_out; 422 + } 423 + 424 + ret = kx022a_turn_off_lock(data); 425 + if (ret) 426 + break; 427 + 428 + ret = regmap_update_bits(data->regmap, KX022A_REG_CNTL, 429 + KX022A_MASK_GSEL, 430 + n << KX022A_GSEL_SHIFT); 431 + kx022a_turn_on_unlock(data); 432 + break; 433 + default: 434 + ret = -EINVAL; 435 + break; 436 + } 437 + 438 + unlock_out: 439 + iio_device_release_direct_mode(idev); 440 + 441 + return ret; 442 + } 443 + 444 + static int kx022a_fifo_set_wmi(struct kx022a_data *data) 445 + { 446 + u8 threshold; 447 + 448 + threshold = data->watermark; 449 + 450 + return regmap_update_bits(data->regmap, KX022A_REG_BUF_CNTL1, 451 + KX022A_MASK_WM_TH, threshold); 452 + } 453 + 454 + static int kx022a_get_axis(struct kx022a_data *data, 455 + struct iio_chan_spec const *chan, 456 + int *val) 457 + { 458 + int ret; 459 + 460 + ret = regmap_bulk_read(data->regmap, chan->address, &data->buffer[0], 461 + sizeof(__le16)); 462 + if (ret) 463 + return ret; 464 + 465 + *val = le16_to_cpu(data->buffer[0]); 466 + 467 + return IIO_VAL_INT; 468 + } 469 + 470 + static int kx022a_read_raw(struct iio_dev *idev, 471 + struct iio_chan_spec const *chan, 472 + int *val, int *val2, long mask) 473 + { 474 + struct kx022a_data *data = iio_priv(idev); 475 + unsigned int regval; 476 + int ret; 477 + 478 + switch (mask) { 479 + case IIO_CHAN_INFO_RAW: 480 + ret = iio_device_claim_direct_mode(idev); 481 + if (ret) 482 + return ret; 483 + 484 + mutex_lock(&data->mutex); 485 + ret = kx022a_get_axis(data, chan, val); 486 + mutex_unlock(&data->mutex); 487 + 488 + iio_device_release_direct_mode(idev); 489 + 490 + return ret; 491 + 492 + case IIO_CHAN_INFO_SAMP_FREQ: 493 + ret = regmap_read(data->regmap, KX022A_REG_ODCNTL, &regval); 494 + if (ret) 495 + return ret; 496 + 497 + if ((regval & KX022A_MASK_ODR) > 498 + ARRAY_SIZE(kx022a_accel_samp_freq_table)) { 499 + dev_err(data->dev, "Invalid ODR\n"); 500 + return -EINVAL; 501 + } 502 + 503 + kx022a_reg2freq(regval, val, val2); 504 + 505 + return IIO_VAL_INT_PLUS_MICRO; 506 + 507 + case IIO_CHAN_INFO_SCALE: 508 + ret = regmap_read(data->regmap, KX022A_REG_CNTL, &regval); 509 + if (ret < 0) 510 + return ret; 511 + 512 + kx022a_reg2scale(regval, val, val2); 513 + 514 + return IIO_VAL_INT_PLUS_MICRO; 515 + } 516 + 517 + return -EINVAL; 518 + }; 519 + 520 + static int kx022a_validate_trigger(struct iio_dev *idev, 521 + struct iio_trigger *trig) 522 + { 523 + struct kx022a_data *data = iio_priv(idev); 524 + 525 + if (data->trig != trig) 526 + return -EINVAL; 527 + 528 + return 0; 529 + } 530 + 531 + static int kx022a_set_watermark(struct iio_dev *idev, unsigned int val) 532 + { 533 + struct kx022a_data *data = iio_priv(idev); 534 + 535 + if (val > KX022A_FIFO_LENGTH) 536 + val = KX022A_FIFO_LENGTH; 537 + 538 + mutex_lock(&data->mutex); 539 + data->watermark = val; 540 + mutex_unlock(&data->mutex); 541 + 542 + return 0; 543 + } 544 + 545 + static ssize_t hwfifo_enabled_show(struct device *dev, 546 + struct device_attribute *attr, 547 + char *buf) 548 + { 549 + struct iio_dev *idev = dev_to_iio_dev(dev); 550 + struct kx022a_data *data = iio_priv(idev); 551 + bool state; 552 + 553 + mutex_lock(&data->mutex); 554 + state = data->state; 555 + mutex_unlock(&data->mutex); 556 + 557 + return sysfs_emit(buf, "%d\n", state); 558 + } 559 + 560 + static ssize_t hwfifo_watermark_show(struct device *dev, 561 + struct device_attribute *attr, 562 + char *buf) 563 + { 564 + struct iio_dev *idev = dev_to_iio_dev(dev); 565 + struct kx022a_data *data = iio_priv(idev); 566 + int wm; 567 + 568 + mutex_lock(&data->mutex); 569 + wm = data->watermark; 570 + mutex_unlock(&data->mutex); 571 + 572 + return sysfs_emit(buf, "%d\n", wm); 573 + } 574 + 575 + static IIO_DEVICE_ATTR_RO(hwfifo_enabled, 0); 576 + static IIO_DEVICE_ATTR_RO(hwfifo_watermark, 0); 577 + 578 + static const struct iio_dev_attr *kx022a_fifo_attributes[] = { 579 + &iio_dev_attr_hwfifo_watermark, 580 + &iio_dev_attr_hwfifo_enabled, 581 + NULL 582 + }; 583 + 584 + static int kx022a_drop_fifo_contents(struct kx022a_data *data) 585 + { 586 + /* 587 + * We must clear the old time-stamp to avoid computing the timestamps 588 + * based on samples acquired when buffer was last enabled. 589 + * 590 + * We don't need to protect the timestamp as long as we are only 591 + * called from fifo-disable where we can guarantee the sensor is not 592 + * triggering interrupts and where the mutex is locked to prevent the 593 + * user-space access. 594 + */ 595 + data->timestamp = 0; 596 + 597 + return regmap_write(data->regmap, KX022A_REG_BUF_CLEAR, 0x0); 598 + } 599 + 600 + static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples, 601 + bool irq) 602 + { 603 + struct kx022a_data *data = iio_priv(idev); 604 + struct device *dev = regmap_get_device(data->regmap); 605 + __le16 buffer[KX022A_FIFO_LENGTH * 3]; 606 + uint64_t sample_period; 607 + int count, fifo_bytes; 608 + bool renable = false; 609 + int64_t tstamp; 610 + int ret, i; 611 + 612 + ret = regmap_read(data->regmap, KX022A_REG_BUF_STATUS_1, &fifo_bytes); 613 + if (ret) { 614 + dev_err(dev, "Error reading buffer status\n"); 615 + return ret; 616 + } 617 + 618 + /* Let's not overflow if we for some reason get bogus value from i2c */ 619 + if (fifo_bytes == KX022A_FIFO_FULL_VALUE) 620 + fifo_bytes = KX022A_FIFO_MAX_BYTES; 621 + 622 + if (fifo_bytes % KX022A_FIFO_SAMPLES_SIZE_BYTES) 623 + dev_warn(data->dev, "Bad FIFO alignment. Data may be corrupt\n"); 624 + 625 + count = fifo_bytes / KX022A_FIFO_SAMPLES_SIZE_BYTES; 626 + if (!count) 627 + return 0; 628 + 629 + /* 630 + * If we are being called from IRQ handler we know the stored timestamp 631 + * is fairly accurate for the last stored sample. Otherwise, if we are 632 + * called as a result of a read operation from userspace and hence 633 + * before the watermark interrupt was triggered, take a timestamp 634 + * now. We can fall anywhere in between two samples so the error in this 635 + * case is at most one sample period. 636 + */ 637 + if (!irq) { 638 + /* 639 + * We need to have the IRQ disabled or we risk of messing-up 640 + * the timestamps. If we are ran from IRQ, then the 641 + * IRQF_ONESHOT has us covered - but if we are ran by the 642 + * user-space read we need to disable the IRQ to be on a safe 643 + * side. We do this usng synchronous disable so that if the 644 + * IRQ thread is being ran on other CPU we wait for it to be 645 + * finished. 646 + */ 647 + disable_irq(data->irq); 648 + renable = true; 649 + 650 + data->old_timestamp = data->timestamp; 651 + data->timestamp = iio_get_time_ns(idev); 652 + } 653 + 654 + /* 655 + * Approximate timestamps for each of the sample based on the sampling 656 + * frequency, timestamp for last sample and number of samples. 657 + * 658 + * We'd better not use the current bandwidth settings to compute the 659 + * sample period. The real sample rate varies with the device and 660 + * small variation adds when we store a large number of samples. 661 + * 662 + * To avoid this issue we compute the actual sample period ourselves 663 + * based on the timestamp delta between the last two flush operations. 664 + */ 665 + if (data->old_timestamp) { 666 + sample_period = data->timestamp - data->old_timestamp; 667 + do_div(sample_period, count); 668 + } else { 669 + sample_period = data->odr_ns; 670 + } 671 + tstamp = data->timestamp - (count - 1) * sample_period; 672 + 673 + if (samples && count > samples) { 674 + /* 675 + * Here we leave some old samples to the buffer. We need to 676 + * adjust the timestamp to match the first sample in the buffer 677 + * or we will miscalculate the sample_period at next round. 678 + */ 679 + data->timestamp -= (count - samples) * sample_period; 680 + count = samples; 681 + } 682 + 683 + fifo_bytes = count * KX022A_FIFO_SAMPLES_SIZE_BYTES; 684 + ret = regmap_noinc_read(data->regmap, KX022A_REG_BUF_READ, 685 + &buffer[0], fifo_bytes); 686 + if (ret) 687 + goto renable_out; 688 + 689 + for (i = 0; i < count; i++) { 690 + __le16 *sam = &buffer[i * 3]; 691 + __le16 *chs; 692 + int bit; 693 + 694 + chs = &data->scan.channels[0]; 695 + for_each_set_bit(bit, idev->active_scan_mask, AXIS_MAX) 696 + chs[bit] = sam[bit]; 697 + 698 + iio_push_to_buffers_with_timestamp(idev, &data->scan, tstamp); 699 + 700 + tstamp += sample_period; 701 + } 702 + 703 + ret = count; 704 + 705 + renable_out: 706 + if (renable) 707 + enable_irq(data->irq); 708 + 709 + return ret; 710 + } 711 + 712 + static int kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples) 713 + { 714 + struct kx022a_data *data = iio_priv(idev); 715 + int ret; 716 + 717 + mutex_lock(&data->mutex); 718 + ret = __kx022a_fifo_flush(idev, samples, false); 719 + mutex_unlock(&data->mutex); 720 + 721 + return ret; 722 + } 723 + 724 + static const struct iio_info kx022a_info = { 725 + .read_raw = &kx022a_read_raw, 726 + .write_raw = &kx022a_write_raw, 727 + .read_avail = &kx022a_read_avail, 728 + 729 + .validate_trigger = kx022a_validate_trigger, 730 + .hwfifo_set_watermark = kx022a_set_watermark, 731 + .hwfifo_flush_to_buffer = kx022a_fifo_flush, 732 + }; 733 + 734 + static int kx022a_set_drdy_irq(struct kx022a_data *data, bool en) 735 + { 736 + if (en) 737 + return regmap_set_bits(data->regmap, KX022A_REG_CNTL, 738 + KX022A_MASK_DRDY); 739 + 740 + return regmap_clear_bits(data->regmap, KX022A_REG_CNTL, 741 + KX022A_MASK_DRDY); 742 + } 743 + 744 + static int kx022a_prepare_irq_pin(struct kx022a_data *data) 745 + { 746 + /* Enable IRQ1 pin. Set polarity to active low */ 747 + int mask = KX022A_MASK_IEN | KX022A_MASK_IPOL | 748 + KX022A_MASK_ITYP; 749 + int val = KX022A_MASK_IEN | KX022A_IPOL_LOW | 750 + KX022A_ITYP_LEVEL; 751 + int ret; 752 + 753 + ret = regmap_update_bits(data->regmap, data->inc_reg, mask, val); 754 + if (ret) 755 + return ret; 756 + 757 + /* We enable WMI to IRQ pin only at buffer_enable */ 758 + mask = KX022A_MASK_INS2_DRDY; 759 + 760 + return regmap_set_bits(data->regmap, data->ien_reg, mask); 761 + } 762 + 763 + static int kx022a_fifo_disable(struct kx022a_data *data) 764 + { 765 + int ret = 0; 766 + 767 + ret = kx022a_turn_off_lock(data); 768 + if (ret) 769 + return ret; 770 + 771 + ret = regmap_clear_bits(data->regmap, data->ien_reg, KX022A_MASK_WMI); 772 + if (ret) 773 + goto unlock_out; 774 + 775 + ret = regmap_clear_bits(data->regmap, KX022A_REG_BUF_CNTL2, 776 + KX022A_MASK_BUF_EN); 777 + if (ret) 778 + goto unlock_out; 779 + 780 + data->state &= ~KX022A_STATE_FIFO; 781 + 782 + kx022a_drop_fifo_contents(data); 783 + 784 + return kx022a_turn_on_unlock(data); 785 + 786 + unlock_out: 787 + mutex_unlock(&data->mutex); 788 + 789 + return ret; 790 + } 791 + 792 + static int kx022a_buffer_predisable(struct iio_dev *idev) 793 + { 794 + struct kx022a_data *data = iio_priv(idev); 795 + 796 + if (iio_device_get_current_mode(idev) == INDIO_BUFFER_TRIGGERED) 797 + return 0; 798 + 799 + return kx022a_fifo_disable(data); 800 + } 801 + 802 + static int kx022a_fifo_enable(struct kx022a_data *data) 803 + { 804 + int ret; 805 + 806 + ret = kx022a_turn_off_lock(data); 807 + if (ret) 808 + return ret; 809 + 810 + /* Update watermark to HW */ 811 + ret = kx022a_fifo_set_wmi(data); 812 + if (ret) 813 + goto unlock_out; 814 + 815 + /* Enable buffer */ 816 + ret = regmap_set_bits(data->regmap, KX022A_REG_BUF_CNTL2, 817 + KX022A_MASK_BUF_EN); 818 + if (ret) 819 + goto unlock_out; 820 + 821 + data->state |= KX022A_STATE_FIFO; 822 + ret = regmap_set_bits(data->regmap, data->ien_reg, 823 + KX022A_MASK_WMI); 824 + if (ret) 825 + goto unlock_out; 826 + 827 + return kx022a_turn_on_unlock(data); 828 + 829 + unlock_out: 830 + mutex_unlock(&data->mutex); 831 + 832 + return ret; 833 + } 834 + 835 + static int kx022a_buffer_postenable(struct iio_dev *idev) 836 + { 837 + struct kx022a_data *data = iio_priv(idev); 838 + 839 + /* 840 + * If we use data-ready trigger, then the IRQ masks should be handled by 841 + * trigger enable and the hardware buffer is not used but we just update 842 + * results to the IIO fifo when data-ready triggers. 843 + */ 844 + if (iio_device_get_current_mode(idev) == INDIO_BUFFER_TRIGGERED) 845 + return 0; 846 + 847 + return kx022a_fifo_enable(data); 848 + } 849 + 850 + static const struct iio_buffer_setup_ops kx022a_buffer_ops = { 851 + .postenable = kx022a_buffer_postenable, 852 + .predisable = kx022a_buffer_predisable, 853 + }; 854 + 855 + static irqreturn_t kx022a_trigger_handler(int irq, void *p) 856 + { 857 + struct iio_poll_func *pf = p; 858 + struct iio_dev *idev = pf->indio_dev; 859 + struct kx022a_data *data = iio_priv(idev); 860 + int ret; 861 + 862 + ret = regmap_bulk_read(data->regmap, KX022A_REG_XOUT_L, data->buffer, 863 + KX022A_FIFO_SAMPLES_SIZE_BYTES); 864 + if (ret < 0) 865 + goto err_read; 866 + 867 + iio_push_to_buffers_with_timestamp(idev, data->buffer, pf->timestamp); 868 + err_read: 869 + iio_trigger_notify_done(idev->trig); 870 + 871 + return IRQ_HANDLED; 872 + } 873 + 874 + /* Get timestamps and wake the thread if we need to read data */ 875 + static irqreturn_t kx022a_irq_handler(int irq, void *private) 876 + { 877 + struct iio_dev *idev = private; 878 + struct kx022a_data *data = iio_priv(idev); 879 + 880 + data->old_timestamp = data->timestamp; 881 + data->timestamp = iio_get_time_ns(idev); 882 + 883 + if (data->state & KX022A_STATE_FIFO || data->trigger_enabled) 884 + return IRQ_WAKE_THREAD; 885 + 886 + return IRQ_NONE; 887 + } 888 + 889 + /* 890 + * WMI and data-ready IRQs are acked when results are read. If we add 891 + * TILT/WAKE or other IRQs - then we may need to implement the acking 892 + * (which is racy). 893 + */ 894 + static irqreturn_t kx022a_irq_thread_handler(int irq, void *private) 895 + { 896 + struct iio_dev *idev = private; 897 + struct kx022a_data *data = iio_priv(idev); 898 + irqreturn_t ret = IRQ_NONE; 899 + 900 + mutex_lock(&data->mutex); 901 + 902 + if (data->trigger_enabled) { 903 + iio_trigger_poll_chained(data->trig); 904 + ret = IRQ_HANDLED; 905 + } 906 + 907 + if (data->state & KX022A_STATE_FIFO) { 908 + int ok; 909 + 910 + ok = __kx022a_fifo_flush(idev, KX022A_FIFO_LENGTH, true); 911 + if (ok > 0) 912 + ret = IRQ_HANDLED; 913 + } 914 + 915 + mutex_unlock(&data->mutex); 916 + 917 + return ret; 918 + } 919 + 920 + static int kx022a_trigger_set_state(struct iio_trigger *trig, 921 + bool state) 922 + { 923 + struct kx022a_data *data = iio_trigger_get_drvdata(trig); 924 + int ret = 0; 925 + 926 + mutex_lock(&data->mutex); 927 + 928 + if (data->trigger_enabled == state) 929 + goto unlock_out; 930 + 931 + if (data->state & KX022A_STATE_FIFO) { 932 + dev_warn(data->dev, "Can't set trigger when FIFO enabled\n"); 933 + ret = -EBUSY; 934 + goto unlock_out; 935 + } 936 + 937 + ret = kx022a_turn_on_off_unlocked(data, false); 938 + if (ret) 939 + goto unlock_out; 940 + 941 + data->trigger_enabled = state; 942 + ret = kx022a_set_drdy_irq(data, state); 943 + if (ret) 944 + goto unlock_out; 945 + 946 + ret = kx022a_turn_on_off_unlocked(data, true); 947 + 948 + unlock_out: 949 + mutex_unlock(&data->mutex); 950 + 951 + return ret; 952 + } 953 + 954 + static const struct iio_trigger_ops kx022a_trigger_ops = { 955 + .set_trigger_state = kx022a_trigger_set_state, 956 + }; 957 + 958 + static int kx022a_chip_init(struct kx022a_data *data) 959 + { 960 + int ret, val; 961 + 962 + /* Reset the senor */ 963 + ret = regmap_write(data->regmap, KX022A_REG_CNTL2, KX022A_MASK_SRST); 964 + if (ret) 965 + return ret; 966 + 967 + /* 968 + * I've seen I2C read failures if we poll too fast after the sensor 969 + * reset. Slight delay gives I2C block the time to recover. 970 + */ 971 + msleep(1); 972 + 973 + ret = regmap_read_poll_timeout(data->regmap, KX022A_REG_CNTL2, val, 974 + !(val & KX022A_MASK_SRST), 975 + KX022A_SOFT_RESET_WAIT_TIME_US, 976 + KX022A_SOFT_RESET_TOTAL_WAIT_TIME_US); 977 + if (ret) { 978 + dev_err(data->dev, "Sensor reset %s\n", 979 + val & KX022A_MASK_SRST ? "timeout" : "fail#"); 980 + return ret; 981 + } 982 + 983 + ret = regmap_reinit_cache(data->regmap, &kx022a_regmap); 984 + if (ret) { 985 + dev_err(data->dev, "Failed to reinit reg cache\n"); 986 + return ret; 987 + } 988 + 989 + /* set data res 16bit */ 990 + ret = regmap_set_bits(data->regmap, KX022A_REG_BUF_CNTL2, 991 + KX022A_MASK_BRES16); 992 + if (ret) { 993 + dev_err(data->dev, "Failed to set data resolution\n"); 994 + return ret; 995 + } 996 + 997 + return kx022a_prepare_irq_pin(data); 998 + } 999 + 1000 + int kx022a_probe_internal(struct device *dev) 1001 + { 1002 + static const char * const regulator_names[] = {"io-vdd", "vdd"}; 1003 + struct iio_trigger *indio_trig; 1004 + struct fwnode_handle *fwnode; 1005 + struct kx022a_data *data; 1006 + struct regmap *regmap; 1007 + unsigned int chip_id; 1008 + struct iio_dev *idev; 1009 + int ret, irq; 1010 + char *name; 1011 + 1012 + regmap = dev_get_regmap(dev, NULL); 1013 + if (!regmap) { 1014 + dev_err(dev, "no regmap\n"); 1015 + return -EINVAL; 1016 + } 1017 + 1018 + fwnode = dev_fwnode(dev); 1019 + if (!fwnode) 1020 + return -ENODEV; 1021 + 1022 + idev = devm_iio_device_alloc(dev, sizeof(*data)); 1023 + if (!idev) 1024 + return -ENOMEM; 1025 + 1026 + data = iio_priv(idev); 1027 + 1028 + /* 1029 + * VDD is the analog and digital domain voltage supply and 1030 + * IO_VDD is the digital I/O voltage supply. 1031 + */ 1032 + ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names), 1033 + regulator_names); 1034 + if (ret && ret != -ENODEV) 1035 + return dev_err_probe(dev, ret, "failed to enable regulator\n"); 1036 + 1037 + ret = regmap_read(regmap, KX022A_REG_WHO, &chip_id); 1038 + if (ret) 1039 + return dev_err_probe(dev, ret, "Failed to access sensor\n"); 1040 + 1041 + if (chip_id != KX022A_ID) { 1042 + dev_err(dev, "unsupported device 0x%x\n", chip_id); 1043 + return -EINVAL; 1044 + } 1045 + 1046 + irq = fwnode_irq_get_byname(fwnode, "INT1"); 1047 + if (irq > 0) { 1048 + data->inc_reg = KX022A_REG_INC1; 1049 + data->ien_reg = KX022A_REG_INC4; 1050 + } else { 1051 + irq = fwnode_irq_get_byname(fwnode, "INT2"); 1052 + if (irq <= 0) 1053 + return dev_err_probe(dev, irq, "No suitable IRQ\n"); 1054 + 1055 + data->inc_reg = KX022A_REG_INC5; 1056 + data->ien_reg = KX022A_REG_INC6; 1057 + } 1058 + 1059 + data->regmap = regmap; 1060 + data->dev = dev; 1061 + data->irq = irq; 1062 + data->odr_ns = KX022A_DEFAULT_PERIOD_NS; 1063 + mutex_init(&data->mutex); 1064 + 1065 + idev->channels = kx022a_channels; 1066 + idev->num_channels = ARRAY_SIZE(kx022a_channels); 1067 + idev->name = "kx022-accel"; 1068 + idev->info = &kx022a_info; 1069 + idev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; 1070 + idev->available_scan_masks = kx022a_scan_masks; 1071 + 1072 + /* Read the mounting matrix, if present */ 1073 + ret = iio_read_mount_matrix(dev, &data->orientation); 1074 + if (ret) 1075 + return ret; 1076 + 1077 + /* The sensor must be turned off for configuration */ 1078 + ret = kx022a_turn_off_lock(data); 1079 + if (ret) 1080 + return ret; 1081 + 1082 + ret = kx022a_chip_init(data); 1083 + if (ret) { 1084 + mutex_unlock(&data->mutex); 1085 + return ret; 1086 + } 1087 + 1088 + ret = kx022a_turn_on_unlock(data); 1089 + if (ret) 1090 + return ret; 1091 + 1092 + ret = devm_iio_triggered_buffer_setup_ext(dev, idev, 1093 + &iio_pollfunc_store_time, 1094 + kx022a_trigger_handler, 1095 + IIO_BUFFER_DIRECTION_IN, 1096 + &kx022a_buffer_ops, 1097 + kx022a_fifo_attributes); 1098 + 1099 + if (ret) 1100 + return dev_err_probe(data->dev, ret, 1101 + "iio_triggered_buffer_setup_ext FAIL\n"); 1102 + indio_trig = devm_iio_trigger_alloc(dev, "%sdata-rdy-dev%d", idev->name, 1103 + iio_device_id(idev)); 1104 + if (!indio_trig) 1105 + return -ENOMEM; 1106 + 1107 + data->trig = indio_trig; 1108 + 1109 + indio_trig->ops = &kx022a_trigger_ops; 1110 + iio_trigger_set_drvdata(indio_trig, data); 1111 + 1112 + /* 1113 + * No need to check for NULL. request_threaded_irq() defaults to 1114 + * dev_name() should the alloc fail. 1115 + */ 1116 + name = devm_kasprintf(data->dev, GFP_KERNEL, "%s-kx022a", 1117 + dev_name(data->dev)); 1118 + 1119 + ret = devm_request_threaded_irq(data->dev, irq, kx022a_irq_handler, 1120 + &kx022a_irq_thread_handler, 1121 + IRQF_ONESHOT, name, idev); 1122 + if (ret) 1123 + return dev_err_probe(data->dev, ret, "Could not request IRQ\n"); 1124 + 1125 + 1126 + ret = devm_iio_trigger_register(dev, indio_trig); 1127 + if (ret) 1128 + return dev_err_probe(data->dev, ret, 1129 + "Trigger registration failed\n"); 1130 + 1131 + ret = devm_iio_device_register(data->dev, idev); 1132 + if (ret < 0) 1133 + return dev_err_probe(dev, ret, 1134 + "Unable to register iio device\n"); 1135 + 1136 + return ret; 1137 + } 1138 + EXPORT_SYMBOL_NS_GPL(kx022a_probe_internal, IIO_KX022A); 1139 + 1140 + MODULE_DESCRIPTION("ROHM/Kionix KX022A accelerometer driver"); 1141 + MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>"); 1142 + MODULE_LICENSE("GPL");
+82
drivers/iio/accel/kionix-kx022a.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + /* 3 + * Copyright (C) 2022 ROHM Semiconductors 4 + * 5 + * ROHM/KIONIX KX022A accelerometer driver 6 + */ 7 + 8 + #ifndef _KX022A_H_ 9 + #define _KX022A_H_ 10 + 11 + #include <linux/bits.h> 12 + #include <linux/regmap.h> 13 + 14 + #define KX022A_REG_WHO 0x0f 15 + #define KX022A_ID 0xc8 16 + 17 + #define KX022A_REG_CNTL2 0x19 18 + #define KX022A_MASK_SRST BIT(7) 19 + #define KX022A_REG_CNTL 0x18 20 + #define KX022A_MASK_PC1 BIT(7) 21 + #define KX022A_MASK_RES BIT(6) 22 + #define KX022A_MASK_DRDY BIT(5) 23 + #define KX022A_MASK_GSEL GENMASK(4, 3) 24 + #define KX022A_GSEL_SHIFT 3 25 + #define KX022A_GSEL_2 0x0 26 + #define KX022A_GSEL_4 BIT(3) 27 + #define KX022A_GSEL_8 BIT(4) 28 + #define KX022A_GSEL_16 GENMASK(4, 3) 29 + 30 + #define KX022A_REG_INS2 0x13 31 + #define KX022A_MASK_INS2_DRDY BIT(4) 32 + #define KX122_MASK_INS2_WMI BIT(5) 33 + 34 + #define KX022A_REG_XHP_L 0x0 35 + #define KX022A_REG_XOUT_L 0x06 36 + #define KX022A_REG_YOUT_L 0x08 37 + #define KX022A_REG_ZOUT_L 0x0a 38 + #define KX022A_REG_COTR 0x0c 39 + #define KX022A_REG_TSCP 0x10 40 + #define KX022A_REG_INT_REL 0x17 41 + 42 + #define KX022A_REG_ODCNTL 0x1b 43 + 44 + #define KX022A_REG_BTS_WUF_TH 0x31 45 + #define KX022A_REG_MAN_WAKE 0x2c 46 + 47 + #define KX022A_REG_BUF_CNTL1 0x3a 48 + #define KX022A_MASK_WM_TH GENMASK(6, 0) 49 + #define KX022A_REG_BUF_CNTL2 0x3b 50 + #define KX022A_MASK_BUF_EN BIT(7) 51 + #define KX022A_MASK_BRES16 BIT(6) 52 + #define KX022A_REG_BUF_STATUS_1 0x3c 53 + #define KX022A_REG_BUF_STATUS_2 0x3d 54 + #define KX022A_REG_BUF_CLEAR 0x3e 55 + #define KX022A_REG_BUF_READ 0x3f 56 + #define KX022A_MASK_ODR GENMASK(3, 0) 57 + #define KX022A_ODR_SHIFT 3 58 + #define KX022A_FIFO_MAX_WMI_TH 41 59 + 60 + #define KX022A_REG_INC1 0x1c 61 + #define KX022A_REG_INC5 0x20 62 + #define KX022A_REG_INC6 0x21 63 + #define KX022A_MASK_IEN BIT(5) 64 + #define KX022A_MASK_IPOL BIT(4) 65 + #define KX022A_IPOL_LOW 0 66 + #define KX022A_IPOL_HIGH KX022A_MASK_IPOL1 67 + #define KX022A_MASK_ITYP BIT(3) 68 + #define KX022A_ITYP_PULSE KX022A_MASK_ITYP 69 + #define KX022A_ITYP_LEVEL 0 70 + 71 + #define KX022A_REG_INC4 0x1f 72 + #define KX022A_MASK_WMI BIT(5) 73 + 74 + #define KX022A_REG_SELF_TEST 0x60 75 + #define KX022A_MAX_REGISTER 0x60 76 + 77 + struct device; 78 + 79 + int kx022a_probe_internal(struct device *dev); 80 + extern const struct regmap_config kx022a_regmap; 81 + 82 + #endif
+4 -21
drivers/iio/accel/kxcjk-1013.c
··· 241 241 }; 242 242 243 243 struct kxcjk1013_data { 244 - struct regulator_bulk_data regulators[2]; 245 244 struct i2c_client *client; 246 245 struct iio_trigger *dready_trig; 247 246 struct iio_trigger *motion_trig; ··· 1424 1425 return dev_name(dev); 1425 1426 } 1426 1427 1427 - static void kxcjk1013_disable_regulators(void *d) 1428 - { 1429 - struct kxcjk1013_data *data = d; 1430 - 1431 - regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); 1432 - } 1433 - 1434 1428 static int kxcjk1013_probe(struct i2c_client *client, 1435 1429 const struct i2c_device_id *id) 1436 1430 { 1431 + static const char * const regulator_names[] = { "vdd", "vddio" }; 1437 1432 struct kxcjk1013_data *data; 1438 1433 struct iio_dev *indio_dev; 1439 1434 struct kxcjk_1013_platform_data *pdata; ··· 1454 1461 return ret; 1455 1462 } 1456 1463 1457 - data->regulators[0].supply = "vdd"; 1458 - data->regulators[1].supply = "vddio"; 1459 - ret = devm_regulator_bulk_get(&client->dev, ARRAY_SIZE(data->regulators), 1460 - data->regulators); 1464 + ret = devm_regulator_bulk_get_enable(&client->dev, 1465 + ARRAY_SIZE(regulator_names), 1466 + regulator_names); 1461 1467 if (ret) 1462 1468 return dev_err_probe(&client->dev, ret, "Failed to get regulators\n"); 1463 - 1464 - ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators), 1465 - data->regulators); 1466 - if (ret) 1467 - return ret; 1468 - 1469 - ret = devm_add_action_or_reset(&client->dev, kxcjk1013_disable_regulators, data); 1470 - if (ret) 1471 - return ret; 1472 1469 1473 1470 /* 1474 1471 * A typical delay of 10ms is required for powering up
+2 -3
drivers/iio/accel/kxsd9-i2c.c
··· 10 10 11 11 #include "kxsd9.h" 12 12 13 - static int kxsd9_i2c_probe(struct i2c_client *i2c, 14 - const struct i2c_device_id *id) 13 + static int kxsd9_i2c_probe(struct i2c_client *i2c) 15 14 { 16 15 static const struct regmap_config config = { 17 16 .reg_bits = 8, ··· 54 55 .of_match_table = kxsd9_of_match, 55 56 .pm = pm_ptr(&kxsd9_dev_pm_ops), 56 57 }, 57 - .probe = kxsd9_i2c_probe, 58 + .probe_new = kxsd9_i2c_probe, 58 59 .remove = kxsd9_i2c_remove, 59 60 .id_table = kxsd9_i2c_id, 60 61 };
+2 -3
drivers/iio/accel/mc3230.c
··· 106 106 .read_raw = mc3230_read_raw, 107 107 }; 108 108 109 - static int mc3230_probe(struct i2c_client *client, 110 - const struct i2c_device_id *id) 109 + static int mc3230_probe(struct i2c_client *client) 111 110 { 112 111 int ret; 113 112 struct iio_dev *indio_dev; ··· 190 191 .name = "mc3230", 191 192 .pm = pm_sleep_ptr(&mc3230_pm_ops), 192 193 }, 193 - .probe = mc3230_probe, 194 + .probe_new = mc3230_probe, 194 195 .remove = mc3230_remove, 195 196 .id_table = mc3230_i2c_id, 196 197 };
+2 -3
drivers/iio/accel/mma7660.c
··· 169 169 .attrs = &mma7660_attribute_group, 170 170 }; 171 171 172 - static int mma7660_probe(struct i2c_client *client, 173 - const struct i2c_device_id *id) 172 + static int mma7660_probe(struct i2c_client *client) 174 173 { 175 174 int ret; 176 175 struct iio_dev *indio_dev; ··· 266 267 .of_match_table = mma7660_of_match, 267 268 .acpi_match_table = mma7660_acpi_id, 268 269 }, 269 - .probe = mma7660_probe, 270 + .probe_new = mma7660_probe, 270 271 .remove = mma7660_remove, 271 272 .id_table = mma7660_i2c_id, 272 273 };
+2 -19
drivers/iio/accel/msa311.c
··· 351 351 * @chip_name: Chip name in the format "msa311-%02x" % partid 352 352 * @new_data_trig: Optional NEW_DATA interrupt driven trigger used 353 353 * to notify external consumers a new sample is ready 354 - * @vdd: Optional external voltage regulator for the device power supply 355 354 */ 356 355 struct msa311_priv { 357 356 struct regmap *regs; ··· 361 362 char *chip_name; 362 363 363 364 struct iio_trigger *new_data_trig; 364 - struct regulator *vdd; 365 365 }; 366 366 367 367 enum msa311_si { ··· 1144 1146 msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_SUSPEND); 1145 1147 } 1146 1148 1147 - static void msa311_vdd_disable(void *vdd) 1148 - { 1149 - regulator_disable(vdd); 1150 - } 1151 - 1152 1149 static int msa311_probe(struct i2c_client *i2c) 1153 1150 { 1154 1151 struct device *dev = &i2c->dev; ··· 1166 1173 1167 1174 mutex_init(&msa311->lock); 1168 1175 1169 - msa311->vdd = devm_regulator_get(dev, "vdd"); 1170 - if (IS_ERR(msa311->vdd)) 1171 - return dev_err_probe(dev, PTR_ERR(msa311->vdd), 1172 - "can't get vdd supply\n"); 1173 - 1174 - err = regulator_enable(msa311->vdd); 1176 + err = devm_regulator_get_enable(dev, "vdd"); 1175 1177 if (err) 1176 - return dev_err_probe(dev, err, "can't enable vdd supply\n"); 1177 - 1178 - err = devm_add_action_or_reset(dev, msa311_vdd_disable, msa311->vdd); 1179 - if (err) 1180 - return dev_err_probe(dev, err, 1181 - "can't add vdd disable action\n"); 1178 + return dev_err_probe(dev, err, "can't get vdd supply\n"); 1182 1179 1183 1180 err = msa311_check_partid(msa311); 1184 1181 if (err)
+2 -3
drivers/iio/accel/mxc4005.c
··· 385 385 return 0; 386 386 } 387 387 388 - static int mxc4005_probe(struct i2c_client *client, 389 - const struct i2c_device_id *id) 388 + static int mxc4005_probe(struct i2c_client *client) 390 389 { 391 390 struct mxc4005_data *data; 392 391 struct iio_dev *indio_dev; ··· 488 489 .name = MXC4005_DRV_NAME, 489 490 .acpi_match_table = ACPI_PTR(mxc4005_acpi_match), 490 491 }, 491 - .probe = mxc4005_probe, 492 + .probe_new = mxc4005_probe, 492 493 .id_table = mxc4005_id, 493 494 }; 494 495
+2 -3
drivers/iio/accel/mxc6255.c
··· 113 113 .readable_reg = mxc6255_is_readable_reg, 114 114 }; 115 115 116 - static int mxc6255_probe(struct i2c_client *client, 117 - const struct i2c_device_id *id) 116 + static int mxc6255_probe(struct i2c_client *client) 118 117 { 119 118 struct mxc6255_data *data; 120 119 struct iio_dev *indio_dev; ··· 183 184 .name = MXC6255_DRV_NAME, 184 185 .acpi_match_table = ACPI_PTR(mxc6255_acpi_match), 185 186 }, 186 - .probe = mxc6255_probe, 187 + .probe_new = mxc6255_probe, 187 188 .id_table = mxc6255_id, 188 189 }; 189 190
+10 -2
drivers/iio/accel/sca3300.c
··· 679 679 }; 680 680 MODULE_DEVICE_TABLE(of, sca3300_dt_ids); 681 681 682 + static const struct spi_device_id sca3300_ids[] = { 683 + { "sca3300" }, 684 + { "scl3300" }, 685 + {} 686 + }; 687 + MODULE_DEVICE_TABLE(spi, sca3300_ids); 688 + 682 689 static struct spi_driver sca3300_driver = { 683 - .driver = { 690 + .driver = { 684 691 .name = SCA3300_ALIAS, 685 692 .of_match_table = sca3300_dt_ids, 686 693 }, 687 - .probe = sca3300_probe, 694 + .probe = sca3300_probe, 695 + .id_table = sca3300_ids, 688 696 }; 689 697 module_spi_driver(sca3300_driver); 690 698
+2 -3
drivers/iio/accel/stk8312.c
··· 498 498 .postdisable = stk8312_buffer_postdisable, 499 499 }; 500 500 501 - static int stk8312_probe(struct i2c_client *client, 502 - const struct i2c_device_id *id) 501 + static int stk8312_probe(struct i2c_client *client) 503 502 { 504 503 int ret; 505 504 struct iio_dev *indio_dev; ··· 644 645 .name = STK8312_DRIVER_NAME, 645 646 .pm = pm_sleep_ptr(&stk8312_pm_ops), 646 647 }, 647 - .probe = stk8312_probe, 648 + .probe_new = stk8312_probe, 648 649 .remove = stk8312_remove, 649 650 .id_table = stk8312_i2c_id, 650 651 };
+2 -3
drivers/iio/accel/stk8ba50.c
··· 379 379 .postdisable = stk8ba50_buffer_postdisable, 380 380 }; 381 381 382 - static int stk8ba50_probe(struct i2c_client *client, 383 - const struct i2c_device_id *id) 382 + static int stk8ba50_probe(struct i2c_client *client) 384 383 { 385 384 int ret; 386 385 struct iio_dev *indio_dev; ··· 543 544 .pm = pm_sleep_ptr(&stk8ba50_pm_ops), 544 545 .acpi_match_table = ACPI_PTR(stk8ba50_acpi_id), 545 546 }, 546 - .probe = stk8ba50_probe, 547 + .probe_new = stk8ba50_probe, 547 548 .remove = stk8ba50_remove, 548 549 .id_table = stk8ba50_i2c_id, 549 550 };
+40
drivers/iio/adc/Kconfig
··· 21 21 select IIO_BUFFER 22 22 select IIO_TRIGGERED_BUFFER 23 23 24 + config AD4130 25 + tristate "Analog Device AD4130 ADC Driver" 26 + depends on SPI 27 + depends on GPIOLIB 28 + select IIO_BUFFER 29 + select IIO_KFIFO_BUF 30 + select REGMAP_SPI 31 + depends on COMMON_CLK 32 + help 33 + Say yes here to build support for Analog Devices AD4130-8 SPI analog 34 + to digital converters (ADC). 35 + 36 + To compile this driver as a module, choose M here: the module will be 37 + called ad4130. 38 + 24 39 config AD7091R5 25 40 tristate "Analog Devices AD7091R5 ADC Driver" 26 41 depends on I2C ··· 682 667 To compile this driver as a module, choose M here: the module will be 683 668 called max11205. 684 669 670 + config MAX11410 671 + tristate "Analog Devices MAX11410 ADC driver" 672 + depends on SPI 673 + select REGMAP_SPI 674 + select IIO_BUFFER 675 + select IIO_TRIGGER 676 + select IIO_TRIGGERED_BUFFER 677 + help 678 + Say yes here to build support for Analog Devices MAX11410 ADCs. 679 + 680 + To compile this driver as a module, choose M here: the module will be 681 + called max11410. 682 + 685 683 config MAX1241 686 684 tristate "Maxim max1241 ADC driver" 687 685 depends on SPI_MASTER ··· 779 751 Integrated for System Monitoring includes 780 752 is used in smartphones and tablets and supports a 11 channel 781 753 general purpose ADC. 754 + 755 + config MEDIATEK_MT6370_ADC 756 + tristate "MediaTek MT6370 ADC driver" 757 + depends on MFD_MT6370 758 + help 759 + Say yes here to enable MediaTek MT6370 ADC support. 760 + 761 + This ADC driver provides 9 channels for system monitoring (charger 762 + current, voltage, and temperature). 763 + 764 + This driver can also be built as a module. If so, the module 765 + will be called "mt6370-adc". 782 766 783 767 config MEDIATEK_MT6577_AUXADC 784 768 tristate "MediaTek AUXADC driver"
+3
drivers/iio/adc/Makefile
··· 6 6 # When adding new entries keep the list in alphabetical order 7 7 obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o 8 8 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o 9 + obj-$(CONFIG_AD4130) += ad4130.o 9 10 obj-$(CONFIG_AD7091R5) += ad7091r5.o ad7091r-base.o 10 11 obj-$(CONFIG_AD7124) += ad7124.o 11 12 obj-$(CONFIG_AD7192) += ad7192.o ··· 63 62 obj-$(CONFIG_MAX11100) += max11100.o 64 63 obj-$(CONFIG_MAX1118) += max1118.o 65 64 obj-$(CONFIG_MAX11205) += max11205.o 65 + obj-$(CONFIG_MAX11410) += max11410.o 66 66 obj-$(CONFIG_MAX1241) += max1241.o 67 67 obj-$(CONFIG_MAX1363) += max1363.o 68 68 obj-$(CONFIG_MAX9611) += max9611.o ··· 71 69 obj-$(CONFIG_MCP3422) += mcp3422.o 72 70 obj-$(CONFIG_MCP3911) += mcp3911.o 73 71 obj-$(CONFIG_MEDIATEK_MT6360_ADC) += mt6360-adc.o 72 + obj-$(CONFIG_MEDIATEK_MT6370_ADC) += mt6370-adc.o 74 73 obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o 75 74 obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o 76 75 obj-$(CONFIG_MESON_SARADC) += meson_saradc.o
+2100
drivers/iio/adc/ad4130.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Copyright (C) 2022 Analog Devices, Inc. 4 + * Author: Cosmin Tanislav <cosmin.tanislav@analog.com> 5 + */ 6 + 7 + #include <linux/bitfield.h> 8 + #include <linux/bitops.h> 9 + #include <linux/clk.h> 10 + #include <linux/clk-provider.h> 11 + #include <linux/delay.h> 12 + #include <linux/device.h> 13 + #include <linux/err.h> 14 + #include <linux/gpio/driver.h> 15 + #include <linux/interrupt.h> 16 + #include <linux/irq.h> 17 + #include <linux/kernel.h> 18 + #include <linux/module.h> 19 + #include <linux/property.h> 20 + #include <linux/regmap.h> 21 + #include <linux/regulator/consumer.h> 22 + #include <linux/spi/spi.h> 23 + #include <linux/units.h> 24 + 25 + #include <asm/div64.h> 26 + #include <asm/unaligned.h> 27 + 28 + #include <linux/iio/buffer.h> 29 + #include <linux/iio/iio.h> 30 + #include <linux/iio/kfifo_buf.h> 31 + #include <linux/iio/sysfs.h> 32 + 33 + #define AD4130_NAME "ad4130" 34 + 35 + #define AD4130_COMMS_READ_MASK BIT(6) 36 + 37 + #define AD4130_STATUS_REG 0x00 38 + 39 + #define AD4130_ADC_CONTROL_REG 0x01 40 + #define AD4130_ADC_CONTROL_BIPOLAR_MASK BIT(14) 41 + #define AD4130_ADC_CONTROL_INT_REF_VAL_MASK BIT(13) 42 + #define AD4130_INT_REF_2_5V 2500000 43 + #define AD4130_INT_REF_1_25V 1250000 44 + #define AD4130_ADC_CONTROL_CSB_EN_MASK BIT(9) 45 + #define AD4130_ADC_CONTROL_INT_REF_EN_MASK BIT(8) 46 + #define AD4130_ADC_CONTROL_MODE_MASK GENMASK(5, 2) 47 + #define AD4130_ADC_CONTROL_MCLK_SEL_MASK GENMASK(1, 0) 48 + #define AD4130_MCLK_FREQ_76_8KHZ 76800 49 + #define AD4130_MCLK_FREQ_153_6KHZ 153600 50 + 51 + #define AD4130_DATA_REG 0x02 52 + 53 + #define AD4130_IO_CONTROL_REG 0x03 54 + #define AD4130_IO_CONTROL_INT_PIN_SEL_MASK GENMASK(9, 8) 55 + #define AD4130_IO_CONTROL_GPIO_DATA_MASK GENMASK(7, 4) 56 + #define AD4130_IO_CONTROL_GPIO_CTRL_MASK GENMASK(3, 0) 57 + 58 + #define AD4130_VBIAS_REG 0x04 59 + 60 + #define AD4130_ID_REG 0x05 61 + 62 + #define AD4130_ERROR_REG 0x06 63 + 64 + #define AD4130_ERROR_EN_REG 0x07 65 + 66 + #define AD4130_MCLK_COUNT_REG 0x08 67 + 68 + #define AD4130_CHANNEL_X_REG(x) (0x09 + (x)) 69 + #define AD4130_CHANNEL_EN_MASK BIT(23) 70 + #define AD4130_CHANNEL_SETUP_MASK GENMASK(22, 20) 71 + #define AD4130_CHANNEL_AINP_MASK GENMASK(17, 13) 72 + #define AD4130_CHANNEL_AINM_MASK GENMASK(12, 8) 73 + #define AD4130_CHANNEL_IOUT1_MASK GENMASK(7, 4) 74 + #define AD4130_CHANNEL_IOUT2_MASK GENMASK(3, 0) 75 + 76 + #define AD4130_CONFIG_X_REG(x) (0x19 + (x)) 77 + #define AD4130_CONFIG_IOUT1_VAL_MASK GENMASK(15, 13) 78 + #define AD4130_CONFIG_IOUT2_VAL_MASK GENMASK(12, 10) 79 + #define AD4130_CONFIG_BURNOUT_MASK GENMASK(9, 8) 80 + #define AD4130_CONFIG_REF_BUFP_MASK BIT(7) 81 + #define AD4130_CONFIG_REF_BUFM_MASK BIT(6) 82 + #define AD4130_CONFIG_REF_SEL_MASK GENMASK(5, 4) 83 + #define AD4130_CONFIG_PGA_MASK GENMASK(3, 1) 84 + 85 + #define AD4130_FILTER_X_REG(x) (0x21 + (x)) 86 + #define AD4130_FILTER_MODE_MASK GENMASK(15, 12) 87 + #define AD4130_FILTER_SELECT_MASK GENMASK(10, 0) 88 + #define AD4130_FILTER_SELECT_MIN 1 89 + 90 + #define AD4130_OFFSET_X_REG(x) (0x29 + (x)) 91 + 92 + #define AD4130_GAIN_X_REG(x) (0x31 + (x)) 93 + 94 + #define AD4130_MISC_REG 0x39 95 + 96 + #define AD4130_FIFO_CONTROL_REG 0x3a 97 + #define AD4130_FIFO_CONTROL_HEADER_MASK BIT(18) 98 + #define AD4130_FIFO_CONTROL_MODE_MASK GENMASK(17, 16) 99 + #define AD4130_FIFO_CONTROL_WM_INT_EN_MASK BIT(9) 100 + #define AD4130_FIFO_CONTROL_WM_MASK GENMASK(7, 0) 101 + #define AD4130_WATERMARK_256 0 102 + 103 + #define AD4130_FIFO_STATUS_REG 0x3b 104 + 105 + #define AD4130_FIFO_THRESHOLD_REG 0x3c 106 + 107 + #define AD4130_FIFO_DATA_REG 0x3d 108 + #define AD4130_FIFO_SIZE 256 109 + #define AD4130_FIFO_MAX_SAMPLE_SIZE 3 110 + 111 + #define AD4130_MAX_ANALOG_PINS 16 112 + #define AD4130_MAX_CHANNELS 16 113 + #define AD4130_MAX_DIFF_INPUTS 30 114 + #define AD4130_MAX_GPIOS 4 115 + #define AD4130_MAX_ODR 2400 116 + #define AD4130_MAX_PGA 8 117 + #define AD4130_MAX_SETUPS 8 118 + 119 + #define AD4130_AIN2_P1 0x2 120 + #define AD4130_AIN3_P2 0x3 121 + 122 + #define AD4130_RESET_BUF_SIZE 8 123 + #define AD4130_RESET_SLEEP_US (160 * MICRO / AD4130_MCLK_FREQ_76_8KHZ) 124 + 125 + #define AD4130_INVALID_SLOT -1 126 + 127 + static const unsigned int ad4130_reg_size[] = { 128 + [AD4130_STATUS_REG] = 1, 129 + [AD4130_ADC_CONTROL_REG] = 2, 130 + [AD4130_DATA_REG] = 3, 131 + [AD4130_IO_CONTROL_REG] = 2, 132 + [AD4130_VBIAS_REG] = 2, 133 + [AD4130_ID_REG] = 1, 134 + [AD4130_ERROR_REG] = 2, 135 + [AD4130_ERROR_EN_REG] = 2, 136 + [AD4130_MCLK_COUNT_REG] = 1, 137 + [AD4130_CHANNEL_X_REG(0) ... AD4130_CHANNEL_X_REG(AD4130_MAX_CHANNELS - 1)] = 3, 138 + [AD4130_CONFIG_X_REG(0) ... AD4130_CONFIG_X_REG(AD4130_MAX_SETUPS - 1)] = 2, 139 + [AD4130_FILTER_X_REG(0) ... AD4130_FILTER_X_REG(AD4130_MAX_SETUPS - 1)] = 3, 140 + [AD4130_OFFSET_X_REG(0) ... AD4130_OFFSET_X_REG(AD4130_MAX_SETUPS - 1)] = 3, 141 + [AD4130_GAIN_X_REG(0) ... AD4130_GAIN_X_REG(AD4130_MAX_SETUPS - 1)] = 3, 142 + [AD4130_MISC_REG] = 2, 143 + [AD4130_FIFO_CONTROL_REG] = 3, 144 + [AD4130_FIFO_STATUS_REG] = 1, 145 + [AD4130_FIFO_THRESHOLD_REG] = 3, 146 + [AD4130_FIFO_DATA_REG] = 3, 147 + }; 148 + 149 + enum ad4130_int_ref_val { 150 + AD4130_INT_REF_VAL_2_5V, 151 + AD4130_INT_REF_VAL_1_25V, 152 + }; 153 + 154 + enum ad4130_mclk_sel { 155 + AD4130_MCLK_76_8KHZ, 156 + AD4130_MCLK_76_8KHZ_OUT, 157 + AD4130_MCLK_76_8KHZ_EXT, 158 + AD4130_MCLK_153_6KHZ_EXT, 159 + }; 160 + 161 + enum ad4130_int_pin_sel { 162 + AD4130_INT_PIN_INT, 163 + AD4130_INT_PIN_CLK, 164 + AD4130_INT_PIN_P2, 165 + AD4130_INT_PIN_DOUT, 166 + }; 167 + 168 + enum ad4130_iout { 169 + AD4130_IOUT_OFF, 170 + AD4130_IOUT_10000NA, 171 + AD4130_IOUT_20000NA, 172 + AD4130_IOUT_50000NA, 173 + AD4130_IOUT_100000NA, 174 + AD4130_IOUT_150000NA, 175 + AD4130_IOUT_200000NA, 176 + AD4130_IOUT_100NA, 177 + AD4130_IOUT_MAX 178 + }; 179 + 180 + enum ad4130_burnout { 181 + AD4130_BURNOUT_OFF, 182 + AD4130_BURNOUT_500NA, 183 + AD4130_BURNOUT_2000NA, 184 + AD4130_BURNOUT_4000NA, 185 + AD4130_BURNOUT_MAX 186 + }; 187 + 188 + enum ad4130_ref_sel { 189 + AD4130_REF_REFIN1, 190 + AD4130_REF_REFIN2, 191 + AD4130_REF_REFOUT_AVSS, 192 + AD4130_REF_AVDD_AVSS, 193 + AD4130_REF_SEL_MAX 194 + }; 195 + 196 + enum ad4130_fifo_mode { 197 + AD4130_FIFO_MODE_DISABLED = 0b00, 198 + AD4130_FIFO_MODE_WM = 0b01, 199 + }; 200 + 201 + enum ad4130_mode { 202 + AD4130_MODE_CONTINUOUS = 0b0000, 203 + AD4130_MODE_IDLE = 0b0100, 204 + }; 205 + 206 + enum ad4130_filter_mode { 207 + AD4130_FILTER_SINC4, 208 + AD4130_FILTER_SINC4_SINC1, 209 + AD4130_FILTER_SINC3, 210 + AD4130_FILTER_SINC3_REJ60, 211 + AD4130_FILTER_SINC3_SINC1, 212 + AD4130_FILTER_SINC3_PF1, 213 + AD4130_FILTER_SINC3_PF2, 214 + AD4130_FILTER_SINC3_PF3, 215 + AD4130_FILTER_SINC3_PF4, 216 + }; 217 + 218 + enum ad4130_pin_function { 219 + AD4130_PIN_FN_NONE, 220 + AD4130_PIN_FN_SPECIAL = BIT(0), 221 + AD4130_PIN_FN_DIFF = BIT(1), 222 + AD4130_PIN_FN_EXCITATION = BIT(2), 223 + AD4130_PIN_FN_VBIAS = BIT(3), 224 + }; 225 + 226 + struct ad4130_setup_info { 227 + unsigned int iout0_val; 228 + unsigned int iout1_val; 229 + unsigned int burnout; 230 + unsigned int pga; 231 + unsigned int fs; 232 + u32 ref_sel; 233 + enum ad4130_filter_mode filter_mode; 234 + bool ref_bufp; 235 + bool ref_bufm; 236 + }; 237 + 238 + struct ad4130_slot_info { 239 + struct ad4130_setup_info setup; 240 + unsigned int enabled_channels; 241 + unsigned int channels; 242 + }; 243 + 244 + struct ad4130_chan_info { 245 + struct ad4130_setup_info setup; 246 + u32 iout0; 247 + u32 iout1; 248 + int slot; 249 + bool enabled; 250 + bool initialized; 251 + }; 252 + 253 + struct ad4130_filter_config { 254 + enum ad4130_filter_mode filter_mode; 255 + unsigned int odr_div; 256 + unsigned int fs_max; 257 + enum iio_available_type samp_freq_avail_type; 258 + int samp_freq_avail_len; 259 + int samp_freq_avail[3][2]; 260 + }; 261 + 262 + struct ad4130_state { 263 + struct regmap *regmap; 264 + struct spi_device *spi; 265 + struct clk *mclk; 266 + struct regulator_bulk_data regulators[4]; 267 + u32 irq_trigger; 268 + u32 inv_irq_trigger; 269 + 270 + /* 271 + * Synchronize access to members the of driver state, and ensure 272 + * atomicity of consecutive regmap operations. 273 + */ 274 + struct mutex lock; 275 + struct completion completion; 276 + 277 + struct iio_chan_spec chans[AD4130_MAX_CHANNELS]; 278 + struct ad4130_chan_info chans_info[AD4130_MAX_CHANNELS]; 279 + struct ad4130_slot_info slots_info[AD4130_MAX_SETUPS]; 280 + enum ad4130_pin_function pins_fn[AD4130_MAX_ANALOG_PINS]; 281 + u32 vbias_pins[AD4130_MAX_ANALOG_PINS]; 282 + u32 num_vbias_pins; 283 + int scale_tbls[AD4130_REF_SEL_MAX][AD4130_MAX_PGA][2]; 284 + struct gpio_chip gc; 285 + struct clk_hw int_clk_hw; 286 + 287 + u32 int_pin_sel; 288 + u32 int_ref_uv; 289 + u32 mclk_sel; 290 + bool int_ref_en; 291 + bool bipolar; 292 + 293 + unsigned int num_enabled_channels; 294 + unsigned int effective_watermark; 295 + unsigned int watermark; 296 + 297 + struct spi_message fifo_msg; 298 + struct spi_transfer fifo_xfer[2]; 299 + 300 + /* 301 + * DMA (thus cache coherency maintenance) requires any transfer 302 + * buffers to live in their own cache lines. As the use of these 303 + * buffers is synchronous, all of the buffers used for DMA in this 304 + * driver may share a cache line. 305 + */ 306 + u8 reset_buf[AD4130_RESET_BUF_SIZE] __aligned(IIO_DMA_MINALIGN); 307 + u8 reg_write_tx_buf[4]; 308 + u8 reg_read_tx_buf[1]; 309 + u8 reg_read_rx_buf[3]; 310 + u8 fifo_tx_buf[2]; 311 + u8 fifo_rx_buf[AD4130_FIFO_SIZE * 312 + AD4130_FIFO_MAX_SAMPLE_SIZE]; 313 + }; 314 + 315 + static const char * const ad4130_int_pin_names[] = { 316 + [AD4130_INT_PIN_INT] = "int", 317 + [AD4130_INT_PIN_CLK] = "clk", 318 + [AD4130_INT_PIN_P2] = "p2", 319 + [AD4130_INT_PIN_DOUT] = "dout", 320 + }; 321 + 322 + static const unsigned int ad4130_iout_current_na_tbl[AD4130_IOUT_MAX] = { 323 + [AD4130_IOUT_OFF] = 0, 324 + [AD4130_IOUT_100NA] = 100, 325 + [AD4130_IOUT_10000NA] = 10000, 326 + [AD4130_IOUT_20000NA] = 20000, 327 + [AD4130_IOUT_50000NA] = 50000, 328 + [AD4130_IOUT_100000NA] = 100000, 329 + [AD4130_IOUT_150000NA] = 150000, 330 + [AD4130_IOUT_200000NA] = 200000, 331 + }; 332 + 333 + static const unsigned int ad4130_burnout_current_na_tbl[AD4130_BURNOUT_MAX] = { 334 + [AD4130_BURNOUT_OFF] = 0, 335 + [AD4130_BURNOUT_500NA] = 500, 336 + [AD4130_BURNOUT_2000NA] = 2000, 337 + [AD4130_BURNOUT_4000NA] = 4000, 338 + }; 339 + 340 + #define AD4130_VARIABLE_ODR_CONFIG(_filter_mode, _odr_div, _fs_max) \ 341 + { \ 342 + .filter_mode = (_filter_mode), \ 343 + .odr_div = (_odr_div), \ 344 + .fs_max = (_fs_max), \ 345 + .samp_freq_avail_type = IIO_AVAIL_RANGE, \ 346 + .samp_freq_avail = { \ 347 + { AD4130_MAX_ODR, (_odr_div) * (_fs_max) }, \ 348 + { AD4130_MAX_ODR, (_odr_div) * (_fs_max) }, \ 349 + { AD4130_MAX_ODR, (_odr_div) }, \ 350 + }, \ 351 + } 352 + 353 + #define AD4130_FIXED_ODR_CONFIG(_filter_mode, _odr_div) \ 354 + { \ 355 + .filter_mode = (_filter_mode), \ 356 + .odr_div = (_odr_div), \ 357 + .fs_max = AD4130_FILTER_SELECT_MIN, \ 358 + .samp_freq_avail_type = IIO_AVAIL_LIST, \ 359 + .samp_freq_avail_len = 1, \ 360 + .samp_freq_avail = { \ 361 + { AD4130_MAX_ODR, (_odr_div) }, \ 362 + }, \ 363 + } 364 + 365 + static const struct ad4130_filter_config ad4130_filter_configs[] = { 366 + AD4130_VARIABLE_ODR_CONFIG(AD4130_FILTER_SINC4, 1, 10), 367 + AD4130_VARIABLE_ODR_CONFIG(AD4130_FILTER_SINC4_SINC1, 11, 10), 368 + AD4130_VARIABLE_ODR_CONFIG(AD4130_FILTER_SINC3, 1, 2047), 369 + AD4130_VARIABLE_ODR_CONFIG(AD4130_FILTER_SINC3_REJ60, 1, 2047), 370 + AD4130_VARIABLE_ODR_CONFIG(AD4130_FILTER_SINC3_SINC1, 10, 2047), 371 + AD4130_FIXED_ODR_CONFIG(AD4130_FILTER_SINC3_PF1, 92), 372 + AD4130_FIXED_ODR_CONFIG(AD4130_FILTER_SINC3_PF2, 100), 373 + AD4130_FIXED_ODR_CONFIG(AD4130_FILTER_SINC3_PF3, 124), 374 + AD4130_FIXED_ODR_CONFIG(AD4130_FILTER_SINC3_PF4, 148), 375 + }; 376 + 377 + static const char * const ad4130_filter_modes_str[] = { 378 + [AD4130_FILTER_SINC4] = "sinc4", 379 + [AD4130_FILTER_SINC4_SINC1] = "sinc4+sinc1", 380 + [AD4130_FILTER_SINC3] = "sinc3", 381 + [AD4130_FILTER_SINC3_REJ60] = "sinc3+rej60", 382 + [AD4130_FILTER_SINC3_SINC1] = "sinc3+sinc1", 383 + [AD4130_FILTER_SINC3_PF1] = "sinc3+pf1", 384 + [AD4130_FILTER_SINC3_PF2] = "sinc3+pf2", 385 + [AD4130_FILTER_SINC3_PF3] = "sinc3+pf3", 386 + [AD4130_FILTER_SINC3_PF4] = "sinc3+pf4", 387 + }; 388 + 389 + static int ad4130_get_reg_size(struct ad4130_state *st, unsigned int reg, 390 + unsigned int *size) 391 + { 392 + if (reg >= ARRAY_SIZE(ad4130_reg_size)) 393 + return -EINVAL; 394 + 395 + *size = ad4130_reg_size[reg]; 396 + 397 + return 0; 398 + } 399 + 400 + static unsigned int ad4130_data_reg_size(struct ad4130_state *st) 401 + { 402 + unsigned int data_reg_size; 403 + int ret; 404 + 405 + ret = ad4130_get_reg_size(st, AD4130_DATA_REG, &data_reg_size); 406 + if (ret) 407 + return 0; 408 + 409 + return data_reg_size; 410 + } 411 + 412 + static unsigned int ad4130_resolution(struct ad4130_state *st) 413 + { 414 + return ad4130_data_reg_size(st) * BITS_PER_BYTE; 415 + } 416 + 417 + static int ad4130_reg_write(void *context, unsigned int reg, unsigned int val) 418 + { 419 + struct ad4130_state *st = context; 420 + unsigned int size; 421 + int ret; 422 + 423 + ret = ad4130_get_reg_size(st, reg, &size); 424 + if (ret) 425 + return ret; 426 + 427 + st->reg_write_tx_buf[0] = reg; 428 + 429 + switch (size) { 430 + case 3: 431 + put_unaligned_be24(val, &st->reg_write_tx_buf[1]); 432 + break; 433 + case 2: 434 + put_unaligned_be16(val, &st->reg_write_tx_buf[1]); 435 + break; 436 + case 1: 437 + st->reg_write_tx_buf[1] = val; 438 + break; 439 + default: 440 + return -EINVAL; 441 + } 442 + 443 + return spi_write(st->spi, st->reg_write_tx_buf, size + 1); 444 + } 445 + 446 + static int ad4130_reg_read(void *context, unsigned int reg, unsigned int *val) 447 + { 448 + struct ad4130_state *st = context; 449 + struct spi_transfer t[] = { 450 + { 451 + .tx_buf = st->reg_read_tx_buf, 452 + .len = sizeof(st->reg_read_tx_buf), 453 + }, 454 + { 455 + .rx_buf = st->reg_read_rx_buf, 456 + }, 457 + }; 458 + unsigned int size; 459 + int ret; 460 + 461 + ret = ad4130_get_reg_size(st, reg, &size); 462 + if (ret) 463 + return ret; 464 + 465 + st->reg_read_tx_buf[0] = AD4130_COMMS_READ_MASK | reg; 466 + t[1].len = size; 467 + 468 + ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); 469 + if (ret) 470 + return ret; 471 + 472 + switch (size) { 473 + case 3: 474 + *val = get_unaligned_be24(st->reg_read_rx_buf); 475 + break; 476 + case 2: 477 + *val = get_unaligned_be16(st->reg_read_rx_buf); 478 + break; 479 + case 1: 480 + *val = st->reg_read_rx_buf[0]; 481 + break; 482 + default: 483 + return -EINVAL; 484 + } 485 + 486 + return 0; 487 + } 488 + 489 + static const struct regmap_config ad4130_regmap_config = { 490 + .reg_read = ad4130_reg_read, 491 + .reg_write = ad4130_reg_write, 492 + }; 493 + 494 + static int ad4130_gpio_init_valid_mask(struct gpio_chip *gc, 495 + unsigned long *valid_mask, 496 + unsigned int ngpios) 497 + { 498 + struct ad4130_state *st = gpiochip_get_data(gc); 499 + unsigned int i; 500 + 501 + /* 502 + * Output-only GPIO functionality is available on pins AIN2 through 503 + * AIN5. If these pins are used for anything else, do not expose them. 504 + */ 505 + for (i = 0; i < ngpios; i++) { 506 + unsigned int pin = i + AD4130_AIN2_P1; 507 + bool valid = st->pins_fn[pin] == AD4130_PIN_FN_NONE; 508 + 509 + __assign_bit(i, valid_mask, valid); 510 + } 511 + 512 + return 0; 513 + } 514 + 515 + static int ad4130_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) 516 + { 517 + return GPIO_LINE_DIRECTION_OUT; 518 + } 519 + 520 + static void ad4130_gpio_set(struct gpio_chip *gc, unsigned int offset, 521 + int value) 522 + { 523 + struct ad4130_state *st = gpiochip_get_data(gc); 524 + unsigned int mask = FIELD_PREP(AD4130_IO_CONTROL_GPIO_DATA_MASK, 525 + BIT(offset)); 526 + 527 + regmap_update_bits(st->regmap, AD4130_IO_CONTROL_REG, mask, 528 + value ? mask : 0); 529 + } 530 + 531 + static int ad4130_set_mode(struct ad4130_state *st, enum ad4130_mode mode) 532 + { 533 + return regmap_update_bits(st->regmap, AD4130_ADC_CONTROL_REG, 534 + AD4130_ADC_CONTROL_MODE_MASK, 535 + FIELD_PREP(AD4130_ADC_CONTROL_MODE_MASK, mode)); 536 + } 537 + 538 + static int ad4130_set_watermark_interrupt_en(struct ad4130_state *st, bool en) 539 + { 540 + return regmap_update_bits(st->regmap, AD4130_FIFO_CONTROL_REG, 541 + AD4130_FIFO_CONTROL_WM_INT_EN_MASK, 542 + FIELD_PREP(AD4130_FIFO_CONTROL_WM_INT_EN_MASK, en)); 543 + } 544 + 545 + static unsigned int ad4130_watermark_reg_val(unsigned int val) 546 + { 547 + if (val == AD4130_FIFO_SIZE) 548 + val = AD4130_WATERMARK_256; 549 + 550 + return val; 551 + } 552 + 553 + static int ad4130_set_fifo_mode(struct ad4130_state *st, 554 + enum ad4130_fifo_mode mode) 555 + { 556 + return regmap_update_bits(st->regmap, AD4130_FIFO_CONTROL_REG, 557 + AD4130_FIFO_CONTROL_MODE_MASK, 558 + FIELD_PREP(AD4130_FIFO_CONTROL_MODE_MASK, mode)); 559 + } 560 + 561 + static void ad4130_push_fifo_data(struct iio_dev *indio_dev) 562 + { 563 + struct ad4130_state *st = iio_priv(indio_dev); 564 + unsigned int data_reg_size = ad4130_data_reg_size(st); 565 + unsigned int transfer_len = st->effective_watermark * data_reg_size; 566 + unsigned int set_size = st->num_enabled_channels * data_reg_size; 567 + unsigned int i; 568 + int ret; 569 + 570 + st->fifo_tx_buf[1] = ad4130_watermark_reg_val(st->effective_watermark); 571 + st->fifo_xfer[1].len = transfer_len; 572 + 573 + ret = spi_sync(st->spi, &st->fifo_msg); 574 + if (ret) 575 + return; 576 + 577 + for (i = 0; i < transfer_len; i += set_size) 578 + iio_push_to_buffers(indio_dev, &st->fifo_rx_buf[i]); 579 + } 580 + 581 + static irqreturn_t ad4130_irq_handler(int irq, void *private) 582 + { 583 + struct iio_dev *indio_dev = private; 584 + struct ad4130_state *st = iio_priv(indio_dev); 585 + 586 + if (iio_buffer_enabled(indio_dev)) 587 + ad4130_push_fifo_data(indio_dev); 588 + else 589 + complete(&st->completion); 590 + 591 + return IRQ_HANDLED; 592 + } 593 + 594 + static int ad4130_find_slot(struct ad4130_state *st, 595 + struct ad4130_setup_info *target_setup_info, 596 + unsigned int *slot, bool *overwrite) 597 + { 598 + unsigned int i; 599 + 600 + *slot = AD4130_INVALID_SLOT; 601 + *overwrite = false; 602 + 603 + for (i = 0; i < AD4130_MAX_SETUPS; i++) { 604 + struct ad4130_slot_info *slot_info = &st->slots_info[i]; 605 + 606 + /* Immediately accept a matching setup info. */ 607 + if (!memcmp(target_setup_info, &slot_info->setup, 608 + sizeof(*target_setup_info))) { 609 + *slot = i; 610 + return 0; 611 + } 612 + 613 + /* Ignore all setups which are used by enabled channels. */ 614 + if (slot_info->enabled_channels) 615 + continue; 616 + 617 + /* Find the least used slot. */ 618 + if (*slot == AD4130_INVALID_SLOT || 619 + slot_info->channels < st->slots_info[*slot].channels) 620 + *slot = i; 621 + } 622 + 623 + if (*slot == AD4130_INVALID_SLOT) 624 + return -EINVAL; 625 + 626 + *overwrite = true; 627 + 628 + return 0; 629 + } 630 + 631 + static void ad4130_unlink_channel(struct ad4130_state *st, unsigned int channel) 632 + { 633 + struct ad4130_chan_info *chan_info = &st->chans_info[channel]; 634 + struct ad4130_slot_info *slot_info = &st->slots_info[chan_info->slot]; 635 + 636 + chan_info->slot = AD4130_INVALID_SLOT; 637 + slot_info->channels--; 638 + } 639 + 640 + static int ad4130_unlink_slot(struct ad4130_state *st, unsigned int slot) 641 + { 642 + unsigned int i; 643 + 644 + for (i = 0; i < AD4130_MAX_CHANNELS; i++) { 645 + struct ad4130_chan_info *chan_info = &st->chans_info[i]; 646 + 647 + if (!chan_info->initialized || chan_info->slot != slot) 648 + continue; 649 + 650 + ad4130_unlink_channel(st, i); 651 + } 652 + 653 + return 0; 654 + } 655 + 656 + static int ad4130_link_channel_slot(struct ad4130_state *st, 657 + unsigned int channel, unsigned int slot) 658 + { 659 + struct ad4130_slot_info *slot_info = &st->slots_info[slot]; 660 + struct ad4130_chan_info *chan_info = &st->chans_info[channel]; 661 + int ret; 662 + 663 + ret = regmap_update_bits(st->regmap, AD4130_CHANNEL_X_REG(channel), 664 + AD4130_CHANNEL_SETUP_MASK, 665 + FIELD_PREP(AD4130_CHANNEL_SETUP_MASK, slot)); 666 + if (ret) 667 + return ret; 668 + 669 + chan_info->slot = slot; 670 + slot_info->channels++; 671 + 672 + return 0; 673 + } 674 + 675 + static int ad4130_write_slot_setup(struct ad4130_state *st, 676 + unsigned int slot, 677 + struct ad4130_setup_info *setup_info) 678 + { 679 + unsigned int val; 680 + int ret; 681 + 682 + val = FIELD_PREP(AD4130_CONFIG_IOUT1_VAL_MASK, setup_info->iout0_val) | 683 + FIELD_PREP(AD4130_CONFIG_IOUT1_VAL_MASK, setup_info->iout1_val) | 684 + FIELD_PREP(AD4130_CONFIG_BURNOUT_MASK, setup_info->burnout) | 685 + FIELD_PREP(AD4130_CONFIG_REF_BUFP_MASK, setup_info->ref_bufp) | 686 + FIELD_PREP(AD4130_CONFIG_REF_BUFM_MASK, setup_info->ref_bufm) | 687 + FIELD_PREP(AD4130_CONFIG_REF_SEL_MASK, setup_info->ref_sel) | 688 + FIELD_PREP(AD4130_CONFIG_PGA_MASK, setup_info->pga); 689 + 690 + ret = regmap_write(st->regmap, AD4130_CONFIG_X_REG(slot), val); 691 + if (ret) 692 + return ret; 693 + 694 + val = FIELD_PREP(AD4130_FILTER_MODE_MASK, setup_info->filter_mode) | 695 + FIELD_PREP(AD4130_FILTER_SELECT_MASK, setup_info->fs); 696 + 697 + ret = regmap_write(st->regmap, AD4130_FILTER_X_REG(slot), val); 698 + if (ret) 699 + return ret; 700 + 701 + memcpy(&st->slots_info[slot].setup, setup_info, sizeof(*setup_info)); 702 + 703 + return 0; 704 + } 705 + 706 + static int ad4130_write_channel_setup(struct ad4130_state *st, 707 + unsigned int channel, bool on_enable) 708 + { 709 + struct ad4130_chan_info *chan_info = &st->chans_info[channel]; 710 + struct ad4130_setup_info *setup_info = &chan_info->setup; 711 + bool overwrite; 712 + int slot; 713 + int ret; 714 + 715 + /* 716 + * The following cases need to be handled. 717 + * 718 + * 1. Enabled and linked channel with setup changes: 719 + * - Find a slot. If not possible, return error. 720 + * - Unlink channel from current slot. 721 + * - If the slot has channels linked to it, unlink all channels, and 722 + * write the new setup to it. 723 + * - Link channel to new slot. 724 + * 725 + * 2. Soon to be enabled and unlinked channel: 726 + * - Find a slot. If not possible, return error. 727 + * - If the slot has channels linked to it, unlink all channels, and 728 + * write the new setup to it. 729 + * - Link channel to the slot. 730 + * 731 + * 3. Disabled and linked channel with setup changes: 732 + * - Unlink channel from current slot. 733 + * 734 + * 4. Soon to be enabled and linked channel: 735 + * 5. Disabled and unlinked channel with setup changes: 736 + * - Do nothing. 737 + */ 738 + 739 + /* Case 4 */ 740 + if (on_enable && chan_info->slot != AD4130_INVALID_SLOT) 741 + return 0; 742 + 743 + if (!on_enable && !chan_info->enabled) { 744 + if (chan_info->slot != AD4130_INVALID_SLOT) 745 + /* Case 3 */ 746 + ad4130_unlink_channel(st, channel); 747 + 748 + /* Cases 3 & 5 */ 749 + return 0; 750 + } 751 + 752 + /* Cases 1 & 2 */ 753 + ret = ad4130_find_slot(st, setup_info, &slot, &overwrite); 754 + if (ret) 755 + return ret; 756 + 757 + if (chan_info->slot != AD4130_INVALID_SLOT) 758 + /* Case 1 */ 759 + ad4130_unlink_channel(st, channel); 760 + 761 + if (overwrite) { 762 + ret = ad4130_unlink_slot(st, slot); 763 + if (ret) 764 + return ret; 765 + 766 + ret = ad4130_write_slot_setup(st, slot, setup_info); 767 + if (ret) 768 + return ret; 769 + } 770 + 771 + return ad4130_link_channel_slot(st, channel, slot); 772 + } 773 + 774 + static int ad4130_set_channel_enable(struct ad4130_state *st, 775 + unsigned int channel, bool status) 776 + { 777 + struct ad4130_chan_info *chan_info = &st->chans_info[channel]; 778 + struct ad4130_slot_info *slot_info; 779 + int ret; 780 + 781 + if (chan_info->enabled == status) 782 + return 0; 783 + 784 + if (status) { 785 + ret = ad4130_write_channel_setup(st, channel, true); 786 + if (ret) 787 + return ret; 788 + } 789 + 790 + slot_info = &st->slots_info[chan_info->slot]; 791 + 792 + ret = regmap_update_bits(st->regmap, AD4130_CHANNEL_X_REG(channel), 793 + AD4130_CHANNEL_EN_MASK, 794 + FIELD_PREP(AD4130_CHANNEL_EN_MASK, status)); 795 + if (ret) 796 + return ret; 797 + 798 + slot_info->enabled_channels += status ? 1 : -1; 799 + chan_info->enabled = status; 800 + 801 + return 0; 802 + } 803 + 804 + /* 805 + * Table 58. FILTER_MODE_n bits and Filter Types of the datasheet describes 806 + * the relation between filter mode, ODR and FS. 807 + * 808 + * Notice that the max ODR of each filter mode is not necessarily the 809 + * absolute max ODR supported by the chip. 810 + * 811 + * The ODR divider is not explicitly specified, but it can be deduced based 812 + * on the ODR range of each filter mode. 813 + * 814 + * For example, for Sinc4+Sinc1, max ODR is 218.18. That means that the 815 + * absolute max ODR is divided by 11 to achieve the max ODR of this filter 816 + * mode. 817 + * 818 + * The formulas for converting between ODR and FS for a specific filter 819 + * mode can be deduced from the same table. 820 + * 821 + * Notice that FS = 1 actually means max ODR, and that ODR decreases by 822 + * (maximum ODR / maximum FS) for each increment of FS. 823 + * 824 + * odr = MAX_ODR / odr_div * (1 - (fs - 1) / fs_max) <=> 825 + * odr = MAX_ODR * (1 - (fs - 1) / fs_max) / odr_div <=> 826 + * odr = MAX_ODR * (1 - (fs - 1) / fs_max) / odr_div <=> 827 + * odr = MAX_ODR * (fs_max - fs + 1) / (fs_max * odr_div) 828 + * (used in ad4130_fs_to_freq) 829 + * 830 + * For the opposite formula, FS can be extracted from the last one. 831 + * 832 + * MAX_ODR * (fs_max - fs + 1) = fs_max * odr_div * odr <=> 833 + * fs_max - fs + 1 = fs_max * odr_div * odr / MAX_ODR <=> 834 + * fs = 1 + fs_max - fs_max * odr_div * odr / MAX_ODR 835 + * (used in ad4130_fs_to_freq) 836 + */ 837 + 838 + static void ad4130_freq_to_fs(enum ad4130_filter_mode filter_mode, 839 + int val, int val2, unsigned int *fs) 840 + { 841 + const struct ad4130_filter_config *filter_config = 842 + &ad4130_filter_configs[filter_mode]; 843 + u64 dividend, divisor; 844 + int temp; 845 + 846 + dividend = filter_config->fs_max * filter_config->odr_div * 847 + ((u64)val * NANO + val2); 848 + divisor = (u64)AD4130_MAX_ODR * NANO; 849 + 850 + temp = AD4130_FILTER_SELECT_MIN + filter_config->fs_max - 851 + DIV64_U64_ROUND_CLOSEST(dividend, divisor); 852 + 853 + if (temp < AD4130_FILTER_SELECT_MIN) 854 + temp = AD4130_FILTER_SELECT_MIN; 855 + else if (temp > filter_config->fs_max) 856 + temp = filter_config->fs_max; 857 + 858 + *fs = temp; 859 + } 860 + 861 + static void ad4130_fs_to_freq(enum ad4130_filter_mode filter_mode, 862 + unsigned int fs, int *val, int *val2) 863 + { 864 + const struct ad4130_filter_config *filter_config = 865 + &ad4130_filter_configs[filter_mode]; 866 + unsigned int dividend, divisor; 867 + u64 temp; 868 + 869 + dividend = (filter_config->fs_max - fs + AD4130_FILTER_SELECT_MIN) * 870 + AD4130_MAX_ODR; 871 + divisor = filter_config->fs_max * filter_config->odr_div; 872 + 873 + temp = div_u64((u64)dividend * NANO, divisor); 874 + *val = div_u64_rem(temp, NANO, val2); 875 + } 876 + 877 + static int ad4130_set_filter_mode(struct iio_dev *indio_dev, 878 + const struct iio_chan_spec *chan, 879 + unsigned int val) 880 + { 881 + struct ad4130_state *st = iio_priv(indio_dev); 882 + unsigned int channel = chan->scan_index; 883 + struct ad4130_chan_info *chan_info = &st->chans_info[channel]; 884 + struct ad4130_setup_info *setup_info = &chan_info->setup; 885 + enum ad4130_filter_mode old_filter_mode; 886 + int freq_val, freq_val2; 887 + unsigned int old_fs; 888 + int ret = 0; 889 + 890 + mutex_lock(&st->lock); 891 + if (setup_info->filter_mode == val) 892 + goto out; 893 + 894 + old_fs = setup_info->fs; 895 + old_filter_mode = setup_info->filter_mode; 896 + 897 + /* 898 + * When switching between filter modes, try to match the ODR as 899 + * close as possible. To do this, convert the current FS into ODR 900 + * using the old filter mode, then convert it back into FS using 901 + * the new filter mode. 902 + */ 903 + ad4130_fs_to_freq(setup_info->filter_mode, setup_info->fs, 904 + &freq_val, &freq_val2); 905 + 906 + ad4130_freq_to_fs(val, freq_val, freq_val2, &setup_info->fs); 907 + 908 + setup_info->filter_mode = val; 909 + 910 + ret = ad4130_write_channel_setup(st, channel, false); 911 + if (ret) { 912 + setup_info->fs = old_fs; 913 + setup_info->filter_mode = old_filter_mode; 914 + } 915 + 916 + out: 917 + mutex_unlock(&st->lock); 918 + 919 + return ret; 920 + } 921 + 922 + static int ad4130_get_filter_mode(struct iio_dev *indio_dev, 923 + const struct iio_chan_spec *chan) 924 + { 925 + struct ad4130_state *st = iio_priv(indio_dev); 926 + unsigned int channel = chan->scan_index; 927 + struct ad4130_setup_info *setup_info = &st->chans_info[channel].setup; 928 + enum ad4130_filter_mode filter_mode; 929 + 930 + mutex_lock(&st->lock); 931 + filter_mode = setup_info->filter_mode; 932 + mutex_unlock(&st->lock); 933 + 934 + return filter_mode; 935 + } 936 + 937 + static const struct iio_enum ad4130_filter_mode_enum = { 938 + .items = ad4130_filter_modes_str, 939 + .num_items = ARRAY_SIZE(ad4130_filter_modes_str), 940 + .set = ad4130_set_filter_mode, 941 + .get = ad4130_get_filter_mode, 942 + }; 943 + 944 + static const struct iio_chan_spec_ext_info ad4130_filter_mode_ext_info[] = { 945 + IIO_ENUM("filter_mode", IIO_SEPARATE, &ad4130_filter_mode_enum), 946 + IIO_ENUM_AVAILABLE("filter_mode", IIO_SHARED_BY_TYPE, 947 + &ad4130_filter_mode_enum), 948 + { } 949 + }; 950 + 951 + static const struct iio_chan_spec ad4130_channel_template = { 952 + .type = IIO_VOLTAGE, 953 + .indexed = 1, 954 + .differential = 1, 955 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 956 + BIT(IIO_CHAN_INFO_SCALE) | 957 + BIT(IIO_CHAN_INFO_OFFSET) | 958 + BIT(IIO_CHAN_INFO_SAMP_FREQ), 959 + .info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE) | 960 + BIT(IIO_CHAN_INFO_SAMP_FREQ), 961 + .ext_info = ad4130_filter_mode_ext_info, 962 + .scan_type = { 963 + .sign = 'u', 964 + .endianness = IIO_BE, 965 + }, 966 + }; 967 + 968 + static int ad4130_set_channel_pga(struct ad4130_state *st, unsigned int channel, 969 + int val, int val2) 970 + { 971 + struct ad4130_chan_info *chan_info = &st->chans_info[channel]; 972 + struct ad4130_setup_info *setup_info = &chan_info->setup; 973 + unsigned int pga, old_pga; 974 + int ret = 0; 975 + 976 + for (pga = 0; pga < AD4130_MAX_PGA; pga++) 977 + if (val == st->scale_tbls[setup_info->ref_sel][pga][0] && 978 + val2 == st->scale_tbls[setup_info->ref_sel][pga][1]) 979 + break; 980 + 981 + if (pga == AD4130_MAX_PGA) 982 + return -EINVAL; 983 + 984 + mutex_lock(&st->lock); 985 + if (pga == setup_info->pga) 986 + goto out; 987 + 988 + old_pga = setup_info->pga; 989 + setup_info->pga = pga; 990 + 991 + ret = ad4130_write_channel_setup(st, channel, false); 992 + if (ret) 993 + setup_info->pga = old_pga; 994 + 995 + out: 996 + mutex_unlock(&st->lock); 997 + 998 + return ret; 999 + } 1000 + 1001 + static int ad4130_set_channel_freq(struct ad4130_state *st, 1002 + unsigned int channel, int val, int val2) 1003 + { 1004 + struct ad4130_chan_info *chan_info = &st->chans_info[channel]; 1005 + struct ad4130_setup_info *setup_info = &chan_info->setup; 1006 + unsigned int fs, old_fs; 1007 + int ret = 0; 1008 + 1009 + mutex_lock(&st->lock); 1010 + old_fs = setup_info->fs; 1011 + 1012 + ad4130_freq_to_fs(setup_info->filter_mode, val, val2, &fs); 1013 + 1014 + if (fs == setup_info->fs) 1015 + goto out; 1016 + 1017 + setup_info->fs = fs; 1018 + 1019 + ret = ad4130_write_channel_setup(st, channel, false); 1020 + if (ret) 1021 + setup_info->fs = old_fs; 1022 + 1023 + out: 1024 + mutex_unlock(&st->lock); 1025 + 1026 + return ret; 1027 + } 1028 + 1029 + static int _ad4130_read_sample(struct iio_dev *indio_dev, unsigned int channel, 1030 + int *val) 1031 + { 1032 + struct ad4130_state *st = iio_priv(indio_dev); 1033 + int ret; 1034 + 1035 + ret = ad4130_set_channel_enable(st, channel, true); 1036 + if (ret) 1037 + return ret; 1038 + 1039 + reinit_completion(&st->completion); 1040 + 1041 + ret = ad4130_set_mode(st, AD4130_MODE_CONTINUOUS); 1042 + if (ret) 1043 + return ret; 1044 + 1045 + ret = wait_for_completion_timeout(&st->completion, 1046 + msecs_to_jiffies(1000)); 1047 + if (!ret) 1048 + return -ETIMEDOUT; 1049 + 1050 + ret = ad4130_set_mode(st, AD4130_MODE_IDLE); 1051 + if (ret) 1052 + return ret; 1053 + 1054 + ret = regmap_read(st->regmap, AD4130_DATA_REG, val); 1055 + if (ret) 1056 + return ret; 1057 + 1058 + ret = ad4130_set_channel_enable(st, channel, false); 1059 + if (ret) 1060 + return ret; 1061 + 1062 + return IIO_VAL_INT; 1063 + } 1064 + 1065 + static int ad4130_read_sample(struct iio_dev *indio_dev, unsigned int channel, 1066 + int *val) 1067 + { 1068 + struct ad4130_state *st = iio_priv(indio_dev); 1069 + int ret; 1070 + 1071 + ret = iio_device_claim_direct_mode(indio_dev); 1072 + if (ret) 1073 + return ret; 1074 + 1075 + mutex_lock(&st->lock); 1076 + ret = _ad4130_read_sample(indio_dev, channel, val); 1077 + mutex_unlock(&st->lock); 1078 + 1079 + iio_device_release_direct_mode(indio_dev); 1080 + 1081 + return ret; 1082 + } 1083 + 1084 + static int ad4130_read_raw(struct iio_dev *indio_dev, 1085 + struct iio_chan_spec const *chan, 1086 + int *val, int *val2, long info) 1087 + { 1088 + struct ad4130_state *st = iio_priv(indio_dev); 1089 + unsigned int channel = chan->scan_index; 1090 + struct ad4130_setup_info *setup_info = &st->chans_info[channel].setup; 1091 + 1092 + switch (info) { 1093 + case IIO_CHAN_INFO_RAW: 1094 + return ad4130_read_sample(indio_dev, channel, val); 1095 + case IIO_CHAN_INFO_SCALE: 1096 + mutex_lock(&st->lock); 1097 + *val = st->scale_tbls[setup_info->ref_sel][setup_info->pga][0]; 1098 + *val2 = st->scale_tbls[setup_info->ref_sel][setup_info->pga][1]; 1099 + mutex_unlock(&st->lock); 1100 + 1101 + return IIO_VAL_INT_PLUS_NANO; 1102 + case IIO_CHAN_INFO_OFFSET: 1103 + *val = st->bipolar ? -BIT(chan->scan_type.realbits - 1) : 0; 1104 + 1105 + return IIO_VAL_INT; 1106 + case IIO_CHAN_INFO_SAMP_FREQ: 1107 + mutex_lock(&st->lock); 1108 + ad4130_fs_to_freq(setup_info->filter_mode, setup_info->fs, 1109 + val, val2); 1110 + mutex_unlock(&st->lock); 1111 + 1112 + return IIO_VAL_INT_PLUS_NANO; 1113 + default: 1114 + return -EINVAL; 1115 + } 1116 + } 1117 + 1118 + static int ad4130_read_avail(struct iio_dev *indio_dev, 1119 + struct iio_chan_spec const *chan, 1120 + const int **vals, int *type, int *length, 1121 + long info) 1122 + { 1123 + struct ad4130_state *st = iio_priv(indio_dev); 1124 + unsigned int channel = chan->scan_index; 1125 + struct ad4130_setup_info *setup_info = &st->chans_info[channel].setup; 1126 + const struct ad4130_filter_config *filter_config; 1127 + 1128 + switch (info) { 1129 + case IIO_CHAN_INFO_SCALE: 1130 + *vals = (int *)st->scale_tbls[setup_info->ref_sel]; 1131 + *length = ARRAY_SIZE(st->scale_tbls[setup_info->ref_sel]) * 2; 1132 + 1133 + *type = IIO_VAL_INT_PLUS_NANO; 1134 + 1135 + return IIO_AVAIL_LIST; 1136 + case IIO_CHAN_INFO_SAMP_FREQ: 1137 + mutex_lock(&st->lock); 1138 + filter_config = &ad4130_filter_configs[setup_info->filter_mode]; 1139 + mutex_unlock(&st->lock); 1140 + 1141 + *vals = (int *)filter_config->samp_freq_avail; 1142 + *length = filter_config->samp_freq_avail_len * 2; 1143 + *type = IIO_VAL_FRACTIONAL; 1144 + 1145 + return filter_config->samp_freq_avail_type; 1146 + default: 1147 + return -EINVAL; 1148 + } 1149 + } 1150 + 1151 + static int ad4130_write_raw_get_fmt(struct iio_dev *indio_dev, 1152 + struct iio_chan_spec const *chan, 1153 + long info) 1154 + { 1155 + switch (info) { 1156 + case IIO_CHAN_INFO_SCALE: 1157 + case IIO_CHAN_INFO_SAMP_FREQ: 1158 + return IIO_VAL_INT_PLUS_NANO; 1159 + default: 1160 + return -EINVAL; 1161 + } 1162 + } 1163 + 1164 + static int ad4130_write_raw(struct iio_dev *indio_dev, 1165 + struct iio_chan_spec const *chan, 1166 + int val, int val2, long info) 1167 + { 1168 + struct ad4130_state *st = iio_priv(indio_dev); 1169 + unsigned int channel = chan->scan_index; 1170 + 1171 + switch (info) { 1172 + case IIO_CHAN_INFO_SCALE: 1173 + return ad4130_set_channel_pga(st, channel, val, val2); 1174 + case IIO_CHAN_INFO_SAMP_FREQ: 1175 + return ad4130_set_channel_freq(st, channel, val, val2); 1176 + default: 1177 + return -EINVAL; 1178 + } 1179 + } 1180 + 1181 + static int ad4130_reg_access(struct iio_dev *indio_dev, unsigned int reg, 1182 + unsigned int writeval, unsigned int *readval) 1183 + { 1184 + struct ad4130_state *st = iio_priv(indio_dev); 1185 + 1186 + if (readval) 1187 + return regmap_read(st->regmap, reg, readval); 1188 + 1189 + return regmap_write(st->regmap, reg, writeval); 1190 + } 1191 + 1192 + static int ad4130_update_scan_mode(struct iio_dev *indio_dev, 1193 + const unsigned long *scan_mask) 1194 + { 1195 + struct ad4130_state *st = iio_priv(indio_dev); 1196 + unsigned int channel; 1197 + unsigned int val = 0; 1198 + int ret; 1199 + 1200 + mutex_lock(&st->lock); 1201 + 1202 + for_each_set_bit(channel, scan_mask, indio_dev->num_channels) { 1203 + ret = ad4130_set_channel_enable(st, channel, true); 1204 + if (ret) 1205 + goto out; 1206 + 1207 + val++; 1208 + } 1209 + 1210 + st->num_enabled_channels = val; 1211 + 1212 + out: 1213 + mutex_unlock(&st->lock); 1214 + 1215 + return 0; 1216 + } 1217 + 1218 + static int ad4130_set_fifo_watermark(struct iio_dev *indio_dev, unsigned int val) 1219 + { 1220 + struct ad4130_state *st = iio_priv(indio_dev); 1221 + unsigned int eff; 1222 + int ret; 1223 + 1224 + if (val > AD4130_FIFO_SIZE) 1225 + return -EINVAL; 1226 + 1227 + eff = val * st->num_enabled_channels; 1228 + if (eff > AD4130_FIFO_SIZE) 1229 + /* 1230 + * Always set watermark to a multiple of the number of 1231 + * enabled channels to avoid making the FIFO unaligned. 1232 + */ 1233 + eff = rounddown(AD4130_FIFO_SIZE, st->num_enabled_channels); 1234 + 1235 + mutex_lock(&st->lock); 1236 + 1237 + ret = regmap_update_bits(st->regmap, AD4130_FIFO_CONTROL_REG, 1238 + AD4130_FIFO_CONTROL_WM_MASK, 1239 + FIELD_PREP(AD4130_FIFO_CONTROL_WM_MASK, 1240 + ad4130_watermark_reg_val(eff))); 1241 + if (ret) 1242 + goto out; 1243 + 1244 + st->effective_watermark = eff; 1245 + st->watermark = val; 1246 + 1247 + out: 1248 + mutex_unlock(&st->lock); 1249 + 1250 + return ret; 1251 + } 1252 + 1253 + static const struct iio_info ad4130_info = { 1254 + .read_raw = ad4130_read_raw, 1255 + .read_avail = ad4130_read_avail, 1256 + .write_raw_get_fmt = ad4130_write_raw_get_fmt, 1257 + .write_raw = ad4130_write_raw, 1258 + .update_scan_mode = ad4130_update_scan_mode, 1259 + .hwfifo_set_watermark = ad4130_set_fifo_watermark, 1260 + .debugfs_reg_access = ad4130_reg_access, 1261 + }; 1262 + 1263 + static int ad4130_buffer_postenable(struct iio_dev *indio_dev) 1264 + { 1265 + struct ad4130_state *st = iio_priv(indio_dev); 1266 + int ret; 1267 + 1268 + mutex_lock(&st->lock); 1269 + 1270 + ret = ad4130_set_watermark_interrupt_en(st, true); 1271 + if (ret) 1272 + goto out; 1273 + 1274 + ret = irq_set_irq_type(st->spi->irq, st->inv_irq_trigger); 1275 + if (ret) 1276 + goto out; 1277 + 1278 + ret = ad4130_set_fifo_mode(st, AD4130_FIFO_MODE_WM); 1279 + if (ret) 1280 + goto out; 1281 + 1282 + ret = ad4130_set_mode(st, AD4130_MODE_CONTINUOUS); 1283 + 1284 + out: 1285 + mutex_unlock(&st->lock); 1286 + 1287 + return ret; 1288 + } 1289 + 1290 + static int ad4130_buffer_predisable(struct iio_dev *indio_dev) 1291 + { 1292 + struct ad4130_state *st = iio_priv(indio_dev); 1293 + unsigned int i; 1294 + int ret; 1295 + 1296 + mutex_lock(&st->lock); 1297 + 1298 + ret = ad4130_set_mode(st, AD4130_MODE_IDLE); 1299 + if (ret) 1300 + goto out; 1301 + 1302 + ret = irq_set_irq_type(st->spi->irq, st->irq_trigger); 1303 + if (ret) 1304 + goto out; 1305 + 1306 + ret = ad4130_set_fifo_mode(st, AD4130_FIFO_MODE_DISABLED); 1307 + if (ret) 1308 + goto out; 1309 + 1310 + ret = ad4130_set_watermark_interrupt_en(st, false); 1311 + if (ret) 1312 + goto out; 1313 + 1314 + /* 1315 + * update_scan_mode() is not called in the disable path, disable all 1316 + * channels here. 1317 + */ 1318 + for (i = 0; i < indio_dev->num_channels; i++) { 1319 + ret = ad4130_set_channel_enable(st, i, false); 1320 + if (ret) 1321 + goto out; 1322 + } 1323 + 1324 + out: 1325 + mutex_unlock(&st->lock); 1326 + 1327 + return ret; 1328 + } 1329 + 1330 + static const struct iio_buffer_setup_ops ad4130_buffer_ops = { 1331 + .postenable = ad4130_buffer_postenable, 1332 + .predisable = ad4130_buffer_predisable, 1333 + }; 1334 + 1335 + static ssize_t hwfifo_watermark_show(struct device *dev, 1336 + struct device_attribute *attr, char *buf) 1337 + { 1338 + struct ad4130_state *st = iio_priv(dev_to_iio_dev(dev)); 1339 + unsigned int val; 1340 + 1341 + mutex_lock(&st->lock); 1342 + val = st->watermark; 1343 + mutex_unlock(&st->lock); 1344 + 1345 + return sysfs_emit(buf, "%d\n", val); 1346 + } 1347 + 1348 + static ssize_t hwfifo_enabled_show(struct device *dev, 1349 + struct device_attribute *attr, char *buf) 1350 + { 1351 + struct ad4130_state *st = iio_priv(dev_to_iio_dev(dev)); 1352 + unsigned int val; 1353 + int ret; 1354 + 1355 + ret = regmap_read(st->regmap, AD4130_FIFO_CONTROL_REG, &val); 1356 + if (ret) 1357 + return ret; 1358 + 1359 + val = FIELD_GET(AD4130_FIFO_CONTROL_MODE_MASK, val); 1360 + 1361 + return sysfs_emit(buf, "%d\n", val != AD4130_FIFO_MODE_DISABLED); 1362 + } 1363 + 1364 + static ssize_t hwfifo_watermark_min_show(struct device *dev, 1365 + struct device_attribute *attr, 1366 + char *buf) 1367 + { 1368 + return sysfs_emit(buf, "%s\n", "1"); 1369 + } 1370 + 1371 + static ssize_t hwfifo_watermark_max_show(struct device *dev, 1372 + struct device_attribute *attr, 1373 + char *buf) 1374 + { 1375 + return sysfs_emit(buf, "%s\n", __stringify(AD4130_FIFO_SIZE)); 1376 + } 1377 + 1378 + static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0); 1379 + static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0); 1380 + static IIO_DEVICE_ATTR_RO(hwfifo_watermark, 0); 1381 + static IIO_DEVICE_ATTR_RO(hwfifo_enabled, 0); 1382 + 1383 + static const struct iio_dev_attr *ad4130_fifo_attributes[] = { 1384 + &iio_dev_attr_hwfifo_watermark_min, 1385 + &iio_dev_attr_hwfifo_watermark_max, 1386 + &iio_dev_attr_hwfifo_watermark, 1387 + &iio_dev_attr_hwfifo_enabled, 1388 + NULL 1389 + }; 1390 + 1391 + static int _ad4130_find_table_index(const unsigned int *tbl, size_t len, 1392 + unsigned int val) 1393 + { 1394 + unsigned int i; 1395 + 1396 + for (i = 0; i < len; i++) 1397 + if (tbl[i] == val) 1398 + return i; 1399 + 1400 + return -EINVAL; 1401 + } 1402 + 1403 + #define ad4130_find_table_index(table, val) \ 1404 + _ad4130_find_table_index(table, ARRAY_SIZE(table), val) 1405 + 1406 + static int ad4130_get_ref_voltage(struct ad4130_state *st, 1407 + enum ad4130_ref_sel ref_sel) 1408 + { 1409 + switch (ref_sel) { 1410 + case AD4130_REF_REFIN1: 1411 + return regulator_get_voltage(st->regulators[2].consumer); 1412 + case AD4130_REF_REFIN2: 1413 + return regulator_get_voltage(st->regulators[3].consumer); 1414 + case AD4130_REF_AVDD_AVSS: 1415 + return regulator_get_voltage(st->regulators[0].consumer); 1416 + case AD4130_REF_REFOUT_AVSS: 1417 + return st->int_ref_uv; 1418 + default: 1419 + return -EINVAL; 1420 + } 1421 + } 1422 + 1423 + static int ad4130_parse_fw_setup(struct ad4130_state *st, 1424 + struct fwnode_handle *child, 1425 + struct ad4130_setup_info *setup_info) 1426 + { 1427 + struct device *dev = &st->spi->dev; 1428 + u32 tmp; 1429 + int ret; 1430 + 1431 + tmp = 0; 1432 + fwnode_property_read_u32(child, "adi,excitation-current-0-nanoamp", &tmp); 1433 + ret = ad4130_find_table_index(ad4130_iout_current_na_tbl, tmp); 1434 + if (ret < 0) 1435 + return dev_err_probe(dev, ret, 1436 + "Invalid excitation current %unA\n", tmp); 1437 + setup_info->iout0_val = ret; 1438 + 1439 + tmp = 0; 1440 + fwnode_property_read_u32(child, "adi,excitation-current-1-nanoamp", &tmp); 1441 + ret = ad4130_find_table_index(ad4130_iout_current_na_tbl, tmp); 1442 + if (ret < 0) 1443 + return dev_err_probe(dev, ret, 1444 + "Invalid excitation current %unA\n", tmp); 1445 + setup_info->iout1_val = ret; 1446 + 1447 + tmp = 0; 1448 + fwnode_property_read_u32(child, "adi,burnout-current-nanoamp", &tmp); 1449 + ret = ad4130_find_table_index(ad4130_burnout_current_na_tbl, tmp); 1450 + if (ret < 0) 1451 + return dev_err_probe(dev, ret, 1452 + "Invalid burnout current %unA\n", tmp); 1453 + setup_info->burnout = ret; 1454 + 1455 + setup_info->ref_bufp = fwnode_property_read_bool(child, "adi,buffered-positive"); 1456 + setup_info->ref_bufm = fwnode_property_read_bool(child, "adi,buffered-negative"); 1457 + 1458 + setup_info->ref_sel = AD4130_REF_REFIN1; 1459 + fwnode_property_read_u32(child, "adi,reference-select", 1460 + &setup_info->ref_sel); 1461 + if (setup_info->ref_sel >= AD4130_REF_SEL_MAX) 1462 + return dev_err_probe(dev, -EINVAL, 1463 + "Invalid reference selected %u\n", 1464 + setup_info->ref_sel); 1465 + 1466 + if (setup_info->ref_sel == AD4130_REF_REFOUT_AVSS) 1467 + st->int_ref_en = true; 1468 + 1469 + ret = ad4130_get_ref_voltage(st, setup_info->ref_sel); 1470 + if (ret < 0) 1471 + return dev_err_probe(dev, ret, "Cannot use reference %u\n", 1472 + setup_info->ref_sel); 1473 + 1474 + return 0; 1475 + } 1476 + 1477 + static int ad4130_validate_diff_channel(struct ad4130_state *st, u32 pin) 1478 + { 1479 + struct device *dev = &st->spi->dev; 1480 + 1481 + if (pin >= AD4130_MAX_DIFF_INPUTS) 1482 + return dev_err_probe(dev, -EINVAL, 1483 + "Invalid differential channel %u\n", pin); 1484 + 1485 + if (pin >= AD4130_MAX_ANALOG_PINS) 1486 + return 0; 1487 + 1488 + if (st->pins_fn[pin] == AD4130_PIN_FN_SPECIAL) 1489 + return dev_err_probe(dev, -EINVAL, 1490 + "Pin %u already used with fn %u\n", pin, 1491 + st->pins_fn[pin]); 1492 + 1493 + st->pins_fn[pin] |= AD4130_PIN_FN_DIFF; 1494 + 1495 + return 0; 1496 + } 1497 + 1498 + static int ad4130_validate_diff_channels(struct ad4130_state *st, 1499 + u32 *pins, unsigned int len) 1500 + { 1501 + unsigned int i; 1502 + int ret; 1503 + 1504 + for (i = 0; i < len; i++) { 1505 + ret = ad4130_validate_diff_channel(st, pins[i]); 1506 + if (ret) 1507 + return ret; 1508 + } 1509 + 1510 + return 0; 1511 + } 1512 + 1513 + static int ad4130_validate_excitation_pin(struct ad4130_state *st, u32 pin) 1514 + { 1515 + struct device *dev = &st->spi->dev; 1516 + 1517 + if (pin >= AD4130_MAX_ANALOG_PINS) 1518 + return dev_err_probe(dev, -EINVAL, 1519 + "Invalid excitation pin %u\n", pin); 1520 + 1521 + if (st->pins_fn[pin] == AD4130_PIN_FN_SPECIAL) 1522 + return dev_err_probe(dev, -EINVAL, 1523 + "Pin %u already used with fn %u\n", pin, 1524 + st->pins_fn[pin]); 1525 + 1526 + st->pins_fn[pin] |= AD4130_PIN_FN_EXCITATION; 1527 + 1528 + return 0; 1529 + } 1530 + 1531 + static int ad4130_validate_vbias_pin(struct ad4130_state *st, u32 pin) 1532 + { 1533 + struct device *dev = &st->spi->dev; 1534 + 1535 + if (pin >= AD4130_MAX_ANALOG_PINS) 1536 + return dev_err_probe(dev, -EINVAL, "Invalid vbias pin %u\n", 1537 + pin); 1538 + 1539 + if (st->pins_fn[pin] == AD4130_PIN_FN_SPECIAL) 1540 + return dev_err_probe(dev, -EINVAL, 1541 + "Pin %u already used with fn %u\n", pin, 1542 + st->pins_fn[pin]); 1543 + 1544 + st->pins_fn[pin] |= AD4130_PIN_FN_VBIAS; 1545 + 1546 + return 0; 1547 + } 1548 + 1549 + static int ad4130_validate_vbias_pins(struct ad4130_state *st, 1550 + u32 *pins, unsigned int len) 1551 + { 1552 + unsigned int i; 1553 + int ret; 1554 + 1555 + for (i = 0; i < st->num_vbias_pins; i++) { 1556 + ret = ad4130_validate_vbias_pin(st, pins[i]); 1557 + if (ret) 1558 + return ret; 1559 + } 1560 + 1561 + return 0; 1562 + } 1563 + 1564 + static int ad4130_parse_fw_channel(struct iio_dev *indio_dev, 1565 + struct fwnode_handle *child) 1566 + { 1567 + struct ad4130_state *st = iio_priv(indio_dev); 1568 + unsigned int resolution = ad4130_resolution(st); 1569 + unsigned int index = indio_dev->num_channels++; 1570 + struct device *dev = &st->spi->dev; 1571 + struct ad4130_chan_info *chan_info; 1572 + struct iio_chan_spec *chan; 1573 + u32 pins[2]; 1574 + int ret; 1575 + 1576 + if (index >= AD4130_MAX_CHANNELS) 1577 + return dev_err_probe(dev, -EINVAL, "Too many channels\n"); 1578 + 1579 + chan = &st->chans[index]; 1580 + chan_info = &st->chans_info[index]; 1581 + 1582 + *chan = ad4130_channel_template; 1583 + chan->scan_type.realbits = resolution; 1584 + chan->scan_type.storagebits = resolution; 1585 + chan->scan_index = index; 1586 + 1587 + chan_info->slot = AD4130_INVALID_SLOT; 1588 + chan_info->setup.fs = AD4130_FILTER_SELECT_MIN; 1589 + chan_info->initialized = true; 1590 + 1591 + ret = fwnode_property_read_u32_array(child, "diff-channels", pins, 1592 + ARRAY_SIZE(pins)); 1593 + if (ret) 1594 + return ret; 1595 + 1596 + ret = ad4130_validate_diff_channels(st, pins, ARRAY_SIZE(pins)); 1597 + if (ret) 1598 + return ret; 1599 + 1600 + chan->channel = pins[0]; 1601 + chan->channel2 = pins[1]; 1602 + 1603 + ret = ad4130_parse_fw_setup(st, child, &chan_info->setup); 1604 + if (ret) 1605 + return ret; 1606 + 1607 + fwnode_property_read_u32(child, "adi,excitation-pin-0", 1608 + &chan_info->iout0); 1609 + if (chan_info->setup.iout0_val != AD4130_IOUT_OFF) { 1610 + ret = ad4130_validate_excitation_pin(st, chan_info->iout0); 1611 + if (ret) 1612 + return ret; 1613 + } 1614 + 1615 + fwnode_property_read_u32(child, "adi,excitation-pin-1", 1616 + &chan_info->iout1); 1617 + if (chan_info->setup.iout1_val != AD4130_IOUT_OFF) { 1618 + ret = ad4130_validate_excitation_pin(st, chan_info->iout1); 1619 + if (ret) 1620 + return ret; 1621 + } 1622 + 1623 + return 0; 1624 + } 1625 + 1626 + static int ad4130_parse_fw_children(struct iio_dev *indio_dev) 1627 + { 1628 + struct ad4130_state *st = iio_priv(indio_dev); 1629 + struct device *dev = &st->spi->dev; 1630 + struct fwnode_handle *child; 1631 + int ret; 1632 + 1633 + indio_dev->channels = st->chans; 1634 + 1635 + device_for_each_child_node(dev, child) { 1636 + ret = ad4130_parse_fw_channel(indio_dev, child); 1637 + if (ret) { 1638 + fwnode_handle_put(child); 1639 + return ret; 1640 + } 1641 + } 1642 + 1643 + return 0; 1644 + } 1645 + 1646 + static int ad4310_parse_fw(struct iio_dev *indio_dev) 1647 + { 1648 + struct ad4130_state *st = iio_priv(indio_dev); 1649 + struct device *dev = &st->spi->dev; 1650 + u32 ext_clk_freq = AD4130_MCLK_FREQ_76_8KHZ; 1651 + unsigned int i; 1652 + int avdd_uv; 1653 + int irq; 1654 + int ret; 1655 + 1656 + st->mclk = devm_clk_get_optional(dev, "mclk"); 1657 + if (IS_ERR(st->mclk)) 1658 + return dev_err_probe(dev, PTR_ERR(st->mclk), 1659 + "Failed to get mclk\n"); 1660 + 1661 + st->int_pin_sel = AD4130_INT_PIN_INT; 1662 + 1663 + for (i = 0; i < ARRAY_SIZE(ad4130_int_pin_names); i++) { 1664 + irq = fwnode_irq_get_byname(dev_fwnode(dev), 1665 + ad4130_int_pin_names[i]); 1666 + if (irq > 0) { 1667 + st->int_pin_sel = i; 1668 + break; 1669 + } 1670 + } 1671 + 1672 + if (st->int_pin_sel == AD4130_INT_PIN_DOUT) 1673 + return dev_err_probe(dev, -EINVAL, 1674 + "Cannot use DOUT as interrupt pin\n"); 1675 + 1676 + if (st->int_pin_sel == AD4130_INT_PIN_P2) 1677 + st->pins_fn[AD4130_AIN3_P2] = AD4130_PIN_FN_SPECIAL; 1678 + 1679 + device_property_read_u32(dev, "adi,ext-clk-freq-hz", &ext_clk_freq); 1680 + if (ext_clk_freq != AD4130_MCLK_FREQ_153_6KHZ && 1681 + ext_clk_freq != AD4130_MCLK_FREQ_76_8KHZ) 1682 + return dev_err_probe(dev, -EINVAL, 1683 + "Invalid external clock frequency %u\n", 1684 + ext_clk_freq); 1685 + 1686 + if (st->mclk && ext_clk_freq == AD4130_MCLK_FREQ_153_6KHZ) 1687 + st->mclk_sel = AD4130_MCLK_153_6KHZ_EXT; 1688 + else if (st->mclk) 1689 + st->mclk_sel = AD4130_MCLK_76_8KHZ_EXT; 1690 + else 1691 + st->mclk_sel = AD4130_MCLK_76_8KHZ; 1692 + 1693 + if (st->int_pin_sel == AD4130_INT_PIN_CLK && 1694 + st->mclk_sel != AD4130_MCLK_76_8KHZ) 1695 + return dev_err_probe(dev, -EINVAL, 1696 + "Invalid clock %u for interrupt pin %u\n", 1697 + st->mclk_sel, st->int_pin_sel); 1698 + 1699 + st->int_ref_uv = AD4130_INT_REF_2_5V; 1700 + 1701 + /* 1702 + * When the AVDD supply is set to below 2.5V the internal reference of 1703 + * 1.25V should be selected. 1704 + * See datasheet page 37, section ADC REFERENCE. 1705 + */ 1706 + avdd_uv = regulator_get_voltage(st->regulators[0].consumer); 1707 + if (avdd_uv > 0 && avdd_uv < AD4130_INT_REF_2_5V) 1708 + st->int_ref_uv = AD4130_INT_REF_1_25V; 1709 + 1710 + st->bipolar = device_property_read_bool(dev, "adi,bipolar"); 1711 + 1712 + ret = device_property_count_u32(dev, "adi,vbias-pins"); 1713 + if (ret > 0) { 1714 + if (ret > AD4130_MAX_ANALOG_PINS) 1715 + return dev_err_probe(dev, -EINVAL, 1716 + "Too many vbias pins %u\n", ret); 1717 + 1718 + st->num_vbias_pins = ret; 1719 + 1720 + ret = device_property_read_u32_array(dev, "adi,vbias-pins", 1721 + st->vbias_pins, 1722 + st->num_vbias_pins); 1723 + if (ret) 1724 + return dev_err_probe(dev, ret, 1725 + "Failed to read vbias pins\n"); 1726 + 1727 + ret = ad4130_validate_vbias_pins(st, st->vbias_pins, 1728 + st->num_vbias_pins); 1729 + if (ret) 1730 + return ret; 1731 + } 1732 + 1733 + ret = ad4130_parse_fw_children(indio_dev); 1734 + if (ret) 1735 + return ret; 1736 + 1737 + return 0; 1738 + } 1739 + 1740 + static void ad4130_fill_scale_tbls(struct ad4130_state *st) 1741 + { 1742 + unsigned int pow = ad4130_resolution(st) - st->bipolar; 1743 + unsigned int i, j; 1744 + 1745 + for (i = 0; i < AD4130_REF_SEL_MAX; i++) { 1746 + int ret; 1747 + u64 nv; 1748 + 1749 + ret = ad4130_get_ref_voltage(st, i); 1750 + if (ret < 0) 1751 + continue; 1752 + 1753 + nv = (u64)ret * NANO; 1754 + 1755 + for (j = 0; j < AD4130_MAX_PGA; j++) 1756 + st->scale_tbls[i][j][1] = div_u64(nv >> (pow + j), MILLI); 1757 + } 1758 + } 1759 + 1760 + static void ad4130_clk_disable_unprepare(void *clk) 1761 + { 1762 + clk_disable_unprepare(clk); 1763 + } 1764 + 1765 + static int ad4130_set_mclk_sel(struct ad4130_state *st, 1766 + enum ad4130_mclk_sel mclk_sel) 1767 + { 1768 + return regmap_update_bits(st->regmap, AD4130_ADC_CONTROL_REG, 1769 + AD4130_ADC_CONTROL_MCLK_SEL_MASK, 1770 + FIELD_PREP(AD4130_ADC_CONTROL_MCLK_SEL_MASK, 1771 + mclk_sel)); 1772 + } 1773 + 1774 + static unsigned long ad4130_int_clk_recalc_rate(struct clk_hw *hw, 1775 + unsigned long parent_rate) 1776 + { 1777 + return AD4130_MCLK_FREQ_76_8KHZ; 1778 + } 1779 + 1780 + static int ad4130_int_clk_is_enabled(struct clk_hw *hw) 1781 + { 1782 + struct ad4130_state *st = container_of(hw, struct ad4130_state, int_clk_hw); 1783 + 1784 + return st->mclk_sel == AD4130_MCLK_76_8KHZ_OUT; 1785 + } 1786 + 1787 + static int ad4130_int_clk_prepare(struct clk_hw *hw) 1788 + { 1789 + struct ad4130_state *st = container_of(hw, struct ad4130_state, int_clk_hw); 1790 + int ret; 1791 + 1792 + ret = ad4130_set_mclk_sel(st, AD4130_MCLK_76_8KHZ_OUT); 1793 + if (ret) 1794 + return ret; 1795 + 1796 + st->mclk_sel = AD4130_MCLK_76_8KHZ_OUT; 1797 + 1798 + return 0; 1799 + } 1800 + 1801 + static void ad4130_int_clk_unprepare(struct clk_hw *hw) 1802 + { 1803 + struct ad4130_state *st = container_of(hw, struct ad4130_state, int_clk_hw); 1804 + int ret; 1805 + 1806 + ret = ad4130_set_mclk_sel(st, AD4130_MCLK_76_8KHZ); 1807 + if (ret) 1808 + return; 1809 + 1810 + st->mclk_sel = AD4130_MCLK_76_8KHZ; 1811 + } 1812 + 1813 + static const struct clk_ops ad4130_int_clk_ops = { 1814 + .recalc_rate = ad4130_int_clk_recalc_rate, 1815 + .is_enabled = ad4130_int_clk_is_enabled, 1816 + .prepare = ad4130_int_clk_prepare, 1817 + .unprepare = ad4130_int_clk_unprepare, 1818 + }; 1819 + 1820 + static int ad4130_setup_int_clk(struct ad4130_state *st) 1821 + { 1822 + struct device *dev = &st->spi->dev; 1823 + struct device_node *of_node = dev_of_node(dev); 1824 + struct clk_init_data init; 1825 + const char *clk_name; 1826 + struct clk *clk; 1827 + 1828 + if (st->int_pin_sel == AD4130_INT_PIN_CLK || 1829 + st->mclk_sel != AD4130_MCLK_76_8KHZ) 1830 + return 0; 1831 + 1832 + if (!of_node) 1833 + return 0; 1834 + 1835 + clk_name = of_node->name; 1836 + of_property_read_string(of_node, "clock-output-names", &clk_name); 1837 + 1838 + init.name = clk_name; 1839 + init.ops = &ad4130_int_clk_ops; 1840 + 1841 + st->int_clk_hw.init = &init; 1842 + clk = devm_clk_register(dev, &st->int_clk_hw); 1843 + if (IS_ERR(clk)) 1844 + return PTR_ERR(clk); 1845 + 1846 + return of_clk_add_provider(of_node, of_clk_src_simple_get, clk); 1847 + } 1848 + 1849 + static int ad4130_setup(struct iio_dev *indio_dev) 1850 + { 1851 + struct ad4130_state *st = iio_priv(indio_dev); 1852 + struct device *dev = &st->spi->dev; 1853 + unsigned int int_ref_val; 1854 + unsigned long rate = AD4130_MCLK_FREQ_76_8KHZ; 1855 + unsigned int val; 1856 + unsigned int i; 1857 + int ret; 1858 + 1859 + if (st->mclk_sel == AD4130_MCLK_153_6KHZ_EXT) 1860 + rate = AD4130_MCLK_FREQ_153_6KHZ; 1861 + 1862 + ret = clk_set_rate(st->mclk, rate); 1863 + if (ret) 1864 + return ret; 1865 + 1866 + ret = clk_prepare_enable(st->mclk); 1867 + if (ret) 1868 + return ret; 1869 + 1870 + ret = devm_add_action_or_reset(dev, ad4130_clk_disable_unprepare, 1871 + st->mclk); 1872 + if (ret) 1873 + return ret; 1874 + 1875 + if (st->int_ref_uv == AD4130_INT_REF_2_5V) 1876 + int_ref_val = AD4130_INT_REF_VAL_2_5V; 1877 + else 1878 + int_ref_val = AD4130_INT_REF_VAL_1_25V; 1879 + 1880 + /* Switch to SPI 4-wire mode. */ 1881 + val = FIELD_PREP(AD4130_ADC_CONTROL_CSB_EN_MASK, 1); 1882 + val |= FIELD_PREP(AD4130_ADC_CONTROL_BIPOLAR_MASK, st->bipolar); 1883 + val |= FIELD_PREP(AD4130_ADC_CONTROL_INT_REF_EN_MASK, st->int_ref_en); 1884 + val |= FIELD_PREP(AD4130_ADC_CONTROL_MODE_MASK, AD4130_MODE_IDLE); 1885 + val |= FIELD_PREP(AD4130_ADC_CONTROL_MCLK_SEL_MASK, st->mclk_sel); 1886 + val |= FIELD_PREP(AD4130_ADC_CONTROL_INT_REF_VAL_MASK, int_ref_val); 1887 + 1888 + ret = regmap_write(st->regmap, AD4130_ADC_CONTROL_REG, val); 1889 + if (ret) 1890 + return ret; 1891 + 1892 + /* 1893 + * Configure all GPIOs for output. If configured, the interrupt function 1894 + * of P2 takes priority over the GPIO out function. 1895 + */ 1896 + val = AD4130_IO_CONTROL_GPIO_CTRL_MASK; 1897 + val |= FIELD_PREP(AD4130_IO_CONTROL_INT_PIN_SEL_MASK, st->int_pin_sel); 1898 + 1899 + ret = regmap_write(st->regmap, AD4130_IO_CONTROL_REG, val); 1900 + if (ret) 1901 + return ret; 1902 + 1903 + val = 0; 1904 + for (i = 0; i < st->num_vbias_pins; i++) 1905 + val |= BIT(st->vbias_pins[i]); 1906 + 1907 + ret = regmap_write(st->regmap, AD4130_VBIAS_REG, val); 1908 + if (ret) 1909 + return ret; 1910 + 1911 + ret = regmap_update_bits(st->regmap, AD4130_FIFO_CONTROL_REG, 1912 + AD4130_FIFO_CONTROL_HEADER_MASK, 0); 1913 + if (ret) 1914 + return ret; 1915 + 1916 + /* FIFO watermark interrupt starts out as enabled, disable it. */ 1917 + ret = ad4130_set_watermark_interrupt_en(st, false); 1918 + if (ret) 1919 + return ret; 1920 + 1921 + /* Setup channels. */ 1922 + for (i = 0; i < indio_dev->num_channels; i++) { 1923 + struct ad4130_chan_info *chan_info = &st->chans_info[i]; 1924 + struct iio_chan_spec *chan = &st->chans[i]; 1925 + unsigned int val; 1926 + 1927 + val = FIELD_PREP(AD4130_CHANNEL_AINP_MASK, chan->channel) | 1928 + FIELD_PREP(AD4130_CHANNEL_AINM_MASK, chan->channel2) | 1929 + FIELD_PREP(AD4130_CHANNEL_IOUT1_MASK, chan_info->iout0) | 1930 + FIELD_PREP(AD4130_CHANNEL_IOUT2_MASK, chan_info->iout1); 1931 + 1932 + ret = regmap_write(st->regmap, AD4130_CHANNEL_X_REG(i), val); 1933 + if (ret) 1934 + return ret; 1935 + } 1936 + 1937 + return 0; 1938 + } 1939 + 1940 + static int ad4130_soft_reset(struct ad4130_state *st) 1941 + { 1942 + int ret; 1943 + 1944 + ret = spi_write(st->spi, st->reset_buf, sizeof(st->reset_buf)); 1945 + if (ret) 1946 + return ret; 1947 + 1948 + fsleep(AD4130_RESET_SLEEP_US); 1949 + 1950 + return 0; 1951 + } 1952 + 1953 + static void ad4130_disable_regulators(void *data) 1954 + { 1955 + struct ad4130_state *st = data; 1956 + 1957 + regulator_bulk_disable(ARRAY_SIZE(st->regulators), st->regulators); 1958 + } 1959 + 1960 + static int ad4130_probe(struct spi_device *spi) 1961 + { 1962 + struct device *dev = &spi->dev; 1963 + struct iio_dev *indio_dev; 1964 + struct ad4130_state *st; 1965 + int ret; 1966 + 1967 + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 1968 + if (!indio_dev) 1969 + return -ENOMEM; 1970 + 1971 + st = iio_priv(indio_dev); 1972 + 1973 + memset(st->reset_buf, 0xff, sizeof(st->reset_buf)); 1974 + init_completion(&st->completion); 1975 + mutex_init(&st->lock); 1976 + st->spi = spi; 1977 + 1978 + /* 1979 + * Xfer: [ XFR1 ] [ XFR2 ] 1980 + * Master: 0x7D N ...................... 1981 + * Slave: ...... DATA1 DATA2 ... DATAN 1982 + */ 1983 + st->fifo_tx_buf[0] = AD4130_COMMS_READ_MASK | AD4130_FIFO_DATA_REG; 1984 + st->fifo_xfer[0].tx_buf = st->fifo_tx_buf; 1985 + st->fifo_xfer[0].len = sizeof(st->fifo_tx_buf); 1986 + st->fifo_xfer[1].rx_buf = st->fifo_rx_buf; 1987 + spi_message_init_with_transfers(&st->fifo_msg, st->fifo_xfer, 1988 + ARRAY_SIZE(st->fifo_xfer)); 1989 + 1990 + indio_dev->name = AD4130_NAME; 1991 + indio_dev->modes = INDIO_DIRECT_MODE; 1992 + indio_dev->info = &ad4130_info; 1993 + 1994 + st->regmap = devm_regmap_init(dev, NULL, st, &ad4130_regmap_config); 1995 + if (IS_ERR(st->regmap)) 1996 + return PTR_ERR(st->regmap); 1997 + 1998 + st->regulators[0].supply = "avdd"; 1999 + st->regulators[1].supply = "iovdd"; 2000 + st->regulators[2].supply = "refin1"; 2001 + st->regulators[3].supply = "refin2"; 2002 + 2003 + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(st->regulators), 2004 + st->regulators); 2005 + if (ret) 2006 + return dev_err_probe(dev, ret, "Failed to get regulators\n"); 2007 + 2008 + ret = regulator_bulk_enable(ARRAY_SIZE(st->regulators), st->regulators); 2009 + if (ret) 2010 + return dev_err_probe(dev, ret, "Failed to enable regulators\n"); 2011 + 2012 + ret = devm_add_action_or_reset(dev, ad4130_disable_regulators, st); 2013 + if (ret) 2014 + return dev_err_probe(dev, ret, 2015 + "Failed to add regulators disable action\n"); 2016 + 2017 + ret = ad4130_soft_reset(st); 2018 + if (ret) 2019 + return ret; 2020 + 2021 + ret = ad4310_parse_fw(indio_dev); 2022 + if (ret) 2023 + return ret; 2024 + 2025 + ret = ad4130_setup(indio_dev); 2026 + if (ret) 2027 + return ret; 2028 + 2029 + ret = ad4130_setup_int_clk(st); 2030 + if (ret) 2031 + return ret; 2032 + 2033 + ad4130_fill_scale_tbls(st); 2034 + 2035 + st->gc.owner = THIS_MODULE; 2036 + st->gc.label = AD4130_NAME; 2037 + st->gc.base = -1; 2038 + st->gc.ngpio = AD4130_MAX_GPIOS; 2039 + st->gc.parent = dev; 2040 + st->gc.can_sleep = true; 2041 + st->gc.init_valid_mask = ad4130_gpio_init_valid_mask; 2042 + st->gc.get_direction = ad4130_gpio_get_direction; 2043 + st->gc.set = ad4130_gpio_set; 2044 + 2045 + ret = devm_gpiochip_add_data(dev, &st->gc, st); 2046 + if (ret) 2047 + return ret; 2048 + 2049 + ret = devm_iio_kfifo_buffer_setup_ext(dev, indio_dev, 2050 + &ad4130_buffer_ops, 2051 + ad4130_fifo_attributes); 2052 + if (ret) 2053 + return ret; 2054 + 2055 + ret = devm_request_threaded_irq(dev, spi->irq, NULL, 2056 + ad4130_irq_handler, IRQF_ONESHOT, 2057 + indio_dev->name, indio_dev); 2058 + if (ret) 2059 + return dev_err_probe(dev, ret, "Failed to request irq\n"); 2060 + 2061 + /* 2062 + * When the chip enters FIFO mode, IRQ polarity is inverted. 2063 + * When the chip exits FIFO mode, IRQ polarity returns to normal. 2064 + * See datasheet pages: 65, FIFO Watermark Interrupt section, 2065 + * and 71, Bit Descriptions for STATUS Register, RDYB. 2066 + * Cache the normal and inverted IRQ triggers to set them when 2067 + * entering and exiting FIFO mode. 2068 + */ 2069 + st->irq_trigger = irq_get_trigger_type(spi->irq); 2070 + if (st->irq_trigger & IRQF_TRIGGER_RISING) 2071 + st->inv_irq_trigger = IRQF_TRIGGER_FALLING; 2072 + else if (st->irq_trigger & IRQF_TRIGGER_FALLING) 2073 + st->inv_irq_trigger = IRQF_TRIGGER_RISING; 2074 + else 2075 + return dev_err_probe(dev, -EINVAL, "Invalid irq flags: %u\n", 2076 + st->irq_trigger); 2077 + 2078 + return devm_iio_device_register(dev, indio_dev); 2079 + } 2080 + 2081 + static const struct of_device_id ad4130_of_match[] = { 2082 + { 2083 + .compatible = "adi,ad4130", 2084 + }, 2085 + { } 2086 + }; 2087 + MODULE_DEVICE_TABLE(of, ad4130_of_match); 2088 + 2089 + static struct spi_driver ad4130_driver = { 2090 + .driver = { 2091 + .name = AD4130_NAME, 2092 + .of_match_table = ad4130_of_match, 2093 + }, 2094 + .probe = ad4130_probe, 2095 + }; 2096 + module_spi_driver(ad4130_driver); 2097 + 2098 + MODULE_AUTHOR("Cosmin Tanislav <cosmin.tanislav@analog.com>"); 2099 + MODULE_DESCRIPTION("Analog Devices AD4130 SPI driver"); 2100 + MODULE_LICENSE("GPL");
+10
drivers/iio/adc/ad7124.c
··· 945 945 946 946 info = of_device_get_match_data(&spi->dev); 947 947 if (!info) 948 + info = (void *)spi_get_device_id(spi)->driver_data; 949 + if (!info) 948 950 return -ENODEV; 949 951 950 952 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); ··· 1023 1021 }; 1024 1022 MODULE_DEVICE_TABLE(of, ad7124_of_match); 1025 1023 1024 + static const struct spi_device_id ad71124_ids[] = { 1025 + { "ad7124-4", (kernel_ulong_t)&ad7124_chip_info_tbl[ID_AD7124_4] }, 1026 + { "ad7124-8", (kernel_ulong_t)&ad7124_chip_info_tbl[ID_AD7124_8] }, 1027 + {} 1028 + }; 1029 + MODULE_DEVICE_TABLE(spi, ad71124_ids); 1030 + 1026 1031 static struct spi_driver ad71124_driver = { 1027 1032 .driver = { 1028 1033 .name = "ad7124", 1029 1034 .of_match_table = ad7124_of_match, 1030 1035 }, 1031 1036 .probe = ad7124_probe, 1037 + .id_table = ad71124_ids, 1032 1038 }; 1033 1039 module_spi_driver(ad71124_driver); 1034 1040
+14 -13
drivers/iio/adc/ad7192.c
··· 177 177 struct ad7192_state { 178 178 const struct ad7192_chip_info *chip_info; 179 179 struct regulator *avdd; 180 - struct regulator *dvdd; 181 180 struct clk *mclk; 182 181 u16 int_vref_mv; 183 182 u32 fclk; ··· 1014 1015 if (ret) 1015 1016 return ret; 1016 1017 1017 - st->dvdd = devm_regulator_get(&spi->dev, "dvdd"); 1018 - if (IS_ERR(st->dvdd)) 1019 - return PTR_ERR(st->dvdd); 1020 - 1021 - ret = regulator_enable(st->dvdd); 1022 - if (ret) { 1023 - dev_err(&spi->dev, "Failed to enable specified DVdd supply\n"); 1024 - return ret; 1025 - } 1026 - 1027 - ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, st->dvdd); 1018 + ret = devm_regulator_get_enable(&spi->dev, "dvdd"); 1028 1019 if (ret) 1029 - return ret; 1020 + return dev_err_probe(&spi->dev, ret, "Failed to enable specified DVdd supply\n"); 1030 1021 1031 1022 ret = regulator_get_voltage(st->avdd); 1032 1023 if (ret < 0) { ··· 1026 1037 st->int_vref_mv = ret / 1000; 1027 1038 1028 1039 st->chip_info = of_device_get_match_data(&spi->dev); 1040 + if (!st->chip_info) 1041 + st->chip_info = (void *)spi_get_device_id(spi)->driver_data; 1029 1042 indio_dev->name = st->chip_info->name; 1030 1043 indio_dev->modes = INDIO_DIRECT_MODE; 1031 1044 ··· 1089 1098 }; 1090 1099 MODULE_DEVICE_TABLE(of, ad7192_of_match); 1091 1100 1101 + static const struct spi_device_id ad7192_ids[] = { 1102 + { "ad7190", (kernel_ulong_t)&ad7192_chip_info_tbl[ID_AD7190] }, 1103 + { "ad7192", (kernel_ulong_t)&ad7192_chip_info_tbl[ID_AD7192] }, 1104 + { "ad7193", (kernel_ulong_t)&ad7192_chip_info_tbl[ID_AD7193] }, 1105 + { "ad7195", (kernel_ulong_t)&ad7192_chip_info_tbl[ID_AD7195] }, 1106 + {} 1107 + }; 1108 + MODULE_DEVICE_TABLE(spi, ad7192_ids); 1109 + 1092 1110 static struct spi_driver ad7192_driver = { 1093 1111 .driver = { 1094 1112 .name = "ad7192", 1095 1113 .of_match_table = ad7192_of_match, 1096 1114 }, 1097 1115 .probe = ad7192_probe, 1116 + .id_table = ad7192_ids, 1098 1117 }; 1099 1118 module_spi_driver(ad7192_driver); 1100 1119
+1 -10
drivers/iio/adc/ad7476.c
··· 368 368 } 369 369 370 370 if (st->chip_info->has_vdrive) { 371 - reg = devm_regulator_get(&spi->dev, "vdrive"); 372 - if (IS_ERR(reg)) 373 - return PTR_ERR(reg); 374 - 375 - ret = regulator_enable(reg); 376 - if (ret) 377 - return ret; 378 - 379 - ret = devm_add_action_or_reset(&spi->dev, ad7476_reg_disable, 380 - reg); 371 + ret = devm_regulator_get_enable(&spi->dev, "vdrive"); 381 372 if (ret) 382 373 return ret; 383 374 }
+3 -19
drivers/iio/adc/ad7606.c
··· 557 557 .validate_device = iio_trigger_validate_own_device, 558 558 }; 559 559 560 - static void ad7606_regulator_disable(void *data) 561 - { 562 - struct ad7606_state *st = data; 563 - 564 - regulator_disable(st->reg); 565 - } 566 - 567 560 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, 568 561 const char *name, unsigned int id, 569 562 const struct ad7606_bus_ops *bops) ··· 582 589 st->scale_avail = ad7606_scale_avail; 583 590 st->num_scales = ARRAY_SIZE(ad7606_scale_avail); 584 591 585 - st->reg = devm_regulator_get(dev, "avcc"); 586 - if (IS_ERR(st->reg)) 587 - return PTR_ERR(st->reg); 588 - 589 - ret = regulator_enable(st->reg); 590 - if (ret) { 591 - dev_err(dev, "Failed to enable specified AVcc supply\n"); 592 - return ret; 593 - } 594 - 595 - ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st); 592 + ret = devm_regulator_get_enable(dev, "avcc"); 596 593 if (ret) 597 - return ret; 594 + return dev_err_probe(dev, ret, 595 + "Failed to enable specified AVcc supply\n"); 598 596 599 597 st->chip_info = &ad7606_chip_info_tbl[id]; 600 598
-2
drivers/iio/adc/ad7606.h
··· 62 62 * struct ad7606_state - driver instance specific data 63 63 * @dev pointer to kernel device 64 64 * @chip_info entry in the table of chips that describes this device 65 - * @reg regulator info for the power supply of the device 66 65 * @bops bus operations (SPI or parallel) 67 66 * @range voltage range selection, selects which scale to apply 68 67 * @oversampling oversampling selection ··· 91 92 struct ad7606_state { 92 93 struct device *dev; 93 94 const struct ad7606_chip_info *chip_info; 94 - struct regulator *reg; 95 95 const struct ad7606_bus_ops *bops; 96 96 unsigned int range[16]; 97 97 unsigned int oversampling;
+14 -6
drivers/iio/adc/ad799x.c
··· 28 28 #include <linux/types.h> 29 29 #include <linux/err.h> 30 30 #include <linux/module.h> 31 + #include <linux/mutex.h> 31 32 #include <linux/bitops.h> 32 33 33 34 #include <linux/iio/iio.h> ··· 126 125 const struct ad799x_chip_config *chip_config; 127 126 struct regulator *reg; 128 127 struct regulator *vref; 128 + /* lock to protect against multiple access to the device */ 129 + struct mutex lock; 129 130 unsigned id; 130 131 u16 config; 131 132 ··· 293 290 ret = iio_device_claim_direct_mode(indio_dev); 294 291 if (ret) 295 292 return ret; 293 + mutex_lock(&st->lock); 296 294 ret = ad799x_scan_direct(st, chan->scan_index); 295 + mutex_unlock(&st->lock); 297 296 iio_device_release_direct_mode(indio_dev); 298 297 299 298 if (ret < 0) ··· 356 351 if (ret) 357 352 return ret; 358 353 359 - mutex_lock(&indio_dev->mlock); 354 + mutex_lock(&st->lock); 355 + 360 356 ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG); 361 357 if (ret < 0) 362 358 goto error_ret_mutex; ··· 379 373 ret = len; 380 374 381 375 error_ret_mutex: 382 - mutex_unlock(&indio_dev->mlock); 376 + mutex_unlock(&st->lock); 383 377 384 378 return ret; 385 379 } ··· 413 407 if (ret) 414 408 return ret; 415 409 410 + mutex_lock(&st->lock); 411 + 416 412 if (state) 417 413 st->config |= BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT; 418 414 else ··· 426 418 st->config &= ~AD7998_ALERT_EN; 427 419 428 420 ret = ad799x_write_config(st, st->config); 421 + mutex_unlock(&st->lock); 429 422 iio_device_release_direct_mode(indio_dev); 430 423 return ret; 431 424 } ··· 463 454 if (val < 0 || val > GENMASK(chan->scan_type.realbits - 1, 0)) 464 455 return -EINVAL; 465 456 466 - mutex_lock(&indio_dev->mlock); 467 457 ret = i2c_smbus_write_word_swapped(st->client, 468 458 ad799x_threshold_reg(chan, dir, info), 469 459 val << chan->scan_type.shift); 470 - mutex_unlock(&indio_dev->mlock); 471 460 472 461 return ret; 473 462 } ··· 480 473 int ret; 481 474 struct ad799x_state *st = iio_priv(indio_dev); 482 475 483 - mutex_lock(&indio_dev->mlock); 484 476 ret = i2c_smbus_read_word_swapped(st->client, 485 477 ad799x_threshold_reg(chan, dir, info)); 486 - mutex_unlock(&indio_dev->mlock); 487 478 if (ret < 0) 488 479 return ret; 489 480 *val = (ret >> chan->scan_type.shift) & ··· 868 863 if (ret) 869 864 goto error_cleanup_ring; 870 865 } 866 + 867 + mutex_init(&st->lock); 868 + 871 869 ret = iio_device_register(indio_dev); 872 870 if (ret) 873 871 goto error_cleanup_ring;
+11
drivers/iio/adc/ad9467.c
··· 388 388 389 389 info = of_device_get_match_data(&spi->dev); 390 390 if (!info) 391 + info = (void *)spi_get_device_id(spi)->driver_data; 392 + if (!info) 391 393 return -ENODEV; 392 394 393 395 conv = devm_adi_axi_adc_conv_register(&spi->dev, sizeof(*st)); ··· 449 447 }; 450 448 MODULE_DEVICE_TABLE(of, ad9467_of_match); 451 449 450 + static const struct spi_device_id ad9467_ids[] = { 451 + { "ad9265", (kernel_ulong_t)&ad9467_chip_tbl[ID_AD9265] }, 452 + { "ad9434", (kernel_ulong_t)&ad9467_chip_tbl[ID_AD9434] }, 453 + { "ad9467", (kernel_ulong_t)&ad9467_chip_tbl[ID_AD9467] }, 454 + {} 455 + }; 456 + MODULE_DEVICE_TABLE(spi, ad9467_ids); 457 + 452 458 static struct spi_driver ad9467_driver = { 453 459 .driver = { 454 460 .name = "ad9467", 455 461 .of_match_table = ad9467_of_match, 456 462 }, 457 463 .probe = ad9467_probe, 464 + .id_table = ad9467_ids, 458 465 }; 459 466 module_spi_driver(ad9467_driver); 460 467
+4 -4
drivers/iio/adc/ad_sigma_delta.c
··· 281 281 unsigned int data_reg; 282 282 int ret = 0; 283 283 284 - if (iio_buffer_enabled(indio_dev)) 285 - return -EBUSY; 284 + ret = iio_device_claim_direct_mode(indio_dev); 285 + if (ret) 286 + return ret; 286 287 287 - mutex_lock(&indio_dev->mlock); 288 288 ad_sigma_delta_set_channel(sigma_delta, chan->address); 289 289 290 290 spi_bus_lock(sigma_delta->spi->master); ··· 323 323 ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE); 324 324 sigma_delta->bus_locked = false; 325 325 spi_bus_unlock(sigma_delta->spi->master); 326 - mutex_unlock(&indio_dev->mlock); 326 + iio_device_release_direct_mode(indio_dev); 327 327 328 328 if (ret) 329 329 return ret;
+9 -22
drivers/iio/adc/at91-sama5d2_adc.c
··· 2193 2193 return scnprintf(buf, PAGE_SIZE, "%d\n", st->dma_st.watermark); 2194 2194 } 2195 2195 2196 - static ssize_t hwfifo_watermark_min_show(struct device *dev, 2197 - struct device_attribute *attr, 2198 - char *buf) 2199 - { 2200 - return sysfs_emit(buf, "%s\n", "2"); 2201 - } 2202 - 2203 - static ssize_t hwfifo_watermark_max_show(struct device *dev, 2204 - struct device_attribute *attr, 2205 - char *buf) 2206 - { 2207 - return sysfs_emit(buf, "%s\n", AT91_HWFIFO_MAX_SIZE_STR); 2208 - } 2209 - 2210 2196 static IIO_DEVICE_ATTR(hwfifo_enabled, 0444, 2211 2197 at91_adc_get_fifo_state, NULL, 0); 2212 2198 static IIO_DEVICE_ATTR(hwfifo_watermark, 0444, 2213 2199 at91_adc_get_watermark, NULL, 0); 2214 - static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0); 2215 - static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0); 2216 2200 2217 - static const struct attribute *at91_adc_fifo_attributes[] = { 2218 - &iio_dev_attr_hwfifo_watermark_min.dev_attr.attr, 2219 - &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr, 2220 - &iio_dev_attr_hwfifo_watermark.dev_attr.attr, 2221 - &iio_dev_attr_hwfifo_enabled.dev_attr.attr, 2201 + IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_min, "2"); 2202 + IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_max, AT91_HWFIFO_MAX_SIZE_STR); 2203 + 2204 + static const struct iio_dev_attr *at91_adc_fifo_attributes[] = { 2205 + &iio_dev_attr_hwfifo_watermark_min, 2206 + &iio_dev_attr_hwfifo_watermark_max, 2207 + &iio_dev_attr_hwfifo_watermark, 2208 + &iio_dev_attr_hwfifo_enabled, 2222 2209 NULL, 2223 2210 }; 2224 2211 ··· 2222 2235 struct iio_dev *indio) 2223 2236 { 2224 2237 struct at91_adc_state *st = iio_priv(indio); 2225 - const struct attribute **fifo_attrs; 2238 + const struct iio_dev_attr **fifo_attrs; 2226 2239 int ret; 2227 2240 2228 2241 if (st->selected_trig->hw_trig)
+7 -2
drivers/iio/adc/axp288_adc.c
··· 9 9 10 10 #include <linux/dmi.h> 11 11 #include <linux/module.h> 12 + #include <linux/mutex.h> 12 13 #include <linux/kernel.h> 13 14 #include <linux/device.h> 14 15 #include <linux/regmap.h> ··· 51 50 struct axp288_adc_info { 52 51 int irq; 53 52 struct regmap *regmap; 53 + /* lock to protect against multiple access to the device */ 54 + struct mutex lock; 54 55 bool ts_enabled; 55 56 }; 56 57 ··· 164 161 int ret; 165 162 struct axp288_adc_info *info = iio_priv(indio_dev); 166 163 167 - mutex_lock(&indio_dev->mlock); 164 + mutex_lock(&info->lock); 168 165 switch (mask) { 169 166 case IIO_CHAN_INFO_RAW: 170 167 if (axp288_adc_set_ts(info, AXP288_ADC_TS_CURRENT_ON_ONDEMAND, ··· 181 178 default: 182 179 ret = -EINVAL; 183 180 } 184 - mutex_unlock(&indio_dev->mlock); 181 + mutex_unlock(&info->lock); 185 182 186 183 return ret; 187 184 } ··· 291 288 ret = devm_iio_map_array_register(&pdev->dev, indio_dev, axp288_adc_default_maps); 292 289 if (ret < 0) 293 290 return ret; 291 + 292 + mutex_init(&info->lock); 294 293 295 294 return devm_iio_device_register(&pdev->dev, indio_dev); 296 295 }
+34 -55
drivers/iio/adc/cc10001_adc.c
··· 305 305 return 0; 306 306 } 307 307 308 + static void cc10001_reg_disable(void *priv) 309 + { 310 + regulator_disable(priv); 311 + } 312 + 313 + static void cc10001_pd_cb(void *priv) 314 + { 315 + cc10001_adc_power_down(priv); 316 + } 317 + 308 318 static int cc10001_adc_probe(struct platform_device *pdev) 309 319 { 310 - struct device_node *node = pdev->dev.of_node; 320 + struct device *dev = &pdev->dev; 321 + struct device_node *node = dev->of_node; 311 322 struct cc10001_adc_device *adc_dev; 312 323 unsigned long adc_clk_rate; 313 324 struct iio_dev *indio_dev; 314 325 unsigned long channel_map; 315 326 int ret; 316 327 317 - indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc_dev)); 328 + indio_dev = devm_iio_device_alloc(dev, sizeof(*adc_dev)); 318 329 if (indio_dev == NULL) 319 330 return -ENOMEM; 320 331 ··· 337 326 channel_map &= ~ret; 338 327 } 339 328 340 - adc_dev->reg = devm_regulator_get(&pdev->dev, "vref"); 329 + adc_dev->reg = devm_regulator_get(dev, "vref"); 341 330 if (IS_ERR(adc_dev->reg)) 342 331 return PTR_ERR(adc_dev->reg); 343 332 ··· 345 334 if (ret) 346 335 return ret; 347 336 348 - indio_dev->name = dev_name(&pdev->dev); 337 + ret = devm_add_action_or_reset(dev, cc10001_reg_disable, adc_dev->reg); 338 + if (ret) 339 + return ret; 340 + 341 + indio_dev->name = dev_name(dev); 349 342 indio_dev->info = &cc10001_adc_info; 350 343 indio_dev->modes = INDIO_DIRECT_MODE; 351 344 352 345 adc_dev->reg_base = devm_platform_ioremap_resource(pdev, 0); 353 - if (IS_ERR(adc_dev->reg_base)) { 354 - ret = PTR_ERR(adc_dev->reg_base); 355 - goto err_disable_reg; 356 - } 346 + if (IS_ERR(adc_dev->reg_base)) 347 + return PTR_ERR(adc_dev->reg_base); 357 348 358 - adc_dev->adc_clk = devm_clk_get(&pdev->dev, "adc"); 349 + adc_dev->adc_clk = devm_clk_get_enabled(dev, "adc"); 359 350 if (IS_ERR(adc_dev->adc_clk)) { 360 - dev_err(&pdev->dev, "failed to get the clock\n"); 361 - ret = PTR_ERR(adc_dev->adc_clk); 362 - goto err_disable_reg; 363 - } 364 - 365 - ret = clk_prepare_enable(adc_dev->adc_clk); 366 - if (ret) { 367 - dev_err(&pdev->dev, "failed to enable the clock\n"); 368 - goto err_disable_reg; 351 + dev_err(dev, "failed to get/enable the clock\n"); 352 + return PTR_ERR(adc_dev->adc_clk); 369 353 } 370 354 371 355 adc_clk_rate = clk_get_rate(adc_dev->adc_clk); 372 356 if (!adc_clk_rate) { 373 - ret = -EINVAL; 374 - dev_err(&pdev->dev, "null clock rate!\n"); 375 - goto err_disable_clk; 357 + dev_err(dev, "null clock rate!\n"); 358 + return -EINVAL; 376 359 } 377 360 378 361 adc_dev->eoc_delay_ns = NSEC_PER_SEC / adc_clk_rate; ··· 380 375 if (adc_dev->shared) 381 376 cc10001_adc_power_up(adc_dev); 382 377 378 + ret = devm_add_action_or_reset(dev, cc10001_pd_cb, adc_dev); 379 + if (ret) 380 + return ret; 383 381 /* Setup the ADC channels available on the device */ 384 382 ret = cc10001_adc_channel_init(indio_dev, channel_map); 385 383 if (ret < 0) 386 - goto err_disable_clk; 384 + return ret; 387 385 388 386 mutex_init(&adc_dev->lock); 389 387 390 - ret = iio_triggered_buffer_setup(indio_dev, NULL, 391 - &cc10001_adc_trigger_h, NULL); 388 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, 389 + &cc10001_adc_trigger_h, NULL); 392 390 if (ret < 0) 393 - goto err_disable_clk; 391 + return ret; 394 392 395 - ret = iio_device_register(indio_dev); 396 - if (ret < 0) 397 - goto err_cleanup_buffer; 398 - 399 - platform_set_drvdata(pdev, indio_dev); 400 - 401 - return 0; 402 - 403 - err_cleanup_buffer: 404 - iio_triggered_buffer_cleanup(indio_dev); 405 - err_disable_clk: 406 - clk_disable_unprepare(adc_dev->adc_clk); 407 - err_disable_reg: 408 - regulator_disable(adc_dev->reg); 409 - return ret; 410 - } 411 - 412 - static int cc10001_adc_remove(struct platform_device *pdev) 413 - { 414 - struct iio_dev *indio_dev = platform_get_drvdata(pdev); 415 - struct cc10001_adc_device *adc_dev = iio_priv(indio_dev); 416 - 417 - cc10001_adc_power_down(adc_dev); 418 - iio_device_unregister(indio_dev); 419 - iio_triggered_buffer_cleanup(indio_dev); 420 - clk_disable_unprepare(adc_dev->adc_clk); 421 - regulator_disable(adc_dev->reg); 422 - 423 - return 0; 393 + return devm_iio_device_register(dev, indio_dev); 424 394 } 425 395 426 396 static const struct of_device_id cc10001_adc_dt_ids[] = { ··· 410 430 .of_match_table = cc10001_adc_dt_ids, 411 431 }, 412 432 .probe = cc10001_adc_probe, 413 - .remove = cc10001_adc_remove, 414 433 }; 415 434 module_platform_driver(cc10001_adc_driver); 416 435
+9 -5
drivers/iio/adc/imx7d_adc.c
··· 13 13 #include <linux/kernel.h> 14 14 #include <linux/mod_devicetable.h> 15 15 #include <linux/module.h> 16 + #include <linux/mutex.h> 16 17 #include <linux/platform_device.h> 17 18 #include <linux/regulator/consumer.h> 18 19 ··· 109 108 struct device *dev; 110 109 void __iomem *regs; 111 110 struct clk *clk; 112 - 111 + /* lock to protect against multiple access to the device */ 112 + struct mutex lock; 113 113 u32 vref_uv; 114 114 u32 value; 115 115 u32 channel; ··· 295 293 296 294 switch (mask) { 297 295 case IIO_CHAN_INFO_RAW: 298 - mutex_lock(&indio_dev->mlock); 296 + mutex_lock(&info->lock); 299 297 reinit_completion(&info->completion); 300 298 301 299 channel = chan->channel & 0x03; ··· 305 303 ret = wait_for_completion_interruptible_timeout 306 304 (&info->completion, IMX7D_ADC_TIMEOUT); 307 305 if (ret == 0) { 308 - mutex_unlock(&indio_dev->mlock); 306 + mutex_unlock(&info->lock); 309 307 return -ETIMEDOUT; 310 308 } 311 309 if (ret < 0) { 312 - mutex_unlock(&indio_dev->mlock); 310 + mutex_unlock(&info->lock); 313 311 return ret; 314 312 } 315 313 316 314 *val = info->value; 317 - mutex_unlock(&indio_dev->mlock); 315 + mutex_unlock(&info->lock); 318 316 return IIO_VAL_INT; 319 317 320 318 case IIO_CHAN_INFO_SCALE: ··· 532 530 ret = devm_add_action_or_reset(dev, __imx7d_adc_disable, dev); 533 531 if (ret) 534 532 return ret; 533 + 534 + mutex_init(&info->lock); 535 535 536 536 ret = devm_iio_device_register(dev, indio_dev); 537 537 if (ret) {
+8 -3
drivers/iio/adc/lpc32xx_adc.c
··· 15 15 #include <linux/io.h> 16 16 #include <linux/module.h> 17 17 #include <linux/mod_devicetable.h> 18 + #include <linux/mutex.h> 18 19 #include <linux/platform_device.h> 19 20 #include <linux/regulator/consumer.h> 20 21 ··· 50 49 struct clk *clk; 51 50 struct completion completion; 52 51 struct regulator *vref; 52 + /* lock to protect against multiple access to the device */ 53 + struct mutex lock; 53 54 54 55 u32 value; 55 56 }; ··· 67 64 68 65 switch (mask) { 69 66 case IIO_CHAN_INFO_RAW: 70 - mutex_lock(&indio_dev->mlock); 67 + mutex_lock(&st->lock); 71 68 ret = clk_prepare_enable(st->clk); 72 69 if (ret) { 73 - mutex_unlock(&indio_dev->mlock); 70 + mutex_unlock(&st->lock); 74 71 return ret; 75 72 } 76 73 /* Measurement setup */ ··· 83 80 wait_for_completion(&st->completion); /* set by ISR */ 84 81 clk_disable_unprepare(st->clk); 85 82 *val = st->value; 86 - mutex_unlock(&indio_dev->mlock); 83 + mutex_unlock(&st->lock); 87 84 88 85 return IIO_VAL_INT; 89 86 ··· 203 200 iodev->info = &lpc32xx_adc_iio_info; 204 201 iodev->modes = INDIO_DIRECT_MODE; 205 202 iodev->num_channels = ARRAY_SIZE(lpc32xx_adc_iio_channels); 203 + 204 + mutex_init(&st->lock); 206 205 207 206 retval = devm_iio_device_register(&pdev->dev, iodev); 208 207 if (retval)
+5 -2
drivers/iio/adc/ltc2497-core.c
··· 10 10 #include <linux/iio/iio.h> 11 11 #include <linux/iio/driver.h> 12 12 #include <linux/module.h> 13 + #include <linux/mutex.h> 13 14 #include <linux/regulator/consumer.h> 14 15 15 16 #include "ltc2497.h" ··· 82 81 83 82 switch (mask) { 84 83 case IIO_CHAN_INFO_RAW: 85 - mutex_lock(&indio_dev->mlock); 84 + mutex_lock(&ddata->lock); 86 85 ret = ltc2497core_read(ddata, chan->address, val); 87 - mutex_unlock(&indio_dev->mlock); 86 + mutex_unlock(&ddata->lock); 88 87 if (ret < 0) 89 88 return ret; 90 89 ··· 214 213 215 214 ddata->addr_prev = LTC2497_CONFIG_DEFAULT; 216 215 ddata->time_prev = ktime_get(); 216 + 217 + mutex_init(&ddata->lock); 217 218 218 219 ret = iio_device_register(indio_dev); 219 220 if (ret < 0)
+2
drivers/iio/adc/ltc2497.h
··· 12 12 struct ltc2497core_driverdata { 13 13 struct regulator *ref; 14 14 ktime_t time_prev; 15 + /* lock to protect against multiple access to the device */ 16 + struct mutex lock; 15 17 const struct ltc2497_chip_info *chip_info; 16 18 u8 addr_prev; 17 19 int (*result_and_measure)(struct ltc2497core_driverdata *ddata,
+1050
drivers/iio/adc/max11410.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * MAX11410 SPI ADC driver 4 + * 5 + * Copyright 2022 Analog Devices Inc. 6 + */ 7 + #include <asm-generic/unaligned.h> 8 + #include <linux/bitfield.h> 9 + #include <linux/delay.h> 10 + #include <linux/device.h> 11 + #include <linux/err.h> 12 + #include <linux/interrupt.h> 13 + #include <linux/kernel.h> 14 + #include <linux/module.h> 15 + #include <linux/regmap.h> 16 + #include <linux/regulator/consumer.h> 17 + #include <linux/spi/spi.h> 18 + 19 + #include <linux/iio/buffer.h> 20 + #include <linux/iio/sysfs.h> 21 + #include <linux/iio/trigger.h> 22 + #include <linux/iio/trigger_consumer.h> 23 + #include <linux/iio/triggered_buffer.h> 24 + 25 + #define MAX11410_REG_CONV_START 0x01 26 + #define MAX11410_CONV_TYPE_SINGLE 0x00 27 + #define MAX11410_CONV_TYPE_CONTINUOUS 0x01 28 + #define MAX11410_REG_CAL_START 0x03 29 + #define MAX11410_CAL_START_SELF 0x00 30 + #define MAX11410_CAL_START_PGA 0x01 31 + #define MAX11410_REG_GPIO_CTRL(ch) ((ch) ? 0x05 : 0x04) 32 + #define MAX11410_GPIO_INTRB 0xC1 33 + #define MAX11410_REG_FILTER 0x08 34 + #define MAX11410_FILTER_RATE_MASK GENMASK(3, 0) 35 + #define MAX11410_FILTER_RATE_MAX 0x0F 36 + #define MAX11410_FILTER_LINEF_MASK GENMASK(5, 4) 37 + #define MAX11410_FILTER_50HZ BIT(5) 38 + #define MAX11410_FILTER_60HZ BIT(4) 39 + #define MAX11410_REG_CTRL 0x09 40 + #define MAX11410_CTRL_REFSEL_MASK GENMASK(2, 0) 41 + #define MAX11410_CTRL_VREFN_BUF_BIT BIT(3) 42 + #define MAX11410_CTRL_VREFP_BUF_BIT BIT(4) 43 + #define MAX11410_CTRL_FORMAT_BIT BIT(5) 44 + #define MAX11410_CTRL_UNIPOLAR_BIT BIT(6) 45 + #define MAX11410_REG_MUX_CTRL0 0x0B 46 + #define MAX11410_REG_PGA 0x0E 47 + #define MAX11410_PGA_GAIN_MASK GENMASK(2, 0) 48 + #define MAX11410_PGA_SIG_PATH_MASK GENMASK(5, 4) 49 + #define MAX11410_PGA_SIG_PATH_BUFFERED 0x00 50 + #define MAX11410_PGA_SIG_PATH_BYPASS 0x01 51 + #define MAX11410_PGA_SIG_PATH_PGA 0x02 52 + #define MAX11410_REG_DATA0 0x30 53 + #define MAX11410_REG_STATUS 0x38 54 + #define MAX11410_STATUS_CONV_READY_BIT BIT(0) 55 + #define MAX11410_STATUS_CAL_READY_BIT BIT(2) 56 + 57 + #define MAX11410_REFSEL_AVDD_AGND 0x03 58 + #define MAX11410_REFSEL_MAX 0x06 59 + #define MAX11410_SIG_PATH_MAX 0x02 60 + #define MAX11410_CHANNEL_INDEX_MAX 0x0A 61 + #define MAX11410_AINP_AVDD 0x0A 62 + #define MAX11410_AINN_GND 0x0A 63 + 64 + #define MAX11410_CONVERSION_TIMEOUT_MS 2000 65 + #define MAX11410_CALIB_TIMEOUT_MS 2000 66 + 67 + #define MAX11410_SCALE_AVAIL_SIZE 8 68 + 69 + enum max11410_filter { 70 + MAX11410_FILTER_FIR5060, 71 + MAX11410_FILTER_FIR50, 72 + MAX11410_FILTER_FIR60, 73 + MAX11410_FILTER_SINC4, 74 + }; 75 + 76 + static const u8 max11410_sampling_len[] = { 77 + [MAX11410_FILTER_FIR5060] = 5, 78 + [MAX11410_FILTER_FIR50] = 6, 79 + [MAX11410_FILTER_FIR60] = 6, 80 + [MAX11410_FILTER_SINC4] = 10, 81 + }; 82 + 83 + static const int max11410_sampling_rates[4][10][2] = { 84 + [MAX11410_FILTER_FIR5060] = { 85 + { 1, 100000 }, 86 + { 2, 100000 }, 87 + { 4, 200000 }, 88 + { 8, 400000 }, 89 + { 16, 800000 } 90 + }, 91 + [MAX11410_FILTER_FIR50] = { 92 + { 1, 300000 }, 93 + { 2, 700000 }, 94 + { 5, 300000 }, 95 + { 10, 700000 }, 96 + { 21, 300000 }, 97 + { 40 } 98 + }, 99 + [MAX11410_FILTER_FIR60] = { 100 + { 1, 300000 }, 101 + { 2, 700000 }, 102 + { 5, 300000 }, 103 + { 10, 700000 }, 104 + { 21, 300000 }, 105 + { 40 } 106 + }, 107 + [MAX11410_FILTER_SINC4] = { 108 + { 4 }, 109 + { 10 }, 110 + { 20 }, 111 + { 40 }, 112 + { 60 }, 113 + { 120 }, 114 + { 240 }, 115 + { 480 }, 116 + { 960 }, 117 + { 1920 } 118 + } 119 + }; 120 + 121 + struct max11410_channel_config { 122 + u32 settling_time_us; 123 + u32 *scale_avail; 124 + u8 refsel; 125 + u8 sig_path; 126 + u8 gain; 127 + bool bipolar; 128 + bool buffered_vrefp; 129 + bool buffered_vrefn; 130 + }; 131 + 132 + struct max11410_state { 133 + struct spi_device *spi_dev; 134 + struct iio_trigger *trig; 135 + struct completion completion; 136 + struct mutex lock; /* Prevent changing channel config during sampling */ 137 + struct regmap *regmap; 138 + struct regulator *avdd; 139 + struct regulator *vrefp[3]; 140 + struct regulator *vrefn[3]; 141 + struct max11410_channel_config *channels; 142 + int irq; 143 + struct { 144 + u32 data __aligned(IIO_DMA_MINALIGN); 145 + s64 ts __aligned(8); 146 + } scan; 147 + }; 148 + 149 + static const struct iio_chan_spec chanspec_template = { 150 + .type = IIO_VOLTAGE, 151 + .indexed = 1, 152 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 153 + BIT(IIO_CHAN_INFO_SCALE) | 154 + BIT(IIO_CHAN_INFO_OFFSET), 155 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 156 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 157 + .scan_type = { 158 + .sign = 's', 159 + .realbits = 24, 160 + .storagebits = 32, 161 + .endianness = IIO_LE, 162 + }, 163 + }; 164 + 165 + static unsigned int max11410_reg_size(unsigned int reg) 166 + { 167 + /* Registers from 0x00 to 0x10 are 1 byte, the rest are 3 bytes long. */ 168 + return reg <= 0x10 ? 1 : 3; 169 + } 170 + 171 + static int max11410_write_reg(struct max11410_state *st, unsigned int reg, 172 + unsigned int val) 173 + { 174 + /* This driver only needs to write 8-bit registers */ 175 + if (max11410_reg_size(reg) != 1) 176 + return -EINVAL; 177 + 178 + return regmap_write(st->regmap, reg, val); 179 + } 180 + 181 + static int max11410_read_reg(struct max11410_state *st, unsigned int reg, 182 + int *val) 183 + { 184 + int ret; 185 + 186 + if (max11410_reg_size(reg) == 3) { 187 + ret = regmap_bulk_read(st->regmap, reg, &st->scan.data, 3); 188 + if (ret) 189 + return ret; 190 + 191 + *val = get_unaligned_be24(&st->scan.data); 192 + return 0; 193 + } 194 + 195 + return regmap_read(st->regmap, reg, val); 196 + } 197 + 198 + static struct regulator *max11410_get_vrefp(struct max11410_state *st, 199 + u8 refsel) 200 + { 201 + refsel = refsel % 4; 202 + if (refsel == 3) 203 + return st->avdd; 204 + 205 + return st->vrefp[refsel]; 206 + } 207 + 208 + static struct regulator *max11410_get_vrefn(struct max11410_state *st, 209 + u8 refsel) 210 + { 211 + if (refsel > 2) 212 + return NULL; 213 + 214 + return st->vrefn[refsel]; 215 + } 216 + 217 + static const struct regmap_config regmap_config = { 218 + .reg_bits = 8, 219 + .val_bits = 8, 220 + .max_register = 0x39, 221 + }; 222 + 223 + static ssize_t max11410_notch_en_show(struct device *dev, 224 + struct device_attribute *devattr, 225 + char *buf) 226 + { 227 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 228 + struct max11410_state *state = iio_priv(indio_dev); 229 + struct iio_dev_attr *iio_attr = to_iio_dev_attr(devattr); 230 + unsigned int val; 231 + int ret; 232 + 233 + ret = max11410_read_reg(state, MAX11410_REG_FILTER, &val); 234 + if (ret) 235 + return ret; 236 + 237 + switch (iio_attr->address) { 238 + case 0: 239 + val = !FIELD_GET(MAX11410_FILTER_50HZ, val); 240 + break; 241 + case 1: 242 + val = !FIELD_GET(MAX11410_FILTER_60HZ, val); 243 + break; 244 + case 2: 245 + val = FIELD_GET(MAX11410_FILTER_LINEF_MASK, val) == 3; 246 + break; 247 + default: 248 + return -EINVAL; 249 + } 250 + 251 + return sysfs_emit(buf, "%d\n", val); 252 + } 253 + 254 + static ssize_t max11410_notch_en_store(struct device *dev, 255 + struct device_attribute *devattr, 256 + const char *buf, size_t count) 257 + { 258 + struct iio_dev_attr *iio_attr = to_iio_dev_attr(devattr); 259 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 260 + struct max11410_state *state = iio_priv(indio_dev); 261 + unsigned int filter_bits; 262 + bool enable; 263 + int ret; 264 + 265 + ret = kstrtobool(buf, &enable); 266 + if (ret) 267 + return ret; 268 + 269 + switch (iio_attr->address) { 270 + case 0: 271 + filter_bits = MAX11410_FILTER_50HZ; 272 + break; 273 + case 1: 274 + filter_bits = MAX11410_FILTER_60HZ; 275 + break; 276 + case 2: 277 + default: 278 + filter_bits = MAX11410_FILTER_50HZ | MAX11410_FILTER_60HZ; 279 + enable = !enable; 280 + break; 281 + } 282 + 283 + if (enable) 284 + ret = regmap_clear_bits(state->regmap, MAX11410_REG_FILTER, 285 + filter_bits); 286 + else 287 + ret = regmap_set_bits(state->regmap, MAX11410_REG_FILTER, 288 + filter_bits); 289 + 290 + if (ret) 291 + return ret; 292 + 293 + return count; 294 + } 295 + 296 + static ssize_t in_voltage_filter2_notch_center_show(struct device *dev, 297 + struct device_attribute *devattr, 298 + char *buf) 299 + { 300 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 301 + struct max11410_state *state = iio_priv(indio_dev); 302 + int ret, reg, rate, filter; 303 + 304 + ret = regmap_read(state->regmap, MAX11410_REG_FILTER, &reg); 305 + if (ret) 306 + return ret; 307 + 308 + rate = FIELD_GET(MAX11410_FILTER_RATE_MASK, reg); 309 + rate = clamp_val(rate, 0, 310 + max11410_sampling_len[MAX11410_FILTER_SINC4] - 1); 311 + filter = max11410_sampling_rates[MAX11410_FILTER_SINC4][rate][0]; 312 + 313 + return sysfs_emit(buf, "%d\n", filter); 314 + } 315 + 316 + static IIO_CONST_ATTR(in_voltage_filter0_notch_center, "50"); 317 + static IIO_CONST_ATTR(in_voltage_filter1_notch_center, "60"); 318 + static IIO_DEVICE_ATTR_RO(in_voltage_filter2_notch_center, 2); 319 + 320 + static IIO_DEVICE_ATTR(in_voltage_filter0_notch_en, 0644, 321 + max11410_notch_en_show, max11410_notch_en_store, 0); 322 + static IIO_DEVICE_ATTR(in_voltage_filter1_notch_en, 0644, 323 + max11410_notch_en_show, max11410_notch_en_store, 1); 324 + static IIO_DEVICE_ATTR(in_voltage_filter2_notch_en, 0644, 325 + max11410_notch_en_show, max11410_notch_en_store, 2); 326 + 327 + static struct attribute *max11410_attributes[] = { 328 + &iio_const_attr_in_voltage_filter0_notch_center.dev_attr.attr, 329 + &iio_const_attr_in_voltage_filter1_notch_center.dev_attr.attr, 330 + &iio_dev_attr_in_voltage_filter2_notch_center.dev_attr.attr, 331 + &iio_dev_attr_in_voltage_filter0_notch_en.dev_attr.attr, 332 + &iio_dev_attr_in_voltage_filter1_notch_en.dev_attr.attr, 333 + &iio_dev_attr_in_voltage_filter2_notch_en.dev_attr.attr, 334 + NULL 335 + }; 336 + 337 + static const struct attribute_group max11410_attribute_group = { 338 + .attrs = max11410_attributes, 339 + }; 340 + 341 + static int max11410_set_input_mux(struct max11410_state *st, u8 ainp, u8 ainn) 342 + { 343 + if (ainp > MAX11410_CHANNEL_INDEX_MAX || 344 + ainn > MAX11410_CHANNEL_INDEX_MAX) 345 + return -EINVAL; 346 + 347 + return max11410_write_reg(st, MAX11410_REG_MUX_CTRL0, 348 + (ainp << 4) | ainn); 349 + } 350 + 351 + static int max11410_configure_channel(struct max11410_state *st, 352 + struct iio_chan_spec const *chan) 353 + { 354 + struct max11410_channel_config cfg = st->channels[chan->address]; 355 + unsigned int regval; 356 + int ret; 357 + 358 + if (chan->differential) 359 + ret = max11410_set_input_mux(st, chan->channel, chan->channel2); 360 + else 361 + ret = max11410_set_input_mux(st, chan->channel, 362 + MAX11410_AINN_GND); 363 + 364 + if (ret) 365 + return ret; 366 + 367 + regval = FIELD_PREP(MAX11410_CTRL_VREFP_BUF_BIT, cfg.buffered_vrefp) | 368 + FIELD_PREP(MAX11410_CTRL_VREFN_BUF_BIT, cfg.buffered_vrefn) | 369 + FIELD_PREP(MAX11410_CTRL_REFSEL_MASK, cfg.refsel) | 370 + FIELD_PREP(MAX11410_CTRL_UNIPOLAR_BIT, cfg.bipolar ? 0 : 1); 371 + ret = regmap_update_bits(st->regmap, MAX11410_REG_CTRL, 372 + MAX11410_CTRL_REFSEL_MASK | 373 + MAX11410_CTRL_VREFN_BUF_BIT | 374 + MAX11410_CTRL_VREFN_BUF_BIT | 375 + MAX11410_CTRL_UNIPOLAR_BIT, regval); 376 + if (ret) 377 + return ret; 378 + 379 + regval = FIELD_PREP(MAX11410_PGA_SIG_PATH_MASK, cfg.sig_path) | 380 + FIELD_PREP(MAX11410_PGA_GAIN_MASK, cfg.gain); 381 + ret = regmap_write(st->regmap, MAX11410_REG_PGA, regval); 382 + if (ret) 383 + return ret; 384 + 385 + if (cfg.settling_time_us) 386 + fsleep(cfg.settling_time_us); 387 + 388 + return 0; 389 + } 390 + 391 + static int max11410_sample(struct max11410_state *st, int *sample_raw, 392 + struct iio_chan_spec const *chan) 393 + { 394 + int val, ret; 395 + 396 + ret = max11410_configure_channel(st, chan); 397 + if (ret) 398 + return ret; 399 + 400 + if (st->irq > 0) 401 + reinit_completion(&st->completion); 402 + 403 + /* Start Conversion */ 404 + ret = max11410_write_reg(st, MAX11410_REG_CONV_START, 405 + MAX11410_CONV_TYPE_SINGLE); 406 + if (ret) 407 + return ret; 408 + 409 + if (st->irq > 0) { 410 + /* Wait for an interrupt. */ 411 + ret = wait_for_completion_timeout(&st->completion, 412 + msecs_to_jiffies(MAX11410_CONVERSION_TIMEOUT_MS)); 413 + if (!ret) 414 + return -ETIMEDOUT; 415 + } else { 416 + /* Wait for status register Conversion Ready flag */ 417 + ret = read_poll_timeout(max11410_read_reg, ret, 418 + ret || (val & MAX11410_STATUS_CONV_READY_BIT), 419 + 5000, MAX11410_CONVERSION_TIMEOUT_MS * 1000, 420 + true, st, MAX11410_REG_STATUS, &val); 421 + if (ret) 422 + return ret; 423 + } 424 + 425 + /* Read ADC Data */ 426 + return max11410_read_reg(st, MAX11410_REG_DATA0, sample_raw); 427 + } 428 + 429 + static int max11410_get_scale(struct max11410_state *state, 430 + struct max11410_channel_config cfg) 431 + { 432 + struct regulator *vrefp, *vrefn; 433 + int scale; 434 + 435 + vrefp = max11410_get_vrefp(state, cfg.refsel); 436 + 437 + scale = regulator_get_voltage(vrefp) / 1000; 438 + vrefn = max11410_get_vrefn(state, cfg.refsel); 439 + if (vrefn) 440 + scale -= regulator_get_voltage(vrefn) / 1000; 441 + 442 + if (cfg.bipolar) 443 + scale *= 2; 444 + 445 + return scale >> cfg.gain; 446 + } 447 + 448 + static int max11410_read_raw(struct iio_dev *indio_dev, 449 + struct iio_chan_spec const *chan, 450 + int *val, int *val2, long info) 451 + { 452 + struct max11410_state *state = iio_priv(indio_dev); 453 + struct max11410_channel_config cfg = state->channels[chan->address]; 454 + int ret, reg_val, filter, rate; 455 + 456 + switch (info) { 457 + case IIO_CHAN_INFO_SCALE: 458 + *val = max11410_get_scale(state, cfg); 459 + *val2 = chan->scan_type.realbits; 460 + return IIO_VAL_FRACTIONAL_LOG2; 461 + case IIO_CHAN_INFO_OFFSET: 462 + if (cfg.bipolar) 463 + *val = -BIT(chan->scan_type.realbits - 1); 464 + else 465 + *val = 0; 466 + 467 + return IIO_VAL_INT; 468 + case IIO_CHAN_INFO_RAW: 469 + ret = iio_device_claim_direct_mode(indio_dev); 470 + if (ret) 471 + return ret; 472 + 473 + mutex_lock(&state->lock); 474 + 475 + ret = max11410_sample(state, &reg_val, chan); 476 + 477 + mutex_unlock(&state->lock); 478 + 479 + iio_device_release_direct_mode(indio_dev); 480 + 481 + if (ret) 482 + return ret; 483 + 484 + *val = reg_val; 485 + 486 + return IIO_VAL_INT; 487 + case IIO_CHAN_INFO_SAMP_FREQ: 488 + ret = regmap_read(state->regmap, MAX11410_REG_FILTER, &reg_val); 489 + if (ret) 490 + return ret; 491 + 492 + filter = FIELD_GET(MAX11410_FILTER_LINEF_MASK, reg_val); 493 + rate = reg_val & MAX11410_FILTER_RATE_MASK; 494 + if (rate >= max11410_sampling_len[filter]) 495 + rate = max11410_sampling_len[filter] - 1; 496 + 497 + *val = max11410_sampling_rates[filter][rate][0]; 498 + *val2 = max11410_sampling_rates[filter][rate][1]; 499 + 500 + return IIO_VAL_INT_PLUS_MICRO; 501 + } 502 + return -EINVAL; 503 + } 504 + 505 + static int max11410_write_raw(struct iio_dev *indio_dev, 506 + struct iio_chan_spec const *chan, 507 + int val, int val2, long mask) 508 + { 509 + struct max11410_state *st = iio_priv(indio_dev); 510 + int i, ret, reg_val, filter, gain; 511 + u32 *scale_avail; 512 + 513 + switch (mask) { 514 + case IIO_CHAN_INFO_SCALE: 515 + scale_avail = st->channels[chan->address].scale_avail; 516 + if (!scale_avail) 517 + return -EOPNOTSUPP; 518 + 519 + /* Accept values in range 0.000001 <= scale < 1.000000 */ 520 + if (val != 0 || val2 == 0) 521 + return -EINVAL; 522 + 523 + ret = iio_device_claim_direct_mode(indio_dev); 524 + if (ret) 525 + return ret; 526 + 527 + /* Convert from INT_PLUS_MICRO to FRACTIONAL_LOG2 */ 528 + val2 = val2 * DIV_ROUND_CLOSEST(BIT(24), 1000000); 529 + val2 = DIV_ROUND_CLOSEST(scale_avail[0], val2); 530 + gain = order_base_2(val2); 531 + 532 + st->channels[chan->address].gain = clamp_val(gain, 0, 7); 533 + 534 + iio_device_release_direct_mode(indio_dev); 535 + 536 + return 0; 537 + case IIO_CHAN_INFO_SAMP_FREQ: 538 + ret = iio_device_claim_direct_mode(indio_dev); 539 + if (ret) 540 + return ret; 541 + 542 + mutex_lock(&st->lock); 543 + 544 + ret = regmap_read(st->regmap, MAX11410_REG_FILTER, &reg_val); 545 + if (ret) 546 + goto out; 547 + 548 + filter = FIELD_GET(MAX11410_FILTER_LINEF_MASK, reg_val); 549 + 550 + for (i = 0; i < max11410_sampling_len[filter]; ++i) { 551 + if (val == max11410_sampling_rates[filter][i][0] && 552 + val2 == max11410_sampling_rates[filter][i][1]) 553 + break; 554 + } 555 + if (i == max11410_sampling_len[filter]) { 556 + ret = -EINVAL; 557 + goto out; 558 + } 559 + 560 + ret = regmap_write_bits(st->regmap, MAX11410_REG_FILTER, 561 + MAX11410_FILTER_RATE_MASK, i); 562 + 563 + out: 564 + mutex_unlock(&st->lock); 565 + iio_device_release_direct_mode(indio_dev); 566 + 567 + return ret; 568 + default: 569 + return -EINVAL; 570 + } 571 + } 572 + 573 + static int max11410_read_avail(struct iio_dev *indio_dev, 574 + struct iio_chan_spec const *chan, 575 + const int **vals, int *type, int *length, 576 + long info) 577 + { 578 + struct max11410_state *st = iio_priv(indio_dev); 579 + struct max11410_channel_config cfg; 580 + int ret, reg_val, filter; 581 + 582 + switch (info) { 583 + case IIO_CHAN_INFO_SAMP_FREQ: 584 + ret = regmap_read(st->regmap, MAX11410_REG_FILTER, &reg_val); 585 + if (ret) 586 + return ret; 587 + 588 + filter = FIELD_GET(MAX11410_FILTER_LINEF_MASK, reg_val); 589 + 590 + *vals = (const int *)max11410_sampling_rates[filter]; 591 + *length = max11410_sampling_len[filter] * 2; 592 + *type = IIO_VAL_INT_PLUS_MICRO; 593 + 594 + return IIO_AVAIL_LIST; 595 + case IIO_CHAN_INFO_SCALE: 596 + cfg = st->channels[chan->address]; 597 + 598 + if (!cfg.scale_avail) 599 + return -EINVAL; 600 + 601 + *vals = cfg.scale_avail; 602 + *length = MAX11410_SCALE_AVAIL_SIZE * 2; 603 + *type = IIO_VAL_FRACTIONAL_LOG2; 604 + 605 + return IIO_AVAIL_LIST; 606 + } 607 + return -EINVAL; 608 + } 609 + 610 + static const struct iio_info max11410_info = { 611 + .read_raw = max11410_read_raw, 612 + .write_raw = max11410_write_raw, 613 + .read_avail = max11410_read_avail, 614 + .attrs = &max11410_attribute_group, 615 + }; 616 + 617 + static irqreturn_t max11410_trigger_handler(int irq, void *p) 618 + { 619 + struct iio_poll_func *pf = p; 620 + struct iio_dev *indio_dev = pf->indio_dev; 621 + struct max11410_state *st = iio_priv(indio_dev); 622 + int ret; 623 + 624 + ret = max11410_read_reg(st, MAX11410_REG_DATA0, &st->scan.data); 625 + if (ret) { 626 + dev_err(&indio_dev->dev, "cannot read data\n"); 627 + goto out; 628 + } 629 + 630 + iio_push_to_buffers_with_timestamp(indio_dev, &st->scan, 631 + iio_get_time_ns(indio_dev)); 632 + 633 + out: 634 + iio_trigger_notify_done(indio_dev->trig); 635 + 636 + return IRQ_HANDLED; 637 + } 638 + 639 + static int max11410_buffer_postenable(struct iio_dev *indio_dev) 640 + { 641 + struct max11410_state *st = iio_priv(indio_dev); 642 + int scan_ch, ret; 643 + 644 + scan_ch = ffs(*indio_dev->active_scan_mask) - 1; 645 + 646 + ret = max11410_configure_channel(st, &indio_dev->channels[scan_ch]); 647 + if (ret) 648 + return ret; 649 + 650 + /* Start continuous conversion. */ 651 + return max11410_write_reg(st, MAX11410_REG_CONV_START, 652 + MAX11410_CONV_TYPE_CONTINUOUS); 653 + } 654 + 655 + static int max11410_buffer_predisable(struct iio_dev *indio_dev) 656 + { 657 + struct max11410_state *st = iio_priv(indio_dev); 658 + 659 + /* Stop continuous conversion. */ 660 + return max11410_write_reg(st, MAX11410_REG_CONV_START, 661 + MAX11410_CONV_TYPE_SINGLE); 662 + } 663 + 664 + static const struct iio_buffer_setup_ops max11410_buffer_ops = { 665 + .postenable = &max11410_buffer_postenable, 666 + .predisable = &max11410_buffer_predisable, 667 + .validate_scan_mask = &iio_validate_scan_mask_onehot, 668 + }; 669 + 670 + static const struct iio_trigger_ops max11410_trigger_ops = { 671 + .validate_device = iio_trigger_validate_own_device, 672 + }; 673 + 674 + static irqreturn_t max11410_interrupt(int irq, void *dev_id) 675 + { 676 + struct iio_dev *indio_dev = dev_id; 677 + struct max11410_state *st = iio_priv(indio_dev); 678 + 679 + if (iio_buffer_enabled(indio_dev)) 680 + iio_trigger_poll_chained(st->trig); 681 + else 682 + complete(&st->completion); 683 + 684 + return IRQ_HANDLED; 685 + }; 686 + 687 + static int max11410_parse_channels(struct max11410_state *st, 688 + struct iio_dev *indio_dev) 689 + { 690 + struct iio_chan_spec chanspec = chanspec_template; 691 + struct device *dev = &st->spi_dev->dev; 692 + struct max11410_channel_config *cfg; 693 + struct iio_chan_spec *channels; 694 + struct fwnode_handle *child; 695 + u32 reference, sig_path; 696 + const char *node_name; 697 + u32 inputs[2], scale; 698 + unsigned int num_ch; 699 + int chan_idx = 0; 700 + int ret, i; 701 + 702 + num_ch = device_get_child_node_count(dev); 703 + if (num_ch == 0) 704 + return dev_err_probe(&indio_dev->dev, -ENODEV, 705 + "FW has no channels defined\n"); 706 + 707 + /* Reserve space for soft timestamp channel */ 708 + num_ch++; 709 + channels = devm_kcalloc(dev, num_ch, sizeof(*channels), GFP_KERNEL); 710 + if (!channels) 711 + return -ENOMEM; 712 + 713 + st->channels = devm_kcalloc(dev, num_ch, sizeof(*st->channels), 714 + GFP_KERNEL); 715 + if (!st->channels) 716 + return -ENOMEM; 717 + 718 + device_for_each_child_node(dev, child) { 719 + node_name = fwnode_get_name(child); 720 + if (fwnode_property_present(child, "diff-channels")) { 721 + ret = fwnode_property_read_u32_array(child, 722 + "diff-channels", 723 + inputs, 724 + ARRAY_SIZE(inputs)); 725 + 726 + chanspec.differential = 1; 727 + } else { 728 + ret = fwnode_property_read_u32(child, "reg", &inputs[0]); 729 + 730 + inputs[1] = 0; 731 + chanspec.differential = 0; 732 + } 733 + if (ret) { 734 + fwnode_handle_put(child); 735 + return ret; 736 + } 737 + 738 + if (inputs[0] > MAX11410_CHANNEL_INDEX_MAX || 739 + inputs[1] > MAX11410_CHANNEL_INDEX_MAX) { 740 + fwnode_handle_put(child); 741 + return dev_err_probe(&indio_dev->dev, -EINVAL, 742 + "Invalid channel index for %s, should be less than %d\n", 743 + node_name, 744 + MAX11410_CHANNEL_INDEX_MAX + 1); 745 + } 746 + 747 + cfg = &st->channels[chan_idx]; 748 + 749 + reference = MAX11410_REFSEL_AVDD_AGND; 750 + fwnode_property_read_u32(child, "adi,reference", &reference); 751 + if (reference > MAX11410_REFSEL_MAX) { 752 + fwnode_handle_put(child); 753 + return dev_err_probe(&indio_dev->dev, -EINVAL, 754 + "Invalid adi,reference value for %s, should be less than %d.\n", 755 + node_name, MAX11410_REFSEL_MAX + 1); 756 + } 757 + 758 + if (!max11410_get_vrefp(st, reference) || 759 + (!max11410_get_vrefn(st, reference) && reference <= 2)) { 760 + fwnode_handle_put(child); 761 + return dev_err_probe(&indio_dev->dev, -EINVAL, 762 + "Invalid VREF configuration for %s, either specify corresponding VREF regulators or change adi,reference property.\n", 763 + node_name); 764 + } 765 + 766 + sig_path = MAX11410_PGA_SIG_PATH_BUFFERED; 767 + fwnode_property_read_u32(child, "adi,input-mode", &sig_path); 768 + if (sig_path > MAX11410_SIG_PATH_MAX) { 769 + fwnode_handle_put(child); 770 + return dev_err_probe(&indio_dev->dev, -EINVAL, 771 + "Invalid adi,input-mode value for %s, should be less than %d.\n", 772 + node_name, MAX11410_SIG_PATH_MAX + 1); 773 + } 774 + 775 + fwnode_property_read_u32(child, "settling-time-us", 776 + &cfg->settling_time_us); 777 + cfg->bipolar = fwnode_property_read_bool(child, "bipolar"); 778 + cfg->buffered_vrefp = fwnode_property_read_bool(child, "adi,buffered-vrefp"); 779 + cfg->buffered_vrefn = fwnode_property_read_bool(child, "adi,buffered-vrefn"); 780 + cfg->refsel = reference; 781 + cfg->sig_path = sig_path; 782 + cfg->gain = 0; 783 + 784 + /* Enable scale_available property if input mode is PGA */ 785 + if (sig_path == MAX11410_PGA_SIG_PATH_PGA) { 786 + __set_bit(IIO_CHAN_INFO_SCALE, 787 + &chanspec.info_mask_separate_available); 788 + cfg->scale_avail = devm_kcalloc(dev, MAX11410_SCALE_AVAIL_SIZE * 2, 789 + sizeof(*cfg->scale_avail), 790 + GFP_KERNEL); 791 + if (!cfg->scale_avail) { 792 + fwnode_handle_put(child); 793 + return -ENOMEM; 794 + } 795 + 796 + scale = max11410_get_scale(st, *cfg); 797 + for (i = 0; i < MAX11410_SCALE_AVAIL_SIZE; i++) { 798 + cfg->scale_avail[2 * i] = scale >> i; 799 + cfg->scale_avail[2 * i + 1] = chanspec.scan_type.realbits; 800 + } 801 + } else { 802 + __clear_bit(IIO_CHAN_INFO_SCALE, 803 + &chanspec.info_mask_separate_available); 804 + } 805 + 806 + chanspec.address = chan_idx; 807 + chanspec.scan_index = chan_idx; 808 + chanspec.channel = inputs[0]; 809 + chanspec.channel2 = inputs[1]; 810 + 811 + channels[chan_idx] = chanspec; 812 + chan_idx++; 813 + } 814 + 815 + channels[chan_idx] = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(chan_idx); 816 + 817 + indio_dev->num_channels = chan_idx + 1; 818 + indio_dev->channels = channels; 819 + 820 + return 0; 821 + } 822 + 823 + static void max11410_disable_reg(void *reg) 824 + { 825 + regulator_disable(reg); 826 + } 827 + 828 + static int max11410_init_vref(struct device *dev, 829 + struct regulator **vref, 830 + const char *id) 831 + { 832 + struct regulator *reg; 833 + int ret; 834 + 835 + reg = devm_regulator_get_optional(dev, id); 836 + if (PTR_ERR(reg) == -ENODEV) { 837 + *vref = NULL; 838 + return 0; 839 + } else if (IS_ERR(reg)) { 840 + return PTR_ERR(reg); 841 + } 842 + ret = regulator_enable(reg); 843 + if (ret) 844 + return dev_err_probe(dev, ret, 845 + "Failed to enable regulator %s\n", id); 846 + 847 + *vref = reg; 848 + return devm_add_action_or_reset(dev, max11410_disable_reg, reg); 849 + } 850 + 851 + static int max11410_calibrate(struct max11410_state *st, u32 cal_type) 852 + { 853 + int ret, val; 854 + 855 + ret = max11410_write_reg(st, MAX11410_REG_CAL_START, cal_type); 856 + if (ret) 857 + return ret; 858 + 859 + /* Wait for status register Calibration Ready flag */ 860 + return read_poll_timeout(max11410_read_reg, ret, 861 + ret || (val & MAX11410_STATUS_CAL_READY_BIT), 862 + 50000, MAX11410_CALIB_TIMEOUT_MS * 1000, true, 863 + st, MAX11410_REG_STATUS, &val); 864 + } 865 + 866 + static int max11410_self_calibrate(struct max11410_state *st) 867 + { 868 + int ret, i; 869 + 870 + ret = regmap_write_bits(st->regmap, MAX11410_REG_FILTER, 871 + MAX11410_FILTER_RATE_MASK, 872 + FIELD_PREP(MAX11410_FILTER_RATE_MASK, 873 + MAX11410_FILTER_RATE_MAX)); 874 + if (ret) 875 + return ret; 876 + 877 + ret = max11410_calibrate(st, MAX11410_CAL_START_SELF); 878 + if (ret) 879 + return ret; 880 + 881 + ret = regmap_write_bits(st->regmap, MAX11410_REG_PGA, 882 + MAX11410_PGA_SIG_PATH_MASK, 883 + FIELD_PREP(MAX11410_PGA_SIG_PATH_MASK, 884 + MAX11410_PGA_SIG_PATH_PGA)); 885 + if (ret) 886 + return ret; 887 + 888 + /* PGA calibrations */ 889 + for (i = 1; i < 8; ++i) { 890 + ret = regmap_write_bits(st->regmap, MAX11410_REG_PGA, 891 + MAX11410_PGA_GAIN_MASK, i); 892 + if (ret) 893 + return ret; 894 + 895 + ret = max11410_calibrate(st, MAX11410_CAL_START_PGA); 896 + if (ret) 897 + return ret; 898 + } 899 + 900 + /* Cleanup */ 901 + ret = regmap_write_bits(st->regmap, MAX11410_REG_PGA, 902 + MAX11410_PGA_GAIN_MASK, 0); 903 + if (ret) 904 + return ret; 905 + 906 + ret = regmap_write_bits(st->regmap, MAX11410_REG_FILTER, 907 + MAX11410_FILTER_RATE_MASK, 0); 908 + if (ret) 909 + return ret; 910 + 911 + return regmap_write_bits(st->regmap, MAX11410_REG_PGA, 912 + MAX11410_PGA_SIG_PATH_MASK, 913 + FIELD_PREP(MAX11410_PGA_SIG_PATH_MASK, 914 + MAX11410_PGA_SIG_PATH_BUFFERED)); 915 + } 916 + 917 + static int max11410_probe(struct spi_device *spi) 918 + { 919 + const char *vrefp_regs[] = { "vref0p", "vref1p", "vref2p" }; 920 + const char *vrefn_regs[] = { "vref0n", "vref1n", "vref2n" }; 921 + struct device *dev = &spi->dev; 922 + struct max11410_state *st; 923 + struct iio_dev *indio_dev; 924 + int ret, irqs[2]; 925 + int i; 926 + 927 + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 928 + if (!indio_dev) 929 + return -ENOMEM; 930 + 931 + st = iio_priv(indio_dev); 932 + st->spi_dev = spi; 933 + init_completion(&st->completion); 934 + mutex_init(&st->lock); 935 + 936 + indio_dev->name = "max11410"; 937 + indio_dev->modes = INDIO_DIRECT_MODE; 938 + indio_dev->info = &max11410_info; 939 + 940 + st->regmap = devm_regmap_init_spi(spi, &regmap_config); 941 + if (IS_ERR(st->regmap)) 942 + return dev_err_probe(dev, PTR_ERR(st->regmap), 943 + "regmap initialization failed\n"); 944 + 945 + ret = max11410_init_vref(dev, &st->avdd, "avdd"); 946 + if (ret) 947 + return ret; 948 + 949 + for (i = 0; i < ARRAY_SIZE(vrefp_regs); i++) { 950 + ret = max11410_init_vref(dev, &st->vrefp[i], vrefp_regs[i]); 951 + if (ret) 952 + return ret; 953 + 954 + ret = max11410_init_vref(dev, &st->vrefn[i], vrefn_regs[i]); 955 + if (ret) 956 + return ret; 957 + } 958 + 959 + /* 960 + * Regulators must be configured before parsing channels for 961 + * validating "adi,reference" property of each channel. 962 + */ 963 + ret = max11410_parse_channels(st, indio_dev); 964 + if (ret) 965 + return ret; 966 + 967 + irqs[0] = fwnode_irq_get_byname(dev_fwnode(dev), "gpio0"); 968 + irqs[1] = fwnode_irq_get_byname(dev_fwnode(dev), "gpio1"); 969 + 970 + if (irqs[0] > 0) { 971 + st->irq = irqs[0]; 972 + ret = regmap_write(st->regmap, MAX11410_REG_GPIO_CTRL(0), 973 + MAX11410_GPIO_INTRB); 974 + } else if (irqs[1] > 0) { 975 + st->irq = irqs[1]; 976 + ret = regmap_write(st->regmap, MAX11410_REG_GPIO_CTRL(1), 977 + MAX11410_GPIO_INTRB); 978 + } else if (spi->irq > 0) { 979 + return dev_err_probe(dev, -ENODEV, 980 + "no interrupt name specified"); 981 + } 982 + 983 + if (ret) 984 + return ret; 985 + 986 + ret = regmap_set_bits(st->regmap, MAX11410_REG_CTRL, 987 + MAX11410_CTRL_FORMAT_BIT); 988 + if (ret) 989 + return ret; 990 + 991 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, 992 + &max11410_trigger_handler, 993 + &max11410_buffer_ops); 994 + if (ret) 995 + return ret; 996 + 997 + if (st->irq > 0) { 998 + st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", 999 + indio_dev->name, 1000 + iio_device_id(indio_dev)); 1001 + if (!st->trig) 1002 + return -ENOMEM; 1003 + 1004 + st->trig->ops = &max11410_trigger_ops; 1005 + ret = devm_iio_trigger_register(dev, st->trig); 1006 + if (ret) 1007 + return ret; 1008 + 1009 + ret = devm_request_threaded_irq(dev, st->irq, NULL, 1010 + &max11410_interrupt, 1011 + IRQF_ONESHOT, "max11410", 1012 + indio_dev); 1013 + if (ret) 1014 + return ret; 1015 + } 1016 + 1017 + ret = max11410_self_calibrate(st); 1018 + if (ret) 1019 + return dev_err_probe(dev, ret, 1020 + "cannot perform device self calibration\n"); 1021 + 1022 + return devm_iio_device_register(dev, indio_dev); 1023 + } 1024 + 1025 + static const struct of_device_id max11410_spi_of_id[] = { 1026 + { .compatible = "adi,max11410" }, 1027 + { } 1028 + }; 1029 + MODULE_DEVICE_TABLE(of, max11410_spi_of_id); 1030 + 1031 + static const struct spi_device_id max11410_id[] = { 1032 + { "max11410" }, 1033 + { } 1034 + }; 1035 + MODULE_DEVICE_TABLE(spi, max11410_id); 1036 + 1037 + static struct spi_driver max11410_driver = { 1038 + .driver = { 1039 + .name = "max11410", 1040 + .of_match_table = max11410_spi_of_id, 1041 + }, 1042 + .probe = max11410_probe, 1043 + .id_table = max11410_id, 1044 + }; 1045 + module_spi_driver(max11410_driver); 1046 + 1047 + MODULE_AUTHOR("David Jung <David.Jung@analog.com>"); 1048 + MODULE_AUTHOR("Ibrahim Tilki <Ibrahim.Tilki@analog.com>"); 1049 + MODULE_DESCRIPTION("Analog Devices MAX11410 ADC"); 1050 + MODULE_LICENSE("GPL");
+3 -25
drivers/iio/adc/max1241.c
··· 22 22 struct max1241 { 23 23 struct spi_device *spi; 24 24 struct mutex lock; 25 - struct regulator *vdd; 26 25 struct regulator *vref; 27 26 struct gpio_desc *shutdown; 28 27 ··· 109 110 .read_raw = max1241_read_raw, 110 111 }; 111 112 112 - static void max1241_disable_vdd_action(void *data) 113 - { 114 - struct max1241 *adc = data; 115 - struct device *dev = &adc->spi->dev; 116 - int err; 117 - 118 - err = regulator_disable(adc->vdd); 119 - if (err) 120 - dev_err(dev, "could not disable vdd regulator.\n"); 121 - } 122 - 123 113 static void max1241_disable_vref_action(void *data) 124 114 { 125 115 struct max1241 *adc = data; ··· 135 147 adc->spi = spi; 136 148 mutex_init(&adc->lock); 137 149 138 - adc->vdd = devm_regulator_get(dev, "vdd"); 139 - if (IS_ERR(adc->vdd)) 140 - return dev_err_probe(dev, PTR_ERR(adc->vdd), 141 - "failed to get vdd regulator\n"); 142 - 143 - ret = regulator_enable(adc->vdd); 150 + ret = devm_regulator_get_enable(dev, "vdd"); 144 151 if (ret) 145 - return ret; 146 - 147 - ret = devm_add_action_or_reset(dev, max1241_disable_vdd_action, adc); 148 - if (ret) { 149 - dev_err(dev, "could not set up vdd regulator cleanup action\n"); 150 - return ret; 151 - } 152 + return dev_err_probe(dev, ret, 153 + "failed to get/enable vdd regulator\n"); 152 154 153 155 adc->vref = devm_regulator_get(dev, "vref"); 154 156 if (IS_ERR(adc->vref))
+1 -11
drivers/iio/adc/max1363.c
··· 148 148 * @chip_info: chip model specific constants, available modes, etc. 149 149 * @current_mode: the scan mode of this chip 150 150 * @requestedmask: a valid requested set of channels 151 - * @reg: supply regulator 152 151 * @lock: lock to ensure state is consistent 153 152 * @monitor_on: whether monitor mode is enabled 154 153 * @monitor_speed: parameter corresponding to device monitor speed setting ··· 167 168 const struct max1363_chip_info *chip_info; 168 169 const struct max1363_mode *current_mode; 169 170 u32 requestedmask; 170 - struct regulator *reg; 171 171 struct mutex lock; 172 172 173 173 /* Using monitor modes and buffer at the same time is ··· 1595 1597 st = iio_priv(indio_dev); 1596 1598 1597 1599 mutex_init(&st->lock); 1598 - st->reg = devm_regulator_get(&client->dev, "vcc"); 1599 - if (IS_ERR(st->reg)) 1600 - return PTR_ERR(st->reg); 1601 - 1602 - ret = regulator_enable(st->reg); 1603 - if (ret) 1604 - return ret; 1605 - 1606 - ret = devm_add_action_or_reset(&client->dev, max1363_reg_disable, st->reg); 1600 + ret = devm_regulator_get_enable(&client->dev, "vcc"); 1607 1601 if (ret) 1608 1602 return ret; 1609 1603
+80 -24
drivers/iio/adc/mcp3911.c
··· 29 29 #define MCP3911_REG_MOD 0x06 30 30 #define MCP3911_REG_PHASE 0x07 31 31 #define MCP3911_REG_GAIN 0x09 32 + #define MCP3911_GAIN_MASK(ch) (GENMASK(2, 0) << 3 * ch) 33 + #define MCP3911_GAIN_VAL(ch, val) ((val << 3 * ch) & MCP3911_GAIN_MASK(ch)) 32 34 33 35 #define MCP3911_REG_STATUSCOM 0x0a 34 36 #define MCP3911_STATUSCOM_DRHIZ BIT(12) ··· 62 60 #define MCP3911_REG_MASK GENMASK(4, 1) 63 61 64 62 #define MCP3911_NUM_CHANNELS 2 63 + #define MCP3911_NUM_SCALES 6 65 64 66 65 static const int mcp3911_osr_table[] = { 32, 64, 128, 256, 512, 1024, 2048, 4096 }; 66 + static u32 mcp3911_scale_table[MCP3911_NUM_SCALES][2]; 67 67 68 68 struct mcp3911 { 69 69 struct spi_device *spi; ··· 74 70 struct clk *clki; 75 71 u32 dev_addr; 76 72 struct iio_trigger *trig; 73 + u32 gain[MCP3911_NUM_CHANNELS]; 77 74 struct { 78 75 u32 channels[MCP3911_NUM_CHANNELS]; 79 76 s64 ts __aligned(8); ··· 151 146 *vals = mcp3911_osr_table; 152 147 *length = ARRAY_SIZE(mcp3911_osr_table); 153 148 return IIO_AVAIL_LIST; 149 + case IIO_CHAN_INFO_SCALE: 150 + *type = IIO_VAL_INT_PLUS_NANO; 151 + *vals = (int *)mcp3911_scale_table; 152 + *length = ARRAY_SIZE(mcp3911_scale_table) * 2; 153 + return IIO_AVAIL_LIST; 154 154 default: 155 155 return -EINVAL; 156 156 } ··· 200 190 break; 201 191 202 192 case IIO_CHAN_INFO_SCALE: 203 - if (adc->vref) { 204 - ret = regulator_get_voltage(adc->vref); 205 - if (ret < 0) { 206 - dev_err(indio_dev->dev.parent, 207 - "failed to get vref voltage: %d\n", 208 - ret); 209 - goto out; 210 - } 211 - 212 - *val = ret / 1000; 213 - } else { 214 - *val = MCP3911_INT_VREF_MV; 215 - } 216 - 217 - /* 218 - * For 24bit Conversion 219 - * Raw = ((Voltage)/(Vref) * 2^23 * Gain * 1.5 220 - * Voltage = Raw * (Vref)/(2^23 * Gain * 1.5) 221 - */ 222 - 223 - /* val2 = (2^23 * 1.5) */ 224 - *val2 = 12582912; 225 - ret = IIO_VAL_FRACTIONAL; 193 + *val = mcp3911_scale_table[ilog2(adc->gain[channel->channel])][0]; 194 + *val2 = mcp3911_scale_table[ilog2(adc->gain[channel->channel])][1]; 195 + ret = IIO_VAL_INT_PLUS_NANO; 226 196 break; 227 197 } 228 198 ··· 220 230 221 231 mutex_lock(&adc->lock); 222 232 switch (mask) { 233 + case IIO_CHAN_INFO_SCALE: 234 + for (int i = 0; i < MCP3911_NUM_SCALES; i++) { 235 + if (val == mcp3911_scale_table[i][0] && 236 + val2 == mcp3911_scale_table[i][1]) { 237 + 238 + adc->gain[channel->channel] = BIT(i); 239 + ret = mcp3911_update(adc, MCP3911_REG_GAIN, 240 + MCP3911_GAIN_MASK(channel->channel), 241 + MCP3911_GAIN_VAL(channel->channel, i), 1); 242 + } 243 + } 244 + break; 223 245 case IIO_CHAN_INFO_OFFSET: 224 246 if (val2 != 0) { 225 247 ret = -EINVAL; ··· 267 265 return ret; 268 266 } 269 267 268 + static int mcp3911_calc_scale_table(struct mcp3911 *adc) 269 + { 270 + u32 ref = MCP3911_INT_VREF_MV; 271 + u32 div; 272 + int ret; 273 + u64 tmp; 274 + 275 + if (adc->vref) { 276 + ret = regulator_get_voltage(adc->vref); 277 + if (ret < 0) { 278 + dev_err(&adc->spi->dev, 279 + "failed to get vref voltage: %d\n", 280 + ret); 281 + return ret; 282 + } 283 + 284 + ref = ret / 1000; 285 + } 286 + 287 + /* 288 + * For 24-bit Conversion 289 + * Raw = ((Voltage)/(Vref) * 2^23 * Gain * 1.5 290 + * Voltage = Raw * (Vref)/(2^23 * Gain * 1.5) 291 + * 292 + * ref = Reference voltage 293 + * div = (2^23 * 1.5 * gain) = 12582912 * gain 294 + */ 295 + for (int i = 0; i < MCP3911_NUM_SCALES; i++) { 296 + div = 12582912 * BIT(i); 297 + tmp = div_s64((s64)ref * 1000000000LL, div); 298 + 299 + mcp3911_scale_table[i][0] = 0; 300 + mcp3911_scale_table[i][1] = tmp; 301 + } 302 + 303 + return 0; 304 + } 305 + 270 306 #define MCP3911_CHAN(idx) { \ 271 307 .type = IIO_VOLTAGE, \ 272 308 .indexed = 1, \ ··· 314 274 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 315 275 BIT(IIO_CHAN_INFO_OFFSET) | \ 316 276 BIT(IIO_CHAN_INFO_SCALE), \ 317 - .info_mask_shared_by_type_available = \ 277 + .info_mask_shared_by_type_available = \ 318 278 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 279 + .info_mask_separate_available = \ 280 + BIT(IIO_CHAN_INFO_SCALE), \ 319 281 .scan_type = { \ 320 282 .sign = 's', \ 321 283 .realbits = 24, \ ··· 523 481 MCP3911_STATUSCOM_DRHIZ, 2); 524 482 if (ret) 525 483 return ret; 484 + 485 + ret = mcp3911_calc_scale_table(adc); 486 + if (ret) 487 + return ret; 488 + 489 + /* Set gain to 1 for all channels */ 490 + for (int i = 0; i < MCP3911_NUM_CHANNELS; i++) { 491 + adc->gain[i] = 1; 492 + ret = mcp3911_update(adc, MCP3911_REG_GAIN, 493 + MCP3911_GAIN_MASK(i), 494 + MCP3911_GAIN_VAL(i, 0), 1); 495 + if (ret) 496 + return ret; 497 + } 526 498 527 499 indio_dev->name = spi_get_device_id(spi)->name; 528 500 indio_dev->modes = INDIO_DIRECT_MODE;
+8 -3
drivers/iio/adc/meson_saradc.c
··· 12 12 #include <linux/io.h> 13 13 #include <linux/iio/iio.h> 14 14 #include <linux/module.h> 15 + #include <linux/mutex.h> 15 16 #include <linux/nvmem-consumer.h> 16 17 #include <linux/interrupt.h> 17 18 #include <linux/of.h> ··· 277 276 struct clk *adc_div_clk; 278 277 struct clk_divider clk_div; 279 278 struct completion done; 279 + /* lock to protect against multiple access to the device */ 280 + struct mutex lock; 280 281 int calibbias; 281 282 int calibscale; 282 283 struct regmap *tsc_regmap; ··· 489 486 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 490 487 int val, ret; 491 488 492 - mutex_lock(&indio_dev->mlock); 489 + mutex_lock(&priv->lock); 493 490 494 491 if (priv->param->has_bl30_integration) { 495 492 /* prevent BL30 from using the SAR ADC while we are using it */ ··· 507 504 !(val & MESON_SAR_ADC_DELAY_BL30_BUSY), 508 505 1, 10000); 509 506 if (ret) { 510 - mutex_unlock(&indio_dev->mlock); 507 + mutex_unlock(&priv->lock); 511 508 return ret; 512 509 } 513 510 } ··· 524 521 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY, 525 522 MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0); 526 523 527 - mutex_unlock(&indio_dev->mlock); 524 + mutex_unlock(&priv->lock); 528 525 } 529 526 530 527 static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev) ··· 1252 1249 ret = meson_sar_adc_init(indio_dev); 1253 1250 if (ret) 1254 1251 goto err; 1252 + 1253 + mutex_init(&priv->lock); 1255 1254 1256 1255 ret = meson_sar_adc_hw_enable(indio_dev); 1257 1256 if (ret)
+305
drivers/iio/adc/mt6370-adc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2022 Richtek Technology Corp. 4 + * 5 + * Author: ChiaEn Wu <chiaen_wu@richtek.com> 6 + */ 7 + 8 + #include <linux/bits.h> 9 + #include <linux/bitfield.h> 10 + #include <linux/iio/iio.h> 11 + #include <linux/kernel.h> 12 + #include <linux/mod_devicetable.h> 13 + #include <linux/module.h> 14 + #include <linux/mutex.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/regmap.h> 17 + #include <linux/sysfs.h> 18 + #include <linux/units.h> 19 + 20 + #include <dt-bindings/iio/adc/mediatek,mt6370_adc.h> 21 + 22 + #define MT6370_REG_CHG_CTRL3 0x113 23 + #define MT6370_REG_CHG_CTRL7 0x117 24 + #define MT6370_REG_CHG_ADC 0x121 25 + #define MT6370_REG_ADC_DATA_H 0x14C 26 + 27 + #define MT6370_ADC_START_MASK BIT(0) 28 + #define MT6370_ADC_IN_SEL_MASK GENMASK(7, 4) 29 + #define MT6370_AICR_ICHG_MASK GENMASK(7, 2) 30 + 31 + #define MT6370_AICR_100_mA 0x0 32 + #define MT6370_AICR_150_mA 0x1 33 + #define MT6370_AICR_200_mA 0x2 34 + #define MT6370_AICR_250_mA 0x3 35 + #define MT6370_AICR_300_mA 0x4 36 + #define MT6370_AICR_350_mA 0x5 37 + 38 + #define MT6370_ICHG_100_mA 0x0 39 + #define MT6370_ICHG_200_mA 0x1 40 + #define MT6370_ICHG_300_mA 0x2 41 + #define MT6370_ICHG_400_mA 0x3 42 + #define MT6370_ICHG_500_mA 0x4 43 + #define MT6370_ICHG_600_mA 0x5 44 + #define MT6370_ICHG_700_mA 0x6 45 + #define MT6370_ICHG_800_mA 0x7 46 + 47 + #define ADC_CONV_TIME_MS 35 48 + #define ADC_CONV_POLLING_TIME_US 1000 49 + 50 + struct mt6370_adc_data { 51 + struct device *dev; 52 + struct regmap *regmap; 53 + /* 54 + * This mutex lock is for preventing the different ADC channels 55 + * from being read at the same time. 56 + */ 57 + struct mutex adc_lock; 58 + }; 59 + 60 + static int mt6370_adc_read_channel(struct mt6370_adc_data *priv, int chan, 61 + unsigned long addr, int *val) 62 + { 63 + unsigned int reg_val; 64 + __be16 be_val; 65 + int ret; 66 + 67 + mutex_lock(&priv->adc_lock); 68 + 69 + reg_val = MT6370_ADC_START_MASK | 70 + FIELD_PREP(MT6370_ADC_IN_SEL_MASK, addr); 71 + ret = regmap_write(priv->regmap, MT6370_REG_CHG_ADC, reg_val); 72 + if (ret) 73 + goto adc_unlock; 74 + 75 + msleep(ADC_CONV_TIME_MS); 76 + 77 + ret = regmap_read_poll_timeout(priv->regmap, 78 + MT6370_REG_CHG_ADC, reg_val, 79 + !(reg_val & MT6370_ADC_START_MASK), 80 + ADC_CONV_POLLING_TIME_US, 81 + ADC_CONV_TIME_MS * MILLI * 3); 82 + if (ret) { 83 + dev_err(priv->dev, "Failed to read ADC register (%d)\n", ret); 84 + goto adc_unlock; 85 + } 86 + 87 + ret = regmap_raw_read(priv->regmap, MT6370_REG_ADC_DATA_H, 88 + &be_val, sizeof(be_val)); 89 + if (ret) 90 + goto adc_unlock; 91 + 92 + *val = be16_to_cpu(be_val); 93 + ret = IIO_VAL_INT; 94 + 95 + adc_unlock: 96 + mutex_unlock(&priv->adc_lock); 97 + 98 + return ret; 99 + } 100 + 101 + static int mt6370_adc_read_scale(struct mt6370_adc_data *priv, 102 + int chan, int *val1, int *val2) 103 + { 104 + unsigned int reg_val; 105 + int ret; 106 + 107 + switch (chan) { 108 + case MT6370_CHAN_VBAT: 109 + case MT6370_CHAN_VSYS: 110 + case MT6370_CHAN_CHG_VDDP: 111 + *val1 = 5; 112 + return IIO_VAL_INT; 113 + case MT6370_CHAN_IBUS: 114 + ret = regmap_read(priv->regmap, MT6370_REG_CHG_CTRL3, &reg_val); 115 + if (ret) 116 + return ret; 117 + 118 + reg_val = FIELD_GET(MT6370_AICR_ICHG_MASK, reg_val); 119 + switch (reg_val) { 120 + case MT6370_AICR_100_mA: 121 + case MT6370_AICR_150_mA: 122 + case MT6370_AICR_200_mA: 123 + case MT6370_AICR_250_mA: 124 + case MT6370_AICR_300_mA: 125 + case MT6370_AICR_350_mA: 126 + *val1 = 3350; 127 + break; 128 + default: 129 + *val1 = 5000; 130 + break; 131 + } 132 + 133 + *val2 = 100; 134 + 135 + return IIO_VAL_FRACTIONAL; 136 + case MT6370_CHAN_IBAT: 137 + ret = regmap_read(priv->regmap, MT6370_REG_CHG_CTRL7, &reg_val); 138 + if (ret) 139 + return ret; 140 + 141 + reg_val = FIELD_GET(MT6370_AICR_ICHG_MASK, reg_val); 142 + switch (reg_val) { 143 + case MT6370_ICHG_100_mA: 144 + case MT6370_ICHG_200_mA: 145 + case MT6370_ICHG_300_mA: 146 + case MT6370_ICHG_400_mA: 147 + *val1 = 2375; 148 + break; 149 + case MT6370_ICHG_500_mA: 150 + case MT6370_ICHG_600_mA: 151 + case MT6370_ICHG_700_mA: 152 + case MT6370_ICHG_800_mA: 153 + *val1 = 2680; 154 + break; 155 + default: 156 + *val1 = 5000; 157 + break; 158 + } 159 + 160 + *val2 = 100; 161 + 162 + return IIO_VAL_FRACTIONAL; 163 + case MT6370_CHAN_VBUSDIV5: 164 + *val1 = 25; 165 + return IIO_VAL_INT; 166 + case MT6370_CHAN_VBUSDIV2: 167 + *val1 = 10; 168 + return IIO_VAL_INT; 169 + case MT6370_CHAN_TS_BAT: 170 + *val1 = 25; 171 + *val2 = 10000; 172 + return IIO_VAL_FRACTIONAL; 173 + case MT6370_CHAN_TEMP_JC: 174 + *val1 = 2000; 175 + return IIO_VAL_INT; 176 + default: 177 + return -EINVAL; 178 + } 179 + } 180 + 181 + static int mt6370_adc_read_offset(struct mt6370_adc_data *priv, 182 + int chan, int *val) 183 + { 184 + *val = -20; 185 + 186 + return IIO_VAL_INT; 187 + } 188 + 189 + static int mt6370_adc_read_raw(struct iio_dev *iio_dev, 190 + const struct iio_chan_spec *chan, 191 + int *val, int *val2, long mask) 192 + { 193 + struct mt6370_adc_data *priv = iio_priv(iio_dev); 194 + 195 + switch (mask) { 196 + case IIO_CHAN_INFO_RAW: 197 + return mt6370_adc_read_channel(priv, chan->channel, 198 + chan->address, val); 199 + case IIO_CHAN_INFO_SCALE: 200 + return mt6370_adc_read_scale(priv, chan->channel, val, val2); 201 + case IIO_CHAN_INFO_OFFSET: 202 + return mt6370_adc_read_offset(priv, chan->channel, val); 203 + default: 204 + return -EINVAL; 205 + } 206 + } 207 + 208 + static const char * const mt6370_channel_labels[MT6370_CHAN_MAX] = { 209 + [MT6370_CHAN_VBUSDIV5] = "vbusdiv5", 210 + [MT6370_CHAN_VBUSDIV2] = "vbusdiv2", 211 + [MT6370_CHAN_VSYS] = "vsys", 212 + [MT6370_CHAN_VBAT] = "vbat", 213 + [MT6370_CHAN_TS_BAT] = "ts_bat", 214 + [MT6370_CHAN_IBUS] = "ibus", 215 + [MT6370_CHAN_IBAT] = "ibat", 216 + [MT6370_CHAN_CHG_VDDP] = "chg_vddp", 217 + [MT6370_CHAN_TEMP_JC] = "temp_jc", 218 + }; 219 + 220 + static int mt6370_adc_read_label(struct iio_dev *iio_dev, 221 + struct iio_chan_spec const *chan, char *label) 222 + { 223 + return sysfs_emit(label, "%s\n", mt6370_channel_labels[chan->channel]); 224 + } 225 + 226 + static const struct iio_info mt6370_adc_iio_info = { 227 + .read_raw = mt6370_adc_read_raw, 228 + .read_label = mt6370_adc_read_label, 229 + }; 230 + 231 + #define MT6370_ADC_CHAN(_idx, _type, _addr, _extra_info) { \ 232 + .type = _type, \ 233 + .channel = MT6370_CHAN_##_idx, \ 234 + .address = _addr, \ 235 + .scan_index = MT6370_CHAN_##_idx, \ 236 + .indexed = 1, \ 237 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 238 + BIT(IIO_CHAN_INFO_SCALE) | \ 239 + _extra_info, \ 240 + } 241 + 242 + static const struct iio_chan_spec mt6370_adc_channels[] = { 243 + MT6370_ADC_CHAN(VBUSDIV5, IIO_VOLTAGE, 1, 0), 244 + MT6370_ADC_CHAN(VBUSDIV2, IIO_VOLTAGE, 2, 0), 245 + MT6370_ADC_CHAN(VSYS, IIO_VOLTAGE, 3, 0), 246 + MT6370_ADC_CHAN(VBAT, IIO_VOLTAGE, 4, 0), 247 + MT6370_ADC_CHAN(TS_BAT, IIO_VOLTAGE, 6, 0), 248 + MT6370_ADC_CHAN(IBUS, IIO_CURRENT, 8, 0), 249 + MT6370_ADC_CHAN(IBAT, IIO_CURRENT, 9, 0), 250 + MT6370_ADC_CHAN(CHG_VDDP, IIO_VOLTAGE, 11, 0), 251 + MT6370_ADC_CHAN(TEMP_JC, IIO_TEMP, 12, BIT(IIO_CHAN_INFO_OFFSET)), 252 + }; 253 + 254 + static int mt6370_adc_probe(struct platform_device *pdev) 255 + { 256 + struct device *dev = &pdev->dev; 257 + struct mt6370_adc_data *priv; 258 + struct iio_dev *indio_dev; 259 + struct regmap *regmap; 260 + int ret; 261 + 262 + regmap = dev_get_regmap(pdev->dev.parent, NULL); 263 + if (!regmap) 264 + return dev_err_probe(dev, -ENODEV, "Failed to get regmap\n"); 265 + 266 + indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); 267 + if (!indio_dev) 268 + return -ENOMEM; 269 + 270 + priv = iio_priv(indio_dev); 271 + priv->dev = dev; 272 + priv->regmap = regmap; 273 + mutex_init(&priv->adc_lock); 274 + 275 + ret = regmap_write(priv->regmap, MT6370_REG_CHG_ADC, 0); 276 + if (ret) 277 + return dev_err_probe(dev, ret, "Failed to reset ADC\n"); 278 + 279 + indio_dev->name = "mt6370-adc"; 280 + indio_dev->info = &mt6370_adc_iio_info; 281 + indio_dev->modes = INDIO_DIRECT_MODE; 282 + indio_dev->channels = mt6370_adc_channels; 283 + indio_dev->num_channels = ARRAY_SIZE(mt6370_adc_channels); 284 + 285 + return devm_iio_device_register(dev, indio_dev); 286 + } 287 + 288 + static const struct of_device_id mt6370_adc_of_id[] = { 289 + { .compatible = "mediatek,mt6370-adc", }, 290 + {} 291 + }; 292 + MODULE_DEVICE_TABLE(of, mt6370_adc_of_id); 293 + 294 + static struct platform_driver mt6370_adc_driver = { 295 + .driver = { 296 + .name = "mt6370-adc", 297 + .of_match_table = mt6370_adc_of_id, 298 + }, 299 + .probe = mt6370_adc_probe, 300 + }; 301 + module_platform_driver(mt6370_adc_driver); 302 + 303 + MODULE_AUTHOR("ChiaEn Wu <chiaen_wu@richtek.com>"); 304 + MODULE_DESCRIPTION("MT6370 ADC Driver"); 305 + MODULE_LICENSE("GPL v2");
+10 -5
drivers/iio/adc/rockchip_saradc.c
··· 5 5 */ 6 6 7 7 #include <linux/module.h> 8 + #include <linux/mutex.h> 8 9 #include <linux/platform_device.h> 9 10 #include <linux/interrupt.h> 10 11 #include <linux/io.h> ··· 50 49 struct clk *clk; 51 50 struct completion completion; 52 51 struct regulator *vref; 52 + /* lock to protect against multiple access to the device */ 53 + struct mutex lock; 53 54 int uv_vref; 54 55 struct reset_control *reset; 55 56 const struct rockchip_saradc_data *data; ··· 97 94 98 95 switch (mask) { 99 96 case IIO_CHAN_INFO_RAW: 100 - mutex_lock(&indio_dev->mlock); 97 + mutex_lock(&info->lock); 101 98 102 99 ret = rockchip_saradc_conversion(info, chan); 103 100 if (ret) { 104 101 rockchip_saradc_power_down(info); 105 - mutex_unlock(&indio_dev->mlock); 102 + mutex_unlock(&info->lock); 106 103 return ret; 107 104 } 108 105 109 106 *val = info->last_val; 110 - mutex_unlock(&indio_dev->mlock); 107 + mutex_unlock(&info->lock); 111 108 return IIO_VAL_INT; 112 109 case IIO_CHAN_INFO_SCALE: 113 110 *val = info->uv_vref / 1000; ··· 273 270 int ret; 274 271 int i, j = 0; 275 272 276 - mutex_lock(&i_dev->mlock); 273 + mutex_lock(&info->lock); 277 274 278 275 for_each_set_bit(i, i_dev->active_scan_mask, i_dev->masklength) { 279 276 const struct iio_chan_spec *chan = &i_dev->channels[i]; ··· 290 287 291 288 iio_push_to_buffers_with_timestamp(i_dev, &data, iio_get_time_ns(i_dev)); 292 289 out: 293 - mutex_unlock(&i_dev->mlock); 290 + mutex_unlock(&info->lock); 294 291 295 292 iio_trigger_notify_done(i_dev->trig); 296 293 ··· 480 477 info); 481 478 if (ret) 482 479 return ret; 480 + 481 + mutex_init(&info->lock); 483 482 484 483 return devm_iio_device_register(&pdev->dev, indio_dev); 485 484 }
+10 -4
drivers/iio/adc/sc27xx_adc.c
··· 4 4 #include <linux/hwspinlock.h> 5 5 #include <linux/iio/iio.h> 6 6 #include <linux/module.h> 7 + #include <linux/mutex.h> 7 8 #include <linux/nvmem-consumer.h> 8 9 #include <linux/of.h> 9 10 #include <linux/of_device.h> ··· 84 83 struct device *dev; 85 84 struct regulator *volref; 86 85 struct regmap *regmap; 86 + /* lock to protect against multiple access to the device */ 87 + struct mutex lock; 87 88 /* 88 89 * One hardware spinlock to synchronize between the multiple 89 90 * subsystems which will access the unique ADC controller. ··· 667 664 668 665 switch (mask) { 669 666 case IIO_CHAN_INFO_RAW: 670 - mutex_lock(&indio_dev->mlock); 667 + mutex_lock(&data->lock); 671 668 ret = sc27xx_adc_read(data, chan->channel, scale, &tmp); 672 - mutex_unlock(&indio_dev->mlock); 669 + mutex_unlock(&data->lock); 673 670 674 671 if (ret) 675 672 return ret; ··· 678 675 return IIO_VAL_INT; 679 676 680 677 case IIO_CHAN_INFO_PROCESSED: 681 - mutex_lock(&indio_dev->mlock); 678 + mutex_lock(&data->lock); 682 679 ret = sc27xx_adc_read_processed(data, chan->channel, scale, 683 680 &tmp); 684 - mutex_unlock(&indio_dev->mlock); 681 + mutex_unlock(&data->lock); 685 682 686 683 if (ret) 687 684 return ret; ··· 937 934 indio_dev->info = &sc27xx_info; 938 935 indio_dev->channels = sc27xx_channels; 939 936 indio_dev->num_channels = ARRAY_SIZE(sc27xx_channels); 937 + 938 + mutex_init(&sc27xx_data->lock); 939 + 940 940 ret = devm_iio_device_register(dev, indio_dev); 941 941 if (ret) 942 942 dev_err(dev, "could not register iio (ADC)");
+26 -4
drivers/iio/adc/stm32-adc-core.c
··· 22 22 #include <linux/regmap.h> 23 23 #include <linux/regulator/consumer.h> 24 24 #include <linux/slab.h> 25 + #include <linux/units.h> 25 26 26 27 #include "stm32-adc-core.h" 27 28 ··· 307 306 static const struct stm32_adc_common_regs stm32f4_adc_common_regs = { 308 307 .csr = STM32F4_ADC_CSR, 309 308 .ccr = STM32F4_ADC_CCR, 310 - .eoc_msk = { STM32F4_EOC1, STM32F4_EOC2, STM32F4_EOC3}, 311 - .ovr_msk = { STM32F4_OVR1, STM32F4_OVR2, STM32F4_OVR3}, 309 + .eoc_msk = { STM32F4_EOC1, STM32F4_EOC2, STM32F4_EOC3 }, 310 + .ovr_msk = { STM32F4_OVR1, STM32F4_OVR2, STM32F4_OVR3 }, 312 311 .ier = STM32F4_ADC_CR1, 313 312 .eocie_msk = STM32F4_EOCIE, 314 313 }; ··· 317 316 static const struct stm32_adc_common_regs stm32h7_adc_common_regs = { 318 317 .csr = STM32H7_ADC_CSR, 319 318 .ccr = STM32H7_ADC_CCR, 320 - .eoc_msk = { STM32H7_EOC_MST, STM32H7_EOC_SLV}, 321 - .ovr_msk = { STM32H7_OVR_MST, STM32H7_OVR_SLV}, 319 + .eoc_msk = { STM32H7_EOC_MST, STM32H7_EOC_SLV }, 320 + .ovr_msk = { STM32H7_OVR_MST, STM32H7_OVR_SLV }, 321 + .ier = STM32H7_ADC_IER, 322 + .eocie_msk = STM32H7_EOCIE, 323 + }; 324 + 325 + /* STM32MP13 common registers definitions */ 326 + static const struct stm32_adc_common_regs stm32mp13_adc_common_regs = { 327 + .csr = STM32H7_ADC_CSR, 328 + .ccr = STM32H7_ADC_CCR, 329 + .eoc_msk = { STM32H7_EOC_MST }, 330 + .ovr_msk = { STM32H7_OVR_MST }, 322 331 .ier = STM32H7_ADC_IER, 323 332 .eocie_msk = STM32H7_EOCIE, 324 333 }; ··· 879 868 .num_irqs = 2, 880 869 }; 881 870 871 + static const struct stm32_adc_priv_cfg stm32mp13_adc_priv_cfg = { 872 + .regs = &stm32mp13_adc_common_regs, 873 + .clk_sel = stm32h7_adc_clk_sel, 874 + .max_clk_rate_hz = 75 * HZ_PER_MHZ, 875 + .ipid = STM32MP13_IPIDR_NUMBER, 876 + .num_irqs = 1, 877 + }; 878 + 882 879 static const struct of_device_id stm32_adc_of_match[] = { 883 880 { 884 881 .compatible = "st,stm32f4-adc-core", ··· 897 878 }, { 898 879 .compatible = "st,stm32mp1-adc-core", 899 880 .data = (void *)&stm32mp1_adc_priv_cfg 881 + }, { 882 + .compatible = "st,stm32mp13-adc-core", 883 + .data = (void *)&stm32mp13_adc_priv_cfg 900 884 }, { 901 885 }, 902 886 };
+30
drivers/iio/adc/stm32-adc-core.h
··· 112 112 #define STM32MP1_ADC_IPDR 0x3F8 113 113 #define STM32MP1_ADC_SIDR 0x3FC 114 114 115 + /* STM32MP13 - Registers for each ADC instance */ 116 + #define STM32MP13_ADC_DIFSEL 0xB0 117 + #define STM32MP13_ADC_CALFACT 0xB4 118 + #define STM32MP13_ADC2_OR 0xC8 119 + 115 120 /* STM32H7 - common registers for all ADC instances */ 116 121 #define STM32H7_ADC_CSR (STM32_ADCX_COMN_OFFSET + 0x00) 117 122 #define STM32H7_ADC_CCR (STM32_ADCX_COMN_OFFSET + 0x08) ··· 165 160 STM32H7_DMNGT_DFSDM, /* DFSDM mode */ 166 161 STM32H7_DMNGT_DMA_CIRC, /* DMA circular mode */ 167 162 }; 163 + 164 + /* STM32H7_ADC_DIFSEL - bit fields */ 165 + #define STM32H7_DIFSEL_MASK GENMASK(19, 0) 168 166 169 167 /* STM32H7_ADC_CALFACT - bit fields */ 170 168 #define STM32H7_CALFACT_D_SHIFT 16 ··· 218 210 /* STM32MP1_ADC_SIDR - bit fields */ 219 211 #define STM32MP1_SIDR_MASK GENMASK(31, 0) 220 212 213 + /* STM32MP13_ADC_CFGR specific bit fields */ 214 + #define STM32MP13_DMAEN BIT(0) 215 + #define STM32MP13_DMACFG BIT(1) 216 + #define STM32MP13_DFSDMCFG BIT(2) 217 + #define STM32MP13_RES_SHIFT 3 218 + #define STM32MP13_RES_MASK GENMASK(4, 3) 219 + 220 + /* STM32MP13_ADC_DIFSEL - bit fields */ 221 + #define STM32MP13_DIFSEL_MASK GENMASK(18, 0) 222 + 223 + /* STM32MP13_ADC_CALFACT - bit fields */ 224 + #define STM32MP13_CALFACT_D_SHIFT 16 225 + #define STM32MP13_CALFACT_D_MASK GENMASK(22, 16) 226 + #define STM32MP13_CALFACT_S_SHIFT 0 227 + #define STM32MP13_CALFACT_S_MASK GENMASK(6, 0) 228 + 229 + /* STM32MP13_ADC2_OR - bit fields */ 230 + #define STM32MP13_OP2 BIT(2) 231 + #define STM32MP13_OP1 BIT(1) 232 + #define STM32MP13_OP0 BIT(0) 233 + 221 234 #define STM32MP15_IPIDR_NUMBER 0x00110005 235 + #define STM32MP13_IPIDR_NUMBER 0x00110006 222 236 223 237 /** 224 238 * struct stm32_adc_common - stm32 ADC driver common data (for all instances)
+202 -34
drivers/iio/adc/stm32-adc.c
··· 82 82 enum stm32_adc_int_ch { 83 83 STM32_ADC_INT_CH_NONE = -1, 84 84 STM32_ADC_INT_CH_VDDCORE, 85 + STM32_ADC_INT_CH_VDDCPU, 86 + STM32_ADC_INT_CH_VDDQ_DDR, 85 87 STM32_ADC_INT_CH_VREFINT, 86 88 STM32_ADC_INT_CH_VBAT, 87 89 STM32_ADC_INT_CH_NB, ··· 101 99 102 100 static const struct stm32_adc_ic stm32_adc_ic[STM32_ADC_INT_CH_NB] = { 103 101 { "vddcore", STM32_ADC_INT_CH_VDDCORE }, 102 + { "vddcpu", STM32_ADC_INT_CH_VDDCPU }, 103 + { "vddq_ddr", STM32_ADC_INT_CH_VDDQ_DDR }, 104 104 { "vrefint", STM32_ADC_INT_CH_VREFINT }, 105 105 { "vbat", STM32_ADC_INT_CH_VBAT }, 106 106 }; ··· 164 160 * @exten: trigger control register & bitfield 165 161 * @extsel: trigger selection register & bitfield 166 162 * @res: resolution selection register & bitfield 163 + * @difsel: differential mode selection register & bitfield 164 + * @calfact_s: single-ended calibration factors register & bitfield 165 + * @calfact_d: differential calibration factors register & bitfield 167 166 * @smpr: smpr1 & smpr2 registers offset array 168 167 * @smp_bits: smpr1 & smpr2 index and bitfields 169 - * @or_vdd: option register & vddcore bitfield 168 + * @or_vddcore: option register & vddcore bitfield 169 + * @or_vddcpu: option register & vddcpu bitfield 170 + * @or_vddq_ddr: option register & vddq_ddr bitfield 170 171 * @ccr_vbat: common register & vbat bitfield 171 172 * @ccr_vref: common register & vrefint bitfield 172 173 */ ··· 185 176 const struct stm32_adc_regs exten; 186 177 const struct stm32_adc_regs extsel; 187 178 const struct stm32_adc_regs res; 179 + const struct stm32_adc_regs difsel; 180 + const struct stm32_adc_regs calfact_s; 181 + const struct stm32_adc_regs calfact_d; 188 182 const u32 smpr[2]; 189 183 const struct stm32_adc_regs *smp_bits; 190 - const struct stm32_adc_regs or_vdd; 184 + const struct stm32_adc_regs or_vddcore; 185 + const struct stm32_adc_regs or_vddcpu; 186 + const struct stm32_adc_regs or_vddq_ddr; 191 187 const struct stm32_adc_regs ccr_vbat; 192 188 const struct stm32_adc_regs ccr_vref; 193 189 }; ··· 206 192 * @trigs: external trigger sources 207 193 * @clk_required: clock is required 208 194 * @has_vregready: vregready status flag presence 195 + * @has_boostmode: boost mode support flag 196 + * @has_linearcal: linear calibration support flag 197 + * @has_presel: channel preselection support flag 209 198 * @prepare: optional prepare routine (power-up, enable) 210 199 * @start_conv: routine to start conversions 211 200 * @stop_conv: routine to stop conversions 212 201 * @unprepare: optional unprepare routine (disable, power-down) 213 202 * @irq_clear: routine to clear irqs 214 203 * @smp_cycles: programmable sampling time (ADC clock cycles) 215 - * @ts_vrefint_ns: vrefint minimum sampling time in ns 204 + * @ts_int_ch: pointer to array of internal channels minimum sampling time in ns 216 205 */ 217 206 struct stm32_adc_cfg { 218 207 const struct stm32_adc_regspec *regs; ··· 223 206 struct stm32_adc_trig_info *trigs; 224 207 bool clk_required; 225 208 bool has_vregready; 209 + bool has_boostmode; 210 + bool has_linearcal; 211 + bool has_presel; 226 212 int (*prepare)(struct iio_dev *); 227 213 void (*start_conv)(struct iio_dev *, bool dma); 228 214 void (*stop_conv)(struct iio_dev *); 229 215 void (*unprepare)(struct iio_dev *); 230 216 void (*irq_clear)(struct iio_dev *indio_dev, u32 msk); 231 217 const unsigned int *smp_cycles; 232 - const unsigned int ts_vrefint_ns; 218 + const unsigned int *ts_int_ch; 233 219 }; 234 220 235 221 /** ··· 330 310 .max_channels = STM32_ADC_CH_MAX, 331 311 .resolutions = stm32h7_adc_resolutions, 332 312 .num_res = ARRAY_SIZE(stm32h7_adc_resolutions), 313 + }; 314 + 315 + /* stm32mp13 can have up to 19 channels */ 316 + static const struct stm32_adc_info stm32mp13_adc_info = { 317 + .max_channels = 19, 318 + .resolutions = stm32f4_adc_resolutions, 319 + .num_res = ARRAY_SIZE(stm32f4_adc_resolutions), 333 320 }; 334 321 335 322 /* ··· 524 497 .extsel = { STM32H7_ADC_CFGR, STM32H7_EXTSEL_MASK, 525 498 STM32H7_EXTSEL_SHIFT }, 526 499 .res = { STM32H7_ADC_CFGR, STM32H7_RES_MASK, STM32H7_RES_SHIFT }, 500 + .difsel = { STM32H7_ADC_DIFSEL, STM32H7_DIFSEL_MASK}, 501 + .calfact_s = { STM32H7_ADC_CALFACT, STM32H7_CALFACT_S_MASK, 502 + STM32H7_CALFACT_S_SHIFT }, 503 + .calfact_d = { STM32H7_ADC_CALFACT, STM32H7_CALFACT_D_MASK, 504 + STM32H7_CALFACT_D_SHIFT }, 527 505 .smpr = { STM32H7_ADC_SMPR1, STM32H7_ADC_SMPR2 }, 528 506 .smp_bits = stm32h7_smp_bits, 507 + }; 508 + 509 + /* STM32MP13 programmable sampling time (ADC clock cycles, rounded down) */ 510 + static const unsigned int stm32mp13_adc_smp_cycles[STM32_ADC_MAX_SMP + 1] = { 511 + 2, 6, 12, 24, 47, 92, 247, 640, 512 + }; 513 + 514 + static const struct stm32_adc_regspec stm32mp13_adc_regspec = { 515 + .dr = STM32H7_ADC_DR, 516 + .ier_eoc = { STM32H7_ADC_IER, STM32H7_EOCIE }, 517 + .ier_ovr = { STM32H7_ADC_IER, STM32H7_OVRIE }, 518 + .isr_eoc = { STM32H7_ADC_ISR, STM32H7_EOC }, 519 + .isr_ovr = { STM32H7_ADC_ISR, STM32H7_OVR }, 520 + .sqr = stm32h7_sq, 521 + .exten = { STM32H7_ADC_CFGR, STM32H7_EXTEN_MASK, STM32H7_EXTEN_SHIFT }, 522 + .extsel = { STM32H7_ADC_CFGR, STM32H7_EXTSEL_MASK, 523 + STM32H7_EXTSEL_SHIFT }, 524 + .res = { STM32H7_ADC_CFGR, STM32MP13_RES_MASK, STM32MP13_RES_SHIFT }, 525 + .difsel = { STM32MP13_ADC_DIFSEL, STM32MP13_DIFSEL_MASK}, 526 + .calfact_s = { STM32MP13_ADC_CALFACT, STM32MP13_CALFACT_S_MASK, 527 + STM32MP13_CALFACT_S_SHIFT }, 528 + .calfact_d = { STM32MP13_ADC_CALFACT, STM32MP13_CALFACT_D_MASK, 529 + STM32MP13_CALFACT_D_SHIFT }, 530 + .smpr = { STM32H7_ADC_SMPR1, STM32H7_ADC_SMPR2 }, 531 + .smp_bits = stm32h7_smp_bits, 532 + .or_vddcore = { STM32MP13_ADC2_OR, STM32MP13_OP0 }, 533 + .or_vddcpu = { STM32MP13_ADC2_OR, STM32MP13_OP1 }, 534 + .or_vddq_ddr = { STM32MP13_ADC2_OR, STM32MP13_OP2 }, 535 + .ccr_vbat = { STM32H7_ADC_CCR, STM32H7_VBATEN }, 536 + .ccr_vref = { STM32H7_ADC_CCR, STM32H7_VREFEN }, 529 537 }; 530 538 531 539 static const struct stm32_adc_regspec stm32mp1_adc_regspec = { ··· 574 512 .extsel = { STM32H7_ADC_CFGR, STM32H7_EXTSEL_MASK, 575 513 STM32H7_EXTSEL_SHIFT }, 576 514 .res = { STM32H7_ADC_CFGR, STM32H7_RES_MASK, STM32H7_RES_SHIFT }, 515 + .difsel = { STM32H7_ADC_DIFSEL, STM32H7_DIFSEL_MASK}, 516 + .calfact_s = { STM32H7_ADC_CALFACT, STM32H7_CALFACT_S_MASK, 517 + STM32H7_CALFACT_S_SHIFT }, 518 + .calfact_d = { STM32H7_ADC_CALFACT, STM32H7_CALFACT_D_MASK, 519 + STM32H7_CALFACT_D_SHIFT }, 577 520 .smpr = { STM32H7_ADC_SMPR1, STM32H7_ADC_SMPR2 }, 578 521 .smp_bits = stm32h7_smp_bits, 579 - .or_vdd = { STM32MP1_ADC2_OR, STM32MP1_VDDCOREEN }, 522 + .or_vddcore = { STM32MP1_ADC2_OR, STM32MP1_VDDCOREEN }, 580 523 .ccr_vbat = { STM32H7_ADC_CCR, STM32H7_VBATEN }, 581 524 .ccr_vref = { STM32H7_ADC_CCR, STM32H7_VREFEN }, 582 525 }; ··· 742 675 switch (i) { 743 676 case STM32_ADC_INT_CH_VDDCORE: 744 677 dev_dbg(&indio_dev->dev, "Enable VDDCore\n"); 745 - stm32_adc_set_bits(adc, adc->cfg->regs->or_vdd.reg, 746 - adc->cfg->regs->or_vdd.mask); 678 + stm32_adc_set_bits(adc, adc->cfg->regs->or_vddcore.reg, 679 + adc->cfg->regs->or_vddcore.mask); 680 + break; 681 + case STM32_ADC_INT_CH_VDDCPU: 682 + dev_dbg(&indio_dev->dev, "Enable VDDCPU\n"); 683 + stm32_adc_set_bits(adc, adc->cfg->regs->or_vddcpu.reg, 684 + adc->cfg->regs->or_vddcpu.mask); 685 + break; 686 + case STM32_ADC_INT_CH_VDDQ_DDR: 687 + dev_dbg(&indio_dev->dev, "Enable VDDQ_DDR\n"); 688 + stm32_adc_set_bits(adc, adc->cfg->regs->or_vddq_ddr.reg, 689 + adc->cfg->regs->or_vddq_ddr.mask); 747 690 break; 748 691 case STM32_ADC_INT_CH_VREFINT: 749 692 dev_dbg(&indio_dev->dev, "Enable VREFInt\n"); ··· 779 702 780 703 switch (i) { 781 704 case STM32_ADC_INT_CH_VDDCORE: 782 - stm32_adc_clr_bits(adc, adc->cfg->regs->or_vdd.reg, 783 - adc->cfg->regs->or_vdd.mask); 705 + stm32_adc_clr_bits(adc, adc->cfg->regs->or_vddcore.reg, 706 + adc->cfg->regs->or_vddcore.mask); 707 + break; 708 + case STM32_ADC_INT_CH_VDDCPU: 709 + stm32_adc_clr_bits(adc, adc->cfg->regs->or_vddcpu.reg, 710 + adc->cfg->regs->or_vddcpu.mask); 711 + break; 712 + case STM32_ADC_INT_CH_VDDQ_DDR: 713 + stm32_adc_clr_bits(adc, adc->cfg->regs->or_vddq_ddr.reg, 714 + adc->cfg->regs->or_vddq_ddr.mask); 784 715 break; 785 716 case STM32_ADC_INT_CH_VREFINT: 786 717 stm32_adc_clr_bits_common(adc, adc->cfg->regs->ccr_vref.reg, ··· 886 801 if (ret) 887 802 dev_warn(&indio_dev->dev, "stop failed\n"); 888 803 804 + /* STM32H7_DMNGT_MASK covers STM32MP13_DMAEN & STM32MP13_DMACFG */ 889 805 stm32_adc_clr_bits(adc, STM32H7_ADC_CFGR, STM32H7_DMNGT_MASK); 890 806 } 891 807 ··· 895 809 struct stm32_adc *adc = iio_priv(indio_dev); 896 810 /* On STM32H7 IRQs are cleared by writing 1 into ISR register */ 897 811 stm32_adc_set_bits(adc, adc->cfg->regs->isr_eoc.reg, msk); 812 + } 813 + 814 + static void stm32mp13_adc_start_conv(struct iio_dev *indio_dev, bool dma) 815 + { 816 + struct stm32_adc *adc = iio_priv(indio_dev); 817 + 818 + if (dma) 819 + stm32_adc_set_bits(adc, STM32H7_ADC_CFGR, 820 + STM32MP13_DMAEN | STM32MP13_DMACFG); 821 + 822 + stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADSTART); 898 823 } 899 824 900 825 static int stm32h7_adc_exit_pwr_down(struct iio_dev *indio_dev) ··· 918 821 stm32_adc_clr_bits(adc, STM32H7_ADC_CR, STM32H7_DEEPPWD); 919 822 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADVREGEN); 920 823 921 - if (adc->common->rate > STM32H7_BOOST_CLKRATE) 824 + if (adc->cfg->has_boostmode && 825 + adc->common->rate > STM32H7_BOOST_CLKRATE) 922 826 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_BOOST); 923 827 924 828 /* Wait for startup time */ ··· 941 843 942 844 static void stm32h7_adc_enter_pwr_down(struct stm32_adc *adc) 943 845 { 944 - stm32_adc_clr_bits(adc, STM32H7_ADC_CR, STM32H7_BOOST); 846 + if (adc->cfg->has_boostmode) 847 + stm32_adc_clr_bits(adc, STM32H7_ADC_CR, STM32H7_BOOST); 945 848 946 849 /* Setting DEEPPWD disables ADC vreg and clears ADVREGEN */ 947 850 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_DEEPPWD); ··· 1000 901 int i, ret; 1001 902 u32 lincalrdyw_mask, val; 1002 903 904 + if (!adc->cfg->has_linearcal) 905 + goto skip_linearcal; 906 + 1003 907 /* Read linearity calibration */ 1004 908 lincalrdyw_mask = STM32H7_LINCALRDYW6; 1005 909 for (i = STM32H7_LINCALFACT_NUM - 1; i >= 0; i--) { ··· 1025 923 lincalrdyw_mask >>= 1; 1026 924 } 1027 925 926 + skip_linearcal: 1028 927 /* Read offset calibration */ 1029 - val = stm32_adc_readl(adc, STM32H7_ADC_CALFACT); 1030 - adc->cal.calfact_s = (val & STM32H7_CALFACT_S_MASK); 1031 - adc->cal.calfact_s >>= STM32H7_CALFACT_S_SHIFT; 1032 - adc->cal.calfact_d = (val & STM32H7_CALFACT_D_MASK); 1033 - adc->cal.calfact_d >>= STM32H7_CALFACT_D_SHIFT; 928 + val = stm32_adc_readl(adc, adc->cfg->regs->calfact_s.reg); 929 + adc->cal.calfact_s = (val & adc->cfg->regs->calfact_s.mask); 930 + adc->cal.calfact_s >>= adc->cfg->regs->calfact_s.shift; 931 + adc->cal.calfact_d = (val & adc->cfg->regs->calfact_d.mask); 932 + adc->cal.calfact_d >>= adc->cfg->regs->calfact_d.shift; 1034 933 adc->cal.calibrated = true; 1035 934 1036 935 return 0; ··· 1048 945 int i, ret; 1049 946 u32 lincalrdyw_mask, val; 1050 947 1051 - val = (adc->cal.calfact_s << STM32H7_CALFACT_S_SHIFT) | 1052 - (adc->cal.calfact_d << STM32H7_CALFACT_D_SHIFT); 1053 - stm32_adc_writel(adc, STM32H7_ADC_CALFACT, val); 948 + val = (adc->cal.calfact_s << adc->cfg->regs->calfact_s.shift) | 949 + (adc->cal.calfact_d << adc->cfg->regs->calfact_d.shift); 950 + stm32_adc_writel(adc, adc->cfg->regs->calfact_s.reg, val); 951 + 952 + if (!adc->cfg->has_linearcal) 953 + return 0; 1054 954 1055 955 lincalrdyw_mask = STM32H7_LINCALRDYW6; 1056 956 for (i = STM32H7_LINCALFACT_NUM - 1; i >= 0; i--) { ··· 1122 1016 { 1123 1017 struct stm32_adc *adc = iio_priv(indio_dev); 1124 1018 int ret; 1019 + u32 msk = STM32H7_ADCALDIF; 1125 1020 u32 val; 1126 1021 1127 1022 if (adc->cal.calibrated) 1128 1023 return true; 1129 1024 1025 + if (adc->cfg->has_linearcal) 1026 + msk |= STM32H7_ADCALLIN; 1130 1027 /* ADC must be disabled for calibration */ 1131 1028 stm32h7_adc_disable(indio_dev); 1132 1029 ··· 1138 1029 * - Offset calibration for single ended inputs 1139 1030 * - No linearity calibration (do it later, before reading it) 1140 1031 */ 1141 - stm32_adc_clr_bits(adc, STM32H7_ADC_CR, STM32H7_ADCALDIF); 1142 - stm32_adc_clr_bits(adc, STM32H7_ADC_CR, STM32H7_ADCALLIN); 1032 + stm32_adc_clr_bits(adc, STM32H7_ADC_CR, msk); 1143 1033 1144 1034 /* Start calibration, then wait for completion */ 1145 1035 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADCAL); ··· 1156 1048 * - Linearity calibration (needs to be done only once for single/diff) 1157 1049 * will run simultaneously with offset calibration. 1158 1050 */ 1159 - stm32_adc_set_bits(adc, STM32H7_ADC_CR, 1160 - STM32H7_ADCALDIF | STM32H7_ADCALLIN); 1051 + stm32_adc_set_bits(adc, STM32H7_ADC_CR, msk); 1161 1052 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADCAL); 1162 1053 ret = stm32_adc_readl_poll_timeout(STM32H7_ADC_CR, val, 1163 1054 !(val & STM32H7_ADCAL), 100, ··· 1167 1060 } 1168 1061 1169 1062 out: 1170 - stm32_adc_clr_bits(adc, STM32H7_ADC_CR, 1171 - STM32H7_ADCALDIF | STM32H7_ADCALLIN); 1063 + stm32_adc_clr_bits(adc, STM32H7_ADC_CR, msk); 1172 1064 1173 1065 return ret; 1174 1066 } ··· 1199 1093 1200 1094 stm32_adc_int_ch_enable(indio_dev); 1201 1095 1202 - stm32_adc_writel(adc, STM32H7_ADC_DIFSEL, adc->difsel); 1096 + stm32_adc_writel(adc, adc->cfg->regs->difsel.reg, adc->difsel); 1203 1097 1204 1098 ret = stm32h7_adc_enable(indio_dev); 1205 1099 if (ret) ··· 1213 1107 if (ret) 1214 1108 goto disable; 1215 1109 1216 - stm32_adc_writel(adc, STM32H7_ADC_PCSEL, adc->pcsel); 1110 + if (adc->cfg->has_presel) 1111 + stm32_adc_writel(adc, STM32H7_ADC_PCSEL, adc->pcsel); 1217 1112 1218 1113 return 0; 1219 1114 ··· 1232 1125 { 1233 1126 struct stm32_adc *adc = iio_priv(indio_dev); 1234 1127 1235 - stm32_adc_writel(adc, STM32H7_ADC_PCSEL, 0); 1128 + if (adc->cfg->has_presel) 1129 + stm32_adc_writel(adc, STM32H7_ADC_PCSEL, 0); 1236 1130 stm32h7_adc_disable(indio_dev); 1237 1131 stm32_adc_int_ch_disable(adc); 1238 1132 stm32h7_adc_enter_pwr_down(adc); ··· 1910 1802 { 1911 1803 const struct stm32_adc_regs *smpr = &adc->cfg->regs->smp_bits[channel]; 1912 1804 u32 period_ns, shift = smpr->shift, mask = smpr->mask; 1913 - unsigned int smp, r = smpr->reg; 1805 + unsigned int i, smp, r = smpr->reg; 1914 1806 1915 1807 /* 1916 - * For vrefint channel, ensure that the sampling time cannot 1808 + * For internal channels, ensure that the sampling time cannot 1917 1809 * be lower than the one specified in the datasheet 1918 1810 */ 1919 - if (channel == adc->int_ch[STM32_ADC_INT_CH_VREFINT]) 1920 - smp_ns = max(smp_ns, adc->cfg->ts_vrefint_ns); 1811 + for (i = 0; i < STM32_ADC_INT_CH_NB; i++) 1812 + if (channel == adc->int_ch[i] && adc->int_ch[i] != STM32_ADC_INT_CH_NONE) 1813 + smp_ns = max(smp_ns, adc->cfg->ts_int_ch[i]); 1921 1814 1922 1815 /* Determine sampling time (ADC clock cycles) */ 1923 1816 period_ns = NSEC_PER_SEC / adc->common->rate; ··· 1966 1857 adc->pcsel |= BIT(chan->channel); 1967 1858 if (differential) { 1968 1859 /* pre-build diff channels mask */ 1969 - adc->difsel |= BIT(chan->channel); 1860 + adc->difsel |= BIT(chan->channel) & adc->cfg->regs->difsel.mask; 1970 1861 /* Also add negative input to pre-selected channels */ 1971 1862 adc->pcsel |= BIT(chan->channel2); 1972 1863 } ··· 2107 1998 2108 1999 for (i = 0; i < STM32_ADC_INT_CH_NB; i++) { 2109 2000 if (!strncmp(stm32_adc_ic[i].name, ch_name, STM32_ADC_CH_SZ)) { 2001 + /* Check internal channel availability */ 2002 + switch (i) { 2003 + case STM32_ADC_INT_CH_VDDCORE: 2004 + if (!adc->cfg->regs->or_vddcore.reg) 2005 + dev_warn(&indio_dev->dev, 2006 + "%s channel not available\n", ch_name); 2007 + break; 2008 + case STM32_ADC_INT_CH_VDDCPU: 2009 + if (!adc->cfg->regs->or_vddcpu.reg) 2010 + dev_warn(&indio_dev->dev, 2011 + "%s channel not available\n", ch_name); 2012 + break; 2013 + case STM32_ADC_INT_CH_VDDQ_DDR: 2014 + if (!adc->cfg->regs->or_vddq_ddr.reg) 2015 + dev_warn(&indio_dev->dev, 2016 + "%s channel not available\n", ch_name); 2017 + break; 2018 + case STM32_ADC_INT_CH_VREFINT: 2019 + if (!adc->cfg->regs->ccr_vref.reg) 2020 + dev_warn(&indio_dev->dev, 2021 + "%s channel not available\n", ch_name); 2022 + break; 2023 + case STM32_ADC_INT_CH_VBAT: 2024 + if (!adc->cfg->regs->ccr_vbat.reg) 2025 + dev_warn(&indio_dev->dev, 2026 + "%s channel not available\n", ch_name); 2027 + break; 2028 + } 2029 + 2110 2030 if (stm32_adc_ic[i].idx != STM32_ADC_INT_CH_VREFINT) { 2111 2031 adc->int_ch[i] = chan; 2112 2032 break; ··· 2569 2431 .irq_clear = stm32f4_adc_irq_clear, 2570 2432 }; 2571 2433 2434 + const unsigned int stm32_adc_min_ts_h7[] = { 0, 0, 0, 4300, 9000 }; 2435 + static_assert(ARRAY_SIZE(stm32_adc_min_ts_h7) == STM32_ADC_INT_CH_NB); 2436 + 2572 2437 static const struct stm32_adc_cfg stm32h7_adc_cfg = { 2573 2438 .regs = &stm32h7_adc_regspec, 2574 2439 .adc_info = &stm32h7_adc_info, 2575 2440 .trigs = stm32h7_adc_trigs, 2441 + .has_boostmode = true, 2442 + .has_linearcal = true, 2443 + .has_presel = true, 2576 2444 .start_conv = stm32h7_adc_start_conv, 2577 2445 .stop_conv = stm32h7_adc_stop_conv, 2578 2446 .prepare = stm32h7_adc_prepare, 2579 2447 .unprepare = stm32h7_adc_unprepare, 2580 2448 .smp_cycles = stm32h7_adc_smp_cycles, 2581 2449 .irq_clear = stm32h7_adc_irq_clear, 2450 + .ts_int_ch = stm32_adc_min_ts_h7, 2582 2451 }; 2452 + 2453 + const unsigned int stm32_adc_min_ts_mp1[] = { 100, 100, 100, 4300, 9800 }; 2454 + static_assert(ARRAY_SIZE(stm32_adc_min_ts_mp1) == STM32_ADC_INT_CH_NB); 2583 2455 2584 2456 static const struct stm32_adc_cfg stm32mp1_adc_cfg = { 2585 2457 .regs = &stm32mp1_adc_regspec, 2586 2458 .adc_info = &stm32h7_adc_info, 2587 2459 .trigs = stm32h7_adc_trigs, 2588 2460 .has_vregready = true, 2461 + .has_boostmode = true, 2462 + .has_linearcal = true, 2463 + .has_presel = true, 2589 2464 .start_conv = stm32h7_adc_start_conv, 2590 2465 .stop_conv = stm32h7_adc_stop_conv, 2591 2466 .prepare = stm32h7_adc_prepare, 2592 2467 .unprepare = stm32h7_adc_unprepare, 2593 2468 .smp_cycles = stm32h7_adc_smp_cycles, 2594 2469 .irq_clear = stm32h7_adc_irq_clear, 2595 - .ts_vrefint_ns = 4300, 2470 + .ts_int_ch = stm32_adc_min_ts_mp1, 2471 + }; 2472 + 2473 + const unsigned int stm32_adc_min_ts_mp13[] = { 100, 0, 0, 4300, 9800 }; 2474 + static_assert(ARRAY_SIZE(stm32_adc_min_ts_mp13) == STM32_ADC_INT_CH_NB); 2475 + 2476 + static const struct stm32_adc_cfg stm32mp13_adc_cfg = { 2477 + .regs = &stm32mp13_adc_regspec, 2478 + .adc_info = &stm32mp13_adc_info, 2479 + .trigs = stm32h7_adc_trigs, 2480 + .start_conv = stm32mp13_adc_start_conv, 2481 + .stop_conv = stm32h7_adc_stop_conv, 2482 + .prepare = stm32h7_adc_prepare, 2483 + .unprepare = stm32h7_adc_unprepare, 2484 + .smp_cycles = stm32mp13_adc_smp_cycles, 2485 + .irq_clear = stm32h7_adc_irq_clear, 2486 + .ts_int_ch = stm32_adc_min_ts_mp13, 2596 2487 }; 2597 2488 2598 2489 static const struct of_device_id stm32_adc_of_match[] = { 2599 2490 { .compatible = "st,stm32f4-adc", .data = (void *)&stm32f4_adc_cfg }, 2600 2491 { .compatible = "st,stm32h7-adc", .data = (void *)&stm32h7_adc_cfg }, 2601 2492 { .compatible = "st,stm32mp1-adc", .data = (void *)&stm32mp1_adc_cfg }, 2493 + { .compatible = "st,stm32mp13-adc", .data = (void *)&stm32mp13_adc_cfg }, 2602 2494 {}, 2603 2495 }; 2604 2496 MODULE_DEVICE_TABLE(of, stm32_adc_of_match);
+11
drivers/iio/adc/ti-ads131e08.c
··· 807 807 int ret; 808 808 809 809 info = device_get_match_data(&spi->dev); 810 + if (!info) 811 + info = (void *)spi_get_device_id(spi)->driver_data; 810 812 if (!info) { 811 813 dev_err(&spi->dev, "failed to get match data\n"); 812 814 return -ENODEV; ··· 928 926 }; 929 927 MODULE_DEVICE_TABLE(of, ads131e08_of_match); 930 928 929 + static const struct spi_device_id ads131e08_ids[] = { 930 + { "ads131e04", (kernel_ulong_t)&ads131e08_info_tbl[ads131e04] }, 931 + { "ads131e06", (kernel_ulong_t)&ads131e08_info_tbl[ads131e06] }, 932 + { "ads131e08", (kernel_ulong_t)&ads131e08_info_tbl[ads131e08] }, 933 + {} 934 + }; 935 + MODULE_DEVICE_TABLE(spi, ads131e08_ids); 936 + 931 937 static struct spi_driver ads131e08_driver = { 932 938 .driver = { 933 939 .name = "ads131e08", 934 940 .of_match_table = ads131e08_of_match, 935 941 }, 936 942 .probe = ads131e08_probe, 943 + .id_table = ads131e08_ids, 937 944 }; 938 945 module_spi_driver(ads131e08_driver); 939 946
+62 -42
drivers/iio/adc/vf610_adc.c
··· 7 7 8 8 #include <linux/mod_devicetable.h> 9 9 #include <linux/module.h> 10 + #include <linux/mutex.h> 10 11 #include <linux/property.h> 11 12 #include <linux/platform_device.h> 12 13 #include <linux/interrupt.h> ··· 156 155 struct device *dev; 157 156 void __iomem *regs; 158 157 struct clk *clk; 158 + 159 + /* lock to protect against multiple access to the device */ 160 + struct mutex lock; 159 161 160 162 u32 vref_uv; 161 163 u32 value; ··· 471 467 { 472 468 struct vf610_adc *info = iio_priv(indio_dev); 473 469 474 - mutex_lock(&indio_dev->mlock); 470 + mutex_lock(&info->lock); 475 471 info->adc_feature.conv_mode = mode; 476 472 vf610_adc_calculate_rates(info); 477 473 vf610_adc_hw_init(info); 478 - mutex_unlock(&indio_dev->mlock); 474 + mutex_unlock(&info->lock); 479 475 480 476 return 0; 481 477 } ··· 626 622 .attrs = vf610_attributes, 627 623 }; 628 624 625 + static int vf610_read_sample(struct iio_dev *indio_dev, 626 + struct iio_chan_spec const *chan, int *val) 627 + { 628 + struct vf610_adc *info = iio_priv(indio_dev); 629 + unsigned int hc_cfg; 630 + int ret; 631 + 632 + ret = iio_device_claim_direct_mode(indio_dev); 633 + if (ret) 634 + return ret; 635 + 636 + mutex_lock(&info->lock); 637 + reinit_completion(&info->completion); 638 + hc_cfg = VF610_ADC_ADCHC(chan->channel); 639 + hc_cfg |= VF610_ADC_AIEN; 640 + writel(hc_cfg, info->regs + VF610_REG_ADC_HC0); 641 + ret = wait_for_completion_interruptible_timeout(&info->completion, 642 + VF610_ADC_TIMEOUT); 643 + if (ret == 0) { 644 + ret = -ETIMEDOUT; 645 + goto out_unlock; 646 + } 647 + 648 + if (ret < 0) 649 + goto out_unlock; 650 + 651 + switch (chan->type) { 652 + case IIO_VOLTAGE: 653 + *val = info->value; 654 + break; 655 + case IIO_TEMP: 656 + /* 657 + * Calculate in degree Celsius times 1000 658 + * Using the typical sensor slope of 1.84 mV/°C 659 + * and VREFH_ADC at 3.3V, V at 25°C of 699 mV 660 + */ 661 + *val = 25000 - ((int)info->value - VF610_VTEMP25_3V3) * 662 + 1000000 / VF610_TEMP_SLOPE_COEFF; 663 + 664 + break; 665 + default: 666 + ret = -EINVAL; 667 + break; 668 + } 669 + 670 + out_unlock: 671 + mutex_unlock(&info->lock); 672 + iio_device_release_direct_mode(indio_dev); 673 + 674 + return ret; 675 + } 676 + 629 677 static int vf610_read_raw(struct iio_dev *indio_dev, 630 678 struct iio_chan_spec const *chan, 631 679 int *val, ··· 685 629 long mask) 686 630 { 687 631 struct vf610_adc *info = iio_priv(indio_dev); 688 - unsigned int hc_cfg; 689 632 long ret; 690 633 691 634 switch (mask) { 692 635 case IIO_CHAN_INFO_RAW: 693 636 case IIO_CHAN_INFO_PROCESSED: 694 - mutex_lock(&indio_dev->mlock); 695 - if (iio_buffer_enabled(indio_dev)) { 696 - mutex_unlock(&indio_dev->mlock); 697 - return -EBUSY; 698 - } 699 - 700 - reinit_completion(&info->completion); 701 - hc_cfg = VF610_ADC_ADCHC(chan->channel); 702 - hc_cfg |= VF610_ADC_AIEN; 703 - writel(hc_cfg, info->regs + VF610_REG_ADC_HC0); 704 - ret = wait_for_completion_interruptible_timeout 705 - (&info->completion, VF610_ADC_TIMEOUT); 706 - if (ret == 0) { 707 - mutex_unlock(&indio_dev->mlock); 708 - return -ETIMEDOUT; 709 - } 710 - if (ret < 0) { 711 - mutex_unlock(&indio_dev->mlock); 637 + ret = vf610_read_sample(indio_dev, chan, val); 638 + if (ret < 0) 712 639 return ret; 713 - } 714 640 715 - switch (chan->type) { 716 - case IIO_VOLTAGE: 717 - *val = info->value; 718 - break; 719 - case IIO_TEMP: 720 - /* 721 - * Calculate in degree Celsius times 1000 722 - * Using the typical sensor slope of 1.84 mV/°C 723 - * and VREFH_ADC at 3.3V, V at 25°C of 699 mV 724 - */ 725 - *val = 25000 - ((int)info->value - VF610_VTEMP25_3V3) * 726 - 1000000 / VF610_TEMP_SLOPE_COEFF; 727 - 728 - break; 729 - default: 730 - mutex_unlock(&indio_dev->mlock); 731 - return -EINVAL; 732 - } 733 - 734 - mutex_unlock(&indio_dev->mlock); 735 641 return IIO_VAL_INT; 736 642 737 643 case IIO_CHAN_INFO_SCALE: ··· 895 877 dev_err(&pdev->dev, "Couldn't initialise the buffer\n"); 896 878 goto error_iio_device_register; 897 879 } 880 + 881 + mutex_init(&info->lock); 898 882 899 883 ret = iio_device_register(indio_dev); 900 884 if (ret) {
+1 -16
drivers/iio/amplifiers/hmc425a.c
··· 34 34 }; 35 35 36 36 struct hmc425a_state { 37 - struct regulator *reg; 38 37 struct mutex lock; /* protect sensor state */ 39 38 struct hmc425a_chip_info *chip_info; 40 39 struct gpio_descs *gpios; ··· 161 162 }; 162 163 MODULE_DEVICE_TABLE(of, hmc425a_of_match); 163 164 164 - static void hmc425a_reg_disable(void *data) 165 - { 166 - struct hmc425a_state *st = data; 167 - 168 - regulator_disable(st->reg); 169 - } 170 - 171 165 static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = { 172 166 [ID_HMC425A] = { 173 167 .name = "hmc425a", ··· 203 211 return -ENODEV; 204 212 } 205 213 206 - st->reg = devm_regulator_get(&pdev->dev, "vcc-supply"); 207 - if (IS_ERR(st->reg)) 208 - return PTR_ERR(st->reg); 209 - 210 - ret = regulator_enable(st->reg); 211 - if (ret) 212 - return ret; 213 - ret = devm_add_action_or_reset(&pdev->dev, hmc425a_reg_disable, st); 214 + ret = devm_regulator_get_enable(&pdev->dev, "vcc-supply"); 214 215 if (ret) 215 216 return ret; 216 217
+2 -2
drivers/iio/buffer/industrialio-buffer-dmaengine.c
··· 142 142 static IIO_DEVICE_ATTR(length_align_bytes, 0444, 143 143 iio_dmaengine_buffer_get_length_align, NULL, 0); 144 144 145 - static const struct attribute *iio_dmaengine_buffer_attrs[] = { 146 - &iio_dev_attr_length_align_bytes.dev_attr.attr, 145 + static const struct iio_dev_attr *iio_dmaengine_buffer_attrs[] = { 146 + &iio_dev_attr_length_align_bytes, 147 147 NULL, 148 148 }; 149 149
+2 -2
drivers/iio/buffer/industrialio-triggered-buffer.c
··· 41 41 irqreturn_t (*thread)(int irq, void *p), 42 42 enum iio_buffer_direction direction, 43 43 const struct iio_buffer_setup_ops *setup_ops, 44 - const struct attribute **buffer_attrs) 44 + const struct iio_dev_attr **buffer_attrs) 45 45 { 46 46 struct iio_buffer *buffer; 47 47 int ret; ··· 110 110 irqreturn_t (*thread)(int irq, void *p), 111 111 enum iio_buffer_direction direction, 112 112 const struct iio_buffer_setup_ops *ops, 113 - const struct attribute **buffer_attrs) 113 + const struct iio_dev_attr **buffer_attrs) 114 114 { 115 115 int ret; 116 116
+1 -1
drivers/iio/buffer/kfifo_buf.c
··· 270 270 int devm_iio_kfifo_buffer_setup_ext(struct device *dev, 271 271 struct iio_dev *indio_dev, 272 272 const struct iio_buffer_setup_ops *setup_ops, 273 - const struct attribute **buffer_attrs) 273 + const struct iio_dev_attr **buffer_attrs) 274 274 { 275 275 struct iio_buffer *buffer; 276 276
+1 -17
drivers/iio/cdc/ad7150.c
··· 536 536 .read_raw = &ad7150_read_raw, 537 537 }; 538 538 539 - static void ad7150_reg_disable(void *data) 540 - { 541 - struct regulator *reg = data; 542 - 543 - regulator_disable(reg); 544 - } 545 - 546 539 static int ad7150_probe(struct i2c_client *client, 547 540 const struct i2c_device_id *id) 548 541 { 549 542 struct ad7150_chip_info *chip; 550 543 struct iio_dev *indio_dev; 551 - struct regulator *reg; 552 544 int ret; 553 545 554 546 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); ··· 555 563 556 564 indio_dev->modes = INDIO_DIRECT_MODE; 557 565 558 - reg = devm_regulator_get(&client->dev, "vdd"); 559 - if (IS_ERR(reg)) 560 - return PTR_ERR(reg); 561 - 562 - ret = regulator_enable(reg); 563 - if (ret) 564 - return ret; 565 - 566 - ret = devm_add_action_or_reset(&client->dev, ad7150_reg_disable, reg); 566 + ret = devm_regulator_get_enable(&client->dev, "vdd"); 567 567 if (ret) 568 568 return ret; 569 569
+3 -3
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
··· 172 172 173 173 static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0); 174 174 175 - static const struct attribute *cros_ec_sensor_fifo_attributes[] = { 176 - &iio_dev_attr_hwfifo_timeout.dev_attr.attr, 177 - &iio_dev_attr_hwfifo_watermark_max.dev_attr.attr, 175 + static const struct iio_dev_attr *cros_ec_sensor_fifo_attributes[] = { 176 + &iio_dev_attr_hwfifo_timeout, 177 + &iio_dev_attr_hwfifo_watermark_max, 178 178 NULL, 179 179 }; 180 180
+4 -4
drivers/iio/common/hid-sensors/hid-sensor-trigger.c
··· 75 75 static IIO_DEVICE_ATTR(hwfifo_enabled, 0444, 76 76 _hid_sensor_get_fifo_state, NULL, 0); 77 77 78 - static const struct attribute *hid_sensor_fifo_attributes[] = { 79 - &iio_dev_attr_hwfifo_timeout.dev_attr.attr, 80 - &iio_dev_attr_hwfifo_enabled.dev_attr.attr, 78 + static const struct iio_dev_attr *hid_sensor_fifo_attributes[] = { 79 + &iio_dev_attr_hwfifo_timeout, 80 + &iio_dev_attr_hwfifo_enabled, 81 81 NULL, 82 82 }; 83 83 ··· 231 231 int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, 232 232 struct hid_sensor_common *attrb) 233 233 { 234 - const struct attribute **fifo_attrs; 234 + const struct iio_dev_attr **fifo_attrs; 235 235 int ret; 236 236 struct iio_trigger *trig; 237 237
+7 -2
drivers/iio/common/scmi_sensors/scmi_iio.c
··· 15 15 #include <linux/kernel.h> 16 16 #include <linux/kthread.h> 17 17 #include <linux/module.h> 18 + #include <linux/mutex.h> 18 19 #include <linux/scmi_protocol.h> 19 20 #include <linux/time.h> 20 21 #include <linux/types.h> ··· 28 27 struct scmi_protocol_handle *ph; 29 28 const struct scmi_sensor_info *sensor_info; 30 29 struct iio_dev *indio_dev; 30 + /* lock to protect against multiple access to the device */ 31 + struct mutex lock; 31 32 /* adding one additional channel for timestamp */ 32 33 s64 iio_buf[SCMI_IIO_NUM_OF_AXIS + 1]; 33 34 struct notifier_block sensor_update_nb; ··· 201 198 struct iio_chan_spec const *chan, int val, 202 199 int val2, long mask) 203 200 { 201 + struct scmi_iio_priv *sensor = iio_priv(iio_dev); 204 202 int err; 205 203 206 204 switch (mask) { 207 205 case IIO_CHAN_INFO_SAMP_FREQ: 208 - mutex_lock(&iio_dev->mlock); 206 + mutex_lock(&sensor->lock); 209 207 err = scmi_iio_set_odr_val(iio_dev, val, val2); 210 - mutex_unlock(&iio_dev->mlock); 208 + mutex_unlock(&sensor->lock); 211 209 return err; 212 210 default: 213 211 return -EINVAL; ··· 590 586 sensor->sensor_info = sensor_info; 591 587 sensor->sensor_update_nb.notifier_call = scmi_iio_sensor_update_cb; 592 588 sensor->indio_dev = iiodev; 589 + mutex_init(&sensor->lock); 593 590 594 591 /* adding one additional channel for timestamp */ 595 592 iiodev->num_channels = sensor_info->num_axis + 1;
+7 -32
drivers/iio/common/st_sensors/st_sensors_core.c
··· 219 219 } 220 220 EXPORT_SYMBOL_NS(st_sensors_set_axis_enable, IIO_ST_SENSORS); 221 221 222 - static void st_reg_disable(void *reg) 223 - { 224 - regulator_disable(reg); 225 - } 226 222 227 223 int st_sensors_power_enable(struct iio_dev *indio_dev) 228 224 { 229 - struct st_sensor_data *pdata = iio_priv(indio_dev); 225 + static const char * const regulator_names[] = { "vdd", "vddio" }; 230 226 struct device *parent = indio_dev->dev.parent; 231 227 int err; 232 228 233 229 /* Regulators not mandatory, but if requested we should enable them. */ 234 - pdata->vdd = devm_regulator_get(parent, "vdd"); 235 - if (IS_ERR(pdata->vdd)) 236 - return dev_err_probe(&indio_dev->dev, PTR_ERR(pdata->vdd), 237 - "unable to get Vdd supply\n"); 238 - 239 - err = regulator_enable(pdata->vdd); 240 - if (err != 0) { 241 - dev_warn(&indio_dev->dev, 242 - "Failed to enable specified Vdd supply\n"); 243 - return err; 244 - } 245 - 246 - err = devm_add_action_or_reset(parent, st_reg_disable, pdata->vdd); 230 + err = devm_regulator_bulk_get_enable(parent, 231 + ARRAY_SIZE(regulator_names), 232 + regulator_names); 247 233 if (err) 248 - return err; 234 + return dev_err_probe(&indio_dev->dev, err, 235 + "unable to enable supplies\n"); 249 236 250 - pdata->vdd_io = devm_regulator_get(parent, "vddio"); 251 - if (IS_ERR(pdata->vdd_io)) 252 - return dev_err_probe(&indio_dev->dev, PTR_ERR(pdata->vdd_io), 253 - "unable to get Vdd_IO supply\n"); 254 - 255 - err = regulator_enable(pdata->vdd_io); 256 - if (err != 0) { 257 - dev_warn(&indio_dev->dev, 258 - "Failed to enable specified Vdd_IO supply\n"); 259 - return err; 260 - } 261 - 262 - return devm_add_action_or_reset(parent, st_reg_disable, pdata->vdd_io); 237 + return 0; 263 238 } 264 239 EXPORT_SYMBOL_NS(st_sensors_power_enable, IIO_ST_SENSORS); 265 240
+3 -20
drivers/iio/dac/ltc2688.c
··· 84 84 struct ltc2688_state { 85 85 struct spi_device *spi; 86 86 struct regmap *regmap; 87 - struct regulator_bulk_data regulators[2]; 88 87 struct ltc2688_chan channels[LTC2688_DAC_CHANNELS]; 89 88 struct iio_chan_spec *iio_chan; 90 89 /* lock to protect against multiple access to the device and shared data */ ··· 901 902 LTC2688_CONFIG_EXT_REF); 902 903 } 903 904 904 - static void ltc2688_disable_regulators(void *data) 905 - { 906 - struct ltc2688_state *st = data; 907 - 908 - regulator_bulk_disable(ARRAY_SIZE(st->regulators), st->regulators); 909 - } 910 - 911 905 static void ltc2688_disable_regulator(void *regulator) 912 906 { 913 907 regulator_disable(regulator); ··· 957 965 958 966 static int ltc2688_probe(struct spi_device *spi) 959 967 { 968 + static const char * const regulators[] = { "vcc", "iovcc" }; 960 969 struct ltc2688_state *st; 961 970 struct iio_dev *indio_dev; 962 971 struct regulator *vref_reg; ··· 981 988 return dev_err_probe(dev, PTR_ERR(st->regmap), 982 989 "Failed to init regmap"); 983 990 984 - st->regulators[0].supply = "vcc"; 985 - st->regulators[1].supply = "iovcc"; 986 - ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(st->regulators), 987 - st->regulators); 988 - if (ret) 989 - return dev_err_probe(dev, ret, "Failed to get regulators\n"); 990 - 991 - ret = regulator_bulk_enable(ARRAY_SIZE(st->regulators), st->regulators); 991 + ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), 992 + regulators); 992 993 if (ret) 993 994 return dev_err_probe(dev, ret, "Failed to enable regulators\n"); 994 - 995 - ret = devm_add_action_or_reset(dev, ltc2688_disable_regulators, st); 996 - if (ret) 997 - return ret; 998 995 999 996 vref_reg = devm_regulator_get_optional(dev, "vref"); 1000 997 if (IS_ERR(vref_reg)) {
+2 -2
drivers/iio/filter/admv8818.c
··· 265 265 return ret; 266 266 267 267 hpf_band = FIELD_GET(ADMV8818_SW_IN_WR0_MSK, data); 268 - if (!hpf_band) { 268 + if (!hpf_band || hpf_band > 4) { 269 269 *hpf_freq = 0; 270 270 return ret; 271 271 } ··· 303 303 return ret; 304 304 305 305 lpf_band = FIELD_GET(ADMV8818_SW_OUT_WR0_MSK, data); 306 - if (!lpf_band) { 306 + if (!lpf_band || lpf_band > 4) { 307 307 *lpf_freq = 0; 308 308 return ret; 309 309 }
+3 -19
drivers/iio/frequency/ad9523.c
··· 265 265 266 266 struct ad9523_state { 267 267 struct spi_device *spi; 268 - struct regulator *reg; 269 268 struct ad9523_platform_data *pdata; 270 269 struct iio_chan_spec ad9523_channels[AD9523_NUM_CHAN]; 271 270 struct gpio_desc *pwrdown_gpio; ··· 968 969 return 0; 969 970 } 970 971 971 - static void ad9523_reg_disable(void *data) 972 - { 973 - struct regulator *reg = data; 974 - 975 - regulator_disable(reg); 976 - } 977 - 978 972 static int ad9523_probe(struct spi_device *spi) 979 973 { 980 974 struct ad9523_platform_data *pdata = spi->dev.platform_data; ··· 988 996 989 997 mutex_init(&st->lock); 990 998 991 - st->reg = devm_regulator_get(&spi->dev, "vcc"); 992 - if (!IS_ERR(st->reg)) { 993 - ret = regulator_enable(st->reg); 994 - if (ret) 995 - return ret; 996 - 997 - ret = devm_add_action_or_reset(&spi->dev, ad9523_reg_disable, 998 - st->reg); 999 - if (ret) 1000 - return ret; 1001 - } 999 + ret = devm_regulator_get_enable(&spi->dev, "vcc"); 1000 + if (ret) 1001 + return ret; 1002 1002 1003 1003 st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown", 1004 1004 GPIOD_OUT_HIGH);
+3 -21
drivers/iio/gyro/bmg160_core.c
··· 93 93 94 94 struct bmg160_data { 95 95 struct regmap *regmap; 96 - struct regulator_bulk_data regulators[2]; 97 96 struct iio_trigger *dready_trig; 98 97 struct iio_trigger *motion_trig; 99 98 struct iio_mount_matrix orientation; ··· 1066 1067 return dev_name(dev); 1067 1068 } 1068 1069 1069 - static void bmg160_disable_regulators(void *d) 1070 - { 1071 - struct bmg160_data *data = d; 1072 - 1073 - regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); 1074 - } 1075 - 1076 1070 int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, 1077 1071 const char *name) 1078 1072 { 1073 + static const char * const regulators[] = { "vdd", "vddio" }; 1079 1074 struct bmg160_data *data; 1080 1075 struct iio_dev *indio_dev; 1081 1076 int ret; ··· 1083 1090 data->irq = irq; 1084 1091 data->regmap = regmap; 1085 1092 1086 - data->regulators[0].supply = "vdd"; 1087 - data->regulators[1].supply = "vddio"; 1088 - ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->regulators), 1089 - data->regulators); 1093 + ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), 1094 + regulators); 1090 1095 if (ret) 1091 1096 return dev_err_probe(dev, ret, "Failed to get regulators\n"); 1092 - 1093 - ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators), 1094 - data->regulators); 1095 - if (ret) 1096 - return ret; 1097 - 1098 - ret = devm_add_action_or_reset(dev, bmg160_disable_regulators, data); 1099 - if (ret) 1100 - return ret; 1101 1097 1102 1098 ret = iio_read_mount_matrix(dev, &data->orientation); 1103 1099 if (ret)
+10 -11
drivers/iio/gyro/fxas21002c_core.c
··· 998 998 999 999 return ret; 1000 1000 } 1001 - EXPORT_SYMBOL_GPL(fxas21002c_core_probe); 1001 + EXPORT_SYMBOL_NS_GPL(fxas21002c_core_probe, IIO_FXAS21002C); 1002 1002 1003 1003 void fxas21002c_core_remove(struct device *dev) 1004 1004 { ··· 1009 1009 pm_runtime_disable(dev); 1010 1010 pm_runtime_set_suspended(dev); 1011 1011 } 1012 - EXPORT_SYMBOL_GPL(fxas21002c_core_remove); 1012 + EXPORT_SYMBOL_NS_GPL(fxas21002c_core_remove, IIO_FXAS21002C); 1013 1013 1014 - static int __maybe_unused fxas21002c_suspend(struct device *dev) 1014 + static int fxas21002c_suspend(struct device *dev) 1015 1015 { 1016 1016 struct fxas21002c_data *data = iio_priv(dev_get_drvdata(dev)); 1017 1017 ··· 1021 1021 return 0; 1022 1022 } 1023 1023 1024 - static int __maybe_unused fxas21002c_resume(struct device *dev) 1024 + static int fxas21002c_resume(struct device *dev) 1025 1025 { 1026 1026 struct fxas21002c_data *data = iio_priv(dev_get_drvdata(dev)); 1027 1027 int ret; ··· 1033 1033 return fxas21002c_mode_set(data, data->prev_mode); 1034 1034 } 1035 1035 1036 - static int __maybe_unused fxas21002c_runtime_suspend(struct device *dev) 1036 + static int fxas21002c_runtime_suspend(struct device *dev) 1037 1037 { 1038 1038 struct fxas21002c_data *data = iio_priv(dev_get_drvdata(dev)); 1039 1039 1040 1040 return fxas21002c_mode_set(data, FXAS21002C_MODE_READY); 1041 1041 } 1042 1042 1043 - static int __maybe_unused fxas21002c_runtime_resume(struct device *dev) 1043 + static int fxas21002c_runtime_resume(struct device *dev) 1044 1044 { 1045 1045 struct fxas21002c_data *data = iio_priv(dev_get_drvdata(dev)); 1046 1046 1047 1047 return fxas21002c_mode_set(data, FXAS21002C_MODE_ACTIVE); 1048 1048 } 1049 1049 1050 - const struct dev_pm_ops fxas21002c_pm_ops = { 1051 - SET_SYSTEM_SLEEP_PM_OPS(fxas21002c_suspend, fxas21002c_resume) 1052 - SET_RUNTIME_PM_OPS(fxas21002c_runtime_suspend, 1053 - fxas21002c_runtime_resume, NULL) 1050 + EXPORT_NS_GPL_DEV_PM_OPS(fxas21002c_pm_ops, IIO_FXAS21002C) = { 1051 + SYSTEM_SLEEP_PM_OPS(fxas21002c_suspend, fxas21002c_resume) 1052 + RUNTIME_PM_OPS(fxas21002c_runtime_suspend, fxas21002c_runtime_resume, 1053 + NULL) 1054 1054 }; 1055 - EXPORT_SYMBOL_GPL(fxas21002c_pm_ops); 1056 1055 1057 1056 MODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>"); 1058 1057 MODULE_LICENSE("GPL v2");
+2 -1
drivers/iio/gyro/fxas21002c_i2c.c
··· 53 53 static struct i2c_driver fxas21002c_i2c_driver = { 54 54 .driver = { 55 55 .name = "fxas21002c_i2c", 56 - .pm = &fxas21002c_pm_ops, 56 + .pm = pm_ptr(&fxas21002c_pm_ops), 57 57 .of_match_table = fxas21002c_i2c_of_match, 58 58 }, 59 59 .probe_new = fxas21002c_i2c_probe, ··· 65 65 MODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>"); 66 66 MODULE_LICENSE("GPL v2"); 67 67 MODULE_DESCRIPTION("FXAS21002C I2C Gyro driver"); 68 + MODULE_IMPORT_NS(IIO_FXAS21002C);
+2 -1
drivers/iio/gyro/fxas21002c_spi.c
··· 54 54 static struct spi_driver fxas21002c_spi_driver = { 55 55 .driver = { 56 56 .name = "fxas21002c_spi", 57 - .pm = &fxas21002c_pm_ops, 57 + .pm = pm_ptr(&fxas21002c_pm_ops), 58 58 .of_match_table = fxas21002c_spi_of_match, 59 59 }, 60 60 .probe = fxas21002c_spi_probe, ··· 66 66 MODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>"); 67 67 MODULE_LICENSE("GPL v2"); 68 68 MODULE_DESCRIPTION("FXAS21002C SPI Gyro driver"); 69 + MODULE_IMPORT_NS(IIO_FXAS21002C);
+7 -3
drivers/iio/gyro/itg3200_core.c
··· 18 18 #include <linux/slab.h> 19 19 #include <linux/stat.h> 20 20 #include <linux/module.h> 21 + #include <linux/mutex.h> 21 22 #include <linux/delay.h> 22 23 23 24 #include <linux/iio/iio.h> ··· 132 131 int val2, 133 132 long mask) 134 133 { 134 + struct itg3200 *st = iio_priv(indio_dev); 135 135 int ret; 136 136 u8 t; 137 137 ··· 141 139 if (val == 0 || val2 != 0) 142 140 return -EINVAL; 143 141 144 - mutex_lock(&indio_dev->mlock); 142 + mutex_lock(&st->lock); 145 143 146 144 ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_DLPF, &t); 147 145 if (ret) { 148 - mutex_unlock(&indio_dev->mlock); 146 + mutex_unlock(&st->lock); 149 147 return ret; 150 148 } 151 149 t = ((t & ITG3200_DLPF_CFG_MASK) ? 1000u : 8000u) / val - 1; ··· 154 152 ITG3200_REG_SAMPLE_RATE_DIV, 155 153 t); 156 154 157 - mutex_unlock(&indio_dev->mlock); 155 + mutex_unlock(&st->lock); 158 156 return ret; 159 157 160 158 default: ··· 337 335 ret = itg3200_initial_setup(indio_dev); 338 336 if (ret) 339 337 goto error_remove_trigger; 338 + 339 + mutex_init(&st->lock); 340 340 341 341 ret = iio_device_register(indio_dev); 342 342 if (ret)
+9 -6
drivers/iio/health/max30100.c
··· 387 387 * Temperature reading can only be acquired while engine 388 388 * is running 389 389 */ 390 - mutex_lock(&indio_dev->mlock); 391 - 392 - if (!iio_buffer_enabled(indio_dev)) 390 + if (iio_device_claim_buffer_mode(indio_dev)) { 391 + /* 392 + * Replacing -EBUSY or other error code 393 + * returned by iio_device_claim_buffer_mode() 394 + * because user space may rely on the current 395 + * one. 396 + */ 393 397 ret = -EAGAIN; 394 - else { 398 + } else { 395 399 ret = max30100_get_temp(data, val); 396 400 if (!ret) 397 401 ret = IIO_VAL_INT; 398 402 403 + iio_device_release_buffer_mode(indio_dev); 399 404 } 400 - 401 - mutex_unlock(&indio_dev->mlock); 402 405 break; 403 406 case IIO_CHAN_INFO_SCALE: 404 407 *val = 1; /* 0.0625 */
+15 -4
drivers/iio/health/max30102.c
··· 477 477 * Temperature reading can only be acquired when not in 478 478 * shutdown; leave shutdown briefly when buffer not running 479 479 */ 480 - mutex_lock(&indio_dev->mlock); 481 - if (!iio_buffer_enabled(indio_dev)) 480 + any_mode_retry: 481 + if (iio_device_claim_buffer_mode(indio_dev)) { 482 + /* 483 + * This one is a *bit* hacky. If we cannot claim buffer 484 + * mode, then try direct mode so that we make sure 485 + * things cannot concurrently change. And we just keep 486 + * trying until we get one of the modes... 487 + */ 488 + if (iio_device_claim_direct_mode(indio_dev)) 489 + goto any_mode_retry; 490 + 482 491 ret = max30102_get_temp(data, val, true); 483 - else 492 + iio_device_release_direct_mode(indio_dev); 493 + } else { 484 494 ret = max30102_get_temp(data, val, false); 485 - mutex_unlock(&indio_dev->mlock); 495 + iio_device_release_buffer_mode(indio_dev); 496 + } 486 497 if (ret) 487 498 return ret; 488 499
-2
drivers/iio/humidity/hts221.h
··· 13 13 #define HTS221_DEV_NAME "hts221" 14 14 15 15 #include <linux/iio/iio.h> 16 - #include <linux/regulator/consumer.h> 17 16 18 17 enum hts221_sensor_type { 19 18 HTS221_SENSOR_H, ··· 29 30 const char *name; 30 31 struct device *dev; 31 32 struct regmap *regmap; 32 - struct regulator *vdd; 33 33 34 34 struct iio_trigger *trig; 35 35 int irq;
+4 -23
drivers/iio/humidity/hts221_core.c
··· 14 14 #include <linux/delay.h> 15 15 #include <linux/pm.h> 16 16 #include <linux/regmap.h> 17 + #include <linux/regulator/consumer.h> 17 18 #include <linux/bitfield.h> 18 19 19 20 #include "hts221.h" ··· 550 549 551 550 static int hts221_init_regulators(struct device *dev) 552 551 { 553 - struct iio_dev *iio_dev = dev_get_drvdata(dev); 554 - struct hts221_hw *hw = iio_priv(iio_dev); 555 552 int err; 556 553 557 - hw->vdd = devm_regulator_get(dev, "vdd"); 558 - if (IS_ERR(hw->vdd)) 559 - return dev_err_probe(dev, PTR_ERR(hw->vdd), 560 - "failed to get vdd regulator\n"); 561 - 562 - err = regulator_enable(hw->vdd); 563 - if (err) { 564 - dev_err(dev, "failed to enable vdd regulator: %d\n", err); 565 - return err; 566 - } 554 + err = devm_regulator_get_enable(dev, "vdd"); 555 + if (err) 556 + return dev_err_probe(dev, err, "failed to get vdd regulator\n"); 567 557 568 558 msleep(50); 569 559 570 560 return 0; 571 - } 572 - 573 - static void hts221_chip_uninit(void *data) 574 - { 575 - struct hts221_hw *hw = data; 576 - 577 - regulator_disable(hw->vdd); 578 561 } 579 562 580 563 int hts221_probe(struct device *dev, int irq, const char *name, ··· 582 597 hw->regmap = regmap; 583 598 584 599 err = hts221_init_regulators(dev); 585 - if (err) 586 - return err; 587 - 588 - err = devm_add_action_or_reset(dev, hts221_chip_uninit, hw); 589 600 if (err) 590 601 return err; 591 602
+2
drivers/iio/imu/inv_icm42600/inv_icm42600.h
··· 22 22 INV_CHIP_ICM42602, 23 23 INV_CHIP_ICM42605, 24 24 INV_CHIP_ICM42622, 25 + INV_CHIP_ICM42631, 25 26 INV_CHIP_NB, 26 27 }; 27 28 ··· 304 303 #define INV_ICM42600_WHOAMI_ICM42602 0x41 305 304 #define INV_ICM42600_WHOAMI_ICM42605 0x42 306 305 #define INV_ICM42600_WHOAMI_ICM42622 0x46 306 + #define INV_ICM42600_WHOAMI_ICM42631 0x5C 307 307 308 308 /* User bank 1 (MSB 0x10) */ 309 309 #define INV_ICM42600_REG_SENSOR_CONFIG0 0x1003
+15 -11
drivers/iio/imu/inv_icm42600/inv_icm42600_core.c
··· 41 41 .ranges = inv_icm42600_regmap_ranges, 42 42 .num_ranges = ARRAY_SIZE(inv_icm42600_regmap_ranges), 43 43 }; 44 - EXPORT_SYMBOL_GPL(inv_icm42600_regmap_config); 44 + EXPORT_SYMBOL_NS_GPL(inv_icm42600_regmap_config, IIO_ICM42600); 45 45 46 46 struct inv_icm42600_hw { 47 47 uint8_t whoami; ··· 85 85 [INV_CHIP_ICM42622] = { 86 86 .whoami = INV_ICM42600_WHOAMI_ICM42622, 87 87 .name = "icm42622", 88 + .conf = &inv_icm42600_default_conf, 89 + }, 90 + [INV_CHIP_ICM42631] = { 91 + .whoami = INV_ICM42600_WHOAMI_ICM42631, 92 + .name = "icm42631", 88 93 .conf = &inv_icm42600_default_conf, 89 94 }, 90 95 }; ··· 665 660 666 661 return devm_add_action_or_reset(dev, inv_icm42600_disable_pm, dev); 667 662 } 668 - EXPORT_SYMBOL_GPL(inv_icm42600_core_probe); 663 + EXPORT_SYMBOL_NS_GPL(inv_icm42600_core_probe, IIO_ICM42600); 669 664 670 665 /* 671 666 * Suspend saves sensors state and turns everything off. 672 667 * Check first if runtime suspend has not already done the job. 673 668 */ 674 - static int __maybe_unused inv_icm42600_suspend(struct device *dev) 669 + static int inv_icm42600_suspend(struct device *dev) 675 670 { 676 671 struct inv_icm42600_state *st = dev_get_drvdata(dev); 677 672 int ret; ··· 711 706 * System resume gets the system back on and restores the sensors state. 712 707 * Manually put runtime power management in system active state. 713 708 */ 714 - static int __maybe_unused inv_icm42600_resume(struct device *dev) 709 + static int inv_icm42600_resume(struct device *dev) 715 710 { 716 711 struct inv_icm42600_state *st = dev_get_drvdata(dev); 717 712 int ret; ··· 744 739 } 745 740 746 741 /* Runtime suspend will turn off sensors that are enabled by iio devices. */ 747 - static int __maybe_unused inv_icm42600_runtime_suspend(struct device *dev) 742 + static int inv_icm42600_runtime_suspend(struct device *dev) 748 743 { 749 744 struct inv_icm42600_state *st = dev_get_drvdata(dev); 750 745 int ret; ··· 766 761 } 767 762 768 763 /* Sensors are enabled by iio devices, no need to turn them back on here. */ 769 - static int __maybe_unused inv_icm42600_runtime_resume(struct device *dev) 764 + static int inv_icm42600_runtime_resume(struct device *dev) 770 765 { 771 766 struct inv_icm42600_state *st = dev_get_drvdata(dev); 772 767 int ret; ··· 779 774 return ret; 780 775 } 781 776 782 - const struct dev_pm_ops inv_icm42600_pm_ops = { 783 - SET_SYSTEM_SLEEP_PM_OPS(inv_icm42600_suspend, inv_icm42600_resume) 784 - SET_RUNTIME_PM_OPS(inv_icm42600_runtime_suspend, 785 - inv_icm42600_runtime_resume, NULL) 777 + EXPORT_NS_GPL_DEV_PM_OPS(inv_icm42600_pm_ops, IIO_ICM42600) = { 778 + SYSTEM_SLEEP_PM_OPS(inv_icm42600_suspend, inv_icm42600_resume) 779 + RUNTIME_PM_OPS(inv_icm42600_runtime_suspend, 780 + inv_icm42600_runtime_resume, NULL) 786 781 }; 787 - EXPORT_SYMBOL_GPL(inv_icm42600_pm_ops); 788 782 789 783 MODULE_AUTHOR("InvenSense, Inc."); 790 784 MODULE_DESCRIPTION("InvenSense ICM-426xx device driver");
+5 -1
drivers/iio/imu/inv_icm42600/inv_icm42600_i2c.c
··· 84 84 }, { 85 85 .compatible = "invensense,icm42622", 86 86 .data = (void *)INV_CHIP_ICM42622, 87 + }, { 88 + .compatible = "invensense,icm42631", 89 + .data = (void *)INV_CHIP_ICM42631, 87 90 }, 88 91 {} 89 92 }; ··· 96 93 .driver = { 97 94 .name = "inv-icm42600-i2c", 98 95 .of_match_table = inv_icm42600_of_matches, 99 - .pm = &inv_icm42600_pm_ops, 96 + .pm = pm_ptr(&inv_icm42600_pm_ops), 100 97 }, 101 98 .probe_new = inv_icm42600_probe, 102 99 }; ··· 105 102 MODULE_AUTHOR("InvenSense, Inc."); 106 103 MODULE_DESCRIPTION("InvenSense ICM-426xx I2C driver"); 107 104 MODULE_LICENSE("GPL"); 105 + MODULE_IMPORT_NS(IIO_ICM42600);
+5 -1
drivers/iio/imu/inv_icm42600/inv_icm42600_spi.c
··· 80 80 }, { 81 81 .compatible = "invensense,icm42622", 82 82 .data = (void *)INV_CHIP_ICM42622, 83 + }, { 84 + .compatible = "invensense,icm42631", 85 + .data = (void *)INV_CHIP_ICM42631, 83 86 }, 84 87 {} 85 88 }; ··· 92 89 .driver = { 93 90 .name = "inv-icm42600-spi", 94 91 .of_match_table = inv_icm42600_of_matches, 95 - .pm = &inv_icm42600_pm_ops, 92 + .pm = pm_ptr(&inv_icm42600_pm_ops), 96 93 }, 97 94 .probe = inv_icm42600_probe, 98 95 }; ··· 101 98 MODULE_AUTHOR("InvenSense, Inc."); 102 99 MODULE_DESCRIPTION("InvenSense ICM-426xx SPI driver"); 103 100 MODULE_LICENSE("GPL"); 101 + MODULE_IMPORT_NS(IIO_ICM42600);
+8 -9
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 1653 1653 inv_mpu6050_set_power_itg(st, false); 1654 1654 return result; 1655 1655 } 1656 - EXPORT_SYMBOL_GPL(inv_mpu_core_probe); 1656 + EXPORT_SYMBOL_NS_GPL(inv_mpu_core_probe, IIO_MPU6050); 1657 1657 1658 - static int __maybe_unused inv_mpu_resume(struct device *dev) 1658 + static int inv_mpu_resume(struct device *dev) 1659 1659 { 1660 1660 struct iio_dev *indio_dev = dev_get_drvdata(dev); 1661 1661 struct inv_mpu6050_state *st = iio_priv(indio_dev); ··· 1687 1687 return result; 1688 1688 } 1689 1689 1690 - static int __maybe_unused inv_mpu_suspend(struct device *dev) 1690 + static int inv_mpu_suspend(struct device *dev) 1691 1691 { 1692 1692 struct iio_dev *indio_dev = dev_get_drvdata(dev); 1693 1693 struct inv_mpu6050_state *st = iio_priv(indio_dev); ··· 1730 1730 return result; 1731 1731 } 1732 1732 1733 - static int __maybe_unused inv_mpu_runtime_suspend(struct device *dev) 1733 + static int inv_mpu_runtime_suspend(struct device *dev) 1734 1734 { 1735 1735 struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(dev)); 1736 1736 unsigned int sensors; ··· 1755 1755 return ret; 1756 1756 } 1757 1757 1758 - static int __maybe_unused inv_mpu_runtime_resume(struct device *dev) 1758 + static int inv_mpu_runtime_resume(struct device *dev) 1759 1759 { 1760 1760 struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(dev)); 1761 1761 int ret; ··· 1767 1767 return inv_mpu6050_set_power_itg(st, true); 1768 1768 } 1769 1769 1770 - const struct dev_pm_ops inv_mpu_pmops = { 1771 - SET_SYSTEM_SLEEP_PM_OPS(inv_mpu_suspend, inv_mpu_resume) 1772 - SET_RUNTIME_PM_OPS(inv_mpu_runtime_suspend, inv_mpu_runtime_resume, NULL) 1770 + EXPORT_NS_GPL_DEV_PM_OPS(inv_mpu_pmops, IIO_MPU6050) = { 1771 + SYSTEM_SLEEP_PM_OPS(inv_mpu_suspend, inv_mpu_resume) 1772 + RUNTIME_PM_OPS(inv_mpu_runtime_suspend, inv_mpu_runtime_resume, NULL) 1773 1773 }; 1774 - EXPORT_SYMBOL_GPL(inv_mpu_pmops); 1775 1774 1776 1775 MODULE_AUTHOR("Invensense Corporation"); 1777 1776 MODULE_DESCRIPTION("Invensense device MPU6050 driver");
+2 -1
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
··· 267 267 .of_match_table = inv_of_match, 268 268 .acpi_match_table = inv_acpi_match, 269 269 .name = "inv-mpu6050-i2c", 270 - .pm = &inv_mpu_pmops, 270 + .pm = pm_ptr(&inv_mpu_pmops), 271 271 }, 272 272 }; 273 273 ··· 276 276 MODULE_AUTHOR("Invensense Corporation"); 277 277 MODULE_DESCRIPTION("Invensense device MPU6050 driver"); 278 278 MODULE_LICENSE("GPL"); 279 + MODULE_IMPORT_NS(IIO_MPU6050);
+2 -1
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
··· 154 154 .of_match_table = inv_of_match, 155 155 .acpi_match_table = inv_acpi_match, 156 156 .name = "inv-mpu6000-spi", 157 - .pm = &inv_mpu_pmops, 157 + .pm = pm_ptr(&inv_mpu_pmops), 158 158 }, 159 159 }; 160 160 ··· 163 163 MODULE_AUTHOR("Adriana Reus <adriana.reus@intel.com>"); 164 164 MODULE_DESCRIPTION("Invensense device MPU6000 driver"); 165 165 MODULE_LICENSE("GPL"); 166 + MODULE_IMPORT_NS(IIO_MPU6050);
+2 -1
drivers/iio/imu/st_lsm6dsx/Kconfig
··· 13 13 sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm, 14 14 ism330dlc, lsm6dso, lsm6dsox, asm330lhh, asm330lhhx, lsm6dsr, 15 15 lsm6ds3tr-c, ism330dhcx, lsm6dsrx, lsm6ds0, lsm6dsop, lsm6dstx, 16 - the accelerometer/gyroscope of lsm9ds1 and lsm6dst. 16 + lsm6dsv, lsm6dsv16x, the accelerometer/gyroscope of lsm9ds1 17 + and lsm6dst. 17 18 18 19 To compile this driver as a module, choose M here: the module 19 20 will be called st_lsm6dsx.
+17 -3
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
··· 33 33 #define ST_LSM6DSOP_DEV_NAME "lsm6dsop" 34 34 #define ST_ASM330LHHX_DEV_NAME "asm330lhhx" 35 35 #define ST_LSM6DSTX_DEV_NAME "lsm6dstx" 36 + #define ST_LSM6DSV_DEV_NAME "lsm6dsv" 37 + #define ST_LSM6DSV16X_DEV_NAME "lsm6dsv16x" 36 38 37 39 enum st_lsm6dsx_hw_id { 38 40 ST_LSM6DS3_ID, ··· 55 53 ST_LSM6DSOP_ID, 56 54 ST_ASM330LHHX_ID, 57 55 ST_LSM6DSTX_ID, 56 + ST_LSM6DSV_ID, 57 + ST_LSM6DSV16X_ID, 58 58 ST_LSM6DSX_MAX_ID, 59 59 }; 60 60 ··· 378 374 * struct st_lsm6dsx_hw - ST IMU MEMS hw instance 379 375 * @dev: Pointer to instance of struct device (I2C or SPI). 380 376 * @regmap: Register map of the device. 381 - * @regulators: VDD/VDDIO voltage regulators. 382 377 * @irq: Device interrupt line (I2C or SPI). 383 378 * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO. 384 379 * @conf_lock: Mutex to prevent concurrent FIFO configuration update. ··· 400 397 struct st_lsm6dsx_hw { 401 398 struct device *dev; 402 399 struct regmap *regmap; 403 - struct regulator_bulk_data regulators[2]; 404 400 int irq; 405 401 406 402 struct mutex fifo_lock; ··· 428 426 struct { 429 427 __le16 channels[3]; 430 428 s64 ts __aligned(8); 431 - } scan[3]; 429 + } scan[ST_LSM6DSX_ID_MAX]; 432 430 }; 433 431 434 432 static __maybe_unused const struct iio_event_spec st_lsm6dsx_event = { ··· 460 458 int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u32 odr, u8 *val); 461 459 int st_lsm6dsx_shub_probe(struct st_lsm6dsx_hw *hw, const char *name); 462 460 int st_lsm6dsx_shub_set_enable(struct st_lsm6dsx_sensor *sensor, bool enable); 461 + int st_lsm6dsx_shub_read_output(struct st_lsm6dsx_hw *hw, u8 *data, int len); 463 462 int st_lsm6dsx_set_page(struct st_lsm6dsx_hw *hw, bool enable); 464 463 465 464 static inline int ··· 510 507 struct st_lsm6dsx_hw *hw = sensor->hw; 511 508 512 509 return &hw->orientation; 510 + } 511 + 512 + static inline int 513 + st_lsm6dsx_device_set_enable(struct st_lsm6dsx_sensor *sensor, bool enable) 514 + { 515 + if (sensor->id == ST_LSM6DSX_ID_EXT0 || 516 + sensor->id == ST_LSM6DSX_ID_EXT1 || 517 + sensor->id == ST_LSM6DSX_ID_EXT2) 518 + return st_lsm6dsx_shub_set_enable(sensor, enable); 519 + 520 + return st_lsm6dsx_sensor_set_enable(sensor, enable); 513 521 } 514 522 515 523 static const
+4 -12
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
··· 15 15 * value of the decimation factor and ODR set for each FIFO data set. 16 16 * 17 17 * LSM6DSO/LSM6DSOX/ASM330LHH/ASM330LHHX/LSM6DSR/LSM6DSRX/ISM330DHCX/ 18 - * LSM6DST/LSM6DSOP/LSM6DSTX: 18 + * LSM6DST/LSM6DSOP/LSM6DSTX/LSM6DSV: 19 19 * The FIFO buffer can be configured to store data from gyroscope and 20 20 * accelerometer. Each sample is queued with a tag (1B) indicating data 21 21 * source (gyroscope, accelerometer, hw timer). ··· 673 673 goto out; 674 674 } 675 675 676 - if (sensor->id == ST_LSM6DSX_ID_EXT0 || 677 - sensor->id == ST_LSM6DSX_ID_EXT1 || 678 - sensor->id == ST_LSM6DSX_ID_EXT2) { 679 - err = st_lsm6dsx_shub_set_enable(sensor, enable); 680 - if (err < 0) 681 - goto out; 682 - } else { 683 - err = st_lsm6dsx_sensor_set_enable(sensor, enable); 684 - if (err < 0) 685 - goto out; 686 - } 676 + err = st_lsm6dsx_device_set_enable(sensor, enable); 677 + if (err < 0) 678 + goto out; 687 679 688 680 err = st_lsm6dsx_set_fifo_odr(sensor, enable); 689 681 if (err < 0)
+297 -36
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 34 34 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 35 35 * - FIFO size: 3KB 36 36 * 37 + * - LSM6DSV/LSM6DSV16X: 38 + * - Accelerometer/Gyroscope supported ODR [Hz]: 7.5, 15, 30, 60, 120, 240, 39 + * 480, 960 40 + * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 41 + * - Gyroscope supported full-scale [dps]: +-125/+-250/+-500/+-1000/+-2000 42 + * - FIFO size: 3KB 43 + * 37 44 * - LSM9DS1/LSM6DS0: 38 45 * - Accelerometer supported ODR [Hz]: 10, 50, 119, 238, 476, 952 39 46 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 ··· 60 53 #include <linux/iio/events.h> 61 54 #include <linux/iio/iio.h> 62 55 #include <linux/iio/sysfs.h> 56 + #include <linux/iio/triggered_buffer.h> 57 + #include <linux/iio/trigger_consumer.h> 63 58 #include <linux/interrupt.h> 64 59 #include <linux/irq.h> 65 60 #include <linux/minmax.h> ··· 1169 1160 .wakeup_src_x_mask = BIT(2), 1170 1161 }, 1171 1162 }, 1163 + { 1164 + .reset = { 1165 + .addr = 0x12, 1166 + .mask = BIT(0), 1167 + }, 1168 + .boot = { 1169 + .addr = 0x12, 1170 + .mask = BIT(7), 1171 + }, 1172 + .bdu = { 1173 + .addr = 0x12, 1174 + .mask = BIT(6), 1175 + }, 1176 + .id = { 1177 + { 1178 + .hw_id = ST_LSM6DSV_ID, 1179 + .name = ST_LSM6DSV_DEV_NAME, 1180 + .wai = 0x70, 1181 + }, { 1182 + .hw_id = ST_LSM6DSV16X_ID, 1183 + .name = ST_LSM6DSV16X_DEV_NAME, 1184 + .wai = 0x70, 1185 + }, 1186 + }, 1187 + .channels = { 1188 + [ST_LSM6DSX_ID_ACC] = { 1189 + .chan = st_lsm6dsx_acc_channels, 1190 + .len = ARRAY_SIZE(st_lsm6dsx_acc_channels), 1191 + }, 1192 + [ST_LSM6DSX_ID_GYRO] = { 1193 + .chan = st_lsm6dsx_gyro_channels, 1194 + .len = ARRAY_SIZE(st_lsm6dsx_gyro_channels), 1195 + }, 1196 + }, 1197 + .drdy_mask = { 1198 + .addr = 0x13, 1199 + .mask = BIT(3), 1200 + }, 1201 + .odr_table = { 1202 + [ST_LSM6DSX_ID_ACC] = { 1203 + .reg = { 1204 + .addr = 0x10, 1205 + .mask = GENMASK(3, 0), 1206 + }, 1207 + .odr_avl[0] = { 7500, 0x02 }, 1208 + .odr_avl[1] = { 15000, 0x03 }, 1209 + .odr_avl[2] = { 30000, 0x04 }, 1210 + .odr_avl[3] = { 60000, 0x05 }, 1211 + .odr_avl[4] = { 120000, 0x06 }, 1212 + .odr_avl[5] = { 240000, 0x07 }, 1213 + .odr_avl[6] = { 480000, 0x08 }, 1214 + .odr_avl[7] = { 960000, 0x09 }, 1215 + .odr_len = 8, 1216 + }, 1217 + [ST_LSM6DSX_ID_GYRO] = { 1218 + .reg = { 1219 + .addr = 0x11, 1220 + .mask = GENMASK(3, 0), 1221 + }, 1222 + .odr_avl[0] = { 7500, 0x02 }, 1223 + .odr_avl[1] = { 15000, 0x03 }, 1224 + .odr_avl[2] = { 30000, 0x04 }, 1225 + .odr_avl[3] = { 60000, 0x05 }, 1226 + .odr_avl[4] = { 120000, 0x06 }, 1227 + .odr_avl[5] = { 240000, 0x07 }, 1228 + .odr_avl[6] = { 480000, 0x08 }, 1229 + .odr_avl[7] = { 960000, 0x09 }, 1230 + .odr_len = 8, 1231 + }, 1232 + }, 1233 + .fs_table = { 1234 + [ST_LSM6DSX_ID_ACC] = { 1235 + .reg = { 1236 + .addr = 0x17, 1237 + .mask = GENMASK(1, 0), 1238 + }, 1239 + .fs_avl[0] = { IIO_G_TO_M_S_2(61000), 0x0 }, 1240 + .fs_avl[1] = { IIO_G_TO_M_S_2(122000), 0x1 }, 1241 + .fs_avl[2] = { IIO_G_TO_M_S_2(244000), 0x2 }, 1242 + .fs_avl[3] = { IIO_G_TO_M_S_2(488000), 0x3 }, 1243 + .fs_len = 4, 1244 + }, 1245 + [ST_LSM6DSX_ID_GYRO] = { 1246 + .reg = { 1247 + .addr = 0x15, 1248 + .mask = GENMASK(3, 0), 1249 + }, 1250 + .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750000), 0x1 }, 1251 + .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500000), 0x2 }, 1252 + .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000000), 0x3 }, 1253 + .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000000), 0x4 }, 1254 + .fs_len = 4, 1255 + }, 1256 + }, 1257 + .irq_config = { 1258 + .irq1 = { 1259 + .addr = 0x0d, 1260 + .mask = BIT(3), 1261 + }, 1262 + .irq2 = { 1263 + .addr = 0x0e, 1264 + .mask = BIT(3), 1265 + }, 1266 + .lir = { 1267 + .addr = 0x56, 1268 + .mask = BIT(0), 1269 + }, 1270 + .irq1_func = { 1271 + .addr = 0x5e, 1272 + .mask = BIT(5), 1273 + }, 1274 + .irq2_func = { 1275 + .addr = 0x5f, 1276 + .mask = BIT(5), 1277 + }, 1278 + .hla = { 1279 + .addr = 0x03, 1280 + .mask = BIT(4), 1281 + }, 1282 + .od = { 1283 + .addr = 0x03, 1284 + .mask = BIT(3), 1285 + }, 1286 + }, 1287 + .batch = { 1288 + [ST_LSM6DSX_ID_ACC] = { 1289 + .addr = 0x09, 1290 + .mask = GENMASK(3, 0), 1291 + }, 1292 + [ST_LSM6DSX_ID_GYRO] = { 1293 + .addr = 0x09, 1294 + .mask = GENMASK(7, 4), 1295 + }, 1296 + }, 1297 + .fifo_ops = { 1298 + .update_fifo = st_lsm6dsx_update_fifo, 1299 + .read_fifo = st_lsm6dsx_read_tagged_fifo, 1300 + .fifo_th = { 1301 + .addr = 0x07, 1302 + .mask = GENMASK(7, 0), 1303 + }, 1304 + .fifo_diff = { 1305 + .addr = 0x1b, 1306 + .mask = GENMASK(8, 0), 1307 + }, 1308 + .max_size = 512, 1309 + .th_wl = 1, 1310 + }, 1311 + .ts_settings = { 1312 + .timer_en = { 1313 + .addr = 0x50, 1314 + .mask = BIT(6), 1315 + }, 1316 + .decimator = { 1317 + .addr = 0x0a, 1318 + .mask = GENMASK(7, 6), 1319 + }, 1320 + .freq_fine = 0x4f, 1321 + }, 1322 + .shub_settings = { 1323 + .page_mux = { 1324 + .addr = 0x01, 1325 + .mask = BIT(6), 1326 + }, 1327 + .master_en = { 1328 + .sec_page = true, 1329 + .addr = 0x14, 1330 + .mask = BIT(2), 1331 + }, 1332 + .pullup_en = { 1333 + .addr = 0x03, 1334 + .mask = BIT(6), 1335 + }, 1336 + .aux_sens = { 1337 + .addr = 0x14, 1338 + .mask = GENMASK(1, 0), 1339 + }, 1340 + .wr_once = { 1341 + .addr = 0x14, 1342 + .mask = BIT(6), 1343 + }, 1344 + .num_ext_dev = 3, 1345 + .shub_out = { 1346 + .sec_page = true, 1347 + .addr = 0x02, 1348 + }, 1349 + .slv0_addr = 0x15, 1350 + .dw_slv0_addr = 0x21, 1351 + .batch_en = BIT(3), 1352 + }, 1353 + .event_settings = { 1354 + .enable_reg = { 1355 + .addr = 0x50, 1356 + .mask = BIT(7), 1357 + }, 1358 + .wakeup_reg = { 1359 + .addr = 0x5b, 1360 + .mask = GENMASK(5, 0), 1361 + }, 1362 + .wakeup_src_reg = 0x45, 1363 + .wakeup_src_status_mask = BIT(3), 1364 + .wakeup_src_z_mask = BIT(0), 1365 + .wakeup_src_y_mask = BIT(1), 1366 + .wakeup_src_x_mask = BIT(2), 1367 + }, 1368 + }, 1172 1369 }; 1173 1370 1174 1371 int st_lsm6dsx_set_page(struct st_lsm6dsx_hw *hw, bool enable) ··· 2332 2117 return fifo_len || event ? IRQ_HANDLED : IRQ_NONE; 2333 2118 } 2334 2119 2120 + static irqreturn_t st_lsm6dsx_sw_trigger_handler_thread(int irq, 2121 + void *private) 2122 + { 2123 + struct iio_poll_func *pf = private; 2124 + struct iio_dev *iio_dev = pf->indio_dev; 2125 + struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 2126 + struct st_lsm6dsx_hw *hw = sensor->hw; 2127 + 2128 + if (sensor->id == ST_LSM6DSX_ID_EXT0 || 2129 + sensor->id == ST_LSM6DSX_ID_EXT1 || 2130 + sensor->id == ST_LSM6DSX_ID_EXT2) 2131 + st_lsm6dsx_shub_read_output(hw, 2132 + (u8 *)hw->scan[sensor->id].channels, 2133 + sizeof(hw->scan[sensor->id].channels)); 2134 + else 2135 + st_lsm6dsx_read_locked(hw, iio_dev->channels[0].address, 2136 + hw->scan[sensor->id].channels, 2137 + sizeof(hw->scan[sensor->id].channels)); 2138 + 2139 + iio_push_to_buffers_with_timestamp(iio_dev, &hw->scan[sensor->id], 2140 + iio_get_time_ns(iio_dev)); 2141 + iio_trigger_notify_done(iio_dev->trig); 2142 + 2143 + return IRQ_HANDLED; 2144 + } 2145 + 2335 2146 static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw) 2336 2147 { 2337 2148 struct st_sensors_platform_data *pdata; ··· 2416 2175 return 0; 2417 2176 } 2418 2177 2419 - static int st_lsm6dsx_init_regulators(struct device *dev) 2178 + static int st_lsm6dsx_sw_buffer_preenable(struct iio_dev *iio_dev) 2420 2179 { 2421 - struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev); 2422 - int err; 2180 + struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 2423 2181 2424 - /* vdd-vddio power regulators */ 2425 - hw->regulators[0].supply = "vdd"; 2426 - hw->regulators[1].supply = "vddio"; 2427 - err = devm_regulator_bulk_get(dev, ARRAY_SIZE(hw->regulators), 2428 - hw->regulators); 2429 - if (err) 2430 - return dev_err_probe(dev, err, "failed to get regulators\n"); 2182 + return st_lsm6dsx_device_set_enable(sensor, true); 2183 + } 2431 2184 2432 - err = regulator_bulk_enable(ARRAY_SIZE(hw->regulators), 2433 - hw->regulators); 2434 - if (err) { 2435 - dev_err(dev, "failed to enable regulators: %d\n", err); 2436 - return err; 2185 + static int st_lsm6dsx_sw_buffer_postdisable(struct iio_dev *iio_dev) 2186 + { 2187 + struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 2188 + 2189 + return st_lsm6dsx_device_set_enable(sensor, false); 2190 + } 2191 + 2192 + static const struct iio_buffer_setup_ops st_lsm6dsx_sw_buffer_ops = { 2193 + .preenable = st_lsm6dsx_sw_buffer_preenable, 2194 + .postdisable = st_lsm6dsx_sw_buffer_postdisable, 2195 + }; 2196 + 2197 + static int st_lsm6dsx_sw_buffers_setup(struct st_lsm6dsx_hw *hw) 2198 + { 2199 + int i; 2200 + 2201 + for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 2202 + int err; 2203 + 2204 + if (!hw->iio_devs[i]) 2205 + continue; 2206 + 2207 + err = devm_iio_triggered_buffer_setup(hw->dev, 2208 + hw->iio_devs[i], NULL, 2209 + st_lsm6dsx_sw_trigger_handler_thread, 2210 + &st_lsm6dsx_sw_buffer_ops); 2211 + if (err) 2212 + return err; 2437 2213 } 2438 - 2439 - msleep(50); 2440 2214 2441 2215 return 0; 2442 2216 } 2443 2217 2444 - static void st_lsm6dsx_chip_uninit(void *data) 2218 + static int st_lsm6dsx_init_regulators(struct device *dev) 2445 2219 { 2446 - struct st_lsm6dsx_hw *hw = data; 2220 + /* vdd-vddio power regulators */ 2221 + static const char * const regulators[] = { "vdd", "vddio" }; 2222 + int err; 2447 2223 2448 - regulator_bulk_disable(ARRAY_SIZE(hw->regulators), hw->regulators); 2224 + err = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), 2225 + regulators); 2226 + if (err) 2227 + return dev_err_probe(dev, err, "failed to enable regulators\n"); 2228 + 2229 + msleep(50); 2230 + 2231 + return 0; 2449 2232 } 2450 2233 2451 2234 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, ··· 2492 2227 mutex_init(&hw->page_lock); 2493 2228 2494 2229 err = st_lsm6dsx_init_regulators(dev); 2495 - if (err) 2496 - return err; 2497 - 2498 - err = devm_add_action_or_reset(dev, st_lsm6dsx_chip_uninit, hw); 2499 2230 if (err) 2500 2231 return err; 2501 2232 ··· 2533 2272 2534 2273 err = st_lsm6dsx_fifo_setup(hw); 2535 2274 if (err < 0) 2275 + return err; 2276 + } 2277 + 2278 + if (!hw->irq || !hw->settings->fifo_ops.read_fifo) { 2279 + /* 2280 + * Rely on sw triggers (e.g. hr-timers) if irq pin is not 2281 + * connected of if the device does not support HW FIFO 2282 + */ 2283 + err = st_lsm6dsx_sw_buffers_setup(hw); 2284 + if (err) 2536 2285 return err; 2537 2286 } 2538 2287 ··· 2588 2317 continue; 2589 2318 } 2590 2319 2591 - if (sensor->id == ST_LSM6DSX_ID_EXT0 || 2592 - sensor->id == ST_LSM6DSX_ID_EXT1 || 2593 - sensor->id == ST_LSM6DSX_ID_EXT2) 2594 - err = st_lsm6dsx_shub_set_enable(sensor, false); 2595 - else 2596 - err = st_lsm6dsx_sensor_set_enable(sensor, false); 2320 + err = st_lsm6dsx_device_set_enable(sensor, false); 2597 2321 if (err < 0) 2598 2322 return err; 2599 2323 ··· 2619 2353 if (!(hw->suspend_mask & BIT(sensor->id))) 2620 2354 continue; 2621 2355 2622 - if (sensor->id == ST_LSM6DSX_ID_EXT0 || 2623 - sensor->id == ST_LSM6DSX_ID_EXT1 || 2624 - sensor->id == ST_LSM6DSX_ID_EXT2) 2625 - err = st_lsm6dsx_shub_set_enable(sensor, true); 2626 - else 2627 - err = st_lsm6dsx_sensor_set_enable(sensor, true); 2356 + err = st_lsm6dsx_device_set_enable(sensor, true); 2628 2357 if (err < 0) 2629 2358 return err; 2630 2359
+10
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
··· 109 109 .compatible = "st,lsm6dstx", 110 110 .data = (void *)ST_LSM6DSTX_ID, 111 111 }, 112 + { 113 + .compatible = "st,lsm6dsv", 114 + .data = (void *)ST_LSM6DSV_ID, 115 + }, 116 + { 117 + .compatible = "st,lsm6dsv16x", 118 + .data = (void *)ST_LSM6DSV16X_ID, 119 + }, 112 120 {}, 113 121 }; 114 122 MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match); ··· 140 132 { ST_LSM6DSOP_DEV_NAME, ST_LSM6DSOP_ID }, 141 133 { ST_ASM330LHHX_DEV_NAME, ST_ASM330LHHX_ID }, 142 134 { ST_LSM6DSTX_DEV_NAME, ST_LSM6DSTX_ID }, 135 + { ST_LSM6DSV_DEV_NAME, ST_LSM6DSV_ID }, 136 + { ST_LSM6DSV16X_DEV_NAME, ST_LSM6DSV16X_ID }, 143 137 {}, 144 138 }; 145 139 MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
+1 -3
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
··· 170 170 * 171 171 * Read st_lsm6dsx i2c controller register 172 172 */ 173 - static int 174 - st_lsm6dsx_shub_read_output(struct st_lsm6dsx_hw *hw, u8 *data, 175 - int len) 173 + int st_lsm6dsx_shub_read_output(struct st_lsm6dsx_hw *hw, u8 *data, int len) 176 174 { 177 175 const struct st_lsm6dsx_shub_settings *hub_settings; 178 176 int err;
+10
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
··· 109 109 .compatible = "st,lsm6dstx", 110 110 .data = (void *)ST_LSM6DSTX_ID, 111 111 }, 112 + { 113 + .compatible = "st,lsm6dsv", 114 + .data = (void *)ST_LSM6DSV_ID, 115 + }, 116 + { 117 + .compatible = "st,lsm6dsv16x", 118 + .data = (void *)ST_LSM6DSV16X_ID, 119 + }, 112 120 {}, 113 121 }; 114 122 MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match); ··· 140 132 { ST_LSM6DSOP_DEV_NAME, ST_LSM6DSOP_ID }, 141 133 { ST_ASM330LHHX_DEV_NAME, ST_ASM330LHHX_ID }, 142 134 { ST_LSM6DSTX_DEV_NAME, ST_LSM6DSTX_ID }, 135 + { ST_LSM6DSV_DEV_NAME, ST_LSM6DSV_ID }, 136 + { ST_LSM6DSV16X_DEV_NAME, ST_LSM6DSV16X_ID }, 143 137 {}, 144 138 }; 145 139 MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
+7 -58
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_core.c
··· 18 18 19 19 #include "st_lsm9ds0.h" 20 20 21 - static int st_lsm9ds0_power_enable(struct device *dev, struct st_lsm9ds0 *lsm9ds0) 22 - { 23 - int ret; 24 - 25 - /* Regulators not mandatory, but if requested we should enable them. */ 26 - lsm9ds0->vdd = devm_regulator_get(dev, "vdd"); 27 - if (IS_ERR(lsm9ds0->vdd)) 28 - return dev_err_probe(dev, PTR_ERR(lsm9ds0->vdd), 29 - "unable to get Vdd supply\n"); 30 - 31 - ret = regulator_enable(lsm9ds0->vdd); 32 - if (ret) { 33 - dev_warn(dev, "Failed to enable specified Vdd supply\n"); 34 - return ret; 35 - } 36 - 37 - lsm9ds0->vdd_io = devm_regulator_get(dev, "vddio"); 38 - if (IS_ERR(lsm9ds0->vdd_io)) { 39 - regulator_disable(lsm9ds0->vdd); 40 - return dev_err_probe(dev, PTR_ERR(lsm9ds0->vdd_io), 41 - "unable to get Vdd_IO supply\n"); 42 - } 43 - ret = regulator_enable(lsm9ds0->vdd_io); 44 - if (ret) { 45 - dev_warn(dev, "Failed to enable specified Vdd_IO supply\n"); 46 - regulator_disable(lsm9ds0->vdd); 47 - return ret; 48 - } 49 - 50 - return 0; 51 - } 52 - 53 - static void st_lsm9ds0_power_disable(void *data) 54 - { 55 - struct st_lsm9ds0 *lsm9ds0 = data; 56 - 57 - regulator_disable(lsm9ds0->vdd_io); 58 - regulator_disable(lsm9ds0->vdd); 59 - } 60 - 61 - static int devm_st_lsm9ds0_power_enable(struct st_lsm9ds0 *lsm9ds0) 62 - { 63 - struct device *dev = lsm9ds0->dev; 64 - int ret; 65 - 66 - ret = st_lsm9ds0_power_enable(dev, lsm9ds0); 67 - if (ret) 68 - return ret; 69 - 70 - return devm_add_action_or_reset(dev, st_lsm9ds0_power_disable, lsm9ds0); 71 - } 72 - 73 21 static int st_lsm9ds0_probe_accel(struct st_lsm9ds0 *lsm9ds0, struct regmap *regmap) 74 22 { 75 23 const struct st_sensor_settings *settings; ··· 40 92 data->sensor_settings = (struct st_sensor_settings *)settings; 41 93 data->irq = lsm9ds0->irq; 42 94 data->regmap = regmap; 43 - data->vdd = lsm9ds0->vdd; 44 - data->vdd_io = lsm9ds0->vdd_io; 45 95 46 96 return st_accel_common_probe(lsm9ds0->accel); 47 97 } ··· 66 120 data->sensor_settings = (struct st_sensor_settings *)settings; 67 121 data->irq = lsm9ds0->irq; 68 122 data->regmap = regmap; 69 - data->vdd = lsm9ds0->vdd; 70 - data->vdd_io = lsm9ds0->vdd_io; 71 123 72 124 return st_magn_common_probe(lsm9ds0->magn); 73 125 } 74 126 75 127 int st_lsm9ds0_probe(struct st_lsm9ds0 *lsm9ds0, struct regmap *regmap) 76 128 { 129 + struct device *dev = lsm9ds0->dev; 130 + static const char * const regulator_names[] = { "vdd", "vddio" }; 77 131 int ret; 78 132 79 - ret = devm_st_lsm9ds0_power_enable(lsm9ds0); 133 + /* Regulators not mandatory, but if requested we should enable them. */ 134 + ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names), 135 + regulator_names); 80 136 if (ret) 81 - return ret; 137 + return dev_err_probe(dev, ret, 138 + "unable to enable Vdd supply\n"); 82 139 83 140 /* Setup accelerometer device */ 84 141 ret = st_lsm9ds0_probe_accel(lsm9ds0, regmap);
+24 -16
drivers/iio/industrialio-buffer.c
··· 507 507 int ret; 508 508 bool state; 509 509 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 510 + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 510 511 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 511 512 struct iio_buffer *buffer = this_attr->buffer; 512 513 513 514 ret = kstrtobool(buf, &state); 514 515 if (ret < 0) 515 516 return ret; 516 - mutex_lock(&indio_dev->mlock); 517 + mutex_lock(&iio_dev_opaque->mlock); 517 518 if (iio_buffer_is_active(buffer)) { 518 519 ret = -EBUSY; 519 520 goto error_ret; ··· 533 532 } 534 533 535 534 error_ret: 536 - mutex_unlock(&indio_dev->mlock); 535 + mutex_unlock(&iio_dev_opaque->mlock); 537 536 538 537 return ret < 0 ? ret : len; 539 538 ··· 555 554 { 556 555 int ret; 557 556 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 557 + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 558 558 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 559 559 bool state; 560 560 ··· 563 561 if (ret < 0) 564 562 return ret; 565 563 566 - mutex_lock(&indio_dev->mlock); 564 + mutex_lock(&iio_dev_opaque->mlock); 567 565 if (iio_buffer_is_active(buffer)) { 568 566 ret = -EBUSY; 569 567 goto error_ret; 570 568 } 571 569 buffer->scan_timestamp = state; 572 570 error_ret: 573 - mutex_unlock(&indio_dev->mlock); 571 + mutex_unlock(&iio_dev_opaque->mlock); 574 572 575 573 return ret ? ret : len; 576 574 } ··· 644 642 const char *buf, size_t len) 645 643 { 646 644 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 645 + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 647 646 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 648 647 unsigned int val; 649 648 int ret; ··· 656 653 if (val == buffer->length) 657 654 return len; 658 655 659 - mutex_lock(&indio_dev->mlock); 656 + mutex_lock(&iio_dev_opaque->mlock); 660 657 if (iio_buffer_is_active(buffer)) { 661 658 ret = -EBUSY; 662 659 } else { ··· 668 665 if (buffer->length && buffer->length < buffer->watermark) 669 666 buffer->watermark = buffer->length; 670 667 out: 671 - mutex_unlock(&indio_dev->mlock); 668 + mutex_unlock(&iio_dev_opaque->mlock); 672 669 673 670 return ret ? ret : len; 674 671 } ··· 1259 1256 return -EINVAL; 1260 1257 1261 1258 mutex_lock(&iio_dev_opaque->info_exist_lock); 1262 - mutex_lock(&indio_dev->mlock); 1259 + mutex_lock(&iio_dev_opaque->mlock); 1263 1260 1264 1261 if (insert_buffer && iio_buffer_is_active(insert_buffer)) 1265 1262 insert_buffer = NULL; ··· 1280 1277 ret = __iio_update_buffers(indio_dev, insert_buffer, remove_buffer); 1281 1278 1282 1279 out_unlock: 1283 - mutex_unlock(&indio_dev->mlock); 1280 + mutex_unlock(&iio_dev_opaque->mlock); 1284 1281 mutex_unlock(&iio_dev_opaque->info_exist_lock); 1285 1282 1286 1283 return ret; ··· 1299 1296 int ret; 1300 1297 bool requested_state; 1301 1298 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1299 + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 1302 1300 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 1303 1301 bool inlist; 1304 1302 ··· 1307 1303 if (ret < 0) 1308 1304 return ret; 1309 1305 1310 - mutex_lock(&indio_dev->mlock); 1306 + mutex_lock(&iio_dev_opaque->mlock); 1311 1307 1312 1308 /* Find out if it is in the list */ 1313 1309 inlist = iio_buffer_is_active(buffer); ··· 1321 1317 ret = __iio_update_buffers(indio_dev, NULL, buffer); 1322 1318 1323 1319 done: 1324 - mutex_unlock(&indio_dev->mlock); 1320 + mutex_unlock(&iio_dev_opaque->mlock); 1325 1321 return (ret < 0) ? ret : len; 1326 1322 } 1327 1323 ··· 1338 1334 const char *buf, size_t len) 1339 1335 { 1340 1336 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1337 + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 1341 1338 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 1342 1339 unsigned int val; 1343 1340 int ret; ··· 1349 1344 if (!val) 1350 1345 return -EINVAL; 1351 1346 1352 - mutex_lock(&indio_dev->mlock); 1347 + mutex_lock(&iio_dev_opaque->mlock); 1353 1348 1354 1349 if (val > buffer->length) { 1355 1350 ret = -EINVAL; ··· 1363 1358 1364 1359 buffer->watermark = val; 1365 1360 out: 1366 - mutex_unlock(&indio_dev->mlock); 1361 + mutex_unlock(&iio_dev_opaque->mlock); 1367 1362 1368 1363 return ret ? ret : len; 1369 1364 } ··· 1605 1600 { 1606 1601 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 1607 1602 struct iio_dev_attr *p; 1603 + const struct iio_dev_attr *id_attr; 1608 1604 struct attribute **attr; 1609 1605 int ret, i, attrn, scan_el_attrcount, buffer_attrcount; 1610 1606 const struct iio_chan_spec *channels; ··· 1615 1609 while (buffer->attrs[buffer_attrcount] != NULL) 1616 1610 buffer_attrcount++; 1617 1611 } 1612 + buffer_attrcount += ARRAY_SIZE(iio_buffer_attrs); 1618 1613 1619 1614 scan_el_attrcount = 0; 1620 1615 INIT_LIST_HEAD(&buffer->buffer_attr_list); ··· 1658 1651 } 1659 1652 } 1660 1653 1661 - attrn = buffer_attrcount + scan_el_attrcount + ARRAY_SIZE(iio_buffer_attrs); 1654 + attrn = buffer_attrcount + scan_el_attrcount; 1662 1655 attr = kcalloc(attrn + 1, sizeof(*attr), GFP_KERNEL); 1663 1656 if (!attr) { 1664 1657 ret = -ENOMEM; ··· 1673 1666 attr[2] = &dev_attr_watermark_ro.attr; 1674 1667 1675 1668 if (buffer->attrs) 1676 - memcpy(&attr[ARRAY_SIZE(iio_buffer_attrs)], buffer->attrs, 1677 - sizeof(struct attribute *) * buffer_attrcount); 1669 + for (i = 0, id_attr = buffer->attrs[i]; 1670 + (id_attr = buffer->attrs[i]); i++) 1671 + attr[ARRAY_SIZE(iio_buffer_attrs) + i] = 1672 + (struct attribute *)&id_attr->dev_attr.attr; 1678 1673 1679 - buffer_attrcount += ARRAY_SIZE(iio_buffer_attrs); 1680 1674 buffer->buffer_group.attrs = attr; 1681 1675 1682 1676 for (i = 0; i < buffer_attrcount; i++) {
+50 -8
drivers/iio/industrialio-core.c
··· 285 285 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 286 286 const struct iio_event_interface *ev_int = iio_dev_opaque->event_interface; 287 287 288 - ret = mutex_lock_interruptible(&indio_dev->mlock); 288 + ret = mutex_lock_interruptible(&iio_dev_opaque->mlock); 289 289 if (ret) 290 290 return ret; 291 291 if ((ev_int && iio_event_enabled(ev_int)) || 292 292 iio_buffer_enabled(indio_dev)) { 293 - mutex_unlock(&indio_dev->mlock); 293 + mutex_unlock(&iio_dev_opaque->mlock); 294 294 return -EBUSY; 295 295 } 296 296 iio_dev_opaque->clock_id = clock_id; 297 - mutex_unlock(&indio_dev->mlock); 297 + mutex_unlock(&iio_dev_opaque->mlock); 298 298 299 299 return 0; 300 300 } ··· 1674 1674 indio_dev->dev.type = &iio_device_type; 1675 1675 indio_dev->dev.bus = &iio_bus_type; 1676 1676 device_initialize(&indio_dev->dev); 1677 - mutex_init(&indio_dev->mlock); 1677 + mutex_init(&iio_dev_opaque->mlock); 1678 1678 mutex_init(&iio_dev_opaque->info_exist_lock); 1679 1679 INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list); 1680 1680 ··· 1696 1696 INIT_LIST_HEAD(&iio_dev_opaque->ioctl_handlers); 1697 1697 1698 1698 lockdep_register_key(&iio_dev_opaque->mlock_key); 1699 - lockdep_set_class(&indio_dev->mlock, &iio_dev_opaque->mlock_key); 1699 + lockdep_set_class(&iio_dev_opaque->mlock, &iio_dev_opaque->mlock_key); 1700 1700 1701 1701 return indio_dev; 1702 1702 } ··· 2058 2058 */ 2059 2059 int iio_device_claim_direct_mode(struct iio_dev *indio_dev) 2060 2060 { 2061 - mutex_lock(&indio_dev->mlock); 2061 + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 2062 + 2063 + mutex_lock(&iio_dev_opaque->mlock); 2062 2064 2063 2065 if (iio_buffer_enabled(indio_dev)) { 2064 - mutex_unlock(&indio_dev->mlock); 2066 + mutex_unlock(&iio_dev_opaque->mlock); 2065 2067 return -EBUSY; 2066 2068 } 2067 2069 return 0; ··· 2081 2079 */ 2082 2080 void iio_device_release_direct_mode(struct iio_dev *indio_dev) 2083 2081 { 2084 - mutex_unlock(&indio_dev->mlock); 2082 + mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); 2085 2083 } 2086 2084 EXPORT_SYMBOL_GPL(iio_device_release_direct_mode); 2085 + 2086 + /** 2087 + * iio_device_claim_buffer_mode - Keep device in buffer mode 2088 + * @indio_dev: the iio_dev associated with the device 2089 + * 2090 + * If the device is in buffer mode it is guaranteed to stay 2091 + * that way until iio_device_release_buffer_mode() is called. 2092 + * 2093 + * Use with iio_device_release_buffer_mode(). 2094 + * 2095 + * Returns: 0 on success, -EBUSY on failure. 2096 + */ 2097 + int iio_device_claim_buffer_mode(struct iio_dev *indio_dev) 2098 + { 2099 + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 2100 + 2101 + mutex_lock(&iio_dev_opaque->mlock); 2102 + 2103 + if (iio_buffer_enabled(indio_dev)) 2104 + return 0; 2105 + 2106 + mutex_unlock(&iio_dev_opaque->mlock); 2107 + return -EBUSY; 2108 + } 2109 + EXPORT_SYMBOL_GPL(iio_device_claim_buffer_mode); 2110 + 2111 + /** 2112 + * iio_device_release_buffer_mode - releases claim on buffer mode 2113 + * @indio_dev: the iio_dev associated with the device 2114 + * 2115 + * Release the claim. Device is no longer guaranteed to stay 2116 + * in buffer mode. 2117 + * 2118 + * Use with iio_device_claim_buffer_mode(). 2119 + */ 2120 + void iio_device_release_buffer_mode(struct iio_dev *indio_dev) 2121 + { 2122 + mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); 2123 + } 2124 + EXPORT_SYMBOL_GPL(iio_device_release_buffer_mode); 2087 2125 2088 2126 /** 2089 2127 * iio_device_get_current_mode() - helper function providing read-only access to
+2 -2
drivers/iio/industrialio-event.c
··· 198 198 if (ev_int == NULL) 199 199 return -ENODEV; 200 200 201 - fd = mutex_lock_interruptible(&indio_dev->mlock); 201 + fd = mutex_lock_interruptible(&iio_dev_opaque->mlock); 202 202 if (fd) 203 203 return fd; 204 204 ··· 219 219 } 220 220 221 221 unlock: 222 - mutex_unlock(&indio_dev->mlock); 222 + mutex_unlock(&iio_dev_opaque->mlock); 223 223 return fd; 224 224 } 225 225
+6 -6
drivers/iio/industrialio-trigger.c
··· 120 120 return -EINVAL; 121 121 122 122 iio_dev_opaque = to_iio_dev_opaque(indio_dev); 123 - mutex_lock(&indio_dev->mlock); 123 + mutex_lock(&iio_dev_opaque->mlock); 124 124 WARN_ON(iio_dev_opaque->trig_readonly); 125 125 126 126 indio_dev->trig = iio_trigger_get(trig); 127 127 iio_dev_opaque->trig_readonly = true; 128 - mutex_unlock(&indio_dev->mlock); 128 + mutex_unlock(&iio_dev_opaque->mlock); 129 129 130 130 return 0; 131 131 } ··· 438 438 struct iio_trigger *trig; 439 439 int ret; 440 440 441 - mutex_lock(&indio_dev->mlock); 441 + mutex_lock(&iio_dev_opaque->mlock); 442 442 if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) { 443 - mutex_unlock(&indio_dev->mlock); 443 + mutex_unlock(&iio_dev_opaque->mlock); 444 444 return -EBUSY; 445 445 } 446 446 if (iio_dev_opaque->trig_readonly) { 447 - mutex_unlock(&indio_dev->mlock); 447 + mutex_unlock(&iio_dev_opaque->mlock); 448 448 return -EPERM; 449 449 } 450 - mutex_unlock(&indio_dev->mlock); 450 + mutex_unlock(&iio_dev_opaque->mlock); 451 451 452 452 trig = iio_trigger_acquire_by_name(buf); 453 453 if (oldtrig == trig) {
+12 -8
drivers/iio/light/apds9960.c
··· 223 223 { 224 224 .type = IIO_EV_TYPE_THRESH, 225 225 .dir = IIO_EV_DIR_RISING, 226 - .mask_separate = BIT(IIO_EV_INFO_VALUE) | 227 - BIT(IIO_EV_INFO_ENABLE), 226 + .mask_separate = BIT(IIO_EV_INFO_VALUE), 228 227 }, 229 228 { 230 229 .type = IIO_EV_TYPE_THRESH, 231 230 .dir = IIO_EV_DIR_FALLING, 232 - .mask_separate = BIT(IIO_EV_INFO_VALUE) | 233 - BIT(IIO_EV_INFO_ENABLE), 231 + .mask_separate = BIT(IIO_EV_INFO_VALUE), 232 + }, 233 + { 234 + .type = IIO_EV_TYPE_THRESH, 235 + .mask_separate = BIT(IIO_EV_INFO_ENABLE), 234 236 }, 235 237 }; 236 238 ··· 240 238 { 241 239 .type = IIO_EV_TYPE_THRESH, 242 240 .dir = IIO_EV_DIR_RISING, 243 - .mask_separate = BIT(IIO_EV_INFO_VALUE) | 244 - BIT(IIO_EV_INFO_ENABLE), 241 + .mask_separate = BIT(IIO_EV_INFO_VALUE), 245 242 }, 246 243 { 247 244 .type = IIO_EV_TYPE_THRESH, 248 245 .dir = IIO_EV_DIR_FALLING, 249 - .mask_separate = BIT(IIO_EV_INFO_VALUE) | 250 - BIT(IIO_EV_INFO_ENABLE), 246 + .mask_separate = BIT(IIO_EV_INFO_VALUE), 247 + }, 248 + { 249 + .type = IIO_EV_TYPE_THRESH, 250 + .mask_separate = BIT(IIO_EV_INFO_ENABLE), 251 251 }, 252 252 }; 253 253
+4 -23
drivers/iio/light/ltr501.c
··· 153 153 154 154 struct ltr501_data { 155 155 struct i2c_client *client; 156 - struct regulator_bulk_data regulators[2]; 157 156 struct mutex lock_als, lock_ps; 158 157 const struct ltr501_chip_info *chip_info; 159 158 u8 als_contr, ps_contr; ··· 1414 1415 .volatile_reg = ltr501_is_volatile_reg, 1415 1416 }; 1416 1417 1417 - static void ltr501_disable_regulators(void *d) 1418 - { 1419 - struct ltr501_data *data = d; 1420 - 1421 - regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); 1422 - } 1423 - 1424 1418 static int ltr501_powerdown(struct ltr501_data *data) 1425 1419 { 1426 1420 return ltr501_write_contr(data, data->als_contr & ··· 1435 1443 static int ltr501_probe(struct i2c_client *client, 1436 1444 const struct i2c_device_id *id) 1437 1445 { 1446 + static const char * const regulator_names[] = { "vdd", "vddio" }; 1438 1447 struct ltr501_data *data; 1439 1448 struct iio_dev *indio_dev; 1440 1449 struct regmap *regmap; ··· 1459 1466 mutex_init(&data->lock_als); 1460 1467 mutex_init(&data->lock_ps); 1461 1468 1462 - data->regulators[0].supply = "vdd"; 1463 - data->regulators[1].supply = "vddio"; 1464 - ret = devm_regulator_bulk_get(&client->dev, 1465 - ARRAY_SIZE(data->regulators), 1466 - data->regulators); 1469 + ret = devm_regulator_bulk_get_enable(&client->dev, 1470 + ARRAY_SIZE(regulator_names), 1471 + regulator_names); 1467 1472 if (ret) 1468 1473 return dev_err_probe(&client->dev, ret, 1469 1474 "Failed to get regulators\n"); 1470 - 1471 - ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators), 1472 - data->regulators); 1473 - if (ret) 1474 - return ret; 1475 - 1476 - ret = devm_add_action_or_reset(&client->dev, 1477 - ltr501_disable_regulators, data); 1478 - if (ret) 1479 - return ret; 1480 1475 1481 1476 data->reg_it = devm_regmap_field_alloc(&client->dev, regmap, 1482 1477 reg_field_it);
+3 -23
drivers/iio/light/noa1305.c
··· 46 46 struct noa1305_priv { 47 47 struct i2c_client *client; 48 48 struct regmap *regmap; 49 - struct regulator *vin_reg; 50 49 }; 51 50 52 51 static int noa1305_measure(struct noa1305_priv *priv) ··· 186 187 .writeable_reg = noa1305_writable_reg, 187 188 }; 188 189 189 - static void noa1305_reg_remove(void *data) 190 - { 191 - struct noa1305_priv *priv = data; 192 - 193 - regulator_disable(priv->vin_reg); 194 - } 195 - 196 190 static int noa1305_probe(struct i2c_client *client, 197 191 const struct i2c_device_id *id) 198 192 { ··· 208 216 209 217 priv = iio_priv(indio_dev); 210 218 211 - priv->vin_reg = devm_regulator_get(&client->dev, "vin"); 212 - if (IS_ERR(priv->vin_reg)) 213 - return dev_err_probe(&client->dev, PTR_ERR(priv->vin_reg), 219 + ret = devm_regulator_get_enable(&client->dev, "vin"); 220 + if (ret) 221 + return dev_err_probe(&client->dev, ret, 214 222 "get regulator vin failed\n"); 215 - 216 - ret = regulator_enable(priv->vin_reg); 217 - if (ret) { 218 - dev_err(&client->dev, "enable regulator vin failed\n"); 219 - return ret; 220 - } 221 - 222 - ret = devm_add_action_or_reset(&client->dev, noa1305_reg_remove, priv); 223 - if (ret) { 224 - dev_err(&client->dev, "addition of devm action failed\n"); 225 - return ret; 226 - } 227 223 228 224 i2c_set_clientdata(client, indio_dev); 229 225 priv->client = client;
+180 -7
drivers/iio/light/vcnl4000.c
··· 17 17 * interrupts (VCNL4040, VCNL4200) 18 18 */ 19 19 20 + #include <linux/bitfield.h> 20 21 #include <linux/module.h> 21 22 #include <linux/i2c.h> 22 23 #include <linux/err.h> ··· 75 74 #define VCNL4000_PROX_EN BIT(1) /* start proximity measurement */ 76 75 #define VCNL4000_SELF_TIMED_EN BIT(0) /* start self-timed measurement */ 77 76 77 + #define VCNL4040_ALS_CONF_ALS_SHUTDOWN BIT(0) 78 + #define VCNL4040_PS_CONF1_PS_SHUTDOWN BIT(0) 79 + #define VCNL4040_PS_CONF2_PS_IT GENMASK(3, 1) /* Proximity integration time */ 80 + 78 81 /* Bit masks for interrupt registers. */ 79 82 #define VCNL4010_INT_THR_SEL BIT(0) /* Select threshold interrupt source */ 80 83 #define VCNL4010_INT_THR_EN BIT(1) /* Threshold interrupt type */ ··· 104 99 {62, 500000}, 105 100 {125, 0}, 106 101 {250, 0}, 102 + }; 103 + 104 + static const int vcnl4040_ps_it_times[][2] = { 105 + {0, 100}, 106 + {0, 150}, 107 + {0, 200}, 108 + {0, 250}, 109 + {0, 300}, 110 + {0, 350}, 111 + {0, 400}, 112 + {0, 800}, 107 113 }; 108 114 109 115 #define VCNL4000_SLEEP_DELAY_MS 2000 /* before we enter pm_runtime_suspend */ ··· 204 188 return data->chip_spec->set_power_state(data, true); 205 189 }; 206 190 207 - static int vcnl4200_set_power_state(struct vcnl4000_data *data, bool on) 191 + static ssize_t vcnl4000_write_als_enable(struct vcnl4000_data *data, bool en) 208 192 { 209 - u16 val = on ? 0 /* power on */ : 1 /* shut down */; 210 193 int ret; 211 194 212 - ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, val); 195 + mutex_lock(&data->vcnl4000_lock); 196 + 197 + ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF); 198 + if (ret < 0) 199 + goto out; 200 + 201 + if (en) 202 + ret &= ~VCNL4040_ALS_CONF_ALS_SHUTDOWN; 203 + else 204 + ret |= VCNL4040_ALS_CONF_ALS_SHUTDOWN; 205 + 206 + ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, ret); 207 + 208 + out: 209 + mutex_unlock(&data->vcnl4000_lock); 210 + 211 + return ret; 212 + } 213 + 214 + static ssize_t vcnl4000_write_ps_enable(struct vcnl4000_data *data, bool en) 215 + { 216 + int ret; 217 + 218 + mutex_lock(&data->vcnl4000_lock); 219 + 220 + ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); 221 + if (ret < 0) 222 + goto out; 223 + 224 + if (en) 225 + ret &= ~VCNL4040_PS_CONF1_PS_SHUTDOWN; 226 + else 227 + ret |= VCNL4040_PS_CONF1_PS_SHUTDOWN; 228 + 229 + ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, ret); 230 + 231 + out: 232 + mutex_unlock(&data->vcnl4000_lock); 233 + 234 + return ret; 235 + } 236 + 237 + static int vcnl4200_set_power_state(struct vcnl4000_data *data, bool on) 238 + { 239 + int ret; 240 + 241 + ret = vcnl4000_write_als_enable(data, on); 213 242 if (ret < 0) 214 243 return ret; 215 244 216 - ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, val); 245 + ret = vcnl4000_write_ps_enable(data, on); 217 246 if (ret < 0) 218 247 return ret; 219 248 ··· 483 422 return ret; 484 423 } 485 424 425 + static int vcnl4040_read_ps_it(struct vcnl4000_data *data, int *val, int *val2) 426 + { 427 + int ret; 428 + 429 + ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); 430 + if (ret < 0) 431 + return ret; 432 + 433 + ret = FIELD_GET(VCNL4040_PS_CONF2_PS_IT, ret); 434 + 435 + if (ret >= ARRAY_SIZE(vcnl4040_ps_it_times)) 436 + return -EINVAL; 437 + 438 + *val = vcnl4040_ps_it_times[ret][0]; 439 + *val2 = vcnl4040_ps_it_times[ret][1]; 440 + 441 + return 0; 442 + } 443 + 444 + static ssize_t vcnl4040_write_ps_it(struct vcnl4000_data *data, int val) 445 + { 446 + unsigned int i; 447 + int ret, index = -1; 448 + u16 regval; 449 + 450 + for (i = 0; i < ARRAY_SIZE(vcnl4040_ps_it_times); i++) { 451 + if (val == vcnl4040_ps_it_times[i][1]) { 452 + index = i; 453 + break; 454 + } 455 + } 456 + 457 + if (index < 0) 458 + return -EINVAL; 459 + 460 + mutex_lock(&data->vcnl4000_lock); 461 + 462 + ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); 463 + if (ret < 0) 464 + goto out; 465 + 466 + regval = (ret & ~VCNL4040_PS_CONF2_PS_IT) | 467 + FIELD_PREP(VCNL4040_PS_CONF2_PS_IT, index); 468 + ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, 469 + regval); 470 + 471 + out: 472 + mutex_unlock(&data->vcnl4000_lock); 473 + return ret; 474 + } 475 + 486 476 static int vcnl4000_read_raw(struct iio_dev *indio_dev, 487 477 struct iio_chan_spec const *chan, 488 478 int *val, int *val2, long mask) ··· 570 458 *val = 0; 571 459 *val2 = data->al_scale; 572 460 return IIO_VAL_INT_PLUS_MICRO; 461 + case IIO_CHAN_INFO_INT_TIME: 462 + if (chan->type != IIO_PROXIMITY) 463 + return -EINVAL; 464 + ret = vcnl4040_read_ps_it(data, val, val2); 465 + if (ret < 0) 466 + return ret; 467 + return IIO_VAL_INT_PLUS_MICRO; 468 + default: 469 + return -EINVAL; 470 + } 471 + } 472 + 473 + static int vcnl4040_write_raw(struct iio_dev *indio_dev, 474 + struct iio_chan_spec const *chan, 475 + int val, int val2, long mask) 476 + { 477 + struct vcnl4000_data *data = iio_priv(indio_dev); 478 + 479 + switch (mask) { 480 + case IIO_CHAN_INFO_INT_TIME: 481 + if (val != 0) 482 + return -EINVAL; 483 + if (chan->type != IIO_PROXIMITY) 484 + return -EINVAL; 485 + return vcnl4040_write_ps_it(data, val2); 486 + default: 487 + return -EINVAL; 488 + } 489 + } 490 + 491 + static int vcnl4040_read_avail(struct iio_dev *indio_dev, 492 + struct iio_chan_spec const *chan, 493 + const int **vals, int *type, int *length, 494 + long mask) 495 + { 496 + switch (mask) { 497 + case IIO_CHAN_INFO_INT_TIME: 498 + *vals = (int *)vcnl4040_ps_it_times; 499 + *type = IIO_VAL_INT_PLUS_MICRO; 500 + *length = 2 * ARRAY_SIZE(vcnl4040_ps_it_times); 501 + return IIO_AVAIL_LIST; 573 502 default: 574 503 return -EINVAL; 575 504 } ··· 949 796 IIO_CHAN_SOFT_TIMESTAMP(1), 950 797 }; 951 798 799 + static const struct iio_chan_spec vcnl4040_channels[] = { 800 + { 801 + .type = IIO_LIGHT, 802 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 803 + BIT(IIO_CHAN_INFO_SCALE), 804 + }, { 805 + .type = IIO_PROXIMITY, 806 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 807 + BIT(IIO_CHAN_INFO_INT_TIME), 808 + .info_mask_separate_available = BIT(IIO_CHAN_INFO_INT_TIME), 809 + .ext_info = vcnl4000_ext_info, 810 + } 811 + }; 812 + 952 813 static const struct iio_info vcnl4000_info = { 953 814 .read_raw = vcnl4000_read_raw, 954 815 }; ··· 975 808 .write_event_value = vcnl4010_write_event, 976 809 .read_event_config = vcnl4010_read_event_config, 977 810 .write_event_config = vcnl4010_write_event_config, 811 + }; 812 + 813 + static const struct iio_info vcnl4040_info = { 814 + .read_raw = vcnl4000_read_raw, 815 + .write_raw = vcnl4040_write_raw, 816 + .read_avail = vcnl4040_read_avail, 978 817 }; 979 818 980 819 static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = { ··· 1012 839 .measure_light = vcnl4200_measure_light, 1013 840 .measure_proximity = vcnl4200_measure_proximity, 1014 841 .set_power_state = vcnl4200_set_power_state, 1015 - .channels = vcnl4000_channels, 1016 - .num_channels = ARRAY_SIZE(vcnl4000_channels), 1017 - .info = &vcnl4000_info, 842 + .channels = vcnl4040_channels, 843 + .num_channels = ARRAY_SIZE(vcnl4040_channels), 844 + .info = &vcnl4040_info, 1018 845 .irq_support = false, 1019 846 }, 1020 847 [VCNL4200] = {
+2 -3
drivers/iio/light/vl6180.c
··· 493 493 return vl6180_hold(data, false); 494 494 } 495 495 496 - static int vl6180_probe(struct i2c_client *client, 497 - const struct i2c_device_id *id) 496 + static int vl6180_probe(struct i2c_client *client) 498 497 { 499 498 struct vl6180_data *data; 500 499 struct iio_dev *indio_dev; ··· 538 539 .name = VL6180_DRV_NAME, 539 540 .of_match_table = vl6180_of_match, 540 541 }, 541 - .probe = vl6180_probe, 542 + .probe_new = vl6180_probe, 542 543 .id_table = vl6180_id, 543 544 }; 544 545
+2 -3
drivers/iio/magnetometer/st_magn_i2c.c
··· 54 54 }; 55 55 MODULE_DEVICE_TABLE(of, st_magn_of_match); 56 56 57 - static int st_magn_i2c_probe(struct i2c_client *client, 58 - const struct i2c_device_id *id) 57 + static int st_magn_i2c_probe(struct i2c_client *client) 59 58 { 60 59 const struct st_sensor_settings *settings; 61 60 struct st_sensor_data *mdata; ··· 106 107 .name = "st-magn-i2c", 107 108 .of_match_table = st_magn_of_match, 108 109 }, 109 - .probe = st_magn_i2c_probe, 110 + .probe_new = st_magn_i2c_probe, 110 111 .id_table = st_magn_id_table, 111 112 }; 112 113 module_i2c_driver(st_magn_driver);
+3 -5
drivers/iio/multiplexer/iio-mux.c
··· 416 416 } 417 417 418 418 mux->control = devm_mux_control_get(dev, NULL); 419 - if (IS_ERR(mux->control)) { 420 - if (PTR_ERR(mux->control) != -EPROBE_DEFER) 421 - dev_err(dev, "failed to get control-mux\n"); 422 - return PTR_ERR(mux->control); 423 - } 419 + if (IS_ERR(mux->control)) 420 + return dev_err_probe(dev, PTR_ERR(mux->control), 421 + "failed to get control-mux\n"); 424 422 425 423 i = 0; 426 424 for (state = 0; state < all_children; state++) {
+3 -3
drivers/iio/pressure/bmp280-i2c.c
··· 5 5 6 6 #include "bmp280.h" 7 7 8 - static int bmp280_i2c_probe(struct i2c_client *client, 9 - const struct i2c_device_id *id) 8 + static int bmp280_i2c_probe(struct i2c_client *client) 10 9 { 11 10 struct regmap *regmap; 12 11 const struct regmap_config *regmap_config; 12 + const struct i2c_device_id *id = i2c_client_get_device_id(client); 13 13 14 14 switch (id->driver_data) { 15 15 case BMP180_CHIP_ID: ··· 65 65 .of_match_table = bmp280_of_i2c_match, 66 66 .pm = pm_ptr(&bmp280_dev_pm_ops), 67 67 }, 68 - .probe = bmp280_i2c_probe, 68 + .probe_new = bmp280_i2c_probe, 69 69 .id_table = bmp280_i2c_id, 70 70 }; 71 71 module_i2c_driver(bmp280_i2c_driver);
+61 -1
drivers/iio/pressure/mpl115.c
··· 4 4 * 5 5 * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net> 6 6 * 7 - * TODO: shutdown pin 7 + * TODO: synchronization with system suspend 8 8 */ 9 9 10 10 #include <linux/module.h> 11 11 #include <linux/iio/iio.h> 12 12 #include <linux/delay.h> 13 + #include <linux/gpio/consumer.h> 13 14 14 15 #include "mpl115.h" 15 16 ··· 28 27 s16 a0; 29 28 s16 b1, b2; 30 29 s16 c12; 30 + struct gpio_desc *shutdown; 31 31 const struct mpl115_ops *ops; 32 32 }; 33 33 ··· 104 102 105 103 switch (mask) { 106 104 case IIO_CHAN_INFO_PROCESSED: 105 + pm_runtime_get_sync(data->dev); 107 106 ret = mpl115_comp_pressure(data, val, val2); 108 107 if (ret < 0) 109 108 return ret; 109 + pm_runtime_mark_last_busy(data->dev); 110 + pm_runtime_put_autosuspend(data->dev); 111 + 110 112 return IIO_VAL_INT_PLUS_MICRO; 111 113 case IIO_CHAN_INFO_RAW: 114 + pm_runtime_get_sync(data->dev); 112 115 /* temperature -5.35 C / LSB, 472 LSB is 25 C */ 113 116 ret = mpl115_read_temp(data); 114 117 if (ret < 0) 115 118 return ret; 119 + pm_runtime_mark_last_busy(data->dev); 120 + pm_runtime_put_autosuspend(data->dev); 116 121 *val = ret >> 6; 122 + 117 123 return IIO_VAL_INT; 118 124 case IIO_CHAN_INFO_OFFSET: 119 125 *val = -605; ··· 178 168 if (ret) 179 169 return ret; 180 170 171 + dev_set_drvdata(dev, indio_dev); 172 + 181 173 ret = data->ops->read(data->dev, MPL115_A0); 182 174 if (ret < 0) 183 175 return ret; ··· 197 185 return ret; 198 186 data->c12 = ret; 199 187 188 + data->shutdown = devm_gpiod_get_optional(dev, "shutdown", 189 + GPIOD_OUT_LOW); 190 + if (IS_ERR(data->shutdown)) 191 + return dev_err_probe(dev, PTR_ERR(data->shutdown), 192 + "cannot get shutdown gpio\n"); 193 + 194 + if (data->shutdown) { 195 + /* Enable runtime PM */ 196 + pm_runtime_get_noresume(dev); 197 + pm_runtime_set_active(dev); 198 + pm_runtime_enable(dev); 199 + 200 + /* 201 + * As the device takes 3 ms to come up with a fresh 202 + * reading after power-on and 5 ms to actually power-on, 203 + * do not shut it down unnecessarily. Set autosuspend to 204 + * 2000 ms. 205 + */ 206 + pm_runtime_set_autosuspend_delay(dev, 2000); 207 + pm_runtime_use_autosuspend(dev); 208 + pm_runtime_put(dev); 209 + 210 + dev_dbg(dev, "low-power mode enabled"); 211 + } else 212 + dev_dbg(dev, "low-power mode disabled"); 213 + 200 214 return devm_iio_device_register(dev, indio_dev); 201 215 } 202 216 EXPORT_SYMBOL_NS_GPL(mpl115_probe, IIO_MPL115); 217 + 218 + static int mpl115_runtime_suspend(struct device *dev) 219 + { 220 + struct mpl115_data *data = iio_priv(dev_get_drvdata(dev)); 221 + 222 + gpiod_set_value(data->shutdown, 1); 223 + 224 + return 0; 225 + } 226 + 227 + static int mpl115_runtime_resume(struct device *dev) 228 + { 229 + struct mpl115_data *data = iio_priv(dev_get_drvdata(dev)); 230 + 231 + gpiod_set_value(data->shutdown, 0); 232 + usleep_range(5000, 6000); 233 + 234 + return 0; 235 + } 236 + 237 + EXPORT_NS_RUNTIME_DEV_PM_OPS(mpl115_dev_pm_ops, mpl115_runtime_suspend, 238 + mpl115_runtime_resume, NULL, IIO_MPL115); 203 239 204 240 MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>"); 205 241 MODULE_DESCRIPTION("Freescale MPL115 pressure/temperature driver");
+5
drivers/iio/pressure/mpl115.h
··· 6 6 * Copyright (c) 2016 Akinobu Mita <akinobu.mita@gmail.com> 7 7 */ 8 8 9 + #include <linux/pm_runtime.h> 10 + 9 11 #ifndef _MPL115_H_ 10 12 #define _MPL115_H_ 11 13 ··· 19 17 20 18 int mpl115_probe(struct device *dev, const char *name, 21 19 const struct mpl115_ops *ops); 20 + 21 + /*PM ops */ 22 + extern const struct dev_pm_ops mpl115_dev_pm_ops; 22 23 23 24 #endif
+1
drivers/iio/pressure/mpl115_i2c.c
··· 53 53 static struct i2c_driver mpl115_i2c_driver = { 54 54 .driver = { 55 55 .name = "mpl115", 56 + .pm = pm_ptr(&mpl115_dev_pm_ops), 56 57 }, 57 58 .probe = mpl115_i2c_probe, 58 59 .id_table = mpl115_i2c_id,
+1
drivers/iio/pressure/mpl115_spi.c
··· 92 92 static struct spi_driver mpl115_spi_driver = { 93 93 .driver = { 94 94 .name = "mpl115", 95 + .pm = pm_ptr(&mpl115_dev_pm_ops), 95 96 }, 96 97 .probe = mpl115_spi_probe, 97 98 .id_table = mpl115_spi_ids,
+1
drivers/iio/proximity/sx9360.c
··· 865 865 866 866 static const struct acpi_device_id sx9360_acpi_match[] = { 867 867 { "STH9360", SX9360_WHOAMI_VALUE }, 868 + { "SAMM0208", SX9360_WHOAMI_VALUE }, 868 869 { } 869 870 }; 870 871 MODULE_DEVICE_TABLE(acpi, sx9360_acpi_match);
+3 -20
drivers/iio/proximity/sx_common.c
··· 424 424 .postdisable = sx_common_buffer_postdisable, 425 425 }; 426 426 427 - static void sx_common_regulator_disable(void *_data) 428 - { 429 - struct sx_common_data *data = _data; 430 - 431 - regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies); 432 - } 433 - 434 427 #define SX_COMMON_SOFT_RESET 0xde 435 428 436 429 static int sx_common_init_device(struct device *dev, struct iio_dev *indio_dev) ··· 467 474 const struct sx_common_chip_info *chip_info, 468 475 const struct regmap_config *regmap_config) 469 476 { 477 + static const char * const regulator_names[] = { "vdd", "svdd" }; 470 478 struct device *dev = &client->dev; 471 479 struct iio_dev *indio_dev; 472 480 struct sx_common_data *data; ··· 481 487 482 488 data->chip_info = chip_info; 483 489 data->client = client; 484 - data->supplies[0].supply = "vdd"; 485 - data->supplies[1].supply = "svdd"; 486 490 mutex_init(&data->mutex); 487 491 init_completion(&data->completion); 488 492 ··· 489 497 return dev_err_probe(dev, PTR_ERR(data->regmap), 490 498 "Could init register map\n"); 491 499 492 - ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->supplies), 493 - data->supplies); 500 + ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names), 501 + regulator_names); 494 502 if (ret) 495 503 return dev_err_probe(dev, ret, "Unable to get regulators\n"); 496 504 497 - ret = regulator_bulk_enable(ARRAY_SIZE(data->supplies), data->supplies); 498 - if (ret) 499 - return dev_err_probe(dev, ret, "Unable to enable regulators\n"); 500 - 501 505 /* Must wait for Tpor time after initial power up */ 502 506 usleep_range(1000, 1100); 503 - 504 - ret = devm_add_action_or_reset(dev, sx_common_regulator_disable, data); 505 - if (ret) 506 - return dev_err_probe(dev, ret, 507 - "Unable to register regulators deleter\n"); 508 507 509 508 ret = data->chip_info->ops.check_whoami(dev, indio_dev); 510 509 if (ret)
-2
drivers/iio/proximity/sx_common.h
··· 102 102 * @trig: IIO trigger object. 103 103 * @regmap: Register map. 104 104 * @num_default_regs: Number of default registers to set at init. 105 - * @supplies: Power supplies object. 106 105 * @chan_prox_stat: Last reading of the proximity status for each channel. 107 106 * We only send an event to user space when this changes. 108 107 * @trigger_enabled: True when the device trigger is enabled. ··· 119 120 struct iio_trigger *trig; 120 121 struct regmap *regmap; 121 122 122 - struct regulator_bulk_data supplies[2]; 123 123 unsigned long chan_prox_stat; 124 124 bool trigger_enabled; 125 125
+181 -12
drivers/iio/temperature/ltc2983.c
··· 25 25 #define LTC2983_STATUS_REG 0x0000 26 26 #define LTC2983_TEMP_RES_START_REG 0x0010 27 27 #define LTC2983_TEMP_RES_END_REG 0x005F 28 + #define LTC2983_EEPROM_KEY_REG 0x00B0 29 + #define LTC2983_EEPROM_READ_STATUS_REG 0x00D0 28 30 #define LTC2983_GLOBAL_CONFIG_REG 0x00F0 29 31 #define LTC2983_MULT_CHANNEL_START_REG 0x00F4 30 32 #define LTC2983_MULT_CHANNEL_END_REG 0x00F7 33 + #define LTC2986_EEPROM_STATUS_REG 0x00F9 31 34 #define LTC2983_MUX_CONFIG_REG 0x00FF 32 35 #define LTC2983_CHAN_ASSIGN_START_REG 0x0200 33 36 #define LTC2983_CHAN_ASSIGN_END_REG 0x024F ··· 38 35 #define LTC2983_CUST_SENS_TBL_END_REG 0x03CF 39 36 40 37 #define LTC2983_DIFFERENTIAL_CHAN_MIN 2 41 - #define LTC2983_MAX_CHANNELS_NR 20 42 38 #define LTC2983_MIN_CHANNELS_NR 1 43 39 #define LTC2983_SLEEP 0x97 44 40 #define LTC2983_CUSTOM_STEINHART_SIZE 24 45 41 #define LTC2983_CUSTOM_SENSOR_ENTRY_SZ 6 46 42 #define LTC2983_CUSTOM_STEINHART_ENTRY_SZ 4 43 + 44 + #define LTC2983_EEPROM_KEY 0xA53C0F5A 45 + #define LTC2983_EEPROM_WRITE_CMD 0x15 46 + #define LTC2983_EEPROM_READ_CMD 0x16 47 + #define LTC2983_EEPROM_STATUS_FAILURE_MASK GENMASK(3, 1) 48 + #define LTC2983_EEPROM_READ_FAILURE_MASK GENMASK(7, 0) 49 + 50 + #define LTC2983_EEPROM_WRITE_TIME_MS 2600 51 + #define LTC2983_EEPROM_READ_TIME_MS 20 47 52 48 53 #define LTC2983_CHAN_START_ADDR(chan) \ 49 54 (((chan - 1) * 4) + LTC2983_CHAN_ASSIGN_START_REG) ··· 182 171 LTC2983_SENSOR_DIODE = 28, 183 172 LTC2983_SENSOR_SENSE_RESISTOR = 29, 184 173 LTC2983_SENSOR_DIRECT_ADC = 30, 174 + LTC2983_SENSOR_ACTIVE_TEMP = 31, 185 175 }; 186 176 187 177 #define to_thermocouple(_sensor) \ ··· 203 191 #define to_adc(_sensor) \ 204 192 container_of(_sensor, struct ltc2983_adc, sensor) 205 193 194 + #define to_temp(_sensor) \ 195 + container_of(_sensor, struct ltc2983_temp, sensor) 196 + 197 + struct ltc2983_chip_info { 198 + unsigned int max_channels_nr; 199 + bool has_temp; 200 + bool has_eeprom; 201 + }; 202 + 206 203 struct ltc2983_data { 204 + const struct ltc2983_chip_info *info; 207 205 struct regmap *regmap; 208 206 struct spi_device *spi; 209 207 struct mutex lock; ··· 231 209 * Holds the converted temperature 232 210 */ 233 211 __be32 temp __aligned(IIO_DMA_MINALIGN); 212 + __be32 chan_val; 213 + __be32 eeprom_key; 234 214 }; 235 215 236 216 struct ltc2983_sensor { ··· 295 271 bool single_ended; 296 272 }; 297 273 274 + struct ltc2983_temp { 275 + struct ltc2983_sensor sensor; 276 + struct ltc2983_custom_sensor *custom; 277 + bool single_ended; 278 + }; 279 + 298 280 /* 299 281 * Convert to Q format numbers. These number's are integers where 300 282 * the number of integer and fractional bits are specified. The resolution ··· 343 313 return 0; 344 314 } 345 315 346 - static int __ltc2983_chan_assign_common(const struct ltc2983_data *st, 316 + static int __ltc2983_chan_assign_common(struct ltc2983_data *st, 347 317 const struct ltc2983_sensor *sensor, 348 318 u32 chan_val) 349 319 { 350 320 u32 reg = LTC2983_CHAN_START_ADDR(sensor->chan); 351 - __be32 __chan_val; 352 321 353 322 chan_val |= LTC2983_CHAN_TYPE(sensor->type); 354 323 dev_dbg(&st->spi->dev, "Assign reg:0x%04X, val:0x%08X\n", reg, 355 324 chan_val); 356 - __chan_val = cpu_to_be32(chan_val); 357 - return regmap_bulk_write(st->regmap, reg, &__chan_val, 358 - sizeof(__chan_val)); 325 + st->chan_val = cpu_to_be32(chan_val); 326 + return regmap_bulk_write(st->regmap, reg, &st->chan_val, 327 + sizeof(st->chan_val)); 359 328 } 360 329 361 330 static int __ltc2983_chan_custom_sensor_assign(struct ltc2983_data *st, ··· 635 606 return __ltc2983_chan_assign_common(st, sensor, chan_val); 636 607 } 637 608 609 + static int ltc2983_temp_assign_chan(struct ltc2983_data *st, 610 + const struct ltc2983_sensor *sensor) 611 + { 612 + struct ltc2983_temp *temp = to_temp(sensor); 613 + u32 chan_val; 614 + int ret; 615 + 616 + chan_val = LTC2983_ADC_SINGLE_ENDED(temp->single_ended); 617 + 618 + ret = __ltc2983_chan_custom_sensor_assign(st, temp->custom, &chan_val); 619 + if (ret) 620 + return ret; 621 + 622 + return __ltc2983_chan_assign_common(st, sensor, chan_val); 623 + } 624 + 638 625 static struct ltc2983_sensor * 639 626 ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data *st, 640 627 const struct ltc2983_sensor *sensor) ··· 816 771 if (rtd->sensor_config & LTC2983_RTD_4_WIRE_MASK) { 817 772 /* 4-wire */ 818 773 u8 min = LTC2983_DIFFERENTIAL_CHAN_MIN, 819 - max = LTC2983_MAX_CHANNELS_NR; 774 + max = st->info->max_channels_nr; 820 775 821 776 if (rtd->sensor_config & LTC2983_RTD_ROTATION_MASK) 822 - max = LTC2983_MAX_CHANNELS_NR - 1; 777 + max = st->info->max_channels_nr - 1; 823 778 824 779 if (((rtd->sensor_config & LTC2983_RTD_KELVIN_R_SENSE_MASK) 825 780 == LTC2983_RTD_KELVIN_R_SENSE_MASK) && ··· 1188 1143 return &adc->sensor; 1189 1144 } 1190 1145 1146 + static struct ltc2983_sensor *ltc2983_temp_new(struct fwnode_handle *child, 1147 + struct ltc2983_data *st, 1148 + const struct ltc2983_sensor *sensor) 1149 + { 1150 + struct ltc2983_temp *temp; 1151 + 1152 + temp = devm_kzalloc(&st->spi->dev, sizeof(*temp), GFP_KERNEL); 1153 + if (!temp) 1154 + return ERR_PTR(-ENOMEM); 1155 + 1156 + if (fwnode_property_read_bool(child, "adi,single-ended")) 1157 + temp->single_ended = true; 1158 + 1159 + if (!temp->single_ended && 1160 + sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { 1161 + dev_err(&st->spi->dev, "Invalid chan:%d for differential temp\n", 1162 + sensor->chan); 1163 + return ERR_PTR(-EINVAL); 1164 + } 1165 + 1166 + temp->custom = __ltc2983_custom_sensor_new(st, child, "adi,custom-temp", 1167 + false, 4096, true); 1168 + if (IS_ERR(temp->custom)) 1169 + return ERR_CAST(temp->custom); 1170 + 1171 + /* set common parameters */ 1172 + temp->sensor.assign_chan = ltc2983_temp_assign_chan; 1173 + temp->sensor.fault_handler = ltc2983_common_fault_handler; 1174 + 1175 + return &temp->sensor; 1176 + } 1177 + 1191 1178 static int ltc2983_chan_read(struct ltc2983_data *st, 1192 1179 const struct ltc2983_sensor *sensor, int *val) 1193 1180 { ··· 1379 1302 1380 1303 /* check if we have a valid channel */ 1381 1304 if (sensor.chan < LTC2983_MIN_CHANNELS_NR || 1382 - sensor.chan > LTC2983_MAX_CHANNELS_NR) { 1305 + sensor.chan > st->info->max_channels_nr) { 1383 1306 ret = -EINVAL; 1384 1307 dev_err(dev, "chan:%d must be from %u to %u\n", sensor.chan, 1385 - LTC2983_MIN_CHANNELS_NR, LTC2983_MAX_CHANNELS_NR); 1308 + LTC2983_MIN_CHANNELS_NR, st->info->max_channels_nr); 1386 1309 goto put_child; 1387 1310 } else if (channel_avail_mask & BIT(sensor.chan)) { 1388 1311 ret = -EINVAL; ··· 1422 1345 st->iio_channels--; 1423 1346 } else if (sensor.type == LTC2983_SENSOR_DIRECT_ADC) { 1424 1347 st->sensors[chan] = ltc2983_adc_new(child, st, &sensor); 1348 + } else if (st->info->has_temp && 1349 + sensor.type == LTC2983_SENSOR_ACTIVE_TEMP) { 1350 + st->sensors[chan] = ltc2983_temp_new(child, st, &sensor); 1425 1351 } else { 1426 1352 dev_err(dev, "Unknown sensor type %d\n", sensor.type); 1427 1353 ret = -EINVAL; ··· 1451 1371 return ret; 1452 1372 } 1453 1373 1374 + static int ltc2983_eeprom_cmd(struct ltc2983_data *st, unsigned int cmd, 1375 + unsigned int wait_time, unsigned int status_reg, 1376 + unsigned long status_fail_mask) 1377 + { 1378 + unsigned long time; 1379 + unsigned int val; 1380 + int ret; 1381 + 1382 + ret = regmap_bulk_write(st->regmap, LTC2983_EEPROM_KEY_REG, 1383 + &st->eeprom_key, sizeof(st->eeprom_key)); 1384 + if (ret) 1385 + return ret; 1386 + 1387 + reinit_completion(&st->completion); 1388 + 1389 + ret = regmap_write(st->regmap, LTC2983_STATUS_REG, 1390 + LTC2983_STATUS_START(true) | cmd); 1391 + if (ret) 1392 + return ret; 1393 + 1394 + time = wait_for_completion_timeout(&st->completion, 1395 + msecs_to_jiffies(wait_time)); 1396 + if (!time) { 1397 + dev_err(&st->spi->dev, "EEPROM command timed out\n"); 1398 + return -ETIMEDOUT; 1399 + } 1400 + 1401 + ret = regmap_read(st->regmap, status_reg, &val); 1402 + if (ret) 1403 + return ret; 1404 + 1405 + if (val & status_fail_mask) { 1406 + dev_err(&st->spi->dev, "EEPROM command failed: 0x%02X\n", val); 1407 + return -EINVAL; 1408 + } 1409 + 1410 + return 0; 1411 + } 1412 + 1454 1413 static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio) 1455 1414 { 1456 1415 u32 iio_chan_t = 0, iio_chan_v = 0, chan, iio_idx = 0, status; ··· 1514 1395 st->mux_delay_config); 1515 1396 if (ret) 1516 1397 return ret; 1398 + 1399 + if (st->info->has_eeprom && !assign_iio) { 1400 + ret = ltc2983_eeprom_cmd(st, LTC2983_EEPROM_READ_CMD, 1401 + LTC2983_EEPROM_READ_TIME_MS, 1402 + LTC2983_EEPROM_READ_STATUS_REG, 1403 + LTC2983_EEPROM_READ_FAILURE_MASK); 1404 + if (!ret) 1405 + return 0; 1406 + } 1517 1407 1518 1408 for (chan = 0; chan < st->num_channels; chan++) { 1519 1409 u32 chan_type = 0, *iio_chan; ··· 1563 1435 static const struct regmap_range ltc2983_reg_ranges[] = { 1564 1436 regmap_reg_range(LTC2983_STATUS_REG, LTC2983_STATUS_REG), 1565 1437 regmap_reg_range(LTC2983_TEMP_RES_START_REG, LTC2983_TEMP_RES_END_REG), 1438 + regmap_reg_range(LTC2983_EEPROM_KEY_REG, LTC2983_EEPROM_KEY_REG), 1439 + regmap_reg_range(LTC2983_EEPROM_READ_STATUS_REG, 1440 + LTC2983_EEPROM_READ_STATUS_REG), 1566 1441 regmap_reg_range(LTC2983_GLOBAL_CONFIG_REG, LTC2983_GLOBAL_CONFIG_REG), 1567 1442 regmap_reg_range(LTC2983_MULT_CHANNEL_START_REG, 1568 1443 LTC2983_MULT_CHANNEL_END_REG), 1444 + regmap_reg_range(LTC2986_EEPROM_STATUS_REG, LTC2986_EEPROM_STATUS_REG), 1569 1445 regmap_reg_range(LTC2983_MUX_CONFIG_REG, LTC2983_MUX_CONFIG_REG), 1570 1446 regmap_reg_range(LTC2983_CHAN_ASSIGN_START_REG, 1571 1447 LTC2983_CHAN_ASSIGN_END_REG), ··· 1614 1482 1615 1483 st = iio_priv(indio_dev); 1616 1484 1485 + st->info = device_get_match_data(&spi->dev); 1486 + if (!st->info) 1487 + st->info = (void *)spi_get_device_id(spi)->driver_data; 1488 + if (!st->info) 1489 + return -ENODEV; 1490 + 1617 1491 st->regmap = devm_regmap_init_spi(spi, &ltc2983_regmap_config); 1618 1492 if (IS_ERR(st->regmap)) { 1619 1493 dev_err(&spi->dev, "Failed to initialize regmap\n"); ··· 1629 1491 mutex_init(&st->lock); 1630 1492 init_completion(&st->completion); 1631 1493 st->spi = spi; 1494 + st->eeprom_key = cpu_to_be32(LTC2983_EEPROM_KEY); 1632 1495 spi_set_drvdata(spi, st); 1633 1496 1634 1497 ret = ltc2983_parse_dt(st); ··· 1663 1524 return ret; 1664 1525 } 1665 1526 1527 + if (st->info->has_eeprom) { 1528 + ret = ltc2983_eeprom_cmd(st, LTC2983_EEPROM_WRITE_CMD, 1529 + LTC2983_EEPROM_WRITE_TIME_MS, 1530 + LTC2986_EEPROM_STATUS_REG, 1531 + LTC2983_EEPROM_STATUS_FAILURE_MASK); 1532 + if (ret) 1533 + return ret; 1534 + } 1535 + 1666 1536 indio_dev->name = name; 1667 1537 indio_dev->num_channels = st->iio_channels; 1668 1538 indio_dev->channels = st->iio_chan; ··· 1702 1554 static DEFINE_SIMPLE_DEV_PM_OPS(ltc2983_pm_ops, ltc2983_suspend, 1703 1555 ltc2983_resume); 1704 1556 1557 + static const struct ltc2983_chip_info ltc2983_chip_info_data = { 1558 + .max_channels_nr = 20, 1559 + }; 1560 + 1561 + static const struct ltc2983_chip_info ltc2984_chip_info_data = { 1562 + .max_channels_nr = 20, 1563 + .has_eeprom = true, 1564 + }; 1565 + 1566 + static const struct ltc2983_chip_info ltc2986_chip_info_data = { 1567 + .max_channels_nr = 10, 1568 + .has_temp = true, 1569 + .has_eeprom = true, 1570 + }; 1571 + 1705 1572 static const struct spi_device_id ltc2983_id_table[] = { 1706 - { "ltc2983" }, 1573 + { "ltc2983", (kernel_ulong_t)&ltc2983_chip_info_data }, 1574 + { "ltc2984", (kernel_ulong_t)&ltc2984_chip_info_data }, 1575 + { "ltc2986", (kernel_ulong_t)&ltc2986_chip_info_data }, 1576 + { "ltm2985", (kernel_ulong_t)&ltc2986_chip_info_data }, 1707 1577 {}, 1708 1578 }; 1709 1579 MODULE_DEVICE_TABLE(spi, ltc2983_id_table); 1710 1580 1711 1581 static const struct of_device_id ltc2983_of_match[] = { 1712 - { .compatible = "adi,ltc2983" }, 1582 + { .compatible = "adi,ltc2983", .data = &ltc2983_chip_info_data }, 1583 + { .compatible = "adi,ltc2984", .data = &ltc2984_chip_info_data }, 1584 + { .compatible = "adi,ltc2986", .data = &ltc2986_chip_info_data }, 1585 + { .compatible = "adi,ltm2985", .data = &ltc2986_chip_info_data }, 1713 1586 {}, 1714 1587 }; 1715 1588 MODULE_DEVICE_TABLE(of, ltc2983_of_match);
+392 -82
drivers/iio/temperature/mlx90632.c
··· 6 6 * 7 7 * Driver for the Melexis MLX90632 I2C 16-bit IR thermopile sensor 8 8 */ 9 + #include <linux/bitfield.h> 9 10 #include <linux/delay.h> 11 + #include <linux/device.h> 10 12 #include <linux/err.h> 11 13 #include <linux/gpio/consumer.h> 12 14 #include <linux/i2c.h> 13 15 #include <linux/iopoll.h> 16 + #include <linux/jiffies.h> 14 17 #include <linux/kernel.h> 15 18 #include <linux/limits.h> 16 19 #include <linux/mod_devicetable.h> ··· 58 55 #define MLX90632_EE_Ha 0x2481 /* Ha customer calib value reg 16bit */ 59 56 #define MLX90632_EE_Hb 0x2482 /* Hb customer calib value reg 16bit */ 60 57 58 + #define MLX90632_EE_MEDICAL_MEAS1 0x24E1 /* Medical measurement 1 16bit */ 59 + #define MLX90632_EE_MEDICAL_MEAS2 0x24E2 /* Medical measurement 2 16bit */ 60 + #define MLX90632_EE_EXTENDED_MEAS1 0x24F1 /* Extended measurement 1 16bit */ 61 + #define MLX90632_EE_EXTENDED_MEAS2 0x24F2 /* Extended measurement 2 16bit */ 62 + #define MLX90632_EE_EXTENDED_MEAS3 0x24F3 /* Extended measurement 3 16bit */ 63 + 61 64 /* Register addresses - volatile */ 62 65 #define MLX90632_REG_I2C_ADDR 0x3000 /* Chip I2C address register */ 63 66 ··· 71 62 #define MLX90632_REG_CONTROL 0x3001 /* Control Register address */ 72 63 #define MLX90632_CFG_PWR_MASK GENMASK(2, 1) /* PowerMode Mask */ 73 64 #define MLX90632_CFG_MTYP_MASK GENMASK(8, 4) /* Meas select Mask */ 65 + #define MLX90632_CFG_SOB_MASK BIT(11) 74 66 75 67 /* PowerModes statuses */ 76 68 #define MLX90632_PWR_STATUS(ctrl_val) (ctrl_val << 1) 77 69 #define MLX90632_PWR_STATUS_HALT MLX90632_PWR_STATUS(0) /* hold */ 78 - #define MLX90632_PWR_STATUS_SLEEP_STEP MLX90632_PWR_STATUS(1) /* sleep step*/ 70 + #define MLX90632_PWR_STATUS_SLEEP_STEP MLX90632_PWR_STATUS(1) /* sleep step */ 79 71 #define MLX90632_PWR_STATUS_STEP MLX90632_PWR_STATUS(2) /* step */ 80 - #define MLX90632_PWR_STATUS_CONTINUOUS MLX90632_PWR_STATUS(3) /* continuous*/ 72 + #define MLX90632_PWR_STATUS_CONTINUOUS MLX90632_PWR_STATUS(3) /* continuous */ 73 + 74 + #define MLX90632_EE_RR GENMASK(10, 8) /* Only Refresh Rate bits */ 75 + #define MLX90632_REFRESH_RATE(ee_val) FIELD_GET(MLX90632_EE_RR, ee_val) 76 + /* Extract Refresh Rate from ee register */ 77 + #define MLX90632_REFRESH_RATE_STATUS(refresh_rate) (refresh_rate << 8) 81 78 82 79 /* Measurement types */ 83 80 #define MLX90632_MTYP_MEDICAL 0 ··· 131 116 #define MLX90632_REF_12 12LL /* ResCtrlRef value of Ch 1 or Ch 2 */ 132 117 #define MLX90632_REF_3 12LL /* ResCtrlRef value of Channel 3 */ 133 118 #define MLX90632_MAX_MEAS_NUM 31 /* Maximum measurements in list */ 134 - #define MLX90632_SLEEP_DELAY_MS 3000 /* Autosleep delay */ 119 + #define MLX90632_SLEEP_DELAY_MS 6000 /* Autosleep delay */ 135 120 #define MLX90632_EXTENDED_LIMIT 27000 /* Extended mode raw value limit */ 121 + #define MLX90632_MEAS_MAX_TIME 2000 /* Max measurement time in ms for the lowest refresh rate */ 136 122 137 123 /** 138 124 * struct mlx90632_data - private data for the MLX90632 device ··· 146 130 * @object_ambient_temperature: Ambient temperature at object (might differ of 147 131 * the ambient temperature of sensor. 148 132 * @regulator: Regulator of the device 133 + * @powerstatus: Current POWER status of the device 134 + * @interaction_ts: Timestamp of the last temperature read that is used 135 + * for power management in jiffies 149 136 */ 150 137 struct mlx90632_data { 151 138 struct i2c_client *client; ··· 158 139 u8 mtyp; 159 140 u32 object_ambient_temperature; 160 141 struct regulator *regulator; 142 + int powerstatus; 143 + unsigned long interaction_ts; 161 144 }; 162 145 163 146 static const struct regmap_range mlx90632_volatile_reg_range[] = { ··· 179 158 regmap_reg_range(MLX90632_EE_VERSION, MLX90632_EE_Ka), 180 159 regmap_reg_range(MLX90632_EE_CTRL, MLX90632_EE_I2C_ADDR), 181 160 regmap_reg_range(MLX90632_EE_Ha, MLX90632_EE_Hb), 161 + regmap_reg_range(MLX90632_EE_MEDICAL_MEAS1, MLX90632_EE_MEDICAL_MEAS2), 162 + regmap_reg_range(MLX90632_EE_EXTENDED_MEAS1, MLX90632_EE_EXTENDED_MEAS3), 182 163 regmap_reg_range(MLX90632_REG_I2C_ADDR, MLX90632_REG_CONTROL), 183 164 regmap_reg_range(MLX90632_REG_I2C_CMD, MLX90632_REG_I2C_CMD), 184 165 regmap_reg_range(MLX90632_REG_STATUS, MLX90632_REG_STATUS), ··· 219 196 .cache_type = REGCACHE_RBTREE, 220 197 }; 221 198 222 - static s32 mlx90632_pwr_set_sleep_step(struct regmap *regmap) 199 + static int mlx90632_pwr_set_sleep_step(struct regmap *regmap) 223 200 { 224 - return regmap_update_bits(regmap, MLX90632_REG_CONTROL, 225 - MLX90632_CFG_PWR_MASK, 226 - MLX90632_PWR_STATUS_SLEEP_STEP); 201 + struct mlx90632_data *data = 202 + iio_priv(dev_get_drvdata(regmap_get_device(regmap))); 203 + int ret; 204 + 205 + if (data->powerstatus == MLX90632_PWR_STATUS_SLEEP_STEP) 206 + return 0; 207 + 208 + ret = regmap_write_bits(regmap, MLX90632_REG_CONTROL, MLX90632_CFG_PWR_MASK, 209 + MLX90632_PWR_STATUS_SLEEP_STEP); 210 + if (ret < 0) 211 + return ret; 212 + 213 + data->powerstatus = MLX90632_PWR_STATUS_SLEEP_STEP; 214 + return 0; 227 215 } 228 216 229 - static s32 mlx90632_pwr_continuous(struct regmap *regmap) 217 + static int mlx90632_pwr_continuous(struct regmap *regmap) 230 218 { 231 - return regmap_update_bits(regmap, MLX90632_REG_CONTROL, 232 - MLX90632_CFG_PWR_MASK, 233 - MLX90632_PWR_STATUS_CONTINUOUS); 219 + struct mlx90632_data *data = 220 + iio_priv(dev_get_drvdata(regmap_get_device(regmap))); 221 + int ret; 222 + 223 + if (data->powerstatus == MLX90632_PWR_STATUS_CONTINUOUS) 224 + return 0; 225 + 226 + ret = regmap_write_bits(regmap, MLX90632_REG_CONTROL, MLX90632_CFG_PWR_MASK, 227 + MLX90632_PWR_STATUS_CONTINUOUS); 228 + if (ret < 0) 229 + return ret; 230 + 231 + data->powerstatus = MLX90632_PWR_STATUS_CONTINUOUS; 232 + return 0; 234 233 } 235 234 236 235 /** ··· 262 217 static void mlx90632_reset_delay(void) 263 218 { 264 219 usleep_range(150, 200); 220 + } 221 + 222 + static int mlx90632_get_measurement_time(struct regmap *regmap, u16 meas) 223 + { 224 + unsigned int reg; 225 + int ret; 226 + 227 + ret = regmap_read(regmap, meas, &reg); 228 + if (ret < 0) 229 + return ret; 230 + 231 + return MLX90632_MEAS_MAX_TIME >> FIELD_GET(MLX90632_EE_RR, reg); 232 + } 233 + 234 + static int mlx90632_calculate_dataset_ready_time(struct mlx90632_data *data) 235 + { 236 + unsigned int refresh_time; 237 + int ret; 238 + 239 + if (data->mtyp == MLX90632_MTYP_MEDICAL) { 240 + ret = mlx90632_get_measurement_time(data->regmap, 241 + MLX90632_EE_MEDICAL_MEAS1); 242 + if (ret < 0) 243 + return ret; 244 + 245 + refresh_time = ret; 246 + 247 + ret = mlx90632_get_measurement_time(data->regmap, 248 + MLX90632_EE_MEDICAL_MEAS2); 249 + if (ret < 0) 250 + return ret; 251 + 252 + refresh_time += ret; 253 + } else { 254 + ret = mlx90632_get_measurement_time(data->regmap, 255 + MLX90632_EE_EXTENDED_MEAS1); 256 + if (ret < 0) 257 + return ret; 258 + 259 + refresh_time = ret; 260 + 261 + ret = mlx90632_get_measurement_time(data->regmap, 262 + MLX90632_EE_EXTENDED_MEAS2); 263 + if (ret < 0) 264 + return ret; 265 + 266 + refresh_time += ret; 267 + 268 + ret = mlx90632_get_measurement_time(data->regmap, 269 + MLX90632_EE_EXTENDED_MEAS3); 270 + if (ret < 0) 271 + return ret; 272 + 273 + refresh_time += ret; 274 + } 275 + 276 + return refresh_time; 265 277 } 266 278 267 279 /** ··· 351 249 return (reg_status & MLX90632_STAT_CYCLE_POS) >> 2; 352 250 } 353 251 354 - static int mlx90632_set_meas_type(struct regmap *regmap, u8 type) 252 + /** 253 + * mlx90632_perform_measurement_burst() - Trigger and retrieve current measurement 254 + * cycle in step sleep mode 255 + * @data: pointer to mlx90632_data object containing regmap information 256 + * 257 + * Perform a measurement and return 2 as measurement cycle position reported 258 + * by sensor. This is a blocking function for amount dependent on the sensor 259 + * refresh rate. 260 + */ 261 + static int mlx90632_perform_measurement_burst(struct mlx90632_data *data) 355 262 { 263 + unsigned int reg_status; 356 264 int ret; 357 265 358 - if ((type != MLX90632_MTYP_MEDICAL) && (type != MLX90632_MTYP_EXTENDED)) 359 - return -EINVAL; 266 + ret = regmap_write_bits(data->regmap, MLX90632_REG_CONTROL, 267 + MLX90632_CFG_SOB_MASK, MLX90632_CFG_SOB_MASK); 268 + if (ret < 0) 269 + return ret; 360 270 361 - ret = regmap_write(regmap, MLX90632_REG_I2C_CMD, MLX90632_RESET_CMD); 271 + ret = mlx90632_calculate_dataset_ready_time(data); 272 + if (ret < 0) 273 + return ret; 274 + 275 + msleep(ret); /* Wait minimum time for dataset to be ready */ 276 + 277 + ret = regmap_read_poll_timeout(data->regmap, MLX90632_REG_STATUS, 278 + reg_status, 279 + (reg_status & MLX90632_STAT_BUSY) == 0, 280 + 10000, 100 * 10000); 281 + if (ret < 0) { 282 + dev_err(&data->client->dev, "data not ready"); 283 + return -ETIMEDOUT; 284 + } 285 + 286 + return 2; 287 + } 288 + 289 + static int mlx90632_set_meas_type(struct mlx90632_data *data, u8 type) 290 + { 291 + int current_powerstatus; 292 + int ret; 293 + 294 + if (data->mtyp == type) 295 + return 0; 296 + 297 + current_powerstatus = data->powerstatus; 298 + ret = mlx90632_pwr_continuous(data->regmap); 299 + if (ret < 0) 300 + return ret; 301 + 302 + ret = regmap_write(data->regmap, MLX90632_REG_I2C_CMD, MLX90632_RESET_CMD); 362 303 if (ret < 0) 363 304 return ret; 364 305 365 306 mlx90632_reset_delay(); 366 307 367 - ret = regmap_write_bits(regmap, MLX90632_REG_CONTROL, 308 + ret = regmap_update_bits(data->regmap, MLX90632_REG_CONTROL, 368 309 (MLX90632_CFG_MTYP_MASK | MLX90632_CFG_PWR_MASK), 369 310 (MLX90632_MTYP_STATUS(type) | MLX90632_PWR_STATUS_HALT)); 370 311 if (ret < 0) 371 312 return ret; 372 313 373 - return mlx90632_pwr_continuous(regmap); 314 + data->mtyp = type; 315 + data->powerstatus = MLX90632_PWR_STATUS_HALT; 316 + 317 + if (current_powerstatus == MLX90632_PWR_STATUS_SLEEP_STEP) 318 + return mlx90632_pwr_set_sleep_step(data->regmap); 319 + 320 + return mlx90632_pwr_continuous(data->regmap); 374 321 } 375 322 376 323 static int mlx90632_channel_new_select(int perform_ret, uint8_t *channel_new, ··· 435 284 *channel_old = 1; 436 285 break; 437 286 default: 438 - return -EINVAL; 287 + return -ECHRNG; 439 288 } 440 289 441 290 return 0; ··· 444 293 static int mlx90632_read_ambient_raw(struct regmap *regmap, 445 294 s16 *ambient_new_raw, s16 *ambient_old_raw) 446 295 { 447 - int ret; 448 296 unsigned int read_tmp; 297 + int ret; 449 298 450 299 ret = regmap_read(regmap, MLX90632_RAM_3(1), &read_tmp); 451 300 if (ret < 0) ··· 464 313 int perform_measurement_ret, 465 314 s16 *object_new_raw, s16 *object_old_raw) 466 315 { 467 - int ret; 468 316 unsigned int read_tmp; 469 - s16 read; 470 - u8 channel = 0; 471 317 u8 channel_old = 0; 318 + u8 channel = 0; 319 + s16 read; 320 + int ret; 472 321 473 322 ret = mlx90632_channel_new_select(perform_measurement_ret, &channel, 474 323 &channel_old); ··· 503 352 s16 *ambient_new_raw, s16 *ambient_old_raw, 504 353 s16 *object_new_raw, s16 *object_old_raw) 505 354 { 506 - s32 ret, measurement; 355 + s32 measurement; 356 + int ret; 507 357 508 358 mutex_lock(&data->lock); 509 - measurement = mlx90632_perform_measurement(data); 510 - if (measurement < 0) { 511 - ret = measurement; 359 + ret = mlx90632_set_meas_type(data, MLX90632_MTYP_MEDICAL); 360 + if (ret < 0) 361 + goto read_unlock; 362 + 363 + switch (data->powerstatus) { 364 + case MLX90632_PWR_STATUS_CONTINUOUS: 365 + ret = mlx90632_perform_measurement(data); 366 + if (ret < 0) 367 + goto read_unlock; 368 + 369 + break; 370 + case MLX90632_PWR_STATUS_SLEEP_STEP: 371 + ret = mlx90632_perform_measurement_burst(data); 372 + if (ret < 0) 373 + goto read_unlock; 374 + 375 + break; 376 + default: 377 + ret = -EOPNOTSUPP; 512 378 goto read_unlock; 513 379 } 380 + 381 + measurement = ret; /* If we came here ret holds the measurement position */ 382 + 514 383 ret = mlx90632_read_ambient_raw(data->regmap, ambient_new_raw, 515 384 ambient_old_raw); 516 385 if (ret < 0) ··· 612 441 s32 ret, meas; 613 442 614 443 mutex_lock(&data->lock); 615 - ret = mlx90632_set_meas_type(data->regmap, MLX90632_MTYP_EXTENDED); 444 + ret = mlx90632_set_meas_type(data, MLX90632_MTYP_EXTENDED); 616 445 if (ret < 0) 617 446 goto read_unlock; 618 447 619 - ret = read_poll_timeout(mlx90632_perform_measurement, meas, meas == 19, 620 - 50000, 800000, false, data); 621 - if (ret != 0) 448 + switch (data->powerstatus) { 449 + case MLX90632_PWR_STATUS_CONTINUOUS: 450 + ret = read_poll_timeout(mlx90632_perform_measurement, meas, meas == 19, 451 + 50000, 800000, false, data); 452 + if (ret) 453 + goto read_unlock; 454 + break; 455 + case MLX90632_PWR_STATUS_SLEEP_STEP: 456 + ret = mlx90632_perform_measurement_burst(data); 457 + if (ret < 0) 458 + goto read_unlock; 459 + break; 460 + default: 461 + ret = -EOPNOTSUPP; 622 462 goto read_unlock; 463 + } 623 464 624 465 ret = mlx90632_read_object_raw_extended(data->regmap, object_new_raw); 625 466 if (ret < 0) ··· 640 457 ret = mlx90632_read_ambient_raw_extended(data->regmap, ambient_new_raw, ambient_old_raw); 641 458 642 459 read_unlock: 643 - (void) mlx90632_set_meas_type(data->regmap, MLX90632_MTYP_MEDICAL); 644 - 645 460 mutex_unlock(&data->lock); 646 461 return ret; 647 462 } ··· 647 466 static int mlx90632_read_ee_register(struct regmap *regmap, u16 reg_lsb, 648 467 s32 *reg_value) 649 468 { 650 - s32 ret; 651 469 unsigned int read; 652 470 u32 value; 471 + int ret; 653 472 654 473 ret = regmap_read(regmap, reg_lsb, &read); 655 474 if (ret < 0) ··· 813 632 814 633 static int mlx90632_calc_object_dsp105(struct mlx90632_data *data, int *val) 815 634 { 816 - s32 ret; 635 + s16 ambient_new_raw, ambient_old_raw, object_new_raw, object_old_raw; 817 636 s32 Ea, Eb, Fa, Fb, Ga; 818 637 unsigned int read_tmp; 819 - s16 Ha, Hb, Gb, Ka; 820 - s16 ambient_new_raw, ambient_old_raw, object_new_raw, object_old_raw; 821 638 s64 object, ambient; 639 + s16 Ha, Hb, Gb, Ka; 640 + int ret; 822 641 823 642 ret = mlx90632_read_ee_register(data->regmap, MLX90632_EE_Ea, &Ea); 824 643 if (ret < 0) ··· 892 711 893 712 static int mlx90632_calc_ambient_dsp105(struct mlx90632_data *data, int *val) 894 713 { 895 - s32 ret; 714 + s16 ambient_new_raw, ambient_old_raw; 896 715 unsigned int read_tmp; 897 716 s32 PT, PR, PG, PO; 717 + int ret; 898 718 s16 Gb; 899 - s16 ambient_new_raw, ambient_old_raw; 900 719 901 720 ret = mlx90632_read_ee_register(data->regmap, MLX90632_EE_P_R, &PR); 902 721 if (ret < 0) ··· 924 743 return ret; 925 744 } 926 745 746 + static int mlx90632_get_refresh_rate(struct mlx90632_data *data, 747 + int *refresh_rate) 748 + { 749 + unsigned int meas1; 750 + int ret; 751 + 752 + ret = regmap_read(data->regmap, MLX90632_EE_MEDICAL_MEAS1, &meas1); 753 + if (ret < 0) 754 + return ret; 755 + 756 + *refresh_rate = MLX90632_REFRESH_RATE(meas1); 757 + 758 + return ret; 759 + } 760 + 761 + static const int mlx90632_freqs[][2] = { 762 + {0, 500000}, 763 + {1, 0}, 764 + {2, 0}, 765 + {4, 0}, 766 + {8, 0}, 767 + {16, 0}, 768 + {32, 0}, 769 + {64, 0} 770 + }; 771 + 772 + /** 773 + * mlx90632_pm_interraction_wakeup() - Measure time between user interactions to change powermode 774 + * @data: pointer to mlx90632_data object containing interaction_ts information 775 + * 776 + * Switch to continuous mode when interaction is faster than MLX90632_MEAS_MAX_TIME. Update the 777 + * interaction_ts for each function call with the jiffies to enable measurement between function 778 + * calls. Initial value of the interaction_ts needs to be set before this function call. 779 + */ 780 + static int mlx90632_pm_interraction_wakeup(struct mlx90632_data *data) 781 + { 782 + unsigned long now; 783 + int ret; 784 + 785 + now = jiffies; 786 + if (time_in_range(now, data->interaction_ts, 787 + data->interaction_ts + 788 + msecs_to_jiffies(MLX90632_MEAS_MAX_TIME + 100))) { 789 + if (data->powerstatus == MLX90632_PWR_STATUS_SLEEP_STEP) { 790 + ret = mlx90632_pwr_continuous(data->regmap); 791 + if (ret < 0) 792 + return ret; 793 + } 794 + } 795 + 796 + data->interaction_ts = now; 797 + 798 + return 0; 799 + } 800 + 927 801 static int mlx90632_read_raw(struct iio_dev *indio_dev, 928 802 struct iio_chan_spec const *channel, int *val, 929 803 int *val2, long mask) 930 804 { 931 805 struct mlx90632_data *data = iio_priv(indio_dev); 932 806 int ret; 807 + int cr; 808 + 809 + pm_runtime_get_sync(&data->client->dev); 810 + ret = mlx90632_pm_interraction_wakeup(data); 811 + if (ret < 0) 812 + goto mlx90632_read_raw_pm; 933 813 934 814 switch (mask) { 935 815 case IIO_CHAN_INFO_PROCESSED: ··· 998 756 case IIO_MOD_TEMP_AMBIENT: 999 757 ret = mlx90632_calc_ambient_dsp105(data, val); 1000 758 if (ret < 0) 1001 - return ret; 1002 - return IIO_VAL_INT; 759 + goto mlx90632_read_raw_pm; 760 + 761 + ret = IIO_VAL_INT; 762 + break; 1003 763 case IIO_MOD_TEMP_OBJECT: 1004 764 ret = mlx90632_calc_object_dsp105(data, val); 1005 765 if (ret < 0) 1006 - return ret; 1007 - return IIO_VAL_INT; 766 + goto mlx90632_read_raw_pm; 767 + 768 + ret = IIO_VAL_INT; 769 + break; 1008 770 default: 1009 - return -EINVAL; 771 + ret = -EINVAL; 772 + break; 1010 773 } 774 + break; 1011 775 case IIO_CHAN_INFO_CALIBEMISSIVITY: 1012 776 if (data->emissivity == 1000) { 1013 777 *val = 1; ··· 1022 774 *val = 0; 1023 775 *val2 = data->emissivity * 1000; 1024 776 } 1025 - return IIO_VAL_INT_PLUS_MICRO; 777 + ret = IIO_VAL_INT_PLUS_MICRO; 778 + break; 1026 779 case IIO_CHAN_INFO_CALIBAMBIENT: 1027 780 *val = data->object_ambient_temperature; 1028 - return IIO_VAL_INT; 781 + ret = IIO_VAL_INT; 782 + break; 783 + case IIO_CHAN_INFO_SAMP_FREQ: 784 + ret = mlx90632_get_refresh_rate(data, &cr); 785 + if (ret < 0) 786 + goto mlx90632_read_raw_pm; 787 + 788 + *val = mlx90632_freqs[cr][0]; 789 + *val2 = mlx90632_freqs[cr][1]; 790 + ret = IIO_VAL_INT_PLUS_MICRO; 791 + break; 1029 792 default: 1030 - return -EINVAL; 793 + ret = -EINVAL; 794 + break; 1031 795 } 796 + 797 + mlx90632_read_raw_pm: 798 + pm_runtime_mark_last_busy(&data->client->dev); 799 + pm_runtime_put_autosuspend(&data->client->dev); 800 + return ret; 1032 801 } 1033 802 1034 803 static int mlx90632_write_raw(struct iio_dev *indio_dev, ··· 1070 805 } 1071 806 } 1072 807 808 + static int mlx90632_read_avail(struct iio_dev *indio_dev, 809 + struct iio_chan_spec const *chan, 810 + const int **vals, int *type, int *length, 811 + long mask) 812 + { 813 + switch (mask) { 814 + case IIO_CHAN_INFO_SAMP_FREQ: 815 + *vals = (int *)mlx90632_freqs; 816 + *type = IIO_VAL_INT_PLUS_MICRO; 817 + *length = 2 * ARRAY_SIZE(mlx90632_freqs); 818 + return IIO_AVAIL_LIST; 819 + default: 820 + return -EINVAL; 821 + } 822 + } 823 + 1073 824 static const struct iio_chan_spec mlx90632_channels[] = { 1074 825 { 1075 826 .type = IIO_TEMP, 1076 827 .modified = 1, 1077 828 .channel2 = IIO_MOD_TEMP_AMBIENT, 1078 829 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 830 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 831 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 1079 832 }, 1080 833 { 1081 834 .type = IIO_TEMP, ··· 1101 818 .channel2 = IIO_MOD_TEMP_OBJECT, 1102 819 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 1103 820 BIT(IIO_CHAN_INFO_CALIBEMISSIVITY) | BIT(IIO_CHAN_INFO_CALIBAMBIENT), 821 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 822 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 1104 823 }, 1105 824 }; 1106 825 1107 826 static const struct iio_info mlx90632_info = { 1108 827 .read_raw = mlx90632_read_raw, 1109 828 .write_raw = mlx90632_write_raw, 829 + .read_avail = mlx90632_read_avail, 1110 830 }; 1111 831 1112 - static int mlx90632_sleep(struct mlx90632_data *data) 832 + static void mlx90632_sleep(void *_data) 833 + { 834 + struct mlx90632_data *data = _data; 835 + 836 + mlx90632_pwr_set_sleep_step(data->regmap); 837 + } 838 + 839 + static int mlx90632_suspend(struct mlx90632_data *data) 1113 840 { 1114 841 regcache_mark_dirty(data->regmap); 1115 842 1116 - dev_dbg(&data->client->dev, "Requesting sleep"); 843 + dev_dbg(&data->client->dev, "Requesting suspend"); 1117 844 return mlx90632_pwr_set_sleep_step(data->regmap); 1118 845 } 1119 846 ··· 1171 878 static int mlx90632_probe(struct i2c_client *client, 1172 879 const struct i2c_device_id *id) 1173 880 { 1174 - struct iio_dev *indio_dev; 1175 881 struct mlx90632_data *mlx90632; 882 + struct iio_dev *indio_dev; 1176 883 struct regmap *regmap; 1177 - int ret; 1178 884 unsigned int read; 885 + int ret; 1179 886 1180 887 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*mlx90632)); 1181 888 if (!indio_dev) { ··· 1195 902 mlx90632->client = client; 1196 903 mlx90632->regmap = regmap; 1197 904 mlx90632->mtyp = MLX90632_MTYP_MEDICAL; 905 + mlx90632->powerstatus = MLX90632_PWR_STATUS_HALT; 1198 906 1199 907 mutex_init(&mlx90632->lock); 1200 908 indio_dev->name = id->name; ··· 1227 933 return ret; 1228 934 } 1229 935 936 + ret = devm_add_action_or_reset(&client->dev, mlx90632_sleep, mlx90632); 937 + if (ret < 0) { 938 + dev_err(&client->dev, "Failed to setup low power cleanup action %d\n", 939 + ret); 940 + return ret; 941 + } 942 + 1230 943 ret = regmap_read(mlx90632->regmap, MLX90632_EE_VERSION, &read); 1231 944 if (ret < 0) { 1232 945 dev_err(&client->dev, "read of version failed: %d\n", ret); ··· 1262 961 1263 962 mlx90632->emissivity = 1000; 1264 963 mlx90632->object_ambient_temperature = 25000; /* 25 degrees milliCelsius */ 964 + mlx90632->interaction_ts = jiffies; /* Set initial value */ 1265 965 1266 - pm_runtime_disable(&client->dev); 1267 - ret = pm_runtime_set_active(&client->dev); 1268 - if (ret < 0) { 1269 - mlx90632_sleep(mlx90632); 966 + pm_runtime_get_noresume(&client->dev); 967 + pm_runtime_set_active(&client->dev); 968 + 969 + ret = devm_pm_runtime_enable(&client->dev); 970 + if (ret) 1270 971 return ret; 1271 - } 1272 - pm_runtime_enable(&client->dev); 972 + 1273 973 pm_runtime_set_autosuspend_delay(&client->dev, MLX90632_SLEEP_DELAY_MS); 1274 974 pm_runtime_use_autosuspend(&client->dev); 975 + pm_runtime_put_autosuspend(&client->dev); 1275 976 1276 - return iio_device_register(indio_dev); 1277 - } 1278 - 1279 - static void mlx90632_remove(struct i2c_client *client) 1280 - { 1281 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 1282 - struct mlx90632_data *data = iio_priv(indio_dev); 1283 - 1284 - iio_device_unregister(indio_dev); 1285 - 1286 - pm_runtime_disable(&client->dev); 1287 - pm_runtime_set_suspended(&client->dev); 1288 - pm_runtime_put_noidle(&client->dev); 1289 - 1290 - mlx90632_sleep(data); 977 + return devm_iio_device_register(&client->dev, indio_dev); 1291 978 } 1292 979 1293 980 static const struct i2c_device_id mlx90632_id[] = { ··· 1290 1001 }; 1291 1002 MODULE_DEVICE_TABLE(of, mlx90632_of_match); 1292 1003 1293 - static int __maybe_unused mlx90632_pm_suspend(struct device *dev) 1004 + static int mlx90632_pm_suspend(struct device *dev) 1294 1005 { 1295 - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 1296 - struct mlx90632_data *data = iio_priv(indio_dev); 1006 + struct mlx90632_data *data = iio_priv(dev_get_drvdata(dev)); 1007 + int ret; 1297 1008 1298 - return mlx90632_sleep(data); 1009 + ret = mlx90632_suspend(data); 1010 + if (ret < 0) 1011 + return ret; 1012 + 1013 + ret = regulator_disable(data->regulator); 1014 + if (ret < 0) 1015 + dev_err(regmap_get_device(data->regmap), 1016 + "Failed to disable power regulator: %d\n", ret); 1017 + 1018 + return ret; 1299 1019 } 1300 1020 1301 - static int __maybe_unused mlx90632_pm_resume(struct device *dev) 1021 + static int mlx90632_pm_resume(struct device *dev) 1302 1022 { 1303 - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 1304 - struct mlx90632_data *data = iio_priv(indio_dev); 1023 + struct mlx90632_data *data = iio_priv(dev_get_drvdata(dev)); 1024 + int ret; 1025 + 1026 + ret = mlx90632_enable_regulator(data); 1027 + if (ret < 0) 1028 + return ret; 1305 1029 1306 1030 return mlx90632_wakeup(data); 1307 1031 } 1308 1032 1309 - static UNIVERSAL_DEV_PM_OPS(mlx90632_pm_ops, mlx90632_pm_suspend, 1310 - mlx90632_pm_resume, NULL); 1033 + static int mlx90632_pm_runtime_suspend(struct device *dev) 1034 + { 1035 + struct mlx90632_data *data = iio_priv(dev_get_drvdata(dev)); 1036 + 1037 + return mlx90632_pwr_set_sleep_step(data->regmap); 1038 + } 1039 + 1040 + static const struct dev_pm_ops mlx90632_pm_ops = { 1041 + SYSTEM_SLEEP_PM_OPS(mlx90632_pm_suspend, mlx90632_pm_resume) 1042 + RUNTIME_PM_OPS(mlx90632_pm_runtime_suspend, NULL, NULL) 1043 + }; 1311 1044 1312 1045 static struct i2c_driver mlx90632_driver = { 1313 1046 .driver = { 1314 1047 .name = "mlx90632", 1315 1048 .of_match_table = mlx90632_of_match, 1316 - .pm = &mlx90632_pm_ops, 1049 + .pm = pm_ptr(&mlx90632_pm_ops), 1317 1050 }, 1318 1051 .probe = mlx90632_probe, 1319 - .remove = mlx90632_remove, 1320 1052 .id_table = mlx90632_id, 1321 1053 }; 1322 1054 module_i2c_driver(mlx90632_driver);
+7 -7
drivers/iio/trigger/iio-trig-sysfs.c
··· 138 138 } 139 139 if (foundit) { 140 140 ret = -EINVAL; 141 - goto out1; 141 + goto err_unlock; 142 142 } 143 143 t = kmalloc(sizeof(*t), GFP_KERNEL); 144 144 if (t == NULL) { 145 145 ret = -ENOMEM; 146 - goto out1; 146 + goto err_unlock; 147 147 } 148 148 t->id = id; 149 149 t->trig = iio_trigger_alloc(&iio_sysfs_trig_dev, "sysfstrig%d", id); 150 150 if (!t->trig) { 151 151 ret = -ENOMEM; 152 - goto free_t; 152 + goto err_free_sys_trig; 153 153 } 154 154 155 155 t->trig->dev.groups = iio_sysfs_trigger_attr_groups; ··· 159 159 160 160 ret = iio_trigger_register(t->trig); 161 161 if (ret) 162 - goto out2; 162 + goto err_free_trig; 163 163 list_add(&t->l, &iio_sysfs_trig_list); 164 164 __module_get(THIS_MODULE); 165 165 mutex_unlock(&iio_sysfs_trig_list_mut); 166 166 return 0; 167 167 168 - out2: 168 + err_free_trig: 169 169 iio_trigger_free(t->trig); 170 - free_t: 170 + err_free_sys_trig: 171 171 kfree(t); 172 - out1: 172 + err_unlock: 173 173 mutex_unlock(&iio_sysfs_trig_list_mut); 174 174 return ret; 175 175 }
+2 -4
drivers/staging/iio/frequency/ad9834.c
··· 331 331 static IIO_DEV_ATTR_PHASESYMBOL(0, 0200, NULL, ad9834_write, AD9834_PSEL); 332 332 static IIO_CONST_ATTR_PHASE_SCALE(0, "0.0015339808"); /* 2PI/2^12 rad*/ 333 333 334 - static IIO_DEV_ATTR_PINCONTROL_EN(0, 0200, NULL, 335 - ad9834_write, AD9834_PIN_SW); 334 + static IIO_DEV_ATTR_PINCONTROL_EN(0, 0200, NULL, ad9834_write, AD9834_PIN_SW); 336 335 static IIO_DEV_ATTR_OUT_ENABLE(0, 0200, NULL, ad9834_write, AD9834_RESET); 337 - static IIO_DEV_ATTR_OUTY_ENABLE(0, 1, 0200, NULL, 338 - ad9834_write, AD9834_OPBITEN); 336 + static IIO_DEV_ATTR_OUTY_ENABLE(0, 1, 0200, NULL, ad9834_write, AD9834_OPBITEN); 339 337 static IIO_DEV_ATTR_OUT_WAVETYPE(0, 0, ad9834_store_wavetype, 0); 340 338 static IIO_DEV_ATTR_OUT_WAVETYPE(0, 1, ad9834_store_wavetype, 1); 341 339
+4 -1
drivers/staging/iio/meter/ade7854-i2c.c
··· 61 61 unlock: 62 62 mutex_unlock(&st->buf_lock); 63 63 64 - return ret < 0 ? ret : 0; 64 + if (ret < 0) 65 + return ret; 66 + 67 + return 0; 65 68 } 66 69 67 70 static int ade7854_i2c_read_reg(struct device *dev,
+1
include/linux/i2c.h
··· 189 189 u8 *values); 190 190 int i2c_get_device_id(const struct i2c_client *client, 191 191 struct i2c_device_identity *id); 192 + const struct i2c_device_id *i2c_client_get_device_id(const struct i2c_client *client); 192 193 #endif /* I2C */ 193 194 194 195 /**
+1 -1
include/linux/iio/buffer_impl.h
··· 123 123 struct attribute_group buffer_group; 124 124 125 125 /* @attrs: Standard attributes of the buffer. */ 126 - const struct attribute **attrs; 126 + const struct iio_dev_attr **attrs; 127 127 128 128 /* @demux_bounce: Buffer for doing gather from incoming scan. */ 129 129 void *demux_bounce;
-4
include/linux/iio/common/st_sensors.h
··· 224 224 * @mount_matrix: The mounting matrix of the sensor. 225 225 * @sensor_settings: Pointer to the specific sensor settings in use. 226 226 * @current_fullscale: Maximum range of measure by the sensor. 227 - * @vdd: Pointer to sensor's Vdd power supply 228 - * @vdd_io: Pointer to sensor's Vdd-IO power supply 229 227 * @regmap: Pointer to specific sensor regmap configuration. 230 228 * @enabled: Status of the sensor (false->off, true->on). 231 229 * @odr: Output data rate of the sensor [Hz]. ··· 242 244 struct iio_mount_matrix mount_matrix; 243 245 struct st_sensor_settings *sensor_settings; 244 246 struct st_sensor_fullscale_avl *current_fullscale; 245 - struct regulator *vdd; 246 - struct regulator *vdd_io; 247 247 struct regmap *regmap; 248 248 249 249 bool enabled;
+2
include/linux/iio/gyro/itg3200.h
··· 102 102 struct i2c_client *i2c; 103 103 struct iio_trigger *trig; 104 104 struct iio_mount_matrix orientation; 105 + /* lock to protect against multiple access to the device */ 106 + struct mutex lock; 105 107 }; 106 108 107 109 enum ITG3200_SCAN_INDEX {
+2
include/linux/iio/iio-opaque.h
··· 11 11 * checked by device drivers but should be considered 12 12 * read-only as this is a core internal bit 13 13 * @driver_module: used to make it harder to undercut users 14 + * @mlock: lock used to prevent simultaneous device state changes 14 15 * @mlock_key: lockdep class for iio_dev lock 15 16 * @info_exist_lock: lock to prevent use during removal 16 17 * @trig_readonly: mark the current trigger immutable ··· 44 43 int currentmode; 45 44 int id; 46 45 struct module *driver_module; 46 + struct mutex mlock; 47 47 struct lock_class_key mlock_key; 48 48 struct mutex info_exist_lock; 49 49 bool trig_readonly;
+2 -3
include/linux/iio/iio.h
··· 548 548 * and owner 549 549 * @buffer: [DRIVER] any buffer present 550 550 * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux 551 - * @mlock: [INTERN] lock used to prevent simultaneous device state 552 - * changes 553 551 * @available_scan_masks: [DRIVER] optional array of allowed bitmasks 554 552 * @masklength: [INTERN] the length of the mask established from 555 553 * channels ··· 572 574 573 575 struct iio_buffer *buffer; 574 576 int scan_bytes; 575 - struct mutex mlock; 576 577 577 578 const unsigned long *available_scan_masks; 578 579 unsigned masklength; ··· 626 629 int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); 627 630 int iio_device_claim_direct_mode(struct iio_dev *indio_dev); 628 631 void iio_device_release_direct_mode(struct iio_dev *indio_dev); 632 + int iio_device_claim_buffer_mode(struct iio_dev *indio_dev); 633 + void iio_device_release_buffer_mode(struct iio_dev *indio_dev); 629 634 630 635 extern struct bus_type iio_bus_type; 631 636
+2 -1
include/linux/iio/kfifo_buf.h
··· 5 5 struct iio_buffer; 6 6 struct iio_buffer_setup_ops; 7 7 struct iio_dev; 8 + struct iio_dev_attr; 8 9 struct device; 9 10 10 11 struct iio_buffer *iio_kfifo_allocate(void); ··· 14 13 int devm_iio_kfifo_buffer_setup_ext(struct device *dev, 15 14 struct iio_dev *indio_dev, 16 15 const struct iio_buffer_setup_ops *setup_ops, 17 - const struct attribute **buffer_attrs); 16 + const struct iio_dev_attr **buffer_attrs); 18 17 19 18 #define devm_iio_kfifo_buffer_setup(dev, indio_dev, setup_ops) \ 20 19 devm_iio_kfifo_buffer_setup_ext((dev), (indio_dev), (setup_ops), NULL)
+11
include/linux/iio/sysfs.h
··· 97 97 = { .string = _string, \ 98 98 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)} 99 99 100 + #define IIO_STATIC_CONST_DEVICE_ATTR(_name, _string) \ 101 + static ssize_t iio_const_dev_attr_show_##_name( \ 102 + struct device *dev, \ 103 + struct device_attribute *attr, \ 104 + char *buf) \ 105 + { \ 106 + return sysfs_emit(buf, "%s\n", _string); \ 107 + } \ 108 + static IIO_DEVICE_ATTR(_name, 0444, \ 109 + iio_const_dev_attr_show_##_name, NULL, 0) 110 + 100 111 /* Generic attributes of onetype or another */ 101 112 102 113 /**
+3 -3
include/linux/iio/triggered_buffer.h
··· 5 5 #include <linux/iio/buffer.h> 6 6 #include <linux/interrupt.h> 7 7 8 - struct attribute; 9 8 struct iio_dev; 9 + struct iio_dev_attr; 10 10 struct iio_buffer_setup_ops; 11 11 12 12 int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev, ··· 14 14 irqreturn_t (*thread)(int irq, void *p), 15 15 enum iio_buffer_direction direction, 16 16 const struct iio_buffer_setup_ops *setup_ops, 17 - const struct attribute **buffer_attrs); 17 + const struct iio_dev_attr **buffer_attrs); 18 18 void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev); 19 19 20 20 #define iio_triggered_buffer_setup(indio_dev, h, thread, setup_ops) \ ··· 28 28 irqreturn_t (*thread)(int irq, void *p), 29 29 enum iio_buffer_direction direction, 30 30 const struct iio_buffer_setup_ops *ops, 31 - const struct attribute **buffer_attrs); 31 + const struct iio_dev_attr **buffer_attrs); 32 32 33 33 #define devm_iio_triggered_buffer_setup(dev, indio_dev, h, thread, setup_ops) \ 34 34 devm_iio_triggered_buffer_setup_ext((dev), (indio_dev), (h), (thread), \