History

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

Jonathan writes: First set of IIO new device support, features and cleanup for 5.19 Usual mixed bag. Stand out this time is Andy Shevchenko's continuing effort to move drivers over the generic firmware interfaces. Device support * sprd,sc2720 - upm9620 binding addition. - Refactor and support for sc2720, sc2721 and sc2730. * ti,ads1015 - Refactor driver and add support for TLA2024. Device support (IDs only) * invensense,mpu6050 - Add ID for ICM-20608-D. * st,accel: - Add ID for lis302dl. * st,lsm6dsx - Add support for ASM330LHHX (can fallback to LSM6DSR.) Features * convert drivers to device properties - IIO core - adi,ad7266 - adi,adis16480 - adi,adxl355 - bosch,bmi160 - domintech,dmard06 - fsl,fxas21002c - invensense,mpu3050 - linear,ltc2983 - linear,ltc2632 - maxbotix,mb1232 - maxim,max31856 - maxim,max31865 - multiplexer - ping - rescale - taos,tsl2772 * core - Add runtime check on whether realbits fit in storagebits for each channel. * adi,ad_sigma_delta - Add sequencer support and relevant update_scan_mode callbacks for adi,ad7192 and adi,ad7124. Cleanup and minor fixes * MAINTAINERS - Update Lorenzo Bianconi's email address for IIO drivers. - Add entry for ad3552r and update maintainer in dt-binding doc. * tree-wide - Replace strtobool() with kstrtobool(). - Drop false OF dependencies. * core - Tidy up and document IIO modes. - Take iio_buffer_enabled() out of header allowing current_mode to be moved to the opaque structure. - As all kfifo buffers use the same mode value, drop that parameter and set it unconditionally. - White space fixes and similar. - Drop use of list iterator variable for list_for_each_entry_continue_reverse and use list_prepare_entry to restart. * sysfs-trigger - Replace use of 'found' variable with dedicate list iterator variable. * adi,ad7124 - Drop misleading shift. * adi,ad2s1210 - Remove redundant local variable assignment. * adi,adis16480 - Use local device pointer to reduce repetition. - Improve handling of clocks. * domintech,dmard09 - White space. * dummy driver - Improve error handling. * fsl,mma8452 - Add missing documentation of name element. * invensense,mpu3050 - Stop remove() returning non 0. * kionix,kxsd9 - White space. * linear,ltc2688 - Use local variable for struct device. - Combine of_node_put() error handling paths. * linear,ltc2983 - Avoid use of constants in messages where a define is available. * microchip,mcp4131 - Fix compatible in dt example. * pni,rm3100 - Stop directly accessing iio_dev->current_mode just to find out if the buffer is enabled. * renesas,rzg2l - Relax kconfig constraint to include newer devices. * sprd,sc27xx - Fix wrong scaling mask. - Improve the calibration values. * samsung,ssp - Replace a 'found' variable in favor of an explicit value that was found. * sensortek,stk3xx - Add proximity-near-level binding and driver support. * st,st_sensors: - Drop unused accel_type enum. - Return early in *_write_raw() - Drop unnecessary locking in _avail functions. - Add local lock to protect odr against concurrent updates allowing mlock to no longer be used outside of the core. - Use iio_device_claim_direct_mode() rather than racy checking of the current mode. * st,stmpe-adc - Fix checks on wait_for_completion_timeout(). - Allow use of of_device_id for matching. * st,stm32-dfsdm - Stop accessing iio_dev->current_mode to find out if the buffer is enabled (so we can hide that variable in the opaque structure) * st,vl53l0x - Fix checks on wait_for_completion_timeout. * ti,ads1015 - Add missing ID for ti,ads1115 in binding doc. - Convert from repeated chip ID look up to selecting static const data. - Switch to read_avail() callback. * ti,ads8688 - Use of_device_id for driver matching. * ti,palmas-adc - Drop a warning on minor calibration mismatch leading to slightly negative values after applying the calibration. * tag 'iio-for-5.19a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (95 commits) iio: ti-ads8688: use of_device_id for OF matching iio: stmpe-adc: use of_device_id for OF matching dt-bindings: iio: Fix incorrect compatible strings in examples iio: gyro: mpu3050: Make mpu3050_common_remove() return void iio: dac: ltc2632: Make use of device properties iio: temperature: max31865: Make use of device properties iio: proximity: mb1232: Switch to use fwnode_irq_get() iio: imu: adis16480: Improve getting the optional clocks iio: imu: adis16480: Use temporary variable for struct device iio: imu: adis16480: Make use of device properties staging: iio: ad2s1210: remove redundant assignment to variable negative iio: adc: sc27xx: add support for PMIC sc2730 iio: adc: sc27xx: add support for PMIC sc2720 and sc2721 iio: adc: sc27xx: refactor some functions for support more PMiCs iio: adc: sc27xx: structure adjustment and optimization iio: adc: sc27xx: Fine tune the scale calibration values iio: adc: sc27xx: fix read big scale voltage not right dt-bindings:iio:adc: add sprd,ump9620-adc dt-binding iio: proximity: stk3310: Export near level property for proximity sensor dt-bindings: iio: light: stk33xx: Add proximity-near-level ...

Greg Kroah-Hartman committed 4 years ago

Commit bcfa9542 parents 33a1c66 eda75f8122 files · +1718 −835Browse files

Unified · Split

122 files
  1. Documentation/devicetree/bindings/iio/adc/renesas,rzg2l-adc.yaml +2 −1
  2. Documentation/devicetree/bindings/iio/adc/sprd,sc2720-adc.yaml +54 −6
  3. Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml +5 −2
  4. Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml +1 −1
  5. Documentation/devicetree/bindings/iio/dac/lltc,ltc2632.yaml +1 −1
  6. Documentation/devicetree/bindings/iio/imu/invensense,mpu6050.yaml +19 −15
  7. Documentation/devicetree/bindings/iio/imu/st,lsm6dsx.yaml +21 −17
  8. Documentation/devicetree/bindings/iio/light/stk33xx.yaml +6 −0
  9. Documentation/devicetree/bindings/iio/potentiometer/microchip,mcp4131.yaml +1 −1
  10. Documentation/devicetree/bindings/iio/st,st-sensors.yaml +1 −0
  11. MAINTAINERS +10 −2
  12. drivers/iio/accel/Kconfig +0 −1
  13. drivers/iio/accel/adxl355_core.c +2 −5
  14. drivers/iio/accel/adxl367.c +0 −1
  15. drivers/iio/accel/bmc150-accel-core.c +2 −2
  16. drivers/iio/accel/dmard09.c +1 −1
  17. drivers/iio/accel/fxls8962af-core.c +0 −1
  18. drivers/iio/accel/kxsd9-spi.c +2 −2
  19. drivers/iio/accel/mma8452.c +1 −0
  20. drivers/iio/accel/sca3000.c +0 −1
  21. drivers/iio/accel/ssp_accel_sensor.c +0 −1
  22. drivers/iio/accel/st_accel.h +2 −26
  23. drivers/iio/accel/st_accel_core.c +4 −10
  24. drivers/iio/accel/st_accel_i2c.c +5 −0
  25. drivers/iio/accel/st_accel_spi.c +5 −0
  26. drivers/iio/adc/Kconfig +1 −1
  27. drivers/iio/adc/ad7124.c +81 −5
  28. drivers/iio/adc/ad7192.c +65 −3
  29. drivers/iio/adc/ad7266.c +14 −30
  30. drivers/iio/adc/ad7280a.c +1 −1
  31. drivers/iio/adc/ad_sigma_delta.c +133 −10
  32. drivers/iio/adc/at91-sama5d2_adc.c +2 −2
  33. drivers/iio/adc/ina2xx-adc.c +1 −2
  34. drivers/iio/adc/palmas_gpadc.c +2 −1
  35. drivers/iio/adc/sc27xx_adc.c +435 −35
  36. drivers/iio/adc/stm32-dfsdm-adc.c +2 −3
  37. drivers/iio/adc/stmpe-adc.c +11 −10
  38. drivers/iio/adc/ti-ads1015.c +232 −166
  39. drivers/iio/adc/ti-ads8688.c +1 −0
  40. drivers/iio/adc/ti_am335x_adc.c +1 −3
  41. drivers/iio/afe/Kconfig +0 −1
  42. drivers/iio/afe/iio-rescale.c +2 −3
  43. drivers/iio/buffer/kfifo_buf.c +1 −9
  44. drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +2 −3
  45. drivers/iio/common/scmi_sensors/scmi_iio.c +0 −1
  46. drivers/iio/common/ssp_sensors/ssp_spi.c +6 −7
  47. drivers/iio/common/st_sensors/st_sensors_core.c +27 −23
  48. drivers/iio/dac/Kconfig +1 −3
  49. drivers/iio/dac/ad5064.c +1 −1
  50. drivers/iio/dac/ad5360.c +1 −1
  51. drivers/iio/dac/ad5380.c +1 −1
  52. drivers/iio/dac/ad5446.c +1 −1
  53. drivers/iio/dac/ad5504.c +1 −1
  54. drivers/iio/dac/ad5624r_spi.c +1 −1
  55. drivers/iio/dac/ad5686.c +1 −1
  56. drivers/iio/dac/ad5755.c +1 −1
  57. drivers/iio/dac/ad5791.c +1 −1
  58. drivers/iio/dac/ad7303.c +1 −1
  59. drivers/iio/dac/ltc2632.c +4 −4
  60. drivers/iio/dac/ltc2688.c +9 −10
  61. drivers/iio/dac/max5821.c +1 −1
  62. drivers/iio/dac/mcp4725.c +2 −2
  63. drivers/iio/dac/stm32-dac.c +1 −1
  64. drivers/iio/dac/ti-dac082s085.c +1 −1
  65. drivers/iio/dac/ti-dac5571.c +1 −1
  66. drivers/iio/dac/ti-dac7311.c +1 −1
  67. drivers/iio/dummy/iio_simple_dummy.c +12 −8
  68. drivers/iio/frequency/ad9523.c +1 −1
  69. drivers/iio/gyro/fxas21002c_core.c +3 −5
  70. drivers/iio/gyro/mpu3050-core.c +6 −8
  71. drivers/iio/gyro/mpu3050-i2c.c +3 −1
  72. drivers/iio/gyro/mpu3050.h +1 −1
  73. drivers/iio/gyro/ssp_gyro_sensor.c +0 −1
  74. drivers/iio/gyro/st_gyro_core.c +4 −11
  75. drivers/iio/health/max30100.c +0 −1
  76. drivers/iio/health/max30102.c +0 −1
  77. drivers/iio/imu/adis16480.c +43 −48
  78. drivers/iio/imu/bmi160/bmi160_core.c +6 −21
  79. drivers/iio/imu/bmi160/bmi160_i2c.c +6 −7
  80. drivers/iio/imu/bmi160/bmi160_spi.c +11 −7
  81. drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +0 −1
  82. drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +0 −1
  83. drivers/iio/imu/inv_mpu6050/Kconfig +2 −2
  84. drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +9 −0
  85. drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +6 −0
  86. drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +2 −0
  87. drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c +5 −0
  88. drivers/iio/imu/st_lsm6dsx/Kconfig +3 −3
  89. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +2 −0
  90. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +2 −2
  91. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +5 −1
  92. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c +5 −0
  93. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c +5 −0
  94. drivers/iio/industrialio-buffer.c +29 −13
  95. drivers/iio/industrialio-core.c +37 −9
  96. drivers/iio/industrialio-event.c +1 −1
  97. drivers/iio/industrialio-trigger.c +1 −1
  98. drivers/iio/light/Kconfig +0 −1
  99. drivers/iio/light/apds9960.c +0 −1
  100. drivers/iio/light/stk3310.c +25 −0
  101. drivers/iio/light/tsl2772.c +10 −15
  102. drivers/iio/magnetometer/Kconfig +0 −1
  103. drivers/iio/magnetometer/rm3100-core.c +3 −12
  104. drivers/iio/magnetometer/st_magn_core.c +4 −11
  105. drivers/iio/multiplexer/Kconfig +0 −1
  106. drivers/iio/multiplexer/iio-mux.c +23 −26
  107. drivers/iio/pressure/st_pressure_core.c +2 −6
  108. drivers/iio/proximity/mb1232.c +5 −3
  109. drivers/iio/proximity/ping.c +2 −3
  110. drivers/iio/proximity/vl53l0x-i2c.c +3 −4
  111. drivers/iio/temperature/ltc2983.c +120 −116
  112. drivers/iio/temperature/max31856.c +3 −3
  113. drivers/iio/temperature/max31865.c +3 −1
  114. drivers/iio/trigger/iio-trig-sysfs.c +5 −6
  115. drivers/staging/iio/cdc/ad7746.c +1 −1
  116. drivers/staging/iio/impedance-analyzer/ad5933.c +0 −1
  117. drivers/staging/iio/resolver/ad2s1210.c +0 −1
  118. include/linux/iio/adc/ad_sigma_delta.h +38 −0
  119. include/linux/iio/common/st_sensors.h +3 −0
  120. include/linux/iio/iio-opaque.h +4 −0
  121. include/linux/iio/iio.h +56 −14
  122. include/linux/iio/kfifo_buf.h +2 −3
Documentation/devicetree/bindings/iio/adc/renesas,rzg2l-adc.yaml+2−1
@@ -19,7 +19,8 @@ properties: · 18 unmodified lines
1919 compatible:
2020 items:
2121 - enum:
22− - renesas,r9a07g044-adc # RZ/G2{L,LC}
22+ - renesas,r9a07g044-adc # RZ/G2L
23+ - renesas,r9a07g054-adc # RZ/V2L
2324 - const: renesas,rzg2l-adc
2425
2526 reg:
Documentation/devicetree/bindings/iio/adc/sprd,sc2720-adc.yaml+54−6
@@ -20,6 +20,7 @@ properties: · 19 unmodified lines
2020 - sprd,sc2723-adc
2121 - sprd,sc2730-adc
2222 - sprd,sc2731-adc
23+ - sprd,ump9620-adc
2324
2425 reg:
2526 maxItems: 1
@@ -33,13 +34,39 @@ properties: · 7 unmodified lines
3334 hwlocks:
3435 maxItems: 1
3536
36− nvmem-cells:
37− maxItems: 2
37+ nvmem-cells: true
3838
39− nvmem-cell-names:
40− items:
41− - const: big_scale_calib
42− - const: small_scale_calib
39+ nvmem-cell-names: true
40+
41+allOf:
42+ - if:
43+ not:
44+ properties:
45+ compatible:
46+ contains:
47+ enum:
48+ - sprd,ump9620-adc
49+ then:
50+ properties:
51+ nvmem-cells:
52+ maxItems: 2
53+ nvmem-cell-names:
54+ items:
55+ - const: big_scale_calib
56+ - const: small_scale_calib
57+
58+ else:
59+ properties:
60+ nvmem-cells:
61+ maxItems: 6
62+ nvmem-cell-names:
63+ items:
64+ - const: big_scale_calib1
65+ - const: big_scale_calib2
66+ - const: small_scale_calib1
67+ - const: small_scale_calib2
68+ - const: vbat_det_cal1
69+ - const: vbat_det_cal2
4370
4471 required:
4572 - compatible
@@ -69,4 +96,25 @@ examples: · 23 unmodified lines
6996 nvmem-cell-names = "big_scale_calib", "small_scale_calib";
7097 };
7198 };
99+
100+ - |
101+ #include <dt-bindings/interrupt-controller/irq.h>
102+ pmic {
103+ #address-cells = <1>;
104+ #size-cells = <0>;
105+ adc@504 {
106+ compatible = "sprd,ump9620-adc";
107+ reg = <0x504>;
108+ interrupt-parent = <&ump9620_pmic>;
109+ interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
110+ #io-channel-cells = <1>;
111+ hwlocks = <&hwlock 4>;
112+ nvmem-cells = <&adc_bcal1>, <&adc_bcal2>,
113+ <&adc_scal1>, <&adc_scal2>,
114+ <&vbat_det_cal1>, <&vbat_det_cal2>;
115+ nvmem-cell-names = "big_scale_calib1", "big_scale_calib2",
116+ "small_scale_calib1", "small_scale_calib2",
117+ "vbat_det_cal1", "vbat_det_cal2";
118+ };
119+ };
72120 ...
Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml+5−2
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 $id: http://devicetree.org/schemas/iio/adc/ti,ads1015.yaml#
55 $schema: http://devicetree.org/meta-schemas/core.yaml#
66
7−title: TI ADS1015 4 channel I2C analog to digital converter
7+title: TI ADS1015/ADS1115 4 channel I2C analog to digital converter
88
99 maintainers:
1010 - Daniel Baluta <daniel.baluta@nxp.com>
@@ -15,7 +15,10 @@ description: | · 4 unmodified lines
1515
1616 properties:
1717 compatible:
18− const: ti,ads1015
18+ enum:
19+ - ti,ads1015
20+ - ti,ads1115
21+ - ti,tla2024
1922
2023 reg:
2124 maxItems: 1
Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml+1−1
@@ -8,7 +8,7 @@ $schema: http://devicetree.org/meta-schemas/core.yaml# · 7 unmodified lines
88 title: Analog Devices AD2552R DAC device driver
99
1010 maintainers:
11− - Mihail Chindris <mihail.chindris@analog.com>
11+ - Nuno Sá <nuno.sa@analog.com>
1212
1313 description: |
1414 Bindings for the Analog Devices AD3552R DAC device and similar.
Documentation/devicetree/bindings/iio/dac/lltc,ltc2632.yaml+1−1
@@ -68,7 +68,7 @@ examples: · 67 unmodified lines
6868 #size-cells = <0>;
6969
7070 dac@0 {
71− compatible = "lltc,ltc2632";
71+ compatible = "lltc,ltc2632-l12";
7272 reg = <0>; /* CS0 */
7373 spi-max-frequency = <1000000>;
7474 vref-supply = <&vref>;
Documentation/devicetree/bindings/iio/imu/invensense,mpu6050.yaml+19−15
@@ -14,21 +14,25 @@ description: | · 13 unmodified lines
1414
1515 properties:
1616 compatible:
17− enum:
18− - invensense,iam20680
19− - invensense,icm20608
20− - invensense,icm20609
21− - invensense,icm20689
22− - invensense,icm20602
23− - invensense,icm20690
24− - invensense,mpu6000
25− - invensense,mpu6050
26− - invensense,mpu6500
27− - invensense,mpu6515
28− - invensense,mpu6880
29− - invensense,mpu9150
30− - invensense,mpu9250
31− - invensense,mpu9255
17+ oneOf:
18+ - enum:
19+ - invensense,iam20680
20+ - invensense,icm20608
21+ - invensense,icm20609
22+ - invensense,icm20689
23+ - invensense,icm20602
24+ - invensense,icm20690
25+ - invensense,mpu6000
26+ - invensense,mpu6050
27+ - invensense,mpu6500
28+ - invensense,mpu6515
29+ - invensense,mpu6880
30+ - invensense,mpu9150
31+ - invensense,mpu9250
32+ - invensense,mpu9255
33+ - items:
34+ - const: invensense,icm20608d
35+ - const: invensense,icm20608
3236
3337 reg:
3438 maxItems: 1
Documentation/devicetree/bindings/iio/imu/st,lsm6dsx.yaml+21−17
@@ -14,23 +14,27 @@ description: · 13 unmodified lines
1414
1515 properties:
1616 compatible:
17− enum:
18− - st,lsm6ds3
19− - st,lsm6ds3h
20− - st,lsm6dsl
21− - st,lsm6dsm
22− - st,ism330dlc
23− - st,lsm6dso
24− - st,asm330lhh
25− - st,lsm6dsox
26− - st,lsm6dsr
27− - st,lsm6ds3tr-c
28− - st,ism330dhcx
29− - st,lsm9ds1-imu
30− - st,lsm6ds0
31− - st,lsm6dsrx
32− - st,lsm6dst
33− - st,lsm6dsop
17+ oneOf:
18+ - enum:
19+ - st,lsm6ds3
20+ - st,lsm6ds3h
21+ - st,lsm6dsl
22+ - st,lsm6dsm
23+ - st,ism330dlc
24+ - st,lsm6dso
25+ - st,asm330lhh
26+ - st,lsm6dsox
27+ - st,lsm6dsr
28+ - st,lsm6ds3tr-c
29+ - st,ism330dhcx
30+ - st,lsm9ds1-imu
31+ - st,lsm6ds0
32+ - st,lsm6dsrx
33+ - st,lsm6dst
34+ - st,lsm6dsop
35+ - items:
36+ - const: st,asm330lhhx
37+ - const: st,lsm6dsr
3438
3539 reg:
3640 maxItems: 1
Documentation/devicetree/bindings/iio/light/stk33xx.yaml+6−0
@@ -13,6 +13,9 @@ maintainers: · 12 unmodified lines
1313 description: |
1414 Ambient light and proximity sensor over an i2c interface.
1515
16+allOf:
17+ - $ref: ../common.yaml#
18+
1619 properties:
1720 compatible:
1821 enum:
@@ -26,6 +29,8 @@ properties: · 7 unmodified lines
2629 interrupts:
2730 maxItems: 1
2831
32+ proximity-near-level: true
33+
2934 required:
3035 - compatible
3136 - reg
@@ -44,6 +49,7 @@ examples: · 12 unmodified lines
4449 stk3310@48 {
4550 compatible = "sensortek,stk3310";
4651 reg = <0x48>;
52+ proximity-near-level = <25>;
4753 interrupt-parent = <&gpio1>;
4854 interrupts = <5 IRQ_TYPE_LEVEL_LOW>;
4955 };
Documentation/devicetree/bindings/iio/potentiometer/microchip,mcp4131.yaml+1−1
@@ -95,7 +95,7 @@ examples: · 94 unmodified lines
9595 #size-cells = <0>;
9696
9797 potentiometer@0 {
98− compatible = "mcp4131-502";
98+ compatible = "microchip,mcp4131-502";
9999 reg = <0>;
100100 spi-max-frequency = <500000>;
101101 };
Documentation/devicetree/bindings/iio/st,st-sensors.yaml+1−0
@@ -29,6 +29,7 @@ properties: · 28 unmodified lines
2929 - st,lis2dw12
3030 - st,lis2hh12
3131 - st,lis2dh12-accel
32+ - st,lis302dl
3233 - st,lis331dl-accel
3334 - st,lis331dlh-accel
3435 - st,lis3de
MAINTAINERS+10−2
@@ -1091,6 +1091,14 @@ W: https://ez.analog.com/linux-software-drivers · 1090 unmodified lines
10911091 F: Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
10921092 F: drivers/iio/adc/ad7292.c
10931093
1094+ANALOG DEVICES INC AD3552R DRIVER
1095+M: Nuno Sá <nuno.sa@analog.com>
1096+L: linux-iio@vger.kernel.org
1097+S: Supported
1098+W: https://ez.analog.com/linux-software-drivers
1099+F: Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml
1100+F: drivers/iio/dac/ad3552r.c
1101+
10941102 ANALOG DEVICES INC AD7293 DRIVER
10951103 M: Antoniu Miclaus <antoniu.miclaus@analog.com>
10961104 L: linux-iio@vger.kernel.org
@@ -9006,7 +9014,7 @@ S: Maintained · 7909 unmodified lines
90069014 F: drivers/input/touchscreen/htcpen.c
90079015
90089016 HTS221 TEMPERATURE-HUMIDITY IIO DRIVER
9009−M: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
9017+M: Lorenzo Bianconi <lorenzo@kernel.org>
90109018 L: linux-iio@vger.kernel.org
90119019 S: Maintained
90129020 W: http://www.st.com/
@@ -18637,7 +18645,7 @@ S: Maintained · 9624 unmodified lines
1863718645 F: arch/alpha/kernel/srm_env.c
1863818646
1863918647 ST LSM6DSx IMU IIO DRIVER
18640−M: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
18648+M: Lorenzo Bianconi <lorenzo@kernel.org>
1864118649 L: linux-iio@vger.kernel.org
1864218650 S: Maintained
1864318651 W: http://www.st.com/
drivers/iio/accel/Kconfig+0−1
@@ -290,7 +290,6 @@ config DA311 · 289 unmodified lines
290290
291291 config DMARD06
292292 tristate "Domintech DMARD06 Digital Accelerometer Driver"
293− depends on OF || COMPILE_TEST
294293 depends on I2C
295294 help
296295 Say yes here to build support for the Domintech low-g tri-axial
drivers/iio/accel/adxl355_core.c+2−5
@@ -18,7 +18,7 @@ · 17 unmodified lines
1818 #include <linux/math64.h>
1919 #include <linux/module.h>
2020 #include <linux/mod_devicetable.h>
21−#include <linux/of_irq.h>
21+#include <linux/property.h>
2222 #include <linux/regmap.h>
2323 #include <linux/units.h>
2424
@@ -745,10 +745,7 @@ int adxl355_core_probe(struct device *dev, struct regmap *regmap, · 720 unmodified lines
745745 return ret;
746746 }
747747
748− /*
749− * TODO: Would be good to move it to the generic version.
750− */
751− irq = of_irq_get_byname(dev->of_node, "DRDY");
748+ irq = fwnode_irq_get_byname(dev_fwnode(dev), "DRDY");
752749 if (irq > 0) {
753750 ret = adxl355_probe_trigger(indio_dev, irq);
754751 if (ret)
drivers/iio/accel/adxl367.c+0−1
@@ -1567,7 +1567,6 @@ int adxl367_probe(struct device *dev, const struct adxl367_ops *ops, · 1566 unmodified lines
15671567 return ret;
15681568
15691569 ret = devm_iio_kfifo_buffer_setup_ext(st->dev, indio_dev,
1570− INDIO_BUFFER_SOFTWARE,
15711570 &adxl367_buffer_ops,
15721571 adxl367_fifo_attributes);
15731572 if (ret)
drivers/iio/accel/bmc150-accel-core.c+2−2
@@ -1525,7 +1525,7 @@ static int bmc150_accel_buffer_postenable(struct iio_dev *indio_dev) · 1524 unmodified lines
15251525 struct bmc150_accel_data *data = iio_priv(indio_dev);
15261526 int ret = 0;
15271527
1528− if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1528+ if (iio_device_get_current_mode(indio_dev) == INDIO_BUFFER_TRIGGERED)
15291529 return 0;
15301530
15311531 mutex_lock(&data->mutex);
@@ -1557,7 +1557,7 @@ static int bmc150_accel_buffer_predisable(struct iio_dev *indio_dev) · 25 unmodified lines
15571557 {
15581558 struct bmc150_accel_data *data = iio_priv(indio_dev);
15591559
1560− if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1560+ if (iio_device_get_current_mode(indio_dev) == INDIO_BUFFER_TRIGGERED)
15611561 return 0;
15621562
15631563 mutex_lock(&data->mutex);
drivers/iio/accel/dmard09.c+1−1
@@ -24,7 +24,7 @@ · 23 unmodified lines
2424 #define DMARD09_AXIS_Y 1
2525 #define DMARD09_AXIS_Z 2
2626 #define DMARD09_AXIS_X_OFFSET ((DMARD09_AXIS_X + 1) * 2)
27−#define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1 )* 2)
27+#define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1) * 2)
2828 #define DMARD09_AXIS_Z_OFFSET ((DMARD09_AXIS_Z + 1) * 2)
2929
3030 struct dmard09_data {
drivers/iio/accel/fxls8962af-core.c+0−1
@@ -1217,7 +1217,6 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq) · 1216 unmodified lines
12171217 return ret;
12181218
12191219 ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
1220− INDIO_BUFFER_SOFTWARE,
12211220 &fxls8962af_buffer_ops);
12221221 if (ret)
12231222 return ret;
drivers/iio/accel/kxsd9-spi.c+2−2
@@ -44,8 +44,8 @@ static const struct spi_device_id kxsd9_spi_id[] = { · 43 unmodified lines
4444 MODULE_DEVICE_TABLE(spi, kxsd9_spi_id);
4545
4646 static const struct of_device_id kxsd9_of_match[] = {
47− { .compatible = "kionix,kxsd9" },
48− { },
47+ { .compatible = "kionix,kxsd9" },
48+ { }
4949 };
5050 MODULE_DEVICE_TABLE(of, kxsd9_of_match);
5151
drivers/iio/accel/mma8452.c+1−0
@@ -166,6 +166,7 @@ static const struct mma8452_event_regs trans_ev_regs = { · 165 unmodified lines
166166
167167 /**
168168 * struct mma_chip_info - chip specific data
169+ * @name: part number of device reported via 'name' attr
169170 * @chip_id: WHO_AM_I register's value
170171 * @channels: struct iio_chan_spec matching the device's
171172 * capabilities
drivers/iio/accel/sca3000.c+0−1
@@ -1474,7 +1474,6 @@ static int sca3000_probe(struct spi_device *spi) · 1473 unmodified lines
14741474 indio_dev->modes = INDIO_DIRECT_MODE;
14751475
14761476 ret = devm_iio_kfifo_buffer_setup(&spi->dev, indio_dev,
1477− INDIO_BUFFER_SOFTWARE,
14781477 &sca3000_ring_setup_ops);
14791478 if (ret)
14801479 return ret;
drivers/iio/accel/ssp_accel_sensor.c+0−1
@@ -113,7 +113,6 @@ static int ssp_accel_probe(struct platform_device *pdev) · 112 unmodified lines
113113 indio_dev->available_scan_masks = ssp_accel_scan_mask;
114114
115115 ret = devm_iio_kfifo_buffer_setup(&pdev->dev, indio_dev,
116− INDIO_BUFFER_SOFTWARE,
117116 &ssp_accel_buffer_ops);
118117 if (ret)
119118 return ret;
drivers/iio/accel/st_accel.h+2−26
@@ -14,32 +14,6 @@ · 13 unmodified lines
1414 #include <linux/types.h>
1515 #include <linux/iio/common/st_sensors.h>
1616
17−enum st_accel_type {
18− LSM303DLH,
19− LSM303DLHC,
20− LIS3DH,
21− LSM330D,
22− LSM330DL,
23− LSM330DLC,
24− LIS331DLH,
25− LSM303DL,
26− LSM303DLM,
27− LSM330,
28− LSM303AGR,
29− LIS2DH12,
30− LIS3L02DQ,
31− LNG2DM,
32− H3LIS331DL,
33− LIS331DL,
34− LIS3LV02DL,
35− LIS2DW12,
36− LIS3DHH,
37− LIS2DE12,
38− LIS2HH12,
39− SC7A20,
40− ST_ACCEL_MAX,
41−};
42−
4317 #define H3LIS331DL_ACCEL_DEV_NAME "h3lis331dl_accel"
4418 #define LIS3LV02DL_ACCEL_DEV_NAME "lis3lv02dl_accel"
4519 #define LSM303DLHC_ACCEL_DEV_NAME "lsm303dlhc_accel"
@@ -62,8 +36,10 @@ enum st_accel_type { · 16 unmodified lines
6236 #define LIS3DE_ACCEL_DEV_NAME "lis3de"
6337 #define LIS2DE12_ACCEL_DEV_NAME "lis2de12"
6438 #define LIS2HH12_ACCEL_DEV_NAME "lis2hh12"
39+#define LIS302DL_ACCEL_DEV_NAME "lis302dl"
6540 #define SC7A20_ACCEL_DEV_NAME "sc7a20"
6641
42+
6743 #ifdef CONFIG_IIO_BUFFER
6844 int st_accel_allocate_ring(struct iio_dev *indio_dev);
6945 int st_accel_trig_set_state(struct iio_trigger *trig, bool state);
drivers/iio/accel/st_accel_core.c+4−10
@@ -444,6 +444,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { · 443 unmodified lines
444444 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
445445 .sensors_supported = {
446446 [0] = LIS331DL_ACCEL_DEV_NAME,
447+ [1] = LIS302DL_ACCEL_DEV_NAME,
447448 },
448449 .ch = (struct iio_chan_spec *)st_accel_8bit_channels,
449450 .odr = {
@@ -1209,28 +1210,21 @@ read_error: · 759 unmodified lines
12091210 static int st_accel_write_raw(struct iio_dev *indio_dev,
12101211 struct iio_chan_spec const *chan, int val, int val2, long mask)
12111212 {
1212− int err;
1213−
12141213 switch (mask) {
12151214 case IIO_CHAN_INFO_SCALE: {
12161215 int gain;
12171216
12181217 gain = val * 1000000 + val2;
1219− err = st_sensors_set_fullscale_by_gain(indio_dev, gain);
1220− break;
1218+ return st_sensors_set_fullscale_by_gain(indio_dev, gain);
12211219 }
12221220 case IIO_CHAN_INFO_SAMP_FREQ:
12231221 if (val2)
12241222 return -EINVAL;
1225− mutex_lock(&indio_dev->mlock);
1226− err = st_sensors_set_odr(indio_dev, val);
1227− mutex_unlock(&indio_dev->mlock);
1228− return err;
1223+
1224+ return st_sensors_set_odr(indio_dev, val);
12291225 default:
12301226 return -EINVAL;
12311227 }
1232−
1233− return err;
12341228 }
12351229
12361230 static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
drivers/iio/accel/st_accel_i2c.c+5−0
@@ -107,6 +107,10 @@ static const struct of_device_id st_accel_of_match[] = { · 106 unmodified lines
107107 .compatible = "st,lis2hh12",
108108 .data = LIS2HH12_ACCEL_DEV_NAME,
109109 },
110+ {
111+ .compatible = "st,lis302dl",
112+ .data = LIS302DL_ACCEL_DEV_NAME,
113+ },
110114 {
111115 .compatible = "silan,sc7a20",
112116 .data = SC7A20_ACCEL_DEV_NAME,
@@ -146,6 +150,7 @@ static const struct i2c_device_id st_accel_id_table[] = { · 33 unmodified lines
146150 { LIS3DE_ACCEL_DEV_NAME },
147151 { LIS2DE12_ACCEL_DEV_NAME },
148152 { LIS2HH12_ACCEL_DEV_NAME },
153+ { LIS302DL_ACCEL_DEV_NAME },
149154 { SC7A20_ACCEL_DEV_NAME },
150155 {},
151156 };
drivers/iio/accel/st_accel_spi.c+5−0
@@ -92,6 +92,10 @@ static const struct of_device_id st_accel_of_match[] = { · 91 unmodified lines
9292 .compatible = "st,lis3de",
9393 .data = LIS3DE_ACCEL_DEV_NAME,
9494 },
95+ {
96+ .compatible = "st,lis302dl",
97+ .data = LIS302DL_ACCEL_DEV_NAME,
98+ },
9599 {}
96100 };
97101 MODULE_DEVICE_TABLE(of, st_accel_of_match);
@@ -147,6 +151,7 @@ static const struct spi_device_id st_accel_id_table[] = { · 49 unmodified lines
147151 { LIS2DW12_ACCEL_DEV_NAME },
148152 { LIS3DHH_ACCEL_DEV_NAME },
149153 { LIS3DE_ACCEL_DEV_NAME },
154+ { LIS302DL_ACCEL_DEV_NAME },
150155 {},
151156 };
152157 MODULE_DEVICE_TABLE(spi, st_accel_id_table);
drivers/iio/adc/Kconfig+1−1
@@ -910,7 +910,7 @@ config ROCKCHIP_SARADC · 909 unmodified lines
910910
911911 config RZG2L_ADC
912912 tristate "Renesas RZ/G2L ADC driver"
913− depends on ARCH_R9A07G044 || COMPILE_TEST
913+ depends on ARCH_RZG2L || COMPILE_TEST
914914 help
915915 Say yes here to build support for the ADC found in Renesas
916916 RZ/G2L family.
drivers/iio/adc/ad7124.c+81−5
@@ -43,6 +43,8 @@ · 42 unmodified lines
4343 #define AD7124_STATUS_POR_FLAG_MSK BIT(4)
4444
4545 /* AD7124_ADC_CONTROL */
46+#define AD7124_ADC_STATUS_EN_MSK BIT(10)
47+#define AD7124_ADC_STATUS_EN(x) FIELD_PREP(AD7124_ADC_STATUS_EN_MSK, x)
4648 #define AD7124_ADC_CTRL_REF_EN_MSK BIT(8)
4749 #define AD7124_ADC_CTRL_REF_EN(x) FIELD_PREP(AD7124_ADC_CTRL_REF_EN_MSK, x)
4850 #define AD7124_ADC_CTRL_PWR_MSK GENMASK(7, 6)
@@ -188,7 +190,6 @@ static const struct iio_chan_spec ad7124_channel_template = { · 139 unmodified lines
188190 .sign = 'u',
189191 .realbits = 24,
190192 .storagebits = 32,
191− .shift = 8,
192193 .endianness = IIO_BE,
193194 },
194195 };
@@ -501,26 +502,70 @@ static int ad7124_prepare_read(struct ad7124_state *st, int address) · 306 unmodified lines
501502 return ad7124_enable_channel(st, &st->channels[address]);
502503 }
503504
505+static int __ad7124_set_channel(struct ad_sigma_delta *sd, unsigned int channel)
506+{
507+ struct ad7124_state *st = container_of(sd, struct ad7124_state, sd);
508+
509+ return ad7124_prepare_read(st, channel);
510+}
511+
504512 static int ad7124_set_channel(struct ad_sigma_delta *sd, unsigned int channel)
505513 {
506514 struct ad7124_state *st = container_of(sd, struct ad7124_state, sd);
507515 int ret;
508516
509517 mutex_lock(&st->cfgs_lock);
510− ret = ad7124_prepare_read(st, channel);
518+ ret = __ad7124_set_channel(sd, channel);
511519 mutex_unlock(&st->cfgs_lock);
512520
513521 return ret;
514522 }
515523
524+static int ad7124_append_status(struct ad_sigma_delta *sd, bool append)
525+{
526+ struct ad7124_state *st = container_of(sd, struct ad7124_state, sd);
527+ unsigned int adc_control = st->adc_control;
528+ int ret;
529+
530+ adc_control &= ~AD7124_ADC_STATUS_EN_MSK;
531+ adc_control |= AD7124_ADC_STATUS_EN(append);
532+
533+ ret = ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, adc_control);
534+ if (ret < 0)
535+ return ret;
536+
537+ st->adc_control = adc_control;
538+
539+ return 0;
540+}
541+
542+static int ad7124_disable_all(struct ad_sigma_delta *sd)
543+{
544+ struct ad7124_state *st = container_of(sd, struct ad7124_state, sd);
545+ int ret;
546+ int i;
547+
548+ for (i = 0; i < st->num_channels; i++) {
549+ ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i), AD7124_CHANNEL_EN_MSK, 0, 2);
550+ if (ret < 0)
551+ return ret;
552+ }
553+
554+ return 0;
555+}
556+
516557 static const struct ad_sigma_delta_info ad7124_sigma_delta_info = {
517558 .set_channel = ad7124_set_channel,
559+ .append_status = ad7124_append_status,
560+ .disable_all = ad7124_disable_all,
518561 .set_mode = ad7124_set_mode,
519562 .has_registers = true,
520563 .addr_shift = 0,
521564 .read_mask = BIT(6),
565+ .status_ch_mask = GENMASK(3, 0),
522566 .data_reg = AD7124_DATA,
523− .irq_flags = IRQF_TRIGGER_FALLING
567+ .num_slots = 8,
568+ .irq_flags = IRQF_TRIGGER_FALLING,
524569 };
525570
526571 static int ad7124_read_raw(struct iio_dev *indio_dev,
@@ -670,11 +715,40 @@ static const struct attribute_group ad7124_attrs_group = { · 143 unmodified lines
670715 .attrs = ad7124_attributes,
671716 };
672717
718+static int ad7124_update_scan_mode(struct iio_dev *indio_dev,
719+ const unsigned long *scan_mask)
720+{
721+ struct ad7124_state *st = iio_priv(indio_dev);
722+ bool bit_set;
723+ int ret;
724+ int i;
725+
726+ mutex_lock(&st->cfgs_lock);
727+ for (i = 0; i < st->num_channels; i++) {
728+ bit_set = test_bit(i, scan_mask);
729+ if (bit_set)
730+ ret = __ad7124_set_channel(&st->sd, i);
731+ else
732+ ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i), AD7124_CHANNEL_EN_MSK,
733+ 0, 2);
734+ if (ret < 0) {
735+ mutex_unlock(&st->cfgs_lock);
736+
737+ return ret;
738+ }
739+ }
740+
741+ mutex_unlock(&st->cfgs_lock);
742+
743+ return 0;
744+}
745+
673746 static const struct iio_info ad7124_info = {
674747 .read_raw = ad7124_read_raw,
675748 .write_raw = ad7124_write_raw,
676749 .debugfs_reg_access = &ad7124_reg_access,
677750 .validate_trigger = ad_sd_validate_trigger,
751+ .update_scan_mode = ad7124_update_scan_mode,
678752 .attrs = &ad7124_attrs_group,
679753 };
680754
@@ -886,12 +960,14 @@ static int ad7124_probe(struct spi_device *spi) · 205 unmodified lines
886960
887961 st->chip_info = info;
888962
889− ad_sd_init(&st->sd, indio_dev, spi, &ad7124_sigma_delta_info);
890−
891963 indio_dev->name = st->chip_info->name;
892964 indio_dev->modes = INDIO_DIRECT_MODE;
893965 indio_dev->info = &ad7124_info;
894966
967+ ret = ad_sd_init(&st->sd, indio_dev, spi, &ad7124_sigma_delta_info);
968+ if (ret < 0)
969+ return ret;
970+
895971 ret = ad7124_of_parse_channel_config(indio_dev, spi->dev.of_node);
896972 if (ret < 0)
897973 return ret;
drivers/iio/adc/ad7192.c+65−3
@@ -58,7 +58,8 @@ · 57 unmodified lines
5858 /* Mode Register Bit Designations (AD7192_REG_MODE) */
5959 #define AD7192_MODE_SEL(x) (((x) & 0x7) << 21) /* Operation Mode Select */
6060 #define AD7192_MODE_SEL_MASK (0x7 << 21) /* Operation Mode Select Mask */
61−#define AD7192_MODE_DAT_STA BIT(20) /* Status Register transmission */
61+#define AD7192_MODE_STA(x) (((x) & 0x1) << 20) /* Status Register transmission */
62+#define AD7192_MODE_STA_MASK BIT(20) /* Status Register transmission Mask */
6263 #define AD7192_MODE_CLKSRC(x) (((x) & 0x3) << 18) /* Clock Source Select */
6364 #define AD7192_MODE_SINC3 BIT(15) /* SINC3 Filter Select */
6465 #define AD7192_MODE_ACX BIT(14) /* AC excitation enable(AD7195 only)*/
@@ -225,7 +226,7 @@ static ssize_t ad7192_write_syscalib(struct iio_dev *indio_dev, · 160 unmodified lines
225226 bool sys_calib;
226227 int ret, temp;
227228
228− ret = strtobool(buf, &sys_calib);
229+ ret = kstrtobool(buf, &sys_calib);
229230 if (ret)
230231 return ret;
231232
@@ -288,12 +289,51 @@ static int ad7192_set_mode(struct ad_sigma_delta *sd, · 56 unmodified lines
288289 return ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode);
289290 }
290291
292+static int ad7192_append_status(struct ad_sigma_delta *sd, bool append)
293+{
294+ struct ad7192_state *st = ad_sigma_delta_to_ad7192(sd);
295+ unsigned int mode = st->mode;
296+ int ret;
297+
298+ mode &= ~AD7192_MODE_STA_MASK;
299+ mode |= AD7192_MODE_STA(append);
300+
301+ ret = ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, mode);
302+ if (ret < 0)
303+ return ret;
304+
305+ st->mode = mode;
306+
307+ return 0;
308+}
309+
310+static int ad7192_disable_all(struct ad_sigma_delta *sd)
311+{
312+ struct ad7192_state *st = ad_sigma_delta_to_ad7192(sd);
313+ u32 conf = st->conf;
314+ int ret;
315+
316+ conf &= ~AD7192_CONF_CHAN_MASK;
317+
318+ ret = ad_sd_write_reg(&st->sd, AD7192_REG_CONF, 3, conf);
319+ if (ret < 0)
320+ return ret;
321+
322+ st->conf = conf;
323+
324+ return 0;
325+}
326+
291327 static const struct ad_sigma_delta_info ad7192_sigma_delta_info = {
292328 .set_channel = ad7192_set_channel,
329+ .append_status = ad7192_append_status,
330+ .disable_all = ad7192_disable_all,
293331 .set_mode = ad7192_set_mode,
294332 .has_registers = true,
295333 .addr_shift = 3,
296334 .read_mask = BIT(6),
335+ .status_ch_mask = GENMASK(3, 0),
336+ .num_slots = 4,
297337 .irq_flags = IRQF_TRIGGER_FALLING,
298338 };
299339
@@ -457,7 +497,7 @@ static ssize_t ad7192_set(struct device *dev, · 157 unmodified lines
457497 int ret;
458498 bool val;
459499
460− ret = strtobool(buf, &val);
500+ ret = kstrtobool(buf, &val);
461501 if (ret < 0)
462502 return ret;
463503
@@ -783,6 +823,26 @@ static int ad7192_read_avail(struct iio_dev *indio_dev, · 319 unmodified lines
783823 return -EINVAL;
784824 }
785825
826+static int ad7192_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask)
827+{
828+ struct ad7192_state *st = iio_priv(indio_dev);
829+ u32 conf = st->conf;
830+ int ret;
831+ int i;
832+
833+ conf &= ~AD7192_CONF_CHAN_MASK;
834+ for_each_set_bit(i, scan_mask, 8)
835+ conf |= AD7192_CONF_CHAN(i);
836+
837+ ret = ad_sd_write_reg(&st->sd, AD7192_REG_CONF, 3, conf);
838+ if (ret < 0)
839+ return ret;
840+
841+ st->conf = conf;
842+
843+ return 0;
844+}
845+
786846 static const struct iio_info ad7192_info = {
787847 .read_raw = ad7192_read_raw,
788848 .write_raw = ad7192_write_raw,
@@ -790,6 +850,7 @@ static const struct iio_info ad7192_info = { · 1 unmodified line
790850 .read_avail = ad7192_read_avail,
791851 .attrs = &ad7192_attribute_group,
792852 .validate_trigger = ad_sd_validate_trigger,
853+ .update_scan_mode = ad7192_update_scan_mode,
793854 };
794855
795856 static const struct iio_info ad7195_info = {
@@ -799,6 +860,7 @@ static const struct iio_info ad7195_info = { · 3 unmodified lines
799860 .read_avail = ad7192_read_avail,
800861 .attrs = &ad7195_attribute_group,
801862 .validate_trigger = ad_sd_validate_trigger,
863+ .update_scan_mode = ad7192_update_scan_mode,
802864 };
803865
804866 #define __AD719x_CHANNEL(_si, _channel1, _channel2, _address, _extend_name, \
drivers/iio/adc/ad7266.c+14−30
@@ -378,6 +378,11 @@ static const char * const ad7266_gpio_labels[] = { · 377 unmodified lines
378378 "ad0", "ad1", "ad2",
379379 };
380380
381+static void ad7266_reg_disable(void *reg)
382+{
383+ regulator_disable(reg);
384+}
385+
381386 static int ad7266_probe(struct spi_device *spi)
382387 {
383388 struct ad7266_platform_data *pdata = spi->dev.platform_data;
@@ -398,9 +403,13 @@ static int ad7266_probe(struct spi_device *spi) · 14 unmodified lines
398403 if (ret)
399404 return ret;
400405
406+ ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg);
407+ if (ret)
408+ return ret;
409+
401410 ret = regulator_get_voltage(st->reg);
402411 if (ret < 0)
403− goto error_disable_reg;
412+ return ret;
404413
405414 st->vref_mv = ret / 1000;
406415 } else {
@@ -423,7 +432,7 @@ static int ad7266_probe(struct spi_device *spi) · 16 unmodified lines
423432 GPIOD_OUT_LOW);
424433 if (IS_ERR(st->gpios[i])) {
425434 ret = PTR_ERR(st->gpios[i]);
426− goto error_disable_reg;
435+ return ret;
427436 }
428437 }
429438 }
@@ -433,7 +442,6 @@ static int ad7266_probe(struct spi_device *spi) · 3 unmodified lines
433442 st->mode = AD7266_MODE_DIFF;
434443 }
435444
436− spi_set_drvdata(spi, indio_dev);
437445 st->spi = spi;
438446
439447 indio_dev->name = spi_get_device_id(spi)->name;
@@ -459,35 +467,12 @@ static int ad7266_probe(struct spi_device *spi) · 19 unmodified lines
459467 spi_message_add_tail(&st->single_xfer[1], &st->single_msg);
460468 spi_message_add_tail(&st->single_xfer[2], &st->single_msg);
461469
462− ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
470+ ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, &iio_pollfunc_store_time,
463471 &ad7266_trigger_handler, &iio_triggered_buffer_setup_ops);
464472 if (ret)
465− goto error_disable_reg;
466−
467− ret = iio_device_register(indio_dev);
468− if (ret)
469− goto error_buffer_cleanup;
470−
471− return 0;
472−
473−error_buffer_cleanup:
474− iio_triggered_buffer_cleanup(indio_dev);
475−error_disable_reg:
476− if (!IS_ERR(st->reg))
477− regulator_disable(st->reg);
478−
479− return ret;
480−}
481−
482−static void ad7266_remove(struct spi_device *spi)
483−{
484− struct iio_dev *indio_dev = spi_get_drvdata(spi);
485− struct ad7266_state *st = iio_priv(indio_dev);
473+ return ret;
486474
487− iio_device_unregister(indio_dev);
488− iio_triggered_buffer_cleanup(indio_dev);
489− if (!IS_ERR(st->reg))
490− regulator_disable(st->reg);
475+ return devm_iio_device_register(&spi->dev, indio_dev);
491476 }
492477
493478 static const struct spi_device_id ad7266_id[] = {
@@ -502,7 +487,6 @@ static struct spi_driver ad7266_driver = { · 8 unmodified lines
502487 .name = "ad7266",
503488 },
504489 .probe = ad7266_probe,
505− .remove = ad7266_remove,
506490 .id_table = ad7266_id,
507491 };
508492 module_spi_driver(ad7266_driver);
drivers/iio/adc/ad7280a.c+1−1
@@ -488,7 +488,7 @@ static ssize_t ad7280_store_balance_sw(struct iio_dev *indio_dev, · 487 unmodified lines
488488 bool readin;
489489 int ret;
490490
491− ret = strtobool(buf, &readin);
491+ ret = kstrtobool(buf, &readin);
492492 if (ret)
493493 return ret;
494494
drivers/iio/adc/ad_sigma_delta.c+133−10
@@ -6,6 +6,7 @@ · 5 unmodified lines
66 * Author: Lars-Peter Clausen <lars@metafoo.de>
77 */
88
9+#include <linux/align.h>
910 #include <linux/interrupt.h>
1011 #include <linux/device.h>
1112 #include <linux/kernel.h>
@@ -342,15 +343,49 @@ EXPORT_SYMBOL_NS_GPL(ad_sigma_delta_single_conversion, IIO_AD_SIGMA_DELTA); · 330 unmodified lines
342343 static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
343344 {
344345 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
346+ unsigned int i, slot, samples_buf_size;
345347 unsigned int channel;
348+ uint8_t *samples_buf;
346349 int ret;
347350
348− channel = find_first_bit(indio_dev->active_scan_mask,
349− indio_dev->masklength);
350− ret = ad_sigma_delta_set_channel(sigma_delta,
351− indio_dev->channels[channel].address);
352− if (ret)
353− return ret;
351+ if (sigma_delta->num_slots == 1) {
352+ channel = find_first_bit(indio_dev->active_scan_mask,
353+ indio_dev->masklength);
354+ ret = ad_sigma_delta_set_channel(sigma_delta,
355+ indio_dev->channels[channel].address);
356+ if (ret)
357+ return ret;
358+ slot = 1;
359+ } else {
360+ /*
361+ * At this point update_scan_mode already enabled the required channels.
362+ * For sigma-delta sequencer drivers with multiple slots, an update_scan_mode
363+ * implementation is mandatory.
364+ */
365+ slot = 0;
366+ for_each_set_bit(i, indio_dev->active_scan_mask, indio_dev->masklength) {
367+ sigma_delta->slots[slot] = indio_dev->channels[i].address;
368+ slot++;
369+ }
370+ }
371+
372+ sigma_delta->active_slots = slot;
373+ sigma_delta->current_slot = 0;
374+
375+ if (sigma_delta->active_slots > 1) {
376+ ret = ad_sigma_delta_append_status(sigma_delta, true);
377+ if (ret)
378+ return ret;
379+ }
380+
381+ samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits, 8);
382+ samples_buf_size += sizeof(int64_t);
383+ samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
384+ samples_buf_size, GFP_KERNEL);
385+ if (!samples_buf)
386+ return -ENOMEM;
387+
388+ sigma_delta->samples_buf = samples_buf;
354389
355390 spi_bus_lock(sigma_delta->spi->master);
356391 sigma_delta->bus_locked = true;
@@ -386,6 +421,10 @@ static int ad_sd_buffer_postdisable(struct iio_dev *indio_dev) · 29 unmodified lines
386421 sigma_delta->keep_cs_asserted = false;
387422 ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
388423
424+ if (sigma_delta->status_appended)
425+ ad_sigma_delta_append_status(sigma_delta, false);
426+
427+ ad_sigma_delta_disable_all(sigma_delta);
389428 sigma_delta->bus_locked = false;
390429 return spi_bus_unlock(sigma_delta->spi->master);
391430 }
@@ -396,6 +435,10 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p) · 4 unmodified lines
396435 struct iio_dev *indio_dev = pf->indio_dev;
397436 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
398437 uint8_t *data = sigma_delta->rx_buf;
438+ unsigned int transfer_size;
439+ unsigned int sample_size;
440+ unsigned int sample_pos;
441+ unsigned int status_pos;
399442 unsigned int reg_size;
400443 unsigned int data_reg;
401444
@@ -408,21 +451,69 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p) · 6 unmodified lines
408451 else
409452 data_reg = AD_SD_REG_DATA;
410453
454+ /* Status word will be appended to the sample during transfer */
455+ if (sigma_delta->status_appended)
456+ transfer_size = reg_size + 1;
457+ else
458+ transfer_size = reg_size;
459+
411460 switch (reg_size) {
412461 case 4:
413462 case 2:
414463 case 1:
415− ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size, &data[0]);
464+ status_pos = reg_size;
465+ ad_sd_read_reg_raw(sigma_delta, data_reg, transfer_size, &data[0]);
416466 break;
417467 case 3:
468+ /*
469+ * Data array after transfer will look like (if status is appended):
470+ * data[] = { [0][sample][sample][sample][status] }
471+ * Keeping the first byte 0 shifts the status postion by 1 byte to the right.
472+ */
473+ status_pos = reg_size + 1;
474+
418475 /* We store 24 bit samples in a 32 bit word. Keep the upper
419476 * byte set to zero. */
420− ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size, &data[1]);
477+ ad_sd_read_reg_raw(sigma_delta, data_reg, transfer_size, &data[1]);
421478 break;
422479 }
423480
424− iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp);
481+ /*
482+ * For devices sampling only one channel at
483+ * once, there is no need for sample number tracking.
484+ */
485+ if (sigma_delta->active_slots == 1) {
486+ iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp);
487+ goto irq_handled;
488+ }
489+
490+ if (sigma_delta->status_appended) {
491+ u8 converted_channel;
492+
493+ converted_channel = data[status_pos] & sigma_delta->info->status_ch_mask;
494+ if (converted_channel != sigma_delta->slots[sigma_delta->current_slot]) {
495+ /*
496+ * Desync occurred during continuous sampling of multiple channels.
497+ * Drop this incomplete sample and start from first channel again.
498+ */
499+
500+ sigma_delta->current_slot = 0;
501+ goto irq_handled;
502+ }
503+ }
504+
505+ sample_size = indio_dev->channels[0].scan_type.storagebits / 8;
506+ sample_pos = sample_size * sigma_delta->current_slot;
507+ memcpy(&sigma_delta->samples_buf[sample_pos], data, sample_size);
508+ sigma_delta->current_slot++;
425509
510+ if (sigma_delta->current_slot == sigma_delta->active_slots) {
511+ sigma_delta->current_slot = 0;
512+ iio_push_to_buffers_with_timestamp(indio_dev, sigma_delta->samples_buf,
513+ pf->timestamp);
514+ }
515+
516+irq_handled:
426517 iio_trigger_notify_done(indio_dev->trig);
427518 sigma_delta->irq_dis = false;
428519 enable_irq(sigma_delta->spi->irq);
@@ -430,10 +521,17 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p) · 1 unmodified line
430521 return IRQ_HANDLED;
431522 }
432523
524+static bool ad_sd_validate_scan_mask(struct iio_dev *indio_dev, const unsigned long *mask)
525+{
526+ struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
527+
528+ return bitmap_weight(mask, indio_dev->masklength) <= sigma_delta->num_slots;
529+}
530+
433531 static const struct iio_buffer_setup_ops ad_sd_buffer_setup_ops = {
434532 .postenable = &ad_sd_buffer_postenable,
435533 .postdisable = &ad_sd_buffer_postdisable,
436− .validate_scan_mask = &iio_validate_scan_mask_onehot,
534+ .validate_scan_mask = &ad_sd_validate_scan_mask,
437535 };
438536
439537 static irqreturn_t ad_sd_data_rdy_trig_poll(int irq, void *private)
@@ -513,8 +611,14 @@ static int devm_ad_sd_probe_trigger(struct device *dev, struct iio_dev *indio_de · 73 unmodified lines
513611 */
514612 int devm_ad_sd_setup_buffer_and_trigger(struct device *dev, struct iio_dev *indio_dev)
515613 {
614+ struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
516615 int ret;
517616
617+ sigma_delta->slots = devm_kcalloc(dev, sigma_delta->num_slots,
618+ sizeof(*sigma_delta->slots), GFP_KERNEL);
619+ if (!sigma_delta->slots)
620+ return -ENOMEM;
621+
518622 ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
519623 &iio_pollfunc_store_time,
520624 &ad_sd_trigger_handler,
@@ -541,6 +645,25 @@ int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev, · 20 unmodified lines
541645 {
542646 sigma_delta->spi = spi;
543647 sigma_delta->info = info;
648+
649+ /* If the field is unset in ad_sigma_delta_info, asume there can only be 1 slot. */
650+ if (!info->num_slots)
651+ sigma_delta->num_slots = 1;
652+ else
653+ sigma_delta->num_slots = info->num_slots;
654+
655+ if (sigma_delta->num_slots > 1) {
656+ if (!indio_dev->info->update_scan_mode) {
657+ dev_err(&spi->dev, "iio_dev lacks update_scan_mode().\n");
658+ return -EINVAL;
659+ }
660+
661+ if (!info->disable_all) {
662+ dev_err(&spi->dev, "ad_sigma_delta_info lacks disable_all().\n");
663+ return -EINVAL;
664+ }
665+ }
666+
544667 iio_device_set_drvdata(indio_dev, sigma_delta);
545668
546669 return 0;
drivers/iio/adc/at91-sama5d2_adc.c+2−2
@@ -1117,7 +1117,7 @@ static int at91_adc_buffer_prepare(struct iio_dev *indio_dev) · 1116 unmodified lines
11171117 return at91_adc_configure_touch(st, true);
11181118
11191119 /* if we are not in triggered mode, we cannot enable the buffer. */
1120− if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES))
1120+ if (!(iio_device_get_current_mode(indio_dev) & INDIO_ALL_TRIGGERED_MODES))
11211121 return -EINVAL;
11221122
11231123 /* we continue with the triggered buffer */
@@ -1159,7 +1159,7 @@ static int at91_adc_buffer_postdisable(struct iio_dev *indio_dev) · 35 unmodified lines
11591159 return at91_adc_configure_touch(st, false);
11601160
11611161 /* if we are not in triggered mode, nothing to do here */
1162− if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES))
1162+ if (!(iio_device_get_current_mode(indio_dev) & INDIO_ALL_TRIGGERED_MODES))
11631163 return -EINVAL;
11641164
11651165 /*
drivers/iio/adc/ina2xx-adc.c+1−2
@@ -550,7 +550,7 @@ static ssize_t ina2xx_allow_async_readout_store(struct device *dev, · 549 unmodified lines
550550 bool val;
551551 int ret;
552552
553− ret = strtobool(buf, &val);
553+ ret = kstrtobool(buf, &val);
554554 if (ret)
555555 return ret;
556556
@@ -1027,7 +1027,6 @@ static int ina2xx_probe(struct i2c_client *client, · 470 unmodified lines
10271027 indio_dev->name = id->name;
10281028
10291029 ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
1030− INDIO_BUFFER_SOFTWARE,
10311030 &ina2xx_setup_ops);
10321031 if (ret)
10331032 return ret;
drivers/iio/adc/palmas_gpadc.c+2−1
@@ -376,7 +376,8 @@ static int palmas_gpadc_get_calibrated_code(struct palmas_gpadc *adc, · 375 unmodified lines
376376 adc->adc_info[adc_chan].gain_error;
377377
378378 if (val < 0) {
379− dev_err(adc->dev, "Mismatch with calibration\n");
379+ if (val < -10)
380+ dev_err(adc->dev, "Mismatch with calibration var = %d\n", val);
380381 return 0;
381382 }
382383
drivers/iio/adc/sc27xx_adc.c+435−35
@@ -9,12 +9,16 @@ · 8 unmodified lines
99 #include <linux/of_device.h>
1010 #include <linux/platform_device.h>
1111 #include <linux/regmap.h>
12+#include <linux/regulator/consumer.h>
1213 #include <linux/slab.h>
1314
1415 /* PMIC global registers definition */
15−#define SC27XX_MODULE_EN 0xc08
16+#define SC2730_MODULE_EN 0x1808
17+#define SC2731_MODULE_EN 0xc08
1618 #define SC27XX_MODULE_ADC_EN BIT(5)
17−#define SC27XX_ARM_CLK_EN 0xc10
19+#define SC2721_ARM_CLK_EN 0xc0c
20+#define SC2730_ARM_CLK_EN 0x180c
21+#define SC2731_ARM_CLK_EN 0xc10
1822 #define SC27XX_CLK_ADC_EN BIT(5)
1923 #define SC27XX_CLK_ADC_CLK_EN BIT(6)
2024
@@ -36,8 +40,10 @@ · 15 unmodified lines
3640
3741 /* Bits and mask definition for SC27XX_ADC_CH_CFG register */
3842 #define SC27XX_ADC_CHN_ID_MASK GENMASK(4, 0)
39−#define SC27XX_ADC_SCALE_MASK GENMASK(10, 8)
40−#define SC27XX_ADC_SCALE_SHIFT 8
43+#define SC27XX_ADC_SCALE_MASK GENMASK(10, 9)
44+#define SC2721_ADC_SCALE_MASK BIT(5)
45+#define SC27XX_ADC_SCALE_SHIFT 9
46+#define SC2721_ADC_SCALE_SHIFT 5
4147
4248 /* Bits definitions for SC27XX_ADC_INT_EN registers */
4349 #define SC27XX_ADC_IRQ_EN BIT(0)
@@ -67,8 +73,15 @@ · 23 unmodified lines
6773 #define SC27XX_RATIO_NUMERATOR_OFFSET 16
6874 #define SC27XX_RATIO_DENOMINATOR_MASK GENMASK(15, 0)
6975
76+/* ADC specific channel reference voltage 3.5V */
77+#define SC27XX_ADC_REFVOL_VDD35 3500000
78+
79+/* ADC default channel reference voltage is 2.8V */
80+#define SC27XX_ADC_REFVOL_VDD28 2800000
81+
7082 struct sc27xx_adc_data {
7183 struct device *dev;
84+ struct regulator *volref;
7285 struct regmap *regmap;
7386 /*
7487 * One hardware spinlock to synchronize between the multiple
@@ -78,6 +91,24 @@ struct sc27xx_adc_data { · 3 unmodified lines
7891 int channel_scale[SC27XX_ADC_CHANNEL_MAX];
7992 u32 base;
8093 int irq;
94+ const struct sc27xx_adc_variant_data *var_data;
95+};
96+
97+/*
98+ * Since different PMICs of SC27xx series can have different
99+ * address and ratio, we should save ratio config and base
100+ * in the device data structure.
101+ */
102+struct sc27xx_adc_variant_data {
103+ u32 module_en;
104+ u32 clk_en;
105+ u32 scale_shift;
106+ u32 scale_mask;
107+ const struct sc27xx_adc_linear_graph *bscale_cal;
108+ const struct sc27xx_adc_linear_graph *sscale_cal;
109+ void (*init_scale)(struct sc27xx_adc_data *data);
110+ int (*get_ratio)(int channel, int scale);
111+ bool set_volref;
81112 };
82113
83114 struct sc27xx_adc_linear_graph {
@@ -103,6 +134,16 @@ static struct sc27xx_adc_linear_graph small_scale_graph = { · 19 unmodified lines
103134 100, 341,
104135 };
105136
137+static const struct sc27xx_adc_linear_graph sc2731_big_scale_graph_calib = {
138+ 4200, 850,
139+ 3600, 728,
140+};
141+
142+static const struct sc27xx_adc_linear_graph sc2731_small_scale_graph_calib = {
143+ 1000, 838,
144+ 100, 84,
145+};
146+
106147 static const struct sc27xx_adc_linear_graph big_scale_graph_calib = {
107148 4200, 856,
108149 3600, 733,
@@ -118,49 +159,225 @@ static int sc27xx_adc_get_calib_data(u32 calib_data, int calib_adc) · 9 unmodified lines
118159 return ((calib_data & 0xff) + calib_adc - 128) * 4;
119160 }
120161
162+/* get the adc nvmem cell calibration data */
163+static int adc_nvmem_cell_calib_data(struct sc27xx_adc_data *data, const char *cell_name)
164+{
165+ struct nvmem_cell *cell;
166+ void *buf;
167+ u32 origin_calib_data = 0;
168+ size_t len;
169+
170+ if (!data)
171+ return -EINVAL;
172+
173+ cell = nvmem_cell_get(data->dev, cell_name);
174+ if (IS_ERR(cell))
175+ return PTR_ERR(cell);
176+
177+ buf = nvmem_cell_read(cell, &len);
178+ if (IS_ERR(buf)) {
179+ nvmem_cell_put(cell);
180+ return PTR_ERR(buf);
181+ }
182+
183+ memcpy(&origin_calib_data, buf, min(len, sizeof(u32)));
184+
185+ kfree(buf);
186+ nvmem_cell_put(cell);
187+ return origin_calib_data;
188+}
189+
121190 static int sc27xx_adc_scale_calibration(struct sc27xx_adc_data *data,
122191 bool big_scale)
123192 {
124193 const struct sc27xx_adc_linear_graph *calib_graph;
125194 struct sc27xx_adc_linear_graph *graph;
126− struct nvmem_cell *cell;
127195 const char *cell_name;
128196 u32 calib_data = 0;
129− void *buf;
130− size_t len;
131197
132198 if (big_scale) {
133− calib_graph = &big_scale_graph_calib;
199+ calib_graph = data->var_data->bscale_cal;
134200 graph = &big_scale_graph;
135201 cell_name = "big_scale_calib";
136202 } else {
137− calib_graph = &small_scale_graph_calib;
203+ calib_graph = data->var_data->sscale_cal;
138204 graph = &small_scale_graph;
139205 cell_name = "small_scale_calib";
140206 }
141207
142− cell = nvmem_cell_get(data->dev, cell_name);
143− if (IS_ERR(cell))
144− return PTR_ERR(cell);
145−
146− buf = nvmem_cell_read(cell, &len);
147− nvmem_cell_put(cell);
148−
149− if (IS_ERR(buf))
150− return PTR_ERR(buf);
151−
152− memcpy(&calib_data, buf, min(len, sizeof(u32)));
208+ calib_data = adc_nvmem_cell_calib_data(data, cell_name);
153209
154210 /* Only need to calibrate the adc values in the linear graph. */
155211 graph->adc0 = sc27xx_adc_get_calib_data(calib_data, calib_graph->adc0);
156212 graph->adc1 = sc27xx_adc_get_calib_data(calib_data >> 8,
157213 calib_graph->adc1);
158214
159− kfree(buf);
160215 return 0;
161216 }
162217
163−static int sc27xx_adc_get_ratio(int channel, int scale)
218+static int sc2720_adc_get_ratio(int channel, int scale)
219+{
220+ switch (channel) {
221+ case 14:
222+ switch (scale) {
223+ case 0:
224+ return SC27XX_VOLT_RATIO(68, 900);
225+ case 1:
226+ return SC27XX_VOLT_RATIO(68, 1760);
227+ case 2:
228+ return SC27XX_VOLT_RATIO(68, 2327);
229+ case 3:
230+ return SC27XX_VOLT_RATIO(68, 3654);
231+ default:
232+ return SC27XX_VOLT_RATIO(1, 1);
233+ }
234+ case 16:
235+ switch (scale) {
236+ case 0:
237+ return SC27XX_VOLT_RATIO(48, 100);
238+ case 1:
239+ return SC27XX_VOLT_RATIO(480, 1955);
240+ case 2:
241+ return SC27XX_VOLT_RATIO(480, 2586);
242+ case 3:
243+ return SC27XX_VOLT_RATIO(48, 406);
244+ default:
245+ return SC27XX_VOLT_RATIO(1, 1);
246+ }
247+ case 21:
248+ case 22:
249+ case 23:
250+ switch (scale) {
251+ case 0:
252+ return SC27XX_VOLT_RATIO(3, 8);
253+ case 1:
254+ return SC27XX_VOLT_RATIO(375, 1955);
255+ case 2:
256+ return SC27XX_VOLT_RATIO(375, 2586);
257+ case 3:
258+ return SC27XX_VOLT_RATIO(300, 3248);
259+ default:
260+ return SC27XX_VOLT_RATIO(1, 1);
261+ }
262+ default:
263+ switch (scale) {
264+ case 0:
265+ return SC27XX_VOLT_RATIO(1, 1);
266+ case 1:
267+ return SC27XX_VOLT_RATIO(1000, 1955);
268+ case 2:
269+ return SC27XX_VOLT_RATIO(1000, 2586);
270+ case 3:
271+ return SC27XX_VOLT_RATIO(100, 406);
272+ default:
273+ return SC27XX_VOLT_RATIO(1, 1);
274+ }
275+ }
276+ return SC27XX_VOLT_RATIO(1, 1);
277+}
278+
279+static int sc2721_adc_get_ratio(int channel, int scale)
280+{
281+ switch (channel) {
282+ case 1:
283+ case 2:
284+ case 3:
285+ case 4:
286+ return scale ? SC27XX_VOLT_RATIO(400, 1025) :
287+ SC27XX_VOLT_RATIO(1, 1);
288+ case 5:
289+ return SC27XX_VOLT_RATIO(7, 29);
290+ case 7:
291+ case 9:
292+ return scale ? SC27XX_VOLT_RATIO(100, 125) :
293+ SC27XX_VOLT_RATIO(1, 1);
294+ case 14:
295+ return SC27XX_VOLT_RATIO(68, 900);
296+ case 16:
297+ return SC27XX_VOLT_RATIO(48, 100);
298+ case 19:
299+ return SC27XX_VOLT_RATIO(1, 3);
300+ default:
301+ return SC27XX_VOLT_RATIO(1, 1);
302+ }
303+ return SC27XX_VOLT_RATIO(1, 1);
304+}
305+
306+static int sc2730_adc_get_ratio(int channel, int scale)
307+{
308+ switch (channel) {
309+ case 14:
310+ switch (scale) {
311+ case 0:
312+ return SC27XX_VOLT_RATIO(68, 900);
313+ case 1:
314+ return SC27XX_VOLT_RATIO(68, 1760);
315+ case 2:
316+ return SC27XX_VOLT_RATIO(68, 2327);
317+ case 3:
318+ return SC27XX_VOLT_RATIO(68, 3654);
319+ default:
320+ return SC27XX_VOLT_RATIO(1, 1);
321+ }
322+ case 15:
323+ switch (scale) {
324+ case 0:
325+ return SC27XX_VOLT_RATIO(1, 3);
326+ case 1:
327+ return SC27XX_VOLT_RATIO(1000, 5865);
328+ case 2:
329+ return SC27XX_VOLT_RATIO(500, 3879);
330+ case 3:
331+ return SC27XX_VOLT_RATIO(500, 6090);
332+ default:
333+ return SC27XX_VOLT_RATIO(1, 1);
334+ }
335+ case 16:
336+ switch (scale) {
337+ case 0:
338+ return SC27XX_VOLT_RATIO(48, 100);
339+ case 1:
340+ return SC27XX_VOLT_RATIO(480, 1955);
341+ case 2:
342+ return SC27XX_VOLT_RATIO(480, 2586);
343+ case 3:
344+ return SC27XX_VOLT_RATIO(48, 406);
345+ default:
346+ return SC27XX_VOLT_RATIO(1, 1);
347+ }
348+ case 21:
349+ case 22:
350+ case 23:
351+ switch (scale) {
352+ case 0:
353+ return SC27XX_VOLT_RATIO(3, 8);
354+ case 1:
355+ return SC27XX_VOLT_RATIO(375, 1955);
356+ case 2:
357+ return SC27XX_VOLT_RATIO(375, 2586);
358+ case 3:
359+ return SC27XX_VOLT_RATIO(300, 3248);
360+ default:
361+ return SC27XX_VOLT_RATIO(1, 1);
362+ }
363+ default:
364+ switch (scale) {
365+ case 0:
366+ return SC27XX_VOLT_RATIO(1, 1);
367+ case 1:
368+ return SC27XX_VOLT_RATIO(1000, 1955);
369+ case 2:
370+ return SC27XX_VOLT_RATIO(1000, 2586);
371+ case 3:
372+ return SC27XX_VOLT_RATIO(1000, 4060);
373+ default:
374+ return SC27XX_VOLT_RATIO(1, 1);
375+ }
376+ }
377+ return SC27XX_VOLT_RATIO(1, 1);
378+}
379+
380+static int sc2731_adc_get_ratio(int channel, int scale)
164381 {
165382 switch (channel) {
166383 case 1:
@@ -185,10 +402,87 @@ static int sc27xx_adc_get_ratio(int channel, int scale) · 18 unmodified lines
185402 return SC27XX_VOLT_RATIO(1, 1);
186403 }
187404
405+/*
406+ * According to the datasheet set specific value on some channel.
407+ */
408+static void sc2720_adc_scale_init(struct sc27xx_adc_data *data)
409+{
410+ int i;
411+
412+ for (i = 0; i < SC27XX_ADC_CHANNEL_MAX; i++) {
413+ switch (i) {
414+ case 5:
415+ data->channel_scale[i] = 3;
416+ break;
417+ case 7:
418+ case 9:
419+ data->channel_scale[i] = 2;
420+ break;
421+ case 13:
422+ data->channel_scale[i] = 1;
423+ break;
424+ case 19:
425+ case 30:
426+ case 31:
427+ data->channel_scale[i] = 3;
428+ break;
429+ default:
430+ data->channel_scale[i] = 0;
431+ break;
432+ }
433+ }
434+}
435+
436+static void sc2730_adc_scale_init(struct sc27xx_adc_data *data)
437+{
438+ int i;
439+
440+ for (i = 0; i < SC27XX_ADC_CHANNEL_MAX; i++) {
441+ switch (i) {
442+ case 5:
443+ case 10:
444+ case 19:
445+ case 30:
446+ case 31:
447+ data->channel_scale[i] = 3;
448+ break;
449+ case 7:
450+ case 9:
451+ data->channel_scale[i] = 2;
452+ break;
453+ case 13:
454+ data->channel_scale[i] = 1;
455+ break;
456+ default:
457+ data->channel_scale[i] = 0;
458+ break;
459+ }
460+ }
461+}
462+
463+static void sc2731_adc_scale_init(struct sc27xx_adc_data *data)
464+{
465+ int i;
466+ /*
467+ * In the current software design, SC2731 support 2 scales,
468+ * channels 5 uses big scale, others use smale.
469+ */
470+ for (i = 0; i < SC27XX_ADC_CHANNEL_MAX; i++) {
471+ switch (i) {
472+ case 5:
473+ data->channel_scale[i] = 1;
474+ break;
475+ default:
476+ data->channel_scale[i] = 0;
477+ break;
478+ }
479+ }
480+}
481+
188482 static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel,
189483 int scale, int *val)
190484 {
191− int ret;
485+ int ret, ret_volref;
192486 u32 tmp, value, status;
193487
194488 ret = hwspin_lock_timeout_raw(data->hwlock, SC27XX_ADC_HWLOCK_TIMEOUT);
@@ -197,10 +491,25 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel, · 2 unmodified lines
197491 return ret;
198492 }
199493
494+ /*
495+ * According to the sc2721 chip data sheet, the reference voltage of
496+ * specific channel 30 and channel 31 in ADC module needs to be set from
497+ * the default 2.8v to 3.5v.
498+ */
499+ if ((data->var_data->set_volref) && (channel == 30 || channel == 31)) {
500+ ret = regulator_set_voltage(data->volref,
501+ SC27XX_ADC_REFVOL_VDD35,
502+ SC27XX_ADC_REFVOL_VDD35);
503+ if (ret) {
504+ dev_err(data->dev, "failed to set the volref 3.5v\n");
505+ goto unlock_adc;
506+ }
507+ }
508+
200509 ret = regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CTL,
201510 SC27XX_ADC_EN, SC27XX_ADC_EN);
202511 if (ret)
203− goto unlock_adc;
512+ goto regulator_restore;
204513
205514 ret = regmap_update_bits(data->regmap, data->base + SC27XX_ADC_INT_CLR,
206515 SC27XX_ADC_IRQ_CLR, SC27XX_ADC_IRQ_CLR);
@@ -208,10 +517,11 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel, · 1 unmodified line
208517 goto disable_adc;
209518
210519 /* Configure the channel id and scale */
211− tmp = (scale << SC27XX_ADC_SCALE_SHIFT) & SC27XX_ADC_SCALE_MASK;
520+ tmp = (scale << data->var_data->scale_shift) & data->var_data->scale_mask;
212521 tmp |= channel & SC27XX_ADC_CHN_ID_MASK;
213522 ret = regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CH_CFG,
214− SC27XX_ADC_CHN_ID_MASK | SC27XX_ADC_SCALE_MASK,
523+ SC27XX_ADC_CHN_ID_MASK |
524+ data->var_data->scale_mask,
215525 tmp);
216526 if (ret)
217527 goto disable_adc;
@@ -249,6 +559,17 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel, · 31 unmodified lines
249559 disable_adc:
250560 regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CTL,
251561 SC27XX_ADC_EN, 0);
562+regulator_restore:
563+ if ((data->var_data->set_volref) && (channel == 30 || channel == 31)) {
564+ ret_volref = regulator_set_voltage(data->volref,
565+ SC27XX_ADC_REFVOL_VDD28,
566+ SC27XX_ADC_REFVOL_VDD28);
567+ if (ret_volref) {
568+ dev_err(data->dev, "failed to set the volref 2.8v,ret_volref = 0x%x\n",
569+ ret_volref);
570+ ret = ret || ret_volref;
571+ }
572+ }
252573 unlock_adc:
253574 hwspin_unlock_raw(data->hwlock);
254575
@@ -262,13 +583,14 @@ static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data, · 7 unmodified lines
262583 int channel, int scale,
263584 u32 *div_numerator, u32 *div_denominator)
264585 {
265− u32 ratio = sc27xx_adc_get_ratio(channel, scale);
586+ u32 ratio;
266587
588+ ratio = data->var_data->get_ratio(channel, scale);
267589 *div_numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET;
268590 *div_denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK;
269591 }
270592
271−static int sc27xx_adc_to_volt(struct sc27xx_adc_linear_graph *graph,
593+static int adc_to_volt(struct sc27xx_adc_linear_graph *graph,
272594 int raw_adc)
273595 {
274596 int tmp;
@@ -277,6 +599,16 @@ static int sc27xx_adc_to_volt(struct sc27xx_adc_linear_graph *graph, · 2 unmodified lines
277599 tmp /= (graph->adc0 - graph->adc1);
278600 tmp += graph->volt1;
279601
602+ return tmp;
603+}
604+
605+static int sc27xx_adc_to_volt(struct sc27xx_adc_linear_graph *graph,
606+ int raw_adc)
607+{
608+ int tmp;
609+
610+ tmp = adc_to_volt(graph, raw_adc);
611+
280612 return tmp < 0 ? 0 : tmp;
281613 }
282614
@@ -432,13 +764,13 @@ static int sc27xx_adc_enable(struct sc27xx_adc_data *data) · 149 unmodified lines
432764 {
433765 int ret;
434766
435− ret = regmap_update_bits(data->regmap, SC27XX_MODULE_EN,
767+ ret = regmap_update_bits(data->regmap, data->var_data->module_en,
436768 SC27XX_MODULE_ADC_EN, SC27XX_MODULE_ADC_EN);
437769 if (ret)
438770 return ret;
439771
440772 /* Enable ADC work clock and controller clock */
441− ret = regmap_update_bits(data->regmap, SC27XX_ARM_CLK_EN,
773+ ret = regmap_update_bits(data->regmap, data->var_data->clk_en,
442774 SC27XX_CLK_ADC_EN | SC27XX_CLK_ADC_CLK_EN,
443775 SC27XX_CLK_ADC_EN | SC27XX_CLK_ADC_CLK_EN);
444776 if (ret)
@@ -456,10 +788,10 @@ static int sc27xx_adc_enable(struct sc27xx_adc_data *data) · 11 unmodified lines
456788 return 0;
457789
458790 disable_clk:
459− regmap_update_bits(data->regmap, SC27XX_ARM_CLK_EN,
791+ regmap_update_bits(data->regmap, data->var_data->clk_en,
460792 SC27XX_CLK_ADC_EN | SC27XX_CLK_ADC_CLK_EN, 0);
461793 disable_adc:
462− regmap_update_bits(data->regmap, SC27XX_MODULE_EN,
794+ regmap_update_bits(data->regmap, data->var_data->module_en,
463795 SC27XX_MODULE_ADC_EN, 0);
464796
465797 return ret;
@@ -470,21 +802,76 @@ static void sc27xx_adc_disable(void *_data) · 4 unmodified lines
470802 struct sc27xx_adc_data *data = _data;
471803
472804 /* Disable ADC work clock and controller clock */
473− regmap_update_bits(data->regmap, SC27XX_ARM_CLK_EN,
805+ regmap_update_bits(data->regmap, data->var_data->clk_en,
474806 SC27XX_CLK_ADC_EN | SC27XX_CLK_ADC_CLK_EN, 0);
475807
476− regmap_update_bits(data->regmap, SC27XX_MODULE_EN,
808+ regmap_update_bits(data->regmap, data->var_data->module_en,
477809 SC27XX_MODULE_ADC_EN, 0);
478810 }
479811
812+static const struct sc27xx_adc_variant_data sc2731_data = {
813+ .module_en = SC2731_MODULE_EN,
814+ .clk_en = SC2731_ARM_CLK_EN,
815+ .scale_shift = SC27XX_ADC_SCALE_SHIFT,
816+ .scale_mask = SC27XX_ADC_SCALE_MASK,
817+ .bscale_cal = &sc2731_big_scale_graph_calib,
818+ .sscale_cal = &sc2731_small_scale_graph_calib,
819+ .init_scale = sc2731_adc_scale_init,
820+ .get_ratio = sc2731_adc_get_ratio,
821+ .set_volref = false,
822+};
823+
824+static const struct sc27xx_adc_variant_data sc2730_data = {
825+ .module_en = SC2730_MODULE_EN,
826+ .clk_en = SC2730_ARM_CLK_EN,
827+ .scale_shift = SC27XX_ADC_SCALE_SHIFT,
828+ .scale_mask = SC27XX_ADC_SCALE_MASK,
829+ .bscale_cal = &big_scale_graph_calib,
830+ .sscale_cal = &small_scale_graph_calib,
831+ .init_scale = sc2730_adc_scale_init,
832+ .get_ratio = sc2730_adc_get_ratio,
833+ .set_volref = false,
834+};
835+
836+static const struct sc27xx_adc_variant_data sc2721_data = {
837+ .module_en = SC2731_MODULE_EN,
838+ .clk_en = SC2721_ARM_CLK_EN,
839+ .scale_shift = SC2721_ADC_SCALE_SHIFT,
840+ .scale_mask = SC2721_ADC_SCALE_MASK,
841+ .bscale_cal = &sc2731_big_scale_graph_calib,
842+ .sscale_cal = &sc2731_small_scale_graph_calib,
843+ .init_scale = sc2731_adc_scale_init,
844+ .get_ratio = sc2721_adc_get_ratio,
845+ .set_volref = true,
846+};
847+
848+static const struct sc27xx_adc_variant_data sc2720_data = {
849+ .module_en = SC2731_MODULE_EN,
850+ .clk_en = SC2721_ARM_CLK_EN,
851+ .scale_shift = SC27XX_ADC_SCALE_SHIFT,
852+ .scale_mask = SC27XX_ADC_SCALE_MASK,
853+ .bscale_cal = &big_scale_graph_calib,
854+ .sscale_cal = &small_scale_graph_calib,
855+ .init_scale = sc2720_adc_scale_init,
856+ .get_ratio = sc2720_adc_get_ratio,
857+ .set_volref = false,
858+};
859+
480860 static int sc27xx_adc_probe(struct platform_device *pdev)
481861 {
482862 struct device *dev = &pdev->dev;
483863 struct device_node *np = dev->of_node;
484864 struct sc27xx_adc_data *sc27xx_data;
865+ const struct sc27xx_adc_variant_data *pdata;
485866 struct iio_dev *indio_dev;
486867 int ret;
487868
869+ pdata = of_device_get_match_data(dev);
870+ if (!pdata) {
871+ dev_err(dev, "No matching driver data found\n");
872+ return -EINVAL;
873+ }
874+
488875 indio_dev = devm_iio_device_alloc(dev, sizeof(*sc27xx_data));
489876 if (!indio_dev)
490877 return -ENOMEM;
@@ -520,6 +907,16 @@ static int sc27xx_adc_probe(struct platform_device *pdev) · 29 unmodified lines
520907 }
521908
522909 sc27xx_data->dev = dev;
910+ if (pdata->set_volref) {
911+ sc27xx_data->volref = devm_regulator_get(dev, "vref");
912+ if (IS_ERR(sc27xx_data->volref)) {
913+ ret = PTR_ERR(sc27xx_data->volref);
914+ return dev_err_probe(dev, ret, "failed to get ADC volref\n");
915+ }
916+ }
917+
918+ sc27xx_data->var_data = pdata;
919+ sc27xx_data->var_data->init_scale(sc27xx_data);
523920
524921 ret = sc27xx_adc_enable(sc27xx_data);
525922 if (ret) {
@@ -546,7 +943,10 @@ static int sc27xx_adc_probe(struct platform_device *pdev) · 20 unmodified lines
546943 }
547944
548945 static const struct of_device_id sc27xx_adc_of_match[] = {
549− { .compatible = "sprd,sc2731-adc", },
946+ { .compatible = "sprd,sc2731-adc", .data = &sc2731_data},
947+ { .compatible = "sprd,sc2730-adc", .data = &sc2730_data},
948+ { .compatible = "sprd,sc2721-adc", .data = &sc2721_data},
949+ { .compatible = "sprd,sc2720-adc", .data = &sc2720_data},
550950 { }
551951 };
552952 MODULE_DEVICE_TABLE(of, sc27xx_adc_of_match);
drivers/iio/adc/stm32-dfsdm-adc.c+2−3
@@ -466,8 +466,7 @@ static int stm32_dfsdm_channels_configure(struct iio_dev *indio_dev, · 465 unmodified lines
466466 * In continuous mode, use fast mode configuration,
467467 * if it provides a better resolution.
468468 */
469− if (adc->nconv == 1 && !trig &&
470− (indio_dev->currentmode & INDIO_BUFFER_SOFTWARE)) {
469+ if (adc->nconv == 1 && !trig && iio_buffer_enabled(indio_dev)) {
471470 if (fl->flo[1].res >= fl->flo[0].res) {
472471 fl->fast = 1;
473472 flo = &fl->flo[1];
@@ -562,7 +561,7 @@ static int stm32_dfsdm_filter_configure(struct iio_dev *indio_dev, · 88 unmodified lines
562561 cr1 = DFSDM_CR1_RCH(chan->channel);
563562
564563 /* Continuous conversions triggered by SPI clk in buffer mode */
565− if (indio_dev->currentmode & INDIO_BUFFER_SOFTWARE)
564+ if (iio_buffer_enabled(indio_dev))
566565 cr1 |= DFSDM_CR1_RCONT(1);
567566
568567 cr1 |= DFSDM_CR1_RSYNC(fl->sync_mode);
drivers/iio/adc/stmpe-adc.c+11−10
@@ -61,7 +61,7 @@ struct stmpe_adc { · 60 unmodified lines
6161 static int stmpe_read_voltage(struct stmpe_adc *info,
6262 struct iio_chan_spec const *chan, int *val)
6363 {
64− long ret;
64+ unsigned long ret;
6565
6666 mutex_lock(&info->lock);
6767
@@ -79,7 +79,7 @@ static int stmpe_read_voltage(struct stmpe_adc *info, · 11 unmodified lines
7979
8080 ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
8181
82− if (ret <= 0) {
82+ if (ret == 0) {
8383 stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
8484 STMPE_ADC_CH(info->channel));
8585 mutex_unlock(&info->lock);
@@ -96,7 +96,7 @@ static int stmpe_read_voltage(struct stmpe_adc *info, · 10 unmodified lines
9696 static int stmpe_read_temp(struct stmpe_adc *info,
9797 struct iio_chan_spec const *chan, int *val)
9898 {
99− long ret;
99+ unsigned long ret;
100100
101101 mutex_lock(&info->lock);
102102
@@ -114,7 +114,7 @@ static int stmpe_read_temp(struct stmpe_adc *info, · 11 unmodified lines
114114
115115 ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
116116
117− if (ret <= 0) {
117+ if (ret == 0) {
118118 mutex_unlock(&info->lock);
119119 return -ETIMEDOUT;
120120 }
@@ -345,21 +345,22 @@ static int __maybe_unused stmpe_adc_resume(struct device *dev) · 224 unmodified lines
345345
346346 static SIMPLE_DEV_PM_OPS(stmpe_adc_pm_ops, NULL, stmpe_adc_resume);
347347
348+static const struct of_device_id stmpe_adc_ids[] = {
349+ { .compatible = "st,stmpe-adc", },
350+ { },
351+};
352+MODULE_DEVICE_TABLE(of, stmpe_adc_ids);
353+
348354 static struct platform_driver stmpe_adc_driver = {
349355 .probe = stmpe_adc_probe,
350356 .driver = {
351357 .name = "stmpe-adc",
352358 .pm = &stmpe_adc_pm_ops,
359+ .of_match_table = stmpe_adc_ids,
353360 },
354361 };
355362 module_platform_driver(stmpe_adc_driver);
356363
357−static const struct of_device_id stmpe_adc_ids[] = {
358− { .compatible = "st,stmpe-adc", },
359− { },
360−};
361−MODULE_DEVICE_TABLE(of, stmpe_adc_ids);
362−
363364 MODULE_AUTHOR("Stefan Agner <stefan.agner@toradex.com>");
364365 MODULE_DESCRIPTION("STMPEXXX ADC driver");
365366 MODULE_LICENSE("GPL v2");
drivers/iio/adc/ti-ads1015.c+232−166
@@ -76,10 +76,15 @@ · 75 unmodified lines
7676 #define ADS1015_DEFAULT_DATA_RATE 4
7777 #define ADS1015_DEFAULT_CHAN 0
7878
79−enum chip_ids {
80− ADSXXXX = 0,
81− ADS1015,
82− ADS1115,
79+struct ads1015_chip_data {
80+ struct iio_chan_spec const *channels;
81+ int num_channels;
82+ const struct iio_info *info;
83+ const int *data_rate;
84+ const int data_rate_len;
85+ const int *scale;
86+ const int scale_len;
87+ bool has_comparator;
8388 };
8489
8590 enum ads1015_channels {
@@ -94,11 +99,11 @@ enum ads1015_channels { · 8 unmodified lines
9499 ADS1015_TIMESTAMP,
95100 };
96101
97−static const unsigned int ads1015_data_rate[] = {
102+static const int ads1015_data_rate[] = {
98103 128, 250, 490, 920, 1600, 2400, 3300, 3300
99104 };
100105
101−static const unsigned int ads1115_data_rate[] = {
106+static const int ads1115_data_rate[] = {
102107 8, 16, 32, 64, 128, 250, 475, 860
103108 };
104109
@@ -106,10 +111,28 @@ static const unsigned int ads1115_data_rate[] = { · 1 unmodified line
106111 * Translation from PGA bits to full-scale positive and negative input voltage
107112 * range in mV
108113 */
109−static int ads1015_fullscale_range[] = {
114+static const int ads1015_fullscale_range[] = {
110115 6144, 4096, 2048, 1024, 512, 256, 256, 256
111116 };
112117
118+static const int ads1015_scale[] = { /* 12bit ADC */
119+ 256, 11,
120+ 512, 11,
121+ 1024, 11,
122+ 2048, 11,
123+ 4096, 11,
124+ 6144, 11
125+};
126+
127+static const int ads1115_scale[] = { /* 16bit ADC */
128+ 256, 15,
129+ 512, 15,
130+ 1024, 15,
131+ 2048, 15,
132+ 4096, 15,
133+ 6144, 15
134+};
135+
113136 /*
114137 * Translation from COMP_QUE field value to the number of successive readings
115138 * exceed the threshold values before an interrupt is generated
@@ -134,71 +157,53 @@ static const struct iio_event_spec ads1015_events[] = { · 18 unmodified lines
134157 },
135158 };
136159
137−#define ADS1015_V_CHAN(_chan, _addr) { \
138− .type = IIO_VOLTAGE, \
139− .indexed = 1, \
140− .address = _addr, \
141− .channel = _chan, \
142− .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
143− BIT(IIO_CHAN_INFO_SCALE) | \
144− BIT(IIO_CHAN_INFO_SAMP_FREQ), \
145− .scan_index = _addr, \
146− .scan_type = { \
147− .sign = 's', \
148− .realbits = 12, \
149− .storagebits = 16, \
150− .shift = 4, \
151− .endianness = IIO_CPU, \
152− }, \
153− .event_spec = ads1015_events, \
154− .num_event_specs = ARRAY_SIZE(ads1015_events), \
155− .datasheet_name = "AIN"#_chan, \
156−}
157−
158−#define ADS1015_V_DIFF_CHAN(_chan, _chan2, _addr) { \
160+/*
161+ * Compile-time check whether _fitbits can accommodate up to _testbits
162+ * bits. Returns _fitbits on success, fails to compile otherwise.
163+ *
164+ * The test works such that it multiplies constant _fitbits by constant
165+ * double-negation of size of a non-empty structure, i.e. it multiplies
166+ * constant _fitbits by constant 1 in each successful compilation case.
167+ * The non-empty structure may contain C11 _Static_assert(), make use of
168+ * this and place the kernel variant of static assert in there, so that
169+ * it performs the compile-time check for _testbits <= _fitbits. Note
170+ * that it is not possible to directly use static_assert in compound
171+ * statements, hence this convoluted construct.
172+ */
173+#define FIT_CHECK(_testbits, _fitbits) \
174+ ( \
175+ (_fitbits) * \
176+ !!sizeof(struct { \
177+ static_assert((_testbits) <= (_fitbits)); \
178+ int pad; \
179+ }) \
180+ )
181+
182+#define ADS1015_V_CHAN(_chan, _addr, _realbits, _shift, _event_spec, _num_event_specs) { \
159183 .type = IIO_VOLTAGE, \
160− .differential = 1, \
161184 .indexed = 1, \
162185 .address = _addr, \
163186 .channel = _chan, \
164− .channel2 = _chan2, \
165187 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
166188 BIT(IIO_CHAN_INFO_SCALE) | \
167189 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
168− .scan_index = _addr, \
169− .scan_type = { \
170− .sign = 's', \
171− .realbits = 12, \
172− .storagebits = 16, \
173− .shift = 4, \
174− .endianness = IIO_CPU, \
175− }, \
176− .event_spec = ads1015_events, \
177− .num_event_specs = ARRAY_SIZE(ads1015_events), \
178− .datasheet_name = "AIN"#_chan"-AIN"#_chan2, \
179−}
180−
181−#define ADS1115_V_CHAN(_chan, _addr) { \
182− .type = IIO_VOLTAGE, \
183− .indexed = 1, \
184− .address = _addr, \
185− .channel = _chan, \
186− .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
190+ .info_mask_shared_by_all_available = \
187191 BIT(IIO_CHAN_INFO_SCALE) | \
188192 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
189193 .scan_index = _addr, \
190194 .scan_type = { \
191195 .sign = 's', \
192− .realbits = 16, \
193− .storagebits = 16, \
196+ .realbits = (_realbits), \
197+ .storagebits = FIT_CHECK((_realbits) + (_shift), 16), \
198+ .shift = (_shift), \
194199 .endianness = IIO_CPU, \
195200 }, \
196− .event_spec = ads1015_events, \
197− .num_event_specs = ARRAY_SIZE(ads1015_events), \
201+ .event_spec = (_event_spec), \
202+ .num_event_specs = (_num_event_specs), \
198203 .datasheet_name = "AIN"#_chan, \
199204 }
200205
201−#define ADS1115_V_DIFF_CHAN(_chan, _chan2, _addr) { \
206+#define ADS1015_V_DIFF_CHAN(_chan, _chan2, _addr, _realbits, _shift, _event_spec, _num_event_specs) { \
202207 .type = IIO_VOLTAGE, \
203208 .differential = 1, \
204209 .indexed = 1, \
@@ -208,15 +213,19 @@ static const struct iio_event_spec ads1015_events[] = { · 3 unmodified lines
208213 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
209214 BIT(IIO_CHAN_INFO_SCALE) | \
210215 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
216+ .info_mask_shared_by_all_available = \
217+ BIT(IIO_CHAN_INFO_SCALE) | \
218+ BIT(IIO_CHAN_INFO_SAMP_FREQ), \
211219 .scan_index = _addr, \
212220 .scan_type = { \
213221 .sign = 's', \
214− .realbits = 16, \
215− .storagebits = 16, \
222+ .realbits = (_realbits), \
223+ .storagebits = FIT_CHECK((_realbits) + (_shift), 16), \
224+ .shift = (_shift), \
216225 .endianness = IIO_CPU, \
217226 }, \
218− .event_spec = ads1015_events, \
219− .num_event_specs = ARRAY_SIZE(ads1015_events), \
227+ .event_spec = (_event_spec), \
228+ .num_event_specs = (_num_event_specs), \
220229 .datasheet_name = "AIN"#_chan"-AIN"#_chan2, \
221230 }
222231
@@ -245,7 +254,7 @@ struct ads1015_data { · 22 unmodified lines
245254 unsigned int comp_mode;
246255 struct ads1015_thresh_data thresh_data[ADS1015_CHANNELS];
247256
248− unsigned int *data_rate;
257+ const struct ads1015_chip_data *chip;
249258 /*
250259 * Set to true when the ADC is switched to the continuous-conversion
251260 * mode and exits from a power-down state. This flag is used to avoid
@@ -273,49 +282,91 @@ static void ads1015_event_channel_disable(struct ads1015_data *data, int chan) · 21 unmodified lines
273282 data->event_channel = ADS1015_CHANNELS;
274283 }
275284
276−static bool ads1015_is_writeable_reg(struct device *dev, unsigned int reg)
277−{
278− switch (reg) {
279− case ADS1015_CFG_REG:
280− case ADS1015_LO_THRESH_REG:
281− case ADS1015_HI_THRESH_REG:
282− return true;
283− default:
284− return false;
285− }
286−}
285+static const struct regmap_range ads1015_writeable_ranges[] = {
286+ regmap_reg_range(ADS1015_CFG_REG, ADS1015_HI_THRESH_REG),
287+};
288+
289+static const struct regmap_access_table ads1015_writeable_table = {
290+ .yes_ranges = ads1015_writeable_ranges,
291+ .n_yes_ranges = ARRAY_SIZE(ads1015_writeable_ranges),
292+};
287293
288294 static const struct regmap_config ads1015_regmap_config = {
289295 .reg_bits = 8,
290296 .val_bits = 16,
291297 .max_register = ADS1015_HI_THRESH_REG,
292− .writeable_reg = ads1015_is_writeable_reg,
298+ .wr_table = &ads1015_writeable_table,
299+};
300+
301+static const struct regmap_range tla2024_writeable_ranges[] = {
302+ regmap_reg_range(ADS1015_CFG_REG, ADS1015_CFG_REG),
303+};
304+
305+static const struct regmap_access_table tla2024_writeable_table = {
306+ .yes_ranges = tla2024_writeable_ranges,
307+ .n_yes_ranges = ARRAY_SIZE(tla2024_writeable_ranges),
308+};
309+
310+static const struct regmap_config tla2024_regmap_config = {
311+ .reg_bits = 8,
312+ .val_bits = 16,
313+ .max_register = ADS1015_CFG_REG,
314+ .wr_table = &tla2024_writeable_table,
293315 };
294316
295317 static const struct iio_chan_spec ads1015_channels[] = {
296− ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1),
297− ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3),
298− ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3),
299− ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3),
300− ADS1015_V_CHAN(0, ADS1015_AIN0),
301− ADS1015_V_CHAN(1, ADS1015_AIN1),
302− ADS1015_V_CHAN(2, ADS1015_AIN2),
303− ADS1015_V_CHAN(3, ADS1015_AIN3),
318+ ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4,
319+ ads1015_events, ARRAY_SIZE(ads1015_events)),
320+ ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 12, 4,
321+ ads1015_events, ARRAY_SIZE(ads1015_events)),
322+ ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 12, 4,
323+ ads1015_events, ARRAY_SIZE(ads1015_events)),
324+ ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 12, 4,
325+ ads1015_events, ARRAY_SIZE(ads1015_events)),
326+ ADS1015_V_CHAN(0, ADS1015_AIN0, 12, 4,
327+ ads1015_events, ARRAY_SIZE(ads1015_events)),
328+ ADS1015_V_CHAN(1, ADS1015_AIN1, 12, 4,
329+ ads1015_events, ARRAY_SIZE(ads1015_events)),
330+ ADS1015_V_CHAN(2, ADS1015_AIN2, 12, 4,
331+ ads1015_events, ARRAY_SIZE(ads1015_events)),
332+ ADS1015_V_CHAN(3, ADS1015_AIN3, 12, 4,
333+ ads1015_events, ARRAY_SIZE(ads1015_events)),
304334 IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP),
305335 };
306336
307337 static const struct iio_chan_spec ads1115_channels[] = {
308− ADS1115_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1),
309− ADS1115_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3),
310− ADS1115_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3),
311− ADS1115_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3),
312− ADS1115_V_CHAN(0, ADS1015_AIN0),
313− ADS1115_V_CHAN(1, ADS1015_AIN1),
314− ADS1115_V_CHAN(2, ADS1015_AIN2),
315− ADS1115_V_CHAN(3, ADS1015_AIN3),
338+ ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 16, 0,
339+ ads1015_events, ARRAY_SIZE(ads1015_events)),
340+ ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 16, 0,
341+ ads1015_events, ARRAY_SIZE(ads1015_events)),
342+ ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 16, 0,
343+ ads1015_events, ARRAY_SIZE(ads1015_events)),
344+ ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 16, 0,
345+ ads1015_events, ARRAY_SIZE(ads1015_events)),
346+ ADS1015_V_CHAN(0, ADS1015_AIN0, 16, 0,
347+ ads1015_events, ARRAY_SIZE(ads1015_events)),
348+ ADS1015_V_CHAN(1, ADS1015_AIN1, 16, 0,
349+ ads1015_events, ARRAY_SIZE(ads1015_events)),
350+ ADS1015_V_CHAN(2, ADS1015_AIN2, 16, 0,
351+ ads1015_events, ARRAY_SIZE(ads1015_events)),
352+ ADS1015_V_CHAN(3, ADS1015_AIN3, 16, 0,
353+ ads1015_events, ARRAY_SIZE(ads1015_events)),
316354 IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP),
317355 };
318356
357+static const struct iio_chan_spec tla2024_channels[] = {
358+ ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4, NULL, 0),
359+ ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 12, 4, NULL, 0),
360+ ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 12, 4, NULL, 0),
361+ ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 12, 4, NULL, 0),
362+ ADS1015_V_CHAN(0, ADS1015_AIN0, 12, 4, NULL, 0),
363+ ADS1015_V_CHAN(1, ADS1015_AIN1, 12, 4, NULL, 0),
364+ ADS1015_V_CHAN(2, ADS1015_AIN2, 12, 4, NULL, 0),
365+ ADS1015_V_CHAN(3, ADS1015_AIN3, 12, 4, NULL, 0),
366+ IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP),
367+};
368+
369+
319370 #ifdef CONFIG_PM
320371 static int ads1015_set_power_state(struct ads1015_data *data, bool on)
321372 {
@@ -344,6 +395,7 @@ static int ads1015_set_power_state(struct ads1015_data *data, bool on) · 22 unmodified lines
344395 static
345396 int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
346397 {
398+ const int *data_rate = data->chip->data_rate;
347399 int ret, pga, dr, dr_old, conv_time;
348400 unsigned int old, mask, cfg;
349401
@@ -378,8 +430,8 @@ int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val) · 28 unmodified lines
378430 }
379431 if (data->conv_invalid) {
380432 dr_old = (old & ADS1015_CFG_DR_MASK) >> ADS1015_CFG_DR_SHIFT;
381− conv_time = DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr_old]);
382− conv_time += DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr]);
433+ conv_time = DIV_ROUND_UP(USEC_PER_SEC, data_rate[dr_old]);
434+ conv_time += DIV_ROUND_UP(USEC_PER_SEC, data_rate[dr]);
383435 conv_time += conv_time / 10; /* 10% internal clock inaccuracy */
384436 usleep_range(conv_time, conv_time + 1);
385437 data->conv_invalid = false;
@@ -445,8 +497,8 @@ static int ads1015_set_data_rate(struct ads1015_data *data, int chan, int rate) · 59 unmodified lines
445497 {
446498 int i;
447499
448− for (i = 0; i < ARRAY_SIZE(ads1015_data_rate); i++) {
449− if (data->data_rate[i] == rate) {
500+ for (i = 0; i < data->chip->data_rate_len; i++) {
501+ if (data->chip->data_rate[i] == rate) {
450502 data->channel_data[chan].data_rate = i;
451503 return 0;
452504 }
@@ -455,6 +507,32 @@ static int ads1015_set_data_rate(struct ads1015_data *data, int chan, int rate) · 2 unmodified lines
455507 return -EINVAL;
456508 }
457509
510+static int ads1015_read_avail(struct iio_dev *indio_dev,
511+ struct iio_chan_spec const *chan,
512+ const int **vals, int *type, int *length,
513+ long mask)
514+{
515+ struct ads1015_data *data = iio_priv(indio_dev);
516+
517+ if (chan->type != IIO_VOLTAGE)
518+ return -EINVAL;
519+
520+ switch (mask) {
521+ case IIO_CHAN_INFO_SCALE:
522+ *type = IIO_VAL_FRACTIONAL_LOG2;
523+ *vals = data->chip->scale;
524+ *length = data->chip->scale_len;
525+ return IIO_AVAIL_LIST;
526+ case IIO_CHAN_INFO_SAMP_FREQ:
527+ *type = IIO_VAL_INT;
528+ *vals = data->chip->data_rate;
529+ *length = data->chip->data_rate_len;
530+ return IIO_AVAIL_LIST;
531+ default:
532+ return -EINVAL;
533+ }
534+}
535+
458536 static int ads1015_read_raw(struct iio_dev *indio_dev,
459537 struct iio_chan_spec const *chan, int *val,
460538 int *val2, long mask)
@@ -504,7 +582,7 @@ release_direct: · 43 unmodified lines
504582 break;
505583 case IIO_CHAN_INFO_SAMP_FREQ:
506584 idx = data->channel_data[chan->address].data_rate;
507− *val = data->data_rate[idx];
585+ *val = data->chip->data_rate[idx];
508586 ret = IIO_VAL_INT;
509587 break;
510588 default:
@@ -564,7 +642,7 @@ static int ads1015_read_event(struct iio_dev *indio_dev, · 53 unmodified lines
564642 dr = data->channel_data[chan->address].data_rate;
565643 comp_queue = data->thresh_data[chan->address].comp_queue;
566644 period = ads1015_comp_queue[comp_queue] *
567− USEC_PER_SEC / data->data_rate[dr];
645+ USEC_PER_SEC / data->chip->data_rate[dr];
568646
569647 *val = period / USEC_PER_SEC;
570648 *val2 = period % USEC_PER_SEC;
@@ -586,6 +664,7 @@ static int ads1015_write_event(struct iio_dev *indio_dev, · 15 unmodified lines
586664 int val2)
587665 {
588666 struct ads1015_data *data = iio_priv(indio_dev);
667+ const int *data_rate = data->chip->data_rate;
589668 int realbits = chan->scan_type.realbits;
590669 int ret = 0;
591670 long long period;
@@ -611,7 +690,7 @@ static int ads1015_write_event(struct iio_dev *indio_dev, · 19 unmodified lines
611690
612691 for (i = 0; i < ARRAY_SIZE(ads1015_comp_queue) - 1; i++) {
613692 if (period <= ads1015_comp_queue[i] *
614− USEC_PER_SEC / data->data_rate[dr])
693+ USEC_PER_SEC / data_rate[dr])
615694 break;
616695 }
617696 data->thresh_data[chan->address].comp_queue = i;
@@ -802,54 +881,20 @@ static const struct iio_buffer_setup_ops ads1015_buffer_setup_ops = { · 184 unmodified lines
802881 .validate_scan_mask = &iio_validate_scan_mask_onehot,
803882 };
804883
805−static IIO_CONST_ATTR_NAMED(ads1015_scale_available, scale_available,
806− "3 2 1 0.5 0.25 0.125");
807−static IIO_CONST_ATTR_NAMED(ads1115_scale_available, scale_available,
808− "0.1875 0.125 0.0625 0.03125 0.015625 0.007813");
809−
810−static IIO_CONST_ATTR_NAMED(ads1015_sampling_frequency_available,
811− sampling_frequency_available, "128 250 490 920 1600 2400 3300");
812−static IIO_CONST_ATTR_NAMED(ads1115_sampling_frequency_available,
813− sampling_frequency_available, "8 16 32 64 128 250 475 860");
814−
815−static struct attribute *ads1015_attributes[] = {
816− &iio_const_attr_ads1015_scale_available.dev_attr.attr,
817− &iio_const_attr_ads1015_sampling_frequency_available.dev_attr.attr,
818− NULL,
819−};
820−
821−static const struct attribute_group ads1015_attribute_group = {
822− .attrs = ads1015_attributes,
823−};
824−
825−static struct attribute *ads1115_attributes[] = {
826− &iio_const_attr_ads1115_scale_available.dev_attr.attr,
827− &iio_const_attr_ads1115_sampling_frequency_available.dev_attr.attr,
828− NULL,
829−};
830−
831−static const struct attribute_group ads1115_attribute_group = {
832− .attrs = ads1115_attributes,
833−};
834−
835884 static const struct iio_info ads1015_info = {
885+ .read_avail = ads1015_read_avail,
836886 .read_raw = ads1015_read_raw,
837887 .write_raw = ads1015_write_raw,
838888 .read_event_value = ads1015_read_event,
839889 .write_event_value = ads1015_write_event,
840890 .read_event_config = ads1015_read_event_config,
841891 .write_event_config = ads1015_write_event_config,
842− .attrs = &ads1015_attribute_group,
843892 };
844893
845−static const struct iio_info ads1115_info = {
894+static const struct iio_info tla2024_info = {
895+ .read_avail = ads1015_read_avail,
846896 .read_raw = ads1015_read_raw,
847897 .write_raw = ads1015_write_raw,
848− .read_event_value = ads1015_read_event,
849− .write_event_value = ads1015_write_event,
850− .read_event_config = ads1015_read_event_config,
851− .write_event_config = ads1015_write_event_config,
852− .attrs = &ads1115_attribute_group,
853898 };
854899
855900 static int ads1015_client_get_channels_config(struct i2c_client *client)
@@ -932,12 +977,18 @@ static int ads1015_set_conv_mode(struct ads1015_data *data, int mode) · 76 unmodified lines
932977 static int ads1015_probe(struct i2c_client *client,
933978 const struct i2c_device_id *id)
934979 {
980+ const struct ads1015_chip_data *chip;
935981 struct iio_dev *indio_dev;
936982 struct ads1015_data *data;
937983 int ret;
938− enum chip_ids chip;
939984 int i;
940985
986+ chip = device_get_match_data(&client->dev);
987+ if (!chip)
988+ chip = (const struct ads1015_chip_data *)id->driver_data;
989+ if (!chip)
990+ return dev_err_probe(&client->dev, -EINVAL, "Unknown chip\n");
991+
941992 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
942993 if (!indio_dev)
943994 return -ENOMEM;
@@ -950,28 +1001,12 @@ static int ads1015_probe(struct i2c_client *client, · 6 unmodified lines
9501001 indio_dev->name = ADS1015_DRV_NAME;
9511002 indio_dev->modes = INDIO_DIRECT_MODE;
9521003
953− chip = (uintptr_t)device_get_match_data(&client->dev);
954− if (chip == ADSXXXX)
955− chip = id->driver_data;
956− switch (chip) {
957− case ADS1015:
958− indio_dev->channels = ads1015_channels;
959− indio_dev->num_channels = ARRAY_SIZE(ads1015_channels);
960− indio_dev->info = &ads1015_info;
961− data->data_rate = (unsigned int *) &ads1015_data_rate;
962− break;
963− case ADS1115:
964− indio_dev->channels = ads1115_channels;
965− indio_dev->num_channels = ARRAY_SIZE(ads1115_channels);
966− indio_dev->info = &ads1115_info;
967− data->data_rate = (unsigned int *) &ads1115_data_rate;
968− break;
969− default:
970− dev_err(&client->dev, "Unknown chip %d\n", chip);
971− return -EINVAL;
972− }
973−
1004+ indio_dev->channels = chip->channels;
1005+ indio_dev->num_channels = chip->num_channels;
1006+ indio_dev->info = chip->info;
1007+ data->chip = chip;
9741008 data->event_channel = ADS1015_CHANNELS;
1009+
9751010 /*
9761011 * Set default lower and upper threshold to min and max value
9771012 * respectively.
@@ -986,7 +1021,9 @@ static int ads1015_probe(struct i2c_client *client, · 8 unmodified lines
9861021 /* we need to keep this ABI the same as used by hwmon ADS1015 driver */
9871022 ads1015_get_channels_config(client);
9881023
989− data->regmap = devm_regmap_init_i2c(client, &ads1015_regmap_config);
1024+ data->regmap = devm_regmap_init_i2c(client, chip->has_comparator ?
1025+ &ads1015_regmap_config :
1026+ &tla2024_regmap_config);
9901027 if (IS_ERR(data->regmap)) {
9911028 dev_err(&client->dev, "Failed to allocate register map\n");
9921029 return PTR_ERR(data->regmap);
@@ -1000,7 +1037,7 @@ static int ads1015_probe(struct i2c_client *client, · 7 unmodified lines
10001037 return ret;
10011038 }
10021039
1003− if (client->irq) {
1040+ if (client->irq && chip->has_comparator) {
10041041 unsigned long irq_trig =
10051042 irqd_get_trigger_type(irq_get_irq_data(client->irq));
10061043 unsigned int cfg_comp_mask = ADS1015_CFG_COMP_QUE_MASK |
@@ -1099,22 +1136,51 @@ static const struct dev_pm_ops ads1015_pm_ops = { · 92 unmodified lines
10991136 ads1015_runtime_resume, NULL)
11001137 };
11011138
1139+static const struct ads1015_chip_data ads1015_data = {
1140+ .channels = ads1015_channels,
1141+ .num_channels = ARRAY_SIZE(ads1015_channels),
1142+ .info = &ads1015_info,
1143+ .data_rate = ads1015_data_rate,
1144+ .data_rate_len = ARRAY_SIZE(ads1015_data_rate),
1145+ .scale = ads1015_scale,
1146+ .scale_len = ARRAY_SIZE(ads1015_scale),
1147+ .has_comparator = true,
1148+};
1149+
1150+static const struct ads1015_chip_data ads1115_data = {
1151+ .channels = ads1115_channels,
1152+ .num_channels = ARRAY_SIZE(ads1115_channels),
1153+ .info = &ads1015_info,
1154+ .data_rate = ads1115_data_rate,
1155+ .data_rate_len = ARRAY_SIZE(ads1115_data_rate),
1156+ .scale = ads1115_scale,
1157+ .scale_len = ARRAY_SIZE(ads1115_scale),
1158+ .has_comparator = true,
1159+};
1160+
1161+static const struct ads1015_chip_data tla2024_data = {
1162+ .channels = tla2024_channels,
1163+ .num_channels = ARRAY_SIZE(tla2024_channels),
1164+ .info = &tla2024_info,
1165+ .data_rate = ads1015_data_rate,
1166+ .data_rate_len = ARRAY_SIZE(ads1015_data_rate),
1167+ .scale = ads1015_scale,
1168+ .scale_len = ARRAY_SIZE(ads1015_scale),
1169+ .has_comparator = false,
1170+};
1171+
11021172 static const struct i2c_device_id ads1015_id[] = {
1103− {"ads1015", ADS1015},
1104− {"ads1115", ADS1115},
1173+ { "ads1015", (kernel_ulong_t)&ads1015_data },
1174+ { "ads1115", (kernel_ulong_t)&ads1115_data },
1175+ { "tla2024", (kernel_ulong_t)&tla2024_data },
11051176 {}
11061177 };
11071178 MODULE_DEVICE_TABLE(i2c, ads1015_id);
11081179
11091180 static const struct of_device_id ads1015_of_match[] = {
1110− {
1111− .compatible = "ti,ads1015",
1112− .data = (void *)ADS1015
1113− },
1114− {
1115− .compatible = "ti,ads1115",
1116− .data = (void *)ADS1115
1117− },
1181+ { .compatible = "ti,ads1015", .data = &ads1015_data },
1182+ { .compatible = "ti,ads1115", .data = &ads1115_data },
1183+ { .compatible = "ti,tla2024", .data = &tla2024_data },
11181184 {}
11191185 };
11201186 MODULE_DEVICE_TABLE(of, ads1015_of_match);
drivers/iio/adc/ti-ads8688.c+1−0
@@ -508,6 +508,7 @@ MODULE_DEVICE_TABLE(of, ads8688_of_match); · 507 unmodified lines
508508 static struct spi_driver ads8688_driver = {
509509 .driver = {
510510 .name = "ads8688",
511+ .of_match_table = ads8688_of_match,
511512 },
512513 .probe = ads8688_probe,
513514 .remove = ads8688_remove,
drivers/iio/adc/ti_am335x_adc.c+1−3
@@ -376,9 +376,7 @@ static int tiadc_iio_buffered_hardware_setup(struct device *dev, · 375 unmodified lines
376376 {
377377 int ret;
378378
379− ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
380− INDIO_BUFFER_SOFTWARE,
381− setup_ops);
379+ ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, setup_ops);
382380 if (ret)
383381 return ret;
384382
drivers/iio/afe/Kconfig+0−1
@@ -8,7 +8,6 @@ menu "Analog Front Ends" · 7 unmodified lines
88
99 config IIO_RESCALE
1010 tristate "IIO rescale"
11− depends on OF || COMPILE_TEST
1211 help
1312 Say yes here to build support for the IIO rescaling
1413 that handles voltage dividers, current sense shunts and
drivers/iio/afe/iio-rescale.c+2−3
@@ -10,9 +10,8 @@ · 9 unmodified lines
1010
1111 #include <linux/err.h>
1212 #include <linux/gcd.h>
13+#include <linux/mod_devicetable.h>
1314 #include <linux/module.h>
14−#include <linux/of.h>
15−#include <linux/of_device.h>
1615 #include <linux/platform_device.h>
1716 #include <linux/property.h>
1817
@@ -536,7 +535,7 @@ static int rescale_probe(struct platform_device *pdev) · 517 unmodified lines
536535
537536 rescale = iio_priv(indio_dev);
538537
539− rescale->cfg = of_device_get_match_data(dev);
538+ rescale->cfg = device_get_match_data(dev);
540539 rescale->numerator = 1;
541540 rescale->denominator = 1;
542541 rescale->offset = 0;
drivers/iio/buffer/kfifo_buf.c+1−9
@@ -259,8 +259,6 @@ static struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev) · 258 unmodified lines
259259 * devm_iio_kfifo_buffer_setup_ext - Allocate a kfifo buffer & attach it to an IIO device
260260 * @dev: Device object to which to attach the life-time of this kfifo buffer
261261 * @indio_dev: The device the buffer should be attached to
262− * @mode_flags: The mode flags for this buffer (INDIO_BUFFER_SOFTWARE and/or
263− * INDIO_BUFFER_TRIGGERED).
264262 * @setup_ops: The setup_ops required to configure the HW part of the buffer (optional)
265263 * @buffer_attrs: Extra sysfs buffer attributes for this IIO buffer
266264 *
@@ -271,22 +269,16 @@ static struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev) · 4 unmodified lines
271269 */
272270 int devm_iio_kfifo_buffer_setup_ext(struct device *dev,
273271 struct iio_dev *indio_dev,
274− int mode_flags,
275272 const struct iio_buffer_setup_ops *setup_ops,
276273 const struct attribute **buffer_attrs)
277274 {
278275 struct iio_buffer *buffer;
279276
280− if (!mode_flags)
281− return -EINVAL;
282−
283277 buffer = devm_iio_kfifo_allocate(dev);
284278 if (!buffer)
285279 return -ENOMEM;
286280
287− mode_flags &= kfifo_access_funcs.modes;
288−
289− indio_dev->modes |= mode_flags;
281+ indio_dev->modes |= INDIO_BUFFER_SOFTWARE;
290282 indio_dev->setup_ops = setup_ops;
291283
292284 buffer->attrs = buffer_attrs;
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c+2−3
@@ -333,8 +333,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, · 332 unmodified lines
333333 * We can not use trigger here, as events are generated
334334 * as soon as sample_frequency is set.
335335 */
336− ret = devm_iio_kfifo_buffer_setup_ext(dev, indio_dev,
337− INDIO_BUFFER_SOFTWARE, NULL,
336+ ret = devm_iio_kfifo_buffer_setup_ext(dev, indio_dev, NULL,
338337 cros_ec_sensor_fifo_attributes);
339338 if (ret)
340339 return ret;
@@ -413,7 +412,7 @@ static ssize_t cros_ec_sensors_calibrate(struct iio_dev *indio_dev, · 72 unmodified lines
413412 int ret, i;
414413 bool calibrate;
415414
416− ret = strtobool(buf, &calibrate);
415+ ret = kstrtobool(buf, &calibrate);
417416 if (ret < 0)
418417 return ret;
419418 if (!calibrate)
drivers/iio/common/scmi_sensors/scmi_iio.c+0−1
@@ -686,7 +686,6 @@ static int scmi_iio_dev_probe(struct scmi_device *sdev) · 685 unmodified lines
686686
687687 err = devm_iio_kfifo_buffer_setup(&scmi_iio_dev->dev,
688688 scmi_iio_dev,
689− INDIO_BUFFER_SOFTWARE,
690689 &scmi_iio_buffer_ops);
691690 if (err < 0) {
692691 dev_err(dev,
drivers/iio/common/ssp_sensors/ssp_spi.c+6−7
@@ -331,12 +331,11 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len) · 330 unmodified lines
331331 /* threaded irq */
332332 int ssp_irq_msg(struct ssp_data *data)
333333 {
334− bool found = false;
335334 char *buffer;
336335 u8 msg_type;
337336 int ret;
338337 u16 length, msg_options;
339− struct ssp_msg *msg, *n;
338+ struct ssp_msg *msg = NULL, *iter, *n;
340339
341340 ret = spi_read(data->spi, data->header_buffer, SSP_HEADER_BUFFER_SIZE);
342341 if (ret < 0) {
@@ -362,15 +361,15 @@ int ssp_irq_msg(struct ssp_data *data) · 19 unmodified lines
362361 * received with no order
363362 */
364363 mutex_lock(&data->pending_lock);
365− list_for_each_entry_safe(msg, n, &data->pending_list, list) {
366− if (msg->options == msg_options) {
367− list_del(&msg->list);
368− found = true;
364+ list_for_each_entry_safe(iter, n, &data->pending_list, list) {
365+ if (iter->options == msg_options) {
366+ list_del(&iter->list);
367+ msg = iter;
369368 break;
370369 }
371370 }
372371
373− if (!found) {
372+ if (!msg) {
374373 /*
375374 * here can be implemented dead messages handling
376375 * but the slave should not send such ones - it is to
drivers/iio/common/st_sensors/st_sensors_core.c+27−23
@@ -71,16 +71,18 @@ st_sensors_match_odr_error: · 70 unmodified lines
7171
7272 int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr)
7373 {
74− int err;
74+ int err = 0;
7575 struct st_sensor_odr_avl odr_out = {0, 0};
7676 struct st_sensor_data *sdata = iio_priv(indio_dev);
7777
78+ mutex_lock(&sdata->odr_lock);
79+
7880 if (!sdata->sensor_settings->odr.mask)
79− return 0;
81+ goto unlock_mutex;
8082
8183 err = st_sensors_match_odr(sdata->sensor_settings, odr, &odr_out);
8284 if (err < 0)
83− goto st_sensors_match_odr_error;
85+ goto unlock_mutex;
8486
8587 if ((sdata->sensor_settings->odr.addr ==
8688 sdata->sensor_settings->pw.addr) &&
@@ -103,7 +105,9 @@ int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr) · 16 unmodified lines
103105 if (err >= 0)
104106 sdata->odr = odr_out.hz;
105107
106−st_sensors_match_odr_error:
108+unlock_mutex:
109+ mutex_unlock(&sdata->odr_lock);
110+
107111 return err;
108112 }
109113 EXPORT_SYMBOL_NS(st_sensors_set_odr, IIO_ST_SENSORS);
@@ -361,6 +365,8 @@ int st_sensors_init_sensor(struct iio_dev *indio_dev, · 251 unmodified lines
361365 struct st_sensors_platform_data *of_pdata;
362366 int err = 0;
363367
368+ mutex_init(&sdata->odr_lock);
369+
364370 /* If OF/DT pdata exists, it will take precedence of anything else */
365371 of_pdata = st_sensors_dev_probe(indio_dev->dev.parent, pdata);
366372 if (IS_ERR(of_pdata))
@@ -549,26 +555,28 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev, · 182 unmodified lines
549555 int err;
550556 struct st_sensor_data *sdata = iio_priv(indio_dev);
551557
552− mutex_lock(&indio_dev->mlock);
553− if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
554− err = -EBUSY;
558+ err = iio_device_claim_direct_mode(indio_dev);
559+ if (err)
560+ return err;
561+
562+ mutex_lock(&sdata->odr_lock);
563+
564+ err = st_sensors_set_enable(indio_dev, true);
565+ if (err < 0)
555566 goto out;
556− } else {
557− err = st_sensors_set_enable(indio_dev, true);
558− if (err < 0)
559− goto out;
560567
561− msleep((sdata->sensor_settings->bootime * 1000) / sdata->odr);
562− err = st_sensors_read_axis_data(indio_dev, ch, val);
563− if (err < 0)
564− goto out;
568+ msleep((sdata->sensor_settings->bootime * 1000) / sdata->odr);
569+ err = st_sensors_read_axis_data(indio_dev, ch, val);
570+ if (err < 0)
571+ goto out;
565572
566− *val = *val >> ch->scan_type.shift;
573+ *val = *val >> ch->scan_type.shift;
574+
575+ err = st_sensors_set_enable(indio_dev, false);
567576
568− err = st_sensors_set_enable(indio_dev, false);
569− }
570577 out:
571− mutex_unlock(&indio_dev->mlock);
578+ mutex_unlock(&sdata->odr_lock);
579+ iio_device_release_direct_mode(indio_dev);
572580
573581 return err;
574582 }
@@ -641,7 +649,6 @@ ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev, · 66 unmodified lines
641649 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
642650 struct st_sensor_data *sdata = iio_priv(indio_dev);
643651
644− mutex_lock(&indio_dev->mlock);
645652 for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) {
646653 if (sdata->sensor_settings->odr.odr_avl[i].hz == 0)
647654 break;
@@ -649,7 +656,6 @@ ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev, · 1 unmodified line
649656 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
650657 sdata->sensor_settings->odr.odr_avl[i].hz);
651658 }
652− mutex_unlock(&indio_dev->mlock);
653659 buf[len - 1] = '\n';
654660
655661 return len;
@@ -663,7 +669,6 @@ ssize_t st_sensors_sysfs_scale_avail(struct device *dev, · 7 unmodified lines
663669 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
664670 struct st_sensor_data *sdata = iio_priv(indio_dev);
665671
666− mutex_lock(&indio_dev->mlock);
667672 for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
668673 if (sdata->sensor_settings->fs.fs_avl[i].num == 0)
669674 break;
@@ -673,7 +678,6 @@ ssize_t st_sensors_sysfs_scale_avail(struct device *dev, · 3 unmodified lines
673678
674679 len += scnprintf(buf + len, PAGE_SIZE - len, "%u.%06u ", q, r);
675680 }
676− mutex_unlock(&indio_dev->mlock);
677681 buf[len - 1] = '\n';
678682
679683 return len;
drivers/iio/dac/Kconfig+1−3
@@ -285,7 +285,6 @@ config CIO_DAC · 284 unmodified lines
285285
286286 config DPOT_DAC
287287 tristate "DAC emulation using a DPOT"
288− depends on OF
289288 help
290289 Say yes here to build support for DAC emulation using a digital
291290 potentiometer.
@@ -305,7 +304,7 @@ config DS4424 · 13 unmodified lines
305304 config LPC18XX_DAC
306305 tristate "NXP LPC18xx DAC driver"
307306 depends on ARCH_LPC18XX || COMPILE_TEST
308− depends on OF && HAS_IOMEM
307+ depends on HAS_IOMEM
309308 help
310309 Say yes here to build support for NXP LPC18XX DAC.
311310
@@ -442,7 +441,6 @@ config TI_DAC7612 · 130 unmodified lines
442441
443442 config VF610_DAC
444443 tristate "Vybrid vf610 DAC driver"
445− depends on OF
446444 depends on HAS_IOMEM
447445 help
448446 Say yes here to support Vybrid board digital-to-analog converter.
drivers/iio/dac/ad5064.c+1−1
@@ -288,7 +288,7 @@ static ssize_t ad5064_write_dac_powerdown(struct iio_dev *indio_dev, · 287 unmodified lines
288288 bool pwr_down;
289289 int ret;
290290
291− ret = strtobool(buf, &pwr_down);
291+ ret = kstrtobool(buf, &pwr_down);
292292 if (ret)
293293 return ret;
294294
drivers/iio/dac/ad5360.c+1−1
@@ -284,7 +284,7 @@ static ssize_t ad5360_write_dac_powerdown(struct device *dev, · 283 unmodified lines
284284 bool pwr_down;
285285 int ret;
286286
287− ret = strtobool(buf, &pwr_down);
287+ ret = kstrtobool(buf, &pwr_down);
288288 if (ret)
289289 return ret;
290290
drivers/iio/dac/ad5380.c+1−1
@@ -96,7 +96,7 @@ static ssize_t ad5380_write_dac_powerdown(struct iio_dev *indio_dev, · 95 unmodified lines
9696 bool pwr_down;
9797 int ret;
9898
99− ret = strtobool(buf, &pwr_down);
99+ ret = kstrtobool(buf, &pwr_down);
100100 if (ret)
101101 return ret;
102102
drivers/iio/dac/ad5446.c+1−1
@@ -114,7 +114,7 @@ static ssize_t ad5446_write_dac_powerdown(struct iio_dev *indio_dev, · 113 unmodified lines
114114 bool powerdown;
115115 int ret;
116116
117− ret = strtobool(buf, &powerdown);
117+ ret = kstrtobool(buf, &powerdown);
118118 if (ret)
119119 return ret;
120120
drivers/iio/dac/ad5504.c+1−1
@@ -182,7 +182,7 @@ static ssize_t ad5504_write_dac_powerdown(struct iio_dev *indio_dev, · 181 unmodified lines
182182 int ret;
183183 struct ad5504_state *st = iio_priv(indio_dev);
184184
185− ret = strtobool(buf, &pwr_down);
185+ ret = kstrtobool(buf, &pwr_down);
186186 if (ret)
187187 return ret;
188188
drivers/iio/dac/ad5624r_spi.c+1−1
@@ -129,7 +129,7 @@ static ssize_t ad5624r_write_dac_powerdown(struct iio_dev *indio_dev, · 128 unmodified lines
129129 int ret;
130130 struct ad5624r_state *st = iio_priv(indio_dev);
131131
132− ret = strtobool(buf, &pwr_down);
132+ ret = kstrtobool(buf, &pwr_down);
133133 if (ret)
134134 return ret;
135135
drivers/iio/dac/ad5686.c+1−1
@@ -73,7 +73,7 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev, · 72 unmodified lines
7373 unsigned int val, ref_bit_msk;
7474 u8 shift, address = 0;
7575
76− ret = strtobool(buf, &readin);
76+ ret = kstrtobool(buf, &readin);
7777 if (ret)
7878 return ret;
7979
drivers/iio/dac/ad5755.c+1−1
@@ -502,7 +502,7 @@ static ssize_t ad5755_write_powerdown(struct iio_dev *indio_dev, uintptr_t priv, · 501 unmodified lines
502502 bool pwr_down;
503503 int ret;
504504
505− ret = strtobool(buf, &pwr_down);
505+ ret = kstrtobool(buf, &pwr_down);
506506 if (ret)
507507 return ret;
508508
drivers/iio/dac/ad5791.c+1−1
@@ -188,7 +188,7 @@ static ssize_t ad5791_write_dac_powerdown(struct iio_dev *indio_dev, · 187 unmodified lines
188188 int ret;
189189 struct ad5791_state *st = iio_priv(indio_dev);
190190
191− ret = strtobool(buf, &pwr_down);
191+ ret = kstrtobool(buf, &pwr_down);
192192 if (ret)
193193 return ret;
194194
drivers/iio/dac/ad7303.c+1−1
@@ -77,7 +77,7 @@ static ssize_t ad7303_write_dac_powerdown(struct iio_dev *indio_dev, · 76 unmodified lines
7777 bool pwr_down;
7878 int ret;
7979
80− ret = strtobool(buf, &pwr_down);
80+ ret = kstrtobool(buf, &pwr_down);
8181 if (ret)
8282 return ret;
8383
drivers/iio/dac/ltc2632.c+4−4
@@ -10,6 +10,7 @@ · 9 unmodified lines
1010 #include <linux/spi/spi.h>
1111 #include <linux/module.h>
1212 #include <linux/iio/iio.h>
13+#include <linux/property.h>
1314 #include <linux/regulator/consumer.h>
1415
1516 #include <asm/unaligned.h>
@@ -149,7 +150,7 @@ static ssize_t ltc2632_write_dac_powerdown(struct iio_dev *indio_dev, · 133 unmodified lines
149150 int ret;
150151 struct ltc2632_state *st = iio_priv(indio_dev);
151152
152− ret = strtobool(buf, &pwr_down);
153+ ret = kstrtobool(buf, &pwr_down);
153154 if (ret)
154155 return ret;
155156
@@ -362,8 +363,7 @@ static int ltc2632_probe(struct spi_device *spi) · 206 unmodified lines
362363 }
363364 }
364365
365− indio_dev->name = dev_of_node(&spi->dev) ? dev_of_node(&spi->dev)->name
366− : spi_get_device_id(spi)->name;
366+ indio_dev->name = fwnode_get_name(dev_fwnode(&spi->dev)) ?: spi_get_device_id(spi)->name;
367367 indio_dev->info = &ltc2632_info;
368368 indio_dev->modes = INDIO_DIRECT_MODE;
369369 indio_dev->channels = chip_info->channels;
@@ -469,7 +469,7 @@ MODULE_DEVICE_TABLE(of, ltc2632_of_match); · 99 unmodified lines
469469 static struct spi_driver ltc2632_driver = {
470470 .driver = {
471471 .name = "ltc2632",
472− .of_match_table = of_match_ptr(ltc2632_of_match),
472+ .of_match_table = ltc2632_of_match,
473473 },
474474 .probe = ltc2632_probe,
475475 .remove = ltc2632_remove,
drivers/iio/dac/ltc2688.c+9−10
@@ -703,21 +703,20 @@ static int ltc2688_tgp_clk_setup(struct ltc2688_state *st, · 702 unmodified lines
703703 struct ltc2688_chan *chan,
704704 struct fwnode_handle *node, int tgp)
705705 {
706+ struct device *dev = &st->spi->dev;
706707 unsigned long rate;
707708 struct clk *clk;
708709 int ret, f;
709710
710− clk = devm_get_clk_from_child(&st->spi->dev, to_of_node(node), NULL);
711+ clk = devm_get_clk_from_child(dev, to_of_node(node), NULL);
711712 if (IS_ERR(clk))
712− return dev_err_probe(&st->spi->dev, PTR_ERR(clk),
713− "failed to get tgp clk.\n");
713+ return dev_err_probe(dev, PTR_ERR(clk), "failed to get tgp clk.\n");
714714
715715 ret = clk_prepare_enable(clk);
716716 if (ret)
717− return dev_err_probe(&st->spi->dev, ret,
718− "failed to enable tgp clk.\n");
717+ return dev_err_probe(dev, ret, "failed to enable tgp clk.\n");
719718
720− ret = devm_add_action_or_reset(&st->spi->dev, ltc2688_clk_disable, clk);
719+ ret = devm_add_action_or_reset(dev, ltc2688_clk_disable, clk);
721720 if (ret)
722721 return ret;
723722
@@ -858,6 +857,7 @@ static int ltc2688_channel_config(struct ltc2688_state *st) · 134 unmodified lines
858857
859858 static int ltc2688_setup(struct ltc2688_state *st, struct regulator *vref)
860859 {
860+ struct device *dev = &st->spi->dev;
861861 struct gpio_desc *gpio;
862862 int ret;
863863
@@ -865,10 +865,9 @@ static int ltc2688_setup(struct ltc2688_state *st, struct regulator *vref) · 1 unmodified line
865865 * If we have a reset pin, use that to reset the board, If not, use
866866 * the reset bit.
867867 */
868− gpio = devm_gpiod_get_optional(&st->spi->dev, "clr", GPIOD_OUT_HIGH);
868+ gpio = devm_gpiod_get_optional(dev, "clr", GPIOD_OUT_HIGH);
869869 if (IS_ERR(gpio))
870− return dev_err_probe(&st->spi->dev, PTR_ERR(gpio),
871− "Failed to get reset gpio");
870+ return dev_err_probe(dev, PTR_ERR(gpio), "Failed to get reset gpio");
872871 if (gpio) {
873872 usleep_range(1000, 1200);
874873 /* bring device out of reset */
@@ -887,7 +886,7 @@ static int ltc2688_setup(struct ltc2688_state *st, struct regulator *vref) · 12 unmodified lines
887886 * Duplicate the default channel configuration as it can change during
888887 * @ltc2688_channel_config()
889888 */
890− st->iio_chan = devm_kmemdup(&st->spi->dev, ltc2688_channels,
889+ st->iio_chan = devm_kmemdup(dev, ltc2688_channels,
891890 sizeof(ltc2688_channels), GFP_KERNEL);
892891 if (!st->iio_chan)
893892 return -ENOMEM;
drivers/iio/dac/max5821.c+1−1
@@ -116,7 +116,7 @@ static ssize_t max5821_write_dac_powerdown(struct iio_dev *indio_dev, · 115 unmodified lines
116116 bool powerdown;
117117 int ret;
118118
119− ret = strtobool(buf, &powerdown);
119+ ret = kstrtobool(buf, &powerdown);
120120 if (ret)
121121 return ret;
122122
drivers/iio/dac/mcp4725.c+2−2
@@ -80,7 +80,7 @@ static ssize_t mcp4725_store_eeprom(struct device *dev, · 79 unmodified lines
8080 bool state;
8181 int ret;
8282
83− ret = strtobool(buf, &state);
83+ ret = kstrtobool(buf, &state);
8484 if (ret < 0)
8585 return ret;
8686
@@ -178,7 +178,7 @@ static ssize_t mcp4725_write_powerdown(struct iio_dev *indio_dev, · 91 unmodified lines
178178 bool state;
179179 int ret;
180180
181− ret = strtobool(buf, &state);
181+ ret = kstrtobool(buf, &state);
182182 if (ret)
183183 return ret;
184184
drivers/iio/dac/stm32-dac.c+1−1
@@ -220,7 +220,7 @@ static ssize_t stm32_dac_write_powerdown(struct iio_dev *indio_dev, · 219 unmodified lines
220220 bool powerdown;
221221 int ret;
222222
223− ret = strtobool(buf, &powerdown);
223+ ret = kstrtobool(buf, &powerdown);
224224 if (ret)
225225 return ret;
226226
drivers/iio/dac/ti-dac082s085.c+1−1
@@ -133,7 +133,7 @@ static ssize_t ti_dac_write_powerdown(struct iio_dev *indio_dev, · 132 unmodified lines
133133 bool powerdown;
134134 int ret;
135135
136− ret = strtobool(buf, &powerdown);
136+ ret = kstrtobool(buf, &powerdown);
137137 if (ret)
138138 return ret;
139139
drivers/iio/dac/ti-dac5571.c+1−1
@@ -179,7 +179,7 @@ static ssize_t dac5571_write_powerdown(struct iio_dev *indio_dev, · 178 unmodified lines
179179 bool powerdown;
180180 int ret;
181181
182− ret = strtobool(buf, &powerdown);
182+ ret = kstrtobool(buf, &powerdown);
183183 if (ret)
184184 return ret;
185185
drivers/iio/dac/ti-dac7311.c+1−1
@@ -123,7 +123,7 @@ static ssize_t ti_dac_write_powerdown(struct iio_dev *indio_dev, · 122 unmodified lines
123123 u8 power;
124124 int ret;
125125
126− ret = strtobool(buf, &powerdown);
126+ ret = kstrtobool(buf, &powerdown);
127127 if (ret)
128128 return ret;
129129
drivers/iio/dummy/iio_simple_dummy.c+12−8
@@ -575,10 +575,9 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) · 574 unmodified lines
575575 */
576576
577577 swd = kzalloc(sizeof(*swd), GFP_KERNEL);
578− if (!swd) {
579− ret = -ENOMEM;
580− goto error_kzalloc;
581− }
578+ if (!swd)
579+ return ERR_PTR(-ENOMEM);
580+
582581 /*
583582 * Allocate an IIO device.
584583 *
@@ -590,7 +589,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) · 5 unmodified lines
590589 indio_dev = iio_device_alloc(parent, sizeof(*st));
591590 if (!indio_dev) {
592591 ret = -ENOMEM;
593− goto error_ret;
592+ goto error_free_swd;
594593 }
595594
596595 st = iio_priv(indio_dev);
@@ -616,6 +615,10 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) · 19 unmodified lines
616615 * indio_dev->name = spi_get_device_id(spi)->name;
617616 */
618617 indio_dev->name = kstrdup(name, GFP_KERNEL);
618+ if (!indio_dev->name) {
619+ ret = -ENOMEM;
620+ goto error_free_device;
621+ }
619622
620623 /* Provide description of available channels */
621624 indio_dev->channels = iio_dummy_channels;
@@ -632,7 +635,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) · 10 unmodified lines
632635
633636 ret = iio_simple_dummy_events_register(indio_dev);
634637 if (ret < 0)
635− goto error_free_device;
638+ goto error_free_name;
636639
637640 ret = iio_simple_dummy_configure_buffer(indio_dev);
638641 if (ret < 0)
@@ -649,11 +652,12 @@ error_unconfigure_buffer: · 10 unmodified lines
649652 iio_simple_dummy_unconfigure_buffer(indio_dev);
650653 error_unregister_events:
651654 iio_simple_dummy_events_unregister(indio_dev);
655+error_free_name:
656+ kfree(indio_dev->name);
652657 error_free_device:
653658 iio_device_free(indio_dev);
654−error_ret:
659+error_free_swd:
655660 kfree(swd);
656−error_kzalloc:
657661 return ERR_PTR(ret);
658662 }
659663
drivers/iio/frequency/ad9523.c+1−1
@@ -516,7 +516,7 @@ static ssize_t ad9523_store(struct device *dev, · 515 unmodified lines
516516 bool state;
517517 int ret;
518518
519− ret = strtobool(buf, &state);
519+ ret = kstrtobool(buf, &state);
520520 if (ret < 0)
521521 return ret;
522522
drivers/iio/gyro/fxas21002c_core.c+3−5
@@ -7,9 +7,9 @@ · 6 unmodified lines
77
88 #include <linux/interrupt.h>
99 #include <linux/module.h>
10−#include <linux/of_irq.h>
1110 #include <linux/pm.h>
1211 #include <linux/pm_runtime.h>
12+#include <linux/property.h>
1313 #include <linux/regmap.h>
1414 #include <linux/regulator/consumer.h>
1515
@@ -822,7 +822,6 @@ static int fxas21002c_trigger_probe(struct fxas21002c_data *data) · 806 unmodified lines
822822 {
823823 struct device *dev = regmap_get_device(data->regmap);
824824 struct iio_dev *indio_dev = dev_get_drvdata(dev);
825− struct device_node *np = indio_dev->dev.of_node;
826825 unsigned long irq_trig;
827826 bool irq_open_drain;
828827 int irq1;
@@ -831,8 +830,7 @@ static int fxas21002c_trigger_probe(struct fxas21002c_data *data) · 2 unmodified lines
831830 if (!data->irq)
832831 return 0;
833832
834− irq1 = of_irq_get_byname(np, "INT1");
835−
833+ irq1 = fwnode_irq_get_byname(dev_fwnode(dev), "INT1");
836834 if (irq1 == data->irq) {
837835 dev_info(dev, "using interrupt line INT1\n");
838836 ret = regmap_field_write(data->regmap_fields[F_INT_CFG_DRDY],
@@ -843,7 +841,7 @@ static int fxas21002c_trigger_probe(struct fxas21002c_data *data) · 4 unmodified lines
843841
844842 dev_info(dev, "using interrupt line INT2\n");
845843
846− irq_open_drain = of_property_read_bool(np, "drive-open-drain");
844+ irq_open_drain = device_property_read_bool(dev, "drive-open-drain");
847845
848846 data->dready_trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
849847 indio_dev->name,
drivers/iio/gyro/mpu3050-core.c+6−8
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #include <linux/interrupt.h>
2727 #include <linux/module.h>
2828 #include <linux/pm_runtime.h>
29+#include <linux/property.h>
2930 #include <linux/random.h>
3031 #include <linux/slab.h>
3132
@@ -1050,6 +1051,7 @@ static const struct iio_trigger_ops mpu3050_trigger_ops = { · 1018 unmodified lines
10501051 static int mpu3050_trigger_probe(struct iio_dev *indio_dev, int irq)
10511052 {
10521053 struct mpu3050 *mpu3050 = iio_priv(indio_dev);
1054+ struct device *dev = mpu3050->dev;
10531055 unsigned long irq_trig;
10541056 int ret;
10551057
@@ -1061,8 +1063,7 @@ static int mpu3050_trigger_probe(struct iio_dev *indio_dev, int irq) · 5 unmodified lines
10611063 return -ENOMEM;
10621064
10631065 /* Check if IRQ is open drain */
1064− if (of_property_read_bool(mpu3050->dev->of_node, "drive-open-drain"))
1065− mpu3050->irq_opendrain = true;
1066+ mpu3050->irq_opendrain = device_property_read_bool(dev, "drive-open-drain");
10661067
10671068 irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq));
10681069 /*
@@ -1118,13 +1119,12 @@ static int mpu3050_trigger_probe(struct iio_dev *indio_dev, int irq) · 49 unmodified lines
11181119 mpu3050->trig->name,
11191120 mpu3050->trig);
11201121 if (ret) {
1121− dev_err(mpu3050->dev,
1122− "can't get IRQ %d, error %d\n", irq, ret);
1122+ dev_err(dev, "can't get IRQ %d, error %d\n", irq, ret);
11231123 return ret;
11241124 }
11251125
11261126 mpu3050->irq = irq;
1127− mpu3050->trig->dev.parent = mpu3050->dev;
1127+ mpu3050->trig->dev.parent = dev;
11281128 mpu3050->trig->ops = &mpu3050_trigger_ops;
11291129 iio_trigger_set_drvdata(mpu3050->trig, indio_dev);
11301130
@@ -1263,7 +1263,7 @@ err_power_down: · 132 unmodified lines
12631263 }
12641264 EXPORT_SYMBOL(mpu3050_common_probe);
12651265
1266−int mpu3050_common_remove(struct device *dev)
1266+void mpu3050_common_remove(struct device *dev)
12671267 {
12681268 struct iio_dev *indio_dev = dev_get_drvdata(dev);
12691269 struct mpu3050 *mpu3050 = iio_priv(indio_dev);
@@ -1276,8 +1276,6 @@ int mpu3050_common_remove(struct device *dev) · 6 unmodified lines
12761276 free_irq(mpu3050->irq, mpu3050);
12771277 iio_device_unregister(indio_dev);
12781278 mpu3050_power_down(mpu3050);
1279−
1280− return 0;
12811279 }
12821280 EXPORT_SYMBOL(mpu3050_common_remove);
12831281
drivers/iio/gyro/mpu3050-i2c.c+3−1
@@ -86,7 +86,9 @@ static int mpu3050_i2c_remove(struct i2c_client *client) · 85 unmodified lines
8686 if (mpu3050->i2cmux)
8787 i2c_mux_del_adapters(mpu3050->i2cmux);
8888
89− return mpu3050_common_remove(&client->dev);
89+ mpu3050_common_remove(&client->dev);
90+
91+ return 0;
9092 }
9193
9294 /*
drivers/iio/gyro/mpu3050.h+1−1
@@ -91,7 +91,7 @@ int mpu3050_common_probe(struct device *dev, · 90 unmodified lines
9191 struct regmap *map,
9292 int irq,
9393 const char *name);
94−int mpu3050_common_remove(struct device *dev);
94+void mpu3050_common_remove(struct device *dev);
9595
9696 /* PM ops */
9797 extern const struct dev_pm_ops mpu3050_dev_pm_ops;
drivers/iio/gyro/ssp_gyro_sensor.c+0−1
@@ -113,7 +113,6 @@ static int ssp_gyro_probe(struct platform_device *pdev) · 112 unmodified lines
113113 indio_dev->available_scan_masks = ssp_gyro_scan_mask;
114114
115115 ret = devm_iio_kfifo_buffer_setup(&pdev->dev, indio_dev,
116− INDIO_BUFFER_SOFTWARE,
117116 &ssp_gyro_buffer_ops);
118117 if (ret)
119118 return ret;
drivers/iio/gyro/st_gyro_core.c+4−11
@@ -406,24 +406,17 @@ read_error: · 405 unmodified lines
406406 static int st_gyro_write_raw(struct iio_dev *indio_dev,
407407 struct iio_chan_spec const *chan, int val, int val2, long mask)
408408 {
409− int err;
410−
411409 switch (mask) {
412410 case IIO_CHAN_INFO_SCALE:
413− err = st_sensors_set_fullscale_by_gain(indio_dev, val2);
414− break;
411+ return st_sensors_set_fullscale_by_gain(indio_dev, val2);
415412 case IIO_CHAN_INFO_SAMP_FREQ:
416413 if (val2)
417414 return -EINVAL;
418− mutex_lock(&indio_dev->mlock);
419− err = st_sensors_set_odr(indio_dev, val);
420− mutex_unlock(&indio_dev->mlock);
421− return err;
415+
416+ return st_sensors_set_odr(indio_dev, val);
422417 default:
423− err = -EINVAL;
418+ return -EINVAL;
424419 }
425−
426− return err;
427420 }
428421
429422 static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
drivers/iio/health/max30100.c+0−1
@@ -433,7 +433,6 @@ static int max30100_probe(struct i2c_client *client, · 432 unmodified lines
433433 indio_dev->modes = INDIO_DIRECT_MODE;
434434
435435 ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
436− INDIO_BUFFER_SOFTWARE,
437436 &max30100_buffer_setup_ops);
438437 if (ret)
439438 return ret;
drivers/iio/health/max30102.c+0−1
@@ -542,7 +542,6 @@ static int max30102_probe(struct i2c_client *client, · 541 unmodified lines
542542 }
543543
544544 ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
545− INDIO_BUFFER_SOFTWARE,
546545 &max30102_buffer_setup_ops);
547546 if (ret)
548547 return ret;
drivers/iio/imu/adis16480.c+43−48
@@ -7,14 +7,16 @@ · 6 unmodified lines
77
88 #include <linux/clk.h>
99 #include <linux/bitfield.h>
10−#include <linux/of_irq.h>
1110 #include <linux/interrupt.h>
11+#include <linux/irq.h>
1212 #include <linux/math.h>
1313 #include <linux/device.h>
1414 #include <linux/kernel.h>
1515 #include <linux/spi/spi.h>
16+#include <linux/mod_devicetable.h>
1617 #include <linux/module.h>
1718 #include <linux/lcm.h>
19+#include <linux/property.h>
1820 #include <linux/swab.h>
1921 #include <linux/crc32.h>
2022
@@ -1119,6 +1121,7 @@ static irqreturn_t adis16480_trigger_handler(int irq, void *p) · 1098 unmodified lines
11191121 struct iio_dev *indio_dev = pf->indio_dev;
11201122 struct adis16480 *st = iio_priv(indio_dev);
11211123 struct adis *adis = &st->adis;
1124+ struct device *dev = &adis->spi->dev;
11221125 int ret, bit, offset, i = 0;
11231126 __be16 *buffer;
11241127 u32 crc;
@@ -1130,7 +1133,7 @@ static irqreturn_t adis16480_trigger_handler(int irq, void *p) · 5 unmodified lines
11301133 adis->tx[1] = 0;
11311134 ret = spi_write(adis->spi, adis->tx, 2);
11321135 if (ret) {
1133− dev_err(&adis->spi->dev, "Failed to change device page: %d\n", ret);
1136+ dev_err(dev, "Failed to change device page: %d\n", ret);
11341137 adis_dev_unlock(adis);
11351138 goto irq_done;
11361139 }
@@ -1140,7 +1143,7 @@ static irqreturn_t adis16480_trigger_handler(int irq, void *p) · 3 unmodified lines
11401143
11411144 ret = spi_sync(adis->spi, &adis->msg);
11421145 if (ret) {
1143− dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret);
1146+ dev_err(dev, "Failed to read data: %d\n", ret);
11441147 adis_dev_unlock(adis);
11451148 goto irq_done;
11461149 }
@@ -1168,14 +1171,14 @@ static irqreturn_t adis16480_trigger_handler(int irq, void *p) · 21 unmodified lines
11681171 }
11691172
11701173 if (offset == 4) {
1171− dev_err(&adis->spi->dev, "Invalid burst data\n");
1174+ dev_err(dev, "Invalid burst data\n");
11721175 goto irq_done;
11731176 }
11741177
11751178 crc = be16_to_cpu(buffer[offset + 16]) << 16 | be16_to_cpu(buffer[offset + 15]);
11761179 valid = adis16480_validate_crc((u16 *)&buffer[offset], 15, crc);
11771180 if (!valid) {
1178− dev_err(&adis->spi->dev, "Invalid crc\n");
1181+ dev_err(dev, "Invalid crc\n");
11791182 goto irq_done;
11801183 }
11811184
@@ -1214,12 +1217,12 @@ static const struct iio_info adis16480_info = { · 32 unmodified lines
12141217 static int adis16480_stop_device(struct iio_dev *indio_dev)
12151218 {
12161219 struct adis16480 *st = iio_priv(indio_dev);
1220+ struct device *dev = &st->adis.spi->dev;
12171221 int ret;
12181222
12191223 ret = adis_write_reg_16(&st->adis, ADIS16480_REG_SLP_CNT, BIT(9));
12201224 if (ret)
1221− dev_err(&indio_dev->dev,
1222− "Could not power down device: %d\n", ret);
1225+ dev_err(dev, "Could not power down device: %d\n", ret);
12231226
12241227 return ret;
12251228 }
@@ -1239,9 +1242,10 @@ static int adis16480_enable_irq(struct adis *adis, bool enable) · 13 unmodified lines
12391242 return __adis_write_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL, val);
12401243 }
12411244
1242−static int adis16480_config_irq_pin(struct device_node *of_node,
1243− struct adis16480 *st)
1245+static int adis16480_config_irq_pin(struct adis16480 *st)
12441246 {
1247+ struct device *dev = &st->adis.spi->dev;
1248+ struct fwnode_handle *fwnode = dev_fwnode(dev);
12451249 struct irq_data *desc;
12461250 enum adis16480_int_pin pin;
12471251 unsigned int irq_type;
@@ -1250,7 +1254,7 @@ static int adis16480_config_irq_pin(struct device_node *of_node, · 2 unmodified lines
12501254
12511255 desc = irq_get_irq_data(st->adis.spi->irq);
12521256 if (!desc) {
1253− dev_err(&st->adis.spi->dev, "Could not find IRQ %d\n", irq);
1257+ dev_err(dev, "Could not find IRQ %d\n", irq);
12541258 return -EINVAL;
12551259 }
12561260
@@ -1267,7 +1271,7 @@ static int adis16480_config_irq_pin(struct device_node *of_node, · 10 unmodified lines
12671271 */
12681272 pin = ADIS16480_PIN_DIO1;
12691273 for (i = 0; i < ARRAY_SIZE(adis16480_int_pin_names); i++) {
1270− irq = of_irq_get_byname(of_node, adis16480_int_pin_names[i]);
1274+ irq = fwnode_irq_get_byname(fwnode, adis16480_int_pin_names[i]);
12711275 if (irq > 0) {
12721276 pin = i;
12731277 break;
@@ -1287,23 +1291,22 @@ static int adis16480_config_irq_pin(struct device_node *of_node, · 13 unmodified lines
12871291 } else if (irq_type == IRQ_TYPE_EDGE_FALLING) {
12881292 val |= ADIS16480_DRDY_POL(0);
12891293 } else {
1290− dev_err(&st->adis.spi->dev,
1291− "Invalid interrupt type 0x%x specified\n", irq_type);
1294+ dev_err(dev, "Invalid interrupt type 0x%x specified\n", irq_type);
12921295 return -EINVAL;
12931296 }
12941297 /* Write the data ready configuration to the FNCTIO_CTRL register */
12951298 return adis_write_reg_16(&st->adis, ADIS16480_REG_FNCTIO_CTRL, val);
12961299 }
12971300
1298−static int adis16480_of_get_ext_clk_pin(struct adis16480 *st,
1299− struct device_node *of_node)
1301+static int adis16480_fw_get_ext_clk_pin(struct adis16480 *st)
13001302 {
1303+ struct device *dev = &st->adis.spi->dev;
13011304 const char *ext_clk_pin;
13021305 enum adis16480_int_pin pin;
13031306 int i;
13041307
13051308 pin = ADIS16480_PIN_DIO2;
1306− if (of_property_read_string(of_node, "adi,ext-clk-pin", &ext_clk_pin))
1309+ if (device_property_read_string(dev, "adi,ext-clk-pin", &ext_clk_pin))
13071310 goto clk_input_not_found;
13081311
13091312 for (i = 0; i < ARRAY_SIZE(adis16480_int_pin_names); i++) {
@@ -1312,15 +1315,13 @@ static int adis16480_of_get_ext_clk_pin(struct adis16480 *st, · 2 unmodified lines
13121315 }
13131316
13141317 clk_input_not_found:
1315− dev_info(&st->adis.spi->dev,
1316− "clk input line not specified, using DIO2\n");
1318+ dev_info(dev, "clk input line not specified, using DIO2\n");
13171319 return pin;
13181320 }
13191321
1320−static int adis16480_ext_clk_config(struct adis16480 *st,
1321− struct device_node *of_node,
1322− bool enable)
1322+static int adis16480_ext_clk_config(struct adis16480 *st, bool enable)
13231323 {
1324+ struct device *dev = &st->adis.spi->dev;
13241325 unsigned int mode, mask;
13251326 enum adis16480_int_pin pin;
13261327 uint16_t val;
@@ -1330,16 +1331,14 @@ static int adis16480_ext_clk_config(struct adis16480 *st, · 3 unmodified lines
13301331 if (ret)
13311332 return ret;
13321333
1333− pin = adis16480_of_get_ext_clk_pin(st, of_node);
1334+ pin = adis16480_fw_get_ext_clk_pin(st);
13341335 /*
13351336 * Each DIOx pin supports only one function at a time. When a single pin
13361337 * has two assignments, the enable bit for a lower priority function
13371338 * automatically resets to zero (disabling the lower priority function).
13381339 */
13391340 if (pin == ADIS16480_DRDY_SEL(val))
1340− dev_warn(&st->adis.spi->dev,
1341− "DIO%x pin supports only one function at a time\n",
1342− pin + 1);
1341+ dev_warn(dev, "DIO%x pin supports only one function at a time\n", pin + 1);
13431342
13441343 mode = ADIS16480_SYNC_EN(enable) | ADIS16480_SYNC_SEL(pin);
13451344 mask = ADIS16480_SYNC_EN_MSK | ADIS16480_SYNC_SEL_MSK;
@@ -1361,31 +1360,27 @@ static int adis16480_ext_clk_config(struct adis16480 *st, · 15 unmodified lines
13611360
13621361 static int adis16480_get_ext_clocks(struct adis16480 *st)
13631362 {
1364− st->clk_mode = ADIS16480_CLK_INT;
1365− st->ext_clk = devm_clk_get(&st->adis.spi->dev, "sync");
1366− if (!IS_ERR_OR_NULL(st->ext_clk)) {
1363+ struct device *dev = &st->adis.spi->dev;
1364+
1365+ st->ext_clk = devm_clk_get_optional(dev, "sync");
1366+ if (IS_ERR(st->ext_clk))
1367+ return dev_err_probe(dev, PTR_ERR(st->ext_clk), "failed to get ext clk\n");
1368+ if (st->ext_clk) {
13671369 st->clk_mode = ADIS16480_CLK_SYNC;
13681370 return 0;
13691371 }
13701372
1371− if (PTR_ERR(st->ext_clk) != -ENOENT) {
1372− dev_err(&st->adis.spi->dev, "failed to get ext clk\n");
1373− return PTR_ERR(st->ext_clk);
1374− }
1375−
13761373 if (st->chip_info->has_pps_clk_mode) {
1377− st->ext_clk = devm_clk_get(&st->adis.spi->dev, "pps");
1378− if (!IS_ERR_OR_NULL(st->ext_clk)) {
1374+ st->ext_clk = devm_clk_get_optional(dev, "pps");
1375+ if (IS_ERR(st->ext_clk))
1376+ return dev_err_probe(dev, PTR_ERR(st->ext_clk), "failed to get ext clk\n");
1377+ if (st->ext_clk) {
13791378 st->clk_mode = ADIS16480_CLK_PPS;
13801379 return 0;
13811380 }
1382−
1383− if (PTR_ERR(st->ext_clk) != -ENOENT) {
1384− dev_err(&st->adis.spi->dev, "failed to get ext clk\n");
1385− return PTR_ERR(st->ext_clk);
1386− }
13871381 }
13881382
1383+ st->clk_mode = ADIS16480_CLK_INT;
13891384 return 0;
13901385 }
13911386
@@ -1404,11 +1399,12 @@ static int adis16480_probe(struct spi_device *spi) · 12 unmodified lines
14041399 const struct spi_device_id *id = spi_get_device_id(spi);
14051400 const struct adis_data *adis16480_data;
14061401 irq_handler_t trigger_handler = NULL;
1402+ struct device *dev = &spi->dev;
14071403 struct iio_dev *indio_dev;
14081404 struct adis16480 *st;
14091405 int ret;
14101406
1411− indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
1407+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
14121408 if (indio_dev == NULL)
14131409 return -ENOMEM;
14141410
@@ -1432,13 +1428,12 @@ static int adis16480_probe(struct spi_device *spi) · 17 unmodified lines
14321428 return ret;
14331429
14341430 if (st->chip_info->has_sleep_cnt) {
1435− ret = devm_add_action_or_reset(&spi->dev, adis16480_stop,
1436− indio_dev);
1431+ ret = devm_add_action_or_reset(dev, adis16480_stop, indio_dev);
14371432 if (ret)
14381433 return ret;
14391434 }
14401435
1441− ret = adis16480_config_irq_pin(spi->dev.of_node, st);
1436+ ret = adis16480_config_irq_pin(st);
14421437 if (ret)
14431438 return ret;
14441439
@@ -1446,12 +1441,12 @@ static int adis16480_probe(struct spi_device *spi) · 1 unmodified line
14461441 if (ret)
14471442 return ret;
14481443
1449− if (!IS_ERR_OR_NULL(st->ext_clk)) {
1450− ret = adis16480_ext_clk_config(st, spi->dev.of_node, true);
1444+ if (st->ext_clk) {
1445+ ret = adis16480_ext_clk_config(st, true);
14511446 if (ret)
14521447 return ret;
14531448
1454− ret = devm_add_action_or_reset(&spi->dev, adis16480_clk_disable, st->ext_clk);
1449+ ret = devm_add_action_or_reset(dev, adis16480_clk_disable, st->ext_clk);
14551450 if (ret)
14561451 return ret;
14571452
@@ -1484,7 +1479,7 @@ static int adis16480_probe(struct spi_device *spi) · 26 unmodified lines
14841479 if (ret)
14851480 return ret;
14861481
1487− ret = devm_iio_device_register(&spi->dev, indio_dev);
1482+ ret = devm_iio_device_register(dev, indio_dev);
14881483 if (ret)
14891484 return ret;
14901485
drivers/iio/imu/bmi160/bmi160_core.c+6−21
@@ -11,10 +11,9 @@ · 10 unmodified lines
1111 */
1212 #include <linux/module.h>
1313 #include <linux/regmap.h>
14−#include <linux/acpi.h>
1514 #include <linux/delay.h>
1615 #include <linux/irq.h>
17−#include <linux/of_irq.h>
16+#include <linux/property.h>
1817 #include <linux/regulator/consumer.h>
1918
2019 #include <linux/iio/iio.h>
@@ -525,17 +524,6 @@ static const struct iio_info bmi160_info = { · 504 unmodified lines
525524 .attrs = &bmi160_attrs_group,
526525 };
527526
528−static const char *bmi160_match_acpi_device(struct device *dev)
529−{
530− const struct acpi_device_id *id;
531−
532− id = acpi_match_device(dev->driver->acpi_match_table, dev);
533− if (!id)
534− return NULL;
535−
536− return dev_name(dev);
537−}
538−
539527 static int bmi160_write_conf_reg(struct regmap *regmap, unsigned int reg,
540528 unsigned int mask, unsigned int bits,
541529 unsigned int write_usleep)
@@ -647,18 +635,18 @@ int bmi160_enable_irq(struct regmap *regmap, bool enable) · 105 unmodified lines
647635 }
648636 EXPORT_SYMBOL(bmi160_enable_irq);
649637
650−static int bmi160_get_irq(struct device_node *of_node, enum bmi160_int_pin *pin)
638+static int bmi160_get_irq(struct fwnode_handle *fwnode, enum bmi160_int_pin *pin)
651639 {
652640 int irq;
653641
654642 /* Use INT1 if possible, otherwise fall back to INT2. */
655− irq = of_irq_get_byname(of_node, "INT1");
643+ irq = fwnode_irq_get_byname(fwnode, "INT1");
656644 if (irq > 0) {
657645 *pin = BMI160_PIN_INT1;
658646 return irq;
659647 }
660648
661− irq = of_irq_get_byname(of_node, "INT2");
649+ irq = fwnode_irq_get_byname(fwnode, "INT2");
662650 if (irq > 0)
663651 *pin = BMI160_PIN_INT2;
664652
@@ -688,7 +676,7 @@ static int bmi160_config_device_irq(struct iio_dev *indio_dev, int irq_type, · 23 unmodified lines
688676 return -EINVAL;
689677 }
690678
691− open_drain = of_property_read_bool(dev->of_node, "drive-open-drain");
679+ open_drain = device_property_read_bool(dev, "drive-open-drain");
692680
693681 return bmi160_config_pin(data->regmap, pin, open_drain, irq_mask,
694682 BMI160_NORMAL_WRITE_USLEEP);
@@ -872,9 +860,6 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, · 177 unmodified lines
872860 if (ret)
873861 return ret;
874862
875− if (!name && ACPI_HANDLE(dev))
876− name = bmi160_match_acpi_device(dev);
877−
878863 indio_dev->channels = bmi160_channels;
879864 indio_dev->num_channels = ARRAY_SIZE(bmi160_channels);
880865 indio_dev->name = name;
@@ -887,7 +872,7 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, · 6 unmodified lines
887872 if (ret)
888873 return ret;
889874
890− irq = bmi160_get_irq(dev->of_node, &int_pin);
875+ irq = bmi160_get_irq(dev_fwnode(dev), &int_pin);
891876 if (irq > 0) {
892877 ret = bmi160_setup_irq(indio_dev, irq, int_pin);
893878 if (ret)
drivers/iio/imu/bmi160/bmi160_i2c.c+6−7
@@ -8,10 +8,9 @@ · 7 unmodified lines
88 * - 0x68 if SDO is pulled to GND
99 * - 0x69 if SDO is pulled to VDDIO
1010 */
11−#include <linux/acpi.h>
1211 #include <linux/i2c.h>
12+#include <linux/mod_devicetable.h>
1313 #include <linux/module.h>
14−#include <linux/of.h>
1514 #include <linux/regmap.h>
1615
1716 #include "bmi160.h"
@@ -20,7 +19,7 @@ static int bmi160_i2c_probe(struct i2c_client *client, · 2 unmodified lines
2019 const struct i2c_device_id *id)
2120 {
2221 struct regmap *regmap;
23− const char *name = NULL;
22+ const char *name;
2423
2524 regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config);
2625 if (IS_ERR(regmap)) {
@@ -31,6 +30,8 @@ static int bmi160_i2c_probe(struct i2c_client *client, · 4 unmodified lines
3130
3231 if (id)
3332 name = id->name;
33+ else
34+ name = dev_name(&client->dev);
3435
3536 return bmi160_core_probe(&client->dev, regmap, name, false);
3637 }
@@ -47,19 +48,17 @@ static const struct acpi_device_id bmi160_acpi_match[] = { · 10 unmodified lines
4748 };
4849 MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
4950
50−#ifdef CONFIG_OF
5151 static const struct of_device_id bmi160_of_match[] = {
5252 { .compatible = "bosch,bmi160" },
5353 { },
5454 };
5555 MODULE_DEVICE_TABLE(of, bmi160_of_match);
56−#endif
5756
5857 static struct i2c_driver bmi160_i2c_driver = {
5958 .driver = {
6059 .name = "bmi160_i2c",
61− .acpi_match_table = ACPI_PTR(bmi160_acpi_match),
62− .of_match_table = of_match_ptr(bmi160_of_match),
60+ .acpi_match_table = bmi160_acpi_match,
61+ .of_match_table = bmi160_of_match,
6362 },
6463 .probe = bmi160_i2c_probe,
6564 .id_table = bmi160_i2c_id,
drivers/iio/imu/bmi160/bmi160_spi.c+11−7
@@ -5,9 +5,8 @@ · 4 unmodified lines
55 * Copyright (c) 2016, Intel Corporation.
66 *
77 */
8−#include <linux/acpi.h>
8+#include <linux/mod_devicetable.h>
99 #include <linux/module.h>
10−#include <linux/of.h>
1110 #include <linux/regmap.h>
1211 #include <linux/spi/spi.h>
1312
@@ -17,6 +16,7 @@ static int bmi160_spi_probe(struct spi_device *spi) · 3 unmodified lines
1716 {
1817 struct regmap *regmap;
1918 const struct spi_device_id *id = spi_get_device_id(spi);
19+ const char *name;
2020
2121 regmap = devm_regmap_init_spi(spi, &bmi160_regmap_config);
2222 if (IS_ERR(regmap)) {
@@ -24,7 +24,13 @@ static int bmi160_spi_probe(struct spi_device *spi) · 1 unmodified line
2424 regmap);
2525 return PTR_ERR(regmap);
2626 }
27− return bmi160_core_probe(&spi->dev, regmap, id->name, true);
27+
28+ if (id)
29+ name = id->name;
30+ else
31+ name = dev_name(&spi->dev);
32+
33+ return bmi160_core_probe(&spi->dev, regmap, name, true);
2834 }
2935
3036 static const struct spi_device_id bmi160_spi_id[] = {
@@ -39,20 +45,18 @@ static const struct acpi_device_id bmi160_acpi_match[] = { · 8 unmodified lines
3945 };
4046 MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
4147
42−#ifdef CONFIG_OF
4348 static const struct of_device_id bmi160_of_match[] = {
4449 { .compatible = "bosch,bmi160" },
4550 { },
4651 };
4752 MODULE_DEVICE_TABLE(of, bmi160_of_match);
48−#endif
4953
5054 static struct spi_driver bmi160_spi_driver = {
5155 .probe = bmi160_spi_probe,
5256 .id_table = bmi160_spi_id,
5357 .driver = {
54− .acpi_match_table = ACPI_PTR(bmi160_acpi_match),
55− .of_match_table = of_match_ptr(bmi160_of_match),
58+ .acpi_match_table = bmi160_acpi_match,
59+ .of_match_table = bmi160_of_match,
5660 .name = "bmi160_spi",
5761 },
5862 };
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c+0−1
@@ -731,7 +731,6 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st) · 730 unmodified lines
731731 indio_dev->available_scan_masks = inv_icm42600_accel_scan_masks;
732732
733733 ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
734− INDIO_BUFFER_SOFTWARE,
735734 &inv_icm42600_buffer_ops);
736735 if (ret)
737736 return ERR_PTR(ret);
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c+0−1
@@ -743,7 +743,6 @@ struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st) · 742 unmodified lines
743743 indio_dev->setup_ops = &inv_icm42600_buffer_ops;
744744
745745 ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
746− INDIO_BUFFER_SOFTWARE,
747746 &inv_icm42600_buffer_ops);
748747 if (ret)
749748 return ERR_PTR(ret);
drivers/iio/imu/inv_mpu6050/Kconfig+2−2
@@ -16,7 +16,7 @@ config INV_MPU6050_I2C · 15 unmodified lines
1616 select REGMAP_I2C
1717 help
1818 This driver supports the Invensense MPU6050/9150,
19− MPU6500/6515/6880/9250/9255, ICM20608/20609/20689, ICM20602/ICM20690
19+ MPU6500/6515/6880/9250/9255, ICM20608(D)/20609/20689, ICM20602/ICM20690
2020 and IAM20680 motion tracking devices over I2C.
2121 This driver can be built as a module. The module will be called
2222 inv-mpu6050-i2c.
@@ -28,7 +28,7 @@ config INV_MPU6050_SPI · 5 unmodified lines
2828 select REGMAP_SPI
2929 help
3030 This driver supports the Invensense MPU6000,
31− MPU6500/6515/6880/9250/9255, ICM20608/20609/20689, ICM20602/ICM20690
31+ MPU6500/6515/6880/9250/9255, ICM20608(D)/20609/20689, ICM20602/ICM20690
3232 and IAM20680 motion tracking devices over SPI.
3333 This driver can be built as a module. The module will be called
3434 inv-mpu6050-spi.
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c+9−0
@@ -217,6 +217,15 @@ static const struct inv_mpu6050_hw hw_info[] = { · 216 unmodified lines
217217 .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
218218 .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
219219 },
220+ {
221+ .whoami = INV_ICM20608D_WHOAMI_VALUE,
222+ .name = "ICM20608D",
223+ .reg = &reg_set_6500,
224+ .config = &chip_config_6500,
225+ .fifo_size = 512,
226+ .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
227+ .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME},
228+ },
220229 {
221230 .whoami = INV_ICM20609_WHOAMI_VALUE,
222231 .name = "ICM20609",
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c+6−0
@@ -29,6 +29,7 @@ static bool inv_mpu_i2c_aux_bus(struct device *dev) · 28 unmodified lines
2929
3030 switch (st->chip_type) {
3131 case INV_ICM20608:
32+ case INV_ICM20608D:
3233 case INV_ICM20609:
3334 case INV_ICM20689:
3435 case INV_ICM20602:
@@ -182,6 +183,7 @@ static const struct i2c_device_id inv_mpu_id[] = { · 147 unmodified lines
182183 {"mpu9250", INV_MPU9250},
183184 {"mpu9255", INV_MPU9255},
184185 {"icm20608", INV_ICM20608},
186+ {"icm20608d", INV_ICM20608D},
185187 {"icm20609", INV_ICM20609},
186188 {"icm20689", INV_ICM20689},
187189 {"icm20602", INV_ICM20602},
@@ -225,6 +227,10 @@ static const struct of_device_id inv_of_match[] = { · 37 unmodified lines
225227 .compatible = "invensense,icm20608",
226228 .data = (void *)INV_ICM20608
227229 },
230+ {
231+ .compatible = "invensense,icm20608d",
232+ .data = (void *)INV_ICM20608D
233+ },
228234 {
229235 .compatible = "invensense,icm20609",
230236 .data = (void *)INV_ICM20609
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h+2−0
@@ -76,6 +76,7 @@ enum inv_devices { · 75 unmodified lines
7676 INV_MPU9250,
7777 INV_MPU9255,
7878 INV_ICM20608,
79+ INV_ICM20608D,
7980 INV_ICM20609,
8081 INV_ICM20689,
8182 INV_ICM20602,
@@ -394,6 +395,7 @@ struct inv_mpu6050_state { · 312 unmodified lines
394395 #define INV_MPU9255_WHOAMI_VALUE 0x73
395396 #define INV_MPU6515_WHOAMI_VALUE 0x74
396397 #define INV_ICM20608_WHOAMI_VALUE 0xAF
398+#define INV_ICM20608D_WHOAMI_VALUE 0xAE
397399 #define INV_ICM20609_WHOAMI_VALUE 0xA6
398400 #define INV_ICM20689_WHOAMI_VALUE 0x98
399401 #define INV_ICM20602_WHOAMI_VALUE 0x12
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c+5−0
@@ -73,6 +73,7 @@ static const struct spi_device_id inv_mpu_id[] = { · 72 unmodified lines
7373 {"mpu9250", INV_MPU9250},
7474 {"mpu9255", INV_MPU9255},
7575 {"icm20608", INV_ICM20608},
76+ {"icm20608d", INV_ICM20608D},
7677 {"icm20609", INV_ICM20609},
7778 {"icm20689", INV_ICM20689},
7879 {"icm20602", INV_ICM20602},
@@ -112,6 +113,10 @@ static const struct of_device_id inv_of_match[] = { · 33 unmodified lines
112113 .compatible = "invensense,icm20608",
113114 .data = (void *)INV_ICM20608
114115 },
116+ {
117+ .compatible = "invensense,icm20608d",
118+ .data = (void *)INV_ICM20608D
119+ },
115120 {
116121 .compatible = "invensense,icm20609",
117122 .data = (void *)INV_ICM20609
drivers/iio/imu/st_lsm6dsx/Kconfig+3−3
@@ -11,9 +11,9 @@ config IIO_ST_LSM6DSX · 10 unmodified lines
1111 help
1212 Say yes here to build support for STMicroelectronics LSM6DSx imu
1313 sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm,
14− ism330dlc, lsm6dso, lsm6dsox, asm330lhh, lsm6dsr, lsm6ds3tr-c,
15− ism330dhcx, lsm6dsrx, lsm6ds0, lsm6dsop, the accelerometer/gyroscope
16− of lsm9ds1 and lsm6dst.
14+ ism330dlc, lsm6dso, lsm6dsox, asm330lhh, asm330lhhx, lsm6dsr,
15+ lsm6ds3tr-c, ism330dhcx, lsm6dsrx, lsm6ds0, lsm6dsop,
16+ the accelerometer/gyroscope of lsm9ds1 and lsm6dst.
1717
1818 To compile this driver as a module, choose M here: the module
1919 will be called st_lsm6dsx.
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h+2−0
@@ -31,6 +31,7 @@ · 30 unmodified lines
3131 #define ST_LSM6DSRX_DEV_NAME "lsm6dsrx"
3232 #define ST_LSM6DST_DEV_NAME "lsm6dst"
3333 #define ST_LSM6DSOP_DEV_NAME "lsm6dsop"
34+#define ST_ASM330LHHX_DEV_NAME "asm330lhhx"
3435
3536 enum st_lsm6dsx_hw_id {
3637 ST_LSM6DS3_ID,
@@ -49,6 +50,7 @@ enum st_lsm6dsx_hw_id { · 12 unmodified lines
4950 ST_LSM6DSRX_ID,
5051 ST_LSM6DST_ID,
5152 ST_LSM6DSOP_ID,
53+ ST_ASM330LHHX_ID,
5254 ST_LSM6DSX_MAX_ID,
5355 };
5456
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c+2−2
@@ -14,7 +14,8 @@ · 13 unmodified lines
1414 * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated depending on the
1515 * value of the decimation factor and ODR set for each FIFO data set.
1616 *
17− * LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR/LSM6DSRX/ISM330DHCX/LSM6DST/LSM6DSOP:
17+ * LSM6DSO/LSM6DSOX/ASM330LHH/ASM330LHHX/LSM6DSR/LSM6DSRX/ISM330DHCX/
18+ * LSM6DST/LSM6DSOP:
1819 * The FIFO buffer can be configured to store data from gyroscope and
1920 * accelerometer. Each sample is queued with a tag (1B) indicating data
2021 * source (gyroscope, accelerometer, hw timer).
@@ -746,7 +747,6 @@ int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw) · 725 unmodified lines
746747 continue;
747748
748749 ret = devm_iio_kfifo_buffer_setup(hw->dev, hw->iio_devs[i],
749− INDIO_BUFFER_SOFTWARE,
750750 &st_lsm6dsx_buffer_ops);
751751 if (ret)
752752 return ret;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c+5−1
@@ -26,7 +26,7 @@ · 25 unmodified lines
2626 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
2727 * - FIFO size: 4KB
2828 *
29− * - LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR/ISM330DHCX/LSM6DST/LSM6DSOP:
29+ * - LSM6DSO/LSM6DSOX/ASM330LHH/ASM330LHHX/LSM6DSR/ISM330DHCX/LSM6DST/LSM6DSOP:
3030 * - Accelerometer/Gyroscope supported ODR [Hz]: 12.5, 26, 52, 104, 208, 416,
3131 * 833
3232 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
@@ -786,6 +786,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { · 753 unmodified lines
786786 .hw_id = ST_LSM6DST_ID,
787787 .name = ST_LSM6DST_DEV_NAME,
788788 .wai = 0x6d,
789+ }, {
790+ .hw_id = ST_ASM330LHHX_ID,
791+ .name = ST_ASM330LHHX_DEV_NAME,
792+ .wai = 0x6b,
789793 },
790794 },
791795 .channels = {
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c+5−0
@@ -101,6 +101,10 @@ static const struct of_device_id st_lsm6dsx_i2c_of_match[] = { · 100 unmodified lines
101101 .compatible = "st,lsm6dsop",
102102 .data = (void *)ST_LSM6DSOP_ID,
103103 },
104+ {
105+ .compatible = "st,asm330lhhx",
106+ .data = (void *)ST_ASM330LHHX_ID,
107+ },
104108 {},
105109 };
106110 MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match);
@@ -122,6 +126,7 @@ static const struct i2c_device_id st_lsm6dsx_i2c_id_table[] = { · 15 unmodified lines
122126 { ST_LSM6DSRX_DEV_NAME, ST_LSM6DSRX_ID },
123127 { ST_LSM6DST_DEV_NAME, ST_LSM6DST_ID },
124128 { ST_LSM6DSOP_DEV_NAME, ST_LSM6DSOP_ID },
129+ { ST_ASM330LHHX_DEV_NAME, ST_ASM330LHHX_ID },
125130 {},
126131 };
127132 MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c+5−0
@@ -101,6 +101,10 @@ static const struct of_device_id st_lsm6dsx_spi_of_match[] = { · 100 unmodified lines
101101 .compatible = "st,lsm6dsop",
102102 .data = (void *)ST_LSM6DSOP_ID,
103103 },
104+ {
105+ .compatible = "st,asm330lhhx",
106+ .data = (void *)ST_ASM330LHHX_ID,
107+ },
104108 {},
105109 };
106110 MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match);
@@ -122,6 +126,7 @@ static const struct spi_device_id st_lsm6dsx_spi_id_table[] = { · 15 unmodified lines
122126 { ST_LSM6DSRX_DEV_NAME, ST_LSM6DSRX_ID },
123127 { ST_LSM6DST_DEV_NAME, ST_LSM6DST_ID },
124128 { ST_LSM6DSOP_DEV_NAME, ST_LSM6DSOP_ID },
129+ { ST_ASM330LHHX_DEV_NAME, ST_ASM330LHHX_ID },
125130 {},
126131 };
127132 MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
drivers/iio/industrialio-buffer.c+29−13
@@ -510,7 +510,7 @@ static ssize_t iio_scan_el_store(struct device *dev, · 509 unmodified lines
510510 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
511511 struct iio_buffer *buffer = this_attr->buffer;
512512
513− ret = strtobool(buf, &state);
513+ ret = kstrtobool(buf, &state);
514514 if (ret < 0)
515515 return ret;
516516 mutex_lock(&indio_dev->mlock);
@@ -557,7 +557,7 @@ static ssize_t iio_scan_el_ts_store(struct device *dev, · 40 unmodified lines
557557 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer;
558558 bool state;
559559
560− ret = strtobool(buf, &state);
560+ ret = kstrtobool(buf, &state);
561561 if (ret < 0)
562562 return ret;
563563
@@ -915,7 +915,7 @@ static int iio_verify_update(struct iio_dev *indio_dev, · 351 unmodified lines
915915 if (scan_mask == NULL)
916916 return -EINVAL;
917917 } else {
918− scan_mask = compound_mask;
918+ scan_mask = compound_mask;
919919 }
920920
921921 config->scan_bytes = iio_compute_scan_bytes(indio_dev,
@@ -1059,13 +1059,13 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, · 137 unmodified lines
10591059 struct iio_device_config *config)
10601060 {
10611061 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
1062− struct iio_buffer *buffer;
1062+ struct iio_buffer *buffer, *tmp = NULL;
10631063 int ret;
10641064
10651065 indio_dev->active_scan_mask = config->scan_mask;
10661066 indio_dev->scan_timestamp = config->scan_timestamp;
10671067 indio_dev->scan_bytes = config->scan_bytes;
1068− indio_dev->currentmode = config->mode;
1068+ iio_dev_opaque->currentmode = config->mode;
10691069
10701070 iio_update_demux(indio_dev);
10711071
@@ -1097,11 +1097,13 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, · 25 unmodified lines
10971097
10981098 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) {
10991099 ret = iio_buffer_enable(buffer, indio_dev);
1100− if (ret)
1100+ if (ret) {
1101+ tmp = buffer;
11011102 goto err_disable_buffers;
1103+ }
11021104 }
11031105
1104− if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
1106+ if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) {
11051107 ret = iio_trigger_attach_poll_func(indio_dev->trig,
11061108 indio_dev->pollfunc);
11071109 if (ret)
@@ -1120,11 +1122,12 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, · 12 unmodified lines
11201122 return 0;
11211123
11221124 err_detach_pollfunc:
1123− if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
1125+ if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) {
11241126 iio_trigger_detach_poll_func(indio_dev->trig,
11251127 indio_dev->pollfunc);
11261128 }
11271129 err_disable_buffers:
1130+ buffer = list_prepare_entry(tmp, &iio_dev_opaque->buffer_list, buffer_list);
11281131 list_for_each_entry_continue_reverse(buffer, &iio_dev_opaque->buffer_list,
11291132 buffer_list)
11301133 iio_buffer_disable(buffer, indio_dev);
@@ -1132,7 +1135,7 @@ err_run_postdisable: · 1 unmodified line
11321135 if (indio_dev->setup_ops->postdisable)
11331136 indio_dev->setup_ops->postdisable(indio_dev);
11341137 err_undo_config:
1135− indio_dev->currentmode = INDIO_DIRECT_MODE;
1138+ iio_dev_opaque->currentmode = INDIO_DIRECT_MODE;
11361139 indio_dev->active_scan_mask = NULL;
11371140
11381141 return ret;
@@ -1162,7 +1165,7 @@ static int iio_disable_buffers(struct iio_dev *indio_dev) · 23 unmodified lines
11621165 ret = ret2;
11631166 }
11641167
1165− if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
1168+ if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) {
11661169 iio_trigger_detach_poll_func(indio_dev->trig,
11671170 indio_dev->pollfunc);
11681171 }
@@ -1181,7 +1184,7 @@ static int iio_disable_buffers(struct iio_dev *indio_dev) · 12 unmodified lines
11811184
11821185 iio_free_scan_mask(indio_dev, indio_dev->active_scan_mask);
11831186 indio_dev->active_scan_mask = NULL;
1184− indio_dev->currentmode = INDIO_DIRECT_MODE;
1187+ iio_dev_opaque->currentmode = INDIO_DIRECT_MODE;
11851188
11861189 return ret;
11871190 }
@@ -1300,7 +1303,7 @@ static ssize_t iio_buffer_store_enable(struct device *dev, · 112 unmodified lines
13001303 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer;
13011304 bool inlist;
13021305
1303− ret = strtobool(buf, &requested_state);
1306+ ret = kstrtobool(buf, &requested_state);
13041307 if (ret < 0)
13051308 return ret;
13061309
@@ -1629,6 +1632,19 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, · 322 unmodified lines
16291632 if (channels[i].scan_index < 0)
16301633 continue;
16311634
1635+ /* Verify that sample bits fit into storage */
1636+ if (channels[i].scan_type.storagebits <
1637+ channels[i].scan_type.realbits +
1638+ channels[i].scan_type.shift) {
1639+ dev_err(&indio_dev->dev,
1640+ "Channel %d storagebits (%d) < shifted realbits (%d + %d)\n",
1641+ i, channels[i].scan_type.storagebits,
1642+ channels[i].scan_type.realbits,
1643+ channels[i].scan_type.shift);
1644+ ret = -EINVAL;
1645+ goto error_cleanup_dynamic;
1646+ }
1647+
16321648 ret = iio_buffer_add_channel_sysfs(indio_dev, buffer,
16331649 &channels[i]);
16341650 if (ret < 0)
@@ -1649,7 +1665,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, · 14 unmodified lines
16491665 }
16501666
16511667 attrn = buffer_attrcount + scan_el_attrcount + ARRAY_SIZE(iio_buffer_attrs);
1652− attr = kcalloc(attrn + 1, sizeof(* attr), GFP_KERNEL);
1668+ attr = kcalloc(attrn + 1, sizeof(*attr), GFP_KERNEL);
16531669 if (!attr) {
16541670 ret = -ENOMEM;
16551671 goto error_free_scan_mask;
drivers/iio/industrialio-core.c+37−9
@@ -184,6 +184,20 @@ int iio_device_id(struct iio_dev *indio_dev) · 183 unmodified lines
184184 }
185185 EXPORT_SYMBOL_GPL(iio_device_id);
186186
187+/**
188+ * iio_buffer_enabled() - helper function to test if the buffer is enabled
189+ * @indio_dev: IIO device structure for device
190+ */
191+bool iio_buffer_enabled(struct iio_dev *indio_dev)
192+{
193+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
194+
195+ return iio_dev_opaque->currentmode
196+ & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE |
197+ INDIO_BUFFER_SOFTWARE);
198+}
199+EXPORT_SYMBOL_GPL(iio_buffer_enabled);
200+
187201 /**
188202 * iio_sysfs_match_string_with_gaps - matches given string in an array with gaps
189203 * @array: array of strings
@@ -892,8 +906,7 @@ static int __iio_str_to_fixpoint(const char *str, int fract_mult, · 702 unmodified lines
892906 } else if (*str == '\n') {
893907 if (*(str + 1) == '\0')
894908 break;
895− else
896− return -EINVAL;
909+ return -EINVAL;
897910 } else if (!strncmp(str, " dB", sizeof(" dB") - 1) && scale_db) {
898911 /* Ignore the dB suffix */
899912 str += sizeof(" dB") - 1;
@@ -1894,20 +1907,22 @@ static const struct iio_buffer_setup_ops noop_ring_setup_ops; · 994 unmodified lines
18941907 int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
18951908 {
18961909 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
1897− const char *label;
1910+ struct fwnode_handle *fwnode;
18981911 int ret;
18991912
19001913 if (!indio_dev->info)
19011914 return -EINVAL;
19021915
19031916 iio_dev_opaque->driver_module = this_mod;
1904− /* If the calling driver did not initialize of_node, do it here */
1905− if (!indio_dev->dev.of_node && indio_dev->dev.parent)
1906− indio_dev->dev.of_node = indio_dev->dev.parent->of_node;
19071917
1908− label = of_get_property(indio_dev->dev.of_node, "label", NULL);
1909− if (label)
1910− indio_dev->label = label;
1918+ /* If the calling driver did not initialize firmware node, do it here */
1919+ if (dev_fwnode(&indio_dev->dev))
1920+ fwnode = dev_fwnode(&indio_dev->dev);
1921+ else
1922+ fwnode = dev_fwnode(indio_dev->dev.parent);
1923+ device_set_node(&indio_dev->dev, fwnode);
1924+
1925+ fwnode_property_read_string(fwnode, "label", &indio_dev->label);
19111926
19121927 ret = iio_check_unique_scan_index(indio_dev);
19131928 if (ret < 0)
@@ -2059,6 +2074,19 @@ void iio_device_release_direct_mode(struct iio_dev *indio_dev) · 145 unmodified lines
20592074 }
20602075 EXPORT_SYMBOL_GPL(iio_device_release_direct_mode);
20612076
2077+/**
2078+ * iio_device_get_current_mode() - helper function providing read-only access to
2079+ * the opaque @currentmode variable
2080+ * @indio_dev: IIO device structure for device
2081+ */
2082+int iio_device_get_current_mode(struct iio_dev *indio_dev)
2083+{
2084+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
2085+
2086+ return iio_dev_opaque->currentmode;
2087+}
2088+EXPORT_SYMBOL_GPL(iio_device_get_current_mode);
2089+
20622090 subsys_initcall(iio_init);
20632091 module_exit(iio_exit);
20642092
drivers/iio/industrialio-event.c+1−1
@@ -274,7 +274,7 @@ static ssize_t iio_ev_state_store(struct device *dev, · 273 unmodified lines
274274 int ret;
275275 bool val;
276276
277− ret = strtobool(buf, &val);
277+ ret = kstrtobool(buf, &val);
278278 if (ret < 0)
279279 return ret;
280280
drivers/iio/industrialio-trigger.c+1−1
@@ -444,7 +444,7 @@ static ssize_t iio_trigger_write_current(struct device *dev, · 443 unmodified lines
444444 int ret;
445445
446446 mutex_lock(&indio_dev->mlock);
447− if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
447+ if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) {
448448 mutex_unlock(&indio_dev->mlock);
449449 return -EBUSY;
450450 }
drivers/iio/light/Kconfig+0−1
@@ -155,7 +155,6 @@ config CM3323 · 154 unmodified lines
155155
156156 config CM3605
157157 tristate "Capella CM3605 ambient light and proximity sensor"
158− depends on OF
159158 help
160159 Say Y here if you want to build a driver for Capella CM3605
161160 ambient light and short range proximity sensor.
drivers/iio/light/apds9960.c+0−1
@@ -1003,7 +1003,6 @@ static int apds9960_probe(struct i2c_client *client, · 1002 unmodified lines
10031003 indio_dev->modes = INDIO_DIRECT_MODE;
10041004
10051005 ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
1006− INDIO_BUFFER_SOFTWARE,
10071006 &apds9960_buffer_setup_ops);
10081007 if (ret)
10091008 return ret;
drivers/iio/light/stk3310.c+25−0
@@ -106,6 +106,7 @@ struct stk3310_data { · 105 unmodified lines
106106 struct mutex lock;
107107 bool als_enabled;
108108 bool ps_enabled;
109+ uint32_t ps_near_level;
109110 u64 timestamp;
110111 struct regmap *regmap;
111112 struct regmap_field *reg_state;
@@ -135,6 +136,25 @@ static const struct iio_event_spec stk3310_events[] = { · 23 unmodified lines
135136 },
136137 };
137138
139+static ssize_t stk3310_read_near_level(struct iio_dev *indio_dev,
140+ uintptr_t priv,
141+ const struct iio_chan_spec *chan,
142+ char *buf)
143+{
144+ struct stk3310_data *data = iio_priv(indio_dev);
145+
146+ return sprintf(buf, "%u\n", data->ps_near_level);
147+}
148+
149+static const struct iio_chan_spec_ext_info stk3310_ext_info[] = {
150+ {
151+ .name = "nearlevel",
152+ .shared = IIO_SEPARATE,
153+ .read = stk3310_read_near_level,
154+ },
155+ { /* sentinel */ }
156+};
157+
138158 static const struct iio_chan_spec stk3310_channels[] = {
139159 {
140160 .type = IIO_LIGHT,
@@ -151,6 +171,7 @@ static const struct iio_chan_spec stk3310_channels[] = { · 10 unmodified lines
151171 BIT(IIO_CHAN_INFO_INT_TIME),
152172 .event_spec = stk3310_events,
153173 .num_event_specs = ARRAY_SIZE(stk3310_events),
174+ .ext_info = stk3310_ext_info,
154175 }
155176 };
156177
@@ -581,6 +602,10 @@ static int stk3310_probe(struct i2c_client *client, · 424 unmodified lines
581602 data = iio_priv(indio_dev);
582603 data->client = client;
583604 i2c_set_clientdata(client, indio_dev);
605+
606+ device_property_read_u32(&client->dev, "proximity-near-level",
607+ &data->ps_near_level);
608+
584609 mutex_init(&data->lock);
585610
586611 ret = stk3310_regmap_init(data);
drivers/iio/light/tsl2772.c+10−15
@@ -15,7 +15,9 @@ · 14 unmodified lines
1515 #include <linux/kernel.h>
1616 #include <linux/module.h>
1717 #include <linux/mutex.h>
18+#include <linux/property.h>
1819 #include <linux/slab.h>
20+
1921 #include <linux/iio/events.h>
2022 #include <linux/iio/iio.h>
2123 #include <linux/iio/sysfs.h>
@@ -549,10 +551,10 @@ prox_poll_err: · 527 unmodified lines
549551
550552 static int tsl2772_read_prox_led_current(struct tsl2772_chip *chip)
551553 {
552− struct device_node *of_node = chip->client->dev.of_node;
554+ struct device *dev = &chip->client->dev;
553555 int ret, tmp, i;
554556
555− ret = of_property_read_u32(of_node, "led-max-microamp", &tmp);
557+ ret = device_property_read_u32(dev, "led-max-microamp", &tmp);
556558 if (ret < 0)
557559 return ret;
558560
@@ -563,20 +565,18 @@ static int tsl2772_read_prox_led_current(struct tsl2772_chip *chip) · 4 unmodified lines
563565 }
564566 }
565567
566− dev_err(&chip->client->dev, "Invalid value %d for led-max-microamp\n",
567− tmp);
568+ dev_err(dev, "Invalid value %d for led-max-microamp\n", tmp);
568569
569570 return -EINVAL;
570−
571571 }
572572
573573 static int tsl2772_read_prox_diodes(struct tsl2772_chip *chip)
574574 {
575− struct device_node *of_node = chip->client->dev.of_node;
575+ struct device *dev = &chip->client->dev;
576576 int i, ret, num_leds, prox_diode_mask;
577577 u32 leds[TSL2772_MAX_PROX_LEDS];
578578
579− ret = of_property_count_u32_elems(of_node, "amstaos,proximity-diodes");
579+ ret = device_property_count_u32(dev, "amstaos,proximity-diodes");
580580 if (ret < 0)
581581 return ret;
582582
@@ -584,12 +584,9 @@ static int tsl2772_read_prox_diodes(struct tsl2772_chip *chip) · 1 unmodified line
584584 if (num_leds > TSL2772_MAX_PROX_LEDS)
585585 num_leds = TSL2772_MAX_PROX_LEDS;
586586
587− ret = of_property_read_u32_array(of_node, "amstaos,proximity-diodes",
588− leds, num_leds);
587+ ret = device_property_read_u32_array(dev, "amstaos,proximity-diodes", leds, num_leds);
589588 if (ret < 0) {
590− dev_err(&chip->client->dev,
591− "Invalid value for amstaos,proximity-diodes: %d.\n",
592− ret);
589+ dev_err(dev, "Invalid value for amstaos,proximity-diodes: %d.\n", ret);
593590 return ret;
594591 }
595592
@@ -600,9 +597,7 @@ static int tsl2772_read_prox_diodes(struct tsl2772_chip *chip) · 4 unmodified lines
600597 else if (leds[i] == 1)
601598 prox_diode_mask |= TSL2772_DIODE1;
602599 else {
603− dev_err(&chip->client->dev,
604− "Invalid value %d in amstaos,proximity-diodes.\n",
605− leds[i]);
600+ dev_err(dev, "Invalid value %d in amstaos,proximity-diodes.\n", leds[i]);
606601 return -EINVAL;
607602 }
608603 }
drivers/iio/magnetometer/Kconfig+0−1
@@ -9,7 +9,6 @@ menu "Magnetometer sensors" · 8 unmodified lines
99 config AK8974
1010 tristate "Asahi Kasei AK8974 3-Axis Magnetometer"
1111 depends on I2C
12− depends on OF
1312 select REGMAP_I2C
1413 select IIO_BUFFER
1514 select IIO_TRIGGERED_BUFFER
drivers/iio/magnetometer/rm3100-core.c+3−12
@@ -141,18 +141,10 @@ static irqreturn_t rm3100_irq_handler(int irq, void *d) · 140 unmodified lines
141141 struct iio_dev *indio_dev = d;
142142 struct rm3100_data *data = iio_priv(indio_dev);
143143
144− switch (indio_dev->currentmode) {
145− case INDIO_DIRECT_MODE:
144+ if (!iio_buffer_enabled(indio_dev))
146145 complete(&data->measuring_done);
147− break;
148− case INDIO_BUFFER_TRIGGERED:
146+ else
149147 iio_trigger_poll(data->drdy_trig);
150− break;
151− default:
152− dev_err(indio_dev->dev.parent,
153− "device mode out of control, current mode: %d",
154− indio_dev->currentmode);
155− }
156148
157149 return IRQ_WAKE_THREAD;
158150 }
@@ -377,7 +369,7 @@ static int rm3100_set_samp_freq(struct iio_dev *indio_dev, int val, int val2) · 218 unmodified lines
377369 goto unlock_return;
378370 }
379371
380− if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
372+ if (iio_buffer_enabled(indio_dev)) {
381373 /* Writing TMRC registers requires CMM reset. */
382374 ret = regmap_write(regmap, RM3100_REG_CMM, 0);
383375 if (ret < 0)
@@ -553,7 +545,6 @@ int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq) · 169 unmodified lines
553545 indio_dev->channels = rm3100_channels;
554546 indio_dev->num_channels = ARRAY_SIZE(rm3100_channels);
555547 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_TRIGGERED;
556− indio_dev->currentmode = INDIO_DIRECT_MODE;
557548
558549 if (!irq)
559550 data->use_interrupt = false;
drivers/iio/magnetometer/st_magn_core.c+4−11
@@ -540,24 +540,17 @@ read_error: · 539 unmodified lines
540540 static int st_magn_write_raw(struct iio_dev *indio_dev,
541541 struct iio_chan_spec const *chan, int val, int val2, long mask)
542542 {
543− int err;
544−
545543 switch (mask) {
546544 case IIO_CHAN_INFO_SCALE:
547− err = st_sensors_set_fullscale_by_gain(indio_dev, val2);
548− break;
545+ return st_sensors_set_fullscale_by_gain(indio_dev, val2);
549546 case IIO_CHAN_INFO_SAMP_FREQ:
550547 if (val2)
551548 return -EINVAL;
552− mutex_lock(&indio_dev->mlock);
553− err = st_sensors_set_odr(indio_dev, val);
554− mutex_unlock(&indio_dev->mlock);
555− return err;
549+
550+ return st_sensors_set_odr(indio_dev, val);
556551 default:
557− err = -EINVAL;
552+ return -EINVAL;
558553 }
559−
560− return err;
561554 }
562555
563556 static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
drivers/iio/multiplexer/Kconfig+0−1
@@ -9,7 +9,6 @@ menu "Multiplexers" · 8 unmodified lines
99 config IIO_MUX
1010 tristate "IIO multiplexer driver"
1111 select MULTIPLEXER
12− depends on OF || COMPILE_TEST
1312 help
1413 Say yes here to build support for the IIO multiplexer.
1514
drivers/iio/multiplexer/iio-mux.c+23−26
@@ -10,11 +10,12 @@ · 9 unmodified lines
1010 #include <linux/err.h>
1111 #include <linux/iio/consumer.h>
1212 #include <linux/iio/iio.h>
13+#include <linux/mod_devicetable.h>
1314 #include <linux/module.h>
1415 #include <linux/mutex.h>
1516 #include <linux/mux/consumer.h>
16−#include <linux/of.h>
1717 #include <linux/platform_device.h>
18+#include <linux/property.h>
1819
1920 struct mux_ext_info_cache {
2021 char *data;
@@ -324,37 +325,21 @@ static int mux_configure_channel(struct device *dev, struct mux *mux, · 303 unmodified lines
324325 return 0;
325326 }
326327
327−/*
328− * Same as of_property_for_each_string(), but also keeps track of the
329− * index of each string.
330− */
331−#define of_property_for_each_string_index(np, propname, prop, s, i) \
332− for (prop = of_find_property(np, propname, NULL), \
333− s = of_prop_next_string(prop, NULL), \
334− i = 0; \
335− s; \
336− s = of_prop_next_string(prop, s), \
337− i++)
338−
339328 static int mux_probe(struct platform_device *pdev)
340329 {
341330 struct device *dev = &pdev->dev;
342− struct device_node *np = pdev->dev.of_node;
343331 struct iio_dev *indio_dev;
344332 struct iio_channel *parent;
345333 struct mux *mux;
346− struct property *prop;
347− const char *label;
334+ const char **labels;
335+ int all_children;
336+ int children;
348337 u32 state;
349338 int sizeof_ext_info;
350− int children;
351339 int sizeof_priv;
352340 int i;
353341 int ret;
354342
355− if (!np)
356− return -ENODEV;
357−
358343 parent = devm_iio_channel_get(dev, "parent");
359344 if (IS_ERR(parent))
360345 return dev_err_probe(dev, PTR_ERR(parent),
@@ -366,9 +351,21 @@ static int mux_probe(struct platform_device *pdev) · 5 unmodified lines
366351 sizeof_ext_info *= sizeof(*mux->ext_info);
367352 }
368353
354+ all_children = device_property_string_array_count(dev, "channels");
355+ if (all_children < 0)
356+ return all_children;
357+
358+ labels = devm_kmalloc_array(dev, all_children, sizeof(*labels), GFP_KERNEL);
359+ if (!labels)
360+ return -ENOMEM;
361+
362+ ret = device_property_read_string_array(dev, "channels", labels, all_children);
363+ if (ret < 0)
364+ return ret;
365+
369366 children = 0;
370− of_property_for_each_string(np, "channels", prop, label) {
371− if (*label)
367+ for (state = 0; state < all_children; state++) {
368+ if (*labels[state])
372369 children++;
373370 }
374371 if (children <= 0) {
@@ -395,7 +392,7 @@ static int mux_probe(struct platform_device *pdev) · 20 unmodified lines
395392 mux->cached_state = -1;
396393
397394 mux->delay_us = 0;
398− of_property_read_u32(np, "settle-time-us", &mux->delay_us);
395+ device_property_read_u32(dev, "settle-time-us", &mux->delay_us);
399396
400397 indio_dev->name = dev_name(dev);
401398 indio_dev->info = &mux_info;
@@ -426,11 +423,11 @@ static int mux_probe(struct platform_device *pdev) · 24 unmodified lines
426423 }
427424
428425 i = 0;
429− of_property_for_each_string_index(np, "channels", prop, label, state) {
430− if (!*label)
426+ for (state = 0; state < all_children; state++) {
427+ if (!*labels[state])
431428 continue;
432429
433− ret = mux_configure_channel(dev, mux, state, label, i++);
430+ ret = mux_configure_channel(dev, mux, state, labels[state], i++);
434431 if (ret < 0)
435432 return ret;
436433 }
drivers/iio/pressure/st_pressure_core.c+2−6
@@ -560,16 +560,12 @@ static int st_press_write_raw(struct iio_dev *indio_dev, · 559 unmodified lines
560560 int val2,
561561 long mask)
562562 {
563− int err;
564−
565563 switch (mask) {
566564 case IIO_CHAN_INFO_SAMP_FREQ:
567565 if (val2)
568566 return -EINVAL;
569− mutex_lock(&indio_dev->mlock);
570− err = st_sensors_set_odr(indio_dev, val);
571− mutex_unlock(&indio_dev->mlock);
572− return err;
567+
568+ return st_sensors_set_odr(indio_dev, val);
573569 default:
574570 return -EINVAL;
575571 }
drivers/iio/proximity/mb1232.c+5−3
@@ -10,12 +10,14 @@ · 9 unmodified lines
1010 * https://www.maxbotix.com/documents/I2CXL-MaxSonar-EZ_Datasheet.pdf
1111 */
1212
13+#include <linux/bitops.h>
1314 #include <linux/err.h>
1415 #include <linux/i2c.h>
15−#include <linux/of_irq.h>
1616 #include <linux/delay.h>
17+#include <linux/mod_devicetable.h>
1718 #include <linux/module.h>
18−#include <linux/bitops.h>
19+#include <linux/property.h>
20+
1921 #include <linux/iio/iio.h>
2022 #include <linux/iio/sysfs.h>
2123 #include <linux/iio/buffer.h>
@@ -209,7 +211,7 @@ static int mb1232_probe(struct i2c_client *client, · 187 unmodified lines
209211
210212 init_completion(&data->ranging);
211213
212− data->irqnr = irq_of_parse_and_map(dev->of_node, 0);
214+ data->irqnr = fwnode_irq_get(dev_fwnode(&client->dev), 0);
213215 if (data->irqnr <= 0) {
214216 /* usage of interrupt is optional */
215217 data->irqnr = -1;
drivers/iio/proximity/ping.c+2−3
@@ -29,9 +29,8 @@ · 28 unmodified lines
2929 #include <linux/err.h>
3030 #include <linux/gpio/consumer.h>
3131 #include <linux/kernel.h>
32+#include <linux/mod_devicetable.h>
3233 #include <linux/module.h>
33−#include <linux/of.h>
34−#include <linux/of_device.h>
3534 #include <linux/platform_device.h>
3635 #include <linux/property.h>
3736 #include <linux/sched.h>
@@ -288,7 +287,7 @@ static int ping_probe(struct platform_device *pdev) · 250 unmodified lines
288287
289288 data = iio_priv(indio_dev);
290289 data->dev = dev;
291− data->cfg = of_device_get_match_data(dev);
290+ data->cfg = device_get_match_data(dev);
292291
293292 mutex_init(&data->lock);
294293 init_completion(&data->rising);
drivers/iio/proximity/vl53l0x-i2c.c+3−4
@@ -104,6 +104,7 @@ static int vl53l0x_read_proximity(struct vl53l0x_data *data, · 103 unmodified lines
104104 u16 tries = 20;
105105 u8 buffer[12];
106106 int ret;
107+ unsigned long time_left;
107108
108109 ret = i2c_smbus_write_byte_data(client, VL_REG_SYSRANGE_START, 1);
109110 if (ret < 0)
@@ -112,10 +113,8 @@ static int vl53l0x_read_proximity(struct vl53l0x_data *data, · 2 unmodified lines
112113 if (data->client->irq) {
113114 reinit_completion(&data->completion);
114115
115− ret = wait_for_completion_timeout(&data->completion, HZ/10);
116− if (ret < 0)
117− return ret;
118− else if (ret == 0)
116+ time_left = wait_for_completion_timeout(&data->completion, HZ/10);
117+ if (time_left == 0)
119118 return -ETIMEDOUT;
120119
121120 vl53l0x_clear_irq(data);
drivers/iio/temperature/ltc2983.c+120−116
@@ -12,11 +12,15 @@ · 11 unmodified lines
1212 #include <linux/iio/iio.h>
1313 #include <linux/interrupt.h>
1414 #include <linux/list.h>
15+#include <linux/mod_devicetable.h>
1516 #include <linux/module.h>
16−#include <linux/of_gpio.h>
17+#include <linux/property.h>
1718 #include <linux/regmap.h>
1819 #include <linux/spi/spi.h>
1920
21+#include <asm/byteorder.h>
22+#include <asm/unaligned.h>
23+
2024 /* register map */
2125 #define LTC2983_STATUS_REG 0x0000
2226 #define LTC2983_TEMP_RES_START_REG 0x0010
@@ -219,7 +223,7 @@ struct ltc2983_sensor { · 196 unmodified lines
219223
220224 struct ltc2983_custom_sensor {
221225 /* raw table sensor data */
222− u8 *table;
226+ void *table;
223227 size_t size;
224228 /* address offset */
225229 s8 offset;
@@ -377,25 +381,25 @@ static int __ltc2983_chan_custom_sensor_assign(struct ltc2983_data *st, · 151 unmodified lines
377381 return regmap_bulk_write(st->regmap, reg, custom->table, custom->size);
378382 }
379383
380−static struct ltc2983_custom_sensor *__ltc2983_custom_sensor_new(
381− struct ltc2983_data *st,
382− const struct device_node *np,
383− const char *propname,
384− const bool is_steinhart,
385− const u32 resolution,
386− const bool has_signed)
384+static struct ltc2983_custom_sensor *
385+__ltc2983_custom_sensor_new(struct ltc2983_data *st, const struct fwnode_handle *fn,
386+ const char *propname, const bool is_steinhart,
387+ const u32 resolution, const bool has_signed)
387388 {
388389 struct ltc2983_custom_sensor *new_custom;
389− u8 index, n_entries, tbl = 0;
390390 struct device *dev = &st->spi->dev;
391391 /*
392392 * For custom steinhart, the full u32 is taken. For all the others
393393 * the MSB is discarded.
394394 */
395395 const u8 n_size = is_steinhart ? 4 : 3;
396− const u8 e_size = is_steinhart ? sizeof(u32) : sizeof(u64);
396+ u8 index, n_entries;
397+ int ret;
397398
398− n_entries = of_property_count_elems_of_size(np, propname, e_size);
399+ if (is_steinhart)
400+ n_entries = fwnode_property_count_u32(fn, propname);
401+ else
402+ n_entries = fwnode_property_count_u64(fn, propname);
399403 /* n_entries must be an even number */
400404 if (!n_entries || (n_entries % 2) != 0) {
401405 dev_err(dev, "Number of entries either 0 or not even\n");
@@ -409,8 +413,8 @@ static struct ltc2983_custom_sensor *__ltc2983_custom_sensor_new( · 7 unmodified lines
409413 new_custom->size = n_entries * n_size;
410414 /* check Steinhart size */
411415 if (is_steinhart && new_custom->size != LTC2983_CUSTOM_STEINHART_SIZE) {
412− dev_err(dev, "Steinhart sensors size(%zu) must be 24",
413− new_custom->size);
416+ dev_err(dev, "Steinhart sensors size(%zu) must be %u\n", new_custom->size,
417+ LTC2983_CUSTOM_STEINHART_SIZE);
414418 return ERR_PTR(-EINVAL);
415419 }
416420 /* Check space on the table. */
@@ -423,21 +427,33 @@ static struct ltc2983_custom_sensor *__ltc2983_custom_sensor_new( · 6 unmodified lines
423427 }
424428
425429 /* allocate the table */
426− new_custom->table = devm_kzalloc(dev, new_custom->size, GFP_KERNEL);
430+ if (is_steinhart)
431+ new_custom->table = devm_kcalloc(dev, n_entries, sizeof(u32), GFP_KERNEL);
432+ else
433+ new_custom->table = devm_kcalloc(dev, n_entries, sizeof(u64), GFP_KERNEL);
427434 if (!new_custom->table)
428435 return ERR_PTR(-ENOMEM);
429436
430− for (index = 0; index < n_entries; index++) {
431− u64 temp = 0, j;
432− /*
433− * Steinhart sensors are configured with raw values in the
434− * devicetree. For the other sensors we must convert the
435− * value to raw. The odd index's correspond to temperarures
436− * and always have 1/1024 of resolution. Temperatures also
437− * come in kelvin, so signed values is not possible
438− */
439− if (!is_steinhart) {
440− of_property_read_u64_index(np, propname, index, &temp);
437+ /*
438+ * Steinhart sensors are configured with raw values in the firmware
439+ * node. For the other sensors we must convert the value to raw.
440+ * The odd index's correspond to temperatures and always have 1/1024
441+ * of resolution. Temperatures also come in Kelvin, so signed values
442+ * are not possible.
443+ */
444+ if (is_steinhart) {
445+ ret = fwnode_property_read_u32_array(fn, propname, new_custom->table, n_entries);
446+ if (ret < 0)
447+ return ERR_PTR(ret);
448+
449+ cpu_to_be32_array(new_custom->table, new_custom->table, n_entries);
450+ } else {
451+ ret = fwnode_property_read_u64_array(fn, propname, new_custom->table, n_entries);
452+ if (ret < 0)
453+ return ERR_PTR(ret);
454+
455+ for (index = 0; index < n_entries; index++) {
456+ u64 temp = ((u64 *)new_custom->table)[index];
441457
442458 if ((index % 2) != 0)
443459 temp = __convert_to_raw(temp, 1024);
@@ -445,16 +461,9 @@ static struct ltc2983_custom_sensor *__ltc2983_custom_sensor_new( · 1 unmodified line
445461 temp = __convert_to_raw_sign(temp, resolution);
446462 else
447463 temp = __convert_to_raw(temp, resolution);
448− } else {
449− u32 t32;
450464
451− of_property_read_u32_index(np, propname, index, &t32);
452− temp = t32;
465+ put_unaligned_be24(temp, new_custom->table + index * 3);
453466 }
454−
455− for (j = 0; j < n_size; j++)
456− new_custom->table[tbl++] =
457− temp >> (8 * (n_size - j - 1));
458467 }
459468
460469 new_custom->is_steinhart = is_steinhart;
@@ -597,13 +606,12 @@ static int ltc2983_adc_assign_chan(struct ltc2983_data *st, · 136 unmodified lines
597606 return __ltc2983_chan_assign_common(st, sensor, chan_val);
598607 }
599608
600−static struct ltc2983_sensor *ltc2983_thermocouple_new(
601− const struct device_node *child,
602− struct ltc2983_data *st,
603− const struct ltc2983_sensor *sensor)
609+static struct ltc2983_sensor *
610+ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data *st,
611+ const struct ltc2983_sensor *sensor)
604612 {
605613 struct ltc2983_thermocouple *thermo;
606− struct device_node *phandle;
614+ struct fwnode_handle *ref;
607615 u32 oc_current;
608616 int ret;
609617
@@ -611,11 +619,10 @@ static struct ltc2983_sensor *ltc2983_thermocouple_new( · 1 unmodified line
611619 if (!thermo)
612620 return ERR_PTR(-ENOMEM);
613621
614− if (of_property_read_bool(child, "adi,single-ended"))
622+ if (fwnode_property_read_bool(child, "adi,single-ended"))
615623 thermo->sensor_config = LTC2983_THERMOCOUPLE_SGL(1);
616624
617− ret = of_property_read_u32(child, "adi,sensor-oc-current-microamp",
618− &oc_current);
625+ ret = fwnode_property_read_u32(child, "adi,sensor-oc-current-microamp", &oc_current);
619626 if (!ret) {
620627 switch (oc_current) {
621628 case 10:
@@ -651,20 +658,18 @@ static struct ltc2983_sensor *ltc2983_thermocouple_new( · 29 unmodified lines
651658 return ERR_PTR(-EINVAL);
652659 }
653660
654− phandle = of_parse_phandle(child, "adi,cold-junction-handle", 0);
655− if (phandle) {
656− int ret;
657−
658− ret = of_property_read_u32(phandle, "reg",
659− &thermo->cold_junction_chan);
661+ ref = fwnode_find_reference(child, "adi,cold-junction-handle", 0);
662+ if (IS_ERR(ref)) {
663+ ref = NULL;
664+ } else {
665+ ret = fwnode_property_read_u32(ref, "reg", &thermo->cold_junction_chan);
660666 if (ret) {
661667 /*
662668 * This would be catched later but we can just return
663669 * the error right away.
664670 */
665671 dev_err(&st->spi->dev, "Property reg must be given\n");
666− of_node_put(phandle);
667− return ERR_PTR(-EINVAL);
672+ goto fail;
668673 }
669674 }
670675
@@ -676,8 +681,8 @@ static struct ltc2983_sensor *ltc2983_thermocouple_new( · 5 unmodified lines
676681 propname, false,
677682 16384, true);
678683 if (IS_ERR(thermo->custom)) {
679− of_node_put(phandle);
680− return ERR_CAST(thermo->custom);
684+ ret = PTR_ERR(thermo->custom);
685+ goto fail;
681686 }
682687 }
683688
@@ -685,37 +690,41 @@ static struct ltc2983_sensor *ltc2983_thermocouple_new( · 1 unmodified line
685690 thermo->sensor.fault_handler = ltc2983_thermocouple_fault_handler;
686691 thermo->sensor.assign_chan = ltc2983_thermocouple_assign_chan;
687692
688− of_node_put(phandle);
693+ fwnode_handle_put(ref);
689694 return &thermo->sensor;
695+
696+fail:
697+ fwnode_handle_put(ref);
698+ return ERR_PTR(ret);
690699 }
691700
692−static struct ltc2983_sensor *ltc2983_rtd_new(const struct device_node *child,
693− struct ltc2983_data *st,
694− const struct ltc2983_sensor *sensor)
701+static struct ltc2983_sensor *
702+ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st,
703+ const struct ltc2983_sensor *sensor)
695704 {
696705 struct ltc2983_rtd *rtd;
697706 int ret = 0;
698707 struct device *dev = &st->spi->dev;
699− struct device_node *phandle;
708+ struct fwnode_handle *ref;
700709 u32 excitation_current = 0, n_wires = 0;
701710
702711 rtd = devm_kzalloc(dev, sizeof(*rtd), GFP_KERNEL);
703712 if (!rtd)
704713 return ERR_PTR(-ENOMEM);
705714
706− phandle = of_parse_phandle(child, "adi,rsense-handle", 0);
707− if (!phandle) {
715+ ref = fwnode_find_reference(child, "adi,rsense-handle", 0);
716+ if (IS_ERR(ref)) {
708717 dev_err(dev, "Property adi,rsense-handle missing or invalid");
709− return ERR_PTR(-EINVAL);
718+ return ERR_CAST(ref);
710719 }
711720
712− ret = of_property_read_u32(phandle, "reg", &rtd->r_sense_chan);
721+ ret = fwnode_property_read_u32(ref, "reg", &rtd->r_sense_chan);
713722 if (ret) {
714723 dev_err(dev, "Property reg must be given\n");
715724 goto fail;
716725 }
717726
718− ret = of_property_read_u32(child, "adi,number-of-wires", &n_wires);
727+ ret = fwnode_property_read_u32(child, "adi,number-of-wires", &n_wires);
719728 if (!ret) {
720729 switch (n_wires) {
721730 case 2:
@@ -738,9 +747,9 @@ static struct ltc2983_sensor *ltc2983_rtd_new(const struct device_node *child, · 16 unmodified lines
738747 }
739748 }
740749
741− if (of_property_read_bool(child, "adi,rsense-share")) {
750+ if (fwnode_property_read_bool(child, "adi,rsense-share")) {
742751 /* Current rotation is only available with rsense sharing */
743− if (of_property_read_bool(child, "adi,current-rotate")) {
752+ if (fwnode_property_read_bool(child, "adi,current-rotate")) {
744753 if (n_wires == 2 || n_wires == 3) {
745754 dev_err(dev,
746755 "Rotation not allowed for 2/3 Wire RTDs");
@@ -803,8 +812,8 @@ static struct ltc2983_sensor *ltc2983_rtd_new(const struct device_node *child, · 56 unmodified lines
803812 "adi,custom-rtd",
804813 false, 2048, false);
805814 if (IS_ERR(rtd->custom)) {
806− of_node_put(phandle);
807− return ERR_CAST(rtd->custom);
815+ ret = PTR_ERR(rtd->custom);
816+ goto fail;
808817 }
809818 }
810819
@@ -812,8 +821,8 @@ static struct ltc2983_sensor *ltc2983_rtd_new(const struct device_node *child, · 1 unmodified line
812821 rtd->sensor.fault_handler = ltc2983_common_fault_handler;
813822 rtd->sensor.assign_chan = ltc2983_rtd_assign_chan;
814823
815− ret = of_property_read_u32(child, "adi,excitation-current-microamp",
816− &excitation_current);
824+ ret = fwnode_property_read_u32(child, "adi,excitation-current-microamp",
825+ &excitation_current);
817826 if (ret) {
818827 /* default to 5uA */
819828 rtd->excitation_current = 1;
@@ -852,23 +861,22 @@ static struct ltc2983_sensor *ltc2983_rtd_new(const struct device_node *child, · 32 unmodified lines
852861 }
853862 }
854863
855− of_property_read_u32(child, "adi,rtd-curve", &rtd->rtd_curve);
864+ fwnode_property_read_u32(child, "adi,rtd-curve", &rtd->rtd_curve);
856865
857− of_node_put(phandle);
866+ fwnode_handle_put(ref);
858867 return &rtd->sensor;
859868 fail:
860− of_node_put(phandle);
869+ fwnode_handle_put(ref);
861870 return ERR_PTR(ret);
862871 }
863872
864−static struct ltc2983_sensor *ltc2983_thermistor_new(
865− const struct device_node *child,
866− struct ltc2983_data *st,
867− const struct ltc2983_sensor *sensor)
873+static struct ltc2983_sensor *
874+ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *st,
875+ const struct ltc2983_sensor *sensor)
868876 {
869877 struct ltc2983_thermistor *thermistor;
870878 struct device *dev = &st->spi->dev;
871− struct device_node *phandle;
879+ struct fwnode_handle *ref;
872880 u32 excitation_current = 0;
873881 int ret = 0;
874882
@@ -876,23 +884,23 @@ static struct ltc2983_sensor *ltc2983_thermistor_new( · 1 unmodified line
876884 if (!thermistor)
877885 return ERR_PTR(-ENOMEM);
878886
879− phandle = of_parse_phandle(child, "adi,rsense-handle", 0);
880− if (!phandle) {
887+ ref = fwnode_find_reference(child, "adi,rsense-handle", 0);
888+ if (IS_ERR(ref)) {
881889 dev_err(dev, "Property adi,rsense-handle missing or invalid");
882− return ERR_PTR(-EINVAL);
890+ return ERR_CAST(ref);
883891 }
884892
885− ret = of_property_read_u32(phandle, "reg", &thermistor->r_sense_chan);
893+ ret = fwnode_property_read_u32(ref, "reg", &thermistor->r_sense_chan);
886894 if (ret) {
887895 dev_err(dev, "rsense channel must be configured...\n");
888896 goto fail;
889897 }
890898
891− if (of_property_read_bool(child, "adi,single-ended")) {
899+ if (fwnode_property_read_bool(child, "adi,single-ended")) {
892900 thermistor->sensor_config = LTC2983_THERMISTOR_SGL(1);
893− } else if (of_property_read_bool(child, "adi,rsense-share")) {
901+ } else if (fwnode_property_read_bool(child, "adi,rsense-share")) {
894902 /* rotation is only possible if sharing rsense */
895− if (of_property_read_bool(child, "adi,current-rotate"))
903+ if (fwnode_property_read_bool(child, "adi,current-rotate"))
896904 thermistor->sensor_config =
897905 LTC2983_THERMISTOR_C_ROTATE(1);
898906 else
@@ -926,16 +934,16 @@ static struct ltc2983_sensor *ltc2983_thermistor_new( · 27 unmodified lines
926934 steinhart,
927935 64, false);
928936 if (IS_ERR(thermistor->custom)) {
929− of_node_put(phandle);
930− return ERR_CAST(thermistor->custom);
937+ ret = PTR_ERR(thermistor->custom);
938+ goto fail;
931939 }
932940 }
933941 /* set common parameters */
934942 thermistor->sensor.fault_handler = ltc2983_common_fault_handler;
935943 thermistor->sensor.assign_chan = ltc2983_thermistor_assign_chan;
936944
937− ret = of_property_read_u32(child, "adi,excitation-current-nanoamp",
938− &excitation_current);
945+ ret = fwnode_property_read_u32(child, "adi,excitation-current-nanoamp",
946+ &excitation_current);
939947 if (ret) {
940948 /* Auto range is not allowed for custom sensors */
941949 if (sensor->type >= LTC2983_SENSOR_THERMISTOR_STEINHART)
@@ -999,17 +1007,16 @@ static struct ltc2983_sensor *ltc2983_thermistor_new( · 57 unmodified lines
9991007 }
10001008 }
10011009
1002− of_node_put(phandle);
1010+ fwnode_handle_put(ref);
10031011 return &thermistor->sensor;
10041012 fail:
1005− of_node_put(phandle);
1013+ fwnode_handle_put(ref);
10061014 return ERR_PTR(ret);
10071015 }
10081016
1009−static struct ltc2983_sensor *ltc2983_diode_new(
1010− const struct device_node *child,
1011− const struct ltc2983_data *st,
1012− const struct ltc2983_sensor *sensor)
1017+static struct ltc2983_sensor *
1018+ltc2983_diode_new(const struct fwnode_handle *child, const struct ltc2983_data *st,
1019+ const struct ltc2983_sensor *sensor)
10131020 {
10141021 struct ltc2983_diode *diode;
10151022 u32 temp = 0, excitation_current = 0;
@@ -1019,13 +1026,13 @@ static struct ltc2983_sensor *ltc2983_diode_new( · 3 unmodified lines
10191026 if (!diode)
10201027 return ERR_PTR(-ENOMEM);
10211028
1022− if (of_property_read_bool(child, "adi,single-ended"))
1029+ if (fwnode_property_read_bool(child, "adi,single-ended"))
10231030 diode->sensor_config = LTC2983_DIODE_SGL(1);
10241031
1025− if (of_property_read_bool(child, "adi,three-conversion-cycles"))
1032+ if (fwnode_property_read_bool(child, "adi,three-conversion-cycles"))
10261033 diode->sensor_config |= LTC2983_DIODE_3_CONV_CYCLE(1);
10271034
1028− if (of_property_read_bool(child, "adi,average-on"))
1035+ if (fwnode_property_read_bool(child, "adi,average-on"))
10291036 diode->sensor_config |= LTC2983_DIODE_AVERAGE_ON(1);
10301037
10311038 /* validate channel index */
@@ -1040,8 +1047,8 @@ static struct ltc2983_sensor *ltc2983_diode_new( · 8 unmodified lines
10401047 diode->sensor.fault_handler = ltc2983_common_fault_handler;
10411048 diode->sensor.assign_chan = ltc2983_diode_assign_chan;
10421049
1043− ret = of_property_read_u32(child, "adi,excitation-current-microamp",
1044− &excitation_current);
1050+ ret = fwnode_property_read_u32(child, "adi,excitation-current-microamp",
1051+ &excitation_current);
10451052 if (!ret) {
10461053 switch (excitation_current) {
10471054 case 10:
@@ -1064,7 +1071,7 @@ static struct ltc2983_sensor *ltc2983_diode_new( · 16 unmodified lines
10641071 }
10651072 }
10661073
1067− of_property_read_u32(child, "adi,ideal-factor-value", &temp);
1074+ fwnode_property_read_u32(child, "adi,ideal-factor-value", &temp);
10681075
10691076 /* 2^20 resolution */
10701077 diode->ideal_factor_value = __convert_to_raw(temp, 1048576);
@@ -1072,7 +1079,7 @@ static struct ltc2983_sensor *ltc2983_diode_new( · 1 unmodified line
10721079 return &diode->sensor;
10731080 }
10741081
1075−static struct ltc2983_sensor *ltc2983_r_sense_new(struct device_node *child,
1082+static struct ltc2983_sensor *ltc2983_r_sense_new(struct fwnode_handle *child,
10761083 struct ltc2983_data *st,
10771084 const struct ltc2983_sensor *sensor)
10781085 {
@@ -1091,7 +1098,7 @@ static struct ltc2983_sensor *ltc2983_r_sense_new(struct device_node *child, · 12 unmodified lines
10911098 return ERR_PTR(-EINVAL);
10921099 }
10931100
1094− ret = of_property_read_u32(child, "adi,rsense-val-milli-ohms", &temp);
1101+ ret = fwnode_property_read_u32(child, "adi,rsense-val-milli-ohms", &temp);
10951102 if (ret) {
10961103 dev_err(&st->spi->dev, "Property adi,rsense-val-milli-ohms missing\n");
10971104 return ERR_PTR(-EINVAL);
@@ -1110,7 +1117,7 @@ static struct ltc2983_sensor *ltc2983_r_sense_new(struct device_node *child, · 12 unmodified lines
11101117 return &rsense->sensor;
11111118 }
11121119
1113−static struct ltc2983_sensor *ltc2983_adc_new(struct device_node *child,
1120+static struct ltc2983_sensor *ltc2983_adc_new(struct fwnode_handle *child,
11141121 struct ltc2983_data *st,
11151122 const struct ltc2983_sensor *sensor)
11161123 {
@@ -1120,7 +1127,7 @@ static struct ltc2983_sensor *ltc2983_adc_new(struct device_node *child, · 3 unmodified lines
11201127 if (!adc)
11211128 return ERR_PTR(-ENOMEM);
11221129
1123− if (of_property_read_bool(child, "adi,single-ended"))
1130+ if (fwnode_property_read_bool(child, "adi,single-ended"))
11241131 adc->single_ended = true;
11251132
11261133 if (!adc->single_ended &&
@@ -1264,17 +1271,15 @@ static irqreturn_t ltc2983_irq_handler(int irq, void *data) · 137 unmodified lines
12641271
12651272 static int ltc2983_parse_dt(struct ltc2983_data *st)
12661273 {
1267− struct device_node *child;
12681274 struct device *dev = &st->spi->dev;
1275+ struct fwnode_handle *child;
12691276 int ret = 0, chan = 0, channel_avail_mask = 0;
12701277
1271− of_property_read_u32(dev->of_node, "adi,mux-delay-config-us",
1272− &st->mux_delay_config);
1278+ device_property_read_u32(dev, "adi,mux-delay-config-us", &st->mux_delay_config);
12731279
1274− of_property_read_u32(dev->of_node, "adi,filter-notch-freq",
1275− &st->filter_notch_freq);
1280+ device_property_read_u32(dev, "adi,filter-notch-freq", &st->filter_notch_freq);
12761281
1277− st->num_channels = of_get_available_child_count(dev->of_node);
1282+ st->num_channels = device_get_child_node_count(dev);
12781283 if (!st->num_channels) {
12791284 dev_err(&st->spi->dev, "At least one channel must be given!");
12801285 return -EINVAL;
@@ -1286,10 +1291,10 @@ static int ltc2983_parse_dt(struct ltc2983_data *st) · 5 unmodified lines
12861291 return -ENOMEM;
12871292
12881293 st->iio_channels = st->num_channels;
1289− for_each_available_child_of_node(dev->of_node, child) {
1294+ device_for_each_child_node(dev, child) {
12901295 struct ltc2983_sensor sensor;
12911296
1292− ret = of_property_read_u32(child, "reg", &sensor.chan);
1297+ ret = fwnode_property_read_u32(child, "reg", &sensor.chan);
12931298 if (ret) {
12941299 dev_err(dev, "reg property must given for child nodes\n");
12951300 goto put_child;
@@ -1299,8 +1304,8 @@ static int ltc2983_parse_dt(struct ltc2983_data *st) · 3 unmodified lines
12991304 if (sensor.chan < LTC2983_MIN_CHANNELS_NR ||
13001305 sensor.chan > LTC2983_MAX_CHANNELS_NR) {
13011306 ret = -EINVAL;
1302− dev_err(dev,
1303− "chan:%d must be from 1 to 20\n", sensor.chan);
1307+ dev_err(dev, "chan:%d must be from %u to %u\n", sensor.chan,
1308+ LTC2983_MIN_CHANNELS_NR, LTC2983_MAX_CHANNELS_NR);
13041309 goto put_child;
13051310 } else if (channel_avail_mask & BIT(sensor.chan)) {
13061311 ret = -EINVAL;
@@ -1308,8 +1313,7 @@ static int ltc2983_parse_dt(struct ltc2983_data *st) · 1 unmodified line
13081313 goto put_child;
13091314 }
13101315
1311− ret = of_property_read_u32(child, "adi,sensor-type",
1312− &sensor.type);
1316+ ret = fwnode_property_read_u32(child, "adi,sensor-type", &sensor.type);
13131317 if (ret) {
13141318 dev_err(dev,
13151319 "adi,sensor-type property must given for child nodes\n");
@@ -1363,7 +1367,7 @@ static int ltc2983_parse_dt(struct ltc2983_data *st) · 47 unmodified lines
13631367
13641368 return 0;
13651369 put_child:
1366− of_node_put(child);
1370+ fwnode_handle_put(child);
13671371 return ret;
13681372 }
13691373
drivers/iio/temperature/max31856.c+3−3
@@ -7,9 +7,11 @@ · 6 unmodified lines
77 */
88
99 #include <linux/ctype.h>
10+#include <linux/mod_devicetable.h>
1011 #include <linux/module.h>
1112 #include <linux/init.h>
1213 #include <linux/err.h>
14+#include <linux/property.h>
1315 #include <linux/spi/spi.h>
1416 #include <linux/iio/iio.h>
1517 #include <linux/iio/sysfs.h>
@@ -422,9 +424,7 @@ static int max31856_probe(struct spi_device *spi) · 406 unmodified lines
422424 indio_dev->channels = max31856_channels;
423425 indio_dev->num_channels = ARRAY_SIZE(max31856_channels);
424426
425− ret = of_property_read_u32(spi->dev.of_node, "thermocouple-type",
426− &data->thermocouple_type);
427−
427+ ret = device_property_read_u32(&spi->dev, "thermocouple-type", &data->thermocouple_type);
428428 if (ret) {
429429 dev_info(&spi->dev,
430430 "Could not read thermocouple type DT property, configuring as a K-Type\n");
drivers/iio/temperature/max31865.c+3−1
@@ -12,9 +12,11 @@ · 11 unmodified lines
1212 #include <linux/delay.h>
1313 #include <linux/err.h>
1414 #include <linux/init.h>
15+#include <linux/mod_devicetable.h>
1516 #include <linux/module.h>
1617 #include <linux/iio/iio.h>
1718 #include <linux/iio/sysfs.h>
19+#include <linux/property.h>
1820 #include <linux/spi/spi.h>
1921 #include <asm/unaligned.h>
2022
@@ -305,7 +307,7 @@ static int max31865_probe(struct spi_device *spi) · 284 unmodified lines
305307 indio_dev->channels = max31865_channels;
306308 indio_dev->num_channels = ARRAY_SIZE(max31865_channels);
307309
308− if (of_property_read_bool(spi->dev.of_node, "maxim,3-wire")) {
310+ if (device_property_read_bool(&spi->dev, "maxim,3-wire")) {
309311 /* select 3 wire */
310312 data->three_wire = 1;
311313 } else {
drivers/iio/trigger/iio-trig-sysfs.c+5−6
@@ -176,16 +176,15 @@ out1: · 175 unmodified lines
176176
177177 static int iio_sysfs_trigger_remove(int id)
178178 {
179− bool foundit = false;
180− struct iio_sysfs_trig *t;
179+ struct iio_sysfs_trig *t = NULL, *iter;
181180
182181 mutex_lock(&iio_sysfs_trig_list_mut);
183− list_for_each_entry(t, &iio_sysfs_trig_list, l)
184− if (id == t->id) {
185− foundit = true;
182+ list_for_each_entry(iter, &iio_sysfs_trig_list, l)
183+ if (id == iter->id) {
184+ t = iter;
186185 break;
187186 }
188− if (!foundit) {
187+ if (!t) {
189188 mutex_unlock(&iio_sysfs_trig_list_mut);
190189 return -EINVAL;
191190 }
drivers/staging/iio/cdc/ad7746.c+1−1
@@ -290,7 +290,7 @@ static inline ssize_t ad7746_start_calib(struct device *dev, · 289 unmodified lines
290290 int ret, timeout = 10;
291291 bool doit;
292292
293− ret = strtobool(buf, &doit);
293+ ret = kstrtobool(buf, &doit);
294294 if (ret < 0)
295295 return ret;
296296
drivers/staging/iio/impedance-analyzer/ad5933.c+0−1
@@ -749,7 +749,6 @@ static int ad5933_probe(struct i2c_client *client, · 748 unmodified lines
749749 indio_dev->num_channels = ARRAY_SIZE(ad5933_channels);
750750
751751 ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
752− INDIO_BUFFER_SOFTWARE,
753752 &ad5933_ring_setup_ops);
754753 if (ret)
755754 return ret;
drivers/staging/iio/resolver/ad2s1210.c+0−1
@@ -499,7 +499,6 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, · 498 unmodified lines
499499 ret = IIO_VAL_INT;
500500 break;
501501 case IIO_ANGL_VEL:
502− negative = st->rx[0] & 0x80;
503502 vel = be16_to_cpup((__be16 *)st->rx);
504503 vel >>= 16 - st->resolution;
505504 if (vel & 0x8000) {
include/linux/iio/adc/ad_sigma_delta.h+38−0
@@ -32,26 +32,34 @@ struct iio_dev; · 31 unmodified lines
3232 /**
3333 * struct ad_sigma_delta_info - Sigma Delta driver specific callbacks and options
3434 * @set_channel: Will be called to select the current channel, may be NULL.
35+ * @append_status: Will be called to enable status append at the end of the sample, may be NULL.
3536 * @set_mode: Will be called to select the current mode, may be NULL.
37+ * @disable_all: Will be called to disable all channels, may be NULL.
3638 * @postprocess_sample: Is called for each sampled data word, can be used to
3739 * modify or drop the sample data, it, may be NULL.
3840 * @has_registers: true if the device has writable and readable registers, false
3941 * if there is just one read-only sample data shift register.
4042 * @addr_shift: Shift of the register address in the communications register.
4143 * @read_mask: Mask for the communications register having the read bit set.
44+ * @status_ch_mask: Mask for the channel number stored in status register.
4245 * @data_reg: Address of the data register, if 0 the default address of 0x3 will
4346 * be used.
4447 * @irq_flags: flags for the interrupt used by the triggered buffer
48+ * @num_slots: Number of sequencer slots
4549 */
4650 struct ad_sigma_delta_info {
4751 int (*set_channel)(struct ad_sigma_delta *, unsigned int channel);
52+ int (*append_status)(struct ad_sigma_delta *, bool append);
4853 int (*set_mode)(struct ad_sigma_delta *, enum ad_sigma_delta_mode mode);
54+ int (*disable_all)(struct ad_sigma_delta *);
4955 int (*postprocess_sample)(struct ad_sigma_delta *, unsigned int raw_sample);
5056 bool has_registers;
5157 unsigned int addr_shift;
5258 unsigned int read_mask;
59+ unsigned int status_ch_mask;
5360 unsigned int data_reg;
5461 unsigned long irq_flags;
62+ unsigned int num_slots;
5563 };
5664
5765 /**
@@ -76,6 +84,13 @@ struct ad_sigma_delta { · 18 unmodified lines
7684 uint8_t comm;
7785
7886 const struct ad_sigma_delta_info *info;
87+ unsigned int active_slots;
88+ unsigned int current_slot;
89+ unsigned int num_slots;
90+ bool status_appended;
91+ /* map slots to channels in order to know what to expect from devices */
92+ unsigned int *slots;
93+ uint8_t *samples_buf;
7994
8095 /*
8196 * DMA (thus cache coherency maintenance) requires the
@@ -97,6 +112,29 @@ static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd, · 15 unmodified lines
97112 return 0;
98113 }
99114
115+static inline int ad_sigma_delta_append_status(struct ad_sigma_delta *sd, bool append)
116+{
117+ int ret;
118+
119+ if (sd->info->append_status) {
120+ ret = sd->info->append_status(sd, append);
121+ if (ret < 0)
122+ return ret;
123+
124+ sd->status_appended = append;
125+ }
126+
127+ return 0;
128+}
129+
130+static inline int ad_sigma_delta_disable_all(struct ad_sigma_delta *sd)
131+{
132+ if (sd->info->disable_all)
133+ return sd->info->disable_all(sd);
134+
135+ return 0;
136+}
137+
100138 static inline int ad_sigma_delta_set_mode(struct ad_sigma_delta *sd,
101139 unsigned int mode)
102140 {
include/linux/iio/common/st_sensors.h+3−0
@@ -237,6 +237,7 @@ struct st_sensor_settings { · 236 unmodified lines
237237 * @hw_irq_trigger: if we're using the hardware interrupt on the sensor.
238238 * @hw_timestamp: Latest timestamp from the interrupt handler, when in use.
239239 * @buffer_data: Data used by buffer part.
240+ * @odr_lock: Local lock for preventing concurrent ODR accesses/changes
240241 */
241242 struct st_sensor_data {
242243 struct iio_trigger *trig;
@@ -261,6 +262,8 @@ struct st_sensor_data { · 18 unmodified lines
261262 s64 hw_timestamp;
262263
263264 char buffer_data[ST_SENSORS_MAX_BUFFER_SIZE] ____cacheline_aligned;
265+
266+ struct mutex odr_lock;
264267 };
265268
266269 #ifdef CONFIG_IIO_BUFFER
include/linux/iio/iio-opaque.h+4−0
@@ -7,6 +7,9 @@ · 6 unmodified lines
77 * struct iio_dev_opaque - industrial I/O device opaque information
88 * @indio_dev: public industrial I/O device information
99 * @id: used to identify device internally
10+ * @currentmode: operating mode currently in use, may be eventually
11+ * checked by device drivers but should be considered
12+ * read-only as this is a core internal bit
1013 * @driver_module: used to make it harder to undercut users
1114 * @info_exist_lock: lock to prevent use during removal
1215 * @trig_readonly: mark the current trigger immutable
@@ -36,6 +39,7 @@ · 23 unmodified lines
3639 */
3740 struct iio_dev_opaque {
3841 struct iio_dev indio_dev;
42+ int currentmode;
3943 int id;
4044 struct module *driver_module;
4145 struct mutex info_exist_lock;
include/linux/iio/iio.h+56−14
@@ -315,7 +315,54 @@ static inline bool iio_channel_has_available(const struct iio_chan_spec *chan, · 314 unmodified lines
315315 s64 iio_get_time_ns(const struct iio_dev *indio_dev);
316316 unsigned int iio_get_time_res(const struct iio_dev *indio_dev);
317317
318−/* Device operating modes */
318+/*
319+ * Device operating modes
320+ * @INDIO_DIRECT_MODE: There is an access to either:
321+ * a) The last single value available for devices that do not provide
322+ * on-demand reads.
323+ * b) A new value after performing an on-demand read otherwise.
324+ * On most devices, this is a single-shot read. On some devices with data
325+ * streams without an 'on-demand' function, this might also be the 'last value'
326+ * feature. Above all, this mode internally means that we are not in any of the
327+ * other modes, and sysfs reads should work.
328+ * Device drivers should inform the core if they support this mode.
329+ * @INDIO_BUFFER_TRIGGERED: Common mode when dealing with kfifo buffers.
330+ * It indicates that an explicit trigger is required. This requests the core to
331+ * attach a poll function when enabling the buffer, which is indicated by the
332+ * _TRIGGERED suffix.
333+ * The core will ensure this mode is set when registering a triggered buffer
334+ * with iio_triggered_buffer_setup().
335+ * @INDIO_BUFFER_SOFTWARE: Another kfifo buffer mode, but not event triggered.
336+ * No poll function can be attached because there is no triggered infrastructure
337+ * we can use to cause capture. There is a kfifo that the driver will fill, but
338+ * not "only one scan at a time". Typically, hardware will have a buffer that
339+ * can hold multiple scans. Software may read one or more scans at a single time
340+ * and push the available data to a Kfifo. This means the core will not attach
341+ * any poll function when enabling the buffer.
342+ * The core will ensure this mode is set when registering a simple kfifo buffer
343+ * with devm_iio_kfifo_buffer_setup().
344+ * @INDIO_BUFFER_HARDWARE: For specific hardware, if unsure do not use this mode.
345+ * Same as above but this time the buffer is not a kfifo where we have direct
346+ * access to the data. Instead, the consumer driver must access the data through
347+ * non software visible channels (or DMA when there is no demux possible in
348+ * software)
349+ * The core will ensure this mode is set when registering a dmaengine buffer
350+ * with devm_iio_dmaengine_buffer_setup().
351+ * @INDIO_EVENT_TRIGGERED: Very unusual mode.
352+ * Triggers usually refer to an external event which will start data capture.
353+ * Here it is kind of the opposite as, a particular state of the data might
354+ * produce an event which can be considered as an event. We don't necessarily
355+ * have access to the data itself, but to the event produced. For example, this
356+ * can be a threshold detector. The internal path of this mode is very close to
357+ * the INDIO_BUFFER_TRIGGERED mode.
358+ * The core will ensure this mode is set when registering a triggered event.
359+ * @INDIO_HARDWARE_TRIGGERED: Very unusual mode.
360+ * Here, triggers can result in data capture and can be routed to multiple
361+ * hardware components, which make them close to regular triggers in the way
362+ * they must be managed by the core, but without the entire interrupts/poll
363+ * functions burden. Interrupts are irrelevant as the data flow is hardware
364+ * mediated and distributed.
365+ */
319366 #define INDIO_DIRECT_MODE 0x01
320367 #define INDIO_BUFFER_TRIGGERED 0x02
321368 #define INDIO_BUFFER_SOFTWARE 0x04
@@ -488,8 +535,12 @@ struct iio_buffer_setup_ops { · 166 unmodified lines
488535
489536 /**
490537 * struct iio_dev - industrial I/O device
491− * @modes: [DRIVER] operating modes supported by device
492− * @currentmode: [INTERN] current operating mode
538+ * @modes: [DRIVER] bitmask listing all the operating modes
539+ * supported by the IIO device. This list should be
540+ * initialized before registering the IIO device. It can
541+ * also be filed up by the IIO core, as a result of
542+ * enabling particular features in the driver
543+ * (see iio_triggered_event_setup()).
493544 * @dev: [DRIVER] device structure, should be assigned a parent
494545 * and owner
495546 * @buffer: [DRIVER] any buffer present
@@ -516,7 +567,6 @@ struct iio_buffer_setup_ops { · 20 unmodified lines
516567 */
517568 struct iio_dev {
518569 int modes;
519− int currentmode;
520570 struct device dev;
521571
522572 struct iio_buffer *buffer;
@@ -543,6 +593,8 @@ struct iio_dev { · 20 unmodified lines
543593 };
544594
545595 int iio_device_id(struct iio_dev *indio_dev);
596+int iio_device_get_current_mode(struct iio_dev *indio_dev);
597+bool iio_buffer_enabled(struct iio_dev *indio_dev);
546598
547599 const struct iio_chan_spec
548600 *iio_find_channel_from_si(struct iio_dev *indio_dev, int si);
@@ -672,16 +724,6 @@ struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv); · 123 unmodified lines
672724 __printf(2, 3)
673725 struct iio_trigger *devm_iio_trigger_alloc(struct device *parent,
674726 const char *fmt, ...);
675−/**
676− * iio_buffer_enabled() - helper function to test if the buffer is enabled
677− * @indio_dev: IIO device structure for device
678− **/
679−static inline bool iio_buffer_enabled(struct iio_dev *indio_dev)
680−{
681− return indio_dev->currentmode
682− & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE |
683− INDIO_BUFFER_SOFTWARE);
684−}
685727
686728 /**
687729 * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry
include/linux/iio/kfifo_buf.h+2−3
@@ -12,11 +12,10 @@ void iio_kfifo_free(struct iio_buffer *r); · 11 unmodified lines
1212
1313 int devm_iio_kfifo_buffer_setup_ext(struct device *dev,
1414 struct iio_dev *indio_dev,
15− int mode_flags,
1615 const struct iio_buffer_setup_ops *setup_ops,
1716 const struct attribute **buffer_attrs);
1817
19−#define devm_iio_kfifo_buffer_setup(dev, indio_dev, mode_flags, setup_ops) \
20− devm_iio_kfifo_buffer_setup_ext((dev), (indio_dev), (mode_flags), (setup_ops), NULL)
18+#define devm_iio_kfifo_buffer_setup(dev, indio_dev, setup_ops) \
19+ devm_iio_kfifo_buffer_setup_ext((dev), (indio_dev), (setup_ops), NULL)
2120
2221 #endif