History

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

Jonathan writes: First set of new device support, cleanups and features for IIO in the 5.9 cycle Some new devices, but particularly good this time is the core rework coming from Alexandru. Some of this has been in Analog's tree a long time, but other parts are motivated by closing down common mistakes in new drivers. Changes since first try at this pull request: * Add missed patch to actually remove iio_priv_to_dev and as a result also drop a few ingenic patches that need to be updated to take this into account. * Fix an ordering issue int he pollfunc attach in the core rework. New device support * qcom pmic7 adc - New driver using common qcom-vadc library. Some associated cleanups and refactors. * invensense icm42600 - New driver supporting icm42600, icm42602, icm42605 and icm42622 via i2c or spi. These are all 6 axis IMUs with gyro and accelerometers. Driver supports buffered modes using the hardware fifo and interpolation for accurate timestamps. * sensirion scd30 - New driver for this carbon dioxide sensor including i2c and serial interfaces + bindings. Features * ak8975 - Add reset gpio support. * bma400 - Support SPI. * bmc150 - Document and add support for bmc156b and bmm150b, tidy up _magn endings. * bmi160 - Regulator and mount matrix support. * mxc4005 - Add ID for mxc6655 * rockchip-saradc - Triggered buffer support. DT bindings * qcom spmi-vadc converted to yaml + pmic7 bindings * ak8975 tidy up and convert to yaml + add reset-gpio binding * ingenic-adc -convert to yaml. Core rework all carried through by Alexandru Ardelean. * Assign parent device in the core rather than every driver. A few devices need to provide specific non standard parents, so there is support for overriding. * Start to take parts of struct iio_dev opaque to the drivers. This will be a long term job, but should reduce the number of drivers we get that use parts that are currently only 'internal' by documentation. * Move attach and detach of pollfunc to the core. Every triggered buffer using driver had to do the same thing, so lets do it in the core. The hard part here was getting all the drivers into canonical form so there would be no functional changes in this final patch. That's taken quite a lot of work over last couple of cycles! Cleanups and minor fixes. * docs - Improve IIO_CONCENTRATION channel type description in ABI docs. - Drop doubled word cases. - Http to Https conversion. * core - Make iio_device_get_drvdata take a const struct iio_dev * avoiding some nasty casts. * ADCs - Drop lots of users of of_match_ptr macro, includes of mod_devicetable.h and CONFIG_OF protections. These prevent use of ACPI PRP0001 with these drivers and get coppied into lots of new drivers. * ad5380 - Constify iio_chan_spec_ext_info * ad5592r - Constify iio_chan_spec_ext_info - Avoid use of iio_priv_to_dev (precursor to taking parts of iio_dev opaque) * ad8366 - Make gpio optional as doesn't matter if its there or not. * adis16480 - Use irq types instead of the flags. * atlas-ezo-sensor - Minimize scope of ret variable. * at91-adc - Add COMPILE_TEST dependency to driver to improve build coverage. - Avoid use of iio_priv_to_dev (precursor to taking parts of iio_dev opaque) * at91-sama5d2 - Avoid use of iio_priv_to_dev (precursor to taking parts of iio_dev opaque) - Drop Ludovic as a co-maintaienr. * cros_ec - Reapply the range after resume. - Add a read only frequency entry for legacy version. - Typo fixes * hts221 - Avoid use of iio_priv_to_dev (precursor to taking parts of iio_dev opaque) * inv_mpu - Drop double check on ACPI companion device. * iqs621 - Avoid use of iio_priv_to_dev (precursor to taking parts of iio_dev opaque) * iqs624 - Avoid use of iio_priv_to_dev (precursor to taking parts of iio_dev opaque) * max11100 - Constify iio_chan_spec * mmc35240 - Constify reg_default * rockchip-saradc - Move to managed allocators for everything in probe. - Use more distinctive prefix for channel macros. * stk3310 - Constify regmap_config. * stm32-adc - Avoid use of iio_priv_to_dev (precursor to taking parts of iio_dev opaque) * stm32-dfsdm-adc - Avoid use of iio_priv_to_dev (precursor to taking parts of iio_dev opaque) * ti-am335x - Use managed allocations where straight forward in probe function. * tsl2563 - Avoid use of iio_priv_to_dev (precursor to taking parts of iio_dev opaque) * tag 'iio-for-5.9a-take2' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (107 commits) iio: buffer: fix attach/detach pollfunc order iio: core: remove iio_priv_to_dev() helper Replace HTTP links with HTTPS ones: drivers/iio Replace HTTP links with HTTPS ones: Documentation/devicetree/bindings/iio dt-bindings: iio/adc: Convert ingenic-adc docs to YAML. iio: cros_ec_accel_legacy: Add Read Only frequency entries MAINTAINERS: adc: at91-sama5d2_adc: remove myself as co-maintainer iio: adc: ti_am335x_adc: alloc kfifo & IRQ via devm_ functions iio: adc: ti_am335x_adc: alloc channels via devm_kcalloc() iio:adc:ingenic: drop of_match_ptr protection and include mod_devicetable.h iio:adc:ti-tlc4541: Drop CONFIG_OF and of_match_ptr protections. iio:adc:ti-adc161s626: Drop of_match_ptr protection. iio:adc:ti-adc084s021: drop of_match_ptr protection iio:adc:ti-adc0832: drop CONFIG_OF and of_match_ptr protections iio:adc:ti-adc081c: Drop of_match_ptr and change to mod_devicetable.h iio:adc:sd_adc_modulator: Drop of_match_ptr and tweak includes iio:adc:mcp3422: remove CONFIG_OF and of_match_ptr protections iio:adc:mcp320x: Drop CONFIG_OF and of_match_ptr protections iio:adc:max1118: Drop CONFIG_OF / of_match_ptr protections iio:adc:max11100: Drop of_match_ptr protection / add mod_devicetable.h include ...

Greg Kroah-Hartman committed 6 years ago

Commit f6b35db2 parents 4193170 62a30a2429 files · +7973 −1642Browse files

Unified · Split

429 files
  1. Documentation/ABI/testing/sysfs-bus-iio +2 −1
  2. Documentation/ABI/testing/sysfs-bus-iio-icm42600 +20 −0
  3. Documentation/ABI/testing/sysfs-bus-iio-scd30 +34 −0
  4. Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +2 −2
  5. Documentation/devicetree/bindings/iio/adc/ingenic,adc.txt +0 −49
  6. Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml +71 −0
  7. Documentation/devicetree/bindings/iio/adc/qcom,spmi-vadc.txt +0 −173
  8. Documentation/devicetree/bindings/iio/adc/qcom,spmi-vadc.yaml +278 −0
  9. Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml +68 −0
  10. Documentation/devicetree/bindings/iio/dac/ti,dac7612.txt +1 −1
  11. Documentation/devicetree/bindings/iio/iio-bindings.txt +1 −1
  12. Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml +14 −0
  13. Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml +90 −0
  14. Documentation/devicetree/bindings/iio/light/apds9300.txt +1 −1
  15. Documentation/devicetree/bindings/iio/light/apds9960.txt +1 −1
  16. Documentation/devicetree/bindings/iio/light/opt3001.txt +1 −1
  17. Documentation/devicetree/bindings/iio/light/vl6180.txt +1 −1
  18. Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt +0 −30
  19. Documentation/devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml +83 −0
  20. Documentation/devicetree/bindings/iio/magnetometer/bmc150_magn.txt +5 −1
  21. Documentation/devicetree/bindings/iio/potentiometer/mcp41010.txt +1 −1
  22. Documentation/devicetree/bindings/iio/potentiostat/lmp91000.txt +2 −2
  23. Documentation/devicetree/bindings/iio/pressure/asc,dlhl60d.yaml +1 −1
  24. Documentation/devicetree/bindings/iio/proximity/devantech-srf04.yaml +2 −2
  25. Documentation/driver-api/generic-counter.rst +1 −1
  26. Documentation/driver-api/iio/buffers.rst +1 −1
  27. MAINTAINERS +17 −1
  28. drivers/counter/104-quad-8.c +0 −1
  29. drivers/counter/stm32-lptimer-cnt.c +0 −1
  30. drivers/iio/accel/Kconfig +7 −1
  31. drivers/iio/accel/Makefile +1 −0
  32. drivers/iio/accel/adis16201.c +0 −1
  33. drivers/iio/accel/adis16209.c +0 −1
  34. drivers/iio/accel/adxl345_core.c +1 −2
  35. drivers/iio/accel/adxl372.c +5 −16
  36. drivers/iio/accel/bma180.c +0 −1
  37. drivers/iio/accel/bma220_spi.c +0 −1
  38. drivers/iio/accel/bma400_core.c +0 −1
  39. drivers/iio/accel/bma400_spi.c +120 −0
  40. drivers/iio/accel/bmc150-accel-core.c +2 −3
  41. drivers/iio/accel/cros_ec_accel_legacy.c +45 −1
  42. drivers/iio/accel/da280.c +0 −1
  43. drivers/iio/accel/da311.c +0 −1
  44. drivers/iio/accel/dmard06.c +0 −1
  45. drivers/iio/accel/dmard09.c +0 −1
  46. drivers/iio/accel/dmard10.c +0 −1
  47. drivers/iio/accel/hid-sensor-accel-3d.c +0 −1
  48. drivers/iio/accel/kxcjk-1013.c +0 −3
  49. drivers/iio/accel/kxsd9.c +0 −3
  50. drivers/iio/accel/mc3230.c +0 −1
  51. drivers/iio/accel/mma7455_core.c +0 −1
  52. drivers/iio/accel/mma7660.c +0 −1
  53. drivers/iio/accel/mma8452.c +0 −1
  54. drivers/iio/accel/mma9551.c +0 −1
  55. drivers/iio/accel/mma9553.c +0 −1
  56. drivers/iio/accel/mxc4005.c +2 −1
  57. drivers/iio/accel/mxc6255.c +0 −1
  58. drivers/iio/accel/sca3000.c +0 −1
  59. drivers/iio/accel/ssp_accel_sensor.c +0 −2
  60. drivers/iio/accel/st_accel_buffer.c +5 −17
  61. drivers/iio/accel/stk8312.c +0 −3
  62. drivers/iio/accel/stk8ba50.c +0 −3
  63. drivers/iio/adc/Kconfig +1 −1
  64. drivers/iio/adc/ab8500-gpadc.c +0 −2
  65. drivers/iio/adc/ad7091r-base.c +0 −1
  66. drivers/iio/adc/ad7124.c +0 −1
  67. drivers/iio/adc/ad7192.c +0 −1
  68. drivers/iio/adc/ad7266.c +0 −4
  69. drivers/iio/adc/ad7291.c +0 −2
  70. drivers/iio/adc/ad7292.c +0 −1
  71. drivers/iio/adc/ad7298.c +0 −2
  72. drivers/iio/adc/ad7476.c +0 −3
  73. drivers/iio/adc/ad7606.c +1 −3
  74. drivers/iio/adc/ad7766.c +0 −3
  75. drivers/iio/adc/ad7768-1.c +1 −8
  76. drivers/iio/adc/ad7780.c +0 −1
  77. drivers/iio/adc/ad7791.c +0 −2
  78. drivers/iio/adc/ad7793.c +0 −2
  79. drivers/iio/adc/ad7887.c +0 −5
  80. drivers/iio/adc/ad7923.c +0 −2
  81. drivers/iio/adc/ad7949.c +1 −3
  82. drivers/iio/adc/ad799x.c +0 −2
  83. drivers/iio/adc/ad_sigma_delta.c +0 −5
  84. drivers/iio/adc/adi-axi-adc.c +0 −1
  85. drivers/iio/adc/aspeed_adc.c +0 −1
  86. drivers/iio/adc/at91-sama5d2_adc.c +17 −32
  87. drivers/iio/adc/at91_adc.c +15 −16
  88. drivers/iio/adc/axp20x_adc.c +0 −2
  89. drivers/iio/adc/axp288_adc.c +0 −1
  90. drivers/iio/adc/bcm_iproc_adc.c +0 −2
  91. drivers/iio/adc/berlin2-adc.c +0 −1
  92. drivers/iio/adc/cc10001_adc.c +0 −1
  93. drivers/iio/adc/cpcap-adc.c +6 −18
  94. drivers/iio/adc/da9150-gpadc.c +0 −2
  95. drivers/iio/adc/dln2-adc.c +1 −12
  96. drivers/iio/adc/envelope-detector.c +0 −2
  97. drivers/iio/adc/ep93xx_adc.c +0 −1
  98. drivers/iio/adc/exynos_adc.c +0 −2
  99. drivers/iio/adc/fsl-imx25-gcq.c +0 −1
  100. drivers/iio/adc/hi8435.c +2 −6
  101. drivers/iio/adc/hx711.c +0 −1
  102. drivers/iio/adc/imx7d_adc.c +0 −1
  103. drivers/iio/adc/ina2xx-adc.c +1 −3
  104. drivers/iio/adc/ingenic-adc.c +2 −4
  105. drivers/iio/adc/intel_mrfld_adc.c +0 −1
  106. drivers/iio/adc/lp8788_adc.c +0 −2
  107. drivers/iio/adc/lpc18xx_adc.c +0 −1
  108. drivers/iio/adc/lpc32xx_adc.c +2 −4
  109. drivers/iio/adc/ltc2471.c +0 −1
  110. drivers/iio/adc/ltc2485.c +0 −1
  111. drivers/iio/adc/ltc2496.c +2 −2
  112. drivers/iio/adc/ltc2497-core.c +0 −1
  113. drivers/iio/adc/ltc2497.c +2 −2
  114. drivers/iio/adc/max1027.c +2 −5
  115. drivers/iio/adc/max11100.c +3 −4
  116. drivers/iio/adc/max1118.c +2 −6
  117. drivers/iio/adc/max1241.c +0 −1
  118. drivers/iio/adc/max1363.c +4 −11
  119. drivers/iio/adc/max9611.c +0 −2
  120. drivers/iio/adc/mcp320x.c +6 −9
  121. drivers/iio/adc/mcp3422.c +4 −8
  122. drivers/iio/adc/mcp3911.c +0 −2
  123. drivers/iio/adc/men_z188_adc.c +0 −1
  124. drivers/iio/adc/meson_saradc.c +0 −2
  125. drivers/iio/adc/mt6577_auxadc.c +0 −1
  126. drivers/iio/adc/mxs-lradc-adc.c +0 −3
  127. drivers/iio/adc/nau7802.c +0 −2
  128. drivers/iio/adc/npcm_adc.c +0 −1
  129. drivers/iio/adc/palmas_gpadc.c +0 −1
  130. drivers/iio/adc/qcom-pm8xxx-xoadc.c +0 −2
  131. drivers/iio/adc/qcom-spmi-adc5.c +220 −24
  132. drivers/iio/adc/qcom-spmi-iadc.c +0 −2
  133. drivers/iio/adc/qcom-spmi-vadc.c +0 −2
  134. drivers/iio/adc/qcom-vadc-common.c +262 −0
  135. drivers/iio/adc/qcom-vadc-common.h +15 −0
  136. drivers/iio/adc/rcar-gyroadc.c +0 −2
  137. drivers/iio/adc/rn5t618-adc.c +0 −1
  138. drivers/iio/adc/rockchip_saradc.c +154 −65
  139. drivers/iio/adc/sc27xx_adc.c +0 −1
  140. drivers/iio/adc/sd_adc_modulator.c +3 −4
  141. drivers/iio/adc/spear_adc.c +0 −1
  142. drivers/iio/adc/stm32-adc.c +68 −87
  143. drivers/iio/adc/stm32-dfsdm-adc.c +37 −68
  144. drivers/iio/adc/stmpe-adc.c +0 −1
  145. drivers/iio/adc/stx104.c +0 −1
  146. drivers/iio/adc/sun4i-gpadc-iio.c +0 −2
  147. drivers/iio/adc/ti-adc081c.c +5 −9
  148. drivers/iio/adc/ti-adc0832.c +3 −8
  149. drivers/iio/adc/ti-adc084s021.c +3 −6
  150. drivers/iio/adc/ti-adc108s102.c +0 −1
  151. drivers/iio/adc/ti-adc12138.c +0 −1
  152. drivers/iio/adc/ti-adc128s052.c +3 −5
  153. drivers/iio/adc/ti-adc161s626.c +2 −3
  154. drivers/iio/adc/ti-ads1015.c +0 −4
  155. drivers/iio/adc/ti-ads124s08.c +1 −3
  156. drivers/iio/adc/ti-ads7950.c +1 −2
  157. drivers/iio/adc/ti-ads8344.c +1 −3
  158. drivers/iio/adc/ti-ads8688.c +0 −2
  159. drivers/iio/adc/ti-tlc4541.c +4 −6
  160. drivers/iio/adc/ti_am335x_adc.c +11 −27
  161. drivers/iio/adc/twl4030-madc.c +1 −3
  162. drivers/iio/adc/twl6030-gpadc.c +0 −1
  163. drivers/iio/adc/vf610_adc.c +1 −8
  164. drivers/iio/adc/viperboard_adc.c +0 −1
  165. drivers/iio/adc/xilinx-xadc-core.c +0 −4
  166. drivers/iio/afe/iio-rescale.c +0 −1
  167. drivers/iio/amplifiers/ad8366.c +5 −3
  168. drivers/iio/amplifiers/hmc425a.c +0 −1
  169. drivers/iio/buffer/industrialio-triggered-buffer.c +1 −9
  170. drivers/iio/chemical/Kconfig +33 −0
  171. drivers/iio/chemical/Makefile +3 −0
  172. drivers/iio/chemical/ams-iaq-core.c +0 −1
  173. drivers/iio/chemical/atlas-ezo-sensor.c +2 −3
  174. drivers/iio/chemical/atlas-sensor.c +1 −6
  175. drivers/iio/chemical/bme680_core.c +0 −1
  176. drivers/iio/chemical/ccs811.c +0 −1
  177. drivers/iio/chemical/pms7003.c +0 −1
  178. drivers/iio/chemical/scd30.h +78 −0
  179. drivers/iio/chemical/scd30_core.c +771 −0
  180. drivers/iio/chemical/scd30_i2c.c +139 −0
  181. drivers/iio/chemical/scd30_serial.c +263 −0
  182. drivers/iio/chemical/sgp30.c +0 −1
  183. drivers/iio/chemical/sps30.c +0 −1
  184. drivers/iio/chemical/vz89x.c +0 −1
  185. drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +5 −0
  186. drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +22 −2
  187. drivers/iio/common/st_sensors/st_sensors_i2c.c +0 −1
  188. drivers/iio/common/st_sensors/st_sensors_spi.c +0 −1
  189. drivers/iio/dac/ad5064.c +0 −1
  190. drivers/iio/dac/ad5360.c +0 −1
  191. drivers/iio/dac/ad5380.c +1 −2
  192. drivers/iio/dac/ad5421.c +0 −1
  193. drivers/iio/dac/ad5446.c +0 −2
  194. drivers/iio/dac/ad5449.c +0 −1
  195. drivers/iio/dac/ad5504.c +0 −1
  196. drivers/iio/dac/ad5592r-base.c +4 −5
  197. drivers/iio/dac/ad5624r_spi.c +0 −1
  198. drivers/iio/dac/ad5686.c +0 −1
  199. drivers/iio/dac/ad5755.c +0 −1
  200. drivers/iio/dac/ad5758.c +0 −1
  201. drivers/iio/dac/ad5761.c +0 −1
  202. drivers/iio/dac/ad5764.c +0 −1
  203. drivers/iio/dac/ad5770r.c +0 −1
  204. drivers/iio/dac/ad5791.c +0 −1
  205. drivers/iio/dac/ad7303.c +0 −1
  206. drivers/iio/dac/ad8801.c +0 −1
  207. drivers/iio/dac/cio-dac.c +0 −1
  208. drivers/iio/dac/dpot-dac.c +0 −1
  209. drivers/iio/dac/ds4424.c +0 −2
  210. drivers/iio/dac/lpc18xx_dac.c +0 −1
  211. drivers/iio/dac/ltc1660.c +0 −1
  212. drivers/iio/dac/ltc2632.c +0 −1
  213. drivers/iio/dac/m62332.c +0 −3
  214. drivers/iio/dac/max517.c +0 −3
  215. drivers/iio/dac/max5821.c +0 −1
  216. drivers/iio/dac/mcp4725.c +0 −1
  217. drivers/iio/dac/mcp4922.c +0 −1
  218. drivers/iio/dac/stm32-dac.c +0 −1
  219. drivers/iio/dac/ti-dac082s085.c +6 −7
  220. drivers/iio/dac/ti-dac5571.c +9 −11
  221. drivers/iio/dac/ti-dac7311.c +1 −3
  222. drivers/iio/dac/ti-dac7612.c +0 −1
  223. drivers/iio/dac/vf610_dac.c +0 −2
  224. drivers/iio/dummy/iio_simple_dummy.c +8 −6
  225. drivers/iio/dummy/iio_simple_dummy_buffer.c +0 −14
  226. drivers/iio/frequency/ad9523.c +0 −1
  227. drivers/iio/frequency/adf4350.c +0 −1
  228. drivers/iio/frequency/adf4371.c +0 −1
  229. drivers/iio/gyro/adis16080.c +0 −1
  230. drivers/iio/gyro/adis16130.c +0 −1
  231. drivers/iio/gyro/adis16136.c +0 −1
  232. drivers/iio/gyro/adis16260.c +0 −1
  233. drivers/iio/gyro/adxrs450.c +0 −1
  234. drivers/iio/gyro/bmg160_core.c +0 −3
  235. drivers/iio/gyro/fxas21002c_core.c +0 −1
  236. drivers/iio/gyro/hid-sensor-gyro-3d.c +0 −1
  237. drivers/iio/gyro/itg3200_core.c +0 −1
  238. drivers/iio/gyro/mpu3050-core.c +0 −3
  239. drivers/iio/gyro/ssp_gyro_sensor.c +0 −1
  240. drivers/iio/gyro/st_gyro_buffer.c +4 −17
  241. drivers/iio/health/afe4403.c +1 −2
  242. drivers/iio/health/afe4404.c +1 −2
  243. drivers/iio/health/afe440x.h +1 −1
  244. drivers/iio/health/max30100.c +0 −1
  245. drivers/iio/health/max30102.c +0 −1
  246. drivers/iio/humidity/am2315.c +0 −1
  247. drivers/iio/humidity/dht11.c +0 −1
  248. drivers/iio/humidity/hdc100x.c +6 −17
  249. drivers/iio/humidity/hid-sensor-humidity.c +0 −1
  250. drivers/iio/humidity/hts221.h +2 −2
  251. drivers/iio/humidity/hts221_buffer.c +5 −6
  252. drivers/iio/humidity/hts221_core.c +2 −3
  253. drivers/iio/humidity/htu21.c +0 −1
  254. drivers/iio/humidity/si7005.c +0 −1
  255. drivers/iio/humidity/si7020.c +0 −1
  256. drivers/iio/iio_core_trigger.h +17 −0
  257. drivers/iio/imu/Kconfig +1 −0
  258. drivers/iio/imu/Makefile +1 −0
  259. drivers/iio/imu/adis16400.c +0 −1
  260. drivers/iio/imu/adis16460.c +0 −1
  261. drivers/iio/imu/adis16475.c +0 −1
  262. drivers/iio/imu/adis16480.c +3 −4
  263. drivers/iio/imu/bmi160/bmi160.h +3 −0
  264. drivers/iio/imu/bmi160/bmi160_core.c +45 −2
  265. drivers/iio/imu/fxos8700_core.c +0 −1
  266. drivers/iio/imu/inv_icm42600/Kconfig +29 −0
  267. drivers/iio/imu/inv_icm42600/Makefile +15 −0
  268. drivers/iio/imu/inv_icm42600/inv_icm42600.h +395 −0
  269. drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +787 −0
  270. drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +601 −0
  271. drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.h +98 −0
  272. drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +786 −0
  273. drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +798 −0
  274. drivers/iio/imu/inv_icm42600/inv_icm42600_i2c.c +101 −0
  275. drivers/iio/imu/inv_icm42600/inv_icm42600_spi.c +100 −0
  276. drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c +84 −0
  277. drivers/iio/imu/inv_icm42600/inv_icm42600_temp.h +30 −0
  278. drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +195 −0
  279. drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h +85 −0
  280. drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c +1 −5
  281. drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +0 −1
  282. drivers/iio/imu/kmx61.c +0 −1
  283. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +0 −1
  284. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c +0 −1
  285. drivers/iio/industrialio-buffer.c +43 −15
  286. drivers/iio/industrialio-core.c +81 −48
  287. drivers/iio/industrialio-event.c +40 −28
  288. drivers/iio/industrialio-trigger.c +4 −18
  289. drivers/iio/light/acpi-als.c +0 −1
  290. drivers/iio/light/adjd_s311.c +0 −1
  291. drivers/iio/light/adux1020.c +0 −1
  292. drivers/iio/light/al3010.c +0 −1
  293. drivers/iio/light/al3320a.c +0 −1
  294. drivers/iio/light/apds9300.c +0 −1
  295. drivers/iio/light/apds9960.c +0 −1
  296. drivers/iio/light/bh1750.c +0 −1
  297. drivers/iio/light/bh1780.c +0 −1
  298. drivers/iio/light/cm32181.c +0 −1
  299. drivers/iio/light/cm3232.c +0 −1
  300. drivers/iio/light/cm3323.c +0 −1
  301. drivers/iio/light/cm3605.c +0 −1
  302. drivers/iio/light/cm36651.c +0 −1
  303. drivers/iio/light/cros_ec_light_prox.c +5 −1
  304. drivers/iio/light/gp2ap002.c +0 −1
  305. drivers/iio/light/gp2ap020a00f.c +0 −11
  306. drivers/iio/light/hid-sensor-als.c +0 −1
  307. drivers/iio/light/hid-sensor-prox.c +0 −1
  308. drivers/iio/light/iqs621-als.c +4 −3
  309. drivers/iio/light/isl29018.c +0 −1
  310. drivers/iio/light/isl29028.c +0 −1
  311. drivers/iio/light/isl29125.c +2 −19
  312. drivers/iio/light/jsa1212.c +0 −1
  313. drivers/iio/light/lm3533-als.c +1 −1
  314. drivers/iio/light/ltr501.c +0 −1
  315. drivers/iio/light/lv0104cs.c +1 −2
  316. drivers/iio/light/max44000.c +0 −1
  317. drivers/iio/light/max44009.c +0 −1
  318. drivers/iio/light/noa1305.c +0 −1
  319. drivers/iio/light/opt3001.c +1 −2
  320. drivers/iio/light/pa12203001.c +0 −1
  321. drivers/iio/light/rpr0521.c +0 −3
  322. drivers/iio/light/si1133.c +0 −1
  323. drivers/iio/light/si1145.c +0 −3
  324. drivers/iio/light/st_uvis25_core.c +0 −3
  325. drivers/iio/light/stk3310.c +1 −2
  326. drivers/iio/light/tcs3414.c +2 −19
  327. drivers/iio/light/tcs3472.c +0 −1
  328. drivers/iio/light/tsl2563.c +7 −6
  329. drivers/iio/light/tsl2583.c +0 −1
  330. drivers/iio/light/tsl2772.c +0 −1
  331. drivers/iio/light/tsl4531.c +0 −1
  332. drivers/iio/light/us5182d.c +0 −1
  333. drivers/iio/light/vcnl4000.c +7 −29
  334. drivers/iio/light/vcnl4035.c +0 −1
  335. drivers/iio/light/veml6030.c +0 −1
  336. drivers/iio/light/veml6070.c +0 −1
  337. drivers/iio/light/vl6180.c +0 −1
  338. drivers/iio/light/zopt2201.c +0 −1
  339. drivers/iio/magnetometer/ak8974.c +0 −1
  340. drivers/iio/magnetometer/ak8975.c +20 −3
  341. drivers/iio/magnetometer/bmc150_magn.c +0 −3
  342. drivers/iio/magnetometer/bmc150_magn_i2c.c +2 −1
  343. drivers/iio/magnetometer/hid-sensor-magn-3d.c +0 −1
  344. drivers/iio/magnetometer/hmc5843_core.c +0 −1
  345. drivers/iio/magnetometer/mag3110.c +0 −1
  346. drivers/iio/magnetometer/mmc35240.c +1 −2
  347. drivers/iio/magnetometer/rm3100-core.c +0 −3
  348. drivers/iio/magnetometer/st_magn_buffer.c +2 −24
  349. drivers/iio/multiplexer/iio-mux.c +0 −1
  350. drivers/iio/orientation/hid-sensor-incl-3d.c +0 −1
  351. drivers/iio/orientation/hid-sensor-rotation.c +0 −1
  352. drivers/iio/position/iqs624-pos.c +4 −3
  353. drivers/iio/potentiometer/ad5272.c +1 −2
  354. drivers/iio/potentiometer/ds1803.c +0 −1
  355. drivers/iio/potentiometer/max5432.c +0 −1
  356. drivers/iio/potentiometer/max5481.c +1 −2
  357. drivers/iio/potentiometer/max5487.c +0 −1
  358. drivers/iio/potentiometer/mcp4018.c +0 −1
  359. drivers/iio/potentiometer/mcp41010.c +1 −2
  360. drivers/iio/potentiometer/mcp4131.c +1 −2
  361. drivers/iio/potentiometer/mcp4531.c +0 −1
  362. drivers/iio/potentiometer/tpl0102.c +0 −1
  363. drivers/iio/potentiostat/lmp91000.c +2 −12
  364. drivers/iio/pressure/abp060mg.c +0 −1
  365. drivers/iio/pressure/bmp280-core.c +0 −1
  366. drivers/iio/pressure/cros_ec_baro.c +6 −2
  367. drivers/iio/pressure/dlhl60d.c +1 −3
  368. drivers/iio/pressure/dps310.c +0 −1
  369. drivers/iio/pressure/hid-sensor-press.c +0 −1
  370. drivers/iio/pressure/hp03.c +0 −1
  371. drivers/iio/pressure/hp206c.c +0 −1
  372. drivers/iio/pressure/icp10100.c +0 −1
  373. drivers/iio/pressure/mpl115.c +0 −1
  374. drivers/iio/pressure/mpl3115.c +0 −1
  375. drivers/iio/pressure/ms5611_core.c +0 −1
  376. drivers/iio/pressure/ms5637.c +0 −1
  377. drivers/iio/pressure/st_pressure_buffer.c +2 −24
  378. drivers/iio/pressure/t5403.c +0 −1
  379. drivers/iio/pressure/zpa2326.c +10 −18
  380. drivers/iio/proximity/as3935.c +0 −1
  381. drivers/iio/proximity/isl29501.c +0 −1
  382. drivers/iio/proximity/mb1232.c +0 −1
  383. drivers/iio/proximity/ping.c +0 −1
  384. drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +0 −1
  385. drivers/iio/proximity/rfd77402.c +0 −1
  386. drivers/iio/proximity/srf04.c +1 −2
  387. drivers/iio/proximity/srf08.c +3 −4
  388. drivers/iio/proximity/sx9310.c +0 −3
  389. drivers/iio/proximity/sx9500.c +0 −10
  390. drivers/iio/proximity/vcnl3020.c +0 −1
  391. drivers/iio/proximity/vl53l0x-i2c.c +0 −1
  392. drivers/iio/resolver/ad2s1200.c +0 −1
  393. drivers/iio/resolver/ad2s90.c +0 −1
  394. drivers/iio/temperature/hid-sensor-temperature.c +0 −1
  395. drivers/iio/temperature/iqs620at-temp.c +0 −1
  396. drivers/iio/temperature/ltc2983.c +0 −1
  397. drivers/iio/temperature/max31856.c +0 −2
  398. drivers/iio/temperature/maxim_thermocouple.c +0 −1
  399. drivers/iio/temperature/mlx90614.c +0 −1
  400. drivers/iio/temperature/mlx90632.c +0 −1
  401. drivers/iio/temperature/tmp006.c +0 −1
  402. drivers/iio/temperature/tmp007.c +0 −1
  403. drivers/iio/temperature/tsys01.c +0 −1
  404. drivers/iio/temperature/tsys02d.c +0 −1
  405. drivers/iio/trigger/stm32-timer-trigger.c +0 −2
  406. drivers/input/touchscreen/tsc2007_iio.c +0 −1
  407. drivers/platform/x86/toshiba_acpi.c +1 −2
  408. drivers/staging/iio/Documentation/device.txt +1 −3
  409. drivers/staging/iio/accel/adis16203.c +0 −1
  410. drivers/staging/iio/accel/adis16240.c +0 −1
  411. drivers/staging/iio/adc/ad7280a.c +0 −1
  412. drivers/staging/iio/adc/ad7816.c +0 −1
  413. drivers/staging/iio/addac/adt7316.c +0 −1
  414. drivers/staging/iio/cdc/ad7150.c +0 −2
  415. drivers/staging/iio/cdc/ad7746.c +0 −2
  416. drivers/staging/iio/frequency/ad9832.c +0 −1
  417. drivers/staging/iio/frequency/ad9834.c +0 −1
  418. drivers/staging/iio/impedance-analyzer/ad5933.c +0 −1
  419. drivers/staging/iio/resolver/ad2s1210.c +0 −1
  420. include/dt-bindings/iio/qcom,spmi-adc7-pm8350.h +67 −0
  421. include/dt-bindings/iio/qcom,spmi-adc7-pm8350b.h +88 −0
  422. include/dt-bindings/iio/qcom,spmi-adc7-pmk8350.h +46 −0
  423. include/dt-bindings/iio/qcom,spmi-adc7-pmr735a.h +28 −0
  424. include/dt-bindings/iio/qcom,spmi-adc7-pmr735b.h +28 −0
  425. include/dt-bindings/iio/qcom,spmi-vadc.h +77 −1
  426. include/linux/iio/common/cros_ec_sensors_core.h +10 −1
  427. include/linux/iio/iio-opaque.h +36 −0
  428. include/linux/iio/iio.h +29 −32
  429. include/linux/iio/trigger_consumer.h +0 −7
Documentation/ABI/testing/sysfs-bus-iio+2−1
@@ -1569,7 +1569,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_voc_raw · 1568 unmodified lines
15691569 KernelVersion: 4.3
15701570 Contact: linux-iio@vger.kernel.org
15711571 Description:
1572− Raw (unscaled no offset etc.) percentage reading of a substance.
1572+ Raw (unscaled no offset etc.) reading of a substance. Units
1573+ after application of scale and offset are percents.
15731574
15741575 What: /sys/bus/iio/devices/iio:deviceX/in_resistance_raw
15751576 What: /sys/bus/iio/devices/iio:deviceX/in_resistanceX_raw
Documentation/ABI/testing/sysfs-bus-iio-icm42600+20−0
@@ -0,0 +1,20 @@
1+What: /sys/bus/iio/devices/iio:deviceX/in_accel_x_calibbias
2+What: /sys/bus/iio/devices/iio:deviceX/in_accel_y_calibbias
3+What: /sys/bus/iio/devices/iio:deviceX/in_accel_z_calibbias
4+What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_x_calibbias
5+What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_y_calibbias
6+What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_z_calibbias
7+KernelVersion: 5.8
8+Contact: linux-iio@vger.kernel.org
9+Description:
10+ Hardware applied calibration offset (assumed to fix production
11+ inaccuracies). Values represent a real physical offset expressed
12+ in SI units (m/s^2 for accelerometer and rad/s for gyroscope).
13+
14+What: /sys/bus/iio/devices/iio:deviceX/in_accel_calibbias_available
15+What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_calibbias_available
16+KernelVersion: 5.8
17+Contact: linux-iio@vger.kernel.org
18+Description:
19+ Range of available values for hardware offset. Values in SI
20+ units (m/s^2 for accelerometer and rad/s for gyroscope).
Documentation/ABI/testing/sysfs-bus-iio-scd30+34−0
@@ -0,0 +1,34 @@
1+What: /sys/bus/iio/devices/iio:deviceX/calibration_auto_enable
2+Date: June 2020
3+KernelVersion: 5.8
4+Contact: linux-iio@vger.kernel.org
5+Description:
6+ Contaminants build-up in the measurement chamber or optical
7+ elements deterioration leads to sensor drift.
8+
9+ One can compensate for sensor drift by using automatic self
10+ calibration procedure (asc).
11+
12+ Writing 1 or 0 to this attribute will respectively activate or
13+ deactivate asc.
14+
15+ Upon reading current asc status is returned.
16+
17+What: /sys/bus/iio/devices/iio:deviceX/calibration_forced_value
18+Date: June 2020
19+KernelVersion: 5.8
20+Contact: linux-iio@vger.kernel.org
21+Description:
22+ Contaminants build-up in the measurement chamber or optical
23+ elements deterioration leads to sensor drift.
24+
25+ One can compensate for sensor drift by using forced
26+ recalibration (frc). This is useful in case there's known
27+ co2 reference available nearby the sensor.
28+
29+ Picking value from the range [400 1 2000] and writing it to the
30+ sensor will set frc.
31+
32+ Upon reading current frc value is returned. Note that after
33+ power cycling default value (i.e 400) is returned even though
34+ internally sensor had recalibrated itself.
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml+2−2
@@ -12,8 +12,8 @@ maintainers: · 11 unmodified lines
1212 description: |
1313 Analog Devices ADXL345/ADXL375 3-Axis Digital Accelerometers that supports
1414 both I2C & SPI interfaces.
15− http://www.analog.com/en/products/mems/accelerometers/adxl345.html
16− http://www.analog.com/en/products/sensors-mems/accelerometers/adxl375.html
15+ https://www.analog.com/en/products/mems/accelerometers/adxl345.html
16+ https://www.analog.com/en/products/sensors-mems/accelerometers/adxl375.html
1717
1818 properties:
1919 compatible:
Documentation/devicetree/bindings/iio/adc/ingenic,adc.txt+0−49
@@ -1,49 +0,0 @@
1−* Ingenic JZ47xx ADC controller IIO bindings
2−
3−Required properties:
4−
5−- compatible: Should be one of:
6− * ingenic,jz4725b-adc
7− * ingenic,jz4740-adc
8− * ingenic,jz4770-adc
9−- reg: ADC controller registers location and length.
10−- clocks: phandle to the SoC's ADC clock.
11−- clock-names: Must be set to "adc".
12−- #io-channel-cells: Must be set to <1> to indicate channels are selected
13− by index.
14−
15−ADC clients must use the format described in iio-bindings.txt, giving
16−a phandle and IIO specifier pair ("io-channels") to the ADC controller.
17−
18−Example:
19−
20−#include <dt-bindings/iio/adc/ingenic,adc.h>
21−
22−adc: adc@10070000 {
23− compatible = "ingenic,jz4740-adc";
24− #io-channel-cells = <1>;
25−
26− reg = <0x10070000 0x30>;
27−
28− clocks = <&cgu JZ4740_CLK_ADC>;
29− clock-names = "adc";
30−
31− interrupt-parent = <&intc>;
32− interrupts = <18>;
33−};
34−
35−adc-keys {
36− ...
37− compatible = "adc-keys";
38− io-channels = <&adc INGENIC_ADC_AUX>;
39− io-channel-names = "buttons";
40− ...
41−};
42−
43−battery {
44− ...
45− compatible = "ingenic,jz4740-battery";
46− io-channels = <&adc INGENIC_ADC_BATTERY>;
47− io-channel-names = "battery";
48− ...
49−};
Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml+71−0
@@ -0,0 +1,71 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+# Copyright 2019-2020 Artur Rojek
3+%YAML 1.2
4+---
5+$id: "http://devicetree.org/schemas/iio/adc/ingenic,adc.yaml#"
6+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
7+
8+title: Ingenic JZ47xx ADC controller IIO bindings
9+
10+maintainers:
11+ - Artur Rojek <contact@artur-rojek.eu>
12+
13+description: >
14+ Industrial I/O subsystem bindings for ADC controller found in
15+ Ingenic JZ47xx SoCs.
16+
17+ ADC clients must use the format described in iio-bindings.txt, giving
18+ a phandle and IIO specifier pair ("io-channels") to the ADC controller.
19+
20+properties:
21+ compatible:
22+ enum:
23+ - ingenic,jz4725b-adc
24+ - ingenic,jz4740-adc
25+ - ingenic,jz4770-adc
26+
27+ '#io-channel-cells':
28+ const: 1
29+ description:
30+ Must be set to <1> to indicate channels are selected by index.
31+
32+ reg:
33+ maxItems: 1
34+
35+ clocks:
36+ maxItems: 1
37+
38+ clock-names:
39+ items:
40+ - const: adc
41+
42+ interrupts:
43+ maxItems: 1
44+
45+required:
46+ - compatible
47+ - '#io-channel-cells'
48+ - reg
49+ - clocks
50+ - clock-names
51+ - interrupts
52+
53+additionalProperties: false
54+
55+examples:
56+ - |
57+ #include <dt-bindings/clock/jz4740-cgu.h>
58+ #include <dt-bindings/iio/adc/ingenic,adc.h>
59+
60+ adc@10070000 {
61+ compatible = "ingenic,jz4740-adc";
62+ #io-channel-cells = <1>;
63+
64+ reg = <0x10070000 0x30>;
65+
66+ clocks = <&cgu JZ4740_CLK_ADC>;
67+ clock-names = "adc";
68+
69+ interrupt-parent = <&intc>;
70+ interrupts = <18>;
71+ };
Documentation/devicetree/bindings/iio/adc/qcom,spmi-vadc.txt+0−173
@@ -1,173 +0,0 @@
1−Qualcomm's SPMI PMIC ADC
2−
3−- SPMI PMIC voltage ADC (VADC) provides interface to clients to read
4− voltage. The VADC is a 15-bit sigma-delta ADC.
5−- SPMI PMIC5 voltage ADC (ADC) provides interface to clients to read
6− voltage. The VADC is a 16-bit sigma-delta ADC.
7−
8−VADC node:
9−
10−- compatible:
11− Usage: required
12− Value type: <string>
13− Definition: Should contain "qcom,spmi-vadc".
14− Should contain "qcom,spmi-adc5" for PMIC5 ADC driver.
15− Should contain "qcom,spmi-adc-rev2" for PMIC rev2 ADC driver.
16− Should contain "qcom,pms405-adc" for PMS405 PMIC
17−
18−- reg:
19− Usage: required
20− Value type: <prop-encoded-array>
21− Definition: VADC base address in the SPMI PMIC register map.
22−
23−- #address-cells:
24− Usage: required
25− Value type: <u32>
26− Definition: Must be one. Child node 'reg' property should define ADC
27− channel number.
28−
29−- #size-cells:
30− Usage: required
31− Value type: <u32>
32− Definition: Must be zero.
33−
34−- #io-channel-cells:
35− Usage: required
36− Value type: <u32>
37− Definition: Must be one. For details about IIO bindings see:
38− Documentation/devicetree/bindings/iio/iio-bindings.txt
39−
40−- interrupts:
41− Usage: optional
42− Value type: <prop-encoded-array>
43− Definition: End of conversion interrupt.
44−
45−Channel node properties:
46−
47−- reg:
48− Usage: required
49− Value type: <u32>
50− Definition: ADC channel number.
51− See include/dt-bindings/iio/qcom,spmi-vadc.h
52−
53−- label:
54− Usage: required for "qcom,spmi-adc5" and "qcom,spmi-adc-rev2"
55− Value type: <empty>
56− Definition: ADC input of the platform as seen in the schematics.
57− For thermistor inputs connected to generic AMUX or GPIO inputs
58− these can vary across platform for the same pins. Hence select
59− the platform schematics name for this channel.
60−
61−- qcom,decimation:
62− Usage: optional
63− Value type: <u32>
64− Definition: This parameter is used to decrease ADC sampling rate.
65− Quicker measurements can be made by reducing decimation ratio.
66− - For compatible property "qcom,spmi-vadc", valid values are
67− 512, 1024, 2048, 4096. If property is not found, default value
68− of 512 will be used.
69− - For compatible property "qcom,spmi-adc5", valid values are 250, 420
70− and 840. If property is not found, default value of 840 is used.
71− - For compatible property "qcom,spmi-adc-rev2", valid values are 256,
72− 512 and 1024. If property is not present, default value is 1024.
73−
74−- qcom,pre-scaling:
75− Usage: optional
76− Value type: <u32 array>
77− Definition: Used for scaling the channel input signal before the signal is
78− fed to VADC. The configuration for this node is to know the
79− pre-determined ratio and use it for post scaling. Select one from
80− the following options.
81− <1 1>, <1 3>, <1 4>, <1 6>, <1 20>, <1 8>, <10 81>, <1 10>
82− If property is not found default value depending on chip will be used.
83−
84−- qcom,ratiometric:
85− Usage: optional
86− Value type: <empty>
87− Definition: Channel calibration type.
88− - For compatible property "qcom,spmi-vadc", if this property is
89− specified VADC will use the VDD reference (1.8V) and GND for
90− channel calibration. If property is not found, channel will be
91− calibrated with 0.625V and 1.25V reference channels, also
92− known as absolute calibration.
93− - For compatible property "qcom,spmi-adc5" and "qcom,spmi-adc-rev2",
94− if this property is specified VADC will use the VDD reference
95− (1.875V) and GND for channel calibration. If property is not found,
96− channel will be calibrated with 0V and 1.25V reference channels,
97− also known as absolute calibration.
98−
99−- qcom,hw-settle-time:
100− Usage: optional
101− Value type: <u32>
102− Definition: Time between AMUX getting configured and the ADC starting
103− conversion. The 'hw_settle_time' is an index used from valid values
104− and programmed in hardware to achieve the hardware settling delay.
105− - For compatible property "qcom,spmi-vadc" and "qcom,spmi-adc-rev2",
106− Delay = 100us * (hw_settle_time) for hw_settle_time < 11,
107− and 2ms * (hw_settle_time - 10) otherwise.
108− Valid values are: 0, 100, 200, 300, 400, 500, 600, 700, 800,
109− 900 us and 1, 2, 4, 6, 8, 10 ms.
110− If property is not found, channel will use 0us.
111− - For compatible property "qcom,spmi-adc5", delay = 15us for
112− value 0, 100us * (value) for values < 11,
113− and 2ms * (value - 10) otherwise.
114− Valid values are: 15, 100, 200, 300, 400, 500, 600, 700, 800,
115− 900 us and 1, 2, 4, 6, 8, 10 ms
116− Certain controller digital versions have valid values of
117− 15, 100, 200, 300, 400, 500, 600, 700, 1, 2, 4, 8, 16, 32, 64, 128 ms
118− If property is not found, channel will use 15us.
119−
120−- qcom,avg-samples:
121− Usage: optional
122− Value type: <u32>
123− Definition: Number of samples to be used for measurement.
124− Averaging provides the option to obtain a single measurement
125− from the ADC that is an average of multiple samples. The value
126− selected is 2^(value).
127− - For compatible property "qcom,spmi-vadc", valid values
128− are: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512
129− If property is not found, 1 sample will be used.
130− - For compatible property "qcom,spmi-adc5" and "qcom,spmi-adc-rev2",
131− valid values are: 1, 2, 4, 8, 16
132− If property is not found, 1 sample will be used.
133−
134−NOTE:
135−
136−For compatible property "qcom,spmi-vadc" following channels, also known as
137−reference point channels, are used for result calibration and their channel
138−configuration nodes should be defined:
139−VADC_REF_625MV and/or VADC_SPARE1(based on PMIC version) VADC_REF_1250MV,
140−VADC_GND_REF and VADC_VDD_VADC.
141−
142−Example:
143−
144−#include <dt-bindings/iio/qcom,spmi-vadc.h>
145−#include <linux/irq.h>
146−/* ... */
147−
148− /* VADC node */
149− pmic_vadc: vadc@3100 {
150− compatible = "qcom,spmi-vadc";
151− reg = <0x3100>;
152− interrupts = <0x0 0x31 0x0 IRQ_TYPE_EDGE_RISING>;
153− #address-cells = <1>;
154− #size-cells = <0>;
155− #io-channel-cells = <1>;
156− io-channel-ranges;
157−
158− /* Channel node */
159− adc-chan@VADC_LR_MUX10_USB_ID {
160− reg = <VADC_LR_MUX10_USB_ID>;
161− qcom,decimation = <512>;
162− qcom,ratiometric;
163− qcom,hw-settle-time = <200>;
164− qcom,avg-samples = <1>;
165− qcom,pre-scaling = <1 3>;
166− };
167− };
168−
169− /* IIO client node */
170− usb {
171− io-channels = <&pmic_vadc VADC_LR_MUX10_USB_ID>;
172− io-channel-names = "vadc";
173− };
Documentation/devicetree/bindings/iio/adc/qcom,spmi-vadc.yaml+278−0
@@ -0,0 +1,278 @@
1+# SPDX-License-Identifier: GPL-2.0-only
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/adc/qcom,spmi-vadc.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Qualcomm's SPMI PMIC ADC
8+
9+maintainers:
10+ - Andy Gross <agross@kernel.org>
11+ - Bjorn Andersson <bjorn.andersson@linaro.org>
12+
13+description: |
14+ SPMI PMIC voltage ADC (VADC) provides interface to clients to read
15+ voltage. The VADC is a 15-bit sigma-delta ADC.
16+ SPMI PMIC5/PMIC7 voltage ADC (ADC) provides interface to clients to read
17+ voltage. The VADC is a 16-bit sigma-delta ADC.
18+
19+properties:
20+ compatible:
21+ oneOf:
22+ - items:
23+ - const: qcom,pms405-adc
24+ - const: qcom,spmi-adc-rev2
25+
26+ - items:
27+ - enum:
28+ - qcom,spmi-vadc
29+ - qcom,spmi-adc5
30+ - qcom,spmi-adc-rev2
31+ - qcom,spmi-adc7
32+
33+ reg:
34+ description: VADC base address in the SPMI PMIC register map
35+ maxItems: 1
36+
37+ '#address-cells':
38+ const: 1
39+
40+ '#size-cells':
41+ const: 0
42+
43+ '#io-channel-cells':
44+ const: 1
45+
46+ interrupts:
47+ maxItems: 1
48+ description:
49+ End of conversion interrupt.
50+
51+required:
52+ - compatible
53+ - reg
54+ - '#address-cells'
55+ - '#size-cells'
56+ - '#io-channel-cells'
57+
58+patternProperties:
59+ "^.*@[0-9a-f]+$":
60+ type: object
61+ description: |
62+ Represents the external channels which are connected to the ADC.
63+ For compatible property "qcom,spmi-vadc" following channels, also known as
64+ reference point channels, are used for result calibration and their channel
65+ configuration nodes should be defined:
66+ VADC_REF_625MV and/or VADC_SPARE1(based on PMIC version) VADC_REF_1250MV,
67+ VADC_GND_REF and VADC_VDD_VADC.
68+
69+ properties:
70+ reg:
71+ description: |
72+ ADC channel number.
73+ See include/dt-bindings/iio/qcom,spmi-vadc.h
74+ For PMIC7 ADC, the channel numbers are specified separately per PMIC
75+ in the PMIC-specific files in include/dt-bindings/iio/.
76+
77+ label:
78+ $ref: /schemas/types.yaml#/definitions/string
79+ description: |
80+ ADC input of the platform as seen in the schematics.
81+ For thermistor inputs connected to generic AMUX or GPIO inputs
82+ these can vary across platform for the same pins. Hence select
83+ the platform schematics name for this channel.
84+
85+ qcom,decimation:
86+ $ref: /schemas/types.yaml#/definitions/uint32
87+ description: |
88+ This parameter is used to decrease ADC sampling rate.
89+ Quicker measurements can be made by reducing decimation ratio.
90+
91+ qcom,pre-scaling:
92+ description: |
93+ Used for scaling the channel input signal before the signal is
94+ fed to VADC. The configuration for this node is to know the
95+ pre-determined ratio and use it for post scaling. It is a pair of
96+ integers, denoting the numerator and denominator of the fraction by which
97+ input signal is multiplied. For example, <1 3> indicates the signal is scaled
98+ down to 1/3 of its value before ADC measurement.
99+ If property is not found default value depending on chip will be used.
100+ allOf:
101+ - $ref: /schemas/types.yaml#/definitions/uint32-array
102+ oneOf:
103+ - items:
104+ - const: 1
105+ - enum: [ 1, 3, 4, 6, 20, 8, 10 ]
106+
107+ - items:
108+ - const: 10
109+ - const: 81
110+
111+ qcom,ratiometric:
112+ description: |
113+ Channel calibration type.
114+ - For compatible property "qcom,spmi-vadc", if this property is
115+ specified VADC will use the VDD reference (1.8V) and GND for
116+ channel calibration. If property is not found, channel will be
117+ calibrated with 0.625V and 1.25V reference channels, also
118+ known as absolute calibration.
119+ - For compatible property "qcom,spmi-adc5", "qcom,spmi-adc7" and
120+ "qcom,spmi-adc-rev2", if this property is specified VADC will use
121+ the VDD reference (1.875V) and GND for channel calibration. If
122+ property is not found, channel will be calibrated with 0V and 1.25V
123+ reference channels, also known as absolute calibration.
124+ type: boolean
125+
126+ qcom,hw-settle-time:
127+ $ref: /schemas/types.yaml#/definitions/uint32
128+ description: |
129+ Time between AMUX getting configured and the ADC starting
130+ conversion. The 'hw_settle_time' is an index used from valid values
131+ and programmed in hardware to achieve the hardware settling delay.
132+
133+ qcom,avg-samples:
134+ $ref: /schemas/types.yaml#/definitions/uint32
135+ description: |
136+ Number of samples to be used for measurement.
137+ Averaging provides the option to obtain a single measurement
138+ from the ADC that is an average of multiple samples. The value
139+ selected is 2^(value).
140+
141+ required:
142+ - reg
143+
144+allOf:
145+ - if:
146+ properties:
147+ compatible:
148+ contains:
149+ const: qcom,spmi-vadc
150+
151+ then:
152+ patternProperties:
153+ "^.*@[0-9a-f]+$":
154+ properties:
155+ qcom,decimation:
156+ enum: [ 512, 1024, 2048, 4096 ]
157+ default: 512
158+
159+ qcom,hw-settle-time:
160+ enum: [ 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1, 2,
161+ 4, 6, 8, 10 ]
162+ default: 0
163+
164+ qcom,avg-samples:
165+ enum: [ 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 ]
166+ default: 1
167+
168+ - if:
169+ properties:
170+ compatible:
171+ contains:
172+ const: qcom,spmi-adc-rev2
173+
174+ then:
175+ patternProperties:
176+ "^.*@[0-9a-f]+$":
177+ properties:
178+ qcom,decimation:
179+ enum: [ 256, 512, 1024 ]
180+ default: 1024
181+
182+ qcom,hw-settle-time:
183+ enum: [ 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1, 2,
184+ 4, 6, 8, 10 ]
185+ default: 0
186+
187+ qcom,avg-samples:
188+ enum: [ 1, 2, 4, 8, 16 ]
189+ default: 1
190+
191+ - if:
192+ properties:
193+ compatible:
194+ contains:
195+ const: qcom,spmi-adc5
196+
197+ then:
198+ patternProperties:
199+ "^.*@[0-9a-f]+$":
200+ properties:
201+ qcom,decimation:
202+ enum: [ 250, 420, 840 ]
203+ default: 840
204+
205+ qcom,hw-settle-time:
206+ enum: [ 15, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1, 2,
207+ 4, 6, 8, 10, 16, 32, 64, 128 ]
208+ default: 15
209+
210+ qcom,avg-samples:
211+ enum: [ 1, 2, 4, 8, 16 ]
212+ default: 1
213+
214+ - if:
215+ properties:
216+ compatible:
217+ contains:
218+ const: qcom,spmi-adc7
219+
220+ then:
221+ patternProperties:
222+ "^.*@[0-9a-f]+$":
223+ properties:
224+ qcom,decimation:
225+ enum: [ 85, 340, 1360 ]
226+ default: 1360
227+
228+ qcom,hw-settle-time:
229+ enum: [ 15, 100, 200, 300, 400, 500, 600, 700, 1000, 2000, 4000,
230+ 8000, 16000, 32000, 64000, 128000 ]
231+ default: 15
232+
233+ qcom,avg-samples:
234+ enum: [ 1, 2, 4, 8, 16 ]
235+ default: 1
236+
237+examples:
238+ - |
239+ spmi_bus {
240+ #address-cells = <1>;
241+ #size-cells = <0>;
242+ /* VADC node */
243+ pmic_vadc: adc@3100 {
244+ compatible = "qcom,spmi-vadc";
245+ reg = <0x3100>;
246+ interrupts = <0x0 0x31 0x0 0x1>;
247+ #address-cells = <1>;
248+ #size-cells = <0>;
249+ #io-channel-cells = <1>;
250+ io-channel-ranges;
251+
252+ /* Channel node */
253+ adc-chan@39 {
254+ reg = <0x39>;
255+ qcom,decimation = <512>;
256+ qcom,ratiometric;
257+ qcom,hw-settle-time = <200>;
258+ qcom,avg-samples = <1>;
259+ qcom,pre-scaling = <1 3>;
260+ };
261+
262+ adc-chan@9 {
263+ reg = <0x9>;
264+ };
265+
266+ adc-chan@a {
267+ reg = <0xa>;
268+ };
269+
270+ adc-chan@e {
271+ reg = <0xe>;
272+ };
273+
274+ adc-chan@f {
275+ reg = <0xf>;
276+ };
277+ };
278+ };
Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml+68−0
@@ -0,0 +1,68 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/chemical/sensirion,scd30.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Sensirion SCD30 carbon dioxide sensor
8+
9+maintainers:
10+ - Tomasz Duszynski <tomasz.duszynski@octakon.com>
11+
12+description: |
13+ Air quality sensor capable of measuring co2 concentration, temperature
14+ and relative humidity.
15+
16+properties:
17+ compatible:
18+ enum:
19+ - sensirion,scd30
20+
21+ reg:
22+ maxItems: 1
23+
24+ interrupts:
25+ maxItems: 1
26+
27+ vdd-supply: true
28+
29+ sensirion,sel-gpios:
30+ description: GPIO connected to the SEL line
31+ maxItems: 1
32+
33+ sensirion,pwm-gpios:
34+ description: GPIO connected to the PWM line
35+ maxItems: 1
36+
37+required:
38+ - compatible
39+
40+additionalProperties: false
41+
42+examples:
43+ - |
44+ # include <dt-bindings/interrupt-controller/irq.h>
45+ i2c {
46+ #address-cells = <1>;
47+ #size-cells = <0>;
48+
49+ co2-sensor@61 {
50+ compatible = "sensirion,scd30";
51+ reg = <0x61>;
52+ vdd-supply = <&vdd>;
53+ interrupt-parent = <&gpio0>;
54+ interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
55+ };
56+ };
57+ - |
58+ # include <dt-bindings/interrupt-controller/irq.h>
59+ serial {
60+ co2-sensor {
61+ compatible = "sensirion,scd30";
62+ vdd-supply = <&vdd>;
63+ interrupt-parent = <&gpio0>;
64+ interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
65+ };
66+ };
67+
68+...
Documentation/devicetree/bindings/iio/dac/ti,dac7612.txt+1−1
@@ -6,7 +6,7 @@ Is is programmable through an SPI interface. · 5 unmodified lines
66
77 The internal DACs are loaded when the LOADDACS pin is pulled down.
88
9−http://www.ti.com/lit/ds/sbas106/sbas106.pdf
9+https://www.ti.com/lit/ds/sbas106/sbas106.pdf
1010
1111 Required Properties:
1212 - compatible: Should be one of:
Documentation/devicetree/bindings/iio/iio-bindings.txt+1−1
@@ -9,7 +9,7 @@ specifier is an array of one or more cells identifying the IIO · 8 unmodified lines
99 output on a device. The length of an IIO specifier is defined by the
1010 value of a #io-channel-cells property in the IIO provider node.
1111
12−[1] http://marc.info/?l=linux-iio&m=135902119507483&w=2
12+[1] https://marc.info/?l=linux-iio&m=135902119507483&w=2
1313
1414 ==IIO providers==
1515
Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml+14−0
@@ -37,6 +37,15 @@ properties: · 36 unmodified lines
3737 set if the specified interrupt pin should be configured as
3838 open drain. If not set, defaults to push-pull.
3939
40+ vdd-supply:
41+ description: provide VDD power to the sensor.
42+
43+ vddio-supply:
44+ description: provide VDD IO power to the sensor.
45+
46+ mount-matrix:
47+ description: an optional 3x3 mounting rotation matrix
48+
4049 required:
4150 - compatible
4251 - reg
@@ -52,9 +61,14 @@ examples: · 9 unmodified lines
5261 bmi160@68 {
5362 compatible = "bosch,bmi160";
5463 reg = <0x68>;
64+ vdd-supply = <&pm8916_l17>;
65+ vddio-supply = <&pm8916_l6>;
5566 interrupt-parent = <&gpio4>;
5667 interrupts = <12 IRQ_TYPE_EDGE_RISING>;
5768 interrupt-names = "INT1";
69+ mount-matrix = "0", "1", "0",
70+ "-1", "0", "0",
71+ "0", "0", "1";
5872 };
5973 };
6074 - |
Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml+90−0
@@ -0,0 +1,90 @@
1+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/imu/invensense,icm42600.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: InvenSense ICM-426xx Inertial Measurement Unit
8+
9+maintainers:
10+ - Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
11+
12+description: |
13+ 6-axis MotionTracking device that combines a 3-axis gyroscope and a 3-axis
14+ accelerometer.
15+
16+ It has a configurable host interface that supports I3C, I2C and SPI serial
17+ communication, features a 2kB FIFO and 2 programmable interrupts with
18+ ultra-low-power wake-on-motion support to minimize system power consumption.
19+
20+ Other industry-leading features include InvenSense on-chip APEX Motion
21+ Processing engine for gesture recognition, activity classification, and
22+ pedometer, along with programmable digital filters, and an embedded
23+ temperature sensor.
24+
25+ https://invensense.tdk.com/wp-content/uploads/2020/03/DS-000292-ICM-42605-v1.4.pdf
26+
27+properties:
28+ compatible:
29+ enum:
30+ - invensense,icm42600
31+ - invensense,icm42602
32+ - invensense,icm42605
33+ - invensense,icm42622
34+
35+ reg:
36+ maxItems: 1
37+
38+ interrupts:
39+ maxItems: 1
40+
41+ drive-open-drain:
42+ type: boolean
43+
44+ vdd-supply:
45+ description: Regulator that provides power to the sensor
46+
47+ vddio-supply:
48+ description: Regulator that provides power to the bus
49+
50+required:
51+ - compatible
52+ - reg
53+ - interrupts
54+
55+examples:
56+ - |
57+ #include <dt-bindings/gpio/gpio.h>
58+ #include <dt-bindings/interrupt-controller/irq.h>
59+ i2c0 {
60+ #address-cells = <1>;
61+ #size-cells = <0>;
62+
63+ icm42605@68 {
64+ compatible = "invensense,icm42605";
65+ reg = <0x68>;
66+ interrupt-parent = <&gpio2>;
67+ interrupts = <7 IRQ_TYPE_EDGE_FALLING>;
68+ vdd-supply = <&vdd>;
69+ vddio-supply = <&vddio>;
70+ };
71+ };
72+ - |
73+ #include <dt-bindings/gpio/gpio.h>
74+ #include <dt-bindings/interrupt-controller/irq.h>
75+ spi0 {
76+ #address-cells = <1>;
77+ #size-cells = <0>;
78+
79+ icm42602@0 {
80+ compatible = "invensense,icm42602";
81+ reg = <0>;
82+ spi-max-frequency = <24000000>;
83+ spi-cpha;
84+ spi-cpol;
85+ interrupt-parent = <&gpio1>;
86+ interrupts = <2 IRQ_TYPE_EDGE_FALLING>;
87+ vdd-supply = <&vdd>;
88+ vddio-supply = <&vddio>;
89+ };
90+ };
Documentation/devicetree/bindings/iio/light/apds9300.txt+1−1
@@ -1,6 +1,6 @@
11 * Avago APDS9300 ambient light sensor
22
3−http://www.avagotech.com/docs/AV02-1077EN
3+https://www.avagotech.com/docs/AV02-1077EN
44
55 Required properties:
66
Documentation/devicetree/bindings/iio/light/apds9960.txt+1−1
@@ -1,6 +1,6 @@
11 * Avago APDS9960 gesture/RGB/ALS/proximity sensor
22
3−http://www.avagotech.com/docs/AV02-4191EN
3+https://www.avagotech.com/docs/AV02-4191EN
44
55 Required properties:
66
Documentation/devicetree/bindings/iio/light/opt3001.txt+1−1
@@ -6,7 +6,7 @@ the optional generation of IIO events on rising/falling light threshold changes · 5 unmodified lines
66 requires the use of interrupts. Without interrupts, only the simple reading
77 of the current light value is supported through the IIO API.
88
9−http://www.ti.com/product/opt3001
9+https://www.ti.com/product/opt3001
1010
1111 Required properties:
1212 - compatible: should be "ti,opt3001"
Documentation/devicetree/bindings/iio/light/vl6180.txt+1−1
@@ -1,6 +1,6 @@
11 STMicro VL6180 - ALS, range and proximity sensor
22
3−Link to datasheet: http://www.st.com/resource/en/datasheet/vl6180x.pdf
3+Link to datasheet: https://www.st.com/resource/en/datasheet/vl6180x.pdf
44
55 Required properties:
66
Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt+0−30
@@ -1,30 +0,0 @@
1−* AsahiKASEI AK8975 magnetometer sensor
2−
3−Required properties:
4−
5− - compatible : should be "asahi-kasei,ak8975"
6− - reg : the I2C address of the magnetometer
7−
8−Optional properties:
9−
10− - gpios : should be device tree identifier of the magnetometer DRDY pin
11− - vdd-supply: an optional regulator that needs to be on to provide VDD
12− - mount-matrix: an optional 3x3 mounting rotation matrix
13−
14−Example:
15−
16−ak8975@c {
17− compatible = "asahi-kasei,ak8975";
18− reg = <0x0c>;
19− gpios = <&gpj0 7 0>;
20− vdd-supply = <&ldo_3v3_gnss>;
21− mount-matrix = "-0.984807753012208", /* x0 */
22− "0", /* y0 */
23− "-0.173648177666930", /* z0 */
24− "0", /* x1 */
25− "-1", /* y1 */
26− "0", /* z1 */
27− "-0.173648177666930", /* x2 */
28− "0", /* y2 */
29− "0.984807753012208"; /* z2 */
30−};
Documentation/devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml+83−0
@@ -0,0 +1,83 @@
1+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/iio/magnetometer/asahi-kasei,ak8975.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: AsahiKASEI AK8975 magnetometer sensor
8+
9+maintainers:
10+ - Jonathan Albrieux <jonathan.albrieux@gmail.com>
11+
12+properties:
13+ compatible:
14+ oneOf:
15+ - enum:
16+ - asahi-kasei,ak8975
17+ - asahi-kasei,ak8963
18+ - asahi-kasei,ak09911
19+ - asahi-kasei,ak09912
20+ - enum:
21+ - ak8975
22+ - ak8963
23+ - ak09911
24+ - ak09912
25+ deprecated: true
26+
27+ reg:
28+ maxItems: 1
29+
30+ gpios:
31+ maxItems: 1
32+ description: |
33+ AK8975 has a "Data ready" pin (DRDY) which informs that data
34+ is ready to be read and is possible to listen on it. If used,
35+ this should be active high. Prefer interrupt over this.
36+
37+ interrupts:
38+ maxItems: 1
39+ description: interrupt for DRDY pin. Triggered on rising edge.
40+
41+ vdd-supply:
42+ description: |
43+ an optional regulator that needs to be on to provide VDD power to
44+ the sensor.
45+
46+ mount-matrix:
47+ description: an optional 3x3 mounting rotation matrix.
48+
49+ reset-gpios:
50+ description: |
51+ an optional pin needed for AK09911 to set the reset state. This should
52+ be usually active low
53+
54+required:
55+ - compatible
56+ - reg
57+
58+examples:
59+ - |
60+ #include <dt-bindings/interrupt-controller/irq.h>
61+ #include <dt-bindings/gpio/gpio.h>
62+ i2c {
63+ #address-cells = <1>;
64+ #size-cells = <0>;
65+
66+ magnetometer@c {
67+ compatible = "asahi-kasei,ak8975";
68+ reg = <0x0c>;
69+ interrupt-parent = <&gpio6>;
70+ interrupts = <15 IRQ_TYPE_EDGE_RISING>;
71+ vdd-supply = <&ldo_3v3_gnss>;
72+ reset-gpios = <&msmgpio 111 GPIO_ACTIVE_LOW>;
73+ mount-matrix = "-0.984807753012208", /* x0 */
74+ "0", /* y0 */
75+ "-0.173648177666930", /* z0 */
76+ "0", /* x1 */
77+ "-1", /* y1 */
78+ "0", /* z1 */
79+ "-0.173648177666930", /* x2 */
80+ "0", /* y2 */
81+ "0.984807753012208"; /* z2 */
82+ };
83+ };
Documentation/devicetree/bindings/iio/magnetometer/bmc150_magn.txt+5−1
@@ -4,7 +4,11 @@ http://ae-bst.resource.bosch.com/media/products/dokumente/bmc150/BST-BMC150-DS00 · 3 unmodified lines
44
55 Required properties:
66
7− - compatible : should be "bosch,bmc150_magn"
7+ - compatible : should be one of:
8+ "bosch,bmc150_magn"
9+ "bosch,bmc156_magn"
10+ "bosch,bmm150"
11+ "bosch,bmm150_magn" (DEPRECATED, use bosch,bmm150)
812 - reg : the I2C address of the magnetometer
913
1014 Optional properties:
Documentation/devicetree/bindings/iio/potentiometer/mcp41010.txt+1−1
@@ -1,7 +1,7 @@
11 * Microchip MCP41010/41050/41100/42010/42050/42100 Digital Potentiometer
22
33 Datasheet publicly available at:
4−http://ww1.microchip.com/downloads/en/devicedoc/11195c.pdf
4+https://ww1.microchip.com/downloads/en/devicedoc/11195c.pdf
55
66 The node for this driver must be a child node of a SPI controller, hence
77 all mandatory properties described in
Documentation/devicetree/bindings/iio/potentiostat/lmp91000.txt+2−2
@@ -1,7 +1,7 @@
11 * Texas Instruments LMP91000 series of potentiostats
22
3−LMP91000: http://www.ti.com/lit/ds/symlink/lmp91000.pdf
4−LMP91002: http://www.ti.com/lit/ds/symlink/lmp91002.pdf
3+LMP91000: https://www.ti.com/lit/ds/symlink/lmp91000.pdf
4+LMP91002: https://www.ti.com/lit/ds/symlink/lmp91002.pdf
55
66 Required properties:
77
Documentation/devicetree/bindings/iio/pressure/asc,dlhl60d.yaml+1−1
@@ -13,7 +13,7 @@ description: | · 12 unmodified lines
1313 Bindings for the All Sensors DLH series pressure sensors.
1414
1515 Specifications about the sensors can be found at:
16− http://www.allsensors.com/cad/DS-0355_Rev_B.PDF
16+ https://www.allsensors.com/cad/DS-0355_Rev_B.PDF
1717
1818 properties:
1919 compatible:
Documentation/devicetree/bindings/iio/proximity/devantech-srf04.yaml+2−2
@@ -17,9 +17,9 @@ description: | · 16 unmodified lines
1717 until it is received once again
1818
1919 Specifications about the devices can be found at:
20− http://www.robot-electronics.co.uk/htm/srf04tech.htm
20+ https://www.robot-electronics.co.uk/htm/srf04tech.htm
2121
22− http://www.maxbotix.com/documents/LV-MaxSonar-EZ_Datasheet.pdf
22+ https://www.maxbotix.com/documents/LV-MaxSonar-EZ_Datasheet.pdf
2323
2424 properties:
2525 compatible:
Documentation/driver-api/generic-counter.rst+1−1
@@ -262,7 +262,7 @@ the system. · 261 unmodified lines
262262 Counter Counts may be allocated via counter_count structures, and
263263 respective Counter Signal associations (Synapses) made via
264264 counter_synapse structures. Associated counter_synapse structures are
265−stored as an array and set to the the synapses array member of the
265+stored as an array and set to the synapses array member of the
266266 respective counter_count structure. These counter_count structures are
267267 set to the counts array member of an allocated counter_device structure
268268 before the Counter is registered to the system.
Documentation/driver-api/iio/buffers.rst+1−1
@@ -88,7 +88,7 @@ fields in iio_chan_spec definition:: · 87 unmodified lines
8888 The driver implementing the accelerometer described above will have the
8989 following channel definition::
9090
91− struct struct iio_chan_spec accel_channels[] = {
91+ struct iio_chan_spec accel_channels[] = {
9292 {
9393 .type = IIO_ACCEL,
9494 .modified = 1,
MAINTAINERS+17−1
@@ -8979,6 +8979,14 @@ F: include/dt-bindings/interconnect/ · 8978 unmodified lines
89798979 F: include/linux/interconnect-provider.h
89808980 F: include/linux/interconnect.h
89818981
8982+INVENSENSE ICM-426xx IMU DRIVER
8983+M: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
8984+L: linux-iio@vger.kernel.org
8985+S: Maintained
8986+W https://invensense.tdk.com/
8987+F: Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml
8988+F: drivers/iio/imu/inv_icm42600/
8989+
89828990 INVENSENSE MPU-3050 GYROSCOPE DRIVER
89838991 M: Linus Walleij <linus.walleij@linaro.org>
89848992 L: linux-iio@vger.kernel.org
@@ -11324,7 +11332,6 @@ F: Documentation/devicetree/bindings/pwm/atmel-pwm.txt · 2339 unmodified lines
1132411332 F: drivers/pwm/pwm-atmel.c
1132511333
1132611334 MICROCHIP SAMA5D2-COMPATIBLE ADC DRIVER
11327−M: Ludovic Desroches <ludovic.desroches@microchip.com>
1132811335 M: Eugen Hristev <eugen.hristev@microchip.com>
1132911336 L: linux-iio@vger.kernel.org
1133011337 S: Supported
@@ -15373,6 +15380,15 @@ S: Maintained · 4042 unmodified lines
1537315380 F: drivers/misc/phantom.c
1537415381 F: include/uapi/linux/phantom.h
1537515382
15383+SENSIRION SCD30 CARBON DIOXIDE SENSOR DRIVER
15384+M: Tomasz Duszynski <tomasz.duszynski@octakon.com>
15385+S: Maintained
15386+F: Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml
15387+F: drivers/iio/chemical/scd30.h
15388+F: drivers/iio/chemical/scd30_core.c
15389+F: drivers/iio/chemical/scd30_i2c.c
15390+F: drivers/iio/chemical/scd30_serial.c
15391+
1537615392 SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER
1537715393 M: Tomasz Duszynski <tduszyns@gmail.com>
1537815394 S: Maintained
drivers/counter/104-quad-8.c+0−1
@@ -1538,7 +1538,6 @@ static int quad8_probe(struct device *dev, unsigned int id) · 1537 unmodified lines
15381538 indio_dev->num_channels = ARRAY_SIZE(quad8_channels);
15391539 indio_dev->channels = quad8_channels;
15401540 indio_dev->name = dev_name(dev);
1541− indio_dev->dev.parent = dev;
15421541
15431542 /* Initialize Counter device and driver data */
15441543 quad8iio = iio_priv(indio_dev);
drivers/counter/stm32-lptimer-cnt.c+0−1
@@ -648,7 +648,6 @@ static int stm32_lptim_cnt_probe(struct platform_device *pdev) · 647 unmodified lines
648648
649649 /* Initialize IIO device */
650650 indio_dev->name = dev_name(&pdev->dev);
651− indio_dev->dev.parent = &pdev->dev;
652651 indio_dev->dev.of_node = pdev->dev.of_node;
653652 indio_dev->info = &stm32_lptim_cnt_iio_info;
654653 if (ddata->has_encoder)
drivers/iio/accel/Kconfig+7−1
@@ -116,18 +116,24 @@ config BMA400 · 115 unmodified lines
116116 tristate "Bosch BMA400 3-Axis Accelerometer Driver"
117117 select REGMAP
118118 select BMA400_I2C if I2C
119+ select BMA400_SPI if SPI
119120 help
120121 Say Y here if you want to build a driver for the Bosch BMA400
121122 triaxial acceleration sensor.
122123
123124 To compile this driver as a module, choose M here: the
124125 module will be called bma400_core and you will also get
125− bma400_i2c if I2C is enabled.
126+ bma400_i2c if I2C is enabled and bma400_spi if SPI is
127+ enabled.
126128
127129 config BMA400_I2C
128130 tristate
129131 depends on BMA400
130132
133+config BMA400_SPI
134+ tristate
135+ depends on BMA400
136+
131137 config BMC150_ACCEL
132138 tristate "Bosch BMC150 Accelerometer Driver"
133139 select IIO_BUFFER
drivers/iio/accel/Makefile+1−0
@@ -16,6 +16,7 @@ obj-$(CONFIG_BMA180) += bma180.o · 15 unmodified lines
1616 obj-$(CONFIG_BMA220) += bma220_spi.o
1717 obj-$(CONFIG_BMA400) += bma400_core.o
1818 obj-$(CONFIG_BMA400_I2C) += bma400_i2c.o
19+obj-$(CONFIG_BMA400_SPI) += bma400_spi.o
1920 obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o
2021 obj-$(CONFIG_BMC150_ACCEL_I2C) += bmc150-accel-i2c.o
2122 obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
drivers/iio/accel/adis16201.c+0−1
@@ -271,7 +271,6 @@ static int adis16201_probe(struct spi_device *spi) · 270 unmodified lines
271271 spi_set_drvdata(spi, indio_dev);
272272
273273 indio_dev->name = spi->dev.driver->name;
274− indio_dev->dev.parent = &spi->dev;
275274 indio_dev->info = &adis16201_info;
276275
277276 indio_dev->channels = adis16201_channels;
drivers/iio/accel/adis16209.c+0−1
@@ -282,7 +282,6 @@ static int adis16209_probe(struct spi_device *spi) · 281 unmodified lines
282282 spi_set_drvdata(spi, indio_dev);
283283
284284 indio_dev->name = spi->dev.driver->name;
285− indio_dev->dev.parent = &spi->dev;
286285 indio_dev->info = &adis16209_info;
287286 indio_dev->channels = adis16209_channels;
288287 indio_dev->num_channels = ARRAY_SIZE(adis16209_channels);
drivers/iio/accel/adxl345_core.c+1−2
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 *
55 * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com>
66 *
7− * Datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf
7+ * Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf
88 */
99
1010 #include <linux/module.h>
@@ -246,7 +246,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, · 235 unmodified lines
246246 return ret;
247247 }
248248
249− indio_dev->dev.parent = dev;
250249 indio_dev->name = name;
251250 indio_dev->info = &adxl345_info;
252251 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/accel/adxl372.c+5−16
@@ -795,13 +795,9 @@ static int adxl372_buffer_postenable(struct iio_dev *indio_dev) · 794 unmodified lines
795795 unsigned int mask;
796796 int i, ret;
797797
798− ret = iio_triggered_buffer_postenable(indio_dev);
799− if (ret < 0)
800− return ret;
801−
802798 ret = adxl372_set_interrupts(st, ADXL372_INT1_MAP_FIFO_FULL_MSK, 0);
803799 if (ret < 0)
804− goto err;
800+ return ret;
805801
806802 mask = *indio_dev->active_scan_mask;
807803
@@ -810,10 +806,8 @@ static int adxl372_buffer_postenable(struct iio_dev *indio_dev) · 2 unmodified lines
810806 break;
811807 }
812808
813− if (i == ARRAY_SIZE(adxl372_axis_lookup_table)) {
814− ret = -EINVAL;
815− goto err;
816− }
809+ if (i == ARRAY_SIZE(adxl372_axis_lookup_table))
810+ return -EINVAL;
817811
818812 st->fifo_format = adxl372_axis_lookup_table[i].fifo_format;
819813 st->fifo_set_size = bitmap_weight(indio_dev->active_scan_mask,
@@ -833,14 +827,10 @@ static int adxl372_buffer_postenable(struct iio_dev *indio_dev) · 13 unmodified lines
833827 if (ret < 0) {
834828 st->fifo_mode = ADXL372_FIFO_BYPASSED;
835829 adxl372_set_interrupts(st, 0, 0);
836− goto err;
830+ return ret;
837831 }
838832
839833 return 0;
840−
841−err:
842− iio_triggered_buffer_predisable(indio_dev);
843− return ret;
844834 }
845835
846836 static int adxl372_buffer_predisable(struct iio_dev *indio_dev)
@@ -851,7 +841,7 @@ static int adxl372_buffer_predisable(struct iio_dev *indio_dev) · 4 unmodified lines
851841 st->fifo_mode = ADXL372_FIFO_BYPASSED;
852842 adxl372_configure_fifo(st);
853843
854− return iio_triggered_buffer_predisable(indio_dev);
844+ return 0;
855845 }
856846
857847 static const struct iio_buffer_setup_ops adxl372_buffer_ops = {
@@ -938,7 +928,6 @@ int adxl372_probe(struct device *dev, struct regmap *regmap, · 80 unmodified lines
938928 indio_dev->channels = adxl372_channels;
939929 indio_dev->num_channels = ARRAY_SIZE(adxl372_channels);
940930 indio_dev->available_scan_masks = adxl372_channel_masks;
941− indio_dev->dev.parent = dev;
942931 indio_dev->name = name;
943932 indio_dev->info = &adxl372_info;
944933 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
drivers/iio/accel/bma180.c+0−1
@@ -1038,7 +1038,6 @@ static int bma180_probe(struct i2c_client *client, · 1037 unmodified lines
10381038 goto err_chip_disable;
10391039
10401040 mutex_init(&data->mutex);
1041− indio_dev->dev.parent = dev;
10421041 indio_dev->channels = data->part_info->channels;
10431042 indio_dev->num_channels = data->part_info->num_channels;
10441043 indio_dev->name = id->name;
drivers/iio/accel/bma220_spi.c+0−1
@@ -237,7 +237,6 @@ static int bma220_probe(struct spi_device *spi) · 236 unmodified lines
237237 spi_set_drvdata(spi, indio_dev);
238238 mutex_init(&data->lock);
239239
240− indio_dev->dev.parent = &spi->dev;
241240 indio_dev->info = &bma220_info;
242241 indio_dev->name = BMA220_DEVICE_NAME;
243242 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/accel/bma400_core.c+0−1
@@ -816,7 +816,6 @@ int bma400_probe(struct device *dev, struct regmap *regmap, const char *name) · 815 unmodified lines
816816 return ret;
817817
818818 mutex_init(&data->mutex);
819− indio_dev->dev.parent = dev;
820819 indio_dev->name = name;
821820 indio_dev->info = &bma400_info;
822821 indio_dev->channels = bma400_channels;
drivers/iio/accel/bma400_spi.c+120−0
@@ -0,0 +1,120 @@
1+// SPDX-License-Identifier: GPL-2.0-only
2+/*
3+ * SPI IIO driver for Bosch BMA400 triaxial acceleration sensor.
4+ *
5+ * Copyright 2020 Dan Robertson <dan@dlrobertson.com>
6+ *
7+ */
8+#include <linux/bits.h>
9+#include <linux/init.h>
10+#include <linux/mod_devicetable.h>
11+#include <linux/module.h>
12+#include <linux/regmap.h>
13+#include <linux/spi/spi.h>
14+
15+#include "bma400.h"
16+
17+#define BMA400_MAX_SPI_READ 2
18+#define BMA400_SPI_READ_BUFFER_SIZE (BMA400_MAX_SPI_READ + 1)
19+
20+static int bma400_regmap_spi_read(void *context,
21+ const void *reg, size_t reg_size,
22+ void *val, size_t val_size)
23+{
24+ struct device *dev = context;
25+ struct spi_device *spi = to_spi_device(dev);
26+ u8 result[BMA400_SPI_READ_BUFFER_SIZE];
27+ ssize_t status;
28+
29+ if (val_size > BMA400_MAX_SPI_READ)
30+ return -EINVAL;
31+
32+ status = spi_write_then_read(spi, reg, 1, result, val_size + 1);
33+ if (status)
34+ return status;
35+
36+ /*
37+ * From the BMA400 datasheet:
38+ *
39+ * > For a basic read operation two bytes have to be read and the first
40+ * > has to be dropped and the second byte must be interpreted.
41+ */
42+ memcpy(val, result + 1, val_size);
43+
44+ return 0;
45+}
46+
47+static int bma400_regmap_spi_write(void *context, const void *data,
48+ size_t count)
49+{
50+ struct device *dev = context;
51+ struct spi_device *spi = to_spi_device(dev);
52+
53+ return spi_write(spi, data, count);
54+}
55+
56+static struct regmap_bus bma400_regmap_bus = {
57+ .read = bma400_regmap_spi_read,
58+ .write = bma400_regmap_spi_write,
59+ .read_flag_mask = BIT(7),
60+ .max_raw_read = BMA400_MAX_SPI_READ,
61+};
62+
63+static int bma400_spi_probe(struct spi_device *spi)
64+{
65+ const struct spi_device_id *id = spi_get_device_id(spi);
66+ struct regmap *regmap;
67+ unsigned int val;
68+ int ret;
69+
70+ regmap = devm_regmap_init(&spi->dev, &bma400_regmap_bus,
71+ &spi->dev, &bma400_regmap_config);
72+ if (IS_ERR(regmap)) {
73+ dev_err(&spi->dev, "failed to create regmap\n");
74+ return PTR_ERR(regmap);
75+ }
76+
77+ /*
78+ * Per the bma400 datasheet, the first SPI read may
79+ * return garbage. As the datasheet recommends, the
80+ * chip ID register will be read here and checked
81+ * again in the following probe.
82+ */
83+ ret = regmap_read(regmap, BMA400_CHIP_ID_REG, &val);
84+ if (ret)
85+ dev_err(&spi->dev, "Failed to read chip id register\n");
86+
87+ return bma400_probe(&spi->dev, regmap, id->name);
88+}
89+
90+static int bma400_spi_remove(struct spi_device *spi)
91+{
92+ return bma400_remove(&spi->dev);
93+}
94+
95+static const struct spi_device_id bma400_spi_ids[] = {
96+ { "bma400", 0 },
97+ { }
98+};
99+MODULE_DEVICE_TABLE(spi, bma400_spi_ids);
100+
101+static const struct of_device_id bma400_of_spi_match[] = {
102+ { .compatible = "bosch,bma400" },
103+ { }
104+};
105+MODULE_DEVICE_TABLE(of, bma400_of_spi_match);
106+
107+static struct spi_driver bma400_spi_driver = {
108+ .driver = {
109+ .name = "bma400",
110+ .of_match_table = bma400_of_spi_match,
111+ },
112+ .probe = bma400_spi_probe,
113+ .remove = bma400_spi_remove,
114+ .id_table = bma400_spi_ids,
115+};
116+
117+module_spi_driver(bma400_spi_driver);
118+MODULE_AUTHOR("Dan Robertson <dan@dlrobertson.com>");
119+MODULE_DESCRIPTION("Bosch BMA400 triaxial acceleration sensor (SPI)");
120+MODULE_LICENSE("GPL");
drivers/iio/accel/bmc150-accel-core.c+2−3
@@ -1411,7 +1411,7 @@ static int bmc150_accel_buffer_postenable(struct iio_dev *indio_dev) · 1410 unmodified lines
14111411 int ret = 0;
14121412
14131413 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1414− return iio_triggered_buffer_postenable(indio_dev);
1414+ return 0;
14151415
14161416 mutex_lock(&data->mutex);
14171417
@@ -1443,7 +1443,7 @@ static int bmc150_accel_buffer_predisable(struct iio_dev *indio_dev) · 25 unmodified lines
14431443 struct bmc150_accel_data *data = iio_priv(indio_dev);
14441444
14451445 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1446− return iio_triggered_buffer_predisable(indio_dev);
1446+ return 0;
14471447
14481448 mutex_lock(&data->mutex);
14491449
@@ -1574,7 +1574,6 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, · 124 unmodified lines
15741574
15751575 mutex_init(&data->mutex);
15761576
1577− indio_dev->dev.parent = dev;
15781577 indio_dev->channels = data->chip_info->channels;
15791578 indio_dev->num_channels = data->chip_info->num_channels;
15801579 indio_dev->name = name ? name : data->chip_info->name;
drivers/iio/accel/cros_ec_accel_legacy.c+45−1
@@ -33,6 +33,11 @@ · 32 unmodified lines
3333 */
3434 #define ACCEL_LEGACY_NSCALE 9586168
3535
36+/*
37+ * Sensor frequency is hard-coded to 10Hz.
38+ */
39+static const int cros_ec_legacy_sample_freq[] = { 10, 0 };
40+
3641 static int cros_ec_accel_legacy_read_cmd(struct iio_dev *indio_dev,
3742 unsigned long scan_mask, s16 *data)
3843 {
@@ -96,6 +101,11 @@ static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev, · 57 unmodified lines
96101 *val = 0;
97102 ret = IIO_VAL_INT;
98103 break;
104+ case IIO_CHAN_INFO_SAMP_FREQ:
105+ *val = cros_ec_legacy_sample_freq[0];
106+ *val2 = cros_ec_legacy_sample_freq[1];
107+ ret = IIO_VAL_INT_PLUS_MICRO;
108+ break;
99109 default:
100110 ret = cros_ec_sensors_core_read(st, chan, val, val2,
101111 mask);
@@ -120,9 +130,39 @@ static int cros_ec_accel_legacy_write(struct iio_dev *indio_dev, · 18 unmodified lines
120130 return -EINVAL;
121131 }
122132
133+/**
134+ * cros_ec_accel_legacy_read_avail() - get available values
135+ * @indio_dev: pointer to state information for device
136+ * @chan: channel specification structure table
137+ * @vals: list of available values
138+ * @type: type of data returned
139+ * @length: number of data returned in the array
140+ * @mask: specifies which values to be requested
141+ *
142+ * Return: an error code or IIO_AVAIL_LIST
143+ */
144+static int cros_ec_accel_legacy_read_avail(struct iio_dev *indio_dev,
145+ struct iio_chan_spec const *chan,
146+ const int **vals,
147+ int *type,
148+ int *length,
149+ long mask)
150+{
151+ switch (mask) {
152+ case IIO_CHAN_INFO_SAMP_FREQ:
153+ *length = ARRAY_SIZE(cros_ec_legacy_sample_freq);
154+ *vals = cros_ec_legacy_sample_freq;
155+ *type = IIO_VAL_INT_PLUS_MICRO;
156+ return IIO_AVAIL_LIST;
157+ }
158+
159+ return -EINVAL;
160+}
161+
123162 static const struct iio_info cros_ec_accel_legacy_info = {
124163 .read_raw = &cros_ec_accel_legacy_read,
125164 .write_raw = &cros_ec_accel_legacy_write,
165+ .read_avail = &cros_ec_accel_legacy_read_avail,
126166 };
127167
128168 /*
@@ -142,7 +182,11 @@ static const struct iio_info cros_ec_accel_legacy_info = { · 13 unmodified lines
142182 .info_mask_separate = \
143183 BIT(IIO_CHAN_INFO_RAW) | \
144184 BIT(IIO_CHAN_INFO_CALIBBIAS), \
145− .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE), \
185+ .info_mask_shared_by_all = \
186+ BIT(IIO_CHAN_INFO_SCALE) | \
187+ BIT(IIO_CHAN_INFO_SAMP_FREQ), \
188+ .info_mask_shared_by_all_available = \
189+ BIT(IIO_CHAN_INFO_SAMP_FREQ), \
146190 .ext_info = cros_ec_sensors_ext_info, \
147191 .scan_type = { \
148192 .sign = 's', \
drivers/iio/accel/da280.c+0−1
@@ -120,7 +120,6 @@ static int da280_probe(struct i2c_client *client, · 119 unmodified lines
120120 data->client = client;
121121 i2c_set_clientdata(client, indio_dev);
122122
123− indio_dev->dev.parent = &client->dev;
124123 indio_dev->info = &da280_info;
125124 indio_dev->modes = INDIO_DIRECT_MODE;
126125 indio_dev->channels = da280_channels;
drivers/iio/accel/da311.c+0−1
@@ -231,7 +231,6 @@ static int da311_probe(struct i2c_client *client, · 230 unmodified lines
231231 data->client = client;
232232 i2c_set_clientdata(client, indio_dev);
233233
234− indio_dev->dev.parent = &client->dev;
235234 indio_dev->info = &da311_info;
236235 indio_dev->name = "da311";
237236 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/accel/dmard06.c+0−1
@@ -161,7 +161,6 @@ static int dmard06_probe(struct i2c_client *client, · 160 unmodified lines
161161 dmard06->chip_id = ret;
162162
163163 i2c_set_clientdata(client, indio_dev);
164− indio_dev->dev.parent = &client->dev;
165164 indio_dev->name = DMARD06_DRV_NAME;
166165 indio_dev->modes = INDIO_DIRECT_MODE;
167166 indio_dev->channels = dmard06_channels;
drivers/iio/accel/dmard09.c+0−1
@@ -116,7 +116,6 @@ static int dmard09_probe(struct i2c_client *client, · 115 unmodified lines
116116 }
117117
118118 i2c_set_clientdata(client, indio_dev);
119− indio_dev->dev.parent = &client->dev;
120119 indio_dev->name = DMARD09_DRV_NAME;
121120 indio_dev->modes = INDIO_DIRECT_MODE;
122121 indio_dev->channels = dmard09_channels;
drivers/iio/accel/dmard10.c+0−1
@@ -196,7 +196,6 @@ static int dmard10_probe(struct i2c_client *client, · 195 unmodified lines
196196 data->client = client;
197197 i2c_set_clientdata(client, indio_dev);
198198
199− indio_dev->dev.parent = &client->dev;
200199 indio_dev->info = &dmard10_info;
201200 indio_dev->name = "dmard10";
202201 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/accel/hid-sensor-accel-3d.c+0−1
@@ -384,7 +384,6 @@ static int hid_accel_3d_probe(struct platform_device *pdev) · 383 unmodified lines
384384 goto error_free_dev_mem;
385385 }
386386
387− indio_dev->dev.parent = &pdev->dev;
388387 indio_dev->info = &accel_3d_info;
389388 indio_dev->name = name;
390389 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/accel/kxcjk-1013.c+0−3
@@ -1027,9 +1027,7 @@ static const struct iio_chan_spec kxcjk1013_channels[] = { · 1026 unmodified lines
10271027
10281028 static const struct iio_buffer_setup_ops kxcjk1013_buffer_setup_ops = {
10291029 .preenable = kxcjk1013_buffer_preenable,
1030− .postenable = iio_triggered_buffer_postenable,
10311030 .postdisable = kxcjk1013_buffer_postdisable,
1032− .predisable = iio_triggered_buffer_predisable,
10331031 };
10341032
10351033 static const struct iio_info kxcjk1013_info = {
@@ -1311,7 +1309,6 @@ static int kxcjk1013_probe(struct i2c_client *client, · 275 unmodified lines
13111309
13121310 mutex_init(&data->mutex);
13131311
1314− indio_dev->dev.parent = &client->dev;
13151312 indio_dev->channels = kxcjk1013_channels;
13161313 indio_dev->num_channels = ARRAY_SIZE(kxcjk1013_channels);
13171314 indio_dev->available_scan_masks = kxcjk1013_scan_masks;
drivers/iio/accel/kxsd9.c+0−3
@@ -252,8 +252,6 @@ static int kxsd9_buffer_postdisable(struct iio_dev *indio_dev) · 251 unmodified lines
252252
253253 static const struct iio_buffer_setup_ops kxsd9_buffer_setup_ops = {
254254 .preenable = kxsd9_buffer_preenable,
255− .postenable = iio_triggered_buffer_postenable,
256− .predisable = iio_triggered_buffer_predisable,
257255 .postdisable = kxsd9_buffer_postdisable,
258256 };
259257
@@ -411,7 +409,6 @@ int kxsd9_common_probe(struct device *dev, · 151 unmodified lines
411409 indio_dev->channels = kxsd9_channels;
412410 indio_dev->num_channels = ARRAY_SIZE(kxsd9_channels);
413411 indio_dev->name = name;
414− indio_dev->dev.parent = dev;
415412 indio_dev->info = &kxsd9_info;
416413 indio_dev->modes = INDIO_DIRECT_MODE;
417414 indio_dev->available_scan_masks = kxsd9_scan_masks;
drivers/iio/accel/mc3230.c+0−1
@@ -132,7 +132,6 @@ static int mc3230_probe(struct i2c_client *client, · 131 unmodified lines
132132 data->client = client;
133133 i2c_set_clientdata(client, indio_dev);
134134
135− indio_dev->dev.parent = &client->dev;
136135 indio_dev->info = &mc3230_info;
137136 indio_dev->name = "mc3230";
138137 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/accel/mma7455_core.c+0−1
@@ -260,7 +260,6 @@ int mma7455_core_probe(struct device *dev, struct regmap *regmap, · 259 unmodified lines
260260
261261 indio_dev->info = &mma7455_info;
262262 indio_dev->name = name;
263− indio_dev->dev.parent = dev;
264263 indio_dev->modes = INDIO_DIRECT_MODE;
265264 indio_dev->channels = mma7455_channels;
266265 indio_dev->num_channels = ARRAY_SIZE(mma7455_channels);
drivers/iio/accel/mma7660.c+0−1
@@ -188,7 +188,6 @@ static int mma7660_probe(struct i2c_client *client, · 187 unmodified lines
188188 mutex_init(&data->lock);
189189 data->mode = MMA7660_MODE_STANDBY;
190190
191− indio_dev->dev.parent = &client->dev;
192191 indio_dev->info = &mma7660_info;
193192 indio_dev->name = MMA7660_DRIVER_NAME;
194193 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/accel/mma8452.c+0−1
@@ -1592,7 +1592,6 @@ static int mma8452_probe(struct i2c_client *client, · 1591 unmodified lines
15921592 i2c_set_clientdata(client, indio_dev);
15931593 indio_dev->info = &mma8452_info;
15941594 indio_dev->name = id->name;
1595− indio_dev->dev.parent = &client->dev;
15961595 indio_dev->modes = INDIO_DIRECT_MODE;
15971596 indio_dev->channels = data->chip_info->channels;
15981597 indio_dev->num_channels = data->chip_info->num_channels;
drivers/iio/accel/mma9551.c+0−1
@@ -473,7 +473,6 @@ static int mma9551_probe(struct i2c_client *client, · 472 unmodified lines
473473
474474 mutex_init(&data->mutex);
475475
476− indio_dev->dev.parent = &client->dev;
477476 indio_dev->channels = mma9551_channels;
478477 indio_dev->num_channels = ARRAY_SIZE(mma9551_channels);
479478 indio_dev->name = name;
drivers/iio/accel/mma9553.c+0−1
@@ -1103,7 +1103,6 @@ static int mma9553_probe(struct i2c_client *client, · 1102 unmodified lines
11031103 if (ret < 0)
11041104 return ret;
11051105
1106− indio_dev->dev.parent = &client->dev;
11071106 indio_dev->channels = mma9553_channels;
11081107 indio_dev->num_channels = ARRAY_SIZE(mma9553_channels);
11091108 indio_dev->name = name;
drivers/iio/accel/mxc4005.c+2−1
@@ -416,7 +416,6 @@ static int mxc4005_probe(struct i2c_client *client, · 415 unmodified lines
416416
417417 mutex_init(&data->mutex);
418418
419− indio_dev->dev.parent = &client->dev;
420419 indio_dev->channels = mxc4005_channels;
421420 indio_dev->num_channels = ARRAY_SIZE(mxc4005_channels);
422421 indio_dev->available_scan_masks = mxc4005_scan_masks;
@@ -474,12 +473,14 @@ static int mxc4005_probe(struct i2c_client *client, · 51 unmodified lines
474473
475474 static const struct acpi_device_id mxc4005_acpi_match[] = {
476475 {"MXC4005", 0},
476+ {"MXC6655", 0},
477477 { },
478478 };
479479 MODULE_DEVICE_TABLE(acpi, mxc4005_acpi_match);
480480
481481 static const struct i2c_device_id mxc4005_id[] = {
482482 {"mxc4005", 0},
483+ {"mxc6655", 0},
483484 { },
484485 };
485486 MODULE_DEVICE_TABLE(i2c, mxc4005_id);
drivers/iio/accel/mxc6255.c+0−1
@@ -138,7 +138,6 @@ static int mxc6255_probe(struct i2c_client *client, · 137 unmodified lines
138138 data->regmap = regmap;
139139
140140 indio_dev->name = MXC6255_DRV_NAME;
141− indio_dev->dev.parent = &client->dev;
142141 indio_dev->channels = mxc6255_channels;
143142 indio_dev->num_channels = ARRAY_SIZE(mxc6255_channels);
144143 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/accel/sca3000.c+0−1
@@ -1467,7 +1467,6 @@ static int sca3000_probe(struct spi_device *spi) · 1466 unmodified lines
14671467 st->info = &sca3000_spi_chip_info_tbl[spi_get_device_id(spi)
14681468 ->driver_data];
14691469
1470− indio_dev->dev.parent = &spi->dev;
14711470 indio_dev->name = spi_get_device_id(spi)->name;
14721471 indio_dev->info = &sca3000_info;
14731472 if (st->info->temp_output) {
drivers/iio/accel/ssp_accel_sensor.c+0−2
@@ -108,8 +108,6 @@ static int ssp_accel_probe(struct platform_device *pdev) · 107 unmodified lines
108108 spd->type = SSP_ACCELEROMETER_SENSOR;
109109
110110 indio_dev->name = ssp_accel_device_name;
111− indio_dev->dev.parent = &pdev->dev;
112− indio_dev->dev.of_node = pdev->dev.of_node;
113111 indio_dev->info = &ssp_accel_iio_info;
114112 indio_dev->modes = INDIO_BUFFER_SOFTWARE;
115113 indio_dev->channels = ssp_acc_channels;
drivers/iio/accel/st_accel_buffer.c+5−17
@@ -33,13 +33,9 @@ static int st_accel_buffer_postenable(struct iio_dev *indio_dev) · 32 unmodified lines
3333 {
3434 int err;
3535
36− err = iio_triggered_buffer_postenable(indio_dev);
37− if (err < 0)
38− return err;
39−
4036 err = st_sensors_set_axis_enable(indio_dev, indio_dev->active_scan_mask[0]);
4137 if (err < 0)
42− goto st_accel_buffer_predisable;
38+ return err;
4339
4440 err = st_sensors_set_enable(indio_dev, true);
4541 if (err < 0)
@@ -49,27 +45,19 @@ static int st_accel_buffer_postenable(struct iio_dev *indio_dev) · 3 unmodified lines
4945
5046 st_accel_buffer_enable_all_axis:
5147 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
52−st_accel_buffer_predisable:
53− iio_triggered_buffer_predisable(indio_dev);
5448 return err;
5549 }
5650
5751 static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
5852 {
59− int err, err2;
53+ int err;
6054
6155 err = st_sensors_set_enable(indio_dev, false);
6256 if (err < 0)
63− goto st_accel_buffer_predisable;
64−
65− err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
66−
67−st_accel_buffer_predisable:
68− err2 = iio_triggered_buffer_predisable(indio_dev);
69− if (!err)
70− err = err2;
57+ return err;
7158
72− return err;
59+ return st_sensors_set_axis_enable(indio_dev,
60+ ST_SENSORS_ENABLE_ALL_AXIS);
7361 }
7462
7563 static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = {
drivers/iio/accel/stk8312.c+0−3
@@ -492,8 +492,6 @@ static int stk8312_buffer_postdisable(struct iio_dev *indio_dev) · 491 unmodified lines
492492
493493 static const struct iio_buffer_setup_ops stk8312_buffer_setup_ops = {
494494 .preenable = stk8312_buffer_preenable,
495− .postenable = iio_triggered_buffer_postenable,
496− .predisable = iio_triggered_buffer_predisable,
497495 .postdisable = stk8312_buffer_postdisable,
498496 };
499497
@@ -515,7 +513,6 @@ static int stk8312_probe(struct i2c_client *client, · 15 unmodified lines
515513 i2c_set_clientdata(client, indio_dev);
516514 mutex_init(&data->lock);
517515
518− indio_dev->dev.parent = &client->dev;
519516 indio_dev->info = &stk8312_info;
520517 indio_dev->name = STK8312_DRIVER_NAME;
521518 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/accel/stk8ba50.c+0−3
@@ -376,8 +376,6 @@ static int stk8ba50_buffer_postdisable(struct iio_dev *indio_dev) · 375 unmodified lines
376376
377377 static const struct iio_buffer_setup_ops stk8ba50_buffer_setup_ops = {
378378 .preenable = stk8ba50_buffer_preenable,
379− .postenable = iio_triggered_buffer_postenable,
380− .predisable = iio_triggered_buffer_predisable,
381379 .postdisable = stk8ba50_buffer_postdisable,
382380 };
383381
@@ -399,7 +397,6 @@ static int stk8ba50_probe(struct i2c_client *client, · 15 unmodified lines
399397 i2c_set_clientdata(client, indio_dev);
400398 mutex_init(&data->lock);
401399
402− indio_dev->dev.parent = &client->dev;
403400 indio_dev->info = &stk8ba50_info;
404401 indio_dev->name = STK8BA50_DRIVER_NAME;
405402 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/Kconfig+1−1
@@ -294,7 +294,7 @@ config ASPEED_ADC · 293 unmodified lines
294294
295295 config AT91_ADC
296296 tristate "Atmel AT91 ADC"
297− depends on ARCH_AT91
297+ depends on ARCH_AT91 || COMPILE_TEST
298298 depends on INPUT && SYSFS
299299 select IIO_BUFFER
300300 select IIO_TRIGGERED_BUFFER
drivers/iio/adc/ab8500-gpadc.c+0−2
@@ -1163,8 +1163,6 @@ static int ab8500_gpadc_probe(struct platform_device *pdev) · 1162 unmodified lines
11631163
11641164 pm_runtime_put(dev);
11651165
1166− indio_dev->dev.parent = dev;
1167− indio_dev->dev.of_node = np;
11681166 indio_dev->name = "ab8500-gpadc";
11691167 indio_dev->modes = INDIO_DIRECT_MODE;
11701168 indio_dev->info = &ab8500_gpadc_info;
drivers/iio/adc/ad7091r-base.c+0−1
@@ -224,7 +224,6 @@ int ad7091r_probe(struct device *dev, const char *name, · 223 unmodified lines
224224 st->chip_info = chip_info;
225225 st->map = map;
226226
227− iio_dev->dev.parent = dev;
228227 iio_dev->name = name;
229228 iio_dev->info = &ad7091r_info;
230229 iio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/ad7124.c+0−1
@@ -683,7 +683,6 @@ static int ad7124_probe(struct spi_device *spi) · 682 unmodified lines
683683
684684 spi_set_drvdata(spi, indio_dev);
685685
686− indio_dev->dev.parent = &spi->dev;
687686 indio_dev->name = spi_get_device_id(spi)->name;
688687 indio_dev->modes = INDIO_DIRECT_MODE;
689688 indio_dev->info = &ad7124_info;
drivers/iio/adc/ad7192.c+0−1
@@ -970,7 +970,6 @@ static int ad7192_probe(struct spi_device *spi) · 969 unmodified lines
970970
971971 spi_set_drvdata(spi, indio_dev);
972972 st->chip_info = of_device_get_match_data(&spi->dev);
973− indio_dev->dev.parent = &spi->dev;
974973 indio_dev->name = st->chip_info->name;
975974 indio_dev->modes = INDIO_DIRECT_MODE;
976975
drivers/iio/adc/ad7266.c+0−4
@@ -74,8 +74,6 @@ static int ad7266_postdisable(struct iio_dev *indio_dev) · 73 unmodified lines
7474
7575 static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {
7676 .preenable = &ad7266_preenable,
77− .postenable = &iio_triggered_buffer_postenable,
78− .predisable = &iio_triggered_buffer_predisable,
7977 .postdisable = &ad7266_postdisable,
8078 };
8179
@@ -437,8 +435,6 @@ static int ad7266_probe(struct spi_device *spi) · 355 unmodified lines
437435 spi_set_drvdata(spi, indio_dev);
438436 st->spi = spi;
439437
440− indio_dev->dev.parent = &spi->dev;
441− indio_dev->dev.of_node = spi->dev.of_node;
442438 indio_dev->name = spi_get_device_id(spi)->name;
443439 indio_dev->modes = INDIO_DIRECT_MODE;
444440 indio_dev->info = &ad7266_info;
drivers/iio/adc/ad7291.c+0−2
@@ -502,8 +502,6 @@ static int ad7291_probe(struct i2c_client *client, · 501 unmodified lines
502502 indio_dev->channels = ad7291_channels;
503503 indio_dev->num_channels = ARRAY_SIZE(ad7291_channels);
504504
505− indio_dev->dev.parent = &client->dev;
506− indio_dev->dev.of_node = client->dev.of_node;
507505 indio_dev->info = &ad7291_info;
508506 indio_dev->modes = INDIO_DIRECT_MODE;
509507
drivers/iio/adc/ad7292.c+0−1
@@ -304,7 +304,6 @@ static int ad7292_probe(struct spi_device *spi) · 303 unmodified lines
304304 st->vref_mv = 1250;
305305 }
306306
307− indio_dev->dev.parent = &spi->dev;
308307 indio_dev->name = spi_get_device_id(spi)->name;
309308 indio_dev->modes = INDIO_DIRECT_MODE;
310309 indio_dev->info = &ad7292_info;
drivers/iio/adc/ad7298.c+0−2
@@ -312,8 +312,6 @@ static int ad7298_probe(struct spi_device *spi) · 311 unmodified lines
312312 st->spi = spi;
313313
314314 indio_dev->name = spi_get_device_id(spi)->name;
315− indio_dev->dev.parent = &spi->dev;
316− indio_dev->dev.of_node = spi->dev.of_node;
317315 indio_dev->modes = INDIO_DIRECT_MODE;
318316 indio_dev->channels = ad7298_channels;
319317 indio_dev->num_channels = ARRAY_SIZE(ad7298_channels);
drivers/iio/adc/ad7476.c+0−3
@@ -300,9 +300,6 @@ static int ad7476_probe(struct spi_device *spi) · 299 unmodified lines
300300
301301 st->spi = spi;
302302
303− /* Establish that the iio_dev is a child of the spi device */
304− indio_dev->dev.parent = &spi->dev;
305− indio_dev->dev.of_node = spi->dev.of_node;
306303 indio_dev->name = spi_get_device_id(spi)->name;
307304 indio_dev->modes = INDIO_DIRECT_MODE;
308305 indio_dev->channels = st->chip_info->channel;
drivers/iio/adc/ad7606.c+1−3
@@ -499,7 +499,6 @@ static int ad7606_buffer_postenable(struct iio_dev *indio_dev) · 498 unmodified lines
499499 {
500500 struct ad7606_state *st = iio_priv(indio_dev);
501501
502− iio_triggered_buffer_postenable(indio_dev);
503502 gpiod_set_value(st->gpio_convst, 1);
504503
505504 return 0;
@@ -511,7 +510,7 @@ static int ad7606_buffer_predisable(struct iio_dev *indio_dev) · 5 unmodified lines
511510
512511 gpiod_set_value(st->gpio_convst, 0);
513512
514− return iio_triggered_buffer_predisable(indio_dev);
513+ return 0;
515514 }
516515
517516 static const struct iio_buffer_setup_ops ad7606_buffer_ops = {
@@ -614,7 +613,6 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, · 96 unmodified lines
614613 if (ret)
615614 return ret;
616615
617− indio_dev->dev.parent = dev;
618616 if (st->gpio_os) {
619617 if (st->gpio_range)
620618 indio_dev->info = &ad7606_info_os_and_range;
drivers/iio/adc/ad7766.c+0−3
@@ -178,8 +178,6 @@ static const struct ad7766_chip_info ad7766_chip_info[] = { · 177 unmodified lines
178178
179179 static const struct iio_buffer_setup_ops ad7766_buffer_setup_ops = {
180180 .preenable = &ad7766_preenable,
181− .postenable = &iio_triggered_buffer_postenable,
182− .predisable = &iio_triggered_buffer_predisable,
183181 .postdisable = &ad7766_postdisable,
184182 };
185183
@@ -242,7 +240,6 @@ static int ad7766_probe(struct spi_device *spi) · 56 unmodified lines
242240 if (IS_ERR(ad7766->pd_gpio))
243241 return PTR_ERR(ad7766->pd_gpio);
244242
245− indio_dev->dev.parent = &spi->dev;
246243 indio_dev->name = spi_get_device_id(spi)->name;
247244 indio_dev->modes = INDIO_DIRECT_MODE;
248245 indio_dev->channels = ad7766_channels;
drivers/iio/adc/ad7768-1.c+1−8
@@ -490,7 +490,6 @@ static int ad7768_buffer_postenable(struct iio_dev *indio_dev) · 489 unmodified lines
490490 {
491491 struct ad7768_state *st = iio_priv(indio_dev);
492492
493− iio_triggered_buffer_postenable(indio_dev);
494493 /*
495494 * Write a 1 to the LSB of the INTERFACE_FORMAT register to enter
496495 * continuous read mode. Subsequent data reads do not require an
@@ -502,17 +501,12 @@ static int ad7768_buffer_postenable(struct iio_dev *indio_dev) · 5 unmodified lines
502501 static int ad7768_buffer_predisable(struct iio_dev *indio_dev)
503502 {
504503 struct ad7768_state *st = iio_priv(indio_dev);
505− int ret;
506504
507505 /*
508506 * To exit continuous read mode, perform a single read of the ADC_DATA
509507 * reg (0x2C), which allows further configuration of the device.
510508 */
511− ret = ad7768_spi_reg_read(st, AD7768_REG_ADC_DATA, 3);
512− if (ret < 0)
513− return ret;
514−
515− return iio_triggered_buffer_predisable(indio_dev);
509+ return ad7768_spi_reg_read(st, AD7768_REG_ADC_DATA, 3);
516510 }
517511
518512 static const struct iio_buffer_setup_ops ad7768_buffer_ops = {
@@ -584,7 +578,6 @@ static int ad7768_probe(struct spi_device *spi) · 65 unmodified lines
584578
585579 indio_dev->channels = ad7768_channels;
586580 indio_dev->num_channels = ARRAY_SIZE(ad7768_channels);
587− indio_dev->dev.parent = &spi->dev;
588581 indio_dev->name = spi_get_device_id(spi)->name;
589582 indio_dev->info = &ad7768_info;
590583 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_TRIGGERED;
drivers/iio/adc/ad7780.c+0−1
@@ -320,7 +320,6 @@ static int ad7780_probe(struct spi_device *spi) · 319 unmodified lines
320320
321321 spi_set_drvdata(spi, indio_dev);
322322
323− indio_dev->dev.parent = &spi->dev;
324323 indio_dev->name = spi_get_device_id(spi)->name;
325324 indio_dev->modes = INDIO_DIRECT_MODE;
326325 indio_dev->channels = &st->chip_info->channel;
drivers/iio/adc/ad7791.c+0−2
@@ -425,8 +425,6 @@ static int ad7791_probe(struct spi_device *spi) · 424 unmodified lines
425425
426426 spi_set_drvdata(spi, indio_dev);
427427
428− indio_dev->dev.parent = &spi->dev;
429− indio_dev->dev.of_node = spi->dev.of_node;
430428 indio_dev->name = spi_get_device_id(spi)->name;
431429 indio_dev->modes = INDIO_DIRECT_MODE;
432430 indio_dev->channels = st->info->channels;
drivers/iio/adc/ad7793.c+0−2
@@ -818,8 +818,6 @@ static int ad7793_probe(struct spi_device *spi) · 817 unmodified lines
818818
819819 spi_set_drvdata(spi, indio_dev);
820820
821− indio_dev->dev.parent = &spi->dev;
822− indio_dev->dev.of_node = spi->dev.of_node;
823821 indio_dev->name = spi_get_device_id(spi)->name;
824822 indio_dev->modes = INDIO_DIRECT_MODE;
825823 indio_dev->channels = st->chip_info->channels;
drivers/iio/adc/ad7887.c+0−5
@@ -136,8 +136,6 @@ done: · 135 unmodified lines
136136
137137 static const struct iio_buffer_setup_ops ad7887_ring_setup_ops = {
138138 .preenable = &ad7887_ring_preenable,
139− .postenable = &iio_triggered_buffer_postenable,
140− .predisable = &iio_triggered_buffer_predisable,
141139 .postdisable = &ad7887_ring_postdisable,
142140 };
143141
@@ -264,9 +262,6 @@ static int ad7887_probe(struct spi_device *spi) · 120 unmodified lines
264262 spi_set_drvdata(spi, indio_dev);
265263 st->spi = spi;
266264
267− /* Estabilish that the iio_dev is a child of the spi device */
268− indio_dev->dev.parent = &spi->dev;
269− indio_dev->dev.of_node = spi->dev.of_node;
270265 indio_dev->name = spi_get_device_id(spi)->name;
271266 indio_dev->info = &ad7887_info;
272267 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/ad7923.c+0−2
@@ -315,8 +315,6 @@ static int ad7923_probe(struct spi_device *spi) · 314 unmodified lines
315315 info = &ad7923_chip_info[spi_get_device_id(spi)->driver_data];
316316
317317 indio_dev->name = spi_get_device_id(spi)->name;
318− indio_dev->dev.parent = &spi->dev;
319− indio_dev->dev.of_node = spi->dev.of_node;
320318 indio_dev->modes = INDIO_DIRECT_MODE;
321319 indio_dev->channels = info->channels;
322320 indio_dev->num_channels = info->num_channels;
drivers/iio/adc/ad7949.c+1−3
@@ -3,7 +3,7 @@ · 2 unmodified lines
33 *
44 * Copyright (C) 2018 CMC NV
55 *
6− * http://www.analog.com/media/en/technical-documentation/data-sheets/AD7949.pdf
6+ * https://www.analog.com/media/en/technical-documentation/data-sheets/AD7949.pdf
77 */
88
99 #include <linux/delay.h>
@@ -243,8 +243,6 @@ static int ad7949_spi_probe(struct spi_device *spi) · 233 unmodified lines
243243 return -ENOMEM;
244244 }
245245
246− indio_dev->dev.parent = dev;
247− indio_dev->dev.of_node = dev->of_node;
248246 indio_dev->info = &ad7949_spi_info;
249247 indio_dev->name = spi_get_device_id(spi)->name;
250248 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/ad799x.c+0−2
@@ -814,8 +814,6 @@ static int ad799x_probe(struct i2c_client *client, · 813 unmodified lines
814814
815815 st->client = client;
816816
817− indio_dev->dev.parent = &client->dev;
818− indio_dev->dev.of_node = client->dev.of_node;
819817 indio_dev->name = id->name;
820818 indio_dev->info = st->chip_config->info;
821819
drivers/iio/adc/ad_sigma_delta.c+0−5
@@ -345,10 +345,6 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev) · 344 unmodified lines
345345 unsigned int channel;
346346 int ret;
347347
348− ret = iio_triggered_buffer_postenable(indio_dev);
349− if (ret < 0)
350− return ret;
351−
352348 channel = find_first_bit(indio_dev->active_scan_mask,
353349 indio_dev->masklength);
354350 ret = ad_sigma_delta_set_channel(sigma_delta,
@@ -441,7 +437,6 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p) · 86 unmodified lines
441437
442438 static const struct iio_buffer_setup_ops ad_sd_buffer_setup_ops = {
443439 .postenable = &ad_sd_buffer_postenable,
444− .predisable = &iio_triggered_buffer_predisable,
445440 .postdisable = &ad_sd_buffer_postdisable,
446441 .validate_scan_mask = &iio_validate_scan_mask_onehot,
447442 };
drivers/iio/adc/adi-axi-adc.c+0−1
@@ -435,7 +435,6 @@ static int adi_axi_adc_probe(struct platform_device *pdev) · 434 unmodified lines
435435 }
436436
437437 indio_dev->info = &adi_axi_adc_info;
438− indio_dev->dev.parent = &pdev->dev;
439438 indio_dev->name = "adi-axi-adc";
440439 indio_dev->modes = INDIO_DIRECT_MODE;
441440 indio_dev->num_channels = conv->chip_info->num_channels;
drivers/iio/adc/aspeed_adc.c+0−1
@@ -252,7 +252,6 @@ static int aspeed_adc_probe(struct platform_device *pdev) · 251 unmodified lines
252252
253253 model_data = of_device_get_match_data(&pdev->dev);
254254 indio_dev->name = model_data->model_name;
255− indio_dev->dev.parent = &pdev->dev;
256255 indio_dev->info = &aspeed_adc_iio_info;
257256 indio_dev->modes = INDIO_DIRECT_MODE;
258257 indio_dev->channels = aspeed_adc_iio_channels;
drivers/iio/adc/at91-sama5d2_adc.c+17−32
@@ -402,6 +402,7 @@ struct at91_adc_state { · 401 unmodified lines
402402 wait_queue_head_t wq_data_available;
403403 struct at91_adc_dma dma_st;
404404 struct at91_adc_touch touch_st;
405+ struct iio_dev *indio_dev;
405406 u16 buffer[AT91_BUFFER_MAX_HWORDS];
406407 /*
407408 * lock to prevent concurrent 'single conversion' requests through
@@ -642,13 +643,13 @@ static u16 at91_adc_touch_pos(struct at91_adc_state *st, int reg) · 234 unmodified lines
642643 /* first half of register is the x or y, second half is the scale */
643644 val = at91_adc_readl(st, reg);
644645 if (!val)
645− dev_dbg(&iio_priv_to_dev(st)->dev, "pos is 0\n");
646+ dev_dbg(&st->indio_dev->dev, "pos is 0\n");
646647
647648 pos = val & AT91_SAMA5D2_XYZ_MASK;
648649 result = (pos << AT91_SAMA5D2_MAX_POS_BITS) - pos;
649650 scale = (val >> 16) & AT91_SAMA5D2_XYZ_MASK;
650651 if (scale == 0) {
651− dev_err(&iio_priv_to_dev(st)->dev, "scale is 0\n");
652+ dev_err(&st->indio_dev->dev, "scale is 0\n");
652653 return 0;
653654 }
654655 result /= scale;
@@ -937,14 +938,6 @@ static int at91_adc_buffer_preenable(struct iio_dev *indio_dev) · 282 unmodified lines
937938 return 0;
938939 }
939940
940−static int at91_adc_buffer_postenable(struct iio_dev *indio_dev)
941−{
942− if (at91_adc_current_chan_is_touch(indio_dev))
943− return 0;
944−
945− return iio_triggered_buffer_postenable(indio_dev);
946−}
947−
948941 static int at91_adc_buffer_postdisable(struct iio_dev *indio_dev)
949942 {
950943 struct at91_adc_state *st = iio_priv(indio_dev);
@@ -995,19 +988,9 @@ static int at91_adc_buffer_postdisable(struct iio_dev *indio_dev) · 44 unmodified lines
995988 return 0;
996989 }
997990
998−static int at91_adc_buffer_predisable(struct iio_dev *indio_dev)
999−{
1000− if (at91_adc_current_chan_is_touch(indio_dev))
1001− return 0;
1002−
1003− return iio_triggered_buffer_predisable(indio_dev);
1004−}
1005−
1006991 static const struct iio_buffer_setup_ops at91_buffer_setup_ops = {
1007992 .preenable = &at91_adc_buffer_preenable,
1008993 .postdisable = &at91_adc_buffer_postdisable,
1009− .postenable = &at91_adc_buffer_postenable,
1010− .predisable = &at91_adc_buffer_predisable,
1011994 };
1012995
1013996 static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *indio,
@@ -1204,9 +1187,9 @@ static unsigned at91_adc_startup_time(unsigned startup_time_min, · 190 unmodified lines
12041187 return i;
12051188 }
12061189
1207−static void at91_adc_setup_samp_freq(struct at91_adc_state *st, unsigned freq)
1190+static void at91_adc_setup_samp_freq(struct iio_dev *indio_dev, unsigned freq)
12081191 {
1209− struct iio_dev *indio_dev = iio_priv_to_dev(st);
1192+ struct at91_adc_state *st = iio_priv(indio_dev);
12101193 unsigned f_per, prescal, startup, mr;
12111194
12121195 f_per = clk_get_rate(st->per_clk);
@@ -1275,9 +1258,9 @@ static void at91_adc_pen_detect_interrupt(struct at91_adc_state *st) · 62 unmodified lines
12751258 st->touch_st.touching = true;
12761259 }
12771260
1278−static void at91_adc_no_pen_detect_interrupt(struct at91_adc_state *st)
1261+static void at91_adc_no_pen_detect_interrupt(struct iio_dev *indio_dev)
12791262 {
1280− struct iio_dev *indio_dev = iio_priv_to_dev(st);
1263+ struct at91_adc_state *st = iio_priv(indio_dev);
12811264
12821265 at91_adc_writel(st, AT91_SAMA5D2_TRGR,
12831266 AT91_SAMA5D2_TRGR_TRGMOD_NO_TRIGGER);
@@ -1297,7 +1280,7 @@ static void at91_adc_workq_handler(struct work_struct *workq) · 13 unmodified lines
12971280 struct at91_adc_touch, workq);
12981281 struct at91_adc_state *st = container_of(touch_st,
12991282 struct at91_adc_state, touch_st);
1300− struct iio_dev *indio_dev = iio_priv_to_dev(st);
1283+ struct iio_dev *indio_dev = st->indio_dev;
13011284
13021285 iio_push_to_buffers(indio_dev, st->buffer);
13031286 }
@@ -1318,7 +1301,7 @@ static irqreturn_t at91_adc_interrupt(int irq, void *private) · 14 unmodified lines
13181301 at91_adc_pen_detect_interrupt(st);
13191302 } else if ((status & AT91_SAMA5D2_IER_NOPEN)) {
13201303 /* nopen detected IRQ */
1321− at91_adc_no_pen_detect_interrupt(st);
1304+ at91_adc_no_pen_detect_interrupt(indio);
13221305 } else if ((status & AT91_SAMA5D2_ISR_PENS) &&
13231306 ((status & rdy_mask) == rdy_mask)) {
13241307 /* periodic trigger IRQ - during pen sense */
@@ -1486,7 +1469,7 @@ static int at91_adc_write_raw(struct iio_dev *indio_dev, · 161 unmodified lines
14861469 val > st->soc_info.max_sample_rate)
14871470 return -EINVAL;
14881471
1489− at91_adc_setup_samp_freq(st, val);
1472+ at91_adc_setup_samp_freq(indio_dev, val);
14901473 return 0;
14911474 default:
14921475 return -EINVAL;
@@ -1624,8 +1607,10 @@ static int at91_adc_update_scan_mode(struct iio_dev *indio_dev, · 131 unmodified lines
16241607 return 0;
16251608 }
16261609
1627−static void at91_adc_hw_init(struct at91_adc_state *st)
1610+static void at91_adc_hw_init(struct iio_dev *indio_dev)
16281611 {
1612+ struct at91_adc_state *st = iio_priv(indio_dev);
1613+
16291614 at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST);
16301615 at91_adc_writel(st, AT91_SAMA5D2_IDR, 0xffffffff);
16311616 /*
@@ -1635,7 +1620,7 @@ static void at91_adc_hw_init(struct at91_adc_state *st) · 3 unmodified lines
16351620 at91_adc_writel(st, AT91_SAMA5D2_MR,
16361621 AT91_SAMA5D2_MR_TRANSFER(2) | AT91_SAMA5D2_MR_ANACH);
16371622
1638− at91_adc_setup_samp_freq(st, st->soc_info.min_sample_rate);
1623+ at91_adc_setup_samp_freq(indio_dev, st->soc_info.min_sample_rate);
16391624
16401625 /* configure extended mode register */
16411626 at91_adc_config_emr(st);
@@ -1710,7 +1695,6 @@ static int at91_adc_probe(struct platform_device *pdev) · 68 unmodified lines
17101695 if (!indio_dev)
17111696 return -ENOMEM;
17121697
1713− indio_dev->dev.parent = &pdev->dev;
17141698 indio_dev->name = dev_name(&pdev->dev);
17151699 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
17161700 indio_dev->info = &at91_adc_info;
@@ -1718,6 +1702,7 @@ static int at91_adc_probe(struct platform_device *pdev) · 1 unmodified line
17181702 indio_dev->num_channels = ARRAY_SIZE(at91_adc_channels);
17191703
17201704 st = iio_priv(indio_dev);
1705+ st->indio_dev = indio_dev;
17211706
17221707 bitmap_set(&st->touch_st.channels_bitmask,
17231708 AT91_SAMA5D2_TOUCH_X_CHAN_IDX, 1);
@@ -1829,7 +1814,7 @@ static int at91_adc_probe(struct platform_device *pdev) · 105 unmodified lines
18291814 goto vref_disable;
18301815 }
18311816
1832− at91_adc_hw_init(st);
1817+ at91_adc_hw_init(indio_dev);
18331818
18341819 ret = clk_prepare_enable(st->per_clk);
18351820 if (ret)
@@ -1945,7 +1930,7 @@ static __maybe_unused int at91_adc_resume(struct device *dev) · 109 unmodified lines
19451930 if (ret)
19461931 goto vref_disable_resume;
19471932
1948− at91_adc_hw_init(st);
1933+ at91_adc_hw_init(indio_dev);
19491934
19501935 /* reconfiguring trigger hardware state */
19511936 if (!iio_buffer_enabled(indio_dev))
drivers/iio/adc/at91_adc.c+15−16
@@ -287,13 +287,13 @@ static void handle_adc_eoc_trigger(int irq, struct iio_dev *idev) · 286 unmodified lines
287287 }
288288 }
289289
290−static int at91_ts_sample(struct at91_adc_state *st)
290+static int at91_ts_sample(struct iio_dev *idev)
291291 {
292+ struct at91_adc_state *st = iio_priv(idev);
292293 unsigned int xscale, yscale, reg, z1, z2;
293294 unsigned int x, y, pres, xpos, ypos;
294295 unsigned int rxp = 1;
295296 unsigned int factor = 1000;
296− struct iio_dev *idev = iio_priv_to_dev(st);
297297
298298 unsigned int xyz_mask_bits = st->res;
299299 unsigned int xyz_mask = (1 << xyz_mask_bits) - 1;
@@ -449,7 +449,7 @@ static irqreturn_t at91_adc_9x5_interrupt(int irq, void *private) · 149 unmodified lines
449449
450450 if (status & AT91_ADC_ISR_PENS) {
451451 /* validate data by pen contact */
452− at91_ts_sample(st);
452+ at91_ts_sample(idev);
453453 } else {
454454 /* triggered by event that is no pen contact, just read
455455 * them to clean the interrupt and discard all.
@@ -737,10 +737,10 @@ static int at91_adc_read_raw(struct iio_dev *idev, · 281 unmodified lines
737737 return -EINVAL;
738738 }
739739
740−static int at91_adc_of_get_resolution(struct at91_adc_state *st,
740+static int at91_adc_of_get_resolution(struct iio_dev *idev,
741741 struct platform_device *pdev)
742742 {
743− struct iio_dev *idev = iio_priv_to_dev(st);
743+ struct at91_adc_state *st = iio_priv(idev);
744744 struct device_node *np = pdev->dev.of_node;
745745 int count, i, ret = 0;
746746 char *res_name, *s;
@@ -866,10 +866,10 @@ static int at91_adc_probe_dt_ts(struct device_node *node, · 119 unmodified lines
866866 }
867867 }
868868
869−static int at91_adc_probe_dt(struct at91_adc_state *st,
869+static int at91_adc_probe_dt(struct iio_dev *idev,
870870 struct platform_device *pdev)
871871 {
872− struct iio_dev *idev = iio_priv_to_dev(st);
872+ struct at91_adc_state *st = iio_priv(idev);
873873 struct device_node *node = pdev->dev.of_node;
874874 struct device_node *trig_node;
875875 int i = 0, ret;
@@ -910,7 +910,7 @@ static int at91_adc_probe_dt(struct at91_adc_state *st, · 34 unmodified lines
910910 }
911911 st->vref_mv = prop;
912912
913− ret = at91_adc_of_get_resolution(st, pdev);
913+ ret = at91_adc_of_get_resolution(idev, pdev);
914914 if (ret)
915915 goto error_ret;
916916
@@ -1010,9 +1010,9 @@ static void atmel_ts_close(struct input_dev *dev) · 93 unmodified lines
10101010 at91_adc_writel(st, AT91_ADC_IDR, AT91RL_ADC_IER_PEN);
10111011 }
10121012
1013−static int at91_ts_hw_init(struct at91_adc_state *st, u32 adc_clk_khz)
1013+static int at91_ts_hw_init(struct iio_dev *idev, u32 adc_clk_khz)
10141014 {
1015− struct iio_dev *idev = iio_priv_to_dev(st);
1015+ struct at91_adc_state *st = iio_priv(idev);
10161016 u32 reg = 0;
10171017 u32 tssctim = 0;
10181018 int i = 0;
@@ -1085,11 +1085,11 @@ static int at91_ts_hw_init(struct at91_adc_state *st, u32 adc_clk_khz) · 66 unmodified lines
10851085 return 0;
10861086 }
10871087
1088−static int at91_ts_register(struct at91_adc_state *st,
1088+static int at91_ts_register(struct iio_dev *idev,
10891089 struct platform_device *pdev)
10901090 {
1091+ struct at91_adc_state *st = iio_priv(idev);
10911092 struct input_dev *input;
1092− struct iio_dev *idev = iio_priv_to_dev(st);
10931093 int ret;
10941094
10951095 input = input_allocate_device();
@@ -1161,7 +1161,7 @@ static int at91_adc_probe(struct platform_device *pdev) · 65 unmodified lines
11611161 st = iio_priv(idev);
11621162
11631163 if (pdev->dev.of_node)
1164− ret = at91_adc_probe_dt(st, pdev);
1164+ ret = at91_adc_probe_dt(idev, pdev);
11651165 else
11661166 ret = at91_adc_probe_pdata(st, pdev);
11671167
@@ -1172,7 +1172,6 @@ static int at91_adc_probe(struct platform_device *pdev) · 4 unmodified lines
11721172
11731173 platform_set_drvdata(pdev, idev);
11741174
1175− idev->dev.parent = &pdev->dev;
11761175 idev->name = dev_name(&pdev->dev);
11771176 idev->modes = INDIO_DIRECT_MODE;
11781177 idev->info = &at91_adc_info;
@@ -1301,11 +1300,11 @@ static int at91_adc_probe(struct platform_device *pdev) · 122 unmodified lines
13011300 goto error_disable_adc_clk;
13021301 }
13031302 } else {
1304− ret = at91_ts_register(st, pdev);
1303+ ret = at91_ts_register(idev, pdev);
13051304 if (ret)
13061305 goto error_disable_adc_clk;
13071306
1308− at91_ts_hw_init(st, adc_clk_khz);
1307+ at91_ts_hw_init(idev, adc_clk_khz);
13091308 }
13101309
13111310 ret = iio_device_register(idev);
drivers/iio/adc/axp20x_adc.c+0−2
@@ -668,8 +668,6 @@ static int axp20x_probe(struct platform_device *pdev) · 667 unmodified lines
668668 platform_set_drvdata(pdev, indio_dev);
669669
670670 info->regmap = axp20x_dev->regmap;
671− indio_dev->dev.parent = &pdev->dev;
672− indio_dev->dev.of_node = pdev->dev.of_node;
673671 indio_dev->modes = INDIO_DIRECT_MODE;
674672
675673 if (!pdev->dev.of_node) {
drivers/iio/adc/axp288_adc.c+0−1
@@ -271,7 +271,6 @@ static int axp288_adc_probe(struct platform_device *pdev) · 270 unmodified lines
271271 return ret;
272272 }
273273
274− indio_dev->dev.parent = &pdev->dev;
275274 indio_dev->name = pdev->name;
276275 indio_dev->channels = axp288_adc_channels;
277276 indio_dev->num_channels = ARRAY_SIZE(axp288_adc_channels);
drivers/iio/adc/bcm_iproc_adc.c+0−2
@@ -573,8 +573,6 @@ static int iproc_adc_probe(struct platform_device *pdev) · 572 unmodified lines
573573 }
574574
575575 indio_dev->name = "iproc-static-adc";
576− indio_dev->dev.parent = &pdev->dev;
577− indio_dev->dev.of_node = pdev->dev.of_node;
578576 indio_dev->info = &iproc_adc_iio_info;
579577 indio_dev->modes = INDIO_DIRECT_MODE;
580578 indio_dev->channels = iproc_adc_iio_channels;
drivers/iio/adc/berlin2-adc.c+0−1
@@ -321,7 +321,6 @@ static int berlin2_adc_probe(struct platform_device *pdev) · 320 unmodified lines
321321 init_waitqueue_head(&priv->wq);
322322 mutex_init(&priv->lock);
323323
324− indio_dev->dev.parent = &pdev->dev;
325324 indio_dev->name = dev_name(&pdev->dev);
326325 indio_dev->modes = INDIO_DIRECT_MODE;
327326 indio_dev->info = &berlin2_adc_info;
drivers/iio/adc/cc10001_adc.c+0−1
@@ -334,7 +334,6 @@ static int cc10001_adc_probe(struct platform_device *pdev) · 333 unmodified lines
334334 if (ret)
335335 return ret;
336336
337− indio_dev->dev.parent = &pdev->dev;
338337 indio_dev->name = dev_name(&pdev->dev);
339338 indio_dev->info = &cc10001_adc_info;
340339 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/cpcap-adc.c+6−18
@@ -15,9 +15,9 @@ · 14 unmodified lines
1515 #include <linux/interrupt.h>
1616 #include <linux/kernel.h>
1717 #include <linux/module.h>
18−#include <linux/of.h>
19−#include <linux/of_platform.h>
18+#include <linux/mod_devicetable.h>
2019 #include <linux/platform_device.h>
20+#include <linux/property.h>
2121 #include <linux/regmap.h>
2222
2323 #include <linux/iio/buffer.h>
@@ -955,22 +955,10 @@ MODULE_DEVICE_TABLE(of, cpcap_adc_id_table); · 931 unmodified lines
955955
956956 static int cpcap_adc_probe(struct platform_device *pdev)
957957 {
958− const struct of_device_id *match;
959958 struct cpcap_adc *ddata;
960959 struct iio_dev *indio_dev;
961960 int error;
962961
963− match = of_match_device(of_match_ptr(cpcap_adc_id_table),
964− &pdev->dev);
965− if (!match)
966− return -EINVAL;
967−
968− if (!match->data) {
969− dev_err(&pdev->dev, "no configuration data found\n");
970−
971− return -ENODEV;
972− }
973−
974962 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*ddata));
975963 if (!indio_dev) {
976964 dev_err(&pdev->dev, "failed to allocate iio device\n");
@@ -978,15 +966,15 @@ static int cpcap_adc_probe(struct platform_device *pdev) · 1 unmodified line
978966 return -ENOMEM;
979967 }
980968 ddata = iio_priv(indio_dev);
981− ddata->ato = match->data;
969+ ddata->ato = device_get_match_data(&pdev->dev);
970+ if (!ddata->ato)
971+ return -ENODEV;
982972 ddata->dev = &pdev->dev;
983973
984974 mutex_init(&ddata->lock);
985975 init_waitqueue_head(&ddata->wq_data_avail);
986976
987977 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
988− indio_dev->dev.parent = &pdev->dev;
989− indio_dev->dev.of_node = pdev->dev.of_node;
990978 indio_dev->channels = cpcap_adc_channels;
991979 indio_dev->num_channels = ARRAY_SIZE(cpcap_adc_channels);
992980 indio_dev->name = dev_name(&pdev->dev);
@@ -1029,7 +1017,7 @@ static int cpcap_adc_probe(struct platform_device *pdev) · 36 unmodified lines
10291017 static struct platform_driver cpcap_adc_driver = {
10301018 .driver = {
10311019 .name = "cpcap_adc",
1032− .of_match_table = of_match_ptr(cpcap_adc_id_table),
1020+ .of_match_table = cpcap_adc_id_table,
10331021 },
10341022 .probe = cpcap_adc_probe,
10351023 };
drivers/iio/adc/da9150-gpadc.c+0−2
@@ -354,8 +354,6 @@ static int da9150_gpadc_probe(struct platform_device *pdev) · 353 unmodified lines
354354 }
355355
356356 indio_dev->name = dev_name(dev);
357− indio_dev->dev.parent = dev;
358− indio_dev->dev.of_node = pdev->dev.of_node;
359357 indio_dev->info = &da9150_gpadc_info;
360358 indio_dev->modes = INDIO_DIRECT_MODE;
361359 indio_dev->channels = da9150_gpadc_channels;
drivers/iio/adc/dln2-adc.c+1−12
@@ -524,10 +524,6 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev) · 523 unmodified lines
524524 u16 conflict;
525525 unsigned int trigger_chan;
526526
527− ret = iio_triggered_buffer_postenable(indio_dev);
528− if (ret)
529− return ret;
530−
531527 mutex_lock(&dln2->mutex);
532528
533529 /* Enable ADC */
@@ -541,7 +537,6 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev) · 7 unmodified lines
541537 (int)conflict);
542538 ret = -EBUSY;
543539 }
544− iio_triggered_buffer_predisable(indio_dev);
545540 return ret;
546541 }
547542
@@ -555,7 +550,6 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev) · 7 unmodified lines
555550 mutex_unlock(&dln2->mutex);
556551 if (ret < 0) {
557552 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
558− iio_triggered_buffer_predisable(indio_dev);
559553 return ret;
560554 }
561555 } else {
@@ -568,7 +562,7 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev) · 6 unmodified lines
568562
569563 static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev)
570564 {
571− int ret, ret2;
565+ int ret;
572566 struct dln2_adc *dln2 = iio_priv(indio_dev);
573567
574568 mutex_lock(&dln2->mutex);
@@ -586,10 +580,6 @@ static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev) · 11 unmodified lines
586580 if (ret < 0)
587581 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
588582
589− ret2 = iio_triggered_buffer_predisable(indio_dev);
590− if (ret == 0)
591− ret = ret2;
592−
593583 return ret;
594584 }
595585
@@ -652,7 +642,6 @@ static int dln2_adc_probe(struct platform_device *pdev) · 56 unmodified lines
652642 IIO_CHAN_SOFT_TIMESTAMP_ASSIGN(dln2->iio_channels[i], i);
653643
654644 indio_dev->name = DLN2_ADC_MOD_NAME;
655− indio_dev->dev.parent = dev;
656645 indio_dev->info = &dln2_adc_info;
657646 indio_dev->modes = INDIO_DIRECT_MODE;
658647 indio_dev->channels = dln2->iio_channels;
drivers/iio/adc/envelope-detector.c+0−2
@@ -343,8 +343,6 @@ static int envelope_detector_probe(struct platform_device *pdev) · 342 unmodified lines
343343 INIT_DELAYED_WORK(&env->comp_timeout, envelope_detector_timeout);
344344
345345 indio_dev->name = dev_name(dev);
346− indio_dev->dev.parent = dev;
347− indio_dev->dev.of_node = dev->of_node;
348346 indio_dev->info = &envelope_detector_info;
349347 indio_dev->channels = &envelope_detector_iio_channel;
350348 indio_dev->num_channels = 1;
drivers/iio/adc/ep93xx_adc.c+0−1
@@ -170,7 +170,6 @@ static int ep93xx_adc_probe(struct platform_device *pdev) · 169 unmodified lines
170170 return PTR_ERR(priv->base);
171171 }
172172
173− iiodev->dev.parent = &pdev->dev;
174173 iiodev->name = dev_name(&pdev->dev);
175174 iiodev->modes = INDIO_DIRECT_MODE;
176175 iiodev->info = &ep93xx_adc_info;
drivers/iio/adc/exynos_adc.c+0−2
@@ -867,8 +867,6 @@ static int exynos_adc_probe(struct platform_device *pdev) · 866 unmodified lines
867867 platform_set_drvdata(pdev, indio_dev);
868868
869869 indio_dev->name = dev_name(&pdev->dev);
870− indio_dev->dev.parent = &pdev->dev;
871− indio_dev->dev.of_node = pdev->dev.of_node;
872870 indio_dev->info = &exynos_adc_iio_info;
873871 indio_dev->modes = INDIO_DIRECT_MODE;
874872 indio_dev->channels = exynos_adc_iio_channels;
drivers/iio/adc/fsl-imx25-gcq.c+0−1
@@ -350,7 +350,6 @@ static int mx25_gcq_probe(struct platform_device *pdev) · 349 unmodified lines
350350 goto err_clk_unprepare;
351351 }
352352
353− indio_dev->dev.parent = &pdev->dev;
354353 indio_dev->channels = mx25_gcq_channels;
355354 indio_dev->num_channels = ARRAY_SIZE(mx25_gcq_channels);
356355 indio_dev->info = &mx25_gcq_iio_info;
drivers/iio/adc/hi8435.c+2−6
@@ -15,9 +15,7 @@ · 14 unmodified lines
1515 #include <linux/iio/triggered_event.h>
1616 #include <linux/interrupt.h>
1717 #include <linux/module.h>
18−#include <linux/of.h>
19−#include <linux/of_device.h>
20−#include <linux/of_gpio.h>
18+#include <linux/mod_devicetable.h>
2119 #include <linux/spi/spi.h>
2220 #include <linux/gpio/consumer.h>
2321
@@ -488,8 +486,6 @@ static int hi8435_probe(struct spi_device *spi) · 464 unmodified lines
488486 spi_set_drvdata(spi, idev);
489487 mutex_init(&priv->lock);
490488
491− idev->dev.parent = &spi->dev;
492− idev->dev.of_node = spi->dev.of_node;
493489 idev->name = spi_get_device_id(spi)->name;
494490 idev->modes = INDIO_DIRECT_MODE;
495491 idev->info = &hi8435_info;
@@ -542,7 +538,7 @@ MODULE_DEVICE_TABLE(spi, hi8435_id); · 46 unmodified lines
542538 static struct spi_driver hi8435_driver = {
543539 .driver = {
544540 .name = DRV_NAME,
545− .of_match_table = of_match_ptr(hi8435_dt_ids),
541+ .of_match_table = hi8435_dt_ids,
546542 },
547543 .probe = hi8435_probe,
548544 .id_table = hi8435_id,
drivers/iio/adc/hx711.c+0−1
@@ -551,7 +551,6 @@ static int hx711_probe(struct platform_device *pdev) · 550 unmodified lines
551551 platform_set_drvdata(pdev, indio_dev);
552552
553553 indio_dev->name = "hx711";
554− indio_dev->dev.parent = &pdev->dev;
555554 indio_dev->info = &hx711_iio_info;
556555 indio_dev->modes = INDIO_DIRECT_MODE;
557556 indio_dev->channels = hx711_chan_spec;
drivers/iio/adc/imx7d_adc.c+0−1
@@ -515,7 +515,6 @@ static int imx7d_adc_probe(struct platform_device *pdev) · 514 unmodified lines
515515 init_completion(&info->completion);
516516
517517 indio_dev->name = dev_name(dev);
518− indio_dev->dev.parent = dev;
519518 indio_dev->info = &imx7d_adc_iio_info;
520519 indio_dev->modes = INDIO_DIRECT_MODE;
521520 indio_dev->channels = imx7d_adc_iio_channels;
drivers/iio/adc/ina2xx-adc.c+1−3
@@ -273,7 +273,7 @@ static int ina2xx_read_raw(struct iio_dev *indio_dev, · 272 unmodified lines
273273 * Available averaging rates for ina226. The indices correspond with
274274 * the bit values expected by the chip (according to the ina226 datasheet,
275275 * table 3 AVG bit settings, found at
276− * http://www.ti.com/lit/ds/symlink/ina226.pdf.
276+ * https://www.ti.com/lit/ds/symlink/ina226.pdf.
277277 */
278278 static const int ina226_avg_tab[] = { 1, 4, 16, 64, 128, 256, 512, 1024 };
279279
@@ -1015,8 +1015,6 @@ static int ina2xx_probe(struct i2c_client *client, · 735 unmodified lines
10151015 }
10161016
10171017 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
1018− indio_dev->dev.parent = &client->dev;
1019− indio_dev->dev.of_node = client->dev.of_node;
10201018 if (id->driver_data == ina226) {
10211019 indio_dev->channels = ina226_channels;
10221020 indio_dev->num_channels = ARRAY_SIZE(ina226_channels);
drivers/iio/adc/ingenic-adc.c+2−4
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313 #include <linux/iopoll.h>
1414 #include <linux/kernel.h>
1515 #include <linux/module.h>
16+#include <linux/mod_devicetable.h>
1617 #include <linux/mutex.h>
1718 #include <linux/platform_device.h>
1819
@@ -481,7 +482,6 @@ static int ingenic_adc_probe(struct platform_device *pdev) · 462 unmodified lines
481482 return ret;
482483 }
483484
484− iio_dev->dev.parent = dev;
485485 iio_dev->name = "jz-adc";
486486 iio_dev->modes = INDIO_DIRECT_MODE;
487487 iio_dev->channels = ingenic_channels;
@@ -498,7 +498,6 @@ static int ingenic_adc_probe(struct platform_device *pdev) · 10 unmodified lines
498498 return ret;
499499 }
500500
501−#ifdef CONFIG_OF
502501 static const struct of_device_id ingenic_adc_of_match[] = {
503502 { .compatible = "ingenic,jz4725b-adc", .data = &jz4725b_adc_soc_data, },
504503 { .compatible = "ingenic,jz4740-adc", .data = &jz4740_adc_soc_data, },
@@ -506,12 +505,11 @@ static const struct of_device_id ingenic_adc_of_match[] = { · 1 unmodified line
506505 { },
507506 };
508507 MODULE_DEVICE_TABLE(of, ingenic_adc_of_match);
509−#endif
510508
511509 static struct platform_driver ingenic_adc_driver = {
512510 .driver = {
513511 .name = "ingenic-adc",
514− .of_match_table = of_match_ptr(ingenic_adc_of_match),
512+ .of_match_table = ingenic_adc_of_match,
515513 },
516514 .probe = ingenic_adc_probe,
517515 };
drivers/iio/adc/intel_mrfld_adc.c+0−1
@@ -207,7 +207,6 @@ static int mrfld_adc_probe(struct platform_device *pdev) · 206 unmodified lines
207207
208208 platform_set_drvdata(pdev, indio_dev);
209209
210− indio_dev->dev.parent = dev;
211210 indio_dev->name = pdev->name;
212211
213212 indio_dev->channels = mrfld_adc_channels;
drivers/iio/adc/lp8788_adc.c+0−2
@@ -198,14 +198,12 @@ static int lp8788_adc_probe(struct platform_device *pdev) · 197 unmodified lines
198198 adc->lp = lp;
199199 platform_set_drvdata(pdev, indio_dev);
200200
201− indio_dev->dev.of_node = pdev->dev.of_node;
202201 ret = lp8788_iio_map_register(indio_dev, lp->pdata, adc);
203202 if (ret)
204203 return ret;
205204
206205 mutex_init(&adc->lock);
207206
208− indio_dev->dev.parent = &pdev->dev;
209207 indio_dev->name = pdev->name;
210208 indio_dev->modes = INDIO_DIRECT_MODE;
211209 indio_dev->info = &lp8788_adc_info;
drivers/iio/adc/lpc18xx_adc.c+0−1
@@ -152,7 +152,6 @@ static int lpc18xx_adc_probe(struct platform_device *pdev) · 151 unmodified lines
152152 }
153153
154154 indio_dev->name = dev_name(&pdev->dev);
155− indio_dev->dev.parent = &pdev->dev;
156155 indio_dev->info = &lpc18xx_adc_info;
157156 indio_dev->modes = INDIO_DIRECT_MODE;
158157 indio_dev->channels = lpc18xx_adc_iio_channels;
drivers/iio/adc/lpc32xx_adc.c+2−4
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #include <linux/interrupt.h>
1515 #include <linux/io.h>
1616 #include <linux/module.h>
17+#include <linux/mod_devicetable.h>
1718 #include <linux/platform_device.h>
1819 #include <linux/regulator/consumer.h>
1920
@@ -196,7 +197,6 @@ static int lpc32xx_adc_probe(struct platform_device *pdev) · 176 unmodified lines
196197 init_completion(&st->completion);
197198
198199 iodev->name = LPC32XXAD_NAME;
199− iodev->dev.parent = &pdev->dev;
200200 iodev->info = &lpc32xx_adc_iio_info;
201201 iodev->modes = INDIO_DIRECT_MODE;
202202 iodev->num_channels = ARRAY_SIZE(lpc32xx_adc_iio_channels);
@@ -210,19 +210,17 @@ static int lpc32xx_adc_probe(struct platform_device *pdev) · 7 unmodified lines
210210 return 0;
211211 }
212212
213−#ifdef CONFIG_OF
214213 static const struct of_device_id lpc32xx_adc_match[] = {
215214 { .compatible = "nxp,lpc3220-adc" },
216215 {},
217216 };
218217 MODULE_DEVICE_TABLE(of, lpc32xx_adc_match);
219−#endif
220218
221219 static struct platform_driver lpc32xx_adc_driver = {
222220 .probe = lpc32xx_adc_probe,
223221 .driver = {
224222 .name = LPC32XXAD_NAME,
225− .of_match_table = of_match_ptr(lpc32xx_adc_match),
223+ .of_match_table = lpc32xx_adc_match,
226224 },
227225 };
228226
drivers/iio/adc/ltc2471.c+0−1
@@ -116,7 +116,6 @@ static int ltc2471_i2c_probe(struct i2c_client *client, · 115 unmodified lines
116116 data = iio_priv(indio_dev);
117117 data->client = client;
118118
119− indio_dev->dev.parent = &client->dev;
120119 indio_dev->name = id->name;
121120 indio_dev->info = &ltc2471_info;
122121 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/ltc2485.c+0−1
@@ -108,7 +108,6 @@ static int ltc2485_probe(struct i2c_client *client, · 107 unmodified lines
108108 i2c_set_clientdata(client, indio_dev);
109109 data->client = client;
110110
111− indio_dev->dev.parent = &client->dev;
112111 indio_dev->name = id->name;
113112 indio_dev->info = &ltc2485_info;
114113 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/ltc2496.c+2−2
@@ -14,7 +14,7 @@ · 13 unmodified lines
1414 #include <linux/iio/iio.h>
1515 #include <linux/iio/driver.h>
1616 #include <linux/module.h>
17−#include <linux/of.h>
17+#include <linux/mod_devicetable.h>
1818
1919 #include "ltc2497.h"
2020
@@ -96,7 +96,7 @@ MODULE_DEVICE_TABLE(of, ltc2496_of_match); · 75 unmodified lines
9696 static struct spi_driver ltc2496_driver = {
9797 .driver = {
9898 .name = "ltc2496",
99− .of_match_table = of_match_ptr(ltc2496_of_match),
99+ .of_match_table = ltc2496_of_match,
100100 },
101101 .probe = ltc2496_probe,
102102 .remove = ltc2496_remove,
drivers/iio/adc/ltc2497-core.c+0−1
@@ -169,7 +169,6 @@ int ltc2497core_probe(struct device *dev, struct iio_dev *indio_dev) · 168 unmodified lines
169169 struct ltc2497core_driverdata *ddata = iio_priv(indio_dev);
170170 int ret;
171171
172− indio_dev->dev.parent = dev;
173172 indio_dev->name = dev_name(dev);
174173 indio_dev->info = &ltc2497core_info;
175174 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/ltc2497.c+2−2
@@ -11,7 +11,7 @@ · 10 unmodified lines
1111 #include <linux/iio/iio.h>
1212 #include <linux/iio/driver.h>
1313 #include <linux/module.h>
14−#include <linux/of.h>
14+#include <linux/mod_devicetable.h>
1515
1616 #include "ltc2497.h"
1717
@@ -98,7 +98,7 @@ MODULE_DEVICE_TABLE(of, ltc2497_of_match); · 80 unmodified lines
9898 static struct i2c_driver ltc2497_driver = {
9999 .driver = {
100100 .name = "ltc2497",
101− .of_match_table = of_match_ptr(ltc2497_of_match),
101+ .of_match_table = ltc2497_of_match,
102102 },
103103 .probe = ltc2497_probe,
104104 .remove = ltc2497_remove,
drivers/iio/adc/max1027.c+2−5
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414
1515 #include <linux/kernel.h>
1616 #include <linux/module.h>
17+#include <linux/mod_devicetable.h>
1718 #include <linux/spi/spi.h>
1819 #include <linux/delay.h>
1920
@@ -79,7 +80,6 @@ static const struct spi_device_id max1027_id[] = { · 59 unmodified lines
7980 };
8081 MODULE_DEVICE_TABLE(spi, max1027_id);
8182
82−#ifdef CONFIG_OF
8383 static const struct of_device_id max1027_adc_dt_ids[] = {
8484 { .compatible = "maxim,max1027" },
8585 { .compatible = "maxim,max1029" },
@@ -90,7 +90,6 @@ static const struct of_device_id max1027_adc_dt_ids[] = { · 4 unmodified lines
9090 {},
9191 };
9292 MODULE_DEVICE_TABLE(of, max1027_adc_dt_ids);
93−#endif
9493
9594 #define MAX1027_V_CHAN(index, depth) \
9695 { \
@@ -440,8 +439,6 @@ static int max1027_probe(struct spi_device *spi) · 343 unmodified lines
440439 mutex_init(&st->lock);
441440
442441 indio_dev->name = spi_get_device_id(spi)->name;
443− indio_dev->dev.parent = &spi->dev;
444− indio_dev->dev.of_node = spi->dev.of_node;
445442 indio_dev->info = &max1027_info;
446443 indio_dev->modes = INDIO_DIRECT_MODE;
447444 indio_dev->channels = st->info->channels;
@@ -520,7 +517,7 @@ static int max1027_probe(struct spi_device *spi) · 72 unmodified lines
520517 static struct spi_driver max1027_driver = {
521518 .driver = {
522519 .name = "max1027",
523− .of_match_table = of_match_ptr(max1027_adc_dt_ids),
520+ .of_match_table = max1027_adc_dt_ids,
524521 },
525522 .probe = max1027_probe,
526523 .id_table = max1027_id,
drivers/iio/adc/max11100.c+3−4
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 */
99 #include <linux/delay.h>
1010 #include <linux/kernel.h>
11+#include <linux/mod_devicetable.h>
1112 #include <linux/module.h>
1213 #include <linux/regulator/consumer.h>
1314 #include <linux/spi/spi.h>
@@ -37,7 +38,7 @@ struct max11100_state { · 23 unmodified lines
3738 u8 buffer[3] ____cacheline_aligned;
3839 };
3940
40−static struct iio_chan_spec max11100_channels[] = {
41+static const struct iio_chan_spec max11100_channels[] = {
4142 { /* [0] */
4243 .type = IIO_VOLTAGE,
4344 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
@@ -115,8 +116,6 @@ static int max11100_probe(struct spi_device *spi) · 71 unmodified lines
115116 state = iio_priv(indio_dev);
116117 state->spi = spi;
117118
118− indio_dev->dev.parent = &spi->dev;
119− indio_dev->dev.of_node = spi->dev.of_node;
120119 indio_dev->name = "max11100";
121120 indio_dev->info = &max11100_info;
122121 indio_dev->modes = INDIO_DIRECT_MODE;
@@ -163,7 +162,7 @@ MODULE_DEVICE_TABLE(of, max11100_ids); · 40 unmodified lines
163162 static struct spi_driver max11100_driver = {
164163 .driver = {
165164 .name = "max11100",
166− .of_match_table = of_match_ptr(max11100_ids),
165+ .of_match_table = max11100_ids,
167166 },
168167 .probe = max11100_probe,
169168 .remove = max11100_remove,
drivers/iio/adc/max1118.c+2−6
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 */
1919
2020 #include <linux/module.h>
21+#include <linux/mod_devicetable.h>
2122 #include <linux/spi/spi.h>
2223 #include <linux/iio/iio.h>
2324 #include <linux/iio/buffer.h>
@@ -225,7 +226,6 @@ static int max1118_probe(struct spi_device *spi) · 201 unmodified lines
225226 spi_set_drvdata(spi, indio_dev);
226227
227228 indio_dev->name = spi_get_device_id(spi)->name;
228− indio_dev->dev.parent = &spi->dev;
229229 indio_dev->info = &max1118_info;
230230 indio_dev->modes = INDIO_DIRECT_MODE;
231231 indio_dev->channels = max1118_channels;
@@ -281,8 +281,6 @@ static const struct spi_device_id max1118_id[] = { · 49 unmodified lines
281281 };
282282 MODULE_DEVICE_TABLE(spi, max1118_id);
283283
284−#ifdef CONFIG_OF
285−
286284 static const struct of_device_id max1118_dt_ids[] = {
287285 { .compatible = "maxim,max1117" },
288286 { .compatible = "maxim,max1118" },
@@ -291,12 +289,10 @@ static const struct of_device_id max1118_dt_ids[] = { · 2 unmodified lines
291289 };
292290 MODULE_DEVICE_TABLE(of, max1118_dt_ids);
293291
294−#endif
295−
296292 static struct spi_driver max1118_spi_driver = {
297293 .driver = {
298294 .name = "max1118",
299− .of_match_table = of_match_ptr(max1118_dt_ids),
295+ .of_match_table = max1118_dt_ids,
300296 },
301297 .probe = max1118_probe,
302298 .remove = max1118_remove,
drivers/iio/adc/max1241.c+0−1
@@ -192,7 +192,6 @@ static int max1241_probe(struct spi_device *spi) · 191 unmodified lines
192192 dev_dbg(dev, "no shutdown pin passed, low-power mode disabled");
193193
194194 indio_dev->name = spi_get_device_id(spi)->name;
195− indio_dev->dev.parent = dev;
196195 indio_dev->info = &max1241_info;
197196 indio_dev->modes = INDIO_DIRECT_MODE;
198197 indio_dev->channels = max1241_channels;
drivers/iio/adc/max1363.c+4−11
@@ -22,8 +22,8 @@ · 21 unmodified lines
2222 #include <linux/slab.h>
2323 #include <linux/err.h>
2424 #include <linux/module.h>
25−#include <linux/of.h>
26−#include <linux/of_device.h>
25+#include <linux/mod_devicetable.h>
26+#include <linux/property.h>
2727
2828 #include <linux/iio/iio.h>
2929 #include <linux/iio/sysfs.h>
@@ -1529,8 +1529,6 @@ done: · 1499 unmodified lines
15291529 return IRQ_HANDLED;
15301530 }
15311531
1532−#ifdef CONFIG_OF
1533−
15341532 #define MAX1363_COMPATIBLE(of_compatible, cfg) { \
15351533 .compatible = of_compatible, \
15361534 .data = &max1363_chip_info_tbl[cfg], \
@@ -1578,7 +1576,6 @@ static const struct of_device_id max1363_of_match[] = { · 41 unmodified lines
15781576 { /* sentinel */ }
15791577 };
15801578 MODULE_DEVICE_TABLE(of, max1363_of_match);
1581−#endif
15821579
15831580 static int max1363_probe(struct i2c_client *client,
15841581 const struct i2c_device_id *id)
@@ -1593,7 +1590,6 @@ static int max1363_probe(struct i2c_client *client, · 8 unmodified lines
15931590 if (!indio_dev)
15941591 return -ENOMEM;
15951592
1596− indio_dev->dev.of_node = client->dev.of_node;
15971593 ret = iio_map_array_register(indio_dev, client->dev.platform_data);
15981594 if (ret < 0)
15991595 return ret;
@@ -1614,7 +1610,7 @@ static int max1363_probe(struct i2c_client *client, · 14 unmodified lines
16141610 /* this is only used for device removal purposes */
16151611 i2c_set_clientdata(client, indio_dev);
16161612
1617− st->chip_info = of_device_get_match_data(&client->dev);
1613+ st->chip_info = device_get_match_data(&client->dev);
16181614 if (!st->chip_info)
16191615 st->chip_info = &max1363_chip_info_tbl[id->driver_data];
16201616 st->client = client;
@@ -1652,9 +1648,6 @@ static int max1363_probe(struct i2c_client *client, · 31 unmodified lines
16521648 if (ret)
16531649 goto error_disable_reg;
16541650
1655− /* Establish that the iio_dev is a child of the i2c device */
1656− indio_dev->dev.parent = &client->dev;
1657− indio_dev->dev.of_node = client->dev.of_node;
16581651 indio_dev->name = id->name;
16591652 indio_dev->channels = st->chip_info->channels;
16601653 indio_dev->num_channels = st->chip_info->num_channels;
@@ -1760,7 +1753,7 @@ MODULE_DEVICE_TABLE(i2c, max1363_id); · 99 unmodified lines
17601753 static struct i2c_driver max1363_driver = {
17611754 .driver = {
17621755 .name = "max1363",
1763− .of_match_table = of_match_ptr(max1363_of_match),
1756+ .of_match_table = max1363_of_match,
17641757 },
17651758 .probe = max1363_probe,
17661759 .remove = max1363_remove,
drivers/iio/adc/max9611.c+0−2
@@ -545,8 +545,6 @@ static int max9611_probe(struct i2c_client *client, · 544 unmodified lines
545545 if (ret)
546546 return ret;
547547
548− indio_dev->dev.parent = &client->dev;
549− indio_dev->dev.of_node = client->dev.of_node;
550548 indio_dev->name = of_id->data;
551549 indio_dev->modes = INDIO_DIRECT_MODE;
552550 indio_dev->info = &indio_info;
drivers/iio/adc/mcp320x.c+6−9
@@ -27,13 +27,13 @@ · 26 unmodified lines
2727 * MCP3553
2828 *
2929 * Datasheet can be found here:
30− * http://ww1.microchip.com/downloads/en/DeviceDoc/21293C.pdf mcp3001
31− * http://ww1.microchip.com/downloads/en/DeviceDoc/21294E.pdf mcp3002
32− * http://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf mcp3004/08
30+ * https://ww1.microchip.com/downloads/en/DeviceDoc/21293C.pdf mcp3001
31+ * https://ww1.microchip.com/downloads/en/DeviceDoc/21294E.pdf mcp3002
32+ * https://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf mcp3004/08
3333 * http://ww1.microchip.com/downloads/en/DeviceDoc/21290D.pdf mcp3201
3434 * http://ww1.microchip.com/downloads/en/DeviceDoc/21034D.pdf mcp3202
3535 * http://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf mcp3204/08
36− * http://ww1.microchip.com/downloads/en/DeviceDoc/21700E.pdf mcp3301
36+ * https://ww1.microchip.com/downloads/en/DeviceDoc/21700E.pdf mcp3301
3737 * http://ww1.microchip.com/downloads/en/DeviceDoc/21950D.pdf mcp3550/1/3
3838 */
3939
@@ -41,6 +41,7 @@ · 1 unmodified line
4141 #include <linux/delay.h>
4242 #include <linux/spi/spi.h>
4343 #include <linux/module.h>
44+#include <linux/mod_devicetable.h>
4445 #include <linux/iio/iio.h>
4546 #include <linux/regulator/consumer.h>
4647
@@ -384,8 +385,6 @@ static int mcp320x_probe(struct spi_device *spi) · 337 unmodified lines
384385 adc = iio_priv(indio_dev);
385386 adc->spi = spi;
386387
387− indio_dev->dev.parent = &spi->dev;
388− indio_dev->dev.of_node = spi->dev.of_node;
389388 indio_dev->name = spi_get_device_id(spi)->name;
390389 indio_dev->modes = INDIO_DIRECT_MODE;
391390 indio_dev->info = &mcp320x_info;
@@ -471,7 +470,6 @@ static int mcp320x_remove(struct spi_device *spi) · 79 unmodified lines
471470 return 0;
472471 }
473472
474−#if defined(CONFIG_OF)
475473 static const struct of_device_id mcp320x_dt_ids[] = {
476474 /* NOTE: The use of compatibles with no vendor prefix is deprecated. */
477475 { .compatible = "mcp3001" },
@@ -499,7 +497,6 @@ static const struct of_device_id mcp320x_dt_ids[] = { · 21 unmodified lines
499497 { }
500498 };
501499 MODULE_DEVICE_TABLE(of, mcp320x_dt_ids);
502−#endif
503500
504501 static const struct spi_device_id mcp320x_id[] = {
505502 { "mcp3001", mcp3001 },
@@ -522,7 +519,7 @@ MODULE_DEVICE_TABLE(spi, mcp320x_id); · 16 unmodified lines
522519 static struct spi_driver mcp320x_driver = {
523520 .driver = {
524521 .name = "mcp320x",
525− .of_match_table = of_match_ptr(mcp320x_dt_ids),
522+ .of_match_table = mcp320x_dt_ids,
526523 },
527524 .probe = mcp320x_probe,
528525 .remove = mcp320x_remove,
drivers/iio/adc/mcp3422.c+4−8
@@ -6,8 +6,8 @@ · 5 unmodified lines
66 * Author: Angelo Compagnucci <angelo.compagnucci@gmail.com>
77 *
88 * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/22088b.pdf
9− * http://ww1.microchip.com/downloads/en/DeviceDoc/22226a.pdf
10− * http://ww1.microchip.com/downloads/en/DeviceDoc/22072b.pdf
9+ * https://ww1.microchip.com/downloads/en/DeviceDoc/22226a.pdf
10+ * https://ww1.microchip.com/downloads/en/DeviceDoc/22072b.pdf
1111 *
1212 * This driver exports the value of analog input voltage to sysfs, the
1313 * voltage unit is nV.
@@ -16,9 +16,9 @@ · 2 unmodified lines
1616 #include <linux/err.h>
1717 #include <linux/i2c.h>
1818 #include <linux/module.h>
19+#include <linux/mod_devicetable.h>
1920 #include <linux/delay.h>
2021 #include <linux/sysfs.h>
21−#include <linux/of.h>
2222 #include <asm/unaligned.h>
2323
2424 #include <linux/iio/iio.h>
@@ -347,8 +347,6 @@ static int mcp3422_probe(struct i2c_client *client, · 322 unmodified lines
347347
348348 mutex_init(&adc->lock);
349349
350− indio_dev->dev.parent = &client->dev;
351− indio_dev->dev.of_node = client->dev.of_node;
352350 indio_dev->name = dev_name(&client->dev);
353351 indio_dev->modes = INDIO_DIRECT_MODE;
354352 indio_dev->info = &mcp3422_info;
@@ -404,18 +402,16 @@ static const struct i2c_device_id mcp3422_id[] = { · 49 unmodified lines
404402 };
405403 MODULE_DEVICE_TABLE(i2c, mcp3422_id);
406404
407−#ifdef CONFIG_OF
408405 static const struct of_device_id mcp3422_of_match[] = {
409406 { .compatible = "mcp3422" },
410407 { }
411408 };
412409 MODULE_DEVICE_TABLE(of, mcp3422_of_match);
413−#endif
414410
415411 static struct i2c_driver mcp3422_driver = {
416412 .driver = {
417413 .name = "mcp3422",
418− .of_match_table = of_match_ptr(mcp3422_of_match),
414+ .of_match_table = mcp3422_of_match,
419415 },
420416 .probe = mcp3422_probe,
421417 .id_table = mcp3422_id,
drivers/iio/adc/mcp3911.c+0−2
@@ -293,8 +293,6 @@ static int mcp3911_probe(struct spi_device *spi) · 292 unmodified lines
293293 if (ret)
294294 goto clk_disable;
295295
296− indio_dev->dev.parent = &spi->dev;
297− indio_dev->dev.of_node = spi->dev.of_node;
298296 indio_dev->name = spi_get_device_id(spi)->name;
299297 indio_dev->modes = INDIO_DIRECT_MODE;
300298 indio_dev->info = &mcp3911_info;
drivers/iio/adc/men_z188_adc.c+0−1
@@ -110,7 +110,6 @@ static int men_z188_probe(struct mcb_device *dev, · 109 unmodified lines
110110
111111 adc = iio_priv(indio_dev);
112112 indio_dev->name = "z188-adc";
113− indio_dev->dev.parent = &dev->dev;
114113 indio_dev->info = &z188_adc_info;
115114 indio_dev->modes = INDIO_DIRECT_MODE;
116115 indio_dev->channels = z188_adc_iio_channels;
drivers/iio/adc/meson_saradc.c+0−2
@@ -1208,8 +1208,6 @@ static int meson_sar_adc_probe(struct platform_device *pdev) · 1207 unmodified lines
12081208 priv->param = match_data->param;
12091209
12101210 indio_dev->name = match_data->name;
1211− indio_dev->dev.parent = &pdev->dev;
1212− indio_dev->dev.of_node = pdev->dev.of_node;
12131211 indio_dev->modes = INDIO_DIRECT_MODE;
12141212 indio_dev->info = &meson_sar_adc_iio_info;
12151213
drivers/iio/adc/mt6577_auxadc.c+0−1
@@ -245,7 +245,6 @@ static int mt6577_auxadc_probe(struct platform_device *pdev) · 244 unmodified lines
245245 return -ENOMEM;
246246
247247 adc_dev = iio_priv(indio_dev);
248− indio_dev->dev.parent = &pdev->dev;
249248 indio_dev->name = dev_name(&pdev->dev);
250249 indio_dev->info = &mt6577_auxadc_info;
251250 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/mxs-lradc-adc.c+0−3
@@ -568,8 +568,6 @@ static bool mxs_lradc_adc_validate_scan_mask(struct iio_dev *iio, · 567 unmodified lines
568568
569569 static const struct iio_buffer_setup_ops mxs_lradc_adc_buffer_ops = {
570570 .preenable = &mxs_lradc_adc_buffer_preenable,
571− .postenable = &iio_triggered_buffer_postenable,
572− .predisable = &iio_triggered_buffer_predisable,
573571 .postdisable = &mxs_lradc_adc_buffer_postdisable,
574572 .validate_scan_mask = &mxs_lradc_adc_validate_scan_mask,
575573 };
@@ -722,7 +720,6 @@ static int mxs_lradc_adc_probe(struct platform_device *pdev) · 146 unmodified lines
722720 platform_set_drvdata(pdev, iio);
723721
724722 iio->name = pdev->name;
725− iio->dev.parent = dev;
726723 iio->dev.of_node = dev->parent->of_node;
727724 iio->info = &mxs_lradc_adc_iio_info;
728725 iio->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/nau7802.c+0−2
@@ -430,8 +430,6 @@ static int nau7802_probe(struct i2c_client *client, · 429 unmodified lines
430430
431431 i2c_set_clientdata(client, indio_dev);
432432
433− indio_dev->dev.parent = &client->dev;
434− indio_dev->dev.of_node = client->dev.of_node;
435433 indio_dev->name = dev_name(&client->dev);
436434 indio_dev->modes = INDIO_DIRECT_MODE;
437435 indio_dev->info = &nau7802_info;
drivers/iio/adc/npcm_adc.c+0−1
@@ -261,7 +261,6 @@ static int npcm_adc_probe(struct platform_device *pdev) · 260 unmodified lines
261261
262262 platform_set_drvdata(pdev, indio_dev);
263263 indio_dev->name = dev_name(&pdev->dev);
264− indio_dev->dev.parent = &pdev->dev;
265264 indio_dev->info = &npcm_adc_iio_info;
266265 indio_dev->modes = INDIO_DIRECT_MODE;
267266 indio_dev->channels = npcm_adc_iio_channels;
drivers/iio/adc/palmas_gpadc.c+0−1
@@ -593,7 +593,6 @@ static int palmas_gpadc_probe(struct platform_device *pdev) · 592 unmodified lines
593593 adc->extended_delay = gpadc_pdata->extended_delay;
594594
595595 indio_dev->name = MOD_NAME;
596− indio_dev->dev.parent = &pdev->dev;
597596 indio_dev->info = &palmas_gpadc_iio_info;
598597 indio_dev->modes = INDIO_DIRECT_MODE;
599598 indio_dev->channels = palmas_gpadc_iio_channel;
drivers/iio/adc/qcom-pm8xxx-xoadc.c+0−2
@@ -933,8 +933,6 @@ static int pm8xxx_xoadc_probe(struct platform_device *pdev) · 932 unmodified lines
933933 goto out_disable_vref;
934934 }
935935
936− indio_dev->dev.parent = dev;
937− indio_dev->dev.of_node = np;
938936 indio_dev->name = variant->name;
939937 indio_dev->modes = INDIO_DIRECT_MODE;
940938 indio_dev->info = &pm8xxx_xoadc_info;
drivers/iio/adc/qcom-spmi-adc5.c+220−24
@@ -1,6 +1,6 @@
11 // SPDX-License-Identifier: GPL-2.0
22 /*
3− * Copyright (c) 2018, The Linux Foundation. All rights reserved.
3+ * Copyright (c) 2018, 2020, The Linux Foundation. All rights reserved.
44 */
55
66 #include <linux/bitops.h>
@@ -23,6 +23,7 @@ · 16 unmodified lines
2323
2424 #define ADC5_USR_REVISION1 0x0
2525 #define ADC5_USR_STATUS1 0x8
26+#define ADC5_USR_STATUS1_CONV_FAULT BIT(7)
2627 #define ADC5_USR_STATUS1_REQ_STS BIT(1)
2728 #define ADC5_USR_STATUS1_EOC BIT(0)
2829 #define ADC5_USR_STATUS1_REQ_STS_EOC_MASK 0x3
@@ -65,6 +66,9 @@ · 36 unmodified lines
6566
6667 #define ADC5_USR_IBAT_DATA1 0x53
6768
69+#define ADC_CHANNEL_OFFSET 0x8
70+#define ADC_CHANNEL_MASK GENMASK(7, 0)
71+
6872 /*
6973 * Conversion time varies based on the decimation, clock rate, fast average
7074 * samples and measurements queued across different VADC peripherals.
@@ -79,6 +83,11 @@ · 8 unmodified lines
7983 #define ADC5_HW_SETTLE_DIFF_MINOR 3
8084 #define ADC5_HW_SETTLE_DIFF_MAJOR 5
8185
86+/* For PMIC7 */
87+#define ADC_APP_SID 0x40
88+#define ADC_APP_SID_MASK GENMASK(3, 0)
89+#define ADC7_CONV_TIMEOUT msecs_to_jiffies(10)
90+
8291 enum adc5_cal_method {
8392 ADC5_NO_CAL = 0,
8493 ADC5_RATIOMETRIC_CAL,
@@ -96,6 +105,7 @@ enum adc5_cal_val { · 11 unmodified lines
96105 * @cal_method: calibration method.
97106 * @cal_val: calibration value
98107 * @decimation: sampling rate supported for the channel.
108+ * @sid: slave id of PMIC owning the channel, for PMIC7.
99109 * @prescale: channel scaling performed on the input signal.
100110 * @hw_settle_time: the time between AMUX being configured and the
101111 * start of conversion.
@@ -110,6 +120,7 @@ struct adc5_channel_prop { · 8 unmodified lines
110120 enum adc5_cal_method cal_method;
111121 enum adc5_cal_val cal_val;
112122 unsigned int decimation;
123+ unsigned int sid;
113124 unsigned int prescale;
114125 unsigned int hw_settle_time;
115126 unsigned int avg_samples;
@@ -165,6 +176,11 @@ static int adc5_write(struct adc5_chip *adc, u16 offset, u8 *data, int len) · 49 unmodified lines
165176 return regmap_bulk_write(adc->regmap, adc->base + offset, data, len);
166177 }
167178
179+static int adc5_masked_write(struct adc5_chip *adc, u16 offset, u8 mask, u8 val)
180+{
181+ return regmap_update_bits(adc->regmap, adc->base + offset, mask, val);
182+}
183+
168184 static int adc5_prescaling_from_dt(u32 num, u32 den)
169185 {
170186 unsigned int pre;
@@ -230,11 +246,11 @@ static int adc5_read_voltage_data(struct adc5_chip *adc, u16 *data) · 59 unmodified lines
230246 *data = (rslt_msb << 8) | rslt_lsb;
231247
232248 if (*data == ADC5_USR_DATA_CHECK) {
233− pr_err("Invalid data:0x%x\n", *data);
249+ dev_err(adc->dev, "Invalid data:0x%x\n", *data);
234250 return -EINVAL;
235251 }
236252
237− pr_debug("voltage raw code:0x%x\n", *data);
253+ dev_dbg(adc->dev, "voltage raw code:0x%x\n", *data);
238254
239255 return 0;
240256 }
@@ -285,7 +301,7 @@ static int adc5_configure(struct adc5_chip *adc, · 44 unmodified lines
285301
286302 /* Read registers 0x42 through 0x46 */
287303 ret = adc5_read(adc, ADC5_USR_DIG_PARAM, buf, sizeof(buf));
288− if (ret < 0)
304+ if (ret)
289305 return ret;
290306
291307 /* Digital param selection */
@@ -314,6 +330,47 @@ static int adc5_configure(struct adc5_chip *adc, · 22 unmodified lines
314330 return adc5_write(adc, ADC5_USR_DIG_PARAM, buf, sizeof(buf));
315331 }
316332
333+static int adc7_configure(struct adc5_chip *adc,
334+ struct adc5_channel_prop *prop)
335+{
336+ int ret;
337+ u8 conv_req = 0, buf[4];
338+
339+ ret = adc5_masked_write(adc, ADC_APP_SID, ADC_APP_SID_MASK, prop->sid);
340+ if (ret)
341+ return ret;
342+
343+ ret = adc5_read(adc, ADC5_USR_DIG_PARAM, buf, sizeof(buf));
344+ if (ret)
345+ return ret;
346+
347+ /* Digital param selection */
348+ adc5_update_dig_param(adc, prop, &buf[0]);
349+
350+ /* Update fast average sample value */
351+ buf[1] &= ~ADC5_USR_FAST_AVG_CTL_SAMPLES_MASK;
352+ buf[1] |= prop->avg_samples;
353+
354+ /* Select ADC channel */
355+ buf[2] = prop->channel;
356+
357+ /* Select HW settle delay for channel */
358+ buf[3] &= ~ADC5_USR_HW_SETTLE_DELAY_MASK;
359+ buf[3] |= prop->hw_settle_time;
360+
361+ /* Select CONV request */
362+ conv_req = ADC5_USR_CONV_REQ_REQ;
363+
364+ if (!adc->poll_eoc)
365+ reinit_completion(&adc->complete);
366+
367+ ret = adc5_write(adc, ADC5_USR_DIG_PARAM, buf, sizeof(buf));
368+ if (ret)
369+ return ret;
370+
371+ return adc5_write(adc, ADC5_USR_CONV_REQ, &conv_req, 1);
372+}
373+
317374 static int adc5_do_conversion(struct adc5_chip *adc,
318375 struct adc5_channel_prop *prop,
319376 struct iio_chan_spec const *chan,
@@ -325,24 +382,24 @@ static int adc5_do_conversion(struct adc5_chip *adc, · 5 unmodified lines
325382
326383 ret = adc5_configure(adc, prop);
327384 if (ret) {
328− pr_err("ADC configure failed with %d\n", ret);
385+ dev_err(adc->dev, "ADC configure failed with %d\n", ret);
329386 goto unlock;
330387 }
331388
332389 if (adc->poll_eoc) {
333390 ret = adc5_poll_wait_eoc(adc);
334− if (ret < 0) {
335− pr_err("EOC bit not set\n");
391+ if (ret) {
392+ dev_err(adc->dev, "EOC bit not set\n");
336393 goto unlock;
337394 }
338395 } else {
339396 ret = wait_for_completion_timeout(&adc->complete,
340397 ADC5_CONV_TIMEOUT);
341398 if (!ret) {
342− pr_debug("Did not get completion timeout.\n");
399+ dev_dbg(adc->dev, "Did not get completion timeout.\n");
343400 ret = adc5_poll_wait_eoc(adc);
344− if (ret < 0) {
345− pr_err("EOC bit not set\n");
401+ if (ret) {
402+ dev_err(adc->dev, "EOC bit not set\n");
346403 goto unlock;
347404 }
348405 }
@@ -355,6 +412,48 @@ unlock: · 6 unmodified lines
355412 return ret;
356413 }
357414
415+static int adc7_do_conversion(struct adc5_chip *adc,
416+ struct adc5_channel_prop *prop,
417+ struct iio_chan_spec const *chan,
418+ u16 *data_volt, u16 *data_cur)
419+{
420+ int ret;
421+ u8 status;
422+
423+ mutex_lock(&adc->lock);
424+
425+ ret = adc7_configure(adc, prop);
426+ if (ret) {
427+ dev_err(adc->dev, "ADC configure failed with %d\n", ret);
428+ goto unlock;
429+ }
430+
431+ /* No support for polling mode at present */
432+ wait_for_completion_timeout(&adc->complete, ADC7_CONV_TIMEOUT);
433+
434+ ret = adc5_read(adc, ADC5_USR_STATUS1, &status, 1);
435+ if (ret)
436+ goto unlock;
437+
438+ if (status & ADC5_USR_STATUS1_CONV_FAULT) {
439+ dev_err(adc->dev, "Unexpected conversion fault\n");
440+ ret = -EIO;
441+ goto unlock;
442+ }
443+
444+ ret = adc5_read_voltage_data(adc, data_volt);
445+
446+unlock:
447+ mutex_unlock(&adc->lock);
448+
449+ return ret;
450+}
451+
452+typedef int (*adc_do_conversion)(struct adc5_chip *adc,
453+ struct adc5_channel_prop *prop,
454+ struct iio_chan_spec const *chan,
455+ u16 *data_volt, u16 *data_cur);
456+
358457 static irqreturn_t adc5_isr(int irq, void *dev_id)
359458 {
360459 struct adc5_chip *adc = dev_id;
@@ -377,9 +476,25 @@ static int adc5_of_xlate(struct iio_dev *indio_dev, · 16 unmodified lines
377476 return -EINVAL;
378477 }
379478
380−static int adc5_read_raw(struct iio_dev *indio_dev,
479+static int adc7_of_xlate(struct iio_dev *indio_dev,
480+ const struct of_phandle_args *iiospec)
481+{
482+ struct adc5_chip *adc = iio_priv(indio_dev);
483+ int i, v_channel;
484+
485+ for (i = 0; i < adc->nchannels; i++) {
486+ v_channel = (adc->chan_props[i].sid << ADC_CHANNEL_OFFSET) |
487+ adc->chan_props[i].channel;
488+ if (v_channel == iiospec->args[0])
489+ return i;
490+ }
491+
492+ return -EINVAL;
493+}
494+
495+static int adc_read_raw_common(struct iio_dev *indio_dev,
381496 struct iio_chan_spec const *chan, int *val, int *val2,
382− long mask)
497+ long mask, adc_do_conversion do_conv)
383498 {
384499 struct adc5_chip *adc = iio_priv(indio_dev);
385500 struct adc5_channel_prop *prop;
@@ -390,8 +505,8 @@ static int adc5_read_raw(struct iio_dev *indio_dev, · 4 unmodified lines
390505
391506 switch (mask) {
392507 case IIO_CHAN_INFO_PROCESSED:
393− ret = adc5_do_conversion(adc, prop, chan,
394− &adc_code_volt, &adc_code_cur);
508+ ret = do_conv(adc, prop, chan,
509+ &adc_code_volt, &adc_code_cur);
395510 if (ret)
396511 return ret;
397512
@@ -406,8 +521,22 @@ static int adc5_read_raw(struct iio_dev *indio_dev, · 8 unmodified lines
406521 default:
407522 return -EINVAL;
408523 }
524+}
409525
410− return 0;
526+static int adc5_read_raw(struct iio_dev *indio_dev,
527+ struct iio_chan_spec const *chan, int *val, int *val2,
528+ long mask)
529+{
530+ return adc_read_raw_common(indio_dev, chan, val, val2,
531+ mask, adc5_do_conversion);
532+}
533+
534+static int adc7_read_raw(struct iio_dev *indio_dev,
535+ struct iio_chan_spec const *chan, int *val, int *val2,
536+ long mask)
537+{
538+ return adc_read_raw_common(indio_dev, chan, val, val2,
539+ mask, adc7_do_conversion);
411540 }
412541
413542 static const struct iio_info adc5_info = {
@@ -415,6 +544,11 @@ static const struct iio_info adc5_info = { · 1 unmodified line
415544 .of_xlate = adc5_of_xlate,
416545 };
417546
547+static const struct iio_info adc7_info = {
548+ .read_raw = adc7_read_raw,
549+ .of_xlate = adc7_of_xlate,
550+};
551+
418552 struct adc5_channels {
419553 const char *datasheet_name;
420554 unsigned int prescale_index;
@@ -477,6 +611,39 @@ static const struct adc5_channels adc5_chans_pmic[ADC5_MAX_CHANNEL] = { · 56 unmodified lines
477611 SCALE_HW_CALIB_PM5_SMB_TEMP)
478612 };
479613
614+static const struct adc5_channels adc7_chans_pmic[ADC5_MAX_CHANNEL] = {
615+ [ADC7_REF_GND] = ADC5_CHAN_VOLT("ref_gnd", 0,
616+ SCALE_HW_CALIB_DEFAULT)
617+ [ADC7_1P25VREF] = ADC5_CHAN_VOLT("vref_1p25", 0,
618+ SCALE_HW_CALIB_DEFAULT)
619+ [ADC7_VPH_PWR] = ADC5_CHAN_VOLT("vph_pwr", 1,
620+ SCALE_HW_CALIB_DEFAULT)
621+ [ADC7_VBAT_SNS] = ADC5_CHAN_VOLT("vbat_sns", 3,
622+ SCALE_HW_CALIB_DEFAULT)
623+ [ADC7_DIE_TEMP] = ADC5_CHAN_TEMP("die_temp", 0,
624+ SCALE_HW_CALIB_PMIC_THERM_PM7)
625+ [ADC7_AMUX_THM1_100K_PU] = ADC5_CHAN_TEMP("amux_thm1_pu2", 0,
626+ SCALE_HW_CALIB_THERM_100K_PU_PM7)
627+ [ADC7_AMUX_THM2_100K_PU] = ADC5_CHAN_TEMP("amux_thm2_pu2", 0,
628+ SCALE_HW_CALIB_THERM_100K_PU_PM7)
629+ [ADC7_AMUX_THM3_100K_PU] = ADC5_CHAN_TEMP("amux_thm3_pu2", 0,
630+ SCALE_HW_CALIB_THERM_100K_PU_PM7)
631+ [ADC7_AMUX_THM4_100K_PU] = ADC5_CHAN_TEMP("amux_thm4_pu2", 0,
632+ SCALE_HW_CALIB_THERM_100K_PU_PM7)
633+ [ADC7_AMUX_THM5_100K_PU] = ADC5_CHAN_TEMP("amux_thm5_pu2", 0,
634+ SCALE_HW_CALIB_THERM_100K_PU_PM7)
635+ [ADC7_AMUX_THM6_100K_PU] = ADC5_CHAN_TEMP("amux_thm6_pu2", 0,
636+ SCALE_HW_CALIB_THERM_100K_PU_PM7)
637+ [ADC7_GPIO1_100K_PU] = ADC5_CHAN_TEMP("gpio1_pu2", 0,
638+ SCALE_HW_CALIB_THERM_100K_PU_PM7)
639+ [ADC7_GPIO2_100K_PU] = ADC5_CHAN_TEMP("gpio2_pu2", 0,
640+ SCALE_HW_CALIB_THERM_100K_PU_PM7)
641+ [ADC7_GPIO3_100K_PU] = ADC5_CHAN_TEMP("gpio3_pu2", 0,
642+ SCALE_HW_CALIB_THERM_100K_PU_PM7)
643+ [ADC7_GPIO4_100K_PU] = ADC5_CHAN_TEMP("gpio4_pu2", 0,
644+ SCALE_HW_CALIB_THERM_100K_PU_PM7)
645+};
646+
480647 static const struct adc5_channels adc5_chans_rev2[ADC5_MAX_CHANNEL] = {
481648 [ADC5_REF_GND] = ADC5_CHAN_VOLT("ref_gnd", 0,
482649 SCALE_HW_CALIB_DEFAULT)
@@ -511,6 +678,7 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc, · 28 unmodified lines
511678 {
512679 const char *name = node->name, *channel_name;
513680 u32 chan, value, varr[2];
681+ u32 sid = 0;
514682 int ret;
515683 struct device *dev = adc->dev;
516684
@@ -520,6 +688,15 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc, · 3 unmodified lines
520688 return ret;
521689 }
522690
691+ /* Value read from "reg" is virtual channel number */
692+
693+ /* virtual channel number = sid << 8 | channel number */
694+
695+ if (adc->data->info == &adc7_info) {
696+ sid = chan >> ADC_CHANNEL_OFFSET;
697+ chan = chan & ADC_CHANNEL_MASK;
698+ }
699+
523700 if (chan > ADC5_PARALLEL_ISENSE_VBAT_IDATA ||
524701 !data->adc_chans[chan].datasheet_name) {
525702 dev_err(dev, "%s invalid channel number %d\n", name, chan);
@@ -528,11 +705,12 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc, · 2 unmodified lines
528705
529706 /* the channel has DT description */
530707 prop->channel = chan;
708+ prop->sid = sid;
531709
532710 channel_name = of_get_property(node,
533711 "label", NULL) ? : node->name;
534712 if (!channel_name) {
535− pr_err("Invalid channel name\n");
713+ dev_err(dev, "Invalid channel name\n");
536714 return -EINVAL;
537715 }
538716 prop->datasheet_name = channel_name;
@@ -570,16 +748,17 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc, · 31 unmodified lines
570748
571749 ret = adc5_read(adc, ADC5_USR_REVISION1, dig_version,
572750 sizeof(dig_version));
573− if (ret < 0) {
751+ if (ret) {
574752 dev_err(dev, "Invalid dig version read %d\n", ret);
575753 return ret;
576754 }
577755
578− pr_debug("dig_ver:minor:%d, major:%d\n", dig_version[0],
756+ dev_dbg(dev, "dig_ver:minor:%d, major:%d\n", dig_version[0],
579757 dig_version[1]);
580758 /* Digital controller >= 5.3 have hw_settle_2 option */
581− if (dig_version[0] >= ADC5_HW_SETTLE_DIFF_MINOR &&
582− dig_version[1] >= ADC5_HW_SETTLE_DIFF_MAJOR)
759+ if ((dig_version[0] >= ADC5_HW_SETTLE_DIFF_MINOR &&
760+ dig_version[1] >= ADC5_HW_SETTLE_DIFF_MAJOR) ||
761+ adc->data->info == &adc7_info)
583762 ret = adc5_hw_settle_time_from_dt(value,
584763 data->hw_settle_2);
585764 else
@@ -629,6 +808,7 @@ static const struct adc5_data adc5_data_pmic = { · 43 unmodified lines
629808 .full_scale_code_volt = 0x70e4,
630809 .full_scale_code_cur = 0x2710,
631810 .adc_chans = adc5_chans_pmic,
811+ .info = &adc5_info,
632812 .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])
633813 {250, 420, 840},
634814 .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])
@@ -639,10 +819,23 @@ static const struct adc5_data adc5_data_pmic = { · 4 unmodified lines
639819 1, 2, 4, 8, 16, 32, 64, 128},
640820 };
641821
822+static const struct adc5_data adc7_data_pmic = {
823+ .full_scale_code_volt = 0x70e4,
824+ .adc_chans = adc7_chans_pmic,
825+ .info = &adc7_info,
826+ .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])
827+ {85, 340, 1360},
828+ .hw_settle_2 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])
829+ {15, 100, 200, 300, 400, 500, 600, 700,
830+ 1000, 2000, 4000, 8000, 16000, 32000,
831+ 64000, 128000},
832+};
833+
642834 static const struct adc5_data adc5_data_pmic_rev2 = {
643835 .full_scale_code_volt = 0x4000,
644836 .full_scale_code_cur = 0x1800,
645837 .adc_chans = adc5_chans_rev2,
838+ .info = &adc5_info,
646839 .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])
647840 {256, 512, 1024},
648841 .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])
@@ -658,6 +851,10 @@ static const struct of_device_id adc5_match_table[] = { · 9 unmodified lines
658851 .compatible = "qcom,spmi-adc5",
659852 .data = &adc5_data_pmic,
660853 },
854+ {
855+ .compatible = "qcom,spmi-adc7",
856+ .data = &adc7_data_pmic,
857+ },
661858 {
662859 .compatible = "qcom,spmi-adc-rev2",
663860 .data = &adc5_data_pmic_rev2,
@@ -752,12 +949,13 @@ static int adc5_probe(struct platform_device *pdev) · 88 unmodified lines
752949 adc->regmap = regmap;
753950 adc->dev = dev;
754951 adc->base = reg;
952+
755953 init_completion(&adc->complete);
756954 mutex_init(&adc->lock);
757955
758956 ret = adc5_get_dt_data(adc, node);
759957 if (ret) {
760− pr_err("adc get dt data failed\n");
958+ dev_err(dev, "adc get dt data failed\n");
761959 return ret;
762960 }
763961
@@ -773,11 +971,9 @@ static int adc5_probe(struct platform_device *pdev) · 9 unmodified lines
773971 return ret;
774972 }
775973
776− indio_dev->dev.parent = dev;
777− indio_dev->dev.of_node = node;
778974 indio_dev->name = pdev->name;
779975 indio_dev->modes = INDIO_DIRECT_MODE;
780− indio_dev->info = &adc5_info;
976+ indio_dev->info = adc->data->info;
781977 indio_dev->channels = adc->iio_chans;
782978 indio_dev->num_channels = adc->nchannels;
783979
drivers/iio/adc/qcom-spmi-iadc.c+0−2
@@ -553,8 +553,6 @@ static int iadc_probe(struct platform_device *pdev) · 552 unmodified lines
553553 return ret;
554554 }
555555
556− indio_dev->dev.parent = dev;
557− indio_dev->dev.of_node = node;
558556 indio_dev->name = pdev->name;
559557 indio_dev->modes = INDIO_DIRECT_MODE;
560558 indio_dev->info = &iadc_info;
drivers/iio/adc/qcom-spmi-vadc.c+0−2
@@ -907,8 +907,6 @@ static int vadc_probe(struct platform_device *pdev) · 906 unmodified lines
907907 if (ret)
908908 return ret;
909909
910− indio_dev->dev.parent = dev;
911− indio_dev->dev.of_node = node;
912910 indio_dev->name = pdev->name;
913911 indio_dev->modes = INDIO_DIRECT_MODE;
914912 indio_dev->info = &vadc_info;
drivers/iio/adc/qcom-vadc-common.c+262−0
@@ -89,6 +89,195 @@ static const struct vadc_map_pt adcmap_100k_104ef_104fb_1875_vref[] = { · 88 unmodified lines
8989 { 46, 125000 },
9090 };
9191
92+static const struct vadc_map_pt adcmap7_die_temp[] = {
93+ { 433700, 1967},
94+ { 473100, 1964},
95+ { 512400, 1957},
96+ { 551500, 1949},
97+ { 590500, 1940},
98+ { 629300, 1930},
99+ { 667900, 1921},
100+ { 706400, 1910},
101+ { 744600, 1896},
102+ { 782500, 1878},
103+ { 820100, 1859},
104+ { 857300, 0},
105+};
106+
107+/*
108+ * Resistance to temperature table for 100k pull up for NTCG104EF104.
109+ */
110+static const struct vadc_map_pt adcmap7_100k[] = {
111+ { 4250657, -40960 },
112+ { 3962085, -39936 },
113+ { 3694875, -38912 },
114+ { 3447322, -37888 },
115+ { 3217867, -36864 },
116+ { 3005082, -35840 },
117+ { 2807660, -34816 },
118+ { 2624405, -33792 },
119+ { 2454218, -32768 },
120+ { 2296094, -31744 },
121+ { 2149108, -30720 },
122+ { 2012414, -29696 },
123+ { 1885232, -28672 },
124+ { 1766846, -27648 },
125+ { 1656598, -26624 },
126+ { 1553884, -25600 },
127+ { 1458147, -24576 },
128+ { 1368873, -23552 },
129+ { 1285590, -22528 },
130+ { 1207863, -21504 },
131+ { 1135290, -20480 },
132+ { 1067501, -19456 },
133+ { 1004155, -18432 },
134+ { 944935, -17408 },
135+ { 889550, -16384 },
136+ { 837731, -15360 },
137+ { 789229, -14336 },
138+ { 743813, -13312 },
139+ { 701271, -12288 },
140+ { 661405, -11264 },
141+ { 624032, -10240 },
142+ { 588982, -9216 },
143+ { 556100, -8192 },
144+ { 525239, -7168 },
145+ { 496264, -6144 },
146+ { 469050, -5120 },
147+ { 443480, -4096 },
148+ { 419448, -3072 },
149+ { 396851, -2048 },
150+ { 375597, -1024 },
151+ { 355598, 0 },
152+ { 336775, 1024 },
153+ { 319052, 2048 },
154+ { 302359, 3072 },
155+ { 286630, 4096 },
156+ { 271806, 5120 },
157+ { 257829, 6144 },
158+ { 244646, 7168 },
159+ { 232209, 8192 },
160+ { 220471, 9216 },
161+ { 209390, 10240 },
162+ { 198926, 11264 },
163+ { 189040, 12288 },
164+ { 179698, 13312 },
165+ { 170868, 14336 },
166+ { 162519, 15360 },
167+ { 154622, 16384 },
168+ { 147150, 17408 },
169+ { 140079, 18432 },
170+ { 133385, 19456 },
171+ { 127046, 20480 },
172+ { 121042, 21504 },
173+ { 115352, 22528 },
174+ { 109960, 23552 },
175+ { 104848, 24576 },
176+ { 100000, 25600 },
177+ { 95402, 26624 },
178+ { 91038, 27648 },
179+ { 86897, 28672 },
180+ { 82965, 29696 },
181+ { 79232, 30720 },
182+ { 75686, 31744 },
183+ { 72316, 32768 },
184+ { 69114, 33792 },
185+ { 66070, 34816 },
186+ { 63176, 35840 },
187+ { 60423, 36864 },
188+ { 57804, 37888 },
189+ { 55312, 38912 },
190+ { 52940, 39936 },
191+ { 50681, 40960 },
192+ { 48531, 41984 },
193+ { 46482, 43008 },
194+ { 44530, 44032 },
195+ { 42670, 45056 },
196+ { 40897, 46080 },
197+ { 39207, 47104 },
198+ { 37595, 48128 },
199+ { 36057, 49152 },
200+ { 34590, 50176 },
201+ { 33190, 51200 },
202+ { 31853, 52224 },
203+ { 30577, 53248 },
204+ { 29358, 54272 },
205+ { 28194, 55296 },
206+ { 27082, 56320 },
207+ { 26020, 57344 },
208+ { 25004, 58368 },
209+ { 24033, 59392 },
210+ { 23104, 60416 },
211+ { 22216, 61440 },
212+ { 21367, 62464 },
213+ { 20554, 63488 },
214+ { 19776, 64512 },
215+ { 19031, 65536 },
216+ { 18318, 66560 },
217+ { 17636, 67584 },
218+ { 16982, 68608 },
219+ { 16355, 69632 },
220+ { 15755, 70656 },
221+ { 15180, 71680 },
222+ { 14628, 72704 },
223+ { 14099, 73728 },
224+ { 13592, 74752 },
225+ { 13106, 75776 },
226+ { 12640, 76800 },
227+ { 12192, 77824 },
228+ { 11762, 78848 },
229+ { 11350, 79872 },
230+ { 10954, 80896 },
231+ { 10574, 81920 },
232+ { 10209, 82944 },
233+ { 9858, 83968 },
234+ { 9521, 84992 },
235+ { 9197, 86016 },
236+ { 8886, 87040 },
237+ { 8587, 88064 },
238+ { 8299, 89088 },
239+ { 8023, 90112 },
240+ { 7757, 91136 },
241+ { 7501, 92160 },
242+ { 7254, 93184 },
243+ { 7017, 94208 },
244+ { 6789, 95232 },
245+ { 6570, 96256 },
246+ { 6358, 97280 },
247+ { 6155, 98304 },
248+ { 5959, 99328 },
249+ { 5770, 100352 },
250+ { 5588, 101376 },
251+ { 5412, 102400 },
252+ { 5243, 103424 },
253+ { 5080, 104448 },
254+ { 4923, 105472 },
255+ { 4771, 106496 },
256+ { 4625, 107520 },
257+ { 4484, 108544 },
258+ { 4348, 109568 },
259+ { 4217, 110592 },
260+ { 4090, 111616 },
261+ { 3968, 112640 },
262+ { 3850, 113664 },
263+ { 3736, 114688 },
264+ { 3626, 115712 },
265+ { 3519, 116736 },
266+ { 3417, 117760 },
267+ { 3317, 118784 },
268+ { 3221, 119808 },
269+ { 3129, 120832 },
270+ { 3039, 121856 },
271+ { 2952, 122880 },
272+ { 2868, 123904 },
273+ { 2787, 124928 },
274+ { 2709, 125952 },
275+ { 2633, 126976 },
276+ { 2560, 128000 },
277+ { 2489, 129024 },
278+ { 2420, 130048 }
279+};
280+
92281 static int qcom_vadc_scale_hw_calib_volt(
93282 const struct vadc_prescale_ratio *prescale,
94283 const struct adc5_data *data,
@@ -97,6 +286,10 @@ static int qcom_vadc_scale_hw_calib_therm( · 2 unmodified lines
97286 const struct vadc_prescale_ratio *prescale,
98287 const struct adc5_data *data,
99288 u16 adc_code, int *result_mdec);
289+static int qcom_vadc7_scale_hw_calib_therm(
290+ const struct vadc_prescale_ratio *prescale,
291+ const struct adc5_data *data,
292+ u16 adc_code, int *result_mdec);
100293 static int qcom_vadc_scale_hw_smb_temp(
101294 const struct vadc_prescale_ratio *prescale,
102295 const struct adc5_data *data,
@@ -109,12 +302,20 @@ static int qcom_vadc_scale_hw_calib_die_temp( · 6 unmodified lines
109302 const struct vadc_prescale_ratio *prescale,
110303 const struct adc5_data *data,
111304 u16 adc_code, int *result_mdec);
305+static int qcom_vadc7_scale_hw_calib_die_temp(
306+ const struct vadc_prescale_ratio *prescale,
307+ const struct adc5_data *data,
308+ u16 adc_code, int *result_mdec);
112309
113310 static struct qcom_adc5_scale_type scale_adc5_fn[] = {
114311 [SCALE_HW_CALIB_DEFAULT] = {qcom_vadc_scale_hw_calib_volt},
115312 [SCALE_HW_CALIB_THERM_100K_PULLUP] = {qcom_vadc_scale_hw_calib_therm},
116313 [SCALE_HW_CALIB_XOTHERM] = {qcom_vadc_scale_hw_calib_therm},
314+ [SCALE_HW_CALIB_THERM_100K_PU_PM7] = {
315+ qcom_vadc7_scale_hw_calib_therm},
117316 [SCALE_HW_CALIB_PMIC_THERM] = {qcom_vadc_scale_hw_calib_die_temp},
317+ [SCALE_HW_CALIB_PMIC_THERM_PM7] = {
318+ qcom_vadc7_scale_hw_calib_die_temp},
118319 [SCALE_HW_CALIB_PM5_CHG_TEMP] = {qcom_vadc_scale_hw_chg5_temp},
119320 [SCALE_HW_CALIB_PM5_SMB_TEMP] = {qcom_vadc_scale_hw_smb_temp},
120321 };
@@ -291,6 +492,32 @@ static int qcom_vadc_scale_code_voltage_factor(u16 adc_code, · 170 unmodified lines
291492 return (int) voltage;
292493 }
293494
495+static int qcom_vadc7_scale_hw_calib_therm(
496+ const struct vadc_prescale_ratio *prescale,
497+ const struct adc5_data *data,
498+ u16 adc_code, int *result_mdec)
499+{
500+ s64 resistance = adc_code;
501+ int ret, result;
502+
503+ if (adc_code >= RATIO_MAX_ADC7)
504+ return -EINVAL;
505+
506+ /* (ADC code * R_PULLUP (100Kohm)) / (full_scale_code - ADC code)*/
507+ resistance *= R_PU_100K;
508+ resistance = div64_s64(resistance, RATIO_MAX_ADC7 - adc_code);
509+
510+ ret = qcom_vadc_map_voltage_temp(adcmap7_100k,
511+ ARRAY_SIZE(adcmap7_100k),
512+ resistance, &result);
513+ if (ret)
514+ return ret;
515+
516+ *result_mdec = result;
517+
518+ return 0;
519+}
520+
294521 static int qcom_vadc_scale_hw_calib_volt(
295522 const struct vadc_prescale_ratio *prescale,
296523 const struct adc5_data *data,
@@ -330,6 +557,41 @@ static int qcom_vadc_scale_hw_calib_die_temp( · 33 unmodified lines
330557 return 0;
331558 }
332559
560+static int qcom_vadc7_scale_hw_calib_die_temp(
561+ const struct vadc_prescale_ratio *prescale,
562+ const struct adc5_data *data,
563+ u16 adc_code, int *result_mdec)
564+{
565+
566+ int voltage, vtemp0, temp, i;
567+
568+ voltage = qcom_vadc_scale_code_voltage_factor(adc_code,
569+ prescale, data, 1);
570+
571+ if (adcmap7_die_temp[0].x > voltage) {
572+ *result_mdec = DIE_TEMP_ADC7_SCALE_1;
573+ return 0;
574+ }
575+
576+ if (adcmap7_die_temp[ARRAY_SIZE(adcmap7_die_temp) - 1].x <= voltage) {
577+ *result_mdec = DIE_TEMP_ADC7_MAX;
578+ return 0;
579+ }
580+
581+ for (i = 0; i < ARRAY_SIZE(adcmap7_die_temp); i++)
582+ if (adcmap7_die_temp[i].x > voltage)
583+ break;
584+
585+ vtemp0 = adcmap7_die_temp[i - 1].x;
586+ voltage = voltage - vtemp0;
587+ temp = div64_s64(voltage * DIE_TEMP_ADC7_SCALE_FACTOR,
588+ adcmap7_die_temp[i - 1].y);
589+ temp += DIE_TEMP_ADC7_SCALE_1 + (DIE_TEMP_ADC7_SCALE_2 * (i - 1));
590+ *result_mdec = temp;
591+
592+ return 0;
593+}
594+
333595 static int qcom_vadc_scale_hw_smb_temp(
334596 const struct vadc_prescale_ratio *prescale,
335597 const struct adc5_data *data,
drivers/iio/adc/qcom-vadc-common.h+15−0
@@ -49,6 +49,14 @@ · 48 unmodified lines
4949 #define ADC5_FULL_SCALE_CODE 0x70e4
5050 #define ADC5_USR_DATA_CHECK 0x8000
5151
52+#define R_PU_100K 100000
53+#define RATIO_MAX_ADC7 BIT(14)
54+
55+#define DIE_TEMP_ADC7_SCALE_1 -60000
56+#define DIE_TEMP_ADC7_SCALE_2 20000
57+#define DIE_TEMP_ADC7_SCALE_FACTOR 1000
58+#define DIE_TEMP_ADC7_MAX 160000
59+
5260 /**
5361 * struct vadc_map_pt - Map the graph representation for ADC channel
5462 * @x: Represent the ADC digitized code.
@@ -110,8 +118,12 @@ struct vadc_prescale_ratio { · 55 unmodified lines
110118 * lookup table. The hardware applies offset/slope to adc code.
111119 * SCALE_HW_CALIB_XOTHERM: Returns XO thermistor voltage in millidegC using
112120 * 100k pullup. The hardware applies offset/slope to adc code.
121+ * SCALE_HW_CALIB_THERM_100K_PU_PM7: Returns temperature in millidegC using
122+ * lookup table for PMIC7. The hardware applies offset/slope to adc code.
113123 * SCALE_HW_CALIB_PMIC_THERM: Returns result in milli degree's Centigrade.
114124 * The hardware applies offset/slope to adc code.
125+ * SCALE_HW_CALIB_PMIC_THERM: Returns result in milli degree's Centigrade.
126+ * The hardware applies offset/slope to adc code. This is for PMIC7.
115127 * SCALE_HW_CALIB_PM5_CHG_TEMP: Returns result in millidegrees for PMIC5
116128 * charger temperature.
117129 * SCALE_HW_CALIB_PM5_SMB_TEMP: Returns result in millidegrees for PMIC5
@@ -126,7 +138,9 @@ enum vadc_scale_fn_type { · 8 unmodified lines
126138 SCALE_HW_CALIB_DEFAULT,
127139 SCALE_HW_CALIB_THERM_100K_PULLUP,
128140 SCALE_HW_CALIB_XOTHERM,
141+ SCALE_HW_CALIB_THERM_100K_PU_PM7,
129142 SCALE_HW_CALIB_PMIC_THERM,
143+ SCALE_HW_CALIB_PMIC_THERM_PM7,
130144 SCALE_HW_CALIB_PM5_CHG_TEMP,
131145 SCALE_HW_CALIB_PM5_SMB_TEMP,
132146 SCALE_HW_CALIB_INVALID,
@@ -136,6 +150,7 @@ struct adc5_data { · 3 unmodified lines
136150 const u32 full_scale_code_volt;
137151 const u32 full_scale_code_cur;
138152 const struct adc5_channels *adc_chans;
153+ const struct iio_info *info;
139154 unsigned int *decimation;
140155 unsigned int *hw_settle_1;
141156 unsigned int *hw_settle_2;
drivers/iio/adc/rcar-gyroadc.c+0−2
@@ -516,8 +516,6 @@ static int rcar_gyroadc_probe(struct platform_device *pdev) · 515 unmodified lines
516516 platform_set_drvdata(pdev, indio_dev);
517517
518518 indio_dev->name = DRIVER_NAME;
519− indio_dev->dev.parent = dev;
520− indio_dev->dev.of_node = pdev->dev.of_node;
521519 indio_dev->info = &rcar_gyroadc_iio_info;
522520 indio_dev->modes = INDIO_DIRECT_MODE;
523521
drivers/iio/adc/rn5t618-adc.c+0−1
@@ -218,7 +218,6 @@ static int rn5t618_adc_probe(struct platform_device *pdev) · 217 unmodified lines
218218 init_completion(&adc->conv_completion);
219219
220220 iio_dev->name = dev_name(&pdev->dev);
221− iio_dev->dev.parent = &pdev->dev;
222221 iio_dev->info = &rn5t618_adc_iio_info;
223222 iio_dev->modes = INDIO_DIRECT_MODE;
224223 iio_dev->channels = rn5t618_adc_iio_channels;
drivers/iio/adc/rockchip_saradc.c+154−65
@@ -15,7 +15,10 @@ · 14 unmodified lines
1515 #include <linux/delay.h>
1616 #include <linux/reset.h>
1717 #include <linux/regulator/consumer.h>
18+#include <linux/iio/buffer.h>
1819 #include <linux/iio/iio.h>
20+#include <linux/iio/trigger_consumer.h>
21+#include <linux/iio/triggered_buffer.h>
1922
2023 #define SARADC_DATA 0x00
2124
@@ -32,9 +35,9 @@ · 10 unmodified lines
3235 #define SARADC_DLY_PU_SOC_MASK 0x3f
3336
3437 #define SARADC_TIMEOUT msecs_to_jiffies(100)
38+#define SARADC_MAX_CHANNELS 6
3539
3640 struct rockchip_saradc_data {
37− int num_bits;
3841 const struct iio_chan_spec *channels;
3942 int num_channels;
4043 unsigned long clk_rate;
@@ -49,8 +52,37 @@ struct rockchip_saradc { · 8 unmodified lines
4952 struct reset_control *reset;
5053 const struct rockchip_saradc_data *data;
5154 u16 last_val;
55+ const struct iio_chan_spec *last_chan;
5256 };
5357
58+static void rockchip_saradc_power_down(struct rockchip_saradc *info)
59+{
60+ /* Clear irq & power down adc */
61+ writel_relaxed(0, info->regs + SARADC_CTRL);
62+}
63+
64+static int rockchip_saradc_conversion(struct rockchip_saradc *info,
65+ struct iio_chan_spec const *chan)
66+{
67+ reinit_completion(&info->completion);
68+
69+ /* 8 clock periods as delay between power up and start cmd */
70+ writel_relaxed(8, info->regs + SARADC_DLY_PU_SOC);
71+
72+ info->last_chan = chan;
73+
74+ /* Select the channel to be used and trigger conversion */
75+ writel(SARADC_CTRL_POWER_CTRL
76+ | (chan->channel & SARADC_CTRL_CHN_MASK)
77+ | SARADC_CTRL_IRQ_ENABLE,
78+ info->regs + SARADC_CTRL);
79+
80+ if (!wait_for_completion_timeout(&info->completion, SARADC_TIMEOUT))
81+ return -ETIMEDOUT;
82+
83+ return 0;
84+}
85+
5486 static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,
5587 struct iio_chan_spec const *chan,
5688 int *val, int *val2, long mask)
@@ -62,22 +94,11 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev, · 5 unmodified lines
6294 case IIO_CHAN_INFO_RAW:
6395 mutex_lock(&indio_dev->mlock);
6496
65− reinit_completion(&info->completion);
66−
67− /* 8 clock periods as delay between power up and start cmd */
68− writel_relaxed(8, info->regs + SARADC_DLY_PU_SOC);
69−
70− /* Select the channel to be used and trigger conversion */
71− writel(SARADC_CTRL_POWER_CTRL
72− | (chan->channel & SARADC_CTRL_CHN_MASK)
73− | SARADC_CTRL_IRQ_ENABLE,
74− info->regs + SARADC_CTRL);
75−
76− if (!wait_for_completion_timeout(&info->completion,
77− SARADC_TIMEOUT)) {
78− writel_relaxed(0, info->regs + SARADC_CTRL);
97+ ret = rockchip_saradc_conversion(info, chan);
98+ if (ret) {
99+ rockchip_saradc_power_down(info);
79100 mutex_unlock(&indio_dev->mlock);
80− return -ETIMEDOUT;
101+ return ret;
81102 }
82103
83104 *val = info->last_val;
@@ -91,7 +112,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev, · 7 unmodified lines
91112 }
92113
93114 *val = ret / 1000;
94− *val2 = info->data->num_bits;
115+ *val2 = chan->scan_type.realbits;
95116 return IIO_VAL_FRACTIONAL_LOG2;
96117 default:
97118 return -EINVAL;
@@ -104,10 +125,9 @@ static irqreturn_t rockchip_saradc_isr(int irq, void *dev_id) · 6 unmodified lines
104125
105126 /* Read value */
106127 info->last_val = readl_relaxed(info->regs + SARADC_DATA);
107− info->last_val &= GENMASK(info->data->num_bits - 1, 0);
128+ info->last_val &= GENMASK(info->last_chan->scan_type.realbits - 1, 0);
108129
109− /* Clear irq & power down adc */
110− writel_relaxed(0, info->regs + SARADC_CTRL);
130+ rockchip_saradc_power_down(info);
111131
112132 complete(&info->completion);
113133
@@ -118,51 +138,55 @@ static const struct iio_info rockchip_saradc_iio_info = { · 4 unmodified lines
118138 .read_raw = rockchip_saradc_read_raw,
119139 };
120140
121−#define ADC_CHANNEL(_index, _id) { \
141+#define SARADC_CHANNEL(_index, _id, _res) { \
122142 .type = IIO_VOLTAGE, \
123143 .indexed = 1, \
124144 .channel = _index, \
125145 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
126146 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
127147 .datasheet_name = _id, \
148+ .scan_index = _index, \
149+ .scan_type = { \
150+ .sign = 'u', \
151+ .realbits = _res, \
152+ .storagebits = 16, \
153+ .endianness = IIO_CPU, \
154+ }, \
128155 }
129156
130157 static const struct iio_chan_spec rockchip_saradc_iio_channels[] = {
131− ADC_CHANNEL(0, "adc0"),
132− ADC_CHANNEL(1, "adc1"),
133− ADC_CHANNEL(2, "adc2"),
158+ SARADC_CHANNEL(0, "adc0", 10),
159+ SARADC_CHANNEL(1, "adc1", 10),
160+ SARADC_CHANNEL(2, "adc2", 10),
134161 };
135162
136163 static const struct rockchip_saradc_data saradc_data = {
137− .num_bits = 10,
138164 .channels = rockchip_saradc_iio_channels,
139165 .num_channels = ARRAY_SIZE(rockchip_saradc_iio_channels),
140166 .clk_rate = 1000000,
141167 };
142168
143169 static const struct iio_chan_spec rockchip_rk3066_tsadc_iio_channels[] = {
144− ADC_CHANNEL(0, "adc0"),
145− ADC_CHANNEL(1, "adc1"),
170+ SARADC_CHANNEL(0, "adc0", 12),
171+ SARADC_CHANNEL(1, "adc1", 12),
146172 };
147173
148174 static const struct rockchip_saradc_data rk3066_tsadc_data = {
149− .num_bits = 12,
150175 .channels = rockchip_rk3066_tsadc_iio_channels,
151176 .num_channels = ARRAY_SIZE(rockchip_rk3066_tsadc_iio_channels),
152177 .clk_rate = 50000,
153178 };
154179
155180 static const struct iio_chan_spec rockchip_rk3399_saradc_iio_channels[] = {
156− ADC_CHANNEL(0, "adc0"),
157− ADC_CHANNEL(1, "adc1"),
158− ADC_CHANNEL(2, "adc2"),
159− ADC_CHANNEL(3, "adc3"),
160− ADC_CHANNEL(4, "adc4"),
161− ADC_CHANNEL(5, "adc5"),
181+ SARADC_CHANNEL(0, "adc0", 10),
182+ SARADC_CHANNEL(1, "adc1", 10),
183+ SARADC_CHANNEL(2, "adc2", 10),
184+ SARADC_CHANNEL(3, "adc3", 10),
185+ SARADC_CHANNEL(4, "adc4", 10),
186+ SARADC_CHANNEL(5, "adc5", 10),
162187 };
163188
164189 static const struct rockchip_saradc_data rk3399_saradc_data = {
165− .num_bits = 10,
166190 .channels = rockchip_rk3399_saradc_iio_channels,
167191 .num_channels = ARRAY_SIZE(rockchip_rk3399_saradc_iio_channels),
168192 .clk_rate = 1000000,
@@ -193,6 +217,67 @@ static void rockchip_saradc_reset_controller(struct reset_control *reset) · 24 unmodified lines
193217 reset_control_deassert(reset);
194218 }
195219
220+static void rockchip_saradc_clk_disable(void *data)
221+{
222+ struct rockchip_saradc *info = data;
223+
224+ clk_disable_unprepare(info->clk);
225+}
226+
227+static void rockchip_saradc_pclk_disable(void *data)
228+{
229+ struct rockchip_saradc *info = data;
230+
231+ clk_disable_unprepare(info->pclk);
232+}
233+
234+static void rockchip_saradc_regulator_disable(void *data)
235+{
236+ struct rockchip_saradc *info = data;
237+
238+ regulator_disable(info->vref);
239+}
240+
241+static irqreturn_t rockchip_saradc_trigger_handler(int irq, void *p)
242+{
243+ struct iio_poll_func *pf = p;
244+ struct iio_dev *i_dev = pf->indio_dev;
245+ struct rockchip_saradc *info = iio_priv(i_dev);
246+ /*
247+ * @values: each channel takes an u16 value
248+ * @timestamp: will be 8-byte aligned automatically
249+ */
250+ struct {
251+ u16 values[SARADC_MAX_CHANNELS];
252+ int64_t timestamp;
253+ } data;
254+ int ret;
255+ int i, j = 0;
256+
257+ mutex_lock(&i_dev->mlock);
258+
259+ for_each_set_bit(i, i_dev->active_scan_mask, i_dev->masklength) {
260+ const struct iio_chan_spec *chan = &i_dev->channels[i];
261+
262+ ret = rockchip_saradc_conversion(info, chan);
263+ if (ret) {
264+ rockchip_saradc_power_down(info);
265+ goto out;
266+ }
267+
268+ data.values[j] = info->last_val;
269+ j++;
270+ }
271+
272+ iio_push_to_buffers_with_timestamp(i_dev, &data, iio_get_time_ns(i_dev));
273+out:
274+ mutex_unlock(&i_dev->mlock);
275+
276+ iio_trigger_notify_done(i_dev->trig);
277+
278+ return IRQ_HANDLED;
279+}
280+
196281 static int rockchip_saradc_probe(struct platform_device *pdev)
197282 {
198283 struct rockchip_saradc *info = NULL;
@@ -221,6 +306,12 @@ static int rockchip_saradc_probe(struct platform_device *pdev) · 22 unmodified lines
221306
222307 info->data = match->data;
223308
309+ /* Sanity check for possible later IP variants with more channels */
310+ if (info->data->num_channels > SARADC_MAX_CHANNELS) {
311+ dev_err(&pdev->dev, "max channels exceeded");
312+ return -EINVAL;
313+ }
314+
224315 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
225316 info->regs = devm_ioremap_resource(&pdev->dev, mem);
226317 if (IS_ERR(info->regs))
@@ -291,56 +382,55 @@ static int rockchip_saradc_probe(struct platform_device *pdev) · 64 unmodified lines
291382 dev_err(&pdev->dev, "failed to enable vref regulator\n");
292383 return ret;
293384 }
385+ ret = devm_add_action_or_reset(&pdev->dev,
386+ rockchip_saradc_regulator_disable, info);
387+ if (ret) {
388+ dev_err(&pdev->dev, "failed to register devm action, %d\n",
389+ ret);
390+ return ret;
391+ }
294392
295393 ret = clk_prepare_enable(info->pclk);
296394 if (ret < 0) {
297395 dev_err(&pdev->dev, "failed to enable pclk\n");
298− goto err_reg_voltage;
396+ return ret;
397+ }
398+ ret = devm_add_action_or_reset(&pdev->dev,
399+ rockchip_saradc_pclk_disable, info);
400+ if (ret) {
401+ dev_err(&pdev->dev, "failed to register devm action, %d\n",
402+ ret);
403+ return ret;
299404 }
300405
301406 ret = clk_prepare_enable(info->clk);
302407 if (ret < 0) {
303408 dev_err(&pdev->dev, "failed to enable converter clock\n");
304− goto err_pclk;
409+ return ret;
410+ }
411+ ret = devm_add_action_or_reset(&pdev->dev,
412+ rockchip_saradc_clk_disable, info);
413+ if (ret) {
414+ dev_err(&pdev->dev, "failed to register devm action, %d\n",
415+ ret);
416+ return ret;
305417 }
306418
307419 platform_set_drvdata(pdev, indio_dev);
308420
309421 indio_dev->name = dev_name(&pdev->dev);
310− indio_dev->dev.parent = &pdev->dev;
311− indio_dev->dev.of_node = pdev->dev.of_node;
312422 indio_dev->info = &rockchip_saradc_iio_info;
313423 indio_dev->modes = INDIO_DIRECT_MODE;
314424
315425 indio_dev->channels = info->data->channels;
316426 indio_dev->num_channels = info->data->num_channels;
317−
318− ret = iio_device_register(indio_dev);
427+ ret = devm_iio_triggered_buffer_setup(&indio_dev->dev, indio_dev, NULL,
428+ rockchip_saradc_trigger_handler,
429+ NULL);
319430 if (ret)
320− goto err_clk;
321−
322− return 0;
323−
324−err_clk:
325− clk_disable_unprepare(info->clk);
326−err_pclk:
327− clk_disable_unprepare(info->pclk);
328−err_reg_voltage:
329− regulator_disable(info->vref);
330− return ret;
331−}
332−
333−static int rockchip_saradc_remove(struct platform_device *pdev)
334−{
335− struct iio_dev *indio_dev = platform_get_drvdata(pdev);
336− struct rockchip_saradc *info = iio_priv(indio_dev);
337−
338− iio_device_unregister(indio_dev);
339− clk_disable_unprepare(info->clk);
340− clk_disable_unprepare(info->pclk);
341− regulator_disable(info->vref);
431+ return ret;
342432
343− return 0;
433+ return devm_iio_device_register(&pdev->dev, indio_dev);
344434 }
345435
346436 #ifdef CONFIG_PM_SLEEP
@@ -383,7 +473,6 @@ static SIMPLE_DEV_PM_OPS(rockchip_saradc_pm_ops, · 36 unmodified lines
383473
384474 static struct platform_driver rockchip_saradc_driver = {
385475 .probe = rockchip_saradc_probe,
386− .remove = rockchip_saradc_remove,
387476 .driver = {
388477 .name = "rockchip-saradc",
389478 .of_match_table = rockchip_saradc_match,
drivers/iio/adc/sc27xx_adc.c+0−1
@@ -533,7 +533,6 @@ static int sc27xx_adc_probe(struct platform_device *pdev) · 532 unmodified lines
533533 return ret;
534534 }
535535
536− indio_dev->dev.parent = dev;
537536 indio_dev->name = dev_name(dev);
538537 indio_dev->modes = INDIO_DIRECT_MODE;
539538 indio_dev->info = &sc27xx_info;
drivers/iio/adc/sd_adc_modulator.c+3−4
@@ -9,7 +9,8 @@ · 8 unmodified lines
99 #include <linux/iio/iio.h>
1010 #include <linux/iio/triggered_buffer.h>
1111 #include <linux/module.h>
12−#include <linux/of_device.h>
12+#include <linux/mod_devicetable.h>
13+#include <linux/platform_device.h>
1314
1415 static const struct iio_info iio_sd_mod_iio_info;
1516
@@ -32,8 +33,6 @@ static int iio_sd_mod_probe(struct platform_device *pdev) · 16 unmodified lines
3233 if (!iio)
3334 return -ENOMEM;
3435
35− iio->dev.parent = dev;
36− iio->dev.of_node = dev->of_node;
3736 iio->name = dev_name(dev);
3837 iio->info = &iio_sd_mod_iio_info;
3938 iio->modes = INDIO_BUFFER_HARDWARE;
@@ -56,7 +55,7 @@ MODULE_DEVICE_TABLE(of, sd_adc_of_match); · 16 unmodified lines
5655 static struct platform_driver iio_sd_mod_adc = {
5756 .driver = {
5857 .name = "iio_sd_adc_mod",
59− .of_match_table = of_match_ptr(sd_adc_of_match),
58+ .of_match_table = sd_adc_of_match,
6059 },
6160 .probe = iio_sd_mod_probe,
6261 };
drivers/iio/adc/spear_adc.c+0−1
@@ -336,7 +336,6 @@ static int spear_adc_probe(struct platform_device *pdev) · 335 unmodified lines
336336 init_completion(&st->completion);
337337
338338 indio_dev->name = SPEAR_ADC_MOD_NAME;
339− indio_dev->dev.parent = dev;
340339 indio_dev->info = &spear_adc_info;
341340 indio_dev->modes = INDIO_DIRECT_MODE;
342341 indio_dev->channels = spear_adc_iio_channels;
drivers/iio/adc/stm32-adc.c+68−87
@@ -162,10 +162,10 @@ struct stm32_adc_cfg { · 161 unmodified lines
162162 struct stm32_adc_trig_info *trigs;
163163 bool clk_required;
164164 bool has_vregready;
165− int (*prepare)(struct stm32_adc *);
166− void (*start_conv)(struct stm32_adc *, bool dma);
167− void (*stop_conv)(struct stm32_adc *);
168− void (*unprepare)(struct stm32_adc *);
165+ int (*prepare)(struct iio_dev *);
166+ void (*start_conv)(struct iio_dev *, bool dma);
167+ void (*stop_conv)(struct iio_dev *);
168+ void (*unprepare)(struct iio_dev *);
169169 const unsigned int *smp_cycles;
170170 };
171171
@@ -538,10 +538,11 @@ static void stm32_adc_set_res(struct stm32_adc *adc) · 366 unmodified lines
538538
539539 static int stm32_adc_hw_stop(struct device *dev)
540540 {
541− struct stm32_adc *adc = dev_get_drvdata(dev);
541+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
542+ struct stm32_adc *adc = iio_priv(indio_dev);
542543
543544 if (adc->cfg->unprepare)
544− adc->cfg->unprepare(adc);
545+ adc->cfg->unprepare(indio_dev);
545546
546547 if (adc->clk)
547548 clk_disable_unprepare(adc->clk);
@@ -551,7 +552,8 @@ static int stm32_adc_hw_stop(struct device *dev) · 3 unmodified lines
551552
552553 static int stm32_adc_hw_start(struct device *dev)
553554 {
554− struct stm32_adc *adc = dev_get_drvdata(dev);
555+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
556+ struct stm32_adc *adc = iio_priv(indio_dev);
555557 int ret;
556558
557559 if (adc->clk) {
@@ -563,7 +565,7 @@ static int stm32_adc_hw_start(struct device *dev) · 5 unmodified lines
563565 stm32_adc_set_res(adc);
564566
565567 if (adc->cfg->prepare) {
566− ret = adc->cfg->prepare(adc);
568+ ret = adc->cfg->prepare(indio_dev);
567569 if (ret)
568570 goto err_clk_dis;
569571 }
@@ -579,7 +581,7 @@ err_clk_dis: · 9 unmodified lines
579581
580582 /**
581583 * stm32f4_adc_start_conv() - Start conversions for regular channels.
582− * @adc: stm32 adc instance
584+ * @indio_dev: IIO device instance
583585 * @dma: use dma to transfer conversion result
584586 *
585587 * Start conversions for regular channels.
@@ -587,8 +589,10 @@ err_clk_dis: · 1 unmodified line
587589 * conversions, in IIO buffer modes. Otherwise, use ADC interrupt with direct
588590 * DR read instead (e.g. read_raw, or triggered buffer mode without DMA).
589591 */
590−static void stm32f4_adc_start_conv(struct stm32_adc *adc, bool dma)
592+static void stm32f4_adc_start_conv(struct iio_dev *indio_dev, bool dma)
591593 {
594+ struct stm32_adc *adc = iio_priv(indio_dev);
595+
592596 stm32_adc_set_bits(adc, STM32F4_ADC_CR1, STM32F4_SCAN);
593597
594598 if (dma)
@@ -605,8 +609,10 @@ static void stm32f4_adc_start_conv(struct stm32_adc *adc, bool dma) · 10 unmodified lines
605609 stm32_adc_set_bits(adc, STM32F4_ADC_CR2, STM32F4_SWSTART);
606610 }
607611
608−static void stm32f4_adc_stop_conv(struct stm32_adc *adc)
612+static void stm32f4_adc_stop_conv(struct iio_dev *indio_dev)
609613 {
614+ struct stm32_adc *adc = iio_priv(indio_dev);
615+
610616 stm32_adc_clr_bits(adc, STM32F4_ADC_CR2, STM32F4_EXTEN_MASK);
611617 stm32_adc_clr_bits(adc, STM32F4_ADC_SR, STM32F4_STRT);
612618
@@ -615,8 +621,9 @@ static void stm32f4_adc_stop_conv(struct stm32_adc *adc) · 2 unmodified lines
615621 STM32F4_ADON | STM32F4_DMA | STM32F4_DDS);
616622 }
617623
618−static void stm32h7_adc_start_conv(struct stm32_adc *adc, bool dma)
624+static void stm32h7_adc_start_conv(struct iio_dev *indio_dev, bool dma)
619625 {
626+ struct stm32_adc *adc = iio_priv(indio_dev);
620627 enum stm32h7_adc_dmngt dmngt;
621628 unsigned long flags;
622629 u32 val;
@@ -635,9 +642,9 @@ static void stm32h7_adc_start_conv(struct stm32_adc *adc, bool dma) · 12 unmodified lines
635642 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADSTART);
636643 }
637644
638−static void stm32h7_adc_stop_conv(struct stm32_adc *adc)
645+static void stm32h7_adc_stop_conv(struct iio_dev *indio_dev)
639646 {
640− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
647+ struct stm32_adc *adc = iio_priv(indio_dev);
641648 int ret;
642649 u32 val;
643650
@@ -652,9 +659,9 @@ static void stm32h7_adc_stop_conv(struct stm32_adc *adc) · 8 unmodified lines
652659 stm32_adc_clr_bits(adc, STM32H7_ADC_CFGR, STM32H7_DMNGT_MASK);
653660 }
654661
655−static int stm32h7_adc_exit_pwr_down(struct stm32_adc *adc)
662+static int stm32h7_adc_exit_pwr_down(struct iio_dev *indio_dev)
656663 {
657− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
664+ struct stm32_adc *adc = iio_priv(indio_dev);
658665 int ret;
659666 u32 val;
660667
@@ -690,9 +697,9 @@ static void stm32h7_adc_enter_pwr_down(struct stm32_adc *adc) · 29 unmodified lines
690697 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_DEEPPWD);
691698 }
692699
693−static int stm32h7_adc_enable(struct stm32_adc *adc)
700+static int stm32h7_adc_enable(struct iio_dev *indio_dev)
694701 {
695− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
702+ struct stm32_adc *adc = iio_priv(indio_dev);
696703 int ret;
697704 u32 val;
698705
@@ -713,9 +720,9 @@ static int stm32h7_adc_enable(struct stm32_adc *adc) · 14 unmodified lines
713720 return ret;
714721 }
715722
716−static void stm32h7_adc_disable(struct stm32_adc *adc)
723+static void stm32h7_adc_disable(struct iio_dev *indio_dev)
717724 {
718− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
725+ struct stm32_adc *adc = iio_priv(indio_dev);
719726 int ret;
720727 u32 val;
721728
@@ -730,12 +737,12 @@ static void stm32h7_adc_disable(struct stm32_adc *adc) · 8 unmodified lines
730737
731738 /**
732739 * stm32h7_adc_read_selfcalib() - read calibration shadow regs, save result
733− * @adc: stm32 adc instance
740+ * @indio_dev: IIO device instance
734741 * Note: Must be called once ADC is enabled, so LINCALRDYW[1..6] are writable
735742 */
736−static int stm32h7_adc_read_selfcalib(struct stm32_adc *adc)
743+static int stm32h7_adc_read_selfcalib(struct iio_dev *indio_dev)
737744 {
738− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
745+ struct stm32_adc *adc = iio_priv(indio_dev);
739746 int i, ret;
740747 u32 lincalrdyw_mask, val;
741748
@@ -774,12 +781,12 @@ static int stm32h7_adc_read_selfcalib(struct stm32_adc *adc) · 32 unmodified lines
774781
775782 /**
776783 * stm32h7_adc_restore_selfcalib() - Restore saved self-calibration result
777− * @adc: stm32 adc instance
784+ * @indio_dev: IIO device instance
778785 * Note: ADC must be enabled, with no on-going conversions.
779786 */
780−static int stm32h7_adc_restore_selfcalib(struct stm32_adc *adc)
787+static int stm32h7_adc_restore_selfcalib(struct iio_dev *indio_dev)
781788 {
782− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
789+ struct stm32_adc *adc = iio_priv(indio_dev);
783790 int i, ret;
784791 u32 lincalrdyw_mask, val;
785792
@@ -847,12 +854,12 @@ static int stm32h7_adc_restore_selfcalib(struct stm32_adc *adc) · 61 unmodified lines
847854
848855 /**
849856 * stm32h7_adc_selfcalib() - Procedure to calibrate ADC
850− * @adc: stm32 adc instance
857+ * @indio_dev: IIO device instance
851858 * Note: Must be called once ADC is out of power down.
852859 */
853−static int stm32h7_adc_selfcalib(struct stm32_adc *adc)
860+static int stm32h7_adc_selfcalib(struct iio_dev *indio_dev)
854861 {
855− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
862+ struct stm32_adc *adc = iio_priv(indio_dev);
856863 int ret;
857864 u32 val;
858865
@@ -903,7 +910,7 @@ out: · 44 unmodified lines
903910
904911 /**
905912 * stm32h7_adc_prepare() - Leave power down mode to enable ADC.
906− * @adc: stm32 adc instance
913+ * @indio_dev: IIO device instance
907914 * Leave power down mode.
908915 * Configure channels as single ended or differential before enabling ADC.
909916 * Enable ADC.
@@ -912,30 +919,31 @@ out: · 2 unmodified lines
912919 * - Only one input is selected for single ended (e.g. 'vinp')
913920 * - Two inputs are selected for differential channels (e.g. 'vinp' & 'vinn')
914921 */
915−static int stm32h7_adc_prepare(struct stm32_adc *adc)
922+static int stm32h7_adc_prepare(struct iio_dev *indio_dev)
916923 {
924+ struct stm32_adc *adc = iio_priv(indio_dev);
917925 int calib, ret;
918926
919− ret = stm32h7_adc_exit_pwr_down(adc);
927+ ret = stm32h7_adc_exit_pwr_down(indio_dev);
920928 if (ret)
921929 return ret;
922930
923− ret = stm32h7_adc_selfcalib(adc);
931+ ret = stm32h7_adc_selfcalib(indio_dev);
924932 if (ret < 0)
925933 goto pwr_dwn;
926934 calib = ret;
927935
928936 stm32_adc_writel(adc, STM32H7_ADC_DIFSEL, adc->difsel);
929937
930− ret = stm32h7_adc_enable(adc);
938+ ret = stm32h7_adc_enable(indio_dev);
931939 if (ret)
932940 goto pwr_dwn;
933941
934942 /* Either restore or read calibration result for future reference */
935943 if (calib)
936− ret = stm32h7_adc_restore_selfcalib(adc);
944+ ret = stm32h7_adc_restore_selfcalib(indio_dev);
937945 else
938− ret = stm32h7_adc_read_selfcalib(adc);
946+ ret = stm32h7_adc_read_selfcalib(indio_dev);
939947 if (ret)
940948 goto disable;
941949
@@ -944,16 +952,18 @@ static int stm32h7_adc_prepare(struct stm32_adc *adc) · 2 unmodified lines
944952 return 0;
945953
946954 disable:
947− stm32h7_adc_disable(adc);
955+ stm32h7_adc_disable(indio_dev);
948956 pwr_dwn:
949957 stm32h7_adc_enter_pwr_down(adc);
950958
951959 return ret;
952960 }
953961
954−static void stm32h7_adc_unprepare(struct stm32_adc *adc)
962+static void stm32h7_adc_unprepare(struct iio_dev *indio_dev)
955963 {
956− stm32h7_adc_disable(adc);
964+ struct stm32_adc *adc = iio_priv(indio_dev);
965+
966+ stm32h7_adc_disable(indio_dev);
957967 stm32h7_adc_enter_pwr_down(adc);
958968 }
959969
@@ -1160,7 +1170,7 @@ static int stm32_adc_single_conv(struct iio_dev *indio_dev, · 200 unmodified lines
11601170
11611171 stm32_adc_conv_irq_enable(adc);
11621172
1163− adc->cfg->start_conv(adc, false);
1173+ adc->cfg->start_conv(indio_dev, false);
11641174
11651175 timeout = wait_for_completion_interruptible_timeout(
11661176 &adc->completion, STM32_ADC_TIMEOUT);
@@ -1173,7 +1183,7 @@ static int stm32_adc_single_conv(struct iio_dev *indio_dev, · 6 unmodified lines
11731183 ret = IIO_VAL_INT;
11741184 }
11751185
1176− adc->cfg->stop_conv(adc);
1186+ adc->cfg->stop_conv(indio_dev);
11771187
11781188 stm32_adc_conv_irq_disable(adc);
11791189
@@ -1227,8 +1237,8 @@ static int stm32_adc_read_raw(struct iio_dev *indio_dev, · 47 unmodified lines
12271237
12281238 static irqreturn_t stm32_adc_threaded_isr(int irq, void *data)
12291239 {
1230− struct stm32_adc *adc = data;
1231− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
1240+ struct iio_dev *indio_dev = data;
1241+ struct stm32_adc *adc = iio_priv(indio_dev);
12321242 const struct stm32_adc_regspec *regs = adc->cfg->regs;
12331243 u32 status = stm32_adc_readl(adc, regs->isr_eoc.reg);
12341244
@@ -1240,8 +1250,8 @@ static irqreturn_t stm32_adc_threaded_isr(int irq, void *data) · 5 unmodified lines
12401250
12411251 static irqreturn_t stm32_adc_isr(int irq, void *data)
12421252 {
1243− struct stm32_adc *adc = data;
1244− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
1253+ struct iio_dev *indio_dev = data;
1254+ struct stm32_adc *adc = iio_priv(indio_dev);
12451255 const struct stm32_adc_regspec *regs = adc->cfg->regs;
12461256 u32 status = stm32_adc_readl(adc, regs->isr_eoc.reg);
12471257
@@ -1482,7 +1492,7 @@ static int stm32_adc_dma_start(struct iio_dev *indio_dev) · 234 unmodified lines
14821492 return 0;
14831493 }
14841494
1485−static int __stm32_adc_buffer_postenable(struct iio_dev *indio_dev)
1495+static int stm32_adc_buffer_postenable(struct iio_dev *indio_dev)
14861496 {
14871497 struct stm32_adc *adc = iio_priv(indio_dev);
14881498 struct device *dev = indio_dev->dev.parent;
@@ -1514,7 +1524,7 @@ static int __stm32_adc_buffer_postenable(struct iio_dev *indio_dev) · 25 unmodified lines
15141524 if (!adc->dma_chan)
15151525 stm32_adc_conv_irq_enable(adc);
15161526
1517− adc->cfg->start_conv(adc, !!adc->dma_chan);
1527+ adc->cfg->start_conv(indio_dev, !!adc->dma_chan);
15181528
15191529 return 0;
15201530
@@ -1527,27 +1537,12 @@ err_pm_put: · 6 unmodified lines
15271537 return ret;
15281538 }
15291539
1530−static int stm32_adc_buffer_postenable(struct iio_dev *indio_dev)
1531−{
1532− int ret;
1533−
1534− ret = iio_triggered_buffer_postenable(indio_dev);
1535− if (ret < 0)
1536− return ret;
1537−
1538− ret = __stm32_adc_buffer_postenable(indio_dev);
1539− if (ret < 0)
1540− iio_triggered_buffer_predisable(indio_dev);
1541−
1542− return ret;
1543−}
1544−
1545−static void __stm32_adc_buffer_predisable(struct iio_dev *indio_dev)
1540+static int stm32_adc_buffer_predisable(struct iio_dev *indio_dev)
15461541 {
15471542 struct stm32_adc *adc = iio_priv(indio_dev);
15481543 struct device *dev = indio_dev->dev.parent;
15491544
1550− adc->cfg->stop_conv(adc);
1545+ adc->cfg->stop_conv(indio_dev);
15511546 if (!adc->dma_chan)
15521547 stm32_adc_conv_irq_disable(adc);
15531548
@@ -1561,19 +1556,8 @@ static void __stm32_adc_buffer_predisable(struct iio_dev *indio_dev) · 7 unmodified lines
15611556
15621557 pm_runtime_mark_last_busy(dev);
15631558 pm_runtime_put_autosuspend(dev);
1564−}
1565−
1566−static int stm32_adc_buffer_predisable(struct iio_dev *indio_dev)
1567−{
1568− int ret;
15691559
1570− __stm32_adc_buffer_predisable(indio_dev);
1571−
1572− ret = iio_triggered_buffer_predisable(indio_dev);
1573− if (ret < 0)
1574− dev_err(&indio_dev->dev, "predisable failed\n");
1575−
1576− return ret;
1560+ return 0;
15771561 }
15781562
15791563 static const struct iio_buffer_setup_ops stm32_adc_buffer_setup_ops = {
@@ -1886,12 +1870,11 @@ static int stm32_adc_probe(struct platform_device *pdev) · 306 unmodified lines
18861870 of_match_device(dev->driver->of_match_table, dev)->data;
18871871
18881872 indio_dev->name = dev_name(&pdev->dev);
1889− indio_dev->dev.parent = &pdev->dev;
18901873 indio_dev->dev.of_node = pdev->dev.of_node;
18911874 indio_dev->info = &stm32_adc_iio_info;
18921875 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_HARDWARE_TRIGGERED;
18931876
1894− platform_set_drvdata(pdev, adc);
1877+ platform_set_drvdata(pdev, indio_dev);
18951878
18961879 ret = of_property_read_u32(pdev->dev.of_node, "reg", &adc->offset);
18971880 if (ret != 0) {
@@ -1905,7 +1888,7 @@ static int stm32_adc_probe(struct platform_device *pdev) · 7 unmodified lines
19051888
19061889 ret = devm_request_threaded_irq(&pdev->dev, adc->irq, stm32_adc_isr,
19071890 stm32_adc_threaded_isr,
1908− 0, pdev->name, adc);
1891+ 0, pdev->name, indio_dev);
19091892 if (ret) {
19101893 dev_err(&pdev->dev, "failed to request IRQ\n");
19111894 return ret;
@@ -1989,8 +1972,8 @@ err_dma_disable: · 77 unmodified lines
19891972
19901973 static int stm32_adc_remove(struct platform_device *pdev)
19911974 {
1992− struct stm32_adc *adc = platform_get_drvdata(pdev);
1993− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
1975+ struct iio_dev *indio_dev = platform_get_drvdata(pdev);
1976+ struct stm32_adc *adc = iio_priv(indio_dev);
19941977
19951978 pm_runtime_get_sync(&pdev->dev);
19961979 iio_device_unregister(indio_dev);
@@ -2012,19 +1995,17 @@ static int stm32_adc_remove(struct platform_device *pdev) · 15 unmodified lines
20121995 #if defined(CONFIG_PM_SLEEP)
20131996 static int stm32_adc_suspend(struct device *dev)
20141997 {
2015− struct stm32_adc *adc = dev_get_drvdata(dev);
2016− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
1998+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
20171999
20182000 if (iio_buffer_enabled(indio_dev))
2019− __stm32_adc_buffer_predisable(indio_dev);
2001+ stm32_adc_buffer_predisable(indio_dev);
20202002
20212003 return pm_runtime_force_suspend(dev);
20222004 }
20232005
20242006 static int stm32_adc_resume(struct device *dev)
20252007 {
2026− struct stm32_adc *adc = dev_get_drvdata(dev);
2027− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
2008+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
20282009 int ret;
20292010
20302011 ret = pm_runtime_force_resume(dev);
@@ -2039,7 +2020,7 @@ static int stm32_adc_resume(struct device *dev) · 8 unmodified lines
20392020 if (ret < 0)
20402021 return ret;
20412022
2042− return __stm32_adc_buffer_postenable(indio_dev);
2023+ return stm32_adc_buffer_postenable(indio_dev);
20432024 }
20442025 #endif
20452026
drivers/iio/adc/stm32-dfsdm-adc.c+37−68
@@ -330,9 +330,9 @@ static int stm32_dfsdm_compute_all_osrs(struct iio_dev *indio_dev, · 329 unmodified lines
330330 return 0;
331331 }
332332
333−static int stm32_dfsdm_start_channel(struct stm32_dfsdm_adc *adc)
333+static int stm32_dfsdm_start_channel(struct iio_dev *indio_dev)
334334 {
335− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
335+ struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
336336 struct regmap *regmap = adc->dfsdm->regmap;
337337 const struct iio_chan_spec *chan;
338338 unsigned int bit;
@@ -350,9 +350,9 @@ static int stm32_dfsdm_start_channel(struct stm32_dfsdm_adc *adc) · 11 unmodified lines
350350 return 0;
351351 }
352352
353−static void stm32_dfsdm_stop_channel(struct stm32_dfsdm_adc *adc)
353+static void stm32_dfsdm_stop_channel(struct iio_dev *indio_dev)
354354 {
355− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
355+ struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
356356 struct regmap *regmap = adc->dfsdm->regmap;
357357 const struct iio_chan_spec *chan;
358358 unsigned int bit;
@@ -418,11 +418,11 @@ static void stm32_dfsdm_stop_filter(struct stm32_dfsdm *dfsdm, · 59 unmodified lines
418418 DFSDM_CR1_DFEN_MASK, DFSDM_CR1_DFEN(0));
419419 }
420420
421−static int stm32_dfsdm_filter_set_trig(struct stm32_dfsdm_adc *adc,
421+static int stm32_dfsdm_filter_set_trig(struct iio_dev *indio_dev,
422422 unsigned int fl_id,
423423 struct iio_trigger *trig)
424424 {
425− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
425+ struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
426426 struct regmap *regmap = adc->dfsdm->regmap;
427427 u32 jextsel = 0, jexten = STM32_DFSDM_JEXTEN_DISABLED;
428428 int ret;
@@ -447,11 +447,11 @@ static int stm32_dfsdm_filter_set_trig(struct stm32_dfsdm_adc *adc, · 18 unmodified lines
447447 return 0;
448448 }
449449
450−static int stm32_dfsdm_channels_configure(struct stm32_dfsdm_adc *adc,
450+static int stm32_dfsdm_channels_configure(struct iio_dev *indio_dev,
451451 unsigned int fl_id,
452452 struct iio_trigger *trig)
453453 {
454− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
454+ struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
455455 struct regmap *regmap = adc->dfsdm->regmap;
456456 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[fl_id];
457457 struct stm32_dfsdm_filter_osr *flo = &fl->flo[0];
@@ -491,11 +491,11 @@ static int stm32_dfsdm_channels_configure(struct stm32_dfsdm_adc *adc, · 33 unmodified lines
491491 return 0;
492492 }
493493
494−static int stm32_dfsdm_filter_configure(struct stm32_dfsdm_adc *adc,
494+static int stm32_dfsdm_filter_configure(struct iio_dev *indio_dev,
495495 unsigned int fl_id,
496496 struct iio_trigger *trig)
497497 {
498− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
498+ struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
499499 struct regmap *regmap = adc->dfsdm->regmap;
500500 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[fl_id];
501501 struct stm32_dfsdm_filter_osr *flo = &fl->flo[fl->fast];
@@ -521,7 +521,7 @@ static int stm32_dfsdm_filter_configure(struct stm32_dfsdm_adc *adc, · 19 unmodified lines
521521 if (ret)
522522 return ret;
523523
524− ret = stm32_dfsdm_filter_set_trig(adc, fl_id, trig);
524+ ret = stm32_dfsdm_filter_set_trig(indio_dev, fl_id, trig);
525525 if (ret)
526526 return ret;
527527
@@ -729,21 +729,22 @@ static ssize_t dfsdm_adc_audio_set_spiclk(struct iio_dev *indio_dev, · 201 unmodified lines
729729 return len;
730730 }
731731
732−static int stm32_dfsdm_start_conv(struct stm32_dfsdm_adc *adc,
732+static int stm32_dfsdm_start_conv(struct iio_dev *indio_dev,
733733 struct iio_trigger *trig)
734734 {
735+ struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
735736 struct regmap *regmap = adc->dfsdm->regmap;
736737 int ret;
737738
738− ret = stm32_dfsdm_channels_configure(adc, adc->fl_id, trig);
739+ ret = stm32_dfsdm_channels_configure(indio_dev, adc->fl_id, trig);
739740 if (ret < 0)
740741 return ret;
741742
742− ret = stm32_dfsdm_start_channel(adc);
743+ ret = stm32_dfsdm_start_channel(indio_dev);
743744 if (ret < 0)
744745 return ret;
745746
746− ret = stm32_dfsdm_filter_configure(adc, adc->fl_id, trig);
747+ ret = stm32_dfsdm_filter_configure(indio_dev, adc->fl_id, trig);
747748 if (ret < 0)
748749 goto stop_channels;
749750
@@ -757,13 +758,14 @@ filter_unconfigure: · 7 unmodified lines
757758 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),
758759 DFSDM_CR1_CFG_MASK, 0);
759760 stop_channels:
760− stm32_dfsdm_stop_channel(adc);
761+ stm32_dfsdm_stop_channel(indio_dev);
761762
762763 return ret;
763764 }
764765
765−static void stm32_dfsdm_stop_conv(struct stm32_dfsdm_adc *adc)
766+static void stm32_dfsdm_stop_conv(struct iio_dev *indio_dev)
766767 {
768+ struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
767769 struct regmap *regmap = adc->dfsdm->regmap;
768770
769771 stm32_dfsdm_stop_filter(adc->dfsdm, adc->fl_id);
@@ -771,7 +773,7 @@ static void stm32_dfsdm_stop_conv(struct stm32_dfsdm_adc *adc) · 1 unmodified line
771773 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),
772774 DFSDM_CR1_CFG_MASK, 0);
773775
774− stm32_dfsdm_stop_channel(adc);
776+ stm32_dfsdm_stop_channel(indio_dev);
775777 }
776778
777779 static int stm32_dfsdm_set_watermark(struct iio_dev *indio_dev,
@@ -993,7 +995,7 @@ static int stm32_dfsdm_update_scan_mode(struct iio_dev *indio_dev, · 215 unmodified lines
993995 return 0;
994996 }
995997
996−static int __stm32_dfsdm_postenable(struct iio_dev *indio_dev)
998+static int stm32_dfsdm_postenable(struct iio_dev *indio_dev)
997999 {
9981000 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
9991001 int ret;
@@ -1017,7 +1019,7 @@ static int __stm32_dfsdm_postenable(struct iio_dev *indio_dev) · 17 unmodified lines
10171019 goto stop_dfsdm;
10181020 }
10191021
1020− ret = stm32_dfsdm_start_conv(adc, indio_dev->trig);
1022+ ret = stm32_dfsdm_start_conv(indio_dev, indio_dev->trig);
10211023 if (ret) {
10221024 dev_err(&indio_dev->dev, "Can't start conversion\n");
10231025 goto err_stop_dma;
@@ -1036,34 +1038,11 @@ err_stop_hwc: · 12 unmodified lines
10361038 return ret;
10371039 }
10381040
1039−static int stm32_dfsdm_postenable(struct iio_dev *indio_dev)
1040−{
1041− int ret;
1042−
1043− if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
1044− ret = iio_triggered_buffer_postenable(indio_dev);
1045− if (ret < 0)
1046− return ret;
1047− }
1048−
1049− ret = __stm32_dfsdm_postenable(indio_dev);
1050− if (ret < 0)
1051− goto err_predisable;
1052−
1053− return 0;
1054−
1055−err_predisable:
1056− if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1057− iio_triggered_buffer_predisable(indio_dev);
1058−
1059− return ret;
1060−}
1061−
1062−static void __stm32_dfsdm_predisable(struct iio_dev *indio_dev)
1041+static int stm32_dfsdm_predisable(struct iio_dev *indio_dev)
10631042 {
10641043 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
10651044
1066− stm32_dfsdm_stop_conv(adc);
1045+ stm32_dfsdm_stop_conv(indio_dev);
10671046
10681047 stm32_dfsdm_adc_dma_stop(indio_dev);
10691048
@@ -1071,14 +1050,6 @@ static void __stm32_dfsdm_predisable(struct iio_dev *indio_dev) · 1 unmodified line
10711050
10721051 if (adc->hwc)
10731052 iio_hw_consumer_disable(adc->hwc);
1074−}
1075−
1076−static int stm32_dfsdm_predisable(struct iio_dev *indio_dev)
1077−{
1078− __stm32_dfsdm_predisable(indio_dev);
1079−
1080− if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1081− iio_triggered_buffer_predisable(indio_dev);
10821053
10831054 return 0;
10841055 }
@@ -1159,7 +1130,7 @@ static int stm32_dfsdm_single_conv(struct iio_dev *indio_dev, · 74 unmodified lines
11591130
11601131 adc->nconv = 1;
11611132 adc->smask = BIT(chan->scan_index);
1162− ret = stm32_dfsdm_start_conv(adc, NULL);
1133+ ret = stm32_dfsdm_start_conv(indio_dev, NULL);
11631134 if (ret < 0) {
11641135 regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id),
11651136 DFSDM_CR2_REOCIE_MASK, DFSDM_CR2_REOCIE(0));
@@ -1180,7 +1151,7 @@ static int stm32_dfsdm_single_conv(struct iio_dev *indio_dev, · 14 unmodified lines
11801151 else
11811152 ret = IIO_VAL_INT;
11821153
1183− stm32_dfsdm_stop_conv(adc);
1154+ stm32_dfsdm_stop_conv(indio_dev);
11841155
11851156 stm32_dfsdm_process_data(adc, res);
11861157
@@ -1313,8 +1284,8 @@ static const struct iio_info stm32_dfsdm_info_adc = { · 126 unmodified lines
13131284
13141285 static irqreturn_t stm32_dfsdm_irq(int irq, void *arg)
13151286 {
1316− struct stm32_dfsdm_adc *adc = arg;
1317− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
1287+ struct iio_dev *indio_dev = arg;
1288+ struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
13181289 struct regmap *regmap = adc->dfsdm->regmap;
13191290 unsigned int status, int_en;
13201291
@@ -1571,11 +1542,10 @@ static int stm32_dfsdm_adc_probe(struct platform_device *pdev) · 250 unmodified lines
15711542 adc = iio_priv(iio);
15721543 adc->dfsdm = dev_get_drvdata(dev->parent);
15731544
1574− iio->dev.parent = dev;
15751545 iio->dev.of_node = np;
15761546 iio->modes = INDIO_DIRECT_MODE;
15771547
1578− platform_set_drvdata(pdev, adc);
1548+ platform_set_drvdata(pdev, iio);
15791549
15801550 ret = of_property_read_u32(dev->of_node, "reg", &adc->fl_id);
15811551 if (ret != 0 || adc->fl_id >= adc->dfsdm->num_fls) {
@@ -1604,7 +1574,7 @@ static int stm32_dfsdm_adc_probe(struct platform_device *pdev) · 22 unmodified lines
16041574 return irq;
16051575
16061576 ret = devm_request_irq(dev, irq, stm32_dfsdm_irq,
1607− 0, pdev->name, adc);
1577+ 0, pdev->name, iio);
16081578 if (ret < 0) {
16091579 dev_err(dev, "Failed to request IRQ\n");
16101580 return ret;
@@ -1651,8 +1621,8 @@ err_cleanup: · 40 unmodified lines
16511621
16521622 static int stm32_dfsdm_adc_remove(struct platform_device *pdev)
16531623 {
1654− struct stm32_dfsdm_adc *adc = platform_get_drvdata(pdev);
1655− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
1624+ struct iio_dev *indio_dev = platform_get_drvdata(pdev);
1625+ struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
16561626
16571627 if (adc->dev_data->type == DFSDM_AUDIO)
16581628 of_platform_depopulate(&pdev->dev);
@@ -1664,19 +1634,18 @@ static int stm32_dfsdm_adc_remove(struct platform_device *pdev) · 5 unmodified lines
16641634
16651635 static int __maybe_unused stm32_dfsdm_adc_suspend(struct device *dev)
16661636 {
1667− struct stm32_dfsdm_adc *adc = dev_get_drvdata(dev);
1668− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
1637+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
16691638
16701639 if (iio_buffer_enabled(indio_dev))
1671− __stm32_dfsdm_predisable(indio_dev);
1640+ stm32_dfsdm_predisable(indio_dev);
16721641
16731642 return 0;
16741643 }
16751644
16761645 static int __maybe_unused stm32_dfsdm_adc_resume(struct device *dev)
16771646 {
1678− struct stm32_dfsdm_adc *adc = dev_get_drvdata(dev);
1679− struct iio_dev *indio_dev = iio_priv_to_dev(adc);
1647+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
1648+ struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
16801649 const struct iio_chan_spec *chan;
16811650 struct stm32_dfsdm_channel *ch;
16821651 int i, ret;
@@ -1691,7 +1660,7 @@ static int __maybe_unused stm32_dfsdm_adc_resume(struct device *dev) · 8 unmodified lines
16911660 }
16921661
16931662 if (iio_buffer_enabled(indio_dev))
1694− __stm32_dfsdm_postenable(indio_dev);
1663+ stm32_dfsdm_postenable(indio_dev);
16951664
16961665 return 0;
16971666 }
drivers/iio/adc/stmpe-adc.c+0−1
@@ -297,7 +297,6 @@ static int stmpe_adc_probe(struct platform_device *pdev) · 296 unmodified lines
297297 platform_set_drvdata(pdev, indio_dev);
298298
299299 indio_dev->name = dev_name(&pdev->dev);
300− indio_dev->dev.parent = &pdev->dev;
301300 indio_dev->info = &stmpe_adc_iio_info;
302301 indio_dev->modes = INDIO_DIRECT_MODE;
303302
drivers/iio/adc/stx104.c+0−1
@@ -319,7 +319,6 @@ static int stx104_probe(struct device *dev, unsigned int id) · 318 unmodified lines
319319 }
320320
321321 indio_dev->name = dev_name(dev);
322− indio_dev->dev.parent = dev;
323322
324323 priv = iio_priv(indio_dev);
325324 priv->base = base[id];
drivers/iio/adc/sun4i-gpadc-iio.c+0−2
@@ -619,8 +619,6 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) · 618 unmodified lines
619619 info->indio_dev = indio_dev;
620620 init_completion(&info->completion);
621621 indio_dev->name = dev_name(&pdev->dev);
622− indio_dev->dev.parent = &pdev->dev;
623− indio_dev->dev.of_node = pdev->dev.of_node;
624622 indio_dev->info = &sun4i_gpadc_iio_info;
625623 indio_dev->modes = INDIO_DIRECT_MODE;
626624
drivers/iio/adc/ti-adc081c.c+5−9
@@ -6,9 +6,9 @@ · 5 unmodified lines
66 * Copyright (C) 2016 Intel
77 *
88 * Datasheets:
9− * http://www.ti.com/lit/ds/symlink/adc081c021.pdf
10− * http://www.ti.com/lit/ds/symlink/adc101c021.pdf
11− * http://www.ti.com/lit/ds/symlink/adc121c021.pdf
9+ * https://www.ti.com/lit/ds/symlink/adc081c021.pdf
10+ * https://www.ti.com/lit/ds/symlink/adc101c021.pdf
11+ * https://www.ti.com/lit/ds/symlink/adc121c021.pdf
1212 *
1313 * The devices have a very similar interface and differ mostly in the number of
1414 * bits handled. For the 8-bit and 10-bit models the least-significant 4 or 2
@@ -18,7 +18,7 @@ · 3 unmodified lines
1818 #include <linux/err.h>
1919 #include <linux/i2c.h>
2020 #include <linux/module.h>
21−#include <linux/of.h>
21+#include <linux/mod_devicetable.h>
2222 #include <linux/acpi.h>
2323
2424 #include <linux/iio/iio.h>
@@ -181,8 +181,6 @@ static int adc081c_probe(struct i2c_client *client, · 156 unmodified lines
181181 if (err < 0)
182182 return err;
183183
184− iio->dev.parent = &client->dev;
185− iio->dev.of_node = client->dev.of_node;
186184 iio->name = dev_name(&client->dev);
187185 iio->modes = INDIO_DIRECT_MODE;
188186 iio->info = &adc081c_info;
@@ -232,7 +230,6 @@ static const struct i2c_device_id adc081c_id[] = { · 43 unmodified lines
232230 };
233231 MODULE_DEVICE_TABLE(i2c, adc081c_id);
234232
235−#ifdef CONFIG_OF
236233 static const struct of_device_id adc081c_of_match[] = {
237234 { .compatible = "ti,adc081c" },
238235 { .compatible = "ti,adc101c" },
@@ -240,7 +237,6 @@ static const struct of_device_id adc081c_of_match[] = { · 1 unmodified line
240237 { }
241238 };
242239 MODULE_DEVICE_TABLE(of, adc081c_of_match);
243−#endif
244240
245241 #ifdef CONFIG_ACPI
246242 static const struct acpi_device_id adc081c_acpi_match[] = {
@@ -255,7 +251,7 @@ MODULE_DEVICE_TABLE(acpi, adc081c_acpi_match); · 8 unmodified lines
255251 static struct i2c_driver adc081c_driver = {
256252 .driver = {
257253 .name = "adc081c",
258− .of_match_table = of_match_ptr(adc081c_of_match),
254+ .of_match_table = adc081c_of_match,
259255 .acpi_match_table = ACPI_PTR(adc081c_acpi_match),
260256 },
261257 .probe = adc081c_probe,
drivers/iio/adc/ti-adc0832.c+3−8
@@ -4,10 +4,11 @@ · 3 unmodified lines
44 *
55 * Copyright (c) 2016 Akinobu Mita <akinobu.mita@gmail.com>
66 *
7− * Datasheet: http://www.ti.com/lit/ds/symlink/adc0832-n.pdf
7+ * Datasheet: https://www.ti.com/lit/ds/symlink/adc0832-n.pdf
88 */
99
1010 #include <linux/module.h>
11+#include <linux/mod_devicetable.h>
1112 #include <linux/spi/spi.h>
1213 #include <linux/iio/iio.h>
1314 #include <linux/regulator/consumer.h>
@@ -245,8 +246,6 @@ static int adc0832_probe(struct spi_device *spi) · 231 unmodified lines
245246 mutex_init(&adc->lock);
246247
247248 indio_dev->name = spi_get_device_id(spi)->name;
248− indio_dev->dev.parent = &spi->dev;
249− indio_dev->dev.of_node = spi->dev.of_node;
250249 indio_dev->info = &adc0832_info;
251250 indio_dev->modes = INDIO_DIRECT_MODE;
252251
@@ -315,8 +314,6 @@ static int adc0832_remove(struct spi_device *spi) · 62 unmodified lines
315314 return 0;
316315 }
317316
318−#ifdef CONFIG_OF
319−
320317 static const struct of_device_id adc0832_dt_ids[] = {
321318 { .compatible = "ti,adc0831", },
322319 { .compatible = "ti,adc0832", },
@@ -326,8 +323,6 @@ static const struct of_device_id adc0832_dt_ids[] = { · 3 unmodified lines
326323 };
327324 MODULE_DEVICE_TABLE(of, adc0832_dt_ids);
328325
329−#endif
330−
331326 static const struct spi_device_id adc0832_id[] = {
332327 { "adc0831", adc0831 },
333328 { "adc0832", adc0832 },
@@ -340,7 +335,7 @@ MODULE_DEVICE_TABLE(spi, adc0832_id); · 6 unmodified lines
340335 static struct spi_driver adc0832_driver = {
341336 .driver = {
342337 .name = "adc0832",
343− .of_match_table = of_match_ptr(adc0832_dt_ids),
338+ .of_match_table = adc0832_dt_ids,
344339 },
345340 .probe = adc0832_probe,
346341 .remove = adc0832_remove,
drivers/iio/adc/ti-adc084s021.c+3−6
@@ -4,12 +4,13 @@ · 3 unmodified lines
44 *
55 * Driver for Texas Instruments' ADC084S021 ADC chip.
66 * Datasheets can be found here:
7− * http://www.ti.com/lit/ds/symlink/adc084s021.pdf
7+ * https://www.ti.com/lit/ds/symlink/adc084s021.pdf
88 */
99
1010 #include <linux/err.h>
1111 #include <linux/spi/spi.h>
1212 #include <linux/module.h>
13+#include <linux/mod_devicetable.h>
1314 #include <linux/interrupt.h>
1415 #include <linux/iio/iio.h>
1516 #include <linux/iio/buffer.h>
@@ -187,8 +188,6 @@ static const struct iio_info adc084s021_info = { · 171 unmodified lines
187188
188189 static const struct iio_buffer_setup_ops adc084s021_buffer_setup_ops = {
189190 .preenable = adc084s021_buffer_preenable,
190− .postenable = iio_triggered_buffer_postenable,
191− .predisable = iio_triggered_buffer_predisable,
192191 .postdisable = adc084s021_buffer_postdisable,
193192 };
194193
@@ -211,8 +210,6 @@ static int adc084s021_probe(struct spi_device *spi) · 16 unmodified lines
211210 spi_set_drvdata(spi, indio_dev);
212211
213212 /* Initiate the Industrial I/O device */
214− indio_dev->dev.parent = &spi->dev;
215− indio_dev->dev.of_node = spi->dev.of_node;
216213 indio_dev->name = spi_get_device_id(spi)->name;
217214 indio_dev->modes = INDIO_DIRECT_MODE;
218215 indio_dev->info = &adc084s021_info;
@@ -258,7 +255,7 @@ MODULE_DEVICE_TABLE(spi, adc084s021_id); · 39 unmodified lines
258255 static struct spi_driver adc084s021_driver = {
259256 .driver = {
260257 .name = ADC084S021_DRIVER_NAME,
261− .of_match_table = of_match_ptr(adc084s021_of_match),
258+ .of_match_table = adc084s021_of_match,
262259 },
263260 .probe = adc084s021_probe,
264261 .id_table = adc084s021_id,
drivers/iio/adc/ti-adc108s102.c+0−1
@@ -252,7 +252,6 @@ static int adc108s102_probe(struct spi_device *spi) · 251 unmodified lines
252252 st->spi = spi;
253253
254254 indio_dev->name = spi->modalias;
255− indio_dev->dev.parent = &spi->dev;
256255 indio_dev->modes = INDIO_DIRECT_MODE;
257256 indio_dev->channels = adc108s102_channels;
258257 indio_dev->num_channels = ARRAY_SIZE(adc108s102_channels);
drivers/iio/adc/ti-adc12138.c+0−1
@@ -407,7 +407,6 @@ static int adc12138_probe(struct spi_device *spi) · 406 unmodified lines
407407 init_completion(&adc->complete);
408408
409409 indio_dev->name = spi_get_device_id(spi)->name;
410− indio_dev->dev.parent = &spi->dev;
411410 indio_dev->info = &adc12138_info;
412411 indio_dev->modes = INDIO_DIRECT_MODE;
413412
drivers/iio/adc/ti-adc128s052.c+3−5
@@ -4,9 +4,9 @@ · 3 unmodified lines
44 *
55 * Driver for Texas Instruments' ADC128S052, ADC122S021 and ADC124S021 ADC chip.
66 * Datasheets can be found here:
7− * http://www.ti.com/lit/ds/symlink/adc128s052.pdf
8− * http://www.ti.com/lit/ds/symlink/adc122s021.pdf
9− * http://www.ti.com/lit/ds/symlink/adc124s021.pdf
7+ * https://www.ti.com/lit/ds/symlink/adc128s052.pdf
8+ * https://www.ti.com/lit/ds/symlink/adc122s021.pdf
9+ * https://www.ti.com/lit/ds/symlink/adc124s021.pdf
1010 */
1111
1212 #include <linux/acpi.h>
@@ -152,8 +152,6 @@ static int adc128_probe(struct spi_device *spi) · 139 unmodified lines
152152
153153 spi_set_drvdata(spi, indio_dev);
154154
155− indio_dev->dev.parent = &spi->dev;
156− indio_dev->dev.of_node = spi->dev.of_node;
157155 indio_dev->name = spi_get_device_id(spi)->name;
158156 indio_dev->modes = INDIO_DIRECT_MODE;
159157 indio_dev->info = &adc128_info;
drivers/iio/adc/ti-adc161s626.c+2−3
@@ -11,6 +11,7 @@ · 10 unmodified lines
1111 */
1212
1313 #include <linux/module.h>
14+#include <linux/mod_devicetable.h>
1415 #include <linux/init.h>
1516 #include <linux/err.h>
1617 #include <linux/spi/spi.h>
@@ -179,8 +180,6 @@ static int ti_adc_probe(struct spi_device *spi) · 162 unmodified lines
179180 return -ENOMEM;
180181
181182 indio_dev->info = &ti_adc_info;
182− indio_dev->dev.parent = &spi->dev;
183− indio_dev->dev.of_node = spi->dev.of_node;
184183 indio_dev->name = TI_ADC_DRV_NAME;
185184 indio_dev->modes = INDIO_DIRECT_MODE;
186185 spi_set_drvdata(spi, indio_dev);
@@ -259,7 +258,7 @@ MODULE_DEVICE_TABLE(spi, ti_adc_id); · 72 unmodified lines
259258 static struct spi_driver ti_adc_driver = {
260259 .driver = {
261260 .name = TI_ADC_DRV_NAME,
262− .of_match_table = of_match_ptr(ti_adc_dt_ids),
261+ .of_match_table = ti_adc_dt_ids,
263262 },
264263 .probe = ti_adc_probe,
265264 .remove = ti_adc_remove,
drivers/iio/adc/ti-ads1015.c+0−4
@@ -788,8 +788,6 @@ static int ads1015_buffer_postdisable(struct iio_dev *indio_dev) · 787 unmodified lines
788788
789789 static const struct iio_buffer_setup_ops ads1015_buffer_setup_ops = {
790790 .preenable = ads1015_buffer_preenable,
791− .postenable = iio_triggered_buffer_postenable,
792− .predisable = iio_triggered_buffer_predisable,
793791 .postdisable = ads1015_buffer_postdisable,
794792 .validate_scan_mask = &iio_validate_scan_mask_onehot,
795793 };
@@ -939,8 +937,6 @@ static int ads1015_probe(struct i2c_client *client, · 143 unmodified lines
939937
940938 mutex_init(&data->lock);
941939
942− indio_dev->dev.parent = &client->dev;
943− indio_dev->dev.of_node = client->dev.of_node;
944940 indio_dev->name = ADS1015_DRV_NAME;
945941 indio_dev->modes = INDIO_DIRECT_MODE;
946942
drivers/iio/adc/ti-ads124s08.c+1−3
@@ -1,6 +1,6 @@
11 // SPDX-License-Identifier: GPL-2.0
22 /* TI ADS124S0X chip family driver
3− * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
3+ * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
44 */
55
66 #include <linux/err.h>
@@ -325,8 +325,6 @@ static int ads124s_probe(struct spi_device *spi) · 318 unmodified lines
325325 ads124s_priv->spi = spi;
326326
327327 indio_dev->name = spi_id->name;
328− indio_dev->dev.parent = &spi->dev;
329− indio_dev->dev.of_node = spi->dev.of_node;
330328 indio_dev->modes = INDIO_DIRECT_MODE;
331329 indio_dev->channels = ads124s_priv->chip_info->channels;
332330 indio_dev->num_channels = ads124s_priv->chip_info->num_channels;
drivers/iio/adc/ti-ads7950.c+1−2
@@ -9,7 +9,7 @@ · 8 unmodified lines
99 * Copyright 2012 CS Systemes d'Information
1010 *
1111 * And also on hwmon/ads79xx.c
12− * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
12+ * Copyright (C) 2013 Texas Instruments Incorporated - https://www.ti.com/
1313 * Nishanth Menon
1414 */
1515
@@ -557,7 +557,6 @@ static int ti_ads7950_probe(struct spi_device *spi) · 541 unmodified lines
557557 info = &ti_ads7950_chip_info[spi_get_device_id(spi)->driver_data];
558558
559559 indio_dev->name = spi_get_device_id(spi)->name;
560− indio_dev->dev.parent = &spi->dev;
561560 indio_dev->modes = INDIO_DIRECT_MODE;
562561 indio_dev->channels = info->channels;
563562 indio_dev->num_channels = info->num_channels;
drivers/iio/adc/ti-ads8344.c+1−3
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 *
55 * Author: Gregory CLEMENT <gregory.clement@bootlin.com>
66 *
7− * Datasheet: http://www.ti.com/lit/ds/symlink/ads8344.pdf
7+ * Datasheet: https://www.ti.com/lit/ds/symlink/ads8344.pdf
88 */
99
1010 #include <linux/delay.h>
@@ -148,8 +148,6 @@ static int ads8344_probe(struct spi_device *spi) · 137 unmodified lines
148148 mutex_init(&adc->lock);
149149
150150 indio_dev->name = dev_name(&spi->dev);
151− indio_dev->dev.parent = &spi->dev;
152− indio_dev->dev.of_node = spi->dev.of_node;
153151 indio_dev->info = &ads8344_info;
154152 indio_dev->modes = INDIO_DIRECT_MODE;
155153 indio_dev->channels = ads8344_channels;
drivers/iio/adc/ti-ads8688.c+0−2
@@ -449,8 +449,6 @@ static int ads8688_probe(struct spi_device *spi) · 448 unmodified lines
449449 st->spi = spi;
450450
451451 indio_dev->name = spi_get_device_id(spi)->name;
452− indio_dev->dev.parent = &spi->dev;
453− indio_dev->dev.of_node = spi->dev.of_node;
454452 indio_dev->modes = INDIO_DIRECT_MODE;
455453 indio_dev->channels = st->chip_info->channels;
456454 indio_dev->num_channels = st->chip_info->num_channels;
drivers/iio/adc/ti-tlc4541.c+4−6
@@ -5,8 +5,8 @@ · 4 unmodified lines
55 * Copyright (C) 2017 Phil Reid
66 *
77 * Datasheets can be found here:
8− * http://www.ti.com/lit/gpn/tlc3541
9− * http://www.ti.com/lit/gpn/tlc4541
8+ * https://www.ti.com/lit/gpn/tlc3541
9+ * https://www.ti.com/lit/gpn/tlc4541
1010 *
1111 * The tlc4541 requires 24 clock cycles to start a transfer.
1212 * Conversion then takes 2.94us to complete before data is ready
@@ -24,6 +24,7 @@ · 11 unmodified lines
2424 #include <linux/iio/triggered_buffer.h>
2525 #include <linux/kernel.h>
2626 #include <linux/module.h>
27+#include <linux/mod_devicetable.h>
2728 #include <linux/regulator/consumer.h>
2829 #include <linux/slab.h>
2930 #include <linux/spi/spi.h>
@@ -177,7 +178,6 @@ static int tlc4541_probe(struct spi_device *spi) · 147 unmodified lines
177178 info = &tlc4541_chip_info[spi_get_device_id(spi)->driver_data];
178179
179180 indio_dev->name = spi_get_device_id(spi)->name;
180− indio_dev->dev.parent = &spi->dev;
181181 indio_dev->modes = INDIO_DIRECT_MODE;
182182 indio_dev->channels = info->channels;
183183 indio_dev->num_channels = info->num_channels;
@@ -236,14 +236,12 @@ static int tlc4541_remove(struct spi_device *spi) · 52 unmodified lines
236236 return 0;
237237 }
238238
239−#ifdef CONFIG_OF
240239 static const struct of_device_id tlc4541_dt_ids[] = {
241240 { .compatible = "ti,tlc3541", },
242241 { .compatible = "ti,tlc4541", },
243242 {}
244243 };
245244 MODULE_DEVICE_TABLE(of, tlc4541_dt_ids);
246−#endif
247245
248246 static const struct spi_device_id tlc4541_id[] = {
249247 {"tlc3541", TLC3541},
@@ -255,7 +253,7 @@ MODULE_DEVICE_TABLE(spi, tlc4541_id); · 5 unmodified lines
255253 static struct spi_driver tlc4541_driver = {
256254 .driver = {
257255 .name = "tlc4541",
258− .of_match_table = of_match_ptr(tlc4541_dt_ids),
256+ .of_match_table = tlc4541_dt_ids,
259257 },
260258 .probe = tlc4541_probe,
261259 .remove = tlc4541_remove,
drivers/iio/adc/ti_am335x_adc.c+11−27
@@ -1,7 +1,7 @@
11 /*
22 * TI ADC MFD driver
33 *
4− * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
4+ * Copyright (C) 2012 Texas Instruments Incorporated - https://www.ti.com/
55 *
66 * This program is free software; you can redistribute it and/or
77 * modify it under the terms of the GNU General Public License as
@@ -377,7 +377,8 @@ static const struct iio_buffer_setup_ops tiadc_buffer_setup_ops = { · 369 unmodified lines
377377 .postdisable = &tiadc_buffer_postdisable,
378378 };
379379
380−static int tiadc_iio_buffered_hardware_setup(struct iio_dev *indio_dev,
380+static int tiadc_iio_buffered_hardware_setup(struct device *dev,
381+ struct iio_dev *indio_dev,
381382 irqreturn_t (*pollfunc_bh)(int irq, void *p),
382383 irqreturn_t (*pollfunc_th)(int irq, void *p),
383384 int irq,
@@ -387,13 +388,13 @@ static int tiadc_iio_buffered_hardware_setup(struct iio_dev *indio_dev, · 3 unmodified lines
387388 struct iio_buffer *buffer;
388389 int ret;
389390
390− buffer = iio_kfifo_allocate();
391+ buffer = devm_iio_kfifo_allocate(dev);
391392 if (!buffer)
392393 return -ENOMEM;
393394
394395 iio_device_attach_buffer(indio_dev, buffer);
395396
396− ret = request_threaded_irq(irq, pollfunc_th, pollfunc_bh,
397+ ret = devm_request_threaded_irq(dev, irq, pollfunc_th, pollfunc_bh,
397398 flags, indio_dev->name, indio_dev);
398399 if (ret)
399400 goto error_kfifo_free;
@@ -408,15 +409,6 @@ error_kfifo_free: · 8 unmodified lines
408409 return ret;
409410 }
410411
411−static void tiadc_iio_buffered_hardware_remove(struct iio_dev *indio_dev)
412−{
413− struct tiadc_device *adc_dev = iio_priv(indio_dev);
414−
415− free_irq(adc_dev->mfd_tscadc->irq, indio_dev);
416− iio_kfifo_free(indio_dev->buffer);
417−}
418−
419−
420412 static const char * const chan_name_ain[] = {
421413 "AIN0",
422414 "AIN1",
@@ -428,7 +420,8 @@ static const char * const chan_name_ain[] = { · 5 unmodified lines
428420 "AIN7",
429421 };
430422
431−static int tiadc_channel_init(struct iio_dev *indio_dev, int channels)
423+static int tiadc_channel_init(struct device *dev, struct iio_dev *indio_dev,
424+ int channels)
432425 {
433426 struct tiadc_device *adc_dev = iio_priv(indio_dev);
434427 struct iio_chan_spec *chan_array;
@@ -436,7 +429,8 @@ static int tiadc_channel_init(struct iio_dev *indio_dev, int channels) · 1 unmodified line
436429 int i;
437430
438431 indio_dev->num_channels = channels;
439− chan_array = kcalloc(channels, sizeof(*chan_array), GFP_KERNEL);
432+ chan_array = devm_kcalloc(dev, channels, sizeof(*chan_array),
433+ GFP_KERNEL);
440434 if (chan_array == NULL)
441435 return -ENOMEM;
442436
@@ -459,11 +453,6 @@ static int tiadc_channel_init(struct iio_dev *indio_dev, int channels) · 16 unmodified lines
459453 return 0;
460454 }
461455
462−static void tiadc_channels_remove(struct iio_dev *indio_dev)
463−{
464− kfree(indio_dev->channels);
465−}
466−
467456 static int tiadc_read_raw(struct iio_dev *indio_dev,
468457 struct iio_chan_spec const *chan,
469458 int *val, int *val2, long mask)
@@ -626,7 +615,6 @@ static int tiadc_probe(struct platform_device *pdev) · 156 unmodified lines
626615 adc_dev->mfd_tscadc = ti_tscadc_dev_get(pdev);
627616 tiadc_parse_dt(pdev, adc_dev);
628617
629− indio_dev->dev.parent = &pdev->dev;
630618 indio_dev->name = dev_name(&pdev->dev);
631619 indio_dev->modes = INDIO_DIRECT_MODE;
632620 indio_dev->info = &tiadc_info;
@@ -635,11 +623,11 @@ static int tiadc_probe(struct platform_device *pdev) · 2 unmodified lines
635623 tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD);
636624 mutex_init(&adc_dev->fifo1_lock);
637625
638− err = tiadc_channel_init(indio_dev, adc_dev->channels);
626+ err = tiadc_channel_init(&pdev->dev, indio_dev, adc_dev->channels);
639627 if (err < 0)
640628 return err;
641629
642− err = tiadc_iio_buffered_hardware_setup(indio_dev,
630+ err = tiadc_iio_buffered_hardware_setup(&pdev->dev, indio_dev,
643631 &tiadc_worker_h,
644632 &tiadc_irq_h,
645633 adc_dev->mfd_tscadc->irq,
@@ -664,9 +652,7 @@ static int tiadc_probe(struct platform_device *pdev) · 18 unmodified lines
664652 err_dma:
665653 iio_device_unregister(indio_dev);
666654 err_buffer_unregister:
667− tiadc_iio_buffered_hardware_remove(indio_dev);
668655 err_free_channels:
669− tiadc_channels_remove(indio_dev);
670656 return err;
671657 }
672658
@@ -683,8 +669,6 @@ static int tiadc_remove(struct platform_device *pdev) · 10 unmodified lines
683669 dma_release_channel(dma->chan);
684670 }
685671 iio_device_unregister(indio_dev);
686− tiadc_iio_buffered_hardware_remove(indio_dev);
687− tiadc_channels_remove(indio_dev);
688672
689673 step_en = get_adc_step_mask(adc_dev);
690674 am335x_tsc_se_clr(adc_dev->mfd_tscadc, step_en);
drivers/iio/adc/twl4030-madc.c+1−3
@@ -5,7 +5,7 @@ · 4 unmodified lines
55 * conversion of analog signals like battery temperature,
66 * battery type, battery level etc.
77 *
8− * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
8+ * Copyright (C) 2011 Texas Instruments Incorporated - https://www.ti.com/
99 * J Keerthy <j-keerthy@ti.com>
1010 *
1111 * Based on twl4030-madc.c
@@ -772,8 +772,6 @@ static int twl4030_madc_probe(struct platform_device *pdev) · 760 unmodified lines
772772 madc->dev = &pdev->dev;
773773
774774 iio_dev->name = dev_name(&pdev->dev);
775− iio_dev->dev.parent = &pdev->dev;
776− iio_dev->dev.of_node = pdev->dev.of_node;
777775 iio_dev->info = &twl4030_madc_iio_info;
778776 iio_dev->modes = INDIO_DIRECT_MODE;
779777 iio_dev->channels = twl4030_madc_iio_channels;
drivers/iio/adc/twl6030-gpadc.c+0−1
@@ -926,7 +926,6 @@ static int twl6030_gpadc_probe(struct platform_device *pdev) · 925 unmodified lines
926926 }
927927
928928 indio_dev->name = DRIVER_NAME;
929− indio_dev->dev.parent = dev;
930929 indio_dev->info = &twl6030_gpadc_iio_info;
931930 indio_dev->modes = INDIO_DIRECT_MODE;
932931 indio_dev->channels = pdata->iio_channels;
drivers/iio/adc/vf610_adc.c+1−8
@@ -724,13 +724,8 @@ static int vf610_adc_buffer_postenable(struct iio_dev *indio_dev) · 723 unmodified lines
724724 {
725725 struct vf610_adc *info = iio_priv(indio_dev);
726726 unsigned int channel;
727− int ret;
728727 int val;
729728
730− ret = iio_triggered_buffer_postenable(indio_dev);
731− if (ret)
732− return ret;
733−
734729 val = readl(info->regs + VF610_REG_ADC_GC);
735730 val |= VF610_ADC_ADCON;
736731 writel(val, info->regs + VF610_REG_ADC_GC);
@@ -761,7 +756,7 @@ static int vf610_adc_buffer_predisable(struct iio_dev *indio_dev) · 24 unmodified lines
761756
762757 writel(hc_cfg, info->regs + VF610_REG_ADC_HC0);
763758
764− return iio_triggered_buffer_predisable(indio_dev);
759+ return 0;
765760 }
766761
767762 static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {
@@ -860,8 +855,6 @@ static int vf610_adc_probe(struct platform_device *pdev) · 92 unmodified lines
860855 init_completion(&info->completion);
861856
862857 indio_dev->name = dev_name(&pdev->dev);
863− indio_dev->dev.parent = &pdev->dev;
864− indio_dev->dev.of_node = pdev->dev.of_node;
865858 indio_dev->info = &vf610_adc_iio_info;
866859 indio_dev->modes = INDIO_DIRECT_MODE;
867860 indio_dev->channels = vf610_adc_iio_channels;
drivers/iio/adc/viperboard_adc.c+0−1
@@ -121,7 +121,6 @@ static int vprbrd_adc_probe(struct platform_device *pdev) · 120 unmodified lines
121121 adc = iio_priv(indio_dev);
122122 adc->vb = vb;
123123 indio_dev->name = "viperboard adc";
124− indio_dev->dev.parent = &pdev->dev;
125124 indio_dev->info = &vprbrd_adc_iio_info;
126125 indio_dev->modes = INDIO_DIRECT_MODE;
127126 indio_dev->channels = vprbrd_adc_iio_channels;
drivers/iio/adc/xilinx-xadc-core.c+0−4
@@ -839,8 +839,6 @@ err: · 838 unmodified lines
839839
840840 static const struct iio_buffer_setup_ops xadc_buffer_ops = {
841841 .preenable = &xadc_preenable,
842− .postenable = &iio_triggered_buffer_postenable,
843− .predisable = &iio_triggered_buffer_predisable,
844842 .postdisable = &xadc_postdisable,
845843 };
846844
@@ -1221,8 +1219,6 @@ static int xadc_probe(struct platform_device *pdev) · 374 unmodified lines
12211219 if (IS_ERR(xadc->base))
12221220 return PTR_ERR(xadc->base);
12231221
1224− indio_dev->dev.parent = &pdev->dev;
1225− indio_dev->dev.of_node = pdev->dev.of_node;
12261222 indio_dev->name = "xadc";
12271223 indio_dev->modes = INDIO_DIRECT_MODE;
12281224 indio_dev->info = &xadc_info;
drivers/iio/afe/iio-rescale.c+0−1
@@ -314,7 +314,6 @@ static int rescale_probe(struct platform_device *pdev) · 313 unmodified lines
314314 rescale->source = source;
315315
316316 indio_dev->name = dev_name(dev);
317− indio_dev->dev.parent = dev;
318317 indio_dev->info = &rescale_info;
319318 indio_dev->modes = INDIO_DIRECT_MODE;
320319 indio_dev->channels = &rescale->chan;
drivers/iio/amplifiers/ad8366.c+5−3
@@ -262,8 +262,11 @@ static int ad8366_probe(struct spi_device *spi) · 261 unmodified lines
262262 case ID_ADA4961:
263263 case ID_ADL5240:
264264 case ID_HMC1119:
265− st->reset_gpio = devm_gpiod_get(&spi->dev, "reset",
266− GPIOD_OUT_HIGH);
265+ st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_HIGH);
266+ if (IS_ERR(st->reset_gpio)) {
267+ ret = PTR_ERR(st->reset_gpio);
268+ goto error_disable_reg;
269+ }
267270 indio_dev->channels = ada4961_channels;
268271 indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
269272 break;
@@ -274,7 +277,6 @@ static int ad8366_probe(struct spi_device *spi) · 4 unmodified lines
274277 }
275278
276279 st->info = &ad8366_infos[st->type];
277− indio_dev->dev.parent = &spi->dev;
278280 indio_dev->name = spi_get_device_id(spi)->name;
279281 indio_dev->info = &ad8366_info;
280282 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/amplifiers/hmc425a.c+0−1
@@ -227,7 +227,6 @@ static int hmc425a_probe(struct platform_device *pdev) · 226 unmodified lines
227227
228228 mutex_init(&st->lock);
229229
230− indio_dev->dev.parent = &pdev->dev;
231230 indio_dev->info = &hmc425a_info;
232231 indio_dev->modes = INDIO_DIRECT_MODE;
233232
drivers/iio/buffer/industrialio-triggered-buffer.c+1−9
@@ -13,11 +13,6 @@ · 12 unmodified lines
1313 #include <linux/iio/triggered_buffer.h>
1414 #include <linux/iio/trigger_consumer.h>
1515
16−static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {
17− .postenable = &iio_triggered_buffer_postenable,
18− .predisable = &iio_triggered_buffer_predisable,
19−};
20−
2116 /**
2217 * iio_triggered_buffer_setup() - Setup triggered buffer and pollfunc
2318 * @indio_dev: IIO device structure
@@ -67,10 +62,7 @@ int iio_triggered_buffer_setup(struct iio_dev *indio_dev, · 43 unmodified lines
6762 }
6863
6964 /* Ring buffer functions - here trigger setup related */
70− if (setup_ops)
71− indio_dev->setup_ops = setup_ops;
72− else
73− indio_dev->setup_ops = &iio_triggered_buffer_setup_ops;
65+ indio_dev->setup_ops = setup_ops;
7466
7567 /* Flag that polled ring buffering is possible */
7668 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
drivers/iio/chemical/Kconfig+33−0
@@ -85,6 +85,39 @@ config PMS7003 · 84 unmodified lines
8585 To compile this driver as a module, choose M here: the module will
8686 be called pms7003.
8787
88+config SCD30_CORE
89+ tristate "SCD30 carbon dioxide sensor driver"
90+ select IIO_BUFFER
91+ select IIO_TRIGGERED_BUFFER
92+ help
93+ Say Y here to build support for the Sensirion SCD30 sensor with carbon
94+ dioxide, relative humidity and temperature sensing capabilities.
95+
96+ To compile this driver as a module, choose M here: the module will
97+ be called scd30_core.
98+
99+config SCD30_I2C
100+ tristate "SCD30 carbon dioxide sensor I2C driver"
101+ depends on SCD30_CORE && I2C
102+ select CRC8
103+ help
104+ Say Y here to build support for the Sensirion SCD30 I2C interface
105+ driver.
106+
107+ To compile this driver as a module, choose M here: the module will
108+ be called scd30_i2c.
109+
110+config SCD30_SERIAL
111+ tristate "SCD30 carbon dioxide sensor serial driver"
112+ depends on SCD30_CORE && SERIAL_DEV_BUS
113+ select CRC16
114+ help
115+ Say Y here to build support for the Sensirion SCD30 serial interface
116+ driver.
117+
118+ To compile this driver as a module, choose M here: the module will
119+ be called scd30_serial.
120+
88121 config SENSIRION_SGP30
89122 tristate "Sensirion SGPxx gas sensors"
90123 depends on I2C
drivers/iio/chemical/Makefile+3−0
@@ -12,6 +12,9 @@ obj-$(CONFIG_BME680_SPI) += bme680_spi.o · 11 unmodified lines
1212 obj-$(CONFIG_CCS811) += ccs811.o
1313 obj-$(CONFIG_IAQCORE) += ams-iaq-core.o
1414 obj-$(CONFIG_PMS7003) += pms7003.o
15+obj-$(CONFIG_SCD30_CORE) += scd30_core.o
16+obj-$(CONFIG_SCD30_I2C) += scd30_i2c.o
17+obj-$(CONFIG_SCD30_SERIAL) += scd30_serial.o
1518 obj-$(CONFIG_SENSIRION_SGP30) += sgp30.o
1619 obj-$(CONFIG_SPS30) += sps30.o
1720 obj-$(CONFIG_VZ89X) += vz89x.o
drivers/iio/chemical/ams-iaq-core.c+0−1
@@ -152,7 +152,6 @@ static int ams_iaqcore_probe(struct i2c_client *client, · 151 unmodified lines
152152 data->last_update = jiffies - HZ;
153153 mutex_init(&data->lock);
154154
155− indio_dev->dev.parent = &client->dev;
156155 indio_dev->info = &ams_iaqcore_info;
157156 indio_dev->name = dev_name(&client->dev);
158157 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/chemical/atlas-ezo-sensor.c+2−3
@@ -69,13 +69,13 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev, · 68 unmodified lines
6969 {
7070 struct atlas_ezo_data *data = iio_priv(indio_dev);
7171 struct i2c_client *client = data->client;
72− int ret = 0;
7372
7473 if (chan->type != IIO_CONCENTRATION)
7574 return -EINVAL;
7675
7776 switch (mask) {
7877 case IIO_CHAN_INFO_RAW: {
78+ int ret;
7979 long tmp;
8080
8181 mutex_lock(&data->lock);
@@ -110,7 +110,7 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev, · 28 unmodified lines
110110 return IIO_VAL_INT_PLUS_MICRO;
111111 }
112112
113− return ret;
113+ return 0;
114114 }
115115
116116 static const struct iio_info atlas_info = {
@@ -152,7 +152,6 @@ static int atlas_ezo_probe(struct i2c_client *client, · 35 unmodified lines
152152 indio_dev->channels = chip->channels;
153153 indio_dev->num_channels = chip->num_channels;
154154 indio_dev->modes = INDIO_DIRECT_MODE;
155− indio_dev->dev.parent = &client->dev;
156155
157156 data = iio_priv(indio_dev);
158157 data->client = client;
drivers/iio/chemical/atlas-sensor.c+1−6
@@ -410,10 +410,6 @@ static int atlas_buffer_postenable(struct iio_dev *indio_dev) · 409 unmodified lines
410410 struct atlas_data *data = iio_priv(indio_dev);
411411 int ret;
412412
413− ret = iio_triggered_buffer_postenable(indio_dev);
414− if (ret)
415− return ret;
416−
417413 ret = pm_runtime_get_sync(&data->client->dev);
418414 if (ret < 0) {
419415 pm_runtime_put_noidle(&data->client->dev);
@@ -437,7 +433,7 @@ static int atlas_buffer_predisable(struct iio_dev *indio_dev) · 17 unmodified lines
437433 if (ret)
438434 return ret;
439435
440− return iio_triggered_buffer_predisable(indio_dev);
436+ return 0;
441437 }
442438
443439 static const struct iio_trigger_ops atlas_interrupt_trigger_ops = {
@@ -644,7 +640,6 @@ static int atlas_probe(struct i2c_client *client, · 200 unmodified lines
644640 indio_dev->channels = chip->channels;
645641 indio_dev->num_channels = chip->num_channels;
646642 indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE;
647− indio_dev->dev.parent = &client->dev;
648643
649644 trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
650645 indio_dev->name, indio_dev->id);
drivers/iio/chemical/bme680_core.c+0−1
@@ -923,7 +923,6 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, · 922 unmodified lines
923923 data = iio_priv(indio_dev);
924924 dev_set_drvdata(dev, indio_dev);
925925 data->regmap = regmap;
926− indio_dev->dev.parent = dev;
927926 indio_dev->name = name;
928927 indio_dev->channels = bme680_channels;
929928 indio_dev->num_channels = ARRAY_SIZE(bme680_channels);
drivers/iio/chemical/ccs811.c+0−1
@@ -464,7 +464,6 @@ static int ccs811_probe(struct i2c_client *client, · 463 unmodified lines
464464
465465 mutex_init(&data->lock);
466466
467− indio_dev->dev.parent = &client->dev;
468467 indio_dev->name = id->name;
469468 indio_dev->info = &ccs811_info;
470469 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/chemical/pms7003.c+0−1
@@ -280,7 +280,6 @@ static int pms7003_probe(struct serdev_device *serdev) · 279 unmodified lines
280280 state = iio_priv(indio_dev);
281281 serdev_device_set_drvdata(serdev, indio_dev);
282282 state->serdev = serdev;
283− indio_dev->dev.parent = &serdev->dev;
284283 indio_dev->info = &pms7003_info;
285284 indio_dev->name = PMS7003_DRIVER_NAME;
286285 indio_dev->channels = pms7003_channels,
drivers/iio/chemical/scd30.h+78−0
@@ -0,0 +1,78 @@
1+/* SPDX-License-Identifier: GPL-2.0 */
2+#ifndef _SCD30_H
3+#define _SCD30_H
4+
5+#include <linux/completion.h>
6+#include <linux/device.h>
7+#include <linux/mutex.h>
8+#include <linux/pm.h>
9+#include <linux/regulator/consumer.h>
10+#include <linux/types.h>
11+
12+struct scd30_state;
13+
14+enum scd30_cmd {
15+ /* start continuous measurement with pressure compensation */
16+ CMD_START_MEAS,
17+ /* stop continuous measurement */
18+ CMD_STOP_MEAS,
19+ /* set/get measurement interval */
20+ CMD_MEAS_INTERVAL,
21+ /* check whether new measurement is ready */
22+ CMD_MEAS_READY,
23+ /* get measurement */
24+ CMD_READ_MEAS,
25+ /* turn on/off automatic self calibration */
26+ CMD_ASC,
27+ /* set/get forced recalibration value */
28+ CMD_FRC,
29+ /* set/get temperature offset */
30+ CMD_TEMP_OFFSET,
31+ /* get firmware version */
32+ CMD_FW_VERSION,
33+ /* reset sensor */
34+ CMD_RESET,
35+ /*
36+ * Command for altitude compensation was omitted intentionally because
37+ * the same can be achieved by means of CMD_START_MEAS which takes
38+ * pressure above the sea level as an argument.
39+ */
40+};
41+
42+#define SCD30_MEAS_COUNT 3
43+
44+typedef int (*scd30_command_t)(struct scd30_state *state, enum scd30_cmd cmd, u16 arg,
45+ void *response, int size);
46+
47+struct scd30_state {
48+ /* serialize access to the device */
49+ struct mutex lock;
50+ struct device *dev;
51+ struct regulator *vdd;
52+ struct completion meas_ready;
53+ /*
54+ * priv pointer is solely for serdev driver private data. We keep it
55+ * here because driver_data inside dev has been already used for iio and
56+ * struct serdev_device doesn't have one.
57+ */
58+ void *priv;
59+ int irq;
60+ /*
61+ * no way to retrieve current ambient pressure compensation value from
62+ * the sensor so keep one around
63+ */
64+ u16 pressure_comp;
65+ u16 meas_interval;
66+ int meas[SCD30_MEAS_COUNT];
67+
68+ scd30_command_t command;
69+};
70+
71+int scd30_suspend(struct device *dev);
72+int scd30_resume(struct device *dev);
73+
74+static __maybe_unused SIMPLE_DEV_PM_OPS(scd30_pm_ops, scd30_suspend, scd30_resume);
75+
76+int scd30_probe(struct device *dev, int irq, const char *name, void *priv, scd30_command_t command);
77+
78+#endif
drivers/iio/chemical/scd30_core.c+771−0
@@ -0,0 +1,771 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/*
3+ * Sensirion SCD30 carbon dioxide sensor core driver
4+ *
5+ * Copyright (c) 2020 Tomasz Duszynski <tomasz.duszynski@octakon.com>
6+ */
7+#include <linux/bits.h>
8+#include <linux/completion.h>
9+#include <linux/delay.h>
10+#include <linux/device.h>
11+#include <linux/errno.h>
12+#include <linux/export.h>
13+#include <linux/iio/buffer.h>
14+#include <linux/iio/iio.h>
15+#include <linux/iio/sysfs.h>
16+#include <linux/iio/trigger.h>
17+#include <linux/iio/trigger_consumer.h>
18+#include <linux/iio/triggered_buffer.h>
19+#include <linux/iio/types.h>
20+#include <linux/interrupt.h>
21+#include <linux/irqreturn.h>
22+#include <linux/jiffies.h>
23+#include <linux/kernel.h>
24+#include <linux/module.h>
25+#include <linux/mutex.h>
26+#include <linux/regulator/consumer.h>
27+#include <linux/string.h>
28+#include <linux/sysfs.h>
29+#include <linux/types.h>
30+#include <asm/byteorder.h>
31+
32+#include "scd30.h"
33+
34+#define SCD30_PRESSURE_COMP_MIN_MBAR 700
35+#define SCD30_PRESSURE_COMP_MAX_MBAR 1400
36+#define SCD30_PRESSURE_COMP_DEFAULT 1013
37+#define SCD30_MEAS_INTERVAL_MIN_S 2
38+#define SCD30_MEAS_INTERVAL_MAX_S 1800
39+#define SCD30_MEAS_INTERVAL_DEFAULT SCD30_MEAS_INTERVAL_MIN_S
40+#define SCD30_FRC_MIN_PPM 400
41+#define SCD30_FRC_MAX_PPM 2000
42+#define SCD30_TEMP_OFFSET_MAX 655360
43+#define SCD30_EXTRA_TIMEOUT_PER_S 250
44+
45+enum {
46+ SCD30_CONC,
47+ SCD30_TEMP,
48+ SCD30_HR,
49+};
50+
51+static int scd30_command_write(struct scd30_state *state, enum scd30_cmd cmd, u16 arg)
52+{
53+ return state->command(state, cmd, arg, NULL, 0);
54+}
55+
56+static int scd30_command_read(struct scd30_state *state, enum scd30_cmd cmd, u16 *val)
57+{
58+ __be16 tmp;
59+ int ret;
60+
61+ ret = state->command(state, cmd, 0, &tmp, sizeof(tmp));
62+ *val = be16_to_cpup(&tmp);
63+
64+ return ret;
65+}
66+
67+static int scd30_reset(struct scd30_state *state)
68+{
69+ int ret;
70+ u16 val;
71+
72+ ret = scd30_command_write(state, CMD_RESET, 0);
73+ if (ret)
74+ return ret;
75+
76+ /* sensor boots up within 2 secs */
77+ msleep(2000);
78+ /*
79+ * Power-on-reset causes sensor to produce some glitch on i2c bus and
80+ * some controllers end up in error state. Try to recover by placing
81+ * any data on the bus.
82+ */
83+ scd30_command_read(state, CMD_MEAS_READY, &val);
84+
85+ return 0;
86+}
87+
88+/* simplified float to fixed point conversion with a scaling factor of 0.01 */
89+static int scd30_float_to_fp(int float32)
90+{
91+ int fraction, shift,
92+ mantissa = float32 & GENMASK(22, 0),
93+ sign = (float32 & BIT(31)) ? -1 : 1,
94+ exp = (float32 & ~BIT(31)) >> 23;
95+
96+ /* special case 0 */
97+ if (!exp && !mantissa)
98+ return 0;
99+
100+ exp -= 127;
101+ if (exp < 0) {
102+ exp = -exp;
103+ /* return values ranging from 1 to 99 */
104+ return sign * ((((BIT(23) + mantissa) * 100) >> 23) >> exp);
105+ }
106+
107+ /* return values starting at 100 */
108+ shift = 23 - exp;
109+ float32 = BIT(exp) + (mantissa >> shift);
110+ fraction = mantissa & GENMASK(shift - 1, 0);
111+
112+ return sign * (float32 * 100 + ((fraction * 100) >> shift));
113+}
114+
115+static int scd30_read_meas(struct scd30_state *state)
116+{
117+ int i, ret;
118+
119+ ret = state->command(state, CMD_READ_MEAS, 0, state->meas, sizeof(state->meas));
120+ if (ret)
121+ return ret;
122+
123+ be32_to_cpu_array(state->meas, (__be32 *)state->meas, ARRAY_SIZE(state->meas));
124+
125+ for (i = 0; i < ARRAY_SIZE(state->meas); i++)
126+ state->meas[i] = scd30_float_to_fp(state->meas[i]);
127+
128+ /*
129+ * co2 is left unprocessed while temperature and humidity are scaled
130+ * to milli deg C and milli percent respectively.
131+ */
132+ state->meas[SCD30_TEMP] *= 10;
133+ state->meas[SCD30_HR] *= 10;
134+
135+ return 0;
136+}
137+
138+static int scd30_wait_meas_irq(struct scd30_state *state)
139+{
140+ int ret, timeout;
141+
142+ reinit_completion(&state->meas_ready);
143+ enable_irq(state->irq);
144+ timeout = msecs_to_jiffies(state->meas_interval * (1000 + SCD30_EXTRA_TIMEOUT_PER_S));
145+ ret = wait_for_completion_interruptible_timeout(&state->meas_ready, timeout);
146+ if (ret > 0)
147+ ret = 0;
148+ else if (!ret)
149+ ret = -ETIMEDOUT;
150+
151+ disable_irq(state->irq);
152+
153+ return ret;
154+}
155+
156+static int scd30_wait_meas_poll(struct scd30_state *state)
157+{
158+ int timeout = state->meas_interval * SCD30_EXTRA_TIMEOUT_PER_S, tries = 5;
159+
160+ do {
161+ int ret;
162+ u16 val;
163+
164+ ret = scd30_command_read(state, CMD_MEAS_READY, &val);
165+ if (ret)
166+ return -EIO;
167+
168+ /* new measurement available */
169+ if (val)
170+ break;
171+
172+ msleep_interruptible(timeout);
173+ } while (--tries);
174+
175+ return tries ? 0 : -ETIMEDOUT;
176+}
177+
178+static int scd30_read_poll(struct scd30_state *state)
179+{
180+ int ret;
181+
182+ ret = scd30_wait_meas_poll(state);
183+ if (ret)
184+ return ret;
185+
186+ return scd30_read_meas(state);
187+}
188+
189+static int scd30_read(struct scd30_state *state)
190+{
191+ if (state->irq > 0)
192+ return scd30_wait_meas_irq(state);
193+
194+ return scd30_read_poll(state);
195+}
196+
197+static int scd30_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
198+ int *val, int *val2, long mask)
199+{
200+ struct scd30_state *state = iio_priv(indio_dev);
201+ int ret = -EINVAL;
202+ u16 tmp;
203+
204+ mutex_lock(&state->lock);
205+ switch (mask) {
206+ case IIO_CHAN_INFO_RAW:
207+ case IIO_CHAN_INFO_PROCESSED:
208+ if (chan->output) {
209+ *val = state->pressure_comp;
210+ ret = IIO_VAL_INT;
211+ break;
212+ }
213+
214+ ret = iio_device_claim_direct_mode(indio_dev);
215+ if (ret)
216+ break;
217+
218+ ret = scd30_read(state);
219+ if (ret) {
220+ iio_device_release_direct_mode(indio_dev);
221+ break;
222+ }
223+
224+ *val = state->meas[chan->address];
225+ iio_device_release_direct_mode(indio_dev);
226+ ret = IIO_VAL_INT;
227+ break;
228+ case IIO_CHAN_INFO_SCALE:
229+ *val = 0;
230+ *val2 = 1;
231+ ret = IIO_VAL_INT_PLUS_MICRO;
232+ break;
233+ case IIO_CHAN_INFO_SAMP_FREQ:
234+ ret = scd30_command_read(state, CMD_MEAS_INTERVAL, &tmp);
235+ if (ret)
236+ break;
237+
238+ *val = 0;
239+ *val2 = 1000000000 / tmp;
240+ ret = IIO_VAL_INT_PLUS_NANO;
241+ break;
242+ case IIO_CHAN_INFO_CALIBBIAS:
243+ ret = scd30_command_read(state, CMD_TEMP_OFFSET, &tmp);
244+ if (ret)
245+ break;
246+
247+ *val = tmp;
248+ ret = IIO_VAL_INT;
249+ break;
250+ }
251+ mutex_unlock(&state->lock);
252+
253+ return ret;
254+}
255+
256+static int scd30_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
257+ int val, int val2, long mask)
258+{
259+ struct scd30_state *state = iio_priv(indio_dev);
260+ int ret = -EINVAL;
261+
262+ mutex_lock(&state->lock);
263+ switch (mask) {
264+ case IIO_CHAN_INFO_SAMP_FREQ:
265+ if (val)
266+ break;
267+
268+ val = 1000000000 / val2;
269+ if (val < SCD30_MEAS_INTERVAL_MIN_S || val > SCD30_MEAS_INTERVAL_MAX_S)
270+ break;
271+
272+ ret = scd30_command_write(state, CMD_MEAS_INTERVAL, val);
273+ if (ret)
274+ break;
275+
276+ state->meas_interval = val;
277+ break;
278+ case IIO_CHAN_INFO_RAW:
279+ switch (chan->type) {
280+ case IIO_PRESSURE:
281+ if (val < SCD30_PRESSURE_COMP_MIN_MBAR ||
282+ val > SCD30_PRESSURE_COMP_MAX_MBAR)
283+ break;
284+
285+ ret = scd30_command_write(state, CMD_START_MEAS, val);
286+ if (ret)
287+ break;
288+
289+ state->pressure_comp = val;
290+ break;
291+ default:
292+ break;
293+ }
294+ break;
295+ case IIO_CHAN_INFO_CALIBBIAS:
296+ if (val < 0 || val > SCD30_TEMP_OFFSET_MAX)
297+ break;
298+ /*
299+ * Manufacturer does not explicitly specify min/max sensible
300+ * values hence check is omitted for simplicity.
301+ */
302+ ret = scd30_command_write(state, CMD_TEMP_OFFSET / 10, val);
303+ }
304+ mutex_unlock(&state->lock);
305+
306+ return ret;
307+}
308+
309+static int scd30_write_raw_get_fmt(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
310+ long mask)
311+{
312+ switch (mask) {
313+ case IIO_CHAN_INFO_SAMP_FREQ:
314+ return IIO_VAL_INT_PLUS_NANO;
315+ case IIO_CHAN_INFO_RAW:
316+ case IIO_CHAN_INFO_CALIBBIAS:
317+ return IIO_VAL_INT;
318+ }
319+
320+ return -EINVAL;
321+}
322+
323+static const int scd30_pressure_raw_available[] = {
324+ SCD30_PRESSURE_COMP_MIN_MBAR, 1, SCD30_PRESSURE_COMP_MAX_MBAR,
325+};
326+
327+static const int scd30_temp_calibbias_available[] = {
328+ 0, 10, SCD30_TEMP_OFFSET_MAX,
329+};
330+
331+static int scd30_read_avail(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
332+ const int **vals, int *type, int *length, long mask)
333+{
334+ switch (mask) {
335+ case IIO_CHAN_INFO_RAW:
336+ *vals = scd30_pressure_raw_available;
337+ *type = IIO_VAL_INT;
338+
339+ return IIO_AVAIL_RANGE;
340+ case IIO_CHAN_INFO_CALIBBIAS:
341+ *vals = scd30_temp_calibbias_available;
342+ *type = IIO_VAL_INT;
343+
344+ return IIO_AVAIL_RANGE;
345+ }
346+
347+ return -EINVAL;
348+}
349+
350+static ssize_t sampling_frequency_available_show(struct device *dev, struct device_attribute *attr,
351+ char *buf)
352+{
353+ int i = SCD30_MEAS_INTERVAL_MIN_S;
354+ ssize_t len = 0;
355+
356+ do {
357+ len += scnprintf(buf + len, PAGE_SIZE - len, "0.%09u ", 1000000000 / i);
358+ /*
359+ * Not all values fit PAGE_SIZE buffer hence print every 6th
360+ * (each frequency differs by 6s in time domain from the
361+ * adjacent). Unlisted but valid ones are still accepted.
362+ */
363+ i += 6;
364+ } while (i <= SCD30_MEAS_INTERVAL_MAX_S);
365+
366+ buf[len - 1] = '\n';
367+
368+ return len;
369+}
370+
371+static ssize_t calibration_auto_enable_show(struct device *dev, struct device_attribute *attr,
372+ char *buf)
373+{
374+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
375+ struct scd30_state *state = iio_priv(indio_dev);
376+ int ret;
377+ u16 val;
378+
379+ mutex_lock(&state->lock);
380+ ret = scd30_command_read(state, CMD_ASC, &val);
381+ mutex_unlock(&state->lock);
382+
383+ return ret ?: sprintf(buf, "%d\n", val);
384+}
385+
386+static ssize_t calibration_auto_enable_store(struct device *dev, struct device_attribute *attr,
387+ const char *buf, size_t len)
388+{
389+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
390+ struct scd30_state *state = iio_priv(indio_dev);
391+ bool val;
392+ int ret;
393+
394+ ret = kstrtobool(buf, &val);
395+ if (ret)
396+ return ret;
397+
398+ mutex_lock(&state->lock);
399+ ret = scd30_command_write(state, CMD_ASC, val);
400+ mutex_unlock(&state->lock);
401+
402+ return ret ?: len;
403+}
404+
405+static ssize_t calibration_forced_value_show(struct device *dev, struct device_attribute *attr,
406+ char *buf)
407+{
408+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
409+ struct scd30_state *state = iio_priv(indio_dev);
410+ int ret;
411+ u16 val;
412+
413+ mutex_lock(&state->lock);
414+ ret = scd30_command_read(state, CMD_FRC, &val);
415+ mutex_unlock(&state->lock);
416+
417+ return ret ?: sprintf(buf, "%d\n", val);
418+}
419+
420+static ssize_t calibration_forced_value_store(struct device *dev, struct device_attribute *attr,
421+ const char *buf, size_t len)
422+{
423+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
424+ struct scd30_state *state = iio_priv(indio_dev);
425+ int ret;
426+ u16 val;
427+
428+ ret = kstrtou16(buf, 0, &val);
429+ if (ret)
430+ return ret;
431+
432+ if (val < SCD30_FRC_MIN_PPM || val > SCD30_FRC_MAX_PPM)
433+ return -EINVAL;
434+
435+ mutex_lock(&state->lock);
436+ ret = scd30_command_write(state, CMD_FRC, val);
437+ mutex_unlock(&state->lock);
438+
439+ return ret ?: len;
440+}
441+
442+static IIO_DEVICE_ATTR_RO(sampling_frequency_available, 0);
443+static IIO_DEVICE_ATTR_RW(calibration_auto_enable, 0);
444+static IIO_DEVICE_ATTR_RW(calibration_forced_value, 0);
445+
446+static struct attribute *scd30_attrs[] = {
447+ &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
448+ &iio_dev_attr_calibration_auto_enable.dev_attr.attr,
449+ &iio_dev_attr_calibration_forced_value.dev_attr.attr,
450+ NULL
451+};
452+
453+static const struct attribute_group scd30_attr_group = {
454+ .attrs = scd30_attrs,
455+};
456+
457+static const struct iio_info scd30_info = {
458+ .attrs = &scd30_attr_group,
459+ .read_raw = scd30_read_raw,
460+ .write_raw = scd30_write_raw,
461+ .write_raw_get_fmt = scd30_write_raw_get_fmt,
462+ .read_avail = scd30_read_avail,
463+};
464+
465+#define SCD30_CHAN_SCAN_TYPE(_sign, _realbits) .scan_type = { \
466+ .sign = _sign, \
467+ .realbits = _realbits, \
468+ .storagebits = 32, \
469+ .endianness = IIO_CPU, \
470+}
471+
472+static const struct iio_chan_spec scd30_channels[] = {
473+ {
474+ /*
475+ * this channel is special in a sense we are pretending that
476+ * sensor is able to change measurement chamber pressure but in
477+ * fact we're just setting pressure compensation value
478+ */
479+ .type = IIO_PRESSURE,
480+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
481+ .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW),
482+ .output = 1,
483+ .scan_index = -1,
484+ },
485+ {
486+ .type = IIO_CONCENTRATION,
487+ .channel2 = IIO_MOD_CO2,
488+ .address = SCD30_CONC,
489+ .scan_index = SCD30_CONC,
490+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
491+ BIT(IIO_CHAN_INFO_SCALE),
492+ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
493+ .modified = 1,
494+
495+ SCD30_CHAN_SCAN_TYPE('u', 20),
496+ },
497+ {
498+ .type = IIO_TEMP,
499+ .address = SCD30_TEMP,
500+ .scan_index = SCD30_TEMP,
501+ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
502+ BIT(IIO_CHAN_INFO_CALIBBIAS),
503+ .info_mask_separate_available = BIT(IIO_CHAN_INFO_CALIBBIAS),
504+ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
505+
506+ SCD30_CHAN_SCAN_TYPE('s', 18),
507+ },
508+ {
509+ .type = IIO_HUMIDITYRELATIVE,
510+ .address = SCD30_HR,
511+ .scan_index = SCD30_HR,
512+ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
513+ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
514+
515+ SCD30_CHAN_SCAN_TYPE('u', 17),
516+ },
517+ IIO_CHAN_SOFT_TIMESTAMP(3),
518+};
519+
520+int __maybe_unused scd30_suspend(struct device *dev)
521+{
522+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
523+ struct scd30_state *state = iio_priv(indio_dev);
524+ int ret;
525+
526+ ret = scd30_command_write(state, CMD_STOP_MEAS, 0);
527+ if (ret)
528+ return ret;
529+
530+ return regulator_disable(state->vdd);
531+}
532+EXPORT_SYMBOL(scd30_suspend);
533+
534+int __maybe_unused scd30_resume(struct device *dev)
535+{
536+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
537+ struct scd30_state *state = iio_priv(indio_dev);
538+ int ret;
539+
540+ ret = regulator_enable(state->vdd);
541+ if (ret)
542+ return ret;
543+
544+ return scd30_command_write(state, CMD_START_MEAS, state->pressure_comp);
545+}
546+EXPORT_SYMBOL(scd30_resume);
547+
548+static void scd30_stop_meas(void *data)
549+{
550+ struct scd30_state *state = data;
551+
552+ scd30_command_write(state, CMD_STOP_MEAS, 0);
553+}
554+
555+static void scd30_disable_regulator(void *data)
556+{
557+ struct scd30_state *state = data;
558+
559+ regulator_disable(state->vdd);
560+}
561+
562+static irqreturn_t scd30_irq_handler(int irq, void *priv)
563+{
564+ struct iio_dev *indio_dev = priv;
565+
566+ if (iio_buffer_enabled(indio_dev)) {
567+ iio_trigger_poll(indio_dev->trig);
568+
569+ return IRQ_HANDLED;
570+ }
571+
572+ return IRQ_WAKE_THREAD;
573+}
574+
575+static irqreturn_t scd30_irq_thread_handler(int irq, void *priv)
576+{
577+ struct iio_dev *indio_dev = priv;
578+ struct scd30_state *state = iio_priv(indio_dev);
579+ int ret;
580+
581+ ret = scd30_read_meas(state);
582+ if (ret)
583+ goto out;
584+
585+ complete_all(&state->meas_ready);
586+out:
587+ return IRQ_HANDLED;
588+}
589+
590+static irqreturn_t scd30_trigger_handler(int irq, void *p)
591+{
592+ struct iio_poll_func *pf = p;
593+ struct iio_dev *indio_dev = pf->indio_dev;
594+ struct scd30_state *state = iio_priv(indio_dev);
595+ struct {
596+ int data[SCD30_MEAS_COUNT];
597+ s64 ts __aligned(8);
598+ } scan;
599+ int ret;
600+
601+ mutex_lock(&state->lock);
602+ if (!iio_trigger_using_own(indio_dev))
603+ ret = scd30_read_poll(state);
604+ else
605+ ret = scd30_read_meas(state);
606+ memset(&scan, 0, sizeof(scan));
607+ memcpy(scan.data, state->meas, sizeof(state->meas));
608+ mutex_unlock(&state->lock);
609+ if (ret)
610+ goto out;
611+
612+ iio_push_to_buffers_with_timestamp(indio_dev, &scan, iio_get_time_ns(indio_dev));
613+out:
614+ iio_trigger_notify_done(indio_dev->trig);
615+ return IRQ_HANDLED;
616+}
617+
618+static int scd30_set_trigger_state(struct iio_trigger *trig, bool state)
619+{
620+ struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
621+ struct scd30_state *st = iio_priv(indio_dev);
622+
623+ if (state)
624+ enable_irq(st->irq);
625+ else
626+ disable_irq(st->irq);
627+
628+ return 0;
629+}
630+
631+static const struct iio_trigger_ops scd30_trigger_ops = {
632+ .set_trigger_state = scd30_set_trigger_state,
633+ .validate_device = iio_trigger_validate_own_device,
634+};
635+
636+static int scd30_setup_trigger(struct iio_dev *indio_dev)
637+{
638+ struct scd30_state *state = iio_priv(indio_dev);
639+ struct device *dev = indio_dev->dev.parent;
640+ struct iio_trigger *trig;
641+ int ret;
642+
643+ trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id);
644+ if (!trig) {
645+ dev_err(dev, "failed to allocate trigger\n");
646+ return -ENOMEM;
647+ }
648+
649+ trig->dev.parent = dev;
650+ trig->ops = &scd30_trigger_ops;
651+ iio_trigger_set_drvdata(trig, indio_dev);
652+
653+ ret = devm_iio_trigger_register(dev, trig);
654+ if (ret)
655+ return ret;
656+
657+ indio_dev->trig = iio_trigger_get(trig);
658+
659+ ret = devm_request_threaded_irq(dev, state->irq, scd30_irq_handler,
660+ scd30_irq_thread_handler, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
661+ indio_dev->name, indio_dev);
662+ if (ret)
663+ dev_err(dev, "failed to request irq\n");
664+
665+ /*
666+ * Interrupt is enabled just before taking a fresh measurement
667+ * and disabled afterwards. This means we need to disable it here
668+ * to keep calls to enable/disable balanced.
669+ */
670+ disable_irq(state->irq);
671+
672+ return ret;
673+}
674+
675+int scd30_probe(struct device *dev, int irq, const char *name, void *priv,
676+ scd30_command_t command)
677+{
678+ static const unsigned long scd30_scan_masks[] = { 0x07, 0x00 };
679+ struct scd30_state *state;
680+ struct iio_dev *indio_dev;
681+ int ret;
682+ u16 val;
683+
684+ indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
685+ if (!indio_dev)
686+ return -ENOMEM;
687+
688+ state = iio_priv(indio_dev);
689+ state->dev = dev;
690+ state->priv = priv;
691+ state->irq = irq;
692+ state->pressure_comp = SCD30_PRESSURE_COMP_DEFAULT;
693+ state->meas_interval = SCD30_MEAS_INTERVAL_DEFAULT;
694+ state->command = command;
695+ mutex_init(&state->lock);
696+ init_completion(&state->meas_ready);
697+
698+ dev_set_drvdata(dev, indio_dev);
699+
700+ indio_dev->info = &scd30_info;
701+ indio_dev->name = name;
702+ indio_dev->channels = scd30_channels;
703+ indio_dev->num_channels = ARRAY_SIZE(scd30_channels);
704+ indio_dev->modes = INDIO_DIRECT_MODE;
705+ indio_dev->available_scan_masks = scd30_scan_masks;
706+
707+ state->vdd = devm_regulator_get(dev, "vdd");
708+ if (IS_ERR(state->vdd)) {
709+ if (PTR_ERR(state->vdd) == -EPROBE_DEFER)
710+ return -EPROBE_DEFER;
711+
712+ dev_err(dev, "failed to get regulator\n");
713+ return PTR_ERR(state->vdd);
714+ }
715+
716+ ret = regulator_enable(state->vdd);
717+ if (ret)
718+ return ret;
719+
720+ ret = devm_add_action_or_reset(dev, scd30_disable_regulator, state);
721+ if (ret)
722+ return ret;
723+
724+ ret = scd30_reset(state);
725+ if (ret) {
726+ dev_err(dev, "failed to reset device: %d\n", ret);
727+ return ret;
728+ }
729+
730+ if (state->irq > 0) {
731+ ret = scd30_setup_trigger(indio_dev);
732+ if (ret) {
733+ dev_err(dev, "failed to setup trigger: %d\n", ret);
734+ return ret;
735+ }
736+ }
737+
738+ ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, scd30_trigger_handler, NULL);
739+ if (ret)
740+ return ret;
741+
742+ ret = scd30_command_read(state, CMD_FW_VERSION, &val);
743+ if (ret) {
744+ dev_err(dev, "failed to read firmware version: %d\n", ret);
745+ return ret;
746+ }
747+ dev_info(dev, "firmware version: %d.%d\n", val >> 8, (char)val);
748+
749+ ret = scd30_command_write(state, CMD_MEAS_INTERVAL, state->meas_interval);
750+ if (ret) {
751+ dev_err(dev, "failed to set measurement interval: %d\n", ret);
752+ return ret;
753+ }
754+
755+ ret = scd30_command_write(state, CMD_START_MEAS, state->pressure_comp);
756+ if (ret) {
757+ dev_err(dev, "failed to start measurement: %d\n", ret);
758+ return ret;
759+ }
760+
761+ ret = devm_add_action_or_reset(dev, scd30_stop_meas, state);
762+ if (ret)
763+ return ret;
764+
765+ return devm_iio_device_register(dev, indio_dev);
766+}
767+EXPORT_SYMBOL(scd30_probe);
768+
769+MODULE_AUTHOR("Tomasz Duszynski <tomasz.duszynski@octakon.com>");
770+MODULE_DESCRIPTION("Sensirion SCD30 carbon dioxide sensor core driver");
771+MODULE_LICENSE("GPL v2");
drivers/iio/chemical/scd30_i2c.c+139−0
@@ -0,0 +1,139 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/*
3+ * Sensirion SCD30 carbon dioxide sensor i2c driver
4+ *
5+ * Copyright (c) 2020 Tomasz Duszynski <tomasz.duszynski@octakon.com>
6+ *
7+ * I2C slave address: 0x61
8+ */
9+#include <linux/crc8.h>
10+#include <linux/device.h>
11+#include <linux/errno.h>
12+#include <linux/i2c.h>
13+#include <linux/mod_devicetable.h>
14+#include <linux/module.h>
15+#include <linux/types.h>
16+#include <asm/unaligned.h>
17+
18+#include "scd30.h"
19+
20+#define SCD30_I2C_MAX_BUF_SIZE 18
21+#define SCD30_I2C_CRC8_POLYNOMIAL 0x31
22+
23+static u16 scd30_i2c_cmd_lookup_tbl[] = {
24+ [CMD_START_MEAS] = 0x0010,
25+ [CMD_STOP_MEAS] = 0x0104,
26+ [CMD_MEAS_INTERVAL] = 0x4600,
27+ [CMD_MEAS_READY] = 0x0202,
28+ [CMD_READ_MEAS] = 0x0300,
29+ [CMD_ASC] = 0x5306,
30+ [CMD_FRC] = 0x5204,
31+ [CMD_TEMP_OFFSET] = 0x5403,
32+ [CMD_FW_VERSION] = 0xd100,
33+ [CMD_RESET] = 0xd304,
34+};
35+
36+DECLARE_CRC8_TABLE(scd30_i2c_crc8_tbl);
37+
38+static int scd30_i2c_xfer(struct scd30_state *state, char *txbuf, int txsize,
39+ char *rxbuf, int rxsize)
40+{
41+ struct i2c_client *client = to_i2c_client(state->dev);
42+ int ret;
43+
44+ /*
45+ * repeated start is not supported hence instead of sending two i2c
46+ * messages in a row we send one by one
47+ */
48+ ret = i2c_master_send(client, txbuf, txsize);
49+ if (ret < 0)
50+ return ret;
51+ if (ret != txsize)
52+ return -EIO;
53+
54+ if (!rxbuf)
55+ return 0;
56+
57+ ret = i2c_master_recv(client, rxbuf, rxsize);
58+ if (ret < 0)
59+ return ret;
60+ if (ret != rxsize)
61+ return -EIO;
62+
63+ return 0;
64+}
65+
66+static int scd30_i2c_command(struct scd30_state *state, enum scd30_cmd cmd, u16 arg,
67+ void *response, int size)
68+{
69+ char buf[SCD30_I2C_MAX_BUF_SIZE];
70+ char *rsp = response;
71+ int i, ret;
72+ char crc;
73+
74+ put_unaligned_be16(scd30_i2c_cmd_lookup_tbl[cmd], buf);
75+ i = 2;
76+
77+ if (rsp) {
78+ /* each two bytes are followed by a crc8 */
79+ size += size / 2;
80+ } else {
81+ put_unaligned_be16(arg, buf + i);
82+ crc = crc8(scd30_i2c_crc8_tbl, buf + i, 2, CRC8_INIT_VALUE);
83+ i += 2;
84+ buf[i] = crc;
85+ i += 1;
86+
87+ /* commands below don't take an argument */
88+ if ((cmd == CMD_STOP_MEAS) || (cmd == CMD_RESET))
89+ i -= 3;
90+ }
91+
92+ ret = scd30_i2c_xfer(state, buf, i, buf, size);
93+ if (ret)
94+ return ret;
95+
96+ /* validate received data and strip off crc bytes */
97+ for (i = 0; i < size; i += 3) {
98+ crc = crc8(scd30_i2c_crc8_tbl, buf + i, 2, CRC8_INIT_VALUE);
99+ if (crc != buf[i + 2]) {
100+ dev_err(state->dev, "data integrity check failed\n");
101+ return -EIO;
102+ }
103+
104+ *rsp++ = buf[i];
105+ *rsp++ = buf[i + 1];
106+ }
107+
108+ return 0;
109+}
110+
111+static int scd30_i2c_probe(struct i2c_client *client)
112+{
113+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
114+ return -EOPNOTSUPP;
115+
116+ crc8_populate_msb(scd30_i2c_crc8_tbl, SCD30_I2C_CRC8_POLYNOMIAL);
117+
118+ return scd30_probe(&client->dev, client->irq, client->name, NULL, scd30_i2c_command);
119+}
120+
121+static const struct of_device_id scd30_i2c_of_match[] = {
122+ { .compatible = "sensirion,scd30" },
123+ { }
124+};
125+MODULE_DEVICE_TABLE(of, scd30_i2c_of_match);
126+
127+static struct i2c_driver scd30_i2c_driver = {
128+ .driver = {
129+ .name = KBUILD_MODNAME,
130+ .of_match_table = scd30_i2c_of_match,
131+ .pm = &scd30_pm_ops,
132+ },
133+ .probe_new = scd30_i2c_probe,
134+};
135+module_i2c_driver(scd30_i2c_driver);
136+
137+MODULE_AUTHOR("Tomasz Duszynski <tomasz.duszynski@octakon.com>");
138+MODULE_DESCRIPTION("Sensirion SCD30 carbon dioxide sensor i2c driver");
139+MODULE_LICENSE("GPL v2");
drivers/iio/chemical/scd30_serial.c+263−0
@@ -0,0 +1,263 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/*
3+ * Sensirion SCD30 carbon dioxide sensor serial driver
4+ *
5+ * Copyright (c) 2020 Tomasz Duszynski <tomasz.duszynski@octakon.com>
6+ */
7+#include <linux/crc16.h>
8+#include <linux/device.h>
9+#include <linux/errno.h>
10+#include <linux/iio/iio.h>
11+#include <linux/jiffies.h>
12+#include <linux/mod_devicetable.h>
13+#include <linux/module.h>
14+#include <linux/property.h>
15+#include <linux/serdev.h>
16+#include <linux/string.h>
17+#include <linux/types.h>
18+#include <asm/unaligned.h>
19+
20+#include "scd30.h"
21+
22+#define SCD30_SERDEV_ADDR 0x61
23+#define SCD30_SERDEV_WRITE 0x06
24+#define SCD30_SERDEV_READ 0x03
25+#define SCD30_SERDEV_MAX_BUF_SIZE 17
26+#define SCD30_SERDEV_RX_HEADER_SIZE 3
27+#define SCD30_SERDEV_CRC_SIZE 2
28+#define SCD30_SERDEV_TIMEOUT msecs_to_jiffies(200)
29+
30+struct scd30_serdev_priv {
31+ struct completion meas_ready;
32+ char *buf;
33+ int num_expected;
34+ int num;
35+};
36+
37+static u16 scd30_serdev_cmd_lookup_tbl[] = {
38+ [CMD_START_MEAS] = 0x0036,
39+ [CMD_STOP_MEAS] = 0x0037,
40+ [CMD_MEAS_INTERVAL] = 0x0025,
41+ [CMD_MEAS_READY] = 0x0027,
42+ [CMD_READ_MEAS] = 0x0028,
43+ [CMD_ASC] = 0x003a,
44+ [CMD_FRC] = 0x0039,
45+ [CMD_TEMP_OFFSET] = 0x003b,
46+ [CMD_FW_VERSION] = 0x0020,
47+ [CMD_RESET] = 0x0034,
48+};
49+
50+static u16 scd30_serdev_calc_crc(const char *buf, int size)
51+{
52+ return crc16(0xffff, buf, size);
53+}
54+
55+static int scd30_serdev_xfer(struct scd30_state *state, char *txbuf, int txsize,
56+ char *rxbuf, int rxsize)
57+{
58+ struct serdev_device *serdev = to_serdev_device(state->dev);
59+ struct scd30_serdev_priv *priv = state->priv;
60+ int ret;
61+
62+ priv->buf = rxbuf;
63+ priv->num_expected = rxsize;
64+ priv->num = 0;
65+
66+ ret = serdev_device_write(serdev, txbuf, txsize, SCD30_SERDEV_TIMEOUT);
67+ if (ret < 0)
68+ return ret;
69+ if (ret != txsize)
70+ return -EIO;
71+
72+ ret = wait_for_completion_interruptible_timeout(&priv->meas_ready, SCD30_SERDEV_TIMEOUT);
73+ if (ret < 0)
74+ return ret;
75+ if (!ret)
76+ return -ETIMEDOUT;
77+
78+ return 0;
79+}
80+
81+static int scd30_serdev_command(struct scd30_state *state, enum scd30_cmd cmd, u16 arg,
82+ void *response, int size)
83+{
84+ /*
85+ * Communication over serial line is based on modbus protocol (or rather
86+ * its variation called modbus over serial to be precise). Upon
87+ * receiving a request device should reply with response.
88+ *
89+ * Frame below represents a request message. Each field takes
90+ * exactly one byte.
91+ *
92+ * +------+------+-----+-----+-------+-------+-----+-----+
93+ * | dev | op | reg | reg | byte1 | byte0 | crc | crc |
94+ * | addr | code | msb | lsb | | | lsb | msb |
95+ * +------+------+-----+-----+-------+-------+-----+-----+
96+ *
97+ * The message device replies with depends on the 'op code' field from
98+ * the request. In case it was set to SCD30_SERDEV_WRITE sensor should
99+ * reply with unchanged request. Otherwise 'op code' was set to
100+ * SCD30_SERDEV_READ and response looks like the one below. As with
101+ * request, each field takes one byte.
102+ *
103+ * +------+------+--------+-------+-----+-------+-----+-----+
104+ * | dev | op | num of | byte0 | ... | byteN | crc | crc |
105+ * | addr | code | bytes | | | | lsb | msb |
106+ * +------+------+--------+-------+-----+-------+-----+-----+
107+ */
108+ char txbuf[SCD30_SERDEV_MAX_BUF_SIZE] = { SCD30_SERDEV_ADDR },
109+ rxbuf[SCD30_SERDEV_MAX_BUF_SIZE];
110+ int ret, rxsize, txsize = 2;
111+ char *rsp = response;
112+ u16 crc;
113+
114+ put_unaligned_be16(scd30_serdev_cmd_lookup_tbl[cmd], txbuf + txsize);
115+ txsize += 2;
116+
117+ if (rsp) {
118+ txbuf[1] = SCD30_SERDEV_READ;
119+ if (cmd == CMD_READ_MEAS)
120+ /* number of u16 words to read */
121+ put_unaligned_be16(size / 2, txbuf + txsize);
122+ else
123+ put_unaligned_be16(0x0001, txbuf + txsize);
124+ txsize += 2;
125+ crc = scd30_serdev_calc_crc(txbuf, txsize);
126+ put_unaligned_le16(crc, txbuf + txsize);
127+ txsize += 2;
128+ rxsize = SCD30_SERDEV_RX_HEADER_SIZE + size + SCD30_SERDEV_CRC_SIZE;
129+ } else {
130+ if ((cmd == CMD_STOP_MEAS) || (cmd == CMD_RESET))
131+ arg = 0x0001;
132+
133+ txbuf[1] = SCD30_SERDEV_WRITE;
134+ put_unaligned_be16(arg, txbuf + txsize);
135+ txsize += 2;
136+ crc = scd30_serdev_calc_crc(txbuf, txsize);
137+ put_unaligned_le16(crc, txbuf + txsize);
138+ txsize += 2;
139+ rxsize = txsize;
140+ }
141+
142+ ret = scd30_serdev_xfer(state, txbuf, txsize, rxbuf, rxsize);
143+ if (ret)
144+ return ret;
145+
146+ switch (txbuf[1]) {
147+ case SCD30_SERDEV_WRITE:
148+ if (memcmp(txbuf, rxbuf, txsize)) {
149+ dev_err(state->dev, "wrong message received\n");
150+ return -EIO;
151+ }
152+ break;
153+ case SCD30_SERDEV_READ:
154+ if (rxbuf[2] != (rxsize - SCD30_SERDEV_RX_HEADER_SIZE - SCD30_SERDEV_CRC_SIZE)) {
155+ dev_err(state->dev, "received data size does not match header\n");
156+ return -EIO;
157+ }
158+
159+ rxsize -= SCD30_SERDEV_CRC_SIZE;
160+ crc = get_unaligned_le16(rxbuf + rxsize);
161+ if (crc != scd30_serdev_calc_crc(rxbuf, rxsize)) {
162+ dev_err(state->dev, "data integrity check failed\n");
163+ return -EIO;
164+ }
165+
166+ rxsize -= SCD30_SERDEV_RX_HEADER_SIZE;
167+ memcpy(rsp, rxbuf + SCD30_SERDEV_RX_HEADER_SIZE, rxsize);
168+ break;
169+ default:
170+ dev_err(state->dev, "received unknown op code\n");
171+ return -EIO;
172+ }
173+
174+ return 0;
175+}
176+
177+static int scd30_serdev_receive_buf(struct serdev_device *serdev,
178+ const unsigned char *buf, size_t size)
179+{
180+ struct iio_dev *indio_dev = dev_get_drvdata(&serdev->dev);
181+ struct scd30_serdev_priv *priv;
182+ struct scd30_state *state;
183+ int num;
184+
185+ if (!indio_dev)
186+ return 0;
187+
188+ state = iio_priv(indio_dev);
189+ priv = state->priv;
190+
191+ /* just in case sensor puts some unexpected bytes on the bus */
192+ if (!priv->buf)
193+ return 0;
194+
195+ if (priv->num + size >= priv->num_expected)
196+ num = priv->num_expected - priv->num;
197+ else
198+ num = size;
199+
200+ memcpy(priv->buf + priv->num, buf, num);
201+ priv->num += num;
202+
203+ if (priv->num == priv->num_expected) {
204+ priv->buf = NULL;
205+ complete(&priv->meas_ready);
206+ }
207+
208+ return num;
209+}
210+
211+static const struct serdev_device_ops scd30_serdev_ops = {
212+ .receive_buf = scd30_serdev_receive_buf,
213+ .write_wakeup = serdev_device_write_wakeup,
214+};
215+
216+static int scd30_serdev_probe(struct serdev_device *serdev)
217+{
218+ struct device *dev = &serdev->dev;
219+ struct scd30_serdev_priv *priv;
220+ int irq, ret;
221+
222+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
223+ if (!priv)
224+ return -ENOMEM;
225+
226+ init_completion(&priv->meas_ready);
227+ serdev_device_set_client_ops(serdev, &scd30_serdev_ops);
228+
229+ ret = devm_serdev_device_open(dev, serdev);
230+ if (ret)
231+ return ret;
232+
233+ serdev_device_set_baudrate(serdev, 19200);
234+ serdev_device_set_flow_control(serdev, false);
235+
236+ ret = serdev_device_set_parity(serdev, SERDEV_PARITY_NONE);
237+ if (ret)
238+ return ret;
239+
240+ irq = fwnode_irq_get(dev_fwnode(dev), 0);
241+
242+ return scd30_probe(dev, irq, KBUILD_MODNAME, priv, scd30_serdev_command);
243+}
244+
245+static const struct of_device_id scd30_serdev_of_match[] = {
246+ { .compatible = "sensirion,scd30" },
247+ { }
248+};
249+MODULE_DEVICE_TABLE(of, scd30_serdev_of_match);
250+
251+static struct serdev_device_driver scd30_serdev_driver = {
252+ .driver = {
253+ .name = KBUILD_MODNAME,
254+ .of_match_table = scd30_serdev_of_match,
255+ .pm = &scd30_pm_ops,
256+ },
257+ .probe = scd30_serdev_probe,
258+};
259+module_serdev_device_driver(scd30_serdev_driver);
260+
261+MODULE_AUTHOR("Tomasz Duszynski <tomasz.duszynski@octakon.com>");
262+MODULE_DESCRIPTION("Sensirion SCD30 carbon dioxide sensor serial driver");
263+MODULE_LICENSE("GPL v2");
drivers/iio/chemical/sgp30.c+0−1
@@ -533,7 +533,6 @@ static int sgp_probe(struct i2c_client *client, · 532 unmodified lines
533533 if (ret)
534534 return ret;
535535
536− indio_dev->dev.parent = &client->dev;
537536 indio_dev->info = &sgp_info;
538537 indio_dev->name = id->name;
539538 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/chemical/sps30.c+0−1
@@ -487,7 +487,6 @@ static int sps30_probe(struct i2c_client *client) · 486 unmodified lines
487487 i2c_set_clientdata(client, indio_dev);
488488 state->client = client;
489489 state->state = RESET;
490− indio_dev->dev.parent = &client->dev;
491490 indio_dev->info = &sps30_info;
492491 indio_dev->name = client->name;
493492 indio_dev->channels = sps30_channels;
drivers/iio/chemical/vz89x.c+0−1
@@ -382,7 +382,6 @@ static int vz89x_probe(struct i2c_client *client, · 381 unmodified lines
382382 data->last_update = jiffies - HZ;
383383 mutex_init(&data->lock);
384384
385− indio_dev->dev.parent = &client->dev;
386385 indio_dev->info = &vz89x_info;
387386 indio_dev->name = dev_name(&client->dev);
388387 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c+5−0
@@ -200,6 +200,10 @@ static int cros_ec_sensors_write(struct iio_dev *indio_dev, · 199 unmodified lines
200200 st->core.param.sensor_range.roundup = 1;
201201
202202 ret = cros_ec_motion_send_host_cmd(&st->core, 0);
203+ if (ret == 0) {
204+ st->core.range_updated = true;
205+ st->core.curr_range = val;
206+ }
203207 break;
204208 default:
205209 ret = cros_ec_sensors_core_write(
@@ -315,6 +319,7 @@ MODULE_DEVICE_TABLE(platform, cros_ec_sensors_ids); · 109 unmodified lines
315319 static struct platform_driver cros_ec_sensors_platform_driver = {
316320 .driver = {
317321 .name = "cros-ec-sensors",
322+ .pm = &cros_ec_sensors_pm_ops,
318323 },
319324 .probe = cros_ec_sensors_probe,
320325 .id_table = cros_ec_sensors_ids,
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c+22−2
@@ -281,7 +281,6 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, · 280 unmodified lines
281281 state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
282282 state->msg->outsize = sizeof(struct ec_params_motion_sense);
283283
284− indio_dev->dev.parent = &pdev->dev;
285284 indio_dev->name = pdev->name;
286285
287286 if (physical_device) {
@@ -352,7 +351,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, · 64 unmodified lines
352351 } else {
353352 /*
354353 * The only way to get samples in buffer is to set a
355− * software tigger (systrig, hrtimer).
354+ * software trigger (systrig, hrtimer).
356355 */
357356 ret = devm_iio_triggered_buffer_setup(
358357 dev, indio_dev, NULL, trigger_capture,
@@ -824,5 +823,26 @@ int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st, · 465 unmodified lines
824823 }
825824 EXPORT_SYMBOL_GPL(cros_ec_sensors_core_write);
826825
826+static int __maybe_unused cros_ec_sensors_resume(struct device *dev)
827+{
828+ struct platform_device *pdev = to_platform_device(dev);
829+ struct iio_dev *indio_dev = platform_get_drvdata(pdev);
830+ struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
831+ int ret = 0;
832+
833+ if (st->range_updated) {
834+ mutex_lock(&st->cmd_lock);
835+ st->param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
836+ st->param.sensor_range.data = st->curr_range;
837+ st->param.sensor_range.roundup = 1;
838+ ret = cros_ec_motion_send_host_cmd(st, 0);
839+ mutex_unlock(&st->cmd_lock);
840+ }
841+ return ret;
842+}
843+
844+SIMPLE_DEV_PM_OPS(cros_ec_sensors_pm_ops, NULL, cros_ec_sensors_resume);
845+EXPORT_SYMBOL_GPL(cros_ec_sensors_pm_ops);
846+
827847 MODULE_DESCRIPTION("ChromeOS EC sensor hub core functions");
828848 MODULE_LICENSE("GPL v2");
drivers/iio/common/st_sensors/st_sensors_i2c.c+0−1
@@ -56,7 +56,6 @@ int st_sensors_i2c_configure(struct iio_dev *indio_dev, · 55 unmodified lines
5656
5757 i2c_set_clientdata(client, indio_dev);
5858
59− indio_dev->dev.parent = &client->dev;
6059 indio_dev->name = client->name;
6160
6261 sdata->dev = &client->dev;
drivers/iio/common/st_sensors/st_sensors_spi.c+0−1
@@ -108,7 +108,6 @@ int st_sensors_spi_configure(struct iio_dev *indio_dev, · 107 unmodified lines
108108
109109 spi_set_drvdata(spi, indio_dev);
110110
111− indio_dev->dev.parent = &spi->dev;
112111 indio_dev->name = spi->modalias;
113112
114113 sdata->dev = &spi->dev;
drivers/iio/dac/ad5064.c+0−1
@@ -874,7 +874,6 @@ static int ad5064_probe(struct device *dev, enum ad5064_type type, · 873 unmodified lines
874874 return ret;
875875 }
876876
877− indio_dev->dev.parent = dev;
878877 indio_dev->name = name;
879878 indio_dev->info = &ad5064_info;
880879 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad5360.c+0−1
@@ -476,7 +476,6 @@ static int ad5360_probe(struct spi_device *spi) · 475 unmodified lines
476476 st->chip_info = &ad5360_chip_info_tbl[type];
477477 st->spi = spi;
478478
479− indio_dev->dev.parent = &spi->dev;
480479 indio_dev->name = spi_get_device_id(spi)->name;
481480 indio_dev->info = &ad5360_info;
482481 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad5380.c+1−2
@@ -240,7 +240,7 @@ static const struct iio_info ad5380_info = { · 239 unmodified lines
240240 .write_raw = ad5380_write_raw,
241241 };
242242
243−static struct iio_chan_spec_ext_info ad5380_ext_info[] = {
243+static const struct iio_chan_spec_ext_info ad5380_ext_info[] = {
244244 {
245245 .name = "powerdown",
246246 .read = ad5380_read_dac_powerdown,
@@ -386,7 +386,6 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap, · 139 unmodified lines
386386 st->chip_info = &ad5380_chip_info_tbl[type];
387387 st->regmap = regmap;
388388
389− indio_dev->dev.parent = dev;
390389 indio_dev->name = name;
391390 indio_dev->info = &ad5380_info;
392391 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad5421.c+0−1
@@ -487,7 +487,6 @@ static int ad5421_probe(struct spi_device *spi) · 486 unmodified lines
487487
488488 st->spi = spi;
489489
490− indio_dev->dev.parent = &spi->dev;
491490 indio_dev->name = "ad5421";
492491 indio_dev->info = &ad5421_info;
493492 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad5446.c+0−2
@@ -250,8 +250,6 @@ static int ad5446_probe(struct device *dev, const char *name, · 249 unmodified lines
250250 st->reg = reg;
251251 st->dev = dev;
252252
253− /* Establish that the iio_dev is a child of the device */
254− indio_dev->dev.parent = dev;
255253 indio_dev->name = name;
256254 indio_dev->info = &ad5446_info;
257255 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad5449.c+0−1
@@ -297,7 +297,6 @@ static int ad5449_spi_probe(struct spi_device *spi) · 296 unmodified lines
297297 if (ret)
298298 return ret;
299299
300− indio_dev->dev.parent = &spi->dev;
301300 indio_dev->name = id->name;
302301 indio_dev->info = &ad5449_info;
303302 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad5504.c+0−1
@@ -304,7 +304,6 @@ static int ad5504_probe(struct spi_device *spi) · 303 unmodified lines
304304
305305 st->reg = reg;
306306 st->spi = spi;
307− indio_dev->dev.parent = &spi->dev;
308307 indio_dev->name = spi_get_device_id(st->spi)->name;
309308 indio_dev->info = &ad5504_info;
310309 if (spi_get_device_id(st->spi)->driver_data == ID_AD5501)
drivers/iio/dac/ad5592r-base.c+4−5
@@ -484,7 +484,7 @@ static ssize_t ad5592r_show_scale_available(struct iio_dev *iio_dev, · 483 unmodified lines
484484 st->scale_avail[1][0], st->scale_avail[1][1]);
485485 }
486486
487−static struct iio_chan_spec_ext_info ad5592r_ext_info[] = {
487+static const struct iio_chan_spec_ext_info ad5592r_ext_info[] = {
488488 {
489489 .name = "scale_available",
490490 .read = ad5592r_show_scale_available,
@@ -508,11 +508,11 @@ static void ad5592r_setup_channel(struct iio_dev *iio_dev, · 17 unmodified lines
508508 chan->ext_info = ad5592r_ext_info;
509509 }
510510
511−static int ad5592r_alloc_channels(struct ad5592r_state *st)
511+static int ad5592r_alloc_channels(struct iio_dev *iio_dev)
512512 {
513+ struct ad5592r_state *st = iio_priv(iio_dev);
513514 unsigned i, curr_channel = 0,
514515 num_channels = st->num_channels;
515− struct iio_dev *iio_dev = iio_priv_to_dev(st);
516516 struct iio_chan_spec *channels;
517517 struct fwnode_handle *child;
518518 u32 reg, tmp;
@@ -618,7 +618,6 @@ int ad5592r_probe(struct device *dev, const char *name, · 99 unmodified lines
618618 return ret;
619619 }
620620
621− iio_dev->dev.parent = dev;
622621 iio_dev->name = name;
623622 iio_dev->info = &ad5592r_info;
624623 iio_dev->modes = INDIO_DIRECT_MODE;
@@ -636,7 +635,7 @@ int ad5592r_probe(struct device *dev, const char *name, · 11 unmodified lines
636635 if (ret)
637636 goto error_disable_reg;
638637
639− ret = ad5592r_alloc_channels(st);
638+ ret = ad5592r_alloc_channels(iio_dev);
640639 if (ret)
641640 goto error_disable_reg;
642641
drivers/iio/dac/ad5624r_spi.c+0−1
@@ -253,7 +253,6 @@ static int ad5624r_probe(struct spi_device *spi) · 252 unmodified lines
253253
254254 st->us = spi;
255255
256− indio_dev->dev.parent = &spi->dev;
257256 indio_dev->name = spi_get_device_id(spi)->name;
258257 indio_dev->info = &ad5624r_info;
259258 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad5686.c+0−1
@@ -461,7 +461,6 @@ int ad5686_probe(struct device *dev, · 460 unmodified lines
461461 for (i = 0; i < st->chip_info->num_channels; i++)
462462 st->pwr_down_mode |= (0x01 << (i * 2));
463463
464− indio_dev->dev.parent = dev;
465464 indio_dev->name = name;
466465 indio_dev->info = &ad5686_info;
467466 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad5755.c+0−1
@@ -744,7 +744,6 @@ static int ad5755_probe(struct spi_device *spi) · 743 unmodified lines
744744 st->spi = spi;
745745 st->pwr_down = 0xf;
746746
747− indio_dev->dev.parent = &spi->dev;
748747 indio_dev->name = spi_get_device_id(spi)->name;
749748 indio_dev->info = &ad5755_info;
750749 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad5758.c+0−1
@@ -854,7 +854,6 @@ static int ad5758_probe(struct spi_device *spi) · 853 unmodified lines
854854
855855 mutex_init(&st->lock);
856856
857− indio_dev->dev.parent = &spi->dev;
858857 indio_dev->name = spi_get_device_id(spi)->name;
859858 indio_dev->info = &ad5758_info;
860859 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad5761.c+0−1
@@ -376,7 +376,6 @@ static int ad5761_probe(struct spi_device *spi) · 375 unmodified lines
376376 if (ret)
377377 goto disable_regulator_err;
378378
379− iio_dev->dev.parent = &spi->dev;
380379 iio_dev->info = &ad5761_info;
381380 iio_dev->modes = INDIO_DIRECT_MODE;
382381 iio_dev->channels = &chip_info->channel;
drivers/iio/dac/ad5764.c+0−1
@@ -290,7 +290,6 @@ static int ad5764_probe(struct spi_device *spi) · 289 unmodified lines
290290 st->spi = spi;
291291 st->chip_info = &ad5764_chip_infos[type];
292292
293− indio_dev->dev.parent = &spi->dev;
294293 indio_dev->name = spi_get_device_id(spi)->name;
295294 indio_dev->info = &ad5764_info;
296295 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad5770r.c+0−1
@@ -651,7 +651,6 @@ static int ad5770r_probe(struct spi_device *spi) · 650 unmodified lines
651651 }
652652 }
653653
654− indio_dev->dev.parent = &spi->dev;
655654 indio_dev->name = spi_get_device_id(spi)->name;
656655 indio_dev->info = &ad5770r_info;
657656 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad5791.c+0−1
@@ -409,7 +409,6 @@ static int ad5791_probe(struct spi_device *spi) · 408 unmodified lines
409409 goto error_disable_reg_neg;
410410
411411 spi_set_drvdata(spi, indio_dev);
412− indio_dev->dev.parent = &spi->dev;
413412 indio_dev->info = &ad5791_info;
414413 indio_dev->modes = INDIO_DIRECT_MODE;
415414 indio_dev->channels
drivers/iio/dac/ad7303.c+0−1
@@ -238,7 +238,6 @@ static int ad7303_probe(struct spi_device *spi) · 237 unmodified lines
238238 st->config |= AD7303_CFG_EXTERNAL_VREF;
239239 }
240240
241− indio_dev->dev.parent = &spi->dev;
242241 indio_dev->name = id->name;
243242 indio_dev->info = &ad7303_info;
244243 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ad8801.c+0−1
@@ -171,7 +171,6 @@ static int ad8801_probe(struct spi_device *spi) · 170 unmodified lines
171171 }
172172
173173 spi_set_drvdata(spi, indio_dev);
174− indio_dev->dev.parent = &spi->dev;
175174 indio_dev->info = &ad8801_info;
176175 indio_dev->modes = INDIO_DIRECT_MODE;
177176 indio_dev->channels = ad8801_channels;
drivers/iio/dac/cio-dac.c+0−1
@@ -110,7 +110,6 @@ static int cio_dac_probe(struct device *dev, unsigned int id) · 109 unmodified lines
110110 indio_dev->channels = cio_dac_channels;
111111 indio_dev->num_channels = CIO_DAC_NUM_CHAN;
112112 indio_dev->name = dev_name(dev);
113− indio_dev->dev.parent = dev;
114113
115114 priv = iio_priv(indio_dev);
116115 priv->base = base[id];
drivers/iio/dac/dpot-dac.c+0−1
@@ -177,7 +177,6 @@ static int dpot_dac_probe(struct platform_device *pdev) · 176 unmodified lines
177177 dac = iio_priv(indio_dev);
178178
179179 indio_dev->name = dev_name(dev);
180− indio_dev->dev.parent = dev;
181180 indio_dev->info = &dpot_dac_info;
182181 indio_dev->modes = INDIO_DIRECT_MODE;
183182 indio_dev->channels = &dpot_dac_iio_channel;
drivers/iio/dac/ds4424.c+0−2
@@ -230,8 +230,6 @@ static int ds4424_probe(struct i2c_client *client, · 229 unmodified lines
230230 i2c_set_clientdata(client, indio_dev);
231231 data->client = client;
232232 indio_dev->name = id->name;
233− indio_dev->dev.of_node = client->dev.of_node;
234− indio_dev->dev.parent = &client->dev;
235233
236234 data->vcc_reg = devm_regulator_get(&client->dev, "vcc");
237235 if (IS_ERR(data->vcc_reg)) {
drivers/iio/dac/lpc18xx_dac.c+0−1
@@ -133,7 +133,6 @@ static int lpc18xx_dac_probe(struct platform_device *pdev) · 132 unmodified lines
133133 }
134134
135135 indio_dev->name = dev_name(&pdev->dev);
136− indio_dev->dev.parent = &pdev->dev;
137136 indio_dev->info = &lpc18xx_dac_info;
138137 indio_dev->modes = INDIO_DIRECT_MODE;
139138 indio_dev->channels = lpc18xx_dac_iio_channels;
drivers/iio/dac/ltc1660.c+0−1
@@ -186,7 +186,6 @@ static int ltc1660_probe(struct spi_device *spi) · 185 unmodified lines
186186
187187 priv->spi = spi;
188188 spi_set_drvdata(spi, indio_dev);
189− indio_dev->dev.parent = &spi->dev;
190189 indio_dev->info = &ltc1660_info;
191190 indio_dev->modes = INDIO_DIRECT_MODE;
192191 indio_dev->channels = ltc1660_channels[id->driver_data];
drivers/iio/dac/ltc2632.c+0−1
@@ -362,7 +362,6 @@ static int ltc2632_probe(struct spi_device *spi) · 361 unmodified lines
362362 }
363363 }
364364
365− indio_dev->dev.parent = &spi->dev;
366365 indio_dev->name = dev_of_node(&spi->dev) ? dev_of_node(&spi->dev)->name
367366 : spi_get_device_id(spi)->name;
368367 indio_dev->info = &ltc2632_info;
drivers/iio/dac/m62332.c+0−3
@@ -204,9 +204,6 @@ static int m62332_probe(struct i2c_client *client, · 203 unmodified lines
204204 if (IS_ERR(data->vcc))
205205 return PTR_ERR(data->vcc);
206206
207− /* establish that the iio_dev is a child of the i2c device */
208− indio_dev->dev.parent = &client->dev;
209−
210207 indio_dev->num_channels = ARRAY_SIZE(m62332_channels);
211208 indio_dev->channels = m62332_channels;
212209 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/max517.c+0−3
@@ -156,9 +156,6 @@ static int max517_probe(struct i2c_client *client, · 155 unmodified lines
156156 i2c_set_clientdata(client, indio_dev);
157157 data->client = client;
158158
159− /* establish that the iio_dev is a child of the i2c device */
160− indio_dev->dev.parent = &client->dev;
161−
162159 switch (id->driver_data) {
163160 case ID_MAX521:
164161 indio_dev->num_channels = 8;
drivers/iio/dac/max5821.c+0−1
@@ -341,7 +341,6 @@ static int max5821_probe(struct i2c_client *client, · 340 unmodified lines
341341 data->vref_mv = ret / 1000;
342342
343343 indio_dev->name = id->name;
344− indio_dev->dev.parent = &client->dev;
345344 indio_dev->num_channels = ARRAY_SIZE(max5821_channels);
346345 indio_dev->channels = max5821_channels;
347346 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/mcp4725.c+0−1
@@ -453,7 +453,6 @@ static int mcp4725_probe(struct i2c_client *client, · 452 unmodified lines
453453 goto err_disable_vdd_reg;
454454 }
455455
456− indio_dev->dev.parent = &client->dev;
457456 indio_dev->name = id->name;
458457 indio_dev->info = &mcp4725_info;
459458 indio_dev->channels = &mcp472x_channel[id->driver_data];
drivers/iio/dac/mcp4922.c+0−1
@@ -152,7 +152,6 @@ static int mcp4922_probe(struct spi_device *spi) · 151 unmodified lines
152152
153153 spi_set_drvdata(spi, indio_dev);
154154 id = spi_get_device_id(spi);
155− indio_dev->dev.parent = &spi->dev;
156155 indio_dev->info = &mcp4922_info;
157156 indio_dev->modes = INDIO_DIRECT_MODE;
158157 indio_dev->channels = mcp4922_channels[id->driver_data];
drivers/iio/dac/stm32-dac.c+0−1
@@ -323,7 +323,6 @@ static int stm32_dac_probe(struct platform_device *pdev) · 322 unmodified lines
323323 dac = iio_priv(indio_dev);
324324 dac->common = dev_get_drvdata(pdev->dev.parent);
325325 indio_dev->name = dev_name(&pdev->dev);
326− indio_dev->dev.parent = &pdev->dev;
327326 indio_dev->dev.of_node = pdev->dev.of_node;
328327 indio_dev->info = &stm32_dac_iio_info;
329328 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ti-dac082s085.c+6−7
@@ -4,12 +4,12 @@ · 3 unmodified lines
44 *
55 * Copyright (C) 2017 KUNBUS GmbH
66 *
7− * http://www.ti.com/lit/ds/symlink/dac082s085.pdf
8− * http://www.ti.com/lit/ds/symlink/dac102s085.pdf
9− * http://www.ti.com/lit/ds/symlink/dac122s085.pdf
10− * http://www.ti.com/lit/ds/symlink/dac084s085.pdf
11− * http://www.ti.com/lit/ds/symlink/dac104s085.pdf
12− * http://www.ti.com/lit/ds/symlink/dac124s085.pdf
7+ * https://www.ti.com/lit/ds/symlink/dac082s085.pdf
8+ * https://www.ti.com/lit/ds/symlink/dac102s085.pdf
9+ * https://www.ti.com/lit/ds/symlink/dac122s085.pdf
10+ * https://www.ti.com/lit/ds/symlink/dac084s085.pdf
11+ * https://www.ti.com/lit/ds/symlink/dac104s085.pdf
12+ * https://www.ti.com/lit/ds/symlink/dac124s085.pdf
1313 */
1414
1515 #include <linux/iio/iio.h>
@@ -268,7 +268,6 @@ static int ti_dac_probe(struct spi_device *spi) · 252 unmodified lines
268268 if (!indio_dev)
269269 return -ENOMEM;
270270
271− indio_dev->dev.parent = dev;
272271 indio_dev->info = &ti_dac_info;
273272 indio_dev->name = spi->modalias;
274273 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ti-dac5571.c+9−11
@@ -4,15 +4,15 @@ · 3 unmodified lines
44 *
55 * Copyright (C) 2018 Prevas A/S
66 *
7− * http://www.ti.com/lit/ds/symlink/dac5571.pdf
8− * http://www.ti.com/lit/ds/symlink/dac6571.pdf
9− * http://www.ti.com/lit/ds/symlink/dac7571.pdf
10− * http://www.ti.com/lit/ds/symlink/dac5574.pdf
11− * http://www.ti.com/lit/ds/symlink/dac6574.pdf
12− * http://www.ti.com/lit/ds/symlink/dac7574.pdf
13− * http://www.ti.com/lit/ds/symlink/dac5573.pdf
14− * http://www.ti.com/lit/ds/symlink/dac6573.pdf
15− * http://www.ti.com/lit/ds/symlink/dac7573.pdf
7+ * https://www.ti.com/lit/ds/symlink/dac5571.pdf
8+ * https://www.ti.com/lit/ds/symlink/dac6571.pdf
9+ * https://www.ti.com/lit/ds/symlink/dac7571.pdf
10+ * https://www.ti.com/lit/ds/symlink/dac5574.pdf
11+ * https://www.ti.com/lit/ds/symlink/dac6574.pdf
12+ * https://www.ti.com/lit/ds/symlink/dac7574.pdf
13+ * https://www.ti.com/lit/ds/symlink/dac5573.pdf
14+ * https://www.ti.com/lit/ds/symlink/dac6573.pdf
15+ * https://www.ti.com/lit/ds/symlink/dac7573.pdf
1616 */
1717
1818 #include <linux/iio/iio.h>
@@ -321,8 +321,6 @@ static int dac5571_probe(struct i2c_client *client, · 302 unmodified lines
321321 i2c_set_clientdata(client, indio_dev);
322322 data->client = client;
323323
324− indio_dev->dev.parent = dev;
325− indio_dev->dev.of_node = client->dev.of_node;
326324 indio_dev->info = &dac5571_info;
327325 indio_dev->name = id->name;
328326 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ti-dac7311.c+1−3
@@ -3,7 +3,7 @@ · 2 unmodified lines
33 *
44 * Copyright (C) 2018 CMC NV
55 *
6− * http://www.ti.com/lit/ds/symlink/dac7311.pdf
6+ * https://www.ti.com/lit/ds/symlink/dac7311.pdf
77 */
88
99 #include <linux/iio/iio.h>
@@ -251,8 +251,6 @@ static int ti_dac_probe(struct spi_device *spi) · 241 unmodified lines
251251 spi->bits_per_word = 16;
252252 spi_setup(spi);
253253
254− indio_dev->dev.parent = dev;
255− indio_dev->dev.of_node = spi->dev.of_node;
256254 indio_dev->info = &ti_dac_info;
257255 indio_dev->name = spi_get_device_id(spi)->name;
258256 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ti-dac7612.c+0−1
@@ -139,7 +139,6 @@ static int dac7612_probe(struct spi_device *spi) · 138 unmodified lines
139139 return PTR_ERR(priv->loaddacs);
140140 priv->spi = spi;
141141 spi_set_drvdata(spi, iio_dev);
142− iio_dev->dev.parent = &spi->dev;
143142 iio_dev->info = &dac7612_info;
144143 iio_dev->modes = INDIO_DIRECT_MODE;
145144 iio_dev->channels = dac7612_channels;
drivers/iio/dac/vf610_dac.c+0−2
@@ -199,8 +199,6 @@ static int vf610_dac_probe(struct platform_device *pdev) · 198 unmodified lines
199199 platform_set_drvdata(pdev, indio_dev);
200200
201201 indio_dev->name = dev_name(&pdev->dev);
202− indio_dev->dev.parent = &pdev->dev;
203− indio_dev->dev.of_node = pdev->dev.of_node;
204202 indio_dev->info = &vf610_dac_iio_info;
205203 indio_dev->modes = INDIO_DIRECT_MODE;
206204 indio_dev->channels = vf610_dac_iio_channels;
drivers/iio/dummy/iio_simple_dummy.c+8−6
@@ -566,6 +566,13 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) · 565 unmodified lines
566566 struct iio_dev *indio_dev;
567567 struct iio_dummy_state *st;
568568 struct iio_sw_device *swd;
569+ struct device *parent = NULL;
570+
571+ /*
572+ * With hardware: Set the parent device.
573+ * parent = &spi->dev;
574+ * parent = &client->dev;
575+ */
569576
570577 swd = kzalloc(sizeof(*swd), GFP_KERNEL);
571578 if (!swd) {
@@ -580,7 +587,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) · 8 unmodified lines
580587 * It also has a region (accessed by iio_priv()
581588 * for chip specific state information.
582589 */
583− indio_dev = iio_device_alloc(sizeof(*st));
590+ indio_dev = iio_device_alloc(parent, sizeof(*st));
584591 if (!indio_dev) {
585592 ret = -ENOMEM;
586593 goto error_ret;
@@ -590,11 +597,6 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) · 3 unmodified lines
590597 mutex_init(&st->lock);
591598
592599 iio_dummy_init_device(indio_dev);
593− /*
594− * With hardware: Set the parent device.
595− * indio_dev->dev.parent = &spi->dev;
596− * indio_dev->dev.parent = &client->dev;
597− */
598600
599601 /*
600602 * Make the iio_dev struct available to remove function.
drivers/iio/dummy/iio_simple_dummy_buffer.c+0−14
@@ -99,20 +99,6 @@ done: · 98 unmodified lines
9999 }
100100
101101 static const struct iio_buffer_setup_ops iio_simple_dummy_buffer_setup_ops = {
102− /*
103− * iio_triggered_buffer_postenable:
104− * Generic function that simply attaches the pollfunc to the trigger.
105− * Replace this to mess with hardware state before we attach the
106− * trigger.
107− */
108− .postenable = &iio_triggered_buffer_postenable,
109− /*
110− * iio_triggered_buffer_predisable:
111− * Generic function that simple detaches the pollfunc from the trigger.
112− * Replace this to put hardware state back again after the trigger is
113− * detached but before userspace knows we have disabled the ring.
114− */
115− .predisable = &iio_triggered_buffer_predisable,
116102 };
117103
118104 int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
drivers/iio/frequency/ad9523.c+0−1
@@ -1026,7 +1026,6 @@ static int ad9523_probe(struct spi_device *spi) · 1025 unmodified lines
10261026 st->spi = spi;
10271027 st->pdata = pdata;
10281028
1029− indio_dev->dev.parent = &spi->dev;
10301029 indio_dev->name = (pdata->name[0] != 0) ? pdata->name :
10311030 spi_get_device_id(spi)->name;
10321031 indio_dev->info = &ad9523_info;
drivers/iio/frequency/adf4350.c+0−1
@@ -531,7 +531,6 @@ static int adf4350_probe(struct spi_device *spi) · 530 unmodified lines
531531 st->spi = spi;
532532 st->pdata = pdata;
533533
534− indio_dev->dev.parent = &spi->dev;
535534 indio_dev->name = (pdata->name[0] != 0) ? pdata->name :
536535 spi_get_device_id(spi)->name;
537536
drivers/iio/frequency/adf4371.c+0−1
@@ -573,7 +573,6 @@ static int adf4371_probe(struct spi_device *spi) · 572 unmodified lines
573573 mutex_init(&st->lock);
574574
575575 st->chip_info = &adf4371_chip_info[id->driver_data];
576− indio_dev->dev.parent = &spi->dev;
577576 indio_dev->name = id->name;
578577 indio_dev->info = &adf4371_info;
579578 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/gyro/adis16080.c+0−1
@@ -207,7 +207,6 @@ static int adis16080_probe(struct spi_device *spi) · 206 unmodified lines
207207 indio_dev->name = spi->dev.driver->name;
208208 indio_dev->channels = adis16080_channels;
209209 indio_dev->num_channels = ARRAY_SIZE(adis16080_channels);
210− indio_dev->dev.parent = &spi->dev;
211210 indio_dev->info = &adis16080_info;
212211 indio_dev->modes = INDIO_DIRECT_MODE;
213212
drivers/iio/gyro/adis16130.c+0−1
@@ -155,7 +155,6 @@ static int adis16130_probe(struct spi_device *spi) · 154 unmodified lines
155155 indio_dev->name = spi->dev.driver->name;
156156 indio_dev->channels = adis16130_channels;
157157 indio_dev->num_channels = ARRAY_SIZE(adis16130_channels);
158− indio_dev->dev.parent = &spi->dev;
159158 indio_dev->info = &adis16130_info;
160159 indio_dev->modes = INDIO_DIRECT_MODE;
161160
drivers/iio/gyro/adis16136.c+0−1
@@ -540,7 +540,6 @@ static int adis16136_probe(struct spi_device *spi) · 539 unmodified lines
540540 adis16136 = iio_priv(indio_dev);
541541
542542 adis16136->chip_info = &adis16136_chip_info[id->driver_data];
543− indio_dev->dev.parent = &spi->dev;
544543 indio_dev->name = spi_get_device_id(spi)->name;
545544 indio_dev->channels = adis16136_channels;
546545 indio_dev->num_channels = ARRAY_SIZE(adis16136_channels);
drivers/iio/gyro/adis16260.c+0−1
@@ -381,7 +381,6 @@ static int adis16260_probe(struct spi_device *spi) · 380 unmodified lines
381381 adis16260->info = &adis16260_chip_info_table[id->driver_data];
382382
383383 indio_dev->name = id->name;
384− indio_dev->dev.parent = &spi->dev;
385384 indio_dev->info = &adis16260_info;
386385 indio_dev->channels = adis16260->info->channels;
387386 indio_dev->num_channels = adis16260->info->num_channels;
drivers/iio/gyro/adxrs450.c+0−1
@@ -424,7 +424,6 @@ static int adxrs450_probe(struct spi_device *spi) · 423 unmodified lines
424424 /* This is only used for removal purposes */
425425 spi_set_drvdata(spi, indio_dev);
426426
427− indio_dev->dev.parent = &spi->dev;
428427 indio_dev->info = &adxrs450_info;
429428 indio_dev->modes = INDIO_DIRECT_MODE;
430429 indio_dev->channels =
drivers/iio/gyro/bmg160_core.c+0−3
@@ -1051,8 +1051,6 @@ static int bmg160_buffer_postdisable(struct iio_dev *indio_dev) · 1050 unmodified lines
10511051
10521052 static const struct iio_buffer_setup_ops bmg160_buffer_setup_ops = {
10531053 .preenable = bmg160_buffer_preenable,
1054− .postenable = iio_triggered_buffer_postenable,
1055− .predisable = iio_triggered_buffer_predisable,
10561054 .postdisable = bmg160_buffer_postdisable,
10571055 };
10581056
@@ -1097,7 +1095,6 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, · 38 unmodified lines
10971095 if (ACPI_HANDLE(dev))
10981096 name = bmg160_match_acpi_device(dev);
10991097
1100− indio_dev->dev.parent = dev;
11011098 indio_dev->channels = bmg160_channels;
11021099 indio_dev->num_channels = ARRAY_SIZE(bmg160_channels);
11031100 indio_dev->name = name;
drivers/iio/gyro/fxas21002c_core.c+0−1
@@ -905,7 +905,6 @@ int fxas21002c_core_probe(struct device *dev, struct regmap *regmap, int irq, · 904 unmodified lines
905905 if (ret < 0)
906906 return ret;
907907
908− indio_dev->dev.parent = dev;
909908 indio_dev->channels = fxas21002c_channels;
910909 indio_dev->num_channels = ARRAY_SIZE(fxas21002c_channels);
911910 indio_dev->name = name;
drivers/iio/gyro/hid-sensor-gyro-3d.c+0−1
@@ -319,7 +319,6 @@ static int hid_gyro_3d_probe(struct platform_device *pdev) · 318 unmodified lines
319319 }
320320
321321 indio_dev->num_channels = ARRAY_SIZE(gyro_3d_channels);
322− indio_dev->dev.parent = &pdev->dev;
323322 indio_dev->info = &gyro_3d_info;
324323 indio_dev->name = name;
325324 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/gyro/itg3200_core.c+0−1
@@ -316,7 +316,6 @@ static int itg3200_probe(struct i2c_client *client, · 315 unmodified lines
316316 i2c_set_clientdata(client, indio_dev);
317317 st->i2c = client;
318318
319− indio_dev->dev.parent = &client->dev;
320319 indio_dev->name = client->dev.driver->name;
321320 indio_dev->channels = itg3200_channels;
322321 indio_dev->num_channels = ARRAY_SIZE(itg3200_channels);
drivers/iio/gyro/mpu3050-core.c+0−3
@@ -662,8 +662,6 @@ static int mpu3050_buffer_postdisable(struct iio_dev *indio_dev) · 661 unmodified lines
662662
663663 static const struct iio_buffer_setup_ops mpu3050_buffer_setup_ops = {
664664 .preenable = mpu3050_buffer_preenable,
665− .postenable = iio_triggered_buffer_postenable,
666− .predisable = iio_triggered_buffer_predisable,
667665 .postdisable = mpu3050_buffer_postdisable,
668666 };
669667
@@ -1198,7 +1196,6 @@ int mpu3050_common_probe(struct device *dev, · 528 unmodified lines
11981196 if (ret)
11991197 goto err_power_down;
12001198
1201− indio_dev->dev.parent = dev;
12021199 indio_dev->channels = mpu3050_channels;
12031200 indio_dev->num_channels = ARRAY_SIZE(mpu3050_channels);
12041201 indio_dev->info = &mpu3050_info;
drivers/iio/gyro/ssp_gyro_sensor.c+0−1
@@ -108,7 +108,6 @@ static int ssp_gyro_probe(struct platform_device *pdev) · 107 unmodified lines
108108 spd->type = SSP_GYROSCOPE_SENSOR;
109109
110110 indio_dev->name = ssp_gyro_name;
111− indio_dev->dev.parent = &pdev->dev;
112111 indio_dev->info = &ssp_gyro_iio_info;
113112 indio_dev->modes = INDIO_BUFFER_SOFTWARE;
114113 indio_dev->channels = ssp_gyro_channels;
drivers/iio/gyro/st_gyro_buffer.c+4−17
@@ -33,13 +33,9 @@ static int st_gyro_buffer_postenable(struct iio_dev *indio_dev) · 32 unmodified lines
3333 {
3434 int err;
3535
36− err = iio_triggered_buffer_postenable(indio_dev);
37− if (err < 0)
38− return err;
39−
4036 err = st_sensors_set_axis_enable(indio_dev, indio_dev->active_scan_mask[0]);
4137 if (err < 0)
42− goto st_gyro_buffer_predisable;
38+ return err;
4339
4440 err = st_sensors_set_enable(indio_dev, true);
4541 if (err < 0)
@@ -49,27 +45,18 @@ static int st_gyro_buffer_postenable(struct iio_dev *indio_dev) · 3 unmodified lines
4945
5046 st_gyro_buffer_enable_all_axis:
5147 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
52−st_gyro_buffer_predisable:
53− iio_triggered_buffer_predisable(indio_dev);
5448 return err;
5549 }
5650
5751 static int st_gyro_buffer_predisable(struct iio_dev *indio_dev)
5852 {
59− int err, err2;
53+ int err;
6054
6155 err = st_sensors_set_enable(indio_dev, false);
6256 if (err < 0)
63− goto st_gyro_buffer_predisable;
64−
65− err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
66−
67−st_gyro_buffer_predisable:
68− err2 = iio_triggered_buffer_predisable(indio_dev);
69− if (!err)
70− err = err2;
57+ return err;
7158
72− return err;
59+ return st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
7360 }
7461
7562 static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = {
drivers/iio/health/afe4403.c+1−2
@@ -2,7 +2,7 @@ · 1 unmodified line
22 /*
33 * AFE4403 Heart Rate Monitors and Low-Cost Pulse Oximeters
44 *
5− * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
5+ * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/
66 * Andrew F. Davis <afd@ti.com>
77 */
88
@@ -509,7 +509,6 @@ static int afe4403_probe(struct spi_device *spi) · 500 unmodified lines
509509 }
510510
511511 indio_dev->modes = INDIO_DIRECT_MODE;
512− indio_dev->dev.parent = afe->dev;
513512 indio_dev->channels = afe4403_channels;
514513 indio_dev->num_channels = ARRAY_SIZE(afe4403_channels);
515514 indio_dev->name = AFE4403_DRIVER_NAME;
drivers/iio/health/afe4404.c+1−2
@@ -2,7 +2,7 @@ · 1 unmodified line
22 /*
33 * AFE4404 Heart Rate Monitors and Low-Cost Pulse Oximeters
44 *
5− * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
5+ * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/
66 * Andrew F. Davis <afd@ti.com>
77 */
88
@@ -517,7 +517,6 @@ static int afe4404_probe(struct i2c_client *client, · 508 unmodified lines
517517 }
518518
519519 indio_dev->modes = INDIO_DIRECT_MODE;
520− indio_dev->dev.parent = afe->dev;
521520 indio_dev->channels = afe4404_channels;
522521 indio_dev->num_channels = ARRAY_SIZE(afe4404_channels);
523522 indio_dev->name = AFE4404_DRIVER_NAME;
drivers/iio/health/afe440x.h+1−1
@@ -2,7 +2,7 @@ · 1 unmodified line
22 /*
33 * AFE440X Heart Rate Monitors and Low-Cost Pulse Oximeters
44 *
5− * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
5+ * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
66 * Andrew F. Davis <afd@ti.com>
77 */
88
drivers/iio/health/max30100.c+0−1
@@ -439,7 +439,6 @@ static int max30100_probe(struct i2c_client *client, · 438 unmodified lines
439439 indio_dev->available_scan_masks = max30100_scan_masks;
440440 indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);
441441 indio_dev->setup_ops = &max30100_buffer_setup_ops;
442− indio_dev->dev.parent = &client->dev;
443442
444443 data = iio_priv(indio_dev);
445444 data->indio_dev = indio_dev;
drivers/iio/health/max30102.c+0−1
@@ -526,7 +526,6 @@ static int max30102_probe(struct i2c_client *client, · 525 unmodified lines
526526 indio_dev->info = &max30102_info;
527527 indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);
528528 indio_dev->setup_ops = &max30102_buffer_setup_ops;
529− indio_dev->dev.parent = &client->dev;
530529
531530 data = iio_priv(indio_dev);
532531 data->indio_dev = indio_dev;
drivers/iio/humidity/am2315.c+0−1
@@ -233,7 +233,6 @@ static int am2315_probe(struct i2c_client *client, · 232 unmodified lines
233233 i2c_set_clientdata(client, indio_dev);
234234 mutex_init(&data->lock);
235235
236− indio_dev->dev.parent = &client->dev;
237236 indio_dev->info = &am2315_info;
238237 indio_dev->name = AM2315_DRIVER_NAME;
239238 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/humidity/dht11.c+0−1
@@ -321,7 +321,6 @@ static int dht11_probe(struct platform_device *pdev) · 320 unmodified lines
321321 init_completion(&dht11->completion);
322322 mutex_init(&dht11->lock);
323323 iio->name = pdev->name;
324− iio->dev.parent = &pdev->dev;
325324 iio->info = &dht11_iio_info;
326325 iio->modes = INDIO_DIRECT_MODE;
327326 iio->channels = dht11_chan_spec;
drivers/iio/humidity/hdc100x.c+6−17
@@ -6,11 +6,11 @@ · 5 unmodified lines
66 * Author: Matt Ranostay <matt.ranostay@konsulko.com>
77 *
88 * Datasheets:
9− * http://www.ti.com/product/HDC1000/datasheet
10− * http://www.ti.com/product/HDC1008/datasheet
11− * http://www.ti.com/product/HDC1010/datasheet
12− * http://www.ti.com/product/HDC1050/datasheet
13− * http://www.ti.com/product/HDC1080/datasheet
9+ * https://www.ti.com/product/HDC1000/datasheet
10+ * https://www.ti.com/product/HDC1008/datasheet
11+ * https://www.ti.com/product/HDC1010/datasheet
12+ * https://www.ti.com/product/HDC1050/datasheet
13+ * https://www.ti.com/product/HDC1080/datasheet
1414 */
1515
1616 #include <linux/delay.h>
@@ -278,17 +278,11 @@ static int hdc100x_buffer_postenable(struct iio_dev *indio_dev) · 261 unmodified lines
278278 struct hdc100x_data *data = iio_priv(indio_dev);
279279 int ret;
280280
281− ret = iio_triggered_buffer_postenable(indio_dev);
282− if (ret)
283− return ret;
284−
285281 /* Buffer is enabled. First set ACQ Mode, then attach poll func */
286282 mutex_lock(&data->lock);
287283 ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE,
288284 HDC100X_REG_CONFIG_ACQ_MODE);
289285 mutex_unlock(&data->lock);
290− if (ret)
291− iio_triggered_buffer_predisable(indio_dev);
292286
293287 return ret;
294288 }
@@ -296,16 +290,12 @@ static int hdc100x_buffer_postenable(struct iio_dev *indio_dev) · 1 unmodified line
296290 static int hdc100x_buffer_predisable(struct iio_dev *indio_dev)
297291 {
298292 struct hdc100x_data *data = iio_priv(indio_dev);
299− int ret, ret2;
293+ int ret;
300294
301295 mutex_lock(&data->lock);
302296 ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE, 0);
303297 mutex_unlock(&data->lock);
304298
305− ret2 = iio_triggered_buffer_predisable(indio_dev);
306− if (ret == 0)
307− ret = ret2;
308−
309299 return ret;
310300 }
311301
@@ -374,7 +364,6 @@ static int hdc100x_probe(struct i2c_client *client, · 62 unmodified lines
374364 data->client = client;
375365 mutex_init(&data->lock);
376366
377− indio_dev->dev.parent = &client->dev;
378367 indio_dev->name = dev_name(&client->dev);
379368 indio_dev->modes = INDIO_DIRECT_MODE;
380369 indio_dev->info = &hdc100x_info;
drivers/iio/humidity/hid-sensor-humidity.c+0−1
@@ -226,7 +226,6 @@ static int hid_humidity_probe(struct platform_device *pdev) · 225 unmodified lines
226226
227227 indio_dev->channels = humid_chans;
228228 indio_dev->num_channels = ARRAY_SIZE(humidity_channels);
229− indio_dev->dev.parent = &pdev->dev;
230229 indio_dev->info = &humidity_info;
231230 indio_dev->name = name;
232231 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/humidity/hts221.h+2−2
@@ -46,7 +46,7 @@ extern const struct dev_pm_ops hts221_pm_ops; · 45 unmodified lines
4646 int hts221_probe(struct device *dev, int irq, const char *name,
4747 struct regmap *regmap);
4848 int hts221_set_enable(struct hts221_hw *hw, bool enable);
49−int hts221_allocate_buffers(struct hts221_hw *hw);
50−int hts221_allocate_trigger(struct hts221_hw *hw);
49+int hts221_allocate_buffers(struct iio_dev *iio_dev);
50+int hts221_allocate_trigger(struct iio_dev *iio_dev);
5151
5252 #endif /* HTS221_H */
drivers/iio/humidity/hts221_buffer.c+5−6
@@ -72,10 +72,10 @@ static irqreturn_t hts221_trigger_handler_thread(int irq, void *private) · 71 unmodified lines
7272 return IRQ_HANDLED;
7373 }
7474
75−int hts221_allocate_trigger(struct hts221_hw *hw)
75+int hts221_allocate_trigger(struct iio_dev *iio_dev)
7676 {
77+ struct hts221_hw *hw = iio_priv(iio_dev);
7778 struct st_sensors_platform_data *pdata = dev_get_platdata(hw->dev);
78− struct iio_dev *iio_dev = iio_priv_to_dev(hw);
7979 bool irq_active_low = false, open_drain = false;
8080 unsigned long irq_type;
8181 int err;
@@ -153,8 +153,6 @@ static int hts221_buffer_postdisable(struct iio_dev *iio_dev) · 71 unmodified lines
153153
154154 static const struct iio_buffer_setup_ops hts221_buffer_ops = {
155155 .preenable = hts221_buffer_preenable,
156− .postenable = iio_triggered_buffer_postenable,
157− .predisable = iio_triggered_buffer_predisable,
158156 .postdisable = hts221_buffer_postdisable,
159157 };
160158
@@ -190,9 +188,10 @@ out: · 29 unmodified lines
190188 return IRQ_HANDLED;
191189 }
192190
193−int hts221_allocate_buffers(struct hts221_hw *hw)
191+int hts221_allocate_buffers(struct iio_dev *iio_dev)
194192 {
195− return devm_iio_triggered_buffer_setup(hw->dev, iio_priv_to_dev(hw),
193+ struct hts221_hw *hw = iio_priv(iio_dev);
194+ return devm_iio_triggered_buffer_setup(hw->dev, iio_dev,
196195 NULL, hts221_buffer_handler_thread,
197196 &hts221_buffer_ops);
198197 }
drivers/iio/humidity/hts221_core.c+2−3
@@ -572,7 +572,6 @@ int hts221_probe(struct device *dev, int irq, const char *name, · 571 unmodified lines
572572 return err;
573573
574574 iio_dev->modes = INDIO_DIRECT_MODE;
575− iio_dev->dev.parent = hw->dev;
576575 iio_dev->available_scan_masks = hts221_scan_masks;
577576 iio_dev->channels = hts221_channels;
578577 iio_dev->num_channels = ARRAY_SIZE(hts221_channels);
@@ -621,11 +620,11 @@ int hts221_probe(struct device *dev, int irq, const char *name, · 42 unmodified lines
621620 }
622621
623622 if (hw->irq > 0) {
624− err = hts221_allocate_buffers(hw);
623+ err = hts221_allocate_buffers(iio_dev);
625624 if (err < 0)
626625 return err;
627626
628− err = hts221_allocate_trigger(hw);
627+ err = hts221_allocate_trigger(iio_dev);
629628 if (err)
630629 return err;
631630 }
drivers/iio/humidity/htu21.c+0−1
@@ -204,7 +204,6 @@ static int htu21_probe(struct i2c_client *client, · 203 unmodified lines
204204
205205 indio_dev->info = &htu21_info;
206206 indio_dev->name = id->name;
207− indio_dev->dev.parent = &client->dev;
208207 indio_dev->modes = INDIO_DIRECT_MODE;
209208
210209 if (id->driver_data == MS8607) {
drivers/iio/humidity/si7005.c+0−1
@@ -142,7 +142,6 @@ static int si7005_probe(struct i2c_client *client, · 141 unmodified lines
142142 data->client = client;
143143 mutex_init(&data->lock);
144144
145− indio_dev->dev.parent = &client->dev;
146145 indio_dev->name = dev_name(&client->dev);
147146 indio_dev->modes = INDIO_DIRECT_MODE;
148147 indio_dev->info = &si7005_info;
drivers/iio/humidity/si7020.c+0−1
@@ -128,7 +128,6 @@ static int si7020_probe(struct i2c_client *client, · 127 unmodified lines
128128 data = iio_priv(indio_dev);
129129 *data = client;
130130
131− indio_dev->dev.parent = &client->dev;
132131 indio_dev->name = dev_name(&client->dev);
133132 indio_dev->modes = INDIO_DIRECT_MODE;
134133 indio_dev->info = &si7020_info;
drivers/iio/iio_core_trigger.h+17−0
@@ -18,6 +18,12 @@ void iio_device_register_trigger_consumer(struct iio_dev *indio_dev); · 17 unmodified lines
1818 **/
1919 void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev);
2020
21+
22+int iio_trigger_attach_poll_func(struct iio_trigger *trig,
23+ struct iio_poll_func *pf);
24+int iio_trigger_detach_poll_func(struct iio_trigger *trig,
25+ struct iio_poll_func *pf);
26+
2127 #else
2228
2329 /**
@@ -37,4 +43,15 @@ static void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev) · 13 unmodified lines
3743 {
3844 }
3945
46+static inline int iio_trigger_attach_poll_func(struct iio_trigger *trig,
47+ struct iio_poll_func *pf)
48+{
49+ return 0;
50+}
51+static inline int iio_trigger_detach_poll_func(struct iio_trigger *trig,
52+ struct iio_poll_func *pf)
53+{
54+ return 0;
55+}
56+
4057 #endif /* CONFIG_TRIGGER_CONSUMER */
drivers/iio/imu/Kconfig+1−0
@@ -91,6 +91,7 @@ config KMX61 · 90 unmodified lines
9191 To compile this driver as module, choose M here: the module will
9292 be called kmx61.
9393
94+source "drivers/iio/imu/inv_icm42600/Kconfig"
9495 source "drivers/iio/imu/inv_mpu6050/Kconfig"
9596 source "drivers/iio/imu/st_lsm6dsx/Kconfig"
9697
drivers/iio/imu/Makefile+1−0
@@ -20,6 +20,7 @@ obj-$(CONFIG_FXOS8700) += fxos8700_core.o · 19 unmodified lines
2020 obj-$(CONFIG_FXOS8700_I2C) += fxos8700_i2c.o
2121 obj-$(CONFIG_FXOS8700_SPI) += fxos8700_spi.o
2222
23+obj-y += inv_icm42600/
2324 obj-y += inv_mpu6050/
2425
2526 obj-$(CONFIG_KMX61) += kmx61.o
drivers/iio/imu/adis16400.c+0−1
@@ -1181,7 +1181,6 @@ static int adis16400_probe(struct spi_device *spi) · 1180 unmodified lines
11811181
11821182 /* setup the industrialio driver allocated elements */
11831183 st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data];
1184− indio_dev->dev.parent = &spi->dev;
11851184 indio_dev->name = spi_get_device_id(spi)->name;
11861185 indio_dev->channels = st->variant->channels;
11871186 indio_dev->num_channels = st->variant->num_channels;
drivers/iio/imu/adis16460.c+0−1
@@ -393,7 +393,6 @@ static int adis16460_probe(struct spi_device *spi) · 392 unmodified lines
393393 st = iio_priv(indio_dev);
394394
395395 st->chip_info = &adis16460_chip_info;
396− indio_dev->dev.parent = &spi->dev;
397396 indio_dev->name = spi_get_device_id(spi)->name;
398397 indio_dev->channels = st->chip_info->channels;
399398 indio_dev->num_channels = st->chip_info->num_channels;
drivers/iio/imu/adis16475.c+0−1
@@ -1289,7 +1289,6 @@ static int adis16475_probe(struct spi_device *spi) · 1288 unmodified lines
12891289 if (ret)
12901290 return ret;
12911291
1292− indio_dev->dev.parent = &spi->dev;
12931292 indio_dev->name = st->info->name;
12941293 indio_dev->channels = st->info->channels;
12951294 indio_dev->num_channels = st->info->num_channels;
drivers/iio/imu/adis16480.c+3−4
@@ -1102,12 +1102,12 @@ static int adis16480_config_irq_pin(struct device_node *of_node, · 1101 unmodified lines
11021102 /*
11031103 * Get the interrupt line behaviour. The data ready polarity can be
11041104 * configured as positive or negative, corresponding to
1105− * IRQF_TRIGGER_RISING or IRQF_TRIGGER_FALLING respectively.
1105+ * IRQ_TYPE_EDGE_RISING or IRQ_TYPE_EDGE_FALLING respectively.
11061106 */
11071107 irq_type = irqd_get_trigger_type(desc);
1108− if (irq_type == IRQF_TRIGGER_RISING) { /* Default */
1108+ if (irq_type == IRQ_TYPE_EDGE_RISING) { /* Default */
11091109 val |= ADIS16480_DRDY_POL(1);
1110− } else if (irq_type == IRQF_TRIGGER_FALLING) {
1110+ } else if (irq_type == IRQ_TYPE_EDGE_FALLING) {
11111111 val |= ADIS16480_DRDY_POL(0);
11121112 } else {
11131113 dev_err(&st->adis.spi->dev,
@@ -1229,7 +1229,6 @@ static int adis16480_probe(struct spi_device *spi) · 115 unmodified lines
12291229 st = iio_priv(indio_dev);
12301230
12311231 st->chip_info = &adis16480_chip_info[id->driver_data];
1232− indio_dev->dev.parent = &spi->dev;
12331232 indio_dev->name = spi_get_device_id(spi)->name;
12341233 indio_dev->channels = st->chip_info->channels;
12351234 indio_dev->num_channels = st->chip_info->num_channels;
drivers/iio/imu/bmi160/bmi160.h+3−0
@@ -3,10 +3,13 @@ · 2 unmodified lines
33 #define BMI160_H_
44
55 #include <linux/iio/iio.h>
6+#include <linux/regulator/consumer.h>
67
78 struct bmi160_data {
89 struct regmap *regmap;
910 struct iio_trigger *trig;
11+ struct regulator_bulk_data supplies[2];
12+ struct iio_mount_matrix orientation;
1013 };
1114
1215 extern const struct regmap_config bmi160_regmap_config;
drivers/iio/imu/bmi160/bmi160_core.c+45−2
@@ -15,6 +15,7 @@ · 14 unmodified lines
1515 #include <linux/delay.h>
1616 #include <linux/irq.h>
1717 #include <linux/of_irq.h>
18+#include <linux/regulator/consumer.h>
1819
1920 #include <linux/iio/iio.h>
2021 #include <linux/iio/triggered_buffer.h>
@@ -109,6 +110,7 @@ · 88 unmodified lines
109110 .storagebits = 16, \
110111 .endianness = IIO_LE, \
111112 }, \
113+ .ext_info = bmi160_ext_info, \
112114 }
113115
114116 /* scan indexes follow DATA register order */
@@ -264,6 +266,20 @@ static const struct bmi160_odr_item bmi160_odr_table[] = { · 149 unmodified lines
264266 },
265267 };
266268
269+static const struct iio_mount_matrix *
270+bmi160_get_mount_matrix(const struct iio_dev *indio_dev,
271+ const struct iio_chan_spec *chan)
272+{
273+ struct bmi160_data *data = iio_priv(indio_dev);
274+
275+ return &data->orientation;
276+}
277+
278+static const struct iio_chan_spec_ext_info bmi160_ext_info[] = {
279+ IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, bmi160_get_mount_matrix),
280+ { }
281+};
282+
267283 static const struct iio_chan_spec bmi160_channels[] = {
268284 BMI160_CHANNEL(IIO_ACCEL, X, BMI160_SCAN_ACCEL_X),
269285 BMI160_CHANNEL(IIO_ACCEL, Y, BMI160_SCAN_ACCEL_Y),
@@ -709,6 +725,12 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi) · 439 unmodified lines
709725 unsigned int val;
710726 struct device *dev = regmap_get_device(data->regmap);
711727
728+ ret = regulator_bulk_enable(ARRAY_SIZE(data->supplies), data->supplies);
729+ if (ret) {
730+ dev_err(dev, "Failed to enable regulators: %d\n", ret);
731+ return ret;
732+ }
733+
712734 ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
713735 if (ret)
714736 return ret;
@@ -793,9 +815,16 @@ int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type) · 78 unmodified lines
793815 static void bmi160_chip_uninit(void *data)
794816 {
795817 struct bmi160_data *bmi_data = data;
818+ struct device *dev = regmap_get_device(bmi_data->regmap);
819+ int ret;
796820
797821 bmi160_set_mode(bmi_data, BMI160_GYRO, false);
798822 bmi160_set_mode(bmi_data, BMI160_ACCEL, false);
823+
824+ ret = regulator_bulk_disable(ARRAY_SIZE(bmi_data->supplies),
825+ bmi_data->supplies);
826+ if (ret)
827+ dev_err(dev, "Failed to disable regulators: %d\n", ret);
799828 }
800829
801830 int bmi160_core_probe(struct device *dev, struct regmap *regmap,
@@ -815,6 +844,21 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, · 13 unmodified lines
815844 dev_set_drvdata(dev, indio_dev);
816845 data->regmap = regmap;
817846
847+ data->supplies[0].supply = "vdd";
848+ data->supplies[1].supply = "vddio";
849+ ret = devm_regulator_bulk_get(dev,
850+ ARRAY_SIZE(data->supplies),
851+ data->supplies);
852+ if (ret) {
853+ dev_err(dev, "Failed to get regulators: %d\n", ret);
854+ return ret;
855+ }
856+
857+ ret = iio_read_mount_matrix(dev, "mount-matrix",
858+ &data->orientation);
859+ if (ret)
860+ return ret;
861+
818862 ret = bmi160_chip_init(data, use_spi);
819863 if (ret)
820864 return ret;
@@ -826,7 +870,6 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, · 5 unmodified lines
826870 if (!name && ACPI_HANDLE(dev))
827871 name = bmi160_match_acpi_device(dev);
828872
829− indio_dev->dev.parent = dev;
830873 indio_dev->channels = bmi160_channels;
831874 indio_dev->num_channels = ARRAY_SIZE(bmi160_channels);
832875 indio_dev->name = name;
@@ -853,6 +896,6 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, · 20 unmodified lines
853896 }
854897 EXPORT_SYMBOL_GPL(bmi160_core_probe);
855898
856−MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");
899+MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
857900 MODULE_DESCRIPTION("Bosch BMI160 driver");
858901 MODULE_LICENSE("GPL v2");
drivers/iio/imu/fxos8700_core.c+0−1
@@ -633,7 +633,6 @@ int fxos8700_core_probe(struct device *dev, struct regmap *regmap, · 632 unmodified lines
633633 if (ret)
634634 return ret;
635635
636− indio_dev->dev.parent = dev;
637636 indio_dev->channels = fxos8700_channels;
638637 indio_dev->num_channels = ARRAY_SIZE(fxos8700_channels);
639638 indio_dev->name = name ? name : "fxos8700";
drivers/iio/imu/inv_icm42600/Kconfig+29−0
@@ -0,0 +1,29 @@
1+# SPDX-License-Identifier: GPL-2.0-or-later
2+
3+config INV_ICM42600
4+ tristate
5+ select IIO_BUFFER
6+
7+config INV_ICM42600_I2C
8+ tristate "InvenSense ICM-426xx I2C driver"
9+ depends on I2C
10+ select INV_ICM42600
11+ select REGMAP_I2C
12+ help
13+ This driver supports the InvenSense ICM-426xx motion tracking
14+ devices over I2C.
15+
16+ This driver can be built as a module. The module will be called
17+ inv-icm42600-i2c.
18+
19+config INV_ICM42600_SPI
20+ tristate "InvenSense ICM-426xx SPI driver"
21+ depends on SPI_MASTER
22+ select INV_ICM42600
23+ select REGMAP_SPI
24+ help
25+ This driver supports the InvenSense ICM-426xx motion tracking
26+ devices over SPI.
27+
28+ This driver can be built as a module. The module will be called
29+ inv-icm42600-spi.
drivers/iio/imu/inv_icm42600/Makefile+15−0
@@ -0,0 +1,15 @@
1+# SPDX-License-Identifier: GPL-2.0-or-later
2+
3+obj-$(CONFIG_INV_ICM42600) += inv-icm42600.o
4+inv-icm42600-y += inv_icm42600_core.o
5+inv-icm42600-y += inv_icm42600_gyro.o
6+inv-icm42600-y += inv_icm42600_accel.o
7+inv-icm42600-y += inv_icm42600_temp.o
8+inv-icm42600-y += inv_icm42600_buffer.o
9+inv-icm42600-y += inv_icm42600_timestamp.o
10+
11+obj-$(CONFIG_INV_ICM42600_I2C) += inv-icm42600-i2c.o
12+inv-icm42600-i2c-y += inv_icm42600_i2c.o
13+
14+obj-$(CONFIG_INV_ICM42600_SPI) += inv-icm42600-spi.o
15+inv-icm42600-spi-y += inv_icm42600_spi.o
drivers/iio/imu/inv_icm42600/inv_icm42600.h+395−0
@@ -0,0 +1,395 @@
1+/* SPDX-License-Identifier: GPL-2.0-or-later */
2+/*
3+ * Copyright (C) 2020 Invensense, Inc.
4+ */
5+
6+#ifndef INV_ICM42600_H_
7+#define INV_ICM42600_H_
8+
9+#include <linux/bits.h>
10+#include <linux/bitfield.h>
11+#include <linux/regmap.h>
12+#include <linux/mutex.h>
13+#include <linux/regulator/consumer.h>
14+#include <linux/pm.h>
15+#include <linux/iio/iio.h>
16+
17+#include "inv_icm42600_buffer.h"
18+
19+enum inv_icm42600_chip {
20+ INV_CHIP_ICM42600,
21+ INV_CHIP_ICM42602,
22+ INV_CHIP_ICM42605,
23+ INV_CHIP_ICM42622,
24+ INV_CHIP_NB,
25+};
26+
27+/* serial bus slew rates */
28+enum inv_icm42600_slew_rate {
29+ INV_ICM42600_SLEW_RATE_20_60NS,
30+ INV_ICM42600_SLEW_RATE_12_36NS,
31+ INV_ICM42600_SLEW_RATE_6_18NS,
32+ INV_ICM42600_SLEW_RATE_4_12NS,
33+ INV_ICM42600_SLEW_RATE_2_6NS,
34+ INV_ICM42600_SLEW_RATE_INF_2NS,
35+};
36+
37+enum inv_icm42600_sensor_mode {
38+ INV_ICM42600_SENSOR_MODE_OFF,
39+ INV_ICM42600_SENSOR_MODE_STANDBY,
40+ INV_ICM42600_SENSOR_MODE_LOW_POWER,
41+ INV_ICM42600_SENSOR_MODE_LOW_NOISE,
42+ INV_ICM42600_SENSOR_MODE_NB,
43+};
44+
45+/* gyroscope fullscale values */
46+enum inv_icm42600_gyro_fs {
47+ INV_ICM42600_GYRO_FS_2000DPS,
48+ INV_ICM42600_GYRO_FS_1000DPS,
49+ INV_ICM42600_GYRO_FS_500DPS,
50+ INV_ICM42600_GYRO_FS_250DPS,
51+ INV_ICM42600_GYRO_FS_125DPS,
52+ INV_ICM42600_GYRO_FS_62_5DPS,
53+ INV_ICM42600_GYRO_FS_31_25DPS,
54+ INV_ICM42600_GYRO_FS_15_625DPS,
55+ INV_ICM42600_GYRO_FS_NB,
56+};
57+
58+/* accelerometer fullscale values */
59+enum inv_icm42600_accel_fs {
60+ INV_ICM42600_ACCEL_FS_16G,
61+ INV_ICM42600_ACCEL_FS_8G,
62+ INV_ICM42600_ACCEL_FS_4G,
63+ INV_ICM42600_ACCEL_FS_2G,
64+ INV_ICM42600_ACCEL_FS_NB,
65+};
66+
67+/* ODR suffixed by LN or LP are Low-Noise or Low-Power mode only */
68+enum inv_icm42600_odr {
69+ INV_ICM42600_ODR_8KHZ_LN = 3,
70+ INV_ICM42600_ODR_4KHZ_LN,
71+ INV_ICM42600_ODR_2KHZ_LN,
72+ INV_ICM42600_ODR_1KHZ_LN,
73+ INV_ICM42600_ODR_200HZ,
74+ INV_ICM42600_ODR_100HZ,
75+ INV_ICM42600_ODR_50HZ,
76+ INV_ICM42600_ODR_25HZ,
77+ INV_ICM42600_ODR_12_5HZ,
78+ INV_ICM42600_ODR_6_25HZ_LP,
79+ INV_ICM42600_ODR_3_125HZ_LP,
80+ INV_ICM42600_ODR_1_5625HZ_LP,
81+ INV_ICM42600_ODR_500HZ,
82+ INV_ICM42600_ODR_NB,
83+};
84+
85+enum inv_icm42600_filter {
86+ /* Low-Noise mode sensor data filter (3rd order filter by default) */
87+ INV_ICM42600_FILTER_BW_ODR_DIV_2,
88+
89+ /* Low-Power mode sensor data filter (averaging) */
90+ INV_ICM42600_FILTER_AVG_1X = 1,
91+ INV_ICM42600_FILTER_AVG_16X = 6,
92+};
93+
94+struct inv_icm42600_sensor_conf {
95+ int mode;
96+ int fs;
97+ int odr;
98+ int filter;
99+};
100+#define INV_ICM42600_SENSOR_CONF_INIT {-1, -1, -1, -1}
101+
102+struct inv_icm42600_conf {
103+ struct inv_icm42600_sensor_conf gyro;
104+ struct inv_icm42600_sensor_conf accel;
105+ bool temp_en;
106+};
107+
108+struct inv_icm42600_suspended {
109+ enum inv_icm42600_sensor_mode gyro;
110+ enum inv_icm42600_sensor_mode accel;
111+ bool temp;
112+};
113+
114+/**
115+ * struct inv_icm42600_state - driver state variables
116+ * @lock: lock for serializing multiple registers access.
117+ * @chip: chip identifier.
118+ * @name: chip name.
119+ * @map: regmap pointer.
120+ * @vdd_supply: VDD voltage regulator for the chip.
121+ * @vddio_supply: I/O voltage regulator for the chip.
122+ * @orientation: sensor chip orientation relative to main hardware.
123+ * @conf: chip sensors configurations.
124+ * @suspended: suspended sensors configuration.
125+ * @indio_gyro: gyroscope IIO device.
126+ * @indio_accel: accelerometer IIO device.
127+ * @buffer: data transfer buffer aligned for DMA.
128+ * @fifo: FIFO management structure.
129+ * @timestamp: interrupt timestamps.
130+ */
131+struct inv_icm42600_state {
132+ struct mutex lock;
133+ enum inv_icm42600_chip chip;
134+ const char *name;
135+ struct regmap *map;
136+ struct regulator *vdd_supply;
137+ struct regulator *vddio_supply;
138+ struct iio_mount_matrix orientation;
139+ struct inv_icm42600_conf conf;
140+ struct inv_icm42600_suspended suspended;
141+ struct iio_dev *indio_gyro;
142+ struct iio_dev *indio_accel;
143+ uint8_t buffer[2] ____cacheline_aligned;
144+ struct inv_icm42600_fifo fifo;
145+ struct {
146+ int64_t gyro;
147+ int64_t accel;
148+ } timestamp;
149+};
150+
151+/* Virtual register addresses: @bank on MSB (4 upper bits), @address on LSB */
152+
153+/* Bank selection register, available in all banks */
154+#define INV_ICM42600_REG_BANK_SEL 0x76
155+#define INV_ICM42600_BANK_SEL_MASK GENMASK(2, 0)
156+
157+/* User bank 0 (MSB 0x00) */
158+#define INV_ICM42600_REG_DEVICE_CONFIG 0x0011
159+#define INV_ICM42600_DEVICE_CONFIG_SOFT_RESET BIT(0)
160+
161+#define INV_ICM42600_REG_DRIVE_CONFIG 0x0013
162+#define INV_ICM42600_DRIVE_CONFIG_I2C_MASK GENMASK(5, 3)
163+#define INV_ICM42600_DRIVE_CONFIG_I2C(_rate) \
164+ FIELD_PREP(INV_ICM42600_DRIVE_CONFIG_I2C_MASK, (_rate))
165+#define INV_ICM42600_DRIVE_CONFIG_SPI_MASK GENMASK(2, 0)
166+#define INV_ICM42600_DRIVE_CONFIG_SPI(_rate) \
167+ FIELD_PREP(INV_ICM42600_DRIVE_CONFIG_SPI_MASK, (_rate))
168+
169+#define INV_ICM42600_REG_INT_CONFIG 0x0014
170+#define INV_ICM42600_INT_CONFIG_INT2_LATCHED BIT(5)
171+#define INV_ICM42600_INT_CONFIG_INT2_PUSH_PULL BIT(4)
172+#define INV_ICM42600_INT_CONFIG_INT2_ACTIVE_HIGH BIT(3)
173+#define INV_ICM42600_INT_CONFIG_INT2_ACTIVE_LOW 0x00
174+#define INV_ICM42600_INT_CONFIG_INT1_LATCHED BIT(2)
175+#define INV_ICM42600_INT_CONFIG_INT1_PUSH_PULL BIT(1)
176+#define INV_ICM42600_INT_CONFIG_INT1_ACTIVE_HIGH BIT(0)
177+#define INV_ICM42600_INT_CONFIG_INT1_ACTIVE_LOW 0x00
178+
179+#define INV_ICM42600_REG_FIFO_CONFIG 0x0016
180+#define INV_ICM42600_FIFO_CONFIG_MASK GENMASK(7, 6)
181+#define INV_ICM42600_FIFO_CONFIG_BYPASS \
182+ FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 0)
183+#define INV_ICM42600_FIFO_CONFIG_STREAM \
184+ FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 1)
185+#define INV_ICM42600_FIFO_CONFIG_STOP_ON_FULL \
186+ FIELD_PREP(INV_ICM42600_FIFO_CONFIG_MASK, 2)
187+
188+/* all sensor data are 16 bits (2 registers wide) in big-endian */
189+#define INV_ICM42600_REG_TEMP_DATA 0x001D
190+#define INV_ICM42600_REG_ACCEL_DATA_X 0x001F
191+#define INV_ICM42600_REG_ACCEL_DATA_Y 0x0021
192+#define INV_ICM42600_REG_ACCEL_DATA_Z 0x0023
193+#define INV_ICM42600_REG_GYRO_DATA_X 0x0025
194+#define INV_ICM42600_REG_GYRO_DATA_Y 0x0027
195+#define INV_ICM42600_REG_GYRO_DATA_Z 0x0029
196+#define INV_ICM42600_DATA_INVALID -32768
197+
198+#define INV_ICM42600_REG_INT_STATUS 0x002D
199+#define INV_ICM42600_INT_STATUS_UI_FSYNC BIT(6)
200+#define INV_ICM42600_INT_STATUS_PLL_RDY BIT(5)
201+#define INV_ICM42600_INT_STATUS_RESET_DONE BIT(4)
202+#define INV_ICM42600_INT_STATUS_DATA_RDY BIT(3)
203+#define INV_ICM42600_INT_STATUS_FIFO_THS BIT(2)
204+#define INV_ICM42600_INT_STATUS_FIFO_FULL BIT(1)
205+#define INV_ICM42600_INT_STATUS_AGC_RDY BIT(0)
206+
207+/*
208+ * FIFO access registers
209+ * FIFO count is 16 bits (2 registers) big-endian
210+ * FIFO data is a continuous read register to read FIFO content
211+ */
212+#define INV_ICM42600_REG_FIFO_COUNT 0x002E
213+#define INV_ICM42600_REG_FIFO_DATA 0x0030
214+
215+#define INV_ICM42600_REG_SIGNAL_PATH_RESET 0x004B
216+#define INV_ICM42600_SIGNAL_PATH_RESET_DMP_INIT_EN BIT(6)
217+#define INV_ICM42600_SIGNAL_PATH_RESET_DMP_MEM_RESET BIT(5)
218+#define INV_ICM42600_SIGNAL_PATH_RESET_RESET BIT(3)
219+#define INV_ICM42600_SIGNAL_PATH_RESET_TMST_STROBE BIT(2)
220+#define INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH BIT(1)
221+
222+/* default configuration: all data big-endian and fifo count in bytes */
223+#define INV_ICM42600_REG_INTF_CONFIG0 0x004C
224+#define INV_ICM42600_INTF_CONFIG0_FIFO_HOLD_LAST_DATA BIT(7)
225+#define INV_ICM42600_INTF_CONFIG0_FIFO_COUNT_REC BIT(6)
226+#define INV_ICM42600_INTF_CONFIG0_FIFO_COUNT_ENDIAN BIT(5)
227+#define INV_ICM42600_INTF_CONFIG0_SENSOR_DATA_ENDIAN BIT(4)
228+#define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK GENMASK(1, 0)
229+#define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_SPI_DIS \
230+ FIELD_PREP(INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK, 2)
231+#define INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_I2C_DIS \
232+ FIELD_PREP(INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK, 3)
233+
234+#define INV_ICM42600_REG_INTF_CONFIG1 0x004D
235+#define INV_ICM42600_INTF_CONFIG1_ACCEL_LP_CLK_RC BIT(3)
236+
237+#define INV_ICM42600_REG_PWR_MGMT0 0x004E
238+#define INV_ICM42600_PWR_MGMT0_TEMP_DIS BIT(5)
239+#define INV_ICM42600_PWR_MGMT0_IDLE BIT(4)
240+#define INV_ICM42600_PWR_MGMT0_GYRO(_mode) \
241+ FIELD_PREP(GENMASK(3, 2), (_mode))
242+#define INV_ICM42600_PWR_MGMT0_ACCEL(_mode) \
243+ FIELD_PREP(GENMASK(1, 0), (_mode))
244+
245+#define INV_ICM42600_REG_GYRO_CONFIG0 0x004F
246+#define INV_ICM42600_GYRO_CONFIG0_FS(_fs) \
247+ FIELD_PREP(GENMASK(7, 5), (_fs))
248+#define INV_ICM42600_GYRO_CONFIG0_ODR(_odr) \
249+ FIELD_PREP(GENMASK(3, 0), (_odr))
250+
251+#define INV_ICM42600_REG_ACCEL_CONFIG0 0x0050
252+#define INV_ICM42600_ACCEL_CONFIG0_FS(_fs) \
253+ FIELD_PREP(GENMASK(7, 5), (_fs))
254+#define INV_ICM42600_ACCEL_CONFIG0_ODR(_odr) \
255+ FIELD_PREP(GENMASK(3, 0), (_odr))
256+
257+#define INV_ICM42600_REG_GYRO_ACCEL_CONFIG0 0x0052
258+#define INV_ICM42600_GYRO_ACCEL_CONFIG0_ACCEL_FILT(_f) \
259+ FIELD_PREP(GENMASK(7, 4), (_f))
260+#define INV_ICM42600_GYRO_ACCEL_CONFIG0_GYRO_FILT(_f) \
261+ FIELD_PREP(GENMASK(3, 0), (_f))
262+
263+#define INV_ICM42600_REG_TMST_CONFIG 0x0054
264+#define INV_ICM42600_TMST_CONFIG_MASK GENMASK(4, 0)
265+#define INV_ICM42600_TMST_CONFIG_TMST_TO_REGS_EN BIT(4)
266+#define INV_ICM42600_TMST_CONFIG_TMST_RES_16US BIT(3)
267+#define INV_ICM42600_TMST_CONFIG_TMST_DELTA_EN BIT(2)
268+#define INV_ICM42600_TMST_CONFIG_TMST_FSYNC_EN BIT(1)
269+#define INV_ICM42600_TMST_CONFIG_TMST_EN BIT(0)
270+
271+#define INV_ICM42600_REG_FIFO_CONFIG1 0x005F
272+#define INV_ICM42600_FIFO_CONFIG1_RESUME_PARTIAL_RD BIT(6)
273+#define INV_ICM42600_FIFO_CONFIG1_WM_GT_TH BIT(5)
274+#define INV_ICM42600_FIFO_CONFIG1_TMST_FSYNC_EN BIT(3)
275+#define INV_ICM42600_FIFO_CONFIG1_TEMP_EN BIT(2)
276+#define INV_ICM42600_FIFO_CONFIG1_GYRO_EN BIT(1)
277+#define INV_ICM42600_FIFO_CONFIG1_ACCEL_EN BIT(0)
278+
279+/* FIFO watermark is 16 bits (2 registers wide) in little-endian */
280+#define INV_ICM42600_REG_FIFO_WATERMARK 0x0060
281+#define INV_ICM42600_FIFO_WATERMARK_VAL(_wm) \
282+ cpu_to_le16((_wm) & GENMASK(11, 0))
283+/* FIFO is 2048 bytes, let 12 samples for reading latency */
284+#define INV_ICM42600_FIFO_WATERMARK_MAX (2048 - 12 * 16)
285+
286+#define INV_ICM42600_REG_INT_CONFIG1 0x0064
287+#define INV_ICM42600_INT_CONFIG1_TPULSE_DURATION BIT(6)
288+#define INV_ICM42600_INT_CONFIG1_TDEASSERT_DISABLE BIT(5)
289+#define INV_ICM42600_INT_CONFIG1_ASYNC_RESET BIT(4)
290+
291+#define INV_ICM42600_REG_INT_SOURCE0 0x0065
292+#define INV_ICM42600_INT_SOURCE0_UI_FSYNC_INT1_EN BIT(6)
293+#define INV_ICM42600_INT_SOURCE0_PLL_RDY_INT1_EN BIT(5)
294+#define INV_ICM42600_INT_SOURCE0_RESET_DONE_INT1_EN BIT(4)
295+#define INV_ICM42600_INT_SOURCE0_UI_DRDY_INT1_EN BIT(3)
296+#define INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN BIT(2)
297+#define INV_ICM42600_INT_SOURCE0_FIFO_FULL_INT1_EN BIT(1)
298+#define INV_ICM42600_INT_SOURCE0_UI_AGC_RDY_INT1_EN BIT(0)
299+
300+#define INV_ICM42600_REG_WHOAMI 0x0075
301+#define INV_ICM42600_WHOAMI_ICM42600 0x40
302+#define INV_ICM42600_WHOAMI_ICM42602 0x41
303+#define INV_ICM42600_WHOAMI_ICM42605 0x42
304+#define INV_ICM42600_WHOAMI_ICM42622 0x46
305+
306+/* User bank 1 (MSB 0x10) */
307+#define INV_ICM42600_REG_SENSOR_CONFIG0 0x1003
308+#define INV_ICM42600_SENSOR_CONFIG0_ZG_DISABLE BIT(5)
309+#define INV_ICM42600_SENSOR_CONFIG0_YG_DISABLE BIT(4)
310+#define INV_ICM42600_SENSOR_CONFIG0_XG_DISABLE BIT(3)
311+#define INV_ICM42600_SENSOR_CONFIG0_ZA_DISABLE BIT(2)
312+#define INV_ICM42600_SENSOR_CONFIG0_YA_DISABLE BIT(1)
313+#define INV_ICM42600_SENSOR_CONFIG0_XA_DISABLE BIT(0)
314+
315+/* Timestamp value is 20 bits (3 registers) in little-endian */
316+#define INV_ICM42600_REG_TMSTVAL 0x1062
317+#define INV_ICM42600_TMSTVAL_MASK GENMASK(19, 0)
318+
319+#define INV_ICM42600_REG_INTF_CONFIG4 0x107A
320+#define INV_ICM42600_INTF_CONFIG4_I3C_BUS_ONLY BIT(6)
321+#define INV_ICM42600_INTF_CONFIG4_SPI_AP_4WIRE BIT(1)
322+
323+#define INV_ICM42600_REG_INTF_CONFIG6 0x107C
324+#define INV_ICM42600_INTF_CONFIG6_MASK GENMASK(4, 0)
325+#define INV_ICM42600_INTF_CONFIG6_I3C_EN BIT(4)
326+#define INV_ICM42600_INTF_CONFIG6_I3C_IBI_BYTE_EN BIT(3)
327+#define INV_ICM42600_INTF_CONFIG6_I3C_IBI_EN BIT(2)
328+#define INV_ICM42600_INTF_CONFIG6_I3C_DDR_EN BIT(1)
329+#define INV_ICM42600_INTF_CONFIG6_I3C_SDR_EN BIT(0)
330+
331+/* User bank 4 (MSB 0x40) */
332+#define INV_ICM42600_REG_INT_SOURCE8 0x404F
333+#define INV_ICM42600_INT_SOURCE8_FSYNC_IBI_EN BIT(5)
334+#define INV_ICM42600_INT_SOURCE8_PLL_RDY_IBI_EN BIT(4)
335+#define INV_ICM42600_INT_SOURCE8_UI_DRDY_IBI_EN BIT(3)
336+#define INV_ICM42600_INT_SOURCE8_FIFO_THS_IBI_EN BIT(2)
337+#define INV_ICM42600_INT_SOURCE8_FIFO_FULL_IBI_EN BIT(1)
338+#define INV_ICM42600_INT_SOURCE8_AGC_RDY_IBI_EN BIT(0)
339+
340+#define INV_ICM42600_REG_OFFSET_USER0 0x4077
341+#define INV_ICM42600_REG_OFFSET_USER1 0x4078
342+#define INV_ICM42600_REG_OFFSET_USER2 0x4079
343+#define INV_ICM42600_REG_OFFSET_USER3 0x407A
344+#define INV_ICM42600_REG_OFFSET_USER4 0x407B
345+#define INV_ICM42600_REG_OFFSET_USER5 0x407C
346+#define INV_ICM42600_REG_OFFSET_USER6 0x407D
347+#define INV_ICM42600_REG_OFFSET_USER7 0x407E
348+#define INV_ICM42600_REG_OFFSET_USER8 0x407F
349+
350+/* Sleep times required by the driver */
351+#define INV_ICM42600_POWER_UP_TIME_MS 100
352+#define INV_ICM42600_RESET_TIME_MS 1
353+#define INV_ICM42600_ACCEL_STARTUP_TIME_MS 20
354+#define INV_ICM42600_GYRO_STARTUP_TIME_MS 60
355+#define INV_ICM42600_GYRO_STOP_TIME_MS 150
356+#define INV_ICM42600_TEMP_STARTUP_TIME_MS 14
357+#define INV_ICM42600_SUSPEND_DELAY_MS 2000
358+
359+typedef int (*inv_icm42600_bus_setup)(struct inv_icm42600_state *);
360+
361+extern const struct regmap_config inv_icm42600_regmap_config;
362+extern const struct dev_pm_ops inv_icm42600_pm_ops;
363+
364+const struct iio_mount_matrix *
365+inv_icm42600_get_mount_matrix(const struct iio_dev *indio_dev,
366+ const struct iio_chan_spec *chan);
367+
368+uint32_t inv_icm42600_odr_to_period(enum inv_icm42600_odr odr);
369+
370+int inv_icm42600_set_accel_conf(struct inv_icm42600_state *st,
371+ struct inv_icm42600_sensor_conf *conf,
372+ unsigned int *sleep_ms);
373+
374+int inv_icm42600_set_gyro_conf(struct inv_icm42600_state *st,
375+ struct inv_icm42600_sensor_conf *conf,
376+ unsigned int *sleep_ms);
377+
378+int inv_icm42600_set_temp_conf(struct inv_icm42600_state *st, bool enable,
379+ unsigned int *sleep_ms);
380+
381+int inv_icm42600_debugfs_reg(struct iio_dev *indio_dev, unsigned int reg,
382+ unsigned int writeval, unsigned int *readval);
383+
384+int inv_icm42600_core_probe(struct regmap *regmap, int chip, int irq,
385+ inv_icm42600_bus_setup bus_setup);
386+
387+struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st);
388+
389+int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev);
390+
391+struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st);
392+
393+int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev);
394+
395+#endif
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c+787−0
@@ -0,0 +1,787 @@
1+// SPDX-License-Identifier: GPL-2.0-or-later
2+/*
3+ * Copyright (C) 2020 Invensense, Inc.
4+ */
5+
6+#include <linux/kernel.h>
7+#include <linux/device.h>
8+#include <linux/mutex.h>
9+#include <linux/pm_runtime.h>
10+#include <linux/regmap.h>
11+#include <linux/delay.h>
12+#include <linux/math64.h>
13+#include <linux/iio/iio.h>
14+#include <linux/iio/buffer.h>
15+#include <linux/iio/kfifo_buf.h>
16+
17+#include "inv_icm42600.h"
18+#include "inv_icm42600_temp.h"
19+#include "inv_icm42600_buffer.h"
20+#include "inv_icm42600_timestamp.h"
21+
22+#define INV_ICM42600_ACCEL_CHAN(_modifier, _index, _ext_info) \
23+ { \
24+ .type = IIO_ACCEL, \
25+ .modified = 1, \
26+ .channel2 = _modifier, \
27+ .info_mask_separate = \
28+ BIT(IIO_CHAN_INFO_RAW) | \
29+ BIT(IIO_CHAN_INFO_CALIBBIAS), \
30+ .info_mask_shared_by_type = \
31+ BIT(IIO_CHAN_INFO_SCALE), \
32+ .info_mask_shared_by_type_available = \
33+ BIT(IIO_CHAN_INFO_SCALE) | \
34+ BIT(IIO_CHAN_INFO_CALIBBIAS), \
35+ .info_mask_shared_by_all = \
36+ BIT(IIO_CHAN_INFO_SAMP_FREQ), \
37+ .info_mask_shared_by_all_available = \
38+ BIT(IIO_CHAN_INFO_SAMP_FREQ), \
39+ .scan_index = _index, \
40+ .scan_type = { \
41+ .sign = 's', \
42+ .realbits = 16, \
43+ .storagebits = 16, \
44+ .endianness = IIO_BE, \
45+ }, \
46+ .ext_info = _ext_info, \
47+ }
48+
49+enum inv_icm42600_accel_scan {
50+ INV_ICM42600_ACCEL_SCAN_X,
51+ INV_ICM42600_ACCEL_SCAN_Y,
52+ INV_ICM42600_ACCEL_SCAN_Z,
53+ INV_ICM42600_ACCEL_SCAN_TEMP,
54+ INV_ICM42600_ACCEL_SCAN_TIMESTAMP,
55+};
56+
57+static const struct iio_chan_spec_ext_info inv_icm42600_accel_ext_infos[] = {
58+ IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, inv_icm42600_get_mount_matrix),
59+ {},
60+};
61+
62+static const struct iio_chan_spec inv_icm42600_accel_channels[] = {
63+ INV_ICM42600_ACCEL_CHAN(IIO_MOD_X, INV_ICM42600_ACCEL_SCAN_X,
64+ inv_icm42600_accel_ext_infos),
65+ INV_ICM42600_ACCEL_CHAN(IIO_MOD_Y, INV_ICM42600_ACCEL_SCAN_Y,
66+ inv_icm42600_accel_ext_infos),
67+ INV_ICM42600_ACCEL_CHAN(IIO_MOD_Z, INV_ICM42600_ACCEL_SCAN_Z,
68+ inv_icm42600_accel_ext_infos),
69+ INV_ICM42600_TEMP_CHAN(INV_ICM42600_ACCEL_SCAN_TEMP),
70+ IIO_CHAN_SOFT_TIMESTAMP(INV_ICM42600_ACCEL_SCAN_TIMESTAMP),
71+};
72+
73+/*
74+ * IIO buffer data: size must be a power of 2 and timestamp aligned
75+ * 16 bytes: 6 bytes acceleration, 2 bytes temperature, 8 bytes timestamp
76+ */
77+struct inv_icm42600_accel_buffer {
78+ struct inv_icm42600_fifo_sensor_data accel;
79+ int16_t temp;
80+ int64_t timestamp __aligned(8);
81+};
82+
83+#define INV_ICM42600_SCAN_MASK_ACCEL_3AXIS \
84+ (BIT(INV_ICM42600_ACCEL_SCAN_X) | \
85+ BIT(INV_ICM42600_ACCEL_SCAN_Y) | \
86+ BIT(INV_ICM42600_ACCEL_SCAN_Z))
87+
88+#define INV_ICM42600_SCAN_MASK_TEMP BIT(INV_ICM42600_ACCEL_SCAN_TEMP)
89+
90+static const unsigned long inv_icm42600_accel_scan_masks[] = {
91+ /* 3-axis accel + temperature */
92+ INV_ICM42600_SCAN_MASK_ACCEL_3AXIS | INV_ICM42600_SCAN_MASK_TEMP,
93+ 0,
94+};
95+
96+/* enable accelerometer sensor and FIFO write */
97+static int inv_icm42600_accel_update_scan_mode(struct iio_dev *indio_dev,
98+ const unsigned long *scan_mask)
99+{
100+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
101+ struct inv_icm42600_timestamp *ts = iio_priv(indio_dev);
102+ struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
103+ unsigned int fifo_en = 0;
104+ unsigned int sleep_temp = 0;
105+ unsigned int sleep_accel = 0;
106+ unsigned int sleep;
107+ int ret;
108+
109+ mutex_lock(&st->lock);
110+
111+ if (*scan_mask & INV_ICM42600_SCAN_MASK_TEMP) {
112+ /* enable temp sensor */
113+ ret = inv_icm42600_set_temp_conf(st, true, &sleep_temp);
114+ if (ret)
115+ goto out_unlock;
116+ fifo_en |= INV_ICM42600_SENSOR_TEMP;
117+ }
118+
119+ if (*scan_mask & INV_ICM42600_SCAN_MASK_ACCEL_3AXIS) {
120+ /* enable accel sensor */
121+ conf.mode = INV_ICM42600_SENSOR_MODE_LOW_NOISE;
122+ ret = inv_icm42600_set_accel_conf(st, &conf, &sleep_accel);
123+ if (ret)
124+ goto out_unlock;
125+ fifo_en |= INV_ICM42600_SENSOR_ACCEL;
126+ }
127+
128+ /* update data FIFO write */
129+ inv_icm42600_timestamp_apply_odr(ts, 0, 0, 0);
130+ ret = inv_icm42600_buffer_set_fifo_en(st, fifo_en | st->fifo.en);
131+ if (ret)
132+ goto out_unlock;
133+
134+ ret = inv_icm42600_buffer_update_watermark(st);
135+
136+out_unlock:
137+ mutex_unlock(&st->lock);
138+ /* sleep maximum required time */
139+ if (sleep_accel > sleep_temp)
140+ sleep = sleep_accel;
141+ else
142+ sleep = sleep_temp;
143+ if (sleep)
144+ msleep(sleep);
145+ return ret;
146+}
147+
148+static int inv_icm42600_accel_read_sensor(struct inv_icm42600_state *st,
149+ struct iio_chan_spec const *chan,
150+ int16_t *val)
151+{
152+ struct device *dev = regmap_get_device(st->map);
153+ struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
154+ unsigned int reg;
155+ __be16 *data;
156+ int ret;
157+
158+ if (chan->type != IIO_ACCEL)
159+ return -EINVAL;
160+
161+ switch (chan->channel2) {
162+ case IIO_MOD_X:
163+ reg = INV_ICM42600_REG_ACCEL_DATA_X;
164+ break;
165+ case IIO_MOD_Y:
166+ reg = INV_ICM42600_REG_ACCEL_DATA_Y;
167+ break;
168+ case IIO_MOD_Z:
169+ reg = INV_ICM42600_REG_ACCEL_DATA_Z;
170+ break;
171+ default:
172+ return -EINVAL;
173+ }
174+
175+ pm_runtime_get_sync(dev);
176+ mutex_lock(&st->lock);
177+
178+ /* enable accel sensor */
179+ conf.mode = INV_ICM42600_SENSOR_MODE_LOW_NOISE;
180+ ret = inv_icm42600_set_accel_conf(st, &conf, NULL);
181+ if (ret)
182+ goto exit;
183+
184+ /* read accel register data */
185+ data = (__be16 *)&st->buffer[0];
186+ ret = regmap_bulk_read(st->map, reg, data, sizeof(*data));
187+ if (ret)
188+ goto exit;
189+
190+ *val = (int16_t)be16_to_cpup(data);
191+ if (*val == INV_ICM42600_DATA_INVALID)
192+ ret = -EINVAL;
193+exit:
194+ mutex_unlock(&st->lock);
195+ pm_runtime_mark_last_busy(dev);
196+ pm_runtime_put_autosuspend(dev);
197+ return ret;
198+}
199+
200+/* IIO format int + nano */
201+static const int inv_icm42600_accel_scale[] = {
202+ /* +/- 16G => 0.004788403 m/s-2 */
203+ [2 * INV_ICM42600_ACCEL_FS_16G] = 0,
204+ [2 * INV_ICM42600_ACCEL_FS_16G + 1] = 4788403,
205+ /* +/- 8G => 0.002394202 m/s-2 */
206+ [2 * INV_ICM42600_ACCEL_FS_8G] = 0,
207+ [2 * INV_ICM42600_ACCEL_FS_8G + 1] = 2394202,
208+ /* +/- 4G => 0.001197101 m/s-2 */
209+ [2 * INV_ICM42600_ACCEL_FS_4G] = 0,
210+ [2 * INV_ICM42600_ACCEL_FS_4G + 1] = 1197101,
211+ /* +/- 2G => 0.000598550 m/s-2 */
212+ [2 * INV_ICM42600_ACCEL_FS_2G] = 0,
213+ [2 * INV_ICM42600_ACCEL_FS_2G + 1] = 598550,
214+};
215+
216+static int inv_icm42600_accel_read_scale(struct inv_icm42600_state *st,
217+ int *val, int *val2)
218+{
219+ unsigned int idx;
220+
221+ idx = st->conf.accel.fs;
222+
223+ *val = inv_icm42600_accel_scale[2 * idx];
224+ *val2 = inv_icm42600_accel_scale[2 * idx + 1];
225+ return IIO_VAL_INT_PLUS_NANO;
226+}
227+
228+static int inv_icm42600_accel_write_scale(struct inv_icm42600_state *st,
229+ int val, int val2)
230+{
231+ struct device *dev = regmap_get_device(st->map);
232+ unsigned int idx;
233+ struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
234+ int ret;
235+
236+ for (idx = 0; idx < ARRAY_SIZE(inv_icm42600_accel_scale); idx += 2) {
237+ if (val == inv_icm42600_accel_scale[idx] &&
238+ val2 == inv_icm42600_accel_scale[idx + 1])
239+ break;
240+ }
241+ if (idx >= ARRAY_SIZE(inv_icm42600_accel_scale))
242+ return -EINVAL;
243+
244+ conf.fs = idx / 2;
245+
246+ pm_runtime_get_sync(dev);
247+ mutex_lock(&st->lock);
248+
249+ ret = inv_icm42600_set_accel_conf(st, &conf, NULL);
250+
251+ mutex_unlock(&st->lock);
252+ pm_runtime_mark_last_busy(dev);
253+ pm_runtime_put_autosuspend(dev);
254+
255+ return ret;
256+}
257+
258+/* IIO format int + micro */
259+static const int inv_icm42600_accel_odr[] = {
260+ /* 12.5Hz */
261+ 12, 500000,
262+ /* 25Hz */
263+ 25, 0,
264+ /* 50Hz */
265+ 50, 0,
266+ /* 100Hz */
267+ 100, 0,
268+ /* 200Hz */
269+ 200, 0,
270+ /* 1kHz */
271+ 1000, 0,
272+ /* 2kHz */
273+ 2000, 0,
274+ /* 4kHz */
275+ 4000, 0,
276+};
277+
278+static const int inv_icm42600_accel_odr_conv[] = {
279+ INV_ICM42600_ODR_12_5HZ,
280+ INV_ICM42600_ODR_25HZ,
281+ INV_ICM42600_ODR_50HZ,
282+ INV_ICM42600_ODR_100HZ,
283+ INV_ICM42600_ODR_200HZ,
284+ INV_ICM42600_ODR_1KHZ_LN,
285+ INV_ICM42600_ODR_2KHZ_LN,
286+ INV_ICM42600_ODR_4KHZ_LN,
287+};
288+
289+static int inv_icm42600_accel_read_odr(struct inv_icm42600_state *st,
290+ int *val, int *val2)
291+{
292+ unsigned int odr;
293+ unsigned int i;
294+
295+ odr = st->conf.accel.odr;
296+
297+ for (i = 0; i < ARRAY_SIZE(inv_icm42600_accel_odr_conv); ++i) {
298+ if (inv_icm42600_accel_odr_conv[i] == odr)
299+ break;
300+ }
301+ if (i >= ARRAY_SIZE(inv_icm42600_accel_odr_conv))
302+ return -EINVAL;
303+
304+ *val = inv_icm42600_accel_odr[2 * i];
305+ *val2 = inv_icm42600_accel_odr[2 * i + 1];
306+
307+ return IIO_VAL_INT_PLUS_MICRO;
308+}
309+
310+static int inv_icm42600_accel_write_odr(struct iio_dev *indio_dev,
311+ int val, int val2)
312+{
313+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
314+ struct inv_icm42600_timestamp *ts = iio_priv(indio_dev);
315+ struct device *dev = regmap_get_device(st->map);
316+ unsigned int idx;
317+ struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
318+ int ret;
319+
320+ for (idx = 0; idx < ARRAY_SIZE(inv_icm42600_accel_odr); idx += 2) {
321+ if (val == inv_icm42600_accel_odr[idx] &&
322+ val2 == inv_icm42600_accel_odr[idx + 1])
323+ break;
324+ }
325+ if (idx >= ARRAY_SIZE(inv_icm42600_accel_odr))
326+ return -EINVAL;
327+
328+ conf.odr = inv_icm42600_accel_odr_conv[idx / 2];
329+
330+ pm_runtime_get_sync(dev);
331+ mutex_lock(&st->lock);
332+
333+ ret = inv_icm42600_timestamp_update_odr(ts, inv_icm42600_odr_to_period(conf.odr),
334+ iio_buffer_enabled(indio_dev));
335+ if (ret)
336+ goto out_unlock;
337+
338+ ret = inv_icm42600_set_accel_conf(st, &conf, NULL);
339+ if (ret)
340+ goto out_unlock;
341+ inv_icm42600_buffer_update_fifo_period(st);
342+ inv_icm42600_buffer_update_watermark(st);
343+
344+out_unlock:
345+ mutex_unlock(&st->lock);
346+ pm_runtime_mark_last_busy(dev);
347+ pm_runtime_put_autosuspend(dev);
348+
349+ return ret;
350+}
351+
352+/*
353+ * Calibration bias values, IIO range format int + micro.
354+ * Value is limited to +/-1g coded on 12 bits signed. Step is 0.5mg.
355+ */
356+static int inv_icm42600_accel_calibbias[] = {
357+ -10, 42010, /* min: -10.042010 m/s² */
358+ 0, 4903, /* step: 0.004903 m/s² */
359+ 10, 37106, /* max: 10.037106 m/s² */
360+};
361+
362+static int inv_icm42600_accel_read_offset(struct inv_icm42600_state *st,
363+ struct iio_chan_spec const *chan,
364+ int *val, int *val2)
365+{
366+ struct device *dev = regmap_get_device(st->map);
367+ int64_t val64;
368+ int32_t bias;
369+ unsigned int reg;
370+ int16_t offset;
371+ uint8_t data[2];
372+ int ret;
373+
374+ if (chan->type != IIO_ACCEL)
375+ return -EINVAL;
376+
377+ switch (chan->channel2) {
378+ case IIO_MOD_X:
379+ reg = INV_ICM42600_REG_OFFSET_USER4;
380+ break;
381+ case IIO_MOD_Y:
382+ reg = INV_ICM42600_REG_OFFSET_USER6;
383+ break;
384+ case IIO_MOD_Z:
385+ reg = INV_ICM42600_REG_OFFSET_USER7;
386+ break;
387+ default:
388+ return -EINVAL;
389+ }
390+
391+ pm_runtime_get_sync(dev);
392+ mutex_lock(&st->lock);
393+
394+ ret = regmap_bulk_read(st->map, reg, st->buffer, sizeof(data));
395+ memcpy(data, st->buffer, sizeof(data));
396+
397+ mutex_unlock(&st->lock);
398+ pm_runtime_mark_last_busy(dev);
399+ pm_runtime_put_autosuspend(dev);
400+ if (ret)
401+ return ret;
402+
403+ /* 12 bits signed value */
404+ switch (chan->channel2) {
405+ case IIO_MOD_X:
406+ offset = sign_extend32(((data[0] & 0xF0) << 4) | data[1], 11);
407+ break;
408+ case IIO_MOD_Y:
409+ offset = sign_extend32(((data[1] & 0x0F) << 8) | data[0], 11);
410+ break;
411+ case IIO_MOD_Z:
412+ offset = sign_extend32(((data[0] & 0xF0) << 4) | data[1], 11);
413+ break;
414+ default:
415+ return -EINVAL;
416+ }
417+
418+ /*
419+ * convert raw offset to g then to m/s²
420+ * 12 bits signed raw step 0.5mg to g: 5 / 10000
421+ * g to m/s²: 9.806650
422+ * result in micro (1000000)
423+ * (offset * 5 * 9.806650 * 1000000) / 10000
424+ */
425+ val64 = (int64_t)offset * 5LL * 9806650LL;
426+ /* for rounding, add + or - divisor (10000) divided by 2 */
427+ if (val64 >= 0)
428+ val64 += 10000LL / 2LL;
429+ else
430+ val64 -= 10000LL / 2LL;
431+ bias = div_s64(val64, 10000L);
432+ *val = bias / 1000000L;
433+ *val2 = bias % 1000000L;
434+
435+ return IIO_VAL_INT_PLUS_MICRO;
436+}
437+
438+static int inv_icm42600_accel_write_offset(struct inv_icm42600_state *st,
439+ struct iio_chan_spec const *chan,
440+ int val, int val2)
441+{
442+ struct device *dev = regmap_get_device(st->map);
443+ int64_t val64;
444+ int32_t min, max;
445+ unsigned int reg, regval;
446+ int16_t offset;
447+ int ret;
448+
449+ if (chan->type != IIO_ACCEL)
450+ return -EINVAL;
451+
452+ switch (chan->channel2) {
453+ case IIO_MOD_X:
454+ reg = INV_ICM42600_REG_OFFSET_USER4;
455+ break;
456+ case IIO_MOD_Y:
457+ reg = INV_ICM42600_REG_OFFSET_USER6;
458+ break;
459+ case IIO_MOD_Z:
460+ reg = INV_ICM42600_REG_OFFSET_USER7;
461+ break;
462+ default:
463+ return -EINVAL;
464+ }
465+
466+ /* inv_icm42600_accel_calibbias: min - step - max in micro */
467+ min = inv_icm42600_accel_calibbias[0] * 1000000L +
468+ inv_icm42600_accel_calibbias[1];
469+ max = inv_icm42600_accel_calibbias[4] * 1000000L +
470+ inv_icm42600_accel_calibbias[5];
471+ val64 = (int64_t)val * 1000000LL + (int64_t)val2;
472+ if (val64 < min || val64 > max)
473+ return -EINVAL;
474+
475+ /*
476+ * convert m/s² to g then to raw value
477+ * m/s² to g: 1 / 9.806650
478+ * g to raw 12 bits signed, step 0.5mg: 10000 / 5
479+ * val in micro (1000000)
480+ * val * 10000 / (9.806650 * 1000000 * 5)
481+ */
482+ val64 = val64 * 10000LL;
483+ /* for rounding, add + or - divisor (9806650 * 5) divided by 2 */
484+ if (val64 >= 0)
485+ val64 += 9806650 * 5 / 2;
486+ else
487+ val64 -= 9806650 * 5 / 2;
488+ offset = div_s64(val64, 9806650 * 5);
489+
490+ /* clamp value limited to 12 bits signed */
491+ if (offset < -2048)
492+ offset = -2048;
493+ else if (offset > 2047)
494+ offset = 2047;
495+
496+ pm_runtime_get_sync(dev);
497+ mutex_lock(&st->lock);
498+
499+ switch (chan->channel2) {
500+ case IIO_MOD_X:
501+ /* OFFSET_USER4 register is shared */
502+ ret = regmap_read(st->map, INV_ICM42600_REG_OFFSET_USER4,
503+ &regval);
504+ if (ret)
505+ goto out_unlock;
506+ st->buffer[0] = ((offset & 0xF00) >> 4) | (regval & 0x0F);
507+ st->buffer[1] = offset & 0xFF;
508+ break;
509+ case IIO_MOD_Y:
510+ /* OFFSET_USER7 register is shared */
511+ ret = regmap_read(st->map, INV_ICM42600_REG_OFFSET_USER7,
512+ &regval);
513+ if (ret)
514+ goto out_unlock;
515+ st->buffer[0] = offset & 0xFF;
516+ st->buffer[1] = ((offset & 0xF00) >> 8) | (regval & 0xF0);
517+ break;
518+ case IIO_MOD_Z:
519+ /* OFFSET_USER7 register is shared */
520+ ret = regmap_read(st->map, INV_ICM42600_REG_OFFSET_USER7,
521+ &regval);
522+ if (ret)
523+ goto out_unlock;
524+ st->buffer[0] = ((offset & 0xF00) >> 4) | (regval & 0x0F);
525+ st->buffer[1] = offset & 0xFF;
526+ break;
527+ default:
528+ ret = -EINVAL;
529+ goto out_unlock;
530+ }
531+
532+ ret = regmap_bulk_write(st->map, reg, st->buffer, 2);
533+
534+out_unlock:
535+ mutex_unlock(&st->lock);
536+ pm_runtime_mark_last_busy(dev);
537+ pm_runtime_put_autosuspend(dev);
538+ return ret;
539+}
540+
541+static int inv_icm42600_accel_read_raw(struct iio_dev *indio_dev,
542+ struct iio_chan_spec const *chan,
543+ int *val, int *val2, long mask)
544+{
545+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
546+ int16_t data;
547+ int ret;
548+
549+ switch (chan->type) {
550+ case IIO_ACCEL:
551+ break;
552+ case IIO_TEMP:
553+ return inv_icm42600_temp_read_raw(indio_dev, chan, val, val2, mask);
554+ default:
555+ return -EINVAL;
556+ }
557+
558+ switch (mask) {
559+ case IIO_CHAN_INFO_RAW:
560+ ret = iio_device_claim_direct_mode(indio_dev);
561+ if (ret)
562+ return ret;
563+ ret = inv_icm42600_accel_read_sensor(st, chan, &data);
564+ iio_device_release_direct_mode(indio_dev);
565+ if (ret)
566+ return ret;
567+ *val = data;
568+ return IIO_VAL_INT;
569+ case IIO_CHAN_INFO_SCALE:
570+ return inv_icm42600_accel_read_scale(st, val, val2);
571+ case IIO_CHAN_INFO_SAMP_FREQ:
572+ return inv_icm42600_accel_read_odr(st, val, val2);
573+ case IIO_CHAN_INFO_CALIBBIAS:
574+ return inv_icm42600_accel_read_offset(st, chan, val, val2);
575+ default:
576+ return -EINVAL;
577+ }
578+}
579+
580+static int inv_icm42600_accel_read_avail(struct iio_dev *indio_dev,
581+ struct iio_chan_spec const *chan,
582+ const int **vals,
583+ int *type, int *length, long mask)
584+{
585+ if (chan->type != IIO_ACCEL)
586+ return -EINVAL;
587+
588+ switch (mask) {
589+ case IIO_CHAN_INFO_SCALE:
590+ *vals = inv_icm42600_accel_scale;
591+ *type = IIO_VAL_INT_PLUS_NANO;
592+ *length = ARRAY_SIZE(inv_icm42600_accel_scale);
593+ return IIO_AVAIL_LIST;
594+ case IIO_CHAN_INFO_SAMP_FREQ:
595+ *vals = inv_icm42600_accel_odr;
596+ *type = IIO_VAL_INT_PLUS_MICRO;
597+ *length = ARRAY_SIZE(inv_icm42600_accel_odr);
598+ return IIO_AVAIL_LIST;
599+ case IIO_CHAN_INFO_CALIBBIAS:
600+ *vals = inv_icm42600_accel_calibbias;
601+ *type = IIO_VAL_INT_PLUS_MICRO;
602+ return IIO_AVAIL_RANGE;
603+ default:
604+ return -EINVAL;
605+ }
606+}
607+
608+static int inv_icm42600_accel_write_raw(struct iio_dev *indio_dev,
609+ struct iio_chan_spec const *chan,
610+ int val, int val2, long mask)
611+{
612+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
613+ int ret;
614+
615+ if (chan->type != IIO_ACCEL)
616+ return -EINVAL;
617+
618+ switch (mask) {
619+ case IIO_CHAN_INFO_SCALE:
620+ ret = iio_device_claim_direct_mode(indio_dev);
621+ if (ret)
622+ return ret;
623+ ret = inv_icm42600_accel_write_scale(st, val, val2);
624+ iio_device_release_direct_mode(indio_dev);
625+ return ret;
626+ case IIO_CHAN_INFO_SAMP_FREQ:
627+ return inv_icm42600_accel_write_odr(indio_dev, val, val2);
628+ case IIO_CHAN_INFO_CALIBBIAS:
629+ ret = iio_device_claim_direct_mode(indio_dev);
630+ if (ret)
631+ return ret;
632+ ret = inv_icm42600_accel_write_offset(st, chan, val, val2);
633+ iio_device_release_direct_mode(indio_dev);
634+ return ret;
635+ default:
636+ return -EINVAL;
637+ }
638+}
639+
640+static int inv_icm42600_accel_write_raw_get_fmt(struct iio_dev *indio_dev,
641+ struct iio_chan_spec const *chan,
642+ long mask)
643+{
644+ if (chan->type != IIO_ACCEL)
645+ return -EINVAL;
646+
647+ switch (mask) {
648+ case IIO_CHAN_INFO_SCALE:
649+ return IIO_VAL_INT_PLUS_NANO;
650+ case IIO_CHAN_INFO_SAMP_FREQ:
651+ return IIO_VAL_INT_PLUS_MICRO;
652+ case IIO_CHAN_INFO_CALIBBIAS:
653+ return IIO_VAL_INT_PLUS_MICRO;
654+ default:
655+ return -EINVAL;
656+ }
657+}
658+
659+static int inv_icm42600_accel_hwfifo_set_watermark(struct iio_dev *indio_dev,
660+ unsigned int val)
661+{
662+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
663+ int ret;
664+
665+ mutex_lock(&st->lock);
666+
667+ st->fifo.watermark.accel = val;
668+ ret = inv_icm42600_buffer_update_watermark(st);
669+
670+ mutex_unlock(&st->lock);
671+
672+ return ret;
673+}
674+
675+static int inv_icm42600_accel_hwfifo_flush(struct iio_dev *indio_dev,
676+ unsigned int count)
677+{
678+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
679+ int ret;
680+
681+ if (count == 0)
682+ return 0;
683+
684+ mutex_lock(&st->lock);
685+
686+ ret = inv_icm42600_buffer_hwfifo_flush(st, count);
687+ if (!ret)
688+ ret = st->fifo.nb.accel;
689+
690+ mutex_unlock(&st->lock);
691+
692+ return ret;
693+}
694+
695+static const struct iio_info inv_icm42600_accel_info = {
696+ .read_raw = inv_icm42600_accel_read_raw,
697+ .read_avail = inv_icm42600_accel_read_avail,
698+ .write_raw = inv_icm42600_accel_write_raw,
699+ .write_raw_get_fmt = inv_icm42600_accel_write_raw_get_fmt,
700+ .debugfs_reg_access = inv_icm42600_debugfs_reg,
701+ .update_scan_mode = inv_icm42600_accel_update_scan_mode,
702+ .hwfifo_set_watermark = inv_icm42600_accel_hwfifo_set_watermark,
703+ .hwfifo_flush_to_buffer = inv_icm42600_accel_hwfifo_flush,
704+};
705+
706+struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st)
707+{
708+ struct device *dev = regmap_get_device(st->map);
709+ const char *name;
710+ struct inv_icm42600_timestamp *ts;
711+ struct iio_dev *indio_dev;
712+ struct iio_buffer *buffer;
713+ int ret;
714+
715+ name = devm_kasprintf(dev, GFP_KERNEL, "%s-accel", st->name);
716+ if (!name)
717+ return ERR_PTR(-ENOMEM);
718+
719+ indio_dev = devm_iio_device_alloc(dev, sizeof(*ts));
720+ if (!indio_dev)
721+ return ERR_PTR(-ENOMEM);
722+
723+ buffer = devm_iio_kfifo_allocate(dev);
724+ if (!buffer)
725+ return ERR_PTR(-ENOMEM);
726+
727+ ts = iio_priv(indio_dev);
728+ inv_icm42600_timestamp_init(ts, inv_icm42600_odr_to_period(st->conf.accel.odr));
729+
730+ iio_device_set_drvdata(indio_dev, st);
731+ indio_dev->name = name;
732+ indio_dev->info = &inv_icm42600_accel_info;
733+ indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
734+ indio_dev->channels = inv_icm42600_accel_channels;
735+ indio_dev->num_channels = ARRAY_SIZE(inv_icm42600_accel_channels);
736+ indio_dev->available_scan_masks = inv_icm42600_accel_scan_masks;
737+ indio_dev->setup_ops = &inv_icm42600_buffer_ops;
738+
739+ iio_device_attach_buffer(indio_dev, buffer);
740+
741+ ret = devm_iio_device_register(dev, indio_dev);
742+ if (ret)
743+ return ERR_PTR(ret);
744+
745+ return indio_dev;
746+}
747+
748+int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev)
749+{
750+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
751+ struct inv_icm42600_timestamp *ts = iio_priv(indio_dev);
752+ ssize_t i, size;
753+ unsigned int no;
754+ const void *accel, *gyro, *timestamp;
755+ const int8_t *temp;
756+ unsigned int odr;
757+ int64_t ts_val;
758+ struct inv_icm42600_accel_buffer buffer;
759+
760+ /* parse all fifo packets */
761+ for (i = 0, no = 0; i < st->fifo.count; i += size, ++no) {
762+ size = inv_icm42600_fifo_decode_packet(&st->fifo.data[i],
763+ &accel, &gyro, &temp, &timestamp, &odr);
764+ /* quit if error or FIFO is empty */
765+ if (size <= 0)
766+ return size;
767+
768+ /* skip packet if no accel data or data is invalid */
769+ if (accel == NULL || !inv_icm42600_fifo_is_data_valid(accel))
770+ continue;
771+
772+ /* update odr */
773+ if (odr & INV_ICM42600_SENSOR_ACCEL)
774+ inv_icm42600_timestamp_apply_odr(ts, st->fifo.period,
775+ st->fifo.nb.total, no);
776+
777+ /* buffer is copied to userspace, zeroing it to avoid any data leak */
778+ memset(&buffer, 0, sizeof(buffer));
779+ memcpy(&buffer.accel, accel, sizeof(buffer.accel));
780+ /* convert 8 bits FIFO temperature in high resolution format */
781+ buffer.temp = temp ? (*temp * 64) : 0;
782+ ts_val = inv_icm42600_timestamp_pop(ts);
783+ iio_push_to_buffers_with_timestamp(indio_dev, &buffer, ts_val);
784+ }
785+
786+ return 0;
787+}
drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c+601−0
@@ -0,0 +1,601 @@
1+// SPDX-License-Identifier: GPL-2.0-or-later
2+/*
3+ * Copyright (C) 2020 Invensense, Inc.
4+ */
5+
6+#include <linux/kernel.h>
7+#include <linux/device.h>
8+#include <linux/mutex.h>
9+#include <linux/pm_runtime.h>
10+#include <linux/regmap.h>
11+#include <linux/delay.h>
12+#include <linux/iio/iio.h>
13+#include <linux/iio/buffer.h>
14+
15+#include "inv_icm42600.h"
16+#include "inv_icm42600_timestamp.h"
17+#include "inv_icm42600_buffer.h"
18+
19+/* FIFO header: 1 byte */
20+#define INV_ICM42600_FIFO_HEADER_MSG BIT(7)
21+#define INV_ICM42600_FIFO_HEADER_ACCEL BIT(6)
22+#define INV_ICM42600_FIFO_HEADER_GYRO BIT(5)
23+#define INV_ICM42600_FIFO_HEADER_TMST_FSYNC GENMASK(3, 2)
24+#define INV_ICM42600_FIFO_HEADER_ODR_ACCEL BIT(1)
25+#define INV_ICM42600_FIFO_HEADER_ODR_GYRO BIT(0)
26+
27+struct inv_icm42600_fifo_1sensor_packet {
28+ uint8_t header;
29+ struct inv_icm42600_fifo_sensor_data data;
30+ int8_t temp;
31+} __packed;
32+#define INV_ICM42600_FIFO_1SENSOR_PACKET_SIZE 8
33+
34+struct inv_icm42600_fifo_2sensors_packet {
35+ uint8_t header;
36+ struct inv_icm42600_fifo_sensor_data accel;
37+ struct inv_icm42600_fifo_sensor_data gyro;
38+ int8_t temp;
39+ __be16 timestamp;
40+} __packed;
41+#define INV_ICM42600_FIFO_2SENSORS_PACKET_SIZE 16
42+
43+ssize_t inv_icm42600_fifo_decode_packet(const void *packet, const void **accel,
44+ const void **gyro, const int8_t **temp,
45+ const void **timestamp, unsigned int *odr)
46+{
47+ const struct inv_icm42600_fifo_1sensor_packet *pack1 = packet;
48+ const struct inv_icm42600_fifo_2sensors_packet *pack2 = packet;
49+ uint8_t header = *((const uint8_t *)packet);
50+
51+ /* FIFO empty */
52+ if (header & INV_ICM42600_FIFO_HEADER_MSG) {
53+ *accel = NULL;
54+ *gyro = NULL;
55+ *temp = NULL;
56+ *timestamp = NULL;
57+ *odr = 0;
58+ return 0;
59+ }
60+
61+ /* handle odr flags */
62+ *odr = 0;
63+ if (header & INV_ICM42600_FIFO_HEADER_ODR_GYRO)
64+ *odr |= INV_ICM42600_SENSOR_GYRO;
65+ if (header & INV_ICM42600_FIFO_HEADER_ODR_ACCEL)
66+ *odr |= INV_ICM42600_SENSOR_ACCEL;
67+
68+ /* accel + gyro */
69+ if ((header & INV_ICM42600_FIFO_HEADER_ACCEL) &&
70+ (header & INV_ICM42600_FIFO_HEADER_GYRO)) {
71+ *accel = &pack2->accel;
72+ *gyro = &pack2->gyro;
73+ *temp = &pack2->temp;
74+ *timestamp = &pack2->timestamp;
75+ return INV_ICM42600_FIFO_2SENSORS_PACKET_SIZE;
76+ }
77+
78+ /* accel only */
79+ if (header & INV_ICM42600_FIFO_HEADER_ACCEL) {
80+ *accel = &pack1->data;
81+ *gyro = NULL;
82+ *temp = &pack1->temp;
83+ *timestamp = NULL;
84+ return INV_ICM42600_FIFO_1SENSOR_PACKET_SIZE;
85+ }
86+
87+ /* gyro only */
88+ if (header & INV_ICM42600_FIFO_HEADER_GYRO) {
89+ *accel = NULL;
90+ *gyro = &pack1->data;
91+ *temp = &pack1->temp;
92+ *timestamp = NULL;
93+ return INV_ICM42600_FIFO_1SENSOR_PACKET_SIZE;
94+ }
95+
96+ /* invalid packet if here */
97+ return -EINVAL;
98+}
99+
100+void inv_icm42600_buffer_update_fifo_period(struct inv_icm42600_state *st)
101+{
102+ uint32_t period_gyro, period_accel, period;
103+
104+ if (st->fifo.en & INV_ICM42600_SENSOR_GYRO)
105+ period_gyro = inv_icm42600_odr_to_period(st->conf.gyro.odr);
106+ else
107+ period_gyro = U32_MAX;
108+
109+ if (st->fifo.en & INV_ICM42600_SENSOR_ACCEL)
110+ period_accel = inv_icm42600_odr_to_period(st->conf.accel.odr);
111+ else
112+ period_accel = U32_MAX;
113+
114+ if (period_gyro <= period_accel)
115+ period = period_gyro;
116+ else
117+ period = period_accel;
118+
119+ st->fifo.period = period;
120+}
121+
122+int inv_icm42600_buffer_set_fifo_en(struct inv_icm42600_state *st,
123+ unsigned int fifo_en)
124+{
125+ unsigned int mask, val;
126+ int ret;
127+
128+ /* update only FIFO EN bits */
129+ mask = INV_ICM42600_FIFO_CONFIG1_TMST_FSYNC_EN |
130+ INV_ICM42600_FIFO_CONFIG1_TEMP_EN |
131+ INV_ICM42600_FIFO_CONFIG1_GYRO_EN |
132+ INV_ICM42600_FIFO_CONFIG1_ACCEL_EN;
133+
134+ val = 0;
135+ if (fifo_en & INV_ICM42600_SENSOR_GYRO)
136+ val |= INV_ICM42600_FIFO_CONFIG1_GYRO_EN;
137+ if (fifo_en & INV_ICM42600_SENSOR_ACCEL)
138+ val |= INV_ICM42600_FIFO_CONFIG1_ACCEL_EN;
139+ if (fifo_en & INV_ICM42600_SENSOR_TEMP)
140+ val |= INV_ICM42600_FIFO_CONFIG1_TEMP_EN;
141+
142+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_FIFO_CONFIG1, mask, val);
143+ if (ret)
144+ return ret;
145+
146+ st->fifo.en = fifo_en;
147+ inv_icm42600_buffer_update_fifo_period(st);
148+
149+ return 0;
150+}
151+
152+static size_t inv_icm42600_get_packet_size(unsigned int fifo_en)
153+{
154+ size_t packet_size;
155+
156+ if ((fifo_en & INV_ICM42600_SENSOR_GYRO) &&
157+ (fifo_en & INV_ICM42600_SENSOR_ACCEL))
158+ packet_size = INV_ICM42600_FIFO_2SENSORS_PACKET_SIZE;
159+ else
160+ packet_size = INV_ICM42600_FIFO_1SENSOR_PACKET_SIZE;
161+
162+ return packet_size;
163+}
164+
165+static unsigned int inv_icm42600_wm_truncate(unsigned int watermark,
166+ size_t packet_size)
167+{
168+ size_t wm_size;
169+ unsigned int wm;
170+
171+ wm_size = watermark * packet_size;
172+ if (wm_size > INV_ICM42600_FIFO_WATERMARK_MAX)
173+ wm_size = INV_ICM42600_FIFO_WATERMARK_MAX;
174+
175+ wm = wm_size / packet_size;
176+
177+ return wm;
178+}
179+
180+/**
181+ * inv_icm42600_buffer_update_watermark - update watermark FIFO threshold
182+ * @st: driver internal state
183+ *
184+ * Returns 0 on success, a negative error code otherwise.
185+ *
186+ * FIFO watermark threshold is computed based on the required watermark values
187+ * set for gyro and accel sensors. Since watermark is all about acceptable data
188+ * latency, use the smallest setting between the 2. It means choosing the
189+ * smallest latency but this is not as simple as choosing the smallest watermark
190+ * value. Latency depends on watermark and ODR. It requires several steps:
191+ * 1) compute gyro and accel latencies and choose the smallest value.
192+ * 2) adapt the choosen latency so that it is a multiple of both gyro and accel
193+ * ones. Otherwise it is possible that you don't meet a requirement. (for
194+ * example with gyro @100Hz wm 4 and accel @100Hz with wm 6, choosing the
195+ * value of 4 will not meet accel latency requirement because 6 is not a
196+ * multiple of 4. You need to use the value 2.)
197+ * 3) Since all periods are multiple of each others, watermark is computed by
198+ * dividing this computed latency by the smallest period, which corresponds
199+ * to the FIFO frequency. Beware that this is only true because we are not
200+ * using 500Hz frequency which is not a multiple of the others.
201+ */
202+int inv_icm42600_buffer_update_watermark(struct inv_icm42600_state *st)
203+{
204+ size_t packet_size, wm_size;
205+ unsigned int wm_gyro, wm_accel, watermark;
206+ uint32_t period_gyro, period_accel, period;
207+ uint32_t latency_gyro, latency_accel, latency;
208+ bool restore;
209+ __le16 raw_wm;
210+ int ret;
211+
212+ packet_size = inv_icm42600_get_packet_size(st->fifo.en);
213+
214+ /* compute sensors latency, depending on sensor watermark and odr */
215+ wm_gyro = inv_icm42600_wm_truncate(st->fifo.watermark.gyro, packet_size);
216+ wm_accel = inv_icm42600_wm_truncate(st->fifo.watermark.accel, packet_size);
217+ /* use us for odr to avoid overflow using 32 bits values */
218+ period_gyro = inv_icm42600_odr_to_period(st->conf.gyro.odr) / 1000UL;
219+ period_accel = inv_icm42600_odr_to_period(st->conf.accel.odr) / 1000UL;
220+ latency_gyro = period_gyro * wm_gyro;
221+ latency_accel = period_accel * wm_accel;
222+
223+ /* 0 value for watermark means that the sensor is turned off */
224+ if (latency_gyro == 0) {
225+ watermark = wm_accel;
226+ } else if (latency_accel == 0) {
227+ watermark = wm_gyro;
228+ } else {
229+ /* compute the smallest latency that is a multiple of both */
230+ if (latency_gyro <= latency_accel)
231+ latency = latency_gyro - (latency_accel % latency_gyro);
232+ else
233+ latency = latency_accel - (latency_gyro % latency_accel);
234+ /* use the shortest period */
235+ if (period_gyro <= period_accel)
236+ period = period_gyro;
237+ else
238+ period = period_accel;
239+ /* all this works because periods are multiple of each others */
240+ watermark = latency / period;
241+ if (watermark < 1)
242+ watermark = 1;
243+ }
244+
245+ /* compute watermark value in bytes */
246+ wm_size = watermark * packet_size;
247+
248+ /* changing FIFO watermark requires to turn off watermark interrupt */
249+ ret = regmap_update_bits_check(st->map, INV_ICM42600_REG_INT_SOURCE0,
250+ INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN,
251+ 0, &restore);
252+ if (ret)
253+ return ret;
254+
255+ raw_wm = INV_ICM42600_FIFO_WATERMARK_VAL(wm_size);
256+ memcpy(st->buffer, &raw_wm, sizeof(raw_wm));
257+ ret = regmap_bulk_write(st->map, INV_ICM42600_REG_FIFO_WATERMARK,
258+ st->buffer, sizeof(raw_wm));
259+ if (ret)
260+ return ret;
261+
262+ /* restore watermark interrupt */
263+ if (restore) {
264+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_INT_SOURCE0,
265+ INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN,
266+ INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN);
267+ if (ret)
268+ return ret;
269+ }
270+
271+ return 0;
272+}
273+
274+static int inv_icm42600_buffer_preenable(struct iio_dev *indio_dev)
275+{
276+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
277+ struct device *dev = regmap_get_device(st->map);
278+
279+ pm_runtime_get_sync(dev);
280+
281+ return 0;
282+}
283+
284+/*
285+ * update_scan_mode callback is turning sensors on and setting data FIFO enable
286+ * bits.
287+ */
288+static int inv_icm42600_buffer_postenable(struct iio_dev *indio_dev)
289+{
290+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
291+ int ret;
292+
293+ mutex_lock(&st->lock);
294+
295+ /* exit if FIFO is already on */
296+ if (st->fifo.on) {
297+ ret = 0;
298+ goto out_on;
299+ }
300+
301+ /* set FIFO threshold interrupt */
302+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_INT_SOURCE0,
303+ INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN,
304+ INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN);
305+ if (ret)
306+ goto out_unlock;
307+
308+ /* flush FIFO data */
309+ ret = regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET,
310+ INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH);
311+ if (ret)
312+ goto out_unlock;
313+
314+ /* set FIFO in streaming mode */
315+ ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG,
316+ INV_ICM42600_FIFO_CONFIG_STREAM);
317+ if (ret)
318+ goto out_unlock;
319+
320+ /* workaround: first read of FIFO count after reset is always 0 */
321+ ret = regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT, st->buffer, 2);
322+ if (ret)
323+ goto out_unlock;
324+
325+out_on:
326+ /* increase FIFO on counter */
327+ st->fifo.on++;
328+out_unlock:
329+ mutex_unlock(&st->lock);
330+ return ret;
331+}
332+
333+static int inv_icm42600_buffer_predisable(struct iio_dev *indio_dev)
334+{
335+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
336+ int ret;
337+
338+ mutex_lock(&st->lock);
339+
340+ /* exit if there are several sensors using the FIFO */
341+ if (st->fifo.on > 1) {
342+ ret = 0;
343+ goto out_off;
344+ }
345+
346+ /* set FIFO in bypass mode */
347+ ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG,
348+ INV_ICM42600_FIFO_CONFIG_BYPASS);
349+ if (ret)
350+ goto out_unlock;
351+
352+ /* flush FIFO data */
353+ ret = regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET,
354+ INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH);
355+ if (ret)
356+ goto out_unlock;
357+
358+ /* disable FIFO threshold interrupt */
359+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_INT_SOURCE0,
360+ INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN, 0);
361+ if (ret)
362+ goto out_unlock;
363+
364+out_off:
365+ /* decrease FIFO on counter */
366+ st->fifo.on--;
367+out_unlock:
368+ mutex_unlock(&st->lock);
369+ return ret;
370+}
371+
372+static int inv_icm42600_buffer_postdisable(struct iio_dev *indio_dev)
373+{
374+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
375+ struct device *dev = regmap_get_device(st->map);
376+ unsigned int sensor;
377+ unsigned int *watermark;
378+ struct inv_icm42600_timestamp *ts;
379+ struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
380+ unsigned int sleep_temp = 0;
381+ unsigned int sleep_sensor = 0;
382+ unsigned int sleep;
383+ int ret;
384+
385+ if (indio_dev == st->indio_gyro) {
386+ sensor = INV_ICM42600_SENSOR_GYRO;
387+ watermark = &st->fifo.watermark.gyro;
388+ ts = iio_priv(st->indio_gyro);
389+ } else if (indio_dev == st->indio_accel) {
390+ sensor = INV_ICM42600_SENSOR_ACCEL;
391+ watermark = &st->fifo.watermark.accel;
392+ ts = iio_priv(st->indio_accel);
393+ } else {
394+ return -EINVAL;
395+ }
396+
397+ mutex_lock(&st->lock);
398+
399+ ret = inv_icm42600_buffer_set_fifo_en(st, st->fifo.en & ~sensor);
400+ if (ret)
401+ goto out_unlock;
402+
403+ *watermark = 0;
404+ ret = inv_icm42600_buffer_update_watermark(st);
405+ if (ret)
406+ goto out_unlock;
407+
408+ conf.mode = INV_ICM42600_SENSOR_MODE_OFF;
409+ if (sensor == INV_ICM42600_SENSOR_GYRO)
410+ ret = inv_icm42600_set_gyro_conf(st, &conf, &sleep_sensor);
411+ else
412+ ret = inv_icm42600_set_accel_conf(st, &conf, &sleep_sensor);
413+ if (ret)
414+ goto out_unlock;
415+
416+ /* if FIFO is off, turn temperature off */
417+ if (!st->fifo.on)
418+ ret = inv_icm42600_set_temp_conf(st, false, &sleep_temp);
419+
420+ inv_icm42600_timestamp_reset(ts);
421+
422+out_unlock:
423+ mutex_unlock(&st->lock);
424+
425+ /* sleep maximum required time */
426+ if (sleep_sensor > sleep_temp)
427+ sleep = sleep_sensor;
428+ else
429+ sleep = sleep_temp;
430+ if (sleep)
431+ msleep(sleep);
432+
433+ pm_runtime_mark_last_busy(dev);
434+ pm_runtime_put_autosuspend(dev);
435+
436+ return ret;
437+}
438+
439+const struct iio_buffer_setup_ops inv_icm42600_buffer_ops = {
440+ .preenable = inv_icm42600_buffer_preenable,
441+ .postenable = inv_icm42600_buffer_postenable,
442+ .predisable = inv_icm42600_buffer_predisable,
443+ .postdisable = inv_icm42600_buffer_postdisable,
444+};
445+
446+int inv_icm42600_buffer_fifo_read(struct inv_icm42600_state *st,
447+ unsigned int max)
448+{
449+ size_t max_count;
450+ __be16 *raw_fifo_count;
451+ ssize_t i, size;
452+ const void *accel, *gyro, *timestamp;
453+ const int8_t *temp;
454+ unsigned int odr;
455+ int ret;
456+
457+ /* reset all samples counters */
458+ st->fifo.count = 0;
459+ st->fifo.nb.gyro = 0;
460+ st->fifo.nb.accel = 0;
461+ st->fifo.nb.total = 0;
462+
463+ /* compute maximum FIFO read size */
464+ if (max == 0)
465+ max_count = sizeof(st->fifo.data);
466+ else
467+ max_count = max * inv_icm42600_get_packet_size(st->fifo.en);
468+
469+ /* read FIFO count value */
470+ raw_fifo_count = (__be16 *)st->buffer;
471+ ret = regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT,
472+ raw_fifo_count, sizeof(*raw_fifo_count));
473+ if (ret)
474+ return ret;
475+ st->fifo.count = be16_to_cpup(raw_fifo_count);
476+
477+ /* check and clamp FIFO count value */
478+ if (st->fifo.count == 0)
479+ return 0;
480+ if (st->fifo.count > max_count)
481+ st->fifo.count = max_count;
482+
483+ /* read all FIFO data in internal buffer */
484+ ret = regmap_noinc_read(st->map, INV_ICM42600_REG_FIFO_DATA,
485+ st->fifo.data, st->fifo.count);
486+ if (ret)
487+ return ret;
488+
489+ /* compute number of samples for each sensor */
490+ for (i = 0; i < st->fifo.count; i += size) {
491+ size = inv_icm42600_fifo_decode_packet(&st->fifo.data[i],
492+ &accel, &gyro, &temp, &timestamp, &odr);
493+ if (size <= 0)
494+ break;
495+ if (gyro != NULL && inv_icm42600_fifo_is_data_valid(gyro))
496+ st->fifo.nb.gyro++;
497+ if (accel != NULL && inv_icm42600_fifo_is_data_valid(accel))
498+ st->fifo.nb.accel++;
499+ st->fifo.nb.total++;
500+ }
501+
502+ return 0;
503+}
504+
505+int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st)
506+{
507+ struct inv_icm42600_timestamp *ts;
508+ int ret;
509+
510+ if (st->fifo.nb.total == 0)
511+ return 0;
512+
513+ /* handle gyroscope timestamp and FIFO data parsing */
514+ ts = iio_priv(st->indio_gyro);
515+ inv_icm42600_timestamp_interrupt(ts, st->fifo.period, st->fifo.nb.total,
516+ st->fifo.nb.gyro, st->timestamp.gyro);
517+ if (st->fifo.nb.gyro > 0) {
518+ ret = inv_icm42600_gyro_parse_fifo(st->indio_gyro);
519+ if (ret)
520+ return ret;
521+ }
522+
523+ /* handle accelerometer timestamp and FIFO data parsing */
524+ ts = iio_priv(st->indio_accel);
525+ inv_icm42600_timestamp_interrupt(ts, st->fifo.period, st->fifo.nb.total,
526+ st->fifo.nb.accel, st->timestamp.accel);
527+ if (st->fifo.nb.accel > 0) {
528+ ret = inv_icm42600_accel_parse_fifo(st->indio_accel);
529+ if (ret)
530+ return ret;
531+ }
532+
533+ return 0;
534+}
535+
536+int inv_icm42600_buffer_hwfifo_flush(struct inv_icm42600_state *st,
537+ unsigned int count)
538+{
539+ struct inv_icm42600_timestamp *ts;
540+ int64_t gyro_ts, accel_ts;
541+ int ret;
542+
543+ gyro_ts = iio_get_time_ns(st->indio_gyro);
544+ accel_ts = iio_get_time_ns(st->indio_accel);
545+
546+ ret = inv_icm42600_buffer_fifo_read(st, count);
547+ if (ret)
548+ return ret;
549+
550+ if (st->fifo.nb.total == 0)
551+ return 0;
552+
553+ if (st->fifo.nb.gyro > 0) {
554+ ts = iio_priv(st->indio_gyro);
555+ inv_icm42600_timestamp_interrupt(ts, st->fifo.period,
556+ st->fifo.nb.total, st->fifo.nb.gyro,
557+ gyro_ts);
558+ ret = inv_icm42600_gyro_parse_fifo(st->indio_gyro);
559+ if (ret)
560+ return ret;
561+ }
562+
563+ if (st->fifo.nb.accel > 0) {
564+ ts = iio_priv(st->indio_accel);
565+ inv_icm42600_timestamp_interrupt(ts, st->fifo.period,
566+ st->fifo.nb.total, st->fifo.nb.accel,
567+ accel_ts);
568+ ret = inv_icm42600_accel_parse_fifo(st->indio_accel);
569+ if (ret)
570+ return ret;
571+ }
572+
573+ return 0;
574+}
575+
576+int inv_icm42600_buffer_init(struct inv_icm42600_state *st)
577+{
578+ unsigned int val;
579+ int ret;
580+
581+ /*
582+ * Default FIFO configuration (bits 7 to 5)
583+ * - use invalid value
584+ * - FIFO count in bytes
585+ * - FIFO count in big endian
586+ */
587+ val = INV_ICM42600_INTF_CONFIG0_FIFO_COUNT_ENDIAN;
588+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG0,
589+ GENMASK(7, 5), val);
590+ if (ret)
591+ return ret;
592+
593+ /*
594+ * Enable FIFO partial read and continuous watermark interrupt.
595+ * Disable all FIFO EN bits.
596+ */
597+ val = INV_ICM42600_FIFO_CONFIG1_RESUME_PARTIAL_RD |
598+ INV_ICM42600_FIFO_CONFIG1_WM_GT_TH;
599+ return regmap_update_bits(st->map, INV_ICM42600_REG_FIFO_CONFIG1,
600+ GENMASK(6, 5) | GENMASK(3, 0), val);
601+}
drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.h+98−0
@@ -0,0 +1,98 @@
1+/* SPDX-License-Identifier: GPL-2.0-or-later */
2+/*
3+ * Copyright (C) 2020 Invensense, Inc.
4+ */
5+
6+#ifndef INV_ICM42600_BUFFER_H_
7+#define INV_ICM42600_BUFFER_H_
8+
9+#include <linux/kernel.h>
10+#include <linux/bits.h>
11+
12+struct inv_icm42600_state;
13+
14+#define INV_ICM42600_SENSOR_GYRO BIT(0)
15+#define INV_ICM42600_SENSOR_ACCEL BIT(1)
16+#define INV_ICM42600_SENSOR_TEMP BIT(2)
17+
18+/**
19+ * struct inv_icm42600_fifo - FIFO state variables
20+ * @on: reference counter for FIFO on.
21+ * @en: bits field of INV_ICM42600_SENSOR_* for FIFO EN bits.
22+ * @period: FIFO internal period.
23+ * @watermark: watermark configuration values for accel and gyro.
24+ * @count: number of bytes in the FIFO data buffer.
25+ * @nb: gyro, accel and total samples in the FIFO data buffer.
26+ * @data: FIFO data buffer aligned for DMA (2kB + 32 bytes of read cache).
27+ */
28+struct inv_icm42600_fifo {
29+ unsigned int on;
30+ unsigned int en;
31+ uint32_t period;
32+ struct {
33+ unsigned int gyro;
34+ unsigned int accel;
35+ } watermark;
36+ size_t count;
37+ struct {
38+ size_t gyro;
39+ size_t accel;
40+ size_t total;
41+ } nb;
42+ uint8_t data[2080] ____cacheline_aligned;
43+};
44+
45+/* FIFO data packet */
46+struct inv_icm42600_fifo_sensor_data {
47+ __be16 x;
48+ __be16 y;
49+ __be16 z;
50+} __packed;
51+#define INV_ICM42600_FIFO_DATA_INVALID -32768
52+
53+static inline int16_t inv_icm42600_fifo_get_sensor_data(__be16 d)
54+{
55+ return be16_to_cpu(d);
56+}
57+
58+static inline bool
59+inv_icm42600_fifo_is_data_valid(const struct inv_icm42600_fifo_sensor_data *s)
60+{
61+ int16_t x, y, z;
62+
63+ x = inv_icm42600_fifo_get_sensor_data(s->x);
64+ y = inv_icm42600_fifo_get_sensor_data(s->y);
65+ z = inv_icm42600_fifo_get_sensor_data(s->z);
66+
67+ if (x == INV_ICM42600_FIFO_DATA_INVALID &&
68+ y == INV_ICM42600_FIFO_DATA_INVALID &&
69+ z == INV_ICM42600_FIFO_DATA_INVALID)
70+ return false;
71+
72+ return true;
73+}
74+
75+ssize_t inv_icm42600_fifo_decode_packet(const void *packet, const void **accel,
76+ const void **gyro, const int8_t **temp,
77+ const void **timestamp, unsigned int *odr);
78+
79+extern const struct iio_buffer_setup_ops inv_icm42600_buffer_ops;
80+
81+int inv_icm42600_buffer_init(struct inv_icm42600_state *st);
82+
83+void inv_icm42600_buffer_update_fifo_period(struct inv_icm42600_state *st);
84+
85+int inv_icm42600_buffer_set_fifo_en(struct inv_icm42600_state *st,
86+ unsigned int fifo_en);
87+
88+int inv_icm42600_buffer_update_watermark(struct inv_icm42600_state *st);
89+
90+int inv_icm42600_buffer_fifo_read(struct inv_icm42600_state *st,
91+ unsigned int max);
92+
93+int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st);
94+
95+int inv_icm42600_buffer_hwfifo_flush(struct inv_icm42600_state *st,
96+ unsigned int count);
97+
98+#endif
drivers/iio/imu/inv_icm42600/inv_icm42600_core.c+786−0
@@ -0,0 +1,786 @@
1+// SPDX-License-Identifier: GPL-2.0-or-later
2+/*
3+ * Copyright (C) 2020 Invensense, Inc.
4+ */
5+
6+#include <linux/kernel.h>
7+#include <linux/device.h>
8+#include <linux/module.h>
9+#include <linux/slab.h>
10+#include <linux/delay.h>
11+#include <linux/mutex.h>
12+#include <linux/interrupt.h>
13+#include <linux/irq.h>
14+#include <linux/regulator/consumer.h>
15+#include <linux/pm_runtime.h>
16+#include <linux/property.h>
17+#include <linux/regmap.h>
18+#include <linux/iio/iio.h>
19+
20+#include "inv_icm42600.h"
21+#include "inv_icm42600_buffer.h"
22+#include "inv_icm42600_timestamp.h"
23+
24+static const struct regmap_range_cfg inv_icm42600_regmap_ranges[] = {
25+ {
26+ .name = "user banks",
27+ .range_min = 0x0000,
28+ .range_max = 0x4FFF,
29+ .selector_reg = INV_ICM42600_REG_BANK_SEL,
30+ .selector_mask = INV_ICM42600_BANK_SEL_MASK,
31+ .selector_shift = 0,
32+ .window_start = 0,
33+ .window_len = 0x1000,
34+ },
35+};
36+
37+const struct regmap_config inv_icm42600_regmap_config = {
38+ .reg_bits = 8,
39+ .val_bits = 8,
40+ .max_register = 0x4FFF,
41+ .ranges = inv_icm42600_regmap_ranges,
42+ .num_ranges = ARRAY_SIZE(inv_icm42600_regmap_ranges),
43+};
44+EXPORT_SYMBOL_GPL(inv_icm42600_regmap_config);
45+
46+struct inv_icm42600_hw {
47+ uint8_t whoami;
48+ const char *name;
49+ const struct inv_icm42600_conf *conf;
50+};
51+
52+/* chip initial default configuration */
53+static const struct inv_icm42600_conf inv_icm42600_default_conf = {
54+ .gyro = {
55+ .mode = INV_ICM42600_SENSOR_MODE_OFF,
56+ .fs = INV_ICM42600_GYRO_FS_2000DPS,
57+ .odr = INV_ICM42600_ODR_50HZ,
58+ .filter = INV_ICM42600_FILTER_BW_ODR_DIV_2,
59+ },
60+ .accel = {
61+ .mode = INV_ICM42600_SENSOR_MODE_OFF,
62+ .fs = INV_ICM42600_ACCEL_FS_16G,
63+ .odr = INV_ICM42600_ODR_50HZ,
64+ .filter = INV_ICM42600_FILTER_BW_ODR_DIV_2,
65+ },
66+ .temp_en = false,
67+};
68+
69+static const struct inv_icm42600_hw inv_icm42600_hw[INV_CHIP_NB] = {
70+ [INV_CHIP_ICM42600] = {
71+ .whoami = INV_ICM42600_WHOAMI_ICM42600,
72+ .name = "icm42600",
73+ .conf = &inv_icm42600_default_conf,
74+ },
75+ [INV_CHIP_ICM42602] = {
76+ .whoami = INV_ICM42600_WHOAMI_ICM42602,
77+ .name = "icm42602",
78+ .conf = &inv_icm42600_default_conf,
79+ },
80+ [INV_CHIP_ICM42605] = {
81+ .whoami = INV_ICM42600_WHOAMI_ICM42605,
82+ .name = "icm42605",
83+ .conf = &inv_icm42600_default_conf,
84+ },
85+ [INV_CHIP_ICM42622] = {
86+ .whoami = INV_ICM42600_WHOAMI_ICM42622,
87+ .name = "icm42622",
88+ .conf = &inv_icm42600_default_conf,
89+ },
90+};
91+
92+const struct iio_mount_matrix *
93+inv_icm42600_get_mount_matrix(const struct iio_dev *indio_dev,
94+ const struct iio_chan_spec *chan)
95+{
96+ const struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
97+
98+ return &st->orientation;
99+}
100+
101+uint32_t inv_icm42600_odr_to_period(enum inv_icm42600_odr odr)
102+{
103+ static uint32_t odr_periods[INV_ICM42600_ODR_NB] = {
104+ /* reserved values */
105+ 0, 0, 0,
106+ /* 8kHz */
107+ 125000,
108+ /* 4kHz */
109+ 250000,
110+ /* 2kHz */
111+ 500000,
112+ /* 1kHz */
113+ 1000000,
114+ /* 200Hz */
115+ 5000000,
116+ /* 100Hz */
117+ 10000000,
118+ /* 50Hz */
119+ 20000000,
120+ /* 25Hz */
121+ 40000000,
122+ /* 12.5Hz */
123+ 80000000,
124+ /* 6.25Hz */
125+ 160000000,
126+ /* 3.125Hz */
127+ 320000000,
128+ /* 1.5625Hz */
129+ 640000000,
130+ /* 500Hz */
131+ 2000000,
132+ };
133+
134+ return odr_periods[odr];
135+}
136+
137+static int inv_icm42600_set_pwr_mgmt0(struct inv_icm42600_state *st,
138+ enum inv_icm42600_sensor_mode gyro,
139+ enum inv_icm42600_sensor_mode accel,
140+ bool temp, unsigned int *sleep_ms)
141+{
142+ enum inv_icm42600_sensor_mode oldgyro = st->conf.gyro.mode;
143+ enum inv_icm42600_sensor_mode oldaccel = st->conf.accel.mode;
144+ bool oldtemp = st->conf.temp_en;
145+ unsigned int sleepval;
146+ unsigned int val;
147+ int ret;
148+
149+ /* if nothing changed, exit */
150+ if (gyro == oldgyro && accel == oldaccel && temp == oldtemp)
151+ return 0;
152+
153+ val = INV_ICM42600_PWR_MGMT0_GYRO(gyro) |
154+ INV_ICM42600_PWR_MGMT0_ACCEL(accel);
155+ if (!temp)
156+ val |= INV_ICM42600_PWR_MGMT0_TEMP_DIS;
157+ ret = regmap_write(st->map, INV_ICM42600_REG_PWR_MGMT0, val);
158+ if (ret)
159+ return ret;
160+
161+ st->conf.gyro.mode = gyro;
162+ st->conf.accel.mode = accel;
163+ st->conf.temp_en = temp;
164+
165+ /* compute required wait time for sensors to stabilize */
166+ sleepval = 0;
167+ /* temperature stabilization time */
168+ if (temp && !oldtemp) {
169+ if (sleepval < INV_ICM42600_TEMP_STARTUP_TIME_MS)
170+ sleepval = INV_ICM42600_TEMP_STARTUP_TIME_MS;
171+ }
172+ /* accel startup time */
173+ if (accel != oldaccel && oldaccel == INV_ICM42600_SENSOR_MODE_OFF) {
174+ /* block any register write for at least 200 µs */
175+ usleep_range(200, 300);
176+ if (sleepval < INV_ICM42600_ACCEL_STARTUP_TIME_MS)
177+ sleepval = INV_ICM42600_ACCEL_STARTUP_TIME_MS;
178+ }
179+ if (gyro != oldgyro) {
180+ /* gyro startup time */
181+ if (oldgyro == INV_ICM42600_SENSOR_MODE_OFF) {
182+ /* block any register write for at least 200 µs */
183+ usleep_range(200, 300);
184+ if (sleepval < INV_ICM42600_GYRO_STARTUP_TIME_MS)
185+ sleepval = INV_ICM42600_GYRO_STARTUP_TIME_MS;
186+ /* gyro stop time */
187+ } else if (gyro == INV_ICM42600_SENSOR_MODE_OFF) {
188+ if (sleepval < INV_ICM42600_GYRO_STOP_TIME_MS)
189+ sleepval = INV_ICM42600_GYRO_STOP_TIME_MS;
190+ }
191+ }
192+
193+ /* deferred sleep value if sleep pointer is provided or direct sleep */
194+ if (sleep_ms)
195+ *sleep_ms = sleepval;
196+ else if (sleepval)
197+ msleep(sleepval);
198+
199+ return 0;
200+}
201+
202+int inv_icm42600_set_accel_conf(struct inv_icm42600_state *st,
203+ struct inv_icm42600_sensor_conf *conf,
204+ unsigned int *sleep_ms)
205+{
206+ struct inv_icm42600_sensor_conf *oldconf = &st->conf.accel;
207+ unsigned int val;
208+ int ret;
209+
210+ /* Sanitize missing values with current values */
211+ if (conf->mode < 0)
212+ conf->mode = oldconf->mode;
213+ if (conf->fs < 0)
214+ conf->fs = oldconf->fs;
215+ if (conf->odr < 0)
216+ conf->odr = oldconf->odr;
217+ if (conf->filter < 0)
218+ conf->filter = oldconf->filter;
219+
220+ /* set ACCEL_CONFIG0 register (accel fullscale & odr) */
221+ if (conf->fs != oldconf->fs || conf->odr != oldconf->odr) {
222+ val = INV_ICM42600_ACCEL_CONFIG0_FS(conf->fs) |
223+ INV_ICM42600_ACCEL_CONFIG0_ODR(conf->odr);
224+ ret = regmap_write(st->map, INV_ICM42600_REG_ACCEL_CONFIG0, val);
225+ if (ret)
226+ return ret;
227+ oldconf->fs = conf->fs;
228+ oldconf->odr = conf->odr;
229+ }
230+
231+ /* set GYRO_ACCEL_CONFIG0 register (accel filter) */
232+ if (conf->filter != oldconf->filter) {
233+ val = INV_ICM42600_GYRO_ACCEL_CONFIG0_ACCEL_FILT(conf->filter) |
234+ INV_ICM42600_GYRO_ACCEL_CONFIG0_GYRO_FILT(st->conf.gyro.filter);
235+ ret = regmap_write(st->map, INV_ICM42600_REG_GYRO_ACCEL_CONFIG0, val);
236+ if (ret)
237+ return ret;
238+ oldconf->filter = conf->filter;
239+ }
240+
241+ /* set PWR_MGMT0 register (accel sensor mode) */
242+ return inv_icm42600_set_pwr_mgmt0(st, st->conf.gyro.mode, conf->mode,
243+ st->conf.temp_en, sleep_ms);
244+}
245+
246+int inv_icm42600_set_gyro_conf(struct inv_icm42600_state *st,
247+ struct inv_icm42600_sensor_conf *conf,
248+ unsigned int *sleep_ms)
249+{
250+ struct inv_icm42600_sensor_conf *oldconf = &st->conf.gyro;
251+ unsigned int val;
252+ int ret;
253+
254+ /* sanitize missing values with current values */
255+ if (conf->mode < 0)
256+ conf->mode = oldconf->mode;
257+ if (conf->fs < 0)
258+ conf->fs = oldconf->fs;
259+ if (conf->odr < 0)
260+ conf->odr = oldconf->odr;
261+ if (conf->filter < 0)
262+ conf->filter = oldconf->filter;
263+
264+ /* set GYRO_CONFIG0 register (gyro fullscale & odr) */
265+ if (conf->fs != oldconf->fs || conf->odr != oldconf->odr) {
266+ val = INV_ICM42600_GYRO_CONFIG0_FS(conf->fs) |
267+ INV_ICM42600_GYRO_CONFIG0_ODR(conf->odr);
268+ ret = regmap_write(st->map, INV_ICM42600_REG_GYRO_CONFIG0, val);
269+ if (ret)
270+ return ret;
271+ oldconf->fs = conf->fs;
272+ oldconf->odr = conf->odr;
273+ }
274+
275+ /* set GYRO_ACCEL_CONFIG0 register (gyro filter) */
276+ if (conf->filter != oldconf->filter) {
277+ val = INV_ICM42600_GYRO_ACCEL_CONFIG0_ACCEL_FILT(st->conf.accel.filter) |
278+ INV_ICM42600_GYRO_ACCEL_CONFIG0_GYRO_FILT(conf->filter);
279+ ret = regmap_write(st->map, INV_ICM42600_REG_GYRO_ACCEL_CONFIG0, val);
280+ if (ret)
281+ return ret;
282+ oldconf->filter = conf->filter;
283+ }
284+
285+ /* set PWR_MGMT0 register (gyro sensor mode) */
286+ return inv_icm42600_set_pwr_mgmt0(st, conf->mode, st->conf.accel.mode,
287+ st->conf.temp_en, sleep_ms);
288+
289+ return 0;
290+}
291+
292+int inv_icm42600_set_temp_conf(struct inv_icm42600_state *st, bool enable,
293+ unsigned int *sleep_ms)
294+{
295+ return inv_icm42600_set_pwr_mgmt0(st, st->conf.gyro.mode,
296+ st->conf.accel.mode, enable,
297+ sleep_ms);
298+}
299+
300+int inv_icm42600_debugfs_reg(struct iio_dev *indio_dev, unsigned int reg,
301+ unsigned int writeval, unsigned int *readval)
302+{
303+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
304+ int ret;
305+
306+ mutex_lock(&st->lock);
307+
308+ if (readval)
309+ ret = regmap_read(st->map, reg, readval);
310+ else
311+ ret = regmap_write(st->map, reg, writeval);
312+
313+ mutex_unlock(&st->lock);
314+
315+ return ret;
316+}
317+
318+static int inv_icm42600_set_conf(struct inv_icm42600_state *st,
319+ const struct inv_icm42600_conf *conf)
320+{
321+ unsigned int val;
322+ int ret;
323+
324+ /* set PWR_MGMT0 register (gyro & accel sensor mode, temp enabled) */
325+ val = INV_ICM42600_PWR_MGMT0_GYRO(conf->gyro.mode) |
326+ INV_ICM42600_PWR_MGMT0_ACCEL(conf->accel.mode);
327+ if (!conf->temp_en)
328+ val |= INV_ICM42600_PWR_MGMT0_TEMP_DIS;
329+ ret = regmap_write(st->map, INV_ICM42600_REG_PWR_MGMT0, val);
330+ if (ret)
331+ return ret;
332+
333+ /* set GYRO_CONFIG0 register (gyro fullscale & odr) */
334+ val = INV_ICM42600_GYRO_CONFIG0_FS(conf->gyro.fs) |
335+ INV_ICM42600_GYRO_CONFIG0_ODR(conf->gyro.odr);
336+ ret = regmap_write(st->map, INV_ICM42600_REG_GYRO_CONFIG0, val);
337+ if (ret)
338+ return ret;
339+
340+ /* set ACCEL_CONFIG0 register (accel fullscale & odr) */
341+ val = INV_ICM42600_ACCEL_CONFIG0_FS(conf->accel.fs) |
342+ INV_ICM42600_ACCEL_CONFIG0_ODR(conf->accel.odr);
343+ ret = regmap_write(st->map, INV_ICM42600_REG_ACCEL_CONFIG0, val);
344+ if (ret)
345+ return ret;
346+
347+ /* set GYRO_ACCEL_CONFIG0 register (gyro & accel filters) */
348+ val = INV_ICM42600_GYRO_ACCEL_CONFIG0_ACCEL_FILT(conf->accel.filter) |
349+ INV_ICM42600_GYRO_ACCEL_CONFIG0_GYRO_FILT(conf->gyro.filter);
350+ ret = regmap_write(st->map, INV_ICM42600_REG_GYRO_ACCEL_CONFIG0, val);
351+ if (ret)
352+ return ret;
353+
354+ /* update internal conf */
355+ st->conf = *conf;
356+
357+ return 0;
358+}
359+
360+/**
361+ * inv_icm42600_setup() - check and setup chip
362+ * @st: driver internal state
363+ * @bus_setup: callback for setting up bus specific registers
364+ *
365+ * Returns 0 on success, a negative error code otherwise.
366+ */
367+static int inv_icm42600_setup(struct inv_icm42600_state *st,
368+ inv_icm42600_bus_setup bus_setup)
369+{
370+ const struct inv_icm42600_hw *hw = &inv_icm42600_hw[st->chip];
371+ const struct device *dev = regmap_get_device(st->map);
372+ unsigned int val;
373+ int ret;
374+
375+ /* check chip self-identification value */
376+ ret = regmap_read(st->map, INV_ICM42600_REG_WHOAMI, &val);
377+ if (ret)
378+ return ret;
379+ if (val != hw->whoami) {
380+ dev_err(dev, "invalid whoami %#02x expected %#02x (%s)\n",
381+ val, hw->whoami, hw->name);
382+ return -ENODEV;
383+ }
384+ st->name = hw->name;
385+
386+ /* reset to make sure previous state are not there */
387+ ret = regmap_write(st->map, INV_ICM42600_REG_DEVICE_CONFIG,
388+ INV_ICM42600_DEVICE_CONFIG_SOFT_RESET);
389+ if (ret)
390+ return ret;
391+ msleep(INV_ICM42600_RESET_TIME_MS);
392+
393+ ret = regmap_read(st->map, INV_ICM42600_REG_INT_STATUS, &val);
394+ if (ret)
395+ return ret;
396+ if (!(val & INV_ICM42600_INT_STATUS_RESET_DONE)) {
397+ dev_err(dev, "reset error, reset done bit not set\n");
398+ return -ENODEV;
399+ }
400+
401+ /* set chip bus configuration */
402+ ret = bus_setup(st);
403+ if (ret)
404+ return ret;
405+
406+ /* sensor data in big-endian (default) */
407+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG0,
408+ INV_ICM42600_INTF_CONFIG0_SENSOR_DATA_ENDIAN,
409+ INV_ICM42600_INTF_CONFIG0_SENSOR_DATA_ENDIAN);
410+ if (ret)
411+ return ret;
412+
413+ return inv_icm42600_set_conf(st, hw->conf);
414+}
415+
416+static irqreturn_t inv_icm42600_irq_timestamp(int irq, void *_data)
417+{
418+ struct inv_icm42600_state *st = _data;
419+
420+ st->timestamp.gyro = iio_get_time_ns(st->indio_gyro);
421+ st->timestamp.accel = iio_get_time_ns(st->indio_accel);
422+
423+ return IRQ_WAKE_THREAD;
424+}
425+
426+static irqreturn_t inv_icm42600_irq_handler(int irq, void *_data)
427+{
428+ struct inv_icm42600_state *st = _data;
429+ struct device *dev = regmap_get_device(st->map);
430+ unsigned int status;
431+ int ret;
432+
433+ mutex_lock(&st->lock);
434+
435+ ret = regmap_read(st->map, INV_ICM42600_REG_INT_STATUS, &status);
436+ if (ret)
437+ goto out_unlock;
438+
439+ /* FIFO full */
440+ if (status & INV_ICM42600_INT_STATUS_FIFO_FULL)
441+ dev_warn(dev, "FIFO full data lost!\n");
442+
443+ /* FIFO threshold reached */
444+ if (status & INV_ICM42600_INT_STATUS_FIFO_THS) {
445+ ret = inv_icm42600_buffer_fifo_read(st, 0);
446+ if (ret) {
447+ dev_err(dev, "FIFO read error %d\n", ret);
448+ goto out_unlock;
449+ }
450+ ret = inv_icm42600_buffer_fifo_parse(st);
451+ if (ret)
452+ dev_err(dev, "FIFO parsing error %d\n", ret);
453+ }
454+
455+out_unlock:
456+ mutex_unlock(&st->lock);
457+ return IRQ_HANDLED;
458+}
459+
460+/**
461+ * inv_icm42600_irq_init() - initialize int pin and interrupt handler
462+ * @st: driver internal state
463+ * @irq: irq number
464+ * @irq_type: irq trigger type
465+ * @open_drain: true if irq is open drain, false for push-pull
466+ *
467+ * Returns 0 on success, a negative error code otherwise.
468+ */
469+static int inv_icm42600_irq_init(struct inv_icm42600_state *st, int irq,
470+ int irq_type, bool open_drain)
471+{
472+ struct device *dev = regmap_get_device(st->map);
473+ unsigned int val;
474+ int ret;
475+
476+ /* configure INT1 interrupt: default is active low on edge */
477+ switch (irq_type) {
478+ case IRQF_TRIGGER_RISING:
479+ case IRQF_TRIGGER_HIGH:
480+ val = INV_ICM42600_INT_CONFIG_INT1_ACTIVE_HIGH;
481+ break;
482+ default:
483+ val = INV_ICM42600_INT_CONFIG_INT1_ACTIVE_LOW;
484+ break;
485+ }
486+
487+ switch (irq_type) {
488+ case IRQF_TRIGGER_LOW:
489+ case IRQF_TRIGGER_HIGH:
490+ val |= INV_ICM42600_INT_CONFIG_INT1_LATCHED;
491+ break;
492+ default:
493+ break;
494+ }
495+
496+ if (!open_drain)
497+ val |= INV_ICM42600_INT_CONFIG_INT1_PUSH_PULL;
498+
499+ ret = regmap_write(st->map, INV_ICM42600_REG_INT_CONFIG, val);
500+ if (ret)
501+ return ret;
502+
503+ /* Deassert async reset for proper INT pin operation (cf datasheet) */
504+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_INT_CONFIG1,
505+ INV_ICM42600_INT_CONFIG1_ASYNC_RESET, 0);
506+ if (ret)
507+ return ret;
508+
509+ return devm_request_threaded_irq(dev, irq, inv_icm42600_irq_timestamp,
510+ inv_icm42600_irq_handler, irq_type,
511+ "inv_icm42600", st);
512+}
513+
514+static int inv_icm42600_enable_regulator_vddio(struct inv_icm42600_state *st)
515+{
516+ int ret;
517+
518+ ret = regulator_enable(st->vddio_supply);
519+ if (ret)
520+ return ret;
521+
522+ /* wait a little for supply ramp */
523+ usleep_range(3000, 4000);
524+
525+ return 0;
526+}
527+
528+static void inv_icm42600_disable_vdd_reg(void *_data)
529+{
530+ struct inv_icm42600_state *st = _data;
531+ const struct device *dev = regmap_get_device(st->map);
532+ int ret;
533+
534+ ret = regulator_disable(st->vdd_supply);
535+ if (ret)
536+ dev_err(dev, "failed to disable vdd error %d\n", ret);
537+}
538+
539+static void inv_icm42600_disable_vddio_reg(void *_data)
540+{
541+ struct inv_icm42600_state *st = _data;
542+ const struct device *dev = regmap_get_device(st->map);
543+ int ret;
544+
545+ ret = regulator_disable(st->vddio_supply);
546+ if (ret)
547+ dev_err(dev, "failed to disable vddio error %d\n", ret);
548+}
549+
550+static void inv_icm42600_disable_pm(void *_data)
551+{
552+ struct device *dev = _data;
553+
554+ pm_runtime_put_sync(dev);
555+ pm_runtime_disable(dev);
556+}
557+
558+int inv_icm42600_core_probe(struct regmap *regmap, int chip, int irq,
559+ inv_icm42600_bus_setup bus_setup)
560+{
561+ struct device *dev = regmap_get_device(regmap);
562+ struct inv_icm42600_state *st;
563+ struct irq_data *irq_desc;
564+ int irq_type;
565+ bool open_drain;
566+ int ret;
567+
568+ if (chip < 0 || chip >= INV_CHIP_NB) {
569+ dev_err(dev, "invalid chip = %d\n", chip);
570+ return -ENODEV;
571+ }
572+
573+ /* get irq properties, set trigger falling by default */
574+ irq_desc = irq_get_irq_data(irq);
575+ if (!irq_desc) {
576+ dev_err(dev, "could not find IRQ %d\n", irq);
577+ return -EINVAL;
578+ }
579+
580+ irq_type = irqd_get_trigger_type(irq_desc);
581+ if (!irq_type)
582+ irq_type = IRQF_TRIGGER_FALLING;
583+
584+ open_drain = device_property_read_bool(dev, "drive-open-drain");
585+
586+ st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL);
587+ if (!st)
588+ return -ENOMEM;
589+
590+ dev_set_drvdata(dev, st);
591+ mutex_init(&st->lock);
592+ st->chip = chip;
593+ st->map = regmap;
594+
595+ ret = iio_read_mount_matrix(dev, "mount-matrix", &st->orientation);
596+ if (ret) {
597+ dev_err(dev, "failed to retrieve mounting matrix %d\n", ret);
598+ return ret;
599+ }
600+
601+ st->vdd_supply = devm_regulator_get(dev, "vdd");
602+ if (IS_ERR(st->vdd_supply))
603+ return PTR_ERR(st->vdd_supply);
604+
605+ st->vddio_supply = devm_regulator_get(dev, "vddio");
606+ if (IS_ERR(st->vddio_supply))
607+ return PTR_ERR(st->vddio_supply);
608+
609+ ret = regulator_enable(st->vdd_supply);
610+ if (ret)
611+ return ret;
612+ msleep(INV_ICM42600_POWER_UP_TIME_MS);
613+
614+ ret = devm_add_action_or_reset(dev, inv_icm42600_disable_vdd_reg, st);
615+ if (ret)
616+ return ret;
617+
618+ ret = inv_icm42600_enable_regulator_vddio(st);
619+ if (ret)
620+ return ret;
621+
622+ ret = devm_add_action_or_reset(dev, inv_icm42600_disable_vddio_reg, st);
623+ if (ret)
624+ return ret;
625+
626+ /* setup chip registers */
627+ ret = inv_icm42600_setup(st, bus_setup);
628+ if (ret)
629+ return ret;
630+
631+ ret = inv_icm42600_timestamp_setup(st);
632+ if (ret)
633+ return ret;
634+
635+ ret = inv_icm42600_buffer_init(st);
636+ if (ret)
637+ return ret;
638+
639+ st->indio_gyro = inv_icm42600_gyro_init(st);
640+ if (IS_ERR(st->indio_gyro))
641+ return PTR_ERR(st->indio_gyro);
642+
643+ st->indio_accel = inv_icm42600_accel_init(st);
644+ if (IS_ERR(st->indio_accel))
645+ return PTR_ERR(st->indio_accel);
646+
647+ ret = inv_icm42600_irq_init(st, irq, irq_type, open_drain);
648+ if (ret)
649+ return ret;
650+
651+ /* setup runtime power management */
652+ ret = pm_runtime_set_active(dev);
653+ if (ret)
654+ return ret;
655+ pm_runtime_get_noresume(dev);
656+ pm_runtime_enable(dev);
657+ pm_runtime_set_autosuspend_delay(dev, INV_ICM42600_SUSPEND_DELAY_MS);
658+ pm_runtime_use_autosuspend(dev);
659+ pm_runtime_put(dev);
660+
661+ return devm_add_action_or_reset(dev, inv_icm42600_disable_pm, dev);
662+}
663+EXPORT_SYMBOL_GPL(inv_icm42600_core_probe);
664+
665+/*
666+ * Suspend saves sensors state and turns everything off.
667+ * Check first if runtime suspend has not already done the job.
668+ */
669+static int __maybe_unused inv_icm42600_suspend(struct device *dev)
670+{
671+ struct inv_icm42600_state *st = dev_get_drvdata(dev);
672+ int ret;
673+
674+ mutex_lock(&st->lock);
675+
676+ st->suspended.gyro = st->conf.gyro.mode;
677+ st->suspended.accel = st->conf.accel.mode;
678+ st->suspended.temp = st->conf.temp_en;
679+ if (pm_runtime_suspended(dev)) {
680+ ret = 0;
681+ goto out_unlock;
682+ }
683+
684+ /* disable FIFO data streaming */
685+ if (st->fifo.on) {
686+ ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG,
687+ INV_ICM42600_FIFO_CONFIG_BYPASS);
688+ if (ret)
689+ goto out_unlock;
690+ }
691+
692+ ret = inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF,
693+ INV_ICM42600_SENSOR_MODE_OFF, false,
694+ NULL);
695+ if (ret)
696+ goto out_unlock;
697+
698+ regulator_disable(st->vddio_supply);
699+
700+out_unlock:
701+ mutex_unlock(&st->lock);
702+ return ret;
703+}
704+
705+/*
706+ * System resume gets the system back on and restores the sensors state.
707+ * Manually put runtime power management in system active state.
708+ */
709+static int __maybe_unused inv_icm42600_resume(struct device *dev)
710+{
711+ struct inv_icm42600_state *st = dev_get_drvdata(dev);
712+ int ret;
713+
714+ mutex_lock(&st->lock);
715+
716+ ret = inv_icm42600_enable_regulator_vddio(st);
717+ if (ret)
718+ goto out_unlock;
719+
720+ pm_runtime_disable(dev);
721+ pm_runtime_set_active(dev);
722+ pm_runtime_enable(dev);
723+
724+ /* restore sensors state */
725+ ret = inv_icm42600_set_pwr_mgmt0(st, st->suspended.gyro,
726+ st->suspended.accel,
727+ st->suspended.temp, NULL);
728+ if (ret)
729+ goto out_unlock;
730+
731+ /* restore FIFO data streaming */
732+ if (st->fifo.on)
733+ ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG,
734+ INV_ICM42600_FIFO_CONFIG_STREAM);
735+
736+out_unlock:
737+ mutex_unlock(&st->lock);
738+ return ret;
739+}
740+
741+/* Runtime suspend will turn off sensors that are enabled by iio devices. */
742+static int __maybe_unused inv_icm42600_runtime_suspend(struct device *dev)
743+{
744+ struct inv_icm42600_state *st = dev_get_drvdata(dev);
745+ int ret;
746+
747+ mutex_lock(&st->lock);
748+
749+ /* disable all sensors */
750+ ret = inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF,
751+ INV_ICM42600_SENSOR_MODE_OFF, false,
752+ NULL);
753+ if (ret)
754+ goto error_unlock;
755+
756+ regulator_disable(st->vddio_supply);
757+
758+error_unlock:
759+ mutex_unlock(&st->lock);
760+ return ret;
761+}
762+
763+/* Sensors are enabled by iio devices, no need to turn them back on here. */
764+static int __maybe_unused inv_icm42600_runtime_resume(struct device *dev)
765+{
766+ struct inv_icm42600_state *st = dev_get_drvdata(dev);
767+ int ret;
768+
769+ mutex_lock(&st->lock);
770+
771+ ret = inv_icm42600_enable_regulator_vddio(st);
772+
773+ mutex_unlock(&st->lock);
774+ return ret;
775+}
776+
777+const struct dev_pm_ops inv_icm42600_pm_ops = {
778+ SET_SYSTEM_SLEEP_PM_OPS(inv_icm42600_suspend, inv_icm42600_resume)
779+ SET_RUNTIME_PM_OPS(inv_icm42600_runtime_suspend,
780+ inv_icm42600_runtime_resume, NULL)
781+};
782+EXPORT_SYMBOL_GPL(inv_icm42600_pm_ops);
783+
784+MODULE_AUTHOR("InvenSense, Inc.");
785+MODULE_DESCRIPTION("InvenSense ICM-426xx device driver");
786+MODULE_LICENSE("GPL");
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c+798−0
@@ -0,0 +1,798 @@
1+// SPDX-License-Identifier: GPL-2.0-or-later
2+/*
3+ * Copyright (C) 2020 Invensense, Inc.
4+ */
5+
6+#include <linux/kernel.h>
7+#include <linux/device.h>
8+#include <linux/mutex.h>
9+#include <linux/pm_runtime.h>
10+#include <linux/regmap.h>
11+#include <linux/delay.h>
12+#include <linux/math64.h>
13+#include <linux/iio/iio.h>
14+#include <linux/iio/buffer.h>
15+#include <linux/iio/kfifo_buf.h>
16+
17+#include "inv_icm42600.h"
18+#include "inv_icm42600_temp.h"
19+#include "inv_icm42600_buffer.h"
20+#include "inv_icm42600_timestamp.h"
21+
22+#define INV_ICM42600_GYRO_CHAN(_modifier, _index, _ext_info) \
23+ { \
24+ .type = IIO_ANGL_VEL, \
25+ .modified = 1, \
26+ .channel2 = _modifier, \
27+ .info_mask_separate = \
28+ BIT(IIO_CHAN_INFO_RAW) | \
29+ BIT(IIO_CHAN_INFO_CALIBBIAS), \
30+ .info_mask_shared_by_type = \
31+ BIT(IIO_CHAN_INFO_SCALE), \
32+ .info_mask_shared_by_type_available = \
33+ BIT(IIO_CHAN_INFO_SCALE) | \
34+ BIT(IIO_CHAN_INFO_CALIBBIAS), \
35+ .info_mask_shared_by_all = \
36+ BIT(IIO_CHAN_INFO_SAMP_FREQ), \
37+ .info_mask_shared_by_all_available = \
38+ BIT(IIO_CHAN_INFO_SAMP_FREQ), \
39+ .scan_index = _index, \
40+ .scan_type = { \
41+ .sign = 's', \
42+ .realbits = 16, \
43+ .storagebits = 16, \
44+ .endianness = IIO_BE, \
45+ }, \
46+ .ext_info = _ext_info, \
47+ }
48+
49+enum inv_icm42600_gyro_scan {
50+ INV_ICM42600_GYRO_SCAN_X,
51+ INV_ICM42600_GYRO_SCAN_Y,
52+ INV_ICM42600_GYRO_SCAN_Z,
53+ INV_ICM42600_GYRO_SCAN_TEMP,
54+ INV_ICM42600_GYRO_SCAN_TIMESTAMP,
55+};
56+
57+static const struct iio_chan_spec_ext_info inv_icm42600_gyro_ext_infos[] = {
58+ IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, inv_icm42600_get_mount_matrix),
59+ {},
60+};
61+
62+static const struct iio_chan_spec inv_icm42600_gyro_channels[] = {
63+ INV_ICM42600_GYRO_CHAN(IIO_MOD_X, INV_ICM42600_GYRO_SCAN_X,
64+ inv_icm42600_gyro_ext_infos),
65+ INV_ICM42600_GYRO_CHAN(IIO_MOD_Y, INV_ICM42600_GYRO_SCAN_Y,
66+ inv_icm42600_gyro_ext_infos),
67+ INV_ICM42600_GYRO_CHAN(IIO_MOD_Z, INV_ICM42600_GYRO_SCAN_Z,
68+ inv_icm42600_gyro_ext_infos),
69+ INV_ICM42600_TEMP_CHAN(INV_ICM42600_GYRO_SCAN_TEMP),
70+ IIO_CHAN_SOFT_TIMESTAMP(INV_ICM42600_GYRO_SCAN_TIMESTAMP),
71+};
72+
73+/*
74+ * IIO buffer data: size must be a power of 2 and timestamp aligned
75+ * 16 bytes: 6 bytes angular velocity, 2 bytes temperature, 8 bytes timestamp
76+ */
77+struct inv_icm42600_gyro_buffer {
78+ struct inv_icm42600_fifo_sensor_data gyro;
79+ int16_t temp;
80+ int64_t timestamp __aligned(8);
81+};
82+
83+#define INV_ICM42600_SCAN_MASK_GYRO_3AXIS \
84+ (BIT(INV_ICM42600_GYRO_SCAN_X) | \
85+ BIT(INV_ICM42600_GYRO_SCAN_Y) | \
86+ BIT(INV_ICM42600_GYRO_SCAN_Z))
87+
88+#define INV_ICM42600_SCAN_MASK_TEMP BIT(INV_ICM42600_GYRO_SCAN_TEMP)
89+
90+static const unsigned long inv_icm42600_gyro_scan_masks[] = {
91+ /* 3-axis gyro + temperature */
92+ INV_ICM42600_SCAN_MASK_GYRO_3AXIS | INV_ICM42600_SCAN_MASK_TEMP,
93+ 0,
94+};
95+
96+/* enable gyroscope sensor and FIFO write */
97+static int inv_icm42600_gyro_update_scan_mode(struct iio_dev *indio_dev,
98+ const unsigned long *scan_mask)
99+{
100+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
101+ struct inv_icm42600_timestamp *ts = iio_priv(indio_dev);
102+ struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
103+ unsigned int fifo_en = 0;
104+ unsigned int sleep_gyro = 0;
105+ unsigned int sleep_temp = 0;
106+ unsigned int sleep;
107+ int ret;
108+
109+ mutex_lock(&st->lock);
110+
111+ if (*scan_mask & INV_ICM42600_SCAN_MASK_TEMP) {
112+ /* enable temp sensor */
113+ ret = inv_icm42600_set_temp_conf(st, true, &sleep_temp);
114+ if (ret)
115+ goto out_unlock;
116+ fifo_en |= INV_ICM42600_SENSOR_TEMP;
117+ }
118+
119+ if (*scan_mask & INV_ICM42600_SCAN_MASK_GYRO_3AXIS) {
120+ /* enable gyro sensor */
121+ conf.mode = INV_ICM42600_SENSOR_MODE_LOW_NOISE;
122+ ret = inv_icm42600_set_gyro_conf(st, &conf, &sleep_gyro);
123+ if (ret)
124+ goto out_unlock;
125+ fifo_en |= INV_ICM42600_SENSOR_GYRO;
126+ }
127+
128+ /* update data FIFO write */
129+ inv_icm42600_timestamp_apply_odr(ts, 0, 0, 0);
130+ ret = inv_icm42600_buffer_set_fifo_en(st, fifo_en | st->fifo.en);
131+ if (ret)
132+ goto out_unlock;
133+
134+ ret = inv_icm42600_buffer_update_watermark(st);
135+
136+out_unlock:
137+ mutex_unlock(&st->lock);
138+ /* sleep maximum required time */
139+ if (sleep_gyro > sleep_temp)
140+ sleep = sleep_gyro;
141+ else
142+ sleep = sleep_temp;
143+ if (sleep)
144+ msleep(sleep);
145+ return ret;
146+}
147+
148+static int inv_icm42600_gyro_read_sensor(struct inv_icm42600_state *st,
149+ struct iio_chan_spec const *chan,
150+ int16_t *val)
151+{
152+ struct device *dev = regmap_get_device(st->map);
153+ struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
154+ unsigned int reg;
155+ __be16 *data;
156+ int ret;
157+
158+ if (chan->type != IIO_ANGL_VEL)
159+ return -EINVAL;
160+
161+ switch (chan->channel2) {
162+ case IIO_MOD_X:
163+ reg = INV_ICM42600_REG_GYRO_DATA_X;
164+ break;
165+ case IIO_MOD_Y:
166+ reg = INV_ICM42600_REG_GYRO_DATA_Y;
167+ break;
168+ case IIO_MOD_Z:
169+ reg = INV_ICM42600_REG_GYRO_DATA_Z;
170+ break;
171+ default:
172+ return -EINVAL;
173+ }
174+
175+ pm_runtime_get_sync(dev);
176+ mutex_lock(&st->lock);
177+
178+ /* enable gyro sensor */
179+ conf.mode = INV_ICM42600_SENSOR_MODE_LOW_NOISE;
180+ ret = inv_icm42600_set_gyro_conf(st, &conf, NULL);
181+ if (ret)
182+ goto exit;
183+
184+ /* read gyro register data */
185+ data = (__be16 *)&st->buffer[0];
186+ ret = regmap_bulk_read(st->map, reg, data, sizeof(*data));
187+ if (ret)
188+ goto exit;
189+
190+ *val = (int16_t)be16_to_cpup(data);
191+ if (*val == INV_ICM42600_DATA_INVALID)
192+ ret = -EINVAL;
193+exit:
194+ mutex_unlock(&st->lock);
195+ pm_runtime_mark_last_busy(dev);
196+ pm_runtime_put_autosuspend(dev);
197+ return ret;
198+}
199+
200+/* IIO format int + nano */
201+static const int inv_icm42600_gyro_scale[] = {
202+ /* +/- 2000dps => 0.001065264 rad/s */
203+ [2 * INV_ICM42600_GYRO_FS_2000DPS] = 0,
204+ [2 * INV_ICM42600_GYRO_FS_2000DPS + 1] = 1065264,
205+ /* +/- 1000dps => 0.000532632 rad/s */
206+ [2 * INV_ICM42600_GYRO_FS_1000DPS] = 0,
207+ [2 * INV_ICM42600_GYRO_FS_1000DPS + 1] = 532632,
208+ /* +/- 500dps => 0.000266316 rad/s */
209+ [2 * INV_ICM42600_GYRO_FS_500DPS] = 0,
210+ [2 * INV_ICM42600_GYRO_FS_500DPS + 1] = 266316,
211+ /* +/- 250dps => 0.000133158 rad/s */
212+ [2 * INV_ICM42600_GYRO_FS_250DPS] = 0,
213+ [2 * INV_ICM42600_GYRO_FS_250DPS + 1] = 133158,
214+ /* +/- 125dps => 0.000066579 rad/s */
215+ [2 * INV_ICM42600_GYRO_FS_125DPS] = 0,
216+ [2 * INV_ICM42600_GYRO_FS_125DPS + 1] = 66579,
217+ /* +/- 62.5dps => 0.000033290 rad/s */
218+ [2 * INV_ICM42600_GYRO_FS_62_5DPS] = 0,
219+ [2 * INV_ICM42600_GYRO_FS_62_5DPS + 1] = 33290,
220+ /* +/- 31.25dps => 0.000016645 rad/s */
221+ [2 * INV_ICM42600_GYRO_FS_31_25DPS] = 0,
222+ [2 * INV_ICM42600_GYRO_FS_31_25DPS + 1] = 16645,
223+ /* +/- 15.625dps => 0.000008322 rad/s */
224+ [2 * INV_ICM42600_GYRO_FS_15_625DPS] = 0,
225+ [2 * INV_ICM42600_GYRO_FS_15_625DPS + 1] = 8322,
226+};
227+
228+static int inv_icm42600_gyro_read_scale(struct inv_icm42600_state *st,
229+ int *val, int *val2)
230+{
231+ unsigned int idx;
232+
233+ idx = st->conf.gyro.fs;
234+
235+ *val = inv_icm42600_gyro_scale[2 * idx];
236+ *val2 = inv_icm42600_gyro_scale[2 * idx + 1];
237+ return IIO_VAL_INT_PLUS_NANO;
238+}
239+
240+static int inv_icm42600_gyro_write_scale(struct inv_icm42600_state *st,
241+ int val, int val2)
242+{
243+ struct device *dev = regmap_get_device(st->map);
244+ unsigned int idx;
245+ struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
246+ int ret;
247+
248+ for (idx = 0; idx < ARRAY_SIZE(inv_icm42600_gyro_scale); idx += 2) {
249+ if (val == inv_icm42600_gyro_scale[idx] &&
250+ val2 == inv_icm42600_gyro_scale[idx + 1])
251+ break;
252+ }
253+ if (idx >= ARRAY_SIZE(inv_icm42600_gyro_scale))
254+ return -EINVAL;
255+
256+ conf.fs = idx / 2;
257+
258+ pm_runtime_get_sync(dev);
259+ mutex_lock(&st->lock);
260+
261+ ret = inv_icm42600_set_gyro_conf(st, &conf, NULL);
262+
263+ mutex_unlock(&st->lock);
264+ pm_runtime_mark_last_busy(dev);
265+ pm_runtime_put_autosuspend(dev);
266+
267+ return ret;
268+}
269+
270+/* IIO format int + micro */
271+static const int inv_icm42600_gyro_odr[] = {
272+ /* 12.5Hz */
273+ 12, 500000,
274+ /* 25Hz */
275+ 25, 0,
276+ /* 50Hz */
277+ 50, 0,
278+ /* 100Hz */
279+ 100, 0,
280+ /* 200Hz */
281+ 200, 0,
282+ /* 1kHz */
283+ 1000, 0,
284+ /* 2kHz */
285+ 2000, 0,
286+ /* 4kHz */
287+ 4000, 0,
288+};
289+
290+static const int inv_icm42600_gyro_odr_conv[] = {
291+ INV_ICM42600_ODR_12_5HZ,
292+ INV_ICM42600_ODR_25HZ,
293+ INV_ICM42600_ODR_50HZ,
294+ INV_ICM42600_ODR_100HZ,
295+ INV_ICM42600_ODR_200HZ,
296+ INV_ICM42600_ODR_1KHZ_LN,
297+ INV_ICM42600_ODR_2KHZ_LN,
298+ INV_ICM42600_ODR_4KHZ_LN,
299+};
300+
301+static int inv_icm42600_gyro_read_odr(struct inv_icm42600_state *st,
302+ int *val, int *val2)
303+{
304+ unsigned int odr;
305+ unsigned int i;
306+
307+ odr = st->conf.gyro.odr;
308+
309+ for (i = 0; i < ARRAY_SIZE(inv_icm42600_gyro_odr_conv); ++i) {
310+ if (inv_icm42600_gyro_odr_conv[i] == odr)
311+ break;
312+ }
313+ if (i >= ARRAY_SIZE(inv_icm42600_gyro_odr_conv))
314+ return -EINVAL;
315+
316+ *val = inv_icm42600_gyro_odr[2 * i];
317+ *val2 = inv_icm42600_gyro_odr[2 * i + 1];
318+
319+ return IIO_VAL_INT_PLUS_MICRO;
320+}
321+
322+static int inv_icm42600_gyro_write_odr(struct iio_dev *indio_dev,
323+ int val, int val2)
324+{
325+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
326+ struct inv_icm42600_timestamp *ts = iio_priv(indio_dev);
327+ struct device *dev = regmap_get_device(st->map);
328+ unsigned int idx;
329+ struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
330+ int ret;
331+
332+ for (idx = 0; idx < ARRAY_SIZE(inv_icm42600_gyro_odr); idx += 2) {
333+ if (val == inv_icm42600_gyro_odr[idx] &&
334+ val2 == inv_icm42600_gyro_odr[idx + 1])
335+ break;
336+ }
337+ if (idx >= ARRAY_SIZE(inv_icm42600_gyro_odr))
338+ return -EINVAL;
339+
340+ conf.odr = inv_icm42600_gyro_odr_conv[idx / 2];
341+
342+ pm_runtime_get_sync(dev);
343+ mutex_lock(&st->lock);
344+
345+ ret = inv_icm42600_timestamp_update_odr(ts, inv_icm42600_odr_to_period(conf.odr),
346+ iio_buffer_enabled(indio_dev));
347+ if (ret)
348+ goto out_unlock;
349+
350+ ret = inv_icm42600_set_gyro_conf(st, &conf, NULL);
351+ if (ret)
352+ goto out_unlock;
353+ inv_icm42600_buffer_update_fifo_period(st);
354+ inv_icm42600_buffer_update_watermark(st);
355+
356+out_unlock:
357+ mutex_unlock(&st->lock);
358+ pm_runtime_mark_last_busy(dev);
359+ pm_runtime_put_autosuspend(dev);
360+
361+ return ret;
362+}
363+
364+/*
365+ * Calibration bias values, IIO range format int + nano.
366+ * Value is limited to +/-64dps coded on 12 bits signed. Step is 1/32 dps.
367+ */
368+static int inv_icm42600_gyro_calibbias[] = {
369+ -1, 117010721, /* min: -1.117010721 rad/s */
370+ 0, 545415, /* step: 0.000545415 rad/s */
371+ 1, 116465306, /* max: 1.116465306 rad/s */
372+};
373+
374+static int inv_icm42600_gyro_read_offset(struct inv_icm42600_state *st,
375+ struct iio_chan_spec const *chan,
376+ int *val, int *val2)
377+{
378+ struct device *dev = regmap_get_device(st->map);
379+ int64_t val64;
380+ int32_t bias;
381+ unsigned int reg;
382+ int16_t offset;
383+ uint8_t data[2];
384+ int ret;
385+
386+ if (chan->type != IIO_ANGL_VEL)
387+ return -EINVAL;
388+
389+ switch (chan->channel2) {
390+ case IIO_MOD_X:
391+ reg = INV_ICM42600_REG_OFFSET_USER0;
392+ break;
393+ case IIO_MOD_Y:
394+ reg = INV_ICM42600_REG_OFFSET_USER1;
395+ break;
396+ case IIO_MOD_Z:
397+ reg = INV_ICM42600_REG_OFFSET_USER3;
398+ break;
399+ default:
400+ return -EINVAL;
401+ }
402+
403+ pm_runtime_get_sync(dev);
404+ mutex_lock(&st->lock);
405+
406+ ret = regmap_bulk_read(st->map, reg, st->buffer, sizeof(data));
407+ memcpy(data, st->buffer, sizeof(data));
408+
409+ mutex_unlock(&st->lock);
410+ pm_runtime_mark_last_busy(dev);
411+ pm_runtime_put_autosuspend(dev);
412+ if (ret)
413+ return ret;
414+
415+ /* 12 bits signed value */
416+ switch (chan->channel2) {
417+ case IIO_MOD_X:
418+ offset = sign_extend32(((data[1] & 0x0F) << 8) | data[0], 11);
419+ break;
420+ case IIO_MOD_Y:
421+ offset = sign_extend32(((data[0] & 0xF0) << 4) | data[1], 11);
422+ break;
423+ case IIO_MOD_Z:
424+ offset = sign_extend32(((data[1] & 0x0F) << 8) | data[0], 11);
425+ break;
426+ default:
427+ return -EINVAL;
428+ }
429+
430+ /*
431+ * convert raw offset to dps then to rad/s
432+ * 12 bits signed raw max 64 to dps: 64 / 2048
433+ * dps to rad: Pi / 180
434+ * result in nano (1000000000)
435+ * (offset * 64 * Pi * 1000000000) / (2048 * 180)
436+ */
437+ val64 = (int64_t)offset * 64LL * 3141592653LL;
438+ /* for rounding, add + or - divisor (2048 * 180) divided by 2 */
439+ if (val64 >= 0)
440+ val64 += 2048 * 180 / 2;
441+ else
442+ val64 -= 2048 * 180 / 2;
443+ bias = div_s64(val64, 2048 * 180);
444+ *val = bias / 1000000000L;
445+ *val2 = bias % 1000000000L;
446+
447+ return IIO_VAL_INT_PLUS_NANO;
448+}
449+
450+static int inv_icm42600_gyro_write_offset(struct inv_icm42600_state *st,
451+ struct iio_chan_spec const *chan,
452+ int val, int val2)
453+{
454+ struct device *dev = regmap_get_device(st->map);
455+ int64_t val64, min, max;
456+ unsigned int reg, regval;
457+ int16_t offset;
458+ int ret;
459+
460+ if (chan->type != IIO_ANGL_VEL)
461+ return -EINVAL;
462+
463+ switch (chan->channel2) {
464+ case IIO_MOD_X:
465+ reg = INV_ICM42600_REG_OFFSET_USER0;
466+ break;
467+ case IIO_MOD_Y:
468+ reg = INV_ICM42600_REG_OFFSET_USER1;
469+ break;
470+ case IIO_MOD_Z:
471+ reg = INV_ICM42600_REG_OFFSET_USER3;
472+ break;
473+ default:
474+ return -EINVAL;
475+ }
476+
477+ /* inv_icm42600_gyro_calibbias: min - step - max in nano */
478+ min = (int64_t)inv_icm42600_gyro_calibbias[0] * 1000000000LL +
479+ (int64_t)inv_icm42600_gyro_calibbias[1];
480+ max = (int64_t)inv_icm42600_gyro_calibbias[4] * 1000000000LL +
481+ (int64_t)inv_icm42600_gyro_calibbias[5];
482+ val64 = (int64_t)val * 1000000000LL + (int64_t)val2;
483+ if (val64 < min || val64 > max)
484+ return -EINVAL;
485+
486+ /*
487+ * convert rad/s to dps then to raw value
488+ * rad to dps: 180 / Pi
489+ * dps to raw 12 bits signed, max 64: 2048 / 64
490+ * val in nano (1000000000)
491+ * val * 180 * 2048 / (Pi * 1000000000 * 64)
492+ */
493+ val64 = val64 * 180LL * 2048LL;
494+ /* for rounding, add + or - divisor (3141592653 * 64) divided by 2 */
495+ if (val64 >= 0)
496+ val64 += 3141592653LL * 64LL / 2LL;
497+ else
498+ val64 -= 3141592653LL * 64LL / 2LL;
499+ offset = div64_s64(val64, 3141592653LL * 64LL);
500+
501+ /* clamp value limited to 12 bits signed */
502+ if (offset < -2048)
503+ offset = -2048;
504+ else if (offset > 2047)
505+ offset = 2047;
506+
507+ pm_runtime_get_sync(dev);
508+ mutex_lock(&st->lock);
509+
510+ switch (chan->channel2) {
511+ case IIO_MOD_X:
512+ /* OFFSET_USER1 register is shared */
513+ ret = regmap_read(st->map, INV_ICM42600_REG_OFFSET_USER1,
514+ &regval);
515+ if (ret)
516+ goto out_unlock;
517+ st->buffer[0] = offset & 0xFF;
518+ st->buffer[1] = (regval & 0xF0) | ((offset & 0xF00) >> 8);
519+ break;
520+ case IIO_MOD_Y:
521+ /* OFFSET_USER1 register is shared */
522+ ret = regmap_read(st->map, INV_ICM42600_REG_OFFSET_USER1,
523+ &regval);
524+ if (ret)
525+ goto out_unlock;
526+ st->buffer[0] = ((offset & 0xF00) >> 4) | (regval & 0x0F);
527+ st->buffer[1] = offset & 0xFF;
528+ break;
529+ case IIO_MOD_Z:
530+ /* OFFSET_USER4 register is shared */
531+ ret = regmap_read(st->map, INV_ICM42600_REG_OFFSET_USER4,
532+ &regval);
533+ if (ret)
534+ goto out_unlock;
535+ st->buffer[0] = offset & 0xFF;
536+ st->buffer[1] = (regval & 0xF0) | ((offset & 0xF00) >> 8);
537+ break;
538+ default:
539+ ret = -EINVAL;
540+ goto out_unlock;
541+ }
542+
543+ ret = regmap_bulk_write(st->map, reg, st->buffer, 2);
544+
545+out_unlock:
546+ mutex_unlock(&st->lock);
547+ pm_runtime_mark_last_busy(dev);
548+ pm_runtime_put_autosuspend(dev);
549+ return ret;
550+}
551+
552+static int inv_icm42600_gyro_read_raw(struct iio_dev *indio_dev,
553+ struct iio_chan_spec const *chan,
554+ int *val, int *val2, long mask)
555+{
556+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
557+ int16_t data;
558+ int ret;
559+
560+ switch (chan->type) {
561+ case IIO_ANGL_VEL:
562+ break;
563+ case IIO_TEMP:
564+ return inv_icm42600_temp_read_raw(indio_dev, chan, val, val2, mask);
565+ default:
566+ return -EINVAL;
567+ }
568+
569+ switch (mask) {
570+ case IIO_CHAN_INFO_RAW:
571+ ret = iio_device_claim_direct_mode(indio_dev);
572+ if (ret)
573+ return ret;
574+ ret = inv_icm42600_gyro_read_sensor(st, chan, &data);
575+ iio_device_release_direct_mode(indio_dev);
576+ if (ret)
577+ return ret;
578+ *val = data;
579+ return IIO_VAL_INT;
580+ case IIO_CHAN_INFO_SCALE:
581+ return inv_icm42600_gyro_read_scale(st, val, val2);
582+ case IIO_CHAN_INFO_SAMP_FREQ:
583+ return inv_icm42600_gyro_read_odr(st, val, val2);
584+ case IIO_CHAN_INFO_CALIBBIAS:
585+ return inv_icm42600_gyro_read_offset(st, chan, val, val2);
586+ default:
587+ return -EINVAL;
588+ }
589+}
590+
591+static int inv_icm42600_gyro_read_avail(struct iio_dev *indio_dev,
592+ struct iio_chan_spec const *chan,
593+ const int **vals,
594+ int *type, int *length, long mask)
595+{
596+ if (chan->type != IIO_ANGL_VEL)
597+ return -EINVAL;
598+
599+ switch (mask) {
600+ case IIO_CHAN_INFO_SCALE:
601+ *vals = inv_icm42600_gyro_scale;
602+ *type = IIO_VAL_INT_PLUS_NANO;
603+ *length = ARRAY_SIZE(inv_icm42600_gyro_scale);
604+ return IIO_AVAIL_LIST;
605+ case IIO_CHAN_INFO_SAMP_FREQ:
606+ *vals = inv_icm42600_gyro_odr;
607+ *type = IIO_VAL_INT_PLUS_MICRO;
608+ *length = ARRAY_SIZE(inv_icm42600_gyro_odr);
609+ return IIO_AVAIL_LIST;
610+ case IIO_CHAN_INFO_CALIBBIAS:
611+ *vals = inv_icm42600_gyro_calibbias;
612+ *type = IIO_VAL_INT_PLUS_NANO;
613+ return IIO_AVAIL_RANGE;
614+ default:
615+ return -EINVAL;
616+ }
617+}
618+
619+static int inv_icm42600_gyro_write_raw(struct iio_dev *indio_dev,
620+ struct iio_chan_spec const *chan,
621+ int val, int val2, long mask)
622+{
623+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
624+ int ret;
625+
626+ if (chan->type != IIO_ANGL_VEL)
627+ return -EINVAL;
628+
629+ switch (mask) {
630+ case IIO_CHAN_INFO_SCALE:
631+ ret = iio_device_claim_direct_mode(indio_dev);
632+ if (ret)
633+ return ret;
634+ ret = inv_icm42600_gyro_write_scale(st, val, val2);
635+ iio_device_release_direct_mode(indio_dev);
636+ return ret;
637+ case IIO_CHAN_INFO_SAMP_FREQ:
638+ return inv_icm42600_gyro_write_odr(indio_dev, val, val2);
639+ case IIO_CHAN_INFO_CALIBBIAS:
640+ ret = iio_device_claim_direct_mode(indio_dev);
641+ if (ret)
642+ return ret;
643+ ret = inv_icm42600_gyro_write_offset(st, chan, val, val2);
644+ iio_device_release_direct_mode(indio_dev);
645+ return ret;
646+ default:
647+ return -EINVAL;
648+ }
649+}
650+
651+static int inv_icm42600_gyro_write_raw_get_fmt(struct iio_dev *indio_dev,
652+ struct iio_chan_spec const *chan,
653+ long mask)
654+{
655+ if (chan->type != IIO_ANGL_VEL)
656+ return -EINVAL;
657+
658+ switch (mask) {
659+ case IIO_CHAN_INFO_SCALE:
660+ return IIO_VAL_INT_PLUS_NANO;
661+ case IIO_CHAN_INFO_SAMP_FREQ:
662+ return IIO_VAL_INT_PLUS_MICRO;
663+ case IIO_CHAN_INFO_CALIBBIAS:
664+ return IIO_VAL_INT_PLUS_NANO;
665+ default:
666+ return -EINVAL;
667+ }
668+}
669+
670+static int inv_icm42600_gyro_hwfifo_set_watermark(struct iio_dev *indio_dev,
671+ unsigned int val)
672+{
673+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
674+ int ret;
675+
676+ mutex_lock(&st->lock);
677+
678+ st->fifo.watermark.gyro = val;
679+ ret = inv_icm42600_buffer_update_watermark(st);
680+
681+ mutex_unlock(&st->lock);
682+
683+ return ret;
684+}
685+
686+static int inv_icm42600_gyro_hwfifo_flush(struct iio_dev *indio_dev,
687+ unsigned int count)
688+{
689+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
690+ int ret;
691+
692+ if (count == 0)
693+ return 0;
694+
695+ mutex_lock(&st->lock);
696+
697+ ret = inv_icm42600_buffer_hwfifo_flush(st, count);
698+ if (!ret)
699+ ret = st->fifo.nb.gyro;
700+
701+ mutex_unlock(&st->lock);
702+
703+ return ret;
704+}
705+
706+static const struct iio_info inv_icm42600_gyro_info = {
707+ .read_raw = inv_icm42600_gyro_read_raw,
708+ .read_avail = inv_icm42600_gyro_read_avail,
709+ .write_raw = inv_icm42600_gyro_write_raw,
710+ .write_raw_get_fmt = inv_icm42600_gyro_write_raw_get_fmt,
711+ .debugfs_reg_access = inv_icm42600_debugfs_reg,
712+ .update_scan_mode = inv_icm42600_gyro_update_scan_mode,
713+ .hwfifo_set_watermark = inv_icm42600_gyro_hwfifo_set_watermark,
714+ .hwfifo_flush_to_buffer = inv_icm42600_gyro_hwfifo_flush,
715+};
716+
717+struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st)
718+{
719+ struct device *dev = regmap_get_device(st->map);
720+ const char *name;
721+ struct inv_icm42600_timestamp *ts;
722+ struct iio_dev *indio_dev;
723+ struct iio_buffer *buffer;
724+ int ret;
725+
726+ name = devm_kasprintf(dev, GFP_KERNEL, "%s-gyro", st->name);
727+ if (!name)
728+ return ERR_PTR(-ENOMEM);
729+
730+ indio_dev = devm_iio_device_alloc(dev, sizeof(*ts));
731+ if (!indio_dev)
732+ return ERR_PTR(-ENOMEM);
733+
734+ buffer = devm_iio_kfifo_allocate(dev);
735+ if (!buffer)
736+ return ERR_PTR(-ENOMEM);
737+
738+ ts = iio_priv(indio_dev);
739+ inv_icm42600_timestamp_init(ts, inv_icm42600_odr_to_period(st->conf.gyro.odr));
740+
741+ iio_device_set_drvdata(indio_dev, st);
742+ indio_dev->name = name;
743+ indio_dev->info = &inv_icm42600_gyro_info;
744+ indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
745+ indio_dev->channels = inv_icm42600_gyro_channels;
746+ indio_dev->num_channels = ARRAY_SIZE(inv_icm42600_gyro_channels);
747+ indio_dev->available_scan_masks = inv_icm42600_gyro_scan_masks;
748+ indio_dev->setup_ops = &inv_icm42600_buffer_ops;
749+
750+ iio_device_attach_buffer(indio_dev, buffer);
751+
752+ ret = devm_iio_device_register(dev, indio_dev);
753+ if (ret)
754+ return ERR_PTR(ret);
755+
756+ return indio_dev;
757+}
758+
759+int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev)
760+{
761+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
762+ struct inv_icm42600_timestamp *ts = iio_priv(indio_dev);
763+ ssize_t i, size;
764+ unsigned int no;
765+ const void *accel, *gyro, *timestamp;
766+ const int8_t *temp;
767+ unsigned int odr;
768+ int64_t ts_val;
769+ struct inv_icm42600_gyro_buffer buffer;
770+
771+ /* parse all fifo packets */
772+ for (i = 0, no = 0; i < st->fifo.count; i += size, ++no) {
773+ size = inv_icm42600_fifo_decode_packet(&st->fifo.data[i],
774+ &accel, &gyro, &temp, &timestamp, &odr);
775+ /* quit if error or FIFO is empty */
776+ if (size <= 0)
777+ return size;
778+
779+ /* skip packet if no gyro data or data is invalid */
780+ if (gyro == NULL || !inv_icm42600_fifo_is_data_valid(gyro))
781+ continue;
782+
783+ /* update odr */
784+ if (odr & INV_ICM42600_SENSOR_GYRO)
785+ inv_icm42600_timestamp_apply_odr(ts, st->fifo.period,
786+ st->fifo.nb.total, no);
787+
788+ /* buffer is copied to userspace, zeroing it to avoid any data leak */
789+ memset(&buffer, 0, sizeof(buffer));
790+ memcpy(&buffer.gyro, gyro, sizeof(buffer.gyro));
791+ /* convert 8 bits FIFO temperature in high resolution format */
792+ buffer.temp = temp ? (*temp * 64) : 0;
793+ ts_val = inv_icm42600_timestamp_pop(ts);
794+ iio_push_to_buffers_with_timestamp(indio_dev, &buffer, ts_val);
795+ }
796+
797+ return 0;
798+}
drivers/iio/imu/inv_icm42600/inv_icm42600_i2c.c+101−0
@@ -0,0 +1,101 @@
1+// SPDX-License-Identifier: GPL-2.0-or-later
2+/*
3+ * Copyright (C) 2020 InvenSense, Inc.
4+ */
5+
6+#include <linux/kernel.h>
7+#include <linux/device.h>
8+#include <linux/module.h>
9+#include <linux/mod_devicetable.h>
10+#include <linux/i2c.h>
11+#include <linux/regmap.h>
12+#include <linux/property.h>
13+
14+#include "inv_icm42600.h"
15+
16+static int inv_icm42600_i2c_bus_setup(struct inv_icm42600_state *st)
17+{
18+ unsigned int mask, val;
19+ int ret;
20+
21+ /* setup interface registers */
22+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG6,
23+ INV_ICM42600_INTF_CONFIG6_MASK,
24+ INV_ICM42600_INTF_CONFIG6_I3C_EN);
25+ if (ret)
26+ return ret;
27+
28+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG4,
29+ INV_ICM42600_INTF_CONFIG4_I3C_BUS_ONLY, 0);
30+ if (ret)
31+ return ret;
32+
33+ /* set slew rates for I2C and SPI */
34+ mask = INV_ICM42600_DRIVE_CONFIG_I2C_MASK |
35+ INV_ICM42600_DRIVE_CONFIG_SPI_MASK;
36+ val = INV_ICM42600_DRIVE_CONFIG_I2C(INV_ICM42600_SLEW_RATE_12_36NS) |
37+ INV_ICM42600_DRIVE_CONFIG_SPI(INV_ICM42600_SLEW_RATE_12_36NS);
38+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_DRIVE_CONFIG,
39+ mask, val);
40+ if (ret)
41+ return ret;
42+
43+ /* disable SPI bus */
44+ return regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG0,
45+ INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK,
46+ INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_SPI_DIS);
47+}
48+
49+static int inv_icm42600_probe(struct i2c_client *client)
50+{
51+ const void *match;
52+ enum inv_icm42600_chip chip;
53+ struct regmap *regmap;
54+
55+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
56+ return -ENOTSUPP;
57+
58+ match = device_get_match_data(&client->dev);
59+ if (!match)
60+ return -EINVAL;
61+ chip = (enum inv_icm42600_chip)match;
62+
63+ regmap = devm_regmap_init_i2c(client, &inv_icm42600_regmap_config);
64+ if (IS_ERR(regmap))
65+ return PTR_ERR(regmap);
66+
67+ return inv_icm42600_core_probe(regmap, chip, client->irq,
68+ inv_icm42600_i2c_bus_setup);
69+}
70+
71+static const struct of_device_id inv_icm42600_of_matches[] = {
72+ {
73+ .compatible = "invensense,icm42600",
74+ .data = (void *)INV_CHIP_ICM42600,
75+ }, {
76+ .compatible = "invensense,icm42602",
77+ .data = (void *)INV_CHIP_ICM42602,
78+ }, {
79+ .compatible = "invensense,icm42605",
80+ .data = (void *)INV_CHIP_ICM42605,
81+ }, {
82+ .compatible = "invensense,icm42622",
83+ .data = (void *)INV_CHIP_ICM42622,
84+ },
85+ {}
86+};
87+MODULE_DEVICE_TABLE(of, inv_icm42600_of_matches);
88+
89+static struct i2c_driver inv_icm42600_driver = {
90+ .driver = {
91+ .name = "inv-icm42600-i2c",
92+ .of_match_table = inv_icm42600_of_matches,
93+ .pm = &inv_icm42600_pm_ops,
94+ },
95+ .probe_new = inv_icm42600_probe,
96+};
97+module_i2c_driver(inv_icm42600_driver);
98+
99+MODULE_AUTHOR("InvenSense, Inc.");
100+MODULE_DESCRIPTION("InvenSense ICM-426xx I2C driver");
101+MODULE_LICENSE("GPL");
drivers/iio/imu/inv_icm42600/inv_icm42600_spi.c+100−0
@@ -0,0 +1,100 @@
1+// SPDX-License-Identifier: GPL-2.0-or-later
2+/*
3+ * Copyright (C) 2020 InvenSense, Inc.
4+ */
5+
6+#include <linux/kernel.h>
7+#include <linux/device.h>
8+#include <linux/module.h>
9+#include <linux/mod_devicetable.h>
10+#include <linux/spi/spi.h>
11+#include <linux/regmap.h>
12+#include <linux/property.h>
13+
14+#include "inv_icm42600.h"
15+
16+static int inv_icm42600_spi_bus_setup(struct inv_icm42600_state *st)
17+{
18+ unsigned int mask, val;
19+ int ret;
20+
21+ /* setup interface registers */
22+ val = INV_ICM42600_INTF_CONFIG6_I3C_EN |
23+ INV_ICM42600_INTF_CONFIG6_I3C_SDR_EN |
24+ INV_ICM42600_INTF_CONFIG6_I3C_DDR_EN;
25+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG6,
26+ INV_ICM42600_INTF_CONFIG6_MASK, val);
27+ if (ret)
28+ return ret;
29+
30+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG4,
31+ INV_ICM42600_INTF_CONFIG4_I3C_BUS_ONLY, 0);
32+ if (ret)
33+ return ret;
34+
35+ /* set slew rates for I2C and SPI */
36+ mask = INV_ICM42600_DRIVE_CONFIG_I2C_MASK |
37+ INV_ICM42600_DRIVE_CONFIG_SPI_MASK;
38+ val = INV_ICM42600_DRIVE_CONFIG_I2C(INV_ICM42600_SLEW_RATE_20_60NS) |
39+ INV_ICM42600_DRIVE_CONFIG_SPI(INV_ICM42600_SLEW_RATE_INF_2NS);
40+ ret = regmap_update_bits(st->map, INV_ICM42600_REG_DRIVE_CONFIG,
41+ mask, val);
42+ if (ret)
43+ return ret;
44+
45+ /* disable i2c bus */
46+ return regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG0,
47+ INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK,
48+ INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_I2C_DIS);
49+}
50+
51+static int inv_icm42600_probe(struct spi_device *spi)
52+{
53+ const void *match;
54+ enum inv_icm42600_chip chip;
55+ struct regmap *regmap;
56+
57+ match = device_get_match_data(&spi->dev);
58+ if (!match)
59+ return -EINVAL;
60+ chip = (enum inv_icm42600_chip)match;
61+
62+ regmap = devm_regmap_init_spi(spi, &inv_icm42600_regmap_config);
63+ if (IS_ERR(regmap))
64+ return PTR_ERR(regmap);
65+
66+ return inv_icm42600_core_probe(regmap, chip, spi->irq,
67+ inv_icm42600_spi_bus_setup);
68+}
69+
70+static const struct of_device_id inv_icm42600_of_matches[] = {
71+ {
72+ .compatible = "invensense,icm42600",
73+ .data = (void *)INV_CHIP_ICM42600,
74+ }, {
75+ .compatible = "invensense,icm42602",
76+ .data = (void *)INV_CHIP_ICM42602,
77+ }, {
78+ .compatible = "invensense,icm42605",
79+ .data = (void *)INV_CHIP_ICM42605,
80+ }, {
81+ .compatible = "invensense,icm42622",
82+ .data = (void *)INV_CHIP_ICM42622,
83+ },
84+ {}
85+};
86+MODULE_DEVICE_TABLE(of, inv_icm42600_of_matches);
87+
88+static struct spi_driver inv_icm42600_driver = {
89+ .driver = {
90+ .name = "inv-icm42600-spi",
91+ .of_match_table = inv_icm42600_of_matches,
92+ .pm = &inv_icm42600_pm_ops,
93+ },
94+ .probe = inv_icm42600_probe,
95+};
96+module_spi_driver(inv_icm42600_driver);
97+
98+MODULE_AUTHOR("InvenSense, Inc.");
99+MODULE_DESCRIPTION("InvenSense ICM-426xx SPI driver");
100+MODULE_LICENSE("GPL");
drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c+84−0
@@ -0,0 +1,84 @@
1+// SPDX-License-Identifier: GPL-2.0-or-later
2+/*
3+ * Copyright (C) 2020 Invensense, Inc.
4+ */
5+
6+#include <linux/kernel.h>
7+#include <linux/device.h>
8+#include <linux/mutex.h>
9+#include <linux/pm_runtime.h>
10+#include <linux/regmap.h>
11+#include <linux/iio/iio.h>
12+
13+#include "inv_icm42600.h"
14+#include "inv_icm42600_temp.h"
15+
16+static int inv_icm42600_temp_read(struct inv_icm42600_state *st, int16_t *temp)
17+{
18+ struct device *dev = regmap_get_device(st->map);
19+ __be16 *raw;
20+ int ret;
21+
22+ pm_runtime_get_sync(dev);
23+ mutex_lock(&st->lock);
24+
25+ ret = inv_icm42600_set_temp_conf(st, true, NULL);
26+ if (ret)
27+ goto exit;
28+
29+ raw = (__be16 *)&st->buffer[0];
30+ ret = regmap_bulk_read(st->map, INV_ICM42600_REG_TEMP_DATA, raw, sizeof(*raw));
31+ if (ret)
32+ goto exit;
33+
34+ *temp = (int16_t)be16_to_cpup(raw);
35+ if (*temp == INV_ICM42600_DATA_INVALID)
36+ ret = -EINVAL;
37+
38+exit:
39+ mutex_unlock(&st->lock);
40+ pm_runtime_mark_last_busy(dev);
41+ pm_runtime_put_autosuspend(dev);
42+
43+ return ret;
44+}
45+
46+int inv_icm42600_temp_read_raw(struct iio_dev *indio_dev,
47+ struct iio_chan_spec const *chan,
48+ int *val, int *val2, long mask)
49+{
50+ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
51+ int16_t temp;
52+ int ret;
53+
54+ if (chan->type != IIO_TEMP)
55+ return -EINVAL;
56+
57+ switch (mask) {
58+ case IIO_CHAN_INFO_RAW:
59+ ret = iio_device_claim_direct_mode(indio_dev);
60+ if (ret)
61+ return ret;
62+ ret = inv_icm42600_temp_read(st, &temp);
63+ iio_device_release_direct_mode(indio_dev);
64+ if (ret)
65+ return ret;
66+ *val = temp;
67+ return IIO_VAL_INT;
68+ /*
69+ * T°C = (temp / 132.48) + 25
70+ * Tm°C = 1000 * ((temp * 100 / 13248) + 25)
71+ * scale: 100000 / 13248 ~= 7.548309
72+ * offset: 25000
73+ */
74+ case IIO_CHAN_INFO_SCALE:
75+ *val = 7;
76+ *val2 = 548309;
77+ return IIO_VAL_INT_PLUS_MICRO;
78+ case IIO_CHAN_INFO_OFFSET:
79+ *val = 25000;
80+ return IIO_VAL_INT;
81+ default:
82+ return -EINVAL;
83+ }
84+}
drivers/iio/imu/inv_icm42600/inv_icm42600_temp.h+30−0
@@ -0,0 +1,30 @@
1+/* SPDX-License-Identifier: GPL-2.0-or-later */
2+/*
3+ * Copyright (C) 2020 Invensense, Inc.
4+ */
5+
6+#ifndef INV_ICM42600_TEMP_H_
7+#define INV_ICM42600_TEMP_H_
8+
9+#include <linux/iio/iio.h>
10+
11+#define INV_ICM42600_TEMP_CHAN(_index) \
12+ { \
13+ .type = IIO_TEMP, \
14+ .info_mask_separate = \
15+ BIT(IIO_CHAN_INFO_RAW) | \
16+ BIT(IIO_CHAN_INFO_OFFSET) | \
17+ BIT(IIO_CHAN_INFO_SCALE), \
18+ .scan_index = _index, \
19+ .scan_type = { \
20+ .sign = 's', \
21+ .realbits = 16, \
22+ .storagebits = 16, \
23+ }, \
24+ }
25+
26+int inv_icm42600_temp_read_raw(struct iio_dev *indio_dev,
27+ struct iio_chan_spec const *chan,
28+ int *val, int *val2, long mask);
29+
30+#endif
drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c+195−0
@@ -0,0 +1,195 @@
1+// SPDX-License-Identifier: GPL-2.0-or-later
2+/*
3+ * Copyright (C) 2020 Invensense, Inc.
4+ */
5+
6+#include <linux/kernel.h>
7+#include <linux/regmap.h>
8+#include <linux/math64.h>
9+
10+#include "inv_icm42600.h"
11+#include "inv_icm42600_timestamp.h"
12+
13+/* internal chip period is 32kHz, 31250ns */
14+#define INV_ICM42600_TIMESTAMP_PERIOD 31250
15+/* allow a jitter of +/- 2% */
16+#define INV_ICM42600_TIMESTAMP_JITTER 2
17+/* compute min and max periods accepted */
18+#define INV_ICM42600_TIMESTAMP_MIN_PERIOD(_p) \
19+ (((_p) * (100 - INV_ICM42600_TIMESTAMP_JITTER)) / 100)
20+#define INV_ICM42600_TIMESTAMP_MAX_PERIOD(_p) \
21+ (((_p) * (100 + INV_ICM42600_TIMESTAMP_JITTER)) / 100)
22+
23+/* Add a new value inside an accumulator and update the estimate value */
24+static void inv_update_acc(struct inv_icm42600_timestamp_acc *acc, uint32_t val)
25+{
26+ uint64_t sum = 0;
27+ size_t i;
28+
29+ acc->values[acc->idx++] = val;
30+ if (acc->idx >= ARRAY_SIZE(acc->values))
31+ acc->idx = 0;
32+
33+ /* compute the mean of all stored values, use 0 as empty slot */
34+ for (i = 0; i < ARRAY_SIZE(acc->values); ++i) {
35+ if (acc->values[i] == 0)
36+ break;
37+ sum += acc->values[i];
38+ }
39+
40+ acc->val = div_u64(sum, i);
41+}
42+
43+void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts,
44+ uint32_t period)
45+{
46+ /* initial odr for sensor after reset is 1kHz */
47+ const uint32_t default_period = 1000000;
48+
49+ /* current multiplier and period values after reset */
50+ ts->mult = default_period / INV_ICM42600_TIMESTAMP_PERIOD;
51+ ts->period = default_period;
52+ /* new set multiplier is the one from chip initialization */
53+ ts->new_mult = period / INV_ICM42600_TIMESTAMP_PERIOD;
54+
55+ /* use theoretical value for chip period */
56+ inv_update_acc(&ts->chip_period, INV_ICM42600_TIMESTAMP_PERIOD);
57+}
58+
59+int inv_icm42600_timestamp_setup(struct inv_icm42600_state *st)
60+{
61+ unsigned int val;
62+
63+ /* enable timestamp register */
64+ val = INV_ICM42600_TMST_CONFIG_TMST_TO_REGS_EN |
65+ INV_ICM42600_TMST_CONFIG_TMST_EN;
66+ return regmap_update_bits(st->map, INV_ICM42600_REG_TMST_CONFIG,
67+ INV_ICM42600_TMST_CONFIG_MASK, val);
68+}
69+
70+int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts,
71+ uint32_t period, bool fifo)
72+{
73+ /* when FIFO is on, prevent odr change if one is already pending */
74+ if (fifo && ts->new_mult != 0)
75+ return -EAGAIN;
76+
77+ ts->new_mult = period / INV_ICM42600_TIMESTAMP_PERIOD;
78+
79+ return 0;
80+}
81+
82+static bool inv_validate_period(uint32_t period, uint32_t mult)
83+{
84+ const uint32_t chip_period = INV_ICM42600_TIMESTAMP_PERIOD;
85+ uint32_t period_min, period_max;
86+
87+ /* check that period is acceptable */
88+ period_min = INV_ICM42600_TIMESTAMP_MIN_PERIOD(chip_period) * mult;
89+ period_max = INV_ICM42600_TIMESTAMP_MAX_PERIOD(chip_period) * mult;
90+ if (period > period_min && period < period_max)
91+ return true;
92+ else
93+ return false;
94+}
95+
96+static bool inv_compute_chip_period(struct inv_icm42600_timestamp *ts,
97+ uint32_t mult, uint32_t period)
98+{
99+ uint32_t new_chip_period;
100+
101+ if (!inv_validate_period(period, mult))
102+ return false;
103+
104+ /* update chip internal period estimation */
105+ new_chip_period = period / mult;
106+ inv_update_acc(&ts->chip_period, new_chip_period);
107+
108+ return true;
109+}
110+
111+void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp *ts,
112+ uint32_t fifo_period, size_t fifo_nb,
113+ size_t sensor_nb, int64_t timestamp)
114+{
115+ struct inv_icm42600_timestamp_interval *it;
116+ int64_t delta, interval;
117+ const uint32_t fifo_mult = fifo_period / INV_ICM42600_TIMESTAMP_PERIOD;
118+ uint32_t period = ts->period;
119+ int32_t m;
120+ bool valid = false;
121+
122+ if (fifo_nb == 0)
123+ return;
124+
125+ /* update interrupt timestamp and compute chip and sensor periods */
126+ it = &ts->it;
127+ it->lo = it->up;
128+ it->up = timestamp;
129+ delta = it->up - it->lo;
130+ if (it->lo != 0) {
131+ /* compute period: delta time divided by number of samples */
132+ period = div_s64(delta, fifo_nb);
133+ valid = inv_compute_chip_period(ts, fifo_mult, period);
134+ /* update sensor period if chip internal period is updated */
135+ if (valid)
136+ ts->period = ts->mult * ts->chip_period.val;
137+ }
138+
139+ /* no previous data, compute theoritical value from interrupt */
140+ if (ts->timestamp == 0) {
141+ /* elapsed time: sensor period * sensor samples number */
142+ interval = (int64_t)ts->period * (int64_t)sensor_nb;
143+ ts->timestamp = it->up - interval;
144+ return;
145+ }
146+
147+ /* if interrupt interval is valid, sync with interrupt timestamp */
148+ if (valid) {
149+ /* compute measured fifo_period */
150+ fifo_period = fifo_mult * ts->chip_period.val;
151+ /* delta time between last sample and last interrupt */
152+ delta = it->lo - ts->timestamp;
153+ /* if there are multiple samples, go back to first one */
154+ while (delta >= (fifo_period * 3 / 2))
155+ delta -= fifo_period;
156+ /* compute maximal adjustment value */
157+ m = INV_ICM42600_TIMESTAMP_MAX_PERIOD(ts->period) - ts->period;
158+ if (delta > m)
159+ delta = m;
160+ else if (delta < -m)
161+ delta = -m;
162+ ts->timestamp += delta;
163+ }
164+}
165+
166+void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts,
167+ uint32_t fifo_period, size_t fifo_nb,
168+ unsigned int fifo_no)
169+{
170+ int64_t interval;
171+ uint32_t fifo_mult;
172+
173+ if (ts->new_mult == 0)
174+ return;
175+
176+ /* update to new multiplier and update period */
177+ ts->mult = ts->new_mult;
178+ ts->new_mult = 0;
179+ ts->period = ts->mult * ts->chip_period.val;
180+
181+ /*
182+ * After ODR change the time interval with the previous sample is
183+ * undertermined (depends when the change occures). So we compute the
184+ * timestamp from the current interrupt using the new FIFO period, the
185+ * total number of samples and the current sample numero.
186+ */
187+ if (ts->timestamp != 0) {
188+ /* compute measured fifo period */
189+ fifo_mult = fifo_period / INV_ICM42600_TIMESTAMP_PERIOD;
190+ fifo_period = fifo_mult * ts->chip_period.val;
191+ /* computes time interval between interrupt and this sample */
192+ interval = (int64_t)(fifo_nb - fifo_no) * (int64_t)fifo_period;
193+ ts->timestamp = ts->it.up - interval;
194+ }
195+}
drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h+85−0
@@ -0,0 +1,85 @@
1+/* SPDX-License-Identifier: GPL-2.0-or-later */
2+/*
3+ * Copyright (C) 2020 Invensense, Inc.
4+ */
5+
6+#ifndef INV_ICM42600_TIMESTAMP_H_
7+#define INV_ICM42600_TIMESTAMP_H_
8+
9+#include <linux/kernel.h>
10+
11+struct inv_icm42600_state;
12+
13+/**
14+ * struct inv_icm42600_timestamp_interval - timestamps interval
15+ * @lo: interval lower bound
16+ * @up: interval upper bound
17+ */
18+struct inv_icm42600_timestamp_interval {
19+ int64_t lo;
20+ int64_t up;
21+};
22+
23+/**
24+ * struct inv_icm42600_timestamp_acc - accumulator for computing an estimation
25+ * @val: current estimation of the value, the mean of all values
26+ * @idx: current index of the next free place in values table
27+ * @values: table of all measured values, use for computing the mean
28+ */
29+struct inv_icm42600_timestamp_acc {
30+ uint32_t val;
31+ size_t idx;
32+ uint32_t values[32];
33+};
34+
35+/**
36+ * struct inv_icm42600_timestamp - timestamp management states
37+ * @it: interrupts interval timestamps
38+ * @timestamp: store last timestamp for computing next data timestamp
39+ * @mult: current internal period multiplier
40+ * @new_mult: new set internal period multiplier (not yet effective)
41+ * @period: measured current period of the sensor
42+ * @chip_period: accumulator for computing internal chip period
43+ */
44+struct inv_icm42600_timestamp {
45+ struct inv_icm42600_timestamp_interval it;
46+ int64_t timestamp;
47+ uint32_t mult;
48+ uint32_t new_mult;
49+ uint32_t period;
50+ struct inv_icm42600_timestamp_acc chip_period;
51+};
52+
53+void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts,
54+ uint32_t period);
55+
56+int inv_icm42600_timestamp_setup(struct inv_icm42600_state *st);
57+
58+int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts,
59+ uint32_t period, bool fifo);
60+
61+void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp *ts,
62+ uint32_t fifo_period, size_t fifo_nb,
63+ size_t sensor_nb, int64_t timestamp);
64+
65+static inline int64_t
66+inv_icm42600_timestamp_pop(struct inv_icm42600_timestamp *ts)
67+{
68+ ts->timestamp += ts->period;
69+ return ts->timestamp;
70+}
71+
72+void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts,
73+ uint32_t fifo_period, size_t fifo_nb,
74+ unsigned int fifo_no);
75+
76+static inline void
77+inv_icm42600_timestamp_reset(struct inv_icm42600_timestamp *ts)
78+{
79+ const struct inv_icm42600_timestamp_interval interval_init = {0LL, 0LL};
80+
81+ ts->it = interval_init;
82+ ts->timestamp = 0;
83+}
84+
85+#endif
drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c+1−5
@@ -101,8 +101,8 @@ static int inv_mpu_process_acpi_config(struct i2c_client *client, · 100 unmodified lines
101101 unsigned short *primary_addr,
102102 unsigned short *secondary_addr)
103103 {
104+ struct acpi_device *adev = ACPI_COMPANION(&client->dev);
104105 const struct acpi_device_id *id;
105− struct acpi_device *adev;
106106 u32 i2c_addr = 0;
107107 LIST_HEAD(resources);
108108 int ret;
@@ -112,10 +112,6 @@ static int inv_mpu_process_acpi_config(struct i2c_client *client, · 3 unmodified lines
112112 if (!id)
113113 return -ENODEV;
114114
115− adev = ACPI_COMPANION(&client->dev);
116− if (!adev)
117− return -ENODEV;
118−
119115 ret = acpi_dev_get_resources(adev, &resources,
120116 acpi_i2c_check_resource, &i2c_addr);
121117 if (ret < 0)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c+0−1
@@ -1530,7 +1530,6 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, · 1529 unmodified lines
15301530 }
15311531
15321532 dev_set_drvdata(dev, indio_dev);
1533− indio_dev->dev.parent = dev;
15341533 /* name will be NULL when enumerated via ACPI */
15351534 if (name)
15361535 indio_dev->name = name;
drivers/iio/imu/kmx61.c+0−1
@@ -1248,7 +1248,6 @@ static struct iio_dev *kmx61_indiodev_setup(struct kmx61_data *data, · 1247 unmodified lines
12481248
12491249 kmx61_set_data(indio_dev, data);
12501250
1251− indio_dev->dev.parent = &data->client->dev;
12521251 indio_dev->channels = chan;
12531252 indio_dev->num_channels = num_channels;
12541253 indio_dev->name = name;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c+0−1
@@ -2152,7 +2152,6 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw, · 2151 unmodified lines
21522152 return NULL;
21532153
21542154 iio_dev->modes = INDIO_DIRECT_MODE;
2155− iio_dev->dev.parent = hw->dev;
21562155 iio_dev->available_scan_masks = st_lsm6dsx_available_scan_masks;
21572156 iio_dev->channels = hw->settings->channels[id].chan;
21582157 iio_dev->num_channels = hw->settings->channels[id].len;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c+0−1
@@ -735,7 +735,6 @@ st_lsm6dsx_shub_alloc_iiodev(struct st_lsm6dsx_hw *hw, · 734 unmodified lines
735735 return NULL;
736736
737737 iio_dev->modes = INDIO_DIRECT_MODE;
738− iio_dev->dev.parent = hw->dev;
739738 iio_dev->info = &st_lsm6dsx_ext_info;
740739
741740 sensor = iio_priv(iio_dev);
drivers/iio/industrialio-buffer.c+43−15
@@ -19,7 +19,9 @@ · 18 unmodified lines
1919 #include <linux/sched/signal.h>
2020
2121 #include <linux/iio/iio.h>
22+#include <linux/iio/iio-opaque.h>
2223 #include "iio_core.h"
24+#include "iio_core_trigger.h"
2325 #include <linux/iio/sysfs.h>
2426 #include <linux/iio/buffer.h>
2527 #include <linux/iio/buffer_impl.h>
@@ -598,8 +600,10 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev, · 572 unmodified lines
598600 static void iio_buffer_activate(struct iio_dev *indio_dev,
599601 struct iio_buffer *buffer)
600602 {
603+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
604+
601605 iio_buffer_get(buffer);
602− list_add(&buffer->buffer_list, &indio_dev->buffer_list);
606+ list_add(&buffer->buffer_list, &iio_dev_opaque->buffer_list);
603607 }
604608
605609 static void iio_buffer_deactivate(struct iio_buffer *buffer)
@@ -611,10 +615,11 @@ static void iio_buffer_deactivate(struct iio_buffer *buffer) · 5 unmodified lines
611615
612616 static void iio_buffer_deactivate_all(struct iio_dev *indio_dev)
613617 {
618+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
614619 struct iio_buffer *buffer, *_buffer;
615620
616621 list_for_each_entry_safe(buffer, _buffer,
617− &indio_dev->buffer_list, buffer_list)
622+ &iio_dev_opaque->buffer_list, buffer_list)
618623 iio_buffer_deactivate(buffer);
619624 }
620625
@@ -687,6 +692,7 @@ static int iio_verify_update(struct iio_dev *indio_dev, · 66 unmodified lines
687692 struct iio_buffer *insert_buffer, struct iio_buffer *remove_buffer,
688693 struct iio_device_config *config)
689694 {
695+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
690696 unsigned long *compound_mask;
691697 const unsigned long *scan_mask;
692698 bool strict_scanmask = false;
@@ -709,12 +715,12 @@ static int iio_verify_update(struct iio_dev *indio_dev, · 16 unmodified lines
709715 * to verify.
710716 */
711717 if (remove_buffer && !insert_buffer &&
712− list_is_singular(&indio_dev->buffer_list))
718+ list_is_singular(&iio_dev_opaque->buffer_list))
713719 return 0;
714720
715721 modes = indio_dev->modes;
716722
717− list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
723+ list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) {
718724 if (buffer == remove_buffer)
719725 continue;
720726 modes &= buffer->access->modes;
@@ -735,7 +741,7 @@ static int iio_verify_update(struct iio_dev *indio_dev, · 14 unmodified lines
735741 * Keep things simple for now and only allow a single buffer to
736742 * be connected in hardware mode.
737743 */
738− if (insert_buffer && !list_empty(&indio_dev->buffer_list))
744+ if (insert_buffer && !list_empty(&iio_dev_opaque->buffer_list))
739745 return -EINVAL;
740746 config->mode = INDIO_BUFFER_HARDWARE;
741747 strict_scanmask = true;
@@ -755,7 +761,7 @@ static int iio_verify_update(struct iio_dev *indio_dev, · 13 unmodified lines
755761
756762 scan_timestamp = false;
757763
758− list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
764+ list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) {
759765 if (buffer == remove_buffer)
760766 continue;
761767 bitmap_or(compound_mask, compound_mask, buffer->scan_mask,
@@ -901,10 +907,11 @@ error_clear_mux_table: · 139 unmodified lines
901907
902908 static int iio_update_demux(struct iio_dev *indio_dev)
903909 {
910+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
904911 struct iio_buffer *buffer;
905912 int ret;
906913
907− list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
914+ list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) {
908915 ret = iio_buffer_update_demux(indio_dev, buffer);
909916 if (ret < 0)
910917 goto error_clear_mux_table;
@@ -912,7 +919,7 @@ static int iio_update_demux(struct iio_dev *indio_dev) · 1 unmodified line
912919 return 0;
913920
914921 error_clear_mux_table:
915− list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list)
922+ list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list)
916923 iio_buffer_demux_free(buffer);
917924
918925 return ret;
@@ -921,6 +928,7 @@ error_clear_mux_table: · 2 unmodified lines
921928 static int iio_enable_buffers(struct iio_dev *indio_dev,
922929 struct iio_device_config *config)
923930 {
931+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
924932 struct iio_buffer *buffer;
925933 int ret;
926934
@@ -957,25 +965,37 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, · 30 unmodified lines
957965 indio_dev->info->hwfifo_set_watermark(indio_dev,
958966 config->watermark);
959967
960− list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
968+ list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) {
961969 ret = iio_buffer_enable(buffer, indio_dev);
962970 if (ret)
963971 goto err_disable_buffers;
964972 }
965973
974+ if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
975+ ret = iio_trigger_attach_poll_func(indio_dev->trig,
976+ indio_dev->pollfunc);
977+ if (ret)
978+ goto err_disable_buffers;
979+ }
980+
966981 if (indio_dev->setup_ops->postenable) {
967982 ret = indio_dev->setup_ops->postenable(indio_dev);
968983 if (ret) {
969984 dev_dbg(&indio_dev->dev,
970985 "Buffer not started: postenable failed (%d)\n", ret);
971− goto err_disable_buffers;
986+ goto err_detach_pollfunc;
972987 }
973988 }
974989
975990 return 0;
976991
992+err_detach_pollfunc:
993+ if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
994+ iio_trigger_detach_poll_func(indio_dev->trig,
995+ indio_dev->pollfunc);
996+ }
977997 err_disable_buffers:
978− list_for_each_entry_continue_reverse(buffer, &indio_dev->buffer_list,
998+ list_for_each_entry_continue_reverse(buffer, &iio_dev_opaque->buffer_list,
979999 buffer_list)
9801000 iio_buffer_disable(buffer, indio_dev);
9811001 err_run_postdisable:
@@ -990,12 +1010,13 @@ err_undo_config: · 8 unmodified lines
9901010
9911011 static int iio_disable_buffers(struct iio_dev *indio_dev)
9921012 {
1013+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
9931014 struct iio_buffer *buffer;
9941015 int ret = 0;
9951016 int ret2;
9961017
9971018 /* Wind down existing buffers - iff there are any */
998− if (list_empty(&indio_dev->buffer_list))
1019+ if (list_empty(&iio_dev_opaque->buffer_list))
9991020 return 0;
10001021
10011022 /*
@@ -1011,7 +1032,12 @@ static int iio_disable_buffers(struct iio_dev *indio_dev) · 9 unmodified lines
10111032 ret = ret2;
10121033 }
10131034
1014− list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
1035+ if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
1036+ iio_trigger_detach_poll_func(indio_dev->trig,
1037+ indio_dev->pollfunc);
1038+ }
1039+
1040+ list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) {
10151041 ret2 = iio_buffer_disable(buffer, indio_dev);
10161042 if (ret2 && !ret)
10171043 ret = ret2;
@@ -1034,6 +1060,7 @@ static int __iio_update_buffers(struct iio_dev *indio_dev, · 16 unmodified lines
10341060 struct iio_buffer *insert_buffer,
10351061 struct iio_buffer *remove_buffer)
10361062 {
1063+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
10371064 struct iio_device_config new_config;
10381065 int ret;
10391066
@@ -1058,7 +1085,7 @@ static int __iio_update_buffers(struct iio_dev *indio_dev, · 18 unmodified lines
10581085 iio_buffer_activate(indio_dev, insert_buffer);
10591086
10601087 /* If no buffers in list, we are done */
1061− if (list_empty(&indio_dev->buffer_list))
1088+ if (list_empty(&iio_dev_opaque->buffer_list))
10621089 return 0;
10631090
10641091 ret = iio_enable_buffers(indio_dev, &new_config);
@@ -1407,10 +1434,11 @@ static int iio_push_to_buffer(struct iio_buffer *buffer, const void *data) · 342 unmodified lines
14071434 */
14081435 int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data)
14091436 {
1437+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
14101438 int ret;
14111439 struct iio_buffer *buf;
14121440
1413− list_for_each_entry(buf, &indio_dev->buffer_list, buffer_list) {
1441+ list_for_each_entry(buf, &iio_dev_opaque->buffer_list, buffer_list) {
14141442 ret = iio_push_to_buffer(buf, data);
14151443 if (ret < 0)
14161444 return ret;
drivers/iio/industrialio-core.c+81−48
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 #include <linux/debugfs.h>
2626 #include <linux/mutex.h>
2727 #include <linux/iio/iio.h>
28+#include <linux/iio/iio-opaque.h>
2829 #include "iio_core.h"
2930 #include "iio_core_trigger.h"
3031 #include <linux/iio/sysfs.h>
@@ -164,6 +165,19 @@ static const char * const iio_chan_info_postfix[] = { · 133 unmodified lines
164165 [IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type",
165166 };
166167
168+#if defined(CONFIG_DEBUG_FS)
169+/**
170+ * There's also a CONFIG_DEBUG_FS guard in include/linux/iio/iio.h for
171+ * iio_get_debugfs_dentry() to make it inline if CONFIG_DEBUG_FS is undefined
172+ */
173+struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
174+{
175+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
176+ return iio_dev_opaque->debugfs_dentry;
177+}
178+EXPORT_SYMBOL_GPL(iio_get_debugfs_dentry);
179+#endif
180+
167181 /**
168182 * iio_find_channel_from_si() - get channel from its scan index
169183 * @indio_dev: device
@@ -197,7 +211,8 @@ EXPORT_SYMBOL(iio_read_const_attr); · 27 unmodified lines
197211 int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)
198212 {
199213 int ret;
200− const struct iio_event_interface *ev_int = indio_dev->event_interface;
214+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
215+ const struct iio_event_interface *ev_int = iio_dev_opaque->event_interface;
201216
202217 ret = mutex_lock_interruptible(&indio_dev->mlock);
203218 if (ret)
@@ -307,35 +322,37 @@ static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf, · 103 unmodified lines
307322 size_t count, loff_t *ppos)
308323 {
309324 struct iio_dev *indio_dev = file->private_data;
325+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
310326 unsigned val = 0;
311327 int ret;
312328
313329 if (*ppos > 0)
314330 return simple_read_from_buffer(userbuf, count, ppos,
315− indio_dev->read_buf,
316− indio_dev->read_buf_len);
331+ iio_dev_opaque->read_buf,
332+ iio_dev_opaque->read_buf_len);
317333
318334 ret = indio_dev->info->debugfs_reg_access(indio_dev,
319− indio_dev->cached_reg_addr,
335+ iio_dev_opaque->cached_reg_addr,
320336 0, &val);
321337 if (ret) {
322338 dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__);
323339 return ret;
324340 }
325341
326− indio_dev->read_buf_len = snprintf(indio_dev->read_buf,
327− sizeof(indio_dev->read_buf),
328− "0x%X\n", val);
342+ iio_dev_opaque->read_buf_len = snprintf(iio_dev_opaque->read_buf,
343+ sizeof(iio_dev_opaque->read_buf),
344+ "0x%X\n", val);
329345
330346 return simple_read_from_buffer(userbuf, count, ppos,
331− indio_dev->read_buf,
332− indio_dev->read_buf_len);
347+ iio_dev_opaque->read_buf,
348+ iio_dev_opaque->read_buf_len);
333349 }
334350
335351 static ssize_t iio_debugfs_write_reg(struct file *file,
336352 const char __user *userbuf, size_t count, loff_t *ppos)
337353 {
338354 struct iio_dev *indio_dev = file->private_data;
355+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
339356 unsigned reg, val;
340357 char buf[80];
341358 int ret;
@@ -350,10 +367,10 @@ static ssize_t iio_debugfs_write_reg(struct file *file, · 8 unmodified lines
350367
351368 switch (ret) {
352369 case 1:
353− indio_dev->cached_reg_addr = reg;
370+ iio_dev_opaque->cached_reg_addr = reg;
354371 break;
355372 case 2:
356− indio_dev->cached_reg_addr = reg;
373+ iio_dev_opaque->cached_reg_addr = reg;
357374 ret = indio_dev->info->debugfs_reg_access(indio_dev, reg,
358375 val, NULL);
359376 if (ret) {
@@ -377,23 +394,28 @@ static const struct file_operations iio_debugfs_reg_fops = { · 17 unmodified lines
377394
378395 static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
379396 {
380− debugfs_remove_recursive(indio_dev->debugfs_dentry);
397+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
398+ debugfs_remove_recursive(iio_dev_opaque->debugfs_dentry);
381399 }
382400
383401 static void iio_device_register_debugfs(struct iio_dev *indio_dev)
384402 {
403+ struct iio_dev_opaque *iio_dev_opaque;
404+
385405 if (indio_dev->info->debugfs_reg_access == NULL)
386406 return;
387407
388408 if (!iio_debugfs_dentry)
389409 return;
390410
391− indio_dev->debugfs_dentry =
411+ iio_dev_opaque = to_iio_dev_opaque(indio_dev);
412+
413+ iio_dev_opaque->debugfs_dentry =
392414 debugfs_create_dir(dev_name(&indio_dev->dev),
393415 iio_debugfs_dentry);
394416
395417 debugfs_create_file("direct_reg_access", 0644,
396− indio_dev->debugfs_dentry, indio_dev,
418+ iio_dev_opaque->debugfs_dentry, indio_dev,
397419 &iio_debugfs_reg_fops);
398420 }
399421 #else
@@ -1116,6 +1138,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev, · 716 unmodified lines
11161138 enum iio_shared_by shared_by,
11171139 const long *infomask)
11181140 {
1141+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
11191142 int i, ret, attrcount = 0;
11201143
11211144 for_each_set_bit(i, infomask, sizeof(*infomask)*8) {
@@ -1128,7 +1151,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev, · 6 unmodified lines
11281151 i,
11291152 shared_by,
11301153 &indio_dev->dev,
1131− &indio_dev->channel_attr_list);
1154+ &iio_dev_opaque->channel_attr_list);
11321155 if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
11331156 continue;
11341157 else if (ret < 0)
@@ -1144,6 +1167,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev, · 9 unmodified lines
11441167 enum iio_shared_by shared_by,
11451168 const long *infomask)
11461169 {
1170+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
11471171 int i, ret, attrcount = 0;
11481172 char *avail_postfix;
11491173
@@ -1163,7 +1187,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev, · 13 unmodified lines
11631187 i,
11641188 shared_by,
11651189 &indio_dev->dev,
1166− &indio_dev->channel_attr_list);
1190+ &iio_dev_opaque->channel_attr_list);
11671191 kfree(avail_postfix);
11681192 if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
11691193 continue;
@@ -1178,6 +1202,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev, · 8 unmodified lines
11781202 static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
11791203 struct iio_chan_spec const *chan)
11801204 {
1205+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
11811206 int ret, attrcount = 0;
11821207 const struct iio_chan_spec_ext_info *ext_info;
11831208
@@ -1253,7 +1278,7 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev, · 69 unmodified lines
12531278 i,
12541279 ext_info->shared,
12551280 &indio_dev->dev,
1256− &indio_dev->channel_attr_list);
1281+ &iio_dev_opaque->channel_attr_list);
12571282 i++;
12581283 if (ret == -EBUSY && ext_info->shared)
12591284 continue;
@@ -1388,6 +1413,7 @@ static DEVICE_ATTR(current_timestamp_clock, S_IRUGO | S_IWUSR, · 128 unmodified lines
13881413
13891414 static int iio_device_register_sysfs(struct iio_dev *indio_dev)
13901415 {
1416+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
13911417 int i, ret = 0, attrcount, attrn, attrcount_orig = 0;
13921418 struct iio_dev_attr *p;
13931419 struct attribute **attr, *clk = NULL;
@@ -1417,7 +1443,7 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev) · 23 unmodified lines
14171443 attrcount += ret;
14181444 }
14191445
1420− if (indio_dev->event_interface)
1446+ if (iio_dev_opaque->event_interface)
14211447 clk = &dev_attr_current_timestamp_clock.attr;
14221448
14231449 if (indio_dev->name)
@@ -1427,52 +1453,56 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev) · 3 unmodified lines
14271453 if (clk)
14281454 attrcount++;
14291455
1430− indio_dev->chan_attr_group.attrs = kcalloc(attrcount + 1,
1431− sizeof(indio_dev->chan_attr_group.attrs[0]),
1432− GFP_KERNEL);
1433− if (indio_dev->chan_attr_group.attrs == NULL) {
1456+ iio_dev_opaque->chan_attr_group.attrs =
1457+ kcalloc(attrcount + 1,
1458+ sizeof(iio_dev_opaque->chan_attr_group.attrs[0]),
1459+ GFP_KERNEL);
1460+ if (iio_dev_opaque->chan_attr_group.attrs == NULL) {
14341461 ret = -ENOMEM;
14351462 goto error_clear_attrs;
14361463 }
14371464 /* Copy across original attributes */
14381465 if (indio_dev->info->attrs)
1439− memcpy(indio_dev->chan_attr_group.attrs,
1466+ memcpy(iio_dev_opaque->chan_attr_group.attrs,
14401467 indio_dev->info->attrs->attrs,
1441− sizeof(indio_dev->chan_attr_group.attrs[0])
1468+ sizeof(iio_dev_opaque->chan_attr_group.attrs[0])
14421469 *attrcount_orig);
14431470 attrn = attrcount_orig;
14441471 /* Add all elements from the list. */
1445− list_for_each_entry(p, &indio_dev->channel_attr_list, l)
1446− indio_dev->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr;
1472+ list_for_each_entry(p, &iio_dev_opaque->channel_attr_list, l)
1473+ iio_dev_opaque->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr;
14471474 if (indio_dev->name)
1448− indio_dev->chan_attr_group.attrs[attrn++] = &dev_attr_name.attr;
1475+ iio_dev_opaque->chan_attr_group.attrs[attrn++] = &dev_attr_name.attr;
14491476 if (indio_dev->label)
1450− indio_dev->chan_attr_group.attrs[attrn++] = &dev_attr_label.attr;
1477+ iio_dev_opaque->chan_attr_group.attrs[attrn++] = &dev_attr_label.attr;
14511478 if (clk)
1452− indio_dev->chan_attr_group.attrs[attrn++] = clk;
1479+ iio_dev_opaque->chan_attr_group.attrs[attrn++] = clk;
14531480
14541481 indio_dev->groups[indio_dev->groupcounter++] =
1455− &indio_dev->chan_attr_group;
1482+ &iio_dev_opaque->chan_attr_group;
14561483
14571484 return 0;
14581485
14591486 error_clear_attrs:
1460− iio_free_chan_devattr_list(&indio_dev->channel_attr_list);
1487+ iio_free_chan_devattr_list(&iio_dev_opaque->channel_attr_list);
14611488
14621489 return ret;
14631490 }
14641491
14651492 static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
14661493 {
1494+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
14671495
1468− iio_free_chan_devattr_list(&indio_dev->channel_attr_list);
1469− kfree(indio_dev->chan_attr_group.attrs);
1470− indio_dev->chan_attr_group.attrs = NULL;
1496+ iio_free_chan_devattr_list(&iio_dev_opaque->channel_attr_list);
1497+ kfree(iio_dev_opaque->chan_attr_group.attrs);
1498+ iio_dev_opaque->chan_attr_group.attrs = NULL;
14711499 }
14721500
14731501 static void iio_dev_release(struct device *device)
14741502 {
14751503 struct iio_dev *indio_dev = dev_to_iio_dev(device);
1504+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
1505+
14761506 if (indio_dev->modes & INDIO_ALL_TRIGGERED_MODES)
14771507 iio_device_unregister_trigger_consumer(indio_dev);
14781508 iio_device_unregister_eventset(indio_dev);
@@ -1481,7 +1511,7 @@ static void iio_dev_release(struct device *device) · 2 unmodified lines
14811511 iio_buffer_put(indio_dev->buffer);
14821512
14831513 ida_simple_remove(&iio_ida, indio_dev->id);
1484− kfree(indio_dev);
1514+ kfree(iio_dev_opaque);
14851515 }
14861516
14871517 struct device_type iio_device_type = {
@@ -1493,23 +1523,26 @@ struct device_type iio_device_type = { · 5 unmodified lines
14931523 * iio_device_alloc() - allocate an iio_dev from a driver
14941524 * @sizeof_priv: Space to allocate for private structure.
14951525 **/
1496−struct iio_dev *iio_device_alloc(int sizeof_priv)
1526+struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
14971527 {
1528+ struct iio_dev_opaque *iio_dev_opaque;
14981529 struct iio_dev *dev;
14991530 size_t alloc_size;
15001531
1501− alloc_size = sizeof(struct iio_dev);
1532+ alloc_size = sizeof(struct iio_dev_opaque);
15021533 if (sizeof_priv) {
15031534 alloc_size = ALIGN(alloc_size, IIO_ALIGN);
15041535 alloc_size += sizeof_priv;
15051536 }
1506− /* ensure 32-byte alignment of whole construct ? */
1507− alloc_size += IIO_ALIGN - 1;
15081537
1509− dev = kzalloc(alloc_size, GFP_KERNEL);
1510− if (!dev)
1538+ iio_dev_opaque = kzalloc(alloc_size, GFP_KERNEL);
1539+ if (!iio_dev_opaque)
15111540 return NULL;
15121541
1542+ dev = &iio_dev_opaque->indio_dev;
1543+ dev->priv = (char *)iio_dev_opaque +
1544+ ALIGN(sizeof(struct iio_dev_opaque), IIO_ALIGN);
1545+
15131546 dev->dev.groups = dev->groups;
15141547 dev->dev.type = &iio_device_type;
15151548 dev->dev.bus = &iio_bus_type;
@@ -1517,17 +1550,17 @@ struct iio_dev *iio_device_alloc(int sizeof_priv) · 1 unmodified line
15171550 dev_set_drvdata(&dev->dev, (void *)dev);
15181551 mutex_init(&dev->mlock);
15191552 mutex_init(&dev->info_exist_lock);
1520− INIT_LIST_HEAD(&dev->channel_attr_list);
1553+ INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
15211554
15221555 dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
15231556 if (dev->id < 0) {
15241557 /* cannot use a dev_err as the name isn't available */
15251558 pr_err("failed to get device id\n");
1526− kfree(dev);
1559+ kfree(iio_dev_opaque);
15271560 return NULL;
15281561 }
15291562 dev_set_name(&dev->dev, "iio:device%d", dev->id);
1530− INIT_LIST_HEAD(&dev->buffer_list);
1563+ INIT_LIST_HEAD(&iio_dev_opaque->buffer_list);
15311564
15321565 return dev;
15331566 }
@@ -1551,7 +1584,7 @@ static void devm_iio_device_release(struct device *dev, void *res) · 17 unmodified lines
15511584
15521585 /**
15531586 * devm_iio_device_alloc - Resource-managed iio_device_alloc()
1554− * @dev: Device to allocate iio_dev for
1587+ * @parent: Device to allocate iio_dev for, and parent for this IIO device
15551588 * @sizeof_priv: Space to allocate for private structure.
15561589 *
15571590 * Managed iio_device_alloc. iio_dev allocated with this function is
@@ -1560,7 +1593,7 @@ static void devm_iio_device_release(struct device *dev, void *res) · 2 unmodified lines
15601593 * RETURNS:
15611594 * Pointer to allocated iio_dev on success, NULL on failure.
15621595 */
1563−struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv)
1596+struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv)
15641597 {
15651598 struct iio_dev **ptr, *iio_dev;
15661599
@@ -1569,10 +1602,10 @@ struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv) · 2 unmodified lines
15691602 if (!ptr)
15701603 return NULL;
15711604
1572− iio_dev = iio_device_alloc(sizeof_priv);
1605+ iio_dev = iio_device_alloc(parent, sizeof_priv);
15731606 if (iio_dev) {
15741607 *ptr = iio_dev;
1575− devres_add(dev, ptr);
1608+ devres_add(parent, ptr);
15761609 } else {
15771610 devres_free(ptr);
15781611 }
drivers/iio/industrialio-event.c+40−28
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 #include <linux/uaccess.h>
1919 #include <linux/wait.h>
2020 #include <linux/iio/iio.h>
21+#include <linux/iio/iio-opaque.h>
2122 #include "iio_core.h"
2223 #include <linux/iio/sysfs.h>
2324 #include <linux/iio/events.h>
@@ -62,7 +63,8 @@ bool iio_event_enabled(const struct iio_event_interface *ev_int) · 38 unmodified lines
6263 **/
6364 int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
6465 {
65− struct iio_event_interface *ev_int = indio_dev->event_interface;
66+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
67+ struct iio_event_interface *ev_int = iio_dev_opaque->event_interface;
6668 struct iio_event_data ev;
6769 int copied;
6870
@@ -96,7 +98,8 @@ static __poll_t iio_event_poll(struct file *filep, · 27 unmodified lines
9698 struct poll_table_struct *wait)
9799 {
98100 struct iio_dev *indio_dev = filep->private_data;
99− struct iio_event_interface *ev_int = indio_dev->event_interface;
101+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
102+ struct iio_event_interface *ev_int = iio_dev_opaque->event_interface;
100103 __poll_t events = 0;
101104
102105 if (!indio_dev->info)
@@ -116,7 +119,8 @@ static ssize_t iio_event_chrdev_read(struct file *filep, · 13 unmodified lines
116119 loff_t *f_ps)
117120 {
118121 struct iio_dev *indio_dev = filep->private_data;
119− struct iio_event_interface *ev_int = indio_dev->event_interface;
122+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
123+ struct iio_event_interface *ev_int = iio_dev_opaque->event_interface;
120124 unsigned int copied;
121125 int ret;
122126
@@ -165,7 +169,8 @@ static ssize_t iio_event_chrdev_read(struct file *filep, · 42 unmodified lines
165169 static int iio_event_chrdev_release(struct inode *inode, struct file *filep)
166170 {
167171 struct iio_dev *indio_dev = filep->private_data;
168− struct iio_event_interface *ev_int = indio_dev->event_interface;
172+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
173+ struct iio_event_interface *ev_int = iio_dev_opaque->event_interface;
169174
170175 clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
171176
@@ -184,7 +189,8 @@ static const struct file_operations iio_event_chrdev_fileops = { · 12 unmodified lines
184189
185190 int iio_event_getfd(struct iio_dev *indio_dev)
186191 {
187− struct iio_event_interface *ev_int = indio_dev->event_interface;
192+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
193+ struct iio_event_interface *ev_int = iio_dev_opaque->event_interface;
188194 int fd;
189195
190196 if (ev_int == NULL)
@@ -343,6 +349,7 @@ static int iio_device_add_event(struct iio_dev *indio_dev, · 152 unmodified lines
343349 enum iio_event_type type, enum iio_event_direction dir,
344350 enum iio_shared_by shared_by, const unsigned long *mask)
345351 {
352+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
346353 ssize_t (*show)(struct device *, struct device_attribute *, char *);
347354 ssize_t (*store)(struct device *, struct device_attribute *,
348355 const char *, size_t);
@@ -376,7 +383,7 @@ static int iio_device_add_event(struct iio_dev *indio_dev, · 27 unmodified lines
376383
377384 ret = __iio_add_chan_devattr(postfix, chan, show, store,
378385 (i << 16) | spec_index, shared_by, &indio_dev->dev,
379− &indio_dev->event_interface->dev_attr_list);
386+ &iio_dev_opaque->event_interface->dev_attr_list);
380387 kfree(postfix);
381388
382389 if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
@@ -469,6 +476,7 @@ static void iio_setup_ev_int(struct iio_event_interface *ev_int) · 86 unmodified lines
469476 static const char *iio_event_group_name = "events";
470477 int iio_device_register_eventset(struct iio_dev *indio_dev)
471478 {
479+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
472480 struct iio_dev_attr *p;
473481 int ret = 0, attrcount_orig = 0, attrcount, attrn;
474482 struct attribute **attr;
@@ -477,14 +485,14 @@ int iio_device_register_eventset(struct iio_dev *indio_dev) · 2 unmodified lines
477485 iio_check_for_dynamic_events(indio_dev)))
478486 return 0;
479487
480− indio_dev->event_interface =
488+ iio_dev_opaque->event_interface =
481489 kzalloc(sizeof(struct iio_event_interface), GFP_KERNEL);
482− if (indio_dev->event_interface == NULL)
490+ if (iio_dev_opaque->event_interface == NULL)
483491 return -ENOMEM;
484492
485− INIT_LIST_HEAD(&indio_dev->event_interface->dev_attr_list);
493+ INIT_LIST_HEAD(&iio_dev_opaque->event_interface->dev_attr_list);
486494
487− iio_setup_ev_int(indio_dev->event_interface);
495+ iio_setup_ev_int(iio_dev_opaque->event_interface);
488496 if (indio_dev->info->event_attrs != NULL) {
489497 attr = indio_dev->info->event_attrs->attrs;
490498 while (*attr++ != NULL)
@@ -498,35 +506,35 @@ int iio_device_register_eventset(struct iio_dev *indio_dev) · 7 unmodified lines
498506 attrcount += ret;
499507 }
500508
501− indio_dev->event_interface->group.name = iio_event_group_name;
502− indio_dev->event_interface->group.attrs = kcalloc(attrcount + 1,
503− sizeof(indio_dev->event_interface->group.attrs[0]),
509+ iio_dev_opaque->event_interface->group.name = iio_event_group_name;
510+ iio_dev_opaque->event_interface->group.attrs = kcalloc(attrcount + 1,
511+ sizeof(iio_dev_opaque->event_interface->group.attrs[0]),
504512 GFP_KERNEL);
505− if (indio_dev->event_interface->group.attrs == NULL) {
513+ if (iio_dev_opaque->event_interface->group.attrs == NULL) {
506514 ret = -ENOMEM;
507515 goto error_free_setup_event_lines;
508516 }
509517 if (indio_dev->info->event_attrs)
510− memcpy(indio_dev->event_interface->group.attrs,
518+ memcpy(iio_dev_opaque->event_interface->group.attrs,
511519 indio_dev->info->event_attrs->attrs,
512− sizeof(indio_dev->event_interface->group.attrs[0])
520+ sizeof(iio_dev_opaque->event_interface->group.attrs[0])
513521 *attrcount_orig);
514522 attrn = attrcount_orig;
515523 /* Add all elements from the list. */
516524 list_for_each_entry(p,
517− &indio_dev->event_interface->dev_attr_list,
525+ &iio_dev_opaque->event_interface->dev_attr_list,
518526 l)
519− indio_dev->event_interface->group.attrs[attrn++] =
527+ iio_dev_opaque->event_interface->group.attrs[attrn++] =
520528 &p->dev_attr.attr;
521529 indio_dev->groups[indio_dev->groupcounter++] =
522− &indio_dev->event_interface->group;
530+ &iio_dev_opaque->event_interface->group;
523531
524532 return 0;
525533
526534 error_free_setup_event_lines:
527− iio_free_chan_devattr_list(&indio_dev->event_interface->dev_attr_list);
528− kfree(indio_dev->event_interface);
529− indio_dev->event_interface = NULL;
535+ iio_free_chan_devattr_list(&iio_dev_opaque->event_interface->dev_attr_list);
536+ kfree(iio_dev_opaque->event_interface);
537+ iio_dev_opaque->event_interface = NULL;
530538 return ret;
531539 }
532540
@@ -539,16 +547,20 @@ error_free_setup_event_lines: · 6 unmodified lines
539547 */
540548 void iio_device_wakeup_eventset(struct iio_dev *indio_dev)
541549 {
542− if (indio_dev->event_interface == NULL)
550+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
551+
552+ if (iio_dev_opaque->event_interface == NULL)
543553 return;
544− wake_up(&indio_dev->event_interface->wait);
554+ wake_up(&iio_dev_opaque->event_interface->wait);
545555 }
546556
547557 void iio_device_unregister_eventset(struct iio_dev *indio_dev)
548558 {
549− if (indio_dev->event_interface == NULL)
559+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
560+
561+ if (iio_dev_opaque->event_interface == NULL)
550562 return;
551− iio_free_chan_devattr_list(&indio_dev->event_interface->dev_attr_list);
552− kfree(indio_dev->event_interface->group.attrs);
553− kfree(indio_dev->event_interface);
563+ iio_free_chan_devattr_list(&iio_dev_opaque->event_interface->dev_attr_list);
564+ kfree(iio_dev_opaque->event_interface->group.attrs);
565+ kfree(iio_dev_opaque->event_interface);
554566 }
drivers/iio/industrialio-trigger.c+4−18
@@ -239,8 +239,8 @@ static void iio_trigger_put_irq(struct iio_trigger *trig, int irq) · 238 unmodified lines
239239 * the relevant function is in there may be the best option.
240240 */
241241 /* Worth protecting against double additions? */
242−static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
243− struct iio_poll_func *pf)
242+int iio_trigger_attach_poll_func(struct iio_trigger *trig,
243+ struct iio_poll_func *pf)
244244 {
245245 int ret = 0;
246246 bool notinuse
@@ -290,8 +290,8 @@ out_put_module: · 43 unmodified lines
290290 return ret;
291291 }
292292
293−static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
294− struct iio_poll_func *pf)
293+int iio_trigger_detach_poll_func(struct iio_trigger *trig,
294+ struct iio_poll_func *pf)
295295 {
296296 int ret = 0;
297297 bool no_other_users
@@ -705,17 +705,3 @@ void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev) · 407 unmodified lines
705705 if (indio_dev->trig)
706706 iio_trigger_put(indio_dev->trig);
707707 }
708−
709−int iio_triggered_buffer_postenable(struct iio_dev *indio_dev)
710−{
711− return iio_trigger_attach_poll_func(indio_dev->trig,
712− indio_dev->pollfunc);
713−}
714−EXPORT_SYMBOL(iio_triggered_buffer_postenable);
715−
716−int iio_triggered_buffer_predisable(struct iio_dev *indio_dev)
717−{
718− return iio_trigger_detach_poll_func(indio_dev->trig,
719− indio_dev->pollfunc);
720−}
721−EXPORT_SYMBOL(iio_triggered_buffer_predisable);
drivers/iio/light/acpi-als.c+0−1
@@ -178,7 +178,6 @@ static int acpi_als_add(struct acpi_device *device) · 177 unmodified lines
178178 mutex_init(&als->lock);
179179
180180 indio_dev->name = ACPI_ALS_DEVICE_NAME;
181− indio_dev->dev.parent = &device->dev;
182181 indio_dev->info = &acpi_als_info;
183182 indio_dev->modes = INDIO_BUFFER_SOFTWARE;
184183 indio_dev->channels = acpi_als_channels;
drivers/iio/light/adjd_s311.c+0−1
@@ -259,7 +259,6 @@ static int adjd_s311_probe(struct i2c_client *client, · 258 unmodified lines
259259 i2c_set_clientdata(client, indio_dev);
260260 data->client = client;
261261
262− indio_dev->dev.parent = &client->dev;
263262 indio_dev->info = &adjd_s311_info;
264263 indio_dev->name = ADJD_S311_DRV_NAME;
265264 indio_dev->channels = adjd_s311_channels;
drivers/iio/light/adux1020.c+0−1
@@ -785,7 +785,6 @@ static int adux1020_probe(struct i2c_client *client, · 784 unmodified lines
785785 if (!indio_dev)
786786 return -ENOMEM;
787787
788− indio_dev->dev.parent = &client->dev;
789788 indio_dev->info = &adux1020_info;
790789 indio_dev->name = ADUX1020_DRV_NAME;
791790 indio_dev->channels = adux1020_channels;
drivers/iio/light/al3010.c+0−1
@@ -179,7 +179,6 @@ static int al3010_probe(struct i2c_client *client, · 178 unmodified lines
179179 i2c_set_clientdata(client, indio_dev);
180180 data->client = client;
181181
182− indio_dev->dev.parent = &client->dev;
183182 indio_dev->info = &al3010_info;
184183 indio_dev->name = AL3010_DRV_NAME;
185184 indio_dev->channels = al3010_channels;
drivers/iio/light/al3320a.c+0−1
@@ -202,7 +202,6 @@ static int al3320a_probe(struct i2c_client *client, · 201 unmodified lines
202202 i2c_set_clientdata(client, indio_dev);
203203 data->client = client;
204204
205− indio_dev->dev.parent = &client->dev;
206205 indio_dev->info = &al3320a_info;
207206 indio_dev->name = AL3320A_DRV_NAME;
208207 indio_dev->channels = al3320a_channels;
drivers/iio/light/apds9300.c+0−1
@@ -419,7 +419,6 @@ static int apds9300_probe(struct i2c_client *client, · 418 unmodified lines
419419
420420 mutex_init(&data->mutex);
421421
422− indio_dev->dev.parent = &client->dev;
423422 indio_dev->channels = apds9300_channels;
424423 indio_dev->num_channels = ARRAY_SIZE(apds9300_channels);
425424 indio_dev->name = APDS9300_DRV_NAME;
drivers/iio/light/apds9960.c+0−1
@@ -1001,7 +1001,6 @@ static int apds9960_probe(struct i2c_client *client, · 1000 unmodified lines
10011001
10021002 iio_device_attach_buffer(indio_dev, buffer);
10031003
1004− indio_dev->dev.parent = &client->dev;
10051004 indio_dev->info = &apds9960_info;
10061005 indio_dev->name = APDS9960_DRV_NAME;
10071006 indio_dev->channels = apds9960_channels;
drivers/iio/light/bh1750.c+0−1
@@ -254,7 +254,6 @@ static int bh1750_probe(struct i2c_client *client, · 253 unmodified lines
254254 return ret;
255255
256256 mutex_init(&data->lock);
257− indio_dev->dev.parent = &client->dev;
258257 indio_dev->info = &bh1750_info;
259258 indio_dev->name = id->name;
260259 indio_dev->channels = bh1750_channels;
drivers/iio/light/bh1780.c+0−1
@@ -185,7 +185,6 @@ static int bh1780_probe(struct i2c_client *client, · 184 unmodified lines
185185 pm_runtime_use_autosuspend(&client->dev);
186186 pm_runtime_put(&client->dev);
187187
188− indio_dev->dev.parent = &client->dev;
189188 indio_dev->info = &bh1780_info;
190189 indio_dev->name = "bh1780";
191190 indio_dev->channels = bh1780_channels;
drivers/iio/light/cm32181.c+0−1
@@ -465,7 +465,6 @@ static int cm32181_probe(struct i2c_client *client) · 464 unmodified lines
465465 cm32181->dev = dev;
466466
467467 mutex_init(&cm32181->lock);
468− indio_dev->dev.parent = dev;
469468 indio_dev->channels = cm32181_channels;
470469 indio_dev->num_channels = ARRAY_SIZE(cm32181_channels);
471470 indio_dev->info = &cm32181_info;
drivers/iio/light/cm3232.c+0−1
@@ -340,7 +340,6 @@ static int cm3232_probe(struct i2c_client *client, · 339 unmodified lines
340340 i2c_set_clientdata(client, indio_dev);
341341 chip->client = client;
342342
343− indio_dev->dev.parent = &client->dev;
344343 indio_dev->channels = cm3232_channels;
345344 indio_dev->num_channels = ARRAY_SIZE(cm3232_channels);
346345 indio_dev->info = &cm3232_info;
drivers/iio/light/cm3323.c+0−1
@@ -231,7 +231,6 @@ static int cm3323_probe(struct i2c_client *client, · 230 unmodified lines
231231
232232 mutex_init(&data->mutex);
233233
234− indio_dev->dev.parent = &client->dev;
235234 indio_dev->info = &cm3323_info;
236235 indio_dev->name = CM3323_DRV_NAME;
237236 indio_dev->channels = cm3323_channels;
drivers/iio/light/cm3605.c+0−1
@@ -239,7 +239,6 @@ static int cm3605_probe(struct platform_device *pdev) · 238 unmodified lines
239239 led_trigger_register_simple("cm3605", &cm3605->led);
240240 led_trigger_event(cm3605->led, LED_FULL);
241241
242− indio_dev->dev.parent = dev;
243242 indio_dev->info = &cm3605_info;
244243 indio_dev->name = "cm3605";
245244 indio_dev->channels = cm3605_channels;
drivers/iio/light/cm36651.c+0−1
@@ -662,7 +662,6 @@ static int cm36651_probe(struct i2c_client *client, · 661 unmodified lines
662662 }
663663
664664 mutex_init(&cm36651->lock);
665− indio_dev->dev.parent = &client->dev;
666665 indio_dev->channels = cm36651_channels;
667666 indio_dev->num_channels = ARRAY_SIZE(cm36651_channels);
668667 indio_dev->info = &cm36651_info;
drivers/iio/light/cros_ec_light_prox.c+5−1
@@ -145,8 +145,11 @@ static int cros_ec_light_prox_write(struct iio_dev *indio_dev, · 144 unmodified lines
145145 break;
146146 case IIO_CHAN_INFO_CALIBSCALE:
147147 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
148− st->core.param.sensor_range.data = (val << 16) | (val2 / 100);
148+ st->core.curr_range = (val << 16) | (val2 / 100);
149+ st->core.param.sensor_range.data = st->core.curr_range;
149150 ret = cros_ec_motion_send_host_cmd(&st->core, 0);
151+ if (ret == 0)
152+ st->core.range_updated = true;
150153 break;
151154 default:
152155 ret = cros_ec_sensors_core_write(&st->core, chan, val, val2,
@@ -256,6 +259,7 @@ MODULE_DEVICE_TABLE(platform, cros_ec_light_prox_ids); · 103 unmodified lines
256259 static struct platform_driver cros_ec_light_prox_platform_driver = {
257260 .driver = {
258261 .name = "cros-ec-light-prox",
262+ .pm = &cros_ec_sensors_pm_ops,
259263 },
260264 .probe = cros_ec_light_prox_probe,
261265 .id_table = cros_ec_light_prox_ids,
drivers/iio/light/gp2ap002.c+0−1
@@ -596,7 +596,6 @@ static int gp2ap002_probe(struct i2c_client *client, · 595 unmodified lines
596596 pm_runtime_use_autosuspend(dev);
597597 pm_runtime_put(dev);
598598
599− indio_dev->dev.parent = dev;
600599 indio_dev->info = &gp2ap002_info;
601600 indio_dev->name = "gp2ap002";
602601 indio_dev->channels = gp2ap002_channels;
drivers/iio/light/gp2ap020a00f.c+0−11
@@ -1390,12 +1390,6 @@ static int gp2ap020a00f_buffer_postenable(struct iio_dev *indio_dev) · 1389 unmodified lines
13901390
13911391 mutex_lock(&data->lock);
13921392
1393− err = iio_triggered_buffer_postenable(indio_dev);
1394− if (err < 0) {
1395− mutex_unlock(&data->lock);
1396− return err;
1397− }
1398−
13991393 /*
14001394 * Enable triggers according to the scan_mask. Enabling either
14011395 * LIGHT_CLEAR or LIGHT_IR scan mode results in enabling ALS
@@ -1430,8 +1424,6 @@ static int gp2ap020a00f_buffer_postenable(struct iio_dev *indio_dev) · 28 unmodified lines
14301424 err = -ENOMEM;
14311425
14321426 error_unlock:
1433− if (err < 0)
1434− iio_triggered_buffer_predisable(indio_dev);
14351427 mutex_unlock(&data->lock);
14361428
14371429 return err;
@@ -1465,8 +1457,6 @@ static int gp2ap020a00f_buffer_predisable(struct iio_dev *indio_dev) · 27 unmodified lines
14651457 if (err == 0)
14661458 kfree(data->buffer);
14671459
1468− iio_triggered_buffer_predisable(indio_dev);
1469−
14701460 mutex_unlock(&data->lock);
14711461
14721462 return err;
@@ -1527,7 +1517,6 @@ static int gp2ap020a00f_probe(struct i2c_client *client, · 54 unmodified lines
15271517 init_waitqueue_head(&data->data_ready_queue);
15281518
15291519 mutex_init(&data->lock);
1530− indio_dev->dev.parent = &client->dev;
15311520 indio_dev->channels = gp2ap020a00f_channels;
15321521 indio_dev->num_channels = ARRAY_SIZE(gp2ap020a00f_channels);
15331522 indio_dev->info = &gp2ap020a00f_info;
drivers/iio/light/hid-sensor-als.c+0−1
@@ -301,7 +301,6 @@ static int hid_als_probe(struct platform_device *pdev) · 300 unmodified lines
301301
302302 indio_dev->num_channels =
303303 ARRAY_SIZE(als_channels);
304− indio_dev->dev.parent = &pdev->dev;
305304 indio_dev->info = &als_info;
306305 indio_dev->name = name;
307306 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/light/hid-sensor-prox.c+0−1
@@ -279,7 +279,6 @@ static int hid_prox_probe(struct platform_device *pdev) · 278 unmodified lines
279279 }
280280
281281 indio_dev->num_channels = ARRAY_SIZE(prox_channels);
282− indio_dev->dev.parent = &pdev->dev;
283282 indio_dev->info = &prox_info;
284283 indio_dev->name = name;
285284 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/light/iqs621-als.c+4−3
@@ -36,6 +36,7 @@ · 35 unmodified lines
3636
3737 struct iqs621_als_private {
3838 struct iqs62x_core *iqs62x;
39+ struct iio_dev *indio_dev;
3940 struct notifier_block notifier;
4041 struct mutex lock;
4142 bool light_en;
@@ -103,7 +104,7 @@ static int iqs621_als_notifier(struct notifier_block *notifier, · 61 unmodified lines
103104
104105 iqs621_als = container_of(notifier, struct iqs621_als_private,
105106 notifier);
106− indio_dev = iio_priv_to_dev(iqs621_als);
107+ indio_dev = iqs621_als->indio_dev;
107108 timestamp = iio_get_time_ns(indio_dev);
108109
109110 mutex_lock(&iqs621_als->lock);
@@ -191,7 +192,7 @@ err_mutex: · 81 unmodified lines
191192 static void iqs621_als_notifier_unregister(void *context)
192193 {
193194 struct iqs621_als_private *iqs621_als = context;
194− struct iio_dev *indio_dev = iio_priv_to_dev(iqs621_als);
195+ struct iio_dev *indio_dev = iqs621_als->indio_dev;
195196 int ret;
196197
197198 ret = blocking_notifier_chain_unregister(&iqs621_als->iqs62x->nh,
@@ -551,6 +552,7 @@ static int iqs621_als_probe(struct platform_device *pdev) · 353 unmodified lines
551552
552553 iqs621_als = iio_priv(indio_dev);
553554 iqs621_als->iqs62x = iqs62x;
555+ iqs621_als->indio_dev = indio_dev;
554556
555557 if (iqs62x->dev_desc->prod_num == IQS622_PROD_NUM) {
556558 ret = regmap_read(iqs62x->regmap, IQS622_IR_THRESH_TOUCH,
@@ -580,7 +582,6 @@ static int iqs621_als_probe(struct platform_device *pdev) · 23 unmodified lines
580582 }
581583
582584 indio_dev->modes = INDIO_DIRECT_MODE;
583− indio_dev->dev.parent = &pdev->dev;
584585 indio_dev->name = iqs62x->dev_desc->dev_name;
585586 indio_dev->info = &iqs621_als_info;
586587
drivers/iio/light/isl29018.c+0−1
@@ -782,7 +782,6 @@ static int isl29018_probe(struct i2c_client *client, · 781 unmodified lines
782782 indio_dev->channels = isl29018_chip_info_tbl[dev_id].channels;
783783 indio_dev->num_channels = isl29018_chip_info_tbl[dev_id].num_channels;
784784 indio_dev->name = name;
785− indio_dev->dev.parent = &client->dev;
786785 indio_dev->modes = INDIO_DIRECT_MODE;
787786
788787 return devm_iio_device_register(&client->dev, indio_dev);
drivers/iio/light/isl29028.c+0−1
@@ -620,7 +620,6 @@ static int isl29028_probe(struct i2c_client *client, · 619 unmodified lines
620620 indio_dev->channels = isl29028_channels;
621621 indio_dev->num_channels = ARRAY_SIZE(isl29028_channels);
622622 indio_dev->name = id->name;
623− indio_dev->dev.parent = &client->dev;
624623 indio_dev->modes = INDIO_DIRECT_MODE;
625624
626625 pm_runtime_enable(&client->dev);
drivers/iio/light/isl29125.c+2−19
@@ -216,36 +216,20 @@ static const struct iio_info isl29125_info = { · 215 unmodified lines
216216 static int isl29125_buffer_postenable(struct iio_dev *indio_dev)
217217 {
218218 struct isl29125_data *data = iio_priv(indio_dev);
219− int err;
220−
221− err = iio_triggered_buffer_postenable(indio_dev);
222− if (err)
223− return err;
224219
225220 data->conf1 |= ISL29125_MODE_RGB;
226− err = i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
221+ return i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
227222 data->conf1);
228− if (err) {
229− iio_triggered_buffer_predisable(indio_dev);
230− return err;
231− }
232−
233− return 0;
234223 }
235224
236225 static int isl29125_buffer_predisable(struct iio_dev *indio_dev)
237226 {
238227 struct isl29125_data *data = iio_priv(indio_dev);
239− int ret;
240228
241229 data->conf1 &= ~ISL29125_MODE_MASK;
242230 data->conf1 |= ISL29125_MODE_PD;
243− ret = i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
231+ return i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
244232 data->conf1);
245−
246− iio_triggered_buffer_predisable(indio_dev);
247−
248− return ret;
249233 }
250234
251235 static const struct iio_buffer_setup_ops isl29125_buffer_setup_ops = {
@@ -268,7 +252,6 @@ static int isl29125_probe(struct i2c_client *client, · 16 unmodified lines
268252 i2c_set_clientdata(client, indio_dev);
269253 data->client = client;
270254
271− indio_dev->dev.parent = &client->dev;
272255 indio_dev->info = &isl29125_info;
273256 indio_dev->name = ISL29125_DRV_NAME;
274257 indio_dev->channels = isl29125_channels;
drivers/iio/light/jsa1212.c+0−1
@@ -338,7 +338,6 @@ static int jsa1212_probe(struct i2c_client *client, · 337 unmodified lines
338338 if (ret < 0)
339339 return ret;
340340
341− indio_dev->dev.parent = &client->dev;
342341 indio_dev->channels = jsa1212_channels;
343342 indio_dev->num_channels = ARRAY_SIZE(jsa1212_channels);
344343 indio_dev->name = JSA1212_DRIVER_NAME;
drivers/iio/light/lm3533-als.c+1−1
@@ -852,7 +852,7 @@ static int lm3533_als_probe(struct platform_device *pdev) · 851 unmodified lines
852852 indio_dev->channels = lm3533_als_channels;
853853 indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels);
854854 indio_dev->name = dev_name(&pdev->dev);
855− indio_dev->dev.parent = pdev->dev.parent;
855+ iio_device_set_parent(indio_dev, pdev->dev.parent);
856856 indio_dev->modes = INDIO_DIRECT_MODE;
857857
858858 als = iio_priv(indio_dev);
drivers/iio/light/ltr501.c+0−1
@@ -1480,7 +1480,6 @@ static int ltr501_probe(struct i2c_client *client, · 1479 unmodified lines
14801480 if ((partid >> 4) != data->chip_info->partid)
14811481 return -ENODEV;
14821482
1483− indio_dev->dev.parent = &client->dev;
14841483 indio_dev->info = data->chip_info->info;
14851484 indio_dev->channels = data->chip_info->channels;
14861485 indio_dev->num_channels = data->chip_info->no_channels;
drivers/iio/light/lv0104cs.c+1−2
@@ -7,7 +7,7 @@ · 6 unmodified lines
77 *
88 * 7-bit I2C slave address: 0x13
99 *
10− * Link to data sheet: http://www.onsemi.com/pub/Collateral/LV0104CS-D.PDF
10+ * Link to data sheet: https://www.onsemi.com/pub/Collateral/LV0104CS-D.PDF
1111 */
1212
1313 #include <linux/kernel.h>
@@ -502,7 +502,6 @@ static int lv0104cs_probe(struct i2c_client *client, · 488 unmodified lines
502502 return ret;
503503
504504 indio_dev->modes = INDIO_DIRECT_MODE;
505− indio_dev->dev.parent = &client->dev;
506505 indio_dev->channels = lv0104cs_channels;
507506 indio_dev->num_channels = ARRAY_SIZE(lv0104cs_channels);
508507 indio_dev->name = client->name;
drivers/iio/light/max44000.c+0−1
@@ -538,7 +538,6 @@ static int max44000_probe(struct i2c_client *client, · 537 unmodified lines
538538
539539 i2c_set_clientdata(client, indio_dev);
540540 mutex_init(&data->lock);
541− indio_dev->dev.parent = &client->dev;
542541 indio_dev->info = &max44000_info;
543542 indio_dev->name = MAX44000_DRV_NAME;
544543 indio_dev->channels = max44000_channels;
drivers/iio/light/max44009.c+0−1
@@ -501,7 +501,6 @@ static int max44009_probe(struct i2c_client *client, · 500 unmodified lines
501501 data = iio_priv(indio_dev);
502502 i2c_set_clientdata(client, indio_dev);
503503 data->client = client;
504− indio_dev->dev.parent = &client->dev;
505504 indio_dev->info = &max44009_info;
506505 indio_dev->modes = INDIO_DIRECT_MODE;
507506 indio_dev->name = MAX44009_DRV_NAME;
drivers/iio/light/noa1305.c+0−1
@@ -270,7 +270,6 @@ static int noa1305_probe(struct i2c_client *client, · 269 unmodified lines
270270 return ret;
271271 }
272272
273− indio_dev->dev.parent = &client->dev;
274273 indio_dev->info = &noa1305_info;
275274 indio_dev->channels = noa1305_channels;
276275 indio_dev->num_channels = ARRAY_SIZE(noa1305_channels);
drivers/iio/light/opt3001.c+1−2
@@ -2,7 +2,7 @@ · 1 unmodified line
22 /**
33 * opt3001.c - Texas Instruments OPT3001 Light Sensor
44 *
5− * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
5+ * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com
66 *
77 * Author: Andreas Dannenberg <dannenberg@ti.com>
88 * Based on previous work from: Felipe Balbi <balbi@ti.com>
@@ -768,7 +768,6 @@ static int opt3001_probe(struct i2c_client *client, · 759 unmodified lines
768768 iio->name = client->name;
769769 iio->channels = opt3001_channels;
770770 iio->num_channels = ARRAY_SIZE(opt3001_channels);
771− iio->dev.parent = dev;
772771 iio->modes = INDIO_DIRECT_MODE;
773772 iio->info = &opt3001_info;
774773
drivers/iio/light/pa12203001.c+0−1
@@ -362,7 +362,6 @@ static int pa12203001_probe(struct i2c_client *client, · 361 unmodified lines
362362
363363 mutex_init(&data->lock);
364364
365− indio_dev->dev.parent = &client->dev;
366365 indio_dev->info = &pa12203001_info;
367366 indio_dev->name = PA12203001_DRIVER_NAME;
368367 indio_dev->channels = pa12203001_channels;
drivers/iio/light/rpr0521.c+0−3
@@ -570,8 +570,6 @@ static int rpr0521_buffer_postdisable(struct iio_dev *indio_dev) · 569 unmodified lines
570570
571571 static const struct iio_buffer_setup_ops rpr0521_buffer_setup_ops = {
572572 .preenable = rpr0521_buffer_preenable,
573− .postenable = iio_triggered_buffer_postenable,
574− .predisable = iio_triggered_buffer_predisable,
575573 .postdisable = rpr0521_buffer_postdisable,
576574 };
577575
@@ -948,7 +946,6 @@ static int rpr0521_probe(struct i2c_client *client, · 370 unmodified lines
948946
949947 mutex_init(&data->lock);
950948
951− indio_dev->dev.parent = &client->dev;
952949 indio_dev->info = &rpr0521_info;
953950 indio_dev->name = RPR0521_DRV_NAME;
954951 indio_dev->channels = rpr0521_channels;
drivers/iio/light/si1133.c+0−1
@@ -1015,7 +1015,6 @@ static int si1133_probe(struct i2c_client *client, · 1014 unmodified lines
10151015 i2c_set_clientdata(client, iio_dev);
10161016 data->client = client;
10171017
1018− iio_dev->dev.parent = &client->dev;
10191018 iio_dev->name = id->name;
10201019 iio_dev->channels = si1133_channels;
10211020 iio_dev->num_channels = ARRAY_SIZE(si1133_channels);
drivers/iio/light/si1145.c+0−3
@@ -1171,8 +1171,6 @@ static bool si1145_validate_scan_mask(struct iio_dev *indio_dev, · 1170 unmodified lines
11711171
11721172 static const struct iio_buffer_setup_ops si1145_buffer_setup_ops = {
11731173 .preenable = si1145_buffer_preenable,
1174− .postenable = iio_triggered_buffer_postenable,
1175− .predisable = iio_triggered_buffer_predisable,
11761174 .validate_scan_mask = si1145_validate_scan_mask,
11771175 };
11781176
@@ -1307,7 +1305,6 @@ static int si1145_probe(struct i2c_client *client, · 128 unmodified lines
13071305 return -ENODEV;
13081306 }
13091307
1310− indio_dev->dev.parent = &client->dev;
13111308 indio_dev->name = id->name;
13121309 indio_dev->channels = data->part_info->channels;
13131310 indio_dev->num_channels = data->part_info->num_channels;
drivers/iio/light/st_uvis25_core.c+0−3
@@ -227,8 +227,6 @@ static int st_uvis25_buffer_postdisable(struct iio_dev *iio_dev) · 226 unmodified lines
227227
228228 static const struct iio_buffer_setup_ops st_uvis25_buffer_ops = {
229229 .preenable = st_uvis25_buffer_preenable,
230− .postenable = iio_triggered_buffer_postenable,
231− .predisable = iio_triggered_buffer_predisable,
232230 .postdisable = st_uvis25_buffer_postdisable,
233231 };
234232
@@ -303,7 +301,6 @@ int st_uvis25_probe(struct device *dev, int irq, struct regmap *regmap) · 68 unmodified lines
303301 return err;
304302
305303 iio_dev->modes = INDIO_DIRECT_MODE;
306− iio_dev->dev.parent = dev;
307304 iio_dev->channels = st_uvis25_channels;
308305 iio_dev->num_channels = ARRAY_SIZE(st_uvis25_channels);
309306 iio_dev->name = ST_UVIS25_DEV_NAME;
drivers/iio/light/stk3310.c+1−2
@@ -487,7 +487,7 @@ static bool stk3310_is_volatile_reg(struct device *dev, unsigned int reg) · 486 unmodified lines
487487 }
488488 }
489489
490−static struct regmap_config stk3310_regmap_config = {
490+static const struct regmap_config stk3310_regmap_config = {
491491 .name = STK3310_REGMAP_NAME,
492492 .reg_bits = 8,
493493 .val_bits = 8,
@@ -585,7 +585,6 @@ static int stk3310_probe(struct i2c_client *client, · 91 unmodified lines
585585 if (ret < 0)
586586 return ret;
587587
588− indio_dev->dev.parent = &client->dev;
589588 indio_dev->info = &stk3310_info;
590589 indio_dev->name = STK3310_DRIVER_NAME;
591590 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/light/tcs3414.c+2−19
@@ -243,35 +243,19 @@ static const struct iio_info tcs3414_info = { · 242 unmodified lines
243243 static int tcs3414_buffer_postenable(struct iio_dev *indio_dev)
244244 {
245245 struct tcs3414_data *data = iio_priv(indio_dev);
246− int ret;
247−
248− ret = iio_triggered_buffer_postenable(indio_dev);
249− if (ret)
250− return ret;
251246
252247 data->control |= TCS3414_CONTROL_ADC_EN;
253− ret = i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
248+ return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
254249 data->control);
255− if (ret)
256− iio_triggered_buffer_predisable(indio_dev);
257−
258− return ret;
259250 }
260251
261252 static int tcs3414_buffer_predisable(struct iio_dev *indio_dev)
262253 {
263254 struct tcs3414_data *data = iio_priv(indio_dev);
264− int ret, ret2;
265255
266256 data->control &= ~TCS3414_CONTROL_ADC_EN;
267− ret = i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
257+ return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
268258 data->control);
269−
270− ret2 = iio_triggered_buffer_predisable(indio_dev);
271− if (!ret)
272− ret = ret2;
273−
274− return ret;
275259 }
276260
277261 static const struct iio_buffer_setup_ops tcs3414_buffer_setup_ops = {
@@ -294,7 +278,6 @@ static int tcs3414_probe(struct i2c_client *client, · 16 unmodified lines
294278 i2c_set_clientdata(client, indio_dev);
295279 data->client = client;
296280
297− indio_dev->dev.parent = &client->dev;
298281 indio_dev->info = &tcs3414_info;
299282 indio_dev->name = TCS3414_DRV_NAME;
300283 indio_dev->channels = tcs3414_channels;
drivers/iio/light/tcs3472.c+0−1
@@ -454,7 +454,6 @@ static int tcs3472_probe(struct i2c_client *client, · 453 unmodified lines
454454 data->client = client;
455455 mutex_init(&data->lock);
456456
457− indio_dev->dev.parent = &client->dev;
458457 indio_dev->info = &tcs3472_info;
459458 indio_dev->name = TCS3472_DRV_NAME;
460459 indio_dev->channels = tcs3472_channels;
drivers/iio/light/tsl2563.c+7−6
@@ -713,7 +713,7 @@ static int tsl2563_probe(struct i2c_client *client, · 712 unmodified lines
713713
714714 chip = iio_priv(indio_dev);
715715
716− i2c_set_clientdata(client, chip);
716+ i2c_set_clientdata(client, indio_dev);
717717 chip->client = client;
718718
719719 err = tsl2563_detect(chip);
@@ -750,7 +750,6 @@ static int tsl2563_probe(struct i2c_client *client, · 30 unmodified lines
750750 indio_dev->name = client->name;
751751 indio_dev->channels = tsl2563_channels;
752752 indio_dev->num_channels = ARRAY_SIZE(tsl2563_channels);
753− indio_dev->dev.parent = &client->dev;
754753 indio_dev->modes = INDIO_DIRECT_MODE;
755754
756755 if (client->irq)
@@ -797,8 +796,8 @@ fail: · 40 unmodified lines
797796
798797 static int tsl2563_remove(struct i2c_client *client)
799798 {
800− struct tsl2563_chip *chip = i2c_get_clientdata(client);
801− struct iio_dev *indio_dev = iio_priv_to_dev(chip);
799+ struct iio_dev *indio_dev = i2c_get_clientdata(client);
800+ struct tsl2563_chip *chip = iio_priv(indio_dev);
802801
803802 iio_device_unregister(indio_dev);
804803 if (!chip->int_enabled)
@@ -816,7 +815,8 @@ static int tsl2563_remove(struct i2c_client *client) · 11 unmodified lines
816815 #ifdef CONFIG_PM_SLEEP
817816 static int tsl2563_suspend(struct device *dev)
818817 {
819− struct tsl2563_chip *chip = i2c_get_clientdata(to_i2c_client(dev));
818+ struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
819+ struct tsl2563_chip *chip = iio_priv(indio_dev);
820820 int ret;
821821
822822 mutex_lock(&chip->lock);
@@ -834,7 +834,8 @@ out: · 11 unmodified lines
834834
835835 static int tsl2563_resume(struct device *dev)
836836 {
837− struct tsl2563_chip *chip = i2c_get_clientdata(to_i2c_client(dev));
837+ struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
838+ struct tsl2563_chip *chip = iio_priv(indio_dev);
838839 int ret;
839840
840841 mutex_lock(&chip->lock);
drivers/iio/light/tsl2583.c+0−1
@@ -840,7 +840,6 @@ static int tsl2583_probe(struct i2c_client *clientp, · 839 unmodified lines
840840 indio_dev->info = &tsl2583_info;
841841 indio_dev->channels = tsl2583_channels;
842842 indio_dev->num_channels = ARRAY_SIZE(tsl2583_channels);
843− indio_dev->dev.parent = &clientp->dev;
844843 indio_dev->modes = INDIO_DIRECT_MODE;
845844 indio_dev->name = chip->client->name;
846845
drivers/iio/light/tsl2772.c+0−1
@@ -1833,7 +1833,6 @@ static int tsl2772_probe(struct i2c_client *clientp, · 1832 unmodified lines
18331833 &tsl2772_chip_info_tbl[device_channel_config[id->driver_data]];
18341834
18351835 indio_dev->info = chip->chip_info->info;
1836− indio_dev->dev.parent = &clientp->dev;
18371836 indio_dev->modes = INDIO_DIRECT_MODE;
18381837 indio_dev->name = chip->client->name;
18391838 indio_dev->num_channels = chip->chip_info->chan_table_elements;
drivers/iio/light/tsl4531.c+0−1
@@ -192,7 +192,6 @@ static int tsl4531_probe(struct i2c_client *client, · 191 unmodified lines
192192 if (ret < 0)
193193 return ret;
194194
195− indio_dev->dev.parent = &client->dev;
196195 indio_dev->info = &tsl4531_info;
197196 indio_dev->channels = tsl4531_channels;
198197 indio_dev->num_channels = ARRAY_SIZE(tsl4531_channels);
drivers/iio/light/us5182d.c+0−1
@@ -851,7 +851,6 @@ static int us5182d_probe(struct i2c_client *client, · 850 unmodified lines
851851
852852 mutex_init(&data->lock);
853853
854− indio_dev->dev.parent = &client->dev;
855854 indio_dev->info = &us5182d_info;
856855 indio_dev->name = US5182D_DRV_NAME;
857856 indio_dev->channels = us5182d_channels;
drivers/iio/light/vcnl4000.c+7−29
@@ -957,50 +957,29 @@ static int vcnl4010_buffer_postenable(struct iio_dev *indio_dev) · 956 unmodified lines
957957 int ret;
958958 int cmd;
959959
960− ret = iio_triggered_buffer_postenable(indio_dev);
961− if (ret)
962− return ret;
963−
964960 /* Do not enable the buffer if we are already capturing events. */
965− if (vcnl4010_is_in_periodic_mode(data)) {
966− ret = -EBUSY;
967− goto end;
968− }
961+ if (vcnl4010_is_in_periodic_mode(data))
962+ return -EBUSY;
969963
970964 ret = i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL,
971965 VCNL4010_INT_PROX_EN);
972966 if (ret < 0)
973− goto end;
967+ return ret;
974968
975969 cmd = VCNL4000_SELF_TIMED_EN | VCNL4000_PROX_EN;
976− ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, cmd);
977− if (ret < 0)
978− goto end;
979−
980− return 0;
981−end:
982− iio_triggered_buffer_predisable(indio_dev);
983−
984− return ret;
970+ return i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, cmd);
985971 }
986972
987973 static int vcnl4010_buffer_predisable(struct iio_dev *indio_dev)
988974 {
989975 struct vcnl4000_data *data = iio_priv(indio_dev);
990− int ret, ret_disable;
976+ int ret;
991977
992978 ret = i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL, 0);
993979 if (ret < 0)
994− goto end;
995−
996− ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, 0);
997−
998−end:
999− ret_disable = iio_triggered_buffer_predisable(indio_dev);
1000− if (ret == 0)
1001− ret = ret_disable;
980+ return ret;
1002981
1003− return ret;
982+ return i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, 0);
1004983 }
1005984
1006985 static const struct iio_buffer_setup_ops vcnl4010_buffer_ops = {
@@ -1058,7 +1037,6 @@ static int vcnl4000_probe(struct i2c_client *client, · 51 unmodified lines
10581037 &data->near_level))
10591038 data->near_level = 0;
10601039
1061− indio_dev->dev.parent = &client->dev;
10621040 indio_dev->info = data->chip_spec->info;
10631041 indio_dev->channels = data->chip_spec->channels;
10641042 indio_dev->num_channels = data->chip_spec->num_channels;
drivers/iio/light/vcnl4035.c+0−1
@@ -564,7 +564,6 @@ static int vcnl4035_probe(struct i2c_client *client, · 563 unmodified lines
564564 data->client = client;
565565 data->regmap = regmap;
566566
567− indio_dev->dev.parent = &client->dev;
568567 indio_dev->info = &vcnl4035_info;
569568 indio_dev->name = VCNL4035_DRV_NAME;
570569 indio_dev->channels = vcnl4035_channels;
drivers/iio/light/veml6030.c+0−1
@@ -814,7 +814,6 @@ static int veml6030_probe(struct i2c_client *client, · 813 unmodified lines
814814 data->client = client;
815815 data->regmap = regmap;
816816
817− indio_dev->dev.parent = &client->dev;
818817 indio_dev->name = "veml6030";
819818 indio_dev->channels = veml6030_channels;
820819 indio_dev->num_channels = ARRAY_SIZE(veml6030_channels);
drivers/iio/light/veml6070.c+0−1
@@ -151,7 +151,6 @@ static int veml6070_probe(struct i2c_client *client, · 150 unmodified lines
151151 data->client1 = client;
152152 mutex_init(&data->lock);
153153
154− indio_dev->dev.parent = &client->dev;
155154 indio_dev->info = &veml6070_info;
156155 indio_dev->channels = veml6070_channels;
157156 indio_dev->num_channels = ARRAY_SIZE(veml6070_channels);
drivers/iio/light/vl6180.c+0−1
@@ -509,7 +509,6 @@ static int vl6180_probe(struct i2c_client *client, · 508 unmodified lines
509509 data->client = client;
510510 mutex_init(&data->lock);
511511
512− indio_dev->dev.parent = &client->dev;
513512 indio_dev->info = &vl6180_info;
514513 indio_dev->channels = vl6180_channels;
515514 indio_dev->num_channels = ARRAY_SIZE(vl6180_channels);
drivers/iio/light/zopt2201.c+0−1
@@ -527,7 +527,6 @@ static int zopt2201_probe(struct i2c_client *client, · 526 unmodified lines
527527 data->client = client;
528528 mutex_init(&data->lock);
529529
530− indio_dev->dev.parent = &client->dev;
531530 indio_dev->info = &zopt2201_info;
532531 indio_dev->channels = zopt2201_channels;
533532 indio_dev->num_channels = ARRAY_SIZE(zopt2201_channels);
drivers/iio/magnetometer/ak8974.c+0−1
@@ -892,7 +892,6 @@ static int ak8974_probe(struct i2c_client *i2c, · 891 unmodified lines
892892 pm_runtime_use_autosuspend(&i2c->dev);
893893 pm_runtime_put(&i2c->dev);
894894
895− indio_dev->dev.parent = &i2c->dev;
896895 switch (ak8974->variant) {
897896 case AK8974_WHOAMI_VALUE_AMI306:
898897 case AK8974_WHOAMI_VALUE_AMI305:
drivers/iio/magnetometer/ak8975.c+20−3
@@ -358,6 +358,7 @@ struct ak8975_data { · 357 unmodified lines
358358 u8 asa[3];
359359 long raw_to_gauss[3];
360360 struct gpio_desc *eoc_gpiod;
361+ struct gpio_desc *reset_gpiod;
361362 int eoc_irq;
362363 wait_queue_head_t data_ready_queue;
363364 unsigned long flags;
@@ -384,10 +385,13 @@ static int ak8975_power_on(const struct ak8975_data *data) · 20 unmodified lines
384385 "Failed to enable specified Vid supply\n");
385386 return ret;
386387 }
388+
389+ gpiod_set_value_cansleep(data->reset_gpiod, 0);
390+
387391 /*
388− * According to the datasheet the power supply rise time i 200us
392+ * According to the datasheet the power supply rise time is 200us
389393 * and the minimum wait time before mode setting is 100us, in
390− * total 300 us. Add some margin and say minimum 500us here.
394+ * total 300us. Add some margin and say minimum 500us here.
391395 */
392396 usleep_range(500, 1000);
393397 return 0;
@@ -396,6 +400,8 @@ static int ak8975_power_on(const struct ak8975_data *data) · 2 unmodified lines
396400 /* Disable attached power regulator if any. */
397401 static void ak8975_power_off(const struct ak8975_data *data)
398402 {
403+ gpiod_set_value_cansleep(data->reset_gpiod, 1);
404+
399405 regulator_disable(data->vid);
400406 regulator_disable(data->vdd);
401407 }
@@ -839,6 +845,7 @@ static int ak8975_probe(struct i2c_client *client, · 437 unmodified lines
839845 struct ak8975_data *data;
840846 struct iio_dev *indio_dev;
841847 struct gpio_desc *eoc_gpiod;
848+ struct gpio_desc *reset_gpiod;
842849 const void *match;
843850 unsigned int i;
844851 int err;
@@ -856,6 +863,16 @@ static int ak8975_probe(struct i2c_client *client, · 11 unmodified lines
856863 if (eoc_gpiod)
857864 gpiod_set_consumer_name(eoc_gpiod, "ak_8975");
858865
866+ /*
867+ * According to AK09911 datasheet, if reset GPIO is provided then
868+ * deassert reset on ak8975_power_on() and assert reset on
869+ * ak8975_power_off().
870+ */
871+ reset_gpiod = devm_gpiod_get_optional(&client->dev,
872+ "reset", GPIOD_OUT_HIGH);
873+ if (IS_ERR(reset_gpiod))
874+ return PTR_ERR(reset_gpiod);
875+
859876 /* Register with IIO */
860877 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
861878 if (indio_dev == NULL)
@@ -866,6 +883,7 @@ static int ak8975_probe(struct i2c_client *client, · 4 unmodified lines
866883
867884 data->client = client;
868885 data->eoc_gpiod = eoc_gpiod;
886+ data->reset_gpiod = reset_gpiod;
869887 data->eoc_irq = 0;
870888
871889 err = iio_read_mount_matrix(&client->dev, "mount-matrix", &data->orientation);
@@ -922,7 +940,6 @@ static int ak8975_probe(struct i2c_client *client, · 50 unmodified lines
922940 }
923941
924942 mutex_init(&data->lock);
925− indio_dev->dev.parent = &client->dev;
926943 indio_dev->channels = ak8975_channels;
927944 indio_dev->num_channels = ARRAY_SIZE(ak8975_channels);
928945 indio_dev->info = &ak8975_info;
drivers/iio/magnetometer/bmc150_magn.c+0−3
@@ -836,8 +836,6 @@ static int bmc150_magn_buffer_postdisable(struct iio_dev *indio_dev) · 835 unmodified lines
836836
837837 static const struct iio_buffer_setup_ops bmc150_magn_buffer_setup_ops = {
838838 .preenable = bmc150_magn_buffer_preenable,
839− .postenable = iio_triggered_buffer_postenable,
840− .predisable = iio_triggered_buffer_predisable,
841839 .postdisable = bmc150_magn_buffer_postdisable,
842840 };
843841
@@ -883,7 +881,6 @@ int bmc150_magn_probe(struct device *dev, struct regmap *regmap, · 39 unmodified lines
883881 if (ret < 0)
884882 return ret;
885883
886− indio_dev->dev.parent = dev;
887884 indio_dev->channels = bmc150_magn_channels;
888885 indio_dev->num_channels = ARRAY_SIZE(bmc150_magn_channels);
889886 indio_dev->available_scan_masks = bmc150_magn_scan_masks;
drivers/iio/magnetometer/bmc150_magn_i2c.c+2−1
@@ -58,7 +58,8 @@ MODULE_DEVICE_TABLE(i2c, bmc150_magn_i2c_id); · 57 unmodified lines
5858 static const struct of_device_id bmc150_magn_of_match[] = {
5959 { .compatible = "bosch,bmc150_magn" },
6060 { .compatible = "bosch,bmc156_magn" },
61− { .compatible = "bosch,bmm150_magn" },
61+ { .compatible = "bosch,bmm150_magn" }, /* deprecated compatible */
62+ { .compatible = "bosch,bmm150" },
6263 { }
6364 };
6465 MODULE_DEVICE_TABLE(of, bmc150_magn_of_match);
drivers/iio/magnetometer/hid-sensor-magn-3d.c+0−1
@@ -512,7 +512,6 @@ static int hid_magn_3d_probe(struct platform_device *pdev) · 511 unmodified lines
512512
513513 indio_dev->channels = channels;
514514 indio_dev->num_channels = chan_count;
515− indio_dev->dev.parent = &pdev->dev;
516515 indio_dev->info = &magn_3d_info;
517516 indio_dev->name = name;
518517 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/magnetometer/hmc5843_core.c+0−1
@@ -642,7 +642,6 @@ int hmc5843_common_probe(struct device *dev, struct regmap *regmap, · 641 unmodified lines
642642 if (ret)
643643 return ret;
644644
645− indio_dev->dev.parent = dev;
646645 indio_dev->name = name;
647646 indio_dev->info = &hmc5843_info;
648647 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/magnetometer/mag3110.c+0−1
@@ -519,7 +519,6 @@ static int mag3110_probe(struct i2c_client *client, · 518 unmodified lines
519519 i2c_set_clientdata(client, indio_dev);
520520 indio_dev->info = &mag3110_info;
521521 indio_dev->name = id->name;
522− indio_dev->dev.parent = &client->dev;
523522 indio_dev->modes = INDIO_DIRECT_MODE;
524523 indio_dev->channels = mag3110_channels;
525524 indio_dev->num_channels = ARRAY_SIZE(mag3110_channels);
drivers/iio/magnetometer/mmc35240.c+1−2
@@ -459,7 +459,7 @@ static bool mmc35240_is_volatile_reg(struct device *dev, unsigned int reg) · 458 unmodified lines
459459 }
460460 }
461461
462−static struct reg_default mmc35240_reg_defaults[] = {
462+static const struct reg_default mmc35240_reg_defaults[] = {
463463 { MMC35240_REG_CTRL0, 0x00 },
464464 { MMC35240_REG_CTRL1, 0x00 },
465465 };
@@ -507,7 +507,6 @@ static int mmc35240_probe(struct i2c_client *client, · 41 unmodified lines
507507
508508 mutex_init(&data->mutex);
509509
510− indio_dev->dev.parent = &client->dev;
511510 indio_dev->info = &mmc35240_info;
512511 indio_dev->name = MMC35240_DRV_NAME;
513512 indio_dev->channels = mmc35240_channels;
drivers/iio/magnetometer/rm3100-core.c+0−3
@@ -463,8 +463,6 @@ static int rm3100_buffer_postdisable(struct iio_dev *indio_dev) · 462 unmodified lines
463463
464464 static const struct iio_buffer_setup_ops rm3100_buffer_ops = {
465465 .preenable = rm3100_buffer_preenable,
466− .postenable = iio_triggered_buffer_postenable,
467− .predisable = iio_triggered_buffer_predisable,
468466 .postdisable = rm3100_buffer_postdisable,
469467 };
470468
@@ -549,7 +547,6 @@ int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq) · 78 unmodified lines
549547
550548 mutex_init(&data->lock);
551549
552− indio_dev->dev.parent = dev;
553550 indio_dev->name = "rm3100";
554551 indio_dev->info = &rm3100_info;
555552 indio_dev->channels = rm3100_channels;
drivers/iio/magnetometer/st_magn_buffer.c+2−24
@@ -31,34 +31,12 @@ int st_magn_trig_set_state(struct iio_trigger *trig, bool state) · 30 unmodified lines
3131
3232 static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
3333 {
34− int err;
35−
36− err = iio_triggered_buffer_postenable(indio_dev);
37− if (err < 0)
38− return err;
39−
40− err = st_sensors_set_enable(indio_dev, true);
41− if (err < 0)
42− goto st_magn_buffer_predisable;
43−
44− return 0;
45−
46−st_magn_buffer_predisable:
47− iio_triggered_buffer_predisable(indio_dev);
48− return err;
34+ return st_sensors_set_enable(indio_dev, true);
4935 }
5036
5137 static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
5238 {
53− int err, err2;
54−
55− err = st_sensors_set_enable(indio_dev, false);
56−
57− err2 = iio_triggered_buffer_predisable(indio_dev);
58− if (!err)
59− err = err2;
60−
61− return err;
39+ return st_sensors_set_enable(indio_dev, false);
6240 }
6341
6442 static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = {
drivers/iio/multiplexer/iio-mux.c+0−1
@@ -395,7 +395,6 @@ static int mux_probe(struct platform_device *pdev) · 394 unmodified lines
395395 mux->cached_state = -1;
396396
397397 indio_dev->name = dev_name(dev);
398− indio_dev->dev.parent = dev;
399398 indio_dev->info = &mux_info;
400399 indio_dev->modes = INDIO_DIRECT_MODE;
401400 indio_dev->channels = mux->chan;
drivers/iio/orientation/hid-sensor-incl-3d.c+0−1
@@ -339,7 +339,6 @@ static int hid_incl_3d_probe(struct platform_device *pdev) · 338 unmodified lines
339339 }
340340
341341 indio_dev->num_channels = ARRAY_SIZE(incl_3d_channels);
342− indio_dev->dev.parent = &pdev->dev;
343342 indio_dev->info = &incl_3d_info;
344343 indio_dev->name = name;
345344 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/orientation/hid-sensor-rotation.c+0−1
@@ -281,7 +281,6 @@ static int hid_dev_rot_probe(struct platform_device *pdev) · 280 unmodified lines
281281 }
282282
283283 indio_dev->num_channels = ARRAY_SIZE(dev_rot_channels);
284− indio_dev->dev.parent = &pdev->dev;
285284 indio_dev->info = &dev_rot_info;
286285 indio_dev->name = name;
287286 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/position/iqs624-pos.c+4−3
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323
2424 struct iqs624_pos_private {
2525 struct iqs62x_core *iqs62x;
26+ struct iio_dev *indio_dev;
2627 struct notifier_block notifier;
2728 struct mutex lock;
2829 bool angle_en;
@@ -59,7 +60,7 @@ static int iqs624_pos_notifier(struct notifier_block *notifier, · 30 unmodified lines
5960
6061 iqs624_pos = container_of(notifier, struct iqs624_pos_private,
6162 notifier);
62− indio_dev = iio_priv_to_dev(iqs624_pos);
63+ indio_dev = iqs624_pos->indio_dev;
6364 timestamp = iio_get_time_ns(indio_dev);
6465
6566 iqs62x = iqs624_pos->iqs62x;
@@ -98,7 +99,7 @@ static int iqs624_pos_notifier(struct notifier_block *notifier, · 32 unmodified lines
9899 static void iqs624_pos_notifier_unregister(void *context)
99100 {
100101 struct iqs624_pos_private *iqs624_pos = context;
101− struct iio_dev *indio_dev = iio_priv_to_dev(iqs624_pos);
102+ struct iio_dev *indio_dev = iqs624_pos->indio_dev;
102103 int ret;
103104
104105 ret = blocking_notifier_chain_unregister(&iqs624_pos->iqs62x->nh,
@@ -243,9 +244,9 @@ static int iqs624_pos_probe(struct platform_device *pdev) · 138 unmodified lines
243244
244245 iqs624_pos = iio_priv(indio_dev);
245246 iqs624_pos->iqs62x = iqs62x;
247+ iqs624_pos->indio_dev = indio_dev;
246248
247249 indio_dev->modes = INDIO_DIRECT_MODE;
248− indio_dev->dev.parent = &pdev->dev;
249250 indio_dev->channels = iqs624_pos_channels;
250251 indio_dev->num_channels = ARRAY_SIZE(iqs624_pos_channels);
251252 indio_dev->name = iqs62x->dev_desc->dev_name;
drivers/iio/potentiometer/ad5272.c+1−2
@@ -3,7 +3,7 @@ · 2 unmodified lines
33 * Analog Devices AD5272 digital potentiometer driver
44 * Copyright (C) 2018 Phil Reid <preid@electromag.com.au>
55 *
6− * Datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/AD5272_5274.pdf
6+ * Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/AD5272_5274.pdf
77 *
88 * DEVID #Wipers #Positions Resistor Opts (kOhm) i2c address
99 * ad5272 1 1024 20, 50, 100 01011xx
@@ -184,7 +184,6 @@ static int ad5272_probe(struct i2c_client *client, · 174 unmodified lines
184184 if (ret < 0)
185185 return -ENODEV;
186186
187− indio_dev->dev.parent = dev;
188187 indio_dev->info = &ad5272_info;
189188 indio_dev->channels = &ad5272_channel;
190189 indio_dev->num_channels = 1;
drivers/iio/potentiometer/ds1803.c+0−1
@@ -126,7 +126,6 @@ static int ds1803_probe(struct i2c_client *client, · 125 unmodified lines
126126 data->client = client;
127127 data->cfg = &ds1803_cfg[id->driver_data];
128128
129− indio_dev->dev.parent = dev;
130129 indio_dev->info = &ds1803_info;
131130 indio_dev->channels = ds1803_channels;
132131 indio_dev->num_channels = ARRAY_SIZE(ds1803_channels);
drivers/iio/potentiometer/max5432.c+0−1
@@ -102,7 +102,6 @@ static int max5432_probe(struct i2c_client *client, · 101 unmodified lines
102102 data->client = client;
103103 data->ohm = (unsigned long)of_device_get_match_data(dev);
104104
105− indio_dev->dev.parent = dev;
106105 indio_dev->info = &max5432_info;
107106 indio_dev->channels = max5432_channels;
108107 indio_dev->num_channels = ARRAY_SIZE(max5432_channels);
drivers/iio/potentiometer/max5481.c+1−2
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 * Copyright 2016 Rockwell Collins
55 *
66 * Datasheet:
7− * http://datasheets.maximintegrated.com/en/ds/MAX5481-MAX5484.pdf
7+ * https://datasheets.maximintegrated.com/en/ds/MAX5481-MAX5484.pdf
88 */
99
1010 #include <linux/acpi.h>
@@ -149,7 +149,6 @@ static int max5481_probe(struct spi_device *spi) · 138 unmodified lines
149149 data->cfg = &max5481_cfg[id->driver_data];
150150
151151 indio_dev->name = id->name;
152− indio_dev->dev.parent = &spi->dev;
153152 indio_dev->modes = INDIO_DIRECT_MODE;
154153
155154 /* variant specific configuration */
drivers/iio/potentiometer/max5487.c+0−1
@@ -100,7 +100,6 @@ static int max5487_spi_probe(struct spi_device *spi) · 99 unmodified lines
100100
101101 indio_dev->info = &max5487_info;
102102 indio_dev->name = id->name;
103− indio_dev->dev.parent = &spi->dev;
104103 indio_dev->modes = INDIO_DIRECT_MODE;
105104 indio_dev->channels = max5487_channels;
106105 indio_dev->num_channels = ARRAY_SIZE(max5487_channels);
drivers/iio/potentiometer/mcp4018.c+0−1
@@ -165,7 +165,6 @@ static int mcp4018_probe(struct i2c_client *client) · 164 unmodified lines
165165 if (!data->cfg)
166166 data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)->driver_data];
167167
168− indio_dev->dev.parent = dev;
169168 indio_dev->info = &mcp4018_info;
170169 indio_dev->channels = &mcp4018_channel;
171170 indio_dev->num_channels = 1;
drivers/iio/potentiometer/mcp41010.c+1−2
@@ -5,7 +5,7 @@ · 4 unmodified lines
55 * Copyright (c) 2018 Chris Coffey <cmc@babblebit.net>
66 * Based on: Slawomir Stepien's code from mcp4131.c
77 *
8− * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/11195c.pdf
8+ * Datasheet: https://ww1.microchip.com/downloads/en/devicedoc/11195c.pdf
99 *
1010 * DEVID #Wipers #Positions Resistance (kOhm)
1111 * mcp41010 1 256 10
@@ -152,7 +152,6 @@ static int mcp41010_probe(struct spi_device *spi) · 140 unmodified lines
152152
153153 mutex_init(&data->lock);
154154
155− indio_dev->dev.parent = dev;
156155 indio_dev->info = &mcp41010_info;
157156 indio_dev->channels = mcp41010_channels;
158157 indio_dev->num_channels = data->cfg->wipers;
drivers/iio/potentiometer/mcp4131.c+1−2
@@ -5,7 +5,7 @@ · 4 unmodified lines
55 * Copyright (c) 2016 Slawomir Stepien
66 * Based on: Peter Rosin's code from mcp4531.c
77 *
8− * Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/22060b.pdf
8+ * Datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/22060b.pdf
99 *
1010 * DEVID #Wipers #Positions Resistor Opts (kOhm)
1111 * mcp4131 1 129 5, 10, 50, 100
@@ -260,7 +260,6 @@ static int mcp4131_probe(struct spi_device *spi) · 248 unmodified lines
260260
261261 mutex_init(&data->lock);
262262
263− indio_dev->dev.parent = dev;
264263 indio_dev->info = &mcp4131_info;
265264 indio_dev->channels = mcp4131_channels;
266265 indio_dev->num_channels = data->cfg->wipers;
drivers/iio/potentiometer/mcp4531.c+0−1
@@ -375,7 +375,6 @@ static int mcp4531_probe(struct i2c_client *client) · 374 unmodified lines
375375 if (!data->cfg)
376376 data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)->driver_data];
377377
378− indio_dev->dev.parent = dev;
379378 indio_dev->info = &mcp4531_info;
380379 indio_dev->channels = mcp4531_channels;
381380 indio_dev->num_channels = data->cfg->wipers;
drivers/iio/potentiometer/tpl0102.c+0−1
@@ -140,7 +140,6 @@ static int tpl0102_probe(struct i2c_client *client, · 139 unmodified lines
140140 return PTR_ERR(data->regmap);
141141 }
142142
143− indio_dev->dev.parent = dev;
144143 indio_dev->info = &tpl0102_info;
145144 indio_dev->channels = tpl0102_channels;
146145 indio_dev->num_channels = data->cfg->wipers;
drivers/iio/potentiostat/lmp91000.c+2−12
@@ -278,17 +278,8 @@ static const struct iio_trigger_ops lmp91000_trigger_ops = { · 277 unmodified lines
278278 static int lmp91000_buffer_postenable(struct iio_dev *indio_dev)
279279 {
280280 struct lmp91000_data *data = iio_priv(indio_dev);
281− int err;
282281
283− err = iio_triggered_buffer_postenable(indio_dev);
284− if (err)
285− return err;
286−
287− err = iio_channel_start_all_cb(data->cb_buffer);
288− if (err)
289− iio_triggered_buffer_predisable(indio_dev);
290−
291− return err;
282+ return iio_channel_start_all_cb(data->cb_buffer);
292283 }
293284
294285 static int lmp91000_buffer_predisable(struct iio_dev *indio_dev)
@@ -297,7 +288,7 @@ static int lmp91000_buffer_predisable(struct iio_dev *indio_dev) · 2 unmodified lines
297288
298289 iio_channel_stop_all_cb(data->cb_buffer);
299290
300− return iio_triggered_buffer_predisable(indio_dev);
291+ return 0;
301292 }
302293
303294 static const struct iio_buffer_setup_ops lmp91000_buffer_setup_ops = {
@@ -321,7 +312,6 @@ static int lmp91000_probe(struct i2c_client *client, · 17 unmodified lines
321312 indio_dev->channels = lmp91000_channels;
322313 indio_dev->num_channels = ARRAY_SIZE(lmp91000_channels);
323314 indio_dev->name = LMP91000_DRV_NAME;
324− indio_dev->dev.parent = &client->dev;
325315 indio_dev->modes = INDIO_DIRECT_MODE;
326316 i2c_set_clientdata(client, indio_dev);
327317
drivers/iio/pressure/abp060mg.c+0−1
@@ -194,7 +194,6 @@ static int abp060mg_probe(struct i2c_client *client, · 193 unmodified lines
194194
195195 abp060mg_init_device(indio_dev, cfg_id);
196196
197− indio_dev->dev.parent = &client->dev;
198197 indio_dev->name = dev_name(&client->dev);
199198 indio_dev->modes = INDIO_DIRECT_MODE;
200199 indio_dev->info = &abp060mg_info;
drivers/iio/pressure/bmp280-core.c+0−1
@@ -1004,7 +1004,6 @@ int bmp280_common_probe(struct device *dev, · 1003 unmodified lines
10041004 mutex_init(&data->lock);
10051005 data->dev = dev;
10061006
1007− indio_dev->dev.parent = dev;
10081007 indio_dev->name = name;
10091008 indio_dev->channels = bmp280_channels;
10101009 indio_dev->info = &bmp280_info;
drivers/iio/pressure/cros_ec_baro.c+6−2
@@ -96,8 +96,11 @@ static int cros_ec_baro_write(struct iio_dev *indio_dev, · 95 unmodified lines
9696 /* Always roundup, so caller gets at least what it asks for. */
9797 st->core.param.sensor_range.roundup = 1;
9898
99− if (cros_ec_motion_send_host_cmd(&st->core, 0))
100− ret = -EIO;
99+ ret = cros_ec_motion_send_host_cmd(&st->core, 0);
100+ if (ret == 0) {
101+ st->core.range_updated = true;
102+ st->core.curr_range = val;
103+ }
101104 break;
102105 default:
103106 ret = cros_ec_sensors_core_write(&st->core, chan, val, val2,
@@ -199,6 +202,7 @@ MODULE_DEVICE_TABLE(platform, cros_ec_baro_ids); · 95 unmodified lines
199202 static struct platform_driver cros_ec_baro_platform_driver = {
200203 .driver = {
201204 .name = "cros-ec-baro",
205+ .pm = &cros_ec_sensors_pm_ops,
202206 },
203207 .probe = cros_ec_baro_probe,
204208 .id_table = cros_ec_baro_ids,
drivers/iio/pressure/dlhl60d.c+1−3
@@ -5,7 +5,7 @@ · 4 unmodified lines
55 * Copyright (c) 2019 AVL DiTEST GmbH
66 * Tomislav Denis <tomislav.denis@avl.com>
77 *
8− * Datasheet: http://www.allsensors.com/cad/DS-0355_Rev_B.PDF
8+ * Datasheet: https://www.allsensors.com/cad/DS-0355_Rev_B.PDF
99 */
1010
1111 #include <linux/module.h>
@@ -311,8 +311,6 @@ static int dlh_probe(struct i2c_client *client, · 299 unmodified lines
311311 st->use_interrupt = false;
312312
313313 indio_dev->name = id->name;
314− indio_dev->dev.parent = &client->dev;
315− indio_dev->dev.of_node = client->dev.of_node;
316314 indio_dev->info = &dlh_info;
317315 indio_dev->modes = INDIO_DIRECT_MODE;
318316 indio_dev->channels = dlh_channels;
drivers/iio/pressure/dps310.c+0−1
@@ -732,7 +732,6 @@ static int dps310_probe(struct i2c_client *client, · 731 unmodified lines
732732 data->client = client;
733733 mutex_init(&data->lock);
734734
735− iio->dev.parent = &client->dev;
736735 iio->name = id->name;
737736 iio->channels = dps310_channels;
738737 iio->num_channels = ARRAY_SIZE(dps310_channels);
drivers/iio/pressure/hid-sensor-press.c+0−1
@@ -283,7 +283,6 @@ static int hid_press_probe(struct platform_device *pdev) · 282 unmodified lines
283283
284284 indio_dev->num_channels =
285285 ARRAY_SIZE(press_channels);
286− indio_dev->dev.parent = &pdev->dev;
287286 indio_dev->info = &press_info;
288287 indio_dev->name = name;
289288 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/pressure/hp03.c+0−1
@@ -224,7 +224,6 @@ static int hp03_probe(struct i2c_client *client, · 223 unmodified lines
224224 priv->client = client;
225225 mutex_init(&priv->lock);
226226
227− indio_dev->dev.parent = dev;
228227 indio_dev->name = id->name;
229228 indio_dev->channels = hp03_channels;
230229 indio_dev->num_channels = ARRAY_SIZE(hp03_channels);
drivers/iio/pressure/hp206c.c+0−1
@@ -378,7 +378,6 @@ static int hp206c_probe(struct i2c_client *client, · 377 unmodified lines
378378
379379 indio_dev->info = &hp206c_info;
380380 indio_dev->name = id->name;
381− indio_dev->dev.parent = &client->dev;
382381 indio_dev->modes = INDIO_DIRECT_MODE;
383382 indio_dev->channels = hp206c_channels;
384383 indio_dev->num_channels = ARRAY_SIZE(hp206c_channels);
drivers/iio/pressure/icp10100.c+0−1
@@ -545,7 +545,6 @@ static int icp10100_probe(struct i2c_client *client, · 544 unmodified lines
545545 return -ENOMEM;
546546
547547 i2c_set_clientdata(client, indio_dev);
548− indio_dev->dev.parent = &client->dev;
549548 indio_dev->name = client->name;
550549 indio_dev->modes = INDIO_DIRECT_MODE;
551550 indio_dev->channels = icp10100_channels;
drivers/iio/pressure/mpl115.c+0−1
@@ -160,7 +160,6 @@ int mpl115_probe(struct device *dev, const char *name, · 159 unmodified lines
160160
161161 indio_dev->info = &mpl115_info;
162162 indio_dev->name = name;
163− indio_dev->dev.parent = dev;
164163 indio_dev->modes = INDIO_DIRECT_MODE;
165164 indio_dev->channels = mpl115_channels;
166165 indio_dev->num_channels = ARRAY_SIZE(mpl115_channels);
drivers/iio/pressure/mpl3115.c+0−1
@@ -241,7 +241,6 @@ static int mpl3115_probe(struct i2c_client *client, · 240 unmodified lines
241241 i2c_set_clientdata(client, indio_dev);
242242 indio_dev->info = &mpl3115_info;
243243 indio_dev->name = id->name;
244− indio_dev->dev.parent = &client->dev;
245244 indio_dev->modes = INDIO_DIRECT_MODE;
246245 indio_dev->channels = mpl3115_channels;
247246 indio_dev->num_channels = ARRAY_SIZE(mpl3115_channels);
drivers/iio/pressure/ms5611_core.c+0−1
@@ -435,7 +435,6 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, · 434 unmodified lines
435435 st->pressure_osr =
436436 &ms5611_avail_pressure_osr[ARRAY_SIZE(ms5611_avail_pressure_osr)
437437 - 1];
438− indio_dev->dev.parent = dev;
439438 indio_dev->name = name;
440439 indio_dev->info = &ms5611_info;
441440 indio_dev->channels = ms5611_channels;
drivers/iio/pressure/ms5637.c+0−1
@@ -152,7 +152,6 @@ static int ms5637_probe(struct i2c_client *client, · 151 unmodified lines
152152
153153 indio_dev->info = &ms5637_info;
154154 indio_dev->name = id->name;
155− indio_dev->dev.parent = &client->dev;
156155 indio_dev->modes = INDIO_DIRECT_MODE;
157156 indio_dev->channels = ms5637_channels;
158157 indio_dev->num_channels = ARRAY_SIZE(ms5637_channels);
drivers/iio/pressure/st_pressure_buffer.c+2−24
@@ -31,34 +31,12 @@ int st_press_trig_set_state(struct iio_trigger *trig, bool state) · 30 unmodified lines
3131
3232 static int st_press_buffer_postenable(struct iio_dev *indio_dev)
3333 {
34− int err;
35−
36− err = iio_triggered_buffer_postenable(indio_dev);
37− if (err < 0)
38− return err;
39−
40− err = st_sensors_set_enable(indio_dev, true);
41− if (err < 0)
42− goto st_press_buffer_predisable;
43−
44− return 0;
45−
46−st_press_buffer_predisable:
47− iio_triggered_buffer_predisable(indio_dev);
48− return err;
34+ return st_sensors_set_enable(indio_dev, true);
4935 }
5036
5137 static int st_press_buffer_predisable(struct iio_dev *indio_dev)
5238 {
53− int err, err2;
54−
55− err = st_sensors_set_enable(indio_dev, false);
56−
57− err2 = iio_triggered_buffer_predisable(indio_dev);
58− if (!err)
59− err = err2;
60−
61− return err;
39+ return st_sensors_set_enable(indio_dev, false);
6240 }
6341
6442 static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = {
drivers/iio/pressure/t5403.c+0−1
@@ -236,7 +236,6 @@ static int t5403_probe(struct i2c_client *client, · 235 unmodified lines
236236 i2c_set_clientdata(client, indio_dev);
237237 indio_dev->info = &t5403_info;
238238 indio_dev->name = id->name;
239− indio_dev->dev.parent = &client->dev;
240239 indio_dev->modes = INDIO_DIRECT_MODE;
241240 indio_dev->channels = t5403_channels;
242241 indio_dev->num_channels = ARRAY_SIZE(t5403_channels);
drivers/iio/pressure/zpa2326.c+10−18
@@ -1242,19 +1242,17 @@ static int zpa2326_postenable_buffer(struct iio_dev *indio_dev) · 1241 unmodified lines
12421242 const struct zpa2326_private *priv = iio_priv(indio_dev);
12431243 int err;
12441244
1245− /* Plug our own trigger event handler. */
1246− err = iio_triggered_buffer_postenable(indio_dev);
1247− if (err)
1248− goto err;
1249−
12501245 if (!priv->waken) {
12511246 /*
12521247 * We were already power supplied. Just clear hardware FIFO to
12531248 * get rid of samples acquired during previous rounds (if any).
12541249 */
12551250 err = zpa2326_clear_fifo(indio_dev, 0);
1256− if (err)
1257− goto err_buffer_predisable;
1251+ if (err) {
1252+ zpa2326_err(indio_dev,
1253+ "failed to enable buffering (%d)", err);
1254+ return err;
1255+ }
12581256 }
12591257
12601258 if (!iio_trigger_using_own(indio_dev) && priv->waken) {
@@ -1263,18 +1261,14 @@ static int zpa2326_postenable_buffer(struct iio_dev *indio_dev) · 2 unmodified lines
12631261 * powered up: reconfigure one-shot mode.
12641262 */
12651263 err = zpa2326_config_oneshot(indio_dev, priv->irq);
1266− if (err)
1267− goto err_buffer_predisable;
1264+ if (err) {
1265+ zpa2326_err(indio_dev,
1266+ "failed to enable buffering (%d)", err);
1267+ return err;
1268+ }
12681269 }
12691270
12701271 return 0;
1271−
1272−err_buffer_predisable:
1273− iio_triggered_buffer_predisable(indio_dev);
1274−err:
1275− zpa2326_err(indio_dev, "failed to enable buffering (%d)", err);
1276−
1277− return err;
12781272 }
12791273
12801274 static int zpa2326_postdisable_buffer(struct iio_dev *indio_dev)
@@ -1287,7 +1281,6 @@ static int zpa2326_postdisable_buffer(struct iio_dev *indio_dev) · 6 unmodified lines
12871281 static const struct iio_buffer_setup_ops zpa2326_buffer_setup_ops = {
12881282 .preenable = zpa2326_preenable_buffer,
12891283 .postenable = zpa2326_postenable_buffer,
1290− .predisable = iio_triggered_buffer_predisable,
12911284 .postdisable = zpa2326_postdisable_buffer
12921285 };
12931286
@@ -1601,7 +1594,6 @@ static struct iio_dev *zpa2326_create_managed_iiodev(struct device *device, · 307 unmodified lines
16011594
16021595 /* Setup for userspace synchronous on demand sampling. */
16031596 indio_dev->modes = INDIO_DIRECT_MODE;
1604− indio_dev->dev.parent = device;
16051597 indio_dev->channels = zpa2326_channels;
16061598 indio_dev->num_channels = ARRAY_SIZE(zpa2326_channels);
16071599 indio_dev->name = name;
drivers/iio/proximity/as3935.c+0−1
@@ -399,7 +399,6 @@ static int as3935_probe(struct spi_device *spi) · 398 unmodified lines
399399 return -EINVAL;
400400 }
401401
402− indio_dev->dev.parent = &spi->dev;
403402 indio_dev->name = spi_get_device_id(spi)->name;
404403 indio_dev->channels = as3935_channels;
405404 indio_dev->num_channels = ARRAY_SIZE(as3935_channels);
drivers/iio/proximity/isl29501.c+0−1
@@ -972,7 +972,6 @@ static int isl29501_probe(struct i2c_client *client, · 971 unmodified lines
972972 return ret;
973973
974974 indio_dev->modes = INDIO_DIRECT_MODE;
975− indio_dev->dev.parent = &client->dev;
976975 indio_dev->channels = isl29501_channels;
977976 indio_dev->num_channels = ARRAY_SIZE(isl29501_channels);
978977 indio_dev->name = client->name;
drivers/iio/proximity/mb1232.c+0−1
@@ -200,7 +200,6 @@ static int mb1232_probe(struct i2c_client *client, · 199 unmodified lines
200200
201201 indio_dev->info = &mb1232_info;
202202 indio_dev->name = id->name;
203− indio_dev->dev.parent = dev;
204203 indio_dev->modes = INDIO_DIRECT_MODE;
205204 indio_dev->channels = mb1232_channels;
206205 indio_dev->num_channels = ARRAY_SIZE(mb1232_channels);
drivers/iio/proximity/ping.c+0−1
@@ -309,7 +309,6 @@ static int ping_probe(struct platform_device *pdev) · 308 unmodified lines
309309 platform_set_drvdata(pdev, indio_dev);
310310
311311 indio_dev->name = "ping";
312− indio_dev->dev.parent = &pdev->dev;
313312 indio_dev->info = &ping_iio_info;
314313 indio_dev->modes = INDIO_DIRECT_MODE;
315314 indio_dev->channels = ping_chan_spec;
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c+0−1
@@ -270,7 +270,6 @@ static int lidar_probe(struct i2c_client *client, · 269 unmodified lines
270270 indio_dev->name = LIDAR_DRV_NAME;
271271 indio_dev->channels = lidar_channels;
272272 indio_dev->num_channels = ARRAY_SIZE(lidar_channels);
273− indio_dev->dev.parent = &client->dev;
274273 indio_dev->modes = INDIO_DIRECT_MODE;
275274
276275 i2c_set_clientdata(client, indio_dev);
drivers/iio/proximity/rfd77402.c+0−1
@@ -274,7 +274,6 @@ static int rfd77402_probe(struct i2c_client *client, · 273 unmodified lines
274274 data->client = client;
275275 mutex_init(&data->lock);
276276
277− indio_dev->dev.parent = &client->dev;
278277 indio_dev->info = &rfd77402_info;
279278 indio_dev->channels = rfd77402_channels;
280279 indio_dev->num_channels = ARRAY_SIZE(rfd77402_channels);
drivers/iio/proximity/srf04.c+1−2
@@ -5,7 +5,7 @@ · 4 unmodified lines
55 * Copyright (c) 2017 Andreas Klinger <ak@it-klinger.de>
66 *
77 * For details about the device see:
8− * http://www.robot-electronics.co.uk/htm/srf04tech.htm
8+ * https://www.robot-electronics.co.uk/htm/srf04tech.htm
99 *
1010 * the measurement cycle as timing diagram looks like:
1111 *
@@ -317,7 +317,6 @@ static int srf04_probe(struct platform_device *pdev) · 305 unmodified lines
317317 platform_set_drvdata(pdev, indio_dev);
318318
319319 indio_dev->name = "srf04";
320− indio_dev->dev.parent = &pdev->dev;
321320 indio_dev->info = &srf04_iio_info;
322321 indio_dev->modes = INDIO_DIRECT_MODE;
323322 indio_dev->channels = srf04_chan_spec;
drivers/iio/proximity/srf08.c+3−4
@@ -7,9 +7,9 @@ · 6 unmodified lines
77 * Copyright (c) 2016, 2017 Andreas Klinger <ak@it-klinger.de>
88 *
99 * For details about the device see:
10− * http://www.robot-electronics.co.uk/htm/srf08tech.html
11− * http://www.robot-electronics.co.uk/htm/srf10tech.htm
12− * http://www.robot-electronics.co.uk/htm/srf02tech.htm
10+ * https://www.robot-electronics.co.uk/htm/srf08tech.html
11+ * https://www.robot-electronics.co.uk/htm/srf10tech.htm
12+ * https://www.robot-electronics.co.uk/htm/srf02tech.htm
1313 */
1414
1515 #include <linux/err.h>
@@ -483,7 +483,6 @@ static int srf08_probe(struct i2c_client *client, · 467 unmodified lines
483483 }
484484
485485 indio_dev->name = id->name;
486− indio_dev->dev.parent = &client->dev;
487486 indio_dev->modes = INDIO_DIRECT_MODE;
488487 indio_dev->channels = srf08_channels;
489488 indio_dev->num_channels = ARRAY_SIZE(srf08_channels);
drivers/iio/proximity/sx9310.c+0−3
@@ -736,8 +736,6 @@ static int sx9310_buffer_postdisable(struct iio_dev *indio_dev) · 735 unmodified lines
736736
737737 static const struct iio_buffer_setup_ops sx9310_buffer_setup_ops = {
738738 .preenable = sx9310_buffer_preenable,
739− .postenable = iio_triggered_buffer_postenable,
740− .predisable = iio_triggered_buffer_predisable,
741739 .postdisable = sx9310_buffer_postdisable,
742740 };
743741
@@ -931,7 +929,6 @@ static int sx9310_probe(struct i2c_client *client, · 187 unmodified lines
931929 return ret;
932930
933931 ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(&client->dev));
934− indio_dev->dev.parent = &client->dev;
935932 indio_dev->channels = sx9310_channels;
936933 indio_dev->num_channels = ARRAY_SIZE(sx9310_channels);
937934 indio_dev->info = &sx9310_info;
drivers/iio/proximity/sx9500.c+0−10
@@ -680,10 +680,6 @@ static int sx9500_buffer_postenable(struct iio_dev *indio_dev) · 679 unmodified lines
680680 struct sx9500_data *data = iio_priv(indio_dev);
681681 int ret = 0, i;
682682
683− ret = iio_triggered_buffer_postenable(indio_dev);
684− if (ret)
685− return ret;
686−
687683 mutex_lock(&data->mutex);
688684
689685 for (i = 0; i < SX9500_NUM_CHANNELS; i++)
@@ -700,9 +696,6 @@ static int sx9500_buffer_postenable(struct iio_dev *indio_dev) · 10 unmodified lines
700696
701697 mutex_unlock(&data->mutex);
702698
703− if (ret)
704− iio_triggered_buffer_predisable(indio_dev);
705−
706699 return ret;
707700 }
708701
@@ -727,8 +720,6 @@ static int sx9500_buffer_predisable(struct iio_dev *indio_dev) · 18 unmodified lines
727720
728721 mutex_unlock(&data->mutex);
729722
730− iio_triggered_buffer_predisable(indio_dev);
731−
732723 return ret;
733724 }
734725
@@ -931,7 +922,6 @@ static int sx9500_probe(struct i2c_client *client, · 196 unmodified lines
931922 if (IS_ERR(data->regmap))
932923 return PTR_ERR(data->regmap);
933924
934− indio_dev->dev.parent = &client->dev;
935925 indio_dev->name = SX9500_DRIVER_NAME;
936926 indio_dev->channels = sx9500_channels;
937927 indio_dev->num_channels = ARRAY_SIZE(sx9500_channels);
drivers/iio/proximity/vcnl3020.c+0−1
@@ -226,7 +226,6 @@ static int vcnl3020_probe(struct i2c_client *client) · 225 unmodified lines
226226 if (rc)
227227 return rc;
228228
229− indio_dev->dev.parent = &client->dev;
230229 indio_dev->info = &vcnl3020_info;
231230 indio_dev->channels = vcnl3020_channels;
232231 indio_dev->num_channels = ARRAY_SIZE(vcnl3020_channels);
drivers/iio/proximity/vl53l0x-i2c.c+0−1
@@ -134,7 +134,6 @@ static int vl53l0x_probe(struct i2c_client *client) · 133 unmodified lines
134134 I2C_FUNC_SMBUS_BYTE_DATA))
135135 return -EOPNOTSUPP;
136136
137− indio_dev->dev.parent = &client->dev;
138137 indio_dev->name = "vl53l0x";
139138 indio_dev->info = &vl53l0x_info;
140139 indio_dev->channels = vl53l0x_channels;
drivers/iio/resolver/ad2s1200.c+0−1
@@ -157,7 +157,6 @@ static int ad2s1200_probe(struct spi_device *spi) · 156 unmodified lines
157157 return PTR_ERR(st->rdvel);
158158 }
159159
160− indio_dev->dev.parent = &spi->dev;
161160 indio_dev->info = &ad2s1200_info;
162161 indio_dev->modes = INDIO_DIRECT_MODE;
163162 indio_dev->channels = ad2s1200_channels;
drivers/iio/resolver/ad2s90.c+0−1
@@ -94,7 +94,6 @@ static int ad2s90_probe(struct spi_device *spi) · 93 unmodified lines
9494
9595 mutex_init(&st->lock);
9696 st->sdev = spi;
97− indio_dev->dev.parent = &spi->dev;
9897 indio_dev->info = &ad2s90_info;
9998 indio_dev->modes = INDIO_DIRECT_MODE;
10099 indio_dev->channels = &ad2s90_chan;
drivers/iio/temperature/hid-sensor-temperature.c+0−1
@@ -223,7 +223,6 @@ static int hid_temperature_probe(struct platform_device *pdev) · 222 unmodified lines
223223
224224 indio_dev->channels = temp_chans;
225225 indio_dev->num_channels = ARRAY_SIZE(temperature_channels);
226− indio_dev->dev.parent = &pdev->dev;
227226 indio_dev->info = &temperature_info;
228227 indio_dev->name = name;
229228 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/temperature/iqs620at-temp.c+0−1
@@ -74,7 +74,6 @@ static int iqs620_temp_probe(struct platform_device *pdev) · 73 unmodified lines
7474 iio_device_set_drvdata(indio_dev, iqs62x);
7575
7676 indio_dev->modes = INDIO_DIRECT_MODE;
77− indio_dev->dev.parent = &pdev->dev;
7877 indio_dev->channels = iqs620_temp_channels;
7978 indio_dev->num_channels = ARRAY_SIZE(iqs620_temp_channels);
8079 indio_dev->name = iqs62x->dev_desc->dev_name;
drivers/iio/temperature/ltc2983.c+0−1
@@ -1500,7 +1500,6 @@ static int ltc2983_probe(struct spi_device *spi) · 1499 unmodified lines
15001500 if (ret)
15011501 return ret;
15021502
1503− indio_dev->dev.parent = &spi->dev;
15041503 indio_dev->name = name;
15051504 indio_dev->num_channels = st->iio_channels;
15061505 indio_dev->channels = st->iio_chan;
drivers/iio/temperature/max31856.c+0−2
@@ -417,8 +417,6 @@ static int max31856_probe(struct spi_device *spi) · 416 unmodified lines
417417 spi_set_drvdata(spi, indio_dev);
418418
419419 indio_dev->info = &max31856_info;
420− indio_dev->dev.parent = &spi->dev;
421− indio_dev->dev.of_node = spi->dev.of_node;
422420 indio_dev->name = id->name;
423421 indio_dev->modes = INDIO_DIRECT_MODE;
424422 indio_dev->channels = max31856_channels;
drivers/iio/temperature/maxim_thermocouple.c+0−1
@@ -244,7 +244,6 @@ static int maxim_thermocouple_probe(struct spi_device *spi) · 243 unmodified lines
244244 indio_dev->available_scan_masks = chip->scan_masks;
245245 indio_dev->num_channels = chip->num_channels;
246246 indio_dev->modes = INDIO_DIRECT_MODE;
247− indio_dev->dev.parent = &spi->dev;
248247
249248 data = iio_priv(indio_dev);
250249 data->spi = spi;
drivers/iio/temperature/mlx90614.c+0−1
@@ -525,7 +525,6 @@ static int mlx90614_probe(struct i2c_client *client, · 524 unmodified lines
525525
526526 mlx90614_wakeup(data);
527527
528− indio_dev->dev.parent = &client->dev;
529528 indio_dev->name = id->name;
530529 indio_dev->modes = INDIO_DIRECT_MODE;
531530 indio_dev->info = &mlx90614_info;
drivers/iio/temperature/mlx90632.c+0−1
@@ -645,7 +645,6 @@ static int mlx90632_probe(struct i2c_client *client, · 644 unmodified lines
645645 mlx90632->regmap = regmap;
646646
647647 mutex_init(&mlx90632->lock);
648− indio_dev->dev.parent = &client->dev;
649648 indio_dev->name = id->name;
650649 indio_dev->modes = INDIO_DIRECT_MODE;
651650 indio_dev->info = &mlx90632_info;
drivers/iio/temperature/tmp006.c+0−1
@@ -216,7 +216,6 @@ static int tmp006_probe(struct i2c_client *client, · 215 unmodified lines
216216 i2c_set_clientdata(client, indio_dev);
217217 data->client = client;
218218
219− indio_dev->dev.parent = &client->dev;
220219 indio_dev->name = dev_name(&client->dev);
221220 indio_dev->modes = INDIO_DIRECT_MODE;
222221 indio_dev->info = &tmp006_info;
drivers/iio/temperature/tmp007.c+0−1
@@ -463,7 +463,6 @@ static int tmp007_probe(struct i2c_client *client, · 462 unmodified lines
463463 data->client = client;
464464 mutex_init(&data->lock);
465465
466− indio_dev->dev.parent = &client->dev;
467466 indio_dev->name = "tmp007";
468467 indio_dev->modes = INDIO_DIRECT_MODE;
469468 indio_dev->info = &tmp007_info;
drivers/iio/temperature/tsys01.c+0−1
@@ -160,7 +160,6 @@ static int tsys01_probe(struct iio_dev *indio_dev, struct device *dev) · 159 unmodified lines
160160
161161 indio_dev->info = &tsys01_info;
162162 indio_dev->name = dev->driver->name;
163− indio_dev->dev.parent = dev;
164163 indio_dev->modes = INDIO_DIRECT_MODE;
165164 indio_dev->channels = tsys01_channels;
166165 indio_dev->num_channels = ARRAY_SIZE(tsys01_channels);
drivers/iio/temperature/tsys02d.c+0−1
@@ -149,7 +149,6 @@ static int tsys02d_probe(struct i2c_client *client, · 148 unmodified lines
149149
150150 indio_dev->info = &tsys02d_info;
151151 indio_dev->name = id->name;
152− indio_dev->dev.parent = &client->dev;
153152 indio_dev->modes = INDIO_DIRECT_MODE;
154153 indio_dev->channels = tsys02d_channels;
155154 indio_dev->num_channels = ARRAY_SIZE(tsys02d_channels);
drivers/iio/trigger/stm32-timer-trigger.c+0−2
@@ -723,12 +723,10 @@ static struct stm32_timer_trigger *stm32_setup_counter_device(struct device *dev · 722 unmodified lines
723723 return NULL;
724724
725725 indio_dev->name = dev_name(dev);
726− indio_dev->dev.parent = dev;
727726 indio_dev->info = &stm32_trigger_info;
728727 indio_dev->modes = INDIO_HARDWARE_TRIGGERED;
729728 indio_dev->num_channels = 1;
730729 indio_dev->channels = &stm32_trigger_channel;
731− indio_dev->dev.of_node = dev->of_node;
732730
733731 ret = devm_iio_device_register(dev, indio_dev);
734732 if (ret)
drivers/input/touchscreen/tsc2007_iio.c+0−1
@@ -119,7 +119,6 @@ int tsc2007_iio_configure(struct tsc2007 *ts) · 118 unmodified lines
119119 iio->ts = ts;
120120
121121 indio_dev->name = "tsc2007";
122− indio_dev->dev.parent = &ts->client->dev;
123122 indio_dev->info = &tsc2007_iio_info;
124123 indio_dev->modes = INDIO_DIRECT_MODE;
125124 indio_dev->channels = tsc2007_iio_channel;
drivers/platform/x86/toshiba_acpi.c+1−2
@@ -3114,7 +3114,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) · 3113 unmodified lines
31143114
31153115 toshiba_accelerometer_available(dev);
31163116 if (dev->accelerometer_supported) {
3117− dev->indio_dev = iio_device_alloc(sizeof(*dev));
3117+ dev->indio_dev = iio_device_alloc(&acpi_dev->dev, sizeof(*dev));
31183118 if (!dev->indio_dev) {
31193119 pr_err("Unable to allocate iio device\n");
31203120 goto iio_error;
@@ -3124,7 +3124,6 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) · 3 unmodified lines
31243124
31253125 dev->indio_dev->info = &toshiba_iio_accel_info;
31263126 dev->indio_dev->name = "Toshiba accelerometer";
3127− dev->indio_dev->dev.parent = &acpi_dev->dev;
31283127 dev->indio_dev->modes = INDIO_DIRECT_MODE;
31293128 dev->indio_dev->channels = toshiba_iio_accel_channels;
31303129 dev->indio_dev->num_channels =
drivers/staging/iio/Documentation/device.txt+1−3
@@ -8,7 +8,7 @@ The crucial structure for device drivers in iio is iio_dev. · 7 unmodified lines
88
99 First allocate one using:
1010
11−struct iio_dev *indio_dev = iio_device_alloc(sizeof(struct chip_state));
11+struct iio_dev *indio_dev = iio_device_alloc(parent, sizeof(struct chip_state));
1212 where chip_state is a structure of local state data for this instance of
1313 the chip.
1414
@@ -16,8 +16,6 @@ That data can be accessed using iio_priv(struct iio_dev *). · 1 unmodified line
1616
1717 Then fill in the following:
1818
19−- indio_dev->dev.parent
20− Struct device associated with the underlying hardware.
2119 - indio_dev->name
2220 Name of the device being driven - made available as the name
2321 attribute in sysfs.
drivers/staging/iio/accel/adis16203.c+0−1
@@ -277,7 +277,6 @@ static int adis16203_probe(struct spi_device *spi) · 276 unmodified lines
277277 spi_set_drvdata(spi, indio_dev);
278278
279279 indio_dev->name = spi->dev.driver->name;
280− indio_dev->dev.parent = &spi->dev;
281280 indio_dev->channels = adis16203_channels;
282281 indio_dev->num_channels = ARRAY_SIZE(adis16203_channels);
283282 indio_dev->info = &adis16203_info;
drivers/staging/iio/accel/adis16240.c+0−1
@@ -400,7 +400,6 @@ static int adis16240_probe(struct spi_device *spi) · 399 unmodified lines
400400 spi_set_drvdata(spi, indio_dev);
401401
402402 indio_dev->name = spi->dev.driver->name;
403− indio_dev->dev.parent = &spi->dev;
404403 indio_dev->info = &adis16240_info;
405404 indio_dev->channels = adis16240_channels;
406405 indio_dev->num_channels = ARRAY_SIZE(adis16240_channels);
drivers/staging/iio/adc/ad7280a.c+0−1
@@ -978,7 +978,6 @@ static int ad7280_probe(struct spi_device *spi) · 977 unmodified lines
978978 st->readback_delay_us += 5; /* Add tWAIT */
979979
980980 indio_dev->name = spi_get_device_id(spi)->name;
981− indio_dev->dev.parent = &spi->dev;
982981 indio_dev->modes = INDIO_DIRECT_MODE;
983982
984983 ret = ad7280_channel_init(st);
drivers/staging/iio/adc/ad7816.c+0−1
@@ -394,7 +394,6 @@ static int ad7816_probe(struct spi_device *spi_dev) · 393 unmodified lines
394394 }
395395
396396 indio_dev->name = spi_get_device_id(spi_dev)->name;
397− indio_dev->dev.parent = &spi_dev->dev;
398397 indio_dev->info = &ad7816_info;
399398 indio_dev->modes = INDIO_DIRECT_MODE;
400399
drivers/staging/iio/addac/adt7316.c+0−1
@@ -2171,7 +2171,6 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus, · 2170 unmodified lines
21712171 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
21722172 chip->int_mask |= ADT7516_AIN_INT_MASK;
21732173
2174− indio_dev->dev.parent = dev;
21752174 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
21762175 indio_dev->info = &adt7516_info;
21772176 else
drivers/staging/iio/cdc/ad7150.c+0−2
@@ -590,8 +590,6 @@ static int ad7150_probe(struct i2c_client *client, · 589 unmodified lines
590590 indio_dev->name = id->name;
591591 indio_dev->channels = ad7150_channels;
592592 indio_dev->num_channels = ARRAY_SIZE(ad7150_channels);
593− /* Establish that the iio_dev is a child of the i2c device */
594− indio_dev->dev.parent = &client->dev;
595593
596594 indio_dev->info = &ad7150_info;
597595
drivers/staging/iio/cdc/ad7746.c+0−2
@@ -693,9 +693,7 @@ static int ad7746_probe(struct i2c_client *client, · 692 unmodified lines
693693 chip->client = client;
694694 chip->capdac_set = -1;
695695
696− /* Establish that the iio_dev is a child of the i2c device */
697696 indio_dev->name = id->name;
698− indio_dev->dev.parent = &client->dev;
699697 indio_dev->info = &ad7746_info;
700698 indio_dev->channels = ad7746_channels;
701699 if (id->driver_data == 7746)
drivers/staging/iio/frequency/ad9832.c+0−1
@@ -348,7 +348,6 @@ static int ad9832_probe(struct spi_device *spi) · 347 unmodified lines
348348 st->spi = spi;
349349 mutex_init(&st->lock);
350350
351− indio_dev->dev.parent = &spi->dev;
352351 indio_dev->name = spi_get_device_id(spi)->name;
353352 indio_dev->info = &ad9832_info;
354353 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/staging/iio/frequency/ad9834.c+0−1
@@ -431,7 +431,6 @@ static int ad9834_probe(struct spi_device *spi) · 430 unmodified lines
431431 st->spi = spi;
432432 st->devid = spi_get_device_id(spi)->driver_data;
433433 st->reg = reg;
434− indio_dev->dev.parent = &spi->dev;
435434 indio_dev->name = spi_get_device_id(spi)->name;
436435 switch (st->devid) {
437436 case ID_AD9833:
drivers/staging/iio/impedance-analyzer/ad5933.c+0−1
@@ -759,7 +759,6 @@ static int ad5933_probe(struct i2c_client *client, · 758 unmodified lines
759759 INIT_DELAYED_WORK(&st->work, ad5933_work);
760760 st->poll_time_jiffies = msecs_to_jiffies(AD5933_POLL_TIME_ms);
761761
762− indio_dev->dev.parent = &client->dev;
763762 indio_dev->info = &ad5933_info;
764763 indio_dev->name = id->name;
765764 indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);
drivers/staging/iio/resolver/ad2s1210.c+0−1
@@ -671,7 +671,6 @@ static int ad2s1210_probe(struct spi_device *spi) · 670 unmodified lines
671671 st->resolution = 12;
672672 st->fexcit = AD2S1210_DEF_EXCIT;
673673
674− indio_dev->dev.parent = &spi->dev;
675674 indio_dev->info = &ad2s1210_info;
676675 indio_dev->modes = INDIO_DIRECT_MODE;
677676 indio_dev->channels = ad2s1210_channels;
include/dt-bindings/iio/qcom,spmi-adc7-pm8350.h+67−0
@@ -0,0 +1,67 @@
1+/* SPDX-License-Identifier: GPL-2.0-only */
2+/*
3+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
4+ */
5+
6+#ifndef _DT_BINDINGS_QCOM_SPMI_VADC_PM8350_H
7+#define _DT_BINDINGS_QCOM_SPMI_VADC_PM8350_H
8+
9+#ifndef PM8350_SID
10+#define PM8350_SID 1
11+#endif
12+
13+/* ADC channels for PM8350_ADC for PMIC7 */
14+#define PM8350_ADC7_REF_GND (PM8350_SID << 8 | 0x0)
15+#define PM8350_ADC7_1P25VREF (PM8350_SID << 8 | 0x01)
16+#define PM8350_ADC7_VREF_VADC (PM8350_SID << 8 | 0x02)
17+#define PM8350_ADC7_DIE_TEMP (PM8350_SID << 8 | 0x03)
18+
19+#define PM8350_ADC7_AMUX_THM1 (PM8350_SID << 8 | 0x04)
20+#define PM8350_ADC7_AMUX_THM2 (PM8350_SID << 8 | 0x05)
21+#define PM8350_ADC7_AMUX_THM3 (PM8350_SID << 8 | 0x06)
22+#define PM8350_ADC7_AMUX_THM4 (PM8350_SID << 8 | 0x07)
23+#define PM8350_ADC7_AMUX_THM5 (PM8350_SID << 8 | 0x08)
24+#define PM8350_ADC7_GPIO1 (PM8350_SID << 8 | 0x0a)
25+#define PM8350_ADC7_GPIO2 (PM8350_SID << 8 | 0x0b)
26+#define PM8350_ADC7_GPIO3 (PM8350_SID << 8 | 0x0c)
27+#define PM8350_ADC7_GPIO4 (PM8350_SID << 8 | 0x0d)
28+
29+/* 30k pull-up1 */
30+#define PM8350_ADC7_AMUX_THM1_30K_PU (PM8350_SID << 8 | 0x24)
31+#define PM8350_ADC7_AMUX_THM2_30K_PU (PM8350_SID << 8 | 0x25)
32+#define PM8350_ADC7_AMUX_THM3_30K_PU (PM8350_SID << 8 | 0x26)
33+#define PM8350_ADC7_AMUX_THM4_30K_PU (PM8350_SID << 8 | 0x27)
34+#define PM8350_ADC7_AMUX_THM5_30K_PU (PM8350_SID << 8 | 0x28)
35+#define PM8350_ADC7_GPIO1_30K_PU (PM8350_SID << 8 | 0x2a)
36+#define PM8350_ADC7_GPIO2_30K_PU (PM8350_SID << 8 | 0x2b)
37+#define PM8350_ADC7_GPIO3_30K_PU (PM8350_SID << 8 | 0x2c)
38+#define PM8350_ADC7_GPIO4_30K_PU (PM8350_SID << 8 | 0x2d)
39+
40+/* 100k pull-up2 */
41+#define PM8350_ADC7_AMUX_THM1_100K_PU (PM8350_SID << 8 | 0x44)
42+#define PM8350_ADC7_AMUX_THM2_100K_PU (PM8350_SID << 8 | 0x45)
43+#define PM8350_ADC7_AMUX_THM3_100K_PU (PM8350_SID << 8 | 0x46)
44+#define PM8350_ADC7_AMUX_THM4_100K_PU (PM8350_SID << 8 | 0x47)
45+#define PM8350_ADC7_AMUX_THM5_100K_PU (PM8350_SID << 8 | 0x48)
46+#define PM8350_ADC7_GPIO1_100K_PU (PM8350_SID << 8 | 0x4a)
47+#define PM8350_ADC7_GPIO2_100K_PU (PM8350_SID << 8 | 0x4b)
48+#define PM8350_ADC7_GPIO3_100K_PU (PM8350_SID << 8 | 0x4c)
49+#define PM8350_ADC7_GPIO4_100K_PU (PM8350_SID << 8 | 0x4d)
50+
51+/* 400k pull-up3 */
52+#define PM8350_ADC7_AMUX_THM1_400K_PU (PM8350_SID << 8 | 0x64)
53+#define PM8350_ADC7_AMUX_THM2_400K_PU (PM8350_SID << 8 | 0x65)
54+#define PM8350_ADC7_AMUX_THM3_400K_PU (PM8350_SID << 8 | 0x66)
55+#define PM8350_ADC7_AMUX_THM4_400K_PU (PM8350_SID << 8 | 0x67)
56+#define PM8350_ADC7_AMUX_THM5_400K_PU (PM8350_SID << 8 | 0x68)
57+#define PM8350_ADC7_GPIO1_400K_PU (PM8350_SID << 8 | 0x6a)
58+#define PM8350_ADC7_GPIO2_400K_PU (PM8350_SID << 8 | 0x6b)
59+#define PM8350_ADC7_GPIO3_400K_PU (PM8350_SID << 8 | 0x6c)
60+#define PM8350_ADC7_GPIO4_400K_PU (PM8350_SID << 8 | 0x6d)
61+
62+/* 1/3 Divider */
63+#define PM8350_ADC7_GPIO4_DIV3 (PM8350_SID << 8 | 0x8d)
64+
65+#define PM8350_ADC7_VPH_PWR (PM8350_SID << 8 | 0x8e)
66+
67+#endif /* _DT_BINDINGS_QCOM_SPMI_VADC_PM8350_H */
include/dt-bindings/iio/qcom,spmi-adc7-pm8350b.h+88−0
@@ -0,0 +1,88 @@
1+/* SPDX-License-Identifier: GPL-2.0-only */
2+/*
3+ * Copyright (c) 2020 The Linux Foundation. All rights reserved.
4+ */
5+
6+#ifndef _DT_BINDINGS_QCOM_SPMI_VADC_PM8350B_H
7+#define _DT_BINDINGS_QCOM_SPMI_VADC_PM8350B_H
8+
9+#ifndef PM8350B_SID
10+#define PM8350B_SID 3
11+#endif
12+
13+/* ADC channels for PM8350B_ADC for PMIC7 */
14+#define PM8350B_ADC7_REF_GND (PM8350B_SID << 8 | 0x0)
15+#define PM8350B_ADC7_1P25VREF (PM8350B_SID << 8 | 0x01)
16+#define PM8350B_ADC7_VREF_VADC (PM8350B_SID << 8 | 0x02)
17+#define PM8350B_ADC7_DIE_TEMP (PM8350B_SID << 8 | 0x03)
18+
19+#define PM8350B_ADC7_AMUX_THM1 (PM8350B_SID << 8 | 0x04)
20+#define PM8350B_ADC7_AMUX_THM2 (PM8350B_SID << 8 | 0x05)
21+#define PM8350B_ADC7_AMUX_THM3 (PM8350B_SID << 8 | 0x06)
22+#define PM8350B_ADC7_AMUX_THM4 (PM8350B_SID << 8 | 0x07)
23+#define PM8350B_ADC7_AMUX_THM5 (PM8350B_SID << 8 | 0x08)
24+#define PM8350B_ADC7_AMUX_THM6 (PM8350B_SID << 8 | 0x09)
25+#define PM8350B_ADC7_GPIO1 (PM8350B_SID << 8 | 0x0a)
26+#define PM8350B_ADC7_GPIO2 (PM8350B_SID << 8 | 0x0b)
27+#define PM8350B_ADC7_GPIO3 (PM8350B_SID << 8 | 0x0c)
28+#define PM8350B_ADC7_GPIO4 (PM8350B_SID << 8 | 0x0d)
29+
30+#define PM8350B_ADC7_CHG_TEMP (PM8350B_SID << 8 | 0x10)
31+#define PM8350B_ADC7_USB_IN_V_16 (PM8350B_SID << 8 | 0x11)
32+#define PM8350B_ADC7_VDC_16 (PM8350B_SID << 8 | 0x12)
33+#define PM8350B_ADC7_CC1_ID (PM8350B_SID << 8 | 0x13)
34+#define PM8350B_ADC7_VREF_BAT_THERM (PM8350B_SID << 8 | 0x15)
35+#define PM8350B_ADC7_IIN_FB (PM8350B_SID << 8 | 0x17)
36+
37+/* 30k pull-up1 */
38+#define PM8350B_ADC7_AMUX_THM1_30K_PU (PM8350B_SID << 8 | 0x24)
39+#define PM8350B_ADC7_AMUX_THM2_30K_PU (PM8350B_SID << 8 | 0x25)
40+#define PM8350B_ADC7_AMUX_THM3_30K_PU (PM8350B_SID << 8 | 0x26)
41+#define PM8350B_ADC7_AMUX_THM4_30K_PU (PM8350B_SID << 8 | 0x27)
42+#define PM8350B_ADC7_AMUX_THM5_30K_PU (PM8350B_SID << 8 | 0x28)
43+#define PM8350B_ADC7_AMUX_THM6_30K_PU (PM8350B_SID << 8 | 0x29)
44+#define PM8350B_ADC7_GPIO1_30K_PU (PM8350B_SID << 8 | 0x2a)
45+#define PM8350B_ADC7_GPIO2_30K_PU (PM8350B_SID << 8 | 0x2b)
46+#define PM8350B_ADC7_GPIO3_30K_PU (PM8350B_SID << 8 | 0x2c)
47+#define PM8350B_ADC7_GPIO4_30K_PU (PM8350B_SID << 8 | 0x2d)
48+#define PM8350B_ADC7_CC1_ID_30K_PU (PM8350B_SID << 8 | 0x33)
49+
50+/* 100k pull-up2 */
51+#define PM8350B_ADC7_AMUX_THM1_100K_PU (PM8350B_SID << 8 | 0x44)
52+#define PM8350B_ADC7_AMUX_THM2_100K_PU (PM8350B_SID << 8 | 0x45)
53+#define PM8350B_ADC7_AMUX_THM3_100K_PU (PM8350B_SID << 8 | 0x46)
54+#define PM8350B_ADC7_AMUX_THM4_100K_PU (PM8350B_SID << 8 | 0x47)
55+#define PM8350B_ADC7_AMUX_THM5_100K_PU (PM8350B_SID << 8 | 0x48)
56+#define PM8350B_ADC7_AMUX_THM6_100K_PU (PM8350B_SID << 8 | 0x49)
57+#define PM8350B_ADC7_GPIO1_100K_PU (PM8350B_SID << 8 | 0x4a)
58+#define PM8350B_ADC7_GPIO2_100K_PU (PM8350B_SID << 8 | 0x4b)
59+#define PM8350B_ADC7_GPIO3_100K_PU (PM8350B_SID << 8 | 0x4c)
60+#define PM8350B_ADC7_GPIO4_100K_PU (PM8350B_SID << 8 | 0x4d)
61+#define PM8350B_ADC7_CC1_ID_100K_PU (PM8350B_SID << 8 | 0x53)
62+
63+/* 400k pull-up3 */
64+#define PM8350B_ADC7_AMUX_THM1_400K_PU (PM8350B_SID << 8 | 0x64)
65+#define PM8350B_ADC7_AMUX_THM2_400K_PU (PM8350B_SID << 8 | 0x65)
66+#define PM8350B_ADC7_AMUX_THM3_400K_PU (PM8350B_SID << 8 | 0x66)
67+#define PM8350B_ADC7_AMUX_THM4_400K_PU (PM8350B_SID << 8 | 0x67)
68+#define PM8350B_ADC7_AMUX_THM5_400K_PU (PM8350B_SID << 8 | 0x68)
69+#define PM8350B_ADC7_AMUX_THM6_400K_PU (PM8350B_SID << 8 | 0x69)
70+#define PM8350B_ADC7_GPIO1_400K_PU (PM8350B_SID << 8 | 0x6a)
71+#define PM8350B_ADC7_GPIO2_400K_PU (PM8350B_SID << 8 | 0x6b)
72+#define PM8350B_ADC7_GPIO3_400K_PU (PM8350B_SID << 8 | 0x6c)
73+#define PM8350B_ADC7_GPIO4_400K_PU (PM8350B_SID << 8 | 0x6d)
74+#define PM8350B_ADC7_CC1_ID_400K_PU (PM8350B_SID << 8 | 0x73)
75+
76+/* 1/3 Divider */
77+#define PM8350B_ADC7_GPIO1_DIV3 (PM8350B_SID << 8 | 0x8a)
78+#define PM8350B_ADC7_GPIO2_DIV3 (PM8350B_SID << 8 | 0x8b)
79+#define PM8350B_ADC7_GPIO3_DIV3 (PM8350B_SID << 8 | 0x8c)
80+#define PM8350B_ADC7_GPIO4_DIV3 (PM8350B_SID << 8 | 0x8d)
81+
82+#define PM8350B_ADC7_VPH_PWR (PM8350B_SID << 8 | 0x8e)
83+#define PM8350B_ADC7_VBAT_SNS (PM8350B_SID << 8 | 0x8f)
84+
85+#define PM8350B_ADC7_SBUx (PM8350B_SID << 8 | 0x94)
86+#define PM8350B_ADC7_VBAT_2S_MID (PM8350B_SID << 8 | 0x96)
87+
88+#endif /* _DT_BINDINGS_QCOM_SPMI_VADC_PM8350B_H */
include/dt-bindings/iio/qcom,spmi-adc7-pmk8350.h+46−0
@@ -0,0 +1,46 @@
1+/* SPDX-License-Identifier: GPL-2.0-only */
2+/*
3+ * Copyright (c) 2020 The Linux Foundation. All rights reserved.
4+ */
5+
6+#ifndef _DT_BINDINGS_QCOM_SPMI_VADC_PMK8350_H
7+#define _DT_BINDINGS_QCOM_SPMI_VADC_PMK8350_H
8+
9+#ifndef PMK8350_SID
10+#define PMK8350_SID 0
11+#endif
12+
13+/* ADC channels for PMK8350_ADC for PMIC7 */
14+#define PMK8350_ADC7_REF_GND (PMK8350_SID << 8 | 0x0)
15+#define PMK8350_ADC7_1P25VREF (PMK8350_SID << 8 | 0x01)
16+#define PMK8350_ADC7_VREF_VADC (PMK8350_SID << 8 | 0x02)
17+#define PMK8350_ADC7_DIE_TEMP (PMK8350_SID << 8 | 0x03)
18+
19+#define PMK8350_ADC7_AMUX_THM1 (PMK8350_SID << 8 | 0x04)
20+#define PMK8350_ADC7_AMUX_THM2 (PMK8350_SID << 8 | 0x05)
21+#define PMK8350_ADC7_AMUX_THM3 (PMK8350_SID << 8 | 0x06)
22+#define PMK8350_ADC7_AMUX_THM4 (PMK8350_SID << 8 | 0x07)
23+#define PMK8350_ADC7_AMUX_THM5 (PMK8350_SID << 8 | 0x08)
24+
25+/* 30k pull-up1 */
26+#define PMK8350_ADC7_AMUX_THM1_30K_PU (PMK8350_SID << 8 | 0x24)
27+#define PMK8350_ADC7_AMUX_THM2_30K_PU (PMK8350_SID << 8 | 0x25)
28+#define PMK8350_ADC7_AMUX_THM3_30K_PU (PMK8350_SID << 8 | 0x26)
29+#define PMK8350_ADC7_AMUX_THM4_30K_PU (PMK8350_SID << 8 | 0x27)
30+#define PMK8350_ADC7_AMUX_THM5_30K_PU (PMK8350_SID << 8 | 0x28)
31+
32+/* 100k pull-up2 */
33+#define PMK8350_ADC7_AMUX_THM1_100K_PU (PMK8350_SID << 8 | 0x44)
34+#define PMK8350_ADC7_AMUX_THM2_100K_PU (PMK8350_SID << 8 | 0x45)
35+#define PMK8350_ADC7_AMUX_THM3_100K_PU (PMK8350_SID << 8 | 0x46)
36+#define PMK8350_ADC7_AMUX_THM4_100K_PU (PMK8350_SID << 8 | 0x47)
37+#define PMK8350_ADC7_AMUX_THM5_100K_PU (PMK8350_SID << 8 | 0x48)
38+
39+/* 400k pull-up3 */
40+#define PMK8350_ADC7_AMUX_THM1_400K_PU (PMK8350_SID << 8 | 0x64)
41+#define PMK8350_ADC7_AMUX_THM2_400K_PU (PMK8350_SID << 8 | 0x65)
42+#define PMK8350_ADC7_AMUX_THM3_400K_PU (PMK8350_SID << 8 | 0x66)
43+#define PMK8350_ADC7_AMUX_THM4_400K_PU (PMK8350_SID << 8 | 0x67)
44+#define PMK8350_ADC7_AMUX_THM5_400K_PU (PMK8350_SID << 8 | 0x68)
45+
46+#endif /* _DT_BINDINGS_QCOM_SPMI_VADC_PMK8350_H */
include/dt-bindings/iio/qcom,spmi-adc7-pmr735a.h+28−0
@@ -0,0 +1,28 @@
1+/* SPDX-License-Identifier: GPL-2.0-only */
2+/*
3+ * Copyright (c) 2020 The Linux Foundation. All rights reserved.
4+ */
5+
6+#ifndef _DT_BINDINGS_QCOM_SPMI_VADC_PMR735A_H
7+#define _DT_BINDINGS_QCOM_SPMI_VADC_PMR735A_H
8+
9+#ifndef PMR735A_SID
10+#define PMR735A_SID 4
11+#endif
12+
13+/* ADC channels for PMR735A_ADC for PMIC7 */
14+#define PMR735A_ADC7_REF_GND (PMR735A_SID << 8 | 0x0)
15+#define PMR735A_ADC7_1P25VREF (PMR735A_SID << 8 | 0x01)
16+#define PMR735A_ADC7_VREF_VADC (PMR735A_SID << 8 | 0x02)
17+#define PMR735A_ADC7_DIE_TEMP (PMR735A_SID << 8 | 0x03)
18+
19+#define PMR735A_ADC7_GPIO1 (PMR735A_SID << 8 | 0x0a)
20+#define PMR735A_ADC7_GPIO2 (PMR735A_SID << 8 | 0x0b)
21+#define PMR735A_ADC7_GPIO3 (PMR735A_SID << 8 | 0x0c)
22+
23+/* 100k pull-up2 */
24+#define PMR735A_ADC7_GPIO1_100K_PU (PMR735A_SID << 8 | 0x4a)
25+#define PMR735A_ADC7_GPIO2_100K_PU (PMR735A_SID << 8 | 0x4b)
26+#define PMR735A_ADC7_GPIO3_100K_PU (PMR735A_SID << 8 | 0x4c)
27+
28+#endif /* _DT_BINDINGS_QCOM_SPMI_VADC_PMR735A_H */
include/dt-bindings/iio/qcom,spmi-adc7-pmr735b.h+28−0
@@ -0,0 +1,28 @@
1+/* SPDX-License-Identifier: GPL-2.0-only */
2+/*
3+ * Copyright (c) 2020 The Linux Foundation. All rights reserved.
4+ */
5+
6+#ifndef _DT_BINDINGS_QCOM_SPMI_VADC_PMR735B_H
7+#define _DT_BINDINGS_QCOM_SPMI_VADC_PMR735B_H
8+
9+#ifndef PMR735B_SID
10+#define PMR735B_SID 5
11+#endif
12+
13+/* ADC channels for PMR735B_ADC for PMIC7 */
14+#define PMR735B_ADC7_REF_GND (PMR735B_SID << 8 | 0x0)
15+#define PMR735B_ADC7_1P25VREF (PMR735B_SID << 8 | 0x01)
16+#define PMR735B_ADC7_VREF_VADC (PMR735B_SID << 8 | 0x02)
17+#define PMR735B_ADC7_DIE_TEMP (PMR735B_SID << 8 | 0x03)
18+
19+#define PMR735B_ADC7_GPIO1 (PMR735B_SID << 8 | 0x0a)
20+#define PMR735B_ADC7_GPIO2 (PMR735B_SID << 8 | 0x0b)
21+#define PMR735B_ADC7_GPIO3 (PMR735B_SID << 8 | 0x0c)
22+
23+/* 100k pull-up2 */
24+#define PMR735B_ADC7_GPIO1_100K_PU (PMR735B_SID << 8 | 0x4a)
25+#define PMR735B_ADC7_GPIO2_100K_PU (PMR735B_SID << 8 | 0x4b)
26+#define PMR735B_ADC7_GPIO3_100K_PU (PMR735B_SID << 8 | 0x4c)
27+
28+#endif /* _DT_BINDINGS_QCOM_SPMI_VADC_PMR735B_H */
include/dt-bindings/iio/qcom,spmi-vadc.h+77−1
@@ -1,6 +1,6 @@
11 /* SPDX-License-Identifier: GPL-2.0 */
22 /*
3− * Copyright (c) 2012-2014,2018 The Linux Foundation. All rights reserved.
3+ * Copyright (c) 2012-2014,2018,2020 The Linux Foundation. All rights reserved.
44 */
55
66 #ifndef _DT_BINDINGS_QCOM_SPMI_VADC_H
@@ -221,4 +221,80 @@ · 214 unmodified lines
221221
222222 #define ADC5_MAX_CHANNEL 0xc0
223223
224+/* ADC channels for ADC for PMIC7 */
225+
226+#define ADC7_REF_GND 0x00
227+#define ADC7_1P25VREF 0x01
228+#define ADC7_VREF_VADC 0x02
229+#define ADC7_DIE_TEMP 0x03
230+
231+#define ADC7_AMUX_THM1 0x04
232+#define ADC7_AMUX_THM2 0x05
233+#define ADC7_AMUX_THM3 0x06
234+#define ADC7_AMUX_THM4 0x07
235+#define ADC7_AMUX_THM5 0x08
236+#define ADC7_AMUX_THM6 0x09
237+#define ADC7_GPIO1 0x0a
238+#define ADC7_GPIO2 0x0b
239+#define ADC7_GPIO3 0x0c
240+#define ADC7_GPIO4 0x0d
241+
242+#define ADC7_CHG_TEMP 0x10
243+#define ADC7_USB_IN_V_16 0x11
244+#define ADC7_VDC_16 0x12
245+#define ADC7_CC1_ID 0x13
246+#define ADC7_VREF_BAT_THERM 0x15
247+#define ADC7_IIN_FB 0x17
248+
249+/* 30k pull-up1 */
250+#define ADC7_AMUX_THM1_30K_PU 0x24
251+#define ADC7_AMUX_THM2_30K_PU 0x25
252+#define ADC7_AMUX_THM3_30K_PU 0x26
253+#define ADC7_AMUX_THM4_30K_PU 0x27
254+#define ADC7_AMUX_THM5_30K_PU 0x28
255+#define ADC7_AMUX_THM6_30K_PU 0x29
256+#define ADC7_GPIO1_30K_PU 0x2a
257+#define ADC7_GPIO2_30K_PU 0x2b
258+#define ADC7_GPIO3_30K_PU 0x2c
259+#define ADC7_GPIO4_30K_PU 0x2d
260+#define ADC7_CC1_ID_30K_PU 0x33
261+
262+/* 100k pull-up2 */
263+#define ADC7_AMUX_THM1_100K_PU 0x44
264+#define ADC7_AMUX_THM2_100K_PU 0x45
265+#define ADC7_AMUX_THM3_100K_PU 0x46
266+#define ADC7_AMUX_THM4_100K_PU 0x47
267+#define ADC7_AMUX_THM5_100K_PU 0x48
268+#define ADC7_AMUX_THM6_100K_PU 0x49
269+#define ADC7_GPIO1_100K_PU 0x4a
270+#define ADC7_GPIO2_100K_PU 0x4b
271+#define ADC7_GPIO3_100K_PU 0x4c
272+#define ADC7_GPIO4_100K_PU 0x4d
273+#define ADC7_CC1_ID_100K_PU 0x53
274+
275+/* 400k pull-up3 */
276+#define ADC7_AMUX_THM1_400K_PU 0x64
277+#define ADC7_AMUX_THM2_400K_PU 0x65
278+#define ADC7_AMUX_THM3_400K_PU 0x66
279+#define ADC7_AMUX_THM4_400K_PU 0x67
280+#define ADC7_AMUX_THM5_400K_PU 0x68
281+#define ADC7_AMUX_THM6_400K_PU 0x69
282+#define ADC7_GPIO1_400K_PU 0x6a
283+#define ADC7_GPIO2_400K_PU 0x6b
284+#define ADC7_GPIO3_400K_PU 0x6c
285+#define ADC7_GPIO4_400K_PU 0x6d
286+#define ADC7_CC1_ID_400K_PU 0x73
287+
288+/* 1/3 Divider */
289+#define ADC7_GPIO1_DIV3 0x8a
290+#define ADC7_GPIO2_DIV3 0x8b
291+#define ADC7_GPIO3_DIV3 0x8c
292+#define ADC7_GPIO4_DIV3 0x8d
293+
294+#define ADC7_VPH_PWR 0x8e
295+#define ADC7_VBAT_SNS 0x8f
296+
297+#define ADC7_SBUx 0x94
298+#define ADC7_VBAT_2S_MID 0x96
299+
224300 #endif /* _DT_BINDINGS_QCOM_SPMI_VADC_H */
include/linux/iio/common/cros_ec_sensors_core.h+10−1
@@ -42,6 +42,10 @@ typedef irqreturn_t (*cros_ec_sensors_capture_t)(int irq, void *p); · 41 unmodified lines
4242 * @resp: motion sensor response structure
4343 * @type: type of motion sensor
4444 * @loc: location where the motion sensor is placed
45+ * @range_updated: True if the range of the sensor has been
46+ * updated.
47+ * @curr_range: If updated, the current range value.
48+ * It will be reapplied at every resume.
4549 * @calib: calibration parameters. Note that trigger
4650 * captured data will always provide the calibrated
4751 * data
@@ -65,6 +69,9 @@ struct cros_ec_sensors_core_state { · 17 unmodified lines
6569 enum motionsensor_type type;
6670 enum motionsensor_location loc;
6771
72+ bool range_updated;
73+ int curr_range;
74+
6875 struct calib_data {
6976 s16 offset;
7077 u16 scale;
@@ -114,7 +121,9 @@ int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st, · 43 unmodified lines
114121 struct iio_chan_spec const *chan,
115122 int val, int val2, long mask);
116123
117−/* List of extended channel specification for all sensors */
124+extern const struct dev_pm_ops cros_ec_sensors_pm_ops;
125+
126+/* List of extended channel specification for all sensors. */
118127 extern const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[];
119128 extern const struct attribute *cros_ec_sensor_fifo_attributes[];
120129
include/linux/iio/iio-opaque.h+36−0
@@ -0,0 +1,36 @@
1+/* SPDX-License-Identifier: GPL-2.0 */
2+
3+#ifndef _INDUSTRIAL_IO_OPAQUE_H_
4+#define _INDUSTRIAL_IO_OPAQUE_H_
5+
6+/**
7+ * struct iio_dev_opaque - industrial I/O device opaque information
8+ * @indio_dev: public industrial I/O device information
9+ * @event_interface: event chrdevs associated with interrupt lines
10+ * @buffer_list: list of all buffers currently attached
11+ * @channel_attr_list: keep track of automatically created channel
12+ * attributes
13+ * @chan_attr_group: group for all attrs in base directory
14+ * @debugfs_dentry: device specific debugfs dentry
15+ * @cached_reg_addr: cached register address for debugfs reads
16+ * @read_buf: read buffer to be used for the initial reg read
17+ * @read_buf_len: data length in @read_buf
18+ */
19+struct iio_dev_opaque {
20+ struct iio_dev indio_dev;
21+ struct iio_event_interface *event_interface;
22+ struct list_head buffer_list;
23+ struct list_head channel_attr_list;
24+ struct attribute_group chan_attr_group;
25+#if defined(CONFIG_DEBUG_FS)
26+ struct dentry *debugfs_dentry;
27+ unsigned cached_reg_addr;
28+ char read_buf[20];
29+ unsigned int read_buf_len;
30+#endif
31+};
32+
33+#define to_iio_dev_opaque(indio_dev) \
34+ container_of(indio_dev, struct iio_dev_opaque, indio_dev)
35+
36+#endif
include/linux/iio/iio.h+29−32
@@ -488,9 +488,7 @@ struct iio_buffer_setup_ops { · 487 unmodified lines
488488 * @currentmode: [DRIVER] current operating mode
489489 * @dev: [DRIVER] device structure, should be assigned a parent
490490 * and owner
491− * @event_interface: [INTERN] event chrdevs associated with interrupt lines
492491 * @buffer: [DRIVER] any buffer present
493− * @buffer_list: [INTERN] list of all buffers currently attached
494492 * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux
495493 * @mlock: [INTERN] lock used to prevent simultaneous device state
496494 * changes
@@ -506,9 +504,6 @@ struct iio_buffer_setup_ops { · 9 unmodified lines
506504 * @pollfunc_event: [DRIVER] function run on events trigger being received
507505 * @channels: [DRIVER] channel specification structure table
508506 * @num_channels: [DRIVER] number of channels specified in @channels.
509− * @channel_attr_list: [INTERN] keep track of automatically created channel
510− * attributes
511− * @chan_attr_group: [INTERN] group for all attrs in base directory
512507 * @name: [DRIVER] name of the device.
513508 * @label: [DRIVER] unique name to identify which device this is
514509 * @info: [DRIVER] callbacks and constant info from driver
@@ -520,8 +515,8 @@ struct iio_buffer_setup_ops { · 5 unmodified lines
520515 * @groups: [INTERN] attribute groups
521516 * @groupcounter: [INTERN] index of next attribute group
522517 * @flags: [INTERN] file ops related flags including busy flag.
523− * @debugfs_dentry: [INTERN] device specific debugfs dentry.
524− * @cached_reg_addr: [INTERN] cached register address for debugfs reads.
518+ * @priv: [DRIVER] reference to driver's private information
519+ * **MUST** be accessed **ONLY** via iio_priv() helper
525520 */
526521 struct iio_dev {
527522 int id;
@@ -531,10 +526,7 @@ struct iio_dev { · 3 unmodified lines
531526 int currentmode;
532527 struct device dev;
533528
534− struct iio_event_interface *event_interface;
535−
536529 struct iio_buffer *buffer;
537− struct list_head buffer_list;
538530 int scan_bytes;
539531 struct mutex mlock;
540532
@@ -551,8 +543,6 @@ struct iio_dev { · 10 unmodified lines
551543 struct iio_chan_spec const *channels;
552544 int num_channels;
553545
554− struct list_head channel_attr_list;
555− struct attribute_group chan_attr_group;
556546 const char *name;
557547 const char *label;
558548 const struct iio_info *info;
@@ -565,12 +555,7 @@ struct iio_dev { · 6 unmodified lines
565555 int groupcounter;
566556
567557 unsigned long flags;
568−#if defined(CONFIG_DEBUG_FS)
569− struct dentry *debugfs_dentry;
570− unsigned cached_reg_addr;
571− char read_buf[20];
572− unsigned int read_buf_len;
573−#endif
558+ void *priv;
574559 };
575560
576561 const struct iio_chan_spec
@@ -649,6 +634,26 @@ static inline struct iio_dev *iio_device_get(struct iio_dev *indio_dev) · 72 unmodified lines
649634 return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL;
650635 }
651636
637+/**
638+ * iio_device_set_parent() - assign parent device to the IIO device object
639+ * @indio_dev: IIO device structure
640+ * @parent: reference to parent device object
641+ *
642+ * This utility must be called between IIO device allocation
643+ * (via devm_iio_device_alloc()) & IIO device registration
644+ * (via {devm_}iio_device_register()).
645+ * By default, the device allocation will also assign a parent device to
646+ * the IIO device object. In cases where devm_iio_device_alloc() is used,
647+ * sometimes the parent device must be different than the device used to
648+ * manage the allocation.
649+ * In that case, this helper should be used to change the parent, hence the
650+ * requirement to call this between allocation & registration.
651+ **/
652+static inline void iio_device_set_parent(struct iio_dev *indio_dev,
653+ struct device *parent)
654+{
655+ indio_dev->dev.parent = parent;
656+}
652657
653658 /**
654659 * iio_device_set_drvdata() - Set device driver data
@@ -669,28 +674,23 @@ static inline void iio_device_set_drvdata(struct iio_dev *indio_dev, void *data) · 14 unmodified lines
669674 *
670675 * Returns the data previously set with iio_device_set_drvdata()
671676 */
672−static inline void *iio_device_get_drvdata(struct iio_dev *indio_dev)
677+static inline void *iio_device_get_drvdata(const struct iio_dev *indio_dev)
673678 {
674679 return dev_get_drvdata(&indio_dev->dev);
675680 }
676681
677682 /* Can we make this smaller? */
678683 #define IIO_ALIGN L1_CACHE_BYTES
679−struct iio_dev *iio_device_alloc(int sizeof_priv);
684+struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv);
680685
686+/* The information at the returned address is guaranteed to be cacheline aligned */
681687 static inline void *iio_priv(const struct iio_dev *indio_dev)
682688 {
683− return (char *)indio_dev + ALIGN(sizeof(struct iio_dev), IIO_ALIGN);
684−}
685−
686−static inline struct iio_dev *iio_priv_to_dev(void *priv)
687−{
688− return (struct iio_dev *)((char *)priv -
689− ALIGN(sizeof(struct iio_dev), IIO_ALIGN));
689+ return indio_dev->priv;
690690 }
691691
692692 void iio_device_free(struct iio_dev *indio_dev);
693−struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv);
693+struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv);
694694 struct iio_trigger *devm_iio_trigger_alloc(struct device *dev,
695695 const char *fmt, ...);
696696 /**
@@ -709,10 +709,7 @@ static inline bool iio_buffer_enabled(struct iio_dev *indio_dev) · 12 unmodified lines
709709 * @indio_dev: IIO device structure for device
710710 **/
711711 #if defined(CONFIG_DEBUG_FS)
712−static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
713−{
714− return indio_dev->debugfs_dentry;
715−}
712+struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev);
716713 #else
717714 static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
718715 {
include/linux/iio/trigger_consumer.h+0−7
@@ -50,11 +50,4 @@ irqreturn_t iio_pollfunc_store_time(int irq, void *p); · 49 unmodified lines
5050
5151 void iio_trigger_notify_done(struct iio_trigger *trig);
5252
53−/*
54− * Two functions for common case where all that happens is a pollfunc
55− * is attached and detached from a trigger
56− */
57−int iio_triggered_buffer_postenable(struct iio_dev *indio_dev);
58−int iio_triggered_buffer_predisable(struct iio_dev *indio_dev);
59−
6053 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t