History

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

Jonathan writes: First set of new IIO device support, features and cleanup for the 5.8 cycle Usual mix of new drivers, new support in old drivers and lots of minor cleanup. Yaml conversions also continue to trickle in (plenty more to go!) New device support * ad7476 - Add ad7091 support (ID only) * ad9467 - New driver for this 200/250 MSPS adi-axi-adc and SPI attached ADC. * adi-axi-adc - New driver to support ADIs generic AXI ADC IP core, used to provide high speed interfaces to ADCs (JESD204B/C or parallel interfaces). Usually paired with a device using a slow configuration interface (spi etc) Includes DT bindings and some fixes for fpga headers. * bmg160 - Add support for BMI088 (ID only) * max1241 - New driver for this ADC. * st_sensors - Add support for LIS2HH12 accelerometer * sx9310 - New driver supporting sx9310 and sx9311 proximity sensors. Yaml DT binding conversions * rockchip-saradc (including adding some missing parts) * stm32-dac * tsl2563 * vcnl4000 Features * st_lsm6dsx - Add LIS3MDL as a possible sensor hub device. * vcnl4000 - Add new concept of near level (from DT) to provide to userspace which often needs to have some calibrated concept of 'near'. Cleanups, minor fixes etc. * core - Use snprintf for functions where strings are built and there is potential for overflow. - Correct docs to indicate mlock should not be used directly by drivers. - Fix up accidental dropping of a patch to use bitmap_zalloc. - Stop allowing enabling of buffers with no channels enabled. - Drop unused 'stufftoread' from iio_buffer. - Drop scan_el_attrs form iio_buffer as unused. - Reorder sanity checks in __iio_device_register to fail earlier. - Drop all the devm_ runregister / free functions from IIO as they were never used and encourage poor design. * dma-buffer - Tidy up includes. * dma-engine-buffer - Provide dev-managed allocator. - Fix an issue with printing a size_t * cross subsystem (kxsd9, bmg160, mpu3050, bmi160, mpu6050, bmc150) - Replace some unnecessary casts of error ptrs and whilst there. use the %pe printf parameter to print them in a more useful fashion. * cross subsystem - Drop casts in calls to regmap_bulk_read as they make no sense. - Use devm_platform_ioremap_resource to reduce boilerplate. - Fix typos in Analog Devices. * counters/104-quad - Add Syed Nayyar Waris as an additional maintainer. * ad7476 - Generate CONVST signal internally rather than requiring external trigger. Add sysfs read back as can now do so. - use devm_add_action_or_reset to tidy up error and remove handling. * ad7793 - Switch to read_avail from explicit attribute. Mostly done to avoid confusing people with a - sign (without surounding spaces) that was correct but checkpatch didn't like. * adis library - Add missing newlines at end of error messages. * adis16400 - Use DEFINE_DEBUGS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTR. * adis16460 - Use DEFINE_DEBUGS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTR. * ad_sigma_delta - Move some channel definitions into individual drivers to avoid having to deal with complex options. * ak8974 - Silence an error on deffered probe. * bmp280 - Harden against IRQ before registration. - Convert to read_avail instead of opencoding the equivalent. - Explicitly mark GPIO as optional. - Cleanup casts. - Remove line breaks from strings. * htts221 - Replace direct access to platform_data with dev_get_platdata(). - Use device properties rather than device tree ones to allow ACPI probing. - Casting cleanups. * intel_mrfld_adc - Don't use unaligned accessor for aligned data. * isl29125 - Reorder buer pre and post hooks to allow for coming core rework. * ltc2983 - Remove comp to bool. * max1363 - Stop using mlock from the iio_dev directly in favour of a local lock with clearly defined scope. * max30100 - Use generic device properties to allow ACPI probe. * mpu6050 - Convert to i2c_new_client_device. - Add debugfs register access. * st_lsm6dsx - Provide means of configuring full scale on slave device if supported. - Drop include of st_sensors header to get one value. Its not otherwise used by this driver. * st-sensors - Replace direct access to platform_data with dev_get_platdata(). - Casting cleanups. - Avoid splitting strings. * st_uvis25 - Casting cleanups. * tsl2563 - Typo fix. * tsl2772 - scnprintf in a non obvious string building usecase. Note also 'fixes' a wrong calculation of remaining space that couldn't actually cause any trouble as there was lots of room. * xilinx-xadc - Fix Lars-Peter spelling his own name wrong :) + additional typos. * tag 'iio-for-5.8a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (101 commits) iio: magnetometer: ak8974: Silence deferred-probe error Documentation: ABI: document IIO in_proximity_nearlevel file iio: vcnl4000: Export near level property for proximity sensor dt-bindings: iio: light: vcnl4000: Add proximity-near-level dt-bindings: iio: Introduce common properties for iio sensors dt-bindings: iio: vcnl4000: convert bindings to YAML format iio: Fix misspellings of "Analog Devices" iio: light: isl29125: fix iio_triggered_buffer_{predisable,postenable} positions iio: adc: fsl-imx25-gcq: Use devm_platform_ioremap_resource iio: adc: at91-adc: Use devm_platform_ioremap_resource iio: adc: sun4i-gpadc-iio: Use devm_platform_ioremap_resource iio:light:ltr501: Drop unnecessary cast of parameter in regmap_bulk_read iio:magn:mmc35240: Drop unnecessary casts of val parameter in regmap_bulk* iio:imu:mpu6050: Tidy up parameters to regmap_bulk functions. iio:chemical:bme680: Tidy up parameters to regmap_bulk_read iio:chemical:atlas-sensor: Drop unnecessary explicit casts in regmap_bulk_read calls iio:accel:mxc4005: Drop unnecessary explicit casts in regmap_bulk_read calls iio: imu: st_lsm6dsx: drop huge include in sensor-hub driver iio: buffer: drop devm_iio_kfifo_free() API call iio: buffer: drop devm_iio_hw_consumer_free() API call ...

Greg Kroah-Hartman committed 6 years ago

Commit 4e1d9632 parents 710c451 2de8c02110 files · +3625 −774Browse files

Unified · Split

110 files
  1. Documentation/ABI/testing/sysfs-bus-iio-proximity +10 −0
  2. Documentation/ABI/testing/sysfs-bus-iio-sx9310 +10 −0
  3. Documentation/devicetree/bindings/iio/adc/adi,ad9467.yaml +65 −0
  4. Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml +62 −0
  5. Documentation/devicetree/bindings/iio/adc/maxim,max1241.yaml +63 −0
  6. Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt +0 −37
  7. Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml +80 −0
  8. Documentation/devicetree/bindings/iio/common.yaml +35 −0
  9. Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt +0 −63
  10. Documentation/devicetree/bindings/iio/dac/st,stm32-dac.yaml +110 −0
  11. Documentation/devicetree/bindings/iio/gyroscope/bmg160.txt +1 −1
  12. Documentation/devicetree/bindings/iio/light/amstaos,tsl2563.yaml +49 −0
  13. Documentation/devicetree/bindings/iio/light/tsl2563.txt +0 −19
  14. Documentation/devicetree/bindings/iio/light/vcnl4000.txt +0 −24
  15. Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +50 −0
  16. Documentation/devicetree/bindings/iio/st-sensors.txt +1 −0
  17. Documentation/driver-api/driver-model/devres.rst +0 −8
  18. Documentation/driver-api/iio/triggers.rst +0 −2
  19. MAINTAINERS +1 −0
  20. drivers/iio/accel/Kconfig +1 −1
  21. drivers/iio/accel/kxsd9-i2c.c +2 −2
  22. drivers/iio/accel/mxc4005.c +2 −2
  23. drivers/iio/accel/st_accel.h +2 −0
  24. drivers/iio/accel/st_accel_buffer.c +1 −2
  25. drivers/iio/accel/st_accel_core.c +79 −4
  26. drivers/iio/accel/st_accel_i2c.c +5 −0
  27. drivers/iio/adc/Kconfig +45 −0
  28. drivers/iio/adc/Makefile +3 −0
  29. drivers/iio/adc/ad7476.c +46 −13
  30. drivers/iio/adc/ad7780.c +23 −4
  31. drivers/iio/adc/ad7791.c +56 −8
  32. drivers/iio/adc/ad7793.c +105 −39
  33. drivers/iio/adc/ad9467.c +422 −0
  34. drivers/iio/adc/adi-axi-adc.c +482 −0
  35. drivers/iio/adc/at91_adc.c +1 −4
  36. drivers/iio/adc/fsl-imx25-gcq.c +1 −3
  37. drivers/iio/adc/intel_mrfld_adc.c +3 −3
  38. drivers/iio/adc/max1241.c +227 −0
  39. drivers/iio/adc/max1363.c +23 −9
  40. drivers/iio/adc/sun4i-gpadc-iio.c +1 −3
  41. drivers/iio/adc/xilinx-xadc-core.c +2 −2
  42. drivers/iio/adc/xilinx-xadc-events.c +1 −1
  43. drivers/iio/adc/xilinx-xadc.h +1 −1
  44. drivers/iio/buffer/industrialio-buffer-dma.c +0 −1
  45. drivers/iio/buffer/industrialio-buffer-dmaengine.c +40 −1
  46. drivers/iio/buffer/industrialio-hw-consumer.c +0 −31
  47. drivers/iio/buffer/industrialio-triggered-buffer.c +0 −11
  48. drivers/iio/buffer/kfifo_buf.c +0 −22
  49. drivers/iio/chemical/atlas-sensor.c +3 −4
  50. drivers/iio/chemical/bme680_core.c +22 −14
  51. drivers/iio/common/st_sensors/st_sensors_core.c +2 −4
  52. drivers/iio/common/st_sensors/st_sensors_i2c.c +2 −2
  53. drivers/iio/common/st_sensors/st_sensors_spi.c +3 −3
  54. drivers/iio/common/st_sensors/st_sensors_trigger.c +4 −9
  55. drivers/iio/gyro/Kconfig +1 −1
  56. drivers/iio/gyro/bmg160_i2c.c +4 −2
  57. drivers/iio/gyro/bmg160_spi.c +3 −2
  58. drivers/iio/gyro/mpu3050-i2c.c +2 −2
  59. drivers/iio/gyro/st_gyro_buffer.c +1 −2
  60. drivers/iio/gyro/st_gyro_core.c +5 −4
  61. drivers/iio/health/max30100.c +3 −4
  62. drivers/iio/humidity/hts221_buffer.c +2 −4
  63. drivers/iio/humidity/hts221_i2c.c +3 −3
  64. drivers/iio/humidity/hts221_spi.c +3 −3
  65. drivers/iio/imu/adis.c +1 −1
  66. drivers/iio/imu/adis16400.c +10 −9
  67. drivers/iio/imu/adis16460.c +15 −12
  68. drivers/iio/imu/bmi160/bmi160_i2c.c +2 −2
  69. drivers/iio/imu/bmi160/bmi160_spi.c +2 −2
  70. drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c +5 −3
  71. drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +21 −2
  72. drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +2 −2
  73. drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c +2 −2
  74. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +1 −1
  75. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +96 −0
  76. drivers/iio/industrialio-buffer.c +8 −10
  77. drivers/iio/industrialio-core.c +20 −68
  78. drivers/iio/industrialio-trigger.c +0 −53
  79. drivers/iio/inkern.c +0 −27
  80. drivers/iio/light/isl29125.c +19 −9
  81. drivers/iio/light/ltr501.c +1 −1
  82. drivers/iio/light/st_uvis25_i2c.c +2 −2
  83. drivers/iio/light/st_uvis25_spi.c +2 −2
  84. drivers/iio/light/tsl2563.c +1 −1
  85. drivers/iio/light/tsl2772.c +3 −3
  86. drivers/iio/light/vcnl4000.c +25 −0
  87. drivers/iio/magnetometer/ak8974.c +6 −1
  88. drivers/iio/magnetometer/bmc150_magn_spi.c +2 −2
  89. drivers/iio/magnetometer/mmc35240.c +2 −2
  90. drivers/iio/magnetometer/st_magn_core.c +1 −2
  91. drivers/iio/pressure/bmp280-core.c +39 −59
  92. drivers/iio/pressure/st_pressure_core.c +2 −5
  93. drivers/iio/proximity/Kconfig +13 −0
  94. drivers/iio/proximity/Makefile +1 −0
  95. drivers/iio/proximity/sx9310.c +1069 −0
  96. drivers/iio/temperature/ltc2983.c +2 −2
  97. drivers/iio/trigger/iio-trig-hrtimer.c +1 −1
  98. drivers/staging/iio/Documentation/overview.txt +1 −1
  99. include/linux/fpga/adi-axi-common.h +5 −1
  100. include/linux/iio/adc/ad_sigma_delta.h +0 −58
  101. include/linux/iio/adc/adi-axi-adc.h +64 −0
  102. include/linux/iio/buffer-dma.h +1 −1
  103. include/linux/iio/buffer-dmaengine.h +3 −0
  104. include/linux/iio/buffer_impl.h +0 −9
  105. include/linux/iio/consumer.h +0 −18
  106. include/linux/iio/hw-consumer.h +0 −1
  107. include/linux/iio/iio.h +1 −9
  108. include/linux/iio/kfifo_buf.h +0 −1
  109. include/linux/iio/trigger.h +0 −3
  110. include/linux/iio/triggered_buffer.h +0 −2
Documentation/ABI/testing/sysfs-bus-iio-proximity+10−0
@@ -0,0 +1,10 @@
1+What: /sys/bus/iio/devices/iio:deviceX/in_proximity_nearlevel
2+Date: March 2020
3+KernelVersion: 5.7
4+Contact: linux-iio@vger.kernel.org
5+Description:
6+ Near level for proximity sensors. This is a single integer
7+ value that tells user space when an object should be
8+ considered close to the device. If the value read from the
9+ sensor is above or equal to the value in this file an object
10+ should typically be considered near.
Documentation/ABI/testing/sysfs-bus-iio-sx9310+10−0
@@ -0,0 +1,10 @@
1+What: /sys/bus/iio/devices/iio:deviceX/in_proximity3_comb_raw
2+Date: February 2019
3+KernelVersion: 5.6
4+Contact: Daniel Campello <campello@chromium.org>
5+Description:
6+ Proximity measurement indicating that some object is
7+ near the combined sensor. The combined sensor presents
8+ proximity measurements constructed by hardware by
9+ combining measurements taken from a given set of
10+ physical sensors.
Documentation/devicetree/bindings/iio/adc/adi,ad9467.yaml+65−0
@@ -0,0 +1,65 @@
1+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/adc/adi,ad9467.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AD9467 High-Speed ADC
8+
9+maintainers:
10+ - Michael Hennerich <michael.hennerich@analog.com>
11+ - Alexandru Ardelean <alexandru.ardelean@analog.com>
12+
13+description: |
14+ The AD9467 is a 16-bit, monolithic, IF sampling analog-to-digital
15+ converter (ADC).
16+
17+ https://www.analog.com/media/en/technical-documentation/data-sheets/AD9467.pdf
18+
19+properties:
20+ compatible:
21+ enum:
22+ - adi,ad9467
23+
24+ reg:
25+ maxItems: 1
26+
27+ clocks:
28+ maxItems: 1
29+
30+ clock-names:
31+ items:
32+ - const: adc-clk
33+
34+ powerdown-gpios:
35+ description:
36+ Pin that controls the powerdown mode of the device.
37+ maxItems: 1
38+
39+ reset-gpios:
40+ description:
41+ Reset pin for the device.
42+ maxItems: 1
43+
44+required:
45+ - compatible
46+ - reg
47+ - clocks
48+ - clock-names
49+
50+additionalProperties: false
51+
52+examples:
53+ - |
54+ spi {
55+ #address-cells = <1>;
56+ #size-cells = <0>;
57+
58+ adc@0 {
59+ compatible = "adi,ad9467";
60+ reg = <0>;
61+ clocks = <&adc_clk>;
62+ clock-names = "adc-clk";
63+ };
64+ };
65+...
Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml+62−0
@@ -0,0 +1,62 @@
1+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/adc/adi,axi-adc.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Analog Devices AXI ADC IP core
8+
9+maintainers:
10+ - Michael Hennerich <michael.hennerich@analog.com>
11+ - Alexandru Ardelean <alexandru.ardelean@analog.com>
12+
13+description: |
14+ Analog Devices Generic AXI ADC IP core for interfacing an ADC device
15+ with a high speed serial (JESD204B/C) or source synchronous parallel
16+ interface (LVDS/CMOS).
17+ Usually, some other interface type (i.e SPI) is used as a control
18+ interface for the actual ADC, while this IP core will interface
19+ to the data-lines of the ADC and handle the streaming of data into
20+ memory via DMA.
21+
22+ https://wiki.analog.com/resources/fpga/docs/axi_adc_ip
23+
24+properties:
25+ compatible:
26+ enum:
27+ - adi,axi-adc-10.0.a
28+
29+ reg:
30+ maxItems: 1
31+
32+ dmas:
33+ maxItems: 1
34+
35+ dma-names:
36+ items:
37+ - const: rx
38+
39+ adi,adc-dev:
40+ $ref: /schemas/types.yaml#/definitions/phandle
41+ description:
42+ A reference to a the actual ADC to which this FPGA ADC interfaces to.
43+
44+required:
45+ - compatible
46+ - dmas
47+ - reg
48+ - adi,adc-dev
49+
50+additionalProperties: false
51+
52+examples:
53+ - |
54+ axi-adc@44a00000 {
55+ compatible = "adi,axi-adc-10.0.a";
56+ reg = <0x44a00000 0x10000>;
57+ dmas = <&rx_dma 0>;
58+ dma-names = "rx";
59+
60+ adi,adc-dev = <&spi_adc>;
61+ };
62+...
Documentation/devicetree/bindings/iio/adc/maxim,max1241.yaml+63−0
@@ -0,0 +1,63 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+# Copyright 2020 Alexandru Lazar
3+%YAML 1.2
4+---
5+$id: http://devicetree.org/schemas/iio/adc/maxim,max1241.yaml#
6+$schema: http://devicetree.org/meta-schemas/core.yaml#
7+
8+title: Maxim MAX1241 12-bit, single-channel analog to digital converter
9+
10+maintainers:
11+ - Alexandru Lazar <alazar@startmail.com>
12+
13+description: |
14+ Bindings for the max1241 12-bit, single-channel ADC device. Datasheet
15+ can be found at:
16+ https://datasheets.maximintegrated.com/en/ds/MAX1240-MAX1241.pdf
17+
18+properties:
19+ compatible:
20+ enum:
21+ - maxim,max1241
22+
23+ reg:
24+ maxItems: 1
25+
26+ vdd-supply:
27+ description:
28+ Device tree identifier of the regulator that powers the ADC.
29+
30+ vref-supply:
31+ description:
32+ Device tree identifier of the regulator that provides the external
33+ reference voltage.
34+
35+ shutdown-gpios:
36+ description:
37+ GPIO spec for the GPIO pin connected to the ADC's /SHDN pin. If
38+ specified, the /SHDN pin will be asserted between conversions,
39+ thus enabling power-down mode.
40+ maxItems: 1
41+
42+required:
43+ - compatible
44+ - reg
45+ - vdd-supply
46+ - vref-supply
47+
48+examples:
49+ - |
50+ #include <dt-bindings/gpio/gpio.h>
51+ spi {
52+ #address-cells = <1>;
53+ #size-cells = <0>;
54+
55+ adc@0 {
56+ compatible = "maxim,max1241";
57+ reg = <0>;
58+ vdd-supply = <&adc_vdd>;
59+ vref-supply = <&adc_vref>;
60+ spi-max-frequency = <1000000>;
61+ shutdown-gpios = <&gpio 26 1>;
62+ };
63+ };
Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt+0−37
@@ -1,37 +0,0 @@
1−Rockchip Successive Approximation Register (SAR) A/D Converter bindings
2−
3−Required properties:
4−- compatible: should be "rockchip,<name>-saradc" or "rockchip,rk3066-tsadc"
5− - "rockchip,saradc": for rk3188, rk3288
6− - "rockchip,rk3066-tsadc": for rk3036
7− - "rockchip,rk3328-saradc", "rockchip,rk3399-saradc": for rk3328
8− - "rockchip,rk3399-saradc": for rk3399
9− - "rockchip,rv1108-saradc", "rockchip,rk3399-saradc": for rv1108
10−
11−- reg: physical base address of the controller and length of memory mapped
12− region.
13−- interrupts: The interrupt number to the cpu. The interrupt specifier format
14− depends on the interrupt controller.
15−- clocks: Must contain an entry for each entry in clock-names.
16−- clock-names: Shall be "saradc" for the converter-clock, and "apb_pclk" for
17− the peripheral clock.
18−- vref-supply: The regulator supply ADC reference voltage.
19−- #io-channel-cells: Should be 1, see ../iio-bindings.txt
20−
21−Optional properties:
22−- resets: Must contain an entry for each entry in reset-names if need support
23− this option. See ../reset/reset.txt for details.
24−- reset-names: Must include the name "saradc-apb".
25−
26−Example:
27− saradc: saradc@2006c000 {
28− compatible = "rockchip,saradc";
29− reg = <0x2006c000 0x100>;
30− interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
31− clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>;
32− clock-names = "saradc", "apb_pclk";
33− resets = <&cru SRST_SARADC>;
34− reset-names = "saradc-apb";
35− #io-channel-cells = <1>;
36− vref-supply = <&vcc18>;
37− };
Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml+80−0
@@ -0,0 +1,80 @@
1+# SPDX-License-Identifier: GPL-2.0
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/adc/rockchip-saradc.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Rockchip Successive Approximation Register (SAR) A/D Converter
8+
9+maintainers:
10+ - Heiko Stuebner <heiko@sntech.de>
11+
12+properties:
13+ compatible:
14+ oneOf:
15+ - const: rockchip,saradc
16+ - const: rockchip,rk3066-tsadc
17+ - const: rockchip,rk3399-saradc
18+ - items:
19+ - enum:
20+ - rockchip,px30-saradc
21+ - rockchip,rk3308-saradc
22+ - rockchip,rk3328-saradc
23+ - rockchip,rv1108-saradc
24+ - const: rockchip,rk3399-saradc
25+
26+ reg:
27+ maxItems: 1
28+
29+ interrupts:
30+ maxItems: 1
31+
32+ clocks:
33+ items:
34+ - description: converter clock
35+ - description: peripheral clock
36+
37+ clock-names:
38+ items:
39+ - const: saradc
40+ - const: apb_pclk
41+
42+ resets:
43+ maxItems: 1
44+
45+ reset-names:
46+ const: saradc-apb
47+
48+ vref-supply:
49+ description:
50+ The regulator supply for the ADC reference voltage.
51+
52+ "#io-channel-cells":
53+ const: 1
54+
55+required:
56+ - compatible
57+ - reg
58+ - interrupts
59+ - clocks
60+ - clock-names
61+ - vref-supply
62+ - "#io-channel-cells"
63+
64+additionalProperties: false
65+
66+examples:
67+ - |
68+ #include <dt-bindings/clock/rk3288-cru.h>
69+ #include <dt-bindings/interrupt-controller/arm-gic.h>
70+ saradc: saradc@2006c000 {
71+ compatible = "rockchip,saradc";
72+ reg = <0x2006c000 0x100>;
73+ interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
74+ clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>;
75+ clock-names = "saradc", "apb_pclk";
76+ resets = <&cru SRST_SARADC>;
77+ reset-names = "saradc-apb";
78+ vref-supply = <&vcc18>;
79+ #io-channel-cells = <1>;
80+ };
Documentation/devicetree/bindings/iio/common.yaml+35−0
@@ -0,0 +1,35 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/common.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Common properties for iio sensors
8+
9+maintainers:
10+ - Jonathan Cameron <jic23@kernel.org>
11+ - Guido Günther <agx@sigxcpu.org>
12+
13+description: |
14+ This document defines device tree properties common to several iio
15+ sensors. It doesn't constitue a device tree binding specification by itself but
16+ is meant to be referenced by device tree bindings.
17+
18+ When referenced from sensor tree bindings the properties defined in this
19+ document are defined as follows. The sensor tree bindings are responsible for
20+ defining whether each property is required or optional.
21+
22+properties:
23+ proximity-near-level:
24+ $ref: /schemas/types.yaml#/definitions/uint32
25+ description: |
26+ For proximity sensors whether an object can be considered near to the
27+ device depends on parameters like sensor position, covering glass and
28+ aperture. This value gives an indication to userspace for which
29+ sensor readings this is the case.
30+
31+ Raw proximity values equal or above this level should be
32+ considered 'near' to the device (an object is near to the
33+ sensor).
34+
35+...
Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt+0−63
@@ -1,63 +0,0 @@
1−STMicroelectronics STM32 DAC
2−
3−The STM32 DAC is a 12-bit voltage output digital-to-analog converter. The DAC
4−may be configured in 8 or 12-bit mode. It has two output channels, each with
5−its own converter.
6−It has built-in noise and triangle waveform generator and supports external
7−triggers for conversions. The DAC's output buffer allows a high drive output
8−current.
9−
10−Contents of a stm32 dac root node:
11−-----------------------------------
12−Required properties:
13−- compatible: Should be one of:
14− "st,stm32f4-dac-core"
15− "st,stm32h7-dac-core"
16−- reg: Offset and length of the device's register set.
17−- clocks: Must contain an entry for pclk (which feeds the peripheral bus
18− interface)
19−- clock-names: Must be "pclk".
20−- vref-supply: Phandle to the vref+ input analog reference supply.
21−- #address-cells = <1>;
22−- #size-cells = <0>;
23−
24−Optional properties:
25−- resets: Must contain the phandle to the reset controller.
26−- A pinctrl state named "default" for each DAC channel may be defined to set
27− DAC_OUTx pin in mode of operation for analog output on external pin.
28−
29−Contents of a stm32 dac child node:
30−-----------------------------------
31−DAC core node should contain at least one subnode, representing a
32−DAC instance/channel available on the machine.
33−
34−Required properties:
35−- compatible: Must be "st,stm32-dac".
36−- reg: Must be either 1 or 2, to define (single) channel in use
37−- #io-channel-cells = <1>: See the IIO bindings section "IIO consumers" in
38− Documentation/devicetree/bindings/iio/iio-bindings.txt
39−
40−Example:
41− dac: dac@40007400 {
42− compatible = "st,stm32h7-dac-core";
43− reg = <0x40007400 0x400>;
44− clocks = <&clk>;
45− clock-names = "pclk";
46− vref-supply = <&reg_vref>;
47− pinctrl-names = "default";
48− pinctrl-0 = <&dac_out1 &dac_out2>;
49− #address-cells = <1>;
50− #size-cells = <0>;
51−
52− dac1: dac@1 {
53− compatible = "st,stm32-dac";
54− #io-channels-cells = <1>;
55− reg = <1>;
56− };
57−
58− dac2: dac@2 {
59− compatible = "st,stm32-dac";
60− #io-channels-cells = <1>;
61− reg = <2>;
62− };
63− };
Documentation/devicetree/bindings/iio/dac/st,stm32-dac.yaml+110−0
@@ -0,0 +1,110 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: "http://devicetree.org/schemas/iio/dac/st,stm32-dac.yaml#"
5+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
6+
7+title: STMicroelectronics STM32 DAC bindings
8+
9+description: |
10+ The STM32 DAC is a 12-bit voltage output digital-to-analog converter. The DAC
11+ may be configured in 8 or 12-bit mode. It has two output channels, each with
12+ its own converter.
13+ It has built-in noise and triangle waveform generator and supports external
14+ triggers for conversions. The DAC's output buffer allows a high drive output
15+ current.
16+
17+maintainers:
18+ - Fabrice Gasnier <fabrice.gasnier@st.com>
19+
20+properties:
21+ compatible:
22+ enum:
23+ - st,stm32f4-dac-core
24+ - st,stm32h7-dac-core
25+
26+ reg:
27+ maxItems: 1
28+
29+ resets:
30+ maxItems: 1
31+
32+ clocks:
33+ maxItems: 1
34+
35+ clock-names:
36+ items:
37+ - const: pclk
38+
39+ vref-supply:
40+ description: Phandle to the vref input analog reference voltage.
41+
42+ '#address-cells':
43+ const: 1
44+
45+ '#size-cells':
46+ const: 0
47+
48+additionalProperties: false
49+
50+required:
51+ - compatible
52+ - reg
53+ - clocks
54+ - clock-names
55+ - vref-supply
56+ - '#address-cells'
57+ - '#size-cells'
58+
59+patternProperties:
60+ "^dac@[1-2]+$":
61+ type: object
62+ description:
63+ A DAC block node should contain at least one subnode, representing an
64+ DAC instance/channel available on the machine.
65+
66+ properties:
67+ compatible:
68+ const: st,stm32-dac
69+
70+ reg:
71+ description: Must be either 1 or 2, to define (single) channel in use
72+ enum: [1, 2]
73+
74+ '#io-channel-cells':
75+ const: 1
76+
77+ additionalProperties: false
78+
79+ required:
80+ - compatible
81+ - reg
82+ - '#io-channel-cells'
83+
84+examples:
85+ - |
86+ // Example on stm32mp157c
87+ #include <dt-bindings/clock/stm32mp1-clks.h>
88+ dac: dac@40017000 {
89+ compatible = "st,stm32h7-dac-core";
90+ reg = <0x40017000 0x400>;
91+ clocks = <&rcc DAC12>;
92+ clock-names = "pclk";
93+ vref-supply = <&vref>;
94+ #address-cells = <1>;
95+ #size-cells = <0>;
96+
97+ dac@1 {
98+ compatible = "st,stm32-dac";
99+ #io-channel-cells = <1>;
100+ reg = <1>;
101+ };
102+
103+ dac@2 {
104+ compatible = "st,stm32-dac";
105+ #io-channel-cells = <1>;
106+ reg = <2>;
107+ };
108+ };
109+
110+...
Documentation/devicetree/bindings/iio/gyroscope/bmg160.txt+1−1
@@ -2,7 +2,7 @@ · 1 unmodified line
22
33 Required properties:
44
5− - compatible : should be "bosch,bmg160" or "bosch,bmi055_gyro"
5+ - compatible : should be "bosch,bmg160", "bosch,bmi055_gyro" or "bosch,bmi088_gyro"
66 - reg : the I2C address of the sensor (0x69)
77
88 Optional properties:
Documentation/devicetree/bindings/iio/light/amstaos,tsl2563.yaml+49−0
@@ -0,0 +1,49 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/light/amstaos,tsl2563.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: AMS TAOS TSL2563 ambient light sensor
8+
9+maintainers:
10+ - Sebastian Reichel <sre@kernel.org>
11+
12+description: |
13+ Ambient light sensor with an i2c interface.
14+
15+properties:
16+ compatible:
17+ enum:
18+ - amstaos,tsl2560
19+ - amstaos,tsl2561
20+ - amstaos,tsl2562
21+ - amstaos,tsl2563
22+
23+ reg:
24+ maxItems: 1
25+
26+ amstaos,cover-comp-gain:
27+ description: Multiplier for gain compensation
28+ allOf:
29+ - $ref: /schemas/types.yaml#/definitions/uint32
30+ - enum: [1, 16]
31+
32+required:
33+ - compatible
34+ - reg
35+
36+examples:
37+ - |
38+ i2c {
39+
40+ #address-cells = <1>;
41+ #size-cells = <0>;
42+
43+ light-sensor@29 {
44+ compatible = "amstaos,tsl2563";
45+ reg = <0x29>;
46+ amstaos,cover-comp-gain = <16>;
47+ };
48+ };
49+...
Documentation/devicetree/bindings/iio/light/tsl2563.txt+0−19
@@ -1,19 +0,0 @@
1−* AMS TAOS TSL2563 ambient light sensor
2−
3−Required properties:
4−
5− - compatible : should be "amstaos,tsl2563"
6− - reg : the I2C address of the sensor
7−
8−Optional properties:
9−
10− - amstaos,cover-comp-gain : integer used as multiplier for gain
11− compensation (default = 1)
12−
13−Example:
14−
15−tsl2563@29 {
16− compatible = "amstaos,tsl2563";
17− reg = <0x29>;
18− amstaos,cover-comp-gain = <16>;
19−};
Documentation/devicetree/bindings/iio/light/vcnl4000.txt+0−24
@@ -1,24 +0,0 @@
1−VISHAY VCNL4000 - Ambient Light and proximity sensor
2−
3−This driver supports the VCNL4000/10/20/40 and VCNL4200 chips
4−
5−Required properties:
6−
7− -compatible: must be one of :
8− vishay,vcnl4000
9− vishay,vcnl4010
10− vishay,vcnl4020
11− vishay,vcnl4040
12− vishay,vcnl4200
13−
14− -reg: I2C address of the sensor, should be one from below based on the model:
15− 0x13
16− 0x51
17− 0x60
18−
19−Example:
20−
21−light-sensor@51 {
22− compatible = "vishay,vcnl4200";
23− reg = <0x51>;
24−};
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml+50−0
@@ -0,0 +1,50 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/light/vishay,vcnl4000.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: VISHAY VCNL4000 ambient light and proximity sensor
8+
9+maintainers:
10+ - Peter Meerwald <pmeerw@pmeerw.net>
11+
12+description: |
13+ Ambient light sensing with proximity detection over an i2c
14+ interface.
15+
16+allOf:
17+ - $ref: ../common.yaml#
18+
19+properties:
20+ compatible:
21+ enum:
22+ - vishay,vcnl4000
23+ - vishay,vcnl4010
24+ - vishay,vcnl4020
25+ - vishay,vcnl4040
26+ - vishay,vcnl4200
27+ reg:
28+ maxItems: 1
29+
30+ proximity-near-level: true
31+
32+required:
33+ - compatible
34+ - reg
35+
36+additionalProperties: false
37+
38+examples:
39+- |
40+ i2c {
41+ #address-cells = <1>;
42+ #size-cells = <0>;
43+
44+ light-sensor@51 {
45+ compatible = "vishay,vcnl4200";
46+ reg = <0x51>;
47+ proximity-near-level = <220>;
48+ };
49+ };
50+...
Documentation/devicetree/bindings/iio/st-sensors.txt+1−0
@@ -50,6 +50,7 @@ Accelerometers: · 49 unmodified lines
5050 - st,lis3dhh
5151 - st,lis3de
5252 - st,lis2de12
53+- st,lis2hh12
5354
5455 Gyroscopes:
5556 - st,l3g4200d-gyro
Documentation/driver-api/driver-model/devres.rst+0−8
@@ -284,21 +284,13 @@ I2C · 283 unmodified lines
284284
285285 IIO
286286 devm_iio_device_alloc()
287− devm_iio_device_free()
288287 devm_iio_device_register()
289− devm_iio_device_unregister()
290288 devm_iio_kfifo_allocate()
291− devm_iio_kfifo_free()
292289 devm_iio_triggered_buffer_setup()
293− devm_iio_triggered_buffer_cleanup()
294290 devm_iio_trigger_alloc()
295− devm_iio_trigger_free()
296291 devm_iio_trigger_register()
297− devm_iio_trigger_unregister()
298292 devm_iio_channel_get()
299− devm_iio_channel_release()
300293 devm_iio_channel_get_all()
301− devm_iio_channel_release_all()
302294
303295 INPUT
304296 devm_input_allocate_device()
Documentation/driver-api/iio/triggers.rst+0−2
@@ -4,9 +4,7 @@ Triggers · 3 unmodified lines
44
55 * struct :c:type:`iio_trigger` — industrial I/O trigger device
66 * :c:func:`devm_iio_trigger_alloc` — Resource-managed iio_trigger_alloc
7−* :c:func:`devm_iio_trigger_free` — Resource-managed iio_trigger_free
87 * :c:func:`devm_iio_trigger_register` — Resource-managed iio_trigger_register
9−* :c:func:`devm_iio_trigger_unregister` — Resource-managed
108 iio_trigger_unregister
119 * :c:func:`iio_trigger_validate_own_device` — Check if a trigger and IIO
1210 device belong to the same device
MAINTAINERS+1−0
@@ -294,6 +294,7 @@ F: drivers/gpio/gpio-104-idio-16.c · 293 unmodified lines
294294
295295 ACCES 104-QUAD-8 DRIVER
296296 M: William Breathitt Gray <vilhelm.gray@gmail.com>
297+M: Syed Nayyar Waris <syednwaris@gmail.com>
297298 L: linux-iio@vger.kernel.org
298299 S: Maintained
299300 F: Documentation/ABI/testing/sysfs-bus-counter-104-quad-8
drivers/iio/accel/Kconfig+1−1
@@ -238,7 +238,7 @@ config IIO_ST_ACCEL_3AXIS · 237 unmodified lines
238238 Say yes here to build support for STMicroelectronics accelerometers:
239239 LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC,
240240 LIS331DLH, LSM303DL, LSM303DLM, LSM330, LIS2DH12, H3LIS331DL,
241− LNG2DM, LIS3DE, LIS2DE12
241+ LNG2DM, LIS3DE, LIS2DE12, LIS2HH12
242242
243243 This driver can also be built as a module. If so, these modules
244244 will be created:
drivers/iio/accel/kxsd9-i2c.c+2−2
@@ -21,8 +21,8 @@ static int kxsd9_i2c_probe(struct i2c_client *i2c, · 20 unmodified lines
2121
2222 regmap = devm_regmap_init_i2c(i2c, &config);
2323 if (IS_ERR(regmap)) {
24− dev_err(&i2c->dev, "Failed to register i2c regmap %d\n",
25− (int)PTR_ERR(regmap));
24+ dev_err(&i2c->dev, "Failed to register i2c regmap: %pe\n",
25+ regmap);
2626 return PTR_ERR(regmap);
2727 }
2828
drivers/iio/accel/mxc4005.c+2−2
@@ -135,7 +135,7 @@ static int mxc4005_read_xyz(struct mxc4005_data *data) · 134 unmodified lines
135135 int ret;
136136
137137 ret = regmap_bulk_read(data->regmap, MXC4005_REG_XOUT_UPPER,
138− (u8 *) data->buffer, sizeof(data->buffer));
138+ data->buffer, sizeof(data->buffer));
139139 if (ret < 0) {
140140 dev_err(data->dev, "failed to read axes\n");
141141 return ret;
@@ -150,7 +150,7 @@ static int mxc4005_read_axis(struct mxc4005_data *data, · 8 unmodified lines
150150 __be16 reg;
151151 int ret;
152152
153− ret = regmap_bulk_read(data->regmap, addr, (u8 *) &reg, sizeof(reg));
153+ ret = regmap_bulk_read(data->regmap, addr, &reg, sizeof(reg));
154154 if (ret < 0) {
155155 dev_err(data->dev, "failed to read reg %02x\n", addr);
156156 return ret;
drivers/iio/accel/st_accel.h+2−0
@@ -35,6 +35,7 @@ enum st_accel_type { · 34 unmodified lines
3535 LIS2DW12,
3636 LIS3DHH,
3737 LIS2DE12,
38+ LIS2HH12,
3839 ST_ACCEL_MAX,
3940 };
4041
@@ -59,6 +60,7 @@ enum st_accel_type { · 18 unmodified lines
5960 #define LIS3DHH_ACCEL_DEV_NAME "lis3dhh"
6061 #define LIS3DE_ACCEL_DEV_NAME "lis3de"
6162 #define LIS2DE12_ACCEL_DEV_NAME "lis2de12"
63+#define LIS2HH12_ACCEL_DEV_NAME "lis2hh12"
6264
6365 /**
6466 * struct st_sensors_platform_data - default accel platform data
drivers/iio/accel/st_accel_buffer.c+1−2
@@ -37,8 +37,7 @@ static int st_accel_buffer_postenable(struct iio_dev *indio_dev) · 36 unmodified lines
3737 if (err < 0)
3838 return err;
3939
40− err = st_sensors_set_axis_enable(indio_dev,
41− (u8)indio_dev->active_scan_mask[0]);
40+ err = st_sensors_set_axis_enable(indio_dev, indio_dev->active_scan_mask[0]);
4241 if (err < 0)
4342 goto st_accel_buffer_predisable;
4443
drivers/iio/accel/st_accel_core.c+79−4
@@ -904,6 +904,83 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { · 903 unmodified lines
904904 .multi_read_bit = true,
905905 .bootime = 2,
906906 },
907+ {
908+ .wai = 0x41,
909+ .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
910+ .sensors_supported = {
911+ [0] = LIS2HH12_ACCEL_DEV_NAME,
912+ },
913+ .ch = (struct iio_chan_spec *)st_accel_16bit_channels,
914+ .odr = {
915+ .addr = 0x20,
916+ .mask = 0x70,
917+ .odr_avl = {
918+ { .hz = 10, .value = 0x01, },
919+ { .hz = 50, .value = 0x02, },
920+ { .hz = 100, .value = 0x03, },
921+ { .hz = 200, .value = 0x04, },
922+ { .hz = 400, .value = 0x05, },
923+ { .hz = 800, .value = 0x06, },
924+ },
925+ },
926+ .pw = {
927+ .addr = 0x20,
928+ .mask = 0x70,
929+ .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
930+ },
931+ .enable_axis = {
932+ .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
933+ .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
934+ },
935+ .fs = {
936+ .addr = 0x23,
937+ .mask = 0x30,
938+ .fs_avl = {
939+ [0] = {
940+ .num = ST_ACCEL_FS_AVL_2G,
941+ .value = 0x00,
942+ .gain = IIO_G_TO_M_S_2(61),
943+ },
944+ [1] = {
945+ .num = ST_ACCEL_FS_AVL_4G,
946+ .value = 0x02,
947+ .gain = IIO_G_TO_M_S_2(122),
948+ },
949+ [2] = {
950+ .num = ST_ACCEL_FS_AVL_8G,
951+ .value = 0x03,
952+ .gain = IIO_G_TO_M_S_2(244),
953+ },
954+ },
955+ },
956+ .bdu = {
957+ .addr = 0x20,
958+ .mask = 0x08,
959+ },
960+ .drdy_irq = {
961+ .int1 = {
962+ .addr = 0x22,
963+ .mask = 0x01,
964+ },
965+ .int2 = {
966+ .addr = 0x25,
967+ .mask = 0x01,
968+ },
969+ .addr_ihl = 0x24,
970+ .mask_ihl = 0x02,
971+ .stat_drdy = {
972+ .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
973+ .mask = 0x07,
974+ },
975+ },
976+ .sim = {
977+ .addr = 0x23,
978+ .value = BIT(0),
979+ },
980+ .multi_read_bit = true,
981+ .bootime = 2,
982+ },
983+
907984 };
908985
909986 static int st_accel_read_raw(struct iio_dev *indio_dev,
@@ -1170,8 +1247,7 @@ EXPORT_SYMBOL(st_accel_get_settings); · 260 unmodified lines
11701247 int st_accel_common_probe(struct iio_dev *indio_dev)
11711248 {
11721249 struct st_sensor_data *adata = iio_priv(indio_dev);
1173− struct st_sensors_platform_data *pdata =
1174− (struct st_sensors_platform_data *)adata->dev->platform_data;
1250+ struct st_sensors_platform_data *pdata = dev_get_platdata(adata->dev);
11751251 struct iio_chan_spec *channels;
11761252 size_t channels_size;
11771253 int err;
@@ -1204,8 +1280,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev) · 26 unmodified lines
12041280 "failed to apply ACPI orientation data: %d\n", err);
12051281
12061282 indio_dev->channels = channels;
1207− adata->current_fullscale = (struct st_sensor_fullscale_avl *)
1208− &adata->sensor_settings->fs.fs_avl[0];
1283+ adata->current_fullscale = &adata->sensor_settings->fs.fs_avl[0];
12091284 adata->odr = adata->sensor_settings->odr.odr_avl[0].hz;
12101285
12111286 if (!pdata)
drivers/iio/accel/st_accel_i2c.c+5−0
@@ -104,6 +104,10 @@ static const struct of_device_id st_accel_of_match[] = { · 103 unmodified lines
104104 .compatible = "st,lis2de12",
105105 .data = LIS2DE12_ACCEL_DEV_NAME,
106106 },
107+ {
108+ .compatible = "st,lis2hh12",
109+ .data = LIS2HH12_ACCEL_DEV_NAME,
110+ },
107111 {},
108112 };
109113 MODULE_DEVICE_TABLE(of, st_accel_of_match);
@@ -138,6 +142,7 @@ static const struct i2c_device_id st_accel_id_table[] = { · 28 unmodified lines
138142 { LIS2DW12_ACCEL_DEV_NAME },
139143 { LIS3DE_ACCEL_DEV_NAME },
140144 { LIS2DE12_ACCEL_DEV_NAME },
145+ { LIS2HH12_ACCEL_DEV_NAME },
141146 {},
142147 };
143148 MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
drivers/iio/adc/Kconfig+45−0
@@ -246,6 +246,41 @@ config AD799X · 245 unmodified lines
246246 To compile this driver as a module, choose M here: the module will be
247247 called ad799x.
248248
249+config AD9467
250+ tristate "Analog Devices AD9467 High Speed ADC driver"
251+ depends on SPI
252+ select ADI_AXI_ADC
253+ help
254+ Say yes here to build support for Analog Devices:
255+ * AD9467 16-Bit, 200 MSPS/250 MSPS Analog-to-Digital Converter
256+
257+ The driver requires the assistance of the AXI ADC IP core to operate,
258+ since SPI is used for configuration only, while data has to be
259+ streamed into memory via DMA.
260+
261+ To compile this driver as a module, choose M here: the module will be
262+ called ad9467.
263+
264+config ADI_AXI_ADC
265+ tristate "Analog Devices Generic AXI ADC IP core driver"
266+ select IIO_BUFFER
267+ select IIO_BUFFER_HW_CONSUMER
268+ select IIO_BUFFER_DMAENGINE
269+ help
270+ Say yes here to build support for Analog Devices Generic
271+ AXI ADC IP core. The IP core is used for interfacing with
272+ analog-to-digital (ADC) converters that require either a high-speed
273+ serial interface (JESD204B/C) or a source synchronous parallel
274+ interface (LVDS/CMOS).
275+ Typically (for such devices) SPI will be used for configuration only,
276+ while this IP core handles the streaming of data into memory via DMA.
277+
278+ Link: https://wiki.analog.com/resources/fpga/docs/axi_adc_ip
279+ If unsure, say N (but it's safe to say "Y").
280+
281+ To compile this driver as a module, choose M here: the
282+ module will be called adi-axi-adc.
283+
249284 config ASPEED_ADC
250285 tristate "Aspeed ADC"
251286 depends on ARCH_ASPEED || COMPILE_TEST
@@ -595,6 +630,16 @@ config MAX1118 · 343 unmodified lines
595630 To compile this driver as a module, choose M here: the module will be
596631 called max1118.
597632
633+config MAX1241
634+ tristate "Maxim max1241 ADC driver"
635+ depends on SPI_MASTER
636+ help
637+ Say yes here to build support for Maxim max1241 12-bit, single-channel
638+ ADC.
639+
640+ To compile this driver as a module, choose M here: the module will be
641+ called max1241.
642+
598643 config MAX1363
599644 tristate "Maxim max1363 ADC driver"
600645 depends on I2C
drivers/iio/adc/Makefile+3−0
@@ -26,6 +26,8 @@ obj-$(CONFIG_AD7793) += ad7793.o · 25 unmodified lines
2626 obj-$(CONFIG_AD7887) += ad7887.o
2727 obj-$(CONFIG_AD7949) += ad7949.o
2828 obj-$(CONFIG_AD799X) += ad799x.o
29+obj-$(CONFIG_AD9467) += ad9467.o
30+obj-$(CONFIG_ADI_AXI_ADC) += adi-axi-adc.o
2931 obj-$(CONFIG_ASPEED_ADC) += aspeed_adc.o
3032 obj-$(CONFIG_AT91_ADC) += at91_adc.o
3133 obj-$(CONFIG_AT91_SAMA5D2_ADC) += at91-sama5d2_adc.o
@@ -57,6 +59,7 @@ obj-$(CONFIG_LTC2497) += ltc2497.o ltc2497-core.o · 25 unmodified lines
5759 obj-$(CONFIG_MAX1027) += max1027.o
5860 obj-$(CONFIG_MAX11100) += max11100.o
5961 obj-$(CONFIG_MAX1118) += max1118.o
62+obj-$(CONFIG_MAX1241) += max1241.o
6063 obj-$(CONFIG_MAX1363) += max1363.o
6164 obj-$(CONFIG_MAX9611) += max9611.o
6265 obj-$(CONFIG_MCP320X) += mcp320x.o
drivers/iio/adc/ad7476.c+46−13
@@ -12,9 +12,11 @@ · 11 unmodified lines
1212 #include <linux/sysfs.h>
1313 #include <linux/spi/spi.h>
1414 #include <linux/regulator/consumer.h>
15+#include <linux/gpio/consumer.h>
1516 #include <linux/err.h>
1617 #include <linux/module.h>
1718 #include <linux/bitops.h>
19+#include <linux/delay.h>
1820
1921 #include <linux/iio/iio.h>
2022 #include <linux/iio/sysfs.h>
@@ -27,6 +29,8 @@ struct ad7476_state; · 6 unmodified lines
2729 struct ad7476_chip_info {
2830 unsigned int int_vref_uv;
2931 struct iio_chan_spec channel[2];
32+ /* channels used when convst gpio is defined */
33+ struct iio_chan_spec convst_channel[2];
3034 void (*reset)(struct ad7476_state *);
3135 };
3236
@@ -34,6 +38,7 @@ struct ad7476_state { · 1 unmodified line
3438 struct spi_device *spi;
3539 const struct ad7476_chip_info *chip_info;
3640 struct regulator *reg;
41+ struct gpio_desc *convst_gpio;
3742 struct spi_transfer xfer;
3843 struct spi_message msg;
3944 /*
@@ -64,6 +69,17 @@ enum ad7476_supported_device_ids { · 24 unmodified lines
6469 ID_ADS7868,
6570 };
6671
72+static void ad7091_convst(struct ad7476_state *st)
73+{
74+ if (!st->convst_gpio)
75+ return;
76+
77+ gpiod_set_value(st->convst_gpio, 0);
78+ udelay(1); /* CONVST pulse width: 10 ns min */
79+ gpiod_set_value(st->convst_gpio, 1);
80+ udelay(1); /* Conversion time: 650 ns max */
81+}
82+
6783 static irqreturn_t ad7476_trigger_handler(int irq, void *p)
6884 {
6985 struct iio_poll_func *pf = p;
@@ -71,6 +87,8 @@ static irqreturn_t ad7476_trigger_handler(int irq, void *p) · 1 unmodified line
7187 struct ad7476_state *st = iio_priv(indio_dev);
7288 int b_sent;
7389
90+ ad7091_convst(st);
91+
7492 b_sent = spi_sync(st->spi, &st->msg);
7593 if (b_sent < 0)
7694 goto done;
@@ -93,6 +111,8 @@ static int ad7476_scan_direct(struct ad7476_state *st) · 16 unmodified lines
93111 {
94112 int ret;
95113
114+ ad7091_convst(st);
115+
96116 ret = spi_sync(st->spi, &st->msg);
97117 if (ret)
98118 return ret;
@@ -160,6 +180,8 @@ static int ad7476_read_raw(struct iio_dev *indio_dev, · 61 unmodified lines
160180 #define AD7940_CHAN(bits) _AD7476_CHAN((bits), 15 - (bits), \
161181 BIT(IIO_CHAN_INFO_RAW))
162182 #define AD7091R_CHAN(bits) _AD7476_CHAN((bits), 16 - (bits), 0)
183+#define AD7091R_CONVST_CHAN(bits) _AD7476_CHAN((bits), 16 - (bits), \
184+ BIT(IIO_CHAN_INFO_RAW))
163185 #define ADS786X_CHAN(bits) _AD7476_CHAN((bits), 12 - (bits), \
164186 BIT(IIO_CHAN_INFO_RAW))
165187
@@ -167,6 +189,8 @@ static const struct ad7476_chip_info ad7476_chip_info_tbl[] = { · 1 unmodified line
167189 [ID_AD7091R] = {
168190 .channel[0] = AD7091R_CHAN(12),
169191 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
192+ .convst_channel[0] = AD7091R_CONVST_CHAN(12),
193+ .convst_channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
170194 .reset = ad7091_reset,
171195 },
172196 [ID_AD7276] = {
@@ -232,6 +256,13 @@ static const struct iio_info ad7476_info = { · 59 unmodified lines
232256 .read_raw = &ad7476_read_raw,
233257 };
234258
259+static void ad7476_reg_disable(void *data)
260+{
261+ struct ad7476_state *st = data;
262+
263+ regulator_disable(st->reg);
264+}
265+
235266 static int ad7476_probe(struct spi_device *spi)
236267 {
237268 struct ad7476_state *st;
@@ -254,6 +285,17 @@ static int ad7476_probe(struct spi_device *spi) · 16 unmodified lines
254285 if (ret)
255286 return ret;
256287
288+ ret = devm_add_action_or_reset(&spi->dev, ad7476_reg_disable,
289+ st);
290+ if (ret)
291+ return ret;
292+
293+ st->convst_gpio = devm_gpiod_get_optional(&spi->dev,
294+ "adi,conversion-start",
295+ GPIOD_OUT_LOW);
296+ if (IS_ERR(st->convst_gpio))
297+ return PTR_ERR(st->convst_gpio);
298+
257299 spi_set_drvdata(spi, indio_dev);
258300
259301 st->spi = spi;
@@ -266,6 +308,9 @@ static int ad7476_probe(struct spi_device *spi) · 6 unmodified lines
266308 indio_dev->channels = st->chip_info->channel;
267309 indio_dev->num_channels = 2;
268310 indio_dev->info = &ad7476_info;
311+
312+ if (st->convst_gpio && st->chip_info->convst_channel)
313+ indio_dev->channels = st->chip_info->convst_channel;
269314 /* Setup default message */
270315
271316 st->xfer.rx_buf = &st->data;
@@ -295,19 +340,8 @@ error_disable_reg: · 23 unmodified lines
295340 return ret;
296341 }
297342
298−static int ad7476_remove(struct spi_device *spi)
299−{
300− struct iio_dev *indio_dev = spi_get_drvdata(spi);
301− struct ad7476_state *st = iio_priv(indio_dev);
302−
303− iio_device_unregister(indio_dev);
304− iio_triggered_buffer_cleanup(indio_dev);
305− regulator_disable(st->reg);
306−
307− return 0;
308−}
309−
310343 static const struct spi_device_id ad7476_id[] = {
344+ {"ad7091", ID_AD7091R},
311345 {"ad7091r", ID_AD7091R},
312346 {"ad7273", ID_AD7277},
313347 {"ad7274", ID_AD7276},
@@ -343,7 +377,6 @@ static struct spi_driver ad7476_driver = { · 29 unmodified lines
343377 .name = "ad7476",
344378 },
345379 .probe = ad7476_probe,
346− .remove = ad7476_remove,
347380 .id_table = ad7476_id,
348381 };
349382 module_spi_driver(ad7476_driver);
drivers/iio/adc/ad7780.c+23−4
@@ -206,10 +206,29 @@ static const struct ad_sigma_delta_info ad7780_sigma_delta_info = { · 205 unmodified lines
206206 .irq_flags = IRQF_TRIGGER_LOW,
207207 };
208208
209−#define AD7780_CHANNEL(bits, wordsize) \
210− AD_SD_CHANNEL(1, 0, 0, bits, 32, (wordsize) - (bits))
211−#define AD7170_CHANNEL(bits, wordsize) \
212− AD_SD_CHANNEL_NO_SAMP_FREQ(1, 0, 0, bits, 32, (wordsize) - (bits))
209+#define _AD7780_CHANNEL(_bits, _wordsize, _mask_all) \
210+{ \
211+ .type = IIO_VOLTAGE, \
212+ .indexed = 1, \
213+ .channel = 0, \
214+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
215+ BIT(IIO_CHAN_INFO_OFFSET), \
216+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
217+ .info_mask_shared_by_all = _mask_all, \
218+ .scan_index = 1, \
219+ .scan_type = { \
220+ .sign = 'u', \
221+ .realbits = (_bits), \
222+ .storagebits = 32, \
223+ .shift = (_wordsize) - (_bits), \
224+ .endianness = IIO_BE, \
225+ }, \
226+}
227+
228+#define AD7780_CHANNEL(_bits, _wordsize) \
229+ _AD7780_CHANNEL(_bits, _wordsize, BIT(IIO_CHAN_INFO_SAMP_FREQ))
230+#define AD7170_CHANNEL(_bits, _wordsize) \
231+ _AD7780_CHANNEL(_bits, _wordsize, 0)
213232
214233 static const struct ad7780_chip_info ad7780_chip_info_tbl[] = {
215234 [ID_AD7170] = {
drivers/iio/adc/ad7791.c+56−8
@@ -64,25 +64,73 @@ · 63 unmodified lines
6464 #define AD7791_MODE_SEL_MASK (0x3 << 6)
6565 #define AD7791_MODE_SEL(x) ((x) << 6)
6666
67+#define __AD7991_CHANNEL(_si, _channel1, _channel2, _address, _bits, \
68+ _storagebits, _shift, _extend_name, _type, _mask_all) \
69+ { \
70+ .type = (_type), \
71+ .differential = (_channel2 == -1 ? 0 : 1), \
72+ .indexed = 1, \
73+ .channel = (_channel1), \
74+ .channel2 = (_channel2), \
75+ .address = (_address), \
76+ .extend_name = (_extend_name), \
77+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
78+ BIT(IIO_CHAN_INFO_OFFSET), \
79+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
80+ .info_mask_shared_by_all = _mask_all, \
81+ .scan_index = (_si), \
82+ .scan_type = { \
83+ .sign = 'u', \
84+ .realbits = (_bits), \
85+ .storagebits = (_storagebits), \
86+ .shift = (_shift), \
87+ .endianness = IIO_BE, \
88+ }, \
89+ }
90+
91+#define AD7991_SHORTED_CHANNEL(_si, _channel, _address, _bits, \
92+ _storagebits, _shift) \
93+ __AD7991_CHANNEL(_si, _channel, _channel, _address, _bits, \
94+ _storagebits, _shift, "shorted", IIO_VOLTAGE, \
95+ BIT(IIO_CHAN_INFO_SAMP_FREQ))
96+
97+#define AD7991_CHANNEL(_si, _channel, _address, _bits, \
98+ _storagebits, _shift) \
99+ __AD7991_CHANNEL(_si, _channel, -1, _address, _bits, \
100+ _storagebits, _shift, NULL, IIO_VOLTAGE, \
101+ BIT(IIO_CHAN_INFO_SAMP_FREQ))
102+
103+#define AD7991_DIFF_CHANNEL(_si, _channel1, _channel2, _address, _bits, \
104+ _storagebits, _shift) \
105+ __AD7991_CHANNEL(_si, _channel1, _channel2, _address, _bits, \
106+ _storagebits, _shift, NULL, IIO_VOLTAGE, \
107+ BIT(IIO_CHAN_INFO_SAMP_FREQ))
108+
109+#define AD7991_SUPPLY_CHANNEL(_si, _channel, _address, _bits, _storagebits, \
110+ _shift) \
111+ __AD7991_CHANNEL(_si, _channel, -1, _address, _bits, \
112+ _storagebits, _shift, "supply", IIO_VOLTAGE, \
113+ BIT(IIO_CHAN_INFO_SAMP_FREQ))
114+
67115 #define DECLARE_AD7787_CHANNELS(name, bits, storagebits) \
68116 const struct iio_chan_spec name[] = { \
69− AD_SD_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \
117+ AD7991_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \
70118 (bits), (storagebits), 0), \
71− AD_SD_CHANNEL(1, 1, AD7791_CH_AIN2, (bits), (storagebits), 0), \
72− AD_SD_SHORTED_CHANNEL(2, 0, AD7791_CH_AIN1N_AIN1N, \
119+ AD7991_CHANNEL(1, 1, AD7791_CH_AIN2, (bits), (storagebits), 0), \
120+ AD7991_SHORTED_CHANNEL(2, 0, AD7791_CH_AIN1N_AIN1N, \
73121 (bits), (storagebits), 0), \
74− AD_SD_SUPPLY_CHANNEL(3, 2, AD7791_CH_AVDD_MONITOR, \
122+ AD7991_SUPPLY_CHANNEL(3, 2, AD7791_CH_AVDD_MONITOR, \
75123 (bits), (storagebits), 0), \
76124 IIO_CHAN_SOFT_TIMESTAMP(4), \
77125 }
78126
79127 #define DECLARE_AD7791_CHANNELS(name, bits, storagebits) \
80128 const struct iio_chan_spec name[] = { \
81− AD_SD_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \
129+ AD7991_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \
82130 (bits), (storagebits), 0), \
83− AD_SD_SHORTED_CHANNEL(1, 0, AD7791_CH_AIN1N_AIN1N, \
131+ AD7991_SHORTED_CHANNEL(1, 0, AD7791_CH_AIN1N_AIN1N, \
84132 (bits), (storagebits), 0), \
85− AD_SD_SUPPLY_CHANNEL(2, 1, AD7791_CH_AVDD_MONITOR, \
133+ AD7991_SUPPLY_CHANNEL(2, 1, AD7791_CH_AVDD_MONITOR, \
86134 (bits), (storagebits), 0), \
87135 IIO_CHAN_SOFT_TIMESTAMP(3), \
88136 }
@@ -444,5 +492,5 @@ static struct spi_driver ad7791_driver = { · 355 unmodified lines
444492 module_spi_driver(ad7791_driver);
445493
446494 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
447−MODULE_DESCRIPTION("Analog Device AD7787/AD7788/AD7789/AD7790/AD7791 ADC driver");
495+MODULE_DESCRIPTION("Analog Devices AD7787/AD7788/AD7789/AD7790/AD7791 ADC driver");
448496 MODULE_LICENSE("GPL v2");
drivers/iio/adc/ad7793.c+105−39
@@ -354,29 +354,28 @@ static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( · 353 unmodified lines
354354 static IIO_CONST_ATTR_NAMED(sampling_frequency_available_ad7797,
355355 sampling_frequency_available, "123 62 50 33 17 16 12 10 8 6 4");
356356
357−static ssize_t ad7793_show_scale_available(struct device *dev,
358− struct device_attribute *attr, char *buf)
357+static int ad7793_read_avail(struct iio_dev *indio_dev,
358+ struct iio_chan_spec const *chan,
359+ const int **vals, int *type, int *length,
360+ long mask)
359361 {
360− struct iio_dev *indio_dev = dev_to_iio_dev(dev);
361362 struct ad7793_state *st = iio_priv(indio_dev);
362− int i, len = 0;
363363
364− for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++)
365− len += sprintf(buf + len, "%d.%09u ", st->scale_avail[i][0],
366− st->scale_avail[i][1]);
367−
368− len += sprintf(buf + len, "\n");
364+ switch (mask) {
365+ case IIO_CHAN_INFO_SCALE:
366+ *vals = (int *)st->scale_avail;
367+ *type = IIO_VAL_INT_PLUS_NANO;
368+ /* Values are stored in a 2D matrix */
369+ *length = ARRAY_SIZE(st->scale_avail) * 2;
369370
370− return len;
371+ return IIO_AVAIL_LIST;
372+ default:
373+ return -EINVAL;
374+ }
371375 }
372376
373−static IIO_DEVICE_ATTR_NAMED(in_m_in_scale_available,
374− in_voltage-voltage_scale_available, S_IRUGO,
375− ad7793_show_scale_available, NULL, 0);
376−
377377 static struct attribute *ad7793_attributes[] = {
378378 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
379− &iio_dev_attr_in_m_in_scale_available.dev_attr.attr,
380379 NULL
381380 };
382381
@@ -534,6 +533,7 @@ static const struct iio_info ad7793_info = { · 151 unmodified lines
534533 .read_raw = &ad7793_read_raw,
535534 .write_raw = &ad7793_write_raw,
536535 .write_raw_get_fmt = &ad7793_write_raw_get_fmt,
536+ .read_avail = ad7793_read_avail,
537537 .attrs = &ad7793_attribute_group,
538538 .validate_trigger = ad_sd_validate_trigger,
539539 };
@@ -546,47 +546,113 @@ static const struct iio_info ad7797_info = { · 6 unmodified lines
546546 .validate_trigger = ad_sd_validate_trigger,
547547 };
548548
549+#define __AD7793_CHANNEL(_si, _channel1, _channel2, _address, _bits, \
550+ _storagebits, _shift, _extend_name, _type, _mask_type_av, _mask_all) \
551+ { \
552+ .type = (_type), \
553+ .differential = (_channel2 == -1 ? 0 : 1), \
554+ .indexed = 1, \
555+ .channel = (_channel1), \
556+ .channel2 = (_channel2), \
557+ .address = (_address), \
558+ .extend_name = (_extend_name), \
559+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
560+ BIT(IIO_CHAN_INFO_OFFSET), \
561+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
562+ .info_mask_shared_by_type_available = (_mask_type_av), \
563+ .info_mask_shared_by_all = _mask_all, \
564+ .scan_index = (_si), \
565+ .scan_type = { \
566+ .sign = 'u', \
567+ .realbits = (_bits), \
568+ .storagebits = (_storagebits), \
569+ .shift = (_shift), \
570+ .endianness = IIO_BE, \
571+ }, \
572+ }
573+
574+#define AD7793_DIFF_CHANNEL(_si, _channel1, _channel2, _address, _bits, \
575+ _storagebits, _shift) \
576+ __AD7793_CHANNEL(_si, _channel1, _channel2, _address, _bits, \
577+ _storagebits, _shift, NULL, IIO_VOLTAGE, \
578+ BIT(IIO_CHAN_INFO_SCALE), \
579+ BIT(IIO_CHAN_INFO_SAMP_FREQ))
580+
581+#define AD7793_SHORTED_CHANNEL(_si, _channel, _address, _bits, \
582+ _storagebits, _shift) \
583+ __AD7793_CHANNEL(_si, _channel, _channel, _address, _bits, \
584+ _storagebits, _shift, "shorted", IIO_VOLTAGE, \
585+ BIT(IIO_CHAN_INFO_SCALE), \
586+ BIT(IIO_CHAN_INFO_SAMP_FREQ))
587+
588+#define AD7793_TEMP_CHANNEL(_si, _address, _bits, _storagebits, _shift) \
589+ __AD7793_CHANNEL(_si, 0, -1, _address, _bits, \
590+ _storagebits, _shift, NULL, IIO_TEMP, \
591+ 0, \
592+ BIT(IIO_CHAN_INFO_SAMP_FREQ))
593+
594+#define AD7793_SUPPLY_CHANNEL(_si, _channel, _address, _bits, _storagebits, \
595+ _shift) \
596+ __AD7793_CHANNEL(_si, _channel, -1, _address, _bits, \
597+ _storagebits, _shift, "supply", IIO_VOLTAGE, \
598+ 0, \
599+ BIT(IIO_CHAN_INFO_SAMP_FREQ))
600+
601+#define AD7797_DIFF_CHANNEL(_si, _channel1, _channel2, _address, _bits, \
602+ _storagebits, _shift) \
603+ __AD7793_CHANNEL(_si, _channel1, _channel2, _address, _bits, \
604+ _storagebits, _shift, NULL, IIO_VOLTAGE, \
605+ 0, \
606+ BIT(IIO_CHAN_INFO_SAMP_FREQ))
607+
608+#define AD7797_SHORTED_CHANNEL(_si, _channel, _address, _bits, \
609+ _storagebits, _shift) \
610+ __AD7793_CHANNEL(_si, _channel, _channel, _address, _bits, \
611+ _storagebits, _shift, "shorted", IIO_VOLTAGE, \
612+ 0, \
613+ BIT(IIO_CHAN_INFO_SAMP_FREQ))
614+
549615 #define DECLARE_AD7793_CHANNELS(_name, _b, _sb, _s) \
550616 const struct iio_chan_spec _name##_channels[] = { \
551− AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), (_s)), \
552− AD_SD_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), (_s)), \
553− AD_SD_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), (_s)), \
554− AD_SD_SHORTED_CHANNEL(3, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), (_s)), \
555− AD_SD_TEMP_CHANNEL(4, AD7793_CH_TEMP, (_b), (_sb), (_s)), \
556− AD_SD_SUPPLY_CHANNEL(5, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), (_s)), \
617+ AD7793_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), (_s)), \
618+ AD7793_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), (_s)), \
619+ AD7793_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), (_s)), \
620+ AD7793_SHORTED_CHANNEL(3, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), (_s)), \
621+ AD7793_TEMP_CHANNEL(4, AD7793_CH_TEMP, (_b), (_sb), (_s)), \
622+ AD7793_SUPPLY_CHANNEL(5, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), (_s)), \
557623 IIO_CHAN_SOFT_TIMESTAMP(6), \
558624 }
559625
560626 #define DECLARE_AD7795_CHANNELS(_name, _b, _sb) \
561627 const struct iio_chan_spec _name##_channels[] = { \
562− AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \
563− AD_SD_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), 0), \
564− AD_SD_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), 0), \
565− AD_SD_DIFF_CHANNEL(3, 3, 3, AD7795_CH_AIN4P_AIN4M, (_b), (_sb), 0), \
566− AD_SD_DIFF_CHANNEL(4, 4, 4, AD7795_CH_AIN5P_AIN5M, (_b), (_sb), 0), \
567− AD_SD_DIFF_CHANNEL(5, 5, 5, AD7795_CH_AIN6P_AIN6M, (_b), (_sb), 0), \
568− AD_SD_SHORTED_CHANNEL(6, 0, AD7795_CH_AIN1M_AIN1M, (_b), (_sb), 0), \
569− AD_SD_TEMP_CHANNEL(7, AD7793_CH_TEMP, (_b), (_sb), 0), \
570− AD_SD_SUPPLY_CHANNEL(8, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \
628+ AD7793_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \
629+ AD7793_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), 0), \
630+ AD7793_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), 0), \
631+ AD7793_DIFF_CHANNEL(3, 3, 3, AD7795_CH_AIN4P_AIN4M, (_b), (_sb), 0), \
632+ AD7793_DIFF_CHANNEL(4, 4, 4, AD7795_CH_AIN5P_AIN5M, (_b), (_sb), 0), \
633+ AD7793_DIFF_CHANNEL(5, 5, 5, AD7795_CH_AIN6P_AIN6M, (_b), (_sb), 0), \
634+ AD7793_SHORTED_CHANNEL(6, 0, AD7795_CH_AIN1M_AIN1M, (_b), (_sb), 0), \
635+ AD7793_TEMP_CHANNEL(7, AD7793_CH_TEMP, (_b), (_sb), 0), \
636+ AD7793_SUPPLY_CHANNEL(8, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \
571637 IIO_CHAN_SOFT_TIMESTAMP(9), \
572638 }
573639
574640 #define DECLARE_AD7797_CHANNELS(_name, _b, _sb) \
575641 const struct iio_chan_spec _name##_channels[] = { \
576− AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \
577− AD_SD_SHORTED_CHANNEL(1, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), 0), \
578− AD_SD_TEMP_CHANNEL(2, AD7793_CH_TEMP, (_b), (_sb), 0), \
579− AD_SD_SUPPLY_CHANNEL(3, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \
642+ AD7797_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \
643+ AD7797_SHORTED_CHANNEL(1, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), 0), \
644+ AD7793_TEMP_CHANNEL(2, AD7793_CH_TEMP, (_b), (_sb), 0), \
645+ AD7793_SUPPLY_CHANNEL(3, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \
580646 IIO_CHAN_SOFT_TIMESTAMP(4), \
581647 }
582648
583649 #define DECLARE_AD7799_CHANNELS(_name, _b, _sb) \
584650 const struct iio_chan_spec _name##_channels[] = { \
585− AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \
586− AD_SD_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), 0), \
587− AD_SD_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), 0), \
588− AD_SD_SHORTED_CHANNEL(3, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), 0), \
589− AD_SD_SUPPLY_CHANNEL(4, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \
651+ AD7793_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \
652+ AD7793_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), 0), \
653+ AD7793_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), 0), \
654+ AD7793_SHORTED_CHANNEL(3, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), 0), \
655+ AD7793_SUPPLY_CHANNEL(4, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \
590656 IIO_CHAN_SOFT_TIMESTAMP(5), \
591657 }
592658
drivers/iio/adc/ad9467.c+422−0
@@ -0,0 +1,422 @@
1+// SPDX-License-Identifier: GPL-2.0-only
2+/*
3+ * Analog Devices AD9467 SPI ADC driver
4+ *
5+ * Copyright 2012-2020 Analog Devices Inc.
6+ */
7+
8+#include <linux/module.h>
9+#include <linux/device.h>
10+#include <linux/kernel.h>
11+#include <linux/slab.h>
12+#include <linux/spi/spi.h>
13+#include <linux/err.h>
14+#include <linux/delay.h>
15+#include <linux/gpio/consumer.h>
16+#include <linux/of_device.h>
17+
18+
19+#include <linux/iio/iio.h>
20+#include <linux/iio/sysfs.h>
21+
22+#include <linux/clk.h>
23+
24+#include <linux/iio/adc/adi-axi-adc.h>
25+
26+/*
27+ * ADI High-Speed ADC common spi interface registers
28+ * See Application-Note AN-877:
29+ * https://www.analog.com/media/en/technical-documentation/application-notes/AN-877.pdf
30+ */
31+
32+#define AN877_ADC_REG_CHIP_PORT_CONF 0x00
33+#define AN877_ADC_REG_CHIP_ID 0x01
34+#define AN877_ADC_REG_CHIP_GRADE 0x02
35+#define AN877_ADC_REG_CHAN_INDEX 0x05
36+#define AN877_ADC_REG_TRANSFER 0xFF
37+#define AN877_ADC_REG_MODES 0x08
38+#define AN877_ADC_REG_TEST_IO 0x0D
39+#define AN877_ADC_REG_ADC_INPUT 0x0F
40+#define AN877_ADC_REG_OFFSET 0x10
41+#define AN877_ADC_REG_OUTPUT_MODE 0x14
42+#define AN877_ADC_REG_OUTPUT_ADJUST 0x15
43+#define AN877_ADC_REG_OUTPUT_PHASE 0x16
44+#define AN877_ADC_REG_OUTPUT_DELAY 0x17
45+#define AN877_ADC_REG_VREF 0x18
46+#define AN877_ADC_REG_ANALOG_INPUT 0x2C
47+
48+/* AN877_ADC_REG_TEST_IO */
49+#define AN877_ADC_TESTMODE_OFF 0x0
50+#define AN877_ADC_TESTMODE_MIDSCALE_SHORT 0x1
51+#define AN877_ADC_TESTMODE_POS_FULLSCALE 0x2
52+#define AN877_ADC_TESTMODE_NEG_FULLSCALE 0x3
53+#define AN877_ADC_TESTMODE_ALT_CHECKERBOARD 0x4
54+#define AN877_ADC_TESTMODE_PN23_SEQ 0x5
55+#define AN877_ADC_TESTMODE_PN9_SEQ 0x6
56+#define AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE 0x7
57+#define AN877_ADC_TESTMODE_USER 0x8
58+#define AN877_ADC_TESTMODE_BIT_TOGGLE 0x9
59+#define AN877_ADC_TESTMODE_SYNC 0xA
60+#define AN877_ADC_TESTMODE_ONE_BIT_HIGH 0xB
61+#define AN877_ADC_TESTMODE_MIXED_BIT_FREQUENCY 0xC
62+#define AN877_ADC_TESTMODE_RAMP 0xF
63+
64+/* AN877_ADC_REG_TRANSFER */
65+#define AN877_ADC_TRANSFER_SYNC 0x1
66+
67+/* AN877_ADC_REG_OUTPUT_MODE */
68+#define AN877_ADC_OUTPUT_MODE_OFFSET_BINARY 0x0
69+#define AN877_ADC_OUTPUT_MODE_TWOS_COMPLEMENT 0x1
70+#define AN877_ADC_OUTPUT_MODE_GRAY_CODE 0x2
71+
72+/* AN877_ADC_REG_OUTPUT_PHASE */
73+#define AN877_ADC_OUTPUT_EVEN_ODD_MODE_EN 0x20
74+#define AN877_ADC_INVERT_DCO_CLK 0x80
75+
76+/* AN877_ADC_REG_OUTPUT_DELAY */
77+#define AN877_ADC_DCO_DELAY_ENABLE 0x80
78+
79+/*
80+ * Analog Devices AD9467 16-Bit, 200/250 MSPS ADC
81+ */
82+
83+#define CHIPID_AD9467 0x50
84+#define AD9467_DEF_OUTPUT_MODE 0x08
85+#define AD9467_REG_VREF_MASK 0x0F
86+
87+enum {
88+ ID_AD9467,
89+};
90+
91+struct ad9467_state {
92+ struct spi_device *spi;
93+ struct clk *clk;
94+ unsigned int output_mode;
95+
96+ struct gpio_desc *pwrdown_gpio;
97+ struct gpio_desc *reset_gpio;
98+};
99+
100+static int ad9467_spi_read(struct spi_device *spi, unsigned int reg)
101+{
102+ unsigned char tbuf[2], rbuf[1];
103+ int ret;
104+
105+ tbuf[0] = 0x80 | (reg >> 8);
106+ tbuf[1] = reg & 0xFF;
107+
108+ ret = spi_write_then_read(spi,
109+ tbuf, ARRAY_SIZE(tbuf),
110+ rbuf, ARRAY_SIZE(rbuf));
111+
112+ if (ret < 0)
113+ return ret;
114+
115+ return rbuf[0];
116+}
117+
118+static int ad9467_spi_write(struct spi_device *spi, unsigned int reg,
119+ unsigned int val)
120+{
121+ unsigned char buf[3];
122+
123+ buf[0] = reg >> 8;
124+ buf[1] = reg & 0xFF;
125+ buf[2] = val;
126+
127+ return spi_write(spi, buf, ARRAY_SIZE(buf));
128+}
129+
130+static int ad9467_reg_access(struct adi_axi_adc_conv *conv, unsigned int reg,
131+ unsigned int writeval, unsigned int *readval)
132+{
133+ struct ad9467_state *st = adi_axi_adc_conv_priv(conv);
134+ struct spi_device *spi = st->spi;
135+ int ret;
136+
137+ if (readval == NULL) {
138+ ret = ad9467_spi_write(spi, reg, writeval);
139+ ad9467_spi_write(spi, AN877_ADC_REG_TRANSFER,
140+ AN877_ADC_TRANSFER_SYNC);
141+ return ret;
142+ }
143+
144+ ret = ad9467_spi_read(spi, reg);
145+ if (ret < 0)
146+ return ret;
147+ *readval = ret;
148+
149+ return 0;
150+}
151+
152+static const unsigned int ad9467_scale_table[][2] = {
153+ {2000, 0}, {2100, 6}, {2200, 7},
154+ {2300, 8}, {2400, 9}, {2500, 10},
155+};
156+
157+static void __ad9467_get_scale(struct adi_axi_adc_conv *conv, int index,
158+ unsigned int *val, unsigned int *val2)
159+{
160+ const struct adi_axi_adc_chip_info *info = conv->chip_info;
161+ const struct iio_chan_spec *chan = &info->channels[0];
162+ unsigned int tmp;
163+
164+ tmp = (info->scale_table[index][0] * 1000000ULL) >>
165+ chan->scan_type.realbits;
166+ *val = tmp / 1000000;
167+ *val2 = tmp % 1000000;
168+}
169+
170+#define AD9467_CHAN(_chan, _si, _bits, _sign) \
171+{ \
172+ .type = IIO_VOLTAGE, \
173+ .indexed = 1, \
174+ .channel = _chan, \
175+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
176+ BIT(IIO_CHAN_INFO_SAMP_FREQ), \
177+ .scan_index = _si, \
178+ .scan_type = { \
179+ .sign = _sign, \
180+ .realbits = _bits, \
181+ .storagebits = 16, \
182+ }, \
183+}
184+
185+static const struct iio_chan_spec ad9467_channels[] = {
186+ AD9467_CHAN(0, 0, 16, 'S'),
187+};
188+
189+static const struct adi_axi_adc_chip_info ad9467_chip_tbl[] = {
190+ [ID_AD9467] = {
191+ .id = CHIPID_AD9467,
192+ .max_rate = 250000000UL,
193+ .scale_table = ad9467_scale_table,
194+ .num_scales = ARRAY_SIZE(ad9467_scale_table),
195+ .channels = ad9467_channels,
196+ .num_channels = ARRAY_SIZE(ad9467_channels),
197+ },
198+};
199+
200+static int ad9467_get_scale(struct adi_axi_adc_conv *conv, int *val, int *val2)
201+{
202+ const struct adi_axi_adc_chip_info *info = conv->chip_info;
203+ struct ad9467_state *st = adi_axi_adc_conv_priv(conv);
204+ unsigned int i, vref_val, vref_mask;
205+
206+ vref_val = ad9467_spi_read(st->spi, AN877_ADC_REG_VREF);
207+
208+ switch (info->id) {
209+ case CHIPID_AD9467:
210+ vref_mask = AD9467_REG_VREF_MASK;
211+ break;
212+ default:
213+ vref_mask = 0xFFFF;
214+ break;
215+ }
216+
217+ vref_val &= vref_mask;
218+
219+ for (i = 0; i < info->num_scales; i++) {
220+ if (vref_val == info->scale_table[i][1])
221+ break;
222+ }
223+
224+ if (i == info->num_scales)
225+ return -ERANGE;
226+
227+ __ad9467_get_scale(conv, i, val, val2);
228+
229+ return IIO_VAL_INT_PLUS_MICRO;
230+}
231+
232+static int ad9467_set_scale(struct adi_axi_adc_conv *conv, int val, int val2)
233+{
234+ const struct adi_axi_adc_chip_info *info = conv->chip_info;
235+ struct ad9467_state *st = adi_axi_adc_conv_priv(conv);
236+ unsigned int scale_val[2];
237+ unsigned int i;
238+
239+ if (val != 0)
240+ return -EINVAL;
241+
242+ for (i = 0; i < info->num_scales; i++) {
243+ __ad9467_get_scale(conv, i, &scale_val[0], &scale_val[1]);
244+ if (scale_val[0] != val || scale_val[1] != val2)
245+ continue;
246+
247+ ad9467_spi_write(st->spi, AN877_ADC_REG_VREF,
248+ info->scale_table[i][1]);
249+ ad9467_spi_write(st->spi, AN877_ADC_REG_TRANSFER,
250+ AN877_ADC_TRANSFER_SYNC);
251+ return 0;
252+ }
253+
254+ return -EINVAL;
255+}
256+
257+static int ad9467_read_raw(struct adi_axi_adc_conv *conv,
258+ struct iio_chan_spec const *chan,
259+ int *val, int *val2, long m)
260+{
261+ struct ad9467_state *st = adi_axi_adc_conv_priv(conv);
262+
263+ switch (m) {
264+ case IIO_CHAN_INFO_SCALE:
265+ return ad9467_get_scale(conv, val, val2);
266+ case IIO_CHAN_INFO_SAMP_FREQ:
267+ *val = clk_get_rate(st->clk);
268+
269+ return IIO_VAL_INT;
270+ default:
271+ return -EINVAL;
272+ }
273+}
274+
275+static int ad9467_write_raw(struct adi_axi_adc_conv *conv,
276+ struct iio_chan_spec const *chan,
277+ int val, int val2, long mask)
278+{
279+ const struct adi_axi_adc_chip_info *info = conv->chip_info;
280+ struct ad9467_state *st = adi_axi_adc_conv_priv(conv);
281+ long r_clk;
282+
283+ switch (mask) {
284+ case IIO_CHAN_INFO_SCALE:
285+ return ad9467_set_scale(conv, val, val2);
286+ case IIO_CHAN_INFO_SAMP_FREQ:
287+ r_clk = clk_round_rate(st->clk, val);
288+ if (r_clk < 0 || r_clk > info->max_rate) {
289+ dev_warn(&st->spi->dev,
290+ "Error setting ADC sample rate %ld", r_clk);
291+ return -EINVAL;
292+ }
293+
294+ return clk_set_rate(st->clk, r_clk);
295+ default:
296+ return -EINVAL;
297+ }
298+}
299+
300+static int ad9467_outputmode_set(struct spi_device *spi, unsigned int mode)
301+{
302+ int ret;
303+
304+ ret = ad9467_spi_write(spi, AN877_ADC_REG_OUTPUT_MODE, mode);
305+ if (ret < 0)
306+ return ret;
307+
308+ return ad9467_spi_write(spi, AN877_ADC_REG_TRANSFER,
309+ AN877_ADC_TRANSFER_SYNC);
310+}
311+
312+static int ad9467_preenable_setup(struct adi_axi_adc_conv *conv)
313+{
314+ struct ad9467_state *st = adi_axi_adc_conv_priv(conv);
315+
316+ return ad9467_outputmode_set(st->spi, st->output_mode);
317+}
318+
319+static int ad9467_setup(struct ad9467_state *st, unsigned int chip_id)
320+{
321+ switch (chip_id) {
322+ case CHIPID_AD9467:
323+ st->output_mode = AD9467_DEF_OUTPUT_MODE |
324+ AN877_ADC_OUTPUT_MODE_TWOS_COMPLEMENT;
325+ return 0;
326+ default:
327+ return -EINVAL;
328+ }
329+}
330+
331+static void ad9467_clk_disable(void *data)
332+{
333+ struct ad9467_state *st = data;
334+
335+ clk_disable_unprepare(st->clk);
336+}
337+
338+static int ad9467_probe(struct spi_device *spi)
339+{
340+ const struct adi_axi_adc_chip_info *info;
341+ struct adi_axi_adc_conv *conv;
342+ struct ad9467_state *st;
343+ unsigned int id;
344+ int ret;
345+
346+ info = of_device_get_match_data(&spi->dev);
347+ if (!info)
348+ return -ENODEV;
349+
350+ conv = devm_adi_axi_adc_conv_register(&spi->dev, sizeof(*st));
351+ if (IS_ERR(conv))
352+ return PTR_ERR(conv);
353+
354+ st = adi_axi_adc_conv_priv(conv);
355+ st->spi = spi;
356+
357+ st->clk = devm_clk_get(&spi->dev, "adc-clk");
358+ if (IS_ERR(st->clk))
359+ return PTR_ERR(st->clk);
360+
361+ ret = clk_prepare_enable(st->clk);
362+ if (ret < 0)
363+ return ret;
364+
365+ ret = devm_add_action_or_reset(&spi->dev, ad9467_clk_disable, st);
366+ if (ret)
367+ return ret;
368+
369+ st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown",
370+ GPIOD_OUT_LOW);
371+ if (IS_ERR(st->pwrdown_gpio))
372+ return PTR_ERR(st->pwrdown_gpio);
373+
374+ st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
375+ GPIOD_OUT_LOW);
376+ if (IS_ERR(st->reset_gpio))
377+ return PTR_ERR(st->reset_gpio);
378+
379+ if (st->reset_gpio) {
380+ udelay(1);
381+ ret = gpiod_direction_output(st->reset_gpio, 1);
382+ if (ret)
383+ return ret;
384+ mdelay(10);
385+ }
386+
387+ spi_set_drvdata(spi, st);
388+
389+ conv->chip_info = info;
390+
391+ id = ad9467_spi_read(spi, AN877_ADC_REG_CHIP_ID);
392+ if (id != conv->chip_info->id) {
393+ dev_err(&spi->dev, "Unrecognized CHIP_ID 0x%X\n", id);
394+ return -ENODEV;
395+ }
396+
397+ conv->reg_access = ad9467_reg_access;
398+ conv->write_raw = ad9467_write_raw;
399+ conv->read_raw = ad9467_read_raw;
400+ conv->preenable_setup = ad9467_preenable_setup;
401+
402+ return ad9467_setup(st, id);
403+}
404+
405+static const struct of_device_id ad9467_of_match[] = {
406+ { .compatible = "adi,ad9467", .data = &ad9467_chip_tbl[ID_AD9467], },
407+ {}
408+};
409+MODULE_DEVICE_TABLE(of, ad9467_of_match);
410+
411+static struct spi_driver ad9467_driver = {
412+ .driver = {
413+ .name = "ad9467",
414+ .of_match_table = ad9467_of_match,
415+ },
416+ .probe = ad9467_probe,
417+};
418+module_spi_driver(ad9467_driver);
419+
420+MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
421+MODULE_DESCRIPTION("Analog Devices AD9467 ADC driver");
422+MODULE_LICENSE("GPL v2");
drivers/iio/adc/adi-axi-adc.c+482−0
@@ -0,0 +1,482 @@
1+// SPDX-License-Identifier: GPL-2.0-only
2+/*
3+ * Analog Devices Generic AXI ADC IP core
4+ * Link: https://wiki.analog.com/resources/fpga/docs/axi_adc_ip
5+ *
6+ * Copyright 2012-2020 Analog Devices Inc.
7+ */
8+
9+#include <linux/bitfield.h>
10+#include <linux/clk.h>
11+#include <linux/io.h>
12+#include <linux/delay.h>
13+#include <linux/module.h>
14+#include <linux/of_device.h>
15+#include <linux/platform_device.h>
16+#include <linux/slab.h>
17+
18+#include <linux/iio/iio.h>
19+#include <linux/iio/sysfs.h>
20+#include <linux/iio/buffer.h>
21+#include <linux/iio/buffer-dmaengine.h>
22+
23+#include <linux/fpga/adi-axi-common.h>
24+#include <linux/iio/adc/adi-axi-adc.h>
25+
26+/**
27+ * Register definitions:
28+ * https://wiki.analog.com/resources/fpga/docs/axi_adc_ip#register_map
29+ */
30+
31+/* ADC controls */
32+
33+#define ADI_AXI_REG_RSTN 0x0040
34+#define ADI_AXI_REG_RSTN_CE_N BIT(2)
35+#define ADI_AXI_REG_RSTN_MMCM_RSTN BIT(1)
36+#define ADI_AXI_REG_RSTN_RSTN BIT(0)
37+
38+/* ADC Channel controls */
39+
40+#define ADI_AXI_REG_CHAN_CTRL(c) (0x0400 + (c) * 0x40)
41+#define ADI_AXI_REG_CHAN_CTRL_LB_OWR BIT(11)
42+#define ADI_AXI_REG_CHAN_CTRL_PN_SEL_OWR BIT(10)
43+#define ADI_AXI_REG_CHAN_CTRL_IQCOR_EN BIT(9)
44+#define ADI_AXI_REG_CHAN_CTRL_DCFILT_EN BIT(8)
45+#define ADI_AXI_REG_CHAN_CTRL_FMT_SIGNEXT BIT(6)
46+#define ADI_AXI_REG_CHAN_CTRL_FMT_TYPE BIT(5)
47+#define ADI_AXI_REG_CHAN_CTRL_FMT_EN BIT(4)
48+#define ADI_AXI_REG_CHAN_CTRL_PN_TYPE_OWR BIT(1)
49+#define ADI_AXI_REG_CHAN_CTRL_ENABLE BIT(0)
50+
51+#define ADI_AXI_REG_CHAN_CTRL_DEFAULTS \
52+ (ADI_AXI_REG_CHAN_CTRL_FMT_SIGNEXT | \
53+ ADI_AXI_REG_CHAN_CTRL_FMT_EN | \
54+ ADI_AXI_REG_CHAN_CTRL_ENABLE)
55+
56+struct adi_axi_adc_core_info {
57+ unsigned int version;
58+};
59+
60+struct adi_axi_adc_state {
61+ struct mutex lock;
62+
63+ struct adi_axi_adc_client *client;
64+ void __iomem *regs;
65+};
66+
67+struct adi_axi_adc_client {
68+ struct list_head entry;
69+ struct adi_axi_adc_conv conv;
70+ struct adi_axi_adc_state *state;
71+ struct device *dev;
72+ const struct adi_axi_adc_core_info *info;
73+};
74+
75+static LIST_HEAD(registered_clients);
76+static DEFINE_MUTEX(registered_clients_lock);
77+
78+static struct adi_axi_adc_client *conv_to_client(struct adi_axi_adc_conv *conv)
79+{
80+ return container_of(conv, struct adi_axi_adc_client, conv);
81+}
82+
83+void *adi_axi_adc_conv_priv(struct adi_axi_adc_conv *conv)
84+{
85+ struct adi_axi_adc_client *cl = conv_to_client(conv);
86+
87+ return (char *)cl + ALIGN(sizeof(struct adi_axi_adc_client), IIO_ALIGN);
88+}
89+EXPORT_SYMBOL_GPL(adi_axi_adc_conv_priv);
90+
91+static void adi_axi_adc_write(struct adi_axi_adc_state *st,
92+ unsigned int reg,
93+ unsigned int val)
94+{
95+ iowrite32(val, st->regs + reg);
96+}
97+
98+static unsigned int adi_axi_adc_read(struct adi_axi_adc_state *st,
99+ unsigned int reg)
100+{
101+ return ioread32(st->regs + reg);
102+}
103+
104+static int adi_axi_adc_config_dma_buffer(struct device *dev,
105+ struct iio_dev *indio_dev)
106+{
107+ struct iio_buffer *buffer;
108+ const char *dma_name;
109+
110+ if (!device_property_present(dev, "dmas"))
111+ return 0;
112+
113+ if (device_property_read_string(dev, "dma-names", &dma_name))
114+ dma_name = "rx";
115+
116+ buffer = devm_iio_dmaengine_buffer_alloc(indio_dev->dev.parent,
117+ dma_name);
118+ if (IS_ERR(buffer))
119+ return PTR_ERR(buffer);
120+
121+ indio_dev->modes |= INDIO_BUFFER_HARDWARE;
122+ iio_device_attach_buffer(indio_dev, buffer);
123+
124+ return 0;
125+}
126+
127+static int adi_axi_adc_read_raw(struct iio_dev *indio_dev,
128+ struct iio_chan_spec const *chan,
129+ int *val, int *val2, long mask)
130+{
131+ struct adi_axi_adc_state *st = iio_priv(indio_dev);
132+ struct adi_axi_adc_conv *conv = &st->client->conv;
133+
134+ if (!conv->read_raw)
135+ return -EOPNOTSUPP;
136+
137+ return conv->read_raw(conv, chan, val, val2, mask);
138+}
139+
140+static int adi_axi_adc_write_raw(struct iio_dev *indio_dev,
141+ struct iio_chan_spec const *chan,
142+ int val, int val2, long mask)
143+{
144+ struct adi_axi_adc_state *st = iio_priv(indio_dev);
145+ struct adi_axi_adc_conv *conv = &st->client->conv;
146+
147+ if (!conv->write_raw)
148+ return -EOPNOTSUPP;
149+
150+ return conv->write_raw(conv, chan, val, val2, mask);
151+}
152+
153+static int adi_axi_adc_update_scan_mode(struct iio_dev *indio_dev,
154+ const unsigned long *scan_mask)
155+{
156+ struct adi_axi_adc_state *st = iio_priv(indio_dev);
157+ struct adi_axi_adc_conv *conv = &st->client->conv;
158+ unsigned int i, ctrl;
159+
160+ for (i = 0; i < conv->chip_info->num_channels; i++) {
161+ ctrl = adi_axi_adc_read(st, ADI_AXI_REG_CHAN_CTRL(i));
162+
163+ if (test_bit(i, scan_mask))
164+ ctrl |= ADI_AXI_REG_CHAN_CTRL_ENABLE;
165+ else
166+ ctrl &= ~ADI_AXI_REG_CHAN_CTRL_ENABLE;
167+
168+ adi_axi_adc_write(st, ADI_AXI_REG_CHAN_CTRL(i), ctrl);
169+ }
170+
171+ return 0;
172+}
173+
174+static struct adi_axi_adc_conv *adi_axi_adc_conv_register(struct device *dev,
175+ size_t sizeof_priv)
176+{
177+ struct adi_axi_adc_client *cl;
178+ size_t alloc_size;
179+
180+ alloc_size = ALIGN(sizeof(struct adi_axi_adc_client), IIO_ALIGN);
181+ if (sizeof_priv)
182+ alloc_size += ALIGN(sizeof_priv, IIO_ALIGN);
183+
184+ cl = kzalloc(alloc_size, GFP_KERNEL);
185+ if (!cl)
186+ return ERR_PTR(-ENOMEM);
187+
188+ mutex_lock(&registered_clients_lock);
189+
190+ cl->dev = get_device(dev);
191+
192+ list_add_tail(&cl->entry, &registered_clients);
193+
194+ mutex_unlock(&registered_clients_lock);
195+
196+ return &cl->conv;
197+}
198+
199+static void adi_axi_adc_conv_unregister(struct adi_axi_adc_conv *conv)
200+{
201+ struct adi_axi_adc_client *cl = conv_to_client(conv);
202+
203+ mutex_lock(&registered_clients_lock);
204+
205+ list_del(&cl->entry);
206+ put_device(cl->dev);
207+
208+ mutex_unlock(&registered_clients_lock);
209+
210+ kfree(cl);
211+}
212+
213+static void devm_adi_axi_adc_conv_release(struct device *dev, void *res)
214+{
215+ adi_axi_adc_conv_unregister(*(struct adi_axi_adc_conv **)res);
216+}
217+
218+struct adi_axi_adc_conv *devm_adi_axi_adc_conv_register(struct device *dev,
219+ size_t sizeof_priv)
220+{
221+ struct adi_axi_adc_conv **ptr, *conv;
222+
223+ ptr = devres_alloc(devm_adi_axi_adc_conv_release, sizeof(*ptr),
224+ GFP_KERNEL);
225+ if (!ptr)
226+ return ERR_PTR(-ENOMEM);
227+
228+ conv = adi_axi_adc_conv_register(dev, sizeof_priv);
229+ if (IS_ERR(conv)) {
230+ devres_free(ptr);
231+ return ERR_CAST(conv);
232+ }
233+
234+ *ptr = conv;
235+ devres_add(dev, ptr);
236+
237+ return conv;
238+}
239+EXPORT_SYMBOL_GPL(devm_adi_axi_adc_conv_register);
240+
241+static ssize_t in_voltage_scale_available_show(struct device *dev,
242+ struct device_attribute *attr,
243+ char *buf)
244+{
245+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
246+ struct adi_axi_adc_state *st = iio_priv(indio_dev);
247+ struct adi_axi_adc_conv *conv = &st->client->conv;
248+ size_t len = 0;
249+ int i;
250+
251+ for (i = 0; i < conv->chip_info->num_scales; i++) {
252+ const unsigned int *s = conv->chip_info->scale_table[i];
253+
254+ len += scnprintf(buf + len, PAGE_SIZE - len,
255+ "%u.%06u ", s[0], s[1]);
256+ }
257+ buf[len - 1] = '\n';
258+
259+ return len;
260+}
261+
262+static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0);
263+
264+enum {
265+ ADI_AXI_ATTR_SCALE_AVAIL,
266+};
267+
268+#define ADI_AXI_ATTR(_en_, _file_) \
269+ [ADI_AXI_ATTR_##_en_] = &iio_dev_attr_##_file_.dev_attr.attr
270+
271+static struct attribute *adi_axi_adc_attributes[] = {
272+ ADI_AXI_ATTR(SCALE_AVAIL, in_voltage_scale_available),
273+ NULL
274+};
275+
276+static umode_t axi_adc_attr_is_visible(struct kobject *kobj,
277+ struct attribute *attr, int n)
278+{
279+ struct device *dev = container_of(kobj, struct device, kobj);
280+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
281+ struct adi_axi_adc_state *st = iio_priv(indio_dev);
282+ struct adi_axi_adc_conv *conv = &st->client->conv;
283+
284+ switch (n) {
285+ case ADI_AXI_ATTR_SCALE_AVAIL:
286+ if (!conv->chip_info->num_scales)
287+ return 0;
288+ return attr->mode;
289+ default:
290+ return attr->mode;
291+ }
292+}
293+
294+static const struct attribute_group adi_axi_adc_attribute_group = {
295+ .attrs = adi_axi_adc_attributes,
296+ .is_visible = axi_adc_attr_is_visible,
297+};
298+
299+static const struct iio_info adi_axi_adc_info = {
300+ .read_raw = &adi_axi_adc_read_raw,
301+ .write_raw = &adi_axi_adc_write_raw,
302+ .attrs = &adi_axi_adc_attribute_group,
303+ .update_scan_mode = &adi_axi_adc_update_scan_mode,
304+};
305+
306+static const struct adi_axi_adc_core_info adi_axi_adc_10_0_a_info = {
307+ .version = ADI_AXI_PCORE_VER(10, 0, 'a'),
308+};
309+
310+static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev)
311+{
312+ const struct adi_axi_adc_core_info *info;
313+ struct adi_axi_adc_client *cl;
314+ struct device_node *cln;
315+
316+ info = of_device_get_match_data(dev);
317+ if (!info)
318+ return ERR_PTR(-ENODEV);
319+
320+ cln = of_parse_phandle(dev->of_node, "adi,adc-dev", 0);
321+ if (!cln) {
322+ dev_err(dev, "No 'adi,adc-dev' node defined\n");
323+ return ERR_PTR(-ENODEV);
324+ }
325+
326+ mutex_lock(&registered_clients_lock);
327+
328+ list_for_each_entry(cl, &registered_clients, entry) {
329+ if (!cl->dev)
330+ continue;
331+
332+ if (cl->dev->of_node != cln)
333+ continue;
334+
335+ if (!try_module_get(dev->driver->owner)) {
336+ mutex_unlock(&registered_clients_lock);
337+ return ERR_PTR(-ENODEV);
338+ }
339+
340+ get_device(dev);
341+ cl->info = info;
342+ mutex_unlock(&registered_clients_lock);
343+ return cl;
344+ }
345+
346+ mutex_unlock(&registered_clients_lock);
347+
348+ return ERR_PTR(-EPROBE_DEFER);
349+}
350+
351+static int adi_axi_adc_setup_channels(struct device *dev,
352+ struct adi_axi_adc_state *st)
353+{
354+ struct adi_axi_adc_conv *conv = &st->client->conv;
355+ int i, ret;
356+
357+ if (conv->preenable_setup) {
358+ ret = conv->preenable_setup(conv);
359+ if (ret)
360+ return ret;
361+ }
362+
363+ for (i = 0; i < conv->chip_info->num_channels; i++) {
364+ adi_axi_adc_write(st, ADI_AXI_REG_CHAN_CTRL(i),
365+ ADI_AXI_REG_CHAN_CTRL_DEFAULTS);
366+ }
367+
368+ return 0;
369+}
370+
371+static void axi_adc_reset(struct adi_axi_adc_state *st)
372+{
373+ adi_axi_adc_write(st, ADI_AXI_REG_RSTN, 0);
374+ mdelay(10);
375+ adi_axi_adc_write(st, ADI_AXI_REG_RSTN, ADI_AXI_REG_RSTN_MMCM_RSTN);
376+ mdelay(10);
377+ adi_axi_adc_write(st, ADI_AXI_REG_RSTN,
378+ ADI_AXI_REG_RSTN_RSTN | ADI_AXI_REG_RSTN_MMCM_RSTN);
379+}
380+
381+static void adi_axi_adc_cleanup(void *data)
382+{
383+ struct adi_axi_adc_client *cl = data;
384+
385+ put_device(cl->dev);
386+ module_put(cl->dev->driver->owner);
387+}
388+
389+static int adi_axi_adc_probe(struct platform_device *pdev)
390+{
391+ struct adi_axi_adc_conv *conv;
392+ struct iio_dev *indio_dev;
393+ struct adi_axi_adc_client *cl;
394+ struct adi_axi_adc_state *st;
395+ unsigned int ver;
396+ int ret;
397+
398+ cl = adi_axi_adc_attach_client(&pdev->dev);
399+ if (IS_ERR(cl))
400+ return PTR_ERR(cl);
401+
402+ ret = devm_add_action_or_reset(&pdev->dev, adi_axi_adc_cleanup, cl);
403+ if (ret)
404+ return ret;
405+
406+ indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st));
407+ if (indio_dev == NULL)
408+ return -ENOMEM;
409+
410+ st = iio_priv(indio_dev);
411+ st->client = cl;
412+ cl->state = st;
413+ mutex_init(&st->lock);
414+
415+ st->regs = devm_platform_ioremap_resource(pdev, 0);
416+ if (IS_ERR(st->regs))
417+ return PTR_ERR(st->regs);
418+
419+ conv = &st->client->conv;
420+
421+ axi_adc_reset(st);
422+
423+ ver = adi_axi_adc_read(st, ADI_AXI_REG_VERSION);
424+
425+ if (cl->info->version > ver) {
426+ dev_err(&pdev->dev,
427+ "IP core version is too old. Expected %d.%.2d.%c, Reported %d.%.2d.%c\n",
428+ ADI_AXI_PCORE_VER_MAJOR(cl->info->version),
429+ ADI_AXI_PCORE_VER_MINOR(cl->info->version),
430+ ADI_AXI_PCORE_VER_PATCH(cl->info->version),
431+ ADI_AXI_PCORE_VER_MAJOR(ver),
432+ ADI_AXI_PCORE_VER_MINOR(ver),
433+ ADI_AXI_PCORE_VER_PATCH(ver));
434+ return -ENODEV;
435+ }
436+
437+ indio_dev->info = &adi_axi_adc_info;
438+ indio_dev->dev.parent = &pdev->dev;
439+ indio_dev->name = "adi-axi-adc";
440+ indio_dev->modes = INDIO_DIRECT_MODE;
441+ indio_dev->num_channels = conv->chip_info->num_channels;
442+ indio_dev->channels = conv->chip_info->channels;
443+
444+ ret = adi_axi_adc_config_dma_buffer(&pdev->dev, indio_dev);
445+ if (ret)
446+ return ret;
447+
448+ ret = adi_axi_adc_setup_channels(&pdev->dev, st);
449+ if (ret)
450+ return ret;
451+
452+ ret = devm_iio_device_register(&pdev->dev, indio_dev);
453+ if (ret)
454+ return ret;
455+
456+ dev_info(&pdev->dev, "AXI ADC IP core (%d.%.2d.%c) probed\n",
457+ ADI_AXI_PCORE_VER_MAJOR(ver),
458+ ADI_AXI_PCORE_VER_MINOR(ver),
459+ ADI_AXI_PCORE_VER_PATCH(ver));
460+
461+ return 0;
462+}
463+
464+/* Match table for of_platform binding */
465+static const struct of_device_id adi_axi_adc_of_match[] = {
466+ { .compatible = "adi,axi-adc-10.0.a", .data = &adi_axi_adc_10_0_a_info },
467+ { /* end of list */ }
468+};
469+MODULE_DEVICE_TABLE(of, adi_axi_adc_of_match);
470+
471+static struct platform_driver adi_axi_adc_driver = {
472+ .driver = {
473+ .name = KBUILD_MODNAME,
474+ .of_match_table = adi_axi_adc_of_match,
475+ },
476+ .probe = adi_axi_adc_probe,
477+};
478+module_platform_driver(adi_axi_adc_driver);
479+
480+MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
481+MODULE_DESCRIPTION("Analog Devices Generic AXI ADC IP core driver");
482+MODULE_LICENSE("GPL v2");
drivers/iio/adc/at91_adc.c+1−4
@@ -1152,7 +1152,6 @@ static int at91_adc_probe(struct platform_device *pdev) · 1151 unmodified lines
11521152 int ret;
11531153 struct iio_dev *idev;
11541154 struct at91_adc_state *st;
1155− struct resource *res;
11561155 u32 reg;
11571156
11581157 idev = devm_iio_device_alloc(&pdev->dev, sizeof(struct at91_adc_state));
@@ -1182,9 +1181,7 @@ static int at91_adc_probe(struct platform_device *pdev) · 23 unmodified lines
11821181 if (st->irq < 0)
11831182 return -ENODEV;
11841183
1185− res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1186−
1187− st->reg_base = devm_ioremap_resource(&pdev->dev, res);
1184+ st->reg_base = devm_platform_ioremap_resource(pdev, 0);
11881185 if (IS_ERR(st->reg_base))
11891186 return PTR_ERR(st->reg_base);
11901187
drivers/iio/adc/fsl-imx25-gcq.c+1−3
@@ -294,7 +294,6 @@ static int mx25_gcq_probe(struct platform_device *pdev) · 293 unmodified lines
294294 struct mx25_gcq_priv *priv;
295295 struct mx25_tsadc *tsadc = dev_get_drvdata(pdev->dev.parent);
296296 struct device *dev = &pdev->dev;
297− struct resource *res;
298297 void __iomem *mem;
299298 int ret;
300299 int i;
@@ -305,8 +304,7 @@ static int mx25_gcq_probe(struct platform_device *pdev) · 4 unmodified lines
305304
306305 priv = iio_priv(indio_dev);
307306
308− res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
309− mem = devm_ioremap_resource(dev, res);
307+ mem = devm_platform_ioremap_resource(pdev, 0);
310308 if (IS_ERR(mem))
311309 return PTR_ERR(mem);
312310
drivers/iio/adc/intel_mrfld_adc.c+3−3
@@ -75,7 +75,7 @@ static int mrfld_adc_single_conv(struct iio_dev *indio_dev, · 74 unmodified lines
7575 struct regmap *regmap = adc->regmap;
7676 unsigned int req;
7777 long timeout;
78− u8 buf[2];
78+ __be16 value;
7979 int ret;
8080
8181 reinit_completion(&adc->completion);
@@ -105,11 +105,11 @@ static int mrfld_adc_single_conv(struct iio_dev *indio_dev, · 23 unmodified lines
105105 goto done;
106106 }
107107
108− ret = regmap_bulk_read(regmap, chan->address, buf, 2);
108+ ret = regmap_bulk_read(regmap, chan->address, &value, sizeof(value));
109109 if (ret)
110110 goto done;
111111
112− *result = get_unaligned_be16(buf);
112+ *result = be16_to_cpu(value);
113113 ret = IIO_VAL_INT;
114114
115115 done:
drivers/iio/adc/max1241.c+227−0
@@ -0,0 +1,227 @@
1+// SPDX-License-Identifier: GPL-2.0-only
2+/*
3+ * MAX1241 low-power, 12-bit serial ADC
4+ *
5+ * Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX1240-MAX1241.pdf
6+ */
7+
8+#include <linux/delay.h>
9+#include <linux/gpio/consumer.h>
10+#include <linux/iio/iio.h>
11+#include <linux/module.h>
12+#include <linux/regulator/consumer.h>
13+#include <linux/spi/spi.h>
14+
15+#define MAX1241_VAL_MASK GENMASK(11, 0)
16+#define MAX1241_SHUTDOWN_DELAY_USEC 4
17+
18+enum max1241_id {
19+ max1241,
20+};
21+
22+struct max1241 {
23+ struct spi_device *spi;
24+ struct mutex lock;
25+ struct regulator *vdd;
26+ struct regulator *vref;
27+ struct gpio_desc *shutdown;
28+
29+ __be16 data ____cacheline_aligned;
30+};
31+
32+static const struct iio_chan_spec max1241_channels[] = {
33+ {
34+ .type = IIO_VOLTAGE,
35+ .indexed = 1,
36+ .channel = 0,
37+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
38+ BIT(IIO_CHAN_INFO_SCALE),
39+ },
40+};
41+
42+static int max1241_read(struct max1241 *adc)
43+{
44+ struct spi_transfer xfers[] = {
45+ /*
46+ * Begin conversion by bringing /CS low for at least
47+ * tconv us.
48+ */
49+ {
50+ .len = 0,
51+ .delay.value = 8,
52+ .delay.unit = SPI_DELAY_UNIT_USECS,
53+ },
54+ /*
55+ * Then read two bytes of data in our RX buffer.
56+ */
57+ {
58+ .rx_buf = &adc->data,
59+ .len = 2,
60+ },
61+ };
62+
63+ return spi_sync_transfer(adc->spi, xfers, ARRAY_SIZE(xfers));
64+}
65+
66+static int max1241_read_raw(struct iio_dev *indio_dev,
67+ struct iio_chan_spec const *chan,
68+ int *val, int *val2, long mask)
69+{
70+ int ret, vref_uV;
71+ struct max1241 *adc = iio_priv(indio_dev);
72+
73+ switch (mask) {
74+ case IIO_CHAN_INFO_RAW:
75+ mutex_lock(&adc->lock);
76+
77+ if (adc->shutdown) {
78+ gpiod_set_value(adc->shutdown, 0);
79+ udelay(MAX1241_SHUTDOWN_DELAY_USEC);
80+ ret = max1241_read(adc);
81+ gpiod_set_value(adc->shutdown, 1);
82+ } else
83+ ret = max1241_read(adc);
84+
85+ if (ret) {
86+ mutex_unlock(&adc->lock);
87+ return ret;
88+ }
89+
90+ *val = (be16_to_cpu(adc->data) >> 3) & MAX1241_VAL_MASK;
91+
92+ mutex_unlock(&adc->lock);
93+ return IIO_VAL_INT;
94+ case IIO_CHAN_INFO_SCALE:
95+ vref_uV = regulator_get_voltage(adc->vref);
96+
97+ if (vref_uV < 0)
98+ return vref_uV;
99+
100+ *val = vref_uV / 1000;
101+ *val2 = 12;
102+
103+ return IIO_VAL_FRACTIONAL_LOG2;
104+ default:
105+ return -EINVAL;
106+ }
107+}
108+
109+static const struct iio_info max1241_info = {
110+ .read_raw = max1241_read_raw,
111+};
112+
113+static void max1241_disable_vdd_action(void *data)
114+{
115+ struct max1241 *adc = data;
116+ struct device *dev = &adc->spi->dev;
117+ int err;
118+
119+ err = regulator_disable(adc->vdd);
120+ if (err)
121+ dev_err(dev, "could not disable vdd regulator.\n");
122+}
123+
124+static void max1241_disable_vref_action(void *data)
125+{
126+ struct max1241 *adc = data;
127+ struct device *dev = &adc->spi->dev;
128+ int err;
129+
130+ err = regulator_disable(adc->vref);
131+ if (err)
132+ dev_err(dev, "could not disable vref regulator.\n");
133+}
134+
135+static int max1241_probe(struct spi_device *spi)
136+{
137+ struct device *dev = &spi->dev;
138+ struct iio_dev *indio_dev;
139+ struct max1241 *adc;
140+ int ret;
141+
142+ indio_dev = devm_iio_device_alloc(dev, sizeof(*adc));
143+ if (!indio_dev)
144+ return -ENOMEM;
145+
146+ adc = iio_priv(indio_dev);
147+ adc->spi = spi;
148+ mutex_init(&adc->lock);
149+
150+ spi_set_drvdata(spi, indio_dev);
151+
152+ adc->vdd = devm_regulator_get(dev, "vdd");
153+ if (IS_ERR(adc->vdd)) {
154+ dev_err(dev, "failed to get vdd regulator\n");
155+ return PTR_ERR(adc->vdd);
156+ }
157+
158+ ret = regulator_enable(adc->vdd);
159+ if (ret)
160+ return ret;
161+
162+ ret = devm_add_action_or_reset(dev, max1241_disable_vdd_action, adc);
163+ if (ret) {
164+ dev_err(dev, "could not set up vdd regulator cleanup action\n");
165+ return ret;
166+ }
167+
168+ adc->vref = devm_regulator_get(dev, "vref");
169+ if (IS_ERR(adc->vref)) {
170+ dev_err(dev, "failed to get vref regulator\n");
171+ return PTR_ERR(adc->vref);
172+ }
173+
174+ ret = regulator_enable(adc->vref);
175+ if (ret)
176+ return ret;
177+
178+ ret = devm_add_action_or_reset(dev, max1241_disable_vref_action, adc);
179+ if (ret) {
180+ dev_err(dev, "could not set up vref regulator cleanup action\n");
181+ return ret;
182+ }
183+
184+ adc->shutdown = devm_gpiod_get_optional(dev, "shutdown",
185+ GPIOD_OUT_HIGH);
186+ if (IS_ERR(adc->shutdown))
187+ return PTR_ERR(adc->shutdown);
188+
189+ if (adc->shutdown)
190+ dev_dbg(dev, "shutdown pin passed, low-power mode enabled");
191+ else
192+ dev_dbg(dev, "no shutdown pin passed, low-power mode disabled");
193+
194+ indio_dev->name = spi_get_device_id(spi)->name;
195+ indio_dev->dev.parent = dev;
196+ indio_dev->info = &max1241_info;
197+ indio_dev->modes = INDIO_DIRECT_MODE;
198+ indio_dev->channels = max1241_channels;
199+ indio_dev->num_channels = ARRAY_SIZE(max1241_channels);
200+
201+ return devm_iio_device_register(dev, indio_dev);
202+}
203+
204+static const struct spi_device_id max1241_id[] = {
205+ { "max1241", max1241 },
206+ {}
207+};
208+
209+static const struct of_device_id max1241_dt_ids[] = {
210+ { .compatible = "maxim,max1241" },
211+ {}
212+};
213+MODULE_DEVICE_TABLE(of, max1241_dt_ids);
214+
215+static struct spi_driver max1241_spi_driver = {
216+ .driver = {
217+ .name = "max1241",
218+ .of_match_table = max1241_dt_ids,
219+ },
220+ .probe = max1241_probe,
221+ .id_table = max1241_id,
222+};
223+module_spi_driver(max1241_spi_driver);
224+
225+MODULE_AUTHOR("Alexandru Lazar <alazar@startmail.com>");
226+MODULE_DESCRIPTION("MAX1241 ADC driver");
227+MODULE_LICENSE("GPL v2");
drivers/iio/adc/max1363.c+23−9
@@ -150,6 +150,7 @@ struct max1363_chip_info { · 149 unmodified lines
150150 * @current_mode: the scan mode of this chip
151151 * @requestedmask: a valid requested set of channels
152152 * @reg: supply regulator
153+ * @lock lock to ensure state is consistent
153154 * @monitor_on: whether monitor mode is enabled
154155 * @monitor_speed: parameter corresponding to device monitor speed setting
155156 * @mask_high: bitmask for enabled high thresholds
@@ -169,6 +170,7 @@ struct max1363_state { · 13 unmodified lines
169170 const struct max1363_mode *current_mode;
170171 u32 requestedmask;
171172 struct regulator *reg;
173+ struct mutex lock;
172174
173175 /* Using monitor modes and buffer at the same time is
174176 currently not supported */
@@ -364,7 +366,11 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev, · 189 unmodified lines
364366 struct max1363_state *st = iio_priv(indio_dev);
365367 struct i2c_client *client = st->client;
366368
367− mutex_lock(&indio_dev->mlock);
369+ ret = iio_device_claim_direct_mode(indio_dev);
370+ if (ret)
371+ return ret;
372+ mutex_lock(&st->lock);
373+
368374 /*
369375 * If monitor mode is enabled, the method for reading a single
370376 * channel will have to be rather different and has not yet
@@ -372,7 +378,7 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev, · 1 unmodified line
372378 *
373379 * Also, cannot read directly if buffered capture enabled.
374380 */
375− if (st->monitor_on || iio_buffer_enabled(indio_dev)) {
381+ if (st->monitor_on) {
376382 ret = -EBUSY;
377383 goto error_ret;
378384 }
@@ -404,8 +410,10 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev, · 25 unmodified lines
404410 data = rxbuf[0];
405411 }
406412 *val = data;
413+
407414 error_ret:
408− mutex_unlock(&indio_dev->mlock);
415+ mutex_unlock(&st->lock);
416+ iio_device_release_direct_mode(indio_dev);
409417 return ret;
410418
411419 }
@@ -705,9 +713,9 @@ static ssize_t max1363_monitor_store_freq(struct device *dev, · 293 unmodified lines
705713 if (!found)
706714 return -EINVAL;
707715
708− mutex_lock(&indio_dev->mlock);
716+ mutex_lock(&st->lock);
709717 st->monitor_speed = i;
710− mutex_unlock(&indio_dev->mlock);
718+ mutex_unlock(&st->lock);
711719
712720 return 0;
713721 }
@@ -810,12 +818,12 @@ static int max1363_read_event_config(struct iio_dev *indio_dev, · 96 unmodified lines
810818 int val;
811819 int number = chan->channel;
812820
813− mutex_lock(&indio_dev->mlock);
821+ mutex_lock(&st->lock);
814822 if (dir == IIO_EV_DIR_FALLING)
815823 val = (1 << number) & st->mask_low;
816824 else
817825 val = (1 << number) & st->mask_high;
818− mutex_unlock(&indio_dev->mlock);
826+ mutex_unlock(&st->lock);
819827
820828 return val;
821829 }
@@ -962,7 +970,11 @@ static int max1363_write_event_config(struct iio_dev *indio_dev, · 140 unmodified lines
962970 u16 unifiedmask;
963971 int number = chan->channel;
964972
965− mutex_lock(&indio_dev->mlock);
973+ ret = iio_device_claim_direct_mode(indio_dev);
974+ if (ret)
975+ return ret;
976+ mutex_lock(&st->lock);
977+
966978 unifiedmask = st->mask_low | st->mask_high;
967979 if (dir == IIO_EV_DIR_FALLING) {
968980
@@ -989,7 +1001,8 @@ static int max1363_write_event_config(struct iio_dev *indio_dev, · 20 unmodified lines
9891001
9901002 max1363_monitor_mode_update(st, !!(st->mask_high | st->mask_low));
9911003 error_ret:
992− mutex_unlock(&indio_dev->mlock);
1004+ mutex_unlock(&st->lock);
1005+ iio_device_release_direct_mode(indio_dev);
9931006
9941007 return ret;
9951008 }
@@ -1587,6 +1600,7 @@ static int max1363_probe(struct i2c_client *client, · 591 unmodified lines
15871600
15881601 st = iio_priv(indio_dev);
15891602
1603+ mutex_init(&st->lock);
15901604 st->reg = devm_regulator_get(&client->dev, "vcc");
15911605 if (IS_ERR(st->reg)) {
15921606 ret = PTR_ERR(st->reg);
drivers/iio/adc/sun4i-gpadc-iio.c+1−3
@@ -496,7 +496,6 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, · 495 unmodified lines
496496 struct iio_dev *indio_dev)
497497 {
498498 struct sun4i_gpadc_iio *info = iio_priv(indio_dev);
499− struct resource *mem;
500499 void __iomem *base;
501500 int ret;
502501
@@ -508,8 +507,7 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, · 5 unmodified lines
508507 indio_dev->num_channels = ARRAY_SIZE(sun8i_a33_gpadc_channels);
509508 indio_dev->channels = sun8i_a33_gpadc_channels;
510509
511− mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
512− base = devm_ioremap_resource(&pdev->dev, mem);
510+ base = devm_platform_ioremap_resource(pdev, 0);
513511 if (IS_ERR(base))
514512 return PTR_ERR(base);
515513
drivers/iio/adc/xilinx-xadc-core.c+2−2
@@ -3,7 +3,7 @@ · 2 unmodified lines
33 * Xilinx XADC driver
44 *
55 * Copyright 2013-2014 Analog Devices Inc.
6− * Author: Lars-Peter Clauen <lars@metafoo.de>
6+ * Author: Lars-Peter Clausen <lars@metafoo.de>
77 *
88 * Documentation for the parts can be found at:
99 * - XADC hardmacro: Xilinx UG480
@@ -653,7 +653,7 @@ static int xadc_trigger_set_state(struct iio_trigger *trigger, bool state) · 643 unmodified lines
653653 mutex_lock(&xadc->mutex);
654654
655655 if (state) {
656− /* Only one of the two triggers can be active at the a time. */
656+ /* Only one of the two triggers can be active at a time. */
657657 if (xadc->trigger != NULL) {
658658 ret = -EBUSY;
659659 goto err_out;
drivers/iio/adc/xilinx-xadc-events.c+1−1
@@ -3,7 +3,7 @@ · 2 unmodified lines
33 * Xilinx XADC driver
44 *
55 * Copyright 2013 Analog Devices Inc.
6− * Author: Lars-Peter Clauen <lars@metafoo.de>
6+ * Author: Lars-Peter Clausen <lars@metafoo.de>
77 */
88
99 #include <linux/iio/events.h>
drivers/iio/adc/xilinx-xadc.h+1−1
@@ -3,7 +3,7 @@ · 2 unmodified lines
33 * Xilinx XADC driver
44 *
55 * Copyright 2013 Analog Devices Inc.
6− * Author: Lars-Peter Clauen <lars@metafoo.de>
6+ * Author: Lars-Peter Clausen <lars@metafoo.de>
77 */
88
99 #ifndef __IIO_XILINX_XADC__
drivers/iio/buffer/industrialio-buffer-dma.c+0−1
@@ -12,7 +12,6 @@ · 11 unmodified lines
1212 #include <linux/mutex.h>
1313 #include <linux/sched.h>
1414 #include <linux/poll.h>
15−#include <linux/iio/buffer.h>
1615 #include <linux/iio/buffer_impl.h>
1716 #include <linux/iio/buffer-dma.h>
1817 #include <linux/dma-mapping.h>
drivers/iio/buffer/industrialio-buffer-dmaengine.c+40−1
@@ -134,7 +134,7 @@ static ssize_t iio_dmaengine_buffer_get_length_align(struct device *dev, · 133 unmodified lines
134134 struct dmaengine_buffer *dmaengine_buffer =
135135 iio_buffer_to_dmaengine_buffer(indio_dev->buffer);
136136
137− return sprintf(buf, "%u\n", dmaengine_buffer->align);
137+ return sprintf(buf, "%zu\n", dmaengine_buffer->align);
138138 }
139139
140140 static IIO_DEVICE_ATTR(length_align_bytes, 0444,
@@ -229,6 +229,45 @@ void iio_dmaengine_buffer_free(struct iio_buffer *buffer) · 88 unmodified lines
229229 }
230230 EXPORT_SYMBOL_GPL(iio_dmaengine_buffer_free);
231231
232+static void __devm_iio_dmaengine_buffer_free(struct device *dev, void *res)
233+{
234+ iio_dmaengine_buffer_free(*(struct iio_buffer **)res);
235+}
236+
237+/**
238+ * devm_iio_dmaengine_buffer_alloc() - Resource-managed iio_dmaengine_buffer_alloc()
239+ * @dev: Parent device for the buffer
240+ * @channel: DMA channel name, typically "rx".
241+ *
242+ * This allocates a new IIO buffer which internally uses the DMAengine framework
243+ * to perform its transfers. The parent device will be used to request the DMA
244+ * channel.
245+ *
246+ * The buffer will be automatically de-allocated once the device gets destroyed.
247+ */
248+struct iio_buffer *devm_iio_dmaengine_buffer_alloc(struct device *dev,
249+ const char *channel)
250+{
251+ struct iio_buffer **bufferp, *buffer;
252+
253+ bufferp = devres_alloc(__devm_iio_dmaengine_buffer_free,
254+ sizeof(*bufferp), GFP_KERNEL);
255+ if (!bufferp)
256+ return ERR_PTR(-ENOMEM);
257+
258+ buffer = iio_dmaengine_buffer_alloc(dev, channel);
259+ if (IS_ERR(buffer)) {
260+ devres_free(bufferp);
261+ return buffer;
262+ }
263+
264+ *bufferp = buffer;
265+ devres_add(dev, bufferp);
266+
267+ return buffer;
268+}
269+EXPORT_SYMBOL_GPL(devm_iio_dmaengine_buffer_alloc);
270+
232271 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
233272 MODULE_DESCRIPTION("DMA buffer for the IIO framework");
234273 MODULE_LICENSE("GPL");
drivers/iio/buffer/industrialio-hw-consumer.c+0−31
@@ -142,17 +142,6 @@ static void devm_iio_hw_consumer_release(struct device *dev, void *res) · 141 unmodified lines
142142 iio_hw_consumer_free(*(struct iio_hw_consumer **)res);
143143 }
144144
145−static int devm_iio_hw_consumer_match(struct device *dev, void *res, void *data)
146−{
147− struct iio_hw_consumer **r = res;
148−
149− if (!r || !*r) {
150− WARN_ON(!r || !*r);
151− return 0;
152− }
153− return *r == data;
154−}
155−
156145 /**
157146 * devm_iio_hw_consumer_alloc - Resource-managed iio_hw_consumer_alloc()
158147 * @dev: Pointer to consumer device.
@@ -160,9 +149,6 @@ static int devm_iio_hw_consumer_match(struct device *dev, void *res, void *data) · 1 unmodified line
160149 * Managed iio_hw_consumer_alloc. iio_hw_consumer allocated with this function
161150 * is automatically freed on driver detach.
162151 *
163− * If an iio_hw_consumer allocated with this function needs to be freed
164− * separately, devm_iio_hw_consumer_free() must be used.
165− *
166152 * returns pointer to allocated iio_hw_consumer on success, NULL on failure.
167153 */
168154 struct iio_hw_consumer *devm_iio_hw_consumer_alloc(struct device *dev)
@@ -186,23 +172,6 @@ struct iio_hw_consumer *devm_iio_hw_consumer_alloc(struct device *dev) · 17 unmodified lines
186172 }
187173 EXPORT_SYMBOL_GPL(devm_iio_hw_consumer_alloc);
188174
189−/**
190− * devm_iio_hw_consumer_free - Resource-managed iio_hw_consumer_free()
191− * @dev: Pointer to consumer device.
192− * @hwc: iio_hw_consumer to free.
193− *
194− * Free iio_hw_consumer allocated with devm_iio_hw_consumer_alloc().
195− */
196−void devm_iio_hw_consumer_free(struct device *dev, struct iio_hw_consumer *hwc)
197−{
198− int rc;
199−
200− rc = devres_release(dev, devm_iio_hw_consumer_release,
201− devm_iio_hw_consumer_match, hwc);
202− WARN_ON(rc);
203−}
204−EXPORT_SYMBOL_GPL(devm_iio_hw_consumer_free);
205−
206175 /**
207176 * iio_hw_consumer_enable() - Enable IIO hardware consumer
208177 * @hwc: iio_hw_consumer to enable.
drivers/iio/buffer/industrialio-triggered-buffer.c+0−11
@@ -126,17 +126,6 @@ int devm_iio_triggered_buffer_setup(struct device *dev, · 125 unmodified lines
126126 }
127127 EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_setup);
128128
129−void devm_iio_triggered_buffer_cleanup(struct device *dev,
130− struct iio_dev *indio_dev)
131−{
132− int rc;
133−
134− rc = devres_release(dev, devm_iio_triggered_buffer_clean,
135− devm_iio_device_match, indio_dev);
136− WARN_ON(rc);
137−}
138−EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_cleanup);
139−
140129 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
141130 MODULE_DESCRIPTION("IIO helper functions for setting up triggered buffers");
142131 MODULE_LICENSE("GPL");
drivers/iio/buffer/kfifo_buf.c+0−22
@@ -179,16 +179,6 @@ static void devm_iio_kfifo_release(struct device *dev, void *res) · 178 unmodified lines
179179 iio_kfifo_free(*(struct iio_buffer **)res);
180180 }
181181
182−static int devm_iio_kfifo_match(struct device *dev, void *res, void *data)
183−{
184− struct iio_buffer **r = res;
185−
186− if (WARN_ON(!r || !*r))
187− return 0;
188−
189− return *r == data;
190−}
191−
192182 /**
193183 * devm_iio_fifo_allocate - Resource-managed iio_kfifo_allocate()
194184 * @dev: Device to allocate kfifo buffer for
@@ -216,16 +206,4 @@ struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev) · 21 unmodified lines
216206 }
217207 EXPORT_SYMBOL(devm_iio_kfifo_allocate);
218208
219−/**
220− * devm_iio_fifo_free - Resource-managed iio_kfifo_free()
221− * @dev: Device the buffer belongs to
222− * @r: The buffer associated with the device
223− */
224−void devm_iio_kfifo_free(struct device *dev, struct iio_buffer *r)
225−{
226− WARN_ON(devres_release(dev, devm_iio_kfifo_release,
227− devm_iio_kfifo_match, r));
228−}
229−EXPORT_SYMBOL(devm_iio_kfifo_free);
230−
231209 MODULE_LICENSE("GPL");
drivers/iio/chemical/atlas-sensor.c+3−4
@@ -426,8 +426,7 @@ static irqreturn_t atlas_trigger_handler(int irq, void *private) · 425 unmodified lines
426426 int ret;
427427
428428 ret = regmap_bulk_read(data->regmap, data->chip->data_reg,
429− (u8 *) &data->buffer,
430− sizeof(__be32) * channels);
429+ &data->buffer, sizeof(__be32) * channels);
431430
432431 if (!ret)
433432 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
@@ -463,7 +462,7 @@ static int atlas_read_measurement(struct atlas_data *data, int reg, __be32 *val) · 29 unmodified lines
463462 if (suspended)
464463 msleep(data->chip->delay);
465464
466− ret = regmap_bulk_read(data->regmap, reg, (u8 *) val, sizeof(*val));
465+ ret = regmap_bulk_read(data->regmap, reg, val, sizeof(*val));
467466
468467 pm_runtime_mark_last_busy(dev);
469468 pm_runtime_put_autosuspend(dev);
@@ -485,7 +484,7 @@ static int atlas_read_raw(struct iio_dev *indio_dev, · 15 unmodified lines
485484 switch (chan->type) {
486485 case IIO_TEMP:
487486 ret = regmap_bulk_read(data->regmap, chan->address,
488− (u8 *) &reg, sizeof(reg));
487+ &reg, sizeof(reg));
489488 break;
490489 case IIO_PH:
491490 case IIO_CONCENTRATION:
drivers/iio/chemical/bme680_core.c+22−14
@@ -114,14 +114,16 @@ static int bme680_read_calib(struct bme680_data *data, · 113 unmodified lines
114114 __le16 buf;
115115
116116 /* Temperature related coefficients */
117− ret = regmap_bulk_read(data->regmap, BME680_T1_LSB_REG, (u8 *) &buf, 2);
117+ ret = regmap_bulk_read(data->regmap, BME680_T1_LSB_REG,
118+ &buf, sizeof(buf));
118119 if (ret < 0) {
119120 dev_err(dev, "failed to read BME680_T1_LSB_REG\n");
120121 return ret;
121122 }
122123 calib->par_t1 = le16_to_cpu(buf);
123124
124− ret = regmap_bulk_read(data->regmap, BME680_T2_LSB_REG, (u8 *) &buf, 2);
125+ ret = regmap_bulk_read(data->regmap, BME680_T2_LSB_REG,
126+ &buf, sizeof(buf));
125127 if (ret < 0) {
126128 dev_err(dev, "failed to read BME680_T2_LSB_REG\n");
127129 return ret;
@@ -136,14 +138,16 @@ static int bme680_read_calib(struct bme680_data *data, · 8 unmodified lines
136138 calib->par_t3 = tmp;
137139
138140 /* Pressure related coefficients */
139− ret = regmap_bulk_read(data->regmap, BME680_P1_LSB_REG, (u8 *) &buf, 2);
141+ ret = regmap_bulk_read(data->regmap, BME680_P1_LSB_REG,
142+ &buf, sizeof(buf));
140143 if (ret < 0) {
141144 dev_err(dev, "failed to read BME680_P1_LSB_REG\n");
142145 return ret;
143146 }
144147 calib->par_p1 = le16_to_cpu(buf);
145148
146− ret = regmap_bulk_read(data->regmap, BME680_P2_LSB_REG, (u8 *) &buf, 2);
149+ ret = regmap_bulk_read(data->regmap, BME680_P2_LSB_REG,
150+ &buf, sizeof(buf));
147151 if (ret < 0) {
148152 dev_err(dev, "failed to read BME680_P2_LSB_REG\n");
149153 return ret;
@@ -157,14 +161,16 @@ static int bme680_read_calib(struct bme680_data *data, · 7 unmodified lines
157161 }
158162 calib->par_p3 = tmp;
159163
160− ret = regmap_bulk_read(data->regmap, BME680_P4_LSB_REG, (u8 *) &buf, 2);
164+ ret = regmap_bulk_read(data->regmap, BME680_P4_LSB_REG,
165+ &buf, sizeof(buf));
161166 if (ret < 0) {
162167 dev_err(dev, "failed to read BME680_P4_LSB_REG\n");
163168 return ret;
164169 }
165170 calib->par_p4 = le16_to_cpu(buf);
166171
167− ret = regmap_bulk_read(data->regmap, BME680_P5_LSB_REG, (u8 *) &buf, 2);
172+ ret = regmap_bulk_read(data->regmap, BME680_P5_LSB_REG,
173+ &buf, sizeof(buf));
168174 if (ret < 0) {
169175 dev_err(dev, "failed to read BME680_P5_LSB_REG\n");
170176 return ret;
@@ -185,14 +191,16 @@ static int bme680_read_calib(struct bme680_data *data, · 14 unmodified lines
185191 }
186192 calib->par_p7 = tmp;
187193
188− ret = regmap_bulk_read(data->regmap, BME680_P8_LSB_REG, (u8 *) &buf, 2);
194+ ret = regmap_bulk_read(data->regmap, BME680_P8_LSB_REG,
195+ &buf, sizeof(buf));
189196 if (ret < 0) {
190197 dev_err(dev, "failed to read BME680_P8_LSB_REG\n");
191198 return ret;
192199 }
193200 calib->par_p8 = le16_to_cpu(buf);
194201
195− ret = regmap_bulk_read(data->regmap, BME680_P9_LSB_REG, (u8 *) &buf, 2);
202+ ret = regmap_bulk_read(data->regmap, BME680_P9_LSB_REG,
203+ &buf, sizeof(buf));
196204 if (ret < 0) {
197205 dev_err(dev, "failed to read BME680_P9_LSB_REG\n");
198206 return ret;
@@ -276,8 +284,8 @@ static int bme680_read_calib(struct bme680_data *data, · 77 unmodified lines
276284 }
277285 calib->par_gh1 = tmp;
278286
279− ret = regmap_bulk_read(data->regmap, BME680_GH2_LSB_REG, (u8 *) &buf,
280− 2);
287+ ret = regmap_bulk_read(data->regmap, BME680_GH2_LSB_REG,
288+ &buf, sizeof(buf));
281289 if (ret < 0) {
282290 dev_err(dev, "failed to read BME680_GH2_LSB_REG\n");
283291 return ret;
@@ -615,7 +623,7 @@ static int bme680_read_temp(struct bme680_data *data, int *val) · 331 unmodified lines
615623 return ret;
616624
617625 ret = regmap_bulk_read(data->regmap, BME680_REG_TEMP_MSB,
618− (u8 *) &tmp, 3);
626+ &tmp, 3);
619627 if (ret < 0) {
620628 dev_err(dev, "failed to read temperature\n");
621629 return ret;
@@ -656,7 +664,7 @@ static int bme680_read_press(struct bme680_data *data, · 34 unmodified lines
656664 return ret;
657665
658666 ret = regmap_bulk_read(data->regmap, BME680_REG_PRESS_MSB,
659− (u8 *) &tmp, 3);
667+ &tmp, 3);
660668 if (ret < 0) {
661669 dev_err(dev, "failed to read pressure\n");
662670 return ret;
@@ -689,7 +697,7 @@ static int bme680_read_humid(struct bme680_data *data, · 26 unmodified lines
689697 return ret;
690698
691699 ret = regmap_bulk_read(data->regmap, BM6880_REG_HUMIDITY_MSB,
692− (u8 *) &tmp, 2);
700+ &tmp, sizeof(tmp));
693701 if (ret < 0) {
694702 dev_err(dev, "failed to read humidity\n");
695703 return ret;
@@ -754,7 +762,7 @@ static int bme680_read_gas(struct bme680_data *data, · 58 unmodified lines
754762 }
755763
756764 ret = regmap_bulk_read(data->regmap, BME680_REG_GAS_MSB,
757− (u8 *) &tmp, 2);
765+ &tmp, sizeof(tmp));
758766 if (ret < 0) {
759767 dev_err(dev, "failed to read gas resistance\n");
760768 return ret;
drivers/iio/common/st_sensors/st_sensors_core.c+2−4
@@ -150,8 +150,7 @@ static int st_sensors_set_fullscale(struct iio_dev *indio_dev, unsigned int fs) · 149 unmodified lines
150150 if (err < 0)
151151 goto st_accel_set_fullscale_error;
152152
153− sdata->current_fullscale = (struct st_sensor_fullscale_avl *)
154− &sdata->sensor_settings->fs.fs_avl[i];
153+ sdata->current_fullscale = &sdata->sensor_settings->fs.fs_avl[i];
155154 return err;
156155
157156 st_accel_set_fullscale_error:
@@ -278,8 +277,7 @@ static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev, · 120 unmodified lines
278277 !sdata->sensor_settings->drdy_irq.int2.addr) {
279278 if (pdata->drdy_int_pin)
280279 dev_info(&indio_dev->dev,
281− "DRDY on pin INT%d specified, but sensor "
282− "does not support interrupts\n",
280+ "DRDY on pin INT%d specified, but sensor does not support interrupts\n",
283281 pdata->drdy_int_pin);
284282 return 0;
285283 }
drivers/iio/common/st_sensors/st_sensors_i2c.c+2−2
@@ -49,8 +49,8 @@ int st_sensors_i2c_configure(struct iio_dev *indio_dev, · 48 unmodified lines
4949
5050 sdata->regmap = devm_regmap_init_i2c(client, config);
5151 if (IS_ERR(sdata->regmap)) {
52− dev_err(&client->dev, "Failed to register i2c regmap (%d)\n",
53− (int)PTR_ERR(sdata->regmap));
52+ dev_err(&client->dev, "Failed to register i2c regmap (%ld)\n",
53+ PTR_ERR(sdata->regmap));
5454 return PTR_ERR(sdata->regmap);
5555 }
5656
drivers/iio/common/st_sensors/st_sensors_spi.c+3−3
@@ -44,7 +44,7 @@ static bool st_sensors_is_spi_3_wire(struct spi_device *spi) · 43 unmodified lines
4444 if (device_property_read_bool(dev, "spi-3wire"))
4545 return true;
4646
47− pdata = (struct st_sensors_platform_data *)dev->platform_data;
47+ pdata = dev_get_platdata(dev);
4848 if (pdata && pdata->spi_3wire)
4949 return true;
5050
@@ -101,8 +101,8 @@ int st_sensors_spi_configure(struct iio_dev *indio_dev, · 50 unmodified lines
101101
102102 sdata->regmap = devm_regmap_init_spi(spi, config);
103103 if (IS_ERR(sdata->regmap)) {
104− dev_err(&spi->dev, "Failed to register spi regmap (%d)\n",
105− (int)PTR_ERR(sdata->regmap));
104+ dev_err(&spi->dev, "Failed to register spi regmap (%ld)\n",
105+ PTR_ERR(sdata->regmap));
106106 return PTR_ERR(sdata->regmap);
107107 }
108108
drivers/iio/common/st_sensors/st_sensors_trigger.c+4−9
@@ -44,8 +44,7 @@ static int st_sensors_new_samples_available(struct iio_dev *indio_dev, · 43 unmodified lines
4444 sdata->sensor_settings->drdy_irq.stat_drdy.addr,
4545 &status);
4646 if (ret < 0) {
47− dev_err(sdata->dev,
48− "error checking samples available\n");
47+ dev_err(sdata->dev, "error checking samples available\n");
4948 return ret;
5049 }
5150
@@ -148,9 +147,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev, · 96 unmodified lines
148147 case IRQF_TRIGGER_LOW:
149148 if (!sdata->sensor_settings->drdy_irq.addr_ihl) {
150149 dev_err(&indio_dev->dev,
151− "falling/low specified for IRQ "
152− "but hardware supports only rising/high: "
153− "will request rising/high\n");
150+ "falling/low specified for IRQ but hardware supports only rising/high: will request rising/high\n");
154151 if (irq_trig == IRQF_TRIGGER_FALLING)
155152 irq_trig = IRQF_TRIGGER_RISING;
156153 if (irq_trig == IRQF_TRIGGER_LOW)
@@ -163,8 +160,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev, · 6 unmodified lines
163160 if (err < 0)
164161 goto iio_trigger_free;
165162 dev_info(&indio_dev->dev,
166− "interrupts on the falling edge or "
167− "active low level\n");
163+ "interrupts on the falling edge or active low level\n");
168164 }
169165 break;
170166 case IRQF_TRIGGER_RISING:
@@ -178,8 +174,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev, · 7 unmodified lines
178174 default:
179175 /* This is the most preferred mode, if possible */
180176 dev_err(&indio_dev->dev,
181− "unsupported IRQ trigger specified (%lx), enforce "
182− "rising edge\n", irq_trig);
177+ "unsupported IRQ trigger specified (%lx), enforce rising edge\n", irq_trig);
183178 irq_trig = IRQF_TRIGGER_RISING;
184179 }
185180
drivers/iio/gyro/Kconfig+1−1
@@ -61,7 +61,7 @@ config BMG160 · 60 unmodified lines
6161 help
6262 Say yes here to build support for BOSCH BMG160 Tri-axis Gyro Sensor
6363 driver connected via I2C or SPI. This driver also supports BMI055
64− gyroscope.
64+ and BMI088 gyroscope.
6565
6666 This driver can also be built as a module. If so, the module
6767 will be called bmg160_i2c or bmg160_spi.
drivers/iio/gyro/bmg160_i2c.c+4−2
@@ -21,8 +21,8 @@ static int bmg160_i2c_probe(struct i2c_client *client, · 20 unmodified lines
2121
2222 regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
2323 if (IS_ERR(regmap)) {
24− dev_err(&client->dev, "Failed to register i2c regmap %d\n",
25− (int)PTR_ERR(regmap));
24+ dev_err(&client->dev, "Failed to register i2c regmap: %pe\n",
25+ regmap);
2626 return PTR_ERR(regmap);
2727 }
2828
@@ -42,6 +42,7 @@ static int bmg160_i2c_remove(struct i2c_client *client) · 13 unmodified lines
4242 static const struct acpi_device_id bmg160_acpi_match[] = {
4343 {"BMG0160", 0},
4444 {"BMI055B", 0},
45+ {"BMI088B", 0},
4546 {},
4647 };
4748
@@ -50,6 +51,7 @@ MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match); · 2 unmodified lines
5051 static const struct i2c_device_id bmg160_i2c_id[] = {
5152 {"bmg160", 0},
5253 {"bmi055_gyro", 0},
54+ {"bmi088_gyro", 0},
5355 {}
5456 };
5557
drivers/iio/gyro/bmg160_spi.c+3−2
@@ -19,8 +19,8 @@ static int bmg160_spi_probe(struct spi_device *spi) · 18 unmodified lines
1919
2020 regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf);
2121 if (IS_ERR(regmap)) {
22− dev_err(&spi->dev, "Failed to register spi regmap %d\n",
23− (int)PTR_ERR(regmap));
22+ dev_err(&spi->dev, "Failed to register spi regmap: %pe\n",
23+ regmap);
2424 return PTR_ERR(regmap);
2525 }
2626
@@ -37,6 +37,7 @@ static int bmg160_spi_remove(struct spi_device *spi) · 10 unmodified lines
3737 static const struct spi_device_id bmg160_spi_id[] = {
3838 {"bmg160", 0},
3939 {"bmi055_gyro", 0},
40+ {"bmi088_gyro", 0},
4041 {}
4142 };
4243
drivers/iio/gyro/mpu3050-i2c.c+2−2
@@ -51,8 +51,8 @@ static int mpu3050_i2c_probe(struct i2c_client *client, · 50 unmodified lines
5151
5252 regmap = devm_regmap_init_i2c(client, &mpu3050_i2c_regmap_config);
5353 if (IS_ERR(regmap)) {
54− dev_err(&client->dev, "Failed to register i2c regmap %d\n",
55− (int)PTR_ERR(regmap));
54+ dev_err(&client->dev, "Failed to register i2c regmap: %pe\n",
55+ regmap);
5656 return PTR_ERR(regmap);
5757 }
5858
drivers/iio/gyro/st_gyro_buffer.c+1−2
@@ -37,8 +37,7 @@ static int st_gyro_buffer_postenable(struct iio_dev *indio_dev) · 36 unmodified lines
3737 if (err < 0)
3838 return err;
3939
40− err = st_sensors_set_axis_enable(indio_dev,
41− (u8)indio_dev->active_scan_mask[0]);
40+ err = st_sensors_set_axis_enable(indio_dev, indio_dev->active_scan_mask[0]);
4241 if (err < 0)
4342 goto st_gyro_buffer_predisable;
4443
drivers/iio/gyro/st_gyro_core.c+5−4
@@ -460,6 +460,7 @@ EXPORT_SYMBOL(st_gyro_get_settings); · 459 unmodified lines
460460 int st_gyro_common_probe(struct iio_dev *indio_dev)
461461 {
462462 struct st_sensor_data *gdata = iio_priv(indio_dev);
463+ struct st_sensors_platform_data *pdata;
463464 int err;
464465
465466 indio_dev->modes = INDIO_DIRECT_MODE;
@@ -477,12 +478,12 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) · 11 unmodified lines
477478 indio_dev->channels = gdata->sensor_settings->ch;
478479 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
479480
480− gdata->current_fullscale = (struct st_sensor_fullscale_avl *)
481− &gdata->sensor_settings->fs.fs_avl[0];
481+ gdata->current_fullscale = &gdata->sensor_settings->fs.fs_avl[0];
482482 gdata->odr = gdata->sensor_settings->odr.odr_avl[0].hz;
483483
484− err = st_sensors_init_sensor(indio_dev,
485− (struct st_sensors_platform_data *)&gyro_pdata);
484+ pdata = (struct st_sensors_platform_data *)&gyro_pdata;
485+
486+ err = st_sensors_init_sensor(indio_dev, pdata);
486487 if (err < 0)
487488 goto st_gyro_power_off;
488489
drivers/iio/health/max30100.c+3−4
@@ -16,7 +16,7 @@ · 15 unmodified lines
1616 #include <linux/irq.h>
1717 #include <linux/i2c.h>
1818 #include <linux/mutex.h>
19−#include <linux/of.h>
19+#include <linux/property.h>
2020 #include <linux/regmap.h>
2121 #include <linux/iio/iio.h>
2222 #include <linux/iio/buffer.h>
@@ -267,11 +267,10 @@ static int max30100_get_current_idx(unsigned int val, int *reg) · 244 unmodified lines
267267 static int max30100_led_init(struct max30100_data *data)
268268 {
269269 struct device *dev = &data->client->dev;
270− struct device_node *np = dev->of_node;
271270 unsigned int val[2];
272271 int reg, ret;
273272
274− ret = of_property_read_u32_array(np, "maxim,led-current-microamp",
273+ ret = device_property_read_u32_array(dev, "maxim,led-current-microamp",
275274 (unsigned int *) &val, 2);
276275 if (ret) {
277276 /* Default to 24 mA RED LED, 50 mA IR LED */
@@ -502,7 +501,7 @@ MODULE_DEVICE_TABLE(of, max30100_dt_ids); · 224 unmodified lines
502501 static struct i2c_driver max30100_driver = {
503502 .driver = {
504503 .name = MAX30100_DRV_NAME,
505− .of_match_table = of_match_ptr(max30100_dt_ids),
504+ .of_match_table = max30100_dt_ids,
506505 },
507506 .probe = max30100_probe,
508507 .remove = max30100_remove,
drivers/iio/humidity/hts221_buffer.c+2−4
@@ -74,10 +74,9 @@ static irqreturn_t hts221_trigger_handler_thread(int irq, void *private) · 73 unmodified lines
7474
7575 int hts221_allocate_trigger(struct hts221_hw *hw)
7676 {
77+ struct st_sensors_platform_data *pdata = dev_get_platdata(hw->dev);
7778 struct iio_dev *iio_dev = iio_priv_to_dev(hw);
7879 bool irq_active_low = false, open_drain = false;
79− struct device_node *np = hw->dev->of_node;
80− struct st_sensors_platform_data *pdata;
8180 unsigned long irq_type;
8281 int err;
8382
@@ -106,8 +105,7 @@ int hts221_allocate_trigger(struct hts221_hw *hw) · 22 unmodified lines
106105 if (err < 0)
107106 return err;
108107
109− pdata = (struct st_sensors_platform_data *)hw->dev->platform_data;
110− if ((np && of_property_read_bool(np, "drive-open-drain")) ||
108+ if (device_property_read_bool(hw->dev, "drive-open-drain") ||
111109 (pdata && pdata->open_drain)) {
112110 irq_type |= IRQF_SHARED;
113111 open_drain = true;
drivers/iio/humidity/hts221_i2c.c+3−3
@@ -32,8 +32,8 @@ static int hts221_i2c_probe(struct i2c_client *client, · 31 unmodified lines
3232
3333 regmap = devm_regmap_init_i2c(client, &hts221_i2c_regmap_config);
3434 if (IS_ERR(regmap)) {
35− dev_err(&client->dev, "Failed to register i2c regmap %d\n",
36− (int)PTR_ERR(regmap));
35+ dev_err(&client->dev, "Failed to register i2c regmap %ld\n",
36+ PTR_ERR(regmap));
3737 return PTR_ERR(regmap);
3838 }
3939
@@ -63,7 +63,7 @@ static struct i2c_driver hts221_driver = { · 23 unmodified lines
6363 .driver = {
6464 .name = "hts221_i2c",
6565 .pm = &hts221_pm_ops,
66− .of_match_table = of_match_ptr(hts221_i2c_of_match),
66+ .of_match_table = hts221_i2c_of_match,
6767 .acpi_match_table = ACPI_PTR(hts221_acpi_match),
6868 },
6969 .probe = hts221_i2c_probe,
drivers/iio/humidity/hts221_spi.c+3−3
@@ -31,8 +31,8 @@ static int hts221_spi_probe(struct spi_device *spi) · 30 unmodified lines
3131
3232 regmap = devm_regmap_init_spi(spi, &hts221_spi_regmap_config);
3333 if (IS_ERR(regmap)) {
34− dev_err(&spi->dev, "Failed to register spi regmap %d\n",
35− (int)PTR_ERR(regmap));
34+ dev_err(&spi->dev, "Failed to register spi regmap %ld\n",
35+ PTR_ERR(regmap));
3636 return PTR_ERR(regmap);
3737 }
3838
@@ -56,7 +56,7 @@ static struct spi_driver hts221_driver = { · 17 unmodified lines
5656 .driver = {
5757 .name = "hts221_spi",
5858 .pm = &hts221_pm_ops,
59− .of_match_table = of_match_ptr(hts221_spi_of_match),
59+ .of_match_table = hts221_spi_of_match,
6060 },
6161 .probe = hts221_spi_probe,
6262 .id_table = hts221_spi_id_table,
drivers/iio/imu/adis.c+1−1
@@ -419,7 +419,7 @@ int __adis_initial_startup(struct adis *adis) · 418 unmodified lines
419419
420420 if (prod_id != adis->data->prod_id)
421421 dev_warn(&adis->spi->dev,
422− "Device ID(%u) and product ID(%u) do not match.",
422+ "Device ID(%u) and product ID(%u) do not match.\n",
423423 adis->data->prod_id, prod_id);
424424
425425 return 0;
drivers/iio/imu/adis16400.c+10−9
@@ -258,7 +258,7 @@ static int adis16400_show_product_id(void *arg, u64 *val) · 257 unmodified lines
258258
259259 return 0;
260260 }
261−DEFINE_SIMPLE_ATTRIBUTE(adis16400_product_id_fops,
261+DEFINE_DEBUGFS_ATTRIBUTE(adis16400_product_id_fops,
262262 adis16400_show_product_id, NULL, "%lld\n");
263263
264264 static int adis16400_show_flash_count(void *arg, u64 *val)
@@ -275,7 +275,7 @@ static int adis16400_show_flash_count(void *arg, u64 *val) · 10 unmodified lines
275275
276276 return 0;
277277 }
278−DEFINE_SIMPLE_ATTRIBUTE(adis16400_flash_count_fops,
278+DEFINE_DEBUGFS_ATTRIBUTE(adis16400_flash_count_fops,
279279 adis16400_show_flash_count, NULL, "%lld\n");
280280
281281 static int adis16400_debugfs_init(struct iio_dev *indio_dev)
@@ -283,15 +283,16 @@ static int adis16400_debugfs_init(struct iio_dev *indio_dev) · 1 unmodified line
283283 struct adis16400_state *st = iio_priv(indio_dev);
284284
285285 if (st->variant->flags & ADIS16400_HAS_SERIAL_NUMBER)
286− debugfs_create_file("serial_number", 0400,
287− indio_dev->debugfs_dentry, st,
288− &adis16400_serial_number_fops);
286+ debugfs_create_file_unsafe("serial_number", 0400,
287+ indio_dev->debugfs_dentry, st,
288+ &adis16400_serial_number_fops);
289289 if (st->variant->flags & ADIS16400_HAS_PROD_ID)
290− debugfs_create_file("product_id", 0400,
290+ debugfs_create_file_unsafe("product_id", 0400,
291+ indio_dev->debugfs_dentry, st,
292+ &adis16400_product_id_fops);
293+ debugfs_create_file_unsafe("flash_count", 0400,
291294 indio_dev->debugfs_dentry, st,
292− &adis16400_product_id_fops);
293− debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry,
294− st, &adis16400_flash_count_fops);
295+ &adis16400_flash_count_fops);
295296
296297 return 0;
297298 }
drivers/iio/imu/adis16460.c+15−12
@@ -87,8 +87,8 @@ static int adis16460_show_serial_number(void *arg, u64 *val) · 86 unmodified lines
8787
8888 return 0;
8989 }
90−DEFINE_SIMPLE_ATTRIBUTE(adis16460_serial_number_fops,
91− adis16460_show_serial_number, NULL, "0x%.4llx\n");
90+DEFINE_DEBUGFS_ATTRIBUTE(adis16460_serial_number_fops,
91+ adis16460_show_serial_number, NULL, "0x%.4llx\n");
9292
9393 static int adis16460_show_product_id(void *arg, u64 *val)
9494 {
@@ -105,8 +105,8 @@ static int adis16460_show_product_id(void *arg, u64 *val) · 10 unmodified lines
105105
106106 return 0;
107107 }
108−DEFINE_SIMPLE_ATTRIBUTE(adis16460_product_id_fops,
109− adis16460_show_product_id, NULL, "%llu\n");
108+DEFINE_DEBUGFS_ATTRIBUTE(adis16460_product_id_fops,
109+ adis16460_show_product_id, NULL, "%llu\n");
110110
111111 static int adis16460_show_flash_count(void *arg, u64 *val)
112112 {
@@ -123,19 +123,22 @@ static int adis16460_show_flash_count(void *arg, u64 *val) · 10 unmodified lines
123123
124124 return 0;
125125 }
126−DEFINE_SIMPLE_ATTRIBUTE(adis16460_flash_count_fops,
127− adis16460_show_flash_count, NULL, "%lld\n");
126+DEFINE_DEBUGFS_ATTRIBUTE(adis16460_flash_count_fops,
127+ adis16460_show_flash_count, NULL, "%lld\n");
128128
129129 static int adis16460_debugfs_init(struct iio_dev *indio_dev)
130130 {
131131 struct adis16460 *adis16460 = iio_priv(indio_dev);
132132
133− debugfs_create_file("serial_number", 0400, indio_dev->debugfs_dentry,
134− adis16460, &adis16460_serial_number_fops);
135− debugfs_create_file("product_id", 0400, indio_dev->debugfs_dentry,
136− adis16460, &adis16460_product_id_fops);
137− debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry,
138− adis16460, &adis16460_flash_count_fops);
133+ debugfs_create_file_unsafe("serial_number", 0400,
134+ indio_dev->debugfs_dentry, adis16460,
135+ &adis16460_serial_number_fops);
136+ debugfs_create_file_unsafe("product_id", 0400,
137+ indio_dev->debugfs_dentry, adis16460,
138+ &adis16460_product_id_fops);
139+ debugfs_create_file_unsafe("flash_count", 0400,
140+ indio_dev->debugfs_dentry, adis16460,
141+ &adis16460_flash_count_fops);
139142
140143 return 0;
141144 }
drivers/iio/imu/bmi160/bmi160_i2c.c+2−2
@@ -24,8 +24,8 @@ static int bmi160_i2c_probe(struct i2c_client *client, · 23 unmodified lines
2424
2525 regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config);
2626 if (IS_ERR(regmap)) {
27− dev_err(&client->dev, "Failed to register i2c regmap %d\n",
28− (int)PTR_ERR(regmap));
27+ dev_err(&client->dev, "Failed to register i2c regmap: %pe\n",
28+ regmap);
2929 return PTR_ERR(regmap);
3030 }
3131
drivers/iio/imu/bmi160/bmi160_spi.c+2−2
@@ -20,8 +20,8 @@ static int bmi160_spi_probe(struct spi_device *spi) · 19 unmodified lines
2020
2121 regmap = devm_regmap_init_spi(spi, &bmi160_regmap_config);
2222 if (IS_ERR(regmap)) {
23− dev_err(&spi->dev, "Failed to register spi regmap %d\n",
24− (int)PTR_ERR(regmap));
23+ dev_err(&spi->dev, "Failed to register spi regmap: %pe\n",
24+ regmap);
2525 return PTR_ERR(regmap);
2626 }
2727 return bmi160_core_probe(&spi->dev, regmap, id->name, true);
drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c+5−3
@@ -135,6 +135,7 @@ int inv_mpu_acpi_create_mux_client(struct i2c_client *client) · 134 unmodified lines
135135 st->mux_client = NULL;
136136 if (ACPI_HANDLE(&client->dev)) {
137137 struct i2c_board_info info;
138+ struct i2c_client *mux_client;
138139 struct acpi_device *adev;
139140 int ret = -1;
140141
@@ -172,9 +173,10 @@ int inv_mpu_acpi_create_mux_client(struct i2c_client *client) · 31 unmodified lines
172173 } else
173174 return 0; /* no secondary addr, which is OK */
174175 }
175− st->mux_client = i2c_new_device(st->muxc->adapter[0], &info);
176− if (!st->mux_client)
177− return -ENODEV;
176+ mux_client = i2c_new_client_device(st->muxc->adapter[0], &info);
177+ if (IS_ERR(mux_client))
178+ return PTR_ERR(mux_client);
179+ st->mux_client = mux_client;
178180 }
179181
180182 return 0;
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c+21−2
@@ -526,7 +526,7 @@ static int inv_mpu6050_sensor_set(struct inv_mpu6050_state *st, int reg, · 525 unmodified lines
526526 __be16 d = cpu_to_be16(val);
527527
528528 ind = (axis - IIO_MOD_X) * 2;
529− result = regmap_bulk_write(st->map, reg + ind, (u8 *)&d, 2);
529+ result = regmap_bulk_write(st->map, reg + ind, &d, sizeof(d));
530530 if (result)
531531 return -EINVAL;
532532
@@ -540,7 +540,7 @@ static int inv_mpu6050_sensor_show(struct inv_mpu6050_state *st, int reg, · 7 unmodified lines
540540 __be16 d;
541541
542542 ind = (axis - IIO_MOD_X) * 2;
543− result = regmap_bulk_read(st->map, reg + ind, (u8 *)&d, 2);
543+ result = regmap_bulk_read(st->map, reg + ind, &d, sizeof(d));
544544 if (result)
545545 return -EINVAL;
546546 *val = (short)be16_to_cpup(&d);
@@ -1248,12 +1248,31 @@ static const struct attribute_group inv_attribute_group = { · 701 unmodified lines
12481248 .attrs = inv_attributes
12491249 };
12501250
1251+static int inv_mpu6050_reg_access(struct iio_dev *indio_dev,
1252+ unsigned int reg,
1253+ unsigned int writeval,
1254+ unsigned int *readval)
1255+{
1256+ struct inv_mpu6050_state *st = iio_priv(indio_dev);
1257+ int ret;
1258+
1259+ mutex_lock(&st->lock);
1260+ if (readval)
1261+ ret = regmap_read(st->map, reg, readval);
1262+ else
1263+ ret = regmap_write(st->map, reg, writeval);
1264+ mutex_unlock(&st->lock);
1265+
1266+ return ret;
1267+}
1268+
12511269 static const struct iio_info mpu_info = {
12521270 .read_raw = &inv_mpu6050_read_raw,
12531271 .write_raw = &inv_mpu6050_write_raw,
12541272 .write_raw_get_fmt = &inv_write_raw_get_fmt,
12551273 .attrs = &inv_attribute_group,
12561274 .validate_trigger = inv_mpu6050_validate_trigger,
1275+ .debugfs_reg_access = &inv_mpu6050_reg_access,
12571276 };
12581277
12591278 /**
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c+2−2
@@ -122,8 +122,8 @@ static int inv_mpu_probe(struct i2c_client *client, · 121 unmodified lines
122122
123123 regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config);
124124 if (IS_ERR(regmap)) {
125− dev_err(&client->dev, "Failed to register i2c regmap %d\n",
126− (int)PTR_ERR(regmap));
125+ dev_err(&client->dev, "Failed to register i2c regmap: %pe\n",
126+ regmap);
127127 return PTR_ERR(regmap);
128128 }
129129
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c+2−2
@@ -53,8 +53,8 @@ static int inv_mpu_probe(struct spi_device *spi) · 52 unmodified lines
5353
5454 regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config);
5555 if (IS_ERR(regmap)) {
56− dev_err(&spi->dev, "Failed to register spi regmap %d\n",
57− (int)PTR_ERR(regmap));
56+ dev_err(&spi->dev, "Failed to register spi regmap: %pe\n",
57+ regmap);
5858 return PTR_ERR(regmap);
5959 }
6060
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h+1−1
@@ -111,7 +111,7 @@ struct st_lsm6dsx_odr { · 110 unmodified lines
111111 u8 val;
112112 };
113113
114−#define ST_LSM6DSX_ODR_LIST_SIZE 6
114+#define ST_LSM6DSX_ODR_LIST_SIZE 8
115115 struct st_lsm6dsx_odr_table_entry {
116116 struct st_lsm6dsx_reg reg;
117117
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c+96−0
@@ -88,6 +88,69 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = { · 87 unmodified lines
8888 .len = 6,
8989 },
9090 },
91+ /* LIS3MDL */
92+ {
93+ .i2c_addr = { 0x1e },
94+ .wai = {
95+ .addr = 0x0f,
96+ .val = 0x3d,
97+ },
98+ .id = ST_LSM6DSX_ID_MAGN,
99+ .odr_table = {
100+ .reg = {
101+ .addr = 0x20,
102+ .mask = GENMASK(4, 2),
103+ },
104+ .odr_avl[0] = { 1000, 0x0 },
105+ .odr_avl[1] = { 2000, 0x1 },
106+ .odr_avl[2] = { 3000, 0x2 },
107+ .odr_avl[3] = { 5000, 0x3 },
108+ .odr_avl[4] = { 10000, 0x4 },
109+ .odr_avl[5] = { 20000, 0x5 },
110+ .odr_avl[6] = { 40000, 0x6 },
111+ .odr_avl[7] = { 80000, 0x7 },
112+ .odr_len = 8,
113+ },
114+ .fs_table = {
115+ .reg = {
116+ .addr = 0x21,
117+ .mask = GENMASK(6, 5),
118+ },
119+ .fs_avl[0] = {
120+ .gain = 146,
121+ .val = 0x00,
122+ }, /* 4000 uG/LSB */
123+ .fs_avl[1] = {
124+ .gain = 292,
125+ .val = 0x01,
126+ }, /* 8000 uG/LSB */
127+ .fs_avl[2] = {
128+ .gain = 438,
129+ .val = 0x02,
130+ }, /* 12000 uG/LSB */
131+ .fs_avl[3] = {
132+ .gain = 584,
133+ .val = 0x03,
134+ }, /* 16000 uG/LSB */
135+ .fs_len = 4,
136+ },
137+ .pwr_table = {
138+ .reg = {
139+ .addr = 0x22,
140+ .mask = GENMASK(1, 0),
141+ },
142+ .off_val = 0x2,
143+ .on_val = 0x0,
144+ },
145+ .bdu = {
146+ .addr = 0x24,
147+ .mask = BIT(6),
148+ },
149+ .out = {
150+ .addr = 0x28,
151+ .len = 6,
152+ },
153+ },
91154 };
92155
93156 static void st_lsm6dsx_shub_wait_complete(struct st_lsm6dsx_hw *hw)
@@ -517,6 +580,36 @@ st_lsm6dsx_shub_read_raw(struct iio_dev *iio_dev, · 423 unmodified lines
517580 return ret;
518581 }
519582
583+static int
584+st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor,
585+ u32 gain)
586+{
587+ const struct st_lsm6dsx_fs_table_entry *fs_table;
588+ int i, err;
589+
590+ fs_table = &sensor->ext_info.settings->fs_table;
591+ if (!fs_table->reg.addr)
592+ return -ENOTSUPP;
593+
594+ for (i = 0; i < fs_table->fs_len; i++) {
595+ if (fs_table->fs_avl[i].gain == gain)
596+ break;
597+ }
598+
599+ if (i == fs_table->fs_len)
600+ return -EINVAL;
601+
602+ err = st_lsm6dsx_shub_write_with_mask(sensor, fs_table->reg.addr,
603+ fs_table->reg.mask,
604+ fs_table->fs_avl[i].val);
605+ if (err < 0)
606+ return err;
607+
608+ sensor->gain = gain;
609+
610+ return 0;
611+}
612+
520613 static int
521614 st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
522615 struct iio_chan_spec const *chan,
@@ -539,6 +632,9 @@ st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev, · 16 unmodified lines
539632 sensor->odr = val;
540633 break;
541634 }
635+ case IIO_CHAN_INFO_SCALE:
636+ err = st_lsm6dsx_shub_set_full_scale(sensor, val2);
637+ break;
542638 default:
543639 err = -EINVAL;
544640 break;
drivers/iio/industrialio-buffer.c+8−10
@@ -316,8 +316,7 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev, · 315 unmodified lines
316316 const unsigned long *mask;
317317 unsigned long *trialmask;
318318
319− trialmask = kcalloc(BITS_TO_LONGS(indio_dev->masklength),
320− sizeof(*trialmask), GFP_KERNEL);
319+ trialmask = bitmap_zalloc(indio_dev->masklength, GFP_KERNEL);
321320 if (trialmask == NULL)
322321 return -ENOMEM;
323322 if (!indio_dev->masklength) {
@@ -687,6 +686,13 @@ static int iio_verify_update(struct iio_dev *indio_dev, · 363 unmodified lines
687686 bool scan_timestamp;
688687 unsigned int modes;
689688
689+ if (insert_buffer &&
690+ bitmap_empty(insert_buffer->scan_mask, indio_dev->masklength)) {
691+ dev_dbg(&indio_dev->dev,
692+ "At least one scan element must be enabled first\n");
693+ return -EINVAL;
694+ }
695+
690696 memset(config, 0, sizeof(*config));
691697 config->watermark = ~0;
692698
@@ -1277,11 +1283,6 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) · 584 unmodified lines
12771283
12781284 indio_dev->groups[indio_dev->groupcounter++] = &buffer->buffer_group;
12791285
1280− if (buffer->scan_el_attrs != NULL) {
1281− attr = buffer->scan_el_attrs->attrs;
1282− while (*attr++ != NULL)
1283− attrcount_orig++;
1284− }
12851286 attrcount = attrcount_orig;
12861287 INIT_LIST_HEAD(&buffer->scan_el_dev_attr_list);
12871288 channels = indio_dev->channels;
@@ -1319,9 +1320,6 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) · 31 unmodified lines
13191320 ret = -ENOMEM;
13201321 goto error_free_scan_mask;
13211322 }
1322− if (buffer->scan_el_attrs)
1323− memcpy(buffer->scan_el_group.attrs, buffer->scan_el_attrs,
1324− sizeof(buffer->scan_el_group.attrs[0])*attrcount_orig);
13251323 attrn = attrcount_orig;
13261324
13271325 list_for_each_entry(p, &buffer->scan_el_dev_attr_list, l)
drivers/iio/industrialio-core.c+20−68
@@ -572,46 +572,46 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type, · 571 unmodified lines
572572
573573 switch (type) {
574574 case IIO_VAL_INT:
575− return snprintf(buf, len, "%d", vals[0]);
575+ return scnprintf(buf, len, "%d", vals[0]);
576576 case IIO_VAL_INT_PLUS_MICRO_DB:
577577 scale_db = true;
578578 /* fall through */
579579 case IIO_VAL_INT_PLUS_MICRO:
580580 if (vals[1] < 0)
581− return snprintf(buf, len, "-%d.%06u%s", abs(vals[0]),
581+ return scnprintf(buf, len, "-%d.%06u%s", abs(vals[0]),
582582 -vals[1], scale_db ? " dB" : "");
583583 else
584− return snprintf(buf, len, "%d.%06u%s", vals[0], vals[1],
584+ return scnprintf(buf, len, "%d.%06u%s", vals[0], vals[1],
585585 scale_db ? " dB" : "");
586586 case IIO_VAL_INT_PLUS_NANO:
587587 if (vals[1] < 0)
588− return snprintf(buf, len, "-%d.%09u", abs(vals[0]),
588+ return scnprintf(buf, len, "-%d.%09u", abs(vals[0]),
589589 -vals[1]);
590590 else
591− return snprintf(buf, len, "%d.%09u", vals[0], vals[1]);
591+ return scnprintf(buf, len, "%d.%09u", vals[0], vals[1]);
592592 case IIO_VAL_FRACTIONAL:
593593 tmp = div_s64((s64)vals[0] * 1000000000LL, vals[1]);
594594 tmp1 = vals[1];
595595 tmp0 = (int)div_s64_rem(tmp, 1000000000, &tmp1);
596− return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
596+ return scnprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
597597 case IIO_VAL_FRACTIONAL_LOG2:
598598 tmp = shift_right((s64)vals[0] * 1000000000LL, vals[1]);
599599 tmp0 = (int)div_s64_rem(tmp, 1000000000LL, &tmp1);
600− return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
600+ return scnprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
601601 case IIO_VAL_INT_MULTIPLE:
602602 {
603603 int i;
604604 int l = 0;
605605
606606 for (i = 0; i < size; ++i) {
607− l += snprintf(&buf[l], len - l, "%d ", vals[i]);
607+ l += scnprintf(&buf[l], len - l, "%d ", vals[i]);
608608 if (l >= len)
609609 break;
610610 }
611611 return l;
612612 }
613613 case IIO_VAL_CHAR:
614− return snprintf(buf, len, "%c", (char)vals[0]);
614+ return scnprintf(buf, len, "%c", (char)vals[0]);
615615 default:
616616 return 0;
617617 }
@@ -682,10 +682,10 @@ static ssize_t iio_format_avail_list(char *buf, const int *vals, · 64 unmodified lines
682682 if (len >= PAGE_SIZE)
683683 return -EFBIG;
684684 if (i < length - 1)
685− len += snprintf(buf + len, PAGE_SIZE - len,
685+ len += scnprintf(buf + len, PAGE_SIZE - len,
686686 " ");
687687 else
688− len += snprintf(buf + len, PAGE_SIZE - len,
688+ len += scnprintf(buf + len, PAGE_SIZE - len,
689689 "\n");
690690 if (len >= PAGE_SIZE)
691691 return -EFBIG;
@@ -698,10 +698,10 @@ static ssize_t iio_format_avail_list(char *buf, const int *vals, · 6 unmodified lines
698698 if (len >= PAGE_SIZE)
699699 return -EFBIG;
700700 if (i < length / 2 - 1)
701− len += snprintf(buf + len, PAGE_SIZE - len,
701+ len += scnprintf(buf + len, PAGE_SIZE - len,
702702 " ");
703703 else
704− len += snprintf(buf + len, PAGE_SIZE - len,
704+ len += scnprintf(buf + len, PAGE_SIZE - len,
705705 "\n");
706706 if (len >= PAGE_SIZE)
707707 return -EFBIG;
@@ -725,10 +725,10 @@ static ssize_t iio_format_avail_range(char *buf, const int *vals, int type) · 17 unmodified lines
725725 if (len >= PAGE_SIZE)
726726 return -EFBIG;
727727 if (i < 2)
728− len += snprintf(buf + len, PAGE_SIZE - len,
728+ len += scnprintf(buf + len, PAGE_SIZE - len,
729729 " ");
730730 else
731− len += snprintf(buf + len, PAGE_SIZE - len,
731+ len += scnprintf(buf + len, PAGE_SIZE - len,
732732 "]\n");
733733 if (len >= PAGE_SIZE)
734734 return -EFBIG;
@@ -741,10 +741,10 @@ static ssize_t iio_format_avail_range(char *buf, const int *vals, int type) · 6 unmodified lines
741741 if (len >= PAGE_SIZE)
742742 return -EFBIG;
743743 if (i < 2)
744− len += snprintf(buf + len, PAGE_SIZE - len,
744+ len += scnprintf(buf + len, PAGE_SIZE - len,
745745 " ");
746746 else
747− len += snprintf(buf + len, PAGE_SIZE - len,
747+ len += scnprintf(buf + len, PAGE_SIZE - len,
748748 "]\n");
749749 if (len >= PAGE_SIZE)
750750 return -EFBIG;
@@ -1552,17 +1552,6 @@ static void devm_iio_device_release(struct device *dev, void *res) · 801 unmodified lines
15521552 iio_device_free(*(struct iio_dev **)res);
15531553 }
15541554
1555−int devm_iio_device_match(struct device *dev, void *res, void *data)
1556−{
1557− struct iio_dev **r = res;
1558− if (!r || !*r) {
1559− WARN_ON(!r || !*r);
1560− return 0;
1561− }
1562− return *r == data;
1563−}
1564−EXPORT_SYMBOL_GPL(devm_iio_device_match);
1565−
15661555 /**
15671556 * devm_iio_device_alloc - Resource-managed iio_device_alloc()
15681557 * @dev: Device to allocate iio_dev for
@@ -1571,9 +1560,6 @@ EXPORT_SYMBOL_GPL(devm_iio_device_match); · 2 unmodified lines
15711560 * Managed iio_device_alloc. iio_dev allocated with this function is
15721561 * automatically freed on driver detach.
15731562 *
1574− * If an iio_dev allocated with this function needs to be freed separately,
1575− * devm_iio_device_free() must be used.
1576− *
15771563 * RETURNS:
15781564 * Pointer to allocated iio_dev on success, NULL on failure.
15791565 */
@@ -1598,23 +1584,6 @@ struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv) · 18 unmodified lines
15981584 }
15991585 EXPORT_SYMBOL_GPL(devm_iio_device_alloc);
16001586
1601−/**
1602− * devm_iio_device_free - Resource-managed iio_device_free()
1603− * @dev: Device this iio_dev belongs to
1604− * @iio_dev: the iio_dev associated with the device
1605− *
1606− * Free iio_dev allocated with devm_iio_device_alloc().
1607− */
1608−void devm_iio_device_free(struct device *dev, struct iio_dev *iio_dev)
1609−{
1610− int rc;
1611−
1612− rc = devres_release(dev, devm_iio_device_release,
1613− devm_iio_device_match, iio_dev);
1614− WARN_ON(rc);
1615−}
1616−EXPORT_SYMBOL_GPL(devm_iio_device_free);
1617−
16181587 /**
16191588 * iio_chrdev_open() - chrdev file open for buffer access and ioctls
16201589 * @inode: Inode structure for identifying the device in the file system
@@ -1717,6 +1686,9 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) · 96 unmodified lines
17171686 {
17181687 int ret;
17191688
1689+ if (!indio_dev->info)
1690+ return -EINVAL;
1691+
17201692 indio_dev->driver_module = this_mod;
17211693 /* If the calling driver did not initialize of_node, do it here */
17221694 if (!indio_dev->dev.of_node && indio_dev->dev.parent)
@@ -1729,9 +1701,6 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) · 6 unmodified lines
17291701 if (ret < 0)
17301702 return ret;
17311703
1732− if (!indio_dev->info)
1733− return -EINVAL;
1734−
17351704 /* configure elements for the chrdev */
17361705 indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
17371706
@@ -1836,23 +1805,6 @@ int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev, · 98 unmodified lines
18361805 }
18371806 EXPORT_SYMBOL_GPL(__devm_iio_device_register);
18381807
1839−/**
1840− * devm_iio_device_unregister - Resource-managed iio_device_unregister()
1841− * @dev: Device this iio_dev belongs to
1842− * @indio_dev: the iio_dev associated with the device
1843− *
1844− * Unregister iio_dev registered with devm_iio_device_register().
1845− */
1846−void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev)
1847−{
1848− int rc;
1849−
1850− rc = devres_release(dev, devm_iio_device_unreg,
1851− devm_iio_device_match, indio_dev);
1852− WARN_ON(rc);
1853−}
1854−EXPORT_SYMBOL_GPL(devm_iio_device_unregister);
1855−
18561808 /**
18571809 * iio_device_claim_direct_mode - Keep device in direct mode
18581810 * @indio_dev: the iio_dev associated with the device
drivers/iio/industrialio-trigger.c+0−53
@@ -585,18 +585,6 @@ static void devm_iio_trigger_release(struct device *dev, void *res) · 584 unmodified lines
585585 iio_trigger_free(*(struct iio_trigger **)res);
586586 }
587587
588−static int devm_iio_trigger_match(struct device *dev, void *res, void *data)
589−{
590− struct iio_trigger **r = res;
591−
592− if (!r || !*r) {
593− WARN_ON(!r || !*r);
594− return 0;
595− }
596−
597− return *r == data;
598−}
599−
600588 /**
601589 * devm_iio_trigger_alloc - Resource-managed iio_trigger_alloc()
602590 * @dev: Device to allocate iio_trigger for
@@ -608,9 +596,6 @@ static int devm_iio_trigger_match(struct device *dev, void *res, void *data) · 5 unmodified lines
608596 * Managed iio_trigger_alloc. iio_trigger allocated with this function is
609597 * automatically freed on driver detach.
610598 *
611− * If an iio_trigger allocated with this function needs to be freed separately,
612− * devm_iio_trigger_free() must be used.
613− *
614599 * RETURNS:
615600 * Pointer to allocated iio_trigger on success, NULL on failure.
616601 */
@@ -640,23 +625,6 @@ struct iio_trigger *devm_iio_trigger_alloc(struct device *dev, · 23 unmodified lines
640625 }
641626 EXPORT_SYMBOL_GPL(devm_iio_trigger_alloc);
642627
643−/**
644− * devm_iio_trigger_free - Resource-managed iio_trigger_free()
645− * @dev: Device this iio_dev belongs to
646− * @iio_trig: the iio_trigger associated with the device
647− *
648− * Free iio_trigger allocated with devm_iio_trigger_alloc().
649− */
650−void devm_iio_trigger_free(struct device *dev, struct iio_trigger *iio_trig)
651−{
652− int rc;
653−
654− rc = devres_release(dev, devm_iio_trigger_release,
655− devm_iio_trigger_match, iio_trig);
656− WARN_ON(rc);
657−}
658−EXPORT_SYMBOL_GPL(devm_iio_trigger_free);
659−
660628 static void devm_iio_trigger_unreg(struct device *dev, void *res)
661629 {
662630 iio_trigger_unregister(*(struct iio_trigger **)res);
@@ -673,9 +641,6 @@ static void devm_iio_trigger_unreg(struct device *dev, void *res) · 10 unmodified lines
673641 * calls iio_trigger_register() internally. Refer to that function for more
674642 * information.
675643 *
676− * If an iio_trigger registered with this function needs to be unregistered
677− * separately, devm_iio_trigger_unregister() must be used.
678− *
679644 * RETURNS:
680645 * 0 on success, negative error number on failure.
681646 */
@@ -701,24 +666,6 @@ int __devm_iio_trigger_register(struct device *dev, · 19 unmodified lines
701666 }
702667 EXPORT_SYMBOL_GPL(__devm_iio_trigger_register);
703668
704−/**
705− * devm_iio_trigger_unregister - Resource-managed iio_trigger_unregister()
706− * @dev: device this iio_trigger belongs to
707− * @trig_info: the trigger associated with the device
708− *
709− * Unregister trigger registered with devm_iio_trigger_register().
710− */
711−void devm_iio_trigger_unregister(struct device *dev,
712− struct iio_trigger *trig_info)
713−{
714− int rc;
715−
716− rc = devres_release(dev, devm_iio_trigger_unreg, devm_iio_trigger_match,
717− trig_info);
718− WARN_ON(rc);
719−}
720−EXPORT_SYMBOL_GPL(devm_iio_trigger_unregister);
721−
722669 bool iio_trigger_using_own(struct iio_dev *indio_dev)
723670 {
724671 return indio_dev->trig->attached_own_device;
drivers/iio/inkern.c+0−27
@@ -360,18 +360,6 @@ static void devm_iio_channel_free(struct device *dev, void *res) · 359 unmodified lines
360360 iio_channel_release(channel);
361361 }
362362
363−static int devm_iio_channel_match(struct device *dev, void *res, void *data)
364−{
365− struct iio_channel **r = res;
366−
367− if (!r || !*r) {
368− WARN_ON(!r || !*r);
369− return 0;
370− }
371−
372− return *r == data;
373−}
374−
375363 struct iio_channel *devm_iio_channel_get(struct device *dev,
376364 const char *channel_name)
377365 {
@@ -394,13 +382,6 @@ struct iio_channel *devm_iio_channel_get(struct device *dev, · 16 unmodified lines
394382 }
395383 EXPORT_SYMBOL_GPL(devm_iio_channel_get);
396384
397−void devm_iio_channel_release(struct device *dev, struct iio_channel *channel)
398−{
399− WARN_ON(devres_release(dev, devm_iio_channel_free,
400− devm_iio_channel_match, channel));
401−}
402−EXPORT_SYMBOL_GPL(devm_iio_channel_release);
403−
404385 struct iio_channel *iio_channel_get_all(struct device *dev)
405386 {
406387 const char *name;
@@ -514,14 +495,6 @@ struct iio_channel *devm_iio_channel_get_all(struct device *dev) · 107 unmodified lines
514495 }
515496 EXPORT_SYMBOL_GPL(devm_iio_channel_get_all);
516497
517−void devm_iio_channel_release_all(struct device *dev,
518− struct iio_channel *channels)
519−{
520− WARN_ON(devres_release(dev, devm_iio_channel_free_all,
521− devm_iio_channel_match, channels));
522−}
523−EXPORT_SYMBOL_GPL(devm_iio_channel_release_all);
524−
525498 static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,
526499 enum iio_chan_info_enum info)
527500 {
drivers/iio/light/isl29125.c+19−9
@@ -213,13 +213,24 @@ static const struct iio_info isl29125_info = { · 212 unmodified lines
213213 .attrs = &isl29125_attribute_group,
214214 };
215215
216−static int isl29125_buffer_preenable(struct iio_dev *indio_dev)
216+static int isl29125_buffer_postenable(struct iio_dev *indio_dev)
217217 {
218218 struct isl29125_data *data = iio_priv(indio_dev);
219+ int err;
220+
221+ err = iio_triggered_buffer_postenable(indio_dev);
222+ if (err)
223+ return err;
219224
220225 data->conf1 |= ISL29125_MODE_RGB;
221− return i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
226+ err = i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
222227 data->conf1);
228+ if (err) {
229+ iio_triggered_buffer_predisable(indio_dev);
230+ return err;
231+ }
232+
233+ return 0;
223234 }
224235
225236 static int isl29125_buffer_predisable(struct iio_dev *indio_dev)
@@ -227,19 +238,18 @@ static int isl29125_buffer_predisable(struct iio_dev *indio_dev) · 1 unmodified line
227238 struct isl29125_data *data = iio_priv(indio_dev);
228239 int ret;
229240
230− ret = iio_triggered_buffer_predisable(indio_dev);
231− if (ret < 0)
232− return ret;
233−
234241 data->conf1 &= ~ISL29125_MODE_MASK;
235242 data->conf1 |= ISL29125_MODE_PD;
236− return i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
243+ ret = i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
237244 data->conf1);
245+
246+ iio_triggered_buffer_predisable(indio_dev);
247+
248+ return ret;
238249 }
239250
240251 static const struct iio_buffer_setup_ops isl29125_buffer_setup_ops = {
241− .preenable = isl29125_buffer_preenable,
242− .postenable = &iio_triggered_buffer_postenable,
252+ .postenable = isl29125_buffer_postenable,
243253 .predisable = isl29125_buffer_predisable,
244254 };
245255
drivers/iio/light/ltr501.c+1−1
@@ -1263,7 +1263,7 @@ static irqreturn_t ltr501_trigger_handler(int irq, void *p) · 1262 unmodified lines
12631263
12641264 if (mask & LTR501_STATUS_ALS_RDY) {
12651265 ret = regmap_bulk_read(data->regmap, LTR501_ALS_DATA1,
1266− (u8 *)als_buf, sizeof(als_buf));
1266+ als_buf, sizeof(als_buf));
12671267 if (ret < 0)
12681268 return ret;
12691269 if (test_bit(0, indio_dev->active_scan_mask))
drivers/iio/light/st_uvis25_i2c.c+2−2
@@ -31,8 +31,8 @@ static int st_uvis25_i2c_probe(struct i2c_client *client, · 30 unmodified lines
3131
3232 regmap = devm_regmap_init_i2c(client, &st_uvis25_i2c_regmap_config);
3333 if (IS_ERR(regmap)) {
34− dev_err(&client->dev, "Failed to register i2c regmap %d\n",
35− (int)PTR_ERR(regmap));
34+ dev_err(&client->dev, "Failed to register i2c regmap %ld\n",
35+ PTR_ERR(regmap));
3636 return PTR_ERR(regmap);
3737 }
3838
drivers/iio/light/st_uvis25_spi.c+2−2
@@ -31,8 +31,8 @@ static int st_uvis25_spi_probe(struct spi_device *spi) · 30 unmodified lines
3131
3232 regmap = devm_regmap_init_spi(spi, &st_uvis25_spi_regmap_config);
3333 if (IS_ERR(regmap)) {
34− dev_err(&spi->dev, "Failed to register spi regmap %d\n",
35− (int)PTR_ERR(regmap));
34+ dev_err(&spi->dev, "Failed to register spi regmap %ld\n",
35+ PTR_ERR(regmap));
3636 return PTR_ERR(regmap);
3737 }
3838
drivers/iio/light/tsl2563.c+1−1
@@ -69,7 +69,7 @@ · 68 unmodified lines
6969 #define TSL2563_TIMING_GAIN16 0x10
7070 #define TSL2563_TIMING_GAIN1 0x00
7171
72−#define TSL2563_INT_DISBLED 0x00
72+#define TSL2563_INT_DISABLED 0x00
7373 #define TSL2563_INT_LEVEL 0x10
7474 #define TSL2563_INT_PERSIST(n) ((n) & 0x0F)
7575
drivers/iio/light/tsl2772.c+3−3
@@ -932,7 +932,7 @@ static ssize_t in_illuminance0_target_input_show(struct device *dev, · 931 unmodified lines
932932 {
933933 struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));
934934
935− return snprintf(buf, PAGE_SIZE, "%d\n", chip->settings.als_cal_target);
935+ return scnprintf(buf, PAGE_SIZE, "%d\n", chip->settings.als_cal_target);
936936 }
937937
938938 static ssize_t in_illuminance0_target_input_store(struct device *dev,
@@ -986,7 +986,7 @@ static ssize_t in_illuminance0_lux_table_show(struct device *dev, · 47 unmodified lines
986986 int offset = 0;
987987
988988 while (i < TSL2772_MAX_LUX_TABLE_SIZE) {
989− offset += snprintf(buf + offset, PAGE_SIZE, "%u,%u,",
989+ offset += scnprintf(buf + offset, PAGE_SIZE - offset, "%u,%u,",
990990 chip->tsl2772_device_lux[i].ch0,
991991 chip->tsl2772_device_lux[i].ch1);
992992 if (chip->tsl2772_device_lux[i].ch0 == 0) {
@@ -1000,7 +1000,7 @@ static ssize_t in_illuminance0_lux_table_show(struct device *dev, · 7 unmodified lines
10001000 i++;
10011001 }
10021002
1003− offset += snprintf(buf + offset, PAGE_SIZE, "\n");
1003+ offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n");
10041004 return offset;
10051005 }
10061006
drivers/iio/light/vcnl4000.c+25−0
@@ -83,6 +83,7 @@ struct vcnl4000_data { · 82 unmodified lines
8383 struct mutex vcnl4000_lock;
8484 struct vcnl4200_channel vcnl4200_al;
8585 struct vcnl4200_channel vcnl4200_ps;
86+ uint32_t near_level;
8687 };
8788
8889 struct vcnl4000_chip_spec {
@@ -343,6 +344,25 @@ static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = { · 254 unmodified lines
343344 },
344345 };
345346
347+static ssize_t vcnl4000_read_near_level(struct iio_dev *indio_dev,
348+ uintptr_t priv,
349+ const struct iio_chan_spec *chan,
350+ char *buf)
351+{
352+ struct vcnl4000_data *data = iio_priv(indio_dev);
353+
354+ return sprintf(buf, "%u\n", data->near_level);
355+}
356+
357+static const struct iio_chan_spec_ext_info vcnl4000_ext_info[] = {
358+ {
359+ .name = "nearlevel",
360+ .shared = IIO_SEPARATE,
361+ .read = vcnl4000_read_near_level,
362+ },
363+ { /* sentinel */ }
364+};
365+
346366 static const struct iio_chan_spec vcnl4000_channels[] = {
347367 {
348368 .type = IIO_LIGHT,
@@ -351,6 +371,7 @@ static const struct iio_chan_spec vcnl4000_channels[] = { · 2 unmodified lines
351371 }, {
352372 .type = IIO_PROXIMITY,
353373 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
374+ .ext_info = vcnl4000_ext_info,
354375 }
355376 };
356377
@@ -440,6 +461,10 @@ static int vcnl4000_probe(struct i2c_client *client, · 83 unmodified lines
440461 dev_dbg(&client->dev, "%s Ambient light/proximity sensor, Rev: %02x\n",
441462 data->chip_spec->prod, data->rev);
442463
464+ if (device_property_read_u32(&client->dev, "proximity-near-level",
465+ &data->near_level))
466+ data->near_level = 0;
467+
443468 indio_dev->dev.parent = &client->dev;
444469 indio_dev->info = &vcnl4000_info;
445470 indio_dev->channels = vcnl4000_channels;
drivers/iio/magnetometer/ak8974.c+6−1
@@ -746,7 +746,12 @@ static int ak8974_probe(struct i2c_client *i2c, · 745 unmodified lines
746746 ARRAY_SIZE(ak8974->regs),
747747 ak8974->regs);
748748 if (ret < 0) {
749− dev_err(&i2c->dev, "cannot get regulators\n");
749+ if (ret != -EPROBE_DEFER)
750+ dev_err(&i2c->dev, "cannot get regulators: %d\n", ret);
751+ else
752+ dev_dbg(&i2c->dev,
753+ "regulators unavailable, deferring probe\n");
754+
750755 return ret;
751756 }
752757
drivers/iio/magnetometer/bmc150_magn_spi.c+2−2
@@ -22,8 +22,8 @@ static int bmc150_magn_spi_probe(struct spi_device *spi) · 21 unmodified lines
2222
2323 regmap = devm_regmap_init_spi(spi, &bmc150_magn_regmap_config);
2424 if (IS_ERR(regmap)) {
25− dev_err(&spi->dev, "Failed to register spi regmap %d\n",
26− (int)PTR_ERR(regmap));
25+ dev_err(&spi->dev, "Failed to register spi regmap: %pe\n",
26+ regmap);
2727 return PTR_ERR(regmap);
2828 }
2929 return bmc150_magn_probe(&spi->dev, regmap, spi->irq, id->name);
drivers/iio/magnetometer/mmc35240.c+2−2
@@ -239,7 +239,7 @@ static int mmc35240_init(struct mmc35240_data *data) · 238 unmodified lines
239239 return ret;
240240
241241 ret = regmap_bulk_read(data->regmap, MMC35240_OTP_START_ADDR,
242− (u8 *)otp_data, sizeof(otp_data));
242+ otp_data, sizeof(otp_data));
243243 if (ret < 0)
244244 return ret;
245245
@@ -295,7 +295,7 @@ static int mmc35240_read_measurement(struct mmc35240_data *data, __le16 buf[3]) · 49 unmodified lines
295295 if (ret < 0)
296296 return ret;
297297
298− return regmap_bulk_read(data->regmap, MMC35240_REG_XOUT_L, (u8 *)buf,
298+ return regmap_bulk_read(data->regmap, MMC35240_REG_XOUT_L, buf,
299299 3 * sizeof(__le16));
300300 }
301301
drivers/iio/magnetometer/st_magn_core.c+1−2
@@ -506,8 +506,7 @@ int st_magn_common_probe(struct iio_dev *indio_dev) · 505 unmodified lines
506506 indio_dev->channels = mdata->sensor_settings->ch;
507507 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
508508
509− mdata->current_fullscale = (struct st_sensor_fullscale_avl *)
510− &mdata->sensor_settings->fs.fs_avl[0];
509+ mdata->current_fullscale = &mdata->sensor_settings->fs.fs_avl[0];
511510 mdata->odr = mdata->sensor_settings->odr.odr_avl[0].hz;
512511
513512 err = st_sensors_init_sensor(indio_dev, NULL);
drivers/iio/pressure/bmp280-core.c+39−59
@@ -337,8 +337,7 @@ static int bmp280_read_temp(struct bmp280_data *data, · 336 unmodified lines
337337 __be32 tmp = 0;
338338 s32 adc_temp, comp_temp;
339339
340− ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB,
341− (u8 *) &tmp, 3);
340+ ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, &tmp, 3);
342341 if (ret < 0) {
343342 dev_err(data->dev, "failed to read temperature\n");
344343 return ret;
@@ -377,8 +376,7 @@ static int bmp280_read_press(struct bmp280_data *data, · 32 unmodified lines
377376 if (ret < 0)
378377 return ret;
379378
380− ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB,
381− (u8 *) &tmp, 3);
379+ ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, &tmp, 3);
382380 if (ret < 0) {
383381 dev_err(data->dev, "failed to read pressure\n");
384382 return ret;
@@ -400,8 +398,8 @@ static int bmp280_read_press(struct bmp280_data *data, · 15 unmodified lines
400398
401399 static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2)
402400 {
401+ __be16 tmp;
403402 int ret;
404− __be16 tmp = 0;
405403 s32 adc_humidity;
406404 u32 comp_humidity;
407405
@@ -410,8 +408,7 @@ static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2) · 2 unmodified lines
410408 if (ret < 0)
411409 return ret;
412410
413− ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB,
414− (u8 *) &tmp, 2);
411+ ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB, &tmp, 2);
415412 if (ret < 0) {
416413 dev_err(data->dev, "failed to read humidity\n");
417414 return ret;
@@ -575,57 +572,38 @@ static int bmp280_write_raw(struct iio_dev *indio_dev, · 157 unmodified lines
575572 return ret;
576573 }
577574
578−static ssize_t bmp280_show_avail(char *buf, const int *vals, const int n)
575+static int bmp280_read_avail(struct iio_dev *indio_dev,
576+ struct iio_chan_spec const *chan,
577+ const int **vals, int *type, int *length,
578+ long mask)
579579 {
580− size_t len = 0;
581− int i;
582−
583− for (i = 0; i < n; i++)
584− len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", vals[i]);
585−
586− buf[len - 1] = '\n';
587−
588− return len;
589−}
590−
591−static ssize_t bmp280_show_temp_oversampling_avail(struct device *dev,
592− struct device_attribute *attr, char *buf)
593−{
594− struct bmp280_data *data = iio_priv(dev_to_iio_dev(dev));
595−
596− return bmp280_show_avail(buf, data->chip_info->oversampling_temp_avail,
597− data->chip_info->num_oversampling_temp_avail);
598−}
599−
600−static ssize_t bmp280_show_press_oversampling_avail(struct device *dev,
601− struct device_attribute *attr, char *buf)
602−{
603− struct bmp280_data *data = iio_priv(dev_to_iio_dev(dev));
580+ struct bmp280_data *data = iio_priv(indio_dev);
604581
605− return bmp280_show_avail(buf, data->chip_info->oversampling_press_avail,
606− data->chip_info->num_oversampling_press_avail);
582+ switch (mask) {
583+ case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
584+ switch (chan->type) {
585+ case IIO_PRESSURE:
586+ *vals = data->chip_info->oversampling_press_avail;
587+ *length = data->chip_info->num_oversampling_press_avail;
588+ break;
589+ case IIO_TEMP:
590+ *vals = data->chip_info->oversampling_temp_avail;
591+ *length = data->chip_info->num_oversampling_temp_avail;
592+ break;
593+ default:
594+ return -EINVAL;
595+ }
596+ *type = IIO_VAL_INT;
597+ return IIO_AVAIL_LIST;
598+ default:
599+ return -EINVAL;
600+ }
607601 }
608602
609−static IIO_DEVICE_ATTR(in_temp_oversampling_ratio_available,
610− S_IRUGO, bmp280_show_temp_oversampling_avail, NULL, 0);
611−
612−static IIO_DEVICE_ATTR(in_pressure_oversampling_ratio_available,
613− S_IRUGO, bmp280_show_press_oversampling_avail, NULL, 0);
614−
615−static struct attribute *bmp280_attributes[] = {
616− &iio_dev_attr_in_temp_oversampling_ratio_available.dev_attr.attr,
617− &iio_dev_attr_in_pressure_oversampling_ratio_available.dev_attr.attr,
618− NULL,
619−};
620−
621−static const struct attribute_group bmp280_attrs_group = {
622− .attrs = bmp280_attributes,
623−};
624−
625603 static const struct iio_info bmp280_info = {
626604 .read_raw = &bmp280_read_raw,
605+ .read_avail = &bmp280_read_avail,
627606 .write_raw = &bmp280_write_raw,
628− .attrs = &bmp280_attrs_group,
629607 };
630608
631609 static int bmp280_chip_config(struct bmp280_data *data)
@@ -713,7 +691,7 @@ static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas) · 81 unmodified lines
713691 unsigned int ctrl;
714692
715693 if (data->use_eoc)
716− init_completion(&data->done);
694+ reinit_completion(&data->done);
717695
718696 ret = regmap_write(data->regmap, BMP280_REG_CTRL_MEAS, ctrl_meas);
719697 if (ret)
@@ -752,14 +730,14 @@ static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas) · 32 unmodified lines
752730
753731 static int bmp180_read_adc_temp(struct bmp280_data *data, int *val)
754732 {
733+ __be16 tmp;
755734 int ret;
756− __be16 tmp = 0;
757735
758736 ret = bmp180_measure(data, BMP180_MEAS_TEMP);
759737 if (ret)
760738 return ret;
761739
762− ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, (u8 *)&tmp, 2);
740+ ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, &tmp, 2);
763741 if (ret)
764742 return ret;
765743
@@ -856,7 +834,7 @@ static int bmp180_read_adc_press(struct bmp280_data *data, int *val) · 90 unmodified lines
856834 if (ret)
857835 return ret;
858836
859− ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, (u8 *)&tmp, 3);
837+ ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, &tmp, 3);
860838 if (ret)
861839 return ret;
862840
@@ -965,10 +943,12 @@ static int bmp085_fetch_eoc_irq(struct device *dev, · 102 unmodified lines
965943
966944 irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq));
967945 if (irq_trig != IRQF_TRIGGER_RISING) {
968− dev_err(dev, "non-rising trigger given for EOC interrupt, "
969− "trying to enforce it\n");
946+ dev_err(dev, "non-rising trigger given for EOC interrupt, trying to enforce it\n");
970947 irq_trig = IRQF_TRIGGER_RISING;
971948 }
949+
950+ init_completion(&data->done);
951+
972952 ret = devm_request_threaded_irq(dev,
973953 irq,
974954 bmp085_eoc_irq,
@@ -1082,9 +1062,9 @@ int bmp280_common_probe(struct device *dev, · 107 unmodified lines
10821062 usleep_range(data->start_up_time, data->start_up_time + 100);
10831063
10841064 /* Bring chip out of reset if there is an assigned GPIO line */
1085− gpiod = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
1065+ gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
10861066 /* Deassert the signal */
1087− if (!IS_ERR(gpiod)) {
1067+ if (gpiod) {
10881068 dev_info(dev, "release reset\n");
10891069 gpiod_set_value(gpiod, 0);
10901070 }
drivers/iio/pressure/st_pressure_core.c+2−5
@@ -683,8 +683,7 @@ EXPORT_SYMBOL(st_press_get_settings); · 682 unmodified lines
683683 int st_press_common_probe(struct iio_dev *indio_dev)
684684 {
685685 struct st_sensor_data *press_data = iio_priv(indio_dev);
686− struct st_sensors_platform_data *pdata =
687− (struct st_sensors_platform_data *)press_data->dev->platform_data;
686+ struct st_sensors_platform_data *pdata = dev_get_platdata(press_data->dev);
688687 int err;
689688
690689 indio_dev->modes = INDIO_DIRECT_MODE;
@@ -708,9 +707,7 @@ int st_press_common_probe(struct iio_dev *indio_dev) · 17 unmodified lines
708707 indio_dev->channels = press_data->sensor_settings->ch;
709708 indio_dev->num_channels = press_data->sensor_settings->num_ch;
710709
711− press_data->current_fullscale =
712− (struct st_sensor_fullscale_avl *)
713− &press_data->sensor_settings->fs.fs_avl[0];
710+ press_data->current_fullscale = &press_data->sensor_settings->fs.fs_avl[0];
714711
715712 press_data->odr = press_data->sensor_settings->odr.odr_avl[0].hz;
716713
drivers/iio/proximity/Kconfig+13−0
@@ -101,6 +101,19 @@ config SRF04 · 100 unmodified lines
101101 To compile this driver as a module, choose M here: the
102102 module will be called srf04.
103103
104+config SX9310
105+ tristate "SX9310/SX9311 Semtech proximity sensor"
106+ select IIO_BUFFER
107+ select IIO_TRIGGERED_BUFFER
108+ select REGMAP_I2C
109+ depends on I2C
110+ help
111+ Say Y here to build a driver for Semtech's SX9310/SX9311 capacitive
112+ proximity/button sensor.
113+
114+ To compile this driver as a module, choose M here: the
115+ module will be called sx9310.
116+
104117 config SX9500
105118 tristate "SX9500 Semtech proximity sensor"
106119 select IIO_BUFFER
drivers/iio/proximity/Makefile+1−0
@@ -12,6 +12,7 @@ obj-$(CONFIG_PING) += ping.o · 11 unmodified lines
1212 obj-$(CONFIG_RFD77402) += rfd77402.o
1313 obj-$(CONFIG_SRF04) += srf04.o
1414 obj-$(CONFIG_SRF08) += srf08.o
15+obj-$(CONFIG_SX9310) += sx9310.o
1516 obj-$(CONFIG_SX9500) += sx9500.o
1617 obj-$(CONFIG_VL53L0X_I2C) += vl53l0x-i2c.o
1718
drivers/iio/proximity/sx9310.c+1069−0
@@ -0,0 +1,1069 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/*
3+ * Copyright 2018 Google LLC.
4+ *
5+ * Driver for Semtech's SX9310/SX9311 capacitive proximity/button solution.
6+ * Based on SX9500 driver and Semtech driver using the input framework
7+ * <https://my.syncplicity.com/share/teouwsim8niiaud/
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>
11+ */
12+
13+#include <linux/acpi.h>
14+#include <linux/delay.h>
15+#include <linux/i2c.h>
16+#include <linux/irq.h>
17+#include <linux/kernel.h>
18+#include <linux/module.h>
19+#include <linux/of.h>
20+#include <linux/pm.h>
21+#include <linux/regmap.h>
22+#include <linux/slab.h>
23+
24+#include <linux/iio/buffer.h>
25+#include <linux/iio/events.h>
26+#include <linux/iio/iio.h>
27+#include <linux/iio/sysfs.h>
28+#include <linux/iio/trigger.h>
29+#include <linux/iio/triggered_buffer.h>
30+#include <linux/iio/trigger_consumer.h>
31+
32+/* Register definitions. */
33+#define SX9310_REG_IRQ_SRC 0x00
34+#define SX9310_REG_STAT0 0x01
35+#define SX9310_REG_STAT1 0x02
36+#define SX9310_REG_IRQ_MSK 0x03
37+#define SX9310_CONVDONE_IRQ BIT(3)
38+#define SX9310_FAR_IRQ BIT(5)
39+#define SX9310_CLOSE_IRQ BIT(6)
40+#define SX9310_EVENT_IRQ (SX9310_FAR_IRQ | \
41+ SX9310_CLOSE_IRQ)
42+#define SX9310_REG_IRQ_FUNC 0x04
43+
44+#define SX9310_REG_PROX_CTRL0 0x10
45+#define SX9310_REG_PROX_CTRL0_PROXSTAT2 0x10
46+#define SX9310_REG_PROX_CTRL0_EN_MASK 0x0F
47+#define SX9310_REG_PROX_CTRL1 0x11
48+#define SX9310_REG_PROX_CTRL2 0x12
49+#define SX9310_REG_PROX_CTRL2_COMBMODE_ALL 0x80
50+#define SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC 0x04
51+#define SX9310_REG_PROX_CTRL3 0x13
52+#define SX9310_REG_PROX_CTRL3_GAIN0_X8 0x0c
53+#define SX9310_REG_PROX_CTRL3_GAIN12_X4 0x02
54+#define SX9310_REG_PROX_CTRL4 0x14
55+#define SX9310_REG_PROX_CTRL4_RESOLUTION_FINEST 0x07
56+#define SX9310_REG_PROX_CTRL5 0x15
57+#define SX9310_REG_PROX_CTRL5_RANGE_SMALL 0xc0
58+#define SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1 0x04
59+#define SX9310_REG_PROX_CTRL5_RAWFILT_1P25 0x02
60+#define SX9310_REG_PROX_CTRL6 0x16
61+#define SX9310_REG_PROX_CTRL6_COMP_COMMON 0x20
62+#define SX9310_REG_PROX_CTRL7 0x17
63+#define SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 0x08
64+#define SX9310_REG_PROX_CTRL7_AVGPOSFILT_512 0x05
65+#define SX9310_REG_PROX_CTRL8 0x18
66+#define SX9310_REG_PROX_CTRL9 0x19
67+#define SX9310_REG_PROX_CTRL8_9_PTHRESH12_28 0x40
68+#define SX9310_REG_PROX_CTRL8_9_PTHRESH_96 0x88
69+#define SX9310_REG_PROX_CTRL8_9_BODYTHRESH_900 0x03
70+#define SX9310_REG_PROX_CTRL8_9_BODYTHRESH_1500 0x05
71+#define SX9310_REG_PROX_CTRL10 0x1a
72+#define SX9310_REG_PROX_CTRL10_HYST_6PCT 0x10
73+#define SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_8 0x12
74+#define SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_8 0x03
75+#define SX9310_REG_PROX_CTRL11 0x1b
76+#define SX9310_REG_PROX_CTRL12 0x1c
77+#define SX9310_REG_PROX_CTRL13 0x1d
78+#define SX9310_REG_PROX_CTRL14 0x1e
79+#define SX9310_REG_PROX_CTRL15 0x1f
80+#define SX9310_REG_PROX_CTRL16 0x20
81+#define SX9310_REG_PROX_CTRL17 0x21
82+#define SX9310_REG_PROX_CTRL18 0x22
83+#define SX9310_REG_PROX_CTRL19 0x23
84+#define SX9310_REG_SAR_CTRL0 0x2a
85+#define SX9310_REG_SAR_CTRL0_SARDEB_4_SAMPLES 0x40
86+#define SX9310_REG_SAR_CTRL0_SARHYST_8 0x10
87+#define SX9310_REG_SAR_CTRL1 0x2b
88+/* Each increment of the slope register is 0.0078125. */
89+#define SX9310_REG_SAR_CTRL1_SLOPE(_hnslope) (_hnslope / 78125)
90+#define SX9310_REG_SAR_CTRL2 0x2c
91+#define SX9310_REG_SAR_CTRL2_SAROFFSET_DEFAULT 0x3c
92+
93+#define SX9310_REG_SENSOR_SEL 0x30
94+
95+#define SX9310_REG_USE_MSB 0x31
96+#define SX9310_REG_USE_LSB 0x32
97+
98+#define SX9310_REG_AVG_MSB 0x33
99+#define SX9310_REG_AVG_LSB 0x34
100+
101+#define SX9310_REG_DIFF_MSB 0x35
102+#define SX9310_REG_DIFF_LSB 0x36
103+
104+#define SX9310_REG_OFFSET_MSB 0x37
105+#define SX9310_REG_OFFSET_LSB 0x38
106+
107+#define SX9310_REG_SAR_MSB 0x39
108+#define SX9310_REG_SAR_LSB 0x3a
109+
110+#define SX9310_REG_I2CADDR 0x40
111+#define SX9310_REG_PAUSE 0x41
112+#define SX9310_REG_WHOAMI 0x42
113+#define SX9310_WHOAMI_VALUE 0x01
114+#define SX9311_WHOAMI_VALUE 0x02
115+
116+#define SX9310_REG_RESET 0x7f
117+#define SX9310_SOFT_RESET 0xde
118+
119+#define SX9310_SCAN_PERIOD_MASK GENMASK(7, 4)
120+#define SX9310_SCAN_PERIOD_SHIFT 4
121+
122+#define SX9310_COMPSTAT_MASK GENMASK(3, 0)
123+
124+/* 4 hardware channels, as defined in STAT0: COMB, CS2, CS1 and CS0. */
125+#define SX9310_NUM_CHANNELS 4
126+#define SX9310_CHAN_ENABLED_MASK GENMASK(3, 0)
127+
128+struct sx9310_data {
129+ /* Serialize access to registers and channel configuration */
130+ struct mutex mutex;
131+ struct i2c_client *client;
132+ struct iio_trigger *trig;
133+ struct regmap *regmap;
134+ /*
135+ * Last reading of the proximity status for each channel.
136+ * We only send an event to user space when this changes.
137+ */
138+ bool prox_stat[SX9310_NUM_CHANNELS];
139+ bool trigger_enabled;
140+ __be16 buffer[SX9310_NUM_CHANNELS +
141+ 4]; /* 64-bit data + 64-bit timestamp */
142+ /* Remember enabled channels and sample rate during suspend. */
143+ unsigned int suspend_ctrl0;
144+ struct completion completion;
145+ unsigned int chan_read, chan_event;
146+ int channel_users[SX9310_NUM_CHANNELS];
147+ int whoami;
148+};
149+
150+static const struct iio_event_spec sx9310_events[] = {
151+ {
152+ .type = IIO_EV_TYPE_THRESH,
153+ .dir = IIO_EV_DIR_EITHER,
154+ .mask_separate = BIT(IIO_EV_INFO_ENABLE),
155+ },
156+};
157+
158+#define SX9310_NAMED_CHANNEL(idx, name) \
159+ { \
160+ .type = IIO_PROXIMITY, \
161+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
162+ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
163+ .indexed = 1, \
164+ .channel = idx, \
165+ .extend_name = name, \
166+ .address = SX9310_REG_DIFF_MSB, \
167+ .event_spec = sx9310_events, \
168+ .num_event_specs = ARRAY_SIZE(sx9310_events), \
169+ .scan_index = idx, \
170+ .scan_type = { \
171+ .sign = 's', \
172+ .realbits = 12, \
173+ .storagebits = 16, \
174+ .endianness = IIO_BE, \
175+ }, \
176+ }
177+#define SX9310_CHANNEL(idx) SX9310_NAMED_CHANNEL(idx, NULL)
178+
179+static const struct iio_chan_spec sx9310_channels[] = {
180+ SX9310_CHANNEL(0), /* CS0 */
181+ SX9310_CHANNEL(1), /* CS1 */
182+ SX9310_CHANNEL(2), /* CS2 */
183+ SX9310_NAMED_CHANNEL(3, "comb"), /* COMB */
184+
185+ IIO_CHAN_SOFT_TIMESTAMP(4),
186+};
187+
188+/*
189+ * Each entry contains the integer part (val) and the fractional part, in micro
190+ * seconds. It conforms to the IIO output IIO_VAL_INT_PLUS_MICRO.
191+ */
192+static const struct {
193+ int val;
194+ int val2;
195+} sx9310_samp_freq_table[] = {
196+ { 500, 0 }, /* 0000: Min (no idle time) */
197+ { 66, 666666 }, /* 0001: 15 ms */
198+ { 33, 333333 }, /* 0010: 30 ms (Typ.) */
199+ { 22, 222222 }, /* 0011: 45 ms */
200+ { 16, 666666 }, /* 0100: 60 ms */
201+ { 11, 111111 }, /* 0101: 90 ms */
202+ { 8, 333333 }, /* 0110: 120 ms */
203+ { 5, 0 }, /* 0111: 200 ms */
204+ { 2, 500000 }, /* 1000: 400 ms */
205+ { 1, 666666 }, /* 1001: 600 ms */
206+ { 1, 250000 }, /* 1010: 800 ms */
207+ { 1, 0 }, /* 1011: 1 s */
208+ { 0, 500000 }, /* 1100: 2 s */
209+ { 0, 333333 }, /* 1101: 3 s */
210+ { 0, 250000 }, /* 1110: 4 s */
211+ { 0, 200000 }, /* 1111: 5 s */
212+};
213+static const unsigned int sx9310_scan_period_table[] = {
214+ 2, 15, 30, 45, 60, 90, 120, 200,
215+ 400, 600, 800, 1000, 2000, 3000, 4000, 5000,
216+};
217+
218+static ssize_t sx9310_show_samp_freq_avail(struct device *dev,
219+ struct device_attribute *attr,
220+ char *buf)
221+{
222+ size_t len = 0;
223+ int i;
224+
225+ for (i = 0; i < ARRAY_SIZE(sx9310_samp_freq_table); i++)
226+ len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%d ",
227+ sx9310_samp_freq_table[i].val,
228+ sx9310_samp_freq_table[i].val2);
229+ buf[len - 1] = '\n';
230+ return len;
231+}
232+static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(sx9310_show_samp_freq_avail);
233+
234+static const struct regmap_range sx9310_writable_reg_ranges[] = {
235+ regmap_reg_range(SX9310_REG_IRQ_MSK, SX9310_REG_IRQ_FUNC),
236+ regmap_reg_range(SX9310_REG_PROX_CTRL0, SX9310_REG_PROX_CTRL19),
237+ regmap_reg_range(SX9310_REG_SAR_CTRL0, SX9310_REG_SAR_CTRL2),
238+ regmap_reg_range(SX9310_REG_SENSOR_SEL, SX9310_REG_SENSOR_SEL),
239+ regmap_reg_range(SX9310_REG_OFFSET_MSB, SX9310_REG_OFFSET_LSB),
240+ regmap_reg_range(SX9310_REG_PAUSE, SX9310_REG_PAUSE),
241+ regmap_reg_range(SX9310_REG_RESET, SX9310_REG_RESET),
242+};
243+
244+static const struct regmap_access_table sx9310_writeable_regs = {
245+ .yes_ranges = sx9310_writable_reg_ranges,
246+ .n_yes_ranges = ARRAY_SIZE(sx9310_writable_reg_ranges),
247+};
248+
249+static const struct regmap_range sx9310_readable_reg_ranges[] = {
250+ regmap_reg_range(SX9310_REG_IRQ_SRC, SX9310_REG_IRQ_FUNC),
251+ regmap_reg_range(SX9310_REG_PROX_CTRL0, SX9310_REG_PROX_CTRL19),
252+ regmap_reg_range(SX9310_REG_SAR_CTRL0, SX9310_REG_SAR_CTRL2),
253+ regmap_reg_range(SX9310_REG_SENSOR_SEL, SX9310_REG_SAR_LSB),
254+ regmap_reg_range(SX9310_REG_I2CADDR, SX9310_REG_WHOAMI),
255+ regmap_reg_range(SX9310_REG_RESET, SX9310_REG_RESET),
256+};
257+
258+static const struct regmap_access_table sx9310_readable_regs = {
259+ .yes_ranges = sx9310_readable_reg_ranges,
260+ .n_yes_ranges = ARRAY_SIZE(sx9310_readable_reg_ranges),
261+};
262+
263+static const struct regmap_range sx9310_volatile_reg_ranges[] = {
264+ regmap_reg_range(SX9310_REG_IRQ_SRC, SX9310_REG_STAT1),
265+ regmap_reg_range(SX9310_REG_USE_MSB, SX9310_REG_DIFF_LSB),
266+ regmap_reg_range(SX9310_REG_SAR_MSB, SX9310_REG_SAR_LSB),
267+ regmap_reg_range(SX9310_REG_RESET, SX9310_REG_RESET),
268+};
269+
270+static const struct regmap_access_table sx9310_volatile_regs = {
271+ .yes_ranges = sx9310_volatile_reg_ranges,
272+ .n_yes_ranges = ARRAY_SIZE(sx9310_volatile_reg_ranges),
273+};
274+
275+static const struct regmap_config sx9310_regmap_config = {
276+ .reg_bits = 8,
277+ .val_bits = 8,
278+
279+ .max_register = SX9310_REG_RESET,
280+ .cache_type = REGCACHE_RBTREE,
281+
282+ .wr_table = &sx9310_writeable_regs,
283+ .rd_table = &sx9310_readable_regs,
284+ .volatile_table = &sx9310_volatile_regs,
285+};
286+
287+static int sx9310_update_chan_en(struct sx9310_data *data,
288+ unsigned int chan_read,
289+ unsigned int chan_event)
290+{
291+ int ret;
292+
293+ if ((data->chan_read | data->chan_event) != (chan_read | chan_event)) {
294+ ret = regmap_update_bits(data->regmap, SX9310_REG_PROX_CTRL0,
295+ SX9310_CHAN_ENABLED_MASK,
296+ chan_read | chan_event);
297+ if (ret)
298+ return ret;
299+ }
300+ data->chan_read = chan_read;
301+ data->chan_event = chan_event;
302+ return 0;
303+}
304+
305+static int sx9310_get_read_channel(struct sx9310_data *data, int channel)
306+{
307+ return sx9310_update_chan_en(data, data->chan_read | BIT(channel),
308+ data->chan_event);
309+}
310+
311+static int sx9310_put_read_channel(struct sx9310_data *data, int channel)
312+{
313+ return sx9310_update_chan_en(data, data->chan_read & ~BIT(channel),
314+ data->chan_event);
315+}
316+
317+static int sx9310_get_event_channel(struct sx9310_data *data, int channel)
318+{
319+ return sx9310_update_chan_en(data, data->chan_read,
320+ data->chan_event | BIT(channel));
321+}
322+
323+static int sx9310_put_event_channel(struct sx9310_data *data, int channel)
324+{
325+ return sx9310_update_chan_en(data, data->chan_read,
326+ data->chan_event & ~BIT(channel));
327+}
328+
329+static int sx9310_enable_irq(struct sx9310_data *data, unsigned int irq)
330+{
331+ return regmap_update_bits(data->regmap, SX9310_REG_IRQ_MSK, irq, irq);
332+}
333+
334+static int sx9310_disable_irq(struct sx9310_data *data, unsigned int irq)
335+{
336+ return regmap_update_bits(data->regmap, SX9310_REG_IRQ_MSK, irq, 0);
337+}
338+
339+static int sx9310_read_prox_data(struct sx9310_data *data,
340+ const struct iio_chan_spec *chan, __be16 *val)
341+{
342+ int ret;
343+
344+ ret = regmap_write(data->regmap, SX9310_REG_SENSOR_SEL, chan->channel);
345+ if (ret < 0)
346+ return ret;
347+
348+ return regmap_bulk_read(data->regmap, chan->address, val, 2);
349+}
350+
351+/*
352+ * If we have no interrupt support, we have to wait for a scan period
353+ * after enabling a channel to get a result.
354+ */
355+static int sx9310_wait_for_sample(struct sx9310_data *data)
356+{
357+ int ret;
358+ unsigned int val;
359+
360+ ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, &val);
361+ if (ret < 0)
362+ return ret;
363+
364+ val = (val & SX9310_SCAN_PERIOD_MASK) >> SX9310_SCAN_PERIOD_SHIFT;
365+
366+ msleep(sx9310_scan_period_table[val]);
367+
368+ return 0;
369+}
370+
371+static int sx9310_read_proximity(struct sx9310_data *data,
372+ const struct iio_chan_spec *chan, int *val)
373+{
374+ int ret = 0;
375+ __be16 rawval;
376+
377+ mutex_lock(&data->mutex);
378+
379+ ret = sx9310_get_read_channel(data, chan->channel);
380+ if (ret < 0)
381+ goto out;
382+
383+ ret = sx9310_enable_irq(data, SX9310_CONVDONE_IRQ);
384+ if (ret < 0)
385+ goto out_put_channel;
386+
387+ mutex_unlock(&data->mutex);
388+
389+ if (data->client->irq > 0) {
390+ ret = wait_for_completion_interruptible(&data->completion);
391+ reinit_completion(&data->completion);
392+ } else {
393+ ret = sx9310_wait_for_sample(data);
394+ }
395+
396+ mutex_lock(&data->mutex);
397+
398+ if (ret < 0)
399+ goto out_disable_irq;
400+
401+ ret = sx9310_read_prox_data(data, chan, &rawval);
402+ if (ret < 0)
403+ goto out_disable_irq;
404+
405+ *val = sign_extend32(be16_to_cpu(rawval),
406+ (chan->address == SX9310_REG_DIFF_MSB ? 11 : 15));
407+
408+ ret = sx9310_disable_irq(data, SX9310_CONVDONE_IRQ);
409+ if (ret < 0)
410+ goto out_put_channel;
411+
412+ ret = sx9310_put_read_channel(data, chan->channel);
413+ if (ret < 0)
414+ goto out;
415+
416+ mutex_unlock(&data->mutex);
417+
418+ return IIO_VAL_INT;
419+
420+out_disable_irq:
421+ sx9310_disable_irq(data, SX9310_CONVDONE_IRQ);
422+out_put_channel:
423+ sx9310_put_read_channel(data, chan->channel);
424+out:
425+ mutex_unlock(&data->mutex);
426+
427+ return ret;
428+}
429+
430+static int sx9310_read_samp_freq(struct sx9310_data *data, int *val, int *val2)
431+{
432+ unsigned int regval;
433+ int ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, &regval);
434+
435+ if (ret < 0)
436+ return ret;
437+
438+ regval = (regval & SX9310_SCAN_PERIOD_MASK) >> SX9310_SCAN_PERIOD_SHIFT;
439+ *val = sx9310_samp_freq_table[regval].val;
440+ *val2 = sx9310_samp_freq_table[regval].val2;
441+
442+ return IIO_VAL_INT_PLUS_MICRO;
443+}
444+
445+static int sx9310_read_raw(struct iio_dev *indio_dev,
446+ const struct iio_chan_spec *chan, int *val,
447+ int *val2, long mask)
448+{
449+ struct sx9310_data *data = iio_priv(indio_dev);
450+ int ret;
451+
452+ if (chan->type != IIO_PROXIMITY)
453+ return -EINVAL;
454+
455+ switch (mask) {
456+ case IIO_CHAN_INFO_RAW:
457+ ret = iio_device_claim_direct_mode(indio_dev);
458+ if (ret)
459+ return ret;
460+
461+ ret = sx9310_read_proximity(data, chan, val);
462+ iio_device_release_direct_mode(indio_dev);
463+ return ret;
464+ case IIO_CHAN_INFO_SAMP_FREQ:
465+ return sx9310_read_samp_freq(data, val, val2);
466+ default:
467+ return -EINVAL;
468+ }
469+}
470+
471+static int sx9310_set_samp_freq(struct sx9310_data *data, int val, int val2)
472+{
473+ int i, ret;
474+
475+ for (i = 0; i < ARRAY_SIZE(sx9310_samp_freq_table); i++)
476+ if (val == sx9310_samp_freq_table[i].val &&
477+ val2 == sx9310_samp_freq_table[i].val2)
478+ break;
479+
480+ if (i == ARRAY_SIZE(sx9310_samp_freq_table))
481+ return -EINVAL;
482+
483+ mutex_lock(&data->mutex);
484+
485+ ret = regmap_update_bits(data->regmap, SX9310_REG_PROX_CTRL0,
486+ SX9310_SCAN_PERIOD_MASK,
487+ i << SX9310_SCAN_PERIOD_SHIFT);
488+
489+ mutex_unlock(&data->mutex);
490+
491+ return ret;
492+}
493+
494+static int sx9310_write_raw(struct iio_dev *indio_dev,
495+ const struct iio_chan_spec *chan, int val, int val2,
496+ long mask)
497+{
498+ struct sx9310_data *data = iio_priv(indio_dev);
499+
500+ if (chan->type != IIO_PROXIMITY)
501+ return -EINVAL;
502+
503+ if (mask != IIO_CHAN_INFO_SAMP_FREQ)
504+ return -EINVAL;
505+
506+ return sx9310_set_samp_freq(data, val, val2);
507+}
508+
509+static irqreturn_t sx9310_irq_handler(int irq, void *private)
510+{
511+ struct iio_dev *indio_dev = private;
512+ struct sx9310_data *data = iio_priv(indio_dev);
513+
514+ if (data->trigger_enabled)
515+ iio_trigger_poll(data->trig);
516+
517+ /*
518+ * Even if no event is enabled, we need to wake the thread to
519+ * clear the interrupt state by reading SX9310_REG_IRQ_SRC. It
520+ * is not possible to do that here because regmap_read takes a
521+ * mutex.
522+ */
523+ return IRQ_WAKE_THREAD;
524+}
525+
526+static void sx9310_push_events(struct iio_dev *indio_dev)
527+{
528+ int ret;
529+ unsigned int val, chan;
530+ struct sx9310_data *data = iio_priv(indio_dev);
531+ s64 timestamp = iio_get_time_ns(indio_dev);
532+
533+ /* Read proximity state on all channels */
534+ ret = regmap_read(data->regmap, SX9310_REG_STAT0, &val);
535+ if (ret < 0) {
536+ dev_err(&data->client->dev, "i2c transfer error in irq\n");
537+ return;
538+ }
539+
540+ for (chan = 0; chan < SX9310_NUM_CHANNELS; chan++) {
541+ int dir;
542+ u64 ev;
543+ bool new_prox = val & BIT(chan);
544+
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;
552+ ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, chan,
553+ IIO_EV_TYPE_THRESH, dir);
554+
555+ iio_push_event(indio_dev, ev, timestamp);
556+ data->prox_stat[chan] = new_prox;
557+ }
558+}
559+
560+static irqreturn_t sx9310_irq_thread_handler(int irq, void *private)
561+{
562+ struct iio_dev *indio_dev = private;
563+ struct sx9310_data *data = iio_priv(indio_dev);
564+ int ret;
565+ unsigned int val;
566+
567+ mutex_lock(&data->mutex);
568+
569+ ret = regmap_read(data->regmap, SX9310_REG_IRQ_SRC, &val);
570+ if (ret < 0) {
571+ dev_err(&data->client->dev, "i2c transfer error in irq\n");
572+ goto out;
573+ }
574+
575+ if (val & SX9310_EVENT_IRQ)
576+ sx9310_push_events(indio_dev);
577+
578+ if (val & SX9310_CONVDONE_IRQ)
579+ complete(&data->completion);
580+
581+out:
582+ mutex_unlock(&data->mutex);
583+
584+ return IRQ_HANDLED;
585+}
586+
587+static int sx9310_read_event_config(struct iio_dev *indio_dev,
588+ const struct iio_chan_spec *chan,
589+ enum iio_event_type type,
590+ enum iio_event_direction dir)
591+{
592+ struct sx9310_data *data = iio_priv(indio_dev);
593+
594+ return !!(data->chan_event & BIT(chan->channel));
595+}
596+
597+static int sx9310_write_event_config(struct iio_dev *indio_dev,
598+ const struct iio_chan_spec *chan,
599+ enum iio_event_type type,
600+ enum iio_event_direction dir, int state)
601+{
602+ struct sx9310_data *data = iio_priv(indio_dev);
603+ int ret;
604+
605+ /* If the state hasn't changed, there's nothing to do. */
606+ if (!!(data->chan_event & BIT(chan->channel)) == state)
607+ return 0;
608+
609+ mutex_lock(&data->mutex);
610+ if (state) {
611+ ret = sx9310_get_event_channel(data, chan->channel);
612+ if (ret < 0)
613+ goto out_unlock;
614+ if (!(data->chan_event & ~BIT(chan->channel))) {
615+ ret = sx9310_enable_irq(data, SX9310_EVENT_IRQ);
616+ if (ret < 0)
617+ sx9310_put_event_channel(data, chan->channel);
618+ }
619+ } else {
620+ ret = sx9310_put_event_channel(data, chan->channel);
621+ if (ret < 0)
622+ goto out_unlock;
623+ if (!data->chan_event) {
624+ ret = sx9310_disable_irq(data, SX9310_EVENT_IRQ);
625+ if (ret < 0)
626+ sx9310_get_event_channel(data, chan->channel);
627+ }
628+ }
629+
630+out_unlock:
631+ mutex_unlock(&data->mutex);
632+ return ret;
633+}
634+
635+static struct attribute *sx9310_attributes[] = {
636+ &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
637+ NULL,
638+};
639+
640+static const struct attribute_group sx9310_attribute_group = {
641+ .attrs = sx9310_attributes,
642+};
643+
644+static const struct iio_info sx9310_info = {
645+ .attrs = &sx9310_attribute_group,
646+ .read_raw = sx9310_read_raw,
647+ .write_raw = sx9310_write_raw,
648+ .read_event_config = sx9310_read_event_config,
649+ .write_event_config = sx9310_write_event_config,
650+};
651+
652+static int sx9310_set_trigger_state(struct iio_trigger *trig, bool state)
653+{
654+ struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
655+ struct sx9310_data *data = iio_priv(indio_dev);
656+ int ret = 0;
657+
658+ mutex_lock(&data->mutex);
659+
660+ if (state)
661+ ret = sx9310_enable_irq(data, SX9310_CONVDONE_IRQ);
662+ else if (!data->chan_read)
663+ ret = sx9310_disable_irq(data, SX9310_CONVDONE_IRQ);
664+ if (ret < 0)
665+ goto out;
666+
667+ data->trigger_enabled = state;
668+
669+out:
670+ mutex_unlock(&data->mutex);
671+
672+ return ret;
673+}
674+
675+static const struct iio_trigger_ops sx9310_trigger_ops = {
676+ .set_trigger_state = sx9310_set_trigger_state,
677+};
678+
679+static irqreturn_t sx9310_trigger_handler(int irq, void *private)
680+{
681+ struct iio_poll_func *pf = private;
682+ struct iio_dev *indio_dev = pf->indio_dev;
683+ struct sx9310_data *data = iio_priv(indio_dev);
684+ __be16 val;
685+ int bit, ret, i = 0;
686+
687+ mutex_lock(&data->mutex);
688+
689+ for_each_set_bit(bit, indio_dev->active_scan_mask,
690+ indio_dev->masklength) {
691+ ret = sx9310_read_prox_data(data, &indio_dev->channels[bit],
692+ &val);
693+ if (ret < 0)
694+ goto out;
695+
696+ data->buffer[i++] = val;
697+ }
698+
699+ iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
700+ pf->timestamp);
701+
702+out:
703+ mutex_unlock(&data->mutex);
704+
705+ iio_trigger_notify_done(indio_dev->trig);
706+
707+ return IRQ_HANDLED;
708+}
709+
710+static int sx9310_buffer_preenable(struct iio_dev *indio_dev)
711+{
712+ struct sx9310_data *data = iio_priv(indio_dev);
713+ unsigned int channels = 0;
714+ int bit, ret;
715+
716+ mutex_lock(&data->mutex);
717+ for_each_set_bit(bit, indio_dev->active_scan_mask,
718+ indio_dev->masklength)
719+ channels |= BIT(indio_dev->channels[bit].channel);
720+
721+ ret = sx9310_update_chan_en(data, channels, data->chan_event);
722+ mutex_unlock(&data->mutex);
723+ return ret;
724+}
725+
726+static int sx9310_buffer_postdisable(struct iio_dev *indio_dev)
727+{
728+ struct sx9310_data *data = iio_priv(indio_dev);
729+ int ret;
730+
731+ mutex_lock(&data->mutex);
732+ ret = sx9310_update_chan_en(data, 0, data->chan_event);
733+ mutex_unlock(&data->mutex);
734+ return ret;
735+}
736+
737+static const struct iio_buffer_setup_ops sx9310_buffer_setup_ops = {
738+ .preenable = sx9310_buffer_preenable,
739+ .postenable = iio_triggered_buffer_postenable,
740+ .predisable = iio_triggered_buffer_predisable,
741+ .postdisable = sx9310_buffer_postdisable,
742+};
743+
744+struct sx9310_reg_default {
745+ u8 reg;
746+ u8 def;
747+};
748+
749+#define SX_INIT(_reg, _def) \
750+ { \
751+ .reg = SX9310_REG_##_reg, \
752+ .def = _def, \
753+ }
754+
755+static const struct sx9310_reg_default sx9310_default_regs[] = {
756+ SX_INIT(IRQ_MSK, 0x00),
757+ SX_INIT(IRQ_FUNC, 0x00),
758+ /*
759+ * The lower 4 bits should not be set as it enable sensors measurements.
760+ * Turning the detection on before the configuration values are set to
761+ * good values can cause the device to return erroneous readings.
762+ */
763+ SX_INIT(PROX_CTRL0, SX9310_REG_PROX_CTRL0_PROXSTAT2),
764+ SX_INIT(PROX_CTRL1, 0x00),
765+ SX_INIT(PROX_CTRL2, SX9310_REG_PROX_CTRL2_COMBMODE_ALL |
766+ SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC),
767+ SX_INIT(PROX_CTRL3, SX9310_REG_PROX_CTRL3_GAIN0_X8 |
768+ SX9310_REG_PROX_CTRL3_GAIN12_X4),
769+ SX_INIT(PROX_CTRL4, SX9310_REG_PROX_CTRL4_RESOLUTION_FINEST),
770+ SX_INIT(PROX_CTRL5, SX9310_REG_PROX_CTRL5_RANGE_SMALL |
771+ SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1 |
772+ SX9310_REG_PROX_CTRL5_RAWFILT_1P25),
773+ SX_INIT(PROX_CTRL6, SX9310_REG_PROX_CTRL6_COMP_COMMON),
774+ SX_INIT(PROX_CTRL7, SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 |
775+ SX9310_REG_PROX_CTRL7_AVGPOSFILT_512),
776+ SX_INIT(PROX_CTRL8, SX9310_REG_PROX_CTRL8_9_PTHRESH_96 |
777+ SX9310_REG_PROX_CTRL8_9_BODYTHRESH_1500),
778+ SX_INIT(PROX_CTRL9, SX9310_REG_PROX_CTRL8_9_PTHRESH12_28 |
779+ SX9310_REG_PROX_CTRL8_9_BODYTHRESH_900),
780+ SX_INIT(PROX_CTRL10, SX9310_REG_PROX_CTRL10_HYST_6PCT |
781+ SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_8 |
782+ SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_8),
783+ SX_INIT(PROX_CTRL11, 0x00),
784+ SX_INIT(PROX_CTRL12, 0x00),
785+ SX_INIT(PROX_CTRL13, 0x00),
786+ SX_INIT(PROX_CTRL14, 0x00),
787+ SX_INIT(PROX_CTRL15, 0x00),
788+ SX_INIT(PROX_CTRL16, 0x00),
789+ SX_INIT(PROX_CTRL17, 0x00),
790+ SX_INIT(PROX_CTRL18, 0x00),
791+ SX_INIT(PROX_CTRL19, 0x00),
792+ SX_INIT(SAR_CTRL0, SX9310_REG_SAR_CTRL0_SARDEB_4_SAMPLES |
793+ SX9310_REG_SAR_CTRL0_SARHYST_8),
794+ SX_INIT(SAR_CTRL1, SX9310_REG_SAR_CTRL1_SLOPE(10781250)),
795+ SX_INIT(SAR_CTRL2, SX9310_REG_SAR_CTRL2_SAROFFSET_DEFAULT),
796+};
797+
798+/* Activate all channels and perform an initial compensation. */
799+static int sx9310_init_compensation(struct iio_dev *indio_dev)
800+{
801+ struct sx9310_data *data = iio_priv(indio_dev);
802+ int i, ret;
803+ unsigned int val;
804+ unsigned int ctrl0;
805+
806+ ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, &ctrl0);
807+ if (ret < 0)
808+ return ret;
809+
810+ /* run the compensation phase on all channels */
811+ ret = regmap_write(data->regmap, SX9310_REG_PROX_CTRL0,
812+ ctrl0 | SX9310_REG_PROX_CTRL0_EN_MASK);
813+ if (ret < 0)
814+ return ret;
815+
816+ for (i = 100; i >= 0; i--) {
817+ msleep(20);
818+ ret = regmap_read(data->regmap, SX9310_REG_STAT1, &val);
819+ if (ret < 0)
820+ goto out;
821+ if (!(val & SX9310_COMPSTAT_MASK))
822+ break;
823+ }
824+
825+ if (i < 0) {
826+ dev_err(&data->client->dev,
827+ "initial compensation timed out: 0x%02x", val);
828+ ret = -ETIMEDOUT;
829+ }
830+
831+out:
832+ regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0);
833+ return ret;
834+}
835+
836+static int sx9310_init_device(struct iio_dev *indio_dev)
837+{
838+ struct sx9310_data *data = iio_priv(indio_dev);
839+ const struct sx9310_reg_default *initval;
840+ int ret;
841+ unsigned int i, val;
842+
843+ ret = regmap_write(data->regmap, SX9310_REG_RESET, SX9310_SOFT_RESET);
844+ if (ret < 0)
845+ return ret;
846+
847+ usleep_range(1000, 2000); /* power-up time is ~1ms. */
848+
849+ /* Clear reset interrupt state by reading SX9310_REG_IRQ_SRC. */
850+ ret = regmap_read(data->regmap, SX9310_REG_IRQ_SRC, &val);
851+ if (ret < 0)
852+ return ret;
853+
854+ /* Program some sane defaults. */
855+ for (i = 0; i < ARRAY_SIZE(sx9310_default_regs); i++) {
856+ initval = &sx9310_default_regs[i];
857+ ret = regmap_write(data->regmap, initval->reg, initval->def);
858+ if (ret < 0)
859+ return ret;
860+ }
861+
862+ return sx9310_init_compensation(indio_dev);
863+}
864+
865+static int sx9310_set_indio_dev_name(struct device *dev,
866+ struct iio_dev *indio_dev,
867+ const struct i2c_device_id *id, int whoami)
868+{
869+ const struct acpi_device_id *acpi_id;
870+
871+ /* id will be NULL when enumerated via ACPI */
872+ if (id) {
873+ if (id->driver_data != whoami)
874+ dev_err(dev, "WHOAMI does not match i2c_device_id: %s",
875+ id->name);
876+ } else if (ACPI_HANDLE(dev)) {
877+ acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev);
878+ if (!acpi_id)
879+ return -ENODEV;
880+ if (acpi_id->driver_data != whoami)
881+ dev_err(dev, "WHOAMI does not match acpi_device_id: %s",
882+ acpi_id->id);
883+ } else
884+ return -ENODEV;
885+
886+ switch (whoami) {
887+ case SX9310_WHOAMI_VALUE:
888+ indio_dev->name = "sx9310";
889+ break;
890+ case SX9311_WHOAMI_VALUE:
891+ indio_dev->name = "sx9311";
892+ break;
893+ default:
894+ dev_err(dev, "unexpected WHOAMI response: %u", whoami);
895+ return -ENODEV;
896+ }
897+
898+ return 0;
899+}
900+
901+static int sx9310_probe(struct i2c_client *client,
902+ const struct i2c_device_id *id)
903+{
904+ int ret;
905+ struct iio_dev *indio_dev;
906+ struct sx9310_data *data;
907+
908+ indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
909+ if (indio_dev == NULL)
910+ return -ENOMEM;
911+
912+ data = iio_priv(indio_dev);
913+ data->client = client;
914+ mutex_init(&data->mutex);
915+ init_completion(&data->completion);
916+
917+ data->regmap = devm_regmap_init_i2c(client, &sx9310_regmap_config);
918+ if (IS_ERR(data->regmap))
919+ return PTR_ERR(data->regmap);
920+
921+ ret = regmap_read(data->regmap, SX9310_REG_WHOAMI, &data->whoami);
922+ if (ret < 0) {
923+ dev_err(&client->dev, "error in reading WHOAMI register: %d",
924+ ret);
925+ return ret;
926+ }
927+
928+ ret = sx9310_set_indio_dev_name(&client->dev, indio_dev, id,
929+ data->whoami);
930+ if (ret < 0)
931+ return ret;
932+
933+ ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(&client->dev));
934+ indio_dev->dev.parent = &client->dev;
935+ indio_dev->channels = sx9310_channels;
936+ indio_dev->num_channels = ARRAY_SIZE(sx9310_channels);
937+ indio_dev->info = &sx9310_info;
938+ indio_dev->modes = INDIO_DIRECT_MODE;
939+ i2c_set_clientdata(client, indio_dev);
940+
941+ ret = sx9310_init_device(indio_dev);
942+ if (ret < 0)
943+ return ret;
944+
945+ if (client->irq) {
946+ ret = devm_request_threaded_irq(&client->dev, client->irq,
947+ sx9310_irq_handler,
948+ sx9310_irq_thread_handler,
949+ IRQF_TRIGGER_LOW | IRQF_ONESHOT,
950+ "sx9310_event", indio_dev);
951+ if (ret < 0)
952+ return ret;
953+
954+ data->trig =
955+ devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
956+ indio_dev->name, indio_dev->id);
957+ if (!data->trig)
958+ return -ENOMEM;
959+
960+ data->trig->dev.parent = &client->dev;
961+ data->trig->ops = &sx9310_trigger_ops;
962+ iio_trigger_set_drvdata(data->trig, indio_dev);
963+
964+ ret = devm_iio_trigger_register(&client->dev, data->trig);
965+ if (ret)
966+ return ret;
967+ }
968+
969+ ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev,
970+ iio_pollfunc_store_time,
971+ sx9310_trigger_handler,
972+ &sx9310_buffer_setup_ops);
973+ if (ret < 0)
974+ return ret;
975+
976+ return devm_iio_device_register(&client->dev, indio_dev);
977+}
978+
979+static int __maybe_unused sx9310_suspend(struct device *dev)
980+{
981+ struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
982+ struct sx9310_data *data = iio_priv(indio_dev);
983+ u8 ctrl0;
984+ int ret;
985+
986+ disable_irq_nosync(data->client->irq);
987+
988+ mutex_lock(&data->mutex);
989+ ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0,
990+ &data->suspend_ctrl0);
991+
992+ if (ret)
993+ goto out;
994+
995+ ctrl0 = data->suspend_ctrl0 & ~SX9310_REG_PROX_CTRL0_EN_MASK;
996+ ret = regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0);
997+ if (ret)
998+ goto out;
999+
1000+ ret = regmap_write(data->regmap, SX9310_REG_PAUSE, 0);
1001+
1002+out:
1003+ mutex_unlock(&data->mutex);
1004+ return ret;
1005+}
1006+
1007+static int __maybe_unused sx9310_resume(struct device *dev)
1008+{
1009+ struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
1010+ struct sx9310_data *data = iio_priv(indio_dev);
1011+ int ret;
1012+
1013+ mutex_lock(&data->mutex);
1014+ ret = regmap_write(data->regmap, SX9310_REG_PAUSE, 1);
1015+ if (ret)
1016+ goto out;
1017+
1018+ ret = regmap_write(data->regmap, SX9310_REG_PROX_CTRL0,
1019+ data->suspend_ctrl0);
1020+
1021+out:
1022+ mutex_unlock(&data->mutex);
1023+
1024+ enable_irq(data->client->irq);
1025+
1026+ return ret;
1027+}
1028+
1029+static const struct dev_pm_ops sx9310_pm_ops = {
1030+ SET_SYSTEM_SLEEP_PM_OPS(sx9310_suspend, sx9310_resume)
1031+};
1032+
1033+static const struct acpi_device_id sx9310_acpi_match[] = {
1034+ { "STH9310", SX9310_WHOAMI_VALUE },
1035+ { "STH9311", SX9311_WHOAMI_VALUE },
1036+ {},
1037+};
1038+MODULE_DEVICE_TABLE(acpi, sx9310_acpi_match);
1039+
1040+static const struct of_device_id sx9310_of_match[] = {
1041+ { .compatible = "semtech,sx9310" },
1042+ { .compatible = "semtech,sx9311" },
1043+ {},
1044+};
1045+MODULE_DEVICE_TABLE(of, sx9310_of_match);
1046+
1047+static const struct i2c_device_id sx9310_id[] = {
1048+ { "sx9310", SX9310_WHOAMI_VALUE },
1049+ { "sx9311", SX9311_WHOAMI_VALUE },
1050+ {},
1051+};
1052+MODULE_DEVICE_TABLE(i2c, sx9310_id);
1053+
1054+static struct i2c_driver sx9310_driver = {
1055+ .driver = {
1056+ .name = "sx9310",
1057+ .acpi_match_table = ACPI_PTR(sx9310_acpi_match),
1058+ .of_match_table = of_match_ptr(sx9310_of_match),
1059+ .pm = &sx9310_pm_ops,
1060+ },
1061+ .probe = sx9310_probe,
1062+ .id_table = sx9310_id,
1063+};
1064+module_i2c_driver(sx9310_driver);
1065+
1066+MODULE_AUTHOR("Gwendal Grignou <gwendal@chromium.org>");
1067+MODULE_AUTHOR("Daniel Campello <campello@chromium.org>");
1068+MODULE_DESCRIPTION("Driver for Semtech SX9310/SX9311 proximity sensor");
1069+MODULE_LICENSE("GPL v2");
drivers/iio/temperature/ltc2983.c+2−2
@@ -390,8 +390,8 @@ static struct ltc2983_custom_sensor *__ltc2983_custom_sensor_new( · 389 unmodified lines
390390 * For custom steinhart, the full u32 is taken. For all the others
391391 * the MSB is discarded.
392392 */
393− const u8 n_size = (is_steinhart == true) ? 4 : 3;
394− const u8 e_size = (is_steinhart == true) ? sizeof(u32) : sizeof(u64);
393+ const u8 n_size = is_steinhart ? 4 : 3;
394+ const u8 e_size = is_steinhart ? sizeof(u32) : sizeof(u64);
395395
396396 n_entries = of_property_count_elems_of_size(np, propname, e_size);
397397 /* n_entries must be an even number */
drivers/iio/trigger/iio-trig-hrtimer.c+1−1
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 *
55 * Copyright (C) Intuitive Aerial AB
66 * Written by Marten Svanfeldt, marten@intuitiveaerial.com
7− * Copyright (C) 2012, Analog Device Inc.
7+ * Copyright (C) 2012, Analog Devices Inc.
88 * Author: Lars-Peter Clausen <lars@metafoo.de>
99 * Copyright (C) 2015, Intel Corporation
1010 */
drivers/staging/iio/Documentation/overview.txt+1−1
@@ -34,7 +34,7 @@ turned on or off (if possible) via sysfs interfaces. · 33 unmodified lines
3434 fifo / ring buffers on the sensor chip. These greatly reduce the load
3535 on the host CPU by buffering relatively large numbers of data samples
3636 based on an internal sampling clock. Examples include VTI SCA3000
37−series and Analog Device ADXL345 accelerometers. Each buffer supports
37+series and Analog Devices ADXL345 accelerometers. Each buffer supports
3838 polling to establish when data is available.
3939
4040 * Trigger and software buffer support. In many data analysis
include/linux/fpga/adi-axi-common.h+5−1
@@ -11,9 +11,13 @@ · 10 unmodified lines
1111 #ifndef ADI_AXI_COMMON_H_
1212 #define ADI_AXI_COMMON_H_
1313
14−#define ADI_AXI_REG_VERSION 0x0000
14+#define ADI_AXI_REG_VERSION 0x0000
1515
1616 #define ADI_AXI_PCORE_VER(major, minor, patch) \
1717 (((major) << 16) | ((minor) << 8) | (patch))
1818
19+#define ADI_AXI_PCORE_VER_MAJOR(version) (((version) >> 16) & 0xff)
20+#define ADI_AXI_PCORE_VER_MINOR(version) (((version) >> 8) & 0xff)
21+#define ADI_AXI_PCORE_VER_PATCH(version) ((version) & 0xff)
22+
1923 #endif /* ADI_AXI_COMMON_H_ */
include/linux/iio/adc/ad_sigma_delta.h+0−58
@@ -133,62 +133,4 @@ void ad_sd_cleanup_buffer_and_trigger(struct iio_dev *indio_dev); · 132 unmodified lines
133133
134134 int ad_sd_validate_trigger(struct iio_dev *indio_dev, struct iio_trigger *trig);
135135
136−#define __AD_SD_CHANNEL(_si, _channel1, _channel2, _address, _bits, \
137− _storagebits, _shift, _extend_name, _type, _mask_all) \
138− { \
139− .type = (_type), \
140− .differential = (_channel2 == -1 ? 0 : 1), \
141− .indexed = 1, \
142− .channel = (_channel1), \
143− .channel2 = (_channel2), \
144− .address = (_address), \
145− .extend_name = (_extend_name), \
146− .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
147− BIT(IIO_CHAN_INFO_OFFSET), \
148− .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
149− .info_mask_shared_by_all = _mask_all, \
150− .scan_index = (_si), \
151− .scan_type = { \
152− .sign = 'u', \
153− .realbits = (_bits), \
154− .storagebits = (_storagebits), \
155− .shift = (_shift), \
156− .endianness = IIO_BE, \
157− }, \
158− }
159−
160−#define AD_SD_DIFF_CHANNEL(_si, _channel1, _channel2, _address, _bits, \
161− _storagebits, _shift) \
162− __AD_SD_CHANNEL(_si, _channel1, _channel2, _address, _bits, \
163− _storagebits, _shift, NULL, IIO_VOLTAGE, \
164− BIT(IIO_CHAN_INFO_SAMP_FREQ))
165−
166−#define AD_SD_SHORTED_CHANNEL(_si, _channel, _address, _bits, \
167− _storagebits, _shift) \
168− __AD_SD_CHANNEL(_si, _channel, _channel, _address, _bits, \
169− _storagebits, _shift, "shorted", IIO_VOLTAGE, \
170− BIT(IIO_CHAN_INFO_SAMP_FREQ))
171−
172−#define AD_SD_CHANNEL(_si, _channel, _address, _bits, \
173− _storagebits, _shift) \
174− __AD_SD_CHANNEL(_si, _channel, -1, _address, _bits, \
175− _storagebits, _shift, NULL, IIO_VOLTAGE, \
176− BIT(IIO_CHAN_INFO_SAMP_FREQ))
177−
178−#define AD_SD_CHANNEL_NO_SAMP_FREQ(_si, _channel, _address, _bits, \
179− _storagebits, _shift) \
180− __AD_SD_CHANNEL(_si, _channel, -1, _address, _bits, \
181− _storagebits, _shift, NULL, IIO_VOLTAGE, 0)
182−
183−#define AD_SD_TEMP_CHANNEL(_si, _address, _bits, _storagebits, _shift) \
184− __AD_SD_CHANNEL(_si, 0, -1, _address, _bits, \
185− _storagebits, _shift, NULL, IIO_TEMP, \
186− BIT(IIO_CHAN_INFO_SAMP_FREQ))
187−
188−#define AD_SD_SUPPLY_CHANNEL(_si, _channel, _address, _bits, _storagebits, \
189− _shift) \
190− __AD_SD_CHANNEL(_si, _channel, -1, _address, _bits, \
191− _storagebits, _shift, "supply", IIO_VOLTAGE, \
192− BIT(IIO_CHAN_INFO_SAMP_FREQ))
193−
194136 #endif
include/linux/iio/adc/adi-axi-adc.h+64−0
@@ -0,0 +1,64 @@
1+/* SPDX-License-Identifier: GPL-2.0 */
2+/*
3+ * Analog Devices Generic AXI ADC IP core driver/library
4+ * Link: https://wiki.analog.com/resources/fpga/docs/axi_adc_ip
5+ *
6+ * Copyright 2012-2020 Analog Devices Inc.
7+ */
8+#ifndef __ADI_AXI_ADC_H__
9+#define __ADI_AXI_ADC_H__
10+
11+struct device;
12+struct iio_chan_spec;
13+
14+/**
15+ * struct adi_axi_adc_chip_info - Chip specific information
16+ * @name Chip name
17+ * @id Chip ID (usually product ID)
18+ * @channels Channel specifications of type @struct axi_adc_chan_spec
19+ * @num_channels Number of @channels
20+ * @scale_table Supported scales by the chip; tuples of 2 ints
21+ * @num_scales Number of scales in the table
22+ * @max_rate Maximum sampling rate supported by the device
23+ */
24+struct adi_axi_adc_chip_info {
25+ const char *name;
26+ unsigned int id;
27+
28+ const struct iio_chan_spec *channels;
29+ unsigned int num_channels;
30+
31+ const unsigned int (*scale_table)[2];
32+ int num_scales;
33+
34+ unsigned long max_rate;
35+};
36+
37+/**
38+ * struct adi_axi_adc_conv - data of the ADC attached to the AXI ADC
39+ * @chip_info chip info details for the client ADC
40+ * @preenable_setup op to run in the client before enabling the AXI ADC
41+ * @reg_access IIO debugfs_reg_access hook for the client ADC
42+ * @read_raw IIO read_raw hook for the client ADC
43+ * @write_raw IIO write_raw hook for the client ADC
44+ */
45+struct adi_axi_adc_conv {
46+ const struct adi_axi_adc_chip_info *chip_info;
47+
48+ int (*preenable_setup)(struct adi_axi_adc_conv *conv);
49+ int (*reg_access)(struct adi_axi_adc_conv *conv, unsigned int reg,
50+ unsigned int writeval, unsigned int *readval);
51+ int (*read_raw)(struct adi_axi_adc_conv *conv,
52+ struct iio_chan_spec const *chan,
53+ int *val, int *val2, long mask);
54+ int (*write_raw)(struct adi_axi_adc_conv *conv,
55+ struct iio_chan_spec const *chan,
56+ int val, int val2, long mask);
57+};
58+
59+struct adi_axi_adc_conv *devm_adi_axi_adc_conv_register(struct device *dev,
60+ size_t sizeof_priv);
61+
62+void *adi_axi_adc_conv_priv(struct adi_axi_adc_conv *conv);
63+
64+#endif
include/linux/iio/buffer-dma.h+1−1
@@ -11,7 +11,7 @@ · 10 unmodified lines
1111 #include <linux/kref.h>
1212 #include <linux/spinlock.h>
1313 #include <linux/mutex.h>
14−#include <linux/iio/buffer.h>
14+#include <linux/iio/buffer_impl.h>
1515
1616 struct iio_dma_buffer_queue;
1717 struct iio_dma_buffer_ops;
include/linux/iio/buffer-dmaengine.h+3−0
@@ -14,4 +14,7 @@ struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev, · 13 unmodified lines
1414 const char *channel);
1515 void iio_dmaengine_buffer_free(struct iio_buffer *buffer);
1616
17+struct iio_buffer *devm_iio_dmaengine_buffer_alloc(struct device *dev,
18+ const char *channel);
19+
1720 #endif
include/linux/iio/buffer_impl.h+0−9
@@ -94,12 +94,6 @@ struct iio_buffer { · 93 unmodified lines
9494 unsigned int watermark;
9595
9696 /* private: */
97− /*
98− * @scan_el_attrs: Control of scan elements if that scan mode
99− * control method is used.
100− */
101− struct attribute_group *scan_el_attrs;
102−
10397 /* @scan_timestamp: Does the scan mode include a timestamp. */
10498 bool scan_timestamp;
10599
@@ -115,9 +109,6 @@ struct iio_buffer { · 9 unmodified lines
115109 */
116110 struct attribute_group scan_el_group;
117111
118− /* @stufftoread: Flag to indicate new data. */
119− bool stufftoread;
120−
121112 /* @attrs: Standard attributes of the buffer. */
122113 const struct attribute **attrs;
123114
include/linux/iio/consumer.h+0−18
@@ -63,15 +63,6 @@ void iio_channel_release(struct iio_channel *chan); · 62 unmodified lines
6363 */
6464 struct iio_channel *devm_iio_channel_get(struct device *dev,
6565 const char *consumer_channel);
66−/**
67− * devm_iio_channel_release() - Resource managed version of
68− * iio_channel_release().
69− * @dev: Pointer to consumer device for which resource
70− * is allocared.
71− * @chan: The channel to be released.
72− */
73−void devm_iio_channel_release(struct device *dev, struct iio_channel *chan);
74−
7566 /**
7667 * iio_channel_get_all() - get all channels associated with a client
7768 * @dev: Pointer to consumer device.
@@ -106,15 +97,6 @@ void iio_channel_release_all(struct iio_channel *chan); · 28 unmodified lines
10697 */
10798 struct iio_channel *devm_iio_channel_get_all(struct device *dev);
10899
109−/**
110− * devm_iio_channel_release_all() - Resource managed version of
111− * iio_channel_release_all().
112− * @dev: Pointer to consumer device for which resource
113− * is allocared.
114− * @chan: Array channel to be released.
115− */
116−void devm_iio_channel_release_all(struct device *dev, struct iio_channel *chan);
117−
118100 struct iio_cb_buffer;
119101 /**
120102 * iio_channel_get_all_cb() - register callback for triggered capture
include/linux/iio/hw-consumer.h+0−1
@@ -14,7 +14,6 @@ struct iio_hw_consumer; · 13 unmodified lines
1414 struct iio_hw_consumer *iio_hw_consumer_alloc(struct device *dev);
1515 void iio_hw_consumer_free(struct iio_hw_consumer *hwc);
1616 struct iio_hw_consumer *devm_iio_hw_consumer_alloc(struct device *dev);
17−void devm_iio_hw_consumer_free(struct device *dev, struct iio_hw_consumer *hwc);
1817 int iio_hw_consumer_enable(struct iio_hw_consumer *hwc);
1918 void iio_hw_consumer_disable(struct iio_hw_consumer *hwc);
2019
include/linux/iio/iio.h+1−9
@@ -492,7 +492,7 @@ struct iio_buffer_setup_ops { · 491 unmodified lines
492492 * @buffer: [DRIVER] any buffer present
493493 * @buffer_list: [INTERN] list of all buffers currently attached
494494 * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux
495− * @mlock: [DRIVER] lock used to prevent simultaneous device state
495+ * @mlock: [INTERN] lock used to prevent simultaneous device state
496496 * changes
497497 * @available_scan_masks: [DRIVER] optional array of allowed bitmasks
498498 * @masklength: [INTERN] the length of the mask established from
@@ -593,9 +593,6 @@ void iio_device_unregister(struct iio_dev *indio_dev); · 94 unmodified lines
593593 * calls iio_device_register() internally. Refer to that function for more
594594 * information.
595595 *
596− * If an iio_dev registered with this function needs to be unregistered
597− * separately, devm_iio_device_unregister() must be used.
598− *
599596 * RETURNS:
600597 * 0 on success, negative error number on failure.
601598 */
@@ -603,7 +600,6 @@ void iio_device_unregister(struct iio_dev *indio_dev); · 1 unmodified line
603600 __devm_iio_device_register((dev), (indio_dev), THIS_MODULE);
604601 int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev,
605602 struct module *this_mod);
606−void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev);
607603 int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
608604 int iio_device_claim_direct_mode(struct iio_dev *indio_dev);
609605 void iio_device_release_direct_mode(struct iio_dev *indio_dev);
@@ -694,13 +690,9 @@ static inline struct iio_dev *iio_priv_to_dev(void *priv) · 84 unmodified lines
694690 }
695691
696692 void iio_device_free(struct iio_dev *indio_dev);
697−int devm_iio_device_match(struct device *dev, void *res, void *data);
698693 struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv);
699−void devm_iio_device_free(struct device *dev, struct iio_dev *indio_dev);
700694 struct iio_trigger *devm_iio_trigger_alloc(struct device *dev,
701695 const char *fmt, ...);
702−void devm_iio_trigger_free(struct device *dev, struct iio_trigger *iio_trig);
703−
704696 /**
705697 * iio_buffer_enabled() - helper function to test if the buffer is enabled
706698 * @indio_dev: IIO device structure for device
include/linux/iio/kfifo_buf.h+0−1
@@ -9,6 +9,5 @@ struct iio_buffer *iio_kfifo_allocate(void); · 8 unmodified lines
99 void iio_kfifo_free(struct iio_buffer *r);
1010
1111 struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev);
12−void devm_iio_kfifo_free(struct device *dev, struct iio_buffer *r);
1312
1413 #endif
include/linux/iio/trigger.h+0−3
@@ -141,9 +141,6 @@ int __devm_iio_trigger_register(struct device *dev, · 140 unmodified lines
141141 **/
142142 void iio_trigger_unregister(struct iio_trigger *trig_info);
143143
144−void devm_iio_trigger_unregister(struct device *dev,
145− struct iio_trigger *trig_info);
146−
147144 /**
148145 * iio_trigger_set_immutable() - set an immutable trigger on destination
149146 *
include/linux/iio/triggered_buffer.h+0−2
@@ -18,7 +18,5 @@ int devm_iio_triggered_buffer_setup(struct device *dev, · 17 unmodified lines
1818 irqreturn_t (*h)(int irq, void *p),
1919 irqreturn_t (*thread)(int irq, void *p),
2020 const struct iio_buffer_setup_ops *ops);
21−void devm_iio_triggered_buffer_cleanup(struct device *dev,
22− struct iio_dev *indio_dev);
2321
2422 #endif