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

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

Jonathan writes:

IIO: New device support, features and cleanup for 6.18

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

ad,ade9000
- New driver for this complex energy and power monitoring ADC.
infineon,tlv493d
- New driver for this 3D magnetic sensor.
intel,dollar
- New driver for this TI PMIC (part number unknown)
marvel,88pm886
- Driver for this PMIC ADC.
microchip,mcp9600
- Add explicit support for the mcp9601 which has some additional features
over the mcp9600.
rohm,bd79112
- New driver for this ADC / GPIO Chip.

Features
========
Core
- New helper to multiply data expressed in IIO types.
- Add KUnit tests.
- New IIO_ALTCURRENT type, similar to existing IIO_ALTVOLTAGE
- Add some channel modifiers related to energy and power, such as
reactive.
adi,ad7124
- Support external clocks sources and output of the internal clocks.
- Filter control.
adi,ad7173
- Add filter support. Some fiddly interactions with other parameters on this
device.
adi,ad7779
- Add backend support which required control of the number of lanes used.
liteon,ltr390
- Add runtime PM support.
microchip,mcp9600
- Add support for different thermocouple types.

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

core
- Switch info_mask fields to be unsigned. Not clear why they were ever
signed.
- Fix handling of negative channel scale in iio_convert_raw_to_processed()
- Fix offset handling for channels without a scale attribute.
- Improve the precision of scaling slightly.
- Drop apparent handling of IIO_CHAN_INFO_PROCESSED for devices that don't
have any such channels.
various
- Drop many pm_runtime_mark_last_busy() calls now
pm_runtime_put_autosuspend() calls it internally.
- Drop dev_err_probe() calls where the error code is hard coded as -ENOMEM
as they don't do anything.
- Drop dev_err() calls where the error code is -ENOMEM. This will reduce
error prints, but memory failures generate a lot of messages anyway
so unlikely we need these prints.
current-sense-amplifier
- Add #io-channels property this channel to be used by a consumer driver.
adi,ad7124
- Fix incorrect clocks dt-binding property.
- Make the mclk clock optional in DT - this is internal to the ADC so should
never have been in he binding.
- Fix up sample rate to comply with ABI.
- Use read_avail() callback rather than opencoding similar.
- Deploy guard() to clean up some lock handling.
adi,ad7768
- Use devm_regulator_get_enable_read_voltage() to replace similar code.
adi,ad7816
- Drop an unnecessary dev_set_drvdata() call as nothing uses the data.
ad,adxl345
- Fix missing blank line before bullet list in documentation.
arm,scmi
- Use devm_kcalloc() for an array allocation rather than devm_kzalloc().
bosch,bmi270
- Match an ACPI ID seen in the wild. It is not spec compliant but we can't
do much about that.
bosch,bmp280
- Drop overly noisy dev_info()
- Allow for sleeping gpio controllers.
gogle,cros-ec
- Drop unused location attribute that has been replaced by label.
invense,icm42600
- Simplify the power management.
- Use guard() to simplify some locking.
maxim,max1238
- Add io-channel-cells property to dt-binding as there is an in tree
consumer.
microchip,mcp9600
- Specify a default value in dt-binding for the thermocouple type
- General whitespace cleanup.
samsung,exynos
- Drop support for the S3C2410 including bindings, and touchscreen support
as nothing else uses that.
- Drop platform ID based binding as not used.
st,vl53l0x
- Fix returning the wrong variable in an error path.
ti,pac1934
- Replace open coded devm_mutex_init().
xilinx,ams
- Update maintainers entry.

* tag 'iio-for-6.18a' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (178 commits)
MAINTAINERS: Support ROHM BD79112 ADC
iio: adc: Support ROHM BD79112 ADC/GPIO
dt-bindings: iio: adc: ROHM BD79112 ADC/GPIO
iio: pressure: bmp280: Use gpiod_set_value_cansleep()
iio: pressure: bmp280: Remove noisy dev_info()
iio: ABI: add filter types for ad7173
iio: adc: ad7173: support changing filter type
iio: adc: ad7173: rename odr field
iio: adc: ad7173: rename ad7173_chan_spec_ext_info
iio: adc: Add driver for Marvell 88PM886 PMIC ADC
dt-bindings: mfd: 88pm886: Add #io-channel-cells
iio: ABI: document "sinc4+rej60" filter_type
iio: adc: ad7124: add filter support
iio: adc: ad7124: support fractional sampling_frequency
iio: adc: ad7124: use guard(mutex) to simplify return paths
iio: adc: ad7124: use read_avail() for scale_available
iio: adc: ad7124: use clamp()
iio: adc: ad7124: fix sample rate for multi-channel use
Documentation: ABI: iio: add sinc4+lp
docs: iio: add documentation for ade9000 driver
...

+9192 -1864
+46 -10
Documentation/ABI/testing/sysfs-bus-iio
··· 167 167 is required is a consistent labeling. Units after application 168 168 of scale and offset are millivolts. 169 169 170 + What: /sys/bus/iio/devices/iio:deviceX/in_altvoltageY_rms_raw 171 + KernelVersion: 6.18 172 + Contact: linux-iio@vger.kernel.org 173 + Description: 174 + Raw (unscaled) Root Mean Square (RMS) voltage measurement from 175 + channel Y. Units after application of scale and offset are 176 + millivolts. 177 + 170 178 What: /sys/bus/iio/devices/iio:deviceX/in_powerY_raw 179 + What: /sys/bus/iio/devices/iio:deviceX/in_powerY_active_raw 180 + What: /sys/bus/iio/devices/iio:deviceX/in_powerY_reactive_raw 181 + What: /sys/bus/iio/devices/iio:deviceX/in_powerY_apparent_raw 171 182 KernelVersion: 4.5 172 183 Contact: linux-iio@vger.kernel.org 173 184 Description: ··· 186 175 channel Y. The number must always be specified and 187 176 unique to allow association with event codes. Units after 188 177 application of scale and offset are milliwatts. 178 + 179 + What: /sys/bus/iio/devices/iio:deviceX/in_powerY_powerfactor 180 + KernelVersion: 6.18 181 + Contact: linux-iio@vger.kernel.org 182 + Description: 183 + Power factor measurement from channel Y. Power factor is the 184 + ratio of active power to apparent power. The value is unitless. 189 185 190 186 What: /sys/bus/iio/devices/iio:deviceX/in_capacitanceY_raw 191 187 KernelVersion: 3.2 ··· 1587 1569 1588 1570 What: /sys/.../iio:deviceX/in_energy_input 1589 1571 What: /sys/.../iio:deviceX/in_energy_raw 1572 + What: /sys/.../iio:deviceX/in_energyY_active_raw 1573 + What: /sys/.../iio:deviceX/in_energyY_reactive_raw 1574 + What: /sys/.../iio:deviceX/in_energyY_apparent_raw 1590 1575 KernelVersion: 4.0 1591 1576 Contact: linux-iio@vger.kernel.org 1592 1577 Description: ··· 1727 1706 channels refer to the same signal. The 'i' channel contains the in-phase 1728 1707 component of the signal while the 'q' channel contains the quadrature 1729 1708 component. 1709 + 1710 + What: /sys/bus/iio/devices/iio:deviceX/in_altcurrentY_rms_raw 1711 + KernelVersion: 6.18 1712 + Contact: linux-iio@vger.kernel.org 1713 + Description: 1714 + Raw (unscaled no bias removal etc.) Root Mean Square (RMS) current 1715 + measurement from channel Y. Units after application of scale and 1716 + offset are milliamps. 1730 1717 1731 1718 What: /sys/.../iio:deviceX/in_energy_en 1732 1719 What: /sys/.../iio:deviceX/in_distance_en ··· 2310 2281 conversion time. Poor noise performance. 2311 2282 * "sinc3" - The digital sinc3 filter. Moderate 1st 2312 2283 conversion time. Good noise performance. 2313 - * "sinc4" - Sinc 4. Excellent noise performance. Long 2314 - 1st conversion time. 2315 - * "sinc5" - The digital sinc5 filter. Excellent noise 2316 - performance 2317 - * "sinc4+sinc1" - Sinc4 + averaging by 8. Low 1st conversion 2318 - time. 2319 - * "sinc3+rej60" - Sinc3 + 60Hz rejection. 2320 - * "sinc3+sinc1" - Sinc3 + averaging by 8. Low 1st conversion 2321 - time. 2322 2284 * "sinc3+pf1" - Sinc3 + device specific Post Filter 1. 2323 2285 * "sinc3+pf2" - Sinc3 + device specific Post Filter 2. 2324 2286 * "sinc3+pf3" - Sinc3 + device specific Post Filter 3. 2325 2287 * "sinc3+pf4" - Sinc3 + device specific Post Filter 4. 2326 - * "sinc5+pf1" - Sinc5 + device specific Post Filter 1. 2288 + * "sinc3+rej60" - Sinc3 + 60Hz rejection. 2289 + * "sinc3+sinc1" - Sinc3 + averaging by 8. Low 1st conversion 2290 + time. 2291 + * "sinc4" - Sinc 4. Excellent noise performance. Long 2292 + 1st conversion time. 2293 + * "sinc4+lp" - Sinc4 + Low Pass Filter. 2294 + * "sinc4+sinc1" - Sinc4 + averaging by 8. Low 1st conversion 2295 + time. 2296 + * "sinc4+rej60" - Sinc4 + 60Hz rejection. 2297 + * "sinc5" - The digital sinc5 filter. Excellent noise 2298 + performance 2327 2299 * "sinc5+avg" - Sinc5 + averaging by 4. 2300 + * "sinc5+pf1" - Sinc5 + device specific Post Filter 1. 2301 + * "sinc5+sinc1" - Sinc5 + Sinc1. 2302 + * "sinc5+sinc1+pf1" - Sinc5 + Sinc1 + device specific Post Filter 1. 2303 + * "sinc5+sinc1+pf2" - Sinc5 + Sinc1 + device specific Post Filter 2. 2304 + * "sinc5+sinc1+pf3" - Sinc5 + Sinc1 + device specific Post Filter 3. 2305 + * "sinc5+sinc1+pf4" - Sinc5 + Sinc1 + device specific Post Filter 4. 2328 2306 * "wideband" - filter with wideband low ripple passband 2329 2307 and sharp transition band. 2330 2308
-10
Documentation/ABI/testing/sysfs-bus-iio-cros-ec
··· 7 7 corresponding calibration offsets can be read from `*_calibbias` 8 8 entries. 9 9 10 - What: /sys/bus/iio/devices/iio:deviceX/location 11 - Date: July 2015 12 - KernelVersion: 4.7 13 - Contact: linux-iio@vger.kernel.org 14 - Description: 15 - This attribute returns a string with the physical location where 16 - the motion sensor is placed. For example, in a laptop a motion 17 - sensor can be located on the base or on the lid. Current valid 18 - values are 'base' and 'lid'. 19 - 20 10 What: /sys/bus/iio/devices/iio:deviceX/id 21 11 Date: September 2017 22 12 KernelVersion: 4.14
+2 -2
Documentation/devicetree/bindings/iio/accel/adi,adis16240.yaml
··· 7 7 title: ADIS16240 Programmable Impact Sensor and Recorder driver 8 8 9 9 maintainers: 10 - - Alexandru Tachici <alexandru.tachici@analog.com> 10 + - Marcelo Schmitt <marcelo.schmitt@analog.com> 11 + - Nuno Sá <nuno.sa@analog.com> 11 12 12 13 description: | 13 14 ADIS16240 Programmable Impact Sensor and Recorder driver that supports ··· 38 37 39 38 examples: 40 39 - | 41 - #include <dt-bindings/gpio/gpio.h> 42 40 #include <dt-bindings/interrupt-controller/irq.h> 43 41 spi { 44 42 #address-cells = <1>;
-2
Documentation/devicetree/bindings/iio/accel/adi,adxl313.yaml
··· 57 57 58 58 examples: 59 59 - | 60 - #include <dt-bindings/gpio/gpio.h> 61 60 #include <dt-bindings/interrupt-controller/irq.h> 62 61 i2c { 63 62 #address-cells = <1>; ··· 72 73 }; 73 74 }; 74 75 - | 75 - #include <dt-bindings/gpio/gpio.h> 76 76 #include <dt-bindings/interrupt-controller/irq.h> 77 77 spi { 78 78 #address-cells = <1>;
-2
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml
··· 56 56 57 57 examples: 58 58 - | 59 - #include <dt-bindings/gpio/gpio.h> 60 59 #include <dt-bindings/interrupt-controller/irq.h> 61 60 i2c { 62 61 #address-cells = <1>; ··· 71 72 }; 72 73 }; 73 74 - | 74 - #include <dt-bindings/gpio/gpio.h> 75 75 #include <dt-bindings/interrupt-controller/irq.h> 76 76 spi { 77 77 #address-cells = <1>;
-2
Documentation/devicetree/bindings/iio/accel/adi,adxl355.yaml
··· 58 58 59 59 examples: 60 60 - | 61 - #include <dt-bindings/gpio/gpio.h> 62 61 #include <dt-bindings/interrupt-controller/irq.h> 63 62 i2c { 64 63 #address-cells = <1>; ··· 73 74 }; 74 75 }; 75 76 - | 76 - #include <dt-bindings/gpio/gpio.h> 77 77 #include <dt-bindings/interrupt-controller/irq.h> 78 78 spi { 79 79 #address-cells = <1>;
+2 -3
Documentation/devicetree/bindings/iio/accel/adi,adxl372.yaml
··· 7 7 title: Analog Devices ADXL372 3-Axis, +/-(200g) Digital Accelerometer 8 8 9 9 maintainers: 10 - - Stefan Popa <stefan.popa@analog.com> 10 + - Marcelo Schmitt <marcelo.schmitt@analog.com> 11 + - Nuno Sá <nuno.sa@analog.com> 11 12 12 13 description: | 13 14 Analog Devices ADXL372 3-Axis, +/-(200g) Digital Accelerometer that supports ··· 38 37 39 38 examples: 40 39 - | 41 - #include <dt-bindings/gpio/gpio.h> 42 40 #include <dt-bindings/interrupt-controller/irq.h> 43 41 i2c { 44 42 #address-cells = <1>; ··· 52 52 }; 53 53 }; 54 54 - | 55 - #include <dt-bindings/gpio/gpio.h> 56 55 #include <dt-bindings/interrupt-controller/irq.h> 57 56 spi { 58 57 #address-cells = <1>;
-1
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml
··· 107 107 }; 108 108 }; 109 109 - | 110 - # include <dt-bindings/interrupt-controller/irq.h> 111 110 spi { 112 111 #address-cells = <1>; 113 112 #size-cells = <0>;
-1
Documentation/devicetree/bindings/iio/accel/bosch,bma400.yaml
··· 40 40 41 41 examples: 42 42 - | 43 - #include <dt-bindings/gpio/gpio.h> 44 43 #include <dt-bindings/interrupt-controller/irq.h> 45 44 i2c { 46 45 #address-cells = <1>;
-1
Documentation/devicetree/bindings/iio/accel/kionix,kxsd9.yaml
··· 57 57 }; 58 58 }; 59 59 - | 60 - # include <dt-bindings/interrupt-controller/irq.h> 61 60 spi { 62 61 #address-cells = <1>; 63 62 #size-cells = <0>;
-1
Documentation/devicetree/bindings/iio/adc/adi,ad7091r5.yaml
··· 93 93 94 94 examples: 95 95 - | 96 - #include <dt-bindings/gpio/gpio.h> 97 96 #include <dt-bindings/interrupt-controller/irq.h> 98 97 i2c { 99 98 #address-cells = <1>;
+18 -6
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
··· 8 8 title: Analog Devices AD7124 ADC device driver 9 9 10 10 maintainers: 11 - - Stefan Popa <stefan.popa@analog.com> 11 + - Marcelo Schmitt <marcelo.schmitt@analog.com> 12 + - Nuno Sá <nuno.sa@analog.com> 12 13 13 14 description: | 14 15 Bindings for the Analog Devices AD7124 ADC device. Datasheet can be ··· 28 27 29 28 clocks: 30 29 maxItems: 1 31 - description: phandle to the master clock (mclk) 30 + description: Optional external clock connected to the CLK pin. 32 31 33 32 clock-names: 33 + deprecated: true 34 + description: 35 + MCLK is an internal counter in the ADC. Do not use this property. 34 36 items: 35 37 - const: mclk 38 + 39 + '#clock-cells': 40 + description: 41 + The CLK pin can be used as an output. When that is the case, include 42 + this property. 43 + const: 0 36 44 37 45 interrupts: 38 46 description: IRQ line for the ADC ··· 76 66 required: 77 67 - compatible 78 68 - reg 79 - - clocks 80 - - clock-names 81 69 - interrupts 70 + 71 + # Can't have both clock input and output at the same time. 72 + not: 73 + required: 74 + - '#clock-cells' 75 + - clocks 82 76 83 77 patternProperties: 84 78 "^channel@([0-9]|1[0-5])$": ··· 149 135 interrupt-parent = <&gpio>; 150 136 rdy-gpios = <&gpio 25 GPIO_ACTIVE_LOW>; 151 137 refin1-supply = <&adc_vref>; 152 - clocks = <&ad7124_mclk>; 153 - clock-names = "mclk"; 154 138 155 139 #address-cells = <1>; 156 140 #size-cells = <0>;
-1
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml
··· 379 379 examples: 380 380 # Example AD7173-8 with external reference connected to REF+/REF-: 381 381 - | 382 - #include <dt-bindings/gpio/gpio.h> 383 382 #include <dt-bindings/interrupt-controller/irq.h> 384 383 385 384 spi {
+74 -28
Documentation/devicetree/bindings/iio/adc/adi,ad7476.yaml
··· 41 41 - adi,ad7910 42 42 - adi,ad7920 43 43 - adi,ad7940 44 + - rohm,bd79105 44 45 - ti,adc081s 45 46 - ti,adc101s 46 47 - ti,adc121s ··· 54 53 - const: ti,ads7866 55 54 56 55 reg: 56 + maxItems: 1 57 + 58 + interrupts: 59 + description: 60 + The data-ready interrupt. Provided via DOUT pin. 57 61 maxItems: 1 58 62 59 63 vcc-supply: ··· 81 75 description: A GPIO used to trigger the start of a conversion 82 76 maxItems: 1 83 77 78 + rdy-gpios: 79 + description: A GPIO for detecting the data-ready. 80 + maxItems: 1 81 + 84 82 required: 85 83 - compatible 86 84 - reg 87 85 88 86 allOf: 89 87 - $ref: /schemas/spi/spi-peripheral-props.yaml# 88 + 89 + # Devices with an IRQ 90 + - if: 91 + properties: 92 + compatible: 93 + contains: 94 + enum: 95 + - rohm,bd79105 96 + then: 97 + properties: 98 + interrupts: true 99 + else: 100 + properties: 101 + interrupts: false 90 102 91 103 # Devices where reference is vcc 92 104 - if: ··· 130 106 - vcc-supply 131 107 # Devices with a vref 132 108 - if: 133 - properties: 134 - compatible: 135 - contains: 136 - enum: 137 - - adi,ad7091r 138 - - adi,ad7273 139 - - adi,ad7274 140 - - adi,ad7475 141 - - lltc,ltc2314-14 109 + not: 110 + properties: 111 + compatible: 112 + contains: 113 + enum: 114 + - adi,ad7091r 115 + - adi,ad7273 116 + - adi,ad7274 117 + - adi,ad7475 118 + - lltc,ltc2314-14 119 + - rohm,bd79105 142 120 then: 143 - properties: 144 - vref-supply: true 145 - else: 146 121 properties: 147 122 vref-supply: false 148 123 # Devices with a vref where it is not optional ··· 154 131 - adi,ad7274 155 132 - adi,ad7475 156 133 - lltc,ltc2314-14 134 + - rohm,bd79105 157 135 then: 158 136 required: 159 137 - vref-supply 160 138 - if: 161 - properties: 162 - compatible: 163 - contains: 164 - enum: 165 - - adi,ad7475 166 - - adi,ad7495 139 + not: 140 + properties: 141 + compatible: 142 + contains: 143 + enum: 144 + - adi,ad7475 145 + - adi,ad7495 146 + - rohm,bd79105 167 147 then: 168 148 properties: 169 - vdrive-supply: true 170 - else: 171 - properties: 172 149 vdrive-supply: false 150 + 151 + # Devices which support polling the data-ready via GPIO 152 + - if: 153 + not: 154 + properties: 155 + compatible: 156 + contains: 157 + enum: 158 + - rohm,bd79105 159 + then: 160 + properties: 161 + rdy-gpios: false 162 + 163 + - if: 164 + not: 165 + properties: 166 + compatible: 167 + contains: 168 + enum: 169 + - adi,ad7091 170 + - adi,ad7091r 171 + - rohm,bd79105 172 + then: 173 + properties: 174 + adi,conversion-start-gpios: false 175 + 176 + # Devices with a convstart GPIO where it is not optional 173 177 - if: 174 178 properties: 175 179 compatible: 176 180 contains: 177 181 enum: 178 - - adi,ad7091 179 - - adi,ad7091r 182 + - rohm,bd79105 180 183 then: 181 - properties: 182 - adi,conversion-start-gpios: true 183 - else: 184 - properties: 185 - adi,conversion-start-gpios: false 184 + required: 185 + - adi,conversion-start-gpios 186 186 187 187 unevaluatedProperties: false 188 188
+43 -1
Documentation/devicetree/bindings/iio/adc/adi,ad7779.yaml
··· 80 80 reset-gpios: 81 81 maxItems: 1 82 82 83 + io-backends: 84 + maxItems: 1 85 + 86 + adi,num-lanes: 87 + description: 88 + Number of lanes on which the data is sent on the output when the data 89 + output interface is used. 90 + $ref: /schemas/types.yaml#/definitions/uint32 91 + enum: [1, 2, 4] 92 + default: 4 93 + 83 94 required: 84 95 - compatible 85 96 - reg 86 97 - clocks 87 - - interrupts 98 + 99 + allOf: 100 + - if: 101 + not: 102 + required: 103 + - io-backends 104 + then: 105 + properties: 106 + adi,num-lanes: false 107 + 108 + oneOf: 109 + - required: 110 + - interrupts 111 + - required: 112 + - io-backends 88 113 89 114 unevaluatedProperties: false 90 115 ··· 130 105 interrupts = <0 56 IRQ_TYPE_LEVEL_HIGH>; 131 106 interrupt-names = "adc_rdy"; 132 107 clocks = <&adc_clk>; 108 + }; 109 + }; 110 + 111 + - | 112 + #include <dt-bindings/gpio/gpio.h> 113 + spi { 114 + #address-cells = <1>; 115 + #size-cells = <0>; 116 + 117 + adc@0 { 118 + compatible = "adi,ad7779"; 119 + reg = <0>; 120 + start-gpios = <&gpio0 87 GPIO_ACTIVE_LOW>; 121 + reset-gpios = <&gpio0 93 GPIO_ACTIVE_LOW>; 122 + clocks = <&adc_clk>; 123 + io-backends = <&iio_backend>; 124 + adi,num-lanes = <4>; 133 125 }; 134 126 }; 135 127 ...
+95
Documentation/devicetree/bindings/iio/adc/adi,ade9000.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + # Copyright 2025 Analog Devices Inc. 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/iio/adc/adi,ade9000.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: Analog Devices ADE9000 High Performance, Polyphase Energy Metering 9 + 10 + maintainers: 11 + - Antoniu Miclaus <antoniu.miclaus@analog.com> 12 + 13 + description: | 14 + The ADE9000 is a highly accurate, fully integrated, multiphase energy and power 15 + quality monitoring device. Superior analog performance and a digital signal 16 + processing (DSP) core enable accurate energy monitoring over a wide dynamic 17 + range. An integrated high end reference ensures low drift over temperature 18 + with a combined drift of less than ±25 ppm/°C maximum for the entire channel 19 + including a programmable gain amplifier (PGA) and an analog-to-digital 20 + converter (ADC). 21 + 22 + https://www.analog.com/media/en/technical-documentation/data-sheets/ADE9000.pdf 23 + 24 + $ref: /schemas/spi/spi-peripheral-props.yaml# 25 + 26 + properties: 27 + compatible: 28 + enum: 29 + - adi,ade9000 30 + 31 + reg: 32 + maxItems: 1 33 + 34 + spi-max-frequency: 35 + maximum: 20000000 36 + 37 + interrupts: 38 + maxItems: 3 39 + 40 + interrupt-names: 41 + items: 42 + enum: [irq0, irq1, dready] 43 + minItems: 1 44 + maxItems: 3 45 + 46 + reset-gpios: 47 + description: 48 + Must be the device tree identifier of the RESET pin. As the line is 49 + active low, it should be marked GPIO_ACTIVE_LOW. 50 + maxItems: 1 51 + 52 + vdd-supply: true 53 + 54 + vref-supply: true 55 + 56 + clocks: 57 + description: External clock source when not using crystal 58 + maxItems: 1 59 + 60 + 61 + "#clock-cells": 62 + description: 63 + ADE9000 can provide clock output via CLKOUT pin with external buffer. 64 + const: 0 65 + 66 + required: 67 + - compatible 68 + - reg 69 + - vdd-supply 70 + 71 + unevaluatedProperties: false 72 + 73 + examples: 74 + - | 75 + #include <dt-bindings/gpio/gpio.h> 76 + #include <dt-bindings/interrupt-controller/irq.h> 77 + 78 + spi { 79 + #address-cells = <1>; 80 + #size-cells = <0>; 81 + 82 + adc@0 { 83 + compatible = "adi,ade9000"; 84 + reg = <0>; 85 + spi-max-frequency = <7000000>; 86 + 87 + #clock-cells = <0>; 88 + reset-gpios = <&gpio 4 GPIO_ACTIVE_LOW>; 89 + interrupts = <2 IRQ_TYPE_EDGE_FALLING>, <3 IRQ_TYPE_EDGE_FALLING>, <4 IRQ_TYPE_EDGE_FALLING>; 90 + interrupt-names = "irq0", "irq1", "dready"; 91 + interrupt-parent = <&gpio>; 92 + clocks = <&ext_clock_24576khz>; 93 + vdd-supply = <&vdd_reg>; 94 + }; 95 + };
-1
Documentation/devicetree/bindings/iio/adc/lltc,ltc2496.yaml
··· 9 9 maintainers: 10 10 - Lars-Peter Clausen <lars@metafoo.de> 11 11 - Michael Hennerich <Michael.Hennerich@analog.com> 12 - - Stefan Popa <stefan.popa@analog.com> 13 12 14 13 properties: 15 14 compatible:
+3
Documentation/devicetree/bindings/iio/adc/maxim,max1238.yaml
··· 53 53 reg: 54 54 maxItems: 1 55 55 56 + "#io-channel-cells": 57 + const: 1 58 + 56 59 vcc-supply: true 57 60 vref-supply: 58 61 description: Optional external reference. If not supplied, internal
+1 -1
Documentation/devicetree/bindings/iio/adc/maxim,max1241.yaml
··· 63 63 vdd-supply = <&adc_vdd>; 64 64 vref-supply = <&adc_vref>; 65 65 spi-max-frequency = <1000000>; 66 - shutdown-gpios = <&gpio 26 1>; 66 + shutdown-gpios = <&gpio 26 GPIO_ACTIVE_LOW>; 67 67 }; 68 68 };
-1
Documentation/devicetree/bindings/iio/adc/qcom,spmi-vadc.yaml
··· 278 278 - | 279 279 #include <dt-bindings/iio/qcom,spmi-adc7-pmk8350.h> 280 280 #include <dt-bindings/iio/qcom,spmi-adc7-pm8350.h> 281 - #include <dt-bindings/interrupt-controller/irq.h> 282 281 283 282 pmic { 284 283 #address-cells = <1>;
+3
Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml
··· 47 47 - const: saradc 48 48 - const: apb_pclk 49 49 50 + power-domains: 51 + maxItems: 1 52 + 50 53 resets: 51 54 maxItems: 1 52 55
+9 -2
Documentation/devicetree/bindings/iio/adc/rohm,bd79104.yaml
··· 14 14 15 15 properties: 16 16 compatible: 17 - const: rohm,bd79104 17 + oneOf: 18 + - enum: 19 + - rohm,bd79100 20 + - rohm,bd79101 21 + - rohm,bd79102 22 + - rohm,bd79104 23 + - items: 24 + - const: rohm,bd79103 25 + - const: rohm,bd79104 18 26 19 27 reg: 20 28 maxItems: 1 ··· 58 50 59 51 examples: 60 52 - | 61 - #include <dt-bindings/interrupt-controller/irq.h> 62 53 spi { 63 54 #address-cells = <1>; 64 55 #size-cells = <0>;
+104
Documentation/devicetree/bindings/iio/adc/rohm,bd79112.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/adc/rohm,bd79112.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: ROHM BD79112 ADC/GPO 8 + 9 + maintainers: 10 + - Matti Vaittinen <mazziesaccount@gmail.com> 11 + 12 + description: | 13 + The ROHM BD79112 is a 12-bit, 32-channel, SAR ADC. ADC input pins can be 14 + also configured as general purpose inputs/outputs. SPI should use MODE 3. 15 + 16 + properties: 17 + compatible: 18 + const: rohm,bd79112 19 + 20 + reg: 21 + maxItems: 1 22 + 23 + spi-cpha: true 24 + spi-cpol: true 25 + 26 + gpio-controller: true 27 + "#gpio-cells": 28 + const: 2 29 + 30 + vdd-supply: true 31 + 32 + iovdd-supply: true 33 + 34 + "#address-cells": 35 + const: 1 36 + 37 + "#size-cells": 38 + const: 0 39 + 40 + patternProperties: 41 + "^channel@([0-9]|[12][0-9]|3[01])$": 42 + type: object 43 + $ref: /schemas/iio/adc/adc.yaml# 44 + description: Represents ADC channel. Omitted channels' inputs are GPIOs. 45 + 46 + properties: 47 + reg: 48 + description: AIN pin number 49 + minimum: 0 50 + maximum: 31 51 + 52 + required: 53 + - reg 54 + 55 + additionalProperties: false 56 + 57 + required: 58 + - compatible 59 + - reg 60 + - iovdd-supply 61 + - vdd-supply 62 + - spi-cpha 63 + - spi-cpol 64 + 65 + additionalProperties: false 66 + 67 + examples: 68 + - | 69 + spi { 70 + #address-cells = <1>; 71 + #size-cells = <0>; 72 + adc: adc@0 { 73 + compatible = "rohm,bd79112"; 74 + reg = <0x0>; 75 + 76 + spi-cpha; 77 + spi-cpol; 78 + 79 + vdd-supply = <&dummyreg>; 80 + iovdd-supply = <&dummyreg>; 81 + 82 + #address-cells = <1>; 83 + #size-cells = <0>; 84 + 85 + gpio-controller; 86 + #gpio-cells = <2>; 87 + 88 + channel@0 { 89 + reg = <0>; 90 + }; 91 + channel@1 { 92 + reg = <1>; 93 + }; 94 + channel@2 { 95 + reg = <2>; 96 + }; 97 + channel@16 { 98 + reg = <16>; 99 + }; 100 + channel@20 { 101 + reg = <20>; 102 + }; 103 + }; 104 + };
+1 -1
Documentation/devicetree/bindings/iio/adc/rohm,bd79124.yaml
··· 81 81 reg = <0x10>; 82 82 83 83 interrupt-parent = <&gpio1>; 84 - interrupts = <29 8>; 84 + interrupts = <29 IRQ_TYPE_LEVEL_LOW>; 85 85 86 86 vdd-supply = <&dummyreg>; 87 87 iovdd-supply = <&dummyreg>;
+16 -17
Documentation/devicetree/bindings/iio/adc/samsung,exynos-adc.yaml
··· 18 18 - samsung,exynos3250-adc 19 19 - samsung,exynos4212-adc # Exynos4212 and Exynos4412 20 20 - samsung,exynos7-adc 21 - - samsung,s3c2410-adc 22 - - samsung,s3c2416-adc 23 - - samsung,s3c2440-adc 24 - - samsung,s3c2443-adc 25 21 - samsung,s3c6410-adc 26 22 - samsung,s5pv210-adc 27 23 - items: ··· 42 46 maxItems: 2 43 47 44 48 interrupts: 45 - description: 46 - ADC interrupt followed by optional touchscreen interrupt. 47 49 minItems: 1 48 50 maxItems: 2 49 51 ··· 55 61 description: 56 62 Phandle to the PMU system controller node (to access the ADC_PHY 57 63 register on Exynos3250/4x12/5250/5420/5800). 58 - 59 - has-touchscreen: 60 - description: 61 - If present, indicates that a touchscreen is connected and usable. 62 - type: boolean 63 64 64 65 required: 65 66 - compatible ··· 107 118 - const: adc 108 119 109 120 - if: 110 - required: 111 - - has-touchscreen 121 + properties: 122 + compatible: 123 + contains: 124 + const: samsung,s5pv210-adc 112 125 then: 113 126 properties: 114 127 interrupts: 115 - minItems: 2 116 - maxItems: 2 128 + items: 129 + - description: main (ADC) 130 + - description: pending (PENDN) 131 + else: 132 + properties: 133 + interrupts: 134 + maxItems: 1 117 135 118 136 examples: 119 137 - | 138 + #include <dt-bindings/interrupt-controller/arm-gic.h> 139 + 120 140 adc: adc@12d10000 { 121 141 compatible = "samsung,exynos-adc-v1"; 122 142 reg = <0x12d10000 0x100>; 123 - interrupts = <0 106 0>; 143 + interrupts = <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>; 124 144 #io-channel-cells = <1>; 125 145 126 146 clocks = <&clock 303>; ··· 150 152 151 153 - | 152 154 #include <dt-bindings/clock/exynos3250.h> 155 + #include <dt-bindings/interrupt-controller/arm-gic.h> 153 156 154 157 adc@126c0000 { 155 158 compatible = "samsung,exynos3250-adc"; 156 159 reg = <0x126c0000 0x100>; 157 - interrupts = <0 137 0>; 160 + interrupts = <GIC_SPI 137 IRQ_TYPE_LEVEL_HIGH>; 158 161 #io-channel-cells = <1>; 159 162 160 163 clocks = <&cmu CLK_TSADC>,
-1
Documentation/devicetree/bindings/iio/adc/ti,adc128s052.yaml
··· 44 44 45 45 examples: 46 46 - | 47 - #include <dt-bindings/interrupt-controller/irq.h> 48 47 spi { 49 48 #address-cells = <1>; 50 49 #size-cells = <0>;
-1
Documentation/devicetree/bindings/iio/adc/ti,ads1298.yaml
··· 59 59 60 60 examples: 61 61 - | 62 - #include <dt-bindings/gpio/gpio.h> 63 62 #include <dt-bindings/interrupt-controller/irq.h> 64 63 spi { 65 64 #address-cells = <1>;
+2 -1
Documentation/devicetree/bindings/iio/adc/xlnx,zynqmp-ams.yaml
··· 7 7 title: Xilinx Zynq Ultrascale AMS controller 8 8 9 9 maintainers: 10 - - Anand Ashok Dumbre <anand.ashok.dumbre@xilinx.com> 10 + - Salih Erim <salih.erim@amd.com> 11 + - Conall O'Griofa <conall.ogriofa@amd.com> 11 12 12 13 description: | 13 14 The AMS (Analog Monitoring System) includes an ADC as well as on-chip sensors
+4
Documentation/devicetree/bindings/iio/afe/current-sense-amplifier.yaml
··· 24 24 description: | 25 25 Channel node of a voltage io-channel. 26 26 27 + "#io-channel-cells": 28 + const: 0 29 + 27 30 sense-resistor-micro-ohms: 28 31 description: The sense resistance. 29 32 ··· 49 46 - | 50 47 sysi { 51 48 compatible = "current-sense-amplifier"; 49 + #io-channel-cells = <0>; 52 50 io-channels = <&tiadc 0>; 53 51 54 52 sense-resistor-micro-ohms = <20000>;
+2 -1
Documentation/devicetree/bindings/iio/dac/adi,ad5770r.yaml
··· 8 8 title: Analog Devices AD5770R DAC device driver 9 9 10 10 maintainers: 11 - - Alexandru Tachici <alexandru.tachici@analog.com> 11 + - Marcelo Schmitt <marcelo.schmitt@analog.com> 12 + - Nuno Sá <nuno.sa@analog.com> 12 13 13 14 description: | 14 15 Bindings for the Analog Devices AD5770R current DAC device. Datasheet can be
+1 -1
Documentation/devicetree/bindings/iio/dac/adi,ltc2664.yaml
··· 174 174 175 175 channel@1 { 176 176 reg = <1>; 177 - output-range-microvolt= <0 10000000>; 177 + output-range-microvolt = <0 10000000>; 178 178 }; 179 179 }; 180 180 };
+2 -1
Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
··· 7 7 title: Analog Devices ADF4371/ADF4372 Wideband Synthesizers 8 8 9 9 maintainers: 10 - - Popa Stefan <stefan.popa@analog.com> 10 + - Marcelo Schmitt <marcelo.schmitt@analog.com> 11 + - Nuno Sá <nuno.sa@analog.com> 11 12 12 13 description: | 13 14 Analog Devices ADF4371/ADF4372 SPI Wideband Synthesizers
-1
Documentation/devicetree/bindings/iio/imu/adi,adis16460.yaml
··· 44 44 45 45 examples: 46 46 - | 47 - #include <dt-bindings/gpio/gpio.h> 48 47 #include <dt-bindings/interrupt-controller/irq.h> 49 48 spi { 50 49 #address-cells = <1>;
+2 -1
Documentation/devicetree/bindings/iio/imu/adi,adis16480.yaml
··· 7 7 title: Analog Devices ADIS16480 and similar IMUs 8 8 9 9 maintainers: 10 - - Alexandru Tachici <alexandru.tachici@analog.com> 10 + - Marcelo Schmitt <marcelo.schmitt@analog.com> 11 + - Nuno Sá <nuno.sa@analog.com> 11 12 12 13 properties: 13 14 compatible:
-2
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml
··· 74 74 75 75 examples: 76 76 - | 77 - #include <dt-bindings/gpio/gpio.h> 78 77 #include <dt-bindings/interrupt-controller/irq.h> 79 78 i2c { 80 79 #address-cells = <1>; ··· 90 91 }; 91 92 }; 92 93 - | 93 - #include <dt-bindings/gpio/gpio.h> 94 94 #include <dt-bindings/interrupt-controller/irq.h> 95 95 spi { 96 96 #address-cells = <1>;
-2
Documentation/devicetree/bindings/iio/imu/nxp,fxos8700.yaml
··· 47 47 48 48 examples: 49 49 - | 50 - #include <dt-bindings/gpio/gpio.h> 51 50 #include <dt-bindings/interrupt-controller/irq.h> 52 51 i2c { 53 52 #address-cells = <1>; ··· 62 63 }; 63 64 }; 64 65 - | 65 - #include <dt-bindings/gpio/gpio.h> 66 66 #include <dt-bindings/interrupt-controller/irq.h> 67 67 spi { 68 68 #address-cells = <1>;
+1 -1
Documentation/devicetree/bindings/iio/light/dynaimage,al3010.yaml
··· 42 42 compatible = "dynaimage,al3010"; 43 43 reg = <0x1c>; 44 44 vdd-supply = <&vdd_reg>; 45 - interrupts = <0 99 4>; 45 + interrupts = <99 IRQ_TYPE_LEVEL_HIGH>; 46 46 }; 47 47 };
+1 -1
Documentation/devicetree/bindings/iio/light/dynaimage,al3320a.yaml
··· 40 40 compatible = "dynaimage,al3320a"; 41 41 reg = <0x1c>; 42 42 vdd-supply = <&vdd_reg>; 43 - interrupts = <0 99 4>; 43 + interrupts = <99 IRQ_TYPE_LEVEL_HIGH>; 44 44 }; 45 45 };
-1
Documentation/devicetree/bindings/iio/light/st,vl6180.yaml
··· 32 32 33 33 examples: 34 34 - | 35 - #include <dt-bindings/interrupt-controller/irq.h> 36 35 i2c { 37 36 #address-cells = <1>; 38 37 #size-cells = <0>;
+51
Documentation/devicetree/bindings/iio/light/vishay,veml6046x00.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/light/vishay,veml6046x00.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Vishay VEML6046X00 High accuracy RGBIR color sensor 8 + 9 + maintainers: 10 + - Andreas Klinger <ak@it-klinger.de> 11 + 12 + description: 13 + VEML6046X00 datasheet at https://www.vishay.com/docs/80173/veml6046x00.pdf 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - vishay,veml6046x00 19 + 20 + reg: 21 + maxItems: 1 22 + 23 + vdd-supply: true 24 + 25 + interrupts: 26 + maxItems: 1 27 + 28 + required: 29 + - compatible 30 + - reg 31 + - vdd-supply 32 + 33 + additionalProperties: false 34 + 35 + examples: 36 + - | 37 + #include <dt-bindings/interrupt-controller/irq.h> 38 + 39 + i2c { 40 + #address-cells = <1>; 41 + #size-cells = <0>; 42 + 43 + color-sensor@29 { 44 + compatible = "vishay,veml6046x00"; 45 + reg = <0x29>; 46 + vdd-supply = <&vdd_reg>; 47 + interrupt-parent = <&gpio2>; 48 + interrupts = <3 IRQ_TYPE_EDGE_FALLING>; 49 + }; 50 + }; 51 + ...
+45
Documentation/devicetree/bindings/iio/magnetometer/infineon,tlv493d-a1b6.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/magnetometer/infineon,tlv493d-a1b6.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Infineon Technologies TLV493D Low-Power 3D Magnetic Sensor 8 + 9 + maintainers: 10 + - Dixit Parmar <dixitparmar19@gmail.com> 11 + 12 + properties: 13 + $nodename: 14 + pattern: '^magnetometer@[0-9a-f]+$' 15 + 16 + compatible: 17 + const: infineon,tlv493d-a1b6 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + vdd-supply: 23 + description: 2.8V to 3.5V VDD supply 24 + 25 + interrupts: 26 + maxItems: 1 27 + 28 + required: 29 + - compatible 30 + - reg 31 + - vdd-supply 32 + 33 + additionalProperties: false 34 + 35 + examples: 36 + - | 37 + i2c { 38 + #address-cells = <1>; 39 + #size-cells = <0>; 40 + magnetometer@5e { 41 + compatible = "infineon,tlv493d-a1b6"; 42 + reg = <0x5e>; 43 + vdd-supply = <&hall_vcc>; 44 + }; 45 + };
-1
Documentation/devicetree/bindings/iio/magnetometer/voltafield,af8133j.yaml
··· 44 44 45 45 examples: 46 46 - | 47 - #include <dt-bindings/interrupt-controller/irq.h> 48 47 #include <dt-bindings/gpio/gpio.h> 49 48 i2c { 50 49 #address-cells = <1>;
-1
Documentation/devicetree/bindings/iio/pressure/bmp085.yaml
··· 109 109 }; 110 110 - | 111 111 # include <dt-bindings/gpio/gpio.h> 112 - # include <dt-bindings/interrupt-controller/irq.h> 113 112 spi { 114 113 #address-cells = <1>; 115 114 #size-cells = <0>;
+52
Documentation/devicetree/bindings/iio/pressure/invensense,icp10100.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/pressure/invensense,icp10100.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: InvenSense ICP-101xx Barometric Pressure Sensors 8 + 9 + maintainers: 10 + - Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com> 11 + 12 + description: | 13 + Support for ICP-101xx family: ICP-10100, ICP-10101, ICP-10110, ICP-10111. 14 + Those devices uses a simple I2C communication bus, measuring the pressure 15 + in a ultra-low noise at the lowest power. 16 + Datasheet: https://product.tdk.com/system/files/dam/doc/product/sensor/pressure/capacitive-pressure/data_sheet/ds-000186-icp-101xx.pdf 17 + 18 + properties: 19 + compatible: 20 + oneOf: 21 + - items: 22 + - enum: 23 + - invensense,icp10101 24 + - invensense,icp10110 25 + - invensense,icp10111 26 + - const: invensense,icp10100 27 + - const: invensense,icp10100 28 + 29 + reg: 30 + maxItems: 1 31 + 32 + vdd-supply: true 33 + 34 + required: 35 + - compatible 36 + - reg 37 + - vdd-supply 38 + 39 + additionalProperties: false 40 + 41 + examples: 42 + - | 43 + i2c { 44 + #address-cells = <1>; 45 + #size-cells = <0>; 46 + pressure@63 { 47 + compatible = "invensense,icp10101", "invensense,icp10100"; 48 + reg = <0x63>; 49 + vdd-supply = <&vdd_1v8>; 50 + }; 51 + }; 52 + ...
+53 -3
Documentation/devicetree/bindings/iio/temperature/microchip,mcp9600.yaml
··· 4 4 $id: http://devicetree.org/schemas/iio/temperature/microchip,mcp9600.yaml# 5 5 $schema: http://devicetree.org/meta-schemas/core.yaml# 6 6 7 - title: Microchip MCP9600 thermocouple EMF converter 7 + title: Microchip MCP9600 and similar thermocouple EMF converters 8 8 9 9 maintainers: 10 10 - Andrew Hepp <andrew.hepp@ahepp.dev> ··· 14 14 15 15 properties: 16 16 compatible: 17 - const: microchip,mcp9600 17 + oneOf: 18 + - const: microchip,mcp9600 19 + - items: 20 + - const: microchip,mcp9601 21 + - const: microchip,mcp9600 18 22 19 23 reg: 20 24 maxItems: 1 ··· 41 37 42 38 thermocouple-type: 43 39 $ref: /schemas/types.yaml#/definitions/uint32 40 + default: 3 44 41 description: 45 42 Type of thermocouple (THERMOCOUPLE_TYPE_K if omitted). 46 43 Use defines in dt-bindings/iio/temperature/thermocouple.h. 47 44 Supported types are B, E, J, K, N, R, S, T. 48 45 46 + microchip,vsense: 47 + type: boolean 48 + description: 49 + This flag indicates that the chip has been wired with VSENSE to 50 + enable open and short circuit detect. 51 + 49 52 vdd-supply: true 53 + 54 + allOf: 55 + - if: 56 + properties: 57 + compatible: 58 + not: 59 + contains: 60 + const: microchip,mcp9601 61 + then: 62 + properties: 63 + interrupts: 64 + minItems: 1 65 + maxItems: 4 66 + interrupt-names: 67 + minItems: 1 68 + maxItems: 4 69 + items: 70 + enum: 71 + - alert1 72 + - alert2 73 + - alert3 74 + - alert4 75 + microchip,vsense: false 50 76 51 77 required: 52 78 - compatible ··· 97 63 reg = <0x60>; 98 64 interrupt-parent = <&gpio>; 99 65 interrupts = <25 IRQ_TYPE_EDGE_RISING>; 100 - interrupt-names = "open-circuit"; 66 + interrupt-names = "alert1"; 101 67 thermocouple-type = <THERMOCOUPLE_TYPE_K>; 102 68 vdd-supply = <&vdd>; 69 + }; 70 + }; 71 + - | 72 + #include <dt-bindings/interrupt-controller/irq.h> 73 + i2c { 74 + #address-cells = <1>; 75 + #size-cells = <0>; 76 + 77 + temperature-sensor@62 { 78 + compatible = "microchip,mcp9601", "microchip,mcp9600"; 79 + reg = <0x62>; 80 + interrupt-parent = <&gpio>; 81 + interrupts = <22 IRQ_TYPE_EDGE_RISING>, <23 IRQ_TYPE_EDGE_RISING>; 82 + interrupt-names = "open-circuit", "short-circuit"; 83 + vdd-supply = <&vdd>; 84 + microchip,vsense; 103 85 }; 104 86 };
+4
Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
··· 35 35 description: LDO or buck regulator. 36 36 unevaluatedProperties: false 37 37 38 + '#io-channel-cells': 39 + const: 1 40 + 38 41 required: 39 42 - compatible 40 43 - reg ··· 56 53 reg = <0x30>; 57 54 interrupts = <0 4 IRQ_TYPE_LEVEL_HIGH>; 58 55 interrupt-parent = <&gic>; 56 + #io-channel-cells = <1>; 59 57 wakeup-source; 60 58 61 59 regulators {
-2
Documentation/devicetree/bindings/trivial-devices.yaml
··· 133 133 - infineon,ir36021 134 134 # Infineon IRPS5401 Voltage Regulator (PMIC) 135 135 - infineon,irps5401 136 - # Infineon TLV493D-A1B6 I2C 3D Magnetic Sensor 137 - - infineon,tlv493d-a1b6 138 136 # Infineon Hot-swap controller xdp710 139 137 - infineon,xdp710 140 138 # Infineon Multi-phase Digital VR Controller xdpe11280
+2 -1
Documentation/iio/ad3552r.rst
··· 64 64 Usage examples 65 65 -------------- 66 66 67 - . code-block:: bash 67 + .. code-block:: bash 68 + 68 69 root:/sys/bus/iio/devices/iio:device0# cat data_source 69 70 normal 70 71 root:/sys/bus/iio/devices/iio:device0# echo -n ramp-16bit > data_source
+268
Documentation/iio/ade9000.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + =============== 4 + ADE9000 driver 5 + =============== 6 + 7 + This driver supports Analog Device's ADE9000 energy measurement IC on SPI bus. 8 + 9 + 1. Supported devices 10 + ==================== 11 + 12 + * `ADE9000 <https://www.analog.com/media/en/technical-documentation/data-sheets/ADE9000.pdf>`_ 13 + 14 + The ADE9000 is a highly accurate, fully integrated, multiphase energy and power 15 + quality monitoring device. Superior analog performance and a digital signal 16 + processing (DSP) core enable accurate energy monitoring over a wide dynamic 17 + range. An integrated high end reference ensures low drift over temperature 18 + with a combined drift of less than ±25 ppm/°C maximum for the entire channel 19 + including a programmable gain amplifier (PGA) and an analog-to-digital 20 + converter (ADC). 21 + 22 + 2. Device attributes 23 + ==================== 24 + 25 + Power and energy measurements are provided for voltage, current, active power, 26 + reactive power, apparent power, and power factor across three phases. 27 + 28 + Each IIO device has a device folder under ``/sys/bus/iio/devices/iio:deviceX``, 29 + where X is the IIO index of the device. Under these folders reside a set of 30 + device files, depending on the characteristics and features of the hardware 31 + device in question. These files are consistently generalized and documented in 32 + the IIO ABI documentation. 33 + 34 + The following tables show the ADE9000 related device files, found in the 35 + specific device folder path ``/sys/bus/iio/devices/iio:deviceX``. 36 + 37 + +---------------------------------------------------+----------------------------------------------------------+ 38 + | Current measurement related device files | Description | 39 + +---------------------------------------------------+----------------------------------------------------------+ 40 + | in_current[0-2]_raw | Raw current measurement for phases A, B, C. | 41 + +---------------------------------------------------+----------------------------------------------------------+ 42 + | in_current[0-2]_scale | Scale for current channels. | 43 + +---------------------------------------------------+----------------------------------------------------------+ 44 + | in_current[0-2]_calibscale | Calibration gain for current channels (AIGAIN reg). | 45 + +---------------------------------------------------+----------------------------------------------------------+ 46 + | in_altcurrent[0-2]_rms_raw | RMS current measurement for phases A, B, C. | 47 + +---------------------------------------------------+----------------------------------------------------------+ 48 + | in_altcurrent[0-2]_rms_scale | Scale for RMS current channels. | 49 + +---------------------------------------------------+----------------------------------------------------------+ 50 + | in_altcurrent[0-2]_rms_calibbias | RMS offset correction for current channels (IRMSOS reg). | 51 + +---------------------------------------------------+----------------------------------------------------------+ 52 + 53 + +---------------------------------------------------+----------------------------------------------------------+ 54 + | Voltage measurement related device files | Description | 55 + +---------------------------------------------------+----------------------------------------------------------+ 56 + | in_voltage[0-2]_raw | Raw voltage measurement for phases A, B, C. | 57 + +---------------------------------------------------+----------------------------------------------------------+ 58 + | in_voltage[0-2]_scale | Scale for voltage channels. | 59 + +---------------------------------------------------+----------------------------------------------------------+ 60 + | in_voltage[0-2]_calibscale | Calibration gain for voltage channels (AVGAIN reg). | 61 + +---------------------------------------------------+----------------------------------------------------------+ 62 + | in_voltage[0-2]_frequency | Measured line frequency from instantaneous voltage. | 63 + +---------------------------------------------------+----------------------------------------------------------+ 64 + | in_altvoltage[0-2]_rms_raw | RMS voltage measurement for phases A, B, C. | 65 + +---------------------------------------------------+----------------------------------------------------------+ 66 + | in_altvoltage[0-2]_rms_scale | Scale for RMS voltage channels. | 67 + +---------------------------------------------------+----------------------------------------------------------+ 68 + | in_altvoltage[0-2]_rms_calibbias | RMS offset correction for voltage channels (VRMSOS reg). | 69 + +---------------------------------------------------+----------------------------------------------------------+ 70 + 71 + +---------------------------------------------------+----------------------------------------------------------+ 72 + | Power measurement related device files | Description | 73 + +---------------------------------------------------+----------------------------------------------------------+ 74 + | in_power[0-2]_active_raw | Active power measurement for phases A, B, C. | 75 + +---------------------------------------------------+----------------------------------------------------------+ 76 + | in_power[0-2]_active_scale | Scale for active power channels. | 77 + +---------------------------------------------------+----------------------------------------------------------+ 78 + | in_power[0-2]_active_calibbias | Calibration offset for active power (xWATTOS regs). | 79 + +---------------------------------------------------+----------------------------------------------------------+ 80 + | in_power[0-2]_active_calibscale | Calibration gain for active power (APGAIN reg). | 81 + +---------------------------------------------------+----------------------------------------------------------+ 82 + | in_power[0-2]_reactive_raw | Reactive power measurement for phases A, B, C. | 83 + +---------------------------------------------------+----------------------------------------------------------+ 84 + | in_power[0-2]_reactive_scale | Scale for reactive power channels. | 85 + +---------------------------------------------------+----------------------------------------------------------+ 86 + | in_power[0-2]_reactive_calibbias | Calibration offset for reactive power (xVAROS regs). | 87 + +---------------------------------------------------+----------------------------------------------------------+ 88 + | in_power[0-2]_apparent_raw | Apparent power measurement for phases A, B, C. | 89 + +---------------------------------------------------+----------------------------------------------------------+ 90 + | in_power[0-2]_apparent_scale | Scale for apparent power channels. | 91 + +---------------------------------------------------+----------------------------------------------------------+ 92 + | in_power[0-2]_powerfactor | Power factor for phases A, B, C. | 93 + +---------------------------------------------------+----------------------------------------------------------+ 94 + 95 + +---------------------------------------------------+----------------------------------------------------------+ 96 + | Energy measurement related device files | Description | 97 + +---------------------------------------------------+----------------------------------------------------------+ 98 + | in_energy[0-2]_active_raw | Active energy measurement for phases A, B, C. | 99 + +---------------------------------------------------+----------------------------------------------------------+ 100 + | in_energy[0-2]_reactive_raw | Reactive energy measurement for phases A, B, C. | 101 + +---------------------------------------------------+----------------------------------------------------------+ 102 + | in_energy[0-2]_apparent_raw | Apparent energy measurement for phases A, B, C. | 103 + +---------------------------------------------------+----------------------------------------------------------+ 104 + 105 + +------------------------------+------------------------------------------------------------------+ 106 + | Shared device attributes | Description | 107 + +------------------------------+------------------------------------------------------------------+ 108 + | name | Name of the IIO device. | 109 + +------------------------------+------------------------------------------------------------------+ 110 + | filter_type | Waveform buffer filter type (sinc4, sinc4+lp). | 111 + +------------------------------+------------------------------------------------------------------+ 112 + | filter_type_available | Available filter types for waveform buffer. | 113 + +------------------------------+------------------------------------------------------------------+ 114 + 115 + 3. Calibration and scaling 116 + =========================== 117 + 118 + The ADE9000 provides multiple levels of gain and offset correction: 119 + 120 + **Calibration Gain (per-channel)** 121 + Fine-tuning calibration gains applied in the digital domain for each channel type. 122 + Controlled via ``calibscale`` attributes (AIGAIN, AVGAIN, APGAIN registers). 123 + 124 + **Calibration Bias (per-channel)** 125 + Hardware calibration offsets applied by the device internally: 126 + 127 + - Power measurements: Controlled via ``calibbias`` attributes for power channels (xWATTOS, xVAROS registers). 128 + - RMS measurements: Controlled via ``calibbias`` attributes for RMS channels (IRMSOS, VRMSOS registers). 129 + 130 + These are internal chip calibrations, not userspace-applied offsets. 131 + 132 + 4. Event attributes 133 + =================== 134 + 135 + The ADE9000 provides various interrupts that are mapped to IIO events. 136 + Event functionality is only available if the corresponding interrupts are 137 + connected in the device tree. 138 + 139 + +---------------------------------------------------+----------------------------------------------------------+ 140 + | IIO Event Attribute | ADE9000 Datasheet Equivalent | 141 + +---------------------------------------------------+----------------------------------------------------------+ 142 + | in_voltage[0-2]_thresh_either_en | Zero crossing detection interrupt (ZXVx) | 143 + +---------------------------------------------------+----------------------------------------------------------+ 144 + | in_altvoltage[0-2]_rms_thresh_rising_en | RMS swell detection interrupt (SWELLx) | 145 + +---------------------------------------------------+----------------------------------------------------------+ 146 + | in_altvoltage[0-2]_rms_thresh_rising_value | RMS swell threshold (SWELL_LVL register) | 147 + +---------------------------------------------------+----------------------------------------------------------+ 148 + | in_altvoltage[0-2]_rms_thresh_falling_en | RMS sag/dip detection interrupt (DIPx) | 149 + +---------------------------------------------------+----------------------------------------------------------+ 150 + | in_altvoltage[0-2]_rms_thresh_falling_value | RMS sag/dip threshold (DIP_LVL register) | 151 + +---------------------------------------------------+----------------------------------------------------------+ 152 + | in_current[0-2]_thresh_either_en | Current zero crossing detection interrupt (ZXIx) | 153 + +---------------------------------------------------+----------------------------------------------------------+ 154 + 155 + Event directions: 156 + 157 + - ``rising``: Upper threshold crossing (swell detection) 158 + - ``falling``: Lower threshold crossing (sag/dip detection) 159 + - ``either``: Any threshold crossing (zero crossing detection) 160 + - ``none``: Timeout or non-directional events 161 + 162 + **Note**: Event attributes are only available if the corresponding interrupts 163 + (irq0, irq1, dready) are specified in the device tree. The driver works without 164 + interrupts but with reduced functionality. 165 + 166 + 5. Device buffers 167 + ================= 168 + 169 + This driver supports IIO buffers for waveform capture. Buffer functionality 170 + requires the dready interrupt to be connected. 171 + 172 + The device supports capturing voltage and current waveforms for power quality 173 + analysis. The waveform buffer can be configured to capture data from different 174 + channel combinations. 175 + 176 + Supported channel combinations for buffered capture: 177 + 178 + - Phase A: voltage and current (IA + VA) 179 + - Phase B: voltage and current (IB + VB) 180 + - Phase C: voltage and current (IC + VC) 181 + - All phases: all voltage and current channels 182 + - Individual channels: IA, VA, IB, VB, IC, VC 183 + 184 + Usage examples 185 + -------------- 186 + 187 + Enable waveform capture for Phase A: 188 + 189 + .. code-block:: bash 190 + 191 + root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_current0_en 192 + root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_voltage0_en 193 + 194 + Set buffer length and enable: 195 + 196 + .. code-block:: bash 197 + 198 + root:/sys/bus/iio/devices/iio:device0> echo 100 > buffer/length 199 + root:/sys/bus/iio/devices/iio:device0> echo 1 > buffer/enable 200 + 201 + 6. Clock output 202 + =============== 203 + 204 + The ADE9000 can provide a clock output via the CLKOUT pin when using an external 205 + crystal/clock source. This feature is enabled by specifying ``#clock-cells = <0>`` 206 + in the device tree. The output clock will be registered as "clkout" and can be 207 + referenced by other devices. 208 + 209 + 7. Usage examples 210 + ================= 211 + 212 + Show device name: 213 + 214 + .. code-block:: bash 215 + 216 + root:/sys/bus/iio/devices/iio:device0> cat name 217 + ade9000 218 + 219 + Read voltage measurements: 220 + 221 + .. code-block:: bash 222 + 223 + root:/sys/bus/iio/devices/iio:device0> cat in_voltage0_raw 224 + 12345 225 + root:/sys/bus/iio/devices/iio:device0> cat in_voltage0_scale 226 + 0.000030517 227 + 228 + - Phase A voltage = in_voltage0_raw * in_voltage0_scale = 0.3769 V 229 + 230 + Read power measurements: 231 + 232 + .. code-block:: bash 233 + 234 + root:/sys/bus/iio/devices/iio:device0> cat in_power0_active_raw 235 + 5678 236 + root:/sys/bus/iio/devices/iio:device0> cat in_power0_scale 237 + 0.000244140 238 + 239 + - Phase A active power = in_power0_active_raw * in_power0_scale = 1.386 W 240 + 241 + Configure calibration gains: 242 + 243 + .. code-block:: bash 244 + 245 + # Set current channel 0 calibration gain 246 + root:/sys/bus/iio/devices/iio:device0> echo 0x800000 > in_current0_calibscale 247 + # Set voltage channel 0 calibration gain 248 + root:/sys/bus/iio/devices/iio:device0> echo 0x7FFFFF > in_voltage0_calibscale 249 + 250 + Configure RMS voltage event thresholds (requires interrupts): 251 + 252 + .. code-block:: bash 253 + 254 + # Set RMS sag detection threshold 255 + root:/sys/bus/iio/devices/iio:device0> echo 180000 > events/in_altvoltage0_rms_thresh_falling_value 256 + # Enable RMS sag detection 257 + root:/sys/bus/iio/devices/iio:device0> echo 1 > events/in_altvoltage0_rms_thresh_falling_en 258 + 259 + # Set RMS swell detection threshold 260 + root:/sys/bus/iio/devices/iio:device0> echo 260000 > events/in_altvoltage0_rms_thresh_rising_value 261 + # Enable RMS swell detection 262 + root:/sys/bus/iio/devices/iio:device0> echo 1 > events/in_altvoltage0_rms_thresh_rising_en 263 + 264 + 8. IIO Interfacing Tools 265 + ======================== 266 + 267 + See ``Documentation/iio/iio_tools.rst`` for the description of the available IIO 268 + interfacing tools.
+443
Documentation/iio/adxl345.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + =============== 4 + ADXL345 driver 5 + =============== 6 + 7 + This driver supports Analog Device's ADXL345/375 on SPI/I2C bus. 8 + 9 + 1. Supported Devices 10 + ==================== 11 + 12 + * `ADXL345 <https://www.analog.com/ADXL345>`_ 13 + * `ADXL375 <https://www.analog.com/ADXL375>`_ 14 + 15 + The ADXL345 is a generic purpose low power, 3-axis accelerometer with selectable 16 + measurement ranges. The ADXL345 supports the ±2 g, ±4 g, ±8 g, and ±16 g ranges. 17 + 18 + 2. Device Attributes 19 + ==================== 20 + 21 + Each IIO device, has a device folder under ``/sys/bus/iio/devices/iio:deviceX``, 22 + where X is the IIO index of the device. Under these folders reside a set of 23 + device files, depending on the characteristics and features of the hardware 24 + device in questions. These files are consistently generalized and documented in 25 + the IIO ABI documentation. 26 + 27 + The following table shows the ADXL345 related device files, found in the 28 + specific device folder path ``/sys/bus/iio/devices/iio:deviceX``. 29 + 30 + +-------------------------------------------+----------------------------------------------------------+ 31 + | 3-Axis Accelerometer related device files | Description | 32 + +-------------------------------------------+----------------------------------------------------------+ 33 + | in_accel_sampling_frequency | Currently selected sample rate. | 34 + +-------------------------------------------+----------------------------------------------------------+ 35 + | in_accel_sampling_frequency_available | Available sampling frequency configurations. | 36 + +-------------------------------------------+----------------------------------------------------------+ 37 + | in_accel_scale | Scale/range for the accelerometer channels. | 38 + +-------------------------------------------+----------------------------------------------------------+ 39 + | in_accel_scale_available | Available scale ranges for the accelerometer channel. | 40 + +-------------------------------------------+----------------------------------------------------------+ 41 + | in_accel_x_calibbias | Calibration offset for the X-axis accelerometer channel. | 42 + +-------------------------------------------+----------------------------------------------------------+ 43 + | in_accel_x_raw | Raw X-axis accelerometer channel value. | 44 + +-------------------------------------------+----------------------------------------------------------+ 45 + | in_accel_y_calibbias | y-axis acceleration offset correction | 46 + +-------------------------------------------+----------------------------------------------------------+ 47 + | in_accel_y_raw | Raw Y-axis accelerometer channel value. | 48 + +-------------------------------------------+----------------------------------------------------------+ 49 + | in_accel_z_calibbias | Calibration offset for the Z-axis accelerometer channel. | 50 + +-------------------------------------------+----------------------------------------------------------+ 51 + | in_accel_z_raw | Raw Z-axis accelerometer channel value. | 52 + +-------------------------------------------+----------------------------------------------------------+ 53 + 54 + Channel Processed Values 55 + ------------------------- 56 + 57 + A channel value can be read from its _raw attribute. The value returned is the 58 + raw value as reported by the devices. To get the processed value of the channel, 59 + apply the following formula: 60 + 61 + .. code-block:: bash 62 + 63 + processed value = (_raw + _offset) * _scale 64 + 65 + Where _offset and _scale are device attributes. If no _offset attribute is 66 + present, simply assume its value is 0. 67 + 68 + +-------------------------------------+---------------------------+ 69 + | Channel type | Measurement unit | 70 + +-------------------------------------+---------------------------+ 71 + | Acceleration on X, Y, and Z axis | Meters per second squared | 72 + +-------------------------------------+---------------------------+ 73 + 74 + Sensor Events 75 + ------------- 76 + 77 + Specific IIO events are triggered by their corresponding interrupts. The sensor 78 + driver supports either none or a single active interrupt (INT) line, selectable 79 + from the two available options: INT1 or INT2. The active INT line should be 80 + specified in the device tree. If no INT line is configured, the sensor defaults 81 + to FIFO bypass mode, where event detection is disabled and only X, Y, and Z axis 82 + measurements are available. 83 + 84 + The table below lists the ADXL345-related device files located in the 85 + device-specific path: ``/sys/bus/iio/devices/iio:deviceX/events``. 86 + Note that activity and inactivity detection are DC-coupled by default; 87 + therefore, only the AC-coupled activity and inactivity events are explicitly 88 + listed. 89 + 90 + +---------------------------------------------+---------------------------------------------+ 91 + | Event handle | Description | 92 + +---------------------------------------------+---------------------------------------------+ 93 + | in_accel_gesture_doubletap_en | Enable double tap detection on all axis | 94 + +---------------------------------------------+---------------------------------------------+ 95 + | in_accel_gesture_doubletap_reset_timeout | Double tap window in [us] | 96 + +---------------------------------------------+---------------------------------------------+ 97 + | in_accel_gesture_doubletap_tap2_min_delay | Double tap latent in [us] | 98 + +---------------------------------------------+---------------------------------------------+ 99 + | in_accel_gesture_singletap_timeout | Single tap duration in [us] | 100 + +---------------------------------------------+---------------------------------------------+ 101 + | in_accel_gesture_singletap_value | Single tap threshold value in 62.5/LSB | 102 + +---------------------------------------------+---------------------------------------------+ 103 + | in_accel_mag_falling_period | Inactivity time in seconds | 104 + +---------------------------------------------+---------------------------------------------+ 105 + | in_accel_mag_falling_value | Inactivity threshold value in 62.5/LSB | 106 + +---------------------------------------------+---------------------------------------------+ 107 + | in_accel_mag_adaptive_rising_en | Enable AC coupled activity on X axis | 108 + +---------------------------------------------+---------------------------------------------+ 109 + | in_accel_mag_adaptive_falling_period | AC coupled inactivity time in seconds | 110 + +---------------------------------------------+---------------------------------------------+ 111 + | in_accel_mag_adaptive_falling_value | AC coupled inactivity threshold in 62.5/LSB | 112 + +---------------------------------------------+---------------------------------------------+ 113 + | in_accel_mag_adaptive_rising_value | AC coupled activity threshold in 62.5/LSB | 114 + +---------------------------------------------+---------------------------------------------+ 115 + | in_accel_mag_rising_en | Enable activity detection on X axis | 116 + +---------------------------------------------+---------------------------------------------+ 117 + | in_accel_mag_rising_value | Activity threshold value in 62.5/LSB | 118 + +---------------------------------------------+---------------------------------------------+ 119 + | in_accel_x_gesture_singletap_en | Enable single tap detection on X axis | 120 + +---------------------------------------------+---------------------------------------------+ 121 + | in_accel_x&y&z_mag_falling_en | Enable inactivity detection on all axis | 122 + +---------------------------------------------+---------------------------------------------+ 123 + | in_accel_x&y&z_mag_adaptive_falling_en | Enable AC coupled inactivity on all axis | 124 + +---------------------------------------------+---------------------------------------------+ 125 + | in_accel_y_gesture_singletap_en | Enable single tap detection on Y axis | 126 + +---------------------------------------------+---------------------------------------------+ 127 + | in_accel_z_gesture_singletap_en | Enable single tap detection on Z axis | 128 + +---------------------------------------------+---------------------------------------------+ 129 + 130 + Please refer to the sensor's datasheet for a detailed description of this 131 + functionality. 132 + 133 + Manually setting the **ODR** will cause the driver to estimate default values 134 + for inactivity detection timing, where higher ODR values correspond to longer 135 + default wait times, and lower ODR values to shorter ones. If these defaults do 136 + not meet your application’s needs, you can explicitly configure the inactivity 137 + wait time. Setting this value to 0 will revert to the default behavior. 138 + 139 + When changing the **g range** configuration, the driver attempts to estimate 140 + appropriate activity and inactivity thresholds by scaling the default values 141 + based on the ratio of the previous range to the new one. The resulting threshold 142 + will never be zero and will always fall between 1 and 255, corresponding to up 143 + to 62.5 g/LSB as specified in the datasheet. However, you can override these 144 + estimated thresholds by setting explicit values. 145 + 146 + When **activity** and **inactivity** events are enabled, the driver 147 + automatically manages hysteresis behavior by setting the **link** and 148 + **auto-sleep** bits. The link bit connects the activity and inactivity 149 + functions, so that one follows the other. The auto-sleep function puts the 150 + sensor into sleep mode when inactivity is detected, reducing power consumption 151 + to the sub-12.5 Hz rate. 152 + 153 + The inactivity time is configurable between 1 and 255 seconds. In addition to 154 + inactivity detection, the sensor also supports free-fall detection, which, from 155 + the IIO perspective, is treated as a fall in magnitude across all axes. In 156 + sensor terms, free-fall is defined using an inactivity period ranging from 0.000 157 + to 1.000 seconds. 158 + 159 + The driver behaves as follows: 160 + 161 + * If the configured inactivity period is 1 second or more, the driver uses the 162 + sensor's inactivity register. This allows the event to be linked with 163 + activity detection, use auto-sleep, and be either AC- or DC-coupled. 164 + 165 + * If the inactivity period is less than 1 second, the event is treated as plain 166 + inactivity or free-fall detection. In this case, auto-sleep and coupling 167 + (AC/DC) are not applied. 168 + 169 + * If an inactivity time of 0 seconds is configured, the driver selects a 170 + heuristically determined default period (greater than 1 second) to optimize 171 + power consumption. This also uses the inactivity register. 172 + 173 + Note: According to the datasheet, the optimal ODR for detecting activity, 174 + or inactivity (or when operating with the free-fall register) should fall within 175 + the range of 12.5 Hz to 400 Hz. The recommended free-fall threshold is between 176 + 300 mg and 600 mg (register values 0x05 to 0x09). 177 + 178 + In DC-coupled mode, the current acceleration magnitude is directly compared to 179 + the values in the THRESH_ACT and THRESH_INACT registers to determine activity or 180 + inactivity. In contrast, AC-coupled activity detection uses the acceleration 181 + value at the start of detection as a reference point, and subsequent samples are 182 + compared against this reference. While DC-coupling is the default mode-comparing 183 + live values to fixed thresholds-AC-coupling relies on an internal filter 184 + relative to the configured threshold. 185 + 186 + AC and DC coupling modes are configured separately for activity and inactivity 187 + detection, but only one mode can be active at a time for each. For example, if 188 + AC-coupled activity detection is enabled and then DC-coupled mode is set, only 189 + DC-coupled activity detection will be active. In other words, only the most 190 + recent configuration is applied. 191 + 192 + **Single tap** detection can be configured per the datasheet by setting the 193 + threshold and duration parameters. When only single tap detection is enabled, 194 + the single tap interrupt triggers as soon as the acceleration exceeds the 195 + threshold (marking the start of the duration) and then falls below it, provided 196 + the duration limit is not exceeded. If both single tap and double tap detections 197 + are enabled, the single tap interrupt is triggered only after the double tap 198 + event has been either confirmed or dismissed. 199 + 200 + To configure **double tap** detection, you must also set the window and latency 201 + parameters in microseconds (µs). The latency period begins once the single tap 202 + signal drops below the threshold and acts as a waiting time during which any 203 + spikes are ignored for double tap detection. After the latency period ends, the 204 + detection window starts. If the acceleration rises above the threshold and then 205 + falls below it again within this window, a double tap event is triggered upon 206 + the fall below the threshold. 207 + 208 + Double tap event detection is thoroughly explained in the datasheet. After a 209 + single tap event is detected, a double tap event may follow, provided the signal 210 + meets certain criteria. However, double tap detection can be invalidated for 211 + three reasons: 212 + 213 + * If the **suppress bit** is set, any acceleration spike above the tap 214 + threshold during the tap latency period immediately invalidates the double tap 215 + detection. In other words, no spikes are allowed during latency when the 216 + suppress bit is active. 217 + 218 + * The double tap event is invalid if the acceleration is above the threshold at 219 + the start of the double tap window. 220 + 221 + * Double tap detection is also invalidated if the acceleration duration exceeds 222 + the limit set by the duration register. 223 + 224 + For double tap detection, the same duration applies as for single tap: the 225 + acceleration must rise above the threshold and then fall below it within the 226 + specified duration. Note that the suppress bit is typically enabled when double 227 + tap detection is active. 228 + 229 + Usage Examples 230 + -------------- 231 + 232 + Show device name: 233 + 234 + .. code-block:: bash 235 + 236 + root:/sys/bus/iio/devices/iio:device0> cat name 237 + adxl345 238 + 239 + Show accelerometer channels value: 240 + 241 + .. code-block:: bash 242 + 243 + root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_raw 244 + -1 245 + root:/sys/bus/iio/devices/iio:device0> cat in_accel_y_raw 246 + 2 247 + root:/sys/bus/iio/devices/iio:device0> cat in_accel_z_raw 248 + -253 249 + 250 + Set calibration offset for accelerometer channels: 251 + 252 + .. code-block:: bash 253 + 254 + root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_calibbias 255 + 0 256 + 257 + root:/sys/bus/iio/devices/iio:device0> echo 50 > in_accel_x_calibbias 258 + root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_calibbias 259 + 50 260 + 261 + Given the 13-bit full resolution, the available ranges are calculated by the 262 + following formula: 263 + 264 + .. code-block:: bash 265 + 266 + (g * 2 * 9.80665) / (2^(resolution) - 1) * 100; for g := 2|4|8|16 267 + 268 + Scale range configuration: 269 + 270 + .. code-block:: bash 271 + 272 + root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_scale 273 + 0.478899 274 + root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_scale_available 275 + 0.478899 0.957798 1.915595 3.831190 276 + 277 + root:/sys/bus/iio/devices/iio:device0> echo 1.915595 > ./in_accel_scale 278 + root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_scale 279 + 1.915595 280 + 281 + Set output data rate (ODR): 282 + 283 + .. code-block:: bash 284 + 285 + root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_sampling_frequency 286 + 200.000000 287 + 288 + root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_sampling_frequency_available 289 + 0.097000 0.195000 0.390000 0.781000 1.562000 3.125000 6.250000 12.500000 25.000000 50.000000 100.000000 200.000000 400.000000 800.000000 1600.000000 3200.000000 290 + 291 + root:/sys/bus/iio/devices/iio:device0> echo 1.562000 > ./in_accel_sampling_frequency 292 + root:/sys/bus/iio/devices/iio:device0> cat ./in_accel_sampling_frequency 293 + 1.562000 294 + 295 + Configure one or several events: 296 + 297 + .. code-block:: bash 298 + 299 + root:> cd /sys/bus/iio/devices/iio:device0 300 + 301 + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./buffer0/in_accel_x_en 302 + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./buffer0/in_accel_y_en 303 + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./buffer0/in_accel_z_en 304 + 305 + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./scan_elements/in_accel_x_en 306 + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./scan_elements/in_accel_y_en 307 + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./scan_elements/in_accel_z_en 308 + 309 + root:/sys/bus/iio/devices/iio:device0> echo 14 > ./in_accel_x_calibbias 310 + root:/sys/bus/iio/devices/iio:device0> echo 2 > ./in_accel_y_calibbias 311 + root:/sys/bus/iio/devices/iio:device0> echo -250 > ./in_accel_z_calibbias 312 + 313 + root:/sys/bus/iio/devices/iio:device0> echo 24 > ./buffer0/length 314 + 315 + ## AC coupled activity, threshold [62.5/LSB] 316 + root:/sys/bus/iio/devices/iio:device0> echo 6 > ./events/in_accel_mag_adaptive_rising_value 317 + 318 + ## AC coupled inactivity, threshold, [62.5/LSB] 319 + root:/sys/bus/iio/devices/iio:device0> echo 4 > ./events/in_accel_mag_adaptive_falling_value 320 + 321 + ## AC coupled inactivity, time [s] 322 + root:/sys/bus/iio/devices/iio:device0> echo 3 > ./events/in_accel_mag_adaptive_falling_period 323 + 324 + ## singletap, threshold 325 + root:/sys/bus/iio/devices/iio:device0> echo 35 > ./events/in_accel_gesture_singletap_value 326 + 327 + ## singletap, duration [us] 328 + root:/sys/bus/iio/devices/iio:device0> echo 0.001875 > ./events/in_accel_gesture_singletap_timeout 329 + 330 + ## doubletap, window [us] 331 + root:/sys/bus/iio/devices/iio:device0> echo 0.025 > ./events/in_accel_gesture_doubletap_reset_timeout 332 + 333 + ## doubletap, latent [us] 334 + root:/sys/bus/iio/devices/iio:device0> echo 0.025 > ./events/in_accel_gesture_doubletap_tap2_min_delay 335 + 336 + ## AC coupled activity, enable 337 + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_mag_adaptive_rising_en 338 + 339 + ## AC coupled inactivity, enable 340 + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_x\&y\&z_mag_adaptive_falling_en 341 + 342 + ## singletap, enable 343 + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_x_gesture_singletap_en 344 + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_y_gesture_singletap_en 345 + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_z_gesture_singletap_en 346 + 347 + ## doubletap, enable 348 + root:/sys/bus/iio/devices/iio:device0> echo 1 > ./events/in_accel_gesture_doubletap_en 349 + 350 + Verify incoming events: 351 + 352 + .. code-block:: bash 353 + 354 + root:# iio_event_monitor adxl345 355 + Found IIO device with name adxl345 with device number 0 356 + Event: time: 1739063415957073383, type: accel(z), channel: 0, evtype: mag, direction: rising 357 + Event: time: 1739063415963770218, type: accel(z), channel: 0, evtype: mag, direction: rising 358 + Event: time: 1739063416002563061, type: accel(z), channel: 0, evtype: gesture, direction: singletap 359 + Event: time: 1739063426271128739, type: accel(x&y&z), channel: 0, evtype: mag, direction: falling 360 + Event: time: 1739063436539080713, type: accel(x&y&z), channel: 0, evtype: mag, direction: falling 361 + Event: time: 1739063438357970381, type: accel(z), channel: 0, evtype: mag, direction: rising 362 + Event: time: 1739063446726161586, type: accel(z), channel: 0, evtype: mag, direction: rising 363 + Event: time: 1739063446727892670, type: accel(z), channel: 0, evtype: mag, direction: rising 364 + Event: time: 1739063446743019768, type: accel(z), channel: 0, evtype: mag, direction: rising 365 + Event: time: 1739063446744650696, type: accel(z), channel: 0, evtype: mag, direction: rising 366 + Event: time: 1739063446763559386, type: accel(z), channel: 0, evtype: gesture, direction: singletap 367 + Event: time: 1739063448818126480, type: accel(x&y&z), channel: 0, evtype: mag, direction: falling 368 + ... 369 + 370 + Activity and inactivity belong together and indicate state changes as follows 371 + 372 + .. code-block:: bash 373 + 374 + root:# iio_event_monitor adxl345 375 + Found IIO device with name adxl345 with device number 0 376 + Event: time: 1744648001133946293, type: accel(x), channel: 0, evtype: mag, direction: rising 377 + <after inactivity time elapsed> 378 + Event: time: 1744648057724775499, type: accel(x&y&z), channel: 0, evtype: mag, direction: falling 379 + ... 380 + 381 + 3. Device Buffers 382 + ================= 383 + 384 + This driver supports IIO buffers. 385 + 386 + All devices support retrieving the raw acceleration and temperature measurements 387 + using buffers. 388 + 389 + Usage examples 390 + -------------- 391 + 392 + Select channels for buffer read: 393 + 394 + .. code-block:: bash 395 + 396 + root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_accel_x_en 397 + root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_accel_y_en 398 + root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_accel_z_en 399 + 400 + Set the number of samples to be stored in the buffer: 401 + 402 + .. code-block:: bash 403 + 404 + root:/sys/bus/iio/devices/iio:device0> echo 10 > buffer/length 405 + 406 + Enable buffer readings: 407 + 408 + .. code-block:: bash 409 + 410 + root:/sys/bus/iio/devices/iio:device0> echo 1 > buffer/enable 411 + 412 + Obtain buffered data: 413 + 414 + .. code-block:: bash 415 + 416 + root:> iio_readdev -b 16 -s 1024 adxl345 | hexdump -d 417 + WARNING: High-speed mode not enabled 418 + 0000000 00003 00012 00013 00005 00010 00011 00005 00011 419 + 0000010 00013 00004 00012 00011 00003 00012 00014 00007 420 + 0000020 00011 00013 00004 00013 00014 00003 00012 00013 421 + 0000030 00004 00012 00013 00005 00011 00011 00005 00012 422 + 0000040 00014 00005 00012 00014 00004 00010 00012 00004 423 + 0000050 00013 00011 00003 00011 00012 00005 00011 00013 424 + 0000060 00003 00012 00012 00003 00012 00012 00004 00012 425 + 0000070 00012 00003 00013 00013 00003 00013 00012 00005 426 + 0000080 00012 00013 00003 00011 00012 00005 00012 00013 427 + 0000090 00003 00013 00011 00005 00013 00014 00003 00012 428 + 00000a0 00012 00003 00012 00013 00004 00012 00015 00004 429 + 00000b0 00014 00011 00003 00014 00013 00004 00012 00011 430 + 00000c0 00004 00012 00013 00004 00014 00011 00004 00013 431 + 00000d0 00012 00002 00014 00012 00005 00012 00013 00005 432 + 00000e0 00013 00013 00003 00013 00013 00005 00012 00013 433 + 00000f0 00004 00014 00015 00005 00012 00011 00005 00012 434 + ... 435 + 436 + See ``Documentation/iio/iio_devbuf.rst`` for more information about how buffered 437 + data is structured. 438 + 439 + 4. IIO Interfacing Tools 440 + ======================== 441 + 442 + See ``Documentation/iio/iio_tools.rst`` for the description of the available IIO 443 + interfacing tools.
+6 -6
Documentation/iio/bno055.rst
··· 9 9 10 10 This driver supports Bosch BNO055 IMUs (on both serial and I2C busses). 11 11 12 - Accelerometer, magnetometer and gyroscope measures are always provided. 12 + Accelerometer, magnetometer and gyroscope measurements are always available. 13 13 When "fusion_enable" sysfs attribute is set to 1, orientation (both Euler 14 14 angles and quaternion), linear velocity and gravity vector are also 15 15 provided, but some sensor settings (e.g. low pass filtering and range) 16 - became locked (the IMU firmware controls them). 16 + become locked (the IMU firmware controls them). 17 17 18 18 This driver supports also IIO buffers. 19 19 ··· 24 24 operating in fusion mode. The magnetometer autocalibration can however be 25 25 disabled by writing 0 in the sysfs in_magn_calibration_fast_enable attribute. 26 26 27 - The driver provides access to autocalibration flags (i.e. you can known if 28 - the IMU has successfully autocalibrated) and to the calibration data blob. 27 + The driver provides access to autocalibration flags (i.e. you can determine 28 + if the IMU has successfully autocalibrated) and to the calibration data blob. 29 29 30 30 The user can save this blob in a firmware file (i.e. in /lib/firmware) that 31 31 the driver looks for at probe time. If found, then the IMU is initialized 32 32 with this calibration data. This saves the user from performing the 33 - calibration procedure every time (which consist of moving the IMU in 34 - various way). 33 + calibration procedure every time (which consists of moving the IMU in 34 + various ways). 35 35 36 36 The driver looks for calibration data file using two different names: first 37 37 a file whose name is suffixed with the IMU unique ID (exposed in sysfs as
+2
Documentation/iio/index.rst
··· 28 28 ad7606 29 29 ad7625 30 30 ad7944 31 + ade9000 31 32 adis16475 32 33 adis16480 33 34 adis16550 34 35 adxl313 35 36 adxl380 37 + adxl345 36 38 bno055 37 39 ep93xx_adc 38 40 opt4060
+30 -4
MAINTAINERS
··· 457 457 F: Documentation/iio/ad7380.rst 458 458 F: drivers/iio/adc/ad7380.c 459 459 460 + AD7476 ADC DRIVER FOR VARIOUS SIMPLE 1-CHANNEL SPI ADCs 461 + M: Matti Vaittinen <mazziesaccount@gmail.com> 462 + S: Maintained 463 + F: drivers/iio/adc/ad7476.c 464 + 460 465 AD7877 TOUCHSCREEN DRIVER 461 466 M: Michael Hennerich <michael.hennerich@analog.com> 462 467 S: Supported ··· 12022 12017 F: Documentation/devicetree/bindings/sound/infineon,peb2466.yaml 12023 12018 F: sound/soc/codecs/peb2466.c 12024 12019 12020 + INFINEON TLV493D Driver 12021 + M: Dixit Parmar <dixitparmar19@gmail.com> 12022 + L: linux-iio@vger.kernel.org 12023 + S: Maintained 12024 + W: https://www.infineon.com/part/TLV493D-A1B6 12025 + F: Documentation/devicetree/bindings/iio/magnetometer/infineon,tlv493d-a1b6.yaml 12026 + F: drivers/iio/magnetometer/tlv493d.c 12027 + 12025 12028 INFINIBAND SUBSYSTEM 12026 12029 M: Jason Gunthorpe <jgg@nvidia.com> 12027 12030 M: Leon Romanovsky <leonro@nvidia.com> ··· 14724 14711 F: drivers/rtc/rtc-88pm886.c 14725 14712 F: include/linux/mfd/88pm886.h 14726 14713 14714 + MARVELL 88PM886 PMIC GPADC DRIVER 14715 + M: Duje Mihanović <duje@dujemihanovic.xyz> 14716 + S: Maintained 14717 + F: drivers/iio/adc/88pm886-gpadc.c 14718 + 14727 14719 MARVELL ARMADA 3700 PHY DRIVERS 14728 14720 M: Miquel Raynal <miquel.raynal@bootlin.com> 14729 14721 S: Maintained ··· 15036 15018 F: drivers/regulator/max20086-regulator.c 15037 15019 15038 15020 MAXIM MAX30208 TEMPERATURE SENSOR DRIVER 15039 - M: Rajat Khandelwal <rajat.khandelwal@linux.intel.com> 15021 + M: Marcelo Schmitt <marcelo.schmitt@analog.com> 15040 15022 L: linux-iio@vger.kernel.org 15041 - S: Maintained 15023 + S: Supported 15042 15024 F: drivers/iio/temperature/max30208.c 15043 15025 15044 15026 MAXIM MAX77650 PMIC MFD DRIVER ··· 21906 21888 F: drivers/power/supply/bd99954-charger.c 21907 21889 F: drivers/power/supply/bd99954-charger.h 21908 21890 21909 - ROHM BD79124 ADC / GPO IC 21891 + ROHM BD791xx ADC / GPO IC 21910 21892 M: Matti Vaittinen <mazziesaccount@gmail.com> 21911 21893 S: Supported 21894 + F: drivers/iio/adc/rohm-bd79112.c 21912 21895 F: drivers/iio/adc/rohm-bd79124.c 21913 21896 21914 21897 ROHM BH1745 COLOUR SENSOR ··· 26851 26832 F: Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml 26852 26833 F: drivers/iio/light/veml6030.c 26853 26834 26835 + VISHAY VEML6046X00 RGBIR COLOR SENSOR DRIVER 26836 + M: Andreas Klinger <ak@it-klinger.de> 26837 + S: Maintained 26838 + F: Documentation/devicetree/bindings/iio/light/vishay,veml6046x00.yaml 26839 + F: drivers/iio/light/veml6046x00.c 26840 + 26854 26841 VISHAY VEML6075 UVA AND UVB LIGHT SENSOR DRIVER 26855 26842 M: Javier Carrasco <javier.carrasco.cruz@gmail.com> 26856 26843 S: Maintained ··· 27593 27568 F: include/uapi/linux/fsmap.h 27594 27569 27595 27570 XILINX AMS DRIVER 27596 - M: Anand Ashok Dumbre <anand.ashok.dumbre@xilinx.com> 27571 + M: Salih Erim <salih.erim@amd.com> 27572 + M: Conall O'Griofa <conall.ogriofa@amd.com> 27597 27573 L: linux-iio@vger.kernel.org 27598 27574 S: Maintained 27599 27575 F: Documentation/devicetree/bindings/iio/adc/xlnx,zynqmp-ams.yaml
+775 -7
drivers/iio/accel/adxl345_core.c
··· 36 36 #define ADXL345_REG_TAP_AXIS_MSK GENMASK(2, 0) 37 37 #define ADXL345_REG_TAP_SUPPRESS_MSK BIT(3) 38 38 #define ADXL345_REG_TAP_SUPPRESS BIT(3) 39 + #define ADXL345_POWER_CTL_INACT_MSK (ADXL345_POWER_CTL_AUTO_SLEEP | ADXL345_POWER_CTL_LINK) 39 40 40 41 #define ADXL345_TAP_Z_EN BIT(0) 41 42 #define ADXL345_TAP_Y_EN BIT(1) 42 43 #define ADXL345_TAP_X_EN BIT(2) 44 + #define ADXL345_REG_TAP_SUPPRESS BIT(3) 45 + 46 + #define ADXL345_INACT_Z_EN BIT(0) 47 + #define ADXL345_INACT_Y_EN BIT(1) 48 + #define ADXL345_INACT_X_EN BIT(2) 49 + #define ADXL345_REG_INACT_ACDC BIT(3) 50 + #define ADXL345_ACT_INACT_NO_AXIS_EN 0x00 51 + #define ADXL345_INACT_XYZ_EN (ADXL345_INACT_Z_EN | ADXL345_INACT_Y_EN | ADXL345_INACT_X_EN) 52 + 53 + #define ADXL345_ACT_Z_EN BIT(4) 54 + #define ADXL345_ACT_Y_EN BIT(5) 55 + #define ADXL345_ACT_X_EN BIT(6) 56 + #define ADXL345_REG_ACT_ACDC BIT(7) 57 + #define ADXL345_ACT_XYZ_EN (ADXL345_ACT_Z_EN | ADXL345_ACT_Y_EN | ADXL345_ACT_X_EN) 58 + 59 + #define ADXL345_COUPLING_DC 0 60 + #define ADXL345_COUPLING_AC 1 61 + #define ADXL345_REG_NO_ACDC 0x00 43 62 44 63 /* single/double tap */ 45 64 enum adxl345_tap_type { ··· 81 62 [ADXL345_TAP_TIME_LATENT] = ADXL345_REG_LATENT, 82 63 [ADXL345_TAP_TIME_WINDOW] = ADXL345_REG_WINDOW, 83 64 [ADXL345_TAP_TIME_DUR] = ADXL345_REG_DUR, 65 + }; 66 + 67 + /* activity/inactivity */ 68 + enum adxl345_activity_type { 69 + ADXL345_ACTIVITY, 70 + ADXL345_INACTIVITY, 71 + ADXL345_ACTIVITY_AC, 72 + ADXL345_INACTIVITY_AC, 73 + ADXL345_INACTIVITY_FF, 74 + }; 75 + 76 + static const unsigned int adxl345_act_int_reg[] = { 77 + [ADXL345_ACTIVITY] = ADXL345_INT_ACTIVITY, 78 + [ADXL345_INACTIVITY] = ADXL345_INT_INACTIVITY, 79 + [ADXL345_ACTIVITY_AC] = ADXL345_INT_ACTIVITY, 80 + [ADXL345_INACTIVITY_AC] = ADXL345_INT_INACTIVITY, 81 + [ADXL345_INACTIVITY_FF] = ADXL345_INT_FREE_FALL, 82 + }; 83 + 84 + static const unsigned int adxl345_act_thresh_reg[] = { 85 + [ADXL345_ACTIVITY] = ADXL345_REG_THRESH_ACT, 86 + [ADXL345_INACTIVITY] = ADXL345_REG_THRESH_INACT, 87 + [ADXL345_ACTIVITY_AC] = ADXL345_REG_THRESH_ACT, 88 + [ADXL345_INACTIVITY_AC] = ADXL345_REG_THRESH_INACT, 89 + [ADXL345_INACTIVITY_FF] = ADXL345_REG_THRESH_FF, 90 + }; 91 + 92 + static const unsigned int adxl345_act_acdc_msk[] = { 93 + [ADXL345_ACTIVITY] = ADXL345_REG_ACT_ACDC, 94 + [ADXL345_INACTIVITY] = ADXL345_REG_INACT_ACDC, 95 + [ADXL345_ACTIVITY_AC] = ADXL345_REG_ACT_ACDC, 96 + [ADXL345_INACTIVITY_AC] = ADXL345_REG_INACT_ACDC, 97 + [ADXL345_INACTIVITY_FF] = ADXL345_REG_NO_ACDC, 84 98 }; 85 99 86 100 enum adxl345_odr { ··· 181 129 [ADXL345_16G_RANGE] = { 0, 38312 }, 182 130 }; 183 131 132 + /* scaling */ 133 + static const int adxl345_range_factor_tbl[] = { 134 + [ADXL345_2G_RANGE] = 1, 135 + [ADXL345_4G_RANGE] = 2, 136 + [ADXL345_8G_RANGE] = 4, 137 + [ADXL345_16G_RANGE] = 8, 138 + }; 139 + 184 140 struct adxl345_state { 185 141 const struct adxl345_chip_info *info; 186 142 struct regmap *regmap; 187 143 bool fifo_delay; /* delay: delay is needed for SPI */ 188 144 u8 watermark; 189 145 u8 fifo_mode; 146 + 147 + u8 inact_threshold; 148 + u32 inact_time_ms; 190 149 191 150 u32 tap_duration_us; 192 151 u32 tap_latent_us; ··· 207 144 }; 208 145 209 146 static const struct iio_event_spec adxl345_events[] = { 147 + { 148 + /* activity */ 149 + .type = IIO_EV_TYPE_MAG, 150 + .dir = IIO_EV_DIR_RISING, 151 + .mask_shared_by_type = 152 + BIT(IIO_EV_INFO_ENABLE) | 153 + BIT(IIO_EV_INFO_VALUE), 154 + }, 155 + { 156 + /* activity, ac bit set */ 157 + .type = IIO_EV_TYPE_MAG_ADAPTIVE, 158 + .dir = IIO_EV_DIR_RISING, 159 + .mask_shared_by_type = 160 + BIT(IIO_EV_INFO_ENABLE) | 161 + BIT(IIO_EV_INFO_VALUE), 162 + }, 210 163 { 211 164 /* single tap */ 212 165 .type = IIO_EV_TYPE_GESTURE, ··· 267 188 chan_x, chan_y, chan_z, 268 189 }; 269 190 191 + static const struct iio_event_spec adxl345_fake_chan_events[] = { 192 + { 193 + /* inactivity */ 194 + .type = IIO_EV_TYPE_MAG, 195 + .dir = IIO_EV_DIR_FALLING, 196 + .mask_separate = BIT(IIO_EV_INFO_ENABLE), 197 + .mask_shared_by_type = 198 + BIT(IIO_EV_INFO_VALUE) | 199 + BIT(IIO_EV_INFO_PERIOD), 200 + }, 201 + { 202 + /* inactivity, AC bit set */ 203 + .type = IIO_EV_TYPE_MAG_ADAPTIVE, 204 + .dir = IIO_EV_DIR_FALLING, 205 + .mask_separate = BIT(IIO_EV_INFO_ENABLE), 206 + .mask_shared_by_type = 207 + BIT(IIO_EV_INFO_VALUE) | 208 + BIT(IIO_EV_INFO_PERIOD), 209 + }, 210 + }; 211 + 270 212 static const struct iio_chan_spec adxl345_channels[] = { 271 213 ADXL345_CHANNEL(0, chan_x, X), 272 214 ADXL345_CHANNEL(1, chan_y, Y), 273 215 ADXL345_CHANNEL(2, chan_z, Z), 216 + { 217 + .type = IIO_ACCEL, 218 + .modified = 1, 219 + .channel2 = IIO_MOD_X_AND_Y_AND_Z, 220 + .scan_index = -1, /* Fake channel */ 221 + .event_spec = adxl345_fake_chan_events, 222 + .num_event_specs = ARRAY_SIZE(adxl345_fake_chan_events), 223 + }, 274 224 }; 275 225 276 226 static const unsigned long adxl345_scan_masks[] = { ··· 343 235 { 344 236 return regmap_assign_bits(st->regmap, ADXL345_REG_POWER_CTL, 345 237 ADXL345_POWER_CTL_MEASURE, en); 238 + } 239 + 240 + /* activity / inactivity */ 241 + 242 + static int adxl345_set_inact_threshold(struct adxl345_state *st, 243 + unsigned int threshold) 244 + { 245 + int ret; 246 + 247 + st->inact_threshold = min(U8_MAX, threshold); 248 + 249 + ret = regmap_write(st->regmap, 250 + adxl345_act_thresh_reg[ADXL345_INACTIVITY], 251 + st->inact_threshold); 252 + if (ret) 253 + return ret; 254 + 255 + return regmap_write(st->regmap, 256 + adxl345_act_thresh_reg[ADXL345_INACTIVITY_FF], 257 + st->inact_threshold); 258 + } 259 + 260 + static int adxl345_set_default_time(struct adxl345_state *st) 261 + { 262 + int max_boundary = U8_MAX; 263 + int min_boundary = 10; 264 + enum adxl345_odr odr; 265 + unsigned int regval; 266 + unsigned int val; 267 + int ret; 268 + 269 + /* Generated inactivity time based on ODR */ 270 + ret = regmap_read(st->regmap, ADXL345_REG_BW_RATE, &regval); 271 + if (ret) 272 + return ret; 273 + 274 + odr = FIELD_GET(ADXL345_BW_RATE_MSK, regval); 275 + val = clamp(max_boundary - adxl345_odr_tbl[odr][0], 276 + min_boundary, max_boundary); 277 + st->inact_time_ms = MILLI * val; 278 + 279 + /* Inactivity time in s */ 280 + return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val); 281 + } 282 + 283 + static int adxl345_set_inactivity_time(struct adxl345_state *st, u32 val_int) 284 + { 285 + st->inact_time_ms = MILLI * val_int; 286 + 287 + return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val_int); 288 + } 289 + 290 + static int adxl345_set_freefall_time(struct adxl345_state *st, u32 val_fract) 291 + { 292 + /* 293 + * Datasheet max. value is 255 * 5000 us = 1.275000 seconds. 294 + * 295 + * Recommended values between 100ms and 350ms (0x14 to 0x46) 296 + */ 297 + st->inact_time_ms = DIV_ROUND_UP(val_fract, MILLI); 298 + 299 + return regmap_write(st->regmap, ADXL345_REG_TIME_FF, 300 + DIV_ROUND_CLOSEST(val_fract, 5)); 301 + } 302 + 303 + /** 304 + * adxl345_set_inact_time - Configure inactivity time explicitly or by ODR. 305 + * @st: The sensor state instance. 306 + * @val_int: The inactivity time, integer part. 307 + * @val_fract: The inactivity time, fractional part when val_int is 0. 308 + * 309 + * Inactivity time can be configured between 1 and 255 seconds. If a user sets 310 + * val_s to 0, a default inactivity time is calculated automatically (since 0 is 311 + * also invalid and undefined by the sensor). 312 + * 313 + * In such cases, power consumption should be considered: the inactivity period 314 + * should be shorter at higher sampling frequencies and longer at lower ones. 315 + * Specifically, for frequencies above 255 Hz, the default is set to 10 seconds; 316 + * for frequencies below 10 Hz, it defaults to 255 seconds. 317 + * 318 + * The calculation method subtracts the integer part of the configured sample 319 + * frequency from 255 to estimate the inactivity time in seconds. Sub-Hertz 320 + * values are ignored in this approximation. Since the recommended output data 321 + * rates (ODRs) for features like activity/inactivity detection, sleep modes, 322 + * and free fall range between 12.5 Hz and 400 Hz, frequencies outside this 323 + * range will either use the defined boundary defaults or require explicit 324 + * configuration via val_s. 325 + * 326 + * Return: 0 or error value. 327 + */ 328 + static int adxl345_set_inact_time(struct adxl345_state *st, u32 val_int, 329 + u32 val_fract) 330 + { 331 + if (val_int > 0) { 332 + /* Time >= 1s, inactivity */ 333 + return adxl345_set_inactivity_time(st, val_int); 334 + } else if (val_int == 0) { 335 + if (val_fract > 0) { 336 + /* Time < 1s, free-fall */ 337 + return adxl345_set_freefall_time(st, val_fract); 338 + } else if (val_fract == 0) { 339 + /* Time == 0.0s */ 340 + return adxl345_set_default_time(st); 341 + } 342 + } 343 + 344 + /* Do not support negative or wrong input. */ 345 + return -EINVAL; 346 + } 347 + 348 + /** 349 + * adxl345_is_act_inact_ac() - Verify if AC or DC coupling is currently enabled. 350 + * 351 + * @st: The device data. 352 + * @type: The activity or inactivity type. 353 + * 354 + * Given a type of activity / inactivity combined with either AC coupling set or 355 + * default to DC, this function verifies if the combination is currently 356 + * configured, hence enabled or not. 357 + * 358 + * Return: true if configured coupling matches the provided type, else a negative 359 + * error value. 360 + */ 361 + static int adxl345_is_act_inact_ac(struct adxl345_state *st, 362 + enum adxl345_activity_type type) 363 + { 364 + unsigned int regval; 365 + bool coupling; 366 + int ret; 367 + 368 + if (type == ADXL345_INACTIVITY_FF) 369 + return true; 370 + 371 + ret = regmap_read(st->regmap, ADXL345_REG_ACT_INACT_CTRL, &regval); 372 + if (ret) 373 + return ret; 374 + 375 + coupling = adxl345_act_acdc_msk[type] & regval; 376 + 377 + switch (type) { 378 + case ADXL345_ACTIVITY: 379 + case ADXL345_INACTIVITY: 380 + return coupling == ADXL345_COUPLING_DC; 381 + case ADXL345_ACTIVITY_AC: 382 + case ADXL345_INACTIVITY_AC: 383 + return coupling == ADXL345_COUPLING_AC; 384 + default: 385 + return -EINVAL; 386 + } 387 + } 388 + 389 + /** 390 + * adxl345_set_act_inact_ac() - Configure AC coupling or DC coupling. 391 + * 392 + * @st: The device data. 393 + * @type: Provide a type of activity or inactivity. 394 + * @cmd_en: enable or disable AC coupling. 395 + * 396 + * Enables AC coupling or DC coupling depending on the provided type argument. 397 + * Note: Activity and inactivity can be either AC coupled or DC coupled not 398 + * both at the same time. 399 + * 400 + * Return: 0 if successful, else error value. 401 + */ 402 + static int adxl345_set_act_inact_ac(struct adxl345_state *st, 403 + enum adxl345_activity_type type, 404 + bool cmd_en) 405 + { 406 + unsigned int act_inact_ac; 407 + 408 + if (type == ADXL345_ACTIVITY_AC || type == ADXL345_INACTIVITY_AC) 409 + act_inact_ac = ADXL345_COUPLING_AC && cmd_en; 410 + else 411 + act_inact_ac = ADXL345_COUPLING_DC && cmd_en; 412 + 413 + /* 414 + * A setting of false selects dc-coupled operation, and a setting of 415 + * true enables ac-coupled operation. In dc-coupled operation, the 416 + * current acceleration magnitude is compared directly with 417 + * ADXL345_REG_THRESH_ACT and ADXL345_REG_THRESH_INACT to determine 418 + * whether activity or inactivity is detected. 419 + * 420 + * In ac-coupled operation for activity detection, the acceleration 421 + * value at the start of activity detection is taken as a reference 422 + * value. New samples of acceleration are then compared to this 423 + * reference value, and if the magnitude of the difference exceeds the 424 + * ADXL345_REG_THRESH_ACT value, the device triggers an activity 425 + * interrupt. 426 + * 427 + * Similarly, in ac-coupled operation for inactivity detection, a 428 + * reference value is used for comparison and is updated whenever the 429 + * device exceeds the inactivity threshold. After the reference value 430 + * is selected, the device compares the magnitude of the difference 431 + * between the reference value and the current acceleration with 432 + * ADXL345_REG_THRESH_INACT. If the difference is less than the value in 433 + * ADXL345_REG_THRESH_INACT for the time in ADXL345_REG_TIME_INACT, the 434 + * device is considered inactive and the inactivity interrupt is 435 + * triggered. [quoted from p. 24, ADXL345 datasheet Rev. G] 436 + * 437 + * In a conclusion, the first acceleration snapshot sample which hit the 438 + * threshold in a particular direction is always taken as acceleration 439 + * reference value to that direction. Since for the hardware activity 440 + * and inactivity depend on the x/y/z axis, so do ac and dc coupling. 441 + * Note, this sw driver always enables or disables all three x/y/z axis 442 + * for detection via act_axis_ctrl and inact_axis_ctrl, respectively. 443 + * Where in dc-coupling samples are compared against the thresholds, in 444 + * ac-coupling measurement difference to the first acceleration 445 + * reference value are compared against the threshold. So, ac-coupling 446 + * allows for a bit more dynamic compensation depending on the initial 447 + * sample. 448 + */ 449 + return regmap_assign_bits(st->regmap, ADXL345_REG_ACT_INACT_CTRL, 450 + adxl345_act_acdc_msk[type], act_inact_ac); 451 + } 452 + 453 + static int adxl345_is_act_inact_en(struct adxl345_state *st, 454 + enum adxl345_activity_type type) 455 + { 456 + unsigned int axis_ctrl; 457 + unsigned int regval; 458 + bool int_en, en; 459 + int ret; 460 + 461 + ret = regmap_read(st->regmap, ADXL345_REG_ACT_INACT_CTRL, &axis_ctrl); 462 + if (ret) 463 + return ret; 464 + 465 + /* Check if axis for activity are enabled */ 466 + switch (type) { 467 + case ADXL345_ACTIVITY: 468 + case ADXL345_ACTIVITY_AC: 469 + en = FIELD_GET(ADXL345_ACT_XYZ_EN, axis_ctrl); 470 + if (!en) 471 + return false; 472 + break; 473 + case ADXL345_INACTIVITY: 474 + case ADXL345_INACTIVITY_AC: 475 + en = FIELD_GET(ADXL345_INACT_XYZ_EN, axis_ctrl); 476 + if (!en) 477 + return false; 478 + break; 479 + case ADXL345_INACTIVITY_FF: 480 + en = true; 481 + break; 482 + default: 483 + return -EINVAL; 484 + } 485 + 486 + /* Check if specific interrupt is enabled */ 487 + ret = regmap_read(st->regmap, ADXL345_REG_INT_ENABLE, &regval); 488 + if (ret) 489 + return ret; 490 + 491 + int_en = adxl345_act_int_reg[type] & regval; 492 + if (!int_en) 493 + return false; 494 + 495 + /* Check if configured coupling matches provided type */ 496 + return adxl345_is_act_inact_ac(st, type); 497 + } 498 + 499 + static int adxl345_set_act_inact_linkbit(struct adxl345_state *st, 500 + enum adxl345_activity_type type, 501 + bool en) 502 + { 503 + int act_ac_en, inact_ac_en; 504 + int act_en, inact_en; 505 + 506 + act_en = adxl345_is_act_inact_en(st, ADXL345_ACTIVITY); 507 + if (act_en < 0) 508 + return act_en; 509 + 510 + act_ac_en = adxl345_is_act_inact_en(st, ADXL345_ACTIVITY_AC); 511 + if (act_ac_en < 0) 512 + return act_ac_en; 513 + 514 + if (type == ADXL345_INACTIVITY_FF) { 515 + inact_en = false; 516 + } else { 517 + inact_en = adxl345_is_act_inact_en(st, ADXL345_INACTIVITY); 518 + if (inact_en < 0) 519 + return inact_en; 520 + 521 + inact_ac_en = adxl345_is_act_inact_en(st, ADXL345_INACTIVITY_AC); 522 + if (inact_ac_en < 0) 523 + return inact_ac_en; 524 + 525 + inact_en = inact_en || inact_ac_en; 526 + } 527 + 528 + act_en = act_en || act_ac_en; 529 + 530 + return regmap_assign_bits(st->regmap, ADXL345_REG_POWER_CTL, 531 + ADXL345_POWER_CTL_INACT_MSK, 532 + en && act_en && inact_en); 533 + } 534 + 535 + static int adxl345_set_act_inact_en(struct adxl345_state *st, 536 + enum adxl345_activity_type type, 537 + bool cmd_en) 538 + { 539 + unsigned int axis_ctrl; 540 + unsigned int threshold; 541 + unsigned int period; 542 + int ret; 543 + 544 + if (cmd_en) { 545 + /* When turning on, check if threshold is valid */ 546 + if (type == ADXL345_ACTIVITY || type == ADXL345_ACTIVITY_AC) { 547 + ret = regmap_read(st->regmap, 548 + adxl345_act_thresh_reg[type], 549 + &threshold); 550 + if (ret) 551 + return ret; 552 + } else { 553 + threshold = st->inact_threshold; 554 + } 555 + 556 + if (!threshold) /* Just ignore the command if threshold is 0 */ 557 + return 0; 558 + 559 + /* When turning on inactivity, check if inact time is valid */ 560 + if (type == ADXL345_INACTIVITY || type == ADXL345_INACTIVITY_AC) { 561 + ret = regmap_read(st->regmap, 562 + ADXL345_REG_TIME_INACT, 563 + &period); 564 + if (ret) 565 + return ret; 566 + 567 + if (!period) 568 + return 0; 569 + } 570 + } else { 571 + /* 572 + * When turning off an activity, ensure that the correct 573 + * coupling event is specified. This step helps prevent misuse - 574 + * for example, if an AC-coupled activity is active and the 575 + * current call attempts to turn off a DC-coupled activity, this 576 + * inconsistency should be detected here. 577 + */ 578 + if (adxl345_is_act_inact_ac(st, type) <= 0) 579 + return 0; 580 + } 581 + 582 + /* Start modifying configuration registers */ 583 + ret = adxl345_set_measure_en(st, false); 584 + if (ret) 585 + return ret; 586 + 587 + /* Enable axis according to the command */ 588 + switch (type) { 589 + case ADXL345_ACTIVITY: 590 + case ADXL345_ACTIVITY_AC: 591 + axis_ctrl = ADXL345_ACT_XYZ_EN; 592 + break; 593 + case ADXL345_INACTIVITY: 594 + case ADXL345_INACTIVITY_AC: 595 + axis_ctrl = ADXL345_INACT_XYZ_EN; 596 + break; 597 + case ADXL345_INACTIVITY_FF: 598 + axis_ctrl = ADXL345_ACT_INACT_NO_AXIS_EN; 599 + break; 600 + default: 601 + return -EINVAL; 602 + } 603 + 604 + ret = regmap_assign_bits(st->regmap, ADXL345_REG_ACT_INACT_CTRL, 605 + axis_ctrl, cmd_en); 606 + if (ret) 607 + return ret; 608 + 609 + /* Update AC/DC-coupling according to the command */ 610 + ret = adxl345_set_act_inact_ac(st, type, cmd_en); 611 + if (ret) 612 + return ret; 613 + 614 + /* Enable the interrupt line, according to the command */ 615 + ret = regmap_assign_bits(st->regmap, ADXL345_REG_INT_ENABLE, 616 + adxl345_act_int_reg[type], cmd_en); 617 + if (ret) 618 + return ret; 619 + 620 + /* Set link-bit and auto-sleep only when ACT and INACT are enabled */ 621 + ret = adxl345_set_act_inact_linkbit(st, type, cmd_en); 622 + if (ret) 623 + return ret; 624 + 625 + return adxl345_set_measure_en(st, true); 346 626 } 347 627 348 628 /* tap */ ··· 864 368 * Generally suppress detection of spikes during the latency period as 865 369 * double taps here, this is fully optional for double tap detection 866 370 */ 867 - ret = regmap_update_bits(st->regmap, ADXL345_REG_TAP_AXIS, 868 - ADXL345_REG_TAP_SUPPRESS_MSK, 869 - en ? ADXL345_REG_TAP_SUPPRESS : 0x00); 371 + ret = regmap_assign_bits(st->regmap, ADXL345_REG_TAP_AXIS, 372 + ADXL345_REG_TAP_SUPPRESS, en); 870 373 if (ret) 871 374 return ret; 872 375 ··· 961 466 962 467 static int adxl345_set_odr(struct adxl345_state *st, enum adxl345_odr odr) 963 468 { 964 - return regmap_update_bits(st->regmap, ADXL345_REG_BW_RATE, 469 + int ret; 470 + 471 + ret = regmap_update_bits(st->regmap, ADXL345_REG_BW_RATE, 965 472 ADXL345_BW_RATE_MSK, 966 473 FIELD_PREP(ADXL345_BW_RATE_MSK, odr)); 474 + if (ret) 475 + return ret; 476 + 477 + /* update inactivity time by ODR */ 478 + return adxl345_set_inact_time(st, 0, 0); 967 479 } 968 480 969 481 static int adxl345_find_range(struct adxl345_state *st, int val, int val2, ··· 991 489 992 490 static int adxl345_set_range(struct adxl345_state *st, enum adxl345_range range) 993 491 { 994 - return regmap_update_bits(st->regmap, ADXL345_REG_DATA_FORMAT, 492 + unsigned int act_threshold, inact_threshold; 493 + unsigned int range_old; 494 + unsigned int regval; 495 + int ret; 496 + 497 + ret = regmap_read(st->regmap, ADXL345_REG_DATA_FORMAT, &regval); 498 + if (ret) 499 + return ret; 500 + range_old = FIELD_GET(ADXL345_DATA_FORMAT_RANGE, regval); 501 + 502 + ret = regmap_read(st->regmap, 503 + adxl345_act_thresh_reg[ADXL345_ACTIVITY], 504 + &act_threshold); 505 + if (ret) 506 + return ret; 507 + 508 + ret = regmap_update_bits(st->regmap, ADXL345_REG_DATA_FORMAT, 995 509 ADXL345_DATA_FORMAT_RANGE, 996 510 FIELD_PREP(ADXL345_DATA_FORMAT_RANGE, range)); 511 + if (ret) 512 + return ret; 513 + 514 + act_threshold = act_threshold * adxl345_range_factor_tbl[range_old] 515 + / adxl345_range_factor_tbl[range]; 516 + act_threshold = min(U8_MAX, max(1, act_threshold)); 517 + 518 + inact_threshold = st->inact_threshold; 519 + inact_threshold = inact_threshold * adxl345_range_factor_tbl[range_old] 520 + / adxl345_range_factor_tbl[range]; 521 + inact_threshold = min(U8_MAX, max(1, inact_threshold)); 522 + 523 + ret = regmap_write(st->regmap, adxl345_act_thresh_reg[ADXL345_ACTIVITY], 524 + act_threshold); 525 + if (ret) 526 + return ret; 527 + 528 + return adxl345_set_inact_threshold(st, inact_threshold); 997 529 } 998 530 999 531 static int adxl345_read_avail(struct iio_dev *indio_dev, ··· 1160 624 return adxl345_set_measure_en(st, true); 1161 625 } 1162 626 627 + static int adxl345_read_mag_config(struct adxl345_state *st, 628 + enum iio_event_direction dir, 629 + enum adxl345_activity_type type_act, 630 + enum adxl345_activity_type type_inact) 631 + { 632 + switch (dir) { 633 + case IIO_EV_DIR_RISING: 634 + return !!adxl345_is_act_inact_en(st, type_act); 635 + case IIO_EV_DIR_FALLING: 636 + return !!adxl345_is_act_inact_en(st, type_inact); 637 + default: 638 + return -EINVAL; 639 + } 640 + } 641 + 642 + static int adxl345_write_mag_config(struct adxl345_state *st, 643 + enum iio_event_direction dir, 644 + enum adxl345_activity_type type_act, 645 + enum adxl345_activity_type type_inact, 646 + bool state) 647 + { 648 + switch (dir) { 649 + case IIO_EV_DIR_RISING: 650 + return adxl345_set_act_inact_en(st, type_act, state); 651 + case IIO_EV_DIR_FALLING: 652 + return adxl345_set_act_inact_en(st, type_inact, state); 653 + default: 654 + return -EINVAL; 655 + } 656 + } 657 + 1163 658 static int adxl345_read_event_config(struct iio_dev *indio_dev, 1164 659 const struct iio_chan_spec *chan, 1165 660 enum iio_event_type type, ··· 1201 634 int ret; 1202 635 1203 636 switch (type) { 637 + case IIO_EV_TYPE_MAG: 638 + return adxl345_read_mag_config(st, dir, 639 + ADXL345_ACTIVITY, 640 + ADXL345_INACTIVITY); 641 + case IIO_EV_TYPE_MAG_ADAPTIVE: 642 + return adxl345_read_mag_config(st, dir, 643 + ADXL345_ACTIVITY_AC, 644 + ADXL345_INACTIVITY_AC); 1204 645 case IIO_EV_TYPE_GESTURE: 1205 646 switch (dir) { 1206 647 case IIO_EV_DIR_SINGLETAP: ··· 1240 665 struct adxl345_state *st = iio_priv(indio_dev); 1241 666 1242 667 switch (type) { 668 + case IIO_EV_TYPE_MAG: 669 + return adxl345_write_mag_config(st, dir, 670 + ADXL345_ACTIVITY, 671 + ADXL345_INACTIVITY, 672 + state); 673 + case IIO_EV_TYPE_MAG_ADAPTIVE: 674 + return adxl345_write_mag_config(st, dir, 675 + ADXL345_ACTIVITY_AC, 676 + ADXL345_INACTIVITY_AC, 677 + state); 1243 678 case IIO_EV_TYPE_GESTURE: 1244 679 switch (dir) { 1245 680 case IIO_EV_DIR_SINGLETAP: ··· 1259 674 default: 1260 675 return -EINVAL; 1261 676 } 677 + default: 678 + return -EINVAL; 679 + } 680 + } 681 + 682 + static int adxl345_read_mag_value(struct adxl345_state *st, 683 + enum iio_event_direction dir, 684 + enum iio_event_info info, 685 + enum adxl345_activity_type type_act, 686 + enum adxl345_activity_type type_inact, 687 + int *val, int *val2) 688 + { 689 + unsigned int threshold; 690 + int ret; 691 + 692 + switch (info) { 693 + case IIO_EV_INFO_VALUE: 694 + switch (dir) { 695 + case IIO_EV_DIR_RISING: 696 + ret = regmap_read(st->regmap, 697 + adxl345_act_thresh_reg[type_act], 698 + &threshold); 699 + if (ret) 700 + return ret; 701 + *val = 62500 * threshold; 702 + *val2 = MICRO; 703 + return IIO_VAL_FRACTIONAL; 704 + case IIO_EV_DIR_FALLING: 705 + *val = 62500 * st->inact_threshold; 706 + *val2 = MICRO; 707 + return IIO_VAL_FRACTIONAL; 708 + default: 709 + return -EINVAL; 710 + } 711 + case IIO_EV_INFO_PERIOD: 712 + *val = st->inact_time_ms; 713 + *val2 = MILLI; 714 + return IIO_VAL_FRACTIONAL; 715 + default: 716 + return -EINVAL; 717 + } 718 + } 719 + 720 + static int adxl345_write_mag_value(struct adxl345_state *st, 721 + enum iio_event_direction dir, 722 + enum iio_event_info info, 723 + enum adxl345_activity_type type_act, 724 + enum adxl345_activity_type type_inact, 725 + int val, int val2) 726 + { 727 + switch (info) { 728 + case IIO_EV_INFO_VALUE: 729 + /* Scaling factor 62.5mg/LSB, i.e. ~16g corresponds to 0xff */ 730 + val = DIV_ROUND_CLOSEST(val * MICRO + val2, 62500); 731 + switch (dir) { 732 + case IIO_EV_DIR_RISING: 733 + return regmap_write(st->regmap, 734 + adxl345_act_thresh_reg[type_act], 735 + val); 736 + case IIO_EV_DIR_FALLING: 737 + return adxl345_set_inact_threshold(st, val); 738 + default: 739 + return -EINVAL; 740 + } 741 + case IIO_EV_INFO_PERIOD: 742 + return adxl345_set_inact_time(st, val, val2); 1262 743 default: 1263 744 return -EINVAL; 1264 745 } ··· 1342 691 int ret; 1343 692 1344 693 switch (type) { 694 + case IIO_EV_TYPE_MAG: 695 + return adxl345_read_mag_value(st, dir, info, 696 + ADXL345_ACTIVITY, 697 + ADXL345_INACTIVITY, 698 + val, val2); 699 + case IIO_EV_TYPE_MAG_ADAPTIVE: 700 + return adxl345_read_mag_value(st, dir, info, 701 + ADXL345_ACTIVITY_AC, 702 + ADXL345_INACTIVITY_AC, 703 + val, val2); 1345 704 case IIO_EV_TYPE_GESTURE: 1346 705 switch (info) { 1347 706 case IIO_EV_INFO_VALUE: ··· 1402 741 return ret; 1403 742 1404 743 switch (type) { 744 + case IIO_EV_TYPE_MAG: 745 + ret = adxl345_write_mag_value(st, dir, info, 746 + ADXL345_ACTIVITY, 747 + ADXL345_INACTIVITY, 748 + val, val2); 749 + if (ret) 750 + return ret; 751 + break; 752 + case IIO_EV_TYPE_MAG_ADAPTIVE: 753 + ret = adxl345_write_mag_value(st, dir, info, 754 + ADXL345_ACTIVITY_AC, 755 + ADXL345_INACTIVITY_AC, 756 + val, val2); 757 + if (ret) 758 + return ret; 759 + break; 1405 760 case IIO_EV_TYPE_GESTURE: 1406 761 switch (info) { 1407 762 case IIO_EV_INFO_VALUE: ··· 1657 980 } 1658 981 1659 982 static int adxl345_push_event(struct iio_dev *indio_dev, int int_stat, 983 + enum iio_modifier act_dir, 1660 984 enum iio_modifier tap_dir) 1661 985 { 1662 986 s64 ts = iio_get_time_ns(indio_dev); 1663 987 struct adxl345_state *st = iio_priv(indio_dev); 988 + unsigned int regval; 1664 989 int samples; 1665 990 int ret = -ENOENT; 1666 991 ··· 1681 1002 IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, tap_dir, 1682 1003 IIO_EV_TYPE_GESTURE, 1683 1004 IIO_EV_DIR_DOUBLETAP), 1005 + ts); 1006 + if (ret) 1007 + return ret; 1008 + } 1009 + 1010 + if (FIELD_GET(ADXL345_INT_ACTIVITY, int_stat)) { 1011 + ret = regmap_read(st->regmap, ADXL345_REG_ACT_INACT_CTRL, &regval); 1012 + if (ret) 1013 + return ret; 1014 + 1015 + if (FIELD_GET(ADXL345_REG_ACT_ACDC, regval)) { 1016 + /* AC coupled */ 1017 + ret = iio_push_event(indio_dev, 1018 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, act_dir, 1019 + IIO_EV_TYPE_MAG_ADAPTIVE, 1020 + IIO_EV_DIR_RISING), 1021 + ts); 1022 + 1023 + } else { 1024 + /* DC coupled, relying on THRESH */ 1025 + ret = iio_push_event(indio_dev, 1026 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, act_dir, 1027 + IIO_EV_TYPE_MAG, 1028 + IIO_EV_DIR_RISING), 1029 + ts); 1030 + } 1031 + if (ret) 1032 + return ret; 1033 + } 1034 + 1035 + if (FIELD_GET(ADXL345_INT_INACTIVITY, int_stat)) { 1036 + ret = regmap_read(st->regmap, ADXL345_REG_ACT_INACT_CTRL, &regval); 1037 + if (ret) 1038 + return ret; 1039 + 1040 + if (FIELD_GET(ADXL345_REG_INACT_ACDC, regval)) { 1041 + /* AC coupled */ 1042 + ret = iio_push_event(indio_dev, 1043 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, 1044 + IIO_MOD_X_AND_Y_AND_Z, 1045 + IIO_EV_TYPE_MAG_ADAPTIVE, 1046 + IIO_EV_DIR_FALLING), 1047 + ts); 1048 + } else { 1049 + /* DC coupled, relying on THRESH */ 1050 + ret = iio_push_event(indio_dev, 1051 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, 1052 + IIO_MOD_X_AND_Y_AND_Z, 1053 + IIO_EV_TYPE_MAG, 1054 + IIO_EV_DIR_FALLING), 1055 + ts); 1056 + } 1057 + if (ret) 1058 + return ret; 1059 + } 1060 + 1061 + if (FIELD_GET(ADXL345_INT_FREE_FALL, int_stat)) { 1062 + ret = iio_push_event(indio_dev, 1063 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, 1064 + IIO_MOD_X_AND_Y_AND_Z, 1065 + IIO_EV_TYPE_MAG, 1066 + IIO_EV_DIR_FALLING), 1684 1067 ts); 1685 1068 if (ret) 1686 1069 return ret; ··· 1775 1034 struct adxl345_state *st = iio_priv(indio_dev); 1776 1035 unsigned int regval; 1777 1036 enum iio_modifier tap_dir = IIO_NO_MOD; 1037 + enum iio_modifier act_dir = IIO_NO_MOD; 1778 1038 u32 axis_ctrl; 1779 1039 int int_stat; 1780 1040 int ret; ··· 1784 1042 if (ret) 1785 1043 return IRQ_NONE; 1786 1044 1787 - if (FIELD_GET(ADXL345_REG_TAP_AXIS_MSK, axis_ctrl)) { 1045 + if (FIELD_GET(ADXL345_REG_TAP_AXIS_MSK, axis_ctrl) || 1046 + FIELD_GET(ADXL345_ACT_XYZ_EN, axis_ctrl)) { 1788 1047 ret = regmap_read(st->regmap, ADXL345_REG_ACT_TAP_STATUS, &regval); 1789 1048 if (ret) 1790 1049 return IRQ_NONE; ··· 1796 1053 tap_dir = IIO_MOD_Y; 1797 1054 else if (FIELD_GET(ADXL345_TAP_X_EN, regval)) 1798 1055 tap_dir = IIO_MOD_X; 1056 + 1057 + if (FIELD_GET(ADXL345_ACT_Z_EN, regval)) 1058 + act_dir = IIO_MOD_Z; 1059 + else if (FIELD_GET(ADXL345_ACT_Y_EN, regval)) 1060 + act_dir = IIO_MOD_Y; 1061 + else if (FIELD_GET(ADXL345_ACT_X_EN, regval)) 1062 + act_dir = IIO_MOD_X; 1799 1063 } 1800 1064 1801 1065 if (regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, &int_stat)) 1802 1066 return IRQ_NONE; 1803 1067 1804 - if (adxl345_push_event(indio_dev, int_stat, tap_dir)) 1068 + if (adxl345_push_event(indio_dev, int_stat, act_dir, tap_dir)) 1805 1069 goto err; 1806 1070 1807 1071 if (FIELD_GET(ADXL345_INT_OVERRUN, int_stat)) ··· 1973 1223 */ 1974 1224 ret = regmap_assign_bits(st->regmap, ADXL345_REG_INT_MAP, 1975 1225 U8_MAX, intio); 1226 + if (ret) 1227 + return ret; 1228 + 1229 + /* 1230 + * Initialized with sensible default values to streamline 1231 + * sensor operation. These defaults are partly derived from 1232 + * the previous input driver for the ADXL345 and partly 1233 + * based on the recommendations provided in the datasheet. 1234 + */ 1235 + ret = regmap_write(st->regmap, ADXL345_REG_ACT_INACT_CTRL, 0); 1236 + if (ret) 1237 + return ret; 1238 + 1239 + ret = regmap_write(st->regmap, ADXL345_REG_THRESH_ACT, 6); 1240 + if (ret) 1241 + return ret; 1242 + 1243 + ret = adxl345_set_inact_threshold(st, 4); 1976 1244 if (ret) 1977 1245 return ret; 1978 1246
+6 -7
drivers/iio/accel/bma180.c
··· 139 139 int scale; 140 140 int bw; 141 141 bool pmode; 142 - /* Ensure timestamp is naturally aligned */ 143 - struct { 144 - s16 chan[4]; 145 - aligned_s64 timestamp; 146 - } scan; 147 142 }; 148 143 149 144 enum bma180_chan { ··· 865 870 struct bma180_data *data = iio_priv(indio_dev); 866 871 s64 time_ns = iio_get_time_ns(indio_dev); 867 872 int bit, ret, i = 0; 873 + struct { 874 + s16 chan[4]; 875 + aligned_s64 timestamp; 876 + } scan = { }; 868 877 869 878 mutex_lock(&data->mutex); 870 879 ··· 878 879 mutex_unlock(&data->mutex); 879 880 goto err; 880 881 } 881 - data->scan.chan[i++] = ret; 882 + scan.chan[i++] = ret; 882 883 } 883 884 884 885 mutex_unlock(&data->mutex); 885 886 886 - iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan), time_ns); 887 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), time_ns); 887 888 err: 888 889 iio_trigger_notify_done(indio_dev->trig); 889 890
+1 -3
drivers/iio/accel/bma220_spi.c
··· 255 255 struct bma220_data *data; 256 256 257 257 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data)); 258 - if (!indio_dev) { 259 - dev_err(&spi->dev, "iio allocation failed!\n"); 258 + if (!indio_dev) 260 259 return -ENOMEM; 261 - } 262 260 263 261 data = iio_priv(indio_dev); 264 262 data->spi_device = spi;
+2 -5
drivers/iio/accel/bmc150-accel-core.c
··· 332 332 struct device *dev = regmap_get_device(data->regmap); 333 333 int ret; 334 334 335 - if (on) { 335 + if (on) 336 336 ret = pm_runtime_resume_and_get(dev); 337 - } else { 338 - pm_runtime_mark_last_busy(dev); 337 + else 339 338 ret = pm_runtime_put_autosuspend(dev); 340 - } 341 - 342 339 if (ret < 0) { 343 340 dev_err(dev, 344 341 "Failed: %s for %d\n", __func__, on);
-3
drivers/iio/accel/bmi088-accel-core.c
··· 375 375 return -EINVAL; 376 376 377 377 out_read_raw_pm_put: 378 - pm_runtime_mark_last_busy(dev); 379 378 pm_runtime_put_autosuspend(dev); 380 379 381 380 return ret; ··· 418 419 return ret; 419 420 420 421 ret = bmi088_accel_set_scale(data, val, val2); 421 - pm_runtime_mark_last_busy(dev); 422 422 pm_runtime_put_autosuspend(dev); 423 423 return ret; 424 424 case IIO_CHAN_INFO_SAMP_FREQ: ··· 426 428 return ret; 427 429 428 430 ret = bmi088_accel_set_sample_freq(data, val); 429 - pm_runtime_mark_last_busy(dev); 430 431 pm_runtime_put_autosuspend(dev); 431 432 return ret; 432 433 default:
+1 -3
drivers/iio/accel/dmard06.c
··· 137 137 } 138 138 139 139 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dmard06)); 140 - if (!indio_dev) { 141 - dev_err(&client->dev, "Failed to allocate iio device\n"); 140 + if (!indio_dev) 142 141 return -ENOMEM; 143 - } 144 142 145 143 dmard06 = iio_priv(indio_dev); 146 144 dmard06->client = client;
+1 -3
drivers/iio/accel/dmard09.c
··· 95 95 struct dmard09_data *data; 96 96 97 97 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 98 - if (!indio_dev) { 99 - dev_err(&client->dev, "iio allocation failed\n"); 98 + if (!indio_dev) 100 99 return -ENOMEM; 101 - } 102 100 103 101 data = iio_priv(indio_dev); 104 102 data->client = client;
+1 -3
drivers/iio/accel/dmard10.c
··· 191 191 return (ret < 0) ? ret : -ENODEV; 192 192 193 193 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 194 - if (!indio_dev) { 195 - dev_err(&client->dev, "iio allocation failed!\n"); 194 + if (!indio_dev) 196 195 return -ENOMEM; 197 - } 198 196 199 197 data = iio_priv(indio_dev); 200 198 data->client = client;
-1
drivers/iio/accel/fxls8962af-core.c
··· 222 222 struct device *dev = regmap_get_device(data->regmap); 223 223 int ret; 224 224 225 - pm_runtime_mark_last_busy(dev); 226 225 ret = pm_runtime_put_autosuspend(dev); 227 226 if (ret) 228 227 dev_err(dev, "failed to power off\n");
+1 -3
drivers/iio/accel/kxcjk-1013.c
··· 636 636 637 637 if (on) 638 638 ret = pm_runtime_resume_and_get(&data->client->dev); 639 - else { 640 - pm_runtime_mark_last_busy(&data->client->dev); 639 + else 641 640 ret = pm_runtime_put_autosuspend(&data->client->dev); 642 - } 643 641 if (ret < 0) { 644 642 dev_err(&data->client->dev, 645 643 "Failed: %s for %d\n", __func__, on);
-3
drivers/iio/accel/kxsd9.c
··· 151 151 ret = kxsd9_write_scale(indio_dev, val2); 152 152 } 153 153 154 - pm_runtime_mark_last_busy(st->dev); 155 154 pm_runtime_put_autosuspend(st->dev); 156 155 157 156 return ret; ··· 198 199 } 199 200 200 201 error_ret: 201 - pm_runtime_mark_last_busy(st->dev); 202 202 pm_runtime_put_autosuspend(st->dev); 203 203 204 204 return ret; ··· 248 250 { 249 251 struct kxsd9_state *st = iio_priv(indio_dev); 250 252 251 - pm_runtime_mark_last_busy(st->dev); 252 253 pm_runtime_put_autosuspend(st->dev); 253 254 254 255 return 0;
+1 -3
drivers/iio/accel/mc3230.c
··· 169 169 } 170 170 171 171 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 172 - if (!indio_dev) { 173 - dev_err(&client->dev, "iio allocation failed!\n"); 172 + if (!indio_dev) 174 173 return -ENOMEM; 175 - } 176 174 177 175 data = iio_priv(indio_dev); 178 176 data->chip_info = chip_info;
+1 -3
drivers/iio/accel/mma7660.c
··· 192 192 struct mma7660_data *data; 193 193 194 194 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 195 - if (!indio_dev) { 196 - dev_err(&client->dev, "iio allocation failed!\n"); 195 + if (!indio_dev) 197 196 return -ENOMEM; 198 - } 199 197 200 198 data = iio_priv(indio_dev); 201 199 data->client = client;
+2 -5
drivers/iio/accel/mma8452.c
··· 224 224 #ifdef CONFIG_PM 225 225 int ret; 226 226 227 - if (on) { 227 + if (on) 228 228 ret = pm_runtime_resume_and_get(&client->dev); 229 - } else { 230 - pm_runtime_mark_last_busy(&client->dev); 229 + else 231 230 ret = pm_runtime_put_autosuspend(&client->dev); 232 - } 233 - 234 231 if (ret < 0) { 235 232 dev_err(&client->dev, 236 233 "failed to change power state to %d\n", on);
+1 -4
drivers/iio/accel/mma9551_core.c
··· 671 671 672 672 if (on) 673 673 ret = pm_runtime_resume_and_get(&client->dev); 674 - else { 675 - pm_runtime_mark_last_busy(&client->dev); 674 + else 676 675 ret = pm_runtime_put_autosuspend(&client->dev); 677 - } 678 - 679 676 if (ret < 0) { 680 677 dev_err(&client->dev, 681 678 "failed to change power state to %d\n", on);
+4 -12
drivers/iio/accel/msa311.c
··· 607 607 err = msa311_get_axis(msa311, chan, &axis); 608 608 mutex_unlock(&msa311->lock); 609 609 610 - pm_runtime_mark_last_busy(dev); 611 610 pm_runtime_put_autosuspend(dev); 612 611 613 612 iio_device_release_direct(indio_dev); ··· 740 741 break; 741 742 } 742 743 743 - pm_runtime_mark_last_busy(dev); 744 744 pm_runtime_put_autosuspend(dev); 745 745 746 746 if (err) ··· 779 781 break; 780 782 } 781 783 782 - pm_runtime_mark_last_busy(dev); 783 784 pm_runtime_put_autosuspend(dev); 784 785 785 786 iio_device_release_direct(indio_dev); ··· 829 832 830 833 mutex_unlock(&msa311->lock); 831 834 832 - pm_runtime_mark_last_busy(dev); 833 835 pm_runtime_put_autosuspend(dev); 834 836 835 837 if (err) ··· 851 855 struct msa311_priv *msa311 = iio_priv(indio_dev); 852 856 struct device *dev = msa311->dev; 853 857 854 - pm_runtime_mark_last_busy(dev); 855 858 pm_runtime_put_autosuspend(dev); 856 859 857 860 return 0; ··· 985 990 msa311->chip_name = devm_kasprintf(dev, GFP_KERNEL, 986 991 "msa311-%02x", partid); 987 992 if (!msa311->chip_name) 988 - return dev_err_probe(dev, -ENOMEM, "can't alloc chip name\n"); 993 + return -ENOMEM; 989 994 990 995 return 0; 991 996 } ··· 1064 1069 1065 1070 trig = devm_iio_trigger_alloc(dev, "%s-new-data", msa311->chip_name); 1066 1071 if (!trig) 1067 - return dev_err_probe(dev, -ENOMEM, 1068 - "can't allocate newdata trigger\n"); 1072 + return -ENOMEM; 1069 1073 1070 1074 msa311->new_data_trig = trig; 1071 1075 msa311->new_data_trig->ops = &msa311_new_data_trig_ops; ··· 1147 1153 1148 1154 indio_dev = devm_iio_device_alloc(dev, sizeof(*msa311)); 1149 1155 if (!indio_dev) 1150 - return dev_err_probe(dev, -ENOMEM, 1151 - "IIO device allocation failed\n"); 1156 + return -ENOMEM; 1152 1157 1153 1158 msa311 = iio_priv(indio_dev); 1154 1159 msa311->dev = dev; ··· 1188 1195 */ 1189 1196 err = devm_add_action_or_reset(dev, msa311_powerdown, msa311); 1190 1197 if (err) 1191 - return dev_err_probe(dev, err, "can't add powerdown action\n"); 1198 + return err; 1192 1199 1193 1200 err = pm_runtime_set_active(dev); 1194 1201 if (err) ··· 1224 1231 if (err) 1225 1232 return err; 1226 1233 1227 - pm_runtime_mark_last_busy(dev); 1228 1234 pm_runtime_put_autosuspend(dev); 1229 1235 1230 1236 err = devm_iio_device_register(dev, indio_dev);
+1 -3
drivers/iio/accel/stk8312.c
··· 504 504 struct stk8312_data *data; 505 505 506 506 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 507 - if (!indio_dev) { 508 - dev_err(&client->dev, "iio allocation failed!\n"); 507 + if (!indio_dev) 509 508 return -ENOMEM; 510 - } 511 509 512 510 data = iio_priv(indio_dev); 513 511 data->client = client;
+1 -3
drivers/iio/accel/stk8ba50.c
··· 385 385 struct stk8ba50_data *data; 386 386 387 387 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 388 - if (!indio_dev) { 389 - dev_err(&client->dev, "iio allocation failed!\n"); 388 + if (!indio_dev) 390 389 return -ENOMEM; 391 - } 392 390 393 391 data = iio_priv(indio_dev); 394 392 data->client = client;
+393
drivers/iio/adc/88pm886-gpadc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright 2025, Duje Mihanović <duje@dujemihanovic.xyz> 4 + */ 5 + 6 + #include <linux/bits.h> 7 + #include <linux/bug.h> 8 + #include <linux/delay.h> 9 + #include <linux/device.h> 10 + #include <linux/err.h> 11 + #include <linux/i2c.h> 12 + #include <linux/math.h> 13 + #include <linux/mod_devicetable.h> 14 + #include <linux/module.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/pm_runtime.h> 17 + #include <linux/regmap.h> 18 + #include <linux/types.h> 19 + #include <linux/units.h> 20 + 21 + #include <asm/byteorder.h> 22 + 23 + #include <linux/iio/iio.h> 24 + #include <linux/iio/types.h> 25 + 26 + #include <linux/mfd/88pm886.h> 27 + 28 + struct pm886_gpadc { 29 + struct regmap *map; 30 + }; 31 + 32 + enum pm886_gpadc_channel { 33 + VSC_CHAN, 34 + VCHG_PWR_CHAN, 35 + VCF_OUT_CHAN, 36 + VBAT_CHAN, 37 + VBAT_SLP_CHAN, 38 + VBUS_CHAN, 39 + 40 + GPADC0_CHAN, 41 + GPADC1_CHAN, 42 + GPADC2_CHAN, 43 + GPADC3_CHAN, 44 + 45 + GND_DET1_CHAN, 46 + GND_DET2_CHAN, 47 + MIC_DET_CHAN, 48 + 49 + TINT_CHAN, 50 + }; 51 + 52 + static const int pm886_gpadc_regs[] = { 53 + [VSC_CHAN] = PM886_REG_GPADC_VSC, 54 + [VCHG_PWR_CHAN] = PM886_REG_GPADC_VCHG_PWR, 55 + [VCF_OUT_CHAN] = PM886_REG_GPADC_VCF_OUT, 56 + [VBAT_CHAN] = PM886_REG_GPADC_VBAT, 57 + [VBAT_SLP_CHAN] = PM886_REG_GPADC_VBAT_SLP, 58 + [VBUS_CHAN] = PM886_REG_GPADC_VBUS, 59 + 60 + [GPADC0_CHAN] = PM886_REG_GPADC_GPADC0, 61 + [GPADC1_CHAN] = PM886_REG_GPADC_GPADC1, 62 + [GPADC2_CHAN] = PM886_REG_GPADC_GPADC2, 63 + [GPADC3_CHAN] = PM886_REG_GPADC_GPADC3, 64 + 65 + [GND_DET1_CHAN] = PM886_REG_GPADC_GND_DET1, 66 + [GND_DET2_CHAN] = PM886_REG_GPADC_GND_DET2, 67 + [MIC_DET_CHAN] = PM886_REG_GPADC_MIC_DET, 68 + 69 + [TINT_CHAN] = PM886_REG_GPADC_TINT, 70 + }; 71 + 72 + #define ADC_CHANNEL_VOLTAGE(index, lsb, name) \ 73 + { \ 74 + .type = IIO_VOLTAGE, \ 75 + .indexed = 1, \ 76 + .channel = index, \ 77 + .address = lsb, \ 78 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 79 + BIT(IIO_CHAN_INFO_SCALE), \ 80 + .datasheet_name = name, \ 81 + } 82 + 83 + #define ADC_CHANNEL_RESISTANCE(index, lsb, name) \ 84 + { \ 85 + .type = IIO_RESISTANCE, \ 86 + .indexed = 1, \ 87 + .channel = index, \ 88 + .address = lsb, \ 89 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ 90 + .datasheet_name = name, \ 91 + } 92 + 93 + #define ADC_CHANNEL_TEMPERATURE(index, lsb, name) \ 94 + { \ 95 + .type = IIO_TEMP, \ 96 + .indexed = 1, \ 97 + .channel = index, \ 98 + .address = lsb, \ 99 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 100 + BIT(IIO_CHAN_INFO_SCALE) | \ 101 + BIT(IIO_CHAN_INFO_OFFSET), \ 102 + .datasheet_name = name, \ 103 + } 104 + 105 + static const struct iio_chan_spec pm886_gpadc_channels[] = { 106 + ADC_CHANNEL_VOLTAGE(VSC_CHAN, 1367, "vsc"), 107 + ADC_CHANNEL_VOLTAGE(VCHG_PWR_CHAN, 1709, "vchg_pwr"), 108 + ADC_CHANNEL_VOLTAGE(VCF_OUT_CHAN, 1367, "vcf_out"), 109 + ADC_CHANNEL_VOLTAGE(VBAT_CHAN, 1367, "vbat"), 110 + ADC_CHANNEL_VOLTAGE(VBAT_SLP_CHAN, 1367, "vbat_slp"), 111 + ADC_CHANNEL_VOLTAGE(VBUS_CHAN, 1709, "vbus"), 112 + 113 + ADC_CHANNEL_RESISTANCE(GPADC0_CHAN, 342, "gpadc0"), 114 + ADC_CHANNEL_RESISTANCE(GPADC1_CHAN, 342, "gpadc1"), 115 + ADC_CHANNEL_RESISTANCE(GPADC2_CHAN, 342, "gpadc2"), 116 + ADC_CHANNEL_RESISTANCE(GPADC3_CHAN, 342, "gpadc3"), 117 + 118 + ADC_CHANNEL_VOLTAGE(GND_DET1_CHAN, 342, "gnddet1"), 119 + ADC_CHANNEL_VOLTAGE(GND_DET2_CHAN, 342, "gnddet2"), 120 + ADC_CHANNEL_VOLTAGE(MIC_DET_CHAN, 1367, "mic_det"), 121 + 122 + ADC_CHANNEL_TEMPERATURE(TINT_CHAN, 104, "tint"), 123 + }; 124 + 125 + static const struct regmap_config pm886_gpadc_regmap_config = { 126 + .reg_bits = 8, 127 + .val_bits = 8, 128 + .max_register = PM886_GPADC_MAX_REGISTER, 129 + }; 130 + 131 + static int gpadc_get_raw(struct iio_dev *iio, enum pm886_gpadc_channel chan) 132 + { 133 + struct pm886_gpadc *gpadc = iio_priv(iio); 134 + __be16 buf; 135 + int ret; 136 + 137 + ret = regmap_bulk_read(gpadc->map, pm886_gpadc_regs[chan], &buf, sizeof(buf)); 138 + if (ret) 139 + return ret; 140 + 141 + return be16_to_cpu(buf) >> 4; 142 + } 143 + 144 + static int 145 + gpadc_set_bias(struct pm886_gpadc *gpadc, enum pm886_gpadc_channel chan, bool on) 146 + { 147 + unsigned int gpadc_num = chan - GPADC0_CHAN; 148 + unsigned int bits = BIT(gpadc_num + 4) | BIT(gpadc_num); 149 + 150 + return regmap_assign_bits(gpadc->map, PM886_REG_GPADC_CONFIG(0x14), bits, on); 151 + } 152 + 153 + static int 154 + gpadc_find_bias_current(struct iio_dev *iio, struct iio_chan_spec const *chan, 155 + unsigned int *raw_uV, unsigned int *raw_uA) 156 + { 157 + struct pm886_gpadc *gpadc = iio_priv(iio); 158 + unsigned int gpadc_num = chan->channel - GPADC0_CHAN; 159 + unsigned int reg = PM886_REG_GPADC_CONFIG(0xb + gpadc_num); 160 + unsigned long lsb = chan->address; 161 + int ret; 162 + 163 + for (unsigned int i = 0; i < PM886_GPADC_BIAS_LEVELS; i++) { 164 + ret = regmap_update_bits(gpadc->map, reg, GENMASK(3, 0), i); 165 + if (ret) 166 + return ret; 167 + 168 + /* Wait for the new bias level to apply. */ 169 + fsleep(5 * USEC_PER_MSEC); 170 + 171 + *raw_uA = PM886_GPADC_INDEX_TO_BIAS_uA(i); 172 + *raw_uV = gpadc_get_raw(iio, chan->channel) * lsb; 173 + 174 + /* 175 + * Vendor kernel errors out above 1.25 V, but testing shows 176 + * that the resistance of the battery detection channel (GPADC2 177 + * on coreprimevelte) reaches about 1.4 MΩ when the battery is 178 + * removed, which can't be measured with such a low upper 179 + * limit. Therefore, to be able to detect the battery without 180 + * ugly externs as used in the vendor fuel gauge driver, 181 + * increase this limit a bit. 182 + */ 183 + if (WARN_ON(*raw_uV > 1500 * (MICRO / MILLI))) 184 + return -EIO; 185 + 186 + /* 187 + * Vendor kernel errors out under 300 mV, but for the same 188 + * reason as above (except the channel hovers around 3.5 kΩ 189 + * with battery present) reduce this limit. 190 + */ 191 + if (*raw_uV < 200 * (MICRO / MILLI)) { 192 + dev_dbg(&iio->dev, "bad bias for chan %d: %d uA @ %d uV\n", 193 + chan->channel, *raw_uA, *raw_uV); 194 + continue; 195 + } 196 + 197 + dev_dbg(&iio->dev, "good bias for chan %d: %d uA @ %d uV\n", 198 + chan->channel, *raw_uA, *raw_uV); 199 + return 0; 200 + } 201 + 202 + dev_err(&iio->dev, "failed to find good bias for chan %d\n", chan->channel); 203 + return -EINVAL; 204 + } 205 + 206 + static int 207 + gpadc_get_resistance_ohm(struct iio_dev *iio, struct iio_chan_spec const *chan) 208 + { 209 + struct pm886_gpadc *gpadc = iio_priv(iio); 210 + unsigned int raw_uV, raw_uA; 211 + int ret; 212 + 213 + ret = gpadc_set_bias(gpadc, chan->channel, true); 214 + if (ret) 215 + goto out; 216 + 217 + ret = gpadc_find_bias_current(iio, chan, &raw_uV, &raw_uA); 218 + if (ret) 219 + goto out; 220 + 221 + ret = DIV_ROUND_CLOSEST(raw_uV, raw_uA); 222 + out: 223 + gpadc_set_bias(gpadc, chan->channel, false); 224 + return ret; 225 + } 226 + 227 + static int 228 + __pm886_gpadc_read_raw(struct iio_dev *iio, struct iio_chan_spec const *chan, 229 + int *val, int *val2, long mask) 230 + { 231 + unsigned long lsb = chan->address; 232 + 233 + switch (mask) { 234 + case IIO_CHAN_INFO_RAW: 235 + *val = gpadc_get_raw(iio, chan->channel); 236 + if (*val < 0) 237 + return *val; 238 + 239 + return IIO_VAL_INT; 240 + case IIO_CHAN_INFO_SCALE: 241 + *val = lsb; 242 + 243 + if (chan->type == IIO_VOLTAGE) { 244 + *val2 = MILLI; 245 + return IIO_VAL_FRACTIONAL; 246 + } else { 247 + return IIO_VAL_INT; 248 + } 249 + case IIO_CHAN_INFO_OFFSET: 250 + /* Raw value is 104 millikelvin/LSB, convert it to 104 millicelsius/LSB */ 251 + *val = ABSOLUTE_ZERO_MILLICELSIUS; 252 + *val2 = lsb; 253 + return IIO_VAL_FRACTIONAL; 254 + case IIO_CHAN_INFO_PROCESSED: 255 + *val = gpadc_get_resistance_ohm(iio, chan); 256 + if (*val < 0) 257 + return *val; 258 + 259 + return IIO_VAL_INT; 260 + default: 261 + return -EINVAL; 262 + } 263 + } 264 + 265 + static int pm886_gpadc_read_raw(struct iio_dev *iio, struct iio_chan_spec const *chan, 266 + int *val, int *val2, long mask) 267 + { 268 + struct device *dev = iio->dev.parent; 269 + int ret; 270 + 271 + ret = pm_runtime_resume_and_get(dev); 272 + if (ret) 273 + return ret; 274 + 275 + ret = __pm886_gpadc_read_raw(iio, chan, val, val2, mask); 276 + 277 + pm_runtime_put_autosuspend(dev); 278 + return ret; 279 + } 280 + 281 + static int pm886_gpadc_hw_enable(struct regmap *map) 282 + { 283 + const u8 config[] = { 284 + PM886_GPADC_CONFIG1_EN_ALL, 285 + PM886_GPADC_CONFIG2_EN_ALL, 286 + PM886_GPADC_GND_DET2_EN, 287 + }; 288 + int ret; 289 + 290 + /* Enable the ADC block. */ 291 + ret = regmap_set_bits(map, PM886_REG_GPADC_CONFIG(0x6), BIT(0)); 292 + if (ret) 293 + return ret; 294 + 295 + /* Enable all channels. */ 296 + return regmap_bulk_write(map, PM886_REG_GPADC_CONFIG(0x1), config, ARRAY_SIZE(config)); 297 + } 298 + 299 + static int pm886_gpadc_hw_disable(struct regmap *map) 300 + { 301 + return regmap_clear_bits(map, PM886_REG_GPADC_CONFIG(0x6), BIT(0)); 302 + } 303 + 304 + static const struct iio_info pm886_gpadc_iio_info = { 305 + .read_raw = pm886_gpadc_read_raw, 306 + }; 307 + 308 + static int pm886_gpadc_probe(struct platform_device *pdev) 309 + { 310 + struct device *dev = &pdev->dev; 311 + struct pm886_chip *chip = dev_get_drvdata(dev->parent); 312 + struct i2c_client *client = chip->client; 313 + struct pm886_gpadc *gpadc; 314 + struct i2c_client *page; 315 + struct iio_dev *iio; 316 + int ret; 317 + 318 + iio = devm_iio_device_alloc(dev, sizeof(*gpadc)); 319 + if (!iio) 320 + return -ENOMEM; 321 + 322 + gpadc = iio_priv(iio); 323 + dev_set_drvdata(dev, iio); 324 + 325 + page = devm_i2c_new_dummy_device(dev, client->adapter, 326 + client->addr + PM886_PAGE_OFFSET_GPADC); 327 + if (IS_ERR(page)) 328 + return dev_err_probe(dev, PTR_ERR(page), "Failed to initialize GPADC page\n"); 329 + 330 + gpadc->map = devm_regmap_init_i2c(page, &pm886_gpadc_regmap_config); 331 + if (IS_ERR(gpadc->map)) 332 + return dev_err_probe(dev, PTR_ERR(gpadc->map), 333 + "Failed to initialize GPADC regmap\n"); 334 + 335 + iio->name = "88pm886-gpadc"; 336 + iio->modes = INDIO_DIRECT_MODE; 337 + iio->info = &pm886_gpadc_iio_info; 338 + iio->channels = pm886_gpadc_channels; 339 + iio->num_channels = ARRAY_SIZE(pm886_gpadc_channels); 340 + device_set_node(&iio->dev, dev_fwnode(dev->parent)); 341 + 342 + ret = devm_pm_runtime_enable(dev); 343 + if (ret) 344 + return dev_err_probe(dev, ret, "Failed to enable runtime PM\n"); 345 + 346 + pm_runtime_set_autosuspend_delay(dev, 50); 347 + pm_runtime_use_autosuspend(dev); 348 + ret = devm_iio_device_register(dev, iio); 349 + if (ret) 350 + return dev_err_probe(dev, ret, "Failed to register ADC\n"); 351 + 352 + return 0; 353 + } 354 + 355 + static int pm886_gpadc_runtime_resume(struct device *dev) 356 + { 357 + struct iio_dev *iio = dev_get_drvdata(dev); 358 + struct pm886_gpadc *gpadc = iio_priv(iio); 359 + 360 + return pm886_gpadc_hw_enable(gpadc->map); 361 + } 362 + 363 + static int pm886_gpadc_runtime_suspend(struct device *dev) 364 + { 365 + struct iio_dev *iio = dev_get_drvdata(dev); 366 + struct pm886_gpadc *gpadc = iio_priv(iio); 367 + 368 + return pm886_gpadc_hw_disable(gpadc->map); 369 + } 370 + 371 + static DEFINE_RUNTIME_DEV_PM_OPS(pm886_gpadc_pm_ops, 372 + pm886_gpadc_runtime_suspend, 373 + pm886_gpadc_runtime_resume, NULL); 374 + 375 + static const struct platform_device_id pm886_gpadc_id[] = { 376 + { "88pm886-gpadc" }, 377 + { } 378 + }; 379 + MODULE_DEVICE_TABLE(platform, pm886_gpadc_id); 380 + 381 + static struct platform_driver pm886_gpadc_driver = { 382 + .driver = { 383 + .name = "88pm886-gpadc", 384 + .pm = pm_ptr(&pm886_gpadc_pm_ops), 385 + }, 386 + .probe = pm886_gpadc_probe, 387 + .id_table = pm886_gpadc_id, 388 + }; 389 + module_platform_driver(pm886_gpadc_driver); 390 + 391 + MODULE_AUTHOR("Duje Mihanović <duje@dujemihanovic.xyz>"); 392 + MODULE_DESCRIPTION("Marvell 88PM886 GPADC driver"); 393 + MODULE_LICENSE("GPL");
+54
drivers/iio/adc/Kconfig
··· 9 9 config IIO_ADC_HELPER 10 10 tristate 11 11 12 + config 88PM886_GPADC 13 + tristate "Marvell 88PM886 GPADC driver" 14 + depends on MFD_88PM886_PMIC 15 + default MFD_88PM886_PMIC 16 + help 17 + Say Y here to enable support for the GPADC (General Purpose ADC) 18 + found on the Marvell 88PM886 PMIC. The GPADC measures various 19 + internal voltages and temperatures, including (but not limited to) 20 + system, battery and USB Vbus. 21 + 22 + To compile this driver as a module, choose M here: the module will be 23 + called 88pm886-gpadc. 24 + 12 25 config AB8500_GPADC 13 26 bool "ST-Ericsson AB8500 GPADC driver" 14 27 depends on AB8500_CORE && REGULATOR_AB8500 ··· 402 389 depends on SPI 403 390 select CRC8 404 391 select IIO_BUFFER 392 + select IIO_BACKEND 405 393 help 406 394 Say yes here to build support for Analog Devices AD777X family 407 395 (AD7770, AD7771, AD7779) analog to digital converter (ADC). ··· 520 506 521 507 To compile this driver as a module, choose M here: the module will be 522 508 called ad9467. 509 + 510 + config ADE9000 511 + tristate "Analog Devices ADE9000 Multiphase Energy, and Power Quality Monitoring IC Driver" 512 + depends on SPI 513 + select REGMAP_SPI 514 + select IIO_BUFFER 515 + select IIO_KFIFO_BUF 516 + help 517 + Say yes here to build support for the Analog Devices ADE9000, 518 + a highly accurate, multiphase energy and power quality monitoring 519 + integrated circuit. 520 + 521 + The device features high-precision analog-to-digital converters 522 + and digital signal processing to compute RMS values, power factor, 523 + frequency, and harmonic analysis. It supports SPI communication 524 + and provides buffered data output through the IIO framework. 525 + 526 + To compile this driver as a module, choose M here: the module will 527 + be called ade9000. 523 528 524 529 config ADI_AXI_ADC 525 530 tristate "Analog Devices Generic AXI ADC IP core driver" ··· 798 765 799 766 This driver can also be built as a module. If so, the module will be 800 767 called ingenic_adc. 768 + 769 + config INTEL_DC_TI_ADC 770 + tristate "Intel Bay Trail / Cherry Trail Dollar Cove TI ADC driver" 771 + depends on INTEL_SOC_PMIC_CHTDC_TI 772 + help 773 + Say yes here to have support for the Dollar Cove TI PMIC ADC device. 774 + Depending on platform configuration, this general purpose ADC can be 775 + used for sensors such as battery voltage and thermal resistors. 776 + 777 + To compile this driver as a module, choose M here: the module will be 778 + called intel_dc_ti_adc. 801 779 802 780 config INTEL_MRFLD_ADC 803 781 tristate "Intel Merrifield Basin Cove ADC driver" ··· 1341 1297 1342 1298 This driver can also be built as a module. If so, the module 1343 1299 will be called rn5t618-adc. 1300 + 1301 + config ROHM_BD79112 1302 + tristate "Rohm BD79112 ADC driver" 1303 + depends on SPI && GPIOLIB 1304 + select REGMAP_SPI 1305 + select IIO_ADC_HELPER 1306 + help 1307 + Say yes here to build support for the ROHM BD79112 ADC. The 1308 + ROHM BD79112 is a 12-bit, 32-channel, SAR ADC. Analog inputs 1309 + can also be used for GPIO. 1344 1310 1345 1311 config ROHM_BD79124 1346 1312 tristate "Rohm BD79124 ADC driver"
+4
drivers/iio/adc/Makefile
··· 6 6 obj-$(CONFIG_IIO_ADC_HELPER) += industrialio-adc.o 7 7 8 8 # When adding new entries keep the list in alphabetical order 9 + obj-$(CONFIG_88PM886_GPADC) += 88pm886-gpadc.o 9 10 obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o 10 11 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o 11 12 obj-$(CONFIG_AD4000) += ad4000.o ··· 47 46 obj-$(CONFIG_AD7949) += ad7949.o 48 47 obj-$(CONFIG_AD799X) += ad799x.o 49 48 obj-$(CONFIG_AD9467) += ad9467.o 49 + obj-$(CONFIG_ADE9000) += ade9000.o 50 50 obj-$(CONFIG_ADI_AXI_ADC) += adi-axi-adc.o 51 51 obj-$(CONFIG_ASPEED_ADC) += aspeed_adc.o 52 52 obj-$(CONFIG_AT91_ADC) += at91_adc.o ··· 72 70 obj-$(CONFIG_IMX93_ADC) += imx93_adc.o 73 71 obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o 74 72 obj-$(CONFIG_INGENIC_ADC) += ingenic-adc.o 73 + obj-$(CONFIG_INTEL_DC_TI_ADC) += intel_dc_ti_adc.o 75 74 obj-$(CONFIG_INTEL_MRFLD_ADC) += intel_mrfld_adc.o 76 75 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o 77 76 obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o ··· 119 116 obj-$(CONFIG_RCAR_GYRO_ADC) += rcar-gyroadc.o 120 117 obj-$(CONFIG_RICHTEK_RTQ6056) += rtq6056.o 121 118 obj-$(CONFIG_RN5T618_ADC) += rn5t618-adc.o 119 + obj-$(CONFIG_ROHM_BD79112) += rohm-bd79112.o 122 120 obj-$(CONFIG_ROHM_BD79124) += rohm-bd79124.o 123 121 obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o 124 122 obj-$(CONFIG_RZG2L_ADC) += rzg2l_adc.o
-1
drivers/iio/adc/ab8500-gpadc.c
··· 607 607 } 608 608 609 609 /* This eventually drops the regulator */ 610 - pm_runtime_mark_last_busy(gpadc->dev); 611 610 pm_runtime_put_autosuspend(gpadc->dev); 612 611 613 612 return (high_data << 8) | low_data;
+1 -2
drivers/iio/adc/ad4130.c
··· 2035 2035 2036 2036 ret = devm_add_action_or_reset(dev, ad4130_disable_regulators, st); 2037 2037 if (ret) 2038 - return dev_err_probe(dev, ret, 2039 - "Failed to add regulators disable action\n"); 2038 + return ret; 2040 2039 2041 2040 ret = ad4130_soft_reset(st); 2042 2041 if (ret)
+459 -104
drivers/iio/adc/ad7124.c
··· 3 3 * AD7124 SPI ADC driver 4 4 * 5 5 * Copyright 2018 Analog Devices Inc. 6 + * Copyright 2025 BayLibre, SAS 6 7 */ 7 8 #include <linux/bitfield.h> 8 9 #include <linux/bitops.h> 10 + #include <linux/cleanup.h> 9 11 #include <linux/clk.h> 12 + #include <linux/clk-provider.h> 10 13 #include <linux/delay.h> 11 14 #include <linux/device.h> 12 15 #include <linux/err.h> 13 16 #include <linux/interrupt.h> 14 17 #include <linux/kernel.h> 15 18 #include <linux/kfifo.h> 19 + #include <linux/minmax.h> 16 20 #include <linux/module.h> 17 21 #include <linux/mod_devicetable.h> 18 22 #include <linux/property.h> 19 23 #include <linux/regulator/consumer.h> 20 24 #include <linux/spi/spi.h> 25 + #include <linux/sprintf.h> 26 + #include <linux/units.h> 21 27 22 28 #include <linux/iio/iio.h> 23 29 #include <linux/iio/adc/ad_sigma_delta.h> ··· 50 44 #define AD7124_STATUS_POR_FLAG BIT(4) 51 45 52 46 /* AD7124_ADC_CONTROL */ 47 + #define AD7124_ADC_CONTROL_CLK_SEL GENMASK(1, 0) 48 + #define AD7124_ADC_CONTROL_CLK_SEL_INT 0 49 + #define AD7124_ADC_CONTROL_CLK_SEL_INT_OUT 1 50 + #define AD7124_ADC_CONTROL_CLK_SEL_EXT 2 51 + #define AD7124_ADC_CONTROL_CLK_SEL_EXT_DIV4 3 53 52 #define AD7124_ADC_CONTROL_MODE GENMASK(5, 2) 54 53 #define AD7124_ADC_CONTROL_MODE_CONTINUOUS 0 55 54 #define AD7124_ADC_CONTROL_MODE_SINGLE 1 ··· 95 84 #define AD7124_CONFIG_PGA GENMASK(2, 0) 96 85 97 86 /* AD7124_FILTER_X */ 98 - #define AD7124_FILTER_FS GENMASK(10, 0) 99 87 #define AD7124_FILTER_FILTER GENMASK(23, 21) 100 88 #define AD7124_FILTER_FILTER_SINC4 0 101 89 #define AD7124_FILTER_FILTER_SINC3 2 90 + #define AD7124_FILTER_FILTER_SINC4_SINC1 4 91 + #define AD7124_FILTER_FILTER_SINC3_SINC1 5 92 + #define AD7124_FILTER_FILTER_SINC3_PF 7 93 + #define AD7124_FILTER_REJ60 BIT(20) 94 + #define AD7124_FILTER_POST_FILTER GENMASK(19, 17) 95 + #define AD7124_FILTER_POST_FILTER_47dB 2 96 + #define AD7124_FILTER_POST_FILTER_62dB 3 97 + #define AD7124_FILTER_POST_FILTER_86dB 5 98 + #define AD7124_FILTER_POST_FILTER_92dB 6 99 + #define AD7124_FILTER_SINGLE_CYCLE BIT(16) 100 + #define AD7124_FILTER_FS GENMASK(10, 0) 102 101 103 102 #define AD7124_MAX_CONFIGS 8 104 103 #define AD7124_MAX_CHANNELS 16 104 + 105 + #define AD7124_INT_CLK_HZ 614400 105 106 106 107 /* AD7124 input sources */ 107 108 ··· 143 120 }; 144 121 145 122 static const int ad7124_master_clk_freq_hz[3] = { 146 - [AD7124_LOW_POWER] = 76800, 147 - [AD7124_MID_POWER] = 153600, 148 - [AD7124_FULL_POWER] = 614400, 123 + [AD7124_LOW_POWER] = AD7124_INT_CLK_HZ / 8, 124 + [AD7124_MID_POWER] = AD7124_INT_CLK_HZ / 4, 125 + [AD7124_FULL_POWER] = AD7124_INT_CLK_HZ, 149 126 }; 150 127 151 128 static const char * const ad7124_ref_names[] = { ··· 161 138 unsigned int num_inputs; 162 139 }; 163 140 141 + enum ad7124_filter_type { 142 + AD7124_FILTER_TYPE_SINC3, 143 + AD7124_FILTER_TYPE_SINC3_PF1, 144 + AD7124_FILTER_TYPE_SINC3_PF2, 145 + AD7124_FILTER_TYPE_SINC3_PF3, 146 + AD7124_FILTER_TYPE_SINC3_PF4, 147 + AD7124_FILTER_TYPE_SINC3_REJ60, 148 + AD7124_FILTER_TYPE_SINC3_SINC1, 149 + AD7124_FILTER_TYPE_SINC4, 150 + AD7124_FILTER_TYPE_SINC4_REJ60, 151 + AD7124_FILTER_TYPE_SINC4_SINC1, 152 + }; 153 + 164 154 struct ad7124_channel_config { 165 155 bool live; 166 156 unsigned int cfg_slot; 157 + unsigned int requested_odr; 158 + unsigned int requested_odr_micro; 167 159 /* 168 160 * Following fields are used to compare for equality. If you 169 161 * make adaptations in it, you most likely also have to adapt ··· 191 153 bool buf_negative; 192 154 unsigned int vref_mv; 193 155 unsigned int pga_bits; 194 - unsigned int odr; 195 156 unsigned int odr_sel_bits; 196 - unsigned int filter_type; 157 + enum ad7124_filter_type filter_type; 197 158 unsigned int calibration_offset; 198 159 unsigned int calibration_gain; 199 160 ); ··· 211 174 struct ad_sigma_delta sd; 212 175 struct ad7124_channel *channels; 213 176 struct regulator *vref[4]; 214 - struct clk *mclk; 177 + u32 clk_hz; 215 178 unsigned int adc_control; 216 179 unsigned int num_channels; 217 180 struct mutex cfgs_lock; /* lock for configs access */ ··· 287 250 return ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, st->adc_control); 288 251 } 289 252 290 - static void ad7124_set_channel_odr(struct ad7124_state *st, unsigned int channel, unsigned int odr) 253 + static u32 ad7124_get_fclk_hz(struct ad7124_state *st) 291 254 { 292 - unsigned int fclk, odr_sel_bits; 255 + enum ad7124_power_mode power_mode; 256 + u32 fclk_hz; 293 257 294 - fclk = clk_get_rate(st->mclk); 258 + power_mode = FIELD_GET(AD7124_ADC_CONTROL_POWER_MODE, st->adc_control); 259 + fclk_hz = st->clk_hz; 260 + 261 + switch (power_mode) { 262 + case AD7124_LOW_POWER: 263 + fclk_hz /= 8; 264 + break; 265 + case AD7124_MID_POWER: 266 + fclk_hz /= 4; 267 + break; 268 + default: 269 + break; 270 + } 271 + 272 + return fclk_hz; 273 + } 274 + 275 + static u32 ad7124_get_fs_factor(struct ad7124_state *st, unsigned int channel) 276 + { 277 + enum ad7124_power_mode power_mode = 278 + FIELD_GET(AD7124_ADC_CONTROL_POWER_MODE, st->adc_control); 279 + u32 avg = power_mode == AD7124_LOW_POWER ? 8 : 16; 280 + 295 281 /* 296 - * FS[10:0] = fCLK / (fADC x 32) where: 282 + * These are the "zero-latency" factors from the data sheet. For the 283 + * sinc1 filters, these aren't documented, but derived by taking the 284 + * single-channel formula from the sinc1 section of the data sheet and 285 + * multiplying that by the sinc3/4 factor from the corresponding zero- 286 + * latency sections. 287 + */ 288 + switch (st->channels[channel].cfg.filter_type) { 289 + case AD7124_FILTER_TYPE_SINC4: 290 + case AD7124_FILTER_TYPE_SINC4_REJ60: 291 + return 4 * 32; 292 + case AD7124_FILTER_TYPE_SINC4_SINC1: 293 + return 4 * avg * 32; 294 + case AD7124_FILTER_TYPE_SINC3_SINC1: 295 + return 3 * avg * 32; 296 + default: 297 + return 3 * 32; 298 + } 299 + } 300 + 301 + static u32 ad7124_get_fadc_divisor(struct ad7124_state *st, unsigned int channel) 302 + { 303 + u32 factor = ad7124_get_fs_factor(st, channel); 304 + 305 + /* 306 + * The output data rate (f_ADC) is f_CLK / divisor. We are returning 307 + * the divisor. 308 + */ 309 + return st->channels[channel].cfg.odr_sel_bits * factor; 310 + } 311 + 312 + static void ad7124_set_channel_odr(struct ad7124_state *st, unsigned int channel) 313 + { 314 + struct ad7124_channel_config *cfg = &st->channels[channel].cfg; 315 + unsigned int fclk, factor, divisor, odr_sel_bits; 316 + 317 + fclk = ad7124_get_fclk_hz(st); 318 + factor = ad7124_get_fs_factor(st, channel); 319 + 320 + /* 321 + * FS[10:0] = fCLK / (fADC x 32 * N) where: 297 322 * fADC is the output data rate 298 323 * fCLK is the master clock frequency 324 + * N is number of conversions per sample (depends on filter type) 299 325 * FS[10:0] are the bits in the filter register 300 326 * FS[10:0] can have a value from 1 to 2047 301 327 */ 302 - odr_sel_bits = DIV_ROUND_CLOSEST(fclk, odr * 32); 303 - if (odr_sel_bits < 1) 304 - odr_sel_bits = 1; 305 - else if (odr_sel_bits > 2047) 306 - odr_sel_bits = 2047; 328 + divisor = cfg->requested_odr * factor + 329 + cfg->requested_odr_micro * factor / MICRO; 330 + odr_sel_bits = clamp(DIV_ROUND_CLOSEST(fclk, divisor), 1, 2047); 307 331 308 332 if (odr_sel_bits != st->channels[channel].cfg.odr_sel_bits) 309 333 st->channels[channel].cfg.live = false; 310 334 311 - /* fADC = fCLK / (FS[10:0] x 32) */ 312 - st->channels[channel].cfg.odr = DIV_ROUND_CLOSEST(fclk, odr_sel_bits * 32); 313 335 st->channels[channel].cfg.odr_sel_bits = odr_sel_bits; 314 336 } 315 337 316 - static int ad7124_get_3db_filter_freq(struct ad7124_state *st, 317 - unsigned int channel) 338 + static int ad7124_get_3db_filter_factor(struct ad7124_state *st, 339 + unsigned int channel) 318 340 { 319 - unsigned int fadc; 341 + struct ad7124_channel_config *cfg = &st->channels[channel].cfg; 320 342 321 - fadc = st->channels[channel].cfg.odr; 322 - 323 - switch (st->channels[channel].cfg.filter_type) { 324 - case AD7124_FILTER_FILTER_SINC3: 325 - return DIV_ROUND_CLOSEST(fadc * 272, 1000); 326 - case AD7124_FILTER_FILTER_SINC4: 327 - return DIV_ROUND_CLOSEST(fadc * 230, 1000); 343 + /* 344 + * 3dB point is the f_CLK rate times some factor. This functions returns 345 + * the factor times 1000. 346 + */ 347 + switch (cfg->filter_type) { 348 + case AD7124_FILTER_TYPE_SINC3: 349 + case AD7124_FILTER_TYPE_SINC3_REJ60: 350 + case AD7124_FILTER_TYPE_SINC3_SINC1: 351 + return 272; 352 + case AD7124_FILTER_TYPE_SINC4: 353 + case AD7124_FILTER_TYPE_SINC4_REJ60: 354 + case AD7124_FILTER_TYPE_SINC4_SINC1: 355 + return 230; 356 + case AD7124_FILTER_TYPE_SINC3_PF1: 357 + return 633; 358 + case AD7124_FILTER_TYPE_SINC3_PF2: 359 + return 605; 360 + case AD7124_FILTER_TYPE_SINC3_PF3: 361 + return 669; 362 + case AD7124_FILTER_TYPE_SINC3_PF4: 363 + return 759; 328 364 default: 329 365 return -EINVAL; 330 366 } ··· 421 311 bool buf_negative; 422 312 unsigned int vref_mv; 423 313 unsigned int pga_bits; 424 - unsigned int odr; 425 314 unsigned int odr_sel_bits; 426 - unsigned int filter_type; 315 + enum ad7124_filter_type filter_type; 427 316 unsigned int calibration_offset; 428 317 unsigned int calibration_gain; 429 318 })); ··· 437 328 cfg->buf_negative == cfg_aux->buf_negative && 438 329 cfg->vref_mv == cfg_aux->vref_mv && 439 330 cfg->pga_bits == cfg_aux->pga_bits && 440 - cfg->odr == cfg_aux->odr && 441 331 cfg->odr_sel_bits == cfg_aux->odr_sel_bits && 442 332 cfg->filter_type == cfg_aux->filter_type && 443 333 cfg->calibration_offset == cfg_aux->calibration_offset && ··· 489 381 static int ad7124_write_config(struct ad7124_state *st, struct ad7124_channel_config *cfg, 490 382 unsigned int cfg_slot) 491 383 { 492 - unsigned int tmp; 493 - unsigned int val; 384 + unsigned int val, filter; 385 + unsigned int rej60 = 0; 386 + unsigned int post = 0; 494 387 int ret; 495 388 496 389 cfg->cfg_slot = cfg_slot; ··· 514 405 if (ret < 0) 515 406 return ret; 516 407 517 - tmp = FIELD_PREP(AD7124_FILTER_FILTER, cfg->filter_type) | 518 - FIELD_PREP(AD7124_FILTER_FS, cfg->odr_sel_bits); 519 - return ad7124_spi_write_mask(st, AD7124_FILTER(cfg->cfg_slot), 520 - AD7124_FILTER_FILTER | AD7124_FILTER_FS, 521 - tmp, 3); 408 + switch (cfg->filter_type) { 409 + case AD7124_FILTER_TYPE_SINC3: 410 + filter = AD7124_FILTER_FILTER_SINC3; 411 + break; 412 + case AD7124_FILTER_TYPE_SINC3_PF1: 413 + filter = AD7124_FILTER_FILTER_SINC3_PF; 414 + post = AD7124_FILTER_POST_FILTER_47dB; 415 + break; 416 + case AD7124_FILTER_TYPE_SINC3_PF2: 417 + filter = AD7124_FILTER_FILTER_SINC3_PF; 418 + post = AD7124_FILTER_POST_FILTER_62dB; 419 + break; 420 + case AD7124_FILTER_TYPE_SINC3_PF3: 421 + filter = AD7124_FILTER_FILTER_SINC3_PF; 422 + post = AD7124_FILTER_POST_FILTER_86dB; 423 + break; 424 + case AD7124_FILTER_TYPE_SINC3_PF4: 425 + filter = AD7124_FILTER_FILTER_SINC3_PF; 426 + post = AD7124_FILTER_POST_FILTER_92dB; 427 + break; 428 + case AD7124_FILTER_TYPE_SINC3_REJ60: 429 + filter = AD7124_FILTER_FILTER_SINC3; 430 + rej60 = 1; 431 + break; 432 + case AD7124_FILTER_TYPE_SINC3_SINC1: 433 + filter = AD7124_FILTER_FILTER_SINC3_SINC1; 434 + break; 435 + case AD7124_FILTER_TYPE_SINC4: 436 + filter = AD7124_FILTER_FILTER_SINC4; 437 + break; 438 + case AD7124_FILTER_TYPE_SINC4_REJ60: 439 + filter = AD7124_FILTER_FILTER_SINC4; 440 + rej60 = 1; 441 + break; 442 + case AD7124_FILTER_TYPE_SINC4_SINC1: 443 + filter = AD7124_FILTER_FILTER_SINC4_SINC1; 444 + break; 445 + default: 446 + return -EINVAL; 447 + } 448 + 449 + /* 450 + * NB: AD7124_FILTER_SINGLE_CYCLE is always set so that we get the same 451 + * sampling frequency even when only one channel is enabled in a 452 + * buffered read. If it was not set, the N in ad7124_set_channel_odr() 453 + * would be 1 and we would get a faster sampling frequency than what 454 + * was requested. 455 + */ 456 + return ad_sd_write_reg(&st->sd, AD7124_FILTER(cfg->cfg_slot), 3, 457 + FIELD_PREP(AD7124_FILTER_FILTER, filter) | 458 + FIELD_PREP(AD7124_FILTER_REJ60, rej60) | 459 + FIELD_PREP(AD7124_FILTER_POST_FILTER, post) | 460 + AD7124_FILTER_SINGLE_CYCLE | 461 + FIELD_PREP(AD7124_FILTER_FS, cfg->odr_sel_bits)); 522 462 } 523 463 524 464 static struct ad7124_channel_config *ad7124_pop_config(struct ad7124_state *st) ··· 734 576 .num_resetclks = 64, 735 577 }; 736 578 579 + static const int ad7124_voltage_scales[][2] = { 580 + { 0, 1164 }, 581 + { 0, 2328 }, 582 + { 0, 4656 }, 583 + { 0, 9313 }, 584 + { 0, 18626 }, 585 + { 0, 37252 }, 586 + { 0, 74505 }, 587 + { 0, 149011 }, 588 + { 0, 298023 }, 589 + }; 590 + 591 + static int ad7124_read_avail(struct iio_dev *indio_dev, 592 + struct iio_chan_spec const *chan, 593 + const int **vals, int *type, int *length, long info) 594 + { 595 + switch (info) { 596 + case IIO_CHAN_INFO_SCALE: 597 + *vals = (const int *)ad7124_voltage_scales; 598 + *type = IIO_VAL_INT_PLUS_NANO; 599 + *length = ARRAY_SIZE(ad7124_voltage_scales) * 2; 600 + return IIO_AVAIL_LIST; 601 + default: 602 + return -EINVAL; 603 + } 604 + } 605 + 737 606 static int ad7124_read_raw(struct iio_dev *indio_dev, 738 607 struct iio_chan_spec const *chan, 739 608 int *val, int *val2, long info) ··· 829 644 return -EINVAL; 830 645 } 831 646 832 - case IIO_CHAN_INFO_SAMP_FREQ: 833 - mutex_lock(&st->cfgs_lock); 834 - *val = st->channels[chan->address].cfg.odr; 835 - mutex_unlock(&st->cfgs_lock); 647 + case IIO_CHAN_INFO_SAMP_FREQ: { 648 + struct ad7124_channel_config *cfg = &st->channels[chan->address].cfg; 836 649 837 - return IIO_VAL_INT; 838 - case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 839 - mutex_lock(&st->cfgs_lock); 840 - *val = ad7124_get_3db_filter_freq(st, chan->scan_index); 841 - mutex_unlock(&st->cfgs_lock); 650 + guard(mutex)(&st->cfgs_lock); 842 651 843 - return IIO_VAL_INT; 652 + switch (cfg->filter_type) { 653 + case AD7124_FILTER_TYPE_SINC3: 654 + case AD7124_FILTER_TYPE_SINC3_REJ60: 655 + case AD7124_FILTER_TYPE_SINC3_SINC1: 656 + case AD7124_FILTER_TYPE_SINC4: 657 + case AD7124_FILTER_TYPE_SINC4_REJ60: 658 + case AD7124_FILTER_TYPE_SINC4_SINC1: 659 + *val = ad7124_get_fclk_hz(st); 660 + *val2 = ad7124_get_fadc_divisor(st, chan->address); 661 + return IIO_VAL_FRACTIONAL; 662 + /* 663 + * Post filters force the chip to a fixed rate. These are the 664 + * single-channel rates from the data sheet divided by 3 for 665 + * the multi-channel case (data sheet doesn't explicitly state 666 + * this but confirmed through testing). 667 + */ 668 + case AD7124_FILTER_TYPE_SINC3_PF1: 669 + *val = 300; 670 + *val2 = 33; 671 + return IIO_VAL_FRACTIONAL; 672 + case AD7124_FILTER_TYPE_SINC3_PF2: 673 + *val = 25; 674 + *val2 = 3; 675 + return IIO_VAL_FRACTIONAL; 676 + case AD7124_FILTER_TYPE_SINC3_PF3: 677 + *val = 20; 678 + *val2 = 3; 679 + return IIO_VAL_FRACTIONAL; 680 + case AD7124_FILTER_TYPE_SINC3_PF4: 681 + *val = 50; 682 + *val2 = 9; 683 + return IIO_VAL_FRACTIONAL; 684 + default: 685 + return -EINVAL; 686 + } 687 + } 688 + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: { 689 + guard(mutex)(&st->cfgs_lock); 690 + 691 + ret = ad7124_get_3db_filter_factor(st, chan->address); 692 + if (ret < 0) 693 + return ret; 694 + 695 + /* 3dB point is the f_CLK rate times a fractional value */ 696 + *val = ret * ad7124_get_fclk_hz(st); 697 + *val2 = MILLI * ad7124_get_fadc_divisor(st, chan->address); 698 + return IIO_VAL_FRACTIONAL; 699 + } 844 700 default: 845 701 return -EINVAL; 846 702 } ··· 892 666 int val, int val2, long info) 893 667 { 894 668 struct ad7124_state *st = iio_priv(indio_dev); 669 + struct ad7124_channel_config *cfg = &st->channels[chan->address].cfg; 895 670 unsigned int res, gain, full_scale, vref; 896 - int ret = 0; 897 671 898 - mutex_lock(&st->cfgs_lock); 672 + guard(mutex)(&st->cfgs_lock); 899 673 900 674 switch (info) { 901 675 case IIO_CHAN_INFO_SAMP_FREQ: 902 - if (val2 != 0 || val == 0) { 903 - ret = -EINVAL; 904 - break; 905 - } 676 + if (val2 < 0 || val < 0 || (val2 == 0 && val == 0)) 677 + return -EINVAL; 906 678 907 - ad7124_set_channel_odr(st, chan->address, val); 908 - break; 679 + cfg->requested_odr = val; 680 + cfg->requested_odr_micro = val2; 681 + ad7124_set_channel_odr(st, chan->address); 682 + 683 + return 0; 909 684 case IIO_CHAN_INFO_SCALE: 910 - if (val != 0) { 911 - ret = -EINVAL; 912 - break; 913 - } 685 + if (val != 0) 686 + return -EINVAL; 914 687 915 688 if (st->channels[chan->address].cfg.bipolar) 916 689 full_scale = 1 << (chan->scan_type.realbits - 1); ··· 925 700 st->channels[chan->address].cfg.live = false; 926 701 927 702 st->channels[chan->address].cfg.pga_bits = res; 928 - break; 703 + return 0; 929 704 default: 930 - ret = -EINVAL; 705 + return -EINVAL; 931 706 } 932 - 933 - mutex_unlock(&st->cfgs_lock); 934 - return ret; 935 707 } 936 708 937 709 static int ad7124_reg_access(struct iio_dev *indio_dev, ··· 952 730 return ret; 953 731 } 954 732 955 - static IIO_CONST_ATTR(in_voltage_scale_available, 956 - "0.000001164 0.000002328 0.000004656 0.000009313 0.000018626 0.000037252 0.000074505 0.000149011 0.000298023"); 957 - 958 - static struct attribute *ad7124_attributes[] = { 959 - &iio_const_attr_in_voltage_scale_available.dev_attr.attr, 960 - NULL, 961 - }; 962 - 963 - static const struct attribute_group ad7124_attrs_group = { 964 - .attrs = ad7124_attributes, 965 - }; 966 - 967 733 static int ad7124_update_scan_mode(struct iio_dev *indio_dev, 968 734 const unsigned long *scan_mask) 969 735 { ··· 960 750 int ret; 961 751 int i; 962 752 963 - mutex_lock(&st->cfgs_lock); 753 + guard(mutex)(&st->cfgs_lock); 754 + 964 755 for (i = 0; i < st->num_channels; i++) { 965 756 bit_set = test_bit(i, scan_mask); 966 757 if (bit_set) ··· 969 758 else 970 759 ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i), AD7124_CHANNEL_ENABLE, 971 760 0, 2); 972 - if (ret < 0) { 973 - mutex_unlock(&st->cfgs_lock); 974 - 761 + if (ret < 0) 975 762 return ret; 976 - } 977 763 } 978 - 979 - mutex_unlock(&st->cfgs_lock); 980 764 981 765 return 0; 982 766 } 983 767 984 768 static const struct iio_info ad7124_info = { 769 + .read_avail = ad7124_read_avail, 985 770 .read_raw = ad7124_read_raw, 986 771 .write_raw = ad7124_write_raw, 987 772 .debugfs_reg_access = &ad7124_reg_access, 988 773 .validate_trigger = ad_sd_validate_trigger, 989 774 .update_scan_mode = ad7124_update_scan_mode, 990 - .attrs = &ad7124_attrs_group, 991 775 }; 992 776 993 777 /* Only called during probe, so dev_err_probe() can be used */ ··· 1150 944 .get = ad7124_get_syscalib_mode 1151 945 }; 1152 946 947 + static const char * const ad7124_filter_types[] = { 948 + [AD7124_FILTER_TYPE_SINC3] = "sinc3", 949 + [AD7124_FILTER_TYPE_SINC3_PF1] = "sinc3+pf1", 950 + [AD7124_FILTER_TYPE_SINC3_PF2] = "sinc3+pf2", 951 + [AD7124_FILTER_TYPE_SINC3_PF3] = "sinc3+pf3", 952 + [AD7124_FILTER_TYPE_SINC3_PF4] = "sinc3+pf4", 953 + [AD7124_FILTER_TYPE_SINC3_REJ60] = "sinc3+rej60", 954 + [AD7124_FILTER_TYPE_SINC3_SINC1] = "sinc3+sinc1", 955 + [AD7124_FILTER_TYPE_SINC4] = "sinc4", 956 + [AD7124_FILTER_TYPE_SINC4_REJ60] = "sinc4+rej60", 957 + [AD7124_FILTER_TYPE_SINC4_SINC1] = "sinc4+sinc1", 958 + }; 959 + 960 + static int ad7124_set_filter_type_attr(struct iio_dev *dev, 961 + const struct iio_chan_spec *chan, 962 + unsigned int value) 963 + { 964 + struct ad7124_state *st = iio_priv(dev); 965 + struct ad7124_channel_config *cfg = &st->channels[chan->address].cfg; 966 + 967 + guard(mutex)(&st->cfgs_lock); 968 + 969 + cfg->live = false; 970 + cfg->filter_type = value; 971 + ad7124_set_channel_odr(st, chan->address); 972 + 973 + return 0; 974 + } 975 + 976 + static int ad7124_get_filter_type_attr(struct iio_dev *dev, 977 + const struct iio_chan_spec *chan) 978 + { 979 + struct ad7124_state *st = iio_priv(dev); 980 + 981 + guard(mutex)(&st->cfgs_lock); 982 + 983 + return st->channels[chan->address].cfg.filter_type; 984 + } 985 + 986 + static const struct iio_enum ad7124_filter_type_enum = { 987 + .items = ad7124_filter_types, 988 + .num_items = ARRAY_SIZE(ad7124_filter_types), 989 + .set = ad7124_set_filter_type_attr, 990 + .get = ad7124_get_filter_type_attr, 991 + }; 992 + 1153 993 static const struct iio_chan_spec_ext_info ad7124_calibsys_ext_info[] = { 1154 994 { 1155 995 .name = "sys_calibration", ··· 1206 954 &ad7124_syscalib_mode_enum), 1207 955 IIO_ENUM_AVAILABLE("sys_calibration_mode", IIO_SHARED_BY_TYPE, 1208 956 &ad7124_syscalib_mode_enum), 957 + IIO_ENUM("filter_type", IIO_SEPARATE, &ad7124_filter_type_enum), 958 + IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_TYPE, 959 + &ad7124_filter_type_enum), 1209 960 { } 1210 961 }; 1211 962 ··· 1221 966 BIT(IIO_CHAN_INFO_OFFSET) | 1222 967 BIT(IIO_CHAN_INFO_SAMP_FREQ) | 1223 968 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), 969 + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE), 1224 970 .scan_type = { 1225 971 .sign = 'u', 1226 972 .realbits = 24, ··· 1367 1111 static int ad7124_setup(struct ad7124_state *st) 1368 1112 { 1369 1113 struct device *dev = &st->sd.spi->dev; 1370 - unsigned int fclk, power_mode; 1114 + unsigned int power_mode, clk_sel; 1115 + struct clk *mclk; 1371 1116 int i, ret; 1372 1117 1373 - fclk = clk_get_rate(st->mclk); 1374 - if (!fclk) 1375 - return dev_err_probe(dev, -EINVAL, "Failed to get mclk rate\n"); 1118 + /* 1119 + * Always use full power mode for max performance. If needed, the driver 1120 + * could be adapted to use a dynamic power mode based on the requested 1121 + * output data rate. 1122 + */ 1123 + power_mode = AD7124_ADC_CONTROL_POWER_MODE_FULL; 1376 1124 1377 - /* The power mode changes the master clock frequency */ 1378 - power_mode = ad7124_find_closest_match(ad7124_master_clk_freq_hz, 1379 - ARRAY_SIZE(ad7124_master_clk_freq_hz), 1380 - fclk); 1381 - if (fclk != ad7124_master_clk_freq_hz[power_mode]) { 1382 - ret = clk_set_rate(st->mclk, fclk); 1125 + /* 1126 + * This "mclk" business is needed for backwards compatibility with old 1127 + * devicetrees that specified a fake clock named "mclk" to select the 1128 + * power mode. 1129 + */ 1130 + mclk = devm_clk_get_optional_enabled(dev, "mclk"); 1131 + if (IS_ERR(mclk)) 1132 + return dev_err_probe(dev, PTR_ERR(mclk), "Failed to get mclk\n"); 1133 + 1134 + if (mclk) { 1135 + unsigned long mclk_hz; 1136 + 1137 + mclk_hz = clk_get_rate(mclk); 1138 + if (!mclk_hz) 1139 + return dev_err_probe(dev, -EINVAL, 1140 + "Failed to get mclk rate\n"); 1141 + 1142 + /* 1143 + * This logic is a bit backwards, which is why it is only here 1144 + * for backwards compatibility. The driver should be able to set 1145 + * the power mode as it sees fit and the f_clk/mclk rate should 1146 + * be dynamic accordingly. But here, we are selecting a fixed 1147 + * power mode based on the given "mclk" rate. 1148 + */ 1149 + power_mode = ad7124_find_closest_match(ad7124_master_clk_freq_hz, 1150 + ARRAY_SIZE(ad7124_master_clk_freq_hz), mclk_hz); 1151 + 1152 + if (mclk_hz != ad7124_master_clk_freq_hz[power_mode]) { 1153 + ret = clk_set_rate(mclk, mclk_hz); 1154 + if (ret) 1155 + return dev_err_probe(dev, ret, 1156 + "Failed to set mclk rate\n"); 1157 + } 1158 + 1159 + clk_sel = AD7124_ADC_CONTROL_CLK_SEL_INT; 1160 + st->clk_hz = AD7124_INT_CLK_HZ; 1161 + } else if (!device_property_present(dev, "clocks") && 1162 + device_property_present(dev, "#clock-cells")) { 1163 + #ifdef CONFIG_COMMON_CLK 1164 + struct clk_hw *clk_hw; 1165 + 1166 + const char *name __free(kfree) = kasprintf(GFP_KERNEL, "%pfwP-clk", 1167 + dev_fwnode(dev)); 1168 + if (!name) 1169 + return -ENOMEM; 1170 + 1171 + clk_hw = devm_clk_hw_register_fixed_rate(dev, name, NULL, 0, 1172 + AD7124_INT_CLK_HZ); 1173 + if (IS_ERR(clk_hw)) 1174 + return dev_err_probe(dev, PTR_ERR(clk_hw), 1175 + "Failed to register clock provider\n"); 1176 + 1177 + ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, 1178 + clk_hw); 1383 1179 if (ret) 1384 - return dev_err_probe(dev, ret, "Failed to set mclk rate\n"); 1180 + return dev_err_probe(dev, ret, 1181 + "Failed to add clock provider\n"); 1182 + #endif 1183 + 1184 + /* 1185 + * Treat the clock as always on. This way we don't have to deal 1186 + * with someone trying to enable/disable the clock while we are 1187 + * reading samples. 1188 + */ 1189 + clk_sel = AD7124_ADC_CONTROL_CLK_SEL_INT_OUT; 1190 + st->clk_hz = AD7124_INT_CLK_HZ; 1191 + } else { 1192 + struct clk *clk; 1193 + 1194 + clk = devm_clk_get_optional_enabled(dev, NULL); 1195 + if (IS_ERR(clk)) 1196 + return dev_err_probe(dev, PTR_ERR(clk), 1197 + "Failed to get external clock\n"); 1198 + 1199 + if (clk) { 1200 + unsigned long clk_hz; 1201 + 1202 + clk_hz = clk_get_rate(clk); 1203 + if (!clk_hz) 1204 + return dev_err_probe(dev, -EINVAL, 1205 + "Failed to get external clock rate\n"); 1206 + 1207 + /* 1208 + * The external clock may be 4x the nominal clock rate, 1209 + * in which case the ADC needs to be configured to 1210 + * divide it by 4. Using MEGA is a bit arbitrary, but 1211 + * the expected clock rates are either 614.4 kHz or 1212 + * 2.4576 MHz, so this should work. 1213 + */ 1214 + if (clk_hz > (1 * HZ_PER_MHZ)) { 1215 + clk_sel = AD7124_ADC_CONTROL_CLK_SEL_EXT_DIV4; 1216 + st->clk_hz = clk_hz / 4; 1217 + } else { 1218 + clk_sel = AD7124_ADC_CONTROL_CLK_SEL_EXT; 1219 + st->clk_hz = clk_hz; 1220 + } 1221 + } else { 1222 + clk_sel = AD7124_ADC_CONTROL_CLK_SEL_INT; 1223 + st->clk_hz = AD7124_INT_CLK_HZ; 1224 + } 1385 1225 } 1386 1226 1387 - /* Set the power mode */ 1227 + st->adc_control &= ~AD7124_ADC_CONTROL_CLK_SEL; 1228 + st->adc_control |= FIELD_PREP(AD7124_ADC_CONTROL_CLK_SEL, clk_sel); 1229 + 1388 1230 st->adc_control &= ~AD7124_ADC_CONTROL_POWER_MODE; 1389 1231 st->adc_control |= FIELD_PREP(AD7124_ADC_CONTROL_POWER_MODE, power_mode); 1390 1232 ··· 1492 1138 mutex_init(&st->cfgs_lock); 1493 1139 INIT_KFIFO(st->live_cfgs_fifo); 1494 1140 for (i = 0; i < st->num_channels; i++) { 1141 + struct ad7124_channel_config *cfg = &st->channels[i].cfg; 1495 1142 1496 - ret = ad7124_init_config_vref(st, &st->channels[i].cfg); 1143 + ret = ad7124_init_config_vref(st, cfg); 1497 1144 if (ret < 0) 1498 1145 return ret; 1146 + 1147 + /* Default filter type on the ADC after reset. */ 1148 + cfg->filter_type = AD7124_FILTER_TYPE_SINC4; 1499 1149 1500 1150 /* 1501 1151 * 9.38 SPS is the minimum output data rate supported 1502 1152 * regardless of the selected power mode. Round it up to 10 and 1503 1153 * set all channels to this default value. 1504 1154 */ 1505 - ad7124_set_channel_odr(st, i, 10); 1155 + cfg->requested_odr = 10; 1156 + ad7124_set_channel_odr(st, i); 1506 1157 } 1507 1158 1508 1159 ad7124_disable_all(&st->sd); ··· 1659 1300 ret = devm_add_action_or_reset(&spi->dev, ad7124_reg_disable, 1660 1301 st->vref[i]); 1661 1302 if (ret) 1662 - return dev_err_probe(dev, ret, "Failed to register disable handler for regulator #%d\n", i); 1303 + return ret; 1663 1304 } 1664 - 1665 - st->mclk = devm_clk_get_enabled(&spi->dev, "mclk"); 1666 - if (IS_ERR(st->mclk)) 1667 - return dev_err_probe(dev, PTR_ERR(st->mclk), "Failed to get mclk\n"); 1668 1305 1669 1306 ret = ad7124_soft_reset(st); 1670 1307 if (ret < 0)
+205 -16
drivers/iio/adc/ad7173.c
··· 8 8 * AD7175-8/AD7176-2/AD7177-2 9 9 * 10 10 * Copyright (C) 2015, 2024 Analog Devices, Inc. 11 + * Copyright (C) 2025 BayLibre, SAS 11 12 */ 12 13 13 14 #include <linux/array_size.h> ··· 150 149 (pin2) < st->info->num_voltage_in && \ 151 150 (pin2) >= st->info->num_voltage_in_div) 152 151 153 - #define AD7173_FILTER_ODR0_MASK GENMASK(5, 0) 152 + #define AD7173_FILTER_SINC3_MAP BIT(15) 153 + #define AD7173_FILTER_SINC3_MAP_DIV GENMASK(14, 0) 154 + #define AD7173_FILTER_ENHFILTEN BIT(11) 155 + #define AD7173_FILTER_ENHFILT_MASK GENMASK(10, 8) 156 + #define AD7173_FILTER_ORDER BIT(6) 157 + #define AD7173_FILTER_ODR_MASK GENMASK(5, 0) 154 158 #define AD7173_MAX_CONFIGS 8 155 159 #define AD4111_OW_DET_THRSH_MV 300 156 160 ··· 196 190 u8 num_gpios; 197 191 }; 198 192 193 + enum ad7173_filter_type { 194 + AD7173_FILTER_SINC3, 195 + AD7173_FILTER_SINC5_SINC1, 196 + AD7173_FILTER_SINC5_SINC1_PF1, 197 + AD7173_FILTER_SINC5_SINC1_PF2, 198 + AD7173_FILTER_SINC5_SINC1_PF3, 199 + AD7173_FILTER_SINC5_SINC1_PF4, 200 + }; 201 + 199 202 struct ad7173_channel_config { 200 203 /* Openwire detection threshold */ 201 204 unsigned int openwire_thrsh_raw; ··· 220 205 struct_group(config_props, 221 206 bool bipolar; 222 207 bool input_buf; 223 - u8 odr; 208 + u16 sinc3_odr_div; 209 + u8 sinc5_odr_index; 224 210 u8 ref_sel; 211 + enum ad7173_filter_type filter_type; 225 212 ); 226 213 }; 227 214 ··· 282 265 49960, 20000, 16666, 10000, /* 16-19 */ 283 266 5000, /* 20 */ 284 267 }; 268 + 269 + /** 270 + * ad7173_sinc3_odr_div_from_odr() - Convert ODR to divider value 271 + * @odr_millihz: ODR (sampling_frequency) in milliHz 272 + * Returns: Divider value for SINC3 filter to pass. 273 + */ 274 + static u16 ad7173_sinc3_odr_div_from_odr(u32 odr_millihz) 275 + { 276 + /* 277 + * Divider is f_MOD (1 MHz) / 32 / ODR. ODR freq is in milliHz, so 278 + * we need to convert f_MOD to the same units. When SING_CYC=1 or 279 + * multiple channels are enabled (currently always the case), there 280 + * is an additional factor of 3. 281 + */ 282 + u32 div = DIV_ROUND_CLOSEST(MEGA * MILLI, odr_millihz * 32 * 3); 283 + /* Avoid divide by 0 and limit to register field size. */ 284 + return clamp(div, 1U, AD7173_FILTER_SINC3_MAP_DIV); 285 + } 285 286 286 287 static unsigned int ad4111_current_channel_config[] = { 287 288 /* Ain sel: pos neg */ ··· 404 369 .get = ad7173_get_syscalib_mode 405 370 }; 406 371 407 - static const struct iio_chan_spec_ext_info ad7173_calibsys_ext_info[] = { 372 + static const char * const ad7173_filter_types_str[] = { 373 + [AD7173_FILTER_SINC3] = "sinc3", 374 + [AD7173_FILTER_SINC5_SINC1] = "sinc5+sinc1", 375 + [AD7173_FILTER_SINC5_SINC1_PF1] = "sinc5+sinc1+pf1", 376 + [AD7173_FILTER_SINC5_SINC1_PF2] = "sinc5+sinc1+pf2", 377 + [AD7173_FILTER_SINC5_SINC1_PF3] = "sinc5+sinc1+pf3", 378 + [AD7173_FILTER_SINC5_SINC1_PF4] = "sinc5+sinc1+pf4", 379 + }; 380 + 381 + static int ad7173_set_filter_type(struct iio_dev *indio_dev, 382 + const struct iio_chan_spec *chan, 383 + unsigned int val) 384 + { 385 + struct ad7173_state *st = iio_priv(indio_dev); 386 + 387 + if (!iio_device_claim_direct(indio_dev)) 388 + return -EBUSY; 389 + 390 + st->channels[chan->address].cfg.filter_type = val; 391 + st->channels[chan->address].cfg.live = false; 392 + 393 + iio_device_release_direct(indio_dev); 394 + 395 + return 0; 396 + } 397 + 398 + static int ad7173_get_filter_type(struct iio_dev *indio_dev, 399 + const struct iio_chan_spec *chan) 400 + { 401 + struct ad7173_state *st = iio_priv(indio_dev); 402 + 403 + return st->channels[chan->address].cfg.filter_type; 404 + } 405 + 406 + static const struct iio_enum ad7173_filter_type_enum = { 407 + .items = ad7173_filter_types_str, 408 + .num_items = ARRAY_SIZE(ad7173_filter_types_str), 409 + .set = ad7173_set_filter_type, 410 + .get = ad7173_get_filter_type, 411 + }; 412 + 413 + static const struct iio_chan_spec_ext_info ad7173_chan_spec_ext_info[] = { 408 414 { 409 415 .name = "sys_calibration", 410 416 .write = ad7173_write_syscalib, ··· 455 379 &ad7173_syscalib_mode_enum), 456 380 IIO_ENUM_AVAILABLE("sys_calibration_mode", IIO_SHARED_BY_TYPE, 457 381 &ad7173_syscalib_mode_enum), 382 + IIO_ENUM("filter_type", IIO_SEPARATE, &ad7173_filter_type_enum), 383 + IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_TYPE, 384 + &ad7173_filter_type_enum), 385 + { } 386 + }; 387 + 388 + static const struct iio_chan_spec_ext_info ad7173_temp_chan_spec_ext_info[] = { 389 + IIO_ENUM("filter_type", IIO_SEPARATE, &ad7173_filter_type_enum), 390 + IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_TYPE, 391 + &ad7173_filter_type_enum), 458 392 { } 459 393 }; 460 394 ··· 668 582 sizeof(struct { 669 583 bool bipolar; 670 584 bool input_buf; 671 - u8 odr; 585 + u16 sinc3_odr_div; 586 + u8 sinc5_odr_index; 672 587 u8 ref_sel; 588 + enum ad7173_filter_type filter_type; 673 589 })); 674 590 675 591 return cfg1->bipolar == cfg2->bipolar && 676 592 cfg1->input_buf == cfg2->input_buf && 677 - cfg1->odr == cfg2->odr && 678 - cfg1->ref_sel == cfg2->ref_sel; 593 + cfg1->sinc3_odr_div == cfg2->sinc3_odr_div && 594 + cfg1->sinc5_odr_index == cfg2->sinc5_odr_index && 595 + cfg1->ref_sel == cfg2->ref_sel && 596 + cfg1->filter_type == cfg2->filter_type; 679 597 } 680 598 681 599 static struct ad7173_channel_config * ··· 720 630 { 721 631 unsigned int config; 722 632 int free_cfg_slot, ret; 633 + u8 post_filter_enable, post_filter_select; 723 634 724 635 free_cfg_slot = ida_alloc_range(&st->cfg_slots_status, 0, 725 636 st->info->num_configs - 1, GFP_KERNEL); ··· 740 649 if (ret) 741 650 return ret; 742 651 652 + /* 653 + * When SINC3_MAP flag is enabled, the rest of the register has a 654 + * different meaning. We are using this option to allow the most 655 + * possible sampling frequencies with SINC3 filter. 656 + */ 657 + if (cfg->filter_type == AD7173_FILTER_SINC3) 658 + return ad_sd_write_reg(&st->sd, AD7173_REG_FILTER(free_cfg_slot), 2, 659 + FIELD_PREP(AD7173_FILTER_SINC3_MAP, 1) | 660 + FIELD_PREP(AD7173_FILTER_SINC3_MAP_DIV, 661 + cfg->sinc3_odr_div)); 662 + 663 + switch (cfg->filter_type) { 664 + case AD7173_FILTER_SINC5_SINC1_PF1: 665 + post_filter_enable = 1; 666 + post_filter_select = 2; 667 + break; 668 + case AD7173_FILTER_SINC5_SINC1_PF2: 669 + post_filter_enable = 1; 670 + post_filter_select = 3; 671 + break; 672 + case AD7173_FILTER_SINC5_SINC1_PF3: 673 + post_filter_enable = 1; 674 + post_filter_select = 5; 675 + break; 676 + case AD7173_FILTER_SINC5_SINC1_PF4: 677 + post_filter_enable = 1; 678 + post_filter_select = 6; 679 + break; 680 + default: 681 + post_filter_enable = 0; 682 + post_filter_select = 0; 683 + break; 684 + } 685 + 743 686 return ad_sd_write_reg(&st->sd, AD7173_REG_FILTER(free_cfg_slot), 2, 744 - AD7173_FILTER_ODR0_MASK & cfg->odr); 687 + FIELD_PREP(AD7173_FILTER_SINC3_MAP, 0) | 688 + FIELD_PREP(AD7173_FILTER_ENHFILT_MASK, 689 + post_filter_enable) | 690 + FIELD_PREP(AD7173_FILTER_ENHFILTEN, 691 + post_filter_select) | 692 + FIELD_PREP(AD7173_FILTER_ORDER, 0) | 693 + FIELD_PREP(AD7173_FILTER_ODR_MASK, 694 + cfg->sinc5_odr_index)); 745 695 } 746 696 747 697 static int ad7173_config_channel(struct ad7173_state *st, int addr) ··· 893 761 .set_mode = ad7173_set_mode, 894 762 .has_registers = true, 895 763 .has_named_irqs = true, 764 + .supports_spi_offload = true, 896 765 .addr_shift = 0, 897 766 .read_mask = BIT(6), 898 767 .status_ch_mask = GENMASK(3, 0), ··· 910 777 .set_mode = ad7173_set_mode, 911 778 .has_registers = true, 912 779 .has_named_irqs = true, 780 + .supports_spi_offload = true, 913 781 .addr_shift = 0, 914 782 .read_mask = BIT(6), 915 783 .status_ch_mask = GENMASK(3, 0), ··· 927 793 .set_mode = ad7173_set_mode, 928 794 .has_registers = true, 929 795 .has_named_irqs = true, 796 + .supports_spi_offload = true, 930 797 .addr_shift = 0, 931 798 .read_mask = BIT(6), 932 799 .status_ch_mask = GENMASK(3, 0), ··· 1315 1180 return -EINVAL; 1316 1181 } 1317 1182 case IIO_CHAN_INFO_SAMP_FREQ: 1318 - reg = st->channels[chan->address].cfg.odr; 1183 + if (st->channels[chan->address].cfg.filter_type == AD7173_FILTER_SINC3) { 1184 + /* Inverse operation of ad7173_sinc3_odr_div_from_odr() */ 1185 + *val = MEGA; 1186 + *val2 = 3 * 32 * st->channels[chan->address].cfg.sinc3_odr_div; 1187 + return IIO_VAL_FRACTIONAL; 1188 + } 1189 + 1190 + reg = st->channels[chan->address].cfg.sinc5_odr_index; 1319 1191 1320 1192 *val = st->info->sinc5_data_rates[reg] / MILLI; 1321 1193 *val2 = (st->info->sinc5_data_rates[reg] % MILLI) * (MICRO / MILLI); ··· 1360 1218 * 1361 1219 * This will cause the reading of CH1 to be actually done once every 1362 1220 * 200.16ms, an effective rate of 4.99sps. 1221 + * 1222 + * Both the sinc5 and sinc3 rates are set here so that if the filter 1223 + * type is changed, the requested rate will still be set (aside from 1224 + * rounding differences). 1363 1225 */ 1364 1226 case IIO_CHAN_INFO_SAMP_FREQ: 1365 1227 freq = val * MILLI + val2 / MILLI; ··· 1372 1226 break; 1373 1227 1374 1228 cfg = &st->channels[chan->address].cfg; 1375 - cfg->odr = i; 1229 + cfg->sinc5_odr_index = i; 1230 + cfg->sinc3_odr_div = ad7173_sinc3_odr_div_from_odr(freq); 1376 1231 cfg->live = false; 1377 1232 break; 1378 1233 ··· 1390 1243 const unsigned long *scan_mask) 1391 1244 { 1392 1245 struct ad7173_state *st = iio_priv(indio_dev); 1246 + u16 sinc3_count = 0; 1247 + u16 sinc3_div = 0; 1393 1248 int i, j, k, ret; 1394 1249 1395 1250 for (i = 0; i < indio_dev->num_channels; i++) { 1396 - if (test_bit(i, scan_mask)) 1251 + const struct ad7173_channel_config *cfg = &st->channels[i].cfg; 1252 + 1253 + if (test_bit(i, scan_mask)) { 1254 + if (cfg->filter_type == AD7173_FILTER_SINC3) { 1255 + sinc3_count++; 1256 + 1257 + if (sinc3_div == 0) { 1258 + sinc3_div = cfg->sinc3_odr_div; 1259 + } else if (sinc3_div != cfg->sinc3_odr_div) { 1260 + dev_err(&st->sd.spi->dev, 1261 + "All enabled channels must have the same sampling_frequency for sinc3 filter_type\n"); 1262 + return -EINVAL; 1263 + } 1264 + } 1265 + 1397 1266 ret = ad7173_set_channel(&st->sd, i); 1398 - else 1267 + } else { 1399 1268 ret = ad_sd_write_reg(&st->sd, AD7173_REG_CH(i), 2, 0); 1269 + } 1400 1270 if (ret < 0) 1401 1271 return ret; 1272 + } 1273 + 1274 + if (sinc3_count && sinc3_count < bitmap_weight(scan_mask, indio_dev->num_channels)) { 1275 + dev_err(&st->sd.spi->dev, 1276 + "All enabled channels must have sinc3 filter_type\n"); 1277 + return -EINVAL; 1402 1278 } 1403 1279 1404 1280 /* ··· 1566 1396 .storagebits = 32, 1567 1397 .endianness = IIO_BE, 1568 1398 }, 1569 - .ext_info = ad7173_calibsys_ext_info, 1399 + .ext_info = ad7173_chan_spec_ext_info, 1570 1400 }; 1571 1401 1572 1402 static const struct iio_chan_spec ad7173_temp_iio_channel_template = { ··· 1582 1412 .storagebits = 32, 1583 1413 .endianness = IIO_BE, 1584 1414 }, 1415 + .ext_info = ad7173_temp_chan_spec_ext_info, 1585 1416 }; 1586 1417 1587 1418 static void ad7173_disable_regulators(void *data) ··· 1823 1652 chan_st_priv->cfg.bipolar = false; 1824 1653 chan_st_priv->cfg.input_buf = st->info->has_input_buf; 1825 1654 chan_st_priv->cfg.ref_sel = AD7173_SETUP_REF_SEL_INT_REF; 1826 - chan_st_priv->cfg.odr = st->info->odr_start_value; 1655 + chan_st_priv->cfg.sinc3_odr_div = ad7173_sinc3_odr_div_from_odr( 1656 + st->info->sinc5_data_rates[st->info->odr_start_value] 1657 + ); 1658 + chan_st_priv->cfg.sinc5_odr_index = st->info->odr_start_value; 1659 + chan_st_priv->cfg.filter_type = AD7173_FILTER_SINC5_SINC1; 1827 1660 chan_st_priv->cfg.openwire_comp_chan = -1; 1828 1661 st->adc_mode |= AD7173_ADC_MODE_REF_EN; 1829 1662 if (st->info->data_reg_only_16bit) 1830 1663 chan_arr[chan_index].scan_type = ad4113_scan_type; 1664 + 1665 + if (ad_sigma_delta_has_spi_offload(&st->sd)) { 1666 + chan_arr[chan_index].scan_type.storagebits = 32; 1667 + chan_arr[chan_index].scan_type.endianness = IIO_CPU; 1668 + } 1831 1669 1832 1670 chan_index++; 1833 1671 } ··· 1899 1719 chan->scan_index = chan_index; 1900 1720 chan->channel = ain[0]; 1901 1721 chan_st_priv->cfg.input_buf = st->info->has_input_buf; 1902 - chan_st_priv->cfg.odr = st->info->odr_start_value; 1722 + chan_st_priv->cfg.sinc3_odr_div = ad7173_sinc3_odr_div_from_odr( 1723 + st->info->sinc5_data_rates[st->info->odr_start_value] 1724 + ); 1725 + chan_st_priv->cfg.sinc5_odr_index = st->info->odr_start_value; 1726 + chan_st_priv->cfg.filter_type = AD7173_FILTER_SINC5_SINC1; 1903 1727 chan_st_priv->cfg.openwire_comp_chan = -1; 1904 1728 1905 1729 chan_st_priv->cfg.bipolar = fwnode_property_read_bool(child, "bipolar"); ··· 1931 1747 1932 1748 if (st->info->data_reg_only_16bit) 1933 1749 chan_arr[chan_index].scan_type = ad4113_scan_type; 1750 + 1751 + /* Assuming SPI offload is ad411x_ad717x HDL project. */ 1752 + if (ad_sigma_delta_has_spi_offload(&st->sd)) { 1753 + chan_arr[chan_index].scan_type.storagebits = 32; 1754 + chan_arr[chan_index].scan_type.endianness = IIO_CPU; 1755 + } 1934 1756 1935 1757 chan_index++; 1936 1758 } ··· 1970 1780 1971 1781 ret = devm_add_action_or_reset(dev, ad7173_disable_regulators, st); 1972 1782 if (ret) 1973 - return dev_err_probe(dev, ret, 1974 - "Failed to add regulators disable action\n"); 1783 + return ret; 1975 1784 1976 1785 ret = device_property_match_property_string(dev, "clock-names", 1977 1786 ad7173_clk_sel,
+233 -228
drivers/iio/adc/ad7476.c
··· 6 6 * Copyright 2010 Analog Devices Inc. 7 7 */ 8 8 9 + #include <linux/bitops.h> 9 10 #include <linux/device.h> 10 11 #include <linux/kernel.h> 11 12 #include <linux/slab.h> ··· 28 27 struct ad7476_state; 29 28 30 29 struct ad7476_chip_info { 31 - unsigned int int_vref_uv; 30 + unsigned int int_vref_mv; 32 31 struct iio_chan_spec channel[2]; 33 - /* channels used when convst gpio is defined */ 34 - struct iio_chan_spec convst_channel[2]; 35 32 void (*reset)(struct ad7476_state *); 33 + void (*conversion_pre_op)(struct ad7476_state *st); 34 + void (*conversion_post_op)(struct ad7476_state *st); 36 35 bool has_vref; 37 36 bool has_vdrive; 37 + bool convstart_required; 38 38 }; 39 39 40 40 struct ad7476_state { 41 41 struct spi_device *spi; 42 42 const struct ad7476_chip_info *chip_info; 43 - struct regulator *ref_reg; 44 43 struct gpio_desc *convst_gpio; 45 44 struct spi_transfer xfer; 46 45 struct spi_message msg; 46 + struct iio_chan_spec channel[2]; 47 + int scale_mv; 47 48 /* 48 49 * DMA (thus cache coherency maintenance) may require the 49 50 * transfer buffers to live in their own cache lines. ··· 55 52 unsigned char data[ALIGN(2, sizeof(s64)) + sizeof(s64)] __aligned(IIO_DMA_MINALIGN); 56 53 }; 57 54 58 - enum ad7476_supported_device_ids { 59 - ID_AD7091, 60 - ID_AD7091R, 61 - ID_AD7273, 62 - ID_AD7274, 63 - ID_AD7276, 64 - ID_AD7277, 65 - ID_AD7278, 66 - ID_AD7466, 67 - ID_AD7467, 68 - ID_AD7468, 69 - ID_AD7475, 70 - ID_AD7495, 71 - ID_AD7940, 72 - ID_ADC081S, 73 - ID_ADC101S, 74 - ID_ADC121S, 75 - ID_ADS7866, 76 - ID_ADS7867, 77 - ID_ADS7868, 78 - ID_LTC2314_14, 79 - }; 80 - 81 55 static void ad7091_convst(struct ad7476_state *st) 82 56 { 83 57 if (!st->convst_gpio) 84 58 return; 85 59 86 - gpiod_set_value(st->convst_gpio, 0); 60 + gpiod_set_value_cansleep(st->convst_gpio, 0); 87 61 udelay(1); /* CONVST pulse width: 10 ns min */ 88 - gpiod_set_value(st->convst_gpio, 1); 62 + gpiod_set_value_cansleep(st->convst_gpio, 1); 89 63 udelay(1); /* Conversion time: 650 ns max */ 64 + } 65 + 66 + static void bd79105_convst_disable(struct ad7476_state *st) 67 + { 68 + gpiod_set_value_cansleep(st->convst_gpio, 0); 69 + } 70 + 71 + static void bd79105_convst_enable(struct ad7476_state *st) 72 + { 73 + gpiod_set_value_cansleep(st->convst_gpio, 1); 74 + /* Worst case, 2790 ns required for conversion */ 75 + ndelay(2790); 90 76 } 91 77 92 78 static irqreturn_t ad7476_trigger_handler(int irq, void *p) ··· 85 93 struct ad7476_state *st = iio_priv(indio_dev); 86 94 int b_sent; 87 95 88 - ad7091_convst(st); 96 + if (st->chip_info->conversion_pre_op) 97 + st->chip_info->conversion_pre_op(st); 89 98 90 99 b_sent = spi_sync(st->spi, &st->msg); 91 100 if (b_sent < 0) ··· 95 102 iio_push_to_buffers_with_ts(indio_dev, st->data, sizeof(st->data), 96 103 iio_get_time_ns(indio_dev)); 97 104 done: 105 + if (st->chip_info->conversion_post_op) 106 + st->chip_info->conversion_post_op(st); 98 107 iio_trigger_notify_done(indio_dev->trig); 99 108 100 109 return IRQ_HANDLED; ··· 112 117 { 113 118 int ret; 114 119 115 - ad7091_convst(st); 120 + if (st->chip_info->conversion_pre_op) 121 + st->chip_info->conversion_pre_op(st); 116 122 117 123 ret = spi_sync(st->spi, &st->msg); 118 124 if (ret) 119 125 return ret; 126 + 127 + if (st->chip_info->conversion_post_op) 128 + st->chip_info->conversion_post_op(st); 120 129 121 130 return be16_to_cpup((__be16 *)st->data); 122 131 } ··· 133 134 { 134 135 int ret; 135 136 struct ad7476_state *st = iio_priv(indio_dev); 136 - int scale_uv; 137 137 138 138 switch (m) { 139 139 case IIO_CHAN_INFO_RAW: ··· 143 145 144 146 if (ret < 0) 145 147 return ret; 146 - *val = (ret >> st->chip_info->channel[0].scan_type.shift) & 147 - GENMASK(st->chip_info->channel[0].scan_type.realbits - 1, 0); 148 + *val = (ret >> chan->scan_type.shift) & 149 + GENMASK(chan->scan_type.realbits - 1, 0); 148 150 return IIO_VAL_INT; 149 151 case IIO_CHAN_INFO_SCALE: 150 - if (st->ref_reg) { 151 - scale_uv = regulator_get_voltage(st->ref_reg); 152 - if (scale_uv < 0) 153 - return scale_uv; 154 - } else { 155 - scale_uv = st->chip_info->int_vref_uv; 156 - } 157 - *val = scale_uv / 1000; 152 + *val = st->scale_mv; 158 153 *val2 = chan->scan_type.realbits; 159 154 return IIO_VAL_FRACTIONAL_LOG2; 160 155 } ··· 176 185 #define AD7940_CHAN(bits) _AD7476_CHAN((bits), 15 - (bits), \ 177 186 BIT(IIO_CHAN_INFO_RAW)) 178 187 #define AD7091R_CHAN(bits) _AD7476_CHAN((bits), 16 - (bits), 0) 179 - #define AD7091R_CONVST_CHAN(bits) _AD7476_CHAN((bits), 16 - (bits), \ 180 - BIT(IIO_CHAN_INFO_RAW)) 181 188 #define ADS786X_CHAN(bits) _AD7476_CHAN((bits), 12 - (bits), \ 182 189 BIT(IIO_CHAN_INFO_RAW)) 183 190 184 - static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { 185 - [ID_AD7091] = { 186 - .channel[0] = AD7091R_CHAN(12), 187 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 188 - .convst_channel[0] = AD7091R_CONVST_CHAN(12), 189 - .convst_channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 190 - .reset = ad7091_reset, 191 - }, 192 - [ID_AD7091R] = { 193 - .channel[0] = AD7091R_CHAN(12), 194 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 195 - .convst_channel[0] = AD7091R_CONVST_CHAN(12), 196 - .convst_channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 197 - .int_vref_uv = 2500000, 198 - .has_vref = true, 199 - .reset = ad7091_reset, 200 - }, 201 - [ID_AD7273] = { 202 - .channel[0] = AD7940_CHAN(10), 203 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 204 - .has_vref = true, 205 - }, 206 - [ID_AD7274] = { 207 - .channel[0] = AD7940_CHAN(12), 208 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 209 - .has_vref = true, 210 - }, 211 - [ID_AD7276] = { 212 - .channel[0] = AD7940_CHAN(12), 213 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 214 - }, 215 - [ID_AD7277] = { 216 - .channel[0] = AD7940_CHAN(10), 217 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 218 - }, 219 - [ID_AD7278] = { 220 - .channel[0] = AD7940_CHAN(8), 221 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 222 - }, 223 - [ID_AD7466] = { 224 - .channel[0] = AD7476_CHAN(12), 225 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 226 - }, 227 - [ID_AD7467] = { 228 - .channel[0] = AD7476_CHAN(10), 229 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 230 - }, 231 - [ID_AD7468] = { 232 - .channel[0] = AD7476_CHAN(8), 233 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 234 - }, 235 - [ID_AD7475] = { 236 - .channel[0] = AD7476_CHAN(12), 237 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 238 - .has_vref = true, 239 - .has_vdrive = true, 240 - }, 241 - [ID_AD7495] = { 242 - .channel[0] = AD7476_CHAN(12), 243 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 244 - .int_vref_uv = 2500000, 245 - .has_vdrive = true, 246 - }, 247 - [ID_AD7940] = { 248 - .channel[0] = AD7940_CHAN(14), 249 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 250 - }, 251 - [ID_ADC081S] = { 252 - .channel[0] = ADC081S_CHAN(8), 253 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 254 - }, 255 - [ID_ADC101S] = { 256 - .channel[0] = ADC081S_CHAN(10), 257 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 258 - }, 259 - [ID_ADC121S] = { 260 - .channel[0] = ADC081S_CHAN(12), 261 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 262 - }, 263 - [ID_ADS7866] = { 264 - .channel[0] = ADS786X_CHAN(12), 265 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 266 - }, 267 - [ID_ADS7867] = { 268 - .channel[0] = ADS786X_CHAN(10), 269 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 270 - }, 271 - [ID_ADS7868] = { 272 - .channel[0] = ADS786X_CHAN(8), 273 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 274 - }, 275 - [ID_LTC2314_14] = { 276 - .channel[0] = AD7940_CHAN(14), 277 - .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 278 - .has_vref = true, 279 - }, 191 + static const struct ad7476_chip_info ad7091_chip_info = { 192 + .channel[0] = AD7091R_CHAN(12), 193 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 194 + .conversion_pre_op = ad7091_convst, 195 + .reset = ad7091_reset, 196 + }; 197 + 198 + static const struct ad7476_chip_info ad7091r_chip_info = { 199 + .channel[0] = AD7091R_CHAN(12), 200 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 201 + .conversion_pre_op = ad7091_convst, 202 + .int_vref_mv = 2500, 203 + .has_vref = true, 204 + .reset = ad7091_reset, 205 + }; 206 + 207 + static const struct ad7476_chip_info ad7273_chip_info = { 208 + .channel[0] = AD7940_CHAN(10), 209 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 210 + .has_vref = true, 211 + }; 212 + 213 + static const struct ad7476_chip_info ad7274_chip_info = { 214 + .channel[0] = AD7940_CHAN(12), 215 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 216 + .has_vref = true, 217 + }; 218 + 219 + static const struct ad7476_chip_info ad7276_chip_info = { 220 + .channel[0] = AD7940_CHAN(12), 221 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 222 + }; 223 + 224 + static const struct ad7476_chip_info ad7277_chip_info = { 225 + .channel[0] = AD7940_CHAN(10), 226 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 227 + }; 228 + 229 + static const struct ad7476_chip_info ad7278_chip_info = { 230 + .channel[0] = AD7940_CHAN(8), 231 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 232 + }; 233 + 234 + static const struct ad7476_chip_info ad7466_chip_info = { 235 + .channel[0] = AD7476_CHAN(12), 236 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 237 + }; 238 + 239 + static const struct ad7476_chip_info ad7467_chip_info = { 240 + .channel[0] = AD7476_CHAN(10), 241 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 242 + }; 243 + 244 + static const struct ad7476_chip_info ad7468_chip_info = { 245 + .channel[0] = AD7476_CHAN(8), 246 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 247 + }; 248 + 249 + static const struct ad7476_chip_info ad7475_chip_info = { 250 + .channel[0] = AD7476_CHAN(12), 251 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 252 + .has_vref = true, 253 + .has_vdrive = true, 254 + }; 255 + 256 + static const struct ad7476_chip_info ad7495_chip_info = { 257 + .channel[0] = AD7476_CHAN(12), 258 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 259 + .int_vref_mv = 2500, 260 + .has_vdrive = true, 261 + }; 262 + 263 + static const struct ad7476_chip_info ad7940_chip_info = { 264 + .channel[0] = AD7940_CHAN(14), 265 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 266 + }; 267 + 268 + static const struct ad7476_chip_info adc081s_chip_info = { 269 + .channel[0] = ADC081S_CHAN(8), 270 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 271 + }; 272 + 273 + static const struct ad7476_chip_info adc101s_chip_info = { 274 + .channel[0] = ADC081S_CHAN(10), 275 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 276 + }; 277 + 278 + static const struct ad7476_chip_info adc121s_chip_info = { 279 + .channel[0] = ADC081S_CHAN(12), 280 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 281 + }; 282 + 283 + static const struct ad7476_chip_info ads7866_chip_info = { 284 + .channel[0] = ADS786X_CHAN(12), 285 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 286 + }; 287 + 288 + static const struct ad7476_chip_info ads7867_chip_info = { 289 + .channel[0] = ADS786X_CHAN(10), 290 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 291 + }; 292 + 293 + static const struct ad7476_chip_info ads7868_chip_info = { 294 + .channel[0] = ADS786X_CHAN(8), 295 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 296 + }; 297 + 298 + static const struct ad7476_chip_info ltc2314_14_chip_info = { 299 + .channel[0] = AD7940_CHAN(14), 300 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 301 + .has_vref = true, 302 + }; 303 + 304 + static const struct ad7476_chip_info bd79105_chip_info = { 305 + .channel[0] = AD7091R_CHAN(16), 306 + .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 307 + /* 308 + * The BD79105 starts ADC data conversion when the CONVSTART line is 309 + * set HIGH. The CONVSTART must be kept HIGH until the data has been 310 + * read from the ADC. 311 + */ 312 + .conversion_pre_op = bd79105_convst_enable, 313 + .conversion_post_op = bd79105_convst_disable, 314 + /* BD79105 won't do conversion without convstart */ 315 + .convstart_required = true, 316 + .has_vref = true, 317 + .has_vdrive = true, 280 318 }; 281 319 282 320 static const struct iio_info ad7476_info = { 283 321 .read_raw = &ad7476_read_raw, 284 322 }; 285 323 286 - static void ad7476_reg_disable(void *data) 287 - { 288 - struct regulator *reg = data; 289 - 290 - regulator_disable(reg); 291 - } 292 - 293 324 static int ad7476_probe(struct spi_device *spi) 294 325 { 295 326 struct ad7476_state *st; 296 327 struct iio_dev *indio_dev; 297 - struct regulator *reg; 328 + unsigned int i; 298 329 int ret; 299 330 300 331 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); ··· 324 311 return -ENOMEM; 325 312 326 313 st = iio_priv(indio_dev); 327 - st->chip_info = 328 - &ad7476_chip_info_tbl[spi_get_device_id(spi)->driver_data]; 329 314 330 - reg = devm_regulator_get(&spi->dev, "vcc"); 331 - if (IS_ERR(reg)) 332 - return PTR_ERR(reg); 315 + st->chip_info = spi_get_device_match_data(spi); 316 + if (!st->chip_info) 317 + return -ENODEV; 333 318 334 - ret = regulator_enable(reg); 335 - if (ret) 336 - return ret; 337 - 338 - ret = devm_add_action_or_reset(&spi->dev, ad7476_reg_disable, reg); 339 - if (ret) 340 - return ret; 341 - 342 - /* Either vcc or vref (below) as appropriate */ 343 - if (!st->chip_info->int_vref_uv) 344 - st->ref_reg = reg; 319 + /* Use VCC for reference voltage if vref / internal vref aren't used */ 320 + if (!st->chip_info->int_vref_mv && !st->chip_info->has_vref) { 321 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vcc"); 322 + if (ret < 0) 323 + return ret; 324 + st->scale_mv = ret / 1000; 325 + } else { 326 + ret = devm_regulator_get_enable(&spi->dev, "vcc"); 327 + if (ret < 0) 328 + return ret; 329 + } 345 330 346 331 if (st->chip_info->has_vref) { 347 - 348 - /* If a device has an internal reference vref is optional */ 349 - if (st->chip_info->int_vref_uv) { 350 - reg = devm_regulator_get_optional(&spi->dev, "vref"); 351 - if (IS_ERR(reg) && (PTR_ERR(reg) != -ENODEV)) 352 - return PTR_ERR(reg); 353 - } else { 354 - reg = devm_regulator_get(&spi->dev, "vref"); 355 - if (IS_ERR(reg)) 356 - return PTR_ERR(reg); 357 - } 358 - 359 - if (!IS_ERR(reg)) { 360 - ret = regulator_enable(reg); 361 - if (ret) 332 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); 333 + if (ret < 0) { 334 + /* Vref is optional if a device has an internal reference */ 335 + if (!st->chip_info->int_vref_mv || ret != -ENODEV) 362 336 return ret; 363 - 364 - ret = devm_add_action_or_reset(&spi->dev, 365 - ad7476_reg_disable, 366 - reg); 367 - if (ret) 368 - return ret; 369 - st->ref_reg = reg; 370 337 } else { 371 - /* 372 - * Can only get here if device supports both internal 373 - * and external reference, but the regulator connected 374 - * to the external reference is not connected. 375 - * Set the reference regulator pointer to NULL to 376 - * indicate this. 377 - */ 378 - st->ref_reg = NULL; 338 + st->scale_mv = ret / 1000; 379 339 } 380 340 } 341 + 342 + if (!st->scale_mv) 343 + st->scale_mv = st->chip_info->int_vref_mv; 381 344 382 345 if (st->chip_info->has_vdrive) { 383 346 ret = devm_regulator_get_enable(&spi->dev, "vdrive"); ··· 367 378 if (IS_ERR(st->convst_gpio)) 368 379 return PTR_ERR(st->convst_gpio); 369 380 381 + if (st->chip_info->convstart_required && !st->convst_gpio) 382 + return dev_err_probe(&spi->dev, -EINVAL, "No convstart GPIO\n"); 383 + 384 + /* 385 + * This will never happen. Unless someone changes the channel specs 386 + * in this driver. And if someone does, without changing the loop 387 + * below, then we'd better immediately produce a big fat error, before 388 + * the change proceeds from that developer's table. 389 + */ 390 + static_assert(ARRAY_SIZE(st->channel) == ARRAY_SIZE(st->chip_info->channel)); 391 + for (i = 0; i < ARRAY_SIZE(st->channel); i++) { 392 + st->channel[i] = st->chip_info->channel[i]; 393 + if (st->convst_gpio) 394 + __set_bit(IIO_CHAN_INFO_RAW, 395 + &st->channel[i].info_mask_separate); 396 + } 397 + 370 398 st->spi = spi; 371 399 372 400 indio_dev->name = spi_get_device_id(spi)->name; 373 401 indio_dev->modes = INDIO_DIRECT_MODE; 374 - indio_dev->channels = st->chip_info->channel; 375 - indio_dev->num_channels = 2; 402 + indio_dev->channels = st->channel; 403 + indio_dev->num_channels = ARRAY_SIZE(st->channel); 376 404 indio_dev->info = &ad7476_info; 377 405 378 - if (st->convst_gpio) 379 - indio_dev->channels = st->chip_info->convst_channel; 380 406 /* Setup default message */ 381 407 382 408 st->xfer.rx_buf = &st->data; 383 - st->xfer.len = st->chip_info->channel[0].scan_type.storagebits / 8; 409 + st->xfer.len = indio_dev->channels[0].scan_type.storagebits / 8; 384 410 385 411 spi_message_init(&st->msg); 386 412 spi_message_add_tail(&st->xfer, &st->msg); ··· 412 408 } 413 409 414 410 static const struct spi_device_id ad7476_id[] = { 415 - { "ad7091", ID_AD7091 }, 416 - { "ad7091r", ID_AD7091R }, 417 - { "ad7273", ID_AD7273 }, 418 - { "ad7274", ID_AD7274 }, 419 - { "ad7276", ID_AD7276}, 420 - { "ad7277", ID_AD7277 }, 421 - { "ad7278", ID_AD7278 }, 422 - { "ad7466", ID_AD7466 }, 423 - { "ad7467", ID_AD7467 }, 424 - { "ad7468", ID_AD7468 }, 425 - { "ad7475", ID_AD7475 }, 426 - { "ad7476", ID_AD7466 }, 427 - { "ad7476a", ID_AD7466 }, 428 - { "ad7477", ID_AD7467 }, 429 - { "ad7477a", ID_AD7467 }, 430 - { "ad7478", ID_AD7468 }, 431 - { "ad7478a", ID_AD7468 }, 432 - { "ad7495", ID_AD7495 }, 433 - { "ad7910", ID_AD7467 }, 434 - { "ad7920", ID_AD7466 }, 435 - { "ad7940", ID_AD7940 }, 436 - { "adc081s", ID_ADC081S }, 437 - { "adc101s", ID_ADC101S }, 438 - { "adc121s", ID_ADC121S }, 439 - { "ads7866", ID_ADS7866 }, 440 - { "ads7867", ID_ADS7867 }, 441 - { "ads7868", ID_ADS7868 }, 411 + { "ad7091", (kernel_ulong_t)&ad7091_chip_info }, 412 + { "ad7091r", (kernel_ulong_t)&ad7091r_chip_info }, 413 + { "ad7273", (kernel_ulong_t)&ad7273_chip_info }, 414 + { "ad7274", (kernel_ulong_t)&ad7274_chip_info }, 415 + { "ad7276", (kernel_ulong_t)&ad7276_chip_info }, 416 + { "ad7277", (kernel_ulong_t)&ad7277_chip_info }, 417 + { "ad7278", (kernel_ulong_t)&ad7278_chip_info }, 418 + { "ad7466", (kernel_ulong_t)&ad7466_chip_info }, 419 + { "ad7467", (kernel_ulong_t)&ad7467_chip_info }, 420 + { "ad7468", (kernel_ulong_t)&ad7468_chip_info }, 421 + { "ad7475", (kernel_ulong_t)&ad7475_chip_info }, 422 + { "ad7476", (kernel_ulong_t)&ad7466_chip_info }, 423 + { "ad7476a", (kernel_ulong_t)&ad7466_chip_info }, 424 + { "ad7477", (kernel_ulong_t)&ad7467_chip_info }, 425 + { "ad7477a", (kernel_ulong_t)&ad7467_chip_info }, 426 + { "ad7478", (kernel_ulong_t)&ad7468_chip_info }, 427 + { "ad7478a", (kernel_ulong_t)&ad7468_chip_info }, 428 + { "ad7495", (kernel_ulong_t)&ad7495_chip_info }, 429 + { "ad7910", (kernel_ulong_t)&ad7467_chip_info }, 430 + { "ad7920", (kernel_ulong_t)&ad7466_chip_info }, 431 + { "ad7940", (kernel_ulong_t)&ad7940_chip_info }, 432 + { "adc081s", (kernel_ulong_t)&adc081s_chip_info }, 433 + { "adc101s", (kernel_ulong_t)&adc101s_chip_info }, 434 + { "adc121s", (kernel_ulong_t)&adc121s_chip_info }, 435 + { "ads7866", (kernel_ulong_t)&ads7866_chip_info }, 436 + { "ads7867", (kernel_ulong_t)&ads7867_chip_info }, 437 + { "ads7868", (kernel_ulong_t)&ads7868_chip_info }, 438 + { "bd79105", (kernel_ulong_t)&bd79105_chip_info }, 442 439 /* 443 440 * The ROHM BU79100G is identical to the TI's ADS7866 from the software 444 441 * point of view. The binding document mandates the ADS7866 to be 445 442 * marked as a fallback for the BU79100G, but we still need the SPI ID 446 443 * here to make the module loading work. 447 444 */ 448 - { "bu79100g", ID_ADS7866 }, 449 - { "ltc2314-14", ID_LTC2314_14 }, 445 + { "bu79100g", (kernel_ulong_t)&ads7866_chip_info }, 446 + { "ltc2314-14", (kernel_ulong_t)&ltc2314_14_chip_info }, 450 447 { } 451 448 }; 452 449 MODULE_DEVICE_TABLE(spi, ad7476_id);
+8 -29
drivers/iio/adc/ad7768-1.c
··· 217 217 struct spi_device *spi; 218 218 struct regmap *regmap; 219 219 struct regmap *regmap24; 220 - struct regulator *vref; 220 + int vref_uv; 221 221 struct regulator_dev *vcm_rdev; 222 222 unsigned int vcm_output_sel; 223 223 struct clk *mclk; ··· 687 687 int ret; 688 688 689 689 freq = clamp(freq, 50, 1024000); 690 - if (freq == 0) 691 - return -EINVAL; 692 690 693 691 mclk_div = DIV_ROUND_CLOSEST(st->mclk_freq, freq * st->oversampling_ratio); 694 692 /* Find the closest match for the desired sampling frequency */ ··· 774 776 { 775 777 struct ad7768_state *st = iio_priv(indio_dev); 776 778 const struct iio_scan_type *scan_type; 777 - int scale_uv, ret, temp; 779 + int ret, temp; 778 780 779 781 scan_type = iio_get_current_scan_type(indio_dev, chan); 780 782 if (IS_ERR(scan_type)) ··· 795 797 return IIO_VAL_INT; 796 798 797 799 case IIO_CHAN_INFO_SCALE: 798 - scale_uv = regulator_get_voltage(st->vref); 799 - if (scale_uv < 0) 800 - return scale_uv; 801 - 802 - *val = (scale_uv * 2) / 1000; 800 + *val = (st->vref_uv * 2) / 1000; 803 801 *val2 = scan_type->realbits; 804 802 805 803 return IIO_VAL_FRACTIONAL_LOG2; ··· 1128 1134 .validate_device = iio_trigger_validate_own_device, 1129 1135 }; 1130 1136 1131 - static void ad7768_regulator_disable(void *data) 1132 - { 1133 - struct ad7768_state *st = data; 1134 - 1135 - regulator_disable(st->vref); 1136 - } 1137 - 1138 1137 static int ad7768_set_channel_label(struct iio_dev *indio_dev, 1139 1138 int num_channels) 1140 1139 { ··· 1359 1372 return dev_err_probe(&spi->dev, PTR_ERR(st->regmap24), 1360 1373 "Failed to initialize regmap24"); 1361 1374 1362 - st->vref = devm_regulator_get(&spi->dev, "vref"); 1363 - if (IS_ERR(st->vref)) 1364 - return PTR_ERR(st->vref); 1365 - 1366 - ret = regulator_enable(st->vref); 1367 - if (ret) { 1368 - dev_err(&spi->dev, "Failed to enable specified vref supply\n"); 1369 - return ret; 1370 - } 1371 - 1372 - ret = devm_add_action_or_reset(&spi->dev, ad7768_regulator_disable, st); 1373 - if (ret) 1374 - return ret; 1375 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); 1376 + if (ret < 0) 1377 + return dev_err_probe(&spi->dev, ret, 1378 + "Failed to get VREF voltage\n"); 1379 + st->vref_uv = ret; 1375 1380 1376 1381 st->mclk = devm_clk_get_enabled(&spi->dev, "mclk"); 1377 1382 if (IS_ERR(st->mclk))
+152 -40
drivers/iio/adc/ad7779.c
··· 25 25 #include <linux/units.h> 26 26 27 27 #include <linux/iio/iio.h> 28 + #include <linux/iio/backend.h> 28 29 #include <linux/iio/buffer.h> 29 30 #include <linux/iio/sysfs.h> 30 31 #include <linux/iio/trigger.h> ··· 146 145 struct completion completion; 147 146 unsigned int sampling_freq; 148 147 enum ad7779_filter filter_enabled; 148 + struct iio_backend *back; 149 149 /* 150 150 * DMA (thus cache coherency maintenance) requires the 151 151 * transfer buffers to live in their own cache lines. ··· 632 630 return ret; 633 631 } 634 632 633 + static int ad7779_update_scan_mode(struct iio_dev *indio_dev, 634 + const unsigned long *scan_mask) 635 + { 636 + struct ad7779_state *st = iio_priv(indio_dev); 637 + unsigned int c; 638 + int ret; 639 + 640 + for (c = 0; c < AD7779_NUM_CHANNELS; c++) { 641 + if (test_bit(c, scan_mask)) 642 + ret = iio_backend_chan_enable(st->back, c); 643 + else 644 + ret = iio_backend_chan_disable(st->back, c); 645 + if (ret) 646 + return ret; 647 + } 648 + 649 + return 0; 650 + } 651 + 635 652 static const struct iio_info ad7779_info = { 636 653 .read_raw = ad7779_read_raw, 637 654 .write_raw = ad7779_write_raw, 638 655 .debugfs_reg_access = &ad7779_reg_access, 656 + }; 657 + 658 + static const struct iio_info ad7779_info_data = { 659 + .read_raw = ad7779_read_raw, 660 + .write_raw = ad7779_write_raw, 661 + .debugfs_reg_access = &ad7779_reg_access, 662 + .update_scan_mode = &ad7779_update_scan_mode, 639 663 }; 640 664 641 665 static const struct iio_enum ad7779_filter_enum = { ··· 780 752 return 0; 781 753 } 782 754 755 + static int ad7779_set_data_lines(struct iio_dev *indio_dev, u32 num_lanes) 756 + { 757 + struct ad7779_state *st = iio_priv(indio_dev); 758 + int ret; 759 + 760 + if (num_lanes != 1 && num_lanes != 2 && num_lanes != 4) 761 + return -EINVAL; 762 + 763 + ret = ad7779_set_sampling_frequency(st, num_lanes * AD7779_DEFAULT_SAMPLING_1LINE); 764 + if (ret) 765 + return ret; 766 + 767 + ret = iio_backend_num_lanes_set(st->back, num_lanes); 768 + if (ret) 769 + return ret; 770 + 771 + return ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT, 772 + AD7779_DOUT_FORMAT_MSK, 773 + FIELD_PREP(AD7779_DOUT_FORMAT_MSK, 2 - ilog2(num_lanes))); 774 + } 775 + 776 + static int ad7779_setup_channels(struct iio_dev *indio_dev, const struct ad7779_state *st) 777 + { 778 + struct iio_chan_spec *channels; 779 + struct device *dev = &st->spi->dev; 780 + 781 + channels = devm_kmemdup_array(dev, st->chip_info->channels, 782 + ARRAY_SIZE(ad7779_channels), 783 + sizeof(*channels), GFP_KERNEL); 784 + if (!channels) 785 + return -ENOMEM; 786 + 787 + for (unsigned int i = 0; i < ARRAY_SIZE(ad7779_channels); i++) 788 + channels[i].scan_type.endianness = IIO_CPU; 789 + 790 + indio_dev->channels = channels; 791 + indio_dev->num_channels = ARRAY_SIZE(ad7779_channels); 792 + 793 + return 0; 794 + } 795 + 796 + static int ad7779_setup_without_backend(struct ad7779_state *st, struct iio_dev *indio_dev) 797 + { 798 + int ret; 799 + struct device *dev = &st->spi->dev; 800 + 801 + indio_dev->info = &ad7779_info; 802 + indio_dev->channels = st->chip_info->channels; 803 + indio_dev->num_channels = ARRAY_SIZE(ad7779_channels); 804 + 805 + st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, 806 + iio_device_id(indio_dev)); 807 + if (!st->trig) 808 + return -ENOMEM; 809 + 810 + st->trig->ops = &ad7779_trigger_ops; 811 + 812 + iio_trigger_set_drvdata(st->trig, st); 813 + 814 + ret = devm_request_irq(dev, st->spi->irq, iio_trigger_generic_data_rdy_poll, 815 + IRQF_ONESHOT | IRQF_NO_AUTOEN, indio_dev->name, 816 + st->trig); 817 + if (ret) 818 + return dev_err_probe(dev, ret, "request IRQ %d failed\n", 819 + st->spi->irq); 820 + 821 + ret = devm_iio_trigger_register(dev, st->trig); 822 + if (ret) 823 + return ret; 824 + 825 + indio_dev->trig = iio_trigger_get(st->trig); 826 + 827 + init_completion(&st->completion); 828 + 829 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 830 + &iio_pollfunc_store_time, 831 + &ad7779_trigger_handler, 832 + &ad7779_buffer_setup_ops); 833 + if (ret) 834 + return ret; 835 + 836 + return ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT, 837 + AD7779_DCLK_CLK_DIV_MSK, 838 + FIELD_PREP(AD7779_DCLK_CLK_DIV_MSK, 7)); 839 + } 840 + 841 + static int ad7779_setup_backend(struct ad7779_state *st, struct iio_dev *indio_dev) 842 + { 843 + struct device *dev = &st->spi->dev; 844 + int ret; 845 + u32 num_lanes; 846 + 847 + indio_dev->info = &ad7779_info_data; 848 + 849 + ret = ad7779_setup_channels(indio_dev, st); 850 + if (ret) 851 + return ret; 852 + 853 + st->back = devm_iio_backend_get(dev, NULL); 854 + if (IS_ERR(st->back)) 855 + return dev_err_probe(dev, PTR_ERR(st->back), 856 + "failed to get iio backend"); 857 + 858 + ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev); 859 + if (ret) 860 + return ret; 861 + 862 + ret = devm_iio_backend_enable(dev, st->back); 863 + if (ret) 864 + return ret; 865 + 866 + num_lanes = 4; 867 + ret = device_property_read_u32(dev, "adi,num-lanes", &num_lanes); 868 + if (ret && ret != -EINVAL) 869 + return ret; 870 + 871 + return ad7779_set_data_lines(indio_dev, num_lanes); 872 + } 873 + 783 874 static int ad7779_probe(struct spi_device *spi) 784 875 { 785 876 struct iio_dev *indio_dev; ··· 906 759 struct gpio_desc *reset_gpio, *start_gpio; 907 760 struct device *dev = &spi->dev; 908 761 int ret = -EINVAL; 909 - 910 - if (!spi->irq) 911 - return dev_err_probe(dev, ret, "DRDY irq not present\n"); 912 762 913 763 indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 914 764 if (!indio_dev) ··· 948 804 return ret; 949 805 950 806 indio_dev->name = st->chip_info->name; 951 - indio_dev->info = &ad7779_info; 952 807 indio_dev->modes = INDIO_DIRECT_MODE; 953 - indio_dev->channels = st->chip_info->channels; 954 - indio_dev->num_channels = ARRAY_SIZE(ad7779_channels); 955 808 956 - st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, 957 - iio_device_id(indio_dev)); 958 - if (!st->trig) 959 - return -ENOMEM; 960 - 961 - st->trig->ops = &ad7779_trigger_ops; 962 - 963 - iio_trigger_set_drvdata(st->trig, st); 964 - 965 - ret = devm_request_irq(dev, spi->irq, iio_trigger_generic_data_rdy_poll, 966 - IRQF_ONESHOT | IRQF_NO_AUTOEN, indio_dev->name, 967 - st->trig); 968 - if (ret) 969 - return dev_err_probe(dev, ret, "request IRQ %d failed\n", 970 - st->spi->irq); 971 - 972 - ret = devm_iio_trigger_register(dev, st->trig); 973 - if (ret) 974 - return ret; 975 - 976 - indio_dev->trig = iio_trigger_get(st->trig); 977 - 978 - init_completion(&st->completion); 979 - 980 - ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 981 - &iio_pollfunc_store_time, 982 - &ad7779_trigger_handler, 983 - &ad7779_buffer_setup_ops); 984 - if (ret) 985 - return ret; 986 - 987 - ret = ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT, 988 - AD7779_DCLK_CLK_DIV_MSK, 989 - FIELD_PREP(AD7779_DCLK_CLK_DIV_MSK, 7)); 809 + if (device_property_present(dev, "io-backends")) 810 + ret = ad7779_setup_backend(st, indio_dev); 811 + else 812 + ret = ad7779_setup_without_backend(st, indio_dev); 990 813 if (ret) 991 814 return ret; 992 815 ··· 1047 936 MODULE_AUTHOR("Ramona Alexandra Nechita <ramona.nechita@analog.com>"); 1048 937 MODULE_DESCRIPTION("Analog Devices AD7779 ADC"); 1049 938 MODULE_LICENSE("GPL"); 939 + MODULE_IMPORT_NS("IIO_BACKEND");
+1 -3
drivers/iio/adc/ad7949.c
··· 316 316 int ret; 317 317 318 318 indio_dev = devm_iio_device_alloc(dev, sizeof(*ad7949_adc)); 319 - if (!indio_dev) { 320 - dev_err(dev, "can not allocate iio device\n"); 319 + if (!indio_dev) 321 320 return -ENOMEM; 322 - } 323 321 324 322 indio_dev->info = &ad7949_spi_info; 325 323 indio_dev->name = spi_get_device_id(spi)->name;
+13 -17
drivers/iio/adc/ad799x.c
··· 114 114 * @num_channels: number of channels 115 115 * @noirq_config: device configuration w/o IRQ 116 116 * @irq_config: device configuration w/IRQ 117 + * @has_vref: device supports external reference voltage 117 118 */ 118 119 struct ad799x_chip_info { 119 120 int num_channels; 120 121 const struct ad799x_chip_config noirq_config; 121 122 const struct ad799x_chip_config irq_config; 123 + bool has_vref; 122 124 }; 123 125 124 126 struct ad799x_state { ··· 606 604 static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { 607 605 [ad7991] = { 608 606 .num_channels = 5, 607 + .has_vref = true, 609 608 .noirq_config = { 610 609 .channel = { 611 610 AD799X_CHANNEL(0, 12), ··· 620 617 }, 621 618 [ad7995] = { 622 619 .num_channels = 5, 620 + .has_vref = true, 623 621 .noirq_config = { 624 622 .channel = { 625 623 AD799X_CHANNEL(0, 10), ··· 634 630 }, 635 631 [ad7999] = { 636 632 .num_channels = 5, 633 + .has_vref = true, 637 634 .noirq_config = { 638 635 .channel = { 639 636 AD799X_CHANNEL(0, 8), ··· 692 687 }, 693 688 [ad7994] = { 694 689 .num_channels = 5, 690 + .has_vref = true, 695 691 .noirq_config = { 696 692 .channel = { 697 693 AD799X_CHANNEL(0, 12), ··· 815 809 return ret; 816 810 817 811 /* check if an external reference is supplied */ 818 - st->vref = devm_regulator_get_optional(&client->dev, "vref"); 819 - 820 - if (IS_ERR(st->vref)) { 821 - if (PTR_ERR(st->vref) == -ENODEV) { 812 + if (chip_info->has_vref) { 813 + st->vref = devm_regulator_get_optional(&client->dev, "vref"); 814 + ret = PTR_ERR_OR_ZERO(st->vref); 815 + if (ret) { 816 + if (ret != -ENODEV) 817 + goto error_disable_reg; 822 818 st->vref = NULL; 823 819 dev_info(&client->dev, "Using VCC reference voltage\n"); 824 - } else { 825 - ret = PTR_ERR(st->vref); 826 - goto error_disable_reg; 827 820 } 828 - } 829 821 830 - if (st->vref) { 831 - /* 832 - * Use external reference voltage if supported by hardware. 833 - * This is optional if voltage / regulator present, use VCC otherwise. 834 - */ 835 - if ((st->id == ad7991) || (st->id == ad7995) || (st->id == ad7999)) { 822 + if (st->vref) { 836 823 dev_info(&client->dev, "Using external reference voltage\n"); 837 824 extra_config |= AD7991_REF_SEL; 838 825 ret = regulator_enable(st->vref); 839 826 if (ret) 840 827 goto error_disable_reg; 841 - } else { 842 - st->vref = NULL; 843 - dev_warn(&client->dev, "Supplied reference not supported\n"); 844 828 } 845 829 } 846 830
+1799
drivers/iio/adc/ade9000.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /** 3 + * ADE9000 driver 4 + * 5 + * Copyright 2025 Analog Devices Inc. 6 + */ 7 + 8 + #include <linux/bitfield.h> 9 + #include <linux/clk.h> 10 + #include <linux/clk-provider.h> 11 + #include <linux/completion.h> 12 + #include <linux/delay.h> 13 + #include <linux/gpio/consumer.h> 14 + #include <linux/iio/iio.h> 15 + #include <linux/iio/buffer.h> 16 + #include <linux/iio/kfifo_buf.h> 17 + #include <linux/iio/events.h> 18 + #include <linux/interrupt.h> 19 + #include <linux/minmax.h> 20 + #include <linux/module.h> 21 + #include <linux/property.h> 22 + #include <linux/regmap.h> 23 + #include <linux/regulator/consumer.h> 24 + #include <linux/spi/spi.h> 25 + #include <linux/unaligned.h> 26 + 27 + /* Address of ADE9000 registers */ 28 + #define ADE9000_REG_AIGAIN 0x000 29 + #define ADE9000_REG_AVGAIN 0x00B 30 + #define ADE9000_REG_AIRMSOS 0x00C 31 + #define ADE9000_REG_AVRMSOS 0x00D 32 + #define ADE9000_REG_APGAIN 0x00E 33 + #define ADE9000_REG_AWATTOS 0x00F 34 + #define ADE9000_REG_AVAROS 0x010 35 + #define ADE9000_REG_AFVAROS 0x012 36 + #define ADE9000_REG_CONFIG0 0x060 37 + #define ADE9000_REG_DICOEFF 0x072 38 + #define ADE9000_REG_AI_PCF 0x20A 39 + #define ADE9000_REG_AV_PCF 0x20B 40 + #define ADE9000_REG_AIRMS 0x20C 41 + #define ADE9000_REG_AVRMS 0x20D 42 + #define ADE9000_REG_AWATT 0x210 43 + #define ADE9000_REG_AVAR 0x211 44 + #define ADE9000_REG_AVA 0x212 45 + #define ADE9000_REG_AFVAR 0x214 46 + #define ADE9000_REG_APF 0x216 47 + #define ADE9000_REG_BI_PCF 0x22A 48 + #define ADE9000_REG_BV_PCF 0x22B 49 + #define ADE9000_REG_BIRMS 0x22C 50 + #define ADE9000_REG_BVRMS 0x22D 51 + #define ADE9000_REG_CI_PCF 0x24A 52 + #define ADE9000_REG_CV_PCF 0x24B 53 + #define ADE9000_REG_CIRMS 0x24C 54 + #define ADE9000_REG_CVRMS 0x24D 55 + #define ADE9000_REG_AWATT_ACC 0x2E5 56 + #define ADE9000_REG_AWATTHR_LO 0x2E6 57 + #define ADE9000_REG_AVAHR_LO 0x2FA 58 + #define ADE9000_REG_AFVARHR_LO 0x30E 59 + #define ADE9000_REG_BWATTHR_LO 0x322 60 + #define ADE9000_REG_BVAHR_LO 0x336 61 + #define ADE9000_REG_BFVARHR_LO 0x34A 62 + #define ADE9000_REG_CWATTHR_LO 0x35E 63 + #define ADE9000_REG_CVAHR_LO 0x372 64 + #define ADE9000_REG_CFVARHR_LO 0x386 65 + #define ADE9000_REG_STATUS0 0x402 66 + #define ADE9000_REG_STATUS1 0x403 67 + #define ADE9000_REG_MASK0 0x405 68 + #define ADE9000_REG_MASK1 0x406 69 + #define ADE9000_REG_EVENT_MASK 0x407 70 + #define ADE9000_REG_VLEVEL 0x40F 71 + #define ADE9000_REG_DIP_LVL 0x410 72 + #define ADE9000_REG_DIPA 0x411 73 + #define ADE9000_REG_DIPB 0x412 74 + #define ADE9000_REG_DIPC 0x413 75 + #define ADE9000_REG_SWELL_LVL 0x414 76 + #define ADE9000_REG_SWELLA 0x415 77 + #define ADE9000_REG_SWELLB 0x416 78 + #define ADE9000_REG_SWELLC 0x417 79 + #define ADE9000_REG_APERIOD 0x418 80 + #define ADE9000_REG_BPERIOD 0x419 81 + #define ADE9000_REG_CPERIOD 0x41A 82 + #define ADE9000_REG_RUN 0x480 83 + #define ADE9000_REG_CONFIG1 0x481 84 + #define ADE9000_REG_ACCMODE 0x492 85 + #define ADE9000_REG_CONFIG3 0x493 86 + #define ADE9000_REG_ZXTOUT 0x498 87 + #define ADE9000_REG_ZX_LP_SEL 0x49A 88 + #define ADE9000_REG_WFB_CFG 0x4A0 89 + #define ADE9000_REG_WFB_PG_IRQEN 0x4A1 90 + #define ADE9000_REG_WFB_TRG_CFG 0x4A2 91 + #define ADE9000_REG_WFB_TRG_STAT 0x4A3 92 + #define ADE9000_REG_CONFIG2 0x4AF 93 + #define ADE9000_REG_EP_CFG 0x4B0 94 + #define ADE9000_REG_EGY_TIME 0x4B2 95 + #define ADE9000_REG_PGA_GAIN 0x4B9 96 + #define ADE9000_REG_VERSION 0x4FE 97 + #define ADE9000_REG_WF_BUFF 0x800 98 + #define ADE9000_REG_WF_HALF_BUFF 0xC00 99 + 100 + #define ADE9000_REG_ADDR_MASK GENMASK(15, 4) 101 + #define ADE9000_REG_READ_BIT_MASK BIT(3) 102 + 103 + #define ADE9000_WF_CAP_EN_MASK BIT(4) 104 + #define ADE9000_WF_CAP_SEL_MASK BIT(5) 105 + #define ADE9000_WF_MODE_MASK GENMASK(7, 6) 106 + #define ADE9000_WF_SRC_MASK GENMASK(9, 8) 107 + #define ADE9000_WF_IN_EN_MASK BIT(12) 108 + 109 + /* External reference selection bit in CONFIG1 */ 110 + #define ADE9000_EXT_REF_MASK BIT(15) 111 + 112 + /* 113 + * Configuration registers 114 + */ 115 + #define ADE9000_PGA_GAIN 0x0000 116 + 117 + /* Default configuration */ 118 + 119 + #define ADE9000_CONFIG0 0x00000000 120 + 121 + /* CF3/ZX pin outputs Zero crossing, CF4 = DREADY */ 122 + #define ADE9000_CONFIG1 0x000E 123 + 124 + /* Default High pass corner frequency of 1.25Hz */ 125 + #define ADE9000_CONFIG2 0x0A00 126 + 127 + /* Peak and overcurrent detection disabled */ 128 + #define ADE9000_CONFIG3 0x0000 129 + 130 + /* 131 + * 50Hz operation, 3P4W Wye configuration, signed accumulation 132 + * 3P4W Wye = 3-Phase 4-Wire star configuration (3 phases + neutral wire) 133 + * Clear bit 8 i.e. ACCMODE=0x00xx for 50Hz operation 134 + * ACCMODE=0x0x9x for 3Wire delta when phase B is used as reference 135 + * 3Wire delta = 3-Phase 3-Wire triangle configuration (3 phases, no neutral) 136 + */ 137 + #define ADE9000_ACCMODE 0x0000 138 + #define ADE9000_ACCMODE_60HZ 0x0100 139 + 140 + /*Line period and zero crossing obtained from VA */ 141 + #define ADE9000_ZX_LP_SEL 0x0000 142 + 143 + /* Interrupt mask values for initialization */ 144 + #define ADE9000_MASK0_ALL_INT_DIS 0 145 + #define ADE9000_MASK1_ALL_INT_DIS 0x00000000 146 + 147 + /* Events disabled */ 148 + #define ADE9000_EVENT_DISABLE 0x00000000 149 + 150 + /* 151 + * Assuming Vnom=1/2 of full scale. 152 + * Refer to Technical reference manual for detailed calculations. 153 + */ 154 + #define ADE9000_VLEVEL 0x0022EA28 155 + 156 + /* Set DICOEFF= 0xFFFFE000 when integrator is enabled */ 157 + #define ADE9000_DICOEFF 0x00000000 158 + 159 + /* DSP ON */ 160 + #define ADE9000_RUN_ON 0xFFFFFFFF 161 + 162 + /* 163 + * Energy Accumulation Settings 164 + * Enable energy accumulation, accumulate samples at 8ksps 165 + * latch energy accumulation after EGYRDY 166 + * If accumulation is changed to half line cycle mode, change EGY_TIME 167 + */ 168 + #define ADE9000_EP_CFG 0x0011 169 + 170 + /* Accumulate 4000 samples */ 171 + #define ADE9000_EGY_TIME 7999 172 + 173 + /* 174 + * Constant Definitions 175 + * ADE9000 FDSP: 8000sps, ADE9000 FDSP: 4000sps 176 + */ 177 + #define ADE9000_FDSP 4000 178 + #define ADE9000_DEFAULT_CLK_FREQ_HZ 24576000 179 + #define ADE9000_WFB_CFG 0x03E9 180 + #define ADE9000_WFB_PAGE_SIZE 128 181 + #define ADE9000_WFB_NR_OF_PAGES 16 182 + #define ADE9000_WFB_MAX_CHANNELS 8 183 + #define ADE9000_WFB_BYTES_IN_SAMPLE 4 184 + #define ADE9000_WFB_SAMPLES_IN_PAGE \ 185 + (ADE9000_WFB_PAGE_SIZE / ADE9000_WFB_MAX_CHANNELS) 186 + #define ADE9000_WFB_MAX_SAMPLES_CHAN \ 187 + (ADE9000_WFB_SAMPLES_IN_PAGE * ADE9000_WFB_NR_OF_PAGES) 188 + #define ADE9000_WFB_FULL_BUFF_NR_SAMPLES \ 189 + (ADE9000_WFB_PAGE_SIZE * ADE9000_WFB_NR_OF_PAGES) 190 + #define ADE9000_WFB_FULL_BUFF_SIZE \ 191 + (ADE9000_WFB_FULL_BUFF_NR_SAMPLES * ADE9000_WFB_BYTES_IN_SAMPLE) 192 + 193 + #define ADE9000_SWRST_BIT BIT(0) 194 + 195 + /* Status and Mask register bits*/ 196 + #define ADE9000_ST0_WFB_TRIG_BIT BIT(16) 197 + #define ADE9000_ST0_PAGE_FULL_BIT BIT(17) 198 + #define ADE9000_ST0_EGYRDY BIT(0) 199 + 200 + #define ADE9000_ST1_ZXTOVA_BIT BIT(6) 201 + #define ADE9000_ST1_ZXTOVB_BIT BIT(7) 202 + #define ADE9000_ST1_ZXTOVC_BIT BIT(8) 203 + #define ADE9000_ST1_ZXVA_BIT BIT(9) 204 + #define ADE9000_ST1_ZXVB_BIT BIT(10) 205 + #define ADE9000_ST1_ZXVC_BIT BIT(11) 206 + #define ADE9000_ST1_ZXIA_BIT BIT(13) 207 + #define ADE9000_ST1_ZXIB_BIT BIT(14) 208 + #define ADE9000_ST1_ZXIC_BIT BIT(15) 209 + #define ADE9000_ST1_RSTDONE_BIT BIT(16) 210 + #define ADE9000_ST1_SEQERR_BIT BIT(18) 211 + #define ADE9000_ST1_SWELLA_BIT BIT(20) 212 + #define ADE9000_ST1_SWELLB_BIT BIT(21) 213 + #define ADE9000_ST1_SWELLC_BIT BIT(22) 214 + #define ADE9000_ST1_DIPA_BIT BIT(23) 215 + #define ADE9000_ST1_DIPB_BIT BIT(24) 216 + #define ADE9000_ST1_DIPC_BIT BIT(25) 217 + #define ADE9000_ST1_ERROR0_BIT BIT(28) 218 + #define ADE9000_ST1_ERROR1_BIT BIT(29) 219 + #define ADE9000_ST1_ERROR2_BIT BIT(30) 220 + #define ADE9000_ST1_ERROR3_BIT BIT(31) 221 + #define ADE9000_ST_ERROR \ 222 + (ADE9000_ST1_ERROR0 | ADE9000_ST1_ERROR1 | \ 223 + ADE9000_ST1_ERROR2 | ADE9000_ST1_ERROR3) 224 + #define ADE9000_ST1_CROSSING_FIRST 6 225 + #define ADE9000_ST1_CROSSING_DEPTH 25 226 + 227 + #define ADE9000_WFB_TRG_DIP_BIT BIT(0) 228 + #define ADE9000_WFB_TRG_SWELL_BIT BIT(1) 229 + #define ADE9000_WFB_TRG_ZXIA_BIT BIT(3) 230 + #define ADE9000_WFB_TRG_ZXIB_BIT BIT(4) 231 + #define ADE9000_WFB_TRG_ZXIC_BIT BIT(5) 232 + #define ADE9000_WFB_TRG_ZXVA_BIT BIT(6) 233 + #define ADE9000_WFB_TRG_ZXVB_BIT BIT(7) 234 + #define ADE9000_WFB_TRG_ZXVC_BIT BIT(8) 235 + 236 + /* Stop when waveform buffer is full */ 237 + #define ADE9000_WFB_FULL_MODE 0x0 238 + /* Continuous fill—stop only on enabled trigger events */ 239 + #define ADE9000_WFB_EN_TRIG_MODE 0x1 240 + /* Continuous filling—center capture around enabled trigger events */ 241 + #define ADE9000_WFB_C_EN_TRIG_MODE 0x2 242 + /* Continuous fill—used as streaming mode for continuous data output */ 243 + #define ADE9000_WFB_STREAMING_MODE 0x3 244 + 245 + #define ADE9000_LAST_PAGE_BIT BIT(15) 246 + #define ADE9000_MIDDLE_PAGE_BIT BIT(7) 247 + 248 + /* 249 + * Full scale Codes referred from Datasheet. Respective digital codes are 250 + * produced when ADC inputs are at full scale. 251 + */ 252 + #define ADE9000_RMS_FULL_SCALE_CODES 52866837 253 + #define ADE9000_WATT_FULL_SCALE_CODES 20694066 254 + #define ADE9000_PCF_FULL_SCALE_CODES 74770000 255 + 256 + /* Phase and channel definitions */ 257 + #define ADE9000_PHASE_A_NR 0 258 + #define ADE9000_PHASE_B_NR 1 259 + #define ADE9000_PHASE_C_NR 2 260 + 261 + #define ADE9000_SCAN_POS_IA BIT(0) 262 + #define ADE9000_SCAN_POS_VA BIT(1) 263 + #define ADE9000_SCAN_POS_IB BIT(2) 264 + #define ADE9000_SCAN_POS_VB BIT(3) 265 + #define ADE9000_SCAN_POS_IC BIT(4) 266 + #define ADE9000_SCAN_POS_VC BIT(5) 267 + 268 + /* Waveform buffer configuration values */ 269 + enum ade9000_wfb_cfg { 270 + ADE9000_WFB_CFG_ALL_CHAN = 0x0, 271 + ADE9000_WFB_CFG_IA_VA = 0x1, 272 + ADE9000_WFB_CFG_IB_VB = 0x2, 273 + ADE9000_WFB_CFG_IC_VC = 0x3, 274 + ADE9000_WFB_CFG_IA = 0x8, 275 + ADE9000_WFB_CFG_VA = 0x9, 276 + ADE9000_WFB_CFG_IB = 0xA, 277 + ADE9000_WFB_CFG_VB = 0xB, 278 + ADE9000_WFB_CFG_IC = 0xC, 279 + ADE9000_WFB_CFG_VC = 0xD, 280 + }; 281 + 282 + #define ADE9000_PHASE_B_POS_BIT BIT(5) 283 + #define ADE9000_PHASE_C_POS_BIT BIT(6) 284 + 285 + #define ADE9000_MAX_PHASE_NR 3 286 + #define AD9000_CHANNELS_PER_PHASE 10 287 + 288 + /* 289 + * Calculate register address for multi-phase device. 290 + * Phase A (chan 0): base address + 0x00 291 + * Phase B (chan 1): base address + 0x20 292 + * Phase C (chan 2): base address + 0x40 293 + */ 294 + #define ADE9000_ADDR_ADJUST(addr, chan) \ 295 + (((chan) == 0 ? 0 : (chan) == 1 ? 2 : 4) << 4 | (addr)) 296 + 297 + struct ade9000_state { 298 + struct completion reset_completion; 299 + struct mutex lock; /* Protects SPI transactions */ 300 + u8 wf_src; 301 + u32 wfb_trg; 302 + u8 wfb_nr_activ_chan; 303 + u32 wfb_nr_samples; 304 + struct spi_device *spi; 305 + struct clk *clkin; 306 + struct spi_transfer xfer[2]; 307 + struct spi_message spi_msg; 308 + struct regmap *regmap; 309 + union{ 310 + u8 byte[ADE9000_WFB_FULL_BUFF_SIZE]; 311 + __be32 word[ADE9000_WFB_FULL_BUFF_NR_SAMPLES]; 312 + } rx_buff __aligned(IIO_DMA_MINALIGN); 313 + u8 tx_buff[2] __aligned(IIO_DMA_MINALIGN); 314 + unsigned int bulk_read_buf[2]; 315 + }; 316 + 317 + struct ade9000_irq1_event { 318 + u32 bit_mask; 319 + enum iio_chan_type chan_type; 320 + u32 channel; 321 + enum iio_event_type event_type; 322 + enum iio_event_direction event_dir; 323 + }; 324 + 325 + static const struct ade9000_irq1_event ade9000_irq1_events[] = { 326 + { ADE9000_ST1_ZXVA_BIT, IIO_VOLTAGE, ADE9000_PHASE_A_NR, IIO_EV_TYPE_THRESH, IIO_EV_DIR_EITHER }, 327 + { ADE9000_ST1_ZXIA_BIT, IIO_CURRENT, ADE9000_PHASE_A_NR, IIO_EV_TYPE_THRESH, IIO_EV_DIR_EITHER }, 328 + { ADE9000_ST1_ZXVB_BIT, IIO_VOLTAGE, ADE9000_PHASE_B_NR, IIO_EV_TYPE_THRESH, IIO_EV_DIR_EITHER }, 329 + { ADE9000_ST1_ZXIB_BIT, IIO_CURRENT, ADE9000_PHASE_B_NR, IIO_EV_TYPE_THRESH, IIO_EV_DIR_EITHER }, 330 + { ADE9000_ST1_ZXVC_BIT, IIO_VOLTAGE, ADE9000_PHASE_C_NR, IIO_EV_TYPE_THRESH, IIO_EV_DIR_EITHER }, 331 + { ADE9000_ST1_ZXIC_BIT, IIO_CURRENT, ADE9000_PHASE_C_NR, IIO_EV_TYPE_THRESH, IIO_EV_DIR_EITHER }, 332 + { ADE9000_ST1_SWELLA_BIT, IIO_ALTVOLTAGE, ADE9000_PHASE_A_NR, IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING }, 333 + { ADE9000_ST1_SWELLB_BIT, IIO_ALTVOLTAGE, ADE9000_PHASE_B_NR, IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING }, 334 + { ADE9000_ST1_SWELLC_BIT, IIO_ALTVOLTAGE, ADE9000_PHASE_C_NR, IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING }, 335 + { ADE9000_ST1_DIPA_BIT, IIO_ALTVOLTAGE, ADE9000_PHASE_A_NR, IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING }, 336 + { ADE9000_ST1_DIPB_BIT, IIO_ALTVOLTAGE, ADE9000_PHASE_B_NR, IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING }, 337 + { ADE9000_ST1_DIPC_BIT, IIO_ALTVOLTAGE, ADE9000_PHASE_C_NR, IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING }, 338 + }; 339 + 340 + /* Voltage events (zero crossing on instantaneous voltage) */ 341 + static const struct iio_event_spec ade9000_voltage_events[] = { 342 + { 343 + /* Zero crossing detection - datasheet: ZXV interrupts */ 344 + .type = IIO_EV_TYPE_THRESH, 345 + .dir = IIO_EV_DIR_EITHER, 346 + .mask_separate = BIT(IIO_EV_INFO_ENABLE), 347 + }, 348 + }; 349 + 350 + /* Current events (zero crossing on instantaneous current) */ 351 + static const struct iio_event_spec ade9000_current_events[] = { 352 + { 353 + /* Zero crossing detection - datasheet: ZXI interrupts */ 354 + .type = IIO_EV_TYPE_THRESH, 355 + .dir = IIO_EV_DIR_EITHER, 356 + .mask_separate = BIT(IIO_EV_INFO_ENABLE), 357 + }, 358 + }; 359 + 360 + /* RMS voltage events (swell/sag detection on RMS values) */ 361 + static const struct iio_event_spec ade9000_rms_voltage_events[] = { 362 + { 363 + .type = IIO_EV_TYPE_THRESH, 364 + .dir = IIO_EV_DIR_RISING, /* RMS swell detection */ 365 + .mask_separate = BIT(IIO_EV_INFO_ENABLE) | BIT(IIO_EV_INFO_VALUE), 366 + }, 367 + { 368 + .type = IIO_EV_TYPE_THRESH, 369 + .dir = IIO_EV_DIR_FALLING, /* RMS sag/dip detection */ 370 + .mask_separate = BIT(IIO_EV_INFO_ENABLE) | BIT(IIO_EV_INFO_VALUE), 371 + }, 372 + }; 373 + 374 + static const char * const ade9000_filter_type_items[] = { 375 + "sinc4", "sinc4+lp", 376 + }; 377 + 378 + static const int ade9000_filter_type_values[] = { 379 + 0, 2, 380 + }; 381 + 382 + static int ade9000_filter_type_get(struct iio_dev *indio_dev, 383 + const struct iio_chan_spec *chan) 384 + { 385 + struct ade9000_state *st = iio_priv(indio_dev); 386 + u32 val; 387 + int ret; 388 + unsigned int i; 389 + 390 + ret = regmap_read(st->regmap, ADE9000_REG_WFB_CFG, &val); 391 + if (ret) 392 + return ret; 393 + 394 + val = FIELD_GET(ADE9000_WF_SRC_MASK, val); 395 + 396 + for (i = 0; i < ARRAY_SIZE(ade9000_filter_type_values); i++) { 397 + if (ade9000_filter_type_values[i] == val) 398 + return i; 399 + } 400 + 401 + return -EINVAL; 402 + } 403 + 404 + static int ade9000_filter_type_set(struct iio_dev *indio_dev, 405 + const struct iio_chan_spec *chan, 406 + unsigned int index) 407 + { 408 + struct ade9000_state *st = iio_priv(indio_dev); 409 + int ret, val; 410 + 411 + if (index >= ARRAY_SIZE(ade9000_filter_type_values)) 412 + return -EINVAL; 413 + 414 + val = ade9000_filter_type_values[index]; 415 + 416 + /* Update the WFB_CFG register with the new filter type */ 417 + ret = regmap_update_bits(st->regmap, ADE9000_REG_WFB_CFG, 418 + ADE9000_WF_SRC_MASK, 419 + FIELD_PREP(ADE9000_WF_SRC_MASK, val)); 420 + if (ret) 421 + return ret; 422 + 423 + /* Update cached value */ 424 + st->wf_src = val; 425 + 426 + return 0; 427 + } 428 + 429 + static const struct iio_enum ade9000_filter_type_enum = { 430 + .items = ade9000_filter_type_items, 431 + .num_items = ARRAY_SIZE(ade9000_filter_type_items), 432 + .get = ade9000_filter_type_get, 433 + .set = ade9000_filter_type_set, 434 + }; 435 + 436 + static const struct iio_chan_spec_ext_info ade9000_ext_info[] = { 437 + IIO_ENUM("filter_type", IIO_SHARED_BY_ALL, &ade9000_filter_type_enum), 438 + IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_ALL, &ade9000_filter_type_enum), 439 + { } 440 + }; 441 + 442 + #define ADE9000_CURRENT_CHANNEL(num) { \ 443 + .type = IIO_CURRENT, \ 444 + .channel = num, \ 445 + .address = ADE9000_ADDR_ADJUST(ADE9000_REG_AI_PCF, num), \ 446 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 447 + BIT(IIO_CHAN_INFO_SCALE) | \ 448 + BIT(IIO_CHAN_INFO_CALIBSCALE), \ 449 + .event_spec = ade9000_current_events, \ 450 + .num_event_specs = ARRAY_SIZE(ade9000_current_events), \ 451 + .scan_index = num, \ 452 + .indexed = 1, \ 453 + .scan_type = { \ 454 + .sign = 's', \ 455 + .realbits = 32, \ 456 + .storagebits = 32, \ 457 + .endianness = IIO_BE, \ 458 + }, \ 459 + } 460 + 461 + #define ADE9000_VOLTAGE_CHANNEL(num) { \ 462 + .type = IIO_VOLTAGE, \ 463 + .channel = num, \ 464 + .address = ADE9000_ADDR_ADJUST(ADE9000_REG_AV_PCF, num), \ 465 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 466 + BIT(IIO_CHAN_INFO_SCALE) | \ 467 + BIT(IIO_CHAN_INFO_CALIBSCALE) | \ 468 + BIT(IIO_CHAN_INFO_FREQUENCY), \ 469 + .event_spec = ade9000_voltage_events, \ 470 + .num_event_specs = ARRAY_SIZE(ade9000_voltage_events), \ 471 + .scan_index = num + 1, /* interleave with current channels */ \ 472 + .indexed = 1, \ 473 + .scan_type = { \ 474 + .sign = 's', \ 475 + .realbits = 32, \ 476 + .storagebits = 32, \ 477 + .endianness = IIO_BE, \ 478 + }, \ 479 + .ext_info = ade9000_ext_info, \ 480 + } 481 + 482 + #define ADE9000_ALTCURRENT_RMS_CHANNEL(num) { \ 483 + .type = IIO_ALTCURRENT, \ 484 + .channel = num, \ 485 + .address = ADE9000_ADDR_ADJUST(ADE9000_REG_AIRMS, num), \ 486 + .channel2 = IIO_MOD_RMS, \ 487 + .modified = 1, \ 488 + .indexed = 1, \ 489 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 490 + BIT(IIO_CHAN_INFO_SCALE) | \ 491 + BIT(IIO_CHAN_INFO_CALIBBIAS), \ 492 + .scan_index = -1 \ 493 + } 494 + 495 + #define ADE9000_ALTVOLTAGE_RMS_CHANNEL(num) { \ 496 + .type = IIO_ALTVOLTAGE, \ 497 + .channel = num, \ 498 + .address = ADE9000_ADDR_ADJUST(ADE9000_REG_AVRMS, num), \ 499 + .channel2 = IIO_MOD_RMS, \ 500 + .modified = 1, \ 501 + .indexed = 1, \ 502 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 503 + BIT(IIO_CHAN_INFO_SCALE) | \ 504 + BIT(IIO_CHAN_INFO_CALIBBIAS), \ 505 + .event_spec = ade9000_rms_voltage_events, \ 506 + .num_event_specs = ARRAY_SIZE(ade9000_rms_voltage_events), \ 507 + .scan_index = -1 \ 508 + } 509 + 510 + #define ADE9000_POWER_ACTIVE_CHANNEL(num) { \ 511 + .type = IIO_POWER, \ 512 + .channel = num, \ 513 + .address = ADE9000_ADDR_ADJUST(ADE9000_REG_AWATT, num), \ 514 + .channel2 = IIO_MOD_ACTIVE, \ 515 + .modified = 1, \ 516 + .indexed = 1, \ 517 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 518 + BIT(IIO_CHAN_INFO_SCALE) | \ 519 + BIT(IIO_CHAN_INFO_CALIBBIAS) | \ 520 + BIT(IIO_CHAN_INFO_CALIBSCALE), \ 521 + .scan_index = -1 \ 522 + } 523 + 524 + #define ADE9000_POWER_REACTIVE_CHANNEL(num) { \ 525 + .type = IIO_POWER, \ 526 + .channel = num, \ 527 + .address = ADE9000_ADDR_ADJUST(ADE9000_REG_AVAR, num), \ 528 + .channel2 = IIO_MOD_REACTIVE, \ 529 + .modified = 1, \ 530 + .indexed = 1, \ 531 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 532 + BIT(IIO_CHAN_INFO_SCALE) | \ 533 + BIT(IIO_CHAN_INFO_CALIBBIAS), \ 534 + .scan_index = -1 \ 535 + } 536 + 537 + #define ADE9000_POWER_APPARENT_CHANNEL(num) { \ 538 + .type = IIO_POWER, \ 539 + .channel = num, \ 540 + .address = ADE9000_ADDR_ADJUST(ADE9000_REG_AVA, num), \ 541 + .channel2 = IIO_MOD_APPARENT, \ 542 + .modified = 1, \ 543 + .indexed = 1, \ 544 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 545 + BIT(IIO_CHAN_INFO_SCALE), \ 546 + .scan_index = -1 \ 547 + } 548 + 549 + #define ADE9000_ENERGY_ACTIVE_CHANNEL(num, addr) { \ 550 + .type = IIO_ENERGY, \ 551 + .channel = num, \ 552 + .address = addr, \ 553 + .channel2 = IIO_MOD_ACTIVE, \ 554 + .modified = 1, \ 555 + .indexed = 1, \ 556 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 557 + .scan_index = -1 \ 558 + } 559 + 560 + #define ADE9000_ENERGY_APPARENT_CHANNEL(num, addr) { \ 561 + .type = IIO_ENERGY, \ 562 + .channel = num, \ 563 + .address = addr, \ 564 + .channel2 = IIO_MOD_APPARENT, \ 565 + .modified = 1, \ 566 + .indexed = 1, \ 567 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 568 + .scan_index = -1 \ 569 + } 570 + 571 + #define ADE9000_ENERGY_REACTIVE_CHANNEL(num, addr) { \ 572 + .type = IIO_ENERGY, \ 573 + .channel = num, \ 574 + .address = addr, \ 575 + .channel2 = IIO_MOD_REACTIVE, \ 576 + .modified = 1, \ 577 + .indexed = 1, \ 578 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 579 + .scan_index = -1 \ 580 + } 581 + 582 + #define ADE9000_POWER_FACTOR_CHANNEL(num) { \ 583 + .type = IIO_POWER, \ 584 + .channel = num, \ 585 + .address = ADE9000_ADDR_ADJUST(ADE9000_REG_APF, num), \ 586 + .indexed = 1, \ 587 + .info_mask_separate = BIT(IIO_CHAN_INFO_POWERFACTOR), \ 588 + .scan_index = -1 \ 589 + } 590 + 591 + static const struct iio_chan_spec ade9000_channels[] = { 592 + /* Phase A channels */ 593 + ADE9000_CURRENT_CHANNEL(ADE9000_PHASE_A_NR), 594 + ADE9000_VOLTAGE_CHANNEL(ADE9000_PHASE_A_NR), 595 + ADE9000_ALTCURRENT_RMS_CHANNEL(ADE9000_PHASE_A_NR), 596 + ADE9000_ALTVOLTAGE_RMS_CHANNEL(ADE9000_PHASE_A_NR), 597 + ADE9000_POWER_ACTIVE_CHANNEL(ADE9000_PHASE_A_NR), 598 + ADE9000_POWER_REACTIVE_CHANNEL(ADE9000_PHASE_A_NR), 599 + ADE9000_POWER_APPARENT_CHANNEL(ADE9000_PHASE_A_NR), 600 + ADE9000_ENERGY_ACTIVE_CHANNEL(ADE9000_PHASE_A_NR, ADE9000_REG_AWATTHR_LO), 601 + ADE9000_ENERGY_APPARENT_CHANNEL(ADE9000_PHASE_A_NR, ADE9000_REG_AVAHR_LO), 602 + ADE9000_ENERGY_REACTIVE_CHANNEL(ADE9000_PHASE_A_NR, ADE9000_REG_AFVARHR_LO), 603 + ADE9000_POWER_FACTOR_CHANNEL(ADE9000_PHASE_A_NR), 604 + /* Phase B channels */ 605 + ADE9000_CURRENT_CHANNEL(ADE9000_PHASE_B_NR), 606 + ADE9000_VOLTAGE_CHANNEL(ADE9000_PHASE_B_NR), 607 + ADE9000_ALTCURRENT_RMS_CHANNEL(ADE9000_PHASE_B_NR), 608 + ADE9000_ALTVOLTAGE_RMS_CHANNEL(ADE9000_PHASE_B_NR), 609 + ADE9000_POWER_ACTIVE_CHANNEL(ADE9000_PHASE_B_NR), 610 + ADE9000_POWER_REACTIVE_CHANNEL(ADE9000_PHASE_B_NR), 611 + ADE9000_POWER_APPARENT_CHANNEL(ADE9000_PHASE_B_NR), 612 + ADE9000_ENERGY_ACTIVE_CHANNEL(ADE9000_PHASE_B_NR, ADE9000_REG_BWATTHR_LO), 613 + ADE9000_ENERGY_APPARENT_CHANNEL(ADE9000_PHASE_B_NR, ADE9000_REG_BVAHR_LO), 614 + ADE9000_ENERGY_REACTIVE_CHANNEL(ADE9000_PHASE_B_NR, ADE9000_REG_BFVARHR_LO), 615 + ADE9000_POWER_FACTOR_CHANNEL(ADE9000_PHASE_B_NR), 616 + /* Phase C channels */ 617 + ADE9000_CURRENT_CHANNEL(ADE9000_PHASE_C_NR), 618 + ADE9000_VOLTAGE_CHANNEL(ADE9000_PHASE_C_NR), 619 + ADE9000_ALTCURRENT_RMS_CHANNEL(ADE9000_PHASE_C_NR), 620 + ADE9000_ALTVOLTAGE_RMS_CHANNEL(ADE9000_PHASE_C_NR), 621 + ADE9000_POWER_ACTIVE_CHANNEL(ADE9000_PHASE_C_NR), 622 + ADE9000_POWER_REACTIVE_CHANNEL(ADE9000_PHASE_C_NR), 623 + ADE9000_POWER_APPARENT_CHANNEL(ADE9000_PHASE_C_NR), 624 + ADE9000_ENERGY_ACTIVE_CHANNEL(ADE9000_PHASE_C_NR, ADE9000_REG_CWATTHR_LO), 625 + ADE9000_ENERGY_APPARENT_CHANNEL(ADE9000_PHASE_C_NR, ADE9000_REG_CVAHR_LO), 626 + ADE9000_ENERGY_REACTIVE_CHANNEL(ADE9000_PHASE_C_NR, ADE9000_REG_CFVARHR_LO), 627 + ADE9000_POWER_FACTOR_CHANNEL(ADE9000_PHASE_C_NR), 628 + }; 629 + 630 + static const struct reg_sequence ade9000_initialization_sequence[] = { 631 + { ADE9000_REG_PGA_GAIN, ADE9000_PGA_GAIN }, 632 + { ADE9000_REG_CONFIG0, ADE9000_CONFIG0 }, 633 + { ADE9000_REG_CONFIG1, ADE9000_CONFIG1 }, 634 + { ADE9000_REG_CONFIG2, ADE9000_CONFIG2 }, 635 + { ADE9000_REG_CONFIG3, ADE9000_CONFIG3 }, 636 + { ADE9000_REG_ACCMODE, ADE9000_ACCMODE }, 637 + { ADE9000_REG_ZX_LP_SEL, ADE9000_ZX_LP_SEL }, 638 + { ADE9000_REG_MASK0, ADE9000_MASK0_ALL_INT_DIS }, 639 + { ADE9000_REG_MASK1, ADE9000_MASK1_ALL_INT_DIS }, 640 + { ADE9000_REG_EVENT_MASK, ADE9000_EVENT_DISABLE }, 641 + { ADE9000_REG_WFB_CFG, ADE9000_WFB_CFG }, 642 + { ADE9000_REG_VLEVEL, ADE9000_VLEVEL }, 643 + { ADE9000_REG_DICOEFF, ADE9000_DICOEFF }, 644 + { ADE9000_REG_EGY_TIME, ADE9000_EGY_TIME }, 645 + { ADE9000_REG_EP_CFG, ADE9000_EP_CFG }, 646 + /* Clear all pending status bits by writing 1s */ 647 + { ADE9000_REG_STATUS0, GENMASK(31, 0) }, 648 + { ADE9000_REG_STATUS1, GENMASK(31, 0) }, 649 + { ADE9000_REG_RUN, ADE9000_RUN_ON } 650 + }; 651 + 652 + static int ade9000_spi_write_reg(void *context, unsigned int reg, 653 + unsigned int val) 654 + { 655 + struct ade9000_state *st = context; 656 + u8 tx_buf[6]; 657 + u16 addr; 658 + int ret, len; 659 + 660 + guard(mutex)(&st->lock); 661 + 662 + addr = FIELD_PREP(ADE9000_REG_ADDR_MASK, reg); 663 + put_unaligned_be16(addr, tx_buf); 664 + 665 + if (reg > ADE9000_REG_RUN && reg < ADE9000_REG_VERSION) { 666 + put_unaligned_be16(val, &tx_buf[2]); 667 + len = 4; 668 + } else { 669 + put_unaligned_be32(val, &tx_buf[2]); 670 + len = 6; 671 + } 672 + 673 + ret = spi_write_then_read(st->spi, tx_buf, len, NULL, 0); 674 + if (ret) 675 + dev_err(&st->spi->dev, "problem when writing register 0x%x\n", reg); 676 + 677 + return ret; 678 + } 679 + 680 + static int ade9000_spi_read_reg(void *context, unsigned int reg, 681 + unsigned int *val) 682 + { 683 + struct ade9000_state *st = context; 684 + u8 tx_buf[2]; 685 + u8 rx_buf[4]; 686 + u16 addr; 687 + int ret, rx_len; 688 + 689 + guard(mutex)(&st->lock); 690 + 691 + addr = FIELD_PREP(ADE9000_REG_ADDR_MASK, reg) | 692 + ADE9000_REG_READ_BIT_MASK; 693 + 694 + put_unaligned_be16(addr, tx_buf); 695 + 696 + /* Skip CRC bytes - only read actual data */ 697 + if (reg > ADE9000_REG_RUN && reg < ADE9000_REG_VERSION) 698 + rx_len = 2; 699 + else 700 + rx_len = 4; 701 + 702 + ret = spi_write_then_read(st->spi, tx_buf, 2, rx_buf, rx_len); 703 + if (ret) { 704 + dev_err(&st->spi->dev, "error reading register 0x%x\n", reg); 705 + return ret; 706 + } 707 + 708 + if (reg > ADE9000_REG_RUN && reg < ADE9000_REG_VERSION) 709 + *val = get_unaligned_be16(rx_buf); 710 + else 711 + *val = get_unaligned_be32(rx_buf); 712 + 713 + return 0; 714 + } 715 + 716 + static bool ade9000_is_volatile_reg(struct device *dev, unsigned int reg) 717 + { 718 + switch (reg) { 719 + /* Interrupt/error status registers - volatile */ 720 + case ADE9000_REG_STATUS0: 721 + case ADE9000_REG_STATUS1: 722 + return true; 723 + default: 724 + /* All other registers are non-volatile */ 725 + return false; 726 + } 727 + } 728 + 729 + static void ade9000_configure_scan(struct iio_dev *indio_dev, u32 wfb_addr) 730 + { 731 + struct ade9000_state *st = iio_priv(indio_dev); 732 + u16 addr; 733 + 734 + addr = FIELD_PREP(ADE9000_REG_ADDR_MASK, wfb_addr) | 735 + ADE9000_REG_READ_BIT_MASK; 736 + 737 + put_unaligned_be16(addr, st->tx_buff); 738 + 739 + st->xfer[0].tx_buf = &st->tx_buff[0]; 740 + st->xfer[0].len = 2; 741 + 742 + st->xfer[1].rx_buf = st->rx_buff.byte; 743 + 744 + /* Always use streaming mode */ 745 + st->xfer[1].len = (st->wfb_nr_samples / 2) * 4; 746 + 747 + spi_message_init_with_transfers(&st->spi_msg, st->xfer, ARRAY_SIZE(st->xfer)); 748 + } 749 + 750 + static int ade9000_iio_push_streaming(struct iio_dev *indio_dev) 751 + { 752 + struct ade9000_state *st = iio_priv(indio_dev); 753 + struct device *dev = &st->spi->dev; 754 + u32 current_page, i; 755 + int ret; 756 + 757 + guard(mutex)(&st->lock); 758 + 759 + ret = spi_sync(st->spi, &st->spi_msg); 760 + if (ret) { 761 + dev_err_ratelimited(dev, "SPI fail in trigger handler\n"); 762 + return ret; 763 + } 764 + 765 + /* In streaming mode, only half the buffer is filled per interrupt */ 766 + for (i = 0; i < st->wfb_nr_samples / 2; i += st->wfb_nr_activ_chan) 767 + iio_push_to_buffers(indio_dev, &st->rx_buff.word[i]); 768 + 769 + ret = regmap_read(st->regmap, ADE9000_REG_WFB_PG_IRQEN, &current_page); 770 + if (ret) { 771 + dev_err_ratelimited(dev, "IRQ0 WFB read fail\n"); 772 + return ret; 773 + } 774 + 775 + if (current_page & ADE9000_MIDDLE_PAGE_BIT) { 776 + ret = regmap_write(st->regmap, ADE9000_REG_WFB_PG_IRQEN, 777 + ADE9000_LAST_PAGE_BIT); 778 + if (ret) { 779 + dev_err_ratelimited(dev, "IRQ0 WFB write fail\n"); 780 + return ret; 781 + } 782 + 783 + ade9000_configure_scan(indio_dev, 784 + ADE9000_REG_WF_HALF_BUFF); 785 + } else { 786 + ret = regmap_write(st->regmap, ADE9000_REG_WFB_PG_IRQEN, 787 + ADE9000_MIDDLE_PAGE_BIT); 788 + if (ret) { 789 + dev_err_ratelimited(dev, "IRQ0 WFB write fail"); 790 + return IRQ_HANDLED; 791 + } 792 + 793 + ade9000_configure_scan(indio_dev, ADE9000_REG_WF_BUFF); 794 + } 795 + 796 + return 0; 797 + } 798 + 799 + static int ade9000_iio_push_buffer(struct iio_dev *indio_dev) 800 + { 801 + struct ade9000_state *st = iio_priv(indio_dev); 802 + int ret; 803 + u32 i; 804 + 805 + guard(mutex)(&st->lock); 806 + 807 + ret = spi_sync(st->spi, &st->spi_msg); 808 + if (ret) { 809 + dev_err_ratelimited(&st->spi->dev, 810 + "SPI fail in trigger handler\n"); 811 + return ret; 812 + } 813 + 814 + for (i = 0; i < st->wfb_nr_samples; i += st->wfb_nr_activ_chan) 815 + iio_push_to_buffers(indio_dev, &st->rx_buff.word[i]); 816 + 817 + return 0; 818 + } 819 + 820 + static irqreturn_t ade9000_irq0_thread(int irq, void *data) 821 + { 822 + struct iio_dev *indio_dev = data; 823 + struct ade9000_state *st = iio_priv(indio_dev); 824 + struct device *dev = &st->spi->dev; 825 + u32 handled_irq = 0; 826 + u32 interrupts, status; 827 + int ret; 828 + 829 + ret = regmap_read(st->regmap, ADE9000_REG_STATUS0, &status); 830 + if (ret) { 831 + dev_err_ratelimited(dev, "IRQ0 read status fail\n"); 832 + return IRQ_HANDLED; 833 + } 834 + 835 + ret = regmap_read(st->regmap, ADE9000_REG_MASK0, &interrupts); 836 + if (ret) { 837 + dev_err_ratelimited(dev, "IRQ0 read mask fail\n"); 838 + return IRQ_HANDLED; 839 + } 840 + 841 + if ((status & ADE9000_ST0_PAGE_FULL_BIT) && 842 + (interrupts & ADE9000_ST0_PAGE_FULL_BIT)) { 843 + /* Always use streaming mode */ 844 + ret = ade9000_iio_push_streaming(indio_dev); 845 + if (ret) { 846 + dev_err_ratelimited(dev, "IRQ0 IIO push fail\n"); 847 + return IRQ_HANDLED; 848 + } 849 + 850 + handled_irq |= ADE9000_ST0_PAGE_FULL_BIT; 851 + } 852 + 853 + if ((status & ADE9000_ST0_WFB_TRIG_BIT) && 854 + (interrupts & ADE9000_ST0_WFB_TRIG_BIT)) { 855 + ret = regmap_update_bits(st->regmap, ADE9000_REG_WFB_CFG, 856 + ADE9000_WF_CAP_EN_MASK, 0); 857 + if (ret) { 858 + dev_err_ratelimited(dev, "IRQ0 WFB fail\n"); 859 + return IRQ_HANDLED; 860 + } 861 + 862 + if (iio_buffer_enabled(indio_dev)) { 863 + ret = ade9000_iio_push_buffer(indio_dev); 864 + if (ret) { 865 + dev_err_ratelimited(dev, 866 + "IRQ0 IIO push fail @ WFB TRIG\n"); 867 + return IRQ_HANDLED; 868 + } 869 + } 870 + 871 + handled_irq |= ADE9000_ST0_WFB_TRIG_BIT; 872 + } 873 + 874 + ret = regmap_write(st->regmap, ADE9000_REG_STATUS0, handled_irq); 875 + if (ret) 876 + dev_err_ratelimited(dev, "IRQ0 write status fail\n"); 877 + 878 + return IRQ_HANDLED; 879 + } 880 + 881 + static irqreturn_t ade9000_irq1_thread(int irq, void *data) 882 + { 883 + struct iio_dev *indio_dev = data; 884 + struct ade9000_state *st = iio_priv(indio_dev); 885 + unsigned int bit = ADE9000_ST1_CROSSING_FIRST; 886 + s64 timestamp = iio_get_time_ns(indio_dev); 887 + u32 handled_irq = 0; 888 + u32 interrupts, result, status, tmp; 889 + DECLARE_BITMAP(interrupt_bits, ADE9000_ST1_CROSSING_DEPTH); 890 + const struct ade9000_irq1_event *event; 891 + int ret, i; 892 + 893 + if (!completion_done(&st->reset_completion)) { 894 + ret = regmap_read(st->regmap, ADE9000_REG_STATUS1, &result); 895 + if (ret) { 896 + dev_err_ratelimited(&st->spi->dev, "IRQ1 read status fail\n"); 897 + return IRQ_HANDLED; 898 + } 899 + 900 + if (result & ADE9000_ST1_RSTDONE_BIT) { 901 + complete(&st->reset_completion); 902 + /* Clear the reset done status bit */ 903 + ret = regmap_write(st->regmap, ADE9000_REG_STATUS1, ADE9000_ST1_RSTDONE_BIT); 904 + if (ret) 905 + dev_err_ratelimited(&st->spi->dev, 906 + "IRQ1 clear reset status fail\n"); 907 + } else { 908 + dev_err_ratelimited(&st->spi->dev, 909 + "Error testing reset done\n"); 910 + } 911 + 912 + return IRQ_HANDLED; 913 + } 914 + 915 + ret = regmap_read(st->regmap, ADE9000_REG_STATUS1, &status); 916 + if (ret) { 917 + dev_err_ratelimited(&st->spi->dev, "IRQ1 read status fail\n"); 918 + return IRQ_HANDLED; 919 + } 920 + 921 + ret = regmap_read(st->regmap, ADE9000_REG_MASK1, &interrupts); 922 + if (ret) { 923 + dev_err_ratelimited(&st->spi->dev, "IRQ1 read mask fail\n"); 924 + return IRQ_HANDLED; 925 + } 926 + 927 + bitmap_from_arr32(interrupt_bits, &interrupts, ADE9000_ST1_CROSSING_DEPTH); 928 + for_each_set_bit_from(bit, interrupt_bits, 929 + ADE9000_ST1_CROSSING_DEPTH) { 930 + tmp = status & BIT(bit); 931 + if (!tmp) 932 + continue; 933 + 934 + event = NULL; 935 + 936 + /* Find corresponding event in lookup table */ 937 + for (i = 0; i < ARRAY_SIZE(ade9000_irq1_events); i++) { 938 + if (ade9000_irq1_events[i].bit_mask == tmp) { 939 + event = &ade9000_irq1_events[i]; 940 + break; 941 + } 942 + } 943 + 944 + if (event) { 945 + iio_push_event(indio_dev, 946 + IIO_UNMOD_EVENT_CODE(event->chan_type, 947 + event->channel, 948 + event->event_type, 949 + event->event_dir), 950 + timestamp); 951 + } 952 + handled_irq |= tmp; 953 + } 954 + 955 + ret = regmap_write(st->regmap, ADE9000_REG_STATUS1, handled_irq); 956 + if (ret) 957 + dev_err_ratelimited(&st->spi->dev, "IRQ1 write status fail\n"); 958 + 959 + return IRQ_HANDLED; 960 + } 961 + 962 + static irqreturn_t ade9000_dready_thread(int irq, void *data) 963 + { 964 + struct iio_dev *indio_dev = data; 965 + 966 + /* Handle data ready interrupt from C4/EVENT/DREADY pin */ 967 + if (!iio_device_claim_buffer_mode(indio_dev)) { 968 + ade9000_iio_push_buffer(indio_dev); 969 + iio_device_release_buffer_mode(indio_dev); 970 + } 971 + 972 + return IRQ_HANDLED; 973 + } 974 + 975 + static int ade9000_read_raw(struct iio_dev *indio_dev, 976 + struct iio_chan_spec const *chan, 977 + int *val, 978 + int *val2, 979 + long mask) 980 + { 981 + struct ade9000_state *st = iio_priv(indio_dev); 982 + unsigned int measured; 983 + int ret; 984 + 985 + switch (mask) { 986 + case IIO_CHAN_INFO_FREQUENCY: 987 + if (chan->type == IIO_VOLTAGE) { 988 + int period_reg; 989 + int period; 990 + 991 + switch (chan->channel) { 992 + case ADE9000_PHASE_A_NR: 993 + period_reg = ADE9000_REG_APERIOD; 994 + break; 995 + case ADE9000_PHASE_B_NR: 996 + period_reg = ADE9000_REG_BPERIOD; 997 + break; 998 + case ADE9000_PHASE_C_NR: 999 + period_reg = ADE9000_REG_CPERIOD; 1000 + break; 1001 + default: 1002 + return -EINVAL; 1003 + } 1004 + ret = regmap_read(st->regmap, period_reg, &period); 1005 + if (ret) 1006 + return ret; 1007 + /* 1008 + * Frequency = (4MHz * 65536) / (PERIOD + 1) 1009 + * 4MHz = ADC sample rate, 65536 = 2^16 period register scaling 1010 + * See ADE9000 datasheet section on period measurement 1011 + */ 1012 + *val = 4000 * 65536; 1013 + *val2 = period + 1; 1014 + return IIO_VAL_FRACTIONAL; 1015 + } 1016 + 1017 + return -EINVAL; 1018 + case IIO_CHAN_INFO_RAW: 1019 + if (chan->type == IIO_ENERGY) { 1020 + u16 lo_reg = chan->address; 1021 + 1022 + ret = regmap_bulk_read(st->regmap, lo_reg, 1023 + st->bulk_read_buf, 2); 1024 + if (ret) 1025 + return ret; 1026 + 1027 + *val = st->bulk_read_buf[0]; /* Lower 32 bits */ 1028 + *val2 = st->bulk_read_buf[1]; /* Upper 32 bits */ 1029 + return IIO_VAL_INT_64; 1030 + } 1031 + 1032 + if (!iio_device_claim_direct(indio_dev)) 1033 + return -EBUSY; 1034 + 1035 + ret = regmap_read(st->regmap, chan->address, &measured); 1036 + iio_device_release_direct(indio_dev); 1037 + if (ret) 1038 + return ret; 1039 + 1040 + *val = measured; 1041 + 1042 + return IIO_VAL_INT; 1043 + 1044 + case IIO_CHAN_INFO_POWERFACTOR: 1045 + if (!iio_device_claim_direct(indio_dev)) 1046 + return -EBUSY; 1047 + 1048 + ret = regmap_read(st->regmap, chan->address, &measured); 1049 + iio_device_release_direct(indio_dev); 1050 + if (ret) 1051 + return ret; 1052 + 1053 + *val = measured; 1054 + 1055 + return IIO_VAL_INT; 1056 + 1057 + case IIO_CHAN_INFO_SCALE: 1058 + switch (chan->type) { 1059 + case IIO_CURRENT: 1060 + case IIO_VOLTAGE: 1061 + case IIO_ALTVOLTAGE: 1062 + case IIO_ALTCURRENT: 1063 + switch (chan->address) { 1064 + case ADE9000_REG_AI_PCF: 1065 + case ADE9000_REG_AV_PCF: 1066 + case ADE9000_REG_BI_PCF: 1067 + case ADE9000_REG_BV_PCF: 1068 + case ADE9000_REG_CI_PCF: 1069 + case ADE9000_REG_CV_PCF: 1070 + *val = 1; 1071 + *val2 = ADE9000_PCF_FULL_SCALE_CODES; 1072 + return IIO_VAL_FRACTIONAL; 1073 + case ADE9000_REG_AIRMS: 1074 + case ADE9000_REG_AVRMS: 1075 + case ADE9000_REG_BIRMS: 1076 + case ADE9000_REG_BVRMS: 1077 + case ADE9000_REG_CIRMS: 1078 + case ADE9000_REG_CVRMS: 1079 + *val = 1; 1080 + *val2 = ADE9000_RMS_FULL_SCALE_CODES; 1081 + return IIO_VAL_FRACTIONAL; 1082 + default: 1083 + return -EINVAL; 1084 + } 1085 + case IIO_POWER: 1086 + *val = 1; 1087 + *val2 = ADE9000_WATT_FULL_SCALE_CODES; 1088 + return IIO_VAL_FRACTIONAL; 1089 + default: 1090 + break; 1091 + } 1092 + 1093 + return -EINVAL; 1094 + default: 1095 + return -EINVAL; 1096 + } 1097 + } 1098 + 1099 + static int ade9000_write_raw(struct iio_dev *indio_dev, 1100 + struct iio_chan_spec const *chan, 1101 + int val, 1102 + int val2, 1103 + long mask) 1104 + { 1105 + struct ade9000_state *st = iio_priv(indio_dev); 1106 + u32 tmp; 1107 + 1108 + switch (mask) { 1109 + case IIO_CHAN_INFO_CALIBBIAS: 1110 + switch (chan->type) { 1111 + case IIO_CURRENT: 1112 + return regmap_write(st->regmap, 1113 + ADE9000_ADDR_ADJUST(ADE9000_REG_AIRMSOS, 1114 + chan->channel), val); 1115 + case IIO_VOLTAGE: 1116 + case IIO_ALTVOLTAGE: 1117 + return regmap_write(st->regmap, 1118 + ADE9000_ADDR_ADJUST(ADE9000_REG_AVRMSOS, 1119 + chan->channel), val); 1120 + case IIO_POWER: 1121 + tmp = chan->address; 1122 + tmp &= ~ADE9000_PHASE_B_POS_BIT; 1123 + tmp &= ~ADE9000_PHASE_C_POS_BIT; 1124 + 1125 + switch (tmp) { 1126 + case ADE9000_REG_AWATTOS: 1127 + return regmap_write(st->regmap, 1128 + ADE9000_ADDR_ADJUST(ADE9000_REG_AWATTOS, 1129 + chan->channel), val); 1130 + case ADE9000_REG_AVAR: 1131 + return regmap_write(st->regmap, 1132 + ADE9000_ADDR_ADJUST(ADE9000_REG_AVAROS, 1133 + chan->channel), val); 1134 + case ADE9000_REG_AFVAR: 1135 + return regmap_write(st->regmap, 1136 + ADE9000_ADDR_ADJUST(ADE9000_REG_AFVAROS, 1137 + chan->channel), val); 1138 + default: 1139 + return -EINVAL; 1140 + } 1141 + default: 1142 + return -EINVAL; 1143 + } 1144 + case IIO_CHAN_INFO_CALIBSCALE: 1145 + /* 1146 + * Calibration gain registers for fine-tuning measurements. 1147 + * These are separate from PGA gain and applied in the digital domain. 1148 + */ 1149 + switch (chan->type) { 1150 + case IIO_CURRENT: 1151 + return regmap_write(st->regmap, 1152 + ADE9000_ADDR_ADJUST(ADE9000_REG_AIGAIN, 1153 + chan->channel), val); 1154 + case IIO_VOLTAGE: 1155 + return regmap_write(st->regmap, 1156 + ADE9000_ADDR_ADJUST(ADE9000_REG_AVGAIN, 1157 + chan->channel), val); 1158 + case IIO_POWER: 1159 + return regmap_write(st->regmap, 1160 + ADE9000_ADDR_ADJUST(ADE9000_REG_APGAIN, 1161 + chan->channel), val); 1162 + default: 1163 + return -EINVAL; 1164 + } 1165 + case IIO_CHAN_INFO_SCALE: 1166 + /* Per-channel scales are read-only */ 1167 + return -EINVAL; 1168 + default: 1169 + return -EINVAL; 1170 + } 1171 + } 1172 + 1173 + static int ade9000_reg_access(struct iio_dev *indio_dev, 1174 + unsigned int reg, 1175 + unsigned int tx_val, 1176 + unsigned int *rx_val) 1177 + { 1178 + struct ade9000_state *st = iio_priv(indio_dev); 1179 + 1180 + if (rx_val) 1181 + return regmap_read(st->regmap, reg, rx_val); 1182 + 1183 + return regmap_write(st->regmap, reg, tx_val); 1184 + } 1185 + 1186 + static int ade9000_read_event_config(struct iio_dev *indio_dev, 1187 + const struct iio_chan_spec *chan, 1188 + enum iio_event_type type, 1189 + enum iio_event_direction dir) 1190 + { 1191 + struct ade9000_state *st = iio_priv(indio_dev); 1192 + u32 interrupts1; 1193 + int ret; 1194 + 1195 + /* All events use MASK1 register */ 1196 + ret = regmap_read(st->regmap, ADE9000_REG_MASK1, &interrupts1); 1197 + if (ret) 1198 + return ret; 1199 + 1200 + switch (chan->channel) { 1201 + case ADE9000_PHASE_A_NR: 1202 + if (chan->type == IIO_VOLTAGE && dir == IIO_EV_DIR_EITHER) 1203 + return !!(interrupts1 & ADE9000_ST1_ZXVA_BIT); 1204 + else if (chan->type == IIO_CURRENT && dir == IIO_EV_DIR_EITHER) 1205 + return !!(interrupts1 & ADE9000_ST1_ZXIA_BIT); 1206 + else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_RISING) 1207 + return !!(interrupts1 & ADE9000_ST1_SWELLA_BIT); 1208 + else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_FALLING) 1209 + return !!(interrupts1 & ADE9000_ST1_DIPA_BIT); 1210 + dev_err_ratelimited(&indio_dev->dev, 1211 + "Invalid channel type %d or direction %d for phase A\n", chan->type, dir); 1212 + return -EINVAL; 1213 + case ADE9000_PHASE_B_NR: 1214 + if (chan->type == IIO_VOLTAGE && dir == IIO_EV_DIR_EITHER) 1215 + return !!(interrupts1 & ADE9000_ST1_ZXVB_BIT); 1216 + else if (chan->type == IIO_CURRENT && dir == IIO_EV_DIR_EITHER) 1217 + return !!(interrupts1 & ADE9000_ST1_ZXIB_BIT); 1218 + else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_RISING) 1219 + return !!(interrupts1 & ADE9000_ST1_SWELLB_BIT); 1220 + else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_FALLING) 1221 + return !!(interrupts1 & ADE9000_ST1_DIPB_BIT); 1222 + dev_err_ratelimited(&indio_dev->dev, 1223 + "Invalid channel type %d or direction %d for phase B\n", chan->type, dir); 1224 + return -EINVAL; 1225 + case ADE9000_PHASE_C_NR: 1226 + if (chan->type == IIO_VOLTAGE && dir == IIO_EV_DIR_EITHER) 1227 + return !!(interrupts1 & ADE9000_ST1_ZXVC_BIT); 1228 + else if (chan->type == IIO_CURRENT && dir == IIO_EV_DIR_EITHER) 1229 + return !!(interrupts1 & ADE9000_ST1_ZXIC_BIT); 1230 + else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_RISING) 1231 + return !!(interrupts1 & ADE9000_ST1_SWELLC_BIT); 1232 + else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_FALLING) 1233 + return !!(interrupts1 & ADE9000_ST1_DIPC_BIT); 1234 + dev_err_ratelimited(&indio_dev->dev, 1235 + "Invalid channel type %d or direction %d for phase C\n", chan->type, dir); 1236 + return -EINVAL; 1237 + default: 1238 + return -EINVAL; 1239 + } 1240 + } 1241 + 1242 + static int ade9000_write_event_config(struct iio_dev *indio_dev, 1243 + const struct iio_chan_spec *chan, 1244 + enum iio_event_type type, 1245 + enum iio_event_direction dir, 1246 + bool state) 1247 + { 1248 + struct ade9000_state *st = iio_priv(indio_dev); 1249 + u32 bit_mask; 1250 + int ret; 1251 + 1252 + /* Clear all pending events in STATUS1 register (write 1 to clear) */ 1253 + ret = regmap_write(st->regmap, ADE9000_REG_STATUS1, GENMASK(31, 0)); 1254 + if (ret) 1255 + return ret; 1256 + 1257 + /* Determine which interrupt bit to enable/disable */ 1258 + switch (chan->channel) { 1259 + case ADE9000_PHASE_A_NR: 1260 + if (chan->type == IIO_VOLTAGE && dir == IIO_EV_DIR_EITHER) { 1261 + bit_mask = ADE9000_ST1_ZXVA_BIT; 1262 + if (state) 1263 + st->wfb_trg |= ADE9000_WFB_TRG_ZXVA_BIT; 1264 + else 1265 + st->wfb_trg &= ~ADE9000_WFB_TRG_ZXVA_BIT; 1266 + } else if (chan->type == IIO_CURRENT && dir == IIO_EV_DIR_EITHER) { 1267 + bit_mask = ADE9000_ST1_ZXIA_BIT; 1268 + if (state) 1269 + st->wfb_trg |= ADE9000_WFB_TRG_ZXIA_BIT; 1270 + else 1271 + st->wfb_trg &= ~ADE9000_WFB_TRG_ZXIA_BIT; 1272 + } else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_RISING) { 1273 + bit_mask = ADE9000_ST1_SWELLA_BIT; 1274 + if (state) 1275 + st->wfb_trg |= ADE9000_WFB_TRG_SWELL_BIT; 1276 + else 1277 + st->wfb_trg &= ~ADE9000_WFB_TRG_SWELL_BIT; 1278 + } else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_FALLING) { 1279 + bit_mask = ADE9000_ST1_DIPA_BIT; 1280 + if (state) 1281 + st->wfb_trg |= ADE9000_WFB_TRG_DIP_BIT; 1282 + else 1283 + st->wfb_trg &= ~ADE9000_WFB_TRG_DIP_BIT; 1284 + } else { 1285 + dev_err_ratelimited(&indio_dev->dev, "Invalid channel type %d or direction %d for phase A\n", 1286 + chan->type, dir); 1287 + return -EINVAL; 1288 + } 1289 + break; 1290 + case ADE9000_PHASE_B_NR: 1291 + if (chan->type == IIO_VOLTAGE && dir == IIO_EV_DIR_EITHER) { 1292 + bit_mask = ADE9000_ST1_ZXVB_BIT; 1293 + if (state) 1294 + st->wfb_trg |= ADE9000_WFB_TRG_ZXVB_BIT; 1295 + else 1296 + st->wfb_trg &= ~ADE9000_WFB_TRG_ZXVB_BIT; 1297 + } else if (chan->type == IIO_CURRENT && dir == IIO_EV_DIR_EITHER) { 1298 + bit_mask = ADE9000_ST1_ZXIB_BIT; 1299 + if (state) 1300 + st->wfb_trg |= ADE9000_WFB_TRG_ZXIB_BIT; 1301 + else 1302 + st->wfb_trg &= ~ADE9000_WFB_TRG_ZXIB_BIT; 1303 + } else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_RISING) { 1304 + bit_mask = ADE9000_ST1_SWELLB_BIT; 1305 + if (state) 1306 + st->wfb_trg |= ADE9000_WFB_TRG_SWELL_BIT; 1307 + else 1308 + st->wfb_trg &= ~ADE9000_WFB_TRG_SWELL_BIT; 1309 + } else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_FALLING) { 1310 + bit_mask = ADE9000_ST1_DIPB_BIT; 1311 + if (state) 1312 + st->wfb_trg |= ADE9000_WFB_TRG_DIP_BIT; 1313 + else 1314 + st->wfb_trg &= ~ADE9000_WFB_TRG_DIP_BIT; 1315 + } else { 1316 + dev_err_ratelimited(&indio_dev->dev, 1317 + "Invalid channel type %d or direction %d for phase B\n", 1318 + chan->type, dir); 1319 + return -EINVAL; 1320 + } 1321 + break; 1322 + case ADE9000_PHASE_C_NR: 1323 + if (chan->type == IIO_VOLTAGE && dir == IIO_EV_DIR_EITHER) { 1324 + bit_mask = ADE9000_ST1_ZXVC_BIT; 1325 + if (state) 1326 + st->wfb_trg |= ADE9000_WFB_TRG_ZXVC_BIT; 1327 + else 1328 + st->wfb_trg &= ~ADE9000_WFB_TRG_ZXVC_BIT; 1329 + } else if (chan->type == IIO_CURRENT && dir == IIO_EV_DIR_EITHER) { 1330 + bit_mask = ADE9000_ST1_ZXIC_BIT; 1331 + if (state) 1332 + st->wfb_trg |= ADE9000_WFB_TRG_ZXIC_BIT; 1333 + else 1334 + st->wfb_trg &= ~ADE9000_WFB_TRG_ZXIC_BIT; 1335 + } else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_RISING) { 1336 + bit_mask = ADE9000_ST1_SWELLC_BIT; 1337 + if (state) 1338 + st->wfb_trg |= ADE9000_WFB_TRG_SWELL_BIT; 1339 + else 1340 + st->wfb_trg &= ~ADE9000_WFB_TRG_SWELL_BIT; 1341 + } else if (chan->type == IIO_ALTVOLTAGE && dir == IIO_EV_DIR_FALLING) { 1342 + bit_mask = ADE9000_ST1_DIPC_BIT; 1343 + if (state) 1344 + st->wfb_trg |= ADE9000_WFB_TRG_DIP_BIT; 1345 + else 1346 + st->wfb_trg &= ~ADE9000_WFB_TRG_DIP_BIT; 1347 + } else { 1348 + dev_err_ratelimited(&indio_dev->dev, 1349 + "Invalid channel type %d or direction %d for phase C\n", 1350 + chan->type, dir); 1351 + return -EINVAL; 1352 + } 1353 + break; 1354 + default: 1355 + return -EINVAL; 1356 + } 1357 + 1358 + /* Set bits if enabling event, clear bits if disabling */ 1359 + return regmap_assign_bits(st->regmap, ADE9000_REG_MASK1, bit_mask, state ? bit_mask : 0); 1360 + } 1361 + 1362 + static int ade9000_write_event_value(struct iio_dev *indio_dev, 1363 + const struct iio_chan_spec *chan, 1364 + enum iio_event_type type, 1365 + enum iio_event_direction dir, 1366 + enum iio_event_info info, 1367 + int val, int val2) 1368 + { 1369 + struct ade9000_state *st = iio_priv(indio_dev); 1370 + 1371 + switch (info) { 1372 + case IIO_EV_INFO_VALUE: 1373 + switch (dir) { 1374 + case IIO_EV_DIR_FALLING: 1375 + return regmap_write(st->regmap, ADE9000_REG_DIP_LVL, val); 1376 + case IIO_EV_DIR_RISING: 1377 + return regmap_write(st->regmap, ADE9000_REG_SWELL_LVL, val); 1378 + default: 1379 + return -EINVAL; 1380 + } 1381 + default: 1382 + return -EINVAL; 1383 + } 1384 + } 1385 + 1386 + static int ade9000_read_event_value(struct iio_dev *indio_dev, 1387 + const struct iio_chan_spec *chan, 1388 + enum iio_event_type type, 1389 + enum iio_event_direction dir, 1390 + enum iio_event_info info, 1391 + int *val, int *val2) 1392 + { 1393 + struct ade9000_state *st = iio_priv(indio_dev); 1394 + unsigned int data; 1395 + int ret; 1396 + 1397 + switch (info) { 1398 + case IIO_EV_INFO_VALUE: 1399 + switch (dir) { 1400 + case IIO_EV_DIR_FALLING: 1401 + ret = regmap_read(st->regmap, ADE9000_REG_DIP_LVL, &data); 1402 + if (ret) 1403 + return ret; 1404 + *val = data; 1405 + return IIO_VAL_INT; 1406 + case IIO_EV_DIR_RISING: 1407 + ret = regmap_read(st->regmap, ADE9000_REG_SWELL_LVL, &data); 1408 + if (ret) 1409 + return ret; 1410 + *val = data; 1411 + return IIO_VAL_INT; 1412 + default: 1413 + return -EINVAL; 1414 + } 1415 + default: 1416 + return -EINVAL; 1417 + } 1418 + } 1419 + 1420 + static int ade9000_waveform_buffer_config(struct iio_dev *indio_dev) 1421 + { 1422 + struct ade9000_state *st = iio_priv(indio_dev); 1423 + u32 wfb_cfg_val; 1424 + u32 active_scans; 1425 + 1426 + bitmap_to_arr32(&active_scans, indio_dev->active_scan_mask, 1427 + iio_get_masklength(indio_dev)); 1428 + 1429 + switch (active_scans) { 1430 + case ADE9000_SCAN_POS_IA | ADE9000_SCAN_POS_VA: 1431 + wfb_cfg_val = ADE9000_WFB_CFG_IA_VA; 1432 + st->wfb_nr_activ_chan = 2; 1433 + break; 1434 + case ADE9000_SCAN_POS_IB | ADE9000_SCAN_POS_VB: 1435 + wfb_cfg_val = ADE9000_WFB_CFG_IB_VB; 1436 + st->wfb_nr_activ_chan = 2; 1437 + break; 1438 + case ADE9000_SCAN_POS_IC | ADE9000_SCAN_POS_VC: 1439 + wfb_cfg_val = ADE9000_WFB_CFG_IC_VC; 1440 + st->wfb_nr_activ_chan = 2; 1441 + break; 1442 + case ADE9000_SCAN_POS_IA: 1443 + wfb_cfg_val = ADE9000_WFB_CFG_IA; 1444 + st->wfb_nr_activ_chan = 1; 1445 + break; 1446 + case ADE9000_SCAN_POS_VA: 1447 + wfb_cfg_val = ADE9000_WFB_CFG_VA; 1448 + st->wfb_nr_activ_chan = 1; 1449 + break; 1450 + case ADE9000_SCAN_POS_IB: 1451 + wfb_cfg_val = ADE9000_WFB_CFG_IB; 1452 + st->wfb_nr_activ_chan = 1; 1453 + break; 1454 + case ADE9000_SCAN_POS_VB: 1455 + wfb_cfg_val = ADE9000_WFB_CFG_VB; 1456 + st->wfb_nr_activ_chan = 1; 1457 + break; 1458 + case ADE9000_SCAN_POS_IC: 1459 + wfb_cfg_val = ADE9000_WFB_CFG_IC; 1460 + st->wfb_nr_activ_chan = 1; 1461 + break; 1462 + case ADE9000_SCAN_POS_VC: 1463 + wfb_cfg_val = ADE9000_WFB_CFG_VC; 1464 + st->wfb_nr_activ_chan = 1; 1465 + break; 1466 + case (ADE9000_SCAN_POS_IA | ADE9000_SCAN_POS_VA | ADE9000_SCAN_POS_IB | 1467 + ADE9000_SCAN_POS_VB | ADE9000_SCAN_POS_IC | ADE9000_SCAN_POS_VC): 1468 + wfb_cfg_val = ADE9000_WFB_CFG_ALL_CHAN; 1469 + st->wfb_nr_activ_chan = 6; 1470 + break; 1471 + default: 1472 + dev_err(&st->spi->dev, "Unsupported combination of scans\n"); 1473 + return -EINVAL; 1474 + } 1475 + 1476 + wfb_cfg_val |= FIELD_PREP(ADE9000_WF_SRC_MASK, st->wf_src); 1477 + 1478 + return regmap_write(st->regmap, ADE9000_REG_WFB_CFG, wfb_cfg_val); 1479 + } 1480 + 1481 + static int ade9000_waveform_buffer_interrupt_setup(struct ade9000_state *st) 1482 + { 1483 + int ret; 1484 + 1485 + ret = regmap_write(st->regmap, ADE9000_REG_WFB_TRG_CFG, 0x0); 1486 + if (ret) 1487 + return ret; 1488 + 1489 + /* Always use streaming mode setup */ 1490 + ret = regmap_write(st->regmap, ADE9000_REG_WFB_PG_IRQEN, 1491 + ADE9000_MIDDLE_PAGE_BIT); 1492 + if (ret) 1493 + return ret; 1494 + 1495 + ret = regmap_write(st->regmap, ADE9000_REG_STATUS0, GENMASK(31, 0)); 1496 + if (ret) 1497 + return ret; 1498 + 1499 + return regmap_set_bits(st->regmap, ADE9000_REG_MASK0, 1500 + ADE9000_ST0_PAGE_FULL_BIT); 1501 + } 1502 + 1503 + static int ade9000_buffer_preenable(struct iio_dev *indio_dev) 1504 + { 1505 + struct ade9000_state *st = iio_priv(indio_dev); 1506 + int ret; 1507 + 1508 + ret = ade9000_waveform_buffer_config(indio_dev); 1509 + if (ret) 1510 + return ret; 1511 + 1512 + st->wfb_nr_samples = ADE9000_WFB_MAX_SAMPLES_CHAN * st->wfb_nr_activ_chan; 1513 + 1514 + ade9000_configure_scan(indio_dev, ADE9000_REG_WF_BUFF); 1515 + 1516 + ret = ade9000_waveform_buffer_interrupt_setup(st); 1517 + if (ret) 1518 + return ret; 1519 + 1520 + ret = regmap_set_bits(st->regmap, ADE9000_REG_WFB_CFG, 1521 + ADE9000_WF_CAP_EN_MASK); 1522 + if (ret) { 1523 + dev_err(&st->spi->dev, "Post-enable waveform buffer enable fail\n"); 1524 + return ret; 1525 + } 1526 + 1527 + return 0; 1528 + } 1529 + 1530 + static int ade9000_buffer_postdisable(struct iio_dev *indio_dev) 1531 + { 1532 + struct ade9000_state *st = iio_priv(indio_dev); 1533 + struct device *dev = &st->spi->dev; 1534 + u32 interrupts; 1535 + int ret; 1536 + 1537 + ret = regmap_clear_bits(st->regmap, ADE9000_REG_WFB_CFG, 1538 + ADE9000_WF_CAP_EN_MASK); 1539 + if (ret) { 1540 + dev_err(dev, "Post-disable waveform buffer disable fail\n"); 1541 + return ret; 1542 + } 1543 + 1544 + ret = regmap_write(st->regmap, ADE9000_REG_WFB_TRG_CFG, 0x0); 1545 + if (ret) 1546 + return ret; 1547 + 1548 + interrupts = ADE9000_ST0_WFB_TRIG_BIT | ADE9000_ST0_PAGE_FULL_BIT; 1549 + 1550 + ret = regmap_clear_bits(st->regmap, ADE9000_REG_MASK0, interrupts); 1551 + if (ret) { 1552 + dev_err(dev, "Post-disable update maks0 fail\n"); 1553 + return ret; 1554 + } 1555 + 1556 + return regmap_write(st->regmap, ADE9000_REG_STATUS0, GENMASK(31, 0)); 1557 + } 1558 + 1559 + static const struct iio_buffer_setup_ops ade9000_buffer_ops = { 1560 + .preenable = &ade9000_buffer_preenable, 1561 + .postdisable = &ade9000_buffer_postdisable, 1562 + }; 1563 + 1564 + static int ade9000_reset(struct ade9000_state *st) 1565 + { 1566 + struct device *dev = &st->spi->dev; 1567 + struct gpio_desc *gpio_reset; 1568 + int ret; 1569 + 1570 + gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 1571 + if (IS_ERR(gpio_reset)) 1572 + return PTR_ERR(gpio_reset); 1573 + 1574 + /* Software reset via register if no GPIO available */ 1575 + if (!gpio_reset) { 1576 + ret = regmap_set_bits(st->regmap, ADE9000_REG_CONFIG1, 1577 + ADE9000_SWRST_BIT); 1578 + if (ret) 1579 + return ret; 1580 + fsleep(90); 1581 + return 0; 1582 + } 1583 + 1584 + /* Hardware reset via GPIO */ 1585 + fsleep(10); 1586 + gpiod_set_value_cansleep(gpio_reset, 0); 1587 + fsleep(50000); 1588 + 1589 + /* Only wait for completion if IRQ1 is available to signal reset done */ 1590 + if (fwnode_irq_get_byname(dev_fwnode(dev), "irq1") >= 0) { 1591 + if (!wait_for_completion_timeout(&st->reset_completion, 1592 + msecs_to_jiffies(1000))) { 1593 + dev_err(dev, "Reset timeout after 1s\n"); 1594 + return -ETIMEDOUT; 1595 + } 1596 + } 1597 + /* If no IRQ available, reset is already complete after the 50ms delay above */ 1598 + 1599 + return 0; 1600 + } 1601 + 1602 + static int ade9000_setup(struct ade9000_state *st) 1603 + { 1604 + struct device *dev = &st->spi->dev; 1605 + int ret; 1606 + 1607 + ret = regmap_multi_reg_write(st->regmap, ade9000_initialization_sequence, 1608 + ARRAY_SIZE(ade9000_initialization_sequence)); 1609 + if (ret) 1610 + return dev_err_probe(dev, ret, "Failed to write register sequence"); 1611 + 1612 + fsleep(2000); 1613 + 1614 + return 0; 1615 + } 1616 + 1617 + static const struct iio_info ade9000_info = { 1618 + .read_raw = ade9000_read_raw, 1619 + .write_raw = ade9000_write_raw, 1620 + .debugfs_reg_access = ade9000_reg_access, 1621 + .write_event_config = ade9000_write_event_config, 1622 + .read_event_config = ade9000_read_event_config, 1623 + .write_event_value = ade9000_write_event_value, 1624 + .read_event_value = ade9000_read_event_value, 1625 + }; 1626 + 1627 + static const struct regmap_config ade9000_regmap_config = { 1628 + .reg_bits = 16, 1629 + .val_bits = 32, 1630 + .max_register = 0x6bc, 1631 + .zero_flag_mask = true, 1632 + .cache_type = REGCACHE_RBTREE, 1633 + .reg_read = ade9000_spi_read_reg, 1634 + .reg_write = ade9000_spi_write_reg, 1635 + .volatile_reg = ade9000_is_volatile_reg, 1636 + }; 1637 + 1638 + static int ade9000_setup_clkout(struct device *dev, struct ade9000_state *st) 1639 + { 1640 + struct clk_hw *clkout_hw; 1641 + int ret; 1642 + 1643 + if (!IS_ENABLED(CONFIG_COMMON_CLK)) 1644 + return 0; 1645 + 1646 + /* 1647 + * Only provide clock output when using external CMOS clock. 1648 + * When using crystal, CLKOUT is connected to crystal and shouldn't 1649 + * be used as clock provider for other devices. 1650 + */ 1651 + if (!device_property_present(dev, "#clock-cells") || !st->clkin) 1652 + return 0; 1653 + 1654 + /* CLKOUT passes through CLKIN with divider of 1 */ 1655 + clkout_hw = devm_clk_hw_register_divider(dev, "clkout", __clk_get_name(st->clkin), 1656 + CLK_SET_RATE_PARENT, NULL, 0, 1, 0, NULL); 1657 + if (IS_ERR(clkout_hw)) 1658 + return dev_err_probe(dev, PTR_ERR(clkout_hw), "Failed to register clkout"); 1659 + 1660 + ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, clkout_hw); 1661 + if (ret) 1662 + return dev_err_probe(dev, ret, "Failed to add clock provider"); 1663 + 1664 + return 0; 1665 + } 1666 + 1667 + static int ade9000_request_irq(struct device *dev, const char *name, 1668 + irq_handler_t handler, void *dev_id) 1669 + { 1670 + int irq, ret; 1671 + 1672 + irq = fwnode_irq_get_byname(dev_fwnode(dev), name); 1673 + if (irq == -EINVAL) 1674 + return 0; /* interrupts are optional */ 1675 + if (irq < 0) 1676 + return dev_err_probe(dev, irq, "Failed to get %s irq", name); 1677 + 1678 + ret = devm_request_threaded_irq(dev, irq, NULL, handler, 1679 + IRQF_ONESHOT, KBUILD_MODNAME, dev_id); 1680 + if (ret) 1681 + return dev_err_probe(dev, ret, "Failed to request %s irq", name); 1682 + 1683 + return 0; 1684 + } 1685 + 1686 + static int ade9000_probe(struct spi_device *spi) 1687 + { 1688 + struct device *dev = &spi->dev; 1689 + struct iio_dev *indio_dev; 1690 + struct ade9000_state *st; 1691 + struct regmap *regmap; 1692 + int ret; 1693 + 1694 + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 1695 + if (!indio_dev) 1696 + return -ENOMEM; 1697 + 1698 + st = iio_priv(indio_dev); 1699 + 1700 + regmap = devm_regmap_init(dev, NULL, st, &ade9000_regmap_config); 1701 + if (IS_ERR(regmap)) 1702 + return dev_err_probe(dev, PTR_ERR(regmap), "Unable to allocate ADE9000 regmap"); 1703 + 1704 + st->regmap = regmap; 1705 + st->spi = spi; 1706 + 1707 + init_completion(&st->reset_completion); 1708 + 1709 + ret = ade9000_request_irq(dev, "irq0", ade9000_irq0_thread, indio_dev); 1710 + if (ret) 1711 + return ret; 1712 + 1713 + ret = ade9000_request_irq(dev, "irq1", ade9000_irq1_thread, indio_dev); 1714 + if (ret) 1715 + return ret; 1716 + 1717 + ret = ade9000_request_irq(dev, "dready", ade9000_dready_thread, indio_dev); 1718 + if (ret) 1719 + return ret; 1720 + 1721 + ret = devm_mutex_init(dev, &st->lock); 1722 + if (ret) 1723 + return ret; 1724 + 1725 + /* External CMOS clock input (optional - crystal can be used instead) */ 1726 + st->clkin = devm_clk_get_optional_enabled(dev, NULL); 1727 + if (IS_ERR(st->clkin)) 1728 + return dev_err_probe(dev, PTR_ERR(st->clkin), "Failed to get and enable clkin"); 1729 + 1730 + ret = ade9000_setup_clkout(dev, st); 1731 + if (ret) 1732 + return ret; 1733 + 1734 + indio_dev->name = "ade9000"; 1735 + indio_dev->info = &ade9000_info; 1736 + indio_dev->modes = INDIO_DIRECT_MODE; 1737 + indio_dev->setup_ops = &ade9000_buffer_ops; 1738 + 1739 + ret = devm_regulator_get_enable(&spi->dev, "vdd"); 1740 + if (ret) 1741 + return dev_err_probe(&spi->dev, ret, 1742 + "Failed to get and enable vdd regulator\n"); 1743 + 1744 + indio_dev->channels = ade9000_channels; 1745 + indio_dev->num_channels = ARRAY_SIZE(ade9000_channels); 1746 + 1747 + ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, 1748 + &ade9000_buffer_ops); 1749 + if (ret) 1750 + return dev_err_probe(dev, ret, "Failed to setup IIO buffer"); 1751 + 1752 + ret = ade9000_reset(st); 1753 + if (ret) 1754 + return ret; 1755 + 1756 + /* Configure reference selection if vref regulator is available */ 1757 + ret = devm_regulator_get_enable_optional(dev, "vref"); 1758 + if (ret != -ENODEV && ret >= 0) { 1759 + ret = regmap_set_bits(st->regmap, ADE9000_REG_CONFIG1, 1760 + ADE9000_EXT_REF_MASK); 1761 + if (ret) 1762 + return ret; 1763 + } else if (ret < 0 && ret != -ENODEV) { 1764 + return dev_err_probe(dev, ret, 1765 + "Failed to get and enable vref regulator\n"); 1766 + } 1767 + 1768 + ret = ade9000_setup(st); 1769 + if (ret) 1770 + return ret; 1771 + 1772 + return devm_iio_device_register(dev, indio_dev); 1773 + }; 1774 + 1775 + static const struct spi_device_id ade9000_id[] = { 1776 + { "ade9000", 0 }, 1777 + { } 1778 + }; 1779 + MODULE_DEVICE_TABLE(spi, ade9000_id); 1780 + 1781 + static const struct of_device_id ade9000_of_match[] = { 1782 + { .compatible = "adi,ade9000" }, 1783 + { } 1784 + }; 1785 + MODULE_DEVICE_TABLE(of, ade9000_of_match); 1786 + 1787 + static struct spi_driver ade9000_driver = { 1788 + .driver = { 1789 + .name = "ade9000", 1790 + .of_match_table = ade9000_of_match, 1791 + }, 1792 + .probe = ade9000_probe, 1793 + .id_table = ade9000_id, 1794 + }; 1795 + module_spi_driver(ade9000_driver); 1796 + 1797 + MODULE_AUTHOR("Antoniu Miclaus <antoniu.miclaus@analog.com>"); 1798 + MODULE_DESCRIPTION("Analog Devices ADE9000"); 1799 + MODULE_LICENSE("GPL");
+1
drivers/iio/adc/adi-axi-adc.c
··· 618 618 .chan_status = axi_adc_chan_status, 619 619 .interface_type_get = axi_adc_interface_type_get, 620 620 .oversampling_ratio_set = axi_adc_oversampling_ratio_set, 621 + .num_lanes_set = axi_adc_num_lanes_set, 621 622 .debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access), 622 623 .debugfs_print_chan_status = iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status), 623 624 };
+1 -12
drivers/iio/adc/at91-sama5d2_adc.c
··· 896 896 emr |= osr | AT91_SAMA5D2_TRACKX(trackx); 897 897 at91_adc_writel(st, EMR, emr); 898 898 899 - pm_runtime_mark_last_busy(st->dev); 900 899 pm_runtime_put_autosuspend(st->dev); 901 900 902 901 st->oversampling_ratio = oversampling_ratio; ··· 970 971 AT91_SAMA5D2_IER_PEN | AT91_SAMA5D2_IER_NOPEN); 971 972 at91_adc_writel(st, TSMR, 0); 972 973 973 - pm_runtime_mark_last_busy(st->dev); 974 974 pm_runtime_put_autosuspend(st->dev); 975 975 return 0; 976 976 } ··· 1140 1142 1141 1143 at91_adc_configure_trigger_registers(st, state); 1142 1144 1143 - if (!state) { 1144 - pm_runtime_mark_last_busy(st->dev); 1145 + if (!state) 1145 1146 pm_runtime_put_autosuspend(st->dev); 1146 - } 1147 1147 1148 1148 return 0; 1149 1149 } ··· 1332 1336 at91_adc_writel(st, IER, AT91_SAMA5D2_IER_DRDY); 1333 1337 1334 1338 pm_runtime_put: 1335 - pm_runtime_mark_last_busy(st->dev); 1336 1339 pm_runtime_put_autosuspend(st->dev); 1337 1340 return ret; 1338 1341 } ··· 1389 1394 if (st->dma_st.dma_chan) 1390 1395 dmaengine_terminate_sync(st->dma_st.dma_chan); 1391 1396 1392 - pm_runtime_mark_last_busy(st->dev); 1393 1397 pm_runtime_put_autosuspend(st->dev); 1394 1398 1395 1399 return 0; ··· 1597 1603 mr |= AT91_SAMA5D2_MR_TRACKTIM(tracktim); 1598 1604 at91_adc_writel(st, MR, mr); 1599 1605 1600 - pm_runtime_mark_last_busy(st->dev); 1601 1606 pm_runtime_put_autosuspend(st->dev); 1602 1607 1603 1608 dev_dbg(&indio_dev->dev, "freq: %u, startup: %u, prescal: %u, tracktim=%u\n", ··· 1802 1809 at91_adc_readl(st, LCDR); 1803 1810 1804 1811 pm_runtime_put: 1805 - pm_runtime_mark_last_busy(st->dev); 1806 1812 pm_runtime_put_autosuspend(st->dev); 1807 1813 return ret; 1808 1814 } ··· 1882 1890 restore_config: 1883 1891 /* Revert previous settings. */ 1884 1892 at91_adc_temp_sensor_configure(st, false); 1885 - pm_runtime_mark_last_busy(st->dev); 1886 1893 pm_runtime_put_autosuspend(st->dev); 1887 1894 if (ret < 0) 1888 1895 return ret; ··· 2456 2465 dev_info(&pdev->dev, "version: %x\n", 2457 2466 readl_relaxed(st->base + st->soc_info.platform->layout->VERSION)); 2458 2467 2459 - pm_runtime_mark_last_busy(st->dev); 2460 2468 pm_runtime_put_autosuspend(st->dev); 2461 2469 2462 2470 return 0; ··· 2557 2567 at91_adc_configure_trigger_registers(st, true); 2558 2568 } 2559 2569 2560 - pm_runtime_mark_last_busy(st->dev); 2561 2570 pm_runtime_put_autosuspend(st->dev); 2562 2571 2563 2572 return 0;
+1 -3
drivers/iio/adc/bcm_iproc_adc.c
··· 511 511 512 512 indio_dev = devm_iio_device_alloc(&pdev->dev, 513 513 sizeof(*adc_priv)); 514 - if (!indio_dev) { 515 - dev_err(&pdev->dev, "failed to allocate iio device\n"); 514 + if (!indio_dev) 516 515 return -ENOMEM; 517 - } 518 516 519 517 adc_priv = iio_priv(indio_dev); 520 518 platform_set_drvdata(pdev, indio_dev);
+2 -4
drivers/iio/adc/cpcap-adc.c
··· 953 953 int error; 954 954 955 955 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*ddata)); 956 - if (!indio_dev) { 957 - dev_err(&pdev->dev, "failed to allocate iio device\n"); 958 - 956 + if (!indio_dev) 959 957 return -ENOMEM; 960 - } 958 + 961 959 ddata = iio_priv(indio_dev); 962 960 ddata->ato = device_get_match_data(&pdev->dev); 963 961 if (!ddata->ato)
+2 -3
drivers/iio/adc/da9150-gpadc.c
··· 308 308 int irq, ret; 309 309 310 310 indio_dev = devm_iio_device_alloc(dev, sizeof(*gpadc)); 311 - if (!indio_dev) { 312 - dev_err(&pdev->dev, "Failed to allocate IIO device\n"); 311 + if (!indio_dev) 313 312 return -ENOMEM; 314 - } 313 + 315 314 gpadc = iio_priv(indio_dev); 316 315 317 316 gpadc->da9150 = da9150;
+3 -6
drivers/iio/adc/dln2-adc.c
··· 584 584 int i, ret, chans; 585 585 586 586 indio_dev = devm_iio_device_alloc(dev, sizeof(*dln2)); 587 - if (!indio_dev) { 588 - dev_err(dev, "failed allocating iio device\n"); 587 + if (!indio_dev) 589 588 return -ENOMEM; 590 - } 591 589 592 590 dln2 = iio_priv(indio_dev); 593 591 dln2->pdev = pdev; ··· 626 628 dln2->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", 627 629 indio_dev->name, 628 630 iio_device_id(indio_dev)); 629 - if (!dln2->trig) { 630 - dev_err(dev, "failed to allocate trigger\n"); 631 + if (!dln2->trig) 631 632 return -ENOMEM; 632 - } 633 + 633 634 iio_trigger_set_drvdata(dln2->trig, dln2); 634 635 ret = devm_iio_trigger_register(dev, dln2->trig); 635 636 if (ret) {
+4 -282
drivers/iio/adc/exynos_adc.c
··· 19 19 #include <linux/clk.h> 20 20 #include <linux/completion.h> 21 21 #include <linux/of.h> 22 - #include <linux/of_irq.h> 23 22 #include <linux/regulator/consumer.h> 24 23 #include <linux/of_platform.h> 25 24 #include <linux/err.h> 26 - #include <linux/input.h> 27 25 28 26 #include <linux/iio/iio.h> 29 27 #include <linux/iio/machine.h> ··· 29 31 #include <linux/mfd/syscon.h> 30 32 #include <linux/regmap.h> 31 33 32 - #include <linux/platform_data/touchscreen-s3c2410.h> 33 - 34 34 /* S3C/EXYNOS4412/5250 ADC_V1 registers definitions */ 35 35 #define ADC_V1_CON(x) ((x) + 0x00) 36 - #define ADC_V1_TSC(x) ((x) + 0x04) 37 36 #define ADC_V1_DLY(x) ((x) + 0x08) 38 37 #define ADC_V1_DATX(x) ((x) + 0x0C) 39 38 #define ADC_V1_DATY(x) ((x) + 0x10) 40 39 #define ADC_V1_UPDN(x) ((x) + 0x14) 41 40 #define ADC_V1_INTCLR(x) ((x) + 0x18) 42 41 #define ADC_V1_MUX(x) ((x) + 0x1c) 43 - #define ADC_V1_CLRINTPNDNUP(x) ((x) + 0x20) 44 - 45 - /* S3C2410 ADC registers definitions */ 46 - #define ADC_S3C2410_MUX(x) ((x) + 0x18) 47 42 48 43 /* Future ADC_V2 registers definitions */ 49 44 #define ADC_V2_CON1(x) ((x) + 0x00) ··· 52 61 #define ADC_V1_CON_PRSCLV(x) (((x) & 0xFF) << 6) 53 62 #define ADC_V1_CON_STANDBY (1u << 2) 54 63 55 - /* Bit definitions for S3C2410 ADC */ 64 + /* Bit definitions for S3C2410 / S3C6410 ADC */ 56 65 #define ADC_S3C2410_CON_SELMUX(x) (((x) & 7) << 3) 57 - #define ADC_S3C2410_DATX_MASK 0x3FF 58 - #define ADC_S3C2416_CON_RES_SEL (1u << 3) 59 - 60 - /* touch screen always uses channel 0 */ 61 - #define ADC_S3C2410_MUX_TS 0 62 66 63 67 /* ADCTSC Register Bits */ 64 68 #define ADC_S3C2443_TSC_UD_SEN (1u << 8) ··· 61 75 #define ADC_S3C2410_TSC_YP_SEN (1u << 6) 62 76 #define ADC_S3C2410_TSC_XM_SEN (1u << 5) 63 77 #define ADC_S3C2410_TSC_XP_SEN (1u << 4) 64 - #define ADC_S3C2410_TSC_PULL_UP_DISABLE (1u << 3) 65 - #define ADC_S3C2410_TSC_AUTO_PST (1u << 2) 66 78 #define ADC_S3C2410_TSC_XY_PST(x) (((x) & 0x3) << 0) 67 79 68 80 #define ADC_TSC_WAIT4INT (ADC_S3C2410_TSC_YM_SEN | \ 69 81 ADC_S3C2410_TSC_YP_SEN | \ 70 82 ADC_S3C2410_TSC_XP_SEN | \ 71 83 ADC_S3C2410_TSC_XY_PST(3)) 72 - 73 - #define ADC_TSC_AUTOPST (ADC_S3C2410_TSC_YM_SEN | \ 74 - ADC_S3C2410_TSC_YP_SEN | \ 75 - ADC_S3C2410_TSC_XP_SEN | \ 76 - ADC_S3C2410_TSC_AUTO_PST | \ 77 - ADC_S3C2410_TSC_XY_PST(0)) 78 84 79 85 /* Bit definitions for ADC_V2 */ 80 86 #define ADC_V2_CON1_SOFT_RESET (1u << 2) ··· 99 121 struct exynos_adc { 100 122 struct exynos_adc_data *data; 101 123 struct device *dev; 102 - struct input_dev *input; 103 124 void __iomem *regs; 104 125 struct regmap *pmu_map; 105 126 struct clk *clk; 106 127 struct clk *sclk; 107 128 unsigned int irq; 108 - unsigned int tsirq; 109 - unsigned int delay; 110 129 struct regulator *vdd; 111 130 112 131 struct completion completion; 113 132 114 133 u32 value; 115 134 unsigned int version; 116 - 117 - bool ts_enabled; 118 - 119 - bool read_ts; 120 - u32 ts_x; 121 - u32 ts_y; 122 135 123 136 /* 124 137 * Lock to protect from potential concurrent access to the ··· 210 241 writel(con1, ADC_V1_CON(info->regs)); 211 242 212 243 /* set touchscreen delay */ 213 - writel(info->delay, ADC_V1_DLY(info->regs)); 244 + writel(10000, ADC_V1_DLY(info->regs)); 214 245 } 215 246 216 247 static void exynos_adc_v1_exit_hw(struct exynos_adc *info) ··· 276 307 .start_conv = exynos_adc_v1_start_conv, 277 308 }; 278 309 279 - static void exynos_adc_s3c2416_start_conv(struct exynos_adc *info, 280 - unsigned long addr) 281 - { 282 - u32 con1; 283 - 284 - /* Enable 12 bit ADC resolution */ 285 - con1 = readl(ADC_V1_CON(info->regs)); 286 - con1 |= ADC_S3C2416_CON_RES_SEL; 287 - writel(con1, ADC_V1_CON(info->regs)); 288 - 289 - /* Select channel for S3C2416 */ 290 - writel(addr, ADC_S3C2410_MUX(info->regs)); 291 - 292 - con1 = readl(ADC_V1_CON(info->regs)); 293 - writel(con1 | ADC_CON_EN_START, ADC_V1_CON(info->regs)); 294 - } 295 - 296 - static struct exynos_adc_data const exynos_adc_s3c2416_data = { 297 - .num_channels = MAX_ADC_V1_CHANNELS, 298 - .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */ 299 - 300 - .init_hw = exynos_adc_v1_init_hw, 301 - .exit_hw = exynos_adc_v1_exit_hw, 302 - .start_conv = exynos_adc_s3c2416_start_conv, 303 - }; 304 - 305 - static void exynos_adc_s3c2443_start_conv(struct exynos_adc *info, 306 - unsigned long addr) 307 - { 308 - u32 con1; 309 - 310 - /* Select channel for S3C2433 */ 311 - writel(addr, ADC_S3C2410_MUX(info->regs)); 312 - 313 - con1 = readl(ADC_V1_CON(info->regs)); 314 - writel(con1 | ADC_CON_EN_START, ADC_V1_CON(info->regs)); 315 - } 316 - 317 - static struct exynos_adc_data const exynos_adc_s3c2443_data = { 318 - .num_channels = MAX_ADC_V1_CHANNELS, 319 - .mask = ADC_S3C2410_DATX_MASK, /* 10 bit ADC resolution */ 320 - 321 - .init_hw = exynos_adc_v1_init_hw, 322 - .exit_hw = exynos_adc_v1_exit_hw, 323 - .start_conv = exynos_adc_s3c2443_start_conv, 324 - }; 325 - 326 310 static void exynos_adc_s3c64xx_start_conv(struct exynos_adc *info, 327 311 unsigned long addr) 328 312 { ··· 286 364 con1 |= ADC_S3C2410_CON_SELMUX(addr); 287 365 writel(con1 | ADC_CON_EN_START, ADC_V1_CON(info->regs)); 288 366 } 289 - 290 - static struct exynos_adc_data const exynos_adc_s3c24xx_data = { 291 - .num_channels = MAX_ADC_V1_CHANNELS, 292 - .mask = ADC_S3C2410_DATX_MASK, /* 10 bit ADC resolution */ 293 - 294 - .init_hw = exynos_adc_v1_init_hw, 295 - .exit_hw = exynos_adc_v1_exit_hw, 296 - .start_conv = exynos_adc_s3c64xx_start_conv, 297 - }; 298 367 299 368 static struct exynos_adc_data const exynos_adc_s3c64xx_data = { 300 369 .num_channels = MAX_ADC_V1_CHANNELS, ··· 399 486 400 487 static const struct of_device_id exynos_adc_match[] = { 401 488 { 402 - .compatible = "samsung,s3c2410-adc", 403 - .data = &exynos_adc_s3c24xx_data, 404 - }, { 405 - .compatible = "samsung,s3c2416-adc", 406 - .data = &exynos_adc_s3c2416_data, 407 - }, { 408 - .compatible = "samsung,s3c2440-adc", 409 - .data = &exynos_adc_s3c24xx_data, 410 - }, { 411 - .compatible = "samsung,s3c2443-adc", 412 - .data = &exynos_adc_s3c2443_data, 413 - }, { 414 489 .compatible = "samsung,s3c6410-adc", 415 490 .data = &exynos_adc_s3c64xx_data, 416 491 }, { ··· 481 580 return ret; 482 581 } 483 582 484 - static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y) 485 - { 486 - struct exynos_adc *info = iio_priv(indio_dev); 487 - unsigned long time_left; 488 - int ret; 489 - 490 - mutex_lock(&info->lock); 491 - info->read_ts = true; 492 - 493 - reinit_completion(&info->completion); 494 - 495 - writel(ADC_S3C2410_TSC_PULL_UP_DISABLE | ADC_TSC_AUTOPST, 496 - ADC_V1_TSC(info->regs)); 497 - 498 - /* Select the ts channel to be used and Trigger conversion */ 499 - info->data->start_conv(info, ADC_S3C2410_MUX_TS); 500 - 501 - time_left = wait_for_completion_timeout(&info->completion, 502 - EXYNOS_ADC_TIMEOUT); 503 - if (time_left == 0) { 504 - dev_warn(&indio_dev->dev, "Conversion timed out! Resetting\n"); 505 - if (info->data->init_hw) 506 - info->data->init_hw(info); 507 - ret = -ETIMEDOUT; 508 - } else { 509 - *x = info->ts_x; 510 - *y = info->ts_y; 511 - ret = 0; 512 - } 513 - 514 - info->read_ts = false; 515 - mutex_unlock(&info->lock); 516 - 517 - return ret; 518 - } 519 - 520 583 static irqreturn_t exynos_adc_isr(int irq, void *dev_id) 521 584 { 522 585 struct exynos_adc *info = dev_id; 523 586 u32 mask = info->data->mask; 524 587 525 588 /* Read value */ 526 - if (info->read_ts) { 527 - info->ts_x = readl(ADC_V1_DATX(info->regs)); 528 - info->ts_y = readl(ADC_V1_DATY(info->regs)); 529 - writel(ADC_TSC_WAIT4INT | ADC_S3C2443_TSC_UD_SEN, ADC_V1_TSC(info->regs)); 530 - } else { 531 - info->value = readl(ADC_V1_DATX(info->regs)) & mask; 532 - } 589 + info->value = readl(ADC_V1_DATX(info->regs)) & mask; 533 590 534 591 /* clear irq */ 535 592 if (info->data->clear_irq) 536 593 info->data->clear_irq(info); 537 594 538 595 complete(&info->completion); 539 - 540 - return IRQ_HANDLED; 541 - } 542 - 543 - /* 544 - * Here we (ab)use a threaded interrupt handler to stay running 545 - * for as long as the touchscreen remains pressed, we report 546 - * a new event with the latest data and then sleep until the 547 - * next timer tick. This mirrors the behavior of the old 548 - * driver, with much less code. 549 - */ 550 - static irqreturn_t exynos_ts_isr(int irq, void *dev_id) 551 - { 552 - struct exynos_adc *info = dev_id; 553 - struct iio_dev *dev = dev_get_drvdata(info->dev); 554 - u32 x, y; 555 - bool pressed; 556 - int ret; 557 - 558 - while (READ_ONCE(info->ts_enabled)) { 559 - ret = exynos_read_s3c64xx_ts(dev, &x, &y); 560 - if (ret == -ETIMEDOUT) 561 - break; 562 - 563 - pressed = x & y & ADC_DATX_PRESSED; 564 - if (!pressed) { 565 - input_report_key(info->input, BTN_TOUCH, 0); 566 - input_sync(info->input); 567 - break; 568 - } 569 - 570 - input_report_abs(info->input, ABS_X, x & ADC_DATX_MASK); 571 - input_report_abs(info->input, ABS_Y, y & ADC_DATY_MASK); 572 - input_report_key(info->input, BTN_TOUCH, 1); 573 - input_sync(info->input); 574 - 575 - usleep_range(1000, 1100); 576 - } 577 - 578 - writel(0, ADC_V1_CLRINTPNDNUP(info->regs)); 579 596 580 597 return IRQ_HANDLED; 581 598 } ··· 549 730 return 0; 550 731 } 551 732 552 - static int exynos_adc_ts_open(struct input_dev *dev) 553 - { 554 - struct exynos_adc *info = input_get_drvdata(dev); 555 - 556 - WRITE_ONCE(info->ts_enabled, true); 557 - enable_irq(info->tsirq); 558 - 559 - return 0; 560 - } 561 - 562 - static void exynos_adc_ts_close(struct input_dev *dev) 563 - { 564 - struct exynos_adc *info = input_get_drvdata(dev); 565 - 566 - WRITE_ONCE(info->ts_enabled, false); 567 - disable_irq(info->tsirq); 568 - } 569 - 570 - static int exynos_adc_ts_init(struct exynos_adc *info) 571 - { 572 - int ret; 573 - 574 - if (info->tsirq <= 0) 575 - return -ENODEV; 576 - 577 - info->input = input_allocate_device(); 578 - if (!info->input) 579 - return -ENOMEM; 580 - 581 - info->input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 582 - info->input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 583 - 584 - input_set_abs_params(info->input, ABS_X, 0, 0x3FF, 0, 0); 585 - input_set_abs_params(info->input, ABS_Y, 0, 0x3FF, 0, 0); 586 - 587 - info->input->name = "S3C24xx TouchScreen"; 588 - info->input->id.bustype = BUS_HOST; 589 - info->input->open = exynos_adc_ts_open; 590 - info->input->close = exynos_adc_ts_close; 591 - 592 - input_set_drvdata(info->input, info); 593 - 594 - ret = input_register_device(info->input); 595 - if (ret) { 596 - input_free_device(info->input); 597 - return ret; 598 - } 599 - 600 - ret = request_threaded_irq(info->tsirq, NULL, exynos_ts_isr, 601 - IRQF_ONESHOT | IRQF_NO_AUTOEN, 602 - "touchscreen", info); 603 - if (ret) 604 - input_unregister_device(info->input); 605 - 606 - return ret; 607 - } 608 - 609 733 static int exynos_adc_probe(struct platform_device *pdev) 610 734 { 611 735 struct exynos_adc *info = NULL; 612 736 struct device_node *np = pdev->dev.of_node; 613 - struct s3c2410_ts_mach_info *pdata = dev_get_platdata(&pdev->dev); 614 737 struct iio_dev *indio_dev = NULL; 615 - bool has_ts = false; 616 738 int ret; 617 739 int irq; 618 740 619 741 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct exynos_adc)); 620 - if (!indio_dev) { 621 - dev_err(&pdev->dev, "failed allocating iio device\n"); 742 + if (!indio_dev) 622 743 return -ENOMEM; 623 - } 624 744 625 745 info = iio_priv(indio_dev); 626 746 ··· 584 826 } 585 827 } 586 828 587 - /* leave out any TS related code if unreachable */ 588 - if (IS_REACHABLE(CONFIG_INPUT)) { 589 - has_ts = of_property_read_bool(pdev->dev.of_node, 590 - "has-touchscreen") || pdata; 591 - } 592 - 593 829 irq = platform_get_irq(pdev, 0); 594 830 if (irq < 0) 595 831 return irq; 596 832 info->irq = irq; 597 - 598 - if (has_ts) { 599 - irq = platform_get_irq(pdev, 1); 600 - if (irq == -EPROBE_DEFER) 601 - return irq; 602 - 603 - info->tsirq = irq; 604 - } else { 605 - info->tsirq = -1; 606 - } 607 - 608 833 info->dev = &pdev->dev; 609 834 610 835 init_completion(&info->completion); ··· 651 910 if (info->data->init_hw) 652 911 info->data->init_hw(info); 653 912 654 - if (pdata) 655 - info->delay = pdata->delay; 656 - else 657 - info->delay = 10000; 658 - 659 - if (has_ts) 660 - ret = exynos_adc_ts_init(info); 661 - if (ret) 662 - goto err_iio; 663 - 664 913 ret = of_platform_populate(np, exynos_adc_match, NULL, &indio_dev->dev); 665 914 if (ret < 0) { 666 915 dev_err(&pdev->dev, "failed adding child nodes\n"); ··· 662 931 err_of_populate: 663 932 device_for_each_child(&indio_dev->dev, NULL, 664 933 exynos_adc_remove_devices); 665 - if (has_ts) { 666 - input_unregister_device(info->input); 667 - free_irq(info->tsirq, info); 668 - } 669 - err_iio: 670 934 iio_device_unregister(indio_dev); 671 935 err_irq: 672 936 free_irq(info->irq, info); ··· 681 955 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 682 956 struct exynos_adc *info = iio_priv(indio_dev); 683 957 684 - if (IS_REACHABLE(CONFIG_INPUT) && info->input) { 685 - free_irq(info->tsirq, info); 686 - input_unregister_device(info->input); 687 - } 688 958 device_for_each_child(&indio_dev->dev, NULL, 689 959 exynos_adc_remove_devices); 690 960 iio_device_unregister(indio_dev);
+1 -1
drivers/iio/adc/hx711.c
··· 465 465 466 466 indio_dev = devm_iio_device_alloc(dev, sizeof(struct hx711_data)); 467 467 if (!indio_dev) 468 - return dev_err_probe(dev, -ENOMEM, "failed to allocate IIO device\n"); 468 + return -ENOMEM; 469 469 470 470 hx711_data = iio_priv(indio_dev); 471 471 hx711_data->dev = dev;
+1 -3
drivers/iio/adc/imx7d_adc.c
··· 482 482 int ret; 483 483 484 484 indio_dev = devm_iio_device_alloc(dev, sizeof(*info)); 485 - if (!indio_dev) { 486 - dev_err(&pdev->dev, "Failed allocating iio device\n"); 485 + if (!indio_dev) 487 486 return -ENOMEM; 488 - } 489 487 490 488 info = iio_priv(indio_dev); 491 489 info->dev = dev;
+1 -5
drivers/iio/adc/imx8qxp-adc.c
··· 229 229 ret = wait_for_completion_interruptible_timeout(&adc->completion, 230 230 IMX8QXP_ADC_TIMEOUT); 231 231 232 - pm_runtime_mark_last_busy(dev); 233 232 pm_runtime_put_sync_autosuspend(dev); 234 233 235 234 if (ret == 0) { ··· 294 295 295 296 *readval = readl(adc->regs + reg); 296 297 297 - pm_runtime_mark_last_busy(dev); 298 298 pm_runtime_put_sync_autosuspend(dev); 299 299 300 300 return 0; ··· 313 315 int ret; 314 316 315 317 indio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); 316 - if (!indio_dev) { 317 - dev_err(dev, "Failed allocating iio device\n"); 318 + if (!indio_dev) 318 319 return -ENOMEM; 319 - } 320 320 321 321 adc = iio_priv(indio_dev); 322 322 adc->dev = dev;
+18 -8
drivers/iio/adc/imx93_adc.c
··· 32 32 #define IMX93_ADC_PCDR0 0x100 33 33 #define IMX93_ADC_PCDR1 0x104 34 34 #define IMX93_ADC_PCDR2 0x108 35 - #define IMX93_ADC_PCDR3 0x10c 35 + #define IMX93_ADC_PCDR3 0x10C 36 36 #define IMX93_ADC_PCDR4 0x110 37 37 #define IMX93_ADC_PCDR5 0x114 38 38 #define IMX93_ADC_PCDR6 0x118 39 - #define IMX93_ADC_PCDR7 0x11c 39 + #define IMX93_ADC_PCDR7 0x11C 40 40 #define IMX93_ADC_CALSTAT 0x39C 41 + #define IMX93_ADC_CALCFG0 0x3A0 41 42 42 43 /* ADC bit shift */ 43 44 #define IMX93_ADC_MCR_MODE_MASK BIT(29) ··· 58 57 #define IMX93_ADC_IMR_EOC_MASK BIT(1) 59 58 #define IMX93_ADC_IMR_ECH_MASK BIT(0) 60 59 #define IMX93_ADC_PCDR_CDATA_MASK GENMASK(11, 0) 60 + 61 + #define IMX93_ADC_CALCFG0_LDFAIL_MASK BIT(4) 61 62 62 63 /* ADC status */ 63 64 #define IMX93_ADC_MSR_ADCSTATUS_IDLE 0 ··· 148 145 149 146 static int imx93_adc_calibration(struct imx93_adc *adc) 150 147 { 151 - u32 mcr, msr; 148 + u32 mcr, msr, calcfg; 152 149 int ret; 153 150 154 151 /* make sure ADC in power down mode */ ··· 160 157 writel(mcr, adc->regs + IMX93_ADC_MCR); 161 158 162 159 imx93_adc_power_up(adc); 160 + 161 + /* Enable loading of calibrated values even in fail condition */ 162 + calcfg = readl(adc->regs + IMX93_ADC_CALCFG0); 163 + calcfg |= IMX93_ADC_CALCFG0_LDFAIL_MASK; 164 + writel(calcfg, adc->regs + IMX93_ADC_CALCFG0); 163 165 164 166 /* 165 167 * TODO: we use the default TSAMP/NRSMPL/AVGEN in MCR, ··· 188 180 /* check whether calbration is success or not */ 189 181 msr = readl(adc->regs + IMX93_ADC_MSR); 190 182 if (msr & IMX93_ADC_MSR_CALFAIL_MASK) { 183 + /* 184 + * Only give warning here, this means the noise of the 185 + * reference voltage do not meet the requirement: 186 + * ADC reference voltage Noise < 1.8V * 1/2^ENOB 187 + * And the resault of ADC is not that accurate. 188 + */ 191 189 dev_warn(adc->dev, "ADC calibration failed!\n"); 192 - imx93_adc_power_down(adc); 193 - return -EAGAIN; 194 190 } 195 191 196 192 return 0; ··· 260 248 mutex_lock(&adc->lock); 261 249 ret = imx93_adc_read_channel_conversion(adc, chan->channel, val); 262 250 mutex_unlock(&adc->lock); 263 - pm_runtime_mark_last_busy(dev); 264 251 pm_runtime_put_sync_autosuspend(dev); 265 252 if (ret < 0) 266 253 return ret; ··· 319 308 320 309 indio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); 321 310 if (!indio_dev) 322 - return dev_err_probe(dev, -ENOMEM, 323 - "Failed allocating iio device\n"); 311 + return -ENOMEM; 324 312 325 313 adc = iio_priv(indio_dev); 326 314 adc->dev = dev;
+328
drivers/iio/adc/intel_dc_ti_adc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Intel Dollar Cove TI PMIC GPADC Driver 4 + * 5 + * Copyright (C) 2014 Intel Corporation (Ramakrishna Pallala <ramakrishna.pallala@intel.com>) 6 + * Copyright (C) 2024 - 2025 Hans de Goede <hansg@kernel.org> 7 + */ 8 + 9 + #include <linux/bits.h> 10 + #include <linux/bitfield.h> 11 + #include <linux/bitops.h> 12 + #include <linux/cleanup.h> 13 + #include <linux/delay.h> 14 + #include <linux/device.h> 15 + #include <linux/interrupt.h> 16 + #include <linux/mfd/intel_soc_pmic.h> 17 + #include <linux/mod_devicetable.h> 18 + #include <linux/module.h> 19 + #include <linux/mutex.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/regmap.h> 22 + #include <linux/wait.h> 23 + 24 + #include <linux/iio/driver.h> 25 + #include <linux/iio/iio.h> 26 + #include <linux/iio/machine.h> 27 + 28 + #define DC_TI_ADC_CNTL_REG 0x50 29 + #define DC_TI_ADC_START BIT(0) 30 + #define DC_TI_ADC_CH_SEL GENMASK(2, 1) 31 + #define DC_TI_ADC_EN BIT(5) 32 + #define DC_TI_ADC_EN_EXT_BPTH_BIAS BIT(6) 33 + 34 + #define DC_TI_VBAT_ZSE_GE_REG 0x53 35 + #define DC_TI_VBAT_GE GENMASK(3, 0) 36 + #define DC_TI_VBAT_ZSE GENMASK(7, 4) 37 + 38 + /* VBAT GE gain correction is in 0.0015 increments, ZSE is in 1.0 increments */ 39 + #define DC_TI_VBAT_GE_STEP 15 40 + #define DC_TI_VBAT_GE_DIV 10000 41 + 42 + #define DC_TI_ADC_DATA_REG_CH(x) (0x54 + 2 * (x)) 43 + 44 + enum dc_ti_adc_id { 45 + DC_TI_ADC_VBAT, 46 + DC_TI_ADC_PMICTEMP, 47 + DC_TI_ADC_BATTEMP, 48 + DC_TI_ADC_SYSTEMP0, 49 + }; 50 + 51 + struct dc_ti_adc_info { 52 + struct mutex lock; /* Protects against concurrent accesses to the ADC */ 53 + wait_queue_head_t wait; 54 + struct device *dev; 55 + struct regmap *regmap; 56 + int vbat_zse; 57 + int vbat_ge; 58 + bool conversion_done; 59 + }; 60 + 61 + static const struct iio_chan_spec dc_ti_adc_channels[] = { 62 + { 63 + .indexed = 1, 64 + .type = IIO_VOLTAGE, 65 + .channel = DC_TI_ADC_VBAT, 66 + .address = DC_TI_ADC_DATA_REG_CH(0), 67 + .datasheet_name = "CH0", 68 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 69 + BIT(IIO_CHAN_INFO_SCALE) | 70 + BIT(IIO_CHAN_INFO_PROCESSED), 71 + }, { 72 + .indexed = 1, 73 + .type = IIO_TEMP, 74 + .channel = DC_TI_ADC_PMICTEMP, 75 + .address = DC_TI_ADC_DATA_REG_CH(1), 76 + .datasheet_name = "CH1", 77 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 78 + }, { 79 + .indexed = 1, 80 + .type = IIO_TEMP, 81 + .channel = DC_TI_ADC_BATTEMP, 82 + .address = DC_TI_ADC_DATA_REG_CH(2), 83 + .datasheet_name = "CH2", 84 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 85 + }, { 86 + .indexed = 1, 87 + .type = IIO_TEMP, 88 + .channel = DC_TI_ADC_SYSTEMP0, 89 + .address = DC_TI_ADC_DATA_REG_CH(3), 90 + .datasheet_name = "CH3", 91 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 92 + } 93 + }; 94 + 95 + static struct iio_map dc_ti_adc_default_maps[] = { 96 + IIO_MAP("CH0", "chtdc_ti_battery", "VBAT"), 97 + IIO_MAP("CH1", "chtdc_ti_battery", "PMICTEMP"), 98 + IIO_MAP("CH2", "chtdc_ti_battery", "BATTEMP"), 99 + IIO_MAP("CH3", "chtdc_ti_battery", "SYSTEMP0"), 100 + { } 101 + }; 102 + 103 + static irqreturn_t dc_ti_adc_isr(int irq, void *data) 104 + { 105 + struct dc_ti_adc_info *info = data; 106 + 107 + info->conversion_done = true; 108 + wake_up(&info->wait); 109 + return IRQ_HANDLED; 110 + } 111 + 112 + static int dc_ti_adc_scale(struct dc_ti_adc_info *info, 113 + struct iio_chan_spec const *chan, 114 + int *val, int *val2) 115 + { 116 + if (chan->channel != DC_TI_ADC_VBAT) 117 + return -EINVAL; 118 + 119 + /* Vbat ADC scale is 4.6875 mV / unit */ 120 + *val = 4; 121 + *val2 = 687500; 122 + 123 + return IIO_VAL_INT_PLUS_MICRO; 124 + } 125 + 126 + static int dc_ti_adc_raw_to_processed(struct dc_ti_adc_info *info, 127 + struct iio_chan_spec const *chan, 128 + int raw, int *val, int *val2) 129 + { 130 + if (chan->channel != DC_TI_ADC_VBAT) 131 + return -EINVAL; 132 + 133 + /* Apply calibration */ 134 + raw -= info->vbat_zse; 135 + raw = raw * (DC_TI_VBAT_GE_DIV - info->vbat_ge * DC_TI_VBAT_GE_STEP) / 136 + DC_TI_VBAT_GE_DIV; 137 + /* Vbat ADC scale is 4.6875 mV / unit */ 138 + raw *= 46875; 139 + 140 + /* raw is now in 10000 units / mV, convert to milli + milli/1e6 */ 141 + *val = raw / 10000; 142 + *val2 = (raw % 10000) * 100; 143 + 144 + return IIO_VAL_INT_PLUS_MICRO; 145 + } 146 + 147 + static int dc_ti_adc_sample(struct dc_ti_adc_info *info, 148 + struct iio_chan_spec const *chan, int *val) 149 + { 150 + int ret, ch = chan->channel; 151 + __be16 buf; 152 + 153 + info->conversion_done = false; 154 + 155 + /* 156 + * As per TI (PMIC Vendor), the ADC enable and ADC start commands should 157 + * not be sent together. Hence send the commands separately. 158 + */ 159 + ret = regmap_set_bits(info->regmap, DC_TI_ADC_CNTL_REG, DC_TI_ADC_EN); 160 + if (ret) 161 + return ret; 162 + 163 + ret = regmap_update_bits(info->regmap, DC_TI_ADC_CNTL_REG, 164 + DC_TI_ADC_CH_SEL, 165 + FIELD_PREP(DC_TI_ADC_CH_SEL, ch)); 166 + if (ret) 167 + return ret; 168 + 169 + /* 170 + * As per PMIC Vendor, a minimum of 50 ųs delay is required between ADC 171 + * Enable and ADC START commands. This is also recommended by Intel 172 + * Hardware team after the timing analysis of GPADC signals. Since the 173 + * I2C Write transaction to set the channel number also imparts 25 ųs 174 + * delay, we need to wait for another 25 ųs before issuing ADC START. 175 + */ 176 + fsleep(25); 177 + 178 + ret = regmap_set_bits(info->regmap, DC_TI_ADC_CNTL_REG, 179 + DC_TI_ADC_START); 180 + if (ret) 181 + return ret; 182 + 183 + /* TI (PMIC Vendor) recommends 5 s timeout for conversion */ 184 + ret = wait_event_timeout(info->wait, info->conversion_done, 5 * HZ); 185 + if (ret == 0) { 186 + ret = -ETIMEDOUT; 187 + goto disable_adc; 188 + } 189 + 190 + ret = regmap_bulk_read(info->regmap, chan->address, &buf, sizeof(buf)); 191 + if (ret) 192 + goto disable_adc; 193 + 194 + /* The ADC values are 10 bits wide */ 195 + *val = be16_to_cpu(buf) & GENMASK(9, 0); 196 + 197 + disable_adc: 198 + regmap_clear_bits(info->regmap, DC_TI_ADC_CNTL_REG, 199 + DC_TI_ADC_START | DC_TI_ADC_EN); 200 + return ret; 201 + } 202 + 203 + static int dc_ti_adc_read_raw(struct iio_dev *indio_dev, 204 + struct iio_chan_spec const *chan, 205 + int *val, int *val2, long mask) 206 + { 207 + struct dc_ti_adc_info *info = iio_priv(indio_dev); 208 + int ret; 209 + 210 + if (mask == IIO_CHAN_INFO_SCALE) 211 + return dc_ti_adc_scale(info, chan, val, val2); 212 + 213 + guard(mutex)(&info->lock); 214 + 215 + /* 216 + * If channel BPTHERM has been selected, first enable the BPTHERM BIAS 217 + * which provides the VREF Voltage reference to convert BPTHERM Input 218 + * voltage to temperature. 219 + */ 220 + if (chan->channel == DC_TI_ADC_BATTEMP) { 221 + ret = regmap_set_bits(info->regmap, DC_TI_ADC_CNTL_REG, 222 + DC_TI_ADC_EN_EXT_BPTH_BIAS); 223 + if (ret) 224 + return ret; 225 + /* 226 + * As per PMIC Vendor specifications, BPTHERM BIAS should be 227 + * enabled 35 ms before ADC_EN command. 228 + */ 229 + msleep(35); 230 + } 231 + 232 + ret = dc_ti_adc_sample(info, chan, val); 233 + 234 + if (chan->channel == DC_TI_ADC_BATTEMP) 235 + regmap_clear_bits(info->regmap, DC_TI_ADC_CNTL_REG, 236 + DC_TI_ADC_EN_EXT_BPTH_BIAS); 237 + 238 + if (ret) 239 + return ret; 240 + 241 + switch (mask) { 242 + case IIO_CHAN_INFO_RAW: 243 + return IIO_VAL_INT; 244 + case IIO_CHAN_INFO_PROCESSED: 245 + return dc_ti_adc_raw_to_processed(info, chan, *val, val, val2); 246 + } 247 + 248 + return -EINVAL; 249 + } 250 + 251 + static const struct iio_info dc_ti_adc_iio_info = { 252 + .read_raw = dc_ti_adc_read_raw, 253 + }; 254 + 255 + static int dc_ti_adc_probe(struct platform_device *pdev) 256 + { 257 + struct device *dev = &pdev->dev; 258 + struct intel_soc_pmic *pmic = dev_get_drvdata(dev->parent); 259 + struct dc_ti_adc_info *info; 260 + struct iio_dev *indio_dev; 261 + unsigned int val; 262 + int irq, ret; 263 + 264 + irq = platform_get_irq(pdev, 0); 265 + if (irq < 0) 266 + return irq; 267 + 268 + indio_dev = devm_iio_device_alloc(dev, sizeof(*info)); 269 + if (!indio_dev) 270 + return -ENOMEM; 271 + 272 + info = iio_priv(indio_dev); 273 + 274 + ret = devm_mutex_init(dev, &info->lock); 275 + if (ret) 276 + return ret; 277 + 278 + init_waitqueue_head(&info->wait); 279 + 280 + info->dev = dev; 281 + info->regmap = pmic->regmap; 282 + 283 + indio_dev->name = "dc_ti_adc"; 284 + indio_dev->channels = dc_ti_adc_channels; 285 + indio_dev->num_channels = ARRAY_SIZE(dc_ti_adc_channels); 286 + indio_dev->info = &dc_ti_adc_iio_info; 287 + indio_dev->modes = INDIO_DIRECT_MODE; 288 + 289 + ret = regmap_read(info->regmap, DC_TI_VBAT_ZSE_GE_REG, &val); 290 + if (ret) 291 + return ret; 292 + 293 + info->vbat_zse = sign_extend32(FIELD_GET(DC_TI_VBAT_ZSE, val), 3); 294 + info->vbat_ge = sign_extend32(FIELD_GET(DC_TI_VBAT_GE, val), 3); 295 + 296 + dev_dbg(dev, "vbat-zse %d vbat-ge %d\n", info->vbat_zse, info->vbat_ge); 297 + 298 + ret = devm_iio_map_array_register(dev, indio_dev, dc_ti_adc_default_maps); 299 + if (ret) 300 + return ret; 301 + 302 + ret = devm_request_threaded_irq(dev, irq, NULL, dc_ti_adc_isr, 303 + IRQF_ONESHOT, indio_dev->name, info); 304 + if (ret) 305 + return ret; 306 + 307 + return devm_iio_device_register(dev, indio_dev); 308 + } 309 + 310 + static const struct platform_device_id dc_ti_adc_ids[] = { 311 + { .name = "chtdc_ti_adc" }, 312 + { } 313 + }; 314 + MODULE_DEVICE_TABLE(platform, dc_ti_adc_ids); 315 + 316 + static struct platform_driver dc_ti_adc_driver = { 317 + .driver = { 318 + .name = "dc_ti_adc", 319 + }, 320 + .probe = dc_ti_adc_probe, 321 + .id_table = dc_ti_adc_ids, 322 + }; 323 + module_platform_driver(dc_ti_adc_driver); 324 + 325 + MODULE_AUTHOR("Ramakrishna Pallala (Intel)"); 326 + MODULE_AUTHOR("Hans de Goede <hansg@kernel.org>"); 327 + MODULE_DESCRIPTION("Intel Dollar Cove (TI) GPADC Driver"); 328 + MODULE_LICENSE("GPL");
+1 -1
drivers/iio/adc/mcp3564.c
··· 1019 1019 1020 1020 channels = devm_kcalloc(dev, num_ch, sizeof(*channels), GFP_KERNEL); 1021 1021 if (!channels) 1022 - return dev_err_probe(dev, -ENOMEM, "Can't allocate memory\n"); 1022 + return -ENOMEM; 1023 1023 1024 1024 device_for_each_child_node_scoped(dev, child) { 1025 1025 node_name = fwnode_get_name(child);
+1 -1
drivers/iio/adc/meson_saradc.c
··· 1357 1357 1358 1358 indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); 1359 1359 if (!indio_dev) 1360 - return dev_err_probe(dev, -ENOMEM, "failed allocating iio device\n"); 1360 + return -ENOMEM; 1361 1361 1362 1362 priv = iio_priv(indio_dev); 1363 1363 init_completion(&priv->done);
+1 -2
drivers/iio/adc/mt6577_auxadc.c
··· 297 297 298 298 ret = devm_add_action_or_reset(&pdev->dev, mt6577_power_off, adc_dev); 299 299 if (ret) 300 - return dev_err_probe(&pdev->dev, ret, 301 - "Failed to add action to managed power off\n"); 300 + return ret; 302 301 303 302 ret = devm_iio_device_register(&pdev->dev, indio_dev); 304 303 if (ret < 0)
+1 -3
drivers/iio/adc/mxs-lradc-adc.c
··· 697 697 698 698 /* Allocate the IIO device. */ 699 699 iio = devm_iio_device_alloc(dev, sizeof(*adc)); 700 - if (!iio) { 701 - dev_err(dev, "Failed to allocate IIO device\n"); 700 + if (!iio) 702 701 return -ENOMEM; 703 - } 704 702 705 703 adc = iio_priv(iio); 706 704 adc->lradc = lradc;
+1 -2
drivers/iio/adc/pac1921.c
··· 1279 1279 ret = devm_add_action_or_reset(dev, pac1921_regulator_disable, 1280 1280 priv->vdd); 1281 1281 if (ret) 1282 - return dev_err_probe(dev, ret, 1283 - "Cannot add action for vdd regulator disposal\n"); 1282 + return ret; 1284 1283 1285 1284 msleep(PAC1921_POWERUP_TIME_MS); 1286 1285
+1 -10
drivers/iio/adc/pac1934.c
··· 1471 1471 return 0; 1472 1472 } 1473 1473 1474 - static void pac1934_mutex_destroy(void *data) 1475 - { 1476 - struct mutex *lock = data; 1477 - 1478 - mutex_destroy(lock); 1479 - } 1480 - 1481 1474 static const struct iio_info pac1934_info = { 1482 1475 .read_raw = pac1934_read_raw, 1483 1476 .write_raw = pac1934_write_raw, ··· 1529 1536 return dev_err_probe(dev, ret, 1530 1537 "parameter parsing returned an error\n"); 1531 1538 1532 - mutex_init(&info->lock); 1533 - ret = devm_add_action_or_reset(dev, pac1934_mutex_destroy, 1534 - &info->lock); 1539 + ret = devm_mutex_init(dev, &info->lock); 1535 1540 if (ret < 0) 1536 1541 return ret; 1537 1542
+1 -3
drivers/iio/adc/palmas_gpadc.c
··· 885 885 return -EINVAL; 886 886 887 887 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc)); 888 - if (!indio_dev) { 889 - dev_err(&pdev->dev, "iio_device_alloc failed\n"); 888 + if (!indio_dev) 890 889 return -ENOMEM; 891 - } 892 890 893 891 adc = iio_priv(indio_dev); 894 892 adc->dev = &pdev->dev;
+3 -5
drivers/iio/adc/rcar-gyroadc.c
··· 163 163 { 164 164 struct device *dev = priv->dev; 165 165 166 - if (on) { 166 + if (on) 167 167 return pm_runtime_resume_and_get(dev); 168 - } else { 169 - pm_runtime_mark_last_busy(dev); 170 - return pm_runtime_put_autosuspend(dev); 171 - } 168 + 169 + return pm_runtime_put_autosuspend(dev); 172 170 } 173 171 174 172 static int rcar_gyroadc_read_raw(struct iio_dev *indio_dev,
+1 -3
drivers/iio/adc/rn5t618-adc.c
··· 199 199 struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent); 200 200 201 201 iio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc)); 202 - if (!iio_dev) { 203 - dev_err(&pdev->dev, "failed allocating iio device\n"); 202 + if (!iio_dev) 204 203 return -ENOMEM; 205 - } 206 204 207 205 adc = iio_priv(iio_dev); 208 206 adc->dev = &pdev->dev;
+2 -4
drivers/iio/adc/rockchip_saradc.c
··· 466 466 467 467 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); 468 468 if (!indio_dev) 469 - return dev_err_probe(&pdev->dev, -ENOMEM, 470 - "failed allocating iio device\n"); 469 + return -ENOMEM; 471 470 472 471 info = iio_priv(indio_dev); 473 472 ··· 526 527 ret = devm_add_action_or_reset(&pdev->dev, 527 528 rockchip_saradc_regulator_disable, info); 528 529 if (ret) 529 - return dev_err_probe(&pdev->dev, ret, 530 - "failed to register devm action\n"); 530 + return ret; 531 531 532 532 ret = regulator_get_voltage(info->vref); 533 533 if (ret < 0)
+556
drivers/iio/adc/rohm-bd79112.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * ROHM ADC driver for BD79112 signal monitoring hub. 4 + * Copyright (C) 2025, ROHM Semiconductor. 5 + * 6 + * SPI communication derived from ad7923.c and ti-ads7950.c 7 + */ 8 + 9 + #include <linux/array_size.h> 10 + #include <linux/bitfield.h> 11 + #include <linux/bitops.h> 12 + #include <linux/bits.h> 13 + #include <linux/dev_printk.h> 14 + #include <linux/err.h> 15 + #include <linux/errno.h> 16 + #include <linux/gpio/driver.h> 17 + #include <linux/mod_devicetable.h> 18 + #include <linux/module.h> 19 + #include <linux/regmap.h> 20 + #include <linux/regulator/consumer.h> 21 + #include <linux/spi/spi.h> 22 + #include <linux/types.h> 23 + #include <asm/byteorder.h> 24 + 25 + #include <linux/iio/adc-helpers.h> 26 + #include <linux/iio/iio.h> 27 + 28 + #define BD79112_MAX_NUM_CHANNELS 32 29 + 30 + struct bd79112_data { 31 + struct spi_device *spi; 32 + struct regmap *map; 33 + struct device *dev; 34 + struct gpio_chip gc; 35 + unsigned long gpio_valid_mask; 36 + unsigned int vref_mv; 37 + struct spi_transfer read_xfer[2]; 38 + struct spi_transfer write_xfer; 39 + struct spi_message read_msg; 40 + struct spi_message write_msg; 41 + /* 16-bit TX, valid data in high byte */ 42 + u8 read_tx[2] __aligned(IIO_DMA_MINALIGN); 43 + /* 8-bit address followed by 8-bit data */ 44 + u8 reg_write_tx[2]; 45 + /* 12-bit of ADC data or 8 bit of reg data */ 46 + __be16 read_rx; 47 + }; 48 + 49 + /* 50 + * The ADC data is read issuing SPI-command matching the channel number. 51 + * We treat this as a register address. 52 + */ 53 + #define BD79112_REG_AGIO0A 0x00 54 + #define BD79112_REG_AGIO15B 0x1f 55 + 56 + /* 57 + * ADC STATUS_FLAG appended to ADC data will be set, if the ADC result is being 58 + * read for a channel, which input pin is muxed to be a GPIO. 59 + */ 60 + #define BD79112_ADC_STATUS_FLAG BIT(14) 61 + 62 + /* 63 + * The BD79112 requires "R/W bit" to be set for SPI register (not ADC data) 64 + * reads and an "IOSET bit" to be set for read/write operations (which aren't 65 + * reading the ADC data). 66 + */ 67 + #define BD79112_BIT_RW BIT(4) 68 + #define BD79112_BIT_IO BIT(5) 69 + 70 + #define BD79112_REG_GPI_VALUE_B8_15 (BD79112_BIT_IO | 0x0) 71 + #define BD79112_REG_GPI_VALUE_B0_B7 (BD79112_BIT_IO | 0x1) 72 + #define BD79112_REG_GPI_VALUE_A8_15 (BD79112_BIT_IO | 0x2) 73 + #define BD79112_REG_GPI_VALUE_A0_A7 (BD79112_BIT_IO | 0x3) 74 + 75 + #define BD79112_REG_GPI_EN_B7_B15 (BD79112_BIT_IO | 0x4) 76 + #define BD79112_REG_GPI_EN_B0_B7 (BD79112_BIT_IO | 0x5) 77 + #define BD79112_REG_GPI_EN_A8_A15 (BD79112_BIT_IO | 0x6) 78 + #define BD79112_REG_GPI_EN_A0_A7 (BD79112_BIT_IO | 0x7) 79 + 80 + #define BD79112_REG_GPO_EN_B7_B15 (BD79112_BIT_IO | 0x8) 81 + #define BD79112_REG_GPO_EN_B0_B7 (BD79112_BIT_IO | 0x9) 82 + #define BD79112_REG_GPO_EN_A8_A15 (BD79112_BIT_IO | 0xa) 83 + #define BD79112_REG_GPO_EN_A0_A7 (BD79112_BIT_IO | 0xb) 84 + 85 + #define BD79112_NUM_GPIO_EN_REGS 8 86 + #define BD79112_FIRST_GPIO_EN_REG BD79112_REG_GPI_EN_B7_B15 87 + 88 + #define BD79112_REG_GPO_VALUE_B8_15 (BD79112_BIT_IO | 0xc) 89 + #define BD79112_REG_GPO_VALUE_B0_B7 (BD79112_BIT_IO | 0xd) 90 + #define BD79112_REG_GPO_VALUE_A8_15 (BD79112_BIT_IO | 0xe) 91 + #define BD79112_REG_GPO_VALUE_A0_A7 (BD79112_BIT_IO | 0xf) 92 + 93 + #define BD79112_REG_MAX BD79112_REG_GPO_VALUE_A0_A7 94 + 95 + /* 96 + * Read transaction consists of two 16-bit sequences separated by CSB. 97 + * For register read, 'IOSET' bit must be set. For ADC read, IOSET is cleared 98 + * and ADDR equals the channel number (0 ... 31). 99 + * 100 + * First 16-bit sequence, MOSI as below, MISO data ignored: 101 + * - SCK: | 1 | 2 | 3 | 4 | 5 .. 8 | 9 .. 16 | 102 + * - MOSI:| 0 | 0 | IOSET | RW (1) | ADDR | 8'b0 | 103 + * 104 + * CSB released and re-acquired between these sequences 105 + * 106 + * Second 16-bit sequence, MISO as below, MOSI data ignored: 107 + * For Register read data is 8 bits: 108 + * - SCK: | 1 .. 8 | 9 .. 16 | 109 + * - MISO:| 8'b0 | 8-bit data | 110 + * 111 + * For ADC read data is 12 bits: 112 + * - SCK: | 1 | 2 | 3 4 | 4 .. 16 | 113 + * - MISO:| 0 | STATUS_FLAG | 2'b0 | 12-bit data | 114 + * The 'STATUS_FLAG' is set if the read input pin was configured as a GPIO. 115 + */ 116 + static int bd79112_reg_read(void *context, unsigned int reg, unsigned int *val) 117 + { 118 + struct bd79112_data *data = context; 119 + int ret; 120 + 121 + if (reg & BD79112_BIT_IO) 122 + reg |= BD79112_BIT_RW; 123 + 124 + data->read_tx[0] = reg; 125 + 126 + ret = spi_sync(data->spi, &data->read_msg); 127 + if (!ret) 128 + *val = be16_to_cpu(data->read_rx); 129 + 130 + return ret; 131 + } 132 + 133 + /* 134 + * Write, single 16-bit sequence (broken down below): 135 + * 136 + * First 8-bit, MOSI as below, MISO data ignored: 137 + * - SCK: | 1 | 2 | 3 | 4 | 5 .. 8 | 138 + * - MOSI:| 0 | 0 |IOSET| RW(0) | ADDR | 139 + * 140 + * Last 8 SCK cycles (b8 ... b15), MISO contains register data, MOSI ignored. 141 + * - SCK: | 9 .. 16 | 142 + * - MISO:| data | 143 + */ 144 + static int bd79112_reg_write(void *context, unsigned int reg, unsigned int val) 145 + { 146 + struct bd79112_data *data = context; 147 + 148 + data->reg_write_tx[0] = reg; 149 + data->reg_write_tx[1] = val; 150 + 151 + return spi_sync(data->spi, &data->write_msg); 152 + } 153 + 154 + static int _get_gpio_reg(unsigned int offset, unsigned int base) 155 + { 156 + int regoffset = offset / 8; 157 + 158 + if (offset > 31) 159 + return -EINVAL; 160 + 161 + return base - regoffset; 162 + } 163 + 164 + #define GET_GPIO_BIT(offset) BIT((offset) % 8) 165 + #define GET_GPO_EN_REG(offset) _get_gpio_reg((offset), BD79112_REG_GPO_EN_A0_A7) 166 + #define GET_GPI_EN_REG(offset) _get_gpio_reg((offset), BD79112_REG_GPI_EN_A0_A7) 167 + #define GET_GPO_VAL_REG(offset) _get_gpio_reg((offset), BD79112_REG_GPO_VALUE_A0_A7) 168 + #define GET_GPI_VAL_REG(offset) _get_gpio_reg((offset), BD79112_REG_GPI_VALUE_A0_A7) 169 + 170 + static const struct regmap_range bd71815_volatile_ro_ranges[] = { 171 + { 172 + /* Read ADC data */ 173 + .range_min = BD79112_REG_AGIO0A, 174 + .range_max = BD79112_REG_AGIO15B, 175 + }, { 176 + /* GPI state */ 177 + .range_min = BD79112_REG_GPI_VALUE_B8_15, 178 + .range_max = BD79112_REG_GPI_VALUE_A0_A7, 179 + }, 180 + }; 181 + 182 + static const struct regmap_access_table bd79112_volatile_regs = { 183 + .yes_ranges = &bd71815_volatile_ro_ranges[0], 184 + .n_yes_ranges = ARRAY_SIZE(bd71815_volatile_ro_ranges), 185 + }; 186 + 187 + static const struct regmap_access_table bd79112_ro_regs = { 188 + .no_ranges = &bd71815_volatile_ro_ranges[0], 189 + .n_no_ranges = ARRAY_SIZE(bd71815_volatile_ro_ranges), 190 + }; 191 + 192 + static const struct regmap_config bd79112_regmap = { 193 + .reg_read = bd79112_reg_read, 194 + .reg_write = bd79112_reg_write, 195 + .volatile_table = &bd79112_volatile_regs, 196 + .wr_table = &bd79112_ro_regs, 197 + .cache_type = REGCACHE_MAPLE, 198 + .max_register = BD79112_REG_MAX, 199 + }; 200 + 201 + static int bd79112_read_raw(struct iio_dev *indio_dev, 202 + struct iio_chan_spec const *chan, int *val, 203 + int *val2, long m) 204 + { 205 + struct bd79112_data *data = iio_priv(indio_dev); 206 + int ret; 207 + 208 + switch (m) { 209 + case IIO_CHAN_INFO_RAW: 210 + ret = regmap_read(data->map, chan->channel, val); 211 + if (ret < 0) 212 + return ret; 213 + 214 + return IIO_VAL_INT; 215 + 216 + case IIO_CHAN_INFO_SCALE: 217 + *val = data->vref_mv; 218 + *val2 = 12; 219 + 220 + return IIO_VAL_FRACTIONAL_LOG2; 221 + default: 222 + return -EINVAL; 223 + } 224 + } 225 + 226 + static const struct iio_info bd79112_info = { 227 + .read_raw = bd79112_read_raw, 228 + }; 229 + 230 + static const struct iio_chan_spec bd79112_chan_template = { 231 + .type = IIO_VOLTAGE, 232 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 233 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 234 + .indexed = 1, 235 + }; 236 + 237 + static int bd79112_gpio_init_valid_mask(struct gpio_chip *gc, 238 + unsigned long *valid_mask, 239 + unsigned int ngpios) 240 + { 241 + struct bd79112_data *data = gpiochip_get_data(gc); 242 + 243 + *valid_mask = data->gpio_valid_mask; 244 + 245 + return 0; 246 + } 247 + 248 + static int bd79112_gpio_dir_get(struct gpio_chip *gc, unsigned int offset) 249 + { 250 + struct bd79112_data *data = gpiochip_get_data(gc); 251 + unsigned int reg, bit, val; 252 + int ret; 253 + 254 + bit = GET_GPIO_BIT(offset); 255 + reg = GET_GPO_EN_REG(offset); 256 + 257 + ret = regmap_read(data->map, reg, &val); 258 + if (ret) 259 + return ret; 260 + 261 + if (bit & val) 262 + return GPIO_LINE_DIRECTION_OUT; 263 + 264 + reg = GET_GPI_EN_REG(offset); 265 + ret = regmap_read(data->map, reg, &val); 266 + if (ret) 267 + return ret; 268 + 269 + if (bit & val) 270 + return GPIO_LINE_DIRECTION_IN; 271 + 272 + /* 273 + * Ouch. Seems the pin is ADC input - shouldn't happen as changing mux 274 + * at runtime is not supported and non GPIO pins should be invalidated 275 + * by the valid_mask at probe. Maybe someone wrote a register bypassing 276 + * the driver? 277 + */ 278 + dev_err(data->dev, "Pin not a GPIO\n"); 279 + 280 + return -EINVAL; 281 + } 282 + 283 + static int bd79112_gpio_get(struct gpio_chip *gc, unsigned int offset) 284 + { 285 + struct bd79112_data *data = gpiochip_get_data(gc); 286 + unsigned int reg, bit, val; 287 + int ret; 288 + 289 + bit = GET_GPIO_BIT(offset); 290 + reg = GET_GPI_VAL_REG(offset); 291 + 292 + ret = regmap_read(data->map, reg, &val); 293 + if (ret) 294 + return ret; 295 + 296 + return !!(val & bit); 297 + } 298 + 299 + static int bd79112_gpio_set(struct gpio_chip *gc, unsigned int offset, 300 + int value) 301 + { 302 + struct bd79112_data *data = gpiochip_get_data(gc); 303 + unsigned int reg, bit; 304 + 305 + bit = GET_GPIO_BIT(offset); 306 + reg = GET_GPO_VAL_REG(offset); 307 + 308 + return regmap_assign_bits(data->map, reg, bit, value); 309 + } 310 + 311 + static int bd79112_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, 312 + unsigned long *bits) 313 + { 314 + struct bd79112_data *data = gpiochip_get_data(gc); 315 + unsigned long i, bank_mask; 316 + 317 + for_each_set_clump8(i, bank_mask, mask, gc->ngpio) { 318 + unsigned long bank_bits; 319 + unsigned int reg; 320 + int ret; 321 + 322 + bank_bits = bitmap_get_value8(bits, i); 323 + reg = BD79112_REG_GPO_VALUE_A0_A7 - i / 8; 324 + ret = regmap_update_bits(data->map, reg, bank_mask, bank_bits); 325 + if (ret) 326 + return ret; 327 + } 328 + 329 + return 0; 330 + } 331 + 332 + static int bd79112_gpio_dir_set(struct bd79112_data *data, unsigned int offset, 333 + int dir) 334 + { 335 + unsigned int gpi_reg, gpo_reg, bit; 336 + int ret; 337 + 338 + bit = GET_GPIO_BIT(offset); 339 + gpi_reg = GET_GPI_EN_REG(offset); 340 + gpo_reg = GET_GPO_EN_REG(offset); 341 + 342 + if (dir == GPIO_LINE_DIRECTION_OUT) { 343 + ret = regmap_clear_bits(data->map, gpi_reg, bit); 344 + if (ret) 345 + return ret; 346 + 347 + return regmap_set_bits(data->map, gpo_reg, bit); 348 + } 349 + 350 + ret = regmap_set_bits(data->map, gpi_reg, bit); 351 + if (ret) 352 + return ret; 353 + 354 + return regmap_clear_bits(data->map, gpo_reg, bit); 355 + } 356 + 357 + static int bd79112_gpio_input(struct gpio_chip *gc, unsigned int offset) 358 + { 359 + struct bd79112_data *data = gpiochip_get_data(gc); 360 + 361 + return bd79112_gpio_dir_set(data, offset, GPIO_LINE_DIRECTION_IN); 362 + } 363 + 364 + static int bd79112_gpio_output(struct gpio_chip *gc, unsigned int offset, 365 + int value) 366 + { 367 + struct bd79112_data *data = gpiochip_get_data(gc); 368 + int ret; 369 + 370 + ret = bd79112_gpio_set(gc, offset, value); 371 + if (ret) 372 + return ret; 373 + 374 + return bd79112_gpio_dir_set(data, offset, GPIO_LINE_DIRECTION_OUT); 375 + } 376 + 377 + static const struct gpio_chip bd79112_gpio_chip = { 378 + .label = "bd79112-gpio", 379 + .get_direction = bd79112_gpio_dir_get, 380 + .direction_input = bd79112_gpio_input, 381 + .direction_output = bd79112_gpio_output, 382 + .get = bd79112_gpio_get, 383 + .set = bd79112_gpio_set, 384 + .set_multiple = bd79112_gpio_set_multiple, 385 + .init_valid_mask = bd79112_gpio_init_valid_mask, 386 + .can_sleep = true, 387 + .ngpio = 32, 388 + .base = -1, 389 + }; 390 + 391 + static unsigned int bd79112_get_gpio_pins(const struct iio_chan_spec *cs, int num_channels) 392 + { 393 + unsigned int i, gpio_channels; 394 + 395 + /* 396 + * Let's initialize the mux config to say that all 32 channels are 397 + * GPIOs. Then we can just loop through the iio_chan_spec and clear the 398 + * bits for found ADC channels. 399 + */ 400 + gpio_channels = GENMASK(31, 0); 401 + for (i = 0; i < num_channels; i++) 402 + gpio_channels &= ~BIT(cs[i].channel); 403 + 404 + return gpio_channels; 405 + } 406 + 407 + /* ADC channels as named in the data-sheet */ 408 + static const char * const bd79112_chan_names[] = { 409 + "AGIO0A", "AGIO1A", "AGIO2A", "AGIO3A", /* 0 - 3 */ 410 + "AGIO4A", "AGIO5A", "AGIO6A", "AGIO7A", /* 4 - 7 */ 411 + "AGIO8A", "AGIO9A", "AGIO10A", "AGIO11A", /* 8 - 11 */ 412 + "AGIO12A", "AGIO13A", "AGIO14A", "AGIO15A", /* 12 - 15 */ 413 + "AGIO0B", "AGIO1B", "AGIO2B", "AGIO3B", /* 16 - 19 */ 414 + "AGIO4B", "AGIO5B", "AGIO6B", "AGIO7B", /* 20 - 23 */ 415 + "AGIO8B", "AGIO9B", "AGIO10B", "AGIO11B", /* 24 - 27 */ 416 + "AGIO12B", "AGIO13B", "AGIO14B", "AGIO15B", /* 28 - 31 */ 417 + }; 418 + 419 + static int bd79112_probe(struct spi_device *spi) 420 + { 421 + struct bd79112_data *data; 422 + struct iio_dev *iio_dev; 423 + struct iio_chan_spec *cs; 424 + struct device *dev = &spi->dev; 425 + unsigned long gpio_pins, pin; 426 + unsigned int i; 427 + int ret; 428 + 429 + iio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 430 + if (!iio_dev) 431 + return -ENOMEM; 432 + 433 + data = iio_priv(iio_dev); 434 + data->spi = spi; 435 + data->dev = dev; 436 + data->map = devm_regmap_init(dev, NULL, data, &bd79112_regmap); 437 + if (IS_ERR(data->map)) 438 + return dev_err_probe(dev, PTR_ERR(data->map), 439 + "Failed to initialize Regmap\n"); 440 + 441 + ret = devm_regulator_get_enable_read_voltage(dev, "vdd"); 442 + if (ret < 0) 443 + return dev_err_probe(dev, ret, "Failed to get the Vdd\n"); 444 + 445 + data->vref_mv = ret / 1000; 446 + 447 + ret = devm_regulator_get_enable(dev, "iovdd"); 448 + if (ret < 0) 449 + return dev_err_probe(dev, ret, "Failed to enable I/O voltage\n"); 450 + 451 + data->read_xfer[0].tx_buf = &data->read_tx[0]; 452 + data->read_xfer[0].len = sizeof(data->read_tx); 453 + data->read_xfer[0].cs_change = 1; 454 + data->read_xfer[1].rx_buf = &data->read_rx; 455 + data->read_xfer[1].len = sizeof(data->read_rx); 456 + spi_message_init_with_transfers(&data->read_msg, data->read_xfer, 2); 457 + ret = devm_spi_optimize_message(dev, spi, &data->read_msg); 458 + if (ret < 0) 459 + return dev_err_probe(dev, ret, 460 + "Failed to optimize SPI read message\n"); 461 + 462 + data->write_xfer.tx_buf = &data->reg_write_tx[0]; 463 + data->write_xfer.len = sizeof(data->reg_write_tx); 464 + spi_message_init_with_transfers(&data->write_msg, &data->write_xfer, 1); 465 + ret = devm_spi_optimize_message(dev, spi, &data->write_msg); 466 + if (ret < 0) 467 + return dev_err_probe(dev, ret, 468 + "Failed to optimize SPI write message\n"); 469 + 470 + ret = devm_iio_adc_device_alloc_chaninfo_se(dev, &bd79112_chan_template, 471 + BD79112_MAX_NUM_CHANNELS - 1, 472 + &cs); 473 + 474 + /* Register all pins as GPIOs if there are no ADC channels */ 475 + if (ret == -ENOENT) 476 + goto register_gpios; 477 + 478 + if (ret < 0) 479 + return ret; 480 + 481 + iio_dev->num_channels = ret; 482 + iio_dev->channels = cs; 483 + 484 + for (i = 0; i < iio_dev->num_channels; i++) 485 + cs[i].datasheet_name = bd79112_chan_names[cs[i].channel]; 486 + 487 + iio_dev->info = &bd79112_info; 488 + iio_dev->name = "bd79112"; 489 + iio_dev->modes = INDIO_DIRECT_MODE; 490 + 491 + /* 492 + * Ensure all channels are ADCs. This allows us to register the IIO 493 + * device early (before checking which pins are to be used for GPIO) 494 + * without having to worry about some pins being initially used for 495 + * GPIO. 496 + */ 497 + for (i = 0; i < BD79112_NUM_GPIO_EN_REGS; i++) { 498 + ret = regmap_write(data->map, BD79112_FIRST_GPIO_EN_REG + i, 0); 499 + if (ret) 500 + return dev_err_probe(dev, ret, 501 + "Failed to initialize channels\n"); 502 + } 503 + 504 + ret = devm_iio_device_register(data->dev, iio_dev); 505 + if (ret) 506 + return dev_err_probe(data->dev, ret, "Failed to register ADC\n"); 507 + 508 + register_gpios: 509 + gpio_pins = bd79112_get_gpio_pins(iio_dev->channels, 510 + iio_dev->num_channels); 511 + 512 + /* If all channels are reserved for ADC, then we're done. */ 513 + if (!gpio_pins) 514 + return 0; 515 + 516 + /* Default all the GPIO pins to GPI */ 517 + for_each_set_bit(pin, &gpio_pins, BD79112_MAX_NUM_CHANNELS) { 518 + ret = bd79112_gpio_dir_set(data, pin, GPIO_LINE_DIRECTION_IN); 519 + if (ret) 520 + return dev_err_probe(dev, ret, 521 + "Failed to mark pin as GPI\n"); 522 + } 523 + 524 + data->gpio_valid_mask = gpio_pins; 525 + data->gc = bd79112_gpio_chip; 526 + data->gc.parent = dev; 527 + 528 + return devm_gpiochip_add_data(dev, &data->gc, data); 529 + } 530 + 531 + static const struct of_device_id bd79112_of_match[] = { 532 + { .compatible = "rohm,bd79112" }, 533 + { } 534 + }; 535 + MODULE_DEVICE_TABLE(of, bd79112_of_match); 536 + 537 + static const struct spi_device_id bd79112_id[] = { 538 + { "bd79112" }, 539 + { } 540 + }; 541 + MODULE_DEVICE_TABLE(spi, bd79112_id); 542 + 543 + static struct spi_driver bd79112_driver = { 544 + .driver = { 545 + .name = "bd79112", 546 + .of_match_table = bd79112_of_match, 547 + }, 548 + .probe = bd79112_probe, 549 + .id_table = bd79112_id, 550 + }; 551 + module_spi_driver(bd79112_driver); 552 + 553 + MODULE_AUTHOR("Matti Vaittinen <mazziesaccount@gmail.com>"); 554 + MODULE_DESCRIPTION("Driver for ROHM BD79112 ADC/GPIO"); 555 + MODULE_LICENSE("GPL"); 556 + MODULE_IMPORT_NS("IIO_DRIVER");
-2
drivers/iio/adc/rzg2l_adc.c
··· 248 248 rzg2l_adc_start_stop(adc, false); 249 249 250 250 rpm_put: 251 - pm_runtime_mark_last_busy(dev); 252 251 pm_runtime_put_autosuspend(dev); 253 252 return ret; 254 253 } ··· 409 410 rzg2l_adc_writel(adc, RZG2L_ADM(3), reg); 410 411 411 412 exit_hw_init: 412 - pm_runtime_mark_last_busy(dev); 413 413 pm_runtime_put_autosuspend(dev); 414 414 return ret; 415 415 }
+6 -6
drivers/iio/adc/spear_adc.c
··· 14 14 #include <linux/kernel.h> 15 15 #include <linux/slab.h> 16 16 #include <linux/io.h> 17 + #include <linux/bitfield.h> 17 18 #include <linux/clk.h> 18 19 #include <linux/err.h> 19 20 #include <linux/completion.h> ··· 30 29 31 30 /* Bit definitions for SPEAR_ADC_STATUS */ 32 31 #define SPEAR_ADC_STATUS_START_CONVERSION BIT(0) 33 - #define SPEAR_ADC_STATUS_CHANNEL_NUM(x) ((x) << 1) 32 + #define SPEAR_ADC_STATUS_CHANNEL_NUM_MASK GENMASK(3, 1) 34 33 #define SPEAR_ADC_STATUS_ADC_ENABLE BIT(4) 35 - #define SPEAR_ADC_STATUS_AVG_SAMPLE(x) ((x) << 5) 34 + #define SPEAR_ADC_STATUS_AVG_SAMPLE_MASK GENMASK(8, 5) 36 35 #define SPEAR_ADC_STATUS_VREF_INTERNAL BIT(9) 37 36 38 37 #define SPEAR_ADC_DATA_MASK 0x03ff ··· 158 157 case IIO_CHAN_INFO_RAW: 159 158 mutex_lock(&st->lock); 160 159 161 - status = SPEAR_ADC_STATUS_CHANNEL_NUM(chan->channel) | 162 - SPEAR_ADC_STATUS_AVG_SAMPLE(st->avg_samples) | 160 + status = FIELD_PREP(SPEAR_ADC_STATUS_CHANNEL_NUM_MASK, chan->channel) | 161 + FIELD_PREP(SPEAR_ADC_STATUS_AVG_SAMPLE_MASK, st->avg_samples) | 163 162 SPEAR_ADC_STATUS_START_CONVERSION | 164 163 SPEAR_ADC_STATUS_ADC_ENABLE; 165 164 if (st->vref_external == 0) ··· 275 274 276 275 indio_dev = devm_iio_device_alloc(dev, sizeof(struct spear_adc_state)); 277 276 if (!indio_dev) 278 - return dev_err_probe(dev, -ENOMEM, 279 - "failed allocating iio device\n"); 277 + return -ENOMEM; 280 278 281 279 st = iio_priv(indio_dev); 282 280 st->dev = dev;
-1
drivers/iio/adc/stm32-adc-core.c
··· 794 794 goto err_irq_remove; 795 795 } 796 796 797 - pm_runtime_mark_last_busy(dev); 798 797 pm_runtime_put_autosuspend(dev); 799 798 800 799 return 0;
-7
drivers/iio/adc/stm32-adc.c
··· 1528 1528 1529 1529 stm32_adc_conv_irq_disable(adc); 1530 1530 1531 - pm_runtime_mark_last_busy(dev); 1532 1531 pm_runtime_put_autosuspend(dev); 1533 1532 1534 1533 return ret; ··· 1563 1564 1564 1565 adc->cfg->set_ovs(indio_dev, idx); 1565 1566 1566 - pm_runtime_mark_last_busy(dev); 1567 1567 pm_runtime_put_autosuspend(dev); 1568 1568 1569 1569 adc->ovs_idx = idx; ··· 1757 1759 adc->num_conv = bitmap_weight(scan_mask, iio_get_masklength(indio_dev)); 1758 1760 1759 1761 ret = stm32_adc_conf_scan_seq(indio_dev, scan_mask); 1760 - pm_runtime_mark_last_busy(dev); 1761 1762 pm_runtime_put_autosuspend(dev); 1762 1763 1763 1764 return ret; ··· 1805 1808 else 1806 1809 *readval = stm32_adc_readl(adc, reg); 1807 1810 1808 - pm_runtime_mark_last_busy(dev); 1809 1811 pm_runtime_put_autosuspend(dev); 1810 1812 1811 1813 return 0; ··· 1950 1954 err_clr_trig: 1951 1955 stm32_adc_set_trig(indio_dev, NULL); 1952 1956 err_pm_put: 1953 - pm_runtime_mark_last_busy(dev); 1954 1957 pm_runtime_put_autosuspend(dev); 1955 1958 1956 1959 return ret; ··· 1972 1977 if (stm32_adc_set_trig(indio_dev, NULL)) 1973 1978 dev_err(&indio_dev->dev, "Can't clear trigger\n"); 1974 1979 1975 - pm_runtime_mark_last_busy(dev); 1976 1980 pm_runtime_put_autosuspend(dev); 1977 1981 1978 1982 return 0; ··· 2608 2614 goto err_hw_stop; 2609 2615 } 2610 2616 2611 - pm_runtime_mark_last_busy(dev); 2612 2617 pm_runtime_put_autosuspend(dev); 2613 2618 2614 2619 if (IS_ENABLED(CONFIG_DEBUG_FS))
+1 -3
drivers/iio/adc/stm32-dfsdm-adc.c
··· 1764 1764 1765 1765 dev_data = of_device_get_match_data(dev); 1766 1766 iio = devm_iio_device_alloc(dev, sizeof(*adc)); 1767 - if (!iio) { 1768 - dev_err(dev, "%s: Failed to allocate IIO\n", __func__); 1767 + if (!iio) 1769 1768 return -ENOMEM; 1770 - } 1771 1769 1772 1770 adc = iio_priv(iio); 1773 1771 adc->dfsdm = dev_get_drvdata(dev->parent);
+1 -3
drivers/iio/adc/stmpe-adc.c
··· 267 267 return irq_adc; 268 268 269 269 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct stmpe_adc)); 270 - if (!indio_dev) { 271 - dev_err(&pdev->dev, "failed allocating iio device\n"); 270 + if (!indio_dev) 272 271 return -ENOMEM; 273 - } 274 272 275 273 info = iio_priv(indio_dev); 276 274 mutex_init(&info->lock);
-3
drivers/iio/adc/sun4i-gpadc-iio.c
··· 154 154 .reg_bits = 32, 155 155 .val_bits = 32, 156 156 .reg_stride = 4, 157 - .fast_io = true, 158 157 }; 159 158 160 159 static int sun4i_prepare_for_irq(struct iio_dev *indio_dev, int channel, ··· 244 245 *val = info->temp_data; 245 246 246 247 ret = 0; 247 - pm_runtime_mark_last_busy(indio_dev->dev.parent); 248 248 249 249 err: 250 250 pm_runtime_put_autosuspend(indio_dev->dev.parent); ··· 270 272 271 273 regmap_read(info->regmap, SUN4I_GPADC_TEMP_DATA, val); 272 274 273 - pm_runtime_mark_last_busy(indio_dev->dev.parent); 274 275 pm_runtime_put_autosuspend(indio_dev->dev.parent); 275 276 276 277 return 0;
+18 -22
drivers/iio/adc/ti-adc081c.c
··· 102 102 int bits; 103 103 }; 104 104 105 - #define ADCxx1C_MODEL(_name, _bits) \ 106 - { \ 107 - .channels = _name ## _channels, \ 108 - .bits = (_bits), \ 109 - } 110 - 111 105 DEFINE_ADCxx1C_CHANNELS(adc081c, 8); 112 106 DEFINE_ADCxx1C_CHANNELS(adc101c, 10); 113 107 DEFINE_ADCxx1C_CHANNELS(adc121c, 12); 114 108 115 - /* Model ids are indexes in _models array */ 116 - enum adcxx1c_model_id { 117 - ADC081C = 0, 118 - ADC101C = 1, 119 - ADC121C = 2, 109 + static const struct adcxx1c_model adc081c_model = { 110 + .channels = adc081c_channels, 111 + .bits = 8, 120 112 }; 121 113 122 - static struct adcxx1c_model adcxx1c_models[] = { 123 - ADCxx1C_MODEL(adc081c, 8), 124 - ADCxx1C_MODEL(adc101c, 10), 125 - ADCxx1C_MODEL(adc121c, 12), 114 + static const struct adcxx1c_model adc101c_model = { 115 + .channels = adc101c_channels, 116 + .bits = 10, 117 + }; 118 + 119 + static const struct adcxx1c_model adc121c_model = { 120 + .channels = adc121c_channels, 121 + .bits = 12, 126 122 }; 127 123 128 124 static const struct iio_info adc081c_info = { ··· 199 203 } 200 204 201 205 static const struct i2c_device_id adc081c_id[] = { 202 - { "adc081c", (kernel_ulong_t)&adcxx1c_models[ADC081C] }, 203 - { "adc101c", (kernel_ulong_t)&adcxx1c_models[ADC101C] }, 204 - { "adc121c", (kernel_ulong_t)&adcxx1c_models[ADC121C] }, 206 + { "adc081c", (kernel_ulong_t)&adc081c_model }, 207 + { "adc101c", (kernel_ulong_t)&adc101c_model }, 208 + { "adc121c", (kernel_ulong_t)&adc121c_model }, 205 209 { } 206 210 }; 207 211 MODULE_DEVICE_TABLE(i2c, adc081c_id); 208 212 209 213 static const struct acpi_device_id adc081c_acpi_match[] = { 210 214 /* Used on some AAEON boards */ 211 - { "ADC081C", (kernel_ulong_t)&adcxx1c_models[ADC081C] }, 215 + { "ADC081C", (kernel_ulong_t)&adc081c_model }, 212 216 { } 213 217 }; 214 218 MODULE_DEVICE_TABLE(acpi, adc081c_acpi_match); 215 219 216 220 static const struct of_device_id adc081c_of_match[] = { 217 - { .compatible = "ti,adc081c", .data = &adcxx1c_models[ADC081C] }, 218 - { .compatible = "ti,adc101c", .data = &adcxx1c_models[ADC101C] }, 219 - { .compatible = "ti,adc121c", .data = &adcxx1c_models[ADC121C] }, 221 + { .compatible = "ti,adc081c", .data = &adc081c_model }, 222 + { .compatible = "ti,adc101c", .data = &adc101c_model }, 223 + { .compatible = "ti,adc121c", .data = &adc121c_model }, 220 224 { } 221 225 }; 222 226 MODULE_DEVICE_TABLE(of, adc081c_of_match);
+1 -3
drivers/iio/adc/ti-adc084s021.c
··· 200 200 int ret; 201 201 202 202 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); 203 - if (!indio_dev) { 204 - dev_err(&spi->dev, "Failed to allocate IIO device\n"); 203 + if (!indio_dev) 205 204 return -ENOMEM; 206 - } 207 205 208 206 adc = iio_priv(indio_dev); 209 207 adc->spi = spi;
+11 -19
drivers/iio/adc/ti-adc12138.c
··· 38 38 struct adc12138 { 39 39 struct spi_device *spi; 40 40 unsigned int id; 41 - /* conversion clock */ 42 - struct clk *cclk; 43 41 /* positive analog voltage reference */ 44 42 struct regulator *vref_p; 45 43 /* negative analog voltage reference */ 46 44 struct regulator *vref_n; 47 45 struct mutex lock; 48 46 struct completion complete; 49 - /* The number of cclk periods for the S/H's acquisition time */ 47 + /* The number of conversion clock periods for the S/H's acquisition time */ 50 48 unsigned int acquisition_time; 51 49 /* 52 50 * Maximum size needed: 16x 2 bytes ADC data + 8 bytes timestamp. ··· 398 400 { 399 401 struct iio_dev *indio_dev; 400 402 struct adc12138 *adc; 403 + struct clk *cclk; 401 404 int ret; 402 405 403 406 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); ··· 434 435 if (ret) 435 436 adc->acquisition_time = 10; 436 437 437 - adc->cclk = devm_clk_get(&spi->dev, NULL); 438 - if (IS_ERR(adc->cclk)) 439 - return PTR_ERR(adc->cclk); 438 + ret = devm_request_irq(&spi->dev, spi->irq, adc12138_eoc_handler, 439 + IRQF_TRIGGER_RISING, indio_dev->name, indio_dev); 440 + if (ret) 441 + return ret; 442 + 443 + cclk = devm_clk_get_enabled(&spi->dev, NULL); 444 + if (IS_ERR(cclk)) 445 + return PTR_ERR(cclk); 440 446 441 447 adc->vref_p = devm_regulator_get(&spi->dev, "vref-p"); 442 448 if (IS_ERR(adc->vref_p)) ··· 458 454 return ret; 459 455 } 460 456 461 - ret = devm_request_irq(&spi->dev, spi->irq, adc12138_eoc_handler, 462 - IRQF_TRIGGER_RISING, indio_dev->name, indio_dev); 463 - if (ret) 464 - return ret; 465 - 466 - ret = clk_prepare_enable(adc->cclk); 467 - if (ret) 468 - return ret; 469 - 470 457 ret = regulator_enable(adc->vref_p); 471 458 if (ret) 472 - goto err_clk_disable; 459 + return ret; 473 460 474 461 if (!IS_ERR(adc->vref_n)) { 475 462 ret = regulator_enable(adc->vref_n); ··· 491 496 regulator_disable(adc->vref_n); 492 497 err_vref_p_disable: 493 498 regulator_disable(adc->vref_p); 494 - err_clk_disable: 495 - clk_disable_unprepare(adc->cclk); 496 499 497 500 return ret; 498 501 } ··· 505 512 if (!IS_ERR(adc->vref_n)) 506 513 regulator_disable(adc->vref_n); 507 514 regulator_disable(adc->vref_p); 508 - clk_disable_unprepare(adc->cclk); 509 515 } 510 516 511 517 static const struct of_device_id adc12138_dt_ids[] = {
+90 -50
drivers/iio/adc/ti-adc128s052.c
··· 99 99 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \ 100 100 } 101 101 102 - static const struct iio_chan_spec adc128s052_channels[] = { 102 + static const struct iio_chan_spec simple_1chan_adc_channels[] = { 103 + ADC128_VOLTAGE_CHANNEL(0), 104 + }; 105 + 106 + static const struct iio_chan_spec simple_2chan_adc_channels[] = { 107 + ADC128_VOLTAGE_CHANNEL(0), 108 + ADC128_VOLTAGE_CHANNEL(1), 109 + }; 110 + 111 + static const struct iio_chan_spec simple_4chan_adc_channels[] = { 112 + ADC128_VOLTAGE_CHANNEL(0), 113 + ADC128_VOLTAGE_CHANNEL(1), 114 + ADC128_VOLTAGE_CHANNEL(2), 115 + ADC128_VOLTAGE_CHANNEL(3), 116 + }; 117 + 118 + static const struct iio_chan_spec simple_8chan_adc_channels[] = { 103 119 ADC128_VOLTAGE_CHANNEL(0), 104 120 ADC128_VOLTAGE_CHANNEL(1), 105 121 ADC128_VOLTAGE_CHANNEL(2), ··· 126 110 ADC128_VOLTAGE_CHANNEL(7), 127 111 }; 128 112 129 - static const struct iio_chan_spec adc122s021_channels[] = { 130 - ADC128_VOLTAGE_CHANNEL(0), 131 - ADC128_VOLTAGE_CHANNEL(1), 132 - }; 133 - 134 - static const struct iio_chan_spec adc124s021_channels[] = { 135 - ADC128_VOLTAGE_CHANNEL(0), 136 - ADC128_VOLTAGE_CHANNEL(1), 137 - ADC128_VOLTAGE_CHANNEL(2), 138 - ADC128_VOLTAGE_CHANNEL(3), 139 - }; 140 - 141 113 static const char * const bd79104_regulators[] = { "iovdd" }; 142 114 143 - static const struct adc128_configuration adc128_config[] = { 144 - { 145 - .channels = adc128s052_channels, 146 - .num_channels = ARRAY_SIZE(adc128s052_channels), 147 - .refname = "vref", 148 - }, { 149 - .channels = adc122s021_channels, 150 - .num_channels = ARRAY_SIZE(adc122s021_channels), 151 - .refname = "vref", 152 - }, { 153 - .channels = adc124s021_channels, 154 - .num_channels = ARRAY_SIZE(adc124s021_channels), 155 - .refname = "vref", 156 - }, { 157 - .channels = adc128s052_channels, 158 - .num_channels = ARRAY_SIZE(adc128s052_channels), 159 - .refname = "vdd", 160 - .other_regulators = &bd79104_regulators, 161 - .num_other_regulators = 1, 162 - }, 115 + static const struct adc128_configuration adc122s_config = { 116 + .channels = simple_2chan_adc_channels, 117 + .num_channels = ARRAY_SIZE(simple_2chan_adc_channels), 118 + .refname = "vref", 119 + }; 120 + 121 + static const struct adc128_configuration adc124s_config = { 122 + .channels = simple_4chan_adc_channels, 123 + .num_channels = ARRAY_SIZE(simple_4chan_adc_channels), 124 + .refname = "vref", 125 + }; 126 + 127 + static const struct adc128_configuration adc128s_config = { 128 + .channels = simple_8chan_adc_channels, 129 + .num_channels = ARRAY_SIZE(simple_8chan_adc_channels), 130 + .refname = "vref", 131 + }; 132 + 133 + static const struct adc128_configuration bd79100_config = { 134 + .channels = simple_1chan_adc_channels, 135 + .num_channels = ARRAY_SIZE(simple_1chan_adc_channels), 136 + .refname = "vdd", 137 + .other_regulators = &bd79104_regulators, 138 + .num_other_regulators = 1, 139 + }; 140 + 141 + static const struct adc128_configuration bd79101_config = { 142 + .channels = simple_2chan_adc_channels, 143 + .num_channels = ARRAY_SIZE(simple_2chan_adc_channels), 144 + .refname = "vdd", 145 + .other_regulators = &bd79104_regulators, 146 + .num_other_regulators = 1, 147 + }; 148 + 149 + static const struct adc128_configuration bd79102_config = { 150 + .channels = simple_4chan_adc_channels, 151 + .num_channels = ARRAY_SIZE(simple_4chan_adc_channels), 152 + .refname = "vdd", 153 + .other_regulators = &bd79104_regulators, 154 + .num_other_regulators = 1, 155 + }; 156 + 157 + static const struct adc128_configuration bd79104_config = { 158 + .channels = simple_8chan_adc_channels, 159 + .num_channels = ARRAY_SIZE(simple_8chan_adc_channels), 160 + .refname = "vdd", 161 + .other_regulators = &bd79104_regulators, 162 + .num_other_regulators = 1, 163 163 }; 164 164 165 165 static const struct iio_info adc128_info = { ··· 231 199 } 232 200 233 201 static const struct of_device_id adc128_of_match[] = { 234 - { .compatible = "ti,adc128s052", .data = &adc128_config[0] }, 235 - { .compatible = "ti,adc122s021", .data = &adc128_config[1] }, 236 - { .compatible = "ti,adc122s051", .data = &adc128_config[1] }, 237 - { .compatible = "ti,adc122s101", .data = &adc128_config[1] }, 238 - { .compatible = "ti,adc124s021", .data = &adc128_config[2] }, 239 - { .compatible = "ti,adc124s051", .data = &adc128_config[2] }, 240 - { .compatible = "ti,adc124s101", .data = &adc128_config[2] }, 241 - { .compatible = "rohm,bd79104", .data = &adc128_config[3] }, 202 + { .compatible = "ti,adc128s052", .data = &adc128s_config }, 203 + { .compatible = "ti,adc122s021", .data = &adc122s_config }, 204 + { .compatible = "ti,adc122s051", .data = &adc122s_config }, 205 + { .compatible = "ti,adc122s101", .data = &adc122s_config }, 206 + { .compatible = "ti,adc124s021", .data = &adc124s_config }, 207 + { .compatible = "ti,adc124s051", .data = &adc124s_config }, 208 + { .compatible = "ti,adc124s101", .data = &adc124s_config }, 209 + { .compatible = "rohm,bd79100", .data = &bd79100_config }, 210 + { .compatible = "rohm,bd79101", .data = &bd79101_config }, 211 + { .compatible = "rohm,bd79102", .data = &bd79102_config }, 212 + { .compatible = "rohm,bd79103", .data = &bd79104_config }, 213 + { .compatible = "rohm,bd79104", .data = &bd79104_config }, 242 214 { } 243 215 }; 244 216 MODULE_DEVICE_TABLE(of, adc128_of_match); 245 217 246 218 static const struct spi_device_id adc128_id[] = { 247 - { "adc128s052", (kernel_ulong_t)&adc128_config[0] }, 248 - { "adc122s021", (kernel_ulong_t)&adc128_config[1] }, 249 - { "adc122s051", (kernel_ulong_t)&adc128_config[1] }, 250 - { "adc122s101", (kernel_ulong_t)&adc128_config[1] }, 251 - { "adc124s021", (kernel_ulong_t)&adc128_config[2] }, 252 - { "adc124s051", (kernel_ulong_t)&adc128_config[2] }, 253 - { "adc124s101", (kernel_ulong_t)&adc128_config[2] }, 254 - { "bd79104", (kernel_ulong_t)&adc128_config[3] }, 219 + { "adc128s052", (kernel_ulong_t)&adc128s_config }, 220 + { "adc122s021", (kernel_ulong_t)&adc122s_config }, 221 + { "adc122s051", (kernel_ulong_t)&adc122s_config }, 222 + { "adc122s101", (kernel_ulong_t)&adc122s_config }, 223 + { "adc124s021", (kernel_ulong_t)&adc124s_config }, 224 + { "adc124s051", (kernel_ulong_t)&adc124s_config }, 225 + { "adc124s101", (kernel_ulong_t)&adc124s_config }, 226 + { "bd79100", (kernel_ulong_t)&bd79100_config }, 227 + { "bd79101", (kernel_ulong_t)&bd79101_config }, 228 + { "bd79102", (kernel_ulong_t)&bd79102_config }, 229 + { "bd79103", (kernel_ulong_t)&bd79104_config }, 230 + { "bd79104", (kernel_ulong_t)&bd79104_config }, 255 231 { } 256 232 }; 257 233 MODULE_DEVICE_TABLE(spi, adc128_id); 258 234 259 235 static const struct acpi_device_id adc128_acpi_match[] = { 260 - { "AANT1280", (kernel_ulong_t)&adc128_config[2] }, 236 + { "AANT1280", (kernel_ulong_t)&adc124s_config }, 261 237 { } 262 238 }; 263 239 MODULE_DEVICE_TABLE(acpi, adc128_acpi_match);
+2 -4
drivers/iio/adc/ti-ads1015.c
··· 374 374 int ret; 375 375 struct device *dev = regmap_get_device(data->regmap); 376 376 377 - if (on) { 377 + if (on) 378 378 ret = pm_runtime_resume_and_get(dev); 379 - } else { 380 - pm_runtime_mark_last_busy(dev); 379 + else 381 380 ret = pm_runtime_put_autosuspend(dev); 382 - } 383 381 384 382 return ret < 0 ? ret : 0; 385 383 }
-1
drivers/iio/adc/ti-ads1100.c
··· 105 105 106 106 ret = i2c_master_recv(data->client, (char *)&buffer, sizeof(buffer)); 107 107 108 - pm_runtime_mark_last_busy(&data->client->dev); 109 108 pm_runtime_put_autosuspend(&data->client->dev); 110 109 111 110 if (ret < 0) {
+3 -8
drivers/iio/adc/ti-ads1119.c
··· 291 291 *val = sign_extend32(sample, chan->scan_type.realbits - 1); 292 292 ret = IIO_VAL_INT; 293 293 pdown: 294 - pm_runtime_mark_last_busy(dev); 295 294 pm_runtime_put_autosuspend(dev); 296 295 return ret; 297 296 } ··· 469 470 if (ret) 470 471 return ret; 471 472 472 - pm_runtime_mark_last_busy(dev); 473 473 pm_runtime_put_autosuspend(dev); 474 474 475 475 return 0; ··· 691 693 692 694 indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 693 695 if (!indio_dev) 694 - return dev_err_probe(dev, -ENOMEM, 695 - "Failed to allocate IIO device\n"); 696 + return -ENOMEM; 696 697 697 698 st = iio_priv(indio_dev); 698 699 st->client = client; ··· 747 750 indio_dev->name, 748 751 iio_device_id(indio_dev)); 749 752 if (!st->trig) 750 - return dev_err_probe(dev, -ENOMEM, 751 - "Failed to allocate IIO trigger\n"); 753 + return -ENOMEM; 752 754 753 755 st->trig->ops = &ads1119_trigger_ops; 754 756 iio_trigger_set_drvdata(st->trig, indio_dev); ··· 774 778 775 779 ret = devm_add_action_or_reset(dev, ads1119_powerdown, st); 776 780 if (ret) 777 - return dev_err_probe(dev, ret, 778 - "Failed to add powerdown action\n"); 781 + return ret; 779 782 780 783 return devm_iio_device_register(dev, indio_dev); 781 784 }
+2 -6
drivers/iio/adc/ti-ads131e08.c
··· 807 807 } 808 808 809 809 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 810 - if (!indio_dev) { 811 - dev_err(&spi->dev, "failed to allocate IIO device\n"); 810 + if (!indio_dev) 812 811 return -ENOMEM; 813 - } 814 812 815 813 st = iio_priv(indio_dev); 816 814 st->info = info; ··· 839 841 840 842 st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d", 841 843 indio_dev->name, iio_device_id(indio_dev)); 842 - if (!st->trig) { 843 - dev_err(&spi->dev, "failed to allocate IIO trigger\n"); 844 + if (!st->trig) 844 845 return -ENOMEM; 845 - } 846 846 847 847 st->trig->ops = &ads131e08_trigger_ops; 848 848 st->trig->dev.parent = &spi->dev;
+3 -6
drivers/iio/adc/ti-ads7924.c
··· 355 355 356 356 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 357 357 if (!indio_dev) 358 - return dev_err_probe(dev, -ENOMEM, 359 - "failed to allocate iio device\n"); 358 + return -ENOMEM; 360 359 361 360 data = iio_priv(indio_dev); 362 361 ··· 398 399 399 400 ret = devm_add_action_or_reset(dev, ads7924_reg_disable, data->vref_reg); 400 401 if (ret) 401 - return dev_err_probe(dev, ret, 402 - "failed to add regulator disable action\n"); 402 + return ret; 403 403 404 404 ret = ads7924_reset(indio_dev); 405 405 if (ret < 0) ··· 412 414 413 415 ret = devm_add_action_or_reset(dev, ads7924_set_idle_mode, data); 414 416 if (ret) 415 - return dev_err_probe(dev, ret, 416 - "failed to add idle mode action\n"); 417 + return ret; 417 418 418 419 /* Use minimum signal acquire time. */ 419 420 ret = regmap_update_bits(data->regmap, ADS7924_ACQCONFIG_REG,
+2 -4
drivers/iio/adc/ti-tsc2046.c
··· 535 535 if (priv->poll_cnt < TI_TSC2046_POLL_CNT) { 536 536 priv->poll_cnt++; 537 537 hrtimer_start(&priv->trig_timer, 538 - ns_to_ktime(priv->scan_interval_us * 539 - NSEC_PER_USEC), 538 + us_to_ktime(priv->scan_interval_us), 540 539 HRTIMER_MODE_REL_SOFT); 541 540 542 541 if (priv->poll_cnt >= TI_TSC2046_MIN_POLL_CNT) { ··· 604 605 * many samples. Reduce the sample rate for default (touchscreen) use 605 606 * case. 606 607 */ 607 - tim = ns_to_ktime((priv->scan_interval_us - priv->time_per_scan_us) * 608 - NSEC_PER_USEC); 608 + tim = us_to_ktime(priv->scan_interval_us - priv->time_per_scan_us); 609 609 hrtimer_start(&priv->trig_timer, tim, HRTIMER_MODE_REL_SOFT); 610 610 } 611 611
+2 -3
drivers/iio/adc/ti_am335x_adc.c
··· 631 631 } 632 632 633 633 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc_dev)); 634 - if (!indio_dev) { 635 - dev_err(&pdev->dev, "failed to allocate iio device\n"); 634 + if (!indio_dev) 636 635 return -ENOMEM; 637 - } 636 + 638 637 adc_dev = iio_priv(indio_dev); 639 638 640 639 adc_dev->mfd_tscadc = ti_tscadc_dev_get(pdev);
+1 -3
drivers/iio/adc/twl4030-madc.c
··· 758 758 } 759 759 760 760 iio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*madc)); 761 - if (!iio_dev) { 762 - dev_err(&pdev->dev, "failed allocating iio device\n"); 761 + if (!iio_dev) 763 762 return -ENOMEM; 764 - } 765 763 766 764 madc = iio_priv(iio_dev); 767 765 madc->dev = &pdev->dev;
+1 -1
drivers/iio/adc/vf610_adc.c
··· 832 832 833 833 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct vf610_adc)); 834 834 if (!indio_dev) 835 - return dev_err_probe(&pdev->dev, -ENOMEM, "Failed allocating iio device\n"); 835 + return -ENOMEM; 836 836 837 837 info = iio_priv(indio_dev); 838 838 info->dev = &pdev->dev;
+1 -3
drivers/iio/adc/viperboard_adc.c
··· 113 113 114 114 /* registering iio */ 115 115 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc)); 116 - if (!indio_dev) { 117 - dev_err(&pdev->dev, "failed allocating iio device\n"); 116 + if (!indio_dev) 118 117 return -ENOMEM; 119 - } 120 118 121 119 adc = iio_priv(indio_dev); 122 120 adc->vb = vb;
-1
drivers/iio/buffer/industrialio-buffer-cb.c
··· 68 68 cb_buff->private = private; 69 69 cb_buff->cb = cb; 70 70 cb_buff->buffer.access = &iio_cb_access; 71 - INIT_LIST_HEAD(&cb_buff->buffer.demux_list); 72 71 73 72 cb_buff->channels = iio_channel_get_all(dev); 74 73 if (IS_ERR(cb_buff->channels)) {
-2
drivers/iio/chemical/atlas-sensor.c
··· 425 425 if (ret) 426 426 return ret; 427 427 428 - pm_runtime_mark_last_busy(&data->client->dev); 429 428 ret = pm_runtime_put_autosuspend(&data->client->dev); 430 429 if (ret) 431 430 return ret; ··· 490 491 491 492 ret = regmap_bulk_read(data->regmap, reg, val, sizeof(*val)); 492 493 493 - pm_runtime_mark_last_busy(dev); 494 494 pm_runtime_put_autosuspend(dev); 495 495 496 496 return ret;
-3
drivers/iio/chemical/bme680_core.c
··· 950 950 return ret; 951 951 952 952 ret = __bme680_read_raw(indio_dev, chan, val, val2, mask); 953 - pm_runtime_mark_last_busy(dev); 954 953 pm_runtime_put_autosuspend(dev); 955 954 956 955 return ret; ··· 1020 1021 return ret; 1021 1022 1022 1023 ret = __bme680_write_raw(indio_dev, chan, val, val2, mask); 1023 - pm_runtime_mark_last_busy(dev); 1024 1024 pm_runtime_put_autosuspend(dev); 1025 1025 1026 1026 return ret; ··· 1138 1140 struct bme680_data *data = iio_priv(indio_dev); 1139 1141 struct device *dev = regmap_get_device(data->regmap); 1140 1142 1141 - pm_runtime_mark_last_busy(dev); 1142 1143 pm_runtime_put_autosuspend(dev); 1143 1144 return 0; 1144 1145 }
+1 -2
drivers/iio/chemical/ens160_core.c
··· 305 305 trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, 306 306 iio_device_id(indio_dev)); 307 307 if (!trig) 308 - return dev_err_probe(dev, -ENOMEM, 309 - "failed to allocate trigger\n"); 308 + return -ENOMEM; 310 309 311 310 trig->ops = &ens160_trigger_ops; 312 311 iio_trigger_set_drvdata(trig, indio_dev);
+1 -1
drivers/iio/chemical/scd30_core.c
··· 635 635 trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, 636 636 iio_device_id(indio_dev)); 637 637 if (!trig) 638 - return dev_err_probe(dev, -ENOMEM, "failed to allocate trigger\n"); 638 + return -ENOMEM; 639 639 640 640 trig->ops = &scd30_trigger_ops; 641 641 iio_trigger_set_drvdata(trig, indio_dev);
-1
drivers/iio/common/hid-sensors/hid-sensor-trigger.c
··· 163 163 ret = pm_runtime_resume_and_get(&st->pdev->dev); 164 164 } else { 165 165 atomic_dec(&st->user_requested_state); 166 - pm_runtime_mark_last_busy(&st->pdev->dev); 167 166 pm_runtime_use_autosuspend(&st->pdev->dev); 168 167 ret = pm_runtime_put_autosuspend(&st->pdev->dev); 169 168 }
+5 -5
drivers/iio/common/scmi_sensors/scmi_iio.c
··· 521 521 int i; 522 522 523 523 sensor->freq_avail = 524 - devm_kzalloc(&iio_dev->dev, 525 - sizeof(*sensor->freq_avail) * 526 - (sensor->sensor_info->intervals.count * 2), 524 + devm_kcalloc(&iio_dev->dev, 525 + array_size(sensor->sensor_info->intervals.count, 2), 526 + sizeof(*sensor->freq_avail), 527 527 GFP_KERNEL); 528 528 if (!sensor->freq_avail) 529 529 return -ENOMEM; ··· 597 597 iiodev->info = &scmi_iio_info; 598 598 599 599 iio_channels = 600 - devm_kzalloc(dev, 601 - sizeof(*iio_channels) * (iiodev->num_channels), 600 + devm_kcalloc(dev, iiodev->num_channels, 601 + sizeof(*iio_channels), 602 602 GFP_KERNEL); 603 603 if (!iio_channels) 604 604 return ERR_PTR(-ENOMEM);
+1 -3
drivers/iio/dac/ad5380.c
··· 371 371 int ret; 372 372 373 373 indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 374 - if (indio_dev == NULL) { 375 - dev_err(dev, "Failed to allocate iio device\n"); 374 + if (indio_dev == NULL) 376 375 return -ENOMEM; 377 - } 378 376 379 377 st = iio_priv(indio_dev); 380 378
+1 -3
drivers/iio/dac/ad5764.c
··· 278 278 int ret; 279 279 280 280 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 281 - if (indio_dev == NULL) { 282 - dev_err(&spi->dev, "Failed to allocate iio device\n"); 281 + if (indio_dev == NULL) 283 282 return -ENOMEM; 284 - } 285 283 286 284 st = iio_priv(indio_dev); 287 285 spi_set_drvdata(spi, indio_dev);
-4
drivers/iio/dac/ad5791.c
··· 80 80 /** 81 81 * struct ad5791_state - driver instance specific data 82 82 * @spi: spi_device 83 - * @reg_vdd: positive supply regulator 84 - * @reg_vss: negative supply regulator 85 83 * @gpio_reset: reset gpio 86 84 * @gpio_clear: clear gpio 87 85 * @gpio_ldac: load dac gpio ··· 98 100 */ 99 101 struct ad5791_state { 100 102 struct spi_device *spi; 101 - struct regulator *reg_vdd; 102 - struct regulator *reg_vss; 103 103 struct gpio_desc *gpio_reset; 104 104 struct gpio_desc *gpio_clear; 105 105 struct gpio_desc *gpio_ldac;
+1 -3
drivers/iio/dac/ds4424.c
··· 221 221 int ret; 222 222 223 223 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 224 - if (!indio_dev) { 225 - dev_err(&client->dev, "iio dev alloc failed.\n"); 224 + if (!indio_dev) 226 225 return -ENOMEM; 227 - } 228 226 229 227 data = iio_priv(indio_dev); 230 228 i2c_set_clientdata(client, indio_dev);
+5 -14
drivers/iio/dac/stm32-dac.c
··· 82 82 83 83 ret = regmap_update_bits(dac->common->regmap, STM32_DAC_CR, msk, en); 84 84 mutex_unlock(&dac->lock); 85 - if (ret < 0) { 85 + if (ret) { 86 86 dev_err(&indio_dev->dev, "%s failed\n", str_enable_disable(en)); 87 - goto err_put_pm; 87 + if (enable) 88 + pm_runtime_put_autosuspend(dev); 89 + return ret; 88 90 } 89 91 90 92 /* ··· 97 95 if (en && dac->common->hfsel) 98 96 udelay(1); 99 97 100 - if (!enable) { 101 - pm_runtime_mark_last_busy(dev); 98 + if (!enable) 102 99 pm_runtime_put_autosuspend(dev); 103 - } 104 100 105 101 return 0; 106 - 107 - err_put_pm: 108 - if (enable) { 109 - pm_runtime_mark_last_busy(dev); 110 - pm_runtime_put_autosuspend(dev); 111 - } 112 - 113 - return ret; 114 102 } 115 103 116 104 static int stm32_dac_get_value(struct stm32_dac *dac, int channel, int *val) ··· 341 349 if (ret) 342 350 goto err_pm_put; 343 351 344 - pm_runtime_mark_last_busy(dev); 345 352 pm_runtime_put_autosuspend(dev); 346 353 347 354 return 0;
+1 -3
drivers/iio/dac/ti-dac7311.c
··· 242 242 int ret; 243 243 244 244 indio_dev = devm_iio_device_alloc(dev, sizeof(*ti_dac)); 245 - if (!indio_dev) { 246 - dev_err(dev, "can not allocate iio device\n"); 245 + if (!indio_dev) 247 246 return -ENOMEM; 248 - } 249 247 250 248 spi->mode = SPI_MODE_1; 251 249 spi->bits_per_word = 16;
+1 -2
drivers/iio/frequency/adf4350.c
··· 679 679 680 680 ret = devm_add_action_or_reset(&spi->dev, adf4350_power_down, indio_dev); 681 681 if (ret) 682 - return dev_err_probe(&spi->dev, ret, 683 - "Failed to add action to managed power down\n"); 682 + return ret; 684 683 685 684 return devm_iio_device_register(&spi->dev, indio_dev); 686 685 }
+1 -3
drivers/iio/gyro/bmg160_core.c
··· 309 309 310 310 if (on) 311 311 ret = pm_runtime_get_sync(dev); 312 - else { 313 - pm_runtime_mark_last_busy(dev); 312 + else 314 313 ret = pm_runtime_put_autosuspend(dev); 315 - } 316 314 317 315 if (ret < 0) { 318 316 dev_err(dev, "Failed: bmg160_set_power_state for %d\n", on);
-2
drivers/iio/gyro/fxas21002c_core.c
··· 373 373 { 374 374 struct device *dev = regmap_get_device(data->regmap); 375 375 376 - pm_runtime_mark_last_busy(dev); 377 - 378 376 return pm_runtime_put_autosuspend(dev); 379 377 } 380 378
-3
drivers/iio/gyro/mpu3050-core.c
··· 370 370 371 371 out_read_raw_unlock: 372 372 mutex_unlock(&mpu3050->lock); 373 - pm_runtime_mark_last_busy(mpu3050->dev); 374 373 pm_runtime_put_autosuspend(mpu3050->dev); 375 374 376 375 return ret; ··· 661 662 { 662 663 struct mpu3050 *mpu3050 = iio_priv(indio_dev); 663 664 664 - pm_runtime_mark_last_busy(mpu3050->dev); 665 665 pm_runtime_put_autosuspend(mpu3050->dev); 666 666 667 667 return 0; ··· 974 976 if (ret) 975 977 dev_err(mpu3050->dev, "error resetting FIFO\n"); 976 978 977 - pm_runtime_mark_last_busy(mpu3050->dev); 978 979 pm_runtime_put_autosuspend(mpu3050->dev); 979 980 mpu3050->hw_irq_trigger = false; 980 981
-1
drivers/iio/gyro/mpu3050-i2c.c
··· 27 27 { 28 28 struct mpu3050 *mpu3050 = i2c_mux_priv(mux); 29 29 30 - pm_runtime_mark_last_busy(mpu3050->dev); 31 30 pm_runtime_put_autosuspend(mpu3050->dev); 32 31 return 0; 33 32 }
+22 -26
drivers/iio/health/afe4403.c
··· 58 58 59 59 /** 60 60 * struct afe4403_data - AFE4403 device instance data 61 - * @dev: Device structure 62 61 * @spi: SPI device handle 63 62 * @regmap: Register map of the device 64 63 * @fields: Register fields of the device ··· 67 68 * @buffer: Used to construct data layout to push into IIO buffer. 68 69 */ 69 70 struct afe4403_data { 70 - struct device *dev; 71 71 struct spi_device *spi; 72 72 struct regmap *regmap; 73 73 struct regmap_field *fields[F_MAX_FIELDS]; ··· 458 460 459 461 static int afe4403_probe(struct spi_device *spi) 460 462 { 463 + struct device *dev = &spi->dev; 461 464 struct iio_dev *indio_dev; 462 465 struct afe4403_data *afe; 463 466 int i, ret; 464 467 465 - indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*afe)); 468 + indio_dev = devm_iio_device_alloc(dev, sizeof(*afe)); 466 469 if (!indio_dev) 467 470 return -ENOMEM; 468 471 469 472 afe = iio_priv(indio_dev); 470 473 spi_set_drvdata(spi, indio_dev); 471 474 472 - afe->dev = &spi->dev; 473 475 afe->spi = spi; 474 476 afe->irq = spi->irq; 475 477 476 478 afe->regmap = devm_regmap_init_spi(spi, &afe4403_regmap_config); 477 479 if (IS_ERR(afe->regmap)) { 478 - dev_err(afe->dev, "Unable to allocate register map\n"); 480 + dev_err(dev, "Unable to allocate register map\n"); 479 481 return PTR_ERR(afe->regmap); 480 482 } 481 483 482 484 for (i = 0; i < F_MAX_FIELDS; i++) { 483 - afe->fields[i] = devm_regmap_field_alloc(afe->dev, afe->regmap, 485 + afe->fields[i] = devm_regmap_field_alloc(dev, afe->regmap, 484 486 afe4403_reg_fields[i]); 485 487 if (IS_ERR(afe->fields[i])) { 486 - dev_err(afe->dev, "Unable to allocate regmap fields\n"); 488 + dev_err(dev, "Unable to allocate regmap fields\n"); 487 489 return PTR_ERR(afe->fields[i]); 488 490 } 489 491 } 490 492 491 - afe->regulator = devm_regulator_get(afe->dev, "tx_sup"); 493 + afe->regulator = devm_regulator_get(dev, "tx_sup"); 492 494 if (IS_ERR(afe->regulator)) 493 - return dev_err_probe(afe->dev, PTR_ERR(afe->regulator), 495 + return dev_err_probe(dev, PTR_ERR(afe->regulator), 494 496 "Unable to get regulator\n"); 495 497 496 498 ret = regulator_enable(afe->regulator); 497 499 if (ret) { 498 - dev_err(afe->dev, "Unable to enable regulator\n"); 500 + dev_err(dev, "Unable to enable regulator\n"); 499 501 return ret; 500 502 } 501 - ret = devm_add_action_or_reset(afe->dev, afe4403_regulator_disable, afe->regulator); 503 + ret = devm_add_action_or_reset(dev, afe4403_regulator_disable, afe->regulator); 502 504 if (ret) { 503 - dev_err(afe->dev, "Unable to add regulator disable action\n"); 505 + dev_err(dev, "Unable to add regulator disable action\n"); 504 506 return ret; 505 507 } 506 508 507 509 ret = regmap_write(afe->regmap, AFE440X_CONTROL0, 508 510 AFE440X_CONTROL0_SW_RESET); 509 511 if (ret) { 510 - dev_err(afe->dev, "Unable to reset device\n"); 512 + dev_err(dev, "Unable to reset device\n"); 511 513 return ret; 512 514 } 513 515 514 516 ret = regmap_multi_reg_write(afe->regmap, afe4403_reg_sequences, 515 517 ARRAY_SIZE(afe4403_reg_sequences)); 516 518 if (ret) { 517 - dev_err(afe->dev, "Unable to set register defaults\n"); 519 + dev_err(dev, "Unable to set register defaults\n"); 518 520 return ret; 519 521 } 520 522 ··· 525 527 indio_dev->info = &afe4403_iio_info; 526 528 527 529 if (afe->irq > 0) { 528 - afe->trig = devm_iio_trigger_alloc(afe->dev, 530 + afe->trig = devm_iio_trigger_alloc(dev, 529 531 "%s-dev%d", 530 532 indio_dev->name, 531 533 iio_device_id(indio_dev)); 532 - if (!afe->trig) { 533 - dev_err(afe->dev, "Unable to allocate IIO trigger\n"); 534 + if (!afe->trig) 534 535 return -ENOMEM; 535 - } 536 536 537 537 iio_trigger_set_drvdata(afe->trig, indio_dev); 538 538 539 - ret = devm_iio_trigger_register(afe->dev, afe->trig); 539 + ret = devm_iio_trigger_register(dev, afe->trig); 540 540 if (ret) { 541 - dev_err(afe->dev, "Unable to register IIO trigger\n"); 541 + dev_err(dev, "Unable to register IIO trigger\n"); 542 542 return ret; 543 543 } 544 544 545 - ret = devm_request_threaded_irq(afe->dev, afe->irq, 545 + ret = devm_request_threaded_irq(dev, afe->irq, 546 546 iio_trigger_generic_data_rdy_poll, 547 547 NULL, IRQF_ONESHOT, 548 548 AFE4403_DRIVER_NAME, 549 549 afe->trig); 550 550 if (ret) { 551 - dev_err(afe->dev, "Unable to request IRQ\n"); 551 + dev_err(dev, "Unable to request IRQ\n"); 552 552 return ret; 553 553 } 554 554 } 555 555 556 - ret = devm_iio_triggered_buffer_setup(afe->dev, indio_dev, 556 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 557 557 &iio_pollfunc_store_time, 558 558 afe4403_trigger_handler, NULL); 559 559 if (ret) { 560 - dev_err(afe->dev, "Unable to setup buffer\n"); 560 + dev_err(dev, "Unable to setup buffer\n"); 561 561 return ret; 562 562 } 563 563 564 - ret = devm_iio_device_register(afe->dev, indio_dev); 564 + ret = devm_iio_device_register(dev, indio_dev); 565 565 if (ret) { 566 - dev_err(afe->dev, "Unable to register IIO device\n"); 566 + dev_err(dev, "Unable to register IIO device\n"); 567 567 return ret; 568 568 } 569 569
+22 -26
drivers/iio/health/afe4404.c
··· 77 77 78 78 /** 79 79 * struct afe4404_data - AFE4404 device instance data 80 - * @dev: Device structure 81 80 * @regmap: Register map of the device 82 81 * @fields: Register fields of the device 83 82 * @regulator: Pointer to the regulator for the IC ··· 85 86 * @buffer: Used to construct a scan to push to the iio buffer. 86 87 */ 87 88 struct afe4404_data { 88 - struct device *dev; 89 89 struct regmap *regmap; 90 90 struct regmap_field *fields[F_MAX_FIELDS]; 91 91 struct regulator *regulator; ··· 466 468 467 469 static int afe4404_probe(struct i2c_client *client) 468 470 { 471 + struct device *dev = &client->dev; 469 472 struct iio_dev *indio_dev; 470 473 struct afe4404_data *afe; 471 474 int i, ret; 472 475 473 - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*afe)); 476 + indio_dev = devm_iio_device_alloc(dev, sizeof(*afe)); 474 477 if (!indio_dev) 475 478 return -ENOMEM; 476 479 477 480 afe = iio_priv(indio_dev); 478 481 i2c_set_clientdata(client, indio_dev); 479 482 480 - afe->dev = &client->dev; 481 483 afe->irq = client->irq; 482 484 483 485 afe->regmap = devm_regmap_init_i2c(client, &afe4404_regmap_config); 484 486 if (IS_ERR(afe->regmap)) { 485 - dev_err(afe->dev, "Unable to allocate register map\n"); 487 + dev_err(dev, "Unable to allocate register map\n"); 486 488 return PTR_ERR(afe->regmap); 487 489 } 488 490 489 491 for (i = 0; i < F_MAX_FIELDS; i++) { 490 - afe->fields[i] = devm_regmap_field_alloc(afe->dev, afe->regmap, 492 + afe->fields[i] = devm_regmap_field_alloc(dev, afe->regmap, 491 493 afe4404_reg_fields[i]); 492 494 if (IS_ERR(afe->fields[i])) { 493 - dev_err(afe->dev, "Unable to allocate regmap fields\n"); 495 + dev_err(dev, "Unable to allocate regmap fields\n"); 494 496 return PTR_ERR(afe->fields[i]); 495 497 } 496 498 } 497 499 498 - afe->regulator = devm_regulator_get(afe->dev, "tx_sup"); 500 + afe->regulator = devm_regulator_get(dev, "tx_sup"); 499 501 if (IS_ERR(afe->regulator)) 500 - return dev_err_probe(afe->dev, PTR_ERR(afe->regulator), 502 + return dev_err_probe(dev, PTR_ERR(afe->regulator), 501 503 "Unable to get regulator\n"); 502 504 503 505 ret = regulator_enable(afe->regulator); 504 506 if (ret) { 505 - dev_err(afe->dev, "Unable to enable regulator\n"); 507 + dev_err(dev, "Unable to enable regulator\n"); 506 508 return ret; 507 509 } 508 - ret = devm_add_action_or_reset(afe->dev, afe4404_regulator_disable, afe->regulator); 510 + ret = devm_add_action_or_reset(dev, afe4404_regulator_disable, afe->regulator); 509 511 if (ret) { 510 - dev_err(afe->dev, "Unable to enable regulator\n"); 512 + dev_err(dev, "Unable to enable regulator\n"); 511 513 return ret; 512 514 } 513 515 514 516 ret = regmap_write(afe->regmap, AFE440X_CONTROL0, 515 517 AFE440X_CONTROL0_SW_RESET); 516 518 if (ret) { 517 - dev_err(afe->dev, "Unable to reset device\n"); 519 + dev_err(dev, "Unable to reset device\n"); 518 520 return ret; 519 521 } 520 522 521 523 ret = regmap_multi_reg_write(afe->regmap, afe4404_reg_sequences, 522 524 ARRAY_SIZE(afe4404_reg_sequences)); 523 525 if (ret) { 524 - dev_err(afe->dev, "Unable to set register defaults\n"); 526 + dev_err(dev, "Unable to set register defaults\n"); 525 527 return ret; 526 528 } 527 529 ··· 532 534 indio_dev->info = &afe4404_iio_info; 533 535 534 536 if (afe->irq > 0) { 535 - afe->trig = devm_iio_trigger_alloc(afe->dev, 537 + afe->trig = devm_iio_trigger_alloc(dev, 536 538 "%s-dev%d", 537 539 indio_dev->name, 538 540 iio_device_id(indio_dev)); 539 - if (!afe->trig) { 540 - dev_err(afe->dev, "Unable to allocate IIO trigger\n"); 541 + if (!afe->trig) 541 542 return -ENOMEM; 542 - } 543 543 544 544 iio_trigger_set_drvdata(afe->trig, indio_dev); 545 545 546 - ret = devm_iio_trigger_register(afe->dev, afe->trig); 546 + ret = devm_iio_trigger_register(dev, afe->trig); 547 547 if (ret) { 548 - dev_err(afe->dev, "Unable to register IIO trigger\n"); 548 + dev_err(dev, "Unable to register IIO trigger\n"); 549 549 return ret; 550 550 } 551 551 552 - ret = devm_request_threaded_irq(afe->dev, afe->irq, 552 + ret = devm_request_threaded_irq(dev, afe->irq, 553 553 iio_trigger_generic_data_rdy_poll, 554 554 NULL, IRQF_ONESHOT, 555 555 AFE4404_DRIVER_NAME, 556 556 afe->trig); 557 557 if (ret) { 558 - dev_err(afe->dev, "Unable to request IRQ\n"); 558 + dev_err(dev, "Unable to request IRQ\n"); 559 559 return ret; 560 560 } 561 561 } 562 562 563 - ret = devm_iio_triggered_buffer_setup(afe->dev, indio_dev, 563 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 564 564 &iio_pollfunc_store_time, 565 565 afe4404_trigger_handler, NULL); 566 566 if (ret) { 567 - dev_err(afe->dev, "Unable to setup buffer\n"); 567 + dev_err(dev, "Unable to setup buffer\n"); 568 568 return ret; 569 569 } 570 570 571 - ret = devm_iio_device_register(afe->dev, indio_dev); 571 + ret = devm_iio_device_register(dev, indio_dev); 572 572 if (ret) { 573 - dev_err(afe->dev, "Unable to register IIO device\n"); 573 + dev_err(dev, "Unable to register IIO device\n"); 574 574 return ret; 575 575 } 576 576
+1 -3
drivers/iio/humidity/am2315.c
··· 224 224 struct am2315_data *data; 225 225 226 226 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 227 - if (!indio_dev) { 228 - dev_err(&client->dev, "iio allocation failed!\n"); 227 + if (!indio_dev) 229 228 return -ENOMEM; 230 - } 231 229 232 230 data = iio_priv(indio_dev); 233 231 data->client = client;
+1 -3
drivers/iio/humidity/dht11.c
··· 294 294 struct iio_dev *iio; 295 295 296 296 iio = devm_iio_device_alloc(dev, sizeof(*dht11)); 297 - if (!iio) { 298 - dev_err(dev, "Failed to allocate IIO device\n"); 297 + if (!iio) 299 298 return -ENOMEM; 300 - } 301 299 302 300 dht11 = iio_priv(iio); 303 301 dht11->dev = dev;
-1
drivers/iio/imu/adis16475.c
··· 1930 1930 return 0; 1931 1931 } 1932 1932 1933 - 1934 1933 static int adis16475_probe(struct spi_device *spi) 1935 1934 { 1936 1935 struct iio_dev *indio_dev;
+2
drivers/iio/imu/bmi270/bmi270_i2c.c
··· 41 41 static const struct acpi_device_id bmi270_acpi_match[] = { 42 42 /* GPD Win Mini, Aya Neo AIR Pro, OXP Mini Pro, etc. */ 43 43 { "BMI0160", (kernel_ulong_t)&bmi260_chip_info }, 44 + /* GPD Win Max 2 2023(sincice BIOS v0.40), etc. */ 45 + { "BMI0260", (kernel_ulong_t)&bmi260_chip_info }, 44 46 { } 45 47 }; 46 48
+1 -2
drivers/iio/imu/bmi323/bmi323_core.c
··· 2112 2112 2113 2113 indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 2114 2114 if (!indio_dev) 2115 - return dev_err_probe(dev, -ENOMEM, 2116 - "Failed to allocate device\n"); 2115 + return -ENOMEM; 2117 2116 2118 2117 ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names), 2119 2118 regulator_names);
-1
drivers/iio/imu/inv_icm42600/inv_icm42600.h
··· 167 167 enum inv_icm42600_chip chip; 168 168 const char *name; 169 169 struct regmap *map; 170 - struct regulator *vdd_supply; 171 170 struct regulator *vddio_supply; 172 171 int irq; 173 172 struct iio_mount_matrix orientation;
+8 -21
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
··· 315 315 ret = -EINVAL; 316 316 exit: 317 317 mutex_unlock(&st->lock); 318 - pm_runtime_mark_last_busy(dev); 319 318 pm_runtime_put_autosuspend(dev); 320 319 return ret; 321 320 } ··· 561 562 conf.fs = idx / 2; 562 563 563 564 pm_runtime_get_sync(dev); 564 - mutex_lock(&st->lock); 565 565 566 - ret = inv_icm42600_set_accel_conf(st, &conf, NULL); 566 + scoped_guard(mutex, &st->lock) 567 + ret = inv_icm42600_set_accel_conf(st, &conf, NULL); 567 568 568 - mutex_unlock(&st->lock); 569 - pm_runtime_mark_last_busy(dev); 570 569 pm_runtime_put_autosuspend(dev); 571 570 572 571 return ret; ··· 672 675 673 676 out_unlock: 674 677 mutex_unlock(&st->lock); 675 - pm_runtime_mark_last_busy(dev); 676 678 pm_runtime_put_autosuspend(dev); 677 679 678 680 return ret; ··· 723 727 memcpy(data, st->buffer, sizeof(data)); 724 728 725 729 mutex_unlock(&st->lock); 726 - pm_runtime_mark_last_busy(dev); 727 730 pm_runtime_put_autosuspend(dev); 728 731 if (ret) 729 732 return ret; ··· 860 865 861 866 out_unlock: 862 867 mutex_unlock(&st->lock); 863 - pm_runtime_mark_last_busy(dev); 864 868 pm_runtime_put_autosuspend(dev); 865 869 return ret; 866 870 } ··· 985 991 unsigned int val) 986 992 { 987 993 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 988 - int ret; 989 994 990 - mutex_lock(&st->lock); 995 + guard(mutex)(&st->lock); 991 996 992 997 st->fifo.watermark.accel = val; 993 - ret = inv_icm42600_buffer_update_watermark(st); 994 - 995 - mutex_unlock(&st->lock); 996 - 997 - return ret; 998 + return inv_icm42600_buffer_update_watermark(st); 998 999 } 999 1000 1000 1001 static int inv_icm42600_accel_hwfifo_flush(struct iio_dev *indio_dev, ··· 1001 1012 if (count == 0) 1002 1013 return 0; 1003 1014 1004 - mutex_lock(&st->lock); 1015 + guard(mutex)(&st->lock); 1005 1016 1006 1017 ret = inv_icm42600_buffer_hwfifo_flush(st, count); 1007 - if (!ret) 1008 - ret = st->fifo.nb.accel; 1018 + if (ret) 1019 + return ret; 1009 1020 1010 - mutex_unlock(&st->lock); 1011 - 1012 - return ret; 1021 + return st->fifo.nb.accel; 1013 1022 } 1014 1023 1015 1024 static int inv_icm42600_accel_read_event_config(struct iio_dev *indio_dev,
+23 -42
drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c
··· 5 5 6 6 #include <linux/kernel.h> 7 7 #include <linux/device.h> 8 + #include <linux/minmax.h> 8 9 #include <linux/mutex.h> 9 10 #include <linux/pm_runtime.h> 10 11 #include <linux/regmap.h> ··· 101 100 102 101 void inv_icm42600_buffer_update_fifo_period(struct inv_icm42600_state *st) 103 102 { 104 - u32 period_gyro, period_accel, period; 103 + u32 period_gyro, period_accel; 105 104 106 105 if (st->fifo.en & INV_ICM42600_SENSOR_GYRO) 107 106 period_gyro = inv_icm42600_odr_to_period(st->conf.gyro.odr); ··· 113 112 else 114 113 period_accel = U32_MAX; 115 114 116 - if (period_gyro <= period_accel) 117 - period = period_gyro; 118 - else 119 - period = period_accel; 120 - 121 - st->fifo.period = period; 115 + st->fifo.period = min(period_gyro, period_accel); 122 116 } 123 117 124 118 int inv_icm42600_buffer_set_fifo_en(struct inv_icm42600_state *st, ··· 200 204 { 201 205 size_t packet_size, wm_size; 202 206 unsigned int wm_gyro, wm_accel, watermark; 203 - u32 period_gyro, period_accel, period; 207 + u32 period_gyro, period_accel; 204 208 u32 latency_gyro, latency_accel, latency; 205 209 bool restore; 206 210 __le16 raw_wm; ··· 233 237 latency = latency_gyro - (latency_accel % latency_gyro); 234 238 else 235 239 latency = latency_accel - (latency_gyro % latency_accel); 236 - /* use the shortest period */ 237 - if (period_gyro <= period_accel) 238 - period = period_gyro; 239 - else 240 - period = period_accel; 241 240 /* all this works because periods are multiple of each others */ 242 - watermark = latency / period; 241 + watermark = latency / min(period_gyro, period_accel); 243 242 if (watermark < 1) 244 243 watermark = 1; 245 244 /* update effective watermark */ ··· 283 292 284 293 pm_runtime_get_sync(dev); 285 294 286 - mutex_lock(&st->lock); 295 + guard(mutex)(&st->lock); 287 296 inv_sensors_timestamp_reset(ts); 288 - mutex_unlock(&st->lock); 289 297 290 298 return 0; 291 299 } ··· 298 308 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 299 309 int ret; 300 310 301 - mutex_lock(&st->lock); 311 + guard(mutex)(&st->lock); 302 312 303 - /* exit if FIFO is already on */ 304 313 if (st->fifo.on) { 305 - ret = 0; 306 - goto out_on; 314 + st->fifo.on++; 315 + return 0; 307 316 } 308 317 309 318 /* set FIFO threshold interrupt */ 310 319 ret = regmap_set_bits(st->map, INV_ICM42600_REG_INT_SOURCE0, 311 320 INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN); 312 321 if (ret) 313 - goto out_unlock; 322 + return ret; 314 323 315 324 /* flush FIFO data */ 316 325 ret = regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET, 317 326 INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH); 318 327 if (ret) 319 - goto out_unlock; 328 + return ret; 320 329 321 330 /* set FIFO in streaming mode */ 322 331 ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG, 323 332 INV_ICM42600_FIFO_CONFIG_STREAM); 324 333 if (ret) 325 - goto out_unlock; 334 + return ret; 326 335 327 336 /* workaround: first read of FIFO count after reset is always 0 */ 328 337 ret = regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT, st->buffer, 2); 329 338 if (ret) 330 - goto out_unlock; 339 + return ret; 331 340 332 - out_on: 333 - /* increase FIFO on counter */ 334 341 st->fifo.on++; 335 - out_unlock: 336 - mutex_unlock(&st->lock); 337 - return ret; 342 + 343 + return 0; 338 344 } 339 345 340 346 static int inv_icm42600_buffer_predisable(struct iio_dev *indio_dev) ··· 338 352 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 339 353 int ret; 340 354 341 - mutex_lock(&st->lock); 355 + guard(mutex)(&st->lock); 342 356 343 - /* exit if there are several sensors using the FIFO */ 344 357 if (st->fifo.on > 1) { 345 - ret = 0; 346 - goto out_off; 358 + st->fifo.on--; 359 + return 0; 347 360 } 348 361 349 362 /* set FIFO in bypass mode */ 350 363 ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG, 351 364 INV_ICM42600_FIFO_CONFIG_BYPASS); 352 365 if (ret) 353 - goto out_unlock; 366 + return ret; 354 367 355 368 /* flush FIFO data */ 356 369 ret = regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET, 357 370 INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH); 358 371 if (ret) 359 - goto out_unlock; 372 + return ret; 360 373 361 374 /* disable FIFO threshold interrupt */ 362 375 ret = regmap_clear_bits(st->map, INV_ICM42600_REG_INT_SOURCE0, 363 376 INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN); 364 377 if (ret) 365 - goto out_unlock; 378 + return ret; 366 379 367 - out_off: 368 - /* decrease FIFO on counter */ 369 380 st->fifo.on--; 370 - out_unlock: 371 - mutex_unlock(&st->lock); 372 - return ret; 381 + 382 + return 0; 373 383 } 374 384 375 385 static int inv_icm42600_buffer_postdisable(struct iio_dev *indio_dev) ··· 421 439 if (sleep) 422 440 msleep(sleep); 423 441 424 - pm_runtime_mark_last_busy(dev); 425 442 pm_runtime_put_autosuspend(dev); 426 443 427 444 return ret;
+36 -81
drivers/iio/imu/inv_icm42600/inv_icm42600_core.c
··· 439 439 unsigned int writeval, unsigned int *readval) 440 440 { 441 441 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 442 - int ret; 443 442 444 - mutex_lock(&st->lock); 443 + guard(mutex)(&st->lock); 445 444 446 445 if (readval) 447 - ret = regmap_read(st->map, reg, readval); 448 - else 449 - ret = regmap_write(st->map, reg, writeval); 446 + return regmap_read(st->map, reg, readval); 450 447 451 - mutex_unlock(&st->lock); 452 - 453 - return ret; 448 + return regmap_write(st->map, reg, writeval); 454 449 } 455 450 456 451 static int inv_icm42600_set_conf(struct inv_icm42600_state *st, ··· 692 697 return 0; 693 698 } 694 699 695 - static void inv_icm42600_disable_vdd_reg(void *_data) 696 - { 697 - struct inv_icm42600_state *st = _data; 698 - const struct device *dev = regmap_get_device(st->map); 699 - int ret; 700 - 701 - ret = regulator_disable(st->vdd_supply); 702 - if (ret) 703 - dev_err(dev, "failed to disable vdd error %d\n", ret); 704 - } 705 - 706 700 static void inv_icm42600_disable_vddio_reg(void *_data) 707 701 { 708 702 struct inv_icm42600_state *st = _data; 709 - const struct device *dev = regmap_get_device(st->map); 710 - int ret; 703 + struct device *dev = regmap_get_device(st->map); 711 704 712 - ret = regulator_disable(st->vddio_supply); 713 - if (ret) 714 - dev_err(dev, "failed to disable vddio error %d\n", ret); 715 - } 705 + if (pm_runtime_status_suspended(dev)) 706 + return; 716 707 717 - static void inv_icm42600_disable_pm(void *_data) 718 - { 719 - struct device *dev = _data; 720 - 721 - pm_runtime_put_sync(dev); 722 - pm_runtime_disable(dev); 708 + regulator_disable(st->vddio_supply); 723 709 } 724 710 725 711 int inv_icm42600_core_probe(struct regmap *regmap, int chip, ··· 749 773 return ret; 750 774 } 751 775 752 - st->vdd_supply = devm_regulator_get(dev, "vdd"); 753 - if (IS_ERR(st->vdd_supply)) 754 - return PTR_ERR(st->vdd_supply); 776 + ret = devm_regulator_get_enable(dev, "vdd"); 777 + if (ret) 778 + return dev_err_probe(dev, ret, 779 + "Failed to get vdd regulator\n"); 780 + 781 + msleep(INV_ICM42600_POWER_UP_TIME_MS); 755 782 756 783 st->vddio_supply = devm_regulator_get(dev, "vddio"); 757 784 if (IS_ERR(st->vddio_supply)) 758 785 return PTR_ERR(st->vddio_supply); 759 - 760 - ret = regulator_enable(st->vdd_supply); 761 - if (ret) 762 - return ret; 763 - msleep(INV_ICM42600_POWER_UP_TIME_MS); 764 - 765 - ret = devm_add_action_or_reset(dev, inv_icm42600_disable_vdd_reg, st); 766 - if (ret) 767 - return ret; 768 786 769 787 ret = inv_icm42600_enable_regulator_vddio(st); 770 788 if (ret) ··· 794 824 return ret; 795 825 796 826 /* setup runtime power management */ 797 - ret = pm_runtime_set_active(dev); 827 + ret = devm_pm_runtime_set_active_enabled(dev); 798 828 if (ret) 799 829 return ret; 800 - pm_runtime_get_noresume(dev); 801 - pm_runtime_enable(dev); 830 + 802 831 pm_runtime_set_autosuspend_delay(dev, INV_ICM42600_SUSPEND_DELAY_MS); 803 832 pm_runtime_use_autosuspend(dev); 804 - pm_runtime_put(dev); 805 833 806 - return devm_add_action_or_reset(dev, inv_icm42600_disable_pm, dev); 834 + return ret; 807 835 } 808 836 EXPORT_SYMBOL_NS_GPL(inv_icm42600_core_probe, "IIO_ICM42600"); 809 837 ··· 817 849 int accel_conf; 818 850 int ret; 819 851 820 - mutex_lock(&st->lock); 852 + guard(mutex)(&st->lock); 821 853 822 854 st->suspended.gyro = st->conf.gyro.mode; 823 855 st->suspended.accel = st->conf.accel.mode; 824 856 st->suspended.temp = st->conf.temp_en; 825 - if (pm_runtime_suspended(dev)) { 826 - ret = 0; 827 - goto out_unlock; 828 - } 857 + if (pm_runtime_suspended(dev)) 858 + return 0; 829 859 830 860 /* disable FIFO data streaming */ 831 861 if (st->fifo.on) { 832 862 ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG, 833 863 INV_ICM42600_FIFO_CONFIG_BYPASS); 834 864 if (ret) 835 - goto out_unlock; 865 + return ret; 836 866 } 837 867 838 868 /* keep chip on and wake-up capable if APEX and wakeup on */ ··· 846 880 if (st->apex.wom.enable) { 847 881 ret = inv_icm42600_disable_wom(st); 848 882 if (ret) 849 - goto out_unlock; 883 + return ret; 850 884 } 851 885 accel_conf = INV_ICM42600_SENSOR_MODE_OFF; 852 886 } ··· 854 888 ret = inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF, 855 889 accel_conf, false, NULL); 856 890 if (ret) 857 - goto out_unlock; 891 + return ret; 858 892 859 893 /* disable vddio regulator if chip is sleeping */ 860 894 if (!wakeup) 861 895 regulator_disable(st->vddio_supply); 862 896 863 - out_unlock: 864 - mutex_unlock(&st->lock); 865 - return ret; 897 + return 0; 866 898 } 867 899 868 900 /* ··· 876 912 bool wakeup; 877 913 int ret; 878 914 879 - mutex_lock(&st->lock); 915 + guard(mutex)(&st->lock); 916 + 917 + if (pm_runtime_suspended(dev)) 918 + return 0; 880 919 881 920 /* check wakeup capability */ 882 921 accel_dev = &st->indio_accel->dev; ··· 891 924 } else { 892 925 ret = inv_icm42600_enable_regulator_vddio(st); 893 926 if (ret) 894 - goto out_unlock; 927 + return ret; 895 928 } 896 - 897 - pm_runtime_disable(dev); 898 - pm_runtime_set_active(dev); 899 - pm_runtime_enable(dev); 900 929 901 930 /* restore sensors state */ 902 931 ret = inv_icm42600_set_pwr_mgmt0(st, st->suspended.gyro, 903 932 st->suspended.accel, 904 933 st->suspended.temp, NULL); 905 934 if (ret) 906 - goto out_unlock; 935 + return ret; 907 936 908 937 /* restore APEX features if disabled */ 909 938 if (!wakeup && st->apex.wom.enable) { 910 939 ret = inv_icm42600_enable_wom(st); 911 940 if (ret) 912 - goto out_unlock; 941 + return ret; 913 942 } 914 943 915 944 /* restore FIFO data streaming */ ··· 916 953 INV_ICM42600_FIFO_CONFIG_STREAM); 917 954 } 918 955 919 - out_unlock: 920 - mutex_unlock(&st->lock); 921 - return ret; 956 + return 0; 922 957 } 923 958 924 959 /* Runtime suspend will turn off sensors that are enabled by iio devices. */ ··· 925 964 struct inv_icm42600_state *st = dev_get_drvdata(dev); 926 965 int ret; 927 966 928 - mutex_lock(&st->lock); 967 + guard(mutex)(&st->lock); 929 968 930 969 /* disable all sensors */ 931 970 ret = inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF, 932 971 INV_ICM42600_SENSOR_MODE_OFF, false, 933 972 NULL); 934 973 if (ret) 935 - goto error_unlock; 974 + return ret; 936 975 937 976 regulator_disable(st->vddio_supply); 938 977 939 - error_unlock: 940 - mutex_unlock(&st->lock); 941 - return ret; 978 + return 0; 942 979 } 943 980 944 981 /* Sensors are enabled by iio devices, no need to turn them back on here. */ 945 982 static int inv_icm42600_runtime_resume(struct device *dev) 946 983 { 947 984 struct inv_icm42600_state *st = dev_get_drvdata(dev); 948 - int ret; 949 985 950 - mutex_lock(&st->lock); 986 + guard(mutex)(&st->lock); 951 987 952 - ret = inv_icm42600_enable_regulator_vddio(st); 953 - 954 - mutex_unlock(&st->lock); 955 - return ret; 988 + return inv_icm42600_enable_regulator_vddio(st); 956 989 } 957 990 958 991 EXPORT_NS_GPL_DEV_PM_OPS(inv_icm42600_pm_ops, IIO_ICM42600) = {
+8 -21
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
··· 184 184 ret = -EINVAL; 185 185 exit: 186 186 mutex_unlock(&st->lock); 187 - pm_runtime_mark_last_busy(dev); 188 187 pm_runtime_put_autosuspend(dev); 189 188 return ret; 190 189 } ··· 277 278 conf.fs = idx / 2; 278 279 279 280 pm_runtime_get_sync(dev); 280 - mutex_lock(&st->lock); 281 281 282 - ret = inv_icm42600_set_gyro_conf(st, &conf, NULL); 282 + scoped_guard(mutex, &st->lock) 283 + ret = inv_icm42600_set_gyro_conf(st, &conf, NULL); 283 284 284 - mutex_unlock(&st->lock); 285 - pm_runtime_mark_last_busy(dev); 286 285 pm_runtime_put_autosuspend(dev); 287 286 288 287 return ret; ··· 375 378 376 379 out_unlock: 377 380 mutex_unlock(&st->lock); 378 - pm_runtime_mark_last_busy(dev); 379 381 pm_runtime_put_autosuspend(dev); 380 382 381 383 return ret; ··· 426 430 memcpy(data, st->buffer, sizeof(data)); 427 431 428 432 mutex_unlock(&st->lock); 429 - pm_runtime_mark_last_busy(dev); 430 433 pm_runtime_put_autosuspend(dev); 431 434 if (ret) 432 435 return ret; ··· 562 567 563 568 out_unlock: 564 569 mutex_unlock(&st->lock); 565 - pm_runtime_mark_last_busy(dev); 566 570 pm_runtime_put_autosuspend(dev); 567 571 return ret; 568 572 } ··· 687 693 unsigned int val) 688 694 { 689 695 struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); 690 - int ret; 691 696 692 - mutex_lock(&st->lock); 697 + guard(mutex)(&st->lock); 693 698 694 699 st->fifo.watermark.gyro = val; 695 - ret = inv_icm42600_buffer_update_watermark(st); 696 - 697 - mutex_unlock(&st->lock); 698 - 699 - return ret; 700 + return inv_icm42600_buffer_update_watermark(st); 700 701 } 701 702 702 703 static int inv_icm42600_gyro_hwfifo_flush(struct iio_dev *indio_dev, ··· 703 714 if (count == 0) 704 715 return 0; 705 716 706 - mutex_lock(&st->lock); 717 + guard(mutex)(&st->lock); 707 718 708 719 ret = inv_icm42600_buffer_hwfifo_flush(st, count); 709 - if (!ret) 710 - ret = st->fifo.nb.gyro; 720 + if (ret) 721 + return ret; 711 722 712 - mutex_unlock(&st->lock); 713 - 714 - return ret; 723 + return st->fifo.nb.gyro; 715 724 } 716 725 717 726 static const struct iio_info inv_icm42600_gyro_info = {
-1
drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
··· 41 41 42 42 exit: 43 43 mutex_unlock(&st->lock); 44 - pm_runtime_mark_last_busy(dev); 45 44 pm_runtime_put_autosuspend(dev); 46 45 47 46 return ret;
-6
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 735 735 break; 736 736 } 737 737 738 - pm_runtime_mark_last_busy(pdev); 739 738 pm_runtime_put_autosuspend(pdev); 740 739 741 740 return ret; ··· 937 938 break; 938 939 } 939 940 940 - pm_runtime_mark_last_busy(pdev); 941 941 pm_runtime_put_autosuspend(pdev); 942 942 error_write_raw_unlock: 943 943 mutex_unlock(&st->lock); ··· 1144 1146 st->chip_config.wom_en = false; 1145 1147 } 1146 1148 1147 - pm_runtime_mark_last_busy(pdev); 1148 1149 pm_runtime_put_autosuspend(pdev); 1149 1150 } 1150 1151 1151 1152 return result; 1152 1153 1153 1154 error_suspend: 1154 - pm_runtime_mark_last_busy(pdev); 1155 1155 pm_runtime_put_autosuspend(pdev); 1156 1156 return result; 1157 1157 } ··· 1245 1249 value = (u64)val * 1000000ULL + (u64)val2; 1246 1250 result = inv_mpu6050_set_wom_threshold(st, value, INV_MPU6050_FREQ_DIVIDER(st)); 1247 1251 1248 - pm_runtime_mark_last_busy(pdev); 1249 1252 pm_runtime_put_autosuspend(pdev); 1250 1253 1251 1254 return result; ··· 1352 1357 if (result) 1353 1358 goto fifo_rate_fail_power_off; 1354 1359 1355 - pm_runtime_mark_last_busy(pdev); 1356 1360 fifo_rate_fail_power_off: 1357 1361 pm_runtime_put_autosuspend(pdev); 1358 1362 fifo_rate_fail_unlock:
-1
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
··· 194 194 result = inv_mpu6050_prepare_fifo(st, false); 195 195 if (result) 196 196 goto error_power_off; 197 - pm_runtime_mark_last_busy(pdev); 198 197 pm_runtime_put_autosuspend(pdev); 199 198 } 200 199
+2 -4
drivers/iio/imu/kmx61.c
··· 747 747 data->mag_ps = on; 748 748 } 749 749 750 - if (on) { 750 + if (on) 751 751 ret = pm_runtime_resume_and_get(&data->client->dev); 752 - } else { 753 - pm_runtime_mark_last_busy(&data->client->dev); 752 + else 754 753 ret = pm_runtime_put_autosuspend(&data->client->dev); 755 - } 756 754 if (ret < 0) { 757 755 dev_err(&data->client->dev, 758 756 "Failed: kmx61_set_power_state for %d, ret %d\n",
+7 -7
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 2035 2035 2036 2036 odr_table = &sensor->hw->settings->odr_table[sensor->id]; 2037 2037 for (i = 0; i < odr_table->odr_len; i++) 2038 - len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%03d ", 2039 - odr_table->odr_avl[i].milli_hz / 1000, 2040 - odr_table->odr_avl[i].milli_hz % 1000); 2041 - buf[len - 1] = '\n'; 2038 + len += sysfs_emit_at(buf, len, "%d.%03d%c", 2039 + odr_table->odr_avl[i].milli_hz / 1000, 2040 + odr_table->odr_avl[i].milli_hz % 1000, 2041 + (i == odr_table->odr_len - 1) ? '\n' : ' '); 2042 2042 2043 2043 return len; 2044 2044 } ··· 2054 2054 2055 2055 fs_table = &hw->settings->fs_table[sensor->id]; 2056 2056 for (i = 0; i < fs_table->fs_len; i++) 2057 - len += scnprintf(buf + len, PAGE_SIZE - len, "0.%09u ", 2058 - fs_table->fs_avl[i].gain); 2059 - buf[len - 1] = '\n'; 2057 + len += sysfs_emit_at(buf, len, "0.%09u%c", 2058 + fs_table->fs_avl[i].gain, 2059 + (i == fs_table->fs_len - 1) ? '\n' : ' '); 2060 2060 2061 2061 return len; 2062 2062 }
+9 -2
drivers/iio/industrialio-core.c
··· 97 97 [IIO_COLORTEMP] = "colortemp", 98 98 [IIO_CHROMATICITY] = "chromaticity", 99 99 [IIO_ATTENTION] = "attention", 100 + [IIO_ALTCURRENT] = "altcurrent", 100 101 }; 101 102 102 103 static const char * const iio_modifier_names[] = { ··· 153 152 [IIO_MOD_PITCH] = "pitch", 154 153 [IIO_MOD_YAW] = "yaw", 155 154 [IIO_MOD_ROLL] = "roll", 155 + [IIO_MOD_RMS] = "rms", 156 + [IIO_MOD_ACTIVE] = "active", 157 + [IIO_MOD_REACTIVE] = "reactive", 158 + [IIO_MOD_APPARENT] = "apparent", 156 159 }; 157 160 158 161 /* relies on pairs of these shared then separate */ ··· 194 189 [IIO_CHAN_INFO_ZEROPOINT] = "zeropoint", 195 190 [IIO_CHAN_INFO_TROUGH] = "trough_raw", 196 191 [IIO_CHAN_INFO_CONVDELAY] = "convdelay", 192 + [IIO_CHAN_INFO_POWERFACTOR] = "powerfactor", 197 193 }; 198 194 /** 199 195 * iio_device_id() - query the unique ID for the device ··· 796 790 797 791 switch (type) { 798 792 case IIO_VAL_INT: 793 + case IIO_VAL_CHAR: 799 794 stride = 1; 800 795 break; 801 796 default: ··· 1250 1243 static int iio_device_add_info_mask_type(struct iio_dev *indio_dev, 1251 1244 struct iio_chan_spec const *chan, 1252 1245 enum iio_shared_by shared_by, 1253 - const long *infomask) 1246 + const unsigned long *infomask) 1254 1247 { 1255 1248 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 1256 1249 int i, ret, attrcount = 0; ··· 1280 1273 static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev, 1281 1274 struct iio_chan_spec const *chan, 1282 1275 enum iio_shared_by shared_by, 1283 - const long *infomask) 1276 + const unsigned long *infomask) 1284 1277 { 1285 1278 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 1286 1279 int i, ret, attrcount = 0;
+46 -35
drivers/iio/inkern.c
··· 11 11 #include <linux/mutex.h> 12 12 #include <linux/property.h> 13 13 #include <linux/slab.h> 14 + #include <linux/units.h> 14 15 15 16 #include <linux/iio/iio.h> 16 17 #include <linux/iio/iio-opaque.h> ··· 599 598 } 600 599 EXPORT_SYMBOL_GPL(iio_read_channel_average_raw); 601 600 601 + int iio_multiply_value(int *result, s64 multiplier, 602 + unsigned int type, int val, int val2) 603 + { 604 + s64 denominator; 605 + 606 + switch (type) { 607 + case IIO_VAL_INT: 608 + *result = multiplier * val; 609 + return IIO_VAL_INT; 610 + case IIO_VAL_INT_PLUS_MICRO: 611 + case IIO_VAL_INT_PLUS_NANO: 612 + switch (type) { 613 + case IIO_VAL_INT_PLUS_MICRO: 614 + denominator = MICRO; 615 + break; 616 + case IIO_VAL_INT_PLUS_NANO: 617 + denominator = NANO; 618 + break; 619 + } 620 + *result = multiplier * abs(val); 621 + *result += div_s64(multiplier * abs(val2), denominator); 622 + if (val < 0 || val2 < 0) 623 + *result *= -1; 624 + return IIO_VAL_INT; 625 + case IIO_VAL_FRACTIONAL: 626 + *result = div_s64(multiplier * val, val2); 627 + return IIO_VAL_INT; 628 + case IIO_VAL_FRACTIONAL_LOG2: 629 + *result = (multiplier * val) >> val2; 630 + return IIO_VAL_INT; 631 + default: 632 + return -EINVAL; 633 + } 634 + } 635 + EXPORT_SYMBOL_NS_GPL(iio_multiply_value, "IIO_UNIT_TEST"); 636 + 602 637 static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, 603 638 int raw, int *processed, 604 639 unsigned int scale) ··· 642 605 int scale_type, scale_val, scale_val2; 643 606 int offset_type, offset_val, offset_val2; 644 607 s64 raw64 = raw; 608 + int ret; 645 609 646 610 offset_type = iio_channel_read(chan, &offset_val, &offset_val2, 647 611 IIO_CHAN_INFO_OFFSET); ··· 677 639 * If no channel scaling is available apply consumer scale to 678 640 * raw value and return. 679 641 */ 680 - *processed = raw * scale; 642 + *processed = raw64 * scale; 681 643 return 0; 682 644 } 683 645 684 - switch (scale_type) { 685 - case IIO_VAL_INT: 686 - *processed = raw64 * scale_val * scale; 687 - break; 688 - case IIO_VAL_INT_PLUS_MICRO: 689 - if (scale_val2 < 0) 690 - *processed = -raw64 * scale_val * scale; 691 - else 692 - *processed = raw64 * scale_val * scale; 693 - *processed += div_s64(raw64 * (s64)scale_val2 * scale, 694 - 1000000LL); 695 - break; 696 - case IIO_VAL_INT_PLUS_NANO: 697 - if (scale_val2 < 0) 698 - *processed = -raw64 * scale_val * scale; 699 - else 700 - *processed = raw64 * scale_val * scale; 701 - *processed += div_s64(raw64 * (s64)scale_val2 * scale, 702 - 1000000000LL); 703 - break; 704 - case IIO_VAL_FRACTIONAL: 705 - *processed = div_s64(raw64 * (s64)scale_val * scale, 706 - scale_val2); 707 - break; 708 - case IIO_VAL_FRACTIONAL_LOG2: 709 - *processed = (raw64 * (s64)scale_val * scale) >> scale_val2; 710 - break; 711 - default: 712 - return -EINVAL; 713 - } 646 + ret = iio_multiply_value(processed, raw64 * scale, 647 + scale_type, scale_val, scale_val2); 648 + if (ret < 0) 649 + return ret; 714 650 715 651 return 0; 716 652 } ··· 726 714 unsigned int scale) 727 715 { 728 716 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev); 729 - int ret; 717 + int ret, pval, pval2; 730 718 731 719 guard(mutex)(&iio_dev_opaque->info_exist_lock); 732 720 if (!chan->indio_dev->info) 733 721 return -ENODEV; 734 722 735 723 if (iio_channel_has_info(chan->channel, IIO_CHAN_INFO_PROCESSED)) { 736 - ret = iio_channel_read(chan, val, NULL, 724 + ret = iio_channel_read(chan, &pval, &pval2, 737 725 IIO_CHAN_INFO_PROCESSED); 738 726 if (ret < 0) 739 727 return ret; 740 - *val *= scale; 741 728 742 - return ret; 729 + return iio_multiply_value(val, scale, ret, pval, pval2); 743 730 } else { 744 731 ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_RAW); 745 732 if (ret < 0)
+13
drivers/iio/light/Kconfig
··· 724 724 To compile this driver as a module, choose M here: the 725 725 module will be called veml6040. 726 726 727 + config VEML6046X00 728 + tristate "VEML6046X00 RGBIR color sensor" 729 + select REGMAP_I2C 730 + select IIO_BUFFER 731 + select IIO_TRIGGERED_BUFFER 732 + depends on I2C 733 + help 734 + Say Y here if you want to build a driver for the Vishay VEML6046X00 735 + high accuracy RGBIR color sensor. 736 + 737 + To compile this driver as a module, choose M here: the 738 + module will be called veml6046x00. 739 + 727 740 config VEML6070 728 741 tristate "VEML6070 UV A light sensor" 729 742 depends on I2C
+1
drivers/iio/light/Makefile
··· 67 67 obj-$(CONFIG_VEML3235) += veml3235.o 68 68 obj-$(CONFIG_VEML6030) += veml6030.o 69 69 obj-$(CONFIG_VEML6040) += veml6040.o 70 + obj-$(CONFIG_VEML6046X00) += veml6046x00.o 70 71 obj-$(CONFIG_VEML6070) += veml6070.o 71 72 obj-$(CONFIG_VEML6075) += veml6075.o 72 73 obj-$(CONFIG_VL6180) += vl6180.o
+6 -13
drivers/iio/light/acpi-als.c
··· 49 49 IIO_CHAN_SOFT_TIMESTAMP(1), 50 50 }; 51 51 52 - /* 53 - * The event buffer contains timestamp and all the data from 54 - * the ACPI0008 block. There are multiple, but so far we only 55 - * support _ALI (illuminance): One channel, padding and timestamp. 56 - */ 57 - #define ACPI_ALS_EVT_BUFFER_SIZE \ 58 - (sizeof(s32) + sizeof(s32) + sizeof(s64)) 59 - 60 52 struct acpi_als { 61 53 struct acpi_device *device; 62 54 struct mutex lock; 63 55 struct iio_trigger *trig; 64 - 65 - s32 evt_buffer[ACPI_ALS_EVT_BUFFER_SIZE / sizeof(s32)] __aligned(8); 66 56 }; 67 57 68 58 /* ··· 142 152 struct iio_poll_func *pf = p; 143 153 struct iio_dev *indio_dev = pf->indio_dev; 144 154 struct acpi_als *als = iio_priv(indio_dev); 145 - s32 *buffer = als->evt_buffer; 155 + struct { 156 + s32 light; 157 + aligned_s64 ts; 158 + } scan = { }; 146 159 s32 val; 147 160 int ret; 148 161 ··· 154 161 ret = acpi_als_read_value(als, ACPI_ALS_ILLUMINANCE, &val); 155 162 if (ret < 0) 156 163 goto out; 157 - *buffer = val; 164 + scan.light = val; 158 165 159 166 /* 160 167 * When coming from own trigger via polls, set polling function ··· 167 174 if (!pf->timestamp) 168 175 pf->timestamp = iio_get_time_ns(indio_dev); 169 176 170 - iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp); 177 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), pf->timestamp); 171 178 out: 172 179 mutex_unlock(&als->lock); 173 180 iio_trigger_notify_done(indio_dev->trig);
+6 -6
drivers/iio/light/adjd_s311.c
··· 54 54 55 55 struct adjd_s311_data { 56 56 struct i2c_client *client; 57 - struct { 58 - s16 chans[4]; 59 - aligned_s64 ts; 60 - } scan; 61 57 }; 62 58 63 59 enum adjd_s311_channel_idx { ··· 116 120 struct adjd_s311_data *data = iio_priv(indio_dev); 117 121 s64 time_ns = iio_get_time_ns(indio_dev); 118 122 int i, j = 0; 123 + struct { 124 + s16 chans[4]; 125 + aligned_s64 ts; 126 + } scan = { }; 119 127 120 128 int ret = adjd_s311_req_data(indio_dev); 121 129 if (ret < 0) ··· 131 131 if (ret < 0) 132 132 goto done; 133 133 134 - data->scan.chans[j++] = ret & ADJD_S311_DATA_MASK; 134 + scan.chans[j++] = ret & ADJD_S311_DATA_MASK; 135 135 } 136 136 137 - iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, time_ns); 137 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), time_ns); 138 138 139 139 done: 140 140 iio_trigger_notify_done(indio_dev->trig);
+1 -1
drivers/iio/light/al3000a.c
··· 94 94 95 95 ret = devm_add_action_or_reset(dev, al3000a_set_pwr_off, data); 96 96 if (ret) 97 - return dev_err_probe(dev, ret, "failed to add action\n"); 97 + return ret; 98 98 99 99 ret = regmap_write(data->regmap, AL3000A_REG_SYSTEM, AL3000A_CONFIG_RESET); 100 100 if (ret)
+1 -3
drivers/iio/light/apds9306.c
··· 537 537 538 538 *val = get_unaligned_le24(&buff); 539 539 540 - pm_runtime_mark_last_busy(data->dev); 541 540 pm_runtime_put_autosuspend(data->dev); 542 541 543 542 return 0; ··· 1120 1121 if (ret) 1121 1122 return ret; 1122 1123 1123 - pm_runtime_mark_last_busy(data->dev); 1124 1124 pm_runtime_put_autosuspend(data->dev); 1125 1125 1126 1126 return 0; ··· 1307 1309 1308 1310 ret = devm_add_action_or_reset(dev, apds9306_powerdown, data); 1309 1311 if (ret) 1310 - return dev_err_probe(dev, ret, "failed to add action or reset\n"); 1312 + return ret; 1311 1313 1312 1314 ret = devm_iio_device_register(dev, indio_dev); 1313 1315 if (ret)
-1
drivers/iio/light/apds9960.c
··· 495 495 usleep_range(data->als_adc_int_us, 496 496 APDS9960_MAX_INT_TIME_IN_US); 497 497 } else { 498 - pm_runtime_mark_last_busy(dev); 499 498 ret = pm_runtime_put_autosuspend(dev); 500 499 } 501 500
+3 -4
drivers/iio/light/bh1745.c
··· 755 755 scan.chans[j++] = value; 756 756 } 757 757 758 - iio_push_to_buffers_with_timestamp(indio_dev, &scan, 759 - iio_get_time_ns(indio_dev)); 758 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), 759 + iio_get_time_ns(indio_dev)); 760 760 761 761 err: 762 762 iio_trigger_notify_done(indio_dev->trig); ··· 814 814 815 815 ret = devm_add_action_or_reset(dev, bh1745_power_off, data); 816 816 if (ret) 817 - return dev_err_probe(dev, ret, 818 - "Failed to add action or reset\n"); 817 + return ret; 819 818 820 819 return 0; 821 820 }
-1
drivers/iio/light/bh1780.c
··· 111 111 value = bh1780_read_word(bh1780, BH1780_REG_DLOW); 112 112 if (value < 0) 113 113 return value; 114 - pm_runtime_mark_last_busy(&bh1780->client->dev); 115 114 pm_runtime_put_autosuspend(&bh1780->client->dev); 116 115 *val = value; 117 116
-2
drivers/iio/light/gp2ap002.c
··· 271 271 } 272 272 273 273 out: 274 - pm_runtime_mark_last_busy(gp2ap002->dev); 275 274 pm_runtime_put_autosuspend(gp2ap002->dev); 276 275 277 276 return ret; ··· 352 353 pm_runtime_get_sync(gp2ap002->dev); 353 354 gp2ap002->enabled = true; 354 355 } else { 355 - pm_runtime_mark_last_busy(gp2ap002->dev); 356 356 pm_runtime_put_autosuspend(gp2ap002->dev); 357 357 gp2ap002->enabled = false; 358 358 }
+3 -2
drivers/iio/light/hid-sensor-als.c
··· 262 262 if (!als_state->timestamp) 263 263 als_state->timestamp = iio_get_time_ns(indio_dev); 264 264 265 - iio_push_to_buffers_with_timestamp(indio_dev, &als_state->scan, 266 - als_state->timestamp); 265 + iio_push_to_buffers_with_ts(indio_dev, &als_state->scan, 266 + sizeof(als_state->scan), 267 + als_state->timestamp); 267 268 als_state->timestamp = 0; 268 269 } 269 270
+3 -8
drivers/iio/light/isl29028.c
··· 336 336 static int isl29028_set_pm_runtime_busy(struct isl29028_chip *chip, bool on) 337 337 { 338 338 struct device *dev = regmap_get_device(chip->regmap); 339 - int ret; 340 339 341 - if (on) { 342 - ret = pm_runtime_resume_and_get(dev); 343 - } else { 344 - pm_runtime_mark_last_busy(dev); 345 - ret = pm_runtime_put_autosuspend(dev); 346 - } 340 + if (on) 341 + return pm_runtime_resume_and_get(dev); 347 342 348 - return ret; 343 + return pm_runtime_put_autosuspend(dev); 349 344 } 350 345 351 346 /* Channel IO */
+7 -7
drivers/iio/light/isl29125.c
··· 51 51 struct isl29125_data { 52 52 struct i2c_client *client; 53 53 u8 conf1; 54 - /* Ensure timestamp is naturally aligned */ 55 - struct { 56 - u16 chans[3]; 57 - aligned_s64 timestamp; 58 - } scan; 59 54 }; 60 55 61 56 #define ISL29125_CHANNEL(_color, _si) { \ ··· 174 179 struct iio_dev *indio_dev = pf->indio_dev; 175 180 struct isl29125_data *data = iio_priv(indio_dev); 176 181 int i, j = 0; 182 + /* Ensure timestamp is naturally aligned */ 183 + struct { 184 + u16 chans[3]; 185 + aligned_s64 timestamp; 186 + } scan = { }; 177 187 178 188 iio_for_each_active_channel(indio_dev, i) { 179 189 int ret = i2c_smbus_read_word_data(data->client, ··· 186 186 if (ret < 0) 187 187 goto done; 188 188 189 - data->scan.chans[j++] = ret; 189 + scan.chans[j++] = ret; 190 190 } 191 191 192 - iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, 192 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), 193 193 iio_get_time_ns(indio_dev)); 194 194 195 195 done:
+185 -12
drivers/iio/light/ltr390.c
··· 26 26 #include <linux/math.h> 27 27 #include <linux/module.h> 28 28 #include <linux/mutex.h> 29 + #include <linux/pm_runtime.h> 29 30 #include <linux/regmap.h> 30 31 31 32 #include <linux/iio/iio.h> ··· 39 38 #define LTR390_ALS_UVS_GAIN 0x05 40 39 #define LTR390_PART_ID 0x06 41 40 #define LTR390_MAIN_STATUS 0x07 41 + 42 42 #define LTR390_ALS_DATA 0x0D 43 + #define LTR390_ALS_DATA_BYTE(n) (LTR390_ALS_DATA + (n)) 44 + 43 45 #define LTR390_UVS_DATA 0x10 46 + #define LTR390_UVS_DATA_BYTE(n) (LTR390_UVS_DATA + (n)) 47 + 44 48 #define LTR390_INT_CFG 0x19 45 49 #define LTR390_INT_PST 0x1A 50 + 46 51 #define LTR390_THRESH_UP 0x21 52 + #define LTR390_THRESH_UP_BYTE(n) (LTR390_THRESH_UP + (n)) 53 + 47 54 #define LTR390_THRESH_LOW 0x24 55 + #define LTR390_THRESH_LOW_BYTE(n) (LTR390_THRESH_LOW + (n)) 48 56 49 57 #define LTR390_PART_NUMBER_ID 0xb 50 58 #define LTR390_ALS_UVS_GAIN_MASK GENMASK(2, 0) ··· 106 96 enum ltr390_mode mode; 107 97 int gain; 108 98 int int_time_us; 99 + bool irq_enabled; 100 + }; 101 + 102 + static const struct regmap_range ltr390_readable_reg_ranges[] = { 103 + regmap_reg_range(LTR390_MAIN_CTRL, LTR390_MAIN_CTRL), 104 + regmap_reg_range(LTR390_ALS_UVS_MEAS_RATE, LTR390_MAIN_STATUS), 105 + regmap_reg_range(LTR390_ALS_DATA_BYTE(0), LTR390_UVS_DATA_BYTE(2)), 106 + regmap_reg_range(LTR390_INT_CFG, LTR390_INT_PST), 107 + regmap_reg_range(LTR390_THRESH_UP_BYTE(0), LTR390_THRESH_LOW_BYTE(2)), 108 + }; 109 + 110 + static const struct regmap_access_table ltr390_readable_reg_table = { 111 + .yes_ranges = ltr390_readable_reg_ranges, 112 + .n_yes_ranges = ARRAY_SIZE(ltr390_readable_reg_ranges), 113 + }; 114 + 115 + static const struct regmap_range ltr390_writeable_reg_ranges[] = { 116 + regmap_reg_range(LTR390_MAIN_CTRL, LTR390_MAIN_CTRL), 117 + regmap_reg_range(LTR390_ALS_UVS_MEAS_RATE, LTR390_ALS_UVS_GAIN), 118 + regmap_reg_range(LTR390_INT_CFG, LTR390_INT_PST), 119 + regmap_reg_range(LTR390_THRESH_UP_BYTE(0), LTR390_THRESH_LOW_BYTE(2)), 120 + }; 121 + 122 + static const struct regmap_access_table ltr390_writeable_reg_table = { 123 + .yes_ranges = ltr390_writeable_reg_ranges, 124 + .n_yes_ranges = ARRAY_SIZE(ltr390_writeable_reg_ranges), 109 125 }; 110 126 111 127 static const struct regmap_config ltr390_regmap_config = { ··· 139 103 .reg_bits = 8, 140 104 .reg_stride = 1, 141 105 .val_bits = 8, 106 + .max_register = LTR390_THRESH_LOW_BYTE(2), 107 + .rd_table = &ltr390_readable_reg_table, 108 + .wr_table = &ltr390_writeable_reg_table, 142 109 }; 143 110 144 111 /* Sampling frequency is in mili Hz and mili Seconds */ ··· 217 178 return ltr390_samp_freq_table[value][option]; 218 179 } 219 180 220 - static int ltr390_read_raw(struct iio_dev *iio_device, 221 - struct iio_chan_spec const *chan, int *val, 222 - int *val2, long mask) 181 + 182 + static int ltr390_do_read_raw(struct iio_dev *iio_device, 183 + struct iio_chan_spec const *chan, int *val, 184 + int *val2, long mask) 223 185 { 224 186 int ret; 225 187 struct ltr390_data *data = iio_priv(iio_device); ··· 281 241 default: 282 242 return -EINVAL; 283 243 } 244 + } 245 + 246 + static int ltr390_read_raw(struct iio_dev *iio_device, 247 + struct iio_chan_spec const *chan, 248 + int *val, int *val2, long mask) 249 + { 250 + int ret; 251 + struct ltr390_data *data = iio_priv(iio_device); 252 + struct device *dev = &data->client->dev; 253 + 254 + ret = pm_runtime_resume_and_get(dev); 255 + if (ret < 0) { 256 + dev_err(dev, "runtime PM failed to resume: %d\n", ret); 257 + return ret; 258 + } 259 + 260 + ret = ltr390_do_read_raw(iio_device, chan, val, val2, mask); 261 + 262 + pm_runtime_put_autosuspend(dev); 263 + 264 + return ret; 284 265 } 285 266 286 267 /* integration time in us */ ··· 610 549 return FIELD_GET(LTR390_LS_INT_EN, status); 611 550 } 612 551 613 - static int ltr390_write_event_config(struct iio_dev *indio_dev, 614 - const struct iio_chan_spec *chan, 615 - enum iio_event_type type, 616 - enum iio_event_direction dir, 617 - bool state) 552 + static int ltr390_do_event_config(struct iio_dev *indio_dev, 553 + const struct iio_chan_spec *chan, 554 + enum iio_event_type type, 555 + enum iio_event_direction dir, 556 + bool state) 618 557 { 619 558 struct ltr390_data *data = iio_priv(indio_dev); 620 559 int ret; ··· 622 561 if (!state) 623 562 return regmap_clear_bits(data->regmap, LTR390_INT_CFG, LTR390_LS_INT_EN); 624 563 625 - guard(mutex)(&data->lock); 626 564 ret = regmap_set_bits(data->regmap, LTR390_INT_CFG, LTR390_LS_INT_EN); 627 565 if (ret < 0) 628 566 return ret; ··· 646 586 } 647 587 } 648 588 589 + static int ltr390_write_event_config(struct iio_dev *indio_dev, 590 + const struct iio_chan_spec *chan, 591 + enum iio_event_type type, 592 + enum iio_event_direction dir, 593 + bool state) 594 + { 595 + int ret; 596 + struct ltr390_data *data = iio_priv(indio_dev); 597 + struct device *dev = &data->client->dev; 598 + 599 + guard(mutex)(&data->lock); 600 + 601 + if (state && !data->irq_enabled) { 602 + ret = pm_runtime_resume_and_get(dev); 603 + if (ret < 0) { 604 + dev_err(dev, "runtime PM failed to resume: %d\n", ret); 605 + return ret; 606 + } 607 + data->irq_enabled = true; 608 + } 609 + 610 + ret = ltr390_do_event_config(indio_dev, chan, type, dir, state); 611 + 612 + if (!state && data->irq_enabled) { 613 + data->irq_enabled = false; 614 + pm_runtime_put_autosuspend(dev); 615 + } 616 + 617 + return ret; 618 + } 619 + 620 + static int ltr390_debugfs_reg_access(struct iio_dev *indio_dev, 621 + unsigned int reg, unsigned int writeval, 622 + unsigned int *readval) 623 + { 624 + struct ltr390_data *data = iio_priv(indio_dev); 625 + 626 + guard(mutex)(&data->lock); 627 + 628 + if (readval) 629 + return regmap_read(data->regmap, reg, readval); 630 + 631 + return regmap_write(data->regmap, reg, writeval); 632 + } 633 + 649 634 static const struct iio_info ltr390_info = { 650 635 .read_raw = ltr390_read_raw, 651 636 .write_raw = ltr390_write_raw, ··· 699 594 .read_event_config = ltr390_read_event_config, 700 595 .write_event_value = ltr390_write_event_value, 701 596 .write_event_config = ltr390_write_event_config, 597 + .debugfs_reg_access = ltr390_debugfs_reg_access, 702 598 }; 703 599 704 600 static irqreturn_t ltr390_interrupt_handler(int irq, void *private) ··· 734 628 return IRQ_HANDLED; 735 629 } 736 630 631 + static void ltr390_powerdown(void *priv) 632 + { 633 + struct ltr390_data *data = priv; 634 + struct device *dev = &data->client->dev; 635 + int ret; 636 + 637 + guard(mutex)(&data->lock); 638 + 639 + /* Ensure that power off and interrupts are disabled */ 640 + if (data->irq_enabled) { 641 + ret = regmap_clear_bits(data->regmap, LTR390_INT_CFG, LTR390_LS_INT_EN); 642 + if (ret < 0) 643 + dev_err(dev, "failed to disable interrupts\n"); 644 + 645 + data->irq_enabled = false; 646 + pm_runtime_put_autosuspend(dev); 647 + } 648 + 649 + ret = regmap_clear_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_SENSOR_ENABLE); 650 + if (ret < 0) 651 + dev_err(dev, "failed to disable sensor\n"); 652 + } 653 + 654 + static int ltr390_pm_init(struct ltr390_data *data) 655 + { 656 + int ret; 657 + struct device *dev = &data->client->dev; 658 + 659 + ret = devm_pm_runtime_set_active_enabled(dev); 660 + if (ret) 661 + return dev_err_probe(dev, ret, "failed to enable runtime PM\n"); 662 + 663 + pm_runtime_set_autosuspend_delay(dev, 1000); 664 + pm_runtime_use_autosuspend(dev); 665 + return 0; 666 + } 667 + 737 668 static int ltr390_probe(struct i2c_client *client) 738 669 { 739 670 struct ltr390_data *data; ··· 783 640 if (!indio_dev) 784 641 return -ENOMEM; 785 642 786 - data = iio_priv(indio_dev); 643 + i2c_set_clientdata(client, indio_dev); 787 644 645 + data = iio_priv(indio_dev); 788 646 data->regmap = devm_regmap_init_i2c(client, &ltr390_regmap_config); 789 647 if (IS_ERR(data->regmap)) 790 648 return dev_err_probe(dev, PTR_ERR(data->regmap), ··· 798 654 data->gain = 3; 799 655 /* default mode for ltr390 is ALS mode */ 800 656 data->mode = LTR390_SET_ALS_MODE; 657 + /* default value of irq_enabled is false */ 658 + data->irq_enabled = false; 801 659 802 660 mutex_init(&data->lock); 803 661 ··· 827 681 if (ret) 828 682 return dev_err_probe(dev, ret, "failed to enable the sensor\n"); 829 683 684 + ret = devm_add_action_or_reset(dev, ltr390_powerdown, data); 685 + if (ret) 686 + return dev_err_probe(dev, ret, "failed to add action or reset\n"); 687 + 830 688 if (client->irq) { 831 689 ret = devm_request_threaded_irq(dev, client->irq, 832 690 NULL, ltr390_interrupt_handler, ··· 841 691 return dev_err_probe(dev, ret, 842 692 "request irq (%d) failed\n", client->irq); 843 693 } 694 + 695 + ret = ltr390_pm_init(data); 696 + if (ret) 697 + return dev_err_probe(dev, ret, "failed to initialize runtime PM\n"); 844 698 845 699 return devm_iio_device_register(dev, indio_dev); 846 700 } ··· 867 713 LTR390_SENSOR_ENABLE); 868 714 } 869 715 870 - static DEFINE_SIMPLE_DEV_PM_OPS(ltr390_pm_ops, ltr390_suspend, ltr390_resume); 716 + static int ltr390_runtime_suspend(struct device *dev) 717 + { 718 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 719 + struct ltr390_data *data = iio_priv(indio_dev); 720 + 721 + return regmap_clear_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_SENSOR_ENABLE); 722 + } 723 + 724 + static int ltr390_runtime_resume(struct device *dev) 725 + { 726 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 727 + struct ltr390_data *data = iio_priv(indio_dev); 728 + 729 + return regmap_set_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_SENSOR_ENABLE); 730 + } 731 + 732 + static const struct dev_pm_ops ltr390_pm_ops = { 733 + SYSTEM_SLEEP_PM_OPS(ltr390_suspend, ltr390_resume) 734 + RUNTIME_PM_OPS(ltr390_runtime_suspend, ltr390_runtime_resume, NULL) 735 + }; 871 736 872 737 static const struct i2c_device_id ltr390_id[] = { 873 738 { "ltr390" }, ··· 904 731 .driver = { 905 732 .name = "ltr390", 906 733 .of_match_table = ltr390_of_table, 907 - .pm = pm_sleep_ptr(&ltr390_pm_ops), 734 + .pm = pm_ptr(&ltr390_pm_ops), 908 735 }, 909 736 .probe = ltr390_probe, 910 737 .id_table = ltr390_id,
+2 -2
drivers/iio/light/ltr501.c
··· 1315 1315 scan.channels[j++] = psdata & LTR501_PS_DATA_MASK; 1316 1316 } 1317 1317 1318 - iio_push_to_buffers_with_timestamp(indio_dev, &scan, 1319 - iio_get_time_ns(indio_dev)); 1318 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), 1319 + iio_get_time_ns(indio_dev)); 1320 1320 1321 1321 done: 1322 1322 iio_trigger_notify_done(indio_dev->trig);
-1
drivers/iio/light/ltrf216a.c
··· 208 208 return ret; 209 209 } 210 210 } else { 211 - pm_runtime_mark_last_busy(dev); 212 211 pm_runtime_put_autosuspend(dev); 213 212 } 214 213
+9 -9
drivers/iio/light/max44000.c
··· 75 75 struct max44000_data { 76 76 struct mutex lock; 77 77 struct regmap *regmap; 78 - /* Ensure naturally aligned timestamp */ 79 - struct { 80 - u16 channels[2]; 81 - aligned_s64 ts; 82 - } scan; 83 78 }; 84 79 85 80 /* Default scale is set to the minimum of 0.03125 or 1 / (1 << 5) lux */ ··· 491 496 int index = 0; 492 497 unsigned int regval; 493 498 int ret; 499 + struct { 500 + u16 channels[2]; 501 + aligned_s64 ts; 502 + } scan = { }; 503 + 494 504 495 505 mutex_lock(&data->lock); 496 506 if (test_bit(MAX44000_SCAN_INDEX_ALS, indio_dev->active_scan_mask)) { 497 507 ret = max44000_read_alsval(data); 498 508 if (ret < 0) 499 509 goto out_unlock; 500 - data->scan.channels[index++] = ret; 510 + scan.channels[index++] = ret; 501 511 } 502 512 if (test_bit(MAX44000_SCAN_INDEX_PRX, indio_dev->active_scan_mask)) { 503 513 ret = regmap_read(data->regmap, MAX44000_REG_PRX_DATA, &regval); 504 514 if (ret < 0) 505 515 goto out_unlock; 506 - data->scan.channels[index] = regval; 516 + scan.channels[index] = regval; 507 517 } 508 518 mutex_unlock(&data->lock); 509 519 510 - iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, 511 - iio_get_time_ns(indio_dev)); 520 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), 521 + iio_get_time_ns(indio_dev)); 512 522 iio_trigger_notify_done(indio_dev->trig); 513 523 return IRQ_HANDLED; 514 524
+1 -2
drivers/iio/light/opt4001.c
··· 428 428 opt4001_chip_off_action, 429 429 chip); 430 430 if (ret < 0) 431 - return dev_err_probe(&client->dev, ret, 432 - "Failed to setup power off action\n"); 431 + return ret; 433 432 434 433 return devm_iio_device_register(&client->dev, indio_dev); 435 434 }
+3 -4
drivers/iio/light/opt4060.c
··· 1104 1104 } 1105 1105 } 1106 1106 1107 - iio_push_to_buffers_with_timestamp(idev, &raw, pf->timestamp); 1107 + iio_push_to_buffers_with_ts(idev, &raw, sizeof(raw), pf->timestamp); 1108 1108 err_read: 1109 1109 iio_trigger_notify_done(idev->trig); 1110 1110 return IRQ_HANDLED; ··· 1212 1212 name = devm_kasprintf(chip->dev, GFP_KERNEL, "%s-opt4060", 1213 1213 dev_name(chip->dev)); 1214 1214 if (!name) 1215 - return dev_err_probe(chip->dev, -ENOMEM, "Failed to alloc chip name\n"); 1215 + return -ENOMEM; 1216 1216 1217 1217 ret = devm_request_threaded_irq(chip->dev, chip->irq, NULL, opt4060_irq_thread, 1218 1218 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, ··· 1299 1299 1300 1300 ret = devm_add_action_or_reset(dev, opt4060_chip_off_action, chip); 1301 1301 if (ret < 0) 1302 - return dev_err_probe(dev, ret, 1303 - "Failed to setup power off action\n"); 1302 + return ret; 1304 1303 1305 1304 ret = opt4060_setup_buffer(chip, indio_dev); 1306 1305 if (ret)
+3 -8
drivers/iio/light/pa12203001.c
··· 185 185 mutex_unlock(&data->lock); 186 186 } 187 187 188 - if (on) { 189 - ret = pm_runtime_resume_and_get(&data->client->dev); 188 + if (on) 189 + return pm_runtime_resume_and_get(&data->client->dev); 190 190 191 - } else { 192 - pm_runtime_mark_last_busy(&data->client->dev); 193 - ret = pm_runtime_put_autosuspend(&data->client->dev); 194 - } 195 - 196 - return ret; 191 + return pm_runtime_put_autosuspend(&data->client->dev); 197 192 198 193 err: 199 194 mutex_unlock(&data->lock);
+2 -1
drivers/iio/light/rohm-bu27034.c
··· 1193 1193 */ 1194 1194 data->scan.mlux = (u32)mlux; 1195 1195 } 1196 - iio_push_to_buffers_with_timestamp(idev, &data->scan, tstamp); 1196 + iio_push_to_buffers_with_ts(idev, &data->scan, 1197 + sizeof(data->scan), tstamp); 1197 1198 } 1198 1199 1199 1200 return 0;
+4 -6
drivers/iio/light/rpr0521.c
··· 358 358 * Note: If either measurement is re-enabled before _suspend(), 359 359 * both stay enabled until _suspend(). 360 360 */ 361 - if (on) { 361 + if (on) 362 362 ret = pm_runtime_resume_and_get(&data->client->dev); 363 - } else { 364 - pm_runtime_mark_last_busy(&data->client->dev); 363 + else 365 364 ret = pm_runtime_put_autosuspend(&data->client->dev); 366 - } 367 365 if (ret < 0) { 368 366 dev_err(&data->client->dev, 369 367 "Failed: rpr0521_set_power_state for %d, ret %d\n", ··· 455 457 data->scan.channels, 456 458 (3 * 2) + 1); /* 3 * 16-bit + (discarded) int clear reg. */ 457 459 if (!err) 458 - iio_push_to_buffers_with_timestamp(indio_dev, 459 - &data->scan, pf->timestamp); 460 + iio_push_to_buffers_with_ts(indio_dev, &data->scan, 461 + sizeof(data->scan), pf->timestamp); 460 462 else 461 463 dev_err(&data->client->dev, 462 464 "Trigger consumer can't read from sensor.\n");
+3 -2
drivers/iio/light/si1145.c
··· 494 494 goto done; 495 495 } 496 496 497 - iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 498 - iio_get_time_ns(indio_dev)); 497 + iio_push_to_buffers_with_ts(indio_dev, data->buffer, 498 + sizeof(data->buffer), 499 + iio_get_time_ns(indio_dev)); 499 500 500 501 done: 501 502 iio_trigger_notify_done(indio_dev->trig);
-5
drivers/iio/light/st_uvis25.h
··· 27 27 struct iio_trigger *trig; 28 28 bool enabled; 29 29 int irq; 30 - /* Ensure timestamp is naturally aligned */ 31 - struct { 32 - u8 chan; 33 - aligned_s64 ts; 34 - } scan; 35 30 }; 36 31 37 32 extern const struct dev_pm_ops st_uvis25_pm_ops;
+9 -3
drivers/iio/light/st_uvis25_core.c
··· 234 234 struct st_uvis25_hw *hw = iio_priv(iio_dev); 235 235 unsigned int val; 236 236 int err; 237 + /* Ensure timestamp is naturally aligned */ 238 + struct { 239 + u8 chan; 240 + aligned_s64 ts; 241 + } scan = { }; 242 + 237 243 238 244 err = regmap_read(hw->regmap, ST_UVIS25_REG_OUT_ADDR, &val); 239 245 if (err < 0) 240 246 goto out; 241 247 242 - hw->scan.chan = val; 248 + scan.chan = val; 243 249 244 - iio_push_to_buffers_with_timestamp(iio_dev, &hw->scan, 245 - iio_get_time_ns(iio_dev)); 250 + iio_push_to_buffers_with_ts(iio_dev, &scan, sizeof(scan), 251 + iio_get_time_ns(iio_dev)); 246 252 247 253 out: 248 254 iio_trigger_notify_done(hw->trig);
+1 -3
drivers/iio/light/stk3310.c
··· 607 607 struct stk3310_data *data; 608 608 609 609 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 610 - if (!indio_dev) { 611 - dev_err(&client->dev, "iio allocation failed!\n"); 610 + if (!indio_dev) 612 611 return -ENOMEM; 613 - } 614 612 615 613 data = iio_priv(indio_dev); 616 614 data->client = client;
+8 -7
drivers/iio/light/tcs3414.c
··· 53 53 u8 control; 54 54 u8 gain; 55 55 u8 timing; 56 - /* Ensure timestamp is naturally aligned */ 57 - struct { 58 - u16 chans[4]; 59 - aligned_s64 timestamp; 60 - } scan; 61 56 }; 62 57 63 58 #define TCS3414_CHANNEL(_color, _si, _addr) { \ ··· 199 204 struct iio_dev *indio_dev = pf->indio_dev; 200 205 struct tcs3414_data *data = iio_priv(indio_dev); 201 206 int i, j = 0; 207 + /* Ensure timestamp is naturally aligned */ 208 + struct { 209 + u16 chans[4]; 210 + aligned_s64 timestamp; 211 + } scan = { }; 212 + 202 213 203 214 iio_for_each_active_channel(indio_dev, i) { 204 215 int ret = i2c_smbus_read_word_data(data->client, ··· 212 211 if (ret < 0) 213 212 goto done; 214 213 215 - data->scan.chans[j++] = ret; 214 + scan.chans[j++] = ret; 216 215 } 217 216 218 - iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, 217 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), 219 218 iio_get_time_ns(indio_dev)); 220 219 221 220 done:
+7 -7
drivers/iio/light/tcs3472.c
··· 64 64 u8 control; 65 65 u8 atime; 66 66 u8 apers; 67 - /* Ensure timestamp is naturally aligned */ 68 - struct { 69 - u16 chans[4]; 70 - aligned_s64 timestamp; 71 - } scan; 72 67 }; 73 68 74 69 static const struct iio_event_spec tcs3472_events[] = { ··· 372 377 struct iio_dev *indio_dev = pf->indio_dev; 373 378 struct tcs3472_data *data = iio_priv(indio_dev); 374 379 int i, j = 0; 380 + /* Ensure timestamp is naturally aligned */ 381 + struct { 382 + u16 chans[4]; 383 + aligned_s64 timestamp; 384 + } scan = { }; 375 385 376 386 int ret = tcs3472_req_data(data); 377 387 if (ret < 0) ··· 388 388 if (ret < 0) 389 389 goto done; 390 390 391 - data->scan.chans[j++] = ret; 391 + scan.chans[j++] = ret; 392 392 } 393 393 394 - iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, 394 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), 395 395 iio_get_time_ns(indio_dev)); 396 396 397 397 done:
+3 -9
drivers/iio/light/tsl2583.c
··· 641 641 642 642 static int tsl2583_set_pm_runtime_busy(struct tsl2583_chip *chip, bool on) 643 643 { 644 - int ret; 644 + if (on) 645 + return pm_runtime_resume_and_get(&chip->client->dev); 645 646 646 - if (on) { 647 - ret = pm_runtime_resume_and_get(&chip->client->dev); 648 - } else { 649 - pm_runtime_mark_last_busy(&chip->client->dev); 650 - ret = pm_runtime_put_autosuspend(&chip->client->dev); 651 - } 652 - 653 - return ret; 647 + return pm_runtime_put_autosuspend(&chip->client->dev); 654 648 } 655 649 656 650 static int tsl2583_read_raw(struct iio_dev *indio_dev,
-2
drivers/iio/light/tsl2591.c
··· 772 772 err_unlock: 773 773 mutex_unlock(&chip->als_mutex); 774 774 775 - pm_runtime_mark_last_busy(&client->dev); 776 775 pm_runtime_put_autosuspend(&client->dev); 777 776 778 777 return ret; ··· 994 995 pm_runtime_get_sync(&client->dev); 995 996 } else if (!state && chip->events_enabled) { 996 997 chip->events_enabled = false; 997 - pm_runtime_mark_last_busy(&client->dev); 998 998 pm_runtime_put_autosuspend(&client->dev); 999 999 } 1000 1000
+3 -9
drivers/iio/light/us5182d.c
··· 361 361 362 362 static int us5182d_set_power_state(struct us5182d_data *data, bool on) 363 363 { 364 - int ret; 365 - 366 364 if (data->power_mode == US5182D_ONESHOT) 367 365 return 0; 368 366 369 - if (on) { 370 - ret = pm_runtime_resume_and_get(&data->client->dev); 371 - } else { 372 - pm_runtime_mark_last_busy(&data->client->dev); 373 - ret = pm_runtime_put_autosuspend(&data->client->dev); 374 - } 367 + if (on) 368 + return pm_runtime_resume_and_get(&data->client->dev); 375 369 376 - return ret; 370 + return pm_runtime_put_autosuspend(&data->client->dev); 377 371 } 378 372 379 373 static int us5182d_read_value(struct us5182d_data *data,
+10 -12
drivers/iio/light/vcnl4000.c
··· 576 576 static int vcnl4000_set_pm_runtime_state(struct vcnl4000_data *data, bool on) 577 577 { 578 578 struct device *dev = &data->client->dev; 579 - int ret; 580 579 581 - if (on) { 582 - ret = pm_runtime_resume_and_get(dev); 583 - } else { 584 - pm_runtime_mark_last_busy(dev); 585 - ret = pm_runtime_put_autosuspend(dev); 586 - } 580 + if (on) 581 + return pm_runtime_resume_and_get(dev); 587 582 588 - return ret; 583 + return pm_runtime_put_autosuspend(dev); 589 584 } 590 585 591 586 static int vcnl4040_read_als_it(struct vcnl4000_data *data, int *val, int *val2) ··· 1657 1662 struct iio_dev *indio_dev = pf->indio_dev; 1658 1663 struct vcnl4000_data *data = iio_priv(indio_dev); 1659 1664 const unsigned long *active_scan_mask = indio_dev->active_scan_mask; 1660 - u16 buffer[8] __aligned(8) = {0}; /* 1x16-bit + naturally aligned ts */ 1665 + struct { 1666 + u16 chan; 1667 + aligned_s64 ts; 1668 + } scan = { }; 1661 1669 bool data_read = false; 1662 1670 unsigned long isr; 1663 1671 int val = 0; ··· 1680 1682 if (ret < 0) 1681 1683 goto end; 1682 1684 1683 - buffer[0] = val; 1685 + scan.chan = val; 1684 1686 data_read = true; 1685 1687 } 1686 1688 } ··· 1693 1695 if (!data_read) 1694 1696 goto end; 1695 1697 1696 - iio_push_to_buffers_with_timestamp(indio_dev, buffer, 1697 - iio_get_time_ns(indio_dev)); 1698 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), 1699 + iio_get_time_ns(indio_dev)); 1698 1700 1699 1701 end: 1700 1702 iio_trigger_notify_done(indio_dev->trig);
+3 -8
drivers/iio/light/vcnl4035.c
··· 141 141 142 142 static int vcnl4035_set_pm_runtime_state(struct vcnl4035_data *data, bool on) 143 143 { 144 - int ret; 145 144 struct device *dev = &data->client->dev; 146 145 147 - if (on) { 148 - ret = pm_runtime_resume_and_get(dev); 149 - } else { 150 - pm_runtime_mark_last_busy(dev); 151 - ret = pm_runtime_put_autosuspend(dev); 152 - } 146 + if (on) 147 + return pm_runtime_resume_and_get(dev); 153 148 154 - return ret; 149 + return pm_runtime_put_autosuspend(dev); 155 150 } 156 151 157 152 static int vcnl4035_read_info_raw(struct iio_dev *indio_dev,
+1 -1
drivers/iio/light/veml6030.c
··· 903 903 scan.chans[i++] = reg; 904 904 } 905 905 906 - iio_push_to_buffers_with_timestamp(iio, &scan, pf->timestamp); 906 + iio_push_to_buffers_with_ts(iio, &scan, sizeof(scan), pf->timestamp); 907 907 908 908 done: 909 909 iio_trigger_notify_done(iio->trig);
+1 -2
drivers/iio/light/veml6040.c
··· 219 219 220 220 indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 221 221 if (!indio_dev) 222 - return dev_err_probe(dev, -ENOMEM, 223 - "IIO device allocation failed\n"); 222 + return -ENOMEM; 224 223 225 224 regmap = devm_regmap_init_i2c(client, &veml6040_regmap_config); 226 225 if (IS_ERR(regmap))
+1030
drivers/iio/light/veml6046x00.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * VEML6046X00 High Accuracy RGBIR Color Sensor 4 + * 5 + * Copyright (c) 2025 Andreas Klinger <ak@it-klinger.de> 6 + */ 7 + 8 + #include <linux/array_size.h> 9 + #include <linux/bitfield.h> 10 + #include <linux/bits.h> 11 + #include <linux/dev_printk.h> 12 + #include <linux/err.h> 13 + #include <linux/i2c.h> 14 + #include <linux/interrupt.h> 15 + #include <linux/module.h> 16 + #include <linux/mod_devicetable.h> 17 + #include <linux/pm_runtime.h> 18 + #include <linux/regmap.h> 19 + #include <linux/time.h> 20 + #include <linux/types.h> 21 + #include <linux/units.h> 22 + 23 + #include <asm/byteorder.h> 24 + 25 + #include <linux/iio/iio.h> 26 + #include <linux/iio/trigger_consumer.h> 27 + #include <linux/iio/triggered_buffer.h> 28 + 29 + /* 30 + * Device registers 31 + * Those which are accessed as bulk io are omitted 32 + */ 33 + #define VEML6046X00_REG_CONF0 0x00 34 + #define VEML6046X00_REG_CONF1 0x01 35 + #define VEML6046X00_REG_THDH 0x04 36 + #define VEML6046X00_REG_THDL 0x06 37 + #define VEML6046X00_REG_R 0x10 38 + #define VEML6046X00_REG_G 0x12 39 + #define VEML6046X00_REG_B 0x14 40 + #define VEML6046X00_REG_IR 0x16 41 + #define VEML6046X00_REG_ID 0x18 42 + #define VEML6046X00_REG_INT 0x1A 43 + #define VEML6046X00_REG_INT_H 0x1B 44 + 45 + /* Bit masks for specific functionality */ 46 + #define VEML6046X00_CONF0_ON_0 BIT(0) 47 + #define VEML6046X00_CONF0_INT BIT(1) 48 + #define VEML6046X00_CONF0_AF_TRIG BIT(2) 49 + #define VEML6046X00_CONF0_AF BIT(3) 50 + #define VEML6046X00_CONF0_IT GENMASK(6, 4) 51 + #define VEML6046X00_CONF1_CAL BIT(0) 52 + #define VEML6046X00_CONF1_PERS GENMASK(2, 1) 53 + #define VEML6046X00_CONF1_GAIN GENMASK(4, 3) 54 + #define VEML6046X00_CONF1_PD_D2 BIT(6) 55 + #define VEML6046X00_CONF1_ON_1 BIT(7) 56 + #define VEML6046X00_INT_TH_H BIT(1) 57 + #define VEML6046X00_INT_TH_L BIT(2) 58 + #define VEML6046X00_INT_DRDY BIT(3) 59 + #define VEML6046X00_INT_MASK \ 60 + (VEML6046X00_INT_TH_H | VEML6046X00_INT_TH_L | VEML6046X00_INT_DRDY) 61 + 62 + #define VEML6046X00_GAIN_1 0x0 63 + #define VEML6046X00_GAIN_2 0x1 64 + #define VEML6046X00_GAIN_0_66 0x2 65 + #define VEML6046X00_GAIN_0_5 0x3 66 + 67 + #define VEML6046X00_PD_2_2 0x0 68 + #define VEML6046X00_PD_1_2 BIT(6) 69 + 70 + /* Autosuspend delay */ 71 + #define VEML6046X00_AUTOSUSPEND_MS (3 * MSEC_PER_SEC) 72 + 73 + enum veml6046x00_scan { 74 + VEML6046X00_SCAN_R, 75 + VEML6046X00_SCAN_G, 76 + VEML6046X00_SCAN_B, 77 + VEML6046X00_SCAN_IR, 78 + VEML6046X00_SCAN_TIMESTAMP, 79 + }; 80 + 81 + /** 82 + * struct veml6046x00_rf - Regmap field of configuration registers. 83 + * @int_en: Interrupt enable of green channel. 84 + * @mode: Mode of operation. 85 + * Driver uses always Active force mode. 86 + * @trig: Trigger to be set in active force mode for starting 87 + * measurement. 88 + * @it: Integration time. 89 + * @pers: Persistense - Number of threshold crossing for triggering 90 + * interrupt. 91 + */ 92 + struct veml6046x00_rf { 93 + struct regmap_field *int_en; 94 + struct regmap_field *mode; 95 + struct regmap_field *trig; 96 + struct regmap_field *it; 97 + struct regmap_field *pers; 98 + }; 99 + 100 + /** 101 + * struct veml6046x00_data - Private data of driver. 102 + * @regmap: Regmap definition of sensor. 103 + * @trig: Industrial-IO trigger. 104 + * @rf: Regmap field of configuration. 105 + */ 106 + struct veml6046x00_data { 107 + struct regmap *regmap; 108 + struct iio_trigger *trig; 109 + struct veml6046x00_rf rf; 110 + }; 111 + 112 + /** 113 + * DOC: Valid integration times (IT) 114 + * 115 + * static const int veml6046x00_it contains the array with valid IT. 116 + * 117 + * Register value to be read or written in regmap_field it on veml6046x00 is 118 + * identical with array index. 119 + * This means there is no separate translation table between valid integration 120 + * times and register values needed. The index of the array is identical with 121 + * the register value. 122 + * 123 + * The array is in the form as expected by the callback of the sysfs attribute 124 + * integration_time_available (IIO_CHAN_INFO_INT_TIME). So there is no 125 + * additional conversion needed. 126 + */ 127 + static const int veml6046x00_it[][2] = { 128 + { 0, 3125 }, 129 + { 0, 6250 }, 130 + { 0, 12500 }, 131 + { 0, 25000 }, 132 + { 0, 50000 }, 133 + { 0, 100000 }, 134 + { 0, 200000 }, 135 + { 0, 400000 }, 136 + }; 137 + 138 + /** 139 + * DOC: Handling of gain and photodiode size (PD) 140 + * 141 + * Gains here in the driver are not exactly the same as in the datasheet of the 142 + * sensor. The gain in the driver is a combination of the gain of the sensor 143 + * with the photodiode size (PD). 144 + * The following combinations are possible: 145 + * gain(driver) = gain(sensor) * PD 146 + * 0.25 = x0.5 * 1/2 147 + * 0.33 = x0.66 * 1/2 148 + * 0.5 = x0.5 * 2/2 149 + * 0.66 = x0.66 * 2/2 150 + * 1 = x1 * 2/2 151 + * 2 = x2 * 2/2 152 + */ 153 + 154 + /** 155 + * struct veml6046x00_gain_pd - Translation of gain and photodiode size (PD). 156 + * @gain_sen: Gain used in the sensor as described in the datasheet of the 157 + * sensor 158 + * @pd: Photodiode size in the sensor 159 + * 160 + * This is the translation table from the gain used in the driver (and also used 161 + * by the userspace interface in sysfs) to the gain and PD used in the sensor 162 + * hardware. 163 + * 164 + * There are six gain values visible to the user (0.25 .. 2) which translate to 165 + * two different gains in the sensor hardware (x0.5 .. x2) and two PD (1/2 and 166 + * 2/2). Theoretical are there eight combinations, but gain values 0.5 and 1 are 167 + * doubled and therefore the combination with the larger PD (2/2) is taken as 168 + * more photodiode cells are supposed to deliver a more precise result. 169 + */ 170 + struct veml6046x00_gain_pd { 171 + unsigned int gain_sen; 172 + unsigned int pd; 173 + }; 174 + 175 + static const struct veml6046x00_gain_pd veml6046x00_gain_pd[] = { 176 + { .gain_sen = VEML6046X00_GAIN_0_5, .pd = VEML6046X00_PD_1_2 }, 177 + { .gain_sen = VEML6046X00_GAIN_0_66, .pd = VEML6046X00_PD_1_2 }, 178 + { .gain_sen = VEML6046X00_GAIN_0_5, .pd = VEML6046X00_PD_2_2 }, 179 + { .gain_sen = VEML6046X00_GAIN_0_66, .pd = VEML6046X00_PD_2_2 }, 180 + { .gain_sen = VEML6046X00_GAIN_1, .pd = VEML6046X00_PD_2_2 }, 181 + { .gain_sen = VEML6046X00_GAIN_2, .pd = VEML6046X00_PD_2_2 }, 182 + }; 183 + 184 + /** 185 + * DOC: Factors for calculation of lux 186 + * 187 + * static const int veml6046x00_it_gains contains the factors for calculation of 188 + * lux. 189 + * 190 + * Depending on the set up integration time (IT), gain and photodiode size (PD) 191 + * the measured raw values are different if the light is constant. As the gain 192 + * and PD are already coupled in the driver (see &struct veml6046x00_gain_pd) 193 + * there are two dimensions remaining: IT and gain(driver). 194 + * 195 + * The array of available factors for a certain IT are grouped together in the 196 + * same form as expected by the callback of scale_available 197 + * (IIO_CHAN_INFO_SCALE). 198 + * 199 + * Factors for lux / raw count are taken directly from the datasheet. 200 + */ 201 + static const int veml6046x00_it_gains[][6][2] = { 202 + /* integration time: 3.125 ms */ 203 + { 204 + { 5, 376000 }, /* gain: x0.25 */ 205 + { 4, 72700 }, /* gain: x0.33 */ 206 + { 2, 688000 }, /* gain: x0.5 */ 207 + { 2, 36400 }, /* gain: x0.66 */ 208 + { 1, 344000 }, /* gain: x1 */ 209 + { 0, 672000 }, /* gain: x2 */ 210 + }, 211 + /* integration time: 6.25 ms */ 212 + { 213 + { 2, 688000 }, /* gain: x0.25 */ 214 + { 2, 36350 }, /* gain: x0.33 */ 215 + { 1, 344000 }, /* gain: x0.5 */ 216 + { 1, 18200 }, /* gain: x0.66 */ 217 + { 0, 672000 }, /* gain: x1 */ 218 + { 0, 336000 }, /* gain: x2 */ 219 + }, 220 + /* integration time: 12.5 ms */ 221 + { 222 + { 1, 344000 }, /* gain: x0.25 */ 223 + { 1, 18175 }, /* gain: x0.33 */ 224 + { 0, 672000 }, /* gain: x0.5 */ 225 + { 0, 509100 }, /* gain: x0.66 */ 226 + { 0, 336000 }, /* gain: x1 */ 227 + { 0, 168000 }, /* gain: x2 */ 228 + }, 229 + /* integration time: 25 ms */ 230 + { 231 + { 0, 672000 }, /* gain: x0.25 */ 232 + { 0, 509087 }, /* gain: x0.33 */ 233 + { 0, 336000 }, /* gain: x0.5 */ 234 + { 0, 254550 }, /* gain: x0.66 */ 235 + { 0, 168000 }, /* gain: x1 */ 236 + { 0, 84000 }, /* gain: x2 */ 237 + }, 238 + /* integration time: 50 ms */ 239 + { 240 + { 0, 336000 }, /* gain: x0.25 */ 241 + { 0, 254543 }, /* gain: x0.33 */ 242 + { 0, 168000 }, /* gain: x0.5 */ 243 + { 0, 127275 }, /* gain: x0.66 */ 244 + { 0, 84000 }, /* gain: x1 */ 245 + { 0, 42000 }, /* gain: x2 */ 246 + }, 247 + /* integration time: 100 ms */ 248 + { 249 + { 0, 168000 }, /* gain: x0.25 */ 250 + { 0, 127271 }, /* gain: x0.33 */ 251 + { 0, 84000 }, /* gain: x0.5 */ 252 + { 0, 63637 }, /* gain: x0.66 */ 253 + { 0, 42000 }, /* gain: x1 */ 254 + { 0, 21000 }, /* gain: x2 */ 255 + }, 256 + /* integration time: 200 ms */ 257 + { 258 + { 0, 84000 }, /* gain: x0.25 */ 259 + { 0, 63635 }, /* gain: x0.33 */ 260 + { 0, 42000 }, /* gain: x0.5 */ 261 + { 0, 31818 }, /* gain: x0.66 */ 262 + { 0, 21000 }, /* gain: x1 */ 263 + { 0, 10500 }, /* gain: x2 */ 264 + }, 265 + /* integration time: 400 ms */ 266 + { 267 + { 0, 42000 }, /* gain: x0.25 */ 268 + { 0, 31817 }, /* gain: x0.33 */ 269 + { 0, 21000 }, /* gain: x0.5 */ 270 + { 0, 15909 }, /* gain: x0.66 */ 271 + { 0, 10500 }, /* gain: x1 */ 272 + { 0, 5250 }, /* gain: x2 */ 273 + }, 274 + }; 275 + 276 + /* 277 + * Two bits (RGB_ON_0 and RGB_ON_1) must be cleared to power on the device. 278 + */ 279 + static int veml6046x00_power_on(struct veml6046x00_data *data) 280 + { 281 + int ret; 282 + struct device *dev = regmap_get_device(data->regmap); 283 + 284 + ret = regmap_clear_bits(data->regmap, VEML6046X00_REG_CONF0, 285 + VEML6046X00_CONF0_ON_0); 286 + if (ret) { 287 + dev_err(dev, "Failed to set bit for power on %d\n", ret); 288 + return ret; 289 + } 290 + 291 + return regmap_clear_bits(data->regmap, VEML6046X00_REG_CONF1, 292 + VEML6046X00_CONF1_ON_1); 293 + } 294 + 295 + /* 296 + * Two bits (RGB_ON_0 and RGB_ON_1) must be set to power off the device. 297 + */ 298 + static int veml6046x00_shutdown(struct veml6046x00_data *data) 299 + { 300 + int ret; 301 + struct device *dev = regmap_get_device(data->regmap); 302 + 303 + ret = regmap_set_bits(data->regmap, VEML6046X00_REG_CONF0, 304 + VEML6046X00_CONF0_ON_0); 305 + if (ret) { 306 + dev_err(dev, "Failed to set bit for shutdown %d\n", ret); 307 + return ret; 308 + } 309 + 310 + return regmap_set_bits(data->regmap, VEML6046X00_REG_CONF1, 311 + VEML6046X00_CONF1_ON_1); 312 + } 313 + 314 + static void veml6046x00_shutdown_action(void *data) 315 + { 316 + veml6046x00_shutdown(data); 317 + } 318 + 319 + static const struct iio_chan_spec veml6046x00_channels[] = { 320 + { 321 + .type = IIO_INTENSITY, 322 + .address = VEML6046X00_REG_R, 323 + .modified = 1, 324 + .channel2 = IIO_MOD_LIGHT_RED, 325 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 326 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME) | 327 + BIT(IIO_CHAN_INFO_SCALE), 328 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 329 + BIT(IIO_CHAN_INFO_SCALE), 330 + .scan_index = VEML6046X00_SCAN_R, 331 + .scan_type = { 332 + .sign = 'u', 333 + .realbits = 16, 334 + .storagebits = 16, 335 + .endianness = IIO_LE, 336 + }, 337 + }, 338 + { 339 + .type = IIO_INTENSITY, 340 + .address = VEML6046X00_REG_G, 341 + .modified = 1, 342 + .channel2 = IIO_MOD_LIGHT_GREEN, 343 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 344 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME) | 345 + BIT(IIO_CHAN_INFO_SCALE), 346 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 347 + BIT(IIO_CHAN_INFO_SCALE), 348 + .scan_index = VEML6046X00_SCAN_G, 349 + .scan_type = { 350 + .sign = 'u', 351 + .realbits = 16, 352 + .storagebits = 16, 353 + .endianness = IIO_LE, 354 + }, 355 + }, 356 + { 357 + .type = IIO_INTENSITY, 358 + .address = VEML6046X00_REG_B, 359 + .modified = 1, 360 + .channel2 = IIO_MOD_LIGHT_BLUE, 361 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 362 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME) | 363 + BIT(IIO_CHAN_INFO_SCALE), 364 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 365 + BIT(IIO_CHAN_INFO_SCALE), 366 + .scan_index = VEML6046X00_SCAN_B, 367 + .scan_type = { 368 + .sign = 'u', 369 + .realbits = 16, 370 + .storagebits = 16, 371 + .endianness = IIO_LE, 372 + }, 373 + }, 374 + { 375 + .type = IIO_INTENSITY, 376 + .address = VEML6046X00_REG_IR, 377 + .modified = 1, 378 + .channel2 = IIO_MOD_LIGHT_IR, 379 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 380 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME) | 381 + BIT(IIO_CHAN_INFO_SCALE), 382 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 383 + BIT(IIO_CHAN_INFO_SCALE), 384 + .scan_index = VEML6046X00_SCAN_IR, 385 + .scan_type = { 386 + .sign = 'u', 387 + .realbits = 16, 388 + .storagebits = 16, 389 + .endianness = IIO_LE, 390 + }, 391 + }, 392 + IIO_CHAN_SOFT_TIMESTAMP(VEML6046X00_SCAN_TIMESTAMP), 393 + }; 394 + 395 + static const struct regmap_config veml6046x00_regmap_config = { 396 + .name = "veml6046x00_regm", 397 + .reg_bits = 8, 398 + .val_bits = 8, 399 + .max_register = VEML6046X00_REG_INT_H, 400 + }; 401 + 402 + static const struct reg_field veml6046x00_rf_int_en = 403 + REG_FIELD(VEML6046X00_REG_CONF0, 1, 1); 404 + 405 + static const struct reg_field veml6046x00_rf_trig = 406 + REG_FIELD(VEML6046X00_REG_CONF0, 2, 2); 407 + 408 + static const struct reg_field veml6046x00_rf_mode = 409 + REG_FIELD(VEML6046X00_REG_CONF0, 3, 3); 410 + 411 + static const struct reg_field veml6046x00_rf_it = 412 + REG_FIELD(VEML6046X00_REG_CONF0, 4, 6); 413 + 414 + static const struct reg_field veml6046x00_rf_pers = 415 + REG_FIELD(VEML6046X00_REG_CONF1, 1, 2); 416 + 417 + static int veml6046x00_regfield_init(struct veml6046x00_data *data) 418 + { 419 + struct regmap *regmap = data->regmap; 420 + struct device *dev = regmap_get_device(data->regmap); 421 + struct regmap_field *rm_field; 422 + struct veml6046x00_rf *rf = &data->rf; 423 + 424 + rm_field = devm_regmap_field_alloc(dev, regmap, veml6046x00_rf_int_en); 425 + if (IS_ERR(rm_field)) 426 + return PTR_ERR(rm_field); 427 + rf->int_en = rm_field; 428 + 429 + rm_field = devm_regmap_field_alloc(dev, regmap, veml6046x00_rf_mode); 430 + if (IS_ERR(rm_field)) 431 + return PTR_ERR(rm_field); 432 + rf->mode = rm_field; 433 + 434 + rm_field = devm_regmap_field_alloc(dev, regmap, veml6046x00_rf_trig); 435 + if (IS_ERR(rm_field)) 436 + return PTR_ERR(rm_field); 437 + rf->trig = rm_field; 438 + 439 + rm_field = devm_regmap_field_alloc(dev, regmap, veml6046x00_rf_it); 440 + if (IS_ERR(rm_field)) 441 + return PTR_ERR(rm_field); 442 + rf->it = rm_field; 443 + 444 + rm_field = devm_regmap_field_alloc(dev, regmap, veml6046x00_rf_pers); 445 + if (IS_ERR(rm_field)) 446 + return PTR_ERR(rm_field); 447 + rf->pers = rm_field; 448 + 449 + return 0; 450 + } 451 + 452 + static int veml6046x00_get_it_index(struct veml6046x00_data *data) 453 + { 454 + int ret; 455 + unsigned int reg; 456 + 457 + ret = regmap_field_read(data->rf.it, &reg); 458 + if (ret) 459 + return ret; 460 + 461 + /* register value is identical with index of array */ 462 + if (reg >= ARRAY_SIZE(veml6046x00_it)) 463 + return -EINVAL; 464 + 465 + return reg; 466 + } 467 + 468 + static int veml6046x00_get_it_usec(struct veml6046x00_data *data, unsigned int *it_usec) 469 + { 470 + int ret; 471 + unsigned int reg; 472 + 473 + ret = regmap_field_read(data->rf.it, &reg); 474 + if (ret) 475 + return ret; 476 + 477 + if (reg >= ARRAY_SIZE(veml6046x00_it)) 478 + return -EINVAL; 479 + 480 + *it_usec = veml6046x00_it[reg][1]; 481 + 482 + return IIO_VAL_INT_PLUS_MICRO; 483 + } 484 + 485 + static int veml6046x00_set_it(struct iio_dev *iio, int val, int val2) 486 + { 487 + struct veml6046x00_data *data = iio_priv(iio); 488 + unsigned int i; 489 + 490 + for (i = 0; i < ARRAY_SIZE(veml6046x00_it); i++) { 491 + if ((veml6046x00_it[i][0] == val) && 492 + (veml6046x00_it[i][1] == val2)) 493 + return regmap_field_write(data->rf.it, i); 494 + } 495 + 496 + return -EINVAL; 497 + } 498 + 499 + static int veml6046x00_get_val_gain_idx(struct veml6046x00_data *data, int val, 500 + int val2) 501 + { 502 + unsigned int i; 503 + int it_idx; 504 + 505 + it_idx = veml6046x00_get_it_index(data); 506 + if (it_idx < 0) 507 + return it_idx; 508 + 509 + for (i = 0; i < ARRAY_SIZE(veml6046x00_it_gains[it_idx]); i++) { 510 + if ((veml6046x00_it_gains[it_idx][i][0] == val) && 511 + (veml6046x00_it_gains[it_idx][i][1] == val2)) 512 + return i; 513 + } 514 + 515 + return -EINVAL; 516 + } 517 + 518 + static int veml6046x00_get_gain_idx(struct veml6046x00_data *data) 519 + { 520 + int ret; 521 + unsigned int i, reg, reg_gain, reg_pd; 522 + 523 + ret = regmap_read(data->regmap, VEML6046X00_REG_CONF1, &reg); 524 + if (ret) 525 + return ret; 526 + 527 + reg_gain = FIELD_GET(VEML6046X00_CONF1_GAIN, reg); 528 + reg_pd = reg & VEML6046X00_CONF1_PD_D2; 529 + 530 + for (i = 0; i < ARRAY_SIZE(veml6046x00_gain_pd); i++) { 531 + if ((veml6046x00_gain_pd[i].gain_sen == reg_gain) && 532 + (veml6046x00_gain_pd[i].pd == reg_pd)) 533 + return i; 534 + } 535 + 536 + return -EINVAL; 537 + } 538 + 539 + static int veml6046x00_set_scale(struct iio_dev *iio, int val, int val2) 540 + { 541 + struct veml6046x00_data *data = iio_priv(iio); 542 + unsigned int new_scale; 543 + int gain_idx; 544 + 545 + gain_idx = veml6046x00_get_val_gain_idx(data, val, val2); 546 + if (gain_idx < 0) 547 + return gain_idx; 548 + 549 + new_scale = FIELD_PREP(VEML6046X00_CONF1_GAIN, 550 + veml6046x00_gain_pd[gain_idx].gain_sen) | 551 + veml6046x00_gain_pd[gain_idx].pd; 552 + 553 + return regmap_update_bits(data->regmap, VEML6046X00_REG_CONF1, 554 + VEML6046X00_CONF1_GAIN | 555 + VEML6046X00_CONF1_PD_D2, 556 + new_scale); 557 + } 558 + 559 + static int veml6046x00_get_scale(struct veml6046x00_data *data, 560 + int *val, int *val2) 561 + { 562 + int gain_idx, it_idx; 563 + 564 + gain_idx = veml6046x00_get_gain_idx(data); 565 + if (gain_idx < 0) 566 + return gain_idx; 567 + 568 + it_idx = veml6046x00_get_it_index(data); 569 + if (it_idx < 0) 570 + return it_idx; 571 + 572 + *val = veml6046x00_it_gains[it_idx][gain_idx][0]; 573 + *val2 = veml6046x00_it_gains[it_idx][gain_idx][1]; 574 + 575 + return IIO_VAL_INT_PLUS_MICRO; 576 + } 577 + 578 + /** 579 + * veml6046x00_read_data_ready() - Read data ready bit 580 + * @data: Private data. 581 + * 582 + * Helper function for reading data ready bit from interrupt register. 583 + * 584 + * Return: 585 + * * %1 - Data is available (AF_DATA_READY is set) 586 + * * %0 - No data available 587 + * * %-EIO - Error during bulk read 588 + */ 589 + static int veml6046x00_read_data_ready(struct veml6046x00_data *data) 590 + { 591 + struct device *dev = regmap_get_device(data->regmap); 592 + int ret; 593 + u8 reg[2]; 594 + 595 + /* 596 + * Note from the vendor, but not explicitly in the datasheet: we 597 + * should always read both registers together. 598 + */ 599 + ret = regmap_bulk_read(data->regmap, VEML6046X00_REG_INT, 600 + &reg, sizeof(reg)); 601 + if (ret) { 602 + dev_err(dev, "Failed to read interrupt register %d\n", ret); 603 + return -EIO; 604 + } 605 + 606 + if (reg[1] & VEML6046X00_INT_DRDY) 607 + return 1; 608 + 609 + return 0; 610 + } 611 + 612 + /** 613 + * veml6046x00_wait_data_available() - Wait until data is available 614 + * @iio: Industrial IO. 615 + * @usecs: Microseconds to wait for data. 616 + * 617 + * This function waits for a certain bit in the interrupt register which signals 618 + * that there is data to be read available. 619 + * 620 + * It tries it two times with a waiting time of usecs in between. 621 + * 622 + * Return: 623 + * * %1 - Data is available (AF_DATA_READY is set) 624 + * * %0 - Timeout, no data available after usecs timeout 625 + * * %-EIO - Error during bulk read 626 + */ 627 + static int veml6046x00_wait_data_available(struct iio_dev *iio, unsigned int usecs) 628 + { 629 + struct veml6046x00_data *data = iio_priv(iio); 630 + int ret; 631 + 632 + ret = veml6046x00_read_data_ready(data); 633 + if (ret) 634 + return ret; 635 + 636 + fsleep(usecs); 637 + return veml6046x00_read_data_ready(data); 638 + } 639 + 640 + static int veml6046x00_single_read(struct iio_dev *iio, 641 + enum iio_modifier modifier, int *val) 642 + { 643 + struct veml6046x00_data *data = iio_priv(iio); 644 + struct device *dev = regmap_get_device(data->regmap); 645 + unsigned int addr, it_usec; 646 + int ret; 647 + __le16 reg; 648 + 649 + switch (modifier) { 650 + case IIO_MOD_LIGHT_RED: 651 + addr = VEML6046X00_REG_R; 652 + break; 653 + case IIO_MOD_LIGHT_GREEN: 654 + addr = VEML6046X00_REG_G; 655 + break; 656 + case IIO_MOD_LIGHT_BLUE: 657 + addr = VEML6046X00_REG_B; 658 + break; 659 + case IIO_MOD_LIGHT_IR: 660 + addr = VEML6046X00_REG_IR; 661 + break; 662 + default: 663 + return -EINVAL; 664 + } 665 + ret = pm_runtime_resume_and_get(dev); 666 + if (ret) 667 + return ret; 668 + 669 + ret = veml6046x00_get_it_usec(data, &it_usec); 670 + if (ret < 0) { 671 + dev_err(dev, "Failed to get integration time ret: %d", ret); 672 + goto out; 673 + } 674 + 675 + ret = regmap_field_write(data->rf.mode, 1); 676 + if (ret) { 677 + dev_err(dev, "Failed to write mode ret: %d", ret); 678 + goto out; 679 + } 680 + 681 + ret = regmap_field_write(data->rf.trig, 1); 682 + if (ret) { 683 + dev_err(dev, "Failed to write trigger ret: %d", ret); 684 + goto out; 685 + } 686 + 687 + /* integration time + 12.5 % to ensure completion */ 688 + fsleep(it_usec + it_usec / 8); 689 + 690 + ret = veml6046x00_wait_data_available(iio, it_usec * 4); 691 + if (ret < 0) 692 + goto out; 693 + if (ret == 0) { 694 + ret = -EAGAIN; 695 + goto out; 696 + } 697 + 698 + if (!iio_device_claim_direct(iio)) { 699 + ret = -EBUSY; 700 + goto out; 701 + } 702 + 703 + ret = regmap_bulk_read(data->regmap, addr, &reg, sizeof(reg)); 704 + iio_device_release_direct(iio); 705 + if (ret) 706 + goto out; 707 + 708 + *val = le16_to_cpu(reg); 709 + 710 + ret = IIO_VAL_INT; 711 + 712 + out: 713 + pm_runtime_put_autosuspend(dev); 714 + 715 + return ret; 716 + } 717 + 718 + static int veml6046x00_read_raw(struct iio_dev *iio, 719 + struct iio_chan_spec const *chan, int *val, 720 + int *val2, long mask) 721 + { 722 + struct veml6046x00_data *data = iio_priv(iio); 723 + 724 + switch (mask) { 725 + case IIO_CHAN_INFO_RAW: 726 + if (chan->type != IIO_INTENSITY) 727 + return -EINVAL; 728 + return veml6046x00_single_read(iio, chan->channel2, val); 729 + case IIO_CHAN_INFO_INT_TIME: 730 + *val = 0; 731 + return veml6046x00_get_it_usec(data, val2); 732 + case IIO_CHAN_INFO_SCALE: 733 + return veml6046x00_get_scale(data, val, val2); 734 + default: 735 + return -EINVAL; 736 + } 737 + } 738 + 739 + static int veml6046x00_read_avail(struct iio_dev *iio, 740 + struct iio_chan_spec const *chan, 741 + const int **vals, int *type, int *length, 742 + long mask) 743 + { 744 + struct veml6046x00_data *data = iio_priv(iio); 745 + int it_idx; 746 + 747 + switch (mask) { 748 + case IIO_CHAN_INFO_INT_TIME: 749 + *vals = (int *)&veml6046x00_it; 750 + *length = 2 * ARRAY_SIZE(veml6046x00_it); 751 + *type = IIO_VAL_INT_PLUS_MICRO; 752 + return IIO_AVAIL_LIST; 753 + case IIO_CHAN_INFO_SCALE: 754 + it_idx = veml6046x00_get_it_index(data); 755 + if (it_idx < 0) 756 + return it_idx; 757 + *vals = (int *)&veml6046x00_it_gains[it_idx]; 758 + *length = 2 * ARRAY_SIZE(veml6046x00_it_gains[it_idx]); 759 + *type = IIO_VAL_INT_PLUS_MICRO; 760 + return IIO_AVAIL_LIST; 761 + default: 762 + return -EINVAL; 763 + } 764 + } 765 + 766 + static int veml6046x00_write_raw(struct iio_dev *iio, 767 + struct iio_chan_spec const *chan, 768 + int val, int val2, long mask) 769 + { 770 + switch (mask) { 771 + case IIO_CHAN_INFO_INT_TIME: 772 + return veml6046x00_set_it(iio, val, val2); 773 + case IIO_CHAN_INFO_SCALE: 774 + return veml6046x00_set_scale(iio, val, val2); 775 + default: 776 + return -EINVAL; 777 + } 778 + } 779 + 780 + static const struct iio_info veml6046x00_info_no_irq = { 781 + .read_raw = veml6046x00_read_raw, 782 + .read_avail = veml6046x00_read_avail, 783 + .write_raw = veml6046x00_write_raw, 784 + }; 785 + 786 + static int veml6046x00_buffer_preenable(struct iio_dev *iio) 787 + { 788 + struct veml6046x00_data *data = iio_priv(iio); 789 + struct device *dev = regmap_get_device(data->regmap); 790 + int ret; 791 + 792 + ret = regmap_field_write(data->rf.mode, 0); 793 + if (ret) { 794 + dev_err(dev, "Failed to set mode %d\n", ret); 795 + return ret; 796 + } 797 + 798 + ret = regmap_field_write(data->rf.trig, 0); 799 + if (ret) { 800 + /* 801 + * no unrolling of mode as it is set appropriately with next 802 + * single read. 803 + */ 804 + dev_err(dev, "Failed to set trigger %d\n", ret); 805 + return ret; 806 + } 807 + 808 + return pm_runtime_resume_and_get(dev); 809 + } 810 + 811 + static int veml6046x00_buffer_postdisable(struct iio_dev *iio) 812 + { 813 + struct veml6046x00_data *data = iio_priv(iio); 814 + struct device *dev = regmap_get_device(data->regmap); 815 + int ret; 816 + 817 + ret = regmap_field_write(data->rf.mode, 1); 818 + if (ret) { 819 + dev_err(dev, "Failed to set mode %d\n", ret); 820 + return ret; 821 + } 822 + 823 + pm_runtime_put_autosuspend(dev); 824 + 825 + return 0; 826 + } 827 + 828 + static const struct iio_buffer_setup_ops veml6046x00_buffer_setup_ops = { 829 + .preenable = veml6046x00_buffer_preenable, 830 + .postdisable = veml6046x00_buffer_postdisable, 831 + }; 832 + 833 + static irqreturn_t veml6046x00_trig_handler(int irq, void *p) 834 + { 835 + struct iio_poll_func *pf = p; 836 + struct iio_dev *iio = pf->indio_dev; 837 + struct veml6046x00_data *data = iio_priv(iio); 838 + int ret; 839 + struct { 840 + __le16 chans[4]; 841 + aligned_s64 timestamp; 842 + } scan; 843 + 844 + ret = regmap_bulk_read(data->regmap, VEML6046X00_REG_R, 845 + &scan.chans, sizeof(scan.chans)); 846 + if (ret) 847 + goto done; 848 + 849 + iio_push_to_buffers_with_ts(iio, &scan, sizeof(scan), 850 + iio_get_time_ns(iio)); 851 + 852 + done: 853 + iio_trigger_notify_done(iio->trig); 854 + 855 + return IRQ_HANDLED; 856 + } 857 + 858 + static int veml6046x00_validate_part_id(struct veml6046x00_data *data) 859 + { 860 + struct device *dev = regmap_get_device(data->regmap); 861 + unsigned int part_id; 862 + int ret; 863 + __le16 reg; 864 + 865 + ret = regmap_bulk_read(data->regmap, VEML6046X00_REG_ID, 866 + &reg, sizeof(reg)); 867 + if (ret) 868 + return dev_err_probe(dev, ret, "Failed to read ID\n"); 869 + 870 + part_id = le16_to_cpu(reg); 871 + if (part_id != 0x01) 872 + dev_info(dev, "Unknown ID %#04x\n", part_id); 873 + 874 + return 0; 875 + } 876 + 877 + static int veml6046x00_setup_device(struct iio_dev *iio) 878 + { 879 + struct veml6046x00_data *data = iio_priv(iio); 880 + struct device *dev = regmap_get_device(data->regmap); 881 + int ret; 882 + __le16 reg16; 883 + 884 + reg16 = cpu_to_le16(VEML6046X00_CONF0_AF); 885 + ret = regmap_bulk_write(data->regmap, VEML6046X00_REG_CONF0, 886 + &reg16, sizeof(reg16)); 887 + if (ret) 888 + return dev_err_probe(dev, ret, "Failed to set configuration\n"); 889 + 890 + reg16 = cpu_to_le16(0); 891 + ret = regmap_bulk_write(data->regmap, VEML6046X00_REG_THDL, 892 + &reg16, sizeof(reg16)); 893 + if (ret) 894 + return dev_err_probe(dev, ret, "Failed to set low threshold\n"); 895 + 896 + reg16 = cpu_to_le16(U16_MAX); 897 + ret = regmap_bulk_write(data->regmap, VEML6046X00_REG_THDH, 898 + &reg16, sizeof(reg16)); 899 + if (ret) 900 + return dev_err_probe(dev, ret, "Failed to set high threshold\n"); 901 + 902 + ret = regmap_bulk_read(data->regmap, VEML6046X00_REG_INT, 903 + &reg16, sizeof(reg16)); 904 + if (ret) 905 + return dev_err_probe(dev, ret, "Failed to clear interrupts\n"); 906 + 907 + return 0; 908 + } 909 + 910 + static int veml6046x00_probe(struct i2c_client *i2c) 911 + { 912 + struct device *dev = &i2c->dev; 913 + struct veml6046x00_data *data; 914 + struct iio_dev *iio; 915 + struct regmap *regmap; 916 + int ret; 917 + 918 + regmap = devm_regmap_init_i2c(i2c, &veml6046x00_regmap_config); 919 + if (IS_ERR(regmap)) 920 + return dev_err_probe(dev, PTR_ERR(regmap), "Failed to set regmap\n"); 921 + 922 + iio = devm_iio_device_alloc(dev, sizeof(*data)); 923 + if (!iio) 924 + return -ENOMEM; 925 + 926 + data = iio_priv(iio); 927 + /* struct iio_dev is retrieved via dev_get_drvdata(). */ 928 + i2c_set_clientdata(i2c, iio); 929 + data->regmap = regmap; 930 + 931 + ret = veml6046x00_regfield_init(data); 932 + if (ret) 933 + return dev_err_probe(dev, ret, "Failed to init regfield\n"); 934 + 935 + ret = devm_regulator_get_enable(dev, "vdd"); 936 + if (ret) 937 + return dev_err_probe(dev, ret, "Failed to enable regulator\n"); 938 + 939 + /* bring device in a known state and switch device on */ 940 + ret = veml6046x00_setup_device(iio); 941 + if (ret < 0) 942 + return ret; 943 + 944 + ret = devm_add_action_or_reset(dev, veml6046x00_shutdown_action, data); 945 + if (ret < 0) 946 + return dev_err_probe(dev, ret, "Failed to add shut down action\n"); 947 + 948 + ret = pm_runtime_set_active(dev); 949 + if (ret < 0) 950 + return dev_err_probe(dev, ret, "Failed to activate PM runtime\n"); 951 + 952 + ret = devm_pm_runtime_enable(dev); 953 + if (ret) 954 + return dev_err_probe(dev, ret, "Failed to enable PM runtime\n"); 955 + 956 + pm_runtime_get_noresume(dev); 957 + pm_runtime_set_autosuspend_delay(dev, VEML6046X00_AUTOSUSPEND_MS); 958 + pm_runtime_use_autosuspend(dev); 959 + 960 + ret = veml6046x00_validate_part_id(data); 961 + if (ret) 962 + return dev_err_probe(dev, ret, "Failed to validate device ID\n"); 963 + 964 + iio->name = "veml6046x00"; 965 + iio->channels = veml6046x00_channels; 966 + iio->num_channels = ARRAY_SIZE(veml6046x00_channels); 967 + iio->modes = INDIO_DIRECT_MODE; 968 + 969 + iio->info = &veml6046x00_info_no_irq; 970 + 971 + ret = devm_iio_triggered_buffer_setup(dev, iio, NULL, 972 + veml6046x00_trig_handler, 973 + &veml6046x00_buffer_setup_ops); 974 + if (ret) 975 + return dev_err_probe(dev, ret, 976 + "Failed to register triggered buffer"); 977 + 978 + pm_runtime_put_autosuspend(dev); 979 + 980 + ret = devm_iio_device_register(dev, iio); 981 + if (ret) 982 + return dev_err_probe(dev, ret, "Failed to register iio device"); 983 + 984 + return 0; 985 + } 986 + 987 + static int veml6046x00_runtime_suspend(struct device *dev) 988 + { 989 + struct veml6046x00_data *data = iio_priv(dev_get_drvdata(dev)); 990 + 991 + return veml6046x00_shutdown(data); 992 + } 993 + 994 + static int veml6046x00_runtime_resume(struct device *dev) 995 + { 996 + struct veml6046x00_data *data = iio_priv(dev_get_drvdata(dev)); 997 + 998 + return veml6046x00_power_on(data); 999 + } 1000 + 1001 + static DEFINE_RUNTIME_DEV_PM_OPS(veml6046x00_pm_ops, 1002 + veml6046x00_runtime_suspend, 1003 + veml6046x00_runtime_resume, NULL); 1004 + 1005 + static const struct of_device_id veml6046x00_of_match[] = { 1006 + { .compatible = "vishay,veml6046x00" }, 1007 + { } 1008 + }; 1009 + MODULE_DEVICE_TABLE(of, veml6046x00_of_match); 1010 + 1011 + static const struct i2c_device_id veml6046x00_id[] = { 1012 + { "veml6046x00" }, 1013 + { } 1014 + }; 1015 + MODULE_DEVICE_TABLE(i2c, veml6046x00_id); 1016 + 1017 + static struct i2c_driver veml6046x00_driver = { 1018 + .driver = { 1019 + .name = "veml6046x00", 1020 + .of_match_table = veml6046x00_of_match, 1021 + .pm = pm_ptr(&veml6046x00_pm_ops), 1022 + }, 1023 + .probe = veml6046x00_probe, 1024 + .id_table = veml6046x00_id, 1025 + }; 1026 + module_i2c_driver(veml6046x00_driver); 1027 + 1028 + MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>"); 1029 + MODULE_DESCRIPTION("VEML6046X00 RGBIR Color Sensor"); 1030 + MODULE_LICENSE("GPL");
+8 -8
drivers/iio/light/vl6180.c
··· 96 96 unsigned int als_it_ms; 97 97 unsigned int als_meas_rate; 98 98 unsigned int range_meas_rate; 99 - 100 - struct { 101 - u16 chan[2]; 102 - aligned_s64 timestamp; 103 - } scan; 104 99 }; 105 100 106 101 enum { VL6180_ALS, VL6180_RANGE, VL6180_PROX }; ··· 540 545 struct vl6180_data *data = iio_priv(indio_dev); 541 546 s64 time_ns = iio_get_time_ns(indio_dev); 542 547 int ret, bit, i = 0; 548 + struct { 549 + u16 chan[2]; 550 + aligned_s64 timestamp; 551 + } scan = { }; 552 + 543 553 544 554 iio_for_each_active_channel(indio_dev, bit) { 545 555 if (vl6180_chan_regs_table[bit].word) ··· 560 560 return IRQ_HANDLED; 561 561 } 562 562 563 - data->scan.chan[i++] = ret; 563 + scan.chan[i++] = ret; 564 564 } 565 565 566 - iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, time_ns); 566 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), time_ns); 567 567 iio_trigger_notify_done(indio_dev->trig); 568 568 569 569 /* Clear the interrupt flag after data read */ ··· 722 722 IRQF_ONESHOT, 723 723 indio_dev->name, indio_dev); 724 724 if (ret) 725 - return dev_err_probe(&client->dev, ret, "devm_request_irq error \n"); 725 + return dev_err_probe(&client->dev, ret, "devm_request_irq error\n"); 726 726 727 727 init_completion(&data->completion); 728 728
+14 -1
drivers/iio/magnetometer/Kconfig
··· 123 123 select IIO_BUFFER 124 124 select HID_SENSOR_IIO_COMMON 125 125 select HID_SENSOR_IIO_TRIGGER 126 - tristate "HID Magenetometer 3D" 126 + tristate "HID Magnetometer 3D" 127 127 help 128 128 Say yes here to build support for the HID SENSOR 129 129 Magnetometer 3D. ··· 172 172 173 173 To compile this driver as a module, choose M here. The module 174 174 will be called st_magn_spi. 175 + 176 + config INFINEON_TLV493D 177 + tristate "Infineon TLV493D Low-Power 3D Magnetic Sensor" 178 + depends on I2C 179 + select IIO_BUFFER 180 + select IIO_TRIGGERED_BUFFER 181 + help 182 + Say Y here to add support for the Infineon TLV493D-A1B6 Low- 183 + Power 3D Magnetic Sensor. 184 + 185 + This driver can also be compiled as a module. 186 + To compile this driver as a module, choose M here: the module 187 + will be called tlv493d. 175 188 176 189 config SENSORS_HMC5843 177 190 tristate
+2
drivers/iio/magnetometer/Makefile
··· 23 23 obj-$(CONFIG_IIO_ST_MAGN_I2C_3AXIS) += st_magn_i2c.o 24 24 obj-$(CONFIG_IIO_ST_MAGN_SPI_3AXIS) += st_magn_spi.o 25 25 26 + obj-$(CONFIG_INFINEON_TLV493D) += tlv493d.o 27 + 26 28 obj-$(CONFIG_SENSORS_HMC5843) += hmc5843_core.o 27 29 obj-$(CONFIG_SENSORS_HMC5843_I2C) += hmc5843_i2c.o 28 30 obj-$(CONFIG_SENSORS_HMC5843_SPI) += hmc5843_spi.o
-2
drivers/iio/magnetometer/ak8974.c
··· 583 583 *val = (s16)le16_to_cpu(hw_values[address]); 584 584 out_unlock: 585 585 mutex_unlock(&ak8974->lock); 586 - pm_runtime_mark_last_busy(&ak8974->i2c->dev); 587 586 pm_runtime_put_autosuspend(&ak8974->i2c->dev); 588 587 589 588 return ret; ··· 677 678 678 679 out_unlock: 679 680 mutex_unlock(&ak8974->lock); 680 - pm_runtime_mark_last_busy(&ak8974->i2c->dev); 681 681 pm_runtime_put_autosuspend(&ak8974->i2c->dev); 682 682 } 683 683
-1
drivers/iio/magnetometer/ak8975.c
··· 775 775 776 776 mutex_unlock(&data->lock); 777 777 778 - pm_runtime_mark_last_busy(&data->client->dev); 779 778 pm_runtime_put_autosuspend(&data->client->dev); 780 779 781 780 /* Swap bytes and convert to valid range. */
+1 -4
drivers/iio/magnetometer/als31300.c
··· 140 140 *z = ALS31300_DATA_Z_GET(buf); 141 141 142 142 out: 143 - pm_runtime_mark_last_busy(data->dev); 144 143 pm_runtime_put_autosuspend(data->dev); 145 144 146 145 return ret; ··· 155 156 int ret; 156 157 157 158 switch (mask) { 158 - case IIO_CHAN_INFO_PROCESSED: 159 159 case IIO_CHAN_INFO_RAW: 160 160 ret = als31300_get_measure(data, &t, &x, &y, &z); 161 161 if (ret) ··· 371 373 372 374 ret = devm_add_action_or_reset(dev, als31300_power_down, data); 373 375 if (ret) 374 - return dev_err_probe(dev, ret, "failed to add powerdown action\n"); 376 + return ret; 375 377 376 378 indio_dev->info = &als31300_info; 377 379 indio_dev->modes = INDIO_DIRECT_MODE; ··· 399 401 pm_runtime_set_autosuspend_delay(dev, 200); 400 402 pm_runtime_use_autosuspend(dev); 401 403 402 - pm_runtime_mark_last_busy(dev); 403 404 pm_runtime_put_autosuspend(dev); 404 405 405 406 ret = devm_iio_device_register(dev, indio_dev);
+4 -9
drivers/iio/magnetometer/bmc150_magn.c
··· 257 257 258 258 static int bmc150_magn_set_power_state(struct bmc150_magn_data *data, bool on) 259 259 { 260 - #ifdef CONFIG_PM 261 - int ret; 260 + int ret = 0; 262 261 263 - if (on) { 262 + if (on) 264 263 ret = pm_runtime_resume_and_get(data->dev); 265 - } else { 266 - pm_runtime_mark_last_busy(data->dev); 267 - ret = pm_runtime_put_autosuspend(data->dev); 268 - } 269 - 264 + else 265 + pm_runtime_put_autosuspend(data->dev); 270 266 if (ret < 0) { 271 267 dev_err(data->dev, 272 268 "failed to change power state to %d\n", on); 273 269 return ret; 274 270 } 275 - #endif 276 271 277 272 return 0; 278 273 }
+526
drivers/iio/magnetometer/tlv493d.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Driver for the Infineon TLV493D Low-Power 3D Magnetic Sensor 4 + * 5 + * Copyright (C) 2025 Dixit Parmar <dixitparmar19@gmail.com> 6 + */ 7 + 8 + #include <linux/array_size.h> 9 + #include <linux/bits.h> 10 + #include <linux/bitfield.h> 11 + #include <linux/cleanup.h> 12 + #include <linux/delay.h> 13 + #include <linux/dev_printk.h> 14 + #include <linux/i2c.h> 15 + #include <linux/iopoll.h> 16 + #include <linux/module.h> 17 + #include <linux/mod_devicetable.h> 18 + #include <linux/pm.h> 19 + #include <linux/pm_runtime.h> 20 + #include <linux/regulator/consumer.h> 21 + #include <linux/types.h> 22 + #include <linux/units.h> 23 + 24 + #include <linux/iio/buffer.h> 25 + #include <linux/iio/iio.h> 26 + #include <linux/iio/trigger_consumer.h> 27 + #include <linux/iio/triggered_buffer.h> 28 + 29 + /* 30 + * TLV493D sensor I2C communication note: 31 + * 32 + * The sensor supports only direct byte-stream write starting from the 33 + * register address 0x0. So for any modification to be made to any write 34 + * registers, it must be written starting from the register address 0x0. 35 + * I2C write operation should not contain the register address in the I2C 36 + * frame, it should contain only raw byte stream for the write registers. 37 + * I2C Frame: |S|SlaveAddr Wr|Ack|Byte[0]|Ack|Byte[1]|Ack|.....|Sp| 38 + * 39 + * Same as the write operation, reading from the sensor registers is also 40 + * performed starting from the register address 0x0 for as many bytes as 41 + * need to be read. 42 + * I2C read operation should not contain the register address in the I2C frame. 43 + * I2C Frame: |S|SlaveAddr Rd|Ack|Byte[0]|Ack|Byte[1]|Ack|.....|Sp| 44 + */ 45 + 46 + #define TLV493D_RD_REG_BX 0x00 47 + #define TLV493D_RD_REG_BY 0x01 48 + #define TLV493D_RD_REG_BZ 0x02 49 + #define TLV493D_RD_REG_TEMP 0x03 50 + #define TLV493D_RD_REG_BX2 0x04 51 + #define TLV493D_RD_REG_BZ2 0x05 52 + #define TLV493D_RD_REG_TEMP2 0x06 53 + #define TLV493D_RD_REG_RES1 0x07 54 + #define TLV493D_RD_REG_RES2 0x08 55 + #define TLV493D_RD_REG_RES3 0x09 56 + #define TLV493D_RD_REG_MAX 0x0a 57 + 58 + #define TLV493D_WR_REG_MODE1 0x01 59 + #define TLV493D_WR_REG_MODE2 0x03 60 + #define TLV493D_WR_REG_MAX 0x04 61 + 62 + #define TLV493D_BX_MAG_X_AXIS_MSB GENMASK(7, 0) 63 + #define TLV493D_BX2_MAG_X_AXIS_LSB GENMASK(7, 4) 64 + #define TLV493D_BY_MAG_Y_AXIS_MSB GENMASK(7, 0) 65 + #define TLV493D_BX2_MAG_Y_AXIS_LSB GENMASK(3, 0) 66 + #define TLV493D_BZ_MAG_Z_AXIS_MSB GENMASK(7, 0) 67 + #define TLV493D_BZ2_MAG_Z_AXIS_LSB GENMASK(3, 0) 68 + #define TLV493D_TEMP_TEMP_MSB GENMASK(7, 4) 69 + #define TLV493D_TEMP2_TEMP_LSB GENMASK(7, 0) 70 + #define TLV493D_TEMP_CHANNEL GENMASK(1, 0) 71 + #define TLV493D_MODE1_MOD_LOWFAST GENMASK(1, 0) 72 + #define TLV493D_MODE2_LP_PERIOD BIT(6) 73 + #define TLV493D_RD_REG_RES1_WR_MASK GENMASK(4, 3) 74 + #define TLV493D_RD_REG_RES2_WR_MASK GENMASK(7, 0) 75 + #define TLV493D_RD_REG_RES3_WR_MASK GENMASK(4, 0) 76 + 77 + enum tlv493d_channels { 78 + TLV493D_AXIS_X, 79 + TLV493D_AXIS_Y, 80 + TLV493D_AXIS_Z, 81 + TLV493D_TEMPERATURE, 82 + }; 83 + 84 + enum tlv493d_op_mode { 85 + TLV493D_OP_MODE_POWERDOWN, 86 + TLV493D_OP_MODE_FAST, 87 + TLV493D_OP_MODE_LOWPOWER, 88 + TLV493D_OP_MODE_ULTRA_LOWPOWER, 89 + TLV493D_OP_MODE_MASTERCONTROLLED, 90 + }; 91 + 92 + struct tlv493d_data { 93 + struct i2c_client *client; 94 + /* protects from simultaneous sensor access and register readings */ 95 + struct mutex lock; 96 + enum tlv493d_op_mode mode; 97 + u8 wr_regs[TLV493D_WR_REG_MAX]; 98 + }; 99 + 100 + /* 101 + * Different mode has different measurement sampling time, this time is 102 + * used in deriving the sleep and timeout while reading the data from 103 + * sensor in polling. 104 + * Power-down mode: No measurement. 105 + * Fast mode: Freq:3.3 KHz. Measurement time:305 usec. 106 + * Low-power mode: Freq:100 Hz. Measurement time:10 msec. 107 + * Ultra low-power mode: Freq:10 Hz. Measurement time:100 msec. 108 + * Master controlled mode: Freq:3.3 Khz. Measurement time:305 usec. 109 + */ 110 + static const u32 tlv493d_sample_rate_us[] = { 111 + [TLV493D_OP_MODE_POWERDOWN] = 0, 112 + [TLV493D_OP_MODE_FAST] = 305, 113 + [TLV493D_OP_MODE_LOWPOWER] = 10 * USEC_PER_MSEC, 114 + [TLV493D_OP_MODE_ULTRA_LOWPOWER] = 100 * USEC_PER_MSEC, 115 + [TLV493D_OP_MODE_MASTERCONTROLLED] = 305, 116 + }; 117 + 118 + static int tlv493d_write_all_regs(struct tlv493d_data *data) 119 + { 120 + int ret; 121 + struct device *dev = &data->client->dev; 122 + 123 + ret = i2c_master_send(data->client, data->wr_regs, ARRAY_SIZE(data->wr_regs)); 124 + if (ret < 0) { 125 + dev_err(dev, "i2c write registers failed, error: %d\n", ret); 126 + return ret; 127 + } 128 + 129 + return 0; 130 + } 131 + 132 + static int tlv493d_set_operating_mode(struct tlv493d_data *data, enum tlv493d_op_mode mode) 133 + { 134 + u8 *mode1_cfg = &data->wr_regs[TLV493D_WR_REG_MODE1]; 135 + u8 *mode2_cfg = &data->wr_regs[TLV493D_WR_REG_MODE2]; 136 + 137 + switch (mode) { 138 + case TLV493D_OP_MODE_POWERDOWN: 139 + FIELD_MODIFY(TLV493D_MODE1_MOD_LOWFAST, mode1_cfg, 0); 140 + FIELD_MODIFY(TLV493D_MODE2_LP_PERIOD, mode2_cfg, 0); 141 + break; 142 + 143 + case TLV493D_OP_MODE_FAST: 144 + FIELD_MODIFY(TLV493D_MODE1_MOD_LOWFAST, mode1_cfg, 1); 145 + FIELD_MODIFY(TLV493D_MODE2_LP_PERIOD, mode2_cfg, 0); 146 + break; 147 + 148 + case TLV493D_OP_MODE_LOWPOWER: 149 + FIELD_MODIFY(TLV493D_MODE1_MOD_LOWFAST, mode1_cfg, 2); 150 + FIELD_MODIFY(TLV493D_MODE2_LP_PERIOD, mode2_cfg, 1); 151 + break; 152 + 153 + case TLV493D_OP_MODE_ULTRA_LOWPOWER: 154 + FIELD_MODIFY(TLV493D_MODE1_MOD_LOWFAST, mode1_cfg, 2); 155 + FIELD_MODIFY(TLV493D_MODE2_LP_PERIOD, mode2_cfg, 0); 156 + break; 157 + 158 + case TLV493D_OP_MODE_MASTERCONTROLLED: 159 + FIELD_MODIFY(TLV493D_MODE1_MOD_LOWFAST, mode1_cfg, 3); 160 + FIELD_MODIFY(TLV493D_MODE2_LP_PERIOD, mode2_cfg, 0); 161 + break; 162 + } 163 + 164 + return tlv493d_write_all_regs(data); 165 + } 166 + 167 + static s16 tlv493d_get_channel_data(u8 *b, enum tlv493d_channels ch) 168 + { 169 + u16 val; 170 + 171 + switch (ch) { 172 + case TLV493D_AXIS_X: 173 + val = FIELD_GET(TLV493D_BX_MAG_X_AXIS_MSB, b[TLV493D_RD_REG_BX]) << 4 | 174 + FIELD_GET(TLV493D_BX2_MAG_X_AXIS_LSB, b[TLV493D_RD_REG_BX2]) >> 4; 175 + break; 176 + case TLV493D_AXIS_Y: 177 + val = FIELD_GET(TLV493D_BY_MAG_Y_AXIS_MSB, b[TLV493D_RD_REG_BY]) << 4 | 178 + FIELD_GET(TLV493D_BX2_MAG_Y_AXIS_LSB, b[TLV493D_RD_REG_BX2]); 179 + break; 180 + case TLV493D_AXIS_Z: 181 + val = FIELD_GET(TLV493D_BZ_MAG_Z_AXIS_MSB, b[TLV493D_RD_REG_BZ]) << 4 | 182 + FIELD_GET(TLV493D_BZ2_MAG_Z_AXIS_LSB, b[TLV493D_RD_REG_BZ2]); 183 + break; 184 + case TLV493D_TEMPERATURE: 185 + val = FIELD_GET(TLV493D_TEMP_TEMP_MSB, b[TLV493D_RD_REG_TEMP]) << 8 | 186 + FIELD_GET(TLV493D_TEMP2_TEMP_LSB, b[TLV493D_RD_REG_TEMP2]); 187 + break; 188 + } 189 + 190 + return sign_extend32(val, 11); 191 + } 192 + 193 + static int tlv493d_get_measurements(struct tlv493d_data *data, s16 *x, s16 *y, 194 + s16 *z, s16 *t) 195 + { 196 + u8 buff[7] = {}; 197 + int err, ret; 198 + struct device *dev = &data->client->dev; 199 + u32 sleep_us = tlv493d_sample_rate_us[data->mode]; 200 + 201 + guard(mutex)(&data->lock); 202 + 203 + ret = pm_runtime_resume_and_get(dev); 204 + if (ret < 0) 205 + return ret; 206 + 207 + /* 208 + * Poll until data is valid. 209 + * For a valid data TLV493D_TEMP_CHANNEL bit of TLV493D_RD_REG_TEMP 210 + * should be set to 0. The sampling time depends on the sensor mode. 211 + * Poll 3x the time of the sampling time. 212 + */ 213 + ret = read_poll_timeout(i2c_master_recv, err, 214 + err || !FIELD_GET(TLV493D_TEMP_CHANNEL, buff[TLV493D_RD_REG_TEMP]), 215 + sleep_us, 3 * sleep_us, false, data->client, buff, 216 + ARRAY_SIZE(buff)); 217 + if (ret) { 218 + dev_err(dev, "i2c read poll timeout, error:%d\n", ret); 219 + goto out_put_autosuspend; 220 + } 221 + if (err < 0) { 222 + dev_err(dev, "i2c read data failed, error:%d\n", err); 223 + ret = err; 224 + goto out_put_autosuspend; 225 + } 226 + 227 + *x = tlv493d_get_channel_data(buff, TLV493D_AXIS_X); 228 + *y = tlv493d_get_channel_data(buff, TLV493D_AXIS_Y); 229 + *z = tlv493d_get_channel_data(buff, TLV493D_AXIS_Z); 230 + *t = tlv493d_get_channel_data(buff, TLV493D_TEMPERATURE); 231 + 232 + out_put_autosuspend: 233 + pm_runtime_put_autosuspend(dev); 234 + return ret; 235 + } 236 + 237 + static int tlv493d_init(struct tlv493d_data *data) 238 + { 239 + int ret; 240 + u8 buff[TLV493D_RD_REG_MAX]; 241 + struct device *dev = &data->client->dev; 242 + 243 + /* 244 + * The sensor initialization requires below steps to be followed, 245 + * 1. Power-up sensor. 246 + * 2. Read and store read-registers map (0x0-0x9). 247 + * 3. Copy values from read reserved registers to write reserved fields 248 + * (0x0-0x3). 249 + * 4. Set operating mode. 250 + * 5. Write to all registers. 251 + */ 252 + ret = i2c_master_recv(data->client, buff, ARRAY_SIZE(buff)); 253 + if (ret < 0) 254 + return dev_err_probe(dev, ret, "i2c read failed\n"); 255 + 256 + /* Write register 0x0 is reserved. Does not require to be updated.*/ 257 + data->wr_regs[0] = 0; 258 + data->wr_regs[1] = buff[TLV493D_RD_REG_RES1] & TLV493D_RD_REG_RES1_WR_MASK; 259 + data->wr_regs[2] = buff[TLV493D_RD_REG_RES2] & TLV493D_RD_REG_RES2_WR_MASK; 260 + data->wr_regs[3] = buff[TLV493D_RD_REG_RES3] & TLV493D_RD_REG_RES3_WR_MASK; 261 + 262 + ret = tlv493d_set_operating_mode(data, data->mode); 263 + if (ret < 0) 264 + return dev_err_probe(dev, ret, "failed to set operating mode\n"); 265 + 266 + return 0; 267 + } 268 + 269 + static int tlv493d_read_raw(struct iio_dev *indio_dev, 270 + const struct iio_chan_spec *chan, int *val, 271 + int *val2, long mask) 272 + { 273 + struct tlv493d_data *data = iio_priv(indio_dev); 274 + s16 x, y, z, t; 275 + int ret; 276 + 277 + switch (mask) { 278 + case IIO_CHAN_INFO_RAW: 279 + ret = tlv493d_get_measurements(data, &x, &y, &z, &t); 280 + if (ret) 281 + return ret; 282 + 283 + switch (chan->address) { 284 + case TLV493D_AXIS_X: 285 + *val = x; 286 + return IIO_VAL_INT; 287 + case TLV493D_AXIS_Y: 288 + *val = y; 289 + return IIO_VAL_INT; 290 + case TLV493D_AXIS_Z: 291 + *val = z; 292 + return IIO_VAL_INT; 293 + case TLV493D_TEMPERATURE: 294 + *val = t; 295 + return IIO_VAL_INT; 296 + default: 297 + return -EINVAL; 298 + } 299 + case IIO_CHAN_INFO_SCALE: 300 + switch (chan->type) { 301 + case IIO_MAGN: 302 + /* 303 + * Magnetic field scale: 0.0098 mTesla (i.e. 9.8 µT) 304 + * Magnetic field in Gauss: mT * 10 = 0.098. 305 + */ 306 + *val = 98; 307 + *val2 = 1000; 308 + return IIO_VAL_FRACTIONAL; 309 + case IIO_TEMP: 310 + /* 311 + * Temperature scale: 1.1 °C per LSB, expressed as 1100 m°C 312 + * Returned as integer for IIO core to apply: 313 + * temp = (raw + offset) * scale 314 + */ 315 + *val = 1100; 316 + return IIO_VAL_INT; 317 + default: 318 + return -EINVAL; 319 + } 320 + case IIO_CHAN_INFO_OFFSET: 321 + switch (chan->type) { 322 + case IIO_TEMP: 323 + /* 324 + * Temperature offset includes sensor-specific raw offset 325 + * plus compensation for +25°C bias in formula. 326 + * offset = -raw_offset + (25000 / 1100) 327 + * -340 + 22.72 = -317.28 328 + */ 329 + *val = -31728; 330 + *val2 = 100; 331 + return IIO_VAL_FRACTIONAL; 332 + default: 333 + return -EINVAL; 334 + } 335 + default: 336 + return -EINVAL; 337 + } 338 + } 339 + 340 + static irqreturn_t tlv493d_trigger_handler(int irq, void *ptr) 341 + { 342 + int ret; 343 + s16 x, y, z, t; 344 + struct iio_poll_func *pf = ptr; 345 + struct iio_dev *indio_dev = pf->indio_dev; 346 + struct tlv493d_data *data = iio_priv(indio_dev); 347 + struct device *dev = &data->client->dev; 348 + struct { 349 + s16 channels[3]; 350 + s16 temperature; 351 + aligned_s64 timestamp; 352 + } scan; 353 + 354 + ret = tlv493d_get_measurements(data, &x, &y, &z, &t); 355 + if (ret) { 356 + dev_err(dev, "failed to read sensor data\n"); 357 + goto out_trigger_notify; 358 + } 359 + 360 + scan.channels[0] = x; 361 + scan.channels[1] = y; 362 + scan.channels[2] = z; 363 + scan.temperature = t; 364 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), pf->timestamp); 365 + 366 + out_trigger_notify: 367 + iio_trigger_notify_done(indio_dev->trig); 368 + 369 + return IRQ_HANDLED; 370 + } 371 + 372 + #define TLV493D_AXIS_CHANNEL(axis, index) \ 373 + { \ 374 + .type = IIO_MAGN, \ 375 + .modified = 1, \ 376 + .channel2 = IIO_MOD_##axis, \ 377 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 378 + BIT(IIO_CHAN_INFO_SCALE), \ 379 + .address = index, \ 380 + .scan_index = index, \ 381 + .scan_type = { \ 382 + .sign = 's', \ 383 + .realbits = 12, \ 384 + .storagebits = 16, \ 385 + .endianness = IIO_CPU, \ 386 + }, \ 387 + } 388 + 389 + static const struct iio_chan_spec tlv493d_channels[] = { 390 + TLV493D_AXIS_CHANNEL(X, TLV493D_AXIS_X), 391 + TLV493D_AXIS_CHANNEL(Y, TLV493D_AXIS_Y), 392 + TLV493D_AXIS_CHANNEL(Z, TLV493D_AXIS_Z), 393 + { 394 + .type = IIO_TEMP, 395 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 396 + BIT(IIO_CHAN_INFO_SCALE) | 397 + BIT(IIO_CHAN_INFO_OFFSET), 398 + .address = TLV493D_TEMPERATURE, 399 + .scan_index = TLV493D_TEMPERATURE, 400 + .scan_type = { 401 + .sign = 's', 402 + .realbits = 12, 403 + .storagebits = 16, 404 + .endianness = IIO_CPU, 405 + }, 406 + }, 407 + IIO_CHAN_SOFT_TIMESTAMP(4), 408 + }; 409 + 410 + static const struct iio_info tlv493d_info = { 411 + .read_raw = tlv493d_read_raw, 412 + }; 413 + 414 + static const unsigned long tlv493d_scan_masks[] = { GENMASK(3, 0), 0 }; 415 + 416 + static int tlv493d_probe(struct i2c_client *client) 417 + { 418 + struct device *dev = &client->dev; 419 + struct iio_dev *indio_dev; 420 + struct tlv493d_data *data; 421 + int ret; 422 + 423 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 424 + if (!indio_dev) 425 + return -ENOMEM; 426 + 427 + data = iio_priv(indio_dev); 428 + data->client = client; 429 + i2c_set_clientdata(client, indio_dev); 430 + 431 + ret = devm_mutex_init(dev, &data->lock); 432 + if (ret) 433 + return ret; 434 + 435 + ret = devm_regulator_get_enable(dev, "vdd"); 436 + if (ret) 437 + return dev_err_probe(dev, ret, "failed to enable regulator\n"); 438 + 439 + /* 440 + * Setting Sensor default operating mode to Master-Controlled mode since 441 + * it performs measurement cycle only on-request and stays in Power-Down 442 + * state until next cycle is initiated. 443 + */ 444 + data->mode = TLV493D_OP_MODE_MASTERCONTROLLED; 445 + ret = tlv493d_init(data); 446 + if (ret) 447 + return dev_err_probe(dev, ret, "failed to initialize\n"); 448 + 449 + indio_dev->info = &tlv493d_info; 450 + indio_dev->modes = INDIO_DIRECT_MODE; 451 + indio_dev->name = client->name; 452 + indio_dev->channels = tlv493d_channels; 453 + indio_dev->num_channels = ARRAY_SIZE(tlv493d_channels); 454 + indio_dev->available_scan_masks = tlv493d_scan_masks; 455 + 456 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 457 + iio_pollfunc_store_time, 458 + tlv493d_trigger_handler, 459 + NULL); 460 + if (ret) 461 + return dev_err_probe(dev, ret, "iio triggered buffer setup failed\n"); 462 + 463 + ret = pm_runtime_set_active(dev); 464 + if (ret) 465 + return ret; 466 + 467 + ret = devm_pm_runtime_enable(dev); 468 + if (ret) 469 + return ret; 470 + 471 + pm_runtime_get_noresume(dev); 472 + pm_runtime_set_autosuspend_delay(dev, 500); 473 + pm_runtime_use_autosuspend(dev); 474 + 475 + pm_runtime_put_autosuspend(dev); 476 + 477 + ret = devm_iio_device_register(dev, indio_dev); 478 + if (ret) 479 + return dev_err_probe(dev, ret, "iio device register failed\n"); 480 + 481 + return 0; 482 + } 483 + 484 + static int tlv493d_runtime_suspend(struct device *dev) 485 + { 486 + struct tlv493d_data *data = iio_priv(dev_get_drvdata(dev)); 487 + 488 + return tlv493d_set_operating_mode(data, TLV493D_OP_MODE_POWERDOWN); 489 + } 490 + 491 + static int tlv493d_runtime_resume(struct device *dev) 492 + { 493 + struct tlv493d_data *data = iio_priv(dev_get_drvdata(dev)); 494 + 495 + return tlv493d_set_operating_mode(data, data->mode); 496 + } 497 + 498 + static DEFINE_RUNTIME_DEV_PM_OPS(tlv493d_pm_ops, tlv493d_runtime_suspend, 499 + tlv493d_runtime_resume, NULL); 500 + 501 + static const struct i2c_device_id tlv493d_id[] = { 502 + { "tlv493d" }, 503 + { } 504 + }; 505 + MODULE_DEVICE_TABLE(i2c, tlv493d_id); 506 + 507 + static const struct of_device_id tlv493d_of_match[] = { 508 + { .compatible = "infineon,tlv493d-a1b6" }, 509 + { } 510 + }; 511 + MODULE_DEVICE_TABLE(of, tlv493d_of_match); 512 + 513 + static struct i2c_driver tlv493d_driver = { 514 + .driver = { 515 + .name = "tlv493d", 516 + .of_match_table = tlv493d_of_match, 517 + .pm = pm_ptr(&tlv493d_pm_ops), 518 + }, 519 + .probe = tlv493d_probe, 520 + .id_table = tlv493d_id, 521 + }; 522 + module_i2c_driver(tlv493d_driver); 523 + 524 + MODULE_LICENSE("GPL"); 525 + MODULE_DESCRIPTION("Infineon TLV493D Low-Power 3D Magnetic Sensor"); 526 + MODULE_AUTHOR("Dixit Parmar <dixitparmar19@gmail.com>");
+1 -4
drivers/iio/magnetometer/tmag5273.c
··· 287 287 int ret; 288 288 289 289 switch (mask) { 290 - case IIO_CHAN_INFO_PROCESSED: 291 290 case IIO_CHAN_INFO_RAW: 292 291 ret = pm_runtime_resume_and_get(data->dev); 293 292 if (ret < 0) ··· 294 295 295 296 ret = tmag5273_get_measure(data, &t, &x, &y, &z, &angle, &magnitude); 296 297 297 - pm_runtime_mark_last_busy(data->dev); 298 298 pm_runtime_put_autosuspend(data->dev); 299 299 300 300 if (ret) ··· 640 642 */ 641 643 ret = devm_add_action_or_reset(dev, tmag5273_power_down, data); 642 644 if (ret) 643 - return dev_err_probe(dev, ret, "failed to add powerdown action\n"); 645 + return ret; 644 646 645 647 ret = pm_runtime_set_active(dev); 646 648 if (ret < 0) ··· 666 668 indio_dev->channels = tmag5273_channels; 667 669 indio_dev->num_channels = ARRAY_SIZE(tmag5273_channels); 668 670 669 - pm_runtime_mark_last_busy(dev); 670 671 pm_runtime_put_autosuspend(dev); 671 672 672 673 ret = devm_iio_device_register(dev, indio_dev);
-2
drivers/iio/magnetometer/yamaha-yas530.c
··· 623 623 case IIO_CHAN_INFO_RAW: 624 624 pm_runtime_get_sync(yas5xx->dev); 625 625 ret = ci->get_measure(yas5xx, &t, &x, &y, &z); 626 - pm_runtime_mark_last_busy(yas5xx->dev); 627 626 pm_runtime_put_autosuspend(yas5xx->dev); 628 627 if (ret) 629 628 return ret; ··· 663 664 664 665 pm_runtime_get_sync(yas5xx->dev); 665 666 ret = ci->get_measure(yas5xx, &t, &x, &y, &z); 666 - pm_runtime_mark_last_busy(yas5xx->dev); 667 667 pm_runtime_put_autosuspend(yas5xx->dev); 668 668 if (ret) { 669 669 dev_err(yas5xx->dev, "error refilling buffer\n");
+1 -3
drivers/iio/potentiostat/lmp91000.c
··· 321 321 data->trig = devm_iio_trigger_alloc(dev, "%s-mux%d", 322 322 indio_dev->name, 323 323 iio_device_id(indio_dev)); 324 - if (!data->trig) { 325 - dev_err(dev, "cannot allocate iio trigger.\n"); 324 + if (!data->trig) 326 325 return -ENOMEM; 327 - } 328 326 329 327 init_completion(&data->completion); 330 328
+1 -7
drivers/iio/pressure/bmp280-core.c
··· 752 752 753 753 pm_runtime_get_sync(data->dev); 754 754 ret = bmp280_read_raw_impl(indio_dev, chan, val, val2, mask); 755 - pm_runtime_mark_last_busy(data->dev); 756 755 pm_runtime_put_autosuspend(data->dev); 757 756 758 757 return ret; ··· 926 927 927 928 pm_runtime_get_sync(data->dev); 928 929 ret = bmp280_write_raw_impl(indio_dev, chan, val, val2, mask); 929 - pm_runtime_mark_last_busy(data->dev); 930 930 pm_runtime_put_autosuspend(data->dev); 931 931 932 932 return ret; ··· 2253 2255 2254 2256 pm_runtime_get_sync(data->dev); 2255 2257 ret = bmp580_nvmem_read_impl(priv, offset, val, bytes); 2256 - pm_runtime_mark_last_busy(data->dev); 2257 2258 pm_runtime_put_autosuspend(data->dev); 2258 2259 2259 2260 return ret; ··· 2327 2330 2328 2331 pm_runtime_get_sync(data->dev); 2329 2332 ret = bmp580_nvmem_write_impl(priv, offset, val, bytes); 2330 - pm_runtime_mark_last_busy(data->dev); 2331 2333 pm_runtime_put_autosuspend(data->dev); 2332 2334 2333 2335 return ret; ··· 3116 3120 { 3117 3121 struct bmp280_data *data = iio_priv(indio_dev); 3118 3122 3119 - pm_runtime_mark_last_busy(data->dev); 3120 3123 pm_runtime_put_autosuspend(data->dev); 3121 3124 3122 3125 return 0; ··· 3212 3217 return dev_err_probe(dev, PTR_ERR(gpiod), "failed to get reset GPIO\n"); 3213 3218 3214 3219 /* Deassert the signal */ 3215 - dev_info(dev, "release reset\n"); 3216 - gpiod_set_value(gpiod, 0); 3220 + gpiod_set_value_cansleep(gpiod, 0); 3217 3221 3218 3222 data->regmap = regmap; 3219 3223
+1 -3
drivers/iio/pressure/dlhl60d.c
··· 289 289 } 290 290 291 291 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); 292 - if (!indio_dev) { 293 - dev_err(&client->dev, "failed to allocate iio device\n"); 292 + if (!indio_dev) 294 293 return -ENOMEM; 295 - } 296 294 297 295 i2c_set_clientdata(client, indio_dev); 298 296
-1
drivers/iio/pressure/icp10100.c
··· 265 265 (be16_to_cpu(measures[1]) >> 8); 266 266 *temperature = be16_to_cpu(measures[2]); 267 267 268 - pm_runtime_mark_last_busy(&st->client->dev); 269 268 error_measure: 270 269 pm_runtime_put_autosuspend(&st->client->dev); 271 270 return ret;
-2
drivers/iio/pressure/mpl115.c
··· 108 108 ret = mpl115_comp_pressure(data, val, val2); 109 109 if (ret < 0) 110 110 return ret; 111 - pm_runtime_mark_last_busy(data->dev); 112 111 pm_runtime_put_autosuspend(data->dev); 113 112 114 113 return IIO_VAL_INT_PLUS_MICRO; ··· 117 118 ret = mpl115_read_temp(data); 118 119 if (ret < 0) 119 120 return ret; 120 - pm_runtime_mark_last_busy(data->dev); 121 121 pm_runtime_put_autosuspend(data->dev); 122 122 *val = ret >> 6; 123 123
-2
drivers/iio/pressure/zpa2326.c
··· 697 697 698 698 zpa2326_sleep(indio_dev); 699 699 700 - pm_runtime_mark_last_busy(parent); 701 700 pm_runtime_put_autosuspend(parent); 702 701 } 703 702 ··· 707 708 pm_runtime_enable(parent); 708 709 pm_runtime_set_autosuspend_delay(parent, 1000); 709 710 pm_runtime_use_autosuspend(parent); 710 - pm_runtime_mark_last_busy(parent); 711 711 pm_runtime_put_autosuspend(parent); 712 712 } 713 713
+1 -2
drivers/iio/proximity/d3323aa.c
··· 722 722 723 723 indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 724 724 if (!indio_dev) 725 - return dev_err_probe(dev, -ENOMEM, 726 - "Could not allocate iio device\n"); 725 + return -ENOMEM; 727 726 728 727 data = iio_priv(indio_dev); 729 728 data->dev = dev;
+1 -2
drivers/iio/proximity/hx9023s.c
··· 1141 1141 indio_dev->name, 1142 1142 iio_device_id(indio_dev)); 1143 1143 if (!data->trig) 1144 - return dev_err_probe(dev, -ENOMEM, 1145 - "iio trigger alloc failed\n"); 1144 + return -ENOMEM; 1146 1145 1147 1146 data->trig->ops = &hx9023s_trigger_ops; 1148 1147 iio_trigger_set_drvdata(data->trig, indio_dev);
+2 -4
drivers/iio/proximity/irsd200.c
··· 862 862 863 863 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 864 864 if (!indio_dev) 865 - return dev_err_probe(&client->dev, -ENOMEM, 866 - "Could not allocate iio device\n"); 865 + return -ENOMEM; 867 866 868 867 data = iio_priv(indio_dev); 869 868 data->dev = &client->dev; ··· 915 916 trigger = devm_iio_trigger_alloc(data->dev, "%s-dev%d", indio_dev->name, 916 917 iio_device_id(indio_dev)); 917 918 if (!trigger) 918 - return dev_err_probe(data->dev, -ENOMEM, 919 - "Could not allocate iio trigger\n"); 919 + return -ENOMEM; 920 920 921 921 trigger->ops = &irsd200_trigger_ops; 922 922 iio_trigger_set_drvdata(trigger, data);
+7 -8
drivers/iio/proximity/mb1232.c
··· 42 42 */ 43 43 struct completion ranging; 44 44 int irqnr; 45 - /* Ensure correct alignment of data to push to IIO buffer */ 46 - struct { 47 - s16 distance; 48 - aligned_s64 ts; 49 - } scan; 50 45 }; 51 46 52 47 static irqreturn_t mb1232_handle_irq(int irq, void *dev_id) ··· 115 120 struct iio_poll_func *pf = p; 116 121 struct iio_dev *indio_dev = pf->indio_dev; 117 122 struct mb1232_data *data = iio_priv(indio_dev); 123 + struct { 124 + s16 distance; 125 + aligned_s64 ts; 126 + } scan = { }; 118 127 119 - data->scan.distance = mb1232_read_distance(data); 120 - if (data->scan.distance < 0) 128 + scan.distance = mb1232_read_distance(data); 129 + if (scan.distance < 0) 121 130 goto err; 122 131 123 - iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan), 132 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), 124 133 pf->timestamp); 125 134 126 135 err:
+1 -3
drivers/iio/proximity/ping.c
··· 280 280 struct iio_dev *indio_dev; 281 281 282 282 indio_dev = devm_iio_device_alloc(dev, sizeof(struct ping_data)); 283 - if (!indio_dev) { 284 - dev_err(dev, "failed to allocate IIO device\n"); 283 + if (!indio_dev) 285 284 return -ENOMEM; 286 - } 287 285 288 286 data = iio_priv(indio_dev); 289 287 data->dev = dev;
+6 -10
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
··· 43 43 44 44 int (*xfer)(struct lidar_data *data, u8 reg, u8 *val, int len); 45 45 int i2c_enabled; 46 - 47 - /* Ensure timestamp is naturally aligned */ 48 - struct { 49 - u16 chan; 50 - aligned_s64 timestamp; 51 - } scan; 52 46 }; 53 47 54 48 static const struct iio_chan_spec lidar_channels[] = { ··· 185 191 } 186 192 ret = -EIO; 187 193 } 188 - pm_runtime_mark_last_busy(&client->dev); 189 194 pm_runtime_put_autosuspend(&client->dev); 190 195 191 196 return ret; ··· 228 235 struct iio_dev *indio_dev = pf->indio_dev; 229 236 struct lidar_data *data = iio_priv(indio_dev); 230 237 int ret; 238 + struct { 239 + u16 chan; 240 + aligned_s64 timestamp; 241 + } scan = { }; 231 242 232 - ret = lidar_get_measurement(data, &data->scan.chan); 243 + ret = lidar_get_measurement(data, &scan.chan); 233 244 if (!ret) { 234 - iio_push_to_buffers_with_ts(indio_dev, &data->scan, 235 - sizeof(data->scan), 245 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), 236 246 iio_get_time_ns(indio_dev)); 237 247 } else if (ret != -EINVAL) { 238 248 dev_err(&data->client->dev, "cannot read LIDAR measurement");
+2 -6
drivers/iio/proximity/srf04.c
··· 117 117 udelay(data->cfg->trigger_pulse_us); 118 118 gpiod_set_value(data->gpiod_trig, 0); 119 119 120 - if (data->gpiod_power) { 121 - pm_runtime_mark_last_busy(data->dev); 120 + if (data->gpiod_power) 122 121 pm_runtime_put_autosuspend(data->dev); 123 - } 124 122 125 123 /* it should not take more than 20 ms until echo is rising */ 126 124 ret = wait_for_completion_killable_timeout(&data->rising, HZ/50); ··· 251 253 int ret; 252 254 253 255 indio_dev = devm_iio_device_alloc(dev, sizeof(struct srf04_data)); 254 - if (!indio_dev) { 255 - dev_err(dev, "failed to allocate IIO device\n"); 256 + if (!indio_dev) 256 257 return -ENOMEM; 257 - } 258 258 259 259 data = iio_priv(indio_dev); 260 260 data->dev = dev;
+7 -11
drivers/iio/proximity/srf08.c
··· 63 63 int range_mm; 64 64 struct mutex lock; 65 65 66 - /* Ensure timestamp is naturally aligned */ 67 - struct { 68 - s16 chan; 69 - aligned_s64 timestamp; 70 - } scan; 71 - 72 66 /* Sensor-Type */ 73 67 enum srf08_sensor_type sensor_type; 74 68 ··· 176 182 struct iio_poll_func *pf = p; 177 183 struct iio_dev *indio_dev = pf->indio_dev; 178 184 struct srf08_data *data = iio_priv(indio_dev); 179 - s16 sensor_data; 185 + struct { 186 + s16 chan; 187 + aligned_s64 timestamp; 188 + } scan = { }; 180 189 181 - sensor_data = srf08_read_ranging(data); 182 - if (sensor_data < 0) 190 + scan.chan = srf08_read_ranging(data); 191 + if (scan.chan < 0) 183 192 goto err; 184 193 185 194 mutex_lock(&data->lock); 186 195 187 - data->scan.chan = sensor_data; 188 - iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan), 196 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), 189 197 pf->timestamp); 190 198 191 199 mutex_unlock(&data->lock);
+6 -21
drivers/iio/proximity/sx9500.c
··· 88 88 bool prox_stat[SX9500_NUM_CHANNELS]; 89 89 bool event_enabled[SX9500_NUM_CHANNELS]; 90 90 bool trigger_enabled; 91 - u16 *buffer; 92 91 /* Remember enabled channels and sample rate during suspend. */ 93 92 unsigned int suspend_ctrl0; 94 93 struct completion completion; ··· 577 578 return ret; 578 579 } 579 580 580 - static int sx9500_update_scan_mode(struct iio_dev *indio_dev, 581 - const unsigned long *scan_mask) 582 - { 583 - struct sx9500_data *data = iio_priv(indio_dev); 584 - 585 - mutex_lock(&data->mutex); 586 - kfree(data->buffer); 587 - data->buffer = kzalloc(indio_dev->scan_bytes, GFP_KERNEL); 588 - mutex_unlock(&data->mutex); 589 - 590 - if (data->buffer == NULL) 591 - return -ENOMEM; 592 - 593 - return 0; 594 - } 595 - 596 581 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( 597 582 "2.500000 3.333333 5 6.666666 8.333333 11.111111 16.666666 33.333333"); 598 583 ··· 595 612 .write_raw = &sx9500_write_raw, 596 613 .read_event_config = &sx9500_read_event_config, 597 614 .write_event_config = &sx9500_write_event_config, 598 - .update_scan_mode = &sx9500_update_scan_mode, 599 615 }; 600 616 601 617 static int sx9500_set_trigger_state(struct iio_trigger *trig, ··· 631 649 struct iio_dev *indio_dev = pf->indio_dev; 632 650 struct sx9500_data *data = iio_priv(indio_dev); 633 651 int val, bit, ret, i = 0; 652 + struct { 653 + u16 chan[SX9500_NUM_CHANNELS]; 654 + aligned_s64 timestamp; 655 + } scan = { }; 634 656 635 657 mutex_lock(&data->mutex); 636 658 ··· 644 658 if (ret < 0) 645 659 goto out; 646 660 647 - data->buffer[i++] = val; 661 + scan.chan[i++] = val; 648 662 } 649 663 650 - iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 664 + iio_push_to_buffers_with_timestamp(indio_dev, &scan, 651 665 iio_get_time_ns(indio_dev)); 652 666 653 667 out: ··· 970 984 iio_triggered_buffer_cleanup(indio_dev); 971 985 if (client->irq > 0) 972 986 iio_trigger_unregister(data->trig); 973 - kfree(data->buffer); 974 987 } 975 988 976 989 static int sx9500_suspend(struct device *dev)
+12 -15
drivers/iio/proximity/vl53l0x-i2c.c
··· 57 57 struct regulator *vdd_supply; 58 58 struct gpio_desc *reset_gpio; 59 59 struct iio_trigger *trig; 60 - 61 - struct { 62 - u16 chan; 63 - aligned_s64 timestamp; 64 - } scan; 65 60 }; 66 61 67 62 static int vl53l0x_clear_irq(struct vl53l0x_data *data) ··· 79 84 struct vl53l0x_data *data = iio_priv(indio_dev); 80 85 u8 buffer[12]; 81 86 int ret; 87 + struct { 88 + u16 chan; 89 + aligned_s64 timestamp; 90 + } scan = { }; 82 91 83 92 ret = i2c_smbus_read_i2c_block_data(data->client, 84 93 VL_REG_RESULT_RANGE_STATUS, ··· 92 93 else if (ret != 12) 93 94 return -EREMOTEIO; 94 95 95 - data->scan.chan = get_unaligned_be16(&buffer[10]); 96 - iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan), 96 + scan.chan = get_unaligned_be16(&buffer[10]); 97 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), 97 98 iio_get_time_ns(indio_dev)); 98 99 99 100 iio_trigger_notify_done(indio_dev->trig); ··· 311 312 { 312 313 struct vl53l0x_data *data; 313 314 struct iio_dev *indio_dev; 314 - int error; 315 315 int ret; 316 316 317 317 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); ··· 343 345 return dev_err_probe(&client->dev, PTR_ERR(data->reset_gpio), 344 346 "Cannot get reset GPIO\n"); 345 347 346 - error = vl53l0x_power_on(data); 347 - if (error) 348 - return dev_err_probe(&client->dev, error, 348 + ret = vl53l0x_power_on(data); 349 + if (ret) 350 + return dev_err_probe(&client->dev, ret, 349 351 "Failed to power on the chip\n"); 350 352 351 - error = devm_add_action_or_reset(&client->dev, vl53l0x_power_off, data); 352 - if (error) 353 - return dev_err_probe(&client->dev, error, 354 - "Failed to install poweroff action\n"); 353 + ret = devm_add_action_or_reset(&client->dev, vl53l0x_power_off, data); 354 + if (ret) 355 + return ret; 355 356 356 357 indio_dev->name = "vl53l0x"; 357 358 indio_dev->info = &vl53l0x_info;
+5 -3
drivers/iio/temperature/Kconfig
··· 173 173 will be called max31865. 174 174 175 175 config MCP9600 176 - tristate "MCP9600 thermocouple EMF converter" 176 + tristate "MCP9600 and similar thermocouple EMF converters" 177 177 depends on I2C 178 178 help 179 - If you say yes here you get support for MCP9600 180 - thermocouple EMF converter connected via I2C. 179 + If you say yes here you get support for... 180 + - MCP9600 181 + - MCP9601 182 + ...thermocouple EMF converters connected via I2C. 181 183 182 184 This driver can also be built as a module. If so, the module 183 185 will be called mcp9600.
+128 -23
drivers/iio/temperature/mcp9600.c
··· 22 22 #include <linux/iio/events.h> 23 23 #include <linux/iio/iio.h> 24 24 25 + #include <dt-bindings/iio/temperature/thermocouple.h> 26 + 25 27 /* MCP9600 registers */ 26 - #define MCP9600_HOT_JUNCTION 0x0 27 - #define MCP9600_COLD_JUNCTION 0x2 28 - #define MCP9600_STATUS 0x4 28 + #define MCP9600_HOT_JUNCTION 0x00 29 + #define MCP9600_COLD_JUNCTION 0x02 30 + #define MCP9600_STATUS 0x04 29 31 #define MCP9600_STATUS_ALERT(x) BIT(x) 30 - #define MCP9600_ALERT_CFG1 0x8 32 + #define MCP9600_SENSOR_CFG 0x05 33 + #define MCP9600_SENSOR_TYPE_MASK GENMASK(6, 4) 34 + #define MCP9600_ALERT_CFG1 0x08 31 35 #define MCP9600_ALERT_CFG(x) (MCP9600_ALERT_CFG1 + (x - 1)) 32 36 #define MCP9600_ALERT_CFG_ENABLE BIT(0) 33 37 #define MCP9600_ALERT_CFG_ACTIVE_HIGH BIT(2) 34 38 #define MCP9600_ALERT_CFG_FALLING BIT(3) 35 39 #define MCP9600_ALERT_CFG_COLD_JUNCTION BIT(4) 36 - #define MCP9600_ALERT_HYSTERESIS1 0xc 40 + #define MCP9600_ALERT_HYSTERESIS1 0x0c 37 41 #define MCP9600_ALERT_HYSTERESIS(x) (MCP9600_ALERT_HYSTERESIS1 + (x - 1)) 38 42 #define MCP9600_ALERT_LIMIT1 0x10 39 43 #define MCP9600_ALERT_LIMIT(x) (MCP9600_ALERT_LIMIT1 + (x - 1)) 40 44 #define MCP9600_ALERT_LIMIT_MASK GENMASK(15, 2) 41 - #define MCP9600_DEVICE_ID 0x20 45 + #define MCP9600_DEVICE_ID 0x20 42 46 43 47 /* MCP9600 device id value */ 44 - #define MCP9600_DEVICE_ID_MCP9600 0x40 48 + #define MCP9600_DEVICE_ID_MCP9600 0x40 49 + #define MCP9600_DEVICE_ID_MCP9601 0x41 45 50 46 51 #define MCP9600_ALERT_COUNT 4 47 52 ··· 70 65 [MCP9600_ALERT4] = "alert4", 71 66 }; 72 67 68 + /* Map between dt-bindings enum and the chip's type value */ 69 + static const unsigned int mcp9600_type_map[] = { 70 + [THERMOCOUPLE_TYPE_K] = 0, 71 + [THERMOCOUPLE_TYPE_J] = 1, 72 + [THERMOCOUPLE_TYPE_T] = 2, 73 + [THERMOCOUPLE_TYPE_N] = 3, 74 + [THERMOCOUPLE_TYPE_S] = 4, 75 + [THERMOCOUPLE_TYPE_E] = 5, 76 + [THERMOCOUPLE_TYPE_B] = 6, 77 + [THERMOCOUPLE_TYPE_R] = 7, 78 + }; 79 + 80 + /* Map thermocouple type to a char for iio info in sysfs */ 81 + static const int mcp9600_tc_types[] = { 82 + [THERMOCOUPLE_TYPE_K] = 'K', 83 + [THERMOCOUPLE_TYPE_J] = 'J', 84 + [THERMOCOUPLE_TYPE_T] = 'T', 85 + [THERMOCOUPLE_TYPE_N] = 'N', 86 + [THERMOCOUPLE_TYPE_S] = 'S', 87 + [THERMOCOUPLE_TYPE_E] = 'E', 88 + [THERMOCOUPLE_TYPE_B] = 'B', 89 + [THERMOCOUPLE_TYPE_R] = 'R', 90 + }; 91 + 73 92 static const struct iio_event_spec mcp9600_events[] = { 74 93 { 75 94 .type = IIO_EV_TYPE_THRESH, ··· 111 82 }, 112 83 }; 113 84 85 + struct mcp_chip_info { 86 + u8 chip_id; 87 + const char *chip_name; 88 + }; 89 + 90 + struct mcp9600_data { 91 + struct i2c_client *client; 92 + u32 thermocouple_type; 93 + }; 94 + 95 + static int mcp9600_config(struct mcp9600_data *data) 96 + { 97 + struct i2c_client *client = data->client; 98 + int ret; 99 + u8 cfg; 100 + 101 + cfg = FIELD_PREP(MCP9600_SENSOR_TYPE_MASK, 102 + mcp9600_type_map[data->thermocouple_type]); 103 + 104 + ret = i2c_smbus_write_byte_data(client, MCP9600_SENSOR_CFG, cfg); 105 + if (ret < 0) { 106 + dev_err(&client->dev, "Failed to set sensor configuration\n"); 107 + return ret; 108 + } 109 + 110 + return 0; 111 + } 112 + 114 113 #define MCP9600_CHANNELS(hj_num_ev, hj_ev_spec_off, cj_num_ev, cj_ev_spec_off) \ 115 114 { \ 116 115 { \ 117 116 .type = IIO_TEMP, \ 118 117 .address = MCP9600_HOT_JUNCTION, \ 119 118 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 119 + BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE) | \ 120 120 BIT(IIO_CHAN_INFO_SCALE), \ 121 121 .event_spec = &mcp9600_events[hj_ev_spec_off], \ 122 122 .num_event_specs = hj_num_ev, \ ··· 181 123 MCP9600_CHANNELS(2, 0, 2, 0), /* Alerts: 1 2 3 4 */ 182 124 }; 183 125 184 - struct mcp9600_data { 185 - struct i2c_client *client; 186 - }; 187 - 188 126 static int mcp9600_read(struct mcp9600_data *data, 189 127 struct iio_chan_spec const *chan, int *val) 190 128 { ··· 213 159 *val = 62; 214 160 *val2 = 500000; 215 161 return IIO_VAL_INT_PLUS_MICRO; 162 + case IIO_CHAN_INFO_THERMOCOUPLE_TYPE: 163 + *val = mcp9600_tc_types[data->thermocouple_type]; 164 + return IIO_VAL_CHAR; 216 165 default: 217 166 return -EINVAL; 218 167 } ··· 473 416 474 417 static int mcp9600_probe(struct i2c_client *client) 475 418 { 419 + struct device *dev = &client->dev; 420 + const struct mcp_chip_info *chip_info; 476 421 struct iio_dev *indio_dev; 477 422 struct mcp9600_data *data; 478 - int ret, ch_sel; 423 + int ch_sel, dev_id, ret; 479 424 480 - ret = i2c_smbus_read_byte_data(client, MCP9600_DEVICE_ID); 481 - if (ret < 0) 482 - return dev_err_probe(&client->dev, ret, "Failed to read device ID\n"); 483 - if (ret != MCP9600_DEVICE_ID_MCP9600) 484 - dev_warn(&client->dev, "Expected ID %x, got %x\n", 485 - MCP9600_DEVICE_ID_MCP9600, ret); 425 + chip_info = i2c_get_match_data(client); 426 + if (!chip_info) 427 + return dev_err_probe(dev, -ENODEV, 428 + "No chip-info found for device\n"); 486 429 487 - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 430 + dev_id = i2c_smbus_read_byte_data(client, MCP9600_DEVICE_ID); 431 + if (dev_id < 0) 432 + return dev_err_probe(dev, dev_id, "Failed to read device ID\n"); 433 + 434 + switch (dev_id) { 435 + case MCP9600_DEVICE_ID_MCP9600: 436 + case MCP9600_DEVICE_ID_MCP9601: 437 + if (dev_id != chip_info->chip_id) 438 + dev_warn(dev, 439 + "Expected id %02x, but device responded with %02x\n", 440 + chip_info->chip_id, dev_id); 441 + break; 442 + 443 + default: 444 + dev_warn(dev, "Unknown id %x, using %x\n", dev_id, 445 + chip_info->chip_id); 446 + } 447 + 448 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 488 449 if (!indio_dev) 489 450 return -ENOMEM; 490 451 491 452 data = iio_priv(indio_dev); 492 453 data->client = client; 493 454 455 + /* Accept type from dt with default of Type-K. */ 456 + data->thermocouple_type = THERMOCOUPLE_TYPE_K; 457 + ret = device_property_read_u32(dev, "thermocouple-type", 458 + &data->thermocouple_type); 459 + if (ret && ret != -EINVAL) 460 + return dev_err_probe(dev, ret, 461 + "Error reading thermocouple-type property\n"); 462 + 463 + if (data->thermocouple_type >= ARRAY_SIZE(mcp9600_type_map)) 464 + return dev_err_probe(dev, -EINVAL, 465 + "Invalid thermocouple-type property %u.\n", 466 + data->thermocouple_type); 467 + 468 + /* Set initial config. */ 469 + ret = mcp9600_config(data); 470 + if (ret) 471 + return ret; 472 + 494 473 ch_sel = mcp9600_probe_alerts(indio_dev); 495 474 if (ch_sel < 0) 496 475 return ch_sel; 497 476 498 477 indio_dev->info = &mcp9600_info; 499 - indio_dev->name = "mcp9600"; 478 + indio_dev->name = chip_info->chip_name; 500 479 indio_dev->modes = INDIO_DIRECT_MODE; 501 480 indio_dev->channels = mcp9600_channels[ch_sel]; 502 481 indio_dev->num_channels = ARRAY_SIZE(mcp9600_channels[ch_sel]); 503 482 504 - return devm_iio_device_register(&client->dev, indio_dev); 483 + return devm_iio_device_register(dev, indio_dev); 505 484 } 506 485 486 + static const struct mcp_chip_info mcp9600_chip_info = { 487 + .chip_id = MCP9600_DEVICE_ID_MCP9600, 488 + .chip_name = "mcp9600", 489 + }; 490 + 491 + static const struct mcp_chip_info mcp9601_chip_info = { 492 + .chip_id = MCP9600_DEVICE_ID_MCP9601, 493 + .chip_name = "mcp9601", 494 + }; 495 + 507 496 static const struct i2c_device_id mcp9600_id[] = { 508 - { "mcp9600" }, 497 + { "mcp9600", .driver_data = (kernel_ulong_t)&mcp9600_chip_info }, 498 + { "mcp9601", .driver_data = (kernel_ulong_t)&mcp9601_chip_info }, 509 499 { } 510 500 }; 511 501 MODULE_DEVICE_TABLE(i2c, mcp9600_id); 512 502 513 503 static const struct of_device_id mcp9600_of_match[] = { 514 - { .compatible = "microchip,mcp9600" }, 504 + { .compatible = "microchip,mcp9600", .data = &mcp9600_chip_info }, 505 + { .compatible = "microchip,mcp9601", .data = &mcp9601_chip_info }, 515 506 { } 516 507 }; 517 508 MODULE_DEVICE_TABLE(of, mcp9600_of_match);
-1
drivers/iio/temperature/mlx90614.c
··· 225 225 if (!data->wakeup_gpio) 226 226 return; 227 227 228 - pm_runtime_mark_last_busy(&data->client->dev); 229 228 pm_runtime_put_autosuspend(&data->client->dev); 230 229 } 231 230 #else
+1 -4
drivers/iio/temperature/mlx90632.c
··· 1043 1043 } 1044 1044 1045 1045 mlx90632_read_raw_pm: 1046 - pm_runtime_mark_last_busy(&data->client->dev); 1047 1046 pm_runtime_put_autosuspend(&data->client->dev); 1048 1047 return ret; 1049 1048 } ··· 1177 1178 int ret; 1178 1179 1179 1180 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*mlx90632)); 1180 - if (!indio_dev) { 1181 - dev_err(&client->dev, "Failed to allocate device\n"); 1181 + if (!indio_dev) 1182 1182 return -ENOMEM; 1183 - } 1184 1183 1185 1184 regmap = devm_regmap_init_i2c(client, &mlx90632_regmap); 1186 1185 if (IS_ERR(regmap)) {
+3 -6
drivers/iio/temperature/mlx90635.c
··· 749 749 } 750 750 751 751 mlx90635_read_raw_pm: 752 - pm_runtime_mark_last_busy(&data->client->dev); 753 752 pm_runtime_put_autosuspend(&data->client->dev); 754 753 return ret; 755 754 } ··· 938 939 939 940 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*mlx90635)); 940 941 if (!indio_dev) 941 - return dev_err_probe(&client->dev, -ENOMEM, "failed to allocate device\n"); 942 + return -ENOMEM; 942 943 943 944 regmap = devm_regmap_init_i2c(client, &mlx90635_regmap); 944 945 if (IS_ERR(regmap)) ··· 976 977 ret = devm_add_action_or_reset(&client->dev, mlx90635_disable_regulator, 977 978 mlx90635); 978 979 if (ret < 0) 979 - return dev_err_probe(&client->dev, ret, 980 - "failed to setup regulator cleanup action\n"); 980 + return ret; 981 981 982 982 ret = mlx90635_wakeup(mlx90635); 983 983 if (ret < 0) ··· 984 986 985 987 ret = devm_add_action_or_reset(&client->dev, mlx90635_sleep, mlx90635); 986 988 if (ret < 0) 987 - return dev_err_probe(&client->dev, ret, 988 - "failed to setup low power cleanup\n"); 989 + return ret; 989 990 990 991 ret = regmap_read(mlx90635->regmap_ee, MLX90635_EE_VERSION, &dsp_version); 991 992 if (ret < 0)
+12
drivers/iio/test/Kconfig
··· 41 41 to the KUnit documentation in Documentation/dev-tools/kunit/. 42 42 43 43 If unsure, say N. 44 + 45 + config IIO_MULTIPLY_KUNIT_TEST 46 + tristate "Test IIO multiply functions" if !KUNIT_ALL_TESTS 47 + depends on KUNIT 48 + default KUNIT_ALL_TESTS 49 + help 50 + build unit tests for the IIO multiply functions. 51 + 52 + For more information on KUnit and unit tests in general, please refer 53 + to the KUnit documentation in Documentation/dev-tools/kunit/. 54 + 55 + If unsure, say N.
+1
drivers/iio/test/Makefile
··· 7 7 obj-$(CONFIG_IIO_RESCALE_KUNIT_TEST) += iio-test-rescale.o 8 8 obj-$(CONFIG_IIO_FORMAT_KUNIT_TEST) += iio-test-format.o 9 9 obj-$(CONFIG_IIO_GTS_KUNIT_TEST) += iio-test-gts.o 10 + obj-$(CONFIG_IIO_MULTIPLY_KUNIT_TEST) += iio-test-multiply.o 10 11 CFLAGS_iio-test-format.o += $(DISABLE_STRUCTLEAK_PLUGIN)
+212
drivers/iio/test/iio-test-multiply.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* Unit tests for IIO multiply functions 3 + * 4 + * Copyright (c) 2025 Hans de Goede <hans@hansg.org> 5 + * Based on iio-test-format.c which is: 6 + * Copyright (c) 2020 Lars-Peter Clausen <lars@metafoo.de> 7 + */ 8 + 9 + #include <kunit/test.h> 10 + #include <linux/iio/consumer.h> 11 + #include <linux/math64.h> 12 + #include <linux/types.h> 13 + 14 + static void __iio_test_iio_multiply_value_integer(struct kunit *test, s64 multiplier) 15 + { 16 + int ret, result, val; 17 + 18 + val = 42; 19 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_INT, val, 0); 20 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 21 + KUNIT_EXPECT_EQ(test, result, multiplier * val); 22 + 23 + val = -23; 24 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_INT, val, 0); 25 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 26 + KUNIT_EXPECT_EQ(test, result, multiplier * val); 27 + 28 + val = 0; 29 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_INT, val, 0); 30 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 31 + KUNIT_EXPECT_EQ(test, result, multiplier * val); 32 + } 33 + 34 + static void iio_test_iio_multiply_value_integer(struct kunit *test) 35 + { 36 + __iio_test_iio_multiply_value_integer(test, 20); 37 + __iio_test_iio_multiply_value_integer(test, -20); 38 + } 39 + 40 + static void __iio_test_iio_multiply_value_fixedpoint(struct kunit *test, s64 multiplier) 41 + { 42 + int ret, result, val, val2; 43 + 44 + /* positive >= 1 (1.5) */ 45 + val = 1; 46 + val2 = 500000; 47 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_INT_PLUS_MICRO, val, val2); 48 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 49 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * 15, 10)); 50 + 51 + val = 1; 52 + val2 = 500000000; 53 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_INT_PLUS_NANO, val, val2); 54 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 55 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * 15, 10)); 56 + 57 + /* positive < 1 (0.5) */ 58 + val = 0; 59 + val2 = 500000; 60 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_INT_PLUS_MICRO, val, val2); 61 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 62 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * 5, 10)); 63 + 64 + val = 0; 65 + val2 = 500000000; 66 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_INT_PLUS_NANO, val, val2); 67 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 68 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * 5, 10)); 69 + 70 + /* negative <= -1 (-1.5) */ 71 + val = -1; 72 + val2 = 500000; 73 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_INT_PLUS_MICRO, val, val2); 74 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 75 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * -15, 10)); 76 + 77 + val = -1; 78 + val2 = 500000000; 79 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_INT_PLUS_NANO, val, val2); 80 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 81 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * -15, 10)); 82 + 83 + /* negative > -1 (-0.5) */ 84 + val = 0; 85 + val2 = -500000; 86 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_INT_PLUS_MICRO, val, val2); 87 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 88 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * -5, 10)); 89 + 90 + val = 0; 91 + val2 = -500000000; 92 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_INT_PLUS_NANO, val, val2); 93 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 94 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * -5, 10)); 95 + } 96 + 97 + static void iio_test_iio_multiply_value_fixedpoint(struct kunit *test) 98 + { 99 + __iio_test_iio_multiply_value_fixedpoint(test, 20); 100 + __iio_test_iio_multiply_value_fixedpoint(test, -20); 101 + } 102 + 103 + static void __iio_test_iio_multiply_value_fractional(struct kunit *test, s64 multiplier) 104 + { 105 + int ret, result, val, val2; 106 + 107 + /* positive < 1 (1/10)*/ 108 + val = 1; 109 + val2 = 10; 110 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_FRACTIONAL, val, val2); 111 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 112 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * val, val2)); 113 + 114 + /* positive >= 1 (100/3)*/ 115 + val = 100; 116 + val2 = 3; 117 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_FRACTIONAL, val, val2); 118 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 119 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * val, val2)); 120 + 121 + /* negative > -1 (-1/10) */ 122 + val = -1; 123 + val2 = 10; 124 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_FRACTIONAL, val, val2); 125 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 126 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * val, val2)); 127 + 128 + /* negative <= -1 (-200/3)*/ 129 + val = -200; 130 + val2 = 3; 131 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_FRACTIONAL, val, val2); 132 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 133 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * val, val2)); 134 + 135 + /* Zero (0/-10) */ 136 + val = 0; 137 + val2 = -10; 138 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_FRACTIONAL, val, val2); 139 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 140 + KUNIT_EXPECT_EQ(test, result, div_s64(multiplier * val, val2)); 141 + } 142 + 143 + static void iio_test_iio_multiply_value_fractional(struct kunit *test) 144 + { 145 + __iio_test_iio_multiply_value_fractional(test, 20); 146 + __iio_test_iio_multiply_value_fractional(test, -20); 147 + } 148 + 149 + static void __iio_test_iio_multiply_value_fractional_log2(struct kunit *test, s64 multiplier) 150 + { 151 + int ret, result, val, val2; 152 + 153 + /* positive < 1 (123/1024) */ 154 + val = 123; 155 + val2 = 10; 156 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_FRACTIONAL_LOG2, val, val2); 157 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 158 + KUNIT_EXPECT_EQ(test, result, (multiplier * val) >> val2); 159 + 160 + /* positive >= 1 (1234567/1024) */ 161 + val = 1234567; 162 + val2 = 10; 163 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_FRACTIONAL_LOG2, val, val2); 164 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 165 + KUNIT_EXPECT_EQ(test, result, (multiplier * val) >> val2); 166 + 167 + /* negative > -1 (-123/1024) */ 168 + val = -123; 169 + val2 = 10; 170 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_FRACTIONAL_LOG2, val, val2); 171 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 172 + KUNIT_EXPECT_EQ(test, result, (multiplier * val) >> val2); 173 + 174 + /* negative <= -1 (-1234567/1024) */ 175 + val = -1234567; 176 + val2 = 10; 177 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_FRACTIONAL_LOG2, val, val2); 178 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 179 + KUNIT_EXPECT_EQ(test, result, (multiplier * val) >> val2); 180 + 181 + /* Zero (0/1024) */ 182 + val = 0; 183 + val2 = 10; 184 + ret = iio_multiply_value(&result, multiplier, IIO_VAL_FRACTIONAL_LOG2, val, val2); 185 + KUNIT_EXPECT_EQ(test, ret, IIO_VAL_INT); 186 + KUNIT_EXPECT_EQ(test, result, (multiplier * val) >> val2); 187 + } 188 + 189 + static void iio_test_iio_multiply_value_fractional_log2(struct kunit *test) 190 + { 191 + __iio_test_iio_multiply_value_fractional_log2(test, 20); 192 + __iio_test_iio_multiply_value_fractional_log2(test, -20); 193 + } 194 + 195 + static struct kunit_case iio_multiply_test_cases[] = { 196 + KUNIT_CASE(iio_test_iio_multiply_value_integer), 197 + KUNIT_CASE(iio_test_iio_multiply_value_fixedpoint), 198 + KUNIT_CASE(iio_test_iio_multiply_value_fractional), 199 + KUNIT_CASE(iio_test_iio_multiply_value_fractional_log2), 200 + { } 201 + }; 202 + 203 + static struct kunit_suite iio_multiply_test_suite = { 204 + .name = "iio-multiply", 205 + .test_cases = iio_multiply_test_cases, 206 + }; 207 + kunit_test_suite(iio_multiply_test_suite); 208 + 209 + MODULE_AUTHOR("Hans de Goede <hans@hansg.org>"); 210 + MODULE_DESCRIPTION("Test IIO multiply functions"); 211 + MODULE_LICENSE("GPL"); 212 + MODULE_IMPORT_NS("IIO_UNIT_TEST");
-2
drivers/staging/iio/adc/ad7816.c
··· 359 359 if (!indio_dev) 360 360 return -ENOMEM; 361 361 chip = iio_priv(indio_dev); 362 - /* this is only used for device removal purposes */ 363 - dev_set_drvdata(&spi_dev->dev, indio_dev); 364 362 365 363 chip->spi_dev = spi_dev; 366 364 for (i = 0; i <= AD7816_CS_MAX; i++)
+18
include/linux/iio/consumer.h
··· 382 382 int *val2); 383 383 384 384 /** 385 + * iio_multiply_value() - Multiply an IIO value 386 + * @result: Destination pointer for the multiplication result 387 + * @multiplier: Multiplier. 388 + * @type: One of the IIO_VAL_* constants. This decides how the @val and 389 + * @val2 parameters are interpreted. 390 + * @val: Value being multiplied. 391 + * @val2: Value being multiplied. @val2 use depends on type. 392 + * 393 + * Multiply an IIO value with a s64 multiplier storing the result as 394 + * IIO_VAL_INT. This is typically used for scaling. 395 + * 396 + * Returns: 397 + * IIO_VAL_INT on success or a negative error-number on failure. 398 + */ 399 + int iio_multiply_value(int *result, s64 multiplier, 400 + unsigned int type, int val, int val2); 401 + 402 + /** 385 403 * iio_convert_raw_to_processed() - Converts a raw value to a processed value 386 404 * @chan: The channel being queried 387 405 * @raw: The raw IIO to convert
+10 -10
include/linux/iio/iio.h
··· 271 271 unsigned int num_ext_scan_type; 272 272 }; 273 273 }; 274 - long info_mask_separate; 275 - long info_mask_separate_available; 276 - long info_mask_shared_by_type; 277 - long info_mask_shared_by_type_available; 278 - long info_mask_shared_by_dir; 279 - long info_mask_shared_by_dir_available; 280 - long info_mask_shared_by_all; 281 - long info_mask_shared_by_all_available; 274 + unsigned long info_mask_separate; 275 + unsigned long info_mask_separate_available; 276 + unsigned long info_mask_shared_by_type; 277 + unsigned long info_mask_shared_by_type_available; 278 + unsigned long info_mask_shared_by_dir; 279 + unsigned long info_mask_shared_by_dir_available; 280 + unsigned long info_mask_shared_by_all; 281 + unsigned long info_mask_shared_by_all_available; 282 282 const struct iio_event_spec *event_spec; 283 283 unsigned int num_event_specs; 284 284 const struct iio_chan_spec_ext_info *ext_info; ··· 779 779 * them safe for use with non-coherent DMA. 780 780 * 781 781 * A number of drivers also use this on buffers that include a 64-bit timestamp 782 - * that is used with iio_push_to_buffer_with_ts(). Therefore, in the case where 782 + * that is used with iio_push_to_buffers_with_ts(). Therefore, in the case where 783 783 * DMA alignment is not sufficient for proper timestamp alignment, we align to 784 784 * 8 bytes instead. 785 785 */ ··· 794 794 * @name: identifier name of the buffer 795 795 * @count: number of elements in the buffer 796 796 * 797 - * Declares a buffer that is safe to use with iio_push_to_buffer_with_ts(). In 797 + * Declares a buffer that is safe to use with iio_push_to_buffers_with_ts(). In 798 798 * addition to allocating enough space for @count elements of @type, it also 799 799 * allocates space for a s64 timestamp at the end of the buffer and ensures 800 800 * proper alignment of the timestamp.
+1
include/linux/iio/types.h
··· 70 70 IIO_CHAN_INFO_ZEROPOINT, 71 71 IIO_CHAN_INFO_TROUGH, 72 72 IIO_CHAN_INFO_CONVDELAY, 73 + IIO_CHAN_INFO_POWERFACTOR, 73 74 }; 74 75 75 76 #endif /* _IIO_TYPES_H_ */
+58
include/linux/mfd/88pm886.h
··· 10 10 #define PM886_IRQ_ONKEY 0 11 11 12 12 #define PM886_PAGE_OFFSET_REGULATORS 1 13 + #define PM886_PAGE_OFFSET_GPADC 2 13 14 14 15 #define PM886_REG_ID 0x00 15 16 ··· 70 69 71 70 #define PM886_LDO_VSEL_MASK 0x0f 72 71 #define PM886_BUCK_VSEL_MASK 0x7f 72 + 73 + /* GPADC enable/disable registers */ 74 + #define PM886_REG_GPADC_CONFIG(n) (n) 75 + 76 + #define PM886_GPADC_VSC_EN BIT(0) 77 + #define PM886_GPADC_VBAT_EN BIT(1) 78 + #define PM886_GPADC_GNDDET1_EN BIT(3) 79 + #define PM886_GPADC_VBUS_EN BIT(4) 80 + #define PM886_GPADC_VCHG_PWR_EN BIT(5) 81 + #define PM886_GPADC_VCF_OUT_EN BIT(6) 82 + #define PM886_GPADC_CONFIG1_EN_ALL \ 83 + (PM886_GPADC_VSC_EN | \ 84 + PM886_GPADC_VBAT_EN | \ 85 + PM886_GPADC_GNDDET1_EN | \ 86 + PM886_GPADC_VBUS_EN | \ 87 + PM886_GPADC_VCHG_PWR_EN | \ 88 + PM886_GPADC_VCF_OUT_EN) 89 + 90 + #define PM886_GPADC_TINT_EN BIT(0) 91 + #define PM886_GPADC_PMODE_EN BIT(1) 92 + #define PM886_GPADC_GPADC0_EN BIT(2) 93 + #define PM886_GPADC_GPADC1_EN BIT(3) 94 + #define PM886_GPADC_GPADC2_EN BIT(4) 95 + #define PM886_GPADC_GPADC3_EN BIT(5) 96 + #define PM886_GPADC_MIC_DET_EN BIT(6) 97 + #define PM886_GPADC_CONFIG2_EN_ALL \ 98 + (PM886_GPADC_TINT_EN | \ 99 + PM886_GPADC_GPADC0_EN | \ 100 + PM886_GPADC_GPADC1_EN | \ 101 + PM886_GPADC_GPADC2_EN | \ 102 + PM886_GPADC_GPADC3_EN | \ 103 + PM886_GPADC_MIC_DET_EN) 104 + 105 + /* No CONFIG3_EN_ALL because this is the only bit there. */ 106 + #define PM886_GPADC_GND_DET2_EN BIT(0) 107 + 108 + /* GPADC channel registers */ 109 + #define PM886_REG_GPADC_VSC 0x40 110 + #define PM886_REG_GPADC_VCHG_PWR 0x4c 111 + #define PM886_REG_GPADC_VCF_OUT 0x4e 112 + #define PM886_REG_GPADC_TINT 0x50 113 + #define PM886_REG_GPADC_GPADC0 0x54 114 + #define PM886_REG_GPADC_GPADC1 0x56 115 + #define PM886_REG_GPADC_GPADC2 0x58 116 + #define PM886_REG_GPADC_VBAT 0xa0 117 + #define PM886_REG_GPADC_GND_DET1 0xa4 118 + #define PM886_REG_GPADC_GND_DET2 0xa6 119 + #define PM886_REG_GPADC_VBUS 0xa8 120 + #define PM886_REG_GPADC_GPADC3 0xaa 121 + #define PM886_REG_GPADC_MIC_DET 0xac 122 + #define PM886_REG_GPADC_VBAT_SLP 0xb0 123 + 124 + /* VBAT_SLP is the last register and is 2 bytes wide like other channels. */ 125 + #define PM886_GPADC_MAX_REGISTER (PM886_REG_GPADC_VBAT_SLP + 1) 126 + 127 + #define PM886_GPADC_BIAS_LEVELS 16 128 + #define PM886_GPADC_INDEX_TO_BIAS_uA(i) (1 + (i) * 5) 73 129 74 130 struct pm886_chip { 75 131 struct i2c_client *client;
-22
include/linux/platform_data/touchscreen-s3c2410.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (c) 2005 Arnaud Patard <arnaud.patard@rtp-net.org> 4 - */ 5 - 6 - #ifndef __TOUCHSCREEN_S3C2410_H 7 - #define __TOUCHSCREEN_S3C2410_H 8 - 9 - struct s3c2410_ts_mach_info { 10 - int delay; 11 - int presc; 12 - int oversampling_shift; 13 - void (*cfg_gpio)(struct platform_device *dev); 14 - }; 15 - 16 - extern void s3c24xx_ts_set_platdata(struct s3c2410_ts_mach_info *); 17 - extern void s3c64xx_ts_set_platdata(struct s3c2410_ts_mach_info *); 18 - 19 - /* defined by architecture to configure gpio */ 20 - extern void s3c24xx_ts_cfg_gpio(struct platform_device *dev); 21 - 22 - #endif /*__TOUCHSCREEN_S3C2410_H */
+5
include/uapi/linux/iio/types.h
··· 52 52 IIO_COLORTEMP, 53 53 IIO_CHROMATICITY, 54 54 IIO_ATTENTION, 55 + IIO_ALTCURRENT, 55 56 }; 56 57 57 58 enum iio_modifier { ··· 109 108 IIO_MOD_ROLL, 110 109 IIO_MOD_LIGHT_UVA, 111 110 IIO_MOD_LIGHT_UVB, 111 + IIO_MOD_RMS, 112 + IIO_MOD_ACTIVE, 113 + IIO_MOD_REACTIVE, 114 + IIO_MOD_APPARENT, 112 115 }; 113 116 114 117 enum iio_event_type {
+10
tools/iio/iio_event_monitor.c
··· 64 64 [IIO_COLORTEMP] = "colortemp", 65 65 [IIO_CHROMATICITY] = "chromaticity", 66 66 [IIO_ATTENTION] = "attention", 67 + [IIO_ALTCURRENT] = "altcurrent", 67 68 }; 68 69 69 70 static const char * const iio_ev_type_text[] = { ··· 141 140 [IIO_MOD_PITCH] = "pitch", 142 141 [IIO_MOD_YAW] = "yaw", 143 142 [IIO_MOD_ROLL] = "roll", 143 + [IIO_MOD_RMS] = "rms", 144 + [IIO_MOD_ACTIVE] = "active", 145 + [IIO_MOD_REACTIVE] = "reactive", 146 + [IIO_MOD_APPARENT] = "apparent", 144 147 }; 145 148 146 149 static bool event_is_known(struct iio_event_data *event) ··· 192 187 case IIO_COLORTEMP: 193 188 case IIO_CHROMATICITY: 194 189 case IIO_ATTENTION: 190 + case IIO_ALTCURRENT: 195 191 break; 196 192 default: 197 193 return false; ··· 244 238 case IIO_MOD_PM4: 245 239 case IIO_MOD_PM10: 246 240 case IIO_MOD_O2: 241 + case IIO_MOD_RMS: 242 + case IIO_MOD_ACTIVE: 243 + case IIO_MOD_REACTIVE: 244 + case IIO_MOD_APPARENT: 247 245 break; 248 246 default: 249 247 return false;