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

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

Jonathan writes:

First set of new device support, features and cleanup for IIO in 5.10 cycle, take 2

A few changes to how I write this cover letter.
* Started to use manufacturer prefixes to group changes better.
* Stop list minor formatting etc changes.
* Whilst I appreciate those changes, we don't need to call them out here.

New device support:
* adi,adxrs290
- New driver for this gyroscope with dt bindings. One fix follows.
* ams,as73211
- New driver for this colour sensor with dt bindings. Also includes
docs for XYZ modifiers as used for the CIE colour space. Sysfs docs.
* atlas,atlas-ezo-sensor
- Support O_2 sensor, includes new modifier for concentration.
- Support humidity sensor.
* ti,hdc2010
- New driver support hdc2010 and hdc2080 humidity sensors. Includes dt
bindings.

Cleanup, minor fixes and features
* core
- Make the trigger related stub functions static inline, avoiding some build
warnings.
- buffer-dmaengine. Allow adjusting bytes_used with residue info.
* dev_error_probe to replace open coded equivalent in many drivers.
* docs and comment fixes
- Fix some typos, doubled words, capitalisation and punctuation.
* dt binding conversions to yaml
- lltc,ltc2497
- lltc,ltc2632
- maxim,max11100
- maxim,max1118
- maxim,max9611
- microchip,mcp3201
- microchip,mcp342x (add to trivial devices)
- ti,adc0832
- ti,adc108s102
- ti,adc128s052
- ti,adc161s626
- ti,ads8344
- ti,tlc4541 (includes adding an accidentally dropped original binding doc)
* adi,adi-axi-adc
- Use kobj_to_dev instead of open coding.
* adi,ad5686
- Constify iio_chan_spec
* adi,ad8366
- Add HMC1119 to kconfig help text as the driver supports it.
* adi,ad9523
- Use devm for reset of probe and drop remove.
* adi,adxl372
- Tidy up alignment
- Add OF table
- Add peak mode support with some docs.
* bosch,bma220 (general tidy up)
- Fix some return codes.
- Use read_avail callback rather than open coding attrs.
- Use dev_get_drvdata rather than dance via to_spi_device()
- Mark PM functions as __maybe_unused rather than #ifdef fun.
- Drop ACPI_PTR protections and ifdefs.
- Tidy up header ordering.
- BIT and GENMASK
* broadcom,bcm_iproc
- Drop of_match_ptr protection and switch to mod_devicetable.h
Part of general move to get this anti-pattern out of IIO.
* melexis,mlx90614
- Simplify some calculations.
- Add some kernel_doc
- Use regmap poll loop rather than open coding.
- Add extended calibration option.
* sensortec,sx9310, wide ranging set of fixes and cleanups.
- Document dt-binding.
- Rename some macros to align better with spec sheet
- Fix some issues with irq handling.
- Drop of_match_ptr and ACPI_PTR macros to avoid unused warnings etc.
- Switch to probe_new
- Fix memory alignment for iio_push_to_buffers_with_timestamp()
- Use long for bitmaps to allow use of for_each_bit_set()
- Use regmap_read_poll instead of opencoding.
- Simplify error paths
- Enabled regulators at probe.
- Use trigger flags from firmware rather than forcing them in the driver.
* ti,adc081c
- Drop ACPI IDs that are not likely to be official ones and we don't believe
anyone is using.
* ti,adc108s102
- Drop CONFIG_OF and of_match_ptr protections.
* ti,adc128s052
- Drop of_match_ptr protection and include mod_devicetable.h
* ti,dac5571
- Support powerdown for mutlichannel usecases.
* xpowers,axp20x
- Convert from OF to generic fw / device properties. Unlikely anyone will
use this with anything other than devicetree, but this is part of a
general move across IIO.

* tag 'iio-for-5.10a-take2' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (96 commits)
drivers/iio/humidity/hdc2010.c:305:2-3: Unneeded semicolon
iio: accel: bma220: Remove unneeded blank lines
iio: accel: bma220: Use BIT() and GENMASK() macros
iio: accel: bma220: Group IIO headers together
iio: accel: bma220: Drop ACPI_PTR() and accompanying ifdeffery
iio: accel: bma220: Mark PM functions as __maybe_unused
iio: accel: bma220: Use dev_get_drvdata() directly
iio: accel: bma220: Convert to use ->read_avail()
iio: accel: bma220: Fix returned codes from bma220_init(), bma220_deinit()
dt-bindings: iio: adc: microchip,mcp3201 yaml conversion.
iio: buffer-dmaengine: adjust `bytes_used` with residue info
dt-bindings: iio: adc: ti,tlc4541 binding conversion
dt-bindings: iio: adc: tlc4541 - recover accidentally dropped binding doc
dt-bindings: iio: adc: ti,ads8344 yaml conversion
dt-bindings: iio: adc: ti,adc128s052 yaml conversion.
dt-bindings: iio: adc: ti,adc0832 yaml conversion.
dt-bindings: iio: adc: ti,adc161s626 yaml conversion.
dt-bindings: iio: adc: lltc,ltc2497 yaml conversion.
dt-bindings: iio: adc: ti,adc108s102 yaml conversion
dt-bindings: trivial-devices: Add mcp342x ADCs and drop separate binding doc.
...

+3693 -957
+54 -28
Documentation/ABI/testing/sysfs-bus-iio
··· 40 40 buffered samples and events for device X. 41 41 42 42 What: /sys/bus/iio/devices/iio:deviceX/sampling_frequency 43 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_sampling_frequency 43 44 What: /sys/bus/iio/devices/iio:deviceX/buffer/sampling_frequency 44 45 What: /sys/bus/iio/devices/triggerX/sampling_frequency 45 46 KernelVersion: 2.6.35 ··· 50 49 resulting sampling frequency. In many devices this 51 50 parameter has an effect on input filters etc. rather than 52 51 simply controlling when the input is sampled. As this 53 - effects data ready triggers, hardware buffers and the sysfs 52 + affects data ready triggers, hardware buffers and the sysfs 54 53 direct access interfaces, it may be found in any of the 55 - relevant directories. If it effects all of the above 54 + relevant directories. If it affects all of the above 56 55 then it is to be found in the base device directory. 57 56 58 57 What: /sys/bus/iio/devices/iio:deviceX/sampling_frequency_available 58 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_sampling_frequency_available 59 59 What: /sys/bus/iio/devices/iio:deviceX/in_proximity_sampling_frequency_available 60 60 What: /sys/.../iio:deviceX/buffer/sampling_frequency_available 61 61 What: /sys/bus/iio/devices/triggerX/sampling_frequency_available ··· 376 374 What: /sys/bus/iio/devices/iio:deviceX/in_illuminance_scale 377 375 What: /sys/bus/iio/devices/iio:deviceX/in_countY_scale 378 376 What: /sys/bus/iio/devices/iio:deviceX/in_angl_scale 377 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_x_scale 378 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_y_scale 379 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_z_scale 379 380 KernelVersion: 2.6.35 380 381 Contact: linux-iio@vger.kernel.org 381 382 Description: ··· 406 401 Hardware applied calibration offset (assumed to fix production 407 402 inaccuracies). 408 403 409 - What /sys/bus/iio/devices/iio:deviceX/in_voltageY_calibscale 410 - What /sys/bus/iio/devices/iio:deviceX/in_voltageY_supply_calibscale 411 - What /sys/bus/iio/devices/iio:deviceX/in_voltageY_i_calibscale 412 - What /sys/bus/iio/devices/iio:deviceX/in_voltageY_q_calibscale 413 - What /sys/bus/iio/devices/iio:deviceX/in_voltage_i_calibscale 414 - What /sys/bus/iio/devices/iio:deviceX/in_voltage_q_calibscale 415 - What /sys/bus/iio/devices/iio:deviceX/in_voltage_calibscale 416 - What /sys/bus/iio/devices/iio:deviceX/in_accel_x_calibscale 417 - What /sys/bus/iio/devices/iio:deviceX/in_accel_y_calibscale 418 - What /sys/bus/iio/devices/iio:deviceX/in_accel_z_calibscale 419 - What /sys/bus/iio/devices/iio:deviceX/in_anglvel_x_calibscale 420 - What /sys/bus/iio/devices/iio:deviceX/in_anglvel_y_calibscale 421 - What /sys/bus/iio/devices/iio:deviceX/in_anglvel_z_calibscale 422 - what /sys/bus/iio/devices/iio:deviceX/in_illuminance0_calibscale 423 - what /sys/bus/iio/devices/iio:deviceX/in_proximity0_calibscale 404 + What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_calibscale 405 + What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_supply_calibscale 406 + What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_i_calibscale 407 + What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_q_calibscale 408 + What: /sys/bus/iio/devices/iio:deviceX/in_voltage_i_calibscale 409 + What: /sys/bus/iio/devices/iio:deviceX/in_voltage_q_calibscale 410 + What: /sys/bus/iio/devices/iio:deviceX/in_voltage_calibscale 411 + What: /sys/bus/iio/devices/iio:deviceX/in_accel_x_calibscale 412 + What: /sys/bus/iio/devices/iio:deviceX/in_accel_y_calibscale 413 + What: /sys/bus/iio/devices/iio:deviceX/in_accel_z_calibscale 414 + What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_x_calibscale 415 + What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_y_calibscale 416 + What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_z_calibscale 417 + What: /sys/bus/iio/devices/iio:deviceX/in_illuminance0_calibscale 418 + What: /sys/bus/iio/devices/iio:deviceX/in_proximity0_calibscale 424 419 What: /sys/bus/iio/devices/iio:deviceX/in_pressureY_calibscale 425 420 What: /sys/bus/iio/devices/iio:deviceX/in_pressure_calibscale 426 421 What: /sys/bus/iio/devices/iio:deviceX/in_illuminance_calibscale ··· 488 483 If a discrete set of scale values is available, they 489 484 are listed in this attribute. 490 485 491 - What /sys/bus/iio/devices/iio:deviceX/out_voltageY_hardwaregain 486 + What: /sys/bus/iio/devices/iio:deviceX/out_voltageY_hardwaregain 487 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_hardwaregain 492 488 What: /sys/bus/iio/devices/iio:deviceX/in_intensity_red_hardwaregain 493 489 What: /sys/bus/iio/devices/iio:deviceX/in_intensity_green_hardwaregain 494 490 What: /sys/bus/iio/devices/iio:deviceX/in_intensity_blue_hardwaregain ··· 499 493 Description: 500 494 Hardware applied gain factor. If shared across all channels, 501 495 <type>_hardwaregain is used. 496 + 497 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_hardwaregain_available 498 + KernelVersion: 5.10 499 + Contact: linux-iio@vger.kernel.org 500 + Description: 501 + Lists all available hardware applied gain factors. Shared across all 502 + channels. 502 503 503 504 What: /sys/.../in_accel_filter_low_pass_3db_frequency 504 505 What: /sys/.../in_magn_filter_low_pass_3db_frequency ··· 763 750 What: /sys/.../events/in_tempY_raw_thresh_rising_value 764 751 What: /sys/.../events/in_tempY_raw_thresh_falling_value 765 752 What: /sys/.../events/in_illuminance0_thresh_falling_value 766 - what: /sys/.../events/in_illuminance0_thresh_rising_value 767 - what: /sys/.../events/in_proximity0_thresh_falling_value 768 - what: /sys/.../events/in_proximity0_thresh_rising_value 753 + What: /sys/.../events/in_illuminance0_thresh_rising_value 754 + What: /sys/.../events/in_proximity0_thresh_falling_value 755 + What: /sys/.../events/in_proximity0_thresh_rising_value 769 756 What: /sys/.../events/in_illuminance_thresh_rising_value 770 757 What: /sys/.../events/in_illuminance_thresh_falling_value 771 758 KernelVersion: 2.6.37 ··· 845 832 What: /sys/.../events/in_tempY_thresh_falling_hysteresis 846 833 What: /sys/.../events/in_tempY_thresh_either_hysteresis 847 834 What: /sys/.../events/in_illuminance0_thresh_falling_hysteresis 848 - what: /sys/.../events/in_illuminance0_thresh_rising_hysteresis 849 - what: /sys/.../events/in_illuminance0_thresh_either_hysteresis 850 - what: /sys/.../events/in_proximity0_thresh_falling_hysteresis 851 - what: /sys/.../events/in_proximity0_thresh_rising_hysteresis 852 - what: /sys/.../events/in_proximity0_thresh_either_hysteresis 835 + What: /sys/.../events/in_illuminance0_thresh_rising_hysteresis 836 + What: /sys/.../events/in_illuminance0_thresh_either_hysteresis 837 + What: /sys/.../events/in_proximity0_thresh_falling_hysteresis 838 + What: /sys/.../events/in_proximity0_thresh_rising_hysteresis 839 + What: /sys/.../events/in_proximity0_thresh_either_hysteresis 853 840 KernelVersion: 3.13 854 841 Contact: linux-iio@vger.kernel.org 855 842 Description: ··· 1026 1013 KernelVersion: 3.19 1027 1014 Contact: linux-iio@vger.kernel.org 1028 1015 Description: 1029 - Enables or disables activitity events. Depending on direction 1016 + Enables or disables activity events. Depending on direction 1030 1017 an event is generated when sensor ENTERS or LEAVES a given state. 1031 1018 1032 1019 What: /sys/.../events/in_activity_still_thresh_rising_value ··· 1346 1333 standardised CIE Erythemal Action Spectrum. UV index values range 1347 1334 from 0 (low) to >=11 (extreme). 1348 1335 1336 + What: /sys/.../iio:deviceX/in_intensity_integration_time 1349 1337 What: /sys/.../iio:deviceX/in_intensity_red_integration_time 1350 1338 What: /sys/.../iio:deviceX/in_intensity_green_integration_time 1351 1339 What: /sys/.../iio:deviceX/in_intensity_blue_integration_time ··· 1356 1342 Contact: linux-iio@vger.kernel.org 1357 1343 Description: 1358 1344 This attribute is used to get/set the integration time in 1359 - seconds. 1345 + seconds. If shared across all channels of a given type, 1346 + <type>_integration_time is used. 1360 1347 1361 1348 What: /sys/.../iio:deviceX/in_velocity_sqrt(x^2+y^2+z^2)_integration_time 1362 1349 KernelVersion: 4.0 ··· 1579 1564 What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_ethanol_raw 1580 1565 What: /sys/bus/iio/devices/iio:deviceX/in_concentration_h2_raw 1581 1566 What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_h2_raw 1567 + What: /sys/bus/iio/devices/iio:deviceX/in_concentration_o2_raw 1568 + What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_o2_raw 1582 1569 What: /sys/bus/iio/devices/iio:deviceX/in_concentration_voc_raw 1583 1570 What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_voc_raw 1584 1571 KernelVersion: 4.3 ··· 1757 1740 Contact: linux-iio@vger.kernel.org 1758 1741 Description: 1759 1742 One of the following thermocouple types: B, E, J, K, N, R, S, T. 1743 + 1744 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_x_raw 1745 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_y_raw 1746 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_z_raw 1747 + KernelVersion: 5.10 1748 + Contact: linux-iio@vger.kernel.org 1749 + Description: 1750 + Unscaled light intensity according to CIE 1931/DIN 5033 color space. 1751 + Units after application of scale are nano nanowatts per square meter.
+7
Documentation/ABI/testing/sysfs-bus-iio-accel-adxl372
··· 1 + What: /sys/bus/iio/devices/triggerX/name = "adxl372-devX-peak" 2 + KernelVersion: 3 + Contact: linux-iio@vger.kernel.org 4 + Description: 5 + The adxl372 accelerometer kernel module provides an additional trigger, 6 + which sets the device in a mode in which it will record only the peak acceleration 7 + sensed over the set period of time in the events sysfs.
+9
Documentation/ABI/testing/sysfs-bus-iio-humidity-hdc2010
··· 1 + What: /sys/bus/iio/devices/iio:deviceX/out_current_heater_raw 2 + What: /sys/bus/iio/devices/iio:deviceX/out_current_heater_raw_available 3 + KernelVersion: 5.3.8 4 + Contact: linux-iio@vger.kernel.org 5 + Description: 6 + Controls the heater device within the humidity sensor to get 7 + rid of excess condensation. 8 + 9 + Valid control values are 0 = OFF, and 1 = ON.
+44
Documentation/devicetree/bindings/iio/adc/lltc,ltc2497.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/lltc,ltc2497.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Linear Technology / Analog Devices LTC2497 ADC 8 + 9 + maintainers: 10 + - Michael Hennerich <michael.hennerich@analog.com> 11 + 12 + description: | 13 + 16bit ADC supporting up to 16 single ended or 8 differential inputs. 14 + I2C interface. 15 + 16 + properties: 17 + compatible: 18 + const: 19 + lltc,ltc2497 20 + 21 + reg: true 22 + vref-supply: true 23 + "#io-channel-cells": 24 + const: 1 25 + 26 + required: 27 + - compatible 28 + - reg 29 + - vref-supply 30 + 31 + examples: 32 + - | 33 + i2c { 34 + #address-cells = <1>; 35 + #size-cells = <0>; 36 + 37 + adc@76 { 38 + compatible = "lltc,ltc2497"; 39 + reg = <0x76>; 40 + vref-supply = <&ltc2497_reg>; 41 + #io-channel-cells = <1>; 42 + }; 43 + }; 44 + ...
-13
Documentation/devicetree/bindings/iio/adc/ltc2497.txt
··· 1 - * Linear Technology / Analog Devices LTC2497 ADC 2 - 3 - Required properties: 4 - - compatible: Must be "lltc,ltc2497" 5 - - reg: Must contain the ADC I2C address 6 - - vref-supply: The regulator supply for ADC reference voltage 7 - 8 - Example: 9 - ltc2497: adc@76 { 10 - compatible = "lltc,ltc2497"; 11 - reg = <0x76>; 12 - vref-supply = <&ltc2497_reg>; 13 - };
-18
Documentation/devicetree/bindings/iio/adc/max11100.txt
··· 1 - * Maxim max11100 Analog to Digital Converter (ADC) 2 - 3 - Required properties: 4 - - compatible: Should be "maxim,max11100" 5 - - reg: the adc unit address 6 - - vref-supply: phandle to the regulator that provides reference voltage 7 - 8 - Optional properties: 9 - - spi-max-frequency: SPI maximum frequency 10 - 11 - Example: 12 - 13 - max11100: adc@0 { 14 - compatible = "maxim,max11100"; 15 - reg = <0>; 16 - vref-supply = <&adc0_vref>; 17 - spi-max-frequency = <240000>; 18 - };
-21
Documentation/devicetree/bindings/iio/adc/max1118.txt
··· 1 - * MAX1117/MAX1118/MAX1119 8-bit, dual-channel ADCs 2 - 3 - Required properties: 4 - - compatible: Should be one of 5 - * "maxim,max1117" 6 - * "maxim,max1118" 7 - * "maxim,max1119" 8 - - reg: spi chip select number for the device 9 - - (max1118 only) vref-supply: The regulator supply for ADC reference voltage 10 - 11 - Recommended properties: 12 - - spi-max-frequency: Definition as per 13 - Documentation/devicetree/bindings/spi/spi-bus.txt 14 - 15 - Example: 16 - adc@0 { 17 - compatible = "maxim,max1118"; 18 - reg = <0>; 19 - vref-supply = <&vdd_supply>; 20 - spi-max-frequency = <1000000>; 21 - };
-27
Documentation/devicetree/bindings/iio/adc/max9611.txt
··· 1 - * Maxim max9611/max9612 current sense amplifier with 12-bits ADC interface 2 - 3 - Maxim max9611/max9612 is an high-side current sense amplifier with integrated 4 - 12-bits ADC communicating over I2c bus. 5 - The device node for this driver shall be a child of a I2c controller. 6 - 7 - Required properties 8 - - compatible: Should be "maxim,max9611" or "maxim,max9612" 9 - - reg: The 7-bits long I2c address of the device 10 - - shunt-resistor-micro-ohms: Value, in micro Ohms, of the current sense shunt 11 - resistor 12 - 13 - Example: 14 - 15 - &i2c4 { 16 - csa: adc@7c { 17 - compatible = "maxim,max9611"; 18 - reg = <0x7c>; 19 - 20 - shunt-resistor-micro-ohms = <5000>; 21 - }; 22 - }; 23 - 24 - This device node describes a current sense amplifier sitting on I2c4 bus 25 - with address 0x7c (read address is 0xf9, write address is 0xf8). 26 - A sense resistor of 0,005 Ohm is installed between RS+ and RS- current-sensing 27 - inputs.
+49
Documentation/devicetree/bindings/iio/adc/maxim,max11100.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/adc/maxim,max11100.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Maxim MAX11100 ADC 8 + 9 + maintainers: 10 + - Jacopo Mondi <jacopo@jmondi.org> 11 + 12 + description: | 13 + Single channel 16 bit ADC with SPI interface. 14 + 15 + properties: 16 + compatible: 17 + const: maxim,max11100 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + vref-supply: 23 + description: External reference, needed to establish input scaling. 24 + 25 + spi-max-frequency: 26 + minimum: 100000 27 + maximum: 4800000 28 + 29 + additionalProperties: false 30 + 31 + required: 32 + - compatible 33 + - reg 34 + - vref-supply 35 + 36 + examples: 37 + - | 38 + spi { 39 + #address-cells = <1>; 40 + #size-cells = <0>; 41 + 42 + adc@0 { 43 + compatible = "maxim,max11100"; 44 + reg = <0>; 45 + vref-supply = <&adc_vref>; 46 + spi-max-frequency = <240000>; 47 + }; 48 + }; 49 + ...
+62
Documentation/devicetree/bindings/iio/adc/maxim,max1118.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/adc/maxim,max1118.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Maxim MAX1118 and similar ADCs 8 + 9 + maintainers: 10 + - Akinobu Mita <akinobu.mita@gmail.com> 11 + 12 + description: | 13 + Dual channel 8bit ADCs. 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - maxim,max1117 19 + - maxim,max1118 20 + - maxim,max1119 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + spi-max-frequency: 26 + maximum: 5000000 27 + 28 + vref-supply: 29 + description: External reference, needed to establish input scaling 30 + 31 + if: 32 + properties: 33 + compatible: 34 + contains: 35 + const: maxim,max1118 36 + then: 37 + required: 38 + - vref-supply 39 + else: 40 + properties: 41 + vref-supply: false 42 + 43 + required: 44 + - compatible 45 + - reg 46 + 47 + additionalProperties: false 48 + 49 + examples: 50 + - | 51 + spi { 52 + #address-cells = <1>; 53 + #size-cells = <0>; 54 + 55 + adc@0 { 56 + compatible = "maxim,max1118"; 57 + reg = <0>; 58 + vref-supply = <&adc_vref>; 59 + spi-max-frequency = <1000000>; 60 + }; 61 + }; 62 + ...
+51
Documentation/devicetree/bindings/iio/adc/maxim,max9611.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/adc/maxim,max9611.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Maxim MAX9611 and similar current sense amplifiers with integrated ADCs 8 + 9 + maintainers: 10 + - Jacopo Mondi <jacopo@jmondi.org> 11 + 12 + description: | 13 + These devices combine a high-side current sense amplifier with a 12 bit ADC. 14 + They have an i2c interface. 15 + 16 + properties: 17 + compatible: 18 + enum: 19 + - maxim,max9611 20 + - maxim,max9612 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + shunt-resistor-micro-ohms: 26 + $ref: /schemas/types.yaml#/definitions/uint32 27 + description: | 28 + Value in micro Ohms of the shunt resistor connected between the RS+ and 29 + RS- inputs, across which the current is measured. Value needed to compute 30 + the scaling of the measured current. 31 + 32 + additionalProperties: false 33 + 34 + required: 35 + - compatible 36 + - reg 37 + - shunt-resistor-micro-ohms 38 + 39 + examples: 40 + - | 41 + i2c { 42 + #address-cells = <1>; 43 + #size-cells = <0>; 44 + 45 + adc@7c { 46 + compatible = "maxim,max9611"; 47 + reg = <0x7c>; 48 + shunt-resistor-micro-ohms = <5000>; 49 + }; 50 + }; 51 + ...
-57
Documentation/devicetree/bindings/iio/adc/mcp320x.txt
··· 1 - * Microchip Analog to Digital Converter (ADC) 2 - 3 - The node for this driver must be a child node of a SPI controller, hence 4 - all mandatory properties described in 5 - 6 - Documentation/devicetree/bindings/spi/spi-bus.txt 7 - 8 - must be specified. 9 - 10 - Required properties: 11 - - compatible: Must be one of the following, depending on the 12 - model: 13 - "mcp3001" (DEPRECATED) 14 - "mcp3002" (DEPRECATED) 15 - "mcp3004" (DEPRECATED) 16 - "mcp3008" (DEPRECATED) 17 - "mcp3201" (DEPRECATED) 18 - "mcp3202" (DEPRECATED) 19 - "mcp3204" (DEPRECATED) 20 - "mcp3208" (DEPRECATED) 21 - "mcp3301" (DEPRECATED) 22 - 23 - "microchip,mcp3001" 24 - "microchip,mcp3002" 25 - "microchip,mcp3004" 26 - "microchip,mcp3008" 27 - "microchip,mcp3201" 28 - "microchip,mcp3202" 29 - "microchip,mcp3204" 30 - "microchip,mcp3208" 31 - "microchip,mcp3301" 32 - "microchip,mcp3550-50" 33 - "microchip,mcp3550-60" 34 - "microchip,mcp3551" 35 - "microchip,mcp3553" 36 - 37 - NOTE: The use of the compatibles with no vendor prefix 38 - is deprecated and only listed because old DT use them. 39 - 40 - - spi-cpha, spi-cpol (boolean): 41 - Either SPI mode (0,0) or (1,1) must be used, so specify 42 - none or both of spi-cpha, spi-cpol. The MCP3550/1/3 43 - is more efficient in mode (1,1) as only 3 instead of 44 - 4 bytes need to be read from the ADC, but not all SPI 45 - masters support it. 46 - 47 - - vref-supply: Phandle to the external reference voltage supply. 48 - 49 - Examples: 50 - spi_controller { 51 - mcp3x0x@0 { 52 - compatible = "microchip,mcp3002"; 53 - reg = <0>; 54 - spi-max-frequency = <1000000>; 55 - vref-supply = <&vref_reg>; 56 - }; 57 - };
-19
Documentation/devicetree/bindings/iio/adc/mcp3422.txt
··· 1 - * Microchip mcp3421/2/3/4/6/7/8 chip family (ADC) 2 - 3 - Required properties: 4 - - compatible: Should be 5 - "microchip,mcp3421" or 6 - "microchip,mcp3422" or 7 - "microchip,mcp3423" or 8 - "microchip,mcp3424" or 9 - "microchip,mcp3425" or 10 - "microchip,mcp3426" or 11 - "microchip,mcp3427" or 12 - "microchip,mcp3428" 13 - - reg: I2C address for the device 14 - 15 - Example: 16 - adc@0 { 17 - compatible = "microchip,mcp3424"; 18 - reg = <0x68>; 19 - };
+77
Documentation/devicetree/bindings/iio/adc/microchip,mcp3201.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/microchip,mcp3201.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Microchip mcp3201 and similar ADCs 8 + 9 + maintainers: 10 + - Oskar Andero <oskar.andero@gmail.com> 11 + 12 + description: | 13 + Family of simple ADCs with an I2C inteface. 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - microchip,mcp3001 19 + - microchip,mcp3002 20 + - microchip,mcp3004 21 + - microchip,mcp3008 22 + - microchip,mcp3201 23 + - microchip,mcp3202 24 + - microchip,mcp3204 25 + - microchip,mcp3208 26 + - microchip,mcp3301 27 + - microchip,mcp3550-50 28 + - microchip,mcp3550-60 29 + - microchip,mcp3551 30 + - microchip,mcp3553 31 + 32 + reg: 33 + maxItems: 1 34 + 35 + spi-max-frequency: true 36 + spi-cpha: true 37 + spi-cpol: true 38 + 39 + vref-supply: 40 + description: External reference. 41 + 42 + "#io-channel-cells": 43 + const: 1 44 + 45 + dependencies: 46 + spi-cpol: [ spi-cpha ] 47 + spi-cpha: [ spi-cpol ] 48 + 49 + required: 50 + - compatible 51 + - reg 52 + - vref-supply 53 + 54 + additionalProperties: false 55 + 56 + examples: 57 + - | 58 + spi { 59 + #address-cells = <1>; 60 + #size-cells = <0>; 61 + 62 + adc@0 { 63 + compatible = "microchip,mcp3002"; 64 + reg = <0>; 65 + vref-supply = <&vref_reg>; 66 + spi-cpha; 67 + spi-cpol; 68 + #io-channel-cells = <1>; 69 + }; 70 + adc@1 { 71 + compatible = "microchip,mcp3002"; 72 + reg = <1>; 73 + vref-supply = <&vref_reg>; 74 + spi-max-frequency = <1500000>; 75 + }; 76 + }; 77 + ...
+56
Documentation/devicetree/bindings/iio/adc/ti,adc0832.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/ti,adc0832.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Texas Instruments ADC0832 and similar ADCs 8 + 9 + maintainers: 10 + - Akinobu Mita <akinobu.mita@gmail.com> 11 + 12 + description: | 13 + 8 bit ADCs with 1, 2, 4 or 8 inputs for single ended or differential 14 + conversion. 15 + 16 + properties: 17 + compatible: 18 + enum: 19 + - ti,adc0831 20 + - ti,adc0832 21 + - ti,adc0834 22 + - ti,adc0838 23 + 24 + reg: 25 + maxItems: 1 26 + 27 + spi-max-frequency: true 28 + 29 + vref-supply: 30 + description: External reference, needed to establish input scaling 31 + 32 + "#io-channel-cells": 33 + const: 1 34 + 35 + required: 36 + - compatible 37 + - reg 38 + - vref-supply 39 + 40 + additionalProperties: false 41 + 42 + examples: 43 + - | 44 + spi { 45 + #address-cells = <1>; 46 + #size-cells = <0>; 47 + 48 + adc@0 { 49 + compatible = "ti,adc0832"; 50 + reg = <0>; 51 + vref-supply = <&vdd_supply>; 52 + spi-max-frequency = <200000>; 53 + #io-channel-cells = <1>; 54 + }; 55 + }; 56 + ...
+47
Documentation/devicetree/bindings/iio/adc/ti,adc108s102.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/ti,adc108s102.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Texas Instruments ADC108S102 and ADC128S102 8 + 9 + maintainers: 10 + - Bogdan Pricop <bogdan.pricop@emutex.com> 11 + 12 + description: | 13 + Family of 8 channel, 10/12 bit, SPI, single ended ADCs. 14 + 15 + properties: 16 + compatible: 17 + const: 18 + ti,adc108s102 19 + 20 + reg: true 21 + vref-supply: true 22 + spi-max-frequency: true 23 + "#io-channel-cells": 24 + const: 1 25 + 26 + required: 27 + - compatible 28 + - reg 29 + - vref-supply 30 + 31 + additionalProperties: false 32 + 33 + examples: 34 + - | 35 + spi { 36 + #address-cells= <1>; 37 + #size-cells = <0>; 38 + 39 + adc@0 { 40 + compatible = "ti,adc108s102"; 41 + reg = <0>; 42 + vref-supply = <&vdd_supply>; 43 + spi-max-frequency = <1000000>; 44 + #io-channel-cells = <1>; 45 + }; 46 + }; 47 + ...
+59
Documentation/devicetree/bindings/iio/adc/ti,adc128s052.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/ti,adc128s052.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Texas Instruments ADC128S052 and similar ADCs 8 + 9 + maintainers: 10 + - Angelo Compagnucci <angelo.compagnucci@gmail.com> 11 + 12 + description: | 13 + Family of 12 bit SPI ADCs with 2 to 8 channels with a range of different 14 + target sample rates. 15 + 16 + properties: 17 + compatible: 18 + enum: 19 + - ti,adc122s021 20 + - ti,adc122s051 21 + - ti,adc122s101 22 + - ti,adc124s021 23 + - ti,adc124s051 24 + - ti,adc124s101 25 + - ti,adc128s052 26 + 27 + reg: 28 + maxItems: 1 29 + 30 + spi-max-frequency: true 31 + 32 + vref-supply: true 33 + 34 + "#io-channel-cells": 35 + const: 1 36 + 37 + required: 38 + - compatible 39 + - reg 40 + - vref-supply 41 + 42 + additionalProperties: false 43 + 44 + examples: 45 + - | 46 + #include <dt-bindings/interrupt-controller/irq.h> 47 + spi { 48 + #address-cells = <1>; 49 + #size-cells = <0>; 50 + 51 + adc@0 { 52 + compatible = "ti,adc128s052"; 53 + reg = <0>; 54 + vref-supply = <&vdd_supply>; 55 + spi-max-frequency = <1000000>; 56 + #io-channel-cells = <1>; 57 + }; 58 + }; 59 + ...
+51
Documentation/devicetree/bindings/iio/adc/ti,adc161s626.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/ti,adc161s626.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Texas Instruments ADC141S626 and ADC161S626 ADCs 8 + 9 + maintainers: 10 + - Matt Ranostay <matt.ranostay@konsulko.com> 11 + 12 + description: | 13 + Single channel 14/16bit differential ADCs 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - ti,adc141s626 19 + - ti,adc161s626 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + spi-max-frequency: true 25 + 26 + vdda-supply: true 27 + 28 + "#io-channel-cells": 29 + const: 1 30 + 31 + required: 32 + - compatible 33 + - reg 34 + 35 + additionalProperties: false 36 + 37 + examples: 38 + - | 39 + spi { 40 + #address-cells = <1>; 41 + #size-cells = <0>; 42 + 43 + adc@0 { 44 + compatible = "ti,adc161s626"; 45 + vdda-supply = <&vdda_fixed>; 46 + reg = <0>; 47 + spi-max-frequency = <4300000>; 48 + #io-channel-cells = <1>; 49 + }; 50 + }; 51 + ...
+51
Documentation/devicetree/bindings/iio/adc/ti,ads8344.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/ti,ads8344.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Texas Instruments ADS8344 ADC 8 + 9 + maintainers: 10 + - Gregory Clement <gregory.clement@bootlin.com> 11 + 12 + description: | 13 + 16bit 8-channel ADC with single ended inputs. 14 + 15 + properties: 16 + compatible: 17 + const: ti,ads8344 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + spi-max-frequency: true 23 + 24 + vref-supply: 25 + description: Supply the 2.5V or 5V reference voltage 26 + 27 + "#io-channel-cells": 28 + const: 1 29 + 30 + required: 31 + - compatible 32 + - reg 33 + - vref-supply 34 + 35 + additionalProperties: false 36 + 37 + examples: 38 + - | 39 + spi { 40 + #address-cells = <1>; 41 + #size-cells = <0>; 42 + 43 + adc@0 { 44 + compatible = "ti,ads8344"; 45 + reg = <0>; 46 + vref-supply = <&refin_supply>; 47 + spi-max-frequency = <10000000>; 48 + #io-channel-cells = <1>; 49 + }; 50 + }; 51 + ...
+52
Documentation/devicetree/bindings/iio/adc/ti,tlc4541.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/ti,tlc4541.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Texas Instruments TLC4541 and similar ADCs 8 + 9 + maintainers: 10 + - Phil Reid <preid@electromag.com.au> 11 + 12 + description: | 13 + 14/16bit single channel ADC with SPI interface. 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - ti,tlc3541 19 + - ti,tlc4541 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + spi-max-frequency: true 25 + 26 + vref-supply: true 27 + 28 + "#io-channel-cells": 29 + const: 1 30 + 31 + required: 32 + - compatible 33 + - reg 34 + - vref-supply 35 + 36 + additionalProperties: false 37 + 38 + examples: 39 + - | 40 + spi { 41 + #address-cells = <1>; 42 + #size-cells = <0>; 43 + 44 + adc@0 { 45 + compatible = "ti,tlc4541"; 46 + reg = <0>; 47 + vref-supply = <&vdd_supply>; 48 + spi-max-frequency = <200000>; 49 + #io-channel-cells = <1>; 50 + }; 51 + }; 52 + ...
-19
Documentation/devicetree/bindings/iio/adc/ti-adc0832.txt
··· 1 - * Texas Instruments' ADC0831/ADC0832/ADC0832/ADC0838 2 - 3 - Required properties: 4 - - compatible: Should be one of 5 - * "ti,adc0831" 6 - * "ti,adc0832" 7 - * "ti,adc0834" 8 - * "ti,adc0838" 9 - - reg: spi chip select number for the device 10 - - vref-supply: The regulator supply for ADC reference voltage 11 - - spi-max-frequency: Max SPI frequency to use (< 400000) 12 - 13 - Example: 14 - adc@0 { 15 - compatible = "ti,adc0832"; 16 - reg = <0>; 17 - vref-supply = <&vdd_supply>; 18 - spi-max-frequency = <200000>; 19 - };
-18
Documentation/devicetree/bindings/iio/adc/ti-adc108s102.txt
··· 1 - * Texas Instruments' ADC108S102 and ADC128S102 ADC chip 2 - 3 - Required properties: 4 - - compatible: Should be "ti,adc108s102" 5 - - reg: spi chip select number for the device 6 - - vref-supply: The regulator supply for ADC reference voltage 7 - 8 - Recommended properties: 9 - - spi-max-frequency: Definition as per 10 - Documentation/devicetree/bindings/spi/spi-bus.txt 11 - 12 - Example: 13 - adc@0 { 14 - compatible = "ti,adc108s102"; 15 - reg = <0>; 16 - vref-supply = <&vdd_supply>; 17 - spi-max-frequency = <1000000>; 18 - };
-25
Documentation/devicetree/bindings/iio/adc/ti-adc128s052.txt
··· 1 - * Texas Instruments' ADC128S052, ADC122S021 and ADC124S021 ADC chip 2 - 3 - Required properties: 4 - - compatible: Should be one of: 5 - - "ti,adc128s052" 6 - - "ti,adc122s021" 7 - - "ti,adc122s051" 8 - - "ti,adc122s101" 9 - - "ti,adc124s021" 10 - - "ti,adc124s051" 11 - - "ti,adc124s101" 12 - - reg: spi chip select number for the device 13 - - vref-supply: The regulator supply for ADC reference voltage 14 - 15 - Recommended properties: 16 - - spi-max-frequency: Definition as per 17 - Documentation/devicetree/bindings/spi/spi-bus.txt 18 - 19 - Example: 20 - adc@0 { 21 - compatible = "ti,adc128s052"; 22 - reg = <0>; 23 - vref-supply = <&vdd_supply>; 24 - spi-max-frequency = <1000000>; 25 - };
-18
Documentation/devicetree/bindings/iio/adc/ti-adc161s626.txt
··· 1 - * Texas Instruments ADC141S626 and ADC161S626 chips 2 - 3 - Required properties: 4 - - compatible: Should be "ti,adc141s626" or "ti,adc161s626" 5 - - reg: spi chip select number for the device 6 - - vdda-supply: supply voltage to VDDA pin 7 - 8 - Recommended properties: 9 - - spi-max-frequency: Definition as per 10 - Documentation/devicetree/bindings/spi/spi-bus.txt 11 - 12 - Example: 13 - adc@0 { 14 - compatible = "ti,adc161s626"; 15 - vdda-supply = <&vdda_fixed>; 16 - reg = <0>; 17 - spi-max-frequency = <4300000>; 18 - };
-19
Documentation/devicetree/bindings/iio/adc/ti-ads8344.txt
··· 1 - * Texas Instruments ADS8344 A/DC chip 2 - 3 - Required properties: 4 - - compatible: Must be "ti,ads8344" 5 - - reg: SPI chip select number for the device 6 - - vref-supply: phandle to a regulator node that supplies the 7 - reference voltage 8 - 9 - Recommended properties: 10 - - spi-max-frequency: Definition as per 11 - Documentation/devicetree/bindings/spi/spi-bus.txt 12 - 13 - Example: 14 - adc@0 { 15 - compatible = "ti,ads8344"; 16 - reg = <0>; 17 - vref-supply = <&refin_supply>; 18 - spi-max-frequency = <10000000>; 19 - };
+4
Documentation/devicetree/bindings/iio/chemical/atlas,sensor.yaml
··· 19 19 http://www.atlas-scientific.com/_files/_datasheets/_oem/pH_oem_datasheet.pdf 20 20 http://www.atlas-scientific.com/_files/_datasheets/_oem/RTD_oem_datasheet.pdf 21 21 http://www.atlas-scientific.com/_files/_datasheets/_probe/EZO_CO2_Datasheet.pdf 22 + https://www.atlas-scientific.com/files/EZO_O2_datasheet.pdf 23 + https://www.atlas-scientific.com/files/EZO_HUM_Datasheet.pdf 22 24 23 25 properties: 24 26 compatible: ··· 31 29 - atlas,ph-sm 32 30 - atlas,rtd-sm 33 31 - atlas,co2-ezo 32 + - atlas,o2-ezo 33 + - atlas,hum-ezo 34 34 35 35 reg: 36 36 maxItems: 1
+77
Documentation/devicetree/bindings/iio/dac/lltc,ltc2632.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: "http://devicetree.org/schemas/iio/dac/lltc,ltc2632.yaml#" 5 + $schema: "http://devicetree.org/meta-schemas/core.yaml#" 6 + 7 + title: Linear Technology LTC263x 12-/10-/8-Bit Rail-to-Rail DAC 8 + 9 + maintainers: 10 + - Michael Hennerich <michael.hennerich@analog.com> 11 + 12 + description: | 13 + Bindings for the Linear Technology LTC2632/2634/2636 DAC 14 + Datasheet can be found here: https://www.analog.com/media/en/technical-documentation/data-sheets/LTC263[246].pdf 15 + 16 + properties: 17 + compatible: 18 + enum: 19 + - lltc,ltc2632-l12 20 + - lltc,ltc2632-l10 21 + - lltc,ltc2632-l8 22 + - lltc,ltc2632-h12 23 + - lltc,ltc2632-h10 24 + - lltc,ltc2632-h8 25 + - lltc,ltc2634-l12 26 + - lltc,ltc2634-l10 27 + - lltc,ltc2634-l8 28 + - lltc,ltc2634-h12 29 + - lltc,ltc2634-h10 30 + - lltc,ltc2634-h8 31 + - lltc,ltc2636-l12 32 + - lltc,ltc2636-l10 33 + - lltc,ltc2636-l8 34 + - lltc,ltc2636-h12 35 + - lltc,ltc2636-h10 36 + - lltc,ltc2636-h8 37 + 38 + reg: 39 + maxItems: 1 40 + 41 + spi-max-frequency: 42 + maximum: 2000000 43 + 44 + vref-supply: 45 + description: 46 + Phandle to the external reference voltage supply. This should 47 + only be set if there is an external reference voltage connected to the VREF 48 + pin. If the property is not set the internal reference is used. 49 + 50 + required: 51 + - compatible 52 + - reg 53 + 54 + additionalProperties: false 55 + 56 + examples: 57 + - | 58 + vref: regulator-vref { 59 + compatible = "regulator-fixed"; 60 + regulator-name = "vref-ltc2632"; 61 + regulator-min-microvolt = <1250000>; 62 + regulator-max-microvolt = <1250000>; 63 + regulator-always-on; 64 + }; 65 + 66 + spi { 67 + #address-cells = <1>; 68 + #size-cells = <0>; 69 + 70 + dac@0 { 71 + compatible = "lltc,ltc2632"; 72 + reg = <0>; /* CS0 */ 73 + spi-max-frequency = <1000000>; 74 + vref-supply = <&vref>; 75 + }; 76 + }; 77 + ...
-49
Documentation/devicetree/bindings/iio/dac/ltc2632.txt
··· 1 - Linear Technology LTC2632/2634/2636 DAC 2 - 3 - Required properties: 4 - - compatible: Has to contain one of the following: 5 - lltc,ltc2632-l12 6 - lltc,ltc2632-l10 7 - lltc,ltc2632-l8 8 - lltc,ltc2632-h12 9 - lltc,ltc2632-h10 10 - lltc,ltc2632-h8 11 - lltc,ltc2634-l12 12 - lltc,ltc2634-l10 13 - lltc,ltc2634-l8 14 - lltc,ltc2634-h12 15 - lltc,ltc2634-h10 16 - lltc,ltc2634-h8 17 - lltc,ltc2636-l12 18 - lltc,ltc2636-l10 19 - lltc,ltc2636-l8 20 - lltc,ltc2636-h12 21 - lltc,ltc2636-h10 22 - lltc,ltc2636-h8 23 - 24 - Property rules described in Documentation/devicetree/bindings/spi/spi-bus.txt 25 - apply. In particular, "reg" and "spi-max-frequency" properties must be given. 26 - 27 - Optional properties: 28 - - vref-supply: Phandle to the external reference voltage supply. This should 29 - only be set if there is an external reference voltage connected to the VREF 30 - pin. If the property is not set the internal reference is used. 31 - 32 - Example: 33 - 34 - vref: regulator-vref { 35 - compatible = "regulator-fixed"; 36 - regulator-name = "vref-ltc2632"; 37 - regulator-min-microvolt = <1250000>; 38 - regulator-max-microvolt = <1250000>; 39 - regulator-always-on; 40 - }; 41 - 42 - spi_master { 43 - dac: ltc2632@0 { 44 - compatible = "lltc,ltc2632-l12"; 45 - reg = <0>; /* CS0 */ 46 - spi-max-frequency = <1000000>; 47 - vref-supply = <&vref>; /* optional */ 48 - }; 49 - };
+53
Documentation/devicetree/bindings/iio/gyroscope/adi,adxrs290.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + # Copyright 2020 Analog Devices Inc. 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/iio/gyroscope/adi,adxrs290.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: Analog Devices ADXRS290 Dual-Axis MEMS Gyroscope 9 + 10 + maintainers: 11 + - Nishant Malpani <nish.malpani25@gmail.com> 12 + 13 + description: | 14 + Bindings for the Analog Devices ADXRS290 dual-axis MEMS gyroscope device. 15 + https://www.analog.com/media/en/technical-documentation/data-sheets/ADXRS290.pdf 16 + 17 + properties: 18 + compatible: 19 + const: adi,adxrs290 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + spi-max-frequency: 25 + maximum: 5000000 26 + 27 + spi-cpol: true 28 + 29 + spi-cpha: true 30 + 31 + required: 32 + - compatible 33 + - reg 34 + - spi-max-frequency 35 + - spi-cpol 36 + - spi-cpha 37 + 38 + additionalProperties: false 39 + 40 + examples: 41 + - | 42 + spi { 43 + #address-cells = <1>; 44 + #size-cells = <0>; 45 + gyro@0 { 46 + compatible = "adi,adxrs290"; 47 + reg = <0>; 48 + spi-max-frequency = <5000000>; 49 + spi-cpol; 50 + spi-cpha; 51 + }; 52 + }; 53 + ...
+45
Documentation/devicetree/bindings/iio/humidity/ti,hdc2010.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/humidity/ti,hdc2010.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: HDC2010/HDC2080 humidity and temperature iio sensors 8 + 9 + maintainers: 10 + - Eugene Zaikonnikov <ez@norophonic.com> 11 + 12 + description: | 13 + Relative humidity and tempereature sensors on I2C bus 14 + 15 + Datasheets are available at: 16 + http://www.ti.com/product/HDC2010/datasheet 17 + http://www.ti.com/product/HDC2080/datasheet 18 + 19 + properties: 20 + compatible: 21 + enum: 22 + - ti,hdc2010 23 + - ti,hdc2080 24 + 25 + vdd-supply: 26 + maxItems: 1 27 + 28 + reg: 29 + maxItems: 1 30 + 31 + required: 32 + - compatible 33 + - reg 34 + 35 + examples: 36 + - | 37 + i2c0 { 38 + #address-cells = <1>; 39 + #size-cells = <0>; 40 + 41 + humidity@40 { 42 + compatible = "ti,hdc2010"; 43 + reg = <0x40>; 44 + }; 45 + };
+54
Documentation/devicetree/bindings/iio/light/ams,as73211.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iio/light/ams,as73211.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: AMS AS73211 JENCOLOR(R) Digital XYZ Sensor 8 + 9 + maintainers: 10 + - Christian Eggers <ceggers@arri.de> 11 + 12 + description: | 13 + XYZ True Color Sensor with I2C Interface 14 + https://ams.com/documents/20143/36005/AS73211_DS000556_3-01.pdf/a65474c0-b302-c2fd-e30a-c98df87616df 15 + 16 + properties: 17 + compatible: 18 + enum: 19 + - ams,as73211 20 + 21 + reg: 22 + description: 23 + I2C address of the device (0x74...0x77). 24 + maxItems: 1 25 + 26 + interrupts: 27 + description: 28 + Interrupt specifier for the READY interrupt generated by the device. 29 + maxItems: 1 30 + 31 + required: 32 + - compatible 33 + - reg 34 + 35 + additionalProperties: false 36 + 37 + examples: 38 + - | 39 + #include <dt-bindings/interrupt-controller/irq.h> 40 + 41 + i2c { 42 + #address-cells = <1>; 43 + #size-cells = <0>; 44 + 45 + as73211@74 { 46 + compatible = "ams,as73211"; 47 + reg = <0x74>; 48 + pinctrl-names = "default"; 49 + pinctrl-0 = <&pinctrl_color_sensor>; 50 + interrupt-parent = <&gpio2>; 51 + interrupts = <19 IRQ_TYPE_EDGE_RISING>; /* READY */ 52 + }; 53 + }; 54 + ...
+65
Documentation/devicetree/bindings/iio/proximity/semtech,sx9310.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/proximity/semtech,sx9310.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Semtech's SX9310 capacitive proximity sensor 8 + 9 + maintainers: 10 + - Daniel Campello <campello@chromium.org> 11 + 12 + description: | 13 + Semtech's SX9310/SX9311 capacitive proximity/button solution. 14 + 15 + Specifications about the devices can be found at: 16 + https://www.semtech.com/products/smart-sensing/sar-sensors/sx9310 17 + 18 + properties: 19 + compatible: 20 + enum: 21 + - semtech,sx9310 22 + - semtech,sx9311 23 + 24 + reg: 25 + maxItems: 1 26 + 27 + interrupts: 28 + description: 29 + The sole interrupt generated by the device used to announce the 30 + preceding reading request has finished and that data is 31 + available or that a close/far proximity event has happened. 32 + maxItems: 1 33 + 34 + vdd-supply: 35 + description: Main power supply 36 + 37 + svdd-supply: 38 + description: Host interface power supply 39 + 40 + "#io-channel-cells": 41 + const: 1 42 + 43 + required: 44 + - compatible 45 + - reg 46 + - "#io-channel-cells" 47 + 48 + additionalProperties: false 49 + 50 + examples: 51 + - | 52 + #include <dt-bindings/interrupt-controller/irq.h> 53 + i2c { 54 + #address-cells = <1>; 55 + #size-cells = <0>; 56 + proximity@28 { 57 + compatible = "semtech,sx9310"; 58 + reg = <0x28>; 59 + interrupt-parent = <&pio>; 60 + interrupts = <5 IRQ_TYPE_LEVEL_LOW 5>; 61 + vdd-supply = <&pp3300_a>; 62 + svdd-supply = <&pp1800_prox>; 63 + #io-channel-cells = <1>; 64 + }; 65 + };
+16
Documentation/devicetree/bindings/trivial-devices.yaml
··· 128 128 - mcube,mc3230 129 129 # MEMSIC 2-axis 8-bit digital accelerometer 130 130 - memsic,mxc6225 131 + # Microchip differential I2C ADC, 1 Channel, 18 bit 132 + - microchip,mcp3421 133 + # Microchip differential I2C ADC, 2 Channel, 18 bit 134 + - microchip,mcp3422 135 + # Microchip differential I2C ADC, 2 Channel, 18 bit 136 + - microchip,mcp3423 137 + # Microchip differential I2C ADC, 4 Channel, 18 bit 138 + - microchip,mcp3424 139 + # Microchip differential I2C ADC, 1 Channel, 16 bit 140 + - microchip,mcp3425 141 + # Microchip differential I2C ADC, 2 Channel, 16 bit 142 + - microchip,mcp3426 143 + # Microchip differential I2C ADC, 2 Channel, 16 bit 144 + - microchip,mcp3427 145 + # Microchip differential I2C ADC, 4 Channel, 16 bit 146 + - microchip,mcp3428 131 147 # Microchip 7-bit Single I2C Digital POT (5k) 132 148 - microchip,mcp4017-502 133 149 # Microchip 7-bit Single I2C Digital POT (10k)
+14
MAINTAINERS
··· 943 943 F: arch/arm64/boot/dts/amd/amd-seattle-xgbe*.dtsi 944 944 F: drivers/net/ethernet/amd/xgbe/ 945 945 946 + AMS AS73211 DRIVER 947 + M: Christian Eggers <ceggers@arri.de> 948 + L: linux-iio@vger.kernel.org 949 + S: Maintained 950 + F: Documentation/devicetree/bindings/iio/light/ams,as73211.yaml 951 + F: drivers/iio/light/as73211.c 952 + 946 953 ANALOG DEVICES INC AD5686 DRIVER 947 954 M: Michael Hennerich <Michael.Hennerich@analog.com> 948 955 L: linux-pm@vger.kernel.org ··· 1114 1107 L: linux-media@vger.kernel.org 1115 1108 S: Maintained 1116 1109 F: drivers/media/i2c/adv7842* 1110 + 1111 + ANALOG DEVICES INC ADXRS290 DRIVER 1112 + M: Nishant Malpani <nish.malpani25@gmail.com> 1113 + L: linux-iio@vger.kernel.org 1114 + S: Supported 1115 + F: drivers/iio/gyro/adxrs290.c 1116 + F: Documentation/devicetree/bindings/iio/gyroscope/adi,adxrs290.yaml 1117 1117 1118 1118 ANALOG DEVICES INC ASOC CODEC DRIVERS 1119 1119 M: Lars-Peter Clausen <lars@metafoo.de>
+299 -12
drivers/iio/accel/adxl372.c
··· 5 5 * Copyright 2018 Analog Devices Inc. 6 6 */ 7 7 8 + #include <linux/bitfield.h> 8 9 #include <linux/bitops.h> 9 10 #include <linux/interrupt.h> 10 11 #include <linux/irq.h> ··· 114 113 #define ADXL372_STATUS_1_AWAKE(x) (((x) >> 6) & 0x1) 115 114 #define ADXL372_STATUS_1_ERR_USR_REGS(x) (((x) >> 7) & 0x1) 116 115 116 + /* ADXL372_STATUS_2 */ 117 + #define ADXL372_STATUS_2_INACT(x) (((x) >> 4) & 0x1) 118 + #define ADXL372_STATUS_2_ACT(x) (((x) >> 5) & 0x1) 119 + #define ADXL372_STATUS_2_AC2(x) (((x) >> 6) & 0x1) 120 + 117 121 /* ADXL372_INT1_MAP */ 118 122 #define ADXL372_INT1_MAP_DATA_RDY_MSK BIT(0) 119 123 #define ADXL372_INT1_MAP_DATA_RDY_MODE(x) (((x) & 0x1) << 0) ··· 137 131 #define ADXL372_INT1_MAP_LOW_MSK BIT(7) 138 132 #define ADXL372_INT1_MAP_LOW_MODE(x) (((x) & 0x1) << 7) 139 133 134 + /* ADX372_THRESH */ 135 + #define ADXL372_THRESH_VAL_H_MSK GENMASK(10, 3) 136 + #define ADXL372_THRESH_VAL_H_SEL(x) FIELD_GET(ADXL372_THRESH_VAL_H_MSK, x) 137 + #define ADXL372_THRESH_VAL_L_MSK GENMASK(2, 0) 138 + #define ADXL372_THRESH_VAL_L_SEL(x) FIELD_GET(ADXL372_THRESH_VAL_L_MSK, x) 139 + 140 140 /* The ADXL372 includes a deep, 512 sample FIFO buffer */ 141 141 #define ADXL372_FIFO_SIZE 512 142 + #define ADXL372_X_AXIS_EN(x) ((x) & BIT(0)) 143 + #define ADXL372_Y_AXIS_EN(x) ((x) & BIT(1)) 144 + #define ADXL372_Z_AXIS_EN(x) ((x) & BIT(2)) 142 145 143 146 /* 144 147 * At +/- 200g with 12-bit resolution, scale is computed as: ··· 237 222 { BIT(0) | BIT(1) | BIT(2), ADXL372_XYZ_FIFO }, 238 223 }; 239 224 225 + static const struct iio_event_spec adxl372_events[] = { 226 + { 227 + .type = IIO_EV_TYPE_THRESH, 228 + .dir = IIO_EV_DIR_RISING, 229 + .mask_separate = BIT(IIO_EV_INFO_VALUE), 230 + .mask_shared_by_all = BIT(IIO_EV_INFO_PERIOD) | BIT(IIO_EV_INFO_ENABLE), 231 + }, { 232 + .type = IIO_EV_TYPE_THRESH, 233 + .dir = IIO_EV_DIR_FALLING, 234 + .mask_separate = BIT(IIO_EV_INFO_VALUE), 235 + .mask_shared_by_all = BIT(IIO_EV_INFO_PERIOD) | BIT(IIO_EV_INFO_ENABLE), 236 + }, 237 + }; 238 + 240 239 #define ADXL372_ACCEL_CHANNEL(index, reg, axis) { \ 241 240 .type = IIO_ACCEL, \ 242 241 .address = reg, \ ··· 268 239 .shift = 4, \ 269 240 .endianness = IIO_BE, \ 270 241 }, \ 242 + .event_spec = adxl372_events, \ 243 + .num_event_specs = ARRAY_SIZE(adxl372_events) \ 271 244 } 272 245 273 246 static const struct iio_chan_spec adxl372_channels[] = { ··· 283 252 struct device *dev; 284 253 struct regmap *regmap; 285 254 struct iio_trigger *dready_trig; 255 + struct iio_trigger *peak_datardy_trig; 286 256 enum adxl372_fifo_mode fifo_mode; 287 257 enum adxl372_fifo_format fifo_format; 258 + unsigned int fifo_axis_mask; 288 259 enum adxl372_op_mode op_mode; 289 260 enum adxl372_act_proc_mode act_proc_mode; 290 261 enum adxl372_odr odr; ··· 294 261 u32 act_time_ms; 295 262 u32 inact_time_ms; 296 263 u8 fifo_set_size; 297 - u8 int1_bitmask; 298 - u8 int2_bitmask; 264 + unsigned long int1_bitmask; 265 + unsigned long int2_bitmask; 299 266 u16 watermark; 300 267 __be16 fifo_buf[ADXL372_FIFO_SIZE]; 268 + bool peak_fifo_mode_en; 269 + struct mutex threshold_m; /* lock for threshold */ 301 270 }; 302 271 303 272 static const unsigned long adxl372_channel_masks[] = { ··· 310 275 BIT(0) | BIT(1) | BIT(2), 311 276 0 312 277 }; 278 + 279 + static ssize_t adxl372_read_threshold_value(struct iio_dev *indio_dev, unsigned int addr, 280 + u16 *threshold) 281 + { 282 + struct adxl372_state *st = iio_priv(indio_dev); 283 + __be16 raw_regval; 284 + u16 regval; 285 + int ret; 286 + 287 + ret = regmap_bulk_read(st->regmap, addr, &raw_regval, sizeof(raw_regval)); 288 + if (ret < 0) 289 + return ret; 290 + 291 + regval = be16_to_cpu(raw_regval); 292 + regval >>= 5; 293 + 294 + *threshold = regval; 295 + 296 + return 0; 297 + } 298 + 299 + static ssize_t adxl372_write_threshold_value(struct iio_dev *indio_dev, unsigned int addr, 300 + u16 threshold) 301 + { 302 + struct adxl372_state *st = iio_priv(indio_dev); 303 + int ret; 304 + 305 + mutex_lock(&st->threshold_m); 306 + ret = regmap_write(st->regmap, addr, ADXL372_THRESH_VAL_H_SEL(threshold)); 307 + if (ret < 0) 308 + goto unlock; 309 + 310 + ret = regmap_update_bits(st->regmap, addr + 1, GENMASK(7, 5), 311 + ADXL372_THRESH_VAL_L_SEL(threshold) << 5); 312 + 313 + unlock: 314 + mutex_unlock(&st->threshold_m); 315 + 316 + return ret; 317 + } 313 318 314 319 static int adxl372_read_axis(struct adxl372_state *st, u8 addr) 315 320 { ··· 528 453 } 529 454 530 455 static int adxl372_set_interrupts(struct adxl372_state *st, 531 - unsigned char int1_bitmask, 532 - unsigned char int2_bitmask) 456 + unsigned long int1_bitmask, 457 + unsigned long int2_bitmask) 533 458 { 534 459 int ret; 535 460 ··· 598 523 return ret; 599 524 } 600 525 526 + static void adxl372_arrange_axis_data(struct adxl372_state *st, __be16 *sample) 527 + { 528 + __be16 axis_sample[3]; 529 + int i = 0; 530 + 531 + memset(axis_sample, 0, 3 * sizeof(__be16)); 532 + if (ADXL372_X_AXIS_EN(st->fifo_axis_mask)) 533 + axis_sample[i++] = sample[0]; 534 + if (ADXL372_Y_AXIS_EN(st->fifo_axis_mask)) 535 + axis_sample[i++] = sample[1]; 536 + if (ADXL372_Z_AXIS_EN(st->fifo_axis_mask)) 537 + axis_sample[i++] = sample[2]; 538 + 539 + memcpy(sample, axis_sample, 3 * sizeof(__be16)); 540 + } 541 + 542 + static void adxl372_push_event(struct iio_dev *indio_dev, s64 timestamp, u8 status2) 543 + { 544 + unsigned int ev_dir = IIO_EV_DIR_NONE; 545 + 546 + if (ADXL372_STATUS_2_ACT(status2)) 547 + ev_dir = IIO_EV_DIR_RISING; 548 + 549 + if (ADXL372_STATUS_2_INACT(status2)) 550 + ev_dir = IIO_EV_DIR_FALLING; 551 + 552 + if (ev_dir != IIO_EV_DIR_NONE) 553 + iio_push_event(indio_dev, 554 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X_OR_Y_OR_Z, 555 + IIO_EV_TYPE_THRESH, ev_dir), 556 + timestamp); 557 + } 558 + 601 559 static irqreturn_t adxl372_trigger_handler(int irq, void *p) 602 560 { 603 561 struct iio_poll_func *pf = p; ··· 643 535 ret = adxl372_get_status(st, &status1, &status2, &fifo_entries); 644 536 if (ret < 0) 645 537 goto err; 538 + 539 + adxl372_push_event(indio_dev, iio_get_time_ns(indio_dev), status2); 646 540 647 541 if (st->fifo_mode != ADXL372_FIFO_BYPASSED && 648 542 ADXL372_STATUS_1_FIFO_FULL(status1)) { ··· 664 554 goto err; 665 555 666 556 /* Each sample is 2 bytes */ 667 - for (i = 0; i < fifo_entries; i += st->fifo_set_size) 557 + for (i = 0; i < fifo_entries; i += st->fifo_set_size) { 558 + /* filter peak detection data */ 559 + if (st->peak_fifo_mode_en) 560 + adxl372_arrange_axis_data(st, &st->fifo_buf[i]); 668 561 iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); 562 + } 669 563 } 670 564 err: 671 565 iio_trigger_notify_done(indio_dev->trig); ··· 837 723 } 838 724 } 839 725 726 + static int adxl372_read_event_value(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, 727 + enum iio_event_type type, enum iio_event_direction dir, 728 + enum iio_event_info info, int *val, int *val2) 729 + { 730 + struct adxl372_state *st = iio_priv(indio_dev); 731 + unsigned int addr; 732 + u16 raw_value; 733 + int ret; 734 + 735 + switch (info) { 736 + case IIO_EV_INFO_VALUE: 737 + switch (dir) { 738 + case IIO_EV_DIR_RISING: 739 + addr = ADXL372_X_THRESH_ACT_H + 2 * chan->scan_index; 740 + ret = adxl372_read_threshold_value(indio_dev, addr, &raw_value); 741 + if (ret < 0) 742 + return ret; 743 + *val = raw_value * ADXL372_USCALE; 744 + *val2 = 1000000; 745 + return IIO_VAL_FRACTIONAL; 746 + case IIO_EV_DIR_FALLING: 747 + addr = ADXL372_X_THRESH_INACT_H + 2 * chan->scan_index; 748 + ret = adxl372_read_threshold_value(indio_dev, addr, &raw_value); 749 + if (ret < 0) 750 + return ret; 751 + *val = raw_value * ADXL372_USCALE; 752 + *val2 = 1000000; 753 + return IIO_VAL_FRACTIONAL; 754 + default: 755 + return -EINVAL; 756 + } 757 + case IIO_EV_INFO_PERIOD: 758 + switch (dir) { 759 + case IIO_EV_DIR_RISING: 760 + *val = st->act_time_ms; 761 + *val2 = 1000; 762 + return IIO_VAL_FRACTIONAL; 763 + case IIO_EV_DIR_FALLING: 764 + *val = st->inact_time_ms; 765 + *val2 = 1000; 766 + return IIO_VAL_FRACTIONAL; 767 + default: 768 + return -EINVAL; 769 + } 770 + default: 771 + return -EINVAL; 772 + } 773 + } 774 + 775 + static int adxl372_write_event_value(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, 776 + enum iio_event_type type, enum iio_event_direction dir, 777 + enum iio_event_info info, int val, int val2) 778 + { 779 + struct adxl372_state *st = iio_priv(indio_dev); 780 + unsigned int val_ms; 781 + unsigned int addr; 782 + u16 raw_val; 783 + 784 + switch (info) { 785 + case IIO_EV_INFO_VALUE: 786 + raw_val = DIV_ROUND_UP(val * 1000000, ADXL372_USCALE); 787 + switch (dir) { 788 + case IIO_EV_DIR_RISING: 789 + addr = ADXL372_X_THRESH_ACT_H + 2 * chan->scan_index; 790 + return adxl372_write_threshold_value(indio_dev, addr, raw_val); 791 + case IIO_EV_DIR_FALLING: 792 + addr = ADXL372_X_THRESH_INACT_H + 2 * chan->scan_index; 793 + return adxl372_write_threshold_value(indio_dev, addr, raw_val); 794 + default: 795 + return -EINVAL; 796 + } 797 + case IIO_EV_INFO_PERIOD: 798 + val_ms = val * 1000 + DIV_ROUND_UP(val2, 1000); 799 + switch (dir) { 800 + case IIO_EV_DIR_RISING: 801 + return adxl372_set_activity_time_ms(st, val_ms); 802 + case IIO_EV_DIR_FALLING: 803 + return adxl372_set_inactivity_time_ms(st, val_ms); 804 + default: 805 + return -EINVAL; 806 + } 807 + default: 808 + return -EINVAL; 809 + } 810 + } 811 + 812 + static int adxl372_read_event_config(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, 813 + enum iio_event_type type, enum iio_event_direction dir) 814 + { 815 + struct adxl372_state *st = iio_priv(indio_dev); 816 + 817 + switch (dir) { 818 + case IIO_EV_DIR_RISING: 819 + return FIELD_GET(ADXL372_INT1_MAP_ACT_MSK, st->int1_bitmask); 820 + case IIO_EV_DIR_FALLING: 821 + return FIELD_GET(ADXL372_INT1_MAP_INACT_MSK, st->int1_bitmask); 822 + default: 823 + return -EINVAL; 824 + } 825 + } 826 + 827 + static int adxl372_write_event_config(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, 828 + enum iio_event_type type, enum iio_event_direction dir, 829 + int state) 830 + { 831 + struct adxl372_state *st = iio_priv(indio_dev); 832 + 833 + switch (dir) { 834 + case IIO_EV_DIR_RISING: 835 + set_mask_bits(&st->int1_bitmask, ADXL372_INT1_MAP_ACT_MSK, 836 + ADXL372_INT1_MAP_ACT_MODE(state)); 837 + break; 838 + case IIO_EV_DIR_FALLING: 839 + set_mask_bits(&st->int1_bitmask, ADXL372_INT1_MAP_INACT_MSK, 840 + ADXL372_INT1_MAP_INACT_MODE(state)); 841 + break; 842 + default: 843 + return -EINVAL; 844 + } 845 + 846 + return adxl372_set_interrupts(st, st->int1_bitmask, 0); 847 + } 848 + 840 849 static ssize_t adxl372_show_filter_freq_avail(struct device *dev, 841 850 struct device_attribute *attr, 842 851 char *buf) ··· 1032 795 unsigned int mask; 1033 796 int i, ret; 1034 797 1035 - ret = adxl372_set_interrupts(st, ADXL372_INT1_MAP_FIFO_FULL_MSK, 0); 798 + st->int1_bitmask |= ADXL372_INT1_MAP_FIFO_FULL_MSK; 799 + ret = adxl372_set_interrupts(st, st->int1_bitmask, 0); 1036 800 if (ret < 0) 1037 801 return ret; 1038 802 ··· 1048 810 return -EINVAL; 1049 811 1050 812 st->fifo_format = adxl372_axis_lookup_table[i].fifo_format; 813 + st->fifo_axis_mask = adxl372_axis_lookup_table[i].bits; 1051 814 st->fifo_set_size = bitmap_weight(indio_dev->active_scan_mask, 1052 815 indio_dev->masklength); 816 + 817 + /* Configure the FIFO to store sets of impact event peak. */ 818 + if (st->peak_fifo_mode_en) { 819 + st->fifo_set_size = 3; 820 + st->fifo_format = ADXL372_XYZ_PEAK_FIFO; 821 + } 822 + 1053 823 /* 1054 824 * The 512 FIFO samples can be allotted in several ways, such as: 1055 825 * 170 sample sets of concurrent 3-axis data 1056 826 * 256 sample sets of concurrent 2-axis data (user selectable) 1057 827 * 512 sample sets of single-axis data 828 + * 170 sets of impact event peak (x, y, z) 1058 829 */ 1059 830 if ((st->watermark * st->fifo_set_size) > ADXL372_FIFO_SIZE) 1060 831 st->watermark = (ADXL372_FIFO_SIZE / st->fifo_set_size); ··· 1073 826 ret = adxl372_configure_fifo(st); 1074 827 if (ret < 0) { 1075 828 st->fifo_mode = ADXL372_FIFO_BYPASSED; 1076 - adxl372_set_interrupts(st, 0, 0); 829 + st->int1_bitmask &= ~ADXL372_INT1_MAP_FIFO_FULL_MSK; 830 + adxl372_set_interrupts(st, st->int1_bitmask, 0); 1077 831 return ret; 1078 832 } 1079 833 ··· 1085 837 { 1086 838 struct adxl372_state *st = iio_priv(indio_dev); 1087 839 1088 - adxl372_set_interrupts(st, 0, 0); 840 + st->int1_bitmask &= ~ADXL372_INT1_MAP_FIFO_FULL_MSK; 841 + adxl372_set_interrupts(st, st->int1_bitmask, 0); 1089 842 st->fifo_mode = ADXL372_FIFO_BYPASSED; 1090 843 adxl372_configure_fifo(st); 1091 844 ··· 1103 854 { 1104 855 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 1105 856 struct adxl372_state *st = iio_priv(indio_dev); 1106 - unsigned long int mask = 0; 1107 857 1108 858 if (state) 1109 - mask = ADXL372_INT1_MAP_FIFO_FULL_MSK; 859 + st->int1_bitmask |= ADXL372_INT1_MAP_FIFO_FULL_MSK; 1110 860 1111 - return adxl372_set_interrupts(st, mask, 0); 861 + return adxl372_set_interrupts(st, st->int1_bitmask, 0); 1112 862 } 1113 863 1114 864 static int adxl372_validate_trigger(struct iio_dev *indio_dev, ··· 1115 867 { 1116 868 struct adxl372_state *st = iio_priv(indio_dev); 1117 869 1118 - if (st->dready_trig != trig) 870 + if (st->dready_trig != trig && st->peak_datardy_trig != trig) 1119 871 return -EINVAL; 1120 872 1121 873 return 0; ··· 1124 876 static const struct iio_trigger_ops adxl372_trigger_ops = { 1125 877 .validate_device = &iio_trigger_validate_own_device, 1126 878 .set_trigger_state = adxl372_dready_trig_set_state, 879 + }; 880 + 881 + static int adxl372_peak_dready_trig_set_state(struct iio_trigger *trig, 882 + bool state) 883 + { 884 + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 885 + struct adxl372_state *st = iio_priv(indio_dev); 886 + 887 + if (state) 888 + st->int1_bitmask |= ADXL372_INT1_MAP_FIFO_FULL_MSK; 889 + 890 + st->peak_fifo_mode_en = state; 891 + 892 + return adxl372_set_interrupts(st, st->int1_bitmask, 0); 893 + } 894 + 895 + static const struct iio_trigger_ops adxl372_peak_data_trigger_ops = { 896 + .validate_device = &iio_trigger_validate_own_device, 897 + .set_trigger_state = adxl372_peak_dready_trig_set_state, 1127 898 }; 1128 899 1129 900 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("400 800 1600 3200 6400"); ··· 1164 897 .attrs = &adxl372_attrs_group, 1165 898 .read_raw = adxl372_read_raw, 1166 899 .write_raw = adxl372_write_raw, 900 + .read_event_config = adxl372_read_event_config, 901 + .write_event_config = adxl372_write_event_config, 902 + .read_event_value = adxl372_read_event_value, 903 + .write_event_value = adxl372_write_event_value, 1167 904 .debugfs_reg_access = &adxl372_reg_access, 1168 905 .hwfifo_set_watermark = adxl372_set_watermark, 1169 906 }; ··· 1195 924 st->dev = dev; 1196 925 st->regmap = regmap; 1197 926 st->irq = irq; 927 + 928 + mutex_init(&st->threshold_m); 1198 929 1199 930 indio_dev->channels = adxl372_channels; 1200 931 indio_dev->num_channels = ARRAY_SIZE(adxl372_channels); ··· 1228 955 if (st->dready_trig == NULL) 1229 956 return -ENOMEM; 1230 957 958 + st->peak_datardy_trig = devm_iio_trigger_alloc(dev, 959 + "%s-dev%d-peak", 960 + indio_dev->name, 961 + indio_dev->id); 962 + if (!st->peak_datardy_trig) 963 + return -ENOMEM; 964 + 1231 965 st->dready_trig->ops = &adxl372_trigger_ops; 966 + st->peak_datardy_trig->ops = &adxl372_peak_data_trigger_ops; 1232 967 st->dready_trig->dev.parent = dev; 968 + st->peak_datardy_trig->dev.parent = dev; 1233 969 iio_trigger_set_drvdata(st->dready_trig, indio_dev); 970 + iio_trigger_set_drvdata(st->peak_datardy_trig, indio_dev); 1234 971 ret = devm_iio_trigger_register(dev, st->dready_trig); 972 + if (ret < 0) 973 + return ret; 974 + 975 + ret = devm_iio_trigger_register(dev, st->peak_datardy_trig); 1235 976 if (ret < 0) 1236 977 return ret; 1237 978
+8
drivers/iio/accel/adxl372_i2c.c
··· 6 6 */ 7 7 8 8 #include <linux/i2c.h> 9 + #include <linux/mod_devicetable.h> 9 10 #include <linux/module.h> 10 11 #include <linux/regmap.h> 11 12 ··· 47 46 }; 48 47 MODULE_DEVICE_TABLE(i2c, adxl372_i2c_id); 49 48 49 + static const struct of_device_id adxl372_of_match[] = { 50 + { .compatible = "adi,adxl372" }, 51 + { } 52 + }; 53 + MODULE_DEVICE_TABLE(of, adxl372_of_match); 54 + 50 55 static struct i2c_driver adxl372_i2c_driver = { 51 56 .driver = { 52 57 .name = "adxl372_i2c", 58 + .of_match_table = adxl372_of_match, 53 59 }, 54 60 .probe = adxl372_i2c_probe, 55 61 .id_table = adxl372_i2c_id,
+2 -2
drivers/iio/accel/adxl372_spi.c
··· 40 40 MODULE_DEVICE_TABLE(spi, adxl372_spi_id); 41 41 42 42 static const struct of_device_id adxl372_of_match[] = { 43 - { .compatible = "adi,adxl372" }, 44 - { }, 43 + { .compatible = "adi,adxl372" }, 44 + { } 45 45 }; 46 46 MODULE_DEVICE_TABLE(of, adxl372_of_match); 47 47
+8 -12
drivers/iio/accel/bma180.c
··· 1000 1000 return ret; 1001 1001 1002 1002 data->vdd_supply = devm_regulator_get(dev, "vdd"); 1003 - if (IS_ERR(data->vdd_supply)) { 1004 - if (PTR_ERR(data->vdd_supply) != -EPROBE_DEFER) 1005 - dev_err(dev, "Failed to get vdd regulator %d\n", 1006 - (int)PTR_ERR(data->vdd_supply)); 1007 - return PTR_ERR(data->vdd_supply); 1008 - } 1003 + if (IS_ERR(data->vdd_supply)) 1004 + return dev_err_probe(dev, PTR_ERR(data->vdd_supply), 1005 + "Failed to get vdd regulator\n"); 1006 + 1009 1007 data->vddio_supply = devm_regulator_get(dev, "vddio"); 1010 - if (IS_ERR(data->vddio_supply)) { 1011 - if (PTR_ERR(data->vddio_supply) != -EPROBE_DEFER) 1012 - dev_err(dev, "Failed to get vddio regulator %d\n", 1013 - (int)PTR_ERR(data->vddio_supply)); 1014 - return PTR_ERR(data->vddio_supply); 1015 - } 1008 + if (IS_ERR(data->vddio_supply)) 1009 + return dev_err_probe(dev, PTR_ERR(data->vddio_supply), 1010 + "Failed to get vddio regulator\n"); 1011 + 1016 1012 /* Typical voltage 2.4V these are min and max */ 1017 1013 ret = regulator_set_voltage(data->vdd_supply, 1620000, 3600000); 1018 1014 if (ret)
+41 -44
drivers/iio/accel/bma220_spi.c
··· 2 2 /** 3 3 * BMA220 Digital triaxial acceleration sensor driver 4 4 * 5 - * Copyright (c) 2016, Intel Corporation. 5 + * Copyright (c) 2016,2020 Intel Corporation. 6 6 */ 7 7 8 - #include <linux/acpi.h> 8 + #include <linux/bits.h> 9 9 #include <linux/kernel.h> 10 + #include <linux/mod_devicetable.h> 10 11 #include <linux/module.h> 12 + #include <linux/spi/spi.h> 13 + 11 14 #include <linux/iio/buffer.h> 12 15 #include <linux/iio/iio.h> 13 16 #include <linux/iio/sysfs.h> 14 - #include <linux/spi/spi.h> 15 17 #include <linux/iio/trigger_consumer.h> 16 18 #include <linux/iio/triggered_buffer.h> 17 19 ··· 25 23 #define BMA220_REG_SUSPEND 0x18 26 24 27 25 #define BMA220_CHIP_ID 0xDD 28 - #define BMA220_READ_MASK 0x80 29 - #define BMA220_RANGE_MASK 0x03 26 + #define BMA220_READ_MASK BIT(7) 27 + #define BMA220_RANGE_MASK GENMASK(1, 0) 30 28 #define BMA220_DATA_SHIFT 2 31 29 #define BMA220_SUSPEND_SLEEP 0xFF 32 30 #define BMA220_SUSPEND_WAKE 0x00 33 31 34 32 #define BMA220_DEVICE_NAME "bma220" 35 - #define BMA220_SCALE_AVAILABLE "0.623 1.248 2.491 4.983" 36 33 37 34 #define BMA220_ACCEL_CHANNEL(index, reg, axis) { \ 38 35 .type = IIO_ACCEL, \ ··· 56 55 AXIS_Z, 57 56 }; 58 57 59 - static IIO_CONST_ATTR(in_accel_scale_available, BMA220_SCALE_AVAILABLE); 60 - 61 - static struct attribute *bma220_attributes[] = { 62 - &iio_const_attr_in_accel_scale_available.dev_attr.attr, 63 - NULL, 64 - }; 65 - 66 - static const struct attribute_group bma220_attribute_group = { 67 - .attrs = bma220_attributes, 68 - }; 69 - 70 - static const int bma220_scale_table[][4] = { 71 - {0, 623000}, {1, 248000}, {2, 491000}, {4, 983000} 58 + static const int bma220_scale_table[][2] = { 59 + {0, 623000}, {1, 248000}, {2, 491000}, {4, 983000}, 72 60 }; 73 61 74 62 struct bma220_data { ··· 172 182 return -EINVAL; 173 183 } 174 184 185 + static int bma220_read_avail(struct iio_dev *indio_dev, 186 + struct iio_chan_spec const *chan, 187 + const int **vals, int *type, int *length, 188 + long mask) 189 + { 190 + switch (mask) { 191 + case IIO_CHAN_INFO_SCALE: 192 + *vals = (int *)bma220_scale_table; 193 + *type = IIO_VAL_INT_PLUS_MICRO; 194 + *length = ARRAY_SIZE(bma220_scale_table) * 2; 195 + return IIO_AVAIL_LIST; 196 + default: 197 + return -EINVAL; 198 + } 199 + } 200 + 175 201 static const struct iio_info bma220_info = { 176 202 .read_raw = bma220_read_raw, 177 203 .write_raw = bma220_write_raw, 178 - .attrs = &bma220_attribute_group, 204 + .read_avail = bma220_read_avail, 179 205 }; 180 206 181 207 static int bma220_init(struct spi_device *spi) ··· 204 198 205 199 /* Make sure the chip is powered on */ 206 200 ret = bma220_read_reg(spi, BMA220_REG_SUSPEND); 201 + if (ret == BMA220_SUSPEND_WAKE) 202 + ret = bma220_read_reg(spi, BMA220_REG_SUSPEND); 207 203 if (ret < 0) 208 204 return ret; 209 - else if (ret == BMA220_SUSPEND_WAKE) 210 - return bma220_read_reg(spi, BMA220_REG_SUSPEND); 205 + if (ret == BMA220_SUSPEND_WAKE) 206 + return -EBUSY; 211 207 212 208 return 0; 213 209 } ··· 220 212 221 213 /* Make sure the chip is powered off */ 222 214 ret = bma220_read_reg(spi, BMA220_REG_SUSPEND); 215 + if (ret == BMA220_SUSPEND_SLEEP) 216 + ret = bma220_read_reg(spi, BMA220_REG_SUSPEND); 223 217 if (ret < 0) 224 218 return ret; 225 - else if (ret == BMA220_SUSPEND_SLEEP) 226 - return bma220_read_reg(spi, BMA220_REG_SUSPEND); 219 + if (ret == BMA220_SUSPEND_SLEEP) 220 + return -EBUSY; 227 221 228 222 return 0; 229 223 } ··· 255 245 indio_dev->available_scan_masks = bma220_accel_scan_masks; 256 246 257 247 ret = bma220_init(data->spi_device); 258 - if (ret < 0) 248 + if (ret) 259 249 return ret; 260 250 261 251 ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time, ··· 288 278 return bma220_deinit(spi); 289 279 } 290 280 291 - #ifdef CONFIG_PM_SLEEP 292 - static int bma220_suspend(struct device *dev) 281 + static __maybe_unused int bma220_suspend(struct device *dev) 293 282 { 294 - struct bma220_data *data = 295 - iio_priv(spi_get_drvdata(to_spi_device(dev))); 283 + struct bma220_data *data = iio_priv(dev_get_drvdata(dev)); 296 284 297 285 /* The chip can be suspended/woken up by a simple register read. */ 298 286 return bma220_read_reg(data->spi_device, BMA220_REG_SUSPEND); 299 287 } 300 288 301 - static int bma220_resume(struct device *dev) 289 + static __maybe_unused int bma220_resume(struct device *dev) 302 290 { 303 - struct bma220_data *data = 304 - iio_priv(spi_get_drvdata(to_spi_device(dev))); 291 + struct bma220_data *data = iio_priv(dev_get_drvdata(dev)); 305 292 306 293 return bma220_read_reg(data->spi_device, BMA220_REG_SUSPEND); 307 294 } 308 - 309 295 static SIMPLE_DEV_PM_OPS(bma220_pm_ops, bma220_suspend, bma220_resume); 310 - 311 - #define BMA220_PM_OPS (&bma220_pm_ops) 312 - #else 313 - #define BMA220_PM_OPS NULL 314 - #endif 315 296 316 297 static const struct spi_device_id bma220_spi_id[] = { 317 298 {"bma220", 0}, 318 299 {} 319 300 }; 320 301 321 - #ifdef CONFIG_ACPI 322 302 static const struct acpi_device_id bma220_acpi_id[] = { 323 303 {"BMA0220", 0}, 324 304 {} 325 305 }; 326 - 327 306 MODULE_DEVICE_TABLE(spi, bma220_spi_id); 328 - #endif 329 307 330 308 static struct spi_driver bma220_driver = { 331 309 .driver = { 332 310 .name = "bma220_spi", 333 - .pm = BMA220_PM_OPS, 334 - .acpi_match_table = ACPI_PTR(bma220_acpi_id), 311 + .pm = &bma220_pm_ops, 312 + .acpi_match_table = bma220_acpi_id, 335 313 }, 336 314 .probe = bma220_probe, 337 315 .remove = bma220_remove, 338 316 .id_table = bma220_spi_id, 339 317 }; 340 - 341 318 module_spi_driver(bma220_driver); 342 319 343 320 MODULE_AUTHOR("Tiberiu Breana <tiberiu.a.breana@intel.com>");
+6 -14
drivers/iio/accel/mma8452.c
··· 1538 1538 data->chip_info = match->data; 1539 1539 1540 1540 data->vdd_reg = devm_regulator_get(&client->dev, "vdd"); 1541 - if (IS_ERR(data->vdd_reg)) { 1542 - if (PTR_ERR(data->vdd_reg) == -EPROBE_DEFER) 1543 - return -EPROBE_DEFER; 1544 - 1545 - dev_err(&client->dev, "failed to get VDD regulator!\n"); 1546 - return PTR_ERR(data->vdd_reg); 1547 - } 1541 + if (IS_ERR(data->vdd_reg)) 1542 + return dev_err_probe(&client->dev, PTR_ERR(data->vdd_reg), 1543 + "failed to get VDD regulator!\n"); 1548 1544 1549 1545 data->vddio_reg = devm_regulator_get(&client->dev, "vddio"); 1550 - if (IS_ERR(data->vddio_reg)) { 1551 - if (PTR_ERR(data->vddio_reg) == -EPROBE_DEFER) 1552 - return -EPROBE_DEFER; 1553 - 1554 - dev_err(&client->dev, "failed to get VDDIO regulator!\n"); 1555 - return PTR_ERR(data->vddio_reg); 1556 - } 1546 + if (IS_ERR(data->vddio_reg)) 1547 + return dev_err_probe(&client->dev, PTR_ERR(data->vddio_reg), 1548 + "failed to get VDDIO regulator!\n"); 1557 1549 1558 1550 ret = regulator_enable(data->vdd_reg); 1559 1551 if (ret) {
+1 -1
drivers/iio/adc/Kconfig
··· 340 340 341 341 config BCM_IPROC_ADC 342 342 tristate "Broadcom IPROC ADC driver" 343 - depends on ARCH_BCM_IPROC || COMPILE_TEST 343 + depends on (ARCH_BCM_IPROC && OF) || COMPILE_TEST 344 344 depends on MFD_SYSCON 345 345 default ARCH_BCM_CYGNUS 346 346 help
+1 -1
drivers/iio/adc/adi-axi-adc.c
··· 276 276 static umode_t axi_adc_attr_is_visible(struct kobject *kobj, 277 277 struct attribute *attr, int n) 278 278 { 279 - struct device *dev = container_of(kobj, struct device, kobj); 279 + struct device *dev = kobj_to_dev(kobj); 280 280 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 281 281 struct adi_axi_adc_state *st = iio_priv(indio_dev); 282 282 struct adi_axi_adc_conv *conv = &st->client->conv;
+7 -7
drivers/iio/adc/axp20x_adc.c
··· 9 9 #include <linux/interrupt.h> 10 10 #include <linux/io.h> 11 11 #include <linux/module.h> 12 - #include <linux/of.h> 13 - #include <linux/of_device.h> 12 + #include <linux/mod_devicetable.h> 14 13 #include <linux/platform_device.h> 15 14 #include <linux/pm_runtime.h> 15 + #include <linux/property.h> 16 16 #include <linux/regmap.h> 17 17 #include <linux/thermal.h> 18 18 ··· 67 67 68 68 struct axp20x_adc_iio { 69 69 struct regmap *regmap; 70 - struct axp_data *data; 70 + const struct axp_data *data; 71 71 }; 72 72 73 73 enum axp20x_adc_channel_v { ··· 670 670 info->regmap = axp20x_dev->regmap; 671 671 indio_dev->modes = INDIO_DIRECT_MODE; 672 672 673 - if (!pdev->dev.of_node) { 673 + if (!dev_fwnode(&pdev->dev)) { 674 674 const struct platform_device_id *id; 675 675 676 676 id = platform_get_device_id(pdev); 677 - info->data = (struct axp_data *)id->driver_data; 677 + info->data = (const struct axp_data *)id->driver_data; 678 678 } else { 679 679 struct device *dev = &pdev->dev; 680 680 681 - info->data = (struct axp_data *)of_device_get_match_data(dev); 681 + info->data = device_get_match_data(dev); 682 682 } 683 683 684 684 indio_dev->name = platform_get_device_id(pdev)->name; ··· 742 742 static struct platform_driver axp20x_adc_driver = { 743 743 .driver = { 744 744 .name = "axp20x-adc", 745 - .of_match_table = of_match_ptr(axp20x_adc_of_match), 745 + .of_match_table = axp20x_adc_of_match, 746 746 }, 747 747 .id_table = axp20x_adc_id_match, 748 748 .probe = axp20x_probe,
+2 -2
drivers/iio/adc/bcm_iproc_adc.c
··· 4 4 */ 5 5 6 6 #include <linux/module.h> 7 - #include <linux/of.h> 7 + #include <linux/mod_devicetable.h> 8 8 #include <linux/io.h> 9 9 #include <linux/clk.h> 10 10 #include <linux/mfd/syscon.h> ··· 617 617 .remove = iproc_adc_remove, 618 618 .driver = { 619 619 .name = "iproc-static-adc", 620 - .of_match_table = of_match_ptr(iproc_adc_of_match), 620 + .of_match_table = iproc_adc_of_match, 621 621 }, 622 622 }; 623 623 module_platform_driver(iproc_adc_driver);
+6 -10
drivers/iio/adc/envelope-detector.c
··· 348 348 indio_dev->num_channels = 1; 349 349 350 350 env->dac = devm_iio_channel_get(dev, "dac"); 351 - if (IS_ERR(env->dac)) { 352 - if (PTR_ERR(env->dac) != -EPROBE_DEFER) 353 - dev_err(dev, "failed to get dac input channel\n"); 354 - return PTR_ERR(env->dac); 355 - } 351 + if (IS_ERR(env->dac)) 352 + return dev_err_probe(dev, PTR_ERR(env->dac), 353 + "failed to get dac input channel\n"); 356 354 357 355 env->comp_irq = platform_get_irq_byname(pdev, "comp"); 358 356 if (env->comp_irq < 0) ··· 358 360 359 361 ret = devm_request_irq(dev, env->comp_irq, envelope_detector_comp_isr, 360 362 0, "envelope-detector", env); 361 - if (ret) { 362 - if (ret != -EPROBE_DEFER) 363 - dev_err(dev, "failed to request interrupt\n"); 364 - return ret; 365 - } 363 + if (ret) 364 + return dev_err_probe(dev, ret, "failed to request interrupt\n"); 365 + 366 366 env->comp_irq_trigger = irq_get_trigger_type(env->comp_irq); 367 367 if (env->comp_irq_trigger & IRQF_TRIGGER_RISING) 368 368 env->comp_irq_trigger_inv |= IRQF_TRIGGER_FALLING;
+3 -7
drivers/iio/adc/exynos_adc.c
··· 844 844 } 845 845 846 846 info->vdd = devm_regulator_get(&pdev->dev, "vdd"); 847 - if (IS_ERR(info->vdd)) { 848 - if (PTR_ERR(info->vdd) != -EPROBE_DEFER) 849 - dev_err(&pdev->dev, 850 - "failed getting regulator, err = %ld\n", 851 - PTR_ERR(info->vdd)); 852 - return PTR_ERR(info->vdd); 853 - } 847 + if (IS_ERR(info->vdd)) 848 + return dev_err_probe(&pdev->dev, PTR_ERR(info->vdd), 849 + "failed getting regulator"); 854 850 855 851 ret = regulator_enable(info->vdd); 856 852 if (ret)
+3 -7
drivers/iio/adc/ltc2497-core.c
··· 180 180 return ret; 181 181 182 182 ddata->ref = devm_regulator_get(dev, "vref"); 183 - if (IS_ERR(ddata->ref)) { 184 - if (PTR_ERR(ddata->ref) != -EPROBE_DEFER) 185 - dev_err(dev, "Failed to get vref regulator: %pe\n", 186 - ddata->ref); 187 - 188 - return PTR_ERR(ddata->ref); 189 - } 183 + if (IS_ERR(ddata->ref)) 184 + return dev_err_probe(dev, PTR_ERR(ddata->ref), 185 + "Failed to get vref regulator\n"); 190 186 191 187 ret = regulator_enable(ddata->ref); 192 188 if (ret < 0) {
+2 -5
drivers/iio/adc/meson_saradc.c
··· 719 719 if (ret == -ENODEV) 720 720 return 0; 721 721 722 - if (ret != -EPROBE_DEFER) 723 - dev_err(indio_dev->dev.parent, 724 - "failed to get temperature_calib cell\n"); 725 - 726 - return ret; 722 + return dev_err_probe(indio_dev->dev.parent, ret, 723 + "failed to get temperature_calib cell\n"); 727 724 } 728 725 729 726 priv->tsc_regmap =
+3 -6
drivers/iio/adc/rcar-gyroadc.c
··· 495 495 return PTR_ERR(priv->regs); 496 496 497 497 priv->clk = devm_clk_get(dev, "fck"); 498 - if (IS_ERR(priv->clk)) { 499 - ret = PTR_ERR(priv->clk); 500 - if (ret != -EPROBE_DEFER) 501 - dev_err(dev, "Failed to get IF clock (ret=%i)\n", ret); 502 - return ret; 503 - } 498 + if (IS_ERR(priv->clk)) 499 + return dev_err_probe(dev, PTR_ERR(priv->clk), 500 + "Failed to get IF clock\n"); 504 501 505 502 ret = rcar_gyroadc_parse_subdevs(indio_dev); 506 503 if (ret)
+23 -48
drivers/iio/adc/stm32-adc-core.c
··· 582 582 priv->syscfg = syscon_regmap_lookup_by_phandle(np, "st,syscfg"); 583 583 if (IS_ERR(priv->syscfg)) { 584 584 ret = PTR_ERR(priv->syscfg); 585 - if (ret != -ENODEV) { 586 - if (ret != -EPROBE_DEFER) 587 - dev_err(dev, "Can't probe syscfg: %d\n", ret); 588 - return ret; 589 - } 585 + if (ret != -ENODEV) 586 + return dev_err_probe(dev, ret, "Can't probe syscfg\n"); 587 + 590 588 priv->syscfg = NULL; 591 589 } 592 590 ··· 594 596 priv->booster = devm_regulator_get_optional(dev, "booster"); 595 597 if (IS_ERR(priv->booster)) { 596 598 ret = PTR_ERR(priv->booster); 597 - if (ret != -ENODEV) { 598 - if (ret != -EPROBE_DEFER) 599 - dev_err(dev, "can't get booster %d\n", 600 - ret); 601 - return ret; 602 - } 599 + if (ret != -ENODEV) 600 + dev_err_probe(dev, ret, "can't get booster\n"); 601 + 603 602 priv->booster = NULL; 604 603 } 605 604 } ··· 607 612 priv->vdd = devm_regulator_get_optional(dev, "vdd"); 608 613 if (IS_ERR(priv->vdd)) { 609 614 ret = PTR_ERR(priv->vdd); 610 - if (ret != -ENODEV) { 611 - if (ret != -EPROBE_DEFER) 612 - dev_err(dev, "can't get vdd %d\n", ret); 613 - return ret; 614 - } 615 + if (ret != -ENODEV) 616 + return dev_err_probe(dev, ret, "can't get vdd\n"); 617 + 615 618 priv->vdd = NULL; 616 619 } 617 620 } ··· 662 669 priv->common.phys_base = res->start; 663 670 664 671 priv->vdda = devm_regulator_get(&pdev->dev, "vdda"); 665 - if (IS_ERR(priv->vdda)) { 666 - ret = PTR_ERR(priv->vdda); 667 - if (ret != -EPROBE_DEFER) 668 - dev_err(&pdev->dev, "vdda get failed, %d\n", ret); 669 - return ret; 670 - } 672 + if (IS_ERR(priv->vdda)) 673 + return dev_err_probe(&pdev->dev, PTR_ERR(priv->vdda), 674 + "vdda get failed\n"); 671 675 672 676 priv->vref = devm_regulator_get(&pdev->dev, "vref"); 673 - if (IS_ERR(priv->vref)) { 674 - ret = PTR_ERR(priv->vref); 675 - if (ret != -EPROBE_DEFER) 676 - dev_err(&pdev->dev, "vref get failed, %d\n", ret); 677 - return ret; 678 - } 677 + if (IS_ERR(priv->vref)) 678 + return dev_err_probe(&pdev->dev, PTR_ERR(priv->vref), 679 + "vref get failed\n"); 679 680 680 - priv->aclk = devm_clk_get(&pdev->dev, "adc"); 681 - if (IS_ERR(priv->aclk)) { 682 - ret = PTR_ERR(priv->aclk); 683 - if (ret != -ENOENT) { 684 - if (ret != -EPROBE_DEFER) 685 - dev_err(&pdev->dev, "Can't get 'adc' clock\n"); 686 - return ret; 687 - } 688 - priv->aclk = NULL; 689 - } 681 + priv->aclk = devm_clk_get_optional(&pdev->dev, "adc"); 682 + if (IS_ERR(priv->aclk)) 683 + return dev_err_probe(&pdev->dev, PTR_ERR(priv->aclk), 684 + "Can't get 'adc' clock\n"); 690 685 691 - priv->bclk = devm_clk_get(&pdev->dev, "bus"); 692 - if (IS_ERR(priv->bclk)) { 693 - ret = PTR_ERR(priv->bclk); 694 - if (ret != -ENOENT) { 695 - if (ret != -EPROBE_DEFER) 696 - dev_err(&pdev->dev, "Can't get 'bus' clock\n"); 697 - return ret; 698 - } 699 - priv->bclk = NULL; 700 - } 686 + priv->bclk = devm_clk_get_optional(&pdev->dev, "bus"); 687 + if (IS_ERR(priv->bclk)) 688 + return dev_err_probe(&pdev->dev, PTR_ERR(priv->bclk), 689 + "Can't get 'bus' clock\n"); 701 690 702 691 ret = stm32_adc_core_switches_probe(dev, priv); 703 692 if (ret)
+3 -7
drivers/iio/adc/stm32-adc.c
··· 1805 1805 adc->dma_chan = dma_request_chan(dev, "rx"); 1806 1806 if (IS_ERR(adc->dma_chan)) { 1807 1807 ret = PTR_ERR(adc->dma_chan); 1808 - if (ret != -ENODEV) { 1809 - if (ret != -EPROBE_DEFER) 1810 - dev_err(dev, 1811 - "DMA channel request failed with %d\n", 1812 - ret); 1813 - return ret; 1814 - } 1808 + if (ret != -ENODEV) 1809 + return dev_err_probe(dev, ret, 1810 + "DMA channel request failed with\n"); 1815 1811 1816 1812 /* DMA is optional: fall back to IRQ mode */ 1817 1813 adc->dma_chan = NULL;
+3 -7
drivers/iio/adc/stm32-dfsdm-adc.c
··· 1473 1473 /* Optionally request DMA */ 1474 1474 ret = stm32_dfsdm_dma_request(dev, indio_dev); 1475 1475 if (ret) { 1476 - if (ret != -ENODEV) { 1477 - if (ret != -EPROBE_DEFER) 1478 - dev_err(dev, 1479 - "DMA channel request failed with %d\n", 1480 - ret); 1481 - return ret; 1482 - } 1476 + if (ret != -ENODEV) 1477 + return dev_err_probe(dev, ret, 1478 + "DMA channel request failed with\n"); 1483 1479 1484 1480 dev_dbg(dev, "No DMA support\n"); 1485 1481 return 0;
+3 -6
drivers/iio/adc/stm32-dfsdm-core.c
··· 243 243 * on use case. 244 244 */ 245 245 priv->clk = devm_clk_get(&pdev->dev, "dfsdm"); 246 - if (IS_ERR(priv->clk)) { 247 - ret = PTR_ERR(priv->clk); 248 - if (ret != -EPROBE_DEFER) 249 - dev_err(&pdev->dev, "Failed to get clock (%d)\n", ret); 250 - return ret; 251 - } 246 + if (IS_ERR(priv->clk)) 247 + return dev_err_probe(&pdev->dev, PTR_ERR(priv->clk), 248 + "Failed to get clock\n"); 252 249 253 250 priv->aclk = devm_clk_get(&pdev->dev, "audio"); 254 251 if (IS_ERR(priv->aclk))
+1 -23
drivers/iio/adc/ti-adc081c.c
··· 19 19 #include <linux/i2c.h> 20 20 #include <linux/module.h> 21 21 #include <linux/mod_devicetable.h> 22 - #include <linux/acpi.h> 23 22 24 23 #include <linux/iio/iio.h> 25 24 #include <linux/iio/buffer.h> ··· 152 153 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 153 154 return -EOPNOTSUPP; 154 155 155 - if (ACPI_COMPANION(&client->dev)) { 156 - const struct acpi_device_id *ad_id; 157 - 158 - ad_id = acpi_match_device(client->dev.driver->acpi_match_table, 159 - &client->dev); 160 - if (!ad_id) 161 - return -ENODEV; 162 - model = &adcxx1c_models[ad_id->driver_data]; 163 - } else { 164 - model = &adcxx1c_models[id->driver_data]; 165 - } 156 + model = &adcxx1c_models[id->driver_data]; 166 157 167 158 iio = devm_iio_device_alloc(&client->dev, sizeof(*adc)); 168 159 if (!iio) ··· 227 238 }; 228 239 MODULE_DEVICE_TABLE(of, adc081c_of_match); 229 240 230 - #ifdef CONFIG_ACPI 231 - static const struct acpi_device_id adc081c_acpi_match[] = { 232 - { "ADC081C", ADC081C }, 233 - { "ADC101C", ADC101C }, 234 - { "ADC121C", ADC121C }, 235 - { } 236 - }; 237 - MODULE_DEVICE_TABLE(acpi, adc081c_acpi_match); 238 - #endif 239 - 240 241 static struct i2c_driver adc081c_driver = { 241 242 .driver = { 242 243 .name = "adc081c", 243 244 .of_match_table = adc081c_of_match, 244 - .acpi_match_table = ACPI_PTR(adc081c_acpi_match), 245 245 }, 246 246 .probe = adc081c_probe, 247 247 .remove = adc081c_remove,
+2 -3
drivers/iio/adc/ti-adc108s102.c
··· 20 20 #include <linux/iio/trigger_consumer.h> 21 21 #include <linux/interrupt.h> 22 22 #include <linux/module.h> 23 + #include <linux/mod_devicetable.h> 23 24 #include <linux/property.h> 24 25 #include <linux/regulator/consumer.h> 25 26 #include <linux/spi/spi.h> ··· 300 299 return 0; 301 300 } 302 301 303 - #ifdef CONFIG_OF 304 302 static const struct of_device_id adc108s102_of_match[] = { 305 303 { .compatible = "ti,adc108s102" }, 306 304 { } 307 305 }; 308 306 MODULE_DEVICE_TABLE(of, adc108s102_of_match); 309 - #endif 310 307 311 308 #ifdef CONFIG_ACPI 312 309 static const struct acpi_device_id adc108s102_acpi_ids[] = { ··· 323 324 static struct spi_driver adc108s102_driver = { 324 325 .driver = { 325 326 .name = "adc108s102", 326 - .of_match_table = of_match_ptr(adc108s102_of_match), 327 + .of_match_table = adc108s102_of_match, 327 328 .acpi_match_table = ACPI_PTR(adc108s102_acpi_ids), 328 329 }, 329 330 .probe = adc108s102_probe,
+2 -1
drivers/iio/adc/ti-adc128s052.c
··· 13 13 #include <linux/err.h> 14 14 #include <linux/spi/spi.h> 15 15 #include <linux/module.h> 16 + #include <linux/mod_devicetable.h> 16 17 #include <linux/iio/iio.h> 17 18 #include <linux/property.h> 18 19 #include <linux/regulator/consumer.h> ··· 221 220 static struct spi_driver adc128_driver = { 222 221 .driver = { 223 222 .name = "adc128s052", 224 - .of_match_table = of_match_ptr(adc128_of_match), 223 + .of_match_table = adc128_of_match, 225 224 .acpi_match_table = ACPI_PTR(adc128_acpi_match), 226 225 }, 227 226 .probe = adc128_probe,
+3 -5
drivers/iio/afe/iio-rescale.c
··· 276 276 int ret; 277 277 278 278 source = devm_iio_channel_get(dev, NULL); 279 - if (IS_ERR(source)) { 280 - if (PTR_ERR(source) != -EPROBE_DEFER) 281 - dev_err(dev, "failed to get source channel\n"); 282 - return PTR_ERR(source); 283 - } 279 + if (IS_ERR(source)) 280 + return dev_err_probe(dev, PTR_ERR(source), 281 + "failed to get source channel\n"); 284 282 285 283 sizeof_ext_info = iio_get_channel_ext_info_count(source); 286 284 if (sizeof_ext_info) {
+1
drivers/iio/amplifiers/Kconfig
··· 18 18 AD8366 Dual-Digital Variable Gain Amplifier (VGA) 19 19 ADA4961 BiCMOS RF Digital Gain Amplifier (DGA) 20 20 ADL5240 Digitally controlled variable gain amplifier (VGA) 21 + HMC1119 0.25 dB LSB, 7-Bit, Silicon Digital Attenuator 21 22 22 23 To compile this driver as a module, choose M here: the 23 24 module will be called ad8366.
+3 -6
drivers/iio/amplifiers/hmc425a.c
··· 201 201 st->gain = st->chip_info->default_gain; 202 202 203 203 st->gpios = devm_gpiod_get_array(&pdev->dev, "ctrl", GPIOD_OUT_LOW); 204 - if (IS_ERR(st->gpios)) { 205 - ret = PTR_ERR(st->gpios); 206 - if (ret != -EPROBE_DEFER) 207 - dev_err(&pdev->dev, "failed to get gpios\n"); 208 - return ret; 209 - } 204 + if (IS_ERR(st->gpios)) 205 + return dev_err_probe(&pdev->dev, PTR_ERR(st->gpios), 206 + "failed to get gpios\n"); 210 207 211 208 if (st->gpios->ndescs != st->chip_info->num_gpios) { 212 209 dev_err(&pdev->dev, "%d GPIOs needed to operate\n",
+4 -2
drivers/iio/buffer/industrialio-buffer-dmaengine.c
··· 45 45 return container_of(buffer, struct dmaengine_buffer, queue.buffer); 46 46 } 47 47 48 - static void iio_dmaengine_buffer_block_done(void *data) 48 + static void iio_dmaengine_buffer_block_done(void *data, 49 + const struct dmaengine_result *result) 49 50 { 50 51 struct iio_dma_buffer_block *block = data; 51 52 unsigned long flags; ··· 54 53 spin_lock_irqsave(&block->queue->list_lock, flags); 55 54 list_del(&block->head); 56 55 spin_unlock_irqrestore(&block->queue->list_lock, flags); 56 + block->bytes_used -= result->residue; 57 57 iio_dma_buffer_block_done(block); 58 58 } 59 59 ··· 76 74 if (!desc) 77 75 return -ENOMEM; 78 76 79 - desc->callback = iio_dmaengine_buffer_block_done; 77 + desc->callback_result = iio_dmaengine_buffer_block_done; 80 78 desc->callback_param = block; 81 79 82 80 cookie = dmaengine_submit(desc);
+79 -9
drivers/iio/chemical/atlas-ezo-sensor.c
··· 16 16 #include <linux/iio/iio.h> 17 17 18 18 #define ATLAS_EZO_DRV_NAME "atlas-ezo-sensor" 19 - #define ATLAS_CO2_INT_TIME_IN_MS 950 19 + #define ATLAS_INT_TIME_IN_MS 950 20 + #define ATLAS_INT_HUM_TIME_IN_MS 350 20 21 21 22 enum { 22 23 ATLAS_CO2_EZO, 24 + ATLAS_O2_EZO, 25 + ATLAS_HUM_EZO, 23 26 }; 24 27 25 28 struct atlas_ezo_device { ··· 41 38 u8 buffer[8]; 42 39 }; 43 40 41 + #define ATLAS_CONCENTRATION_CHANNEL(_modifier) \ 42 + { \ 43 + .type = IIO_CONCENTRATION, \ 44 + .modified = 1,\ 45 + .channel2 = _modifier, \ 46 + .info_mask_separate = \ 47 + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \ 48 + .scan_index = 0, \ 49 + .scan_type = { \ 50 + .sign = 'u', \ 51 + .realbits = 32, \ 52 + .storagebits = 32, \ 53 + .endianness = IIO_CPU, \ 54 + }, \ 55 + } 56 + 44 57 static const struct iio_chan_spec atlas_co2_ezo_channels[] = { 58 + ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_CO2), 59 + }; 60 + 61 + static const struct iio_chan_spec atlas_o2_ezo_channels[] = { 62 + ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_O2), 63 + }; 64 + 65 + static const struct iio_chan_spec atlas_hum_ezo_channels[] = { 45 66 { 46 - .type = IIO_CONCENTRATION, 47 - .modified = 1, 48 - .channel2 = IIO_MOD_CO2, 67 + .type = IIO_HUMIDITYRELATIVE, 49 68 .info_mask_separate = 50 69 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 51 70 .scan_index = 0, 52 - .scan_type = { 71 + .scan_type = { 53 72 .sign = 'u', 54 73 .realbits = 32, 55 74 .storagebits = 32, ··· 84 59 [ATLAS_CO2_EZO] = { 85 60 .channels = atlas_co2_ezo_channels, 86 61 .num_channels = 1, 87 - .delay = ATLAS_CO2_INT_TIME_IN_MS, 62 + .delay = ATLAS_INT_TIME_IN_MS, 63 + }, 64 + [ATLAS_O2_EZO] = { 65 + .channels = atlas_o2_ezo_channels, 66 + .num_channels = 1, 67 + .delay = ATLAS_INT_TIME_IN_MS, 68 + }, 69 + [ATLAS_HUM_EZO] = { 70 + .channels = atlas_hum_ezo_channels, 71 + .num_channels = 1, 72 + .delay = ATLAS_INT_HUM_TIME_IN_MS, 88 73 }, 89 74 }; 75 + 76 + static void atlas_ezo_sanitize(char *buf) 77 + { 78 + char *ptr = strchr(buf, '.'); 79 + 80 + if (!ptr) 81 + return; 82 + 83 + memmove(ptr, ptr + 1, strlen(ptr)); 84 + } 90 85 91 86 static int atlas_ezo_read_raw(struct iio_dev *indio_dev, 92 87 struct iio_chan_spec const *chan, ··· 141 96 return -EBUSY; 142 97 } 143 98 99 + /* removing floating point for fixed number representation */ 100 + atlas_ezo_sanitize(data->buffer + 2); 101 + 144 102 ret = kstrtol(data->buffer + 1, 10, &tmp); 145 103 146 104 *val = tmp; ··· 153 105 return ret ? ret : IIO_VAL_INT; 154 106 } 155 107 case IIO_CHAN_INFO_SCALE: 156 - *val = 0; 157 - *val2 = 100; /* 0.0001 */ 158 - return IIO_VAL_INT_PLUS_MICRO; 108 + switch (chan->type) { 109 + case IIO_HUMIDITYRELATIVE: 110 + *val = 10; 111 + return IIO_VAL_INT; 112 + case IIO_CONCENTRATION: 113 + break; 114 + default: 115 + return -EINVAL; 116 + } 117 + 118 + /* IIO_CONCENTRATION modifiers */ 119 + switch (chan->channel2) { 120 + case IIO_MOD_CO2: 121 + *val = 0; 122 + *val2 = 100; /* 0.0001 */ 123 + return IIO_VAL_INT_PLUS_MICRO; 124 + case IIO_MOD_O2: 125 + *val = 100; 126 + return IIO_VAL_INT; 127 + } 128 + return -EINVAL; 159 129 } 160 130 161 131 return 0; ··· 185 119 186 120 static const struct i2c_device_id atlas_ezo_id[] = { 187 121 { "atlas-co2-ezo", ATLAS_CO2_EZO }, 122 + { "atlas-o2-ezo", ATLAS_O2_EZO }, 123 + { "atlas-hum-ezo", ATLAS_HUM_EZO }, 188 124 {} 189 125 }; 190 126 MODULE_DEVICE_TABLE(i2c, atlas_ezo_id); 191 127 192 128 static const struct of_device_id atlas_ezo_dt_ids[] = { 193 129 { .compatible = "atlas,co2-ezo", .data = (void *)ATLAS_CO2_EZO, }, 130 + { .compatible = "atlas,o2-ezo", .data = (void *)ATLAS_O2_EZO, }, 131 + { .compatible = "atlas,hum-ezo", .data = (void *)ATLAS_HUM_EZO, }, 194 132 {} 195 133 }; 196 134 MODULE_DEVICE_TABLE(of, atlas_ezo_dt_ids);
+2 -7
drivers/iio/chemical/scd30_core.c
··· 705 705 indio_dev->available_scan_masks = scd30_scan_masks; 706 706 707 707 state->vdd = devm_regulator_get(dev, "vdd"); 708 - if (IS_ERR(state->vdd)) { 709 - if (PTR_ERR(state->vdd) == -EPROBE_DEFER) 710 - return -EPROBE_DEFER; 711 - 712 - dev_err(dev, "failed to get regulator\n"); 713 - return PTR_ERR(state->vdd); 714 - } 708 + if (IS_ERR(state->vdd)) 709 + return dev_err_probe(dev, PTR_ERR(state->vdd), "failed to get regulator\n"); 715 710 716 711 ret = regulator_enable(state->vdd); 717 712 if (ret)
+4 -4
drivers/iio/dac/ad5686.c
··· 206 206 } 207 207 208 208 #define DECLARE_AD5693_CHANNELS(name, bits, _shift) \ 209 - static struct iio_chan_spec name[] = { \ 209 + static const struct iio_chan_spec name[] = { \ 210 210 AD5868_CHANNEL(0, 0, bits, _shift), \ 211 211 } 212 212 213 213 #define DECLARE_AD5686_CHANNELS(name, bits, _shift) \ 214 - static struct iio_chan_spec name[] = { \ 214 + static const struct iio_chan_spec name[] = { \ 215 215 AD5868_CHANNEL(0, 1, bits, _shift), \ 216 216 AD5868_CHANNEL(1, 2, bits, _shift), \ 217 217 AD5868_CHANNEL(2, 4, bits, _shift), \ ··· 219 219 } 220 220 221 221 #define DECLARE_AD5676_CHANNELS(name, bits, _shift) \ 222 - static struct iio_chan_spec name[] = { \ 222 + static const struct iio_chan_spec name[] = { \ 223 223 AD5868_CHANNEL(0, 0, bits, _shift), \ 224 224 AD5868_CHANNEL(1, 1, bits, _shift), \ 225 225 AD5868_CHANNEL(2, 2, bits, _shift), \ ··· 231 231 } 232 232 233 233 #define DECLARE_AD5679_CHANNELS(name, bits, _shift) \ 234 - static struct iio_chan_spec name[] = { \ 234 + static const struct iio_chan_spec name[] = { \ 235 235 AD5868_CHANNEL(0, 0, bits, _shift), \ 236 236 AD5868_CHANNEL(1, 1, bits, _shift), \ 237 237 AD5868_CHANNEL(2, 2, bits, _shift), \
+1 -1
drivers/iio/dac/ad5686.h
··· 104 104 struct ad5686_chip_info { 105 105 u16 int_vref_mv; 106 106 unsigned int num_channels; 107 - struct iio_chan_spec *channels; 107 + const struct iio_chan_spec *channels; 108 108 enum ad5686_regmap_type regmap_type; 109 109 }; 110 110
+6 -10
drivers/iio/dac/dpot-dac.c
··· 183 183 indio_dev->num_channels = 1; 184 184 185 185 dac->vref = devm_regulator_get(dev, "vref"); 186 - if (IS_ERR(dac->vref)) { 187 - if (PTR_ERR(dac->vref) != -EPROBE_DEFER) 188 - dev_err(&pdev->dev, "failed to get vref regulator\n"); 189 - return PTR_ERR(dac->vref); 190 - } 186 + if (IS_ERR(dac->vref)) 187 + return dev_err_probe(&pdev->dev, PTR_ERR(dac->vref), 188 + "failed to get vref regulator\n"); 191 189 192 190 dac->dpot = devm_iio_channel_get(dev, "dpot"); 193 - if (IS_ERR(dac->dpot)) { 194 - if (PTR_ERR(dac->dpot) != -EPROBE_DEFER) 195 - dev_err(dev, "failed to get dpot input channel\n"); 196 - return PTR_ERR(dac->dpot); 197 - } 191 + if (IS_ERR(dac->dpot)) 192 + return dev_err_probe(&pdev->dev, PTR_ERR(dac->dpot), 193 + "failed to get dpot input channel\n"); 198 194 199 195 ret = iio_get_channel_type(dac->dpot, &type); 200 196 if (ret < 0)
+1 -4
drivers/iio/dac/stm32-dac-core.c
··· 150 150 rst = devm_reset_control_get_optional_exclusive(dev, NULL); 151 151 if (rst) { 152 152 if (IS_ERR(rst)) { 153 - ret = PTR_ERR(rst); 154 - if (ret != -EPROBE_DEFER) 155 - dev_err(dev, "reset get failed, %d\n", ret); 156 - 153 + ret = dev_err_probe(dev, PTR_ERR(rst), "reset get failed\n"); 157 154 goto err_hw_stop; 158 155 } 159 156
+15 -14
drivers/iio/dac/ti-dac5571.c
··· 47 47 struct mutex lock; 48 48 struct regulator *vref; 49 49 u16 val[4]; 50 - bool powerdown; 51 - u8 powerdown_mode; 50 + bool powerdown[4]; 51 + u8 powerdown_mode[4]; 52 52 struct dac5571_spec const *spec; 53 53 int (*dac5571_cmd)(struct dac5571_data *data, int channel, u16 val); 54 54 int (*dac5571_pwrdwn)(struct dac5571_data *data, int channel, u8 pwrdwn); ··· 125 125 { 126 126 struct dac5571_data *data = iio_priv(indio_dev); 127 127 128 - return data->powerdown_mode; 128 + return data->powerdown_mode[chan->channel]; 129 129 } 130 130 131 131 static int dac5571_set_powerdown_mode(struct iio_dev *indio_dev, ··· 135 135 struct dac5571_data *data = iio_priv(indio_dev); 136 136 int ret = 0; 137 137 138 - if (data->powerdown_mode == mode) 138 + if (data->powerdown_mode[chan->channel] == mode) 139 139 return 0; 140 140 141 141 mutex_lock(&data->lock); 142 - if (data->powerdown) { 142 + if (data->powerdown[chan->channel]) { 143 143 ret = data->dac5571_pwrdwn(data, chan->channel, 144 144 DAC5571_POWERDOWN(mode)); 145 145 if (ret) 146 146 goto out; 147 147 } 148 - data->powerdown_mode = mode; 148 + data->powerdown_mode[chan->channel] = mode; 149 149 150 150 out: 151 151 mutex_unlock(&data->lock); ··· 167 167 { 168 168 struct dac5571_data *data = iio_priv(indio_dev); 169 169 170 - return sprintf(buf, "%d\n", data->powerdown); 170 + return sprintf(buf, "%d\n", data->powerdown[chan->channel]); 171 171 } 172 172 173 173 static ssize_t dac5571_write_powerdown(struct iio_dev *indio_dev, ··· 183 183 if (ret) 184 184 return ret; 185 185 186 - if (data->powerdown == powerdown) 186 + if (data->powerdown[chan->channel] == powerdown) 187 187 return len; 188 188 189 189 mutex_lock(&data->lock); 190 190 if (powerdown) 191 191 ret = data->dac5571_pwrdwn(data, chan->channel, 192 - DAC5571_POWERDOWN(data->powerdown_mode)); 192 + DAC5571_POWERDOWN(data->powerdown_mode[chan->channel])); 193 193 else 194 - ret = data->dac5571_cmd(data, chan->channel, data->val[0]); 194 + ret = data->dac5571_cmd(data, chan->channel, 195 + data->val[chan->channel]); 195 196 if (ret) 196 197 goto out; 197 198 198 - data->powerdown = powerdown; 199 + data->powerdown[chan->channel] = powerdown; 199 200 200 201 out: 201 202 mutex_unlock(&data->lock); ··· 210 209 .name = "powerdown", 211 210 .read = dac5571_read_powerdown, 212 211 .write = dac5571_write_powerdown, 213 - .shared = IIO_SHARED_BY_TYPE, 212 + .shared = IIO_SEPARATE, 214 213 }, 215 - IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE, &dac5571_powerdown_mode), 214 + IIO_ENUM("powerdown_mode", IIO_SEPARATE, &dac5571_powerdown_mode), 216 215 IIO_ENUM_AVAILABLE("powerdown_mode", &dac5571_powerdown_mode), 217 216 {}, 218 217 }; ··· 277 276 if (val >= (1 << data->spec->resolution) || val < 0) 278 277 return -EINVAL; 279 278 280 - if (data->powerdown) 279 + if (data->powerdown[chan->channel]) 281 280 return -EBUSY; 282 281 283 282 mutex_lock(&data->lock);
+20 -40
drivers/iio/frequency/ad9523.c
··· 969 969 return 0; 970 970 } 971 971 972 + static void ad9523_reg_disable(void *data) 973 + { 974 + struct regulator *reg = data; 975 + 976 + regulator_disable(reg); 977 + } 978 + 972 979 static int ad9523_probe(struct spi_device *spi) 973 980 { 974 981 struct ad9523_platform_data *pdata = spi->dev.platform_data; ··· 1001 994 ret = regulator_enable(st->reg); 1002 995 if (ret) 1003 996 return ret; 997 + 998 + ret = devm_add_action_or_reset(&spi->dev, ad9523_reg_disable, 999 + st->reg); 1000 + if (ret) 1001 + return ret; 1004 1002 } 1005 1003 1006 1004 st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown", 1007 1005 GPIOD_OUT_HIGH); 1008 - if (IS_ERR(st->pwrdown_gpio)) { 1009 - ret = PTR_ERR(st->pwrdown_gpio); 1010 - goto error_disable_reg; 1011 - } 1006 + if (IS_ERR(st->pwrdown_gpio)) 1007 + return PTR_ERR(st->pwrdown_gpio); 1012 1008 1013 1009 st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", 1014 1010 GPIOD_OUT_LOW); 1015 - if (IS_ERR(st->reset_gpio)) { 1016 - ret = PTR_ERR(st->reset_gpio); 1017 - goto error_disable_reg; 1018 - } 1011 + if (IS_ERR(st->reset_gpio)) 1012 + return PTR_ERR(st->reset_gpio); 1019 1013 1020 1014 if (st->reset_gpio) { 1021 1015 udelay(1); ··· 1025 1017 1026 1018 st->sync_gpio = devm_gpiod_get_optional(&spi->dev, "sync", 1027 1019 GPIOD_OUT_HIGH); 1028 - if (IS_ERR(st->sync_gpio)) { 1029 - ret = PTR_ERR(st->sync_gpio); 1030 - goto error_disable_reg; 1031 - } 1020 + if (IS_ERR(st->sync_gpio)) 1021 + return PTR_ERR(st->sync_gpio); 1032 1022 1033 1023 spi_set_drvdata(spi, indio_dev); 1034 1024 st->spi = spi; ··· 1041 1035 1042 1036 ret = ad9523_setup(indio_dev); 1043 1037 if (ret < 0) 1044 - goto error_disable_reg; 1038 + return ret; 1045 1039 1046 - ret = iio_device_register(indio_dev); 1047 - if (ret) 1048 - goto error_disable_reg; 1049 - 1050 - dev_info(&spi->dev, "probed %s\n", indio_dev->name); 1051 - 1052 - return 0; 1053 - 1054 - error_disable_reg: 1055 - if (!IS_ERR(st->reg)) 1056 - regulator_disable(st->reg); 1057 - 1058 - return ret; 1059 - } 1060 - 1061 - static int ad9523_remove(struct spi_device *spi) 1062 - { 1063 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 1064 - struct ad9523_state *st = iio_priv(indio_dev); 1065 - 1066 - iio_device_unregister(indio_dev); 1067 - 1068 - if (!IS_ERR(st->reg)) 1069 - regulator_disable(st->reg); 1070 - 1071 - return 0; 1040 + return devm_iio_device_register(&spi->dev, indio_dev); 1072 1041 } 1073 1042 1074 1043 static const struct spi_device_id ad9523_id[] = { ··· 1057 1076 .name = "ad9523", 1058 1077 }, 1059 1078 .probe = ad9523_probe, 1060 - .remove = ad9523_remove, 1061 1079 .id_table = ad9523_id, 1062 1080 }; 1063 1081 module_spi_driver(ad9523_driver);
+10
drivers/iio/gyro/Kconfig
··· 41 41 This driver can also be built as a module. If so, the module 42 42 will be called adis16260. 43 43 44 + config ADXRS290 45 + tristate "Analog Devices ADXRS290 Dual-Axis MEMS Gyroscope SPI driver" 46 + depends on SPI 47 + help 48 + Say yes here to build support for Analog Devices ADXRS290 programmable 49 + digital output gyroscope. 50 + 51 + This driver can also be built as a module. If so, the module will be 52 + called adxrs290. 53 + 44 54 config ADXRS450 45 55 tristate "Analog Devices ADXRS450/3 Digital Output Gyroscope SPI driver" 46 56 depends on SPI
+1
drivers/iio/gyro/Makefile
··· 8 8 obj-$(CONFIG_ADIS16130) += adis16130.o 9 9 obj-$(CONFIG_ADIS16136) += adis16136.o 10 10 obj-$(CONFIG_ADIS16260) += adis16260.o 11 + obj-$(CONFIG_ADXRS290) += adxrs290.o 11 12 obj-$(CONFIG_ADXRS450) += adxrs450.o 12 13 obj-$(CONFIG_BMG160) += bmg160_core.o 13 14 obj-$(CONFIG_BMG160_I2C) += bmg160_i2c.o
+446
drivers/iio/gyro/adxrs290.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * ADXRS290 SPI Gyroscope Driver 4 + * 5 + * Copyright (C) 2020 Nishant Malpani <nish.malpani25@gmail.com> 6 + * Copyright (C) 2020 Analog Devices, Inc. 7 + */ 8 + 9 + #include <linux/bitfield.h> 10 + #include <linux/delay.h> 11 + #include <linux/device.h> 12 + #include <linux/kernel.h> 13 + #include <linux/module.h> 14 + #include <linux/spi/spi.h> 15 + 16 + #include <linux/iio/iio.h> 17 + #include <linux/iio/sysfs.h> 18 + 19 + #define ADXRS290_ADI_ID 0xAD 20 + #define ADXRS290_MEMS_ID 0x1D 21 + #define ADXRS290_DEV_ID 0x92 22 + 23 + #define ADXRS290_REG_ADI_ID 0x00 24 + #define ADXRS290_REG_MEMS_ID 0x01 25 + #define ADXRS290_REG_DEV_ID 0x02 26 + #define ADXRS290_REG_REV_ID 0x03 27 + #define ADXRS290_REG_SN0 0x04 /* Serial Number Registers, 4 bytes */ 28 + #define ADXRS290_REG_DATAX0 0x08 /* Roll Rate o/p Data Regs, 2 bytes */ 29 + #define ADXRS290_REG_DATAY0 0x0A /* Pitch Rate o/p Data Regs, 2 bytes */ 30 + #define ADXRS290_REG_TEMP0 0x0C 31 + #define ADXRS290_REG_POWER_CTL 0x10 32 + #define ADXRS290_REG_FILTER 0x11 33 + #define ADXRS290_REG_DATA_RDY 0x12 34 + 35 + #define ADXRS290_READ BIT(7) 36 + #define ADXRS290_TSM BIT(0) 37 + #define ADXRS290_MEASUREMENT BIT(1) 38 + #define ADXRS290_SYNC GENMASK(1, 0) 39 + #define ADXRS290_LPF_MASK GENMASK(2, 0) 40 + #define ADXRS290_LPF(x) FIELD_PREP(ADXRS290_LPF_MASK, x) 41 + #define ADXRS290_HPF_MASK GENMASK(7, 4) 42 + #define ADXRS290_HPF(x) FIELD_PREP(ADXRS290_HPF_MASK, x) 43 + 44 + #define ADXRS290_READ_REG(reg) (ADXRS290_READ | (reg)) 45 + 46 + #define ADXRS290_MAX_TRANSITION_TIME_MS 100 47 + 48 + enum adxrs290_mode { 49 + ADXRS290_MODE_STANDBY, 50 + ADXRS290_MODE_MEASUREMENT, 51 + }; 52 + 53 + struct adxrs290_state { 54 + struct spi_device *spi; 55 + /* Serialize reads and their subsequent processing */ 56 + struct mutex lock; 57 + enum adxrs290_mode mode; 58 + unsigned int lpf_3db_freq_idx; 59 + unsigned int hpf_3db_freq_idx; 60 + }; 61 + 62 + /* 63 + * Available cut-off frequencies of the low pass filter in Hz. 64 + * The integer part and fractional part are represented separately. 65 + */ 66 + static const int adxrs290_lpf_3db_freq_hz_table[][2] = { 67 + [0] = {480, 0}, 68 + [1] = {320, 0}, 69 + [2] = {160, 0}, 70 + [3] = {80, 0}, 71 + [4] = {56, 600000}, 72 + [5] = {40, 0}, 73 + [6] = {28, 300000}, 74 + [7] = {20, 0}, 75 + }; 76 + 77 + /* 78 + * Available cut-off frequencies of the high pass filter in Hz. 79 + * The integer part and fractional part are represented separately. 80 + */ 81 + static const int adxrs290_hpf_3db_freq_hz_table[][2] = { 82 + [0] = {0, 0}, 83 + [1] = {0, 11000}, 84 + [2] = {0, 22000}, 85 + [3] = {0, 44000}, 86 + [4] = {0, 87000}, 87 + [5] = {0, 175000}, 88 + [6] = {0, 350000}, 89 + [7] = {0, 700000}, 90 + [8] = {1, 400000}, 91 + [9] = {2, 800000}, 92 + [10] = {11, 300000}, 93 + }; 94 + 95 + static int adxrs290_get_rate_data(struct iio_dev *indio_dev, const u8 cmd, int *val) 96 + { 97 + struct adxrs290_state *st = iio_priv(indio_dev); 98 + int ret = 0; 99 + int temp; 100 + 101 + mutex_lock(&st->lock); 102 + temp = spi_w8r16(st->spi, cmd); 103 + if (temp < 0) { 104 + ret = temp; 105 + goto err_unlock; 106 + } 107 + 108 + *val = temp; 109 + 110 + err_unlock: 111 + mutex_unlock(&st->lock); 112 + return ret; 113 + } 114 + 115 + static int adxrs290_get_temp_data(struct iio_dev *indio_dev, int *val) 116 + { 117 + const u8 cmd = ADXRS290_READ_REG(ADXRS290_REG_TEMP0); 118 + struct adxrs290_state *st = iio_priv(indio_dev); 119 + int ret = 0; 120 + int temp; 121 + 122 + mutex_lock(&st->lock); 123 + temp = spi_w8r16(st->spi, cmd); 124 + if (temp < 0) { 125 + ret = temp; 126 + goto err_unlock; 127 + } 128 + 129 + /* extract lower 12 bits temperature reading */ 130 + *val = temp & 0x0FFF; 131 + 132 + err_unlock: 133 + mutex_unlock(&st->lock); 134 + return ret; 135 + } 136 + 137 + static int adxrs290_get_3db_freq(struct iio_dev *indio_dev, u8 *val, u8 *val2) 138 + { 139 + const u8 cmd = ADXRS290_READ_REG(ADXRS290_REG_FILTER); 140 + struct adxrs290_state *st = iio_priv(indio_dev); 141 + int ret = 0; 142 + short temp; 143 + 144 + mutex_lock(&st->lock); 145 + temp = spi_w8r8(st->spi, cmd); 146 + if (temp < 0) { 147 + ret = temp; 148 + goto err_unlock; 149 + } 150 + 151 + *val = FIELD_GET(ADXRS290_LPF_MASK, temp); 152 + *val2 = FIELD_GET(ADXRS290_HPF_MASK, temp); 153 + 154 + err_unlock: 155 + mutex_unlock(&st->lock); 156 + return ret; 157 + } 158 + 159 + static int adxrs290_spi_write_reg(struct spi_device *spi, const u8 reg, 160 + const u8 val) 161 + { 162 + u8 buf[2]; 163 + 164 + buf[0] = reg; 165 + buf[1] = val; 166 + 167 + return spi_write_then_read(spi, buf, ARRAY_SIZE(buf), NULL, 0); 168 + } 169 + 170 + static int adxrs290_find_match(const int (*freq_tbl)[2], const int n, 171 + const int val, const int val2) 172 + { 173 + int i; 174 + 175 + for (i = 0; i < n; i++) { 176 + if (freq_tbl[i][0] == val && freq_tbl[i][1] == val2) 177 + return i; 178 + } 179 + 180 + return -EINVAL; 181 + } 182 + 183 + static int adxrs290_set_filter_freq(struct iio_dev *indio_dev, 184 + const unsigned int lpf_idx, 185 + const unsigned int hpf_idx) 186 + { 187 + struct adxrs290_state *st = iio_priv(indio_dev); 188 + u8 val; 189 + 190 + val = ADXRS290_HPF(hpf_idx) | ADXRS290_LPF(lpf_idx); 191 + 192 + return adxrs290_spi_write_reg(st->spi, ADXRS290_REG_FILTER, val); 193 + } 194 + 195 + static int adxrs290_initial_setup(struct iio_dev *indio_dev) 196 + { 197 + struct adxrs290_state *st = iio_priv(indio_dev); 198 + 199 + st->mode = ADXRS290_MODE_MEASUREMENT; 200 + 201 + return adxrs290_spi_write_reg(st->spi, 202 + ADXRS290_REG_POWER_CTL, 203 + ADXRS290_MEASUREMENT | ADXRS290_TSM); 204 + } 205 + 206 + static int adxrs290_read_raw(struct iio_dev *indio_dev, 207 + struct iio_chan_spec const *chan, 208 + int *val, 209 + int *val2, 210 + long mask) 211 + { 212 + struct adxrs290_state *st = iio_priv(indio_dev); 213 + unsigned int t; 214 + int ret; 215 + 216 + switch (mask) { 217 + case IIO_CHAN_INFO_RAW: 218 + switch (chan->type) { 219 + case IIO_ANGL_VEL: 220 + ret = adxrs290_get_rate_data(indio_dev, 221 + ADXRS290_READ_REG(chan->address), 222 + val); 223 + if (ret < 0) 224 + return ret; 225 + 226 + return IIO_VAL_INT; 227 + case IIO_TEMP: 228 + ret = adxrs290_get_temp_data(indio_dev, val); 229 + if (ret < 0) 230 + return ret; 231 + 232 + return IIO_VAL_INT; 233 + default: 234 + return -EINVAL; 235 + } 236 + case IIO_CHAN_INFO_SCALE: 237 + switch (chan->type) { 238 + case IIO_ANGL_VEL: 239 + /* 1 LSB = 0.005 degrees/sec */ 240 + *val = 0; 241 + *val2 = 87266; 242 + return IIO_VAL_INT_PLUS_NANO; 243 + case IIO_TEMP: 244 + /* 1 LSB = 0.1 degrees Celsius */ 245 + *val = 100; 246 + return IIO_VAL_INT; 247 + default: 248 + return -EINVAL; 249 + } 250 + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 251 + switch (chan->type) { 252 + case IIO_ANGL_VEL: 253 + t = st->lpf_3db_freq_idx; 254 + *val = adxrs290_lpf_3db_freq_hz_table[t][0]; 255 + *val2 = adxrs290_lpf_3db_freq_hz_table[t][1]; 256 + return IIO_VAL_INT_PLUS_MICRO; 257 + default: 258 + return -EINVAL; 259 + } 260 + case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: 261 + switch (chan->type) { 262 + case IIO_ANGL_VEL: 263 + t = st->hpf_3db_freq_idx; 264 + *val = adxrs290_hpf_3db_freq_hz_table[t][0]; 265 + *val2 = adxrs290_hpf_3db_freq_hz_table[t][1]; 266 + return IIO_VAL_INT_PLUS_MICRO; 267 + default: 268 + return -EINVAL; 269 + } 270 + } 271 + 272 + return -EINVAL; 273 + } 274 + 275 + static int adxrs290_write_raw(struct iio_dev *indio_dev, 276 + struct iio_chan_spec const *chan, 277 + int val, 278 + int val2, 279 + long mask) 280 + { 281 + struct adxrs290_state *st = iio_priv(indio_dev); 282 + int lpf_idx, hpf_idx; 283 + 284 + switch (mask) { 285 + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 286 + lpf_idx = adxrs290_find_match(adxrs290_lpf_3db_freq_hz_table, 287 + ARRAY_SIZE(adxrs290_lpf_3db_freq_hz_table), 288 + val, val2); 289 + if (lpf_idx < 0) 290 + return -EINVAL; 291 + /* caching the updated state of the low-pass filter */ 292 + st->lpf_3db_freq_idx = lpf_idx; 293 + /* retrieving the current state of the high-pass filter */ 294 + hpf_idx = st->hpf_3db_freq_idx; 295 + return adxrs290_set_filter_freq(indio_dev, lpf_idx, hpf_idx); 296 + case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: 297 + hpf_idx = adxrs290_find_match(adxrs290_hpf_3db_freq_hz_table, 298 + ARRAY_SIZE(adxrs290_hpf_3db_freq_hz_table), 299 + val, val2); 300 + if (hpf_idx < 0) 301 + return -EINVAL; 302 + /* caching the updated state of the high-pass filter */ 303 + st->hpf_3db_freq_idx = hpf_idx; 304 + /* retrieving the current state of the low-pass filter */ 305 + lpf_idx = st->lpf_3db_freq_idx; 306 + return adxrs290_set_filter_freq(indio_dev, lpf_idx, hpf_idx); 307 + } 308 + 309 + return -EINVAL; 310 + } 311 + 312 + static int adxrs290_read_avail(struct iio_dev *indio_dev, 313 + struct iio_chan_spec const *chan, 314 + const int **vals, int *type, int *length, 315 + long mask) 316 + { 317 + switch (mask) { 318 + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 319 + *vals = (const int *)adxrs290_lpf_3db_freq_hz_table; 320 + *type = IIO_VAL_INT_PLUS_MICRO; 321 + /* Values are stored in a 2D matrix */ 322 + *length = ARRAY_SIZE(adxrs290_lpf_3db_freq_hz_table) * 2; 323 + 324 + return IIO_AVAIL_LIST; 325 + case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: 326 + *vals = (const int *)adxrs290_hpf_3db_freq_hz_table; 327 + *type = IIO_VAL_INT_PLUS_MICRO; 328 + /* Values are stored in a 2D matrix */ 329 + *length = ARRAY_SIZE(adxrs290_hpf_3db_freq_hz_table) * 2; 330 + 331 + return IIO_AVAIL_LIST; 332 + default: 333 + return -EINVAL; 334 + } 335 + } 336 + 337 + #define ADXRS290_ANGL_VEL_CHANNEL(reg, axis) { \ 338 + .type = IIO_ANGL_VEL, \ 339 + .address = reg, \ 340 + .modified = 1, \ 341 + .channel2 = IIO_MOD_##axis, \ 342 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 343 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 344 + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | \ 345 + BIT(IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY), \ 346 + .info_mask_shared_by_type_available = \ 347 + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | \ 348 + BIT(IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY), \ 349 + } 350 + 351 + static const struct iio_chan_spec adxrs290_channels[] = { 352 + ADXRS290_ANGL_VEL_CHANNEL(ADXRS290_REG_DATAX0, X), 353 + ADXRS290_ANGL_VEL_CHANNEL(ADXRS290_REG_DATAY0, Y), 354 + { 355 + .type = IIO_TEMP, 356 + .address = ADXRS290_REG_TEMP0, 357 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 358 + BIT(IIO_CHAN_INFO_SCALE), 359 + }, 360 + }; 361 + 362 + static const struct iio_info adxrs290_info = { 363 + .read_raw = &adxrs290_read_raw, 364 + .write_raw = &adxrs290_write_raw, 365 + .read_avail = &adxrs290_read_avail, 366 + }; 367 + 368 + static int adxrs290_probe(struct spi_device *spi) 369 + { 370 + struct iio_dev *indio_dev; 371 + struct adxrs290_state *st; 372 + u8 val, val2; 373 + int ret; 374 + 375 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 376 + if (!indio_dev) 377 + return -ENOMEM; 378 + 379 + st = iio_priv(indio_dev); 380 + st->spi = spi; 381 + 382 + indio_dev->name = "adxrs290"; 383 + indio_dev->modes = INDIO_DIRECT_MODE; 384 + indio_dev->channels = adxrs290_channels; 385 + indio_dev->num_channels = ARRAY_SIZE(adxrs290_channels); 386 + indio_dev->info = &adxrs290_info; 387 + 388 + mutex_init(&st->lock); 389 + 390 + val = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_ADI_ID)); 391 + if (val != ADXRS290_ADI_ID) { 392 + dev_err(&spi->dev, "Wrong ADI ID 0x%02x\n", val); 393 + return -ENODEV; 394 + } 395 + 396 + val = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_MEMS_ID)); 397 + if (val != ADXRS290_MEMS_ID) { 398 + dev_err(&spi->dev, "Wrong MEMS ID 0x%02x\n", val); 399 + return -ENODEV; 400 + } 401 + 402 + val = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_DEV_ID)); 403 + if (val != ADXRS290_DEV_ID) { 404 + dev_err(&spi->dev, "Wrong DEV ID 0x%02x\n", val); 405 + return -ENODEV; 406 + } 407 + 408 + /* default mode the gyroscope starts in */ 409 + st->mode = ADXRS290_MODE_STANDBY; 410 + 411 + /* switch to measurement mode and switch on the temperature sensor */ 412 + ret = adxrs290_initial_setup(indio_dev); 413 + if (ret < 0) 414 + return ret; 415 + 416 + /* max transition time to measurement mode */ 417 + msleep(ADXRS290_MAX_TRANSITION_TIME_MS); 418 + 419 + ret = adxrs290_get_3db_freq(indio_dev, &val, &val2); 420 + if (ret < 0) 421 + return ret; 422 + 423 + st->lpf_3db_freq_idx = val; 424 + st->hpf_3db_freq_idx = val2; 425 + 426 + return devm_iio_device_register(&spi->dev, indio_dev); 427 + } 428 + 429 + static const struct of_device_id adxrs290_of_match[] = { 430 + { .compatible = "adi,adxrs290" }, 431 + { } 432 + }; 433 + MODULE_DEVICE_TABLE(of, adxrs290_of_match); 434 + 435 + static struct spi_driver adxrs290_driver = { 436 + .driver = { 437 + .name = "adxrs290", 438 + .of_match_table = adxrs290_of_match, 439 + }, 440 + .probe = adxrs290_probe, 441 + }; 442 + module_spi_driver(adxrs290_driver); 443 + 444 + MODULE_AUTHOR("Nishant Malpani <nish.malpani25@gmail.com>"); 445 + MODULE_DESCRIPTION("Analog Devices ADXRS290 Gyroscope SPI driver"); 446 + MODULE_LICENSE("GPL");
+2 -2
drivers/iio/health/max30102.c
··· 2 2 /* 3 3 * max30102.c - Support for MAX30102 heart rate and pulse oximeter sensor 4 4 * 5 - * Copyright (C) 2017 Matt Ranostay <matt@ranostay.consulting> 5 + * Copyright (C) 2017 Matt Ranostay <matt.ranostay@konsulko.com> 6 6 * 7 7 * Support for MAX30105 optical particle sensor 8 8 * Copyright (C) 2017 Peter Meerwald-Stadler <pmeerw@pmeerw.net> ··· 632 632 }; 633 633 module_i2c_driver(max30102_driver); 634 634 635 - MODULE_AUTHOR("Matt Ranostay <matt@ranostay.consulting>"); 635 + MODULE_AUTHOR("Matt Ranostay <matt.ranostay@konsulko.com>"); 636 636 MODULE_DESCRIPTION("MAX30102 heart rate/pulse oximeter and MAX30105 particle sensor driver"); 637 637 MODULE_LICENSE("GPL");
+10
drivers/iio/humidity/Kconfig
··· 38 38 To compile this driver as a module, choose M here: the module 39 39 will be called hdc100x. 40 40 41 + config HDC2010 42 + tristate "TI HDC2010 relative humidity and temperature sensor" 43 + depends on I2C 44 + help 45 + Say yes here to build support for the Texas Instruments 46 + HDC2010 and HDC2080 relative humidity and temperature sensors. 47 + 48 + To compile this driver as a module, choose M here: the module 49 + will be called hdc2010. 50 + 41 51 config HID_SENSOR_HUMIDITY 42 52 tristate "HID Environmental humidity sensor" 43 53 depends on HID_SENSOR_HUB
+1
drivers/iio/humidity/Makefile
··· 6 6 obj-$(CONFIG_AM2315) += am2315.o 7 7 obj-$(CONFIG_DHT11) += dht11.o 8 8 obj-$(CONFIG_HDC100X) += hdc100x.o 9 + obj-$(CONFIG_HDC2010) += hdc2010.o 9 10 obj-$(CONFIG_HID_SENSOR_HUMIDITY) += hid-sensor-humidity.o 10 11 11 12 hts221-y := hts221_core.o \
+353
drivers/iio/humidity/hdc2010.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * hdc2010.c - Support for the TI HDC2010 and HDC2080 4 + * temperature + relative humidity sensors 5 + * 6 + * Copyright (C) 2020 Norphonic AS 7 + * Author: Eugene Zaikonnikov <ez@norphonic.com> 8 + * 9 + * Datasheet: https://www.ti.com/product/HDC2010/datasheet 10 + * Datasheet: https://www.ti.com/product/HDC2080/datasheet 11 + */ 12 + 13 + #include <linux/module.h> 14 + #include <linux/init.h> 15 + #include <linux/i2c.h> 16 + #include <linux/bitops.h> 17 + 18 + #include <linux/iio/iio.h> 19 + #include <linux/iio/sysfs.h> 20 + 21 + #define HDC2010_REG_TEMP_LOW 0x00 22 + #define HDC2010_REG_TEMP_HIGH 0x01 23 + #define HDC2010_REG_HUMIDITY_LOW 0x02 24 + #define HDC2010_REG_HUMIDITY_HIGH 0x03 25 + #define HDC2010_REG_INTERRUPT_DRDY 0x04 26 + #define HDC2010_REG_TEMP_MAX 0x05 27 + #define HDC2010_REG_HUMIDITY_MAX 0x06 28 + #define HDC2010_REG_INTERRUPT_EN 0x07 29 + #define HDC2010_REG_TEMP_OFFSET_ADJ 0x08 30 + #define HDC2010_REG_HUMIDITY_OFFSET_ADJ 0x09 31 + #define HDC2010_REG_TEMP_THR_L 0x0a 32 + #define HDC2010_REG_TEMP_THR_H 0x0b 33 + #define HDC2010_REG_RH_THR_L 0x0c 34 + #define HDC2010_REG_RH_THR_H 0x0d 35 + #define HDC2010_REG_RESET_DRDY_INT_CONF 0x0e 36 + #define HDC2010_REG_MEASUREMENT_CONF 0x0f 37 + 38 + #define HDC2010_MEAS_CONF GENMASK(2, 1) 39 + #define HDC2010_MEAS_TRIG BIT(0) 40 + #define HDC2010_HEATER_EN BIT(3) 41 + #define HDC2010_AMM GENMASK(6, 4) 42 + 43 + struct hdc2010_data { 44 + struct i2c_client *client; 45 + struct mutex lock; 46 + u8 measurement_config; 47 + u8 interrupt_config; 48 + u8 drdy_config; 49 + }; 50 + 51 + enum hdc2010_addr_groups { 52 + HDC2010_GROUP_TEMP = 0, 53 + HDC2010_GROUP_HUMIDITY, 54 + }; 55 + 56 + struct hdc2010_reg_record { 57 + unsigned long primary; 58 + unsigned long peak; 59 + }; 60 + 61 + static const struct hdc2010_reg_record hdc2010_reg_translation[] = { 62 + [HDC2010_GROUP_TEMP] = { 63 + .primary = HDC2010_REG_TEMP_LOW, 64 + .peak = HDC2010_REG_TEMP_MAX, 65 + }, 66 + [HDC2010_GROUP_HUMIDITY] = { 67 + .primary = HDC2010_REG_HUMIDITY_LOW, 68 + .peak = HDC2010_REG_HUMIDITY_MAX, 69 + }, 70 + }; 71 + 72 + static IIO_CONST_ATTR(out_current_heater_raw_available, "0 1"); 73 + 74 + static struct attribute *hdc2010_attributes[] = { 75 + &iio_const_attr_out_current_heater_raw_available.dev_attr.attr, 76 + NULL 77 + }; 78 + 79 + static const struct attribute_group hdc2010_attribute_group = { 80 + .attrs = hdc2010_attributes, 81 + }; 82 + 83 + static const struct iio_chan_spec hdc2010_channels[] = { 84 + { 85 + .type = IIO_TEMP, 86 + .address = HDC2010_GROUP_TEMP, 87 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 88 + BIT(IIO_CHAN_INFO_PEAK) | 89 + BIT(IIO_CHAN_INFO_OFFSET) | 90 + BIT(IIO_CHAN_INFO_SCALE), 91 + }, 92 + { 93 + .type = IIO_HUMIDITYRELATIVE, 94 + .address = HDC2010_GROUP_HUMIDITY, 95 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 96 + BIT(IIO_CHAN_INFO_PEAK) | 97 + BIT(IIO_CHAN_INFO_SCALE), 98 + }, 99 + { 100 + .type = IIO_CURRENT, 101 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 102 + .extend_name = "heater", 103 + .output = 1, 104 + }, 105 + }; 106 + 107 + static int hdc2010_update_drdy_config(struct hdc2010_data *data, 108 + char mask, char val) 109 + { 110 + u8 tmp = (~mask & data->drdy_config) | val; 111 + int ret; 112 + 113 + ret = i2c_smbus_write_byte_data(data->client, 114 + HDC2010_REG_RESET_DRDY_INT_CONF, tmp); 115 + if (ret) 116 + return ret; 117 + 118 + data->drdy_config = tmp; 119 + 120 + return 0; 121 + } 122 + 123 + static int hdc2010_get_prim_measurement_word(struct hdc2010_data *data, 124 + struct iio_chan_spec const *chan) 125 + { 126 + struct i2c_client *client = data->client; 127 + s32 ret; 128 + 129 + ret = i2c_smbus_read_word_data(client, 130 + hdc2010_reg_translation[chan->address].primary); 131 + 132 + if (ret < 0) 133 + dev_err(&client->dev, "Could not read sensor measurement word\n"); 134 + 135 + return ret; 136 + } 137 + 138 + static int hdc2010_get_peak_measurement_byte(struct hdc2010_data *data, 139 + struct iio_chan_spec const *chan) 140 + { 141 + struct i2c_client *client = data->client; 142 + s32 ret; 143 + 144 + ret = i2c_smbus_read_byte_data(client, 145 + hdc2010_reg_translation[chan->address].peak); 146 + 147 + if (ret < 0) 148 + dev_err(&client->dev, "Could not read sensor measurement byte\n"); 149 + 150 + return ret; 151 + } 152 + 153 + static int hdc2010_get_heater_status(struct hdc2010_data *data) 154 + { 155 + return !!(data->drdy_config & HDC2010_HEATER_EN); 156 + } 157 + 158 + static int hdc2010_read_raw(struct iio_dev *indio_dev, 159 + struct iio_chan_spec const *chan, int *val, 160 + int *val2, long mask) 161 + { 162 + struct hdc2010_data *data = iio_priv(indio_dev); 163 + 164 + switch (mask) { 165 + case IIO_CHAN_INFO_RAW: { 166 + int ret; 167 + 168 + if (chan->type == IIO_CURRENT) { 169 + *val = hdc2010_get_heater_status(data); 170 + return IIO_VAL_INT; 171 + } 172 + ret = iio_device_claim_direct_mode(indio_dev); 173 + if (ret) 174 + return ret; 175 + mutex_lock(&data->lock); 176 + ret = hdc2010_get_prim_measurement_word(data, chan); 177 + mutex_unlock(&data->lock); 178 + iio_device_release_direct_mode(indio_dev); 179 + if (ret < 0) 180 + return ret; 181 + *val = ret; 182 + return IIO_VAL_INT; 183 + } 184 + case IIO_CHAN_INFO_PEAK: { 185 + int ret; 186 + 187 + ret = iio_device_claim_direct_mode(indio_dev); 188 + if (ret) 189 + return ret; 190 + mutex_lock(&data->lock); 191 + ret = hdc2010_get_peak_measurement_byte(data, chan); 192 + mutex_unlock(&data->lock); 193 + iio_device_release_direct_mode(indio_dev); 194 + if (ret < 0) 195 + return ret; 196 + /* Scaling up the value so we can use same offset as RAW */ 197 + *val = ret * 256; 198 + return IIO_VAL_INT; 199 + } 200 + case IIO_CHAN_INFO_SCALE: 201 + *val2 = 65536; 202 + if (chan->type == IIO_TEMP) 203 + *val = 165000; 204 + else 205 + *val = 100000; 206 + return IIO_VAL_FRACTIONAL; 207 + case IIO_CHAN_INFO_OFFSET: 208 + *val = -15887; 209 + *val2 = 515151; 210 + return IIO_VAL_INT_PLUS_MICRO; 211 + default: 212 + return -EINVAL; 213 + } 214 + } 215 + 216 + static int hdc2010_write_raw(struct iio_dev *indio_dev, 217 + struct iio_chan_spec const *chan, 218 + int val, int val2, long mask) 219 + { 220 + struct hdc2010_data *data = iio_priv(indio_dev); 221 + int new, ret; 222 + 223 + switch (mask) { 224 + case IIO_CHAN_INFO_RAW: 225 + if (chan->type != IIO_CURRENT || val2 != 0) 226 + return -EINVAL; 227 + 228 + switch (val) { 229 + case 1: 230 + new = HDC2010_HEATER_EN; 231 + break; 232 + case 0: 233 + new = 0; 234 + break; 235 + default: 236 + return -EINVAL; 237 + } 238 + 239 + mutex_lock(&data->lock); 240 + ret = hdc2010_update_drdy_config(data, HDC2010_HEATER_EN, new); 241 + mutex_unlock(&data->lock); 242 + return ret; 243 + default: 244 + return -EINVAL; 245 + } 246 + } 247 + 248 + static const struct iio_info hdc2010_info = { 249 + .read_raw = hdc2010_read_raw, 250 + .write_raw = hdc2010_write_raw, 251 + .attrs = &hdc2010_attribute_group, 252 + }; 253 + 254 + static int hdc2010_probe(struct i2c_client *client, 255 + const struct i2c_device_id *id) 256 + { 257 + struct iio_dev *indio_dev; 258 + struct hdc2010_data *data; 259 + u8 tmp; 260 + int ret; 261 + 262 + if (!i2c_check_functionality(client->adapter, 263 + I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BYTE | I2C_FUNC_I2C)) 264 + return -EOPNOTSUPP; 265 + 266 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 267 + if (!indio_dev) 268 + return -ENOMEM; 269 + 270 + data = iio_priv(indio_dev); 271 + i2c_set_clientdata(client, indio_dev); 272 + data->client = client; 273 + mutex_init(&data->lock); 274 + 275 + indio_dev->dev.parent = &client->dev; 276 + /* 277 + * As DEVICE ID register does not differentiate between 278 + * HDC2010 and HDC2080, we have the name hardcoded 279 + */ 280 + indio_dev->name = "hdc2010"; 281 + indio_dev->modes = INDIO_DIRECT_MODE; 282 + indio_dev->info = &hdc2010_info; 283 + 284 + indio_dev->channels = hdc2010_channels; 285 + indio_dev->num_channels = ARRAY_SIZE(hdc2010_channels); 286 + 287 + /* Enable Automatic Measurement Mode at 5Hz */ 288 + ret = hdc2010_update_drdy_config(data, HDC2010_AMM, HDC2010_AMM); 289 + if (ret) 290 + return ret; 291 + 292 + /* 293 + * We enable both temp and humidity measurement. 294 + * However the measurement won't start even in AMM until triggered. 295 + */ 296 + tmp = (data->measurement_config & ~HDC2010_MEAS_CONF) | 297 + HDC2010_MEAS_TRIG; 298 + 299 + ret = i2c_smbus_write_byte_data(client, HDC2010_REG_MEASUREMENT_CONF, tmp); 300 + if (ret) { 301 + dev_warn(&client->dev, "Unable to set up measurement\n"); 302 + if (hdc2010_update_drdy_config(data, HDC2010_AMM, 0)) 303 + dev_warn(&client->dev, "Unable to restore default AMM\n"); 304 + return ret; 305 + } 306 + 307 + data->measurement_config = tmp; 308 + 309 + return iio_device_register(indio_dev); 310 + } 311 + 312 + static int hdc2010_remove(struct i2c_client *client) 313 + { 314 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 315 + struct hdc2010_data *data = iio_priv(indio_dev); 316 + 317 + iio_device_unregister(indio_dev); 318 + 319 + /* Disable Automatic Measurement Mode */ 320 + if (hdc2010_update_drdy_config(data, HDC2010_AMM, 0)) 321 + dev_warn(&client->dev, "Unable to restore default AMM\n"); 322 + 323 + return 0; 324 + } 325 + 326 + static const struct i2c_device_id hdc2010_id[] = { 327 + { "hdc2010" }, 328 + { "hdc2080" }, 329 + { } 330 + }; 331 + MODULE_DEVICE_TABLE(i2c, hdc2010_id); 332 + 333 + static const struct of_device_id hdc2010_dt_ids[] = { 334 + { .compatible = "ti,hdc2010" }, 335 + { .compatible = "ti,hdc2080" }, 336 + { } 337 + }; 338 + MODULE_DEVICE_TABLE(of, hdc2010_dt_ids); 339 + 340 + static struct i2c_driver hdc2010_driver = { 341 + .driver = { 342 + .name = "hdc2010", 343 + .of_match_table = hdc2010_dt_ids, 344 + }, 345 + .probe = hdc2010_probe, 346 + .remove = hdc2010_remove, 347 + .id_table = hdc2010_id, 348 + }; 349 + module_i2c_driver(hdc2010_driver); 350 + 351 + MODULE_AUTHOR("Eugene Zaikonnikov <ez@norphonic.com>"); 352 + MODULE_DESCRIPTION("TI HDC2010 humidity and temperature sensor driver"); 353 + MODULE_LICENSE("GPL");
+2 -2
drivers/iio/iio_core_trigger.h
··· 30 30 * iio_device_register_trigger_consumer() - set up an iio_dev to use triggers 31 31 * @indio_dev: iio_dev associated with the device that will consume the trigger 32 32 **/ 33 - static int iio_device_register_trigger_consumer(struct iio_dev *indio_dev) 33 + static inline int iio_device_register_trigger_consumer(struct iio_dev *indio_dev) 34 34 { 35 35 return 0; 36 36 } ··· 39 39 * iio_device_unregister_trigger_consumer() - reverse the registration process 40 40 * @indio_dev: iio_dev associated with the device that consumed the trigger 41 41 **/ 42 - static void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev) 42 + static inline void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev) 43 43 { 44 44 } 45 45
+6 -14
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 1475 1475 } 1476 1476 1477 1477 st->vdd_supply = devm_regulator_get(dev, "vdd"); 1478 - if (IS_ERR(st->vdd_supply)) { 1479 - if (PTR_ERR(st->vdd_supply) != -EPROBE_DEFER) 1480 - dev_err(dev, "Failed to get vdd regulator %d\n", 1481 - (int)PTR_ERR(st->vdd_supply)); 1482 - 1483 - return PTR_ERR(st->vdd_supply); 1484 - } 1478 + if (IS_ERR(st->vdd_supply)) 1479 + return dev_err_probe(dev, PTR_ERR(st->vdd_supply), 1480 + "Failed to get vdd regulator\n"); 1485 1481 1486 1482 st->vddio_supply = devm_regulator_get(dev, "vddio"); 1487 - if (IS_ERR(st->vddio_supply)) { 1488 - if (PTR_ERR(st->vddio_supply) != -EPROBE_DEFER) 1489 - dev_err(dev, "Failed to get vddio regulator %d\n", 1490 - (int)PTR_ERR(st->vddio_supply)); 1491 - 1492 - return PTR_ERR(st->vddio_supply); 1493 - } 1483 + if (IS_ERR(st->vddio_supply)) 1484 + return dev_err_probe(dev, PTR_ERR(st->vddio_supply), 1485 + "Failed to get vddio regulator\n"); 1494 1486 1495 1487 result = regulator_enable(st->vdd_supply); 1496 1488 if (result) {
+1
drivers/iio/industrialio-core.c
··· 133 133 [IIO_MOD_PM10] = "pm10", 134 134 [IIO_MOD_ETHANOL] = "ethanol", 135 135 [IIO_MOD_H2] = "h2", 136 + [IIO_MOD_O2] = "o2", 136 137 }; 137 138 138 139 /* relies on pairs of these shared then separate */
+15
drivers/iio/light/Kconfig
··· 86 86 To compile this driver as a module, choose M here: the 87 87 module will be called apds9960 88 88 89 + config AS73211 90 + tristate "AMS AS73211 XYZ color sensor" 91 + depends on I2C 92 + select IIO_BUFFER 93 + select IIO_TRIGGERED_BUFFER 94 + help 95 + If you say yes here you get support for the AMS AS73211 96 + JENCOLOR(R) Digital XYZ Sensor. 97 + 98 + For triggered measurements, you will need an additional trigger driver 99 + like IIO_HRTIMER_TRIGGER or IIO_SYSFS_TRIGGER. 100 + 101 + This driver can also be built as a module. If so, the module 102 + will be called as73211. 103 + 89 104 config BH1750 90 105 tristate "ROHM BH1750 ambient light sensor" 91 106 depends on I2C
+1
drivers/iio/light/Makefile
··· 11 11 obj-$(CONFIG_AL3320A) += al3320a.o 12 12 obj-$(CONFIG_APDS9300) += apds9300.o 13 13 obj-$(CONFIG_APDS9960) += apds9960.o 14 + obj-$(CONFIG_AS73211) += as73211.o 14 15 obj-$(CONFIG_BH1750) += bh1750.o 15 16 obj-$(CONFIG_BH1780) += bh1780.o 16 17 obj-$(CONFIG_CM32181) += cm32181.o
+801
drivers/iio/light/as73211.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Support for AMS AS73211 JENCOLOR(R) Digital XYZ Sensor 4 + * 5 + * Author: Christian Eggers <ceggers@arri.de> 6 + * 7 + * Copyright (c) 2020 ARRI Lighting 8 + * 9 + * Color light sensor with 16-bit channels for x, y, z and temperature); 10 + * 7-bit I2C slave address 0x74 .. 0x77. 11 + * 12 + * Datasheet: https://ams.com/documents/20143/36005/AS73211_DS000556_3-01.pdf 13 + */ 14 + 15 + #include <linux/bitfield.h> 16 + #include <linux/completion.h> 17 + #include <linux/delay.h> 18 + #include <linux/i2c.h> 19 + #include <linux/iio/buffer.h> 20 + #include <linux/iio/iio.h> 21 + #include <linux/iio/sysfs.h> 22 + #include <linux/iio/trigger_consumer.h> 23 + #include <linux/iio/triggered_buffer.h> 24 + #include <linux/module.h> 25 + #include <linux/mutex.h> 26 + #include <linux/pm.h> 27 + 28 + #define HZ_PER_KHZ 1000 29 + 30 + #define AS73211_DRV_NAME "as73211" 31 + 32 + /* AS73211 configuration registers */ 33 + #define AS73211_REG_OSR 0x0 34 + #define AS73211_REG_AGEN 0x2 35 + #define AS73211_REG_CREG1 0x6 36 + #define AS73211_REG_CREG2 0x7 37 + #define AS73211_REG_CREG3 0x8 38 + 39 + /* AS73211 output register bank */ 40 + #define AS73211_OUT_OSR_STATUS 0 41 + #define AS73211_OUT_TEMP 1 42 + #define AS73211_OUT_MRES1 2 43 + #define AS73211_OUT_MRES2 3 44 + #define AS73211_OUT_MRES3 4 45 + 46 + #define AS73211_OSR_SS BIT(7) 47 + #define AS73211_OSR_PD BIT(6) 48 + #define AS73211_OSR_SW_RES BIT(3) 49 + #define AS73211_OSR_DOS_MASK GENMASK(2, 0) 50 + #define AS73211_OSR_DOS_CONFIG FIELD_PREP(AS73211_OSR_DOS_MASK, 0x2) 51 + #define AS73211_OSR_DOS_MEASURE FIELD_PREP(AS73211_OSR_DOS_MASK, 0x3) 52 + 53 + #define AS73211_AGEN_DEVID_MASK GENMASK(7, 4) 54 + #define AS73211_AGEN_DEVID(x) FIELD_PREP(AS73211_AGEN_DEVID_MASK, (x)) 55 + #define AS73211_AGEN_MUT_MASK GENMASK(3, 0) 56 + #define AS73211_AGEN_MUT(x) FIELD_PREP(AS73211_AGEN_MUT_MASK, (x)) 57 + 58 + #define AS73211_CREG1_GAIN_MASK GENMASK(7, 4) 59 + #define AS73211_CREG1_GAIN_1 11 60 + #define AS73211_CREG1_TIME_MASK GENMASK(3, 0) 61 + 62 + #define AS73211_CREG3_CCLK_MASK GENMASK(1, 0) 63 + 64 + #define AS73211_OSR_STATUS_OUTCONVOF BIT(15) 65 + #define AS73211_OSR_STATUS_MRESOF BIT(14) 66 + #define AS73211_OSR_STATUS_ADCOF BIT(13) 67 + #define AS73211_OSR_STATUS_LDATA BIT(12) 68 + #define AS73211_OSR_STATUS_NDATA BIT(11) 69 + #define AS73211_OSR_STATUS_NOTREADY BIT(10) 70 + 71 + #define AS73211_SAMPLE_FREQ_BASE 1024000 72 + 73 + #define AS73211_SAMPLE_TIME_NUM 15 74 + #define AS73211_SAMPLE_TIME_MAX_MS BIT(AS73211_SAMPLE_TIME_NUM - 1) 75 + 76 + /* Available sample frequencies are 1.024MHz multiplied by powers of two. */ 77 + static const int as73211_samp_freq_avail[] = { 78 + AS73211_SAMPLE_FREQ_BASE * 1, 79 + AS73211_SAMPLE_FREQ_BASE * 2, 80 + AS73211_SAMPLE_FREQ_BASE * 4, 81 + AS73211_SAMPLE_FREQ_BASE * 8, 82 + }; 83 + 84 + static const int as73211_hardwaregain_avail[] = { 85 + 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 86 + }; 87 + 88 + /** 89 + * struct as73211_data - Instance data for one AS73211 90 + * @client: I2C client. 91 + * @osr: Cached Operational State Register. 92 + * @creg1: Cached Configuration Register 1. 93 + * @creg2: Cached Configuration Register 2. 94 + * @creg3: Cached Configuration Register 3. 95 + * @mutex: Keeps cached registers in sync with the device. 96 + * @completion: Completion to wait for interrupt. 97 + * @int_time_avail: Available integration times (depend on sampling frequency). 98 + */ 99 + struct as73211_data { 100 + struct i2c_client *client; 101 + u8 osr; 102 + u8 creg1; 103 + u8 creg2; 104 + u8 creg3; 105 + struct mutex mutex; 106 + struct completion completion; 107 + int int_time_avail[AS73211_SAMPLE_TIME_NUM * 2]; 108 + }; 109 + 110 + #define AS73211_COLOR_CHANNEL(_color, _si, _addr) { \ 111 + .type = IIO_INTENSITY, \ 112 + .modified = 1, \ 113 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \ 114 + .info_mask_shared_by_type = \ 115 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ 116 + BIT(IIO_CHAN_INFO_HARDWAREGAIN) | \ 117 + BIT(IIO_CHAN_INFO_INT_TIME), \ 118 + .info_mask_shared_by_type_available = \ 119 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ 120 + BIT(IIO_CHAN_INFO_HARDWAREGAIN) | \ 121 + BIT(IIO_CHAN_INFO_INT_TIME), \ 122 + .channel2 = IIO_MOD_##_color, \ 123 + .address = _addr, \ 124 + .scan_index = _si, \ 125 + .scan_type = { \ 126 + .sign = 'u', \ 127 + .realbits = 16, \ 128 + .storagebits = 16, \ 129 + .endianness = IIO_LE, \ 130 + }, \ 131 + } 132 + 133 + #define AS73211_OFFSET_TEMP_INT (-66) 134 + #define AS73211_OFFSET_TEMP_MICRO 900000 135 + #define AS73211_SCALE_TEMP_INT 0 136 + #define AS73211_SCALE_TEMP_MICRO 50000 137 + 138 + #define AS73211_SCALE_X 277071108 /* nW/m^2 */ 139 + #define AS73211_SCALE_Y 298384270 /* nW/m^2 */ 140 + #define AS73211_SCALE_Z 160241927 /* nW/m^2 */ 141 + 142 + /* Channel order MUST match devices result register order */ 143 + #define AS73211_SCAN_INDEX_TEMP 0 144 + #define AS73211_SCAN_INDEX_X 1 145 + #define AS73211_SCAN_INDEX_Y 2 146 + #define AS73211_SCAN_INDEX_Z 3 147 + #define AS73211_SCAN_INDEX_TS 4 148 + 149 + #define AS73211_SCAN_MASK_COLOR ( \ 150 + BIT(AS73211_SCAN_INDEX_X) | \ 151 + BIT(AS73211_SCAN_INDEX_Y) | \ 152 + BIT(AS73211_SCAN_INDEX_Z)) 153 + 154 + #define AS73211_SCAN_MASK_ALL ( \ 155 + BIT(AS73211_SCAN_INDEX_TEMP) | \ 156 + AS73211_SCAN_MASK_COLOR) 157 + 158 + static const struct iio_chan_spec as73211_channels[] = { 159 + { 160 + .type = IIO_TEMP, 161 + .info_mask_separate = 162 + BIT(IIO_CHAN_INFO_RAW) | 163 + BIT(IIO_CHAN_INFO_OFFSET) | 164 + BIT(IIO_CHAN_INFO_SCALE), 165 + .address = AS73211_OUT_TEMP, 166 + .scan_index = AS73211_SCAN_INDEX_TEMP, 167 + .scan_type = { 168 + .sign = 'u', 169 + .realbits = 16, 170 + .storagebits = 16, 171 + .endianness = IIO_LE, 172 + } 173 + }, 174 + AS73211_COLOR_CHANNEL(X, AS73211_SCAN_INDEX_X, AS73211_OUT_MRES1), 175 + AS73211_COLOR_CHANNEL(Y, AS73211_SCAN_INDEX_Y, AS73211_OUT_MRES2), 176 + AS73211_COLOR_CHANNEL(Z, AS73211_SCAN_INDEX_Z, AS73211_OUT_MRES3), 177 + IIO_CHAN_SOFT_TIMESTAMP(AS73211_SCAN_INDEX_TS), 178 + }; 179 + 180 + static unsigned int as73211_integration_time_1024cyc(struct as73211_data *data) 181 + { 182 + /* 183 + * Return integration time in units of 1024 clock cycles. Integration time 184 + * in CREG1 is in powers of 2 (x 1024 cycles). 185 + */ 186 + return BIT(FIELD_GET(AS73211_CREG1_TIME_MASK, data->creg1)); 187 + } 188 + 189 + static unsigned int as73211_integration_time_us(struct as73211_data *data, 190 + unsigned int integration_time_1024cyc) 191 + { 192 + /* 193 + * f_samp is configured in CREG3 in powers of 2 (x 1.024 MHz) 194 + * t_cycl is configured in CREG1 in powers of 2 (x 1024 cycles) 195 + * t_int_us = 1 / (f_samp) * t_cycl * US_PER_SEC 196 + * = 1 / (2^CREG3_CCLK * 1,024,000) * 2^CREG1_CYCLES * 1,024 * US_PER_SEC 197 + * = 2^(-CREG3_CCLK) * 2^CREG1_CYCLES * 1,000 198 + * In order to get rid of negative exponents, we extend the "fraction" 199 + * by 2^3 (CREG3_CCLK,max = 3) 200 + * t_int_us = 2^(3-CREG3_CCLK) * 2^CREG1_CYCLES * 125 201 + */ 202 + return BIT(3 - FIELD_GET(AS73211_CREG3_CCLK_MASK, data->creg3)) * 203 + integration_time_1024cyc * 125; 204 + } 205 + 206 + static void as73211_integration_time_calc_avail(struct as73211_data *data) 207 + { 208 + int i; 209 + 210 + for (i = 0; i < ARRAY_SIZE(data->int_time_avail) / 2; i++) { 211 + unsigned int time_us = as73211_integration_time_us(data, BIT(i)); 212 + 213 + data->int_time_avail[i * 2 + 0] = time_us / USEC_PER_SEC; 214 + data->int_time_avail[i * 2 + 1] = time_us % USEC_PER_SEC; 215 + } 216 + } 217 + 218 + static unsigned int as73211_gain(struct as73211_data *data) 219 + { 220 + /* gain can be calculated from CREG1 as 2^(11 - CREG1_GAIN) */ 221 + return BIT(AS73211_CREG1_GAIN_1 - FIELD_GET(AS73211_CREG1_GAIN_MASK, data->creg1)); 222 + } 223 + 224 + /* must be called with as73211_data::mutex held. */ 225 + static int as73211_req_data(struct as73211_data *data) 226 + { 227 + unsigned int time_us = as73211_integration_time_us(data, 228 + as73211_integration_time_1024cyc(data)); 229 + struct device *dev = &data->client->dev; 230 + union i2c_smbus_data smbus_data; 231 + u16 osr_status; 232 + int ret; 233 + 234 + if (data->client->irq) 235 + reinit_completion(&data->completion); 236 + 237 + /* 238 + * During measurement, there should be no traffic on the i2c bus as the 239 + * electrical noise would disturb the measurement process. 240 + */ 241 + i2c_lock_bus(data->client->adapter, I2C_LOCK_SEGMENT); 242 + 243 + data->osr &= ~AS73211_OSR_DOS_MASK; 244 + data->osr |= AS73211_OSR_DOS_MEASURE | AS73211_OSR_SS; 245 + 246 + smbus_data.byte = data->osr; 247 + ret = __i2c_smbus_xfer(data->client->adapter, data->client->addr, 248 + data->client->flags, I2C_SMBUS_WRITE, 249 + AS73211_REG_OSR, I2C_SMBUS_BYTE_DATA, &smbus_data); 250 + if (ret < 0) { 251 + i2c_unlock_bus(data->client->adapter, I2C_LOCK_SEGMENT); 252 + return ret; 253 + } 254 + 255 + /* 256 + * Reset AS73211_OSR_SS (is self clearing) in order to avoid unintentional 257 + * triggering of further measurements later. 258 + */ 259 + data->osr &= ~AS73211_OSR_SS; 260 + 261 + /* 262 + * Add some extra margin for the timeout. sensor timing is not as precise 263 + * as our one ... 264 + */ 265 + time_us += time_us / 8; 266 + if (data->client->irq) { 267 + ret = wait_for_completion_timeout(&data->completion, usecs_to_jiffies(time_us)); 268 + if (!ret) { 269 + dev_err(dev, "timeout waiting for READY IRQ\n"); 270 + i2c_unlock_bus(data->client->adapter, I2C_LOCK_SEGMENT); 271 + return -ETIMEDOUT; 272 + } 273 + } else { 274 + /* Wait integration time */ 275 + usleep_range(time_us, 2 * time_us); 276 + } 277 + 278 + i2c_unlock_bus(data->client->adapter, I2C_LOCK_SEGMENT); 279 + 280 + ret = i2c_smbus_read_word_data(data->client, AS73211_OUT_OSR_STATUS); 281 + if (ret < 0) 282 + return ret; 283 + 284 + osr_status = ret; 285 + if (osr_status != (AS73211_OSR_DOS_MEASURE | AS73211_OSR_STATUS_NDATA)) { 286 + if (osr_status & AS73211_OSR_SS) { 287 + dev_err(dev, "%s() Measurement has not stopped\n", __func__); 288 + return -ETIME; 289 + } 290 + if (osr_status & AS73211_OSR_STATUS_NOTREADY) { 291 + dev_err(dev, "%s() Data is not ready\n", __func__); 292 + return -ENODATA; 293 + } 294 + if (!(osr_status & AS73211_OSR_STATUS_NDATA)) { 295 + dev_err(dev, "%s() No new data available\n", __func__); 296 + return -ENODATA; 297 + } 298 + if (osr_status & AS73211_OSR_STATUS_LDATA) { 299 + dev_err(dev, "%s() Result buffer overrun\n", __func__); 300 + return -ENOBUFS; 301 + } 302 + if (osr_status & AS73211_OSR_STATUS_ADCOF) { 303 + dev_err(dev, "%s() ADC overflow\n", __func__); 304 + return -EOVERFLOW; 305 + } 306 + if (osr_status & AS73211_OSR_STATUS_MRESOF) { 307 + dev_err(dev, "%s() Measurement result overflow\n", __func__); 308 + return -EOVERFLOW; 309 + } 310 + if (osr_status & AS73211_OSR_STATUS_OUTCONVOF) { 311 + dev_err(dev, "%s() Timer overflow\n", __func__); 312 + return -EOVERFLOW; 313 + } 314 + dev_err(dev, "%s() Unexpected status value\n", __func__); 315 + return -EIO; 316 + } 317 + 318 + return 0; 319 + } 320 + 321 + static int as73211_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, 322 + int *val, int *val2, long mask) 323 + { 324 + struct as73211_data *data = iio_priv(indio_dev); 325 + 326 + switch (mask) { 327 + case IIO_CHAN_INFO_RAW: { 328 + int ret; 329 + 330 + ret = iio_device_claim_direct_mode(indio_dev); 331 + if (ret < 0) 332 + return ret; 333 + 334 + ret = as73211_req_data(data); 335 + if (ret < 0) { 336 + iio_device_release_direct_mode(indio_dev); 337 + return ret; 338 + } 339 + 340 + ret = i2c_smbus_read_word_data(data->client, chan->address); 341 + iio_device_release_direct_mode(indio_dev); 342 + if (ret < 0) 343 + return ret; 344 + 345 + *val = ret; 346 + return IIO_VAL_INT; 347 + } 348 + case IIO_CHAN_INFO_OFFSET: 349 + *val = AS73211_OFFSET_TEMP_INT; 350 + *val2 = AS73211_OFFSET_TEMP_MICRO; 351 + return IIO_VAL_INT_PLUS_MICRO; 352 + 353 + case IIO_CHAN_INFO_SCALE: 354 + switch (chan->type) { 355 + case IIO_TEMP: 356 + *val = AS73211_SCALE_TEMP_INT; 357 + *val2 = AS73211_SCALE_TEMP_MICRO; 358 + return IIO_VAL_INT_PLUS_MICRO; 359 + 360 + case IIO_INTENSITY: { 361 + unsigned int scale; 362 + 363 + switch (chan->channel2) { 364 + case IIO_MOD_X: 365 + scale = AS73211_SCALE_X; 366 + break; 367 + case IIO_MOD_Y: 368 + scale = AS73211_SCALE_Y; 369 + break; 370 + case IIO_MOD_Z: 371 + scale = AS73211_SCALE_Z; 372 + break; 373 + default: 374 + return -EINVAL; 375 + } 376 + scale /= as73211_gain(data); 377 + scale /= as73211_integration_time_1024cyc(data); 378 + *val = scale; 379 + return IIO_VAL_INT; 380 + 381 + default: 382 + return -EINVAL; 383 + }} 384 + 385 + case IIO_CHAN_INFO_SAMP_FREQ: 386 + /* f_samp is configured in CREG3 in powers of 2 (x 1.024 MHz) */ 387 + *val = BIT(FIELD_GET(AS73211_CREG3_CCLK_MASK, data->creg3)) * 388 + AS73211_SAMPLE_FREQ_BASE; 389 + return IIO_VAL_INT; 390 + 391 + case IIO_CHAN_INFO_HARDWAREGAIN: 392 + *val = as73211_gain(data); 393 + return IIO_VAL_INT; 394 + 395 + case IIO_CHAN_INFO_INT_TIME: { 396 + unsigned int time_us; 397 + 398 + mutex_lock(&data->mutex); 399 + time_us = as73211_integration_time_us(data, as73211_integration_time_1024cyc(data)); 400 + mutex_unlock(&data->mutex); 401 + *val = time_us / USEC_PER_SEC; 402 + *val2 = time_us % USEC_PER_SEC; 403 + return IIO_VAL_INT_PLUS_MICRO; 404 + 405 + default: 406 + return -EINVAL; 407 + }} 408 + } 409 + 410 + static int as73211_read_avail(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, 411 + const int **vals, int *type, int *length, long mask) 412 + { 413 + struct as73211_data *data = iio_priv(indio_dev); 414 + 415 + switch (mask) { 416 + case IIO_CHAN_INFO_SAMP_FREQ: 417 + *length = ARRAY_SIZE(as73211_samp_freq_avail); 418 + *vals = as73211_samp_freq_avail; 419 + *type = IIO_VAL_INT; 420 + return IIO_AVAIL_LIST; 421 + 422 + case IIO_CHAN_INFO_HARDWAREGAIN: 423 + *length = ARRAY_SIZE(as73211_hardwaregain_avail); 424 + *vals = as73211_hardwaregain_avail; 425 + *type = IIO_VAL_INT; 426 + return IIO_AVAIL_LIST; 427 + 428 + case IIO_CHAN_INFO_INT_TIME: 429 + *length = ARRAY_SIZE(data->int_time_avail); 430 + *vals = data->int_time_avail; 431 + *type = IIO_VAL_INT_PLUS_MICRO; 432 + return IIO_AVAIL_LIST; 433 + 434 + default: 435 + return -EINVAL; 436 + } 437 + } 438 + 439 + static int _as73211_write_raw(struct iio_dev *indio_dev, 440 + struct iio_chan_spec const *chan __always_unused, 441 + int val, int val2, long mask) 442 + { 443 + struct as73211_data *data = iio_priv(indio_dev); 444 + int ret; 445 + 446 + switch (mask) { 447 + case IIO_CHAN_INFO_SAMP_FREQ: { 448 + int reg_bits, freq_kHz = val / HZ_PER_KHZ; /* 1024, 2048, ... */ 449 + 450 + /* val must be 1024 * 2^x */ 451 + if (val < 0 || (freq_kHz * HZ_PER_KHZ) != val || 452 + !is_power_of_2(freq_kHz) || val2) 453 + return -EINVAL; 454 + 455 + /* f_samp is configured in CREG3 in powers of 2 (x 1.024 MHz (=2^10)) */ 456 + reg_bits = ilog2(freq_kHz) - 10; 457 + if (!FIELD_FIT(AS73211_CREG3_CCLK_MASK, reg_bits)) 458 + return -EINVAL; 459 + 460 + data->creg3 &= ~AS73211_CREG3_CCLK_MASK; 461 + data->creg3 |= FIELD_PREP(AS73211_CREG3_CCLK_MASK, reg_bits); 462 + as73211_integration_time_calc_avail(data); 463 + 464 + ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_CREG3, data->creg3); 465 + if (ret < 0) 466 + return ret; 467 + 468 + return 0; 469 + } 470 + case IIO_CHAN_INFO_HARDWAREGAIN: { 471 + unsigned int reg_bits; 472 + 473 + if (val < 0 || !is_power_of_2(val) || val2) 474 + return -EINVAL; 475 + 476 + /* gain can be calculated from CREG1 as 2^(11 - CREG1_GAIN) */ 477 + reg_bits = AS73211_CREG1_GAIN_1 - ilog2(val); 478 + if (!FIELD_FIT(AS73211_CREG1_GAIN_MASK, reg_bits)) 479 + return -EINVAL; 480 + 481 + data->creg1 &= ~AS73211_CREG1_GAIN_MASK; 482 + data->creg1 |= FIELD_PREP(AS73211_CREG1_GAIN_MASK, reg_bits); 483 + 484 + ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_CREG1, data->creg1); 485 + if (ret < 0) 486 + return ret; 487 + 488 + return 0; 489 + } 490 + case IIO_CHAN_INFO_INT_TIME: { 491 + int val_us = val * USEC_PER_SEC + val2; 492 + int time_ms; 493 + int reg_bits; 494 + 495 + /* f_samp is configured in CREG3 in powers of 2 (x 1.024 MHz) */ 496 + int f_samp_1_024mhz = BIT(FIELD_GET(AS73211_CREG3_CCLK_MASK, data->creg3)); 497 + 498 + /* 499 + * time_ms = time_us * US_PER_MS * f_samp_1_024mhz / MHZ_PER_HZ 500 + * = time_us * f_samp_1_024mhz / 1000 501 + */ 502 + time_ms = (val_us * f_samp_1_024mhz) / 1000; /* 1 ms, 2 ms, ... (power of two) */ 503 + if (time_ms < 0 || !is_power_of_2(time_ms) || time_ms > AS73211_SAMPLE_TIME_MAX_MS) 504 + return -EINVAL; 505 + 506 + reg_bits = ilog2(time_ms); 507 + if (!FIELD_FIT(AS73211_CREG1_TIME_MASK, reg_bits)) 508 + return -EINVAL; /* not possible due to previous tests */ 509 + 510 + data->creg1 &= ~AS73211_CREG1_TIME_MASK; 511 + data->creg1 |= FIELD_PREP(AS73211_CREG1_TIME_MASK, reg_bits); 512 + 513 + ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_CREG1, data->creg1); 514 + if (ret < 0) 515 + return ret; 516 + 517 + return 0; 518 + 519 + default: 520 + return -EINVAL; 521 + }} 522 + } 523 + 524 + static int as73211_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, 525 + int val, int val2, long mask) 526 + { 527 + struct as73211_data *data = iio_priv(indio_dev); 528 + int ret; 529 + 530 + mutex_lock(&data->mutex); 531 + 532 + ret = iio_device_claim_direct_mode(indio_dev); 533 + if (ret < 0) 534 + goto error_unlock; 535 + 536 + /* Need to switch to config mode ... */ 537 + if ((data->osr & AS73211_OSR_DOS_MASK) != AS73211_OSR_DOS_CONFIG) { 538 + data->osr &= ~AS73211_OSR_DOS_MASK; 539 + data->osr |= AS73211_OSR_DOS_CONFIG; 540 + 541 + ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_OSR, data->osr); 542 + if (ret < 0) 543 + goto error_release; 544 + } 545 + 546 + ret = _as73211_write_raw(indio_dev, chan, val, val2, mask); 547 + 548 + error_release: 549 + iio_device_release_direct_mode(indio_dev); 550 + error_unlock: 551 + mutex_unlock(&data->mutex); 552 + return ret; 553 + } 554 + 555 + static irqreturn_t as73211_ready_handler(int irq __always_unused, void *priv) 556 + { 557 + struct as73211_data *data = iio_priv(priv); 558 + 559 + complete(&data->completion); 560 + 561 + return IRQ_HANDLED; 562 + } 563 + 564 + static irqreturn_t as73211_trigger_handler(int irq __always_unused, void *p) 565 + { 566 + struct iio_poll_func *pf = p; 567 + struct iio_dev *indio_dev = pf->indio_dev; 568 + struct as73211_data *data = iio_priv(indio_dev); 569 + struct { 570 + __le16 chan[4]; 571 + s64 ts __aligned(8); 572 + } scan; 573 + int data_result, ret; 574 + 575 + mutex_lock(&data->mutex); 576 + 577 + data_result = as73211_req_data(data); 578 + if (data_result < 0 && data_result != -EOVERFLOW) 579 + goto done; /* don't push any data for errors other than EOVERFLOW */ 580 + 581 + if (*indio_dev->active_scan_mask == AS73211_SCAN_MASK_ALL) { 582 + /* Optimization for reading all (color + temperature) channels */ 583 + u8 addr = as73211_channels[0].address; 584 + struct i2c_msg msgs[] = { 585 + { 586 + .addr = data->client->addr, 587 + .flags = 0, 588 + .len = 1, 589 + .buf = &addr, 590 + }, 591 + { 592 + .addr = data->client->addr, 593 + .flags = I2C_M_RD, 594 + .len = sizeof(scan.chan), 595 + .buf = (u8 *)&scan.chan, 596 + }, 597 + }; 598 + 599 + ret = i2c_transfer(data->client->adapter, msgs, ARRAY_SIZE(msgs)); 600 + if (ret < 0) 601 + goto done; 602 + } else { 603 + /* Optimization for reading only color channels */ 604 + 605 + /* AS73211 starts reading at address 2 */ 606 + ret = i2c_master_recv(data->client, 607 + (char *)&scan.chan[1], 3 * sizeof(scan.chan[1])); 608 + if (ret < 0) 609 + goto done; 610 + } 611 + 612 + if (data_result) { 613 + /* 614 + * Saturate all channels (in case of overflows). Temperature channel 615 + * is not affected by overflows. 616 + */ 617 + scan.chan[1] = cpu_to_le16(U16_MAX); 618 + scan.chan[2] = cpu_to_le16(U16_MAX); 619 + scan.chan[3] = cpu_to_le16(U16_MAX); 620 + } 621 + 622 + iio_push_to_buffers_with_timestamp(indio_dev, &scan, iio_get_time_ns(indio_dev)); 623 + 624 + done: 625 + mutex_unlock(&data->mutex); 626 + iio_trigger_notify_done(indio_dev->trig); 627 + 628 + return IRQ_HANDLED; 629 + } 630 + 631 + static const struct iio_info as73211_info = { 632 + .read_raw = as73211_read_raw, 633 + .read_avail = as73211_read_avail, 634 + .write_raw = as73211_write_raw, 635 + }; 636 + 637 + static int as73211_power(struct iio_dev *indio_dev, bool state) 638 + { 639 + struct as73211_data *data = iio_priv(indio_dev); 640 + int ret; 641 + 642 + mutex_lock(&data->mutex); 643 + 644 + if (state) 645 + data->osr &= ~AS73211_OSR_PD; 646 + else 647 + data->osr |= AS73211_OSR_PD; 648 + 649 + ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_OSR, data->osr); 650 + 651 + mutex_unlock(&data->mutex); 652 + 653 + if (ret < 0) 654 + return ret; 655 + 656 + return 0; 657 + } 658 + 659 + static void as73211_power_disable(void *data) 660 + { 661 + struct iio_dev *indio_dev = data; 662 + 663 + as73211_power(indio_dev, false); 664 + } 665 + 666 + static int as73211_probe(struct i2c_client *client) 667 + { 668 + struct device *dev = &client->dev; 669 + struct as73211_data *data; 670 + struct iio_dev *indio_dev; 671 + int ret; 672 + 673 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 674 + if (!indio_dev) 675 + return -ENOMEM; 676 + 677 + data = iio_priv(indio_dev); 678 + i2c_set_clientdata(client, indio_dev); 679 + data->client = client; 680 + 681 + mutex_init(&data->mutex); 682 + init_completion(&data->completion); 683 + 684 + indio_dev->info = &as73211_info; 685 + indio_dev->name = AS73211_DRV_NAME; 686 + indio_dev->channels = as73211_channels; 687 + indio_dev->num_channels = ARRAY_SIZE(as73211_channels); 688 + indio_dev->modes = INDIO_DIRECT_MODE; 689 + 690 + ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_OSR); 691 + if (ret < 0) 692 + return ret; 693 + data->osr = ret; 694 + 695 + /* reset device */ 696 + data->osr |= AS73211_OSR_SW_RES; 697 + ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_OSR, data->osr); 698 + if (ret < 0) 699 + return ret; 700 + 701 + ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_OSR); 702 + if (ret < 0) 703 + return ret; 704 + data->osr = ret; 705 + 706 + /* 707 + * Reading AGEN is only possible after reset (AGEN is not available if 708 + * device is in measurement mode). 709 + */ 710 + ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_AGEN); 711 + if (ret < 0) 712 + return ret; 713 + 714 + /* At the time of writing this driver, only DEVID 2 and MUT 1 are known. */ 715 + if ((ret & AS73211_AGEN_DEVID_MASK) != AS73211_AGEN_DEVID(2) || 716 + (ret & AS73211_AGEN_MUT_MASK) != AS73211_AGEN_MUT(1)) 717 + return -ENODEV; 718 + 719 + ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_CREG1); 720 + if (ret < 0) 721 + return ret; 722 + data->creg1 = ret; 723 + 724 + ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_CREG2); 725 + if (ret < 0) 726 + return ret; 727 + data->creg2 = ret; 728 + 729 + ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_CREG3); 730 + if (ret < 0) 731 + return ret; 732 + data->creg3 = ret; 733 + as73211_integration_time_calc_avail(data); 734 + 735 + ret = as73211_power(indio_dev, true); 736 + if (ret < 0) 737 + return ret; 738 + 739 + ret = devm_add_action_or_reset(dev, as73211_power_disable, indio_dev); 740 + if (ret) 741 + return ret; 742 + 743 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, as73211_trigger_handler, NULL); 744 + if (ret) 745 + return ret; 746 + 747 + if (client->irq) { 748 + ret = devm_request_threaded_irq(&client->dev, client->irq, 749 + NULL, 750 + as73211_ready_handler, 751 + IRQF_ONESHOT, 752 + client->name, indio_dev); 753 + if (ret) 754 + return ret; 755 + } 756 + 757 + return devm_iio_device_register(dev, indio_dev); 758 + } 759 + 760 + static int __maybe_unused as73211_suspend(struct device *dev) 761 + { 762 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 763 + 764 + return as73211_power(indio_dev, false); 765 + } 766 + 767 + static int __maybe_unused as73211_resume(struct device *dev) 768 + { 769 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 770 + 771 + return as73211_power(indio_dev, true); 772 + } 773 + 774 + static SIMPLE_DEV_PM_OPS(as73211_pm_ops, as73211_suspend, as73211_resume); 775 + 776 + static const struct of_device_id as73211_of_match[] = { 777 + { .compatible = "ams,as73211" }, 778 + { } 779 + }; 780 + MODULE_DEVICE_TABLE(of, as73211_of_match); 781 + 782 + static const struct i2c_device_id as73211_id[] = { 783 + { "as73211", 0 }, 784 + { } 785 + }; 786 + MODULE_DEVICE_TABLE(i2c, as73211_id); 787 + 788 + static struct i2c_driver as73211_driver = { 789 + .driver = { 790 + .name = AS73211_DRV_NAME, 791 + .of_match_table = as73211_of_match, 792 + .pm = &as73211_pm_ops, 793 + }, 794 + .probe_new = as73211_probe, 795 + .id_table = as73211_id, 796 + }; 797 + module_i2c_driver(as73211_driver); 798 + 799 + MODULE_AUTHOR("Christian Eggers <ceggers@arri.de>"); 800 + MODULE_DESCRIPTION("AS73211 XYZ True Color Sensor driver"); 801 + MODULE_LICENSE("GPL");
+3 -6
drivers/iio/light/isl29018.c
··· 746 746 chip->suspended = false; 747 747 748 748 chip->vcc_reg = devm_regulator_get(&client->dev, "vcc"); 749 - if (IS_ERR(chip->vcc_reg)) { 750 - err = PTR_ERR(chip->vcc_reg); 751 - if (err != -EPROBE_DEFER) 752 - dev_err(&client->dev, "failed to get VCC regulator!\n"); 753 - return err; 754 - } 749 + if (IS_ERR(chip->vcc_reg)) 750 + return dev_err_probe(&client->dev, PTR_ERR(chip->vcc_reg), 751 + "failed to get VCC regulator!\n"); 755 752 756 753 err = regulator_enable(chip->vcc_reg); 757 754 if (err) {
+2 -8
drivers/iio/light/tsl2772.c
··· 1776 1776 ret = devm_regulator_bulk_get(&clientp->dev, 1777 1777 ARRAY_SIZE(chip->supplies), 1778 1778 chip->supplies); 1779 - if (ret < 0) { 1780 - if (ret != -EPROBE_DEFER) 1781 - dev_err(&clientp->dev, 1782 - "Failed to get regulators: %d\n", 1783 - ret); 1784 - 1785 - return ret; 1786 - } 1779 + if (ret < 0) 1780 + return dev_err_probe(&clientp->dev, ret, "Failed to get regulators\n"); 1787 1781 1788 1782 ret = regulator_bulk_enable(ARRAY_SIZE(chip->supplies), chip->supplies); 1789 1783 if (ret < 0) {
+2 -9
drivers/iio/magnetometer/ak8974.c
··· 843 843 ret = devm_regulator_bulk_get(&i2c->dev, 844 844 ARRAY_SIZE(ak8974->regs), 845 845 ak8974->regs); 846 - if (ret < 0) { 847 - if (ret != -EPROBE_DEFER) 848 - dev_err(&i2c->dev, "cannot get regulators: %d\n", ret); 849 - else 850 - dev_dbg(&i2c->dev, 851 - "regulators unavailable, deferring probe\n"); 852 - 853 - return ret; 854 - } 846 + if (ret < 0) 847 + return dev_err_probe(&i2c->dev, ret, "cannot get regulators\n"); 855 848 856 849 ret = regulator_bulk_enable(ARRAY_SIZE(ak8974->regs), ak8974->regs); 857 850 if (ret < 0) {
+6 -14
drivers/iio/magnetometer/mag3110.c
··· 476 476 data = iio_priv(indio_dev); 477 477 478 478 data->vdd_reg = devm_regulator_get(&client->dev, "vdd"); 479 - if (IS_ERR(data->vdd_reg)) { 480 - if (PTR_ERR(data->vdd_reg) == -EPROBE_DEFER) 481 - return -EPROBE_DEFER; 482 - 483 - dev_err(&client->dev, "failed to get VDD regulator!\n"); 484 - return PTR_ERR(data->vdd_reg); 485 - } 479 + if (IS_ERR(data->vdd_reg)) 480 + return dev_err_probe(&client->dev, PTR_ERR(data->vdd_reg), 481 + "failed to get VDD regulator!\n"); 486 482 487 483 data->vddio_reg = devm_regulator_get(&client->dev, "vddio"); 488 - if (IS_ERR(data->vddio_reg)) { 489 - if (PTR_ERR(data->vddio_reg) == -EPROBE_DEFER) 490 - return -EPROBE_DEFER; 491 - 492 - dev_err(&client->dev, "failed to get VDDIO regulator!\n"); 493 - return PTR_ERR(data->vddio_reg); 494 - } 484 + if (IS_ERR(data->vddio_reg)) 485 + return dev_err_probe(&client->dev, PTR_ERR(data->vddio_reg), 486 + "failed to get VDDIO regulator!\n"); 495 487 496 488 ret = regulator_enable(data->vdd_reg); 497 489 if (ret) {
+3 -5
drivers/iio/multiplexer/iio-mux.c
··· 354 354 return -ENODEV; 355 355 356 356 parent = devm_iio_channel_get(dev, "parent"); 357 - if (IS_ERR(parent)) { 358 - if (PTR_ERR(parent) != -EPROBE_DEFER) 359 - dev_err(dev, "failed to get parent channel\n"); 360 - return PTR_ERR(parent); 361 - } 357 + if (IS_ERR(parent)) 358 + return dev_err_probe(dev, PTR_ERR(parent), 359 + "failed to get parent channel\n"); 362 360 363 361 sizeof_ext_info = iio_get_channel_ext_info_count(parent); 364 362 if (sizeof_ext_info) {
+210 -208
drivers/iio/proximity/sx9310.c
··· 6 6 * Based on SX9500 driver and Semtech driver using the input framework 7 7 * <https://my.syncplicity.com/share/teouwsim8niiaud/ 8 8 * linux-driver-SX9310_NoSmartHSensing>. 9 - * Reworked April 2019 by Evan Green <evgreen@chromium.org> 10 - * and January 2020 by Daniel Campello <campello@chromium.org> 9 + * Reworked in April 2019 by Evan Green <evgreen@chromium.org> 10 + * and in January 2020 by Daniel Campello <campello@chromium.org>. 11 11 */ 12 12 13 13 #include <linux/acpi.h> 14 + #include <linux/bitfield.h> 14 15 #include <linux/delay.h> 15 16 #include <linux/i2c.h> 16 17 #include <linux/irq.h> 17 18 #include <linux/kernel.h> 19 + #include <linux/mod_devicetable.h> 18 20 #include <linux/module.h> 19 - #include <linux/of.h> 20 21 #include <linux/pm.h> 21 22 #include <linux/regmap.h> 23 + #include <linux/regulator/consumer.h> 22 24 #include <linux/slab.h> 23 25 24 26 #include <linux/iio/buffer.h> ··· 35 33 #define SX9310_REG_IRQ_SRC 0x00 36 34 #define SX9310_REG_STAT0 0x01 37 35 #define SX9310_REG_STAT1 0x02 36 + #define SX9310_REG_STAT1_COMPSTAT_MASK GENMASK(3, 0) 38 37 #define SX9310_REG_IRQ_MSK 0x03 39 38 #define SX9310_CONVDONE_IRQ BIT(3) 40 39 #define SX9310_FAR_IRQ BIT(5) 41 40 #define SX9310_CLOSE_IRQ BIT(6) 42 - #define SX9310_EVENT_IRQ (SX9310_FAR_IRQ | \ 43 - SX9310_CLOSE_IRQ) 44 41 #define SX9310_REG_IRQ_FUNC 0x04 45 42 46 43 #define SX9310_REG_PROX_CTRL0 0x10 47 - #define SX9310_REG_PROX_CTRL0_PROXSTAT2 0x10 48 - #define SX9310_REG_PROX_CTRL0_EN_MASK 0x0F 44 + #define SX9310_REG_PROX_CTRL0_SENSOREN_MASK GENMASK(3, 0) 45 + #define SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK GENMASK(7, 4) 46 + #define SX9310_REG_PROX_CTRL0_SCANPERIOD_15MS 0x01 49 47 #define SX9310_REG_PROX_CTRL1 0x11 50 48 #define SX9310_REG_PROX_CTRL2 0x12 51 - #define SX9310_REG_PROX_CTRL2_COMBMODE_ALL 0x80 52 - #define SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC 0x04 49 + #define SX9310_REG_PROX_CTRL2_COMBMODE_CS1_CS2 (0x02 << 6) 50 + #define SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC (0x01 << 2) 53 51 #define SX9310_REG_PROX_CTRL3 0x13 54 - #define SX9310_REG_PROX_CTRL3_GAIN0_X8 0x0c 52 + #define SX9310_REG_PROX_CTRL3_GAIN0_X8 (0x03 << 2) 55 53 #define SX9310_REG_PROX_CTRL3_GAIN12_X4 0x02 56 54 #define SX9310_REG_PROX_CTRL4 0x14 57 55 #define SX9310_REG_PROX_CTRL4_RESOLUTION_FINEST 0x07 58 56 #define SX9310_REG_PROX_CTRL5 0x15 59 - #define SX9310_REG_PROX_CTRL5_RANGE_SMALL 0xc0 60 - #define SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1 0x04 57 + #define SX9310_REG_PROX_CTRL5_RANGE_SMALL (0x03 << 6) 58 + #define SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1 (0x01 << 2) 61 59 #define SX9310_REG_PROX_CTRL5_RAWFILT_1P25 0x02 62 60 #define SX9310_REG_PROX_CTRL6 0x16 63 - #define SX9310_REG_PROX_CTRL6_COMP_COMMON 0x20 61 + #define SX9310_REG_PROX_CTRL6_AVGTHRESH_DEFAULT 0x20 64 62 #define SX9310_REG_PROX_CTRL7 0x17 65 - #define SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 0x08 63 + #define SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 (0x01 << 3) 66 64 #define SX9310_REG_PROX_CTRL7_AVGPOSFILT_512 0x05 67 65 #define SX9310_REG_PROX_CTRL8 0x18 68 66 #define SX9310_REG_PROX_CTRL9 0x19 69 - #define SX9310_REG_PROX_CTRL8_9_PTHRESH12_28 0x40 70 - #define SX9310_REG_PROX_CTRL8_9_PTHRESH_96 0x88 67 + #define SX9310_REG_PROX_CTRL8_9_PTHRESH_28 (0x08 << 3) 68 + #define SX9310_REG_PROX_CTRL8_9_PTHRESH_96 (0x11 << 3) 71 69 #define SX9310_REG_PROX_CTRL8_9_BODYTHRESH_900 0x03 72 70 #define SX9310_REG_PROX_CTRL8_9_BODYTHRESH_1500 0x05 73 71 #define SX9310_REG_PROX_CTRL10 0x1a 74 - #define SX9310_REG_PROX_CTRL10_HYST_6PCT 0x10 75 - #define SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_8 0x12 76 - #define SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_8 0x03 72 + #define SX9310_REG_PROX_CTRL10_HYST_6PCT (0x01 << 4) 73 + #define SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_2 0x01 77 74 #define SX9310_REG_PROX_CTRL11 0x1b 78 75 #define SX9310_REG_PROX_CTRL12 0x1c 79 76 #define SX9310_REG_PROX_CTRL13 0x1d ··· 83 82 #define SX9310_REG_PROX_CTRL18 0x22 84 83 #define SX9310_REG_PROX_CTRL19 0x23 85 84 #define SX9310_REG_SAR_CTRL0 0x2a 86 - #define SX9310_REG_SAR_CTRL0_SARDEB_4_SAMPLES 0x40 87 - #define SX9310_REG_SAR_CTRL0_SARHYST_8 0x10 85 + #define SX9310_REG_SAR_CTRL0_SARDEB_4_SAMPLES (0x02 << 5) 86 + #define SX9310_REG_SAR_CTRL0_SARHYST_8 (0x02 << 3) 88 87 #define SX9310_REG_SAR_CTRL1 0x2b 89 88 /* Each increment of the slope register is 0.0078125. */ 90 89 #define SX9310_REG_SAR_CTRL1_SLOPE(_hnslope) (_hnslope / 78125) ··· 92 91 #define SX9310_REG_SAR_CTRL2_SAROFFSET_DEFAULT 0x3c 93 92 94 93 #define SX9310_REG_SENSOR_SEL 0x30 95 - 96 94 #define SX9310_REG_USE_MSB 0x31 97 95 #define SX9310_REG_USE_LSB 0x32 98 - 99 96 #define SX9310_REG_AVG_MSB 0x33 100 97 #define SX9310_REG_AVG_LSB 0x34 101 - 102 98 #define SX9310_REG_DIFF_MSB 0x35 103 99 #define SX9310_REG_DIFF_LSB 0x36 104 - 105 100 #define SX9310_REG_OFFSET_MSB 0x37 106 101 #define SX9310_REG_OFFSET_LSB 0x38 107 - 108 102 #define SX9310_REG_SAR_MSB 0x39 109 103 #define SX9310_REG_SAR_LSB 0x3a 110 - 111 - #define SX9310_REG_I2CADDR 0x40 104 + #define SX9310_REG_I2C_ADDR 0x40 112 105 #define SX9310_REG_PAUSE 0x41 113 106 #define SX9310_REG_WHOAMI 0x42 114 107 #define SX9310_WHOAMI_VALUE 0x01 115 108 #define SX9311_WHOAMI_VALUE 0x02 116 - 117 109 #define SX9310_REG_RESET 0x7f 118 110 #define SX9310_SOFT_RESET 0xde 119 111 120 - #define SX9310_SCAN_PERIOD_MASK GENMASK(7, 4) 121 - #define SX9310_SCAN_PERIOD_SHIFT 4 122 - 123 - #define SX9310_COMPSTAT_MASK GENMASK(3, 0) 124 112 125 113 /* 4 hardware channels, as defined in STAT0: COMB, CS2, CS1 and CS0. */ 126 114 #define SX9310_NUM_CHANNELS 4 127 - #define SX9310_CHAN_ENABLED_MASK GENMASK(3, 0) 115 + static_assert(SX9310_NUM_CHANNELS < BITS_PER_LONG); 128 116 129 117 struct sx9310_data { 130 118 /* Serialize access to registers and channel configuration */ ··· 121 131 struct i2c_client *client; 122 132 struct iio_trigger *trig; 123 133 struct regmap *regmap; 134 + struct regulator_bulk_data supplies[2]; 124 135 /* 125 136 * Last reading of the proximity status for each channel. 126 137 * We only send an event to user space when this changes. 127 138 */ 128 - bool prox_stat[SX9310_NUM_CHANNELS]; 139 + unsigned long chan_prox_stat; 129 140 bool trigger_enabled; 130 - __be16 buffer[SX9310_NUM_CHANNELS + 131 - 4]; /* 64-bit data + 64-bit timestamp */ 141 + /* Ensure correct alignment of timestamp when present. */ 142 + struct { 143 + __be16 channels[SX9310_NUM_CHANNELS]; 144 + s64 ts __aligned(8); 145 + } buffer; 132 146 /* Remember enabled channels and sample rate during suspend. */ 133 147 unsigned int suspend_ctrl0; 134 148 struct completion completion; 135 - unsigned int chan_read, chan_event; 136 - int channel_users[SX9310_NUM_CHANNELS]; 137 - int whoami; 149 + unsigned long chan_read; 150 + unsigned long chan_event; 151 + unsigned int whoami; 138 152 }; 139 153 140 154 static const struct iio_event_spec sx9310_events[] = { ··· 245 251 regmap_reg_range(SX9310_REG_PROX_CTRL0, SX9310_REG_PROX_CTRL19), 246 252 regmap_reg_range(SX9310_REG_SAR_CTRL0, SX9310_REG_SAR_CTRL2), 247 253 regmap_reg_range(SX9310_REG_SENSOR_SEL, SX9310_REG_SAR_LSB), 248 - regmap_reg_range(SX9310_REG_I2CADDR, SX9310_REG_WHOAMI), 254 + regmap_reg_range(SX9310_REG_I2C_ADDR, SX9310_REG_WHOAMI), 249 255 regmap_reg_range(SX9310_REG_RESET, SX9310_REG_RESET), 250 256 }; 251 257 ··· 279 285 }; 280 286 281 287 static int sx9310_update_chan_en(struct sx9310_data *data, 282 - unsigned int chan_read, 283 - unsigned int chan_event) 288 + unsigned long chan_read, 289 + unsigned long chan_event) 284 290 { 285 291 int ret; 292 + unsigned long channels = chan_read | chan_event; 286 293 287 - if ((data->chan_read | data->chan_event) != (chan_read | chan_event)) { 294 + if ((data->chan_read | data->chan_event) != channels) { 288 295 ret = regmap_update_bits(data->regmap, SX9310_REG_PROX_CTRL0, 289 - SX9310_CHAN_ENABLED_MASK, 290 - chan_read | chan_event); 296 + SX9310_REG_PROX_CTRL0_SENSOREN_MASK, 297 + channels); 291 298 if (ret) 292 299 return ret; 293 300 } ··· 323 328 324 329 static int sx9310_enable_irq(struct sx9310_data *data, unsigned int irq) 325 330 { 331 + if (!data->client->irq) 332 + return 0; 326 333 return regmap_update_bits(data->regmap, SX9310_REG_IRQ_MSK, irq, irq); 327 334 } 328 335 329 336 static int sx9310_disable_irq(struct sx9310_data *data, unsigned int irq) 330 337 { 338 + if (!data->client->irq) 339 + return 0; 331 340 return regmap_update_bits(data->regmap, SX9310_REG_IRQ_MSK, irq, 0); 332 341 } 333 342 ··· 341 342 int ret; 342 343 343 344 ret = regmap_write(data->regmap, SX9310_REG_SENSOR_SEL, chan->channel); 344 - if (ret < 0) 345 + if (ret) 345 346 return ret; 346 347 347 - return regmap_bulk_read(data->regmap, chan->address, val, 2); 348 + return regmap_bulk_read(data->regmap, chan->address, val, sizeof(*val)); 348 349 } 349 350 350 351 /* ··· 357 358 unsigned int val; 358 359 359 360 ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, &val); 360 - if (ret < 0) 361 + if (ret) 361 362 return ret; 362 363 363 - val = (val & SX9310_SCAN_PERIOD_MASK) >> SX9310_SCAN_PERIOD_SHIFT; 364 + val = FIELD_GET(SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK, val); 364 365 365 366 msleep(sx9310_scan_period_table[val]); 366 367 ··· 370 371 static int sx9310_read_proximity(struct sx9310_data *data, 371 372 const struct iio_chan_spec *chan, int *val) 372 373 { 373 - int ret = 0; 374 + int ret; 374 375 __be16 rawval; 375 376 376 377 mutex_lock(&data->mutex); 377 378 378 379 ret = sx9310_get_read_channel(data, chan->channel); 379 - if (ret < 0) 380 + if (ret) 380 381 goto out; 381 382 382 383 ret = sx9310_enable_irq(data, SX9310_CONVDONE_IRQ); 383 - if (ret < 0) 384 + if (ret) 384 385 goto out_put_channel; 385 386 386 387 mutex_unlock(&data->mutex); 387 388 388 - if (data->client->irq > 0) { 389 + if (data->client->irq) { 389 390 ret = wait_for_completion_interruptible(&data->completion); 390 391 reinit_completion(&data->completion); 391 392 } else { ··· 394 395 395 396 mutex_lock(&data->mutex); 396 397 397 - if (ret < 0) 398 + if (ret) 398 399 goto out_disable_irq; 399 400 400 401 ret = sx9310_read_prox_data(data, chan, &rawval); 401 - if (ret < 0) 402 + if (ret) 402 403 goto out_disable_irq; 403 404 404 405 *val = sign_extend32(be16_to_cpu(rawval), 405 - (chan->address == SX9310_REG_DIFF_MSB ? 11 : 15)); 406 + chan->address == SX9310_REG_DIFF_MSB ? 11 : 15); 406 407 407 408 ret = sx9310_disable_irq(data, SX9310_CONVDONE_IRQ); 408 - if (ret < 0) 409 + if (ret) 409 410 goto out_put_channel; 410 411 411 412 ret = sx9310_put_read_channel(data, chan->channel); 412 - if (ret < 0) 413 + if (ret) 413 414 goto out; 414 415 415 416 mutex_unlock(&data->mutex); ··· 429 430 static int sx9310_read_samp_freq(struct sx9310_data *data, int *val, int *val2) 430 431 { 431 432 unsigned int regval; 432 - int ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, &regval); 433 + int ret; 433 434 434 - if (ret < 0) 435 + ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, &regval); 436 + if (ret) 435 437 return ret; 436 438 437 - regval = (regval & SX9310_SCAN_PERIOD_MASK) >> SX9310_SCAN_PERIOD_SHIFT; 439 + regval = FIELD_GET(SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK, regval); 438 440 *val = sx9310_samp_freq_table[regval].val; 439 441 *val2 = sx9310_samp_freq_table[regval].val2; 440 442 ··· 482 482 483 483 mutex_lock(&data->mutex); 484 484 485 - ret = regmap_update_bits(data->regmap, SX9310_REG_PROX_CTRL0, 486 - SX9310_SCAN_PERIOD_MASK, 487 - i << SX9310_SCAN_PERIOD_SHIFT); 485 + ret = regmap_update_bits( 486 + data->regmap, SX9310_REG_PROX_CTRL0, 487 + SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK, 488 + FIELD_PREP(SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK, i)); 488 489 489 490 mutex_unlock(&data->mutex); 490 491 ··· 516 515 iio_trigger_poll(data->trig); 517 516 518 517 /* 519 - * Even if no event is enabled, we need to wake the thread to 520 - * clear the interrupt state by reading SX9310_REG_IRQ_SRC. It 521 - * is not possible to do that here because regmap_read takes a 522 - * mutex. 518 + * Even if no event is enabled, we need to wake the thread to clear the 519 + * interrupt state by reading SX9310_REG_IRQ_SRC. 520 + * It is not possible to do that here because regmap_read takes a mutex. 523 521 */ 524 522 return IRQ_WAKE_THREAD; 525 523 } ··· 529 529 unsigned int val, chan; 530 530 struct sx9310_data *data = iio_priv(indio_dev); 531 531 s64 timestamp = iio_get_time_ns(indio_dev); 532 + unsigned long prox_changed; 532 533 533 534 /* Read proximity state on all channels */ 534 535 ret = regmap_read(data->regmap, SX9310_REG_STAT0, &val); 535 - if (ret < 0) { 536 + if (ret) { 536 537 dev_err(&data->client->dev, "i2c transfer error in irq\n"); 537 538 return; 538 539 } 539 540 540 - for (chan = 0; chan < SX9310_NUM_CHANNELS; chan++) { 541 + /* 542 + * Only iterate over channels with changes on proximity status that have 543 + * events enabled. 544 + */ 545 + prox_changed = (data->chan_prox_stat ^ val) & data->chan_event; 546 + 547 + for_each_set_bit(chan, &prox_changed, SX9310_NUM_CHANNELS) { 541 548 int dir; 542 549 u64 ev; 543 - bool new_prox = val & BIT(chan); 544 550 545 - if (!(data->chan_event & BIT(chan))) 546 - continue; 547 - if (new_prox == data->prox_stat[chan]) 548 - /* No change on this channel. */ 549 - continue; 550 - 551 - dir = new_prox ? IIO_EV_DIR_FALLING : IIO_EV_DIR_RISING; 551 + dir = (val & BIT(chan)) ? IIO_EV_DIR_FALLING : IIO_EV_DIR_RISING; 552 552 ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, chan, 553 553 IIO_EV_TYPE_THRESH, dir); 554 554 555 555 iio_push_event(indio_dev, ev, timestamp); 556 - data->prox_stat[chan] = new_prox; 557 556 } 557 + data->chan_prox_stat = val; 558 558 } 559 559 560 560 static irqreturn_t sx9310_irq_thread_handler(int irq, void *private) ··· 567 567 mutex_lock(&data->mutex); 568 568 569 569 ret = regmap_read(data->regmap, SX9310_REG_IRQ_SRC, &val); 570 - if (ret < 0) { 570 + if (ret) { 571 571 dev_err(&data->client->dev, "i2c transfer error in irq\n"); 572 572 goto out; 573 573 } 574 574 575 - if (val & SX9310_EVENT_IRQ) 575 + if (val & (SX9310_FAR_IRQ | SX9310_CLOSE_IRQ)) 576 576 sx9310_push_events(indio_dev); 577 577 578 578 if (val & SX9310_CONVDONE_IRQ) ··· 600 600 enum iio_event_direction dir, int state) 601 601 { 602 602 struct sx9310_data *data = iio_priv(indio_dev); 603 + unsigned int eventirq = SX9310_FAR_IRQ | SX9310_CLOSE_IRQ; 603 604 int ret; 604 605 605 606 /* If the state hasn't changed, there's nothing to do. */ ··· 610 609 mutex_lock(&data->mutex); 611 610 if (state) { 612 611 ret = sx9310_get_event_channel(data, chan->channel); 613 - if (ret < 0) 612 + if (ret) 614 613 goto out_unlock; 615 614 if (!(data->chan_event & ~BIT(chan->channel))) { 616 - ret = sx9310_enable_irq(data, SX9310_EVENT_IRQ); 617 - if (ret < 0) 615 + ret = sx9310_enable_irq(data, eventirq); 616 + if (ret) 618 617 sx9310_put_event_channel(data, chan->channel); 619 618 } 620 619 } else { 621 620 ret = sx9310_put_event_channel(data, chan->channel); 622 - if (ret < 0) 621 + if (ret) 623 622 goto out_unlock; 624 623 if (!data->chan_event) { 625 - ret = sx9310_disable_irq(data, SX9310_EVENT_IRQ); 626 - if (ret < 0) 624 + ret = sx9310_disable_irq(data, eventirq); 625 + if (ret) 627 626 sx9310_get_event_channel(data, chan->channel); 628 627 } 629 628 } ··· 635 634 636 635 static struct attribute *sx9310_attributes[] = { 637 636 &iio_dev_attr_sampling_frequency_available.dev_attr.attr, 638 - NULL, 637 + NULL 639 638 }; 640 639 641 640 static const struct attribute_group sx9310_attribute_group = { ··· 662 661 ret = sx9310_enable_irq(data, SX9310_CONVDONE_IRQ); 663 662 else if (!data->chan_read) 664 663 ret = sx9310_disable_irq(data, SX9310_CONVDONE_IRQ); 665 - if (ret < 0) 664 + if (ret) 666 665 goto out; 667 666 668 667 data->trigger_enabled = state; ··· 691 690 indio_dev->masklength) { 692 691 ret = sx9310_read_prox_data(data, &indio_dev->channels[bit], 693 692 &val); 694 - if (ret < 0) 693 + if (ret) 695 694 goto out; 696 695 697 - data->buffer[i++] = val; 696 + data->buffer.channels[i++] = val; 698 697 } 699 698 700 - iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 699 + iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer, 701 700 pf->timestamp); 702 701 703 702 out: ··· 711 710 static int sx9310_buffer_preenable(struct iio_dev *indio_dev) 712 711 { 713 712 struct sx9310_data *data = iio_priv(indio_dev); 714 - unsigned int channels = 0; 713 + unsigned long channels = 0; 715 714 int bit, ret; 716 715 717 716 mutex_lock(&data->mutex); 718 717 for_each_set_bit(bit, indio_dev->active_scan_mask, 719 718 indio_dev->masklength) 720 - channels |= BIT(indio_dev->channels[bit].channel); 719 + __set_bit(indio_dev->channels[bit].channel, &channels); 721 720 722 721 ret = sx9310_update_chan_en(data, channels, data->chan_event); 723 722 mutex_unlock(&data->mutex); ··· 745 744 u8 def; 746 745 }; 747 746 748 - #define SX_INIT(_reg, _def) \ 749 - { \ 750 - .reg = SX9310_REG_##_reg, \ 751 - .def = _def, \ 752 - } 753 - 754 747 static const struct sx9310_reg_default sx9310_default_regs[] = { 755 - SX_INIT(IRQ_MSK, 0x00), 756 - SX_INIT(IRQ_FUNC, 0x00), 748 + { SX9310_REG_IRQ_MSK, 0x00 }, 749 + { SX9310_REG_IRQ_FUNC, 0x00 }, 757 750 /* 758 751 * The lower 4 bits should not be set as it enable sensors measurements. 759 752 * Turning the detection on before the configuration values are set to 760 753 * good values can cause the device to return erroneous readings. 761 754 */ 762 - SX_INIT(PROX_CTRL0, SX9310_REG_PROX_CTRL0_PROXSTAT2), 763 - SX_INIT(PROX_CTRL1, 0x00), 764 - SX_INIT(PROX_CTRL2, SX9310_REG_PROX_CTRL2_COMBMODE_ALL | 765 - SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC), 766 - SX_INIT(PROX_CTRL3, SX9310_REG_PROX_CTRL3_GAIN0_X8 | 767 - SX9310_REG_PROX_CTRL3_GAIN12_X4), 768 - SX_INIT(PROX_CTRL4, SX9310_REG_PROX_CTRL4_RESOLUTION_FINEST), 769 - SX_INIT(PROX_CTRL5, SX9310_REG_PROX_CTRL5_RANGE_SMALL | 770 - SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1 | 771 - SX9310_REG_PROX_CTRL5_RAWFILT_1P25), 772 - SX_INIT(PROX_CTRL6, SX9310_REG_PROX_CTRL6_COMP_COMMON), 773 - SX_INIT(PROX_CTRL7, SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 | 774 - SX9310_REG_PROX_CTRL7_AVGPOSFILT_512), 775 - SX_INIT(PROX_CTRL8, SX9310_REG_PROX_CTRL8_9_PTHRESH_96 | 776 - SX9310_REG_PROX_CTRL8_9_BODYTHRESH_1500), 777 - SX_INIT(PROX_CTRL9, SX9310_REG_PROX_CTRL8_9_PTHRESH12_28 | 778 - SX9310_REG_PROX_CTRL8_9_BODYTHRESH_900), 779 - SX_INIT(PROX_CTRL10, SX9310_REG_PROX_CTRL10_HYST_6PCT | 780 - SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_8 | 781 - SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_8), 782 - SX_INIT(PROX_CTRL11, 0x00), 783 - SX_INIT(PROX_CTRL12, 0x00), 784 - SX_INIT(PROX_CTRL13, 0x00), 785 - SX_INIT(PROX_CTRL14, 0x00), 786 - SX_INIT(PROX_CTRL15, 0x00), 787 - SX_INIT(PROX_CTRL16, 0x00), 788 - SX_INIT(PROX_CTRL17, 0x00), 789 - SX_INIT(PROX_CTRL18, 0x00), 790 - SX_INIT(PROX_CTRL19, 0x00), 791 - SX_INIT(SAR_CTRL0, SX9310_REG_SAR_CTRL0_SARDEB_4_SAMPLES | 792 - SX9310_REG_SAR_CTRL0_SARHYST_8), 793 - SX_INIT(SAR_CTRL1, SX9310_REG_SAR_CTRL1_SLOPE(10781250)), 794 - SX_INIT(SAR_CTRL2, SX9310_REG_SAR_CTRL2_SAROFFSET_DEFAULT), 755 + { SX9310_REG_PROX_CTRL0, SX9310_REG_PROX_CTRL0_SCANPERIOD_15MS }, 756 + { SX9310_REG_PROX_CTRL1, 0x00 }, 757 + { SX9310_REG_PROX_CTRL2, SX9310_REG_PROX_CTRL2_COMBMODE_CS1_CS2 | 758 + SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC }, 759 + { SX9310_REG_PROX_CTRL3, SX9310_REG_PROX_CTRL3_GAIN0_X8 | 760 + SX9310_REG_PROX_CTRL3_GAIN12_X4 }, 761 + { SX9310_REG_PROX_CTRL4, SX9310_REG_PROX_CTRL4_RESOLUTION_FINEST }, 762 + { SX9310_REG_PROX_CTRL5, SX9310_REG_PROX_CTRL5_RANGE_SMALL | 763 + SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1 | 764 + SX9310_REG_PROX_CTRL5_RAWFILT_1P25 }, 765 + { SX9310_REG_PROX_CTRL6, SX9310_REG_PROX_CTRL6_AVGTHRESH_DEFAULT }, 766 + { SX9310_REG_PROX_CTRL7, SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 | 767 + SX9310_REG_PROX_CTRL7_AVGPOSFILT_512 }, 768 + { SX9310_REG_PROX_CTRL8, SX9310_REG_PROX_CTRL8_9_PTHRESH_96 | 769 + SX9310_REG_PROX_CTRL8_9_BODYTHRESH_1500 }, 770 + { SX9310_REG_PROX_CTRL9, SX9310_REG_PROX_CTRL8_9_PTHRESH_28 | 771 + SX9310_REG_PROX_CTRL8_9_BODYTHRESH_900 }, 772 + { SX9310_REG_PROX_CTRL10, SX9310_REG_PROX_CTRL10_HYST_6PCT | 773 + SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_2 }, 774 + { SX9310_REG_PROX_CTRL11, 0x00 }, 775 + { SX9310_REG_PROX_CTRL12, 0x00 }, 776 + { SX9310_REG_PROX_CTRL13, 0x00 }, 777 + { SX9310_REG_PROX_CTRL14, 0x00 }, 778 + { SX9310_REG_PROX_CTRL15, 0x00 }, 779 + { SX9310_REG_PROX_CTRL16, 0x00 }, 780 + { SX9310_REG_PROX_CTRL17, 0x00 }, 781 + { SX9310_REG_PROX_CTRL18, 0x00 }, 782 + { SX9310_REG_PROX_CTRL19, 0x00 }, 783 + { SX9310_REG_SAR_CTRL0, SX9310_REG_SAR_CTRL0_SARDEB_4_SAMPLES | 784 + SX9310_REG_SAR_CTRL0_SARHYST_8 }, 785 + { SX9310_REG_SAR_CTRL1, SX9310_REG_SAR_CTRL1_SLOPE(10781250) }, 786 + { SX9310_REG_SAR_CTRL2, SX9310_REG_SAR_CTRL2_SAROFFSET_DEFAULT }, 795 787 }; 796 788 797 789 /* Activate all channels and perform an initial compensation. */ 798 790 static int sx9310_init_compensation(struct iio_dev *indio_dev) 799 791 { 800 792 struct sx9310_data *data = iio_priv(indio_dev); 801 - int i, ret; 793 + int ret; 802 794 unsigned int val; 803 795 unsigned int ctrl0; 804 796 805 797 ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, &ctrl0); 806 - if (ret < 0) 798 + if (ret) 807 799 return ret; 808 800 809 801 /* run the compensation phase on all channels */ 810 802 ret = regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, 811 - ctrl0 | SX9310_REG_PROX_CTRL0_EN_MASK); 812 - if (ret < 0) 803 + ctrl0 | SX9310_REG_PROX_CTRL0_SENSOREN_MASK); 804 + if (ret) 813 805 return ret; 814 806 815 - for (i = 100; i >= 0; i--) { 816 - msleep(20); 817 - ret = regmap_read(data->regmap, SX9310_REG_STAT1, &val); 818 - if (ret < 0) 819 - goto out; 820 - if (!(val & SX9310_COMPSTAT_MASK)) 821 - break; 807 + ret = regmap_read_poll_timeout(data->regmap, SX9310_REG_STAT1, val, 808 + !(val & SX9310_REG_STAT1_COMPSTAT_MASK), 809 + 20000, 2000000); 810 + if (ret) { 811 + if (ret == -ETIMEDOUT) 812 + dev_err(&data->client->dev, 813 + "initial compensation timed out: 0x%02x\n", 814 + val); 815 + return ret; 822 816 } 823 817 824 - if (i < 0) { 825 - dev_err(&data->client->dev, 826 - "initial compensation timed out: 0x%02x", val); 827 - ret = -ETIMEDOUT; 828 - } 829 - 830 - out: 831 818 regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0); 832 819 return ret; 833 820 } ··· 828 839 unsigned int i, val; 829 840 830 841 ret = regmap_write(data->regmap, SX9310_REG_RESET, SX9310_SOFT_RESET); 831 - if (ret < 0) 842 + if (ret) 832 843 return ret; 833 844 834 845 usleep_range(1000, 2000); /* power-up time is ~1ms. */ 835 846 836 847 /* Clear reset interrupt state by reading SX9310_REG_IRQ_SRC. */ 837 848 ret = regmap_read(data->regmap, SX9310_REG_IRQ_SRC, &val); 838 - if (ret < 0) 849 + if (ret) 839 850 return ret; 840 851 841 852 /* Program some sane defaults. */ 842 853 for (i = 0; i < ARRAY_SIZE(sx9310_default_regs); i++) { 843 854 initval = &sx9310_default_regs[i]; 844 855 ret = regmap_write(data->regmap, initval->reg, initval->def); 845 - if (ret < 0) 856 + if (ret) 846 857 return ret; 847 858 } 848 859 ··· 851 862 852 863 static int sx9310_set_indio_dev_name(struct device *dev, 853 864 struct iio_dev *indio_dev, 854 - const struct i2c_device_id *id, int whoami) 865 + unsigned int whoami) 855 866 { 856 - const struct acpi_device_id *acpi_id; 867 + unsigned int long ddata; 857 868 858 - /* id will be NULL when enumerated via ACPI */ 859 - if (id) { 860 - if (id->driver_data != whoami) 861 - dev_err(dev, "WHOAMI does not match i2c_device_id: %s", 862 - id->name); 863 - } else if (ACPI_HANDLE(dev)) { 864 - acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); 865 - if (!acpi_id) 866 - return -ENODEV; 867 - if (acpi_id->driver_data != whoami) 868 - dev_err(dev, "WHOAMI does not match acpi_device_id: %s", 869 - acpi_id->id); 870 - } else 869 + ddata = (uintptr_t)device_get_match_data(dev); 870 + if (ddata != whoami) { 871 + dev_err(dev, "WHOAMI does not match device data: %u\n", whoami); 871 872 return -ENODEV; 873 + } 872 874 873 875 switch (whoami) { 874 876 case SX9310_WHOAMI_VALUE: ··· 869 889 indio_dev->name = "sx9311"; 870 890 break; 871 891 default: 872 - dev_err(dev, "unexpected WHOAMI response: %u", whoami); 892 + dev_err(dev, "unexpected WHOAMI response: %u\n", whoami); 873 893 return -ENODEV; 874 894 } 875 895 876 896 return 0; 877 897 } 878 898 879 - static int sx9310_probe(struct i2c_client *client, 880 - const struct i2c_device_id *id) 899 + static void sx9310_regulator_disable(void *_data) 900 + { 901 + struct sx9310_data *data = _data; 902 + 903 + regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies); 904 + } 905 + 906 + static int sx9310_probe(struct i2c_client *client) 881 907 { 882 908 int ret; 909 + struct device *dev = &client->dev; 883 910 struct iio_dev *indio_dev; 884 911 struct sx9310_data *data; 885 912 886 - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 887 - if (indio_dev == NULL) 913 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 914 + if (!indio_dev) 888 915 return -ENOMEM; 889 916 890 917 data = iio_priv(indio_dev); 891 918 data->client = client; 919 + data->supplies[0].supply = "vdd"; 920 + data->supplies[1].supply = "svdd"; 892 921 mutex_init(&data->mutex); 893 922 init_completion(&data->completion); 894 923 ··· 905 916 if (IS_ERR(data->regmap)) 906 917 return PTR_ERR(data->regmap); 907 918 919 + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->supplies), 920 + data->supplies); 921 + if (ret) 922 + return ret; 923 + 924 + ret = regulator_bulk_enable(ARRAY_SIZE(data->supplies), data->supplies); 925 + if (ret) 926 + return ret; 927 + /* Must wait for Tpor time after initial power up */ 928 + usleep_range(1000, 1100); 929 + 930 + ret = devm_add_action_or_reset(dev, sx9310_regulator_disable, data); 931 + if (ret) 932 + return ret; 933 + 908 934 ret = regmap_read(data->regmap, SX9310_REG_WHOAMI, &data->whoami); 909 - if (ret < 0) { 910 - dev_err(&client->dev, "error in reading WHOAMI register: %d", 911 - ret); 935 + if (ret) { 936 + dev_err(dev, "error in reading WHOAMI register: %d", ret); 912 937 return ret; 913 938 } 914 939 915 - ret = sx9310_set_indio_dev_name(&client->dev, indio_dev, id, 916 - data->whoami); 917 - if (ret < 0) 940 + ret = sx9310_set_indio_dev_name(dev, indio_dev, data->whoami); 941 + if (ret) 918 942 return ret; 919 943 920 - ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(&client->dev)); 944 + ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(dev)); 921 945 indio_dev->channels = sx9310_channels; 922 946 indio_dev->num_channels = ARRAY_SIZE(sx9310_channels); 923 947 indio_dev->info = &sx9310_info; ··· 938 936 i2c_set_clientdata(client, indio_dev); 939 937 940 938 ret = sx9310_init_device(indio_dev); 941 - if (ret < 0) 939 + if (ret) 942 940 return ret; 943 941 944 942 if (client->irq) { 945 - ret = devm_request_threaded_irq(&client->dev, client->irq, 943 + ret = devm_request_threaded_irq(dev, client->irq, 946 944 sx9310_irq_handler, 947 945 sx9310_irq_thread_handler, 948 - IRQF_TRIGGER_LOW | IRQF_ONESHOT, 946 + IRQF_ONESHOT, 949 947 "sx9310_event", indio_dev); 950 - if (ret < 0) 948 + if (ret) 951 949 return ret; 952 950 953 - data->trig = 954 - devm_iio_trigger_alloc(&client->dev, "%s-dev%d", 955 - indio_dev->name, indio_dev->id); 951 + data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", 952 + indio_dev->name, 953 + indio_dev->id); 956 954 if (!data->trig) 957 955 return -ENOMEM; 958 956 959 - data->trig->dev.parent = &client->dev; 957 + data->trig->dev.parent = dev; 960 958 data->trig->ops = &sx9310_trigger_ops; 961 959 iio_trigger_set_drvdata(data->trig, indio_dev); 962 960 963 - ret = devm_iio_trigger_register(&client->dev, data->trig); 961 + ret = devm_iio_trigger_register(dev, data->trig); 964 962 if (ret) 965 963 return ret; 966 964 } 967 965 968 - ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, 966 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 969 967 iio_pollfunc_store_time, 970 968 sx9310_trigger_handler, 971 969 &sx9310_buffer_setup_ops); 972 - if (ret < 0) 970 + if (ret) 973 971 return ret; 974 972 975 - return devm_iio_device_register(&client->dev, indio_dev); 973 + return devm_iio_device_register(dev, indio_dev); 976 974 } 977 975 978 976 static int __maybe_unused sx9310_suspend(struct device *dev) ··· 987 985 mutex_lock(&data->mutex); 988 986 ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, 989 987 &data->suspend_ctrl0); 990 - 991 988 if (ret) 992 989 goto out; 993 990 994 - ctrl0 = data->suspend_ctrl0 & ~SX9310_REG_PROX_CTRL0_EN_MASK; 991 + ctrl0 = data->suspend_ctrl0 & ~SX9310_REG_PROX_CTRL0_SENSOREN_MASK; 995 992 ret = regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0); 996 993 if (ret) 997 994 goto out; ··· 1018 1017 1019 1018 out: 1020 1019 mutex_unlock(&data->mutex); 1020 + if (ret) 1021 + return ret; 1021 1022 1022 1023 enable_irq(data->client->irq); 1023 - 1024 - return ret; 1024 + return 0; 1025 1025 } 1026 1026 1027 1027 static const struct dev_pm_ops sx9310_pm_ops = { ··· 1032 1030 static const struct acpi_device_id sx9310_acpi_match[] = { 1033 1031 { "STH9310", SX9310_WHOAMI_VALUE }, 1034 1032 { "STH9311", SX9311_WHOAMI_VALUE }, 1035 - {}, 1033 + {} 1036 1034 }; 1037 1035 MODULE_DEVICE_TABLE(acpi, sx9310_acpi_match); 1038 1036 1039 1037 static const struct of_device_id sx9310_of_match[] = { 1040 - { .compatible = "semtech,sx9310" }, 1041 - { .compatible = "semtech,sx9311" }, 1042 - {}, 1038 + { .compatible = "semtech,sx9310", (void *)SX9310_WHOAMI_VALUE }, 1039 + { .compatible = "semtech,sx9311", (void *)SX9311_WHOAMI_VALUE }, 1040 + {} 1043 1041 }; 1044 1042 MODULE_DEVICE_TABLE(of, sx9310_of_match); 1045 1043 1046 1044 static const struct i2c_device_id sx9310_id[] = { 1047 1045 { "sx9310", SX9310_WHOAMI_VALUE }, 1048 1046 { "sx9311", SX9311_WHOAMI_VALUE }, 1049 - {}, 1047 + {} 1050 1048 }; 1051 1049 MODULE_DEVICE_TABLE(i2c, sx9310_id); 1052 1050 1053 1051 static struct i2c_driver sx9310_driver = { 1054 1052 .driver = { 1055 1053 .name = "sx9310", 1056 - .acpi_match_table = ACPI_PTR(sx9310_acpi_match), 1057 - .of_match_table = of_match_ptr(sx9310_of_match), 1054 + .acpi_match_table = sx9310_acpi_match, 1055 + .of_match_table = sx9310_of_match, 1058 1056 .pm = &sx9310_pm_ops, 1059 1057 }, 1060 - .probe = sx9310_probe, 1058 + .probe_new = sx9310_probe, 1061 1059 .id_table = sx9310_id, 1062 1060 }; 1063 1061 module_i2c_driver(sx9310_driver);
+247 -27
drivers/iio/temperature/mlx90632.c
··· 10 10 #include <linux/err.h> 11 11 #include <linux/gpio/consumer.h> 12 12 #include <linux/i2c.h> 13 + #include <linux/iopoll.h> 13 14 #include <linux/kernel.h> 15 + #include <linux/limits.h> 14 16 #include <linux/module.h> 15 17 #include <linux/math64.h> 16 18 #include <linux/of.h> ··· 60 58 /* Control register address - volatile */ 61 59 #define MLX90632_REG_CONTROL 0x3001 /* Control Register address */ 62 60 #define MLX90632_CFG_PWR_MASK GENMASK(2, 1) /* PowerMode Mask */ 61 + #define MLX90632_CFG_MTYP_MASK GENMASK(8, 4) /* Meas select Mask */ 62 + 63 63 /* PowerModes statuses */ 64 64 #define MLX90632_PWR_STATUS(ctrl_val) (ctrl_val << 1) 65 65 #define MLX90632_PWR_STATUS_HALT MLX90632_PWR_STATUS(0) /* hold */ 66 66 #define MLX90632_PWR_STATUS_SLEEP_STEP MLX90632_PWR_STATUS(1) /* sleep step*/ 67 67 #define MLX90632_PWR_STATUS_STEP MLX90632_PWR_STATUS(2) /* step */ 68 68 #define MLX90632_PWR_STATUS_CONTINUOUS MLX90632_PWR_STATUS(3) /* continuous*/ 69 + 70 + /* Measurement types */ 71 + #define MLX90632_MTYP_MEDICAL 0 72 + #define MLX90632_MTYP_EXTENDED 17 73 + 74 + /* Measurement type select*/ 75 + #define MLX90632_MTYP_STATUS(ctrl_val) (ctrl_val << 4) 76 + #define MLX90632_MTYP_STATUS_MEDICAL MLX90632_MTYP_STATUS(MLX90632_MTYP_MEDICAL) 77 + #define MLX90632_MTYP_STATUS_EXTENDED MLX90632_MTYP_STATUS(MLX90632_MTYP_EXTENDED) 78 + 79 + /* I2C command register - volatile */ 80 + #define MLX90632_REG_I2C_CMD 0x3005 /* I2C command Register address */ 69 81 70 82 /* Device status register - volatile */ 71 83 #define MLX90632_REG_STATUS 0x3fff /* Device status register */ ··· 94 78 #define MLX90632_RAM_2(meas_num) (MLX90632_ADDR_RAM + 3 * meas_num + 1) 95 79 #define MLX90632_RAM_3(meas_num) (MLX90632_ADDR_RAM + 3 * meas_num + 2) 96 80 81 + /* Name important RAM_MEAS channels */ 82 + #define MLX90632_RAM_DSP5_EXTENDED_AMBIENT_1 MLX90632_RAM_3(17) 83 + #define MLX90632_RAM_DSP5_EXTENDED_AMBIENT_2 MLX90632_RAM_3(18) 84 + #define MLX90632_RAM_DSP5_EXTENDED_OBJECT_1 MLX90632_RAM_1(17) 85 + #define MLX90632_RAM_DSP5_EXTENDED_OBJECT_2 MLX90632_RAM_2(17) 86 + #define MLX90632_RAM_DSP5_EXTENDED_OBJECT_3 MLX90632_RAM_1(18) 87 + #define MLX90632_RAM_DSP5_EXTENDED_OBJECT_4 MLX90632_RAM_2(18) 88 + #define MLX90632_RAM_DSP5_EXTENDED_OBJECT_5 MLX90632_RAM_1(19) 89 + #define MLX90632_RAM_DSP5_EXTENDED_OBJECT_6 MLX90632_RAM_2(19) 90 + 97 91 /* Magic constants */ 98 92 #define MLX90632_ID_MEDICAL 0x0105 /* EEPROM DSPv5 Medical device id */ 99 93 #define MLX90632_ID_CONSUMER 0x0205 /* EEPROM DSPv5 Consumer device id */ 94 + #define MLX90632_ID_EXTENDED 0x0505 /* EEPROM DSPv5 Extended range device id */ 95 + #define MLX90632_ID_MASK GENMASK(14, 0) /* DSP version and device ID in EE_VERSION */ 100 96 #define MLX90632_DSP_VERSION 5 /* DSP version */ 101 97 #define MLX90632_DSP_MASK GENMASK(7, 0) /* DSP version in EE_VERSION */ 102 98 #define MLX90632_RESET_CMD 0x0006 /* Reset sensor (address or global) */ 103 - #define MLX90632_REF_12 12LL /**< ResCtrlRef value of Ch 1 or Ch 2 */ 104 - #define MLX90632_REF_3 12LL /**< ResCtrlRef value of Channel 3 */ 105 - #define MLX90632_MAX_MEAS_NUM 31 /**< Maximum measurements in list */ 106 - #define MLX90632_SLEEP_DELAY_MS 3000 /**< Autosleep delay */ 99 + #define MLX90632_REF_12 12LL /* ResCtrlRef value of Ch 1 or Ch 2 */ 100 + #define MLX90632_REF_3 12LL /* ResCtrlRef value of Channel 3 */ 101 + #define MLX90632_MAX_MEAS_NUM 31 /* Maximum measurements in list */ 102 + #define MLX90632_SLEEP_DELAY_MS 3000 /* Autosleep delay */ 103 + #define MLX90632_EXTENDED_LIMIT 27000 /* Extended mode raw value limit */ 107 104 105 + /** 106 + * struct mlx90632_data - private data for the MLX90632 device 107 + * @client: I2C client of the device 108 + * @lock: Internal mutex for multiple reads for single measurement 109 + * @regmap: Regmap of the device 110 + * @emissivity: Object emissivity from 0 to 1000 where 1000 = 1. 111 + * @mtyp: Measurement type physical sensor configuration for extended range 112 + * calculations 113 + * @object_ambient_temperature: Ambient temperature at object (might differ of 114 + * the ambient temperature of sensor. 115 + */ 108 116 struct mlx90632_data { 109 117 struct i2c_client *client; 110 - struct mutex lock; /* Multiple reads for single measurement */ 118 + struct mutex lock; 111 119 struct regmap *regmap; 112 120 u16 emissivity; 121 + u8 mtyp; 122 + u32 object_ambient_temperature; 113 123 }; 114 124 115 125 static const struct regmap_range mlx90632_volatile_reg_range[] = { 116 126 regmap_reg_range(MLX90632_REG_I2C_ADDR, MLX90632_REG_CONTROL), 127 + regmap_reg_range(MLX90632_REG_I2C_CMD, MLX90632_REG_I2C_CMD), 117 128 regmap_reg_range(MLX90632_REG_STATUS, MLX90632_REG_STATUS), 118 129 regmap_reg_range(MLX90632_RAM_1(0), 119 130 MLX90632_RAM_3(MLX90632_MAX_MEAS_NUM)), ··· 156 113 regmap_reg_range(MLX90632_EE_CTRL, MLX90632_EE_I2C_ADDR), 157 114 regmap_reg_range(MLX90632_EE_Ha, MLX90632_EE_Hb), 158 115 regmap_reg_range(MLX90632_REG_I2C_ADDR, MLX90632_REG_CONTROL), 116 + regmap_reg_range(MLX90632_REG_I2C_CMD, MLX90632_REG_I2C_CMD), 159 117 regmap_reg_range(MLX90632_REG_STATUS, MLX90632_REG_STATUS), 160 118 regmap_reg_range(MLX90632_RAM_1(0), 161 119 MLX90632_RAM_3(MLX90632_MAX_MEAS_NUM)), ··· 217 173 */ 218 174 static int mlx90632_perform_measurement(struct mlx90632_data *data) 219 175 { 220 - int ret, tries = 100; 221 176 unsigned int reg_status; 177 + int ret; 222 178 223 179 ret = regmap_update_bits(data->regmap, MLX90632_REG_STATUS, 224 180 MLX90632_STAT_DATA_RDY, 0); 225 181 if (ret < 0) 226 182 return ret; 227 183 228 - while (tries-- > 0) { 229 - ret = regmap_read(data->regmap, MLX90632_REG_STATUS, 230 - &reg_status); 231 - if (ret < 0) 232 - return ret; 233 - if (reg_status & MLX90632_STAT_DATA_RDY) 234 - break; 235 - usleep_range(10000, 11000); 236 - } 184 + ret = regmap_read_poll_timeout(data->regmap, MLX90632_REG_STATUS, reg_status, 185 + !(reg_status & MLX90632_STAT_DATA_RDY), 10000, 186 + 100 * 10000); 237 187 238 - if (tries < 0) { 188 + if (ret < 0) { 239 189 dev_err(&data->client->dev, "data not ready"); 240 190 return -ETIMEDOUT; 241 191 } 242 192 243 193 return (reg_status & MLX90632_STAT_CYCLE_POS) >> 2; 194 + } 195 + 196 + static int mlx90632_set_meas_type(struct regmap *regmap, u8 type) 197 + { 198 + int ret; 199 + 200 + if ((type != MLX90632_MTYP_MEDICAL) && (type != MLX90632_MTYP_EXTENDED)) 201 + return -EINVAL; 202 + 203 + ret = regmap_write(regmap, MLX90632_REG_I2C_CMD, MLX90632_RESET_CMD); 204 + if (ret < 0) 205 + return ret; 206 + 207 + ret = regmap_write_bits(regmap, MLX90632_REG_CONTROL, 208 + (MLX90632_CFG_MTYP_MASK | MLX90632_CFG_PWR_MASK), 209 + (MLX90632_MTYP_STATUS(type) | MLX90632_PWR_STATUS_HALT)); 210 + if (ret < 0) 211 + return ret; 212 + 213 + return mlx90632_pwr_continuous(regmap); 244 214 } 245 215 246 216 static int mlx90632_channel_new_select(int perform_ret, uint8_t *channel_new, ··· 358 300 return ret; 359 301 } 360 302 303 + static int mlx90632_read_ambient_raw_extended(struct regmap *regmap, 304 + s16 *ambient_new_raw, s16 *ambient_old_raw) 305 + { 306 + unsigned int read_tmp; 307 + int ret; 308 + 309 + ret = regmap_read(regmap, MLX90632_RAM_DSP5_EXTENDED_AMBIENT_1, &read_tmp); 310 + if (ret < 0) 311 + return ret; 312 + *ambient_new_raw = (s16)read_tmp; 313 + 314 + ret = regmap_read(regmap, MLX90632_RAM_DSP5_EXTENDED_AMBIENT_2, &read_tmp); 315 + if (ret < 0) 316 + return ret; 317 + *ambient_old_raw = (s16)read_tmp; 318 + 319 + return 0; 320 + } 321 + 322 + static int mlx90632_read_object_raw_extended(struct regmap *regmap, s16 *object_new_raw) 323 + { 324 + unsigned int read_tmp; 325 + s32 read; 326 + int ret; 327 + 328 + ret = regmap_read(regmap, MLX90632_RAM_DSP5_EXTENDED_OBJECT_1, &read_tmp); 329 + if (ret < 0) 330 + return ret; 331 + read = (s16)read_tmp; 332 + 333 + ret = regmap_read(regmap, MLX90632_RAM_DSP5_EXTENDED_OBJECT_2, &read_tmp); 334 + if (ret < 0) 335 + return ret; 336 + read = read - (s16)read_tmp; 337 + 338 + ret = regmap_read(regmap, MLX90632_RAM_DSP5_EXTENDED_OBJECT_3, &read_tmp); 339 + if (ret < 0) 340 + return ret; 341 + read = read - (s16)read_tmp; 342 + 343 + ret = regmap_read(regmap, MLX90632_RAM_DSP5_EXTENDED_OBJECT_4, &read_tmp); 344 + if (ret < 0) 345 + return ret; 346 + read = (read + (s16)read_tmp) / 2; 347 + 348 + ret = regmap_read(regmap, MLX90632_RAM_DSP5_EXTENDED_OBJECT_5, &read_tmp); 349 + if (ret < 0) 350 + return ret; 351 + read = read + (s16)read_tmp; 352 + 353 + ret = regmap_read(regmap, MLX90632_RAM_DSP5_EXTENDED_OBJECT_6, &read_tmp); 354 + if (ret < 0) 355 + return ret; 356 + read = read + (s16)read_tmp; 357 + 358 + if (read > S16_MAX || read < S16_MIN) 359 + return -ERANGE; 360 + 361 + *object_new_raw = read; 362 + 363 + return 0; 364 + } 365 + 366 + static int mlx90632_read_all_channel_extended(struct mlx90632_data *data, s16 *object_new_raw, 367 + s16 *ambient_new_raw, s16 *ambient_old_raw) 368 + { 369 + s32 ret, meas; 370 + 371 + mutex_lock(&data->lock); 372 + ret = mlx90632_set_meas_type(data->regmap, MLX90632_MTYP_EXTENDED); 373 + if (ret < 0) 374 + goto read_unlock; 375 + 376 + ret = read_poll_timeout(mlx90632_perform_measurement, meas, meas == 19, 377 + 50000, 800000, false, data); 378 + if (ret != 0) 379 + goto read_unlock; 380 + 381 + ret = mlx90632_read_object_raw_extended(data->regmap, object_new_raw); 382 + if (ret < 0) 383 + goto read_unlock; 384 + 385 + ret = mlx90632_read_ambient_raw_extended(data->regmap, ambient_new_raw, ambient_old_raw); 386 + 387 + read_unlock: 388 + (void) mlx90632_set_meas_type(data->regmap, MLX90632_MTYP_MEDICAL); 389 + 390 + mutex_unlock(&data->lock); 391 + return ret; 392 + } 393 + 361 394 static int mlx90632_read_ee_register(struct regmap *regmap, u16 reg_lsb, 362 395 s32 *reg_value) 363 396 { ··· 503 354 return div64_s64((tmp << 19ULL), 1000LL); 504 355 } 505 356 357 + static s64 mlx90632_preprocess_temp_obj_extended(s16 object_new_raw, s16 ambient_new_raw, 358 + s16 ambient_old_raw, s16 Ka) 359 + { 360 + s64 VR_IR, kKa, tmp; 361 + 362 + kKa = ((s64)Ka * 1000LL) >> 10ULL; 363 + VR_IR = (s64)ambient_old_raw * 1000000LL + 364 + kKa * div64_s64((s64)ambient_new_raw * 1000LL, 365 + MLX90632_REF_3); 366 + tmp = div64_s64( 367 + div64_s64((s64) object_new_raw * 1000000000000LL, MLX90632_REF_12), 368 + VR_IR); 369 + return div64_s64(tmp << 19ULL, 1000LL); 370 + } 371 + 506 372 static s32 mlx90632_calc_temp_ambient(s16 ambient_new_raw, s16 ambient_old_raw, 507 - s32 P_T, s32 P_R, s32 P_G, s32 P_O, 508 - s16 Gb) 373 + s32 P_T, s32 P_R, s32 P_G, s32 P_O, s16 Gb) 509 374 { 510 375 s64 Asub, Bsub, Ablock, Bblock, Cblock, AMB, sum; 511 376 ··· 537 374 } 538 375 539 376 static s32 mlx90632_calc_temp_object_iteration(s32 prev_object_temp, s64 object, 540 - s64 TAdut, s32 Fa, s32 Fb, 377 + s64 TAdut, s64 TAdut4, s32 Fa, s32 Fb, 541 378 s32 Ga, s16 Ha, s16 Hb, 542 379 u16 emissivity) 543 380 { 544 - s64 calcedKsTO, calcedKsTA, ir_Alpha, TAdut4, Alpha_corr; 381 + s64 calcedKsTO, calcedKsTA, ir_Alpha, Alpha_corr; 545 382 s64 Ha_customer, Hb_customer; 546 383 547 384 Ha_customer = ((s64)Ha * 1000000LL) >> 14ULL; ··· 556 393 Alpha_corr = emissivity * div64_s64(Alpha_corr, 100000LL); 557 394 Alpha_corr = div64_s64(Alpha_corr, 1000LL); 558 395 ir_Alpha = div64_s64((s64)object * 10000000LL, Alpha_corr); 559 - TAdut4 = (div64_s64(TAdut, 10000LL) + 27315) * 560 - (div64_s64(TAdut, 10000LL) + 27315) * 561 - (div64_s64(TAdut, 10000LL) + 27315) * 562 - (div64_s64(TAdut, 10000LL) + 27315); 563 396 564 397 return (int_sqrt64(int_sqrt64(ir_Alpha * 1000000000000LL + TAdut4)) 565 398 - 27315 - Hb_customer) * 10; 399 + } 400 + 401 + static s64 mlx90632_calc_ta4(s64 TAdut, s64 scale) 402 + { 403 + return (div64_s64(TAdut, scale) + 27315) * 404 + (div64_s64(TAdut, scale) + 27315) * 405 + (div64_s64(TAdut, scale) + 27315) * 406 + (div64_s64(TAdut, scale) + 27315); 566 407 } 567 408 568 409 static s32 mlx90632_calc_temp_object(s64 object, s64 ambient, s32 Ea, s32 Eb, 569 410 s32 Fa, s32 Fb, s32 Ga, s16 Ha, s16 Hb, 570 411 u16 tmp_emi) 571 412 { 572 - s64 kTA, kTA0, TAdut; 413 + s64 kTA, kTA0, TAdut, TAdut4; 573 414 s64 temp = 25000; 574 415 s8 i; 575 416 576 417 kTA = (Ea * 1000LL) >> 16LL; 577 418 kTA0 = (Eb * 1000LL) >> 8LL; 578 419 TAdut = div64_s64(((ambient - kTA0) * 1000000LL), kTA) + 25 * 1000000LL; 420 + TAdut4 = mlx90632_calc_ta4(TAdut, 10000LL); 579 421 580 422 /* Iterations of calculation as described in datasheet */ 581 423 for (i = 0; i < 5; ++i) { 582 - temp = mlx90632_calc_temp_object_iteration(temp, object, TAdut, 424 + temp = mlx90632_calc_temp_object_iteration(temp, object, TAdut, TAdut4, 583 425 Fa, Fb, Ga, Ha, Hb, 584 426 tmp_emi); 585 427 } 428 + return temp; 429 + } 430 + 431 + static s32 mlx90632_calc_temp_object_extended(s64 object, s64 ambient, s64 reflected, 432 + s32 Ea, s32 Eb, s32 Fa, s32 Fb, s32 Ga, 433 + s16 Ha, s16 Hb, u16 tmp_emi) 434 + { 435 + s64 kTA, kTA0, TAdut, TAdut4, Tr4, TaTr4; 436 + s64 temp = 25000; 437 + s8 i; 438 + 439 + kTA = (Ea * 1000LL) >> 16LL; 440 + kTA0 = (Eb * 1000LL) >> 8LL; 441 + TAdut = div64_s64((ambient - kTA0) * 1000000LL, kTA) + 25 * 1000000LL; 442 + Tr4 = mlx90632_calc_ta4(reflected, 10); 443 + TAdut4 = mlx90632_calc_ta4(TAdut, 10000LL); 444 + TaTr4 = Tr4 - div64_s64(Tr4 - TAdut4, tmp_emi) * 1000; 445 + 446 + /* Iterations of calculation as described in datasheet */ 447 + for (i = 0; i < 5; ++i) { 448 + temp = mlx90632_calc_temp_object_iteration(temp, object, TAdut, TaTr4, 449 + Fa / 2, Fb, Ga, Ha, Hb, 450 + tmp_emi); 451 + } 452 + 586 453 return temp; 587 454 } 588 455 ··· 662 469 &object_new_raw, &object_old_raw); 663 470 if (ret < 0) 664 471 return ret; 472 + 473 + if (object_new_raw > MLX90632_EXTENDED_LIMIT && 474 + data->mtyp == MLX90632_MTYP_EXTENDED) { 475 + ret = mlx90632_read_all_channel_extended(data, &object_new_raw, 476 + &ambient_new_raw, &ambient_old_raw); 477 + if (ret < 0) 478 + return ret; 479 + 480 + /* Use extended mode calculations */ 481 + ambient = mlx90632_preprocess_temp_amb(ambient_new_raw, 482 + ambient_old_raw, Gb); 483 + object = mlx90632_preprocess_temp_obj_extended(object_new_raw, 484 + ambient_new_raw, 485 + ambient_old_raw, Ka); 486 + *val = mlx90632_calc_temp_object_extended(object, ambient, 487 + data->object_ambient_temperature, 488 + Ea, Eb, Fa, Fb, Ga, 489 + Ha, Hb, data->emissivity); 490 + return 0; 491 + } 665 492 666 493 ambient = mlx90632_preprocess_temp_amb(ambient_new_raw, 667 494 ambient_old_raw, Gb); ··· 856 643 i2c_set_clientdata(client, indio_dev); 857 644 mlx90632->client = client; 858 645 mlx90632->regmap = regmap; 646 + mlx90632->mtyp = MLX90632_MTYP_MEDICAL; 859 647 860 648 mutex_init(&mlx90632->lock); 861 649 indio_dev->name = id->name; ··· 876 662 dev_err(&client->dev, "read of version failed: %d\n", ret); 877 663 return ret; 878 664 } 665 + read = read & MLX90632_ID_MASK; 879 666 if (read == MLX90632_ID_MEDICAL) { 880 667 dev_dbg(&client->dev, 881 668 "Detected Medical EEPROM calibration %x\n", read); 882 669 } else if (read == MLX90632_ID_CONSUMER) { 883 670 dev_dbg(&client->dev, 884 671 "Detected Consumer EEPROM calibration %x\n", read); 672 + } else if (read == MLX90632_ID_EXTENDED) { 673 + dev_dbg(&client->dev, 674 + "Detected Extended range EEPROM calibration %x\n", read); 675 + mlx90632->mtyp = MLX90632_MTYP_EXTENDED; 885 676 } else if ((read & MLX90632_DSP_MASK) == MLX90632_DSP_VERSION) { 886 677 dev_dbg(&client->dev, 887 - "Detected Unknown EEPROM calibration %x\n", read); 678 + "Detected Unknown EEPROM calibration %x\n", read); 888 679 } else { 889 680 dev_err(&client->dev, 890 681 "Wrong DSP version %x (expected %x)\n", ··· 898 679 } 899 680 900 681 mlx90632->emissivity = 1000; 682 + mlx90632->object_ambient_temperature = 25000; /* 25 degrees milliCelsius */ 901 683 902 684 pm_runtime_disable(&client->dev); 903 685 ret = pm_runtime_set_active(&client->dev);
+2 -2
drivers/staging/iio/Documentation/overview.txt
··· 9 9 input subsystems. Hwmon is very much directed at low sample rate 10 10 sensors used in applications such as fan speed control and temperature 11 11 measurement. Input is, as its name suggests focused on input 12 - devices. In some cases there is considerable overlap between these and 12 + devices. In some cases, there is considerable overlap between these and 13 13 IIO. 14 14 15 15 A typical device falling into this category would be connected via SPI ··· 38 38 polling to establish when data is available. 39 39 40 40 * Trigger and software buffer support. In many data analysis 41 - applications it it useful to be able to capture data based on some 41 + applications it is useful to be able to capture data based on some 42 42 external signal (trigger). These triggers might be a data ready 43 43 signal, a gpio line connected to some external system or an on 44 44 processor periodic interrupt. A single trigger may initialize data
-1
drivers/staging/iio/frequency/ad9834.c
··· 397 397 struct regulator *reg; 398 398 int ret; 399 399 400 - 401 400 reg = devm_regulator_get(&spi->dev, "avdd"); 402 401 if (IS_ERR(reg)) 403 402 return PTR_ERR(reg);
+1 -1
include/linux/platform_data/ad7793.h
··· 40 40 * enum ad7793_refsel - AD7793 reference voltage selection 41 41 * @AD7793_REFSEL_REFIN1: External reference applied between REFIN1(+) 42 42 * and REFIN1(-). 43 - * @AD7793_REFSEL_REFIN2: External reference applied between REFIN2(+) and 43 + * @AD7793_REFSEL_REFIN2: External reference applied between REFIN2(+) 44 44 * and REFIN1(-). Only valid for AD7795/AD7796. 45 45 * @AD7793_REFSEL_INTERNAL: Internal 1.17 V reference. 46 46 */
+1
include/uapi/linux/iio/types.h
··· 94 94 IIO_MOD_PM10, 95 95 IIO_MOD_ETHANOL, 96 96 IIO_MOD_H2, 97 + IIO_MOD_O2, 97 98 }; 98 99 99 100 enum iio_event_type {
+2
tools/iio/iio_event_monitor.c
··· 119 119 [IIO_MOD_PM2P5] = "pm2p5", 120 120 [IIO_MOD_PM4] = "pm4", 121 121 [IIO_MOD_PM10] = "pm10", 122 + [IIO_MOD_O2] = "o2", 122 123 }; 123 124 124 125 static bool event_is_known(struct iio_event_data *event) ··· 212 211 case IIO_MOD_PM2P5: 213 212 case IIO_MOD_PM4: 214 213 case IIO_MOD_PM10: 214 + case IIO_MOD_O2: 215 215 break; 216 216 default: 217 217 return false;