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

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

Jonathan writes:

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

Changes in take2:
- Additional patch to drop the accidentally added empty file.
- Tidy up of a duplicate include.

Two merges of other trees.

6.12-rc2:
To pull in the move of unaligned.h from include/asm to include/linux
This was to resolve issues in linux-next.

pwm/duty_offset-for6.13-rc1@
PWM infrastructure that is use di the AD7625 ADC driver.

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

adi,ad7173
- Add support for the AD4113 8 channel ADC.
adi,ad7606
- Add support for the AD7606C-16 and AD7606C-18 which have higher precision
and support bipolar and differential channels. A lot of driver
rework was needed to add the additional flexibility needed to support
these parts.
adi,ad7625
- New driver supporting AD7625, AD7626, AD7960 and AD7961 LVDS connected
ADCs. Interface uses a combination of a PWM control and an IIO backend
(currently a custom FPGA IP).
adi,ad8460
- New driver for the ad8460 Waveform DAC. This high speed device is
driven by a custom IP via a DMAEngine buffer.
bosch,bmi270
- New driver for this 6-axis IMU. A later patch adds SPI support.
gehc,pmc-adc
- New driver for this GE Healthcare ADC 16-channel 16 bit ADC.
invensense,mpu6050
- Add support for IAM-20680HT and IAM-20680HP variants of the IAM-20680
IMU that have better specifications in various ways including larger
FIFO sizes.
vishay,vl6030
- Support the veml7700, a stripped down veml6030 ambient light sensor.
- Support the veml6035 ambient light sensor.

Features
========

liteon,ltr390
- Allow configuration of sampling frequency
- Support suspend and resume
- Add interrupt support including threshold events + control over
event reporting persistence.
st,vl53l0x
- Add support for continuous mode via IIO buffer support and a dataready
trigger.
ti,tmp0006
- Add triggered buffer support using data ready interrupt.
vishay,vl6030
- Add regulator control support.
vishay,vl6070
- Add regulator control support.
vishay,vl6180
- Allow configuration of waiting between continuous samples.
- Use the interrupt, if available, for single shot captures
- Support continuous mode via the IIO triggered buffer interfaces.

Cleanups and minor fixes
========================

tools/event monitor
- Free dev_dir_name.
treewide
- Introduce aligned_s64 type for timestamps to replace
s64 __aligned(8). Initial use in a few drivers - many others to follow.
- Use dev_get_platform_data() instead of open-coding the access.
- InvenSense email address and maintainer updates to reflect
move to the tdk domain after acquisition.
- Switch platform drivers from remove_new() back to remove() now all
rework this was enabling is done.
- More use of device_for_each_child_node_scoped() to remove need for manual
caling of fwnode_handle_put() in early exits from the loop.
- Use IIO_MAP() macro to replace some open-coded versions.
- Constify struct iio_map arrays.
- Use irq_get_trigger_type(irq) rather than
irqd_get_trigger_type(irq_get_irq_data(irq);
core
- unsigned to unsigned int.
adi,ad3552r
- Fix to low a limit on max SPI clock speed. No rush to upstream this
one as the binding that uses the higher speed will merge via this
tree once ready.
adi,ad5770r
- Use get_unaligned_le16() instead of open-coding. Note this caused
a merge issue in linux-next as unaligned.h has moved.
adi,ad7606
- Use read_avail() callback to handle the various _available attributes.
- Wrap up all data related to channel scaling into a single structure as
the use of this gets more complex for the -16 and -18 parts.
adi,adf4371
- Use chip_info structures and spi_get_device_match_data()
- Drop spi_set_drvdata() as unused.
- Reduce scope of struct clock as only touched in probe().
- Use dev_err_probe() where appropriate.
adi,axi-dac
- Improve register naming to make field and register association clearer.
- Fix a wrong register bit.
amlogic,meson8-saradc
- Allow the meson8-saradc to have the amlogic,hhi-sysctrl property.
bosch,bmp280
- Use u8 for the DMA buffer to avoid implication of other types given it
can contain be24 data.
- Use unsigned types to store raw values to make it clear they cannot be
negative.
- Drop unnecessary check for errors after IIR filter update.
- Support soft reset to get device to know state on driver load.
- Use bulk reads to retrieve the humidity calibration data.
dynaimage,al3010
- Make sure to powerdown device in error paths.
invensense,icm42600
- Add missing i2c_device-id tables.
kionix,kmx61
- Drop ACPI IDs that are not associated with valid ACPI vendor IDs
and for which there is no evidence they are in use in real devices.
liteon,ltrf261a
- Document a bad compatible that we are supporting because it is in
the wild in the Valve Steam Deck via ACPI PRP0001.
maxim,max1363
- Use get_unaligned_be16() instead of open-coding. Note this caused
a merge issue in linux-next as unaligned.h has moved.
mediatek,mt6360
- Use get_unaligned_be16() instead of open-coding. Note this caused
a merge issue in linux-next as unaligned.h has moved.
microchip,pac1921
- Drop various unnecessary type casts that were suggested by
Wconversion compiler warnings which we do not use in IIO.
Remove them because they hurt readability in cases where it is clear
not overflow can occur.
rohm,rpr0521
- Use iio_poll_func_store_time() rather than open-coding a similar solution.
semtech,sx9324
- Make sx_common_get_raw_register() local to the only code that uses it.
- Drop unnecessary acpi.h include.
st,vl53l0x
- Check the part ID register and print an info message if it is not what
is expected.
vishay,veml6030
- Fix DT binding file name to include vishay
- Use regmap_set_bits() for case where all bits are set.
- Use dev_err_probe() where appropriate.
- Add missing delay after powering up in resume path.
- Drop a processed accessor for the white channel as there is no public
information to allow a specific scale to be established.
- Use read_avail() to replace explicit custom _available attributes.
vishay,veml6070
- Use guard() to allow early returns.
- Add a devm callback to unregister the i2c device.
- Use devm_iio_device_register() to simplify removal code.

Various other minor improvements not called out explicitly.

* tag 'iio-for-6.13a-take2' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (161 commits)
iio: imu: bmi270: Remove duplicated include in bmi270_i2c.c
iio: adc: ad7606: Drop spurious empty file.
iio: light: rpr0521: Use generic iio_pollfunc_store_time()
iio: light: vl6180: Add support for Continuous Mode
iio: light: vl6180: Added Interrupt support for single shot access
iio: light: vl6180: Add configurable inter-measurement period support
MAINTAINERS: add entry for VEML6030 ambient light sensor driver
iio: light: veml6030: add support for veml7700
dt-bindings: iio: light: veml6030: add veml7700
iio: light: veml6035: fix read_avail in no_irq case for veml6035
iio: dac: adi-axi-dac: update register names
iio: dac: adi-axi-dac: fix wrong register bitfield
docs: iio: new docs for ad7625 driver
iio: adc: ad7625: add driver
dt-bindings: iio: adc: add AD762x/AD796x ADCs
iio: Convert unsigned to unsigned int
iio: pressure: bmp280: Fix uninitialized variable
iio: Switch back to struct platform_driver::remove()
iio: imu: bmi323: remove redundant register definition
iio: frequency: adf4371: make use of dev_err_probe()
...

+7168 -1427
+4
Documentation/devicetree/bindings/iio/adc/adc.yaml
··· 37 37 to both the positive and negative inputs of a differential ADC. 38 38 The first value specifies the positive input pin, the second 39 39 specifies the negative input pin. 40 + There are also some ADCs, where the differential channel has dedicated 41 + positive and negative inputs which can be used to measure differential 42 + voltage levels. For those setups, this property can be configured with 43 + the 'reg' property for both inputs (i.e. diff-channels = <reg reg>). 40 44 41 45 single-channel: 42 46 $ref: /schemas/types.yaml#/definitions/uint32
+3
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml
··· 28 28 Datasheets for supported chips: 29 29 https://www.analog.com/media/en/technical-documentation/data-sheets/AD4111.pdf 30 30 https://www.analog.com/media/en/technical-documentation/data-sheets/AD4112.pdf 31 + <AD4113: not released yet> 31 32 https://www.analog.com/media/en/technical-documentation/data-sheets/AD4114.pdf 32 33 https://www.analog.com/media/en/technical-documentation/data-sheets/AD4115.pdf 33 34 https://www.analog.com/media/en/technical-documentation/data-sheets/AD4116.pdf ··· 45 44 enum: 46 45 - adi,ad4111 47 46 - adi,ad4112 47 + - adi,ad4113 48 48 - adi,ad4114 49 49 - adi,ad4115 50 50 - adi,ad4116 ··· 333 331 enum: 334 332 - adi,ad4111 335 333 - adi,ad4112 334 + - adi,ad4113 336 335 - adi,ad4114 337 336 - adi,ad4115 338 337 - adi,ad4116
+120
Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
··· 14 14 https://www.analog.com/media/en/technical-documentation/data-sheets/AD7605-4.pdf 15 15 https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606_7606-6_7606-4.pdf 16 16 https://www.analog.com/media/en/technical-documentation/data-sheets/AD7606B.pdf 17 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606c-16.pdf 18 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606c-18.pdf 17 19 https://www.analog.com/media/en/technical-documentation/data-sheets/AD7616.pdf 18 20 19 21 properties: ··· 26 24 - adi,ad7606-6 27 25 - adi,ad7606-8 # Referred to as AD7606 (without -8) in the datasheet 28 26 - adi,ad7606b 27 + - adi,ad7606c-16 28 + - adi,ad7606c-18 29 29 - adi,ad7616 30 30 31 31 reg: 32 32 maxItems: 1 33 + 34 + "#address-cells": 35 + const: 1 36 + 37 + "#size-cells": 38 + const: 0 33 39 34 40 spi-cpha: true 35 41 ··· 124 114 assumed that the pins are hardwired to VDD. 125 115 type: boolean 126 116 117 + patternProperties: 118 + "^channel@[1-8]$": 119 + type: object 120 + $ref: adc.yaml 121 + unevaluatedProperties: false 122 + 123 + properties: 124 + reg: 125 + description: 126 + The channel number, as specified in the datasheet (from 1 to 8). 127 + minimum: 1 128 + maximum: 8 129 + 130 + diff-channels: 131 + description: 132 + Each channel can be configured as a bipolar differential channel. 133 + The ADC uses the same positive and negative inputs for this. 134 + This property must be specified as 'reg' (or the channel number) for 135 + both positive and negative inputs (i.e. diff-channels = <reg reg>). 136 + Since the configuration is bipolar differential, the 'bipolar' 137 + property is required. 138 + items: 139 + minimum: 1 140 + maximum: 8 141 + 142 + bipolar: 143 + description: 144 + The ADC channels can be configured as 145 + * Bipolar single-ended 146 + * Unipolar single-ended 147 + * Bipolar differential 148 + Therefore in the DT, if no channel node is specified, it is considered 149 + 'unipolar single-ended'. So for the other configurations the 'bipolar' 150 + property must be specified. If 'diff-channels' is specified, it is 151 + considered a bipolar differential channel. Otherwise it is bipolar 152 + single-ended. 153 + 154 + required: 155 + - reg 156 + - bipolar 157 + 127 158 required: 128 159 - compatible 129 160 - reg ··· 221 170 adi,conversion-start-gpios: 222 171 maxItems: 1 223 172 173 + - if: 174 + not: 175 + required: 176 + - adi,sw-mode 177 + then: 178 + patternProperties: 179 + "^channel@[1-8]$": false 180 + 181 + - if: 182 + not: 183 + properties: 184 + compatible: 185 + enum: 186 + - adi,ad7606c-16 187 + - adi,ad7606c-18 188 + then: 189 + patternProperties: 190 + "^channel@[1-8]$": false 191 + 224 192 unevaluatedProperties: false 225 193 226 194 examples: ··· 270 200 <&gpio 23 GPIO_ACTIVE_HIGH>, 271 201 <&gpio 26 GPIO_ACTIVE_HIGH>; 272 202 standby-gpios = <&gpio 24 GPIO_ACTIVE_LOW>; 203 + }; 204 + }; 205 + - | 206 + #include <dt-bindings/gpio/gpio.h> 207 + #include <dt-bindings/interrupt-controller/irq.h> 208 + spi { 209 + #address-cells = <1>; 210 + #size-cells = <0>; 211 + 212 + adc@0 { 213 + compatible = "adi,ad7606c-18"; 214 + reg = <0>; 215 + 216 + #address-cells = <1>; 217 + #size-cells = <0>; 218 + 219 + spi-max-frequency = <1000000>; 220 + spi-cpol; 221 + spi-cpha; 222 + 223 + avcc-supply = <&adc_vref>; 224 + vdrive-supply = <&vdd_supply>; 225 + 226 + interrupts = <25 IRQ_TYPE_EDGE_FALLING>; 227 + interrupt-parent = <&gpio>; 228 + 229 + adi,conversion-start-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>; 230 + reset-gpios = <&gpio 27 GPIO_ACTIVE_HIGH>; 231 + adi,first-data-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>; 232 + standby-gpios = <&gpio 24 GPIO_ACTIVE_LOW>; 233 + 234 + adi,sw-mode; 235 + 236 + channel@1 { 237 + reg = <1>; 238 + diff-channels = <1 1>; 239 + bipolar; 240 + }; 241 + 242 + channel@3 { 243 + reg = <3>; 244 + bipolar; 245 + }; 246 + 247 + channel@8 { 248 + reg = <8>; 249 + diff-channels = <8 8>; 250 + bipolar; 251 + }; 252 + 273 253 }; 274 254 }; 275 255 ...
+176
Documentation/devicetree/bindings/iio/adc/adi,ad7625.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/adc/adi,ad7625.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices Fast PulSAR Analog to Digital Converters 8 + 9 + maintainers: 10 + - Michael Hennerich <Michael.Hennerich@analog.com> 11 + - Nuno Sá <nuno.sa@analog.com> 12 + 13 + description: | 14 + A family of single channel differential analog to digital converters. 15 + 16 + * https://www.analog.com/en/products/ad7625.html 17 + * https://www.analog.com/en/products/ad7626.html 18 + * https://www.analog.com/en/products/ad7960.html 19 + * https://www.analog.com/en/products/ad7961.html 20 + 21 + properties: 22 + compatible: 23 + enum: 24 + - adi,ad7625 25 + - adi,ad7626 26 + - adi,ad7960 27 + - adi,ad7961 28 + 29 + vdd1-supply: true 30 + vdd2-supply: true 31 + vio-supply: true 32 + 33 + ref-supply: 34 + description: 35 + Voltage regulator for the external reference voltage (REF). 36 + 37 + refin-supply: 38 + description: 39 + Voltage regulator for the reference buffer input (REFIN). 40 + 41 + clocks: 42 + description: 43 + The clock connected to the CLK pins, gated by the clk_gate PWM. 44 + maxItems: 1 45 + 46 + pwms: 47 + items: 48 + - description: PWM connected to the CNV input on the ADC. 49 + - description: PWM that gates the clock connected to the ADC's CLK input. 50 + 51 + pwm-names: 52 + items: 53 + - const: cnv 54 + - const: clk_gate 55 + 56 + io-backends: 57 + description: 58 + The AXI ADC IP block connected to the D+/- and DCO+/- lines of the 59 + ADC. An example backend can be found at 60 + http://analogdevicesinc.github.io/hdl/projects/pulsar_lvds/index.html. 61 + maxItems: 1 62 + 63 + adi,no-dco: 64 + $ref: /schemas/types.yaml#/definitions/flag 65 + description: 66 + Indicates the wiring of the DCO+/- lines. If true, then they are 67 + grounded and the device is in self-clocked mode. If this is not 68 + present, then the device is in echoed clock mode. 69 + 70 + adi,en0-always-on: 71 + $ref: /schemas/types.yaml#/definitions/flag 72 + description: 73 + Indicates if EN0 is hard-wired to the high state. If neither this 74 + nor en0-gpios are present, then EN0 is hard-wired low. 75 + 76 + adi,en1-always-on: 77 + $ref: /schemas/types.yaml#/definitions/flag 78 + description: 79 + Indicates if EN1 is hard-wired to the high state. If neither this 80 + nor en1-gpios are present, then EN1 is hard-wired low. 81 + 82 + adi,en2-always-on: 83 + $ref: /schemas/types.yaml#/definitions/flag 84 + description: 85 + Indicates if EN2 is hard-wired to the high state. If neither this 86 + nor en2-gpios are present, then EN2 is hard-wired low. 87 + 88 + adi,en3-always-on: 89 + $ref: /schemas/types.yaml#/definitions/flag 90 + description: 91 + Indicates if EN3 is hard-wired to the high state. If neither this 92 + nor en3-gpios are present, then EN3 is hard-wired low. 93 + 94 + en0-gpios: 95 + description: 96 + Configurable EN0 pin. 97 + 98 + en1-gpios: 99 + description: 100 + Configurable EN1 pin. 101 + 102 + en2-gpios: 103 + description: 104 + Configurable EN2 pin. 105 + 106 + en3-gpios: 107 + description: 108 + Configurable EN3 pin. 109 + 110 + required: 111 + - compatible 112 + - vdd1-supply 113 + - vdd2-supply 114 + - vio-supply 115 + - clocks 116 + - pwms 117 + - pwm-names 118 + - io-backends 119 + 120 + allOf: 121 + - if: 122 + required: 123 + - ref-supply 124 + then: 125 + properties: 126 + refin-supply: false 127 + - if: 128 + required: 129 + - refin-supply 130 + then: 131 + properties: 132 + ref-supply: false 133 + - if: 134 + properties: 135 + compatible: 136 + contains: 137 + enum: 138 + - adi,ad7625 139 + - adi,ad7626 140 + then: 141 + properties: 142 + en2-gpios: false 143 + en3-gpios: false 144 + adi,en2-always-on: false 145 + adi,en3-always-on: false 146 + 147 + - if: 148 + properties: 149 + compatible: 150 + contains: 151 + enum: 152 + - adi,ad7960 153 + - adi,ad7961 154 + then: 155 + # ad796x parts must have one of the two supplies 156 + oneOf: 157 + - required: [ref-supply] 158 + - required: [refin-supply] 159 + 160 + additionalProperties: false 161 + 162 + examples: 163 + - | 164 + #include <dt-bindings/gpio/gpio.h> 165 + adc { 166 + compatible = "adi,ad7625"; 167 + vdd1-supply = <&supply_5V>; 168 + vdd2-supply = <&supply_2_5V>; 169 + vio-supply = <&supply_2_5V>; 170 + io-backends = <&axi_adc>; 171 + clocks = <&ref_clk>; 172 + pwms = <&axi_pwm_gen 0 0>, <&axi_pwm_gen 1 0>; 173 + pwm-names = "cnv", "clk_gate"; 174 + en0-gpios = <&gpio0 86 GPIO_ACTIVE_HIGH>; 175 + en1-gpios = <&gpio0 87 GPIO_ACTIVE_HIGH>; 176 + };
+1
Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.yaml
··· 98 98 compatible: 99 99 contains: 100 100 enum: 101 + - amlogic,meson8-saradc 101 102 - amlogic,meson8b-saradc 102 103 - amlogic,meson8m2-saradc 103 104 then:
+86
Documentation/devicetree/bindings/iio/adc/gehc,pmc-adc.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/gehc,pmc-adc.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: GE HealthCare PMC Analog to Digital Converter (ADC) 8 + 9 + maintainers: 10 + - Herve Codina <herve.codina@bootlin.com> 11 + 12 + description: 13 + The GE HealthCare PMC ADC is a 16-Channel (voltage and current), 16-Bit ADC 14 + with an I2C Interface. 15 + 16 + properties: 17 + compatible: 18 + const: gehc,pmc-adc 19 + 20 + reg: 21 + maxItems: 1 22 + 23 + vdd-supply: 24 + description: 25 + Regulator for the VDD power supply. 26 + 27 + vdda-supply: 28 + description: 29 + Regulator for the VDD analog (VDDA) power supply. 30 + 31 + vddio-supply: 32 + description: 33 + Regulator for the VDD IO (VDDIO) power supply. 34 + 35 + vref-supply: 36 + description: 37 + Regulator for the voltage reference power supply. 38 + 39 + clocks: 40 + maxItems: 1 41 + description: 42 + The component uses an external oscillator (osc) if an external oscillator 43 + is connected to its clock pins. Otherwise, it uses an internal reference 44 + clock. 45 + 46 + clock-names: 47 + items: 48 + - const: osc 49 + 50 + "#io-channel-cells": 51 + const: 2 52 + description: | 53 + The first cell is the channel type (dt-bindings/iio/adc/gehc,pmc-adc.h 54 + defines these values): 55 + - 0: voltage 56 + - 1: current 57 + The second cell is the channel number from 0 to 15. 58 + 59 + required: 60 + - compatible 61 + - reg 62 + - vdd-supply 63 + - vdda-supply 64 + - vddio-supply 65 + - vref-supply 66 + - '#io-channel-cells' 67 + 68 + additionalProperties: false 69 + 70 + examples: 71 + - | 72 + i2c { 73 + #address-cells = <1>; 74 + #size-cells = <0>; 75 + 76 + adc@14 { 77 + compatible = "gehc,pmc-adc"; 78 + reg = <0x14>; 79 + vdd-supply = <&reg_vdd>; 80 + vdda-supply = <&reg_vdda>; 81 + vddio-supply = <&reg_vddio>; 82 + vref-supply = <&reg_vref>; 83 + #io-channel-cells = <2>; 84 + }; 85 + }; 86 + ...
+1 -1
Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml
··· 30 30 maxItems: 1 31 31 32 32 spi-max-frequency: 33 - maximum: 30000000 33 + maximum: 66000000 34 34 35 35 reset-gpios: 36 36 maxItems: 1
+164
Documentation/devicetree/bindings/iio/dac/adi,ad8460.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + # Copyright 2024 Analog Devices Inc. 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/iio/dac/adi,ad8460.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: Analog Devices AD8460 DAC 9 + 10 + maintainers: 11 + - Mariel Tinaco <mariel.tinaco@analog.com> 12 + 13 + description: | 14 + Analog Devices AD8460 110 V High Voltage, 1 A High Current, 15 + Arbitrary Waveform Generator with Integrated 14-Bit High Speed DAC 16 + https://www.analog.com/media/en/technical-documentation/data-sheets/ad8460.pdf 17 + 18 + properties: 19 + compatible: 20 + enum: 21 + - adi,ad8460 22 + 23 + reg: 24 + maxItems: 1 25 + 26 + clocks: 27 + maxItems: 1 28 + 29 + dmas: 30 + maxItems: 1 31 + 32 + dma-names: 33 + items: 34 + - const: tx 35 + 36 + spi-max-frequency: 37 + maximum: 20000000 38 + 39 + hvcc-supply: 40 + description: Positive high voltage power supply line 41 + 42 + hvee-supply: 43 + description: Negative high voltage power supply line 44 + 45 + vcc-5v-supply: 46 + description: Low voltage power supply 47 + 48 + vref-5v-supply: 49 + description: Reference voltage for analog low voltage 50 + 51 + dvdd-3p3v-supply: 52 + description: Digital supply bypass 53 + 54 + avdd-3p3v-supply: 55 + description: Analog supply bypass 56 + 57 + refio-1p2v-supply: 58 + description: Drive voltage in the range of 1.2V maximum to as low as 59 + low as 0.12V through the REF_IO pin to adjust full scale output span 60 + 61 + adi,external-resistor-ohms: 62 + description: Specify value of external resistor connected to FS_ADJ pin 63 + to establish internal HVDAC's reference current I_REF 64 + minimum: 2000 65 + maximum: 20000 66 + default: 2000 67 + 68 + adi,range-microvolt: 69 + description: Voltage output range specified as <minimum, maximum> 70 + items: 71 + - minimum: -55000000 72 + maximum: 0 73 + default: 0 74 + - minimum: 0 75 + maximum: 55000000 76 + default: 0 77 + 78 + adi,range-microamp: 79 + description: Current output range specified as <minimum, maximum> 80 + items: 81 + - minimum: -1000000 82 + maximum: 0 83 + default: 0 84 + - minimum: 0 85 + maximum: 1000000 86 + default: 0 87 + 88 + adi,max-millicelsius: 89 + description: Overtemperature threshold 90 + minimum: 0 91 + maximum: 150000 92 + default: 0 93 + 94 + shutdown-reset-gpios: 95 + description: Corresponds to SDN_RESET pin. To exit shutdown 96 + or sleep mode, pulse SDN_RESET HIGH, then leave LOW. 97 + maxItems: 1 98 + 99 + reset-gpios: 100 + description: Manual Power On Reset (POR). Pull this GPIO pin 101 + LOW and then HIGH to reset all digital registers to default 102 + maxItems: 1 103 + 104 + shutdown-gpios: 105 + description: Corresponds to SDN_IO pin. Shutdown may be 106 + initiated by the user, by pulsing SDN_IO high. To exit shutdown, 107 + pulse SDN_IO low, then float. 108 + maxItems: 1 109 + 110 + required: 111 + - compatible 112 + - reg 113 + - clocks 114 + - hvcc-supply 115 + - hvee-supply 116 + - vcc-5v-supply 117 + - vref-5v-supply 118 + - dvdd-3p3v-supply 119 + - avdd-3p3v-supply 120 + - refio-1p2v-supply 121 + 122 + allOf: 123 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 124 + 125 + unevaluatedProperties: false 126 + 127 + examples: 128 + - | 129 + #include <dt-bindings/gpio/gpio.h> 130 + 131 + spi { 132 + #address-cells = <1>; 133 + #size-cells = <0>; 134 + 135 + dac@0 { 136 + compatible = "adi,ad8460"; 137 + reg = <0>; 138 + spi-max-frequency = <8000000>; 139 + 140 + dmas = <&tx_dma 0>; 141 + dma-names = "tx"; 142 + 143 + shutdown-reset-gpios = <&gpio 86 GPIO_ACTIVE_HIGH>; 144 + reset-gpios = <&gpio 91 GPIO_ACTIVE_LOW>; 145 + shutdown-gpios = <&gpio 88 GPIO_ACTIVE_HIGH>; 146 + 147 + clocks = <&sync_ext_clk>; 148 + 149 + hvcc-supply = <&hvcc>; 150 + hvee-supply = <&hvee>; 151 + vcc-5v-supply = <&vcc_5>; 152 + vref-5v-supply = <&vref_5>; 153 + dvdd-3p3v-supply = <&dvdd_3_3>; 154 + avdd-3p3v-supply = <&avdd_3_3>; 155 + refio-1p2v-supply = <&refio_1_2>; 156 + 157 + adi,external-resistor-ohms = <2000>; 158 + adi,range-microvolt = <(-40000000) 40000000>; 159 + adi,range-microamp = <0 50000>; 160 + adi,max-millicelsius = <50000>; 161 + }; 162 + }; 163 + 164 + ...
+77
Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/imu/bosch,bmi270.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Bosch BMI270 6-Axis IMU 8 + 9 + maintainers: 10 + - Alex Lanzano <lanzano.alex@gmail.com> 11 + 12 + description: | 13 + BMI270 is a 6-axis inertial measurement unit that can measure acceleration and 14 + angular velocity. The sensor also supports configurable interrupt events such 15 + as motion, step counter, and wrist motion gestures. The sensor can communicate 16 + I2C or SPI. 17 + https://www.bosch-sensortec.com/products/motion-sensors/imus/bmi270/ 18 + 19 + properties: 20 + compatible: 21 + const: bosch,bmi270 22 + 23 + reg: 24 + maxItems: 1 25 + 26 + vdd-supply: true 27 + vddio-supply: true 28 + 29 + interrupts: 30 + minItems: 1 31 + maxItems: 2 32 + 33 + interrupt-names: 34 + minItems: 1 35 + maxItems: 2 36 + items: 37 + enum: 38 + - INT1 39 + - INT2 40 + 41 + drive-open-drain: 42 + description: 43 + set if the specified interrupt pins should be configured as 44 + open drain. If not set, defaults to push-pull. 45 + 46 + mount-matrix: 47 + description: 48 + an optional 3x3 mounting rotation matrix. 49 + 50 + required: 51 + - compatible 52 + - reg 53 + - vdd-supply 54 + - vddio-supply 55 + 56 + allOf: 57 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 58 + 59 + unevaluatedProperties: false 60 + 61 + examples: 62 + - | 63 + #include <dt-bindings/interrupt-controller/irq.h> 64 + i2c { 65 + #address-cells = <1>; 66 + #size-cells = <0>; 67 + 68 + imu@68 { 69 + compatible = "bosch,bmi270"; 70 + reg = <0x68>; 71 + vdd-supply = <&vdd>; 72 + vddio-supply = <&vddio>; 73 + interrupt-parent = <&gpio1>; 74 + interrupts = <16 IRQ_TYPE_EDGE_RISING>; 75 + interrupt-names = "INT1"; 76 + }; 77 + };
+1 -1
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml
··· 7 7 title: InvenSense ICM-426xx Inertial Measurement Unit 8 8 9 9 maintainers: 10 - - Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> 10 + - Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com> 11 11 12 12 description: | 13 13 6-axis MotionTracking device that combines a 3-axis gyroscope and a 3-axis
+6 -1
Documentation/devicetree/bindings/iio/imu/invensense,mpu6050.yaml
··· 7 7 title: InvenSense MPU-6050 Six-Axis (Gyro + Accelerometer) MEMS MotionTracking Device 8 8 9 9 maintainers: 10 - - Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> 10 + - Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com> 11 11 12 12 description: | 13 13 These devices support both I2C and SPI bus interfaces. ··· 36 36 - items: 37 37 - const: invensense,icm20608d 38 38 - const: invensense,icm20608 39 + - items: 40 + - enum: 41 + - invensense,iam20680hp 42 + - invensense,iam20680ht 43 + - const: invensense,iam20680 39 44 40 45 reg: 41 46 maxItems: 1
-64
Documentation/devicetree/bindings/iio/light/veml6030.yaml
··· 1 - # SPDX-License-Identifier: GPL-2.0+ 2 - %YAML 1.2 3 - --- 4 - $id: http://devicetree.org/schemas/iio/light/veml6030.yaml# 5 - $schema: http://devicetree.org/meta-schemas/core.yaml# 6 - 7 - title: VEML6030 Ambient Light Sensor (ALS) 8 - 9 - maintainers: 10 - - Rishi Gupta <gupt21@gmail.com> 11 - 12 - description: | 13 - Bindings for the ambient light sensor veml6030 from Vishay 14 - Semiconductors over an i2c interface. 15 - 16 - Irrespective of whether interrupt is used or not, application 17 - can get the ALS and White channel reading from IIO raw interface. 18 - 19 - If the interrupts are used, application will receive an IIO event 20 - whenever configured threshold is crossed. 21 - 22 - Specifications about the sensor can be found at: 23 - https://www.vishay.com/docs/84366/veml6030.pdf 24 - 25 - properties: 26 - compatible: 27 - enum: 28 - - vishay,veml6030 29 - 30 - reg: 31 - description: 32 - I2C address of the device. 33 - enum: 34 - - 0x10 # ADDR pin pulled down 35 - - 0x48 # ADDR pin pulled up 36 - 37 - interrupts: 38 - description: 39 - interrupt mapping for IRQ. Configure with IRQ_TYPE_LEVEL_LOW. 40 - Refer to interrupt-controller/interrupts.txt for generic 41 - interrupt client node bindings. 42 - maxItems: 1 43 - 44 - required: 45 - - compatible 46 - - reg 47 - 48 - additionalProperties: false 49 - 50 - examples: 51 - - | 52 - #include <dt-bindings/interrupt-controller/irq.h> 53 - 54 - i2c { 55 - #address-cells = <1>; 56 - #size-cells = <0>; 57 - 58 - light-sensor@10 { 59 - compatible = "vishay,veml6030"; 60 - reg = <0x10>; 61 - interrupts = <12 IRQ_TYPE_LEVEL_LOW>; 62 - }; 63 - }; 64 - ...
+104
Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0+ 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/light/vishay,veml6030.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: VEML6030, VEML6035 and VEML7700 Ambient Light Sensors (ALS) 8 + 9 + maintainers: 10 + - Rishi Gupta <gupt21@gmail.com> 11 + 12 + description: | 13 + Bindings for the ambient light sensors veml6030 and veml6035 from 14 + Vishay Semiconductors over an i2c interface. 15 + 16 + Irrespective of whether interrupt is used or not, application 17 + can get the ALS and White channel reading from IIO raw interface. 18 + 19 + If the interrupts are used, application will receive an IIO event 20 + whenever configured threshold is crossed. 21 + 22 + Specifications about the sensors can be found at: 23 + https://www.vishay.com/docs/84366/veml6030.pdf 24 + https://www.vishay.com/docs/84889/veml6035.pdf 25 + https://www.vishay.com/docs/84286/veml7700.pdf 26 + 27 + properties: 28 + compatible: 29 + enum: 30 + - vishay,veml6030 31 + - vishay,veml6035 32 + - vishay,veml7700 33 + 34 + reg: 35 + maxItems: 1 36 + 37 + interrupts: 38 + description: 39 + interrupt mapping for IRQ. Configure with IRQ_TYPE_LEVEL_LOW. 40 + Refer to interrupt-controller/interrupts.txt for generic 41 + interrupt client node bindings. 42 + maxItems: 1 43 + 44 + vdd-supply: true 45 + 46 + required: 47 + - compatible 48 + - reg 49 + - vdd-supply 50 + 51 + allOf: 52 + - if: 53 + properties: 54 + compatible: 55 + enum: 56 + - vishay,veml6030 57 + then: 58 + properties: 59 + reg: 60 + enum: 61 + - 0x10 # ADDR pin pulled down 62 + - 0x48 # ADDR pin pulled up 63 + 64 + - if: 65 + properties: 66 + compatible: 67 + enum: 68 + - vishay,veml6035 69 + then: 70 + properties: 71 + reg: 72 + enum: 73 + - 0x29 74 + 75 + - if: 76 + properties: 77 + compatible: 78 + enum: 79 + - vishay,veml7700 80 + then: 81 + properties: 82 + reg: 83 + enum: 84 + - 0x10 85 + interrupts: false 86 + 87 + additionalProperties: false 88 + 89 + examples: 90 + - | 91 + #include <dt-bindings/interrupt-controller/irq.h> 92 + 93 + i2c { 94 + #address-cells = <1>; 95 + #size-cells = <0>; 96 + 97 + light-sensor@10 { 98 + compatible = "vishay,veml6030"; 99 + reg = <0x10>; 100 + interrupts = <12 IRQ_TYPE_LEVEL_LOW>; 101 + vdd-supply = <&vdd>; 102 + }; 103 + }; 104 + ...
+2 -1
Documentation/devicetree/bindings/iio/light/vishay,veml6075.yaml
··· 4 4 $id: http://devicetree.org/schemas/iio/light/vishay,veml6075.yaml# 5 5 $schema: http://devicetree.org/meta-schemas/core.yaml# 6 6 7 - title: Vishay VEML6075 UVA/B and VEML6040 RGBW sensors 7 + title: Vishay VEML6070 UVA, VEML6075 UVA/B and VEML6040 RGBW sensors 8 8 9 9 maintainers: 10 10 - Javier Carrasco <javier.carrasco.cruz@gmail.com> ··· 16 16 compatible: 17 17 enum: 18 18 - vishay,veml6040 19 + - vishay,veml6070 19 20 - vishay,veml6075 20 21 21 22 reg:
+6
Documentation/devicetree/bindings/iio/temperature/ti,tmp006.yaml
··· 23 23 vdd-supply: 24 24 description: provide VDD power to the sensor. 25 25 26 + interrupts: 27 + maxItems: 1 28 + 26 29 required: 27 30 - compatible 28 31 - reg ··· 34 31 35 32 examples: 36 33 - | 34 + #include <dt-bindings/interrupt-controller/irq.h> 37 35 i2c { 38 36 #address-cells = <1>; 39 37 #size-cells = <0>; ··· 42 38 compatible = "ti,tmp006"; 43 39 reg = <0x40>; 44 40 vdd-supply = <&ldo4_reg>; 41 + interrupt-parent = <&gpio1>; 42 + interrupts = <4 IRQ_TYPE_EDGE_FALLING>; 45 43 }; 46 44 };
+2
Documentation/devicetree/bindings/vendor-prefixes.yaml
··· 561 561 description: GE Fanuc Intelligent Platforms Embedded Systems, Inc. 562 562 "^GEFanuc,.*": 563 563 description: GE Fanuc Intelligent Platforms Embedded Systems, Inc. 564 + "^gehc,.*": 565 + description: GE HealthCare 564 566 "^gemei,.*": 565 567 description: Gemei Digital Technology Co., Ltd. 566 568 "^gemtek,.*":
+91
Documentation/iio/ad7625.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0-only 2 + 3 + ==================== 4 + AD7625 driver 5 + ==================== 6 + 7 + ADC driver for Analog Devices Inc. AD7625, AD7626, AD7960, and AD7961 8 + devices. The module name is ``ad7625``. 9 + 10 + Supported devices 11 + ================= 12 + 13 + The following chips are supported by this driver: 14 + 15 + * `AD7625 <https://www.analog.com/AD7625>`_ 16 + * `AD7626 <https://www.analog.com/AD7626>`_ 17 + * `AD7960 <https://www.analog.com/AD7960>`_ 18 + * `AD7961 <https://www.analog.com/AD7961>`_ 19 + 20 + The driver requires use of the Pulsar LVDS HDL project: 21 + 22 + * `Pulsar LVDS HDL <http://analogdevicesinc.github.io/hdl/projects/pulsar_lvds/index.html>`_ 23 + 24 + To trigger conversions and enable subsequent data transfer, the devices 25 + require coupled PWM signals with a phase offset. 26 + 27 + Supported features 28 + ================== 29 + 30 + Conversion control modes 31 + ------------------------ 32 + 33 + The driver currently supports one of two possible LVDS conversion control methods. 34 + 35 + Echoed-Clock interface mode 36 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 37 + 38 + .. code-block:: 39 + 40 + +----------------+ 41 + +xxxxxxxxxxxxxxxxxxxxxxxxxx| CNV | 42 + X | | 43 + v | HOST | 44 + +----------------------------+ | | 45 + | CNV+/CNV- DCO+/DCO- |xxxxxxx>| CLK_IN | 46 + | | | | 47 + | | | | 48 + | AD7625 D+/D- |xxxxxxx>| DATA_IN | 49 + | | | | 50 + | | | | 51 + | CLK+/CLK- |<xxxxxxx| CLK & CLK_GATE | 52 + +----------------------------+ | | 53 + +----------------+ 54 + 55 + Reference voltage 56 + ----------------- 57 + 58 + Three possible reference voltage sources are supported: 59 + 60 + - Internal reference (only available on AD7625 and AD7626) 61 + - External reference and internal buffer 62 + - External reference 63 + 64 + The source is determined by the device tree. If ``ref-supply`` is present, then 65 + the external reference is used. If ``refin-supply`` is present, then the internal 66 + buffer is used. If neither is present, then the internal reference is used. 67 + 68 + Unimplemented features 69 + ---------------------- 70 + 71 + - Self-clocked mode 72 + 73 + 74 + Device attributes 75 + ================= 76 + 77 + The AD762x is a fully-differential ADC and has the following attributes: 78 + 79 + +---------------------------------------+--------------------------------------------------------------+ 80 + | Attribute | Description | 81 + +=======================================+==============================================================+ 82 + | ``scale`` | Scale factor to convert raw value from buffered reads to mV. | 83 + +---------------------------------------+--------------------------------------------------------------+ 84 + 85 + 86 + Device buffers 87 + ============== 88 + 89 + This driver supports IIO triggered buffers. 90 + 91 + See :doc:`iio_devbuf` for more information.
+1 -1
Documentation/iio/bno055.rst
··· 22 22 23 23 The IMU continuously performs an autocalibration procedure if (and only if) 24 24 operating in fusion mode. The magnetometer autocalibration can however be 25 - disabled writing 0 in the sysfs in_magn_calibration_fast_enable attribute. 25 + disabled by writing 0 in the sysfs in_magn_calibration_fast_enable attribute. 26 26 27 27 The driver provides access to autocalibration flags (i.e. you can known if 28 28 the IMU has successfully autocalibrated) and to the calibration data blob.
+1
Documentation/iio/index.rst
··· 21 21 ad4000 22 22 ad4695 23 23 ad7380 24 + ad7625 24 25 ad7944 25 26 adis16475 26 27 adis16480
+49 -1
MAINTAINERS
··· 1327 1327 F: drivers/iio/addac/ad74413r.c 1328 1328 F: include/dt-bindings/iio/addac/adi,ad74413r.h 1329 1329 1330 + ANALOG DEVICES INC AD7625 DRIVER 1331 + M: Michael Hennerich <Michael.Hennerich@analog.com> 1332 + M: Nuno Sá <nuno.sa@analog.com> 1333 + R: Trevor Gamblin <tgamblin@baylibre.com> 1334 + S: Supported 1335 + W: https://ez.analog.com/linux-software-drivers 1336 + W: http://analogdevicesinc.github.io/hdl/projects/pulsar_lvds/index.html 1337 + F: Documentation/devicetree/bindings/iio/adc/adi,ad7625.yaml 1338 + F: Documentation/iio/ad7625.rst 1339 + F: drivers/iio/adc/ad7625.c 1340 + 1330 1341 ANALOG DEVICES INC AD7768-1 DRIVER 1331 1342 M: Michael Hennerich <Michael.Hennerich@analog.com> 1332 1343 L: linux-iio@vger.kernel.org ··· 1364 1353 F: Documentation/ABI/testing/debugfs-iio-ad9467 1365 1354 F: Documentation/devicetree/bindings/iio/adc/adi,ad9467.yaml 1366 1355 F: drivers/iio/adc/ad9467.c 1356 + 1357 + ANALOG DEVICES INC AD8460 DRIVER 1358 + M: Mariel Tinaco <Mariel.Tinaco@analog.com> 1359 + L: linux-iio@vger.kernel.org 1360 + S: Supported 1361 + W: https://ez.analog.com/linux-software-drivers 1362 + F: Documentation/devicetree/bindings/iio/dac/adi,ad8460.yaml 1363 + F: drivers/iio/dac/ad8460.c 1367 1364 1368 1365 ANALOG DEVICES INC AD9739a DRIVER 1369 1366 M: Nuno Sa <nuno.sa@analog.com> ··· 4053 4034 S: Maintained 4054 4035 F: Documentation/devicetree/bindings/iio/accel/bosch,bma400.yaml 4055 4036 F: drivers/iio/accel/bma400* 4037 + 4038 + BOSCH SENSORTEC BMI270 IMU IIO DRIVER 4039 + M: Alex Lanzano <lanzano.alex@gmail.com> 4040 + L: linux-iio@vger.kernel.org 4041 + S: Maintained 4042 + F: Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml 4043 + F: drivers/iio/imu/bmi270/ 4056 4044 4057 4045 BOSCH SENSORTEC BMI323 IMU IIO DRIVER 4058 4046 M: Jagath Jog J <jagathjog1996@gmail.com> ··· 9483 9457 S: Supported 9484 9458 F: scripts/gdb/ 9485 9459 9460 + GE HEALTHCARE PMC ADC DRIVER 9461 + M: Herve Codina <herve.codina@bootlin.com> 9462 + L: linux-iio@vger.kernel.org 9463 + S: Maintained 9464 + F: Documentation/devicetree/bindings/iio/adc/gehc,pmc-adc.yaml 9465 + F: drivers/iio/adc/gehc-pmc-adc.c 9466 + F: include/dt-bindings/iio/adc/gehc,pmc-adc.h 9467 + 9486 9468 GEMINI CRYPTO DRIVER 9487 9469 M: Corentin Labbe <clabbe@baylibre.com> 9488 9470 L: linux-crypto@vger.kernel.org ··· 11920 11886 F: drivers/media/i2c/isl7998x.c 11921 11887 11922 11888 INVENSENSE ICM-426xx IMU DRIVER 11923 - M: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> 11889 + M: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com> 11924 11890 L: linux-iio@vger.kernel.org 11925 11891 S: Maintained 11926 11892 W: https://invensense.tdk.com/ ··· 11934 11900 S: Maintained 11935 11901 F: Documentation/devicetree/bindings/iio/gyroscope/invensense,mpu3050.yaml 11936 11902 F: drivers/iio/gyro/mpu3050* 11903 + 11904 + INVENSENSE MPU-6050 IMU DRIVER 11905 + M: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com> 11906 + L: linux-iio@vger.kernel.org 11907 + S: Maintained 11908 + W: https://invensense.tdk.com/ 11909 + F: Documentation/devicetree/bindings/iio/imu/invensense,mpu6050.yaml 11910 + F: drivers/iio/imu/inv_mpu6050/ 11937 11911 11938 11912 IOC3 ETHERNET DRIVER 11939 11913 M: Ralf Baechle <ralf@linux-mips.org> ··· 24734 24692 S: Maintained 24735 24693 F: drivers/input/serio/userio.c 24736 24694 F: include/uapi/linux/userio.h 24695 + 24696 + VISHAY VEML6030 AMBIENT LIGHT SENSOR DRIVER 24697 + M: Javier Carrasco <javier.carrasco.cruz@gmail.com> 24698 + S: Maintained 24699 + F: Documentation/devicetree/bindings/iio/light/vishay,veml6030.yaml 24700 + F: drivers/iio/light/veml6030.c 24737 24701 24738 24702 VISHAY VEML6075 UVA AND UVB LIGHT SENSOR DRIVER 24739 24703 M: Javier Carrasco <javier.carrasco.cruz@gmail.com>
+1 -6
drivers/iio/accel/adxl380.c
··· 1719 1719 { 1720 1720 struct adxl380_state *st = iio_priv(indio_dev); 1721 1721 unsigned long irq_flag; 1722 - struct irq_data *desc; 1723 1722 u32 irq_type; 1724 1723 u8 polarity; 1725 1724 int ret; ··· 1736 1737 st->int_map[1] = ADXL380_INT1_MAP1_REG; 1737 1738 } 1738 1739 1739 - desc = irq_get_irq_data(st->irq); 1740 - if (!desc) 1741 - return dev_err_probe(st->dev, -EINVAL, "Could not find IRQ %d\n", st->irq); 1742 - 1743 - irq_type = irqd_get_trigger_type(desc); 1740 + irq_type = irq_get_trigger_type(st->irq); 1744 1741 if (irq_type == IRQ_TYPE_LEVEL_HIGH) { 1745 1742 polarity = 0; 1746 1743 irq_flag = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
+1 -2
drivers/iio/accel/fxls8962af-core.c
··· 1103 1103 if (ret) 1104 1104 return ret; 1105 1105 1106 - irq_type = irqd_get_trigger_type(irq_get_irq_data(irq)); 1107 - 1106 + irq_type = irq_get_trigger_type(irq); 1108 1107 switch (irq_type) { 1109 1108 case IRQF_TRIGGER_HIGH: 1110 1109 case IRQF_TRIGGER_RISING:
+4 -5
drivers/iio/accel/hid-sensor-accel-3d.c
··· 28 28 /* Ensure timestamp is naturally aligned */ 29 29 struct { 30 30 u32 accel_val[3]; 31 - s64 timestamp __aligned(8); 31 + aligned_s64 timestamp; 32 32 } scan; 33 33 int scale_pre_decml; 34 34 int scale_post_decml; ··· 328 328 /* Function to initialize the processing for usage id */ 329 329 static int hid_accel_3d_probe(struct platform_device *pdev) 330 330 { 331 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 331 332 int ret = 0; 332 333 const char *name; 333 334 struct iio_dev *indio_dev; 334 335 struct accel_3d_state *accel_state; 335 336 const struct iio_chan_spec *channel_spec; 336 337 int channel_size; 337 - 338 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 339 338 340 339 indio_dev = devm_iio_device_alloc(&pdev->dev, 341 340 sizeof(struct accel_3d_state)); ··· 423 424 /* Function to deinitialize the processing for usage id */ 424 425 static void hid_accel_3d_remove(struct platform_device *pdev) 425 426 { 426 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 427 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 427 428 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 428 429 struct accel_3d_state *accel_state = iio_priv(indio_dev); 429 430 ··· 451 452 .pm = &hid_sensor_pm_ops, 452 453 }, 453 454 .probe = hid_accel_3d_probe, 454 - .remove_new = hid_accel_3d_remove, 455 + .remove = hid_accel_3d_remove, 455 456 }; 456 457 module_platform_driver(hid_accel_3d_platform_driver); 457 458
+27 -1
drivers/iio/adc/Kconfig
··· 229 229 ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC). 230 230 231 231 To compile this driver as a module, choose M here: the 232 - module will be called ad7606_parallel. 232 + module will be called ad7606_par. 233 233 234 234 config AD7606_IFACE_SPI 235 235 tristate "Analog Devices AD7606 ADC driver with spi interface support" ··· 241 241 242 242 To compile this driver as a module, choose M here: the 243 243 module will be called ad7606_spi. 244 + 245 + config AD7625 246 + tristate "Analog Devices AD7625/AD7626 High Speed ADC driver" 247 + depends on PWM 248 + select IIO_BACKEND 249 + help 250 + Say yes here to build support for Analog Devices: 251 + * AD7625 16-Bit, 6 MSPS PulSAR Analog-to-Digital Converter 252 + * AD7626 16-Bit, 10 MSPS PulSAR Analog-to-Digital Converter 253 + * AD7960 18-Bit, 5 MSPS PulSAR Analog-to-Digital Converter 254 + * AD7961 16-Bit, 5 MSPS PulSAR Analog-to-Digital Converter 255 + 256 + The driver requires the assistance of the AXI ADC IP core to operate. 257 + 258 + To compile this driver as a module, choose M here: the module will be 259 + called ad7625. 244 260 245 261 config AD7766 246 262 tristate "Analog Devices AD7766/AD7767 ADC driver" ··· 586 570 help 587 571 Generic Conversion Queue driver used for general purpose ADC in the 588 572 MX25. This driver supports single measurements using the MX25 ADC. 573 + 574 + config GEHC_PMC_ADC 575 + tristate "GE HealthCare PMC ADC driver" 576 + depends on I2C 577 + help 578 + Say yes here to build support for the GE HealthCare PMC 16-bit 579 + 16-Channel ADC. 580 + 581 + To compile this driver as a module, choose M here: the module will be 582 + called gehc-pmc-adc. 589 583 590 584 config HI8435 591 585 tristate "Holt Integrated Circuits HI-8435 threshold detector"
+2
drivers/iio/adc/Makefile
··· 25 25 obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o 26 26 obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o 27 27 obj-$(CONFIG_AD7606) += ad7606.o 28 + obj-$(CONFIG_AD7625) += ad7625.o 28 29 obj-$(CONFIG_AD7766) += ad7766.o 29 30 obj-$(CONFIG_AD7768_1) += ad7768-1.o 30 31 obj-$(CONFIG_AD7780) += ad7780.o ··· 53 52 obj-$(CONFIG_EP93XX_ADC) += ep93xx_adc.o 54 53 obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o 55 54 obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o 55 + obj-$(CONFIG_GEHC_PMC_ADC) += gehc-pmc-adc.o 56 56 obj-$(CONFIG_HI8435) += hi8435.o 57 57 obj-$(CONFIG_HX711) += hx711.o 58 58 obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o
+1 -1
drivers/iio/adc/ab8500-gpadc.c
··· 1194 1194 1195 1195 static struct platform_driver ab8500_gpadc_driver = { 1196 1196 .probe = ab8500_gpadc_probe, 1197 - .remove_new = ab8500_gpadc_remove, 1197 + .remove = ab8500_gpadc_remove, 1198 1198 .driver = { 1199 1199 .name = "ab8500-gpadc", 1200 1200 .pm = pm_ptr(&ab8500_gpadc_pm_ops),
+1 -1
drivers/iio/adc/ad7091r-base.h
··· 65 65 struct regulator *vref; 66 66 const struct ad7091r_chip_info *chip_info; 67 67 enum ad7091r_mode mode; 68 - struct mutex lock; /*lock to prevent concurent reads */ 68 + struct mutex lock; /*lock to prevent concurrent reads */ 69 69 __be16 tx_buf __aligned(IIO_DMA_MINALIGN); 70 70 __be16 rx_buf; 71 71 };
+36 -2
drivers/iio/adc/ad7173.c
··· 3 3 * AD717x and AD411x family SPI ADC driver 4 4 * 5 5 * Supported devices: 6 - * AD4111/AD4112/AD4114/AD4115/AD4116 6 + * AD4111/AD4112/AD4113/AD4114/AD4115/AD4116 7 7 * AD7172-2/AD7172-4/AD7173-8/AD7175-2 8 8 * AD7175-8/AD7176-2/AD7177-2 9 9 * ··· 76 76 (x) == AD7173_AIN_REF_NEG) 77 77 78 78 #define AD7172_2_ID 0x00d0 79 - #define AD7175_ID 0x0cd0 80 79 #define AD7176_ID 0x0c90 80 + #define AD7175_ID 0x0cd0 81 81 #define AD7175_2_ID 0x0cd0 82 82 #define AD7172_4_ID 0x2050 83 83 #define AD7173_ID 0x30d0 84 84 #define AD4111_ID AD7173_ID 85 85 #define AD4112_ID AD7173_ID 86 86 #define AD4114_ID AD7173_ID 87 + #define AD4113_ID 0x31d0 87 88 #define AD4116_ID 0x34d0 88 89 #define AD4115_ID 0x38d0 89 90 #define AD7175_8_ID 0x3cd0 ··· 171 170 bool has_temp; 172 171 /* ((AVDD1 − AVSS)/5) */ 173 172 bool has_pow_supply_monitoring; 173 + bool data_reg_only_16bit; 174 174 bool has_input_buf; 175 175 bool has_int_ref; 176 176 bool has_ref2; ··· 290 288 .has_temp = true, 291 289 .has_input_buf = true, 292 290 .has_current_inputs = true, 291 + .has_int_ref = true, 292 + .clock = 2 * HZ_PER_MHZ, 293 + .sinc5_data_rates = ad7173_sinc5_data_rates, 294 + .num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates), 295 + }; 296 + 297 + static const struct ad7173_device_info ad4113_device_info = { 298 + .name = "ad4113", 299 + .id = AD4113_ID, 300 + .num_voltage_in_div = 8, 301 + .num_channels = 16, 302 + .num_configs = 8, 303 + .num_voltage_in = 8, 304 + .num_gpios = 2, 305 + .data_reg_only_16bit = true, 306 + .higher_gpio_bits = true, 307 + .has_vincom_input = true, 308 + .has_input_buf = true, 293 309 .has_int_ref = true, 294 310 .clock = 2 * HZ_PER_MHZ, 295 311 .sinc5_data_rates = ad7173_sinc5_data_rates, ··· 1005 985 .update_scan_mode = ad7173_update_scan_mode, 1006 986 }; 1007 987 988 + static const struct iio_scan_type ad4113_scan_type = { 989 + .sign = 'u', 990 + .realbits = 16, 991 + .storagebits = 16, 992 + .endianness = IIO_BE, 993 + }; 994 + 1008 995 static const struct iio_chan_spec ad7173_channel_template = { 1009 996 .type = IIO_VOLTAGE, 1010 997 .indexed = 1, ··· 1253 1226 chan_st_priv->cfg.input_buf = st->info->has_input_buf; 1254 1227 chan_st_priv->cfg.ref_sel = AD7173_SETUP_REF_SEL_INT_REF; 1255 1228 st->adc_mode |= AD7173_ADC_MODE_REF_EN; 1229 + if (st->info->data_reg_only_16bit) 1230 + chan_arr[chan_index].scan_type = ad4113_scan_type; 1256 1231 1257 1232 chan_index++; 1258 1233 } ··· 1334 1305 chan->channel2 = ain[1]; 1335 1306 chan_st_priv->ain = AD7173_CH_ADDRESS(ain[0], ain[1]); 1336 1307 } 1308 + 1309 + if (st->info->data_reg_only_16bit) 1310 + chan_arr[chan_index].scan_type = ad4113_scan_type; 1337 1311 1338 1312 chan_index++; 1339 1313 } ··· 1466 1434 static const struct of_device_id ad7173_of_match[] = { 1467 1435 { .compatible = "adi,ad4111", .data = &ad4111_device_info }, 1468 1436 { .compatible = "adi,ad4112", .data = &ad4112_device_info }, 1437 + { .compatible = "adi,ad4113", .data = &ad4113_device_info }, 1469 1438 { .compatible = "adi,ad4114", .data = &ad4114_device_info }, 1470 1439 { .compatible = "adi,ad4115", .data = &ad4115_device_info }, 1471 1440 { .compatible = "adi,ad4116", .data = &ad4116_device_info }, ··· 1484 1451 static const struct spi_device_id ad7173_id_table[] = { 1485 1452 { "ad4111", (kernel_ulong_t)&ad4111_device_info }, 1486 1453 { "ad4112", (kernel_ulong_t)&ad4112_device_info }, 1454 + { "ad4113", (kernel_ulong_t)&ad4113_device_info }, 1487 1455 { "ad4114", (kernel_ulong_t)&ad4114_device_info }, 1488 1456 { "ad4115", (kernel_ulong_t)&ad4115_device_info }, 1489 1457 { "ad4116", (kernel_ulong_t)&ad4116_device_info },
+1 -1
drivers/iio/adc/ad7266.c
··· 383 383 384 384 static int ad7266_probe(struct spi_device *spi) 385 385 { 386 - struct ad7266_platform_data *pdata = spi->dev.platform_data; 386 + const struct ad7266_platform_data *pdata = dev_get_platdata(&spi->dev); 387 387 struct iio_dev *indio_dev; 388 388 struct ad7266_state *st; 389 389 unsigned int i;
+407 -68
drivers/iio/adc/ad7606.c
··· 19 19 #include <linux/sysfs.h> 20 20 #include <linux/util_macros.h> 21 21 22 - #include <linux/iio/iio.h> 23 22 #include <linux/iio/buffer.h> 23 + #include <linux/iio/iio.h> 24 24 #include <linux/iio/sysfs.h> 25 25 #include <linux/iio/trigger.h> 26 26 #include <linux/iio/triggered_buffer.h> ··· 32 32 * Scales are computed as 5000/32768 and 10000/32768 respectively, 33 33 * so that when applied to the raw values they provide mV values 34 34 */ 35 - static const unsigned int ad7606_scale_avail[2] = { 35 + static const unsigned int ad7606_16bit_hw_scale_avail[2] = { 36 36 152588, 305176 37 37 }; 38 38 39 + static const unsigned int ad7606_18bit_hw_scale_avail[2] = { 40 + 38147, 76294 41 + }; 39 42 40 - static const unsigned int ad7616_sw_scale_avail[3] = { 43 + static const unsigned int ad7606c_16bit_single_ended_unipolar_scale_avail[3] = { 44 + 76294, 152588, 190735, 45 + }; 46 + 47 + static const unsigned int ad7606c_16bit_single_ended_bipolar_scale_avail[5] = { 48 + 76294, 152588, 190735, 305176, 381470 49 + }; 50 + 51 + static const unsigned int ad7606c_16bit_differential_bipolar_scale_avail[4] = { 52 + 152588, 305176, 381470, 610352 53 + }; 54 + 55 + static const unsigned int ad7606c_18bit_single_ended_unipolar_scale_avail[3] = { 56 + 19073, 38147, 47684 57 + }; 58 + 59 + static const unsigned int ad7606c_18bit_single_ended_bipolar_scale_avail[5] = { 60 + 19073, 38147, 47684, 76294, 95367 61 + }; 62 + 63 + static const unsigned int ad7606c_18bit_differential_bipolar_scale_avail[4] = { 64 + 38147, 76294, 95367, 152588 65 + }; 66 + 67 + static const unsigned int ad7606_16bit_sw_scale_avail[3] = { 41 68 76293, 152588, 305176 42 69 }; 43 70 ··· 88 61 return -ENODEV; 89 62 } 90 63 EXPORT_SYMBOL_NS_GPL(ad7606_reset, IIO_AD7606); 64 + 65 + static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st, 66 + struct iio_chan_spec *chan, int ch) 67 + { 68 + struct ad7606_chan_scale *cs = &st->chan_scales[ch]; 69 + 70 + if (!st->sw_mode_en) { 71 + /* tied to logic low, analog input range is +/- 5V */ 72 + cs->range = 0; 73 + cs->scale_avail = ad7606_16bit_hw_scale_avail; 74 + cs->num_scales = ARRAY_SIZE(ad7606_16bit_hw_scale_avail); 75 + return 0; 76 + } 77 + 78 + /* Scale of 0.076293 is only available in sw mode */ 79 + /* After reset, in software mode, ±10 V is set by default */ 80 + cs->range = 2; 81 + cs->scale_avail = ad7606_16bit_sw_scale_avail; 82 + cs->num_scales = ARRAY_SIZE(ad7606_16bit_sw_scale_avail); 83 + 84 + return 0; 85 + } 86 + 87 + static int ad7606_get_chan_config(struct ad7606_state *st, int ch, 88 + bool *bipolar, bool *differential) 89 + { 90 + unsigned int num_channels = st->chip_info->num_channels - 1; 91 + struct device *dev = st->dev; 92 + int ret; 93 + 94 + *bipolar = false; 95 + *differential = false; 96 + 97 + device_for_each_child_node_scoped(dev, child) { 98 + u32 pins[2]; 99 + int reg; 100 + 101 + ret = fwnode_property_read_u32(child, "reg", &reg); 102 + if (ret) 103 + continue; 104 + 105 + /* channel number (here) is from 1 to num_channels */ 106 + if (reg == 0 || reg > num_channels) { 107 + dev_warn(dev, 108 + "Invalid channel number (ignoring): %d\n", reg); 109 + continue; 110 + } 111 + 112 + if (reg != (ch + 1)) 113 + continue; 114 + 115 + *bipolar = fwnode_property_read_bool(child, "bipolar"); 116 + 117 + ret = fwnode_property_read_u32_array(child, "diff-channels", 118 + pins, ARRAY_SIZE(pins)); 119 + /* Channel is differential, if pins are the same as 'reg' */ 120 + if (ret == 0 && (pins[0] != reg || pins[1] != reg)) { 121 + dev_err(dev, 122 + "Differential pins must be the same as 'reg'"); 123 + return -EINVAL; 124 + } 125 + 126 + *differential = (ret == 0); 127 + 128 + if (*differential && !*bipolar) { 129 + dev_err(dev, 130 + "'bipolar' must be added for diff channel %d\n", 131 + reg); 132 + return -EINVAL; 133 + } 134 + 135 + return 0; 136 + } 137 + 138 + return 0; 139 + } 140 + 141 + static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st, 142 + struct iio_chan_spec *chan, int ch) 143 + { 144 + struct ad7606_chan_scale *cs = &st->chan_scales[ch]; 145 + bool bipolar, differential; 146 + int ret; 147 + 148 + if (!st->sw_mode_en) { 149 + cs->range = 0; 150 + cs->scale_avail = ad7606_18bit_hw_scale_avail; 151 + cs->num_scales = ARRAY_SIZE(ad7606_18bit_hw_scale_avail); 152 + return 0; 153 + } 154 + 155 + ret = ad7606_get_chan_config(st, ch, &bipolar, &differential); 156 + if (ret) 157 + return ret; 158 + 159 + if (differential) { 160 + cs->scale_avail = ad7606c_18bit_differential_bipolar_scale_avail; 161 + cs->num_scales = 162 + ARRAY_SIZE(ad7606c_18bit_differential_bipolar_scale_avail); 163 + /* Bipolar differential ranges start at 8 (b1000) */ 164 + cs->reg_offset = 8; 165 + cs->range = 1; 166 + chan->differential = 1; 167 + chan->channel2 = chan->channel; 168 + 169 + return 0; 170 + } 171 + 172 + chan->differential = 0; 173 + 174 + if (bipolar) { 175 + cs->scale_avail = ad7606c_18bit_single_ended_bipolar_scale_avail; 176 + cs->num_scales = 177 + ARRAY_SIZE(ad7606c_18bit_single_ended_bipolar_scale_avail); 178 + /* Bipolar single-ended ranges start at 0 (b0000) */ 179 + cs->reg_offset = 0; 180 + cs->range = 3; 181 + chan->scan_type.sign = 's'; 182 + 183 + return 0; 184 + } 185 + 186 + cs->scale_avail = ad7606c_18bit_single_ended_unipolar_scale_avail; 187 + cs->num_scales = 188 + ARRAY_SIZE(ad7606c_18bit_single_ended_unipolar_scale_avail); 189 + /* Unipolar single-ended ranges start at 5 (b0101) */ 190 + cs->reg_offset = 5; 191 + cs->range = 1; 192 + chan->scan_type.sign = 'u'; 193 + 194 + return 0; 195 + } 196 + 197 + static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st, 198 + struct iio_chan_spec *chan, int ch) 199 + { 200 + struct ad7606_chan_scale *cs = &st->chan_scales[ch]; 201 + bool bipolar, differential; 202 + int ret; 203 + 204 + if (!st->sw_mode_en) { 205 + cs->range = 0; 206 + cs->scale_avail = ad7606_16bit_hw_scale_avail; 207 + cs->num_scales = ARRAY_SIZE(ad7606_16bit_hw_scale_avail); 208 + return 0; 209 + } 210 + 211 + ret = ad7606_get_chan_config(st, ch, &bipolar, &differential); 212 + if (ret) 213 + return ret; 214 + 215 + if (differential) { 216 + cs->scale_avail = ad7606c_16bit_differential_bipolar_scale_avail; 217 + cs->num_scales = 218 + ARRAY_SIZE(ad7606c_16bit_differential_bipolar_scale_avail); 219 + /* Bipolar differential ranges start at 8 (b1000) */ 220 + cs->reg_offset = 8; 221 + cs->range = 1; 222 + chan->differential = 1; 223 + chan->channel2 = chan->channel; 224 + chan->scan_type.sign = 's'; 225 + 226 + return 0; 227 + } 228 + 229 + chan->differential = 0; 230 + 231 + if (bipolar) { 232 + cs->scale_avail = ad7606c_16bit_single_ended_bipolar_scale_avail; 233 + cs->num_scales = 234 + ARRAY_SIZE(ad7606c_16bit_single_ended_bipolar_scale_avail); 235 + /* Bipolar single-ended ranges start at 0 (b0000) */ 236 + cs->reg_offset = 0; 237 + cs->range = 3; 238 + chan->scan_type.sign = 's'; 239 + 240 + return 0; 241 + } 242 + 243 + cs->scale_avail = ad7606c_16bit_single_ended_unipolar_scale_avail; 244 + cs->num_scales = 245 + ARRAY_SIZE(ad7606c_16bit_single_ended_unipolar_scale_avail); 246 + /* Unipolar single-ended ranges start at 5 (b0101) */ 247 + cs->reg_offset = 5; 248 + cs->range = 1; 249 + chan->scan_type.sign = 'u'; 250 + 251 + return 0; 252 + } 91 253 92 254 static int ad7606_reg_access(struct iio_dev *indio_dev, 93 255 unsigned int reg, ··· 302 86 static int ad7606_read_samples(struct ad7606_state *st) 303 87 { 304 88 unsigned int num = st->chip_info->num_channels - 1; 305 - u16 *data = st->data; 306 89 307 - return st->bops->read_block(st->dev, num, data); 90 + return st->bops->read_block(st->dev, num, &st->data); 308 91 } 309 92 310 93 static irqreturn_t ad7606_trigger_handler(int irq, void *p) ··· 319 104 if (ret) 320 105 goto error_ret; 321 106 322 - iio_push_to_buffers_with_timestamp(indio_dev, st->data, 107 + iio_push_to_buffers_with_timestamp(indio_dev, &st->data, 323 108 iio_get_time_ns(indio_dev)); 324 109 error_ret: 325 110 iio_trigger_notify_done(indio_dev->trig); ··· 329 114 return IRQ_HANDLED; 330 115 } 331 116 332 - static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch) 117 + static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch, 118 + int *val) 333 119 { 334 120 struct ad7606_state *st = iio_priv(indio_dev); 121 + unsigned int storagebits = st->chip_info->channels[1].scan_type.storagebits; 122 + const struct iio_chan_spec *chan; 335 123 int ret; 336 124 337 125 gpiod_set_value(st->gpio_convst, 1); ··· 346 128 } 347 129 348 130 ret = ad7606_read_samples(st); 349 - if (ret == 0) 350 - ret = st->data[ch]; 131 + if (ret) 132 + goto error_ret; 133 + 134 + chan = &indio_dev->channels[ch + 1]; 135 + if (chan->scan_type.sign == 'u') { 136 + if (storagebits > 16) 137 + *val = st->data.buf32[ch]; 138 + else 139 + *val = st->data.buf16[ch]; 140 + } else { 141 + if (storagebits > 16) 142 + *val = sign_extend32(st->data.buf32[ch], 17); 143 + else 144 + *val = sign_extend32(st->data.buf16[ch], 15); 145 + } 351 146 352 147 error_ret: 353 148 gpiod_set_value(st->gpio_convst, 0); ··· 376 145 { 377 146 int ret, ch = 0; 378 147 struct ad7606_state *st = iio_priv(indio_dev); 148 + struct ad7606_chan_scale *cs; 379 149 380 150 switch (m) { 381 151 case IIO_CHAN_INFO_RAW: 382 152 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 383 - ret = ad7606_scan_direct(indio_dev, chan->address); 153 + ret = ad7606_scan_direct(indio_dev, chan->address, val); 384 154 if (ret < 0) 385 155 return ret; 386 - *val = (short) ret; 387 156 return IIO_VAL_INT; 388 157 } 389 158 unreachable(); 390 159 case IIO_CHAN_INFO_SCALE: 391 160 if (st->sw_mode_en) 392 161 ch = chan->address; 162 + cs = &st->chan_scales[ch]; 393 163 *val = 0; 394 - *val2 = st->scale_avail[st->range[ch]]; 164 + *val2 = cs->scale_avail[cs->range]; 395 165 return IIO_VAL_INT_PLUS_MICRO; 396 166 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 397 167 *val = st->oversampling; ··· 422 190 { 423 191 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 424 192 struct ad7606_state *st = iio_priv(indio_dev); 193 + struct ad7606_chan_scale *cs = &st->chan_scales[0]; 425 194 426 - return ad7606_show_avail(buf, st->scale_avail, st->num_scales, true); 195 + return ad7606_show_avail(buf, cs->scale_avail, cs->num_scales, true); 427 196 } 428 197 429 198 static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0); ··· 462 229 long mask) 463 230 { 464 231 struct ad7606_state *st = iio_priv(indio_dev); 232 + struct ad7606_chan_scale *cs; 465 233 int i, ret, ch = 0; 466 234 467 235 guard(mutex)(&st->lock); 468 236 469 237 switch (mask) { 470 238 case IIO_CHAN_INFO_SCALE: 471 - i = find_closest(val2, st->scale_avail, st->num_scales); 472 239 if (st->sw_mode_en) 473 240 ch = chan->address; 474 - ret = st->write_scale(indio_dev, ch, i); 241 + cs = &st->chan_scales[ch]; 242 + i = find_closest(val2, cs->scale_avail, cs->num_scales); 243 + ret = st->write_scale(indio_dev, ch, i + cs->reg_offset); 475 244 if (ret < 0) 476 245 return ret; 477 - st->range[ch] = i; 246 + cs->range = i; 478 247 479 248 return 0; 480 249 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: ··· 544 309 AD7605_CHANNEL(3), 545 310 }; 546 311 547 - static const struct iio_chan_spec ad7606_channels[] = { 312 + static const struct iio_chan_spec ad7606_channels_16bit[] = { 548 313 IIO_CHAN_SOFT_TIMESTAMP(8), 549 - AD7606_CHANNEL(0), 550 - AD7606_CHANNEL(1), 551 - AD7606_CHANNEL(2), 552 - AD7606_CHANNEL(3), 553 - AD7606_CHANNEL(4), 554 - AD7606_CHANNEL(5), 555 - AD7606_CHANNEL(6), 556 - AD7606_CHANNEL(7), 314 + AD7606_CHANNEL(0, 16), 315 + AD7606_CHANNEL(1, 16), 316 + AD7606_CHANNEL(2, 16), 317 + AD7606_CHANNEL(3, 16), 318 + AD7606_CHANNEL(4, 16), 319 + AD7606_CHANNEL(5, 16), 320 + AD7606_CHANNEL(6, 16), 321 + AD7606_CHANNEL(7, 16), 322 + }; 323 + 324 + static const struct iio_chan_spec ad7606_channels_18bit[] = { 325 + IIO_CHAN_SOFT_TIMESTAMP(8), 326 + AD7606_CHANNEL(0, 18), 327 + AD7606_CHANNEL(1, 18), 328 + AD7606_CHANNEL(2, 18), 329 + AD7606_CHANNEL(3, 18), 330 + AD7606_CHANNEL(4, 18), 331 + AD7606_CHANNEL(5, 18), 332 + AD7606_CHANNEL(6, 18), 333 + AD7606_CHANNEL(7, 18), 557 334 }; 558 335 559 336 /* ··· 580 333 */ 581 334 static const struct iio_chan_spec ad7616_channels[] = { 582 335 IIO_CHAN_SOFT_TIMESTAMP(16), 583 - AD7606_CHANNEL(0), 584 - AD7606_CHANNEL(1), 585 - AD7606_CHANNEL(2), 586 - AD7606_CHANNEL(3), 587 - AD7606_CHANNEL(4), 588 - AD7606_CHANNEL(5), 589 - AD7606_CHANNEL(6), 590 - AD7606_CHANNEL(7), 591 - AD7606_CHANNEL(8), 592 - AD7606_CHANNEL(9), 593 - AD7606_CHANNEL(10), 594 - AD7606_CHANNEL(11), 595 - AD7606_CHANNEL(12), 596 - AD7606_CHANNEL(13), 597 - AD7606_CHANNEL(14), 598 - AD7606_CHANNEL(15), 336 + AD7606_CHANNEL(0, 16), 337 + AD7606_CHANNEL(1, 16), 338 + AD7606_CHANNEL(2, 16), 339 + AD7606_CHANNEL(3, 16), 340 + AD7606_CHANNEL(4, 16), 341 + AD7606_CHANNEL(5, 16), 342 + AD7606_CHANNEL(6, 16), 343 + AD7606_CHANNEL(7, 16), 344 + AD7606_CHANNEL(8, 16), 345 + AD7606_CHANNEL(9, 16), 346 + AD7606_CHANNEL(10, 16), 347 + AD7606_CHANNEL(11, 16), 348 + AD7606_CHANNEL(12, 16), 349 + AD7606_CHANNEL(13, 16), 350 + AD7606_CHANNEL(14, 16), 351 + AD7606_CHANNEL(15, 16), 599 352 }; 600 353 601 354 static const struct ad7606_chip_info ad7606_chip_info_tbl[] = { ··· 603 356 [ID_AD7605_4] = { 604 357 .channels = ad7605_channels, 605 358 .num_channels = 5, 359 + .scale_setup_cb = ad7606_16bit_chan_scale_setup, 606 360 }, 607 361 [ID_AD7606_8] = { 608 - .channels = ad7606_channels, 362 + .channels = ad7606_channels_16bit, 609 363 .num_channels = 9, 364 + .scale_setup_cb = ad7606_16bit_chan_scale_setup, 610 365 .oversampling_avail = ad7606_oversampling_avail, 611 366 .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 612 367 }, 613 368 [ID_AD7606_6] = { 614 - .channels = ad7606_channels, 369 + .channels = ad7606_channels_16bit, 615 370 .num_channels = 7, 371 + .scale_setup_cb = ad7606_16bit_chan_scale_setup, 616 372 .oversampling_avail = ad7606_oversampling_avail, 617 373 .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 618 374 }, 619 375 [ID_AD7606_4] = { 620 - .channels = ad7606_channels, 376 + .channels = ad7606_channels_16bit, 621 377 .num_channels = 5, 378 + .scale_setup_cb = ad7606_16bit_chan_scale_setup, 622 379 .oversampling_avail = ad7606_oversampling_avail, 623 380 .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 624 381 }, 625 382 [ID_AD7606B] = { 626 - .channels = ad7606_channels, 383 + .channels = ad7606_channels_16bit, 627 384 .num_channels = 9, 385 + .scale_setup_cb = ad7606_16bit_chan_scale_setup, 386 + .oversampling_avail = ad7606_oversampling_avail, 387 + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 388 + }, 389 + [ID_AD7606C_16] = { 390 + .channels = ad7606_channels_16bit, 391 + .num_channels = 9, 392 + .scale_setup_cb = ad7606c_16bit_chan_scale_setup, 393 + .oversampling_avail = ad7606_oversampling_avail, 394 + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 395 + }, 396 + [ID_AD7606C_18] = { 397 + .channels = ad7606_channels_18bit, 398 + .num_channels = 9, 399 + .scale_setup_cb = ad7606c_18bit_chan_scale_setup, 628 400 .oversampling_avail = ad7606_oversampling_avail, 629 401 .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 630 402 }, 631 403 [ID_AD7616] = { 632 404 .channels = ad7616_channels, 633 405 .num_channels = 17, 406 + .scale_setup_cb = ad7606_16bit_chan_scale_setup, 634 407 .oversampling_avail = ad7616_oversampling_avail, 635 408 .oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail), 636 409 .os_req_reset = true, ··· 745 478 return 0; 746 479 } 747 480 481 + static int ad7606_read_avail(struct iio_dev *indio_dev, 482 + struct iio_chan_spec const *chan, 483 + const int **vals, int *type, int *length, 484 + long info) 485 + { 486 + struct ad7606_state *st = iio_priv(indio_dev); 487 + struct ad7606_chan_scale *cs; 488 + unsigned int ch = 0; 489 + 490 + switch (info) { 491 + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 492 + *vals = st->oversampling_avail; 493 + *length = st->num_os_ratios; 494 + *type = IIO_VAL_INT; 495 + 496 + return IIO_AVAIL_LIST; 497 + 498 + case IIO_CHAN_INFO_SCALE: 499 + if (st->sw_mode_en) 500 + ch = chan->address; 501 + 502 + cs = &st->chan_scales[ch]; 503 + *vals = cs->scale_avail_show; 504 + *length = cs->num_scales * 2; 505 + *type = IIO_VAL_INT_PLUS_MICRO; 506 + 507 + return IIO_AVAIL_LIST; 508 + } 509 + return -EINVAL; 510 + } 511 + 748 512 static const struct iio_buffer_setup_ops ad7606_buffer_ops = { 749 513 .postenable = &ad7606_buffer_postenable, 750 514 .predisable = &ad7606_buffer_predisable, ··· 793 495 .validate_trigger = &ad7606_validate_trigger, 794 496 }; 795 497 796 - static const struct iio_info ad7606_info_os_range_and_debug = { 498 + static const struct iio_info ad7606_info_sw_mode = { 797 499 .read_raw = &ad7606_read_raw, 798 500 .write_raw = &ad7606_write_raw, 501 + .read_avail = &ad7606_read_avail, 799 502 .debugfs_reg_access = &ad7606_reg_access, 800 - .attrs = &ad7606_attribute_group_os_and_range, 801 503 .validate_trigger = &ad7606_validate_trigger, 802 504 }; 803 505 ··· 819 521 .validate_device = iio_trigger_validate_own_device, 820 522 }; 821 523 524 + static int ad7606_sw_mode_setup(struct iio_dev *indio_dev, unsigned int id) 525 + { 526 + struct ad7606_state *st = iio_priv(indio_dev); 527 + 528 + st->sw_mode_en = st->bops->sw_mode_config && 529 + device_property_present(st->dev, "adi,sw-mode"); 530 + if (!st->sw_mode_en) 531 + return 0; 532 + 533 + indio_dev->info = &ad7606_info_sw_mode; 534 + 535 + return st->bops->sw_mode_config(indio_dev); 536 + } 537 + 538 + static int ad7606_chan_scales_setup(struct iio_dev *indio_dev) 539 + { 540 + unsigned int num_channels = indio_dev->num_channels - 1; 541 + struct ad7606_state *st = iio_priv(indio_dev); 542 + struct iio_chan_spec *chans; 543 + size_t size; 544 + int ch, ret; 545 + 546 + /* Clone IIO channels, since some may be differential */ 547 + size = indio_dev->num_channels * sizeof(*indio_dev->channels); 548 + chans = devm_kzalloc(st->dev, size, GFP_KERNEL); 549 + if (!chans) 550 + return -ENOMEM; 551 + 552 + memcpy(chans, indio_dev->channels, size); 553 + indio_dev->channels = chans; 554 + 555 + for (ch = 0; ch < num_channels; ch++) { 556 + struct ad7606_chan_scale *cs; 557 + int i; 558 + 559 + ret = st->chip_info->scale_setup_cb(st, &chans[ch + 1], ch); 560 + if (ret) 561 + return ret; 562 + 563 + cs = &st->chan_scales[ch]; 564 + 565 + if (cs->num_scales * 2 > AD760X_MAX_SCALE_SHOW) 566 + return dev_err_probe(st->dev, -ERANGE, 567 + "Driver error: scale range too big"); 568 + 569 + /* Generate a scale_avail list for showing to userspace */ 570 + for (i = 0; i < cs->num_scales; i++) { 571 + cs->scale_avail_show[i * 2] = 0; 572 + cs->scale_avail_show[i * 2 + 1] = cs->scale_avail[i]; 573 + } 574 + } 575 + 576 + return 0; 577 + } 578 + 822 579 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, 823 580 const char *name, unsigned int id, 824 581 const struct ad7606_bus_ops *bops) ··· 893 540 mutex_init(&st->lock); 894 541 st->bops = bops; 895 542 st->base_address = base_address; 896 - /* tied to logic low, analog input range is +/- 5V */ 897 - st->range[0] = 0; 898 543 st->oversampling = 1; 899 - st->scale_avail = ad7606_scale_avail; 900 - st->num_scales = ARRAY_SIZE(ad7606_scale_avail); 901 544 902 545 ret = devm_regulator_get_enable(dev, "avcc"); 903 546 if (ret) ··· 942 593 st->write_scale = ad7606_write_scale_hw; 943 594 st->write_os = ad7606_write_os_hw; 944 595 945 - if (st->bops->sw_mode_config) 946 - st->sw_mode_en = device_property_present(st->dev, 947 - "adi,sw-mode"); 596 + ret = ad7606_sw_mode_setup(indio_dev, id); 597 + if (ret) 598 + return ret; 948 599 949 - if (st->sw_mode_en) { 950 - /* Scale of 0.076293 is only available in sw mode */ 951 - st->scale_avail = ad7616_sw_scale_avail; 952 - st->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail); 953 - 954 - /* After reset, in software mode, ±10 V is set by default */ 955 - memset32(st->range, 2, ARRAY_SIZE(st->range)); 956 - indio_dev->info = &ad7606_info_os_range_and_debug; 957 - 958 - ret = st->bops->sw_mode_config(indio_dev); 959 - if (ret < 0) 960 - return ret; 961 - } 600 + ret = ad7606_chan_scales_setup(indio_dev); 601 + if (ret) 602 + return ret; 962 603 963 604 st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", 964 605 indio_dev->name, ··· 1004 665 struct ad7606_state *st = iio_priv(indio_dev); 1005 666 1006 667 if (st->gpio_standby) { 1007 - gpiod_set_value(st->gpio_range, st->range[0]); 668 + gpiod_set_value(st->gpio_range, st->chan_scales[0].range); 1008 669 gpiod_set_value(st->gpio_standby, 1); 1009 670 ad7606_reset(st); 1010 671 }
+70 -18
drivers/iio/adc/ad7606.h
··· 8 8 #ifndef IIO_ADC_AD7606_H_ 9 9 #define IIO_ADC_AD7606_H_ 10 10 11 - #define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all) { \ 11 + #define AD760X_MAX_CHANNELS 16 12 + 13 + #define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, bits) { \ 12 14 .type = IIO_VOLTAGE, \ 13 15 .indexed = 1, \ 14 16 .channel = num, \ ··· 21 19 .scan_index = num, \ 22 20 .scan_type = { \ 23 21 .sign = 's', \ 24 - .realbits = 16, \ 25 - .storagebits = 16, \ 22 + .realbits = (bits), \ 23 + .storagebits = (bits) > 16 ? 32 : 16, \ 24 + .endianness = IIO_CPU, \ 25 + }, \ 26 + } 27 + 28 + #define AD7606_SW_CHANNEL(num, bits) { \ 29 + .type = IIO_VOLTAGE, \ 30 + .indexed = 1, \ 31 + .channel = num, \ 32 + .address = num, \ 33 + .info_mask_separate = \ 34 + BIT(IIO_CHAN_INFO_RAW) | \ 35 + BIT(IIO_CHAN_INFO_SCALE), \ 36 + .info_mask_separate_available = \ 37 + BIT(IIO_CHAN_INFO_SCALE), \ 38 + .info_mask_shared_by_all = \ 39 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 40 + .info_mask_shared_by_all_available = \ 41 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 42 + .scan_index = num, \ 43 + .scan_type = { \ 44 + .sign = 's', \ 45 + .realbits = (bits), \ 46 + .storagebits = (bits) > 16 ? 32 : 16, \ 26 47 .endianness = IIO_CPU, \ 27 48 }, \ 28 49 } 29 50 30 51 #define AD7605_CHANNEL(num) \ 31 52 AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \ 32 - BIT(IIO_CHAN_INFO_SCALE), 0) 53 + BIT(IIO_CHAN_INFO_SCALE), 0, 16) 33 54 34 - #define AD7606_CHANNEL(num) \ 55 + #define AD7606_CHANNEL(num, bits) \ 35 56 AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \ 36 57 BIT(IIO_CHAN_INFO_SCALE), \ 37 - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO)) 58 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits) 38 59 39 - #define AD7616_CHANNEL(num) \ 40 - AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),\ 41 - 0, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO)) 60 + #define AD7616_CHANNEL(num) AD7606_SW_CHANNEL(num, 16) 61 + 62 + struct ad7606_state; 63 + 64 + typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st, 65 + struct iio_chan_spec *chan, int ch); 42 66 43 67 /** 44 68 * struct ad7606_chip_info - chip specific information 45 69 * @channels: channel specification 46 70 * @num_channels: number of channels 71 + * @scale_setup_cb: callback to setup the scales for each channel 47 72 * @oversampling_avail pointer to the array which stores the available 48 73 * oversampling ratios. 49 74 * @oversampling_num number of elements stored in oversampling_avail array 50 75 * @os_req_reset some devices require a reset to update oversampling 51 - * @init_delay_ms required delay in miliseconds for initialization 76 + * @init_delay_ms required delay in milliseconds for initialization 52 77 * after a restart 53 78 */ 54 79 struct ad7606_chip_info { 55 80 const struct iio_chan_spec *channels; 56 81 unsigned int num_channels; 82 + ad7606_scale_setup_cb_t scale_setup_cb; 57 83 const unsigned int *oversampling_avail; 58 84 unsigned int oversampling_num; 59 85 bool os_req_reset; ··· 89 59 }; 90 60 91 61 /** 62 + * struct ad7606_chan_scale - channel scale configuration 63 + * @scale_avail pointer to the array which stores the available scales 64 + * @scale_avail_show a duplicate of 'scale_avail' which is readily formatted 65 + * such that it can be read via the 'read_avail' hook 66 + * @num_scales number of elements stored in the scale_avail array 67 + * @range voltage range selection, selects which scale to apply 68 + * @reg_offset offset for the register value, to be applied when 69 + * writing the value of 'range' to the register value 70 + */ 71 + struct ad7606_chan_scale { 72 + #define AD760X_MAX_SCALES 16 73 + #define AD760X_MAX_SCALE_SHOW (AD760X_MAX_SCALES * 2) 74 + const unsigned int *scale_avail; 75 + int scale_avail_show[AD760X_MAX_SCALE_SHOW]; 76 + unsigned int num_scales; 77 + unsigned int range; 78 + unsigned int reg_offset; 79 + }; 80 + 81 + /** 92 82 * struct ad7606_state - driver instance specific data 93 83 * @dev pointer to kernel device 94 84 * @chip_info entry in the table of chips that describes this device 95 85 * @bops bus operations (SPI or parallel) 96 - * @range voltage range selection, selects which scale to apply 86 + * @chan_scales scale configuration for channels 97 87 * @oversampling oversampling selection 98 88 * @base_address address from where to read data in parallel operation 99 89 * @sw_mode_en software mode enabled 100 - * @scale_avail pointer to the array which stores the available scales 101 - * @num_scales number of elements stored in the scale_avail array 102 90 * @oversampling_avail pointer to the array which stores the available 103 91 * oversampling ratios. 104 92 * @num_os_ratios number of elements stored in oversampling_avail array ··· 140 92 struct device *dev; 141 93 const struct ad7606_chip_info *chip_info; 142 94 const struct ad7606_bus_ops *bops; 143 - unsigned int range[16]; 95 + struct ad7606_chan_scale chan_scales[AD760X_MAX_CHANNELS]; 144 96 unsigned int oversampling; 145 97 void __iomem *base_address; 146 98 bool sw_mode_en; 147 - const unsigned int *scale_avail; 148 - unsigned int num_scales; 149 99 const unsigned int *oversampling_avail; 150 100 unsigned int num_os_ratios; 151 101 int (*write_scale)(struct iio_dev *indio_dev, int ch, int val); ··· 162 116 /* 163 117 * DMA (thus cache coherency maintenance) may require the 164 118 * transfer buffers to live in their own cache lines. 165 - * 16 * 16-bit samples + 64-bit timestamp 119 + * 16 * 16-bit samples + 64-bit timestamp - for AD7616 120 + * 8 * 32-bit samples + 64-bit timestamp - for AD7616C-18 (and similar) 166 121 */ 167 - unsigned short data[20] __aligned(IIO_DMA_MINALIGN); 122 + union { 123 + u16 buf16[20]; 124 + u32 buf32[10]; 125 + } data __aligned(IIO_DMA_MINALIGN); 168 126 __be16 d16[2]; 169 127 }; 170 128 ··· 209 159 ID_AD7606_6, 210 160 ID_AD7606_4, 211 161 ID_AD7606B, 162 + ID_AD7606C_16, 163 + ID_AD7606C_18, 212 164 ID_AD7616, 213 165 }; 214 166
+3 -3
drivers/iio/adc/ad7606_par.c
··· 5 5 * Copyright 2011 Analog Devices Inc. 6 6 */ 7 7 8 + #include <linux/err.h> 9 + #include <linux/gpio/consumer.h> 10 + #include <linux/io.h> 8 11 #include <linux/mod_devicetable.h> 9 12 #include <linux/module.h> 10 - #include <linux/gpio/consumer.h> 11 13 #include <linux/platform_device.h> 12 14 #include <linux/types.h> 13 - #include <linux/err.h> 14 - #include <linux/io.h> 15 15 16 16 #include <linux/iio/iio.h> 17 17 #include "ad7606.h"
+64 -9
drivers/iio/adc/ad7606_spi.c
··· 5 5 * Copyright 2011 Analog Devices Inc. 6 6 */ 7 7 8 + #include <linux/err.h> 8 9 #include <linux/module.h> 9 10 #include <linux/spi/spi.h> 10 11 #include <linux/types.h> 11 - #include <linux/err.h> 12 12 13 13 #include <linux/iio/iio.h> 14 14 #include "ad7606.h" ··· 67 67 68 68 static const struct iio_chan_spec ad7606b_sw_channels[] = { 69 69 IIO_CHAN_SOFT_TIMESTAMP(8), 70 - AD7616_CHANNEL(0), 71 - AD7616_CHANNEL(1), 72 - AD7616_CHANNEL(2), 73 - AD7616_CHANNEL(3), 74 - AD7616_CHANNEL(4), 75 - AD7616_CHANNEL(5), 76 - AD7616_CHANNEL(6), 77 - AD7616_CHANNEL(7), 70 + AD7606_SW_CHANNEL(0, 16), 71 + AD7606_SW_CHANNEL(1, 16), 72 + AD7606_SW_CHANNEL(2, 16), 73 + AD7606_SW_CHANNEL(3, 16), 74 + AD7606_SW_CHANNEL(4, 16), 75 + AD7606_SW_CHANNEL(5, 16), 76 + AD7606_SW_CHANNEL(6, 16), 77 + AD7606_SW_CHANNEL(7, 16), 78 + }; 79 + 80 + static const struct iio_chan_spec ad7606c_18_sw_channels[] = { 81 + IIO_CHAN_SOFT_TIMESTAMP(8), 82 + AD7606_SW_CHANNEL(0, 18), 83 + AD7606_SW_CHANNEL(1, 18), 84 + AD7606_SW_CHANNEL(2, 18), 85 + AD7606_SW_CHANNEL(3, 18), 86 + AD7606_SW_CHANNEL(4, 18), 87 + AD7606_SW_CHANNEL(5, 18), 88 + AD7606_SW_CHANNEL(6, 18), 89 + AD7606_SW_CHANNEL(7, 18), 78 90 }; 79 91 80 92 static const unsigned int ad7606B_oversampling_avail[9] = { ··· 130 118 data[i] = be16_to_cpu(bdata[i]); 131 119 132 120 return 0; 121 + } 122 + 123 + static int ad7606_spi_read_block18to32(struct device *dev, 124 + int count, void *buf) 125 + { 126 + struct spi_device *spi = to_spi_device(dev); 127 + struct spi_transfer xfer = { 128 + .bits_per_word = 18, 129 + .len = count * sizeof(u32), 130 + .rx_buf = buf, 131 + }; 132 + 133 + return spi_sync_transfer(spi, &xfer, 1); 133 134 } 134 135 135 136 static int ad7606_spi_reg_read(struct ad7606_state *st, unsigned int addr) ··· 308 283 return 0; 309 284 } 310 285 286 + static int ad7606c_18_sw_mode_config(struct iio_dev *indio_dev) 287 + { 288 + int ret; 289 + 290 + ret = ad7606B_sw_mode_config(indio_dev); 291 + if (ret) 292 + return ret; 293 + 294 + indio_dev->channels = ad7606c_18_sw_channels; 295 + 296 + return 0; 297 + } 298 + 311 299 static const struct ad7606_bus_ops ad7606_spi_bops = { 312 300 .read_block = ad7606_spi_read_block, 313 301 }; ··· 343 305 .sw_mode_config = ad7606B_sw_mode_config, 344 306 }; 345 307 308 + static const struct ad7606_bus_ops ad7606c_18_spi_bops = { 309 + .read_block = ad7606_spi_read_block18to32, 310 + .reg_read = ad7606_spi_reg_read, 311 + .reg_write = ad7606_spi_reg_write, 312 + .write_mask = ad7606_spi_write_mask, 313 + .rd_wr_cmd = ad7606B_spi_rd_wr_cmd, 314 + .sw_mode_config = ad7606c_18_sw_mode_config, 315 + }; 316 + 346 317 static int ad7606_spi_probe(struct spi_device *spi) 347 318 { 348 319 const struct spi_device_id *id = spi_get_device_id(spi); ··· 362 315 bops = &ad7616_spi_bops; 363 316 break; 364 317 case ID_AD7606B: 318 + case ID_AD7606C_16: 365 319 bops = &ad7606B_spi_bops; 320 + break; 321 + case ID_AD7606C_18: 322 + bops = &ad7606c_18_spi_bops; 366 323 break; 367 324 default: 368 325 bops = &ad7606_spi_bops; ··· 384 333 { "ad7606-6", ID_AD7606_6 }, 385 334 { "ad7606-8", ID_AD7606_8 }, 386 335 { "ad7606b", ID_AD7606B }, 336 + { "ad7606c-16", ID_AD7606C_16 }, 337 + { "ad7606c-18", ID_AD7606C_18 }, 387 338 { "ad7616", ID_AD7616 }, 388 339 { } 389 340 }; ··· 397 344 { .compatible = "adi,ad7606-6" }, 398 345 { .compatible = "adi,ad7606-8" }, 399 346 { .compatible = "adi,ad7606b" }, 347 + { .compatible = "adi,ad7606c-16" }, 348 + { .compatible = "adi,ad7606c-18" }, 400 349 { .compatible = "adi,ad7616" }, 401 350 { } 402 351 };
+684
drivers/iio/adc/ad7625.c
··· 1 + // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) 2 + /* 3 + * Analog Devices Inc. AD7625 ADC driver 4 + * 5 + * Copyright 2024 Analog Devices Inc. 6 + * Copyright 2024 BayLibre, SAS 7 + * 8 + * Note that this driver requires the AXI ADC IP block configured for 9 + * LVDS to function. See Documentation/iio/ad7625.rst for more 10 + * information. 11 + */ 12 + 13 + #include <linux/clk.h> 14 + #include <linux/device.h> 15 + #include <linux/err.h> 16 + #include <linux/gpio/consumer.h> 17 + #include <linux/iio/backend.h> 18 + #include <linux/iio/iio.h> 19 + #include <linux/kernel.h> 20 + #include <linux/mod_devicetable.h> 21 + #include <linux/module.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/pwm.h> 24 + #include <linux/regulator/consumer.h> 25 + #include <linux/units.h> 26 + 27 + #define AD7625_INTERNAL_REF_MV 4096 28 + #define AD7960_MAX_NBW_FREQ (2 * MEGA) 29 + 30 + struct ad7625_timing_spec { 31 + /* Max conversion high time (t_{CNVH}). */ 32 + unsigned int conv_high_ns; 33 + /* Max conversion to MSB delay (t_{MSB}). */ 34 + unsigned int conv_msb_ns; 35 + }; 36 + 37 + struct ad7625_chip_info { 38 + const char *name; 39 + const unsigned int max_sample_freq_hz; 40 + const struct ad7625_timing_spec *timing_spec; 41 + const struct iio_chan_spec chan_spec; 42 + const bool has_power_down_state; 43 + const bool has_bandwidth_control; 44 + const bool has_internal_vref; 45 + }; 46 + 47 + /* AD7625_CHAN_SPEC - Define a chan spec structure for a specific chip */ 48 + #define AD7625_CHAN_SPEC(_bits) { \ 49 + .type = IIO_VOLTAGE, \ 50 + .indexed = 1, \ 51 + .differential = 1, \ 52 + .channel = 0, \ 53 + .channel2 = 1, \ 54 + .info_mask_separate = BIT(IIO_CHAN_INFO_SCALE), \ 55 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 56 + .scan_index = 0, \ 57 + .scan_type.sign = 's', \ 58 + .scan_type.storagebits = (_bits) > 16 ? 32 : 16, \ 59 + .scan_type.realbits = (_bits), \ 60 + } 61 + 62 + struct ad7625_state { 63 + const struct ad7625_chip_info *info; 64 + struct iio_backend *back; 65 + /* rate of the clock gated by the "clk_gate" PWM */ 66 + u32 ref_clk_rate_hz; 67 + /* PWM burst signal for transferring acquired data to the host */ 68 + struct pwm_device *clk_gate_pwm; 69 + /* 70 + * PWM control signal for initiating data conversion. Analog 71 + * inputs are sampled beginning on this signal's rising edge. 72 + */ 73 + struct pwm_device *cnv_pwm; 74 + /* 75 + * Waveforms containing the last-requested and rounded 76 + * properties for the clk_gate and cnv PWMs 77 + */ 78 + struct pwm_waveform clk_gate_wf; 79 + struct pwm_waveform cnv_wf; 80 + unsigned int vref_mv; 81 + u32 sampling_freq_hz; 82 + /* 83 + * Optional GPIOs for controlling device state. EN0 and EN1 84 + * determine voltage reference configuration and on/off state. 85 + * EN2 controls the device -3dB bandwidth (and by extension, max 86 + * sample rate). EN3 controls the VCM reference output. EN2 and 87 + * EN3 are only present for the AD796x devices. 88 + */ 89 + struct gpio_desc *en_gpios[4]; 90 + bool can_power_down; 91 + bool can_refin; 92 + bool can_ref_4v096; 93 + /* 94 + * Indicate whether the bandwidth can be narrow (9MHz). 95 + * When true, device sample rate must also be < 2MSPS. 96 + */ 97 + bool can_narrow_bandwidth; 98 + /* Indicate whether the bandwidth can be wide (28MHz). */ 99 + bool can_wide_bandwidth; 100 + bool can_ref_5v; 101 + bool can_snooze; 102 + bool can_test_pattern; 103 + /* Indicate whether there is a REFIN supply connected */ 104 + bool have_refin; 105 + }; 106 + 107 + static const struct ad7625_timing_spec ad7625_timing_spec = { 108 + .conv_high_ns = 40, 109 + .conv_msb_ns = 145, 110 + }; 111 + 112 + static const struct ad7625_timing_spec ad7626_timing_spec = { 113 + .conv_high_ns = 40, 114 + .conv_msb_ns = 80, 115 + }; 116 + 117 + /* 118 + * conv_msb_ns is set to 0 instead of the datasheet maximum of 200ns to 119 + * avoid exceeding the minimum conversion time, i.e. it is effectively 120 + * modulo 200 and offset by a full period. Values greater than or equal 121 + * to the period would be rejected by the PWM API. 122 + */ 123 + static const struct ad7625_timing_spec ad7960_timing_spec = { 124 + .conv_high_ns = 80, 125 + .conv_msb_ns = 0, 126 + }; 127 + 128 + static const struct ad7625_chip_info ad7625_chip_info = { 129 + .name = "ad7625", 130 + .max_sample_freq_hz = 6 * MEGA, 131 + .timing_spec = &ad7625_timing_spec, 132 + .chan_spec = AD7625_CHAN_SPEC(16), 133 + .has_power_down_state = false, 134 + .has_bandwidth_control = false, 135 + .has_internal_vref = true, 136 + }; 137 + 138 + static const struct ad7625_chip_info ad7626_chip_info = { 139 + .name = "ad7626", 140 + .max_sample_freq_hz = 10 * MEGA, 141 + .timing_spec = &ad7626_timing_spec, 142 + .chan_spec = AD7625_CHAN_SPEC(16), 143 + .has_power_down_state = true, 144 + .has_bandwidth_control = false, 145 + .has_internal_vref = true, 146 + }; 147 + 148 + static const struct ad7625_chip_info ad7960_chip_info = { 149 + .name = "ad7960", 150 + .max_sample_freq_hz = 5 * MEGA, 151 + .timing_spec = &ad7960_timing_spec, 152 + .chan_spec = AD7625_CHAN_SPEC(18), 153 + .has_power_down_state = true, 154 + .has_bandwidth_control = true, 155 + .has_internal_vref = false, 156 + }; 157 + 158 + static const struct ad7625_chip_info ad7961_chip_info = { 159 + .name = "ad7961", 160 + .max_sample_freq_hz = 5 * MEGA, 161 + .timing_spec = &ad7960_timing_spec, 162 + .chan_spec = AD7625_CHAN_SPEC(16), 163 + .has_power_down_state = true, 164 + .has_bandwidth_control = true, 165 + .has_internal_vref = false, 166 + }; 167 + 168 + enum ad7960_mode { 169 + AD7960_MODE_POWER_DOWN, 170 + AD7960_MODE_SNOOZE, 171 + AD7960_MODE_NARROW_BANDWIDTH, 172 + AD7960_MODE_WIDE_BANDWIDTH, 173 + AD7960_MODE_TEST_PATTERN, 174 + }; 175 + 176 + static int ad7625_set_sampling_freq(struct ad7625_state *st, u32 freq) 177 + { 178 + u32 target; 179 + struct pwm_waveform clk_gate_wf = { }, cnv_wf = { }; 180 + int ret; 181 + 182 + target = DIV_ROUND_UP(NSEC_PER_SEC, freq); 183 + cnv_wf.period_length_ns = clamp(target, 100, 10 * KILO); 184 + 185 + /* 186 + * Use the maximum conversion time t_CNVH from the datasheet as 187 + * the duty_cycle for ref_clk, cnv, and clk_gate 188 + */ 189 + cnv_wf.duty_length_ns = st->info->timing_spec->conv_high_ns; 190 + 191 + ret = pwm_round_waveform_might_sleep(st->cnv_pwm, &cnv_wf); 192 + if (ret) 193 + return ret; 194 + 195 + /* 196 + * Set up the burst signal for transferring data. period and 197 + * offset should mirror the CNV signal 198 + */ 199 + clk_gate_wf.period_length_ns = cnv_wf.period_length_ns; 200 + 201 + clk_gate_wf.duty_length_ns = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC * 202 + st->info->chan_spec.scan_type.realbits, 203 + st->ref_clk_rate_hz); 204 + 205 + /* max t_MSB from datasheet */ 206 + clk_gate_wf.duty_offset_ns = st->info->timing_spec->conv_msb_ns; 207 + 208 + ret = pwm_round_waveform_might_sleep(st->clk_gate_pwm, &clk_gate_wf); 209 + if (ret) 210 + return ret; 211 + 212 + st->cnv_wf = cnv_wf; 213 + st->clk_gate_wf = clk_gate_wf; 214 + 215 + /* TODO: Add a rounding API for PWMs that can simplify this */ 216 + target = DIV_ROUND_CLOSEST(st->ref_clk_rate_hz, freq); 217 + st->sampling_freq_hz = DIV_ROUND_CLOSEST(st->ref_clk_rate_hz, 218 + target); 219 + 220 + return 0; 221 + } 222 + 223 + static int ad7625_read_raw(struct iio_dev *indio_dev, 224 + const struct iio_chan_spec *chan, 225 + int *val, int *val2, long info) 226 + { 227 + struct ad7625_state *st = iio_priv(indio_dev); 228 + 229 + switch (info) { 230 + case IIO_CHAN_INFO_SAMP_FREQ: 231 + *val = st->sampling_freq_hz; 232 + 233 + return IIO_VAL_INT; 234 + 235 + case IIO_CHAN_INFO_SCALE: 236 + *val = st->vref_mv; 237 + *val2 = chan->scan_type.realbits - 1; 238 + 239 + return IIO_VAL_FRACTIONAL_LOG2; 240 + 241 + default: 242 + return -EINVAL; 243 + } 244 + } 245 + 246 + static int ad7625_write_raw(struct iio_dev *indio_dev, 247 + struct iio_chan_spec const *chan, 248 + int val, int val2, long info) 249 + { 250 + struct ad7625_state *st = iio_priv(indio_dev); 251 + 252 + switch (info) { 253 + case IIO_CHAN_INFO_SAMP_FREQ: 254 + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) 255 + return ad7625_set_sampling_freq(st, val); 256 + unreachable(); 257 + default: 258 + return -EINVAL; 259 + } 260 + } 261 + 262 + static int ad7625_parse_mode(struct device *dev, struct ad7625_state *st, 263 + int num_gpios) 264 + { 265 + bool en_always_on[4], en_always_off[4]; 266 + bool en_may_be_on[4], en_may_be_off[4]; 267 + char en_gpio_buf[4]; 268 + char always_on_buf[18]; 269 + int i; 270 + 271 + for (i = 0; i < num_gpios; i++) { 272 + snprintf(en_gpio_buf, sizeof(en_gpio_buf), "en%d", i); 273 + snprintf(always_on_buf, sizeof(always_on_buf), 274 + "adi,en%d-always-on", i); 275 + /* Set the device to 0b0000 (power-down mode) by default */ 276 + st->en_gpios[i] = devm_gpiod_get_optional(dev, en_gpio_buf, 277 + GPIOD_OUT_LOW); 278 + if (IS_ERR(st->en_gpios[i])) 279 + return dev_err_probe(dev, PTR_ERR(st->en_gpios[i]), 280 + "failed to get EN%d GPIO\n", i); 281 + 282 + en_always_on[i] = device_property_read_bool(dev, always_on_buf); 283 + if (st->en_gpios[i] && en_always_on[i]) 284 + return dev_err_probe(dev, -EINVAL, 285 + "cannot have adi,en%d-always-on and en%d-gpios\n", i, i); 286 + 287 + en_may_be_off[i] = !en_always_on[i]; 288 + en_may_be_on[i] = en_always_on[i] || st->en_gpios[i]; 289 + en_always_off[i] = !en_always_on[i] && !st->en_gpios[i]; 290 + } 291 + 292 + /* 293 + * Power down is mode 0bXX00, but not all devices have a valid 294 + * power down state. 295 + */ 296 + st->can_power_down = en_may_be_off[1] && en_may_be_off[0] && 297 + st->info->has_power_down_state; 298 + /* 299 + * The REFIN pin can take a 1.2V (AD762x) or 2.048V (AD796x) 300 + * external reference when the mode is 0bXX01. 301 + */ 302 + st->can_refin = en_may_be_off[1] && en_may_be_on[0]; 303 + /* 4.096V can be applied to REF when the EN mode is 0bXX10. */ 304 + st->can_ref_4v096 = en_may_be_on[1] && en_may_be_off[0]; 305 + 306 + /* Avoid AD796x-specific setup if the part is an AD762x */ 307 + if (num_gpios == 2) 308 + return 0; 309 + 310 + /* mode 0b1100 (AD796x) is invalid */ 311 + if (en_always_on[3] && en_always_on[2] && 312 + en_always_off[1] && en_always_off[0]) 313 + return dev_err_probe(dev, -EINVAL, 314 + "EN GPIOs set to invalid mode 0b1100\n"); 315 + /* 316 + * 5V can be applied to the AD796x REF pin when the EN mode is 317 + * the same (0bX001 or 0bX101) as for can_refin, and REFIN is 318 + * 0V. 319 + */ 320 + st->can_ref_5v = st->can_refin; 321 + /* 322 + * Bandwidth (AD796x) is controlled solely by EN2. If it's 323 + * specified and not hard-wired, then we can configure it to 324 + * change the bandwidth between 28MHz and 9MHz. 325 + */ 326 + st->can_narrow_bandwidth = en_may_be_on[2]; 327 + /* Wide bandwidth mode is possible if EN2 can be 0. */ 328 + st->can_wide_bandwidth = en_may_be_off[2]; 329 + /* Snooze mode (AD796x) is 0bXX11 when REFIN = 0V. */ 330 + st->can_snooze = en_may_be_on[1] && en_may_be_on[0]; 331 + /* Test pattern mode (AD796x) is 0b0100. */ 332 + st->can_test_pattern = en_may_be_off[3] && en_may_be_on[2] && 333 + en_may_be_off[1] && en_may_be_off[0]; 334 + 335 + return 0; 336 + } 337 + 338 + /* Set EN1 and EN0 based on reference voltage source */ 339 + static void ad7625_set_en_gpios_for_vref(struct ad7625_state *st, 340 + bool have_refin, int ref_mv) 341 + { 342 + if (have_refin || ref_mv == 5000) { 343 + gpiod_set_value_cansleep(st->en_gpios[1], 0); 344 + gpiod_set_value_cansleep(st->en_gpios[0], 1); 345 + } else if (ref_mv == 4096) { 346 + gpiod_set_value_cansleep(st->en_gpios[1], 1); 347 + gpiod_set_value_cansleep(st->en_gpios[0], 0); 348 + } else { 349 + /* 350 + * Unreachable by AD796x, since the driver will error if 351 + * neither REF nor REFIN is provided 352 + */ 353 + gpiod_set_value_cansleep(st->en_gpios[1], 1); 354 + gpiod_set_value_cansleep(st->en_gpios[0], 1); 355 + } 356 + } 357 + 358 + static int ad7960_set_mode(struct ad7625_state *st, enum ad7960_mode mode, 359 + bool have_refin, int ref_mv) 360 + { 361 + switch (mode) { 362 + case AD7960_MODE_POWER_DOWN: 363 + if (!st->can_power_down) 364 + return -EINVAL; 365 + 366 + gpiod_set_value_cansleep(st->en_gpios[2], 0); 367 + gpiod_set_value_cansleep(st->en_gpios[1], 0); 368 + gpiod_set_value_cansleep(st->en_gpios[0], 0); 369 + 370 + return 0; 371 + 372 + case AD7960_MODE_SNOOZE: 373 + if (!st->can_snooze) 374 + return -EINVAL; 375 + 376 + gpiod_set_value_cansleep(st->en_gpios[1], 1); 377 + gpiod_set_value_cansleep(st->en_gpios[0], 1); 378 + 379 + return 0; 380 + 381 + case AD7960_MODE_NARROW_BANDWIDTH: 382 + if (!st->can_narrow_bandwidth) 383 + return -EINVAL; 384 + 385 + gpiod_set_value_cansleep(st->en_gpios[2], 1); 386 + ad7625_set_en_gpios_for_vref(st, have_refin, ref_mv); 387 + 388 + return 0; 389 + 390 + case AD7960_MODE_WIDE_BANDWIDTH: 391 + if (!st->can_wide_bandwidth) 392 + return -EINVAL; 393 + 394 + gpiod_set_value_cansleep(st->en_gpios[2], 0); 395 + ad7625_set_en_gpios_for_vref(st, have_refin, ref_mv); 396 + 397 + return 0; 398 + 399 + case AD7960_MODE_TEST_PATTERN: 400 + if (!st->can_test_pattern) 401 + return -EINVAL; 402 + 403 + gpiod_set_value_cansleep(st->en_gpios[3], 0); 404 + gpiod_set_value_cansleep(st->en_gpios[2], 1); 405 + gpiod_set_value_cansleep(st->en_gpios[1], 0); 406 + gpiod_set_value_cansleep(st->en_gpios[0], 0); 407 + 408 + return 0; 409 + 410 + default: 411 + return -EINVAL; 412 + } 413 + } 414 + 415 + static int ad7625_buffer_preenable(struct iio_dev *indio_dev) 416 + { 417 + struct ad7625_state *st = iio_priv(indio_dev); 418 + int ret; 419 + 420 + ret = pwm_set_waveform_might_sleep(st->cnv_pwm, &st->cnv_wf, false); 421 + if (ret) 422 + return ret; 423 + 424 + ret = pwm_set_waveform_might_sleep(st->clk_gate_pwm, 425 + &st->clk_gate_wf, false); 426 + if (ret) { 427 + /* Disable cnv PWM if clk_gate setup failed */ 428 + pwm_disable(st->cnv_pwm); 429 + return ret; 430 + } 431 + 432 + return 0; 433 + } 434 + 435 + static int ad7625_buffer_postdisable(struct iio_dev *indio_dev) 436 + { 437 + struct ad7625_state *st = iio_priv(indio_dev); 438 + 439 + pwm_disable(st->clk_gate_pwm); 440 + pwm_disable(st->cnv_pwm); 441 + 442 + return 0; 443 + } 444 + 445 + static const struct iio_info ad7625_info = { 446 + .read_raw = ad7625_read_raw, 447 + .write_raw = ad7625_write_raw, 448 + }; 449 + 450 + static const struct iio_buffer_setup_ops ad7625_buffer_setup_ops = { 451 + .preenable = &ad7625_buffer_preenable, 452 + .postdisable = &ad7625_buffer_postdisable, 453 + }; 454 + 455 + static int devm_ad7625_pwm_get(struct device *dev, 456 + struct ad7625_state *st) 457 + { 458 + struct clk *ref_clk; 459 + u32 ref_clk_rate_hz; 460 + 461 + st->cnv_pwm = devm_pwm_get(dev, "cnv"); 462 + if (IS_ERR(st->cnv_pwm)) 463 + return dev_err_probe(dev, PTR_ERR(st->cnv_pwm), 464 + "failed to get cnv pwm\n"); 465 + 466 + /* Preemptively disable the PWM in case it was enabled at boot */ 467 + pwm_disable(st->cnv_pwm); 468 + 469 + st->clk_gate_pwm = devm_pwm_get(dev, "clk_gate"); 470 + if (IS_ERR(st->clk_gate_pwm)) 471 + return dev_err_probe(dev, PTR_ERR(st->clk_gate_pwm), 472 + "failed to get clk_gate pwm\n"); 473 + 474 + /* Preemptively disable the PWM in case it was enabled at boot */ 475 + pwm_disable(st->clk_gate_pwm); 476 + 477 + ref_clk = devm_clk_get_enabled(dev, NULL); 478 + if (IS_ERR(ref_clk)) 479 + return dev_err_probe(dev, PTR_ERR(ref_clk), 480 + "failed to get ref_clk"); 481 + 482 + ref_clk_rate_hz = clk_get_rate(ref_clk); 483 + if (!ref_clk_rate_hz) 484 + return dev_err_probe(dev, -EINVAL, 485 + "failed to get ref_clk rate"); 486 + 487 + st->ref_clk_rate_hz = ref_clk_rate_hz; 488 + 489 + return 0; 490 + } 491 + 492 + /* 493 + * There are three required input voltages for each device, plus two 494 + * conditionally-optional (depending on part) REF and REFIN voltages 495 + * where their validity depends upon the EN pin configuration. 496 + * 497 + * Power-up info for the device says to bring up vio, then vdd2, then 498 + * vdd1, so list them in that order in the regulator_names array. 499 + * 500 + * The reference voltage source is determined like so: 501 + * - internal reference: neither REF or REFIN is connected (invalid for 502 + * AD796x) 503 + * - internal buffer, external reference: REF not connected, REFIN 504 + * connected 505 + * - external reference: REF connected, REFIN not connected 506 + */ 507 + static int devm_ad7625_regulator_setup(struct device *dev, 508 + struct ad7625_state *st) 509 + { 510 + static const char * const regulator_names[] = { "vio", "vdd2", "vdd1" }; 511 + int ret, ref_mv; 512 + 513 + ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names), 514 + regulator_names); 515 + if (ret) 516 + return ret; 517 + 518 + ret = devm_regulator_get_enable_read_voltage(dev, "ref"); 519 + if (ret < 0 && ret != -ENODEV) 520 + return dev_err_probe(dev, ret, "failed to get REF voltage\n"); 521 + 522 + ref_mv = ret == -ENODEV ? 0 : ret / 1000; 523 + 524 + ret = devm_regulator_get_enable_optional(dev, "refin"); 525 + if (ret < 0 && ret != -ENODEV) 526 + return dev_err_probe(dev, ret, "failed to get REFIN voltage\n"); 527 + 528 + st->have_refin = ret != -ENODEV; 529 + 530 + if (st->have_refin && !st->can_refin) 531 + return dev_err_probe(dev, -EINVAL, 532 + "REFIN provided in unsupported mode\n"); 533 + 534 + if (!st->info->has_internal_vref && !st->have_refin && !ref_mv) 535 + return dev_err_probe(dev, -EINVAL, 536 + "Need either REFIN or REF"); 537 + 538 + if (st->have_refin && ref_mv) 539 + return dev_err_probe(dev, -EINVAL, 540 + "cannot have both REFIN and REF supplies\n"); 541 + 542 + if (ref_mv == 4096 && !st->can_ref_4v096) 543 + return dev_err_probe(dev, -EINVAL, 544 + "REF is 4.096V in unsupported mode\n"); 545 + 546 + if (ref_mv == 5000 && !st->can_ref_5v) 547 + return dev_err_probe(dev, -EINVAL, 548 + "REF is 5V in unsupported mode\n"); 549 + 550 + st->vref_mv = ref_mv ?: AD7625_INTERNAL_REF_MV; 551 + 552 + return 0; 553 + } 554 + 555 + static int ad7625_probe(struct platform_device *pdev) 556 + { 557 + struct device *dev = &pdev->dev; 558 + struct iio_dev *indio_dev; 559 + struct ad7625_state *st; 560 + int ret; 561 + u32 default_sample_freq; 562 + 563 + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 564 + if (!indio_dev) 565 + return -ENOMEM; 566 + 567 + st = iio_priv(indio_dev); 568 + 569 + st->info = device_get_match_data(dev); 570 + if (!st->info) 571 + return dev_err_probe(dev, -EINVAL, "no chip info\n"); 572 + 573 + if (device_property_read_bool(dev, "adi,no-dco")) 574 + return dev_err_probe(dev, -EINVAL, 575 + "self-clocked mode not supported\n"); 576 + 577 + if (st->info->has_bandwidth_control) 578 + ret = ad7625_parse_mode(dev, st, 4); 579 + else 580 + ret = ad7625_parse_mode(dev, st, 2); 581 + 582 + if (ret) 583 + return ret; 584 + 585 + ret = devm_ad7625_regulator_setup(dev, st); 586 + if (ret) 587 + return ret; 588 + 589 + /* Set the device mode based on detected EN configuration. */ 590 + if (!st->info->has_bandwidth_control) { 591 + ad7625_set_en_gpios_for_vref(st, st->have_refin, st->vref_mv); 592 + } else { 593 + /* 594 + * If neither sampling mode is available, then report an error, 595 + * since the other modes are not useful defaults. 596 + */ 597 + if (st->can_wide_bandwidth) { 598 + ret = ad7960_set_mode(st, AD7960_MODE_WIDE_BANDWIDTH, 599 + st->have_refin, st->vref_mv); 600 + } else if (st->can_narrow_bandwidth) { 601 + ret = ad7960_set_mode(st, AD7960_MODE_NARROW_BANDWIDTH, 602 + st->have_refin, st->vref_mv); 603 + } else { 604 + return dev_err_probe(dev, -EINVAL, 605 + "couldn't set device to wide or narrow bandwidth modes\n"); 606 + } 607 + 608 + if (ret) 609 + return dev_err_probe(dev, -EINVAL, 610 + "failed to set EN pins\n"); 611 + } 612 + 613 + ret = devm_ad7625_pwm_get(dev, st); 614 + if (ret) 615 + return ret; 616 + 617 + indio_dev->channels = &st->info->chan_spec; 618 + indio_dev->num_channels = 1; 619 + indio_dev->name = st->info->name; 620 + indio_dev->info = &ad7625_info; 621 + indio_dev->setup_ops = &ad7625_buffer_setup_ops; 622 + 623 + st->back = devm_iio_backend_get(dev, NULL); 624 + if (IS_ERR(st->back)) 625 + return dev_err_probe(dev, PTR_ERR(st->back), 626 + "failed to get IIO backend"); 627 + 628 + ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev); 629 + if (ret) 630 + return ret; 631 + 632 + ret = devm_iio_backend_enable(dev, st->back); 633 + if (ret) 634 + return ret; 635 + 636 + /* 637 + * Set the initial sampling frequency to the maximum, unless the 638 + * AD796x device is limited to narrow bandwidth by EN2 == 1, in 639 + * which case the sampling frequency should be limited to 2MSPS 640 + */ 641 + default_sample_freq = st->info->max_sample_freq_hz; 642 + if (st->info->has_bandwidth_control && !st->can_wide_bandwidth) 643 + default_sample_freq = AD7960_MAX_NBW_FREQ; 644 + 645 + ret = ad7625_set_sampling_freq(st, default_sample_freq); 646 + if (ret) 647 + dev_err_probe(dev, ret, 648 + "failed to set valid sampling frequency\n"); 649 + 650 + return devm_iio_device_register(dev, indio_dev); 651 + } 652 + 653 + static const struct of_device_id ad7625_of_match[] = { 654 + { .compatible = "adi,ad7625", .data = &ad7625_chip_info }, 655 + { .compatible = "adi,ad7626", .data = &ad7626_chip_info }, 656 + { .compatible = "adi,ad7960", .data = &ad7960_chip_info }, 657 + { .compatible = "adi,ad7961", .data = &ad7961_chip_info }, 658 + { } 659 + }; 660 + MODULE_DEVICE_TABLE(of, ad7625_of_match); 661 + 662 + static const struct platform_device_id ad7625_device_ids[] = { 663 + { .name = "ad7625", .driver_data = (kernel_ulong_t)&ad7625_chip_info }, 664 + { .name = "ad7626", .driver_data = (kernel_ulong_t)&ad7626_chip_info }, 665 + { .name = "ad7960", .driver_data = (kernel_ulong_t)&ad7960_chip_info }, 666 + { .name = "ad7961", .driver_data = (kernel_ulong_t)&ad7961_chip_info }, 667 + { } 668 + }; 669 + MODULE_DEVICE_TABLE(platform, ad7625_device_ids); 670 + 671 + static struct platform_driver ad7625_driver = { 672 + .probe = ad7625_probe, 673 + .driver = { 674 + .name = "ad7625", 675 + .of_match_table = ad7625_of_match, 676 + }, 677 + .id_table = ad7625_device_ids, 678 + }; 679 + module_platform_driver(ad7625_driver); 680 + 681 + MODULE_AUTHOR("Trevor Gamblin <tgamblin@baylibre.com>"); 682 + MODULE_DESCRIPTION("Analog Devices AD7625 ADC"); 683 + MODULE_LICENSE("Dual BSD/GPL"); 684 + MODULE_IMPORT_NS(IIO_BACKEND);
+2 -2
drivers/iio/adc/ad7791.c
··· 371 371 }; 372 372 373 373 static int ad7791_setup(struct ad7791_state *st, 374 - struct ad7791_platform_data *pdata) 374 + const struct ad7791_platform_data *pdata) 375 375 { 376 376 /* Set to poweron-reset default values */ 377 377 st->mode = AD7791_MODE_BUFFER; ··· 401 401 402 402 static int ad7791_probe(struct spi_device *spi) 403 403 { 404 - struct ad7791_platform_data *pdata = spi->dev.platform_data; 404 + const struct ad7791_platform_data *pdata = dev_get_platdata(&spi->dev); 405 405 struct iio_dev *indio_dev; 406 406 struct ad7791_state *st; 407 407 int ret;
+1 -1
drivers/iio/adc/ad7793.c
··· 770 770 771 771 static int ad7793_probe(struct spi_device *spi) 772 772 { 773 - const struct ad7793_platform_data *pdata = spi->dev.platform_data; 773 + const struct ad7793_platform_data *pdata = dev_get_platdata(&spi->dev); 774 774 struct ad7793_state *st; 775 775 struct iio_dev *indio_dev; 776 776 int ret, vref_mv = 0;
+2 -2
drivers/iio/adc/ad7887.c
··· 41 41 }; 42 42 43 43 /** 44 - * struct ad7887_chip_info - chip specifc information 44 + * struct ad7887_chip_info - chip specific information 45 45 * @int_vref_mv: the internal reference voltage 46 46 * @channels: channels specification 47 47 * @num_channels: number of channels ··· 234 234 235 235 static int ad7887_probe(struct spi_device *spi) 236 236 { 237 - struct ad7887_platform_data *pdata = spi->dev.platform_data; 237 + const struct ad7887_platform_data *pdata = dev_get_platdata(&spi->dev); 238 238 struct ad7887_state *st; 239 239 struct iio_dev *indio_dev; 240 240 uint8_t mode;
+2 -2
drivers/iio/adc/ad7944.c
··· 80 80 }; 81 81 82 82 /* quite time before CNV rising edge */ 83 - #define T_QUIET_NS 20 83 + #define AD7944_T_QUIET_NS 20 84 84 85 85 static const struct ad7944_timing_spec ad7944_timing_spec = { 86 86 .conv_ns = 420, ··· 150 150 * CS is tied to CNV and we need a low to high transition to start the 151 151 * conversion, so place CNV low for t_QUIET to prepare for this. 152 152 */ 153 - xfers[0].delay.value = T_QUIET_NS; 153 + xfers[0].delay.value = AD7944_T_QUIET_NS; 154 154 xfers[0].delay.unit = SPI_DELAY_UNIT_NSECS; 155 155 156 156 /*
+2 -2
drivers/iio/adc/ad_sigma_delta.c
··· 469 469 /* 470 470 * Data array after transfer will look like (if status is appended): 471 471 * data[] = { [0][sample][sample][sample][status] } 472 - * Keeping the first byte 0 shifts the status postion by 1 byte to the right. 472 + * Keeping the first byte 0 shifts the status position by 1 byte to the right. 473 473 */ 474 474 status_pos = reg_size + 1; 475 475 ··· 656 656 sigma_delta->spi = spi; 657 657 sigma_delta->info = info; 658 658 659 - /* If the field is unset in ad_sigma_delta_info, asume there can only be 1 slot. */ 659 + /* If the field is unset in ad_sigma_delta_info, assume there can only be 1 slot. */ 660 660 if (!info->num_slots) 661 661 sigma_delta->num_slots = 1; 662 662 else
+1 -1
drivers/iio/adc/at91-sama5d2_adc.c
··· 2625 2625 2626 2626 static struct platform_driver at91_adc_driver = { 2627 2627 .probe = at91_adc_probe, 2628 - .remove_new = at91_adc_remove, 2628 + .remove = at91_adc_remove, 2629 2629 .driver = { 2630 2630 .name = "at91-sama5d2_adc", 2631 2631 .of_match_table = at91_adc_dt_match,
+1 -1
drivers/iio/adc/at91_adc.c
··· 1341 1341 1342 1342 static struct platform_driver at91_adc_driver = { 1343 1343 .probe = at91_adc_probe, 1344 - .remove_new = at91_adc_remove, 1344 + .remove = at91_adc_remove, 1345 1345 .driver = { 1346 1346 .name = DRIVER_NAME, 1347 1347 .of_match_table = at91_adc_dt_ids,
+16 -46
drivers/iio/adc/axp20x_adc.c
··· 155 155 AXP813_BATT_V, 156 156 }; 157 157 158 - static struct iio_map axp20x_maps[] = { 159 - { 160 - .consumer_dev_name = "axp20x-usb-power-supply", 161 - .consumer_channel = "vbus_v", 162 - .adc_channel_label = "vbus_v", 163 - }, { 164 - .consumer_dev_name = "axp20x-usb-power-supply", 165 - .consumer_channel = "vbus_i", 166 - .adc_channel_label = "vbus_i", 167 - }, { 168 - .consumer_dev_name = "axp20x-ac-power-supply", 169 - .consumer_channel = "acin_v", 170 - .adc_channel_label = "acin_v", 171 - }, { 172 - .consumer_dev_name = "axp20x-ac-power-supply", 173 - .consumer_channel = "acin_i", 174 - .adc_channel_label = "acin_i", 175 - }, { 176 - .consumer_dev_name = "axp20x-battery-power-supply", 177 - .consumer_channel = "batt_v", 178 - .adc_channel_label = "batt_v", 179 - }, { 180 - .consumer_dev_name = "axp20x-battery-power-supply", 181 - .consumer_channel = "batt_chrg_i", 182 - .adc_channel_label = "batt_chrg_i", 183 - }, { 184 - .consumer_dev_name = "axp20x-battery-power-supply", 185 - .consumer_channel = "batt_dischrg_i", 186 - .adc_channel_label = "batt_dischrg_i", 187 - }, { /* sentinel */ } 158 + static const struct iio_map axp20x_maps[] = { 159 + IIO_MAP("vbus_v", "axp20x-usb-power-supply", "vbus_v"), 160 + IIO_MAP("vbus_i", "axp20x-usb-power-supply", "vbus_i"), 161 + IIO_MAP("acin_v", "axp20x-ac-power-supply", "acin_v"), 162 + IIO_MAP("acin_i", "axp20x-ac-power-supply", "acin_i"), 163 + IIO_MAP("batt_v", "axp20x-battery-power-supply", "batt_v"), 164 + IIO_MAP("batt_chrg_i", "axp20x-battery-power-supply", "batt_chrg_i"), 165 + IIO_MAP("batt_dischrg_i", "axp20x-battery-power-supply", "batt_dischrg_i"), 166 + { /* sentinel */ } 188 167 }; 189 168 190 - static struct iio_map axp22x_maps[] = { 191 - { 192 - .consumer_dev_name = "axp20x-battery-power-supply", 193 - .consumer_channel = "batt_v", 194 - .adc_channel_label = "batt_v", 195 - }, { 196 - .consumer_dev_name = "axp20x-battery-power-supply", 197 - .consumer_channel = "batt_chrg_i", 198 - .adc_channel_label = "batt_chrg_i", 199 - }, { 200 - .consumer_dev_name = "axp20x-battery-power-supply", 201 - .consumer_channel = "batt_dischrg_i", 202 - .adc_channel_label = "batt_dischrg_i", 203 - }, { /* sentinel */ } 169 + static const struct iio_map axp22x_maps[] = { 170 + IIO_MAP("batt_v", "axp20x-battery-power-supply", "batt_v"), 171 + IIO_MAP("batt_chrg_i", "axp20x-battery-power-supply", "batt_chrg_i"), 172 + IIO_MAP("batt_dischrg_i", "axp20x-battery-power-supply", "batt_dischrg_i"), 173 + { /* sentinel */ } 204 174 }; 205 175 206 176 static struct iio_map axp717_maps[] = { ··· 1014 1044 unsigned long adc_en2_mask; 1015 1045 int (*adc_rate)(struct axp20x_adc_iio *info, 1016 1046 int rate); 1017 - struct iio_map *maps; 1047 + const struct iio_map *maps; 1018 1048 }; 1019 1049 1020 1050 static const struct axp_data axp192_data = { ··· 1182 1212 }, 1183 1213 .id_table = axp20x_adc_id_match, 1184 1214 .probe = axp20x_probe, 1185 - .remove_new = axp20x_remove, 1215 + .remove = axp20x_remove, 1186 1216 }; 1187 1217 1188 1218 module_platform_driver(axp20x_adc_driver);
+1 -1
drivers/iio/adc/axp288_adc.c
··· 103 103 }; 104 104 105 105 /* for consumer drivers */ 106 - static struct iio_map axp288_adc_default_maps[] = { 106 + static const struct iio_map axp288_adc_default_maps[] = { 107 107 IIO_MAP("TS_PIN", "axp288-batt", "axp288-batt-temp"), 108 108 IIO_MAP("PMIC_TEMP", "axp288-pmic", "axp288-pmic-temp"), 109 109 IIO_MAP("GPADC", "axp288-gpadc", "axp288-system-temp"),
+4 -4
drivers/iio/adc/bcm_iproc_adc.c
··· 611 611 MODULE_DEVICE_TABLE(of, iproc_adc_of_match); 612 612 613 613 static struct platform_driver iproc_adc_driver = { 614 - .probe = iproc_adc_probe, 615 - .remove_new = iproc_adc_remove, 616 - .driver = { 617 - .name = "iproc-static-adc", 614 + .probe = iproc_adc_probe, 615 + .remove = iproc_adc_remove, 616 + .driver = { 617 + .name = "iproc-static-adc", 618 618 .of_match_table = iproc_adc_of_match, 619 619 }, 620 620 };
+5 -21
drivers/iio/adc/da9150-gpadc.c
··· 291 291 }; 292 292 293 293 /* Default maps used by da9150-charger */ 294 - static struct iio_map da9150_gpadc_default_maps[] = { 295 - { 296 - .consumer_dev_name = "da9150-charger", 297 - .consumer_channel = "CHAN_IBUS", 298 - .adc_channel_label = "IBUS", 299 - }, 300 - { 301 - .consumer_dev_name = "da9150-charger", 302 - .consumer_channel = "CHAN_VBUS", 303 - .adc_channel_label = "VBUS", 304 - }, 305 - { 306 - .consumer_dev_name = "da9150-charger", 307 - .consumer_channel = "CHAN_TJUNC", 308 - .adc_channel_label = "TJUNC_CORE", 309 - }, 310 - { 311 - .consumer_dev_name = "da9150-charger", 312 - .consumer_channel = "CHAN_VBAT", 313 - .adc_channel_label = "VBAT", 314 - }, 294 + static const struct iio_map da9150_gpadc_default_maps[] = { 295 + IIO_MAP("IBUS", "da9150-charger", "CHAN_IBUS"), 296 + IIO_MAP("VBUS", "da9150-charger", "CHAN_VBUS"), 297 + IIO_MAP("TJUNC_CORE", "da9150-charger", "CHAN_TJUNC"), 298 + IIO_MAP("VBAT", "da9150-charger", "CHAN_VBAT"), 315 299 {}, 316 300 }; 317 301
+1 -1
drivers/iio/adc/dln2-adc.c
··· 700 700 static struct platform_driver dln2_adc_driver = { 701 701 .driver.name = DLN2_ADC_MOD_NAME, 702 702 .probe = dln2_adc_probe, 703 - .remove_new = dln2_adc_remove, 703 + .remove = dln2_adc_remove, 704 704 }; 705 705 706 706 module_platform_driver(dln2_adc_driver);
+1 -1
drivers/iio/adc/ep93xx_adc.c
··· 238 238 .of_match_table = ep93xx_adc_of_ids, 239 239 }, 240 240 .probe = ep93xx_adc_probe, 241 - .remove_new = ep93xx_adc_remove, 241 + .remove = ep93xx_adc_remove, 242 242 }; 243 243 module_platform_driver(ep93xx_adc_driver); 244 244
+1 -1
drivers/iio/adc/exynos_adc.c
··· 1008 1008 1009 1009 static struct platform_driver exynos_adc_driver = { 1010 1010 .probe = exynos_adc_probe, 1011 - .remove_new = exynos_adc_remove, 1011 + .remove = exynos_adc_remove, 1012 1012 .driver = { 1013 1013 .name = "exynos-adc", 1014 1014 .of_match_table = exynos_adc_match,
+228
drivers/iio/adc/gehc-pmc-adc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * The GE HealthCare PMC ADC is a 16-Channel (Voltage and current), 16-Bit 4 + * ADC with an I2C Interface. 5 + * 6 + * Copyright (C) 2024, GE HealthCare 7 + * 8 + * Authors: 9 + * Herve Codina <herve.codina@bootlin.com> 10 + */ 11 + #include <dt-bindings/iio/adc/gehc,pmc-adc.h> 12 + #include <linux/bitops.h> 13 + #include <linux/clk.h> 14 + #include <linux/i2c.h> 15 + #include <linux/iio/iio.h> 16 + #include <linux/module.h> 17 + #include <linux/regulator/consumer.h> 18 + #include <linux/slab.h> 19 + 20 + struct pmc_adc { 21 + struct i2c_client *client; 22 + }; 23 + 24 + #define PMC_ADC_CMD_REQUEST_PROTOCOL_VERSION 0x01 25 + #define PMC_ADC_CMD_READ_VOLTAGE(_ch) (0x10 | (_ch)) 26 + #define PMC_ADC_CMD_READ_CURRENT(_ch) (0x20 | (_ch)) 27 + 28 + #define PMC_ADC_VOLTAGE_CHANNEL(_ch, _ds_name) { \ 29 + .type = IIO_VOLTAGE, \ 30 + .indexed = 1, \ 31 + .channel = (_ch), \ 32 + .address = PMC_ADC_CMD_READ_VOLTAGE(_ch), \ 33 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ 34 + .datasheet_name = (_ds_name), \ 35 + } 36 + 37 + #define PMC_ADC_CURRENT_CHANNEL(_ch, _ds_name) { \ 38 + .type = IIO_CURRENT, \ 39 + .indexed = 1, \ 40 + .channel = (_ch), \ 41 + .address = PMC_ADC_CMD_READ_CURRENT(_ch), \ 42 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ 43 + .datasheet_name = (_ds_name), \ 44 + } 45 + 46 + static const struct iio_chan_spec pmc_adc_channels[] = { 47 + PMC_ADC_VOLTAGE_CHANNEL(0, "CH0_V"), 48 + PMC_ADC_VOLTAGE_CHANNEL(1, "CH1_V"), 49 + PMC_ADC_VOLTAGE_CHANNEL(2, "CH2_V"), 50 + PMC_ADC_VOLTAGE_CHANNEL(3, "CH3_V"), 51 + PMC_ADC_VOLTAGE_CHANNEL(4, "CH4_V"), 52 + PMC_ADC_VOLTAGE_CHANNEL(5, "CH5_V"), 53 + PMC_ADC_VOLTAGE_CHANNEL(6, "CH6_V"), 54 + PMC_ADC_VOLTAGE_CHANNEL(7, "CH7_V"), 55 + PMC_ADC_VOLTAGE_CHANNEL(8, "CH8_V"), 56 + PMC_ADC_VOLTAGE_CHANNEL(9, "CH9_V"), 57 + PMC_ADC_VOLTAGE_CHANNEL(10, "CH10_V"), 58 + PMC_ADC_VOLTAGE_CHANNEL(11, "CH11_V"), 59 + PMC_ADC_VOLTAGE_CHANNEL(12, "CH12_V"), 60 + PMC_ADC_VOLTAGE_CHANNEL(13, "CH13_V"), 61 + PMC_ADC_VOLTAGE_CHANNEL(14, "CH14_V"), 62 + PMC_ADC_VOLTAGE_CHANNEL(15, "CH15_V"), 63 + 64 + PMC_ADC_CURRENT_CHANNEL(0, "CH0_I"), 65 + PMC_ADC_CURRENT_CHANNEL(1, "CH1_I"), 66 + PMC_ADC_CURRENT_CHANNEL(2, "CH2_I"), 67 + PMC_ADC_CURRENT_CHANNEL(3, "CH3_I"), 68 + PMC_ADC_CURRENT_CHANNEL(4, "CH4_I"), 69 + PMC_ADC_CURRENT_CHANNEL(5, "CH5_I"), 70 + PMC_ADC_CURRENT_CHANNEL(6, "CH6_I"), 71 + PMC_ADC_CURRENT_CHANNEL(7, "CH7_I"), 72 + PMC_ADC_CURRENT_CHANNEL(8, "CH8_I"), 73 + PMC_ADC_CURRENT_CHANNEL(9, "CH9_I"), 74 + PMC_ADC_CURRENT_CHANNEL(10, "CH10_I"), 75 + PMC_ADC_CURRENT_CHANNEL(11, "CH11_I"), 76 + PMC_ADC_CURRENT_CHANNEL(12, "CH12_I"), 77 + PMC_ADC_CURRENT_CHANNEL(13, "CH13_I"), 78 + PMC_ADC_CURRENT_CHANNEL(14, "CH14_I"), 79 + PMC_ADC_CURRENT_CHANNEL(15, "CH15_I"), 80 + }; 81 + 82 + static int pmc_adc_read_raw_ch(struct pmc_adc *pmc_adc, u8 cmd, int *val) 83 + { 84 + s32 ret; 85 + 86 + ret = i2c_smbus_read_word_swapped(pmc_adc->client, cmd); 87 + if (ret < 0) { 88 + dev_err(&pmc_adc->client->dev, "i2c read word failed (%d)\n", ret); 89 + return ret; 90 + } 91 + 92 + *val = sign_extend32(ret, 15); 93 + return 0; 94 + } 95 + 96 + static int pmc_adc_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, 97 + int *val, int *val2, long mask) 98 + { 99 + struct pmc_adc *pmc_adc = iio_priv(indio_dev); 100 + int ret; 101 + 102 + switch (mask) { 103 + case IIO_CHAN_INFO_PROCESSED: 104 + /* Values are directly read in mV or mA */ 105 + ret = pmc_adc_read_raw_ch(pmc_adc, chan->address, val); 106 + if (ret) 107 + return ret; 108 + return IIO_VAL_INT; 109 + } 110 + 111 + return -EINVAL; 112 + } 113 + 114 + static int pmc_adc_fwnode_xlate(struct iio_dev *indio_dev, 115 + const struct fwnode_reference_args *iiospec) 116 + { 117 + enum iio_chan_type expected_type; 118 + unsigned int i; 119 + 120 + /* 121 + * args[0]: Acquisition type (i.e. voltage or current) 122 + * args[1]: PMC ADC channel number 123 + */ 124 + if (iiospec->nargs != 2) 125 + return -EINVAL; 126 + 127 + switch (iiospec->args[0]) { 128 + case GEHC_PMC_ADC_VOLTAGE: 129 + expected_type = IIO_VOLTAGE; 130 + break; 131 + case GEHC_PMC_ADC_CURRENT: 132 + expected_type = IIO_CURRENT; 133 + break; 134 + default: 135 + dev_err(&indio_dev->dev, "Invalid channel type %llu\n", 136 + iiospec->args[0]); 137 + return -EINVAL; 138 + } 139 + 140 + for (i = 0; i < indio_dev->num_channels; i++) 141 + if (indio_dev->channels[i].type == expected_type && 142 + indio_dev->channels[i].channel == iiospec->args[1]) 143 + return i; 144 + 145 + dev_err(&indio_dev->dev, "Invalid channel type %llu number %llu\n", 146 + iiospec->args[0], iiospec->args[1]); 147 + return -EINVAL; 148 + } 149 + 150 + static const struct iio_info pmc_adc_info = { 151 + .read_raw = pmc_adc_read_raw, 152 + .fwnode_xlate = pmc_adc_fwnode_xlate, 153 + }; 154 + 155 + static const char *const pmc_adc_regulator_names[] = { 156 + "vdd", 157 + "vdda", 158 + "vddio", 159 + "vref", 160 + }; 161 + 162 + static int pmc_adc_probe(struct i2c_client *client) 163 + { 164 + struct iio_dev *indio_dev; 165 + struct pmc_adc *pmc_adc; 166 + struct clk *clk; 167 + s32 val; 168 + int ret; 169 + 170 + ret = devm_regulator_bulk_get_enable(&client->dev, ARRAY_SIZE(pmc_adc_regulator_names), 171 + pmc_adc_regulator_names); 172 + if (ret) 173 + return dev_err_probe(&client->dev, ret, "Failed to get regulators\n"); 174 + 175 + clk = devm_clk_get_optional_enabled(&client->dev, "osc"); 176 + if (IS_ERR(clk)) 177 + return dev_err_probe(&client->dev, PTR_ERR(clk), "Failed to get osc clock\n"); 178 + 179 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*pmc_adc)); 180 + if (!indio_dev) 181 + return -ENOMEM; 182 + 183 + pmc_adc = iio_priv(indio_dev); 184 + pmc_adc->client = client; 185 + 186 + val = i2c_smbus_read_byte_data(pmc_adc->client, PMC_ADC_CMD_REQUEST_PROTOCOL_VERSION); 187 + if (val < 0) 188 + return dev_err_probe(&client->dev, val, "Failed to get protocol version\n"); 189 + 190 + if (val != 0x01) 191 + return dev_err_probe(&client->dev, -EINVAL, 192 + "Unsupported protocol version 0x%02x\n", val); 193 + 194 + indio_dev->name = "pmc_adc"; 195 + indio_dev->info = &pmc_adc_info; 196 + indio_dev->modes = INDIO_DIRECT_MODE; 197 + indio_dev->channels = pmc_adc_channels; 198 + indio_dev->num_channels = ARRAY_SIZE(pmc_adc_channels); 199 + 200 + return devm_iio_device_register(&client->dev, indio_dev); 201 + } 202 + 203 + static const struct of_device_id pmc_adc_of_match[] = { 204 + { .compatible = "gehc,pmc-adc"}, 205 + { } 206 + }; 207 + MODULE_DEVICE_TABLE(of, pmc_adc_of_match); 208 + 209 + static const struct i2c_device_id pmc_adc_id_table[] = { 210 + { "pmc-adc" }, 211 + { } 212 + }; 213 + MODULE_DEVICE_TABLE(i2c, pmc_adc_id_table); 214 + 215 + static struct i2c_driver pmc_adc_i2c_driver = { 216 + .driver = { 217 + .name = "pmc-adc", 218 + .of_match_table = pmc_adc_of_match, 219 + }, 220 + .id_table = pmc_adc_id_table, 221 + .probe = pmc_adc_probe, 222 + }; 223 + 224 + module_i2c_driver(pmc_adc_i2c_driver); 225 + 226 + MODULE_AUTHOR("Herve Codina <herve.codina@bootlin.com>"); 227 + MODULE_DESCRIPTION("GE HealthCare PMC ADC driver"); 228 + MODULE_LICENSE("GPL");
+1 -1
drivers/iio/adc/imx8qxp-adc.c
··· 487 487 488 488 static struct platform_driver imx8qxp_adc_driver = { 489 489 .probe = imx8qxp_adc_probe, 490 - .remove_new = imx8qxp_adc_remove, 490 + .remove = imx8qxp_adc_remove, 491 491 .driver = { 492 492 .name = ADC_DRIVER_NAME, 493 493 .of_match_table = imx8qxp_adc_match,
+1 -1
drivers/iio/adc/imx93_adc.c
··· 470 470 471 471 static struct platform_driver imx93_adc_driver = { 472 472 .probe = imx93_adc_probe, 473 - .remove_new = imx93_adc_remove, 473 + .remove = imx93_adc_remove, 474 474 .driver = { 475 475 .name = IMX93_ADC_DRIVER_NAME, 476 476 .of_match_table = imx93_adc_match,
+1 -1
drivers/iio/adc/intel_mrfld_adc.c
··· 164 164 BCOVE_ADC_CHANNEL(IIO_TEMP, 8, "CH8", 0xC6), 165 165 }; 166 166 167 - static struct iio_map iio_maps[] = { 167 + static const struct iio_map iio_maps[] = { 168 168 IIO_MAP("CH0", "bcove-battery", "VBATRSLT"), 169 169 IIO_MAP("CH1", "bcove-battery", "BATTID"), 170 170 IIO_MAP("CH2", "bcove-battery", "IBATRSLT"),
+5 -13
drivers/iio/adc/lp8788_adc.c
··· 26 26 27 27 struct lp8788_adc { 28 28 struct lp8788 *lp; 29 - struct iio_map *map; 29 + const struct iio_map *map; 30 30 struct mutex lock; 31 31 }; 32 32 ··· 149 149 }; 150 150 151 151 /* default maps used by iio consumer (lp8788-charger driver) */ 152 - static struct iio_map lp8788_default_iio_maps[] = { 153 - { 154 - .consumer_dev_name = "lp8788-charger", 155 - .consumer_channel = "lp8788_vbatt_5p0", 156 - .adc_channel_label = "VBATT_5P0", 157 - }, 158 - { 159 - .consumer_dev_name = "lp8788-charger", 160 - .consumer_channel = "lp8788_adc1", 161 - .adc_channel_label = "ADC1", 162 - }, 152 + static const struct iio_map lp8788_default_iio_maps[] = { 153 + IIO_MAP("VBATT_5P0", "lp8788-charger", "lp8788_vbatt_5p0"), 154 + IIO_MAP("ADC1", "lp8788-charger", "lp8788_adc1"), 163 155 { } 164 156 }; 165 157 ··· 160 168 struct lp8788_platform_data *pdata, 161 169 struct lp8788_adc *adc) 162 170 { 163 - struct iio_map *map; 171 + const struct iio_map *map; 164 172 int ret; 165 173 166 174 map = (!pdata || !pdata->adc_pdata) ?
+5 -10
drivers/iio/adc/ltc2497-core.c
··· 168 168 int ltc2497core_probe(struct device *dev, struct iio_dev *indio_dev) 169 169 { 170 170 struct ltc2497core_driverdata *ddata = iio_priv(indio_dev); 171 + struct iio_map *plat_data = dev_get_platdata(dev); 171 172 int ret; 172 173 173 174 /* ··· 201 200 return ret; 202 201 } 203 202 204 - if (dev->platform_data) { 205 - struct iio_map *plat_data; 206 - 207 - plat_data = (struct iio_map *)dev->platform_data; 208 - 209 - ret = iio_map_array_register(indio_dev, plat_data); 210 - if (ret) { 211 - dev_err(&indio_dev->dev, "iio map err: %d\n", ret); 212 - goto err_regulator_disable; 213 - } 203 + ret = iio_map_array_register(indio_dev, plat_data); 204 + if (ret) { 205 + dev_err(&indio_dev->dev, "iio map err: %d\n", ret); 206 + goto err_regulator_disable; 214 207 } 215 208 216 209 ddata->addr_prev = LTC2497_CONFIG_DEFAULT;
+2 -1
drivers/iio/adc/max1363.c
··· 25 25 #include <linux/module.h> 26 26 #include <linux/mod_devicetable.h> 27 27 #include <linux/property.h> 28 + #include <linux/unaligned.h> 28 29 29 30 #include <linux/iio/iio.h> 30 31 #include <linux/iio/sysfs.h> ··· 393 392 if (data < 0) 394 393 return data; 395 394 396 - data = (rxbuf[1] | rxbuf[0] << 8) & 395 + data = get_unaligned_be16(rxbuf) & 397 396 ((1 << st->chip_info->bits) - 1); 398 397 } else { 399 398 /* Get reading */
+1 -1
drivers/iio/adc/max34408.c
··· 161 161 return IIO_VAL_INT; 162 162 case IIO_CHAN_INFO_SCALE: 163 163 /* 164 - * calcluate current for 8bit ADC with Rsense 164 + * calculate current for 8bit ADC with Rsense 165 165 * value. 166 166 * 10 mV * 1000 / Rsense uOhm = max current 167 167 * (max current * adc val * 1000) / (2^8 - 1) mA
+1 -1
drivers/iio/adc/meson_saradc.c
··· 1483 1483 1484 1484 static struct platform_driver meson_sar_adc_driver = { 1485 1485 .probe = meson_sar_adc_probe, 1486 - .remove_new = meson_sar_adc_remove, 1486 + .remove = meson_sar_adc_remove, 1487 1487 .driver = { 1488 1488 .name = "meson-saradc", 1489 1489 .of_match_table = meson_sar_adc_of_match,
+2 -2
drivers/iio/adc/mp2629_adc.c
··· 52 52 MP2629_ADC_CHAN(INPUT_CURRENT, IIO_CURRENT) 53 53 }; 54 54 55 - static struct iio_map mp2629_adc_maps[] = { 55 + static const struct iio_map mp2629_adc_maps[] = { 56 56 MP2629_MAP(BATT_VOLT, "batt-volt"), 57 57 MP2629_MAP(SYSTEM_VOLT, "system-volt"), 58 58 MP2629_MAP(INPUT_VOLT, "input-volt"), ··· 195 195 .of_match_table = mp2629_adc_of_match, 196 196 }, 197 197 .probe = mp2629_adc_probe, 198 - .remove_new = mp2629_adc_remove, 198 + .remove = mp2629_adc_remove, 199 199 }; 200 200 module_platform_driver(mp2629_adc_driver); 201 201
+1 -1
drivers/iio/adc/mt6360-adc.c
··· 124 124 usleep_range(ADC_LOOP_TIME_US / 2, ADC_LOOP_TIME_US); 125 125 } 126 126 127 - *val = rpt[1] << 8 | rpt[2]; 127 + *val = get_unaligned_be16(&rpt[1]); 128 128 ret = IIO_VAL_INT; 129 129 130 130 out_adc_conv:
+3 -3
drivers/iio/adc/mxs-lradc-adc.c
··· 819 819 820 820 static struct platform_driver mxs_lradc_adc_driver = { 821 821 .driver = { 822 - .name = "mxs-lradc-adc", 822 + .name = "mxs-lradc-adc", 823 823 }, 824 - .probe = mxs_lradc_adc_probe, 825 - .remove_new = mxs_lradc_adc_remove, 824 + .probe = mxs_lradc_adc_probe, 825 + .remove = mxs_lradc_adc_remove, 826 826 }; 827 827 module_platform_driver(mxs_lradc_adc_driver); 828 828
+1 -1
drivers/iio/adc/npcm_adc.c
··· 337 337 338 338 static struct platform_driver npcm_adc_driver = { 339 339 .probe = npcm_adc_probe, 340 - .remove_new = npcm_adc_remove, 340 + .remove = npcm_adc_remove, 341 341 .driver = { 342 342 .name = "npcm_adc", 343 343 .of_match_table = npcm_adc_match,
+20 -21
drivers/iio/adc/pac1921.c
··· 241 241 s64 tmp; 242 242 243 243 tmp = div_s64(dividend * (s64)NANO, divisor); 244 - *val = (int)div_s64_rem(tmp, NANO, val2); 244 + *val = div_s64_rem(tmp, NANO, val2); 245 245 } 246 246 247 247 /* ··· 260 260 int max = (PAC1921_MAX_VSENSE_MV * MICRO) >> i; 261 261 int vsense_lsb = DIV_ROUND_CLOSEST(max, PAC1921_RES_RESOLUTION); 262 262 263 - pac1921_calc_scale(vsense_lsb, (int)priv->rshunt_uohm, 263 + pac1921_calc_scale(vsense_lsb, priv->rshunt_uohm, 264 264 &priv->current_scales[i][0], 265 265 &priv->current_scales[i][1]); 266 266 } ··· 314 314 timestamp); 315 315 } 316 316 317 - priv->prev_ovf_flags = (u8)flags; 317 + priv->prev_ovf_flags = flags; 318 318 319 319 return 0; 320 320 } ··· 329 329 static int pac1921_read_res(struct pac1921_priv *priv, unsigned long reg, 330 330 u16 *val) 331 331 { 332 - int ret = regmap_bulk_read(priv->regmap, (unsigned int)reg, val, 333 - sizeof(*val)); 332 + int ret = regmap_bulk_read(priv->regmap, reg, val, sizeof(*val)); 334 333 if (ret) 335 334 return ret; 336 335 ··· 365 366 if (ret) 366 367 return ret; 367 368 368 - *val = (int)res_val; 369 + *val = res_val; 369 370 370 371 return IIO_VAL_INT; 371 372 } ··· 399 400 s64 tmp = curr_scale[0] * (s64)NANO + curr_scale[1]; 400 401 401 402 /* Multiply by max_vbus (V) / dv_gain */ 402 - tmp *= PAC1921_MAX_VBUS_V >> (int)priv->dv_gain; 403 + tmp *= PAC1921_MAX_VBUS_V >> priv->dv_gain; 403 404 404 405 /* Convert back to INT_PLUS_NANO */ 405 - *val = (int)div_s64_rem(tmp, NANO, val2); 406 + *val = div_s64_rem(tmp, NANO, val2); 406 407 407 408 return IIO_VAL_INT_PLUS_NANO; 408 409 } ··· 425 426 * 1/(integr_period_usecs/MICRO) = MICRO/integr_period_usecs 426 427 */ 427 428 *val = MICRO; 428 - *val2 = (int)priv->integr_period_usecs; 429 + *val2 = priv->integr_period_usecs; 429 430 return IIO_VAL_FRACTIONAL; 430 431 431 432 default: ··· 502 503 for (unsigned int i = 0; i < size; i++) 503 504 if (scales_tbl[i][0] == scale_val && 504 505 scales_tbl[i][1] == scale_val2) 505 - return (int)i; 506 + return i; 506 507 507 508 return -EINVAL; 508 509 } ··· 552 553 if (ret < 0) 553 554 return ret; 554 555 555 - return pac1921_update_gain(priv, &priv->dv_gain, (u8)ret, 556 + return pac1921_update_gain(priv, &priv->dv_gain, ret, 556 557 PAC1921_GAIN_DV_GAIN_MASK); 557 558 case PAC1921_CHAN_VSENSE: 558 559 ret = pac1921_lookup_scale(pac1921_vsense_scales, ··· 561 562 if (ret < 0) 562 563 return ret; 563 564 564 - return pac1921_update_gain(priv, &priv->di_gain, (u8)ret, 565 + return pac1921_update_gain(priv, &priv->di_gain, ret, 565 566 PAC1921_GAIN_DI_GAIN_MASK); 566 567 case PAC1921_CHAN_CURRENT: 567 568 ret = pac1921_lookup_scale(priv->current_scales, ··· 570 571 if (ret < 0) 571 572 return ret; 572 573 573 - return pac1921_update_gain(priv, &priv->di_gain, (u8)ret, 574 + return pac1921_update_gain(priv, &priv->di_gain, ret, 574 575 PAC1921_GAIN_DI_GAIN_MASK); 575 576 default: 576 577 return -EINVAL; ··· 585 586 { 586 587 for (unsigned int i = 0; i < ARRAY_SIZE(pac1921_int_num_samples); i++) 587 588 if (pac1921_int_num_samples[i] == num_samples) 588 - return (int)i; 589 + return i; 589 590 590 591 return -EINVAL; 591 592 } ··· 606 607 if (ret < 0) 607 608 return ret; 608 609 609 - n_samples = (u8)ret; 610 + n_samples = ret; 610 611 611 612 if (priv->n_samples == n_samples) 612 613 return 0; ··· 769 770 770 771 guard(mutex)(&priv->lock); 771 772 772 - vals[0] = (int)priv->rshunt_uohm; 773 + vals[0] = priv->rshunt_uohm; 773 774 vals[1] = MICRO; 774 775 775 776 return iio_format_value(buf, IIO_VAL_FRACTIONAL, 1, vals); ··· 792 793 if (ret) 793 794 return ret; 794 795 795 - rshunt_uohm = (u32)val * MICRO + (u32)val_fract; 796 + rshunt_uohm = val * MICRO + val_fract; 796 797 if (rshunt_uohm == 0 || rshunt_uohm > INT_MAX) 797 798 return -EINVAL; 798 799 799 800 guard(mutex)(&priv->lock); 800 801 801 - priv->rshunt_uohm = (u32)rshunt_uohm; 802 + priv->rshunt_uohm = rshunt_uohm; 802 803 803 804 pac1921_calc_current_scales(priv); 804 805 ··· 1076 1077 /* 1077 1078 * Init control register: 1078 1079 * - VPower free run integration mode 1079 - * - OUT pin full scale range: 3V (HW detault) 1080 + * - OUT pin full scale range: 3V (HW default) 1080 1081 * - no timeout, no sleep, no sleep override, no recalc (HW defaults) 1081 1082 */ 1082 1083 val = FIELD_PREP(PAC1921_CONTROL_MXSL_MASK, ··· 1167 1168 1168 1169 priv->regmap = devm_regmap_init_i2c(client, &pac1921_regmap_config); 1169 1170 if (IS_ERR(priv->regmap)) 1170 - return dev_err_probe(dev, (int)PTR_ERR(priv->regmap), 1171 + return dev_err_probe(dev, PTR_ERR(priv->regmap), 1171 1172 "Cannot initialize register map\n"); 1172 1173 1173 1174 devm_mutex_init(dev, &priv->lock); ··· 1190 1191 1191 1192 priv->vdd = devm_regulator_get(dev, "vdd"); 1192 1193 if (IS_ERR(priv->vdd)) 1193 - return dev_err_probe(dev, (int)PTR_ERR(priv->vdd), 1194 + return dev_err_probe(dev, PTR_ERR(priv->vdd), 1194 1195 "Cannot get vdd regulator\n"); 1195 1196 1196 1197 ret = regulator_enable(priv->vdd);
+1 -1
drivers/iio/adc/palmas_gpadc.c
··· 456 456 * raw high threshold = (ideal threshold + INL) * gain error + offset error 457 457 * 458 458 * The gain error include both gain error, as specified in the datasheet, and 459 - * the gain error drift. These paramenters vary depending on device and whether 459 + * the gain error drift. These parameters vary depending on device and whether 460 460 * the channel is calibrated (trimmed) or not. 461 461 */ 462 462 static int palmas_gpadc_threshold_with_tolerance(int val, const int INL,
+4 -6
drivers/iio/adc/qcom-pm8xxx-xoadc.c
··· 821 821 822 822 static int pm8xxx_xoadc_parse_channels(struct pm8xxx_xoadc *adc) 823 823 { 824 - struct fwnode_handle *child; 825 824 struct pm8xxx_chan_info *ch; 826 825 int ret; 827 826 int i; ··· 843 844 return -ENOMEM; 844 845 845 846 i = 0; 846 - device_for_each_child_node(adc->dev, child) { 847 + device_for_each_child_node_scoped(adc->dev, child) { 847 848 ch = &adc->chans[i]; 848 849 ret = pm8xxx_xoadc_parse_channel(adc->dev, child, 849 850 adc->variant->channels, 850 851 &adc->iio_chans[i], 851 852 ch); 852 - if (ret) { 853 - fwnode_handle_put(child); 853 + if (ret) 854 854 return ret; 855 - } 855 + 856 856 i++; 857 857 } 858 858 ··· 1014 1016 .of_match_table = pm8xxx_xoadc_id_table, 1015 1017 }, 1016 1018 .probe = pm8xxx_xoadc_probe, 1017 - .remove_new = pm8xxx_xoadc_remove, 1019 + .remove = pm8xxx_xoadc_remove, 1018 1020 }; 1019 1021 module_platform_driver(pm8xxx_xoadc_driver); 1020 1022
+2 -2
drivers/iio/adc/qcom-spmi-adc5.c
··· 830 830 831 831 adc->nchannels = device_get_child_node_count(adc->dev); 832 832 if (!adc->nchannels) 833 - return -EINVAL; 833 + return dev_err_probe(adc->dev, -EINVAL, "no channels defined\n"); 834 834 835 835 adc->iio_chans = devm_kcalloc(adc->dev, adc->nchannels, 836 836 sizeof(*adc->iio_chans), GFP_KERNEL); ··· 903 903 904 904 ret = adc5_get_fw_data(adc); 905 905 if (ret) 906 - return dev_err_probe(dev, ret, "adc get dt data failed\n"); 906 + return ret; 907 907 908 908 irq_eoc = platform_get_irq(pdev, 0); 909 909 if (irq_eoc < 0) {
+2 -5
drivers/iio/adc/qcom-spmi-vadc.c
··· 754 754 const struct vadc_channels *vadc_chan; 755 755 struct iio_chan_spec *iio_chan; 756 756 struct vadc_channel_prop prop; 757 - struct fwnode_handle *child; 758 757 unsigned int index = 0; 759 758 int ret; 760 759 ··· 773 774 774 775 iio_chan = vadc->iio_chans; 775 776 776 - device_for_each_child_node(vadc->dev, child) { 777 + device_for_each_child_node_scoped(vadc->dev, child) { 777 778 ret = vadc_get_fw_channel_data(vadc->dev, &prop, child); 778 - if (ret) { 779 - fwnode_handle_put(child); 779 + if (ret) 780 780 return ret; 781 - } 782 781 783 782 prop.scale_fn_type = vadc_chans[prop.channel].scale_fn_type; 784 783 vadc->chan_props[index] = prop;
+1 -1
drivers/iio/adc/rcar-gyroadc.c
··· 592 592 593 593 static struct platform_driver rcar_gyroadc_driver = { 594 594 .probe = rcar_gyroadc_probe, 595 - .remove_new = rcar_gyroadc_remove, 595 + .remove = rcar_gyroadc_remove, 596 596 .driver = { 597 597 .name = DRIVER_NAME, 598 598 .of_match_table = rcar_gyroadc_match,
+1 -1
drivers/iio/adc/rn5t618-adc.c
··· 185 185 RN5T618_ADC_CHANNEL(AIN0, IIO_VOLTAGE, "AIN0") 186 186 }; 187 187 188 - static struct iio_map rn5t618_maps[] = { 188 + static const struct iio_map rn5t618_maps[] = { 189 189 IIO_MAP("VADP", "rn5t618-power", "vadp"), 190 190 IIO_MAP("VUSB", "rn5t618-power", "vusb"), 191 191 { /* sentinel */ }
+1 -1
drivers/iio/adc/stm32-adc-core.c
··· 906 906 907 907 static struct platform_driver stm32_adc_driver = { 908 908 .probe = stm32_adc_probe, 909 - .remove_new = stm32_adc_remove, 909 + .remove = stm32_adc_remove, 910 910 .driver = { 911 911 .name = "stm32-adc-core", 912 912 .of_match_table = stm32_adc_of_match,
+1 -1
drivers/iio/adc/stm32-adc.c
··· 2644 2644 2645 2645 static struct platform_driver stm32_adc_driver = { 2646 2646 .probe = stm32_adc_probe, 2647 - .remove_new = stm32_adc_remove, 2647 + .remove = stm32_adc_remove, 2648 2648 .driver = { 2649 2649 .name = "stm32-adc", 2650 2650 .of_match_table = stm32_adc_of_match,
+1 -1
drivers/iio/adc/stm32-dfsdm-adc.c
··· 1890 1890 .pm = pm_sleep_ptr(&stm32_dfsdm_adc_pm_ops), 1891 1891 }, 1892 1892 .probe = stm32_dfsdm_adc_probe, 1893 - .remove_new = stm32_dfsdm_adc_remove, 1893 + .remove = stm32_dfsdm_adc_remove, 1894 1894 }; 1895 1895 module_platform_driver(stm32_dfsdm_adc_driver); 1896 1896
+1 -1
drivers/iio/adc/stm32-dfsdm-core.c
··· 506 506 507 507 static struct platform_driver stm32_dfsdm_driver = { 508 508 .probe = stm32_dfsdm_probe, 509 - .remove_new = stm32_dfsdm_core_remove, 509 + .remove = stm32_dfsdm_core_remove, 510 510 .driver = { 511 511 .name = "stm32-dfsdm", 512 512 .of_match_table = stm32_dfsdm_of_match,
+2 -5
drivers/iio/adc/sun20i-gpadc-iio.c
··· 155 155 unsigned int channel; 156 156 int num_channels, i, ret; 157 157 struct iio_chan_spec *channels; 158 - struct fwnode_handle *node; 159 158 160 159 num_channels = device_get_child_node_count(dev); 161 160 if (num_channels == 0) ··· 166 167 return -ENOMEM; 167 168 168 169 i = 0; 169 - device_for_each_child_node(dev, node) { 170 + device_for_each_child_node_scoped(dev, node) { 170 171 ret = fwnode_property_read_u32(node, "reg", &channel); 171 - if (ret) { 172 - fwnode_handle_put(node); 172 + if (ret) 173 173 return dev_err_probe(dev, ret, "invalid channel number\n"); 174 - } 175 174 176 175 channels[i].type = IIO_VOLTAGE; 177 176 channels[i].indexed = 1;
+3 -6
drivers/iio/adc/sun4i-gpadc-iio.c
··· 114 114 .datasheet_name = _name, \ 115 115 } 116 116 117 - static struct iio_map sun4i_gpadc_hwmon_maps[] = { 118 - { 119 - .adc_channel_label = "temp_adc", 120 - .consumer_dev_name = "iio_hwmon.0", 121 - }, 117 + static const struct iio_map sun4i_gpadc_hwmon_maps[] = { 118 + IIO_MAP("temp_adc", "iio_hwmon.0", NULL), 122 119 { /* sentinel */ }, 123 120 }; 124 121 ··· 697 700 }, 698 701 .id_table = sun4i_gpadc_id, 699 702 .probe = sun4i_gpadc_probe, 700 - .remove_new = sun4i_gpadc_remove, 703 + .remove = sun4i_gpadc_remove, 701 704 }; 702 705 MODULE_DEVICE_TABLE(of, sun4i_gpadc_of_id); 703 706
+1 -2
drivers/iio/adc/ti-ads1015.c
··· 1032 1032 } 1033 1033 1034 1034 if (client->irq && chip->has_comparator) { 1035 - unsigned long irq_trig = 1036 - irqd_get_trigger_type(irq_get_irq_data(client->irq)); 1035 + unsigned long irq_trig = irq_get_trigger_type(client->irq); 1037 1036 unsigned int cfg_comp_mask = ADS1015_CFG_COMP_QUE_MASK | 1038 1037 ADS1015_CFG_COMP_LAT_MASK | ADS1015_CFG_COMP_POL_MASK; 1039 1038 unsigned int cfg_comp =
+1 -1
drivers/iio/adc/ti-ads1119.c
··· 804 804 MODULE_DEVICE_TABLE(of, ads1119_of_match); 805 805 806 806 static const struct i2c_device_id ads1119_id[] = { 807 - { "ads1119", 0 }, 807 + { "ads1119" }, 808 808 { } 809 809 }; 810 810 MODULE_DEVICE_TABLE(i2c, ads1119_id);
+1 -1
drivers/iio/adc/ti-ads1298.c
··· 294 294 if (ret) 295 295 return ret; 296 296 297 - /* Refererence in millivolts */ 297 + /* Reference in millivolts */ 298 298 *val = regval & ADS1298_MASK_CONFIG3_VREF_4V ? 4000 : 2400; 299 299 } 300 300
+5 -5
drivers/iio/adc/ti_am335x_adc.c
··· 494 494 /* 495 495 * We check the complete FIFO. We programmed just one entry but in case 496 496 * something went wrong we left empty handed (-EAGAIN previously) and 497 - * then the value apeared somehow in the FIFO we would have two entries. 497 + * then the value appeared somehow in the FIFO we would have two entries. 498 498 * Therefore we read every item and keep only the latest version of the 499 499 * requested channel. 500 500 */ ··· 740 740 741 741 static struct platform_driver tiadc_driver = { 742 742 .driver = { 743 - .name = "TI-am335x-adc", 744 - .pm = pm_sleep_ptr(&tiadc_pm_ops), 743 + .name = "TI-am335x-adc", 744 + .pm = pm_sleep_ptr(&tiadc_pm_ops), 745 745 .of_match_table = ti_adc_dt_ids, 746 746 }, 747 - .probe = tiadc_probe, 748 - .remove_new = tiadc_remove, 747 + .probe = tiadc_probe, 748 + .remove = tiadc_remove, 749 749 }; 750 750 module_platform_driver(tiadc_driver); 751 751
+2 -2
drivers/iio/adc/twl4030-madc.c
··· 248 248 {15, 100}, /* CHANNEL 11 */ 249 249 {1, 4}, /* CHANNEL 12 */ 250 250 {1, 1}, /* CHANNEL 13 Reserved channels */ 251 - {1, 1}, /* CHANNEL 14 Reseved channels */ 251 + {1, 1}, /* CHANNEL 14 Reserved channels */ 252 252 {5, 11}, /* CHANNEL 15 */ 253 253 }; 254 254 ··· 914 914 915 915 static struct platform_driver twl4030_madc_driver = { 916 916 .probe = twl4030_madc_probe, 917 - .remove_new = twl4030_madc_remove, 917 + .remove = twl4030_madc_remove, 918 918 .driver = { 919 919 .name = "twl4030_madc", 920 920 .of_match_table = twl_madc_of_match,
+1 -1
drivers/iio/adc/twl6030-gpadc.c
··· 1003 1003 1004 1004 static struct platform_driver twl6030_gpadc_driver = { 1005 1005 .probe = twl6030_gpadc_probe, 1006 - .remove_new = twl6030_gpadc_remove, 1006 + .remove = twl6030_gpadc_remove, 1007 1007 .driver = { 1008 1008 .name = DRIVER_NAME, 1009 1009 .pm = pm_sleep_ptr(&twl6030_gpadc_pm_ops),
+1 -1
drivers/iio/adc/vf610_adc.c
··· 972 972 973 973 static struct platform_driver vf610_adc_driver = { 974 974 .probe = vf610_adc_probe, 975 - .remove_new = vf610_adc_remove, 975 + .remove = vf610_adc_remove, 976 976 .driver = { 977 977 .name = DRIVER_NAME, 978 978 .of_match_table = vf610_adc_match,
+1 -1
drivers/iio/adc/xilinx-xadc-events.c
··· 220 220 /* 221 221 * Since we store the hysteresis as relative (to the threshold) 222 222 * value, but the hardware expects an absolute value we need to 223 - * recalcualte this value whenever the hysteresis or the 223 + * recalculate this value whenever the hysteresis or the 224 224 * threshold changes. 225 225 */ 226 226 if (xadc->threshold[offset] < xadc->temp_hysteresis)
+9 -9
drivers/iio/addac/ad74115.c
··· 191 191 }; 192 192 193 193 struct ad74115_channels { 194 - struct iio_chan_spec *channels; 194 + const struct iio_chan_spec *channels; 195 195 unsigned int num_channels; 196 196 }; 197 197 ··· 1295 1295 _AD74115_ADC_CHANNEL(_type, index, BIT(IIO_CHAN_INFO_SCALE) \ 1296 1296 | BIT(IIO_CHAN_INFO_OFFSET)) 1297 1297 1298 - static struct iio_chan_spec ad74115_voltage_input_channels[] = { 1298 + static const struct iio_chan_spec ad74115_voltage_input_channels[] = { 1299 1299 AD74115_ADC_CHANNEL(IIO_VOLTAGE, AD74115_ADC_CH_CONV1), 1300 1300 AD74115_ADC_CHANNEL(IIO_VOLTAGE, AD74115_ADC_CH_CONV2), 1301 1301 }; 1302 1302 1303 - static struct iio_chan_spec ad74115_voltage_output_channels[] = { 1303 + static const struct iio_chan_spec ad74115_voltage_output_channels[] = { 1304 1304 AD74115_DAC_CHANNEL(IIO_VOLTAGE, AD74115_DAC_CH_MAIN), 1305 1305 AD74115_ADC_CHANNEL(IIO_CURRENT, AD74115_ADC_CH_CONV1), 1306 1306 AD74115_ADC_CHANNEL(IIO_VOLTAGE, AD74115_ADC_CH_CONV2), 1307 1307 }; 1308 1308 1309 - static struct iio_chan_spec ad74115_current_input_channels[] = { 1309 + static const struct iio_chan_spec ad74115_current_input_channels[] = { 1310 1310 AD74115_ADC_CHANNEL(IIO_CURRENT, AD74115_ADC_CH_CONV1), 1311 1311 AD74115_ADC_CHANNEL(IIO_VOLTAGE, AD74115_ADC_CH_CONV2), 1312 1312 }; 1313 1313 1314 - static struct iio_chan_spec ad74115_current_output_channels[] = { 1314 + static const struct iio_chan_spec ad74115_current_output_channels[] = { 1315 1315 AD74115_DAC_CHANNEL(IIO_CURRENT, AD74115_DAC_CH_MAIN), 1316 1316 AD74115_ADC_CHANNEL(IIO_VOLTAGE, AD74115_ADC_CH_CONV1), 1317 1317 AD74115_ADC_CHANNEL(IIO_VOLTAGE, AD74115_ADC_CH_CONV2), 1318 1318 }; 1319 1319 1320 - static struct iio_chan_spec ad74115_2_wire_resistance_input_channels[] = { 1320 + static const struct iio_chan_spec ad74115_2_wire_resistance_input_channels[] = { 1321 1321 _AD74115_ADC_CHANNEL(IIO_RESISTANCE, AD74115_ADC_CH_CONV1, 1322 1322 BIT(IIO_CHAN_INFO_PROCESSED)), 1323 1323 AD74115_ADC_CHANNEL(IIO_VOLTAGE, AD74115_ADC_CH_CONV2), 1324 1324 }; 1325 1325 1326 - static struct iio_chan_spec ad74115_3_4_wire_resistance_input_channels[] = { 1326 + static const struct iio_chan_spec ad74115_3_4_wire_resistance_input_channels[] = { 1327 1327 AD74115_ADC_CHANNEL(IIO_RESISTANCE, AD74115_ADC_CH_CONV1), 1328 1328 AD74115_ADC_CHANNEL(IIO_VOLTAGE, AD74115_ADC_CH_CONV2), 1329 1329 }; 1330 1330 1331 - static struct iio_chan_spec ad74115_digital_input_logic_channels[] = { 1331 + static const struct iio_chan_spec ad74115_digital_input_logic_channels[] = { 1332 1332 AD74115_DAC_CHANNEL(IIO_VOLTAGE, AD74115_DAC_CH_COMPARATOR), 1333 1333 AD74115_ADC_CHANNEL(IIO_VOLTAGE, AD74115_ADC_CH_CONV1), 1334 1334 AD74115_ADC_CHANNEL(IIO_VOLTAGE, AD74115_ADC_CH_CONV2), 1335 1335 }; 1336 1336 1337 - static struct iio_chan_spec ad74115_digital_input_loop_channels[] = { 1337 + static const struct iio_chan_spec ad74115_digital_input_loop_channels[] = { 1338 1338 AD74115_DAC_CHANNEL(IIO_CURRENT, AD74115_DAC_CH_MAIN), 1339 1339 AD74115_DAC_CHANNEL(IIO_VOLTAGE, AD74115_DAC_CH_COMPARATOR), 1340 1340 AD74115_ADC_CHANNEL(IIO_VOLTAGE, AD74115_ADC_CH_CONV1),
+11 -10
drivers/iio/addac/ad74413r.c
··· 45 45 }; 46 46 47 47 struct ad74413r_channels { 48 - struct iio_chan_spec *channels; 49 - unsigned int num_channels; 48 + const struct iio_chan_spec *channels; 49 + unsigned int num_channels; 50 50 }; 51 51 52 52 struct ad74413r_state { ··· 1138 1138 AD74413R_ADC_CHANNEL(IIO_CURRENT, BIT(IIO_CHAN_INFO_SCALE) \ 1139 1139 | BIT(IIO_CHAN_INFO_OFFSET)) 1140 1140 1141 - static struct iio_chan_spec ad74413r_voltage_output_channels[] = { 1141 + static const struct iio_chan_spec ad74413r_voltage_output_channels[] = { 1142 1142 AD74413R_DAC_CHANNEL(IIO_VOLTAGE, BIT(IIO_CHAN_INFO_SCALE)), 1143 1143 AD74413R_ADC_CURRENT_CHANNEL, 1144 1144 }; 1145 1145 1146 - static struct iio_chan_spec ad74413r_current_output_channels[] = { 1146 + static const struct iio_chan_spec ad74413r_current_output_channels[] = { 1147 1147 AD74413R_DAC_CHANNEL(IIO_CURRENT, BIT(IIO_CHAN_INFO_SCALE)), 1148 1148 AD74413R_ADC_VOLTAGE_CHANNEL, 1149 1149 }; 1150 1150 1151 - static struct iio_chan_spec ad74413r_voltage_input_channels[] = { 1151 + static const struct iio_chan_spec ad74413r_voltage_input_channels[] = { 1152 1152 AD74413R_ADC_VOLTAGE_CHANNEL, 1153 1153 }; 1154 1154 1155 - static struct iio_chan_spec ad74413r_current_input_channels[] = { 1155 + static const struct iio_chan_spec ad74413r_current_input_channels[] = { 1156 1156 AD74413R_ADC_CURRENT_CHANNEL, 1157 1157 }; 1158 1158 1159 - static struct iio_chan_spec ad74413r_current_input_loop_channels[] = { 1159 + static const struct iio_chan_spec ad74413r_current_input_loop_channels[] = { 1160 1160 AD74413R_DAC_CHANNEL(IIO_CURRENT, BIT(IIO_CHAN_INFO_SCALE)), 1161 1161 AD74413R_ADC_CURRENT_CHANNEL, 1162 1162 }; 1163 1163 1164 - static struct iio_chan_spec ad74413r_resistance_input_channels[] = { 1164 + static const struct iio_chan_spec ad74413r_resistance_input_channels[] = { 1165 1165 AD74413R_ADC_CHANNEL(IIO_RESISTANCE, BIT(IIO_CHAN_INFO_PROCESSED)), 1166 1166 }; 1167 1167 1168 - static struct iio_chan_spec ad74413r_digital_input_channels[] = { 1168 + static const struct iio_chan_spec ad74413r_digital_input_channels[] = { 1169 1169 AD74413R_ADC_VOLTAGE_CHANNEL, 1170 1170 }; 1171 1171 ··· 1270 1270 { 1271 1271 struct ad74413r_state *st = iio_priv(indio_dev); 1272 1272 struct ad74413r_channel_config *config; 1273 - struct iio_chan_spec *channels, *chans; 1273 + const struct iio_chan_spec *chans; 1274 + struct iio_chan_spec *channels; 1274 1275 unsigned int i, num_chans, chan_i; 1275 1276 int ret; 1276 1277
+1 -1
drivers/iio/common/st_sensors/st_sensors_trigger.c
··· 134 134 iio_trigger_set_drvdata(sdata->trig, indio_dev); 135 135 sdata->trig->ops = trigger_ops; 136 136 137 - irq_trig = irqd_get_trigger_type(irq_get_irq_data(sdata->irq)); 138 137 /* 139 138 * If the IRQ is triggered on falling edge, we need to mark the 140 139 * interrupt as active low, if the hardware supports this. 141 140 */ 141 + irq_trig = irq_get_trigger_type(sdata->irq); 142 142 switch(irq_trig) { 143 143 case IRQF_TRIGGER_FALLING: 144 144 case IRQF_TRIGGER_LOW:
+13
drivers/iio/dac/Kconfig
··· 301 301 To compile this driver as module choose M here: the module will be called 302 302 ad7303. 303 303 304 + config AD8460 305 + tristate "Analog Devices AD8460 DAC driver" 306 + depends on SPI 307 + select REGMAP_SPI 308 + select IIO_BUFFER 309 + select IIO_BUFFER_DMAENGINE 310 + help 311 + Say yes here to build support for Analog Devices AD8460 Digital to 312 + Analog Converters (DAC). 313 + 314 + To compile this driver as a module choose M here: the module will be called 315 + ad8460. 316 + 304 317 config AD8801 305 318 tristate "Analog Devices AD8801/AD8803 DAC driver" 306 319 depends on SPI_MASTER
+1
drivers/iio/dac/Makefile
··· 28 28 obj-$(CONFIG_AD5696_I2C) += ad5696-i2c.o 29 29 obj-$(CONFIG_AD7293) += ad7293.o 30 30 obj-$(CONFIG_AD7303) += ad7303.o 31 + obj-$(CONFIG_AD8460) += ad8460.o 31 32 obj-$(CONFIG_AD8801) += ad8801.o 32 33 obj-$(CONFIG_AD9739A) += ad9739a.o 33 34 obj-$(CONFIG_ADI_AXI_DAC) += adi-axi-dac.o
+1 -1
drivers/iio/dac/ad5504.c
··· 270 270 271 271 static int ad5504_probe(struct spi_device *spi) 272 272 { 273 - struct ad5504_platform_data *pdata = spi->dev.platform_data; 273 + const struct ad5504_platform_data *pdata = dev_get_platdata(&spi->dev); 274 274 struct iio_dev *indio_dev; 275 275 struct ad5504_state *st; 276 276 struct regulator *reg;
+3 -8
drivers/iio/dac/ad5755.c
··· 699 699 700 700 static struct ad5755_platform_data *ad5755_parse_fw(struct device *dev) 701 701 { 702 - struct fwnode_handle *pp; 703 702 struct ad5755_platform_data *pdata; 704 703 unsigned int tmp; 705 704 unsigned int tmparray[3]; ··· 745 746 } 746 747 747 748 devnr = 0; 748 - device_for_each_child_node(dev, pp) { 749 + device_for_each_child_node_scoped(dev, pp) { 749 750 if (devnr >= AD5755_NUM_CHANNELS) { 750 751 dev_err(dev, 751 752 "There are too many channels defined in DT\n"); 752 - goto error_out; 753 + devm_kfree(dev, pdata); 754 + return NULL; 753 755 } 754 756 755 757 pdata->dac[devnr].mode = AD5755_MODE_CURRENT_4mA_20mA; ··· 800 800 } 801 801 802 802 return pdata; 803 - 804 - error_out: 805 - fwnode_handle_put(pp); 806 - devm_kfree(dev, pdata); 807 - return NULL; 808 803 } 809 804 810 805 static int ad5755_probe(struct spi_device *spi)
+2 -1
drivers/iio/dac/ad5770r.c
··· 17 17 #include <linux/regmap.h> 18 18 #include <linux/regulator/consumer.h> 19 19 #include <linux/spi/spi.h> 20 + #include <linux/unaligned.h> 20 21 21 22 #define ADI_SPI_IF_CONFIG_A 0x00 22 23 #define ADI_SPI_IF_CONFIG_B 0x01 ··· 326 325 if (ret) 327 326 return 0; 328 327 329 - buf16 = st->transf_buf[0] + (st->transf_buf[1] << 8); 328 + buf16 = get_unaligned_le16(st->transf_buf); 330 329 *val = buf16 >> 2; 331 330 return IIO_VAL_INT; 332 331 case IIO_CHAN_INFO_SCALE:
+1 -1
drivers/iio/dac/ad5791.c
··· 341 341 342 342 static int ad5791_probe(struct spi_device *spi) 343 343 { 344 - struct ad5791_platform_data *pdata = spi->dev.platform_data; 344 + const struct ad5791_platform_data *pdata = dev_get_platdata(&spi->dev); 345 345 struct iio_dev *indio_dev; 346 346 struct ad5791_state *st; 347 347 int ret, pos_voltage_uv = 0, neg_voltage_uv = 0;
+944
drivers/iio/dac/ad8460.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * AD8460 Waveform generator DAC Driver 4 + * 5 + * Copyright (C) 2024 Analog Devices, Inc. 6 + */ 7 + 8 + #include <linux/bitfield.h> 9 + #include <linux/cleanup.h> 10 + #include <linux/clk.h> 11 + #include <linux/debugfs.h> 12 + #include <linux/delay.h> 13 + #include <linux/dmaengine.h> 14 + #include <linux/gpio/consumer.h> 15 + #include <linux/kernel.h> 16 + #include <linux/module.h> 17 + #include <linux/mod_devicetable.h> 18 + #include <linux/regmap.h> 19 + #include <linux/regulator/consumer.h> 20 + #include <linux/spi/spi.h> 21 + 22 + #include <linux/iio/buffer.h> 23 + #include <linux/iio/buffer-dma.h> 24 + #include <linux/iio/buffer-dmaengine.h> 25 + #include <linux/iio/consumer.h> 26 + #include <linux/iio/events.h> 27 + #include <linux/iio/iio.h> 28 + 29 + #define AD8460_CTRL_REG(x) (x) 30 + #define AD8460_HVDAC_DATA_WORD(x) (0x60 + (2 * (x))) 31 + 32 + #define AD8460_HV_RESET_MSK BIT(7) 33 + #define AD8460_HV_SLEEP_MSK BIT(4) 34 + #define AD8460_WAVE_GEN_MODE_MSK BIT(0) 35 + 36 + #define AD8460_HVDAC_SLEEP_MSK BIT(3) 37 + 38 + #define AD8460_FAULT_ARM_MSK BIT(7) 39 + #define AD8460_FAULT_LIMIT_MSK GENMASK(6, 0) 40 + 41 + #define AD8460_APG_MODE_ENABLE_MSK BIT(5) 42 + #define AD8460_PATTERN_DEPTH_MSK GENMASK(3, 0) 43 + 44 + #define AD8460_QUIESCENT_CURRENT_MSK GENMASK(7, 0) 45 + 46 + #define AD8460_SHUTDOWN_FLAG_MSK BIT(7) 47 + 48 + #define AD8460_DATA_BYTE_LOW_MSK GENMASK(7, 0) 49 + #define AD8460_DATA_BYTE_HIGH_MSK GENMASK(5, 0) 50 + #define AD8460_DATA_BYTE_FULL_MSK GENMASK(13, 0) 51 + 52 + #define AD8460_DEFAULT_FAULT_PROTECT 0x00 53 + #define AD8460_DATA_BYTE_WORD_LENGTH 2 54 + #define AD8460_NUM_DATA_WORDS 16 55 + #define AD8460_NOMINAL_VOLTAGE_SPAN 80 56 + #define AD8460_MIN_EXT_RESISTOR_OHMS 2000 57 + #define AD8460_MAX_EXT_RESISTOR_OHMS 20000 58 + #define AD8460_MIN_VREFIO_UV 120000 59 + #define AD8460_MAX_VREFIO_UV 1200000 60 + #define AD8460_ABS_MAX_OVERVOLTAGE_UV 55000000 61 + #define AD8460_ABS_MAX_OVERCURRENT_UA 1000000 62 + #define AD8460_MAX_OVERTEMPERATURE_MC 150000 63 + #define AD8460_MIN_OVERTEMPERATURE_MC 20000 64 + #define AD8460_CURRENT_LIMIT_CONV(x) ((x) / 15625) 65 + #define AD8460_VOLTAGE_LIMIT_CONV(x) ((x) / 1953000) 66 + #define AD8460_TEMP_LIMIT_CONV(x) (((x) + 266640) / 6510) 67 + 68 + enum ad8460_fault_type { 69 + AD8460_OVERCURRENT_SRC, 70 + AD8460_OVERCURRENT_SNK, 71 + AD8460_OVERVOLTAGE_POS, 72 + AD8460_OVERVOLTAGE_NEG, 73 + AD8460_OVERTEMPERATURE, 74 + }; 75 + 76 + struct ad8460_state { 77 + struct spi_device *spi; 78 + struct regmap *regmap; 79 + struct iio_channel *tmp_adc_channel; 80 + struct clk *sync_clk; 81 + /* lock to protect against multiple access to the device and shared data */ 82 + struct mutex lock; 83 + int refio_1p2v_mv; 84 + u32 ext_resistor_ohms; 85 + /* 86 + * DMA (thus cache coherency maintenance) requires the 87 + * transfer buffers to live in their own cache lines. 88 + */ 89 + __le16 spi_tx_buf __aligned(IIO_DMA_MINALIGN); 90 + }; 91 + 92 + static int ad8460_hv_reset(struct ad8460_state *state) 93 + { 94 + int ret; 95 + 96 + ret = regmap_set_bits(state->regmap, AD8460_CTRL_REG(0x00), 97 + AD8460_HV_RESET_MSK); 98 + if (ret) 99 + return ret; 100 + 101 + fsleep(20); 102 + 103 + return regmap_clear_bits(state->regmap, AD8460_CTRL_REG(0x00), 104 + AD8460_HV_RESET_MSK); 105 + } 106 + 107 + static int ad8460_reset(const struct ad8460_state *state) 108 + { 109 + struct device *dev = &state->spi->dev; 110 + struct gpio_desc *reset; 111 + 112 + reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); 113 + if (IS_ERR(reset)) 114 + return dev_err_probe(dev, PTR_ERR(reset), 115 + "Failed to get reset gpio"); 116 + if (reset) { 117 + /* minimum duration of 10ns */ 118 + ndelay(10); 119 + gpiod_set_value_cansleep(reset, 1); 120 + return 0; 121 + } 122 + 123 + /* bring all registers to their default state */ 124 + return regmap_write(state->regmap, AD8460_CTRL_REG(0x03), 1); 125 + } 126 + 127 + static int ad8460_enable_apg_mode(struct ad8460_state *state, int val) 128 + { 129 + int ret; 130 + 131 + ret = regmap_update_bits(state->regmap, AD8460_CTRL_REG(0x02), 132 + AD8460_APG_MODE_ENABLE_MSK, 133 + FIELD_PREP(AD8460_APG_MODE_ENABLE_MSK, val)); 134 + if (ret) 135 + return ret; 136 + 137 + return regmap_update_bits(state->regmap, AD8460_CTRL_REG(0x00), 138 + AD8460_WAVE_GEN_MODE_MSK, 139 + FIELD_PREP(AD8460_WAVE_GEN_MODE_MSK, val)); 140 + } 141 + 142 + static int ad8460_read_shutdown_flag(struct ad8460_state *state, u64 *flag) 143 + { 144 + int ret, val; 145 + 146 + ret = regmap_read(state->regmap, AD8460_CTRL_REG(0x0E), &val); 147 + if (ret) 148 + return ret; 149 + 150 + *flag = FIELD_GET(AD8460_SHUTDOWN_FLAG_MSK, val); 151 + return 0; 152 + } 153 + 154 + static int ad8460_get_hvdac_word(struct ad8460_state *state, int index, int *val) 155 + { 156 + int ret; 157 + 158 + ret = regmap_bulk_read(state->regmap, AD8460_HVDAC_DATA_WORD(index), 159 + &state->spi_tx_buf, AD8460_DATA_BYTE_WORD_LENGTH); 160 + if (ret) 161 + return ret; 162 + 163 + *val = le16_to_cpu(state->spi_tx_buf); 164 + 165 + return ret; 166 + } 167 + 168 + static int ad8460_set_hvdac_word(struct ad8460_state *state, int index, int val) 169 + { 170 + state->spi_tx_buf = cpu_to_le16(FIELD_PREP(AD8460_DATA_BYTE_FULL_MSK, val)); 171 + 172 + return regmap_bulk_write(state->regmap, AD8460_HVDAC_DATA_WORD(index), 173 + &state->spi_tx_buf, AD8460_DATA_BYTE_WORD_LENGTH); 174 + } 175 + 176 + static ssize_t ad8460_dac_input_read(struct iio_dev *indio_dev, uintptr_t private, 177 + const struct iio_chan_spec *chan, char *buf) 178 + { 179 + struct ad8460_state *state = iio_priv(indio_dev); 180 + unsigned int reg; 181 + int ret; 182 + 183 + ret = ad8460_get_hvdac_word(state, private, &reg); 184 + if (ret) 185 + return ret; 186 + 187 + return sysfs_emit(buf, "%u\n", reg); 188 + } 189 + 190 + static ssize_t ad8460_dac_input_write(struct iio_dev *indio_dev, uintptr_t private, 191 + const struct iio_chan_spec *chan, 192 + const char *buf, size_t len) 193 + { 194 + struct ad8460_state *state = iio_priv(indio_dev); 195 + unsigned int reg; 196 + int ret; 197 + 198 + ret = kstrtou32(buf, 10, &reg); 199 + if (ret) 200 + return ret; 201 + 202 + guard(mutex)(&state->lock); 203 + 204 + return ad8460_set_hvdac_word(state, private, reg); 205 + } 206 + 207 + static ssize_t ad8460_read_symbol(struct iio_dev *indio_dev, uintptr_t private, 208 + const struct iio_chan_spec *chan, char *buf) 209 + { 210 + struct ad8460_state *state = iio_priv(indio_dev); 211 + unsigned int reg; 212 + int ret; 213 + 214 + ret = regmap_read(state->regmap, AD8460_CTRL_REG(0x02), &reg); 215 + if (ret) 216 + return ret; 217 + 218 + return sysfs_emit(buf, "%lu\n", FIELD_GET(AD8460_PATTERN_DEPTH_MSK, reg)); 219 + } 220 + 221 + static ssize_t ad8460_write_symbol(struct iio_dev *indio_dev, uintptr_t private, 222 + const struct iio_chan_spec *chan, 223 + const char *buf, size_t len) 224 + { 225 + struct ad8460_state *state = iio_priv(indio_dev); 226 + uint16_t sym; 227 + int ret; 228 + 229 + ret = kstrtou16(buf, 10, &sym); 230 + if (ret) 231 + return ret; 232 + 233 + guard(mutex)(&state->lock); 234 + 235 + return regmap_update_bits(state->regmap, 236 + AD8460_CTRL_REG(0x02), 237 + AD8460_PATTERN_DEPTH_MSK, 238 + FIELD_PREP(AD8460_PATTERN_DEPTH_MSK, sym)); 239 + } 240 + 241 + static ssize_t ad8460_read_toggle_en(struct iio_dev *indio_dev, uintptr_t private, 242 + const struct iio_chan_spec *chan, char *buf) 243 + { 244 + struct ad8460_state *state = iio_priv(indio_dev); 245 + unsigned int reg; 246 + int ret; 247 + 248 + ret = regmap_read(state->regmap, AD8460_CTRL_REG(0x02), &reg); 249 + if (ret) 250 + return ret; 251 + 252 + return sysfs_emit(buf, "%ld\n", FIELD_GET(AD8460_APG_MODE_ENABLE_MSK, reg)); 253 + } 254 + 255 + static ssize_t ad8460_write_toggle_en(struct iio_dev *indio_dev, uintptr_t private, 256 + const struct iio_chan_spec *chan, 257 + const char *buf, size_t len) 258 + { 259 + struct ad8460_state *state = iio_priv(indio_dev); 260 + bool toggle_en; 261 + int ret; 262 + 263 + ret = kstrtobool(buf, &toggle_en); 264 + if (ret) 265 + return ret; 266 + 267 + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) 268 + return ad8460_enable_apg_mode(state, toggle_en); 269 + unreachable(); 270 + } 271 + 272 + static ssize_t ad8460_read_powerdown(struct iio_dev *indio_dev, uintptr_t private, 273 + const struct iio_chan_spec *chan, char *buf) 274 + { 275 + struct ad8460_state *state = iio_priv(indio_dev); 276 + unsigned int reg; 277 + int ret; 278 + 279 + ret = regmap_read(state->regmap, AD8460_CTRL_REG(0x01), &reg); 280 + if (ret) 281 + return ret; 282 + 283 + return sysfs_emit(buf, "%ld\n", FIELD_GET(AD8460_HVDAC_SLEEP_MSK, reg)); 284 + } 285 + 286 + static ssize_t ad8460_write_powerdown(struct iio_dev *indio_dev, uintptr_t private, 287 + const struct iio_chan_spec *chan, 288 + const char *buf, size_t len) 289 + { 290 + struct ad8460_state *state = iio_priv(indio_dev); 291 + bool pwr_down; 292 + u64 sdn_flag; 293 + int ret; 294 + 295 + ret = kstrtobool(buf, &pwr_down); 296 + if (ret) 297 + return ret; 298 + 299 + guard(mutex)(&state->lock); 300 + 301 + /* 302 + * If powerdown is set, HVDAC is enabled and the HV driver is 303 + * enabled via HV_RESET in case it is in shutdown mode, 304 + * If powerdown is cleared, HVDAC is set to shutdown state 305 + * as well as the HV driver. Quiescent current decreases and ouput is 306 + * floating (high impedance). 307 + */ 308 + 309 + ret = regmap_update_bits(state->regmap, AD8460_CTRL_REG(0x01), 310 + AD8460_HVDAC_SLEEP_MSK, 311 + FIELD_PREP(AD8460_HVDAC_SLEEP_MSK, pwr_down)); 312 + if (ret) 313 + return ret; 314 + 315 + if (!pwr_down) { 316 + ret = ad8460_read_shutdown_flag(state, &sdn_flag); 317 + if (ret) 318 + return ret; 319 + 320 + if (sdn_flag) { 321 + ret = ad8460_hv_reset(state); 322 + if (ret) 323 + return ret; 324 + } 325 + } 326 + 327 + ret = regmap_update_bits(state->regmap, AD8460_CTRL_REG(0x00), 328 + AD8460_HV_SLEEP_MSK, 329 + FIELD_PREP(AD8460_HV_SLEEP_MSK, !pwr_down)); 330 + if (ret) 331 + return ret; 332 + 333 + return len; 334 + } 335 + 336 + static const char * const ad8460_powerdown_modes[] = { 337 + "three_state", 338 + }; 339 + 340 + static int ad8460_get_powerdown_mode(struct iio_dev *indio_dev, 341 + const struct iio_chan_spec *chan) 342 + { 343 + return 0; 344 + } 345 + 346 + static int ad8460_set_powerdown_mode(struct iio_dev *indio_dev, 347 + const struct iio_chan_spec *chan, 348 + unsigned int type) 349 + { 350 + return 0; 351 + } 352 + 353 + static int ad8460_set_sample(struct ad8460_state *state, int val) 354 + { 355 + int ret; 356 + 357 + ret = ad8460_enable_apg_mode(state, 1); 358 + if (ret) 359 + return ret; 360 + 361 + guard(mutex)(&state->lock); 362 + ret = ad8460_set_hvdac_word(state, 0, val); 363 + if (ret) 364 + return ret; 365 + 366 + return regmap_update_bits(state->regmap, AD8460_CTRL_REG(0x02), 367 + AD8460_PATTERN_DEPTH_MSK, 368 + FIELD_PREP(AD8460_PATTERN_DEPTH_MSK, 0)); 369 + } 370 + 371 + static int ad8460_set_fault_threshold(struct ad8460_state *state, 372 + enum ad8460_fault_type fault, 373 + unsigned int threshold) 374 + { 375 + return regmap_update_bits(state->regmap, AD8460_CTRL_REG(0x08 + fault), 376 + AD8460_FAULT_LIMIT_MSK, 377 + FIELD_PREP(AD8460_FAULT_LIMIT_MSK, threshold)); 378 + } 379 + 380 + static int ad8460_get_fault_threshold(struct ad8460_state *state, 381 + enum ad8460_fault_type fault, 382 + unsigned int *threshold) 383 + { 384 + unsigned int val; 385 + int ret; 386 + 387 + ret = regmap_read(state->regmap, AD8460_CTRL_REG(0x08 + fault), &val); 388 + if (ret) 389 + return ret; 390 + 391 + *threshold = FIELD_GET(AD8460_FAULT_LIMIT_MSK, val); 392 + 393 + return ret; 394 + } 395 + 396 + static int ad8460_set_fault_threshold_en(struct ad8460_state *state, 397 + enum ad8460_fault_type fault, bool en) 398 + { 399 + return regmap_update_bits(state->regmap, AD8460_CTRL_REG(0x08 + fault), 400 + AD8460_FAULT_ARM_MSK, 401 + FIELD_PREP(AD8460_FAULT_ARM_MSK, en)); 402 + } 403 + 404 + static int ad8460_get_fault_threshold_en(struct ad8460_state *state, 405 + enum ad8460_fault_type fault, bool *en) 406 + { 407 + unsigned int val; 408 + int ret; 409 + 410 + ret = regmap_read(state->regmap, AD8460_CTRL_REG(0x08 + fault), &val); 411 + if (ret) 412 + return ret; 413 + 414 + *en = FIELD_GET(AD8460_FAULT_ARM_MSK, val); 415 + 416 + return 0; 417 + } 418 + 419 + static int ad8460_write_raw(struct iio_dev *indio_dev, 420 + struct iio_chan_spec const *chan, int val, int val2, 421 + long mask) 422 + { 423 + struct ad8460_state *state = iio_priv(indio_dev); 424 + 425 + switch (mask) { 426 + case IIO_CHAN_INFO_RAW: 427 + switch (chan->type) { 428 + case IIO_VOLTAGE: 429 + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) 430 + return ad8460_set_sample(state, val); 431 + unreachable(); 432 + case IIO_CURRENT: 433 + return regmap_write(state->regmap, AD8460_CTRL_REG(0x04), 434 + FIELD_PREP(AD8460_QUIESCENT_CURRENT_MSK, val)); 435 + default: 436 + return -EINVAL; 437 + } 438 + default: 439 + return -EINVAL; 440 + } 441 + } 442 + 443 + static int ad8460_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, 444 + int *val, int *val2, long mask) 445 + { 446 + struct ad8460_state *state = iio_priv(indio_dev); 447 + int data, ret; 448 + 449 + switch (mask) { 450 + case IIO_CHAN_INFO_RAW: 451 + switch (chan->type) { 452 + case IIO_VOLTAGE: 453 + scoped_guard(mutex, &state->lock) { 454 + ret = ad8460_get_hvdac_word(state, 0, &data); 455 + if (ret) 456 + return ret; 457 + } 458 + *val = data; 459 + return IIO_VAL_INT; 460 + case IIO_CURRENT: 461 + ret = regmap_read(state->regmap, AD8460_CTRL_REG(0x04), 462 + &data); 463 + if (ret) 464 + return ret; 465 + *val = data; 466 + return IIO_VAL_INT; 467 + case IIO_TEMP: 468 + ret = iio_read_channel_raw(state->tmp_adc_channel, &data); 469 + if (ret) 470 + return ret; 471 + *val = data; 472 + return IIO_VAL_INT; 473 + default: 474 + return -EINVAL; 475 + } 476 + case IIO_CHAN_INFO_SAMP_FREQ: 477 + *val = clk_get_rate(state->sync_clk); 478 + return IIO_VAL_INT; 479 + case IIO_CHAN_INFO_SCALE: 480 + /* 481 + * vCONV = vNOMINAL_SPAN * (DAC_CODE / 2**14) - 40V 482 + * vMAX = vNOMINAL_SPAN * (2**14 / 2**14) - 40V 483 + * vMIN = vNOMINAL_SPAN * (0 / 2**14) - 40V 484 + * vADJ = vCONV * (2000 / rSET) * (vREF / 1.2) 485 + * vSPAN = vADJ_MAX - vADJ_MIN 486 + * See datasheet page 49, section FULL-SCALE REDUCTION 487 + */ 488 + *val = AD8460_NOMINAL_VOLTAGE_SPAN * 2000 * state->refio_1p2v_mv; 489 + *val2 = state->ext_resistor_ohms * 1200; 490 + return IIO_VAL_FRACTIONAL; 491 + default: 492 + return -EINVAL; 493 + } 494 + } 495 + 496 + static int ad8460_select_fault_type(int chan_type, enum iio_event_direction dir) 497 + { 498 + switch (chan_type) { 499 + case IIO_VOLTAGE: 500 + switch (dir) { 501 + case IIO_EV_DIR_RISING: 502 + return AD8460_OVERVOLTAGE_POS; 503 + case IIO_EV_DIR_FALLING: 504 + return AD8460_OVERVOLTAGE_NEG; 505 + default: 506 + return -EINVAL; 507 + } 508 + case IIO_CURRENT: 509 + switch (dir) { 510 + case IIO_EV_DIR_RISING: 511 + return AD8460_OVERCURRENT_SRC; 512 + case IIO_EV_DIR_FALLING: 513 + return AD8460_OVERCURRENT_SNK; 514 + default: 515 + return -EINVAL; 516 + } 517 + case IIO_TEMP: 518 + switch (dir) { 519 + case IIO_EV_DIR_RISING: 520 + return AD8460_OVERTEMPERATURE; 521 + default: 522 + return -EINVAL; 523 + } 524 + default: 525 + return -EINVAL; 526 + } 527 + } 528 + 529 + static int ad8460_write_event_value(struct iio_dev *indio_dev, 530 + const struct iio_chan_spec *chan, 531 + enum iio_event_type type, 532 + enum iio_event_direction dir, 533 + enum iio_event_info info, int val, int val2) 534 + { 535 + struct ad8460_state *state = iio_priv(indio_dev); 536 + int fault; 537 + 538 + if (type != IIO_EV_TYPE_THRESH) 539 + return -EINVAL; 540 + 541 + if (info != IIO_EV_INFO_VALUE) 542 + return -EINVAL; 543 + 544 + fault = ad8460_select_fault_type(chan->type, dir); 545 + if (fault < 0) 546 + return fault; 547 + 548 + return ad8460_set_fault_threshold(state, fault, val); 549 + } 550 + 551 + static int ad8460_read_event_value(struct iio_dev *indio_dev, 552 + const struct iio_chan_spec *chan, 553 + enum iio_event_type type, 554 + enum iio_event_direction dir, 555 + enum iio_event_info info, int *val, int *val2) 556 + { 557 + struct ad8460_state *state = iio_priv(indio_dev); 558 + int fault; 559 + 560 + if (type != IIO_EV_TYPE_THRESH) 561 + return -EINVAL; 562 + 563 + if (info != IIO_EV_INFO_VALUE) 564 + return -EINVAL; 565 + 566 + fault = ad8460_select_fault_type(chan->type, dir); 567 + if (fault < 0) 568 + return fault; 569 + 570 + return ad8460_get_fault_threshold(state, fault, val); 571 + } 572 + 573 + static int ad8460_write_event_config(struct iio_dev *indio_dev, 574 + const struct iio_chan_spec *chan, 575 + enum iio_event_type type, 576 + enum iio_event_direction dir, int val) 577 + { 578 + struct ad8460_state *state = iio_priv(indio_dev); 579 + int fault; 580 + 581 + if (type != IIO_EV_TYPE_THRESH) 582 + return -EINVAL; 583 + 584 + fault = ad8460_select_fault_type(chan->type, dir); 585 + if (fault < 0) 586 + return fault; 587 + 588 + return ad8460_set_fault_threshold_en(state, fault, val); 589 + } 590 + 591 + static int ad8460_read_event_config(struct iio_dev *indio_dev, 592 + const struct iio_chan_spec *chan, 593 + enum iio_event_type type, 594 + enum iio_event_direction dir) 595 + { 596 + struct ad8460_state *state = iio_priv(indio_dev); 597 + int fault, ret; 598 + bool en; 599 + 600 + if (type != IIO_EV_TYPE_THRESH) 601 + return -EINVAL; 602 + 603 + fault = ad8460_select_fault_type(chan->type, dir); 604 + if (fault < 0) 605 + return fault; 606 + 607 + ret = ad8460_get_fault_threshold_en(state, fault, &en); 608 + if (ret) 609 + return ret; 610 + 611 + return en; 612 + } 613 + 614 + static int ad8460_reg_access(struct iio_dev *indio_dev, unsigned int reg, 615 + unsigned int writeval, unsigned int *readval) 616 + { 617 + struct ad8460_state *state = iio_priv(indio_dev); 618 + 619 + if (readval) 620 + return regmap_read(state->regmap, reg, readval); 621 + 622 + return regmap_write(state->regmap, reg, writeval); 623 + } 624 + 625 + static int ad8460_buffer_preenable(struct iio_dev *indio_dev) 626 + { 627 + struct ad8460_state *state = iio_priv(indio_dev); 628 + 629 + return ad8460_enable_apg_mode(state, 0); 630 + } 631 + 632 + static int ad8460_buffer_postdisable(struct iio_dev *indio_dev) 633 + { 634 + struct ad8460_state *state = iio_priv(indio_dev); 635 + 636 + return ad8460_enable_apg_mode(state, 1); 637 + } 638 + 639 + static const struct iio_buffer_setup_ops ad8460_buffer_setup_ops = { 640 + .preenable = &ad8460_buffer_preenable, 641 + .postdisable = &ad8460_buffer_postdisable, 642 + }; 643 + 644 + static const struct iio_info ad8460_info = { 645 + .read_raw = &ad8460_read_raw, 646 + .write_raw = &ad8460_write_raw, 647 + .write_event_value = &ad8460_write_event_value, 648 + .read_event_value = &ad8460_read_event_value, 649 + .write_event_config = &ad8460_write_event_config, 650 + .read_event_config = &ad8460_read_event_config, 651 + .debugfs_reg_access = &ad8460_reg_access, 652 + }; 653 + 654 + static const struct iio_enum ad8460_powerdown_mode_enum = { 655 + .items = ad8460_powerdown_modes, 656 + .num_items = ARRAY_SIZE(ad8460_powerdown_modes), 657 + .get = ad8460_get_powerdown_mode, 658 + .set = ad8460_set_powerdown_mode, 659 + }; 660 + 661 + #define AD8460_CHAN_EXT_INFO(_name, _what, _read, _write) { \ 662 + .name = (_name), \ 663 + .read = (_read), \ 664 + .write = (_write), \ 665 + .private = (_what), \ 666 + .shared = IIO_SEPARATE, \ 667 + } 668 + 669 + static const struct iio_chan_spec_ext_info ad8460_ext_info[] = { 670 + AD8460_CHAN_EXT_INFO("raw0", 0, ad8460_dac_input_read, 671 + ad8460_dac_input_write), 672 + AD8460_CHAN_EXT_INFO("raw1", 1, ad8460_dac_input_read, 673 + ad8460_dac_input_write), 674 + AD8460_CHAN_EXT_INFO("raw2", 2, ad8460_dac_input_read, 675 + ad8460_dac_input_write), 676 + AD8460_CHAN_EXT_INFO("raw3", 3, ad8460_dac_input_read, 677 + ad8460_dac_input_write), 678 + AD8460_CHAN_EXT_INFO("raw4", 4, ad8460_dac_input_read, 679 + ad8460_dac_input_write), 680 + AD8460_CHAN_EXT_INFO("raw5", 5, ad8460_dac_input_read, 681 + ad8460_dac_input_write), 682 + AD8460_CHAN_EXT_INFO("raw6", 6, ad8460_dac_input_read, 683 + ad8460_dac_input_write), 684 + AD8460_CHAN_EXT_INFO("raw7", 7, ad8460_dac_input_read, 685 + ad8460_dac_input_write), 686 + AD8460_CHAN_EXT_INFO("raw8", 8, ad8460_dac_input_read, 687 + ad8460_dac_input_write), 688 + AD8460_CHAN_EXT_INFO("raw9", 9, ad8460_dac_input_read, 689 + ad8460_dac_input_write), 690 + AD8460_CHAN_EXT_INFO("raw10", 10, ad8460_dac_input_read, 691 + ad8460_dac_input_write), 692 + AD8460_CHAN_EXT_INFO("raw11", 11, ad8460_dac_input_read, 693 + ad8460_dac_input_write), 694 + AD8460_CHAN_EXT_INFO("raw12", 12, ad8460_dac_input_read, 695 + ad8460_dac_input_write), 696 + AD8460_CHAN_EXT_INFO("raw13", 13, ad8460_dac_input_read, 697 + ad8460_dac_input_write), 698 + AD8460_CHAN_EXT_INFO("raw14", 14, ad8460_dac_input_read, 699 + ad8460_dac_input_write), 700 + AD8460_CHAN_EXT_INFO("raw15", 15, ad8460_dac_input_read, 701 + ad8460_dac_input_write), 702 + AD8460_CHAN_EXT_INFO("toggle_en", 0, ad8460_read_toggle_en, 703 + ad8460_write_toggle_en), 704 + AD8460_CHAN_EXT_INFO("symbol", 0, ad8460_read_symbol, 705 + ad8460_write_symbol), 706 + AD8460_CHAN_EXT_INFO("powerdown", 0, ad8460_read_powerdown, 707 + ad8460_write_powerdown), 708 + IIO_ENUM("powerdown_mode", IIO_SEPARATE, &ad8460_powerdown_mode_enum), 709 + IIO_ENUM_AVAILABLE("powerdown_mode", IIO_SHARED_BY_TYPE, 710 + &ad8460_powerdown_mode_enum), 711 + { } 712 + }; 713 + 714 + static const struct iio_event_spec ad8460_events[] = { 715 + { 716 + .type = IIO_EV_TYPE_THRESH, 717 + .dir = IIO_EV_DIR_RISING, 718 + .mask_separate = BIT(IIO_EV_INFO_VALUE) | 719 + BIT(IIO_EV_INFO_ENABLE), 720 + }, 721 + { 722 + .type = IIO_EV_TYPE_THRESH, 723 + .dir = IIO_EV_DIR_FALLING, 724 + .mask_separate = BIT(IIO_EV_INFO_VALUE) | 725 + BIT(IIO_EV_INFO_ENABLE), 726 + }, 727 + }; 728 + 729 + #define AD8460_VOLTAGE_CHAN { \ 730 + .type = IIO_VOLTAGE, \ 731 + .info_mask_separate = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ 732 + BIT(IIO_CHAN_INFO_RAW) | \ 733 + BIT(IIO_CHAN_INFO_SCALE), \ 734 + .output = 1, \ 735 + .indexed = 1, \ 736 + .channel = 0, \ 737 + .scan_index = 0, \ 738 + .scan_type = { \ 739 + .sign = 'u', \ 740 + .realbits = 14, \ 741 + .storagebits = 16, \ 742 + .endianness = IIO_CPU, \ 743 + }, \ 744 + .ext_info = ad8460_ext_info, \ 745 + .event_spec = ad8460_events, \ 746 + .num_event_specs = ARRAY_SIZE(ad8460_events), \ 747 + } 748 + 749 + #define AD8460_CURRENT_CHAN { \ 750 + .type = IIO_CURRENT, \ 751 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 752 + .output = 1, \ 753 + .indexed = 1, \ 754 + .channel = 0, \ 755 + .scan_index = -1, \ 756 + .event_spec = ad8460_events, \ 757 + .num_event_specs = ARRAY_SIZE(ad8460_events), \ 758 + } 759 + 760 + #define AD8460_TEMP_CHAN { \ 761 + .type = IIO_TEMP, \ 762 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 763 + .indexed = 1, \ 764 + .channel = 0, \ 765 + .scan_index = -1, \ 766 + .event_spec = ad8460_events, \ 767 + .num_event_specs = 1, \ 768 + } 769 + 770 + static const struct iio_chan_spec ad8460_channels[] = { 771 + AD8460_VOLTAGE_CHAN, 772 + AD8460_CURRENT_CHAN, 773 + }; 774 + 775 + static const struct iio_chan_spec ad8460_channels_with_tmp_adc[] = { 776 + AD8460_VOLTAGE_CHAN, 777 + AD8460_CURRENT_CHAN, 778 + AD8460_TEMP_CHAN, 779 + }; 780 + 781 + static const struct regmap_config ad8460_regmap_config = { 782 + .reg_bits = 8, 783 + .val_bits = 8, 784 + .max_register = 0x7F, 785 + }; 786 + 787 + static const char * const ad8460_supplies[] = { 788 + "avdd_3p3v", "dvdd_3p3v", "vcc_5v", "hvcc", "hvee", "vref_5v" 789 + }; 790 + 791 + static int ad8460_probe(struct spi_device *spi) 792 + { 793 + struct device *dev = &spi->dev; 794 + struct ad8460_state *state; 795 + struct iio_dev *indio_dev; 796 + u32 tmp[2], temp; 797 + int ret; 798 + 799 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*state)); 800 + if (!indio_dev) 801 + return -ENOMEM; 802 + 803 + state = iio_priv(indio_dev); 804 + 805 + indio_dev->name = "ad8460"; 806 + indio_dev->info = &ad8460_info; 807 + 808 + state->spi = spi; 809 + 810 + state->regmap = devm_regmap_init_spi(spi, &ad8460_regmap_config); 811 + if (IS_ERR(state->regmap)) 812 + return dev_err_probe(dev, PTR_ERR(state->regmap), 813 + "Failed to initialize regmap"); 814 + 815 + ret = devm_mutex_init(dev, &state->lock); 816 + if (ret) 817 + return ret; 818 + 819 + state->sync_clk = devm_clk_get_enabled(dev, NULL); 820 + if (IS_ERR(state->sync_clk)) 821 + return dev_err_probe(dev, PTR_ERR(state->sync_clk), 822 + "Failed to get sync clk\n"); 823 + 824 + state->tmp_adc_channel = devm_iio_channel_get(dev, "ad8460-tmp"); 825 + if (IS_ERR(state->tmp_adc_channel)) { 826 + if (PTR_ERR(state->tmp_adc_channel) == -EPROBE_DEFER) 827 + return -EPROBE_DEFER; 828 + indio_dev->channels = ad8460_channels; 829 + indio_dev->num_channels = ARRAY_SIZE(ad8460_channels); 830 + } else { 831 + indio_dev->channels = ad8460_channels_with_tmp_adc; 832 + indio_dev->num_channels = ARRAY_SIZE(ad8460_channels_with_tmp_adc); 833 + } 834 + 835 + ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(ad8460_supplies), 836 + ad8460_supplies); 837 + if (ret) 838 + return dev_err_probe(dev, ret, 839 + "Failed to enable power supplies\n"); 840 + 841 + ret = devm_regulator_get_enable_read_voltage(dev, "refio_1p2v"); 842 + if (ret < 0 && ret != -ENODEV) 843 + return dev_err_probe(dev, ret, "Failed to get reference voltage\n"); 844 + 845 + state->refio_1p2v_mv = ret == -ENODEV ? 1200 : ret / 1000; 846 + 847 + if (!in_range(state->refio_1p2v_mv, AD8460_MIN_VREFIO_UV / 1000, 848 + AD8460_MAX_VREFIO_UV / 1000)) 849 + return dev_err_probe(dev, -EINVAL, 850 + "Invalid ref voltage range(%u mV) [%u mV, %u mV]\n", 851 + state->refio_1p2v_mv, 852 + AD8460_MIN_VREFIO_UV / 1000, 853 + AD8460_MAX_VREFIO_UV / 1000); 854 + 855 + ret = device_property_read_u32(dev, "adi,external-resistor-ohms", 856 + &state->ext_resistor_ohms); 857 + if (ret) 858 + state->ext_resistor_ohms = 2000; 859 + else if (!in_range(state->ext_resistor_ohms, AD8460_MIN_EXT_RESISTOR_OHMS, 860 + AD8460_MAX_EXT_RESISTOR_OHMS)) 861 + return dev_err_probe(dev, -EINVAL, 862 + "Invalid resistor set range(%u) [%u, %u]\n", 863 + state->ext_resistor_ohms, 864 + AD8460_MIN_EXT_RESISTOR_OHMS, 865 + AD8460_MAX_EXT_RESISTOR_OHMS); 866 + 867 + ret = device_property_read_u32_array(dev, "adi,range-microamp", 868 + tmp, ARRAY_SIZE(tmp)); 869 + if (!ret) { 870 + if (in_range(tmp[1], 0, AD8460_ABS_MAX_OVERCURRENT_UA)) 871 + regmap_write(state->regmap, AD8460_CTRL_REG(0x08), 872 + FIELD_PREP(AD8460_FAULT_ARM_MSK, 1) | 873 + AD8460_CURRENT_LIMIT_CONV(tmp[1])); 874 + 875 + if (in_range(tmp[0], -AD8460_ABS_MAX_OVERCURRENT_UA, 0)) 876 + regmap_write(state->regmap, AD8460_CTRL_REG(0x09), 877 + FIELD_PREP(AD8460_FAULT_ARM_MSK, 1) | 878 + AD8460_CURRENT_LIMIT_CONV(abs(tmp[0]))); 879 + } 880 + 881 + ret = device_property_read_u32_array(dev, "adi,range-microvolt", 882 + tmp, ARRAY_SIZE(tmp)); 883 + if (!ret) { 884 + if (in_range(tmp[1], 0, AD8460_ABS_MAX_OVERVOLTAGE_UV)) 885 + regmap_write(state->regmap, AD8460_CTRL_REG(0x0A), 886 + FIELD_PREP(AD8460_FAULT_ARM_MSK, 1) | 887 + AD8460_VOLTAGE_LIMIT_CONV(tmp[1])); 888 + 889 + if (in_range(tmp[0], -AD8460_ABS_MAX_OVERVOLTAGE_UV, 0)) 890 + regmap_write(state->regmap, AD8460_CTRL_REG(0x0B), 891 + FIELD_PREP(AD8460_FAULT_ARM_MSK, 1) | 892 + AD8460_VOLTAGE_LIMIT_CONV(abs(tmp[0]))); 893 + } 894 + 895 + ret = device_property_read_u32(dev, "adi,max-millicelsius", &temp); 896 + if (!ret) { 897 + if (in_range(temp, AD8460_MIN_OVERTEMPERATURE_MC, 898 + AD8460_MAX_OVERTEMPERATURE_MC)) 899 + regmap_write(state->regmap, AD8460_CTRL_REG(0x0C), 900 + FIELD_PREP(AD8460_FAULT_ARM_MSK, 1) | 901 + AD8460_TEMP_LIMIT_CONV(abs(temp))); 902 + } 903 + 904 + ret = ad8460_reset(state); 905 + if (ret) 906 + return ret; 907 + 908 + /* Enables DAC by default */ 909 + ret = regmap_clear_bits(state->regmap, AD8460_CTRL_REG(0x01), 910 + AD8460_HVDAC_SLEEP_MSK); 911 + if (ret) 912 + return ret; 913 + 914 + indio_dev->modes = INDIO_DIRECT_MODE; 915 + indio_dev->setup_ops = &ad8460_buffer_setup_ops; 916 + 917 + ret = devm_iio_dmaengine_buffer_setup_ext(dev, indio_dev, "tx", 918 + IIO_BUFFER_DIRECTION_OUT); 919 + if (ret) 920 + return dev_err_probe(dev, ret, 921 + "Failed to get DMA buffer\n"); 922 + 923 + return devm_iio_device_register(dev, indio_dev); 924 + } 925 + 926 + static const struct of_device_id ad8460_of_match[] = { 927 + { .compatible = "adi, ad8460" }, 928 + { } 929 + }; 930 + MODULE_DEVICE_TABLE(of, ad8460_of_match); 931 + 932 + static struct spi_driver ad8460_driver = { 933 + .driver = { 934 + .name = "ad8460", 935 + .of_match_table = ad8460_of_match, 936 + }, 937 + .probe = ad8460_probe, 938 + }; 939 + module_spi_driver(ad8460_driver); 940 + 941 + MODULE_AUTHOR("Mariel Tinaco <mariel.tinaco@analog.com"); 942 + MODULE_DESCRIPTION("AD8460 DAC driver"); 943 + MODULE_LICENSE("GPL"); 944 + MODULE_IMPORT_NS(IIO_DMAENGINE_BUFFER);
+74 -63
drivers/iio/dac/adi-axi-dac.c
··· 35 35 */ 36 36 37 37 /* Base controls */ 38 - #define AXI_DAC_REG_CONFIG 0x0c 39 - #define AXI_DDS_DISABLE BIT(6) 38 + #define AXI_DAC_CONFIG_REG 0x0c 39 + #define AXI_DAC_CONFIG_DDS_DISABLE BIT(6) 40 40 41 41 /* DAC controls */ 42 - #define AXI_DAC_REG_RSTN 0x0040 43 - #define AXI_DAC_RSTN_CE_N BIT(2) 44 - #define AXI_DAC_RSTN_MMCM_RSTN BIT(1) 45 - #define AXI_DAC_RSTN_RSTN BIT(0) 46 - #define AXI_DAC_REG_CNTRL_1 0x0044 47 - #define AXI_DAC_SYNC BIT(0) 48 - #define AXI_DAC_REG_CNTRL_2 0x0048 49 - #define ADI_DAC_R1_MODE BIT(4) 50 - #define AXI_DAC_DRP_STATUS 0x0074 51 - #define AXI_DAC_DRP_LOCKED BIT(17) 42 + #define AXI_DAC_RSTN_REG 0x0040 43 + #define AXI_DAC_RSTN_CE_N BIT(2) 44 + #define AXI_DAC_RSTN_MMCM_RSTN BIT(1) 45 + #define AXI_DAC_RSTN_RSTN BIT(0) 46 + #define AXI_DAC_CNTRL_1_REG 0x0044 47 + #define AXI_DAC_CNTRL_1_SYNC BIT(0) 48 + #define AXI_DAC_CNTRL_2_REG 0x0048 49 + #define ADI_DAC_CNTRL_2_R1_MODE BIT(5) 50 + #define AXI_DAC_DRP_STATUS_REG 0x0074 51 + #define AXI_DAC_DRP_STATUS_DRP_LOCKED BIT(17) 52 + 52 53 /* DAC Channel controls */ 53 - #define AXI_DAC_REG_CHAN_CNTRL_1(c) (0x0400 + (c) * 0x40) 54 - #define AXI_DAC_REG_CHAN_CNTRL_3(c) (0x0408 + (c) * 0x40) 55 - #define AXI_DAC_SCALE_SIGN BIT(15) 56 - #define AXI_DAC_SCALE_INT BIT(14) 57 - #define AXI_DAC_SCALE GENMASK(14, 0) 58 - #define AXI_DAC_REG_CHAN_CNTRL_2(c) (0x0404 + (c) * 0x40) 59 - #define AXI_DAC_REG_CHAN_CNTRL_4(c) (0x040c + (c) * 0x40) 60 - #define AXI_DAC_PHASE GENMASK(31, 16) 61 - #define AXI_DAC_FREQUENCY GENMASK(15, 0) 62 - #define AXI_DAC_REG_CHAN_CNTRL_7(c) (0x0418 + (c) * 0x40) 63 - #define AXI_DAC_DATA_SEL GENMASK(3, 0) 54 + #define AXI_DAC_CHAN_CNTRL_1_REG(c) (0x0400 + (c) * 0x40) 55 + #define AXI_DAC_CHAN_CNTRL_3_REG(c) (0x0408 + (c) * 0x40) 56 + #define AXI_DAC_CHAN_CNTRL_3_SCALE_SIGN BIT(15) 57 + #define AXI_DAC_CHAN_CNTRL_3_SCALE_INT BIT(14) 58 + #define AXI_DAC_CHAN_CNTRL_3_SCALE GENMASK(14, 0) 59 + #define AXI_DAC_CHAN_CNTRL_2_REG(c) (0x0404 + (c) * 0x40) 60 + #define AXI_DAC_CHAN_CNTRL_2_PHASE GENMASK(31, 16) 61 + #define AXI_DAC_CHAN_CNTRL_2_FREQUENCY GENMASK(15, 0) 62 + #define AXI_DAC_CHAN_CNTRL_4_REG(c) (0x040c + (c) * 0x40) 63 + #define AXI_DAC_CHAN_CNTRL_7_REG(c) (0x0418 + (c) * 0x40) 64 + #define AXI_DAC_CHAN_CNTRL_7_DATA_SEL GENMASK(3, 0) 64 65 65 66 /* 360 degrees in rad */ 66 - #define AXI_DAC_2_PI_MEGA 6283190 67 + #define AXI_DAC_2_PI_MEGA 6283190 68 + 67 69 enum { 68 70 AXI_DAC_DATA_INTERNAL_TONE, 69 71 AXI_DAC_DATA_DMA = 2, ··· 91 89 int ret; 92 90 93 91 guard(mutex)(&st->lock); 94 - ret = regmap_set_bits(st->regmap, AXI_DAC_REG_RSTN, 92 + ret = regmap_set_bits(st->regmap, AXI_DAC_RSTN_REG, 95 93 AXI_DAC_RSTN_MMCM_RSTN); 96 94 if (ret) 97 95 return ret; ··· 100 98 * designs really use it but if they don't we still get the lock bit 101 99 * set. So let's do it all the time so the code is generic. 102 100 */ 103 - ret = regmap_read_poll_timeout(st->regmap, AXI_DAC_DRP_STATUS, __val, 104 - __val & AXI_DAC_DRP_LOCKED, 100, 1000); 101 + ret = regmap_read_poll_timeout(st->regmap, AXI_DAC_DRP_STATUS_REG, 102 + __val, 103 + __val & AXI_DAC_DRP_STATUS_DRP_LOCKED, 104 + 100, 1000); 105 105 if (ret) 106 106 return ret; 107 107 108 - return regmap_set_bits(st->regmap, AXI_DAC_REG_RSTN, 108 + return regmap_set_bits(st->regmap, AXI_DAC_RSTN_REG, 109 109 AXI_DAC_RSTN_RSTN | AXI_DAC_RSTN_MMCM_RSTN); 110 110 } 111 111 ··· 116 112 struct axi_dac_state *st = iio_backend_get_priv(back); 117 113 118 114 guard(mutex)(&st->lock); 119 - regmap_write(st->regmap, AXI_DAC_REG_RSTN, 0); 115 + regmap_write(st->regmap, AXI_DAC_RSTN_REG, 0); 120 116 } 121 117 122 118 static struct iio_buffer *axi_dac_request_buffer(struct iio_backend *back, ··· 159 155 } 160 156 161 157 if (tone_2) 162 - reg = AXI_DAC_REG_CHAN_CNTRL_4(chan); 158 + reg = AXI_DAC_CHAN_CNTRL_4_REG(chan); 163 159 else 164 - reg = AXI_DAC_REG_CHAN_CNTRL_2(chan); 160 + reg = AXI_DAC_CHAN_CNTRL_2_REG(chan); 165 161 166 162 ret = regmap_read(st->regmap, reg, &raw); 167 163 if (ret) 168 164 return ret; 169 165 170 - raw = FIELD_GET(AXI_DAC_FREQUENCY, raw); 166 + raw = FIELD_GET(AXI_DAC_CHAN_CNTRL_2_FREQUENCY, raw); 171 167 *freq = DIV_ROUND_CLOSEST_ULL(raw * st->dac_clk, BIT(16)); 172 168 173 169 return 0; ··· 198 194 u32 reg, raw; 199 195 200 196 if (tone_2) 201 - reg = AXI_DAC_REG_CHAN_CNTRL_3(chan->channel); 197 + reg = AXI_DAC_CHAN_CNTRL_3_REG(chan->channel); 202 198 else 203 - reg = AXI_DAC_REG_CHAN_CNTRL_1(chan->channel); 199 + reg = AXI_DAC_CHAN_CNTRL_1_REG(chan->channel); 204 200 205 201 ret = regmap_read(st->regmap, reg, &raw); 206 202 if (ret) 207 203 return ret; 208 204 209 - sign = FIELD_GET(AXI_DAC_SCALE_SIGN, raw); 210 - raw = FIELD_GET(AXI_DAC_SCALE, raw); 211 - scale = DIV_ROUND_CLOSEST_ULL((u64)raw * MEGA, AXI_DAC_SCALE_INT); 205 + sign = FIELD_GET(AXI_DAC_CHAN_CNTRL_3_SCALE_SIGN, raw); 206 + raw = FIELD_GET(AXI_DAC_CHAN_CNTRL_3_SCALE, raw); 207 + scale = DIV_ROUND_CLOSEST_ULL((u64)raw * MEGA, 208 + AXI_DAC_CHAN_CNTRL_3_SCALE_INT); 212 209 213 210 vals[0] = scale / MEGA; 214 211 vals[1] = scale % MEGA; ··· 232 227 int ret, vals[2]; 233 228 234 229 if (tone_2) 235 - reg = AXI_DAC_REG_CHAN_CNTRL_4(chan->channel); 230 + reg = AXI_DAC_CHAN_CNTRL_4_REG(chan->channel); 236 231 else 237 - reg = AXI_DAC_REG_CHAN_CNTRL_2(chan->channel); 232 + reg = AXI_DAC_CHAN_CNTRL_2_REG(chan->channel); 238 233 239 234 ret = regmap_read(st->regmap, reg, &raw); 240 235 if (ret) 241 236 return ret; 242 237 243 - raw = FIELD_GET(AXI_DAC_PHASE, raw); 238 + raw = FIELD_GET(AXI_DAC_CHAN_CNTRL_2_PHASE, raw); 244 239 phase = DIV_ROUND_CLOSEST_ULL((u64)raw * AXI_DAC_2_PI_MEGA, U16_MAX); 245 240 246 241 vals[0] = phase / MEGA; ··· 265 260 } 266 261 267 262 if (tone_2) 268 - reg = AXI_DAC_REG_CHAN_CNTRL_4(chan); 263 + reg = AXI_DAC_CHAN_CNTRL_4_REG(chan); 269 264 else 270 - reg = AXI_DAC_REG_CHAN_CNTRL_2(chan); 265 + reg = AXI_DAC_CHAN_CNTRL_2_REG(chan); 271 266 272 267 raw = DIV64_U64_ROUND_CLOSEST((u64)freq * BIT(16), sample_rate); 273 268 274 - ret = regmap_update_bits(st->regmap, reg, AXI_DAC_FREQUENCY, raw); 269 + ret = regmap_update_bits(st->regmap, reg, 270 + AXI_DAC_CHAN_CNTRL_2_FREQUENCY, raw); 275 271 if (ret) 276 272 return ret; 277 273 278 274 /* synchronize channels */ 279 - return regmap_set_bits(st->regmap, AXI_DAC_REG_CNTRL_1, AXI_DAC_SYNC); 275 + return regmap_set_bits(st->regmap, AXI_DAC_CNTRL_1_REG, 276 + AXI_DAC_CNTRL_1_SYNC); 280 277 } 281 278 282 279 static int axi_dac_frequency_set(struct axi_dac_state *st, ··· 319 312 320 313 /* format is 1.1.14 (sign, integer and fractional bits) */ 321 314 if (scale < 0) { 322 - raw = FIELD_PREP(AXI_DAC_SCALE_SIGN, 1); 315 + raw = FIELD_PREP(AXI_DAC_CHAN_CNTRL_3_SCALE_SIGN, 1); 323 316 scale *= -1; 324 317 } 325 318 326 - raw |= div_u64((u64)scale * AXI_DAC_SCALE_INT, MEGA); 319 + raw |= div_u64((u64)scale * AXI_DAC_CHAN_CNTRL_3_SCALE_INT, MEGA); 327 320 328 321 if (tone_2) 329 - reg = AXI_DAC_REG_CHAN_CNTRL_3(chan->channel); 322 + reg = AXI_DAC_CHAN_CNTRL_3_REG(chan->channel); 330 323 else 331 - reg = AXI_DAC_REG_CHAN_CNTRL_1(chan->channel); 324 + reg = AXI_DAC_CHAN_CNTRL_1_REG(chan->channel); 332 325 333 326 guard(mutex)(&st->lock); 334 327 ret = regmap_write(st->regmap, reg, raw); ··· 336 329 return ret; 337 330 338 331 /* synchronize channels */ 339 - ret = regmap_set_bits(st->regmap, AXI_DAC_REG_CNTRL_1, AXI_DAC_SYNC); 332 + ret = regmap_set_bits(st->regmap, AXI_DAC_CNTRL_1_REG, 333 + AXI_DAC_CNTRL_1_SYNC); 340 334 if (ret) 341 335 return ret; 342 336 ··· 363 355 raw = DIV_ROUND_CLOSEST_ULL((u64)phase * U16_MAX, AXI_DAC_2_PI_MEGA); 364 356 365 357 if (tone_2) 366 - reg = AXI_DAC_REG_CHAN_CNTRL_4(chan->channel); 358 + reg = AXI_DAC_CHAN_CNTRL_4_REG(chan->channel); 367 359 else 368 - reg = AXI_DAC_REG_CHAN_CNTRL_2(chan->channel); 360 + reg = AXI_DAC_CHAN_CNTRL_2_REG(chan->channel); 369 361 370 362 guard(mutex)(&st->lock); 371 - ret = regmap_update_bits(st->regmap, reg, AXI_DAC_PHASE, 372 - FIELD_PREP(AXI_DAC_PHASE, raw)); 363 + ret = regmap_update_bits(st->regmap, reg, AXI_DAC_CHAN_CNTRL_2_PHASE, 364 + FIELD_PREP(AXI_DAC_CHAN_CNTRL_2_PHASE, raw)); 373 365 if (ret) 374 366 return ret; 375 367 376 368 /* synchronize channels */ 377 - ret = regmap_set_bits(st->regmap, AXI_DAC_REG_CNTRL_1, AXI_DAC_SYNC); 369 + ret = regmap_set_bits(st->regmap, AXI_DAC_CNTRL_1_REG, 370 + AXI_DAC_CNTRL_1_SYNC); 378 371 if (ret) 379 372 return ret; 380 373 ··· 446 437 447 438 if (chan->type != IIO_ALTVOLTAGE) 448 439 return -EINVAL; 449 - if (st->reg_config & AXI_DDS_DISABLE) 440 + if (st->reg_config & AXI_DAC_CONFIG_DDS_DISABLE) 450 441 /* nothing to extend */ 451 442 return 0; 452 443 ··· 463 454 switch (data) { 464 455 case IIO_BACKEND_INTERNAL_CONTINUOUS_WAVE: 465 456 return regmap_update_bits(st->regmap, 466 - AXI_DAC_REG_CHAN_CNTRL_7(chan), 467 - AXI_DAC_DATA_SEL, 457 + AXI_DAC_CHAN_CNTRL_7_REG(chan), 458 + AXI_DAC_CHAN_CNTRL_7_DATA_SEL, 468 459 AXI_DAC_DATA_INTERNAL_TONE); 469 460 case IIO_BACKEND_EXTERNAL: 470 461 return regmap_update_bits(st->regmap, 471 - AXI_DAC_REG_CHAN_CNTRL_7(chan), 472 - AXI_DAC_DATA_SEL, AXI_DAC_DATA_DMA); 462 + AXI_DAC_CHAN_CNTRL_7_REG(chan), 463 + AXI_DAC_CHAN_CNTRL_7_DATA_SEL, 464 + AXI_DAC_DATA_DMA); 473 465 default: 474 466 return -EINVAL; 475 467 } ··· 485 475 486 476 if (!sample_rate) 487 477 return -EINVAL; 488 - if (st->reg_config & AXI_DDS_DISABLE) 478 + if (st->reg_config & AXI_DAC_CONFIG_DDS_DISABLE) 489 479 /* sample_rate has no meaning if DDS is disabled */ 490 480 return 0; 491 481 ··· 590 580 * Force disable the core. Up to the frontend to enable us. And we can 591 581 * still read/write registers... 592 582 */ 593 - ret = regmap_write(st->regmap, AXI_DAC_REG_RSTN, 0); 583 + ret = regmap_write(st->regmap, AXI_DAC_RSTN_REG, 0); 594 584 if (ret) 595 585 return ret; 596 586 ··· 611 601 } 612 602 613 603 /* Let's get the core read only configuration */ 614 - ret = regmap_read(st->regmap, AXI_DAC_REG_CONFIG, &st->reg_config); 604 + ret = regmap_read(st->regmap, AXI_DAC_CONFIG_REG, &st->reg_config); 615 605 if (ret) 616 606 return ret; 617 607 ··· 623 613 * want independent channels let's override the core's default value and 624 614 * set the R1_MODE bit. 625 615 */ 626 - ret = regmap_set_bits(st->regmap, AXI_DAC_REG_CNTRL_2, ADI_DAC_R1_MODE); 616 + ret = regmap_set_bits(st->regmap, AXI_DAC_CNTRL_2_REG, 617 + ADI_DAC_CNTRL_2_R1_MODE); 627 618 if (ret) 628 619 return ret; 629 620
+1 -1
drivers/iio/dac/dpot-dac.c
··· 243 243 244 244 static struct platform_driver dpot_dac_driver = { 245 245 .probe = dpot_dac_probe, 246 - .remove_new = dpot_dac_remove, 246 + .remove = dpot_dac_remove, 247 247 .driver = { 248 248 .name = "iio-dpot-dac", 249 249 .of_match_table = dpot_dac_match,
+3 -3
drivers/iio/dac/lpc18xx_dac.c
··· 184 184 MODULE_DEVICE_TABLE(of, lpc18xx_dac_match); 185 185 186 186 static struct platform_driver lpc18xx_dac_driver = { 187 - .probe = lpc18xx_dac_probe, 188 - .remove_new = lpc18xx_dac_remove, 189 - .driver = { 187 + .probe = lpc18xx_dac_probe, 188 + .remove = lpc18xx_dac_remove, 189 + .driver = { 190 190 .name = "lpc18xx-dac", 191 191 .of_match_table = lpc18xx_dac_match, 192 192 },
+1 -1
drivers/iio/dac/m62332.c
··· 201 201 indio_dev->modes = INDIO_DIRECT_MODE; 202 202 indio_dev->info = &m62332_info; 203 203 204 - ret = iio_map_array_register(indio_dev, client->dev.platform_data); 204 + ret = iio_map_array_register(indio_dev, dev_get_platdata(&client->dev)); 205 205 if (ret < 0) 206 206 return ret; 207 207
+1 -1
drivers/iio/dac/max517.c
··· 143 143 144 144 static int max517_probe(struct i2c_client *client) 145 145 { 146 + const struct max517_platform_data *platform_data = dev_get_platdata(&client->dev); 146 147 const struct i2c_device_id *id = i2c_client_get_device_id(client); 147 148 struct max517_data *data; 148 149 struct iio_dev *indio_dev; 149 - struct max517_platform_data *platform_data = client->dev.platform_data; 150 150 int chan; 151 151 152 152 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+1 -1
drivers/iio/dac/stm32-dac-core.c
··· 245 245 246 246 static struct platform_driver stm32_dac_driver = { 247 247 .probe = stm32_dac_probe, 248 - .remove_new = stm32_dac_remove, 248 + .remove = stm32_dac_remove, 249 249 .driver = { 250 250 .name = "stm32-dac-core", 251 251 .of_match_table = stm32_dac_of_match,
+1 -1
drivers/iio/dac/stm32-dac.c
··· 398 398 399 399 static struct platform_driver stm32_dac_driver = { 400 400 .probe = stm32_dac_probe, 401 - .remove_new = stm32_dac_remove, 401 + .remove = stm32_dac_remove, 402 402 .driver = { 403 403 .name = "stm32-dac", 404 404 .of_match_table = stm32_dac_of_match,
+1 -1
drivers/iio/dac/vf610_dac.c
··· 272 272 273 273 static struct platform_driver vf610_dac_driver = { 274 274 .probe = vf610_dac_probe, 275 - .remove_new = vf610_dac_remove, 275 + .remove = vf610_dac_remove, 276 276 .driver = { 277 277 .name = "vf610-dac", 278 278 .of_match_table = vf610_dac_match,
+1 -1
drivers/iio/frequency/ad9523.c
··· 970 970 971 971 static int ad9523_probe(struct spi_device *spi) 972 972 { 973 - struct ad9523_platform_data *pdata = spi->dev.platform_data; 973 + struct ad9523_platform_data *pdata = dev_get_platdata(&spi->dev); 974 974 struct iio_dev *indio_dev; 975 975 struct ad9523_state *st; 976 976 int ret;
+1 -1
drivers/iio/frequency/adf4350.c
··· 603 603 if (pdata == NULL) 604 604 return -EINVAL; 605 605 } else { 606 - pdata = spi->dev.platform_data; 606 + pdata = dev_get_platdata(&spi->dev); 607 607 } 608 608 609 609 if (!pdata) {
+32 -31
drivers/iio/frequency/adf4371.c
··· 4 4 * 5 5 * Copyright 2019 Analog Devices Inc. 6 6 */ 7 + #include "linux/dev_printk.h" 7 8 #include <linux/bitfield.h> 8 9 #include <linux/clk.h> 9 10 #include <linux/device.h> ··· 151 150 }; 152 151 153 152 struct adf4371_chip_info { 153 + const char *name; 154 154 unsigned int num_channels; 155 155 const struct iio_chan_spec *channels; 156 156 }; ··· 159 157 struct adf4371_state { 160 158 struct spi_device *spi; 161 159 struct regmap *regmap; 162 - struct clk *clkin; 163 160 /* 164 161 * Lock for accessing device registers. Some operations require 165 162 * multiple consecutive R/W operations, during which the device ··· 445 444 ADF4371_CHANNEL(ADF4371_CH_RF32), 446 445 }; 447 446 448 - static const struct adf4371_chip_info adf4371_chip_info[] = { 449 - [ADF4371] = { 450 - .channels = adf4371_chan, 451 - .num_channels = 4, 452 - }, 453 - [ADF4372] = { 454 - .channels = adf4371_chan, 455 - .num_channels = 3, 456 - } 447 + static const struct adf4371_chip_info adf4371_chip_info = { 448 + .name = "adf4371", 449 + .channels = adf4371_chan, 450 + .num_channels = 4, 451 + }; 452 + 453 + static const struct adf4371_chip_info adf4372_chip_info = { 454 + .name = "adf4372", 455 + .channels = adf4371_chan, 456 + .num_channels = 3, 457 457 }; 458 458 459 459 static int adf4371_reg_access(struct iio_dev *indio_dev, ··· 544 542 545 543 static int adf4371_probe(struct spi_device *spi) 546 544 { 547 - const struct spi_device_id *id = spi_get_device_id(spi); 548 545 struct iio_dev *indio_dev; 549 546 struct adf4371_state *st; 550 547 struct regmap *regmap; 548 + struct clk *clkin; 551 549 int ret; 552 550 553 551 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); ··· 555 553 return -ENOMEM; 556 554 557 555 regmap = devm_regmap_init_spi(spi, &adf4371_regmap_config); 558 - if (IS_ERR(regmap)) { 559 - dev_err(&spi->dev, "Error initializing spi regmap: %ld\n", 560 - PTR_ERR(regmap)); 561 - return PTR_ERR(regmap); 562 - } 556 + if (IS_ERR(regmap)) 557 + return dev_err_probe(&spi->dev, PTR_ERR(regmap), 558 + "Error initializing spi regmap\n"); 563 559 564 560 st = iio_priv(indio_dev); 565 - spi_set_drvdata(spi, indio_dev); 566 561 st->spi = spi; 567 562 st->regmap = regmap; 568 563 mutex_init(&st->lock); 569 564 570 - st->chip_info = &adf4371_chip_info[id->driver_data]; 571 - indio_dev->name = id->name; 565 + st->chip_info = spi_get_device_match_data(spi); 566 + if (!st->chip_info) 567 + return -ENODEV; 568 + 569 + indio_dev->name = st->chip_info->name; 572 570 indio_dev->info = &adf4371_info; 573 571 indio_dev->modes = INDIO_DIRECT_MODE; 574 572 indio_dev->channels = st->chip_info->channels; 575 573 indio_dev->num_channels = st->chip_info->num_channels; 576 574 577 - st->clkin = devm_clk_get_enabled(&spi->dev, "clkin"); 578 - if (IS_ERR(st->clkin)) 579 - return PTR_ERR(st->clkin); 575 + clkin = devm_clk_get_enabled(&spi->dev, "clkin"); 576 + if (IS_ERR(clkin)) 577 + return dev_err_probe(&spi->dev, PTR_ERR(clkin), 578 + "Failed to get clkin\n"); 580 579 581 - st->clkin_freq = clk_get_rate(st->clkin); 580 + st->clkin_freq = clk_get_rate(clkin); 582 581 583 582 ret = adf4371_setup(st); 584 - if (ret < 0) { 585 - dev_err(&spi->dev, "ADF4371 setup failed\n"); 586 - return ret; 587 - } 583 + if (ret < 0) 584 + return dev_err_probe(&spi->dev, ret, "ADF4371 setup failed\n"); 588 585 589 586 return devm_iio_device_register(&spi->dev, indio_dev); 590 587 } 591 588 592 589 static const struct spi_device_id adf4371_id_table[] = { 593 - { "adf4371", ADF4371 }, 594 - { "adf4372", ADF4372 }, 590 + { "adf4371", (kernel_ulong_t)&adf4371_chip_info }, 591 + { "adf4372", (kernel_ulong_t)&adf4372_chip_info }, 595 592 {} 596 593 }; 597 594 MODULE_DEVICE_TABLE(spi, adf4371_id_table); 598 595 599 596 static const struct of_device_id adf4371_of_match[] = { 600 - { .compatible = "adi,adf4371" }, 601 - { .compatible = "adi,adf4372" }, 597 + { .compatible = "adi,adf4371", .data = &adf4371_chip_info }, 598 + { .compatible = "adi,adf4372", .data = &adf4372_chip_info}, 602 599 { }, 603 600 }; 604 601 MODULE_DEVICE_TABLE(of, adf4371_of_match);
+1 -2
drivers/iio/gyro/fxas21002c_core.c
··· 849 849 if (!data->dready_trig) 850 850 return -ENOMEM; 851 851 852 - irq_trig = irqd_get_trigger_type(irq_get_irq_data(data->irq)); 853 - 852 + irq_trig = irq_get_trigger_type(data->irq); 854 853 if (irq_trig == IRQF_TRIGGER_RISING) { 855 854 ret = regmap_field_write(data->regmap_fields[F_IPOL], 1); 856 855 if (ret < 0)
+4 -4
drivers/iio/gyro/hid-sensor-gyro-3d.c
··· 27 27 struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX]; 28 28 struct { 29 29 u32 gyro_val[GYRO_3D_CHANNEL_MAX]; 30 - u64 timestamp __aligned(8); 30 + aligned_s64 timestamp; 31 31 } scan; 32 32 int scale_pre_decml; 33 33 int scale_post_decml; ··· 279 279 /* Function to initialize the processing for usage id */ 280 280 static int hid_gyro_3d_probe(struct platform_device *pdev) 281 281 { 282 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 282 283 int ret = 0; 283 284 static const char *name = "gyro_3d"; 284 285 struct iio_dev *indio_dev; 285 286 struct gyro_3d_state *gyro_state; 286 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 287 287 288 288 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*gyro_state)); 289 289 if (!indio_dev) ··· 361 361 /* Function to deinitialize the processing for usage id */ 362 362 static void hid_gyro_3d_remove(struct platform_device *pdev) 363 363 { 364 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 364 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 365 365 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 366 366 struct gyro_3d_state *gyro_state = iio_priv(indio_dev); 367 367 ··· 386 386 .pm = &hid_sensor_pm_ops, 387 387 }, 388 388 .probe = hid_gyro_3d_probe, 389 - .remove_new = hid_gyro_3d_remove, 389 + .remove = hid_gyro_3d_remove, 390 390 }; 391 391 module_platform_driver(hid_gyro_3d_platform_driver); 392 392
+1 -1
drivers/iio/gyro/mpu3050-core.c
··· 1059 1059 /* Check if IRQ is open drain */ 1060 1060 mpu3050->irq_opendrain = device_property_read_bool(dev, "drive-open-drain"); 1061 1061 1062 - irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq)); 1063 1062 /* 1064 1063 * Configure the interrupt generator hardware to supply whatever 1065 1064 * the interrupt is configured for, edges low/high level low/high, 1066 1065 * we can provide it all. 1067 1066 */ 1067 + irq_trig = irq_get_trigger_type(irq); 1068 1068 switch (irq_trig) { 1069 1069 case IRQF_TRIGGER_RISING: 1070 1070 dev_info(&indio_dev->dev,
+2 -2
drivers/iio/humidity/hid-sensor-humidity.c
··· 18 18 struct hid_sensor_hub_attribute_info humidity_attr; 19 19 struct { 20 20 s32 humidity_data; 21 - u64 timestamp __aligned(8); 21 + aligned_s64 timestamp; 22 22 } scan; 23 23 int scale_pre_decml; 24 24 int scale_post_decml; ··· 287 287 .pm = &hid_sensor_pm_ops, 288 288 }, 289 289 .probe = hid_humidity_probe, 290 - .remove_new = hid_humidity_remove, 290 + .remove = hid_humidity_remove, 291 291 }; 292 292 module_platform_driver(hid_humidity_platform_driver); 293 293
+1 -2
drivers/iio/humidity/hts221_buffer.c
··· 81 81 unsigned long irq_type; 82 82 int err; 83 83 84 - irq_type = irqd_get_trigger_type(irq_get_irq_data(hw->irq)); 85 - 84 + irq_type = irq_get_trigger_type(hw->irq); 86 85 switch (irq_type) { 87 86 case IRQF_TRIGGER_HIGH: 88 87 case IRQF_TRIGGER_RISING:
+1
drivers/iio/imu/Kconfig
··· 53 53 ADIS16485, ADIS16488 inertial sensors. 54 54 55 55 source "drivers/iio/imu/bmi160/Kconfig" 56 + source "drivers/iio/imu/bmi270/Kconfig" 56 57 source "drivers/iio/imu/bmi323/Kconfig" 57 58 source "drivers/iio/imu/bno055/Kconfig" 58 59
+1
drivers/iio/imu/Makefile
··· 15 15 obj-$(CONFIG_IIO_ADIS_LIB) += adis_lib.o 16 16 17 17 obj-y += bmi160/ 18 + obj-y += bmi270/ 18 19 obj-y += bmi323/ 19 20 obj-y += bno055/ 20 21
+1 -10
drivers/iio/imu/bmi160/bmi160_core.c
··· 690 690 static int bmi160_setup_irq(struct iio_dev *indio_dev, int irq, 691 691 enum bmi160_int_pin pin) 692 692 { 693 - struct irq_data *desc; 694 - u32 irq_type; 693 + u32 irq_type = irq_get_trigger_type(irq); 695 694 int ret; 696 - 697 - desc = irq_get_irq_data(irq); 698 - if (!desc) { 699 - dev_err(&indio_dev->dev, "Could not find IRQ %d\n", irq); 700 - return -EINVAL; 701 - } 702 - 703 - irq_type = irqd_get_trigger_type(desc); 704 695 705 696 ret = bmi160_config_device_irq(indio_dev, irq_type, pin); 706 697 if (ret)
+32
drivers/iio/imu/bmi270/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # 3 + # BMI270 IMU driver 4 + # 5 + 6 + config BMI270 7 + tristate 8 + select IIO_BUFFER 9 + 10 + config BMI270_I2C 11 + tristate "Bosch BMI270 I2C driver" 12 + depends on I2C 13 + select BMI270 14 + select REGMAP_I2C 15 + help 16 + Enable support for the Bosch BMI270 6-Axis IMU connected to I2C 17 + interface. 18 + 19 + This driver can also be built as a module. If so, the module will be 20 + called bmi270_i2c. 21 + 22 + config BMI270_SPI 23 + tristate "Bosch BMI270 SPI driver" 24 + depends on SPI 25 + select BMI270 26 + select REGMAP_SPI 27 + help 28 + Enable support for the Bosch BMI270 6-Axis IMU connected to SPI 29 + interface. 30 + 31 + This driver can also be built as a module. If so, the module will be 32 + called bmi270_spi.
+7
drivers/iio/imu/bmi270/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # 3 + # Makefile for Bosch BMI270 IMU 4 + # 5 + obj-$(CONFIG_BMI270) += bmi270_core.o 6 + obj-$(CONFIG_BMI270_I2C) += bmi270_i2c.o 7 + obj-$(CONFIG_BMI270_SPI) += bmi270_spi.o
+19
drivers/iio/imu/bmi270/bmi270.h
··· 1 + /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 2 + 3 + #ifndef BMI270_H_ 4 + #define BMI270_H_ 5 + 6 + #include <linux/regmap.h> 7 + #include <linux/iio/iio.h> 8 + 9 + struct device; 10 + struct bmi270_data { 11 + struct device *dev; 12 + struct regmap *regmap; 13 + }; 14 + 15 + extern const struct regmap_config bmi270_regmap_config; 16 + 17 + int bmi270_core_probe(struct device *dev, struct regmap *regmap); 18 + 19 + #endif /* BMI270_H_ */
+307
drivers/iio/imu/bmi270/bmi270_core.c
··· 1 + // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + 3 + #include <linux/bitfield.h> 4 + #include <linux/firmware.h> 5 + #include <linux/i2c.h> 6 + #include <linux/module.h> 7 + #include <linux/regmap.h> 8 + 9 + #include <linux/iio/iio.h> 10 + 11 + #include "bmi270.h" 12 + 13 + #define BMI270_CHIP_ID_REG 0x00 14 + #define BMI270_CHIP_ID_VAL 0x24 15 + #define BMI270_CHIP_ID_MSK GENMASK(7, 0) 16 + 17 + #define BMI270_ACCEL_X_REG 0x0c 18 + #define BMI270_ANG_VEL_X_REG 0x12 19 + 20 + #define BMI270_INTERNAL_STATUS_REG 0x21 21 + #define BMI270_INTERNAL_STATUS_MSG_MSK GENMASK(3, 0) 22 + #define BMI270_INTERNAL_STATUS_MSG_INIT_OK 0x01 23 + 24 + #define BMI270_INTERNAL_STATUS_AXES_REMAP_ERR_MSK BIT(5) 25 + #define BMI270_INTERNAL_STATUS_ODR_50HZ_ERR_MSK BIT(6) 26 + 27 + #define BMI270_ACC_CONF_REG 0x40 28 + #define BMI270_ACC_CONF_ODR_MSK GENMASK(3, 0) 29 + #define BMI270_ACC_CONF_ODR_100HZ 0x08 30 + #define BMI270_ACC_CONF_BWP_MSK GENMASK(6, 4) 31 + #define BMI270_ACC_CONF_BWP_NORMAL_MODE 0x02 32 + #define BMI270_ACC_CONF_FILTER_PERF_MSK BIT(7) 33 + 34 + #define BMI270_GYR_CONF_REG 0x42 35 + #define BMI270_GYR_CONF_ODR_MSK GENMASK(3, 0) 36 + #define BMI270_GYR_CONF_ODR_200HZ 0x09 37 + #define BMI270_GYR_CONF_BWP_MSK GENMASK(5, 4) 38 + #define BMI270_GYR_CONF_BWP_NORMAL_MODE 0x02 39 + #define BMI270_GYR_CONF_NOISE_PERF_MSK BIT(6) 40 + #define BMI270_GYR_CONF_FILTER_PERF_MSK BIT(7) 41 + 42 + #define BMI270_INIT_CTRL_REG 0x59 43 + #define BMI270_INIT_CTRL_LOAD_DONE_MSK BIT(0) 44 + 45 + #define BMI270_INIT_DATA_REG 0x5e 46 + 47 + #define BMI270_PWR_CONF_REG 0x7c 48 + #define BMI270_PWR_CONF_ADV_PWR_SAVE_MSK BIT(0) 49 + #define BMI270_PWR_CONF_FIFO_WKUP_MSK BIT(1) 50 + #define BMI270_PWR_CONF_FUP_EN_MSK BIT(2) 51 + 52 + #define BMI270_PWR_CTRL_REG 0x7d 53 + #define BMI270_PWR_CTRL_AUX_EN_MSK BIT(0) 54 + #define BMI270_PWR_CTRL_GYR_EN_MSK BIT(1) 55 + #define BMI270_PWR_CTRL_ACCEL_EN_MSK BIT(2) 56 + #define BMI270_PWR_CTRL_TEMP_EN_MSK BIT(3) 57 + 58 + #define BMI270_INIT_DATA_FILE "bmi270-init-data.fw" 59 + 60 + enum bmi270_scan { 61 + BMI270_SCAN_ACCEL_X, 62 + BMI270_SCAN_ACCEL_Y, 63 + BMI270_SCAN_ACCEL_Z, 64 + BMI270_SCAN_GYRO_X, 65 + BMI270_SCAN_GYRO_Y, 66 + BMI270_SCAN_GYRO_Z, 67 + }; 68 + 69 + static int bmi270_get_data(struct bmi270_data *bmi270_device, 70 + int chan_type, int axis, int *val) 71 + { 72 + __le16 sample; 73 + int reg; 74 + int ret; 75 + 76 + switch (chan_type) { 77 + case IIO_ACCEL: 78 + reg = BMI270_ACCEL_X_REG + (axis - IIO_MOD_X) * 2; 79 + break; 80 + case IIO_ANGL_VEL: 81 + reg = BMI270_ANG_VEL_X_REG + (axis - IIO_MOD_X) * 2; 82 + break; 83 + default: 84 + return -EINVAL; 85 + } 86 + 87 + ret = regmap_bulk_read(bmi270_device->regmap, reg, &sample, sizeof(sample)); 88 + if (ret) 89 + return ret; 90 + 91 + *val = sign_extend32(le16_to_cpu(sample), 15); 92 + 93 + return 0; 94 + } 95 + 96 + static int bmi270_read_raw(struct iio_dev *indio_dev, 97 + struct iio_chan_spec const *chan, 98 + int *val, int *val2, long mask) 99 + { 100 + int ret; 101 + struct bmi270_data *bmi270_device = iio_priv(indio_dev); 102 + 103 + switch (mask) { 104 + case IIO_CHAN_INFO_RAW: 105 + ret = bmi270_get_data(bmi270_device, chan->type, chan->channel2, val); 106 + if (ret) 107 + return ret; 108 + 109 + return IIO_VAL_INT; 110 + default: 111 + return -EINVAL; 112 + } 113 + } 114 + 115 + static const struct iio_info bmi270_info = { 116 + .read_raw = bmi270_read_raw, 117 + }; 118 + 119 + #define BMI270_ACCEL_CHANNEL(_axis) { \ 120 + .type = IIO_ACCEL, \ 121 + .modified = 1, \ 122 + .channel2 = IIO_MOD_##_axis, \ 123 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 124 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 125 + BIT(IIO_CHAN_INFO_FREQUENCY), \ 126 + } 127 + 128 + #define BMI270_ANG_VEL_CHANNEL(_axis) { \ 129 + .type = IIO_ANGL_VEL, \ 130 + .modified = 1, \ 131 + .channel2 = IIO_MOD_##_axis, \ 132 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 133 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 134 + BIT(IIO_CHAN_INFO_FREQUENCY), \ 135 + } 136 + 137 + static const struct iio_chan_spec bmi270_channels[] = { 138 + BMI270_ACCEL_CHANNEL(X), 139 + BMI270_ACCEL_CHANNEL(Y), 140 + BMI270_ACCEL_CHANNEL(Z), 141 + BMI270_ANG_VEL_CHANNEL(X), 142 + BMI270_ANG_VEL_CHANNEL(Y), 143 + BMI270_ANG_VEL_CHANNEL(Z), 144 + }; 145 + 146 + static int bmi270_validate_chip_id(struct bmi270_data *bmi270_device) 147 + { 148 + int chip_id; 149 + int ret; 150 + struct device *dev = bmi270_device->dev; 151 + struct regmap *regmap = bmi270_device->regmap; 152 + 153 + ret = regmap_read(regmap, BMI270_CHIP_ID_REG, &chip_id); 154 + if (ret) 155 + return dev_err_probe(dev, ret, "Failed to read chip id"); 156 + 157 + if (chip_id != BMI270_CHIP_ID_VAL) 158 + dev_info(dev, "Unknown chip id 0x%x", chip_id); 159 + 160 + return 0; 161 + } 162 + 163 + static int bmi270_write_calibration_data(struct bmi270_data *bmi270_device) 164 + { 165 + int ret; 166 + int status = 0; 167 + const struct firmware *init_data; 168 + struct device *dev = bmi270_device->dev; 169 + struct regmap *regmap = bmi270_device->regmap; 170 + 171 + ret = regmap_clear_bits(regmap, BMI270_PWR_CONF_REG, 172 + BMI270_PWR_CONF_ADV_PWR_SAVE_MSK); 173 + if (ret) 174 + return dev_err_probe(dev, ret, 175 + "Failed to write power configuration"); 176 + 177 + /* 178 + * After disabling advanced power save, all registers are accessible 179 + * after a 450us delay. This delay is specified in table A of the 180 + * datasheet. 181 + */ 182 + usleep_range(450, 1000); 183 + 184 + ret = regmap_clear_bits(regmap, BMI270_INIT_CTRL_REG, 185 + BMI270_INIT_CTRL_LOAD_DONE_MSK); 186 + if (ret) 187 + return dev_err_probe(dev, ret, 188 + "Failed to prepare device to load init data"); 189 + 190 + ret = request_firmware(&init_data, BMI270_INIT_DATA_FILE, dev); 191 + if (ret) 192 + return dev_err_probe(dev, ret, "Failed to load init data file"); 193 + 194 + ret = regmap_bulk_write(regmap, BMI270_INIT_DATA_REG, 195 + init_data->data, init_data->size); 196 + release_firmware(init_data); 197 + if (ret) 198 + return dev_err_probe(dev, ret, "Failed to write init data"); 199 + 200 + ret = regmap_set_bits(regmap, BMI270_INIT_CTRL_REG, 201 + BMI270_INIT_CTRL_LOAD_DONE_MSK); 202 + if (ret) 203 + return dev_err_probe(dev, ret, 204 + "Failed to stop device initialization"); 205 + 206 + /* 207 + * Wait at least 140ms for the device to complete configuration. 208 + * This delay is specified in table C of the datasheet. 209 + */ 210 + usleep_range(140000, 160000); 211 + 212 + ret = regmap_read(regmap, BMI270_INTERNAL_STATUS_REG, &status); 213 + if (ret) 214 + return dev_err_probe(dev, ret, "Failed to read internal status"); 215 + 216 + if (status != BMI270_INTERNAL_STATUS_MSG_INIT_OK) 217 + return dev_err_probe(dev, -ENODEV, "Device failed to initialize"); 218 + 219 + return 0; 220 + } 221 + 222 + static int bmi270_configure_imu(struct bmi270_data *bmi270_device) 223 + { 224 + int ret; 225 + struct device *dev = bmi270_device->dev; 226 + struct regmap *regmap = bmi270_device->regmap; 227 + 228 + ret = regmap_set_bits(regmap, BMI270_PWR_CTRL_REG, 229 + BMI270_PWR_CTRL_AUX_EN_MSK | 230 + BMI270_PWR_CTRL_GYR_EN_MSK | 231 + BMI270_PWR_CTRL_ACCEL_EN_MSK); 232 + if (ret) 233 + return dev_err_probe(dev, ret, "Failed to enable accelerometer and gyroscope"); 234 + 235 + ret = regmap_set_bits(regmap, BMI270_ACC_CONF_REG, 236 + FIELD_PREP(BMI270_ACC_CONF_ODR_MSK, 237 + BMI270_ACC_CONF_ODR_100HZ) | 238 + FIELD_PREP(BMI270_ACC_CONF_BWP_MSK, 239 + BMI270_ACC_CONF_BWP_NORMAL_MODE) | 240 + BMI270_PWR_CONF_ADV_PWR_SAVE_MSK); 241 + if (ret) 242 + return dev_err_probe(dev, ret, "Failed to configure accelerometer"); 243 + 244 + ret = regmap_set_bits(regmap, BMI270_GYR_CONF_REG, 245 + FIELD_PREP(BMI270_GYR_CONF_ODR_MSK, 246 + BMI270_GYR_CONF_ODR_200HZ) | 247 + FIELD_PREP(BMI270_GYR_CONF_BWP_MSK, 248 + BMI270_GYR_CONF_BWP_NORMAL_MODE) | 249 + BMI270_PWR_CONF_ADV_PWR_SAVE_MSK); 250 + if (ret) 251 + return dev_err_probe(dev, ret, "Failed to configure gyroscope"); 252 + 253 + /* Enable FIFO_WKUP, Disable ADV_PWR_SAVE and FUP_EN */ 254 + ret = regmap_write(regmap, BMI270_PWR_CONF_REG, 255 + BMI270_PWR_CONF_FIFO_WKUP_MSK); 256 + if (ret) 257 + return dev_err_probe(dev, ret, "Failed to set power configuration"); 258 + 259 + return 0; 260 + } 261 + 262 + static int bmi270_chip_init(struct bmi270_data *bmi270_device) 263 + { 264 + int ret; 265 + 266 + ret = bmi270_validate_chip_id(bmi270_device); 267 + if (ret) 268 + return ret; 269 + 270 + ret = bmi270_write_calibration_data(bmi270_device); 271 + if (ret) 272 + return ret; 273 + 274 + return bmi270_configure_imu(bmi270_device); 275 + } 276 + 277 + int bmi270_core_probe(struct device *dev, struct regmap *regmap) 278 + { 279 + int ret; 280 + struct bmi270_data *bmi270_device; 281 + struct iio_dev *indio_dev; 282 + 283 + indio_dev = devm_iio_device_alloc(dev, sizeof(*bmi270_device)); 284 + if (!indio_dev) 285 + return -ENOMEM; 286 + 287 + bmi270_device = iio_priv(indio_dev); 288 + bmi270_device->dev = dev; 289 + bmi270_device->regmap = regmap; 290 + 291 + ret = bmi270_chip_init(bmi270_device); 292 + if (ret) 293 + return ret; 294 + 295 + indio_dev->channels = bmi270_channels; 296 + indio_dev->num_channels = ARRAY_SIZE(bmi270_channels); 297 + indio_dev->name = "bmi270"; 298 + indio_dev->modes = INDIO_DIRECT_MODE; 299 + indio_dev->info = &bmi270_info; 300 + 301 + return devm_iio_device_register(dev, indio_dev); 302 + } 303 + EXPORT_SYMBOL_NS_GPL(bmi270_core_probe, IIO_BMI270); 304 + 305 + MODULE_AUTHOR("Alex Lanzano"); 306 + MODULE_DESCRIPTION("BMI270 driver"); 307 + MODULE_LICENSE("GPL");
+52
drivers/iio/imu/bmi270/bmi270_i2c.c
··· 1 + // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + 3 + #include <linux/i2c.h> 4 + #include <linux/iio/iio.h> 5 + #include <linux/module.h> 6 + #include <linux/mod_devicetable.h> 7 + #include <linux/regmap.h> 8 + 9 + #include "bmi270.h" 10 + 11 + static const struct regmap_config bmi270_i2c_regmap_config = { 12 + .reg_bits = 8, 13 + .val_bits = 8, 14 + }; 15 + 16 + static int bmi270_i2c_probe(struct i2c_client *client) 17 + { 18 + struct regmap *regmap; 19 + struct device *dev = &client->dev; 20 + 21 + regmap = devm_regmap_init_i2c(client, &bmi270_i2c_regmap_config); 22 + if (IS_ERR(regmap)) 23 + return dev_err_probe(dev, PTR_ERR(regmap), 24 + "Failed to init i2c regmap"); 25 + 26 + return bmi270_core_probe(dev, regmap); 27 + } 28 + 29 + static const struct i2c_device_id bmi270_i2c_id[] = { 30 + { "bmi270", 0 }, 31 + { } 32 + }; 33 + 34 + static const struct of_device_id bmi270_of_match[] = { 35 + { .compatible = "bosch,bmi270" }, 36 + { } 37 + }; 38 + 39 + static struct i2c_driver bmi270_i2c_driver = { 40 + .driver = { 41 + .name = "bmi270_i2c", 42 + .of_match_table = bmi270_of_match, 43 + }, 44 + .probe = bmi270_i2c_probe, 45 + .id_table = bmi270_i2c_id, 46 + }; 47 + module_i2c_driver(bmi270_i2c_driver); 48 + 49 + MODULE_AUTHOR("Alex Lanzano"); 50 + MODULE_DESCRIPTION("BMI270 driver"); 51 + MODULE_LICENSE("GPL"); 52 + MODULE_IMPORT_NS(IIO_BMI270);
+85
drivers/iio/imu/bmi270/bmi270_spi.c
··· 1 + // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + 3 + #include <linux/iio/iio.h> 4 + #include <linux/mod_devicetable.h> 5 + #include <linux/module.h> 6 + #include <linux/regmap.h> 7 + #include <linux/spi/spi.h> 8 + 9 + #include "bmi270.h" 10 + 11 + /* 12 + * The following two functions are taken from the BMI323 spi driver code. 13 + * In section 6.4 of the BMI270 data it specifies that after a read 14 + * operation the first data byte from the device is a dummy byte 15 + */ 16 + static int bmi270_regmap_spi_read(void *spi, const void *reg_buf, 17 + size_t reg_size, void *val_buf, 18 + size_t val_size) 19 + { 20 + return spi_write_then_read(spi, reg_buf, reg_size, val_buf, val_size); 21 + } 22 + 23 + static int bmi270_regmap_spi_write(void *spi, const void *data, 24 + size_t count) 25 + { 26 + u8 *data_buff = (u8 *)data; 27 + 28 + /* 29 + * Remove the extra pad byte since its only needed for the read 30 + * operation 31 + */ 32 + data_buff[1] = data_buff[0]; 33 + return spi_write_then_read(spi, data_buff + 1, count - 1, NULL, 0); 34 + } 35 + 36 + static const struct regmap_bus bmi270_regmap_bus = { 37 + .read = bmi270_regmap_spi_read, 38 + .write = bmi270_regmap_spi_write, 39 + }; 40 + 41 + static const struct regmap_config bmi270_spi_regmap_config = { 42 + .reg_bits = 8, 43 + .val_bits = 8, 44 + .pad_bits = 8, 45 + .read_flag_mask = BIT(7), 46 + }; 47 + 48 + static int bmi270_spi_probe(struct spi_device *spi) 49 + { 50 + struct regmap *regmap; 51 + struct device *dev = &spi->dev; 52 + 53 + regmap = devm_regmap_init(dev, &bmi270_regmap_bus, dev, 54 + &bmi270_spi_regmap_config); 55 + if (IS_ERR(regmap)) 56 + return dev_err_probe(dev, PTR_ERR(regmap), 57 + "Failed to init i2c regmap"); 58 + 59 + return bmi270_core_probe(dev, regmap); 60 + } 61 + 62 + static const struct spi_device_id bmi270_spi_id[] = { 63 + { "bmi270" }, 64 + { } 65 + }; 66 + 67 + static const struct of_device_id bmi270_of_match[] = { 68 + { .compatible = "bosch,bmi270" }, 69 + { } 70 + }; 71 + 72 + static struct spi_driver bmi270_spi_driver = { 73 + .driver = { 74 + .name = "bmi270", 75 + .of_match_table = bmi270_of_match, 76 + }, 77 + .probe = bmi270_spi_probe, 78 + .id_table = bmi270_spi_id, 79 + }; 80 + module_spi_driver(bmi270_spi_driver); 81 + 82 + MODULE_AUTHOR("Alex Lanzano"); 83 + MODULE_DESCRIPTION("BMI270 driver"); 84 + MODULE_LICENSE("GPL"); 85 + MODULE_IMPORT_NS(IIO_BMI270);
-1
drivers/iio/imu/bmi323/bmi323.h
··· 141 141 #define BMI323_STEP_SC1_REG 0x10 142 142 #define BMI323_STEP_SC1_WTRMRK_MSK GENMASK(9, 0) 143 143 #define BMI323_STEP_SC1_RST_CNT_MSK BIT(10) 144 - #define BMI323_STEP_SC1_REG 0x10 145 144 #define BMI323_STEP_LEN 2 146 145 147 146 /* Tap gesture config registers */
+1 -7
drivers/iio/imu/bmi323/bmi323_core.c
··· 1881 1881 struct fwnode_handle *fwnode; 1882 1882 enum bmi323_irq_pin irq_pin; 1883 1883 int ret, irq, irq_type; 1884 - struct irq_data *desc; 1885 1884 1886 1885 fwnode = dev_fwnode(data->dev); 1887 1886 if (!fwnode) ··· 1897 1898 irq_pin = BMI323_IRQ_INT2; 1898 1899 } 1899 1900 1900 - desc = irq_get_irq_data(irq); 1901 - if (!desc) 1902 - return dev_err_probe(data->dev, -EINVAL, 1903 - "Could not find IRQ %d\n", irq); 1904 - 1905 - irq_type = irqd_get_trigger_type(desc); 1901 + irq_type = irq_get_trigger_type(irq); 1906 1902 switch (irq_type) { 1907 1903 case IRQF_TRIGGER_RISING: 1908 1904 latch = false;
-1
drivers/iio/imu/fxos8700_core.c
··· 8 8 */ 9 9 #include <linux/module.h> 10 10 #include <linux/regmap.h> 11 - #include <linux/acpi.h> 12 11 #include <linux/bitops.h> 13 12 #include <linux/bitfield.h> 14 13
+1 -9
drivers/iio/imu/inv_icm42600/inv_icm42600_core.c
··· 673 673 { 674 674 struct device *dev = regmap_get_device(regmap); 675 675 struct inv_icm42600_state *st; 676 - struct irq_data *irq_desc; 677 676 int irq_type; 678 677 bool open_drain; 679 678 int ret; ··· 682 683 return -ENODEV; 683 684 } 684 685 685 - /* get irq properties, set trigger falling by default */ 686 - irq_desc = irq_get_irq_data(irq); 687 - if (!irq_desc) { 688 - dev_err(dev, "could not find IRQ %d\n", irq); 689 - return -EINVAL; 690 - } 691 - 692 - irq_type = irqd_get_trigger_type(irq_desc); 686 + irq_type = irq_get_trigger_type(irq); 693 687 if (!irq_type) 694 688 irq_type = IRQF_TRIGGER_FALLING; 695 689
+17
drivers/iio/imu/inv_icm42600/inv_icm42600_i2c.c
··· 71 71 inv_icm42600_i2c_bus_setup); 72 72 } 73 73 74 + /* 75 + * device id table is used to identify what device can be 76 + * supported by this driver 77 + */ 78 + static const struct i2c_device_id inv_icm42600_id[] = { 79 + { "icm42600", INV_CHIP_ICM42600 }, 80 + { "icm42602", INV_CHIP_ICM42602 }, 81 + { "icm42605", INV_CHIP_ICM42605 }, 82 + { "icm42686", INV_CHIP_ICM42686 }, 83 + { "icm42622", INV_CHIP_ICM42622 }, 84 + { "icm42688", INV_CHIP_ICM42688 }, 85 + { "icm42631", INV_CHIP_ICM42631 }, 86 + { } 87 + }; 88 + MODULE_DEVICE_TABLE(i2c, inv_icm42600_id); 89 + 74 90 static const struct of_device_id inv_icm42600_of_matches[] = { 75 91 { 76 92 .compatible = "invensense,icm42600", ··· 120 104 .of_match_table = inv_icm42600_of_matches, 121 105 .pm = pm_ptr(&inv_icm42600_pm_ops), 122 106 }, 107 + .id_table = inv_icm42600_id, 123 108 .probe = inv_icm42600_probe, 124 109 }; 125 110 module_i2c_driver(inv_icm42600_driver);
+17
drivers/iio/imu/inv_icm42600/inv_icm42600_spi.c
··· 67 67 inv_icm42600_spi_bus_setup); 68 68 } 69 69 70 + /* 71 + * device id table is used to identify what device can be 72 + * supported by this driver 73 + */ 74 + static const struct spi_device_id inv_icm42600_id[] = { 75 + { "icm42600", INV_CHIP_ICM42600 }, 76 + { "icm42602", INV_CHIP_ICM42602 }, 77 + { "icm42605", INV_CHIP_ICM42605 }, 78 + { "icm42686", INV_CHIP_ICM42686 }, 79 + { "icm42622", INV_CHIP_ICM42622 }, 80 + { "icm42688", INV_CHIP_ICM42688 }, 81 + { "icm42631", INV_CHIP_ICM42631 }, 82 + { } 83 + }; 84 + MODULE_DEVICE_TABLE(spi, inv_icm42600_id); 85 + 70 86 static const struct of_device_id inv_icm42600_of_matches[] = { 71 87 { 72 88 .compatible = "invensense,icm42600", ··· 116 100 .of_match_table = inv_icm42600_of_matches, 117 101 .pm = pm_ptr(&inv_icm42600_pm_ops), 118 102 }, 103 + .id_table = inv_icm42600_id, 119 104 .probe = inv_icm42600_probe, 120 105 }; 121 106 module_spi_driver(inv_icm42600_driver);
+4 -2
drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
··· 10 10 #include <linux/i2c.h> 11 11 #include <linux/dmi.h> 12 12 #include <linux/acpi.h> 13 + #include <linux/wordpart.h> 14 + 13 15 #include "inv_mpu_iio.h" 14 16 15 17 enum inv_mpu_product_name { ··· 120 118 return ret; 121 119 122 120 acpi_dev_free_resource_list(&resources); 123 - *primary_addr = i2c_addr & 0x0000ffff; 124 - *secondary_addr = (i2c_addr & 0xffff0000) >> 16; 121 + *primary_addr = lower_16_bits(i2c_addr); 122 + *secondary_addr = upper_16_bits(i2c_addr); 125 123 126 124 return 0; 127 125 }
+21 -8
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 286 286 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, 287 287 .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 288 288 }, 289 + { 290 + .whoami = INV_IAM20680HP_WHOAMI_VALUE, 291 + .name = "IAM20680HP", 292 + .reg = &reg_set_6500, 293 + .config = &chip_config_6500, 294 + .fifo_size = 4 * 1024, 295 + .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, 296 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 297 + }, 298 + { 299 + .whoami = INV_IAM20680HT_WHOAMI_VALUE, 300 + .name = "IAM20680HT", 301 + .reg = &reg_set_6500, 302 + .config = &chip_config_6500, 303 + .fifo_size = 4 * 1024, 304 + .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, 305 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 306 + }, 289 307 }; 290 308 291 309 static int inv_mpu6050_pwr_mgmt_1_write(struct inv_mpu6050_state *st, bool sleep, ··· 528 510 return 0; 529 511 case INV_ICM20689: 530 512 case INV_ICM20690: 513 + case INV_IAM20680HT: 514 + case INV_IAM20680HP: 531 515 /* set FIFO size to maximum value */ 532 516 val |= INV_ICM20689_BITS_FIFO_SIZE_MAX; 533 517 break; ··· 1879 1859 struct inv_mpu6050_platform_data *pdata; 1880 1860 struct device *dev = regmap_get_device(regmap); 1881 1861 int result; 1882 - struct irq_data *desc; 1883 1862 int irq_type; 1884 1863 1885 1864 indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); ··· 1912 1893 } 1913 1894 1914 1895 if (irq > 0) { 1915 - desc = irq_get_irq_data(irq); 1916 - if (!desc) { 1917 - dev_err(dev, "Could not find IRQ %d\n", irq); 1918 - return -EINVAL; 1919 - } 1920 - 1921 - irq_type = irqd_get_trigger_type(desc); 1896 + irq_type = irq_get_trigger_type(irq); 1922 1897 if (!irq_type) 1923 1898 irq_type = IRQF_TRIGGER_RISING; 1924 1899 } else {
+10
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
··· 188 188 {"icm20602", INV_ICM20602}, 189 189 {"icm20690", INV_ICM20690}, 190 190 {"iam20680", INV_IAM20680}, 191 + {"iam20680hp", INV_IAM20680HP}, 192 + {"iam20680ht", INV_IAM20680HT}, 191 193 {} 192 194 }; 193 195 ··· 255 253 { 256 254 .compatible = "invensense,iam20680", 257 255 .data = (void *)INV_IAM20680 256 + }, 257 + { 258 + .compatible = "invensense,iam20680hp", 259 + .data = (void *)INV_IAM20680HP 260 + }, 261 + { 262 + .compatible = "invensense,iam20680ht", 263 + .data = (void *)INV_IAM20680HT 258 264 }, 259 265 { } 260 266 };
+4
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
··· 85 85 INV_ICM20602, 86 86 INV_ICM20690, 87 87 INV_IAM20680, 88 + INV_IAM20680HP, 89 + INV_IAM20680HT, 88 90 INV_NUM_PARTS 89 91 }; 90 92 ··· 426 424 #define INV_ICM20602_WHOAMI_VALUE 0x12 427 425 #define INV_ICM20690_WHOAMI_VALUE 0x20 428 426 #define INV_IAM20680_WHOAMI_VALUE 0xA9 427 + #define INV_IAM20680HP_WHOAMI_VALUE 0xF8 428 + #define INV_IAM20680HT_WHOAMI_VALUE 0xFA 429 429 430 430 /* scan element definition for generic MPU6xxx devices */ 431 431 enum inv_mpu6050_scan {
+10
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
··· 80 80 {"icm20602", INV_ICM20602}, 81 81 {"icm20690", INV_ICM20690}, 82 82 {"iam20680", INV_IAM20680}, 83 + {"iam20680hp", INV_IAM20680HP}, 84 + {"iam20680ht", INV_IAM20680HT}, 83 85 {} 84 86 }; 85 87 ··· 143 141 { 144 142 .compatible = "invensense,iam20680", 145 143 .data = (void *)INV_IAM20680 144 + }, 145 + { 146 + .compatible = "invensense,iam20680hp", 147 + .data = (void *)INV_IAM20680HP 148 + }, 149 + { 150 + .compatible = "invensense,iam20680ht", 151 + .data = (void *)INV_IAM20680HT 146 152 }, 147 153 { } 148 154 };
+3 -22
drivers/iio/imu/kmx61.c
··· 7 7 * IIO driver for KMX61 (7-bit I2C slave address 0x0E or 0x0F). 8 8 */ 9 9 10 - #include <linux/module.h> 11 10 #include <linux/i2c.h> 12 - #include <linux/acpi.h> 13 11 #include <linux/interrupt.h> 12 + #include <linux/mod_devicetable.h> 13 + #include <linux/module.h> 14 14 #include <linux/pm.h> 15 15 #include <linux/pm_runtime.h> 16 + 16 17 #include <linux/iio/iio.h> 17 18 #include <linux/iio/sysfs.h> 18 19 #include <linux/iio/events.h> ··· 1218 1217 return IRQ_HANDLED; 1219 1218 } 1220 1219 1221 - static const char *kmx61_match_acpi_device(struct device *dev) 1222 - { 1223 - const struct acpi_device_id *id; 1224 - 1225 - id = acpi_match_device(dev->driver->acpi_match_table, dev); 1226 - if (!id) 1227 - return NULL; 1228 - return dev_name(dev); 1229 - } 1230 - 1231 1220 static struct iio_dev *kmx61_indiodev_setup(struct kmx61_data *data, 1232 1221 const struct iio_info *info, 1233 1222 const struct iio_chan_spec *chan, ··· 1284 1293 1285 1294 if (id) 1286 1295 name = id->name; 1287 - else if (ACPI_HANDLE(&client->dev)) 1288 - name = kmx61_match_acpi_device(&client->dev); 1289 1296 else 1290 1297 return -ENODEV; 1291 1298 ··· 1485 1496 RUNTIME_PM_OPS(kmx61_runtime_suspend, kmx61_runtime_resume, NULL) 1486 1497 }; 1487 1498 1488 - static const struct acpi_device_id kmx61_acpi_match[] = { 1489 - {"KMX61021", 0}, 1490 - {} 1491 - }; 1492 - 1493 - MODULE_DEVICE_TABLE(acpi, kmx61_acpi_match); 1494 - 1495 1499 static const struct i2c_device_id kmx61_id[] = { 1496 1500 { "kmx611021" }, 1497 1501 {} ··· 1495 1513 static struct i2c_driver kmx61_driver = { 1496 1514 .driver = { 1497 1515 .name = KMX61_DRV_NAME, 1498 - .acpi_match_table = kmx61_acpi_match, 1499 1516 .pm = pm_ptr(&kmx61_pm_ops), 1500 1517 }, 1501 1518 .probe = kmx61_probe,
+1 -1
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
··· 447 447 /* Ensure natural alignment of buffer elements */ 448 448 struct { 449 449 __le16 channels[3]; 450 - s64 ts __aligned(8); 450 + aligned_s64 ts; 451 451 } scan[ST_LSM6DSX_ID_MAX]; 452 452 }; 453 453
+6 -12
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 2132 2132 const struct st_lsm6dsx_reg **drdy_reg) 2133 2133 { 2134 2134 struct device *dev = hw->dev; 2135 + const struct st_sensors_platform_data *pdata = dev_get_platdata(dev); 2135 2136 int err = 0, drdy_pin; 2136 2137 2137 - if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0) { 2138 - struct st_sensors_platform_data *pdata; 2139 - 2140 - pdata = (struct st_sensors_platform_data *)dev->platform_data; 2138 + if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0) 2141 2139 drdy_pin = pdata ? pdata->drdy_int_pin : 1; 2142 - } 2143 2140 2144 2141 switch (drdy_pin) { 2145 2142 case 1: ··· 2159 2162 static int st_lsm6dsx_init_shub(struct st_lsm6dsx_hw *hw) 2160 2163 { 2161 2164 const struct st_lsm6dsx_shub_settings *hub_settings; 2162 - struct st_sensors_platform_data *pdata; 2163 2165 struct device *dev = hw->dev; 2166 + const struct st_sensors_platform_data *pdata = dev_get_platdata(dev); 2164 2167 unsigned int data; 2165 2168 int err = 0; 2166 2169 2167 2170 hub_settings = &hw->settings->shub_settings; 2168 2171 2169 - pdata = (struct st_sensors_platform_data *)dev->platform_data; 2170 2172 if (device_property_read_bool(dev, "st,pullups") || 2171 2173 (pdata && pdata->pullups)) { 2172 2174 if (hub_settings->pullup_en.sec_page) { ··· 2520 2524 2521 2525 static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw) 2522 2526 { 2523 - struct st_sensors_platform_data *pdata; 2524 2527 const struct st_lsm6dsx_reg *reg; 2525 2528 struct device *dev = hw->dev; 2529 + const struct st_sensors_platform_data *pdata = dev_get_platdata(dev); 2526 2530 unsigned long irq_type; 2527 2531 bool irq_active_low; 2528 2532 int err; 2529 2533 2530 - irq_type = irqd_get_trigger_type(irq_get_irq_data(hw->irq)); 2531 - 2534 + irq_type = irq_get_trigger_type(hw->irq); 2532 2535 switch (irq_type) { 2533 2536 case IRQF_TRIGGER_HIGH: 2534 2537 case IRQF_TRIGGER_RISING: ··· 2549 2554 if (err < 0) 2550 2555 return err; 2551 2556 2552 - pdata = (struct st_sensors_platform_data *)dev->platform_data; 2553 2557 if (device_property_read_bool(dev, "drive-open-drain") || 2554 2558 (pdata && pdata->open_drain)) { 2555 2559 reg = &hw->settings->irq_config.od; ··· 2633 2639 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, 2634 2640 struct regmap *regmap) 2635 2641 { 2636 - struct st_sensors_platform_data *pdata = dev->platform_data; 2642 + const struct st_sensors_platform_data *pdata = dev_get_platdata(dev); 2637 2643 const struct st_lsm6dsx_shub_settings *hub_settings; 2638 2644 struct st_lsm6dsx_hw *hw; 2639 2645 const char *name = NULL;
+4 -3
drivers/iio/inkern.c
··· 20 20 21 21 struct iio_map_internal { 22 22 struct iio_dev *indio_dev; 23 - struct iio_map *map; 23 + const struct iio_map *map; 24 24 struct list_head l; 25 25 }; 26 26 ··· 42 42 return ret; 43 43 } 44 44 45 - int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps) 45 + int iio_map_array_register(struct iio_dev *indio_dev, const struct iio_map *maps) 46 46 { 47 47 struct iio_map_internal *mapi; 48 48 int i = 0; ··· 86 86 iio_map_array_unregister(indio_dev); 87 87 } 88 88 89 - int devm_iio_map_array_register(struct device *dev, struct iio_dev *indio_dev, struct iio_map *maps) 89 + int devm_iio_map_array_register(struct device *dev, struct iio_dev *indio_dev, 90 + const struct iio_map *maps) 90 91 { 91 92 int ret; 92 93
+2 -2
drivers/iio/light/Kconfig
··· 669 669 module will be called vcnl4035. 670 670 671 671 config VEML6030 672 - tristate "VEML6030 ambient light sensor" 672 + tristate "VEML6030 and VEML6035 ambient light sensors" 673 673 select REGMAP_I2C 674 674 depends on I2C 675 675 help 676 676 Say Y here if you want to build a driver for the Vishay VEML6030 677 - ambient light sensor (ALS). 677 + and VEML6035 ambient light sensors (ALS). 678 678 679 679 To compile this driver as a module, choose M here: the 680 680 module will be called veml6030.
+5 -6
drivers/iio/light/al3010.c
··· 87 87 int ret; 88 88 89 89 ret = al3010_set_pwr(data->client, true); 90 + if (ret < 0) 91 + return ret; 90 92 93 + ret = devm_add_action_or_reset(&data->client->dev, 94 + al3010_set_pwr_off, 95 + data); 91 96 if (ret < 0) 92 97 return ret; 93 98 ··· 194 189 dev_err(&client->dev, "al3010 chip init failed\n"); 195 190 return ret; 196 191 } 197 - 198 - ret = devm_add_action_or_reset(&client->dev, 199 - al3010_set_pwr_off, 200 - data); 201 - if (ret < 0) 202 - return ret; 203 192 204 193 return devm_iio_device_register(&client->dev, indio_dev); 205 194 }
+1 -2
drivers/iio/light/cm32181.c
··· 217 217 cm32181->lux_per_bit = CM32181_LUX_PER_BIT; 218 218 cm32181->lux_per_bit_base_it = CM32181_LUX_PER_BIT_BASE_IT; 219 219 220 - if (ACPI_HANDLE(cm32181->dev)) 221 - cm32181_acpi_parse_cpm_tables(cm32181); 220 + cm32181_acpi_parse_cpm_tables(cm32181); 222 221 223 222 /* Initialize registers*/ 224 223 for_each_set_bit(i, &cm32181->init_regs_bitmap, CM32181_CONF_REG_NUM) {
+1 -1
drivers/iio/light/cm3605.c
··· 318 318 .pm = pm_sleep_ptr(&cm3605_dev_pm_ops), 319 319 }, 320 320 .probe = cm3605_probe, 321 - .remove_new = cm3605_remove, 321 + .remove = cm3605_remove, 322 322 }; 323 323 module_platform_driver(cm3605_driver); 324 324
+4 -4
drivers/iio/light/hid-sensor-als.c
··· 31 31 struct iio_chan_spec channels[CHANNEL_SCAN_INDEX_MAX + 1]; 32 32 struct { 33 33 u32 illum[CHANNEL_SCAN_INDEX_MAX]; 34 - u64 timestamp __aligned(8); 34 + aligned_s64 timestamp; 35 35 } scan; 36 36 int scale_pre_decml; 37 37 int scale_post_decml; ··· 356 356 /* Function to initialize the processing for usage id */ 357 357 static int hid_als_probe(struct platform_device *pdev) 358 358 { 359 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 359 360 int ret = 0; 360 361 static const char *name = "als"; 361 362 struct iio_dev *indio_dev; 362 363 struct als_state *als_state; 363 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 364 364 365 365 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct als_state)); 366 366 if (!indio_dev) ··· 438 438 /* Function to deinitialize the processing for usage id */ 439 439 static void hid_als_remove(struct platform_device *pdev) 440 440 { 441 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 441 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 442 442 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 443 443 struct als_state *als_state = iio_priv(indio_dev); 444 444 ··· 467 467 .pm = &hid_sensor_pm_ops, 468 468 }, 469 469 .probe = hid_als_probe, 470 - .remove_new = hid_als_remove, 470 + .remove = hid_als_remove, 471 471 }; 472 472 module_platform_driver(hid_als_platform_driver); 473 473
+3 -3
drivers/iio/light/hid-sensor-prox.c
··· 233 233 /* Function to initialize the processing for usage id */ 234 234 static int hid_prox_probe(struct platform_device *pdev) 235 235 { 236 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 236 237 int ret = 0; 237 238 static const char *name = "prox"; 238 239 struct iio_dev *indio_dev; 239 240 struct prox_state *prox_state; 240 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 241 241 242 242 indio_dev = devm_iio_device_alloc(&pdev->dev, 243 243 sizeof(struct prox_state)); ··· 315 315 /* Function to deinitialize the processing for usage id */ 316 316 static void hid_prox_remove(struct platform_device *pdev) 317 317 { 318 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 318 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 319 319 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 320 320 struct prox_state *prox_state = iio_priv(indio_dev); 321 321 ··· 344 344 .pm = &hid_sensor_pm_ops, 345 345 }, 346 346 .probe = hid_prox_probe, 347 - .remove_new = hid_prox_remove, 347 + .remove = hid_prox_remove, 348 348 }; 349 349 module_platform_driver(hid_prox_platform_driver); 350 350
+4 -4
drivers/iio/light/lm3533-als.c
··· 754 754 } 755 755 756 756 static int lm3533_als_setup(struct lm3533_als *als, 757 - struct lm3533_als_platform_data *pdata) 757 + const struct lm3533_als_platform_data *pdata) 758 758 { 759 759 int ret; 760 760 ··· 828 828 829 829 static int lm3533_als_probe(struct platform_device *pdev) 830 830 { 831 + const struct lm3533_als_platform_data *pdata; 831 832 struct lm3533 *lm3533; 832 - struct lm3533_als_platform_data *pdata; 833 833 struct lm3533_als *als; 834 834 struct iio_dev *indio_dev; 835 835 int ret; ··· 838 838 if (!lm3533) 839 839 return -EINVAL; 840 840 841 - pdata = pdev->dev.platform_data; 841 + pdata = dev_get_platdata(&pdev->dev); 842 842 if (!pdata) { 843 843 dev_err(&pdev->dev, "no platform data\n"); 844 844 return -EINVAL; ··· 912 912 .name = "lm3533-als", 913 913 }, 914 914 .probe = lm3533_als_probe, 915 - .remove_new = lm3533_als_remove, 915 + .remove = lm3533_als_remove, 916 916 }; 917 917 module_platform_driver(lm3533_als_driver); 918 918
+358 -7
drivers/iio/light/ltr390.c
··· 18 18 * - Interrupt support 19 19 */ 20 20 21 + #include <linux/bitfield.h> 22 + #include <linux/device.h> 21 23 #include <linux/i2c.h> 24 + #include <linux/irq.h> 25 + #include <linux/interrupt.h> 22 26 #include <linux/math.h> 23 27 #include <linux/module.h> 24 28 #include <linux/mutex.h> 25 29 #include <linux/regmap.h> 26 - #include <linux/bitfield.h> 27 30 28 31 #include <linux/iio/iio.h> 32 + #include <linux/iio/events.h> 29 33 30 34 #include <linux/unaligned.h> 31 35 ··· 37 33 #define LTR390_ALS_UVS_MEAS_RATE 0x04 38 34 #define LTR390_ALS_UVS_GAIN 0x05 39 35 #define LTR390_PART_ID 0x06 36 + #define LTR390_MAIN_STATUS 0x07 40 37 #define LTR390_ALS_DATA 0x0D 41 38 #define LTR390_UVS_DATA 0x10 42 39 #define LTR390_INT_CFG 0x19 40 + #define LTR390_INT_PST 0x1A 41 + #define LTR390_THRESH_UP 0x21 42 + #define LTR390_THRESH_LOW 0x24 43 43 44 44 #define LTR390_PART_NUMBER_ID 0xb 45 - #define LTR390_ALS_UVS_GAIN_MASK 0x07 46 - #define LTR390_ALS_UVS_INT_TIME_MASK 0x70 45 + #define LTR390_ALS_UVS_GAIN_MASK GENMASK(2, 0) 46 + #define LTR390_ALS_UVS_MEAS_RATE_MASK GENMASK(2, 0) 47 + #define LTR390_ALS_UVS_INT_TIME_MASK GENMASK(6, 4) 47 48 #define LTR390_ALS_UVS_INT_TIME(x) FIELD_PREP(LTR390_ALS_UVS_INT_TIME_MASK, (x)) 49 + #define LTR390_INT_PST_MASK GENMASK(7, 4) 50 + #define LTR390_INT_PST_VAL(x) FIELD_PREP(LTR390_INT_PST_MASK, (x)) 48 51 49 52 #define LTR390_SW_RESET BIT(4) 50 53 #define LTR390_UVS_MODE BIT(3) 51 54 #define LTR390_SENSOR_ENABLE BIT(1) 55 + #define LTR390_LS_INT_EN BIT(2) 56 + #define LTR390_LS_INT_SEL_UVS BIT(5) 52 57 53 58 #define LTR390_FRACTIONAL_PRECISION 100 54 59 ··· 83 70 LTR390_SET_UVS_MODE, 84 71 }; 85 72 73 + enum ltr390_meas_rate { 74 + LTR390_GET_FREQ, 75 + LTR390_GET_PERIOD, 76 + }; 77 + 86 78 struct ltr390_data { 87 79 struct regmap *regmap; 88 80 struct i2c_client *client; ··· 103 85 .reg_bits = 8, 104 86 .reg_stride = 1, 105 87 .val_bits = 8, 88 + }; 89 + 90 + /* Sampling frequency is in mili Hz and mili Seconds */ 91 + static const int ltr390_samp_freq_table[][2] = { 92 + [0] = { 40000, 25 }, 93 + [1] = { 20000, 50 }, 94 + [2] = { 10000, 100 }, 95 + [3] = { 5000, 200 }, 96 + [4] = { 2000, 500 }, 97 + [5] = { 1000, 1000 }, 98 + [6] = { 500, 2000 }, 99 + [7] = { 500, 2000 }, 106 100 }; 107 101 108 102 static int ltr390_register_read(struct ltr390_data *data, u8 register_address) ··· 163 133 const int orig_int_time = 400; 164 134 165 135 return DIV_ROUND_CLOSEST(23 * data->gain * data->int_time_us, 10 * orig_gain * orig_int_time); 136 + } 137 + 138 + static int ltr390_get_samp_freq_or_period(struct ltr390_data *data, 139 + enum ltr390_meas_rate option) 140 + { 141 + int ret, value; 142 + 143 + ret = regmap_read(data->regmap, LTR390_ALS_UVS_MEAS_RATE, &value); 144 + if (ret < 0) 145 + return ret; 146 + value = FIELD_GET(LTR390_ALS_UVS_MEAS_RATE_MASK, value); 147 + 148 + return ltr390_samp_freq_table[value][option]; 166 149 } 167 150 168 151 static int ltr390_read_raw(struct iio_dev *iio_device, ··· 234 191 *val = data->int_time_us; 235 192 return IIO_VAL_INT; 236 193 194 + case IIO_CHAN_INFO_SAMP_FREQ: 195 + *val = ltr390_get_samp_freq_or_period(data, LTR390_GET_FREQ); 196 + return IIO_VAL_INT; 197 + 237 198 default: 238 199 return -EINVAL; 239 200 } ··· 246 199 /* integration time in us */ 247 200 static const int ltr390_int_time_map_us[] = { 400000, 200000, 100000, 50000, 25000, 12500 }; 248 201 static const int ltr390_gain_map[] = { 1, 3, 6, 9, 18 }; 202 + static const int ltr390_freq_map[] = { 40000, 20000, 10000, 5000, 2000, 1000, 500, 500 }; 203 + 204 + static const struct iio_event_spec ltr390_event_spec[] = { 205 + { 206 + .type = IIO_EV_TYPE_THRESH, 207 + .dir = IIO_EV_DIR_RISING, 208 + .mask_separate = BIT(IIO_EV_INFO_VALUE), 209 + }, { 210 + .type = IIO_EV_TYPE_THRESH, 211 + .dir = IIO_EV_DIR_FALLING, 212 + .mask_separate = BIT(IIO_EV_INFO_VALUE), 213 + }, { 214 + .type = IIO_EV_TYPE_THRESH, 215 + .dir = IIO_EV_DIR_EITHER, 216 + .mask_separate = BIT(IIO_EV_INFO_ENABLE) | 217 + BIT(IIO_EV_INFO_PERIOD), 218 + } 219 + }; 249 220 250 221 static const struct iio_chan_spec ltr390_channels[] = { 251 222 /* UV sensor */ ··· 271 206 .type = IIO_UVINDEX, 272 207 .scan_index = 0, 273 208 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 274 - .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), 275 - .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | BIT(IIO_CHAN_INFO_SCALE) 209 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME) | BIT(IIO_CHAN_INFO_SAMP_FREQ), 210 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 211 + BIT(IIO_CHAN_INFO_SCALE) | 212 + BIT(IIO_CHAN_INFO_SAMP_FREQ), 213 + .event_spec = ltr390_event_spec, 214 + .num_event_specs = ARRAY_SIZE(ltr390_event_spec), 276 215 }, 277 216 /* ALS sensor */ 278 217 { 279 218 .type = IIO_LIGHT, 280 219 .scan_index = 1, 281 220 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 282 - .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), 283 - .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | BIT(IIO_CHAN_INFO_SCALE) 221 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME) | BIT(IIO_CHAN_INFO_SAMP_FREQ), 222 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 223 + BIT(IIO_CHAN_INFO_SCALE) | 224 + BIT(IIO_CHAN_INFO_SAMP_FREQ), 225 + .event_spec = ltr390_event_spec, 226 + .num_event_specs = ARRAY_SIZE(ltr390_event_spec), 284 227 }, 285 228 }; 286 229 ··· 337 264 return -EINVAL; 338 265 } 339 266 267 + static int ltr390_set_samp_freq(struct ltr390_data *data, int val) 268 + { 269 + int idx; 270 + 271 + for (idx = 0; idx < ARRAY_SIZE(ltr390_samp_freq_table); idx++) { 272 + if (ltr390_samp_freq_table[idx][0] != val) 273 + continue; 274 + 275 + guard(mutex)(&data->lock); 276 + return regmap_update_bits(data->regmap, 277 + LTR390_ALS_UVS_MEAS_RATE, 278 + LTR390_ALS_UVS_MEAS_RATE_MASK, idx); 279 + } 280 + 281 + return -EINVAL; 282 + } 283 + 340 284 static int ltr390_read_avail(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, 341 285 const int **vals, int *type, int *length, long mask) 342 286 { ··· 367 277 *length = ARRAY_SIZE(ltr390_int_time_map_us); 368 278 *type = IIO_VAL_INT; 369 279 *vals = ltr390_int_time_map_us; 280 + return IIO_AVAIL_LIST; 281 + case IIO_CHAN_INFO_SAMP_FREQ: 282 + *length = ARRAY_SIZE(ltr390_freq_map); 283 + *type = IIO_VAL_INT; 284 + *vals = ltr390_freq_map; 370 285 return IIO_AVAIL_LIST; 371 286 default: 372 287 return -EINVAL; ··· 396 301 397 302 return ltr390_set_int_time(data, val); 398 303 304 + case IIO_CHAN_INFO_SAMP_FREQ: 305 + if (val2 != 0) 306 + return -EINVAL; 307 + 308 + return ltr390_set_samp_freq(data, val); 309 + 310 + default: 311 + return -EINVAL; 312 + } 313 + } 314 + 315 + static int ltr390_read_intr_prst(struct ltr390_data *data, int *val) 316 + { 317 + int ret, prst, samp_period; 318 + 319 + samp_period = ltr390_get_samp_freq_or_period(data, LTR390_GET_PERIOD); 320 + ret = regmap_read(data->regmap, LTR390_INT_PST, &prst); 321 + if (ret < 0) 322 + return ret; 323 + *val = prst * samp_period; 324 + 325 + return IIO_VAL_INT; 326 + } 327 + 328 + static int ltr390_write_intr_prst(struct ltr390_data *data, int val) 329 + { 330 + int ret, samp_period, new_val; 331 + 332 + samp_period = ltr390_get_samp_freq_or_period(data, LTR390_GET_PERIOD); 333 + 334 + /* persist period should be greater than or equal to samp period */ 335 + if (val < samp_period) 336 + return -EINVAL; 337 + 338 + new_val = DIV_ROUND_UP(val, samp_period); 339 + if (new_val < 0 || new_val > 0x0f) 340 + return -EINVAL; 341 + 342 + guard(mutex)(&data->lock); 343 + ret = regmap_update_bits(data->regmap, 344 + LTR390_INT_PST, 345 + LTR390_INT_PST_MASK, 346 + LTR390_INT_PST_VAL(new_val)); 347 + if (ret) 348 + return ret; 349 + 350 + return 0; 351 + } 352 + 353 + static int ltr390_read_threshold(struct iio_dev *indio_dev, 354 + enum iio_event_direction dir, 355 + int *val, int *val2) 356 + { 357 + struct ltr390_data *data = iio_priv(indio_dev); 358 + int ret; 359 + 360 + switch (dir) { 361 + case IIO_EV_DIR_RISING: 362 + ret = ltr390_register_read(data, LTR390_THRESH_UP); 363 + if (ret < 0) 364 + return ret; 365 + *val = ret; 366 + return IIO_VAL_INT; 367 + 368 + case IIO_EV_DIR_FALLING: 369 + ret = ltr390_register_read(data, LTR390_THRESH_LOW); 370 + if (ret < 0) 371 + return ret; 372 + *val = ret; 373 + return IIO_VAL_INT; 374 + default: 375 + return -EINVAL; 376 + } 377 + } 378 + 379 + static int ltr390_write_threshold(struct iio_dev *indio_dev, 380 + enum iio_event_direction dir, 381 + int val, int val2) 382 + { 383 + struct ltr390_data *data = iio_priv(indio_dev); 384 + 385 + guard(mutex)(&data->lock); 386 + switch (dir) { 387 + case IIO_EV_DIR_RISING: 388 + return regmap_bulk_write(data->regmap, LTR390_THRESH_UP, &val, 3); 389 + 390 + case IIO_EV_DIR_FALLING: 391 + return regmap_bulk_write(data->regmap, LTR390_THRESH_LOW, &val, 3); 392 + 393 + default: 394 + return -EINVAL; 395 + } 396 + } 397 + 398 + static int ltr390_read_event_value(struct iio_dev *indio_dev, 399 + const struct iio_chan_spec *chan, 400 + enum iio_event_type type, 401 + enum iio_event_direction dir, 402 + enum iio_event_info info, 403 + int *val, int *val2) 404 + { 405 + switch (info) { 406 + case IIO_EV_INFO_VALUE: 407 + return ltr390_read_threshold(indio_dev, dir, val, val2); 408 + 409 + case IIO_EV_INFO_PERIOD: 410 + return ltr390_read_intr_prst(iio_priv(indio_dev), val); 411 + 412 + default: 413 + return -EINVAL; 414 + } 415 + } 416 + 417 + static int ltr390_write_event_value(struct iio_dev *indio_dev, 418 + const struct iio_chan_spec *chan, 419 + enum iio_event_type type, 420 + enum iio_event_direction dir, 421 + enum iio_event_info info, 422 + int val, int val2) 423 + { 424 + switch (info) { 425 + case IIO_EV_INFO_VALUE: 426 + if (val2 != 0) 427 + return -EINVAL; 428 + 429 + return ltr390_write_threshold(indio_dev, dir, val, val2); 430 + 431 + case IIO_EV_INFO_PERIOD: 432 + if (val2 != 0) 433 + return -EINVAL; 434 + 435 + return ltr390_write_intr_prst(iio_priv(indio_dev), val); 436 + 437 + default: 438 + return -EINVAL; 439 + } 440 + } 441 + 442 + static int ltr390_read_event_config(struct iio_dev *indio_dev, 443 + const struct iio_chan_spec *chan, 444 + enum iio_event_type type, 445 + enum iio_event_direction dir) 446 + { 447 + struct ltr390_data *data = iio_priv(indio_dev); 448 + int ret, status; 449 + 450 + ret = regmap_read(data->regmap, LTR390_INT_CFG, &status); 451 + if (ret < 0) 452 + return ret; 453 + 454 + return FIELD_GET(LTR390_LS_INT_EN, status); 455 + } 456 + 457 + static int ltr390_write_event_config(struct iio_dev *indio_dev, 458 + const struct iio_chan_spec *chan, 459 + enum iio_event_type type, 460 + enum iio_event_direction dir, 461 + int state) 462 + { 463 + struct ltr390_data *data = iio_priv(indio_dev); 464 + int ret; 465 + 466 + if (state != 1 && state != 0) 467 + return -EINVAL; 468 + 469 + if (state == 0) 470 + return regmap_clear_bits(data->regmap, LTR390_INT_CFG, LTR390_LS_INT_EN); 471 + 472 + guard(mutex)(&data->lock); 473 + ret = regmap_set_bits(data->regmap, LTR390_INT_CFG, LTR390_LS_INT_EN); 474 + if (ret < 0) 475 + return ret; 476 + 477 + switch (chan->type) { 478 + case IIO_LIGHT: 479 + ret = ltr390_set_mode(data, LTR390_SET_ALS_MODE); 480 + if (ret < 0) 481 + return ret; 482 + 483 + return regmap_clear_bits(data->regmap, LTR390_INT_CFG, LTR390_LS_INT_SEL_UVS); 484 + 485 + case IIO_UVINDEX: 486 + ret = ltr390_set_mode(data, LTR390_SET_UVS_MODE); 487 + if (ret < 0) 488 + return ret; 489 + 490 + return regmap_set_bits(data->regmap, LTR390_INT_CFG, LTR390_LS_INT_SEL_UVS); 491 + 399 492 default: 400 493 return -EINVAL; 401 494 } ··· 593 310 .read_raw = ltr390_read_raw, 594 311 .write_raw = ltr390_write_raw, 595 312 .read_avail = ltr390_read_avail, 313 + .read_event_value = ltr390_read_event_value, 314 + .read_event_config = ltr390_read_event_config, 315 + .write_event_value = ltr390_write_event_value, 316 + .write_event_config = ltr390_write_event_config, 596 317 }; 318 + 319 + static irqreturn_t ltr390_interrupt_handler(int irq, void *private) 320 + { 321 + struct iio_dev *indio_dev = private; 322 + struct ltr390_data *data = iio_priv(indio_dev); 323 + int ret, status; 324 + 325 + /* Reading the status register to clear the interrupt flag, Datasheet pg: 17*/ 326 + ret = regmap_read(data->regmap, LTR390_MAIN_STATUS, &status); 327 + if (ret < 0) 328 + return ret; 329 + 330 + switch (data->mode) { 331 + case LTR390_SET_ALS_MODE: 332 + iio_push_event(indio_dev, 333 + IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0, 334 + IIO_EV_TYPE_THRESH, 335 + IIO_EV_DIR_EITHER), 336 + iio_get_time_ns(indio_dev)); 337 + break; 338 + 339 + case LTR390_SET_UVS_MODE: 340 + iio_push_event(indio_dev, 341 + IIO_UNMOD_EVENT_CODE(IIO_UVINDEX, 0, 342 + IIO_EV_TYPE_THRESH, 343 + IIO_EV_DIR_EITHER), 344 + iio_get_time_ns(indio_dev)); 345 + break; 346 + } 347 + 348 + return IRQ_HANDLED; 349 + } 597 350 598 351 static int ltr390_probe(struct i2c_client *client) 599 352 { ··· 684 365 if (ret) 685 366 return dev_err_probe(dev, ret, "failed to enable the sensor\n"); 686 367 368 + if (client->irq) { 369 + ret = devm_request_threaded_irq(dev, client->irq, 370 + NULL, ltr390_interrupt_handler, 371 + IRQF_ONESHOT, 372 + "ltr390_thresh_event", 373 + indio_dev); 374 + if (ret) 375 + return dev_err_probe(dev, ret, 376 + "request irq (%d) failed\n", client->irq); 377 + } 378 + 687 379 return devm_iio_device_register(dev, indio_dev); 688 380 } 381 + 382 + static int ltr390_suspend(struct device *dev) 383 + { 384 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 385 + struct ltr390_data *data = iio_priv(indio_dev); 386 + 387 + return regmap_clear_bits(data->regmap, LTR390_MAIN_CTRL, 388 + LTR390_SENSOR_ENABLE); 389 + } 390 + 391 + static int ltr390_resume(struct device *dev) 392 + { 393 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 394 + struct ltr390_data *data = iio_priv(indio_dev); 395 + 396 + return regmap_set_bits(data->regmap, LTR390_MAIN_CTRL, 397 + LTR390_SENSOR_ENABLE); 398 + } 399 + 400 + static DEFINE_SIMPLE_DEV_PM_OPS(ltr390_pm_ops, ltr390_suspend, ltr390_resume); 689 401 690 402 static const struct i2c_device_id ltr390_id[] = { 691 403 { "ltr390" }, ··· 734 384 .driver = { 735 385 .name = "ltr390", 736 386 .of_match_table = ltr390_of_table, 387 + .pm = pm_sleep_ptr(&ltr390_pm_ops), 737 388 }, 738 389 .probe = ltr390_probe, 739 390 .id_table = ltr390_id,
+1
drivers/iio/light/ltrf216a.c
··· 561 561 static const struct of_device_id ltrf216a_of_match[] = { 562 562 { .compatible = "liteon,ltr308", .data = &ltr308_chip_info }, 563 563 { .compatible = "liteon,ltrf216a", .data = &ltrf216a_chip_info }, 564 + /* For Valve's Steamdeck device, an ACPI platform using PRP0001 */ 564 565 { .compatible = "ltr,ltrf216a", .data = &ltrf216a_chip_info }, 565 566 {} 566 567 };
+1 -13
drivers/iio/light/rpr0521.c
··· 438 438 return IRQ_NONE; 439 439 } 440 440 441 - static irqreturn_t rpr0521_trigger_consumer_store_time(int irq, void *p) 442 - { 443 - struct iio_poll_func *pf = p; 444 - struct iio_dev *indio_dev = pf->indio_dev; 445 - 446 - /* Other trigger polls store time here. */ 447 - if (!iio_trigger_using_own(indio_dev)) 448 - pf->timestamp = iio_get_time_ns(indio_dev); 449 - 450 - return IRQ_WAKE_THREAD; 451 - } 452 - 453 441 static irqreturn_t rpr0521_trigger_consumer_handler(int irq, void *p) 454 442 { 455 443 struct iio_poll_func *pf = p; ··· 1004 1016 /* Trigger consumer setup */ 1005 1017 ret = devm_iio_triggered_buffer_setup(indio_dev->dev.parent, 1006 1018 indio_dev, 1007 - rpr0521_trigger_consumer_store_time, 1019 + iio_pollfunc_store_time, 1008 1020 rpr0521_trigger_consumer_handler, 1009 1021 &rpr0521_buffer_setup_ops); 1010 1022 if (ret < 0) {
+1 -2
drivers/iio/light/st_uvis25_core.c
··· 174 174 unsigned long irq_type; 175 175 int err; 176 176 177 - irq_type = irqd_get_trigger_type(irq_get_irq_data(hw->irq)); 178 - 177 + irq_type = irq_get_trigger_type(hw->irq); 179 178 switch (irq_type) { 180 179 case IRQF_TRIGGER_HIGH: 181 180 case IRQF_TRIGGER_RISING:
+410 -122
drivers/iio/light/veml6030.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0+ 2 2 /* 3 - * VEML6030 Ambient Light Sensor 3 + * VEML6030, VMEL6035 and VEML7700 Ambient Light Sensors 4 4 * 5 5 * Copyright (c) 2019, Rishi Gupta <gupt21@gmail.com> 6 6 * 7 + * VEML6030: 7 8 * Datasheet: https://www.vishay.com/docs/84366/veml6030.pdf 8 9 * Appnote-84367: https://www.vishay.com/docs/84367/designingveml6030.pdf 10 + * 11 + * VEML6035: 12 + * Datasheet: https://www.vishay.com/docs/84889/veml6035.pdf 13 + * Appnote-84944: https://www.vishay.com/docs/84944/designingveml6035.pdf 14 + * 15 + * VEML7700: 16 + * Datasheet: https://www.vishay.com/docs/84286/veml7700.pdf 17 + * Appnote-84323: https://www.vishay.com/docs/84323/designingveml7700.pdf 9 18 */ 10 19 20 + #include <linux/bitfield.h> 11 21 #include <linux/module.h> 12 22 #include <linux/i2c.h> 13 23 #include <linux/err.h> 14 24 #include <linux/regmap.h> 15 25 #include <linux/interrupt.h> 16 26 #include <linux/pm_runtime.h> 27 + #include <linux/regulator/consumer.h> 17 28 #include <linux/iio/iio.h> 18 29 #include <linux/iio/sysfs.h> 19 30 #include <linux/iio/events.h> ··· 49 38 #define VEML6030_ALS_INT_EN BIT(1) 50 39 #define VEML6030_ALS_SD BIT(0) 51 40 41 + #define VEML6035_GAIN_M GENMASK(12, 10) 42 + #define VEML6035_GAIN BIT(10) 43 + #define VEML6035_DG BIT(11) 44 + #define VEML6035_SENS BIT(12) 45 + #define VEML6035_INT_CHAN BIT(3) 46 + #define VEML6035_CHAN_EN BIT(2) 47 + 48 + struct veml603x_chip { 49 + const char *name; 50 + const int(*scale_vals)[][2]; 51 + const int num_scale_vals; 52 + const struct iio_chan_spec *channels; 53 + const int num_channels; 54 + int (*hw_init)(struct iio_dev *indio_dev, struct device *dev); 55 + int (*set_info)(struct iio_dev *indio_dev); 56 + int (*set_als_gain)(struct iio_dev *indio_dev, int val, int val2); 57 + int (*get_als_gain)(struct iio_dev *indio_dev, int *val, int *val2); 58 + }; 59 + 52 60 /* 53 61 * The resolution depends on both gain and integration time. The 54 62 * cur_resolution stores one of the resolution mentioned in the 55 63 * table during startup and gets updated whenever integration time 56 64 * or gain is changed. 57 65 * 58 - * Table 'resolution and maximum detection range' in appnote 84367 66 + * Table 'resolution and maximum detection range' in the appnotes 59 67 * is visualized as a 2D array. The cur_gain stores index of gain 60 - * in this table (0-3) while the cur_integration_time holds index 61 - * of integration time (0-5). 68 + * in this table (0-3 for VEML6030, 0-5 for VEML6035) while the 69 + * cur_integration_time holds index of integration time (0-5). 62 70 */ 63 71 struct veml6030_data { 64 72 struct i2c_client *client; ··· 85 55 int cur_resolution; 86 56 int cur_gain; 87 57 int cur_integration_time; 58 + const struct veml603x_chip *chip; 88 59 }; 89 60 90 - /* Integration time available in seconds */ 91 - static IIO_CONST_ATTR(in_illuminance_integration_time_available, 92 - "0.025 0.05 0.1 0.2 0.4 0.8"); 61 + static const int veml6030_it_times[][2] = { 62 + { 0, 25000 }, 63 + { 0, 50000 }, 64 + { 0, 100000 }, 65 + { 0, 200000 }, 66 + { 0, 400000 }, 67 + { 0, 800000 }, 68 + }; 93 69 94 70 /* 95 71 * Scale is 1/gain. Value 0.125 is ALS gain x (1/8), 0.25 is 96 - * ALS gain x (1/4), 1.0 = ALS gain x 1 and 2.0 is ALS gain x 2. 72 + * ALS gain x (1/4), 0.5 is ALS gain x (1/2), 1.0 is ALS gain x 1, 73 + * 2.0 is ALS gain x2, and 4.0 is ALS gain x 4. 97 74 */ 98 - static IIO_CONST_ATTR(in_illuminance_scale_available, 99 - "0.125 0.25 1.0 2.0"); 100 - 101 - static struct attribute *veml6030_attributes[] = { 102 - &iio_const_attr_in_illuminance_integration_time_available.dev_attr.attr, 103 - &iio_const_attr_in_illuminance_scale_available.dev_attr.attr, 104 - NULL 75 + static const int veml6030_scale_vals[][2] = { 76 + { 0, 125000 }, 77 + { 0, 250000 }, 78 + { 1, 0 }, 79 + { 2, 0 }, 105 80 }; 106 81 107 - static const struct attribute_group veml6030_attr_group = { 108 - .attrs = veml6030_attributes, 82 + static const int veml6035_scale_vals[][2] = { 83 + { 0, 125000 }, 84 + { 0, 250000 }, 85 + { 0, 500000 }, 86 + { 1, 0 }, 87 + { 2, 0 }, 88 + { 4, 0 }, 109 89 }; 110 90 111 91 /* ··· 184 144 185 145 static int veml6030_als_pwr_on(struct veml6030_data *data) 186 146 { 187 - return regmap_clear_bits(data->regmap, VEML6030_REG_ALS_CONF, 188 - VEML6030_ALS_SD); 147 + int ret; 148 + 149 + ret = regmap_clear_bits(data->regmap, VEML6030_REG_ALS_CONF, 150 + VEML6030_ALS_SD); 151 + if (ret) 152 + return ret; 153 + 154 + /* Wait 4 ms to let processor & oscillator start correctly */ 155 + fsleep(4000); 156 + 157 + return 0; 189 158 } 190 159 191 160 static int veml6030_als_shut_down(struct veml6030_data *data) 192 161 { 193 - return regmap_update_bits(data->regmap, VEML6030_REG_ALS_CONF, 194 - VEML6030_ALS_SD, 1); 162 + return regmap_set_bits(data->regmap, VEML6030_REG_ALS_CONF, 163 + VEML6030_ALS_SD); 195 164 } 196 165 197 166 static void veml6030_als_shut_down_action(void *data) ··· 239 190 BIT(IIO_CHAN_INFO_PROCESSED) | 240 191 BIT(IIO_CHAN_INFO_INT_TIME) | 241 192 BIT(IIO_CHAN_INFO_SCALE), 193 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 194 + BIT(IIO_CHAN_INFO_SCALE), 242 195 .event_spec = veml6030_event_spec, 243 196 .num_event_specs = ARRAY_SIZE(veml6030_event_spec), 244 197 }, ··· 250 199 .modified = 1, 251 200 .channel2 = IIO_MOD_LIGHT_BOTH, 252 201 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 253 - BIT(IIO_CHAN_INFO_PROCESSED), 202 + BIT(IIO_CHAN_INFO_INT_TIME) | 203 + BIT(IIO_CHAN_INFO_SCALE), 204 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 205 + BIT(IIO_CHAN_INFO_SCALE), 206 + }, 207 + }; 208 + 209 + static const struct iio_chan_spec veml7700_channels[] = { 210 + { 211 + .type = IIO_LIGHT, 212 + .channel = CH_ALS, 213 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 214 + BIT(IIO_CHAN_INFO_PROCESSED) | 215 + BIT(IIO_CHAN_INFO_INT_TIME) | 216 + BIT(IIO_CHAN_INFO_SCALE), 217 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 218 + BIT(IIO_CHAN_INFO_SCALE), 219 + }, 220 + { 221 + .type = IIO_INTENSITY, 222 + .channel = CH_WHITE, 223 + .modified = 1, 224 + .channel2 = IIO_MOD_LIGHT_BOTH, 225 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 226 + BIT(IIO_CHAN_INFO_INT_TIME) | 227 + BIT(IIO_CHAN_INFO_SCALE), 228 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) | 229 + BIT(IIO_CHAN_INFO_SCALE), 254 230 }, 255 231 }; 256 232 ··· 450 372 return ret; 451 373 } 452 374 375 + /* 376 + * Cache currently set gain & update resolution. For every 377 + * increase in the gain to next level, resolution is halved 378 + * and vice-versa. 379 + */ 380 + static void veml6030_update_gain_res(struct veml6030_data *data, int gain_idx) 381 + { 382 + if (data->cur_gain < gain_idx) 383 + data->cur_resolution <<= gain_idx - data->cur_gain; 384 + else if (data->cur_gain > gain_idx) 385 + data->cur_resolution >>= data->cur_gain - gain_idx; 386 + 387 + data->cur_gain = gain_idx; 388 + } 389 + 453 390 static int veml6030_set_als_gain(struct iio_dev *indio_dev, 454 391 int val, int val2) 455 392 { ··· 495 402 return ret; 496 403 } 497 404 498 - /* 499 - * Cache currently set gain & update resolution. For every 500 - * increase in the gain to next level, resolution is halved 501 - * and vice-versa. 502 - */ 503 - if (data->cur_gain < gain_idx) 504 - data->cur_resolution <<= gain_idx - data->cur_gain; 505 - else if (data->cur_gain > gain_idx) 506 - data->cur_resolution >>= data->cur_gain - gain_idx; 405 + veml6030_update_gain_res(data, gain_idx); 507 406 508 - data->cur_gain = gain_idx; 407 + return 0; 408 + } 509 409 510 - return ret; 410 + static int veml6035_set_als_gain(struct iio_dev *indio_dev, int val, int val2) 411 + { 412 + int ret, new_gain, gain_idx; 413 + struct veml6030_data *data = iio_priv(indio_dev); 414 + 415 + if (val == 0 && val2 == 125000) { 416 + new_gain = VEML6035_SENS; 417 + gain_idx = 5; 418 + } else if (val == 0 && val2 == 250000) { 419 + new_gain = VEML6035_SENS | VEML6035_GAIN; 420 + gain_idx = 4; 421 + } else if (val == 0 && val2 == 500000) { 422 + new_gain = VEML6035_SENS | VEML6035_GAIN | 423 + VEML6035_DG; 424 + gain_idx = 3; 425 + } else if (val == 1 && val2 == 0) { 426 + new_gain = 0x0000; 427 + gain_idx = 2; 428 + } else if (val == 2 && val2 == 0) { 429 + new_gain = VEML6035_GAIN; 430 + gain_idx = 1; 431 + } else if (val == 4 && val2 == 0) { 432 + new_gain = VEML6035_GAIN | VEML6035_DG; 433 + gain_idx = 0; 434 + } else { 435 + return -EINVAL; 436 + } 437 + 438 + ret = regmap_update_bits(data->regmap, VEML6030_REG_ALS_CONF, 439 + VEML6035_GAIN_M, new_gain); 440 + if (ret) { 441 + dev_err(&data->client->dev, "can't set als gain %d\n", ret); 442 + return ret; 443 + } 444 + 445 + veml6030_update_gain_res(data, gain_idx); 446 + 447 + return 0; 511 448 } 512 449 513 450 static int veml6030_get_als_gain(struct iio_dev *indio_dev, ··· 569 446 case 3: 570 447 *val = 0; 571 448 *val2 = 250000; 449 + break; 450 + default: 451 + return -EINVAL; 452 + } 453 + 454 + return IIO_VAL_INT_PLUS_MICRO; 455 + } 456 + 457 + static int veml6035_get_als_gain(struct iio_dev *indio_dev, int *val, int *val2) 458 + { 459 + int ret, reg; 460 + struct veml6030_data *data = iio_priv(indio_dev); 461 + 462 + ret = regmap_read(data->regmap, VEML6030_REG_ALS_CONF, &reg); 463 + if (ret) { 464 + dev_err(&data->client->dev, 465 + "can't read als conf register %d\n", ret); 466 + return ret; 467 + } 468 + 469 + switch (FIELD_GET(VEML6035_GAIN_M, reg)) { 470 + case 0: 471 + *val = 1; 472 + *val2 = 0; 473 + break; 474 + case 1: 475 + case 2: 476 + *val = 2; 477 + *val2 = 0; 478 + break; 479 + case 3: 480 + *val = 4; 481 + *val2 = 0; 482 + break; 483 + case 4: 484 + *val = 0; 485 + *val2 = 125000; 486 + break; 487 + case 5: 488 + case 6: 489 + *val = 0; 490 + *val2 = 250000; 491 + break; 492 + case 7: 493 + *val = 0; 494 + *val2 = 500000; 572 495 break; 573 496 default: 574 497 return -EINVAL; ··· 703 534 dev_err(dev, "can't read white data %d\n", ret); 704 535 return ret; 705 536 } 706 - if (mask == IIO_CHAN_INFO_PROCESSED) { 707 - *val = (reg * data->cur_resolution) / 10000; 708 - *val2 = (reg * data->cur_resolution) % 10000; 709 - return IIO_VAL_INT_PLUS_MICRO; 710 - } 711 537 *val = reg; 712 538 return IIO_VAL_INT; 713 539 default: 714 540 return -EINVAL; 715 541 } 716 542 case IIO_CHAN_INFO_INT_TIME: 717 - if (chan->type == IIO_LIGHT) 718 - return veml6030_get_intgrn_tm(indio_dev, val, val2); 719 - return -EINVAL; 543 + return veml6030_get_intgrn_tm(indio_dev, val, val2); 720 544 case IIO_CHAN_INFO_SCALE: 721 - if (chan->type == IIO_LIGHT) 722 - return veml6030_get_als_gain(indio_dev, val, val2); 723 - return -EINVAL; 545 + return data->chip->get_als_gain(indio_dev, val, val2); 724 546 default: 725 547 return -EINVAL; 726 548 } 549 + } 550 + 551 + static int veml6030_read_avail(struct iio_dev *indio_dev, 552 + struct iio_chan_spec const *chan, 553 + const int **vals, int *type, int *length, 554 + long mask) 555 + { 556 + struct veml6030_data *data = iio_priv(indio_dev); 557 + 558 + switch (mask) { 559 + case IIO_CHAN_INFO_INT_TIME: 560 + *vals = (int *)&veml6030_it_times; 561 + *length = 2 * ARRAY_SIZE(veml6030_it_times); 562 + *type = IIO_VAL_INT_PLUS_MICRO; 563 + return IIO_AVAIL_LIST; 564 + case IIO_CHAN_INFO_SCALE: 565 + *vals = (int *)*data->chip->scale_vals; 566 + *length = 2 * data->chip->num_scale_vals; 567 + *type = IIO_VAL_INT_PLUS_MICRO; 568 + return IIO_AVAIL_LIST; 569 + } 570 + 571 + return -EINVAL; 727 572 } 728 573 729 574 static int veml6030_write_raw(struct iio_dev *indio_dev, 730 575 struct iio_chan_spec const *chan, 731 576 int val, int val2, long mask) 732 577 { 578 + struct veml6030_data *data = iio_priv(indio_dev); 579 + 733 580 switch (mask) { 734 581 case IIO_CHAN_INFO_INT_TIME: 735 - switch (chan->type) { 736 - case IIO_LIGHT: 737 - return veml6030_set_intgrn_tm(indio_dev, val, val2); 738 - default: 739 - return -EINVAL; 740 - } 582 + return veml6030_set_intgrn_tm(indio_dev, val, val2); 741 583 case IIO_CHAN_INFO_SCALE: 742 - switch (chan->type) { 743 - case IIO_LIGHT: 744 - return veml6030_set_als_gain(indio_dev, val, val2); 745 - default: 746 - return -EINVAL; 747 - } 584 + return data->chip->set_als_gain(indio_dev, val, val2); 748 585 default: 749 586 return -EINVAL; 750 587 } ··· 849 674 850 675 static const struct iio_info veml6030_info = { 851 676 .read_raw = veml6030_read_raw, 677 + .read_avail = veml6030_read_avail, 852 678 .write_raw = veml6030_write_raw, 853 679 .read_event_value = veml6030_read_event_val, 854 680 .write_event_value = veml6030_write_event_val, 855 681 .read_event_config = veml6030_read_interrupt_config, 856 682 .write_event_config = veml6030_write_interrupt_config, 857 - .attrs = &veml6030_attr_group, 858 683 .event_attrs = &veml6030_event_attr_group, 859 684 }; 860 685 861 686 static const struct iio_info veml6030_info_no_irq = { 862 687 .read_raw = veml6030_read_raw, 688 + .read_avail = veml6030_read_avail, 863 689 .write_raw = veml6030_write_raw, 864 - .attrs = &veml6030_attr_group, 865 690 }; 866 691 867 692 static irqreturn_t veml6030_event_handler(int irq, void *private) ··· 893 718 return IRQ_HANDLED; 894 719 } 895 720 721 + static int veml6030_set_info(struct iio_dev *indio_dev) 722 + { 723 + struct veml6030_data *data = iio_priv(indio_dev); 724 + struct i2c_client *client = data->client; 725 + int ret; 726 + 727 + if (client->irq) { 728 + ret = devm_request_threaded_irq(&client->dev, client->irq, 729 + NULL, veml6030_event_handler, 730 + IRQF_TRIGGER_LOW | IRQF_ONESHOT, 731 + indio_dev->name, indio_dev); 732 + if (ret < 0) 733 + return dev_err_probe(&client->dev, ret, 734 + "irq %d request failed\n", 735 + client->irq); 736 + 737 + indio_dev->info = &veml6030_info; 738 + } else { 739 + indio_dev->info = &veml6030_info_no_irq; 740 + } 741 + 742 + return 0; 743 + } 744 + 745 + static int veml7700_set_info(struct iio_dev *indio_dev) 746 + { 747 + indio_dev->info = &veml6030_info_no_irq; 748 + 749 + return 0; 750 + } 751 + 896 752 /* 897 753 * Set ALS gain to 1/8, integration time to 100 ms, PSM to mode 2, 898 754 * persistence to 1 x integration time and the threshold 899 755 * interrupt disabled by default. First shutdown the sensor, 900 756 * update registers and then power on the sensor. 901 757 */ 902 - static int veml6030_hw_init(struct iio_dev *indio_dev) 758 + static int veml6030_hw_init(struct iio_dev *indio_dev, struct device *dev) 903 759 { 904 760 int ret, val; 905 761 struct veml6030_data *data = iio_priv(indio_dev); 906 - struct i2c_client *client = data->client; 907 762 908 763 ret = veml6030_als_shut_down(data); 909 - if (ret) { 910 - dev_err(&client->dev, "can't shutdown als %d\n", ret); 911 - return ret; 912 - } 764 + if (ret) 765 + return dev_err_probe(dev, ret, "can't shutdown als\n"); 913 766 914 767 ret = regmap_write(data->regmap, VEML6030_REG_ALS_CONF, 0x1001); 915 - if (ret) { 916 - dev_err(&client->dev, "can't setup als configs %d\n", ret); 917 - return ret; 918 - } 768 + if (ret) 769 + return dev_err_probe(dev, ret, "can't setup als configs\n"); 919 770 920 771 ret = regmap_update_bits(data->regmap, VEML6030_REG_ALS_PSM, 921 772 VEML6030_PSM | VEML6030_PSM_EN, 0x03); 922 - if (ret) { 923 - dev_err(&client->dev, "can't setup default PSM %d\n", ret); 924 - return ret; 925 - } 773 + if (ret) 774 + return dev_err_probe(dev, ret, "can't setup default PSM\n"); 926 775 927 776 ret = regmap_write(data->regmap, VEML6030_REG_ALS_WH, 0xFFFF); 928 - if (ret) { 929 - dev_err(&client->dev, "can't setup high threshold %d\n", ret); 930 - return ret; 931 - } 777 + if (ret) 778 + return dev_err_probe(dev, ret, "can't setup high threshold\n"); 932 779 933 780 ret = regmap_write(data->regmap, VEML6030_REG_ALS_WL, 0x0000); 934 - if (ret) { 935 - dev_err(&client->dev, "can't setup low threshold %d\n", ret); 936 - return ret; 937 - } 781 + if (ret) 782 + return dev_err_probe(dev, ret, "can't setup low threshold\n"); 938 783 939 784 ret = veml6030_als_pwr_on(data); 940 - if (ret) { 941 - dev_err(&client->dev, "can't poweron als %d\n", ret); 942 - return ret; 943 - } 785 + if (ret) 786 + return dev_err_probe(dev, ret, "can't poweron als\n"); 944 787 945 - /* Wait 4 ms to let processor & oscillator start correctly */ 946 - usleep_range(4000, 4002); 788 + ret = devm_add_action_or_reset(dev, veml6030_als_shut_down_action, data); 789 + if (ret < 0) 790 + return ret; 947 791 948 792 /* Clear stale interrupt status bits if any during start */ 949 793 ret = regmap_read(data->regmap, VEML6030_REG_ALS_INT, &val); 950 - if (ret < 0) { 951 - dev_err(&client->dev, 952 - "can't clear als interrupt status %d\n", ret); 953 - return ret; 954 - } 794 + if (ret < 0) 795 + return dev_err_probe(dev, ret, 796 + "can't clear als interrupt status\n"); 955 797 956 798 /* Cache currently active measurement parameters */ 957 799 data->cur_gain = 3; ··· 978 786 return ret; 979 787 } 980 788 789 + /* 790 + * Set ALS gain to 1/8, integration time to 100 ms, ALS and WHITE 791 + * channel enabled, ALS channel interrupt, PSM enabled, 792 + * PSM_WAIT = 0.8 s, persistence to 1 x integration time and the 793 + * threshold interrupt disabled by default. First shutdown the sensor, 794 + * update registers and then power on the sensor. 795 + */ 796 + static int veml6035_hw_init(struct iio_dev *indio_dev, struct device *dev) 797 + { 798 + int ret, val; 799 + struct veml6030_data *data = iio_priv(indio_dev); 800 + 801 + ret = veml6030_als_shut_down(data); 802 + if (ret) 803 + return dev_err_probe(dev, ret, "can't shutdown als\n"); 804 + 805 + ret = regmap_write(data->regmap, VEML6030_REG_ALS_CONF, 806 + VEML6035_SENS | VEML6035_CHAN_EN | VEML6030_ALS_SD); 807 + if (ret) 808 + return dev_err_probe(dev, ret, "can't setup als configs\n"); 809 + 810 + ret = regmap_update_bits(data->regmap, VEML6030_REG_ALS_PSM, 811 + VEML6030_PSM | VEML6030_PSM_EN, 0x03); 812 + if (ret) 813 + return dev_err_probe(dev, ret, "can't setup default PSM\n"); 814 + 815 + ret = regmap_write(data->regmap, VEML6030_REG_ALS_WH, 0xFFFF); 816 + if (ret) 817 + return dev_err_probe(dev, ret, "can't setup high threshold\n"); 818 + 819 + ret = regmap_write(data->regmap, VEML6030_REG_ALS_WL, 0x0000); 820 + if (ret) 821 + return dev_err_probe(dev, ret, "can't setup low threshold\n"); 822 + 823 + ret = veml6030_als_pwr_on(data); 824 + if (ret) 825 + return dev_err_probe(dev, ret, "can't poweron als\n"); 826 + 827 + ret = devm_add_action_or_reset(dev, veml6030_als_shut_down_action, data); 828 + if (ret < 0) 829 + return ret; 830 + 831 + /* Clear stale interrupt status bits if any during start */ 832 + ret = regmap_read(data->regmap, VEML6030_REG_ALS_INT, &val); 833 + if (ret < 0) 834 + return dev_err_probe(dev, ret, 835 + "can't clear als interrupt status\n"); 836 + 837 + /* Cache currently active measurement parameters */ 838 + data->cur_gain = 5; 839 + data->cur_resolution = 1024; 840 + data->cur_integration_time = 3; 841 + 842 + return 0; 843 + } 844 + 981 845 static int veml6030_probe(struct i2c_client *client) 982 846 { 983 847 int ret; ··· 1041 793 struct iio_dev *indio_dev; 1042 794 struct regmap *regmap; 1043 795 1044 - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 1045 - dev_err(&client->dev, "i2c adapter doesn't support plain i2c\n"); 1046 - return -EOPNOTSUPP; 1047 - } 796 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 797 + return dev_err_probe(&client->dev, -EOPNOTSUPP, 798 + "i2c adapter doesn't support plain i2c\n"); 1048 799 1049 800 regmap = devm_regmap_init_i2c(client, &veml6030_regmap_config); 1050 - if (IS_ERR(regmap)) { 1051 - dev_err(&client->dev, "can't setup regmap\n"); 1052 - return PTR_ERR(regmap); 1053 - } 801 + if (IS_ERR(regmap)) 802 + return dev_err_probe(&client->dev, PTR_ERR(regmap), 803 + "can't setup regmap\n"); 1054 804 1055 805 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 1056 806 if (!indio_dev) ··· 1059 813 data->client = client; 1060 814 data->regmap = regmap; 1061 815 1062 - indio_dev->name = "veml6030"; 1063 - indio_dev->channels = veml6030_channels; 1064 - indio_dev->num_channels = ARRAY_SIZE(veml6030_channels); 816 + ret = devm_regulator_get_enable(&client->dev, "vdd"); 817 + if (ret) 818 + return dev_err_probe(&client->dev, ret, 819 + "failed to enable regulator\n"); 820 + 821 + data->chip = i2c_get_match_data(client); 822 + if (!data->chip) 823 + return -EINVAL; 824 + 825 + indio_dev->name = data->chip->name; 826 + indio_dev->channels = data->chip->channels; 827 + indio_dev->num_channels = data->chip->num_channels; 1065 828 indio_dev->modes = INDIO_DIRECT_MODE; 1066 829 1067 - if (client->irq) { 1068 - ret = devm_request_threaded_irq(&client->dev, client->irq, 1069 - NULL, veml6030_event_handler, 1070 - IRQF_TRIGGER_LOW | IRQF_ONESHOT, 1071 - "veml6030", indio_dev); 1072 - if (ret < 0) { 1073 - dev_err(&client->dev, 1074 - "irq %d request failed\n", client->irq); 1075 - return ret; 1076 - } 1077 - indio_dev->info = &veml6030_info; 1078 - } else { 1079 - indio_dev->info = &veml6030_info_no_irq; 1080 - } 1081 - 1082 - ret = veml6030_hw_init(indio_dev); 830 + ret = data->chip->set_info(indio_dev); 1083 831 if (ret < 0) 1084 832 return ret; 1085 833 1086 - ret = devm_add_action_or_reset(&client->dev, 1087 - veml6030_als_shut_down_action, data); 834 + ret = data->chip->hw_init(indio_dev, &client->dev); 1088 835 if (ret < 0) 1089 836 return ret; 1090 837 ··· 1113 874 static DEFINE_RUNTIME_DEV_PM_OPS(veml6030_pm_ops, veml6030_runtime_suspend, 1114 875 veml6030_runtime_resume, NULL); 1115 876 877 + static const struct veml603x_chip veml6030_chip = { 878 + .name = "veml6030", 879 + .scale_vals = &veml6030_scale_vals, 880 + .num_scale_vals = ARRAY_SIZE(veml6030_scale_vals), 881 + .channels = veml6030_channels, 882 + .num_channels = ARRAY_SIZE(veml6030_channels), 883 + .hw_init = veml6030_hw_init, 884 + .set_info = veml6030_set_info, 885 + .set_als_gain = veml6030_set_als_gain, 886 + .get_als_gain = veml6030_get_als_gain, 887 + }; 888 + 889 + static const struct veml603x_chip veml6035_chip = { 890 + .name = "veml6035", 891 + .scale_vals = &veml6035_scale_vals, 892 + .num_scale_vals = ARRAY_SIZE(veml6035_scale_vals), 893 + .channels = veml6030_channels, 894 + .num_channels = ARRAY_SIZE(veml6030_channels), 895 + .hw_init = veml6035_hw_init, 896 + .set_info = veml6030_set_info, 897 + .set_als_gain = veml6035_set_als_gain, 898 + .get_als_gain = veml6035_get_als_gain, 899 + }; 900 + 901 + static const struct veml603x_chip veml7700_chip = { 902 + .name = "veml7700", 903 + .scale_vals = &veml6030_scale_vals, 904 + .num_scale_vals = ARRAY_SIZE(veml6030_scale_vals), 905 + .channels = veml7700_channels, 906 + .num_channels = ARRAY_SIZE(veml7700_channels), 907 + .hw_init = veml6030_hw_init, 908 + .set_info = veml7700_set_info, 909 + .set_als_gain = veml6030_set_als_gain, 910 + .get_als_gain = veml6030_get_als_gain, 911 + }; 912 + 1116 913 static const struct of_device_id veml6030_of_match[] = { 1117 - { .compatible = "vishay,veml6030" }, 914 + { 915 + .compatible = "vishay,veml6030", 916 + .data = &veml6030_chip, 917 + }, 918 + { 919 + .compatible = "vishay,veml6035", 920 + .data = &veml6035_chip, 921 + }, 922 + { 923 + .compatible = "vishay,veml7700", 924 + .data = &veml7700_chip, 925 + }, 1118 926 { } 1119 927 }; 1120 928 MODULE_DEVICE_TABLE(of, veml6030_of_match); 1121 929 1122 930 static const struct i2c_device_id veml6030_id[] = { 1123 - { "veml6030" }, 931 + { "veml6030", (kernel_ulong_t)&veml6030_chip}, 932 + { "veml6035", (kernel_ulong_t)&veml6035_chip}, 933 + { "veml7700", (kernel_ulong_t)&veml7700_chip}, 1124 934 { } 1125 935 }; 1126 936 MODULE_DEVICE_TABLE(i2c, veml6030_id);
+33 -30
drivers/iio/light/veml6070.c
··· 42 42 int ret; 43 43 u8 msb, lsb; 44 44 45 - mutex_lock(&data->lock); 45 + guard(mutex)(&data->lock); 46 46 47 47 /* disable shutdown */ 48 48 ret = i2c_smbus_write_byte(data->client1, 49 49 data->config & ~VEML6070_COMMAND_SD); 50 50 if (ret < 0) 51 - goto out; 51 + return ret; 52 52 53 53 msleep(125 + 10); /* measurement takes up to 125 ms for IT 1x */ 54 54 55 55 ret = i2c_smbus_read_byte(data->client2); /* read MSB, address 0x39 */ 56 56 if (ret < 0) 57 - goto out; 57 + return ret; 58 + 58 59 msb = ret; 59 60 60 61 ret = i2c_smbus_read_byte(data->client1); /* read LSB, address 0x38 */ 61 62 if (ret < 0) 62 - goto out; 63 + return ret; 64 + 63 65 lsb = ret; 64 66 65 67 /* shutdown again */ 66 68 ret = i2c_smbus_write_byte(data->client1, data->config); 67 69 if (ret < 0) 68 - goto out; 70 + return ret; 69 71 70 72 ret = (msb << 8) | lsb; 71 73 72 - out: 73 - mutex_unlock(&data->lock); 74 - return ret; 74 + return 0; 75 75 } 76 76 77 77 static const struct iio_chan_spec veml6070_channels[] = { ··· 135 135 .read_raw = veml6070_read_raw, 136 136 }; 137 137 138 + static void veml6070_i2c_unreg(void *p) 139 + { 140 + struct veml6070_data *data = p; 141 + 142 + i2c_unregister_device(data->client2); 143 + } 144 + 138 145 static int veml6070_probe(struct i2c_client *client) 139 146 { 140 147 struct veml6070_data *data; ··· 163 156 indio_dev->name = VEML6070_DRV_NAME; 164 157 indio_dev->modes = INDIO_DIRECT_MODE; 165 158 159 + ret = devm_regulator_get_enable(&client->dev, "vdd"); 160 + if (ret < 0) 161 + return ret; 162 + 166 163 data->client2 = i2c_new_dummy_device(client->adapter, VEML6070_ADDR_DATA_LSB); 167 - if (IS_ERR(data->client2)) { 168 - dev_err(&client->dev, "i2c device for second chip address failed\n"); 169 - return PTR_ERR(data->client2); 170 - } 164 + if (IS_ERR(data->client2)) 165 + return dev_err_probe(&client->dev, PTR_ERR(data->client2), 166 + "i2c device for second chip address failed\n"); 171 167 172 168 data->config = VEML6070_IT_10 | VEML6070_COMMAND_RSRVD | 173 169 VEML6070_COMMAND_SD; 174 170 ret = i2c_smbus_write_byte(data->client1, data->config); 175 171 if (ret < 0) 176 - goto fail; 172 + return ret; 177 173 178 - ret = iio_device_register(indio_dev); 174 + ret = devm_add_action_or_reset(&client->dev, veml6070_i2c_unreg, data); 179 175 if (ret < 0) 180 - goto fail; 176 + return ret; 181 177 182 - return ret; 183 - 184 - fail: 185 - i2c_unregister_device(data->client2); 186 - return ret; 187 - } 188 - 189 - static void veml6070_remove(struct i2c_client *client) 190 - { 191 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 192 - struct veml6070_data *data = iio_priv(indio_dev); 193 - 194 - iio_device_unregister(indio_dev); 195 - i2c_unregister_device(data->client2); 178 + return devm_iio_device_register(&client->dev, indio_dev); 196 179 } 197 180 198 181 static const struct i2c_device_id veml6070_id[] = { ··· 191 194 }; 192 195 MODULE_DEVICE_TABLE(i2c, veml6070_id); 193 196 197 + static const struct of_device_id veml6070_of_match[] = { 198 + { .compatible = "vishay,veml6070" }, 199 + { } 200 + }; 201 + MODULE_DEVICE_TABLE(of, veml6070_of_match); 202 + 194 203 static struct i2c_driver veml6070_driver = { 195 204 .driver = { 196 205 .name = VEML6070_DRV_NAME, 206 + .of_match_table = veml6070_of_match, 197 207 }, 198 208 .probe = veml6070_probe, 199 - .remove = veml6070_remove, 200 209 .id_table = veml6070_id, 201 210 }; 202 211
+238 -15
drivers/iio/light/vl6180.c
··· 25 25 26 26 #include <linux/iio/iio.h> 27 27 #include <linux/iio/sysfs.h> 28 + #include <linux/iio/buffer.h> 29 + #include <linux/iio/trigger.h> 30 + #include <linux/iio/trigger_consumer.h> 31 + #include <linux/iio/triggered_buffer.h> 28 32 29 33 #define VL6180_DRV_NAME "vl6180" 30 34 ··· 42 38 #define VL6180_OUT_OF_RESET 0x016 43 39 #define VL6180_HOLD 0x017 44 40 #define VL6180_RANGE_START 0x018 41 + #define VL6180_RANGE_INTER_MEAS_TIME 0x01b 45 42 #define VL6180_ALS_START 0x038 43 + #define VL6180_ALS_INTER_MEAS_TIME 0x03e 46 44 #define VL6180_ALS_GAIN 0x03f 47 45 #define VL6180_ALS_IT 0x040 48 46 ··· 90 84 struct vl6180_data { 91 85 struct i2c_client *client; 92 86 struct mutex lock; 87 + struct completion completion; 88 + struct iio_trigger *trig; 93 89 unsigned int als_gain_milli; 94 90 unsigned int als_it_ms; 91 + unsigned int als_meas_rate; 92 + unsigned int range_meas_rate; 93 + 94 + struct { 95 + u16 chan[2]; 96 + aligned_s64 timestamp; 97 + } scan; 95 98 }; 96 99 97 100 enum { VL6180_ALS, VL6180_RANGE, VL6180_PROX }; ··· 222 207 static int vl6180_measure(struct vl6180_data *data, int addr) 223 208 { 224 209 struct i2c_client *client = data->client; 210 + unsigned long time_left; 225 211 int tries = 20, ret; 226 212 u16 value; 227 213 228 214 mutex_lock(&data->lock); 215 + reinit_completion(&data->completion); 216 + 229 217 /* Start single shot measurement */ 230 218 ret = vl6180_write_byte(client, 231 219 vl6180_chan_regs_table[addr].start_reg, VL6180_STARTSTOP); 232 220 if (ret < 0) 233 221 goto fail; 234 222 235 - while (tries--) { 236 - ret = vl6180_read_byte(client, VL6180_INTR_STATUS); 237 - if (ret < 0) 223 + if (client->irq) { 224 + time_left = wait_for_completion_timeout(&data->completion, HZ / 10); 225 + if (time_left == 0) { 226 + ret = -ETIMEDOUT; 238 227 goto fail; 228 + } 229 + } else { 230 + while (tries--) { 231 + ret = vl6180_read_byte(client, VL6180_INTR_STATUS); 232 + if (ret < 0) 233 + goto fail; 239 234 240 - if (ret & vl6180_chan_regs_table[addr].drdy_mask) 241 - break; 242 - msleep(20); 243 - } 235 + if (ret & vl6180_chan_regs_table[addr].drdy_mask) 236 + break; 237 + msleep(20); 238 + } 244 239 245 - if (tries < 0) { 246 - ret = -EIO; 247 - goto fail; 240 + if (tries < 0) { 241 + ret = -EIO; 242 + goto fail; 243 + } 248 244 } 249 245 250 246 /* Read result value from appropriate registers */ ··· 284 258 { 285 259 .type = IIO_LIGHT, 286 260 .address = VL6180_ALS, 261 + .scan_index = VL6180_ALS, 262 + .scan_type = { 263 + .sign = 'u', 264 + .realbits = 16, 265 + .storagebits = 16, 266 + }, 287 267 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 288 268 BIT(IIO_CHAN_INFO_INT_TIME) | 289 269 BIT(IIO_CHAN_INFO_SCALE) | 290 - BIT(IIO_CHAN_INFO_HARDWAREGAIN), 270 + BIT(IIO_CHAN_INFO_HARDWAREGAIN) | 271 + BIT(IIO_CHAN_INFO_SAMP_FREQ), 291 272 }, { 292 273 .type = IIO_DISTANCE, 293 274 .address = VL6180_RANGE, 275 + .scan_index = VL6180_RANGE, 276 + .scan_type = { 277 + .sign = 'u', 278 + .realbits = 8, 279 + .storagebits = 8, 280 + }, 294 281 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 295 - BIT(IIO_CHAN_INFO_SCALE), 282 + BIT(IIO_CHAN_INFO_SCALE) | 283 + BIT(IIO_CHAN_INFO_SAMP_FREQ), 296 284 }, { 297 285 .type = IIO_PROXIMITY, 298 286 .address = VL6180_PROX, 287 + .scan_index = VL6180_PROX, 288 + .scan_type = { 289 + .sign = 'u', 290 + .realbits = 16, 291 + .storagebits = 16, 292 + }, 299 293 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 300 - } 294 + }, 295 + IIO_CHAN_SOFT_TIMESTAMP(3), 301 296 }; 302 297 303 298 /* ··· 379 332 *val2 = 1000; 380 333 381 334 return IIO_VAL_FRACTIONAL; 335 + 336 + case IIO_CHAN_INFO_SAMP_FREQ: 337 + switch (chan->type) { 338 + case IIO_DISTANCE: 339 + *val = data->range_meas_rate; 340 + return IIO_VAL_INT; 341 + case IIO_LIGHT: 342 + *val = data->als_meas_rate; 343 + return IIO_VAL_INT; 344 + default: 345 + return -EINVAL; 346 + } 382 347 383 348 default: 384 349 return -EINVAL; ··· 471 412 return ret; 472 413 } 473 414 415 + static int vl6180_meas_reg_val_from_mhz(unsigned int mhz) 416 + { 417 + unsigned int period = DIV_ROUND_CLOSEST(1000 * 1000, mhz); 418 + unsigned int reg_val = 0; 419 + 420 + if (period > 10) 421 + reg_val = period < 2550 ? (DIV_ROUND_CLOSEST(period, 10) - 1) : 254; 422 + 423 + return reg_val; 424 + } 425 + 474 426 static int vl6180_write_raw(struct iio_dev *indio_dev, 475 427 struct iio_chan_spec const *chan, 476 428 int val, int val2, long mask) 477 429 { 478 430 struct vl6180_data *data = iio_priv(indio_dev); 431 + unsigned int reg_val; 479 432 480 433 switch (mask) { 481 434 case IIO_CHAN_INFO_INT_TIME: ··· 498 427 return -EINVAL; 499 428 500 429 return vl6180_set_als_gain(data, val, val2); 430 + 431 + case IIO_CHAN_INFO_SAMP_FREQ: 432 + { 433 + guard(mutex)(&data->lock); 434 + switch (chan->type) { 435 + case IIO_DISTANCE: 436 + data->range_meas_rate = val; 437 + reg_val = vl6180_meas_reg_val_from_mhz(val); 438 + return vl6180_write_byte(data->client, 439 + VL6180_RANGE_INTER_MEAS_TIME, reg_val); 440 + 441 + case IIO_LIGHT: 442 + data->als_meas_rate = val; 443 + reg_val = vl6180_meas_reg_val_from_mhz(val); 444 + return vl6180_write_byte(data->client, 445 + VL6180_ALS_INTER_MEAS_TIME, reg_val); 446 + 447 + default: 448 + return -EINVAL; 449 + } 450 + } 451 + 501 452 default: 502 453 return -EINVAL; 503 454 } 455 + } 456 + 457 + static irqreturn_t vl6180_threaded_irq(int irq, void *priv) 458 + { 459 + struct iio_dev *indio_dev = priv; 460 + struct vl6180_data *data = iio_priv(indio_dev); 461 + 462 + if (iio_buffer_enabled(indio_dev)) 463 + iio_trigger_poll_nested(indio_dev->trig); 464 + else 465 + complete(&data->completion); 466 + 467 + return IRQ_HANDLED; 468 + } 469 + 470 + static irqreturn_t vl6180_trigger_handler(int irq, void *priv) 471 + { 472 + struct iio_poll_func *pf = priv; 473 + struct iio_dev *indio_dev = pf->indio_dev; 474 + struct vl6180_data *data = iio_priv(indio_dev); 475 + s64 time_ns = iio_get_time_ns(indio_dev); 476 + int ret, bit, i = 0; 477 + 478 + iio_for_each_active_channel(indio_dev, bit) { 479 + if (vl6180_chan_regs_table[bit].word) 480 + ret = vl6180_read_word(data->client, 481 + vl6180_chan_regs_table[bit].value_reg); 482 + else 483 + ret = vl6180_read_byte(data->client, 484 + vl6180_chan_regs_table[bit].value_reg); 485 + 486 + if (ret < 0) { 487 + dev_err(&data->client->dev, 488 + "failed to read from value regs: %d\n", ret); 489 + return IRQ_HANDLED; 490 + } 491 + 492 + data->scan.chan[i++] = ret; 493 + } 494 + 495 + iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, time_ns); 496 + iio_trigger_notify_done(indio_dev->trig); 497 + 498 + /* Clear the interrupt flag after data read */ 499 + ret = vl6180_write_byte(data->client, VL6180_INTR_CLEAR, 500 + VL6180_CLEAR_ERROR | VL6180_CLEAR_ALS | VL6180_CLEAR_RANGE); 501 + if (ret < 0) 502 + dev_err(&data->client->dev, "failed to clear irq: %d\n", ret); 503 + 504 + return IRQ_HANDLED; 504 505 } 505 506 506 507 static const struct iio_info vl6180_info = { 507 508 .read_raw = vl6180_read_raw, 508 509 .write_raw = vl6180_write_raw, 509 510 .attrs = &vl6180_attribute_group, 511 + .validate_trigger = iio_validate_own_trigger, 510 512 }; 511 513 512 - static int vl6180_init(struct vl6180_data *data) 514 + static int vl6180_buffer_postenable(struct iio_dev *indio_dev) 515 + { 516 + struct vl6180_data *data = iio_priv(indio_dev); 517 + int bit; 518 + 519 + iio_for_each_active_channel(indio_dev, bit) 520 + return vl6180_write_byte(data->client, 521 + vl6180_chan_regs_table[bit].start_reg, 522 + VL6180_MODE_CONT | VL6180_STARTSTOP); 523 + 524 + return -EINVAL; 525 + } 526 + 527 + static int vl6180_buffer_postdisable(struct iio_dev *indio_dev) 528 + { 529 + struct vl6180_data *data = iio_priv(indio_dev); 530 + int bit; 531 + 532 + iio_for_each_active_channel(indio_dev, bit) 533 + return vl6180_write_byte(data->client, 534 + vl6180_chan_regs_table[bit].start_reg, 535 + VL6180_STARTSTOP); 536 + 537 + return -EINVAL; 538 + } 539 + 540 + static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = { 541 + .postenable = &vl6180_buffer_postenable, 542 + .postdisable = &vl6180_buffer_postdisable, 543 + }; 544 + 545 + static const struct iio_trigger_ops vl6180_trigger_ops = { 546 + .validate_device = iio_trigger_validate_own_device, 547 + }; 548 + 549 + static int vl6180_init(struct vl6180_data *data, struct iio_dev *indio_dev) 513 550 { 514 551 struct i2c_client *client = data->client; 515 552 int ret; ··· 651 472 VL6180_ALS_READY | VL6180_RANGE_READY); 652 473 if (ret < 0) 653 474 return ret; 475 + 476 + ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, 477 + &vl6180_trigger_handler, 478 + &iio_triggered_buffer_setup_ops); 479 + if (ret) 480 + return ret; 481 + 482 + /* Default Range inter-measurement time: 50ms or 20000 mHz */ 483 + ret = vl6180_write_byte(client, VL6180_RANGE_INTER_MEAS_TIME, 484 + vl6180_meas_reg_val_from_mhz(20000)); 485 + if (ret < 0) 486 + return ret; 487 + data->range_meas_rate = 20000; 488 + 489 + /* Default ALS inter-measurement time: 10ms or 100000 mHz */ 490 + ret = vl6180_write_byte(client, VL6180_ALS_INTER_MEAS_TIME, 491 + vl6180_meas_reg_val_from_mhz(100000)); 492 + if (ret < 0) 493 + return ret; 494 + data->als_meas_rate = 100000; 654 495 655 496 /* ALS integration time: 100ms */ 656 497 data->als_it_ms = 100; ··· 712 513 indio_dev->name = VL6180_DRV_NAME; 713 514 indio_dev->modes = INDIO_DIRECT_MODE; 714 515 715 - ret = vl6180_init(data); 516 + ret = vl6180_init(data, indio_dev); 716 517 if (ret < 0) 717 518 return ret; 519 + 520 + if (client->irq) { 521 + ret = devm_request_threaded_irq(&client->dev, client->irq, 522 + NULL, vl6180_threaded_irq, 523 + IRQF_ONESHOT, 524 + indio_dev->name, indio_dev); 525 + if (ret) 526 + return dev_err_probe(&client->dev, ret, "devm_request_irq error \n"); 527 + 528 + init_completion(&data->completion); 529 + 530 + data->trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d", 531 + indio_dev->name, iio_device_id(indio_dev)); 532 + if (!data->trig) 533 + return -ENOMEM; 534 + 535 + data->trig->ops = &vl6180_trigger_ops; 536 + iio_trigger_set_drvdata(data->trig, indio_dev); 537 + ret = devm_iio_trigger_register(&client->dev, data->trig); 538 + if (ret) 539 + return ret; 540 + 541 + indio_dev->trig = iio_trigger_get(data->trig); 542 + } 718 543 719 544 return devm_iio_device_register(&client->dev, indio_dev); 720 545 }
+1 -1
drivers/iio/magnetometer/ak8974.c
··· 910 910 911 911 /* If we have a valid DRDY IRQ, make use of it */ 912 912 if (irq > 0) { 913 - irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq)); 913 + irq_trig = irq_get_trigger_type(irq); 914 914 if (irq_trig == IRQF_TRIGGER_RISING) { 915 915 dev_info(&i2c->dev, "enable rising edge DRDY IRQ\n"); 916 916 } else if (irq_trig == IRQF_TRIGGER_FALLING) {
+3 -3
drivers/iio/magnetometer/hid-sensor-magn-3d.c
··· 466 466 /* Function to initialize the processing for usage id */ 467 467 static int hid_magn_3d_probe(struct platform_device *pdev) 468 468 { 469 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 469 470 int ret = 0; 470 471 static char *name = "magn_3d"; 471 472 struct iio_dev *indio_dev; 472 473 struct magn_3d_state *magn_state; 473 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 474 474 struct iio_chan_spec *channels; 475 475 int chan_count = 0; 476 476 ··· 549 549 /* Function to deinitialize the processing for usage id */ 550 550 static void hid_magn_3d_remove(struct platform_device *pdev) 551 551 { 552 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 552 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 553 553 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 554 554 struct magn_3d_state *magn_state = iio_priv(indio_dev); 555 555 ··· 574 574 .pm = &hid_sensor_pm_ops, 575 575 }, 576 576 .probe = hid_magn_3d_probe, 577 - .remove_new = hid_magn_3d_remove, 577 + .remove = hid_magn_3d_remove, 578 578 }; 579 579 module_platform_driver(hid_magn_3d_platform_driver); 580 580
+4 -4
drivers/iio/orientation/hid-sensor-incl-3d.c
··· 29 29 struct hid_sensor_hub_attribute_info incl[INCLI_3D_CHANNEL_MAX]; 30 30 struct { 31 31 u32 incl_val[INCLI_3D_CHANNEL_MAX]; 32 - u64 timestamp __aligned(8); 32 + aligned_s64 timestamp; 33 33 } scan; 34 34 int scale_pre_decml; 35 35 int scale_post_decml; ··· 299 299 /* Function to initialize the processing for usage id */ 300 300 static int hid_incl_3d_probe(struct platform_device *pdev) 301 301 { 302 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 302 303 int ret; 303 304 static char *name = "incli_3d"; 304 305 struct iio_dev *indio_dev; 305 306 struct incl_3d_state *incl_state; 306 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 307 307 308 308 indio_dev = devm_iio_device_alloc(&pdev->dev, 309 309 sizeof(struct incl_3d_state)); ··· 385 385 /* Function to deinitialize the processing for usage id */ 386 386 static void hid_incl_3d_remove(struct platform_device *pdev) 387 387 { 388 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 388 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 389 389 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 390 390 struct incl_3d_state *incl_state = iio_priv(indio_dev); 391 391 ··· 410 410 .pm = &hid_sensor_pm_ops, 411 411 }, 412 412 .probe = hid_incl_3d_probe, 413 - .remove_new = hid_incl_3d_remove, 413 + .remove = hid_incl_3d_remove, 414 414 }; 415 415 module_platform_driver(hid_incl_3d_platform_driver); 416 416
+4 -4
drivers/iio/orientation/hid-sensor-rotation.c
··· 20 20 struct hid_sensor_hub_attribute_info quaternion; 21 21 struct { 22 22 s32 sampled_vals[4] __aligned(16); 23 - u64 timestamp __aligned(8); 23 + aligned_s64 timestamp; 24 24 } scan; 25 25 int scale_pre_decml; 26 26 int scale_post_decml; ··· 230 230 /* Function to initialize the processing for usage id */ 231 231 static int hid_dev_rot_probe(struct platform_device *pdev) 232 232 { 233 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 233 234 int ret; 234 235 char *name; 235 236 struct iio_dev *indio_dev; 236 237 struct dev_rot_state *rot_state; 237 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 238 238 239 239 indio_dev = devm_iio_device_alloc(&pdev->dev, 240 240 sizeof(struct dev_rot_state)); ··· 329 329 /* Function to deinitialize the processing for usage id */ 330 330 static void hid_dev_rot_remove(struct platform_device *pdev) 331 331 { 332 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 332 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 333 333 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 334 334 struct dev_rot_state *rot_state = iio_priv(indio_dev); 335 335 ··· 362 362 .pm = &hid_sensor_pm_ops, 363 363 }, 364 364 .probe = hid_dev_rot_probe, 365 - .remove_new = hid_dev_rot_remove, 365 + .remove = hid_dev_rot_remove, 366 366 }; 367 367 module_platform_driver(hid_dev_rot_platform_driver); 368 368
+4 -4
drivers/iio/position/hid-sensor-custom-intel-hinge.c
··· 39 39 const char *labels[CHANNEL_SCAN_INDEX_MAX]; 40 40 struct { 41 41 u32 hinge_val[3]; 42 - u64 timestamp __aligned(8); 42 + aligned_s64 timestamp; 43 43 } scan; 44 44 45 45 int scale_pre_decml; ··· 263 263 /* Function to initialize the processing for usage id */ 264 264 static int hid_hinge_probe(struct platform_device *pdev) 265 265 { 266 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 266 267 struct hinge_state *st; 267 268 struct iio_dev *indio_dev; 268 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 269 269 int ret; 270 270 int i; 271 271 ··· 344 344 /* Function to deinitialize the processing for usage id */ 345 345 static void hid_hinge_remove(struct platform_device *pdev) 346 346 { 347 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 347 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 348 348 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 349 349 struct hinge_state *st = iio_priv(indio_dev); 350 350 ··· 369 369 .pm = &hid_sensor_pm_ops, 370 370 }, 371 371 .probe = hid_hinge_probe, 372 - .remove_new = hid_hinge_remove, 372 + .remove = hid_hinge_remove, 373 373 }; 374 374 module_platform_driver(hid_hinge_platform_driver); 375 375
+101 -76
drivers/iio/pressure/bmp280-core.c
··· 340 340 return 0; 341 341 } 342 342 343 + /* 344 + * These enums are used for indexing into the array of humidity parameters 345 + * for BME280. Due to some weird indexing, unaligned BE/LE accesses co-exist in 346 + * order to prepare the FIELD_{GET/PREP}() fields. Table 16 in Section 4.2.2 of 347 + * the datasheet. 348 + */ 349 + enum { H2 = 0, H3 = 2, H4 = 3, H5 = 4, H6 = 6 }; 350 + 343 351 static int bme280_read_calib(struct bmp280_data *data) 344 352 { 345 353 struct bmp280_calib *calib = &data->calib.bmp280; 346 354 struct device *dev = data->dev; 355 + s16 h4_upper, h4_lower, tmp_1, tmp_2, tmp_3; 347 356 unsigned int tmp; 348 357 int ret; 349 358 ··· 360 351 ret = bmp280_read_calib(data); 361 352 if (ret) 362 353 return ret; 363 - 364 - /* 365 - * Read humidity calibration values. 366 - * Due to some odd register addressing we cannot just 367 - * do a big bulk read. Instead, we have to read each Hx 368 - * value separately and sometimes do some bit shifting... 369 - * Humidity data is only available on BME280. 370 - */ 371 354 372 355 ret = regmap_read(data->regmap, BME280_REG_COMP_H1, &tmp); 373 356 if (ret) { ··· 369 368 calib->H1 = tmp; 370 369 371 370 ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H2, 372 - &data->le16, sizeof(data->le16)); 371 + data->bme280_humid_cal_buf, 372 + sizeof(data->bme280_humid_cal_buf)); 373 373 if (ret) { 374 - dev_err(dev, "failed to read H2 comp value\n"); 374 + dev_err(dev, "failed to read humidity calibration values\n"); 375 375 return ret; 376 376 } 377 - calib->H2 = sign_extend32(le16_to_cpu(data->le16), 15); 378 377 379 - ret = regmap_read(data->regmap, BME280_REG_COMP_H3, &tmp); 380 - if (ret) { 381 - dev_err(dev, "failed to read H3 comp value\n"); 382 - return ret; 383 - } 384 - calib->H3 = tmp; 385 - 386 - ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H4, 387 - &data->be16, sizeof(data->be16)); 388 - if (ret) { 389 - dev_err(dev, "failed to read H4 comp value\n"); 390 - return ret; 391 - } 392 - calib->H4 = sign_extend32(((be16_to_cpu(data->be16) >> 4) & 0xff0) | 393 - (be16_to_cpu(data->be16) & 0xf), 11); 394 - 395 - ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H5, 396 - &data->le16, sizeof(data->le16)); 397 - if (ret) { 398 - dev_err(dev, "failed to read H5 comp value\n"); 399 - return ret; 400 - } 401 - calib->H5 = sign_extend32(FIELD_GET(BME280_COMP_H5_MASK, le16_to_cpu(data->le16)), 11); 402 - 403 - ret = regmap_read(data->regmap, BME280_REG_COMP_H6, &tmp); 404 - if (ret) { 405 - dev_err(dev, "failed to read H6 comp value\n"); 406 - return ret; 407 - } 408 - calib->H6 = sign_extend32(tmp, 7); 378 + calib->H2 = get_unaligned_le16(&data->bme280_humid_cal_buf[H2]); 379 + calib->H3 = data->bme280_humid_cal_buf[H3]; 380 + tmp_1 = get_unaligned_be16(&data->bme280_humid_cal_buf[H4]); 381 + tmp_2 = FIELD_GET(BME280_COMP_H4_GET_MASK_UP, tmp_1); 382 + h4_upper = FIELD_PREP(BME280_COMP_H4_PREP_MASK_UP, tmp_2); 383 + h4_lower = FIELD_GET(BME280_COMP_H4_MASK_LOW, tmp_1); 384 + calib->H4 = sign_extend32(h4_upper | h4_lower, 11); 385 + tmp_3 = get_unaligned_le16(&data->bme280_humid_cal_buf[H5]); 386 + calib->H5 = sign_extend32(FIELD_GET(BME280_COMP_H5_MASK, tmp_3), 11); 387 + calib->H6 = data->bme280_humid_cal_buf[H6]; 409 388 410 389 return 0; 411 390 } ··· 964 983 0 965 984 }; 966 985 986 + static int bmp280_preinit(struct bmp280_data *data) 987 + { 988 + struct device *dev = data->dev; 989 + unsigned int reg; 990 + int ret; 991 + 992 + ret = regmap_write(data->regmap, BMP280_REG_RESET, BMP280_RST_SOFT_CMD); 993 + if (ret) 994 + return dev_err_probe(dev, ret, "Failed to reset device.\n"); 995 + 996 + /* 997 + * According to the datasheet in Chapter 1: Specification, Table 2, 998 + * after resetting, the device uses the complete power-on sequence so 999 + * it needs to wait for the defined start-up time. 1000 + */ 1001 + fsleep(data->start_up_time); 1002 + 1003 + ret = regmap_read(data->regmap, BMP280_REG_STATUS, &reg); 1004 + if (ret) 1005 + return dev_err_probe(dev, ret, "Failed to read status register.\n"); 1006 + 1007 + if (reg & BMP280_REG_STATUS_IM_UPDATE) 1008 + return dev_err_probe(dev, -EIO, "Failed to copy NVM contents.\n"); 1009 + 1010 + return 0; 1011 + } 1012 + 967 1013 static int bmp280_chip_config(struct bmp280_data *data) 968 1014 { 969 1015 u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | ··· 1023 1015 struct iio_poll_func *pf = p; 1024 1016 struct iio_dev *indio_dev = pf->indio_dev; 1025 1017 struct bmp280_data *data = iio_priv(indio_dev); 1026 - s32 adc_temp, adc_press, t_fine; 1018 + u32 adc_temp, adc_press, comp_press; 1019 + s32 t_fine, comp_temp; 1020 + s32 *chans = (s32 *)data->sensor_data; 1027 1021 int ret; 1028 1022 1029 1023 guard(mutex)(&data->lock); ··· 1045 1035 goto out; 1046 1036 } 1047 1037 1048 - data->sensor_data[1] = bmp280_compensate_temp(data, adc_temp); 1038 + comp_temp = bmp280_compensate_temp(data, adc_temp); 1049 1039 1050 1040 /* Pressure calculations */ 1051 1041 adc_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[0])); ··· 1055 1045 } 1056 1046 1057 1047 t_fine = bmp280_calc_t_fine(data, adc_temp); 1048 + comp_press = bmp280_compensate_press(data, adc_press, t_fine); 1058 1049 1059 - data->sensor_data[0] = bmp280_compensate_press(data, adc_press, t_fine); 1050 + chans[0] = comp_press; 1051 + chans[1] = comp_temp; 1060 1052 1061 - iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, 1053 + iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, 1062 1054 iio_get_time_ns(indio_dev)); 1063 1055 1064 1056 out: ··· 1111 1099 .read_temp = bmp280_read_temp, 1112 1100 .read_press = bmp280_read_press, 1113 1101 .read_calib = bmp280_read_calib, 1102 + .preinit = bmp280_preinit, 1114 1103 1115 1104 .trigger_handler = bmp280_trigger_handler, 1116 1105 }; ··· 1141 1128 struct iio_poll_func *pf = p; 1142 1129 struct iio_dev *indio_dev = pf->indio_dev; 1143 1130 struct bmp280_data *data = iio_priv(indio_dev); 1144 - s32 adc_temp, adc_press, adc_humidity, t_fine; 1131 + u32 adc_temp, adc_press, adc_humidity, comp_press, comp_humidity; 1132 + s32 t_fine, comp_temp; 1133 + s32 *chans = (s32 *)data->sensor_data; 1145 1134 int ret; 1146 1135 1147 1136 guard(mutex)(&data->lock); ··· 1163 1148 goto out; 1164 1149 } 1165 1150 1166 - data->sensor_data[1] = bmp280_compensate_temp(data, adc_temp); 1151 + comp_temp = bmp280_compensate_temp(data, adc_temp); 1167 1152 1168 1153 /* Pressure calculations */ 1169 1154 adc_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[0])); ··· 1173 1158 } 1174 1159 1175 1160 t_fine = bmp280_calc_t_fine(data, adc_temp); 1176 - 1177 - data->sensor_data[0] = bmp280_compensate_press(data, adc_press, t_fine); 1161 + comp_press = bmp280_compensate_press(data, adc_press, t_fine); 1178 1162 1179 1163 /* Humidity calculations */ 1180 1164 adc_humidity = get_unaligned_be16(&data->buf[6]); ··· 1182 1168 dev_err(data->dev, "reading humidity skipped\n"); 1183 1169 goto out; 1184 1170 } 1185 - data->sensor_data[2] = bme280_compensate_humidity(data, adc_humidity, t_fine); 1186 1171 1187 - iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, 1172 + comp_humidity = bme280_compensate_humidity(data, adc_humidity, t_fine); 1173 + 1174 + chans[0] = comp_press; 1175 + chans[1] = comp_temp; 1176 + chans[2] = comp_humidity; 1177 + 1178 + iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, 1188 1179 iio_get_time_ns(indio_dev)); 1189 1180 1190 1181 out: ··· 1235 1216 .read_press = bmp280_read_press, 1236 1217 .read_humid = bme280_read_humid, 1237 1218 .read_calib = bme280_read_calib, 1219 + .preinit = bmp280_preinit, 1238 1220 1239 1221 .trigger_handler = bme280_trigger_handler, 1240 1222 }; ··· 1565 1545 change = change || aux; 1566 1546 1567 1547 /* Set filter data */ 1568 - ret = regmap_update_bits_check(data->regmap, BMP380_REG_CONFIG, BMP380_FILTER_MASK, 1569 - FIELD_PREP(BMP380_FILTER_MASK, data->iir_filter_coeff), 1570 - &aux); 1548 + ret = regmap_update_bits(data->regmap, BMP380_REG_CONFIG, BMP380_FILTER_MASK, 1549 + FIELD_PREP(BMP380_FILTER_MASK, data->iir_filter_coeff)); 1571 1550 if (ret) { 1572 1551 dev_err(data->dev, "failed to write config register\n"); 1573 1552 return ret; 1574 1553 } 1575 - change = change || aux; 1576 1554 1577 1555 if (change) { 1578 1556 /* ··· 1626 1608 struct iio_poll_func *pf = p; 1627 1609 struct iio_dev *indio_dev = pf->indio_dev; 1628 1610 struct bmp280_data *data = iio_priv(indio_dev); 1629 - s32 adc_temp, adc_press, t_fine; 1611 + u32 adc_temp, adc_press, comp_press; 1612 + s32 t_fine, comp_temp; 1613 + s32 *chans = (s32 *)data->sensor_data; 1630 1614 int ret; 1631 1615 1632 1616 guard(mutex)(&data->lock); ··· 1648 1628 goto out; 1649 1629 } 1650 1630 1651 - data->sensor_data[1] = bmp380_compensate_temp(data, adc_temp); 1631 + comp_temp = bmp380_compensate_temp(data, adc_temp); 1652 1632 1653 1633 /* Pressure calculations */ 1654 1634 adc_press = get_unaligned_le24(&data->buf[0]); ··· 1658 1638 } 1659 1639 1660 1640 t_fine = bmp380_calc_t_fine(data, adc_temp); 1641 + comp_press = bmp380_compensate_press(data, adc_press, t_fine); 1661 1642 1662 - data->sensor_data[0] = bmp380_compensate_press(data, adc_press, t_fine); 1643 + chans[0] = comp_press; 1644 + chans[1] = comp_temp; 1663 1645 1664 - iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, 1646 + iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, 1665 1647 iio_get_time_ns(indio_dev)); 1666 1648 1667 1649 out: ··· 2163 2141 reg_val = FIELD_PREP(BMP580_DSP_IIR_PRESS_MASK, data->iir_filter_coeff) | 2164 2142 FIELD_PREP(BMP580_DSP_IIR_TEMP_MASK, data->iir_filter_coeff); 2165 2143 2166 - ret = regmap_update_bits_check(data->regmap, BMP580_REG_DSP_IIR, 2167 - BMP580_DSP_IIR_PRESS_MASK | 2168 - BMP580_DSP_IIR_TEMP_MASK, 2169 - reg_val, &aux); 2144 + ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_IIR, 2145 + BMP580_DSP_IIR_PRESS_MASK | BMP580_DSP_IIR_TEMP_MASK, 2146 + reg_val); 2170 2147 if (ret) { 2171 2148 dev_err(data->dev, "failed to write config register\n"); 2172 2149 return ret; 2173 2150 } 2174 - change = change || aux; 2175 2151 2176 2152 /* Restore sensor to normal operation mode */ 2177 2153 ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, ··· 2210 2190 struct iio_poll_func *pf = p; 2211 2191 struct iio_dev *indio_dev = pf->indio_dev; 2212 2192 struct bmp280_data *data = iio_priv(indio_dev); 2213 - int ret; 2193 + int ret, offset; 2214 2194 2215 2195 guard(mutex)(&data->lock); 2216 2196 ··· 2222 2202 goto out; 2223 2203 } 2224 2204 2225 - /* Temperature calculations */ 2226 - memcpy(&data->sensor_data[1], &data->buf[0], 3); 2205 + offset = 0; 2227 2206 2228 2207 /* Pressure calculations */ 2229 - memcpy(&data->sensor_data[0], &data->buf[3], 3); 2208 + memcpy(&data->sensor_data[offset], &data->buf[3], 3); 2230 2209 2231 - iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, 2210 + offset += sizeof(s32); 2211 + 2212 + /* Temperature calculations */ 2213 + memcpy(&data->sensor_data[offset], &data->buf[0], 3); 2214 + 2215 + iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, 2232 2216 iio_get_time_ns(indio_dev)); 2233 2217 2234 2218 out: ··· 2538 2514 struct iio_poll_func *pf = p; 2539 2515 struct iio_dev *indio_dev = pf->indio_dev; 2540 2516 struct bmp280_data *data = iio_priv(indio_dev); 2541 - int ret, chan_value; 2517 + int ret, comp_temp, comp_press; 2518 + s32 *chans = (s32 *)data->sensor_data; 2542 2519 2543 2520 guard(mutex)(&data->lock); 2544 2521 2545 - ret = bmp180_read_temp(data, &chan_value); 2522 + ret = bmp180_read_temp(data, &comp_temp); 2546 2523 if (ret) 2547 2524 goto out; 2548 2525 2549 - data->sensor_data[1] = chan_value; 2550 2526 2551 - ret = bmp180_read_press(data, &chan_value); 2527 + ret = bmp180_read_press(data, &comp_press); 2552 2528 if (ret) 2553 2529 goto out; 2554 2530 2555 - data->sensor_data[0] = chan_value; 2531 + chans[0] = comp_press; 2532 + chans[1] = comp_temp; 2556 2533 2557 - iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, 2534 + iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, 2558 2535 iio_get_time_ns(indio_dev)); 2559 2536 2560 2537 out: ··· 2621 2596 unsigned long irq_trig; 2622 2597 int ret; 2623 2598 2624 - irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq)); 2599 + irq_trig = irq_get_trigger_type(irq); 2625 2600 if (irq_trig != IRQF_TRIGGER_RISING) { 2626 2601 dev_err(dev, "non-rising trigger given for EOC interrupt, trying to enforce it\n"); 2627 2602 irq_trig = IRQF_TRIGGER_RISING;
+12 -1
drivers/iio/pressure/bmp280.h
··· 205 205 #define BMP280_REG_CONFIG 0xF5 206 206 #define BMP280_REG_CTRL_MEAS 0xF4 207 207 #define BMP280_REG_STATUS 0xF3 208 + #define BMP280_REG_STATUS_IM_UPDATE BIT(0) 209 + #define BMP280_REG_RESET 0xE0 210 + #define BMP280_RST_SOFT_CMD 0xB6 208 211 209 212 #define BMP280_REG_COMP_TEMP_START 0x88 210 213 #define BMP280_COMP_TEMP_REG_COUNT 6 ··· 260 257 #define BME280_REG_COMP_H5 0xE5 261 258 #define BME280_REG_COMP_H6 0xE7 262 259 260 + #define BME280_COMP_H4_GET_MASK_UP GENMASK(15, 8) 261 + #define BME280_COMP_H4_PREP_MASK_UP GENMASK(11, 4) 262 + #define BME280_COMP_H4_MASK_LOW GENMASK(3, 0) 263 263 #define BME280_COMP_H5_MASK GENMASK(15, 4) 264 + 265 + #define BME280_CONTIGUOUS_CALIB_REGS 7 264 266 265 267 #define BME280_OSRS_HUMIDITY_MASK GENMASK(2, 0) 266 268 #define BME280_OSRS_HUMIDITY_SKIP 0 ··· 322 314 BMP280_NUM_TEMP_BYTES + \ 323 315 BME280_NUM_HUMIDITY_BYTES) 324 316 317 + #define BME280_NUM_MAX_CHANNELS 3 325 318 /* Core exported structs */ 326 319 327 320 static const char *const bmp280_supply_names[] = { ··· 420 411 * Data to push to userspace triggered buffer. Up to 3 channels and 421 412 * s64 timestamp, aligned. 422 413 */ 423 - s32 sensor_data[6] __aligned(8); 414 + u8 sensor_data[ALIGN(sizeof(s32) * BME280_NUM_MAX_CHANNELS, sizeof(s64)) 415 + + sizeof(s64)] __aligned(sizeof(s64)); 424 416 425 417 /* 426 418 * DMA (thus cache coherency maintenance) may require the ··· 433 423 /* Calibration data buffers */ 434 424 __le16 bmp280_cal_buf[BMP280_CONTIGUOUS_CALIB_REGS / 2]; 435 425 __be16 bmp180_cal_buf[BMP180_REG_CALIB_COUNT / 2]; 426 + u8 bme280_humid_cal_buf[BME280_CONTIGUOUS_CALIB_REGS]; 436 427 u8 bmp380_cal_buf[BMP380_CALIB_REG_COUNT]; 437 428 /* Miscellaneous, endianness-aware data buffers */ 438 429 __le16 le16;
+4 -4
drivers/iio/pressure/hid-sensor-press.c
··· 24 24 struct hid_sensor_hub_attribute_info press_attr; 25 25 struct { 26 26 u32 press_data; 27 - u64 timestamp __aligned(8); 27 + aligned_s64 timestamp; 28 28 } scan; 29 29 int scale_pre_decml; 30 30 int scale_post_decml; ··· 241 241 /* Function to initialize the processing for usage id */ 242 242 static int hid_press_probe(struct platform_device *pdev) 243 243 { 244 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 244 245 int ret = 0; 245 246 static const char *name = "press"; 246 247 struct iio_dev *indio_dev; 247 248 struct press_state *press_state; 248 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 249 249 250 250 indio_dev = devm_iio_device_alloc(&pdev->dev, 251 251 sizeof(struct press_state)); ··· 325 325 /* Function to deinitialize the processing for usage id */ 326 326 static void hid_press_remove(struct platform_device *pdev) 327 327 { 328 - struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 328 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 329 329 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 330 330 struct press_state *press_state = iio_priv(indio_dev); 331 331 ··· 350 350 .pm = &hid_sensor_pm_ops, 351 351 }, 352 352 .probe = hid_press_probe, 353 - .remove_new = hid_press_remove, 353 + .remove = hid_press_remove, 354 354 }; 355 355 module_platform_driver(hid_press_platform_driver); 356 356
-3
drivers/iio/pressure/rohm-bm1390.c
··· 417 417 return ret; 418 418 } 419 419 420 - if (ret) 421 - return ret; 422 - 423 420 for (i = 0; i < smp_lvl; i++) { 424 421 buffer[i].temp = temp; 425 422 iio_push_to_buffers(idev, &buffer[i]);
+1 -1
drivers/iio/proximity/cros_ec_mkbp_proximity.c
··· 261 261 .pm = pm_sleep_ptr(&cros_ec_mkbp_proximity_pm_ops), 262 262 }, 263 263 .probe = cros_ec_mkbp_proximity_probe, 264 - .remove_new = cros_ec_mkbp_proximity_remove, 264 + .remove = cros_ec_mkbp_proximity_remove, 265 265 }; 266 266 module_platform_driver(cros_ec_mkbp_proximity_driver); 267 267
+1 -1
drivers/iio/proximity/srf04.c
··· 389 389 390 390 static struct platform_driver srf04_driver = { 391 391 .probe = srf04_probe, 392 - .remove_new = srf04_remove, 392 + .remove = srf04_remove, 393 393 .driver = { 394 394 .name = "srf04-gpio", 395 395 .of_match_table = of_srf04_match,
+20
drivers/iio/proximity/sx9324.c
··· 868 868 return raw; 869 869 } 870 870 871 + static void sx_common_get_raw_register_config(struct device *dev, 872 + struct sx_common_reg_default *reg_def) 873 + { 874 + #ifdef CONFIG_ACPI 875 + struct acpi_device *adev = ACPI_COMPANION(dev); 876 + u32 raw = 0, ret; 877 + char prop[80]; 878 + 879 + if (!reg_def->property || !adev) 880 + return; 881 + 882 + snprintf(prop, ARRAY_SIZE(prop), "%s,reg_%s", acpi_device_hid(adev), reg_def->property); 883 + ret = device_property_read_u32(dev, prop, &raw); 884 + if (ret) 885 + return; 886 + 887 + reg_def->def = raw; 888 + #endif 889 + } 890 + 871 891 static const struct sx_common_reg_default * 872 892 sx9324_get_default_reg(struct device *dev, int idx, 873 893 struct sx_common_reg_default *reg_def)
-1
drivers/iio/proximity/sx9360.c
··· 7 7 * https://edit.wpgdadawant.com/uploads/news_file/program/2019/30184/tech_files/program_30184_suggest_other_file.pdf 8 8 */ 9 9 10 - #include <linux/acpi.h> 11 10 #include <linux/bits.h> 12 11 #include <linux/bitfield.h> 13 12 #include <linux/delay.h>
-21
drivers/iio/proximity/sx_common.c
··· 421 421 .postdisable = sx_common_buffer_postdisable, 422 422 }; 423 423 424 - void sx_common_get_raw_register_config(struct device *dev, 425 - struct sx_common_reg_default *reg_def) 426 - { 427 - #ifdef CONFIG_ACPI 428 - struct acpi_device *adev = ACPI_COMPANION(dev); 429 - u32 raw = 0, ret; 430 - char prop[80]; 431 - 432 - if (!reg_def->property || !adev) 433 - return; 434 - 435 - snprintf(prop, ARRAY_SIZE(prop), "%s,reg_%s", acpi_device_hid(adev), reg_def->property); 436 - ret = device_property_read_u32(dev, prop, &raw); 437 - if (ret) 438 - return; 439 - 440 - reg_def->def = raw; 441 - #endif 442 - } 443 - EXPORT_SYMBOL_NS_GPL(sx_common_get_raw_register_config, SEMTECH_PROX); 444 - 445 424 #define SX_COMMON_SOFT_RESET 0xde 446 425 447 426 static int sx_common_init_device(struct device *dev, struct iio_dev *indio_dev)
-4
drivers/iio/proximity/sx_common.h
··· 8 8 #ifndef IIO_SX_COMMON_H 9 9 #define IIO_SX_COMMON_H 10 10 11 - #include <linux/acpi.h> 12 11 #include <linux/iio/iio.h> 13 12 #include <linux/iio/types.h> 14 13 #include <linux/regulator/consumer.h> ··· 148 149 int sx_common_probe(struct i2c_client *client, 149 150 const struct sx_common_chip_info *chip_info, 150 151 const struct regmap_config *regmap_config); 151 - 152 - void sx_common_get_raw_register_config(struct device *dev, 153 - struct sx_common_reg_default *reg_def); 154 152 155 153 /* 3 is the number of events defined by a single phase. */ 156 154 extern const struct iio_event_spec sx_common_events[3];
+146 -28
drivers/iio/proximity/vl53l0x-i2c.c
··· 20 20 #include <linux/irq.h> 21 21 #include <linux/interrupt.h> 22 22 #include <linux/module.h> 23 + #include <linux/unaligned.h> 23 24 24 25 #include <linux/iio/iio.h> 26 + #include <linux/iio/buffer.h> 27 + #include <linux/iio/trigger.h> 28 + #include <linux/iio/trigger_consumer.h> 29 + #include <linux/iio/triggered_buffer.h> 25 30 26 31 #define VL_REG_SYSRANGE_START 0x00 27 32 ··· 44 39 45 40 #define VL_REG_RESULT_INT_STATUS 0x13 46 41 #define VL_REG_RESULT_RANGE_STATUS 0x14 42 + #define VL_REG_IDENTIFICATION_MODEL_ID 0xC0 47 43 #define VL_REG_RESULT_RANGE_STATUS_COMPLETE BIT(0) 44 + 45 + #define VL53L0X_MODEL_ID_VAL 0xEE 46 + #define VL53L0X_CONTINUOUS_MODE 0x02 47 + #define VL53L0X_SINGLE_MODE 0x01 48 48 49 49 struct vl53l0x_data { 50 50 struct i2c_client *client; 51 51 struct completion completion; 52 52 struct regulator *vdd_supply; 53 53 struct gpio_desc *reset_gpio; 54 + struct iio_trigger *trig; 55 + 56 + struct { 57 + u16 chan; 58 + aligned_s64 timestamp; 59 + } scan; 54 60 }; 55 61 56 - static irqreturn_t vl53l0x_handle_irq(int irq, void *priv) 62 + static int vl53l0x_clear_irq(struct vl53l0x_data *data) 63 + { int ret; 64 + 65 + ret = i2c_smbus_write_byte_data(data->client, 66 + VL_REG_SYSTEM_INTERRUPT_CLEAR, 1); 67 + if (ret < 0) { 68 + dev_err(&data->client->dev, "failed to clear irq: %d\n", ret); 69 + return -EINVAL; 70 + } 71 + 72 + return 0; 73 + } 74 + 75 + static irqreturn_t vl53l0x_trigger_handler(int irq, void *priv) 76 + { 77 + struct iio_poll_func *pf = priv; 78 + struct iio_dev *indio_dev = pf->indio_dev; 79 + struct vl53l0x_data *data = iio_priv(indio_dev); 80 + u8 buffer[12]; 81 + int ret; 82 + 83 + ret = i2c_smbus_read_i2c_block_data(data->client, 84 + VL_REG_RESULT_RANGE_STATUS, 85 + sizeof(buffer), buffer); 86 + if (ret < 0) 87 + return ret; 88 + else if (ret != 12) 89 + return -EREMOTEIO; 90 + 91 + data->scan.chan = get_unaligned_be16(&buffer[10]); 92 + iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, 93 + iio_get_time_ns(indio_dev)); 94 + 95 + iio_trigger_notify_done(indio_dev->trig); 96 + vl53l0x_clear_irq(data); 97 + 98 + return IRQ_HANDLED; 99 + } 100 + 101 + static irqreturn_t vl53l0x_threaded_irq(int irq, void *priv) 57 102 { 58 103 struct iio_dev *indio_dev = priv; 59 104 struct vl53l0x_data *data = iio_priv(indio_dev); 60 105 61 - complete(&data->completion); 106 + if (iio_buffer_enabled(indio_dev)) 107 + iio_trigger_poll_nested(indio_dev->trig); 108 + else 109 + complete(&data->completion); 62 110 63 111 return IRQ_HANDLED; 64 112 } ··· 126 68 if (!irq_flags) 127 69 irq_flags = IRQF_TRIGGER_FALLING; 128 70 129 - ret = devm_request_irq(&client->dev, client->irq, vl53l0x_handle_irq, 130 - irq_flags, indio_dev->name, indio_dev); 71 + ret = devm_request_threaded_irq(&client->dev, client->irq, 72 + NULL, vl53l0x_threaded_irq, 73 + irq_flags | IRQF_ONESHOT, indio_dev->name, indio_dev); 131 74 if (ret) { 132 75 dev_err(&client->dev, "devm_request_irq error: %d\n", ret); 133 76 return ret; ··· 141 82 dev_err(&client->dev, "failed to configure IRQ: %d\n", ret); 142 83 143 84 return ret; 144 - } 145 - 146 - static void vl53l0x_clear_irq(struct vl53l0x_data *data) 147 - { 148 - struct device *dev = &data->client->dev; 149 - int ret; 150 - 151 - ret = i2c_smbus_write_byte_data(data->client, 152 - VL_REG_SYSTEM_INTERRUPT_CLEAR, 1); 153 - if (ret < 0) 154 - dev_err(dev, "failed to clear error irq: %d\n", ret); 155 - 156 - ret = i2c_smbus_write_byte_data(data->client, 157 - VL_REG_SYSTEM_INTERRUPT_CLEAR, 0); 158 - if (ret < 0) 159 - dev_err(dev, "failed to clear range irq: %d\n", ret); 160 - 161 - ret = i2c_smbus_read_byte_data(data->client, VL_REG_RESULT_INT_STATUS); 162 - if (ret < 0 || ret & 0x07) 163 - dev_err(dev, "failed to clear irq: %d\n", ret); 164 85 } 165 86 166 87 static int vl53l0x_read_proximity(struct vl53l0x_data *data, ··· 164 125 if (time_left == 0) 165 126 return -ETIMEDOUT; 166 127 167 - vl53l0x_clear_irq(data); 128 + ret = vl53l0x_clear_irq(data); 129 + if (ret < 0) 130 + return ret; 168 131 } else { 169 132 do { 170 133 ret = i2c_smbus_read_byte_data(client, ··· 191 150 return -EREMOTEIO; 192 151 193 152 /* Values should be between 30~1200 in millimeters. */ 194 - *val = (buffer[10] << 8) + buffer[11]; 153 + *val = get_unaligned_be16(&buffer[10]); 195 154 196 155 return 0; 197 156 } ··· 201 160 .type = IIO_DISTANCE, 202 161 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 203 162 BIT(IIO_CHAN_INFO_SCALE), 163 + .scan_index = 0, 164 + .scan_type = { 165 + .sign = 'u', 166 + .realbits = 12, 167 + .storagebits = 16, 168 + }, 204 169 }, 170 + IIO_CHAN_SOFT_TIMESTAMP(1), 205 171 }; 206 172 207 173 static int vl53l0x_read_raw(struct iio_dev *indio_dev, ··· 238 190 } 239 191 } 240 192 193 + static int vl53l0x_validate_trigger(struct iio_dev *indio_dev, struct iio_trigger *trig) 194 + { 195 + struct vl53l0x_data *data = iio_priv(indio_dev); 196 + 197 + return data->trig == trig ? 0 : -EINVAL; 198 + } 199 + 241 200 static const struct iio_info vl53l0x_info = { 242 201 .read_raw = vl53l0x_read_raw, 202 + .validate_trigger = vl53l0x_validate_trigger, 243 203 }; 244 204 245 205 static void vl53l0x_power_off(void *_data) ··· 274 218 return 0; 275 219 } 276 220 221 + static int vl53l0x_buffer_postenable(struct iio_dev *indio_dev) 222 + { 223 + struct vl53l0x_data *data = iio_priv(indio_dev); 224 + 225 + return i2c_smbus_write_byte_data(data->client, VL_REG_SYSRANGE_START, 226 + VL53L0X_CONTINUOUS_MODE); 227 + } 228 + 229 + static int vl53l0x_buffer_postdisable(struct iio_dev *indio_dev) 230 + { 231 + struct vl53l0x_data *data = iio_priv(indio_dev); 232 + int ret; 233 + 234 + ret = i2c_smbus_write_byte_data(data->client, VL_REG_SYSRANGE_START, 235 + VL53L0X_SINGLE_MODE); 236 + if (ret < 0) 237 + return ret; 238 + 239 + /* Let the ongoing reading finish */ 240 + reinit_completion(&data->completion); 241 + wait_for_completion_timeout(&data->completion, HZ / 10); 242 + 243 + return vl53l0x_clear_irq(data); 244 + } 245 + 246 + static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = { 247 + .postenable = &vl53l0x_buffer_postenable, 248 + .postdisable = &vl53l0x_buffer_postdisable, 249 + }; 250 + 251 + static const struct iio_trigger_ops vl53l0x_trigger_ops = { 252 + .validate_device = iio_trigger_validate_own_device, 253 + }; 254 + 277 255 static int vl53l0x_probe(struct i2c_client *client) 278 256 { 279 257 struct vl53l0x_data *data; 280 258 struct iio_dev *indio_dev; 281 259 int error; 260 + int ret; 282 261 283 262 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 284 263 if (!indio_dev) ··· 327 236 I2C_FUNC_SMBUS_READ_I2C_BLOCK | 328 237 I2C_FUNC_SMBUS_BYTE_DATA)) 329 238 return -EOPNOTSUPP; 239 + 240 + ret = i2c_smbus_read_byte_data(data->client, VL_REG_IDENTIFICATION_MODEL_ID); 241 + if (ret < 0) 242 + return -EINVAL; 243 + 244 + if (ret != VL53L0X_MODEL_ID_VAL) 245 + dev_info(&client->dev, "Unknown model id: 0x%x", ret); 330 246 331 247 data->vdd_supply = devm_regulator_get(&client->dev, "vdd"); 332 248 if (IS_ERR(data->vdd_supply)) ··· 363 265 364 266 /* usage of interrupt is optional */ 365 267 if (client->irq) { 366 - int ret; 367 - 368 268 init_completion(&data->completion); 369 269 270 + data->trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d", 271 + indio_dev->name, 272 + iio_device_id(indio_dev)); 273 + if (!data->trig) 274 + return -ENOMEM; 275 + 276 + data->trig->ops = &vl53l0x_trigger_ops; 277 + iio_trigger_set_drvdata(data->trig, indio_dev); 278 + ret = devm_iio_trigger_register(&client->dev, data->trig); 279 + if (ret) 280 + return ret; 281 + 282 + indio_dev->trig = iio_trigger_get(data->trig); 283 + 370 284 ret = vl53l0x_configure_irq(client, indio_dev); 285 + if (ret) 286 + return ret; 287 + 288 + ret = devm_iio_triggered_buffer_setup(&client->dev, 289 + indio_dev, 290 + NULL, 291 + &vl53l0x_trigger_handler, 292 + &iio_triggered_buffer_setup_ops); 371 293 if (ret) 372 294 return ret; 373 295 }
+2
drivers/iio/temperature/Kconfig
··· 91 91 config TMP006 92 92 tristate "TMP006 infrared thermopile sensor" 93 93 depends on I2C 94 + select IIO_BUFFER 95 + select IIO_TRIGGERED_BUFFER 94 96 help 95 97 If you say yes here you get support for the Texas Instruments 96 98 TMP006 infrared thermopile sensor.
+2 -2
drivers/iio/temperature/hid-sensor-temperature.c
··· 18 18 struct hid_sensor_hub_attribute_info temperature_attr; 19 19 struct { 20 20 s32 temperature_data; 21 - u64 timestamp __aligned(8); 21 + aligned_s64 timestamp; 22 22 } scan; 23 23 int scale_pre_decml; 24 24 int scale_post_decml; ··· 283 283 .pm = &hid_sensor_pm_ops, 284 284 }, 285 285 .probe = hid_temperature_probe, 286 - .remove_new = hid_temperature_remove, 286 + .remove = hid_temperature_remove, 287 287 }; 288 288 module_platform_driver(hid_temperature_platform_driver); 289 289
+121 -13
drivers/iio/temperature/tmp006.c
··· 7 7 * Driver for the Texas Instruments I2C 16-bit IR thermopile sensor 8 8 * 9 9 * (7-bit I2C slave address 0x40, changeable via ADR pins) 10 - * 11 - * TODO: data ready irq 12 10 */ 13 11 14 12 #include <linux/err.h> ··· 19 21 20 22 #include <linux/iio/iio.h> 21 23 #include <linux/iio/sysfs.h> 24 + #include <linux/iio/trigger.h> 25 + #include <linux/iio/triggered_buffer.h> 26 + #include <linux/iio/trigger_consumer.h> 22 27 23 28 #define TMP006_VOBJECT 0x00 24 29 #define TMP006_TAMBIENT 0x01 ··· 46 45 struct tmp006_data { 47 46 struct i2c_client *client; 48 47 u16 config; 48 + struct iio_trigger *drdy_trig; 49 49 }; 50 50 51 51 static int tmp006_read_measurement(struct tmp006_data *data, u8 reg) ··· 85 83 case IIO_CHAN_INFO_RAW: 86 84 if (channel->type == IIO_VOLTAGE) { 87 85 /* LSB is 156.25 nV */ 88 - ret = tmp006_read_measurement(data, TMP006_VOBJECT); 89 - if (ret < 0) 90 - return ret; 86 + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 87 + ret = tmp006_read_measurement(data, TMP006_VOBJECT); 88 + if (ret < 0) 89 + return ret; 90 + } 91 91 *val = sign_extend32(ret, 15); 92 92 } else if (channel->type == IIO_TEMP) { 93 93 /* LSB is 0.03125 degrees Celsius */ 94 - ret = tmp006_read_measurement(data, TMP006_TAMBIENT); 95 - if (ret < 0) 96 - return ret; 94 + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 95 + ret = tmp006_read_measurement(data, TMP006_TAMBIENT); 96 + if (ret < 0) 97 + return ret; 98 + } 97 99 *val = sign_extend32(ret, 15) >> TMP006_TAMBIENT_SHIFT; 98 100 } else { 99 101 break; ··· 134 128 long mask) 135 129 { 136 130 struct tmp006_data *data = iio_priv(indio_dev); 137 - int i; 131 + int ret, i; 138 132 139 133 if (mask != IIO_CHAN_INFO_SAMP_FREQ) 140 134 return -EINVAL; ··· 142 136 for (i = 0; i < ARRAY_SIZE(tmp006_freqs); i++) 143 137 if ((val == tmp006_freqs[i][0]) && 144 138 (val2 == tmp006_freqs[i][1])) { 139 + ret = iio_device_claim_direct_mode(indio_dev); 140 + if (ret) 141 + return ret; 142 + 145 143 data->config &= ~TMP006_CONFIG_CR_MASK; 146 144 data->config |= i << TMP006_CONFIG_CR_SHIFT; 147 145 148 - return i2c_smbus_write_word_swapped(data->client, 149 - TMP006_CONFIG, 150 - data->config); 146 + ret = i2c_smbus_write_word_swapped(data->client, 147 + TMP006_CONFIG, 148 + data->config); 151 149 150 + iio_device_release_direct_mode(indio_dev); 151 + return ret; 152 152 } 153 153 return -EINVAL; 154 154 } ··· 176 164 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 177 165 BIT(IIO_CHAN_INFO_SCALE), 178 166 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 167 + .scan_index = 0, 168 + .scan_type = { 169 + .sign = 's', 170 + .realbits = 16, 171 + .storagebits = 16, 172 + .endianness = IIO_BE, 173 + } 179 174 }, 180 175 { 181 176 .type = IIO_TEMP, 182 177 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 183 178 BIT(IIO_CHAN_INFO_SCALE), 184 179 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 185 - } 180 + .scan_index = 1, 181 + .scan_type = { 182 + .sign = 's', 183 + .realbits = 14, 184 + .storagebits = 16, 185 + .shift = TMP006_TAMBIENT_SHIFT, 186 + .endianness = IIO_BE, 187 + } 188 + }, 189 + IIO_CHAN_SOFT_TIMESTAMP(2), 186 190 }; 187 191 188 192 static const struct iio_info tmp006_info = { ··· 241 213 tmp006_power(dev, false); 242 214 } 243 215 216 + static irqreturn_t tmp006_trigger_handler(int irq, void *p) 217 + { 218 + struct iio_poll_func *pf = p; 219 + struct iio_dev *indio_dev = pf->indio_dev; 220 + struct tmp006_data *data = iio_priv(indio_dev); 221 + struct { 222 + s16 channels[2]; 223 + s64 ts __aligned(8); 224 + } scan; 225 + s32 ret; 226 + 227 + ret = i2c_smbus_read_word_data(data->client, TMP006_VOBJECT); 228 + if (ret < 0) 229 + goto err; 230 + scan.channels[0] = ret; 231 + 232 + ret = i2c_smbus_read_word_data(data->client, TMP006_TAMBIENT); 233 + if (ret < 0) 234 + goto err; 235 + scan.channels[1] = ret; 236 + 237 + iio_push_to_buffers_with_timestamp(indio_dev, &scan, 238 + iio_get_time_ns(indio_dev)); 239 + err: 240 + iio_trigger_notify_done(indio_dev->trig); 241 + return IRQ_HANDLED; 242 + } 243 + 244 + static int tmp006_set_trigger_state(struct iio_trigger *trig, bool state) 245 + { 246 + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 247 + struct tmp006_data *data = iio_priv(indio_dev); 248 + 249 + if (state) 250 + data->config |= TMP006_CONFIG_DRDY_EN; 251 + else 252 + data->config &= ~TMP006_CONFIG_DRDY_EN; 253 + 254 + return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, 255 + data->config); 256 + } 257 + 258 + static const struct iio_trigger_ops tmp006_trigger_ops = { 259 + .set_trigger_state = tmp006_set_trigger_state, 260 + }; 261 + 262 + static const unsigned long tmp006_scan_masks[] = { 0x3, 0 }; 263 + 244 264 static int tmp006_probe(struct i2c_client *client) 245 265 { 246 266 struct iio_dev *indio_dev; ··· 317 241 318 242 indio_dev->channels = tmp006_channels; 319 243 indio_dev->num_channels = ARRAY_SIZE(tmp006_channels); 244 + indio_dev->available_scan_masks = tmp006_scan_masks; 320 245 321 246 ret = i2c_smbus_read_word_swapped(data->client, TMP006_CONFIG); 322 247 if (ret < 0) ··· 332 255 333 256 ret = devm_add_action_or_reset(&client->dev, tmp006_powerdown_cleanup, 334 257 &client->dev); 258 + if (ret < 0) 259 + return ret; 260 + 261 + if (client->irq > 0) { 262 + data->drdy_trig = devm_iio_trigger_alloc(&client->dev, 263 + "%s-dev%d", 264 + indio_dev->name, 265 + iio_device_id(indio_dev)); 266 + if (!data->drdy_trig) 267 + return -ENOMEM; 268 + 269 + data->drdy_trig->ops = &tmp006_trigger_ops; 270 + iio_trigger_set_drvdata(data->drdy_trig, indio_dev); 271 + ret = iio_trigger_register(data->drdy_trig); 272 + if (ret) 273 + return ret; 274 + 275 + indio_dev->trig = iio_trigger_get(data->drdy_trig); 276 + 277 + ret = devm_request_threaded_irq(&client->dev, client->irq, 278 + iio_trigger_generic_data_rdy_poll, 279 + NULL, 280 + IRQF_ONESHOT, 281 + "tmp006_irq", 282 + data->drdy_trig); 283 + if (ret < 0) 284 + return ret; 285 + } 286 + 287 + ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, 288 + tmp006_trigger_handler, NULL); 335 289 if (ret < 0) 336 290 return ret; 337 291
+1 -1
drivers/iio/trigger/iio-trig-interrupt.c
··· 96 96 97 97 static struct platform_driver iio_interrupt_trigger_driver = { 98 98 .probe = iio_interrupt_trigger_probe, 99 - .remove_new = iio_interrupt_trigger_remove, 99 + .remove = iio_interrupt_trigger_remove, 100 100 .driver = { 101 101 .name = "iio_interrupt_trigger", 102 102 },
+1 -1
drivers/iio/trigger/stm32-timer-trigger.c
··· 900 900 901 901 static struct platform_driver stm32_timer_trigger_driver = { 902 902 .probe = stm32_timer_trigger_probe, 903 - .remove_new = stm32_timer_trigger_remove, 903 + .remove = stm32_timer_trigger_remove, 904 904 .driver = { 905 905 .name = "stm32-timer-trigger", 906 906 .of_match_table = stm32_trig_of_match,
+705 -152
drivers/pwm/core.c
··· 31 31 32 32 static DEFINE_IDR(pwm_chips); 33 33 34 + static void pwmchip_lock(struct pwm_chip *chip) 35 + { 36 + if (chip->atomic) 37 + spin_lock(&chip->atomic_lock); 38 + else 39 + mutex_lock(&chip->nonatomic_lock); 40 + } 41 + 42 + static void pwmchip_unlock(struct pwm_chip *chip) 43 + { 44 + if (chip->atomic) 45 + spin_unlock(&chip->atomic_lock); 46 + else 47 + mutex_unlock(&chip->nonatomic_lock); 48 + } 49 + 50 + DEFINE_GUARD(pwmchip, struct pwm_chip *, pwmchip_lock(_T), pwmchip_unlock(_T)) 51 + 52 + static bool pwm_wf_valid(const struct pwm_waveform *wf) 53 + { 54 + /* 55 + * For now restrict waveforms to period_length_ns <= S64_MAX to provide 56 + * some space for future extensions. One possibility is to simplify 57 + * representing waveforms with inverted polarity using negative values 58 + * somehow. 59 + */ 60 + if (wf->period_length_ns > S64_MAX) 61 + return false; 62 + 63 + if (wf->duty_length_ns > wf->period_length_ns) 64 + return false; 65 + 66 + /* 67 + * .duty_offset_ns is supposed to be smaller than .period_length_ns, apart 68 + * from the corner case .duty_offset_ns == 0 && .period_length_ns == 0. 69 + */ 70 + if (wf->duty_offset_ns && wf->duty_offset_ns >= wf->period_length_ns) 71 + return false; 72 + 73 + return true; 74 + } 75 + 76 + static void pwm_wf2state(const struct pwm_waveform *wf, struct pwm_state *state) 77 + { 78 + if (wf->period_length_ns) { 79 + if (wf->duty_length_ns + wf->duty_offset_ns < wf->period_length_ns) 80 + *state = (struct pwm_state){ 81 + .enabled = true, 82 + .polarity = PWM_POLARITY_NORMAL, 83 + .period = wf->period_length_ns, 84 + .duty_cycle = wf->duty_length_ns, 85 + }; 86 + else 87 + *state = (struct pwm_state){ 88 + .enabled = true, 89 + .polarity = PWM_POLARITY_INVERSED, 90 + .period = wf->period_length_ns, 91 + .duty_cycle = wf->period_length_ns - wf->duty_length_ns, 92 + }; 93 + } else { 94 + *state = (struct pwm_state){ 95 + .enabled = false, 96 + }; 97 + } 98 + } 99 + 100 + static void pwm_state2wf(const struct pwm_state *state, struct pwm_waveform *wf) 101 + { 102 + if (state->enabled) { 103 + if (state->polarity == PWM_POLARITY_NORMAL) 104 + *wf = (struct pwm_waveform){ 105 + .period_length_ns = state->period, 106 + .duty_length_ns = state->duty_cycle, 107 + .duty_offset_ns = 0, 108 + }; 109 + else 110 + *wf = (struct pwm_waveform){ 111 + .period_length_ns = state->period, 112 + .duty_length_ns = state->period - state->duty_cycle, 113 + .duty_offset_ns = state->duty_cycle, 114 + }; 115 + } else { 116 + *wf = (struct pwm_waveform){ 117 + .period_length_ns = 0, 118 + }; 119 + } 120 + } 121 + 122 + static int pwmwfcmp(const struct pwm_waveform *a, const struct pwm_waveform *b) 123 + { 124 + if (a->period_length_ns > b->period_length_ns) 125 + return 1; 126 + 127 + if (a->period_length_ns < b->period_length_ns) 128 + return -1; 129 + 130 + if (a->duty_length_ns > b->duty_length_ns) 131 + return 1; 132 + 133 + if (a->duty_length_ns < b->duty_length_ns) 134 + return -1; 135 + 136 + if (a->duty_offset_ns > b->duty_offset_ns) 137 + return 1; 138 + 139 + if (a->duty_offset_ns < b->duty_offset_ns) 140 + return -1; 141 + 142 + return 0; 143 + } 144 + 145 + static bool pwm_check_rounding(const struct pwm_waveform *wf, 146 + const struct pwm_waveform *wf_rounded) 147 + { 148 + if (!wf->period_length_ns) 149 + return true; 150 + 151 + if (wf->period_length_ns < wf_rounded->period_length_ns) 152 + return false; 153 + 154 + if (wf->duty_length_ns < wf_rounded->duty_length_ns) 155 + return false; 156 + 157 + if (wf->duty_offset_ns < wf_rounded->duty_offset_ns) 158 + return false; 159 + 160 + return true; 161 + } 162 + 163 + static int __pwm_round_waveform_tohw(struct pwm_chip *chip, struct pwm_device *pwm, 164 + const struct pwm_waveform *wf, void *wfhw) 165 + { 166 + const struct pwm_ops *ops = chip->ops; 167 + int ret; 168 + 169 + ret = ops->round_waveform_tohw(chip, pwm, wf, wfhw); 170 + trace_pwm_round_waveform_tohw(pwm, wf, wfhw, ret); 171 + 172 + return ret; 173 + } 174 + 175 + static int __pwm_round_waveform_fromhw(struct pwm_chip *chip, struct pwm_device *pwm, 176 + const void *wfhw, struct pwm_waveform *wf) 177 + { 178 + const struct pwm_ops *ops = chip->ops; 179 + int ret; 180 + 181 + ret = ops->round_waveform_fromhw(chip, pwm, wfhw, wf); 182 + trace_pwm_round_waveform_fromhw(pwm, wfhw, wf, ret); 183 + 184 + return ret; 185 + } 186 + 187 + static int __pwm_read_waveform(struct pwm_chip *chip, struct pwm_device *pwm, void *wfhw) 188 + { 189 + const struct pwm_ops *ops = chip->ops; 190 + int ret; 191 + 192 + ret = ops->read_waveform(chip, pwm, wfhw); 193 + trace_pwm_read_waveform(pwm, wfhw, ret); 194 + 195 + return ret; 196 + } 197 + 198 + static int __pwm_write_waveform(struct pwm_chip *chip, struct pwm_device *pwm, const void *wfhw) 199 + { 200 + const struct pwm_ops *ops = chip->ops; 201 + int ret; 202 + 203 + ret = ops->write_waveform(chip, pwm, wfhw); 204 + trace_pwm_write_waveform(pwm, wfhw, ret); 205 + 206 + return ret; 207 + } 208 + 209 + #define WFHWSIZE 20 210 + 211 + /** 212 + * pwm_round_waveform_might_sleep - Query hardware capabilities 213 + * Cannot be used in atomic context. 214 + * @pwm: PWM device 215 + * @wf: waveform to round and output parameter 216 + * 217 + * Typically a given waveform cannot be implemented exactly by hardware, e.g. 218 + * because hardware only supports coarse period resolution or no duty_offset. 219 + * This function returns the actually implemented waveform if you pass wf to 220 + * pwm_set_waveform_might_sleep now. 221 + * 222 + * Note however that the world doesn't stop turning when you call it, so when 223 + * doing 224 + * 225 + * pwm_round_waveform_might_sleep(mypwm, &wf); 226 + * pwm_set_waveform_might_sleep(mypwm, &wf, true); 227 + * 228 + * the latter might fail, e.g. because an input clock changed its rate between 229 + * these two calls and the waveform determined by 230 + * pwm_round_waveform_might_sleep() cannot be implemented any more. 231 + * 232 + * Returns 0 on success, 1 if there is no valid hardware configuration matching 233 + * the input waveform under the PWM rounding rules or a negative errno. 234 + */ 235 + int pwm_round_waveform_might_sleep(struct pwm_device *pwm, struct pwm_waveform *wf) 236 + { 237 + struct pwm_chip *chip = pwm->chip; 238 + const struct pwm_ops *ops = chip->ops; 239 + struct pwm_waveform wf_req = *wf; 240 + char wfhw[WFHWSIZE]; 241 + int ret_tohw, ret_fromhw; 242 + 243 + BUG_ON(WFHWSIZE < ops->sizeof_wfhw); 244 + 245 + if (!pwm_wf_valid(wf)) 246 + return -EINVAL; 247 + 248 + guard(pwmchip)(chip); 249 + 250 + if (!chip->operational) 251 + return -ENODEV; 252 + 253 + ret_tohw = __pwm_round_waveform_tohw(chip, pwm, wf, wfhw); 254 + if (ret_tohw < 0) 255 + return ret_tohw; 256 + 257 + if (IS_ENABLED(CONFIG_PWM_DEBUG) && ret_tohw > 1) 258 + dev_err(&chip->dev, "Unexpected return value from __pwm_round_waveform_tohw: requested %llu/%llu [+%llu], return value %d\n", 259 + wf_req.duty_length_ns, wf_req.period_length_ns, wf_req.duty_offset_ns, ret_tohw); 260 + 261 + ret_fromhw = __pwm_round_waveform_fromhw(chip, pwm, wfhw, wf); 262 + if (ret_fromhw < 0) 263 + return ret_fromhw; 264 + 265 + if (IS_ENABLED(CONFIG_PWM_DEBUG) && ret_fromhw > 0) 266 + dev_err(&chip->dev, "Unexpected return value from __pwm_round_waveform_fromhw: requested %llu/%llu [+%llu], return value %d\n", 267 + wf_req.duty_length_ns, wf_req.period_length_ns, wf_req.duty_offset_ns, ret_tohw); 268 + 269 + if (IS_ENABLED(CONFIG_PWM_DEBUG) && 270 + ret_tohw == 0 && !pwm_check_rounding(&wf_req, wf)) 271 + dev_err(&chip->dev, "Wrong rounding: requested %llu/%llu [+%llu], result %llu/%llu [+%llu]\n", 272 + wf_req.duty_length_ns, wf_req.period_length_ns, wf_req.duty_offset_ns, 273 + wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns); 274 + 275 + return ret_tohw; 276 + } 277 + EXPORT_SYMBOL_GPL(pwm_round_waveform_might_sleep); 278 + 279 + /** 280 + * pwm_get_waveform_might_sleep - Query hardware about current configuration 281 + * Cannot be used in atomic context. 282 + * @pwm: PWM device 283 + * @wf: output parameter 284 + * 285 + * Stores the current configuration of the PWM in @wf. Note this is the 286 + * equivalent of pwm_get_state_hw() (and not pwm_get_state()) for pwm_waveform. 287 + */ 288 + int pwm_get_waveform_might_sleep(struct pwm_device *pwm, struct pwm_waveform *wf) 289 + { 290 + struct pwm_chip *chip = pwm->chip; 291 + const struct pwm_ops *ops = chip->ops; 292 + char wfhw[WFHWSIZE]; 293 + int err; 294 + 295 + BUG_ON(WFHWSIZE < ops->sizeof_wfhw); 296 + 297 + guard(pwmchip)(chip); 298 + 299 + if (!chip->operational) 300 + return -ENODEV; 301 + 302 + err = __pwm_read_waveform(chip, pwm, &wfhw); 303 + if (err) 304 + return err; 305 + 306 + return __pwm_round_waveform_fromhw(chip, pwm, &wfhw, wf); 307 + } 308 + EXPORT_SYMBOL_GPL(pwm_get_waveform_might_sleep); 309 + 310 + /* Called with the pwmchip lock held */ 311 + static int __pwm_set_waveform(struct pwm_device *pwm, 312 + const struct pwm_waveform *wf, 313 + bool exact) 314 + { 315 + struct pwm_chip *chip = pwm->chip; 316 + const struct pwm_ops *ops = chip->ops; 317 + char wfhw[WFHWSIZE]; 318 + struct pwm_waveform wf_rounded; 319 + int err; 320 + 321 + BUG_ON(WFHWSIZE < ops->sizeof_wfhw); 322 + 323 + if (!pwm_wf_valid(wf)) 324 + return -EINVAL; 325 + 326 + err = __pwm_round_waveform_tohw(chip, pwm, wf, &wfhw); 327 + if (err) 328 + return err; 329 + 330 + if ((IS_ENABLED(CONFIG_PWM_DEBUG) || exact) && wf->period_length_ns) { 331 + err = __pwm_round_waveform_fromhw(chip, pwm, &wfhw, &wf_rounded); 332 + if (err) 333 + return err; 334 + 335 + if (IS_ENABLED(CONFIG_PWM_DEBUG) && !pwm_check_rounding(wf, &wf_rounded)) 336 + dev_err(&chip->dev, "Wrong rounding: requested %llu/%llu [+%llu], result %llu/%llu [+%llu]\n", 337 + wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns, 338 + wf_rounded.duty_length_ns, wf_rounded.period_length_ns, wf_rounded.duty_offset_ns); 339 + 340 + if (exact && pwmwfcmp(wf, &wf_rounded)) { 341 + dev_dbg(&chip->dev, "Requested no rounding, but %llu/%llu [+%llu] -> %llu/%llu [+%llu]\n", 342 + wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns, 343 + wf_rounded.duty_length_ns, wf_rounded.period_length_ns, wf_rounded.duty_offset_ns); 344 + 345 + return 1; 346 + } 347 + } 348 + 349 + err = __pwm_write_waveform(chip, pwm, &wfhw); 350 + if (err) 351 + return err; 352 + 353 + /* update .state */ 354 + pwm_wf2state(wf, &pwm->state); 355 + 356 + if (IS_ENABLED(CONFIG_PWM_DEBUG) && ops->read_waveform && wf->period_length_ns) { 357 + struct pwm_waveform wf_set; 358 + 359 + err = __pwm_read_waveform(chip, pwm, &wfhw); 360 + if (err) 361 + /* maybe ignore? */ 362 + return err; 363 + 364 + err = __pwm_round_waveform_fromhw(chip, pwm, &wfhw, &wf_set); 365 + if (err) 366 + /* maybe ignore? */ 367 + return err; 368 + 369 + if (pwmwfcmp(&wf_set, &wf_rounded) != 0) 370 + dev_err(&chip->dev, 371 + "Unexpected setting: requested %llu/%llu [+%llu], expected %llu/%llu [+%llu], set %llu/%llu [+%llu]\n", 372 + wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns, 373 + wf_rounded.duty_length_ns, wf_rounded.period_length_ns, wf_rounded.duty_offset_ns, 374 + wf_set.duty_length_ns, wf_set.period_length_ns, wf_set.duty_offset_ns); 375 + } 376 + return 0; 377 + } 378 + 379 + /** 380 + * pwm_set_waveform_might_sleep - Apply a new waveform 381 + * Cannot be used in atomic context. 382 + * @pwm: PWM device 383 + * @wf: The waveform to apply 384 + * @exact: If true no rounding is allowed 385 + * 386 + * Typically a requested waveform cannot be implemented exactly, e.g. because 387 + * you requested .period_length_ns = 100 ns, but the hardware can only set 388 + * periods that are a multiple of 8.5 ns. With that hardware passing exact = 389 + * true results in pwm_set_waveform_might_sleep() failing and returning 1. If 390 + * exact = false you get a period of 93.5 ns (i.e. the biggest period not bigger 391 + * than the requested value). 392 + * Note that even with exact = true, some rounding by less than 1 is 393 + * possible/needed. In the above example requesting .period_length_ns = 94 and 394 + * exact = true, you get the hardware configured with period = 93.5 ns. 395 + */ 396 + int pwm_set_waveform_might_sleep(struct pwm_device *pwm, 397 + const struct pwm_waveform *wf, bool exact) 398 + { 399 + struct pwm_chip *chip = pwm->chip; 400 + int err; 401 + 402 + might_sleep(); 403 + 404 + guard(pwmchip)(chip); 405 + 406 + if (!chip->operational) 407 + return -ENODEV; 408 + 409 + if (IS_ENABLED(CONFIG_PWM_DEBUG) && chip->atomic) { 410 + /* 411 + * Catch any drivers that have been marked as atomic but 412 + * that will sleep anyway. 413 + */ 414 + non_block_start(); 415 + err = __pwm_set_waveform(pwm, wf, exact); 416 + non_block_end(); 417 + } else { 418 + err = __pwm_set_waveform(pwm, wf, exact); 419 + } 420 + 421 + return err; 422 + } 423 + EXPORT_SYMBOL_GPL(pwm_set_waveform_might_sleep); 424 + 34 425 static void pwm_apply_debug(struct pwm_device *pwm, 35 426 const struct pwm_state *state) 36 427 { ··· 555 164 static int __pwm_apply(struct pwm_device *pwm, const struct pwm_state *state) 556 165 { 557 166 struct pwm_chip *chip; 167 + const struct pwm_ops *ops; 558 168 int err; 559 169 560 170 if (!pwm || !state) ··· 579 187 } 580 188 581 189 chip = pwm->chip; 190 + ops = chip->ops; 582 191 583 192 if (state->period == pwm->state.period && 584 193 state->duty_cycle == pwm->state.duty_cycle && ··· 588 195 state->usage_power == pwm->state.usage_power) 589 196 return 0; 590 197 591 - err = chip->ops->apply(chip, pwm, state); 592 - trace_pwm_apply(pwm, state, err); 593 - if (err) 594 - return err; 198 + if (ops->write_waveform) { 199 + struct pwm_waveform wf; 200 + char wfhw[WFHWSIZE]; 595 201 596 - pwm->state = *state; 202 + BUG_ON(WFHWSIZE < ops->sizeof_wfhw); 597 203 598 - /* 599 - * only do this after pwm->state was applied as some 600 - * implementations of .get_state depend on this 601 - */ 602 - pwm_apply_debug(pwm, state); 204 + pwm_state2wf(state, &wf); 205 + 206 + /* 207 + * The rounding is wrong here for states with inverted polarity. 208 + * While .apply() rounds down duty_cycle (which represents the 209 + * time from the start of the period to the inner edge), 210 + * .round_waveform_tohw() rounds down the time the PWM is high. 211 + * Can be fixed if the need arises, until reported otherwise 212 + * let's assume that consumers don't care. 213 + */ 214 + 215 + err = __pwm_round_waveform_tohw(chip, pwm, &wf, &wfhw); 216 + if (err) { 217 + if (err > 0) 218 + /* 219 + * This signals an invalid request, typically 220 + * the requested period (or duty_offset) is 221 + * smaller than possible with the hardware. 222 + */ 223 + return -EINVAL; 224 + 225 + return err; 226 + } 227 + 228 + if (IS_ENABLED(CONFIG_PWM_DEBUG)) { 229 + struct pwm_waveform wf_rounded; 230 + 231 + err = __pwm_round_waveform_fromhw(chip, pwm, &wfhw, &wf_rounded); 232 + if (err) 233 + return err; 234 + 235 + if (!pwm_check_rounding(&wf, &wf_rounded)) 236 + dev_err(&chip->dev, "Wrong rounding: requested %llu/%llu [+%llu], result %llu/%llu [+%llu]\n", 237 + wf.duty_length_ns, wf.period_length_ns, wf.duty_offset_ns, 238 + wf_rounded.duty_length_ns, wf_rounded.period_length_ns, wf_rounded.duty_offset_ns); 239 + } 240 + 241 + err = __pwm_write_waveform(chip, pwm, &wfhw); 242 + if (err) 243 + return err; 244 + 245 + pwm->state = *state; 246 + 247 + } else { 248 + err = ops->apply(chip, pwm, state); 249 + trace_pwm_apply(pwm, state, err); 250 + if (err) 251 + return err; 252 + 253 + pwm->state = *state; 254 + 255 + /* 256 + * only do this after pwm->state was applied as some 257 + * implementations of .get_state() depend on this 258 + */ 259 + pwm_apply_debug(pwm, state); 260 + } 603 261 604 262 return 0; 605 263 } ··· 664 220 int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state) 665 221 { 666 222 int err; 223 + struct pwm_chip *chip = pwm->chip; 667 224 668 225 /* 669 226 * Some lowlevel driver's implementations of .apply() make use of ··· 675 230 */ 676 231 might_sleep(); 677 232 678 - if (IS_ENABLED(CONFIG_PWM_DEBUG) && pwm->chip->atomic) { 233 + guard(pwmchip)(chip); 234 + 235 + if (!chip->operational) 236 + return -ENODEV; 237 + 238 + if (IS_ENABLED(CONFIG_PWM_DEBUG) && chip->atomic) { 679 239 /* 680 240 * Catch any drivers that have been marked as atomic but 681 241 * that will sleep anyway. ··· 704 254 */ 705 255 int pwm_apply_atomic(struct pwm_device *pwm, const struct pwm_state *state) 706 256 { 707 - WARN_ONCE(!pwm->chip->atomic, 257 + struct pwm_chip *chip = pwm->chip; 258 + 259 + WARN_ONCE(!chip->atomic, 708 260 "sleeping PWM driver used in atomic context\n"); 261 + 262 + guard(pwmchip)(chip); 263 + 264 + if (!chip->operational) 265 + return -ENODEV; 709 266 710 267 return __pwm_apply(pwm, state); 711 268 } 712 269 EXPORT_SYMBOL_GPL(pwm_apply_atomic); 270 + 271 + static int pwm_get_state_hw(struct pwm_device *pwm, struct pwm_state *state) 272 + { 273 + struct pwm_chip *chip = pwm->chip; 274 + const struct pwm_ops *ops = chip->ops; 275 + int ret = -EOPNOTSUPP; 276 + 277 + if (ops->read_waveform) { 278 + char wfhw[WFHWSIZE]; 279 + struct pwm_waveform wf; 280 + 281 + BUG_ON(WFHWSIZE < ops->sizeof_wfhw); 282 + 283 + scoped_guard(pwmchip, chip) { 284 + 285 + ret = __pwm_read_waveform(chip, pwm, &wfhw); 286 + if (ret) 287 + return ret; 288 + 289 + ret = __pwm_round_waveform_fromhw(chip, pwm, &wfhw, &wf); 290 + if (ret) 291 + return ret; 292 + } 293 + 294 + pwm_wf2state(&wf, state); 295 + 296 + } else if (ops->get_state) { 297 + scoped_guard(pwmchip, chip) 298 + ret = ops->get_state(chip, pwm, state); 299 + 300 + trace_pwm_get(pwm, state, ret); 301 + } 302 + 303 + return ret; 304 + } 713 305 714 306 /** 715 307 * pwm_adjust_config() - adjust the current PWM config to the PWM arguments ··· 826 334 if (!ops->capture) 827 335 return -ENOSYS; 828 336 337 + /* 338 + * Holding the pwm_lock is probably not needed. If you use pwm_capture() 339 + * and you're interested to speed it up, please convince yourself it's 340 + * really not needed, test and then suggest a patch on the mailing list. 341 + */ 829 342 guard(mutex)(&pwm_lock); 343 + 344 + guard(pwmchip)(chip); 345 + 346 + if (!chip->operational) 347 + return -ENODEV; 830 348 831 349 return ops->capture(chip, pwm, result, timeout); 832 350 } ··· 870 368 if (test_bit(PWMF_REQUESTED, &pwm->flags)) 871 369 return -EBUSY; 872 370 371 + /* 372 + * This function is called while holding pwm_lock. As .operational only 373 + * changes while holding this lock, checking it here without holding the 374 + * chip lock is fine. 375 + */ 376 + if (!chip->operational) 377 + return -ENODEV; 378 + 873 379 if (!try_module_get(chip->owner)) 874 380 return -ENODEV; 875 381 ··· 896 386 } 897 387 } 898 388 899 - if (ops->get_state) { 389 + if (ops->read_waveform || ops->get_state) { 900 390 /* 901 391 * Zero-initialize state because most drivers are unaware of 902 392 * .usage_power. The other members of state are supposed to be ··· 906 396 */ 907 397 struct pwm_state state = { 0, }; 908 398 909 - err = ops->get_state(chip, pwm, &state); 910 - trace_pwm_get(pwm, &state, err); 911 - 399 + err = pwm_get_state_hw(pwm, &state); 912 400 if (!err) 913 401 pwm->state = state; 914 402 ··· 1528 1020 1529 1021 chip->npwm = npwm; 1530 1022 chip->uses_pwmchip_alloc = true; 1023 + chip->operational = false; 1531 1024 1532 1025 pwmchip_dev = &chip->dev; 1533 1026 device_initialize(pwmchip_dev); ··· 1593 1084 { 1594 1085 const struct pwm_ops *ops = chip->ops; 1595 1086 1596 - if (!ops->apply) 1597 - return false; 1087 + if (ops->write_waveform) { 1088 + if (!ops->round_waveform_tohw || 1089 + !ops->round_waveform_fromhw || 1090 + !ops->write_waveform) 1091 + return false; 1598 1092 1599 - if (IS_ENABLED(CONFIG_PWM_DEBUG) && !ops->get_state) 1600 - dev_warn(pwmchip_parent(chip), 1601 - "Please implement the .get_state() callback\n"); 1093 + if (WFHWSIZE < ops->sizeof_wfhw) { 1094 + dev_warn(pwmchip_parent(chip), "WFHWSIZE < %zu\n", ops->sizeof_wfhw); 1095 + return false; 1096 + } 1097 + } else { 1098 + if (!ops->apply) 1099 + return false; 1100 + 1101 + if (IS_ENABLED(CONFIG_PWM_DEBUG) && !ops->get_state) 1102 + dev_warn(pwmchip_parent(chip), 1103 + "Please implement the .get_state() callback\n"); 1104 + } 1602 1105 1603 1106 return true; 1604 1107 } 1605 - 1606 - /** 1607 - * __pwmchip_add() - register a new PWM chip 1608 - * @chip: the PWM chip to add 1609 - * @owner: reference to the module providing the chip. 1610 - * 1611 - * Register a new PWM chip. @owner is supposed to be THIS_MODULE, use the 1612 - * pwmchip_add wrapper to do this right. 1613 - * 1614 - * Returns: 0 on success or a negative error code on failure. 1615 - */ 1616 - int __pwmchip_add(struct pwm_chip *chip, struct module *owner) 1617 - { 1618 - int ret; 1619 - 1620 - if (!chip || !pwmchip_parent(chip) || !chip->ops || !chip->npwm) 1621 - return -EINVAL; 1622 - 1623 - /* 1624 - * a struct pwm_chip must be allocated using (devm_)pwmchip_alloc, 1625 - * otherwise the embedded struct device might disappear too early 1626 - * resulting in memory corruption. 1627 - * Catch drivers that were not converted appropriately. 1628 - */ 1629 - if (!chip->uses_pwmchip_alloc) 1630 - return -EINVAL; 1631 - 1632 - if (!pwm_ops_check(chip)) 1633 - return -EINVAL; 1634 - 1635 - chip->owner = owner; 1636 - 1637 - guard(mutex)(&pwm_lock); 1638 - 1639 - ret = idr_alloc(&pwm_chips, chip, 0, 0, GFP_KERNEL); 1640 - if (ret < 0) 1641 - return ret; 1642 - 1643 - chip->id = ret; 1644 - 1645 - dev_set_name(&chip->dev, "pwmchip%u", chip->id); 1646 - 1647 - if (IS_ENABLED(CONFIG_OF)) 1648 - of_pwmchip_add(chip); 1649 - 1650 - ret = device_add(&chip->dev); 1651 - if (ret) 1652 - goto err_device_add; 1653 - 1654 - return 0; 1655 - 1656 - err_device_add: 1657 - if (IS_ENABLED(CONFIG_OF)) 1658 - of_pwmchip_remove(chip); 1659 - 1660 - idr_remove(&pwm_chips, chip->id); 1661 - 1662 - return ret; 1663 - } 1664 - EXPORT_SYMBOL_GPL(__pwmchip_add); 1665 - 1666 - /** 1667 - * pwmchip_remove() - remove a PWM chip 1668 - * @chip: the PWM chip to remove 1669 - * 1670 - * Removes a PWM chip. 1671 - */ 1672 - void pwmchip_remove(struct pwm_chip *chip) 1673 - { 1674 - pwmchip_sysfs_unexport(chip); 1675 - 1676 - if (IS_ENABLED(CONFIG_OF)) 1677 - of_pwmchip_remove(chip); 1678 - 1679 - scoped_guard(mutex, &pwm_lock) 1680 - idr_remove(&pwm_chips, chip->id); 1681 - 1682 - device_del(&chip->dev); 1683 - } 1684 - EXPORT_SYMBOL_GPL(pwmchip_remove); 1685 - 1686 - static void devm_pwmchip_remove(void *data) 1687 - { 1688 - struct pwm_chip *chip = data; 1689 - 1690 - pwmchip_remove(chip); 1691 - } 1692 - 1693 - int __devm_pwmchip_add(struct device *dev, struct pwm_chip *chip, struct module *owner) 1694 - { 1695 - int ret; 1696 - 1697 - ret = __pwmchip_add(chip, owner); 1698 - if (ret) 1699 - return ret; 1700 - 1701 - return devm_add_action_or_reset(dev, devm_pwmchip_remove, chip); 1702 - } 1703 - EXPORT_SYMBOL_GPL(__devm_pwmchip_add); 1704 1108 1705 1109 static struct device_link *pwm_device_link_add(struct device *dev, 1706 1110 struct pwm_device *pwm) ··· 1793 1371 static LIST_HEAD(pwm_lookup_list); 1794 1372 1795 1373 /** 1796 - * pwm_add_table() - register PWM device consumers 1797 - * @table: array of consumers to register 1798 - * @num: number of consumers in table 1799 - */ 1800 - void pwm_add_table(struct pwm_lookup *table, size_t num) 1801 - { 1802 - guard(mutex)(&pwm_lookup_lock); 1803 - 1804 - while (num--) { 1805 - list_add_tail(&table->list, &pwm_lookup_list); 1806 - table++; 1807 - } 1808 - } 1809 - 1810 - /** 1811 - * pwm_remove_table() - unregister PWM device consumers 1812 - * @table: array of consumers to unregister 1813 - * @num: number of consumers in table 1814 - */ 1815 - void pwm_remove_table(struct pwm_lookup *table, size_t num) 1816 - { 1817 - guard(mutex)(&pwm_lookup_lock); 1818 - 1819 - while (num--) { 1820 - list_del(&table->list); 1821 - table++; 1822 - } 1823 - } 1824 - 1825 - /** 1826 1374 * pwm_get() - look up and request a PWM device 1827 1375 * @dev: device for PWM consumer 1828 1376 * @con_id: consumer name ··· 1930 1538 1931 1539 guard(mutex)(&pwm_lock); 1932 1540 1933 - if (!test_and_clear_bit(PWMF_REQUESTED, &pwm->flags)) { 1541 + /* 1542 + * Trigger a warning if a consumer called pwm_put() twice. 1543 + * If the chip isn't operational, PWMF_REQUESTED was already cleared in 1544 + * pwmchip_remove(). So don't warn in this case. 1545 + */ 1546 + if (chip->operational && !test_and_clear_bit(PWMF_REQUESTED, &pwm->flags)) { 1934 1547 pr_warn("PWM device already freed\n"); 1935 1548 return; 1936 1549 } 1937 1550 1938 - if (chip->ops->free) 1551 + if (chip->operational && chip->ops->free) 1939 1552 pwm->chip->ops->free(pwm->chip, pwm); 1940 1553 1941 1554 pwm->label = NULL; ··· 2017 1620 return pwm; 2018 1621 } 2019 1622 EXPORT_SYMBOL_GPL(devm_fwnode_pwm_get); 1623 + 1624 + /** 1625 + * __pwmchip_add() - register a new PWM chip 1626 + * @chip: the PWM chip to add 1627 + * @owner: reference to the module providing the chip. 1628 + * 1629 + * Register a new PWM chip. @owner is supposed to be THIS_MODULE, use the 1630 + * pwmchip_add wrapper to do this right. 1631 + * 1632 + * Returns: 0 on success or a negative error code on failure. 1633 + */ 1634 + int __pwmchip_add(struct pwm_chip *chip, struct module *owner) 1635 + { 1636 + int ret; 1637 + 1638 + if (!chip || !pwmchip_parent(chip) || !chip->ops || !chip->npwm) 1639 + return -EINVAL; 1640 + 1641 + /* 1642 + * a struct pwm_chip must be allocated using (devm_)pwmchip_alloc, 1643 + * otherwise the embedded struct device might disappear too early 1644 + * resulting in memory corruption. 1645 + * Catch drivers that were not converted appropriately. 1646 + */ 1647 + if (!chip->uses_pwmchip_alloc) 1648 + return -EINVAL; 1649 + 1650 + if (!pwm_ops_check(chip)) 1651 + return -EINVAL; 1652 + 1653 + chip->owner = owner; 1654 + 1655 + if (chip->atomic) 1656 + spin_lock_init(&chip->atomic_lock); 1657 + else 1658 + mutex_init(&chip->nonatomic_lock); 1659 + 1660 + guard(mutex)(&pwm_lock); 1661 + 1662 + ret = idr_alloc(&pwm_chips, chip, 0, 0, GFP_KERNEL); 1663 + if (ret < 0) 1664 + return ret; 1665 + 1666 + chip->id = ret; 1667 + 1668 + dev_set_name(&chip->dev, "pwmchip%u", chip->id); 1669 + 1670 + if (IS_ENABLED(CONFIG_OF)) 1671 + of_pwmchip_add(chip); 1672 + 1673 + scoped_guard(pwmchip, chip) 1674 + chip->operational = true; 1675 + 1676 + ret = device_add(&chip->dev); 1677 + if (ret) 1678 + goto err_device_add; 1679 + 1680 + return 0; 1681 + 1682 + err_device_add: 1683 + scoped_guard(pwmchip, chip) 1684 + chip->operational = false; 1685 + 1686 + if (IS_ENABLED(CONFIG_OF)) 1687 + of_pwmchip_remove(chip); 1688 + 1689 + idr_remove(&pwm_chips, chip->id); 1690 + 1691 + return ret; 1692 + } 1693 + EXPORT_SYMBOL_GPL(__pwmchip_add); 1694 + 1695 + /** 1696 + * pwmchip_remove() - remove a PWM chip 1697 + * @chip: the PWM chip to remove 1698 + * 1699 + * Removes a PWM chip. 1700 + */ 1701 + void pwmchip_remove(struct pwm_chip *chip) 1702 + { 1703 + pwmchip_sysfs_unexport(chip); 1704 + 1705 + scoped_guard(mutex, &pwm_lock) { 1706 + unsigned int i; 1707 + 1708 + scoped_guard(pwmchip, chip) 1709 + chip->operational = false; 1710 + 1711 + for (i = 0; i < chip->npwm; ++i) { 1712 + struct pwm_device *pwm = &chip->pwms[i]; 1713 + 1714 + if (test_and_clear_bit(PWMF_REQUESTED, &pwm->flags)) { 1715 + dev_warn(&chip->dev, "Freeing requested PWM #%u\n", i); 1716 + if (pwm->chip->ops->free) 1717 + pwm->chip->ops->free(pwm->chip, pwm); 1718 + } 1719 + } 1720 + 1721 + if (IS_ENABLED(CONFIG_OF)) 1722 + of_pwmchip_remove(chip); 1723 + 1724 + idr_remove(&pwm_chips, chip->id); 1725 + } 1726 + 1727 + device_del(&chip->dev); 1728 + } 1729 + EXPORT_SYMBOL_GPL(pwmchip_remove); 1730 + 1731 + static void devm_pwmchip_remove(void *data) 1732 + { 1733 + struct pwm_chip *chip = data; 1734 + 1735 + pwmchip_remove(chip); 1736 + } 1737 + 1738 + int __devm_pwmchip_add(struct device *dev, struct pwm_chip *chip, struct module *owner) 1739 + { 1740 + int ret; 1741 + 1742 + ret = __pwmchip_add(chip, owner); 1743 + if (ret) 1744 + return ret; 1745 + 1746 + return devm_add_action_or_reset(dev, devm_pwmchip_remove, chip); 1747 + } 1748 + EXPORT_SYMBOL_GPL(__devm_pwmchip_add); 1749 + 1750 + /** 1751 + * pwm_add_table() - register PWM device consumers 1752 + * @table: array of consumers to register 1753 + * @num: number of consumers in table 1754 + */ 1755 + void pwm_add_table(struct pwm_lookup *table, size_t num) 1756 + { 1757 + guard(mutex)(&pwm_lookup_lock); 1758 + 1759 + while (num--) { 1760 + list_add_tail(&table->list, &pwm_lookup_list); 1761 + table++; 1762 + } 1763 + } 1764 + 1765 + /** 1766 + * pwm_remove_table() - unregister PWM device consumers 1767 + * @table: array of consumers to unregister 1768 + * @num: number of consumers in table 1769 + */ 1770 + void pwm_remove_table(struct pwm_lookup *table, size_t num) 1771 + { 1772 + guard(mutex)(&pwm_lookup_lock); 1773 + 1774 + while (num--) { 1775 + list_del(&table->list); 1776 + table++; 1777 + } 1778 + } 2020 1779 2021 1780 static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s) 2022 1781 {
+108 -46
drivers/pwm/pwm-axi-pwmgen.c
··· 23 23 #include <linux/err.h> 24 24 #include <linux/fpga/adi-axi-common.h> 25 25 #include <linux/io.h> 26 + #include <linux/minmax.h> 26 27 #include <linux/module.h> 27 28 #include <linux/platform_device.h> 28 29 #include <linux/pwm.h> ··· 54 53 .max_register = 0xFC, 55 54 }; 56 55 57 - static int axi_pwmgen_apply(struct pwm_chip *chip, struct pwm_device *pwm, 58 - const struct pwm_state *state) 56 + /* This represents a hardware configuration for one channel */ 57 + struct axi_pwmgen_waveform { 58 + u32 period_cnt; 59 + u32 duty_cycle_cnt; 60 + u32 duty_offset_cnt; 61 + }; 62 + 63 + static int axi_pwmgen_round_waveform_tohw(struct pwm_chip *chip, 64 + struct pwm_device *pwm, 65 + const struct pwm_waveform *wf, 66 + void *_wfhw) 59 67 { 68 + struct axi_pwmgen_waveform *wfhw = _wfhw; 60 69 struct axi_pwmgen_ddata *ddata = pwmchip_get_drvdata(chip); 61 - unsigned int ch = pwm->hwpwm; 70 + 71 + if (wf->period_length_ns == 0) { 72 + *wfhw = (struct axi_pwmgen_waveform){ 73 + .period_cnt = 0, 74 + .duty_cycle_cnt = 0, 75 + .duty_offset_cnt = 0, 76 + }; 77 + } else { 78 + /* With ddata->clk_rate_hz < NSEC_PER_SEC this won't overflow. */ 79 + wfhw->period_cnt = min_t(u64, 80 + mul_u64_u32_div(wf->period_length_ns, ddata->clk_rate_hz, NSEC_PER_SEC), 81 + U32_MAX); 82 + 83 + if (wfhw->period_cnt == 0) { 84 + /* 85 + * The specified period is too short for the hardware. 86 + * Let's round .duty_cycle down to 0 to get a (somewhat) 87 + * valid result. 88 + */ 89 + wfhw->period_cnt = 1; 90 + wfhw->duty_cycle_cnt = 0; 91 + wfhw->duty_offset_cnt = 0; 92 + } else { 93 + wfhw->duty_cycle_cnt = min_t(u64, 94 + mul_u64_u32_div(wf->duty_length_ns, ddata->clk_rate_hz, NSEC_PER_SEC), 95 + U32_MAX); 96 + wfhw->duty_offset_cnt = min_t(u64, 97 + mul_u64_u32_div(wf->duty_offset_ns, ddata->clk_rate_hz, NSEC_PER_SEC), 98 + U32_MAX); 99 + } 100 + } 101 + 102 + dev_dbg(&chip->dev, "pwm#%u: %lld/%lld [+%lld] @%lu -> PERIOD: %08x, DUTY: %08x, OFFSET: %08x\n", 103 + pwm->hwpwm, wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns, 104 + ddata->clk_rate_hz, wfhw->period_cnt, wfhw->duty_cycle_cnt, wfhw->duty_offset_cnt); 105 + 106 + return 0; 107 + } 108 + 109 + static int axi_pwmgen_round_waveform_fromhw(struct pwm_chip *chip, struct pwm_device *pwm, 110 + const void *_wfhw, struct pwm_waveform *wf) 111 + { 112 + const struct axi_pwmgen_waveform *wfhw = _wfhw; 113 + struct axi_pwmgen_ddata *ddata = pwmchip_get_drvdata(chip); 114 + 115 + wf->period_length_ns = DIV64_U64_ROUND_UP((u64)wfhw->period_cnt * NSEC_PER_SEC, 116 + ddata->clk_rate_hz); 117 + 118 + wf->duty_length_ns = DIV64_U64_ROUND_UP((u64)wfhw->duty_cycle_cnt * NSEC_PER_SEC, 119 + ddata->clk_rate_hz); 120 + 121 + wf->duty_offset_ns = DIV64_U64_ROUND_UP((u64)wfhw->duty_offset_cnt * NSEC_PER_SEC, 122 + ddata->clk_rate_hz); 123 + 124 + return 0; 125 + } 126 + 127 + static int axi_pwmgen_write_waveform(struct pwm_chip *chip, 128 + struct pwm_device *pwm, 129 + const void *_wfhw) 130 + { 131 + const struct axi_pwmgen_waveform *wfhw = _wfhw; 132 + struct axi_pwmgen_ddata *ddata = pwmchip_get_drvdata(chip); 62 133 struct regmap *regmap = ddata->regmap; 63 - u64 period_cnt, duty_cnt; 134 + unsigned int ch = pwm->hwpwm; 64 135 int ret; 65 136 66 - if (state->polarity != PWM_POLARITY_NORMAL) 67 - return -EINVAL; 137 + ret = regmap_write(regmap, AXI_PWMGEN_CHX_PERIOD(ch), wfhw->period_cnt); 138 + if (ret) 139 + return ret; 68 140 69 - if (state->enabled) { 70 - period_cnt = mul_u64_u64_div_u64(state->period, ddata->clk_rate_hz, NSEC_PER_SEC); 71 - if (period_cnt > UINT_MAX) 72 - period_cnt = UINT_MAX; 141 + ret = regmap_write(regmap, AXI_PWMGEN_CHX_DUTY(ch), wfhw->duty_cycle_cnt); 142 + if (ret) 143 + return ret; 73 144 74 - if (period_cnt == 0) 75 - return -EINVAL; 76 - 77 - ret = regmap_write(regmap, AXI_PWMGEN_CHX_PERIOD(ch), period_cnt); 78 - if (ret) 79 - return ret; 80 - 81 - duty_cnt = mul_u64_u64_div_u64(state->duty_cycle, ddata->clk_rate_hz, NSEC_PER_SEC); 82 - if (duty_cnt > UINT_MAX) 83 - duty_cnt = UINT_MAX; 84 - 85 - ret = regmap_write(regmap, AXI_PWMGEN_CHX_DUTY(ch), duty_cnt); 86 - if (ret) 87 - return ret; 88 - } else { 89 - ret = regmap_write(regmap, AXI_PWMGEN_CHX_PERIOD(ch), 0); 90 - if (ret) 91 - return ret; 92 - 93 - ret = regmap_write(regmap, AXI_PWMGEN_CHX_DUTY(ch), 0); 94 - if (ret) 95 - return ret; 96 - } 145 + ret = regmap_write(regmap, AXI_PWMGEN_CHX_OFFSET(ch), wfhw->duty_offset_cnt); 146 + if (ret) 147 + return ret; 97 148 98 149 return regmap_write(regmap, AXI_PWMGEN_REG_CONFIG, AXI_PWMGEN_LOAD_CONFIG); 99 150 } 100 151 101 - static int axi_pwmgen_get_state(struct pwm_chip *chip, struct pwm_device *pwm, 102 - struct pwm_state *state) 152 + static int axi_pwmgen_read_waveform(struct pwm_chip *chip, 153 + struct pwm_device *pwm, 154 + void *_wfhw) 103 155 { 156 + struct axi_pwmgen_waveform *wfhw = _wfhw; 104 157 struct axi_pwmgen_ddata *ddata = pwmchip_get_drvdata(chip); 105 158 struct regmap *regmap = ddata->regmap; 106 159 unsigned int ch = pwm->hwpwm; 107 - u32 cnt; 108 160 int ret; 109 161 110 - ret = regmap_read(regmap, AXI_PWMGEN_CHX_PERIOD(ch), &cnt); 162 + ret = regmap_read(regmap, AXI_PWMGEN_CHX_PERIOD(ch), &wfhw->period_cnt); 111 163 if (ret) 112 164 return ret; 113 165 114 - state->enabled = cnt != 0; 115 - 116 - state->period = DIV_ROUND_UP_ULL((u64)cnt * NSEC_PER_SEC, ddata->clk_rate_hz); 117 - 118 - ret = regmap_read(regmap, AXI_PWMGEN_CHX_DUTY(ch), &cnt); 166 + ret = regmap_read(regmap, AXI_PWMGEN_CHX_DUTY(ch), &wfhw->duty_cycle_cnt); 119 167 if (ret) 120 168 return ret; 121 169 122 - state->duty_cycle = DIV_ROUND_UP_ULL((u64)cnt * NSEC_PER_SEC, ddata->clk_rate_hz); 170 + ret = regmap_read(regmap, AXI_PWMGEN_CHX_OFFSET(ch), &wfhw->duty_offset_cnt); 171 + if (ret) 172 + return ret; 123 173 124 - state->polarity = PWM_POLARITY_NORMAL; 174 + if (wfhw->duty_cycle_cnt > wfhw->period_cnt) 175 + wfhw->duty_cycle_cnt = wfhw->period_cnt; 176 + 177 + /* XXX: is this the actual behaviour of the hardware? */ 178 + if (wfhw->duty_offset_cnt >= wfhw->period_cnt) { 179 + wfhw->duty_cycle_cnt = 0; 180 + wfhw->duty_offset_cnt = 0; 181 + } 125 182 126 183 return 0; 127 184 } 128 185 129 186 static const struct pwm_ops axi_pwmgen_pwm_ops = { 130 - .apply = axi_pwmgen_apply, 131 - .get_state = axi_pwmgen_get_state, 187 + .sizeof_wfhw = sizeof(struct axi_pwmgen_waveform), 188 + .round_waveform_tohw = axi_pwmgen_round_waveform_tohw, 189 + .round_waveform_fromhw = axi_pwmgen_round_waveform_fromhw, 190 + .read_waveform = axi_pwmgen_read_waveform, 191 + .write_waveform = axi_pwmgen_write_waveform, 132 192 }; 133 193 134 194 static int axi_pwmgen_setup(struct regmap *regmap, struct device *dev)
+391 -221
drivers/pwm/pwm-stm32.c
··· 51 51 return ccer & TIM_CCER_CCXE; 52 52 } 53 53 54 + struct stm32_pwm_waveform { 55 + u32 ccer; 56 + u32 psc; 57 + u32 arr; 58 + u32 ccr; 59 + }; 60 + 61 + static int stm32_pwm_round_waveform_tohw(struct pwm_chip *chip, 62 + struct pwm_device *pwm, 63 + const struct pwm_waveform *wf, 64 + void *_wfhw) 65 + { 66 + struct stm32_pwm_waveform *wfhw = _wfhw; 67 + struct stm32_pwm *priv = to_stm32_pwm_dev(chip); 68 + unsigned int ch = pwm->hwpwm; 69 + unsigned long rate; 70 + u64 ccr, duty; 71 + int ret; 72 + 73 + if (wf->period_length_ns == 0) { 74 + *wfhw = (struct stm32_pwm_waveform){ 75 + .ccer = 0, 76 + }; 77 + 78 + return 0; 79 + } 80 + 81 + ret = clk_enable(priv->clk); 82 + if (ret) 83 + return ret; 84 + 85 + wfhw->ccer = TIM_CCER_CCxE(ch + 1); 86 + if (priv->have_complementary_output) 87 + wfhw->ccer = TIM_CCER_CCxNE(ch + 1); 88 + 89 + rate = clk_get_rate(priv->clk); 90 + 91 + if (active_channels(priv) & ~(1 << ch * 4)) { 92 + u64 arr; 93 + 94 + /* 95 + * Other channels are already enabled, so the configured PSC and 96 + * ARR must be used for this channel, too. 97 + */ 98 + ret = regmap_read(priv->regmap, TIM_PSC, &wfhw->psc); 99 + if (ret) 100 + goto out; 101 + 102 + ret = regmap_read(priv->regmap, TIM_ARR, &wfhw->arr); 103 + if (ret) 104 + goto out; 105 + 106 + /* 107 + * calculate the best value for ARR for the given PSC, refuse if 108 + * the resulting period gets bigger than the requested one. 109 + */ 110 + arr = mul_u64_u64_div_u64(wf->period_length_ns, rate, 111 + (u64)NSEC_PER_SEC * (wfhw->psc + 1)); 112 + if (arr <= wfhw->arr) { 113 + /* 114 + * requested period is small than the currently 115 + * configured and unchangable period, report back the smallest 116 + * possible period, i.e. the current state; Initialize 117 + * ccr to anything valid. 118 + */ 119 + wfhw->ccr = 0; 120 + ret = 1; 121 + goto out; 122 + } 123 + 124 + } else { 125 + /* 126 + * .probe() asserted that clk_get_rate() is not bigger than 1 GHz, so 127 + * the calculations here won't overflow. 128 + * First we need to find the minimal value for prescaler such that 129 + * 130 + * period_ns * clkrate 131 + * ------------------------------ < max_arr + 1 132 + * NSEC_PER_SEC * (prescaler + 1) 133 + * 134 + * This equation is equivalent to 135 + * 136 + * period_ns * clkrate 137 + * ---------------------------- < prescaler + 1 138 + * NSEC_PER_SEC * (max_arr + 1) 139 + * 140 + * Using integer division and knowing that the right hand side is 141 + * integer, this is further equivalent to 142 + * 143 + * (period_ns * clkrate) // (NSEC_PER_SEC * (max_arr + 1)) ≤ prescaler 144 + */ 145 + u64 psc = mul_u64_u64_div_u64(wf->period_length_ns, rate, 146 + (u64)NSEC_PER_SEC * ((u64)priv->max_arr + 1)); 147 + u64 arr; 148 + 149 + wfhw->psc = min_t(u64, psc, MAX_TIM_PSC); 150 + 151 + arr = mul_u64_u64_div_u64(wf->period_length_ns, rate, 152 + (u64)NSEC_PER_SEC * (wfhw->psc + 1)); 153 + if (!arr) { 154 + /* 155 + * requested period is too small, report back the smallest 156 + * possible period, i.e. ARR = 0. The only valid CCR 157 + * value is then zero, too. 158 + */ 159 + wfhw->arr = 0; 160 + wfhw->ccr = 0; 161 + ret = 1; 162 + goto out; 163 + } 164 + 165 + /* 166 + * ARR is limited intentionally to values less than 167 + * priv->max_arr to allow 100% duty cycle. 168 + */ 169 + wfhw->arr = min_t(u64, arr, priv->max_arr) - 1; 170 + } 171 + 172 + duty = mul_u64_u64_div_u64(wf->duty_length_ns, rate, 173 + (u64)NSEC_PER_SEC * (wfhw->psc + 1)); 174 + duty = min_t(u64, duty, wfhw->arr + 1); 175 + 176 + if (wf->duty_length_ns && wf->duty_offset_ns && 177 + wf->duty_length_ns + wf->duty_offset_ns >= wf->period_length_ns) { 178 + wfhw->ccer |= TIM_CCER_CCxP(ch + 1); 179 + if (priv->have_complementary_output) 180 + wfhw->ccer |= TIM_CCER_CCxNP(ch + 1); 181 + 182 + ccr = wfhw->arr + 1 - duty; 183 + } else { 184 + ccr = duty; 185 + } 186 + 187 + wfhw->ccr = min_t(u64, ccr, wfhw->arr + 1); 188 + 189 + dev_dbg(&chip->dev, "pwm#%u: %lld/%lld [+%lld] @%lu -> CCER: %08x, PSC: %08x, ARR: %08x, CCR: %08x\n", 190 + pwm->hwpwm, wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns, 191 + rate, wfhw->ccer, wfhw->psc, wfhw->arr, wfhw->ccr); 192 + 193 + out: 194 + clk_disable(priv->clk); 195 + 196 + return ret; 197 + } 198 + 199 + /* 200 + * This should be moved to lib/math/div64.c. Currently there are some changes 201 + * pending to mul_u64_u64_div_u64. Uwe will care for that when the dust settles. 202 + */ 203 + static u64 stm32_pwm_mul_u64_u64_div_u64_roundup(u64 a, u64 b, u64 c) 204 + { 205 + u64 res = mul_u64_u64_div_u64(a, b, c); 206 + /* Those multiplications might overflow but it doesn't matter */ 207 + u64 rem = a * b - c * res; 208 + 209 + if (rem) 210 + res += 1; 211 + 212 + return res; 213 + } 214 + 215 + static int stm32_pwm_round_waveform_fromhw(struct pwm_chip *chip, 216 + struct pwm_device *pwm, 217 + const void *_wfhw, 218 + struct pwm_waveform *wf) 219 + { 220 + const struct stm32_pwm_waveform *wfhw = _wfhw; 221 + struct stm32_pwm *priv = to_stm32_pwm_dev(chip); 222 + unsigned int ch = pwm->hwpwm; 223 + 224 + if (wfhw->ccer & TIM_CCER_CCxE(ch + 1)) { 225 + unsigned long rate = clk_get_rate(priv->clk); 226 + u64 ccr_ns; 227 + 228 + /* The result doesn't overflow for rate >= 15259 */ 229 + wf->period_length_ns = stm32_pwm_mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * (wfhw->arr + 1), 230 + NSEC_PER_SEC, rate); 231 + 232 + ccr_ns = stm32_pwm_mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * wfhw->ccr, 233 + NSEC_PER_SEC, rate); 234 + 235 + if (wfhw->ccer & TIM_CCER_CCxP(ch + 1)) { 236 + wf->duty_length_ns = 237 + stm32_pwm_mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * (wfhw->arr + 1 - wfhw->ccr), 238 + NSEC_PER_SEC, rate); 239 + 240 + wf->duty_offset_ns = ccr_ns; 241 + } else { 242 + wf->duty_length_ns = ccr_ns; 243 + wf->duty_offset_ns = 0; 244 + } 245 + 246 + dev_dbg(&chip->dev, "pwm#%u: CCER: %08x, PSC: %08x, ARR: %08x, CCR: %08x @%lu -> %lld/%lld [+%lld]\n", 247 + pwm->hwpwm, wfhw->ccer, wfhw->psc, wfhw->arr, wfhw->ccr, rate, 248 + wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns); 249 + 250 + } else { 251 + *wf = (struct pwm_waveform){ 252 + .period_length_ns = 0, 253 + }; 254 + } 255 + 256 + return 0; 257 + } 258 + 259 + static int stm32_pwm_read_waveform(struct pwm_chip *chip, 260 + struct pwm_device *pwm, 261 + void *_wfhw) 262 + { 263 + struct stm32_pwm_waveform *wfhw = _wfhw; 264 + struct stm32_pwm *priv = to_stm32_pwm_dev(chip); 265 + unsigned int ch = pwm->hwpwm; 266 + int ret; 267 + 268 + ret = clk_enable(priv->clk); 269 + if (ret) 270 + return ret; 271 + 272 + ret = regmap_read(priv->regmap, TIM_CCER, &wfhw->ccer); 273 + if (ret) 274 + goto out; 275 + 276 + if (wfhw->ccer & TIM_CCER_CCxE(ch + 1)) { 277 + ret = regmap_read(priv->regmap, TIM_PSC, &wfhw->psc); 278 + if (ret) 279 + goto out; 280 + 281 + ret = regmap_read(priv->regmap, TIM_ARR, &wfhw->arr); 282 + if (ret) 283 + goto out; 284 + 285 + if (wfhw->arr == U32_MAX) 286 + wfhw->arr -= 1; 287 + 288 + ret = regmap_read(priv->regmap, TIM_CCRx(ch + 1), &wfhw->ccr); 289 + if (ret) 290 + goto out; 291 + 292 + if (wfhw->ccr > wfhw->arr + 1) 293 + wfhw->ccr = wfhw->arr + 1; 294 + } 295 + 296 + out: 297 + clk_disable(priv->clk); 298 + 299 + return ret; 300 + } 301 + 302 + static int stm32_pwm_write_waveform(struct pwm_chip *chip, 303 + struct pwm_device *pwm, 304 + const void *_wfhw) 305 + { 306 + const struct stm32_pwm_waveform *wfhw = _wfhw; 307 + struct stm32_pwm *priv = to_stm32_pwm_dev(chip); 308 + unsigned int ch = pwm->hwpwm; 309 + int ret; 310 + 311 + ret = clk_enable(priv->clk); 312 + if (ret) 313 + return ret; 314 + 315 + if (wfhw->ccer & TIM_CCER_CCxE(ch + 1)) { 316 + u32 ccer, mask; 317 + unsigned int shift; 318 + u32 ccmr; 319 + 320 + ret = regmap_read(priv->regmap, TIM_CCER, &ccer); 321 + if (ret) 322 + goto out; 323 + 324 + /* If there are other channels enabled, don't update PSC and ARR */ 325 + if (ccer & ~TIM_CCER_CCxE(ch + 1) & TIM_CCER_CCXE) { 326 + u32 psc, arr; 327 + 328 + ret = regmap_read(priv->regmap, TIM_PSC, &psc); 329 + if (ret) 330 + goto out; 331 + 332 + if (psc != wfhw->psc) { 333 + ret = -EBUSY; 334 + goto out; 335 + } 336 + 337 + ret = regmap_read(priv->regmap, TIM_ARR, &arr); 338 + if (ret) 339 + goto out; 340 + 341 + if (arr != wfhw->arr) { 342 + ret = -EBUSY; 343 + goto out; 344 + } 345 + } else { 346 + ret = regmap_write(priv->regmap, TIM_PSC, wfhw->psc); 347 + if (ret) 348 + goto out; 349 + 350 + ret = regmap_write(priv->regmap, TIM_ARR, wfhw->arr); 351 + if (ret) 352 + goto out; 353 + 354 + ret = regmap_set_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE); 355 + if (ret) 356 + goto out; 357 + 358 + } 359 + 360 + /* set polarity */ 361 + mask = TIM_CCER_CCxP(ch + 1) | TIM_CCER_CCxNP(ch + 1); 362 + ret = regmap_update_bits(priv->regmap, TIM_CCER, mask, wfhw->ccer); 363 + if (ret) 364 + goto out; 365 + 366 + ret = regmap_write(priv->regmap, TIM_CCRx(ch + 1), wfhw->ccr); 367 + if (ret) 368 + goto out; 369 + 370 + /* Configure output mode */ 371 + shift = (ch & 0x1) * CCMR_CHANNEL_SHIFT; 372 + ccmr = (TIM_CCMR_PE | TIM_CCMR_M1) << shift; 373 + mask = CCMR_CHANNEL_MASK << shift; 374 + 375 + if (ch < 2) 376 + ret = regmap_update_bits(priv->regmap, TIM_CCMR1, mask, ccmr); 377 + else 378 + ret = regmap_update_bits(priv->regmap, TIM_CCMR2, mask, ccmr); 379 + if (ret) 380 + goto out; 381 + 382 + ret = regmap_set_bits(priv->regmap, TIM_BDTR, TIM_BDTR_MOE); 383 + if (ret) 384 + goto out; 385 + 386 + if (!(ccer & TIM_CCER_CCxE(ch + 1))) { 387 + mask = TIM_CCER_CCxE(ch + 1) | TIM_CCER_CCxNE(ch + 1); 388 + 389 + ret = clk_enable(priv->clk); 390 + if (ret) 391 + goto out; 392 + 393 + ccer = (ccer & ~mask) | (wfhw->ccer & mask); 394 + regmap_write(priv->regmap, TIM_CCER, ccer); 395 + 396 + /* Make sure that registers are updated */ 397 + regmap_set_bits(priv->regmap, TIM_EGR, TIM_EGR_UG); 398 + 399 + /* Enable controller */ 400 + regmap_set_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN); 401 + } 402 + 403 + } else { 404 + /* disable channel */ 405 + u32 mask, ccer; 406 + 407 + mask = TIM_CCER_CCxE(ch + 1); 408 + if (priv->have_complementary_output) 409 + mask |= TIM_CCER_CCxNE(ch + 1); 410 + 411 + ret = regmap_read(priv->regmap, TIM_CCER, &ccer); 412 + if (ret) 413 + goto out; 414 + 415 + if (ccer & mask) { 416 + ccer = ccer & ~mask; 417 + 418 + ret = regmap_write(priv->regmap, TIM_CCER, ccer); 419 + if (ret) 420 + goto out; 421 + 422 + if (!(ccer & TIM_CCER_CCXE)) { 423 + /* When all channels are disabled, we can disable the controller */ 424 + ret = regmap_clear_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN); 425 + if (ret) 426 + goto out; 427 + } 428 + 429 + clk_disable(priv->clk); 430 + } 431 + } 432 + 433 + out: 434 + clk_disable(priv->clk); 435 + 436 + return ret; 437 + } 438 + 54 439 #define TIM_CCER_CC12P (TIM_CCER_CC1P | TIM_CCER_CC2P) 55 440 #define TIM_CCER_CC12E (TIM_CCER_CC1E | TIM_CCER_CC2E) 56 441 #define TIM_CCER_CC34P (TIM_CCER_CC3P | TIM_CCER_CC4P) ··· 693 308 return ret; 694 309 } 695 310 696 - static int stm32_pwm_config(struct stm32_pwm *priv, unsigned int ch, 697 - u64 duty_ns, u64 period_ns) 698 - { 699 - unsigned long long prd, dty; 700 - unsigned long long prescaler; 701 - u32 ccmr, mask, shift; 702 - 703 - /* 704 - * .probe() asserted that clk_get_rate() is not bigger than 1 GHz, so 705 - * the calculations here won't overflow. 706 - * First we need to find the minimal value for prescaler such that 707 - * 708 - * period_ns * clkrate 709 - * ------------------------------ < max_arr + 1 710 - * NSEC_PER_SEC * (prescaler + 1) 711 - * 712 - * This equation is equivalent to 713 - * 714 - * period_ns * clkrate 715 - * ---------------------------- < prescaler + 1 716 - * NSEC_PER_SEC * (max_arr + 1) 717 - * 718 - * Using integer division and knowing that the right hand side is 719 - * integer, this is further equivalent to 720 - * 721 - * (period_ns * clkrate) // (NSEC_PER_SEC * (max_arr + 1)) ≤ prescaler 722 - */ 723 - 724 - prescaler = mul_u64_u64_div_u64(period_ns, clk_get_rate(priv->clk), 725 - (u64)NSEC_PER_SEC * ((u64)priv->max_arr + 1)); 726 - if (prescaler > MAX_TIM_PSC) 727 - return -EINVAL; 728 - 729 - prd = mul_u64_u64_div_u64(period_ns, clk_get_rate(priv->clk), 730 - (u64)NSEC_PER_SEC * (prescaler + 1)); 731 - if (!prd) 732 - return -EINVAL; 733 - 734 - /* 735 - * All channels share the same prescaler and counter so when two 736 - * channels are active at the same time we can't change them 737 - */ 738 - if (active_channels(priv) & ~(1 << ch * 4)) { 739 - u32 psc, arr; 740 - 741 - regmap_read(priv->regmap, TIM_PSC, &psc); 742 - regmap_read(priv->regmap, TIM_ARR, &arr); 743 - 744 - if ((psc != prescaler) || (arr != prd - 1)) 745 - return -EBUSY; 746 - } 747 - 748 - regmap_write(priv->regmap, TIM_PSC, prescaler); 749 - regmap_write(priv->regmap, TIM_ARR, prd - 1); 750 - regmap_set_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE); 751 - 752 - /* Calculate the duty cycles */ 753 - dty = mul_u64_u64_div_u64(duty_ns, clk_get_rate(priv->clk), 754 - (u64)NSEC_PER_SEC * (prescaler + 1)); 755 - 756 - regmap_write(priv->regmap, TIM_CCRx(ch + 1), dty); 757 - 758 - /* Configure output mode */ 759 - shift = (ch & 0x1) * CCMR_CHANNEL_SHIFT; 760 - ccmr = (TIM_CCMR_PE | TIM_CCMR_M1) << shift; 761 - mask = CCMR_CHANNEL_MASK << shift; 762 - 763 - if (ch < 2) 764 - regmap_update_bits(priv->regmap, TIM_CCMR1, mask, ccmr); 765 - else 766 - regmap_update_bits(priv->regmap, TIM_CCMR2, mask, ccmr); 767 - 768 - regmap_set_bits(priv->regmap, TIM_BDTR, TIM_BDTR_MOE); 769 - 770 - return 0; 771 - } 772 - 773 - static int stm32_pwm_set_polarity(struct stm32_pwm *priv, unsigned int ch, 774 - enum pwm_polarity polarity) 775 - { 776 - u32 mask; 777 - 778 - mask = TIM_CCER_CCxP(ch + 1); 779 - if (priv->have_complementary_output) 780 - mask |= TIM_CCER_CCxNP(ch + 1); 781 - 782 - regmap_update_bits(priv->regmap, TIM_CCER, mask, 783 - polarity == PWM_POLARITY_NORMAL ? 0 : mask); 784 - 785 - return 0; 786 - } 787 - 788 - static int stm32_pwm_enable(struct stm32_pwm *priv, unsigned int ch) 789 - { 790 - u32 mask; 791 - int ret; 792 - 793 - ret = clk_enable(priv->clk); 794 - if (ret) 795 - return ret; 796 - 797 - /* Enable channel */ 798 - mask = TIM_CCER_CCxE(ch + 1); 799 - if (priv->have_complementary_output) 800 - mask |= TIM_CCER_CCxNE(ch + 1); 801 - 802 - regmap_set_bits(priv->regmap, TIM_CCER, mask); 803 - 804 - /* Make sure that registers are updated */ 805 - regmap_set_bits(priv->regmap, TIM_EGR, TIM_EGR_UG); 806 - 807 - /* Enable controller */ 808 - regmap_set_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN); 809 - 810 - return 0; 811 - } 812 - 813 - static void stm32_pwm_disable(struct stm32_pwm *priv, unsigned int ch) 814 - { 815 - u32 mask; 816 - 817 - /* Disable channel */ 818 - mask = TIM_CCER_CCxE(ch + 1); 819 - if (priv->have_complementary_output) 820 - mask |= TIM_CCER_CCxNE(ch + 1); 821 - 822 - regmap_clear_bits(priv->regmap, TIM_CCER, mask); 823 - 824 - /* When all channels are disabled, we can disable the controller */ 825 - if (!active_channels(priv)) 826 - regmap_clear_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN); 827 - 828 - clk_disable(priv->clk); 829 - } 830 - 831 - static int stm32_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 832 - const struct pwm_state *state) 833 - { 834 - bool enabled; 835 - struct stm32_pwm *priv = to_stm32_pwm_dev(chip); 836 - int ret; 837 - 838 - enabled = pwm->state.enabled; 839 - 840 - if (!state->enabled) { 841 - if (enabled) 842 - stm32_pwm_disable(priv, pwm->hwpwm); 843 - return 0; 844 - } 845 - 846 - if (state->polarity != pwm->state.polarity) 847 - stm32_pwm_set_polarity(priv, pwm->hwpwm, state->polarity); 848 - 849 - ret = stm32_pwm_config(priv, pwm->hwpwm, 850 - state->duty_cycle, state->period); 851 - if (ret) 852 - return ret; 853 - 854 - if (!enabled && state->enabled) 855 - ret = stm32_pwm_enable(priv, pwm->hwpwm); 856 - 857 - return ret; 858 - } 859 - 860 - static int stm32_pwm_apply_locked(struct pwm_chip *chip, struct pwm_device *pwm, 861 - const struct pwm_state *state) 862 - { 863 - struct stm32_pwm *priv = to_stm32_pwm_dev(chip); 864 - int ret; 865 - 866 - /* protect common prescaler for all active channels */ 867 - mutex_lock(&priv->lock); 868 - ret = stm32_pwm_apply(chip, pwm, state); 869 - mutex_unlock(&priv->lock); 870 - 871 - return ret; 872 - } 873 - 874 - static int stm32_pwm_get_state(struct pwm_chip *chip, 875 - struct pwm_device *pwm, struct pwm_state *state) 876 - { 877 - struct stm32_pwm *priv = to_stm32_pwm_dev(chip); 878 - int ch = pwm->hwpwm; 879 - unsigned long rate; 880 - u32 ccer, psc, arr, ccr; 881 - u64 dty, prd; 882 - int ret; 883 - 884 - mutex_lock(&priv->lock); 885 - 886 - ret = regmap_read(priv->regmap, TIM_CCER, &ccer); 887 - if (ret) 888 - goto out; 889 - 890 - state->enabled = ccer & TIM_CCER_CCxE(ch + 1); 891 - state->polarity = (ccer & TIM_CCER_CCxP(ch + 1)) ? 892 - PWM_POLARITY_INVERSED : PWM_POLARITY_NORMAL; 893 - ret = regmap_read(priv->regmap, TIM_PSC, &psc); 894 - if (ret) 895 - goto out; 896 - ret = regmap_read(priv->regmap, TIM_ARR, &arr); 897 - if (ret) 898 - goto out; 899 - ret = regmap_read(priv->regmap, TIM_CCRx(ch + 1), &ccr); 900 - if (ret) 901 - goto out; 902 - 903 - rate = clk_get_rate(priv->clk); 904 - 905 - prd = (u64)NSEC_PER_SEC * (psc + 1) * (arr + 1); 906 - state->period = DIV_ROUND_UP_ULL(prd, rate); 907 - dty = (u64)NSEC_PER_SEC * (psc + 1) * ccr; 908 - state->duty_cycle = DIV_ROUND_UP_ULL(dty, rate); 909 - 910 - out: 911 - mutex_unlock(&priv->lock); 912 - return ret; 913 - } 914 - 915 311 static const struct pwm_ops stm32pwm_ops = { 916 - .apply = stm32_pwm_apply_locked, 917 - .get_state = stm32_pwm_get_state, 312 + .sizeof_wfhw = sizeof(struct stm32_pwm_waveform), 313 + .round_waveform_tohw = stm32_pwm_round_waveform_tohw, 314 + .round_waveform_fromhw = stm32_pwm_round_waveform_fromhw, 315 + .read_waveform = stm32_pwm_read_waveform, 316 + .write_waveform = stm32_pwm_write_waveform, 317 + 918 318 .capture = IS_ENABLED(CONFIG_DMA_ENGINE) ? stm32_pwm_capture : NULL, 919 319 }; 920 320
+3 -3
drivers/staging/iio/impedance-analyzer/ad5933.c
··· 628 628 int scan_count = bitmap_weight(indio_dev->active_scan_mask, 629 629 iio_get_masklength(indio_dev)); 630 630 ret = ad5933_i2c_read(st->client, 631 - test_bit(1, indio_dev->active_scan_mask) ? 632 - AD5933_REG_REAL_DATA : AD5933_REG_IMAG_DATA, 633 - scan_count * 2, (u8 *)buf); 631 + test_bit(1, indio_dev->active_scan_mask) ? 632 + AD5933_REG_REAL_DATA : AD5933_REG_IMAG_DATA, 633 + scan_count * 2, (u8 *)buf); 634 634 if (ret) 635 635 return; 636 636
+10
include/dt-bindings/iio/adc/gehc,pmc-adc.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause */ 2 + 3 + #ifndef _DT_BINDINGS_IIO_ADC_GEHC_PMC_ADC_H 4 + #define _DT_BINDINGS_IIO_ADC_GEHC_PMC_ADC_H 5 + 6 + /* ADC channel type */ 7 + #define GEHC_PMC_ADC_VOLTAGE 0 8 + #define GEHC_PMC_ADC_CURRENT 1 9 + 10 + #endif
+3 -2
include/linux/iio/driver.h
··· 18 18 * @map: array of mappings specifying association of channel with client 19 19 */ 20 20 int iio_map_array_register(struct iio_dev *indio_dev, 21 - struct iio_map *map); 21 + const struct iio_map *map); 22 22 23 23 /** 24 24 * iio_map_array_unregister() - tell the core to remove consumer mappings for ··· 38 38 * handle de-registration of the IIO map object when the device's refcount goes to 39 39 * zero. 40 40 */ 41 - int devm_iio_map_array_register(struct device *dev, struct iio_dev *indio_dev, struct iio_map *maps); 41 + int devm_iio_map_array_register(struct device *dev, struct iio_dev *indio_dev, 42 + const struct iio_map *maps); 42 43 43 44 #endif
+1 -1
include/linux/iio/iio-opaque.h
··· 70 70 71 71 #if defined(CONFIG_DEBUG_FS) 72 72 struct dentry *debugfs_dentry; 73 - unsigned cached_reg_addr; 73 + unsigned int cached_reg_addr; 74 74 char read_buf[20]; 75 75 unsigned int read_buf_len; 76 76 #endif
+10 -10
include/linux/iio/iio.h
··· 282 282 const struct iio_chan_spec_ext_info *ext_info; 283 283 const char *extend_name; 284 284 const char *datasheet_name; 285 - unsigned modified:1; 286 - unsigned indexed:1; 287 - unsigned output:1; 288 - unsigned differential:1; 289 - unsigned has_ext_scan_type:1; 285 + unsigned int modified:1; 286 + unsigned int indexed:1; 287 + unsigned int output:1; 288 + unsigned int differential:1; 289 + unsigned int has_ext_scan_type:1; 290 290 }; 291 291 292 292 ··· 541 541 int (*update_scan_mode)(struct iio_dev *indio_dev, 542 542 const unsigned long *scan_mask); 543 543 int (*debugfs_reg_access)(struct iio_dev *indio_dev, 544 - unsigned reg, unsigned writeval, 545 - unsigned *readval); 544 + unsigned int reg, unsigned int writeval, 545 + unsigned int *readval); 546 546 int (*fwnode_xlate)(struct iio_dev *indio_dev, 547 547 const struct fwnode_reference_args *iiospec); 548 - int (*hwfifo_set_watermark)(struct iio_dev *indio_dev, unsigned val); 548 + int (*hwfifo_set_watermark)(struct iio_dev *indio_dev, unsigned int val); 549 549 int (*hwfifo_flush_to_buffer)(struct iio_dev *indio_dev, 550 - unsigned count); 550 + unsigned int count); 551 551 }; 552 552 553 553 /** ··· 609 609 int scan_bytes; 610 610 611 611 const unsigned long *available_scan_masks; 612 - unsigned __private masklength; 612 + unsigned int __private masklength; 613 613 const unsigned long *active_scan_mask; 614 614 bool scan_timestamp; 615 615 struct iio_trigger *trig;
+59 -1
include/linux/pwm.h
··· 49 49 PWMF_EXPORTED = 1, 50 50 }; 51 51 52 + /** 53 + * struct pwm_waveform - description of a PWM waveform 54 + * @period_length_ns: PWM period 55 + * @duty_length_ns: PWM duty cycle 56 + * @duty_offset_ns: offset of the rising edge from the period's start 57 + * 58 + * This is a representation of a PWM waveform alternative to struct pwm_state 59 + * below. It's more expressive than struct pwm_state as it contains a 60 + * duty_offset_ns and so can represent offsets other than zero (with .polarity = 61 + * PWM_POLARITY_NORMAL) and period - duty_cycle (.polarity = 62 + * PWM_POLARITY_INVERSED). 63 + * 64 + * Note there is no explicit bool for enabled. A "disabled" PWM is represented 65 + * by .period_length_ns = 0. Note further that the behaviour of a "disabled" PWM 66 + * is undefined. Depending on the hardware's capabilities it might drive the 67 + * active or inactive level, go high-z or even continue to toggle. 68 + * 69 + * The unit for all three members is nanoseconds. 70 + */ 71 + struct pwm_waveform { 72 + u64 period_length_ns; 73 + u64 duty_length_ns; 74 + u64 duty_offset_ns; 75 + }; 76 + 52 77 /* 53 78 * struct pwm_state - state of a PWM channel 54 79 * @period: PWM period (in nanoseconds) ··· 276 251 * @request: optional hook for requesting a PWM 277 252 * @free: optional hook for freeing a PWM 278 253 * @capture: capture and report PWM signal 254 + * @sizeof_wfhw: size (in bytes) of driver specific waveform presentation 255 + * @round_waveform_tohw: convert a struct pwm_waveform to driver specific presentation 256 + * @round_waveform_fromhw: convert a driver specific waveform presentation to struct pwm_waveform 257 + * @read_waveform: read driver specific waveform presentation from hardware 258 + * @write_waveform: write driver specific waveform presentation to hardware 279 259 * @apply: atomically apply a new PWM config 280 260 * @get_state: get the current PWM state. 281 261 */ ··· 289 259 void (*free)(struct pwm_chip *chip, struct pwm_device *pwm); 290 260 int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm, 291 261 struct pwm_capture *result, unsigned long timeout); 262 + 263 + size_t sizeof_wfhw; 264 + int (*round_waveform_tohw)(struct pwm_chip *chip, struct pwm_device *pwm, 265 + const struct pwm_waveform *wf, void *wfhw); 266 + int (*round_waveform_fromhw)(struct pwm_chip *chip, struct pwm_device *pwm, 267 + const void *wfhw, struct pwm_waveform *wf); 268 + int (*read_waveform)(struct pwm_chip *chip, struct pwm_device *pwm, 269 + void *wfhw); 270 + int (*write_waveform)(struct pwm_chip *chip, struct pwm_device *pwm, 271 + const void *wfhw); 272 + 292 273 int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm, 293 274 const struct pwm_state *state); 294 275 int (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm, ··· 316 275 * @of_xlate: request a PWM device given a device tree PWM specifier 317 276 * @atomic: can the driver's ->apply() be called in atomic context 318 277 * @uses_pwmchip_alloc: signals if pwmchip_allow was used to allocate this chip 278 + * @operational: signals if the chip can be used (or is already deregistered) 279 + * @nonatomic_lock: mutex for nonatomic chips 280 + * @atomic_lock: mutex for atomic chips 319 281 * @pwms: array of PWM devices allocated by the framework 320 282 */ 321 283 struct pwm_chip { ··· 334 290 335 291 /* only used internally by the PWM framework */ 336 292 bool uses_pwmchip_alloc; 293 + bool operational; 294 + union { 295 + /* 296 + * depending on the chip being atomic or not either the mutex or 297 + * the spinlock is used. It protects .operational and 298 + * synchronizes the callbacks in .ops 299 + */ 300 + struct mutex nonatomic_lock; 301 + spinlock_t atomic_lock; 302 + }; 337 303 struct pwm_device pwms[] __counted_by(npwm); 338 304 }; 339 305 ··· 363 309 } 364 310 365 311 #if IS_ENABLED(CONFIG_PWM) 366 - /* PWM user APIs */ 312 + 313 + /* PWM consumer APIs */ 314 + int pwm_round_waveform_might_sleep(struct pwm_device *pwm, struct pwm_waveform *wf); 315 + int pwm_get_waveform_might_sleep(struct pwm_device *pwm, struct pwm_waveform *wf); 316 + int pwm_set_waveform_might_sleep(struct pwm_device *pwm, const struct pwm_waveform *wf, bool exact); 367 317 int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state); 368 318 int pwm_apply_atomic(struct pwm_device *pwm, const struct pwm_state *state); 369 319 int pwm_adjust_config(struct pwm_device *pwm);
+2 -1
include/linux/types.h
··· 115 115 typedef s64 int64_t; 116 116 #endif 117 117 118 - /* this is a special 64bit data type that is 8-byte aligned */ 118 + /* These are the special 64-bit data types that are 8-byte aligned */ 119 119 #define aligned_u64 __aligned_u64 120 + #define aligned_s64 __aligned_s64 120 121 #define aligned_be64 __aligned_be64 121 122 #define aligned_le64 __aligned_le64 122 123
+126 -8
include/trace/events/pwm.h
··· 8 8 #include <linux/pwm.h> 9 9 #include <linux/tracepoint.h> 10 10 11 + #define TP_PROTO_pwm(args...) \ 12 + TP_PROTO(struct pwm_device *pwm, args) 13 + 14 + #define TP_ARGS_pwm(args...) \ 15 + TP_ARGS(pwm, args) 16 + 17 + #define TP_STRUCT__entry_pwm(args...) \ 18 + TP_STRUCT__entry( \ 19 + __field(unsigned int, chipid) \ 20 + __field(unsigned int, hwpwm) \ 21 + args) 22 + 23 + #define TP_fast_assign_pwm(args...) \ 24 + TP_fast_assign( \ 25 + __entry->chipid = pwm->chip->id; \ 26 + __entry->hwpwm = pwm->hwpwm; \ 27 + args) 28 + 29 + #define TP_printk_pwm(fmt, args...) \ 30 + TP_printk("pwmchip%u.%u: " fmt, __entry->chipid, __entry->hwpwm, args) 31 + 32 + #define __field_pwmwf(wf) \ 33 + __field(u64, wf ## _period_length_ns) \ 34 + __field(u64, wf ## _duty_length_ns) \ 35 + __field(u64, wf ## _duty_offset_ns) \ 36 + 37 + #define fast_assign_pwmwf(wf) \ 38 + __entry->wf ## _period_length_ns = wf->period_length_ns; \ 39 + __entry->wf ## _duty_length_ns = wf->duty_length_ns; \ 40 + __entry->wf ## _duty_offset_ns = wf->duty_offset_ns 41 + 42 + #define printk_pwmwf_format(wf) \ 43 + "%lld/%lld [+%lld]" 44 + 45 + #define printk_pwmwf_formatargs(wf) \ 46 + __entry->wf ## _duty_length_ns, __entry->wf ## _period_length_ns, __entry->wf ## _duty_offset_ns 47 + 48 + TRACE_EVENT(pwm_round_waveform_tohw, 49 + 50 + TP_PROTO_pwm(const struct pwm_waveform *wf, void *wfhw, int err), 51 + 52 + TP_ARGS_pwm(wf, wfhw, err), 53 + 54 + TP_STRUCT__entry_pwm( 55 + __field_pwmwf(wf) 56 + __field(void *, wfhw) 57 + __field(int, err) 58 + ), 59 + 60 + TP_fast_assign_pwm( 61 + fast_assign_pwmwf(wf); 62 + __entry->wfhw = wfhw; 63 + __entry->err = err; 64 + ), 65 + 66 + TP_printk_pwm(printk_pwmwf_format(wf) " > %p err=%d", 67 + printk_pwmwf_formatargs(wf), __entry->wfhw, __entry->err) 68 + ); 69 + 70 + TRACE_EVENT(pwm_round_waveform_fromhw, 71 + 72 + TP_PROTO_pwm(const void *wfhw, struct pwm_waveform *wf, int err), 73 + 74 + TP_ARGS_pwm(wfhw, wf, err), 75 + 76 + TP_STRUCT__entry_pwm( 77 + __field(const void *, wfhw) 78 + __field_pwmwf(wf) 79 + __field(int, err) 80 + ), 81 + 82 + TP_fast_assign_pwm( 83 + __entry->wfhw = wfhw; 84 + fast_assign_pwmwf(wf); 85 + __entry->err = err; 86 + ), 87 + 88 + TP_printk_pwm("%p > " printk_pwmwf_format(wf) " err=%d", 89 + __entry->wfhw, printk_pwmwf_formatargs(wf), __entry->err) 90 + ); 91 + 92 + TRACE_EVENT(pwm_read_waveform, 93 + 94 + TP_PROTO_pwm(void *wfhw, int err), 95 + 96 + TP_ARGS_pwm(wfhw, err), 97 + 98 + TP_STRUCT__entry_pwm( 99 + __field(void *, wfhw) 100 + __field(int, err) 101 + ), 102 + 103 + TP_fast_assign_pwm( 104 + __entry->wfhw = wfhw; 105 + __entry->err = err; 106 + ), 107 + 108 + TP_printk_pwm("%p err=%d", 109 + __entry->wfhw, __entry->err) 110 + ); 111 + 112 + TRACE_EVENT(pwm_write_waveform, 113 + 114 + TP_PROTO_pwm(const void *wfhw, int err), 115 + 116 + TP_ARGS_pwm(wfhw, err), 117 + 118 + TP_STRUCT__entry_pwm( 119 + __field(const void *, wfhw) 120 + __field(int, err) 121 + ), 122 + 123 + TP_fast_assign_pwm( 124 + __entry->wfhw = wfhw; 125 + __entry->err = err; 126 + ), 127 + 128 + TP_printk_pwm("%p err=%d", 129 + __entry->wfhw, __entry->err) 130 + ); 131 + 132 + 11 133 DECLARE_EVENT_CLASS(pwm, 12 134 13 135 TP_PROTO(struct pwm_device *pwm, const struct pwm_state *state, int err), 14 136 15 137 TP_ARGS(pwm, state, err), 16 138 17 - TP_STRUCT__entry( 18 - __field(unsigned int, chipid) 19 - __field(unsigned int, hwpwm) 139 + TP_STRUCT__entry_pwm( 20 140 __field(u64, period) 21 141 __field(u64, duty_cycle) 22 142 __field(enum pwm_polarity, polarity) ··· 144 24 __field(int, err) 145 25 ), 146 26 147 - TP_fast_assign( 148 - __entry->chipid = pwm->chip->id; 149 - __entry->hwpwm = pwm->hwpwm; 27 + TP_fast_assign_pwm( 150 28 __entry->period = state->period; 151 29 __entry->duty_cycle = state->duty_cycle; 152 30 __entry->polarity = state->polarity; ··· 152 34 __entry->err = err; 153 35 ), 154 36 155 - TP_printk("pwmchip%u.%u: period=%llu duty_cycle=%llu polarity=%d enabled=%d err=%d", 156 - __entry->chipid, __entry->hwpwm, __entry->period, __entry->duty_cycle, 37 + TP_printk_pwm("period=%llu duty_cycle=%llu polarity=%d enabled=%d err=%d", 38 + __entry->period, __entry->duty_cycle, 157 39 __entry->polarity, __entry->enabled, __entry->err) 158 40 159 41 );
+1
include/uapi/linux/types.h
··· 53 53 * No conversions are necessary between 32-bit user-space and a 64-bit kernel. 54 54 */ 55 55 #define __aligned_u64 __u64 __attribute__((aligned(8))) 56 + #define __aligned_s64 __s64 __attribute__((aligned(8))) 56 57 #define __aligned_be64 __be64 __attribute__((aligned(8))) 57 58 #define __aligned_le64 __le64 __attribute__((aligned(8))) 58 59
+1
tools/iio/iio_event_monitor.c
··· 449 449 enable_events(dev_dir_name, 0); 450 450 451 451 free(chrdev_name); 452 + free(dev_dir_name); 452 453 453 454 return ret; 454 455 }