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

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

Jonathan writes:

1st set of IIO new device support, features and cleanup for 6.1

This includes Nuno Sa's work to move the IIO core over to generic firmware
properties rather than having DT specific code paths. Combined with Andy
Shevchenko's long term work on drivers, this leaves IIO in a good state for
handling other firmware types.

New device support
- liteon,ltrf216a
* New driver and dt bindings to support this Light sensor.
- maxim,max11205
* New driver for this 16bit single channel ADC.
- memsensing,msa311
* New driver for this accelerometer. Includes a string helper for read/write.
- richtek,rtq6056
* New driver and dt binding to support this current monitor used to measure
power usage.
- yamaha,yas530
* Support the YAS537 variant (series includes several fixes for other parts
and new driver features).

Staging graduation
- adi,ad7746 CDC. Cleanup conducted against set of roadtest tests using
the posted RFC of that framework.

Features
- core
* Large rework to make all the core IIO code use generic firmware properties.
Includes switching some drivers over as well using newly provided
generic interfaces and allowing removal of DT specific ones.
* Support for gesture event types for single and double tap. Used in
bosch,bma400.
- atmel,at91-sama5d2
* Add support for temperature sensor which uses two muxed inputs to estimate
the temperature.
* Handle trackx bits of EMR register to improve temp sampling accuracy.
* Runtime PM support.
- liteon,ltrf216a
* Add a _raw channel output to allow working around an issue with
differing conversions equations that breaks some user space controls.
- mexelis,mlx90632
* Support regulator control.
- ti,tsc2046
* External reference voltage support.

Clean up and minor fixes
- Tree-wide
* devm_clk_get_enabled() replacements of opencoded equivalent.
* Remaining IIO_DMA_MINALIGN conversions (the staging/iio drivers).
* Various minor warning and similar cleanup such as missing static
markings.
* strlcpy() to strscpy() for cases where return value not checked.
* provide units.h entries for more HZ units and use them in drivers.
- dt-bindings cleanup
* Drop maintainers listss where the email address is bouncing.
* Switch spi devices over to using spi-peripheral.yaml
* Add some missing unevaluatedProperties / additionalProperties: false
entries.
- ABI docs
* Add some missing channel type specific sampling frequency entries.
* Add parameter names for callback parameters.
- MAINTAINERS
* Fix wrong ADI forum links.
- core
* lockdep class per device, to avoid an issue with nest when one IIO
device is the consumer of another.
* White space tweaks.
- asc,dlhl60d
* Use get_unaligned_be24 to avoid some unusual data manipulation and masking.
- atmel,at91-sama5d2
* Fix wrong max value.
* Improve error handling when measuring pressure and touch.
* Add locks to remove races on updating oversampling / sampling freq.
* Add missing calls in suspend and resume path to ensure state is correctly
brought up if buffered capture was in use when suspend happened.
* Error out of write_raw() callback if buffered capture enabled to avoid
unpredictable behavior.
* Handle different versions having different oversampling ratio support and
drop excess error checking.
* Cleanup magic value defines where the name is just the value and hence
hurts readability.
* Use read_avail() callback to provide info on possible oversampling ratios.
* Correctly handle variable bit depth when doing oversampling on different
supported parts. Also handle higher oversampling ratios.
- fsl,imx8qxp
* Don't ignore errors from regulator_get_voltage() so as to avoid some
very surprising scaling.
- invensense,icp10100
* Switch from UNIVERSAL to DEFINE_RUNTIME_DEV_PM_OPS. UNIVERSAL rarely made
sense and is now deprecated. In this driver we just avoid double disabling
in some paths.
- maxim,max1363
* Drop consumer channel map provision by platform data. There have been
better ways of doing this for years and there are no in tree users.
- microchip,mcp3911
* Update status to maintained.
- qcom,spmi-adc5
* Support measurement of LDO output voltage.
- qcom,spmi-adc
* Add missing channel available on SM6125 SoC.
- st,stmpe
* Drop requirement on node name in binding now that driver correctly
doesn't enforce it.
- stx104
* Move to more appropriate addac directory
- ti,am335x
* Document ti,am654-adc compatible already in use in tree.
- ti,hmc5843
* Move dev_pm_ops out of header and use new pm macros to handle export.
- yamaha,yas530
* Minor cleanups.

* tag 'iio-for-6.1a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (142 commits)
iio: pressure: icp10100: Switch from UNIVERSAL to DEFINE_RUNTIME_DEV_PM_OPS().
iio: adc: max1363: Drop provision to provide an IIO channel map via platform data
iio: accel: bma400: Add support for single and double tap events
iio: Add new event type gesture and use direction for single and double tap
iio: Use per-device lockdep class for mlock
iio: adc: add max11205 adc driver
dt-bindings: iio: adc: Add max11205 documentation file
iio: magnetometer: yamaha-yas530: Use dev_err_probe()
iio: magnetometer: yamaha-yas530: Make strings const in chip info
iio: magnetometer: yamaha-yas530: Use pointers as driver data
iio: adc: tsc2046: silent spi_device_id warning
iio: adc: tsc2046: add vref support
dt-bindings: iio: adc: ti,tsc2046: add vref-supply property
iio: light: ltrf216a: Add raw attribute
dt-bindings: iio: Add missing (unevaluated|additional)Properties on child nodes
MAINTAINERS: fix Analog Devices forum links
iio/accel: fix repeated words in comments
dt-bindings: iio: accel: add dt-binding schema for msa311 accel driver
iio: add MEMSensing MSA311 3-axis accelerometer driver
dt-bindings: vendor-prefixes: add MEMSensing Microsystems Co., Ltd.
...

+5988 -1349
+100 -1
Documentation/ABI/testing/sysfs-bus-iio
··· 196 196 Raw capacitance measurement from channel Y. Units after 197 197 application of scale and offset are nanofarads. 198 198 199 - What: /sys/.../iio:deviceX/in_capacitanceY-in_capacitanceZ_raw 199 + What: /sys/.../iio:deviceX/in_capacitanceY-capacitanceZ_raw 200 200 KernelVersion: 3.2 201 201 Contact: linux-iio@vger.kernel.org 202 202 Description: ··· 206 206 separately available. In differential only parts, then all that 207 207 is required is a consistent labeling. Units after application 208 208 of scale and offset are nanofarads. 209 + 210 + What: /sys/.../iio:deviceX/in_capacitanceY-capacitanceZ_zeropoint 211 + KernelVersion: 6.1 212 + Contact: linux-iio@vger.kernel.org 213 + Description: 214 + For differential channels, this an offset that is applied 215 + equally to both inputs. As the reading is of the difference 216 + between the two inputs, this should not be applied to the _raw 217 + reading by userspace (unlike _offset) and unlike calibbias 218 + it does not affect the differential value measured because 219 + the effect of _zeropoint cancels out across the two inputs 220 + that make up the differential pair. It's purpose is to bring 221 + the individual signals, before the differential is measured, 222 + within the measurement range of the device. The naming is 223 + chosen because if the separate inputs that make the 224 + differential pair are drawn on a graph in their 225 + _raw units, this is the value that the zero point on the 226 + measurement axis represents. It is expressed with the 227 + same scaling as _raw. 209 228 210 229 What: /sys/bus/iio/devices/iio:deviceX/in_temp_raw 211 230 What: /sys/bus/iio/devices/iio:deviceX/in_tempX_raw ··· 2057 2038 Available range for the forced calibration value, expressed as: 2058 2039 2059 2040 - a range specified as "[min step max]" 2041 + 2042 + What: /sys/bus/iio/devices/iio:deviceX/in_voltageX_sampling_frequency 2043 + What: /sys/bus/iio/devices/iio:deviceX/in_powerY_sampling_frequency 2044 + What: /sys/bus/iio/devices/iio:deviceX/in_currentZ_sampling_frequency 2045 + KernelVersion: 5.20 2046 + Contact: linux-iio@vger.kernel.org 2047 + Description: 2048 + Some devices have separate controls of sampling frequency for 2049 + individual channels. If multiple channels are enabled in a scan, 2050 + then the sampling_frequency of the scan may be computed from the 2051 + per channel sampling frequencies. 2052 + 2053 + What: /sys/.../events/in_accel_gesture_singletap_en 2054 + What: /sys/.../events/in_accel_gesture_doubletap_en 2055 + KernelVersion: 6.1 2056 + Contact: linux-iio@vger.kernel.org 2057 + Description: 2058 + Device generates an event on a single or double tap. 2059 + 2060 + What: /sys/.../events/in_accel_gesture_singletap_value 2061 + What: /sys/.../events/in_accel_gesture_doubletap_value 2062 + KernelVersion: 6.1 2063 + Contact: linux-iio@vger.kernel.org 2064 + Description: 2065 + Specifies the threshold value that the device is comparing 2066 + against to generate the tap gesture event. The lower 2067 + threshold value increases the sensitivity of tap detection. 2068 + Units and the exact meaning of value are device-specific. 2069 + 2070 + What: /sys/.../events/in_accel_gesture_tap_value_available 2071 + KernelVersion: 6.1 2072 + Contact: linux-iio@vger.kernel.org 2073 + Description: 2074 + Lists all available threshold values which can be used to 2075 + modify the sensitivity of the tap detection. 2076 + 2077 + What: /sys/.../events/in_accel_gesture_singletap_reset_timeout 2078 + What: /sys/.../events/in_accel_gesture_doubletap_reset_timeout 2079 + KernelVersion: 6.1 2080 + Contact: linux-iio@vger.kernel.org 2081 + Description: 2082 + Specifies the timeout value in seconds for the tap detector 2083 + to not to look for another tap event after the event as 2084 + occurred. Basically the minimum quiet time between the two 2085 + single-tap's or two double-tap's. 2086 + 2087 + What: /sys/.../events/in_accel_gesture_tap_reset_timeout_available 2088 + KernelVersion: 6.1 2089 + Contact: linux-iio@vger.kernel.org 2090 + Description: 2091 + Lists all available tap reset timeout values. Units in seconds. 2092 + 2093 + What: /sys/.../events/in_accel_gesture_doubletap_tap2_min_delay 2094 + KernelVersion: 6.1 2095 + Contact: linux-iio@vger.kernel.org 2096 + Description: 2097 + Specifies the minimum quiet time in seconds between the two 2098 + taps of a double tap. 2099 + 2100 + What: /sys/.../events/in_accel_gesture_doubletap_tap2_min_delay_available 2101 + KernelVersion: 6.1 2102 + Contact: linux-iio@vger.kernel.org 2103 + Description: 2104 + Lists all available delay values between two taps in the double 2105 + tap. Units in seconds. 2106 + 2107 + What: /sys/.../events/in_accel_gesture_tap_maxtomin_time 2108 + KernelVersion: 6.1 2109 + Contact: linux-iio@vger.kernel.org 2110 + Description: 2111 + Specifies the maximum time difference allowed between upper 2112 + and lower peak of tap to consider it as the valid tap event. 2113 + Units in seconds. 2114 + 2115 + What: /sys/.../events/in_accel_gesture_tap_maxtomin_time_available 2116 + KernelVersion: 6.1 2117 + Contact: linux-iio@vger.kernel.org 2118 + Description: 2119 + Lists all available time values between upper peak to lower 2120 + peak. Units in seconds.
+11
Documentation/ABI/testing/sysfs-bus-iio-cdc-ad7746
··· 1 + What: /sys/.../iio:deviceX/in_capacitableY_calibbias_calibration 2 + What: /sys/.../iio:deviceX/in_capacitableY_calibscale_calibration 3 + KernelVersion: 6.1 4 + Contact: linux-iio@vger.kernel.org 5 + Description: 6 + Write 1 to trigger a calibration of the calibbias or 7 + calibscale. For calibscale, a full scale capacitance should 8 + be connected to the capacitance input and a 9 + calibscale_calibration then started. For calibbias see 10 + the device datasheet section on "capacitive system offset 11 + calibration".
+4 -3
Documentation/devicetree/bindings/iio/accel/adi,adis16201.yaml
··· 27 27 interrupts: 28 28 maxItems: 1 29 29 30 - spi-max-frequency: true 31 - 32 30 vdd-supply: true 33 31 34 32 required: 35 33 - compatible 36 34 - reg 37 35 38 - additionalProperties: false 36 + allOf: 37 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 38 + 39 + unevaluatedProperties: false 39 40 40 41 examples: 41 42 - |
+4 -3
Documentation/devicetree/bindings/iio/accel/adi,adis16240.yaml
··· 25 25 interrupts: 26 26 maxItems: 1 27 27 28 - spi-max-frequency: true 29 - 30 28 required: 31 29 - compatible 32 30 - reg 33 31 - interrupts 34 32 35 - additionalProperties: false 33 + allOf: 34 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 35 + 36 + unevaluatedProperties: false 36 37 37 38 examples: 38 39 - |
+4 -3
Documentation/devicetree/bindings/iio/accel/adi,adxl313.yaml
··· 24 24 25 25 spi-3wire: true 26 26 27 - spi-max-frequency: true 28 - 29 27 vs-supply: 30 28 description: Regulator that supplies power to the accelerometer 31 29 ··· 46 48 - compatible 47 49 - reg 48 50 49 - additionalProperties: false 51 + allOf: 52 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 53 + 54 + unevaluatedProperties: false 50 55 51 56 examples: 52 57 - |
+4 -3
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml
··· 32 32 33 33 spi-cpol: true 34 34 35 - spi-max-frequency: true 36 - 37 35 interrupts: 38 36 maxItems: 1 39 37 ··· 40 42 - reg 41 43 - interrupts 42 44 43 - additionalProperties: false 45 + allOf: 46 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 47 + 48 + unevaluatedProperties: false 44 49 45 50 examples: 46 51 - |
+4 -3
Documentation/devicetree/bindings/iio/accel/adi,adxl355.yaml
··· 45 45 vddio-supply: 46 46 description: Regulator that provides power to the bus 47 47 48 - spi-max-frequency: true 49 - 50 48 required: 51 49 - compatible 52 50 - reg 53 51 54 - additionalProperties: false 52 + allOf: 53 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 54 + 55 + unevaluatedProperties: false 55 56 56 57 examples: 57 58 - |
+4 -3
Documentation/devicetree/bindings/iio/accel/adi,adxl367.yaml
··· 35 35 interrupts: 36 36 maxItems: 1 37 37 38 - spi-max-frequency: true 39 - 40 38 vdd-supply: true 41 39 vddio-supply: true 42 40 ··· 43 45 - reg 44 46 - interrupts 45 47 46 - additionalProperties: false 48 + allOf: 49 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 50 + 51 + unevaluatedProperties: false 47 52 48 53 examples: 49 54 - |
+4 -3
Documentation/devicetree/bindings/iio/accel/adi,adxl372.yaml
··· 25 25 interrupts: 26 26 maxItems: 1 27 27 28 - spi-max-frequency: true 29 - 30 28 required: 31 29 - compatible 32 30 - reg 33 31 - interrupts 34 32 35 - additionalProperties: false 33 + allOf: 34 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 35 + 36 + unevaluatedProperties: false 36 37 37 38 examples: 38 39 - |
+4 -3
Documentation/devicetree/bindings/iio/accel/bosch,bma220.yaml
··· 20 20 interrupts: 21 21 maxItems: 1 22 22 23 - spi-max-frequency: true 24 - 25 23 vdda-supply: true 26 24 vddd-supply: true 27 25 vddio-supply: true ··· 28 30 - compatible 29 31 - reg 30 32 31 - additionalProperties: false 33 + allOf: 34 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 35 + 36 + unevaluatedProperties: false 32 37 33 38 examples: 34 39 - |
+4 -1
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml
··· 72 72 - compatible 73 73 - reg 74 74 75 - additionalProperties: false 75 + allOf: 76 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 77 + 78 + unevaluatedProperties: false 76 79 77 80 examples: 78 81 - |
+4 -3
Documentation/devicetree/bindings/iio/accel/bosch,bmi088.yaml
··· 24 24 reg: 25 25 maxItems: 1 26 26 27 - spi-max-frequency: true 28 - 29 27 vdd-supply: true 30 28 31 29 vddio-supply: true ··· 48 50 - compatible 49 51 - reg 50 52 51 - additionalProperties: false 53 + allOf: 54 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 55 + 56 + unevaluatedProperties: false 52 57 53 58 examples: 54 59 - |
+4 -3
Documentation/devicetree/bindings/iio/accel/fsl,mma7455.yaml
··· 39 39 - "INT1" 40 40 - "INT2" 41 41 42 - spi-max-frequency: true 43 - 44 42 required: 45 43 - compatible 46 44 - reg 47 45 48 - additionalProperties: false 46 + allOf: 47 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 48 + 49 + unevaluatedProperties: false 49 50 50 51 examples: 51 52 - |
+4 -3
Documentation/devicetree/bindings/iio/accel/kionix,kxsd9.yaml
··· 29 29 mount-matrix: 30 30 description: an optional 3x3 mounting rotation matrix. 31 31 32 - spi-max-frequency: true 33 - 34 32 required: 35 33 - compatible 36 34 - reg 37 35 38 - additionalProperties: false 36 + allOf: 37 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 38 + 39 + unevaluatedProperties: false 39 40 40 41 examples: 41 42 - |
+53
Documentation/devicetree/bindings/iio/accel/memsensing,msa311.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + 3 + %YAML 1.2 4 + --- 5 + $id: "http://devicetree.org/schemas/iio/accel/memsensing,msa311.yaml#" 6 + $schema: "http://devicetree.org/meta-schemas/core.yaml#" 7 + 8 + title: MEMSensing digital 3-Axis accelerometer 9 + 10 + maintainers: 11 + - Dmitry Rokosov <ddrokosov@sberdevices.ru> 12 + 13 + description: | 14 + MSA311 is a tri-axial, low-g accelerometer with I2C digital output for 15 + sensitivity consumer applications. It has dynamical user selectable full 16 + scales range of +-2g/+-4g/+-8g/+-16g and allows acceleration measurements 17 + with output data rates from 1Hz to 1000Hz. 18 + Datasheet can be found at following URL 19 + https://cdn-shop.adafruit.com/product-files/5309/MSA311-V1.1-ENG.pdf 20 + 21 + properties: 22 + compatible: 23 + const: memsensing,msa311 24 + 25 + reg: 26 + maxItems: 1 27 + 28 + interrupts: 29 + maxItems: 1 30 + 31 + vdd-supply: true 32 + 33 + required: 34 + - compatible 35 + - reg 36 + 37 + additionalProperties: false 38 + 39 + examples: 40 + - | 41 + #include <dt-bindings/interrupt-controller/irq.h> 42 + i2c { 43 + #address-cells = <1>; 44 + #size-cells = <0>; 45 + 46 + accelerometer@62 { 47 + compatible = "memsensing,msa311"; 48 + reg = <0x62>; 49 + interrupt-parent = <&gpio_intc>; 50 + interrupts = <29 IRQ_TYPE_EDGE_RISING>; 51 + vdd-supply = <&vcc_5v>; 52 + }; 53 + };
+4 -1
Documentation/devicetree/bindings/iio/accel/murata,sca3300.yaml
··· 29 29 - compatible 30 30 - reg 31 31 32 - additionalProperties: false 32 + allOf: 33 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 34 + 35 + unevaluatedProperties: false 33 36 34 37 examples: 35 38 - |
+4 -3
Documentation/devicetree/bindings/iio/accel/nxp,fxls8962af.yaml
··· 27 27 vdd-supply: 28 28 description: phandle to the regulator that provides power to the accelerometer 29 29 30 - spi-max-frequency: true 31 - 32 30 interrupts: 33 31 maxItems: 1 34 32 ··· 42 44 - compatible 43 45 - reg 44 46 45 - additionalProperties: false 47 + allOf: 48 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 49 + 50 + unevaluatedProperties: false 46 51 47 52 examples: 48 53 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
··· 52 52 avdd-supply: 53 53 description: avdd supply can be used as reference for conversion. 54 54 55 - spi-max-frequency: true 56 - 57 55 required: 58 56 - compatible 59 57 - reg ··· 104 106 105 107 additionalProperties: false 106 108 107 - additionalProperties: false 109 + allOf: 110 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 111 + 112 + unevaluatedProperties: false 108 113 109 114 examples: 110 115 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
··· 30 30 31 31 spi-cpha: true 32 32 33 - spi-max-frequency: true 34 - 35 33 clocks: 36 34 maxItems: 1 37 35 description: phandle to the master clock (mclk) ··· 92 94 - spi-cpol 93 95 - spi-cpha 94 96 95 - additionalProperties: false 97 + allOf: 98 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 99 + 100 + unevaluatedProperties: false 96 101 97 102 examples: 98 103 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/adi,ad7280a.yaml
··· 28 28 description: IRQ line for the ADC 29 29 maxItems: 1 30 30 31 - spi-max-frequency: true 32 - 33 31 adi,voltage-alert-last-chan: 34 32 $ref: /schemas/types.yaml#/definitions/uint32 35 33 description: ··· 53 55 - compatible 54 56 - reg 55 57 56 - additionalProperties: false 58 + allOf: 59 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 60 + 61 + unevaluatedProperties: false 57 62 58 63 examples: 59 64 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
··· 30 30 31 31 spi-cpha: true 32 32 33 - spi-max-frequency: true 34 - 35 33 '#address-cells': 36 34 const: 1 37 35 ··· 63 65 64 66 additionalProperties: true 65 67 66 - additionalProperties: false 68 + allOf: 69 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 70 + 71 + unevaluatedProperties: false 67 72 68 73 examples: 69 74 - |
+4 -2
Documentation/devicetree/bindings/iio/adc/adi,ad7298.yaml
··· 24 24 25 25 vref-supply: true 26 26 vdd-supply: true 27 - spi-max-frequency: true 28 27 29 28 required: 30 29 - compatible 31 30 - reg 32 31 33 - additionalProperties: false 32 + allOf: 33 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 34 + 35 + unevaluatedProperties: false 34 36 35 37 examples: 36 38 - |
+4 -4
Documentation/devicetree/bindings/iio/adc/adi,ad7476.yaml
··· 66 66 to the other supplies. Needed to be able to establish channel scaling 67 67 unless there is also an internal reference available (e.g. ad7091r) 68 68 69 - spi-max-frequency: true 70 - 71 69 adi,conversion-start-gpios: 72 70 description: A GPIO used to trigger the start of a conversion 73 71 maxItems: 1 ··· 74 76 - compatible 75 77 - reg 76 78 77 - additionalProperties: false 78 - 79 79 allOf: 80 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 81 + 80 82 # Devices where reference is vcc 81 83 - if: 82 84 properties: ··· 155 157 else: 156 158 properties: 157 159 adi,conversion-start-gpios: false 160 + 161 + unevaluatedProperties: false 158 162 159 163 examples: 160 164 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
··· 32 32 33 33 spi-cpol: true 34 34 35 - spi-max-frequency: true 36 - 37 35 avcc-supply: true 38 36 39 37 interrupts: ··· 103 105 - interrupts 104 106 - adi,conversion-start-gpios 105 107 106 - additionalProperties: false 108 + allOf: 109 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 110 + 111 + unevaluatedProperties: false 107 112 108 113 examples: 109 114 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml
··· 50 50 reset-gpios: 51 51 maxItems: 1 52 52 53 - spi-max-frequency: true 54 - 55 53 spi-cpol: true 56 54 57 55 spi-cpha: true ··· 86 88 - reg 87 89 additionalProperties: false 88 90 89 - additionalProperties: false 91 + allOf: 92 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 93 + 94 + unevaluatedProperties: false 90 95 91 96 examples: 92 97 - |
+4 -4
Documentation/devicetree/bindings/iio/adc/adi,ad7923.yaml
··· 8 8 9 9 maintainers: 10 10 - Michael Hennerich <michael.hennerich@analog.com> 11 - - Patrick Vasseur <patrick.vasseur@c-s.fr> 12 11 13 12 description: | 14 13 Analog Devices AD7904, AD7914, AD7923, AD7924 4 Channel ADCs, and AD7908, ··· 42 43 '#size-cells': 43 44 const: 0 44 45 45 - spi-max-frequency: true 46 - 47 46 required: 48 47 - compatible 49 48 - reg 50 49 51 - additionalProperties: false 50 + allOf: 51 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 52 + 53 + unevaluatedProperties: false 52 54 53 55 examples: 54 56 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/adi,ad7949.yaml
··· 49 49 default: 4096000 50 50 51 51 52 - spi-max-frequency: true 53 - 54 52 '#io-channel-cells': 55 53 const: 1 56 54 ··· 62 64 - compatible 63 65 - reg 64 66 65 - additionalProperties: false 67 + allOf: 68 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 69 + 70 + unevaluatedProperties: false 66 71 67 72 examples: 68 73 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/holt,hi8435.yaml
··· 24 24 GPIO used for controlling the reset pin 25 25 maxItems: 1 26 26 27 - spi-max-frequency: true 28 - 29 27 "#io-channel-cells": 30 28 const: 1 31 29 ··· 31 33 - compatible 32 34 - reg 33 35 34 - additionalProperties: false 36 + allOf: 37 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 38 + 39 + unevaluatedProperties: false 35 40 36 41 examples: 37 42 - |
+4 -4
Documentation/devicetree/bindings/iio/adc/lltc,ltc2496.yaml
··· 22 22 reg: 23 23 maxItems: 1 24 24 25 - spi-max-frequency: 26 - description: maximal spi bus frequency supported 27 - 28 25 required: 29 26 - compatible 30 27 - vref-supply 31 28 - reg 32 29 33 - additionalProperties: false 30 + allOf: 31 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 32 + 33 + unevaluatedProperties: false 34 34 35 35 examples: 36 36 - |
+4 -1
Documentation/devicetree/bindings/iio/adc/maxim,max1027.yaml
··· 45 45 - compatible 46 46 - reg 47 47 48 - additionalProperties: false 48 + allOf: 49 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 50 + 51 + unevaluatedProperties: false 49 52 50 53 examples: 51 54 - |
+5 -2
Documentation/devicetree/bindings/iio/adc/maxim,max11100.yaml
··· 26 26 minimum: 100000 27 27 maximum: 4800000 28 28 29 - additionalProperties: false 30 - 31 29 required: 32 30 - compatible 33 31 - reg 34 32 - vref-supply 33 + 34 + allOf: 35 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 36 + 37 + unevaluatedProperties: false 35 38 36 39 examples: 37 40 - |
+14 -12
Documentation/devicetree/bindings/iio/adc/maxim,max1118.yaml
··· 28 28 vref-supply: 29 29 description: External reference, needed to establish input scaling 30 30 31 - if: 32 - properties: 33 - compatible: 34 - contains: 35 - const: maxim,max1118 36 - then: 37 - required: 38 - - vref-supply 39 - else: 40 - properties: 41 - vref-supply: false 31 + allOf: 32 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 33 + - if: 34 + properties: 35 + compatible: 36 + contains: 37 + const: maxim,max1118 38 + then: 39 + required: 40 + - vref-supply 41 + else: 42 + properties: 43 + vref-supply: false 42 44 43 45 required: 44 46 - compatible 45 47 - reg 46 48 47 - additionalProperties: false 49 + unevaluatedProperties: false 48 50 49 51 examples: 50 52 - |
+69
Documentation/devicetree/bindings/iio/adc/maxim,max11205.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/adc/maxim,max11205.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Maxim MAX11205 ADC 8 + 9 + maintainers: 10 + - Ramona Bolboaca <ramona.bolboaca@analog.com> 11 + 12 + description: | 13 + The MAX11205 is an ultra-low-power (< 300FA max active current), 14 + high-resolution, serial-output ADC. 15 + 16 + https://datasheets.maximintegrated.com/en/ds/MAX11205.pdf 17 + 18 + allOf: 19 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 20 + 21 + properties: 22 + compatible: 23 + enum: 24 + - maxim,max11205a 25 + - maxim,max11205b 26 + 27 + reg: 28 + maxItems: 1 29 + 30 + interrupts: 31 + maxItems: 1 32 + 33 + spi-max-frequency: 34 + maximum: 5000000 35 + 36 + spi-cpha: true 37 + 38 + vref-supply: 39 + description: 40 + The regulator supply for the ADC reference voltage. This is a differential 41 + reference. It is equal to the V_REFP - V_REFN. The maximum value is 3.6V. 42 + 43 + required: 44 + - compatible 45 + - reg 46 + - interrupts 47 + - spi-max-frequency 48 + - spi-cpha 49 + - vref-supply 50 + 51 + unevaluatedProperties: false 52 + 53 + examples: 54 + - | 55 + #include <dt-bindings/interrupt-controller/irq.h> 56 + spi { 57 + #address-cells = <1>; 58 + #size-cells = <0>; 59 + adc@0 { 60 + compatible = "maxim,max11205a"; 61 + reg = <0>; 62 + spi-max-frequency = <5000000>; 63 + spi-cpha; 64 + interrupt-parent = <&gpio>; 65 + interrupts = <19 IRQ_TYPE_EDGE_FALLING>; 66 + vref-supply = <&max11205_vref>; 67 + }; 68 + }; 69 + ...
+4 -3
Documentation/devicetree/bindings/iio/adc/maxim,max1241.yaml
··· 39 39 thus enabling power-down mode. 40 40 maxItems: 1 41 41 42 - spi-max-frequency: true 43 - 44 42 required: 45 43 - compatible 46 44 - reg 47 45 - vdd-supply 48 46 - vref-supply 49 47 50 - additionalProperties: false 48 + allOf: 49 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 50 + 51 + unevaluatedProperties: false 51 52 52 53 examples: 53 54 - |
+4 -2
Documentation/devicetree/bindings/iio/adc/microchip,mcp3201.yaml
··· 32 32 reg: 33 33 maxItems: 1 34 34 35 - spi-max-frequency: true 36 35 spi-cpha: true 37 36 spi-cpol: true 38 37 ··· 50 51 - reg 51 52 - vref-supply 52 53 53 - additionalProperties: false 54 + allOf: 55 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 56 + 57 + unevaluatedProperties: false 54 58 55 59 examples: 56 60 - |
+4 -1
Documentation/devicetree/bindings/iio/adc/microchip,mcp3911.yaml
··· 51 51 - compatible 52 52 - reg 53 53 54 - additionalProperties: false 54 + allOf: 55 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 56 + 57 + unevaluatedProperties: false 55 58 56 59 examples: 57 60 - |
+1
Documentation/devicetree/bindings/iio/adc/qcom,spmi-vadc.yaml
··· 58 58 patternProperties: 59 59 "^.*@[0-9a-f]+$": 60 60 type: object 61 + additionalProperties: false 61 62 description: | 62 63 Represents the external channels which are connected to the ADC. 63 64 For compatible property "qcom,spmi-vadc" following channels, also known as
+56
Documentation/devicetree/bindings/iio/adc/richtek,rtq6056.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/adc/richtek,rtq6056.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: RTQ6056 Bi-Directional Current and Power Monitor with 16-bit ADC 8 + 9 + maintainers: 10 + - ChiYuan Huang <cy_huang@richtek.com> 11 + 12 + description: | 13 + The RTQ6056 is a high accuracy current-sense monitor with I2C and SMBus 14 + interface, and the device provides full information for system by reading 15 + out the loading current and power. 16 + 17 + The device monitors both of the drops across sense resistor and the BUS 18 + voltage, converts into the current in amperes, and power in watts through 19 + internal analog-to-digital converter ADC. The programmable calibration, 20 + adjustable conversion time, and averaging function are also built in for 21 + more design flexibility. 22 + 23 + Datasheet is available at 24 + https://www.richtek.com/assets/product_file/RTQ6056/DSQ6056-00.pdf 25 + 26 + properties: 27 + compatible: 28 + const: richtek,rtq6056 29 + 30 + reg: 31 + maxItems: 1 32 + 33 + "#io-channel-cells": 34 + const: 1 35 + 36 + shunt-resistor-micro-ohms: 37 + description: Shunt IN+/IN- sensing node resistor 38 + 39 + required: 40 + - compatible 41 + - reg 42 + - "#io-channel-cells" 43 + 44 + additionalProperties: false 45 + 46 + examples: 47 + - | 48 + i2c { 49 + #address-cells = <1>; 50 + #size-cells = <0>; 51 + adc@40 { 52 + compatible = "richtek,rtq6056"; 53 + reg = <0x40>; 54 + #io-channel-cells = <1>; 55 + }; 56 + };
+2
Documentation/devicetree/bindings/iio/adc/st,stm32-dfsdm-adc.yaml
··· 72 72 patternProperties: 73 73 "^filter@[0-9]+$": 74 74 type: object 75 + unevaluatedProperties: false 75 76 description: child node 76 77 77 78 properties: ··· 226 225 patternProperties: 227 226 "^dfsdm-dai+$": 228 227 type: object 228 + additionalProperties: false 229 229 description: child node 230 230 231 231 properties:
+1 -2
Documentation/devicetree/bindings/iio/adc/st,stmpe-adc.yaml
··· 13 13 This ADC forms part of an ST microelectronics STMPE multifunction device . 14 14 The ADC is shared with the STMPE touchscreen. As a result some ADC related 15 15 settings are specified in the parent node. 16 - The node name myst be stmpe_adc and should be a child node of the stmpe node 17 - to which it belongs. 16 + The node should be a child node of the stmpe node to which it belongs. 18 17 19 18 properties: 20 19 compatible:
+4 -3
Documentation/devicetree/bindings/iio/adc/ti,adc0832.yaml
··· 24 24 reg: 25 25 maxItems: 1 26 26 27 - spi-max-frequency: true 28 - 29 27 vref-supply: 30 28 description: External reference, needed to establish input scaling 31 29 ··· 35 37 - reg 36 38 - vref-supply 37 39 38 - additionalProperties: false 40 + allOf: 41 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 42 + 43 + unevaluatedProperties: false 39 44 40 45 examples: 41 46 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/ti,adc084s021.yaml
··· 19 19 reg: 20 20 maxItems: 1 21 21 22 - spi-max-frequency: true 23 - 24 22 vref-supply: 25 23 description: External reference, needed to establish input scaling 26 24 ··· 35 37 - spi-cpol 36 38 - spi-cpha 37 39 38 - additionalProperties: false 40 + allOf: 41 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 42 + 43 + unevaluatedProperties: false 39 44 40 45 examples: 41 46 - |
+4 -2
Documentation/devicetree/bindings/iio/adc/ti,adc108s102.yaml
··· 19 19 20 20 reg: true 21 21 vref-supply: true 22 - spi-max-frequency: true 23 22 "#io-channel-cells": 24 23 const: 1 25 24 ··· 27 28 - reg 28 29 - vref-supply 29 30 30 - additionalProperties: false 31 + allOf: 32 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 33 + 34 + unevaluatedProperties: false 31 35 32 36 examples: 33 37 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/ti,adc12138.yaml
··· 31 31 maxItems: 1 32 32 description: Conversion clock input. 33 33 34 - spi-max-frequency: true 35 - 36 34 vref-p-supply: 37 35 description: The regulator supply for positive analog voltage reference 38 36 ··· 60 62 - clocks 61 63 - vref-p-supply 62 64 63 - additionalProperties: false 65 + allOf: 66 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 67 + 68 + unevaluatedProperties: false 64 69 65 70 examples: 66 71 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/ti,adc128s052.yaml
··· 27 27 reg: 28 28 maxItems: 1 29 29 30 - spi-max-frequency: true 31 - 32 30 vref-supply: true 33 31 34 32 "#io-channel-cells": ··· 37 39 - reg 38 40 - vref-supply 39 41 40 - additionalProperties: false 42 + allOf: 43 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 44 + 45 + unevaluatedProperties: false 41 46 42 47 examples: 43 48 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/ti,adc161s626.yaml
··· 21 21 reg: 22 22 maxItems: 1 23 23 24 - spi-max-frequency: true 25 - 26 24 vdda-supply: true 27 25 28 26 "#io-channel-cells": ··· 30 32 - compatible 31 33 - reg 32 34 33 - additionalProperties: false 35 + allOf: 36 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 37 + 38 + unevaluatedProperties: false 34 39 35 40 examples: 36 41 - |
+1
Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml
··· 43 43 patternProperties: 44 44 "^channel@[0-7]+$": 45 45 type: object 46 + additionalProperties: false 46 47 description: 47 48 Child nodes needed for each channel that the platform uses. 48 49
+4 -3
Documentation/devicetree/bindings/iio/adc/ti,ads124s08.yaml
··· 18 18 reg: 19 19 maxItems: 1 20 20 21 - spi-max-frequency: true 22 - 23 21 spi-cpha: true 24 22 25 23 reset-gpios: ··· 30 32 - compatible 31 33 - reg 32 34 33 - additionalProperties: false 35 + allOf: 36 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 37 + 38 + unevaluatedProperties: false 34 39 35 40 examples: 36 41 - |
+5 -4
Documentation/devicetree/bindings/iio/adc/ti,ads131e08.yaml
··· 7 7 title: Texas Instruments ADS131E0x 4-, 6- and 8-Channel ADCs 8 8 9 9 maintainers: 10 - - Tomislav Denis <tomislav.denis@avl.com> 10 + - Jonathan Cameron <jic23@kernel.org> 11 11 12 12 description: | 13 13 The ADS131E0x are a family of multichannel, simultaneous sampling, ··· 27 27 28 28 reg: 29 29 maxItems: 1 30 - 31 - spi-max-frequency: true 32 30 33 31 spi-cpha: true 34 32 ··· 118 120 119 121 additionalProperties: false 120 122 121 - additionalProperties: false 123 + allOf: 124 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 125 + 126 + unevaluatedProperties: false 122 127 123 128 examples: 124 129 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/ti,ads8344.yaml
··· 19 19 reg: 20 20 maxItems: 1 21 21 22 - spi-max-frequency: true 23 - 24 22 vref-supply: 25 23 description: Supply the 2.5V or 5V reference voltage 26 24 ··· 30 32 - reg 31 33 - vref-supply 32 34 33 - additionalProperties: false 35 + allOf: 36 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 37 + 38 + unevaluatedProperties: false 34 39 35 40 examples: 36 41 - |
+4 -3
Documentation/devicetree/bindings/iio/adc/ti,ads8688.yaml
··· 25 25 description: Optional external reference. If not supplied, assume 26 26 REFSEL input tied low to enable the internal reference. 27 27 28 - spi-max-frequency: true 29 - 30 28 required: 31 29 - compatible 32 30 - reg 33 31 34 - additionalProperties: false 32 + allOf: 33 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 34 + 35 + unevaluatedProperties: false 35 36 36 37 examples: 37 38 - |
+8 -3
Documentation/devicetree/bindings/iio/adc/ti,am3359-adc.yaml
··· 11 11 12 12 properties: 13 13 compatible: 14 - enum: 15 - - ti,am3359-adc 16 - - ti,am4372-adc 14 + oneOf: 15 + - enum: 16 + - ti,am3359-adc 17 + - ti,am4372-adc 18 + - items: 19 + - enum: 20 + - ti,am654-adc 21 + - const: ti,am3359-adc 17 22 18 23 '#io-channel-cells': 19 24 const: 1
+4 -3
Documentation/devicetree/bindings/iio/adc/ti,tlc4541.yaml
··· 21 21 reg: 22 22 maxItems: 1 23 23 24 - spi-max-frequency: true 25 - 26 24 vref-supply: true 27 25 28 26 "#io-channel-cells": ··· 31 33 - reg 32 34 - vref-supply 33 35 34 - additionalProperties: false 36 + allOf: 37 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 38 + 39 + unevaluatedProperties: false 35 40 36 41 examples: 37 42 - |
+6 -2
Documentation/devicetree/bindings/iio/adc/ti,tsc2046.yaml
··· 23 23 interrupts: 24 24 maxItems: 1 25 25 26 - spi-max-frequency: true 26 + vref-supply: 27 + description: Optional supply of the reference voltage 27 28 28 29 "#io-channel-cells": 29 30 const: 1 ··· 60 59 61 60 additionalProperties: false 62 61 63 - additionalProperties: false 62 + allOf: 63 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 64 + 65 + unevaluatedProperties: false 64 66 65 67 examples: 66 68 - |
+1
Documentation/devicetree/bindings/iio/adc/xlnx,zynqmp-ams.yaml
··· 134 134 135 135 ams-pl@400: 136 136 type: object 137 + additionalProperties: false 137 138 description: 138 139 PL-SYSMON is capable of monitoring off chip voltage and temperature. 139 140 PL-SYSMON block has DRP, JTAG and I2C interface to enable monitoring
+1
Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml
··· 63 63 patternProperties: 64 64 "^channel@[0-3]$": 65 65 type: object 66 + additionalProperties: false 66 67 description: Represents the external channels which are connected to the device. 67 68 68 69 properties:
+4 -3
Documentation/devicetree/bindings/iio/amplifiers/adi,ada4250.yaml
··· 27 27 Enable internal buffer to drive the reference pin. 28 28 type: boolean 29 29 30 - spi-max-frequency: true 31 - 32 30 required: 33 31 - compatible 34 32 - reg 35 33 - avdd-supply 36 34 37 - additionalProperties: false 35 + allOf: 36 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 37 + 38 + unevaluatedProperties: false 38 39 39 40 examples: 40 41 - |
+1
Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml
··· 78 78 79 79 custom-output-range-config: 80 80 type: object 81 + additionalProperties: false 81 82 description: Configuration of custom range when 82 83 adi,output-range-microvolt is not present. 83 84 The formulas for calculation the output voltages are
+3 -4
Documentation/devicetree/bindings/iio/dac/adi,ad5064.yaml
··· 95 95 vrefD-supply: true 96 96 vref-supply: true 97 97 98 - spi-max-frequency: true 99 - 100 - additionalProperties: false 101 - 102 98 required: 103 99 - compatible 104 100 - reg 105 101 106 102 allOf: 103 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 107 104 - # Shared external vref, no internal reference 108 105 if: 109 106 properties: ··· 228 231 required: 229 232 - vrefA-supply 230 233 - vrefB-supply 234 + 235 + unevaluatedProperties: false 231 236 232 237 examples: 233 238 - |
+3 -4
Documentation/devicetree/bindings/iio/dac/adi,ad5360.yaml
··· 28 28 vref1-supply: true 29 29 vref2-supply: true 30 30 31 - spi-max-frequency: true 32 - 33 - additionalProperties: false 34 - 35 31 required: 36 32 - compatible 37 33 - reg ··· 35 39 - vref1-supply 36 40 37 41 allOf: 42 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 38 43 - if: 39 44 properties: 40 45 compatible: ··· 59 62 then: 60 63 required: 61 64 - vref2-supply 65 + 66 + unevaluatedProperties: false 62 67 63 68 examples: 64 69 - |
+5 -4
Documentation/devicetree/bindings/iio/dac/adi,ad5380.yaml
··· 39 39 description: 40 40 If not supplied devices will use internal regulators. 41 41 42 - spi-max-frequency: true 43 - 44 - additionalProperties: false 45 - 46 42 required: 47 43 - compatible 48 44 - reg 45 + 46 + allOf: 47 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 48 + 49 + unevaluatedProperties: false 49 50 50 51 examples: 51 52 - |
+4 -3
Documentation/devicetree/bindings/iio/dac/adi,ad5421.yaml
··· 26 26 maxItems: 1 27 27 description: Fault signal. 28 28 29 - spi-max-frequency: true 30 - 31 29 required: 32 30 - compatible 33 31 - reg 34 32 35 - additionalProperties: false 33 + allOf: 34 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 35 + 36 + unevaluatedProperties: false 36 37 37 38 examples: 38 39 - |
+3 -4
Documentation/devicetree/bindings/iio/dac/adi,ad5449.yaml
··· 27 27 reg: 28 28 maxItems: 1 29 29 30 - spi-max-frequency: true 31 - 32 30 VREF-supply: true 33 31 VREFA-supply: true 34 32 VREFB-supply: true 35 - 36 - additionalProperties: false 37 33 38 34 required: 39 35 - compatible 40 36 - reg 41 37 42 38 allOf: 39 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 43 40 - if: 44 41 properties: 45 42 compatible: ··· 68 71 required: 69 72 - VREFA-supply 70 73 - VREFB-supply 74 + 75 + unevaluatedProperties: false 71 76 72 77 examples: 73 78 - |
+5 -4
Documentation/devicetree/bindings/iio/dac/adi,ad5624r.yaml
··· 22 22 reg: 23 23 maxItems: 1 24 24 25 - spi-max-frequency: true 26 - 27 25 vref-supply: 28 26 description: If not present, internal reference will be used. 29 - 30 - additionalProperties: false 31 27 32 28 required: 33 29 - compatible 34 30 - reg 31 + 32 + allOf: 33 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 34 + 35 + unevaluatedProperties: false 35 36 36 37 examples: 37 38 - |
+5 -4
Documentation/devicetree/bindings/iio/dac/adi,ad5686.yaml
··· 53 53 vcc-supply: 54 54 description: If not supplied the internal reference is used. 55 55 56 - spi-max-frequency: true 57 - 58 - additionalProperties: false 59 - 60 56 required: 61 57 - compatible 62 58 - reg 59 + 60 + allOf: 61 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 62 + 63 + unevaluatedProperties: false 63 64 64 65 examples: 65 66 - |
+5 -4
Documentation/devicetree/bindings/iio/dac/adi,ad5755.yaml
··· 25 25 description: Either this or spi-cpol but not both. 26 26 spi-cpol: true 27 27 28 - spi-max-frequency: true 29 - 30 28 adi,ext-dc-dc-compenstation-resistor: 31 29 $ref: /schemas/types.yaml#/definitions/flag 32 30 description: ··· 64 66 required: 65 67 - compatible 66 68 - reg 67 - 68 - additionalProperties: false 69 69 70 70 patternProperties: 71 71 "^channel@[0-7]$": ··· 118 122 - spi-cpha 119 123 - required: 120 124 - spi-cpol 125 + 126 + allOf: 127 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 128 + 129 + unevaluatedProperties: false 121 130 122 131 examples: 123 132 - |
+2 -2
Documentation/devicetree/bindings/iio/dac/adi,ad5758.yaml
··· 16 16 reg: 17 17 maxItems: 1 18 18 19 - spi-max-frequency: true 20 19 spi-cpha: true 21 20 22 21 adi,dc-dc-mode: ··· 98 99 - adi,dc-dc-mode 99 100 100 101 allOf: 102 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 101 103 - if: 102 104 properties: 103 105 adi,dc-dc-mode: ··· 115 115 required: 116 116 - adi,range-microvolt 117 117 118 - additionalProperties: false 118 + unevaluatedProperties: false 119 119 120 120 examples: 121 121 - |
+3 -4
Documentation/devicetree/bindings/iio/dac/adi,ad5761.yaml
··· 22 22 reg: 23 23 maxItems: 1 24 24 25 - spi-max-frequency: true 26 - 27 25 vref-supply: 28 26 description: If not supplied, internal reference will be used. 29 - 30 - additionalProperties: false 31 27 32 28 required: 33 29 - compatible 34 30 - reg 35 31 36 32 allOf: 33 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 37 34 - if: 38 35 properties: 39 36 compatible: ··· 41 44 then: 42 45 required: 43 46 - vref-supply 47 + 48 + unevaluatedProperties: false 44 49 45 50 examples: 46 51 - |
+3 -4
Documentation/devicetree/bindings/iio/dac/adi,ad5764.yaml
··· 22 22 reg: 23 23 maxItems: 1 24 24 25 - spi-max-frequency: true 26 - 27 25 vrefAB-supply: true 28 26 vrefCD-supply: true 29 - 30 - additionalProperties: false 31 27 32 28 required: 33 29 - compatible 34 30 - reg 35 31 36 32 allOf: 33 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 37 34 - if: 38 35 properties: 39 36 compatible: ··· 42 45 required: 43 46 - vrefAB-supply 44 47 - vrefCD-supply 48 + 49 + unevaluatedProperties: false 45 50 46 51 examples: 47 52 - |
+8 -3
Documentation/devicetree/bindings/iio/dac/adi,ad5770r.yaml
··· 49 49 asserted during driver probe. 50 50 maxItems: 1 51 51 52 - spi-max-frequency: true 53 - 54 52 '#address-cells': 55 53 const: 1 56 54 ··· 60 62 connected to the DAC. Channel 0 can act both as a current 61 63 source and sink. 62 64 type: object 65 + additionalProperties: false 63 66 64 67 properties: 65 68 reg: ··· 84 85 description: Represents an external channel which are 85 86 connected to the DAC. 86 87 type: object 88 + additionalProperties: false 87 89 88 90 properties: 89 91 reg: ··· 101 101 description: Represents an external channel which are 102 102 connected to the DAC. 103 103 type: object 104 + additionalProperties: false 104 105 105 106 properties: 106 107 reg: ··· 117 116 patternProperties: 118 117 "^channel@([3-5])$": 119 118 type: object 119 + additionalProperties: false 120 120 description: Represents the external channels which are connected to the DAC. 121 121 properties: 122 122 reg: ··· 140 138 - channel@4 141 139 - channel@5 142 140 143 - additionalProperties: false 141 + allOf: 142 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 143 + 144 + unevaluatedProperties: false 144 145 145 146 examples: 146 147 - |
+5 -4
Documentation/devicetree/bindings/iio/dac/adi,ad5791.yaml
··· 23 23 reg: 24 24 maxItems: 1 25 25 26 - spi-max-frequency: true 27 - 28 26 vdd-supply: true 29 27 vss-supply: true 30 - 31 - additionalProperties: false 32 28 33 29 required: 34 30 - compatible 35 31 - reg 36 32 - vdd-supply 37 33 - vss-supply 34 + 35 + allOf: 36 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 37 + 38 + unevaluatedProperties: false 38 39 39 40 examples: 40 41 - |
+3 -4
Documentation/devicetree/bindings/iio/dac/adi,ad8801.yaml
··· 19 19 reg: 20 20 maxItems: 1 21 21 22 - spi-max-frequency: true 23 - 24 22 vrefh-supply: true 25 23 vrefl-supply: true 26 - 27 - additionalProperties: false 28 24 29 25 required: 30 26 - compatible ··· 28 32 - vrefh-supply 29 33 30 34 allOf: 35 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 31 36 - if: 32 37 properties: 33 38 compatible: ··· 40 43 else: 41 44 properties: 42 45 vrefl-supply: false 46 + 47 + unevaluatedProperties: false 43 48 44 49 examples: 45 50 - |
+1
Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml
··· 48 48 patternProperties: 49 49 "^channel@([0-9]|1[0-5])$": 50 50 type: object 51 + additionalProperties: false 51 52 52 53 properties: 53 54 reg:
+5 -4
Documentation/devicetree/bindings/iio/dac/microchip,mcp4922.yaml
··· 21 21 reg: 22 22 maxItems: 1 23 23 24 - spi-max-frequency: true 25 - 26 24 vref-supply: true 27 - 28 - additionalProperties: false 29 25 30 26 required: 31 27 - compatible 32 28 - reg 33 29 - vref-supply 30 + 31 + allOf: 32 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 33 + 34 + unevaluatedProperties: false 34 35 35 36 examples: 36 37 - |
+5 -4
Documentation/devicetree/bindings/iio/dac/ti,dac082s085.yaml
··· 33 33 vref-supply: 34 34 description: Needed to provide output scaling. 35 35 36 - spi-max-frequency: true 37 - 38 36 required: 39 37 - compatible 40 38 - reg 41 39 - vref-supply 42 - 43 - additionalProperties: false 44 40 45 41 oneOf: 46 42 - required: 47 43 - spi-cpha 48 44 - required: 49 45 - spi-cpol 46 + 47 + allOf: 48 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 49 + 50 + unevaluatedProperties: false 50 51 51 52 examples: 52 53 - |
+4 -3
Documentation/devicetree/bindings/iio/dac/ti,dac7311.yaml
··· 24 24 Reference voltage must be supplied to establish the scaling of the 25 25 output voltage. 26 26 27 - spi-max-frequency: true 28 - 29 27 required: 30 28 - compatible 31 29 - reg 32 30 - vref-supply 33 31 34 - additionalProperties: false 32 + allOf: 33 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 34 + 35 + unevaluatedProperties: false 35 36 36 37 examples: 37 38 - |
+4 -3
Documentation/devicetree/bindings/iio/dac/ti,dac7612.yaml
··· 29 29 DACs are loaded when the pin connected to this GPIO is pulled low. 30 30 maxItems: 1 31 31 32 - spi-max-frequency: true 33 - 34 32 required: 35 33 - compatible 36 34 - reg 37 35 38 - additionalProperties: false 36 + allOf: 37 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 38 + 39 + unevaluatedProperties: false 39 40 40 41 examples: 41 42 - |
+4 -3
Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
··· 40 40 output stage will shut down until the ADF4371/ADF4372 achieves lock as 41 41 measured by the digital lock detect circuitry. 42 42 43 - spi-max-frequency: true 44 - 45 43 required: 46 44 - compatible 47 45 - reg 48 46 - clocks 49 47 - clock-names 50 48 51 - additionalProperties: false 49 + allOf: 50 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 51 + 52 + unevaluatedProperties: false 52 53 53 54 examples: 54 55 - |
+5 -4
Documentation/devicetree/bindings/iio/health/ti,afe4403.yaml
··· 25 25 26 26 reset-gpios: true 27 27 28 - spi-max-frequency: true 29 - 30 - additionalProperties: false 31 - 32 28 required: 33 29 - compatible 34 30 - reg 31 + 32 + allOf: 33 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 34 + 35 + unevaluatedProperties: false 35 36 36 37 examples: 37 38 - |
+4 -3
Documentation/devicetree/bindings/iio/imu/adi,adis16460.yaml
··· 25 25 26 26 spi-cpol: true 27 27 28 - spi-max-frequency: true 29 - 30 28 interrupts: 31 29 maxItems: 1 32 30 ··· 33 35 - reg 34 36 - interrupts 35 37 36 - additionalProperties: false 38 + allOf: 39 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 40 + 41 + unevaluatedProperties: false 37 42 38 43 examples: 39 44 - |
+5 -4
Documentation/devicetree/bindings/iio/imu/adi,adis16480.yaml
··· 47 47 - DIO3 48 48 - DIO4 49 49 50 - spi-max-frequency: true 51 - 52 50 spi-cpha: true 53 51 spi-cpol: true 54 52 ··· 94 96 - DIO3 95 97 - DIO4 96 98 97 - additionalProperties: false 98 - 99 99 required: 100 100 - compatible 101 101 - reg ··· 101 105 - spi-cpha 102 106 - spi-cpol 103 107 - spi-max-frequency 108 + 109 + allOf: 110 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 111 + 112 + unevaluatedProperties: false 104 113 105 114 examples: 106 115 - |
+4 -3
Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml
··· 46 46 mount-matrix: 47 47 description: an optional 3x3 mounting rotation matrix 48 48 49 - spi-max-frequency: true 50 - 51 49 required: 52 50 - compatible 53 51 - reg 54 52 55 - additionalProperties: false 53 + allOf: 54 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 55 + 56 + unevaluatedProperties: false 56 57 57 58 examples: 58 59 - |
+4 -2
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml
··· 47 47 vddio-supply: 48 48 description: Regulator that provides power to the bus 49 49 50 - spi-max-frequency: true 51 50 spi-cpha: true 52 51 spi-cpol: true 53 52 ··· 55 56 - reg 56 57 - interrupts 57 58 58 - additionalProperties: false 59 + allOf: 60 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 61 + 62 + unevaluatedProperties: false 59 63 60 64 examples: 61 65 - |
+2 -3
Documentation/devicetree/bindings/iio/imu/invensense,mpu6050.yaml
··· 40 40 interrupts: 41 41 maxItems: 1 42 42 43 - spi-max-frequency: true 44 - 45 43 vdd-supply: true 46 44 vddio-supply: true 47 45 ··· 52 54 These devices also support an auxiliary i2c bus via an i2c-gate. 53 55 54 56 allOf: 57 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 55 58 - if: 56 59 not: 57 60 properties: ··· 66 67 properties: 67 68 i2c-gate: false 68 69 69 - additionalProperties: false 70 + unevaluatedProperties: false 70 71 71 72 required: 72 73 - compatible
+4 -3
Documentation/devicetree/bindings/iio/imu/nxp,fxos8700.yaml
··· 36 36 drive-open-drain: 37 37 type: boolean 38 38 39 - spi-max-frequency: true 40 - 41 39 required: 42 40 - compatible 43 41 - reg 44 42 45 - additionalProperties: false 43 + allOf: 44 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 45 + 46 + unevaluatedProperties: false 46 47 47 48 examples: 48 49 - |
+5 -4
Documentation/devicetree/bindings/iio/imu/st,lsm6dsx.yaml
··· 45 45 description: 46 46 Supports up to 2 interrupt lines via the INT1 and INT2 pins. 47 47 48 - spi-max-frequency: true 49 - 50 48 vdd-supply: 51 49 description: if defined provides VDD power to the sensor. 52 50 ··· 79 81 wakeup-source: 80 82 $ref: /schemas/types.yaml#/definitions/flag 81 83 82 - additionalProperties: false 83 - 84 84 required: 85 85 - compatible 86 86 - reg 87 + 88 + allOf: 89 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 90 + 91 + unevaluatedProperties: false 87 92 88 93 examples: 89 94 - |
+49
Documentation/devicetree/bindings/iio/light/liteon,ltrf216a.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/light/liteon,ltrf216a.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: LTRF216A Ambient Light Sensor 8 + 9 + maintainers: 10 + - Shreeya Patel <shreeya.patel@collabora.com> 11 + 12 + description: 13 + Ambient light sensing with an i2c interface. 14 + 15 + properties: 16 + compatible: 17 + const: liteon,ltrf216a 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + interrupts: 23 + maxItems: 1 24 + 25 + vdd-supply: 26 + description: Regulator that provides power to the sensor. 27 + 28 + required: 29 + - compatible 30 + - reg 31 + 32 + additionalProperties: false 33 + 34 + examples: 35 + - | 36 + #include <dt-bindings/interrupt-controller/irq.h> 37 + 38 + i2c { 39 + #address-cells = <1>; 40 + #size-cells = <0>; 41 + 42 + light-sensor@53 { 43 + compatible = "liteon,ltrf216a"; 44 + reg = <0x53>; 45 + vdd-supply = <&vdd_regulator>; 46 + interrupt-parent = <&gpio0>; 47 + interrupts = <5 IRQ_TYPE_LEVEL_LOW>; 48 + }; 49 + };
+5 -4
Documentation/devicetree/bindings/iio/potentiometer/microchip,mcp41010.yaml
··· 25 25 reg: 26 26 maxItems: 1 27 27 28 - spi-max-frequency: true 29 - 30 - additionalProperties: false 31 - 32 28 required: 33 29 - compatible 34 30 - reg 31 + 32 + allOf: 33 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 34 + 35 + unevaluatedProperties: false 35 36 36 37 examples: 37 38 - |
+5 -4
Documentation/devicetree/bindings/iio/potentiometer/microchip,mcp4131.yaml
··· 80 80 reg: 81 81 maxItems: 1 82 82 83 - spi-max-frequency: true 84 - 85 - additionalProperties: false 86 - 87 83 required: 88 84 - compatible 89 85 - reg 86 + 87 + allOf: 88 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 89 + 90 + unevaluatedProperties: false 90 91 91 92 examples: 92 93 - |
+1 -1
Documentation/devicetree/bindings/iio/pressure/asc,dlhl60d.yaml
··· 7 7 title: All Sensors DLH series low voltage digital pressure sensors 8 8 9 9 maintainers: 10 - - Tomislav Denis <tomislav.denis@avl.com> 10 + - Jonathan Cameron <jic23@kernel.org> 11 11 12 12 description: | 13 13 Bindings for the All Sensors DLH series pressure sensors.
+5 -4
Documentation/devicetree/bindings/iio/samsung,sensorhub-rinato.yaml
··· 40 40 description: 41 41 Reset the sensorhub. 42 42 43 - spi-max-frequency: true 44 - 45 - additionalProperties: false 46 - 47 43 required: 48 44 - compatible 49 45 - reg ··· 47 51 - ap-mcu-gpios 48 52 - mcu-ap-gpios 49 53 - mcu-reset-gpios 54 + 55 + allOf: 56 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 57 + 58 + unevaluatedProperties: false 50 59 51 60 examples: 52 61 - |
+2 -2
Documentation/devicetree/bindings/iio/temperature/maxim,max31855k.yaml
··· 32 32 reg: 33 33 maxItems: 1 34 34 35 - spi-max-frequency: true 36 35 spi-cpha: true 37 36 38 37 required: ··· 39 40 - reg 40 41 41 42 allOf: 43 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 42 44 - if: 43 45 properties: 44 46 compatible: ··· 53 53 properties: 54 54 spi-cpha: false 55 55 56 - additionalProperties: false 56 + unevaluatedProperties: false 57 57 58 58 examples: 59 59 - |
+4 -2
Documentation/devicetree/bindings/iio/temperature/maxim,max31856.yaml
··· 19 19 reg: 20 20 maxItems: 1 21 21 22 - spi-max-frequency: true 23 22 spi-cpha: true 24 23 25 24 thermocouple-type: ··· 33 34 - reg 34 35 - spi-cpha 35 36 36 - additionalProperties: false 37 + allOf: 38 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 39 + 40 + unevaluatedProperties: false 37 41 38 42 examples: 39 43 - |
+4 -2
Documentation/devicetree/bindings/iio/temperature/maxim,max31865.yaml
··· 25 25 enables 3-wire RTD connection. Else 2-wire or 4-wire RTD connection. 26 26 type: boolean 27 27 28 - spi-max-frequency: true 29 28 spi-cpha: true 30 29 31 30 required: ··· 32 33 - reg 33 34 - spi-cpha 34 35 35 - additionalProperties: false 36 + allOf: 37 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 38 + 39 + unevaluatedProperties: false 36 40 37 41 examples: 38 42 - |
+4
Documentation/devicetree/bindings/iio/temperature/melexis,mlx90632.yaml
··· 35 35 maxItems: 1 36 36 description: Default is 0x3a, but can be reprogrammed. 37 37 38 + vdd-supply: 39 + description: provide VDD power to the sensor. 40 + 38 41 required: 39 42 - compatible 40 43 - reg ··· 53 50 temp-sensor@3a { 54 51 compatible = "melexis,mlx90632"; 55 52 reg = <0x3a>; 53 + vdd-supply = <&ldo4_reg>; 56 54 }; 57 55 }; 58 56 ...
+2
Documentation/devicetree/bindings/vendor-prefixes.yaml
··· 777 777 description: MELFAS Inc. 778 778 "^mellanox,.*": 779 779 description: Mellanox Technologies 780 + "^memsensing,.*": 781 + description: MEMSensing Microsystems Co., Ltd. 780 782 "^memsic,.*": 781 783 description: MEMSIC Inc. 782 784 "^menlo,.*":
+20 -20
MAINTAINERS
··· 620 620 M: Cosmin Tanislav <cosmin.tanislav@analog.com> 621 621 L: linux-iio@vger.kernel.org 622 622 S: Supported 623 - W: http://ez.analog.com/community/linux-device-drivers 623 + W: https://ez.analog.com/linux-software-drivers 624 624 F: Documentation/devicetree/bindings/iio/accel/adi,adxl367.yaml 625 625 F: drivers/iio/accel/adxl367* 626 626 ··· 753 753 L: Dell.Client.Kernel@dell.com 754 754 S: Maintained 755 755 F: drivers/platform/x86/dell/alienware-wmi.c 756 - 757 - ALL SENSORS DLH SERIES PRESSURE SENSORS DRIVER 758 - M: Tomislav Denis <tomislav.denis@avl.com> 759 - L: linux-iio@vger.kernel.org 760 - S: Maintained 761 - W: http://www.allsensors.com/ 762 - F: Documentation/devicetree/bindings/iio/pressure/asc,dlhl60d.yaml 763 - F: drivers/iio/pressure/dlhl60d.c 764 756 765 757 ALLEGRO DVT VIDEO IP CORE DRIVER 766 758 M: Michael Tretter <m.tretter@pengutronix.de> ··· 1144 1152 M: Cosmin Tanislav <cosmin.tanislav@analog.com> 1145 1153 L: linux-iio@vger.kernel.org 1146 1154 S: Supported 1147 - W: http://ez.analog.com/community/linux-device-drivers 1155 + W: https://ez.analog.com/linux-software-drivers 1148 1156 F: Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml 1149 1157 F: drivers/iio/addac/ad74413r.c 1150 1158 F: include/dt-bindings/iio/addac/adi,ad74413r.h ··· 1374 1382 M: William Breathitt Gray <william.gray@linaro.org> 1375 1383 L: linux-iio@vger.kernel.org 1376 1384 S: Maintained 1377 - F: drivers/iio/adc/stx104.c 1385 + F: drivers/iio/addac/stx104.c 1378 1386 1379 1387 APM DRIVER 1380 1388 M: Jiri Kosina <jikos@kernel.org> ··· 11921 11929 M: Nuno Sá <nuno.sa@analog.com> 11922 11930 L: linux-iio@vger.kernel.org 11923 11931 S: Supported 11924 - W: http://ez.analog.com/community/linux-device-drivers 11932 + W: https://ez.analog.com/linux-software-drivers 11925 11933 F: Documentation/ABI/testing/sysfs-bus-iio-dac-ltc2688 11926 11934 F: Documentation/devicetree/bindings/iio/dac/adi,ltc2688.yaml 11927 11935 F: drivers/iio/dac/ltc2688.c ··· 12337 12345 S: Maintained 12338 12346 F: Documentation/devicetree/bindings/iio/proximity/maxbotix,mb1232.yaml 12339 12347 F: drivers/iio/proximity/mb1232.c 12348 + 12349 + MAXIM MAX11205 DRIVER 12350 + M: Ramona Bolboaca <ramona.bolboaca@analog.com> 12351 + L: linux-iio@vger.kernel.org 12352 + S: Supported 12353 + W: https://ez.analog.com/linux-software-drivers 12354 + F: Documentation/devicetree/bindings/iio/adc/maxim,max11205.yaml 12355 + F: drivers/iio/adc/max11205.c 12340 12356 12341 12357 MAXIM MAX17040 FAMILY FUEL GAUGE DRIVERS 12342 12358 R: Iskren Chernev <iskren.chernev@gmail.com> ··· 13190 13190 F: include/linux/mtd/ 13191 13191 F: include/uapi/mtd/ 13192 13192 13193 + MEMSENSING MICROSYSTEMS MSA311 DRIVER 13194 + M: Dmitry Rokosov <ddrokosov@sberdevices.ru> 13195 + L: linux-iio@vger.kernel.org 13196 + S: Maintained 13197 + F: Documentation/devicetree/bindings/iio/accel/memsensing,msa311.yaml 13198 + F: drivers/iio/accel/msa311.c 13199 + 13193 13200 MEN A21 WATCHDOG DRIVER 13194 13201 M: Johannes Thumshirn <morbidrsa@gmail.com> 13195 13202 L: linux-watchdog@vger.kernel.org ··· 13418 13411 M: Marcus Folkesson <marcus.folkesson@gmail.com> 13419 13412 M: Kent Gustavsson <kent@minoris.se> 13420 13413 L: linux-iio@vger.kernel.org 13421 - S: Supported 13414 + S: Maintained 13422 13415 F: Documentation/devicetree/bindings/iio/adc/microchip,mcp3911.yaml 13423 13416 F: drivers/iio/adc/mcp3911.c 13424 13417 ··· 20266 20259 M: Robert Richter <rric@kernel.org> 20267 20260 S: Odd Fixes 20268 20261 F: drivers/gpio/gpio-thunderx.c 20269 - 20270 - TI ADS131E0X ADC SERIES DRIVER 20271 - M: Tomislav Denis <tomislav.denis@avl.com> 20272 - L: linux-iio@vger.kernel.org 20273 - S: Maintained 20274 - F: Documentation/devicetree/bindings/iio/adc/ti,ads131e08.yaml 20275 - F: drivers/iio/adc/ti-ads131e08.c 20276 20262 20277 20263 TI AM437X VPFE DRIVER 20278 20264 M: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>
+13
drivers/iio/accel/Kconfig
··· 541 541 To compile this driver as a module, choose M here: the module 542 542 will be called mma9553. 543 543 544 + config MSA311 545 + tristate "MEMSensing Digital 3-Axis Accelerometer Driver" 546 + depends on I2C 547 + select IIO_BUFFER 548 + select IIO_TRIGGERED_BUFFER 549 + select REGMAP_I2C 550 + help 551 + Say yes here to build support for the MEMSensing MSA311 552 + accelerometer driver. 553 + 554 + To compile this driver as a module, choose M here: the module will be 555 + called msa311. 556 + 544 557 config MXC4005 545 558 tristate "Memsic MXC4005XC 3-Axis Accelerometer Driver" 546 559 depends on I2C
+2
drivers/iio/accel/Makefile
··· 58 58 obj-$(CONFIG_MMA9551) += mma9551.o 59 59 obj-$(CONFIG_MMA9553) += mma9553.o 60 60 61 + obj-$(CONFIG_MSA311) += msa311.o 62 + 61 63 obj-$(CONFIG_MXC4005) += mxc4005.o 62 64 obj-$(CONFIG_MXC6255) += mxc6255.o 63 65
+4 -3
drivers/iio/accel/adxl345_core.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/property.h> 12 12 #include <linux/regmap.h> 13 + #include <linux/units.h> 13 14 14 15 #include <linux/iio/iio.h> 15 16 #include <linux/iio/sysfs.h> ··· 33 32 34 33 #define ADXL345_BW_RATE GENMASK(3, 0) 35 34 #define ADXL345_BASE_RATE_NANO_HZ 97656250LL 36 - #define NHZ_PER_HZ 1000000000LL 37 35 38 36 #define ADXL345_POWER_CTL_MEASURE BIT(3) 39 37 #define ADXL345_POWER_CTL_STANDBY 0x00 ··· 139 139 140 140 samp_freq_nhz = ADXL345_BASE_RATE_NANO_HZ << 141 141 (regval & ADXL345_BW_RATE); 142 - *val = div_s64_rem(samp_freq_nhz, NHZ_PER_HZ, val2); 142 + *val = div_s64_rem(samp_freq_nhz, NANOHZ_PER_HZ, val2); 143 143 144 144 return IIO_VAL_INT_PLUS_NANO; 145 145 } ··· 164 164 ADXL345_REG_OFS_AXIS(chan->address), 165 165 val / 4); 166 166 case IIO_CHAN_INFO_SAMP_FREQ: 167 - n = div_s64(val * NHZ_PER_HZ + val2, ADXL345_BASE_RATE_NANO_HZ); 167 + n = div_s64(val * NANOHZ_PER_HZ + val2, 168 + ADXL345_BASE_RATE_NANO_HZ); 168 169 169 170 return regmap_update_bits(data->regmap, ADXL345_REG_BW_RATE, 170 171 ADXL345_BW_RATE,
+14
drivers/iio/accel/bma400.h
··· 40 40 #define BMA400_INT_STAT1_REG 0x0f 41 41 #define BMA400_INT_STAT2_REG 0x10 42 42 #define BMA400_INT12_MAP_REG 0x23 43 + #define BMA400_INT_ENG_OVRUN_MSK BIT(4) 43 44 44 45 /* Temperature register */ 45 46 #define BMA400_TEMP_DATA_REG 0x11 ··· 105 104 #define BMA400_INT_GEN1_MSK BIT(2) 106 105 #define BMA400_INT_GEN2_MSK BIT(3) 107 106 #define BMA400_GEN_HYST_MSK GENMASK(1, 0) 107 + 108 + /* TAP config registers */ 109 + #define BMA400_TAP_CONFIG 0x57 110 + #define BMA400_TAP_CONFIG1 0x58 111 + #define BMA400_S_TAP_MSK BIT(2) 112 + #define BMA400_D_TAP_MSK BIT(3) 113 + #define BMA400_INT_S_TAP_MSK BIT(10) 114 + #define BMA400_INT_D_TAP_MSK BIT(11) 115 + #define BMA400_TAP_SEN_MSK GENMASK(2, 0) 116 + #define BMA400_TAP_TICSTH_MSK GENMASK(1, 0) 117 + #define BMA400_TAP_QUIET_MSK GENMASK(3, 2) 118 + #define BMA400_TAP_QUIETDT_MSK GENMASK(5, 4) 119 + #define BMA400_TAP_TIM_LIST_LEN 4 108 120 109 121 /* 110 122 * BMA400_SCALE_MIN macro value represents m/s^2 for 1 LSB before
+333 -10
drivers/iio/accel/bma400_core.c
··· 26 26 #include <linux/iio/iio.h> 27 27 #include <linux/iio/buffer.h> 28 28 #include <linux/iio/events.h> 29 + #include <linux/iio/sysfs.h> 29 30 #include <linux/iio/trigger.h> 30 31 #include <linux/iio/trigger_consumer.h> 31 32 #include <linux/iio/triggered_buffer.h> ··· 47 46 static int bma400_sample_freqs[14]; 48 47 49 48 static const int bma400_osr_range[] = { 0, 1, 3 }; 49 + 50 + static int tap_reset_timeout[BMA400_TAP_TIM_LIST_LEN] = { 51 + 300000, 52 + 400000, 53 + 500000, 54 + 600000 55 + }; 56 + 57 + static int tap_max2min_time[BMA400_TAP_TIM_LIST_LEN] = { 58 + 30000, 59 + 45000, 60 + 60000, 61 + 90000 62 + }; 63 + 64 + static int double_tap2_min_delay[BMA400_TAP_TIM_LIST_LEN] = { 65 + 20000, 66 + 40000, 67 + 60000, 68 + 80000 69 + }; 50 70 51 71 /* See the ACC_CONFIG0 section of the datasheet */ 52 72 enum bma400_power_mode { ··· 110 88 bool step_event_en; 111 89 bool activity_event_en; 112 90 unsigned int generic_event_en; 91 + unsigned int tap_event_en_bitmask; 113 92 /* Correct time stamp alignment */ 114 93 struct { 115 94 __le16 buff[3]; ··· 239 216 BIT(IIO_EV_INFO_HYSTERESIS) | 240 217 BIT(IIO_EV_INFO_ENABLE), 241 218 }, 219 + { 220 + .type = IIO_EV_TYPE_GESTURE, 221 + .dir = IIO_EV_DIR_SINGLETAP, 222 + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | 223 + BIT(IIO_EV_INFO_ENABLE) | 224 + BIT(IIO_EV_INFO_RESET_TIMEOUT), 225 + }, 226 + { 227 + .type = IIO_EV_TYPE_GESTURE, 228 + .dir = IIO_EV_DIR_DOUBLETAP, 229 + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | 230 + BIT(IIO_EV_INFO_ENABLE) | 231 + BIT(IIO_EV_INFO_RESET_TIMEOUT) | 232 + BIT(IIO_EV_INFO_TAP2_MIN_DELAY), 233 + }, 234 + }; 235 + 236 + static int usec_to_tapreg_raw(int usec, const int *time_list) 237 + { 238 + int index; 239 + 240 + for (index = 0; index < BMA400_TAP_TIM_LIST_LEN; index++) { 241 + if (usec == time_list[index]) 242 + return index; 243 + } 244 + return -EINVAL; 245 + } 246 + 247 + static ssize_t in_accel_gesture_tap_maxtomin_time_show(struct device *dev, 248 + struct device_attribute *attr, 249 + char *buf) 250 + { 251 + struct iio_dev *indio_dev = dev_to_iio_dev(dev); 252 + struct bma400_data *data = iio_priv(indio_dev); 253 + int ret, reg_val, raw, vals[2]; 254 + 255 + ret = regmap_read(data->regmap, BMA400_TAP_CONFIG1, &reg_val); 256 + if (ret) 257 + return ret; 258 + 259 + raw = FIELD_GET(BMA400_TAP_TICSTH_MSK, reg_val); 260 + vals[0] = 0; 261 + vals[1] = tap_max2min_time[raw]; 262 + 263 + return iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO, 2, vals); 264 + } 265 + 266 + static ssize_t in_accel_gesture_tap_maxtomin_time_store(struct device *dev, 267 + struct device_attribute *attr, 268 + const char *buf, size_t len) 269 + { 270 + struct iio_dev *indio_dev = dev_to_iio_dev(dev); 271 + struct bma400_data *data = iio_priv(indio_dev); 272 + int ret, val_int, val_fract, raw; 273 + 274 + ret = iio_str_to_fixpoint(buf, 100000, &val_int, &val_fract); 275 + if (ret) 276 + return ret; 277 + 278 + raw = usec_to_tapreg_raw(val_fract, tap_max2min_time); 279 + if (raw < 0) 280 + return -EINVAL; 281 + 282 + ret = regmap_update_bits(data->regmap, BMA400_TAP_CONFIG1, 283 + BMA400_TAP_TICSTH_MSK, 284 + FIELD_PREP(BMA400_TAP_TICSTH_MSK, raw)); 285 + if (ret) 286 + return ret; 287 + 288 + return len; 289 + } 290 + 291 + static IIO_DEVICE_ATTR_RW(in_accel_gesture_tap_maxtomin_time, 0); 292 + 293 + /* 294 + * Tap interrupts works with 200 Hz input data rate and the time based tap 295 + * controls are in the terms of data samples so the below calculation is 296 + * used to convert the configuration values into seconds. 297 + * e.g.: 298 + * 60 data samples * 0.005 ms = 0.3 seconds. 299 + * 80 data samples * 0.005 ms = 0.4 seconds. 300 + */ 301 + 302 + /* quiet configuration values in seconds */ 303 + static IIO_CONST_ATTR(in_accel_gesture_tap_reset_timeout_available, 304 + "0.3 0.4 0.5 0.6"); 305 + 306 + /* tics_th configuration values in seconds */ 307 + static IIO_CONST_ATTR(in_accel_gesture_tap_maxtomin_time_available, 308 + "0.03 0.045 0.06 0.09"); 309 + 310 + /* quiet_dt configuration values in seconds */ 311 + static IIO_CONST_ATTR(in_accel_gesture_doubletap_tap2_min_delay_available, 312 + "0.02 0.04 0.06 0.08"); 313 + 314 + /* List of sensitivity values available to configure tap interrupts */ 315 + static IIO_CONST_ATTR(in_accel_gesture_tap_value_available, "0 1 2 3 4 5 6 7"); 316 + 317 + static struct attribute *bma400_event_attributes[] = { 318 + &iio_const_attr_in_accel_gesture_tap_value_available.dev_attr.attr, 319 + &iio_const_attr_in_accel_gesture_tap_reset_timeout_available.dev_attr.attr, 320 + &iio_const_attr_in_accel_gesture_tap_maxtomin_time_available.dev_attr.attr, 321 + &iio_const_attr_in_accel_gesture_doubletap_tap2_min_delay_available.dev_attr.attr, 322 + &iio_dev_attr_in_accel_gesture_tap_maxtomin_time.dev_attr.attr, 323 + NULL 324 + }; 325 + 326 + static const struct attribute_group bma400_event_attribute_group = { 327 + .attrs = bma400_event_attributes, 242 328 }; 243 329 244 330 #define BMA400_ACC_CHANNEL(_index, _axis) { \ ··· 1144 1012 case IIO_EV_DIR_FALLING: 1145 1013 return FIELD_GET(BMA400_INT_GEN2_MSK, 1146 1014 data->generic_event_en); 1015 + case IIO_EV_DIR_SINGLETAP: 1016 + return FIELD_GET(BMA400_S_TAP_MSK, 1017 + data->tap_event_en_bitmask); 1018 + case IIO_EV_DIR_DOUBLETAP: 1019 + return FIELD_GET(BMA400_D_TAP_MSK, 1020 + data->tap_event_en_bitmask); 1147 1021 default: 1148 1022 return -EINVAL; 1149 1023 } ··· 1239 1101 return 0; 1240 1102 } 1241 1103 1104 + static int bma400_tap_event_en(struct bma400_data *data, 1105 + enum iio_event_direction dir, int state) 1106 + { 1107 + unsigned int mask, field_value; 1108 + int ret; 1109 + 1110 + /* 1111 + * Tap interrupts can be configured only in normal mode. 1112 + * See table in section 4.3 "Power modes - performance modes" of 1113 + * datasheet v1.2. 1114 + */ 1115 + if (data->power_mode != POWER_MODE_NORMAL) 1116 + return -EINVAL; 1117 + 1118 + /* 1119 + * Tap interrupts are operating with a data rate of 200Hz. 1120 + * See section 4.7 "Tap sensing interrupt" in datasheet v1.2. 1121 + */ 1122 + if (data->sample_freq.hz != 200 && state) { 1123 + dev_err(data->dev, "Invalid data rate for tap interrupts.\n"); 1124 + return -EINVAL; 1125 + } 1126 + 1127 + ret = regmap_update_bits(data->regmap, BMA400_INT12_MAP_REG, 1128 + BMA400_S_TAP_MSK, 1129 + FIELD_PREP(BMA400_S_TAP_MSK, state)); 1130 + if (ret) 1131 + return ret; 1132 + 1133 + switch (dir) { 1134 + case IIO_EV_DIR_SINGLETAP: 1135 + mask = BMA400_S_TAP_MSK; 1136 + set_mask_bits(&field_value, BMA400_S_TAP_MSK, 1137 + FIELD_PREP(BMA400_S_TAP_MSK, state)); 1138 + break; 1139 + case IIO_EV_DIR_DOUBLETAP: 1140 + mask = BMA400_D_TAP_MSK; 1141 + set_mask_bits(&field_value, BMA400_D_TAP_MSK, 1142 + FIELD_PREP(BMA400_D_TAP_MSK, state)); 1143 + break; 1144 + default: 1145 + return -EINVAL; 1146 + } 1147 + 1148 + ret = regmap_update_bits(data->regmap, BMA400_INT_CONFIG1_REG, mask, 1149 + field_value); 1150 + if (ret) 1151 + return ret; 1152 + 1153 + set_mask_bits(&data->tap_event_en_bitmask, mask, field_value); 1154 + 1155 + return 0; 1156 + } 1157 + 1158 + static int bma400_disable_adv_interrupt(struct bma400_data *data) 1159 + { 1160 + int ret; 1161 + 1162 + ret = regmap_write(data->regmap, BMA400_INT_CONFIG0_REG, 0); 1163 + if (ret) 1164 + return ret; 1165 + 1166 + ret = regmap_write(data->regmap, BMA400_INT_CONFIG1_REG, 0); 1167 + if (ret) 1168 + return ret; 1169 + 1170 + data->tap_event_en_bitmask = 0; 1171 + data->generic_event_en = 0; 1172 + data->step_event_en = false; 1173 + data->activity_event_en = false; 1174 + 1175 + return 0; 1176 + } 1177 + 1242 1178 static int bma400_write_event_config(struct iio_dev *indio_dev, 1243 1179 const struct iio_chan_spec *chan, 1244 1180 enum iio_event_type type, ··· 1323 1111 1324 1112 switch (chan->type) { 1325 1113 case IIO_ACCEL: 1326 - mutex_lock(&data->mutex); 1327 - ret = bma400_activity_event_en(data, dir, state); 1328 - mutex_unlock(&data->mutex); 1329 - return ret; 1114 + switch (type) { 1115 + case IIO_EV_TYPE_MAG: 1116 + mutex_lock(&data->mutex); 1117 + ret = bma400_activity_event_en(data, dir, state); 1118 + mutex_unlock(&data->mutex); 1119 + return ret; 1120 + case IIO_EV_TYPE_GESTURE: 1121 + mutex_lock(&data->mutex); 1122 + ret = bma400_tap_event_en(data, dir, state); 1123 + mutex_unlock(&data->mutex); 1124 + return ret; 1125 + default: 1126 + return -EINVAL; 1127 + } 1330 1128 case IIO_STEPS: 1331 1129 mutex_lock(&data->mutex); 1332 1130 ret = bma400_steps_event_enable(data, state); ··· 1379 1157 int *val, int *val2) 1380 1158 { 1381 1159 struct bma400_data *data = iio_priv(indio_dev); 1382 - int ret, reg; 1160 + int ret, reg, reg_val, raw; 1383 1161 1384 - switch (chan->type) { 1385 - case IIO_ACCEL: 1162 + if (chan->type != IIO_ACCEL) 1163 + return -EINVAL; 1164 + 1165 + switch (type) { 1166 + case IIO_EV_TYPE_MAG: 1386 1167 reg = get_gen_config_reg(dir); 1387 1168 if (reg < 0) 1388 1169 return -EINVAL; ··· 1421 1196 default: 1422 1197 return -EINVAL; 1423 1198 } 1199 + case IIO_EV_TYPE_GESTURE: 1200 + switch (info) { 1201 + case IIO_EV_INFO_VALUE: 1202 + ret = regmap_read(data->regmap, BMA400_TAP_CONFIG, 1203 + &reg_val); 1204 + if (ret) 1205 + return ret; 1206 + 1207 + *val = FIELD_GET(BMA400_TAP_SEN_MSK, reg_val); 1208 + return IIO_VAL_INT; 1209 + case IIO_EV_INFO_RESET_TIMEOUT: 1210 + ret = regmap_read(data->regmap, BMA400_TAP_CONFIG1, 1211 + &reg_val); 1212 + if (ret) 1213 + return ret; 1214 + 1215 + raw = FIELD_GET(BMA400_TAP_QUIET_MSK, reg_val); 1216 + *val = 0; 1217 + *val2 = tap_reset_timeout[raw]; 1218 + return IIO_VAL_INT_PLUS_MICRO; 1219 + case IIO_EV_INFO_TAP2_MIN_DELAY: 1220 + ret = regmap_read(data->regmap, BMA400_TAP_CONFIG1, 1221 + &reg_val); 1222 + if (ret) 1223 + return ret; 1224 + 1225 + raw = FIELD_GET(BMA400_TAP_QUIETDT_MSK, reg_val); 1226 + *val = 0; 1227 + *val2 = double_tap2_min_delay[raw]; 1228 + return IIO_VAL_INT_PLUS_MICRO; 1229 + default: 1230 + return -EINVAL; 1231 + } 1424 1232 default: 1425 1233 return -EINVAL; 1426 1234 } ··· 1467 1209 int val, int val2) 1468 1210 { 1469 1211 struct bma400_data *data = iio_priv(indio_dev); 1470 - int reg, ret; 1212 + int reg, ret, raw; 1471 1213 1472 - switch (chan->type) { 1473 - case IIO_ACCEL: 1214 + if (chan->type != IIO_ACCEL) 1215 + return -EINVAL; 1216 + 1217 + switch (type) { 1218 + case IIO_EV_TYPE_MAG: 1474 1219 reg = get_gen_config_reg(dir); 1475 1220 if (reg < 0) 1476 1221 return -EINVAL; ··· 1506 1245 BMA400_GEN_HYST_MSK, 1507 1246 FIELD_PREP(BMA400_GEN_HYST_MSK, 1508 1247 val)); 1248 + default: 1249 + return -EINVAL; 1250 + } 1251 + case IIO_EV_TYPE_GESTURE: 1252 + switch (info) { 1253 + case IIO_EV_INFO_VALUE: 1254 + if (val < 0 || val > 7) 1255 + return -EINVAL; 1256 + 1257 + return regmap_update_bits(data->regmap, 1258 + BMA400_TAP_CONFIG, 1259 + BMA400_TAP_SEN_MSK, 1260 + FIELD_PREP(BMA400_TAP_SEN_MSK, 1261 + val)); 1262 + case IIO_EV_INFO_RESET_TIMEOUT: 1263 + raw = usec_to_tapreg_raw(val2, tap_reset_timeout); 1264 + if (raw < 0) 1265 + return -EINVAL; 1266 + 1267 + return regmap_update_bits(data->regmap, 1268 + BMA400_TAP_CONFIG1, 1269 + BMA400_TAP_QUIET_MSK, 1270 + FIELD_PREP(BMA400_TAP_QUIET_MSK, 1271 + raw)); 1272 + case IIO_EV_INFO_TAP2_MIN_DELAY: 1273 + raw = usec_to_tapreg_raw(val2, double_tap2_min_delay); 1274 + if (raw < 0) 1275 + return -EINVAL; 1276 + 1277 + return regmap_update_bits(data->regmap, 1278 + BMA400_TAP_CONFIG1, 1279 + BMA400_TAP_QUIETDT_MSK, 1280 + FIELD_PREP(BMA400_TAP_QUIETDT_MSK, 1281 + raw)); 1509 1282 default: 1510 1283 return -EINVAL; 1511 1284 } ··· 1582 1287 .write_event_config = bma400_write_event_config, 1583 1288 .write_event_value = bma400_write_event_value, 1584 1289 .read_event_value = bma400_read_event_value, 1290 + .event_attrs = &bma400_event_attribute_group, 1585 1291 }; 1586 1292 1587 1293 static const struct iio_trigger_ops bma400_trigger_ops = { ··· 1645 1349 */ 1646 1350 if (ret || !data->status) 1647 1351 goto unlock_err; 1352 + 1353 + /* 1354 + * Disable all advance interrupts if interrupt engine overrun occurs. 1355 + * See section 4.7 "Interrupt engine overrun" in datasheet v1.2. 1356 + */ 1357 + if (FIELD_GET(BMA400_INT_ENG_OVRUN_MSK, le16_to_cpu(data->status))) { 1358 + bma400_disable_adv_interrupt(data); 1359 + dev_err(data->dev, "Interrupt engine overrun\n"); 1360 + goto unlock_err; 1361 + } 1362 + 1363 + if (FIELD_GET(BMA400_INT_S_TAP_MSK, le16_to_cpu(data->status))) 1364 + iio_push_event(indio_dev, 1365 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, 1366 + IIO_MOD_X_OR_Y_OR_Z, 1367 + IIO_EV_TYPE_GESTURE, 1368 + IIO_EV_DIR_SINGLETAP), 1369 + timestamp); 1370 + 1371 + if (FIELD_GET(BMA400_INT_D_TAP_MSK, le16_to_cpu(data->status))) 1372 + iio_push_event(indio_dev, 1373 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, 1374 + IIO_MOD_X_OR_Y_OR_Z, 1375 + IIO_EV_TYPE_GESTURE, 1376 + IIO_EV_DIR_DOUBLETAP), 1377 + timestamp); 1648 1378 1649 1379 if (FIELD_GET(BMA400_INT_GEN1_MSK, le16_to_cpu(data->status))) 1650 1380 ev_dir = IIO_EV_DIR_RISING; ··· 1789 1467 EXPORT_SYMBOL_NS(bma400_probe, IIO_BMA400); 1790 1468 1791 1469 MODULE_AUTHOR("Dan Robertson <dan@dlrobertson.com>"); 1470 + MODULE_AUTHOR("Jagath Jog J <jagathjog1996@gmail.com>"); 1792 1471 MODULE_DESCRIPTION("Bosch BMA400 triaxial acceleration sensor core"); 1793 1472 MODULE_LICENSE("GPL");
+1 -1
drivers/iio/accel/kxcjk-1013.c
··· 1064 1064 1065 1065 /* 1066 1066 * We will expect the enable and disable to do operation in 1067 - * in reverse order. This will happen here anyway as our 1067 + * reverse order. This will happen here anyway as our 1068 1068 * resume operation uses sync mode runtime pm calls, the 1069 1069 * suspend operation will be delayed by autosuspend delay 1070 1070 * So the disable operation will still happen in reverse of
+1321
drivers/iio/accel/msa311.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * MEMSensing digital 3-Axis accelerometer 4 + * 5 + * MSA311 is a tri-axial, low-g accelerometer with I2C digital output for 6 + * sensitivity consumer applications. It has dynamic user-selectable full 7 + * scales range of +-2g/+-4g/+-8g/+-16g and allows acceleration measurements 8 + * with output data rates from 1Hz to 1000Hz. 9 + * 10 + * MSA311 is available in an ultra small (2mm x 2mm, height 0.95mm) LGA package 11 + * and is guaranteed to operate over -40C to +85C. 12 + * 13 + * This driver supports following MSA311 features: 14 + * - IIO interface 15 + * - Different power modes: NORMAL, SUSPEND 16 + * - ODR (Output Data Rate) selection 17 + * - Scale selection 18 + * - IIO triggered buffer 19 + * - NEW_DATA interrupt + trigger 20 + * 21 + * Below features to be done: 22 + * - Motion Events: ACTIVE, TAP, ORIENT, FREEFALL 23 + * - Low Power mode 24 + * 25 + * Copyright (c) 2022, SberDevices. All Rights Reserved. 26 + * 27 + * Author: Dmitry Rokosov <ddrokosov@sberdevices.ru> 28 + */ 29 + 30 + #include <linux/i2c.h> 31 + #include <linux/mod_devicetable.h> 32 + #include <linux/module.h> 33 + #include <linux/pm.h> 34 + #include <linux/pm_runtime.h> 35 + #include <linux/regmap.h> 36 + #include <linux/string_helpers.h> 37 + #include <linux/units.h> 38 + 39 + #include <linux/iio/buffer.h> 40 + #include <linux/iio/iio.h> 41 + #include <linux/iio/sysfs.h> 42 + #include <linux/iio/trigger.h> 43 + #include <linux/iio/trigger_consumer.h> 44 + #include <linux/iio/triggered_buffer.h> 45 + 46 + #define MSA311_SOFT_RESET_REG 0x00 47 + #define MSA311_PARTID_REG 0x01 48 + #define MSA311_ACC_X_REG 0x02 49 + #define MSA311_ACC_Y_REG 0x04 50 + #define MSA311_ACC_Z_REG 0x06 51 + #define MSA311_MOTION_INT_REG 0x09 52 + #define MSA311_DATA_INT_REG 0x0A 53 + #define MSA311_TAP_ACTIVE_STS_REG 0x0B 54 + #define MSA311_ORIENT_STS_REG 0x0C 55 + #define MSA311_RANGE_REG 0x0F 56 + #define MSA311_ODR_REG 0x10 57 + #define MSA311_PWR_MODE_REG 0x11 58 + #define MSA311_SWAP_POLARITY_REG 0x12 59 + #define MSA311_INT_SET_0_REG 0x16 60 + #define MSA311_INT_SET_1_REG 0x17 61 + #define MSA311_INT_MAP_0_REG 0x19 62 + #define MSA311_INT_MAP_1_REG 0x1A 63 + #define MSA311_INT_CONFIG_REG 0x20 64 + #define MSA311_INT_LATCH_REG 0x21 65 + #define MSA311_FREEFALL_DUR_REG 0x22 66 + #define MSA311_FREEFALL_TH_REG 0x23 67 + #define MSA311_FREEFALL_HY_REG 0x24 68 + #define MSA311_ACTIVE_DUR_REG 0x27 69 + #define MSA311_ACTIVE_TH_REG 0x28 70 + #define MSA311_TAP_DUR_REG 0x2A 71 + #define MSA311_TAP_TH_REG 0x2B 72 + #define MSA311_ORIENT_HY_REG 0x2C 73 + #define MSA311_Z_BLOCK_REG 0x2D 74 + #define MSA311_OFFSET_X_REG 0x38 75 + #define MSA311_OFFSET_Y_REG 0x39 76 + #define MSA311_OFFSET_Z_REG 0x3A 77 + 78 + enum msa311_fields { 79 + /* Soft_Reset */ 80 + F_SOFT_RESET_I2C, F_SOFT_RESET_SPI, 81 + /* Motion_Interrupt */ 82 + F_ORIENT_INT, F_S_TAP_INT, F_D_TAP_INT, F_ACTIVE_INT, F_FREEFALL_INT, 83 + /* Data_Interrupt */ 84 + F_NEW_DATA_INT, 85 + /* Tap_Active_Status */ 86 + F_TAP_SIGN, F_TAP_FIRST_X, F_TAP_FIRST_Y, F_TAP_FIRST_Z, F_ACTV_SIGN, 87 + F_ACTV_FIRST_X, F_ACTV_FIRST_Y, F_ACTV_FIRST_Z, 88 + /* Orientation_Status */ 89 + F_ORIENT_Z, F_ORIENT_X_Y, 90 + /* Range */ 91 + F_FS, 92 + /* ODR */ 93 + F_X_AXIS_DIS, F_Y_AXIS_DIS, F_Z_AXIS_DIS, F_ODR, 94 + /* Power Mode/Bandwidth */ 95 + F_PWR_MODE, F_LOW_POWER_BW, 96 + /* Swap_Polarity */ 97 + F_X_POLARITY, F_Y_POLARITY, F_Z_POLARITY, F_X_Y_SWAP, 98 + /* Int_Set_0 */ 99 + F_ORIENT_INT_EN, F_S_TAP_INT_EN, F_D_TAP_INT_EN, F_ACTIVE_INT_EN_Z, 100 + F_ACTIVE_INT_EN_Y, F_ACTIVE_INT_EN_X, 101 + /* Int_Set_1 */ 102 + F_NEW_DATA_INT_EN, F_FREEFALL_INT_EN, 103 + /* Int_Map_0 */ 104 + F_INT1_ORIENT, F_INT1_S_TAP, F_INT1_D_TAP, F_INT1_ACTIVE, 105 + F_INT1_FREEFALL, 106 + /* Int_Map_1 */ 107 + F_INT1_NEW_DATA, 108 + /* Int_Config */ 109 + F_INT1_OD, F_INT1_LVL, 110 + /* Int_Latch */ 111 + F_RESET_INT, F_LATCH_INT, 112 + /* Freefall_Hy */ 113 + F_FREEFALL_MODE, F_FREEFALL_HY, 114 + /* Active_Dur */ 115 + F_ACTIVE_DUR, 116 + /* Tap_Dur */ 117 + F_TAP_QUIET, F_TAP_SHOCK, F_TAP_DUR, 118 + /* Tap_Th */ 119 + F_TAP_TH, 120 + /* Orient_Hy */ 121 + F_ORIENT_HYST, F_ORIENT_BLOCKING, F_ORIENT_MODE, 122 + /* Z_Block */ 123 + F_Z_BLOCKING, 124 + /* End of register map */ 125 + F_MAX_FIELDS, 126 + }; 127 + 128 + static const struct reg_field msa311_reg_fields[] = { 129 + /* Soft_Reset */ 130 + [F_SOFT_RESET_I2C] = REG_FIELD(MSA311_SOFT_RESET_REG, 2, 2), 131 + [F_SOFT_RESET_SPI] = REG_FIELD(MSA311_SOFT_RESET_REG, 5, 5), 132 + /* Motion_Interrupt */ 133 + [F_ORIENT_INT] = REG_FIELD(MSA311_MOTION_INT_REG, 6, 6), 134 + [F_S_TAP_INT] = REG_FIELD(MSA311_MOTION_INT_REG, 5, 5), 135 + [F_D_TAP_INT] = REG_FIELD(MSA311_MOTION_INT_REG, 4, 4), 136 + [F_ACTIVE_INT] = REG_FIELD(MSA311_MOTION_INT_REG, 2, 2), 137 + [F_FREEFALL_INT] = REG_FIELD(MSA311_MOTION_INT_REG, 0, 0), 138 + /* Data_Interrupt */ 139 + [F_NEW_DATA_INT] = REG_FIELD(MSA311_DATA_INT_REG, 0, 0), 140 + /* Tap_Active_Status */ 141 + [F_TAP_SIGN] = REG_FIELD(MSA311_TAP_ACTIVE_STS_REG, 7, 7), 142 + [F_TAP_FIRST_X] = REG_FIELD(MSA311_TAP_ACTIVE_STS_REG, 6, 6), 143 + [F_TAP_FIRST_Y] = REG_FIELD(MSA311_TAP_ACTIVE_STS_REG, 5, 5), 144 + [F_TAP_FIRST_Z] = REG_FIELD(MSA311_TAP_ACTIVE_STS_REG, 4, 4), 145 + [F_ACTV_SIGN] = REG_FIELD(MSA311_TAP_ACTIVE_STS_REG, 3, 3), 146 + [F_ACTV_FIRST_X] = REG_FIELD(MSA311_TAP_ACTIVE_STS_REG, 2, 2), 147 + [F_ACTV_FIRST_Y] = REG_FIELD(MSA311_TAP_ACTIVE_STS_REG, 1, 1), 148 + [F_ACTV_FIRST_Z] = REG_FIELD(MSA311_TAP_ACTIVE_STS_REG, 0, 0), 149 + /* Orientation_Status */ 150 + [F_ORIENT_Z] = REG_FIELD(MSA311_ORIENT_STS_REG, 6, 6), 151 + [F_ORIENT_X_Y] = REG_FIELD(MSA311_ORIENT_STS_REG, 4, 5), 152 + /* Range */ 153 + [F_FS] = REG_FIELD(MSA311_RANGE_REG, 0, 1), 154 + /* ODR */ 155 + [F_X_AXIS_DIS] = REG_FIELD(MSA311_ODR_REG, 7, 7), 156 + [F_Y_AXIS_DIS] = REG_FIELD(MSA311_ODR_REG, 6, 6), 157 + [F_Z_AXIS_DIS] = REG_FIELD(MSA311_ODR_REG, 5, 5), 158 + [F_ODR] = REG_FIELD(MSA311_ODR_REG, 0, 3), 159 + /* Power Mode/Bandwidth */ 160 + [F_PWR_MODE] = REG_FIELD(MSA311_PWR_MODE_REG, 6, 7), 161 + [F_LOW_POWER_BW] = REG_FIELD(MSA311_PWR_MODE_REG, 1, 4), 162 + /* Swap_Polarity */ 163 + [F_X_POLARITY] = REG_FIELD(MSA311_SWAP_POLARITY_REG, 3, 3), 164 + [F_Y_POLARITY] = REG_FIELD(MSA311_SWAP_POLARITY_REG, 2, 2), 165 + [F_Z_POLARITY] = REG_FIELD(MSA311_SWAP_POLARITY_REG, 1, 1), 166 + [F_X_Y_SWAP] = REG_FIELD(MSA311_SWAP_POLARITY_REG, 0, 0), 167 + /* Int_Set_0 */ 168 + [F_ORIENT_INT_EN] = REG_FIELD(MSA311_INT_SET_0_REG, 6, 6), 169 + [F_S_TAP_INT_EN] = REG_FIELD(MSA311_INT_SET_0_REG, 5, 5), 170 + [F_D_TAP_INT_EN] = REG_FIELD(MSA311_INT_SET_0_REG, 4, 4), 171 + [F_ACTIVE_INT_EN_Z] = REG_FIELD(MSA311_INT_SET_0_REG, 2, 2), 172 + [F_ACTIVE_INT_EN_Y] = REG_FIELD(MSA311_INT_SET_0_REG, 1, 1), 173 + [F_ACTIVE_INT_EN_X] = REG_FIELD(MSA311_INT_SET_0_REG, 0, 0), 174 + /* Int_Set_1 */ 175 + [F_NEW_DATA_INT_EN] = REG_FIELD(MSA311_INT_SET_1_REG, 4, 4), 176 + [F_FREEFALL_INT_EN] = REG_FIELD(MSA311_INT_SET_1_REG, 3, 3), 177 + /* Int_Map_0 */ 178 + [F_INT1_ORIENT] = REG_FIELD(MSA311_INT_MAP_0_REG, 6, 6), 179 + [F_INT1_S_TAP] = REG_FIELD(MSA311_INT_MAP_0_REG, 5, 5), 180 + [F_INT1_D_TAP] = REG_FIELD(MSA311_INT_MAP_0_REG, 4, 4), 181 + [F_INT1_ACTIVE] = REG_FIELD(MSA311_INT_MAP_0_REG, 2, 2), 182 + [F_INT1_FREEFALL] = REG_FIELD(MSA311_INT_MAP_0_REG, 0, 0), 183 + /* Int_Map_1 */ 184 + [F_INT1_NEW_DATA] = REG_FIELD(MSA311_INT_MAP_1_REG, 0, 0), 185 + /* Int_Config */ 186 + [F_INT1_OD] = REG_FIELD(MSA311_INT_CONFIG_REG, 1, 1), 187 + [F_INT1_LVL] = REG_FIELD(MSA311_INT_CONFIG_REG, 0, 0), 188 + /* Int_Latch */ 189 + [F_RESET_INT] = REG_FIELD(MSA311_INT_LATCH_REG, 7, 7), 190 + [F_LATCH_INT] = REG_FIELD(MSA311_INT_LATCH_REG, 0, 3), 191 + /* Freefall_Hy */ 192 + [F_FREEFALL_MODE] = REG_FIELD(MSA311_FREEFALL_HY_REG, 2, 2), 193 + [F_FREEFALL_HY] = REG_FIELD(MSA311_FREEFALL_HY_REG, 0, 1), 194 + /* Active_Dur */ 195 + [F_ACTIVE_DUR] = REG_FIELD(MSA311_ACTIVE_DUR_REG, 0, 1), 196 + /* Tap_Dur */ 197 + [F_TAP_QUIET] = REG_FIELD(MSA311_TAP_DUR_REG, 7, 7), 198 + [F_TAP_SHOCK] = REG_FIELD(MSA311_TAP_DUR_REG, 6, 6), 199 + [F_TAP_DUR] = REG_FIELD(MSA311_TAP_DUR_REG, 0, 2), 200 + /* Tap_Th */ 201 + [F_TAP_TH] = REG_FIELD(MSA311_TAP_TH_REG, 0, 4), 202 + /* Orient_Hy */ 203 + [F_ORIENT_HYST] = REG_FIELD(MSA311_ORIENT_HY_REG, 4, 6), 204 + [F_ORIENT_BLOCKING] = REG_FIELD(MSA311_ORIENT_HY_REG, 2, 3), 205 + [F_ORIENT_MODE] = REG_FIELD(MSA311_ORIENT_HY_REG, 0, 1), 206 + /* Z_Block */ 207 + [F_Z_BLOCKING] = REG_FIELD(MSA311_Z_BLOCK_REG, 0, 3), 208 + }; 209 + 210 + #define MSA311_WHO_AM_I 0x13 211 + 212 + /* 213 + * Possible Full Scale ranges 214 + * 215 + * Axis data is 12-bit signed value, so 216 + * 217 + * fs0 = (2 + 2) * 9.81 / (2^11) = 0.009580 218 + * fs1 = (4 + 4) * 9.81 / (2^11) = 0.019160 219 + * fs2 = (8 + 8) * 9.81 / (2^11) = 0.038320 220 + * fs3 = (16 + 16) * 9.81 / (2^11) = 0.076641 221 + */ 222 + enum { 223 + MSA311_FS_2G, 224 + MSA311_FS_4G, 225 + MSA311_FS_8G, 226 + MSA311_FS_16G, 227 + }; 228 + 229 + struct iio_decimal_fract { 230 + int integral; 231 + int microfract; 232 + }; 233 + 234 + static const struct iio_decimal_fract msa311_fs_table[] = { 235 + {0, 9580}, {0, 19160}, {0, 38320}, {0, 76641}, 236 + }; 237 + 238 + /* Possible Output Data Rate values */ 239 + enum { 240 + MSA311_ODR_1_HZ, 241 + MSA311_ODR_1_95_HZ, 242 + MSA311_ODR_3_9_HZ, 243 + MSA311_ODR_7_81_HZ, 244 + MSA311_ODR_15_63_HZ, 245 + MSA311_ODR_31_25_HZ, 246 + MSA311_ODR_62_5_HZ, 247 + MSA311_ODR_125_HZ, 248 + MSA311_ODR_250_HZ, 249 + MSA311_ODR_500_HZ, 250 + MSA311_ODR_1000_HZ, 251 + }; 252 + 253 + static const struct iio_decimal_fract msa311_odr_table[] = { 254 + {1, 0}, {1, 950000}, {3, 900000}, {7, 810000}, {15, 630000}, 255 + {31, 250000}, {62, 500000}, {125, 0}, {250, 0}, {500, 0}, {1000, 0}, 256 + }; 257 + 258 + /* All supported power modes */ 259 + #define MSA311_PWR_MODE_NORMAL 0b00 260 + #define MSA311_PWR_MODE_LOW 0b01 261 + #define MSA311_PWR_MODE_UNKNOWN 0b10 262 + #define MSA311_PWR_MODE_SUSPEND 0b11 263 + static const char * const msa311_pwr_modes[] = { 264 + [MSA311_PWR_MODE_NORMAL] = "normal", 265 + [MSA311_PWR_MODE_LOW] = "low", 266 + [MSA311_PWR_MODE_UNKNOWN] = "unknown", 267 + [MSA311_PWR_MODE_SUSPEND] = "suspend", 268 + }; 269 + 270 + /* Autosuspend delay */ 271 + #define MSA311_PWR_SLEEP_DELAY_MS 2000 272 + 273 + /* Possible INT1 types and levels */ 274 + enum { 275 + MSA311_INT1_OD_PUSH_PULL, 276 + MSA311_INT1_OD_OPEN_DRAIN, 277 + }; 278 + 279 + enum { 280 + MSA311_INT1_LVL_LOW, 281 + MSA311_INT1_LVL_HIGH, 282 + }; 283 + 284 + /* Latch INT modes */ 285 + #define MSA311_LATCH_INT_NOT_LATCHED 0b0000 286 + #define MSA311_LATCH_INT_250MS 0b0001 287 + #define MSA311_LATCH_INT_500MS 0b0010 288 + #define MSA311_LATCH_INT_1S 0b0011 289 + #define MSA311_LATCH_INT_2S 0b0100 290 + #define MSA311_LATCH_INT_4S 0b0101 291 + #define MSA311_LATCH_INT_8S 0b0110 292 + #define MSA311_LATCH_INT_1MS 0b1010 293 + #define MSA311_LATCH_INT_2MS 0b1011 294 + #define MSA311_LATCH_INT_25MS 0b1100 295 + #define MSA311_LATCH_INT_50MS 0b1101 296 + #define MSA311_LATCH_INT_100MS 0b1110 297 + #define MSA311_LATCH_INT_LATCHED 0b0111 298 + 299 + static const struct regmap_range msa311_readonly_registers[] = { 300 + regmap_reg_range(MSA311_PARTID_REG, MSA311_ORIENT_STS_REG), 301 + }; 302 + 303 + static const struct regmap_access_table msa311_writeable_table = { 304 + .no_ranges = msa311_readonly_registers, 305 + .n_no_ranges = ARRAY_SIZE(msa311_readonly_registers), 306 + }; 307 + 308 + static const struct regmap_range msa311_writeonly_registers[] = { 309 + regmap_reg_range(MSA311_SOFT_RESET_REG, MSA311_SOFT_RESET_REG), 310 + }; 311 + 312 + static const struct regmap_access_table msa311_readable_table = { 313 + .no_ranges = msa311_writeonly_registers, 314 + .n_no_ranges = ARRAY_SIZE(msa311_writeonly_registers), 315 + }; 316 + 317 + static const struct regmap_range msa311_volatile_registers[] = { 318 + regmap_reg_range(MSA311_ACC_X_REG, MSA311_ORIENT_STS_REG), 319 + }; 320 + 321 + static const struct regmap_access_table msa311_volatile_table = { 322 + .yes_ranges = msa311_volatile_registers, 323 + .n_yes_ranges = ARRAY_SIZE(msa311_volatile_registers), 324 + }; 325 + 326 + static const struct regmap_config msa311_regmap_config = { 327 + .name = "msa311", 328 + .reg_bits = 8, 329 + .val_bits = 8, 330 + .max_register = MSA311_OFFSET_Z_REG, 331 + .wr_table = &msa311_writeable_table, 332 + .rd_table = &msa311_readable_table, 333 + .volatile_table = &msa311_volatile_table, 334 + .cache_type = REGCACHE_RBTREE, 335 + }; 336 + 337 + #define MSA311_GENMASK(field) ({ \ 338 + typeof(&(msa311_reg_fields)[0]) _field; \ 339 + _field = &msa311_reg_fields[(field)]; \ 340 + GENMASK(_field->msb, _field->lsb); \ 341 + }) 342 + 343 + /** 344 + * struct msa311_priv - MSA311 internal private state 345 + * @regs: Underlying I2C bus adapter used to abstract slave 346 + * register accesses 347 + * @fields: Abstract objects for each registers fields access 348 + * @dev: Device handler associated with appropriate bus client 349 + * @lock: Protects msa311 device state between setup and data access routines 350 + * (power transitions, samp_freq/scale tune, retrieving axes data, etc) 351 + * @chip_name: Chip name in the format "msa311-%02x" % partid 352 + * @new_data_trig: Optional NEW_DATA interrupt driven trigger used 353 + * to notify external consumers a new sample is ready 354 + * @vdd: Optional external voltage regulator for the device power supply 355 + */ 356 + struct msa311_priv { 357 + struct regmap *regs; 358 + struct regmap_field *fields[F_MAX_FIELDS]; 359 + 360 + struct device *dev; 361 + struct mutex lock; 362 + char *chip_name; 363 + 364 + struct iio_trigger *new_data_trig; 365 + struct regulator *vdd; 366 + }; 367 + 368 + enum msa311_si { 369 + MSA311_SI_X, 370 + MSA311_SI_Y, 371 + MSA311_SI_Z, 372 + MSA311_SI_TIMESTAMP, 373 + }; 374 + 375 + #define MSA311_ACCEL_CHANNEL(axis) { \ 376 + .type = IIO_ACCEL, \ 377 + .modified = 1, \ 378 + .channel2 = IIO_MOD_##axis, \ 379 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 380 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 381 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 382 + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE) | \ 383 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 384 + .scan_index = MSA311_SI_##axis, \ 385 + .scan_type = { \ 386 + .sign = 's', \ 387 + .realbits = 12, \ 388 + .storagebits = 16, \ 389 + .shift = 4, \ 390 + .endianness = IIO_LE, \ 391 + }, \ 392 + .datasheet_name = "ACC_"#axis, \ 393 + } 394 + 395 + static const struct iio_chan_spec msa311_channels[] = { 396 + MSA311_ACCEL_CHANNEL(X), 397 + MSA311_ACCEL_CHANNEL(Y), 398 + MSA311_ACCEL_CHANNEL(Z), 399 + IIO_CHAN_SOFT_TIMESTAMP(MSA311_SI_TIMESTAMP), 400 + }; 401 + 402 + /** 403 + * msa311_get_odr() - Read Output Data Rate (ODR) value from MSA311 accel 404 + * @msa311: MSA311 internal private state 405 + * @odr: output ODR value 406 + * 407 + * This function should be called under msa311->lock. 408 + * 409 + * Return: 0 on success, -ERRNO in other failures 410 + */ 411 + static int msa311_get_odr(struct msa311_priv *msa311, unsigned int *odr) 412 + { 413 + int err; 414 + 415 + err = regmap_field_read(msa311->fields[F_ODR], odr); 416 + if (err) 417 + return err; 418 + 419 + /* 420 + * Filter the same 1000Hz ODR register values based on datasheet info. 421 + * ODR can be equal to 1010-1111 for 1000Hz, but function returns 1010 422 + * all the time. 423 + */ 424 + if (*odr > MSA311_ODR_1000_HZ) 425 + *odr = MSA311_ODR_1000_HZ; 426 + 427 + return 0; 428 + } 429 + 430 + /** 431 + * msa311_set_odr() - Setup Output Data Rate (ODR) value for MSA311 accel 432 + * @msa311: MSA311 internal private state 433 + * @odr: requested ODR value 434 + * 435 + * This function should be called under msa311->lock. Possible ODR values: 436 + * - 1Hz (not available in normal mode) 437 + * - 1.95Hz (not available in normal mode) 438 + * - 3.9Hz 439 + * - 7.81Hz 440 + * - 15.63Hz 441 + * - 31.25Hz 442 + * - 62.5Hz 443 + * - 125Hz 444 + * - 250Hz 445 + * - 500Hz 446 + * - 1000Hz 447 + * 448 + * Return: 0 on success, -EINVAL for bad ODR value in the certain power mode, 449 + * -ERRNO in other failures 450 + */ 451 + static int msa311_set_odr(struct msa311_priv *msa311, unsigned int odr) 452 + { 453 + struct device *dev = msa311->dev; 454 + unsigned int pwr_mode; 455 + bool good_odr; 456 + int err; 457 + 458 + err = regmap_field_read(msa311->fields[F_PWR_MODE], &pwr_mode); 459 + if (err) 460 + return err; 461 + 462 + /* Filter bad ODR values */ 463 + if (pwr_mode == MSA311_PWR_MODE_NORMAL) 464 + good_odr = (odr > MSA311_ODR_1_95_HZ); 465 + else 466 + good_odr = false; 467 + 468 + if (!good_odr) { 469 + dev_err(dev, 470 + "can't set odr %u.%06uHz, not available in %s mode\n", 471 + msa311_odr_table[odr].integral, 472 + msa311_odr_table[odr].microfract, 473 + msa311_pwr_modes[pwr_mode]); 474 + return -EINVAL; 475 + } 476 + 477 + return regmap_field_write(msa311->fields[F_ODR], odr); 478 + } 479 + 480 + /** 481 + * msa311_wait_for_next_data() - Wait next accel data available after resume 482 + * @msa311: MSA311 internal private state 483 + * 484 + * Return: 0 on success, -EINTR if msleep() was interrupted, 485 + * -ERRNO in other failures 486 + */ 487 + static int msa311_wait_for_next_data(struct msa311_priv *msa311) 488 + { 489 + static const unsigned int unintr_thresh_ms = 20; 490 + struct device *dev = msa311->dev; 491 + unsigned long freq_uhz; 492 + unsigned long wait_ms; 493 + unsigned int odr; 494 + int err; 495 + 496 + err = msa311_get_odr(msa311, &odr); 497 + if (err) { 498 + dev_err(dev, "can't get actual frequency (%pe)\n", 499 + ERR_PTR(err)); 500 + return err; 501 + } 502 + 503 + /* 504 + * After msa311 resuming is done, we need to wait for data 505 + * to be refreshed by accel logic. 506 + * A certain timeout is calculated based on the current ODR value. 507 + * If requested timeout isn't so long (let's assume 20ms), 508 + * we can wait for next data in uninterruptible sleep. 509 + */ 510 + freq_uhz = msa311_odr_table[odr].integral * MICROHZ_PER_HZ + 511 + msa311_odr_table[odr].microfract; 512 + wait_ms = (MICROHZ_PER_HZ / freq_uhz) * MSEC_PER_SEC; 513 + 514 + if (wait_ms < unintr_thresh_ms) 515 + usleep_range(wait_ms * USEC_PER_MSEC, 516 + unintr_thresh_ms * USEC_PER_MSEC); 517 + else if (msleep_interruptible(wait_ms)) 518 + return -EINTR; 519 + 520 + return 0; 521 + } 522 + 523 + /** 524 + * msa311_set_pwr_mode() - Install certain MSA311 power mode 525 + * @msa311: MSA311 internal private state 526 + * @mode: Power mode can be equal to NORMAL or SUSPEND 527 + * 528 + * This function should be called under msa311->lock. 529 + * 530 + * Return: 0 on success, -ERRNO on failure 531 + */ 532 + static int msa311_set_pwr_mode(struct msa311_priv *msa311, unsigned int mode) 533 + { 534 + struct device *dev = msa311->dev; 535 + unsigned int prev_mode; 536 + int err; 537 + 538 + if (mode >= ARRAY_SIZE(msa311_pwr_modes)) 539 + return -EINVAL; 540 + 541 + dev_dbg(dev, "transition to %s mode\n", msa311_pwr_modes[mode]); 542 + 543 + err = regmap_field_read(msa311->fields[F_PWR_MODE], &prev_mode); 544 + if (err) 545 + return err; 546 + 547 + err = regmap_field_write(msa311->fields[F_PWR_MODE], mode); 548 + if (err) 549 + return err; 550 + 551 + /* Wait actual data if we wake up */ 552 + if (prev_mode == MSA311_PWR_MODE_SUSPEND && 553 + mode == MSA311_PWR_MODE_NORMAL) 554 + return msa311_wait_for_next_data(msa311); 555 + 556 + return 0; 557 + } 558 + 559 + /** 560 + * msa311_get_axis() - Read MSA311 accel data for certain IIO channel axis spec 561 + * @msa311: MSA311 internal private state 562 + * @chan: IIO channel specification 563 + * @axis: Output accel axis data for requested IIO channel spec 564 + * 565 + * This function should be called under msa311->lock. 566 + * 567 + * Return: 0 on success, -EINVAL for unknown IIO channel specification, 568 + * -ERRNO in other failures 569 + */ 570 + static int msa311_get_axis(struct msa311_priv *msa311, 571 + const struct iio_chan_spec * const chan, 572 + __le16 *axis) 573 + { 574 + struct device *dev = msa311->dev; 575 + unsigned int axis_reg; 576 + 577 + if (chan->scan_index < MSA311_SI_X || chan->scan_index > MSA311_SI_Z) { 578 + dev_err(dev, "invalid scan_index value [%d]\n", 579 + chan->scan_index); 580 + return -EINVAL; 581 + } 582 + 583 + /* Axes data layout has 2 byte gap for each axis starting from X axis */ 584 + axis_reg = MSA311_ACC_X_REG + (chan->scan_index << 1); 585 + 586 + return regmap_bulk_read(msa311->regs, axis_reg, axis, sizeof(*axis)); 587 + } 588 + 589 + static int msa311_read_raw_data(struct iio_dev *indio_dev, 590 + struct iio_chan_spec const *chan, 591 + int *val, int *val2) 592 + { 593 + struct msa311_priv *msa311 = iio_priv(indio_dev); 594 + struct device *dev = msa311->dev; 595 + __le16 axis; 596 + int err; 597 + 598 + err = pm_runtime_resume_and_get(dev); 599 + if (err) 600 + return err; 601 + 602 + err = iio_device_claim_direct_mode(indio_dev); 603 + if (err) 604 + return err; 605 + 606 + mutex_lock(&msa311->lock); 607 + err = msa311_get_axis(msa311, chan, &axis); 608 + mutex_unlock(&msa311->lock); 609 + 610 + iio_device_release_direct_mode(indio_dev); 611 + 612 + pm_runtime_mark_last_busy(dev); 613 + pm_runtime_put_autosuspend(dev); 614 + 615 + if (err) { 616 + dev_err(dev, "can't get axis %s (%pe)\n", 617 + chan->datasheet_name, ERR_PTR(err)); 618 + return err; 619 + } 620 + 621 + /* 622 + * Axis data format is: 623 + * ACC_X = (ACC_X_MSB[7:0] << 4) | ACC_X_LSB[7:4] 624 + */ 625 + *val = sign_extend32(le16_to_cpu(axis) >> chan->scan_type.shift, 626 + chan->scan_type.realbits - 1); 627 + 628 + return IIO_VAL_INT; 629 + } 630 + 631 + static int msa311_read_scale(struct iio_dev *indio_dev, int *val, int *val2) 632 + { 633 + struct msa311_priv *msa311 = iio_priv(indio_dev); 634 + struct device *dev = msa311->dev; 635 + unsigned int fs; 636 + int err; 637 + 638 + mutex_lock(&msa311->lock); 639 + err = regmap_field_read(msa311->fields[F_FS], &fs); 640 + mutex_unlock(&msa311->lock); 641 + if (err) { 642 + dev_err(dev, "can't get actual scale (%pe)\n", ERR_PTR(err)); 643 + return err; 644 + } 645 + 646 + *val = msa311_fs_table[fs].integral; 647 + *val2 = msa311_fs_table[fs].microfract; 648 + 649 + return IIO_VAL_INT_PLUS_MICRO; 650 + } 651 + 652 + static int msa311_read_samp_freq(struct iio_dev *indio_dev, 653 + int *val, int *val2) 654 + { 655 + struct msa311_priv *msa311 = iio_priv(indio_dev); 656 + struct device *dev = msa311->dev; 657 + unsigned int odr; 658 + int err; 659 + 660 + mutex_lock(&msa311->lock); 661 + err = msa311_get_odr(msa311, &odr); 662 + mutex_unlock(&msa311->lock); 663 + if (err) { 664 + dev_err(dev, "can't get actual frequency (%pe)\n", 665 + ERR_PTR(err)); 666 + return err; 667 + } 668 + 669 + *val = msa311_odr_table[odr].integral; 670 + *val2 = msa311_odr_table[odr].microfract; 671 + 672 + return IIO_VAL_INT_PLUS_MICRO; 673 + } 674 + 675 + static int msa311_read_raw(struct iio_dev *indio_dev, 676 + struct iio_chan_spec const *chan, 677 + int *val, int *val2, long mask) 678 + { 679 + switch (mask) { 680 + case IIO_CHAN_INFO_RAW: 681 + return msa311_read_raw_data(indio_dev, chan, val, val2); 682 + 683 + case IIO_CHAN_INFO_SCALE: 684 + return msa311_read_scale(indio_dev, val, val2); 685 + 686 + case IIO_CHAN_INFO_SAMP_FREQ: 687 + return msa311_read_samp_freq(indio_dev, val, val2); 688 + 689 + default: 690 + return -EINVAL; 691 + } 692 + } 693 + 694 + static int msa311_read_avail(struct iio_dev *indio_dev, 695 + struct iio_chan_spec const *chan, 696 + const int **vals, int *type, 697 + int *length, long mask) 698 + { 699 + switch (mask) { 700 + case IIO_CHAN_INFO_SAMP_FREQ: 701 + *vals = (int *)msa311_odr_table; 702 + *type = IIO_VAL_INT_PLUS_MICRO; 703 + /* ODR value has 2 ints (integer and fractional parts) */ 704 + *length = ARRAY_SIZE(msa311_odr_table) * 2; 705 + return IIO_AVAIL_LIST; 706 + 707 + case IIO_CHAN_INFO_SCALE: 708 + *vals = (int *)msa311_fs_table; 709 + *type = IIO_VAL_INT_PLUS_MICRO; 710 + /* FS value has 2 ints (integer and fractional parts) */ 711 + *length = ARRAY_SIZE(msa311_fs_table) * 2; 712 + return IIO_AVAIL_LIST; 713 + 714 + default: 715 + return -EINVAL; 716 + } 717 + } 718 + 719 + static int msa311_write_scale(struct iio_dev *indio_dev, int val, int val2) 720 + { 721 + struct msa311_priv *msa311 = iio_priv(indio_dev); 722 + struct device *dev = msa311->dev; 723 + unsigned int fs; 724 + int err; 725 + 726 + /* We do not have fs >= 1, so skip such values */ 727 + if (val) 728 + return 0; 729 + 730 + err = pm_runtime_resume_and_get(dev); 731 + if (err) 732 + return err; 733 + 734 + err = -EINVAL; 735 + for (fs = 0; fs < ARRAY_SIZE(msa311_fs_table); fs++) 736 + /* Do not check msa311_fs_table[fs].integral, it's always 0 */ 737 + if (val2 == msa311_fs_table[fs].microfract) { 738 + mutex_lock(&msa311->lock); 739 + err = regmap_field_write(msa311->fields[F_FS], fs); 740 + mutex_unlock(&msa311->lock); 741 + break; 742 + } 743 + 744 + pm_runtime_mark_last_busy(dev); 745 + pm_runtime_put_autosuspend(dev); 746 + 747 + if (err) 748 + dev_err(dev, "can't update scale (%pe)\n", ERR_PTR(err)); 749 + 750 + return err; 751 + } 752 + 753 + static int msa311_write_samp_freq(struct iio_dev *indio_dev, int val, int val2) 754 + { 755 + struct msa311_priv *msa311 = iio_priv(indio_dev); 756 + struct device *dev = msa311->dev; 757 + unsigned int odr; 758 + int err; 759 + 760 + err = pm_runtime_resume_and_get(dev); 761 + if (err) 762 + return err; 763 + 764 + /* 765 + * Sampling frequency changing is prohibited when buffer mode is 766 + * enabled, because sometimes MSA311 chip returns outliers during 767 + * frequency values growing up in the read operation moment. 768 + */ 769 + err = iio_device_claim_direct_mode(indio_dev); 770 + if (err) 771 + return err; 772 + 773 + err = -EINVAL; 774 + for (odr = 0; odr < ARRAY_SIZE(msa311_odr_table); odr++) 775 + if (val == msa311_odr_table[odr].integral && 776 + val2 == msa311_odr_table[odr].microfract) { 777 + mutex_lock(&msa311->lock); 778 + err = msa311_set_odr(msa311, odr); 779 + mutex_unlock(&msa311->lock); 780 + break; 781 + } 782 + 783 + iio_device_release_direct_mode(indio_dev); 784 + 785 + pm_runtime_mark_last_busy(dev); 786 + pm_runtime_put_autosuspend(dev); 787 + 788 + if (err) 789 + dev_err(dev, "can't update frequency (%pe)\n", ERR_PTR(err)); 790 + 791 + return err; 792 + } 793 + 794 + static int msa311_write_raw(struct iio_dev *indio_dev, 795 + struct iio_chan_spec const *chan, 796 + int val, int val2, long mask) 797 + { 798 + switch (mask) { 799 + case IIO_CHAN_INFO_SCALE: 800 + return msa311_write_scale(indio_dev, val, val2); 801 + 802 + case IIO_CHAN_INFO_SAMP_FREQ: 803 + return msa311_write_samp_freq(indio_dev, val, val2); 804 + 805 + default: 806 + return -EINVAL; 807 + } 808 + } 809 + 810 + static int msa311_debugfs_reg_access(struct iio_dev *indio_dev, 811 + unsigned int reg, unsigned int writeval, 812 + unsigned int *readval) 813 + { 814 + struct msa311_priv *msa311 = iio_priv(indio_dev); 815 + struct device *dev = msa311->dev; 816 + int err; 817 + 818 + if (reg > regmap_get_max_register(msa311->regs)) 819 + return -EINVAL; 820 + 821 + err = pm_runtime_resume_and_get(dev); 822 + if (err) 823 + return err; 824 + 825 + mutex_lock(&msa311->lock); 826 + 827 + if (readval) 828 + err = regmap_read(msa311->regs, reg, readval); 829 + else 830 + err = regmap_write(msa311->regs, reg, writeval); 831 + 832 + mutex_unlock(&msa311->lock); 833 + 834 + pm_runtime_mark_last_busy(dev); 835 + pm_runtime_put_autosuspend(dev); 836 + 837 + if (err) 838 + dev_err(dev, "can't %s register %u from debugfs (%pe)\n", 839 + str_read_write(readval), reg, ERR_PTR(err)); 840 + 841 + return err; 842 + } 843 + 844 + static int msa311_buffer_preenable(struct iio_dev *indio_dev) 845 + { 846 + struct msa311_priv *msa311 = iio_priv(indio_dev); 847 + struct device *dev = msa311->dev; 848 + 849 + return pm_runtime_resume_and_get(dev); 850 + } 851 + 852 + static int msa311_buffer_postdisable(struct iio_dev *indio_dev) 853 + { 854 + struct msa311_priv *msa311 = iio_priv(indio_dev); 855 + struct device *dev = msa311->dev; 856 + 857 + pm_runtime_mark_last_busy(dev); 858 + pm_runtime_put_autosuspend(dev); 859 + 860 + return 0; 861 + } 862 + 863 + static int msa311_set_new_data_trig_state(struct iio_trigger *trig, bool state) 864 + { 865 + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 866 + struct msa311_priv *msa311 = iio_priv(indio_dev); 867 + struct device *dev = msa311->dev; 868 + int err; 869 + 870 + mutex_lock(&msa311->lock); 871 + err = regmap_field_write(msa311->fields[F_NEW_DATA_INT_EN], state); 872 + mutex_unlock(&msa311->lock); 873 + if (err) 874 + dev_err(dev, 875 + "can't %s buffer due to new_data_int failure (%pe)\n", 876 + str_enable_disable(state), ERR_PTR(err)); 877 + 878 + return err; 879 + } 880 + 881 + static int msa311_validate_device(struct iio_trigger *trig, 882 + struct iio_dev *indio_dev) 883 + { 884 + return iio_trigger_get_drvdata(trig) == indio_dev ? 0 : -EINVAL; 885 + } 886 + 887 + static irqreturn_t msa311_buffer_thread(int irq, void *p) 888 + { 889 + struct iio_poll_func *pf = p; 890 + struct msa311_priv *msa311 = iio_priv(pf->indio_dev); 891 + struct iio_dev *indio_dev = pf->indio_dev; 892 + const struct iio_chan_spec *chan; 893 + struct device *dev = msa311->dev; 894 + int bit, err, i = 0; 895 + __le16 axis; 896 + struct { 897 + __le16 channels[MSA311_SI_Z + 1]; 898 + s64 ts __aligned(8); 899 + } buf; 900 + 901 + memset(&buf, 0, sizeof(buf)); 902 + 903 + mutex_lock(&msa311->lock); 904 + 905 + for_each_set_bit(bit, indio_dev->active_scan_mask, 906 + indio_dev->masklength) { 907 + chan = &msa311_channels[bit]; 908 + 909 + err = msa311_get_axis(msa311, chan, &axis); 910 + if (err) { 911 + mutex_unlock(&msa311->lock); 912 + dev_err(dev, "can't get axis %s (%pe)\n", 913 + chan->datasheet_name, ERR_PTR(err)); 914 + goto notify_done; 915 + } 916 + 917 + buf.channels[i++] = axis; 918 + } 919 + 920 + mutex_unlock(&msa311->lock); 921 + 922 + iio_push_to_buffers_with_timestamp(indio_dev, &buf, 923 + iio_get_time_ns(indio_dev)); 924 + 925 + notify_done: 926 + iio_trigger_notify_done(indio_dev->trig); 927 + 928 + return IRQ_HANDLED; 929 + } 930 + 931 + static irqreturn_t msa311_irq_thread(int irq, void *p) 932 + { 933 + struct msa311_priv *msa311 = iio_priv(p); 934 + unsigned int new_data_int_enabled; 935 + struct device *dev = msa311->dev; 936 + int err; 937 + 938 + mutex_lock(&msa311->lock); 939 + 940 + /* 941 + * We do not check NEW_DATA int status, because based on the 942 + * specification it's cleared automatically after a fixed time. 943 + * So just check that is enabled by driver logic. 944 + */ 945 + err = regmap_field_read(msa311->fields[F_NEW_DATA_INT_EN], 946 + &new_data_int_enabled); 947 + 948 + mutex_unlock(&msa311->lock); 949 + if (err) { 950 + dev_err(dev, "can't read new_data interrupt state (%pe)\n", 951 + ERR_PTR(err)); 952 + return IRQ_NONE; 953 + } 954 + 955 + if (new_data_int_enabled) 956 + iio_trigger_poll_chained(msa311->new_data_trig); 957 + 958 + return IRQ_HANDLED; 959 + } 960 + 961 + static const struct iio_info msa311_info = { 962 + .read_raw = msa311_read_raw, 963 + .read_avail = msa311_read_avail, 964 + .write_raw = msa311_write_raw, 965 + .debugfs_reg_access = msa311_debugfs_reg_access, 966 + }; 967 + 968 + static const struct iio_buffer_setup_ops msa311_buffer_setup_ops = { 969 + .preenable = msa311_buffer_preenable, 970 + .postdisable = msa311_buffer_postdisable, 971 + }; 972 + 973 + static const struct iio_trigger_ops msa311_new_data_trig_ops = { 974 + .set_trigger_state = msa311_set_new_data_trig_state, 975 + .validate_device = msa311_validate_device, 976 + }; 977 + 978 + static int msa311_check_partid(struct msa311_priv *msa311) 979 + { 980 + struct device *dev = msa311->dev; 981 + unsigned int partid; 982 + int err; 983 + 984 + err = regmap_read(msa311->regs, MSA311_PARTID_REG, &partid); 985 + if (err) 986 + return dev_err_probe(dev, err, "failed to read partid\n"); 987 + 988 + if (partid != MSA311_WHO_AM_I) 989 + dev_warn(dev, "invalid partid (%#x), expected (%#x)\n", 990 + partid, MSA311_WHO_AM_I); 991 + 992 + msa311->chip_name = devm_kasprintf(dev, GFP_KERNEL, 993 + "msa311-%02x", partid); 994 + if (!msa311->chip_name) 995 + return dev_err_probe(dev, -ENOMEM, "can't alloc chip name\n"); 996 + 997 + return 0; 998 + } 999 + 1000 + static int msa311_soft_reset(struct msa311_priv *msa311) 1001 + { 1002 + struct device *dev = msa311->dev; 1003 + int err; 1004 + 1005 + err = regmap_write(msa311->regs, MSA311_SOFT_RESET_REG, 1006 + MSA311_GENMASK(F_SOFT_RESET_I2C) | 1007 + MSA311_GENMASK(F_SOFT_RESET_SPI)); 1008 + if (err) 1009 + return dev_err_probe(dev, err, "can't soft reset all logic\n"); 1010 + 1011 + return 0; 1012 + } 1013 + 1014 + static int msa311_chip_init(struct msa311_priv *msa311) 1015 + { 1016 + struct device *dev = msa311->dev; 1017 + const char zero_bulk[2] = { }; 1018 + int err; 1019 + 1020 + err = regmap_write(msa311->regs, MSA311_RANGE_REG, MSA311_FS_16G); 1021 + if (err) 1022 + return dev_err_probe(dev, err, "failed to setup accel range\n"); 1023 + 1024 + /* Disable all interrupts by default */ 1025 + err = regmap_bulk_write(msa311->regs, MSA311_INT_SET_0_REG, 1026 + zero_bulk, sizeof(zero_bulk)); 1027 + if (err) 1028 + return dev_err_probe(dev, err, 1029 + "can't disable set0/set1 interrupts\n"); 1030 + 1031 + /* Unmap all INT1 interrupts by default */ 1032 + err = regmap_bulk_write(msa311->regs, MSA311_INT_MAP_0_REG, 1033 + zero_bulk, sizeof(zero_bulk)); 1034 + if (err) 1035 + return dev_err_probe(dev, err, 1036 + "failed to unmap map0/map1 interrupts\n"); 1037 + 1038 + /* Disable all axes by default */ 1039 + err = regmap_update_bits(msa311->regs, MSA311_ODR_REG, 1040 + MSA311_GENMASK(F_X_AXIS_DIS) | 1041 + MSA311_GENMASK(F_Y_AXIS_DIS) | 1042 + MSA311_GENMASK(F_Z_AXIS_DIS), 0); 1043 + if (err) 1044 + return dev_err_probe(dev, err, "can't enable all axes\n"); 1045 + 1046 + err = msa311_set_odr(msa311, MSA311_ODR_125_HZ); 1047 + if (err) 1048 + return dev_err_probe(dev, err, 1049 + "failed to set accel frequency\n"); 1050 + 1051 + return 0; 1052 + } 1053 + 1054 + static int msa311_setup_interrupts(struct msa311_priv *msa311) 1055 + { 1056 + struct device *dev = msa311->dev; 1057 + struct i2c_client *i2c = to_i2c_client(dev); 1058 + struct iio_dev *indio_dev = i2c_get_clientdata(i2c); 1059 + struct iio_trigger *trig; 1060 + int err; 1061 + 1062 + /* Keep going without interrupts if no initialized I2C IRQ */ 1063 + if (i2c->irq <= 0) 1064 + return 0; 1065 + 1066 + err = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, 1067 + msa311_irq_thread, IRQF_ONESHOT, 1068 + msa311->chip_name, indio_dev); 1069 + if (err) 1070 + return dev_err_probe(dev, err, "failed to request IRQ\n"); 1071 + 1072 + trig = devm_iio_trigger_alloc(dev, "%s-new-data", msa311->chip_name); 1073 + if (!trig) 1074 + return dev_err_probe(dev, -ENOMEM, 1075 + "can't allocate newdata trigger\n"); 1076 + 1077 + msa311->new_data_trig = trig; 1078 + msa311->new_data_trig->ops = &msa311_new_data_trig_ops; 1079 + iio_trigger_set_drvdata(msa311->new_data_trig, indio_dev); 1080 + 1081 + err = devm_iio_trigger_register(dev, msa311->new_data_trig); 1082 + if (err) 1083 + return dev_err_probe(dev, err, 1084 + "can't register newdata trigger\n"); 1085 + 1086 + err = regmap_field_write(msa311->fields[F_INT1_OD], 1087 + MSA311_INT1_OD_PUSH_PULL); 1088 + if (err) 1089 + return dev_err_probe(dev, err, 1090 + "can't enable push-pull interrupt\n"); 1091 + 1092 + err = regmap_field_write(msa311->fields[F_INT1_LVL], 1093 + MSA311_INT1_LVL_HIGH); 1094 + if (err) 1095 + return dev_err_probe(dev, err, 1096 + "can't set active interrupt level\n"); 1097 + 1098 + err = regmap_field_write(msa311->fields[F_LATCH_INT], 1099 + MSA311_LATCH_INT_LATCHED); 1100 + if (err) 1101 + return dev_err_probe(dev, err, 1102 + "can't latch interrupt\n"); 1103 + 1104 + err = regmap_field_write(msa311->fields[F_RESET_INT], 1); 1105 + if (err) 1106 + return dev_err_probe(dev, err, 1107 + "can't reset interrupt\n"); 1108 + 1109 + err = regmap_field_write(msa311->fields[F_INT1_NEW_DATA], 1); 1110 + if (err) 1111 + return dev_err_probe(dev, err, 1112 + "can't map new data interrupt\n"); 1113 + 1114 + return 0; 1115 + } 1116 + 1117 + static int msa311_regmap_init(struct msa311_priv *msa311) 1118 + { 1119 + struct regmap_field **fields = msa311->fields; 1120 + struct device *dev = msa311->dev; 1121 + struct i2c_client *i2c = to_i2c_client(dev); 1122 + struct regmap *regmap; 1123 + int i; 1124 + 1125 + regmap = devm_regmap_init_i2c(i2c, &msa311_regmap_config); 1126 + if (IS_ERR(regmap)) 1127 + return dev_err_probe(dev, PTR_ERR(regmap), 1128 + "failed to register i2c regmap\n"); 1129 + 1130 + msa311->regs = regmap; 1131 + 1132 + for (i = 0; i < F_MAX_FIELDS; i++) { 1133 + fields[i] = devm_regmap_field_alloc(dev, 1134 + msa311->regs, 1135 + msa311_reg_fields[i]); 1136 + if (IS_ERR(msa311->fields[i])) 1137 + return dev_err_probe(dev, PTR_ERR(msa311->fields[i]), 1138 + "can't alloc field[%d]\n", i); 1139 + } 1140 + 1141 + return 0; 1142 + } 1143 + 1144 + static void msa311_powerdown(void *msa311) 1145 + { 1146 + msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_SUSPEND); 1147 + } 1148 + 1149 + static void msa311_vdd_disable(void *vdd) 1150 + { 1151 + regulator_disable(vdd); 1152 + } 1153 + 1154 + static int msa311_probe(struct i2c_client *i2c) 1155 + { 1156 + struct device *dev = &i2c->dev; 1157 + struct msa311_priv *msa311; 1158 + struct iio_dev *indio_dev; 1159 + int err; 1160 + 1161 + indio_dev = devm_iio_device_alloc(dev, sizeof(*msa311)); 1162 + if (!indio_dev) 1163 + return dev_err_probe(dev, -ENOMEM, 1164 + "IIO device allocation failed\n"); 1165 + 1166 + msa311 = iio_priv(indio_dev); 1167 + msa311->dev = dev; 1168 + i2c_set_clientdata(i2c, indio_dev); 1169 + 1170 + err = msa311_regmap_init(msa311); 1171 + if (err) 1172 + return err; 1173 + 1174 + mutex_init(&msa311->lock); 1175 + 1176 + msa311->vdd = devm_regulator_get(dev, "vdd"); 1177 + if (IS_ERR(msa311->vdd)) 1178 + return dev_err_probe(dev, PTR_ERR(msa311->vdd), 1179 + "can't get vdd supply\n"); 1180 + 1181 + err = regulator_enable(msa311->vdd); 1182 + if (err) 1183 + return dev_err_probe(dev, err, "can't enable vdd supply\n"); 1184 + 1185 + err = devm_add_action_or_reset(dev, msa311_vdd_disable, msa311->vdd); 1186 + if (err) 1187 + return dev_err_probe(dev, err, 1188 + "can't add vdd disable action\n"); 1189 + 1190 + err = msa311_check_partid(msa311); 1191 + if (err) 1192 + return err; 1193 + 1194 + err = msa311_soft_reset(msa311); 1195 + if (err) 1196 + return err; 1197 + 1198 + err = msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_NORMAL); 1199 + if (err) 1200 + return dev_err_probe(dev, err, "failed to power on device\n"); 1201 + 1202 + /* 1203 + * Register powerdown deferred callback which suspends the chip 1204 + * after module unloaded. 1205 + * 1206 + * MSA311 should be in SUSPEND mode in the two cases: 1207 + * 1) When driver is loaded, but we do not have any data or 1208 + * configuration requests to it (we are solving it using 1209 + * autosuspend feature). 1210 + * 2) When driver is unloaded and device is not used (devm action is 1211 + * used in this case). 1212 + */ 1213 + err = devm_add_action_or_reset(dev, msa311_powerdown, msa311); 1214 + if (err) 1215 + return dev_err_probe(dev, err, "can't add powerdown action\n"); 1216 + 1217 + err = pm_runtime_set_active(dev); 1218 + if (err) 1219 + return err; 1220 + 1221 + err = devm_pm_runtime_enable(dev); 1222 + if (err) 1223 + return err; 1224 + 1225 + pm_runtime_get_noresume(dev); 1226 + pm_runtime_set_autosuspend_delay(dev, MSA311_PWR_SLEEP_DELAY_MS); 1227 + pm_runtime_use_autosuspend(dev); 1228 + 1229 + err = msa311_chip_init(msa311); 1230 + if (err) 1231 + return err; 1232 + 1233 + indio_dev->modes = INDIO_DIRECT_MODE; 1234 + indio_dev->channels = msa311_channels; 1235 + indio_dev->num_channels = ARRAY_SIZE(msa311_channels); 1236 + indio_dev->name = msa311->chip_name; 1237 + indio_dev->info = &msa311_info; 1238 + 1239 + err = devm_iio_triggered_buffer_setup(dev, indio_dev, 1240 + iio_pollfunc_store_time, 1241 + msa311_buffer_thread, 1242 + &msa311_buffer_setup_ops); 1243 + if (err) 1244 + return dev_err_probe(dev, err, 1245 + "can't setup IIO trigger buffer\n"); 1246 + 1247 + err = msa311_setup_interrupts(msa311); 1248 + if (err) 1249 + return err; 1250 + 1251 + pm_runtime_mark_last_busy(dev); 1252 + pm_runtime_put_autosuspend(dev); 1253 + 1254 + err = devm_iio_device_register(dev, indio_dev); 1255 + if (err) 1256 + return dev_err_probe(dev, err, "IIO device register failed\n"); 1257 + 1258 + return 0; 1259 + } 1260 + 1261 + static int msa311_runtime_suspend(struct device *dev) 1262 + { 1263 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 1264 + struct msa311_priv *msa311 = iio_priv(indio_dev); 1265 + int err; 1266 + 1267 + mutex_lock(&msa311->lock); 1268 + err = msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_SUSPEND); 1269 + mutex_unlock(&msa311->lock); 1270 + if (err) 1271 + dev_err(dev, "failed to power off device (%pe)\n", 1272 + ERR_PTR(err)); 1273 + 1274 + return err; 1275 + } 1276 + 1277 + static int msa311_runtime_resume(struct device *dev) 1278 + { 1279 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 1280 + struct msa311_priv *msa311 = iio_priv(indio_dev); 1281 + int err; 1282 + 1283 + mutex_lock(&msa311->lock); 1284 + err = msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_NORMAL); 1285 + mutex_unlock(&msa311->lock); 1286 + if (err) 1287 + dev_err(dev, "failed to power on device (%pe)\n", 1288 + ERR_PTR(err)); 1289 + 1290 + return err; 1291 + } 1292 + 1293 + static DEFINE_RUNTIME_DEV_PM_OPS(msa311_pm_ops, msa311_runtime_suspend, 1294 + msa311_runtime_resume, NULL); 1295 + 1296 + static const struct i2c_device_id msa311_i2c_id[] = { 1297 + { .name = "msa311" }, 1298 + { } 1299 + }; 1300 + MODULE_DEVICE_TABLE(i2c, msa311_i2c_id); 1301 + 1302 + static const struct of_device_id msa311_of_match[] = { 1303 + { .compatible = "memsensing,msa311" }, 1304 + { } 1305 + }; 1306 + MODULE_DEVICE_TABLE(of, msa311_of_match); 1307 + 1308 + static struct i2c_driver msa311_driver = { 1309 + .driver = { 1310 + .name = "msa311", 1311 + .of_match_table = msa311_of_match, 1312 + .pm = pm_ptr(&msa311_pm_ops), 1313 + }, 1314 + .probe_new = msa311_probe, 1315 + .id_table = msa311_i2c_id, 1316 + }; 1317 + module_i2c_driver(msa311_driver); 1318 + 1319 + MODULE_AUTHOR("Dmitry Rokosov <ddrokosov@sberdevices.ru>"); 1320 + MODULE_DESCRIPTION("MEMSensing MSA311 3-axis accelerometer driver"); 1321 + MODULE_LICENSE("GPL");
+29 -16
drivers/iio/adc/Kconfig
··· 653 653 To compile this driver as a module, choose M here: the module will be 654 654 called max1118. 655 655 656 + config MAX11205 657 + tristate "Maxim max11205 ADC driver" 658 + depends on SPI 659 + select AD_SIGMA_DELTA 660 + select IIO_BUFFER 661 + select IIO_TRIGGERED_BUFFER 662 + 663 + help 664 + Say yes here to build support for Maxim max11205 16-bit, single-channel 665 + ultra-low power delta-sigma ADC. 666 + 667 + To compile this driver as a module, choose M here: the module will be 668 + called max11205. 669 + 656 670 config MAX1241 657 671 tristate "Maxim max1241 ADC driver" 658 672 depends on SPI_MASTER ··· 933 919 To compile this driver as a module, choose M here: the 934 920 module will be called rockchip_saradc. 935 921 922 + config RICHTEK_RTQ6056 923 + tristate "Richtek RTQ6056 Current and Power Monitor ADC" 924 + depends on I2C 925 + select REGMAP_I2C 926 + select IIO_BUFFER 927 + select IIO_TRIGGERED_BUFFER 928 + help 929 + Say yes here to enable RQT6056 ADC support. 930 + RTQ6056 is a high accuracy current-sense monitor with I2C and SMBus 931 + compatible interface, and the device provides full information for 932 + system by reading out the load current and power. 933 + 934 + This driver can also be built as a module. If so, the module will be 935 + called rtq6056. 936 + 936 937 config RZG2L_ADC 937 938 tristate "Renesas RZ/G2L ADC driver" 938 939 depends on ARCH_RZG2L || COMPILE_TEST ··· 1050 1021 help 1051 1022 Say yes here to build support for ST Microelectronics STMPE 1052 1023 built-in ADC block (stmpe811). 1053 - 1054 - config STX104 1055 - tristate "Apex Embedded Systems STX104 driver" 1056 - depends on PC104 && X86 1057 - select ISA_BUS_API 1058 - select GPIOLIB 1059 - help 1060 - Say yes here to build support for the Apex Embedded Systems STX104 1061 - integrated analog PC/104 card. 1062 - 1063 - This driver supports the 16 channels of single-ended (8 channels of 1064 - differential) analog inputs, 2 channels of analog output, 4 digital 1065 - inputs, and 4 digital outputs provided by the STX104. 1066 - 1067 - The base port addresses for the devices may be configured via the base 1068 - array module parameter. 1069 1024 1070 1025 config SUN4I_GPADC 1071 1026 tristate "Support for the Allwinner SoCs GPADC"
+2 -1
drivers/iio/adc/Makefile
··· 61 61 obj-$(CONFIG_MAX1027) += max1027.o 62 62 obj-$(CONFIG_MAX11100) += max11100.o 63 63 obj-$(CONFIG_MAX1118) += max1118.o 64 + obj-$(CONFIG_MAX11205) += max11205.o 64 65 obj-$(CONFIG_MAX1241) += max1241.o 65 66 obj-$(CONFIG_MAX1363) += max1363.o 66 67 obj-$(CONFIG_MAX9611) += max9611.o ··· 86 85 obj-$(CONFIG_RCAR_GYRO_ADC) += rcar-gyroadc.o 87 86 obj-$(CONFIG_RN5T618_ADC) += rn5t618-adc.o 88 87 obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o 88 + obj-$(CONFIG_RICHTEK_RTQ6056) += rtq6056.o 89 89 obj-$(CONFIG_RZG2L_ADC) += rzg2l_adc.o 90 90 obj-$(CONFIG_SC27XX_ADC) += sc27xx_adc.o 91 91 obj-$(CONFIG_SPEAR_ADC) += spear_adc.o 92 - obj-$(CONFIG_STX104) += stx104.o 93 92 obj-$(CONFIG_SUN4I_GPADC) += sun4i-gpadc-iio.o 94 93 obj-$(CONFIG_STM32_ADC_CORE) += stm32-adc-core.o 95 94 obj-$(CONFIG_STM32_ADC) += stm32-adc.o
+12 -15
drivers/iio/adc/ab8500-gpadc.c
··· 925 925 return -EINVAL; 926 926 } 927 927 928 - static int ab8500_gpadc_of_xlate(struct iio_dev *indio_dev, 929 - const struct of_phandle_args *iiospec) 928 + static int ab8500_gpadc_fwnode_xlate(struct iio_dev *indio_dev, 929 + const struct fwnode_reference_args *iiospec) 930 930 { 931 931 int i; 932 932 ··· 938 938 } 939 939 940 940 static const struct iio_info ab8500_gpadc_info = { 941 - .of_xlate = ab8500_gpadc_of_xlate, 941 + .fwnode_xlate = ab8500_gpadc_fwnode_xlate, 942 942 .read_raw = ab8500_gpadc_read_raw, 943 943 }; 944 944 ··· 968 968 /** 969 969 * ab8500_gpadc_parse_channel() - process devicetree channel configuration 970 970 * @dev: pointer to containing device 971 - * @np: device tree node for the channel to configure 971 + * @fwnode: fw node for the channel to configure 972 972 * @ch: channel info to fill in 973 973 * @iio_chan: IIO channel specification to fill in 974 974 * ··· 976 976 * and define usage for things like AUX GPADC inputs more precisely. 977 977 */ 978 978 static int ab8500_gpadc_parse_channel(struct device *dev, 979 - struct device_node *np, 979 + struct fwnode_handle *fwnode, 980 980 struct ab8500_gpadc_chan_info *ch, 981 981 struct iio_chan_spec *iio_chan) 982 982 { 983 - const char *name = np->name; 983 + const char *name = fwnode_get_name(fwnode); 984 984 u32 chan; 985 985 int ret; 986 986 987 - ret = of_property_read_u32(np, "reg", &chan); 987 + ret = fwnode_property_read_u32(fwnode, "reg", &chan); 988 988 if (ret) { 989 989 dev_err(dev, "invalid channel number %s\n", name); 990 990 return ret; ··· 1021 1021 /** 1022 1022 * ab8500_gpadc_parse_channels() - Parse the GPADC channels from DT 1023 1023 * @gpadc: the GPADC to configure the channels for 1024 - * @np: device tree node containing the channel configurations 1025 1024 * @chans: the IIO channels we parsed 1026 1025 * @nchans: the number of IIO channels we parsed 1027 1026 */ 1028 1027 static int ab8500_gpadc_parse_channels(struct ab8500_gpadc *gpadc, 1029 - struct device_node *np, 1030 1028 struct iio_chan_spec **chans_parsed, 1031 1029 unsigned int *nchans_parsed) 1032 1030 { 1033 - struct device_node *child; 1031 + struct fwnode_handle *child; 1034 1032 struct ab8500_gpadc_chan_info *ch; 1035 1033 struct iio_chan_spec *iio_chans; 1036 1034 unsigned int nchans; 1037 1035 int i; 1038 1036 1039 - nchans = of_get_available_child_count(np); 1037 + nchans = device_get_child_node_count(gpadc->dev); 1040 1038 if (!nchans) { 1041 1039 dev_err(gpadc->dev, "no channel children\n"); 1042 1040 return -ENODEV; ··· 1052 1054 return -ENOMEM; 1053 1055 1054 1056 i = 0; 1055 - for_each_available_child_of_node(np, child) { 1057 + device_for_each_child_node(gpadc->dev, child) { 1056 1058 struct iio_chan_spec *iio_chan; 1057 1059 int ret; 1058 1060 ··· 1062 1064 ret = ab8500_gpadc_parse_channel(gpadc->dev, child, ch, 1063 1065 iio_chan); 1064 1066 if (ret) { 1065 - of_node_put(child); 1067 + fwnode_handle_put(child); 1066 1068 return ret; 1067 1069 } 1068 1070 i++; ··· 1079 1081 struct ab8500_gpadc *gpadc; 1080 1082 struct iio_dev *indio_dev; 1081 1083 struct device *dev = &pdev->dev; 1082 - struct device_node *np = pdev->dev.of_node; 1083 1084 struct iio_chan_spec *iio_chans; 1084 1085 unsigned int n_iio_chans; 1085 1086 int ret; ··· 1093 1096 gpadc->dev = dev; 1094 1097 gpadc->ab8500 = dev_get_drvdata(dev->parent); 1095 1098 1096 - ret = ab8500_gpadc_parse_channels(gpadc, np, &iio_chans, &n_iio_chans); 1099 + ret = ab8500_gpadc_parse_channels(gpadc, &iio_chans, &n_iio_chans); 1097 1100 if (ret) 1098 1101 return ret; 1099 1102
+1 -14
drivers/iio/adc/ad7124.c
··· 936 936 regulator_disable(r); 937 937 } 938 938 939 - static void ad7124_clk_disable(void *c) 940 - { 941 - clk_disable_unprepare(c); 942 - } 943 - 944 939 static int ad7124_probe(struct spi_device *spi) 945 940 { 946 941 const struct ad7124_chip_info *info; ··· 988 993 return ret; 989 994 } 990 995 991 - st->mclk = devm_clk_get(&spi->dev, "mclk"); 996 + st->mclk = devm_clk_get_enabled(&spi->dev, "mclk"); 992 997 if (IS_ERR(st->mclk)) 993 998 return PTR_ERR(st->mclk); 994 - 995 - ret = clk_prepare_enable(st->mclk); 996 - if (ret < 0) 997 - return ret; 998 - 999 - ret = devm_add_action_or_reset(&spi->dev, ad7124_clk_disable, st->mclk); 1000 - if (ret) 1001 - return ret; 1002 999 1003 1000 ret = ad7124_soft_reset(st); 1004 1001 if (ret < 0)
+1 -16
drivers/iio/adc/ad7768-1.c
··· 539 539 regulator_disable(st->vref); 540 540 } 541 541 542 - static void ad7768_clk_disable(void *data) 543 - { 544 - struct ad7768_state *st = data; 545 - 546 - clk_disable_unprepare(st->mclk); 547 - } 548 - 549 542 static int ad7768_set_channel_label(struct iio_dev *indio_dev, 550 543 int num_channels) 551 544 { ··· 593 600 if (ret) 594 601 return ret; 595 602 596 - st->mclk = devm_clk_get(&spi->dev, "mclk"); 603 + st->mclk = devm_clk_get_enabled(&spi->dev, "mclk"); 597 604 if (IS_ERR(st->mclk)) 598 605 return PTR_ERR(st->mclk); 599 - 600 - ret = clk_prepare_enable(st->mclk); 601 - if (ret < 0) 602 - return ret; 603 - 604 - ret = devm_add_action_or_reset(&spi->dev, ad7768_clk_disable, st); 605 - if (ret) 606 - return ret; 607 606 608 607 st->mclk_freq = clk_get_rate(st->mclk); 609 608
+1 -16
drivers/iio/adc/ad9467.c
··· 378 378 return ad9467_outputmode_set(st->spi, st->output_mode); 379 379 } 380 380 381 - static void ad9467_clk_disable(void *data) 382 - { 383 - struct ad9467_state *st = data; 384 - 385 - clk_disable_unprepare(st->clk); 386 - } 387 - 388 381 static int ad9467_probe(struct spi_device *spi) 389 382 { 390 383 const struct ad9467_chip_info *info; ··· 397 404 st = adi_axi_adc_conv_priv(conv); 398 405 st->spi = spi; 399 406 400 - st->clk = devm_clk_get(&spi->dev, "adc-clk"); 407 + st->clk = devm_clk_get_enabled(&spi->dev, "adc-clk"); 401 408 if (IS_ERR(st->clk)) 402 409 return PTR_ERR(st->clk); 403 - 404 - ret = clk_prepare_enable(st->clk); 405 - if (ret < 0) 406 - return ret; 407 - 408 - ret = devm_add_action_or_reset(&spi->dev, ad9467_clk_disable, st); 409 - if (ret) 410 - return ret; 411 410 412 411 st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown", 413 412 GPIOD_OUT_LOW);
+580 -134
drivers/iio/adc/at91-sama5d2_adc.c
··· 16 16 #include <linux/interrupt.h> 17 17 #include <linux/io.h> 18 18 #include <linux/module.h> 19 - #include <linux/of_device.h> 19 + #include <linux/mod_devicetable.h> 20 20 #include <linux/platform_device.h> 21 + #include <linux/property.h> 21 22 #include <linux/sched.h> 23 + #include <linux/units.h> 22 24 #include <linux/wait.h> 23 25 #include <linux/iio/iio.h> 24 26 #include <linux/iio/sysfs.h> ··· 28 26 #include <linux/iio/trigger.h> 29 27 #include <linux/iio/trigger_consumer.h> 30 28 #include <linux/iio/triggered_buffer.h> 29 + #include <linux/nvmem-consumer.h> 31 30 #include <linux/pinctrl/consumer.h> 31 + #include <linux/pm_runtime.h> 32 32 #include <linux/regulator/consumer.h> 33 + 34 + #include <dt-bindings/iio/adc/at91-sama5d2_adc.h> 33 35 34 36 struct at91_adc_reg_layout { 35 37 /* Control Register */ ··· 79 73 /* Startup Time */ 80 74 #define AT91_SAMA5D2_MR_STARTUP(v) ((v) << 16) 81 75 #define AT91_SAMA5D2_MR_STARTUP_MASK GENMASK(19, 16) 76 + /* Minimum startup time for temperature sensor */ 77 + #define AT91_SAMA5D2_MR_STARTUP_TS_MIN (50) 82 78 /* Analog Change */ 83 79 #define AT91_SAMA5D2_MR_ANACH BIT(23) 84 80 /* Tracking Time */ 85 81 #define AT91_SAMA5D2_MR_TRACKTIM(v) ((v) << 24) 86 - #define AT91_SAMA5D2_MR_TRACKTIM_MAX 0xff 82 + #define AT91_SAMA5D2_MR_TRACKTIM_TS 6 83 + #define AT91_SAMA5D2_MR_TRACKTIM_MAX 0xf 87 84 /* Transfer Time */ 88 85 #define AT91_SAMA5D2_MR_TRANSFER(v) ((v) << 28) 89 86 #define AT91_SAMA5D2_MR_TRANSFER_MAX 0x3 ··· 147 138 /* Extended Mode Register */ 148 139 u16 EMR; 149 140 /* Extended Mode Register - Oversampling rate */ 150 - #define AT91_SAMA5D2_EMR_OSR(V) ((V) << 16) 151 - #define AT91_SAMA5D2_EMR_OSR_MASK GENMASK(17, 16) 141 + #define AT91_SAMA5D2_EMR_OSR(V, M) (((V) << 16) & (M)) 152 142 #define AT91_SAMA5D2_EMR_OSR_1SAMPLES 0 153 143 #define AT91_SAMA5D2_EMR_OSR_4SAMPLES 1 154 144 #define AT91_SAMA5D2_EMR_OSR_16SAMPLES 2 145 + #define AT91_SAMA5D2_EMR_OSR_64SAMPLES 3 146 + #define AT91_SAMA5D2_EMR_OSR_256SAMPLES 4 147 + 148 + /* Extended Mode Register - TRACKX */ 149 + #define AT91_SAMA5D2_TRACKX_MASK GENMASK(23, 22) 150 + #define AT91_SAMA5D2_TRACKX(x) (((x) << 22) & \ 151 + AT91_SAMA5D2_TRACKX_MASK) 152 + /* TRACKX for temperature sensor. */ 153 + #define AT91_SAMA5D2_TRACKX_TS (1) 155 154 156 155 /* Extended Mode Register - Averaging on single trigger event */ 157 156 #define AT91_SAMA5D2_EMR_ASTE(V) ((V) << 20) ··· 176 159 u16 ACR; 177 160 /* Analog Control Register - Pen detect sensitivity mask */ 178 161 #define AT91_SAMA5D2_ACR_PENDETSENS_MASK GENMASK(1, 0) 162 + /* Analog Control Register - Source last channel */ 163 + #define AT91_SAMA5D2_ACR_SRCLCH BIT(16) 179 164 180 165 /* Touchscreen Mode Register */ 181 166 u16 TSMR; ··· 245 226 u16 WPSR; 246 227 /* Version Register */ 247 228 u16 VERSION; 229 + /* Temperature Sensor Mode Register */ 230 + u16 TEMPMR; 231 + /* Temperature Sensor Mode - Temperature sensor on */ 232 + #define AT91_SAMA5D2_TEMPMR_TEMPON BIT(0) 248 233 }; 249 234 250 235 static const struct at91_adc_reg_layout sama5d2_layout = { ··· 303 280 .EOC_IDR = 0x38, 304 281 .EOC_IMR = 0x3c, 305 282 .EOC_ISR = 0x40, 283 + .TEMPMR = 0x44, 306 284 .OVER = 0x4c, 307 285 .EMR = 0x50, 308 286 .CWR = 0x54, ··· 329 305 #define AT91_HWFIFO_MAX_SIZE_STR "128" 330 306 #define AT91_HWFIFO_MAX_SIZE 128 331 307 332 - /* Possible values for oversampling ratio */ 333 - #define AT91_OSR_1SAMPLES 1 334 - #define AT91_OSR_4SAMPLES 4 335 - #define AT91_OSR_16SAMPLES 16 336 - 337 308 #define AT91_SAMA5D2_CHAN_SINGLE(index, num, addr) \ 338 309 { \ 339 310 .type = IIO_VOLTAGE, \ ··· 343 324 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 344 325 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 345 326 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ)|\ 327 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 328 + .info_mask_shared_by_all_available = \ 346 329 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 347 330 .datasheet_name = "CH"#num, \ 348 331 .indexed = 1, \ ··· 367 346 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 368 347 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ)|\ 369 348 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 349 + .info_mask_shared_by_all_available = \ 350 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 370 351 .datasheet_name = "CH"#num"-CH"#num2, \ 371 352 .indexed = 1, \ 372 353 } ··· 388 365 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 389 366 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ)|\ 390 367 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 368 + .info_mask_shared_by_all_available = \ 369 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 391 370 .datasheet_name = name, \ 392 371 } 393 372 #define AT91_SAMA5D2_CHAN_PRESSURE(num, name) \ ··· 404 379 }, \ 405 380 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 406 381 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ)|\ 382 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 383 + .info_mask_shared_by_all_available = \ 384 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 385 + .datasheet_name = name, \ 386 + } 387 + 388 + #define AT91_SAMA5D2_CHAN_TEMP(num, name, addr) \ 389 + { \ 390 + .type = IIO_TEMP, \ 391 + .channel = num, \ 392 + .address = addr, \ 393 + .scan_index = num, \ 394 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ 395 + .info_mask_shared_by_all = \ 396 + BIT(IIO_CHAN_INFO_PROCESSED) | \ 397 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 398 + .info_mask_shared_by_all_available = \ 407 399 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 408 400 .datasheet_name = name, \ 409 401 } ··· 445 403 * @max_index: highest channel index (highest index may be higher 446 404 * than the total channel number) 447 405 * @hw_trig_cnt: number of possible hardware triggers 406 + * @osr_mask: oversampling ratio bitmask on EMR register 407 + * @oversampling_avail: available oversampling values 408 + * @oversampling_avail_no: number of available oversampling values 409 + * @chan_realbits: realbits for registered channels 410 + * @temp_chan: temperature channel index 411 + * @temp_sensor: temperature sensor supported 448 412 */ 449 413 struct at91_adc_platform { 450 414 const struct at91_adc_reg_layout *layout; ··· 462 414 unsigned int max_channels; 463 415 unsigned int max_index; 464 416 unsigned int hw_trig_cnt; 417 + unsigned int osr_mask; 418 + unsigned int oversampling_avail[5]; 419 + unsigned int oversampling_avail_no; 420 + unsigned int chan_realbits; 421 + unsigned int temp_chan; 422 + bool temp_sensor; 465 423 }; 424 + 425 + /** 426 + * struct at91_adc_temp_sensor_clb - at91-sama5d2 temperature sensor 427 + * calibration data structure 428 + * @p1: P1 calibration temperature 429 + * @p4: P4 calibration voltage 430 + * @p6: P6 calibration voltage 431 + */ 432 + struct at91_adc_temp_sensor_clb { 433 + u32 p1; 434 + u32 p4; 435 + u32 p6; 436 + }; 437 + 438 + /** 439 + * enum at91_adc_ts_clb_idx - calibration indexes in NVMEM buffer 440 + * @AT91_ADC_TS_CLB_IDX_P1: index for P1 441 + * @AT91_ADC_TS_CLB_IDX_P4: index for P4 442 + * @AT91_ADC_TS_CLB_IDX_P6: index for P6 443 + * @AT91_ADC_TS_CLB_IDX_MAX: max index for temperature calibration packet in OTP 444 + */ 445 + enum at91_adc_ts_clb_idx { 446 + AT91_ADC_TS_CLB_IDX_P1 = 2, 447 + AT91_ADC_TS_CLB_IDX_P4 = 5, 448 + AT91_ADC_TS_CLB_IDX_P6 = 7, 449 + AT91_ADC_TS_CLB_IDX_MAX = 19, 450 + }; 451 + 452 + /* Temperature sensor calibration - Vtemp voltage sensitivity to temperature. */ 453 + #define AT91_ADC_TS_VTEMP_DT (2080U) 466 454 467 455 /** 468 456 * struct at91_adc_soc_info - at91-sama5d2 soc information struct ··· 506 422 * @min_sample_rate: minimum sample rate in Hz 507 423 * @max_sample_rate: maximum sample rate in Hz 508 424 * @platform: pointer to the platform structure 425 + * @temp_sensor_clb: temperature sensor calibration data structure 509 426 */ 510 427 struct at91_adc_soc_info { 511 428 unsigned startup_time; 512 429 unsigned min_sample_rate; 513 430 unsigned max_sample_rate; 514 431 const struct at91_adc_platform *platform; 432 + struct at91_adc_temp_sensor_clb temp_sensor_clb; 515 433 }; 516 434 517 435 struct at91_adc_trigger { ··· 561 475 struct work_struct workq; 562 476 }; 563 477 478 + /** 479 + * struct at91_adc_temp - at91-sama5d2 temperature information structure 480 + * @sample_period_val: sample period value 481 + * @saved_sample_rate: saved sample rate 482 + * @saved_oversampling: saved oversampling 483 + */ 484 + struct at91_adc_temp { 485 + u16 sample_period_val; 486 + u16 saved_sample_rate; 487 + u16 saved_oversampling; 488 + }; 489 + 564 490 /* 565 491 * Buffer size requirements: 566 492 * No channels * bytes_per_channel(2) + timestamp bytes (8) ··· 600 502 wait_queue_head_t wq_data_available; 601 503 struct at91_adc_dma dma_st; 602 504 struct at91_adc_touch touch_st; 505 + struct at91_adc_temp temp_st; 603 506 struct iio_dev *indio_dev; 507 + struct device *dev; 604 508 /* Ensure naturally aligned timestamp */ 605 509 u16 buffer[AT91_BUFFER_MAX_HWORDS] __aligned(8); 606 510 /* ··· 691 591 AT91_SAMA5D2_CHAN_DIFF(22, 12, 13, 0x90), 692 592 AT91_SAMA5D2_CHAN_DIFF(23, 14, 15, 0x98), 693 593 IIO_CHAN_SOFT_TIMESTAMP(24), 594 + AT91_SAMA5D2_CHAN_TEMP(AT91_SAMA7G5_ADC_TEMP_CHANNEL, "temp", 0xdc), 694 595 }; 695 596 696 597 static const struct at91_adc_platform sama5d2_platform = { ··· 713 612 .max_index = AT91_SAMA5D2_MAX_CHAN_IDX, 714 613 #define AT91_SAMA5D2_HW_TRIG_CNT 3 715 614 .hw_trig_cnt = AT91_SAMA5D2_HW_TRIG_CNT, 615 + .osr_mask = GENMASK(17, 16), 616 + .oversampling_avail = { 1, 4, 16, }, 617 + .oversampling_avail_no = 3, 618 + .chan_realbits = 14, 716 619 }; 717 620 718 621 static const struct at91_adc_platform sama7g5_platform = { ··· 724 619 .adc_channels = &at91_sama7g5_adc_channels, 725 620 #define AT91_SAMA7G5_SINGLE_CHAN_CNT 16 726 621 #define AT91_SAMA7G5_DIFF_CHAN_CNT 8 622 + #define AT91_SAMA7G5_TEMP_CHAN_CNT 1 727 623 .nr_channels = AT91_SAMA7G5_SINGLE_CHAN_CNT + 728 - AT91_SAMA7G5_DIFF_CHAN_CNT, 624 + AT91_SAMA7G5_DIFF_CHAN_CNT + 625 + AT91_SAMA7G5_TEMP_CHAN_CNT, 729 626 #define AT91_SAMA7G5_MAX_CHAN_IDX (AT91_SAMA7G5_SINGLE_CHAN_CNT + \ 730 - AT91_SAMA7G5_DIFF_CHAN_CNT) 627 + AT91_SAMA7G5_DIFF_CHAN_CNT + \ 628 + AT91_SAMA7G5_TEMP_CHAN_CNT) 731 629 .max_channels = ARRAY_SIZE(at91_sama7g5_adc_channels), 732 630 .max_index = AT91_SAMA7G5_MAX_CHAN_IDX, 733 631 #define AT91_SAMA7G5_HW_TRIG_CNT 3 734 632 .hw_trig_cnt = AT91_SAMA7G5_HW_TRIG_CNT, 633 + .osr_mask = GENMASK(18, 16), 634 + .oversampling_avail = { 1, 4, 16, 64, 256, }, 635 + .oversampling_avail_no = 5, 636 + .chan_realbits = 16, 637 + .temp_sensor = true, 638 + .temp_chan = AT91_SAMA7G5_ADC_TEMP_CHANNEL, 735 639 }; 736 640 737 641 static int at91_adc_chan_xlate(struct iio_dev *indio_dev, int chan) ··· 764 650 return indio_dev->channels + index; 765 651 } 766 652 767 - static inline int at91_adc_of_xlate(struct iio_dev *indio_dev, 768 - const struct of_phandle_args *iiospec) 653 + static inline int at91_adc_fwnode_xlate(struct iio_dev *indio_dev, 654 + const struct fwnode_reference_args *iiospec) 769 655 { 770 656 return at91_adc_chan_xlate(indio_dev, iiospec->args[0]); 771 657 } ··· 839 725 at91_adc_writel(st, EOC_IER, BIT(channel)); 840 726 } 841 727 842 - static void at91_adc_config_emr(struct at91_adc_state *st) 728 + static int at91_adc_config_emr(struct at91_adc_state *st, 729 + u32 oversampling_ratio, u32 trackx) 843 730 { 844 731 /* configure the extended mode register */ 845 - unsigned int emr = at91_adc_readl(st, EMR); 732 + unsigned int emr, osr; 733 + unsigned int osr_mask = st->soc_info.platform->osr_mask; 734 + int i, ret; 846 735 847 - /* select oversampling per single trigger event */ 848 - emr |= AT91_SAMA5D2_EMR_ASTE(1); 849 - 850 - /* delete leftover content if it's the case */ 851 - emr &= ~AT91_SAMA5D2_EMR_OSR_MASK; 736 + /* Check against supported oversampling values. */ 737 + for (i = 0; i < st->soc_info.platform->oversampling_avail_no; i++) { 738 + if (oversampling_ratio == st->soc_info.platform->oversampling_avail[i]) 739 + break; 740 + } 741 + if (i == st->soc_info.platform->oversampling_avail_no) 742 + return -EINVAL; 852 743 853 744 /* select oversampling ratio from configuration */ 854 - switch (st->oversampling_ratio) { 855 - case AT91_OSR_1SAMPLES: 856 - emr |= AT91_SAMA5D2_EMR_OSR(AT91_SAMA5D2_EMR_OSR_1SAMPLES) & 857 - AT91_SAMA5D2_EMR_OSR_MASK; 745 + switch (oversampling_ratio) { 746 + case 1: 747 + osr = AT91_SAMA5D2_EMR_OSR(AT91_SAMA5D2_EMR_OSR_1SAMPLES, 748 + osr_mask); 858 749 break; 859 - case AT91_OSR_4SAMPLES: 860 - emr |= AT91_SAMA5D2_EMR_OSR(AT91_SAMA5D2_EMR_OSR_4SAMPLES) & 861 - AT91_SAMA5D2_EMR_OSR_MASK; 750 + case 4: 751 + osr = AT91_SAMA5D2_EMR_OSR(AT91_SAMA5D2_EMR_OSR_4SAMPLES, 752 + osr_mask); 862 753 break; 863 - case AT91_OSR_16SAMPLES: 864 - emr |= AT91_SAMA5D2_EMR_OSR(AT91_SAMA5D2_EMR_OSR_16SAMPLES) & 865 - AT91_SAMA5D2_EMR_OSR_MASK; 754 + case 16: 755 + osr = AT91_SAMA5D2_EMR_OSR(AT91_SAMA5D2_EMR_OSR_16SAMPLES, 756 + osr_mask); 757 + break; 758 + case 64: 759 + osr = AT91_SAMA5D2_EMR_OSR(AT91_SAMA5D2_EMR_OSR_64SAMPLES, 760 + osr_mask); 761 + break; 762 + case 256: 763 + osr = AT91_SAMA5D2_EMR_OSR(AT91_SAMA5D2_EMR_OSR_256SAMPLES, 764 + osr_mask); 866 765 break; 867 766 } 868 767 768 + ret = pm_runtime_resume_and_get(st->dev); 769 + if (ret < 0) 770 + return ret; 771 + 772 + emr = at91_adc_readl(st, EMR); 773 + /* select oversampling per single trigger event */ 774 + emr |= AT91_SAMA5D2_EMR_ASTE(1); 775 + /* delete leftover content if it's the case */ 776 + emr &= ~(osr_mask | AT91_SAMA5D2_TRACKX_MASK); 777 + /* Update osr and trackx. */ 778 + emr |= osr | AT91_SAMA5D2_TRACKX(trackx); 869 779 at91_adc_writel(st, EMR, emr); 780 + 781 + pm_runtime_mark_last_busy(st->dev); 782 + pm_runtime_put_autosuspend(st->dev); 783 + 784 + st->oversampling_ratio = oversampling_ratio; 785 + 786 + return 0; 870 787 } 871 788 872 789 static int at91_adc_adjust_val_osr(struct at91_adc_state *st, int *val) 873 790 { 874 - if (st->oversampling_ratio == AT91_OSR_1SAMPLES) { 875 - /* 876 - * in this case we only have 12 bits of real data, but channel 877 - * is registered as 14 bits, so shift left two bits 878 - */ 879 - *val <<= 2; 880 - } else if (st->oversampling_ratio == AT91_OSR_4SAMPLES) { 881 - /* 882 - * in this case we have 13 bits of real data, but channel 883 - * is registered as 14 bits, so left shift one bit 884 - */ 885 - *val <<= 1; 886 - } 791 + int nbits, diff; 792 + 793 + if (st->oversampling_ratio == 1) 794 + nbits = 12; 795 + else if (st->oversampling_ratio == 4) 796 + nbits = 13; 797 + else if (st->oversampling_ratio == 16) 798 + nbits = 14; 799 + else if (st->oversampling_ratio == 64) 800 + nbits = 15; 801 + else if (st->oversampling_ratio == 256) 802 + nbits = 16; 803 + else 804 + /* Should not happen. */ 805 + return -EINVAL; 806 + 807 + /* 808 + * We have nbits of real data and channel is registered as 809 + * st->soc_info.platform->chan_realbits, so shift left diff bits. 810 + */ 811 + diff = st->soc_info.platform->chan_realbits - nbits; 812 + *val <<= diff; 887 813 888 814 return IIO_VAL_INT; 889 815 } ··· 953 799 static int at91_adc_configure_touch(struct at91_adc_state *st, bool state) 954 800 { 955 801 u32 clk_khz = st->current_sample_rate / 1000; 956 - int i = 0; 802 + int i = 0, ret; 957 803 u16 pendbc; 958 804 u32 tsmr, acr; 959 805 960 - if (!state) { 806 + if (state) { 807 + ret = pm_runtime_resume_and_get(st->dev); 808 + if (ret < 0) 809 + return ret; 810 + } else { 961 811 /* disabling touch IRQs and setting mode to no touch enabled */ 962 812 at91_adc_writel(st, IDR, 963 813 AT91_SAMA5D2_IER_PEN | AT91_SAMA5D2_IER_NOPEN); 964 814 at91_adc_writel(st, TSMR, 0); 815 + 816 + pm_runtime_mark_last_busy(st->dev); 817 + pm_runtime_put_autosuspend(st->dev); 965 818 return 0; 966 819 } 967 820 /* ··· 1109 948 return IIO_VAL_INT; 1110 949 } 1111 950 1112 - static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) 951 + static void at91_adc_configure_trigger_registers(struct at91_adc_state *st, 952 + bool state) 1113 953 { 1114 - struct iio_dev *indio = iio_trigger_get_drvdata(trig); 1115 - struct at91_adc_state *st = iio_priv(indio); 1116 954 u32 status = at91_adc_readl(st, TRGR); 1117 955 1118 956 /* clear TRGMOD */ ··· 1122 962 1123 963 /* set/unset hw trigger */ 1124 964 at91_adc_writel(st, TRGR, status); 965 + } 966 + 967 + static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) 968 + { 969 + struct iio_dev *indio = iio_trigger_get_drvdata(trig); 970 + struct at91_adc_state *st = iio_priv(indio); 971 + int ret; 972 + 973 + if (state) { 974 + ret = pm_runtime_resume_and_get(st->dev); 975 + if (ret < 0) 976 + return ret; 977 + } 978 + 979 + at91_adc_configure_trigger_registers(st, state); 980 + 981 + if (!state) { 982 + pm_runtime_mark_last_busy(st->dev); 983 + pm_runtime_put_autosuspend(st->dev); 984 + } 1125 985 1126 986 return 0; 1127 987 } ··· 1300 1120 if (!(iio_device_get_current_mode(indio_dev) & INDIO_ALL_TRIGGERED_MODES)) 1301 1121 return -EINVAL; 1302 1122 1123 + ret = pm_runtime_resume_and_get(st->dev); 1124 + if (ret < 0) 1125 + return ret; 1126 + 1303 1127 /* we continue with the triggered buffer */ 1304 1128 ret = at91_adc_dma_start(indio_dev); 1305 1129 if (ret) { 1306 1130 dev_err(&indio_dev->dev, "buffer prepare failed\n"); 1307 - return ret; 1131 + goto pm_runtime_put; 1308 1132 } 1309 1133 1310 1134 for_each_set_bit(bit, indio_dev->active_scan_mask, ··· 1319 1135 continue; 1320 1136 /* these channel types cannot be handled by this trigger */ 1321 1137 if (chan->type == IIO_POSITIONRELATIVE || 1322 - chan->type == IIO_PRESSURE) 1138 + chan->type == IIO_PRESSURE || 1139 + chan->type == IIO_TEMP) 1323 1140 continue; 1324 1141 1325 1142 at91_adc_cor(st, chan); ··· 1331 1146 if (at91_adc_buffer_check_use_irq(indio_dev, st)) 1332 1147 at91_adc_writel(st, IER, AT91_SAMA5D2_IER_DRDY); 1333 1148 1334 - return 0; 1149 + pm_runtime_put: 1150 + pm_runtime_mark_last_busy(st->dev); 1151 + pm_runtime_put_autosuspend(st->dev); 1152 + return ret; 1335 1153 } 1336 1154 1337 1155 static int at91_adc_buffer_postdisable(struct iio_dev *indio_dev) 1338 1156 { 1339 1157 struct at91_adc_state *st = iio_priv(indio_dev); 1158 + int ret; 1340 1159 u8 bit; 1341 1160 1342 1161 /* check if we are disabling triggered buffer or the touchscreen */ ··· 1350 1161 /* if we are not in triggered mode, nothing to do here */ 1351 1162 if (!(iio_device_get_current_mode(indio_dev) & INDIO_ALL_TRIGGERED_MODES)) 1352 1163 return -EINVAL; 1164 + 1165 + ret = pm_runtime_resume_and_get(st->dev); 1166 + if (ret < 0) 1167 + return ret; 1353 1168 1354 1169 /* 1355 1170 * For each enable channel we must disable it in hardware. ··· 1370 1177 continue; 1371 1178 /* these channel types are virtual, no need to do anything */ 1372 1179 if (chan->type == IIO_POSITIONRELATIVE || 1373 - chan->type == IIO_PRESSURE) 1180 + chan->type == IIO_PRESSURE || 1181 + chan->type == IIO_TEMP) 1374 1182 continue; 1375 1183 1376 1184 at91_adc_writel(st, CHDR, BIT(chan->channel)); ··· 1389 1195 /* if we are using DMA we must clear registers and end DMA */ 1390 1196 if (st->dma_st.dma_chan) 1391 1197 dmaengine_terminate_sync(st->dma_st.dma_chan); 1198 + 1199 + pm_runtime_mark_last_busy(st->dev); 1200 + pm_runtime_put_autosuspend(st->dev); 1392 1201 1393 1202 return 0; 1394 1203 } ··· 1421 1224 1422 1225 return trig; 1423 1226 } 1227 + 1424 1228 static void at91_adc_trigger_handler_nodma(struct iio_dev *indio_dev, 1425 1229 struct iio_poll_func *pf) 1426 1230 { ··· 1575 1377 return i; 1576 1378 } 1577 1379 1578 - static void at91_adc_setup_samp_freq(struct iio_dev *indio_dev, unsigned freq) 1380 + static void at91_adc_setup_samp_freq(struct iio_dev *indio_dev, unsigned freq, 1381 + unsigned int startup_time, 1382 + unsigned int tracktim) 1579 1383 { 1580 1384 struct at91_adc_state *st = iio_priv(indio_dev); 1581 1385 unsigned f_per, prescal, startup, mr; 1386 + int ret; 1582 1387 1583 1388 f_per = clk_get_rate(st->per_clk); 1584 1389 prescal = (f_per / (2 * freq)) - 1; 1585 1390 1586 - startup = at91_adc_startup_time(st->soc_info.startup_time, 1587 - freq / 1000); 1391 + startup = at91_adc_startup_time(startup_time, freq / 1000); 1392 + 1393 + ret = pm_runtime_resume_and_get(st->dev); 1394 + if (ret < 0) 1395 + return; 1588 1396 1589 1397 mr = at91_adc_readl(st, MR); 1590 1398 mr &= ~(AT91_SAMA5D2_MR_STARTUP_MASK | AT91_SAMA5D2_MR_PRESCAL_MASK); 1591 1399 mr |= AT91_SAMA5D2_MR_STARTUP(startup); 1592 1400 mr |= AT91_SAMA5D2_MR_PRESCAL(prescal); 1401 + mr |= AT91_SAMA5D2_MR_TRACKTIM(tracktim); 1593 1402 at91_adc_writel(st, MR, mr); 1594 1403 1595 - dev_dbg(&indio_dev->dev, "freq: %u, startup: %u, prescal: %u\n", 1596 - freq, startup, prescal); 1404 + pm_runtime_mark_last_busy(st->dev); 1405 + pm_runtime_put_autosuspend(st->dev); 1406 + 1407 + dev_dbg(&indio_dev->dev, "freq: %u, startup: %u, prescal: %u, tracktim=%u\n", 1408 + freq, startup, prescal, tracktim); 1597 1409 st->current_sample_rate = freq; 1598 1410 } 1599 1411 ··· 1730 1522 return IRQ_HANDLED; 1731 1523 } 1732 1524 1525 + /* This needs to be called with direct mode claimed and st->lock locked. */ 1733 1526 static int at91_adc_read_info_raw(struct iio_dev *indio_dev, 1734 1527 struct iio_chan_spec const *chan, int *val) 1735 1528 { ··· 1738 1529 u16 tmp_val; 1739 1530 int ret; 1740 1531 1532 + ret = pm_runtime_resume_and_get(st->dev); 1533 + if (ret < 0) 1534 + return ret; 1535 + 1741 1536 /* 1742 1537 * Keep in mind that we cannot use software trigger or touchscreen 1743 1538 * if external trigger is enabled 1744 1539 */ 1745 1540 if (chan->type == IIO_POSITIONRELATIVE) { 1746 - ret = iio_device_claim_direct_mode(indio_dev); 1747 - if (ret) 1748 - return ret; 1749 - mutex_lock(&st->lock); 1750 - 1751 1541 ret = at91_adc_read_position(st, chan->channel, 1752 1542 &tmp_val); 1753 1543 *val = tmp_val; 1754 - mutex_unlock(&st->lock); 1755 - iio_device_release_direct_mode(indio_dev); 1544 + if (ret > 0) 1545 + ret = at91_adc_adjust_val_osr(st, val); 1756 1546 1757 - return at91_adc_adjust_val_osr(st, val); 1547 + goto pm_runtime_put; 1758 1548 } 1759 1549 if (chan->type == IIO_PRESSURE) { 1760 - ret = iio_device_claim_direct_mode(indio_dev); 1761 - if (ret) 1762 - return ret; 1763 - mutex_lock(&st->lock); 1764 - 1765 1550 ret = at91_adc_read_pressure(st, chan->channel, 1766 1551 &tmp_val); 1767 1552 *val = tmp_val; 1768 - mutex_unlock(&st->lock); 1769 - iio_device_release_direct_mode(indio_dev); 1553 + if (ret > 0) 1554 + ret = at91_adc_adjust_val_osr(st, val); 1770 1555 1771 - return at91_adc_adjust_val_osr(st, val); 1556 + goto pm_runtime_put; 1772 1557 } 1773 1558 1774 - /* in this case we have a voltage channel */ 1775 - 1776 - ret = iio_device_claim_direct_mode(indio_dev); 1777 - if (ret) 1778 - return ret; 1779 - mutex_lock(&st->lock); 1559 + /* in this case we have a voltage or temperature channel */ 1780 1560 1781 1561 st->chan = chan; 1782 1562 1783 1563 at91_adc_cor(st, chan); 1784 1564 at91_adc_writel(st, CHER, BIT(chan->channel)); 1565 + /* 1566 + * TEMPMR.TEMPON needs to update after CHER otherwise if none 1567 + * of the channels are enabled and TEMPMR.TEMPON = 1 will 1568 + * trigger DRDY interruption while preparing for temperature read. 1569 + */ 1570 + if (chan->type == IIO_TEMP) 1571 + at91_adc_writel(st, TEMPMR, AT91_SAMA5D2_TEMPMR_TEMPON); 1785 1572 at91_adc_eoc_ena(st, chan->channel); 1786 1573 at91_adc_writel(st, CR, AT91_SAMA5D2_CR_START); 1787 1574 ··· 1797 1592 } 1798 1593 1799 1594 at91_adc_eoc_dis(st, st->chan->channel); 1595 + if (chan->type == IIO_TEMP) 1596 + at91_adc_writel(st, TEMPMR, 0U); 1800 1597 at91_adc_writel(st, CHDR, BIT(chan->channel)); 1801 1598 1802 1599 /* Needed to ACK the DRDY interruption */ 1803 1600 at91_adc_readl(st, LCDR); 1804 1601 1602 + pm_runtime_put: 1603 + pm_runtime_mark_last_busy(st->dev); 1604 + pm_runtime_put_autosuspend(st->dev); 1605 + return ret; 1606 + } 1607 + 1608 + static int at91_adc_read_info_locked(struct iio_dev *indio_dev, 1609 + struct iio_chan_spec const *chan, int *val) 1610 + { 1611 + struct at91_adc_state *st = iio_priv(indio_dev); 1612 + int ret; 1613 + 1614 + ret = iio_device_claim_direct_mode(indio_dev); 1615 + if (ret) 1616 + return ret; 1617 + 1618 + mutex_lock(&st->lock); 1619 + ret = at91_adc_read_info_raw(indio_dev, chan, val); 1805 1620 mutex_unlock(&st->lock); 1806 1621 1807 1622 iio_device_release_direct_mode(indio_dev); 1623 + 1624 + return ret; 1625 + } 1626 + 1627 + static void at91_adc_temp_sensor_configure(struct at91_adc_state *st, 1628 + bool start) 1629 + { 1630 + u32 sample_rate, oversampling_ratio; 1631 + u32 startup_time, tracktim, trackx; 1632 + 1633 + if (start) { 1634 + /* 1635 + * Configure the sensor for best accuracy: 10MHz frequency, 1636 + * oversampling rate of 256, tracktim=0xf and trackx=1. 1637 + */ 1638 + sample_rate = 10 * MEGA; 1639 + oversampling_ratio = 256; 1640 + startup_time = AT91_SAMA5D2_MR_STARTUP_TS_MIN; 1641 + tracktim = AT91_SAMA5D2_MR_TRACKTIM_TS; 1642 + trackx = AT91_SAMA5D2_TRACKX_TS; 1643 + 1644 + st->temp_st.saved_sample_rate = st->current_sample_rate; 1645 + st->temp_st.saved_oversampling = st->oversampling_ratio; 1646 + } else { 1647 + /* Go back to previous settings. */ 1648 + sample_rate = st->temp_st.saved_sample_rate; 1649 + oversampling_ratio = st->temp_st.saved_oversampling; 1650 + startup_time = st->soc_info.startup_time; 1651 + tracktim = 0; 1652 + trackx = 0; 1653 + } 1654 + 1655 + at91_adc_setup_samp_freq(st->indio_dev, sample_rate, startup_time, 1656 + tracktim); 1657 + at91_adc_config_emr(st, oversampling_ratio, trackx); 1658 + } 1659 + 1660 + static int at91_adc_read_temp(struct iio_dev *indio_dev, 1661 + struct iio_chan_spec const *chan, int *val) 1662 + { 1663 + struct at91_adc_state *st = iio_priv(indio_dev); 1664 + struct at91_adc_temp_sensor_clb *clb = &st->soc_info.temp_sensor_clb; 1665 + u64 div1, div2; 1666 + u32 tmp; 1667 + int ret, vbg, vtemp; 1668 + 1669 + ret = iio_device_claim_direct_mode(indio_dev); 1670 + if (ret) 1671 + return ret; 1672 + mutex_lock(&st->lock); 1673 + 1674 + ret = pm_runtime_resume_and_get(st->dev); 1675 + if (ret < 0) 1676 + goto unlock; 1677 + 1678 + at91_adc_temp_sensor_configure(st, true); 1679 + 1680 + /* Read VBG. */ 1681 + tmp = at91_adc_readl(st, ACR); 1682 + tmp |= AT91_SAMA5D2_ACR_SRCLCH; 1683 + at91_adc_writel(st, ACR, tmp); 1684 + ret = at91_adc_read_info_raw(indio_dev, chan, &vbg); 1685 + if (ret < 0) 1686 + goto restore_config; 1687 + 1688 + /* Read VTEMP. */ 1689 + tmp &= ~AT91_SAMA5D2_ACR_SRCLCH; 1690 + at91_adc_writel(st, ACR, tmp); 1691 + ret = at91_adc_read_info_raw(indio_dev, chan, &vtemp); 1692 + 1693 + restore_config: 1694 + /* Revert previous settings. */ 1695 + at91_adc_temp_sensor_configure(st, false); 1696 + pm_runtime_mark_last_busy(st->dev); 1697 + pm_runtime_put_autosuspend(st->dev); 1698 + unlock: 1699 + mutex_unlock(&st->lock); 1700 + iio_device_release_direct_mode(indio_dev); 1701 + if (ret < 0) 1702 + return ret; 1703 + 1704 + /* 1705 + * Temp[milli] = p1[milli] + (vtemp * clb->p6 - clb->p4 * vbg)/ 1706 + * (vbg * AT91_ADC_TS_VTEMP_DT) 1707 + */ 1708 + div1 = DIV_ROUND_CLOSEST_ULL(((u64)vtemp * clb->p6), vbg); 1709 + div1 = DIV_ROUND_CLOSEST_ULL((div1 * 1000), AT91_ADC_TS_VTEMP_DT); 1710 + div2 = DIV_ROUND_CLOSEST_ULL((u64)clb->p4, AT91_ADC_TS_VTEMP_DT); 1711 + div2 *= 1000; 1712 + *val = clb->p1 + (int)div1 - (int)div2; 1713 + 1808 1714 return ret; 1809 1715 } 1810 1716 ··· 1927 1611 1928 1612 switch (mask) { 1929 1613 case IIO_CHAN_INFO_RAW: 1930 - return at91_adc_read_info_raw(indio_dev, chan, val); 1614 + return at91_adc_read_info_locked(indio_dev, chan, val); 1615 + 1931 1616 case IIO_CHAN_INFO_SCALE: 1932 1617 *val = st->vref_uv / 1000; 1933 1618 if (chan->differential) 1934 1619 *val *= 2; 1935 1620 *val2 = chan->scan_type.realbits; 1936 1621 return IIO_VAL_FRACTIONAL_LOG2; 1622 + 1623 + case IIO_CHAN_INFO_PROCESSED: 1624 + if (chan->type != IIO_TEMP) 1625 + return -EINVAL; 1626 + return at91_adc_read_temp(indio_dev, chan, val); 1937 1627 1938 1628 case IIO_CHAN_INFO_SAMP_FREQ: 1939 1629 *val = at91_adc_get_sample_freq(st); ··· 1959 1637 int val, int val2, long mask) 1960 1638 { 1961 1639 struct at91_adc_state *st = iio_priv(indio_dev); 1640 + int ret; 1962 1641 1963 1642 switch (mask) { 1964 1643 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 1965 - if ((val != AT91_OSR_1SAMPLES) && (val != AT91_OSR_4SAMPLES) && 1966 - (val != AT91_OSR_16SAMPLES)) 1967 - return -EINVAL; 1968 1644 /* if no change, optimize out */ 1969 1645 if (val == st->oversampling_ratio) 1970 1646 return 0; 1971 - st->oversampling_ratio = val; 1647 + 1648 + ret = iio_device_claim_direct_mode(indio_dev); 1649 + if (ret) 1650 + return ret; 1651 + mutex_lock(&st->lock); 1972 1652 /* update ratio */ 1973 - at91_adc_config_emr(st); 1974 - return 0; 1653 + ret = at91_adc_config_emr(st, val, 0); 1654 + mutex_unlock(&st->lock); 1655 + iio_device_release_direct_mode(indio_dev); 1656 + return ret; 1975 1657 case IIO_CHAN_INFO_SAMP_FREQ: 1976 1658 if (val < st->soc_info.min_sample_rate || 1977 1659 val > st->soc_info.max_sample_rate) 1978 1660 return -EINVAL; 1979 1661 1980 - at91_adc_setup_samp_freq(indio_dev, val); 1662 + ret = iio_device_claim_direct_mode(indio_dev); 1663 + if (ret) 1664 + return ret; 1665 + mutex_lock(&st->lock); 1666 + at91_adc_setup_samp_freq(indio_dev, val, 1667 + st->soc_info.startup_time, 0); 1668 + mutex_unlock(&st->lock); 1669 + iio_device_release_direct_mode(indio_dev); 1981 1670 return 0; 1671 + default: 1672 + return -EINVAL; 1673 + } 1674 + } 1675 + 1676 + static int at91_adc_read_avail(struct iio_dev *indio_dev, 1677 + struct iio_chan_spec const *chan, 1678 + const int **vals, int *type, int *length, 1679 + long mask) 1680 + { 1681 + struct at91_adc_state *st = iio_priv(indio_dev); 1682 + 1683 + switch (mask) { 1684 + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 1685 + *vals = (int *)st->soc_info.platform->oversampling_avail; 1686 + *type = IIO_VAL_INT; 1687 + *length = st->soc_info.platform->oversampling_avail_no; 1688 + return IIO_AVAIL_LIST; 1982 1689 default: 1983 1690 return -EINVAL; 1984 1691 } ··· 2168 1817 at91_adc_writel(st, MR, 2169 1818 AT91_SAMA5D2_MR_TRANSFER(2) | AT91_SAMA5D2_MR_ANACH); 2170 1819 2171 - at91_adc_setup_samp_freq(indio_dev, st->soc_info.min_sample_rate); 1820 + at91_adc_setup_samp_freq(indio_dev, st->soc_info.min_sample_rate, 1821 + st->soc_info.startup_time, 0); 2172 1822 2173 1823 /* configure extended mode register */ 2174 - at91_adc_config_emr(st); 1824 + at91_adc_config_emr(st, st->oversampling_ratio, 0); 2175 1825 } 2176 1826 2177 1827 static ssize_t at91_adc_get_fifo_state(struct device *dev, ··· 2201 1849 static IIO_CONST_ATTR(hwfifo_watermark_min, "2"); 2202 1850 static IIO_CONST_ATTR(hwfifo_watermark_max, AT91_HWFIFO_MAX_SIZE_STR); 2203 1851 2204 - static IIO_CONST_ATTR(oversampling_ratio_available, 2205 - __stringify(AT91_OSR_1SAMPLES) " " 2206 - __stringify(AT91_OSR_4SAMPLES) " " 2207 - __stringify(AT91_OSR_16SAMPLES)); 2208 - 2209 - static struct attribute *at91_adc_attributes[] = { 2210 - &iio_const_attr_oversampling_ratio_available.dev_attr.attr, 2211 - NULL, 2212 - }; 2213 - 2214 - static const struct attribute_group at91_adc_attribute_group = { 2215 - .attrs = at91_adc_attributes, 2216 - }; 2217 - 2218 1852 static const struct attribute *at91_adc_fifo_attributes[] = { 2219 1853 &iio_const_attr_hwfifo_watermark_min.dev_attr.attr, 2220 1854 &iio_const_attr_hwfifo_watermark_max.dev_attr.attr, ··· 2210 1872 }; 2211 1873 2212 1874 static const struct iio_info at91_adc_info = { 2213 - .attrs = &at91_adc_attribute_group, 1875 + .read_avail = &at91_adc_read_avail, 2214 1876 .read_raw = &at91_adc_read_raw, 2215 1877 .write_raw = &at91_adc_write_raw, 2216 1878 .update_scan_mode = &at91_adc_update_scan_mode, 2217 - .of_xlate = &at91_adc_of_xlate, 1879 + .fwnode_xlate = &at91_adc_fwnode_xlate, 2218 1880 .hwfifo_set_watermark = &at91_adc_set_watermark, 2219 1881 }; 2220 1882 ··· 2256 1918 return 0; 2257 1919 } 2258 1920 1921 + static int at91_adc_temp_sensor_init(struct at91_adc_state *st, 1922 + struct device *dev) 1923 + { 1924 + struct at91_adc_temp_sensor_clb *clb = &st->soc_info.temp_sensor_clb; 1925 + struct nvmem_cell *temp_calib; 1926 + u32 *buf; 1927 + size_t len; 1928 + int ret = 0; 1929 + 1930 + if (!st->soc_info.platform->temp_sensor) 1931 + return 0; 1932 + 1933 + /* Get the calibration data from NVMEM. */ 1934 + temp_calib = devm_nvmem_cell_get(dev, "temperature_calib"); 1935 + if (IS_ERR(temp_calib)) { 1936 + ret = PTR_ERR(temp_calib); 1937 + if (ret != -ENOENT) 1938 + dev_err(dev, "Failed to get temperature_calib cell!\n"); 1939 + return ret; 1940 + } 1941 + 1942 + buf = nvmem_cell_read(temp_calib, &len); 1943 + if (IS_ERR(buf)) { 1944 + dev_err(dev, "Failed to read calibration data!\n"); 1945 + return PTR_ERR(buf); 1946 + } 1947 + if (len < AT91_ADC_TS_CLB_IDX_MAX * 4) { 1948 + dev_err(dev, "Invalid calibration data!\n"); 1949 + ret = -EINVAL; 1950 + goto free_buf; 1951 + } 1952 + 1953 + /* Store calibration data for later use. */ 1954 + clb->p1 = buf[AT91_ADC_TS_CLB_IDX_P1]; 1955 + clb->p4 = buf[AT91_ADC_TS_CLB_IDX_P4]; 1956 + clb->p6 = buf[AT91_ADC_TS_CLB_IDX_P6]; 1957 + 1958 + /* 1959 + * We prepare here the conversion to milli and also add constant 1960 + * factor (5 degrees Celsius) to p1 here to avoid doing it on 1961 + * hotpath. 1962 + */ 1963 + clb->p1 = clb->p1 * 1000 + 5000; 1964 + 1965 + free_buf: 1966 + kfree(buf); 1967 + return ret; 1968 + } 1969 + 2259 1970 static int at91_adc_probe(struct platform_device *pdev) 2260 1971 { 1972 + struct device *dev = &pdev->dev; 2261 1973 struct iio_dev *indio_dev; 2262 1974 struct at91_adc_state *st; 2263 1975 struct resource *res; 2264 - int ret, i; 1976 + int ret, i, num_channels; 2265 1977 u32 edge_type = IRQ_TYPE_NONE; 2266 1978 2267 1979 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); ··· 2321 1933 st = iio_priv(indio_dev); 2322 1934 st->indio_dev = indio_dev; 2323 1935 2324 - st->soc_info.platform = of_device_get_match_data(&pdev->dev); 1936 + st->soc_info.platform = device_get_match_data(dev); 1937 + 1938 + ret = at91_adc_temp_sensor_init(st, &pdev->dev); 1939 + /* Don't register temperature channel if initialization failed. */ 1940 + if (ret) 1941 + num_channels = st->soc_info.platform->max_channels - 1; 1942 + else 1943 + num_channels = st->soc_info.platform->max_channels; 2325 1944 2326 1945 indio_dev->name = dev_name(&pdev->dev); 2327 1946 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; 2328 1947 indio_dev->info = &at91_adc_info; 2329 1948 indio_dev->channels = *st->soc_info.platform->adc_channels; 2330 - indio_dev->num_channels = st->soc_info.platform->max_channels; 1949 + indio_dev->num_channels = num_channels; 2331 1950 2332 1951 bitmap_set(&st->touch_st.channels_bitmask, 2333 1952 st->soc_info.platform->touch_chan_x, 1); ··· 2343 1948 bitmap_set(&st->touch_st.channels_bitmask, 2344 1949 st->soc_info.platform->touch_chan_p, 1); 2345 1950 2346 - st->oversampling_ratio = AT91_OSR_1SAMPLES; 1951 + st->oversampling_ratio = 1; 2347 1952 2348 - ret = of_property_read_u32(pdev->dev.of_node, 2349 - "atmel,min-sample-rate-hz", 2350 - &st->soc_info.min_sample_rate); 1953 + ret = device_property_read_u32(dev, "atmel,min-sample-rate-hz", 1954 + &st->soc_info.min_sample_rate); 2351 1955 if (ret) { 2352 1956 dev_err(&pdev->dev, 2353 1957 "invalid or missing value for atmel,min-sample-rate-hz\n"); 2354 1958 return ret; 2355 1959 } 2356 1960 2357 - ret = of_property_read_u32(pdev->dev.of_node, 2358 - "atmel,max-sample-rate-hz", 2359 - &st->soc_info.max_sample_rate); 1961 + ret = device_property_read_u32(dev, "atmel,max-sample-rate-hz", 1962 + &st->soc_info.max_sample_rate); 2360 1963 if (ret) { 2361 1964 dev_err(&pdev->dev, 2362 1965 "invalid or missing value for atmel,max-sample-rate-hz\n"); 2363 1966 return ret; 2364 1967 } 2365 1968 2366 - ret = of_property_read_u32(pdev->dev.of_node, "atmel,startup-time-ms", 2367 - &st->soc_info.startup_time); 1969 + ret = device_property_read_u32(dev, "atmel,startup-time-ms", 1970 + &st->soc_info.startup_time); 2368 1971 if (ret) { 2369 1972 dev_err(&pdev->dev, 2370 1973 "invalid or missing value for atmel,startup-time-ms\n"); 2371 1974 return ret; 2372 1975 } 2373 1976 2374 - ret = of_property_read_u32(pdev->dev.of_node, 2375 - "atmel,trigger-edge-type", &edge_type); 1977 + ret = device_property_read_u32(dev, "atmel,trigger-edge-type", 1978 + &edge_type); 2376 1979 if (ret) { 2377 1980 dev_dbg(&pdev->dev, 2378 1981 "atmel,trigger-edge-type not specified, only software trigger available\n"); ··· 2444 2051 if (ret) 2445 2052 goto vref_disable; 2446 2053 2447 - at91_adc_hw_init(indio_dev); 2448 - 2449 2054 platform_set_drvdata(pdev, indio_dev); 2055 + st->dev = &pdev->dev; 2056 + pm_runtime_set_autosuspend_delay(st->dev, 500); 2057 + pm_runtime_use_autosuspend(st->dev); 2058 + pm_runtime_set_active(st->dev); 2059 + pm_runtime_enable(st->dev); 2060 + pm_runtime_get_noresume(st->dev); 2061 + 2062 + at91_adc_hw_init(indio_dev); 2450 2063 2451 2064 ret = at91_adc_buffer_and_trigger_init(&pdev->dev, indio_dev); 2452 2065 if (ret < 0) 2453 - goto per_clk_disable_unprepare; 2066 + goto err_pm_disable; 2454 2067 2455 2068 if (dma_coerce_mask_and_coherent(&indio_dev->dev, DMA_BIT_MASK(32))) 2456 2069 dev_info(&pdev->dev, "cannot set DMA mask to 32-bit\n"); ··· 2472 2073 dev_info(&pdev->dev, "version: %x\n", 2473 2074 readl_relaxed(st->base + st->soc_info.platform->layout->VERSION)); 2474 2075 2076 + pm_runtime_mark_last_busy(st->dev); 2077 + pm_runtime_put_autosuspend(st->dev); 2078 + 2475 2079 return 0; 2476 2080 2477 2081 dma_disable: 2478 2082 at91_adc_dma_disable(st); 2479 - per_clk_disable_unprepare: 2083 + err_pm_disable: 2084 + pm_runtime_put_noidle(st->dev); 2085 + pm_runtime_disable(st->dev); 2086 + pm_runtime_set_suspended(st->dev); 2087 + pm_runtime_dont_use_autosuspend(st->dev); 2480 2088 clk_disable_unprepare(st->per_clk); 2481 2089 vref_disable: 2482 2090 regulator_disable(st->vref); ··· 2501 2095 2502 2096 at91_adc_dma_disable(st); 2503 2097 2098 + pm_runtime_disable(st->dev); 2099 + pm_runtime_set_suspended(st->dev); 2504 2100 clk_disable_unprepare(st->per_clk); 2505 2101 2506 2102 regulator_disable(st->vref); ··· 2515 2107 { 2516 2108 struct iio_dev *indio_dev = dev_get_drvdata(dev); 2517 2109 struct at91_adc_state *st = iio_priv(indio_dev); 2110 + int ret; 2111 + 2112 + ret = pm_runtime_resume_and_get(st->dev); 2113 + if (ret < 0) 2114 + return ret; 2115 + 2116 + if (iio_buffer_enabled(indio_dev)) 2117 + at91_adc_buffer_postdisable(indio_dev); 2518 2118 2519 2119 /* 2520 2120 * Do a sofware reset of the ADC before we go to suspend. ··· 2532 2116 */ 2533 2117 at91_adc_writel(st, CR, AT91_SAMA5D2_CR_SWRST); 2534 2118 2119 + pm_runtime_mark_last_busy(st->dev); 2120 + pm_runtime_put_noidle(st->dev); 2535 2121 clk_disable_unprepare(st->per_clk); 2536 2122 regulator_disable(st->vref); 2537 2123 regulator_disable(st->reg); ··· 2563 2145 if (ret) 2564 2146 goto vref_disable_resume; 2565 2147 2148 + pm_runtime_get_noresume(st->dev); 2149 + 2566 2150 at91_adc_hw_init(indio_dev); 2567 2151 2568 2152 /* reconfiguring trigger hardware state */ 2569 - if (!iio_buffer_enabled(indio_dev)) 2570 - return 0; 2153 + if (iio_buffer_enabled(indio_dev)) { 2154 + ret = at91_adc_buffer_prepare(indio_dev); 2155 + if (ret) 2156 + goto pm_runtime_put; 2571 2157 2572 - /* check if we are enabling triggered buffer or the touchscreen */ 2573 - if (at91_adc_current_chan_is_touch(indio_dev)) 2574 - return at91_adc_configure_touch(st, true); 2575 - else 2576 - return at91_adc_configure_trigger(st->trig, true); 2158 + at91_adc_configure_trigger_registers(st, true); 2159 + } 2577 2160 2578 - /* not needed but more explicit */ 2161 + pm_runtime_mark_last_busy(st->dev); 2162 + pm_runtime_put_autosuspend(st->dev); 2163 + 2579 2164 return 0; 2580 2165 2166 + pm_runtime_put: 2167 + pm_runtime_mark_last_busy(st->dev); 2168 + pm_runtime_put_noidle(st->dev); 2169 + clk_disable_unprepare(st->per_clk); 2581 2170 vref_disable_resume: 2582 2171 regulator_disable(st->vref); 2583 2172 reg_disable_resume: ··· 2594 2169 return ret; 2595 2170 } 2596 2171 2597 - static DEFINE_SIMPLE_DEV_PM_OPS(at91_adc_pm_ops, at91_adc_suspend, 2598 - at91_adc_resume); 2172 + static int at91_adc_runtime_suspend(struct device *dev) 2173 + { 2174 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 2175 + struct at91_adc_state *st = iio_priv(indio_dev); 2176 + 2177 + clk_disable(st->per_clk); 2178 + 2179 + return 0; 2180 + } 2181 + 2182 + static int at91_adc_runtime_resume(struct device *dev) 2183 + { 2184 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 2185 + struct at91_adc_state *st = iio_priv(indio_dev); 2186 + 2187 + return clk_enable(st->per_clk); 2188 + } 2189 + 2190 + static const struct dev_pm_ops at91_adc_pm_ops = { 2191 + SYSTEM_SLEEP_PM_OPS(at91_adc_suspend, at91_adc_resume) 2192 + RUNTIME_PM_OPS(at91_adc_runtime_suspend, at91_adc_runtime_resume, 2193 + NULL) 2194 + }; 2599 2195 2600 2196 static const struct of_device_id at91_adc_dt_match[] = { 2601 2197 { ··· 2637 2191 .driver = { 2638 2192 .name = "at91-sama5d2_adc", 2639 2193 .of_match_table = at91_adc_dt_match, 2640 - .pm = pm_sleep_ptr(&at91_adc_pm_ops), 2194 + .pm = pm_ptr(&at91_adc_pm_ops), 2641 2195 }, 2642 2196 }; 2643 2197 module_platform_driver(at91_adc_driver)
+5 -3
drivers/iio/adc/imx8qxp-adc.c
··· 202 202 struct imx8qxp_adc *adc = iio_priv(indio_dev); 203 203 struct device *dev = adc->dev; 204 204 205 - u32 ctrl, vref_uv; 205 + u32 ctrl; 206 206 long ret; 207 207 208 208 switch (mask) { ··· 245 245 return IIO_VAL_INT; 246 246 247 247 case IIO_CHAN_INFO_SCALE: 248 - vref_uv = regulator_get_voltage(adc->vref); 249 - *val = vref_uv / 1000; 248 + ret = regulator_get_voltage(adc->vref); 249 + if (ret < 0) 250 + return ret; 251 + *val = ret / 1000; 250 252 *val2 = 12; 251 253 return IIO_VAL_FRACTIONAL_LOG2; 252 254
+6 -17
drivers/iio/adc/ingenic-adc.c
··· 719 719 } 720 720 } 721 721 722 - static int ingenic_adc_of_xlate(struct iio_dev *iio_dev, 723 - const struct of_phandle_args *iiospec) 722 + static int ingenic_adc_fwnode_xlate(struct iio_dev *iio_dev, 723 + const struct fwnode_reference_args *iiospec) 724 724 { 725 725 int i; 726 726 727 - if (!iiospec->args_count) 727 + if (!iiospec->nargs) 728 728 return -EINVAL; 729 729 730 730 for (i = 0; i < iio_dev->num_channels; ++i) ··· 734 734 return -EINVAL; 735 735 } 736 736 737 - static void ingenic_adc_clk_cleanup(void *data) 738 - { 739 - clk_unprepare(data); 740 - } 741 - 742 737 static const struct iio_info ingenic_adc_info = { 743 738 .write_raw = ingenic_adc_write_raw, 744 739 .read_raw = ingenic_adc_read_raw, 745 740 .read_avail = ingenic_adc_read_avail, 746 - .of_xlate = ingenic_adc_of_xlate, 741 + .fwnode_xlate = ingenic_adc_fwnode_xlate, 747 742 }; 748 743 749 744 static int ingenic_adc_buffer_enable(struct iio_dev *iio_dev) ··· 853 858 if (IS_ERR(adc->base)) 854 859 return PTR_ERR(adc->base); 855 860 856 - adc->clk = devm_clk_get(dev, "adc"); 861 + adc->clk = devm_clk_get_prepared(dev, "adc"); 857 862 if (IS_ERR(adc->clk)) { 858 863 dev_err(dev, "Unable to get clock\n"); 859 864 return PTR_ERR(adc->clk); 860 865 } 861 866 862 - ret = clk_prepare_enable(adc->clk); 867 + ret = clk_enable(adc->clk); 863 868 if (ret) { 864 869 dev_err(dev, "Failed to enable clock\n"); 865 870 return ret; ··· 887 892 888 893 usleep_range(2000, 3000); /* Must wait at least 2ms. */ 889 894 clk_disable(adc->clk); 890 - 891 - ret = devm_add_action_or_reset(dev, ingenic_adc_clk_cleanup, adc->clk); 892 - if (ret) { 893 - dev_err(dev, "Unable to add action\n"); 894 - return ret; 895 - } 896 895 897 896 iio_dev->name = "jz-adc"; 898 897 iio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
+1 -17
drivers/iio/adc/lpc18xx_adc.c
··· 121 121 writel(0, adc->base + LPC18XX_ADC_CR); 122 122 } 123 123 124 - static void lpc18xx_clk_disable(void *clk) 125 - { 126 - clk_disable_unprepare(clk); 127 - } 128 - 129 124 static void lpc18xx_regulator_disable(void *vref) 130 125 { 131 126 regulator_disable(vref); ··· 146 151 if (IS_ERR(adc->base)) 147 152 return PTR_ERR(adc->base); 148 153 149 - adc->clk = devm_clk_get(&pdev->dev, NULL); 154 + adc->clk = devm_clk_get_enabled(&pdev->dev, NULL); 150 155 if (IS_ERR(adc->clk)) 151 156 return dev_err_probe(&pdev->dev, PTR_ERR(adc->clk), 152 157 "error getting clock\n"); ··· 169 174 } 170 175 171 176 ret = devm_add_action_or_reset(&pdev->dev, lpc18xx_regulator_disable, adc->vref); 172 - if (ret) 173 - return ret; 174 - 175 - ret = clk_prepare_enable(adc->clk); 176 - if (ret) { 177 - dev_err(&pdev->dev, "unable to enable clock\n"); 178 - return ret; 179 - } 180 - 181 - ret = devm_add_action_or_reset(&pdev->dev, lpc18xx_clk_disable, 182 - adc->clk); 183 177 if (ret) 184 178 return ret; 185 179
+183
drivers/iio/adc/max11205.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Maxim MAX11205 16-Bit Delta-Sigma ADC 4 + * 5 + * Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX1240-max11205.pdf 6 + * Copyright (C) 2022 Analog Devices, Inc. 7 + * Author: Ramona Bolboaca <ramona.bolboaca@analog.com> 8 + */ 9 + 10 + #include <linux/device.h> 11 + #include <linux/module.h> 12 + #include <linux/regulator/consumer.h> 13 + #include <linux/spi/spi.h> 14 + 15 + #include <linux/iio/iio.h> 16 + #include <linux/iio/adc/ad_sigma_delta.h> 17 + 18 + #define MAX11205_BIT_SCALE 15 19 + #define MAX11205A_OUT_DATA_RATE 116 20 + #define MAX11205B_OUT_DATA_RATE 13 21 + 22 + enum max11205_chip_type { 23 + TYPE_MAX11205A, 24 + TYPE_MAX11205B, 25 + }; 26 + 27 + struct max11205_chip_info { 28 + unsigned int out_data_rate; 29 + const char *name; 30 + }; 31 + 32 + struct max11205_state { 33 + const struct max11205_chip_info *chip_info; 34 + struct regulator *vref; 35 + struct ad_sigma_delta sd; 36 + }; 37 + 38 + static const struct ad_sigma_delta_info max11205_sigma_delta_info = { 39 + .has_registers = false, 40 + }; 41 + 42 + static int max11205_read_raw(struct iio_dev *indio_dev, 43 + struct iio_chan_spec const *chan, 44 + int *val, int *val2, long mask) 45 + { 46 + struct max11205_state *st = iio_priv(indio_dev); 47 + int reg_mv; 48 + 49 + switch (mask) { 50 + case IIO_CHAN_INFO_RAW: 51 + return ad_sigma_delta_single_conversion(indio_dev, chan, val); 52 + case IIO_CHAN_INFO_SCALE: 53 + reg_mv = regulator_get_voltage(st->vref); 54 + if (reg_mv < 0) 55 + return reg_mv; 56 + reg_mv /= 1000; 57 + *val = reg_mv; 58 + *val2 = MAX11205_BIT_SCALE; 59 + return IIO_VAL_FRACTIONAL_LOG2; 60 + case IIO_CHAN_INFO_SAMP_FREQ: 61 + *val = st->chip_info->out_data_rate; 62 + return IIO_VAL_INT; 63 + default: 64 + return -EINVAL; 65 + } 66 + } 67 + 68 + static const struct iio_info max11205_iio_info = { 69 + .read_raw = max11205_read_raw, 70 + .validate_trigger = ad_sd_validate_trigger, 71 + }; 72 + 73 + static const struct iio_chan_spec max11205_channels[] = { 74 + { 75 + .type = IIO_VOLTAGE, 76 + .indexed = 1, 77 + .scan_type = { 78 + .sign = 's', 79 + .realbits = 16, 80 + .storagebits = 16, 81 + .endianness = IIO_BE, 82 + }, 83 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 84 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | 85 + BIT(IIO_CHAN_INFO_SCALE), 86 + }, 87 + }; 88 + 89 + static const struct max11205_chip_info max11205_chip_info[] = { 90 + [TYPE_MAX11205A] = { 91 + .out_data_rate = MAX11205A_OUT_DATA_RATE, 92 + .name = "max11205a", 93 + }, 94 + [TYPE_MAX11205B] = { 95 + .out_data_rate = MAX11205B_OUT_DATA_RATE, 96 + .name = "max11205b", 97 + }, 98 + }; 99 + 100 + static void max11205_reg_disable(void *reg) 101 + { 102 + regulator_disable(reg); 103 + } 104 + 105 + static int max11205_probe(struct spi_device *spi) 106 + { 107 + struct max11205_state *st; 108 + struct iio_dev *indio_dev; 109 + int ret; 110 + 111 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 112 + if (!indio_dev) 113 + return -ENOMEM; 114 + 115 + st = iio_priv(indio_dev); 116 + 117 + ad_sd_init(&st->sd, indio_dev, spi, &max11205_sigma_delta_info); 118 + 119 + st->chip_info = device_get_match_data(&spi->dev); 120 + if (!st->chip_info) 121 + st->chip_info = 122 + (const struct max11205_chip_info *)spi_get_device_id(spi)->driver_data; 123 + 124 + indio_dev->name = st->chip_info->name; 125 + indio_dev->modes = INDIO_DIRECT_MODE; 126 + indio_dev->channels = max11205_channels; 127 + indio_dev->num_channels = 1; 128 + indio_dev->info = &max11205_iio_info; 129 + 130 + st->vref = devm_regulator_get(&spi->dev, "vref"); 131 + if (IS_ERR(st->vref)) 132 + return dev_err_probe(&spi->dev, PTR_ERR(st->vref), 133 + "Failed to get vref regulator\n"); 134 + 135 + ret = regulator_enable(st->vref); 136 + if (ret) 137 + return ret; 138 + 139 + ret = devm_add_action_or_reset(&spi->dev, max11205_reg_disable, st->vref); 140 + if (ret) 141 + return ret; 142 + 143 + ret = devm_ad_sd_setup_buffer_and_trigger(&spi->dev, indio_dev); 144 + if (ret) 145 + return ret; 146 + 147 + return devm_iio_device_register(&spi->dev, indio_dev); 148 + } 149 + 150 + static const struct spi_device_id max11205_spi_ids[] = { 151 + { "max11205a", (kernel_ulong_t)&max11205_chip_info[TYPE_MAX11205A] }, 152 + { "max11205b", (kernel_ulong_t)&max11205_chip_info[TYPE_MAX11205B] }, 153 + { } 154 + }; 155 + MODULE_DEVICE_TABLE(spi, max11205_spi_ids); 156 + 157 + static const struct of_device_id max11205_dt_ids[] = { 158 + { 159 + .compatible = "maxim,max11205a", 160 + .data = &max11205_chip_info[TYPE_MAX11205A], 161 + }, 162 + { 163 + .compatible = "maxim,max11205b", 164 + .data = &max11205_chip_info[TYPE_MAX11205B], 165 + }, 166 + { } 167 + }; 168 + MODULE_DEVICE_TABLE(of, max11205_dt_ids); 169 + 170 + static struct spi_driver max11205_spi_driver = { 171 + .driver = { 172 + .name = "max11205", 173 + .of_match_table = max11205_dt_ids, 174 + }, 175 + .probe = max11205_probe, 176 + .id_table = max11205_spi_ids, 177 + }; 178 + module_spi_driver(max11205_spi_driver); 179 + 180 + MODULE_AUTHOR("Ramona Bolboaca <ramona.bolboaca@analog.com>"); 181 + MODULE_DESCRIPTION("MAX11205 ADC driver"); 182 + MODULE_LICENSE("GPL v2"); 183 + MODULE_IMPORT_NS(IIO_AD_SIGMA_DELTA);
-6
drivers/iio/adc/max1363.c
··· 29 29 #include <linux/iio/sysfs.h> 30 30 #include <linux/iio/events.h> 31 31 #include <linux/iio/buffer.h> 32 - #include <linux/iio/driver.h> 33 32 #include <linux/iio/kfifo_buf.h> 34 33 #include <linux/iio/trigger_consumer.h> 35 34 #include <linux/iio/triggered_buffer.h> ··· 1593 1594 sizeof(struct max1363_state)); 1594 1595 if (!indio_dev) 1595 1596 return -ENOMEM; 1596 - 1597 - ret = devm_iio_map_array_register(&client->dev, indio_dev, 1598 - client->dev.platform_data); 1599 - if (ret < 0) 1600 - return ret; 1601 1597 1602 1598 st = iio_priv(indio_dev); 1603 1599
+1 -1
drivers/iio/adc/mt6360-adc.c
··· 353 353 return devm_iio_device_register(&pdev->dev, indio_dev); 354 354 } 355 355 356 - static const struct of_device_id __maybe_unused mt6360_adc_of_id[] = { 356 + static const struct of_device_id mt6360_adc_of_id[] = { 357 357 { .compatible = "mediatek,mt6360-adc", }, 358 358 {} 359 359 };
+28 -30
drivers/iio/adc/qcom-pm8xxx-xoadc.c
··· 14 14 #include <linux/iio/iio.h> 15 15 #include <linux/iio/sysfs.h> 16 16 #include <linux/module.h> 17 - #include <linux/of.h> 18 - #include <linux/of_device.h> 17 + #include <linux/mod_devicetable.h> 19 18 #include <linux/platform_device.h> 19 + #include <linux/property.h> 20 20 #include <linux/regmap.h> 21 21 #include <linux/init.h> 22 22 #include <linux/interrupt.h> ··· 694 694 } 695 695 } 696 696 697 - static int pm8xxx_of_xlate(struct iio_dev *indio_dev, 698 - const struct of_phandle_args *iiospec) 697 + static int pm8xxx_fwnode_xlate(struct iio_dev *indio_dev, 698 + const struct fwnode_reference_args *iiospec) 699 699 { 700 700 struct pm8xxx_xoadc *adc = iio_priv(indio_dev); 701 701 u8 pre_scale_mux; ··· 706 706 * First cell is prescaler or premux, second cell is analog 707 707 * mux. 708 708 */ 709 - if (iiospec->args_count != 2) { 710 - dev_err(&indio_dev->dev, "wrong number of arguments for %pOFn need 2 got %d\n", 711 - iiospec->np, 712 - iiospec->args_count); 709 + if (iiospec->nargs != 2) { 710 + dev_err(&indio_dev->dev, "wrong number of arguments for %pfwP need 2 got %d\n", 711 + iiospec->fwnode, 712 + iiospec->nargs); 713 713 return -EINVAL; 714 714 } 715 715 pre_scale_mux = (u8)iiospec->args[0]; ··· 727 727 } 728 728 729 729 static const struct iio_info pm8xxx_xoadc_info = { 730 - .of_xlate = pm8xxx_of_xlate, 730 + .fwnode_xlate = pm8xxx_fwnode_xlate, 731 731 .read_raw = pm8xxx_read_raw, 732 732 }; 733 733 734 734 static int pm8xxx_xoadc_parse_channel(struct device *dev, 735 - struct device_node *np, 735 + struct fwnode_handle *fwnode, 736 736 const struct xoadc_channel *hw_channels, 737 737 struct iio_chan_spec *iio_chan, 738 738 struct pm8xxx_chan_info *ch) 739 739 { 740 - const char *name = np->name; 740 + const char *name = fwnode_get_name(fwnode); 741 741 const struct xoadc_channel *hwchan; 742 - u32 pre_scale_mux, amux_channel; 742 + u32 pre_scale_mux, amux_channel, reg[2]; 743 743 u32 rsv, dec; 744 744 int ret; 745 745 int chid; 746 746 747 - ret = of_property_read_u32_index(np, "reg", 0, &pre_scale_mux); 747 + ret = fwnode_property_read_u32_array(fwnode, "reg", reg, 748 + ARRAY_SIZE(reg)); 748 749 if (ret) { 749 - dev_err(dev, "invalid pre scale/mux number %s\n", name); 750 + dev_err(dev, "invalid pre scale/mux or amux channel number %s\n", 751 + name); 750 752 return ret; 751 753 } 752 - ret = of_property_read_u32_index(np, "reg", 1, &amux_channel); 753 - if (ret) { 754 - dev_err(dev, "invalid amux channel number %s\n", name); 755 - return ret; 756 - } 754 + 755 + pre_scale_mux = reg[0]; 756 + amux_channel = reg[1]; 757 757 758 758 /* Find the right channel setting */ 759 759 chid = 0; ··· 778 778 /* Everyone seems to use default ("type 2") decimation */ 779 779 ch->decimation = VADC_DEF_DECIMATION; 780 780 781 - if (!of_property_read_u32(np, "qcom,ratiometric", &rsv)) { 781 + if (!fwnode_property_read_u32(fwnode, "qcom,ratiometric", &rsv)) { 782 782 ch->calibration = VADC_CALIB_RATIOMETRIC; 783 783 if (rsv > XOADC_RSV_MAX) { 784 784 dev_err(dev, "%s too large RSV value %d\n", name, rsv); ··· 791 791 } 792 792 793 793 /* Optional decimation, if omitted we use the default */ 794 - ret = of_property_read_u32(np, "qcom,decimation", &dec); 794 + ret = fwnode_property_read_u32(fwnode, "qcom,decimation", &dec); 795 795 if (!ret) { 796 796 ret = qcom_vadc_decimation_from_dt(dec); 797 797 if (ret < 0) { ··· 820 820 return 0; 821 821 } 822 822 823 - static int pm8xxx_xoadc_parse_channels(struct pm8xxx_xoadc *adc, 824 - struct device_node *np) 823 + static int pm8xxx_xoadc_parse_channels(struct pm8xxx_xoadc *adc) 825 824 { 826 - struct device_node *child; 825 + struct fwnode_handle *child; 827 826 struct pm8xxx_chan_info *ch; 828 827 int ret; 829 828 int i; 830 829 831 - adc->nchans = of_get_available_child_count(np); 830 + adc->nchans = device_get_child_node_count(adc->dev); 832 831 if (!adc->nchans) { 833 832 dev_err(adc->dev, "no channel children\n"); 834 833 return -ENODEV; ··· 845 846 return -ENOMEM; 846 847 847 848 i = 0; 848 - for_each_available_child_of_node(np, child) { 849 + device_for_each_child_node(adc->dev, child) { 849 850 ch = &adc->chans[i]; 850 851 ret = pm8xxx_xoadc_parse_channel(adc->dev, child, 851 852 adc->variant->channels, 852 853 &adc->iio_chans[i], 853 854 ch); 854 855 if (ret) { 855 - of_node_put(child); 856 + fwnode_handle_put(child); 856 857 return ret; 857 858 } 858 859 i++; ··· 883 884 const struct xoadc_variant *variant; 884 885 struct pm8xxx_xoadc *adc; 885 886 struct iio_dev *indio_dev; 886 - struct device_node *np = pdev->dev.of_node; 887 887 struct regmap *map; 888 888 struct device *dev = &pdev->dev; 889 889 int ret; 890 890 891 - variant = of_device_get_match_data(dev); 891 + variant = device_get_match_data(dev); 892 892 if (!variant) 893 893 return -ENODEV; 894 894 ··· 902 904 init_completion(&adc->complete); 903 905 mutex_init(&adc->lock); 904 906 905 - ret = pm8xxx_xoadc_parse_channels(adc, np); 907 + ret = pm8xxx_xoadc_parse_channels(adc); 906 908 if (ret) 907 909 return ret; 908 910
+40 -33
drivers/iio/adc/qcom-spmi-adc5.c
··· 14 14 #include <linux/log2.h> 15 15 #include <linux/math64.h> 16 16 #include <linux/module.h> 17 - #include <linux/of.h> 18 - #include <linux/of_device.h> 17 + #include <linux/mod_devicetable.h> 19 18 #include <linux/platform_device.h> 19 + #include <linux/property.h> 20 20 #include <linux/regmap.h> 21 21 #include <linux/slab.h> 22 22 ··· 403 403 return IRQ_HANDLED; 404 404 } 405 405 406 - static int adc5_of_xlate(struct iio_dev *indio_dev, 407 - const struct of_phandle_args *iiospec) 406 + static int adc5_fwnode_xlate(struct iio_dev *indio_dev, 407 + const struct fwnode_reference_args *iiospec) 408 408 { 409 409 struct adc5_chip *adc = iio_priv(indio_dev); 410 410 int i; ··· 416 416 return -EINVAL; 417 417 } 418 418 419 - static int adc7_of_xlate(struct iio_dev *indio_dev, 420 - const struct of_phandle_args *iiospec) 419 + static int adc7_fwnode_xlate(struct iio_dev *indio_dev, 420 + const struct fwnode_reference_args *iiospec) 421 421 { 422 422 struct adc5_chip *adc = iio_priv(indio_dev); 423 423 int i, v_channel; ··· 481 481 482 482 static const struct iio_info adc5_info = { 483 483 .read_raw = adc5_read_raw, 484 - .of_xlate = adc5_of_xlate, 484 + .fwnode_xlate = adc5_fwnode_xlate, 485 485 }; 486 486 487 487 static const struct iio_info adc7_info = { 488 488 .read_raw = adc7_read_raw, 489 - .of_xlate = adc7_of_xlate, 489 + .fwnode_xlate = adc7_fwnode_xlate, 490 490 }; 491 491 492 492 struct adc5_channels { ··· 526 526 SCALE_HW_CALIB_DEFAULT) 527 527 [ADC5_VBAT_SNS] = ADC5_CHAN_VOLT("vbat_sns", 1, 528 528 SCALE_HW_CALIB_DEFAULT) 529 + [ADC5_VCOIN] = ADC5_CHAN_VOLT("vcoin", 1, 530 + SCALE_HW_CALIB_DEFAULT) 529 531 [ADC5_DIE_TEMP] = ADC5_CHAN_TEMP("die_temp", 0, 530 532 SCALE_HW_CALIB_PMIC_THERM) 531 533 [ADC5_USB_IN_I] = ADC5_CHAN_VOLT("usb_in_i_uv", 0, ··· 551 549 SCALE_HW_CALIB_THERM_100K_PULLUP) 552 550 [ADC5_AMUX_THM2] = ADC5_CHAN_TEMP("amux_thm2", 0, 553 551 SCALE_HW_CALIB_PM5_SMB_TEMP) 552 + [ADC5_GPIO1_100K_PU] = ADC5_CHAN_TEMP("gpio1_100k_pu", 0, 553 + SCALE_HW_CALIB_THERM_100K_PULLUP) 554 + [ADC5_GPIO3_100K_PU] = ADC5_CHAN_TEMP("gpio3_100k_pu", 0, 555 + SCALE_HW_CALIB_THERM_100K_PULLUP) 556 + [ADC5_GPIO4_100K_PU] = ADC5_CHAN_TEMP("gpio4_100k_pu", 0, 557 + SCALE_HW_CALIB_THERM_100K_PULLUP) 554 558 }; 555 559 556 560 static const struct adc5_channels adc7_chans_pmic[ADC5_MAX_CHANNEL] = { ··· 597 589 SCALE_HW_CALIB_DEFAULT) 598 590 [ADC5_1P25VREF] = ADC5_CHAN_VOLT("vref_1p25", 0, 599 591 SCALE_HW_CALIB_DEFAULT) 592 + [ADC5_VREF_VADC] = ADC5_CHAN_VOLT("vref_vadc", 0, 593 + SCALE_HW_CALIB_DEFAULT) 600 594 [ADC5_VPH_PWR] = ADC5_CHAN_VOLT("vph_pwr", 1, 601 595 SCALE_HW_CALIB_DEFAULT) 602 596 [ADC5_VBAT_SNS] = ADC5_CHAN_VOLT("vbat_sns", 1, ··· 621 611 SCALE_HW_CALIB_THERM_100K_PULLUP) 622 612 }; 623 613 624 - static int adc5_get_dt_channel_data(struct adc5_chip *adc, 614 + static int adc5_get_fw_channel_data(struct adc5_chip *adc, 625 615 struct adc5_channel_prop *prop, 626 - struct device_node *node, 616 + struct fwnode_handle *fwnode, 627 617 const struct adc5_data *data) 628 618 { 629 - const char *name = node->name, *channel_name; 619 + const char *name = fwnode_get_name(fwnode), *channel_name; 630 620 u32 chan, value, varr[2]; 631 621 u32 sid = 0; 632 622 int ret; 633 623 struct device *dev = adc->dev; 634 624 635 - ret = of_property_read_u32(node, "reg", &chan); 625 + ret = fwnode_property_read_u32(fwnode, "reg", &chan); 636 626 if (ret) { 637 627 dev_err(dev, "invalid channel number %s\n", name); 638 628 return ret; ··· 657 647 prop->channel = chan; 658 648 prop->sid = sid; 659 649 660 - channel_name = of_get_property(node, 661 - "label", NULL) ? : node->name; 662 - if (!channel_name) { 663 - dev_err(dev, "Invalid channel name\n"); 664 - return -EINVAL; 665 - } 650 + ret = fwnode_property_read_string(fwnode, "label", &channel_name); 651 + if (ret) 652 + channel_name = name; 653 + 666 654 prop->datasheet_name = channel_name; 667 655 668 - ret = of_property_read_u32(node, "qcom,decimation", &value); 656 + ret = fwnode_property_read_u32(fwnode, "qcom,decimation", &value); 669 657 if (!ret) { 670 658 ret = qcom_adc5_decimation_from_dt(value, data->decimation); 671 659 if (ret < 0) { ··· 676 668 prop->decimation = ADC5_DECIMATION_DEFAULT; 677 669 } 678 670 679 - ret = of_property_read_u32_array(node, "qcom,pre-scaling", varr, 2); 671 + ret = fwnode_property_read_u32_array(fwnode, "qcom,pre-scaling", varr, 2); 680 672 if (!ret) { 681 673 ret = qcom_adc5_prescaling_from_dt(varr[0], varr[1]); 682 674 if (ret < 0) { ··· 690 682 adc->data->adc_chans[prop->channel].prescale_index; 691 683 } 692 684 693 - ret = of_property_read_u32(node, "qcom,hw-settle-time", &value); 685 + ret = fwnode_property_read_u32(fwnode, "qcom,hw-settle-time", &value); 694 686 if (!ret) { 695 687 u8 dig_version[2]; 696 688 ··· 721 713 prop->hw_settle_time = VADC_DEF_HW_SETTLE_TIME; 722 714 } 723 715 724 - ret = of_property_read_u32(node, "qcom,avg-samples", &value); 716 + ret = fwnode_property_read_u32(fwnode, "qcom,avg-samples", &value); 725 717 if (!ret) { 726 718 ret = qcom_adc5_avg_samples_from_dt(value); 727 719 if (ret < 0) { ··· 734 726 prop->avg_samples = VADC_DEF_AVG_SAMPLES; 735 727 } 736 728 737 - if (of_property_read_bool(node, "qcom,ratiometric")) 729 + if (fwnode_property_read_bool(fwnode, "qcom,ratiometric")) 738 730 prop->cal_method = ADC5_RATIOMETRIC_CAL; 739 731 else 740 732 prop->cal_method = ADC5_ABSOLUTE_CAL; ··· 809 801 }; 810 802 MODULE_DEVICE_TABLE(of, adc5_match_table); 811 803 812 - static int adc5_get_dt_data(struct adc5_chip *adc, struct device_node *node) 804 + static int adc5_get_fw_data(struct adc5_chip *adc) 813 805 { 814 806 const struct adc5_channels *adc_chan; 815 807 struct iio_chan_spec *iio_chan; 816 808 struct adc5_channel_prop prop, *chan_props; 817 - struct device_node *child; 809 + struct fwnode_handle *child; 818 810 unsigned int index = 0; 819 811 int ret; 820 812 821 - adc->nchannels = of_get_available_child_count(node); 813 + adc->nchannels = device_get_child_node_count(adc->dev); 822 814 if (!adc->nchannels) 823 815 return -EINVAL; 824 816 ··· 834 826 835 827 chan_props = adc->chan_props; 836 828 iio_chan = adc->iio_chans; 837 - adc->data = of_device_get_match_data(adc->dev); 829 + adc->data = device_get_match_data(adc->dev); 838 830 if (!adc->data) 839 831 adc->data = &adc5_data_pmic; 840 832 841 - for_each_available_child_of_node(node, child) { 842 - ret = adc5_get_dt_channel_data(adc, &prop, child, adc->data); 833 + device_for_each_child_node(adc->dev, child) { 834 + ret = adc5_get_fw_channel_data(adc, &prop, child, adc->data); 843 835 if (ret) { 844 - of_node_put(child); 836 + fwnode_handle_put(child); 845 837 return ret; 846 838 } 847 839 ··· 866 858 867 859 static int adc5_probe(struct platform_device *pdev) 868 860 { 869 - struct device_node *node = pdev->dev.of_node; 870 861 struct device *dev = &pdev->dev; 871 862 struct iio_dev *indio_dev; 872 863 struct adc5_chip *adc; ··· 877 870 if (!regmap) 878 871 return -ENODEV; 879 872 880 - ret = of_property_read_u32(node, "reg", &reg); 873 + ret = device_property_read_u32(dev, "reg", &reg); 881 874 if (ret < 0) 882 875 return ret; 883 876 ··· 893 886 init_completion(&adc->complete); 894 887 mutex_init(&adc->lock); 895 888 896 - ret = adc5_get_dt_data(adc, node); 889 + ret = adc5_get_fw_data(adc); 897 890 if (ret) { 898 891 dev_err(dev, "adc get dt data failed\n"); 899 892 return ret;
+22 -22
drivers/iio/adc/qcom-spmi-vadc.c
··· 13 13 #include <linux/kernel.h> 14 14 #include <linux/math64.h> 15 15 #include <linux/module.h> 16 - #include <linux/of.h> 16 + #include <linux/mod_devicetable.h> 17 17 #include <linux/platform_device.h> 18 + #include <linux/property.h> 18 19 #include <linux/regmap.h> 19 20 #include <linux/slab.h> 20 21 #include <linux/log2.h> ··· 482 481 return ret; 483 482 } 484 483 485 - static int vadc_of_xlate(struct iio_dev *indio_dev, 486 - const struct of_phandle_args *iiospec) 484 + static int vadc_fwnode_xlate(struct iio_dev *indio_dev, 485 + const struct fwnode_reference_args *iiospec) 487 486 { 488 487 struct vadc_priv *vadc = iio_priv(indio_dev); 489 488 unsigned int i; ··· 497 496 498 497 static const struct iio_info vadc_info = { 499 498 .read_raw = vadc_read_raw, 500 - .of_xlate = vadc_of_xlate, 499 + .fwnode_xlate = vadc_fwnode_xlate, 501 500 }; 502 501 503 502 struct vadc_channels { ··· 648 647 VADC_CHAN_NO_SCALE(LR_MUX3_BUF_PU1_PU2_XO_THERM, 0) 649 648 }; 650 649 651 - static int vadc_get_dt_channel_data(struct device *dev, 650 + static int vadc_get_fw_channel_data(struct device *dev, 652 651 struct vadc_channel_prop *prop, 653 - struct device_node *node) 652 + struct fwnode_handle *fwnode) 654 653 { 655 - const char *name = node->name; 654 + const char *name = fwnode_get_name(fwnode); 656 655 u32 chan, value, varr[2]; 657 656 int ret; 658 657 659 - ret = of_property_read_u32(node, "reg", &chan); 658 + ret = fwnode_property_read_u32(fwnode, "reg", &chan); 660 659 if (ret) { 661 660 dev_err(dev, "invalid channel number %s\n", name); 662 661 return ret; ··· 670 669 /* the channel has DT description */ 671 670 prop->channel = chan; 672 671 673 - ret = of_property_read_u32(node, "qcom,decimation", &value); 672 + ret = fwnode_property_read_u32(fwnode, "qcom,decimation", &value); 674 673 if (!ret) { 675 674 ret = qcom_vadc_decimation_from_dt(value); 676 675 if (ret < 0) { ··· 683 682 prop->decimation = VADC_DEF_DECIMATION; 684 683 } 685 684 686 - ret = of_property_read_u32_array(node, "qcom,pre-scaling", varr, 2); 685 + ret = fwnode_property_read_u32_array(fwnode, "qcom,pre-scaling", varr, 2); 687 686 if (!ret) { 688 687 ret = vadc_prescaling_from_dt(varr[0], varr[1]); 689 688 if (ret < 0) { ··· 696 695 prop->prescale = vadc_chans[prop->channel].prescale_index; 697 696 } 698 697 699 - ret = of_property_read_u32(node, "qcom,hw-settle-time", &value); 698 + ret = fwnode_property_read_u32(fwnode, "qcom,hw-settle-time", &value); 700 699 if (!ret) { 701 700 ret = vadc_hw_settle_time_from_dt(value); 702 701 if (ret < 0) { ··· 709 708 prop->hw_settle_time = VADC_DEF_HW_SETTLE_TIME; 710 709 } 711 710 712 - ret = of_property_read_u32(node, "qcom,avg-samples", &value); 711 + ret = fwnode_property_read_u32(fwnode, "qcom,avg-samples", &value); 713 712 if (!ret) { 714 713 ret = vadc_avg_samples_from_dt(value); 715 714 if (ret < 0) { ··· 722 721 prop->avg_samples = VADC_DEF_AVG_SAMPLES; 723 722 } 724 723 725 - if (of_property_read_bool(node, "qcom,ratiometric")) 724 + if (fwnode_property_read_bool(fwnode, "qcom,ratiometric")) 726 725 prop->calibration = VADC_CALIB_RATIOMETRIC; 727 726 else 728 727 prop->calibration = VADC_CALIB_ABSOLUTE; ··· 732 731 return 0; 733 732 } 734 733 735 - static int vadc_get_dt_data(struct vadc_priv *vadc, struct device_node *node) 734 + static int vadc_get_fw_data(struct vadc_priv *vadc) 736 735 { 737 736 const struct vadc_channels *vadc_chan; 738 737 struct iio_chan_spec *iio_chan; 739 738 struct vadc_channel_prop prop; 740 - struct device_node *child; 739 + struct fwnode_handle *child; 741 740 unsigned int index = 0; 742 741 int ret; 743 742 744 - vadc->nchannels = of_get_available_child_count(node); 743 + vadc->nchannels = device_get_child_node_count(vadc->dev); 745 744 if (!vadc->nchannels) 746 745 return -EINVAL; 747 746 ··· 757 756 758 757 iio_chan = vadc->iio_chans; 759 758 760 - for_each_available_child_of_node(node, child) { 761 - ret = vadc_get_dt_channel_data(vadc->dev, &prop, child); 759 + device_for_each_child_node(vadc->dev, child) { 760 + ret = vadc_get_fw_channel_data(vadc->dev, &prop, child); 762 761 if (ret) { 763 - of_node_put(child); 762 + fwnode_handle_put(child); 764 763 return ret; 765 764 } 766 765 ··· 849 848 850 849 static int vadc_probe(struct platform_device *pdev) 851 850 { 852 - struct device_node *node = pdev->dev.of_node; 853 851 struct device *dev = &pdev->dev; 854 852 struct iio_dev *indio_dev; 855 853 struct vadc_priv *vadc; ··· 860 860 if (!regmap) 861 861 return -ENODEV; 862 862 863 - ret = of_property_read_u32(node, "reg", &reg); 863 + ret = device_property_read_u32(dev, "reg", &reg); 864 864 if (ret < 0) 865 865 return ret; 866 866 ··· 880 880 if (ret) 881 881 return ret; 882 882 883 - ret = vadc_get_dt_data(vadc, node); 883 + ret = vadc_get_fw_data(vadc); 884 884 if (ret) 885 885 return ret; 886 886
+661
drivers/iio/adc/rtq6056.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2022 Richtek Technology Corp. 4 + * 5 + * ChiYuan Huang <cy_huang@richtek.com> 6 + */ 7 + 8 + #include <linux/bitops.h> 9 + #include <linux/delay.h> 10 + #include <linux/i2c.h> 11 + #include <linux/kernel.h> 12 + #include <linux/mod_devicetable.h> 13 + #include <linux/module.h> 14 + #include <linux/pm_runtime.h> 15 + #include <linux/property.h> 16 + #include <linux/regmap.h> 17 + #include <linux/sysfs.h> 18 + #include <linux/types.h> 19 + #include <linux/util_macros.h> 20 + 21 + #include <linux/iio/buffer.h> 22 + #include <linux/iio/iio.h> 23 + #include <linux/iio/sysfs.h> 24 + #include <linux/iio/trigger_consumer.h> 25 + #include <linux/iio/triggered_buffer.h> 26 + 27 + #define RTQ6056_REG_CONFIG 0x00 28 + #define RTQ6056_REG_SHUNTVOLT 0x01 29 + #define RTQ6056_REG_BUSVOLT 0x02 30 + #define RTQ6056_REG_POWER 0x03 31 + #define RTQ6056_REG_CURRENT 0x04 32 + #define RTQ6056_REG_CALIBRATION 0x05 33 + #define RTQ6056_REG_MASKENABLE 0x06 34 + #define RTQ6056_REG_ALERTLIMIT 0x07 35 + #define RTQ6056_REG_MANUFACTID 0xFE 36 + #define RTQ6056_REG_DIEID 0xFF 37 + 38 + #define RTQ6056_VENDOR_ID 0x1214 39 + #define RTQ6056_DEFAULT_CONFIG 0x4127 40 + #define RTQ6056_CONT_ALLON 7 41 + 42 + enum { 43 + RTQ6056_CH_VSHUNT = 0, 44 + RTQ6056_CH_VBUS, 45 + RTQ6056_CH_POWER, 46 + RTQ6056_CH_CURRENT, 47 + RTQ6056_MAX_CHANNEL 48 + }; 49 + 50 + enum { 51 + F_OPMODE = 0, 52 + F_VSHUNTCT, 53 + F_VBUSCT, 54 + F_AVG, 55 + F_RESET, 56 + F_MAX_FIELDS 57 + }; 58 + 59 + struct rtq6056_priv { 60 + struct device *dev; 61 + struct regmap *regmap; 62 + struct regmap_field *rm_fields[F_MAX_FIELDS]; 63 + u32 shunt_resistor_uohm; 64 + int vshuntct_us; 65 + int vbusct_us; 66 + int avg_sample; 67 + }; 68 + 69 + static const struct reg_field rtq6056_reg_fields[F_MAX_FIELDS] = { 70 + [F_OPMODE] = REG_FIELD(RTQ6056_REG_CONFIG, 0, 2), 71 + [F_VSHUNTCT] = REG_FIELD(RTQ6056_REG_CONFIG, 3, 5), 72 + [F_VBUSCT] = REG_FIELD(RTQ6056_REG_CONFIG, 6, 8), 73 + [F_AVG] = REG_FIELD(RTQ6056_REG_CONFIG, 9, 11), 74 + [F_RESET] = REG_FIELD(RTQ6056_REG_CONFIG, 15, 15), 75 + }; 76 + 77 + static const struct iio_chan_spec rtq6056_channels[RTQ6056_MAX_CHANNEL + 1] = { 78 + { 79 + .type = IIO_VOLTAGE, 80 + .indexed = 1, 81 + .channel = 0, 82 + .address = RTQ6056_REG_SHUNTVOLT, 83 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 84 + BIT(IIO_CHAN_INFO_SCALE) | 85 + BIT(IIO_CHAN_INFO_SAMP_FREQ), 86 + .info_mask_separate_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 87 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 88 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 89 + .scan_index = 0, 90 + .scan_type = { 91 + .sign = 's', 92 + .realbits = 16, 93 + .storagebits = 16, 94 + .endianness = IIO_CPU, 95 + }, 96 + }, 97 + { 98 + .type = IIO_VOLTAGE, 99 + .indexed = 1, 100 + .channel = 1, 101 + .address = RTQ6056_REG_BUSVOLT, 102 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 103 + BIT(IIO_CHAN_INFO_SCALE) | 104 + BIT(IIO_CHAN_INFO_SAMP_FREQ), 105 + .info_mask_separate_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 106 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 107 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 108 + .scan_index = 1, 109 + .scan_type = { 110 + .sign = 'u', 111 + .realbits = 16, 112 + .storagebits = 16, 113 + .endianness = IIO_CPU, 114 + }, 115 + }, 116 + { 117 + .type = IIO_POWER, 118 + .indexed = 1, 119 + .channel = 2, 120 + .address = RTQ6056_REG_POWER, 121 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 122 + BIT(IIO_CHAN_INFO_SCALE) | 123 + BIT(IIO_CHAN_INFO_SAMP_FREQ), 124 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 125 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 126 + .scan_index = 2, 127 + .scan_type = { 128 + .sign = 'u', 129 + .realbits = 16, 130 + .storagebits = 16, 131 + .endianness = IIO_CPU, 132 + }, 133 + }, 134 + { 135 + .type = IIO_CURRENT, 136 + .indexed = 1, 137 + .channel = 3, 138 + .address = RTQ6056_REG_CURRENT, 139 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 140 + BIT(IIO_CHAN_INFO_SAMP_FREQ), 141 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 142 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 143 + .scan_index = 3, 144 + .scan_type = { 145 + .sign = 's', 146 + .realbits = 16, 147 + .storagebits = 16, 148 + .endianness = IIO_CPU, 149 + }, 150 + }, 151 + IIO_CHAN_SOFT_TIMESTAMP(RTQ6056_MAX_CHANNEL), 152 + }; 153 + 154 + static int rtq6056_adc_read_channel(struct rtq6056_priv *priv, 155 + struct iio_chan_spec const *ch, 156 + int *val) 157 + { 158 + struct device *dev = priv->dev; 159 + unsigned int addr = ch->address; 160 + unsigned int regval; 161 + int ret; 162 + 163 + pm_runtime_get_sync(dev); 164 + ret = regmap_read(priv->regmap, addr, &regval); 165 + pm_runtime_mark_last_busy(dev); 166 + pm_runtime_put(dev); 167 + if (ret) 168 + return ret; 169 + 170 + /* Power and VBUS is unsigned 16-bit, others are signed 16-bit */ 171 + if (addr == RTQ6056_REG_BUSVOLT || addr == RTQ6056_REG_POWER) 172 + *val = regval; 173 + else 174 + *val = sign_extend32(regval, 16); 175 + 176 + return IIO_VAL_INT; 177 + } 178 + 179 + static int rtq6056_adc_read_scale(struct iio_chan_spec const *ch, int *val, 180 + int *val2) 181 + { 182 + switch (ch->address) { 183 + case RTQ6056_REG_SHUNTVOLT: 184 + /* VSHUNT lsb 2.5uV */ 185 + *val = 2500; 186 + *val2 = 1000000; 187 + return IIO_VAL_FRACTIONAL; 188 + case RTQ6056_REG_BUSVOLT: 189 + /* VBUS lsb 1.25mV */ 190 + *val = 1250; 191 + *val2 = 1000; 192 + return IIO_VAL_FRACTIONAL; 193 + case RTQ6056_REG_POWER: 194 + /* Power lsb 25mW */ 195 + *val = 25; 196 + return IIO_VAL_INT; 197 + default: 198 + return -EINVAL; 199 + } 200 + } 201 + 202 + /* 203 + * Sample frequency for channel VSHUNT and VBUS. The indices correspond 204 + * with the bit value expected by the chip. And it can be found at 205 + * https://www.richtek.com/assets/product_file/RTQ6056/DSQ6056-00.pdf 206 + */ 207 + static const int rtq6056_samp_freq_list[] = { 208 + 7194, 4926, 3717, 1904, 964, 485, 243, 122, 209 + }; 210 + 211 + static int rtq6056_adc_set_samp_freq(struct rtq6056_priv *priv, 212 + struct iio_chan_spec const *ch, int val) 213 + { 214 + struct regmap_field *rm_field; 215 + unsigned int selector; 216 + int *ct, ret; 217 + 218 + if (val > 7194 || val < 122) 219 + return -EINVAL; 220 + 221 + if (ch->address == RTQ6056_REG_SHUNTVOLT) { 222 + rm_field = priv->rm_fields[F_VSHUNTCT]; 223 + ct = &priv->vshuntct_us; 224 + } else if (ch->address == RTQ6056_REG_BUSVOLT) { 225 + rm_field = priv->rm_fields[F_VBUSCT]; 226 + ct = &priv->vbusct_us; 227 + } else 228 + return -EINVAL; 229 + 230 + selector = find_closest_descending(val, rtq6056_samp_freq_list, 231 + ARRAY_SIZE(rtq6056_samp_freq_list)); 232 + 233 + ret = regmap_field_write(rm_field, selector); 234 + if (ret) 235 + return ret; 236 + 237 + *ct = 1000000 / rtq6056_samp_freq_list[selector]; 238 + 239 + return 0; 240 + } 241 + 242 + /* 243 + * Available averaging rate for rtq6056. The indices correspond with the bit 244 + * value expected by the chip. And it can be found at 245 + * https://www.richtek.com/assets/product_file/RTQ6056/DSQ6056-00.pdf 246 + */ 247 + static const int rtq6056_avg_sample_list[] = { 248 + 1, 4, 16, 64, 128, 256, 512, 1024, 249 + }; 250 + 251 + static int rtq6056_adc_set_average(struct rtq6056_priv *priv, int val) 252 + { 253 + unsigned int selector; 254 + int ret; 255 + 256 + if (val > 1024 || val < 1) 257 + return -EINVAL; 258 + 259 + selector = find_closest(val, rtq6056_avg_sample_list, 260 + ARRAY_SIZE(rtq6056_avg_sample_list)); 261 + 262 + ret = regmap_field_write(priv->rm_fields[F_AVG], selector); 263 + if (ret) 264 + return ret; 265 + 266 + priv->avg_sample = rtq6056_avg_sample_list[selector]; 267 + 268 + return 0; 269 + } 270 + 271 + static int rtq6056_adc_get_sample_freq(struct rtq6056_priv *priv, 272 + struct iio_chan_spec const *ch, int *val) 273 + { 274 + int sample_time; 275 + 276 + if (ch->address == RTQ6056_REG_SHUNTVOLT) 277 + sample_time = priv->vshuntct_us; 278 + else if (ch->address == RTQ6056_REG_BUSVOLT) 279 + sample_time = priv->vbusct_us; 280 + else { 281 + sample_time = priv->vshuntct_us + priv->vbusct_us; 282 + sample_time *= priv->avg_sample; 283 + } 284 + 285 + *val = 1000000 / sample_time; 286 + 287 + return IIO_VAL_INT; 288 + } 289 + 290 + static int rtq6056_adc_read_raw(struct iio_dev *indio_dev, 291 + struct iio_chan_spec const *chan, int *val, 292 + int *val2, long mask) 293 + { 294 + struct rtq6056_priv *priv = iio_priv(indio_dev); 295 + 296 + switch (mask) { 297 + case IIO_CHAN_INFO_RAW: 298 + return rtq6056_adc_read_channel(priv, chan, val); 299 + case IIO_CHAN_INFO_SCALE: 300 + return rtq6056_adc_read_scale(chan, val, val2); 301 + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 302 + *val = priv->avg_sample; 303 + return IIO_VAL_INT; 304 + case IIO_CHAN_INFO_SAMP_FREQ: 305 + return rtq6056_adc_get_sample_freq(priv, chan, val); 306 + default: 307 + return -EINVAL; 308 + } 309 + } 310 + 311 + static int rtq6056_adc_read_avail(struct iio_dev *indio_dev, 312 + struct iio_chan_spec const *chan, 313 + const int **vals, int *type, int *length, 314 + long mask) 315 + { 316 + switch (mask) { 317 + case IIO_CHAN_INFO_SAMP_FREQ: 318 + *vals = rtq6056_samp_freq_list; 319 + *type = IIO_VAL_INT; 320 + *length = ARRAY_SIZE(rtq6056_samp_freq_list); 321 + return IIO_AVAIL_LIST; 322 + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 323 + *vals = rtq6056_avg_sample_list; 324 + *type = IIO_VAL_INT; 325 + *length = ARRAY_SIZE(rtq6056_avg_sample_list); 326 + return IIO_AVAIL_LIST; 327 + default: 328 + return -EINVAL; 329 + } 330 + } 331 + 332 + static int rtq6056_adc_write_raw(struct iio_dev *indio_dev, 333 + struct iio_chan_spec const *chan, int val, 334 + int val2, long mask) 335 + { 336 + struct rtq6056_priv *priv = iio_priv(indio_dev); 337 + int ret; 338 + 339 + ret = iio_device_claim_direct_mode(indio_dev); 340 + if (ret) 341 + return ret; 342 + 343 + switch (mask) { 344 + case IIO_CHAN_INFO_SAMP_FREQ: 345 + ret = rtq6056_adc_set_samp_freq(priv, chan, val); 346 + break; 347 + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 348 + ret = rtq6056_adc_set_average(priv, val); 349 + break; 350 + default: 351 + ret = -EINVAL; 352 + break; 353 + } 354 + 355 + iio_device_release_direct_mode(indio_dev); 356 + 357 + return ret; 358 + } 359 + 360 + static const char *rtq6056_channel_labels[RTQ6056_MAX_CHANNEL] = { 361 + [RTQ6056_CH_VSHUNT] = "Vshunt", 362 + [RTQ6056_CH_VBUS] = "Vbus", 363 + [RTQ6056_CH_POWER] = "Power", 364 + [RTQ6056_CH_CURRENT] = "Current", 365 + }; 366 + 367 + static int rtq6056_adc_read_label(struct iio_dev *indio_dev, 368 + struct iio_chan_spec const *chan, 369 + char *label) 370 + { 371 + return sysfs_emit(label, "%s\n", rtq6056_channel_labels[chan->channel]); 372 + } 373 + 374 + static int rtq6056_set_shunt_resistor(struct rtq6056_priv *priv, 375 + int resistor_uohm) 376 + { 377 + unsigned int calib_val; 378 + int ret; 379 + 380 + if (resistor_uohm <= 0) { 381 + dev_err(priv->dev, "Invalid resistor [%d]\n", resistor_uohm); 382 + return -EINVAL; 383 + } 384 + 385 + /* calibration = 5120000 / (Rshunt (uOhm) * current lsb (1mA)) */ 386 + calib_val = 5120000 / resistor_uohm; 387 + ret = regmap_write(priv->regmap, RTQ6056_REG_CALIBRATION, calib_val); 388 + if (ret) 389 + return ret; 390 + 391 + priv->shunt_resistor_uohm = resistor_uohm; 392 + 393 + return 0; 394 + } 395 + 396 + static ssize_t shunt_resistor_show(struct device *dev, 397 + struct device_attribute *attr, char *buf) 398 + { 399 + struct rtq6056_priv *priv = iio_priv(dev_to_iio_dev(dev)); 400 + int vals[2] = { priv->shunt_resistor_uohm, 1000000 }; 401 + 402 + return iio_format_value(buf, IIO_VAL_FRACTIONAL, 1, vals); 403 + } 404 + 405 + static ssize_t shunt_resistor_store(struct device *dev, 406 + struct device_attribute *attr, 407 + const char *buf, size_t len) 408 + { 409 + struct iio_dev *indio_dev = dev_to_iio_dev(dev); 410 + struct rtq6056_priv *priv = iio_priv(indio_dev); 411 + int val, val_fract, ret; 412 + 413 + ret = iio_device_claim_direct_mode(indio_dev); 414 + if (ret) 415 + return ret; 416 + 417 + ret = iio_str_to_fixpoint(buf, 100000, &val, &val_fract); 418 + if (ret) 419 + goto out_store; 420 + 421 + ret = rtq6056_set_shunt_resistor(priv, val * 1000000 + val_fract); 422 + 423 + out_store: 424 + iio_device_release_direct_mode(indio_dev); 425 + 426 + return ret ?: len; 427 + } 428 + 429 + static IIO_DEVICE_ATTR_RW(shunt_resistor, 0); 430 + 431 + static struct attribute *rtq6056_attributes[] = { 432 + &iio_dev_attr_shunt_resistor.dev_attr.attr, 433 + NULL 434 + }; 435 + 436 + static const struct attribute_group rtq6056_attribute_group = { 437 + .attrs = rtq6056_attributes, 438 + }; 439 + 440 + static const struct iio_info rtq6056_info = { 441 + .attrs = &rtq6056_attribute_group, 442 + .read_raw = rtq6056_adc_read_raw, 443 + .read_avail = rtq6056_adc_read_avail, 444 + .write_raw = rtq6056_adc_write_raw, 445 + .read_label = rtq6056_adc_read_label, 446 + }; 447 + 448 + static irqreturn_t rtq6056_buffer_trigger_handler(int irq, void *p) 449 + { 450 + struct iio_poll_func *pf = p; 451 + struct iio_dev *indio_dev = pf->indio_dev; 452 + struct rtq6056_priv *priv = iio_priv(indio_dev); 453 + struct device *dev = priv->dev; 454 + struct { 455 + u16 vals[RTQ6056_MAX_CHANNEL]; 456 + s64 timestamp __aligned(8); 457 + } data; 458 + unsigned int raw; 459 + int i = 0, bit, ret; 460 + 461 + memset(&data, 0, sizeof(data)); 462 + 463 + pm_runtime_get_sync(dev); 464 + 465 + for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev->masklength) { 466 + unsigned int addr = rtq6056_channels[bit].address; 467 + 468 + ret = regmap_read(priv->regmap, addr, &raw); 469 + if (ret) 470 + goto out; 471 + 472 + data.vals[i++] = raw; 473 + } 474 + 475 + iio_push_to_buffers_with_timestamp(indio_dev, &data, iio_get_time_ns(indio_dev)); 476 + 477 + out: 478 + pm_runtime_mark_last_busy(dev); 479 + pm_runtime_put(dev); 480 + 481 + iio_trigger_notify_done(indio_dev->trig); 482 + 483 + return IRQ_HANDLED; 484 + } 485 + 486 + static void rtq6056_enter_shutdown_state(void *dev) 487 + { 488 + struct rtq6056_priv *priv = dev_get_drvdata(dev); 489 + 490 + /* Enter shutdown state */ 491 + regmap_field_write(priv->rm_fields[F_OPMODE], 0); 492 + } 493 + 494 + static bool rtq6056_is_readable_reg(struct device *dev, unsigned int reg) 495 + { 496 + switch (reg) { 497 + case RTQ6056_REG_CONFIG ... RTQ6056_REG_ALERTLIMIT: 498 + case RTQ6056_REG_MANUFACTID ... RTQ6056_REG_DIEID: 499 + return true; 500 + default: 501 + return false; 502 + } 503 + } 504 + 505 + static bool rtq6056_is_writeable_reg(struct device *dev, unsigned int reg) 506 + { 507 + switch (reg) { 508 + case RTQ6056_REG_CONFIG: 509 + case RTQ6056_REG_CALIBRATION ... RTQ6056_REG_ALERTLIMIT: 510 + return true; 511 + default: 512 + return false; 513 + } 514 + } 515 + 516 + static const struct regmap_config rtq6056_regmap_config = { 517 + .reg_bits = 8, 518 + .val_bits = 16, 519 + .val_format_endian = REGMAP_ENDIAN_BIG, 520 + .max_register = RTQ6056_REG_DIEID, 521 + .readable_reg = rtq6056_is_readable_reg, 522 + .writeable_reg = rtq6056_is_writeable_reg, 523 + }; 524 + 525 + static int rtq6056_probe(struct i2c_client *i2c) 526 + { 527 + struct iio_dev *indio_dev; 528 + struct rtq6056_priv *priv; 529 + struct device *dev = &i2c->dev; 530 + struct regmap *regmap; 531 + unsigned int vendor_id, shunt_resistor_uohm; 532 + int ret; 533 + 534 + if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 535 + return -EOPNOTSUPP; 536 + 537 + indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); 538 + if (!indio_dev) 539 + return -ENOMEM; 540 + 541 + priv = iio_priv(indio_dev); 542 + priv->dev = dev; 543 + priv->vshuntct_us = priv->vbusct_us = 1037; 544 + priv->avg_sample = 1; 545 + i2c_set_clientdata(i2c, priv); 546 + 547 + regmap = devm_regmap_init_i2c(i2c, &rtq6056_regmap_config); 548 + if (IS_ERR(regmap)) 549 + return dev_err_probe(dev, PTR_ERR(regmap), 550 + "Failed to init regmap\n"); 551 + 552 + priv->regmap = regmap; 553 + 554 + ret = regmap_read(regmap, RTQ6056_REG_MANUFACTID, &vendor_id); 555 + if (ret) 556 + return dev_err_probe(dev, ret, 557 + "Failed to get manufacturer info\n"); 558 + 559 + if (vendor_id != RTQ6056_VENDOR_ID) 560 + return dev_err_probe(dev, -ENODEV, 561 + "Invalid vendor id 0x%04x\n", vendor_id); 562 + 563 + ret = devm_regmap_field_bulk_alloc(dev, regmap, priv->rm_fields, 564 + rtq6056_reg_fields, F_MAX_FIELDS); 565 + if (ret) 566 + return dev_err_probe(dev, ret, "Failed to init regmap field\n"); 567 + 568 + /* 569 + * By default, configure average sample as 1, bus and shunt conversion 570 + * time as 1037 microsecond, and operating mode to all on. 571 + */ 572 + ret = regmap_write(regmap, RTQ6056_REG_CONFIG, RTQ6056_DEFAULT_CONFIG); 573 + if (ret) 574 + return dev_err_probe(dev, ret, 575 + "Failed to enable continuous sensing\n"); 576 + 577 + ret = devm_add_action_or_reset(dev, rtq6056_enter_shutdown_state, dev); 578 + if (ret) 579 + return ret; 580 + 581 + pm_runtime_set_autosuspend_delay(dev, MSEC_PER_SEC); 582 + pm_runtime_use_autosuspend(dev); 583 + pm_runtime_set_active(dev); 584 + pm_runtime_mark_last_busy(dev); 585 + ret = devm_pm_runtime_enable(dev); 586 + if (ret) 587 + return dev_err_probe(dev, ret, "Failed to enable pm_runtime\n"); 588 + 589 + /* By default, use 2000 micro-Ohm resistor */ 590 + shunt_resistor_uohm = 2000; 591 + device_property_read_u32(dev, "shunt-resistor-micro-ohms", 592 + &shunt_resistor_uohm); 593 + 594 + ret = rtq6056_set_shunt_resistor(priv, shunt_resistor_uohm); 595 + if (ret) 596 + return dev_err_probe(dev, ret, 597 + "Failed to init shunt resistor\n"); 598 + 599 + indio_dev->name = "rtq6056"; 600 + indio_dev->modes = INDIO_DIRECT_MODE; 601 + indio_dev->channels = rtq6056_channels; 602 + indio_dev->num_channels = ARRAY_SIZE(rtq6056_channels); 603 + indio_dev->info = &rtq6056_info; 604 + 605 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, 606 + rtq6056_buffer_trigger_handler, 607 + NULL); 608 + if (ret) 609 + return dev_err_probe(dev, ret, 610 + "Failed to allocate iio trigger buffer\n"); 611 + 612 + return devm_iio_device_register(dev, indio_dev); 613 + } 614 + 615 + static int rtq6056_runtime_suspend(struct device *dev) 616 + { 617 + struct rtq6056_priv *priv = dev_get_drvdata(dev); 618 + 619 + /* Configure to shutdown mode */ 620 + return regmap_field_write(priv->rm_fields[F_OPMODE], 0); 621 + } 622 + 623 + static int rtq6056_runtime_resume(struct device *dev) 624 + { 625 + struct rtq6056_priv *priv = dev_get_drvdata(dev); 626 + int sample_rdy_time_us, ret; 627 + 628 + ret = regmap_field_write(priv->rm_fields[F_OPMODE], RTQ6056_CONT_ALLON); 629 + if (ret) 630 + return ret; 631 + 632 + sample_rdy_time_us = priv->vbusct_us + priv->vshuntct_us; 633 + sample_rdy_time_us *= priv->avg_sample; 634 + 635 + usleep_range(sample_rdy_time_us, sample_rdy_time_us + 100); 636 + 637 + return 0; 638 + } 639 + 640 + static DEFINE_RUNTIME_DEV_PM_OPS(rtq6056_pm_ops, rtq6056_runtime_suspend, 641 + rtq6056_runtime_resume, NULL); 642 + 643 + static const struct of_device_id rtq6056_device_match[] = { 644 + { .compatible = "richtek,rtq6056" }, 645 + {} 646 + }; 647 + MODULE_DEVICE_TABLE(of, rtq6056_device_match); 648 + 649 + static struct i2c_driver rtq6056_driver = { 650 + .driver = { 651 + .name = "rtq6056", 652 + .of_match_table = rtq6056_device_match, 653 + .pm = pm_ptr(&rtq6056_pm_ops), 654 + }, 655 + .probe_new = rtq6056_probe, 656 + }; 657 + module_i2c_driver(rtq6056_driver); 658 + 659 + MODULE_AUTHOR("ChiYuan Huang <cy_huang@richtek.com>"); 660 + MODULE_DESCRIPTION("Richtek RTQ6056 Driver"); 661 + MODULE_LICENSE("GPL v2");
+73 -55
drivers/iio/adc/stm32-adc.c
··· 21 21 #include <linux/io.h> 22 22 #include <linux/iopoll.h> 23 23 #include <linux/module.h> 24 + #include <linux/mod_devicetable.h> 24 25 #include <linux/nvmem-consumer.h> 25 26 #include <linux/platform_device.h> 26 27 #include <linux/pm_runtime.h> 27 - #include <linux/of.h> 28 - #include <linux/of_device.h> 28 + #include <linux/property.h> 29 29 30 30 #include "stm32-adc-core.h" 31 31 ··· 241 241 * @chan_name: channel name array 242 242 * @num_diff: number of differential channels 243 243 * @int_ch: internal channel indexes array 244 + * @nsmps: number of channels with optional sample time 244 245 */ 245 246 struct stm32_adc { 246 247 struct stm32_adc_common *common; ··· 268 267 char chan_name[STM32_ADC_CH_MAX][STM32_ADC_CH_SZ]; 269 268 u32 num_diff; 270 269 int int_ch[STM32_ADC_INT_CH_NB]; 270 + int nsmps; 271 271 }; 272 272 273 273 struct stm32_adc_diff_channel { ··· 1522 1520 return ret; 1523 1521 } 1524 1522 1525 - static int stm32_adc_of_xlate(struct iio_dev *indio_dev, 1526 - const struct of_phandle_args *iiospec) 1523 + static int stm32_adc_fwnode_xlate(struct iio_dev *indio_dev, 1524 + const struct fwnode_reference_args *iiospec) 1527 1525 { 1528 1526 int i; 1529 1527 ··· 1577 1575 .hwfifo_set_watermark = stm32_adc_set_watermark, 1578 1576 .update_scan_mode = stm32_adc_update_scan_mode, 1579 1577 .debugfs_reg_access = stm32_adc_debugfs_reg_access, 1580 - .of_xlate = stm32_adc_of_xlate, 1578 + .fwnode_xlate = stm32_adc_fwnode_xlate, 1581 1579 }; 1582 1580 1583 1581 static unsigned int stm32_adc_dma_residue(struct stm32_adc *adc) ··· 1774 1772 {}, 1775 1773 }; 1776 1774 1777 - static int stm32_adc_of_get_resolution(struct iio_dev *indio_dev) 1775 + static int stm32_adc_fw_get_resolution(struct iio_dev *indio_dev) 1778 1776 { 1779 - struct device_node *node = indio_dev->dev.of_node; 1777 + struct device *dev = &indio_dev->dev; 1780 1778 struct stm32_adc *adc = iio_priv(indio_dev); 1781 1779 unsigned int i; 1782 1780 u32 res; 1783 1781 1784 - if (of_property_read_u32(node, "assigned-resolution-bits", &res)) 1782 + if (device_property_read_u32(dev, "assigned-resolution-bits", &res)) 1785 1783 res = adc->cfg->adc_info->resolutions[0]; 1786 1784 1787 1785 for (i = 0; i < adc->cfg->adc_info->num_res; i++) ··· 1865 1863 1866 1864 static int stm32_adc_get_legacy_chan_count(struct iio_dev *indio_dev, struct stm32_adc *adc) 1867 1865 { 1868 - struct device_node *node = indio_dev->dev.of_node; 1866 + struct device *dev = &indio_dev->dev; 1869 1867 const struct stm32_adc_info *adc_info = adc->cfg->adc_info; 1870 1868 int num_channels = 0, ret; 1871 1869 1872 - ret = of_property_count_u32_elems(node, "st,adc-channels"); 1870 + ret = device_property_count_u32(dev, "st,adc-channels"); 1873 1871 if (ret > adc_info->max_channels) { 1874 1872 dev_err(&indio_dev->dev, "Bad st,adc-channels?\n"); 1875 1873 return -EINVAL; ··· 1877 1875 num_channels += ret; 1878 1876 } 1879 1877 1880 - ret = of_property_count_elems_of_size(node, "st,adc-diff-channels", 1881 - sizeof(struct stm32_adc_diff_channel)); 1878 + /* 1879 + * each st,adc-diff-channels is a group of 2 u32 so we divide @ret 1880 + * to get the *real* number of channels. 1881 + */ 1882 + ret = device_property_count_u32(dev, "st,adc-diff-channels"); 1883 + if (ret < 0) 1884 + return ret; 1885 + 1886 + ret /= (int)(sizeof(struct stm32_adc_diff_channel) / sizeof(u32)); 1882 1887 if (ret > adc_info->max_channels) { 1883 1888 dev_err(&indio_dev->dev, "Bad st,adc-diff-channels?\n"); 1884 1889 return -EINVAL; ··· 1895 1886 } 1896 1887 1897 1888 /* Optional sample time is provided either for each, or all channels */ 1898 - ret = of_property_count_u32_elems(node, "st,min-sample-time-nsecs"); 1899 - if (ret > 1 && ret != num_channels) { 1889 + adc->nsmps = device_property_count_u32(dev, "st,min-sample-time-nsecs"); 1890 + if (adc->nsmps > 1 && adc->nsmps != num_channels) { 1900 1891 dev_err(&indio_dev->dev, "Invalid st,min-sample-time-nsecs\n"); 1901 1892 return -EINVAL; 1902 1893 } ··· 1906 1897 1907 1898 static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev, 1908 1899 struct stm32_adc *adc, 1909 - struct iio_chan_spec *channels) 1900 + struct iio_chan_spec *channels, 1901 + int nchans) 1910 1902 { 1911 - struct device_node *node = indio_dev->dev.of_node; 1912 1903 const struct stm32_adc_info *adc_info = adc->cfg->adc_info; 1913 1904 struct stm32_adc_diff_channel diff[STM32_ADC_CH_MAX]; 1905 + struct device *dev = &indio_dev->dev; 1914 1906 u32 num_diff = adc->num_diff; 1915 1907 int size = num_diff * sizeof(*diff) / sizeof(u32); 1916 - int scan_index = 0, val, ret, i; 1917 - struct property *prop; 1918 - const __be32 *cur; 1919 - u32 smp = 0; 1908 + int scan_index = 0, ret, i, c; 1909 + u32 smp = 0, smps[STM32_ADC_CH_MAX], chans[STM32_ADC_CH_MAX]; 1920 1910 1921 1911 if (num_diff) { 1922 - ret = of_property_read_u32_array(node, "st,adc-diff-channels", 1923 - (u32 *)diff, size); 1912 + ret = device_property_read_u32_array(dev, "st,adc-diff-channels", 1913 + (u32 *)diff, size); 1924 1914 if (ret) { 1925 1915 dev_err(&indio_dev->dev, "Failed to get diff channels %d\n", ret); 1926 1916 return ret; ··· 1940 1932 } 1941 1933 } 1942 1934 1943 - of_property_for_each_u32(node, "st,adc-channels", prop, cur, val) { 1944 - if (val >= adc_info->max_channels) { 1945 - dev_err(&indio_dev->dev, "Invalid channel %d\n", val); 1935 + ret = device_property_read_u32_array(dev, "st,adc-channels", chans, 1936 + nchans); 1937 + if (ret) 1938 + return ret; 1939 + 1940 + for (c = 0; c < nchans; c++) { 1941 + if (chans[c] >= adc_info->max_channels) { 1942 + dev_err(&indio_dev->dev, "Invalid channel %d\n", 1943 + chans[c]); 1946 1944 return -EINVAL; 1947 1945 } 1948 1946 1949 1947 /* Channel can't be configured both as single-ended & diff */ 1950 1948 for (i = 0; i < num_diff; i++) { 1951 - if (val == diff[i].vinp) { 1952 - dev_err(&indio_dev->dev, "channel %d misconfigured\n", val); 1949 + if (chans[c] == diff[i].vinp) { 1950 + dev_err(&indio_dev->dev, "channel %d misconfigured\n", chans[c]); 1953 1951 return -EINVAL; 1954 1952 } 1955 1953 } 1956 - stm32_adc_chan_init_one(indio_dev, &channels[scan_index], val, 1957 - 0, scan_index, false); 1954 + stm32_adc_chan_init_one(indio_dev, &channels[scan_index], 1955 + chans[c], 0, scan_index, false); 1958 1956 scan_index++; 1957 + } 1958 + 1959 + if (adc->nsmps > 0) { 1960 + ret = device_property_read_u32_array(dev, "st,min-sample-time-nsecs", 1961 + smps, adc->nsmps); 1962 + if (ret) 1963 + return ret; 1959 1964 } 1960 1965 1961 1966 for (i = 0; i < scan_index; i++) { 1962 1967 /* 1963 - * Using of_property_read_u32_index(), smp value will only be 1964 - * modified if valid u32 value can be decoded. This allows to 1965 - * get either no value, 1 shared value for all indexes, or one 1966 - * value per channel. 1968 + * This check is used with the above logic so that smp value 1969 + * will only be modified if valid u32 value can be decoded. This 1970 + * allows to get either no value, 1 shared value for all indexes, 1971 + * or one value per channel. The point is to have the same 1972 + * behavior as 'of_property_read_u32_index()'. 1967 1973 */ 1968 - of_property_read_u32_index(node, "st,min-sample-time-nsecs", i, &smp); 1974 + if (i < adc->nsmps) 1975 + smp = smps[i]; 1969 1976 1970 1977 /* Prepare sampling time settings */ 1971 1978 stm32_adc_smpr_init(adc, channels[i].channel, smp); ··· 2028 2005 struct stm32_adc *adc, 2029 2006 struct iio_chan_spec *channels) 2030 2007 { 2031 - struct device_node *node = indio_dev->dev.of_node; 2032 2008 const struct stm32_adc_info *adc_info = adc->cfg->adc_info; 2033 - struct device_node *child; 2009 + struct fwnode_handle *child; 2034 2010 const char *name; 2035 2011 int val, scan_index = 0, ret; 2036 2012 bool differential; 2037 2013 u32 vin[2]; 2038 2014 2039 - for_each_available_child_of_node(node, child) { 2040 - ret = of_property_read_u32(child, "reg", &val); 2015 + device_for_each_child_node(&indio_dev->dev, child) { 2016 + ret = fwnode_property_read_u32(child, "reg", &val); 2041 2017 if (ret) { 2042 2018 dev_err(&indio_dev->dev, "Missing channel index %d\n", ret); 2043 2019 goto err; 2044 2020 } 2045 2021 2046 - ret = of_property_read_string(child, "label", &name); 2022 + ret = fwnode_property_read_string(child, "label", &name); 2047 2023 /* label is optional */ 2048 2024 if (!ret) { 2049 2025 if (strlen(name) >= STM32_ADC_CH_SZ) { ··· 2069 2047 } 2070 2048 2071 2049 differential = false; 2072 - ret = of_property_read_u32_array(child, "diff-channels", vin, 2); 2050 + ret = fwnode_property_read_u32_array(child, "diff-channels", vin, 2); 2073 2051 /* diff-channels is optional */ 2074 2052 if (!ret) { 2075 2053 differential = true; ··· 2086 2064 stm32_adc_chan_init_one(indio_dev, &channels[scan_index], val, 2087 2065 vin[1], scan_index, differential); 2088 2066 2089 - ret = of_property_read_u32(child, "st,min-sample-time-ns", &val); 2067 + ret = fwnode_property_read_u32(child, "st,min-sample-time-ns", &val); 2090 2068 /* st,min-sample-time-ns is optional */ 2091 2069 if (!ret) { 2092 2070 stm32_adc_smpr_init(adc, channels[scan_index].channel, val); ··· 2104 2082 return scan_index; 2105 2083 2106 2084 err: 2107 - of_node_put(child); 2085 + fwnode_handle_put(child); 2108 2086 2109 2087 return ret; 2110 2088 } 2111 2089 2112 - static int stm32_adc_chan_of_init(struct iio_dev *indio_dev, bool timestamping) 2090 + static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping) 2113 2091 { 2114 - struct device_node *node = indio_dev->dev.of_node; 2115 2092 struct stm32_adc *adc = iio_priv(indio_dev); 2116 2093 const struct stm32_adc_info *adc_info = adc->cfg->adc_info; 2117 2094 struct iio_chan_spec *channels; ··· 2120 2099 for (i = 0; i < STM32_ADC_INT_CH_NB; i++) 2121 2100 adc->int_ch[i] = STM32_ADC_INT_CH_NONE; 2122 2101 2123 - num_channels = of_get_available_child_count(node); 2102 + num_channels = device_get_child_node_count(&indio_dev->dev); 2124 2103 /* If no channels have been found, fallback to channels legacy properties. */ 2125 2104 if (!num_channels) { 2126 2105 legacy = true; ··· 2151 2130 return -ENOMEM; 2152 2131 2153 2132 if (legacy) 2154 - ret = stm32_adc_legacy_chan_init(indio_dev, adc, channels); 2133 + ret = stm32_adc_legacy_chan_init(indio_dev, adc, channels, 2134 + num_channels); 2155 2135 else 2156 2136 ret = stm32_adc_generic_chan_init(indio_dev, adc, channels); 2157 2137 if (ret < 0) ··· 2234 2212 bool timestamping = false; 2235 2213 int ret; 2236 2214 2237 - if (!pdev->dev.of_node) 2238 - return -ENODEV; 2239 - 2240 2215 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc)); 2241 2216 if (!indio_dev) 2242 2217 return -ENOMEM; ··· 2242 2223 adc->common = dev_get_drvdata(pdev->dev.parent); 2243 2224 spin_lock_init(&adc->lock); 2244 2225 init_completion(&adc->completion); 2245 - adc->cfg = (const struct stm32_adc_cfg *) 2246 - of_match_device(dev->driver->of_match_table, dev)->data; 2226 + adc->cfg = device_get_match_data(dev); 2247 2227 2248 2228 indio_dev->name = dev_name(&pdev->dev); 2249 - indio_dev->dev.of_node = pdev->dev.of_node; 2229 + device_set_node(&indio_dev->dev, dev_fwnode(&pdev->dev)); 2250 2230 indio_dev->info = &stm32_adc_iio_info; 2251 2231 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_HARDWARE_TRIGGERED; 2252 2232 2253 2233 platform_set_drvdata(pdev, indio_dev); 2254 2234 2255 - ret = of_property_read_u32(pdev->dev.of_node, "reg", &adc->offset); 2235 + ret = device_property_read_u32(dev, "reg", &adc->offset); 2256 2236 if (ret != 0) { 2257 2237 dev_err(&pdev->dev, "missing reg property\n"); 2258 2238 return -EINVAL; ··· 2280 2262 } 2281 2263 } 2282 2264 2283 - ret = stm32_adc_of_get_resolution(indio_dev); 2265 + ret = stm32_adc_fw_get_resolution(indio_dev); 2284 2266 if (ret < 0) 2285 2267 return ret; 2286 2268 ··· 2297 2279 timestamping = true; 2298 2280 } 2299 2281 2300 - ret = stm32_adc_chan_of_init(indio_dev, timestamping); 2282 + ret = stm32_adc_chan_fw_init(indio_dev, timestamping); 2301 2283 if (ret < 0) 2302 2284 goto err_dma_disable; 2303 2285
drivers/iio/adc/stx104.c drivers/iio/addac/stx104.c
+1 -18
drivers/iio/adc/ti-ads131e08.c
··· 797 797 regulator_disable(st->vref_reg); 798 798 } 799 799 800 - static void ads131e08_clk_disable(void *data) 801 - { 802 - struct ads131e08_state *st = data; 803 - 804 - clk_disable_unprepare(st->adc_clk); 805 - } 806 - 807 800 static int ads131e08_probe(struct spi_device *spi) 808 801 { 809 802 const struct ads131e08_info *info; ··· 889 896 st->vref_reg = NULL; 890 897 } 891 898 892 - st->adc_clk = devm_clk_get(&spi->dev, "adc-clk"); 899 + st->adc_clk = devm_clk_get_enabled(&spi->dev, "adc-clk"); 893 900 if (IS_ERR(st->adc_clk)) 894 901 return dev_err_probe(&spi->dev, PTR_ERR(st->adc_clk), 895 902 "failed to get the ADC clock\n"); 896 - 897 - ret = clk_prepare_enable(st->adc_clk); 898 - if (ret) { 899 - dev_err(&spi->dev, "failed to prepare/enable the ADC clock\n"); 900 - return ret; 901 - } 902 - 903 - ret = devm_add_action_or_reset(&spi->dev, ads131e08_clk_disable, st); 904 - if (ret) 905 - return ret; 906 903 907 904 adc_clk_hz = clk_get_rate(st->adc_clk); 908 905 if (!adc_clk_hz) {
+67 -2
drivers/iio/adc/ti-tsc2046.c
··· 8 8 #include <linux/bitfield.h> 9 9 #include <linux/delay.h> 10 10 #include <linux/module.h> 11 + #include <linux/regulator/consumer.h> 11 12 #include <linux/spi/spi.h> 13 + #include <linux/units.h> 12 14 13 15 #include <asm/unaligned.h> 14 16 ··· 141 139 struct tsc2046_adc_priv { 142 140 struct spi_device *spi; 143 141 const struct tsc2046_adc_dcfg *dcfg; 142 + struct regulator *vref_reg; 144 143 145 144 struct iio_trigger *trig; 146 145 struct hrtimer trig_timer; ··· 176 173 u32 scan_interval_us; 177 174 u32 time_per_scan_us; 178 175 u32 time_per_bit_ns; 176 + unsigned int vref_mv; 179 177 180 178 struct tsc2046_adc_ch_cfg ch_cfg[TI_TSC2046_MAX_CHAN]; 181 179 }; ··· 256 252 case TI_TSC2046_ADDR_AUX: 257 253 case TI_TSC2046_ADDR_VBAT: 258 254 case TI_TSC2046_ADDR_TEMP0: 259 - pd |= TI_TSC2046_SER | TI_TSC2046_PD1_VREF_ON; 255 + pd |= TI_TSC2046_SER; 256 + if (!priv->vref_reg) 257 + pd |= TI_TSC2046_PD1_VREF_ON; 260 258 } 261 259 262 260 return TI_TSC2046_START | FIELD_PREP(TI_TSC2046_ADDR, ch_idx) | pd; ··· 474 468 * So, it is better to use external voltage-divider driver 475 469 * instead, which is calculating complete chain. 476 470 */ 477 - *val = TI_TSC2046_INT_VREF; 471 + *val = priv->vref_mv; 478 472 *val2 = chan->scan_type.realbits; 479 473 return IIO_VAL_FRACTIONAL_LOG2; 480 474 } ··· 746 740 } 747 741 } 748 742 743 + static void tsc2046_adc_regulator_disable(void *data) 744 + { 745 + struct tsc2046_adc_priv *priv = data; 746 + 747 + regulator_disable(priv->vref_reg); 748 + } 749 + 750 + static int tsc2046_adc_configure_regulator(struct tsc2046_adc_priv *priv) 751 + { 752 + struct device *dev = &priv->spi->dev; 753 + int ret; 754 + 755 + priv->vref_reg = devm_regulator_get_optional(dev, "vref"); 756 + if (IS_ERR(priv->vref_reg)) { 757 + /* If regulator exists but can't be get, return an error */ 758 + if (PTR_ERR(priv->vref_reg) != -ENODEV) 759 + return PTR_ERR(priv->vref_reg); 760 + priv->vref_reg = NULL; 761 + } 762 + if (!priv->vref_reg) { 763 + /* Use internal reference */ 764 + priv->vref_mv = TI_TSC2046_INT_VREF; 765 + return 0; 766 + } 767 + 768 + ret = regulator_enable(priv->vref_reg); 769 + if (ret) 770 + return ret; 771 + 772 + ret = devm_add_action_or_reset(dev, tsc2046_adc_regulator_disable, 773 + priv); 774 + if (ret) 775 + return ret; 776 + 777 + ret = regulator_get_voltage(priv->vref_reg); 778 + if (ret < 0) 779 + return ret; 780 + 781 + priv->vref_mv = ret / MILLI; 782 + 783 + return 0; 784 + } 785 + 749 786 static int tsc2046_adc_probe(struct spi_device *spi) 750 787 { 751 788 const struct tsc2046_adc_dcfg *dcfg; ··· 805 756 } 806 757 807 758 dcfg = device_get_match_data(dev); 759 + if (!dcfg) { 760 + const struct spi_device_id *id = spi_get_device_id(spi); 761 + 762 + dcfg = (const struct tsc2046_adc_dcfg *)id->driver_data; 763 + } 808 764 if (!dcfg) 809 765 return -EINVAL; 810 766 ··· 834 780 indio_dev->channels = dcfg->channels; 835 781 indio_dev->num_channels = dcfg->num_channels; 836 782 indio_dev->info = &tsc2046_adc_info; 783 + 784 + ret = tsc2046_adc_configure_regulator(priv); 785 + if (ret) 786 + return ret; 837 787 838 788 tsc2046_adc_parse_fwnode(priv); 839 789 ··· 891 833 }; 892 834 MODULE_DEVICE_TABLE(of, ads7950_of_table); 893 835 836 + static const struct spi_device_id tsc2046_adc_spi_ids[] = { 837 + { "tsc2046e-adc", (unsigned long)&tsc2046_adc_dcfg_tsc2046e }, 838 + { } 839 + }; 840 + MODULE_DEVICE_TABLE(spi, tsc2046_adc_spi_ids); 841 + 894 842 static struct spi_driver tsc2046_adc_driver = { 895 843 .driver = { 896 844 .name = "tsc2046", 897 845 .of_match_table = ads7950_of_table, 898 846 }, 847 + .id_table = tsc2046_adc_spi_ids, 899 848 .probe = tsc2046_adc_probe, 900 849 }; 901 850 module_spi_driver(tsc2046_adc_driver);
+1 -14
drivers/iio/adc/xilinx-ams.c
··· 1351 1351 }; 1352 1352 MODULE_DEVICE_TABLE(of, ams_of_match_table); 1353 1353 1354 - static void ams_clk_disable_unprepare(void *data) 1355 - { 1356 - clk_disable_unprepare(data); 1357 - } 1358 - 1359 1354 static int ams_probe(struct platform_device *pdev) 1360 1355 { 1361 1356 struct iio_dev *indio_dev; ··· 1375 1380 if (IS_ERR(ams->base)) 1376 1381 return PTR_ERR(ams->base); 1377 1382 1378 - ams->clk = devm_clk_get(&pdev->dev, NULL); 1383 + ams->clk = devm_clk_get_enabled(&pdev->dev, NULL); 1379 1384 if (IS_ERR(ams->clk)) 1380 1385 return PTR_ERR(ams->clk); 1381 - 1382 - ret = clk_prepare_enable(ams->clk); 1383 - if (ret < 0) 1384 - return ret; 1385 - 1386 - ret = devm_add_action_or_reset(&pdev->dev, ams_clk_disable_unprepare, ams->clk); 1387 - if (ret < 0) 1388 - return ret; 1389 1386 1390 1387 ret = devm_delayed_work_autocancel(&pdev->dev, &ams->ams_unmask_work, 1391 1388 ams_unmask_worker);
+1 -17
drivers/iio/adc/xilinx-xadc-core.c
··· 1296 1296 [XADC_TYPE_US] = "xilinx-system-monitor", 1297 1297 }; 1298 1298 1299 - static void xadc_clk_disable_unprepare(void *data) 1300 - { 1301 - struct clk *clk = data; 1302 - 1303 - clk_disable_unprepare(clk); 1304 - } 1305 - 1306 1299 static void xadc_cancel_delayed_work(void *data) 1307 1300 { 1308 1301 struct delayed_work *work = data; ··· 1367 1374 } 1368 1375 } 1369 1376 1370 - xadc->clk = devm_clk_get(dev, NULL); 1377 + xadc->clk = devm_clk_get_enabled(dev, NULL); 1371 1378 if (IS_ERR(xadc->clk)) 1372 1379 return PTR_ERR(xadc->clk); 1373 - 1374 - ret = clk_prepare_enable(xadc->clk); 1375 - if (ret) 1376 - return ret; 1377 - 1378 - ret = devm_add_action_or_reset(dev, 1379 - xadc_clk_disable_unprepare, xadc->clk); 1380 - if (ret) 1381 - return ret; 1382 1380 1383 1381 /* 1384 1382 * Make sure not to exceed the maximum samplerate since otherwise the
+16
drivers/iio/addac/Kconfig
··· 17 17 To compile this driver as a module, choose M here: the 18 18 module will be called ad74413r. 19 19 20 + config STX104 21 + tristate "Apex Embedded Systems STX104 driver" 22 + depends on PC104 && X86 23 + select ISA_BUS_API 24 + select GPIOLIB 25 + help 26 + Say yes here to build support for the Apex Embedded Systems STX104 27 + integrated analog PC/104 card. 28 + 29 + This driver supports the 16 channels of single-ended (8 channels of 30 + differential) analog inputs, 2 channels of analog output, 4 digital 31 + inputs, and 4 digital outputs provided by the STX104. 32 + 33 + The base port addresses for the devices may be configured via the base 34 + array module parameter. 35 + 20 36 endmenu
+1
drivers/iio/addac/Makefile
··· 5 5 6 6 # When adding new entries keep the list in alphabetical order 7 7 obj-$(CONFIG_AD74413R) += ad74413r.o 8 + obj-$(CONFIG_STX104) += stx104.o
+10
drivers/iio/cdc/Kconfig
··· 14 14 To compile this driver as a module, choose M here: the 15 15 module will be called ad7150. 16 16 17 + config AD7746 18 + tristate "Analog Devices AD7745, AD7746 AD7747 capacitive sensor driver" 19 + depends on I2C 20 + help 21 + Say yes here to build support for Analog Devices capacitive sensors. 22 + (AD7745, AD7746, AD7747) Provides direct access via sysfs. 23 + 24 + To compile this driver as a module, choose M here: the 25 + module will be called ad7746. 26 + 17 27 endmenu
+1
drivers/iio/cdc/Makefile
··· 4 4 # 5 5 6 6 obj-$(CONFIG_AD7150) += ad7150.o 7 + obj-$(CONFIG_AD7746) += ad7746.o
+4 -4
drivers/iio/common/scmi_sensors/scmi_iio.c
··· 18 18 #include <linux/scmi_protocol.h> 19 19 #include <linux/time.h> 20 20 #include <linux/types.h> 21 + #include <linux/units.h> 21 22 22 23 #define SCMI_IIO_NUM_OF_AXIS 3 23 24 ··· 131 130 static int scmi_iio_set_odr_val(struct iio_dev *iio_dev, int val, int val2) 132 131 { 133 132 struct scmi_iio_priv *sensor = iio_priv(iio_dev); 134 - const unsigned long UHZ_PER_HZ = 1000000UL; 135 133 u64 sec, mult, uHz, sf; 136 134 u32 sensor_config; 137 135 char buf[32]; ··· 145 145 return err; 146 146 } 147 147 148 - uHz = val * UHZ_PER_HZ + val2; 148 + uHz = val * MICROHZ_PER_HZ + val2; 149 149 150 150 /* 151 151 * The seconds field in the sensor interval in SCMI is 16 bits long ··· 156 156 * count the number of characters 157 157 */ 158 158 sf = (u64)uHz * 0xFFFF; 159 - do_div(sf, UHZ_PER_HZ); 159 + do_div(sf, MICROHZ_PER_HZ); 160 160 mult = scnprintf(buf, sizeof(buf), "%llu", sf) - 1; 161 161 162 - sec = int_pow(10, mult) * UHZ_PER_HZ; 162 + sec = int_pow(10, mult) * MICROHZ_PER_HZ; 163 163 do_div(sec, uHz); 164 164 if (sec == 0) { 165 165 dev_err(&iio_dev->dev,
+1 -1
drivers/iio/common/st_sensors/st_sensors_core.c
··· 354 354 return; 355 355 356 356 /* The name from the match takes precedence if present */ 357 - strlcpy(name, match, len); 357 + strscpy(name, match, len); 358 358 } 359 359 EXPORT_SYMBOL_NS(st_sensors_dev_name_probe, IIO_ST_SENSORS); 360 360
+1 -16
drivers/iio/frequency/adf4371.c
··· 540 540 return regmap_bulk_write(st->regmap, ADF4371_REG(0x30), st->buf, 5); 541 541 } 542 542 543 - static void adf4371_clk_disable(void *data) 544 - { 545 - struct adf4371_state *st = data; 546 - 547 - clk_disable_unprepare(st->clkin); 548 - } 549 - 550 543 static int adf4371_probe(struct spi_device *spi) 551 544 { 552 545 const struct spi_device_id *id = spi_get_device_id(spi); ··· 572 579 indio_dev->channels = st->chip_info->channels; 573 580 indio_dev->num_channels = st->chip_info->num_channels; 574 581 575 - st->clkin = devm_clk_get(&spi->dev, "clkin"); 582 + st->clkin = devm_clk_get_enabled(&spi->dev, "clkin"); 576 583 if (IS_ERR(st->clkin)) 577 584 return PTR_ERR(st->clkin); 578 - 579 - ret = clk_prepare_enable(st->clkin); 580 - if (ret < 0) 581 - return ret; 582 - 583 - ret = devm_add_action_or_reset(&spi->dev, adf4371_clk_disable, st); 584 - if (ret) 585 - return ret; 586 585 587 586 st->clkin_freq = clk_get_rate(st->clkin); 588 587
+1 -2
drivers/iio/frequency/admv1014.c
··· 669 669 chip_id = FIELD_GET(ADMV1014_CHIP_ID_MSK, chip_id); 670 670 if (chip_id != ADMV1014_CHIP_ID) { 671 671 dev_err(&spi->dev, "Invalid Chip ID.\n"); 672 - ret = -EINVAL; 673 - return ret; 672 + return -EINVAL; 674 673 } 675 674 676 675 ret = __admv1014_spi_update_bits(st, ADMV1014_REG_QUAD,
+1 -15
drivers/iio/frequency/adrf6780.c
··· 441 441 st->vdet_out_en = device_property_read_bool(&spi->dev, "adi,vdet-out-en"); 442 442 } 443 443 444 - static void adrf6780_clk_disable(void *data) 445 - { 446 - clk_disable_unprepare(data); 447 - } 448 - 449 444 static void adrf6780_powerdown(void *data) 450 445 { 451 446 /* Disable all components in the Enable Register */ ··· 468 473 469 474 adrf6780_properties_parse(st); 470 475 471 - st->clkin = devm_clk_get(&spi->dev, "lo_in"); 476 + st->clkin = devm_clk_get_enabled(&spi->dev, "lo_in"); 472 477 if (IS_ERR(st->clkin)) 473 478 return dev_err_probe(&spi->dev, PTR_ERR(st->clkin), 474 479 "failed to get the LO input clock\n"); 475 - 476 - ret = clk_prepare_enable(st->clkin); 477 - if (ret) 478 - return ret; 479 - 480 - ret = devm_add_action_or_reset(&spi->dev, adrf6780_clk_disable, 481 - st->clkin); 482 - if (ret) 483 - return ret; 484 480 485 481 mutex_init(&st->lock); 486 482
+1 -14
drivers/iio/imu/adis16475.c
··· 1120 1120 return IRQ_HANDLED; 1121 1121 } 1122 1122 1123 - static void adis16475_disable_clk(void *data) 1124 - { 1125 - clk_disable_unprepare((struct clk *)data); 1126 - } 1127 - 1128 1123 static int adis16475_config_sync_mode(struct adis16475 *st) 1129 1124 { 1130 1125 int ret; ··· 1145 1150 1146 1151 /* All the other modes require external input signal */ 1147 1152 if (sync->sync_mode != ADIS16475_SYNC_OUTPUT) { 1148 - struct clk *clk = devm_clk_get(dev, NULL); 1153 + struct clk *clk = devm_clk_get_enabled(dev, NULL); 1149 1154 1150 1155 if (IS_ERR(clk)) 1151 1156 return PTR_ERR(clk); 1152 - 1153 - ret = clk_prepare_enable(clk); 1154 - if (ret) 1155 - return ret; 1156 - 1157 - ret = devm_add_action_or_reset(dev, adis16475_disable_clk, clk); 1158 - if (ret) 1159 - return ret; 1160 1157 1161 1158 st->clk_freq = clk_get_rate(clk); 1162 1159 if (st->clk_freq < sync->min_rate ||
+2 -2
drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
··· 65 65 66 66 sub_elem = &elem->package.elements[j]; 67 67 if (sub_elem->type == ACPI_TYPE_STRING) 68 - strlcpy(info->type, sub_elem->string.pointer, 68 + strscpy(info->type, sub_elem->string.pointer, 69 69 sizeof(info->type)); 70 70 else if (sub_elem->type == ACPI_TYPE_INTEGER) { 71 71 if (sub_elem->integer.value != client->addr) { ··· 158 158 char *name; 159 159 160 160 info.addr = secondary; 161 - strlcpy(info.type, dev_name(&adev->dev), 161 + strscpy(info.type, dev_name(&adev->dev), 162 162 sizeof(info.type)); 163 163 name = strchr(info.type, ':'); 164 164 if (name)
+3 -2
drivers/iio/industrialio-buffer.c
··· 843 843 * to verify. 844 844 */ 845 845 if (remove_buffer && !insert_buffer && 846 - list_is_singular(&iio_dev_opaque->buffer_list)) 847 - return 0; 846 + list_is_singular(&iio_dev_opaque->buffer_list)) 847 + return 0; 848 848 849 849 modes = indio_dev->modes; 850 850 ··· 940 940 static void iio_buffer_demux_free(struct iio_buffer *buffer) 941 941 { 942 942 struct iio_demux_table *p, *q; 943 + 943 944 list_for_each_entry_safe(p, q, &buffer->demux_list, l) { 944 945 list_del(&p->l); 945 946 kfree(p);
+15 -4
drivers/iio/industrialio-core.c
··· 168 168 [IIO_CHAN_INFO_OVERSAMPLING_RATIO] = "oversampling_ratio", 169 169 [IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type", 170 170 [IIO_CHAN_INFO_CALIBAMBIENT] = "calibambient", 171 + [IIO_CHAN_INFO_ZEROPOINT] = "zeropoint", 171 172 }; 172 173 /** 173 174 * iio_device_id() - query the unique ID for the device ··· 237 236 struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) 238 237 { 239 238 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 239 + 240 240 return iio_dev_opaque->debugfs_dentry; 241 241 } 242 242 EXPORT_SYMBOL_GPL(iio_get_debugfs_dentry); ··· 449 447 static void iio_device_unregister_debugfs(struct iio_dev *indio_dev) 450 448 { 451 449 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 450 + 452 451 debugfs_remove_recursive(iio_dev_opaque->debugfs_dentry); 453 452 } 454 453 ··· 1024 1021 int ret = 0; 1025 1022 char *name = NULL; 1026 1023 char *full_postfix; 1024 + 1027 1025 sysfs_attr_init(&dev_attr->attr); 1028 1026 1029 1027 /* Build up postfix of <extend_name>_<modifier>_postfix */ ··· 1303 1299 1304 1300 ret = iio_device_add_info_mask_type_avail(indio_dev, chan, 1305 1301 IIO_SEPARATE, 1306 - &chan-> 1307 - info_mask_separate_available); 1302 + &chan->info_mask_separate_available); 1308 1303 if (ret < 0) 1309 1304 return ret; 1310 1305 attrcount += ret; ··· 1317 1314 1318 1315 ret = iio_device_add_info_mask_type_avail(indio_dev, chan, 1319 1316 IIO_SHARED_BY_TYPE, 1320 - &chan-> 1321 - info_mask_shared_by_type_available); 1317 + &chan->info_mask_shared_by_type_available); 1322 1318 if (ret < 0) 1323 1319 return ret; 1324 1320 attrcount += ret; ··· 1357 1355 1358 1356 if (chan->ext_info) { 1359 1357 unsigned int i = 0; 1358 + 1360 1359 for (ext_info = chan->ext_info; ext_info->name; ext_info++) { 1361 1360 ret = __iio_add_chan_devattr(ext_info->name, 1362 1361 chan, ··· 1406 1403 char *buf) 1407 1404 { 1408 1405 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1406 + 1409 1407 return sysfs_emit(buf, "%s\n", indio_dev->name); 1410 1408 } 1411 1409 ··· 1416 1412 char *buf) 1417 1413 { 1418 1414 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1415 + 1419 1416 return sysfs_emit(buf, "%s\n", indio_dev->label); 1420 1417 } 1421 1418 ··· 1626 1621 1627 1622 iio_device_detach_buffers(indio_dev); 1628 1623 1624 + lockdep_unregister_key(&iio_dev_opaque->mlock_key); 1625 + 1629 1626 ida_free(&iio_ida, iio_dev_opaque->id); 1630 1627 kfree(iio_dev_opaque); 1631 1628 } ··· 1686 1679 1687 1680 INIT_LIST_HEAD(&iio_dev_opaque->buffer_list); 1688 1681 INIT_LIST_HEAD(&iio_dev_opaque->ioctl_handlers); 1682 + 1683 + lockdep_register_key(&iio_dev_opaque->mlock_key); 1684 + lockdep_set_class(&indio_dev->mlock, &iio_dev_opaque->mlock_key); 1689 1685 1690 1686 return indio_dev; 1691 1687 } ··· 1787 1777 struct iio_dev_opaque *iio_dev_opaque = 1788 1778 container_of(inode->i_cdev, struct iio_dev_opaque, chrdev); 1789 1779 struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev; 1780 + 1790 1781 kfree(ib); 1791 1782 clear_bit(IIO_BUSY_BIT_POS, &iio_dev_opaque->flags); 1792 1783 iio_device_put(indio_dev);
+10 -4
drivers/iio/industrialio-event.c
··· 231 231 [IIO_EV_TYPE_MAG_ADAPTIVE] = "mag_adaptive", 232 232 [IIO_EV_TYPE_CHANGE] = "change", 233 233 [IIO_EV_TYPE_MAG_REFERENCED] = "mag_referenced", 234 + [IIO_EV_TYPE_GESTURE] = "gesture", 234 235 }; 235 236 236 237 static const char * const iio_ev_dir_text[] = { 237 238 [IIO_EV_DIR_EITHER] = "either", 238 239 [IIO_EV_DIR_RISING] = "rising", 239 - [IIO_EV_DIR_FALLING] = "falling" 240 + [IIO_EV_DIR_FALLING] = "falling", 241 + [IIO_EV_DIR_SINGLETAP] = "singletap", 242 + [IIO_EV_DIR_DOUBLETAP] = "doubletap", 240 243 }; 241 244 242 245 static const char * const iio_ev_info_text[] = { ··· 250 247 [IIO_EV_INFO_HIGH_PASS_FILTER_3DB] = "high_pass_filter_3db", 251 248 [IIO_EV_INFO_LOW_PASS_FILTER_3DB] = "low_pass_filter_3db", 252 249 [IIO_EV_INFO_TIMEOUT] = "timeout", 250 + [IIO_EV_INFO_RESET_TIMEOUT] = "reset_timeout", 251 + [IIO_EV_INFO_TAP2_MIN_DELAY] = "tap2_min_delay", 253 252 }; 254 253 255 254 static enum iio_event_direction iio_ev_attr_dir(struct iio_dev_attr *attr) ··· 359 354 enum iio_shared_by shared_by, const unsigned long *mask) 360 355 { 361 356 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 362 - ssize_t (*show)(struct device *, struct device_attribute *, char *); 363 - ssize_t (*store)(struct device *, struct device_attribute *, 364 - const char *, size_t); 357 + ssize_t (*show)(struct device *dev, struct device_attribute *attr, 358 + char *buf); 359 + ssize_t (*store)(struct device *dev, struct device_attribute *attr, 360 + const char *buf, size_t len); 365 361 unsigned int attrcount = 0; 366 362 unsigned int i; 367 363 char *postfix;
+1
drivers/iio/industrialio-trigger.c
··· 50 50 char *buf) 51 51 { 52 52 struct iio_trigger *trig = to_iio_trigger(dev); 53 + 53 54 return sysfs_emit(buf, "%s\n", trig->name); 54 55 } 55 56
+151 -119
drivers/iio/inkern.c
··· 5 5 */ 6 6 #include <linux/err.h> 7 7 #include <linux/export.h> 8 + #include <linux/property.h> 8 9 #include <linux/slab.h> 9 10 #include <linux/mutex.h> 10 - #include <linux/of.h> 11 11 12 12 #include <linux/iio/iio.h> 13 13 #include <linux/iio/iio-opaque.h> ··· 45 45 int i = 0, ret = 0; 46 46 struct iio_map_internal *mapi; 47 47 48 - if (maps == NULL) 48 + if (!maps) 49 49 return 0; 50 50 51 51 mutex_lock(&iio_map_list_lock); 52 - while (maps[i].consumer_dev_name != NULL) { 52 + while (maps[i].consumer_dev_name) { 53 53 mapi = kzalloc(sizeof(*mapi), GFP_KERNEL); 54 - if (mapi == NULL) { 54 + if (!mapi) { 55 55 ret = -ENOMEM; 56 56 goto error_ret; 57 57 } ··· 68 68 return ret; 69 69 } 70 70 EXPORT_SYMBOL_GPL(iio_map_array_register); 71 - 72 71 73 72 /* 74 73 * Remove all map entries associated with the given iio device ··· 116 117 return chan; 117 118 } 118 119 119 - #ifdef CONFIG_OF 120 - 121 - static int iio_dev_node_match(struct device *dev, const void *data) 122 - { 123 - return dev->of_node == data && dev->type == &iio_device_type; 124 - } 125 - 126 120 /** 127 - * __of_iio_simple_xlate - translate iiospec to the IIO channel index 121 + * __fwnode_iio_simple_xlate - translate iiospec to the IIO channel index 128 122 * @indio_dev: pointer to the iio_dev structure 129 123 * @iiospec: IIO specifier as found in the device tree 130 124 * ··· 126 134 * whether IIO index is less than num_channels (that is specified in the 127 135 * iio_dev). 128 136 */ 129 - static int __of_iio_simple_xlate(struct iio_dev *indio_dev, 130 - const struct of_phandle_args *iiospec) 137 + static int __fwnode_iio_simple_xlate(struct iio_dev *indio_dev, 138 + const struct fwnode_reference_args *iiospec) 131 139 { 132 - if (!iiospec->args_count) 140 + if (!iiospec->nargs) 133 141 return 0; 134 142 135 143 if (iiospec->args[0] >= indio_dev->num_channels) { 136 - dev_err(&indio_dev->dev, "invalid channel index %u\n", 144 + dev_err(&indio_dev->dev, "invalid channel index %llu\n", 137 145 iiospec->args[0]); 138 146 return -EINVAL; 139 147 } ··· 141 149 return iiospec->args[0]; 142 150 } 143 151 144 - static int __of_iio_channel_get(struct iio_channel *channel, 145 - struct device_node *np, int index) 152 + static int __fwnode_iio_channel_get(struct iio_channel *channel, 153 + struct fwnode_handle *fwnode, int index) 146 154 { 155 + struct fwnode_reference_args iiospec; 147 156 struct device *idev; 148 157 struct iio_dev *indio_dev; 149 158 int err; 150 - struct of_phandle_args iiospec; 151 159 152 - err = of_parse_phandle_with_args(np, "io-channels", 153 - "#io-channel-cells", 154 - index, &iiospec); 160 + err = fwnode_property_get_reference_args(fwnode, "io-channels", 161 + "#io-channel-cells", 0, 162 + index, &iiospec); 155 163 if (err) 156 164 return err; 157 165 158 - idev = bus_find_device(&iio_bus_type, NULL, iiospec.np, 159 - iio_dev_node_match); 160 - of_node_put(iiospec.np); 161 - if (idev == NULL) 166 + idev = bus_find_device_by_fwnode(&iio_bus_type, iiospec.fwnode); 167 + if (!idev) { 168 + fwnode_handle_put(iiospec.fwnode); 162 169 return -EPROBE_DEFER; 170 + } 163 171 164 172 indio_dev = dev_to_iio_dev(idev); 165 173 channel->indio_dev = indio_dev; 166 - if (indio_dev->info->of_xlate) 167 - index = indio_dev->info->of_xlate(indio_dev, &iiospec); 174 + if (indio_dev->info->fwnode_xlate) 175 + index = indio_dev->info->fwnode_xlate(indio_dev, &iiospec); 168 176 else 169 - index = __of_iio_simple_xlate(indio_dev, &iiospec); 177 + index = __fwnode_iio_simple_xlate(indio_dev, &iiospec); 178 + fwnode_handle_put(iiospec.fwnode); 170 179 if (index < 0) 171 180 goto err_put; 172 181 channel->channel = &indio_dev->channels[index]; ··· 179 186 return index; 180 187 } 181 188 182 - static struct iio_channel *of_iio_channel_get(struct device_node *np, int index) 189 + static struct iio_channel *fwnode_iio_channel_get(struct fwnode_handle *fwnode, 190 + int index) 183 191 { 184 192 struct iio_channel *channel; 185 193 int err; ··· 189 195 return ERR_PTR(-EINVAL); 190 196 191 197 channel = kzalloc(sizeof(*channel), GFP_KERNEL); 192 - if (channel == NULL) 198 + if (!channel) 193 199 return ERR_PTR(-ENOMEM); 194 200 195 - err = __of_iio_channel_get(channel, np, index); 201 + err = __fwnode_iio_channel_get(channel, fwnode, index); 196 202 if (err) 197 203 goto err_free_channel; 198 204 ··· 203 209 return ERR_PTR(err); 204 210 } 205 211 206 - struct iio_channel *of_iio_channel_get_by_name(struct device_node *np, 207 - const char *name) 212 + static struct iio_channel * 213 + __fwnode_iio_channel_get_by_name(struct fwnode_handle *fwnode, const char *name) 208 214 { 209 - struct iio_channel *chan = NULL; 215 + struct iio_channel *chan; 216 + int index = 0; 210 217 211 - /* Walk up the tree of devices looking for a matching iio channel */ 212 - while (np) { 213 - int index = 0; 218 + /* 219 + * For named iio channels, first look up the name in the 220 + * "io-channel-names" property. If it cannot be found, the 221 + * index will be an error code, and fwnode_iio_channel_get() 222 + * will fail. 223 + */ 224 + if (name) 225 + index = fwnode_property_match_string(fwnode, "io-channel-names", 226 + name); 214 227 215 - /* 216 - * For named iio channels, first look up the name in the 217 - * "io-channel-names" property. If it cannot be found, the 218 - * index will be an error code, and of_iio_channel_get() 219 - * will fail. 220 - */ 221 - if (name) 222 - index = of_property_match_string(np, "io-channel-names", 223 - name); 224 - chan = of_iio_channel_get(np, index); 225 - if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER) 226 - break; 227 - else if (name && index >= 0) { 228 - pr_err("ERROR: could not get IIO channel %pOF:%s(%i)\n", 229 - np, name ? name : "", index); 230 - return NULL; 228 + chan = fwnode_iio_channel_get(fwnode, index); 229 + if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER) 230 + return chan; 231 + if (name) { 232 + if (index >= 0) { 233 + pr_err("ERROR: could not get IIO channel %pfw:%s(%i)\n", 234 + fwnode, name, index); 235 + /* 236 + * In this case, we found 'name' in 'io-channel-names' 237 + * but somehow we still fail so that we should not proceed 238 + * with any other lookup. Hence, explicitly return -EINVAL 239 + * (maybe not the better error code) so that the caller 240 + * won't do a system lookup. 241 + */ 242 + return ERR_PTR(-EINVAL); 231 243 } 232 - 233 244 /* 234 - * No matching IIO channel found on this node. 235 - * If the parent node has a "io-channel-ranges" property, 236 - * then we can try one of its channels. 245 + * If index < 0, then fwnode_property_get_reference_args() fails 246 + * with -EINVAL or -ENOENT (ACPI case) which is expected. We 247 + * should not proceed if we get any other error. 237 248 */ 238 - np = np->parent; 239 - if (np && !of_get_property(np, "io-channel-ranges", NULL)) 240 - return NULL; 249 + if (PTR_ERR(chan) != -EINVAL && PTR_ERR(chan) != -ENOENT) 250 + return chan; 251 + } else if (PTR_ERR(chan) != -ENOENT) { 252 + /* 253 + * if !name, then we should only proceed the lookup if 254 + * fwnode_property_get_reference_args() returns -ENOENT. 255 + */ 256 + return chan; 241 257 } 242 258 243 - return chan; 259 + /* so we continue the lookup */ 260 + return ERR_PTR(-ENODEV); 244 261 } 245 - EXPORT_SYMBOL_GPL(of_iio_channel_get_by_name); 246 262 247 - static struct iio_channel *of_iio_channel_get_all(struct device *dev) 263 + struct iio_channel *fwnode_iio_channel_get_by_name(struct fwnode_handle *fwnode, 264 + const char *name) 248 265 { 266 + struct fwnode_handle *parent; 267 + struct iio_channel *chan; 268 + 269 + /* Walk up the tree of devices looking for a matching iio channel */ 270 + chan = __fwnode_iio_channel_get_by_name(fwnode, name); 271 + if (!IS_ERR(chan) || PTR_ERR(chan) != -ENODEV) 272 + return chan; 273 + 274 + /* 275 + * No matching IIO channel found on this node. 276 + * If the parent node has a "io-channel-ranges" property, 277 + * then we can try one of its channels. 278 + */ 279 + fwnode_for_each_parent_node(fwnode, parent) { 280 + if (!fwnode_property_present(parent, "io-channel-ranges")) { 281 + fwnode_handle_put(parent); 282 + return ERR_PTR(-ENODEV); 283 + } 284 + 285 + chan = __fwnode_iio_channel_get_by_name(fwnode, name); 286 + if (!IS_ERR(chan) || PTR_ERR(chan) != -ENODEV) { 287 + fwnode_handle_put(parent); 288 + return chan; 289 + } 290 + } 291 + 292 + return ERR_PTR(-ENODEV); 293 + } 294 + EXPORT_SYMBOL_GPL(fwnode_iio_channel_get_by_name); 295 + 296 + static struct iio_channel *fwnode_iio_channel_get_all(struct device *dev) 297 + { 298 + struct fwnode_handle *fwnode = dev_fwnode(dev); 249 299 struct iio_channel *chans; 250 300 int i, mapind, nummaps = 0; 251 301 int ret; 252 302 253 303 do { 254 - ret = of_parse_phandle_with_args(dev->of_node, 255 - "io-channels", 256 - "#io-channel-cells", 257 - nummaps, NULL); 304 + ret = fwnode_property_get_reference_args(fwnode, "io-channels", 305 + "#io-channel-cells", 0, 306 + nummaps, NULL); 258 307 if (ret < 0) 259 308 break; 260 309 } while (++nummaps); 261 310 262 - if (nummaps == 0) /* no error, return NULL to search map table */ 263 - return NULL; 311 + if (nummaps == 0) 312 + return ERR_PTR(-ENODEV); 264 313 265 314 /* NULL terminated array to save passing size */ 266 315 chans = kcalloc(nummaps + 1, sizeof(*chans), GFP_KERNEL); 267 - if (chans == NULL) 316 + if (!chans) 268 317 return ERR_PTR(-ENOMEM); 269 318 270 - /* Search for OF matches */ 319 + /* Search for FW matches */ 271 320 for (mapind = 0; mapind < nummaps; mapind++) { 272 - ret = __of_iio_channel_get(&chans[mapind], dev->of_node, 273 - mapind); 321 + ret = __fwnode_iio_channel_get(&chans[mapind], fwnode, mapind); 274 322 if (ret) 275 323 goto error_free_chans; 276 324 } ··· 325 289 return ERR_PTR(ret); 326 290 } 327 291 328 - #else /* CONFIG_OF */ 329 - 330 - static inline struct iio_channel *of_iio_channel_get_all(struct device *dev) 331 - { 332 - return NULL; 333 - } 334 - 335 - #endif /* CONFIG_OF */ 336 - 337 292 static struct iio_channel *iio_channel_get_sys(const char *name, 338 293 const char *channel_name) 339 294 { ··· 332 305 struct iio_channel *channel; 333 306 int err; 334 307 335 - if (name == NULL && channel_name == NULL) 308 + if (!(name || channel_name)) 336 309 return ERR_PTR(-ENODEV); 337 310 338 311 /* first find matching entry the channel map */ ··· 347 320 break; 348 321 } 349 322 mutex_unlock(&iio_map_list_lock); 350 - if (c == NULL) 323 + if (!c) 351 324 return ERR_PTR(-ENODEV); 352 325 353 326 channel = kzalloc(sizeof(*channel), GFP_KERNEL); 354 - if (channel == NULL) { 327 + if (!channel) { 355 328 err = -ENOMEM; 356 329 goto error_no_mem; 357 330 } ··· 363 336 iio_chan_spec_from_name(channel->indio_dev, 364 337 c->map->adc_channel_label); 365 338 366 - if (channel->channel == NULL) { 339 + if (!channel->channel) { 367 340 err = -EINVAL; 368 341 goto error_no_chan; 369 342 } ··· 385 358 struct iio_channel *channel; 386 359 387 360 if (dev) { 388 - channel = of_iio_channel_get_by_name(dev->of_node, 389 - channel_name); 390 - if (channel != NULL) 361 + channel = fwnode_iio_channel_get_by_name(dev_fwnode(dev), 362 + channel_name); 363 + if (!IS_ERR(channel) || PTR_ERR(channel) != -ENODEV) 391 364 return channel; 392 365 } 393 366 ··· 427 400 } 428 401 EXPORT_SYMBOL_GPL(devm_iio_channel_get); 429 402 430 - struct iio_channel *devm_of_iio_channel_get_by_name(struct device *dev, 431 - struct device_node *np, 432 - const char *channel_name) 403 + struct iio_channel *devm_fwnode_iio_channel_get_by_name(struct device *dev, 404 + struct fwnode_handle *fwnode, 405 + const char *channel_name) 433 406 { 434 407 struct iio_channel *channel; 435 408 int ret; 436 409 437 - channel = of_iio_channel_get_by_name(np, channel_name); 410 + channel = fwnode_iio_channel_get_by_name(fwnode, channel_name); 438 411 if (IS_ERR(channel)) 439 412 return channel; 440 413 ··· 444 417 445 418 return channel; 446 419 } 447 - EXPORT_SYMBOL_GPL(devm_of_iio_channel_get_by_name); 420 + EXPORT_SYMBOL_GPL(devm_fwnode_iio_channel_get_by_name); 448 421 449 422 struct iio_channel *iio_channel_get_all(struct device *dev) 450 423 { ··· 455 428 int mapind = 0; 456 429 int i, ret; 457 430 458 - if (dev == NULL) 431 + if (!dev) 459 432 return ERR_PTR(-EINVAL); 460 433 461 - chans = of_iio_channel_get_all(dev); 462 - if (chans) 434 + chans = fwnode_iio_channel_get_all(dev); 435 + /* 436 + * We only want to carry on if the error is -ENODEV. Anything else 437 + * should be reported up the stack. 438 + */ 439 + if (!IS_ERR(chans) || PTR_ERR(chans) != -ENODEV) 463 440 return chans; 464 441 465 442 name = dev_name(dev); ··· 483 452 484 453 /* NULL terminated array to save passing size */ 485 454 chans = kcalloc(nummaps + 1, sizeof(*chans), GFP_KERNEL); 486 - if (chans == NULL) { 455 + if (!chans) { 487 456 ret = -ENOMEM; 488 457 goto error_ret; 489 458 } ··· 497 466 chans[mapind].channel = 498 467 iio_chan_spec_from_name(chans[mapind].indio_dev, 499 468 c->map->adc_channel_label); 500 - if (chans[mapind].channel == NULL) { 469 + if (!chans[mapind].channel) { 501 470 ret = -EINVAL; 502 471 goto error_free_chans; 503 472 } ··· 559 528 EXPORT_SYMBOL_GPL(devm_iio_channel_get_all); 560 529 561 530 static int iio_channel_read(struct iio_channel *chan, int *val, int *val2, 562 - enum iio_chan_info_enum info) 531 + enum iio_chan_info_enum info) 563 532 { 564 533 int unused; 565 534 int vals[INDIO_MAX_RAW_ELEMENTS]; 566 535 int ret; 567 536 int val_len = 2; 568 537 569 - if (val2 == NULL) 538 + if (!val2) 570 539 val2 = &unused; 571 540 572 541 if (!iio_channel_has_info(chan->channel, info)) ··· 578 547 vals, &val_len, info); 579 548 *val = vals[0]; 580 549 *val2 = vals[1]; 581 - } else 550 + } else { 582 551 ret = chan->indio_dev->info->read_raw(chan->indio_dev, 583 552 chan->channel, val, val2, info); 553 + } 584 554 585 555 return ret; 586 556 } ··· 592 560 int ret; 593 561 594 562 mutex_lock(&iio_dev_opaque->info_exist_lock); 595 - if (chan->indio_dev->info == NULL) { 563 + if (!chan->indio_dev->info) { 596 564 ret = -ENODEV; 597 565 goto err_unlock; 598 566 } ··· 611 579 int ret; 612 580 613 581 mutex_lock(&iio_dev_opaque->info_exist_lock); 614 - if (chan->indio_dev->info == NULL) { 582 + if (!chan->indio_dev->info) { 615 583 ret = -ENODEV; 616 584 goto err_unlock; 617 585 } ··· 625 593 EXPORT_SYMBOL_GPL(iio_read_channel_average_raw); 626 594 627 595 static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, 628 - int raw, int *processed, unsigned int scale) 596 + int raw, int *processed, 597 + unsigned int scale) 629 598 { 630 599 int scale_type, scale_val, scale_val2; 631 600 int offset_type, offset_val, offset_val2; ··· 659 626 } 660 627 661 628 scale_type = iio_channel_read(chan, &scale_val, &scale_val2, 662 - IIO_CHAN_INFO_SCALE); 629 + IIO_CHAN_INFO_SCALE); 663 630 if (scale_type < 0) { 664 631 /* 665 632 * If no channel scaling is available apply consumer scale to ··· 704 671 } 705 672 706 673 int iio_convert_raw_to_processed(struct iio_channel *chan, int raw, 707 - int *processed, unsigned int scale) 674 + int *processed, unsigned int scale) 708 675 { 709 676 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev); 710 677 int ret; 711 678 712 679 mutex_lock(&iio_dev_opaque->info_exist_lock); 713 - if (chan->indio_dev->info == NULL) { 680 + if (!chan->indio_dev->info) { 714 681 ret = -ENODEV; 715 682 goto err_unlock; 716 683 } 717 684 718 685 ret = iio_convert_raw_to_processed_unlocked(chan, raw, processed, 719 - scale); 686 + scale); 720 687 err_unlock: 721 688 mutex_unlock(&iio_dev_opaque->info_exist_lock); 722 689 ··· 731 698 int ret; 732 699 733 700 mutex_lock(&iio_dev_opaque->info_exist_lock); 734 - if (chan->indio_dev->info == NULL) { 701 + if (!chan->indio_dev->info) { 735 702 ret = -ENODEV; 736 703 goto err_unlock; 737 704 } ··· 757 724 int ret; 758 725 759 726 mutex_lock(&iio_dev_opaque->info_exist_lock); 760 - if (chan->indio_dev->info == NULL) { 727 + if (!chan->indio_dev->info) { 761 728 ret = -ENODEV; 762 729 goto err_unlock; 763 730 } ··· 835 802 int type; 836 803 837 804 ret = iio_read_avail_channel_attribute(chan, vals, &type, length, 838 - IIO_CHAN_INFO_RAW); 805 + IIO_CHAN_INFO_RAW); 839 806 840 807 if (ret >= 0 && type != IIO_VAL_INT) 841 808 /* raw values are assumed to be IIO_VAL_INT */ ··· 919 886 /* Need to verify underlying driver has not gone away */ 920 887 921 888 mutex_lock(&iio_dev_opaque->info_exist_lock); 922 - if (chan->indio_dev->info == NULL) { 889 + if (!chan->indio_dev->info) { 923 890 ret = -ENODEV; 924 891 goto err_unlock; 925 892 } ··· 946 913 int ret; 947 914 948 915 mutex_lock(&iio_dev_opaque->info_exist_lock); 949 - if (chan->indio_dev->info == NULL) { 916 + if (!chan->indio_dev->info) { 950 917 ret = -ENODEV; 951 918 goto err_unlock; 952 919 } ··· 980 947 } 981 948 EXPORT_SYMBOL_GPL(iio_get_channel_ext_info_count); 982 949 983 - static const struct iio_chan_spec_ext_info *iio_lookup_ext_info( 984 - const struct iio_channel *chan, 985 - const char *attr) 950 + static const struct iio_chan_spec_ext_info * 951 + iio_lookup_ext_info(const struct iio_channel *chan, const char *attr) 986 952 { 987 953 const struct iio_chan_spec_ext_info *ext_info; 988 954
+11
drivers/iio/light/Kconfig
··· 331 331 This driver can also be built as a module. If so, the module 332 332 will be called ltr501. 333 333 334 + config LTRF216A 335 + tristate "Liteon LTRF216A Light Sensor" 336 + depends on I2C 337 + select REGMAP_I2C 338 + help 339 + If you say Y or M here, you get support for Liteon LTRF216A 340 + Ambient Light Sensor. 341 + 342 + If built as a dynamically linked module, it will be called 343 + ltrf216a. 344 + 334 345 config LV0104CS 335 346 tristate "LV0104CS Ambient Light Sensor" 336 347 depends on I2C
+1
drivers/iio/light/Makefile
··· 31 31 obj-$(CONFIG_JSA1212) += jsa1212.o 32 32 obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o 33 33 obj-$(CONFIG_LTR501) += ltr501.o 34 + obj-$(CONFIG_LTRF216A) += ltrf216a.o 34 35 obj-$(CONFIG_LV0104CS) += lv0104cs.o 35 36 obj-$(CONFIG_MAX44000) += max44000.o 36 37 obj-$(CONFIG_MAX44009) += max44009.o
+550
drivers/iio/light/ltrf216a.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * LTRF216A Ambient Light Sensor 4 + * 5 + * Copyright (C) 2022 Collabora, Ltd. 6 + * Author: Shreeya Patel <shreeya.patel@collabora.com> 7 + * 8 + * Copyright (C) 2021 Lite-On Technology Corp (Singapore) 9 + * Author: Shi Zhigang <Zhigang.Shi@liteon.com> 10 + * 11 + * IIO driver for LTRF216A (7-bit I2C slave address 0x53). 12 + */ 13 + 14 + #include <linux/bitfield.h> 15 + #include <linux/bits.h> 16 + #include <linux/delay.h> 17 + #include <linux/i2c.h> 18 + #include <linux/init.h> 19 + #include <linux/iopoll.h> 20 + #include <linux/mod_devicetable.h> 21 + #include <linux/module.h> 22 + #include <linux/mutex.h> 23 + #include <linux/pm.h> 24 + #include <linux/pm_runtime.h> 25 + #include <linux/regmap.h> 26 + 27 + #include <linux/iio/iio.h> 28 + 29 + #include <asm/unaligned.h> 30 + 31 + #define LTRF216A_ALS_RESET_MASK BIT(4) 32 + #define LTRF216A_ALS_DATA_STATUS BIT(3) 33 + #define LTRF216A_ALS_ENABLE_MASK BIT(1) 34 + #define LTRF216A_MAIN_CTRL 0x00 35 + #define LTRF216A_ALS_MEAS_RES 0x04 36 + #define LTRF216A_ALS_GAIN 0x05 37 + #define LTRF216A_PART_ID 0x06 38 + #define LTRF216A_MAIN_STATUS 0x07 39 + #define LTRF216A_ALS_CLEAR_DATA_0 0x0a 40 + #define LTRF216A_ALS_CLEAR_DATA_1 0x0b 41 + #define LTRF216A_ALS_CLEAR_DATA_2 0x0c 42 + #define LTRF216A_ALS_DATA_0 0x0d 43 + #define LTRF216A_ALS_DATA_1 0x0e 44 + #define LTRF216A_ALS_DATA_2 0x0f 45 + #define LTRF216A_INT_CFG 0x19 46 + #define LTRF216A_INT_PST 0x1a 47 + #define LTRF216A_ALS_THRES_UP_0 0x21 48 + #define LTRF216A_ALS_THRES_UP_1 0x22 49 + #define LTRF216A_ALS_THRES_UP_2 0x23 50 + #define LTRF216A_ALS_THRES_LOW_0 0x24 51 + #define LTRF216A_ALS_THRES_LOW_1 0x25 52 + #define LTRF216A_ALS_THRES_LOW_2 0x26 53 + #define LTRF216A_ALS_READ_DATA_DELAY_US 20000 54 + 55 + static const int ltrf216a_int_time_available[][2] = { 56 + { 0, 400000 }, 57 + { 0, 200000 }, 58 + { 0, 100000 }, 59 + { 0, 50000 }, 60 + { 0, 25000 }, 61 + }; 62 + 63 + static const int ltrf216a_int_time_reg[][2] = { 64 + { 400, 0x03 }, 65 + { 200, 0x13 }, 66 + { 100, 0x22 }, 67 + { 50, 0x31 }, 68 + { 25, 0x40 }, 69 + }; 70 + 71 + /* 72 + * Window Factor is needed when the device is under Window glass 73 + * with coated tinted ink. This is to compensate for the light loss 74 + * due to the lower transmission rate of the window glass and helps 75 + * in calculating lux. 76 + */ 77 + #define LTRF216A_WIN_FAC 1 78 + 79 + struct ltrf216a_data { 80 + struct regmap *regmap; 81 + struct i2c_client *client; 82 + u32 int_time; 83 + u16 int_time_fac; 84 + u8 als_gain_fac; 85 + /* 86 + * Protects regmap accesses and makes sure integration time 87 + * remains constant during the measurement of lux. 88 + */ 89 + struct mutex lock; 90 + }; 91 + 92 + static const struct iio_chan_spec ltrf216a_channels[] = { 93 + { 94 + .type = IIO_LIGHT, 95 + .info_mask_separate = 96 + BIT(IIO_CHAN_INFO_RAW) | 97 + BIT(IIO_CHAN_INFO_PROCESSED) | 98 + BIT(IIO_CHAN_INFO_INT_TIME), 99 + .info_mask_separate_available = 100 + BIT(IIO_CHAN_INFO_INT_TIME), 101 + }, 102 + }; 103 + 104 + static void ltrf216a_reset(struct iio_dev *indio_dev) 105 + { 106 + struct ltrf216a_data *data = iio_priv(indio_dev); 107 + 108 + /* reset sensor, chip fails to respond to this, so ignore any errors */ 109 + regmap_write(data->regmap, LTRF216A_MAIN_CTRL, LTRF216A_ALS_RESET_MASK); 110 + 111 + /* reset time */ 112 + usleep_range(1000, 2000); 113 + } 114 + 115 + static int ltrf216a_enable(struct iio_dev *indio_dev) 116 + { 117 + struct ltrf216a_data *data = iio_priv(indio_dev); 118 + struct device *dev = &data->client->dev; 119 + int ret; 120 + 121 + /* enable sensor */ 122 + ret = regmap_set_bits(data->regmap, 123 + LTRF216A_MAIN_CTRL, LTRF216A_ALS_ENABLE_MASK); 124 + if (ret) { 125 + dev_err(dev, "failed to enable sensor: %d\n", ret); 126 + return ret; 127 + } 128 + 129 + /* sleep for one integration cycle after enabling the device */ 130 + msleep(ltrf216a_int_time_reg[0][0]); 131 + 132 + return 0; 133 + } 134 + 135 + static int ltrf216a_disable(struct iio_dev *indio_dev) 136 + { 137 + struct ltrf216a_data *data = iio_priv(indio_dev); 138 + struct device *dev = &data->client->dev; 139 + int ret; 140 + 141 + ret = regmap_write(data->regmap, LTRF216A_MAIN_CTRL, 0); 142 + if (ret) 143 + dev_err(dev, "failed to disable sensor: %d\n", ret); 144 + 145 + return ret; 146 + } 147 + 148 + static void ltrf216a_cleanup(void *data) 149 + { 150 + struct iio_dev *indio_dev = data; 151 + 152 + ltrf216a_disable(indio_dev); 153 + } 154 + 155 + static int ltrf216a_set_int_time(struct ltrf216a_data *data, int itime) 156 + { 157 + struct device *dev = &data->client->dev; 158 + unsigned int i; 159 + u8 reg_val; 160 + int ret; 161 + 162 + for (i = 0; i < ARRAY_SIZE(ltrf216a_int_time_available); i++) { 163 + if (ltrf216a_int_time_available[i][1] == itime) 164 + break; 165 + } 166 + if (i == ARRAY_SIZE(ltrf216a_int_time_available)) 167 + return -EINVAL; 168 + 169 + reg_val = ltrf216a_int_time_reg[i][1]; 170 + 171 + ret = regmap_write(data->regmap, LTRF216A_ALS_MEAS_RES, reg_val); 172 + if (ret) { 173 + dev_err(dev, "failed to set integration time: %d\n", ret); 174 + return ret; 175 + } 176 + 177 + data->int_time_fac = ltrf216a_int_time_reg[i][0]; 178 + data->int_time = itime; 179 + 180 + return 0; 181 + } 182 + 183 + static int ltrf216a_get_int_time(struct ltrf216a_data *data, 184 + int *val, int *val2) 185 + { 186 + *val = 0; 187 + *val2 = data->int_time; 188 + return IIO_VAL_INT_PLUS_MICRO; 189 + } 190 + 191 + static int ltrf216a_set_power_state(struct ltrf216a_data *data, bool on) 192 + { 193 + struct device *dev = &data->client->dev; 194 + int ret = 0; 195 + 196 + if (on) { 197 + ret = pm_runtime_resume_and_get(dev); 198 + if (ret) { 199 + dev_err(dev, "failed to resume runtime PM: %d\n", ret); 200 + return ret; 201 + } 202 + } else { 203 + pm_runtime_mark_last_busy(dev); 204 + pm_runtime_put_autosuspend(dev); 205 + } 206 + 207 + return ret; 208 + } 209 + 210 + static int ltrf216a_read_data(struct ltrf216a_data *data, u8 addr) 211 + { 212 + struct device *dev = &data->client->dev; 213 + int ret, val; 214 + u8 buf[3]; 215 + 216 + ret = regmap_read_poll_timeout(data->regmap, LTRF216A_MAIN_STATUS, 217 + val, val & LTRF216A_ALS_DATA_STATUS, 218 + LTRF216A_ALS_READ_DATA_DELAY_US, 219 + LTRF216A_ALS_READ_DATA_DELAY_US * 50); 220 + if (ret) { 221 + dev_err(dev, "failed to wait for measurement data: %d\n", ret); 222 + return ret; 223 + } 224 + 225 + ret = regmap_bulk_read(data->regmap, addr, buf, sizeof(buf)); 226 + if (ret) { 227 + dev_err(dev, "failed to read measurement data: %d\n", ret); 228 + return ret; 229 + } 230 + 231 + return get_unaligned_le24(&buf[0]); 232 + } 233 + 234 + static int ltrf216a_get_lux(struct ltrf216a_data *data) 235 + { 236 + int ret, greendata; 237 + u64 lux, div; 238 + 239 + ret = ltrf216a_set_power_state(data, true); 240 + if (ret) 241 + return ret; 242 + 243 + greendata = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0); 244 + if (greendata < 0) 245 + return greendata; 246 + 247 + ltrf216a_set_power_state(data, false); 248 + 249 + lux = greendata * 45 * LTRF216A_WIN_FAC * 100; 250 + div = data->als_gain_fac * data->int_time_fac * 100; 251 + 252 + return div_u64(lux, div); 253 + } 254 + 255 + static int ltrf216a_read_raw(struct iio_dev *indio_dev, 256 + struct iio_chan_spec const *chan, int *val, 257 + int *val2, long mask) 258 + { 259 + struct ltrf216a_data *data = iio_priv(indio_dev); 260 + int ret; 261 + 262 + switch (mask) { 263 + case IIO_CHAN_INFO_RAW: 264 + ret = ltrf216a_set_power_state(data, true); 265 + if (ret) 266 + return ret; 267 + mutex_lock(&data->lock); 268 + ret = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0); 269 + mutex_unlock(&data->lock); 270 + ltrf216a_set_power_state(data, false); 271 + if (ret < 0) 272 + return ret; 273 + *val = ret; 274 + return IIO_VAL_INT; 275 + case IIO_CHAN_INFO_PROCESSED: 276 + mutex_lock(&data->lock); 277 + ret = ltrf216a_get_lux(data); 278 + mutex_unlock(&data->lock); 279 + if (ret < 0) 280 + return ret; 281 + *val = ret; 282 + return IIO_VAL_INT; 283 + case IIO_CHAN_INFO_INT_TIME: 284 + mutex_lock(&data->lock); 285 + ret = ltrf216a_get_int_time(data, val, val2); 286 + mutex_unlock(&data->lock); 287 + return ret; 288 + default: 289 + return -EINVAL; 290 + } 291 + } 292 + 293 + static int ltrf216a_write_raw(struct iio_dev *indio_dev, 294 + struct iio_chan_spec const *chan, int val, 295 + int val2, long mask) 296 + { 297 + struct ltrf216a_data *data = iio_priv(indio_dev); 298 + int ret; 299 + 300 + switch (mask) { 301 + case IIO_CHAN_INFO_INT_TIME: 302 + if (val != 0) 303 + return -EINVAL; 304 + mutex_lock(&data->lock); 305 + ret = ltrf216a_set_int_time(data, val2); 306 + mutex_unlock(&data->lock); 307 + return ret; 308 + default: 309 + return -EINVAL; 310 + } 311 + } 312 + 313 + static int ltrf216a_read_available(struct iio_dev *indio_dev, 314 + struct iio_chan_spec const *chan, 315 + const int **vals, int *type, int *length, 316 + long mask) 317 + { 318 + switch (mask) { 319 + case IIO_CHAN_INFO_INT_TIME: 320 + *length = ARRAY_SIZE(ltrf216a_int_time_available) * 2; 321 + *vals = (const int *)ltrf216a_int_time_available; 322 + *type = IIO_VAL_INT_PLUS_MICRO; 323 + return IIO_AVAIL_LIST; 324 + default: 325 + return -EINVAL; 326 + } 327 + } 328 + 329 + static const struct iio_info ltrf216a_info = { 330 + .read_raw = ltrf216a_read_raw, 331 + .write_raw = ltrf216a_write_raw, 332 + .read_avail = ltrf216a_read_available, 333 + }; 334 + 335 + static bool ltrf216a_readable_reg(struct device *dev, unsigned int reg) 336 + { 337 + switch (reg) { 338 + case LTRF216A_MAIN_CTRL: 339 + case LTRF216A_ALS_MEAS_RES: 340 + case LTRF216A_ALS_GAIN: 341 + case LTRF216A_PART_ID: 342 + case LTRF216A_MAIN_STATUS: 343 + case LTRF216A_ALS_CLEAR_DATA_0: 344 + case LTRF216A_ALS_CLEAR_DATA_1: 345 + case LTRF216A_ALS_CLEAR_DATA_2: 346 + case LTRF216A_ALS_DATA_0: 347 + case LTRF216A_ALS_DATA_1: 348 + case LTRF216A_ALS_DATA_2: 349 + case LTRF216A_INT_CFG: 350 + case LTRF216A_INT_PST: 351 + case LTRF216A_ALS_THRES_UP_0: 352 + case LTRF216A_ALS_THRES_UP_1: 353 + case LTRF216A_ALS_THRES_UP_2: 354 + case LTRF216A_ALS_THRES_LOW_0: 355 + case LTRF216A_ALS_THRES_LOW_1: 356 + case LTRF216A_ALS_THRES_LOW_2: 357 + return true; 358 + default: 359 + return false; 360 + } 361 + } 362 + 363 + static bool ltrf216a_writable_reg(struct device *dev, unsigned int reg) 364 + { 365 + switch (reg) { 366 + case LTRF216A_MAIN_CTRL: 367 + case LTRF216A_ALS_MEAS_RES: 368 + case LTRF216A_ALS_GAIN: 369 + case LTRF216A_INT_CFG: 370 + case LTRF216A_INT_PST: 371 + case LTRF216A_ALS_THRES_UP_0: 372 + case LTRF216A_ALS_THRES_UP_1: 373 + case LTRF216A_ALS_THRES_UP_2: 374 + case LTRF216A_ALS_THRES_LOW_0: 375 + case LTRF216A_ALS_THRES_LOW_1: 376 + case LTRF216A_ALS_THRES_LOW_2: 377 + return true; 378 + default: 379 + return false; 380 + } 381 + } 382 + 383 + static bool ltrf216a_volatile_reg(struct device *dev, unsigned int reg) 384 + { 385 + switch (reg) { 386 + case LTRF216A_MAIN_STATUS: 387 + case LTRF216A_ALS_CLEAR_DATA_0: 388 + case LTRF216A_ALS_CLEAR_DATA_1: 389 + case LTRF216A_ALS_CLEAR_DATA_2: 390 + case LTRF216A_ALS_DATA_0: 391 + case LTRF216A_ALS_DATA_1: 392 + case LTRF216A_ALS_DATA_2: 393 + return true; 394 + default: 395 + return false; 396 + } 397 + } 398 + 399 + static bool ltrf216a_precious_reg(struct device *dev, unsigned int reg) 400 + { 401 + return reg == LTRF216A_MAIN_STATUS; 402 + } 403 + 404 + static const struct regmap_config ltrf216a_regmap_config = { 405 + .name = "ltrf216a", 406 + .reg_bits = 8, 407 + .val_bits = 8, 408 + .cache_type = REGCACHE_RBTREE, 409 + .max_register = LTRF216A_ALS_THRES_LOW_2, 410 + .readable_reg = ltrf216a_readable_reg, 411 + .writeable_reg = ltrf216a_writable_reg, 412 + .volatile_reg = ltrf216a_volatile_reg, 413 + .precious_reg = ltrf216a_precious_reg, 414 + .disable_locking = true, 415 + }; 416 + 417 + static int ltrf216a_probe(struct i2c_client *client) 418 + { 419 + struct ltrf216a_data *data; 420 + struct iio_dev *indio_dev; 421 + int ret; 422 + 423 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 424 + if (!indio_dev) 425 + return -ENOMEM; 426 + 427 + data = iio_priv(indio_dev); 428 + 429 + data->regmap = devm_regmap_init_i2c(client, &ltrf216a_regmap_config); 430 + if (IS_ERR(data->regmap)) 431 + return dev_err_probe(&client->dev, PTR_ERR(data->regmap), 432 + "regmap initialization failed\n"); 433 + 434 + i2c_set_clientdata(client, indio_dev); 435 + data->client = client; 436 + 437 + mutex_init(&data->lock); 438 + 439 + indio_dev->info = &ltrf216a_info; 440 + indio_dev->name = "ltrf216a"; 441 + indio_dev->channels = ltrf216a_channels; 442 + indio_dev->num_channels = ARRAY_SIZE(ltrf216a_channels); 443 + indio_dev->modes = INDIO_DIRECT_MODE; 444 + 445 + ret = pm_runtime_set_active(&client->dev); 446 + if (ret) 447 + return ret; 448 + 449 + /* reset sensor, chip fails to respond to this, so ignore any errors */ 450 + ltrf216a_reset(indio_dev); 451 + 452 + ret = regmap_reinit_cache(data->regmap, &ltrf216a_regmap_config); 453 + if (ret) 454 + return dev_err_probe(&client->dev, ret, 455 + "failed to reinit regmap cache\n"); 456 + 457 + ret = ltrf216a_enable(indio_dev); 458 + if (ret) 459 + return ret; 460 + 461 + ret = devm_add_action_or_reset(&client->dev, ltrf216a_cleanup, 462 + indio_dev); 463 + if (ret) 464 + return ret; 465 + 466 + ret = devm_pm_runtime_enable(&client->dev); 467 + if (ret) 468 + return dev_err_probe(&client->dev, ret, 469 + "failed to enable runtime PM\n"); 470 + 471 + pm_runtime_set_autosuspend_delay(&client->dev, 1000); 472 + pm_runtime_use_autosuspend(&client->dev); 473 + 474 + data->int_time = 100000; 475 + data->int_time_fac = 100; 476 + data->als_gain_fac = 3; 477 + 478 + return devm_iio_device_register(&client->dev, indio_dev); 479 + } 480 + 481 + static int ltrf216a_runtime_suspend(struct device *dev) 482 + { 483 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 484 + struct ltrf216a_data *data = iio_priv(indio_dev); 485 + int ret; 486 + 487 + ret = ltrf216a_disable(indio_dev); 488 + if (ret) 489 + return ret; 490 + 491 + regcache_cache_only(data->regmap, true); 492 + 493 + return 0; 494 + } 495 + 496 + static int ltrf216a_runtime_resume(struct device *dev) 497 + { 498 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 499 + struct ltrf216a_data *data = iio_priv(indio_dev); 500 + int ret; 501 + 502 + regcache_cache_only(data->regmap, false); 503 + regcache_mark_dirty(data->regmap); 504 + ret = regcache_sync(data->regmap); 505 + if (ret) 506 + goto cache_only; 507 + 508 + ret = ltrf216a_enable(indio_dev); 509 + if (ret) 510 + goto cache_only; 511 + 512 + return 0; 513 + 514 + cache_only: 515 + regcache_cache_only(data->regmap, true); 516 + 517 + return ret; 518 + } 519 + 520 + static DEFINE_RUNTIME_DEV_PM_OPS(ltrf216a_pm_ops, ltrf216a_runtime_suspend, 521 + ltrf216a_runtime_resume, NULL); 522 + 523 + static const struct i2c_device_id ltrf216a_id[] = { 524 + { "ltrf216a" }, 525 + {} 526 + }; 527 + MODULE_DEVICE_TABLE(i2c, ltrf216a_id); 528 + 529 + static const struct of_device_id ltrf216a_of_match[] = { 530 + { .compatible = "liteon,ltrf216a" }, 531 + { .compatible = "ltr,ltrf216a" }, 532 + {} 533 + }; 534 + MODULE_DEVICE_TABLE(of, ltrf216a_of_match); 535 + 536 + static struct i2c_driver ltrf216a_driver = { 537 + .driver = { 538 + .name = "ltrf216a", 539 + .pm = pm_ptr(&ltrf216a_pm_ops), 540 + .of_match_table = ltrf216a_of_match, 541 + }, 542 + .probe_new = ltrf216a_probe, 543 + .id_table = ltrf216a_id, 544 + }; 545 + module_i2c_driver(ltrf216a_driver); 546 + 547 + MODULE_AUTHOR("Shreeya Patel <shreeya.patel@collabora.com>"); 548 + MODULE_AUTHOR("Shi Zhigang <Zhigang.Shi@liteon.com>"); 549 + MODULE_DESCRIPTION("LTRF216A ambient light sensor driver"); 550 + MODULE_LICENSE("GPL");
+2 -2
drivers/iio/magnetometer/Kconfig
··· 216 216 select IIO_TRIGGERED_BUFFER 217 217 help 218 218 Say Y here to add support for the Yamaha YAS530 series of 219 - 3-Axis Magnetometers. Right now YAS530, YAS532 and YAS533 are 220 - fully supported. 219 + 3-Axis Magnetometers. YAS530, YAS532, YAS533 and YAS537 are 220 + supported. 221 221 222 222 This driver can also be compiled as a module. 223 223 To compile this driver as a module, choose M here: the module
+1 -12
drivers/iio/magnetometer/hmc5843.h
··· 52 52 enum hmc5843_ids id, const char *name); 53 53 void hmc5843_common_remove(struct device *dev); 54 54 55 - int hmc5843_common_suspend(struct device *dev); 56 - int hmc5843_common_resume(struct device *dev); 57 - 58 - #ifdef CONFIG_PM_SLEEP 59 - static __maybe_unused SIMPLE_DEV_PM_OPS(hmc5843_pm_ops, 60 - hmc5843_common_suspend, 61 - hmc5843_common_resume); 62 - #define HMC5843_PM_OPS (&hmc5843_pm_ops) 63 - #else 64 - #define HMC5843_PM_OPS NULL 65 - #endif 66 - 55 + extern const struct dev_pm_ops hmc5843_pm_ops; 67 56 #endif /* HMC5843_CORE_H */
+4 -4
drivers/iio/magnetometer/hmc5843_core.c
··· 603 603 604 604 static const unsigned long hmc5843_scan_masks[] = {0x7, 0}; 605 605 606 - int hmc5843_common_suspend(struct device *dev) 606 + static int hmc5843_common_suspend(struct device *dev) 607 607 { 608 608 return hmc5843_set_mode(iio_priv(dev_get_drvdata(dev)), 609 609 HMC5843_MODE_SLEEP); 610 610 } 611 - EXPORT_SYMBOL_NS(hmc5843_common_suspend, IIO_HMC5843); 612 611 613 - int hmc5843_common_resume(struct device *dev) 612 + static int hmc5843_common_resume(struct device *dev) 614 613 { 615 614 return hmc5843_set_mode(iio_priv(dev_get_drvdata(dev)), 616 615 HMC5843_MODE_CONVERSION_CONTINUOUS); 617 616 } 618 - EXPORT_SYMBOL_NS(hmc5843_common_resume, IIO_HMC5843); 617 + EXPORT_NS_SIMPLE_DEV_PM_OPS(hmc5843_pm_ops, hmc5843_common_suspend, 618 + hmc5843_common_resume, IIO_HMC5843); 619 619 620 620 int hmc5843_common_probe(struct device *dev, struct regmap *regmap, 621 621 enum hmc5843_ids id, const char *name)
+1 -1
drivers/iio/magnetometer/hmc5843_i2c.c
··· 93 93 static struct i2c_driver hmc5843_driver = { 94 94 .driver = { 95 95 .name = "hmc5843", 96 - .pm = HMC5843_PM_OPS, 96 + .pm = pm_sleep_ptr(&hmc5843_pm_ops), 97 97 .of_match_table = hmc5843_of_match, 98 98 }, 99 99 .id_table = hmc5843_id,
+7 -7
drivers/iio/magnetometer/hmc5843_spi.c
··· 86 86 MODULE_DEVICE_TABLE(spi, hmc5843_id); 87 87 88 88 static struct spi_driver hmc5843_driver = { 89 - .driver = { 90 - .name = "hmc5843", 91 - .pm = HMC5843_PM_OPS, 92 - }, 93 - .id_table = hmc5843_id, 94 - .probe = hmc5843_spi_probe, 95 - .remove = hmc5843_spi_remove, 89 + .driver = { 90 + .name = "hmc5843", 91 + .pm = pm_sleep_ptr(&hmc5843_pm_ops), 92 + }, 93 + .id_table = hmc5843_id, 94 + .probe = hmc5843_spi_probe, 95 + .remove = hmc5843_spi_remove, 96 96 }; 97 97 98 98 module_spi_driver(hmc5843_driver);
+713 -142
drivers/iio/magnetometer/yamaha-yas530.c
··· 10 10 * (YAS534 is a magnetic switch, not handled) 11 11 * YAS535 MS-6C 12 12 * YAS536 MS-3W 13 - * YAS537 MS-3T (2015 Samsung Galaxy S6, Note 5, Xiaomi) 13 + * YAS537 MS-3T (2015 Samsung Galaxy S6, Note 5, Galaxy S7) 14 14 * YAS539 MS-3S (2018 Samsung Galaxy A7 SM-A750FN) 15 15 * 16 16 * Code functions found in the MPU3050 YAS530 and YAS532 drivers 17 17 * named "inv_compass" in the Tegra Android kernel tree. 18 18 * Copyright (C) 2012 InvenSense Corporation 19 + * 20 + * Code functions for YAS537 based on Yamaha Android kernel driver. 21 + * Copyright (c) 2014 Yamaha Corporation 19 22 * 20 23 * Author: Linus Walleij <linus.walleij@linaro.org> 21 24 */ ··· 32 29 #include <linux/mod_devicetable.h> 33 30 #include <linux/mutex.h> 34 31 #include <linux/pm_runtime.h> 32 + #include <linux/property.h> 35 33 #include <linux/regmap.h> 36 34 #include <linux/regulator/consumer.h> 37 35 #include <linux/random.h> 36 + #include <linux/units.h> 38 37 39 38 #include <linux/iio/buffer.h> 40 39 #include <linux/iio/iio.h> ··· 45 40 46 41 #include <asm/unaligned.h> 47 42 48 - /* This register map covers YAS530 and YAS532 but differs in YAS 537 and YAS539 */ 43 + /* Commonly used registers */ 49 44 #define YAS5XX_DEVICE_ID 0x80 50 - #define YAS5XX_ACTUATE_INIT_COIL 0x81 51 - #define YAS5XX_MEASURE 0x82 52 - #define YAS5XX_CONFIG 0x83 53 - #define YAS5XX_MEASURE_INTERVAL 0x84 54 - #define YAS5XX_OFFSET_X 0x85 /* [-31 .. 31] */ 55 - #define YAS5XX_OFFSET_Y1 0x86 /* [-31 .. 31] */ 56 - #define YAS5XX_OFFSET_Y2 0x87 /* [-31 .. 31] */ 57 - #define YAS5XX_TEST1 0x88 58 - #define YAS5XX_TEST2 0x89 59 - #define YAS5XX_CAL 0x90 60 45 #define YAS5XX_MEASURE_DATA 0xB0 46 + 47 + /* These registers are used by YAS530, YAS532 and YAS533 */ 48 + #define YAS530_ACTUATE_INIT_COIL 0x81 49 + #define YAS530_MEASURE 0x82 50 + #define YAS530_CONFIG 0x83 51 + #define YAS530_MEASURE_INTERVAL 0x84 52 + #define YAS530_OFFSET_X 0x85 /* [-31 .. 31] */ 53 + #define YAS530_OFFSET_Y1 0x86 /* [-31 .. 31] */ 54 + #define YAS530_OFFSET_Y2 0x87 /* [-31 .. 31] */ 55 + #define YAS530_TEST1 0x88 56 + #define YAS530_TEST2 0x89 57 + #define YAS530_CAL 0x90 58 + 59 + /* Registers used by YAS537 */ 60 + #define YAS537_MEASURE 0x81 /* Originally YAS537_REG_CMDR */ 61 + #define YAS537_CONFIG 0x82 /* Originally YAS537_REG_CONFR */ 62 + #define YAS537_MEASURE_INTERVAL 0x83 /* Originally YAS537_REG_INTRVLR */ 63 + #define YAS537_OFFSET_X 0x84 /* Originally YAS537_REG_OXR */ 64 + #define YAS537_OFFSET_Y1 0x85 /* Originally YAS537_REG_OY1R */ 65 + #define YAS537_OFFSET_Y2 0x86 /* Originally YAS537_REG_OY2R */ 66 + #define YAS537_AVR 0x87 67 + #define YAS537_HCK 0x88 68 + #define YAS537_LCK 0x89 69 + #define YAS537_SRST 0x90 70 + #define YAS537_ADCCAL 0x91 71 + #define YAS537_MTC 0x93 72 + #define YAS537_OC 0x9E 73 + #define YAS537_TRM 0x9F 74 + #define YAS537_CAL 0xC0 61 75 62 76 /* Bits in the YAS5xx config register */ 63 77 #define YAS5XX_CONFIG_INTON BIT(0) /* Interrupt on? */ ··· 89 65 #define YAS5XX_MEASURE_LDTC BIT(1) 90 66 #define YAS5XX_MEASURE_FORS BIT(2) 91 67 #define YAS5XX_MEASURE_DLYMES BIT(4) 68 + #define YAS5XX_MEASURE_CONT BIT(5) 92 69 93 70 /* Bits in the measure data register */ 94 71 #define YAS5XX_MEASURE_DATA_BUSY BIT(7) ··· 113 88 #define YAS532_DATA_BITS 13 114 89 #define YAS532_DATA_CENTER BIT(YAS532_DATA_BITS - 1) 115 90 #define YAS532_DATA_OVERFLOW (BIT(YAS532_DATA_BITS) - 1) 116 - #define YAS532_20DEGREES 390 /* Looks like Kelvin */ 117 91 118 - /* These variant IDs are known from code dumps */ 119 92 #define YAS537_DEVICE_ID 0x07 /* YAS537 (MS-3T) */ 120 - #define YAS539_DEVICE_ID 0x08 /* YAS539 (MS-3S) */ 93 + #define YAS537_VERSION_0 0 /* Version naming unknown */ 94 + #define YAS537_VERSION_1 1 /* Version naming unknown */ 95 + #define YAS537_MAG_AVERAGE_32_MASK GENMASK(6, 4) 96 + #define YAS537_MEASURE_TIME_WORST_US 1500 97 + #define YAS537_DEFAULT_SENSOR_DELAY_MS 50 98 + #define YAS537_MAG_RCOIL_TIME_US 65 99 + #define YAS537_MTC3_MASK_PREP GENMASK(7, 0) 100 + #define YAS537_MTC3_MASK_GET GENMASK(7, 5) 101 + #define YAS537_MTC3_ADD_BIT BIT(4) 102 + #define YAS537_HCK_MASK_PREP GENMASK(4, 0) 103 + #define YAS537_HCK_MASK_GET GENMASK(7, 4) 104 + #define YAS537_LCK_MASK_PREP GENMASK(4, 0) 105 + #define YAS537_LCK_MASK_GET GENMASK(3, 0) 106 + #define YAS537_OC_MASK_GET GENMASK(5, 0) 121 107 122 108 /* Turn off device regulators etc after 5 seconds of inactivity */ 123 109 #define YAS5XX_AUTOSUSPEND_DELAY_MS 5000 110 + 111 + enum chip_ids { 112 + yas530, 113 + yas532, 114 + yas533, 115 + yas537, 116 + }; 117 + 118 + static const int yas530_volatile_reg[] = { 119 + YAS530_ACTUATE_INIT_COIL, 120 + YAS530_MEASURE, 121 + }; 122 + 123 + static const int yas537_volatile_reg[] = { 124 + YAS537_MEASURE, 125 + }; 124 126 125 127 struct yas5xx_calibration { 126 128 /* Linearization calibration x, y1, y2 */ 127 129 s32 r[3]; 128 130 u32 f[3]; 129 131 /* Temperature compensation calibration */ 130 - s32 Cx, Cy1, Cy2; 132 + s16 Cx, Cy1, Cy2; 131 133 /* Misc calibration coefficients */ 132 - s32 a2, a3, a4, a5, a6, a7, a8, a9, k; 134 + s8 a2, a3, a4, a6, a7, a8; 135 + s16 a5, a9; 136 + u8 k; 133 137 /* clock divider */ 134 138 u8 dck; 139 + }; 140 + 141 + struct yas5xx; 142 + 143 + /** 144 + * struct yas5xx_chip_info - device-specific data and function pointers 145 + * @devid: device ID number 146 + * @product_name: product name of the YAS variant 147 + * @version_names: version letters or namings 148 + * @volatile_reg: device-specific volatile registers 149 + * @volatile_reg_qty: quantity of device-specific volatile registers 150 + * @scaling_val2: scaling value for IIO_CHAN_INFO_SCALE 151 + * @t_ref: number of counts at reference temperature 20 °C 152 + * @min_temp_x10: starting point of temperature counting in 1/10:s degrees Celsius 153 + * @get_measure: function pointer to get a measurement 154 + * @get_calibration_data: function pointer to get calibration data 155 + * @dump_calibration: function pointer to dump calibration for debugging 156 + * @measure_offsets: function pointer to measure the offsets 157 + * @power_on: function pointer to power-on procedure 158 + * 159 + * The "t_ref" value for YAS532/533 is known from the Android driver. 160 + * For YAS530 and YAS537 it was approximately measured. 161 + * 162 + * The temperatures "min_temp_x10" are derived from the temperature resolutions 163 + * given in the data sheets. 164 + */ 165 + struct yas5xx_chip_info { 166 + unsigned int devid; 167 + const char *product_name; 168 + const char *version_names[2]; 169 + const int *volatile_reg; 170 + int volatile_reg_qty; 171 + u32 scaling_val2; 172 + u16 t_ref; 173 + s16 min_temp_x10; 174 + int (*get_measure)(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo); 175 + int (*get_calibration_data)(struct yas5xx *yas5xx); 176 + void (*dump_calibration)(struct yas5xx *yas5xx); 177 + int (*measure_offsets)(struct yas5xx *yas5xx); 178 + int (*power_on)(struct yas5xx *yas5xx); 135 179 }; 136 180 137 181 /** 138 182 * struct yas5xx - state container for the YAS5xx driver 139 183 * @dev: parent device pointer 140 - * @devid: device ID number 184 + * @chip_info: device-specific data and function pointers 141 185 * @version: device version 142 - * @name: device name 143 186 * @calibration: calibration settings from the OTP storage 144 187 * @hard_offsets: offsets for each axis measured with initcoil actuated 145 188 * @orientation: mounting matrix, flipped axis etc ··· 221 128 */ 222 129 struct yas5xx { 223 130 struct device *dev; 224 - unsigned int devid; 131 + const struct yas5xx_chip_info *chip_info; 225 132 unsigned int version; 226 - char name[16]; 227 133 struct yas5xx_calibration calibration; 228 - u8 hard_offsets[3]; 134 + s8 hard_offsets[3]; 229 135 struct iio_mount_matrix orientation; 230 136 struct regmap *map; 231 137 struct regulator_bulk_data regs[2]; ··· 271 179 } 272 180 273 181 /** 274 - * yas5xx_measure() - Make a measure from the hardware 182 + * yas530_measure() - Make a measure from the hardware 275 183 * @yas5xx: The device state 276 184 * @t: the raw temperature measurement 277 185 * @x: the raw x axis measurement 278 186 * @y1: the y1 axis measurement 279 187 * @y2: the y2 axis measurement 280 188 * @return: 0 on success or error code 189 + * 190 + * Used by YAS530, YAS532 and YAS533. 281 191 */ 282 - static int yas5xx_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2) 192 + static int yas530_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2) 283 193 { 194 + const struct yas5xx_chip_info *ci = yas5xx->chip_info; 284 195 unsigned int busy; 285 196 u8 data[8]; 286 197 int ret; 287 198 u16 val; 288 199 289 200 mutex_lock(&yas5xx->lock); 290 - ret = regmap_write(yas5xx->map, YAS5XX_MEASURE, YAS5XX_MEASURE_START); 201 + ret = regmap_write(yas5xx->map, YAS530_MEASURE, YAS5XX_MEASURE_START); 291 202 if (ret < 0) 292 203 goto out_unlock; 293 204 ··· 314 219 315 220 mutex_unlock(&yas5xx->lock); 316 221 317 - switch (yas5xx->devid) { 222 + switch (ci->devid) { 318 223 case YAS530_DEVICE_ID: 319 224 /* 320 225 * The t value is 9 bits in big endian format ··· 356 261 return ret; 357 262 } 358 263 359 - static s32 yas5xx_linearize(struct yas5xx *yas5xx, u16 val, int axis) 264 + /** 265 + * yas537_measure() - Make a measure from the hardware 266 + * @yas5xx: The device state 267 + * @t: the raw temperature measurement 268 + * @x: the raw x axis measurement 269 + * @y1: the y1 axis measurement 270 + * @y2: the y2 axis measurement 271 + * @return: 0 on success or error code 272 + */ 273 + static int yas537_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2) 360 274 { 275 + struct yas5xx_calibration *c = &yas5xx->calibration; 276 + unsigned int busy; 277 + u8 data[8]; 278 + u16 xy1y2[3]; 279 + s32 h[3], s[3]; 280 + int i, ret; 281 + 282 + mutex_lock(&yas5xx->lock); 283 + 284 + /* Contrary to YAS530/532, also a "cont" bit is set, meaning unknown */ 285 + ret = regmap_write(yas5xx->map, YAS537_MEASURE, YAS5XX_MEASURE_START | 286 + YAS5XX_MEASURE_CONT); 287 + if (ret < 0) 288 + goto out_unlock; 289 + 290 + /* Use same timeout like YAS530/532 but the bit is in data row 2 */ 291 + ret = regmap_read_poll_timeout(yas5xx->map, YAS5XX_MEASURE_DATA + 2, busy, 292 + !(busy & YAS5XX_MEASURE_DATA_BUSY), 293 + 500, 20000); 294 + if (ret) { 295 + dev_err(yas5xx->dev, "timeout waiting for measurement\n"); 296 + goto out_unlock; 297 + } 298 + 299 + ret = regmap_bulk_read(yas5xx->map, YAS5XX_MEASURE_DATA, 300 + data, sizeof(data)); 301 + if (ret) 302 + goto out_unlock; 303 + 304 + mutex_unlock(&yas5xx->lock); 305 + 306 + *t = get_unaligned_be16(&data[0]); 307 + xy1y2[0] = FIELD_GET(GENMASK(13, 0), get_unaligned_be16(&data[2])); 308 + xy1y2[1] = get_unaligned_be16(&data[4]); 309 + xy1y2[2] = get_unaligned_be16(&data[6]); 310 + 311 + /* The second version of YAS537 needs to include calibration coefficients */ 312 + if (yas5xx->version == YAS537_VERSION_1) { 313 + for (i = 0; i < 3; i++) 314 + s[i] = xy1y2[i] - BIT(13); 315 + h[0] = (c->k * (128 * s[0] + c->a2 * s[1] + c->a3 * s[2])) / BIT(13); 316 + h[1] = (c->k * (c->a4 * s[0] + c->a5 * s[1] + c->a6 * s[2])) / BIT(13); 317 + h[2] = (c->k * (c->a7 * s[0] + c->a8 * s[1] + c->a9 * s[2])) / BIT(13); 318 + for (i = 0; i < 3; i++) { 319 + clamp_val(h[i], -BIT(13), BIT(13) - 1); 320 + xy1y2[i] = h[i] + BIT(13); 321 + } 322 + } 323 + 324 + *x = xy1y2[0]; 325 + *y1 = xy1y2[1]; 326 + *y2 = xy1y2[2]; 327 + 328 + return 0; 329 + 330 + out_unlock: 331 + mutex_unlock(&yas5xx->lock); 332 + return ret; 333 + } 334 + 335 + /* Used by YAS530, YAS532 and YAS533 */ 336 + static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis) 337 + { 338 + const struct yas5xx_chip_info *ci = yas5xx->chip_info; 361 339 struct yas5xx_calibration *c = &yas5xx->calibration; 362 340 static const s32 yas532ac_coef[] = { 363 341 YAS532_VERSION_AC_COEF_X, ··· 440 272 s32 coef; 441 273 442 274 /* Select coefficients */ 443 - switch (yas5xx->devid) { 275 + switch (ci->devid) { 444 276 case YAS530_DEVICE_ID: 445 277 if (yas5xx->version == YAS530_VERSION_A) 446 278 coef = YAS530_VERSION_A_COEF; ··· 470 302 (yas5xx->hard_offsets[axis] - c->r[axis]) * coef; 471 303 } 472 304 305 + static s32 yas5xx_calc_temperature(struct yas5xx *yas5xx, u16 t) 306 + { 307 + const struct yas5xx_chip_info *ci = yas5xx->chip_info; 308 + s32 to; 309 + u16 t_ref; 310 + s16 min_temp_x10; 311 + int ref_temp_x10; 312 + 313 + t_ref = ci->t_ref; 314 + min_temp_x10 = ci->min_temp_x10; 315 + ref_temp_x10 = 200; 316 + 317 + to = (min_temp_x10 + ((ref_temp_x10 - min_temp_x10) * t / t_ref)) * 100; 318 + return to; 319 + } 320 + 473 321 /** 474 - * yas5xx_get_measure() - Measure a sample of all axis and process 322 + * yas530_get_measure() - Measure a sample of all axis and process 475 323 * @yas5xx: The device state 476 324 * @to: Temperature out 477 325 * @xo: X axis out ··· 495 311 * @zo: Z axis out 496 312 * @return: 0 on success or error code 497 313 * 498 - * Returned values are in nanotesla according to some code. 314 + * Used by YAS530, YAS532 and YAS533. 499 315 */ 500 - static int yas5xx_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) 316 + static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) 501 317 { 318 + const struct yas5xx_chip_info *ci = yas5xx->chip_info; 502 319 struct yas5xx_calibration *c = &yas5xx->calibration; 503 - u16 t, x, y1, y2; 504 - /* These are "signed x, signed y1 etc */ 320 + u16 t_ref, t_comp, t, x, y1, y2; 321 + /* These are signed x, signed y1 etc */ 505 322 s32 sx, sy1, sy2, sy, sz; 506 323 int ret; 507 324 508 325 /* We first get raw data that needs to be translated to [x,y,z] */ 509 - ret = yas5xx_measure(yas5xx, &t, &x, &y1, &y2); 326 + ret = yas530_measure(yas5xx, &t, &x, &y1, &y2); 510 327 if (ret) 511 328 return ret; 512 329 513 330 /* Do some linearization if available */ 514 - sx = yas5xx_linearize(yas5xx, x, 0); 515 - sy1 = yas5xx_linearize(yas5xx, y1, 1); 516 - sy2 = yas5xx_linearize(yas5xx, y2, 2); 331 + sx = yas530_linearize(yas5xx, x, 0); 332 + sy1 = yas530_linearize(yas5xx, y1, 1); 333 + sy2 = yas530_linearize(yas5xx, y2, 2); 334 + 335 + /* 336 + * Set the temperature for compensation (unit: counts): 337 + * YAS532/YAS533 version AC uses the temperature deviation as a 338 + * multiplier. YAS530 and YAS532 version AB use solely the t value. 339 + */ 340 + t_ref = ci->t_ref; 341 + if (ci->devid == YAS532_DEVICE_ID && 342 + yas5xx->version == YAS532_VERSION_AC) { 343 + t_comp = t - t_ref; 344 + } else { 345 + t_comp = t; 346 + } 517 347 518 348 /* 519 349 * Temperature compensation for x, y1, y2 respectively: 520 350 * 521 - * Cx * t 522 - * x' = x - ------ 523 - * 100 351 + * Cx * t_comp 352 + * x' = x - ----------- 353 + * 100 524 354 */ 525 - sx = sx - (c->Cx * t) / 100; 526 - sy1 = sy1 - (c->Cy1 * t) / 100; 527 - sy2 = sy2 - (c->Cy2 * t) / 100; 355 + sx = sx - (c->Cx * t_comp) / 100; 356 + sy1 = sy1 - (c->Cy1 * t_comp) / 100; 357 + sy2 = sy2 - (c->Cy2 * t_comp) / 100; 528 358 529 359 /* 530 360 * Break y1 and y2 into y and z, y1 and y2 are apparently encoding ··· 547 349 sy = sy1 - sy2; 548 350 sz = -sy1 - sy2; 549 351 550 - /* 551 - * FIXME: convert to Celsius? Just guessing this is given 552 - * as 1/10:s of degrees so multiply by 100 to get millicentigrades. 553 - */ 554 - *to = t * 100; 352 + /* Calculate temperature readout */ 353 + *to = yas5xx_calc_temperature(yas5xx, t); 354 + 555 355 /* 556 356 * Calibrate [x,y,z] with some formulas like this: 557 357 * ··· 572 376 return 0; 573 377 } 574 378 379 + /** 380 + * yas537_get_measure() - Measure a sample of all axis and process 381 + * @yas5xx: The device state 382 + * @to: Temperature out 383 + * @xo: X axis out 384 + * @yo: Y axis out 385 + * @zo: Z axis out 386 + * @return: 0 on success or error code 387 + */ 388 + static int yas537_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) 389 + { 390 + u16 t, x, y1, y2; 391 + int ret; 392 + 393 + /* We first get raw data that needs to be translated to [x,y,z] */ 394 + ret = yas537_measure(yas5xx, &t, &x, &y1, &y2); 395 + if (ret) 396 + return ret; 397 + 398 + /* Calculate temperature readout */ 399 + *to = yas5xx_calc_temperature(yas5xx, t); 400 + 401 + /* 402 + * Unfortunately, no linearization or temperature compensation formulas 403 + * are known for YAS537. 404 + */ 405 + 406 + /* Calculate x, y, z from x, y1, y2 */ 407 + *xo = (x - BIT(13)) * 300; 408 + *yo = (y1 - y2) * 1732 / 10; 409 + *zo = (-y1 - y2 + BIT(14)) * 300; 410 + 411 + return 0; 412 + } 413 + 575 414 static int yas5xx_read_raw(struct iio_dev *indio_dev, 576 415 struct iio_chan_spec const *chan, 577 416 int *val, int *val2, 578 417 long mask) 579 418 { 580 419 struct yas5xx *yas5xx = iio_priv(indio_dev); 420 + const struct yas5xx_chip_info *ci = yas5xx->chip_info; 581 421 s32 t, x, y, z; 582 422 int ret; 583 423 584 424 switch (mask) { 425 + case IIO_CHAN_INFO_PROCESSED: 585 426 case IIO_CHAN_INFO_RAW: 586 427 pm_runtime_get_sync(yas5xx->dev); 587 - ret = yas5xx_get_measure(yas5xx, &t, &x, &y, &z); 428 + ret = ci->get_measure(yas5xx, &t, &x, &y, &z); 588 429 pm_runtime_mark_last_busy(yas5xx->dev); 589 430 pm_runtime_put_autosuspend(yas5xx->dev); 590 431 if (ret) ··· 645 412 } 646 413 return IIO_VAL_INT; 647 414 case IIO_CHAN_INFO_SCALE: 648 - if (chan->address == 0) { 649 - /* Temperature is unscaled */ 650 - *val = 1; 651 - return IIO_VAL_INT; 652 - } 653 - /* 654 - * The axis values are in nanotesla according to the vendor 655 - * drivers, but is clearly in microtesla according to 656 - * experiments. Since 1 uT = 0.01 Gauss, we need to divide 657 - * by 100000000 (10^8) to get to Gauss from the raw value. 658 - */ 659 415 *val = 1; 660 - *val2 = 100000000; 416 + *val2 = ci->scaling_val2; 661 417 return IIO_VAL_FRACTIONAL; 662 418 default: 663 419 /* Unknown request */ ··· 657 435 static void yas5xx_fill_buffer(struct iio_dev *indio_dev) 658 436 { 659 437 struct yas5xx *yas5xx = iio_priv(indio_dev); 438 + const struct yas5xx_chip_info *ci = yas5xx->chip_info; 660 439 s32 t, x, y, z; 661 440 int ret; 662 441 663 442 pm_runtime_get_sync(yas5xx->dev); 664 - ret = yas5xx_get_measure(yas5xx, &t, &x, &y, &z); 443 + ret = ci->get_measure(yas5xx, &t, &x, &y, &z); 665 444 pm_runtime_mark_last_busy(yas5xx->dev); 666 445 pm_runtime_put_autosuspend(yas5xx->dev); 667 446 if (ret) { ··· 728 505 .address = 0, 729 506 .scan_index = 0, 730 507 .scan_type = { 731 - .sign = 'u', 508 + .sign = 's', 732 509 .realbits = 32, 733 510 .storagebits = 32, 734 511 .endianness = IIO_CPU, ··· 748 525 749 526 static bool yas5xx_volatile_reg(struct device *dev, unsigned int reg) 750 527 { 751 - return reg == YAS5XX_ACTUATE_INIT_COIL || 752 - reg == YAS5XX_MEASURE || 753 - (reg >= YAS5XX_MEASURE_DATA && reg <= YAS5XX_MEASURE_DATA + 8); 528 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 529 + struct yas5xx *yas5xx = iio_priv(indio_dev); 530 + const struct yas5xx_chip_info *ci = yas5xx->chip_info; 531 + int reg_qty; 532 + int i; 533 + 534 + if (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8) 535 + return true; 536 + 537 + /* 538 + * YAS versions share different registers on the same address, 539 + * need to differentiate. 540 + */ 541 + reg_qty = ci->volatile_reg_qty; 542 + for (i = 0; i < reg_qty; i++) { 543 + if (reg == ci->volatile_reg[i]) 544 + return true; 545 + } 546 + 547 + return false; 754 548 } 755 549 756 550 /* TODO: enable regmap cache, using mark dirty and sync at runtime resume */ ··· 779 539 }; 780 540 781 541 /** 782 - * yas53x_extract_calibration() - extracts the a2-a9 and k calibration 542 + * yas530_extract_calibration() - extracts the a2-a9 and k calibration 783 543 * @data: the bitfield to use 784 544 * @c: the calibration to populate 545 + * 546 + * Used by YAS530, YAS532 and YAS533. 785 547 */ 786 - static void yas53x_extract_calibration(u8 *data, struct yas5xx_calibration *c) 548 + static void yas530_extract_calibration(u8 *data, struct yas5xx_calibration *c) 787 549 { 788 550 u64 val = get_unaligned_be64(data); 789 551 ··· 823 581 int ret; 824 582 825 583 /* Dummy read, first read is ALWAYS wrong */ 826 - ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data)); 584 + ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); 827 585 if (ret) 828 586 return ret; 829 587 830 588 /* Actual calibration readout */ 831 - ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data)); 589 + ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); 832 590 if (ret) 833 591 return ret; 834 - dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data); 592 + dev_dbg(yas5xx->dev, "calibration data: %16ph\n", data); 835 593 594 + /* Contribute calibration data to the input pool for kernel entropy */ 836 595 add_device_randomness(data, sizeof(data)); 596 + 597 + /* Extract version */ 837 598 yas5xx->version = data[15] & GENMASK(1, 0); 838 599 839 600 /* Extract the calibration from the bitfield */ 840 601 c->Cx = data[0] * 6 - 768; 841 602 c->Cy1 = data[1] * 6 - 768; 842 603 c->Cy2 = data[2] * 6 - 768; 843 - yas53x_extract_calibration(&data[3], c); 604 + yas530_extract_calibration(&data[3], c); 844 605 845 606 /* 846 607 * Extract linearization: ··· 863 618 c->r[0] = sign_extend32(FIELD_GET(GENMASK(28, 23), val), 5); 864 619 c->r[1] = sign_extend32(FIELD_GET(GENMASK(20, 15), val), 5); 865 620 c->r[2] = sign_extend32(FIELD_GET(GENMASK(12, 7), val), 5); 621 + 866 622 return 0; 867 623 } 868 624 ··· 875 629 int ret; 876 630 877 631 /* Dummy read, first read is ALWAYS wrong */ 878 - ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data)); 632 + ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); 879 633 if (ret) 880 634 return ret; 881 635 /* Actual calibration readout */ 882 - ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data)); 636 + ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); 883 637 if (ret) 884 638 return ret; 885 - dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data); 639 + dev_dbg(yas5xx->dev, "calibration data: %14ph\n", data); 886 640 887 641 /* Sanity check, is this all zeroes? */ 888 - if (memchr_inv(data, 0x00, 13) == NULL) { 889 - if (!(data[13] & BIT(7))) 890 - dev_warn(yas5xx->dev, "calibration is blank!\n"); 891 - } 642 + if (!memchr_inv(data, 0x00, 13) && !(data[13] & BIT(7))) 643 + dev_warn(yas5xx->dev, "calibration is blank!\n"); 892 644 645 + /* Contribute calibration data to the input pool for kernel entropy */ 893 646 add_device_randomness(data, sizeof(data)); 647 + 894 648 /* Only one bit of version info reserved here as far as we know */ 895 649 yas5xx->version = data[13] & BIT(0); 896 650 ··· 898 652 c->Cx = data[0] * 10 - 1280; 899 653 c->Cy1 = data[1] * 10 - 1280; 900 654 c->Cy2 = data[2] * 10 - 1280; 901 - yas53x_extract_calibration(&data[3], c); 655 + yas530_extract_calibration(&data[3], c); 656 + 902 657 /* 903 658 * Extract linearization: 904 659 * Linearization layout in the 32 bits at byte 10: ··· 922 675 return 0; 923 676 } 924 677 925 - static void yas5xx_dump_calibration(struct yas5xx *yas5xx) 678 + static int yas537_get_calibration_data(struct yas5xx *yas5xx) 679 + { 680 + struct yas5xx_calibration *c = &yas5xx->calibration; 681 + u8 data[17]; 682 + u32 val1, val2, val3, val4; 683 + int i, ret; 684 + 685 + /* Writing SRST register */ 686 + ret = regmap_write(yas5xx->map, YAS537_SRST, BIT(1)); 687 + if (ret) 688 + return ret; 689 + 690 + /* Calibration readout, YAS537 needs one readout only */ 691 + ret = regmap_bulk_read(yas5xx->map, YAS537_CAL, data, sizeof(data)); 692 + if (ret) 693 + return ret; 694 + dev_dbg(yas5xx->dev, "calibration data: %17ph\n", data); 695 + 696 + /* Sanity check, is this all zeroes? */ 697 + if (!memchr_inv(data, 0x00, 16) && !FIELD_GET(GENMASK(5, 0), data[16])) 698 + dev_warn(yas5xx->dev, "calibration is blank!\n"); 699 + 700 + /* Contribute calibration data to the input pool for kernel entropy */ 701 + add_device_randomness(data, sizeof(data)); 702 + 703 + /* Extract version information */ 704 + yas5xx->version = FIELD_GET(GENMASK(7, 6), data[16]); 705 + 706 + /* There are two versions of YAS537 behaving differently */ 707 + switch (yas5xx->version) { 708 + case YAS537_VERSION_0: 709 + /* 710 + * The first version simply writes data back into registers: 711 + * 712 + * data[0] YAS537_MTC 0x93 713 + * data[1] 0x94 714 + * data[2] 0x95 715 + * data[3] 0x96 716 + * data[4] 0x97 717 + * data[5] 0x98 718 + * data[6] 0x99 719 + * data[7] 0x9a 720 + * data[8] 0x9b 721 + * data[9] 0x9c 722 + * data[10] 0x9d 723 + * data[11] YAS537_OC 0x9e 724 + * 725 + * data[12] YAS537_OFFSET_X 0x84 726 + * data[13] YAS537_OFFSET_Y1 0x85 727 + * data[14] YAS537_OFFSET_Y2 0x86 728 + * 729 + * data[15] YAS537_HCK 0x88 730 + * data[16] YAS537_LCK 0x89 731 + */ 732 + for (i = 0; i < 12; i++) { 733 + ret = regmap_write(yas5xx->map, YAS537_MTC + i, 734 + data[i]); 735 + if (ret) 736 + return ret; 737 + } 738 + for (i = 0; i < 3; i++) { 739 + ret = regmap_write(yas5xx->map, YAS537_OFFSET_X + i, 740 + data[i + 12]); 741 + if (ret) 742 + return ret; 743 + yas5xx->hard_offsets[i] = data[i + 12]; 744 + } 745 + for (i = 0; i < 2; i++) { 746 + ret = regmap_write(yas5xx->map, YAS537_HCK + i, 747 + data[i + 15]); 748 + if (ret) 749 + return ret; 750 + } 751 + break; 752 + case YAS537_VERSION_1: 753 + /* 754 + * The second version writes some data into registers but also 755 + * extracts calibration coefficients. 756 + * 757 + * Registers being written: 758 + * 759 + * data[0] YAS537_MTC 0x93 760 + * data[1] YAS537_MTC+1 0x94 761 + * data[2] YAS537_MTC+2 0x95 762 + * data[3] YAS537_MTC+3 (partially) 0x96 763 + * 764 + * data[12] YAS537_OFFSET_X 0x84 765 + * data[13] YAS537_OFFSET_Y1 0x85 766 + * data[14] YAS537_OFFSET_Y2 0x86 767 + * 768 + * data[15] YAS537_HCK (partially) 0x88 769 + * YAS537_LCK (partially) 0x89 770 + * data[16] YAS537_OC (partially) 0x9e 771 + */ 772 + for (i = 0; i < 3; i++) { 773 + ret = regmap_write(yas5xx->map, YAS537_MTC + i, 774 + data[i]); 775 + if (ret) 776 + return ret; 777 + } 778 + for (i = 0; i < 3; i++) { 779 + ret = regmap_write(yas5xx->map, YAS537_OFFSET_X + i, 780 + data[i + 12]); 781 + if (ret) 782 + return ret; 783 + yas5xx->hard_offsets[i] = data[i + 12]; 784 + } 785 + /* 786 + * Visualization of partially taken data: 787 + * 788 + * data[3] n 7 6 5 4 3 2 1 0 789 + * YAS537_MTC+3 x x x 1 0 0 0 0 790 + * 791 + * data[15] n 7 6 5 4 3 2 1 0 792 + * YAS537_HCK x x x x 0 793 + * 794 + * data[15] n 7 6 5 4 3 2 1 0 795 + * YAS537_LCK x x x x 0 796 + * 797 + * data[16] n 7 6 5 4 3 2 1 0 798 + * YAS537_OC x x x x x x 799 + */ 800 + ret = regmap_write(yas5xx->map, YAS537_MTC + 3, 801 + FIELD_PREP(YAS537_MTC3_MASK_PREP, 802 + FIELD_GET(YAS537_MTC3_MASK_GET, data[3])) | 803 + YAS537_MTC3_ADD_BIT); 804 + if (ret) 805 + return ret; 806 + ret = regmap_write(yas5xx->map, YAS537_HCK, 807 + FIELD_PREP(YAS537_HCK_MASK_PREP, 808 + FIELD_GET(YAS537_HCK_MASK_GET, data[15]))); 809 + if (ret) 810 + return ret; 811 + ret = regmap_write(yas5xx->map, YAS537_LCK, 812 + FIELD_PREP(YAS537_LCK_MASK_PREP, 813 + FIELD_GET(YAS537_LCK_MASK_GET, data[15]))); 814 + if (ret) 815 + return ret; 816 + ret = regmap_write(yas5xx->map, YAS537_OC, 817 + FIELD_GET(YAS537_OC_MASK_GET, data[16])); 818 + if (ret) 819 + return ret; 820 + /* 821 + * For data extraction, build some blocks. Four 32-bit blocks 822 + * look appropriate. 823 + * 824 + * n 7 6 5 4 3 2 1 0 825 + * data[0] 0 [ Cx Cx Cx Cx Cx Cx Cx Cx ] bits 31 .. 24 826 + * data[1] 1 [ Cx C1 C1 C1 C1 C1 C1 C1 ] bits 23 .. 16 827 + * data[2] 2 [ C1 C1 C2 C2 C2 C2 C2 C2 ] bits 15 .. 8 828 + * data[3] 3 [ C2 C2 C2 ] bits 7 .. 0 829 + * 830 + * n 7 6 5 4 3 2 1 0 831 + * data[3] 0 [ a2 a2 a2 a2 a2 ] bits 31 .. 24 832 + * data[4] 1 [ a2 a2 a3 a3 a3 a3 a3 a3 ] bits 23 .. 16 833 + * data[5] 2 [ a3 a4 a4 a4 a4 a4 a4 a4 ] bits 15 .. 8 834 + * data[6] 3 [ a4 ] bits 7 .. 0 835 + * 836 + * n 7 6 5 4 3 2 1 0 837 + * data[6] 0 [ a5 a5 a5 a5 a5 a5 a5 ] bits 31 .. 24 838 + * data[7] 1 [ a5 a5 a6 a6 a6 a6 a6 a6 ] bits 23 .. 16 839 + * data[8] 2 [ a6 a7 a7 a7 a7 a7 a7 a7 ] bits 15 .. 8 840 + * data[9] 3 [ a7 ] bits 7 .. 0 841 + * 842 + * n 7 6 5 4 3 2 1 0 843 + * data[9] 0 [ a8 a8 a8 a8 a8 a8 a8 ] bits 31 .. 24 844 + * data[10] 1 [ a9 a9 a9 a9 a9 a9 a9 a9 ] bits 23 .. 16 845 + * data[11] 2 [ a9 k k k k k k k ] bits 15 .. 8 846 + * data[12] 3 [ ] bits 7 .. 0 847 + */ 848 + val1 = get_unaligned_be32(&data[0]); 849 + val2 = get_unaligned_be32(&data[3]); 850 + val3 = get_unaligned_be32(&data[6]); 851 + val4 = get_unaligned_be32(&data[9]); 852 + /* Extract calibration coefficients and modify */ 853 + c->Cx = FIELD_GET(GENMASK(31, 23), val1) - 256; 854 + c->Cy1 = FIELD_GET(GENMASK(22, 14), val1) - 256; 855 + c->Cy2 = FIELD_GET(GENMASK(13, 5), val1) - 256; 856 + c->a2 = FIELD_GET(GENMASK(28, 22), val2) - 64; 857 + c->a3 = FIELD_GET(GENMASK(21, 15), val2) - 64; 858 + c->a4 = FIELD_GET(GENMASK(14, 7), val2) - 128; 859 + c->a5 = FIELD_GET(GENMASK(30, 22), val3) - 112; 860 + c->a6 = FIELD_GET(GENMASK(21, 15), val3) - 64; 861 + c->a7 = FIELD_GET(GENMASK(14, 7), val3) - 128; 862 + c->a8 = FIELD_GET(GENMASK(30, 24), val4) - 64; 863 + c->a9 = FIELD_GET(GENMASK(23, 15), val4) - 112; 864 + c->k = FIELD_GET(GENMASK(14, 8), val4); 865 + break; 866 + default: 867 + dev_err(yas5xx->dev, "unknown version of YAS537\n"); 868 + return -EINVAL; 869 + } 870 + 871 + return 0; 872 + } 873 + 874 + /* Used by YAS530, YAS532 and YAS533 */ 875 + static void yas530_dump_calibration(struct yas5xx *yas5xx) 926 876 { 927 877 struct yas5xx_calibration *c = &yas5xx->calibration; 928 878 ··· 1142 698 dev_dbg(yas5xx->dev, "dck = %d\n", c->dck); 1143 699 } 1144 700 1145 - static int yas5xx_set_offsets(struct yas5xx *yas5xx, s8 ox, s8 oy1, s8 oy2) 701 + static void yas537_dump_calibration(struct yas5xx *yas5xx) 702 + { 703 + struct yas5xx_calibration *c = &yas5xx->calibration; 704 + 705 + if (yas5xx->version == YAS537_VERSION_1) { 706 + dev_dbg(yas5xx->dev, "Cx = %d\n", c->Cx); 707 + dev_dbg(yas5xx->dev, "Cy1 = %d\n", c->Cy1); 708 + dev_dbg(yas5xx->dev, "Cy2 = %d\n", c->Cy2); 709 + dev_dbg(yas5xx->dev, "a2 = %d\n", c->a2); 710 + dev_dbg(yas5xx->dev, "a3 = %d\n", c->a3); 711 + dev_dbg(yas5xx->dev, "a4 = %d\n", c->a4); 712 + dev_dbg(yas5xx->dev, "a5 = %d\n", c->a5); 713 + dev_dbg(yas5xx->dev, "a6 = %d\n", c->a6); 714 + dev_dbg(yas5xx->dev, "a7 = %d\n", c->a7); 715 + dev_dbg(yas5xx->dev, "a8 = %d\n", c->a8); 716 + dev_dbg(yas5xx->dev, "a9 = %d\n", c->a9); 717 + dev_dbg(yas5xx->dev, "k = %d\n", c->k); 718 + } 719 + } 720 + 721 + /* Used by YAS530, YAS532 and YAS533 */ 722 + static int yas530_set_offsets(struct yas5xx *yas5xx, s8 ox, s8 oy1, s8 oy2) 1146 723 { 1147 724 int ret; 1148 725 1149 - ret = regmap_write(yas5xx->map, YAS5XX_OFFSET_X, ox); 726 + ret = regmap_write(yas5xx->map, YAS530_OFFSET_X, ox); 1150 727 if (ret) 1151 728 return ret; 1152 - ret = regmap_write(yas5xx->map, YAS5XX_OFFSET_Y1, oy1); 729 + ret = regmap_write(yas5xx->map, YAS530_OFFSET_Y1, oy1); 1153 730 if (ret) 1154 731 return ret; 1155 - return regmap_write(yas5xx->map, YAS5XX_OFFSET_Y2, oy2); 732 + return regmap_write(yas5xx->map, YAS530_OFFSET_Y2, oy2); 1156 733 } 1157 734 1158 - static s8 yas5xx_adjust_offset(s8 old, int bit, u16 center, u16 measure) 735 + /* Used by YAS530, YAS532 and YAS533 */ 736 + static s8 yas530_adjust_offset(s8 old, int bit, u16 center, u16 measure) 1159 737 { 1160 738 if (measure > center) 1161 739 return old + BIT(bit); ··· 1186 720 return old; 1187 721 } 1188 722 1189 - static int yas5xx_meaure_offsets(struct yas5xx *yas5xx) 723 + /* Used by YAS530, YAS532 and YAS533 */ 724 + static int yas530_measure_offsets(struct yas5xx *yas5xx) 1190 725 { 726 + const struct yas5xx_chip_info *ci = yas5xx->chip_info; 1191 727 int ret; 1192 728 u16 center; 1193 729 u16 t, x, y1, y2; ··· 1197 729 int i; 1198 730 1199 731 /* Actuate the init coil and measure offsets */ 1200 - ret = regmap_write(yas5xx->map, YAS5XX_ACTUATE_INIT_COIL, 0); 732 + ret = regmap_write(yas5xx->map, YAS530_ACTUATE_INIT_COIL, 0); 1201 733 if (ret) 1202 734 return ret; 1203 735 1204 736 /* When the initcoil is active this should be around the center */ 1205 - switch (yas5xx->devid) { 737 + switch (ci->devid) { 1206 738 case YAS530_DEVICE_ID: 1207 739 center = YAS530_DATA_CENTER; 1208 740 break; ··· 1231 763 oy2 = 0; 1232 764 1233 765 for (i = 4; i >= 0; i--) { 1234 - ret = yas5xx_set_offsets(yas5xx, ox, oy1, oy2); 766 + ret = yas530_set_offsets(yas5xx, ox, oy1, oy2); 1235 767 if (ret) 1236 768 return ret; 1237 769 1238 - ret = yas5xx_measure(yas5xx, &t, &x, &y1, &y2); 770 + ret = yas530_measure(yas5xx, &t, &x, &y1, &y2); 1239 771 if (ret) 1240 772 return ret; 1241 773 dev_dbg(yas5xx->dev, "measurement %d: x=%d, y1=%d, y2=%d\n", 1242 774 5-i, x, y1, y2); 1243 775 1244 - ox = yas5xx_adjust_offset(ox, i, center, x); 1245 - oy1 = yas5xx_adjust_offset(oy1, i, center, y1); 1246 - oy2 = yas5xx_adjust_offset(oy2, i, center, y2); 776 + ox = yas530_adjust_offset(ox, i, center, x); 777 + oy1 = yas530_adjust_offset(oy1, i, center, y1); 778 + oy2 = yas530_adjust_offset(oy2, i, center, y2); 1247 779 } 1248 780 1249 781 /* Needed for calibration algorithm */ 1250 782 yas5xx->hard_offsets[0] = ox; 1251 783 yas5xx->hard_offsets[1] = oy1; 1252 784 yas5xx->hard_offsets[2] = oy2; 1253 - ret = yas5xx_set_offsets(yas5xx, ox, oy1, oy2); 785 + ret = yas530_set_offsets(yas5xx, ox, oy1, oy2); 1254 786 if (ret) 1255 787 return ret; 1256 788 ··· 1259 791 return 0; 1260 792 } 1261 793 1262 - static int yas5xx_power_on(struct yas5xx *yas5xx) 794 + /* Used by YAS530, YAS532 and YAS533 */ 795 + static int yas530_power_on(struct yas5xx *yas5xx) 1263 796 { 1264 797 unsigned int val; 1265 798 int ret; 1266 799 1267 800 /* Zero the test registers */ 1268 - ret = regmap_write(yas5xx->map, YAS5XX_TEST1, 0); 801 + ret = regmap_write(yas5xx->map, YAS530_TEST1, 0); 1269 802 if (ret) 1270 803 return ret; 1271 - ret = regmap_write(yas5xx->map, YAS5XX_TEST2, 0); 804 + ret = regmap_write(yas5xx->map, YAS530_TEST2, 0); 1272 805 if (ret) 1273 806 return ret; 1274 807 1275 808 /* Set up for no interrupts, calibrated clock divider */ 1276 809 val = FIELD_PREP(YAS5XX_CONFIG_CCK_MASK, yas5xx->calibration.dck); 1277 - ret = regmap_write(yas5xx->map, YAS5XX_CONFIG, val); 810 + ret = regmap_write(yas5xx->map, YAS530_CONFIG, val); 1278 811 if (ret) 1279 812 return ret; 1280 813 1281 814 /* Measure interval 0 (back-to-back?) */ 1282 - return regmap_write(yas5xx->map, YAS5XX_MEASURE_INTERVAL, 0); 815 + return regmap_write(yas5xx->map, YAS530_MEASURE_INTERVAL, 0); 1283 816 } 817 + 818 + static int yas537_power_on(struct yas5xx *yas5xx) 819 + { 820 + __be16 buf; 821 + int ret; 822 + u8 intrvl; 823 + 824 + /* Writing ADCCAL and TRM registers */ 825 + buf = cpu_to_be16(GENMASK(9, 3)); 826 + ret = regmap_bulk_write(yas5xx->map, YAS537_ADCCAL, &buf, sizeof(buf)); 827 + if (ret) 828 + return ret; 829 + ret = regmap_write(yas5xx->map, YAS537_TRM, GENMASK(7, 0)); 830 + if (ret) 831 + return ret; 832 + 833 + /* The interval value is static in regular operation */ 834 + intrvl = (YAS537_DEFAULT_SENSOR_DELAY_MS * MILLI 835 + - YAS537_MEASURE_TIME_WORST_US) / 4100; 836 + ret = regmap_write(yas5xx->map, YAS537_MEASURE_INTERVAL, intrvl); 837 + if (ret) 838 + return ret; 839 + 840 + /* The average value is also static in regular operation */ 841 + ret = regmap_write(yas5xx->map, YAS537_AVR, YAS537_MAG_AVERAGE_32_MASK); 842 + if (ret) 843 + return ret; 844 + 845 + /* Perform the "rcoil" part but skip the "last_after_rcoil" read */ 846 + ret = regmap_write(yas5xx->map, YAS537_CONFIG, BIT(3)); 847 + if (ret) 848 + return ret; 849 + 850 + /* Wait until the coil has ramped up */ 851 + usleep_range(YAS537_MAG_RCOIL_TIME_US, YAS537_MAG_RCOIL_TIME_US + 100); 852 + 853 + return 0; 854 + } 855 + 856 + static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { 857 + [yas530] = { 858 + .devid = YAS530_DEVICE_ID, 859 + .product_name = "YAS530 MS-3E", 860 + .version_names = { "A", "B" }, 861 + .volatile_reg = yas530_volatile_reg, 862 + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), 863 + .scaling_val2 = 100000000, /* picotesla to Gauss */ 864 + .t_ref = 182, /* counts */ 865 + .min_temp_x10 = -620, /* 1/10:s degrees Celsius */ 866 + .get_measure = yas530_get_measure, 867 + .get_calibration_data = yas530_get_calibration_data, 868 + .dump_calibration = yas530_dump_calibration, 869 + .measure_offsets = yas530_measure_offsets, 870 + .power_on = yas530_power_on, 871 + }, 872 + [yas532] = { 873 + .devid = YAS532_DEVICE_ID, 874 + .product_name = "YAS532 MS-3R", 875 + .version_names = { "AB", "AC" }, 876 + .volatile_reg = yas530_volatile_reg, 877 + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), 878 + .scaling_val2 = 100000, /* nanotesla to Gauss */ 879 + .t_ref = 390, /* counts */ 880 + .min_temp_x10 = -500, /* 1/10:s degrees Celsius */ 881 + .get_measure = yas530_get_measure, 882 + .get_calibration_data = yas532_get_calibration_data, 883 + .dump_calibration = yas530_dump_calibration, 884 + .measure_offsets = yas530_measure_offsets, 885 + .power_on = yas530_power_on, 886 + }, 887 + [yas533] = { 888 + .devid = YAS532_DEVICE_ID, 889 + .product_name = "YAS533 MS-3F", 890 + .version_names = { "AB", "AC" }, 891 + .volatile_reg = yas530_volatile_reg, 892 + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), 893 + .scaling_val2 = 100000, /* nanotesla to Gauss */ 894 + .t_ref = 390, /* counts */ 895 + .min_temp_x10 = -500, /* 1/10:s degrees Celsius */ 896 + .get_measure = yas530_get_measure, 897 + .get_calibration_data = yas532_get_calibration_data, 898 + .dump_calibration = yas530_dump_calibration, 899 + .measure_offsets = yas530_measure_offsets, 900 + .power_on = yas530_power_on, 901 + }, 902 + [yas537] = { 903 + .devid = YAS537_DEVICE_ID, 904 + .product_name = "YAS537 MS-3T", 905 + .version_names = { "v0", "v1" }, /* version naming unknown */ 906 + .volatile_reg = yas537_volatile_reg, 907 + .volatile_reg_qty = ARRAY_SIZE(yas537_volatile_reg), 908 + .scaling_val2 = 100000, /* nanotesla to Gauss */ 909 + .t_ref = 8120, /* counts */ 910 + .min_temp_x10 = -3860, /* 1/10:s degrees Celsius */ 911 + .get_measure = yas537_get_measure, 912 + .get_calibration_data = yas537_get_calibration_data, 913 + .dump_calibration = yas537_dump_calibration, 914 + /* .measure_offets is not needed for yas537 */ 915 + .power_on = yas537_power_on, 916 + }, 917 + }; 1284 918 1285 919 static int yas5xx_probe(struct i2c_client *i2c, 1286 920 const struct i2c_device_id *id) ··· 1390 820 struct iio_dev *indio_dev; 1391 821 struct device *dev = &i2c->dev; 1392 822 struct yas5xx *yas5xx; 823 + const struct yas5xx_chip_info *ci; 824 + int id_check; 1393 825 int ret; 1394 826 1395 827 indio_dev = devm_iio_device_alloc(dev, sizeof(*yas5xx)); ··· 1415 843 return dev_err_probe(dev, ret, "cannot get regulators\n"); 1416 844 1417 845 ret = regulator_bulk_enable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); 1418 - if (ret) { 1419 - dev_err(dev, "cannot enable regulators\n"); 1420 - return ret; 1421 - } 846 + if (ret) 847 + return dev_err_probe(dev, ret, "cannot enable regulators\n"); 1422 848 1423 849 /* See comment in runtime resume callback */ 1424 850 usleep_range(31000, 40000); ··· 1424 854 /* This will take the device out of reset if need be */ 1425 855 yas5xx->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); 1426 856 if (IS_ERR(yas5xx->reset)) { 1427 - ret = dev_err_probe(dev, PTR_ERR(yas5xx->reset), 1428 - "failed to get reset line\n"); 857 + ret = dev_err_probe(dev, PTR_ERR(yas5xx->reset), "failed to get reset line\n"); 1429 858 goto reg_off; 1430 859 } 1431 860 1432 861 yas5xx->map = devm_regmap_init_i2c(i2c, &yas5xx_regmap_config); 1433 862 if (IS_ERR(yas5xx->map)) { 1434 - dev_err(dev, "failed to allocate register map\n"); 1435 - ret = PTR_ERR(yas5xx->map); 863 + ret = dev_err_probe(dev, PTR_ERR(yas5xx->map), "failed to allocate register map\n"); 1436 864 goto assert_reset; 1437 865 } 1438 866 1439 - ret = regmap_read(yas5xx->map, YAS5XX_DEVICE_ID, &yas5xx->devid); 867 + ci = device_get_match_data(dev); 868 + if (!ci) 869 + ci = (const struct yas5xx_chip_info *)id->driver_data; 870 + yas5xx->chip_info = ci; 871 + 872 + ret = regmap_read(yas5xx->map, YAS5XX_DEVICE_ID, &id_check); 1440 873 if (ret) 1441 874 goto assert_reset; 1442 875 1443 - switch (yas5xx->devid) { 1444 - case YAS530_DEVICE_ID: 1445 - ret = yas530_get_calibration_data(yas5xx); 1446 - if (ret) 1447 - goto assert_reset; 1448 - dev_info(dev, "detected YAS530 MS-3E %s", 1449 - yas5xx->version ? "B" : "A"); 1450 - strncpy(yas5xx->name, "yas530", sizeof(yas5xx->name)); 1451 - break; 1452 - case YAS532_DEVICE_ID: 1453 - ret = yas532_get_calibration_data(yas5xx); 1454 - if (ret) 1455 - goto assert_reset; 1456 - dev_info(dev, "detected YAS532/YAS533 MS-3R/F %s", 1457 - yas5xx->version ? "AC" : "AB"); 1458 - strncpy(yas5xx->name, "yas532", sizeof(yas5xx->name)); 1459 - break; 1460 - default: 1461 - ret = -ENODEV; 1462 - dev_err(dev, "unhandled device ID %02x\n", yas5xx->devid); 876 + if (id_check != ci->devid) { 877 + ret = dev_err_probe(dev, -ENODEV, 878 + "device ID %02x doesn't match %s\n", 879 + id_check, id->name); 1463 880 goto assert_reset; 1464 881 } 1465 882 1466 - yas5xx_dump_calibration(yas5xx); 1467 - ret = yas5xx_power_on(yas5xx); 883 + ret = ci->get_calibration_data(yas5xx); 1468 884 if (ret) 1469 885 goto assert_reset; 1470 - ret = yas5xx_meaure_offsets(yas5xx); 886 + 887 + dev_info(dev, "detected %s %s\n", ci->product_name, 888 + ci->version_names[yas5xx->version]); 889 + 890 + ci->dump_calibration(yas5xx); 891 + 892 + ret = ci->power_on(yas5xx); 1471 893 if (ret) 1472 894 goto assert_reset; 895 + 896 + if (ci->measure_offsets) { 897 + ret = ci->measure_offsets(yas5xx); 898 + if (ret) 899 + goto assert_reset; 900 + } 1473 901 1474 902 indio_dev->info = &yas5xx_info; 1475 903 indio_dev->available_scan_masks = yas5xx_scan_masks; 1476 904 indio_dev->modes = INDIO_DIRECT_MODE; 1477 - indio_dev->name = yas5xx->name; 905 + indio_dev->name = id->name; 1478 906 indio_dev->channels = yas5xx_channels; 1479 907 indio_dev->num_channels = ARRAY_SIZE(yas5xx_channels); 1480 908 ··· 1480 912 yas5xx_handle_trigger, 1481 913 NULL); 1482 914 if (ret) { 1483 - dev_err(dev, "triggered buffer setup failed\n"); 915 + dev_err_probe(dev, ret, "triggered buffer setup failed\n"); 1484 916 goto assert_reset; 1485 917 } 1486 918 1487 919 ret = iio_device_register(indio_dev); 1488 920 if (ret) { 1489 - dev_err(dev, "device register failed\n"); 921 + dev_err_probe(dev, ret, "device register failed\n"); 1490 922 goto cleanup_buffer; 1491 923 } 1492 924 ··· 1548 980 { 1549 981 struct iio_dev *indio_dev = dev_get_drvdata(dev); 1550 982 struct yas5xx *yas5xx = iio_priv(indio_dev); 983 + const struct yas5xx_chip_info *ci = yas5xx->chip_info; 1551 984 int ret; 1552 985 1553 986 ret = regulator_bulk_enable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); ··· 1565 996 usleep_range(31000, 40000); 1566 997 gpiod_set_value_cansleep(yas5xx->reset, 0); 1567 998 1568 - ret = yas5xx_power_on(yas5xx); 999 + ret = ci->power_on(yas5xx); 1569 1000 if (ret) { 1570 1001 dev_err(dev, "cannot power on\n"); 1571 1002 goto out_reset; ··· 1584 1015 yas5xx_runtime_resume, NULL); 1585 1016 1586 1017 static const struct i2c_device_id yas5xx_id[] = { 1587 - {"yas530", }, 1588 - {"yas532", }, 1589 - {"yas533", }, 1018 + {"yas530", (kernel_ulong_t)&yas5xx_chip_info_tbl[yas530] }, 1019 + {"yas532", (kernel_ulong_t)&yas5xx_chip_info_tbl[yas532] }, 1020 + {"yas533", (kernel_ulong_t)&yas5xx_chip_info_tbl[yas533] }, 1021 + {"yas537", (kernel_ulong_t)&yas5xx_chip_info_tbl[yas537] }, 1590 1022 {} 1591 1023 }; 1592 1024 MODULE_DEVICE_TABLE(i2c, yas5xx_id); 1593 1025 1594 1026 static const struct of_device_id yas5xx_of_match[] = { 1595 - { .compatible = "yamaha,yas530", }, 1596 - { .compatible = "yamaha,yas532", }, 1597 - { .compatible = "yamaha,yas533", }, 1027 + { .compatible = "yamaha,yas530", &yas5xx_chip_info_tbl[yas530] }, 1028 + { .compatible = "yamaha,yas532", &yas5xx_chip_info_tbl[yas532] }, 1029 + { .compatible = "yamaha,yas533", &yas5xx_chip_info_tbl[yas533] }, 1030 + { .compatible = "yamaha,yas537", &yas5xx_chip_info_tbl[yas537] }, 1598 1031 {} 1599 1032 }; 1600 1033 MODULE_DEVICE_TABLE(of, yas5xx_of_match);
+2 -3
drivers/iio/pressure/dlhl60d.c
··· 129 129 if (ret) 130 130 return ret; 131 131 132 - *pressure = get_unaligned_be32(&st->rx_buf[1]) >> 8; 133 - *temperature = get_unaligned_be32(&st->rx_buf[3]) & 134 - GENMASK(DLH_NUM_TEMP_BITS - 1, 0); 132 + *pressure = get_unaligned_be24(&st->rx_buf[1]); 133 + *temperature = get_unaligned_be24(&st->rx_buf[4]); 135 134 136 135 return 0; 137 136 }
+5 -5
drivers/iio/pressure/icp10100.c
··· 595 595 return devm_iio_device_register(&client->dev, indio_dev); 596 596 } 597 597 598 - static int __maybe_unused icp10100_suspend(struct device *dev) 598 + static int icp10100_suspend(struct device *dev) 599 599 { 600 600 struct icp10100_state *st = iio_priv(dev_get_drvdata(dev)); 601 601 int ret; ··· 607 607 return ret; 608 608 } 609 609 610 - static int __maybe_unused icp10100_resume(struct device *dev) 610 + static int icp10100_resume(struct device *dev) 611 611 { 612 612 struct icp10100_state *st = iio_priv(dev_get_drvdata(dev)); 613 613 int ret; ··· 626 626 return ret; 627 627 } 628 628 629 - static UNIVERSAL_DEV_PM_OPS(icp10100_pm, icp10100_suspend, icp10100_resume, 630 - NULL); 629 + static DEFINE_RUNTIME_DEV_PM_OPS(icp10100_pm, icp10100_suspend, icp10100_resume, 630 + NULL); 631 631 632 632 static const struct of_device_id icp10100_of_match[] = { 633 633 { ··· 646 646 static struct i2c_driver icp10100_driver = { 647 647 .driver = { 648 648 .name = "icp10100", 649 - .pm = &icp10100_pm, 649 + .pm = pm_ptr(&icp10100_pm), 650 650 .of_match_table = icp10100_of_match, 651 651 }, 652 652 .probe = icp10100_probe,
+56 -5
drivers/iio/temperature/mlx90632.c
··· 18 18 #include <linux/math64.h> 19 19 #include <linux/pm_runtime.h> 20 20 #include <linux/regmap.h> 21 + #include <linux/regulator/consumer.h> 21 22 22 23 #include <linux/iio/iio.h> 23 24 #include <linux/iio/sysfs.h> ··· 129 128 * calculations 130 129 * @object_ambient_temperature: Ambient temperature at object (might differ of 131 130 * the ambient temperature of sensor. 131 + * @regulator: Regulator of the device 132 132 */ 133 133 struct mlx90632_data { 134 134 struct i2c_client *client; ··· 138 136 u16 emissivity; 139 137 u8 mtyp; 140 138 u32 object_ambient_temperature; 139 + struct regulator *regulator; 141 140 }; 142 141 143 142 static const struct regmap_range mlx90632_volatile_reg_range[] = { ··· 211 208 } 212 209 213 210 /** 211 + * mlx90632_reset_delay() - Give the mlx90632 some time to reset properly 212 + * If this is not done, the following I2C command(s) will not be accepted. 213 + */ 214 + static void mlx90632_reset_delay(void) 215 + { 216 + usleep_range(150, 200); 217 + } 218 + 219 + /** 214 220 * mlx90632_perform_measurement() - Trigger and retrieve current measurement cycle 215 221 * @data: pointer to mlx90632_data object containing regmap information 216 222 * ··· 260 248 if (ret < 0) 261 249 return ret; 262 250 263 - /* 264 - * Give the mlx90632 some time to reset properly before sending a new I2C command 265 - * if this is not done, the following I2C command(s) will not be accepted. 266 - */ 267 - usleep_range(150, 200); 251 + mlx90632_reset_delay(); 268 252 269 253 ret = regmap_write_bits(regmap, MLX90632_REG_CONTROL, 270 254 (MLX90632_CFG_MTYP_MASK | MLX90632_CFG_PWR_MASK), ··· 849 841 return mlx90632_pwr_continuous(data->regmap); 850 842 } 851 843 844 + static void mlx90632_disable_regulator(void *_data) 845 + { 846 + struct mlx90632_data *data = _data; 847 + int ret; 848 + 849 + ret = regulator_disable(data->regulator); 850 + if (ret < 0) 851 + dev_err(regmap_get_device(data->regmap), 852 + "Failed to disable power regulator: %d\n", ret); 853 + } 854 + 855 + static int mlx90632_enable_regulator(struct mlx90632_data *data) 856 + { 857 + int ret; 858 + 859 + ret = regulator_enable(data->regulator); 860 + if (ret < 0) { 861 + dev_err(regmap_get_device(data->regmap), "Failed to enable power regulator!\n"); 862 + return ret; 863 + } 864 + 865 + mlx90632_reset_delay(); 866 + 867 + return ret; 868 + } 869 + 852 870 static int mlx90632_probe(struct i2c_client *client, 853 871 const struct i2c_device_id *id) 854 872 { ··· 909 875 indio_dev->info = &mlx90632_info; 910 876 indio_dev->channels = mlx90632_channels; 911 877 indio_dev->num_channels = ARRAY_SIZE(mlx90632_channels); 878 + 879 + mlx90632->regulator = devm_regulator_get(&client->dev, "vdd"); 880 + if (IS_ERR(mlx90632->regulator)) 881 + return dev_err_probe(&client->dev, PTR_ERR(mlx90632->regulator), 882 + "failed to get vdd regulator"); 883 + 884 + ret = mlx90632_enable_regulator(mlx90632); 885 + if (ret < 0) 886 + return ret; 887 + 888 + ret = devm_add_action_or_reset(&client->dev, mlx90632_disable_regulator, 889 + mlx90632); 890 + if (ret < 0) { 891 + dev_err(&client->dev, "Failed to setup regulator cleanup action %d\n", 892 + ret); 893 + return ret; 894 + } 912 895 913 896 ret = mlx90632_wakeup(mlx90632); 914 897 if (ret < 0) {
+2 -2
drivers/iio/test/iio-test-rescale.c
··· 29 29 const char *expected_off; 30 30 }; 31 31 32 - const struct rescale_tc_data scale_cases[] = { 32 + static const struct rescale_tc_data scale_cases[] = { 33 33 /* 34 34 * Typical use cases 35 35 */ ··· 477 477 }, 478 478 }; 479 479 480 - const struct rescale_tc_data offset_cases[] = { 480 + static const struct rescale_tc_data offset_cases[] = { 481 481 /* 482 482 * Typical use cases 483 483 */
-1
drivers/staging/iio/Kconfig
··· 8 8 source "drivers/staging/iio/accel/Kconfig" 9 9 source "drivers/staging/iio/adc/Kconfig" 10 10 source "drivers/staging/iio/addac/Kconfig" 11 - source "drivers/staging/iio/cdc/Kconfig" 12 11 source "drivers/staging/iio/frequency/Kconfig" 13 12 source "drivers/staging/iio/impedance-analyzer/Kconfig" 14 13 source "drivers/staging/iio/meter/Kconfig"
-1
drivers/staging/iio/Makefile
··· 6 6 obj-y += accel/ 7 7 obj-y += adc/ 8 8 obj-y += addac/ 9 - obj-y += cdc/ 10 9 obj-y += frequency/ 11 10 obj-y += impedance-analyzer/ 12 11 obj-y += meter/
-17
drivers/staging/iio/cdc/Kconfig
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - # 3 - # CDC drivers 4 - # 5 - menu "Capacitance to digital converters" 6 - 7 - config AD7746 8 - tristate "Analog Devices AD7745, AD7746 AD7747 capacitive sensor driver" 9 - depends on I2C 10 - help 11 - Say yes here to build support for Analog Devices capacitive sensors. 12 - (AD7745, AD7746, AD7747) Provides direct access via sysfs. 13 - 14 - To compile this driver as a module, choose M here: the 15 - module will be called ad7746. 16 - 17 - endmenu
-6
drivers/staging/iio/cdc/Makefile
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - # 3 - # Makefile for industrial I/O CDC drivers 4 - # 5 - 6 - obj-$(CONFIG_AD7746) += ad7746.o
+247 -194
drivers/staging/iio/cdc/ad7746.c drivers/iio/cdc/ad7746.c
··· 5 5 * Copyright 2011 Analog Devices Inc. 6 6 */ 7 7 8 + #include <linux/bitfield.h> 8 9 #include <linux/delay.h> 9 10 #include <linux/device.h> 10 11 #include <linux/i2c.h> ··· 16 15 #include <linux/stat.h> 17 16 #include <linux/sysfs.h> 18 17 18 + #include <asm/unaligned.h> 19 + 19 20 #include <linux/iio/iio.h> 20 21 #include <linux/iio/sysfs.h> 21 22 22 - /* 23 - * AD7746 Register Definition 24 - */ 23 + /* AD7746 Register Definition */ 25 24 26 25 #define AD7746_REG_STATUS 0 27 26 #define AD7746_REG_CAP_DATA_HIGH 1 ··· 49 48 #define AD7746_CAPSETUP_CACHOP BIT(0) 50 49 51 50 /* Voltage/Temperature Setup Register Bit Designations (AD7746_REG_VT_SETUP) */ 52 - #define AD7746_VTSETUP_VTEN (1 << 7) 53 - #define AD7746_VTSETUP_VTMD_INT_TEMP (0 << 5) 54 - #define AD7746_VTSETUP_VTMD_EXT_TEMP (1 << 5) 55 - #define AD7746_VTSETUP_VTMD_VDD_MON (2 << 5) 56 - #define AD7746_VTSETUP_VTMD_EXT_VIN (3 << 5) 51 + #define AD7746_VTSETUP_VTEN BIT(7) 52 + #define AD7746_VTSETUP_VTMD_MASK GENMASK(6, 5) 53 + #define AD7746_VTSETUP_VTMD_INT_TEMP 0 54 + #define AD7746_VTSETUP_VTMD_EXT_TEMP 1 55 + #define AD7746_VTSETUP_VTMD_VDD_MON 2 56 + #define AD7746_VTSETUP_VTMD_EXT_VIN 3 57 57 #define AD7746_VTSETUP_EXTREF BIT(4) 58 58 #define AD7746_VTSETUP_VTSHORT BIT(1) 59 59 #define AD7746_VTSETUP_VTCHOP BIT(0) ··· 66 64 #define AD7746_EXCSETUP_NEXCB BIT(4) 67 65 #define AD7746_EXCSETUP_EXCA BIT(3) 68 66 #define AD7746_EXCSETUP_NEXCA BIT(2) 69 - #define AD7746_EXCSETUP_EXCLVL(x) (((x) & 0x3) << 0) 67 + #define AD7746_EXCSETUP_EXCLVL_MASK GENMASK(1, 0) 70 68 71 69 /* Config Register Bit Designations (AD7746_REG_CFG) */ 72 - #define AD7746_CONF_VTFS_SHIFT 6 73 - #define AD7746_CONF_CAPFS_SHIFT 3 74 70 #define AD7746_CONF_VTFS_MASK GENMASK(7, 6) 75 71 #define AD7746_CONF_CAPFS_MASK GENMASK(5, 3) 76 - #define AD7746_CONF_MODE_IDLE (0 << 0) 77 - #define AD7746_CONF_MODE_CONT_CONV (1 << 0) 78 - #define AD7746_CONF_MODE_SINGLE_CONV (2 << 0) 79 - #define AD7746_CONF_MODE_PWRDN (3 << 0) 80 - #define AD7746_CONF_MODE_OFFS_CAL (5 << 0) 81 - #define AD7746_CONF_MODE_GAIN_CAL (6 << 0) 72 + #define AD7746_CONF_MODE_MASK GENMASK(2, 0) 73 + #define AD7746_CONF_MODE_IDLE 0 74 + #define AD7746_CONF_MODE_CONT_CONV 1 75 + #define AD7746_CONF_MODE_SINGLE_CONV 2 76 + #define AD7746_CONF_MODE_PWRDN 3 77 + #define AD7746_CONF_MODE_OFFS_CAL 5 78 + #define AD7746_CONF_MODE_GAIN_CAL 6 82 79 83 80 /* CAPDAC Register Bit Designations (AD7746_REG_CAPDACx) */ 84 81 #define AD7746_CAPDAC_DACEN BIT(7) 85 - #define AD7746_CAPDAC_DACP(x) ((x) & 0x7F) 82 + #define AD7746_CAPDAC_DACP_MASK GENMASK(6, 0) 86 83 87 84 struct ad7746_chip_info { 88 85 struct i2c_client *client; ··· 95 94 u8 vt_setup; 96 95 u8 capdac[2][2]; 97 96 s8 capdac_set; 98 - 99 - union { 100 - __be32 d32; 101 - u8 d8[4]; 102 - } data ____cacheline_aligned; 103 97 }; 104 98 105 99 enum ad7746_chan { ··· 108 112 CIN2_DIFF, 109 113 }; 110 114 115 + struct ad7746_chan_info { 116 + u8 addr; 117 + union { 118 + u8 vtmd; 119 + struct { /* CAP SETUP fields */ 120 + unsigned int cin2 : 1; 121 + unsigned int capdiff : 1; 122 + }; 123 + }; 124 + }; 125 + 126 + static const struct ad7746_chan_info ad7746_chan_info[] = { 127 + [VIN] = { 128 + .addr = AD7746_REG_VT_DATA_HIGH, 129 + .vtmd = AD7746_VTSETUP_VTMD_EXT_VIN, 130 + }, 131 + [VIN_VDD] = { 132 + .addr = AD7746_REG_VT_DATA_HIGH, 133 + .vtmd = AD7746_VTSETUP_VTMD_VDD_MON, 134 + }, 135 + [TEMP_INT] = { 136 + .addr = AD7746_REG_VT_DATA_HIGH, 137 + .vtmd = AD7746_VTSETUP_VTMD_INT_TEMP, 138 + }, 139 + [TEMP_EXT] = { 140 + .addr = AD7746_REG_VT_DATA_HIGH, 141 + .vtmd = AD7746_VTSETUP_VTMD_EXT_TEMP, 142 + }, 143 + [CIN1] = { 144 + .addr = AD7746_REG_CAP_DATA_HIGH, 145 + }, 146 + [CIN1_DIFF] = { 147 + .addr = AD7746_REG_CAP_DATA_HIGH, 148 + .capdiff = 1, 149 + }, 150 + [CIN2] = { 151 + .addr = AD7746_REG_CAP_DATA_HIGH, 152 + .cin2 = 1, 153 + }, 154 + [CIN2_DIFF] = { 155 + .addr = AD7746_REG_CAP_DATA_HIGH, 156 + .cin2 = 1, 157 + .capdiff = 1, 158 + }, 159 + }; 160 + 111 161 static const struct iio_chan_spec ad7746_channels[] = { 112 162 [VIN] = { 113 163 .type = IIO_VOLTAGE, 114 164 .indexed = 1, 115 165 .channel = 0, 116 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 117 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | 118 - BIT(IIO_CHAN_INFO_SAMP_FREQ), 119 - .address = AD7746_REG_VT_DATA_HIGH << 8 | 120 - AD7746_VTSETUP_VTMD_EXT_VIN, 166 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 167 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ), 168 + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 169 + .address = VIN, 121 170 }, 122 171 [VIN_VDD] = { 123 172 .type = IIO_VOLTAGE, 124 173 .indexed = 1, 125 174 .channel = 1, 126 175 .extend_name = "supply", 127 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 128 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | 129 - BIT(IIO_CHAN_INFO_SAMP_FREQ), 130 - .address = AD7746_REG_VT_DATA_HIGH << 8 | 131 - AD7746_VTSETUP_VTMD_VDD_MON, 176 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 177 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ), 178 + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 179 + .address = VIN_VDD, 132 180 }, 133 181 [TEMP_INT] = { 134 182 .type = IIO_TEMP, 135 183 .indexed = 1, 136 184 .channel = 0, 137 - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 138 - .address = AD7746_REG_VT_DATA_HIGH << 8 | 139 - AD7746_VTSETUP_VTMD_INT_TEMP, 185 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 186 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 187 + .address = TEMP_INT, 140 188 }, 141 189 [TEMP_EXT] = { 142 190 .type = IIO_TEMP, 143 191 .indexed = 1, 144 192 .channel = 1, 145 - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 146 - .address = AD7746_REG_VT_DATA_HIGH << 8 | 147 - AD7746_VTSETUP_VTMD_EXT_TEMP, 193 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 194 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 195 + .address = TEMP_EXT, 148 196 }, 149 197 [CIN1] = { 150 198 .type = IIO_CAPACITANCE, ··· 198 158 BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET), 199 159 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) | 200 160 BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ), 201 - .address = AD7746_REG_CAP_DATA_HIGH << 8, 161 + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 162 + .address = CIN1, 202 163 }, 203 164 [CIN1_DIFF] = { 204 165 .type = IIO_CAPACITANCE, ··· 208 167 .channel = 0, 209 168 .channel2 = 2, 210 169 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 211 - BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET), 170 + BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_ZEROPOINT), 212 171 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) | 213 172 BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ), 214 - .address = AD7746_REG_CAP_DATA_HIGH << 8 | 215 - AD7746_CAPSETUP_CAPDIFF 173 + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 174 + .address = CIN1_DIFF, 216 175 }, 217 176 [CIN2] = { 218 177 .type = IIO_CAPACITANCE, ··· 222 181 BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET), 223 182 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) | 224 183 BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ), 225 - .address = AD7746_REG_CAP_DATA_HIGH << 8 | 226 - AD7746_CAPSETUP_CIN2, 184 + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 185 + .address = CIN2, 227 186 }, 228 187 [CIN2_DIFF] = { 229 188 .type = IIO_CAPACITANCE, ··· 232 191 .channel = 1, 233 192 .channel2 = 3, 234 193 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 235 - BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET), 194 + BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_ZEROPOINT), 236 195 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) | 237 196 BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ), 238 - .address = AD7746_REG_CAP_DATA_HIGH << 8 | 239 - AD7746_CAPSETUP_CAPDIFF | AD7746_CAPSETUP_CIN2, 197 + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 198 + .address = CIN2_DIFF, 240 199 } 241 200 }; 242 201 243 202 /* Values are Update Rate (Hz), Conversion Time (ms) + 1*/ 244 203 static const unsigned char ad7746_vt_filter_rate_table[][2] = { 245 - {50, 20 + 1}, {31, 32 + 1}, {16, 62 + 1}, {8, 122 + 1}, 204 + { 50, 20 + 1 }, { 31, 32 + 1 }, { 16, 62 + 1 }, { 8, 122 + 1 }, 246 205 }; 247 206 248 207 static const unsigned char ad7746_cap_filter_rate_table[][2] = { 249 - {91, 11 + 1}, {84, 12 + 1}, {50, 20 + 1}, {26, 38 + 1}, 250 - {16, 62 + 1}, {13, 77 + 1}, {11, 92 + 1}, {9, 110 + 1}, 208 + { 91, 11 + 1 }, { 84, 12 + 1 }, { 50, 20 + 1 }, { 26, 38 + 1 }, 209 + { 16, 62 + 1 }, { 13, 77 + 1 }, { 11, 92 + 1 }, { 9, 110 + 1 }, 251 210 }; 252 211 253 212 static int ad7746_set_capdac(struct ad7746_chip_info *chip, int channel) ··· 272 231 273 232 switch (chan->type) { 274 233 case IIO_CAPACITANCE: 275 - cap_setup = (chan->address & 0xFF) | AD7746_CAPSETUP_CAPEN; 234 + cap_setup = FIELD_PREP(AD7746_CAPSETUP_CIN2, 235 + ad7746_chan_info[chan->address].cin2) | 236 + FIELD_PREP(AD7746_CAPSETUP_CAPDIFF, 237 + ad7746_chan_info[chan->address].capdiff) | 238 + FIELD_PREP(AD7746_CAPSETUP_CAPEN, 1); 276 239 vt_setup = chip->vt_setup & ~AD7746_VTSETUP_VTEN; 277 - idx = (chip->config & AD7746_CONF_CAPFS_MASK) >> 278 - AD7746_CONF_CAPFS_SHIFT; 240 + idx = FIELD_GET(AD7746_CONF_CAPFS_MASK, chip->config); 279 241 delay = ad7746_cap_filter_rate_table[idx][1]; 280 242 281 243 ret = ad7746_set_capdac(chip, chan->channel); ··· 290 246 break; 291 247 case IIO_VOLTAGE: 292 248 case IIO_TEMP: 293 - vt_setup = (chan->address & 0xFF) | AD7746_VTSETUP_VTEN; 249 + vt_setup = FIELD_PREP(AD7746_VTSETUP_VTMD_MASK, 250 + ad7746_chan_info[chan->address].vtmd) | 251 + FIELD_PREP(AD7746_VTSETUP_VTEN, 1); 294 252 cap_setup = chip->cap_setup & ~AD7746_CAPSETUP_CAPEN; 295 - idx = (chip->config & AD7746_CONF_VTFS_MASK) >> 296 - AD7746_CONF_VTFS_SHIFT; 253 + idx = FIELD_GET(AD7746_CONF_VTFS_MASK, chip->config); 297 254 delay = ad7746_cap_filter_rate_table[idx][1]; 298 255 break; 299 256 default: ··· 377 332 return ret; 378 333 379 334 return ad7746_start_calib(dev, attr, buf, len, 380 - AD7746_CONF_MODE_OFFS_CAL); 335 + FIELD_PREP(AD7746_CONF_MODE_MASK, 336 + AD7746_CONF_MODE_OFFS_CAL)); 381 337 } 382 338 383 339 static ssize_t ad7746_start_gain_calib(struct device *dev, ··· 393 347 return ret; 394 348 395 349 return ad7746_start_calib(dev, attr, buf, len, 396 - AD7746_CONF_MODE_GAIN_CAL); 350 + FIELD_PREP(AD7746_CONF_MODE_MASK, 351 + AD7746_CONF_MODE_GAIN_CAL)); 397 352 } 398 353 399 354 static IIO_DEVICE_ATTR(in_capacitance0_calibbias_calibration, ··· 421 374 i = ARRAY_SIZE(ad7746_cap_filter_rate_table) - 1; 422 375 423 376 chip->config &= ~AD7746_CONF_CAPFS_MASK; 424 - chip->config |= i << AD7746_CONF_CAPFS_SHIFT; 377 + chip->config |= FIELD_PREP(AD7746_CONF_CAPFS_MASK, i); 425 378 426 379 return 0; 427 380 } ··· 439 392 i = ARRAY_SIZE(ad7746_vt_filter_rate_table) - 1; 440 393 441 394 chip->config &= ~AD7746_CONF_VTFS_MASK; 442 - chip->config |= i << AD7746_CONF_VTFS_SHIFT; 395 + chip->config |= FIELD_PREP(AD7746_CONF_VTFS_MASK, i); 443 396 444 397 return 0; 445 398 } 446 - 447 - static IIO_CONST_ATTR(in_voltage_sampling_frequency_available, "50 31 16 8"); 448 - static IIO_CONST_ATTR(in_capacitance_sampling_frequency_available, 449 - "91 84 50 26 16 13 11 9"); 450 399 451 400 static struct attribute *ad7746_attributes[] = { 452 401 &iio_dev_attr_in_capacitance0_calibbias_calibration.dev_attr.attr, ··· 450 407 &iio_dev_attr_in_capacitance1_calibscale_calibration.dev_attr.attr, 451 408 &iio_dev_attr_in_capacitance1_calibbias_calibration.dev_attr.attr, 452 409 &iio_dev_attr_in_voltage0_calibscale_calibration.dev_attr.attr, 453 - &iio_const_attr_in_voltage_sampling_frequency_available.dev_attr.attr, 454 - &iio_const_attr_in_capacitance_sampling_frequency_available.dev_attr.attr, 455 410 NULL, 456 411 }; 457 412 ··· 466 425 struct ad7746_chip_info *chip = iio_priv(indio_dev); 467 426 int ret, reg; 468 427 469 - mutex_lock(&chip->lock); 470 - 471 428 switch (mask) { 472 429 case IIO_CHAN_INFO_CALIBSCALE: 473 - if (val != 1) { 474 - ret = -EINVAL; 475 - goto out; 476 - } 430 + if (val != 1) 431 + return -EINVAL; 477 432 478 433 val = (val2 * 1024) / 15625; 479 434 ··· 481 444 reg = AD7746_REG_VOLT_GAINH; 482 445 break; 483 446 default: 484 - ret = -EINVAL; 485 - goto out; 447 + return -EINVAL; 486 448 } 487 449 450 + mutex_lock(&chip->lock); 488 451 ret = i2c_smbus_write_word_swapped(chip->client, reg, val); 452 + mutex_unlock(&chip->lock); 489 453 if (ret < 0) 490 - goto out; 454 + return ret; 491 455 492 - ret = 0; 493 - break; 456 + return 0; 494 457 case IIO_CHAN_INFO_CALIBBIAS: 495 - if (val < 0 || val > 0xFFFF) { 496 - ret = -EINVAL; 497 - goto out; 498 - } 458 + if (val < 0 || val > 0xFFFF) 459 + return -EINVAL; 460 + 461 + mutex_lock(&chip->lock); 499 462 ret = i2c_smbus_write_word_swapped(chip->client, 500 463 AD7746_REG_CAP_OFFH, val); 464 + mutex_unlock(&chip->lock); 501 465 if (ret < 0) 502 - goto out; 466 + return ret; 503 467 504 - ret = 0; 505 - break; 468 + return 0; 506 469 case IIO_CHAN_INFO_OFFSET: 507 - if (val < 0 || val > 43008000) { /* 21pF */ 508 - ret = -EINVAL; 509 - goto out; 510 - } 470 + case IIO_CHAN_INFO_ZEROPOINT: 471 + if (val < 0 || val > 43008000) /* 21pF */ 472 + return -EINVAL; 511 473 512 474 /* 513 475 * CAPDAC Scale = 21pF_typ / 127 ··· 515 479 */ 516 480 517 481 val /= 338646; 518 - 482 + mutex_lock(&chip->lock); 519 483 chip->capdac[chan->channel][chan->differential] = val > 0 ? 520 - AD7746_CAPDAC_DACP(val) | AD7746_CAPDAC_DACEN : 0; 484 + FIELD_PREP(AD7746_CAPDAC_DACP_MASK, val) | AD7746_CAPDAC_DACEN : 0; 521 485 522 486 ret = ad7746_set_capdac(chip, chan->channel); 523 - if (ret < 0) 524 - goto out; 487 + if (ret < 0) { 488 + mutex_unlock(&chip->lock); 489 + return ret; 490 + } 525 491 526 492 chip->capdac_set = chan->channel; 493 + mutex_unlock(&chip->lock); 527 494 528 - ret = 0; 529 - break; 495 + return 0; 530 496 case IIO_CHAN_INFO_SAMP_FREQ: 531 - if (val2) { 532 - ret = -EINVAL; 533 - goto out; 534 - } 497 + if (val2) 498 + return -EINVAL; 535 499 536 500 switch (chan->type) { 537 501 case IIO_CAPACITANCE: 502 + mutex_lock(&chip->lock); 538 503 ret = ad7746_store_cap_filter_rate_setup(chip, val); 539 - break; 504 + mutex_unlock(&chip->lock); 505 + return ret; 540 506 case IIO_VOLTAGE: 507 + mutex_lock(&chip->lock); 541 508 ret = ad7746_store_vt_filter_rate_setup(chip, val); 542 - break; 509 + mutex_unlock(&chip->lock); 510 + return ret; 543 511 default: 544 - ret = -EINVAL; 512 + return -EINVAL; 545 513 } 514 + default: 515 + return -EINVAL; 516 + } 517 + } 518 + 519 + static const int ad7746_v_samp_freq[] = { 50, 31, 16, 8, }; 520 + static const int ad7746_cap_samp_freq[] = { 91, 84, 50, 26, 16, 13, 11, 9, }; 521 + 522 + static int ad7746_read_avail(struct iio_dev *indio_dev, 523 + struct iio_chan_spec const *chan, const int **vals, 524 + int *type, int *length, long mask) 525 + { 526 + if (mask != IIO_CHAN_INFO_SAMP_FREQ) 527 + return -EINVAL; 528 + 529 + switch (chan->type) { 530 + case IIO_VOLTAGE: 531 + *vals = ad7746_v_samp_freq; 532 + *length = ARRAY_SIZE(ad7746_v_samp_freq); 533 + break; 534 + case IIO_CAPACITANCE: 535 + *vals = ad7746_cap_samp_freq; 536 + *length = ARRAY_SIZE(ad7746_cap_samp_freq); 546 537 break; 547 538 default: 548 - ret = -EINVAL; 539 + return -EINVAL; 549 540 } 541 + *type = IIO_VAL_INT; 542 + return IIO_AVAIL_LIST; 543 + } 550 544 551 - out: 552 - mutex_unlock(&chip->lock); 553 - return ret; 545 + static int ad7746_read_channel(struct iio_dev *indio_dev, 546 + struct iio_chan_spec const *chan, 547 + int *val) 548 + { 549 + struct ad7746_chip_info *chip = iio_priv(indio_dev); 550 + int ret, delay; 551 + u8 data[3]; 552 + u8 regval; 553 + 554 + ret = ad7746_select_channel(indio_dev, chan); 555 + if (ret < 0) 556 + return ret; 557 + delay = ret; 558 + 559 + regval = chip->config | FIELD_PREP(AD7746_CONF_MODE_MASK, 560 + AD7746_CONF_MODE_SINGLE_CONV); 561 + ret = i2c_smbus_write_byte_data(chip->client, AD7746_REG_CFG, regval); 562 + if (ret < 0) 563 + return ret; 564 + 565 + msleep(delay); 566 + /* Now read the actual register */ 567 + ret = i2c_smbus_read_i2c_block_data(chip->client, 568 + ad7746_chan_info[chan->address].addr, 569 + sizeof(data), data); 570 + if (ret < 0) 571 + return ret; 572 + 573 + /* 574 + * Offset applied internally becaue the _offset userspace interface is 575 + * needed for the CAP DACs which apply a controllable offset. 576 + */ 577 + *val = get_unaligned_be24(data) - 0x800000; 578 + 579 + return 0; 554 580 } 555 581 556 582 static int ad7746_read_raw(struct iio_dev *indio_dev, ··· 621 523 long mask) 622 524 { 623 525 struct ad7746_chip_info *chip = iio_priv(indio_dev); 624 - int ret, delay, idx; 625 - u8 regval, reg; 626 - 627 - mutex_lock(&chip->lock); 526 + int ret, idx; 527 + u8 reg; 628 528 629 529 switch (mask) { 630 530 case IIO_CHAN_INFO_RAW: 631 - case IIO_CHAN_INFO_PROCESSED: 632 - ret = ad7746_select_channel(indio_dev, chan); 531 + mutex_lock(&chip->lock); 532 + ret = ad7746_read_channel(indio_dev, chan, val); 533 + mutex_unlock(&chip->lock); 633 534 if (ret < 0) 634 - goto out; 635 - delay = ret; 535 + return ret; 636 536 637 - regval = chip->config | AD7746_CONF_MODE_SINGLE_CONV; 638 - ret = i2c_smbus_write_byte_data(chip->client, AD7746_REG_CFG, 639 - regval); 640 - if (ret < 0) 641 - goto out; 642 - 643 - msleep(delay); 644 - /* Now read the actual register */ 645 - 646 - ret = i2c_smbus_read_i2c_block_data(chip->client, 647 - chan->address >> 8, 3, 648 - &chip->data.d8[1]); 649 - 650 - if (ret < 0) 651 - goto out; 652 - 653 - *val = (be32_to_cpu(chip->data.d32) & 0xFFFFFF) - 0x800000; 654 - 655 - switch (chan->type) { 656 - case IIO_TEMP: 657 - /* 658 - * temperature in milli degrees Celsius 659 - * T = ((*val / 2048) - 4096) * 1000 660 - */ 661 - *val = (*val * 125) / 256; 662 - break; 663 - case IIO_VOLTAGE: 664 - if (chan->channel == 1) /* supply_raw*/ 665 - *val = *val * 6; 666 - break; 667 - default: 668 - break; 669 - } 670 - 671 - ret = IIO_VAL_INT; 672 - break; 537 + return IIO_VAL_INT; 673 538 case IIO_CHAN_INFO_CALIBSCALE: 674 539 switch (chan->type) { 675 540 case IIO_CAPACITANCE: ··· 642 581 reg = AD7746_REG_VOLT_GAINH; 643 582 break; 644 583 default: 645 - ret = -EINVAL; 646 - goto out; 584 + return -EINVAL; 647 585 } 648 586 587 + mutex_lock(&chip->lock); 649 588 ret = i2c_smbus_read_word_swapped(chip->client, reg); 589 + mutex_unlock(&chip->lock); 650 590 if (ret < 0) 651 - goto out; 591 + return ret; 652 592 /* 1 + gain_val / 2^16 */ 653 593 *val = 1; 654 594 *val2 = (15625 * ret) / 1024; 655 595 656 - ret = IIO_VAL_INT_PLUS_MICRO; 657 - break; 596 + return IIO_VAL_INT_PLUS_MICRO; 658 597 case IIO_CHAN_INFO_CALIBBIAS: 598 + mutex_lock(&chip->lock); 659 599 ret = i2c_smbus_read_word_swapped(chip->client, 660 600 AD7746_REG_CAP_OFFH); 601 + mutex_unlock(&chip->lock); 661 602 if (ret < 0) 662 - goto out; 603 + return ret; 663 604 *val = ret; 664 605 665 - ret = IIO_VAL_INT; 666 - break; 606 + return IIO_VAL_INT; 667 607 case IIO_CHAN_INFO_OFFSET: 668 - *val = AD7746_CAPDAC_DACP(chip->capdac[chan->channel] 669 - [chan->differential]) * 338646; 608 + case IIO_CHAN_INFO_ZEROPOINT: 609 + *val = FIELD_GET(AD7746_CAPDAC_DACP_MASK, 610 + chip->capdac[chan->channel][chan->differential]) * 338646; 670 611 671 - ret = IIO_VAL_INT; 672 - break; 612 + return IIO_VAL_INT; 673 613 case IIO_CHAN_INFO_SCALE: 674 614 switch (chan->type) { 675 615 case IIO_CAPACITANCE: 676 616 /* 8.192pf / 2^24 */ 677 617 *val = 0; 678 618 *val2 = 488; 679 - ret = IIO_VAL_INT_PLUS_NANO; 680 - break; 619 + return IIO_VAL_INT_PLUS_NANO; 681 620 case IIO_VOLTAGE: 682 621 /* 1170mV / 2^23 */ 683 622 *val = 1170; 623 + if (chan->channel == 1) 624 + *val *= 6; 684 625 *val2 = 23; 685 - ret = IIO_VAL_FRACTIONAL_LOG2; 686 - break; 626 + return IIO_VAL_FRACTIONAL_LOG2; 627 + case IIO_TEMP: 628 + *val = 125; 629 + *val2 = 8; 630 + return IIO_VAL_FRACTIONAL_LOG2; 687 631 default: 688 - ret = -EINVAL; 689 - break; 632 + return -EINVAL; 690 633 } 691 - 692 - break; 693 634 case IIO_CHAN_INFO_SAMP_FREQ: 694 635 switch (chan->type) { 695 636 case IIO_CAPACITANCE: 696 - idx = (chip->config & AD7746_CONF_CAPFS_MASK) >> 697 - AD7746_CONF_CAPFS_SHIFT; 637 + idx = FIELD_GET(AD7746_CONF_CAPFS_MASK, chip->config); 698 638 *val = ad7746_cap_filter_rate_table[idx][0]; 699 - ret = IIO_VAL_INT; 700 - break; 639 + return IIO_VAL_INT; 701 640 case IIO_VOLTAGE: 702 - idx = (chip->config & AD7746_CONF_VTFS_MASK) >> 703 - AD7746_CONF_VTFS_SHIFT; 641 + idx = FIELD_GET(AD7746_CONF_VTFS_MASK, chip->config); 704 642 *val = ad7746_vt_filter_rate_table[idx][0]; 705 - ret = IIO_VAL_INT; 706 - break; 643 + return IIO_VAL_INT; 707 644 default: 708 - ret = -EINVAL; 645 + return -EINVAL; 709 646 } 710 - break; 711 647 default: 712 - ret = -EINVAL; 648 + return -EINVAL; 713 649 } 714 - out: 715 - mutex_unlock(&chip->lock); 716 - return ret; 717 650 } 718 651 719 652 static const struct iio_info ad7746_info = { 720 653 .attrs = &ad7746_attribute_group, 721 654 .read_raw = ad7746_read_raw, 655 + .read_avail = ad7746_read_avail, 722 656 .write_raw = ad7746_write_raw, 723 657 }; 724 658 ··· 730 674 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); 731 675 if (!indio_dev) 732 676 return -ENOMEM; 677 + 733 678 chip = iio_priv(indio_dev); 734 679 mutex_init(&chip->lock); 735 - /* this is only used for device removal purposes */ 736 - i2c_set_clientdata(client, indio_dev); 737 680 738 681 chip->client = client; 739 682 chip->capdac_set = -1; ··· 765 710 if (!ret) { 766 711 switch (vdd_permille) { 767 712 case 125: 768 - regval |= AD7746_EXCSETUP_EXCLVL(0); 713 + regval |= FIELD_PREP(AD7746_EXCSETUP_EXCLVL_MASK, 0); 769 714 break; 770 715 case 250: 771 - regval |= AD7746_EXCSETUP_EXCLVL(1); 716 + regval |= FIELD_PREP(AD7746_EXCSETUP_EXCLVL_MASK, 1); 772 717 break; 773 718 case 375: 774 - regval |= AD7746_EXCSETUP_EXCLVL(2); 719 + regval |= FIELD_PREP(AD7746_EXCSETUP_EXCLVL_MASK, 2); 775 720 break; 776 721 case 500: 777 - regval |= AD7746_EXCSETUP_EXCLVL(3); 722 + regval |= FIELD_PREP(AD7746_EXCSETUP_EXCLVL_MASK, 3); 778 723 break; 779 724 default: 780 725 break; 781 726 } 782 727 } 783 728 784 - ret = i2c_smbus_write_byte_data(chip->client, 785 - AD7746_REG_EXC_SETUP, regval); 729 + ret = i2c_smbus_write_byte_data(chip->client, AD7746_REG_EXC_SETUP, 730 + regval); 786 731 if (ret < 0) 787 732 return ret; 788 733 ··· 795 740 { "ad7747", 7747 }, 796 741 {} 797 742 }; 798 - 799 743 MODULE_DEVICE_TABLE(i2c, ad7746_id); 800 744 801 745 static const struct of_device_id ad7746_of_match[] = { ··· 803 749 { .compatible = "adi,ad7747" }, 804 750 { }, 805 751 }; 806 - 807 752 MODULE_DEVICE_TABLE(of, ad7746_of_match); 808 753 809 754 static struct i2c_driver ad7746_driver = {
+2 -2
drivers/staging/iio/frequency/ad9832.c
··· 112 112 * transfer buffers to live in their own cache lines. 113 113 */ 114 114 union { 115 - __be16 freq_data[4]____cacheline_aligned; 115 + __be16 freq_data[4]; 116 116 __be16 phase_data[2]; 117 117 __be16 data; 118 - }; 118 + } __aligned(IIO_DMA_MINALIGN); 119 119 }; 120 120 121 121 static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout)
+1 -1
drivers/staging/iio/frequency/ad9834.c
··· 83 83 * DMA (thus cache coherency maintenance) requires the 84 84 * transfer buffers to live in their own cache lines. 85 85 */ 86 - __be16 data ____cacheline_aligned; 86 + __be16 data __aligned(IIO_DMA_MINALIGN); 87 87 __be16 freq_data[2]; 88 88 }; 89 89
+1 -1
drivers/staging/iio/meter/ade7854.h
··· 162 162 int bits); 163 163 int irq; 164 164 struct mutex buf_lock; 165 - u8 tx[ADE7854_MAX_TX] ____cacheline_aligned; 165 + u8 tx[ADE7854_MAX_TX] __aligned(IIO_DMA_MINALIGN); 166 166 u8 rx[ADE7854_MAX_RX]; 167 167 168 168 };
+2 -2
drivers/staging/iio/resolver/ad2s1210.c
··· 94 94 bool hysteresis; 95 95 u8 resolution; 96 96 enum ad2s1210_mode mode; 97 - u8 rx[2] ____cacheline_aligned; 98 - u8 tx[2] ____cacheline_aligned; 97 + u8 rx[2] __aligned(IIO_DMA_MINALIGN); 98 + u8 tx[2]; 99 99 }; 100 100 101 101 static const int ad2s1210_mode_vals[4][2] = {
+2 -1
drivers/thermal/qcom/qcom-spmi-adc-tm5.c
··· 830 830 } 831 831 channel->adc_channel = args.args[0]; 832 832 833 - channel->iio = devm_of_iio_channel_get_by_name(adc_tm->dev, node, NULL); 833 + channel->iio = devm_fwnode_iio_channel_get_by_name(adc_tm->dev, 834 + of_fwnode_handle(node), NULL); 834 835 if (IS_ERR(channel->iio)) { 835 836 ret = PTR_ERR(channel->iio); 836 837 if (ret != -EPROBE_DEFER)
+3
include/dt-bindings/iio/adc/at91-sama5d2_adc.h
··· 13 13 /* pressure channel index */ 14 14 #define AT91_SAMA5D2_ADC_P_CHANNEL 26 15 15 16 + /* SAMA7G5 Temperature sensor channel index. */ 17 + #define AT91_SAMA7G5_ADC_TEMP_CHANNEL 31 18 + 16 19 #endif
+11 -17
include/linux/iio/consumer.h
··· 13 13 struct iio_dev; 14 14 struct iio_chan_spec; 15 15 struct device; 16 - struct device_node; 16 + struct fwnode_handle; 17 17 18 18 /** 19 19 * struct iio_channel - everything needed for a consumer to use a channel ··· 99 99 struct iio_channel *devm_iio_channel_get_all(struct device *dev); 100 100 101 101 /** 102 - * of_iio_channel_get_by_name() - get description of all that is needed to access channel. 103 - * @np: Pointer to consumer device tree node 102 + * fwnode_iio_channel_get_by_name() - get description of all that is needed to access channel. 103 + * @fwnode: Pointer to consumer Firmware node 104 104 * @consumer_channel: Unique name to identify the channel on the consumer 105 105 * side. This typically describes the channels use within 106 106 * the consumer. E.g. 'battery_voltage' 107 107 */ 108 - #ifdef CONFIG_OF 109 - struct iio_channel *of_iio_channel_get_by_name(struct device_node *np, const char *name); 110 - #else 111 - static inline struct iio_channel * 112 - of_iio_channel_get_by_name(struct device_node *np, const char *name) 113 - { 114 - return NULL; 115 - } 116 - #endif 108 + struct iio_channel *fwnode_iio_channel_get_by_name(struct fwnode_handle *fwnode, 109 + const char *name); 117 110 118 111 /** 119 - * devm_of_iio_channel_get_by_name() - Resource managed version of of_iio_channel_get_by_name(). 112 + * devm_fwnode_iio_channel_get_by_name() - Resource managed version of 113 + * fwnode_iio_channel_get_by_name(). 120 114 * @dev: Pointer to consumer device. 121 - * @np: Pointer to consumer device tree node 115 + * @fwnode: Pointer to consumer Firmware node 122 116 * @consumer_channel: Unique name to identify the channel on the consumer 123 117 * side. This typically describes the channels use within 124 118 * the consumer. E.g. 'battery_voltage' ··· 123 129 * The allocated iio channel is automatically released when the device is 124 130 * unbound. 125 131 */ 126 - struct iio_channel *devm_of_iio_channel_get_by_name(struct device *dev, 127 - struct device_node *np, 128 - const char *consumer_channel); 132 + struct iio_channel *devm_fwnode_iio_channel_get_by_name(struct device *dev, 133 + struct fwnode_handle *fwnode, 134 + const char *consumer_channel); 129 135 130 136 struct iio_cb_buffer; 131 137 /**
+2
include/linux/iio/iio-opaque.h
··· 11 11 * checked by device drivers but should be considered 12 12 * read-only as this is a core internal bit 13 13 * @driver_module: used to make it harder to undercut users 14 + * @mlock_key: lockdep class for iio_dev lock 14 15 * @info_exist_lock: lock to prevent use during removal 15 16 * @trig_readonly: mark the current trigger immutable 16 17 * @event_interface: event chrdevs associated with interrupt lines ··· 43 42 int currentmode; 44 43 int id; 45 44 struct module *driver_module; 45 + struct lock_class_key mlock_key; 46 46 struct mutex info_exist_lock; 47 47 bool trig_readonly; 48 48 struct iio_event_interface *event_interface;
+5 -3
include/linux/iio/iio.h
··· 17 17 * Currently assumes nano seconds. 18 18 */ 19 19 20 - struct of_phandle_args; 20 + struct fwnode_reference_args; 21 21 22 22 enum iio_shared_by { 23 23 IIO_SEPARATE, ··· 429 429 * provide a custom of_xlate function that reads the 430 430 * *args* and returns the appropriate index in registered 431 431 * IIO channels array. 432 + * @fwnode_xlate: fwnode based function pointer to obtain channel specifier index. 433 + * Functionally the same as @of_xlate. 432 434 * @hwfifo_set_watermark: function pointer to set the current hardware 433 435 * fifo watermark level; see hwfifo_* entries in 434 436 * Documentation/ABI/testing/sysfs-bus-iio for details on ··· 510 508 int (*debugfs_reg_access)(struct iio_dev *indio_dev, 511 509 unsigned reg, unsigned writeval, 512 510 unsigned *readval); 513 - int (*of_xlate)(struct iio_dev *indio_dev, 514 - const struct of_phandle_args *iiospec); 511 + int (*fwnode_xlate)(struct iio_dev *indio_dev, 512 + const struct fwnode_reference_args *iiospec); 515 513 int (*hwfifo_set_watermark)(struct iio_dev *indio_dev, unsigned val); 516 514 int (*hwfifo_flush_to_buffer)(struct iio_dev *indio_dev, 517 515 unsigned count);
+3
include/linux/iio/types.h
··· 17 17 IIO_EV_INFO_HIGH_PASS_FILTER_3DB, 18 18 IIO_EV_INFO_LOW_PASS_FILTER_3DB, 19 19 IIO_EV_INFO_TIMEOUT, 20 + IIO_EV_INFO_RESET_TIMEOUT, 21 + IIO_EV_INFO_TAP2_MIN_DELAY, 20 22 }; 21 23 22 24 #define IIO_VAL_INT 1 ··· 65 63 IIO_CHAN_INFO_OVERSAMPLING_RATIO, 66 64 IIO_CHAN_INFO_THERMOCOUPLE_TYPE, 67 65 IIO_CHAN_INFO_CALIBAMBIENT, 66 + IIO_CHAN_INFO_ZEROPOINT, 68 67 }; 69 68 70 69 #endif /* _IIO_TYPES_H_ */
+5
include/linux/string_helpers.h
··· 126 126 return v ? "enabled" : "disabled"; 127 127 } 128 128 129 + static inline const char *str_read_write(bool v) 130 + { 131 + return v ? "read" : "write"; 132 + } 133 + 129 134 #endif
+3
include/linux/units.h
··· 20 20 #define PICO 1000000000000ULL 21 21 #define FEMTO 1000000000000000ULL 22 22 23 + #define NANOHZ_PER_HZ 1000000000UL 24 + #define MICROHZ_PER_HZ 1000000UL 25 + #define MILLIHZ_PER_HZ 1000UL 23 26 #define HZ_PER_KHZ 1000UL 24 27 #define KHZ_PER_MHZ 1000UL 25 28 #define HZ_PER_MHZ 1000000UL
+3
include/uapi/linux/iio/types.h
··· 105 105 IIO_EV_TYPE_MAG_ADAPTIVE, 106 106 IIO_EV_TYPE_CHANGE, 107 107 IIO_EV_TYPE_MAG_REFERENCED, 108 + IIO_EV_TYPE_GESTURE, 108 109 }; 109 110 110 111 enum iio_event_direction { ··· 113 112 IIO_EV_DIR_RISING, 114 113 IIO_EV_DIR_FALLING, 115 114 IIO_EV_DIR_NONE, 115 + IIO_EV_DIR_SINGLETAP, 116 + IIO_EV_DIR_DOUBLETAP, 116 117 }; 117 118 118 119 #endif /* _UAPI_IIO_TYPES_H_ */
+7 -1
tools/iio/iio_event_monitor.c
··· 69 69 [IIO_EV_TYPE_MAG_ADAPTIVE] = "mag_adaptive", 70 70 [IIO_EV_TYPE_CHANGE] = "change", 71 71 [IIO_EV_TYPE_MAG_REFERENCED] = "mag_referenced", 72 + [IIO_EV_TYPE_GESTURE] = "gesture", 72 73 }; 73 74 74 75 static const char * const iio_ev_dir_text[] = { 75 76 [IIO_EV_DIR_EITHER] = "either", 76 77 [IIO_EV_DIR_RISING] = "rising", 77 - [IIO_EV_DIR_FALLING] = "falling" 78 + [IIO_EV_DIR_FALLING] = "falling", 79 + [IIO_EV_DIR_SINGLETAP] = "singletap", 80 + [IIO_EV_DIR_DOUBLETAP] = "doubletap", 78 81 }; 79 82 80 83 static const char * const iio_modifier_names[] = { ··· 230 227 case IIO_EV_TYPE_THRESH_ADAPTIVE: 231 228 case IIO_EV_TYPE_MAG_ADAPTIVE: 232 229 case IIO_EV_TYPE_CHANGE: 230 + case IIO_EV_TYPE_GESTURE: 233 231 break; 234 232 default: 235 233 return false; ··· 240 236 case IIO_EV_DIR_EITHER: 241 237 case IIO_EV_DIR_RISING: 242 238 case IIO_EV_DIR_FALLING: 239 + case IIO_EV_DIR_SINGLETAP: 240 + case IIO_EV_DIR_DOUBLETAP: 243 241 case IIO_EV_DIR_NONE: 244 242 break; 245 243 default: