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
1569KernelVersion: 4.31569KernelVersion: 4.3
1570Contact: linux-iio@vger.kernel.org1570Contact: linux-iio@vger.kernel.org
1571Description:1571Description:
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.
1573 1574
1574What: /sys/bus/iio/devices/iio:deviceX/in_resistance_raw1575What: /sys/bus/iio/devices/iio:deviceX/in_resistance_raw
1575What: /sys/bus/iio/devices/iio:deviceX/in_resistanceX_raw1576What: /sys/bus/iio/devices/iio:deviceX/in_resistanceX_raw
Documentation/ABI/testing/sysfs-bus-iio-icm42600+20−0
@@ -0,0 +1,20 @@
1What: /sys/bus/iio/devices/iio:deviceX/in_accel_x_calibbias
2What: /sys/bus/iio/devices/iio:deviceX/in_accel_y_calibbias
3What: /sys/bus/iio/devices/iio:deviceX/in_accel_z_calibbias
4What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_x_calibbias
5What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_y_calibbias
6What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_z_calibbias
7KernelVersion: 5.8
8Contact: linux-iio@vger.kernel.org
9Description:
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
14What: /sys/bus/iio/devices/iio:deviceX/in_accel_calibbias_available
15What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_calibbias_available
16KernelVersion: 5.8
17Contact: linux-iio@vger.kernel.org
18Description:
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 @@
1What: /sys/bus/iio/devices/iio:deviceX/calibration_auto_enable
2Date: June 2020
3KernelVersion: 5.8
4Contact: linux-iio@vger.kernel.org
5Description:
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
17What: /sys/bus/iio/devices/iio:deviceX/calibration_forced_value
18Date: June 2020
19KernelVersion: 5.8
20Contact: linux-iio@vger.kernel.org
21Description:
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
12description: |12description: |
13 Analog Devices ADXL345/ADXL375 3-Axis Digital Accelerometers that supports13 Analog Devices ADXL345/ADXL375 3-Axis Digital Accelerometers that supports
14 both I2C & SPI interfaces.14 both I2C & SPI interfaces.
15 http://www.analog.com/en/products/mems/accelerometers/adxl345.html15 https://www.analog.com/en/products/mems/accelerometers/adxl345.html
16 http://www.analog.com/en/products/sensors-mems/accelerometers/adxl375.html16 https://www.analog.com/en/products/sensors-mems/accelerometers/adxl375.html
17 17
18properties:18properties:
19 compatible:19 compatible:
Documentation/devicetree/bindings/iio/adc/ingenic,adc.txt+0−49
@@ -1,49 +0,0 @@
1* Ingenic JZ47xx ADC controller IIO bindings
2
3Required 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
15ADC clients must use the format described in iio-bindings.txt, giving
16a phandle and IIO specifier pair ("io-channels") to the ADC controller.
17
18Example:
19
20#include <dt-bindings/iio/adc/ingenic,adc.h>
21
22adc: 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
35adc-keys {
36 ...
37 compatible = "adc-keys";
38 io-channels = <&adc INGENIC_ADC_AUX>;
39 io-channel-names = "buttons";
40 ...
41};
42
43battery {
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
8title: Ingenic JZ47xx ADC controller IIO bindings
9
10maintainers:
11 - Artur Rojek <contact@artur-rojek.eu>
12
13description: >
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
20properties:
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
45required:
46 - compatible
47 - '#io-channel-cells'
48 - reg
49 - clocks
50 - clock-names
51 - interrupts
52
53additionalProperties: false
54
55examples:
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 @@
1Qualcomm'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
8VADC 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
45Channel 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
134NOTE:
135
136For compatible property "qcom,spmi-vadc" following channels, also known as
137reference point channels, are used for result calibration and their channel
138configuration nodes should be defined:
139VADC_REF_625MV and/or VADC_SPARE1(based on PMIC version) VADC_REF_1250MV,
140VADC_GND_REF and VADC_VDD_VADC.
141
142Example:
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
7title: Qualcomm's SPMI PMIC ADC
8
9maintainers:
10 - Andy Gross <agross@kernel.org>
11 - Bjorn Andersson <bjorn.andersson@linaro.org>
12
13description: |
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
19properties:
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
51required:
52 - compatible
53 - reg
54 - '#address-cells'
55 - '#size-cells'
56 - '#io-channel-cells'
57
58patternProperties:
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
144allOf:
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
237examples:
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
7title: Sensirion SCD30 carbon dioxide sensor
8
9maintainers:
10 - Tomasz Duszynski <tomasz.duszynski@octakon.com>
11
12description: |
13 Air quality sensor capable of measuring co2 concentration, temperature
14 and relative humidity.
15
16properties:
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
37required:
38 - compatible
39
40additionalProperties: false
41
42examples:
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
6 6
7The internal DACs are loaded when the LOADDACS pin is pulled down.7The internal DACs are loaded when the LOADDACS pin is pulled down.
8 8
9http://www.ti.com/lit/ds/sbas106/sbas106.pdf9https://www.ti.com/lit/ds/sbas106/sbas106.pdf
10 10
11Required Properties:11Required Properties:
12- compatible: Should be one of:12- 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
9output on a device. The length of an IIO specifier is defined by the9output on a device. The length of an IIO specifier is defined by the
10value of a #io-channel-cells property in the IIO provider node.10value of a #io-channel-cells property in the IIO provider node.
11 11
12[1] http://marc.info/?l=linux-iio&m=135902119507483&w=212[1] https://marc.info/?l=linux-iio&m=135902119507483&w=2
13 13
14==IIO providers==14==IIO providers==
15 15
Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml+14−0
@@ -37,6 +37,15 @@ properties: · 36 unmodified lines
37 set if the specified interrupt pin should be configured as37 set if the specified interrupt pin should be configured as
38 open drain. If not set, defaults to push-pull.38 open drain. If not set, defaults to push-pull.
39 39
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
40required:49required:
41 - compatible50 - compatible
42 - reg51 - reg
@@ -52,9 +61,14 @@ examples: · 9 unmodified lines
52 bmi160@68 {61 bmi160@68 {
53 compatible = "bosch,bmi160";62 compatible = "bosch,bmi160";
54 reg = <0x68>;63 reg = <0x68>;
64 vdd-supply = <&pm8916_l17>;
65 vddio-supply = <&pm8916_l6>;
55 interrupt-parent = <&gpio4>;66 interrupt-parent = <&gpio4>;
56 interrupts = <12 IRQ_TYPE_EDGE_RISING>;67 interrupts = <12 IRQ_TYPE_EDGE_RISING>;
57 interrupt-names = "INT1";68 interrupt-names = "INT1";
69 mount-matrix = "0", "1", "0",
70 "-1", "0", "0",
71 "0", "0", "1";
58 };72 };
59 };73 };
60 - |74 - |
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
7title: InvenSense ICM-426xx Inertial Measurement Unit
8
9maintainers:
10 - Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
11
12description: |
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
27properties:
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
50required:
51 - compatible
52 - reg
53 - interrupts
54
55examples:
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 @@
1* Avago APDS9300 ambient light sensor1* Avago APDS9300 ambient light sensor
2 2
3http://www.avagotech.com/docs/AV02-1077EN3https://www.avagotech.com/docs/AV02-1077EN
4 4
5Required properties:5Required properties:
6 6
Documentation/devicetree/bindings/iio/light/apds9960.txt+1−1
@@ -1,6 +1,6 @@
1* Avago APDS9960 gesture/RGB/ALS/proximity sensor1* Avago APDS9960 gesture/RGB/ALS/proximity sensor
2 2
3http://www.avagotech.com/docs/AV02-4191EN3https://www.avagotech.com/docs/AV02-4191EN
4 4
5Required properties:5Required properties:
6 6
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
6requires the use of interrupts. Without interrupts, only the simple reading6requires the use of interrupts. Without interrupts, only the simple reading
7of the current light value is supported through the IIO API.7of the current light value is supported through the IIO API.
8 8
9http://www.ti.com/product/opt30019https://www.ti.com/product/opt3001
10 10
11Required properties:11Required properties:
12 - compatible: should be "ti,opt3001"12 - compatible: should be "ti,opt3001"
Documentation/devicetree/bindings/iio/light/vl6180.txt+1−1
@@ -1,6 +1,6 @@
1STMicro VL6180 - ALS, range and proximity sensor1STMicro VL6180 - ALS, range and proximity sensor
2 2
3Link to datasheet: http://www.st.com/resource/en/datasheet/vl6180x.pdf3Link to datasheet: https://www.st.com/resource/en/datasheet/vl6180x.pdf
4 4
5Required properties:5Required properties:
6 6
Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt+0−30
@@ -1,30 +0,0 @@
1* AsahiKASEI AK8975 magnetometer sensor
2
3Required properties:
4
5 - compatible : should be "asahi-kasei,ak8975"
6 - reg : the I2C address of the magnetometer
7
8Optional 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
14Example:
15
16ak8975@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
7title: AsahiKASEI AK8975 magnetometer sensor
8
9maintainers:
10 - Jonathan Albrieux <jonathan.albrieux@gmail.com>
11
12properties:
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
54required:
55 - compatible
56 - reg
57
58examples:
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
4 4
5Required properties:5Required properties:
6 6
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)
8 - reg : the I2C address of the magnetometer12 - reg : the I2C address of the magnetometer
9 13
10Optional properties:14Optional properties:
Documentation/devicetree/bindings/iio/potentiometer/mcp41010.txt+1−1
@@ -1,7 +1,7 @@
1* Microchip MCP41010/41050/41100/42010/42050/42100 Digital Potentiometer1* Microchip MCP41010/41050/41100/42010/42050/42100 Digital Potentiometer
2 2
3Datasheet publicly available at:3Datasheet publicly available at:
4http://ww1.microchip.com/downloads/en/devicedoc/11195c.pdf4https://ww1.microchip.com/downloads/en/devicedoc/11195c.pdf
5 5
6The node for this driver must be a child node of a SPI controller, hence6The node for this driver must be a child node of a SPI controller, hence
7all mandatory properties described in7all mandatory properties described in
Documentation/devicetree/bindings/iio/potentiostat/lmp91000.txt+2−2
@@ -1,7 +1,7 @@
1* Texas Instruments LMP91000 series of potentiostats1* Texas Instruments LMP91000 series of potentiostats
2 2
3LMP91000: http://www.ti.com/lit/ds/symlink/lmp91000.pdf3LMP91000: https://www.ti.com/lit/ds/symlink/lmp91000.pdf
4LMP91002: http://www.ti.com/lit/ds/symlink/lmp91002.pdf4LMP91002: https://www.ti.com/lit/ds/symlink/lmp91002.pdf
5 5
6Required properties:6Required properties:
7 7
Documentation/devicetree/bindings/iio/pressure/asc,dlhl60d.yaml+1−1
@@ -13,7 +13,7 @@ description: | · 12 unmodified lines
13 Bindings for the All Sensors DLH series pressure sensors.13 Bindings for the All Sensors DLH series pressure sensors.
14 14
15 Specifications about the sensors can be found at:15 Specifications about the sensors can be found at:
16 http://www.allsensors.com/cad/DS-0355_Rev_B.PDF16 https://www.allsensors.com/cad/DS-0355_Rev_B.PDF
17 17
18properties:18properties:
19 compatible:19 compatible:
Documentation/devicetree/bindings/iio/proximity/devantech-srf04.yaml+2−2
@@ -17,9 +17,9 @@ description: | · 16 unmodified lines
17 until it is received once again17 until it is received once again
18 18
19 Specifications about the devices can be found at:19 Specifications about the devices can be found at:
20 http://www.robot-electronics.co.uk/htm/srf04tech.htm20 https://www.robot-electronics.co.uk/htm/srf04tech.htm
21 21
22 http://www.maxbotix.com/documents/LV-MaxSonar-EZ_Datasheet.pdf22 https://www.maxbotix.com/documents/LV-MaxSonar-EZ_Datasheet.pdf
23 23
24properties:24properties:
25 compatible:25 compatible:
Documentation/driver-api/generic-counter.rst+1−1
@@ -262,7 +262,7 @@ the system. · 261 unmodified lines
262Counter Counts may be allocated via counter_count structures, and262Counter Counts may be allocated via counter_count structures, and
263respective Counter Signal associations (Synapses) made via263respective Counter Signal associations (Synapses) made via
264counter_synapse structures. Associated counter_synapse structures are264counter_synapse structures. Associated counter_synapse structures are
265stored as an array and set to the the synapses array member of the265stored as an array and set to the synapses array member of the
266respective counter_count structure. These counter_count structures are266respective counter_count structure. These counter_count structures are
267set to the counts array member of an allocated counter_device structure267set to the counts array member of an allocated counter_device structure
268before the Counter is registered to the system.268before 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
88The driver implementing the accelerometer described above will have the88The driver implementing the accelerometer described above will have the
89following channel definition::89following channel definition::
90 90
91 struct struct iio_chan_spec accel_channels[] = {91 struct iio_chan_spec accel_channels[] = {
92 {92 {
93 .type = IIO_ACCEL,93 .type = IIO_ACCEL,
94 .modified = 1,94 .modified = 1,
MAINTAINERS+17−1
@@ -8979,6 +8979,14 @@ F: include/dt-bindings/interconnect/ · 8978 unmodified lines
8979F: include/linux/interconnect-provider.h8979F: include/linux/interconnect-provider.h
8980F: include/linux/interconnect.h8980F: include/linux/interconnect.h
8981 8981
8982INVENSENSE ICM-426xx IMU DRIVER
8983M: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
8984L: linux-iio@vger.kernel.org
8985S: Maintained
8986W https://invensense.tdk.com/
8987F: Documentation/devicetree/bindings/iio/imu/invensense,icm42600.yaml
8988F: drivers/iio/imu/inv_icm42600/
8989
8982INVENSENSE MPU-3050 GYROSCOPE DRIVER8990INVENSENSE MPU-3050 GYROSCOPE DRIVER
8983M: Linus Walleij <linus.walleij@linaro.org>8991M: Linus Walleij <linus.walleij@linaro.org>
8984L: linux-iio@vger.kernel.org8992L: linux-iio@vger.kernel.org
@@ -11324,7 +11332,6 @@ F: Documentation/devicetree/bindings/pwm/atmel-pwm.txt · 2339 unmodified lines
11324F: drivers/pwm/pwm-atmel.c11332F: drivers/pwm/pwm-atmel.c
11325 11333
11326MICROCHIP SAMA5D2-COMPATIBLE ADC DRIVER11334MICROCHIP SAMA5D2-COMPATIBLE ADC DRIVER
11327M: Ludovic Desroches <ludovic.desroches@microchip.com>
11328M: Eugen Hristev <eugen.hristev@microchip.com>11335M: Eugen Hristev <eugen.hristev@microchip.com>
11329L: linux-iio@vger.kernel.org11336L: linux-iio@vger.kernel.org
11330S: Supported11337S: Supported
@@ -15373,6 +15380,15 @@ S: Maintained · 4042 unmodified lines
15373F: drivers/misc/phantom.c15380F: drivers/misc/phantom.c
15374F: include/uapi/linux/phantom.h15381F: include/uapi/linux/phantom.h
15375 15382
15383SENSIRION SCD30 CARBON DIOXIDE SENSOR DRIVER
15384M: Tomasz Duszynski <tomasz.duszynski@octakon.com>
15385S: Maintained
15386F: Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml
15387F: drivers/iio/chemical/scd30.h
15388F: drivers/iio/chemical/scd30_core.c
15389F: drivers/iio/chemical/scd30_i2c.c
15390F: drivers/iio/chemical/scd30_serial.c
15391
15376SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER15392SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER
15377M: Tomasz Duszynski <tduszyns@gmail.com>15393M: Tomasz Duszynski <tduszyns@gmail.com>
15378S: Maintained15394S: 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
1538 indio_dev->num_channels = ARRAY_SIZE(quad8_channels);1538 indio_dev->num_channels = ARRAY_SIZE(quad8_channels);
1539 indio_dev->channels = quad8_channels;1539 indio_dev->channels = quad8_channels;
1540 indio_dev->name = dev_name(dev);1540 indio_dev->name = dev_name(dev);
1541 indio_dev->dev.parent = dev;
1542 1541
1543 /* Initialize Counter device and driver data */1542 /* Initialize Counter device and driver data */
1544 quad8iio = iio_priv(indio_dev);1543 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
648 648
649 /* Initialize IIO device */649 /* Initialize IIO device */
650 indio_dev->name = dev_name(&pdev->dev);650 indio_dev->name = dev_name(&pdev->dev);
651 indio_dev->dev.parent = &pdev->dev;
652 indio_dev->dev.of_node = pdev->dev.of_node;651 indio_dev->dev.of_node = pdev->dev.of_node;
653 indio_dev->info = &stm32_lptim_cnt_iio_info;652 indio_dev->info = &stm32_lptim_cnt_iio_info;
654 if (ddata->has_encoder)653 if (ddata->has_encoder)
drivers/iio/accel/Kconfig+7−1
@@ -116,18 +116,24 @@ config BMA400 · 115 unmodified lines
116 tristate "Bosch BMA400 3-Axis Accelerometer Driver"116 tristate "Bosch BMA400 3-Axis Accelerometer Driver"
117 select REGMAP117 select REGMAP
118 select BMA400_I2C if I2C118 select BMA400_I2C if I2C
119 select BMA400_SPI if SPI
119 help120 help
120 Say Y here if you want to build a driver for the Bosch BMA400121 Say Y here if you want to build a driver for the Bosch BMA400
121 triaxial acceleration sensor.122 triaxial acceleration sensor.
122 123
123 To compile this driver as a module, choose M here: the124 To compile this driver as a module, choose M here: the
124 module will be called bma400_core and you will also get125 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.
126 128
127config BMA400_I2C129config BMA400_I2C
128 tristate130 tristate
129 depends on BMA400131 depends on BMA400
130 132
133config BMA400_SPI
134 tristate
135 depends on BMA400
136
131config BMC150_ACCEL137config BMC150_ACCEL
132 tristate "Bosch BMC150 Accelerometer Driver"138 tristate "Bosch BMC150 Accelerometer Driver"
133 select IIO_BUFFER139 select IIO_BUFFER
drivers/iio/accel/Makefile+1−0
@@ -16,6 +16,7 @@ obj-$(CONFIG_BMA180) += bma180.o · 15 unmodified lines
16obj-$(CONFIG_BMA220) += bma220_spi.o16obj-$(CONFIG_BMA220) += bma220_spi.o
17obj-$(CONFIG_BMA400) += bma400_core.o17obj-$(CONFIG_BMA400) += bma400_core.o
18obj-$(CONFIG_BMA400_I2C) += bma400_i2c.o18obj-$(CONFIG_BMA400_I2C) += bma400_i2c.o
19obj-$(CONFIG_BMA400_SPI) += bma400_spi.o
19obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o20obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o
20obj-$(CONFIG_BMC150_ACCEL_I2C) += bmc150-accel-i2c.o21obj-$(CONFIG_BMC150_ACCEL_I2C) += bmc150-accel-i2c.o
21obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o22obj-$(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
271 spi_set_drvdata(spi, indio_dev);271 spi_set_drvdata(spi, indio_dev);
272 272
273 indio_dev->name = spi->dev.driver->name;273 indio_dev->name = spi->dev.driver->name;
274 indio_dev->dev.parent = &spi->dev;
275 indio_dev->info = &adis16201_info;274 indio_dev->info = &adis16201_info;
276 275
277 indio_dev->channels = adis16201_channels;276 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
282 spi_set_drvdata(spi, indio_dev);282 spi_set_drvdata(spi, indio_dev);
283 283
284 indio_dev->name = spi->dev.driver->name;284 indio_dev->name = spi->dev.driver->name;
285 indio_dev->dev.parent = &spi->dev;
286 indio_dev->info = &adis16209_info;285 indio_dev->info = &adis16209_info;
287 indio_dev->channels = adis16209_channels;286 indio_dev->channels = adis16209_channels;
288 indio_dev->num_channels = ARRAY_SIZE(adis16209_channels);287 indio_dev->num_channels = ARRAY_SIZE(adis16209_channels);
drivers/iio/accel/adxl345_core.c+1−2
@@ -4,7 +4,7 @@ · 3 unmodified lines
4 *4 *
5 * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com>5 * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com>
6 *6 *
7 * Datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf7 * Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf
8 */8 */
9 9
10#include <linux/module.h>10#include <linux/module.h>
@@ -246,7 +246,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, · 235 unmodified lines
246 return ret;246 return ret;
247 }247 }
248 248
249 indio_dev->dev.parent = dev;
250 indio_dev->name = name;249 indio_dev->name = name;
251 indio_dev->info = &adxl345_info;250 indio_dev->info = &adxl345_info;
252 indio_dev->modes = INDIO_DIRECT_MODE;251 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
795 unsigned int mask;795 unsigned int mask;
796 int i, ret;796 int i, ret;
797 797
798 ret = iio_triggered_buffer_postenable(indio_dev);
799 if (ret < 0)
800 return ret;
801
802 ret = adxl372_set_interrupts(st, ADXL372_INT1_MAP_FIFO_FULL_MSK, 0);798 ret = adxl372_set_interrupts(st, ADXL372_INT1_MAP_FIFO_FULL_MSK, 0);
803 if (ret < 0)799 if (ret < 0)
804 goto err;800 return ret;
805 801
806 mask = *indio_dev->active_scan_mask;802 mask = *indio_dev->active_scan_mask;
807 803
@@ -810,10 +806,8 @@ static int adxl372_buffer_postenable(struct iio_dev *indio_dev) · 2 unmodified lines
810 break;806 break;
811 }807 }
812 808
813 if (i == ARRAY_SIZE(adxl372_axis_lookup_table)) {809 if (i == ARRAY_SIZE(adxl372_axis_lookup_table))
814 ret = -EINVAL;810 return -EINVAL;
815 goto err;
816 }
817 811
818 st->fifo_format = adxl372_axis_lookup_table[i].fifo_format;812 st->fifo_format = adxl372_axis_lookup_table[i].fifo_format;
819 st->fifo_set_size = bitmap_weight(indio_dev->active_scan_mask,813 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
833 if (ret < 0) {827 if (ret < 0) {
834 st->fifo_mode = ADXL372_FIFO_BYPASSED;828 st->fifo_mode = ADXL372_FIFO_BYPASSED;
835 adxl372_set_interrupts(st, 0, 0);829 adxl372_set_interrupts(st, 0, 0);
836 goto err;830 return ret;
837 }831 }
838 832
839 return 0;833 return 0;
840
841err:
842 iio_triggered_buffer_predisable(indio_dev);
843 return ret;
844}834}
845 835
846static int adxl372_buffer_predisable(struct iio_dev *indio_dev)836static 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
851 st->fifo_mode = ADXL372_FIFO_BYPASSED;841 st->fifo_mode = ADXL372_FIFO_BYPASSED;
852 adxl372_configure_fifo(st);842 adxl372_configure_fifo(st);
853 843
854 return iio_triggered_buffer_predisable(indio_dev);844 return 0;
855}845}
856 846
857static const struct iio_buffer_setup_ops adxl372_buffer_ops = {847static 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
938 indio_dev->channels = adxl372_channels;928 indio_dev->channels = adxl372_channels;
939 indio_dev->num_channels = ARRAY_SIZE(adxl372_channels);929 indio_dev->num_channels = ARRAY_SIZE(adxl372_channels);
940 indio_dev->available_scan_masks = adxl372_channel_masks;930 indio_dev->available_scan_masks = adxl372_channel_masks;
941 indio_dev->dev.parent = dev;
942 indio_dev->name = name;931 indio_dev->name = name;
943 indio_dev->info = &adxl372_info;932 indio_dev->info = &adxl372_info;
944 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;933 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
1038 goto err_chip_disable;1038 goto err_chip_disable;
1039 1039
1040 mutex_init(&data->mutex);1040 mutex_init(&data->mutex);
1041 indio_dev->dev.parent = dev;
1042 indio_dev->channels = data->part_info->channels;1041 indio_dev->channels = data->part_info->channels;
1043 indio_dev->num_channels = data->part_info->num_channels;1042 indio_dev->num_channels = data->part_info->num_channels;
1044 indio_dev->name = id->name;1043 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
237 spi_set_drvdata(spi, indio_dev);237 spi_set_drvdata(spi, indio_dev);
238 mutex_init(&data->lock);238 mutex_init(&data->lock);
239 239
240 indio_dev->dev.parent = &spi->dev;
241 indio_dev->info = &bma220_info;240 indio_dev->info = &bma220_info;
242 indio_dev->name = BMA220_DEVICE_NAME;241 indio_dev->name = BMA220_DEVICE_NAME;
243 indio_dev->modes = INDIO_DIRECT_MODE;242 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
816 return ret;816 return ret;
817 817
818 mutex_init(&data->mutex);818 mutex_init(&data->mutex);
819 indio_dev->dev.parent = dev;
820 indio_dev->name = name;819 indio_dev->name = name;
821 indio_dev->info = &bma400_info;820 indio_dev->info = &bma400_info;
822 indio_dev->channels = bma400_channels;821 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
20static 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
47static 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
56static 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
63static 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
90static int bma400_spi_remove(struct spi_device *spi)
91{
92 return bma400_remove(&spi->dev);
93}
94
95static const struct spi_device_id bma400_spi_ids[] = {
96 { "bma400", 0 },
97 { }
98};
99MODULE_DEVICE_TABLE(spi, bma400_spi_ids);
100
101static const struct of_device_id bma400_of_spi_match[] = {
102 { .compatible = "bosch,bma400" },
103 { }
104};
105MODULE_DEVICE_TABLE(of, bma400_of_spi_match);
106
107static 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
117module_spi_driver(bma400_spi_driver);
118MODULE_AUTHOR("Dan Robertson <dan@dlrobertson.com>");
119MODULE_DESCRIPTION("Bosch BMA400 triaxial acceleration sensor (SPI)");
120MODULE_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
1411 int ret = 0;1411 int ret = 0;
1412 1412
1413 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)1413 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1414 return iio_triggered_buffer_postenable(indio_dev);1414 return 0;
1415 1415
1416 mutex_lock(&data->mutex);1416 mutex_lock(&data->mutex);
1417 1417
@@ -1443,7 +1443,7 @@ static int bmc150_accel_buffer_predisable(struct iio_dev *indio_dev) · 25 unmodified lines
1443 struct bmc150_accel_data *data = iio_priv(indio_dev);1443 struct bmc150_accel_data *data = iio_priv(indio_dev);
1444 1444
1445 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)1445 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1446 return iio_triggered_buffer_predisable(indio_dev);1446 return 0;
1447 1447
1448 mutex_lock(&data->mutex);1448 mutex_lock(&data->mutex);
1449 1449
@@ -1574,7 +1574,6 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, · 124 unmodified lines
1574 1574
1575 mutex_init(&data->mutex);1575 mutex_init(&data->mutex);
1576 1576
1577 indio_dev->dev.parent = dev;
1578 indio_dev->channels = data->chip_info->channels;1577 indio_dev->channels = data->chip_info->channels;
1579 indio_dev->num_channels = data->chip_info->num_channels;1578 indio_dev->num_channels = data->chip_info->num_channels;
1580 indio_dev->name = name ? name : data->chip_info->name;1579 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
33 */33 */
34#define ACCEL_LEGACY_NSCALE 958616834#define ACCEL_LEGACY_NSCALE 9586168
35 35
36/*
37 * Sensor frequency is hard-coded to 10Hz.
38 */
39static const int cros_ec_legacy_sample_freq[] = { 10, 0 };
40
36static int cros_ec_accel_legacy_read_cmd(struct iio_dev *indio_dev,41static int cros_ec_accel_legacy_read_cmd(struct iio_dev *indio_dev,
37 unsigned long scan_mask, s16 *data)42 unsigned long scan_mask, s16 *data)
38{43{
@@ -96,6 +101,11 @@ static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev, · 57 unmodified lines
96 *val = 0;101 *val = 0;
97 ret = IIO_VAL_INT;102 ret = IIO_VAL_INT;
98 break;103 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;
99 default:109 default:
100 ret = cros_ec_sensors_core_read(st, chan, val, val2,110 ret = cros_ec_sensors_core_read(st, chan, val, val2,
101 mask);111 mask);
@@ -120,9 +130,39 @@ static int cros_ec_accel_legacy_write(struct iio_dev *indio_dev, · 18 unmodified lines
120 return -EINVAL;130 return -EINVAL;
121}131}
122 132
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 */
144static 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
123static const struct iio_info cros_ec_accel_legacy_info = {162static const struct iio_info cros_ec_accel_legacy_info = {
124 .read_raw = &cros_ec_accel_legacy_read,163 .read_raw = &cros_ec_accel_legacy_read,
125 .write_raw = &cros_ec_accel_legacy_write,164 .write_raw = &cros_ec_accel_legacy_write,
165 .read_avail = &cros_ec_accel_legacy_read_avail,
126};166};
127 167
128/*168/*
@@ -142,7 +182,11 @@ static const struct iio_info cros_ec_accel_legacy_info = { · 13 unmodified lines
142 .info_mask_separate = \182 .info_mask_separate = \
143 BIT(IIO_CHAN_INFO_RAW) | \183 BIT(IIO_CHAN_INFO_RAW) | \
144 BIT(IIO_CHAN_INFO_CALIBBIAS), \184 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), \
146 .ext_info = cros_ec_sensors_ext_info, \190 .ext_info = cros_ec_sensors_ext_info, \
147 .scan_type = { \191 .scan_type = { \
148 .sign = 's', \192 .sign = 's', \
drivers/iio/accel/da280.c+0−1
@@ -120,7 +120,6 @@ static int da280_probe(struct i2c_client *client, · 119 unmodified lines
120 data->client = client;120 data->client = client;
121 i2c_set_clientdata(client, indio_dev);121 i2c_set_clientdata(client, indio_dev);
122 122
123 indio_dev->dev.parent = &client->dev;
124 indio_dev->info = &da280_info;123 indio_dev->info = &da280_info;
125 indio_dev->modes = INDIO_DIRECT_MODE;124 indio_dev->modes = INDIO_DIRECT_MODE;
126 indio_dev->channels = da280_channels;125 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
231 data->client = client;231 data->client = client;
232 i2c_set_clientdata(client, indio_dev);232 i2c_set_clientdata(client, indio_dev);
233 233
234 indio_dev->dev.parent = &client->dev;
235 indio_dev->info = &da311_info;234 indio_dev->info = &da311_info;
236 indio_dev->name = "da311";235 indio_dev->name = "da311";
237 indio_dev->modes = INDIO_DIRECT_MODE;236 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
161 dmard06->chip_id = ret;161 dmard06->chip_id = ret;
162 162
163 i2c_set_clientdata(client, indio_dev);163 i2c_set_clientdata(client, indio_dev);
164 indio_dev->dev.parent = &client->dev;
165 indio_dev->name = DMARD06_DRV_NAME;164 indio_dev->name = DMARD06_DRV_NAME;
166 indio_dev->modes = INDIO_DIRECT_MODE;165 indio_dev->modes = INDIO_DIRECT_MODE;
167 indio_dev->channels = dmard06_channels;166 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
116 }116 }
117 117
118 i2c_set_clientdata(client, indio_dev);118 i2c_set_clientdata(client, indio_dev);
119 indio_dev->dev.parent = &client->dev;
120 indio_dev->name = DMARD09_DRV_NAME;119 indio_dev->name = DMARD09_DRV_NAME;
121 indio_dev->modes = INDIO_DIRECT_MODE;120 indio_dev->modes = INDIO_DIRECT_MODE;
122 indio_dev->channels = dmard09_channels;121 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
196 data->client = client;196 data->client = client;
197 i2c_set_clientdata(client, indio_dev);197 i2c_set_clientdata(client, indio_dev);
198 198
199 indio_dev->dev.parent = &client->dev;
200 indio_dev->info = &dmard10_info;199 indio_dev->info = &dmard10_info;
201 indio_dev->name = "dmard10";200 indio_dev->name = "dmard10";
202 indio_dev->modes = INDIO_DIRECT_MODE;201 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
384 goto error_free_dev_mem;384 goto error_free_dev_mem;
385 }385 }
386 386
387 indio_dev->dev.parent = &pdev->dev;
388 indio_dev->info = &accel_3d_info;387 indio_dev->info = &accel_3d_info;
389 indio_dev->name = name;388 indio_dev->name = name;
390 indio_dev->modes = INDIO_DIRECT_MODE;389 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
1027 1027
1028static const struct iio_buffer_setup_ops kxcjk1013_buffer_setup_ops = {1028static const struct iio_buffer_setup_ops kxcjk1013_buffer_setup_ops = {
1029 .preenable = kxcjk1013_buffer_preenable,1029 .preenable = kxcjk1013_buffer_preenable,
1030 .postenable = iio_triggered_buffer_postenable,
1031 .postdisable = kxcjk1013_buffer_postdisable,1030 .postdisable = kxcjk1013_buffer_postdisable,
1032 .predisable = iio_triggered_buffer_predisable,
1033};1031};
1034 1032
1035static const struct iio_info kxcjk1013_info = {1033static const struct iio_info kxcjk1013_info = {
@@ -1311,7 +1309,6 @@ static int kxcjk1013_probe(struct i2c_client *client, · 275 unmodified lines
1311 1309
1312 mutex_init(&data->mutex);1310 mutex_init(&data->mutex);
1313 1311
1314 indio_dev->dev.parent = &client->dev;
1315 indio_dev->channels = kxcjk1013_channels;1312 indio_dev->channels = kxcjk1013_channels;
1316 indio_dev->num_channels = ARRAY_SIZE(kxcjk1013_channels);1313 indio_dev->num_channels = ARRAY_SIZE(kxcjk1013_channels);
1317 indio_dev->available_scan_masks = kxcjk1013_scan_masks;1314 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
252 252
253static const struct iio_buffer_setup_ops kxsd9_buffer_setup_ops = {253static const struct iio_buffer_setup_ops kxsd9_buffer_setup_ops = {
254 .preenable = kxsd9_buffer_preenable,254 .preenable = kxsd9_buffer_preenable,
255 .postenable = iio_triggered_buffer_postenable,
256 .predisable = iio_triggered_buffer_predisable,
257 .postdisable = kxsd9_buffer_postdisable,255 .postdisable = kxsd9_buffer_postdisable,
258};256};
259 257
@@ -411,7 +409,6 @@ int kxsd9_common_probe(struct device *dev, · 151 unmodified lines
411 indio_dev->channels = kxsd9_channels;409 indio_dev->channels = kxsd9_channels;
412 indio_dev->num_channels = ARRAY_SIZE(kxsd9_channels);410 indio_dev->num_channels = ARRAY_SIZE(kxsd9_channels);
413 indio_dev->name = name;411 indio_dev->name = name;
414 indio_dev->dev.parent = dev;
415 indio_dev->info = &kxsd9_info;412 indio_dev->info = &kxsd9_info;
416 indio_dev->modes = INDIO_DIRECT_MODE;413 indio_dev->modes = INDIO_DIRECT_MODE;
417 indio_dev->available_scan_masks = kxsd9_scan_masks;414 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
132 data->client = client;132 data->client = client;
133 i2c_set_clientdata(client, indio_dev);133 i2c_set_clientdata(client, indio_dev);
134 134
135 indio_dev->dev.parent = &client->dev;
136 indio_dev->info = &mc3230_info;135 indio_dev->info = &mc3230_info;
137 indio_dev->name = "mc3230";136 indio_dev->name = "mc3230";
138 indio_dev->modes = INDIO_DIRECT_MODE;137 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
260 260
261 indio_dev->info = &mma7455_info;261 indio_dev->info = &mma7455_info;
262 indio_dev->name = name;262 indio_dev->name = name;
263 indio_dev->dev.parent = dev;
264 indio_dev->modes = INDIO_DIRECT_MODE;263 indio_dev->modes = INDIO_DIRECT_MODE;
265 indio_dev->channels = mma7455_channels;264 indio_dev->channels = mma7455_channels;
266 indio_dev->num_channels = ARRAY_SIZE(mma7455_channels);265 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
188 mutex_init(&data->lock);188 mutex_init(&data->lock);
189 data->mode = MMA7660_MODE_STANDBY;189 data->mode = MMA7660_MODE_STANDBY;
190 190
191 indio_dev->dev.parent = &client->dev;
192 indio_dev->info = &mma7660_info;191 indio_dev->info = &mma7660_info;
193 indio_dev->name = MMA7660_DRIVER_NAME;192 indio_dev->name = MMA7660_DRIVER_NAME;
194 indio_dev->modes = INDIO_DIRECT_MODE;193 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
1592 i2c_set_clientdata(client, indio_dev);1592 i2c_set_clientdata(client, indio_dev);
1593 indio_dev->info = &mma8452_info;1593 indio_dev->info = &mma8452_info;
1594 indio_dev->name = id->name;1594 indio_dev->name = id->name;
1595 indio_dev->dev.parent = &client->dev;
1596 indio_dev->modes = INDIO_DIRECT_MODE;1595 indio_dev->modes = INDIO_DIRECT_MODE;
1597 indio_dev->channels = data->chip_info->channels;1596 indio_dev->channels = data->chip_info->channels;
1598 indio_dev->num_channels = data->chip_info->num_channels;1597 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
473 473
474 mutex_init(&data->mutex);474 mutex_init(&data->mutex);
475 475
476 indio_dev->dev.parent = &client->dev;
477 indio_dev->channels = mma9551_channels;476 indio_dev->channels = mma9551_channels;
478 indio_dev->num_channels = ARRAY_SIZE(mma9551_channels);477 indio_dev->num_channels = ARRAY_SIZE(mma9551_channels);
479 indio_dev->name = name;478 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
1103 if (ret < 0)1103 if (ret < 0)
1104 return ret;1104 return ret;
1105 1105
1106 indio_dev->dev.parent = &client->dev;
1107 indio_dev->channels = mma9553_channels;1106 indio_dev->channels = mma9553_channels;
1108 indio_dev->num_channels = ARRAY_SIZE(mma9553_channels);1107 indio_dev->num_channels = ARRAY_SIZE(mma9553_channels);
1109 indio_dev->name = name;1108 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
416 416
417 mutex_init(&data->mutex);417 mutex_init(&data->mutex);
418 418
419 indio_dev->dev.parent = &client->dev;
420 indio_dev->channels = mxc4005_channels;419 indio_dev->channels = mxc4005_channels;
421 indio_dev->num_channels = ARRAY_SIZE(mxc4005_channels);420 indio_dev->num_channels = ARRAY_SIZE(mxc4005_channels);
422 indio_dev->available_scan_masks = mxc4005_scan_masks;421 indio_dev->available_scan_masks = mxc4005_scan_masks;
@@ -474,12 +473,14 @@ static int mxc4005_probe(struct i2c_client *client, · 51 unmodified lines
474 473
475static const struct acpi_device_id mxc4005_acpi_match[] = {474static const struct acpi_device_id mxc4005_acpi_match[] = {
476 {"MXC4005", 0},475 {"MXC4005", 0},
476 {"MXC6655", 0},
477 { },477 { },
478};478};
479MODULE_DEVICE_TABLE(acpi, mxc4005_acpi_match);479MODULE_DEVICE_TABLE(acpi, mxc4005_acpi_match);
480 480
481static const struct i2c_device_id mxc4005_id[] = {481static const struct i2c_device_id mxc4005_id[] = {
482 {"mxc4005", 0},482 {"mxc4005", 0},
483 {"mxc6655", 0},
483 { },484 { },
484};485};
485MODULE_DEVICE_TABLE(i2c, mxc4005_id);486MODULE_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
138 data->regmap = regmap;138 data->regmap = regmap;
139 139
140 indio_dev->name = MXC6255_DRV_NAME;140 indio_dev->name = MXC6255_DRV_NAME;
141 indio_dev->dev.parent = &client->dev;
142 indio_dev->channels = mxc6255_channels;141 indio_dev->channels = mxc6255_channels;
143 indio_dev->num_channels = ARRAY_SIZE(mxc6255_channels);142 indio_dev->num_channels = ARRAY_SIZE(mxc6255_channels);
144 indio_dev->modes = INDIO_DIRECT_MODE;143 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
1467 st->info = &sca3000_spi_chip_info_tbl[spi_get_device_id(spi)1467 st->info = &sca3000_spi_chip_info_tbl[spi_get_device_id(spi)
1468 ->driver_data];1468 ->driver_data];
1469 1469
1470 indio_dev->dev.parent = &spi->dev;
1471 indio_dev->name = spi_get_device_id(spi)->name;1470 indio_dev->name = spi_get_device_id(spi)->name;
1472 indio_dev->info = &sca3000_info;1471 indio_dev->info = &sca3000_info;
1473 if (st->info->temp_output) {1472 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
108 spd->type = SSP_ACCELEROMETER_SENSOR;108 spd->type = SSP_ACCELEROMETER_SENSOR;
109 109
110 indio_dev->name = ssp_accel_device_name;110 indio_dev->name = ssp_accel_device_name;
111 indio_dev->dev.parent = &pdev->dev;
112 indio_dev->dev.of_node = pdev->dev.of_node;
113 indio_dev->info = &ssp_accel_iio_info;111 indio_dev->info = &ssp_accel_iio_info;
114 indio_dev->modes = INDIO_BUFFER_SOFTWARE;112 indio_dev->modes = INDIO_BUFFER_SOFTWARE;
115 indio_dev->channels = ssp_acc_channels;113 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
33{33{
34 int err;34 int err;
35 35
36 err = iio_triggered_buffer_postenable(indio_dev);
37 if (err < 0)
38 return err;
39
40 err = st_sensors_set_axis_enable(indio_dev, indio_dev->active_scan_mask[0]);36 err = st_sensors_set_axis_enable(indio_dev, indio_dev->active_scan_mask[0]);
41 if (err < 0)37 if (err < 0)
42 goto st_accel_buffer_predisable;38 return err;
43 39
44 err = st_sensors_set_enable(indio_dev, true);40 err = st_sensors_set_enable(indio_dev, true);
45 if (err < 0)41 if (err < 0)
@@ -49,27 +45,19 @@ static int st_accel_buffer_postenable(struct iio_dev *indio_dev) · 3 unmodified lines
49 45
50st_accel_buffer_enable_all_axis:46st_accel_buffer_enable_all_axis:
51 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);47 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
52st_accel_buffer_predisable:
53 iio_triggered_buffer_predisable(indio_dev);
54 return err;48 return err;
55}49}
56 50
57static int st_accel_buffer_predisable(struct iio_dev *indio_dev)51static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
58{52{
59 int err, err2;53 int err;
60 54
61 err = st_sensors_set_enable(indio_dev, false);55 err = st_sensors_set_enable(indio_dev, false);
62 if (err < 0)56 if (err < 0)
63 goto st_accel_buffer_predisable;57 return err;
64
65 err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
66
67st_accel_buffer_predisable:
68 err2 = iio_triggered_buffer_predisable(indio_dev);
69 if (!err)
70 err = err2;
71 58
72 return err;59 return st_sensors_set_axis_enable(indio_dev,
60 ST_SENSORS_ENABLE_ALL_AXIS);
73}61}
74 62
75static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = {63static 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
492 492
493static const struct iio_buffer_setup_ops stk8312_buffer_setup_ops = {493static const struct iio_buffer_setup_ops stk8312_buffer_setup_ops = {
494 .preenable = stk8312_buffer_preenable,494 .preenable = stk8312_buffer_preenable,
495 .postenable = iio_triggered_buffer_postenable,
496 .predisable = iio_triggered_buffer_predisable,
497 .postdisable = stk8312_buffer_postdisable,495 .postdisable = stk8312_buffer_postdisable,
498};496};
499 497
@@ -515,7 +513,6 @@ static int stk8312_probe(struct i2c_client *client, · 15 unmodified lines
515 i2c_set_clientdata(client, indio_dev);513 i2c_set_clientdata(client, indio_dev);
516 mutex_init(&data->lock);514 mutex_init(&data->lock);
517 515
518 indio_dev->dev.parent = &client->dev;
519 indio_dev->info = &stk8312_info;516 indio_dev->info = &stk8312_info;
520 indio_dev->name = STK8312_DRIVER_NAME;517 indio_dev->name = STK8312_DRIVER_NAME;
521 indio_dev->modes = INDIO_DIRECT_MODE;518 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
376 376
377static const struct iio_buffer_setup_ops stk8ba50_buffer_setup_ops = {377static const struct iio_buffer_setup_ops stk8ba50_buffer_setup_ops = {
378 .preenable = stk8ba50_buffer_preenable,378 .preenable = stk8ba50_buffer_preenable,
379 .postenable = iio_triggered_buffer_postenable,
380 .predisable = iio_triggered_buffer_predisable,
381 .postdisable = stk8ba50_buffer_postdisable,379 .postdisable = stk8ba50_buffer_postdisable,
382};380};
383 381
@@ -399,7 +397,6 @@ static int stk8ba50_probe(struct i2c_client *client, · 15 unmodified lines
399 i2c_set_clientdata(client, indio_dev);397 i2c_set_clientdata(client, indio_dev);
400 mutex_init(&data->lock);398 mutex_init(&data->lock);
401 399
402 indio_dev->dev.parent = &client->dev;
403 indio_dev->info = &stk8ba50_info;400 indio_dev->info = &stk8ba50_info;
404 indio_dev->name = STK8BA50_DRIVER_NAME;401 indio_dev->name = STK8BA50_DRIVER_NAME;
405 indio_dev->modes = INDIO_DIRECT_MODE;402 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/Kconfig+1−1
@@ -294,7 +294,7 @@ config ASPEED_ADC · 293 unmodified lines
294 294
295config AT91_ADC295config AT91_ADC
296 tristate "Atmel AT91 ADC"296 tristate "Atmel AT91 ADC"
297 depends on ARCH_AT91297 depends on ARCH_AT91 || COMPILE_TEST
298 depends on INPUT && SYSFS298 depends on INPUT && SYSFS
299 select IIO_BUFFER299 select IIO_BUFFER
300 select IIO_TRIGGERED_BUFFER300 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
1163 1163
1164 pm_runtime_put(dev);1164 pm_runtime_put(dev);
1165 1165
1166 indio_dev->dev.parent = dev;
1167 indio_dev->dev.of_node = np;
1168 indio_dev->name = "ab8500-gpadc";1166 indio_dev->name = "ab8500-gpadc";
1169 indio_dev->modes = INDIO_DIRECT_MODE;1167 indio_dev->modes = INDIO_DIRECT_MODE;
1170 indio_dev->info = &ab8500_gpadc_info;1168 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
224 st->chip_info = chip_info;224 st->chip_info = chip_info;
225 st->map = map;225 st->map = map;
226 226
227 iio_dev->dev.parent = dev;
228 iio_dev->name = name;227 iio_dev->name = name;
229 iio_dev->info = &ad7091r_info;228 iio_dev->info = &ad7091r_info;
230 iio_dev->modes = INDIO_DIRECT_MODE;229 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
683 683
684 spi_set_drvdata(spi, indio_dev);684 spi_set_drvdata(spi, indio_dev);
685 685
686 indio_dev->dev.parent = &spi->dev;
687 indio_dev->name = spi_get_device_id(spi)->name;686 indio_dev->name = spi_get_device_id(spi)->name;
688 indio_dev->modes = INDIO_DIRECT_MODE;687 indio_dev->modes = INDIO_DIRECT_MODE;
689 indio_dev->info = &ad7124_info;688 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
970 970
971 spi_set_drvdata(spi, indio_dev);971 spi_set_drvdata(spi, indio_dev);
972 st->chip_info = of_device_get_match_data(&spi->dev);972 st->chip_info = of_device_get_match_data(&spi->dev);
973 indio_dev->dev.parent = &spi->dev;
974 indio_dev->name = st->chip_info->name;973 indio_dev->name = st->chip_info->name;
975 indio_dev->modes = INDIO_DIRECT_MODE;974 indio_dev->modes = INDIO_DIRECT_MODE;
976 975
drivers/iio/adc/ad7266.c+0−4
@@ -74,8 +74,6 @@ static int ad7266_postdisable(struct iio_dev *indio_dev) · 73 unmodified lines
74 74
75static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {75static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {
76 .preenable = &ad7266_preenable,76 .preenable = &ad7266_preenable,
77 .postenable = &iio_triggered_buffer_postenable,
78 .predisable = &iio_triggered_buffer_predisable,
79 .postdisable = &ad7266_postdisable,77 .postdisable = &ad7266_postdisable,
80};78};
81 79
@@ -437,8 +435,6 @@ static int ad7266_probe(struct spi_device *spi) · 355 unmodified lines
437 spi_set_drvdata(spi, indio_dev);435 spi_set_drvdata(spi, indio_dev);
438 st->spi = spi;436 st->spi = spi;
439 437
440 indio_dev->dev.parent = &spi->dev;
441 indio_dev->dev.of_node = spi->dev.of_node;
442 indio_dev->name = spi_get_device_id(spi)->name;438 indio_dev->name = spi_get_device_id(spi)->name;
443 indio_dev->modes = INDIO_DIRECT_MODE;439 indio_dev->modes = INDIO_DIRECT_MODE;
444 indio_dev->info = &ad7266_info;440 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
502 indio_dev->channels = ad7291_channels;502 indio_dev->channels = ad7291_channels;
503 indio_dev->num_channels = ARRAY_SIZE(ad7291_channels);503 indio_dev->num_channels = ARRAY_SIZE(ad7291_channels);
504 504
505 indio_dev->dev.parent = &client->dev;
506 indio_dev->dev.of_node = client->dev.of_node;
507 indio_dev->info = &ad7291_info;505 indio_dev->info = &ad7291_info;
508 indio_dev->modes = INDIO_DIRECT_MODE;506 indio_dev->modes = INDIO_DIRECT_MODE;
509 507
drivers/iio/adc/ad7292.c+0−1
@@ -304,7 +304,6 @@ static int ad7292_probe(struct spi_device *spi) · 303 unmodified lines
304 st->vref_mv = 1250;304 st->vref_mv = 1250;
305 }305 }
306 306
307 indio_dev->dev.parent = &spi->dev;
308 indio_dev->name = spi_get_device_id(spi)->name;307 indio_dev->name = spi_get_device_id(spi)->name;
309 indio_dev->modes = INDIO_DIRECT_MODE;308 indio_dev->modes = INDIO_DIRECT_MODE;
310 indio_dev->info = &ad7292_info;309 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
312 st->spi = spi;312 st->spi = spi;
313 313
314 indio_dev->name = spi_get_device_id(spi)->name;314 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;
317 indio_dev->modes = INDIO_DIRECT_MODE;315 indio_dev->modes = INDIO_DIRECT_MODE;
318 indio_dev->channels = ad7298_channels;316 indio_dev->channels = ad7298_channels;
319 indio_dev->num_channels = ARRAY_SIZE(ad7298_channels);317 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
300 300
301 st->spi = spi;301 st->spi = spi;
302 302
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;
306 indio_dev->name = spi_get_device_id(spi)->name;303 indio_dev->name = spi_get_device_id(spi)->name;
307 indio_dev->modes = INDIO_DIRECT_MODE;304 indio_dev->modes = INDIO_DIRECT_MODE;
308 indio_dev->channels = st->chip_info->channel;305 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
499{499{
500 struct ad7606_state *st = iio_priv(indio_dev);500 struct ad7606_state *st = iio_priv(indio_dev);
501 501
502 iio_triggered_buffer_postenable(indio_dev);
503 gpiod_set_value(st->gpio_convst, 1);502 gpiod_set_value(st->gpio_convst, 1);
504 503
505 return 0;504 return 0;
@@ -511,7 +510,7 @@ static int ad7606_buffer_predisable(struct iio_dev *indio_dev) · 5 unmodified lines
511 510
512 gpiod_set_value(st->gpio_convst, 0);511 gpiod_set_value(st->gpio_convst, 0);
513 512
514 return iio_triggered_buffer_predisable(indio_dev);513 return 0;
515}514}
516 515
517static const struct iio_buffer_setup_ops ad7606_buffer_ops = {516static 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
614 if (ret)613 if (ret)
615 return ret;614 return ret;
616 615
617 indio_dev->dev.parent = dev;
618 if (st->gpio_os) {616 if (st->gpio_os) {
619 if (st->gpio_range)617 if (st->gpio_range)
620 indio_dev->info = &ad7606_info_os_and_range;618 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
178 178
179static const struct iio_buffer_setup_ops ad7766_buffer_setup_ops = {179static const struct iio_buffer_setup_ops ad7766_buffer_setup_ops = {
180 .preenable = &ad7766_preenable,180 .preenable = &ad7766_preenable,
181 .postenable = &iio_triggered_buffer_postenable,
182 .predisable = &iio_triggered_buffer_predisable,
183 .postdisable = &ad7766_postdisable,181 .postdisable = &ad7766_postdisable,
184};182};
185 183
@@ -242,7 +240,6 @@ static int ad7766_probe(struct spi_device *spi) · 56 unmodified lines
242 if (IS_ERR(ad7766->pd_gpio))240 if (IS_ERR(ad7766->pd_gpio))
243 return PTR_ERR(ad7766->pd_gpio);241 return PTR_ERR(ad7766->pd_gpio);
244 242
245 indio_dev->dev.parent = &spi->dev;
246 indio_dev->name = spi_get_device_id(spi)->name;243 indio_dev->name = spi_get_device_id(spi)->name;
247 indio_dev->modes = INDIO_DIRECT_MODE;244 indio_dev->modes = INDIO_DIRECT_MODE;
248 indio_dev->channels = ad7766_channels;245 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
490{490{
491 struct ad7768_state *st = iio_priv(indio_dev);491 struct ad7768_state *st = iio_priv(indio_dev);
492 492
493 iio_triggered_buffer_postenable(indio_dev);
494 /*493 /*
495 * Write a 1 to the LSB of the INTERFACE_FORMAT register to enter494 * Write a 1 to the LSB of the INTERFACE_FORMAT register to enter
496 * continuous read mode. Subsequent data reads do not require an495 * 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
502static int ad7768_buffer_predisable(struct iio_dev *indio_dev)501static int ad7768_buffer_predisable(struct iio_dev *indio_dev)
503{502{
504 struct ad7768_state *st = iio_priv(indio_dev);503 struct ad7768_state *st = iio_priv(indio_dev);
505 int ret;
506 504
507 /*505 /*
508 * To exit continuous read mode, perform a single read of the ADC_DATA506 * To exit continuous read mode, perform a single read of the ADC_DATA
509 * reg (0x2C), which allows further configuration of the device.507 * reg (0x2C), which allows further configuration of the device.
510 */508 */
511 ret = ad7768_spi_reg_read(st, AD7768_REG_ADC_DATA, 3);509 return 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);
516}510}
517 511
518static const struct iio_buffer_setup_ops ad7768_buffer_ops = {512static const struct iio_buffer_setup_ops ad7768_buffer_ops = {
@@ -584,7 +578,6 @@ static int ad7768_probe(struct spi_device *spi) · 65 unmodified lines
584 578
585 indio_dev->channels = ad7768_channels;579 indio_dev->channels = ad7768_channels;
586 indio_dev->num_channels = ARRAY_SIZE(ad7768_channels);580 indio_dev->num_channels = ARRAY_SIZE(ad7768_channels);
587 indio_dev->dev.parent = &spi->dev;
588 indio_dev->name = spi_get_device_id(spi)->name;581 indio_dev->name = spi_get_device_id(spi)->name;
589 indio_dev->info = &ad7768_info;582 indio_dev->info = &ad7768_info;
590 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_TRIGGERED;583 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
320 320
321 spi_set_drvdata(spi, indio_dev);321 spi_set_drvdata(spi, indio_dev);
322 322
323 indio_dev->dev.parent = &spi->dev;
324 indio_dev->name = spi_get_device_id(spi)->name;323 indio_dev->name = spi_get_device_id(spi)->name;
325 indio_dev->modes = INDIO_DIRECT_MODE;324 indio_dev->modes = INDIO_DIRECT_MODE;
326 indio_dev->channels = &st->chip_info->channel;325 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
425 425
426 spi_set_drvdata(spi, indio_dev);426 spi_set_drvdata(spi, indio_dev);
427 427
428 indio_dev->dev.parent = &spi->dev;
429 indio_dev->dev.of_node = spi->dev.of_node;
430 indio_dev->name = spi_get_device_id(spi)->name;428 indio_dev->name = spi_get_device_id(spi)->name;
431 indio_dev->modes = INDIO_DIRECT_MODE;429 indio_dev->modes = INDIO_DIRECT_MODE;
432 indio_dev->channels = st->info->channels;430 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
818 818
819 spi_set_drvdata(spi, indio_dev);819 spi_set_drvdata(spi, indio_dev);
820 820
821 indio_dev->dev.parent = &spi->dev;
822 indio_dev->dev.of_node = spi->dev.of_node;
823 indio_dev->name = spi_get_device_id(spi)->name;821 indio_dev->name = spi_get_device_id(spi)->name;
824 indio_dev->modes = INDIO_DIRECT_MODE;822 indio_dev->modes = INDIO_DIRECT_MODE;
825 indio_dev->channels = st->chip_info->channels;823 indio_dev->channels = st->chip_info->channels;
drivers/iio/adc/ad7887.c+0−5
@@ -136,8 +136,6 @@ done: · 135 unmodified lines
136 136
137static const struct iio_buffer_setup_ops ad7887_ring_setup_ops = {137static const struct iio_buffer_setup_ops ad7887_ring_setup_ops = {
138 .preenable = &ad7887_ring_preenable,138 .preenable = &ad7887_ring_preenable,
139 .postenable = &iio_triggered_buffer_postenable,
140 .predisable = &iio_triggered_buffer_predisable,
141 .postdisable = &ad7887_ring_postdisable,139 .postdisable = &ad7887_ring_postdisable,
142};140};
143 141
@@ -264,9 +262,6 @@ static int ad7887_probe(struct spi_device *spi) · 120 unmodified lines
264 spi_set_drvdata(spi, indio_dev);262 spi_set_drvdata(spi, indio_dev);
265 st->spi = spi;263 st->spi = spi;
266 264
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;
270 indio_dev->name = spi_get_device_id(spi)->name;265 indio_dev->name = spi_get_device_id(spi)->name;
271 indio_dev->info = &ad7887_info;266 indio_dev->info = &ad7887_info;
272 indio_dev->modes = INDIO_DIRECT_MODE;267 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
315 info = &ad7923_chip_info[spi_get_device_id(spi)->driver_data];315 info = &ad7923_chip_info[spi_get_device_id(spi)->driver_data];
316 316
317 indio_dev->name = spi_get_device_id(spi)->name;317 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;
320 indio_dev->modes = INDIO_DIRECT_MODE;318 indio_dev->modes = INDIO_DIRECT_MODE;
321 indio_dev->channels = info->channels;319 indio_dev->channels = info->channels;
322 indio_dev->num_channels = info->num_channels;320 indio_dev->num_channels = info->num_channels;
drivers/iio/adc/ad7949.c+1−3
@@ -3,7 +3,7 @@ · 2 unmodified lines
3 *3 *
4 * Copyright (C) 2018 CMC NV4 * Copyright (C) 2018 CMC NV
5 *5 *
6 * http://www.analog.com/media/en/technical-documentation/data-sheets/AD7949.pdf6 * https://www.analog.com/media/en/technical-documentation/data-sheets/AD7949.pdf
7 */7 */
8 8
9#include <linux/delay.h>9#include <linux/delay.h>
@@ -243,8 +243,6 @@ static int ad7949_spi_probe(struct spi_device *spi) · 233 unmodified lines
243 return -ENOMEM;243 return -ENOMEM;
244 }244 }
245 245
246 indio_dev->dev.parent = dev;
247 indio_dev->dev.of_node = dev->of_node;
248 indio_dev->info = &ad7949_spi_info;246 indio_dev->info = &ad7949_spi_info;
249 indio_dev->name = spi_get_device_id(spi)->name;247 indio_dev->name = spi_get_device_id(spi)->name;
250 indio_dev->modes = INDIO_DIRECT_MODE;248 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
814 814
815 st->client = client;815 st->client = client;
816 816
817 indio_dev->dev.parent = &client->dev;
818 indio_dev->dev.of_node = client->dev.of_node;
819 indio_dev->name = id->name;817 indio_dev->name = id->name;
820 indio_dev->info = st->chip_config->info;818 indio_dev->info = st->chip_config->info;
821 819
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
345 unsigned int channel;345 unsigned int channel;
346 int ret;346 int ret;
347 347
348 ret = iio_triggered_buffer_postenable(indio_dev);
349 if (ret < 0)
350 return ret;
351
352 channel = find_first_bit(indio_dev->active_scan_mask,348 channel = find_first_bit(indio_dev->active_scan_mask,
353 indio_dev->masklength);349 indio_dev->masklength);
354 ret = ad_sigma_delta_set_channel(sigma_delta,350 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
441 437
442static const struct iio_buffer_setup_ops ad_sd_buffer_setup_ops = {438static const struct iio_buffer_setup_ops ad_sd_buffer_setup_ops = {
443 .postenable = &ad_sd_buffer_postenable,439 .postenable = &ad_sd_buffer_postenable,
444 .predisable = &iio_triggered_buffer_predisable,
445 .postdisable = &ad_sd_buffer_postdisable,440 .postdisable = &ad_sd_buffer_postdisable,
446 .validate_scan_mask = &iio_validate_scan_mask_onehot,441 .validate_scan_mask = &iio_validate_scan_mask_onehot,
447};442};
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
435 }435 }
436 436
437 indio_dev->info = &adi_axi_adc_info;437 indio_dev->info = &adi_axi_adc_info;
438 indio_dev->dev.parent = &pdev->dev;
439 indio_dev->name = "adi-axi-adc";438 indio_dev->name = "adi-axi-adc";
440 indio_dev->modes = INDIO_DIRECT_MODE;439 indio_dev->modes = INDIO_DIRECT_MODE;
441 indio_dev->num_channels = conv->chip_info->num_channels;440 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
252 252
253 model_data = of_device_get_match_data(&pdev->dev);253 model_data = of_device_get_match_data(&pdev->dev);
254 indio_dev->name = model_data->model_name;254 indio_dev->name = model_data->model_name;
255 indio_dev->dev.parent = &pdev->dev;
256 indio_dev->info = &aspeed_adc_iio_info;255 indio_dev->info = &aspeed_adc_iio_info;
257 indio_dev->modes = INDIO_DIRECT_MODE;256 indio_dev->modes = INDIO_DIRECT_MODE;
258 indio_dev->channels = aspeed_adc_iio_channels;257 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
402 wait_queue_head_t wq_data_available;402 wait_queue_head_t wq_data_available;
403 struct at91_adc_dma dma_st;403 struct at91_adc_dma dma_st;
404 struct at91_adc_touch touch_st;404 struct at91_adc_touch touch_st;
405 struct iio_dev *indio_dev;
405 u16 buffer[AT91_BUFFER_MAX_HWORDS];406 u16 buffer[AT91_BUFFER_MAX_HWORDS];
406 /*407 /*
407 * lock to prevent concurrent 'single conversion' requests through408 * 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
642 /* first half of register is the x or y, second half is the scale */643 /* first half of register is the x or y, second half is the scale */
643 val = at91_adc_readl(st, reg);644 val = at91_adc_readl(st, reg);
644 if (!val)645 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");
646 647
647 pos = val & AT91_SAMA5D2_XYZ_MASK;648 pos = val & AT91_SAMA5D2_XYZ_MASK;
648 result = (pos << AT91_SAMA5D2_MAX_POS_BITS) - pos;649 result = (pos << AT91_SAMA5D2_MAX_POS_BITS) - pos;
649 scale = (val >> 16) & AT91_SAMA5D2_XYZ_MASK;650 scale = (val >> 16) & AT91_SAMA5D2_XYZ_MASK;
650 if (scale == 0) {651 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");
652 return 0;653 return 0;
653 }654 }
654 result /= scale;655 result /= scale;
@@ -937,14 +938,6 @@ static int at91_adc_buffer_preenable(struct iio_dev *indio_dev) · 282 unmodified lines
937 return 0;938 return 0;
938}939}
939 940
940static 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
948static int at91_adc_buffer_postdisable(struct iio_dev *indio_dev)941static int at91_adc_buffer_postdisable(struct iio_dev *indio_dev)
949{942{
950 struct at91_adc_state *st = iio_priv(indio_dev);943 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
995 return 0;988 return 0;
996}989}
997 990
998static 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
1006static const struct iio_buffer_setup_ops at91_buffer_setup_ops = {991static const struct iio_buffer_setup_ops at91_buffer_setup_ops = {
1007 .preenable = &at91_adc_buffer_preenable,992 .preenable = &at91_adc_buffer_preenable,
1008 .postdisable = &at91_adc_buffer_postdisable,993 .postdisable = &at91_adc_buffer_postdisable,
1009 .postenable = &at91_adc_buffer_postenable,
1010 .predisable = &at91_adc_buffer_predisable,
1011};994};
1012 995
1013static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *indio,996static 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
1204 return i;1187 return i;
1205}1188}
1206 1189
1207static void at91_adc_setup_samp_freq(struct at91_adc_state *st, unsigned freq)1190static void at91_adc_setup_samp_freq(struct iio_dev *indio_dev, unsigned freq)
1208{1191{
1209 struct iio_dev *indio_dev = iio_priv_to_dev(st);1192 struct at91_adc_state *st = iio_priv(indio_dev);
1210 unsigned f_per, prescal, startup, mr;1193 unsigned f_per, prescal, startup, mr;
1211 1194
1212 f_per = clk_get_rate(st->per_clk);1195 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
1275 st->touch_st.touching = true;1258 st->touch_st.touching = true;
1276}1259}
1277 1260
1278static void at91_adc_no_pen_detect_interrupt(struct at91_adc_state *st)1261static void at91_adc_no_pen_detect_interrupt(struct iio_dev *indio_dev)
1279{1262{
1280 struct iio_dev *indio_dev = iio_priv_to_dev(st);1263 struct at91_adc_state *st = iio_priv(indio_dev);
1281 1264
1282 at91_adc_writel(st, AT91_SAMA5D2_TRGR,1265 at91_adc_writel(st, AT91_SAMA5D2_TRGR,
1283 AT91_SAMA5D2_TRGR_TRGMOD_NO_TRIGGER);1266 AT91_SAMA5D2_TRGR_TRGMOD_NO_TRIGGER);
@@ -1297,7 +1280,7 @@ static void at91_adc_workq_handler(struct work_struct *workq) · 13 unmodified lines
1297 struct at91_adc_touch, workq);1280 struct at91_adc_touch, workq);
1298 struct at91_adc_state *st = container_of(touch_st,1281 struct at91_adc_state *st = container_of(touch_st,
1299 struct at91_adc_state, touch_st);1282 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;
1301 1284
1302 iio_push_to_buffers(indio_dev, st->buffer);1285 iio_push_to_buffers(indio_dev, st->buffer);
1303}1286}
@@ -1318,7 +1301,7 @@ static irqreturn_t at91_adc_interrupt(int irq, void *private) · 14 unmodified lines
1318 at91_adc_pen_detect_interrupt(st);1301 at91_adc_pen_detect_interrupt(st);
1319 } else if ((status & AT91_SAMA5D2_IER_NOPEN)) {1302 } else if ((status & AT91_SAMA5D2_IER_NOPEN)) {
1320 /* nopen detected IRQ */1303 /* nopen detected IRQ */
1321 at91_adc_no_pen_detect_interrupt(st);1304 at91_adc_no_pen_detect_interrupt(indio);
1322 } else if ((status & AT91_SAMA5D2_ISR_PENS) &&1305 } else if ((status & AT91_SAMA5D2_ISR_PENS) &&
1323 ((status & rdy_mask) == rdy_mask)) {1306 ((status & rdy_mask) == rdy_mask)) {
1324 /* periodic trigger IRQ - during pen sense */1307 /* periodic trigger IRQ - during pen sense */
@@ -1486,7 +1469,7 @@ static int at91_adc_write_raw(struct iio_dev *indio_dev, · 161 unmodified lines
1486 val > st->soc_info.max_sample_rate)1469 val > st->soc_info.max_sample_rate)
1487 return -EINVAL;1470 return -EINVAL;
1488 1471
1489 at91_adc_setup_samp_freq(st, val);1472 at91_adc_setup_samp_freq(indio_dev, val);
1490 return 0;1473 return 0;
1491 default:1474 default:
1492 return -EINVAL;1475 return -EINVAL;
@@ -1624,8 +1607,10 @@ static int at91_adc_update_scan_mode(struct iio_dev *indio_dev, · 131 unmodified lines
1624 return 0;1607 return 0;
1625}1608}
1626 1609
1627static void at91_adc_hw_init(struct at91_adc_state *st)1610static void at91_adc_hw_init(struct iio_dev *indio_dev)
1628{1611{
1612 struct at91_adc_state *st = iio_priv(indio_dev);
1613
1629 at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST);1614 at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST);
1630 at91_adc_writel(st, AT91_SAMA5D2_IDR, 0xffffffff);1615 at91_adc_writel(st, AT91_SAMA5D2_IDR, 0xffffffff);
1631 /*1616 /*
@@ -1635,7 +1620,7 @@ static void at91_adc_hw_init(struct at91_adc_state *st) · 3 unmodified lines
1635 at91_adc_writel(st, AT91_SAMA5D2_MR,1620 at91_adc_writel(st, AT91_SAMA5D2_MR,
1636 AT91_SAMA5D2_MR_TRANSFER(2) | AT91_SAMA5D2_MR_ANACH);1621 AT91_SAMA5D2_MR_TRANSFER(2) | AT91_SAMA5D2_MR_ANACH);
1637 1622
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);
1639 1624
1640 /* configure extended mode register */1625 /* configure extended mode register */
1641 at91_adc_config_emr(st);1626 at91_adc_config_emr(st);
@@ -1710,7 +1695,6 @@ static int at91_adc_probe(struct platform_device *pdev) · 68 unmodified lines
1710 if (!indio_dev)1695 if (!indio_dev)
1711 return -ENOMEM;1696 return -ENOMEM;
1712 1697
1713 indio_dev->dev.parent = &pdev->dev;
1714 indio_dev->name = dev_name(&pdev->dev);1698 indio_dev->name = dev_name(&pdev->dev);
1715 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;1699 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
1716 indio_dev->info = &at91_adc_info;1700 indio_dev->info = &at91_adc_info;
@@ -1718,6 +1702,7 @@ static int at91_adc_probe(struct platform_device *pdev) · 1 unmodified line
1718 indio_dev->num_channels = ARRAY_SIZE(at91_adc_channels);1702 indio_dev->num_channels = ARRAY_SIZE(at91_adc_channels);
1719 1703
1720 st = iio_priv(indio_dev);1704 st = iio_priv(indio_dev);
1705 st->indio_dev = indio_dev;
1721 1706
1722 bitmap_set(&st->touch_st.channels_bitmask,1707 bitmap_set(&st->touch_st.channels_bitmask,
1723 AT91_SAMA5D2_TOUCH_X_CHAN_IDX, 1);1708 AT91_SAMA5D2_TOUCH_X_CHAN_IDX, 1);
@@ -1829,7 +1814,7 @@ static int at91_adc_probe(struct platform_device *pdev) · 105 unmodified lines
1829 goto vref_disable;1814 goto vref_disable;
1830 }1815 }
1831 1816
1832 at91_adc_hw_init(st);1817 at91_adc_hw_init(indio_dev);
1833 1818
1834 ret = clk_prepare_enable(st->per_clk);1819 ret = clk_prepare_enable(st->per_clk);
1835 if (ret)1820 if (ret)
@@ -1945,7 +1930,7 @@ static __maybe_unused int at91_adc_resume(struct device *dev) · 109 unmodified lines
1945 if (ret)1930 if (ret)
1946 goto vref_disable_resume;1931 goto vref_disable_resume;
1947 1932
1948 at91_adc_hw_init(st);1933 at91_adc_hw_init(indio_dev);
1949 1934
1950 /* reconfiguring trigger hardware state */1935 /* reconfiguring trigger hardware state */
1951 if (!iio_buffer_enabled(indio_dev))1936 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
287 }287 }
288}288}
289 289
290static int at91_ts_sample(struct at91_adc_state *st)290static int at91_ts_sample(struct iio_dev *idev)
291{291{
292 struct at91_adc_state *st = iio_priv(idev);
292 unsigned int xscale, yscale, reg, z1, z2;293 unsigned int xscale, yscale, reg, z1, z2;
293 unsigned int x, y, pres, xpos, ypos;294 unsigned int x, y, pres, xpos, ypos;
294 unsigned int rxp = 1;295 unsigned int rxp = 1;
295 unsigned int factor = 1000;296 unsigned int factor = 1000;
296 struct iio_dev *idev = iio_priv_to_dev(st);
297 297
298 unsigned int xyz_mask_bits = st->res;298 unsigned int xyz_mask_bits = st->res;
299 unsigned int xyz_mask = (1 << xyz_mask_bits) - 1;299 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
449 449
450 if (status & AT91_ADC_ISR_PENS) {450 if (status & AT91_ADC_ISR_PENS) {
451 /* validate data by pen contact */451 /* validate data by pen contact */
452 at91_ts_sample(st);452 at91_ts_sample(idev);
453 } else {453 } else {
454 /* triggered by event that is no pen contact, just read454 /* triggered by event that is no pen contact, just read
455 * them to clean the interrupt and discard all.455 * 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
737 return -EINVAL;737 return -EINVAL;
738}738}
739 739
740static int at91_adc_of_get_resolution(struct at91_adc_state *st,740static int at91_adc_of_get_resolution(struct iio_dev *idev,
741 struct platform_device *pdev)741 struct platform_device *pdev)
742{742{
743 struct iio_dev *idev = iio_priv_to_dev(st);743 struct at91_adc_state *st = iio_priv(idev);
744 struct device_node *np = pdev->dev.of_node;744 struct device_node *np = pdev->dev.of_node;
745 int count, i, ret = 0;745 int count, i, ret = 0;
746 char *res_name, *s;746 char *res_name, *s;
@@ -866,10 +866,10 @@ static int at91_adc_probe_dt_ts(struct device_node *node, · 119 unmodified lines
866 }866 }
867}867}
868 868
869static int at91_adc_probe_dt(struct at91_adc_state *st,869static int at91_adc_probe_dt(struct iio_dev *idev,
870 struct platform_device *pdev)870 struct platform_device *pdev)
871{871{
872 struct iio_dev *idev = iio_priv_to_dev(st);872 struct at91_adc_state *st = iio_priv(idev);
873 struct device_node *node = pdev->dev.of_node;873 struct device_node *node = pdev->dev.of_node;
874 struct device_node *trig_node;874 struct device_node *trig_node;
875 int i = 0, ret;875 int i = 0, ret;
@@ -910,7 +910,7 @@ static int at91_adc_probe_dt(struct at91_adc_state *st, · 34 unmodified lines
910 }910 }
911 st->vref_mv = prop;911 st->vref_mv = prop;
912 912
913 ret = at91_adc_of_get_resolution(st, pdev);913 ret = at91_adc_of_get_resolution(idev, pdev);
914 if (ret)914 if (ret)
915 goto error_ret;915 goto error_ret;
916 916
@@ -1010,9 +1010,9 @@ static void atmel_ts_close(struct input_dev *dev) · 93 unmodified lines
1010 at91_adc_writel(st, AT91_ADC_IDR, AT91RL_ADC_IER_PEN);1010 at91_adc_writel(st, AT91_ADC_IDR, AT91RL_ADC_IER_PEN);
1011}1011}
1012 1012
1013static int at91_ts_hw_init(struct at91_adc_state *st, u32 adc_clk_khz)1013static int at91_ts_hw_init(struct iio_dev *idev, u32 adc_clk_khz)
1014{1014{
1015 struct iio_dev *idev = iio_priv_to_dev(st);1015 struct at91_adc_state *st = iio_priv(idev);
1016 u32 reg = 0;1016 u32 reg = 0;
1017 u32 tssctim = 0;1017 u32 tssctim = 0;
1018 int i = 0;1018 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
1085 return 0;1085 return 0;
1086}1086}
1087 1087
1088static int at91_ts_register(struct at91_adc_state *st,1088static int at91_ts_register(struct iio_dev *idev,
1089 struct platform_device *pdev)1089 struct platform_device *pdev)
1090{1090{
1091 struct at91_adc_state *st = iio_priv(idev);
1091 struct input_dev *input;1092 struct input_dev *input;
1092 struct iio_dev *idev = iio_priv_to_dev(st);
1093 int ret;1093 int ret;
1094 1094
1095 input = input_allocate_device();1095 input = input_allocate_device();
@@ -1161,7 +1161,7 @@ static int at91_adc_probe(struct platform_device *pdev) · 65 unmodified lines
1161 st = iio_priv(idev);1161 st = iio_priv(idev);
1162 1162
1163 if (pdev->dev.of_node)1163 if (pdev->dev.of_node)
1164 ret = at91_adc_probe_dt(st, pdev);1164 ret = at91_adc_probe_dt(idev, pdev);
1165 else1165 else
1166 ret = at91_adc_probe_pdata(st, pdev);1166 ret = at91_adc_probe_pdata(st, pdev);
1167 1167
@@ -1172,7 +1172,6 @@ static int at91_adc_probe(struct platform_device *pdev) · 4 unmodified lines
1172 1172
1173 platform_set_drvdata(pdev, idev);1173 platform_set_drvdata(pdev, idev);
1174 1174
1175 idev->dev.parent = &pdev->dev;
1176 idev->name = dev_name(&pdev->dev);1175 idev->name = dev_name(&pdev->dev);
1177 idev->modes = INDIO_DIRECT_MODE;1176 idev->modes = INDIO_DIRECT_MODE;
1178 idev->info = &at91_adc_info;1177 idev->info = &at91_adc_info;
@@ -1301,11 +1300,11 @@ static int at91_adc_probe(struct platform_device *pdev) · 122 unmodified lines
1301 goto error_disable_adc_clk;1300 goto error_disable_adc_clk;
1302 }1301 }
1303 } else {1302 } else {
1304 ret = at91_ts_register(st, pdev);1303 ret = at91_ts_register(idev, pdev);
1305 if (ret)1304 if (ret)
1306 goto error_disable_adc_clk;1305 goto error_disable_adc_clk;
1307 1306
1308 at91_ts_hw_init(st, adc_clk_khz);1307 at91_ts_hw_init(idev, adc_clk_khz);
1309 }1308 }
1310 1309
1311 ret = iio_device_register(idev);1310 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
668 platform_set_drvdata(pdev, indio_dev);668 platform_set_drvdata(pdev, indio_dev);
669 669
670 info->regmap = axp20x_dev->regmap;670 info->regmap = axp20x_dev->regmap;
671 indio_dev->dev.parent = &pdev->dev;
672 indio_dev->dev.of_node = pdev->dev.of_node;
673 indio_dev->modes = INDIO_DIRECT_MODE;671 indio_dev->modes = INDIO_DIRECT_MODE;
674 672
675 if (!pdev->dev.of_node) {673 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
271 return ret;271 return ret;
272 }272 }
273 273
274 indio_dev->dev.parent = &pdev->dev;
275 indio_dev->name = pdev->name;274 indio_dev->name = pdev->name;
276 indio_dev->channels = axp288_adc_channels;275 indio_dev->channels = axp288_adc_channels;
277 indio_dev->num_channels = ARRAY_SIZE(axp288_adc_channels);276 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
573 }573 }
574 574
575 indio_dev->name = "iproc-static-adc";575 indio_dev->name = "iproc-static-adc";
576 indio_dev->dev.parent = &pdev->dev;
577 indio_dev->dev.of_node = pdev->dev.of_node;
578 indio_dev->info = &iproc_adc_iio_info;576 indio_dev->info = &iproc_adc_iio_info;
579 indio_dev->modes = INDIO_DIRECT_MODE;577 indio_dev->modes = INDIO_DIRECT_MODE;
580 indio_dev->channels = iproc_adc_iio_channels;578 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
321 init_waitqueue_head(&priv->wq);321 init_waitqueue_head(&priv->wq);
322 mutex_init(&priv->lock);322 mutex_init(&priv->lock);
323 323
324 indio_dev->dev.parent = &pdev->dev;
325 indio_dev->name = dev_name(&pdev->dev);324 indio_dev->name = dev_name(&pdev->dev);
326 indio_dev->modes = INDIO_DIRECT_MODE;325 indio_dev->modes = INDIO_DIRECT_MODE;
327 indio_dev->info = &berlin2_adc_info;326 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
334 if (ret)334 if (ret)
335 return ret;335 return ret;
336 336
337 indio_dev->dev.parent = &pdev->dev;
338 indio_dev->name = dev_name(&pdev->dev);337 indio_dev->name = dev_name(&pdev->dev);
339 indio_dev->info = &cc10001_adc_info;338 indio_dev->info = &cc10001_adc_info;
340 indio_dev->modes = INDIO_DIRECT_MODE;339 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/cpcap-adc.c+6−18
@@ -15,9 +15,9 @@ · 14 unmodified lines
15#include <linux/interrupt.h>15#include <linux/interrupt.h>
16#include <linux/kernel.h>16#include <linux/kernel.h>
17#include <linux/module.h>17#include <linux/module.h>
18#include <linux/of.h>18#include <linux/mod_devicetable.h>
19#include <linux/of_platform.h>
20#include <linux/platform_device.h>19#include <linux/platform_device.h>
20#include <linux/property.h>
21#include <linux/regmap.h>21#include <linux/regmap.h>
22 22
23#include <linux/iio/buffer.h>23#include <linux/iio/buffer.h>
@@ -955,22 +955,10 @@ MODULE_DEVICE_TABLE(of, cpcap_adc_id_table); · 931 unmodified lines
955 955
956static int cpcap_adc_probe(struct platform_device *pdev)956static int cpcap_adc_probe(struct platform_device *pdev)
957{957{
958 const struct of_device_id *match;
959 struct cpcap_adc *ddata;958 struct cpcap_adc *ddata;
960 struct iio_dev *indio_dev;959 struct iio_dev *indio_dev;
961 int error;960 int error;
962 961
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
974 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*ddata));962 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*ddata));
975 if (!indio_dev) {963 if (!indio_dev) {
976 dev_err(&pdev->dev, "failed to allocate iio device\n");964 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
978 return -ENOMEM;966 return -ENOMEM;
979 }967 }
980 ddata = iio_priv(indio_dev);968 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;
982 ddata->dev = &pdev->dev;972 ddata->dev = &pdev->dev;
983 973
984 mutex_init(&ddata->lock);974 mutex_init(&ddata->lock);
985 init_waitqueue_head(&ddata->wq_data_avail);975 init_waitqueue_head(&ddata->wq_data_avail);
986 976
987 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;977 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;
990 indio_dev->channels = cpcap_adc_channels;978 indio_dev->channels = cpcap_adc_channels;
991 indio_dev->num_channels = ARRAY_SIZE(cpcap_adc_channels);979 indio_dev->num_channels = ARRAY_SIZE(cpcap_adc_channels);
992 indio_dev->name = dev_name(&pdev->dev);980 indio_dev->name = dev_name(&pdev->dev);
@@ -1029,7 +1017,7 @@ static int cpcap_adc_probe(struct platform_device *pdev) · 36 unmodified lines
1029static struct platform_driver cpcap_adc_driver = {1017static struct platform_driver cpcap_adc_driver = {
1030 .driver = {1018 .driver = {
1031 .name = "cpcap_adc",1019 .name = "cpcap_adc",
1032 .of_match_table = of_match_ptr(cpcap_adc_id_table),1020 .of_match_table = cpcap_adc_id_table,
1033 },1021 },
1034 .probe = cpcap_adc_probe,1022 .probe = cpcap_adc_probe,
1035};1023};
drivers/iio/adc/da9150-gpadc.c+0−2
@@ -354,8 +354,6 @@ static int da9150_gpadc_probe(struct platform_device *pdev) · 353 unmodified lines
354 }354 }
355 355
356 indio_dev->name = dev_name(dev);356 indio_dev->name = dev_name(dev);
357 indio_dev->dev.parent = dev;
358 indio_dev->dev.of_node = pdev->dev.of_node;
359 indio_dev->info = &da9150_gpadc_info;357 indio_dev->info = &da9150_gpadc_info;
360 indio_dev->modes = INDIO_DIRECT_MODE;358 indio_dev->modes = INDIO_DIRECT_MODE;
361 indio_dev->channels = da9150_gpadc_channels;359 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
524 u16 conflict;524 u16 conflict;
525 unsigned int trigger_chan;525 unsigned int trigger_chan;
526 526
527 ret = iio_triggered_buffer_postenable(indio_dev);
528 if (ret)
529 return ret;
530
531 mutex_lock(&dln2->mutex);527 mutex_lock(&dln2->mutex);
532 528
533 /* Enable ADC */529 /* Enable ADC */
@@ -541,7 +537,6 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev) · 7 unmodified lines
541 (int)conflict);537 (int)conflict);
542 ret = -EBUSY;538 ret = -EBUSY;
543 }539 }
544 iio_triggered_buffer_predisable(indio_dev);
545 return ret;540 return ret;
546 }541 }
547 542
@@ -555,7 +550,6 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev) · 7 unmodified lines
555 mutex_unlock(&dln2->mutex);550 mutex_unlock(&dln2->mutex);
556 if (ret < 0) {551 if (ret < 0) {
557 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);552 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
558 iio_triggered_buffer_predisable(indio_dev);
559 return ret;553 return ret;
560 }554 }
561 } else {555 } else {
@@ -568,7 +562,7 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev) · 6 unmodified lines
568 562
569static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev)563static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev)
570{564{
571 int ret, ret2;565 int ret;
572 struct dln2_adc *dln2 = iio_priv(indio_dev);566 struct dln2_adc *dln2 = iio_priv(indio_dev);
573 567
574 mutex_lock(&dln2->mutex);568 mutex_lock(&dln2->mutex);
@@ -586,10 +580,6 @@ static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev) · 11 unmodified lines
586 if (ret < 0)580 if (ret < 0)
587 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);581 dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
588 582
589 ret2 = iio_triggered_buffer_predisable(indio_dev);
590 if (ret == 0)
591 ret = ret2;
592
593 return ret;583 return ret;
594}584}
595 585
@@ -652,7 +642,6 @@ static int dln2_adc_probe(struct platform_device *pdev) · 56 unmodified lines
652 IIO_CHAN_SOFT_TIMESTAMP_ASSIGN(dln2->iio_channels[i], i);642 IIO_CHAN_SOFT_TIMESTAMP_ASSIGN(dln2->iio_channels[i], i);
653 643
654 indio_dev->name = DLN2_ADC_MOD_NAME;644 indio_dev->name = DLN2_ADC_MOD_NAME;
655 indio_dev->dev.parent = dev;
656 indio_dev->info = &dln2_adc_info;645 indio_dev->info = &dln2_adc_info;
657 indio_dev->modes = INDIO_DIRECT_MODE;646 indio_dev->modes = INDIO_DIRECT_MODE;
658 indio_dev->channels = dln2->iio_channels;647 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
343 INIT_DELAYED_WORK(&env->comp_timeout, envelope_detector_timeout);343 INIT_DELAYED_WORK(&env->comp_timeout, envelope_detector_timeout);
344 344
345 indio_dev->name = dev_name(dev);345 indio_dev->name = dev_name(dev);
346 indio_dev->dev.parent = dev;
347 indio_dev->dev.of_node = dev->of_node;
348 indio_dev->info = &envelope_detector_info;346 indio_dev->info = &envelope_detector_info;
349 indio_dev->channels = &envelope_detector_iio_channel;347 indio_dev->channels = &envelope_detector_iio_channel;
350 indio_dev->num_channels = 1;348 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
170 return PTR_ERR(priv->base);170 return PTR_ERR(priv->base);
171 }171 }
172 172
173 iiodev->dev.parent = &pdev->dev;
174 iiodev->name = dev_name(&pdev->dev);173 iiodev->name = dev_name(&pdev->dev);
175 iiodev->modes = INDIO_DIRECT_MODE;174 iiodev->modes = INDIO_DIRECT_MODE;
176 iiodev->info = &ep93xx_adc_info;175 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
867 platform_set_drvdata(pdev, indio_dev);867 platform_set_drvdata(pdev, indio_dev);
868 868
869 indio_dev->name = dev_name(&pdev->dev);869 indio_dev->name = dev_name(&pdev->dev);
870 indio_dev->dev.parent = &pdev->dev;
871 indio_dev->dev.of_node = pdev->dev.of_node;
872 indio_dev->info = &exynos_adc_iio_info;870 indio_dev->info = &exynos_adc_iio_info;
873 indio_dev->modes = INDIO_DIRECT_MODE;871 indio_dev->modes = INDIO_DIRECT_MODE;
874 indio_dev->channels = exynos_adc_iio_channels;872 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
350 goto err_clk_unprepare;350 goto err_clk_unprepare;
351 }351 }
352 352
353 indio_dev->dev.parent = &pdev->dev;
354 indio_dev->channels = mx25_gcq_channels;353 indio_dev->channels = mx25_gcq_channels;
355 indio_dev->num_channels = ARRAY_SIZE(mx25_gcq_channels);354 indio_dev->num_channels = ARRAY_SIZE(mx25_gcq_channels);
356 indio_dev->info = &mx25_gcq_iio_info;355 indio_dev->info = &mx25_gcq_iio_info;
drivers/iio/adc/hi8435.c+2−6
@@ -15,9 +15,7 @@ · 14 unmodified lines
15#include <linux/iio/triggered_event.h>15#include <linux/iio/triggered_event.h>
16#include <linux/interrupt.h>16#include <linux/interrupt.h>
17#include <linux/module.h>17#include <linux/module.h>
18#include <linux/of.h>18#include <linux/mod_devicetable.h>
19#include <linux/of_device.h>
20#include <linux/of_gpio.h>
21#include <linux/spi/spi.h>19#include <linux/spi/spi.h>
22#include <linux/gpio/consumer.h>20#include <linux/gpio/consumer.h>
23 21
@@ -488,8 +486,6 @@ static int hi8435_probe(struct spi_device *spi) · 464 unmodified lines
488 spi_set_drvdata(spi, idev);486 spi_set_drvdata(spi, idev);
489 mutex_init(&priv->lock);487 mutex_init(&priv->lock);
490 488
491 idev->dev.parent = &spi->dev;
492 idev->dev.of_node = spi->dev.of_node;
493 idev->name = spi_get_device_id(spi)->name;489 idev->name = spi_get_device_id(spi)->name;
494 idev->modes = INDIO_DIRECT_MODE;490 idev->modes = INDIO_DIRECT_MODE;
495 idev->info = &hi8435_info;491 idev->info = &hi8435_info;
@@ -542,7 +538,7 @@ MODULE_DEVICE_TABLE(spi, hi8435_id); · 46 unmodified lines
542static struct spi_driver hi8435_driver = {538static struct spi_driver hi8435_driver = {
543 .driver = {539 .driver = {
544 .name = DRV_NAME,540 .name = DRV_NAME,
545 .of_match_table = of_match_ptr(hi8435_dt_ids),541 .of_match_table = hi8435_dt_ids,
546 },542 },
547 .probe = hi8435_probe,543 .probe = hi8435_probe,
548 .id_table = hi8435_id,544 .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
551 platform_set_drvdata(pdev, indio_dev);551 platform_set_drvdata(pdev, indio_dev);
552 552
553 indio_dev->name = "hx711";553 indio_dev->name = "hx711";
554 indio_dev->dev.parent = &pdev->dev;
555 indio_dev->info = &hx711_iio_info;554 indio_dev->info = &hx711_iio_info;
556 indio_dev->modes = INDIO_DIRECT_MODE;555 indio_dev->modes = INDIO_DIRECT_MODE;
557 indio_dev->channels = hx711_chan_spec;556 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
515 init_completion(&info->completion);515 init_completion(&info->completion);
516 516
517 indio_dev->name = dev_name(dev);517 indio_dev->name = dev_name(dev);
518 indio_dev->dev.parent = dev;
519 indio_dev->info = &imx7d_adc_iio_info;518 indio_dev->info = &imx7d_adc_iio_info;
520 indio_dev->modes = INDIO_DIRECT_MODE;519 indio_dev->modes = INDIO_DIRECT_MODE;
521 indio_dev->channels = imx7d_adc_iio_channels;520 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
273 * Available averaging rates for ina226. The indices correspond with273 * Available averaging rates for ina226. The indices correspond with
274 * the bit values expected by the chip (according to the ina226 datasheet,274 * the bit values expected by the chip (according to the ina226 datasheet,
275 * table 3 AVG bit settings, found at275 * 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.
277 */277 */
278static const int ina226_avg_tab[] = { 1, 4, 16, 64, 128, 256, 512, 1024 };278static const int ina226_avg_tab[] = { 1, 4, 16, 64, 128, 256, 512, 1024 };
279 279
@@ -1015,8 +1015,6 @@ static int ina2xx_probe(struct i2c_client *client, · 735 unmodified lines
1015 }1015 }
1016 1016
1017 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;1017 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;
1020 if (id->driver_data == ina226) {1018 if (id->driver_data == ina226) {
1021 indio_dev->channels = ina226_channels;1019 indio_dev->channels = ina226_channels;
1022 indio_dev->num_channels = ARRAY_SIZE(ina226_channels);1020 indio_dev->num_channels = ARRAY_SIZE(ina226_channels);
drivers/iio/adc/ingenic-adc.c+2−4
@@ -13,6 +13,7 @@ · 12 unmodified lines
13#include <linux/iopoll.h>13#include <linux/iopoll.h>
14#include <linux/kernel.h>14#include <linux/kernel.h>
15#include <linux/module.h>15#include <linux/module.h>
16#include <linux/mod_devicetable.h>
16#include <linux/mutex.h>17#include <linux/mutex.h>
17#include <linux/platform_device.h>18#include <linux/platform_device.h>
18 19
@@ -481,7 +482,6 @@ static int ingenic_adc_probe(struct platform_device *pdev) · 462 unmodified lines
481 return ret;482 return ret;
482 }483 }
483 484
484 iio_dev->dev.parent = dev;
485 iio_dev->name = "jz-adc";485 iio_dev->name = "jz-adc";
486 iio_dev->modes = INDIO_DIRECT_MODE;486 iio_dev->modes = INDIO_DIRECT_MODE;
487 iio_dev->channels = ingenic_channels;487 iio_dev->channels = ingenic_channels;
@@ -498,7 +498,6 @@ static int ingenic_adc_probe(struct platform_device *pdev) · 10 unmodified lines
498 return ret;498 return ret;
499}499}
500 500
501#ifdef CONFIG_OF
502static const struct of_device_id ingenic_adc_of_match[] = {501static const struct of_device_id ingenic_adc_of_match[] = {
503 { .compatible = "ingenic,jz4725b-adc", .data = &jz4725b_adc_soc_data, },502 { .compatible = "ingenic,jz4725b-adc", .data = &jz4725b_adc_soc_data, },
504 { .compatible = "ingenic,jz4740-adc", .data = &jz4740_adc_soc_data, },503 { .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
506 { },505 { },
507};506};
508MODULE_DEVICE_TABLE(of, ingenic_adc_of_match);507MODULE_DEVICE_TABLE(of, ingenic_adc_of_match);
509#endif
510 508
511static struct platform_driver ingenic_adc_driver = {509static struct platform_driver ingenic_adc_driver = {
512 .driver = {510 .driver = {
513 .name = "ingenic-adc",511 .name = "ingenic-adc",
514 .of_match_table = of_match_ptr(ingenic_adc_of_match),512 .of_match_table = ingenic_adc_of_match,
515 },513 },
516 .probe = ingenic_adc_probe,514 .probe = ingenic_adc_probe,
517};515};
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
207 207
208 platform_set_drvdata(pdev, indio_dev);208 platform_set_drvdata(pdev, indio_dev);
209 209
210 indio_dev->dev.parent = dev;
211 indio_dev->name = pdev->name;210 indio_dev->name = pdev->name;
212 211
213 indio_dev->channels = mrfld_adc_channels;212 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
198 adc->lp = lp;198 adc->lp = lp;
199 platform_set_drvdata(pdev, indio_dev);199 platform_set_drvdata(pdev, indio_dev);
200 200
201 indio_dev->dev.of_node = pdev->dev.of_node;
202 ret = lp8788_iio_map_register(indio_dev, lp->pdata, adc);201 ret = lp8788_iio_map_register(indio_dev, lp->pdata, adc);
203 if (ret)202 if (ret)
204 return ret;203 return ret;
205 204
206 mutex_init(&adc->lock);205 mutex_init(&adc->lock);
207 206
208 indio_dev->dev.parent = &pdev->dev;
209 indio_dev->name = pdev->name;207 indio_dev->name = pdev->name;
210 indio_dev->modes = INDIO_DIRECT_MODE;208 indio_dev->modes = INDIO_DIRECT_MODE;
211 indio_dev->info = &lp8788_adc_info;209 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
152 }152 }
153 153
154 indio_dev->name = dev_name(&pdev->dev);154 indio_dev->name = dev_name(&pdev->dev);
155 indio_dev->dev.parent = &pdev->dev;
156 indio_dev->info = &lpc18xx_adc_info;155 indio_dev->info = &lpc18xx_adc_info;
157 indio_dev->modes = INDIO_DIRECT_MODE;156 indio_dev->modes = INDIO_DIRECT_MODE;
158 indio_dev->channels = lpc18xx_adc_iio_channels;157 indio_dev->channels = lpc18xx_adc_iio_channels;
drivers/iio/adc/lpc32xx_adc.c+2−4
@@ -14,6 +14,7 @@ · 13 unmodified lines
14#include <linux/interrupt.h>14#include <linux/interrupt.h>
15#include <linux/io.h>15#include <linux/io.h>
16#include <linux/module.h>16#include <linux/module.h>
17#include <linux/mod_devicetable.h>
17#include <linux/platform_device.h>18#include <linux/platform_device.h>
18#include <linux/regulator/consumer.h>19#include <linux/regulator/consumer.h>
19 20
@@ -196,7 +197,6 @@ static int lpc32xx_adc_probe(struct platform_device *pdev) · 176 unmodified lines
196 init_completion(&st->completion);197 init_completion(&st->completion);
197 198
198 iodev->name = LPC32XXAD_NAME;199 iodev->name = LPC32XXAD_NAME;
199 iodev->dev.parent = &pdev->dev;
200 iodev->info = &lpc32xx_adc_iio_info;200 iodev->info = &lpc32xx_adc_iio_info;
201 iodev->modes = INDIO_DIRECT_MODE;201 iodev->modes = INDIO_DIRECT_MODE;
202 iodev->num_channels = ARRAY_SIZE(lpc32xx_adc_iio_channels);202 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
210 return 0;210 return 0;
211}211}
212 212
213#ifdef CONFIG_OF
214static const struct of_device_id lpc32xx_adc_match[] = {213static const struct of_device_id lpc32xx_adc_match[] = {
215 { .compatible = "nxp,lpc3220-adc" },214 { .compatible = "nxp,lpc3220-adc" },
216 {},215 {},
217};216};
218MODULE_DEVICE_TABLE(of, lpc32xx_adc_match);217MODULE_DEVICE_TABLE(of, lpc32xx_adc_match);
219#endif
220 218
221static struct platform_driver lpc32xx_adc_driver = {219static struct platform_driver lpc32xx_adc_driver = {
222 .probe = lpc32xx_adc_probe,220 .probe = lpc32xx_adc_probe,
223 .driver = {221 .driver = {
224 .name = LPC32XXAD_NAME,222 .name = LPC32XXAD_NAME,
225 .of_match_table = of_match_ptr(lpc32xx_adc_match),223 .of_match_table = lpc32xx_adc_match,
226 },224 },
227};225};
228 226
drivers/iio/adc/ltc2471.c+0−1
@@ -116,7 +116,6 @@ static int ltc2471_i2c_probe(struct i2c_client *client, · 115 unmodified lines
116 data = iio_priv(indio_dev);116 data = iio_priv(indio_dev);
117 data->client = client;117 data->client = client;
118 118
119 indio_dev->dev.parent = &client->dev;
120 indio_dev->name = id->name;119 indio_dev->name = id->name;
121 indio_dev->info = &ltc2471_info;120 indio_dev->info = &ltc2471_info;
122 indio_dev->modes = INDIO_DIRECT_MODE;121 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
108 i2c_set_clientdata(client, indio_dev);108 i2c_set_clientdata(client, indio_dev);
109 data->client = client;109 data->client = client;
110 110
111 indio_dev->dev.parent = &client->dev;
112 indio_dev->name = id->name;111 indio_dev->name = id->name;
113 indio_dev->info = &ltc2485_info;112 indio_dev->info = &ltc2485_info;
114 indio_dev->modes = INDIO_DIRECT_MODE;113 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/ltc2496.c+2−2
@@ -14,7 +14,7 @@ · 13 unmodified lines
14#include <linux/iio/iio.h>14#include <linux/iio/iio.h>
15#include <linux/iio/driver.h>15#include <linux/iio/driver.h>
16#include <linux/module.h>16#include <linux/module.h>
17#include <linux/of.h>17#include <linux/mod_devicetable.h>
18 18
19#include "ltc2497.h"19#include "ltc2497.h"
20 20
@@ -96,7 +96,7 @@ MODULE_DEVICE_TABLE(of, ltc2496_of_match); · 75 unmodified lines
96static struct spi_driver ltc2496_driver = {96static struct spi_driver ltc2496_driver = {
97 .driver = {97 .driver = {
98 .name = "ltc2496",98 .name = "ltc2496",
99 .of_match_table = of_match_ptr(ltc2496_of_match),99 .of_match_table = ltc2496_of_match,
100 },100 },
101 .probe = ltc2496_probe,101 .probe = ltc2496_probe,
102 .remove = ltc2496_remove,102 .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
169 struct ltc2497core_driverdata *ddata = iio_priv(indio_dev);169 struct ltc2497core_driverdata *ddata = iio_priv(indio_dev);
170 int ret;170 int ret;
171 171
172 indio_dev->dev.parent = dev;
173 indio_dev->name = dev_name(dev);172 indio_dev->name = dev_name(dev);
174 indio_dev->info = &ltc2497core_info;173 indio_dev->info = &ltc2497core_info;
175 indio_dev->modes = INDIO_DIRECT_MODE;174 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/adc/ltc2497.c+2−2
@@ -11,7 +11,7 @@ · 10 unmodified lines
11#include <linux/iio/iio.h>11#include <linux/iio/iio.h>
12#include <linux/iio/driver.h>12#include <linux/iio/driver.h>
13#include <linux/module.h>13#include <linux/module.h>
14#include <linux/of.h>14#include <linux/mod_devicetable.h>
15 15
16#include "ltc2497.h"16#include "ltc2497.h"
17 17
@@ -98,7 +98,7 @@ MODULE_DEVICE_TABLE(of, ltc2497_of_match); · 80 unmodified lines
98static struct i2c_driver ltc2497_driver = {98static struct i2c_driver ltc2497_driver = {
99 .driver = {99 .driver = {
100 .name = "ltc2497",100 .name = "ltc2497",
101 .of_match_table = of_match_ptr(ltc2497_of_match),101 .of_match_table = ltc2497_of_match,
102 },102 },
103 .probe = ltc2497_probe,103 .probe = ltc2497_probe,
104 .remove = ltc2497_remove,104 .remove = ltc2497_remove,
drivers/iio/adc/max1027.c+2−5
@@ -14,6 +14,7 @@ · 13 unmodified lines
14 14
15#include <linux/kernel.h>15#include <linux/kernel.h>
16#include <linux/module.h>16#include <linux/module.h>
17#include <linux/mod_devicetable.h>
17#include <linux/spi/spi.h>18#include <linux/spi/spi.h>
18#include <linux/delay.h>19#include <linux/delay.h>
19 20
@@ -79,7 +80,6 @@ static const struct spi_device_id max1027_id[] = { · 59 unmodified lines
79};80};
80MODULE_DEVICE_TABLE(spi, max1027_id);81MODULE_DEVICE_TABLE(spi, max1027_id);
81 82
82#ifdef CONFIG_OF
83static const struct of_device_id max1027_adc_dt_ids[] = {83static const struct of_device_id max1027_adc_dt_ids[] = {
84 { .compatible = "maxim,max1027" },84 { .compatible = "maxim,max1027" },
85 { .compatible = "maxim,max1029" },85 { .compatible = "maxim,max1029" },
@@ -90,7 +90,6 @@ static const struct of_device_id max1027_adc_dt_ids[] = { · 4 unmodified lines
90 {},90 {},
91};91};
92MODULE_DEVICE_TABLE(of, max1027_adc_dt_ids);92MODULE_DEVICE_TABLE(of, max1027_adc_dt_ids);
93#endif
94 93
95#define MAX1027_V_CHAN(index, depth) \94#define MAX1027_V_CHAN(index, depth) \
96 { \95 { \
@@ -440,8 +439,6 @@ static int max1027_probe(struct spi_device *spi) · 343 unmodified lines
440 mutex_init(&st->lock);439 mutex_init(&st->lock);
441 440
442 indio_dev->name = spi_get_device_id(spi)->name;441 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;
445 indio_dev->info = &max1027_info;442 indio_dev->info = &max1027_info;
446 indio_dev->modes = INDIO_DIRECT_MODE;443 indio_dev->modes = INDIO_DIRECT_MODE;
447 indio_dev->channels = st->info->channels;444 indio_dev->channels = st->info->channels;
@@ -520,7 +517,7 @@ static int max1027_probe(struct spi_device *spi) · 72 unmodified lines
520static struct spi_driver max1027_driver = {517static struct spi_driver max1027_driver = {
521 .driver = {518 .driver = {
522 .name = "max1027",519 .name = "max1027",
523 .of_match_table = of_match_ptr(max1027_adc_dt_ids),520 .of_match_table = max1027_adc_dt_ids,
524 },521 },
525 .probe = max1027_probe,522 .probe = max1027_probe,
526 .id_table = max1027_id,523 .id_table = max1027_id,
drivers/iio/adc/max11100.c+3−4
@@ -8,6 +8,7 @@ · 7 unmodified lines
8 */8 */
9#include <linux/delay.h>9#include <linux/delay.h>
10#include <linux/kernel.h>10#include <linux/kernel.h>
11#include <linux/mod_devicetable.h>
11#include <linux/module.h>12#include <linux/module.h>
12#include <linux/regulator/consumer.h>13#include <linux/regulator/consumer.h>
13#include <linux/spi/spi.h>14#include <linux/spi/spi.h>
@@ -37,7 +38,7 @@ struct max11100_state { · 23 unmodified lines
37 u8 buffer[3] ____cacheline_aligned;38 u8 buffer[3] ____cacheline_aligned;
38};39};
39 40
40static struct iio_chan_spec max11100_channels[] = {41static const struct iio_chan_spec max11100_channels[] = {
41 { /* [0] */42 { /* [0] */
42 .type = IIO_VOLTAGE,43 .type = IIO_VOLTAGE,
43 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |44 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
@@ -115,8 +116,6 @@ static int max11100_probe(struct spi_device *spi) · 71 unmodified lines
115 state = iio_priv(indio_dev);116 state = iio_priv(indio_dev);
116 state->spi = spi;117 state->spi = spi;
117 118
118 indio_dev->dev.parent = &spi->dev;
119 indio_dev->dev.of_node = spi->dev.of_node;
120 indio_dev->name = "max11100";119 indio_dev->name = "max11100";
121 indio_dev->info = &max11100_info;120 indio_dev->info = &max11100_info;
122 indio_dev->modes = INDIO_DIRECT_MODE;121 indio_dev->modes = INDIO_DIRECT_MODE;
@@ -163,7 +162,7 @@ MODULE_DEVICE_TABLE(of, max11100_ids); · 40 unmodified lines
163static struct spi_driver max11100_driver = {162static struct spi_driver max11100_driver = {
164 .driver = {163 .driver = {
165 .name = "max11100",164 .name = "max11100",
166 .of_match_table = of_match_ptr(max11100_ids),165 .of_match_table = max11100_ids,
167 },166 },
168 .probe = max11100_probe,167 .probe = max11100_probe,
169 .remove = max11100_remove,168 .remove = max11100_remove,
drivers/iio/adc/max1118.c+2−6
@@ -18,6 +18,7 @@ · 17 unmodified lines
18 */18 */
19 19
20#include <linux/module.h>20#include <linux/module.h>
21#include <linux/mod_devicetable.h>
21#include <linux/spi/spi.h>22#include <linux/spi/spi.h>
22#include <linux/iio/iio.h>23#include <linux/iio/iio.h>
23#include <linux/iio/buffer.h>24#include <linux/iio/buffer.h>
@@ -225,7 +226,6 @@ static int max1118_probe(struct spi_device *spi) · 201 unmodified lines
225 spi_set_drvdata(spi, indio_dev);226 spi_set_drvdata(spi, indio_dev);
226 227
227 indio_dev->name = spi_get_device_id(spi)->name;228 indio_dev->name = spi_get_device_id(spi)->name;
228 indio_dev->dev.parent = &spi->dev;
229 indio_dev->info = &max1118_info;229 indio_dev->info = &max1118_info;
230 indio_dev->modes = INDIO_DIRECT_MODE;230 indio_dev->modes = INDIO_DIRECT_MODE;
231 indio_dev->channels = max1118_channels;231 indio_dev->channels = max1118_channels;
@@ -281,8 +281,6 @@ static const struct spi_device_id max1118_id[] = { · 49 unmodified lines
281};281};
282MODULE_DEVICE_TABLE(spi, max1118_id);282MODULE_DEVICE_TABLE(spi, max1118_id);
283 283
284#ifdef CONFIG_OF
285
286static const struct of_device_id max1118_dt_ids[] = {284static const struct of_device_id max1118_dt_ids[] = {
287 { .compatible = "maxim,max1117" },285 { .compatible = "maxim,max1117" },
288 { .compatible = "maxim,max1118" },286 { .compatible = "maxim,max1118" },
@@ -291,12 +289,10 @@ static const struct of_device_id max1118_dt_ids[] = { · 2 unmodified lines
291};289};
292MODULE_DEVICE_TABLE(of, max1118_dt_ids);290MODULE_DEVICE_TABLE(of, max1118_dt_ids);
293 291
294#endif
295
296static struct spi_driver max1118_spi_driver = {292static struct spi_driver max1118_spi_driver = {
297 .driver = {293 .driver = {
298 .name = "max1118",294 .name = "max1118",
299 .of_match_table = of_match_ptr(max1118_dt_ids),295 .of_match_table = max1118_dt_ids,
300 },296 },
301 .probe = max1118_probe,297 .probe = max1118_probe,
302 .remove = max1118_remove,298 .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
192 dev_dbg(dev, "no shutdown pin passed, low-power mode disabled");192 dev_dbg(dev, "no shutdown pin passed, low-power mode disabled");
193 193
194 indio_dev->name = spi_get_device_id(spi)->name;194 indio_dev->name = spi_get_device_id(spi)->name;
195 indio_dev->dev.parent = dev;
196 indio_dev->info = &max1241_info;195 indio_dev->info = &max1241_info;
197 indio_dev->modes = INDIO_DIRECT_MODE;196 indio_dev->modes = INDIO_DIRECT_MODE;
198 indio_dev->channels = max1241_channels;197 indio_dev->channels = max1241_channels;
drivers/iio/adc/max1363.c+4−11
@@ -22,8 +22,8 @@ · 21 unmodified lines
22#include <linux/slab.h>22#include <linux/slab.h>
23#include <linux/err.h>23#include <linux/err.h>
24#include <linux/module.h>24#include <linux/module.h>
25#include <linux/of.h>25#include <linux/mod_devicetable.h>
26#include <linux/of_device.h>26#include <linux/property.h>
27 27
28#include <linux/iio/iio.h>28#include <linux/iio/iio.h>
29#include <linux/iio/sysfs.h>29#include <linux/iio/sysfs.h>
@@ -1529,8 +1529,6 @@ done: · 1499 unmodified lines
1529 return IRQ_HANDLED;1529 return IRQ_HANDLED;
1530}1530}
1531 1531
1532#ifdef CONFIG_OF
1533
1534#define MAX1363_COMPATIBLE(of_compatible, cfg) { \1532#define MAX1363_COMPATIBLE(of_compatible, cfg) { \
1535 .compatible = of_compatible, \1533 .compatible = of_compatible, \
1536 .data = &max1363_chip_info_tbl[cfg], \1534 .data = &max1363_chip_info_tbl[cfg], \
@@ -1578,7 +1576,6 @@ static const struct of_device_id max1363_of_match[] = { · 41 unmodified lines
1578 { /* sentinel */ }1576 { /* sentinel */ }
1579};1577};
1580MODULE_DEVICE_TABLE(of, max1363_of_match);1578MODULE_DEVICE_TABLE(of, max1363_of_match);
1581#endif
1582 1579
1583static int max1363_probe(struct i2c_client *client,1580static int max1363_probe(struct i2c_client *client,
1584 const struct i2c_device_id *id)1581 const struct i2c_device_id *id)
@@ -1593,7 +1590,6 @@ static int max1363_probe(struct i2c_client *client, · 8 unmodified lines
1593 if (!indio_dev)1590 if (!indio_dev)
1594 return -ENOMEM;1591 return -ENOMEM;
1595 1592
1596 indio_dev->dev.of_node = client->dev.of_node;
1597 ret = iio_map_array_register(indio_dev, client->dev.platform_data);1593 ret = iio_map_array_register(indio_dev, client->dev.platform_data);
1598 if (ret < 0)1594 if (ret < 0)
1599 return ret;1595 return ret;
@@ -1614,7 +1610,7 @@ static int max1363_probe(struct i2c_client *client, · 14 unmodified lines
1614 /* this is only used for device removal purposes */1610 /* this is only used for device removal purposes */
1615 i2c_set_clientdata(client, indio_dev);1611 i2c_set_clientdata(client, indio_dev);
1616 1612
1617 st->chip_info = of_device_get_match_data(&client->dev);1613 st->chip_info = device_get_match_data(&client->dev);
1618 if (!st->chip_info)1614 if (!st->chip_info)
1619 st->chip_info = &max1363_chip_info_tbl[id->driver_data];1615 st->chip_info = &max1363_chip_info_tbl[id->driver_data];
1620 st->client = client;1616 st->client = client;
@@ -1652,9 +1648,6 @@ static int max1363_probe(struct i2c_client *client, · 31 unmodified lines
1652 if (ret)1648 if (ret)
1653 goto error_disable_reg;1649 goto error_disable_reg;
1654 1650
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;
1658 indio_dev->name = id->name;1651 indio_dev->name = id->name;
1659 indio_dev->channels = st->chip_info->channels;1652 indio_dev->channels = st->chip_info->channels;
1660 indio_dev->num_channels = st->chip_info->num_channels;1653 indio_dev->num_channels = st->chip_info->num_channels;
@@ -1760,7 +1753,7 @@ MODULE_DEVICE_TABLE(i2c, max1363_id); · 99 unmodified lines
1760static struct i2c_driver max1363_driver = {1753static struct i2c_driver max1363_driver = {
1761 .driver = {1754 .driver = {
1762 .name = "max1363",1755 .name = "max1363",
1763 .of_match_table = of_match_ptr(max1363_of_match),1756 .of_match_table = max1363_of_match,
1764 },1757 },
1765 .probe = max1363_probe,1758 .probe = max1363_probe,
1766 .remove = max1363_remove,1759 .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
545 if (ret)545 if (ret)
546 return ret;546 return ret;
547 547
548 indio_dev->dev.parent = &client->dev;
549 indio_dev->dev.of_node = client->dev.of_node;
550 indio_dev->name = of_id->data;548 indio_dev->name = of_id->data;
551 indio_dev->modes = INDIO_DIRECT_MODE;549 indio_dev->modes = INDIO_DIRECT_MODE;
552 indio_dev->info = &indio_info;550 indio_dev->info = &indio_info;
drivers/iio/adc/mcp320x.c+6−9
@@ -27,13 +27,13 @@ · 26 unmodified lines
27 * MCP355327 * MCP3553
28 *28 *
29 * Datasheet can be found here:29 * Datasheet can be found here:
30 * http://ww1.microchip.com/downloads/en/DeviceDoc/21293C.pdf mcp300130 * https://ww1.microchip.com/downloads/en/DeviceDoc/21293C.pdf mcp3001
31 * http://ww1.microchip.com/downloads/en/DeviceDoc/21294E.pdf mcp300231 * https://ww1.microchip.com/downloads/en/DeviceDoc/21294E.pdf mcp3002
32 * http://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf mcp3004/0832 * https://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf mcp3004/08
33 * http://ww1.microchip.com/downloads/en/DeviceDoc/21290D.pdf mcp320133 * http://ww1.microchip.com/downloads/en/DeviceDoc/21290D.pdf mcp3201
34 * http://ww1.microchip.com/downloads/en/DeviceDoc/21034D.pdf mcp320234 * http://ww1.microchip.com/downloads/en/DeviceDoc/21034D.pdf mcp3202
35 * http://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf mcp3204/0835 * http://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf mcp3204/08
36 * http://ww1.microchip.com/downloads/en/DeviceDoc/21700E.pdf mcp330136 * https://ww1.microchip.com/downloads/en/DeviceDoc/21700E.pdf mcp3301
37 * http://ww1.microchip.com/downloads/en/DeviceDoc/21950D.pdf mcp3550/1/337 * http://ww1.microchip.com/downloads/en/DeviceDoc/21950D.pdf mcp3550/1/3
38 */38 */
39 39
@@ -41,6 +41,7 @@ · 1 unmodified line
41#include <linux/delay.h>41#include <linux/delay.h>
42#include <linux/spi/spi.h>42#include <linux/spi/spi.h>
43#include <linux/module.h>43#include <linux/module.h>
44#include <linux/mod_devicetable.h>
44#include <linux/iio/iio.h>45#include <linux/iio/iio.h>
45#include <linux/regulator/consumer.h>46#include <linux/regulator/consumer.h>
46 47
@@ -384,8 +385,6 @@ static int mcp320x_probe(struct spi_device *spi) · 337 unmodified lines
384 adc = iio_priv(indio_dev);385 adc = iio_priv(indio_dev);
385 adc->spi = spi;386 adc->spi = spi;
386 387
387 indio_dev->dev.parent = &spi->dev;
388 indio_dev->dev.of_node = spi->dev.of_node;
389 indio_dev->name = spi_get_device_id(spi)->name;388 indio_dev->name = spi_get_device_id(spi)->name;
390 indio_dev->modes = INDIO_DIRECT_MODE;389 indio_dev->modes = INDIO_DIRECT_MODE;
391 indio_dev->info = &mcp320x_info;390 indio_dev->info = &mcp320x_info;
@@ -471,7 +470,6 @@ static int mcp320x_remove(struct spi_device *spi) · 79 unmodified lines
471 return 0;470 return 0;
472}471}
473 472
474#if defined(CONFIG_OF)
475static const struct of_device_id mcp320x_dt_ids[] = {473static const struct of_device_id mcp320x_dt_ids[] = {
476 /* NOTE: The use of compatibles with no vendor prefix is deprecated. */474 /* NOTE: The use of compatibles with no vendor prefix is deprecated. */
477 { .compatible = "mcp3001" },475 { .compatible = "mcp3001" },
@@ -499,7 +497,6 @@ static const struct of_device_id mcp320x_dt_ids[] = { · 21 unmodified lines
499 { }497 { }
500};498};
501MODULE_DEVICE_TABLE(of, mcp320x_dt_ids);499MODULE_DEVICE_TABLE(of, mcp320x_dt_ids);
502#endif
503 500
504static const struct spi_device_id mcp320x_id[] = {501static const struct spi_device_id mcp320x_id[] = {
505 { "mcp3001", mcp3001 },502 { "mcp3001", mcp3001 },
@@ -522,7 +519,7 @@ MODULE_DEVICE_TABLE(spi, mcp320x_id); · 16 unmodified lines
522static struct spi_driver mcp320x_driver = {519static struct spi_driver mcp320x_driver = {
523 .driver = {520 .driver = {
524 .name = "mcp320x",521 .name = "mcp320x",
525 .of_match_table = of_match_ptr(mcp320x_dt_ids),522 .of_match_table = mcp320x_dt_ids,
526 },523 },
527 .probe = mcp320x_probe,524 .probe = mcp320x_probe,
528 .remove = mcp320x_remove,525 .remove = mcp320x_remove,
drivers/iio/adc/mcp3422.c+4−8
@@ -6,8 +6,8 @@ · 5 unmodified lines
6 * Author: Angelo Compagnucci <angelo.compagnucci@gmail.com>6 * Author: Angelo Compagnucci <angelo.compagnucci@gmail.com>
7 *7 *
8 * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/22088b.pdf8 * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/22088b.pdf
9 * http://ww1.microchip.com/downloads/en/DeviceDoc/22226a.pdf9 * https://ww1.microchip.com/downloads/en/DeviceDoc/22226a.pdf
10 * http://ww1.microchip.com/downloads/en/DeviceDoc/22072b.pdf10 * https://ww1.microchip.com/downloads/en/DeviceDoc/22072b.pdf
11 *11 *
12 * This driver exports the value of analog input voltage to sysfs, the12 * This driver exports the value of analog input voltage to sysfs, the
13 * voltage unit is nV.13 * voltage unit is nV.
@@ -16,9 +16,9 @@ · 2 unmodified lines
16#include <linux/err.h>16#include <linux/err.h>
17#include <linux/i2c.h>17#include <linux/i2c.h>
18#include <linux/module.h>18#include <linux/module.h>
19#include <linux/mod_devicetable.h>
19#include <linux/delay.h>20#include <linux/delay.h>
20#include <linux/sysfs.h>21#include <linux/sysfs.h>
21#include <linux/of.h>
22#include <asm/unaligned.h>22#include <asm/unaligned.h>
23 23
24#include <linux/iio/iio.h>24#include <linux/iio/iio.h>
@@ -347,8 +347,6 @@ static int mcp3422_probe(struct i2c_client *client, · 322 unmodified lines
347 347
348 mutex_init(&adc->lock);348 mutex_init(&adc->lock);
349 349
350 indio_dev->dev.parent = &client->dev;
351 indio_dev->dev.of_node = client->dev.of_node;
352 indio_dev->name = dev_name(&client->dev);350 indio_dev->name = dev_name(&client->dev);
353 indio_dev->modes = INDIO_DIRECT_MODE;351 indio_dev->modes = INDIO_DIRECT_MODE;
354 indio_dev->info = &mcp3422_info;352 indio_dev->info = &mcp3422_info;
@@ -404,18 +402,16 @@ static const struct i2c_device_id mcp3422_id[] = { · 49 unmodified lines
404};402};
405MODULE_DEVICE_TABLE(i2c, mcp3422_id);403MODULE_DEVICE_TABLE(i2c, mcp3422_id);
406 404
407#ifdef CONFIG_OF
408static const struct of_device_id mcp3422_of_match[] = {405static const struct of_device_id mcp3422_of_match[] = {
409 { .compatible = "mcp3422" },406 { .compatible = "mcp3422" },
410 { }407 { }
411};408};
412MODULE_DEVICE_TABLE(of, mcp3422_of_match);409MODULE_DEVICE_TABLE(of, mcp3422_of_match);
413#endif
414 410
415static struct i2c_driver mcp3422_driver = {411static struct i2c_driver mcp3422_driver = {
416 .driver = {412 .driver = {
417 .name = "mcp3422",413 .name = "mcp3422",
418 .of_match_table = of_match_ptr(mcp3422_of_match),414 .of_match_table = mcp3422_of_match,
419 },415 },
420 .probe = mcp3422_probe,416 .probe = mcp3422_probe,
421 .id_table = mcp3422_id,417 .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
293 if (ret)293 if (ret)
294 goto clk_disable;294 goto clk_disable;
295 295
296 indio_dev->dev.parent = &spi->dev;
297 indio_dev->dev.of_node = spi->dev.of_node;
298 indio_dev->name = spi_get_device_id(spi)->name;296 indio_dev->name = spi_get_device_id(spi)->name;
299 indio_dev->modes = INDIO_DIRECT_MODE;297 indio_dev->modes = INDIO_DIRECT_MODE;
300 indio_dev->info = &mcp3911_info;298 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
110 110
111 adc = iio_priv(indio_dev);111 adc = iio_priv(indio_dev);
112 indio_dev->name = "z188-adc";112 indio_dev->name = "z188-adc";
113 indio_dev->dev.parent = &dev->dev;
114 indio_dev->info = &z188_adc_info;113 indio_dev->info = &z188_adc_info;
115 indio_dev->modes = INDIO_DIRECT_MODE;114 indio_dev->modes = INDIO_DIRECT_MODE;
116 indio_dev->channels = z188_adc_iio_channels;115 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
1208 priv->param = match_data->param;1208 priv->param = match_data->param;
1209 1209
1210 indio_dev->name = match_data->name;1210 indio_dev->name = match_data->name;
1211 indio_dev->dev.parent = &pdev->dev;
1212 indio_dev->dev.of_node = pdev->dev.of_node;
1213 indio_dev->modes = INDIO_DIRECT_MODE;1211 indio_dev->modes = INDIO_DIRECT_MODE;
1214 indio_dev->info = &meson_sar_adc_iio_info;1212 indio_dev->info = &meson_sar_adc_iio_info;
1215 1213
drivers/iio/adc/mt6577_auxadc.c+0−1
@@ -245,7 +245,6 @@ static int mt6577_auxadc_probe(struct platform_device *pdev) · 244 unmodified lines
245 return -ENOMEM;245 return -ENOMEM;
246 246
247 adc_dev = iio_priv(indio_dev);247 adc_dev = iio_priv(indio_dev);
248 indio_dev->dev.parent = &pdev->dev;
249 indio_dev->name = dev_name(&pdev->dev);248 indio_dev->name = dev_name(&pdev->dev);
250 indio_dev->info = &mt6577_auxadc_info;249 indio_dev->info = &mt6577_auxadc_info;
251 indio_dev->modes = INDIO_DIRECT_MODE;250 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
568 568
569static const struct iio_buffer_setup_ops mxs_lradc_adc_buffer_ops = {569static const struct iio_buffer_setup_ops mxs_lradc_adc_buffer_ops = {
570 .preenable = &mxs_lradc_adc_buffer_preenable,570 .preenable = &mxs_lradc_adc_buffer_preenable,
571 .postenable = &iio_triggered_buffer_postenable,
572 .predisable = &iio_triggered_buffer_predisable,
573 .postdisable = &mxs_lradc_adc_buffer_postdisable,571 .postdisable = &mxs_lradc_adc_buffer_postdisable,
574 .validate_scan_mask = &mxs_lradc_adc_validate_scan_mask,572 .validate_scan_mask = &mxs_lradc_adc_validate_scan_mask,
575};573};
@@ -722,7 +720,6 @@ static int mxs_lradc_adc_probe(struct platform_device *pdev) · 146 unmodified lines
722 platform_set_drvdata(pdev, iio);720 platform_set_drvdata(pdev, iio);
723 721
724 iio->name = pdev->name;722 iio->name = pdev->name;
725 iio->dev.parent = dev;
726 iio->dev.of_node = dev->parent->of_node;723 iio->dev.of_node = dev->parent->of_node;
727 iio->info = &mxs_lradc_adc_iio_info;724 iio->info = &mxs_lradc_adc_iio_info;
728 iio->modes = INDIO_DIRECT_MODE;725 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
430 430
431 i2c_set_clientdata(client, indio_dev);431 i2c_set_clientdata(client, indio_dev);
432 432
433 indio_dev->dev.parent = &client->dev;
434 indio_dev->dev.of_node = client->dev.of_node;
435 indio_dev->name = dev_name(&client->dev);433 indio_dev->name = dev_name(&client->dev);
436 indio_dev->modes = INDIO_DIRECT_MODE;434 indio_dev->modes = INDIO_DIRECT_MODE;
437 indio_dev->info = &nau7802_info;435 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
261 261
262 platform_set_drvdata(pdev, indio_dev);262 platform_set_drvdata(pdev, indio_dev);
263 indio_dev->name = dev_name(&pdev->dev);263 indio_dev->name = dev_name(&pdev->dev);
264 indio_dev->dev.parent = &pdev->dev;
265 indio_dev->info = &npcm_adc_iio_info;264 indio_dev->info = &npcm_adc_iio_info;
266 indio_dev->modes = INDIO_DIRECT_MODE;265 indio_dev->modes = INDIO_DIRECT_MODE;
267 indio_dev->channels = npcm_adc_iio_channels;266 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
593 adc->extended_delay = gpadc_pdata->extended_delay;593 adc->extended_delay = gpadc_pdata->extended_delay;
594 594
595 indio_dev->name = MOD_NAME;595 indio_dev->name = MOD_NAME;
596 indio_dev->dev.parent = &pdev->dev;
597 indio_dev->info = &palmas_gpadc_iio_info;596 indio_dev->info = &palmas_gpadc_iio_info;
598 indio_dev->modes = INDIO_DIRECT_MODE;597 indio_dev->modes = INDIO_DIRECT_MODE;
599 indio_dev->channels = palmas_gpadc_iio_channel;598 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
933 goto out_disable_vref;933 goto out_disable_vref;
934 }934 }
935 935
936 indio_dev->dev.parent = dev;
937 indio_dev->dev.of_node = np;
938 indio_dev->name = variant->name;936 indio_dev->name = variant->name;
939 indio_dev->modes = INDIO_DIRECT_MODE;937 indio_dev->modes = INDIO_DIRECT_MODE;
940 indio_dev->info = &pm8xxx_xoadc_info;938 indio_dev->info = &pm8xxx_xoadc_info;
drivers/iio/adc/qcom-spmi-adc5.c+220−24
@@ -1,6 +1,6 @@
1// SPDX-License-Identifier: GPL-2.01// SPDX-License-Identifier: GPL-2.0
2/*2/*
3 * Copyright (c) 2018, The Linux Foundation. All rights reserved.3 * Copyright (c) 2018, 2020, The Linux Foundation. All rights reserved.
4 */4 */
5 5
6#include <linux/bitops.h>6#include <linux/bitops.h>
@@ -23,6 +23,7 @@ · 16 unmodified lines
23 23
24#define ADC5_USR_REVISION1 0x024#define ADC5_USR_REVISION1 0x0
25#define ADC5_USR_STATUS1 0x825#define ADC5_USR_STATUS1 0x8
26#define ADC5_USR_STATUS1_CONV_FAULT BIT(7)
26#define ADC5_USR_STATUS1_REQ_STS BIT(1)27#define ADC5_USR_STATUS1_REQ_STS BIT(1)
27#define ADC5_USR_STATUS1_EOC BIT(0)28#define ADC5_USR_STATUS1_EOC BIT(0)
28#define ADC5_USR_STATUS1_REQ_STS_EOC_MASK 0x329#define ADC5_USR_STATUS1_REQ_STS_EOC_MASK 0x3
@@ -65,6 +66,9 @@ · 36 unmodified lines
65 66
66#define ADC5_USR_IBAT_DATA1 0x5367#define ADC5_USR_IBAT_DATA1 0x53
67 68
69#define ADC_CHANNEL_OFFSET 0x8
70#define ADC_CHANNEL_MASK GENMASK(7, 0)
71
68/*72/*
69 * Conversion time varies based on the decimation, clock rate, fast average73 * Conversion time varies based on the decimation, clock rate, fast average
70 * samples and measurements queued across different VADC peripherals.74 * samples and measurements queued across different VADC peripherals.
@@ -79,6 +83,11 @@ · 8 unmodified lines
79#define ADC5_HW_SETTLE_DIFF_MINOR 383#define ADC5_HW_SETTLE_DIFF_MINOR 3
80#define ADC5_HW_SETTLE_DIFF_MAJOR 584#define ADC5_HW_SETTLE_DIFF_MAJOR 5
81 85
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
82enum adc5_cal_method {91enum adc5_cal_method {
83 ADC5_NO_CAL = 0,92 ADC5_NO_CAL = 0,
84 ADC5_RATIOMETRIC_CAL,93 ADC5_RATIOMETRIC_CAL,
@@ -96,6 +105,7 @@ enum adc5_cal_val { · 11 unmodified lines
96 * @cal_method: calibration method.105 * @cal_method: calibration method.
97 * @cal_val: calibration value106 * @cal_val: calibration value
98 * @decimation: sampling rate supported for the channel.107 * @decimation: sampling rate supported for the channel.
108 * @sid: slave id of PMIC owning the channel, for PMIC7.
99 * @prescale: channel scaling performed on the input signal.109 * @prescale: channel scaling performed on the input signal.
100 * @hw_settle_time: the time between AMUX being configured and the110 * @hw_settle_time: the time between AMUX being configured and the
101 * start of conversion.111 * start of conversion.
@@ -110,6 +120,7 @@ struct adc5_channel_prop { · 8 unmodified lines
110 enum adc5_cal_method cal_method;120 enum adc5_cal_method cal_method;
111 enum adc5_cal_val cal_val;121 enum adc5_cal_val cal_val;
112 unsigned int decimation;122 unsigned int decimation;
123 unsigned int sid;
113 unsigned int prescale;124 unsigned int prescale;
114 unsigned int hw_settle_time;125 unsigned int hw_settle_time;
115 unsigned int avg_samples;126 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
165 return regmap_bulk_write(adc->regmap, adc->base + offset, data, len);176 return regmap_bulk_write(adc->regmap, adc->base + offset, data, len);
166}177}
167 178
179static 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
168static int adc5_prescaling_from_dt(u32 num, u32 den)184static int adc5_prescaling_from_dt(u32 num, u32 den)
169{185{
170 unsigned int pre;186 unsigned int pre;
@@ -230,11 +246,11 @@ static int adc5_read_voltage_data(struct adc5_chip *adc, u16 *data) · 59 unmodified lines
230 *data = (rslt_msb << 8) | rslt_lsb;246 *data = (rslt_msb << 8) | rslt_lsb;
231 247
232 if (*data == ADC5_USR_DATA_CHECK) {248 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);
234 return -EINVAL;250 return -EINVAL;
235 }251 }
236 252
237 pr_debug("voltage raw code:0x%x\n", *data);253 dev_dbg(adc->dev, "voltage raw code:0x%x\n", *data);
238 254
239 return 0;255 return 0;
240}256}
@@ -285,7 +301,7 @@ static int adc5_configure(struct adc5_chip *adc, · 44 unmodified lines
285 301
286 /* Read registers 0x42 through 0x46 */302 /* Read registers 0x42 through 0x46 */
287 ret = adc5_read(adc, ADC5_USR_DIG_PARAM, buf, sizeof(buf));303 ret = adc5_read(adc, ADC5_USR_DIG_PARAM, buf, sizeof(buf));
288 if (ret < 0)304 if (ret)
289 return ret;305 return ret;
290 306
291 /* Digital param selection */307 /* Digital param selection */
@@ -314,6 +330,47 @@ static int adc5_configure(struct adc5_chip *adc, · 22 unmodified lines
314 return adc5_write(adc, ADC5_USR_DIG_PARAM, buf, sizeof(buf));330 return adc5_write(adc, ADC5_USR_DIG_PARAM, buf, sizeof(buf));
315}331}
316 332
333static 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
317static int adc5_do_conversion(struct adc5_chip *adc,374static int adc5_do_conversion(struct adc5_chip *adc,
318 struct adc5_channel_prop *prop,375 struct adc5_channel_prop *prop,
319 struct iio_chan_spec const *chan,376 struct iio_chan_spec const *chan,
@@ -325,24 +382,24 @@ static int adc5_do_conversion(struct adc5_chip *adc, · 5 unmodified lines
325 382
326 ret = adc5_configure(adc, prop);383 ret = adc5_configure(adc, prop);
327 if (ret) {384 if (ret) {
328 pr_err("ADC configure failed with %d\n", ret);385 dev_err(adc->dev, "ADC configure failed with %d\n", ret);
329 goto unlock;386 goto unlock;
330 }387 }
331 388
332 if (adc->poll_eoc) {389 if (adc->poll_eoc) {
333 ret = adc5_poll_wait_eoc(adc);390 ret = adc5_poll_wait_eoc(adc);
334 if (ret < 0) {391 if (ret) {
335 pr_err("EOC bit not set\n");392 dev_err(adc->dev, "EOC bit not set\n");
336 goto unlock;393 goto unlock;
337 }394 }
338 } else {395 } else {
339 ret = wait_for_completion_timeout(&adc->complete,396 ret = wait_for_completion_timeout(&adc->complete,
340 ADC5_CONV_TIMEOUT);397 ADC5_CONV_TIMEOUT);
341 if (!ret) {398 if (!ret) {
342 pr_debug("Did not get completion timeout.\n");399 dev_dbg(adc->dev, "Did not get completion timeout.\n");
343 ret = adc5_poll_wait_eoc(adc);400 ret = adc5_poll_wait_eoc(adc);
344 if (ret < 0) {401 if (ret) {
345 pr_err("EOC bit not set\n");402 dev_err(adc->dev, "EOC bit not set\n");
346 goto unlock;403 goto unlock;
347 }404 }
348 }405 }
@@ -355,6 +412,48 @@ unlock: · 6 unmodified lines
355 return ret;412 return ret;
356}413}
357 414
415static 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
446unlock:
447 mutex_unlock(&adc->lock);
448
449 return ret;
450}
451
452typedef 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
358static irqreturn_t adc5_isr(int irq, void *dev_id)457static irqreturn_t adc5_isr(int irq, void *dev_id)
359{458{
360 struct adc5_chip *adc = dev_id;459 struct adc5_chip *adc = dev_id;
@@ -377,9 +476,25 @@ static int adc5_of_xlate(struct iio_dev *indio_dev, · 16 unmodified lines
377 return -EINVAL;476 return -EINVAL;
378}477}
379 478
380static int adc5_read_raw(struct iio_dev *indio_dev,479static 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
495static int adc_read_raw_common(struct iio_dev *indio_dev,
381 struct iio_chan_spec const *chan, int *val, int *val2,496 struct iio_chan_spec const *chan, int *val, int *val2,
382 long mask)497 long mask, adc_do_conversion do_conv)
383{498{
384 struct adc5_chip *adc = iio_priv(indio_dev);499 struct adc5_chip *adc = iio_priv(indio_dev);
385 struct adc5_channel_prop *prop;500 struct adc5_channel_prop *prop;
@@ -390,8 +505,8 @@ static int adc5_read_raw(struct iio_dev *indio_dev, · 4 unmodified lines
390 505
391 switch (mask) {506 switch (mask) {
392 case IIO_CHAN_INFO_PROCESSED:507 case IIO_CHAN_INFO_PROCESSED:
393 ret = adc5_do_conversion(adc, prop, chan,508 ret = do_conv(adc, prop, chan,
394 &adc_code_volt, &adc_code_cur);509 &adc_code_volt, &adc_code_cur);
395 if (ret)510 if (ret)
396 return ret;511 return ret;
397 512
@@ -406,8 +521,22 @@ static int adc5_read_raw(struct iio_dev *indio_dev, · 8 unmodified lines
406 default:521 default:
407 return -EINVAL;522 return -EINVAL;
408 }523 }
524}
409 525
410 return 0;526static 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
534static 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);
411}540}
412 541
413static const struct iio_info adc5_info = {542static const struct iio_info adc5_info = {
@@ -415,6 +544,11 @@ static const struct iio_info adc5_info = { · 1 unmodified line
415 .of_xlate = adc5_of_xlate,544 .of_xlate = adc5_of_xlate,
416};545};
417 546
547static const struct iio_info adc7_info = {
548 .read_raw = adc7_read_raw,
549 .of_xlate = adc7_of_xlate,
550};
551
418struct adc5_channels {552struct adc5_channels {
419 const char *datasheet_name;553 const char *datasheet_name;
420 unsigned int prescale_index;554 unsigned int prescale_index;
@@ -477,6 +611,39 @@ static const struct adc5_channels adc5_chans_pmic[ADC5_MAX_CHANNEL] = { · 56 unmodified lines
477 SCALE_HW_CALIB_PM5_SMB_TEMP)611 SCALE_HW_CALIB_PM5_SMB_TEMP)
478};612};
479 613
614static 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
480static const struct adc5_channels adc5_chans_rev2[ADC5_MAX_CHANNEL] = {647static const struct adc5_channels adc5_chans_rev2[ADC5_MAX_CHANNEL] = {
481 [ADC5_REF_GND] = ADC5_CHAN_VOLT("ref_gnd", 0,648 [ADC5_REF_GND] = ADC5_CHAN_VOLT("ref_gnd", 0,
482 SCALE_HW_CALIB_DEFAULT)649 SCALE_HW_CALIB_DEFAULT)
@@ -511,6 +678,7 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc, · 28 unmodified lines
511{678{
512 const char *name = node->name, *channel_name;679 const char *name = node->name, *channel_name;
513 u32 chan, value, varr[2];680 u32 chan, value, varr[2];
681 u32 sid = 0;
514 int ret;682 int ret;
515 struct device *dev = adc->dev;683 struct device *dev = adc->dev;
516 684
@@ -520,6 +688,15 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc, · 3 unmodified lines
520 return ret;688 return ret;
521 }689 }
522 690
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
523 if (chan > ADC5_PARALLEL_ISENSE_VBAT_IDATA ||700 if (chan > ADC5_PARALLEL_ISENSE_VBAT_IDATA ||
524 !data->adc_chans[chan].datasheet_name) {701 !data->adc_chans[chan].datasheet_name) {
525 dev_err(dev, "%s invalid channel number %d\n", name, chan);702 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
528 705
529 /* the channel has DT description */706 /* the channel has DT description */
530 prop->channel = chan;707 prop->channel = chan;
708 prop->sid = sid;
531 709
532 channel_name = of_get_property(node,710 channel_name = of_get_property(node,
533 "label", NULL) ? : node->name;711 "label", NULL) ? : node->name;
534 if (!channel_name) {712 if (!channel_name) {
535 pr_err("Invalid channel name\n");713 dev_err(dev, "Invalid channel name\n");
536 return -EINVAL;714 return -EINVAL;
537 }715 }
538 prop->datasheet_name = channel_name;716 prop->datasheet_name = channel_name;
@@ -570,16 +748,17 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc, · 31 unmodified lines
570 748
571 ret = adc5_read(adc, ADC5_USR_REVISION1, dig_version,749 ret = adc5_read(adc, ADC5_USR_REVISION1, dig_version,
572 sizeof(dig_version));750 sizeof(dig_version));
573 if (ret < 0) {751 if (ret) {
574 dev_err(dev, "Invalid dig version read %d\n", ret);752 dev_err(dev, "Invalid dig version read %d\n", ret);
575 return ret;753 return ret;
576 }754 }
577 755
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],
579 dig_version[1]);757 dig_version[1]);
580 /* Digital controller >= 5.3 have hw_settle_2 option */758 /* Digital controller >= 5.3 have hw_settle_2 option */
581 if (dig_version[0] >= ADC5_HW_SETTLE_DIFF_MINOR &&759 if ((dig_version[0] >= ADC5_HW_SETTLE_DIFF_MINOR &&
582 dig_version[1] >= ADC5_HW_SETTLE_DIFF_MAJOR)760 dig_version[1] >= ADC5_HW_SETTLE_DIFF_MAJOR) ||
761 adc->data->info == &adc7_info)
583 ret = adc5_hw_settle_time_from_dt(value,762 ret = adc5_hw_settle_time_from_dt(value,
584 data->hw_settle_2);763 data->hw_settle_2);
585 else764 else
@@ -629,6 +808,7 @@ static const struct adc5_data adc5_data_pmic = { · 43 unmodified lines
629 .full_scale_code_volt = 0x70e4,808 .full_scale_code_volt = 0x70e4,
630 .full_scale_code_cur = 0x2710,809 .full_scale_code_cur = 0x2710,
631 .adc_chans = adc5_chans_pmic,810 .adc_chans = adc5_chans_pmic,
811 .info = &adc5_info,
632 .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])812 .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])
633 {250, 420, 840},813 {250, 420, 840},
634 .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])814 .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
639 1, 2, 4, 8, 16, 32, 64, 128},819 1, 2, 4, 8, 16, 32, 64, 128},
640};820};
641 821
822static 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
642static const struct adc5_data adc5_data_pmic_rev2 = {834static const struct adc5_data adc5_data_pmic_rev2 = {
643 .full_scale_code_volt = 0x4000,835 .full_scale_code_volt = 0x4000,
644 .full_scale_code_cur = 0x1800,836 .full_scale_code_cur = 0x1800,
645 .adc_chans = adc5_chans_rev2,837 .adc_chans = adc5_chans_rev2,
838 .info = &adc5_info,
646 .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])839 .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])
647 {256, 512, 1024},840 {256, 512, 1024},
648 .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])841 .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
658 .compatible = "qcom,spmi-adc5",851 .compatible = "qcom,spmi-adc5",
659 .data = &adc5_data_pmic,852 .data = &adc5_data_pmic,
660 },853 },
854 {
855 .compatible = "qcom,spmi-adc7",
856 .data = &adc7_data_pmic,
857 },
661 {858 {
662 .compatible = "qcom,spmi-adc-rev2",859 .compatible = "qcom,spmi-adc-rev2",
663 .data = &adc5_data_pmic_rev2,860 .data = &adc5_data_pmic_rev2,
@@ -752,12 +949,13 @@ static int adc5_probe(struct platform_device *pdev) · 88 unmodified lines
752 adc->regmap = regmap;949 adc->regmap = regmap;
753 adc->dev = dev;950 adc->dev = dev;
754 adc->base = reg;951 adc->base = reg;
952
755 init_completion(&adc->complete);953 init_completion(&adc->complete);
756 mutex_init(&adc->lock);954 mutex_init(&adc->lock);
757 955
758 ret = adc5_get_dt_data(adc, node);956 ret = adc5_get_dt_data(adc, node);
759 if (ret) {957 if (ret) {
760 pr_err("adc get dt data failed\n");958 dev_err(dev, "adc get dt data failed\n");
761 return ret;959 return ret;
762 }960 }
763 961
@@ -773,11 +971,9 @@ static int adc5_probe(struct platform_device *pdev) · 9 unmodified lines
773 return ret;971 return ret;
774 }972 }
775 973
776 indio_dev->dev.parent = dev;
777 indio_dev->dev.of_node = node;
778 indio_dev->name = pdev->name;974 indio_dev->name = pdev->name;
779 indio_dev->modes = INDIO_DIRECT_MODE;975 indio_dev->modes = INDIO_DIRECT_MODE;
780 indio_dev->info = &adc5_info;976 indio_dev->info = adc->data->info;
781 indio_dev->channels = adc->iio_chans;977 indio_dev->channels = adc->iio_chans;
782 indio_dev->num_channels = adc->nchannels;978 indio_dev->num_channels = adc->nchannels;
783 979
drivers/iio/adc/qcom-spmi-iadc.c+0−2
@@ -553,8 +553,6 @@ static int iadc_probe(struct platform_device *pdev) · 552 unmodified lines
553 return ret;553 return ret;
554 }554 }
555 555
556 indio_dev->dev.parent = dev;
557 indio_dev->dev.of_node = node;
558 indio_dev->name = pdev->name;556 indio_dev->name = pdev->name;
559 indio_dev->modes = INDIO_DIRECT_MODE;557 indio_dev->modes = INDIO_DIRECT_MODE;
560 indio_dev->info = &iadc_info;558 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
907 if (ret)907 if (ret)
908 return ret;908 return ret;
909 909
910 indio_dev->dev.parent = dev;
911 indio_dev->dev.of_node = node;
912 indio_dev->name = pdev->name;910 indio_dev->name = pdev->name;
913 indio_dev->modes = INDIO_DIRECT_MODE;911 indio_dev->modes = INDIO_DIRECT_MODE;
914 indio_dev->info = &vadc_info;912 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
89 { 46, 125000 },89 { 46, 125000 },
90};90};
91 91
92static 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 */
110static 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
92static int qcom_vadc_scale_hw_calib_volt(281static int qcom_vadc_scale_hw_calib_volt(
93 const struct vadc_prescale_ratio *prescale,282 const struct vadc_prescale_ratio *prescale,
94 const struct adc5_data *data,283 const struct adc5_data *data,
@@ -97,6 +286,10 @@ static int qcom_vadc_scale_hw_calib_therm( · 2 unmodified lines
97 const struct vadc_prescale_ratio *prescale,286 const struct vadc_prescale_ratio *prescale,
98 const struct adc5_data *data,287 const struct adc5_data *data,
99 u16 adc_code, int *result_mdec);288 u16 adc_code, int *result_mdec);
289static 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);
100static int qcom_vadc_scale_hw_smb_temp(293static int qcom_vadc_scale_hw_smb_temp(
101 const struct vadc_prescale_ratio *prescale,294 const struct vadc_prescale_ratio *prescale,
102 const struct adc5_data *data,295 const struct adc5_data *data,
@@ -109,12 +302,20 @@ static int qcom_vadc_scale_hw_calib_die_temp( · 6 unmodified lines
109 const struct vadc_prescale_ratio *prescale,302 const struct vadc_prescale_ratio *prescale,
110 const struct adc5_data *data,303 const struct adc5_data *data,
111 u16 adc_code, int *result_mdec);304 u16 adc_code, int *result_mdec);
305static 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);
112 309
113static struct qcom_adc5_scale_type scale_adc5_fn[] = {310static struct qcom_adc5_scale_type scale_adc5_fn[] = {
114 [SCALE_HW_CALIB_DEFAULT] = {qcom_vadc_scale_hw_calib_volt},311 [SCALE_HW_CALIB_DEFAULT] = {qcom_vadc_scale_hw_calib_volt},
115 [SCALE_HW_CALIB_THERM_100K_PULLUP] = {qcom_vadc_scale_hw_calib_therm},312 [SCALE_HW_CALIB_THERM_100K_PULLUP] = {qcom_vadc_scale_hw_calib_therm},
116 [SCALE_HW_CALIB_XOTHERM] = {qcom_vadc_scale_hw_calib_therm},313 [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},
117 [SCALE_HW_CALIB_PMIC_THERM] = {qcom_vadc_scale_hw_calib_die_temp},316 [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},
118 [SCALE_HW_CALIB_PM5_CHG_TEMP] = {qcom_vadc_scale_hw_chg5_temp},319 [SCALE_HW_CALIB_PM5_CHG_TEMP] = {qcom_vadc_scale_hw_chg5_temp},
119 [SCALE_HW_CALIB_PM5_SMB_TEMP] = {qcom_vadc_scale_hw_smb_temp},320 [SCALE_HW_CALIB_PM5_SMB_TEMP] = {qcom_vadc_scale_hw_smb_temp},
120};321};
@@ -291,6 +492,32 @@ static int qcom_vadc_scale_code_voltage_factor(u16 adc_code, · 170 unmodified lines
291 return (int) voltage;492 return (int) voltage;
292}493}
293 494
495static 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
294static int qcom_vadc_scale_hw_calib_volt(521static int qcom_vadc_scale_hw_calib_volt(
295 const struct vadc_prescale_ratio *prescale,522 const struct vadc_prescale_ratio *prescale,
296 const struct adc5_data *data,523 const struct adc5_data *data,
@@ -330,6 +557,41 @@ static int qcom_vadc_scale_hw_calib_die_temp( · 33 unmodified lines
330 return 0;557 return 0;
331}558}
332 559
560static 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
333static int qcom_vadc_scale_hw_smb_temp(595static int qcom_vadc_scale_hw_smb_temp(
334 const struct vadc_prescale_ratio *prescale,596 const struct vadc_prescale_ratio *prescale,
335 const struct adc5_data *data,597 const struct adc5_data *data,
drivers/iio/adc/qcom-vadc-common.h+15−0
@@ -49,6 +49,14 @@ · 48 unmodified lines
49#define ADC5_FULL_SCALE_CODE 0x70e449#define ADC5_FULL_SCALE_CODE 0x70e4
50#define ADC5_USR_DATA_CHECK 0x800050#define ADC5_USR_DATA_CHECK 0x8000
51 51
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
52/**60/**
53 * struct vadc_map_pt - Map the graph representation for ADC channel61 * struct vadc_map_pt - Map the graph representation for ADC channel
54 * @x: Represent the ADC digitized code.62 * @x: Represent the ADC digitized code.
@@ -110,8 +118,12 @@ struct vadc_prescale_ratio { · 55 unmodified lines
110 * lookup table. The hardware applies offset/slope to adc code.118 * lookup table. The hardware applies offset/slope to adc code.
111 * SCALE_HW_CALIB_XOTHERM: Returns XO thermistor voltage in millidegC using119 * SCALE_HW_CALIB_XOTHERM: Returns XO thermistor voltage in millidegC using
112 * 100k pullup. The hardware applies offset/slope to adc code.120 * 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.
113 * SCALE_HW_CALIB_PMIC_THERM: Returns result in milli degree's Centigrade.123 * SCALE_HW_CALIB_PMIC_THERM: Returns result in milli degree's Centigrade.
114 * The hardware applies offset/slope to adc code.124 * 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.
115 * SCALE_HW_CALIB_PM5_CHG_TEMP: Returns result in millidegrees for PMIC5127 * SCALE_HW_CALIB_PM5_CHG_TEMP: Returns result in millidegrees for PMIC5
116 * charger temperature.128 * charger temperature.
117 * SCALE_HW_CALIB_PM5_SMB_TEMP: Returns result in millidegrees for PMIC5129 * SCALE_HW_CALIB_PM5_SMB_TEMP: Returns result in millidegrees for PMIC5
@@ -126,7 +138,9 @@ enum vadc_scale_fn_type { · 8 unmodified lines
126 SCALE_HW_CALIB_DEFAULT,138 SCALE_HW_CALIB_DEFAULT,
127 SCALE_HW_CALIB_THERM_100K_PULLUP,139 SCALE_HW_CALIB_THERM_100K_PULLUP,
128 SCALE_HW_CALIB_XOTHERM,140 SCALE_HW_CALIB_XOTHERM,
141 SCALE_HW_CALIB_THERM_100K_PU_PM7,
129 SCALE_HW_CALIB_PMIC_THERM,142 SCALE_HW_CALIB_PMIC_THERM,
143 SCALE_HW_CALIB_PMIC_THERM_PM7,
130 SCALE_HW_CALIB_PM5_CHG_TEMP,144 SCALE_HW_CALIB_PM5_CHG_TEMP,
131 SCALE_HW_CALIB_PM5_SMB_TEMP,145 SCALE_HW_CALIB_PM5_SMB_TEMP,
132 SCALE_HW_CALIB_INVALID,146 SCALE_HW_CALIB_INVALID,
@@ -136,6 +150,7 @@ struct adc5_data { · 3 unmodified lines
136 const u32 full_scale_code_volt;150 const u32 full_scale_code_volt;
137 const u32 full_scale_code_cur;151 const u32 full_scale_code_cur;
138 const struct adc5_channels *adc_chans;152 const struct adc5_channels *adc_chans;
153 const struct iio_info *info;
139 unsigned int *decimation;154 unsigned int *decimation;
140 unsigned int *hw_settle_1;155 unsigned int *hw_settle_1;
141 unsigned int *hw_settle_2;156 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
516 platform_set_drvdata(pdev, indio_dev);516 platform_set_drvdata(pdev, indio_dev);
517 517
518 indio_dev->name = DRIVER_NAME;518 indio_dev->name = DRIVER_NAME;
519 indio_dev->dev.parent = dev;
520 indio_dev->dev.of_node = pdev->dev.of_node;
521 indio_dev->info = &rcar_gyroadc_iio_info;519 indio_dev->info = &rcar_gyroadc_iio_info;
522 indio_dev->modes = INDIO_DIRECT_MODE;520 indio_dev->modes = INDIO_DIRECT_MODE;
523 521
drivers/iio/adc/rn5t618-adc.c+0−1
@@ -218,7 +218,6 @@ static int rn5t618_adc_probe(struct platform_device *pdev) · 217 unmodified lines
218 init_completion(&adc->conv_completion);218 init_completion(&adc->conv_completion);
219 219
220 iio_dev->name = dev_name(&pdev->dev);220 iio_dev->name = dev_name(&pdev->dev);
221 iio_dev->dev.parent = &pdev->dev;
222 iio_dev->info = &rn5t618_adc_iio_info;221 iio_dev->info = &rn5t618_adc_iio_info;
223 iio_dev->modes = INDIO_DIRECT_MODE;222 iio_dev->modes = INDIO_DIRECT_MODE;
224 iio_dev->channels = rn5t618_adc_iio_channels;223 iio_dev->channels = rn5t618_adc_iio_channels;
drivers/iio/adc/rockchip_saradc.c+154−65
@@ -15,7 +15,10 @@ · 14 unmodified lines
15#include <linux/delay.h>15#include <linux/delay.h>
16#include <linux/reset.h>16#include <linux/reset.h>
17#include <linux/regulator/consumer.h>17#include <linux/regulator/consumer.h>
18#include <linux/iio/buffer.h>
18#include <linux/iio/iio.h>19#include <linux/iio/iio.h>
20#include <linux/iio/trigger_consumer.h>
21#include <linux/iio/triggered_buffer.h>
19 22
20#define SARADC_DATA 0x0023#define SARADC_DATA 0x00
21 24
@@ -32,9 +35,9 @@ · 10 unmodified lines
32#define SARADC_DLY_PU_SOC_MASK 0x3f35#define SARADC_DLY_PU_SOC_MASK 0x3f
33 36
34#define SARADC_TIMEOUT msecs_to_jiffies(100)37#define SARADC_TIMEOUT msecs_to_jiffies(100)
38#define SARADC_MAX_CHANNELS 6
35 39
36struct rockchip_saradc_data {40struct rockchip_saradc_data {
37 int num_bits;
38 const struct iio_chan_spec *channels;41 const struct iio_chan_spec *channels;
39 int num_channels;42 int num_channels;
40 unsigned long clk_rate;43 unsigned long clk_rate;
@@ -49,8 +52,37 @@ struct rockchip_saradc { · 8 unmodified lines
49 struct reset_control *reset;52 struct reset_control *reset;
50 const struct rockchip_saradc_data *data;53 const struct rockchip_saradc_data *data;
51 u16 last_val;54 u16 last_val;
55 const struct iio_chan_spec *last_chan;
52};56};
53 57
58static 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
64static 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
54static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,86static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,
55 struct iio_chan_spec const *chan,87 struct iio_chan_spec const *chan,
56 int *val, int *val2, long mask)88 int *val, int *val2, long mask)
@@ -62,22 +94,11 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev, · 5 unmodified lines
62 case IIO_CHAN_INFO_RAW:94 case IIO_CHAN_INFO_RAW:
63 mutex_lock(&indio_dev->mlock);95 mutex_lock(&indio_dev->mlock);
64 96
65 reinit_completion(&info->completion);97 ret = rockchip_saradc_conversion(info, chan);
66 98 if (ret) {
67 /* 8 clock periods as delay between power up and start cmd */99 rockchip_saradc_power_down(info);
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);
79 mutex_unlock(&indio_dev->mlock);100 mutex_unlock(&indio_dev->mlock);
80 return -ETIMEDOUT;101 return ret;
81 }102 }
82 103
83 *val = info->last_val;104 *val = info->last_val;
@@ -91,7 +112,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev, · 7 unmodified lines
91 }112 }
92 113
93 *val = ret / 1000;114 *val = ret / 1000;
94 *val2 = info->data->num_bits;115 *val2 = chan->scan_type.realbits;
95 return IIO_VAL_FRACTIONAL_LOG2;116 return IIO_VAL_FRACTIONAL_LOG2;
96 default:117 default:
97 return -EINVAL;118 return -EINVAL;
@@ -104,10 +125,9 @@ static irqreturn_t rockchip_saradc_isr(int irq, void *dev_id) · 6 unmodified lines
104 125
105 /* Read value */126 /* Read value */
106 info->last_val = readl_relaxed(info->regs + SARADC_DATA);127 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);
108 129
109 /* Clear irq & power down adc */130 rockchip_saradc_power_down(info);
110 writel_relaxed(0, info->regs + SARADC_CTRL);
111 131
112 complete(&info->completion);132 complete(&info->completion);
113 133
@@ -118,51 +138,55 @@ static const struct iio_info rockchip_saradc_iio_info = { · 4 unmodified lines
118 .read_raw = rockchip_saradc_read_raw,138 .read_raw = rockchip_saradc_read_raw,
119};139};
120 140
121#define ADC_CHANNEL(_index, _id) { \141#define SARADC_CHANNEL(_index, _id, _res) { \
122 .type = IIO_VOLTAGE, \142 .type = IIO_VOLTAGE, \
123 .indexed = 1, \143 .indexed = 1, \
124 .channel = _index, \144 .channel = _index, \
125 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \145 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
126 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \146 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
127 .datasheet_name = _id, \147 .datasheet_name = _id, \
148 .scan_index = _index, \
149 .scan_type = { \
150 .sign = 'u', \
151 .realbits = _res, \
152 .storagebits = 16, \
153 .endianness = IIO_CPU, \
154 }, \
128}155}
129 156
130static const struct iio_chan_spec rockchip_saradc_iio_channels[] = {157static const struct iio_chan_spec rockchip_saradc_iio_channels[] = {
131 ADC_CHANNEL(0, "adc0"),158 SARADC_CHANNEL(0, "adc0", 10),
132 ADC_CHANNEL(1, "adc1"),159 SARADC_CHANNEL(1, "adc1", 10),
133 ADC_CHANNEL(2, "adc2"),160 SARADC_CHANNEL(2, "adc2", 10),
134};161};
135 162
136static const struct rockchip_saradc_data saradc_data = {163static const struct rockchip_saradc_data saradc_data = {
137 .num_bits = 10,
138 .channels = rockchip_saradc_iio_channels,164 .channels = rockchip_saradc_iio_channels,
139 .num_channels = ARRAY_SIZE(rockchip_saradc_iio_channels),165 .num_channels = ARRAY_SIZE(rockchip_saradc_iio_channels),
140 .clk_rate = 1000000,166 .clk_rate = 1000000,
141};167};
142 168
143static const struct iio_chan_spec rockchip_rk3066_tsadc_iio_channels[] = {169static const struct iio_chan_spec rockchip_rk3066_tsadc_iio_channels[] = {
144 ADC_CHANNEL(0, "adc0"),170 SARADC_CHANNEL(0, "adc0", 12),
145 ADC_CHANNEL(1, "adc1"),171 SARADC_CHANNEL(1, "adc1", 12),
146};172};
147 173
148static const struct rockchip_saradc_data rk3066_tsadc_data = {174static const struct rockchip_saradc_data rk3066_tsadc_data = {
149 .num_bits = 12,
150 .channels = rockchip_rk3066_tsadc_iio_channels,175 .channels = rockchip_rk3066_tsadc_iio_channels,
151 .num_channels = ARRAY_SIZE(rockchip_rk3066_tsadc_iio_channels),176 .num_channels = ARRAY_SIZE(rockchip_rk3066_tsadc_iio_channels),
152 .clk_rate = 50000,177 .clk_rate = 50000,
153};178};
154 179
155static const struct iio_chan_spec rockchip_rk3399_saradc_iio_channels[] = {180static const struct iio_chan_spec rockchip_rk3399_saradc_iio_channels[] = {
156 ADC_CHANNEL(0, "adc0"),181 SARADC_CHANNEL(0, "adc0", 10),
157 ADC_CHANNEL(1, "adc1"),182 SARADC_CHANNEL(1, "adc1", 10),
158 ADC_CHANNEL(2, "adc2"),183 SARADC_CHANNEL(2, "adc2", 10),
159 ADC_CHANNEL(3, "adc3"),184 SARADC_CHANNEL(3, "adc3", 10),
160 ADC_CHANNEL(4, "adc4"),185 SARADC_CHANNEL(4, "adc4", 10),
161 ADC_CHANNEL(5, "adc5"),186 SARADC_CHANNEL(5, "adc5", 10),
162};187};
163 188
164static const struct rockchip_saradc_data rk3399_saradc_data = {189static const struct rockchip_saradc_data rk3399_saradc_data = {
165 .num_bits = 10,
166 .channels = rockchip_rk3399_saradc_iio_channels,190 .channels = rockchip_rk3399_saradc_iio_channels,
167 .num_channels = ARRAY_SIZE(rockchip_rk3399_saradc_iio_channels),191 .num_channels = ARRAY_SIZE(rockchip_rk3399_saradc_iio_channels),
168 .clk_rate = 1000000,192 .clk_rate = 1000000,
@@ -193,6 +217,67 @@ static void rockchip_saradc_reset_controller(struct reset_control *reset) · 24 unmodified lines
193 reset_control_deassert(reset);217 reset_control_deassert(reset);
194}218}
195 219
220static void rockchip_saradc_clk_disable(void *data)
221{
222 struct rockchip_saradc *info = data;
223
224 clk_disable_unprepare(info->clk);
225}
226
227static void rockchip_saradc_pclk_disable(void *data)
228{
229 struct rockchip_saradc *info = data;
230
231 clk_disable_unprepare(info->pclk);
232}
233
234static void rockchip_saradc_regulator_disable(void *data)
235{
236 struct rockchip_saradc *info = data;
237
238 regulator_disable(info->vref);
239}
240
241static 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));
273out:
274 mutex_unlock(&i_dev->mlock);
275
276 iio_trigger_notify_done(i_dev->trig);
277
278 return IRQ_HANDLED;
279}
280
196static int rockchip_saradc_probe(struct platform_device *pdev)281static int rockchip_saradc_probe(struct platform_device *pdev)
197{282{
198 struct rockchip_saradc *info = NULL;283 struct rockchip_saradc *info = NULL;
@@ -221,6 +306,12 @@ static int rockchip_saradc_probe(struct platform_device *pdev) · 22 unmodified lines
221 306
222 info->data = match->data;307 info->data = match->data;
223 308
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
224 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);315 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
225 info->regs = devm_ioremap_resource(&pdev->dev, mem);316 info->regs = devm_ioremap_resource(&pdev->dev, mem);
226 if (IS_ERR(info->regs))317 if (IS_ERR(info->regs))
@@ -291,56 +382,55 @@ static int rockchip_saradc_probe(struct platform_device *pdev) · 64 unmodified lines
291 dev_err(&pdev->dev, "failed to enable vref regulator\n");382 dev_err(&pdev->dev, "failed to enable vref regulator\n");
292 return ret;383 return ret;
293 }384 }
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 }
294 392
295 ret = clk_prepare_enable(info->pclk);393 ret = clk_prepare_enable(info->pclk);
296 if (ret < 0) {394 if (ret < 0) {
297 dev_err(&pdev->dev, "failed to enable pclk\n");395 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;
299 }404 }
300 405
301 ret = clk_prepare_enable(info->clk);406 ret = clk_prepare_enable(info->clk);
302 if (ret < 0) {407 if (ret < 0) {
303 dev_err(&pdev->dev, "failed to enable converter clock\n");408 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;
305 }417 }
306 418
307 platform_set_drvdata(pdev, indio_dev);419 platform_set_drvdata(pdev, indio_dev);
308 420
309 indio_dev->name = dev_name(&pdev->dev);421 indio_dev->name = dev_name(&pdev->dev);
310 indio_dev->dev.parent = &pdev->dev;
311 indio_dev->dev.of_node = pdev->dev.of_node;
312 indio_dev->info = &rockchip_saradc_iio_info;422 indio_dev->info = &rockchip_saradc_iio_info;
313 indio_dev->modes = INDIO_DIRECT_MODE;423 indio_dev->modes = INDIO_DIRECT_MODE;
314 424
315 indio_dev->channels = info->data->channels;425 indio_dev->channels = info->data->channels;
316 indio_dev->num_channels = info->data->num_channels;426 indio_dev->num_channels = info->data->num_channels;
317 427 ret = devm_iio_triggered_buffer_setup(&indio_dev->dev, indio_dev, NULL,
318 ret = iio_device_register(indio_dev);428 rockchip_saradc_trigger_handler,
429 NULL);
319 if (ret)430 if (ret)
320 goto err_clk;431 return ret;
321
322 return 0;
323
324err_clk:
325 clk_disable_unprepare(info->clk);
326err_pclk:
327 clk_disable_unprepare(info->pclk);
328err_reg_voltage:
329 regulator_disable(info->vref);
330 return ret;
331}
332
333static 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);
342 432
343 return 0;433 return devm_iio_device_register(&pdev->dev, indio_dev);
344}434}
345 435
346#ifdef CONFIG_PM_SLEEP436#ifdef CONFIG_PM_SLEEP
@@ -383,7 +473,6 @@ static SIMPLE_DEV_PM_OPS(rockchip_saradc_pm_ops, · 36 unmodified lines
383 473
384static struct platform_driver rockchip_saradc_driver = {474static struct platform_driver rockchip_saradc_driver = {
385 .probe = rockchip_saradc_probe,475 .probe = rockchip_saradc_probe,
386 .remove = rockchip_saradc_remove,
387 .driver = {476 .driver = {
388 .name = "rockchip-saradc",477 .name = "rockchip-saradc",
389 .of_match_table = rockchip_saradc_match,478 .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
533 return ret;533 return ret;
534 }534 }
535 535
536 indio_dev->dev.parent = dev;
537 indio_dev->name = dev_name(dev);536 indio_dev->name = dev_name(dev);
538 indio_dev->modes = INDIO_DIRECT_MODE;537 indio_dev->modes = INDIO_DIRECT_MODE;
539 indio_dev->info = &sc27xx_info;538 indio_dev->info = &sc27xx_info;
drivers/iio/adc/sd_adc_modulator.c+3−4
@@ -9,7 +9,8 @@ · 8 unmodified lines
9#include <linux/iio/iio.h>9#include <linux/iio/iio.h>
10#include <linux/iio/triggered_buffer.h>10#include <linux/iio/triggered_buffer.h>
11#include <linux/module.h>11#include <linux/module.h>
12#include <linux/of_device.h>12#include <linux/mod_devicetable.h>
13#include <linux/platform_device.h>
13 14
14static const struct iio_info iio_sd_mod_iio_info;15static const struct iio_info iio_sd_mod_iio_info;
15 16
@@ -32,8 +33,6 @@ static int iio_sd_mod_probe(struct platform_device *pdev) · 16 unmodified lines
32 if (!iio)33 if (!iio)
33 return -ENOMEM;34 return -ENOMEM;
34 35
35 iio->dev.parent = dev;
36 iio->dev.of_node = dev->of_node;
37 iio->name = dev_name(dev);36 iio->name = dev_name(dev);
38 iio->info = &iio_sd_mod_iio_info;37 iio->info = &iio_sd_mod_iio_info;
39 iio->modes = INDIO_BUFFER_HARDWARE;38 iio->modes = INDIO_BUFFER_HARDWARE;
@@ -56,7 +55,7 @@ MODULE_DEVICE_TABLE(of, sd_adc_of_match); · 16 unmodified lines
56static struct platform_driver iio_sd_mod_adc = {55static struct platform_driver iio_sd_mod_adc = {
57 .driver = {56 .driver = {
58 .name = "iio_sd_adc_mod",57 .name = "iio_sd_adc_mod",
59 .of_match_table = of_match_ptr(sd_adc_of_match),58 .of_match_table = sd_adc_of_match,
60 },59 },
61 .probe = iio_sd_mod_probe,60 .probe = iio_sd_mod_probe,
62};61};
drivers/iio/adc/spear_adc.c+0−1
@@ -336,7 +336,6 @@ static int spear_adc_probe(struct platform_device *pdev) · 335 unmodified lines
336 init_completion(&st->completion);336 init_completion(&st->completion);
337 337
338 indio_dev->name = SPEAR_ADC_MOD_NAME;338 indio_dev->name = SPEAR_ADC_MOD_NAME;
339 indio_dev->dev.parent = dev;
340 indio_dev->info = &spear_adc_info;339 indio_dev->info = &spear_adc_info;
341 indio_dev->modes = INDIO_DIRECT_MODE;340 indio_dev->modes = INDIO_DIRECT_MODE;
342 indio_dev->channels = spear_adc_iio_channels;341 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
162 struct stm32_adc_trig_info *trigs;162 struct stm32_adc_trig_info *trigs;
163 bool clk_required;163 bool clk_required;
164 bool has_vregready;164 bool has_vregready;
165 int (*prepare)(struct stm32_adc *);165 int (*prepare)(struct iio_dev *);
166 void (*start_conv)(struct stm32_adc *, bool dma);166 void (*start_conv)(struct iio_dev *, bool dma);
167 void (*stop_conv)(struct stm32_adc *);167 void (*stop_conv)(struct iio_dev *);
168 void (*unprepare)(struct stm32_adc *);168 void (*unprepare)(struct iio_dev *);
169 const unsigned int *smp_cycles;169 const unsigned int *smp_cycles;
170};170};
171 171
@@ -538,10 +538,11 @@ static void stm32_adc_set_res(struct stm32_adc *adc) · 366 unmodified lines
538 538
539static int stm32_adc_hw_stop(struct device *dev)539static int stm32_adc_hw_stop(struct device *dev)
540{540{
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);
542 543
543 if (adc->cfg->unprepare)544 if (adc->cfg->unprepare)
544 adc->cfg->unprepare(adc);545 adc->cfg->unprepare(indio_dev);
545 546
546 if (adc->clk)547 if (adc->clk)
547 clk_disable_unprepare(adc->clk);548 clk_disable_unprepare(adc->clk);
@@ -551,7 +552,8 @@ static int stm32_adc_hw_stop(struct device *dev) · 3 unmodified lines
551 552
552static int stm32_adc_hw_start(struct device *dev)553static int stm32_adc_hw_start(struct device *dev)
553{554{
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);
555 int ret;557 int ret;
556 558
557 if (adc->clk) {559 if (adc->clk) {
@@ -563,7 +565,7 @@ static int stm32_adc_hw_start(struct device *dev) · 5 unmodified lines
563 stm32_adc_set_res(adc);565 stm32_adc_set_res(adc);
564 566
565 if (adc->cfg->prepare) {567 if (adc->cfg->prepare) {
566 ret = adc->cfg->prepare(adc);568 ret = adc->cfg->prepare(indio_dev);
567 if (ret)569 if (ret)
568 goto err_clk_dis;570 goto err_clk_dis;
569 }571 }
@@ -579,7 +581,7 @@ err_clk_dis: · 9 unmodified lines
579 581
580/**582/**
581 * stm32f4_adc_start_conv() - Start conversions for regular channels.583 * stm32f4_adc_start_conv() - Start conversions for regular channels.
582 * @adc: stm32 adc instance584 * @indio_dev: IIO device instance
583 * @dma: use dma to transfer conversion result585 * @dma: use dma to transfer conversion result
584 *586 *
585 * Start conversions for regular channels.587 * Start conversions for regular channels.
@@ -587,8 +589,10 @@ err_clk_dis: · 1 unmodified line
587 * conversions, in IIO buffer modes. Otherwise, use ADC interrupt with direct589 * conversions, in IIO buffer modes. Otherwise, use ADC interrupt with direct
588 * DR read instead (e.g. read_raw, or triggered buffer mode without DMA).590 * DR read instead (e.g. read_raw, or triggered buffer mode without DMA).
589 */591 */
590static void stm32f4_adc_start_conv(struct stm32_adc *adc, bool dma)592static void stm32f4_adc_start_conv(struct iio_dev *indio_dev, bool dma)
591{593{
594 struct stm32_adc *adc = iio_priv(indio_dev);
595
592 stm32_adc_set_bits(adc, STM32F4_ADC_CR1, STM32F4_SCAN);596 stm32_adc_set_bits(adc, STM32F4_ADC_CR1, STM32F4_SCAN);
593 597
594 if (dma)598 if (dma)
@@ -605,8 +609,10 @@ static void stm32f4_adc_start_conv(struct stm32_adc *adc, bool dma) · 10 unmodified lines
605 stm32_adc_set_bits(adc, STM32F4_ADC_CR2, STM32F4_SWSTART);609 stm32_adc_set_bits(adc, STM32F4_ADC_CR2, STM32F4_SWSTART);
606}610}
607 611
608static void stm32f4_adc_stop_conv(struct stm32_adc *adc)612static void stm32f4_adc_stop_conv(struct iio_dev *indio_dev)
609{613{
614 struct stm32_adc *adc = iio_priv(indio_dev);
615
610 stm32_adc_clr_bits(adc, STM32F4_ADC_CR2, STM32F4_EXTEN_MASK);616 stm32_adc_clr_bits(adc, STM32F4_ADC_CR2, STM32F4_EXTEN_MASK);
611 stm32_adc_clr_bits(adc, STM32F4_ADC_SR, STM32F4_STRT);617 stm32_adc_clr_bits(adc, STM32F4_ADC_SR, STM32F4_STRT);
612 618
@@ -615,8 +621,9 @@ static void stm32f4_adc_stop_conv(struct stm32_adc *adc) · 2 unmodified lines
615 STM32F4_ADON | STM32F4_DMA | STM32F4_DDS);621 STM32F4_ADON | STM32F4_DMA | STM32F4_DDS);
616}622}
617 623
618static void stm32h7_adc_start_conv(struct stm32_adc *adc, bool dma)624static void stm32h7_adc_start_conv(struct iio_dev *indio_dev, bool dma)
619{625{
626 struct stm32_adc *adc = iio_priv(indio_dev);
620 enum stm32h7_adc_dmngt dmngt;627 enum stm32h7_adc_dmngt dmngt;
621 unsigned long flags;628 unsigned long flags;
622 u32 val;629 u32 val;
@@ -635,9 +642,9 @@ static void stm32h7_adc_start_conv(struct stm32_adc *adc, bool dma) · 12 unmodified lines
635 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADSTART);642 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADSTART);
636}643}
637 644
638static void stm32h7_adc_stop_conv(struct stm32_adc *adc)645static void stm32h7_adc_stop_conv(struct iio_dev *indio_dev)
639{646{
640 struct iio_dev *indio_dev = iio_priv_to_dev(adc);647 struct stm32_adc *adc = iio_priv(indio_dev);
641 int ret;648 int ret;
642 u32 val;649 u32 val;
643 650
@@ -652,9 +659,9 @@ static void stm32h7_adc_stop_conv(struct stm32_adc *adc) · 8 unmodified lines
652 stm32_adc_clr_bits(adc, STM32H7_ADC_CFGR, STM32H7_DMNGT_MASK);659 stm32_adc_clr_bits(adc, STM32H7_ADC_CFGR, STM32H7_DMNGT_MASK);
653}660}
654 661
655static int stm32h7_adc_exit_pwr_down(struct stm32_adc *adc)662static int stm32h7_adc_exit_pwr_down(struct iio_dev *indio_dev)
656{663{
657 struct iio_dev *indio_dev = iio_priv_to_dev(adc);664 struct stm32_adc *adc = iio_priv(indio_dev);
658 int ret;665 int ret;
659 u32 val;666 u32 val;
660 667
@@ -690,9 +697,9 @@ static void stm32h7_adc_enter_pwr_down(struct stm32_adc *adc) · 29 unmodified lines
690 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_DEEPPWD);697 stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_DEEPPWD);
691}698}
692 699
693static int stm32h7_adc_enable(struct stm32_adc *adc)700static int stm32h7_adc_enable(struct iio_dev *indio_dev)
694{701{
695 struct iio_dev *indio_dev = iio_priv_to_dev(adc);702 struct stm32_adc *adc = iio_priv(indio_dev);
696 int ret;703 int ret;
697 u32 val;704 u32 val;
698 705
@@ -713,9 +720,9 @@ static int stm32h7_adc_enable(struct stm32_adc *adc) · 14 unmodified lines
713 return ret;720 return ret;
714}721}
715 722
716static void stm32h7_adc_disable(struct stm32_adc *adc)723static void stm32h7_adc_disable(struct iio_dev *indio_dev)
717{724{
718 struct iio_dev *indio_dev = iio_priv_to_dev(adc);725 struct stm32_adc *adc = iio_priv(indio_dev);
719 int ret;726 int ret;
720 u32 val;727 u32 val;
721 728
@@ -730,12 +737,12 @@ static void stm32h7_adc_disable(struct stm32_adc *adc) · 8 unmodified lines
730 737
731/**738/**
732 * stm32h7_adc_read_selfcalib() - read calibration shadow regs, save result739 * stm32h7_adc_read_selfcalib() - read calibration shadow regs, save result
733 * @adc: stm32 adc instance740 * @indio_dev: IIO device instance
734 * Note: Must be called once ADC is enabled, so LINCALRDYW[1..6] are writable741 * Note: Must be called once ADC is enabled, so LINCALRDYW[1..6] are writable
735 */742 */
736static int stm32h7_adc_read_selfcalib(struct stm32_adc *adc)743static int stm32h7_adc_read_selfcalib(struct iio_dev *indio_dev)
737{744{
738 struct iio_dev *indio_dev = iio_priv_to_dev(adc);745 struct stm32_adc *adc = iio_priv(indio_dev);
739 int i, ret;746 int i, ret;
740 u32 lincalrdyw_mask, val;747 u32 lincalrdyw_mask, val;
741 748
@@ -774,12 +781,12 @@ static int stm32h7_adc_read_selfcalib(struct stm32_adc *adc) · 32 unmodified lines
774 781
775/**782/**
776 * stm32h7_adc_restore_selfcalib() - Restore saved self-calibration result783 * stm32h7_adc_restore_selfcalib() - Restore saved self-calibration result
777 * @adc: stm32 adc instance784 * @indio_dev: IIO device instance
778 * Note: ADC must be enabled, with no on-going conversions.785 * Note: ADC must be enabled, with no on-going conversions.
779 */786 */
780static int stm32h7_adc_restore_selfcalib(struct stm32_adc *adc)787static int stm32h7_adc_restore_selfcalib(struct iio_dev *indio_dev)
781{788{
782 struct iio_dev *indio_dev = iio_priv_to_dev(adc);789 struct stm32_adc *adc = iio_priv(indio_dev);
783 int i, ret;790 int i, ret;
784 u32 lincalrdyw_mask, val;791 u32 lincalrdyw_mask, val;
785 792
@@ -847,12 +854,12 @@ static int stm32h7_adc_restore_selfcalib(struct stm32_adc *adc) · 61 unmodified lines
847 854
848/**855/**
849 * stm32h7_adc_selfcalib() - Procedure to calibrate ADC856 * stm32h7_adc_selfcalib() - Procedure to calibrate ADC
850 * @adc: stm32 adc instance857 * @indio_dev: IIO device instance
851 * Note: Must be called once ADC is out of power down.858 * Note: Must be called once ADC is out of power down.
852 */859 */
853static int stm32h7_adc_selfcalib(struct stm32_adc *adc)860static int stm32h7_adc_selfcalib(struct iio_dev *indio_dev)
854{861{
855 struct iio_dev *indio_dev = iio_priv_to_dev(adc);862 struct stm32_adc *adc = iio_priv(indio_dev);
856 int ret;863 int ret;
857 u32 val;864 u32 val;
858 865
@@ -903,7 +910,7 @@ out: · 44 unmodified lines
903 910
904/**911/**
905 * stm32h7_adc_prepare() - Leave power down mode to enable ADC.912 * stm32h7_adc_prepare() - Leave power down mode to enable ADC.
906 * @adc: stm32 adc instance913 * @indio_dev: IIO device instance
907 * Leave power down mode.914 * Leave power down mode.
908 * Configure channels as single ended or differential before enabling ADC.915 * Configure channels as single ended or differential before enabling ADC.
909 * Enable ADC.916 * Enable ADC.
@@ -912,30 +919,31 @@ out: · 2 unmodified lines
912 * - Only one input is selected for single ended (e.g. 'vinp')919 * - Only one input is selected for single ended (e.g. 'vinp')
913 * - Two inputs are selected for differential channels (e.g. 'vinp' & 'vinn')920 * - Two inputs are selected for differential channels (e.g. 'vinp' & 'vinn')
914 */921 */
915static int stm32h7_adc_prepare(struct stm32_adc *adc)922static int stm32h7_adc_prepare(struct iio_dev *indio_dev)
916{923{
924 struct stm32_adc *adc = iio_priv(indio_dev);
917 int calib, ret;925 int calib, ret;
918 926
919 ret = stm32h7_adc_exit_pwr_down(adc);927 ret = stm32h7_adc_exit_pwr_down(indio_dev);
920 if (ret)928 if (ret)
921 return ret;929 return ret;
922 930
923 ret = stm32h7_adc_selfcalib(adc);931 ret = stm32h7_adc_selfcalib(indio_dev);
924 if (ret < 0)932 if (ret < 0)
925 goto pwr_dwn;933 goto pwr_dwn;
926 calib = ret;934 calib = ret;
927 935
928 stm32_adc_writel(adc, STM32H7_ADC_DIFSEL, adc->difsel);936 stm32_adc_writel(adc, STM32H7_ADC_DIFSEL, adc->difsel);
929 937
930 ret = stm32h7_adc_enable(adc);938 ret = stm32h7_adc_enable(indio_dev);
931 if (ret)939 if (ret)
932 goto pwr_dwn;940 goto pwr_dwn;
933 941
934 /* Either restore or read calibration result for future reference */942 /* Either restore or read calibration result for future reference */
935 if (calib)943 if (calib)
936 ret = stm32h7_adc_restore_selfcalib(adc);944 ret = stm32h7_adc_restore_selfcalib(indio_dev);
937 else945 else
938 ret = stm32h7_adc_read_selfcalib(adc);946 ret = stm32h7_adc_read_selfcalib(indio_dev);
939 if (ret)947 if (ret)
940 goto disable;948 goto disable;
941 949
@@ -944,16 +952,18 @@ static int stm32h7_adc_prepare(struct stm32_adc *adc) · 2 unmodified lines
944 return 0;952 return 0;
945 953
946disable:954disable:
947 stm32h7_adc_disable(adc);955 stm32h7_adc_disable(indio_dev);
948pwr_dwn:956pwr_dwn:
949 stm32h7_adc_enter_pwr_down(adc);957 stm32h7_adc_enter_pwr_down(adc);
950 958
951 return ret;959 return ret;
952}960}
953 961
954static void stm32h7_adc_unprepare(struct stm32_adc *adc)962static void stm32h7_adc_unprepare(struct iio_dev *indio_dev)
955{963{
956 stm32h7_adc_disable(adc);964 struct stm32_adc *adc = iio_priv(indio_dev);
965
966 stm32h7_adc_disable(indio_dev);
957 stm32h7_adc_enter_pwr_down(adc);967 stm32h7_adc_enter_pwr_down(adc);
958}968}
959 969
@@ -1160,7 +1170,7 @@ static int stm32_adc_single_conv(struct iio_dev *indio_dev, · 200 unmodified lines
1160 1170
1161 stm32_adc_conv_irq_enable(adc);1171 stm32_adc_conv_irq_enable(adc);
1162 1172
1163 adc->cfg->start_conv(adc, false);1173 adc->cfg->start_conv(indio_dev, false);
1164 1174
1165 timeout = wait_for_completion_interruptible_timeout(1175 timeout = wait_for_completion_interruptible_timeout(
1166 &adc->completion, STM32_ADC_TIMEOUT);1176 &adc->completion, STM32_ADC_TIMEOUT);
@@ -1173,7 +1183,7 @@ static int stm32_adc_single_conv(struct iio_dev *indio_dev, · 6 unmodified lines
1173 ret = IIO_VAL_INT;1183 ret = IIO_VAL_INT;
1174 }1184 }
1175 1185
1176 adc->cfg->stop_conv(adc);1186 adc->cfg->stop_conv(indio_dev);
1177 1187
1178 stm32_adc_conv_irq_disable(adc);1188 stm32_adc_conv_irq_disable(adc);
1179 1189
@@ -1227,8 +1237,8 @@ static int stm32_adc_read_raw(struct iio_dev *indio_dev, · 47 unmodified lines
1227 1237
1228static irqreturn_t stm32_adc_threaded_isr(int irq, void *data)1238static irqreturn_t stm32_adc_threaded_isr(int irq, void *data)
1229{1239{
1230 struct stm32_adc *adc = data;1240 struct iio_dev *indio_dev = data;
1231 struct iio_dev *indio_dev = iio_priv_to_dev(adc);1241 struct stm32_adc *adc = iio_priv(indio_dev);
1232 const struct stm32_adc_regspec *regs = adc->cfg->regs;1242 const struct stm32_adc_regspec *regs = adc->cfg->regs;
1233 u32 status = stm32_adc_readl(adc, regs->isr_eoc.reg);1243 u32 status = stm32_adc_readl(adc, regs->isr_eoc.reg);
1234 1244
@@ -1240,8 +1250,8 @@ static irqreturn_t stm32_adc_threaded_isr(int irq, void *data) · 5 unmodified lines
1240 1250
1241static irqreturn_t stm32_adc_isr(int irq, void *data)1251static irqreturn_t stm32_adc_isr(int irq, void *data)
1242{1252{
1243 struct stm32_adc *adc = data;1253 struct iio_dev *indio_dev = data;
1244 struct iio_dev *indio_dev = iio_priv_to_dev(adc);1254 struct stm32_adc *adc = iio_priv(indio_dev);
1245 const struct stm32_adc_regspec *regs = adc->cfg->regs;1255 const struct stm32_adc_regspec *regs = adc->cfg->regs;
1246 u32 status = stm32_adc_readl(adc, regs->isr_eoc.reg);1256 u32 status = stm32_adc_readl(adc, regs->isr_eoc.reg);
1247 1257
@@ -1482,7 +1492,7 @@ static int stm32_adc_dma_start(struct iio_dev *indio_dev) · 234 unmodified lines
1482 return 0;1492 return 0;
1483}1493}
1484 1494
1485static int __stm32_adc_buffer_postenable(struct iio_dev *indio_dev)1495static int stm32_adc_buffer_postenable(struct iio_dev *indio_dev)
1486{1496{
1487 struct stm32_adc *adc = iio_priv(indio_dev);1497 struct stm32_adc *adc = iio_priv(indio_dev);
1488 struct device *dev = indio_dev->dev.parent;1498 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
1514 if (!adc->dma_chan)1524 if (!adc->dma_chan)
1515 stm32_adc_conv_irq_enable(adc);1525 stm32_adc_conv_irq_enable(adc);
1516 1526
1517 adc->cfg->start_conv(adc, !!adc->dma_chan);1527 adc->cfg->start_conv(indio_dev, !!adc->dma_chan);
1518 1528
1519 return 0;1529 return 0;
1520 1530
@@ -1527,27 +1537,12 @@ err_pm_put: · 6 unmodified lines
1527 return ret;1537 return ret;
1528}1538}
1529 1539
1530static int stm32_adc_buffer_postenable(struct iio_dev *indio_dev)1540static int stm32_adc_buffer_predisable(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
1545static void __stm32_adc_buffer_predisable(struct iio_dev *indio_dev)
1546{1541{
1547 struct stm32_adc *adc = iio_priv(indio_dev);1542 struct stm32_adc *adc = iio_priv(indio_dev);
1548 struct device *dev = indio_dev->dev.parent;1543 struct device *dev = indio_dev->dev.parent;
1549 1544
1550 adc->cfg->stop_conv(adc);1545 adc->cfg->stop_conv(indio_dev);
1551 if (!adc->dma_chan)1546 if (!adc->dma_chan)
1552 stm32_adc_conv_irq_disable(adc);1547 stm32_adc_conv_irq_disable(adc);
1553 1548
@@ -1561,19 +1556,8 @@ static void __stm32_adc_buffer_predisable(struct iio_dev *indio_dev) · 7 unmodified lines
1561 1556
1562 pm_runtime_mark_last_busy(dev);1557 pm_runtime_mark_last_busy(dev);
1563 pm_runtime_put_autosuspend(dev);1558 pm_runtime_put_autosuspend(dev);
1564}
1565
1566static int stm32_adc_buffer_predisable(struct iio_dev *indio_dev)
1567{
1568 int ret;
1569 1559
1570 __stm32_adc_buffer_predisable(indio_dev);1560 return 0;
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;
1577}1561}
1578 1562
1579static const struct iio_buffer_setup_ops stm32_adc_buffer_setup_ops = {1563static 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
1886 of_match_device(dev->driver->of_match_table, dev)->data;1870 of_match_device(dev->driver->of_match_table, dev)->data;
1887 1871
1888 indio_dev->name = dev_name(&pdev->dev);1872 indio_dev->name = dev_name(&pdev->dev);
1889 indio_dev->dev.parent = &pdev->dev;
1890 indio_dev->dev.of_node = pdev->dev.of_node;1873 indio_dev->dev.of_node = pdev->dev.of_node;
1891 indio_dev->info = &stm32_adc_iio_info;1874 indio_dev->info = &stm32_adc_iio_info;
1892 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_HARDWARE_TRIGGERED;1875 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_HARDWARE_TRIGGERED;
1893 1876
1894 platform_set_drvdata(pdev, adc);1877 platform_set_drvdata(pdev, indio_dev);
1895 1878
1896 ret = of_property_read_u32(pdev->dev.of_node, "reg", &adc->offset);1879 ret = of_property_read_u32(pdev->dev.of_node, "reg", &adc->offset);
1897 if (ret != 0) {1880 if (ret != 0) {
@@ -1905,7 +1888,7 @@ static int stm32_adc_probe(struct platform_device *pdev) · 7 unmodified lines
1905 1888
1906 ret = devm_request_threaded_irq(&pdev->dev, adc->irq, stm32_adc_isr,1889 ret = devm_request_threaded_irq(&pdev->dev, adc->irq, stm32_adc_isr,
1907 stm32_adc_threaded_isr,1890 stm32_adc_threaded_isr,
1908 0, pdev->name, adc);1891 0, pdev->name, indio_dev);
1909 if (ret) {1892 if (ret) {
1910 dev_err(&pdev->dev, "failed to request IRQ\n");1893 dev_err(&pdev->dev, "failed to request IRQ\n");
1911 return ret;1894 return ret;
@@ -1989,8 +1972,8 @@ err_dma_disable: · 77 unmodified lines
1989 1972
1990static int stm32_adc_remove(struct platform_device *pdev)1973static int stm32_adc_remove(struct platform_device *pdev)
1991{1974{
1992 struct stm32_adc *adc = platform_get_drvdata(pdev);1975 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
1993 struct iio_dev *indio_dev = iio_priv_to_dev(adc);1976 struct stm32_adc *adc = iio_priv(indio_dev);
1994 1977
1995 pm_runtime_get_sync(&pdev->dev);1978 pm_runtime_get_sync(&pdev->dev);
1996 iio_device_unregister(indio_dev);1979 iio_device_unregister(indio_dev);
@@ -2012,19 +1995,17 @@ static int stm32_adc_remove(struct platform_device *pdev) · 15 unmodified lines
2012#if defined(CONFIG_PM_SLEEP)1995#if defined(CONFIG_PM_SLEEP)
2013static int stm32_adc_suspend(struct device *dev)1996static int stm32_adc_suspend(struct device *dev)
2014{1997{
2015 struct stm32_adc *adc = dev_get_drvdata(dev);1998 struct iio_dev *indio_dev = dev_get_drvdata(dev);
2016 struct iio_dev *indio_dev = iio_priv_to_dev(adc);
2017 1999
2018 if (iio_buffer_enabled(indio_dev))2000 if (iio_buffer_enabled(indio_dev))
2019 __stm32_adc_buffer_predisable(indio_dev);2001 stm32_adc_buffer_predisable(indio_dev);
2020 2002
2021 return pm_runtime_force_suspend(dev);2003 return pm_runtime_force_suspend(dev);
2022}2004}
2023 2005
2024static int stm32_adc_resume(struct device *dev)2006static int stm32_adc_resume(struct device *dev)
2025{2007{
2026 struct stm32_adc *adc = dev_get_drvdata(dev);2008 struct iio_dev *indio_dev = dev_get_drvdata(dev);
2027 struct iio_dev *indio_dev = iio_priv_to_dev(adc);
2028 int ret;2009 int ret;
2029 2010
2030 ret = pm_runtime_force_resume(dev);2011 ret = pm_runtime_force_resume(dev);
@@ -2039,7 +2020,7 @@ static int stm32_adc_resume(struct device *dev) · 8 unmodified lines
2039 if (ret < 0)2020 if (ret < 0)
2040 return ret;2021 return ret;
2041 2022
2042 return __stm32_adc_buffer_postenable(indio_dev);2023 return stm32_adc_buffer_postenable(indio_dev);
2043}2024}
2044#endif2025#endif
2045 2026
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
330 return 0;330 return 0;
331}331}
332 332
333static int stm32_dfsdm_start_channel(struct stm32_dfsdm_adc *adc)333static int stm32_dfsdm_start_channel(struct iio_dev *indio_dev)
334{334{
335 struct iio_dev *indio_dev = iio_priv_to_dev(adc);335 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
336 struct regmap *regmap = adc->dfsdm->regmap;336 struct regmap *regmap = adc->dfsdm->regmap;
337 const struct iio_chan_spec *chan;337 const struct iio_chan_spec *chan;
338 unsigned int bit;338 unsigned int bit;
@@ -350,9 +350,9 @@ static int stm32_dfsdm_start_channel(struct stm32_dfsdm_adc *adc) · 11 unmodified lines
350 return 0;350 return 0;
351}351}
352 352
353static void stm32_dfsdm_stop_channel(struct stm32_dfsdm_adc *adc)353static void stm32_dfsdm_stop_channel(struct iio_dev *indio_dev)
354{354{
355 struct iio_dev *indio_dev = iio_priv_to_dev(adc);355 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
356 struct regmap *regmap = adc->dfsdm->regmap;356 struct regmap *regmap = adc->dfsdm->regmap;
357 const struct iio_chan_spec *chan;357 const struct iio_chan_spec *chan;
358 unsigned int bit;358 unsigned int bit;
@@ -418,11 +418,11 @@ static void stm32_dfsdm_stop_filter(struct stm32_dfsdm *dfsdm, · 59 unmodified lines
418 DFSDM_CR1_DFEN_MASK, DFSDM_CR1_DFEN(0));418 DFSDM_CR1_DFEN_MASK, DFSDM_CR1_DFEN(0));
419}419}
420 420
421static int stm32_dfsdm_filter_set_trig(struct stm32_dfsdm_adc *adc,421static int stm32_dfsdm_filter_set_trig(struct iio_dev *indio_dev,
422 unsigned int fl_id,422 unsigned int fl_id,
423 struct iio_trigger *trig)423 struct iio_trigger *trig)
424{424{
425 struct iio_dev *indio_dev = iio_priv_to_dev(adc);425 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
426 struct regmap *regmap = adc->dfsdm->regmap;426 struct regmap *regmap = adc->dfsdm->regmap;
427 u32 jextsel = 0, jexten = STM32_DFSDM_JEXTEN_DISABLED;427 u32 jextsel = 0, jexten = STM32_DFSDM_JEXTEN_DISABLED;
428 int ret;428 int ret;
@@ -447,11 +447,11 @@ static int stm32_dfsdm_filter_set_trig(struct stm32_dfsdm_adc *adc, · 18 unmodified lines
447 return 0;447 return 0;
448}448}
449 449
450static int stm32_dfsdm_channels_configure(struct stm32_dfsdm_adc *adc,450static int stm32_dfsdm_channels_configure(struct iio_dev *indio_dev,
451 unsigned int fl_id,451 unsigned int fl_id,
452 struct iio_trigger *trig)452 struct iio_trigger *trig)
453{453{
454 struct iio_dev *indio_dev = iio_priv_to_dev(adc);454 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
455 struct regmap *regmap = adc->dfsdm->regmap;455 struct regmap *regmap = adc->dfsdm->regmap;
456 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[fl_id];456 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[fl_id];
457 struct stm32_dfsdm_filter_osr *flo = &fl->flo[0];457 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
491 return 0;491 return 0;
492}492}
493 493
494static int stm32_dfsdm_filter_configure(struct stm32_dfsdm_adc *adc,494static int stm32_dfsdm_filter_configure(struct iio_dev *indio_dev,
495 unsigned int fl_id,495 unsigned int fl_id,
496 struct iio_trigger *trig)496 struct iio_trigger *trig)
497{497{
498 struct iio_dev *indio_dev = iio_priv_to_dev(adc);498 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
499 struct regmap *regmap = adc->dfsdm->regmap;499 struct regmap *regmap = adc->dfsdm->regmap;
500 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[fl_id];500 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[fl_id];
501 struct stm32_dfsdm_filter_osr *flo = &fl->flo[fl->fast];501 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
521 if (ret)521 if (ret)
522 return ret;522 return ret;
523 523
524 ret = stm32_dfsdm_filter_set_trig(adc, fl_id, trig);524 ret = stm32_dfsdm_filter_set_trig(indio_dev, fl_id, trig);
525 if (ret)525 if (ret)
526 return ret;526 return ret;
527 527
@@ -729,21 +729,22 @@ static ssize_t dfsdm_adc_audio_set_spiclk(struct iio_dev *indio_dev, · 201 unmodified lines
729 return len;729 return len;
730}730}
731 731
732static int stm32_dfsdm_start_conv(struct stm32_dfsdm_adc *adc,732static int stm32_dfsdm_start_conv(struct iio_dev *indio_dev,
733 struct iio_trigger *trig)733 struct iio_trigger *trig)
734{734{
735 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
735 struct regmap *regmap = adc->dfsdm->regmap;736 struct regmap *regmap = adc->dfsdm->regmap;
736 int ret;737 int ret;
737 738
738 ret = stm32_dfsdm_channels_configure(adc, adc->fl_id, trig);739 ret = stm32_dfsdm_channels_configure(indio_dev, adc->fl_id, trig);
739 if (ret < 0)740 if (ret < 0)
740 return ret;741 return ret;
741 742
742 ret = stm32_dfsdm_start_channel(adc);743 ret = stm32_dfsdm_start_channel(indio_dev);
743 if (ret < 0)744 if (ret < 0)
744 return ret;745 return ret;
745 746
746 ret = stm32_dfsdm_filter_configure(adc, adc->fl_id, trig);747 ret = stm32_dfsdm_filter_configure(indio_dev, adc->fl_id, trig);
747 if (ret < 0)748 if (ret < 0)
748 goto stop_channels;749 goto stop_channels;
749 750
@@ -757,13 +758,14 @@ filter_unconfigure: · 7 unmodified lines
757 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),758 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),
758 DFSDM_CR1_CFG_MASK, 0);759 DFSDM_CR1_CFG_MASK, 0);
759stop_channels:760stop_channels:
760 stm32_dfsdm_stop_channel(adc);761 stm32_dfsdm_stop_channel(indio_dev);
761 762
762 return ret;763 return ret;
763}764}
764 765
765static void stm32_dfsdm_stop_conv(struct stm32_dfsdm_adc *adc)766static void stm32_dfsdm_stop_conv(struct iio_dev *indio_dev)
766{767{
768 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
767 struct regmap *regmap = adc->dfsdm->regmap;769 struct regmap *regmap = adc->dfsdm->regmap;
768 770
769 stm32_dfsdm_stop_filter(adc->dfsdm, adc->fl_id);771 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
771 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),773 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),
772 DFSDM_CR1_CFG_MASK, 0);774 DFSDM_CR1_CFG_MASK, 0);
773 775
774 stm32_dfsdm_stop_channel(adc);776 stm32_dfsdm_stop_channel(indio_dev);
775}777}
776 778
777static int stm32_dfsdm_set_watermark(struct iio_dev *indio_dev,779static 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
993 return 0;995 return 0;
994}996}
995 997
996static int __stm32_dfsdm_postenable(struct iio_dev *indio_dev)998static int stm32_dfsdm_postenable(struct iio_dev *indio_dev)
997{999{
998 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);1000 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
999 int ret;1001 int ret;
@@ -1017,7 +1019,7 @@ static int __stm32_dfsdm_postenable(struct iio_dev *indio_dev) · 17 unmodified lines
1017 goto stop_dfsdm;1019 goto stop_dfsdm;
1018 }1020 }
1019 1021
1020 ret = stm32_dfsdm_start_conv(adc, indio_dev->trig);1022 ret = stm32_dfsdm_start_conv(indio_dev, indio_dev->trig);
1021 if (ret) {1023 if (ret) {
1022 dev_err(&indio_dev->dev, "Can't start conversion\n");1024 dev_err(&indio_dev->dev, "Can't start conversion\n");
1023 goto err_stop_dma;1025 goto err_stop_dma;
@@ -1036,34 +1038,11 @@ err_stop_hwc: · 12 unmodified lines
1036 return ret;1038 return ret;
1037}1039}
1038 1040
1039static int stm32_dfsdm_postenable(struct iio_dev *indio_dev)1041static int stm32_dfsdm_predisable(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
1055err_predisable:
1056 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1057 iio_triggered_buffer_predisable(indio_dev);
1058
1059 return ret;
1060}
1061
1062static void __stm32_dfsdm_predisable(struct iio_dev *indio_dev)
1063{1042{
1064 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);1043 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
1065 1044
1066 stm32_dfsdm_stop_conv(adc);1045 stm32_dfsdm_stop_conv(indio_dev);
1067 1046
1068 stm32_dfsdm_adc_dma_stop(indio_dev);1047 stm32_dfsdm_adc_dma_stop(indio_dev);
1069 1048
@@ -1071,14 +1050,6 @@ static void __stm32_dfsdm_predisable(struct iio_dev *indio_dev) · 1 unmodified line
1071 1050
1072 if (adc->hwc)1051 if (adc->hwc)
1073 iio_hw_consumer_disable(adc->hwc);1052 iio_hw_consumer_disable(adc->hwc);
1074}
1075
1076static 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);
1082 1053
1083 return 0;1054 return 0;
1084}1055}
@@ -1159,7 +1130,7 @@ static int stm32_dfsdm_single_conv(struct iio_dev *indio_dev, · 74 unmodified lines
1159 1130
1160 adc->nconv = 1;1131 adc->nconv = 1;
1161 adc->smask = BIT(chan->scan_index);1132 adc->smask = BIT(chan->scan_index);
1162 ret = stm32_dfsdm_start_conv(adc, NULL);1133 ret = stm32_dfsdm_start_conv(indio_dev, NULL);
1163 if (ret < 0) {1134 if (ret < 0) {
1164 regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id),1135 regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id),
1165 DFSDM_CR2_REOCIE_MASK, DFSDM_CR2_REOCIE(0));1136 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
1180 else1151 else
1181 ret = IIO_VAL_INT;1152 ret = IIO_VAL_INT;
1182 1153
1183 stm32_dfsdm_stop_conv(adc);1154 stm32_dfsdm_stop_conv(indio_dev);
1184 1155
1185 stm32_dfsdm_process_data(adc, res);1156 stm32_dfsdm_process_data(adc, res);
1186 1157
@@ -1313,8 +1284,8 @@ static const struct iio_info stm32_dfsdm_info_adc = { · 126 unmodified lines
1313 1284
1314static irqreturn_t stm32_dfsdm_irq(int irq, void *arg)1285static irqreturn_t stm32_dfsdm_irq(int irq, void *arg)
1315{1286{
1316 struct stm32_dfsdm_adc *adc = arg;1287 struct iio_dev *indio_dev = arg;
1317 struct iio_dev *indio_dev = iio_priv_to_dev(adc);1288 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
1318 struct regmap *regmap = adc->dfsdm->regmap;1289 struct regmap *regmap = adc->dfsdm->regmap;
1319 unsigned int status, int_en;1290 unsigned int status, int_en;
1320 1291
@@ -1571,11 +1542,10 @@ static int stm32_dfsdm_adc_probe(struct platform_device *pdev) · 250 unmodified lines
1571 adc = iio_priv(iio);1542 adc = iio_priv(iio);
1572 adc->dfsdm = dev_get_drvdata(dev->parent);1543 adc->dfsdm = dev_get_drvdata(dev->parent);
1573 1544
1574 iio->dev.parent = dev;
1575 iio->dev.of_node = np;1545 iio->dev.of_node = np;
1576 iio->modes = INDIO_DIRECT_MODE;1546 iio->modes = INDIO_DIRECT_MODE;
1577 1547
1578 platform_set_drvdata(pdev, adc);1548 platform_set_drvdata(pdev, iio);
1579 1549
1580 ret = of_property_read_u32(dev->of_node, "reg", &adc->fl_id);1550 ret = of_property_read_u32(dev->of_node, "reg", &adc->fl_id);
1581 if (ret != 0 || adc->fl_id >= adc->dfsdm->num_fls) {1551 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
1604 return irq;1574 return irq;
1605 1575
1606 ret = devm_request_irq(dev, irq, stm32_dfsdm_irq,1576 ret = devm_request_irq(dev, irq, stm32_dfsdm_irq,
1607 0, pdev->name, adc);1577 0, pdev->name, iio);
1608 if (ret < 0) {1578 if (ret < 0) {
1609 dev_err(dev, "Failed to request IRQ\n");1579 dev_err(dev, "Failed to request IRQ\n");
1610 return ret;1580 return ret;
@@ -1651,8 +1621,8 @@ err_cleanup: · 40 unmodified lines
1651 1621
1652static int stm32_dfsdm_adc_remove(struct platform_device *pdev)1622static int stm32_dfsdm_adc_remove(struct platform_device *pdev)
1653{1623{
1654 struct stm32_dfsdm_adc *adc = platform_get_drvdata(pdev);1624 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
1655 struct iio_dev *indio_dev = iio_priv_to_dev(adc);1625 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
1656 1626
1657 if (adc->dev_data->type == DFSDM_AUDIO)1627 if (adc->dev_data->type == DFSDM_AUDIO)
1658 of_platform_depopulate(&pdev->dev);1628 of_platform_depopulate(&pdev->dev);
@@ -1664,19 +1634,18 @@ static int stm32_dfsdm_adc_remove(struct platform_device *pdev) · 5 unmodified lines
1664 1634
1665static int __maybe_unused stm32_dfsdm_adc_suspend(struct device *dev)1635static int __maybe_unused stm32_dfsdm_adc_suspend(struct device *dev)
1666{1636{
1667 struct stm32_dfsdm_adc *adc = dev_get_drvdata(dev);1637 struct iio_dev *indio_dev = dev_get_drvdata(dev);
1668 struct iio_dev *indio_dev = iio_priv_to_dev(adc);
1669 1638
1670 if (iio_buffer_enabled(indio_dev))1639 if (iio_buffer_enabled(indio_dev))
1671 __stm32_dfsdm_predisable(indio_dev);1640 stm32_dfsdm_predisable(indio_dev);
1672 1641
1673 return 0;1642 return 0;
1674}1643}
1675 1644
1676static int __maybe_unused stm32_dfsdm_adc_resume(struct device *dev)1645static int __maybe_unused stm32_dfsdm_adc_resume(struct device *dev)
1677{1646{
1678 struct stm32_dfsdm_adc *adc = dev_get_drvdata(dev);1647 struct iio_dev *indio_dev = dev_get_drvdata(dev);
1679 struct iio_dev *indio_dev = iio_priv_to_dev(adc);1648 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
1680 const struct iio_chan_spec *chan;1649 const struct iio_chan_spec *chan;
1681 struct stm32_dfsdm_channel *ch;1650 struct stm32_dfsdm_channel *ch;
1682 int i, ret;1651 int i, ret;
@@ -1691,7 +1660,7 @@ static int __maybe_unused stm32_dfsdm_adc_resume(struct device *dev) · 8 unmodified lines
1691 }1660 }
1692 1661
1693 if (iio_buffer_enabled(indio_dev))1662 if (iio_buffer_enabled(indio_dev))
1694 __stm32_dfsdm_postenable(indio_dev);1663 stm32_dfsdm_postenable(indio_dev);
1695 1664
1696 return 0;1665 return 0;
1697}1666}
drivers/iio/adc/stmpe-adc.c+0−1
@@ -297,7 +297,6 @@ static int stmpe_adc_probe(struct platform_device *pdev) · 296 unmodified lines
297 platform_set_drvdata(pdev, indio_dev);297 platform_set_drvdata(pdev, indio_dev);
298 298
299 indio_dev->name = dev_name(&pdev->dev);299 indio_dev->name = dev_name(&pdev->dev);
300 indio_dev->dev.parent = &pdev->dev;
301 indio_dev->info = &stmpe_adc_iio_info;300 indio_dev->info = &stmpe_adc_iio_info;
302 indio_dev->modes = INDIO_DIRECT_MODE;301 indio_dev->modes = INDIO_DIRECT_MODE;
303 302
drivers/iio/adc/stx104.c+0−1
@@ -319,7 +319,6 @@ static int stx104_probe(struct device *dev, unsigned int id) · 318 unmodified lines
319 }319 }
320 320
321 indio_dev->name = dev_name(dev);321 indio_dev->name = dev_name(dev);
322 indio_dev->dev.parent = dev;
323 322
324 priv = iio_priv(indio_dev);323 priv = iio_priv(indio_dev);
325 priv->base = base[id];324 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
619 info->indio_dev = indio_dev;619 info->indio_dev = indio_dev;
620 init_completion(&info->completion);620 init_completion(&info->completion);
621 indio_dev->name = dev_name(&pdev->dev);621 indio_dev->name = dev_name(&pdev->dev);
622 indio_dev->dev.parent = &pdev->dev;
623 indio_dev->dev.of_node = pdev->dev.of_node;
624 indio_dev->info = &sun4i_gpadc_iio_info;622 indio_dev->info = &sun4i_gpadc_iio_info;
625 indio_dev->modes = INDIO_DIRECT_MODE;623 indio_dev->modes = INDIO_DIRECT_MODE;
626 624
drivers/iio/adc/ti-adc081c.c+5−9
@@ -6,9 +6,9 @@ · 5 unmodified lines
6 * Copyright (C) 2016 Intel6 * Copyright (C) 2016 Intel
7 *7 *
8 * Datasheets:8 * Datasheets:
9 * http://www.ti.com/lit/ds/symlink/adc081c021.pdf9 * https://www.ti.com/lit/ds/symlink/adc081c021.pdf
10 * http://www.ti.com/lit/ds/symlink/adc101c021.pdf10 * https://www.ti.com/lit/ds/symlink/adc101c021.pdf
11 * http://www.ti.com/lit/ds/symlink/adc121c021.pdf11 * https://www.ti.com/lit/ds/symlink/adc121c021.pdf
12 *12 *
13 * The devices have a very similar interface and differ mostly in the number of13 * The devices have a very similar interface and differ mostly in the number of
14 * bits handled. For the 8-bit and 10-bit models the least-significant 4 or 214 * bits handled. For the 8-bit and 10-bit models the least-significant 4 or 2
@@ -18,7 +18,7 @@ · 3 unmodified lines
18#include <linux/err.h>18#include <linux/err.h>
19#include <linux/i2c.h>19#include <linux/i2c.h>
20#include <linux/module.h>20#include <linux/module.h>
21#include <linux/of.h>21#include <linux/mod_devicetable.h>
22#include <linux/acpi.h>22#include <linux/acpi.h>
23 23
24#include <linux/iio/iio.h>24#include <linux/iio/iio.h>
@@ -181,8 +181,6 @@ static int adc081c_probe(struct i2c_client *client, · 156 unmodified lines
181 if (err < 0)181 if (err < 0)
182 return err;182 return err;
183 183
184 iio->dev.parent = &client->dev;
185 iio->dev.of_node = client->dev.of_node;
186 iio->name = dev_name(&client->dev);184 iio->name = dev_name(&client->dev);
187 iio->modes = INDIO_DIRECT_MODE;185 iio->modes = INDIO_DIRECT_MODE;
188 iio->info = &adc081c_info;186 iio->info = &adc081c_info;
@@ -232,7 +230,6 @@ static const struct i2c_device_id adc081c_id[] = { · 43 unmodified lines
232};230};
233MODULE_DEVICE_TABLE(i2c, adc081c_id);231MODULE_DEVICE_TABLE(i2c, adc081c_id);
234 232
235#ifdef CONFIG_OF
236static const struct of_device_id adc081c_of_match[] = {233static const struct of_device_id adc081c_of_match[] = {
237 { .compatible = "ti,adc081c" },234 { .compatible = "ti,adc081c" },
238 { .compatible = "ti,adc101c" },235 { .compatible = "ti,adc101c" },
@@ -240,7 +237,6 @@ static const struct of_device_id adc081c_of_match[] = { · 1 unmodified line
240 { }237 { }
241};238};
242MODULE_DEVICE_TABLE(of, adc081c_of_match);239MODULE_DEVICE_TABLE(of, adc081c_of_match);
243#endif
244 240
245#ifdef CONFIG_ACPI241#ifdef CONFIG_ACPI
246static const struct acpi_device_id adc081c_acpi_match[] = {242static const struct acpi_device_id adc081c_acpi_match[] = {
@@ -255,7 +251,7 @@ MODULE_DEVICE_TABLE(acpi, adc081c_acpi_match); · 8 unmodified lines
255static struct i2c_driver adc081c_driver = {251static struct i2c_driver adc081c_driver = {
256 .driver = {252 .driver = {
257 .name = "adc081c",253 .name = "adc081c",
258 .of_match_table = of_match_ptr(adc081c_of_match),254 .of_match_table = adc081c_of_match,
259 .acpi_match_table = ACPI_PTR(adc081c_acpi_match),255 .acpi_match_table = ACPI_PTR(adc081c_acpi_match),
260 },256 },
261 .probe = adc081c_probe,257 .probe = adc081c_probe,
drivers/iio/adc/ti-adc0832.c+3−8
@@ -4,10 +4,11 @@ · 3 unmodified lines
4 *4 *
5 * Copyright (c) 2016 Akinobu Mita <akinobu.mita@gmail.com>5 * Copyright (c) 2016 Akinobu Mita <akinobu.mita@gmail.com>
6 *6 *
7 * Datasheet: http://www.ti.com/lit/ds/symlink/adc0832-n.pdf7 * Datasheet: https://www.ti.com/lit/ds/symlink/adc0832-n.pdf
8 */8 */
9 9
10#include <linux/module.h>10#include <linux/module.h>
11#include <linux/mod_devicetable.h>
11#include <linux/spi/spi.h>12#include <linux/spi/spi.h>
12#include <linux/iio/iio.h>13#include <linux/iio/iio.h>
13#include <linux/regulator/consumer.h>14#include <linux/regulator/consumer.h>
@@ -245,8 +246,6 @@ static int adc0832_probe(struct spi_device *spi) · 231 unmodified lines
245 mutex_init(&adc->lock);246 mutex_init(&adc->lock);
246 247
247 indio_dev->name = spi_get_device_id(spi)->name;248 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;
250 indio_dev->info = &adc0832_info;249 indio_dev->info = &adc0832_info;
251 indio_dev->modes = INDIO_DIRECT_MODE;250 indio_dev->modes = INDIO_DIRECT_MODE;
252 251
@@ -315,8 +314,6 @@ static int adc0832_remove(struct spi_device *spi) · 62 unmodified lines
315 return 0;314 return 0;
316}315}
317 316
318#ifdef CONFIG_OF
319
320static const struct of_device_id adc0832_dt_ids[] = {317static const struct of_device_id adc0832_dt_ids[] = {
321 { .compatible = "ti,adc0831", },318 { .compatible = "ti,adc0831", },
322 { .compatible = "ti,adc0832", },319 { .compatible = "ti,adc0832", },
@@ -326,8 +323,6 @@ static const struct of_device_id adc0832_dt_ids[] = { · 3 unmodified lines
326};323};
327MODULE_DEVICE_TABLE(of, adc0832_dt_ids);324MODULE_DEVICE_TABLE(of, adc0832_dt_ids);
328 325
329#endif
330
331static const struct spi_device_id adc0832_id[] = {326static const struct spi_device_id adc0832_id[] = {
332 { "adc0831", adc0831 },327 { "adc0831", adc0831 },
333 { "adc0832", adc0832 },328 { "adc0832", adc0832 },
@@ -340,7 +335,7 @@ MODULE_DEVICE_TABLE(spi, adc0832_id); · 6 unmodified lines
340static struct spi_driver adc0832_driver = {335static struct spi_driver adc0832_driver = {
341 .driver = {336 .driver = {
342 .name = "adc0832",337 .name = "adc0832",
343 .of_match_table = of_match_ptr(adc0832_dt_ids),338 .of_match_table = adc0832_dt_ids,
344 },339 },
345 .probe = adc0832_probe,340 .probe = adc0832_probe,
346 .remove = adc0832_remove,341 .remove = adc0832_remove,
drivers/iio/adc/ti-adc084s021.c+3−6
@@ -4,12 +4,13 @@ · 3 unmodified lines
4 *4 *
5 * Driver for Texas Instruments' ADC084S021 ADC chip.5 * Driver for Texas Instruments' ADC084S021 ADC chip.
6 * Datasheets can be found here:6 * Datasheets can be found here:
7 * http://www.ti.com/lit/ds/symlink/adc084s021.pdf7 * https://www.ti.com/lit/ds/symlink/adc084s021.pdf
8 */8 */
9 9
10#include <linux/err.h>10#include <linux/err.h>
11#include <linux/spi/spi.h>11#include <linux/spi/spi.h>
12#include <linux/module.h>12#include <linux/module.h>
13#include <linux/mod_devicetable.h>
13#include <linux/interrupt.h>14#include <linux/interrupt.h>
14#include <linux/iio/iio.h>15#include <linux/iio/iio.h>
15#include <linux/iio/buffer.h>16#include <linux/iio/buffer.h>
@@ -187,8 +188,6 @@ static const struct iio_info adc084s021_info = { · 171 unmodified lines
187 188
188static const struct iio_buffer_setup_ops adc084s021_buffer_setup_ops = {189static const struct iio_buffer_setup_ops adc084s021_buffer_setup_ops = {
189 .preenable = adc084s021_buffer_preenable,190 .preenable = adc084s021_buffer_preenable,
190 .postenable = iio_triggered_buffer_postenable,
191 .predisable = iio_triggered_buffer_predisable,
192 .postdisable = adc084s021_buffer_postdisable,191 .postdisable = adc084s021_buffer_postdisable,
193};192};
194 193
@@ -211,8 +210,6 @@ static int adc084s021_probe(struct spi_device *spi) · 16 unmodified lines
211 spi_set_drvdata(spi, indio_dev);210 spi_set_drvdata(spi, indio_dev);
212 211
213 /* Initiate the Industrial I/O device */212 /* Initiate the Industrial I/O device */
214 indio_dev->dev.parent = &spi->dev;
215 indio_dev->dev.of_node = spi->dev.of_node;
216 indio_dev->name = spi_get_device_id(spi)->name;213 indio_dev->name = spi_get_device_id(spi)->name;
217 indio_dev->modes = INDIO_DIRECT_MODE;214 indio_dev->modes = INDIO_DIRECT_MODE;
218 indio_dev->info = &adc084s021_info;215 indio_dev->info = &adc084s021_info;
@@ -258,7 +255,7 @@ MODULE_DEVICE_TABLE(spi, adc084s021_id); · 39 unmodified lines
258static struct spi_driver adc084s021_driver = {255static struct spi_driver adc084s021_driver = {
259 .driver = {256 .driver = {
260 .name = ADC084S021_DRIVER_NAME,257 .name = ADC084S021_DRIVER_NAME,
261 .of_match_table = of_match_ptr(adc084s021_of_match),258 .of_match_table = adc084s021_of_match,
262 },259 },
263 .probe = adc084s021_probe,260 .probe = adc084s021_probe,
264 .id_table = adc084s021_id,261 .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
252 st->spi = spi;252 st->spi = spi;
253 253
254 indio_dev->name = spi->modalias;254 indio_dev->name = spi->modalias;
255 indio_dev->dev.parent = &spi->dev;
256 indio_dev->modes = INDIO_DIRECT_MODE;255 indio_dev->modes = INDIO_DIRECT_MODE;
257 indio_dev->channels = adc108s102_channels;256 indio_dev->channels = adc108s102_channels;
258 indio_dev->num_channels = ARRAY_SIZE(adc108s102_channels);257 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
407 init_completion(&adc->complete);407 init_completion(&adc->complete);
408 408
409 indio_dev->name = spi_get_device_id(spi)->name;409 indio_dev->name = spi_get_device_id(spi)->name;
410 indio_dev->dev.parent = &spi->dev;
411 indio_dev->info = &adc12138_info;410 indio_dev->info = &adc12138_info;
412 indio_dev->modes = INDIO_DIRECT_MODE;411 indio_dev->modes = INDIO_DIRECT_MODE;
413 412
drivers/iio/adc/ti-adc128s052.c+3−5
@@ -4,9 +4,9 @@ · 3 unmodified lines
4 *4 *
5 * Driver for Texas Instruments' ADC128S052, ADC122S021 and ADC124S021 ADC chip.5 * Driver for Texas Instruments' ADC128S052, ADC122S021 and ADC124S021 ADC chip.
6 * Datasheets can be found here:6 * Datasheets can be found here:
7 * http://www.ti.com/lit/ds/symlink/adc128s052.pdf7 * https://www.ti.com/lit/ds/symlink/adc128s052.pdf
8 * http://www.ti.com/lit/ds/symlink/adc122s021.pdf8 * https://www.ti.com/lit/ds/symlink/adc122s021.pdf
9 * http://www.ti.com/lit/ds/symlink/adc124s021.pdf9 * https://www.ti.com/lit/ds/symlink/adc124s021.pdf
10 */10 */
11 11
12#include <linux/acpi.h>12#include <linux/acpi.h>
@@ -152,8 +152,6 @@ static int adc128_probe(struct spi_device *spi) · 139 unmodified lines
152 152
153 spi_set_drvdata(spi, indio_dev);153 spi_set_drvdata(spi, indio_dev);
154 154
155 indio_dev->dev.parent = &spi->dev;
156 indio_dev->dev.of_node = spi->dev.of_node;
157 indio_dev->name = spi_get_device_id(spi)->name;155 indio_dev->name = spi_get_device_id(spi)->name;
158 indio_dev->modes = INDIO_DIRECT_MODE;156 indio_dev->modes = INDIO_DIRECT_MODE;
159 indio_dev->info = &adc128_info;157 indio_dev->info = &adc128_info;
drivers/iio/adc/ti-adc161s626.c+2−3
@@ -11,6 +11,7 @@ · 10 unmodified lines
11 */11 */
12 12
13#include <linux/module.h>13#include <linux/module.h>
14#include <linux/mod_devicetable.h>
14#include <linux/init.h>15#include <linux/init.h>
15#include <linux/err.h>16#include <linux/err.h>
16#include <linux/spi/spi.h>17#include <linux/spi/spi.h>
@@ -179,8 +180,6 @@ static int ti_adc_probe(struct spi_device *spi) · 162 unmodified lines
179 return -ENOMEM;180 return -ENOMEM;
180 181
181 indio_dev->info = &ti_adc_info;182 indio_dev->info = &ti_adc_info;
182 indio_dev->dev.parent = &spi->dev;
183 indio_dev->dev.of_node = spi->dev.of_node;
184 indio_dev->name = TI_ADC_DRV_NAME;183 indio_dev->name = TI_ADC_DRV_NAME;
185 indio_dev->modes = INDIO_DIRECT_MODE;184 indio_dev->modes = INDIO_DIRECT_MODE;
186 spi_set_drvdata(spi, indio_dev);185 spi_set_drvdata(spi, indio_dev);
@@ -259,7 +258,7 @@ MODULE_DEVICE_TABLE(spi, ti_adc_id); · 72 unmodified lines
259static struct spi_driver ti_adc_driver = {258static struct spi_driver ti_adc_driver = {
260 .driver = {259 .driver = {
261 .name = TI_ADC_DRV_NAME,260 .name = TI_ADC_DRV_NAME,
262 .of_match_table = of_match_ptr(ti_adc_dt_ids),261 .of_match_table = ti_adc_dt_ids,
263 },262 },
264 .probe = ti_adc_probe,263 .probe = ti_adc_probe,
265 .remove = ti_adc_remove,264 .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
788 788
789static const struct iio_buffer_setup_ops ads1015_buffer_setup_ops = {789static const struct iio_buffer_setup_ops ads1015_buffer_setup_ops = {
790 .preenable = ads1015_buffer_preenable,790 .preenable = ads1015_buffer_preenable,
791 .postenable = iio_triggered_buffer_postenable,
792 .predisable = iio_triggered_buffer_predisable,
793 .postdisable = ads1015_buffer_postdisable,791 .postdisable = ads1015_buffer_postdisable,
794 .validate_scan_mask = &iio_validate_scan_mask_onehot,792 .validate_scan_mask = &iio_validate_scan_mask_onehot,
795};793};
@@ -939,8 +937,6 @@ static int ads1015_probe(struct i2c_client *client, · 143 unmodified lines
939 937
940 mutex_init(&data->lock);938 mutex_init(&data->lock);
941 939
942 indio_dev->dev.parent = &client->dev;
943 indio_dev->dev.of_node = client->dev.of_node;
944 indio_dev->name = ADS1015_DRV_NAME;940 indio_dev->name = ADS1015_DRV_NAME;
945 indio_dev->modes = INDIO_DIRECT_MODE;941 indio_dev->modes = INDIO_DIRECT_MODE;
946 942
drivers/iio/adc/ti-ads124s08.c+1−3
@@ -1,6 +1,6 @@
1// SPDX-License-Identifier: GPL-2.01// SPDX-License-Identifier: GPL-2.0
2/* TI ADS124S0X chip family driver2/* 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/
4 */4 */
5 5
6#include <linux/err.h>6#include <linux/err.h>
@@ -325,8 +325,6 @@ static int ads124s_probe(struct spi_device *spi) · 318 unmodified lines
325 ads124s_priv->spi = spi;325 ads124s_priv->spi = spi;
326 326
327 indio_dev->name = spi_id->name;327 indio_dev->name = spi_id->name;
328 indio_dev->dev.parent = &spi->dev;
329 indio_dev->dev.of_node = spi->dev.of_node;
330 indio_dev->modes = INDIO_DIRECT_MODE;328 indio_dev->modes = INDIO_DIRECT_MODE;
331 indio_dev->channels = ads124s_priv->chip_info->channels;329 indio_dev->channels = ads124s_priv->chip_info->channels;
332 indio_dev->num_channels = ads124s_priv->chip_info->num_channels;330 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
9 * Copyright 2012 CS Systemes d'Information9 * Copyright 2012 CS Systemes d'Information
10 *10 *
11 * And also on hwmon/ads79xx.c11 * 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/
13 * Nishanth Menon13 * Nishanth Menon
14 */14 */
15 15
@@ -557,7 +557,6 @@ static int ti_ads7950_probe(struct spi_device *spi) · 541 unmodified lines
557 info = &ti_ads7950_chip_info[spi_get_device_id(spi)->driver_data];557 info = &ti_ads7950_chip_info[spi_get_device_id(spi)->driver_data];
558 558
559 indio_dev->name = spi_get_device_id(spi)->name;559 indio_dev->name = spi_get_device_id(spi)->name;
560 indio_dev->dev.parent = &spi->dev;
561 indio_dev->modes = INDIO_DIRECT_MODE;560 indio_dev->modes = INDIO_DIRECT_MODE;
562 indio_dev->channels = info->channels;561 indio_dev->channels = info->channels;
563 indio_dev->num_channels = info->num_channels;562 indio_dev->num_channels = info->num_channels;
drivers/iio/adc/ti-ads8344.c+1−3
@@ -4,7 +4,7 @@ · 3 unmodified lines
4 *4 *
5 * Author: Gregory CLEMENT <gregory.clement@bootlin.com>5 * Author: Gregory CLEMENT <gregory.clement@bootlin.com>
6 *6 *
7 * Datasheet: http://www.ti.com/lit/ds/symlink/ads8344.pdf7 * Datasheet: https://www.ti.com/lit/ds/symlink/ads8344.pdf
8 */8 */
9 9
10#include <linux/delay.h>10#include <linux/delay.h>
@@ -148,8 +148,6 @@ static int ads8344_probe(struct spi_device *spi) · 137 unmodified lines
148 mutex_init(&adc->lock);148 mutex_init(&adc->lock);
149 149
150 indio_dev->name = dev_name(&spi->dev);150 indio_dev->name = dev_name(&spi->dev);
151 indio_dev->dev.parent = &spi->dev;
152 indio_dev->dev.of_node = spi->dev.of_node;
153 indio_dev->info = &ads8344_info;151 indio_dev->info = &ads8344_info;
154 indio_dev->modes = INDIO_DIRECT_MODE;152 indio_dev->modes = INDIO_DIRECT_MODE;
155 indio_dev->channels = ads8344_channels;153 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
449 st->spi = spi;449 st->spi = spi;
450 450
451 indio_dev->name = spi_get_device_id(spi)->name;451 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;
454 indio_dev->modes = INDIO_DIRECT_MODE;452 indio_dev->modes = INDIO_DIRECT_MODE;
455 indio_dev->channels = st->chip_info->channels;453 indio_dev->channels = st->chip_info->channels;
456 indio_dev->num_channels = st->chip_info->num_channels;454 indio_dev->num_channels = st->chip_info->num_channels;
drivers/iio/adc/ti-tlc4541.c+4−6
@@ -5,8 +5,8 @@ · 4 unmodified lines
5 * Copyright (C) 2017 Phil Reid5 * Copyright (C) 2017 Phil Reid
6 *6 *
7 * Datasheets can be found here:7 * Datasheets can be found here:
8 * http://www.ti.com/lit/gpn/tlc35418 * https://www.ti.com/lit/gpn/tlc3541
9 * http://www.ti.com/lit/gpn/tlc45419 * https://www.ti.com/lit/gpn/tlc4541
10 *10 *
11 * The tlc4541 requires 24 clock cycles to start a transfer.11 * The tlc4541 requires 24 clock cycles to start a transfer.
12 * Conversion then takes 2.94us to complete before data is ready12 * Conversion then takes 2.94us to complete before data is ready
@@ -24,6 +24,7 @@ · 11 unmodified lines
24#include <linux/iio/triggered_buffer.h>24#include <linux/iio/triggered_buffer.h>
25#include <linux/kernel.h>25#include <linux/kernel.h>
26#include <linux/module.h>26#include <linux/module.h>
27#include <linux/mod_devicetable.h>
27#include <linux/regulator/consumer.h>28#include <linux/regulator/consumer.h>
28#include <linux/slab.h>29#include <linux/slab.h>
29#include <linux/spi/spi.h>30#include <linux/spi/spi.h>
@@ -177,7 +178,6 @@ static int tlc4541_probe(struct spi_device *spi) · 147 unmodified lines
177 info = &tlc4541_chip_info[spi_get_device_id(spi)->driver_data];178 info = &tlc4541_chip_info[spi_get_device_id(spi)->driver_data];
178 179
179 indio_dev->name = spi_get_device_id(spi)->name;180 indio_dev->name = spi_get_device_id(spi)->name;
180 indio_dev->dev.parent = &spi->dev;
181 indio_dev->modes = INDIO_DIRECT_MODE;181 indio_dev->modes = INDIO_DIRECT_MODE;
182 indio_dev->channels = info->channels;182 indio_dev->channels = info->channels;
183 indio_dev->num_channels = info->num_channels;183 indio_dev->num_channels = info->num_channels;
@@ -236,14 +236,12 @@ static int tlc4541_remove(struct spi_device *spi) · 52 unmodified lines
236 return 0;236 return 0;
237}237}
238 238
239#ifdef CONFIG_OF
240static const struct of_device_id tlc4541_dt_ids[] = {239static const struct of_device_id tlc4541_dt_ids[] = {
241 { .compatible = "ti,tlc3541", },240 { .compatible = "ti,tlc3541", },
242 { .compatible = "ti,tlc4541", },241 { .compatible = "ti,tlc4541", },
243 {}242 {}
244};243};
245MODULE_DEVICE_TABLE(of, tlc4541_dt_ids);244MODULE_DEVICE_TABLE(of, tlc4541_dt_ids);
246#endif
247 245
248static const struct spi_device_id tlc4541_id[] = {246static const struct spi_device_id tlc4541_id[] = {
249 {"tlc3541", TLC3541},247 {"tlc3541", TLC3541},
@@ -255,7 +253,7 @@ MODULE_DEVICE_TABLE(spi, tlc4541_id); · 5 unmodified lines
255static struct spi_driver tlc4541_driver = {253static struct spi_driver tlc4541_driver = {
256 .driver = {254 .driver = {
257 .name = "tlc4541",255 .name = "tlc4541",
258 .of_match_table = of_match_ptr(tlc4541_dt_ids),256 .of_match_table = tlc4541_dt_ids,
259 },257 },
260 .probe = tlc4541_probe,258 .probe = tlc4541_probe,
261 .remove = tlc4541_remove,259 .remove = tlc4541_remove,
drivers/iio/adc/ti_am335x_adc.c+11−27
@@ -1,7 +1,7 @@
1/*1/*
2 * TI ADC MFD driver2 * TI ADC MFD driver
3 *3 *
4 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/4 * Copyright (C) 2012 Texas Instruments Incorporated - https://www.ti.com/
5 *5 *
6 * This program is free software; you can redistribute it and/or6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as7 * 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
377 .postdisable = &tiadc_buffer_postdisable,377 .postdisable = &tiadc_buffer_postdisable,
378};378};
379 379
380static int tiadc_iio_buffered_hardware_setup(struct iio_dev *indio_dev,380static int tiadc_iio_buffered_hardware_setup(struct device *dev,
381 struct iio_dev *indio_dev,
381 irqreturn_t (*pollfunc_bh)(int irq, void *p),382 irqreturn_t (*pollfunc_bh)(int irq, void *p),
382 irqreturn_t (*pollfunc_th)(int irq, void *p),383 irqreturn_t (*pollfunc_th)(int irq, void *p),
383 int irq,384 int irq,
@@ -387,13 +388,13 @@ static int tiadc_iio_buffered_hardware_setup(struct iio_dev *indio_dev, · 3 unmodified lines
387 struct iio_buffer *buffer;388 struct iio_buffer *buffer;
388 int ret;389 int ret;
389 390
390 buffer = iio_kfifo_allocate();391 buffer = devm_iio_kfifo_allocate(dev);
391 if (!buffer)392 if (!buffer)
392 return -ENOMEM;393 return -ENOMEM;
393 394
394 iio_device_attach_buffer(indio_dev, buffer);395 iio_device_attach_buffer(indio_dev, buffer);
395 396
396 ret = request_threaded_irq(irq, pollfunc_th, pollfunc_bh,397 ret = devm_request_threaded_irq(dev, irq, pollfunc_th, pollfunc_bh,
397 flags, indio_dev->name, indio_dev);398 flags, indio_dev->name, indio_dev);
398 if (ret)399 if (ret)
399 goto error_kfifo_free;400 goto error_kfifo_free;
@@ -408,15 +409,6 @@ error_kfifo_free: · 8 unmodified lines
408 return ret;409 return ret;
409}410}
410 411
411static 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
420static const char * const chan_name_ain[] = {412static const char * const chan_name_ain[] = {
421 "AIN0",413 "AIN0",
422 "AIN1",414 "AIN1",
@@ -428,7 +420,8 @@ static const char * const chan_name_ain[] = { · 5 unmodified lines
428 "AIN7",420 "AIN7",
429};421};
430 422
431static int tiadc_channel_init(struct iio_dev *indio_dev, int channels)423static int tiadc_channel_init(struct device *dev, struct iio_dev *indio_dev,
424 int channels)
432{425{
433 struct tiadc_device *adc_dev = iio_priv(indio_dev);426 struct tiadc_device *adc_dev = iio_priv(indio_dev);
434 struct iio_chan_spec *chan_array;427 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
436 int i;429 int i;
437 430
438 indio_dev->num_channels = channels;431 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);
440 if (chan_array == NULL)434 if (chan_array == NULL)
441 return -ENOMEM;435 return -ENOMEM;
442 436
@@ -459,11 +453,6 @@ static int tiadc_channel_init(struct iio_dev *indio_dev, int channels) · 16 unmodified lines
459 return 0;453 return 0;
460}454}
461 455
462static void tiadc_channels_remove(struct iio_dev *indio_dev)
463{
464 kfree(indio_dev->channels);
465}
466
467static int tiadc_read_raw(struct iio_dev *indio_dev,456static int tiadc_read_raw(struct iio_dev *indio_dev,
468 struct iio_chan_spec const *chan,457 struct iio_chan_spec const *chan,
469 int *val, int *val2, long mask)458 int *val, int *val2, long mask)
@@ -626,7 +615,6 @@ static int tiadc_probe(struct platform_device *pdev) · 156 unmodified lines
626 adc_dev->mfd_tscadc = ti_tscadc_dev_get(pdev);615 adc_dev->mfd_tscadc = ti_tscadc_dev_get(pdev);
627 tiadc_parse_dt(pdev, adc_dev);616 tiadc_parse_dt(pdev, adc_dev);
628 617
629 indio_dev->dev.parent = &pdev->dev;
630 indio_dev->name = dev_name(&pdev->dev);618 indio_dev->name = dev_name(&pdev->dev);
631 indio_dev->modes = INDIO_DIRECT_MODE;619 indio_dev->modes = INDIO_DIRECT_MODE;
632 indio_dev->info = &tiadc_info;620 indio_dev->info = &tiadc_info;
@@ -635,11 +623,11 @@ static int tiadc_probe(struct platform_device *pdev) · 2 unmodified lines
635 tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD);623 tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD);
636 mutex_init(&adc_dev->fifo1_lock);624 mutex_init(&adc_dev->fifo1_lock);
637 625
638 err = tiadc_channel_init(indio_dev, adc_dev->channels);626 err = tiadc_channel_init(&pdev->dev, indio_dev, adc_dev->channels);
639 if (err < 0)627 if (err < 0)
640 return err;628 return err;
641 629
642 err = tiadc_iio_buffered_hardware_setup(indio_dev,630 err = tiadc_iio_buffered_hardware_setup(&pdev->dev, indio_dev,
643 &tiadc_worker_h,631 &tiadc_worker_h,
644 &tiadc_irq_h,632 &tiadc_irq_h,
645 adc_dev->mfd_tscadc->irq,633 adc_dev->mfd_tscadc->irq,
@@ -664,9 +652,7 @@ static int tiadc_probe(struct platform_device *pdev) · 18 unmodified lines
664err_dma:652err_dma:
665 iio_device_unregister(indio_dev);653 iio_device_unregister(indio_dev);
666err_buffer_unregister:654err_buffer_unregister:
667 tiadc_iio_buffered_hardware_remove(indio_dev);
668err_free_channels:655err_free_channels:
669 tiadc_channels_remove(indio_dev);
670 return err;656 return err;
671}657}
672 658
@@ -683,8 +669,6 @@ static int tiadc_remove(struct platform_device *pdev) · 10 unmodified lines
683 dma_release_channel(dma->chan);669 dma_release_channel(dma->chan);
684 }670 }
685 iio_device_unregister(indio_dev);671 iio_device_unregister(indio_dev);
686 tiadc_iio_buffered_hardware_remove(indio_dev);
687 tiadc_channels_remove(indio_dev);
688 672
689 step_en = get_adc_step_mask(adc_dev);673 step_en = get_adc_step_mask(adc_dev);
690 am335x_tsc_se_clr(adc_dev->mfd_tscadc, step_en);674 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
5 * conversion of analog signals like battery temperature,5 * conversion of analog signals like battery temperature,
6 * battery type, battery level etc.6 * battery type, battery level etc.
7 *7 *
8 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/8 * Copyright (C) 2011 Texas Instruments Incorporated - https://www.ti.com/
9 * J Keerthy <j-keerthy@ti.com>9 * J Keerthy <j-keerthy@ti.com>
10 *10 *
11 * Based on twl4030-madc.c11 * Based on twl4030-madc.c
@@ -772,8 +772,6 @@ static int twl4030_madc_probe(struct platform_device *pdev) · 760 unmodified lines
772 madc->dev = &pdev->dev;772 madc->dev = &pdev->dev;
773 773
774 iio_dev->name = dev_name(&pdev->dev);774 iio_dev->name = dev_name(&pdev->dev);
775 iio_dev->dev.parent = &pdev->dev;
776 iio_dev->dev.of_node = pdev->dev.of_node;
777 iio_dev->info = &twl4030_madc_iio_info;775 iio_dev->info = &twl4030_madc_iio_info;
778 iio_dev->modes = INDIO_DIRECT_MODE;776 iio_dev->modes = INDIO_DIRECT_MODE;
779 iio_dev->channels = twl4030_madc_iio_channels;777 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
926 }926 }
927 927
928 indio_dev->name = DRIVER_NAME;928 indio_dev->name = DRIVER_NAME;
929 indio_dev->dev.parent = dev;
930 indio_dev->info = &twl6030_gpadc_iio_info;929 indio_dev->info = &twl6030_gpadc_iio_info;
931 indio_dev->modes = INDIO_DIRECT_MODE;930 indio_dev->modes = INDIO_DIRECT_MODE;
932 indio_dev->channels = pdata->iio_channels;931 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
724{724{
725 struct vf610_adc *info = iio_priv(indio_dev);725 struct vf610_adc *info = iio_priv(indio_dev);
726 unsigned int channel;726 unsigned int channel;
727 int ret;
728 int val;727 int val;
729 728
730 ret = iio_triggered_buffer_postenable(indio_dev);
731 if (ret)
732 return ret;
733
734 val = readl(info->regs + VF610_REG_ADC_GC);729 val = readl(info->regs + VF610_REG_ADC_GC);
735 val |= VF610_ADC_ADCON;730 val |= VF610_ADC_ADCON;
736 writel(val, info->regs + VF610_REG_ADC_GC);731 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
761 756
762 writel(hc_cfg, info->regs + VF610_REG_ADC_HC0);757 writel(hc_cfg, info->regs + VF610_REG_ADC_HC0);
763 758
764 return iio_triggered_buffer_predisable(indio_dev);759 return 0;
765}760}
766 761
767static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {762static 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
860 init_completion(&info->completion);855 init_completion(&info->completion);
861 856
862 indio_dev->name = dev_name(&pdev->dev);857 indio_dev->name = dev_name(&pdev->dev);
863 indio_dev->dev.parent = &pdev->dev;
864 indio_dev->dev.of_node = pdev->dev.of_node;
865 indio_dev->info = &vf610_adc_iio_info;858 indio_dev->info = &vf610_adc_iio_info;
866 indio_dev->modes = INDIO_DIRECT_MODE;859 indio_dev->modes = INDIO_DIRECT_MODE;
867 indio_dev->channels = vf610_adc_iio_channels;860 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
121 adc = iio_priv(indio_dev);121 adc = iio_priv(indio_dev);
122 adc->vb = vb;122 adc->vb = vb;
123 indio_dev->name = "viperboard adc";123 indio_dev->name = "viperboard adc";
124 indio_dev->dev.parent = &pdev->dev;
125 indio_dev->info = &vprbrd_adc_iio_info;124 indio_dev->info = &vprbrd_adc_iio_info;
126 indio_dev->modes = INDIO_DIRECT_MODE;125 indio_dev->modes = INDIO_DIRECT_MODE;
127 indio_dev->channels = vprbrd_adc_iio_channels;126 indio_dev->channels = vprbrd_adc_iio_channels;
drivers/iio/adc/xilinx-xadc-core.c+0−4
@@ -839,8 +839,6 @@ err: · 838 unmodified lines
839 839
840static const struct iio_buffer_setup_ops xadc_buffer_ops = {840static const struct iio_buffer_setup_ops xadc_buffer_ops = {
841 .preenable = &xadc_preenable,841 .preenable = &xadc_preenable,
842 .postenable = &iio_triggered_buffer_postenable,
843 .predisable = &iio_triggered_buffer_predisable,
844 .postdisable = &xadc_postdisable,842 .postdisable = &xadc_postdisable,
845};843};
846 844
@@ -1221,8 +1219,6 @@ static int xadc_probe(struct platform_device *pdev) · 374 unmodified lines
1221 if (IS_ERR(xadc->base))1219 if (IS_ERR(xadc->base))
1222 return PTR_ERR(xadc->base);1220 return PTR_ERR(xadc->base);
1223 1221
1224 indio_dev->dev.parent = &pdev->dev;
1225 indio_dev->dev.of_node = pdev->dev.of_node;
1226 indio_dev->name = "xadc";1222 indio_dev->name = "xadc";
1227 indio_dev->modes = INDIO_DIRECT_MODE;1223 indio_dev->modes = INDIO_DIRECT_MODE;
1228 indio_dev->info = &xadc_info;1224 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
314 rescale->source = source;314 rescale->source = source;
315 315
316 indio_dev->name = dev_name(dev);316 indio_dev->name = dev_name(dev);
317 indio_dev->dev.parent = dev;
318 indio_dev->info = &rescale_info;317 indio_dev->info = &rescale_info;
319 indio_dev->modes = INDIO_DIRECT_MODE;318 indio_dev->modes = INDIO_DIRECT_MODE;
320 indio_dev->channels = &rescale->chan;319 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
262 case ID_ADA4961:262 case ID_ADA4961:
263 case ID_ADL5240:263 case ID_ADL5240:
264 case ID_HMC1119:264 case ID_HMC1119:
265 st->reset_gpio = devm_gpiod_get(&spi->dev, "reset",265 st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_HIGH);
266 GPIOD_OUT_HIGH);266 if (IS_ERR(st->reset_gpio)) {
267 ret = PTR_ERR(st->reset_gpio);
268 goto error_disable_reg;
269 }
267 indio_dev->channels = ada4961_channels;270 indio_dev->channels = ada4961_channels;
268 indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);271 indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
269 break;272 break;
@@ -274,7 +277,6 @@ static int ad8366_probe(struct spi_device *spi) · 4 unmodified lines
274 }277 }
275 278
276 st->info = &ad8366_infos[st->type];279 st->info = &ad8366_infos[st->type];
277 indio_dev->dev.parent = &spi->dev;
278 indio_dev->name = spi_get_device_id(spi)->name;280 indio_dev->name = spi_get_device_id(spi)->name;
279 indio_dev->info = &ad8366_info;281 indio_dev->info = &ad8366_info;
280 indio_dev->modes = INDIO_DIRECT_MODE;282 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
227 227
228 mutex_init(&st->lock);228 mutex_init(&st->lock);
229 229
230 indio_dev->dev.parent = &pdev->dev;
231 indio_dev->info = &hmc425a_info;230 indio_dev->info = &hmc425a_info;
232 indio_dev->modes = INDIO_DIRECT_MODE;231 indio_dev->modes = INDIO_DIRECT_MODE;
233 232
drivers/iio/buffer/industrialio-triggered-buffer.c+1−9
@@ -13,11 +13,6 @@ · 12 unmodified lines
13#include <linux/iio/triggered_buffer.h>13#include <linux/iio/triggered_buffer.h>
14#include <linux/iio/trigger_consumer.h>14#include <linux/iio/trigger_consumer.h>
15 15
16static 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
21/**16/**
22 * iio_triggered_buffer_setup() - Setup triggered buffer and pollfunc17 * iio_triggered_buffer_setup() - Setup triggered buffer and pollfunc
23 * @indio_dev: IIO device structure18 * @indio_dev: IIO device structure
@@ -67,10 +62,7 @@ int iio_triggered_buffer_setup(struct iio_dev *indio_dev, · 43 unmodified lines
67 }62 }
68 63
69 /* Ring buffer functions - here trigger setup related */64 /* Ring buffer functions - here trigger setup related */
70 if (setup_ops)65 indio_dev->setup_ops = setup_ops;
71 indio_dev->setup_ops = setup_ops;
72 else
73 indio_dev->setup_ops = &iio_triggered_buffer_setup_ops;
74 66
75 /* Flag that polled ring buffering is possible */67 /* Flag that polled ring buffering is possible */
76 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;68 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
drivers/iio/chemical/Kconfig+33−0
@@ -85,6 +85,39 @@ config PMS7003 · 84 unmodified lines
85 To compile this driver as a module, choose M here: the module will85 To compile this driver as a module, choose M here: the module will
86 be called pms7003.86 be called pms7003.
87 87
88config 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
99config 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
110config 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
88config SENSIRION_SGP30121config SENSIRION_SGP30
89 tristate "Sensirion SGPxx gas sensors"122 tristate "Sensirion SGPxx gas sensors"
90 depends on I2C123 depends on I2C
drivers/iio/chemical/Makefile+3−0
@@ -12,6 +12,9 @@ obj-$(CONFIG_BME680_SPI) += bme680_spi.o · 11 unmodified lines
12obj-$(CONFIG_CCS811) += ccs811.o12obj-$(CONFIG_CCS811) += ccs811.o
13obj-$(CONFIG_IAQCORE) += ams-iaq-core.o13obj-$(CONFIG_IAQCORE) += ams-iaq-core.o
14obj-$(CONFIG_PMS7003) += pms7003.o14obj-$(CONFIG_PMS7003) += pms7003.o
15obj-$(CONFIG_SCD30_CORE) += scd30_core.o
16obj-$(CONFIG_SCD30_I2C) += scd30_i2c.o
17obj-$(CONFIG_SCD30_SERIAL) += scd30_serial.o
15obj-$(CONFIG_SENSIRION_SGP30) += sgp30.o18obj-$(CONFIG_SENSIRION_SGP30) += sgp30.o
16obj-$(CONFIG_SPS30) += sps30.o19obj-$(CONFIG_SPS30) += sps30.o
17obj-$(CONFIG_VZ89X) += vz89x.o20obj-$(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
152 data->last_update = jiffies - HZ;152 data->last_update = jiffies - HZ;
153 mutex_init(&data->lock);153 mutex_init(&data->lock);
154 154
155 indio_dev->dev.parent = &client->dev;
156 indio_dev->info = &ams_iaqcore_info;155 indio_dev->info = &ams_iaqcore_info;
157 indio_dev->name = dev_name(&client->dev);156 indio_dev->name = dev_name(&client->dev);
158 indio_dev->modes = INDIO_DIRECT_MODE;157 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
69{69{
70 struct atlas_ezo_data *data = iio_priv(indio_dev);70 struct atlas_ezo_data *data = iio_priv(indio_dev);
71 struct i2c_client *client = data->client;71 struct i2c_client *client = data->client;
72 int ret = 0;
73 72
74 if (chan->type != IIO_CONCENTRATION)73 if (chan->type != IIO_CONCENTRATION)
75 return -EINVAL;74 return -EINVAL;
76 75
77 switch (mask) {76 switch (mask) {
78 case IIO_CHAN_INFO_RAW: {77 case IIO_CHAN_INFO_RAW: {
78 int ret;
79 long tmp;79 long tmp;
80 80
81 mutex_lock(&data->lock);81 mutex_lock(&data->lock);
@@ -110,7 +110,7 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev, · 28 unmodified lines
110 return IIO_VAL_INT_PLUS_MICRO;110 return IIO_VAL_INT_PLUS_MICRO;
111 }111 }
112 112
113 return ret;113 return 0;
114}114}
115 115
116static const struct iio_info atlas_info = {116static const struct iio_info atlas_info = {
@@ -152,7 +152,6 @@ static int atlas_ezo_probe(struct i2c_client *client, · 35 unmodified lines
152 indio_dev->channels = chip->channels;152 indio_dev->channels = chip->channels;
153 indio_dev->num_channels = chip->num_channels;153 indio_dev->num_channels = chip->num_channels;
154 indio_dev->modes = INDIO_DIRECT_MODE;154 indio_dev->modes = INDIO_DIRECT_MODE;
155 indio_dev->dev.parent = &client->dev;
156 155
157 data = iio_priv(indio_dev);156 data = iio_priv(indio_dev);
158 data->client = client;157 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
410 struct atlas_data *data = iio_priv(indio_dev);410 struct atlas_data *data = iio_priv(indio_dev);
411 int ret;411 int ret;
412 412
413 ret = iio_triggered_buffer_postenable(indio_dev);
414 if (ret)
415 return ret;
416
417 ret = pm_runtime_get_sync(&data->client->dev);413 ret = pm_runtime_get_sync(&data->client->dev);
418 if (ret < 0) {414 if (ret < 0) {
419 pm_runtime_put_noidle(&data->client->dev);415 pm_runtime_put_noidle(&data->client->dev);
@@ -437,7 +433,7 @@ static int atlas_buffer_predisable(struct iio_dev *indio_dev) · 17 unmodified lines
437 if (ret)433 if (ret)
438 return ret;434 return ret;
439 435
440 return iio_triggered_buffer_predisable(indio_dev);436 return 0;
441}437}
442 438
443static const struct iio_trigger_ops atlas_interrupt_trigger_ops = {439static const struct iio_trigger_ops atlas_interrupt_trigger_ops = {
@@ -644,7 +640,6 @@ static int atlas_probe(struct i2c_client *client, · 200 unmodified lines
644 indio_dev->channels = chip->channels;640 indio_dev->channels = chip->channels;
645 indio_dev->num_channels = chip->num_channels;641 indio_dev->num_channels = chip->num_channels;
646 indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE;642 indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE;
647 indio_dev->dev.parent = &client->dev;
648 643
649 trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",644 trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
650 indio_dev->name, indio_dev->id);645 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
923 data = iio_priv(indio_dev);923 data = iio_priv(indio_dev);
924 dev_set_drvdata(dev, indio_dev);924 dev_set_drvdata(dev, indio_dev);
925 data->regmap = regmap;925 data->regmap = regmap;
926 indio_dev->dev.parent = dev;
927 indio_dev->name = name;926 indio_dev->name = name;
928 indio_dev->channels = bme680_channels;927 indio_dev->channels = bme680_channels;
929 indio_dev->num_channels = ARRAY_SIZE(bme680_channels);928 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
464 464
465 mutex_init(&data->lock);465 mutex_init(&data->lock);
466 466
467 indio_dev->dev.parent = &client->dev;
468 indio_dev->name = id->name;467 indio_dev->name = id->name;
469 indio_dev->info = &ccs811_info;468 indio_dev->info = &ccs811_info;
470 indio_dev->modes = INDIO_DIRECT_MODE;469 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
280 state = iio_priv(indio_dev);280 state = iio_priv(indio_dev);
281 serdev_device_set_drvdata(serdev, indio_dev);281 serdev_device_set_drvdata(serdev, indio_dev);
282 state->serdev = serdev;282 state->serdev = serdev;
283 indio_dev->dev.parent = &serdev->dev;
284 indio_dev->info = &pms7003_info;283 indio_dev->info = &pms7003_info;
285 indio_dev->name = PMS7003_DRIVER_NAME;284 indio_dev->name = PMS7003_DRIVER_NAME;
286 indio_dev->channels = pms7003_channels,285 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
12struct scd30_state;
13
14enum 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
44typedef int (*scd30_command_t)(struct scd30_state *state, enum scd30_cmd cmd, u16 arg,
45 void *response, int size);
46
47struct 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
71int scd30_suspend(struct device *dev);
72int scd30_resume(struct device *dev);
73
74static __maybe_unused SIMPLE_DEV_PM_OPS(scd30_pm_ops, scd30_suspend, scd30_resume);
75
76int 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
45enum {
46 SCD30_CONC,
47 SCD30_TEMP,
48 SCD30_HR,
49};
50
51static 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
56static 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
67static 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 */
89static 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
115static 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
138static 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
156static 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
178static 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
189static 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
197static 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
256static 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
309static 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
323static const int scd30_pressure_raw_available[] = {
324 SCD30_PRESSURE_COMP_MIN_MBAR, 1, SCD30_PRESSURE_COMP_MAX_MBAR,
325};
326
327static const int scd30_temp_calibbias_available[] = {
328 0, 10, SCD30_TEMP_OFFSET_MAX,
329};
330
331static 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
350static 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
371static 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
386static 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
405static 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
420static 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
442static IIO_DEVICE_ATTR_RO(sampling_frequency_available, 0);
443static IIO_DEVICE_ATTR_RW(calibration_auto_enable, 0);
444static IIO_DEVICE_ATTR_RW(calibration_forced_value, 0);
445
446static 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
453static const struct attribute_group scd30_attr_group = {
454 .attrs = scd30_attrs,
455};
456
457static 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
472static 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
520int __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}
532EXPORT_SYMBOL(scd30_suspend);
533
534int __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}
546EXPORT_SYMBOL(scd30_resume);
547
548static 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
555static void scd30_disable_regulator(void *data)
556{
557 struct scd30_state *state = data;
558
559 regulator_disable(state->vdd);
560}
561
562static 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
575static 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);
586out:
587 return IRQ_HANDLED;
588}
589
590static 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));
613out:
614 iio_trigger_notify_done(indio_dev->trig);
615 return IRQ_HANDLED;
616}
617
618static 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
631static 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
636static 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
675int 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}
767EXPORT_SYMBOL(scd30_probe);
768
769MODULE_AUTHOR("Tomasz Duszynski <tomasz.duszynski@octakon.com>");
770MODULE_DESCRIPTION("Sensirion SCD30 carbon dioxide sensor core driver");
771MODULE_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
23static 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
36DECLARE_CRC8_TABLE(scd30_i2c_crc8_tbl);
37
38static 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
66static 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
111static 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
121static const struct of_device_id scd30_i2c_of_match[] = {
122 { .compatible = "sensirion,scd30" },
123 { }
124};
125MODULE_DEVICE_TABLE(of, scd30_i2c_of_match);
126
127static 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};
135module_i2c_driver(scd30_i2c_driver);
136
137MODULE_AUTHOR("Tomasz Duszynski <tomasz.duszynski@octakon.com>");
138MODULE_DESCRIPTION("Sensirion SCD30 carbon dioxide sensor i2c driver");
139MODULE_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
30struct scd30_serdev_priv {
31 struct completion meas_ready;
32 char *buf;
33 int num_expected;
34 int num;
35};
36
37static 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
50static u16 scd30_serdev_calc_crc(const char *buf, int size)
51{
52 return crc16(0xffff, buf, size);
53}
54
55static 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
81static 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
177static 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
211static const struct serdev_device_ops scd30_serdev_ops = {
212 .receive_buf = scd30_serdev_receive_buf,
213 .write_wakeup = serdev_device_write_wakeup,
214};
215
216static 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
245static const struct of_device_id scd30_serdev_of_match[] = {
246 { .compatible = "sensirion,scd30" },
247 { }
248};
249MODULE_DEVICE_TABLE(of, scd30_serdev_of_match);
250
251static 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};
259module_serdev_device_driver(scd30_serdev_driver);
260
261MODULE_AUTHOR("Tomasz Duszynski <tomasz.duszynski@octakon.com>");
262MODULE_DESCRIPTION("Sensirion SCD30 carbon dioxide sensor serial driver");
263MODULE_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
533 if (ret)533 if (ret)
534 return ret;534 return ret;
535 535
536 indio_dev->dev.parent = &client->dev;
537 indio_dev->info = &sgp_info;536 indio_dev->info = &sgp_info;
538 indio_dev->name = id->name;537 indio_dev->name = id->name;
539 indio_dev->modes = INDIO_DIRECT_MODE;538 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
487 i2c_set_clientdata(client, indio_dev);487 i2c_set_clientdata(client, indio_dev);
488 state->client = client;488 state->client = client;
489 state->state = RESET;489 state->state = RESET;
490 indio_dev->dev.parent = &client->dev;
491 indio_dev->info = &sps30_info;490 indio_dev->info = &sps30_info;
492 indio_dev->name = client->name;491 indio_dev->name = client->name;
493 indio_dev->channels = sps30_channels;492 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
382 data->last_update = jiffies - HZ;382 data->last_update = jiffies - HZ;
383 mutex_init(&data->lock);383 mutex_init(&data->lock);
384 384
385 indio_dev->dev.parent = &client->dev;
386 indio_dev->info = &vz89x_info;385 indio_dev->info = &vz89x_info;
387 indio_dev->name = dev_name(&client->dev);386 indio_dev->name = dev_name(&client->dev);
388 indio_dev->modes = INDIO_DIRECT_MODE;387 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
200 st->core.param.sensor_range.roundup = 1;200 st->core.param.sensor_range.roundup = 1;
201 201
202 ret = cros_ec_motion_send_host_cmd(&st->core, 0);202 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 }
203 break;207 break;
204 default:208 default:
205 ret = cros_ec_sensors_core_write(209 ret = cros_ec_sensors_core_write(
@@ -315,6 +319,7 @@ MODULE_DEVICE_TABLE(platform, cros_ec_sensors_ids); · 109 unmodified lines
315static struct platform_driver cros_ec_sensors_platform_driver = {319static struct platform_driver cros_ec_sensors_platform_driver = {
316 .driver = {320 .driver = {
317 .name = "cros-ec-sensors",321 .name = "cros-ec-sensors",
322 .pm = &cros_ec_sensors_pm_ops,
318 },323 },
319 .probe = cros_ec_sensors_probe,324 .probe = cros_ec_sensors_probe,
320 .id_table = cros_ec_sensors_ids,325 .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
281 state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;281 state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
282 state->msg->outsize = sizeof(struct ec_params_motion_sense);282 state->msg->outsize = sizeof(struct ec_params_motion_sense);
283 283
284 indio_dev->dev.parent = &pdev->dev;
285 indio_dev->name = pdev->name;284 indio_dev->name = pdev->name;
286 285
287 if (physical_device) {286 if (physical_device) {
@@ -352,7 +351,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, · 64 unmodified lines
352 } else {351 } else {
353 /*352 /*
354 * The only way to get samples in buffer is to set a353 * The only way to get samples in buffer is to set a
355 * software tigger (systrig, hrtimer).354 * software trigger (systrig, hrtimer).
356 */355 */
357 ret = devm_iio_triggered_buffer_setup(356 ret = devm_iio_triggered_buffer_setup(
358 dev, indio_dev, NULL, trigger_capture,357 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
824}823}
825EXPORT_SYMBOL_GPL(cros_ec_sensors_core_write);824EXPORT_SYMBOL_GPL(cros_ec_sensors_core_write);
826 825
826static 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
844SIMPLE_DEV_PM_OPS(cros_ec_sensors_pm_ops, NULL, cros_ec_sensors_resume);
845EXPORT_SYMBOL_GPL(cros_ec_sensors_pm_ops);
846
827MODULE_DESCRIPTION("ChromeOS EC sensor hub core functions");847MODULE_DESCRIPTION("ChromeOS EC sensor hub core functions");
828MODULE_LICENSE("GPL v2");848MODULE_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
56 56
57 i2c_set_clientdata(client, indio_dev);57 i2c_set_clientdata(client, indio_dev);
58 58
59 indio_dev->dev.parent = &client->dev;
60 indio_dev->name = client->name;59 indio_dev->name = client->name;
61 60
62 sdata->dev = &client->dev;61 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
108 108
109 spi_set_drvdata(spi, indio_dev);109 spi_set_drvdata(spi, indio_dev);
110 110
111 indio_dev->dev.parent = &spi->dev;
112 indio_dev->name = spi->modalias;111 indio_dev->name = spi->modalias;
113 112
114 sdata->dev = &spi->dev;113 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
874 return ret;874 return ret;
875 }875 }
876 876
877 indio_dev->dev.parent = dev;
878 indio_dev->name = name;877 indio_dev->name = name;
879 indio_dev->info = &ad5064_info;878 indio_dev->info = &ad5064_info;
880 indio_dev->modes = INDIO_DIRECT_MODE;879 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
476 st->chip_info = &ad5360_chip_info_tbl[type];476 st->chip_info = &ad5360_chip_info_tbl[type];
477 st->spi = spi;477 st->spi = spi;
478 478
479 indio_dev->dev.parent = &spi->dev;
480 indio_dev->name = spi_get_device_id(spi)->name;479 indio_dev->name = spi_get_device_id(spi)->name;
481 indio_dev->info = &ad5360_info;480 indio_dev->info = &ad5360_info;
482 indio_dev->modes = INDIO_DIRECT_MODE;481 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
240 .write_raw = ad5380_write_raw,240 .write_raw = ad5380_write_raw,
241};241};
242 242
243static struct iio_chan_spec_ext_info ad5380_ext_info[] = {243static const struct iio_chan_spec_ext_info ad5380_ext_info[] = {
244 {244 {
245 .name = "powerdown",245 .name = "powerdown",
246 .read = ad5380_read_dac_powerdown,246 .read = ad5380_read_dac_powerdown,
@@ -386,7 +386,6 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap, · 139 unmodified lines
386 st->chip_info = &ad5380_chip_info_tbl[type];386 st->chip_info = &ad5380_chip_info_tbl[type];
387 st->regmap = regmap;387 st->regmap = regmap;
388 388
389 indio_dev->dev.parent = dev;
390 indio_dev->name = name;389 indio_dev->name = name;
391 indio_dev->info = &ad5380_info;390 indio_dev->info = &ad5380_info;
392 indio_dev->modes = INDIO_DIRECT_MODE;391 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
487 487
488 st->spi = spi;488 st->spi = spi;
489 489
490 indio_dev->dev.parent = &spi->dev;
491 indio_dev->name = "ad5421";490 indio_dev->name = "ad5421";
492 indio_dev->info = &ad5421_info;491 indio_dev->info = &ad5421_info;
493 indio_dev->modes = INDIO_DIRECT_MODE;492 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
250 st->reg = reg;250 st->reg = reg;
251 st->dev = dev;251 st->dev = dev;
252 252
253 /* Establish that the iio_dev is a child of the device */
254 indio_dev->dev.parent = dev;
255 indio_dev->name = name;253 indio_dev->name = name;
256 indio_dev->info = &ad5446_info;254 indio_dev->info = &ad5446_info;
257 indio_dev->modes = INDIO_DIRECT_MODE;255 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
297 if (ret)297 if (ret)
298 return ret;298 return ret;
299 299
300 indio_dev->dev.parent = &spi->dev;
301 indio_dev->name = id->name;300 indio_dev->name = id->name;
302 indio_dev->info = &ad5449_info;301 indio_dev->info = &ad5449_info;
303 indio_dev->modes = INDIO_DIRECT_MODE;302 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
304 304
305 st->reg = reg;305 st->reg = reg;
306 st->spi = spi;306 st->spi = spi;
307 indio_dev->dev.parent = &spi->dev;
308 indio_dev->name = spi_get_device_id(st->spi)->name;307 indio_dev->name = spi_get_device_id(st->spi)->name;
309 indio_dev->info = &ad5504_info;308 indio_dev->info = &ad5504_info;
310 if (spi_get_device_id(st->spi)->driver_data == ID_AD5501)309 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
484 st->scale_avail[1][0], st->scale_avail[1][1]);484 st->scale_avail[1][0], st->scale_avail[1][1]);
485}485}
486 486
487static struct iio_chan_spec_ext_info ad5592r_ext_info[] = {487static const struct iio_chan_spec_ext_info ad5592r_ext_info[] = {
488 {488 {
489 .name = "scale_available",489 .name = "scale_available",
490 .read = ad5592r_show_scale_available,490 .read = ad5592r_show_scale_available,
@@ -508,11 +508,11 @@ static void ad5592r_setup_channel(struct iio_dev *iio_dev, · 17 unmodified lines
508 chan->ext_info = ad5592r_ext_info;508 chan->ext_info = ad5592r_ext_info;
509}509}
510 510
511static int ad5592r_alloc_channels(struct ad5592r_state *st)511static int ad5592r_alloc_channels(struct iio_dev *iio_dev)
512{512{
513 struct ad5592r_state *st = iio_priv(iio_dev);
513 unsigned i, curr_channel = 0,514 unsigned i, curr_channel = 0,
514 num_channels = st->num_channels;515 num_channels = st->num_channels;
515 struct iio_dev *iio_dev = iio_priv_to_dev(st);
516 struct iio_chan_spec *channels;516 struct iio_chan_spec *channels;
517 struct fwnode_handle *child;517 struct fwnode_handle *child;
518 u32 reg, tmp;518 u32 reg, tmp;
@@ -618,7 +618,6 @@ int ad5592r_probe(struct device *dev, const char *name, · 99 unmodified lines
618 return ret;618 return ret;
619 }619 }
620 620
621 iio_dev->dev.parent = dev;
622 iio_dev->name = name;621 iio_dev->name = name;
623 iio_dev->info = &ad5592r_info;622 iio_dev->info = &ad5592r_info;
624 iio_dev->modes = INDIO_DIRECT_MODE;623 iio_dev->modes = INDIO_DIRECT_MODE;
@@ -636,7 +635,7 @@ int ad5592r_probe(struct device *dev, const char *name, · 11 unmodified lines
636 if (ret)635 if (ret)
637 goto error_disable_reg;636 goto error_disable_reg;
638 637
639 ret = ad5592r_alloc_channels(st);638 ret = ad5592r_alloc_channels(iio_dev);
640 if (ret)639 if (ret)
641 goto error_disable_reg;640 goto error_disable_reg;
642 641
drivers/iio/dac/ad5624r_spi.c+0−1
@@ -253,7 +253,6 @@ static int ad5624r_probe(struct spi_device *spi) · 252 unmodified lines
253 253
254 st->us = spi;254 st->us = spi;
255 255
256 indio_dev->dev.parent = &spi->dev;
257 indio_dev->name = spi_get_device_id(spi)->name;256 indio_dev->name = spi_get_device_id(spi)->name;
258 indio_dev->info = &ad5624r_info;257 indio_dev->info = &ad5624r_info;
259 indio_dev->modes = INDIO_DIRECT_MODE;258 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
461 for (i = 0; i < st->chip_info->num_channels; i++)461 for (i = 0; i < st->chip_info->num_channels; i++)
462 st->pwr_down_mode |= (0x01 << (i * 2));462 st->pwr_down_mode |= (0x01 << (i * 2));
463 463
464 indio_dev->dev.parent = dev;
465 indio_dev->name = name;464 indio_dev->name = name;
466 indio_dev->info = &ad5686_info;465 indio_dev->info = &ad5686_info;
467 indio_dev->modes = INDIO_DIRECT_MODE;466 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
744 st->spi = spi;744 st->spi = spi;
745 st->pwr_down = 0xf;745 st->pwr_down = 0xf;
746 746
747 indio_dev->dev.parent = &spi->dev;
748 indio_dev->name = spi_get_device_id(spi)->name;747 indio_dev->name = spi_get_device_id(spi)->name;
749 indio_dev->info = &ad5755_info;748 indio_dev->info = &ad5755_info;
750 indio_dev->modes = INDIO_DIRECT_MODE;749 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
854 854
855 mutex_init(&st->lock);855 mutex_init(&st->lock);
856 856
857 indio_dev->dev.parent = &spi->dev;
858 indio_dev->name = spi_get_device_id(spi)->name;857 indio_dev->name = spi_get_device_id(spi)->name;
859 indio_dev->info = &ad5758_info;858 indio_dev->info = &ad5758_info;
860 indio_dev->modes = INDIO_DIRECT_MODE;859 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
376 if (ret)376 if (ret)
377 goto disable_regulator_err;377 goto disable_regulator_err;
378 378
379 iio_dev->dev.parent = &spi->dev;
380 iio_dev->info = &ad5761_info;379 iio_dev->info = &ad5761_info;
381 iio_dev->modes = INDIO_DIRECT_MODE;380 iio_dev->modes = INDIO_DIRECT_MODE;
382 iio_dev->channels = &chip_info->channel;381 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
290 st->spi = spi;290 st->spi = spi;
291 st->chip_info = &ad5764_chip_infos[type];291 st->chip_info = &ad5764_chip_infos[type];
292 292
293 indio_dev->dev.parent = &spi->dev;
294 indio_dev->name = spi_get_device_id(spi)->name;293 indio_dev->name = spi_get_device_id(spi)->name;
295 indio_dev->info = &ad5764_info;294 indio_dev->info = &ad5764_info;
296 indio_dev->modes = INDIO_DIRECT_MODE;295 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
651 }651 }
652 }652 }
653 653
654 indio_dev->dev.parent = &spi->dev;
655 indio_dev->name = spi_get_device_id(spi)->name;654 indio_dev->name = spi_get_device_id(spi)->name;
656 indio_dev->info = &ad5770r_info;655 indio_dev->info = &ad5770r_info;
657 indio_dev->modes = INDIO_DIRECT_MODE;656 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
409 goto error_disable_reg_neg;409 goto error_disable_reg_neg;
410 410
411 spi_set_drvdata(spi, indio_dev);411 spi_set_drvdata(spi, indio_dev);
412 indio_dev->dev.parent = &spi->dev;
413 indio_dev->info = &ad5791_info;412 indio_dev->info = &ad5791_info;
414 indio_dev->modes = INDIO_DIRECT_MODE;413 indio_dev->modes = INDIO_DIRECT_MODE;
415 indio_dev->channels414 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
238 st->config |= AD7303_CFG_EXTERNAL_VREF;238 st->config |= AD7303_CFG_EXTERNAL_VREF;
239 }239 }
240 240
241 indio_dev->dev.parent = &spi->dev;
242 indio_dev->name = id->name;241 indio_dev->name = id->name;
243 indio_dev->info = &ad7303_info;242 indio_dev->info = &ad7303_info;
244 indio_dev->modes = INDIO_DIRECT_MODE;243 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
171 }171 }
172 172
173 spi_set_drvdata(spi, indio_dev);173 spi_set_drvdata(spi, indio_dev);
174 indio_dev->dev.parent = &spi->dev;
175 indio_dev->info = &ad8801_info;174 indio_dev->info = &ad8801_info;
176 indio_dev->modes = INDIO_DIRECT_MODE;175 indio_dev->modes = INDIO_DIRECT_MODE;
177 indio_dev->channels = ad8801_channels;176 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
110 indio_dev->channels = cio_dac_channels;110 indio_dev->channels = cio_dac_channels;
111 indio_dev->num_channels = CIO_DAC_NUM_CHAN;111 indio_dev->num_channels = CIO_DAC_NUM_CHAN;
112 indio_dev->name = dev_name(dev);112 indio_dev->name = dev_name(dev);
113 indio_dev->dev.parent = dev;
114 113
115 priv = iio_priv(indio_dev);114 priv = iio_priv(indio_dev);
116 priv->base = base[id];115 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
177 dac = iio_priv(indio_dev);177 dac = iio_priv(indio_dev);
178 178
179 indio_dev->name = dev_name(dev);179 indio_dev->name = dev_name(dev);
180 indio_dev->dev.parent = dev;
181 indio_dev->info = &dpot_dac_info;180 indio_dev->info = &dpot_dac_info;
182 indio_dev->modes = INDIO_DIRECT_MODE;181 indio_dev->modes = INDIO_DIRECT_MODE;
183 indio_dev->channels = &dpot_dac_iio_channel;182 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
230 i2c_set_clientdata(client, indio_dev);230 i2c_set_clientdata(client, indio_dev);
231 data->client = client;231 data->client = client;
232 indio_dev->name = id->name;232 indio_dev->name = id->name;
233 indio_dev->dev.of_node = client->dev.of_node;
234 indio_dev->dev.parent = &client->dev;
235 233
236 data->vcc_reg = devm_regulator_get(&client->dev, "vcc");234 data->vcc_reg = devm_regulator_get(&client->dev, "vcc");
237 if (IS_ERR(data->vcc_reg)) {235 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
133 }133 }
134 134
135 indio_dev->name = dev_name(&pdev->dev);135 indio_dev->name = dev_name(&pdev->dev);
136 indio_dev->dev.parent = &pdev->dev;
137 indio_dev->info = &lpc18xx_dac_info;136 indio_dev->info = &lpc18xx_dac_info;
138 indio_dev->modes = INDIO_DIRECT_MODE;137 indio_dev->modes = INDIO_DIRECT_MODE;
139 indio_dev->channels = lpc18xx_dac_iio_channels;138 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
186 186
187 priv->spi = spi;187 priv->spi = spi;
188 spi_set_drvdata(spi, indio_dev);188 spi_set_drvdata(spi, indio_dev);
189 indio_dev->dev.parent = &spi->dev;
190 indio_dev->info = &ltc1660_info;189 indio_dev->info = &ltc1660_info;
191 indio_dev->modes = INDIO_DIRECT_MODE;190 indio_dev->modes = INDIO_DIRECT_MODE;
192 indio_dev->channels = ltc1660_channels[id->driver_data];191 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
362 }362 }
363 }363 }
364 364
365 indio_dev->dev.parent = &spi->dev;
366 indio_dev->name = dev_of_node(&spi->dev) ? dev_of_node(&spi->dev)->name365 indio_dev->name = dev_of_node(&spi->dev) ? dev_of_node(&spi->dev)->name
367 : spi_get_device_id(spi)->name;366 : spi_get_device_id(spi)->name;
368 indio_dev->info = &ltc2632_info;367 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
204 if (IS_ERR(data->vcc))204 if (IS_ERR(data->vcc))
205 return PTR_ERR(data->vcc);205 return PTR_ERR(data->vcc);
206 206
207 /* establish that the iio_dev is a child of the i2c device */
208 indio_dev->dev.parent = &client->dev;
209
210 indio_dev->num_channels = ARRAY_SIZE(m62332_channels);207 indio_dev->num_channels = ARRAY_SIZE(m62332_channels);
211 indio_dev->channels = m62332_channels;208 indio_dev->channels = m62332_channels;
212 indio_dev->modes = INDIO_DIRECT_MODE;209 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
156 i2c_set_clientdata(client, indio_dev);156 i2c_set_clientdata(client, indio_dev);
157 data->client = client;157 data->client = client;
158 158
159 /* establish that the iio_dev is a child of the i2c device */
160 indio_dev->dev.parent = &client->dev;
161
162 switch (id->driver_data) {159 switch (id->driver_data) {
163 case ID_MAX521:160 case ID_MAX521:
164 indio_dev->num_channels = 8;161 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
341 data->vref_mv = ret / 1000;341 data->vref_mv = ret / 1000;
342 342
343 indio_dev->name = id->name;343 indio_dev->name = id->name;
344 indio_dev->dev.parent = &client->dev;
345 indio_dev->num_channels = ARRAY_SIZE(max5821_channels);344 indio_dev->num_channels = ARRAY_SIZE(max5821_channels);
346 indio_dev->channels = max5821_channels;345 indio_dev->channels = max5821_channels;
347 indio_dev->modes = INDIO_DIRECT_MODE;346 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
453 goto err_disable_vdd_reg;453 goto err_disable_vdd_reg;
454 }454 }
455 455
456 indio_dev->dev.parent = &client->dev;
457 indio_dev->name = id->name;456 indio_dev->name = id->name;
458 indio_dev->info = &mcp4725_info;457 indio_dev->info = &mcp4725_info;
459 indio_dev->channels = &mcp472x_channel[id->driver_data];458 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
152 152
153 spi_set_drvdata(spi, indio_dev);153 spi_set_drvdata(spi, indio_dev);
154 id = spi_get_device_id(spi);154 id = spi_get_device_id(spi);
155 indio_dev->dev.parent = &spi->dev;
156 indio_dev->info = &mcp4922_info;155 indio_dev->info = &mcp4922_info;
157 indio_dev->modes = INDIO_DIRECT_MODE;156 indio_dev->modes = INDIO_DIRECT_MODE;
158 indio_dev->channels = mcp4922_channels[id->driver_data];157 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
323 dac = iio_priv(indio_dev);323 dac = iio_priv(indio_dev);
324 dac->common = dev_get_drvdata(pdev->dev.parent);324 dac->common = dev_get_drvdata(pdev->dev.parent);
325 indio_dev->name = dev_name(&pdev->dev);325 indio_dev->name = dev_name(&pdev->dev);
326 indio_dev->dev.parent = &pdev->dev;
327 indio_dev->dev.of_node = pdev->dev.of_node;326 indio_dev->dev.of_node = pdev->dev.of_node;
328 indio_dev->info = &stm32_dac_iio_info;327 indio_dev->info = &stm32_dac_iio_info;
329 indio_dev->modes = INDIO_DIRECT_MODE;328 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ti-dac082s085.c+6−7
@@ -4,12 +4,12 @@ · 3 unmodified lines
4 *4 *
5 * Copyright (C) 2017 KUNBUS GmbH5 * Copyright (C) 2017 KUNBUS GmbH
6 *6 *
7 * http://www.ti.com/lit/ds/symlink/dac082s085.pdf7 * https://www.ti.com/lit/ds/symlink/dac082s085.pdf
8 * http://www.ti.com/lit/ds/symlink/dac102s085.pdf8 * https://www.ti.com/lit/ds/symlink/dac102s085.pdf
9 * http://www.ti.com/lit/ds/symlink/dac122s085.pdf9 * https://www.ti.com/lit/ds/symlink/dac122s085.pdf
10 * http://www.ti.com/lit/ds/symlink/dac084s085.pdf10 * https://www.ti.com/lit/ds/symlink/dac084s085.pdf
11 * http://www.ti.com/lit/ds/symlink/dac104s085.pdf11 * https://www.ti.com/lit/ds/symlink/dac104s085.pdf
12 * http://www.ti.com/lit/ds/symlink/dac124s085.pdf12 * https://www.ti.com/lit/ds/symlink/dac124s085.pdf
13 */13 */
14 14
15#include <linux/iio/iio.h>15#include <linux/iio/iio.h>
@@ -268,7 +268,6 @@ static int ti_dac_probe(struct spi_device *spi) · 252 unmodified lines
268 if (!indio_dev)268 if (!indio_dev)
269 return -ENOMEM;269 return -ENOMEM;
270 270
271 indio_dev->dev.parent = dev;
272 indio_dev->info = &ti_dac_info;271 indio_dev->info = &ti_dac_info;
273 indio_dev->name = spi->modalias;272 indio_dev->name = spi->modalias;
274 indio_dev->modes = INDIO_DIRECT_MODE;273 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ti-dac5571.c+9−11
@@ -4,15 +4,15 @@ · 3 unmodified lines
4 *4 *
5 * Copyright (C) 2018 Prevas A/S5 * Copyright (C) 2018 Prevas A/S
6 *6 *
7 * http://www.ti.com/lit/ds/symlink/dac5571.pdf7 * https://www.ti.com/lit/ds/symlink/dac5571.pdf
8 * http://www.ti.com/lit/ds/symlink/dac6571.pdf8 * https://www.ti.com/lit/ds/symlink/dac6571.pdf
9 * http://www.ti.com/lit/ds/symlink/dac7571.pdf9 * https://www.ti.com/lit/ds/symlink/dac7571.pdf
10 * http://www.ti.com/lit/ds/symlink/dac5574.pdf10 * https://www.ti.com/lit/ds/symlink/dac5574.pdf
11 * http://www.ti.com/lit/ds/symlink/dac6574.pdf11 * https://www.ti.com/lit/ds/symlink/dac6574.pdf
12 * http://www.ti.com/lit/ds/symlink/dac7574.pdf12 * https://www.ti.com/lit/ds/symlink/dac7574.pdf
13 * http://www.ti.com/lit/ds/symlink/dac5573.pdf13 * https://www.ti.com/lit/ds/symlink/dac5573.pdf
14 * http://www.ti.com/lit/ds/symlink/dac6573.pdf14 * https://www.ti.com/lit/ds/symlink/dac6573.pdf
15 * http://www.ti.com/lit/ds/symlink/dac7573.pdf15 * https://www.ti.com/lit/ds/symlink/dac7573.pdf
16 */16 */
17 17
18#include <linux/iio/iio.h>18#include <linux/iio/iio.h>
@@ -321,8 +321,6 @@ static int dac5571_probe(struct i2c_client *client, · 302 unmodified lines
321 i2c_set_clientdata(client, indio_dev);321 i2c_set_clientdata(client, indio_dev);
322 data->client = client;322 data->client = client;
323 323
324 indio_dev->dev.parent = dev;
325 indio_dev->dev.of_node = client->dev.of_node;
326 indio_dev->info = &dac5571_info;324 indio_dev->info = &dac5571_info;
327 indio_dev->name = id->name;325 indio_dev->name = id->name;
328 indio_dev->modes = INDIO_DIRECT_MODE;326 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/dac/ti-dac7311.c+1−3
@@ -3,7 +3,7 @@ · 2 unmodified lines
3 *3 *
4 * Copyright (C) 2018 CMC NV4 * Copyright (C) 2018 CMC NV
5 *5 *
6 * http://www.ti.com/lit/ds/symlink/dac7311.pdf6 * https://www.ti.com/lit/ds/symlink/dac7311.pdf
7 */7 */
8 8
9#include <linux/iio/iio.h>9#include <linux/iio/iio.h>
@@ -251,8 +251,6 @@ static int ti_dac_probe(struct spi_device *spi) · 241 unmodified lines
251 spi->bits_per_word = 16;251 spi->bits_per_word = 16;
252 spi_setup(spi);252 spi_setup(spi);
253 253
254 indio_dev->dev.parent = dev;
255 indio_dev->dev.of_node = spi->dev.of_node;
256 indio_dev->info = &ti_dac_info;254 indio_dev->info = &ti_dac_info;
257 indio_dev->name = spi_get_device_id(spi)->name;255 indio_dev->name = spi_get_device_id(spi)->name;
258 indio_dev->modes = INDIO_DIRECT_MODE;256 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
139 return PTR_ERR(priv->loaddacs);139 return PTR_ERR(priv->loaddacs);
140 priv->spi = spi;140 priv->spi = spi;
141 spi_set_drvdata(spi, iio_dev);141 spi_set_drvdata(spi, iio_dev);
142 iio_dev->dev.parent = &spi->dev;
143 iio_dev->info = &dac7612_info;142 iio_dev->info = &dac7612_info;
144 iio_dev->modes = INDIO_DIRECT_MODE;143 iio_dev->modes = INDIO_DIRECT_MODE;
145 iio_dev->channels = dac7612_channels;144 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
199 platform_set_drvdata(pdev, indio_dev);199 platform_set_drvdata(pdev, indio_dev);
200 200
201 indio_dev->name = dev_name(&pdev->dev);201 indio_dev->name = dev_name(&pdev->dev);
202 indio_dev->dev.parent = &pdev->dev;
203 indio_dev->dev.of_node = pdev->dev.of_node;
204 indio_dev->info = &vf610_dac_iio_info;202 indio_dev->info = &vf610_dac_iio_info;
205 indio_dev->modes = INDIO_DIRECT_MODE;203 indio_dev->modes = INDIO_DIRECT_MODE;
206 indio_dev->channels = vf610_dac_iio_channels;204 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
566 struct iio_dev *indio_dev;566 struct iio_dev *indio_dev;
567 struct iio_dummy_state *st;567 struct iio_dummy_state *st;
568 struct iio_sw_device *swd;568 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 */
569 576
570 swd = kzalloc(sizeof(*swd), GFP_KERNEL);577 swd = kzalloc(sizeof(*swd), GFP_KERNEL);
571 if (!swd) {578 if (!swd) {
@@ -580,7 +587,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) · 8 unmodified lines
580 * It also has a region (accessed by iio_priv()587 * It also has a region (accessed by iio_priv()
581 * for chip specific state information.588 * for chip specific state information.
582 */589 */
583 indio_dev = iio_device_alloc(sizeof(*st));590 indio_dev = iio_device_alloc(parent, sizeof(*st));
584 if (!indio_dev) {591 if (!indio_dev) {
585 ret = -ENOMEM;592 ret = -ENOMEM;
586 goto error_ret;593 goto error_ret;
@@ -590,11 +597,6 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) · 3 unmodified lines
590 mutex_init(&st->lock);597 mutex_init(&st->lock);
591 598
592 iio_dummy_init_device(indio_dev);599 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 */
598 600
599 /*601 /*
600 * Make the iio_dev struct available to remove function.602 * 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
99}99}
100 100
101static const struct iio_buffer_setup_ops iio_simple_dummy_buffer_setup_ops = {101static 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,
116};102};
117 103
118int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)104int 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
1026 st->spi = spi;1026 st->spi = spi;
1027 st->pdata = pdata;1027 st->pdata = pdata;
1028 1028
1029 indio_dev->dev.parent = &spi->dev;
1030 indio_dev->name = (pdata->name[0] != 0) ? pdata->name :1029 indio_dev->name = (pdata->name[0] != 0) ? pdata->name :
1031 spi_get_device_id(spi)->name;1030 spi_get_device_id(spi)->name;
1032 indio_dev->info = &ad9523_info;1031 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
531 st->spi = spi;531 st->spi = spi;
532 st->pdata = pdata;532 st->pdata = pdata;
533 533
534 indio_dev->dev.parent = &spi->dev;
535 indio_dev->name = (pdata->name[0] != 0) ? pdata->name :534 indio_dev->name = (pdata->name[0] != 0) ? pdata->name :
536 spi_get_device_id(spi)->name;535 spi_get_device_id(spi)->name;
537 536
drivers/iio/frequency/adf4371.c+0−1
@@ -573,7 +573,6 @@ static int adf4371_probe(struct spi_device *spi) · 572 unmodified lines
573 mutex_init(&st->lock);573 mutex_init(&st->lock);
574 574
575 st->chip_info = &adf4371_chip_info[id->driver_data];575 st->chip_info = &adf4371_chip_info[id->driver_data];
576 indio_dev->dev.parent = &spi->dev;
577 indio_dev->name = id->name;576 indio_dev->name = id->name;
578 indio_dev->info = &adf4371_info;577 indio_dev->info = &adf4371_info;
579 indio_dev->modes = INDIO_DIRECT_MODE;578 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
207 indio_dev->name = spi->dev.driver->name;207 indio_dev->name = spi->dev.driver->name;
208 indio_dev->channels = adis16080_channels;208 indio_dev->channels = adis16080_channels;
209 indio_dev->num_channels = ARRAY_SIZE(adis16080_channels);209 indio_dev->num_channels = ARRAY_SIZE(adis16080_channels);
210 indio_dev->dev.parent = &spi->dev;
211 indio_dev->info = &adis16080_info;210 indio_dev->info = &adis16080_info;
212 indio_dev->modes = INDIO_DIRECT_MODE;211 indio_dev->modes = INDIO_DIRECT_MODE;
213 212
drivers/iio/gyro/adis16130.c+0−1
@@ -155,7 +155,6 @@ static int adis16130_probe(struct spi_device *spi) · 154 unmodified lines
155 indio_dev->name = spi->dev.driver->name;155 indio_dev->name = spi->dev.driver->name;
156 indio_dev->channels = adis16130_channels;156 indio_dev->channels = adis16130_channels;
157 indio_dev->num_channels = ARRAY_SIZE(adis16130_channels);157 indio_dev->num_channels = ARRAY_SIZE(adis16130_channels);
158 indio_dev->dev.parent = &spi->dev;
159 indio_dev->info = &adis16130_info;158 indio_dev->info = &adis16130_info;
160 indio_dev->modes = INDIO_DIRECT_MODE;159 indio_dev->modes = INDIO_DIRECT_MODE;
161 160
drivers/iio/gyro/adis16136.c+0−1
@@ -540,7 +540,6 @@ static int adis16136_probe(struct spi_device *spi) · 539 unmodified lines
540 adis16136 = iio_priv(indio_dev);540 adis16136 = iio_priv(indio_dev);
541 541
542 adis16136->chip_info = &adis16136_chip_info[id->driver_data];542 adis16136->chip_info = &adis16136_chip_info[id->driver_data];
543 indio_dev->dev.parent = &spi->dev;
544 indio_dev->name = spi_get_device_id(spi)->name;543 indio_dev->name = spi_get_device_id(spi)->name;
545 indio_dev->channels = adis16136_channels;544 indio_dev->channels = adis16136_channels;
546 indio_dev->num_channels = ARRAY_SIZE(adis16136_channels);545 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
381 adis16260->info = &adis16260_chip_info_table[id->driver_data];381 adis16260->info = &adis16260_chip_info_table[id->driver_data];
382 382
383 indio_dev->name = id->name;383 indio_dev->name = id->name;
384 indio_dev->dev.parent = &spi->dev;
385 indio_dev->info = &adis16260_info;384 indio_dev->info = &adis16260_info;
386 indio_dev->channels = adis16260->info->channels;385 indio_dev->channels = adis16260->info->channels;
387 indio_dev->num_channels = adis16260->info->num_channels;386 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
424 /* This is only used for removal purposes */424 /* This is only used for removal purposes */
425 spi_set_drvdata(spi, indio_dev);425 spi_set_drvdata(spi, indio_dev);
426 426
427 indio_dev->dev.parent = &spi->dev;
428 indio_dev->info = &adxrs450_info;427 indio_dev->info = &adxrs450_info;
429 indio_dev->modes = INDIO_DIRECT_MODE;428 indio_dev->modes = INDIO_DIRECT_MODE;
430 indio_dev->channels =429 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
1051 1051
1052static const struct iio_buffer_setup_ops bmg160_buffer_setup_ops = {1052static const struct iio_buffer_setup_ops bmg160_buffer_setup_ops = {
1053 .preenable = bmg160_buffer_preenable,1053 .preenable = bmg160_buffer_preenable,
1054 .postenable = iio_triggered_buffer_postenable,
1055 .predisable = iio_triggered_buffer_predisable,
1056 .postdisable = bmg160_buffer_postdisable,1054 .postdisable = bmg160_buffer_postdisable,
1057};1055};
1058 1056
@@ -1097,7 +1095,6 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, · 38 unmodified lines
1097 if (ACPI_HANDLE(dev))1095 if (ACPI_HANDLE(dev))
1098 name = bmg160_match_acpi_device(dev);1096 name = bmg160_match_acpi_device(dev);
1099 1097
1100 indio_dev->dev.parent = dev;
1101 indio_dev->channels = bmg160_channels;1098 indio_dev->channels = bmg160_channels;
1102 indio_dev->num_channels = ARRAY_SIZE(bmg160_channels);1099 indio_dev->num_channels = ARRAY_SIZE(bmg160_channels);
1103 indio_dev->name = name;1100 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
905 if (ret < 0)905 if (ret < 0)
906 return ret;906 return ret;
907 907
908 indio_dev->dev.parent = dev;
909 indio_dev->channels = fxas21002c_channels;908 indio_dev->channels = fxas21002c_channels;
910 indio_dev->num_channels = ARRAY_SIZE(fxas21002c_channels);909 indio_dev->num_channels = ARRAY_SIZE(fxas21002c_channels);
911 indio_dev->name = name;910 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
319 }319 }
320 320
321 indio_dev->num_channels = ARRAY_SIZE(gyro_3d_channels);321 indio_dev->num_channels = ARRAY_SIZE(gyro_3d_channels);
322 indio_dev->dev.parent = &pdev->dev;
323 indio_dev->info = &gyro_3d_info;322 indio_dev->info = &gyro_3d_info;
324 indio_dev->name = name;323 indio_dev->name = name;
325 indio_dev->modes = INDIO_DIRECT_MODE;324 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
316 i2c_set_clientdata(client, indio_dev);316 i2c_set_clientdata(client, indio_dev);
317 st->i2c = client;317 st->i2c = client;
318 318
319 indio_dev->dev.parent = &client->dev;
320 indio_dev->name = client->dev.driver->name;319 indio_dev->name = client->dev.driver->name;
321 indio_dev->channels = itg3200_channels;320 indio_dev->channels = itg3200_channels;
322 indio_dev->num_channels = ARRAY_SIZE(itg3200_channels);321 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
662 662
663static const struct iio_buffer_setup_ops mpu3050_buffer_setup_ops = {663static const struct iio_buffer_setup_ops mpu3050_buffer_setup_ops = {
664 .preenable = mpu3050_buffer_preenable,664 .preenable = mpu3050_buffer_preenable,
665 .postenable = iio_triggered_buffer_postenable,
666 .predisable = iio_triggered_buffer_predisable,
667 .postdisable = mpu3050_buffer_postdisable,665 .postdisable = mpu3050_buffer_postdisable,
668};666};
669 667
@@ -1198,7 +1196,6 @@ int mpu3050_common_probe(struct device *dev, · 528 unmodified lines
1198 if (ret)1196 if (ret)
1199 goto err_power_down;1197 goto err_power_down;
1200 1198
1201 indio_dev->dev.parent = dev;
1202 indio_dev->channels = mpu3050_channels;1199 indio_dev->channels = mpu3050_channels;
1203 indio_dev->num_channels = ARRAY_SIZE(mpu3050_channels);1200 indio_dev->num_channels = ARRAY_SIZE(mpu3050_channels);
1204 indio_dev->info = &mpu3050_info;1201 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
108 spd->type = SSP_GYROSCOPE_SENSOR;108 spd->type = SSP_GYROSCOPE_SENSOR;
109 109
110 indio_dev->name = ssp_gyro_name;110 indio_dev->name = ssp_gyro_name;
111 indio_dev->dev.parent = &pdev->dev;
112 indio_dev->info = &ssp_gyro_iio_info;111 indio_dev->info = &ssp_gyro_iio_info;
113 indio_dev->modes = INDIO_BUFFER_SOFTWARE;112 indio_dev->modes = INDIO_BUFFER_SOFTWARE;
114 indio_dev->channels = ssp_gyro_channels;113 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
33{33{
34 int err;34 int err;
35 35
36 err = iio_triggered_buffer_postenable(indio_dev);
37 if (err < 0)
38 return err;
39
40 err = st_sensors_set_axis_enable(indio_dev, indio_dev->active_scan_mask[0]);36 err = st_sensors_set_axis_enable(indio_dev, indio_dev->active_scan_mask[0]);
41 if (err < 0)37 if (err < 0)
42 goto st_gyro_buffer_predisable;38 return err;
43 39
44 err = st_sensors_set_enable(indio_dev, true);40 err = st_sensors_set_enable(indio_dev, true);
45 if (err < 0)41 if (err < 0)
@@ -49,27 +45,18 @@ static int st_gyro_buffer_postenable(struct iio_dev *indio_dev) · 3 unmodified lines
49 45
50st_gyro_buffer_enable_all_axis:46st_gyro_buffer_enable_all_axis:
51 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);47 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
52st_gyro_buffer_predisable:
53 iio_triggered_buffer_predisable(indio_dev);
54 return err;48 return err;
55}49}
56 50
57static int st_gyro_buffer_predisable(struct iio_dev *indio_dev)51static int st_gyro_buffer_predisable(struct iio_dev *indio_dev)
58{52{
59 int err, err2;53 int err;
60 54
61 err = st_sensors_set_enable(indio_dev, false);55 err = st_sensors_set_enable(indio_dev, false);
62 if (err < 0)56 if (err < 0)
63 goto st_gyro_buffer_predisable;57 return err;
64
65 err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
66
67st_gyro_buffer_predisable:
68 err2 = iio_triggered_buffer_predisable(indio_dev);
69 if (!err)
70 err = err2;
71 58
72 return err;59 return st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
73}60}
74 61
75static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = {62static 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
2/*2/*
3 * AFE4403 Heart Rate Monitors and Low-Cost Pulse Oximeters3 * AFE4403 Heart Rate Monitors and Low-Cost Pulse Oximeters
4 *4 *
5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/
6 * Andrew F. Davis <afd@ti.com>6 * Andrew F. Davis <afd@ti.com>
7 */7 */
8 8
@@ -509,7 +509,6 @@ static int afe4403_probe(struct spi_device *spi) · 500 unmodified lines
509 }509 }
510 510
511 indio_dev->modes = INDIO_DIRECT_MODE;511 indio_dev->modes = INDIO_DIRECT_MODE;
512 indio_dev->dev.parent = afe->dev;
513 indio_dev->channels = afe4403_channels;512 indio_dev->channels = afe4403_channels;
514 indio_dev->num_channels = ARRAY_SIZE(afe4403_channels);513 indio_dev->num_channels = ARRAY_SIZE(afe4403_channels);
515 indio_dev->name = AFE4403_DRIVER_NAME;514 indio_dev->name = AFE4403_DRIVER_NAME;
drivers/iio/health/afe4404.c+1−2
@@ -2,7 +2,7 @@ · 1 unmodified line
2/*2/*
3 * AFE4404 Heart Rate Monitors and Low-Cost Pulse Oximeters3 * AFE4404 Heart Rate Monitors and Low-Cost Pulse Oximeters
4 *4 *
5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/
6 * Andrew F. Davis <afd@ti.com>6 * Andrew F. Davis <afd@ti.com>
7 */7 */
8 8
@@ -517,7 +517,6 @@ static int afe4404_probe(struct i2c_client *client, · 508 unmodified lines
517 }517 }
518 518
519 indio_dev->modes = INDIO_DIRECT_MODE;519 indio_dev->modes = INDIO_DIRECT_MODE;
520 indio_dev->dev.parent = afe->dev;
521 indio_dev->channels = afe4404_channels;520 indio_dev->channels = afe4404_channels;
522 indio_dev->num_channels = ARRAY_SIZE(afe4404_channels);521 indio_dev->num_channels = ARRAY_SIZE(afe4404_channels);
523 indio_dev->name = AFE4404_DRIVER_NAME;522 indio_dev->name = AFE4404_DRIVER_NAME;
drivers/iio/health/afe440x.h+1−1
@@ -2,7 +2,7 @@ · 1 unmodified line
2/*2/*
3 * AFE440X Heart Rate Monitors and Low-Cost Pulse Oximeters3 * AFE440X Heart Rate Monitors and Low-Cost Pulse Oximeters
4 *4 *
5 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/5 * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
6 * Andrew F. Davis <afd@ti.com>6 * Andrew F. Davis <afd@ti.com>
7 */7 */
8 8
drivers/iio/health/max30100.c+0−1
@@ -439,7 +439,6 @@ static int max30100_probe(struct i2c_client *client, · 438 unmodified lines
439 indio_dev->available_scan_masks = max30100_scan_masks;439 indio_dev->available_scan_masks = max30100_scan_masks;
440 indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);440 indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);
441 indio_dev->setup_ops = &max30100_buffer_setup_ops;441 indio_dev->setup_ops = &max30100_buffer_setup_ops;
442 indio_dev->dev.parent = &client->dev;
443 442
444 data = iio_priv(indio_dev);443 data = iio_priv(indio_dev);
445 data->indio_dev = indio_dev;444 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
526 indio_dev->info = &max30102_info;526 indio_dev->info = &max30102_info;
527 indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);527 indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);
528 indio_dev->setup_ops = &max30102_buffer_setup_ops;528 indio_dev->setup_ops = &max30102_buffer_setup_ops;
529 indio_dev->dev.parent = &client->dev;
530 529
531 data = iio_priv(indio_dev);530 data = iio_priv(indio_dev);
532 data->indio_dev = indio_dev;531 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
233 i2c_set_clientdata(client, indio_dev);233 i2c_set_clientdata(client, indio_dev);
234 mutex_init(&data->lock);234 mutex_init(&data->lock);
235 235
236 indio_dev->dev.parent = &client->dev;
237 indio_dev->info = &am2315_info;236 indio_dev->info = &am2315_info;
238 indio_dev->name = AM2315_DRIVER_NAME;237 indio_dev->name = AM2315_DRIVER_NAME;
239 indio_dev->modes = INDIO_DIRECT_MODE;238 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
321 init_completion(&dht11->completion);321 init_completion(&dht11->completion);
322 mutex_init(&dht11->lock);322 mutex_init(&dht11->lock);
323 iio->name = pdev->name;323 iio->name = pdev->name;
324 iio->dev.parent = &pdev->dev;
325 iio->info = &dht11_iio_info;324 iio->info = &dht11_iio_info;
326 iio->modes = INDIO_DIRECT_MODE;325 iio->modes = INDIO_DIRECT_MODE;
327 iio->channels = dht11_chan_spec;326 iio->channels = dht11_chan_spec;
drivers/iio/humidity/hdc100x.c+6−17
@@ -6,11 +6,11 @@ · 5 unmodified lines
6 * Author: Matt Ranostay <matt.ranostay@konsulko.com>6 * Author: Matt Ranostay <matt.ranostay@konsulko.com>
7 *7 *
8 * Datasheets:8 * Datasheets:
9 * http://www.ti.com/product/HDC1000/datasheet9 * https://www.ti.com/product/HDC1000/datasheet
10 * http://www.ti.com/product/HDC1008/datasheet10 * https://www.ti.com/product/HDC1008/datasheet
11 * http://www.ti.com/product/HDC1010/datasheet11 * https://www.ti.com/product/HDC1010/datasheet
12 * http://www.ti.com/product/HDC1050/datasheet12 * https://www.ti.com/product/HDC1050/datasheet
13 * http://www.ti.com/product/HDC1080/datasheet13 * https://www.ti.com/product/HDC1080/datasheet
14 */14 */
15 15
16#include <linux/delay.h>16#include <linux/delay.h>
@@ -278,17 +278,11 @@ static int hdc100x_buffer_postenable(struct iio_dev *indio_dev) · 261 unmodified lines
278 struct hdc100x_data *data = iio_priv(indio_dev);278 struct hdc100x_data *data = iio_priv(indio_dev);
279 int ret;279 int ret;
280 280
281 ret = iio_triggered_buffer_postenable(indio_dev);
282 if (ret)
283 return ret;
284
285 /* Buffer is enabled. First set ACQ Mode, then attach poll func */281 /* Buffer is enabled. First set ACQ Mode, then attach poll func */
286 mutex_lock(&data->lock);282 mutex_lock(&data->lock);
287 ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE,283 ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE,
288 HDC100X_REG_CONFIG_ACQ_MODE);284 HDC100X_REG_CONFIG_ACQ_MODE);
289 mutex_unlock(&data->lock);285 mutex_unlock(&data->lock);
290 if (ret)
291 iio_triggered_buffer_predisable(indio_dev);
292 286
293 return ret;287 return ret;
294}288}
@@ -296,16 +290,12 @@ static int hdc100x_buffer_postenable(struct iio_dev *indio_dev) · 1 unmodified line
296static int hdc100x_buffer_predisable(struct iio_dev *indio_dev)290static int hdc100x_buffer_predisable(struct iio_dev *indio_dev)
297{291{
298 struct hdc100x_data *data = iio_priv(indio_dev);292 struct hdc100x_data *data = iio_priv(indio_dev);
299 int ret, ret2;293 int ret;
300 294
301 mutex_lock(&data->lock);295 mutex_lock(&data->lock);
302 ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE, 0);296 ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE, 0);
303 mutex_unlock(&data->lock);297 mutex_unlock(&data->lock);
304 298
305 ret2 = iio_triggered_buffer_predisable(indio_dev);
306 if (ret == 0)
307 ret = ret2;
308
309 return ret;299 return ret;
310}300}
311 301
@@ -374,7 +364,6 @@ static int hdc100x_probe(struct i2c_client *client, · 62 unmodified lines
374 data->client = client;364 data->client = client;
375 mutex_init(&data->lock);365 mutex_init(&data->lock);
376 366
377 indio_dev->dev.parent = &client->dev;
378 indio_dev->name = dev_name(&client->dev);367 indio_dev->name = dev_name(&client->dev);
379 indio_dev->modes = INDIO_DIRECT_MODE;368 indio_dev->modes = INDIO_DIRECT_MODE;
380 indio_dev->info = &hdc100x_info;369 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
226 226
227 indio_dev->channels = humid_chans;227 indio_dev->channels = humid_chans;
228 indio_dev->num_channels = ARRAY_SIZE(humidity_channels);228 indio_dev->num_channels = ARRAY_SIZE(humidity_channels);
229 indio_dev->dev.parent = &pdev->dev;
230 indio_dev->info = &humidity_info;229 indio_dev->info = &humidity_info;
231 indio_dev->name = name;230 indio_dev->name = name;
232 indio_dev->modes = INDIO_DIRECT_MODE;231 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
46int hts221_probe(struct device *dev, int irq, const char *name,46int hts221_probe(struct device *dev, int irq, const char *name,
47 struct regmap *regmap);47 struct regmap *regmap);
48int hts221_set_enable(struct hts221_hw *hw, bool enable);48int hts221_set_enable(struct hts221_hw *hw, bool enable);
49int hts221_allocate_buffers(struct hts221_hw *hw);49int hts221_allocate_buffers(struct iio_dev *iio_dev);
50int hts221_allocate_trigger(struct hts221_hw *hw);50int hts221_allocate_trigger(struct iio_dev *iio_dev);
51 51
52#endif /* HTS221_H */52#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
72 return IRQ_HANDLED;72 return IRQ_HANDLED;
73}73}
74 74
75int hts221_allocate_trigger(struct hts221_hw *hw)75int hts221_allocate_trigger(struct iio_dev *iio_dev)
76{76{
77 struct hts221_hw *hw = iio_priv(iio_dev);
77 struct st_sensors_platform_data *pdata = dev_get_platdata(hw->dev);78 struct st_sensors_platform_data *pdata = dev_get_platdata(hw->dev);
78 struct iio_dev *iio_dev = iio_priv_to_dev(hw);
79 bool irq_active_low = false, open_drain = false;79 bool irq_active_low = false, open_drain = false;
80 unsigned long irq_type;80 unsigned long irq_type;
81 int err;81 int err;
@@ -153,8 +153,6 @@ static int hts221_buffer_postdisable(struct iio_dev *iio_dev) · 71 unmodified lines
153 153
154static const struct iio_buffer_setup_ops hts221_buffer_ops = {154static const struct iio_buffer_setup_ops hts221_buffer_ops = {
155 .preenable = hts221_buffer_preenable,155 .preenable = hts221_buffer_preenable,
156 .postenable = iio_triggered_buffer_postenable,
157 .predisable = iio_triggered_buffer_predisable,
158 .postdisable = hts221_buffer_postdisable,156 .postdisable = hts221_buffer_postdisable,
159};157};
160 158
@@ -190,9 +188,10 @@ out: · 29 unmodified lines
190 return IRQ_HANDLED;188 return IRQ_HANDLED;
191}189}
192 190
193int hts221_allocate_buffers(struct hts221_hw *hw)191int hts221_allocate_buffers(struct iio_dev *iio_dev)
194{192{
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,
196 NULL, hts221_buffer_handler_thread,195 NULL, hts221_buffer_handler_thread,
197 &hts221_buffer_ops);196 &hts221_buffer_ops);
198}197}
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
572 return err;572 return err;
573 573
574 iio_dev->modes = INDIO_DIRECT_MODE;574 iio_dev->modes = INDIO_DIRECT_MODE;
575 iio_dev->dev.parent = hw->dev;
576 iio_dev->available_scan_masks = hts221_scan_masks;575 iio_dev->available_scan_masks = hts221_scan_masks;
577 iio_dev->channels = hts221_channels;576 iio_dev->channels = hts221_channels;
578 iio_dev->num_channels = ARRAY_SIZE(hts221_channels);577 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
621 }620 }
622 621
623 if (hw->irq > 0) {622 if (hw->irq > 0) {
624 err = hts221_allocate_buffers(hw);623 err = hts221_allocate_buffers(iio_dev);
625 if (err < 0)624 if (err < 0)
626 return err;625 return err;
627 626
628 err = hts221_allocate_trigger(hw);627 err = hts221_allocate_trigger(iio_dev);
629 if (err)628 if (err)
630 return err;629 return err;
631 }630 }
drivers/iio/humidity/htu21.c+0−1
@@ -204,7 +204,6 @@ static int htu21_probe(struct i2c_client *client, · 203 unmodified lines
204 204
205 indio_dev->info = &htu21_info;205 indio_dev->info = &htu21_info;
206 indio_dev->name = id->name;206 indio_dev->name = id->name;
207 indio_dev->dev.parent = &client->dev;
208 indio_dev->modes = INDIO_DIRECT_MODE;207 indio_dev->modes = INDIO_DIRECT_MODE;
209 208
210 if (id->driver_data == MS8607) {209 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
142 data->client = client;142 data->client = client;
143 mutex_init(&data->lock);143 mutex_init(&data->lock);
144 144
145 indio_dev->dev.parent = &client->dev;
146 indio_dev->name = dev_name(&client->dev);145 indio_dev->name = dev_name(&client->dev);
147 indio_dev->modes = INDIO_DIRECT_MODE;146 indio_dev->modes = INDIO_DIRECT_MODE;
148 indio_dev->info = &si7005_info;147 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
128 data = iio_priv(indio_dev);128 data = iio_priv(indio_dev);
129 *data = client;129 *data = client;
130 130
131 indio_dev->dev.parent = &client->dev;
132 indio_dev->name = dev_name(&client->dev);131 indio_dev->name = dev_name(&client->dev);
133 indio_dev->modes = INDIO_DIRECT_MODE;132 indio_dev->modes = INDIO_DIRECT_MODE;
134 indio_dev->info = &si7020_info;133 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
18 **/18 **/
19void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev);19void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev);
20 20
21
22int iio_trigger_attach_poll_func(struct iio_trigger *trig,
23 struct iio_poll_func *pf);
24int iio_trigger_detach_poll_func(struct iio_trigger *trig,
25 struct iio_poll_func *pf);
26
21#else27#else
22 28
23/**29/**
@@ -37,4 +43,15 @@ static void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev) · 13 unmodified lines
37{43{
38}44}
39 45
46static inline int iio_trigger_attach_poll_func(struct iio_trigger *trig,
47 struct iio_poll_func *pf)
48{
49 return 0;
50}
51static inline int iio_trigger_detach_poll_func(struct iio_trigger *trig,
52 struct iio_poll_func *pf)
53{
54 return 0;
55}
56
40#endif /* CONFIG_TRIGGER_CONSUMER */57#endif /* CONFIG_TRIGGER_CONSUMER */
drivers/iio/imu/Kconfig+1−0
@@ -91,6 +91,7 @@ config KMX61 · 90 unmodified lines
91 To compile this driver as module, choose M here: the module will91 To compile this driver as module, choose M here: the module will
92 be called kmx61.92 be called kmx61.
93 93
94source "drivers/iio/imu/inv_icm42600/Kconfig"
94source "drivers/iio/imu/inv_mpu6050/Kconfig"95source "drivers/iio/imu/inv_mpu6050/Kconfig"
95source "drivers/iio/imu/st_lsm6dsx/Kconfig"96source "drivers/iio/imu/st_lsm6dsx/Kconfig"
96 97
drivers/iio/imu/Makefile+1−0
@@ -20,6 +20,7 @@ obj-$(CONFIG_FXOS8700) += fxos8700_core.o · 19 unmodified lines
20obj-$(CONFIG_FXOS8700_I2C) += fxos8700_i2c.o20obj-$(CONFIG_FXOS8700_I2C) += fxos8700_i2c.o
21obj-$(CONFIG_FXOS8700_SPI) += fxos8700_spi.o21obj-$(CONFIG_FXOS8700_SPI) += fxos8700_spi.o
22 22
23obj-y += inv_icm42600/
23obj-y += inv_mpu6050/24obj-y += inv_mpu6050/
24 25
25obj-$(CONFIG_KMX61) += kmx61.o26obj-$(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
1181 1181
1182 /* setup the industrialio driver allocated elements */1182 /* setup the industrialio driver allocated elements */
1183 st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data];1183 st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data];
1184 indio_dev->dev.parent = &spi->dev;
1185 indio_dev->name = spi_get_device_id(spi)->name;1184 indio_dev->name = spi_get_device_id(spi)->name;
1186 indio_dev->channels = st->variant->channels;1185 indio_dev->channels = st->variant->channels;
1187 indio_dev->num_channels = st->variant->num_channels;1186 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
393 st = iio_priv(indio_dev);393 st = iio_priv(indio_dev);
394 394
395 st->chip_info = &adis16460_chip_info;395 st->chip_info = &adis16460_chip_info;
396 indio_dev->dev.parent = &spi->dev;
397 indio_dev->name = spi_get_device_id(spi)->name;396 indio_dev->name = spi_get_device_id(spi)->name;
398 indio_dev->channels = st->chip_info->channels;397 indio_dev->channels = st->chip_info->channels;
399 indio_dev->num_channels = st->chip_info->num_channels;398 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
1289 if (ret)1289 if (ret)
1290 return ret;1290 return ret;
1291 1291
1292 indio_dev->dev.parent = &spi->dev;
1293 indio_dev->name = st->info->name;1292 indio_dev->name = st->info->name;
1294 indio_dev->channels = st->info->channels;1293 indio_dev->channels = st->info->channels;
1295 indio_dev->num_channels = st->info->num_channels;1294 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
1102 /*1102 /*
1103 * Get the interrupt line behaviour. The data ready polarity can be1103 * Get the interrupt line behaviour. The data ready polarity can be
1104 * configured as positive or negative, corresponding to1104 * 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.
1106 */1106 */
1107 irq_type = irqd_get_trigger_type(desc);1107 irq_type = irqd_get_trigger_type(desc);
1108 if (irq_type == IRQF_TRIGGER_RISING) { /* Default */1108 if (irq_type == IRQ_TYPE_EDGE_RISING) { /* Default */
1109 val |= ADIS16480_DRDY_POL(1);1109 val |= ADIS16480_DRDY_POL(1);
1110 } else if (irq_type == IRQF_TRIGGER_FALLING) {1110 } else if (irq_type == IRQ_TYPE_EDGE_FALLING) {
1111 val |= ADIS16480_DRDY_POL(0);1111 val |= ADIS16480_DRDY_POL(0);
1112 } else {1112 } else {
1113 dev_err(&st->adis.spi->dev,1113 dev_err(&st->adis.spi->dev,
@@ -1229,7 +1229,6 @@ static int adis16480_probe(struct spi_device *spi) · 115 unmodified lines
1229 st = iio_priv(indio_dev);1229 st = iio_priv(indio_dev);
1230 1230
1231 st->chip_info = &adis16480_chip_info[id->driver_data];1231 st->chip_info = &adis16480_chip_info[id->driver_data];
1232 indio_dev->dev.parent = &spi->dev;
1233 indio_dev->name = spi_get_device_id(spi)->name;1232 indio_dev->name = spi_get_device_id(spi)->name;
1234 indio_dev->channels = st->chip_info->channels;1233 indio_dev->channels = st->chip_info->channels;
1235 indio_dev->num_channels = st->chip_info->num_channels;1234 indio_dev->num_channels = st->chip_info->num_channels;
drivers/iio/imu/bmi160/bmi160.h+3−0
@@ -3,10 +3,13 @@ · 2 unmodified lines
3#define BMI160_H_3#define BMI160_H_
4 4
5#include <linux/iio/iio.h>5#include <linux/iio/iio.h>
6#include <linux/regulator/consumer.h>
6 7
7struct bmi160_data {8struct bmi160_data {
8 struct regmap *regmap;9 struct regmap *regmap;
9 struct iio_trigger *trig;10 struct iio_trigger *trig;
11 struct regulator_bulk_data supplies[2];
12 struct iio_mount_matrix orientation;
10};13};
11 14
12extern const struct regmap_config bmi160_regmap_config;15extern const struct regmap_config bmi160_regmap_config;
drivers/iio/imu/bmi160/bmi160_core.c+45−2
@@ -15,6 +15,7 @@ · 14 unmodified lines
15#include <linux/delay.h>15#include <linux/delay.h>
16#include <linux/irq.h>16#include <linux/irq.h>
17#include <linux/of_irq.h>17#include <linux/of_irq.h>
18#include <linux/regulator/consumer.h>
18 19
19#include <linux/iio/iio.h>20#include <linux/iio/iio.h>
20#include <linux/iio/triggered_buffer.h>21#include <linux/iio/triggered_buffer.h>
@@ -109,6 +110,7 @@ · 88 unmodified lines
109 .storagebits = 16, \110 .storagebits = 16, \
110 .endianness = IIO_LE, \111 .endianness = IIO_LE, \
111 }, \112 }, \
113 .ext_info = bmi160_ext_info, \
112}114}
113 115
114/* scan indexes follow DATA register order */116/* scan indexes follow DATA register order */
@@ -264,6 +266,20 @@ static const struct bmi160_odr_item bmi160_odr_table[] = { · 149 unmodified lines
264 },266 },
265};267};
266 268
269static const struct iio_mount_matrix *
270bmi160_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
278static 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
267static const struct iio_chan_spec bmi160_channels[] = {283static const struct iio_chan_spec bmi160_channels[] = {
268 BMI160_CHANNEL(IIO_ACCEL, X, BMI160_SCAN_ACCEL_X),284 BMI160_CHANNEL(IIO_ACCEL, X, BMI160_SCAN_ACCEL_X),
269 BMI160_CHANNEL(IIO_ACCEL, Y, BMI160_SCAN_ACCEL_Y),285 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
709 unsigned int val;725 unsigned int val;
710 struct device *dev = regmap_get_device(data->regmap);726 struct device *dev = regmap_get_device(data->regmap);
711 727
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
712 ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);734 ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
713 if (ret)735 if (ret)
714 return ret;736 return ret;
@@ -793,9 +815,16 @@ int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type) · 78 unmodified lines
793static void bmi160_chip_uninit(void *data)815static void bmi160_chip_uninit(void *data)
794{816{
795 struct bmi160_data *bmi_data = data;817 struct bmi160_data *bmi_data = data;
818 struct device *dev = regmap_get_device(bmi_data->regmap);
819 int ret;
796 820
797 bmi160_set_mode(bmi_data, BMI160_GYRO, false);821 bmi160_set_mode(bmi_data, BMI160_GYRO, false);
798 bmi160_set_mode(bmi_data, BMI160_ACCEL, false);822 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);
799}828}
800 829
801int bmi160_core_probe(struct device *dev, struct regmap *regmap,830int 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
815 dev_set_drvdata(dev, indio_dev);844 dev_set_drvdata(dev, indio_dev);
816 data->regmap = regmap;845 data->regmap = regmap;
817 846
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
818 ret = bmi160_chip_init(data, use_spi);862 ret = bmi160_chip_init(data, use_spi);
819 if (ret)863 if (ret)
820 return ret;864 return ret;
@@ -826,7 +870,6 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, · 5 unmodified lines
826 if (!name && ACPI_HANDLE(dev))870 if (!name && ACPI_HANDLE(dev))
827 name = bmi160_match_acpi_device(dev);871 name = bmi160_match_acpi_device(dev);
828 872
829 indio_dev->dev.parent = dev;
830 indio_dev->channels = bmi160_channels;873 indio_dev->channels = bmi160_channels;
831 indio_dev->num_channels = ARRAY_SIZE(bmi160_channels);874 indio_dev->num_channels = ARRAY_SIZE(bmi160_channels);
832 indio_dev->name = name;875 indio_dev->name = name;
@@ -853,6 +896,6 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, · 20 unmodified lines
853}896}
854EXPORT_SYMBOL_GPL(bmi160_core_probe);897EXPORT_SYMBOL_GPL(bmi160_core_probe);
855 898
856MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");899MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
857MODULE_DESCRIPTION("Bosch BMI160 driver");900MODULE_DESCRIPTION("Bosch BMI160 driver");
858MODULE_LICENSE("GPL v2");901MODULE_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
633 if (ret)633 if (ret)
634 return ret;634 return ret;
635 635
636 indio_dev->dev.parent = dev;
637 indio_dev->channels = fxos8700_channels;636 indio_dev->channels = fxos8700_channels;
638 indio_dev->num_channels = ARRAY_SIZE(fxos8700_channels);637 indio_dev->num_channels = ARRAY_SIZE(fxos8700_channels);
639 indio_dev->name = name ? name : "fxos8700";638 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
3config INV_ICM42600
4 tristate
5 select IIO_BUFFER
6
7config 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
19config 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
3obj-$(CONFIG_INV_ICM42600) += inv-icm42600.o
4inv-icm42600-y += inv_icm42600_core.o
5inv-icm42600-y += inv_icm42600_gyro.o
6inv-icm42600-y += inv_icm42600_accel.o
7inv-icm42600-y += inv_icm42600_temp.o
8inv-icm42600-y += inv_icm42600_buffer.o
9inv-icm42600-y += inv_icm42600_timestamp.o
10
11obj-$(CONFIG_INV_ICM42600_I2C) += inv-icm42600-i2c.o
12inv-icm42600-i2c-y += inv_icm42600_i2c.o
13
14obj-$(CONFIG_INV_ICM42600_SPI) += inv-icm42600-spi.o
15inv-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
19enum 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 */
28enum 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
37enum 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 */
46enum 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 */
59enum 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 */
68enum 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
85enum 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
94struct 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
102struct inv_icm42600_conf {
103 struct inv_icm42600_sensor_conf gyro;
104 struct inv_icm42600_sensor_conf accel;
105 bool temp_en;
106};
107
108struct 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 */
131struct 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
359typedef int (*inv_icm42600_bus_setup)(struct inv_icm42600_state *);
360
361extern const struct regmap_config inv_icm42600_regmap_config;
362extern const struct dev_pm_ops inv_icm42600_pm_ops;
363
364const struct iio_mount_matrix *
365inv_icm42600_get_mount_matrix(const struct iio_dev *indio_dev,
366 const struct iio_chan_spec *chan);
367
368uint32_t inv_icm42600_odr_to_period(enum inv_icm42600_odr odr);
369
370int inv_icm42600_set_accel_conf(struct inv_icm42600_state *st,
371 struct inv_icm42600_sensor_conf *conf,
372 unsigned int *sleep_ms);
373
374int inv_icm42600_set_gyro_conf(struct inv_icm42600_state *st,
375 struct inv_icm42600_sensor_conf *conf,
376 unsigned int *sleep_ms);
377
378int inv_icm42600_set_temp_conf(struct inv_icm42600_state *st, bool enable,
379 unsigned int *sleep_ms);
380
381int inv_icm42600_debugfs_reg(struct iio_dev *indio_dev, unsigned int reg,
382 unsigned int writeval, unsigned int *readval);
383
384int inv_icm42600_core_probe(struct regmap *regmap, int chip, int irq,
385 inv_icm42600_bus_setup bus_setup);
386
387struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st);
388
389int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev);
390
391struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st);
392
393int 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
49enum 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
57static 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
62static 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 */
77struct 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
90static 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 */
97static 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
136out_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
148static 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;
193exit:
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 */
201static 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
216static 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
228static 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 */
259static 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
278static 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
289static 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
310static 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
344out_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 */
356static 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
362static 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
438static 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
534out_unlock:
535 mutex_unlock(&st->lock);
536 pm_runtime_mark_last_busy(dev);
537 pm_runtime_put_autosuspend(dev);
538 return ret;
539}
540
541static 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
580static 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
608static 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
640static 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
659static 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
675static 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
695static 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
706struct 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
748int 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
27struct 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
34struct 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
43ssize_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
100void 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
122int 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
152static 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
165static 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 */
202int 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
274static 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 */
288static 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
325out_on:
326 /* increase FIFO on counter */
327 st->fifo.on++;
328out_unlock:
329 mutex_unlock(&st->lock);
330 return ret;
331}
332
333static 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
364out_off:
365 /* decrease FIFO on counter */
366 st->fifo.on--;
367out_unlock:
368 mutex_unlock(&st->lock);
369 return ret;
370}
371
372static 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
422out_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
439const 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
446int 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
505int 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
536int 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
576int 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
12struct 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 */
28struct 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 */
46struct 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
53static inline int16_t inv_icm42600_fifo_get_sensor_data(__be16 d)
54{
55 return be16_to_cpu(d);
56}
57
58static inline bool
59inv_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
75ssize_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
79extern const struct iio_buffer_setup_ops inv_icm42600_buffer_ops;
80
81int inv_icm42600_buffer_init(struct inv_icm42600_state *st);
82
83void inv_icm42600_buffer_update_fifo_period(struct inv_icm42600_state *st);
84
85int inv_icm42600_buffer_set_fifo_en(struct inv_icm42600_state *st,
86 unsigned int fifo_en);
87
88int inv_icm42600_buffer_update_watermark(struct inv_icm42600_state *st);
89
90int inv_icm42600_buffer_fifo_read(struct inv_icm42600_state *st,
91 unsigned int max);
92
93int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st);
94
95int 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
24static 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
37const 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};
44EXPORT_SYMBOL_GPL(inv_icm42600_regmap_config);
45
46struct 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 */
53static 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
69static 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
92const struct iio_mount_matrix *
93inv_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
101uint32_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
137static 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
202int 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
246int 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
292int 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
300int 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
318static 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 */
367static 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
416static 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
426static 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
455out_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 */
469static 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
514static 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
528static 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
539static 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
550static 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
558int 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}
663EXPORT_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 */
669static 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
700out_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 */
709static 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
736out_unlock:
737 mutex_unlock(&st->lock);
738 return ret;
739}
740
741/* Runtime suspend will turn off sensors that are enabled by iio devices. */
742static 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
758error_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. */
764static 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
777const 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};
782EXPORT_SYMBOL_GPL(inv_icm42600_pm_ops);
783
784MODULE_AUTHOR("InvenSense, Inc.");
785MODULE_DESCRIPTION("InvenSense ICM-426xx device driver");
786MODULE_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
49enum 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
57static 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
62static 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 */
77struct 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
90static 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 */
97static 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
136out_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
148static 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;
193exit:
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 */
201static 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
228static 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
240static 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 */
271static 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
290static 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
301static 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
322static 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
356out_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 */
368static 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
374static 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
450static 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
545out_unlock:
546 mutex_unlock(&st->lock);
547 pm_runtime_mark_last_busy(dev);
548 pm_runtime_put_autosuspend(dev);
549 return ret;
550}
551
552static 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
591static 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
619static 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
651static 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
670static 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
686static 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
706static 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
717struct 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
759int 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
16static 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
49static 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
71static 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};
87MODULE_DEVICE_TABLE(of, inv_icm42600_of_matches);
88
89static 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};
97module_i2c_driver(inv_icm42600_driver);
98
99MODULE_AUTHOR("InvenSense, Inc.");
100MODULE_DESCRIPTION("InvenSense ICM-426xx I2C driver");
101MODULE_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
16static 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
51static 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
70static 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};
86MODULE_DEVICE_TABLE(of, inv_icm42600_of_matches);
87
88static 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};
96module_spi_driver(inv_icm42600_driver);
97
98MODULE_AUTHOR("InvenSense, Inc.");
99MODULE_DESCRIPTION("InvenSense ICM-426xx SPI driver");
100MODULE_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
16static 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
38exit:
39 mutex_unlock(&st->lock);
40 pm_runtime_mark_last_busy(dev);
41 pm_runtime_put_autosuspend(dev);
42
43 return ret;
44}
45
46int 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
26int 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 */
24static 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
43void 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
59int 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
70int 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
82static 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
96static 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
111void 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
166void 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
11struct inv_icm42600_state;
12
13/**
14 * struct inv_icm42600_timestamp_interval - timestamps interval
15 * @lo: interval lower bound
16 * @up: interval upper bound
17 */
18struct 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 */
29struct 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 */
44struct 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
53void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts,
54 uint32_t period);
55
56int inv_icm42600_timestamp_setup(struct inv_icm42600_state *st);
57
58int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts,
59 uint32_t period, bool fifo);
60
61void 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
65static inline int64_t
66inv_icm42600_timestamp_pop(struct inv_icm42600_timestamp *ts)
67{
68 ts->timestamp += ts->period;
69 return ts->timestamp;
70}
71
72void 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
76static inline void
77inv_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
101 unsigned short *primary_addr,101 unsigned short *primary_addr,
102 unsigned short *secondary_addr)102 unsigned short *secondary_addr)
103{103{
104 struct acpi_device *adev = ACPI_COMPANION(&client->dev);
104 const struct acpi_device_id *id;105 const struct acpi_device_id *id;
105 struct acpi_device *adev;
106 u32 i2c_addr = 0;106 u32 i2c_addr = 0;
107 LIST_HEAD(resources);107 LIST_HEAD(resources);
108 int ret;108 int ret;
@@ -112,10 +112,6 @@ static int inv_mpu_process_acpi_config(struct i2c_client *client, · 3 unmodified lines
112 if (!id)112 if (!id)
113 return -ENODEV;113 return -ENODEV;
114 114
115 adev = ACPI_COMPANION(&client->dev);
116 if (!adev)
117 return -ENODEV;
118
119 ret = acpi_dev_get_resources(adev, &resources,115 ret = acpi_dev_get_resources(adev, &resources,
120 acpi_i2c_check_resource, &i2c_addr);116 acpi_i2c_check_resource, &i2c_addr);
121 if (ret < 0)117 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
1530 }1530 }
1531 1531
1532 dev_set_drvdata(dev, indio_dev);1532 dev_set_drvdata(dev, indio_dev);
1533 indio_dev->dev.parent = dev;
1534 /* name will be NULL when enumerated via ACPI */1533 /* name will be NULL when enumerated via ACPI */
1535 if (name)1534 if (name)
1536 indio_dev->name = name;1535 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
1248 1248
1249 kmx61_set_data(indio_dev, data);1249 kmx61_set_data(indio_dev, data);
1250 1250
1251 indio_dev->dev.parent = &data->client->dev;
1252 indio_dev->channels = chan;1251 indio_dev->channels = chan;
1253 indio_dev->num_channels = num_channels;1252 indio_dev->num_channels = num_channels;
1254 indio_dev->name = name;1253 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
2152 return NULL;2152 return NULL;
2153 2153
2154 iio_dev->modes = INDIO_DIRECT_MODE;2154 iio_dev->modes = INDIO_DIRECT_MODE;
2155 iio_dev->dev.parent = hw->dev;
2156 iio_dev->available_scan_masks = st_lsm6dsx_available_scan_masks;2155 iio_dev->available_scan_masks = st_lsm6dsx_available_scan_masks;
2157 iio_dev->channels = hw->settings->channels[id].chan;2156 iio_dev->channels = hw->settings->channels[id].chan;
2158 iio_dev->num_channels = hw->settings->channels[id].len;2157 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
735 return NULL;735 return NULL;
736 736
737 iio_dev->modes = INDIO_DIRECT_MODE;737 iio_dev->modes = INDIO_DIRECT_MODE;
738 iio_dev->dev.parent = hw->dev;
739 iio_dev->info = &st_lsm6dsx_ext_info;738 iio_dev->info = &st_lsm6dsx_ext_info;
740 739
741 sensor = iio_priv(iio_dev);740 sensor = iio_priv(iio_dev);
drivers/iio/industrialio-buffer.c+43−15
@@ -19,7 +19,9 @@ · 18 unmodified lines
19#include <linux/sched/signal.h>19#include <linux/sched/signal.h>
20 20
21#include <linux/iio/iio.h>21#include <linux/iio/iio.h>
22#include <linux/iio/iio-opaque.h>
22#include "iio_core.h"23#include "iio_core.h"
24#include "iio_core_trigger.h"
23#include <linux/iio/sysfs.h>25#include <linux/iio/sysfs.h>
24#include <linux/iio/buffer.h>26#include <linux/iio/buffer.h>
25#include <linux/iio/buffer_impl.h>27#include <linux/iio/buffer_impl.h>
@@ -598,8 +600,10 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev, · 572 unmodified lines
598static void iio_buffer_activate(struct iio_dev *indio_dev,600static void iio_buffer_activate(struct iio_dev *indio_dev,
599 struct iio_buffer *buffer)601 struct iio_buffer *buffer)
600{602{
603 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
604
601 iio_buffer_get(buffer);605 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);
603}607}
604 608
605static void iio_buffer_deactivate(struct iio_buffer *buffer)609static void iio_buffer_deactivate(struct iio_buffer *buffer)
@@ -611,10 +615,11 @@ static void iio_buffer_deactivate(struct iio_buffer *buffer) · 5 unmodified lines
611 615
612static void iio_buffer_deactivate_all(struct iio_dev *indio_dev)616static void iio_buffer_deactivate_all(struct iio_dev *indio_dev)
613{617{
618 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
614 struct iio_buffer *buffer, *_buffer;619 struct iio_buffer *buffer, *_buffer;
615 620
616 list_for_each_entry_safe(buffer, _buffer,621 list_for_each_entry_safe(buffer, _buffer,
617 &indio_dev->buffer_list, buffer_list)622 &iio_dev_opaque->buffer_list, buffer_list)
618 iio_buffer_deactivate(buffer);623 iio_buffer_deactivate(buffer);
619}624}
620 625
@@ -687,6 +692,7 @@ static int iio_verify_update(struct iio_dev *indio_dev, · 66 unmodified lines
687 struct iio_buffer *insert_buffer, struct iio_buffer *remove_buffer,692 struct iio_buffer *insert_buffer, struct iio_buffer *remove_buffer,
688 struct iio_device_config *config)693 struct iio_device_config *config)
689{694{
695 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
690 unsigned long *compound_mask;696 unsigned long *compound_mask;
691 const unsigned long *scan_mask;697 const unsigned long *scan_mask;
692 bool strict_scanmask = false;698 bool strict_scanmask = false;
@@ -709,12 +715,12 @@ static int iio_verify_update(struct iio_dev *indio_dev, · 16 unmodified lines
709 * to verify.715 * to verify.
710 */716 */
711 if (remove_buffer && !insert_buffer &&717 if (remove_buffer && !insert_buffer &&
712 list_is_singular(&indio_dev->buffer_list))718 list_is_singular(&iio_dev_opaque->buffer_list))
713 return 0;719 return 0;
714 720
715 modes = indio_dev->modes;721 modes = indio_dev->modes;
716 722
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) {
718 if (buffer == remove_buffer)724 if (buffer == remove_buffer)
719 continue;725 continue;
720 modes &= buffer->access->modes;726 modes &= buffer->access->modes;
@@ -735,7 +741,7 @@ static int iio_verify_update(struct iio_dev *indio_dev, · 14 unmodified lines
735 * Keep things simple for now and only allow a single buffer to741 * Keep things simple for now and only allow a single buffer to
736 * be connected in hardware mode.742 * be connected in hardware mode.
737 */743 */
738 if (insert_buffer && !list_empty(&indio_dev->buffer_list))744 if (insert_buffer && !list_empty(&iio_dev_opaque->buffer_list))
739 return -EINVAL;745 return -EINVAL;
740 config->mode = INDIO_BUFFER_HARDWARE;746 config->mode = INDIO_BUFFER_HARDWARE;
741 strict_scanmask = true;747 strict_scanmask = true;
@@ -755,7 +761,7 @@ static int iio_verify_update(struct iio_dev *indio_dev, · 13 unmodified lines
755 761
756 scan_timestamp = false;762 scan_timestamp = false;
757 763
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) {
759 if (buffer == remove_buffer)765 if (buffer == remove_buffer)
760 continue;766 continue;
761 bitmap_or(compound_mask, compound_mask, buffer->scan_mask,767 bitmap_or(compound_mask, compound_mask, buffer->scan_mask,
@@ -901,10 +907,11 @@ error_clear_mux_table: · 139 unmodified lines
901 907
902static int iio_update_demux(struct iio_dev *indio_dev)908static int iio_update_demux(struct iio_dev *indio_dev)
903{909{
910 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
904 struct iio_buffer *buffer;911 struct iio_buffer *buffer;
905 int ret;912 int ret;
906 913
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) {
908 ret = iio_buffer_update_demux(indio_dev, buffer);915 ret = iio_buffer_update_demux(indio_dev, buffer);
909 if (ret < 0)916 if (ret < 0)
910 goto error_clear_mux_table;917 goto error_clear_mux_table;
@@ -912,7 +919,7 @@ static int iio_update_demux(struct iio_dev *indio_dev) · 1 unmodified line
912 return 0;919 return 0;
913 920
914error_clear_mux_table:921error_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)
916 iio_buffer_demux_free(buffer);923 iio_buffer_demux_free(buffer);
917 924
918 return ret;925 return ret;
@@ -921,6 +928,7 @@ error_clear_mux_table: · 2 unmodified lines
921static int iio_enable_buffers(struct iio_dev *indio_dev,928static int iio_enable_buffers(struct iio_dev *indio_dev,
922 struct iio_device_config *config)929 struct iio_device_config *config)
923{930{
931 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
924 struct iio_buffer *buffer;932 struct iio_buffer *buffer;
925 int ret;933 int ret;
926 934
@@ -957,25 +965,37 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, · 30 unmodified lines
957 indio_dev->info->hwfifo_set_watermark(indio_dev,965 indio_dev->info->hwfifo_set_watermark(indio_dev,
958 config->watermark);966 config->watermark);
959 967
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) {
961 ret = iio_buffer_enable(buffer, indio_dev);969 ret = iio_buffer_enable(buffer, indio_dev);
962 if (ret)970 if (ret)
963 goto err_disable_buffers;971 goto err_disable_buffers;
964 }972 }
965 973
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
966 if (indio_dev->setup_ops->postenable) {981 if (indio_dev->setup_ops->postenable) {
967 ret = indio_dev->setup_ops->postenable(indio_dev);982 ret = indio_dev->setup_ops->postenable(indio_dev);
968 if (ret) {983 if (ret) {
969 dev_dbg(&indio_dev->dev,984 dev_dbg(&indio_dev->dev,
970 "Buffer not started: postenable failed (%d)\n", ret);985 "Buffer not started: postenable failed (%d)\n", ret);
971 goto err_disable_buffers;986 goto err_detach_pollfunc;
972 }987 }
973 }988 }
974 989
975 return 0;990 return 0;
976 991
992err_detach_pollfunc:
993 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
994 iio_trigger_detach_poll_func(indio_dev->trig,
995 indio_dev->pollfunc);
996 }
977err_disable_buffers:997err_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,
979 buffer_list)999 buffer_list)
980 iio_buffer_disable(buffer, indio_dev);1000 iio_buffer_disable(buffer, indio_dev);
981err_run_postdisable:1001err_run_postdisable:
@@ -990,12 +1010,13 @@ err_undo_config: · 8 unmodified lines
990 1010
991static int iio_disable_buffers(struct iio_dev *indio_dev)1011static int iio_disable_buffers(struct iio_dev *indio_dev)
992{1012{
1013 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
993 struct iio_buffer *buffer;1014 struct iio_buffer *buffer;
994 int ret = 0;1015 int ret = 0;
995 int ret2;1016 int ret2;
996 1017
997 /* Wind down existing buffers - iff there are any */1018 /* 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))
999 return 0;1020 return 0;
1000 1021
1001 /*1022 /*
@@ -1011,7 +1032,12 @@ static int iio_disable_buffers(struct iio_dev *indio_dev) · 9 unmodified lines
1011 ret = ret2;1032 ret = ret2;
1012 }1033 }
1013 1034
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) {
1015 ret2 = iio_buffer_disable(buffer, indio_dev);1041 ret2 = iio_buffer_disable(buffer, indio_dev);
1016 if (ret2 && !ret)1042 if (ret2 && !ret)
1017 ret = ret2;1043 ret = ret2;
@@ -1034,6 +1060,7 @@ static int __iio_update_buffers(struct iio_dev *indio_dev, · 16 unmodified lines
1034 struct iio_buffer *insert_buffer,1060 struct iio_buffer *insert_buffer,
1035 struct iio_buffer *remove_buffer)1061 struct iio_buffer *remove_buffer)
1036{1062{
1063 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
1037 struct iio_device_config new_config;1064 struct iio_device_config new_config;
1038 int ret;1065 int ret;
1039 1066
@@ -1058,7 +1085,7 @@ static int __iio_update_buffers(struct iio_dev *indio_dev, · 18 unmodified lines
1058 iio_buffer_activate(indio_dev, insert_buffer);1085 iio_buffer_activate(indio_dev, insert_buffer);
1059 1086
1060 /* If no buffers in list, we are done */1087 /* 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))
1062 return 0;1089 return 0;
1063 1090
1064 ret = iio_enable_buffers(indio_dev, &new_config);1091 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
1407 */1434 */
1408int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data)1435int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data)
1409{1436{
1437 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
1410 int ret;1438 int ret;
1411 struct iio_buffer *buf;1439 struct iio_buffer *buf;
1412 1440
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) {
1414 ret = iio_push_to_buffer(buf, data);1442 ret = iio_push_to_buffer(buf, data);
1415 if (ret < 0)1443 if (ret < 0)
1416 return ret;1444 return ret;
drivers/iio/industrialio-core.c+81−48
@@ -25,6 +25,7 @@ · 24 unmodified lines
25#include <linux/debugfs.h>25#include <linux/debugfs.h>
26#include <linux/mutex.h>26#include <linux/mutex.h>
27#include <linux/iio/iio.h>27#include <linux/iio/iio.h>
28#include <linux/iio/iio-opaque.h>
28#include "iio_core.h"29#include "iio_core.h"
29#include "iio_core_trigger.h"30#include "iio_core_trigger.h"
30#include <linux/iio/sysfs.h>31#include <linux/iio/sysfs.h>
@@ -164,6 +165,19 @@ static const char * const iio_chan_info_postfix[] = { · 133 unmodified lines
164 [IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type",165 [IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type",
165};166};
166 167
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 */
173struct 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}
178EXPORT_SYMBOL_GPL(iio_get_debugfs_dentry);
179#endif
180
167/**181/**
168 * iio_find_channel_from_si() - get channel from its scan index182 * iio_find_channel_from_si() - get channel from its scan index
169 * @indio_dev: device183 * @indio_dev: device
@@ -197,7 +211,8 @@ EXPORT_SYMBOL(iio_read_const_attr); · 27 unmodified lines
197int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)211int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)
198{212{
199 int ret;213 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;
201 216
202 ret = mutex_lock_interruptible(&indio_dev->mlock);217 ret = mutex_lock_interruptible(&indio_dev->mlock);
203 if (ret)218 if (ret)
@@ -307,35 +322,37 @@ static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf, · 103 unmodified lines
307 size_t count, loff_t *ppos)322 size_t count, loff_t *ppos)
308{323{
309 struct iio_dev *indio_dev = file->private_data;324 struct iio_dev *indio_dev = file->private_data;
325 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
310 unsigned val = 0;326 unsigned val = 0;
311 int ret;327 int ret;
312 328
313 if (*ppos > 0)329 if (*ppos > 0)
314 return simple_read_from_buffer(userbuf, count, ppos,330 return simple_read_from_buffer(userbuf, count, ppos,
315 indio_dev->read_buf,331 iio_dev_opaque->read_buf,
316 indio_dev->read_buf_len);332 iio_dev_opaque->read_buf_len);
317 333
318 ret = indio_dev->info->debugfs_reg_access(indio_dev,334 ret = indio_dev->info->debugfs_reg_access(indio_dev,
319 indio_dev->cached_reg_addr,335 iio_dev_opaque->cached_reg_addr,
320 0, &val);336 0, &val);
321 if (ret) {337 if (ret) {
322 dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__);338 dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__);
323 return ret;339 return ret;
324 }340 }
325 341
326 indio_dev->read_buf_len = snprintf(indio_dev->read_buf,342 iio_dev_opaque->read_buf_len = snprintf(iio_dev_opaque->read_buf,
327 sizeof(indio_dev->read_buf),343 sizeof(iio_dev_opaque->read_buf),
328 "0x%X\n", val);344 "0x%X\n", val);
329 345
330 return simple_read_from_buffer(userbuf, count, ppos,346 return simple_read_from_buffer(userbuf, count, ppos,
331 indio_dev->read_buf,347 iio_dev_opaque->read_buf,
332 indio_dev->read_buf_len);348 iio_dev_opaque->read_buf_len);
333}349}
334 350
335static ssize_t iio_debugfs_write_reg(struct file *file,351static ssize_t iio_debugfs_write_reg(struct file *file,
336 const char __user *userbuf, size_t count, loff_t *ppos)352 const char __user *userbuf, size_t count, loff_t *ppos)
337{353{
338 struct iio_dev *indio_dev = file->private_data;354 struct iio_dev *indio_dev = file->private_data;
355 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
339 unsigned reg, val;356 unsigned reg, val;
340 char buf[80];357 char buf[80];
341 int ret;358 int ret;
@@ -350,10 +367,10 @@ static ssize_t iio_debugfs_write_reg(struct file *file, · 8 unmodified lines
350 367
351 switch (ret) {368 switch (ret) {
352 case 1:369 case 1:
353 indio_dev->cached_reg_addr = reg;370 iio_dev_opaque->cached_reg_addr = reg;
354 break;371 break;
355 case 2:372 case 2:
356 indio_dev->cached_reg_addr = reg;373 iio_dev_opaque->cached_reg_addr = reg;
357 ret = indio_dev->info->debugfs_reg_access(indio_dev, reg,374 ret = indio_dev->info->debugfs_reg_access(indio_dev, reg,
358 val, NULL);375 val, NULL);
359 if (ret) {376 if (ret) {
@@ -377,23 +394,28 @@ static const struct file_operations iio_debugfs_reg_fops = { · 17 unmodified lines
377 394
378static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)395static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
379{396{
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);
381}399}
382 400
383static void iio_device_register_debugfs(struct iio_dev *indio_dev)401static void iio_device_register_debugfs(struct iio_dev *indio_dev)
384{402{
403 struct iio_dev_opaque *iio_dev_opaque;
404
385 if (indio_dev->info->debugfs_reg_access == NULL)405 if (indio_dev->info->debugfs_reg_access == NULL)
386 return;406 return;
387 407
388 if (!iio_debugfs_dentry)408 if (!iio_debugfs_dentry)
389 return;409 return;
390 410
391 indio_dev->debugfs_dentry =411 iio_dev_opaque = to_iio_dev_opaque(indio_dev);
412
413 iio_dev_opaque->debugfs_dentry =
392 debugfs_create_dir(dev_name(&indio_dev->dev),414 debugfs_create_dir(dev_name(&indio_dev->dev),
393 iio_debugfs_dentry);415 iio_debugfs_dentry);
394 416
395 debugfs_create_file("direct_reg_access", 0644,417 debugfs_create_file("direct_reg_access", 0644,
396 indio_dev->debugfs_dentry, indio_dev,418 iio_dev_opaque->debugfs_dentry, indio_dev,
397 &iio_debugfs_reg_fops);419 &iio_debugfs_reg_fops);
398}420}
399#else421#else
@@ -1116,6 +1138,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev, · 716 unmodified lines
1116 enum iio_shared_by shared_by,1138 enum iio_shared_by shared_by,
1117 const long *infomask)1139 const long *infomask)
1118{1140{
1141 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
1119 int i, ret, attrcount = 0;1142 int i, ret, attrcount = 0;
1120 1143
1121 for_each_set_bit(i, infomask, sizeof(*infomask)*8) {1144 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
1128 i,1151 i,
1129 shared_by,1152 shared_by,
1130 &indio_dev->dev,1153 &indio_dev->dev,
1131 &indio_dev->channel_attr_list);1154 &iio_dev_opaque->channel_attr_list);
1132 if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))1155 if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
1133 continue;1156 continue;
1134 else if (ret < 0)1157 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
1144 enum iio_shared_by shared_by,1167 enum iio_shared_by shared_by,
1145 const long *infomask)1168 const long *infomask)
1146{1169{
1170 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
1147 int i, ret, attrcount = 0;1171 int i, ret, attrcount = 0;
1148 char *avail_postfix;1172 char *avail_postfix;
1149 1173
@@ -1163,7 +1187,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev, · 13 unmodified lines
1163 i,1187 i,
1164 shared_by,1188 shared_by,
1165 &indio_dev->dev,1189 &indio_dev->dev,
1166 &indio_dev->channel_attr_list);1190 &iio_dev_opaque->channel_attr_list);
1167 kfree(avail_postfix);1191 kfree(avail_postfix);
1168 if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))1192 if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
1169 continue;1193 continue;
@@ -1178,6 +1202,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev, · 8 unmodified lines
1178static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,1202static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
1179 struct iio_chan_spec const *chan)1203 struct iio_chan_spec const *chan)
1180{1204{
1205 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
1181 int ret, attrcount = 0;1206 int ret, attrcount = 0;
1182 const struct iio_chan_spec_ext_info *ext_info;1207 const struct iio_chan_spec_ext_info *ext_info;
1183 1208
@@ -1253,7 +1278,7 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev, · 69 unmodified lines
1253 i,1278 i,
1254 ext_info->shared,1279 ext_info->shared,
1255 &indio_dev->dev,1280 &indio_dev->dev,
1256 &indio_dev->channel_attr_list);1281 &iio_dev_opaque->channel_attr_list);
1257 i++;1282 i++;
1258 if (ret == -EBUSY && ext_info->shared)1283 if (ret == -EBUSY && ext_info->shared)
1259 continue;1284 continue;
@@ -1388,6 +1413,7 @@ static DEVICE_ATTR(current_timestamp_clock, S_IRUGO | S_IWUSR, · 128 unmodified lines
1388 1413
1389static int iio_device_register_sysfs(struct iio_dev *indio_dev)1414static int iio_device_register_sysfs(struct iio_dev *indio_dev)
1390{1415{
1416 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
1391 int i, ret = 0, attrcount, attrn, attrcount_orig = 0;1417 int i, ret = 0, attrcount, attrn, attrcount_orig = 0;
1392 struct iio_dev_attr *p;1418 struct iio_dev_attr *p;
1393 struct attribute **attr, *clk = NULL;1419 struct attribute **attr, *clk = NULL;
@@ -1417,7 +1443,7 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev) · 23 unmodified lines
1417 attrcount += ret;1443 attrcount += ret;
1418 }1444 }
1419 1445
1420 if (indio_dev->event_interface)1446 if (iio_dev_opaque->event_interface)
1421 clk = &dev_attr_current_timestamp_clock.attr;1447 clk = &dev_attr_current_timestamp_clock.attr;
1422 1448
1423 if (indio_dev->name)1449 if (indio_dev->name)
@@ -1427,52 +1453,56 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev) · 3 unmodified lines
1427 if (clk)1453 if (clk)
1428 attrcount++;1454 attrcount++;
1429 1455
1430 indio_dev->chan_attr_group.attrs = kcalloc(attrcount + 1,1456 iio_dev_opaque->chan_attr_group.attrs =
1431 sizeof(indio_dev->chan_attr_group.attrs[0]),1457 kcalloc(attrcount + 1,
1432 GFP_KERNEL);1458 sizeof(iio_dev_opaque->chan_attr_group.attrs[0]),
1433 if (indio_dev->chan_attr_group.attrs == NULL) {1459 GFP_KERNEL);
1460 if (iio_dev_opaque->chan_attr_group.attrs == NULL) {
1434 ret = -ENOMEM;1461 ret = -ENOMEM;
1435 goto error_clear_attrs;1462 goto error_clear_attrs;
1436 }1463 }
1437 /* Copy across original attributes */1464 /* Copy across original attributes */
1438 if (indio_dev->info->attrs)1465 if (indio_dev->info->attrs)
1439 memcpy(indio_dev->chan_attr_group.attrs,1466 memcpy(iio_dev_opaque->chan_attr_group.attrs,
1440 indio_dev->info->attrs->attrs,1467 indio_dev->info->attrs->attrs,
1441 sizeof(indio_dev->chan_attr_group.attrs[0])1468 sizeof(iio_dev_opaque->chan_attr_group.attrs[0])
1442 *attrcount_orig);1469 *attrcount_orig);
1443 attrn = attrcount_orig;1470 attrn = attrcount_orig;
1444 /* Add all elements from the list. */1471 /* Add all elements from the list. */
1445 list_for_each_entry(p, &indio_dev->channel_attr_list, l)1472 list_for_each_entry(p, &iio_dev_opaque->channel_attr_list, l)
1446 indio_dev->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr;1473 iio_dev_opaque->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr;
1447 if (indio_dev->name)1474 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;
1449 if (indio_dev->label)1476 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;
1451 if (clk)1478 if (clk)
1452 indio_dev->chan_attr_group.attrs[attrn++] = clk;1479 iio_dev_opaque->chan_attr_group.attrs[attrn++] = clk;
1453 1480
1454 indio_dev->groups[indio_dev->groupcounter++] =1481 indio_dev->groups[indio_dev->groupcounter++] =
1455 &indio_dev->chan_attr_group;1482 &iio_dev_opaque->chan_attr_group;
1456 1483
1457 return 0;1484 return 0;
1458 1485
1459error_clear_attrs:1486error_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);
1461 1488
1462 return ret;1489 return ret;
1463}1490}
1464 1491
1465static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)1492static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
1466{1493{
1494 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
1467 1495
1468 iio_free_chan_devattr_list(&indio_dev->channel_attr_list);1496 iio_free_chan_devattr_list(&iio_dev_opaque->channel_attr_list);
1469 kfree(indio_dev->chan_attr_group.attrs);1497 kfree(iio_dev_opaque->chan_attr_group.attrs);
1470 indio_dev->chan_attr_group.attrs = NULL;1498 iio_dev_opaque->chan_attr_group.attrs = NULL;
1471}1499}
1472 1500
1473static void iio_dev_release(struct device *device)1501static void iio_dev_release(struct device *device)
1474{1502{
1475 struct iio_dev *indio_dev = dev_to_iio_dev(device);1503 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
1476 if (indio_dev->modes & INDIO_ALL_TRIGGERED_MODES)1506 if (indio_dev->modes & INDIO_ALL_TRIGGERED_MODES)
1477 iio_device_unregister_trigger_consumer(indio_dev);1507 iio_device_unregister_trigger_consumer(indio_dev);
1478 iio_device_unregister_eventset(indio_dev);1508 iio_device_unregister_eventset(indio_dev);
@@ -1481,7 +1511,7 @@ static void iio_dev_release(struct device *device) · 2 unmodified lines
1481 iio_buffer_put(indio_dev->buffer);1511 iio_buffer_put(indio_dev->buffer);
1482 1512
1483 ida_simple_remove(&iio_ida, indio_dev->id);1513 ida_simple_remove(&iio_ida, indio_dev->id);
1484 kfree(indio_dev);1514 kfree(iio_dev_opaque);
1485}1515}
1486 1516
1487struct device_type iio_device_type = {1517struct device_type iio_device_type = {
@@ -1493,23 +1523,26 @@ struct device_type iio_device_type = { · 5 unmodified lines
1493 * iio_device_alloc() - allocate an iio_dev from a driver1523 * iio_device_alloc() - allocate an iio_dev from a driver
1494 * @sizeof_priv: Space to allocate for private structure.1524 * @sizeof_priv: Space to allocate for private structure.
1495 **/1525 **/
1496struct iio_dev *iio_device_alloc(int sizeof_priv)1526struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
1497{1527{
1528 struct iio_dev_opaque *iio_dev_opaque;
1498 struct iio_dev *dev;1529 struct iio_dev *dev;
1499 size_t alloc_size;1530 size_t alloc_size;
1500 1531
1501 alloc_size = sizeof(struct iio_dev);1532 alloc_size = sizeof(struct iio_dev_opaque);
1502 if (sizeof_priv) {1533 if (sizeof_priv) {
1503 alloc_size = ALIGN(alloc_size, IIO_ALIGN);1534 alloc_size = ALIGN(alloc_size, IIO_ALIGN);
1504 alloc_size += sizeof_priv;1535 alloc_size += sizeof_priv;
1505 }1536 }
1506 /* ensure 32-byte alignment of whole construct ? */
1507 alloc_size += IIO_ALIGN - 1;
1508 1537
1509 dev = kzalloc(alloc_size, GFP_KERNEL);1538 iio_dev_opaque = kzalloc(alloc_size, GFP_KERNEL);
1510 if (!dev)1539 if (!iio_dev_opaque)
1511 return NULL;1540 return NULL;
1512 1541
1542 dev = &iio_dev_opaque->indio_dev;
1543 dev->priv = (char *)iio_dev_opaque +
1544 ALIGN(sizeof(struct iio_dev_opaque), IIO_ALIGN);
1545
1513 dev->dev.groups = dev->groups;1546 dev->dev.groups = dev->groups;
1514 dev->dev.type = &iio_device_type;1547 dev->dev.type = &iio_device_type;
1515 dev->dev.bus = &iio_bus_type;1548 dev->dev.bus = &iio_bus_type;
@@ -1517,17 +1550,17 @@ struct iio_dev *iio_device_alloc(int sizeof_priv) · 1 unmodified line
1517 dev_set_drvdata(&dev->dev, (void *)dev);1550 dev_set_drvdata(&dev->dev, (void *)dev);
1518 mutex_init(&dev->mlock);1551 mutex_init(&dev->mlock);
1519 mutex_init(&dev->info_exist_lock);1552 mutex_init(&dev->info_exist_lock);
1520 INIT_LIST_HEAD(&dev->channel_attr_list);1553 INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
1521 1554
1522 dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);1555 dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
1523 if (dev->id < 0) {1556 if (dev->id < 0) {
1524 /* cannot use a dev_err as the name isn't available */1557 /* cannot use a dev_err as the name isn't available */
1525 pr_err("failed to get device id\n");1558 pr_err("failed to get device id\n");
1526 kfree(dev);1559 kfree(iio_dev_opaque);
1527 return NULL;1560 return NULL;
1528 }1561 }
1529 dev_set_name(&dev->dev, "iio:device%d", dev->id);1562 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);
1531 1564
1532 return dev;1565 return dev;
1533}1566}
@@ -1551,7 +1584,7 @@ static void devm_iio_device_release(struct device *dev, void *res) · 17 unmodified lines
1551 1584
1552/**1585/**
1553 * devm_iio_device_alloc - Resource-managed iio_device_alloc()1586 * devm_iio_device_alloc - Resource-managed iio_device_alloc()
1554 * @dev: Device to allocate iio_dev for1587 * @parent: Device to allocate iio_dev for, and parent for this IIO device
1555 * @sizeof_priv: Space to allocate for private structure.1588 * @sizeof_priv: Space to allocate for private structure.
1556 *1589 *
1557 * Managed iio_device_alloc. iio_dev allocated with this function is1590 * 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
1560 * RETURNS:1593 * RETURNS:
1561 * Pointer to allocated iio_dev on success, NULL on failure.1594 * Pointer to allocated iio_dev on success, NULL on failure.
1562 */1595 */
1563struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv)1596struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv)
1564{1597{
1565 struct iio_dev **ptr, *iio_dev;1598 struct iio_dev **ptr, *iio_dev;
1566 1599
@@ -1569,10 +1602,10 @@ struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv) · 2 unmodified lines
1569 if (!ptr)1602 if (!ptr)
1570 return NULL;1603 return NULL;
1571 1604
1572 iio_dev = iio_device_alloc(sizeof_priv);1605 iio_dev = iio_device_alloc(parent, sizeof_priv);
1573 if (iio_dev) {1606 if (iio_dev) {
1574 *ptr = iio_dev;1607 *ptr = iio_dev;
1575 devres_add(dev, ptr);1608 devres_add(parent, ptr);
1576 } else {1609 } else {
1577 devres_free(ptr);1610 devres_free(ptr);
1578 }1611 }
drivers/iio/industrialio-event.c+40−28
@@ -18,6 +18,7 @@ · 17 unmodified lines
18#include <linux/uaccess.h>18#include <linux/uaccess.h>
19#include <linux/wait.h>19#include <linux/wait.h>
20#include <linux/iio/iio.h>20#include <linux/iio/iio.h>
21#include <linux/iio/iio-opaque.h>
21#include "iio_core.h"22#include "iio_core.h"
22#include <linux/iio/sysfs.h>23#include <linux/iio/sysfs.h>
23#include <linux/iio/events.h>24#include <linux/iio/events.h>
@@ -62,7 +63,8 @@ bool iio_event_enabled(const struct iio_event_interface *ev_int) · 38 unmodified lines
62 **/63 **/
63int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)64int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
64{65{
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;
66 struct iio_event_data ev;68 struct iio_event_data ev;
67 int copied;69 int copied;
68 70
@@ -96,7 +98,8 @@ static __poll_t iio_event_poll(struct file *filep, · 27 unmodified lines
96 struct poll_table_struct *wait)98 struct poll_table_struct *wait)
97{99{
98 struct iio_dev *indio_dev = filep->private_data;100 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;
100 __poll_t events = 0;103 __poll_t events = 0;
101 104
102 if (!indio_dev->info)105 if (!indio_dev->info)
@@ -116,7 +119,8 @@ static ssize_t iio_event_chrdev_read(struct file *filep, · 13 unmodified lines
116 loff_t *f_ps)119 loff_t *f_ps)
117{120{
118 struct iio_dev *indio_dev = filep->private_data;121 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;
120 unsigned int copied;124 unsigned int copied;
121 int ret;125 int ret;
122 126
@@ -165,7 +169,8 @@ static ssize_t iio_event_chrdev_read(struct file *filep, · 42 unmodified lines
165static int iio_event_chrdev_release(struct inode *inode, struct file *filep)169static int iio_event_chrdev_release(struct inode *inode, struct file *filep)
166{170{
167 struct iio_dev *indio_dev = filep->private_data;171 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;
169 174
170 clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags);175 clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
171 176
@@ -184,7 +189,8 @@ static const struct file_operations iio_event_chrdev_fileops = { · 12 unmodified lines
184 189
185int iio_event_getfd(struct iio_dev *indio_dev)190int iio_event_getfd(struct iio_dev *indio_dev)
186{191{
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;
188 int fd;194 int fd;
189 195
190 if (ev_int == NULL)196 if (ev_int == NULL)
@@ -343,6 +349,7 @@ static int iio_device_add_event(struct iio_dev *indio_dev, · 152 unmodified lines
343 enum iio_event_type type, enum iio_event_direction dir,349 enum iio_event_type type, enum iio_event_direction dir,
344 enum iio_shared_by shared_by, const unsigned long *mask)350 enum iio_shared_by shared_by, const unsigned long *mask)
345{351{
352 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
346 ssize_t (*show)(struct device *, struct device_attribute *, char *);353 ssize_t (*show)(struct device *, struct device_attribute *, char *);
347 ssize_t (*store)(struct device *, struct device_attribute *,354 ssize_t (*store)(struct device *, struct device_attribute *,
348 const char *, size_t);355 const char *, size_t);
@@ -376,7 +383,7 @@ static int iio_device_add_event(struct iio_dev *indio_dev, · 27 unmodified lines
376 383
377 ret = __iio_add_chan_devattr(postfix, chan, show, store,384 ret = __iio_add_chan_devattr(postfix, chan, show, store,
378 (i << 16) | spec_index, shared_by, &indio_dev->dev,385 (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);
380 kfree(postfix);387 kfree(postfix);
381 388
382 if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))389 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
469static const char *iio_event_group_name = "events";476static const char *iio_event_group_name = "events";
470int iio_device_register_eventset(struct iio_dev *indio_dev)477int iio_device_register_eventset(struct iio_dev *indio_dev)
471{478{
479 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
472 struct iio_dev_attr *p;480 struct iio_dev_attr *p;
473 int ret = 0, attrcount_orig = 0, attrcount, attrn;481 int ret = 0, attrcount_orig = 0, attrcount, attrn;
474 struct attribute **attr;482 struct attribute **attr;
@@ -477,14 +485,14 @@ int iio_device_register_eventset(struct iio_dev *indio_dev) · 2 unmodified lines
477 iio_check_for_dynamic_events(indio_dev)))485 iio_check_for_dynamic_events(indio_dev)))
478 return 0;486 return 0;
479 487
480 indio_dev->event_interface =488 iio_dev_opaque->event_interface =
481 kzalloc(sizeof(struct iio_event_interface), GFP_KERNEL);489 kzalloc(sizeof(struct iio_event_interface), GFP_KERNEL);
482 if (indio_dev->event_interface == NULL)490 if (iio_dev_opaque->event_interface == NULL)
483 return -ENOMEM;491 return -ENOMEM;
484 492
485 INIT_LIST_HEAD(&indio_dev->event_interface->dev_attr_list);493 INIT_LIST_HEAD(&iio_dev_opaque->event_interface->dev_attr_list);
486 494
487 iio_setup_ev_int(indio_dev->event_interface);495 iio_setup_ev_int(iio_dev_opaque->event_interface);
488 if (indio_dev->info->event_attrs != NULL) {496 if (indio_dev->info->event_attrs != NULL) {
489 attr = indio_dev->info->event_attrs->attrs;497 attr = indio_dev->info->event_attrs->attrs;
490 while (*attr++ != NULL)498 while (*attr++ != NULL)
@@ -498,35 +506,35 @@ int iio_device_register_eventset(struct iio_dev *indio_dev) · 7 unmodified lines
498 attrcount += ret;506 attrcount += ret;
499 }507 }
500 508
501 indio_dev->event_interface->group.name = iio_event_group_name;509 iio_dev_opaque->event_interface->group.name = iio_event_group_name;
502 indio_dev->event_interface->group.attrs = kcalloc(attrcount + 1,510 iio_dev_opaque->event_interface->group.attrs = kcalloc(attrcount + 1,
503 sizeof(indio_dev->event_interface->group.attrs[0]),511 sizeof(iio_dev_opaque->event_interface->group.attrs[0]),
504 GFP_KERNEL);512 GFP_KERNEL);
505 if (indio_dev->event_interface->group.attrs == NULL) {513 if (iio_dev_opaque->event_interface->group.attrs == NULL) {
506 ret = -ENOMEM;514 ret = -ENOMEM;
507 goto error_free_setup_event_lines;515 goto error_free_setup_event_lines;
508 }516 }
509 if (indio_dev->info->event_attrs)517 if (indio_dev->info->event_attrs)
510 memcpy(indio_dev->event_interface->group.attrs,518 memcpy(iio_dev_opaque->event_interface->group.attrs,
511 indio_dev->info->event_attrs->attrs,519 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])
513 *attrcount_orig);521 *attrcount_orig);
514 attrn = attrcount_orig;522 attrn = attrcount_orig;
515 /* Add all elements from the list. */523 /* Add all elements from the list. */
516 list_for_each_entry(p,524 list_for_each_entry(p,
517 &indio_dev->event_interface->dev_attr_list,525 &iio_dev_opaque->event_interface->dev_attr_list,
518 l)526 l)
519 indio_dev->event_interface->group.attrs[attrn++] =527 iio_dev_opaque->event_interface->group.attrs[attrn++] =
520 &p->dev_attr.attr;528 &p->dev_attr.attr;
521 indio_dev->groups[indio_dev->groupcounter++] =529 indio_dev->groups[indio_dev->groupcounter++] =
522 &indio_dev->event_interface->group;530 &iio_dev_opaque->event_interface->group;
523 531
524 return 0;532 return 0;
525 533
526error_free_setup_event_lines:534error_free_setup_event_lines:
527 iio_free_chan_devattr_list(&indio_dev->event_interface->dev_attr_list);535 iio_free_chan_devattr_list(&iio_dev_opaque->event_interface->dev_attr_list);
528 kfree(indio_dev->event_interface);536 kfree(iio_dev_opaque->event_interface);
529 indio_dev->event_interface = NULL;537 iio_dev_opaque->event_interface = NULL;
530 return ret;538 return ret;
531}539}
532 540
@@ -539,16 +547,20 @@ error_free_setup_event_lines: · 6 unmodified lines
539 */547 */
540void iio_device_wakeup_eventset(struct iio_dev *indio_dev)548void iio_device_wakeup_eventset(struct iio_dev *indio_dev)
541{549{
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)
543 return;553 return;
544 wake_up(&indio_dev->event_interface->wait);554 wake_up(&iio_dev_opaque->event_interface->wait);
545}555}
546 556
547void iio_device_unregister_eventset(struct iio_dev *indio_dev)557void iio_device_unregister_eventset(struct iio_dev *indio_dev)
548{558{
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)
550 return;562 return;
551 iio_free_chan_devattr_list(&indio_dev->event_interface->dev_attr_list);563 iio_free_chan_devattr_list(&iio_dev_opaque->event_interface->dev_attr_list);
552 kfree(indio_dev->event_interface->group.attrs);564 kfree(iio_dev_opaque->event_interface->group.attrs);
553 kfree(indio_dev->event_interface);565 kfree(iio_dev_opaque->event_interface);
554}566}
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
239 * the relevant function is in there may be the best option.239 * the relevant function is in there may be the best option.
240 */240 */
241/* Worth protecting against double additions? */241/* Worth protecting against double additions? */
242static int iio_trigger_attach_poll_func(struct iio_trigger *trig,242int iio_trigger_attach_poll_func(struct iio_trigger *trig,
243 struct iio_poll_func *pf)243 struct iio_poll_func *pf)
244{244{
245 int ret = 0;245 int ret = 0;
246 bool notinuse246 bool notinuse
@@ -290,8 +290,8 @@ out_put_module: · 43 unmodified lines
290 return ret;290 return ret;
291}291}
292 292
293static int iio_trigger_detach_poll_func(struct iio_trigger *trig,293int iio_trigger_detach_poll_func(struct iio_trigger *trig,
294 struct iio_poll_func *pf)294 struct iio_poll_func *pf)
295{295{
296 int ret = 0;296 int ret = 0;
297 bool no_other_users297 bool no_other_users
@@ -705,17 +705,3 @@ void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev) · 407 unmodified lines
705 if (indio_dev->trig)705 if (indio_dev->trig)
706 iio_trigger_put(indio_dev->trig);706 iio_trigger_put(indio_dev->trig);
707}707}
708
709int 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}
714EXPORT_SYMBOL(iio_triggered_buffer_postenable);
715
716int 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}
721EXPORT_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
178 mutex_init(&als->lock);178 mutex_init(&als->lock);
179 179
180 indio_dev->name = ACPI_ALS_DEVICE_NAME;180 indio_dev->name = ACPI_ALS_DEVICE_NAME;
181 indio_dev->dev.parent = &device->dev;
182 indio_dev->info = &acpi_als_info;181 indio_dev->info = &acpi_als_info;
183 indio_dev->modes = INDIO_BUFFER_SOFTWARE;182 indio_dev->modes = INDIO_BUFFER_SOFTWARE;
184 indio_dev->channels = acpi_als_channels;183 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
259 i2c_set_clientdata(client, indio_dev);259 i2c_set_clientdata(client, indio_dev);
260 data->client = client;260 data->client = client;
261 261
262 indio_dev->dev.parent = &client->dev;
263 indio_dev->info = &adjd_s311_info;262 indio_dev->info = &adjd_s311_info;
264 indio_dev->name = ADJD_S311_DRV_NAME;263 indio_dev->name = ADJD_S311_DRV_NAME;
265 indio_dev->channels = adjd_s311_channels;264 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
785 if (!indio_dev)785 if (!indio_dev)
786 return -ENOMEM;786 return -ENOMEM;
787 787
788 indio_dev->dev.parent = &client->dev;
789 indio_dev->info = &adux1020_info;788 indio_dev->info = &adux1020_info;
790 indio_dev->name = ADUX1020_DRV_NAME;789 indio_dev->name = ADUX1020_DRV_NAME;
791 indio_dev->channels = adux1020_channels;790 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
179 i2c_set_clientdata(client, indio_dev);179 i2c_set_clientdata(client, indio_dev);
180 data->client = client;180 data->client = client;
181 181
182 indio_dev->dev.parent = &client->dev;
183 indio_dev->info = &al3010_info;182 indio_dev->info = &al3010_info;
184 indio_dev->name = AL3010_DRV_NAME;183 indio_dev->name = AL3010_DRV_NAME;
185 indio_dev->channels = al3010_channels;184 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
202 i2c_set_clientdata(client, indio_dev);202 i2c_set_clientdata(client, indio_dev);
203 data->client = client;203 data->client = client;
204 204
205 indio_dev->dev.parent = &client->dev;
206 indio_dev->info = &al3320a_info;205 indio_dev->info = &al3320a_info;
207 indio_dev->name = AL3320A_DRV_NAME;206 indio_dev->name = AL3320A_DRV_NAME;
208 indio_dev->channels = al3320a_channels;207 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
419 419
420 mutex_init(&data->mutex);420 mutex_init(&data->mutex);
421 421
422 indio_dev->dev.parent = &client->dev;
423 indio_dev->channels = apds9300_channels;422 indio_dev->channels = apds9300_channels;
424 indio_dev->num_channels = ARRAY_SIZE(apds9300_channels);423 indio_dev->num_channels = ARRAY_SIZE(apds9300_channels);
425 indio_dev->name = APDS9300_DRV_NAME;424 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
1001 1001
1002 iio_device_attach_buffer(indio_dev, buffer);1002 iio_device_attach_buffer(indio_dev, buffer);
1003 1003
1004 indio_dev->dev.parent = &client->dev;
1005 indio_dev->info = &apds9960_info;1004 indio_dev->info = &apds9960_info;
1006 indio_dev->name = APDS9960_DRV_NAME;1005 indio_dev->name = APDS9960_DRV_NAME;
1007 indio_dev->channels = apds9960_channels;1006 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
254 return ret;254 return ret;
255 255
256 mutex_init(&data->lock);256 mutex_init(&data->lock);
257 indio_dev->dev.parent = &client->dev;
258 indio_dev->info = &bh1750_info;257 indio_dev->info = &bh1750_info;
259 indio_dev->name = id->name;258 indio_dev->name = id->name;
260 indio_dev->channels = bh1750_channels;259 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
185 pm_runtime_use_autosuspend(&client->dev);185 pm_runtime_use_autosuspend(&client->dev);
186 pm_runtime_put(&client->dev);186 pm_runtime_put(&client->dev);
187 187
188 indio_dev->dev.parent = &client->dev;
189 indio_dev->info = &bh1780_info;188 indio_dev->info = &bh1780_info;
190 indio_dev->name = "bh1780";189 indio_dev->name = "bh1780";
191 indio_dev->channels = bh1780_channels;190 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
465 cm32181->dev = dev;465 cm32181->dev = dev;
466 466
467 mutex_init(&cm32181->lock);467 mutex_init(&cm32181->lock);
468 indio_dev->dev.parent = dev;
469 indio_dev->channels = cm32181_channels;468 indio_dev->channels = cm32181_channels;
470 indio_dev->num_channels = ARRAY_SIZE(cm32181_channels);469 indio_dev->num_channels = ARRAY_SIZE(cm32181_channels);
471 indio_dev->info = &cm32181_info;470 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
340 i2c_set_clientdata(client, indio_dev);340 i2c_set_clientdata(client, indio_dev);
341 chip->client = client;341 chip->client = client;
342 342
343 indio_dev->dev.parent = &client->dev;
344 indio_dev->channels = cm3232_channels;343 indio_dev->channels = cm3232_channels;
345 indio_dev->num_channels = ARRAY_SIZE(cm3232_channels);344 indio_dev->num_channels = ARRAY_SIZE(cm3232_channels);
346 indio_dev->info = &cm3232_info;345 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
231 231
232 mutex_init(&data->mutex);232 mutex_init(&data->mutex);
233 233
234 indio_dev->dev.parent = &client->dev;
235 indio_dev->info = &cm3323_info;234 indio_dev->info = &cm3323_info;
236 indio_dev->name = CM3323_DRV_NAME;235 indio_dev->name = CM3323_DRV_NAME;
237 indio_dev->channels = cm3323_channels;236 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
239 led_trigger_register_simple("cm3605", &cm3605->led);239 led_trigger_register_simple("cm3605", &cm3605->led);
240 led_trigger_event(cm3605->led, LED_FULL);240 led_trigger_event(cm3605->led, LED_FULL);
241 241
242 indio_dev->dev.parent = dev;
243 indio_dev->info = &cm3605_info;242 indio_dev->info = &cm3605_info;
244 indio_dev->name = "cm3605";243 indio_dev->name = "cm3605";
245 indio_dev->channels = cm3605_channels;244 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
662 }662 }
663 663
664 mutex_init(&cm36651->lock);664 mutex_init(&cm36651->lock);
665 indio_dev->dev.parent = &client->dev;
666 indio_dev->channels = cm36651_channels;665 indio_dev->channels = cm36651_channels;
667 indio_dev->num_channels = ARRAY_SIZE(cm36651_channels);666 indio_dev->num_channels = ARRAY_SIZE(cm36651_channels);
668 indio_dev->info = &cm36651_info;667 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
145 break;145 break;
146 case IIO_CHAN_INFO_CALIBSCALE:146 case IIO_CHAN_INFO_CALIBSCALE:
147 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;147 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;
149 ret = cros_ec_motion_send_host_cmd(&st->core, 0);150 ret = cros_ec_motion_send_host_cmd(&st->core, 0);
151 if (ret == 0)
152 st->core.range_updated = true;
150 break;153 break;
151 default:154 default:
152 ret = cros_ec_sensors_core_write(&st->core, chan, val, val2,155 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
256static struct platform_driver cros_ec_light_prox_platform_driver = {259static struct platform_driver cros_ec_light_prox_platform_driver = {
257 .driver = {260 .driver = {
258 .name = "cros-ec-light-prox",261 .name = "cros-ec-light-prox",
262 .pm = &cros_ec_sensors_pm_ops,
259 },263 },
260 .probe = cros_ec_light_prox_probe,264 .probe = cros_ec_light_prox_probe,
261 .id_table = cros_ec_light_prox_ids,265 .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
596 pm_runtime_use_autosuspend(dev);596 pm_runtime_use_autosuspend(dev);
597 pm_runtime_put(dev);597 pm_runtime_put(dev);
598 598
599 indio_dev->dev.parent = dev;
600 indio_dev->info = &gp2ap002_info;599 indio_dev->info = &gp2ap002_info;
601 indio_dev->name = "gp2ap002";600 indio_dev->name = "gp2ap002";
602 indio_dev->channels = gp2ap002_channels;601 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
1390 1390
1391 mutex_lock(&data->lock);1391 mutex_lock(&data->lock);
1392 1392
1393 err = iio_triggered_buffer_postenable(indio_dev);
1394 if (err < 0) {
1395 mutex_unlock(&data->lock);
1396 return err;
1397 }
1398
1399 /*1393 /*
1400 * Enable triggers according to the scan_mask. Enabling either1394 * Enable triggers according to the scan_mask. Enabling either
1401 * LIGHT_CLEAR or LIGHT_IR scan mode results in enabling ALS1395 * 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
1430 err = -ENOMEM;1424 err = -ENOMEM;
1431 1425
1432error_unlock:1426error_unlock:
1433 if (err < 0)
1434 iio_triggered_buffer_predisable(indio_dev);
1435 mutex_unlock(&data->lock);1427 mutex_unlock(&data->lock);
1436 1428
1437 return err;1429 return err;
@@ -1465,8 +1457,6 @@ static int gp2ap020a00f_buffer_predisable(struct iio_dev *indio_dev) · 27 unmodified lines
1465 if (err == 0)1457 if (err == 0)
1466 kfree(data->buffer);1458 kfree(data->buffer);
1467 1459
1468 iio_triggered_buffer_predisable(indio_dev);
1469
1470 mutex_unlock(&data->lock);1460 mutex_unlock(&data->lock);
1471 1461
1472 return err;1462 return err;
@@ -1527,7 +1517,6 @@ static int gp2ap020a00f_probe(struct i2c_client *client, · 54 unmodified lines
1527 init_waitqueue_head(&data->data_ready_queue);1517 init_waitqueue_head(&data->data_ready_queue);
1528 1518
1529 mutex_init(&data->lock);1519 mutex_init(&data->lock);
1530 indio_dev->dev.parent = &client->dev;
1531 indio_dev->channels = gp2ap020a00f_channels;1520 indio_dev->channels = gp2ap020a00f_channels;
1532 indio_dev->num_channels = ARRAY_SIZE(gp2ap020a00f_channels);1521 indio_dev->num_channels = ARRAY_SIZE(gp2ap020a00f_channels);
1533 indio_dev->info = &gp2ap020a00f_info;1522 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
301 301
302 indio_dev->num_channels =302 indio_dev->num_channels =
303 ARRAY_SIZE(als_channels);303 ARRAY_SIZE(als_channels);
304 indio_dev->dev.parent = &pdev->dev;
305 indio_dev->info = &als_info;304 indio_dev->info = &als_info;
306 indio_dev->name = name;305 indio_dev->name = name;
307 indio_dev->modes = INDIO_DIRECT_MODE;306 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
279 }279 }
280 280
281 indio_dev->num_channels = ARRAY_SIZE(prox_channels);281 indio_dev->num_channels = ARRAY_SIZE(prox_channels);
282 indio_dev->dev.parent = &pdev->dev;
283 indio_dev->info = &prox_info;282 indio_dev->info = &prox_info;
284 indio_dev->name = name;283 indio_dev->name = name;
285 indio_dev->modes = INDIO_DIRECT_MODE;284 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/light/iqs621-als.c+4−3
@@ -36,6 +36,7 @@ · 35 unmodified lines
36 36
37struct iqs621_als_private {37struct iqs621_als_private {
38 struct iqs62x_core *iqs62x;38 struct iqs62x_core *iqs62x;
39 struct iio_dev *indio_dev;
39 struct notifier_block notifier;40 struct notifier_block notifier;
40 struct mutex lock;41 struct mutex lock;
41 bool light_en;42 bool light_en;
@@ -103,7 +104,7 @@ static int iqs621_als_notifier(struct notifier_block *notifier, · 61 unmodified lines
103 104
104 iqs621_als = container_of(notifier, struct iqs621_als_private,105 iqs621_als = container_of(notifier, struct iqs621_als_private,
105 notifier);106 notifier);
106 indio_dev = iio_priv_to_dev(iqs621_als);107 indio_dev = iqs621_als->indio_dev;
107 timestamp = iio_get_time_ns(indio_dev);108 timestamp = iio_get_time_ns(indio_dev);
108 109
109 mutex_lock(&iqs621_als->lock);110 mutex_lock(&iqs621_als->lock);
@@ -191,7 +192,7 @@ err_mutex: · 81 unmodified lines
191static void iqs621_als_notifier_unregister(void *context)192static void iqs621_als_notifier_unregister(void *context)
192{193{
193 struct iqs621_als_private *iqs621_als = context;194 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;
195 int ret;196 int ret;
196 197
197 ret = blocking_notifier_chain_unregister(&iqs621_als->iqs62x->nh,198 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
551 552
552 iqs621_als = iio_priv(indio_dev);553 iqs621_als = iio_priv(indio_dev);
553 iqs621_als->iqs62x = iqs62x;554 iqs621_als->iqs62x = iqs62x;
555 iqs621_als->indio_dev = indio_dev;
554 556
555 if (iqs62x->dev_desc->prod_num == IQS622_PROD_NUM) {557 if (iqs62x->dev_desc->prod_num == IQS622_PROD_NUM) {
556 ret = regmap_read(iqs62x->regmap, IQS622_IR_THRESH_TOUCH,558 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
580 }582 }
581 583
582 indio_dev->modes = INDIO_DIRECT_MODE;584 indio_dev->modes = INDIO_DIRECT_MODE;
583 indio_dev->dev.parent = &pdev->dev;
584 indio_dev->name = iqs62x->dev_desc->dev_name;585 indio_dev->name = iqs62x->dev_desc->dev_name;
585 indio_dev->info = &iqs621_als_info;586 indio_dev->info = &iqs621_als_info;
586 587
drivers/iio/light/isl29018.c+0−1
@@ -782,7 +782,6 @@ static int isl29018_probe(struct i2c_client *client, · 781 unmodified lines
782 indio_dev->channels = isl29018_chip_info_tbl[dev_id].channels;782 indio_dev->channels = isl29018_chip_info_tbl[dev_id].channels;
783 indio_dev->num_channels = isl29018_chip_info_tbl[dev_id].num_channels;783 indio_dev->num_channels = isl29018_chip_info_tbl[dev_id].num_channels;
784 indio_dev->name = name;784 indio_dev->name = name;
785 indio_dev->dev.parent = &client->dev;
786 indio_dev->modes = INDIO_DIRECT_MODE;785 indio_dev->modes = INDIO_DIRECT_MODE;
787 786
788 return devm_iio_device_register(&client->dev, indio_dev);787 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
620 indio_dev->channels = isl29028_channels;620 indio_dev->channels = isl29028_channels;
621 indio_dev->num_channels = ARRAY_SIZE(isl29028_channels);621 indio_dev->num_channels = ARRAY_SIZE(isl29028_channels);
622 indio_dev->name = id->name;622 indio_dev->name = id->name;
623 indio_dev->dev.parent = &client->dev;
624 indio_dev->modes = INDIO_DIRECT_MODE;623 indio_dev->modes = INDIO_DIRECT_MODE;
625 624
626 pm_runtime_enable(&client->dev);625 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
216static int isl29125_buffer_postenable(struct iio_dev *indio_dev)216static int isl29125_buffer_postenable(struct iio_dev *indio_dev)
217{217{
218 struct isl29125_data *data = iio_priv(indio_dev);218 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;
224 219
225 data->conf1 |= ISL29125_MODE_RGB;220 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,
227 data->conf1);222 data->conf1);
228 if (err) {
229 iio_triggered_buffer_predisable(indio_dev);
230 return err;
231 }
232
233 return 0;
234}223}
235 224
236static int isl29125_buffer_predisable(struct iio_dev *indio_dev)225static int isl29125_buffer_predisable(struct iio_dev *indio_dev)
237{226{
238 struct isl29125_data *data = iio_priv(indio_dev);227 struct isl29125_data *data = iio_priv(indio_dev);
239 int ret;
240 228
241 data->conf1 &= ~ISL29125_MODE_MASK;229 data->conf1 &= ~ISL29125_MODE_MASK;
242 data->conf1 |= ISL29125_MODE_PD;230 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,
244 data->conf1);232 data->conf1);
245
246 iio_triggered_buffer_predisable(indio_dev);
247
248 return ret;
249}233}
250 234
251static const struct iio_buffer_setup_ops isl29125_buffer_setup_ops = {235static 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
268 i2c_set_clientdata(client, indio_dev);252 i2c_set_clientdata(client, indio_dev);
269 data->client = client;253 data->client = client;
270 254
271 indio_dev->dev.parent = &client->dev;
272 indio_dev->info = &isl29125_info;255 indio_dev->info = &isl29125_info;
273 indio_dev->name = ISL29125_DRV_NAME;256 indio_dev->name = ISL29125_DRV_NAME;
274 indio_dev->channels = isl29125_channels;257 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
338 if (ret < 0)338 if (ret < 0)
339 return ret;339 return ret;
340 340
341 indio_dev->dev.parent = &client->dev;
342 indio_dev->channels = jsa1212_channels;341 indio_dev->channels = jsa1212_channels;
343 indio_dev->num_channels = ARRAY_SIZE(jsa1212_channels);342 indio_dev->num_channels = ARRAY_SIZE(jsa1212_channels);
344 indio_dev->name = JSA1212_DRIVER_NAME;343 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
852 indio_dev->channels = lm3533_als_channels;852 indio_dev->channels = lm3533_als_channels;
853 indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels);853 indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels);
854 indio_dev->name = dev_name(&pdev->dev);854 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);
856 indio_dev->modes = INDIO_DIRECT_MODE;856 indio_dev->modes = INDIO_DIRECT_MODE;
857 857
858 als = iio_priv(indio_dev);858 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
1480 if ((partid >> 4) != data->chip_info->partid)1480 if ((partid >> 4) != data->chip_info->partid)
1481 return -ENODEV;1481 return -ENODEV;
1482 1482
1483 indio_dev->dev.parent = &client->dev;
1484 indio_dev->info = data->chip_info->info;1483 indio_dev->info = data->chip_info->info;
1485 indio_dev->channels = data->chip_info->channels;1484 indio_dev->channels = data->chip_info->channels;
1486 indio_dev->num_channels = data->chip_info->no_channels;1485 indio_dev->num_channels = data->chip_info->no_channels;
drivers/iio/light/lv0104cs.c+1−2
@@ -7,7 +7,7 @@ · 6 unmodified lines
7 *7 *
8 * 7-bit I2C slave address: 0x138 * 7-bit I2C slave address: 0x13
9 *9 *
10 * Link to data sheet: http://www.onsemi.com/pub/Collateral/LV0104CS-D.PDF10 * Link to data sheet: https://www.onsemi.com/pub/Collateral/LV0104CS-D.PDF
11 */11 */
12 12
13#include <linux/kernel.h>13#include <linux/kernel.h>
@@ -502,7 +502,6 @@ static int lv0104cs_probe(struct i2c_client *client, · 488 unmodified lines
502 return ret;502 return ret;
503 503
504 indio_dev->modes = INDIO_DIRECT_MODE;504 indio_dev->modes = INDIO_DIRECT_MODE;
505 indio_dev->dev.parent = &client->dev;
506 indio_dev->channels = lv0104cs_channels;505 indio_dev->channels = lv0104cs_channels;
507 indio_dev->num_channels = ARRAY_SIZE(lv0104cs_channels);506 indio_dev->num_channels = ARRAY_SIZE(lv0104cs_channels);
508 indio_dev->name = client->name;507 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
538 538
539 i2c_set_clientdata(client, indio_dev);539 i2c_set_clientdata(client, indio_dev);
540 mutex_init(&data->lock);540 mutex_init(&data->lock);
541 indio_dev->dev.parent = &client->dev;
542 indio_dev->info = &max44000_info;541 indio_dev->info = &max44000_info;
543 indio_dev->name = MAX44000_DRV_NAME;542 indio_dev->name = MAX44000_DRV_NAME;
544 indio_dev->channels = max44000_channels;543 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
501 data = iio_priv(indio_dev);501 data = iio_priv(indio_dev);
502 i2c_set_clientdata(client, indio_dev);502 i2c_set_clientdata(client, indio_dev);
503 data->client = client;503 data->client = client;
504 indio_dev->dev.parent = &client->dev;
505 indio_dev->info = &max44009_info;504 indio_dev->info = &max44009_info;
506 indio_dev->modes = INDIO_DIRECT_MODE;505 indio_dev->modes = INDIO_DIRECT_MODE;
507 indio_dev->name = MAX44009_DRV_NAME;506 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
270 return ret;270 return ret;
271 }271 }
272 272
273 indio_dev->dev.parent = &client->dev;
274 indio_dev->info = &noa1305_info;273 indio_dev->info = &noa1305_info;
275 indio_dev->channels = noa1305_channels;274 indio_dev->channels = noa1305_channels;
276 indio_dev->num_channels = ARRAY_SIZE(noa1305_channels);275 indio_dev->num_channels = ARRAY_SIZE(noa1305_channels);
drivers/iio/light/opt3001.c+1−2
@@ -2,7 +2,7 @@ · 1 unmodified line
2/**2/**
3 * opt3001.c - Texas Instruments OPT3001 Light Sensor3 * opt3001.c - Texas Instruments OPT3001 Light Sensor
4 *4 *
5 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com5 * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com
6 *6 *
7 * Author: Andreas Dannenberg <dannenberg@ti.com>7 * Author: Andreas Dannenberg <dannenberg@ti.com>
8 * Based on previous work from: Felipe Balbi <balbi@ti.com>8 * 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
768 iio->name = client->name;768 iio->name = client->name;
769 iio->channels = opt3001_channels;769 iio->channels = opt3001_channels;
770 iio->num_channels = ARRAY_SIZE(opt3001_channels);770 iio->num_channels = ARRAY_SIZE(opt3001_channels);
771 iio->dev.parent = dev;
772 iio->modes = INDIO_DIRECT_MODE;771 iio->modes = INDIO_DIRECT_MODE;
773 iio->info = &opt3001_info;772 iio->info = &opt3001_info;
774 773
drivers/iio/light/pa12203001.c+0−1
@@ -362,7 +362,6 @@ static int pa12203001_probe(struct i2c_client *client, · 361 unmodified lines
362 362
363 mutex_init(&data->lock);363 mutex_init(&data->lock);
364 364
365 indio_dev->dev.parent = &client->dev;
366 indio_dev->info = &pa12203001_info;365 indio_dev->info = &pa12203001_info;
367 indio_dev->name = PA12203001_DRIVER_NAME;366 indio_dev->name = PA12203001_DRIVER_NAME;
368 indio_dev->channels = pa12203001_channels;367 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
570 570
571static const struct iio_buffer_setup_ops rpr0521_buffer_setup_ops = {571static const struct iio_buffer_setup_ops rpr0521_buffer_setup_ops = {
572 .preenable = rpr0521_buffer_preenable,572 .preenable = rpr0521_buffer_preenable,
573 .postenable = iio_triggered_buffer_postenable,
574 .predisable = iio_triggered_buffer_predisable,
575 .postdisable = rpr0521_buffer_postdisable,573 .postdisable = rpr0521_buffer_postdisable,
576};574};
577 575
@@ -948,7 +946,6 @@ static int rpr0521_probe(struct i2c_client *client, · 370 unmodified lines
948 946
949 mutex_init(&data->lock);947 mutex_init(&data->lock);
950 948
951 indio_dev->dev.parent = &client->dev;
952 indio_dev->info = &rpr0521_info;949 indio_dev->info = &rpr0521_info;
953 indio_dev->name = RPR0521_DRV_NAME;950 indio_dev->name = RPR0521_DRV_NAME;
954 indio_dev->channels = rpr0521_channels;951 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
1015 i2c_set_clientdata(client, iio_dev);1015 i2c_set_clientdata(client, iio_dev);
1016 data->client = client;1016 data->client = client;
1017 1017
1018 iio_dev->dev.parent = &client->dev;
1019 iio_dev->name = id->name;1018 iio_dev->name = id->name;
1020 iio_dev->channels = si1133_channels;1019 iio_dev->channels = si1133_channels;
1021 iio_dev->num_channels = ARRAY_SIZE(si1133_channels);1020 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
1171 1171
1172static const struct iio_buffer_setup_ops si1145_buffer_setup_ops = {1172static const struct iio_buffer_setup_ops si1145_buffer_setup_ops = {
1173 .preenable = si1145_buffer_preenable,1173 .preenable = si1145_buffer_preenable,
1174 .postenable = iio_triggered_buffer_postenable,
1175 .predisable = iio_triggered_buffer_predisable,
1176 .validate_scan_mask = si1145_validate_scan_mask,1174 .validate_scan_mask = si1145_validate_scan_mask,
1177};1175};
1178 1176
@@ -1307,7 +1305,6 @@ static int si1145_probe(struct i2c_client *client, · 128 unmodified lines
1307 return -ENODEV;1305 return -ENODEV;
1308 }1306 }
1309 1307
1310 indio_dev->dev.parent = &client->dev;
1311 indio_dev->name = id->name;1308 indio_dev->name = id->name;
1312 indio_dev->channels = data->part_info->channels;1309 indio_dev->channels = data->part_info->channels;
1313 indio_dev->num_channels = data->part_info->num_channels;1310 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
227 227
228static const struct iio_buffer_setup_ops st_uvis25_buffer_ops = {228static const struct iio_buffer_setup_ops st_uvis25_buffer_ops = {
229 .preenable = st_uvis25_buffer_preenable,229 .preenable = st_uvis25_buffer_preenable,
230 .postenable = iio_triggered_buffer_postenable,
231 .predisable = iio_triggered_buffer_predisable,
232 .postdisable = st_uvis25_buffer_postdisable,230 .postdisable = st_uvis25_buffer_postdisable,
233};231};
234 232
@@ -303,7 +301,6 @@ int st_uvis25_probe(struct device *dev, int irq, struct regmap *regmap) · 68 unmodified lines
303 return err;301 return err;
304 302
305 iio_dev->modes = INDIO_DIRECT_MODE;303 iio_dev->modes = INDIO_DIRECT_MODE;
306 iio_dev->dev.parent = dev;
307 iio_dev->channels = st_uvis25_channels;304 iio_dev->channels = st_uvis25_channels;
308 iio_dev->num_channels = ARRAY_SIZE(st_uvis25_channels);305 iio_dev->num_channels = ARRAY_SIZE(st_uvis25_channels);
309 iio_dev->name = ST_UVIS25_DEV_NAME;306 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
487 }487 }
488}488}
489 489
490static struct regmap_config stk3310_regmap_config = {490static const struct regmap_config stk3310_regmap_config = {
491 .name = STK3310_REGMAP_NAME,491 .name = STK3310_REGMAP_NAME,
492 .reg_bits = 8,492 .reg_bits = 8,
493 .val_bits = 8,493 .val_bits = 8,
@@ -585,7 +585,6 @@ static int stk3310_probe(struct i2c_client *client, · 91 unmodified lines
585 if (ret < 0)585 if (ret < 0)
586 return ret;586 return ret;
587 587
588 indio_dev->dev.parent = &client->dev;
589 indio_dev->info = &stk3310_info;588 indio_dev->info = &stk3310_info;
590 indio_dev->name = STK3310_DRIVER_NAME;589 indio_dev->name = STK3310_DRIVER_NAME;
591 indio_dev->modes = INDIO_DIRECT_MODE;590 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
243static int tcs3414_buffer_postenable(struct iio_dev *indio_dev)243static int tcs3414_buffer_postenable(struct iio_dev *indio_dev)
244{244{
245 struct tcs3414_data *data = iio_priv(indio_dev);245 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;
251 246
252 data->control |= TCS3414_CONTROL_ADC_EN;247 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,
254 data->control);249 data->control);
255 if (ret)
256 iio_triggered_buffer_predisable(indio_dev);
257
258 return ret;
259}250}
260 251
261static int tcs3414_buffer_predisable(struct iio_dev *indio_dev)252static int tcs3414_buffer_predisable(struct iio_dev *indio_dev)
262{253{
263 struct tcs3414_data *data = iio_priv(indio_dev);254 struct tcs3414_data *data = iio_priv(indio_dev);
264 int ret, ret2;
265 255
266 data->control &= ~TCS3414_CONTROL_ADC_EN;256 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,
268 data->control);258 data->control);
269
270 ret2 = iio_triggered_buffer_predisable(indio_dev);
271 if (!ret)
272 ret = ret2;
273
274 return ret;
275}259}
276 260
277static const struct iio_buffer_setup_ops tcs3414_buffer_setup_ops = {261static 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
294 i2c_set_clientdata(client, indio_dev);278 i2c_set_clientdata(client, indio_dev);
295 data->client = client;279 data->client = client;
296 280
297 indio_dev->dev.parent = &client->dev;
298 indio_dev->info = &tcs3414_info;281 indio_dev->info = &tcs3414_info;
299 indio_dev->name = TCS3414_DRV_NAME;282 indio_dev->name = TCS3414_DRV_NAME;
300 indio_dev->channels = tcs3414_channels;283 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
454 data->client = client;454 data->client = client;
455 mutex_init(&data->lock);455 mutex_init(&data->lock);
456 456
457 indio_dev->dev.parent = &client->dev;
458 indio_dev->info = &tcs3472_info;457 indio_dev->info = &tcs3472_info;
459 indio_dev->name = TCS3472_DRV_NAME;458 indio_dev->name = TCS3472_DRV_NAME;
460 indio_dev->channels = tcs3472_channels;459 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
713 713
714 chip = iio_priv(indio_dev);714 chip = iio_priv(indio_dev);
715 715
716 i2c_set_clientdata(client, chip);716 i2c_set_clientdata(client, indio_dev);
717 chip->client = client;717 chip->client = client;
718 718
719 err = tsl2563_detect(chip);719 err = tsl2563_detect(chip);
@@ -750,7 +750,6 @@ static int tsl2563_probe(struct i2c_client *client, · 30 unmodified lines
750 indio_dev->name = client->name;750 indio_dev->name = client->name;
751 indio_dev->channels = tsl2563_channels;751 indio_dev->channels = tsl2563_channels;
752 indio_dev->num_channels = ARRAY_SIZE(tsl2563_channels);752 indio_dev->num_channels = ARRAY_SIZE(tsl2563_channels);
753 indio_dev->dev.parent = &client->dev;
754 indio_dev->modes = INDIO_DIRECT_MODE;753 indio_dev->modes = INDIO_DIRECT_MODE;
755 754
756 if (client->irq)755 if (client->irq)
@@ -797,8 +796,8 @@ fail: · 40 unmodified lines
797 796
798static int tsl2563_remove(struct i2c_client *client)797static int tsl2563_remove(struct i2c_client *client)
799{798{
800 struct tsl2563_chip *chip = i2c_get_clientdata(client);799 struct iio_dev *indio_dev = i2c_get_clientdata(client);
801 struct iio_dev *indio_dev = iio_priv_to_dev(chip);800 struct tsl2563_chip *chip = iio_priv(indio_dev);
802 801
803 iio_device_unregister(indio_dev);802 iio_device_unregister(indio_dev);
804 if (!chip->int_enabled)803 if (!chip->int_enabled)
@@ -816,7 +815,8 @@ static int tsl2563_remove(struct i2c_client *client) · 11 unmodified lines
816#ifdef CONFIG_PM_SLEEP815#ifdef CONFIG_PM_SLEEP
817static int tsl2563_suspend(struct device *dev)816static int tsl2563_suspend(struct device *dev)
818{817{
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);
820 int ret;820 int ret;
821 821
822 mutex_lock(&chip->lock);822 mutex_lock(&chip->lock);
@@ -834,7 +834,8 @@ out: · 11 unmodified lines
834 834
835static int tsl2563_resume(struct device *dev)835static int tsl2563_resume(struct device *dev)
836{836{
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);
838 int ret;839 int ret;
839 840
840 mutex_lock(&chip->lock);841 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
840 indio_dev->info = &tsl2583_info;840 indio_dev->info = &tsl2583_info;
841 indio_dev->channels = tsl2583_channels;841 indio_dev->channels = tsl2583_channels;
842 indio_dev->num_channels = ARRAY_SIZE(tsl2583_channels);842 indio_dev->num_channels = ARRAY_SIZE(tsl2583_channels);
843 indio_dev->dev.parent = &clientp->dev;
844 indio_dev->modes = INDIO_DIRECT_MODE;843 indio_dev->modes = INDIO_DIRECT_MODE;
845 indio_dev->name = chip->client->name;844 indio_dev->name = chip->client->name;
846 845
drivers/iio/light/tsl2772.c+0−1
@@ -1833,7 +1833,6 @@ static int tsl2772_probe(struct i2c_client *clientp, · 1832 unmodified lines
1833 &tsl2772_chip_info_tbl[device_channel_config[id->driver_data]];1833 &tsl2772_chip_info_tbl[device_channel_config[id->driver_data]];
1834 1834
1835 indio_dev->info = chip->chip_info->info;1835 indio_dev->info = chip->chip_info->info;
1836 indio_dev->dev.parent = &clientp->dev;
1837 indio_dev->modes = INDIO_DIRECT_MODE;1836 indio_dev->modes = INDIO_DIRECT_MODE;
1838 indio_dev->name = chip->client->name;1837 indio_dev->name = chip->client->name;
1839 indio_dev->num_channels = chip->chip_info->chan_table_elements;1838 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
192 if (ret < 0)192 if (ret < 0)
193 return ret;193 return ret;
194 194
195 indio_dev->dev.parent = &client->dev;
196 indio_dev->info = &tsl4531_info;195 indio_dev->info = &tsl4531_info;
197 indio_dev->channels = tsl4531_channels;196 indio_dev->channels = tsl4531_channels;
198 indio_dev->num_channels = ARRAY_SIZE(tsl4531_channels);197 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
851 851
852 mutex_init(&data->lock);852 mutex_init(&data->lock);
853 853
854 indio_dev->dev.parent = &client->dev;
855 indio_dev->info = &us5182d_info;854 indio_dev->info = &us5182d_info;
856 indio_dev->name = US5182D_DRV_NAME;855 indio_dev->name = US5182D_DRV_NAME;
857 indio_dev->channels = us5182d_channels;856 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
957 int ret;957 int ret;
958 int cmd;958 int cmd;
959 959
960 ret = iio_triggered_buffer_postenable(indio_dev);
961 if (ret)
962 return ret;
963
964 /* Do not enable the buffer if we are already capturing events. */960 /* Do not enable the buffer if we are already capturing events. */
965 if (vcnl4010_is_in_periodic_mode(data)) {961 if (vcnl4010_is_in_periodic_mode(data))
966 ret = -EBUSY;962 return -EBUSY;
967 goto end;
968 }
969 963
970 ret = i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL,964 ret = i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL,
971 VCNL4010_INT_PROX_EN);965 VCNL4010_INT_PROX_EN);
972 if (ret < 0)966 if (ret < 0)
973 goto end;967 return ret;
974 968
975 cmd = VCNL4000_SELF_TIMED_EN | VCNL4000_PROX_EN;969 cmd = VCNL4000_SELF_TIMED_EN | VCNL4000_PROX_EN;
976 ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, cmd);970 return i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, cmd);
977 if (ret < 0)
978 goto end;
979
980 return 0;
981end:
982 iio_triggered_buffer_predisable(indio_dev);
983
984 return ret;
985}971}
986 972
987static int vcnl4010_buffer_predisable(struct iio_dev *indio_dev)973static int vcnl4010_buffer_predisable(struct iio_dev *indio_dev)
988{974{
989 struct vcnl4000_data *data = iio_priv(indio_dev);975 struct vcnl4000_data *data = iio_priv(indio_dev);
990 int ret, ret_disable;976 int ret;
991 977
992 ret = i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL, 0);978 ret = i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL, 0);
993 if (ret < 0)979 if (ret < 0)
994 goto end;980 return ret;
995
996 ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, 0);
997
998end:
999 ret_disable = iio_triggered_buffer_predisable(indio_dev);
1000 if (ret == 0)
1001 ret = ret_disable;
1002 981
1003 return ret;982 return i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, 0);
1004}983}
1005 984
1006static const struct iio_buffer_setup_ops vcnl4010_buffer_ops = {985static const struct iio_buffer_setup_ops vcnl4010_buffer_ops = {
@@ -1058,7 +1037,6 @@ static int vcnl4000_probe(struct i2c_client *client, · 51 unmodified lines
1058 &data->near_level))1037 &data->near_level))
1059 data->near_level = 0;1038 data->near_level = 0;
1060 1039
1061 indio_dev->dev.parent = &client->dev;
1062 indio_dev->info = data->chip_spec->info;1040 indio_dev->info = data->chip_spec->info;
1063 indio_dev->channels = data->chip_spec->channels;1041 indio_dev->channels = data->chip_spec->channels;
1064 indio_dev->num_channels = data->chip_spec->num_channels;1042 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
564 data->client = client;564 data->client = client;
565 data->regmap = regmap;565 data->regmap = regmap;
566 566
567 indio_dev->dev.parent = &client->dev;
568 indio_dev->info = &vcnl4035_info;567 indio_dev->info = &vcnl4035_info;
569 indio_dev->name = VCNL4035_DRV_NAME;568 indio_dev->name = VCNL4035_DRV_NAME;
570 indio_dev->channels = vcnl4035_channels;569 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
814 data->client = client;814 data->client = client;
815 data->regmap = regmap;815 data->regmap = regmap;
816 816
817 indio_dev->dev.parent = &client->dev;
818 indio_dev->name = "veml6030";817 indio_dev->name = "veml6030";
819 indio_dev->channels = veml6030_channels;818 indio_dev->channels = veml6030_channels;
820 indio_dev->num_channels = ARRAY_SIZE(veml6030_channels);819 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
151 data->client1 = client;151 data->client1 = client;
152 mutex_init(&data->lock);152 mutex_init(&data->lock);
153 153
154 indio_dev->dev.parent = &client->dev;
155 indio_dev->info = &veml6070_info;154 indio_dev->info = &veml6070_info;
156 indio_dev->channels = veml6070_channels;155 indio_dev->channels = veml6070_channels;
157 indio_dev->num_channels = ARRAY_SIZE(veml6070_channels);156 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
509 data->client = client;509 data->client = client;
510 mutex_init(&data->lock);510 mutex_init(&data->lock);
511 511
512 indio_dev->dev.parent = &client->dev;
513 indio_dev->info = &vl6180_info;512 indio_dev->info = &vl6180_info;
514 indio_dev->channels = vl6180_channels;513 indio_dev->channels = vl6180_channels;
515 indio_dev->num_channels = ARRAY_SIZE(vl6180_channels);514 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
527 data->client = client;527 data->client = client;
528 mutex_init(&data->lock);528 mutex_init(&data->lock);
529 529
530 indio_dev->dev.parent = &client->dev;
531 indio_dev->info = &zopt2201_info;530 indio_dev->info = &zopt2201_info;
532 indio_dev->channels = zopt2201_channels;531 indio_dev->channels = zopt2201_channels;
533 indio_dev->num_channels = ARRAY_SIZE(zopt2201_channels);532 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
892 pm_runtime_use_autosuspend(&i2c->dev);892 pm_runtime_use_autosuspend(&i2c->dev);
893 pm_runtime_put(&i2c->dev);893 pm_runtime_put(&i2c->dev);
894 894
895 indio_dev->dev.parent = &i2c->dev;
896 switch (ak8974->variant) {895 switch (ak8974->variant) {
897 case AK8974_WHOAMI_VALUE_AMI306:896 case AK8974_WHOAMI_VALUE_AMI306:
898 case AK8974_WHOAMI_VALUE_AMI305:897 case AK8974_WHOAMI_VALUE_AMI305:
drivers/iio/magnetometer/ak8975.c+20−3
@@ -358,6 +358,7 @@ struct ak8975_data { · 357 unmodified lines
358 u8 asa[3];358 u8 asa[3];
359 long raw_to_gauss[3];359 long raw_to_gauss[3];
360 struct gpio_desc *eoc_gpiod;360 struct gpio_desc *eoc_gpiod;
361 struct gpio_desc *reset_gpiod;
361 int eoc_irq;362 int eoc_irq;
362 wait_queue_head_t data_ready_queue;363 wait_queue_head_t data_ready_queue;
363 unsigned long flags;364 unsigned long flags;
@@ -384,10 +385,13 @@ static int ak8975_power_on(const struct ak8975_data *data) · 20 unmodified lines
384 "Failed to enable specified Vid supply\n");385 "Failed to enable specified Vid supply\n");
385 return ret;386 return ret;
386 }387 }
388
389 gpiod_set_value_cansleep(data->reset_gpiod, 0);
390
387 /*391 /*
388 * According to the datasheet the power supply rise time i 200us392 * According to the datasheet the power supply rise time is 200us
389 * and the minimum wait time before mode setting is 100us, in393 * 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.
391 */395 */
392 usleep_range(500, 1000);396 usleep_range(500, 1000);
393 return 0;397 return 0;
@@ -396,6 +400,8 @@ static int ak8975_power_on(const struct ak8975_data *data) · 2 unmodified lines
396/* Disable attached power regulator if any. */400/* Disable attached power regulator if any. */
397static void ak8975_power_off(const struct ak8975_data *data)401static void ak8975_power_off(const struct ak8975_data *data)
398{402{
403 gpiod_set_value_cansleep(data->reset_gpiod, 1);
404
399 regulator_disable(data->vid);405 regulator_disable(data->vid);
400 regulator_disable(data->vdd);406 regulator_disable(data->vdd);
401}407}
@@ -839,6 +845,7 @@ static int ak8975_probe(struct i2c_client *client, · 437 unmodified lines
839 struct ak8975_data *data;845 struct ak8975_data *data;
840 struct iio_dev *indio_dev;846 struct iio_dev *indio_dev;
841 struct gpio_desc *eoc_gpiod;847 struct gpio_desc *eoc_gpiod;
848 struct gpio_desc *reset_gpiod;
842 const void *match;849 const void *match;
843 unsigned int i;850 unsigned int i;
844 int err;851 int err;
@@ -856,6 +863,16 @@ static int ak8975_probe(struct i2c_client *client, · 11 unmodified lines
856 if (eoc_gpiod)863 if (eoc_gpiod)
857 gpiod_set_consumer_name(eoc_gpiod, "ak_8975");864 gpiod_set_consumer_name(eoc_gpiod, "ak_8975");
858 865
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
859 /* Register with IIO */876 /* Register with IIO */
860 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));877 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
861 if (indio_dev == NULL)878 if (indio_dev == NULL)
@@ -866,6 +883,7 @@ static int ak8975_probe(struct i2c_client *client, · 4 unmodified lines
866 883
867 data->client = client;884 data->client = client;
868 data->eoc_gpiod = eoc_gpiod;885 data->eoc_gpiod = eoc_gpiod;
886 data->reset_gpiod = reset_gpiod;
869 data->eoc_irq = 0;887 data->eoc_irq = 0;
870 888
871 err = iio_read_mount_matrix(&client->dev, "mount-matrix", &data->orientation);889 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
922 }940 }
923 941
924 mutex_init(&data->lock);942 mutex_init(&data->lock);
925 indio_dev->dev.parent = &client->dev;
926 indio_dev->channels = ak8975_channels;943 indio_dev->channels = ak8975_channels;
927 indio_dev->num_channels = ARRAY_SIZE(ak8975_channels);944 indio_dev->num_channels = ARRAY_SIZE(ak8975_channels);
928 indio_dev->info = &ak8975_info;945 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
836 836
837static const struct iio_buffer_setup_ops bmc150_magn_buffer_setup_ops = {837static const struct iio_buffer_setup_ops bmc150_magn_buffer_setup_ops = {
838 .preenable = bmc150_magn_buffer_preenable,838 .preenable = bmc150_magn_buffer_preenable,
839 .postenable = iio_triggered_buffer_postenable,
840 .predisable = iio_triggered_buffer_predisable,
841 .postdisable = bmc150_magn_buffer_postdisable,839 .postdisable = bmc150_magn_buffer_postdisable,
842};840};
843 841
@@ -883,7 +881,6 @@ int bmc150_magn_probe(struct device *dev, struct regmap *regmap, · 39 unmodified lines
883 if (ret < 0)881 if (ret < 0)
884 return ret;882 return ret;
885 883
886 indio_dev->dev.parent = dev;
887 indio_dev->channels = bmc150_magn_channels;884 indio_dev->channels = bmc150_magn_channels;
888 indio_dev->num_channels = ARRAY_SIZE(bmc150_magn_channels);885 indio_dev->num_channels = ARRAY_SIZE(bmc150_magn_channels);
889 indio_dev->available_scan_masks = bmc150_magn_scan_masks;886 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
58static const struct of_device_id bmc150_magn_of_match[] = {58static const struct of_device_id bmc150_magn_of_match[] = {
59 { .compatible = "bosch,bmc150_magn" },59 { .compatible = "bosch,bmc150_magn" },
60 { .compatible = "bosch,bmc156_magn" },60 { .compatible = "bosch,bmc156_magn" },
61 { .compatible = "bosch,bmm150_magn" },61 { .compatible = "bosch,bmm150_magn" }, /* deprecated compatible */
62 { .compatible = "bosch,bmm150" },
62 { }63 { }
63};64};
64MODULE_DEVICE_TABLE(of, bmc150_magn_of_match);65MODULE_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
512 512
513 indio_dev->channels = channels;513 indio_dev->channels = channels;
514 indio_dev->num_channels = chan_count;514 indio_dev->num_channels = chan_count;
515 indio_dev->dev.parent = &pdev->dev;
516 indio_dev->info = &magn_3d_info;515 indio_dev->info = &magn_3d_info;
517 indio_dev->name = name;516 indio_dev->name = name;
518 indio_dev->modes = INDIO_DIRECT_MODE;517 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
642 if (ret)642 if (ret)
643 return ret;643 return ret;
644 644
645 indio_dev->dev.parent = dev;
646 indio_dev->name = name;645 indio_dev->name = name;
647 indio_dev->info = &hmc5843_info;646 indio_dev->info = &hmc5843_info;
648 indio_dev->modes = INDIO_DIRECT_MODE;647 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
519 i2c_set_clientdata(client, indio_dev);519 i2c_set_clientdata(client, indio_dev);
520 indio_dev->info = &mag3110_info;520 indio_dev->info = &mag3110_info;
521 indio_dev->name = id->name;521 indio_dev->name = id->name;
522 indio_dev->dev.parent = &client->dev;
523 indio_dev->modes = INDIO_DIRECT_MODE;522 indio_dev->modes = INDIO_DIRECT_MODE;
524 indio_dev->channels = mag3110_channels;523 indio_dev->channels = mag3110_channels;
525 indio_dev->num_channels = ARRAY_SIZE(mag3110_channels);524 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
459 }459 }
460}460}
461 461
462static struct reg_default mmc35240_reg_defaults[] = {462static const struct reg_default mmc35240_reg_defaults[] = {
463 { MMC35240_REG_CTRL0, 0x00 },463 { MMC35240_REG_CTRL0, 0x00 },
464 { MMC35240_REG_CTRL1, 0x00 },464 { MMC35240_REG_CTRL1, 0x00 },
465};465};
@@ -507,7 +507,6 @@ static int mmc35240_probe(struct i2c_client *client, · 41 unmodified lines
507 507
508 mutex_init(&data->mutex);508 mutex_init(&data->mutex);
509 509
510 indio_dev->dev.parent = &client->dev;
511 indio_dev->info = &mmc35240_info;510 indio_dev->info = &mmc35240_info;
512 indio_dev->name = MMC35240_DRV_NAME;511 indio_dev->name = MMC35240_DRV_NAME;
513 indio_dev->channels = mmc35240_channels;512 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
463 463
464static const struct iio_buffer_setup_ops rm3100_buffer_ops = {464static const struct iio_buffer_setup_ops rm3100_buffer_ops = {
465 .preenable = rm3100_buffer_preenable,465 .preenable = rm3100_buffer_preenable,
466 .postenable = iio_triggered_buffer_postenable,
467 .predisable = iio_triggered_buffer_predisable,
468 .postdisable = rm3100_buffer_postdisable,466 .postdisable = rm3100_buffer_postdisable,
469};467};
470 468
@@ -549,7 +547,6 @@ int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq) · 78 unmodified lines
549 547
550 mutex_init(&data->lock);548 mutex_init(&data->lock);
551 549
552 indio_dev->dev.parent = dev;
553 indio_dev->name = "rm3100";550 indio_dev->name = "rm3100";
554 indio_dev->info = &rm3100_info;551 indio_dev->info = &rm3100_info;
555 indio_dev->channels = rm3100_channels;552 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
31 31
32static int st_magn_buffer_postenable(struct iio_dev *indio_dev)32static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
33{33{
34 int err;34 return st_sensors_set_enable(indio_dev, true);
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
46st_magn_buffer_predisable:
47 iio_triggered_buffer_predisable(indio_dev);
48 return err;
49}35}
50 36
51static int st_magn_buffer_predisable(struct iio_dev *indio_dev)37static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
52{38{
53 int err, err2;39 return st_sensors_set_enable(indio_dev, false);
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;
62}40}
63 41
64static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = {42static 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
395 mux->cached_state = -1;395 mux->cached_state = -1;
396 396
397 indio_dev->name = dev_name(dev);397 indio_dev->name = dev_name(dev);
398 indio_dev->dev.parent = dev;
399 indio_dev->info = &mux_info;398 indio_dev->info = &mux_info;
400 indio_dev->modes = INDIO_DIRECT_MODE;399 indio_dev->modes = INDIO_DIRECT_MODE;
401 indio_dev->channels = mux->chan;400 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
339 }339 }
340 340
341 indio_dev->num_channels = ARRAY_SIZE(incl_3d_channels);341 indio_dev->num_channels = ARRAY_SIZE(incl_3d_channels);
342 indio_dev->dev.parent = &pdev->dev;
343 indio_dev->info = &incl_3d_info;342 indio_dev->info = &incl_3d_info;
344 indio_dev->name = name;343 indio_dev->name = name;
345 indio_dev->modes = INDIO_DIRECT_MODE;344 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
281 }281 }
282 282
283 indio_dev->num_channels = ARRAY_SIZE(dev_rot_channels);283 indio_dev->num_channels = ARRAY_SIZE(dev_rot_channels);
284 indio_dev->dev.parent = &pdev->dev;
285 indio_dev->info = &dev_rot_info;284 indio_dev->info = &dev_rot_info;
286 indio_dev->name = name;285 indio_dev->name = name;
287 indio_dev->modes = INDIO_DIRECT_MODE;286 indio_dev->modes = INDIO_DIRECT_MODE;
drivers/iio/position/iqs624-pos.c+4−3
@@ -23,6 +23,7 @@ · 22 unmodified lines
23 23
24struct iqs624_pos_private {24struct iqs624_pos_private {
25 struct iqs62x_core *iqs62x;25 struct iqs62x_core *iqs62x;
26 struct iio_dev *indio_dev;
26 struct notifier_block notifier;27 struct notifier_block notifier;
27 struct mutex lock;28 struct mutex lock;
28 bool angle_en;29 bool angle_en;
@@ -59,7 +60,7 @@ static int iqs624_pos_notifier(struct notifier_block *notifier, · 30 unmodified lines
59 60
60 iqs624_pos = container_of(notifier, struct iqs624_pos_private,61 iqs624_pos = container_of(notifier, struct iqs624_pos_private,
61 notifier);62 notifier);
62 indio_dev = iio_priv_to_dev(iqs624_pos);63 indio_dev = iqs624_pos->indio_dev;
63 timestamp = iio_get_time_ns(indio_dev);64 timestamp = iio_get_time_ns(indio_dev);
64 65
65 iqs62x = iqs624_pos->iqs62x;66 iqs62x = iqs624_pos->iqs62x;
@@ -98,7 +99,7 @@ static int iqs624_pos_notifier(struct notifier_block *notifier, · 32 unmodified lines
98static void iqs624_pos_notifier_unregister(void *context)99static void iqs624_pos_notifier_unregister(void *context)
99{100{
100 struct iqs624_pos_private *iqs624_pos = context;101 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;
102 int ret;103 int ret;
103 104
104 ret = blocking_notifier_chain_unregister(&iqs624_pos->iqs62x->nh,105 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
243 244
244 iqs624_pos = iio_priv(indio_dev);245 iqs624_pos = iio_priv(indio_dev);
245 iqs624_pos->iqs62x = iqs62x;246 iqs624_pos->iqs62x = iqs62x;
247 iqs624_pos->indio_dev = indio_dev;
246 248
247 indio_dev->modes = INDIO_DIRECT_MODE;249 indio_dev->modes = INDIO_DIRECT_MODE;
248 indio_dev->dev.parent = &pdev->dev;
249 indio_dev->channels = iqs624_pos_channels;250 indio_dev->channels = iqs624_pos_channels;
250 indio_dev->num_channels = ARRAY_SIZE(iqs624_pos_channels);251 indio_dev->num_channels = ARRAY_SIZE(iqs624_pos_channels);
251 indio_dev->name = iqs62x->dev_desc->dev_name;252 indio_dev->name = iqs62x->dev_desc->dev_name;
drivers/iio/potentiometer/ad5272.c+1−2
@@ -3,7 +3,7 @@ · 2 unmodified lines
3 * Analog Devices AD5272 digital potentiometer driver3 * Analog Devices AD5272 digital potentiometer driver
4 * Copyright (C) 2018 Phil Reid <preid@electromag.com.au>4 * Copyright (C) 2018 Phil Reid <preid@electromag.com.au>
5 *5 *
6 * Datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/AD5272_5274.pdf6 * Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/AD5272_5274.pdf
7 *7 *
8 * DEVID #Wipers #Positions Resistor Opts (kOhm) i2c address8 * DEVID #Wipers #Positions Resistor Opts (kOhm) i2c address
9 * ad5272 1 1024 20, 50, 100 01011xx9 * ad5272 1 1024 20, 50, 100 01011xx
@@ -184,7 +184,6 @@ static int ad5272_probe(struct i2c_client *client, · 174 unmodified lines
184 if (ret < 0)184 if (ret < 0)
185 return -ENODEV;185 return -ENODEV;
186 186
187 indio_dev->dev.parent = dev;
188 indio_dev->info = &ad5272_info;187 indio_dev->info = &ad5272_info;
189 indio_dev->channels = &ad5272_channel;188 indio_dev->channels = &ad5272_channel;
190 indio_dev->num_channels = 1;189 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
126 data->client = client;126 data->client = client;
127 data->cfg = &ds1803_cfg[id->driver_data];127 data->cfg = &ds1803_cfg[id->driver_data];
128 128
129 indio_dev->dev.parent = dev;
130 indio_dev->info = &ds1803_info;129 indio_dev->info = &ds1803_info;
131 indio_dev->channels = ds1803_channels;130 indio_dev->channels = ds1803_channels;
132 indio_dev->num_channels = ARRAY_SIZE(ds1803_channels);131 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
102 data->client = client;102 data->client = client;
103 data->ohm = (unsigned long)of_device_get_match_data(dev);103 data->ohm = (unsigned long)of_device_get_match_data(dev);
104 104
105 indio_dev->dev.parent = dev;
106 indio_dev->info = &max5432_info;105 indio_dev->info = &max5432_info;
107 indio_dev->channels = max5432_channels;106 indio_dev->channels = max5432_channels;
108 indio_dev->num_channels = ARRAY_SIZE(max5432_channels);107 indio_dev->num_channels = ARRAY_SIZE(max5432_channels);
drivers/iio/potentiometer/max5481.c+1−2
@@ -4,7 +4,7 @@ · 3 unmodified lines
4 * Copyright 2016 Rockwell Collins4 * Copyright 2016 Rockwell Collins
5 *5 *
6 * Datasheet:6 * Datasheet:
7 * http://datasheets.maximintegrated.com/en/ds/MAX5481-MAX5484.pdf7 * https://datasheets.maximintegrated.com/en/ds/MAX5481-MAX5484.pdf
8 */8 */
9 9
10#include <linux/acpi.h>10#include <linux/acpi.h>
@@ -149,7 +149,6 @@ static int max5481_probe(struct spi_device *spi) · 138 unmodified lines
149 data->cfg = &max5481_cfg[id->driver_data];149 data->cfg = &max5481_cfg[id->driver_data];
150 150
151 indio_dev->name = id->name;151 indio_dev->name = id->name;
152 indio_dev->dev.parent = &spi->dev;
153 indio_dev->modes = INDIO_DIRECT_MODE;152 indio_dev->modes = INDIO_DIRECT_MODE;
154 153
155 /* variant specific configuration */154 /* 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
100 100
101 indio_dev->info = &max5487_info;101 indio_dev->info = &max5487_info;
102 indio_dev->name = id->name;102 indio_dev->name = id->name;
103 indio_dev->dev.parent = &spi->dev;
104 indio_dev->modes = INDIO_DIRECT_MODE;103 indio_dev->modes = INDIO_DIRECT_MODE;
105 indio_dev->channels = max5487_channels;104 indio_dev->channels = max5487_channels;
106 indio_dev->num_channels = ARRAY_SIZE(max5487_channels);105 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
165 if (!data->cfg)165 if (!data->cfg)
166 data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)->driver_data];166 data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)->driver_data];
167 167
168 indio_dev->dev.parent = dev;
169 indio_dev->info = &mcp4018_info;168 indio_dev->info = &mcp4018_info;
170 indio_dev->channels = &mcp4018_channel;169 indio_dev->channels = &mcp4018_channel;
171 indio_dev->num_channels = 1;170 indio_dev->num_channels = 1;
drivers/iio/potentiometer/mcp41010.c+1−2
@@ -5,7 +5,7 @@ · 4 unmodified lines
5 * Copyright (c) 2018 Chris Coffey <cmc@babblebit.net>5 * Copyright (c) 2018 Chris Coffey <cmc@babblebit.net>
6 * Based on: Slawomir Stepien's code from mcp4131.c6 * Based on: Slawomir Stepien's code from mcp4131.c
7 *7 *
8 * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/11195c.pdf8 * Datasheet: https://ww1.microchip.com/downloads/en/devicedoc/11195c.pdf
9 *9 *
10 * DEVID #Wipers #Positions Resistance (kOhm)10 * DEVID #Wipers #Positions Resistance (kOhm)
11 * mcp41010 1 256 1011 * mcp41010 1 256 10
@@ -152,7 +152,6 @@ static int mcp41010_probe(struct spi_device *spi) · 140 unmodified lines
152 152
153 mutex_init(&data->lock);153 mutex_init(&data->lock);
154 154
155 indio_dev->dev.parent = dev;
156 indio_dev->info = &mcp41010_info;155 indio_dev->info = &mcp41010_info;
157 indio_dev->channels = mcp41010_channels;156 indio_dev->channels = mcp41010_channels;
158 indio_dev->num_channels = data->cfg->wipers;157 indio_dev->num_channels = data->cfg->wipers;
drivers/iio/potentiometer/mcp4131.c+1−2
@@ -5,7 +5,7 @@ · 4 unmodified lines
5 * Copyright (c) 2016 Slawomir Stepien5 * Copyright (c) 2016 Slawomir Stepien
6 * Based on: Peter Rosin's code from mcp4531.c6 * Based on: Peter Rosin's code from mcp4531.c
7 *7 *
8 * Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/22060b.pdf8 * Datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/22060b.pdf
9 *9 *
10 * DEVID #Wipers #Positions Resistor Opts (kOhm)10 * DEVID #Wipers #Positions Resistor Opts (kOhm)
11 * mcp4131 1 129 5, 10, 50, 10011 * mcp4131 1 129 5, 10, 50, 100
@@ -260,7 +260,6 @@ static int mcp4131_probe(struct spi_device *spi) · 248 unmodified lines
260 260
261 mutex_init(&data->lock);261 mutex_init(&data->lock);
262 262
263 indio_dev->dev.parent = dev;
264 indio_dev->info = &mcp4131_info;263 indio_dev->info = &mcp4131_info;
265 indio_dev->channels = mcp4131_channels;264 indio_dev->channels = mcp4131_channels;
266 indio_dev->num_channels = data->cfg->wipers;265 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
375 if (!data->cfg)375 if (!data->cfg)
376 data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)->driver_data];376 data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)->driver_data];
377 377
378 indio_dev->dev.parent = dev;
379 indio_dev->info = &mcp4531_info;378 indio_dev->info = &mcp4531_info;
380 indio_dev->channels = mcp4531_channels;379 indio_dev->channels = mcp4531_channels;
381 indio_dev->num_channels = data->cfg->wipers;380 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
140 return PTR_ERR(data->regmap);140 return PTR_ERR(data->regmap);
141 }141 }
142 142
143 indio_dev->dev.parent = dev;
144 indio_dev->info = &tpl0102_info;143 indio_dev->info = &tpl0102_info;
145 indio_dev->channels = tpl0102_channels;144 indio_dev->channels = tpl0102_channels;
146 indio_dev->num_channels = data->cfg->wipers;145 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
278static int lmp91000_buffer_postenable(struct iio_dev *indio_dev)278static int lmp91000_buffer_postenable(struct iio_dev *indio_dev)
279{279{
280 struct lmp91000_data *data = iio_priv(indio_dev);280 struct lmp91000_data *data = iio_priv(indio_dev);
281 int err;
282 281
283 err = iio_triggered_buffer_postenable(indio_dev);282 return iio_channel_start_all_cb(data->cb_buffer);
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;
292}283}
293 284
294static int lmp91000_buffer_predisable(struct iio_dev *indio_dev)285static 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
297 288
298 iio_channel_stop_all_cb(data->cb_buffer);289 iio_channel_stop_all_cb(data->cb_buffer);
299 290
300 return iio_triggered_buffer_predisable(indio_dev);291 return 0;
301}292}
302 293
303static const struct iio_buffer_setup_ops lmp91000_buffer_setup_ops = {294static 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
321 indio_dev->channels = lmp91000_channels;312 indio_dev->channels = lmp91000_channels;
322 indio_dev->num_channels = ARRAY_SIZE(lmp91000_channels);313 indio_dev->num_channels = ARRAY_SIZE(lmp91000_channels);
323 indio_dev->name = LMP91000_DRV_NAME;314 indio_dev->name = LMP91000_DRV_NAME;
324 indio_dev->dev.parent = &client->dev;
325 indio_dev->modes = INDIO_DIRECT_MODE;315 indio_dev->modes = INDIO_DIRECT_MODE;
326 i2c_set_clientdata(client, indio_dev);316 i2c_set_clientdata(client, indio_dev);
327 317
drivers/iio/pressure/abp060mg.c+0−1
@@ -194,7 +194,6 @@ static int abp060mg_probe(struct i2c_client *client, · 193 unmodified lines
194 194
195 abp060mg_init_device(indio_dev, cfg_id);195 abp060mg_init_device(indio_dev, cfg_id);
196 196
197 indio_dev->dev.parent = &client->dev;
198 indio_dev->name = dev_name(&client->dev);197 indio_dev->name = dev_name(&client->dev);
199 indio_dev->modes = INDIO_DIRECT_MODE;198 indio_dev->modes = INDIO_DIRECT_MODE;
200 indio_dev->info = &abp060mg_info;199 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
1004 mutex_init(&data->lock);1004 mutex_init(&data->lock);
1005 data->dev = dev;1005 data->dev = dev;
1006 1006
1007 indio_dev->dev.parent = dev;
1008 indio_dev->name = name;1007 indio_dev->name = name;
1009 indio_dev->channels = bmp280_channels;1008 indio_dev->channels = bmp280_channels;
1010 indio_dev->info = &bmp280_info;1009 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
96 /* Always roundup, so caller gets at least what it asks for. */96 /* Always roundup, so caller gets at least what it asks for. */
97 st->core.param.sensor_range.roundup = 1;97 st->core.param.sensor_range.roundup = 1;
98 98
99 if (cros_ec_motion_send_host_cmd(&st->core, 0))99 ret = cros_ec_motion_send_host_cmd(&st->core, 0);
100 ret = -EIO;100 if (ret == 0) {
101 st->core.range_updated = true;
102 st->core.curr_range = val;
103 }
101 break;104 break;
102 default:105 default:
103 ret = cros_ec_sensors_core_write(&st->core, chan, val, val2,106 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
199static struct platform_driver cros_ec_baro_platform_driver = {202static struct platform_driver cros_ec_baro_platform_driver = {
200 .driver = {203 .driver = {
201 .name = "cros-ec-baro",204 .name = "cros-ec-baro",
205 .pm = &cros_ec_sensors_pm_ops,
202 },206 },
203 .probe = cros_ec_baro_probe,207 .probe = cros_ec_baro_probe,
204 .id_table = cros_ec_baro_ids,208 .id_table = cros_ec_baro_ids,
drivers/iio/pressure/dlhl60d.c+1−3
@@ -5,7 +5,7 @@ · 4 unmodified lines
5 * Copyright (c) 2019 AVL DiTEST GmbH5 * Copyright (c) 2019 AVL DiTEST GmbH
6 * Tomislav Denis <tomislav.denis@avl.com>6 * Tomislav Denis <tomislav.denis@avl.com>
7 *7 *
8 * Datasheet: http://www.allsensors.com/cad/DS-0355_Rev_B.PDF8 * Datasheet: https://www.allsensors.com/cad/DS-0355_Rev_B.PDF
9 */9 */
10 10
11#include <linux/module.h>11#include <linux/module.h>
@@ -311,8 +311,6 @@ static int dlh_probe(struct i2c_client *client, · 299 unmodified lines
311 st->use_interrupt = false;311 st->use_interrupt = false;
312 312
313 indio_dev->name = id->name;313 indio_dev->name = id->name;
314 indio_dev->dev.parent = &client->dev;
315 indio_dev->dev.of_node = client->dev.of_node;
316 indio_dev->info = &dlh_info;314 indio_dev->info = &dlh_info;
317 indio_dev->modes = INDIO_DIRECT_MODE;315 indio_dev->modes = INDIO_DIRECT_MODE;
318 indio_dev->channels = dlh_channels;316 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
732 data->client = client;732 data->client = client;
733 mutex_init(&data->lock);733 mutex_init(&data->lock);
734 734
735 iio->dev.parent = &client->dev;
736 iio->name = id->name;735 iio->name = id->name;
737 iio->channels = dps310_channels;736 iio->channels = dps310_channels;
738 iio->num_channels = ARRAY_SIZE(dps310_channels);737 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
283 283
284 indio_dev->num_channels =284 indio_dev->num_channels =
285 ARRAY_SIZE(press_channels);285 ARRAY_SIZE(press_channels);
286 indio_dev->dev.parent = &pdev->dev;
287 indio_dev->info = &press_info;286 indio_dev->info = &press_info;
288 indio_dev->name = name;287 indio_dev->name = name;
289 indio_dev->modes = INDIO_DIRECT_MODE;288 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
224 priv->client = client;224 priv->client = client;
225 mutex_init(&priv->lock);225 mutex_init(&priv->lock);
226 226
227 indio_dev->dev.parent = dev;
228 indio_dev->name = id->name;227 indio_dev->name = id->name;
229 indio_dev->channels = hp03_channels;228 indio_dev->channels = hp03_channels;
230 indio_dev->num_channels = ARRAY_SIZE(hp03_channels);229 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
378 378
379 indio_dev->info = &hp206c_info;379 indio_dev->info = &hp206c_info;
380 indio_dev->name = id->name;380 indio_dev->name = id->name;
381 indio_dev->dev.parent = &client->dev;
382 indio_dev->modes = INDIO_DIRECT_MODE;381 indio_dev->modes = INDIO_DIRECT_MODE;
383 indio_dev->channels = hp206c_channels;382 indio_dev->channels = hp206c_channels;
384 indio_dev->num_channels = ARRAY_SIZE(hp206c_channels);383 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
545 return -ENOMEM;545 return -ENOMEM;
546 546
547 i2c_set_clientdata(client, indio_dev);547 i2c_set_clientdata(client, indio_dev);
548 indio_dev->dev.parent = &client->dev;
549 indio_dev->name = client->name;548 indio_dev->name = client->name;
550 indio_dev->modes = INDIO_DIRECT_MODE;549 indio_dev->modes = INDIO_DIRECT_MODE;
551 indio_dev->channels = icp10100_channels;550 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
160 160
161 indio_dev->info = &mpl115_info;161 indio_dev->info = &mpl115_info;
162 indio_dev->name = name;162 indio_dev->name = name;
163 indio_dev->dev.parent = dev;
164 indio_dev->modes = INDIO_DIRECT_MODE;163 indio_dev->modes = INDIO_DIRECT_MODE;
165 indio_dev->channels = mpl115_channels;164 indio_dev->channels = mpl115_channels;
166 indio_dev->num_channels = ARRAY_SIZE(mpl115_channels);165 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
241 i2c_set_clientdata(client, indio_dev);241 i2c_set_clientdata(client, indio_dev);
242 indio_dev->info = &mpl3115_info;242 indio_dev->info = &mpl3115_info;
243 indio_dev->name = id->name;243 indio_dev->name = id->name;
244 indio_dev->dev.parent = &client->dev;
245 indio_dev->modes = INDIO_DIRECT_MODE;244 indio_dev->modes = INDIO_DIRECT_MODE;
246 indio_dev->channels = mpl3115_channels;245 indio_dev->channels = mpl3115_channels;
247 indio_dev->num_channels = ARRAY_SIZE(mpl3115_channels);246 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
435 st->pressure_osr =435 st->pressure_osr =
436 &ms5611_avail_pressure_osr[ARRAY_SIZE(ms5611_avail_pressure_osr)436 &ms5611_avail_pressure_osr[ARRAY_SIZE(ms5611_avail_pressure_osr)
437 - 1];437 - 1];
438 indio_dev->dev.parent = dev;
439 indio_dev->name = name;438 indio_dev->name = name;
440 indio_dev->info = &ms5611_info;439 indio_dev->info = &ms5611_info;
441 indio_dev->channels = ms5611_channels;440 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
152 152
153 indio_dev->info = &ms5637_info;153 indio_dev->info = &ms5637_info;
154 indio_dev->name = id->name;154 indio_dev->name = id->name;
155 indio_dev->dev.parent = &client->dev;
156 indio_dev->modes = INDIO_DIRECT_MODE;155 indio_dev->modes = INDIO_DIRECT_MODE;
157 indio_dev->channels = ms5637_channels;156 indio_dev->channels = ms5637_channels;
158 indio_dev->num_channels = ARRAY_SIZE(ms5637_channels);157 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
31 31
32static int st_press_buffer_postenable(struct iio_dev *indio_dev)32static int st_press_buffer_postenable(struct iio_dev *indio_dev)
33{33{
34 int err;34 return st_sensors_set_enable(indio_dev, true);
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
46st_press_buffer_predisable:
47 iio_triggered_buffer_predisable(indio_dev);
48 return err;
49}35}
50 36
51static int st_press_buffer_predisable(struct iio_dev *indio_dev)37static int st_press_buffer_predisable(struct iio_dev *indio_dev)
52{38{
53 int err, err2;39 return st_sensors_set_enable(indio_dev, false);
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;
62}40}
63 41
64static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = {42static 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
236 i2c_set_clientdata(client, indio_dev);236 i2c_set_clientdata(client, indio_dev);
237 indio_dev->info = &t5403_info;237 indio_dev->info = &t5403_info;
238 indio_dev->name = id->name;238 indio_dev->name = id->name;
239 indio_dev->dev.parent = &client->dev;
240 indio_dev->modes = INDIO_DIRECT_MODE;239 indio_dev->modes = INDIO_DIRECT_MODE;
241 indio_dev->channels = t5403_channels;240 indio_dev->channels = t5403_channels;
242 indio_dev->num_channels = ARRAY_SIZE(t5403_channels);241 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
1242 const struct zpa2326_private *priv = iio_priv(indio_dev);1242 const struct zpa2326_private *priv = iio_priv(indio_dev);
1243 int err;1243 int err;
1244 1244
1245 /* Plug our own trigger event handler. */
1246 err = iio_triggered_buffer_postenable(indio_dev);
1247 if (err)
1248 goto err;
1249
1250 if (!priv->waken) {1245 if (!priv->waken) {
1251 /*1246 /*
1252 * We were already power supplied. Just clear hardware FIFO to1247 * We were already power supplied. Just clear hardware FIFO to
1253 * get rid of samples acquired during previous rounds (if any).1248 * get rid of samples acquired during previous rounds (if any).
1254 */1249 */
1255 err = zpa2326_clear_fifo(indio_dev, 0);1250 err = zpa2326_clear_fifo(indio_dev, 0);
1256 if (err)1251 if (err) {
1257 goto err_buffer_predisable;1252 zpa2326_err(indio_dev,
1253 "failed to enable buffering (%d)", err);
1254 return err;
1255 }
1258 }1256 }
1259 1257
1260 if (!iio_trigger_using_own(indio_dev) && priv->waken) {1258 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
1263 * powered up: reconfigure one-shot mode.1261 * powered up: reconfigure one-shot mode.
1264 */1262 */
1265 err = zpa2326_config_oneshot(indio_dev, priv->irq);1263 err = zpa2326_config_oneshot(indio_dev, priv->irq);
1266 if (err)1264 if (err) {
1267 goto err_buffer_predisable;1265 zpa2326_err(indio_dev,
1266 "failed to enable buffering (%d)", err);
1267 return err;
1268 }
1268 }1269 }
1269 1270
1270 return 0;1271 return 0;
1271
1272err_buffer_predisable:
1273 iio_triggered_buffer_predisable(indio_dev);
1274err:
1275 zpa2326_err(indio_dev, "failed to enable buffering (%d)", err);
1276
1277 return err;
1278}1272}
1279 1273
1280static int zpa2326_postdisable_buffer(struct iio_dev *indio_dev)1274static 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
1287static const struct iio_buffer_setup_ops zpa2326_buffer_setup_ops = {1281static const struct iio_buffer_setup_ops zpa2326_buffer_setup_ops = {
1288 .preenable = zpa2326_preenable_buffer,1282 .preenable = zpa2326_preenable_buffer,
1289 .postenable = zpa2326_postenable_buffer,1283 .postenable = zpa2326_postenable_buffer,
1290 .predisable = iio_triggered_buffer_predisable,
1291 .postdisable = zpa2326_postdisable_buffer1284 .postdisable = zpa2326_postdisable_buffer
1292};1285};
1293 1286
@@ -1601,7 +1594,6 @@ static struct iio_dev *zpa2326_create_managed_iiodev(struct device *device, · 307 unmodified lines
1601 1594
1602 /* Setup for userspace synchronous on demand sampling. */1595 /* Setup for userspace synchronous on demand sampling. */
1603 indio_dev->modes = INDIO_DIRECT_MODE;1596 indio_dev->modes = INDIO_DIRECT_MODE;
1604 indio_dev->dev.parent = device;
1605 indio_dev->channels = zpa2326_channels;1597 indio_dev->channels = zpa2326_channels;
1606 indio_dev->num_channels = ARRAY_SIZE(zpa2326_channels);1598 indio_dev->num_channels = ARRAY_SIZE(zpa2326_channels);
1607 indio_dev->name = name;1599 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
399 return -EINVAL;399 return -EINVAL;
400 }400 }
401 401
402 indio_dev->dev.parent = &spi->dev;
403 indio_dev->name = spi_get_device_id(spi)->name;402 indio_dev->name = spi_get_device_id(spi)->name;
404 indio_dev->channels = as3935_channels;403 indio_dev->channels = as3935_channels;
405 indio_dev->num_channels = ARRAY_SIZE(as3935_channels);404 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
972 return ret;972 return ret;
973 973
974 indio_dev->modes = INDIO_DIRECT_MODE;974 indio_dev->modes = INDIO_DIRECT_MODE;
975 indio_dev->dev.parent = &client->dev;
976 indio_dev->channels = isl29501_channels;975 indio_dev->channels = isl29501_channels;
977 indio_dev->num_channels = ARRAY_SIZE(isl29501_channels);976 indio_dev->num_channels = ARRAY_SIZE(isl29501_channels);
978 indio_dev->name = client->name;977 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
200 200
201 indio_dev->info = &mb1232_info;201 indio_dev->info = &mb1232_info;
202 indio_dev->name = id->name;202 indio_dev->name = id->name;
203 indio_dev->dev.parent = dev;
204 indio_dev->modes = INDIO_DIRECT_MODE;203 indio_dev->modes = INDIO_DIRECT_MODE;
205 indio_dev->channels = mb1232_channels;204 indio_dev->channels = mb1232_channels;
206 indio_dev->num_channels = ARRAY_SIZE(mb1232_channels);205 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
309 platform_set_drvdata(pdev, indio_dev);309 platform_set_drvdata(pdev, indio_dev);
310 310
311 indio_dev->name = "ping";311 indio_dev->name = "ping";
312 indio_dev->dev.parent = &pdev->dev;
313 indio_dev->info = &ping_iio_info;312 indio_dev->info = &ping_iio_info;
314 indio_dev->modes = INDIO_DIRECT_MODE;313 indio_dev->modes = INDIO_DIRECT_MODE;
315 indio_dev->channels = ping_chan_spec;314 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
270 indio_dev->name = LIDAR_DRV_NAME;270 indio_dev->name = LIDAR_DRV_NAME;
271 indio_dev->channels = lidar_channels;271 indio_dev->channels = lidar_channels;
272 indio_dev->num_channels = ARRAY_SIZE(lidar_channels);272 indio_dev->num_channels = ARRAY_SIZE(lidar_channels);
273 indio_dev->dev.parent = &client->dev;
274 indio_dev->modes = INDIO_DIRECT_MODE;273 indio_dev->modes = INDIO_DIRECT_MODE;
275 274
276 i2c_set_clientdata(client, indio_dev);275 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
274 data->client = client;274 data->client = client;
275 mutex_init(&data->lock);275 mutex_init(&data->lock);
276 276
277 indio_dev->dev.parent = &client->dev;
278 indio_dev->info = &rfd77402_info;277 indio_dev->info = &rfd77402_info;
279 indio_dev->channels = rfd77402_channels;278 indio_dev->channels = rfd77402_channels;
280 indio_dev->num_channels = ARRAY_SIZE(rfd77402_channels);279 indio_dev->num_channels = ARRAY_SIZE(rfd77402_channels);
drivers/iio/proximity/srf04.c+1−2
@@ -5,7 +5,7 @@ · 4 unmodified lines
5 * Copyright (c) 2017 Andreas Klinger <ak@it-klinger.de>5 * Copyright (c) 2017 Andreas Klinger <ak@it-klinger.de>
6 *6 *
7 * For details about the device see:7 * For details about the device see:
8 * http://www.robot-electronics.co.uk/htm/srf04tech.htm8 * https://www.robot-electronics.co.uk/htm/srf04tech.htm
9 *9 *
10 * the measurement cycle as timing diagram looks like:10 * the measurement cycle as timing diagram looks like:
11 *11 *
@@ -317,7 +317,6 @@ static int srf04_probe(struct platform_device *pdev) · 305 unmodified lines
317 platform_set_drvdata(pdev, indio_dev);317 platform_set_drvdata(pdev, indio_dev);
318 318
319 indio_dev->name = "srf04";319 indio_dev->name = "srf04";
320 indio_dev->dev.parent = &pdev->dev;
321 indio_dev->info = &srf04_iio_info;320 indio_dev->info = &srf04_iio_info;
322 indio_dev->modes = INDIO_DIRECT_MODE;321 indio_dev->modes = INDIO_DIRECT_MODE;
323 indio_dev->channels = srf04_chan_spec;322 indio_dev->channels = srf04_chan_spec;
drivers/iio/proximity/srf08.c+3−4
@@ -7,9 +7,9 @@ · 6 unmodified lines
7 * Copyright (c) 2016, 2017 Andreas Klinger <ak@it-klinger.de>7 * Copyright (c) 2016, 2017 Andreas Klinger <ak@it-klinger.de>
8 *8 *
9 * For details about the device see:9 * For details about the device see:
10 * http://www.robot-electronics.co.uk/htm/srf08tech.html10 * https://www.robot-electronics.co.uk/htm/srf08tech.html
11 * http://www.robot-electronics.co.uk/htm/srf10tech.htm11 * https://www.robot-electronics.co.uk/htm/srf10tech.htm
12 * http://www.robot-electronics.co.uk/htm/srf02tech.htm12 * https://www.robot-electronics.co.uk/htm/srf02tech.htm
13 */13 */
14 14
15#include <linux/err.h>15#include <linux/err.h>
@@ -483,7 +483,6 @@ static int srf08_probe(struct i2c_client *client, · 467 unmodified lines
483 }483 }
484 484
485 indio_dev->name = id->name;485 indio_dev->name = id->name;
486 indio_dev->dev.parent = &client->dev;
487 indio_dev->modes = INDIO_DIRECT_MODE;486 indio_dev->modes = INDIO_DIRECT_MODE;
488 indio_dev->channels = srf08_channels;487 indio_dev->channels = srf08_channels;
489 indio_dev->num_channels = ARRAY_SIZE(srf08_channels);488 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
736 736
737static const struct iio_buffer_setup_ops sx9310_buffer_setup_ops = {737static const struct iio_buffer_setup_ops sx9310_buffer_setup_ops = {
738 .preenable = sx9310_buffer_preenable,738 .preenable = sx9310_buffer_preenable,
739 .postenable = iio_triggered_buffer_postenable,
740 .predisable = iio_triggered_buffer_predisable,
741 .postdisable = sx9310_buffer_postdisable,739 .postdisable = sx9310_buffer_postdisable,
742};740};
743 741
@@ -931,7 +929,6 @@ static int sx9310_probe(struct i2c_client *client, · 187 unmodified lines
931 return ret;929 return ret;
932 930
933 ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(&client->dev));931 ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(&client->dev));
934 indio_dev->dev.parent = &client->dev;
935 indio_dev->channels = sx9310_channels;932 indio_dev->channels = sx9310_channels;
936 indio_dev->num_channels = ARRAY_SIZE(sx9310_channels);933 indio_dev->num_channels = ARRAY_SIZE(sx9310_channels);
937 indio_dev->info = &sx9310_info;934 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
680 struct sx9500_data *data = iio_priv(indio_dev);680 struct sx9500_data *data = iio_priv(indio_dev);
681 int ret = 0, i;681 int ret = 0, i;
682 682
683 ret = iio_triggered_buffer_postenable(indio_dev);
684 if (ret)
685 return ret;
686
687 mutex_lock(&data->mutex);683 mutex_lock(&data->mutex);
688 684
689 for (i = 0; i < SX9500_NUM_CHANNELS; i++)685 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
700 696
701 mutex_unlock(&data->mutex);697 mutex_unlock(&data->mutex);
702 698
703 if (ret)
704 iio_triggered_buffer_predisable(indio_dev);
705
706 return ret;699 return ret;
707}700}
708 701
@@ -727,8 +720,6 @@ static int sx9500_buffer_predisable(struct iio_dev *indio_dev) · 18 unmodified lines
727 720
728 mutex_unlock(&data->mutex);721 mutex_unlock(&data->mutex);
729 722
730 iio_triggered_buffer_predisable(indio_dev);
731
732 return ret;723 return ret;
733}724}
734 725
@@ -931,7 +922,6 @@ static int sx9500_probe(struct i2c_client *client, · 196 unmodified lines
931 if (IS_ERR(data->regmap))922 if (IS_ERR(data->regmap))
932 return PTR_ERR(data->regmap);923 return PTR_ERR(data->regmap);
933 924
934 indio_dev->dev.parent = &client->dev;
935 indio_dev->name = SX9500_DRIVER_NAME;925 indio_dev->name = SX9500_DRIVER_NAME;
936 indio_dev->channels = sx9500_channels;926 indio_dev->channels = sx9500_channels;
937 indio_dev->num_channels = ARRAY_SIZE(sx9500_channels);927 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
226 if (rc)226 if (rc)
227 return rc;227 return rc;
228 228
229 indio_dev->dev.parent = &client->dev;
230 indio_dev->info = &vcnl3020_info;229 indio_dev->info = &vcnl3020_info;
231 indio_dev->channels = vcnl3020_channels;230 indio_dev->channels = vcnl3020_channels;
232 indio_dev->num_channels = ARRAY_SIZE(vcnl3020_channels);231 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
134 I2C_FUNC_SMBUS_BYTE_DATA))134 I2C_FUNC_SMBUS_BYTE_DATA))
135 return -EOPNOTSUPP;135 return -EOPNOTSUPP;
136 136
137 indio_dev->dev.parent = &client->dev;
138 indio_dev->name = "vl53l0x";137 indio_dev->name = "vl53l0x";
139 indio_dev->info = &vl53l0x_info;138 indio_dev->info = &vl53l0x_info;
140 indio_dev->channels = vl53l0x_channels;139 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
157 return PTR_ERR(st->rdvel);157 return PTR_ERR(st->rdvel);
158 }158 }
159 159
160 indio_dev->dev.parent = &spi->dev;
161 indio_dev->info = &ad2s1200_info;160 indio_dev->info = &ad2s1200_info;
162 indio_dev->modes = INDIO_DIRECT_MODE;161 indio_dev->modes = INDIO_DIRECT_MODE;
163 indio_dev->channels = ad2s1200_channels;162 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
94 94
95 mutex_init(&st->lock);95 mutex_init(&st->lock);
96 st->sdev = spi;96 st->sdev = spi;
97 indio_dev->dev.parent = &spi->dev;
98 indio_dev->info = &ad2s90_info;97 indio_dev->info = &ad2s90_info;
99 indio_dev->modes = INDIO_DIRECT_MODE;98 indio_dev->modes = INDIO_DIRECT_MODE;
100 indio_dev->channels = &ad2s90_chan;99 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
223 223
224 indio_dev->channels = temp_chans;224 indio_dev->channels = temp_chans;
225 indio_dev->num_channels = ARRAY_SIZE(temperature_channels);225 indio_dev->num_channels = ARRAY_SIZE(temperature_channels);
226 indio_dev->dev.parent = &pdev->dev;
227 indio_dev->info = &temperature_info;226 indio_dev->info = &temperature_info;
228 indio_dev->name = name;227 indio_dev->name = name;
229 indio_dev->modes = INDIO_DIRECT_MODE;228 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
74 iio_device_set_drvdata(indio_dev, iqs62x);74 iio_device_set_drvdata(indio_dev, iqs62x);
75 75
76 indio_dev->modes = INDIO_DIRECT_MODE;76 indio_dev->modes = INDIO_DIRECT_MODE;
77 indio_dev->dev.parent = &pdev->dev;
78 indio_dev->channels = iqs620_temp_channels;77 indio_dev->channels = iqs620_temp_channels;
79 indio_dev->num_channels = ARRAY_SIZE(iqs620_temp_channels);78 indio_dev->num_channels = ARRAY_SIZE(iqs620_temp_channels);
80 indio_dev->name = iqs62x->dev_desc->dev_name;79 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
1500 if (ret)1500 if (ret)
1501 return ret;1501 return ret;
1502 1502
1503 indio_dev->dev.parent = &spi->dev;
1504 indio_dev->name = name;1503 indio_dev->name = name;
1505 indio_dev->num_channels = st->iio_channels;1504 indio_dev->num_channels = st->iio_channels;
1506 indio_dev->channels = st->iio_chan;1505 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
417 spi_set_drvdata(spi, indio_dev);417 spi_set_drvdata(spi, indio_dev);
418 418
419 indio_dev->info = &max31856_info;419 indio_dev->info = &max31856_info;
420 indio_dev->dev.parent = &spi->dev;
421 indio_dev->dev.of_node = spi->dev.of_node;
422 indio_dev->name = id->name;420 indio_dev->name = id->name;
423 indio_dev->modes = INDIO_DIRECT_MODE;421 indio_dev->modes = INDIO_DIRECT_MODE;
424 indio_dev->channels = max31856_channels;422 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
244 indio_dev->available_scan_masks = chip->scan_masks;244 indio_dev->available_scan_masks = chip->scan_masks;
245 indio_dev->num_channels = chip->num_channels;245 indio_dev->num_channels = chip->num_channels;
246 indio_dev->modes = INDIO_DIRECT_MODE;246 indio_dev->modes = INDIO_DIRECT_MODE;
247 indio_dev->dev.parent = &spi->dev;
248 247
249 data = iio_priv(indio_dev);248 data = iio_priv(indio_dev);
250 data->spi = spi;249 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
525 525
526 mlx90614_wakeup(data);526 mlx90614_wakeup(data);
527 527
528 indio_dev->dev.parent = &client->dev;
529 indio_dev->name = id->name;528 indio_dev->name = id->name;
530 indio_dev->modes = INDIO_DIRECT_MODE;529 indio_dev->modes = INDIO_DIRECT_MODE;
531 indio_dev->info = &mlx90614_info;530 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
645 mlx90632->regmap = regmap;645 mlx90632->regmap = regmap;
646 646
647 mutex_init(&mlx90632->lock);647 mutex_init(&mlx90632->lock);
648 indio_dev->dev.parent = &client->dev;
649 indio_dev->name = id->name;648 indio_dev->name = id->name;
650 indio_dev->modes = INDIO_DIRECT_MODE;649 indio_dev->modes = INDIO_DIRECT_MODE;
651 indio_dev->info = &mlx90632_info;650 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
216 i2c_set_clientdata(client, indio_dev);216 i2c_set_clientdata(client, indio_dev);
217 data->client = client;217 data->client = client;
218 218
219 indio_dev->dev.parent = &client->dev;
220 indio_dev->name = dev_name(&client->dev);219 indio_dev->name = dev_name(&client->dev);
221 indio_dev->modes = INDIO_DIRECT_MODE;220 indio_dev->modes = INDIO_DIRECT_MODE;
222 indio_dev->info = &tmp006_info;221 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
463 data->client = client;463 data->client = client;
464 mutex_init(&data->lock);464 mutex_init(&data->lock);
465 465
466 indio_dev->dev.parent = &client->dev;
467 indio_dev->name = "tmp007";466 indio_dev->name = "tmp007";
468 indio_dev->modes = INDIO_DIRECT_MODE;467 indio_dev->modes = INDIO_DIRECT_MODE;
469 indio_dev->info = &tmp007_info;468 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
160 160
161 indio_dev->info = &tsys01_info;161 indio_dev->info = &tsys01_info;
162 indio_dev->name = dev->driver->name;162 indio_dev->name = dev->driver->name;
163 indio_dev->dev.parent = dev;
164 indio_dev->modes = INDIO_DIRECT_MODE;163 indio_dev->modes = INDIO_DIRECT_MODE;
165 indio_dev->channels = tsys01_channels;164 indio_dev->channels = tsys01_channels;
166 indio_dev->num_channels = ARRAY_SIZE(tsys01_channels);165 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
149 149
150 indio_dev->info = &tsys02d_info;150 indio_dev->info = &tsys02d_info;
151 indio_dev->name = id->name;151 indio_dev->name = id->name;
152 indio_dev->dev.parent = &client->dev;
153 indio_dev->modes = INDIO_DIRECT_MODE;152 indio_dev->modes = INDIO_DIRECT_MODE;
154 indio_dev->channels = tsys02d_channels;153 indio_dev->channels = tsys02d_channels;
155 indio_dev->num_channels = ARRAY_SIZE(tsys02d_channels);154 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
723 return NULL;723 return NULL;
724 724
725 indio_dev->name = dev_name(dev);725 indio_dev->name = dev_name(dev);
726 indio_dev->dev.parent = dev;
727 indio_dev->info = &stm32_trigger_info;726 indio_dev->info = &stm32_trigger_info;
728 indio_dev->modes = INDIO_HARDWARE_TRIGGERED;727 indio_dev->modes = INDIO_HARDWARE_TRIGGERED;
729 indio_dev->num_channels = 1;728 indio_dev->num_channels = 1;
730 indio_dev->channels = &stm32_trigger_channel;729 indio_dev->channels = &stm32_trigger_channel;
731 indio_dev->dev.of_node = dev->of_node;
732 730
733 ret = devm_iio_device_register(dev, indio_dev);731 ret = devm_iio_device_register(dev, indio_dev);
734 if (ret)732 if (ret)
drivers/input/touchscreen/tsc2007_iio.c+0−1
@@ -119,7 +119,6 @@ int tsc2007_iio_configure(struct tsc2007 *ts) · 118 unmodified lines
119 iio->ts = ts;119 iio->ts = ts;
120 120
121 indio_dev->name = "tsc2007";121 indio_dev->name = "tsc2007";
122 indio_dev->dev.parent = &ts->client->dev;
123 indio_dev->info = &tsc2007_iio_info;122 indio_dev->info = &tsc2007_iio_info;
124 indio_dev->modes = INDIO_DIRECT_MODE;123 indio_dev->modes = INDIO_DIRECT_MODE;
125 indio_dev->channels = tsc2007_iio_channel;124 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
3114 3114
3115 toshiba_accelerometer_available(dev);3115 toshiba_accelerometer_available(dev);
3116 if (dev->accelerometer_supported) {3116 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));
3118 if (!dev->indio_dev) {3118 if (!dev->indio_dev) {
3119 pr_err("Unable to allocate iio device\n");3119 pr_err("Unable to allocate iio device\n");
3120 goto iio_error;3120 goto iio_error;
@@ -3124,7 +3124,6 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) · 3 unmodified lines
3124 3124
3125 dev->indio_dev->info = &toshiba_iio_accel_info;3125 dev->indio_dev->info = &toshiba_iio_accel_info;
3126 dev->indio_dev->name = "Toshiba accelerometer";3126 dev->indio_dev->name = "Toshiba accelerometer";
3127 dev->indio_dev->dev.parent = &acpi_dev->dev;
3128 dev->indio_dev->modes = INDIO_DIRECT_MODE;3127 dev->indio_dev->modes = INDIO_DIRECT_MODE;
3129 dev->indio_dev->channels = toshiba_iio_accel_channels;3128 dev->indio_dev->channels = toshiba_iio_accel_channels;
3130 dev->indio_dev->num_channels =3129 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
8 8
9First allocate one using:9First allocate one using:
10 10
11struct iio_dev *indio_dev = iio_device_alloc(sizeof(struct chip_state));11struct iio_dev *indio_dev = iio_device_alloc(parent, sizeof(struct chip_state));
12where chip_state is a structure of local state data for this instance of12where chip_state is a structure of local state data for this instance of
13the chip.13the chip.
14 14
@@ -16,8 +16,6 @@ That data can be accessed using iio_priv(struct iio_dev *). · 1 unmodified line
16 16
17Then fill in the following:17Then fill in the following:
18 18
19- indio_dev->dev.parent
20 Struct device associated with the underlying hardware.
21- indio_dev->name19- indio_dev->name
22 Name of the device being driven - made available as the name20 Name of the device being driven - made available as the name
23 attribute in sysfs.21 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
277 spi_set_drvdata(spi, indio_dev);277 spi_set_drvdata(spi, indio_dev);
278 278
279 indio_dev->name = spi->dev.driver->name;279 indio_dev->name = spi->dev.driver->name;
280 indio_dev->dev.parent = &spi->dev;
281 indio_dev->channels = adis16203_channels;280 indio_dev->channels = adis16203_channels;
282 indio_dev->num_channels = ARRAY_SIZE(adis16203_channels);281 indio_dev->num_channels = ARRAY_SIZE(adis16203_channels);
283 indio_dev->info = &adis16203_info;282 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
400 spi_set_drvdata(spi, indio_dev);400 spi_set_drvdata(spi, indio_dev);
401 401
402 indio_dev->name = spi->dev.driver->name;402 indio_dev->name = spi->dev.driver->name;
403 indio_dev->dev.parent = &spi->dev;
404 indio_dev->info = &adis16240_info;403 indio_dev->info = &adis16240_info;
405 indio_dev->channels = adis16240_channels;404 indio_dev->channels = adis16240_channels;
406 indio_dev->num_channels = ARRAY_SIZE(adis16240_channels);405 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
978 st->readback_delay_us += 5; /* Add tWAIT */978 st->readback_delay_us += 5; /* Add tWAIT */
979 979
980 indio_dev->name = spi_get_device_id(spi)->name;980 indio_dev->name = spi_get_device_id(spi)->name;
981 indio_dev->dev.parent = &spi->dev;
982 indio_dev->modes = INDIO_DIRECT_MODE;981 indio_dev->modes = INDIO_DIRECT_MODE;
983 982
984 ret = ad7280_channel_init(st);983 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
394 }394 }
395 395
396 indio_dev->name = spi_get_device_id(spi_dev)->name;396 indio_dev->name = spi_get_device_id(spi_dev)->name;
397 indio_dev->dev.parent = &spi_dev->dev;
398 indio_dev->info = &ad7816_info;397 indio_dev->info = &ad7816_info;
399 indio_dev->modes = INDIO_DIRECT_MODE;398 indio_dev->modes = INDIO_DIRECT_MODE;
400 399
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
2171 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)2171 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
2172 chip->int_mask |= ADT7516_AIN_INT_MASK;2172 chip->int_mask |= ADT7516_AIN_INT_MASK;
2173 2173
2174 indio_dev->dev.parent = dev;
2175 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)2174 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
2176 indio_dev->info = &adt7516_info;2175 indio_dev->info = &adt7516_info;
2177 else2176 else
drivers/staging/iio/cdc/ad7150.c+0−2
@@ -590,8 +590,6 @@ static int ad7150_probe(struct i2c_client *client, · 589 unmodified lines
590 indio_dev->name = id->name;590 indio_dev->name = id->name;
591 indio_dev->channels = ad7150_channels;591 indio_dev->channels = ad7150_channels;
592 indio_dev->num_channels = ARRAY_SIZE(ad7150_channels);592 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;
595 593
596 indio_dev->info = &ad7150_info;594 indio_dev->info = &ad7150_info;
597 595
drivers/staging/iio/cdc/ad7746.c+0−2
@@ -693,9 +693,7 @@ static int ad7746_probe(struct i2c_client *client, · 692 unmodified lines
693 chip->client = client;693 chip->client = client;
694 chip->capdac_set = -1;694 chip->capdac_set = -1;
695 695
696 /* Establish that the iio_dev is a child of the i2c device */
697 indio_dev->name = id->name;696 indio_dev->name = id->name;
698 indio_dev->dev.parent = &client->dev;
699 indio_dev->info = &ad7746_info;697 indio_dev->info = &ad7746_info;
700 indio_dev->channels = ad7746_channels;698 indio_dev->channels = ad7746_channels;
701 if (id->driver_data == 7746)699 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
348 st->spi = spi;348 st->spi = spi;
349 mutex_init(&st->lock);349 mutex_init(&st->lock);
350 350
351 indio_dev->dev.parent = &spi->dev;
352 indio_dev->name = spi_get_device_id(spi)->name;351 indio_dev->name = spi_get_device_id(spi)->name;
353 indio_dev->info = &ad9832_info;352 indio_dev->info = &ad9832_info;
354 indio_dev->modes = INDIO_DIRECT_MODE;353 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
431 st->spi = spi;431 st->spi = spi;
432 st->devid = spi_get_device_id(spi)->driver_data;432 st->devid = spi_get_device_id(spi)->driver_data;
433 st->reg = reg;433 st->reg = reg;
434 indio_dev->dev.parent = &spi->dev;
435 indio_dev->name = spi_get_device_id(spi)->name;434 indio_dev->name = spi_get_device_id(spi)->name;
436 switch (st->devid) {435 switch (st->devid) {
437 case ID_AD9833:436 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
759 INIT_DELAYED_WORK(&st->work, ad5933_work);759 INIT_DELAYED_WORK(&st->work, ad5933_work);
760 st->poll_time_jiffies = msecs_to_jiffies(AD5933_POLL_TIME_ms);760 st->poll_time_jiffies = msecs_to_jiffies(AD5933_POLL_TIME_ms);
761 761
762 indio_dev->dev.parent = &client->dev;
763 indio_dev->info = &ad5933_info;762 indio_dev->info = &ad5933_info;
764 indio_dev->name = id->name;763 indio_dev->name = id->name;
765 indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);764 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
671 st->resolution = 12;671 st->resolution = 12;
672 st->fexcit = AD2S1210_DEF_EXCIT;672 st->fexcit = AD2S1210_DEF_EXCIT;
673 673
674 indio_dev->dev.parent = &spi->dev;
675 indio_dev->info = &ad2s1210_info;674 indio_dev->info = &ad2s1210_info;
676 indio_dev->modes = INDIO_DIRECT_MODE;675 indio_dev->modes = INDIO_DIRECT_MODE;
677 indio_dev->channels = ad2s1210_channels;676 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 @@
1/* SPDX-License-Identifier: GPL-2.0 */1/* SPDX-License-Identifier: GPL-2.0 */
2/*2/*
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.
4 */4 */
5 5
6#ifndef _DT_BINDINGS_QCOM_SPMI_VADC_H6#ifndef _DT_BINDINGS_QCOM_SPMI_VADC_H
@@ -221,4 +221,80 @@ · 214 unmodified lines
221 221
222#define ADC5_MAX_CHANNEL 0xc0222#define ADC5_MAX_CHANNEL 0xc0
223 223
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
224#endif /* _DT_BINDINGS_QCOM_SPMI_VADC_H */300#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
42 * @resp: motion sensor response structure42 * @resp: motion sensor response structure
43 * @type: type of motion sensor43 * @type: type of motion sensor
44 * @loc: location where the motion sensor is placed44 * @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.
45 * @calib: calibration parameters. Note that trigger49 * @calib: calibration parameters. Note that trigger
46 * captured data will always provide the calibrated50 * captured data will always provide the calibrated
47 * data51 * data
@@ -65,6 +69,9 @@ struct cros_ec_sensors_core_state { · 17 unmodified lines
65 enum motionsensor_type type;69 enum motionsensor_type type;
66 enum motionsensor_location loc;70 enum motionsensor_location loc;
67 71
72 bool range_updated;
73 int curr_range;
74
68 struct calib_data {75 struct calib_data {
69 s16 offset;76 s16 offset;
70 u16 scale;77 u16 scale;
@@ -114,7 +121,9 @@ int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st, · 43 unmodified lines
114 struct iio_chan_spec const *chan,121 struct iio_chan_spec const *chan,
115 int val, int val2, long mask);122 int val, int val2, long mask);
116 123
117/* List of extended channel specification for all sensors */124extern const struct dev_pm_ops cros_ec_sensors_pm_ops;
125
126/* List of extended channel specification for all sensors. */
118extern const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[];127extern const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[];
119extern const struct attribute *cros_ec_sensor_fifo_attributes[];128extern const struct attribute *cros_ec_sensor_fifo_attributes[];
120 129
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 */
19struct 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
488 * @currentmode: [DRIVER] current operating mode488 * @currentmode: [DRIVER] current operating mode
489 * @dev: [DRIVER] device structure, should be assigned a parent489 * @dev: [DRIVER] device structure, should be assigned a parent
490 * and owner490 * and owner
491 * @event_interface: [INTERN] event chrdevs associated with interrupt lines
492 * @buffer: [DRIVER] any buffer present491 * @buffer: [DRIVER] any buffer present
493 * @buffer_list: [INTERN] list of all buffers currently attached
494 * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux492 * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux
495 * @mlock: [INTERN] lock used to prevent simultaneous device state493 * @mlock: [INTERN] lock used to prevent simultaneous device state
496 * changes494 * changes
@@ -506,9 +504,6 @@ struct iio_buffer_setup_ops { · 9 unmodified lines
506 * @pollfunc_event: [DRIVER] function run on events trigger being received504 * @pollfunc_event: [DRIVER] function run on events trigger being received
507 * @channels: [DRIVER] channel specification structure table505 * @channels: [DRIVER] channel specification structure table
508 * @num_channels: [DRIVER] number of channels specified in @channels.506 * @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
512 * @name: [DRIVER] name of the device.507 * @name: [DRIVER] name of the device.
513 * @label: [DRIVER] unique name to identify which device this is508 * @label: [DRIVER] unique name to identify which device this is
514 * @info: [DRIVER] callbacks and constant info from driver509 * @info: [DRIVER] callbacks and constant info from driver
@@ -520,8 +515,8 @@ struct iio_buffer_setup_ops { · 5 unmodified lines
520 * @groups: [INTERN] attribute groups515 * @groups: [INTERN] attribute groups
521 * @groupcounter: [INTERN] index of next attribute group516 * @groupcounter: [INTERN] index of next attribute group
522 * @flags: [INTERN] file ops related flags including busy flag.517 * @flags: [INTERN] file ops related flags including busy flag.
523 * @debugfs_dentry: [INTERN] device specific debugfs dentry.518 * @priv: [DRIVER] reference to driver's private information
524 * @cached_reg_addr: [INTERN] cached register address for debugfs reads.519 * **MUST** be accessed **ONLY** via iio_priv() helper
525 */520 */
526struct iio_dev {521struct iio_dev {
527 int id;522 int id;
@@ -531,10 +526,7 @@ struct iio_dev { · 3 unmodified lines
531 int currentmode;526 int currentmode;
532 struct device dev;527 struct device dev;
533 528
534 struct iio_event_interface *event_interface;
535
536 struct iio_buffer *buffer;529 struct iio_buffer *buffer;
537 struct list_head buffer_list;
538 int scan_bytes;530 int scan_bytes;
539 struct mutex mlock;531 struct mutex mlock;
540 532
@@ -551,8 +543,6 @@ struct iio_dev { · 10 unmodified lines
551 struct iio_chan_spec const *channels;543 struct iio_chan_spec const *channels;
552 int num_channels;544 int num_channels;
553 545
554 struct list_head channel_attr_list;
555 struct attribute_group chan_attr_group;
556 const char *name;546 const char *name;
557 const char *label;547 const char *label;
558 const struct iio_info *info;548 const struct iio_info *info;
@@ -565,12 +555,7 @@ struct iio_dev { · 6 unmodified lines
565 int groupcounter;555 int groupcounter;
566 556
567 unsigned long flags;557 unsigned long flags;
568#if defined(CONFIG_DEBUG_FS)558 void *priv;
569 struct dentry *debugfs_dentry;
570 unsigned cached_reg_addr;
571 char read_buf[20];
572 unsigned int read_buf_len;
573#endif
574};559};
575 560
576const struct iio_chan_spec561const struct iio_chan_spec
@@ -649,6 +634,26 @@ static inline struct iio_dev *iio_device_get(struct iio_dev *indio_dev) · 72 unmodified lines
649 return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL;634 return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL;
650}635}
651 636
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 **/
652static inline void iio_device_set_parent(struct iio_dev *indio_dev,
653 struct device *parent)
654{
655 indio_dev->dev.parent = parent;
656}
652 657
653/**658/**
654 * iio_device_set_drvdata() - Set device driver data659 * 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
669 *674 *
670 * Returns the data previously set with iio_device_set_drvdata()675 * Returns the data previously set with iio_device_set_drvdata()
671 */676 */
672static inline void *iio_device_get_drvdata(struct iio_dev *indio_dev)677static inline void *iio_device_get_drvdata(const struct iio_dev *indio_dev)
673{678{
674 return dev_get_drvdata(&indio_dev->dev);679 return dev_get_drvdata(&indio_dev->dev);
675}680}
676 681
677/* Can we make this smaller? */682/* Can we make this smaller? */
678#define IIO_ALIGN L1_CACHE_BYTES683#define IIO_ALIGN L1_CACHE_BYTES
679struct iio_dev *iio_device_alloc(int sizeof_priv);684struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv);
680 685
686/* The information at the returned address is guaranteed to be cacheline aligned */
681static inline void *iio_priv(const struct iio_dev *indio_dev)687static inline void *iio_priv(const struct iio_dev *indio_dev)
682{688{
683 return (char *)indio_dev + ALIGN(sizeof(struct iio_dev), IIO_ALIGN);689 return indio_dev->priv;
684}
685
686static 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));
690}690}
691 691
692void iio_device_free(struct iio_dev *indio_dev);692void iio_device_free(struct iio_dev *indio_dev);
693struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv);693struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv);
694struct iio_trigger *devm_iio_trigger_alloc(struct device *dev,694struct iio_trigger *devm_iio_trigger_alloc(struct device *dev,
695 const char *fmt, ...);695 const char *fmt, ...);
696/**696/**
@@ -709,10 +709,7 @@ static inline bool iio_buffer_enabled(struct iio_dev *indio_dev) · 12 unmodified lines
709 * @indio_dev: IIO device structure for device709 * @indio_dev: IIO device structure for device
710 **/710 **/
711#if defined(CONFIG_DEBUG_FS)711#if defined(CONFIG_DEBUG_FS)
712static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)712struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev);
713{
714 return indio_dev->debugfs_dentry;
715}
716#else713#else
717static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)714static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
718{715{
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
50 50
51void iio_trigger_notify_done(struct iio_trigger *trig);51void iio_trigger_notify_done(struct iio_trigger *trig);
52 52
53/*
54 * Two functions for common case where all that happens is a pollfunc
55 * is attached and detached from a trigger
56 */
57int iio_triggered_buffer_postenable(struct iio_dev *indio_dev);
58int iio_triggered_buffer_predisable(struct iio_dev *indio_dev);
59
60#endif53#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