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

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

Jonathan writes:

First set of IIO new device support, features and cleanup for 5.19

Usual mixed bag. Stand out this time is Andy Shevchenko's continuing
effort to move drivers over the generic firmware interfaces.

Device support
* sprd,sc2720
- upm9620 binding addition.
- Refactor and support for sc2720, sc2721 and sc2730.
* ti,ads1015
- Refactor driver and add support for TLA2024.

Device support (IDs only)
* invensense,mpu6050
- Add ID for ICM-20608-D.
* st,accel:
- Add ID for lis302dl.
* st,lsm6dsx
- Add support for ASM330LHHX (can fallback to LSM6DSR.)

Features
* convert drivers to device properties
- IIO core
- adi,ad7266
- adi,adis16480
- adi,adxl355
- bosch,bmi160
- domintech,dmard06
- fsl,fxas21002c
- invensense,mpu3050
- linear,ltc2983
- linear,ltc2632
- maxbotix,mb1232
- maxim,max31856
- maxim,max31865
- multiplexer
- ping
- rescale
- taos,tsl2772
* core
- Add runtime check on whether realbits fit in storagebits for each
channel.
* adi,ad_sigma_delta
- Add sequencer support and relevant update_scan_mode callbacks for
adi,ad7192 and adi,ad7124.

Cleanup and minor fixes
* MAINTAINERS
- Update Lorenzo Bianconi's email address for IIO drivers.
- Add entry for ad3552r and update maintainer in dt-binding doc.
* tree-wide
- Replace strtobool() with kstrtobool().
- Drop false OF dependencies.
* core
- Tidy up and document IIO modes.
- Take iio_buffer_enabled() out of header allowing current_mode to be
moved to the opaque structure.
- As all kfifo buffers use the same mode value, drop that parameter
and set it unconditionally.
- White space fixes and similar.
- Drop use of list iterator variable for
list_for_each_entry_continue_reverse and use list_prepare_entry to
restart.
* sysfs-trigger
- Replace use of 'found' variable with dedicate list iterator variable.
* adi,ad7124
- Drop misleading shift.
* adi,ad2s1210
- Remove redundant local variable assignment.
* adi,adis16480
- Use local device pointer to reduce repetition.
- Improve handling of clocks.
* domintech,dmard09
- White space.
* dummy driver
- Improve error handling.
* fsl,mma8452
- Add missing documentation of name element.
* invensense,mpu3050
- Stop remove() returning non 0.
* kionix,kxsd9
- White space.
* linear,ltc2688
- Use local variable for struct device.
- Combine of_node_put() error handling paths.
* linear,ltc2983
- Avoid use of constants in messages where a define is available.
* microchip,mcp4131
- Fix compatible in dt example.
* pni,rm3100
- Stop directly accessing iio_dev->current_mode just to find out
if the buffer is enabled.
* renesas,rzg2l
- Relax kconfig constraint to include newer devices.
* sprd,sc27xx
- Fix wrong scaling mask.
- Improve the calibration values.
* samsung,ssp
- Replace a 'found' variable in favor of an explicit value that was
found.
* sensortek,stk3xx
- Add proximity-near-level binding and driver support.
* st,st_sensors:
- Drop unused accel_type enum.
- Return early in *_write_raw()
- Drop unnecessary locking in _avail functions.
- Add local lock to protect odr against concurrent updates allowing
mlock to no longer be used outside of the core.
- Use iio_device_claim_direct_mode() rather than racy checking of
the current mode.
* st,stmpe-adc
- Fix checks on wait_for_completion_timeout().
- Allow use of of_device_id for matching.
* st,stm32-dfsdm
- Stop accessing iio_dev->current_mode to find out if the buffer
is enabled (so we can hide that variable in the opaque structure)
* st,vl53l0x
- Fix checks on wait_for_completion_timeout.
* ti,ads1015
- Add missing ID for ti,ads1115 in binding doc.
- Convert from repeated chip ID look up to selecting static const
data.
- Switch to read_avail() callback.
* ti,ads8688
- Use of_device_id for driver matching.
* ti,palmas-adc
- Drop a warning on minor calibration mismatch leading to slightly
negative values after applying the calibration.

* tag 'iio-for-5.19a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (95 commits)
iio: ti-ads8688: use of_device_id for OF matching
iio: stmpe-adc: use of_device_id for OF matching
dt-bindings: iio: Fix incorrect compatible strings in examples
iio: gyro: mpu3050: Make mpu3050_common_remove() return void
iio: dac: ltc2632: Make use of device properties
iio: temperature: max31865: Make use of device properties
iio: proximity: mb1232: Switch to use fwnode_irq_get()
iio: imu: adis16480: Improve getting the optional clocks
iio: imu: adis16480: Use temporary variable for struct device
iio: imu: adis16480: Make use of device properties
staging: iio: ad2s1210: remove redundant assignment to variable negative
iio: adc: sc27xx: add support for PMIC sc2730
iio: adc: sc27xx: add support for PMIC sc2720 and sc2721
iio: adc: sc27xx: refactor some functions for support more PMiCs
iio: adc: sc27xx: structure adjustment and optimization
iio: adc: sc27xx: Fine tune the scale calibration values
iio: adc: sc27xx: fix read big scale voltage not right
dt-bindings:iio:adc: add sprd,ump9620-adc dt-binding
iio: proximity: stk3310: Export near level property for proximity sensor
dt-bindings: iio: light: stk33xx: Add proximity-near-level
...

+1726 -843
+2 -1
Documentation/devicetree/bindings/iio/adc/renesas,rzg2l-adc.yaml
··· 19 19 compatible: 20 20 items: 21 21 - enum: 22 - - renesas,r9a07g044-adc # RZ/G2{L,LC} 22 + - renesas,r9a07g044-adc # RZ/G2L 23 + - renesas,r9a07g054-adc # RZ/V2L 23 24 - const: renesas,rzg2l-adc 24 25 25 26 reg:
+54 -6
Documentation/devicetree/bindings/iio/adc/sprd,sc2720-adc.yaml
··· 20 20 - sprd,sc2723-adc 21 21 - sprd,sc2730-adc 22 22 - sprd,sc2731-adc 23 + - sprd,ump9620-adc 23 24 24 25 reg: 25 26 maxItems: 1 ··· 34 33 hwlocks: 35 34 maxItems: 1 36 35 37 - nvmem-cells: 38 - maxItems: 2 36 + nvmem-cells: true 39 37 40 - nvmem-cell-names: 41 - items: 42 - - const: big_scale_calib 43 - - const: small_scale_calib 38 + nvmem-cell-names: true 39 + 40 + allOf: 41 + - if: 42 + not: 43 + properties: 44 + compatible: 45 + contains: 46 + enum: 47 + - sprd,ump9620-adc 48 + then: 49 + properties: 50 + nvmem-cells: 51 + maxItems: 2 52 + nvmem-cell-names: 53 + items: 54 + - const: big_scale_calib 55 + - const: small_scale_calib 56 + 57 + else: 58 + properties: 59 + nvmem-cells: 60 + maxItems: 6 61 + nvmem-cell-names: 62 + items: 63 + - const: big_scale_calib1 64 + - const: big_scale_calib2 65 + - const: small_scale_calib1 66 + - const: small_scale_calib2 67 + - const: vbat_det_cal1 68 + - const: vbat_det_cal2 44 69 45 70 required: 46 71 - compatible ··· 94 67 hwlocks = <&hwlock 4>; 95 68 nvmem-cells = <&adc_big_scale>, <&adc_small_scale>; 96 69 nvmem-cell-names = "big_scale_calib", "small_scale_calib"; 70 + }; 71 + }; 72 + 73 + - | 74 + #include <dt-bindings/interrupt-controller/irq.h> 75 + pmic { 76 + #address-cells = <1>; 77 + #size-cells = <0>; 78 + adc@504 { 79 + compatible = "sprd,ump9620-adc"; 80 + reg = <0x504>; 81 + interrupt-parent = <&ump9620_pmic>; 82 + interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; 83 + #io-channel-cells = <1>; 84 + hwlocks = <&hwlock 4>; 85 + nvmem-cells = <&adc_bcal1>, <&adc_bcal2>, 86 + <&adc_scal1>, <&adc_scal2>, 87 + <&vbat_det_cal1>, <&vbat_det_cal2>; 88 + nvmem-cell-names = "big_scale_calib1", "big_scale_calib2", 89 + "small_scale_calib1", "small_scale_calib2", 90 + "vbat_det_cal1", "vbat_det_cal2"; 97 91 }; 98 92 }; 99 93 ...
+5 -2
Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml
··· 4 4 $id: http://devicetree.org/schemas/iio/adc/ti,ads1015.yaml# 5 5 $schema: http://devicetree.org/meta-schemas/core.yaml# 6 6 7 - title: TI ADS1015 4 channel I2C analog to digital converter 7 + title: TI ADS1015/ADS1115 4 channel I2C analog to digital converter 8 8 9 9 maintainers: 10 10 - Daniel Baluta <daniel.baluta@nxp.com> ··· 15 15 16 16 properties: 17 17 compatible: 18 - const: ti,ads1015 18 + enum: 19 + - ti,ads1015 20 + - ti,ads1115 21 + - ti,tla2024 19 22 20 23 reg: 21 24 maxItems: 1
+1 -1
Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml
··· 8 8 title: Analog Devices AD2552R DAC device driver 9 9 10 10 maintainers: 11 - - Mihail Chindris <mihail.chindris@analog.com> 11 + - Nuno Sá <nuno.sa@analog.com> 12 12 13 13 description: | 14 14 Bindings for the Analog Devices AD3552R DAC device and similar.
+1 -1
Documentation/devicetree/bindings/iio/dac/lltc,ltc2632.yaml
··· 68 68 #size-cells = <0>; 69 69 70 70 dac@0 { 71 - compatible = "lltc,ltc2632"; 71 + compatible = "lltc,ltc2632-l12"; 72 72 reg = <0>; /* CS0 */ 73 73 spi-max-frequency = <1000000>; 74 74 vref-supply = <&vref>;
+19 -15
Documentation/devicetree/bindings/iio/imu/invensense,mpu6050.yaml
··· 14 14 15 15 properties: 16 16 compatible: 17 - enum: 18 - - invensense,iam20680 19 - - invensense,icm20608 20 - - invensense,icm20609 21 - - invensense,icm20689 22 - - invensense,icm20602 23 - - invensense,icm20690 24 - - invensense,mpu6000 25 - - invensense,mpu6050 26 - - invensense,mpu6500 27 - - invensense,mpu6515 28 - - invensense,mpu6880 29 - - invensense,mpu9150 30 - - invensense,mpu9250 31 - - invensense,mpu9255 17 + oneOf: 18 + - enum: 19 + - invensense,iam20680 20 + - invensense,icm20608 21 + - invensense,icm20609 22 + - invensense,icm20689 23 + - invensense,icm20602 24 + - invensense,icm20690 25 + - invensense,mpu6000 26 + - invensense,mpu6050 27 + - invensense,mpu6500 28 + - invensense,mpu6515 29 + - invensense,mpu6880 30 + - invensense,mpu9150 31 + - invensense,mpu9250 32 + - invensense,mpu9255 33 + - items: 34 + - const: invensense,icm20608d 35 + - const: invensense,icm20608 32 36 33 37 reg: 34 38 maxItems: 1
+21 -17
Documentation/devicetree/bindings/iio/imu/st,lsm6dsx.yaml
··· 14 14 15 15 properties: 16 16 compatible: 17 - enum: 18 - - st,lsm6ds3 19 - - st,lsm6ds3h 20 - - st,lsm6dsl 21 - - st,lsm6dsm 22 - - st,ism330dlc 23 - - st,lsm6dso 24 - - st,asm330lhh 25 - - st,lsm6dsox 26 - - st,lsm6dsr 27 - - st,lsm6ds3tr-c 28 - - st,ism330dhcx 29 - - st,lsm9ds1-imu 30 - - st,lsm6ds0 31 - - st,lsm6dsrx 32 - - st,lsm6dst 33 - - st,lsm6dsop 17 + oneOf: 18 + - enum: 19 + - st,lsm6ds3 20 + - st,lsm6ds3h 21 + - st,lsm6dsl 22 + - st,lsm6dsm 23 + - st,ism330dlc 24 + - st,lsm6dso 25 + - st,asm330lhh 26 + - st,lsm6dsox 27 + - st,lsm6dsr 28 + - st,lsm6ds3tr-c 29 + - st,ism330dhcx 30 + - st,lsm9ds1-imu 31 + - st,lsm6ds0 32 + - st,lsm6dsrx 33 + - st,lsm6dst 34 + - st,lsm6dsop 35 + - items: 36 + - const: st,asm330lhhx 37 + - const: st,lsm6dsr 34 38 35 39 reg: 36 40 maxItems: 1
+6
Documentation/devicetree/bindings/iio/light/stk33xx.yaml
··· 13 13 description: | 14 14 Ambient light and proximity sensor over an i2c interface. 15 15 16 + allOf: 17 + - $ref: ../common.yaml# 18 + 16 19 properties: 17 20 compatible: 18 21 enum: ··· 28 25 29 26 interrupts: 30 27 maxItems: 1 28 + 29 + proximity-near-level: true 31 30 32 31 required: 33 32 - compatible ··· 49 44 stk3310@48 { 50 45 compatible = "sensortek,stk3310"; 51 46 reg = <0x48>; 47 + proximity-near-level = <25>; 52 48 interrupt-parent = <&gpio1>; 53 49 interrupts = <5 IRQ_TYPE_LEVEL_LOW>; 54 50 };
+1 -1
Documentation/devicetree/bindings/iio/potentiometer/microchip,mcp4131.yaml
··· 95 95 #size-cells = <0>; 96 96 97 97 potentiometer@0 { 98 - compatible = "mcp4131-502"; 98 + compatible = "microchip,mcp4131-502"; 99 99 reg = <0>; 100 100 spi-max-frequency = <500000>; 101 101 };
+1
Documentation/devicetree/bindings/iio/st,st-sensors.yaml
··· 29 29 - st,lis2dw12 30 30 - st,lis2hh12 31 31 - st,lis2dh12-accel 32 + - st,lis302dl 32 33 - st,lis331dl-accel 33 34 - st,lis331dlh-accel 34 35 - st,lis3de
+10 -2
MAINTAINERS
··· 1091 1091 F: Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml 1092 1092 F: drivers/iio/adc/ad7292.c 1093 1093 1094 + ANALOG DEVICES INC AD3552R DRIVER 1095 + M: Nuno Sá <nuno.sa@analog.com> 1096 + L: linux-iio@vger.kernel.org 1097 + S: Supported 1098 + W: https://ez.analog.com/linux-software-drivers 1099 + F: Documentation/devicetree/bindings/iio/dac/adi,ad3552r.yaml 1100 + F: drivers/iio/dac/ad3552r.c 1101 + 1094 1102 ANALOG DEVICES INC AD7293 DRIVER 1095 1103 M: Antoniu Miclaus <antoniu.miclaus@analog.com> 1096 1104 L: linux-iio@vger.kernel.org ··· 9014 9006 F: drivers/input/touchscreen/htcpen.c 9015 9007 9016 9008 HTS221 TEMPERATURE-HUMIDITY IIO DRIVER 9017 - M: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> 9009 + M: Lorenzo Bianconi <lorenzo@kernel.org> 9018 9010 L: linux-iio@vger.kernel.org 9019 9011 S: Maintained 9020 9012 W: http://www.st.com/ ··· 18645 18637 F: arch/alpha/kernel/srm_env.c 18646 18638 18647 18639 ST LSM6DSx IMU IIO DRIVER 18648 - M: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> 18640 + M: Lorenzo Bianconi <lorenzo@kernel.org> 18649 18641 L: linux-iio@vger.kernel.org 18650 18642 S: Maintained 18651 18643 W: http://www.st.com/
-1
drivers/iio/accel/Kconfig
··· 290 290 291 291 config DMARD06 292 292 tristate "Domintech DMARD06 Digital Accelerometer Driver" 293 - depends on OF || COMPILE_TEST 294 293 depends on I2C 295 294 help 296 295 Say yes here to build support for the Domintech low-g tri-axial
+2 -5
drivers/iio/accel/adxl355_core.c
··· 18 18 #include <linux/math64.h> 19 19 #include <linux/module.h> 20 20 #include <linux/mod_devicetable.h> 21 - #include <linux/of_irq.h> 21 + #include <linux/property.h> 22 22 #include <linux/regmap.h> 23 23 #include <linux/units.h> 24 24 ··· 745 745 return ret; 746 746 } 747 747 748 - /* 749 - * TODO: Would be good to move it to the generic version. 750 - */ 751 - irq = of_irq_get_byname(dev->of_node, "DRDY"); 748 + irq = fwnode_irq_get_byname(dev_fwnode(dev), "DRDY"); 752 749 if (irq > 0) { 753 750 ret = adxl355_probe_trigger(indio_dev, irq); 754 751 if (ret)
-1
drivers/iio/accel/adxl367.c
··· 1567 1567 return ret; 1568 1568 1569 1569 ret = devm_iio_kfifo_buffer_setup_ext(st->dev, indio_dev, 1570 - INDIO_BUFFER_SOFTWARE, 1571 1570 &adxl367_buffer_ops, 1572 1571 adxl367_fifo_attributes); 1573 1572 if (ret)
+2 -2
drivers/iio/accel/bmc150-accel-core.c
··· 1525 1525 struct bmc150_accel_data *data = iio_priv(indio_dev); 1526 1526 int ret = 0; 1527 1527 1528 - if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) 1528 + if (iio_device_get_current_mode(indio_dev) == INDIO_BUFFER_TRIGGERED) 1529 1529 return 0; 1530 1530 1531 1531 mutex_lock(&data->mutex); ··· 1557 1557 { 1558 1558 struct bmc150_accel_data *data = iio_priv(indio_dev); 1559 1559 1560 - if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) 1560 + if (iio_device_get_current_mode(indio_dev) == INDIO_BUFFER_TRIGGERED) 1561 1561 return 0; 1562 1562 1563 1563 mutex_lock(&data->mutex);
+1 -1
drivers/iio/accel/dmard09.c
··· 24 24 #define DMARD09_AXIS_Y 1 25 25 #define DMARD09_AXIS_Z 2 26 26 #define DMARD09_AXIS_X_OFFSET ((DMARD09_AXIS_X + 1) * 2) 27 - #define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1 )* 2) 27 + #define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1) * 2) 28 28 #define DMARD09_AXIS_Z_OFFSET ((DMARD09_AXIS_Z + 1) * 2) 29 29 30 30 struct dmard09_data {
-1
drivers/iio/accel/fxls8962af-core.c
··· 1217 1217 return ret; 1218 1218 1219 1219 ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, 1220 - INDIO_BUFFER_SOFTWARE, 1221 1220 &fxls8962af_buffer_ops); 1222 1221 if (ret) 1223 1222 return ret;
+2 -2
drivers/iio/accel/kxsd9-spi.c
··· 44 44 MODULE_DEVICE_TABLE(spi, kxsd9_spi_id); 45 45 46 46 static const struct of_device_id kxsd9_of_match[] = { 47 - { .compatible = "kionix,kxsd9" }, 48 - { }, 47 + { .compatible = "kionix,kxsd9" }, 48 + { } 49 49 }; 50 50 MODULE_DEVICE_TABLE(of, kxsd9_of_match); 51 51
+1
drivers/iio/accel/mma8452.c
··· 166 166 167 167 /** 168 168 * struct mma_chip_info - chip specific data 169 + * @name: part number of device reported via 'name' attr 169 170 * @chip_id: WHO_AM_I register's value 170 171 * @channels: struct iio_chan_spec matching the device's 171 172 * capabilities
-1
drivers/iio/accel/sca3000.c
··· 1474 1474 indio_dev->modes = INDIO_DIRECT_MODE; 1475 1475 1476 1476 ret = devm_iio_kfifo_buffer_setup(&spi->dev, indio_dev, 1477 - INDIO_BUFFER_SOFTWARE, 1478 1477 &sca3000_ring_setup_ops); 1479 1478 if (ret) 1480 1479 return ret;
-1
drivers/iio/accel/ssp_accel_sensor.c
··· 113 113 indio_dev->available_scan_masks = ssp_accel_scan_mask; 114 114 115 115 ret = devm_iio_kfifo_buffer_setup(&pdev->dev, indio_dev, 116 - INDIO_BUFFER_SOFTWARE, 117 116 &ssp_accel_buffer_ops); 118 117 if (ret) 119 118 return ret;
+2 -26
drivers/iio/accel/st_accel.h
··· 14 14 #include <linux/types.h> 15 15 #include <linux/iio/common/st_sensors.h> 16 16 17 - enum st_accel_type { 18 - LSM303DLH, 19 - LSM303DLHC, 20 - LIS3DH, 21 - LSM330D, 22 - LSM330DL, 23 - LSM330DLC, 24 - LIS331DLH, 25 - LSM303DL, 26 - LSM303DLM, 27 - LSM330, 28 - LSM303AGR, 29 - LIS2DH12, 30 - LIS3L02DQ, 31 - LNG2DM, 32 - H3LIS331DL, 33 - LIS331DL, 34 - LIS3LV02DL, 35 - LIS2DW12, 36 - LIS3DHH, 37 - LIS2DE12, 38 - LIS2HH12, 39 - SC7A20, 40 - ST_ACCEL_MAX, 41 - }; 42 - 43 17 #define H3LIS331DL_ACCEL_DEV_NAME "h3lis331dl_accel" 44 18 #define LIS3LV02DL_ACCEL_DEV_NAME "lis3lv02dl_accel" 45 19 #define LSM303DLHC_ACCEL_DEV_NAME "lsm303dlhc_accel" ··· 36 62 #define LIS3DE_ACCEL_DEV_NAME "lis3de" 37 63 #define LIS2DE12_ACCEL_DEV_NAME "lis2de12" 38 64 #define LIS2HH12_ACCEL_DEV_NAME "lis2hh12" 65 + #define LIS302DL_ACCEL_DEV_NAME "lis302dl" 39 66 #define SC7A20_ACCEL_DEV_NAME "sc7a20" 67 + 40 68 41 69 #ifdef CONFIG_IIO_BUFFER 42 70 int st_accel_allocate_ring(struct iio_dev *indio_dev);
+4 -10
drivers/iio/accel/st_accel_core.c
··· 444 444 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, 445 445 .sensors_supported = { 446 446 [0] = LIS331DL_ACCEL_DEV_NAME, 447 + [1] = LIS302DL_ACCEL_DEV_NAME, 447 448 }, 448 449 .ch = (struct iio_chan_spec *)st_accel_8bit_channels, 449 450 .odr = { ··· 1210 1209 static int st_accel_write_raw(struct iio_dev *indio_dev, 1211 1210 struct iio_chan_spec const *chan, int val, int val2, long mask) 1212 1211 { 1213 - int err; 1214 - 1215 1212 switch (mask) { 1216 1213 case IIO_CHAN_INFO_SCALE: { 1217 1214 int gain; 1218 1215 1219 1216 gain = val * 1000000 + val2; 1220 - err = st_sensors_set_fullscale_by_gain(indio_dev, gain); 1221 - break; 1217 + return st_sensors_set_fullscale_by_gain(indio_dev, gain); 1222 1218 } 1223 1219 case IIO_CHAN_INFO_SAMP_FREQ: 1224 1220 if (val2) 1225 1221 return -EINVAL; 1226 - mutex_lock(&indio_dev->mlock); 1227 - err = st_sensors_set_odr(indio_dev, val); 1228 - mutex_unlock(&indio_dev->mlock); 1229 - return err; 1222 + 1223 + return st_sensors_set_odr(indio_dev, val); 1230 1224 default: 1231 1225 return -EINVAL; 1232 1226 } 1233 - 1234 - return err; 1235 1227 } 1236 1228 1237 1229 static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
+5
drivers/iio/accel/st_accel_i2c.c
··· 108 108 .data = LIS2HH12_ACCEL_DEV_NAME, 109 109 }, 110 110 { 111 + .compatible = "st,lis302dl", 112 + .data = LIS302DL_ACCEL_DEV_NAME, 113 + }, 114 + { 111 115 .compatible = "silan,sc7a20", 112 116 .data = SC7A20_ACCEL_DEV_NAME, 113 117 }, ··· 150 146 { LIS3DE_ACCEL_DEV_NAME }, 151 147 { LIS2DE12_ACCEL_DEV_NAME }, 152 148 { LIS2HH12_ACCEL_DEV_NAME }, 149 + { LIS302DL_ACCEL_DEV_NAME }, 153 150 { SC7A20_ACCEL_DEV_NAME }, 154 151 {}, 155 152 };
+5
drivers/iio/accel/st_accel_spi.c
··· 92 92 .compatible = "st,lis3de", 93 93 .data = LIS3DE_ACCEL_DEV_NAME, 94 94 }, 95 + { 96 + .compatible = "st,lis302dl", 97 + .data = LIS302DL_ACCEL_DEV_NAME, 98 + }, 95 99 {} 96 100 }; 97 101 MODULE_DEVICE_TABLE(of, st_accel_of_match); ··· 151 147 { LIS2DW12_ACCEL_DEV_NAME }, 152 148 { LIS3DHH_ACCEL_DEV_NAME }, 153 149 { LIS3DE_ACCEL_DEV_NAME }, 150 + { LIS302DL_ACCEL_DEV_NAME }, 154 151 {}, 155 152 }; 156 153 MODULE_DEVICE_TABLE(spi, st_accel_id_table);
+1 -1
drivers/iio/adc/Kconfig
··· 910 910 911 911 config RZG2L_ADC 912 912 tristate "Renesas RZ/G2L ADC driver" 913 - depends on ARCH_R9A07G044 || COMPILE_TEST 913 + depends on ARCH_RZG2L || COMPILE_TEST 914 914 help 915 915 Say yes here to build support for the ADC found in Renesas 916 916 RZ/G2L family.
+81 -5
drivers/iio/adc/ad7124.c
··· 43 43 #define AD7124_STATUS_POR_FLAG_MSK BIT(4) 44 44 45 45 /* AD7124_ADC_CONTROL */ 46 + #define AD7124_ADC_STATUS_EN_MSK BIT(10) 47 + #define AD7124_ADC_STATUS_EN(x) FIELD_PREP(AD7124_ADC_STATUS_EN_MSK, x) 46 48 #define AD7124_ADC_CTRL_REF_EN_MSK BIT(8) 47 49 #define AD7124_ADC_CTRL_REF_EN(x) FIELD_PREP(AD7124_ADC_CTRL_REF_EN_MSK, x) 48 50 #define AD7124_ADC_CTRL_PWR_MSK GENMASK(7, 6) ··· 190 188 .sign = 'u', 191 189 .realbits = 24, 192 190 .storagebits = 32, 193 - .shift = 8, 194 191 .endianness = IIO_BE, 195 192 }, 196 193 }; ··· 502 501 return ad7124_enable_channel(st, &st->channels[address]); 503 502 } 504 503 504 + static int __ad7124_set_channel(struct ad_sigma_delta *sd, unsigned int channel) 505 + { 506 + struct ad7124_state *st = container_of(sd, struct ad7124_state, sd); 507 + 508 + return ad7124_prepare_read(st, channel); 509 + } 510 + 505 511 static int ad7124_set_channel(struct ad_sigma_delta *sd, unsigned int channel) 506 512 { 507 513 struct ad7124_state *st = container_of(sd, struct ad7124_state, sd); 508 514 int ret; 509 515 510 516 mutex_lock(&st->cfgs_lock); 511 - ret = ad7124_prepare_read(st, channel); 517 + ret = __ad7124_set_channel(sd, channel); 512 518 mutex_unlock(&st->cfgs_lock); 513 519 514 520 return ret; 515 521 } 516 522 523 + static int ad7124_append_status(struct ad_sigma_delta *sd, bool append) 524 + { 525 + struct ad7124_state *st = container_of(sd, struct ad7124_state, sd); 526 + unsigned int adc_control = st->adc_control; 527 + int ret; 528 + 529 + adc_control &= ~AD7124_ADC_STATUS_EN_MSK; 530 + adc_control |= AD7124_ADC_STATUS_EN(append); 531 + 532 + ret = ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, adc_control); 533 + if (ret < 0) 534 + return ret; 535 + 536 + st->adc_control = adc_control; 537 + 538 + return 0; 539 + } 540 + 541 + static int ad7124_disable_all(struct ad_sigma_delta *sd) 542 + { 543 + struct ad7124_state *st = container_of(sd, struct ad7124_state, sd); 544 + int ret; 545 + int i; 546 + 547 + for (i = 0; i < st->num_channels; i++) { 548 + ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i), AD7124_CHANNEL_EN_MSK, 0, 2); 549 + if (ret < 0) 550 + return ret; 551 + } 552 + 553 + return 0; 554 + } 555 + 517 556 static const struct ad_sigma_delta_info ad7124_sigma_delta_info = { 518 557 .set_channel = ad7124_set_channel, 558 + .append_status = ad7124_append_status, 559 + .disable_all = ad7124_disable_all, 519 560 .set_mode = ad7124_set_mode, 520 561 .has_registers = true, 521 562 .addr_shift = 0, 522 563 .read_mask = BIT(6), 564 + .status_ch_mask = GENMASK(3, 0), 523 565 .data_reg = AD7124_DATA, 524 - .irq_flags = IRQF_TRIGGER_FALLING 566 + .num_slots = 8, 567 + .irq_flags = IRQF_TRIGGER_FALLING, 525 568 }; 526 569 527 570 static int ad7124_read_raw(struct iio_dev *indio_dev, ··· 715 670 .attrs = ad7124_attributes, 716 671 }; 717 672 673 + static int ad7124_update_scan_mode(struct iio_dev *indio_dev, 674 + const unsigned long *scan_mask) 675 + { 676 + struct ad7124_state *st = iio_priv(indio_dev); 677 + bool bit_set; 678 + int ret; 679 + int i; 680 + 681 + mutex_lock(&st->cfgs_lock); 682 + for (i = 0; i < st->num_channels; i++) { 683 + bit_set = test_bit(i, scan_mask); 684 + if (bit_set) 685 + ret = __ad7124_set_channel(&st->sd, i); 686 + else 687 + ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i), AD7124_CHANNEL_EN_MSK, 688 + 0, 2); 689 + if (ret < 0) { 690 + mutex_unlock(&st->cfgs_lock); 691 + 692 + return ret; 693 + } 694 + } 695 + 696 + mutex_unlock(&st->cfgs_lock); 697 + 698 + return 0; 699 + } 700 + 718 701 static const struct iio_info ad7124_info = { 719 702 .read_raw = ad7124_read_raw, 720 703 .write_raw = ad7124_write_raw, 721 704 .debugfs_reg_access = &ad7124_reg_access, 722 705 .validate_trigger = ad_sd_validate_trigger, 706 + .update_scan_mode = ad7124_update_scan_mode, 723 707 .attrs = &ad7124_attrs_group, 724 708 }; 725 709 ··· 960 886 961 887 st->chip_info = info; 962 888 963 - ad_sd_init(&st->sd, indio_dev, spi, &ad7124_sigma_delta_info); 964 - 965 889 indio_dev->name = st->chip_info->name; 966 890 indio_dev->modes = INDIO_DIRECT_MODE; 967 891 indio_dev->info = &ad7124_info; 892 + 893 + ret = ad_sd_init(&st->sd, indio_dev, spi, &ad7124_sigma_delta_info); 894 + if (ret < 0) 895 + return ret; 968 896 969 897 ret = ad7124_of_parse_channel_config(indio_dev, spi->dev.of_node); 970 898 if (ret < 0)
+65 -3
drivers/iio/adc/ad7192.c
··· 58 58 /* Mode Register Bit Designations (AD7192_REG_MODE) */ 59 59 #define AD7192_MODE_SEL(x) (((x) & 0x7) << 21) /* Operation Mode Select */ 60 60 #define AD7192_MODE_SEL_MASK (0x7 << 21) /* Operation Mode Select Mask */ 61 - #define AD7192_MODE_DAT_STA BIT(20) /* Status Register transmission */ 61 + #define AD7192_MODE_STA(x) (((x) & 0x1) << 20) /* Status Register transmission */ 62 + #define AD7192_MODE_STA_MASK BIT(20) /* Status Register transmission Mask */ 62 63 #define AD7192_MODE_CLKSRC(x) (((x) & 0x3) << 18) /* Clock Source Select */ 63 64 #define AD7192_MODE_SINC3 BIT(15) /* SINC3 Filter Select */ 64 65 #define AD7192_MODE_ACX BIT(14) /* AC excitation enable(AD7195 only)*/ ··· 226 225 bool sys_calib; 227 226 int ret, temp; 228 227 229 - ret = strtobool(buf, &sys_calib); 228 + ret = kstrtobool(buf, &sys_calib); 230 229 if (ret) 231 230 return ret; 232 231 ··· 289 288 return ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode); 290 289 } 291 290 291 + static int ad7192_append_status(struct ad_sigma_delta *sd, bool append) 292 + { 293 + struct ad7192_state *st = ad_sigma_delta_to_ad7192(sd); 294 + unsigned int mode = st->mode; 295 + int ret; 296 + 297 + mode &= ~AD7192_MODE_STA_MASK; 298 + mode |= AD7192_MODE_STA(append); 299 + 300 + ret = ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, mode); 301 + if (ret < 0) 302 + return ret; 303 + 304 + st->mode = mode; 305 + 306 + return 0; 307 + } 308 + 309 + static int ad7192_disable_all(struct ad_sigma_delta *sd) 310 + { 311 + struct ad7192_state *st = ad_sigma_delta_to_ad7192(sd); 312 + u32 conf = st->conf; 313 + int ret; 314 + 315 + conf &= ~AD7192_CONF_CHAN_MASK; 316 + 317 + ret = ad_sd_write_reg(&st->sd, AD7192_REG_CONF, 3, conf); 318 + if (ret < 0) 319 + return ret; 320 + 321 + st->conf = conf; 322 + 323 + return 0; 324 + } 325 + 292 326 static const struct ad_sigma_delta_info ad7192_sigma_delta_info = { 293 327 .set_channel = ad7192_set_channel, 328 + .append_status = ad7192_append_status, 329 + .disable_all = ad7192_disable_all, 294 330 .set_mode = ad7192_set_mode, 295 331 .has_registers = true, 296 332 .addr_shift = 3, 297 333 .read_mask = BIT(6), 334 + .status_ch_mask = GENMASK(3, 0), 335 + .num_slots = 4, 298 336 .irq_flags = IRQF_TRIGGER_FALLING, 299 337 }; 300 338 ··· 497 457 int ret; 498 458 bool val; 499 459 500 - ret = strtobool(buf, &val); 460 + ret = kstrtobool(buf, &val); 501 461 if (ret < 0) 502 462 return ret; 503 463 ··· 823 783 return -EINVAL; 824 784 } 825 785 786 + static int ad7192_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask) 787 + { 788 + struct ad7192_state *st = iio_priv(indio_dev); 789 + u32 conf = st->conf; 790 + int ret; 791 + int i; 792 + 793 + conf &= ~AD7192_CONF_CHAN_MASK; 794 + for_each_set_bit(i, scan_mask, 8) 795 + conf |= AD7192_CONF_CHAN(i); 796 + 797 + ret = ad_sd_write_reg(&st->sd, AD7192_REG_CONF, 3, conf); 798 + if (ret < 0) 799 + return ret; 800 + 801 + st->conf = conf; 802 + 803 + return 0; 804 + } 805 + 826 806 static const struct iio_info ad7192_info = { 827 807 .read_raw = ad7192_read_raw, 828 808 .write_raw = ad7192_write_raw, ··· 850 790 .read_avail = ad7192_read_avail, 851 791 .attrs = &ad7192_attribute_group, 852 792 .validate_trigger = ad_sd_validate_trigger, 793 + .update_scan_mode = ad7192_update_scan_mode, 853 794 }; 854 795 855 796 static const struct iio_info ad7195_info = { ··· 860 799 .read_avail = ad7192_read_avail, 861 800 .attrs = &ad7195_attribute_group, 862 801 .validate_trigger = ad_sd_validate_trigger, 802 + .update_scan_mode = ad7192_update_scan_mode, 863 803 }; 864 804 865 805 #define __AD719x_CHANNEL(_si, _channel1, _channel2, _address, _extend_name, \
+14 -30
drivers/iio/adc/ad7266.c
··· 378 378 "ad0", "ad1", "ad2", 379 379 }; 380 380 381 + static void ad7266_reg_disable(void *reg) 382 + { 383 + regulator_disable(reg); 384 + } 385 + 381 386 static int ad7266_probe(struct spi_device *spi) 382 387 { 383 388 struct ad7266_platform_data *pdata = spi->dev.platform_data; ··· 403 398 if (ret) 404 399 return ret; 405 400 401 + ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg); 402 + if (ret) 403 + return ret; 404 + 406 405 ret = regulator_get_voltage(st->reg); 407 406 if (ret < 0) 408 - goto error_disable_reg; 407 + return ret; 409 408 410 409 st->vref_mv = ret / 1000; 411 410 } else { ··· 432 423 GPIOD_OUT_LOW); 433 424 if (IS_ERR(st->gpios[i])) { 434 425 ret = PTR_ERR(st->gpios[i]); 435 - goto error_disable_reg; 426 + return ret; 436 427 } 437 428 } 438 429 } ··· 442 433 st->mode = AD7266_MODE_DIFF; 443 434 } 444 435 445 - spi_set_drvdata(spi, indio_dev); 446 436 st->spi = spi; 447 437 448 438 indio_dev->name = spi_get_device_id(spi)->name; ··· 467 459 spi_message_add_tail(&st->single_xfer[1], &st->single_msg); 468 460 spi_message_add_tail(&st->single_xfer[2], &st->single_msg); 469 461 470 - ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, 462 + ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, &iio_pollfunc_store_time, 471 463 &ad7266_trigger_handler, &iio_triggered_buffer_setup_ops); 472 464 if (ret) 473 - goto error_disable_reg; 465 + return ret; 474 466 475 - ret = iio_device_register(indio_dev); 476 - if (ret) 477 - goto error_buffer_cleanup; 478 - 479 - return 0; 480 - 481 - error_buffer_cleanup: 482 - iio_triggered_buffer_cleanup(indio_dev); 483 - error_disable_reg: 484 - if (!IS_ERR(st->reg)) 485 - regulator_disable(st->reg); 486 - 487 - return ret; 488 - } 489 - 490 - static void ad7266_remove(struct spi_device *spi) 491 - { 492 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 493 - struct ad7266_state *st = iio_priv(indio_dev); 494 - 495 - iio_device_unregister(indio_dev); 496 - iio_triggered_buffer_cleanup(indio_dev); 497 - if (!IS_ERR(st->reg)) 498 - regulator_disable(st->reg); 467 + return devm_iio_device_register(&spi->dev, indio_dev); 499 468 } 500 469 501 470 static const struct spi_device_id ad7266_id[] = { ··· 487 502 .name = "ad7266", 488 503 }, 489 504 .probe = ad7266_probe, 490 - .remove = ad7266_remove, 491 505 .id_table = ad7266_id, 492 506 }; 493 507 module_spi_driver(ad7266_driver);
+1 -1
drivers/iio/adc/ad7280a.c
··· 488 488 bool readin; 489 489 int ret; 490 490 491 - ret = strtobool(buf, &readin); 491 + ret = kstrtobool(buf, &readin); 492 492 if (ret) 493 493 return ret; 494 494
+133 -10
drivers/iio/adc/ad_sigma_delta.c
··· 6 6 * Author: Lars-Peter Clausen <lars@metafoo.de> 7 7 */ 8 8 9 + #include <linux/align.h> 9 10 #include <linux/interrupt.h> 10 11 #include <linux/device.h> 11 12 #include <linux/kernel.h> ··· 343 342 static int ad_sd_buffer_postenable(struct iio_dev *indio_dev) 344 343 { 345 344 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); 345 + unsigned int i, slot, samples_buf_size; 346 346 unsigned int channel; 347 + uint8_t *samples_buf; 347 348 int ret; 348 349 349 - channel = find_first_bit(indio_dev->active_scan_mask, 350 - indio_dev->masklength); 351 - ret = ad_sigma_delta_set_channel(sigma_delta, 352 - indio_dev->channels[channel].address); 353 - if (ret) 354 - return ret; 350 + if (sigma_delta->num_slots == 1) { 351 + channel = find_first_bit(indio_dev->active_scan_mask, 352 + indio_dev->masklength); 353 + ret = ad_sigma_delta_set_channel(sigma_delta, 354 + indio_dev->channels[channel].address); 355 + if (ret) 356 + return ret; 357 + slot = 1; 358 + } else { 359 + /* 360 + * At this point update_scan_mode already enabled the required channels. 361 + * For sigma-delta sequencer drivers with multiple slots, an update_scan_mode 362 + * implementation is mandatory. 363 + */ 364 + slot = 0; 365 + for_each_set_bit(i, indio_dev->active_scan_mask, indio_dev->masklength) { 366 + sigma_delta->slots[slot] = indio_dev->channels[i].address; 367 + slot++; 368 + } 369 + } 370 + 371 + sigma_delta->active_slots = slot; 372 + sigma_delta->current_slot = 0; 373 + 374 + if (sigma_delta->active_slots > 1) { 375 + ret = ad_sigma_delta_append_status(sigma_delta, true); 376 + if (ret) 377 + return ret; 378 + } 379 + 380 + samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits, 8); 381 + samples_buf_size += sizeof(int64_t); 382 + samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf, 383 + samples_buf_size, GFP_KERNEL); 384 + if (!samples_buf) 385 + return -ENOMEM; 386 + 387 + sigma_delta->samples_buf = samples_buf; 355 388 356 389 spi_bus_lock(sigma_delta->spi->master); 357 390 sigma_delta->bus_locked = true; ··· 421 386 sigma_delta->keep_cs_asserted = false; 422 387 ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE); 423 388 389 + if (sigma_delta->status_appended) 390 + ad_sigma_delta_append_status(sigma_delta, false); 391 + 392 + ad_sigma_delta_disable_all(sigma_delta); 424 393 sigma_delta->bus_locked = false; 425 394 return spi_bus_unlock(sigma_delta->spi->master); 426 395 } ··· 435 396 struct iio_dev *indio_dev = pf->indio_dev; 436 397 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); 437 398 uint8_t *data = sigma_delta->rx_buf; 399 + unsigned int transfer_size; 400 + unsigned int sample_size; 401 + unsigned int sample_pos; 402 + unsigned int status_pos; 438 403 unsigned int reg_size; 439 404 unsigned int data_reg; 440 405 ··· 451 408 else 452 409 data_reg = AD_SD_REG_DATA; 453 410 411 + /* Status word will be appended to the sample during transfer */ 412 + if (sigma_delta->status_appended) 413 + transfer_size = reg_size + 1; 414 + else 415 + transfer_size = reg_size; 416 + 454 417 switch (reg_size) { 455 418 case 4: 456 419 case 2: 457 420 case 1: 458 - ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size, &data[0]); 421 + status_pos = reg_size; 422 + ad_sd_read_reg_raw(sigma_delta, data_reg, transfer_size, &data[0]); 459 423 break; 460 424 case 3: 425 + /* 426 + * Data array after transfer will look like (if status is appended): 427 + * data[] = { [0][sample][sample][sample][status] } 428 + * Keeping the first byte 0 shifts the status postion by 1 byte to the right. 429 + */ 430 + status_pos = reg_size + 1; 431 + 461 432 /* We store 24 bit samples in a 32 bit word. Keep the upper 462 433 * byte set to zero. */ 463 - ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size, &data[1]); 434 + ad_sd_read_reg_raw(sigma_delta, data_reg, transfer_size, &data[1]); 464 435 break; 465 436 } 466 437 467 - iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp); 438 + /* 439 + * For devices sampling only one channel at 440 + * once, there is no need for sample number tracking. 441 + */ 442 + if (sigma_delta->active_slots == 1) { 443 + iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp); 444 + goto irq_handled; 445 + } 468 446 447 + if (sigma_delta->status_appended) { 448 + u8 converted_channel; 449 + 450 + converted_channel = data[status_pos] & sigma_delta->info->status_ch_mask; 451 + if (converted_channel != sigma_delta->slots[sigma_delta->current_slot]) { 452 + /* 453 + * Desync occurred during continuous sampling of multiple channels. 454 + * Drop this incomplete sample and start from first channel again. 455 + */ 456 + 457 + sigma_delta->current_slot = 0; 458 + goto irq_handled; 459 + } 460 + } 461 + 462 + sample_size = indio_dev->channels[0].scan_type.storagebits / 8; 463 + sample_pos = sample_size * sigma_delta->current_slot; 464 + memcpy(&sigma_delta->samples_buf[sample_pos], data, sample_size); 465 + sigma_delta->current_slot++; 466 + 467 + if (sigma_delta->current_slot == sigma_delta->active_slots) { 468 + sigma_delta->current_slot = 0; 469 + iio_push_to_buffers_with_timestamp(indio_dev, sigma_delta->samples_buf, 470 + pf->timestamp); 471 + } 472 + 473 + irq_handled: 469 474 iio_trigger_notify_done(indio_dev->trig); 470 475 sigma_delta->irq_dis = false; 471 476 enable_irq(sigma_delta->spi->irq); ··· 521 430 return IRQ_HANDLED; 522 431 } 523 432 433 + static bool ad_sd_validate_scan_mask(struct iio_dev *indio_dev, const unsigned long *mask) 434 + { 435 + struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); 436 + 437 + return bitmap_weight(mask, indio_dev->masklength) <= sigma_delta->num_slots; 438 + } 439 + 524 440 static const struct iio_buffer_setup_ops ad_sd_buffer_setup_ops = { 525 441 .postenable = &ad_sd_buffer_postenable, 526 442 .postdisable = &ad_sd_buffer_postdisable, 527 - .validate_scan_mask = &iio_validate_scan_mask_onehot, 443 + .validate_scan_mask = &ad_sd_validate_scan_mask, 528 444 }; 529 445 530 446 static irqreturn_t ad_sd_data_rdy_trig_poll(int irq, void *private) ··· 611 513 */ 612 514 int devm_ad_sd_setup_buffer_and_trigger(struct device *dev, struct iio_dev *indio_dev) 613 515 { 516 + struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); 614 517 int ret; 518 + 519 + sigma_delta->slots = devm_kcalloc(dev, sigma_delta->num_slots, 520 + sizeof(*sigma_delta->slots), GFP_KERNEL); 521 + if (!sigma_delta->slots) 522 + return -ENOMEM; 615 523 616 524 ret = devm_iio_triggered_buffer_setup(dev, indio_dev, 617 525 &iio_pollfunc_store_time, ··· 645 541 { 646 542 sigma_delta->spi = spi; 647 543 sigma_delta->info = info; 544 + 545 + /* If the field is unset in ad_sigma_delta_info, asume there can only be 1 slot. */ 546 + if (!info->num_slots) 547 + sigma_delta->num_slots = 1; 548 + else 549 + sigma_delta->num_slots = info->num_slots; 550 + 551 + if (sigma_delta->num_slots > 1) { 552 + if (!indio_dev->info->update_scan_mode) { 553 + dev_err(&spi->dev, "iio_dev lacks update_scan_mode().\n"); 554 + return -EINVAL; 555 + } 556 + 557 + if (!info->disable_all) { 558 + dev_err(&spi->dev, "ad_sigma_delta_info lacks disable_all().\n"); 559 + return -EINVAL; 560 + } 561 + } 562 + 648 563 iio_device_set_drvdata(indio_dev, sigma_delta); 649 564 650 565 return 0;
+2 -2
drivers/iio/adc/at91-sama5d2_adc.c
··· 1117 1117 return at91_adc_configure_touch(st, true); 1118 1118 1119 1119 /* if we are not in triggered mode, we cannot enable the buffer. */ 1120 - if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES)) 1120 + if (!(iio_device_get_current_mode(indio_dev) & INDIO_ALL_TRIGGERED_MODES)) 1121 1121 return -EINVAL; 1122 1122 1123 1123 /* we continue with the triggered buffer */ ··· 1159 1159 return at91_adc_configure_touch(st, false); 1160 1160 1161 1161 /* if we are not in triggered mode, nothing to do here */ 1162 - if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES)) 1162 + if (!(iio_device_get_current_mode(indio_dev) & INDIO_ALL_TRIGGERED_MODES)) 1163 1163 return -EINVAL; 1164 1164 1165 1165 /*
+1 -2
drivers/iio/adc/ina2xx-adc.c
··· 550 550 bool val; 551 551 int ret; 552 552 553 - ret = strtobool(buf, &val); 553 + ret = kstrtobool(buf, &val); 554 554 if (ret) 555 555 return ret; 556 556 ··· 1027 1027 indio_dev->name = id->name; 1028 1028 1029 1029 ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev, 1030 - INDIO_BUFFER_SOFTWARE, 1031 1030 &ina2xx_setup_ops); 1032 1031 if (ret) 1033 1032 return ret;
+2 -1
drivers/iio/adc/palmas_gpadc.c
··· 376 376 adc->adc_info[adc_chan].gain_error; 377 377 378 378 if (val < 0) { 379 - dev_err(adc->dev, "Mismatch with calibration\n"); 379 + if (val < -10) 380 + dev_err(adc->dev, "Mismatch with calibration var = %d\n", val); 380 381 return 0; 381 382 } 382 383
+438 -38
drivers/iio/adc/sc27xx_adc.c
··· 9 9 #include <linux/of_device.h> 10 10 #include <linux/platform_device.h> 11 11 #include <linux/regmap.h> 12 + #include <linux/regulator/consumer.h> 12 13 #include <linux/slab.h> 13 14 14 15 /* PMIC global registers definition */ 15 - #define SC27XX_MODULE_EN 0xc08 16 + #define SC2730_MODULE_EN 0x1808 17 + #define SC2731_MODULE_EN 0xc08 16 18 #define SC27XX_MODULE_ADC_EN BIT(5) 17 - #define SC27XX_ARM_CLK_EN 0xc10 19 + #define SC2721_ARM_CLK_EN 0xc0c 20 + #define SC2730_ARM_CLK_EN 0x180c 21 + #define SC2731_ARM_CLK_EN 0xc10 18 22 #define SC27XX_CLK_ADC_EN BIT(5) 19 23 #define SC27XX_CLK_ADC_CLK_EN BIT(6) 20 24 ··· 40 36 41 37 /* Bits and mask definition for SC27XX_ADC_CH_CFG register */ 42 38 #define SC27XX_ADC_CHN_ID_MASK GENMASK(4, 0) 43 - #define SC27XX_ADC_SCALE_MASK GENMASK(10, 8) 44 - #define SC27XX_ADC_SCALE_SHIFT 8 39 + #define SC27XX_ADC_SCALE_MASK GENMASK(10, 9) 40 + #define SC2721_ADC_SCALE_MASK BIT(5) 41 + #define SC27XX_ADC_SCALE_SHIFT 9 42 + #define SC2721_ADC_SCALE_SHIFT 5 45 43 46 44 /* Bits definitions for SC27XX_ADC_INT_EN registers */ 47 45 #define SC27XX_ADC_IRQ_EN BIT(0) ··· 73 67 #define SC27XX_RATIO_NUMERATOR_OFFSET 16 74 68 #define SC27XX_RATIO_DENOMINATOR_MASK GENMASK(15, 0) 75 69 70 + /* ADC specific channel reference voltage 3.5V */ 71 + #define SC27XX_ADC_REFVOL_VDD35 3500000 72 + 73 + /* ADC default channel reference voltage is 2.8V */ 74 + #define SC27XX_ADC_REFVOL_VDD28 2800000 75 + 76 76 struct sc27xx_adc_data { 77 77 struct device *dev; 78 + struct regulator *volref; 78 79 struct regmap *regmap; 79 80 /* 80 81 * One hardware spinlock to synchronize between the multiple ··· 91 78 int channel_scale[SC27XX_ADC_CHANNEL_MAX]; 92 79 u32 base; 93 80 int irq; 81 + const struct sc27xx_adc_variant_data *var_data; 82 + }; 83 + 84 + /* 85 + * Since different PMICs of SC27xx series can have different 86 + * address and ratio, we should save ratio config and base 87 + * in the device data structure. 88 + */ 89 + struct sc27xx_adc_variant_data { 90 + u32 module_en; 91 + u32 clk_en; 92 + u32 scale_shift; 93 + u32 scale_mask; 94 + const struct sc27xx_adc_linear_graph *bscale_cal; 95 + const struct sc27xx_adc_linear_graph *sscale_cal; 96 + void (*init_scale)(struct sc27xx_adc_data *data); 97 + int (*get_ratio)(int channel, int scale); 98 + bool set_volref; 94 99 }; 95 100 96 101 struct sc27xx_adc_linear_graph { ··· 134 103 100, 341, 135 104 }; 136 105 106 + static const struct sc27xx_adc_linear_graph sc2731_big_scale_graph_calib = { 107 + 4200, 850, 108 + 3600, 728, 109 + }; 110 + 111 + static const struct sc27xx_adc_linear_graph sc2731_small_scale_graph_calib = { 112 + 1000, 838, 113 + 100, 84, 114 + }; 115 + 137 116 static const struct sc27xx_adc_linear_graph big_scale_graph_calib = { 138 117 4200, 856, 139 118 3600, 733, ··· 159 118 return ((calib_data & 0xff) + calib_adc - 128) * 4; 160 119 } 161 120 162 - static int sc27xx_adc_scale_calibration(struct sc27xx_adc_data *data, 163 - bool big_scale) 121 + /* get the adc nvmem cell calibration data */ 122 + static int adc_nvmem_cell_calib_data(struct sc27xx_adc_data *data, const char *cell_name) 164 123 { 165 - const struct sc27xx_adc_linear_graph *calib_graph; 166 - struct sc27xx_adc_linear_graph *graph; 167 124 struct nvmem_cell *cell; 168 - const char *cell_name; 169 - u32 calib_data = 0; 170 125 void *buf; 126 + u32 origin_calib_data = 0; 171 127 size_t len; 172 128 173 - if (big_scale) { 174 - calib_graph = &big_scale_graph_calib; 175 - graph = &big_scale_graph; 176 - cell_name = "big_scale_calib"; 177 - } else { 178 - calib_graph = &small_scale_graph_calib; 179 - graph = &small_scale_graph; 180 - cell_name = "small_scale_calib"; 181 - } 129 + if (!data) 130 + return -EINVAL; 182 131 183 132 cell = nvmem_cell_get(data->dev, cell_name); 184 133 if (IS_ERR(cell)) 185 134 return PTR_ERR(cell); 186 135 187 136 buf = nvmem_cell_read(cell, &len); 188 - nvmem_cell_put(cell); 189 - 190 - if (IS_ERR(buf)) 137 + if (IS_ERR(buf)) { 138 + nvmem_cell_put(cell); 191 139 return PTR_ERR(buf); 140 + } 192 141 193 - memcpy(&calib_data, buf, min(len, sizeof(u32))); 142 + memcpy(&origin_calib_data, buf, min(len, sizeof(u32))); 143 + 144 + kfree(buf); 145 + nvmem_cell_put(cell); 146 + return origin_calib_data; 147 + } 148 + 149 + static int sc27xx_adc_scale_calibration(struct sc27xx_adc_data *data, 150 + bool big_scale) 151 + { 152 + const struct sc27xx_adc_linear_graph *calib_graph; 153 + struct sc27xx_adc_linear_graph *graph; 154 + const char *cell_name; 155 + u32 calib_data = 0; 156 + 157 + if (big_scale) { 158 + calib_graph = data->var_data->bscale_cal; 159 + graph = &big_scale_graph; 160 + cell_name = "big_scale_calib"; 161 + } else { 162 + calib_graph = data->var_data->sscale_cal; 163 + graph = &small_scale_graph; 164 + cell_name = "small_scale_calib"; 165 + } 166 + 167 + calib_data = adc_nvmem_cell_calib_data(data, cell_name); 194 168 195 169 /* Only need to calibrate the adc values in the linear graph. */ 196 170 graph->adc0 = sc27xx_adc_get_calib_data(calib_data, calib_graph->adc0); 197 171 graph->adc1 = sc27xx_adc_get_calib_data(calib_data >> 8, 198 172 calib_graph->adc1); 199 173 200 - kfree(buf); 201 174 return 0; 202 175 } 203 176 204 - static int sc27xx_adc_get_ratio(int channel, int scale) 177 + static int sc2720_adc_get_ratio(int channel, int scale) 178 + { 179 + switch (channel) { 180 + case 14: 181 + switch (scale) { 182 + case 0: 183 + return SC27XX_VOLT_RATIO(68, 900); 184 + case 1: 185 + return SC27XX_VOLT_RATIO(68, 1760); 186 + case 2: 187 + return SC27XX_VOLT_RATIO(68, 2327); 188 + case 3: 189 + return SC27XX_VOLT_RATIO(68, 3654); 190 + default: 191 + return SC27XX_VOLT_RATIO(1, 1); 192 + } 193 + case 16: 194 + switch (scale) { 195 + case 0: 196 + return SC27XX_VOLT_RATIO(48, 100); 197 + case 1: 198 + return SC27XX_VOLT_RATIO(480, 1955); 199 + case 2: 200 + return SC27XX_VOLT_RATIO(480, 2586); 201 + case 3: 202 + return SC27XX_VOLT_RATIO(48, 406); 203 + default: 204 + return SC27XX_VOLT_RATIO(1, 1); 205 + } 206 + case 21: 207 + case 22: 208 + case 23: 209 + switch (scale) { 210 + case 0: 211 + return SC27XX_VOLT_RATIO(3, 8); 212 + case 1: 213 + return SC27XX_VOLT_RATIO(375, 1955); 214 + case 2: 215 + return SC27XX_VOLT_RATIO(375, 2586); 216 + case 3: 217 + return SC27XX_VOLT_RATIO(300, 3248); 218 + default: 219 + return SC27XX_VOLT_RATIO(1, 1); 220 + } 221 + default: 222 + switch (scale) { 223 + case 0: 224 + return SC27XX_VOLT_RATIO(1, 1); 225 + case 1: 226 + return SC27XX_VOLT_RATIO(1000, 1955); 227 + case 2: 228 + return SC27XX_VOLT_RATIO(1000, 2586); 229 + case 3: 230 + return SC27XX_VOLT_RATIO(100, 406); 231 + default: 232 + return SC27XX_VOLT_RATIO(1, 1); 233 + } 234 + } 235 + return SC27XX_VOLT_RATIO(1, 1); 236 + } 237 + 238 + static int sc2721_adc_get_ratio(int channel, int scale) 239 + { 240 + switch (channel) { 241 + case 1: 242 + case 2: 243 + case 3: 244 + case 4: 245 + return scale ? SC27XX_VOLT_RATIO(400, 1025) : 246 + SC27XX_VOLT_RATIO(1, 1); 247 + case 5: 248 + return SC27XX_VOLT_RATIO(7, 29); 249 + case 7: 250 + case 9: 251 + return scale ? SC27XX_VOLT_RATIO(100, 125) : 252 + SC27XX_VOLT_RATIO(1, 1); 253 + case 14: 254 + return SC27XX_VOLT_RATIO(68, 900); 255 + case 16: 256 + return SC27XX_VOLT_RATIO(48, 100); 257 + case 19: 258 + return SC27XX_VOLT_RATIO(1, 3); 259 + default: 260 + return SC27XX_VOLT_RATIO(1, 1); 261 + } 262 + return SC27XX_VOLT_RATIO(1, 1); 263 + } 264 + 265 + static int sc2730_adc_get_ratio(int channel, int scale) 266 + { 267 + switch (channel) { 268 + case 14: 269 + switch (scale) { 270 + case 0: 271 + return SC27XX_VOLT_RATIO(68, 900); 272 + case 1: 273 + return SC27XX_VOLT_RATIO(68, 1760); 274 + case 2: 275 + return SC27XX_VOLT_RATIO(68, 2327); 276 + case 3: 277 + return SC27XX_VOLT_RATIO(68, 3654); 278 + default: 279 + return SC27XX_VOLT_RATIO(1, 1); 280 + } 281 + case 15: 282 + switch (scale) { 283 + case 0: 284 + return SC27XX_VOLT_RATIO(1, 3); 285 + case 1: 286 + return SC27XX_VOLT_RATIO(1000, 5865); 287 + case 2: 288 + return SC27XX_VOLT_RATIO(500, 3879); 289 + case 3: 290 + return SC27XX_VOLT_RATIO(500, 6090); 291 + default: 292 + return SC27XX_VOLT_RATIO(1, 1); 293 + } 294 + case 16: 295 + switch (scale) { 296 + case 0: 297 + return SC27XX_VOLT_RATIO(48, 100); 298 + case 1: 299 + return SC27XX_VOLT_RATIO(480, 1955); 300 + case 2: 301 + return SC27XX_VOLT_RATIO(480, 2586); 302 + case 3: 303 + return SC27XX_VOLT_RATIO(48, 406); 304 + default: 305 + return SC27XX_VOLT_RATIO(1, 1); 306 + } 307 + case 21: 308 + case 22: 309 + case 23: 310 + switch (scale) { 311 + case 0: 312 + return SC27XX_VOLT_RATIO(3, 8); 313 + case 1: 314 + return SC27XX_VOLT_RATIO(375, 1955); 315 + case 2: 316 + return SC27XX_VOLT_RATIO(375, 2586); 317 + case 3: 318 + return SC27XX_VOLT_RATIO(300, 3248); 319 + default: 320 + return SC27XX_VOLT_RATIO(1, 1); 321 + } 322 + default: 323 + switch (scale) { 324 + case 0: 325 + return SC27XX_VOLT_RATIO(1, 1); 326 + case 1: 327 + return SC27XX_VOLT_RATIO(1000, 1955); 328 + case 2: 329 + return SC27XX_VOLT_RATIO(1000, 2586); 330 + case 3: 331 + return SC27XX_VOLT_RATIO(1000, 4060); 332 + default: 333 + return SC27XX_VOLT_RATIO(1, 1); 334 + } 335 + } 336 + return SC27XX_VOLT_RATIO(1, 1); 337 + } 338 + 339 + static int sc2731_adc_get_ratio(int channel, int scale) 205 340 { 206 341 switch (channel) { 207 342 case 1: ··· 402 185 return SC27XX_VOLT_RATIO(1, 1); 403 186 } 404 187 188 + /* 189 + * According to the datasheet set specific value on some channel. 190 + */ 191 + static void sc2720_adc_scale_init(struct sc27xx_adc_data *data) 192 + { 193 + int i; 194 + 195 + for (i = 0; i < SC27XX_ADC_CHANNEL_MAX; i++) { 196 + switch (i) { 197 + case 5: 198 + data->channel_scale[i] = 3; 199 + break; 200 + case 7: 201 + case 9: 202 + data->channel_scale[i] = 2; 203 + break; 204 + case 13: 205 + data->channel_scale[i] = 1; 206 + break; 207 + case 19: 208 + case 30: 209 + case 31: 210 + data->channel_scale[i] = 3; 211 + break; 212 + default: 213 + data->channel_scale[i] = 0; 214 + break; 215 + } 216 + } 217 + } 218 + 219 + static void sc2730_adc_scale_init(struct sc27xx_adc_data *data) 220 + { 221 + int i; 222 + 223 + for (i = 0; i < SC27XX_ADC_CHANNEL_MAX; i++) { 224 + switch (i) { 225 + case 5: 226 + case 10: 227 + case 19: 228 + case 30: 229 + case 31: 230 + data->channel_scale[i] = 3; 231 + break; 232 + case 7: 233 + case 9: 234 + data->channel_scale[i] = 2; 235 + break; 236 + case 13: 237 + data->channel_scale[i] = 1; 238 + break; 239 + default: 240 + data->channel_scale[i] = 0; 241 + break; 242 + } 243 + } 244 + } 245 + 246 + static void sc2731_adc_scale_init(struct sc27xx_adc_data *data) 247 + { 248 + int i; 249 + /* 250 + * In the current software design, SC2731 support 2 scales, 251 + * channels 5 uses big scale, others use smale. 252 + */ 253 + for (i = 0; i < SC27XX_ADC_CHANNEL_MAX; i++) { 254 + switch (i) { 255 + case 5: 256 + data->channel_scale[i] = 1; 257 + break; 258 + default: 259 + data->channel_scale[i] = 0; 260 + break; 261 + } 262 + } 263 + } 264 + 405 265 static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel, 406 266 int scale, int *val) 407 267 { 408 - int ret; 268 + int ret, ret_volref; 409 269 u32 tmp, value, status; 410 270 411 271 ret = hwspin_lock_timeout_raw(data->hwlock, SC27XX_ADC_HWLOCK_TIMEOUT); ··· 491 197 return ret; 492 198 } 493 199 200 + /* 201 + * According to the sc2721 chip data sheet, the reference voltage of 202 + * specific channel 30 and channel 31 in ADC module needs to be set from 203 + * the default 2.8v to 3.5v. 204 + */ 205 + if ((data->var_data->set_volref) && (channel == 30 || channel == 31)) { 206 + ret = regulator_set_voltage(data->volref, 207 + SC27XX_ADC_REFVOL_VDD35, 208 + SC27XX_ADC_REFVOL_VDD35); 209 + if (ret) { 210 + dev_err(data->dev, "failed to set the volref 3.5v\n"); 211 + goto unlock_adc; 212 + } 213 + } 214 + 494 215 ret = regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CTL, 495 216 SC27XX_ADC_EN, SC27XX_ADC_EN); 496 217 if (ret) 497 - goto unlock_adc; 218 + goto regulator_restore; 498 219 499 220 ret = regmap_update_bits(data->regmap, data->base + SC27XX_ADC_INT_CLR, 500 221 SC27XX_ADC_IRQ_CLR, SC27XX_ADC_IRQ_CLR); ··· 517 208 goto disable_adc; 518 209 519 210 /* Configure the channel id and scale */ 520 - tmp = (scale << SC27XX_ADC_SCALE_SHIFT) & SC27XX_ADC_SCALE_MASK; 211 + tmp = (scale << data->var_data->scale_shift) & data->var_data->scale_mask; 521 212 tmp |= channel & SC27XX_ADC_CHN_ID_MASK; 522 213 ret = regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CH_CFG, 523 - SC27XX_ADC_CHN_ID_MASK | SC27XX_ADC_SCALE_MASK, 214 + SC27XX_ADC_CHN_ID_MASK | 215 + data->var_data->scale_mask, 524 216 tmp); 525 217 if (ret) 526 218 goto disable_adc; ··· 559 249 disable_adc: 560 250 regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CTL, 561 251 SC27XX_ADC_EN, 0); 252 + regulator_restore: 253 + if ((data->var_data->set_volref) && (channel == 30 || channel == 31)) { 254 + ret_volref = regulator_set_voltage(data->volref, 255 + SC27XX_ADC_REFVOL_VDD28, 256 + SC27XX_ADC_REFVOL_VDD28); 257 + if (ret_volref) { 258 + dev_err(data->dev, "failed to set the volref 2.8v,ret_volref = 0x%x\n", 259 + ret_volref); 260 + ret = ret || ret_volref; 261 + } 262 + } 562 263 unlock_adc: 563 264 hwspin_unlock_raw(data->hwlock); 564 265 ··· 583 262 int channel, int scale, 584 263 u32 *div_numerator, u32 *div_denominator) 585 264 { 586 - u32 ratio = sc27xx_adc_get_ratio(channel, scale); 265 + u32 ratio; 587 266 267 + ratio = data->var_data->get_ratio(channel, scale); 588 268 *div_numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET; 589 269 *div_denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK; 590 270 } 591 271 592 - static int sc27xx_adc_to_volt(struct sc27xx_adc_linear_graph *graph, 272 + static int adc_to_volt(struct sc27xx_adc_linear_graph *graph, 593 273 int raw_adc) 594 274 { 595 275 int tmp; ··· 598 276 tmp = (graph->volt0 - graph->volt1) * (raw_adc - graph->adc1); 599 277 tmp /= (graph->adc0 - graph->adc1); 600 278 tmp += graph->volt1; 279 + 280 + return tmp; 281 + } 282 + 283 + static int sc27xx_adc_to_volt(struct sc27xx_adc_linear_graph *graph, 284 + int raw_adc) 285 + { 286 + int tmp; 287 + 288 + tmp = adc_to_volt(graph, raw_adc); 601 289 602 290 return tmp < 0 ? 0 : tmp; 603 291 } ··· 764 432 { 765 433 int ret; 766 434 767 - ret = regmap_update_bits(data->regmap, SC27XX_MODULE_EN, 435 + ret = regmap_update_bits(data->regmap, data->var_data->module_en, 768 436 SC27XX_MODULE_ADC_EN, SC27XX_MODULE_ADC_EN); 769 437 if (ret) 770 438 return ret; 771 439 772 440 /* Enable ADC work clock and controller clock */ 773 - ret = regmap_update_bits(data->regmap, SC27XX_ARM_CLK_EN, 441 + ret = regmap_update_bits(data->regmap, data->var_data->clk_en, 774 442 SC27XX_CLK_ADC_EN | SC27XX_CLK_ADC_CLK_EN, 775 443 SC27XX_CLK_ADC_EN | SC27XX_CLK_ADC_CLK_EN); 776 444 if (ret) ··· 788 456 return 0; 789 457 790 458 disable_clk: 791 - regmap_update_bits(data->regmap, SC27XX_ARM_CLK_EN, 459 + regmap_update_bits(data->regmap, data->var_data->clk_en, 792 460 SC27XX_CLK_ADC_EN | SC27XX_CLK_ADC_CLK_EN, 0); 793 461 disable_adc: 794 - regmap_update_bits(data->regmap, SC27XX_MODULE_EN, 462 + regmap_update_bits(data->regmap, data->var_data->module_en, 795 463 SC27XX_MODULE_ADC_EN, 0); 796 464 797 465 return ret; ··· 802 470 struct sc27xx_adc_data *data = _data; 803 471 804 472 /* Disable ADC work clock and controller clock */ 805 - regmap_update_bits(data->regmap, SC27XX_ARM_CLK_EN, 473 + regmap_update_bits(data->regmap, data->var_data->clk_en, 806 474 SC27XX_CLK_ADC_EN | SC27XX_CLK_ADC_CLK_EN, 0); 807 475 808 - regmap_update_bits(data->regmap, SC27XX_MODULE_EN, 476 + regmap_update_bits(data->regmap, data->var_data->module_en, 809 477 SC27XX_MODULE_ADC_EN, 0); 810 478 } 479 + 480 + static const struct sc27xx_adc_variant_data sc2731_data = { 481 + .module_en = SC2731_MODULE_EN, 482 + .clk_en = SC2731_ARM_CLK_EN, 483 + .scale_shift = SC27XX_ADC_SCALE_SHIFT, 484 + .scale_mask = SC27XX_ADC_SCALE_MASK, 485 + .bscale_cal = &sc2731_big_scale_graph_calib, 486 + .sscale_cal = &sc2731_small_scale_graph_calib, 487 + .init_scale = sc2731_adc_scale_init, 488 + .get_ratio = sc2731_adc_get_ratio, 489 + .set_volref = false, 490 + }; 491 + 492 + static const struct sc27xx_adc_variant_data sc2730_data = { 493 + .module_en = SC2730_MODULE_EN, 494 + .clk_en = SC2730_ARM_CLK_EN, 495 + .scale_shift = SC27XX_ADC_SCALE_SHIFT, 496 + .scale_mask = SC27XX_ADC_SCALE_MASK, 497 + .bscale_cal = &big_scale_graph_calib, 498 + .sscale_cal = &small_scale_graph_calib, 499 + .init_scale = sc2730_adc_scale_init, 500 + .get_ratio = sc2730_adc_get_ratio, 501 + .set_volref = false, 502 + }; 503 + 504 + static const struct sc27xx_adc_variant_data sc2721_data = { 505 + .module_en = SC2731_MODULE_EN, 506 + .clk_en = SC2721_ARM_CLK_EN, 507 + .scale_shift = SC2721_ADC_SCALE_SHIFT, 508 + .scale_mask = SC2721_ADC_SCALE_MASK, 509 + .bscale_cal = &sc2731_big_scale_graph_calib, 510 + .sscale_cal = &sc2731_small_scale_graph_calib, 511 + .init_scale = sc2731_adc_scale_init, 512 + .get_ratio = sc2721_adc_get_ratio, 513 + .set_volref = true, 514 + }; 515 + 516 + static const struct sc27xx_adc_variant_data sc2720_data = { 517 + .module_en = SC2731_MODULE_EN, 518 + .clk_en = SC2721_ARM_CLK_EN, 519 + .scale_shift = SC27XX_ADC_SCALE_SHIFT, 520 + .scale_mask = SC27XX_ADC_SCALE_MASK, 521 + .bscale_cal = &big_scale_graph_calib, 522 + .sscale_cal = &small_scale_graph_calib, 523 + .init_scale = sc2720_adc_scale_init, 524 + .get_ratio = sc2720_adc_get_ratio, 525 + .set_volref = false, 526 + }; 811 527 812 528 static int sc27xx_adc_probe(struct platform_device *pdev) 813 529 { 814 530 struct device *dev = &pdev->dev; 815 531 struct device_node *np = dev->of_node; 816 532 struct sc27xx_adc_data *sc27xx_data; 533 + const struct sc27xx_adc_variant_data *pdata; 817 534 struct iio_dev *indio_dev; 818 535 int ret; 536 + 537 + pdata = of_device_get_match_data(dev); 538 + if (!pdata) { 539 + dev_err(dev, "No matching driver data found\n"); 540 + return -EINVAL; 541 + } 819 542 820 543 indio_dev = devm_iio_device_alloc(dev, sizeof(*sc27xx_data)); 821 544 if (!indio_dev) ··· 907 520 } 908 521 909 522 sc27xx_data->dev = dev; 523 + if (pdata->set_volref) { 524 + sc27xx_data->volref = devm_regulator_get(dev, "vref"); 525 + if (IS_ERR(sc27xx_data->volref)) { 526 + ret = PTR_ERR(sc27xx_data->volref); 527 + return dev_err_probe(dev, ret, "failed to get ADC volref\n"); 528 + } 529 + } 530 + 531 + sc27xx_data->var_data = pdata; 532 + sc27xx_data->var_data->init_scale(sc27xx_data); 910 533 911 534 ret = sc27xx_adc_enable(sc27xx_data); 912 535 if (ret) { ··· 943 546 } 944 547 945 548 static const struct of_device_id sc27xx_adc_of_match[] = { 946 - { .compatible = "sprd,sc2731-adc", }, 549 + { .compatible = "sprd,sc2731-adc", .data = &sc2731_data}, 550 + { .compatible = "sprd,sc2730-adc", .data = &sc2730_data}, 551 + { .compatible = "sprd,sc2721-adc", .data = &sc2721_data}, 552 + { .compatible = "sprd,sc2720-adc", .data = &sc2720_data}, 947 553 { } 948 554 }; 949 555 MODULE_DEVICE_TABLE(of, sc27xx_adc_of_match);
+2 -3
drivers/iio/adc/stm32-dfsdm-adc.c
··· 466 466 * In continuous mode, use fast mode configuration, 467 467 * if it provides a better resolution. 468 468 */ 469 - if (adc->nconv == 1 && !trig && 470 - (indio_dev->currentmode & INDIO_BUFFER_SOFTWARE)) { 469 + if (adc->nconv == 1 && !trig && iio_buffer_enabled(indio_dev)) { 471 470 if (fl->flo[1].res >= fl->flo[0].res) { 472 471 fl->fast = 1; 473 472 flo = &fl->flo[1]; ··· 561 562 cr1 = DFSDM_CR1_RCH(chan->channel); 562 563 563 564 /* Continuous conversions triggered by SPI clk in buffer mode */ 564 - if (indio_dev->currentmode & INDIO_BUFFER_SOFTWARE) 565 + if (iio_buffer_enabled(indio_dev)) 565 566 cr1 |= DFSDM_CR1_RCONT(1); 566 567 567 568 cr1 |= DFSDM_CR1_RSYNC(fl->sync_mode);
+14 -13
drivers/iio/adc/stmpe-adc.c
··· 61 61 static int stmpe_read_voltage(struct stmpe_adc *info, 62 62 struct iio_chan_spec const *chan, int *val) 63 63 { 64 - long ret; 64 + unsigned long ret; 65 65 66 66 mutex_lock(&info->lock); 67 67 ··· 79 79 80 80 ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT); 81 81 82 - if (ret <= 0) { 82 + if (ret == 0) { 83 83 stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA, 84 84 STMPE_ADC_CH(info->channel)); 85 85 mutex_unlock(&info->lock); ··· 96 96 static int stmpe_read_temp(struct stmpe_adc *info, 97 97 struct iio_chan_spec const *chan, int *val) 98 98 { 99 - long ret; 99 + unsigned long ret; 100 100 101 101 mutex_lock(&info->lock); 102 102 ··· 114 114 115 115 ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT); 116 116 117 - if (ret <= 0) { 117 + if (ret == 0) { 118 118 mutex_unlock(&info->lock); 119 119 return -ETIMEDOUT; 120 120 } ··· 345 345 346 346 static SIMPLE_DEV_PM_OPS(stmpe_adc_pm_ops, NULL, stmpe_adc_resume); 347 347 348 - static struct platform_driver stmpe_adc_driver = { 349 - .probe = stmpe_adc_probe, 350 - .driver = { 351 - .name = "stmpe-adc", 352 - .pm = &stmpe_adc_pm_ops, 353 - }, 354 - }; 355 - module_platform_driver(stmpe_adc_driver); 356 - 357 348 static const struct of_device_id stmpe_adc_ids[] = { 358 349 { .compatible = "st,stmpe-adc", }, 359 350 { }, 360 351 }; 361 352 MODULE_DEVICE_TABLE(of, stmpe_adc_ids); 353 + 354 + static struct platform_driver stmpe_adc_driver = { 355 + .probe = stmpe_adc_probe, 356 + .driver = { 357 + .name = "stmpe-adc", 358 + .pm = &stmpe_adc_pm_ops, 359 + .of_match_table = stmpe_adc_ids, 360 + }, 361 + }; 362 + module_platform_driver(stmpe_adc_driver); 362 363 363 364 MODULE_AUTHOR("Stefan Agner <stefan.agner@toradex.com>"); 364 365 MODULE_DESCRIPTION("STMPEXXX ADC driver");
+232 -166
drivers/iio/adc/ti-ads1015.c
··· 76 76 #define ADS1015_DEFAULT_DATA_RATE 4 77 77 #define ADS1015_DEFAULT_CHAN 0 78 78 79 - enum chip_ids { 80 - ADSXXXX = 0, 81 - ADS1015, 82 - ADS1115, 79 + struct ads1015_chip_data { 80 + struct iio_chan_spec const *channels; 81 + int num_channels; 82 + const struct iio_info *info; 83 + const int *data_rate; 84 + const int data_rate_len; 85 + const int *scale; 86 + const int scale_len; 87 + bool has_comparator; 83 88 }; 84 89 85 90 enum ads1015_channels { ··· 99 94 ADS1015_TIMESTAMP, 100 95 }; 101 96 102 - static const unsigned int ads1015_data_rate[] = { 97 + static const int ads1015_data_rate[] = { 103 98 128, 250, 490, 920, 1600, 2400, 3300, 3300 104 99 }; 105 100 106 - static const unsigned int ads1115_data_rate[] = { 101 + static const int ads1115_data_rate[] = { 107 102 8, 16, 32, 64, 128, 250, 475, 860 108 103 }; 109 104 ··· 111 106 * Translation from PGA bits to full-scale positive and negative input voltage 112 107 * range in mV 113 108 */ 114 - static int ads1015_fullscale_range[] = { 109 + static const int ads1015_fullscale_range[] = { 115 110 6144, 4096, 2048, 1024, 512, 256, 256, 256 111 + }; 112 + 113 + static const int ads1015_scale[] = { /* 12bit ADC */ 114 + 256, 11, 115 + 512, 11, 116 + 1024, 11, 117 + 2048, 11, 118 + 4096, 11, 119 + 6144, 11 120 + }; 121 + 122 + static const int ads1115_scale[] = { /* 16bit ADC */ 123 + 256, 15, 124 + 512, 15, 125 + 1024, 15, 126 + 2048, 15, 127 + 4096, 15, 128 + 6144, 15 116 129 }; 117 130 118 131 /* ··· 157 134 }, 158 135 }; 159 136 160 - #define ADS1015_V_CHAN(_chan, _addr) { \ 137 + /* 138 + * Compile-time check whether _fitbits can accommodate up to _testbits 139 + * bits. Returns _fitbits on success, fails to compile otherwise. 140 + * 141 + * The test works such that it multiplies constant _fitbits by constant 142 + * double-negation of size of a non-empty structure, i.e. it multiplies 143 + * constant _fitbits by constant 1 in each successful compilation case. 144 + * The non-empty structure may contain C11 _Static_assert(), make use of 145 + * this and place the kernel variant of static assert in there, so that 146 + * it performs the compile-time check for _testbits <= _fitbits. Note 147 + * that it is not possible to directly use static_assert in compound 148 + * statements, hence this convoluted construct. 149 + */ 150 + #define FIT_CHECK(_testbits, _fitbits) \ 151 + ( \ 152 + (_fitbits) * \ 153 + !!sizeof(struct { \ 154 + static_assert((_testbits) <= (_fitbits)); \ 155 + int pad; \ 156 + }) \ 157 + ) 158 + 159 + #define ADS1015_V_CHAN(_chan, _addr, _realbits, _shift, _event_spec, _num_event_specs) { \ 161 160 .type = IIO_VOLTAGE, \ 162 161 .indexed = 1, \ 163 162 .address = _addr, \ ··· 187 142 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 188 143 BIT(IIO_CHAN_INFO_SCALE) | \ 189 144 BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 145 + .info_mask_shared_by_all_available = \ 146 + BIT(IIO_CHAN_INFO_SCALE) | \ 147 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 190 148 .scan_index = _addr, \ 191 149 .scan_type = { \ 192 150 .sign = 's', \ 193 - .realbits = 12, \ 194 - .storagebits = 16, \ 195 - .shift = 4, \ 151 + .realbits = (_realbits), \ 152 + .storagebits = FIT_CHECK((_realbits) + (_shift), 16), \ 153 + .shift = (_shift), \ 196 154 .endianness = IIO_CPU, \ 197 155 }, \ 198 - .event_spec = ads1015_events, \ 199 - .num_event_specs = ARRAY_SIZE(ads1015_events), \ 156 + .event_spec = (_event_spec), \ 157 + .num_event_specs = (_num_event_specs), \ 200 158 .datasheet_name = "AIN"#_chan, \ 201 159 } 202 160 203 - #define ADS1015_V_DIFF_CHAN(_chan, _chan2, _addr) { \ 161 + #define ADS1015_V_DIFF_CHAN(_chan, _chan2, _addr, _realbits, _shift, _event_spec, _num_event_specs) { \ 204 162 .type = IIO_VOLTAGE, \ 205 163 .differential = 1, \ 206 164 .indexed = 1, \ ··· 213 165 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 214 166 BIT(IIO_CHAN_INFO_SCALE) | \ 215 167 BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 216 - .scan_index = _addr, \ 217 - .scan_type = { \ 218 - .sign = 's', \ 219 - .realbits = 12, \ 220 - .storagebits = 16, \ 221 - .shift = 4, \ 222 - .endianness = IIO_CPU, \ 223 - }, \ 224 - .event_spec = ads1015_events, \ 225 - .num_event_specs = ARRAY_SIZE(ads1015_events), \ 226 - .datasheet_name = "AIN"#_chan"-AIN"#_chan2, \ 227 - } 228 - 229 - #define ADS1115_V_CHAN(_chan, _addr) { \ 230 - .type = IIO_VOLTAGE, \ 231 - .indexed = 1, \ 232 - .address = _addr, \ 233 - .channel = _chan, \ 234 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 168 + .info_mask_shared_by_all_available = \ 235 169 BIT(IIO_CHAN_INFO_SCALE) | \ 236 170 BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 237 171 .scan_index = _addr, \ 238 172 .scan_type = { \ 239 173 .sign = 's', \ 240 - .realbits = 16, \ 241 - .storagebits = 16, \ 174 + .realbits = (_realbits), \ 175 + .storagebits = FIT_CHECK((_realbits) + (_shift), 16), \ 176 + .shift = (_shift), \ 242 177 .endianness = IIO_CPU, \ 243 178 }, \ 244 - .event_spec = ads1015_events, \ 245 - .num_event_specs = ARRAY_SIZE(ads1015_events), \ 246 - .datasheet_name = "AIN"#_chan, \ 247 - } 248 - 249 - #define ADS1115_V_DIFF_CHAN(_chan, _chan2, _addr) { \ 250 - .type = IIO_VOLTAGE, \ 251 - .differential = 1, \ 252 - .indexed = 1, \ 253 - .address = _addr, \ 254 - .channel = _chan, \ 255 - .channel2 = _chan2, \ 256 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 257 - BIT(IIO_CHAN_INFO_SCALE) | \ 258 - BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 259 - .scan_index = _addr, \ 260 - .scan_type = { \ 261 - .sign = 's', \ 262 - .realbits = 16, \ 263 - .storagebits = 16, \ 264 - .endianness = IIO_CPU, \ 265 - }, \ 266 - .event_spec = ads1015_events, \ 267 - .num_event_specs = ARRAY_SIZE(ads1015_events), \ 179 + .event_spec = (_event_spec), \ 180 + .num_event_specs = (_num_event_specs), \ 268 181 .datasheet_name = "AIN"#_chan"-AIN"#_chan2, \ 269 182 } 270 183 ··· 254 245 unsigned int comp_mode; 255 246 struct ads1015_thresh_data thresh_data[ADS1015_CHANNELS]; 256 247 257 - unsigned int *data_rate; 248 + const struct ads1015_chip_data *chip; 258 249 /* 259 250 * Set to true when the ADC is switched to the continuous-conversion 260 251 * mode and exits from a power-down state. This flag is used to avoid ··· 282 273 data->event_channel = ADS1015_CHANNELS; 283 274 } 284 275 285 - static bool ads1015_is_writeable_reg(struct device *dev, unsigned int reg) 286 - { 287 - switch (reg) { 288 - case ADS1015_CFG_REG: 289 - case ADS1015_LO_THRESH_REG: 290 - case ADS1015_HI_THRESH_REG: 291 - return true; 292 - default: 293 - return false; 294 - } 295 - } 276 + static const struct regmap_range ads1015_writeable_ranges[] = { 277 + regmap_reg_range(ADS1015_CFG_REG, ADS1015_HI_THRESH_REG), 278 + }; 279 + 280 + static const struct regmap_access_table ads1015_writeable_table = { 281 + .yes_ranges = ads1015_writeable_ranges, 282 + .n_yes_ranges = ARRAY_SIZE(ads1015_writeable_ranges), 283 + }; 296 284 297 285 static const struct regmap_config ads1015_regmap_config = { 298 286 .reg_bits = 8, 299 287 .val_bits = 16, 300 288 .max_register = ADS1015_HI_THRESH_REG, 301 - .writeable_reg = ads1015_is_writeable_reg, 289 + .wr_table = &ads1015_writeable_table, 290 + }; 291 + 292 + static const struct regmap_range tla2024_writeable_ranges[] = { 293 + regmap_reg_range(ADS1015_CFG_REG, ADS1015_CFG_REG), 294 + }; 295 + 296 + static const struct regmap_access_table tla2024_writeable_table = { 297 + .yes_ranges = tla2024_writeable_ranges, 298 + .n_yes_ranges = ARRAY_SIZE(tla2024_writeable_ranges), 299 + }; 300 + 301 + static const struct regmap_config tla2024_regmap_config = { 302 + .reg_bits = 8, 303 + .val_bits = 16, 304 + .max_register = ADS1015_CFG_REG, 305 + .wr_table = &tla2024_writeable_table, 302 306 }; 303 307 304 308 static const struct iio_chan_spec ads1015_channels[] = { 305 - ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1), 306 - ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3), 307 - ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3), 308 - ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3), 309 - ADS1015_V_CHAN(0, ADS1015_AIN0), 310 - ADS1015_V_CHAN(1, ADS1015_AIN1), 311 - ADS1015_V_CHAN(2, ADS1015_AIN2), 312 - ADS1015_V_CHAN(3, ADS1015_AIN3), 309 + ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4, 310 + ads1015_events, ARRAY_SIZE(ads1015_events)), 311 + ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 12, 4, 312 + ads1015_events, ARRAY_SIZE(ads1015_events)), 313 + ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 12, 4, 314 + ads1015_events, ARRAY_SIZE(ads1015_events)), 315 + ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 12, 4, 316 + ads1015_events, ARRAY_SIZE(ads1015_events)), 317 + ADS1015_V_CHAN(0, ADS1015_AIN0, 12, 4, 318 + ads1015_events, ARRAY_SIZE(ads1015_events)), 319 + ADS1015_V_CHAN(1, ADS1015_AIN1, 12, 4, 320 + ads1015_events, ARRAY_SIZE(ads1015_events)), 321 + ADS1015_V_CHAN(2, ADS1015_AIN2, 12, 4, 322 + ads1015_events, ARRAY_SIZE(ads1015_events)), 323 + ADS1015_V_CHAN(3, ADS1015_AIN3, 12, 4, 324 + ads1015_events, ARRAY_SIZE(ads1015_events)), 313 325 IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), 314 326 }; 315 327 316 328 static const struct iio_chan_spec ads1115_channels[] = { 317 - ADS1115_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1), 318 - ADS1115_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3), 319 - ADS1115_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3), 320 - ADS1115_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3), 321 - ADS1115_V_CHAN(0, ADS1015_AIN0), 322 - ADS1115_V_CHAN(1, ADS1015_AIN1), 323 - ADS1115_V_CHAN(2, ADS1015_AIN2), 324 - ADS1115_V_CHAN(3, ADS1015_AIN3), 329 + ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 16, 0, 330 + ads1015_events, ARRAY_SIZE(ads1015_events)), 331 + ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 16, 0, 332 + ads1015_events, ARRAY_SIZE(ads1015_events)), 333 + ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 16, 0, 334 + ads1015_events, ARRAY_SIZE(ads1015_events)), 335 + ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 16, 0, 336 + ads1015_events, ARRAY_SIZE(ads1015_events)), 337 + ADS1015_V_CHAN(0, ADS1015_AIN0, 16, 0, 338 + ads1015_events, ARRAY_SIZE(ads1015_events)), 339 + ADS1015_V_CHAN(1, ADS1015_AIN1, 16, 0, 340 + ads1015_events, ARRAY_SIZE(ads1015_events)), 341 + ADS1015_V_CHAN(2, ADS1015_AIN2, 16, 0, 342 + ads1015_events, ARRAY_SIZE(ads1015_events)), 343 + ADS1015_V_CHAN(3, ADS1015_AIN3, 16, 0, 344 + ads1015_events, ARRAY_SIZE(ads1015_events)), 325 345 IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), 326 346 }; 347 + 348 + static const struct iio_chan_spec tla2024_channels[] = { 349 + ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4, NULL, 0), 350 + ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 12, 4, NULL, 0), 351 + ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 12, 4, NULL, 0), 352 + ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 12, 4, NULL, 0), 353 + ADS1015_V_CHAN(0, ADS1015_AIN0, 12, 4, NULL, 0), 354 + ADS1015_V_CHAN(1, ADS1015_AIN1, 12, 4, NULL, 0), 355 + ADS1015_V_CHAN(2, ADS1015_AIN2, 12, 4, NULL, 0), 356 + ADS1015_V_CHAN(3, ADS1015_AIN3, 12, 4, NULL, 0), 357 + IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), 358 + }; 359 + 327 360 328 361 #ifdef CONFIG_PM 329 362 static int ads1015_set_power_state(struct ads1015_data *data, bool on) ··· 395 344 static 396 345 int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val) 397 346 { 347 + const int *data_rate = data->chip->data_rate; 398 348 int ret, pga, dr, dr_old, conv_time; 399 349 unsigned int old, mask, cfg; 400 350 ··· 430 378 } 431 379 if (data->conv_invalid) { 432 380 dr_old = (old & ADS1015_CFG_DR_MASK) >> ADS1015_CFG_DR_SHIFT; 433 - conv_time = DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr_old]); 434 - conv_time += DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr]); 381 + conv_time = DIV_ROUND_UP(USEC_PER_SEC, data_rate[dr_old]); 382 + conv_time += DIV_ROUND_UP(USEC_PER_SEC, data_rate[dr]); 435 383 conv_time += conv_time / 10; /* 10% internal clock inaccuracy */ 436 384 usleep_range(conv_time, conv_time + 1); 437 385 data->conv_invalid = false; ··· 497 445 { 498 446 int i; 499 447 500 - for (i = 0; i < ARRAY_SIZE(ads1015_data_rate); i++) { 501 - if (data->data_rate[i] == rate) { 448 + for (i = 0; i < data->chip->data_rate_len; i++) { 449 + if (data->chip->data_rate[i] == rate) { 502 450 data->channel_data[chan].data_rate = i; 503 451 return 0; 504 452 } 505 453 } 506 454 507 455 return -EINVAL; 456 + } 457 + 458 + static int ads1015_read_avail(struct iio_dev *indio_dev, 459 + struct iio_chan_spec const *chan, 460 + const int **vals, int *type, int *length, 461 + long mask) 462 + { 463 + struct ads1015_data *data = iio_priv(indio_dev); 464 + 465 + if (chan->type != IIO_VOLTAGE) 466 + return -EINVAL; 467 + 468 + switch (mask) { 469 + case IIO_CHAN_INFO_SCALE: 470 + *type = IIO_VAL_FRACTIONAL_LOG2; 471 + *vals = data->chip->scale; 472 + *length = data->chip->scale_len; 473 + return IIO_AVAIL_LIST; 474 + case IIO_CHAN_INFO_SAMP_FREQ: 475 + *type = IIO_VAL_INT; 476 + *vals = data->chip->data_rate; 477 + *length = data->chip->data_rate_len; 478 + return IIO_AVAIL_LIST; 479 + default: 480 + return -EINVAL; 481 + } 508 482 } 509 483 510 484 static int ads1015_read_raw(struct iio_dev *indio_dev, ··· 582 504 break; 583 505 case IIO_CHAN_INFO_SAMP_FREQ: 584 506 idx = data->channel_data[chan->address].data_rate; 585 - *val = data->data_rate[idx]; 507 + *val = data->chip->data_rate[idx]; 586 508 ret = IIO_VAL_INT; 587 509 break; 588 510 default: ··· 642 564 dr = data->channel_data[chan->address].data_rate; 643 565 comp_queue = data->thresh_data[chan->address].comp_queue; 644 566 period = ads1015_comp_queue[comp_queue] * 645 - USEC_PER_SEC / data->data_rate[dr]; 567 + USEC_PER_SEC / data->chip->data_rate[dr]; 646 568 647 569 *val = period / USEC_PER_SEC; 648 570 *val2 = period % USEC_PER_SEC; ··· 664 586 int val2) 665 587 { 666 588 struct ads1015_data *data = iio_priv(indio_dev); 589 + const int *data_rate = data->chip->data_rate; 667 590 int realbits = chan->scan_type.realbits; 668 591 int ret = 0; 669 592 long long period; ··· 690 611 691 612 for (i = 0; i < ARRAY_SIZE(ads1015_comp_queue) - 1; i++) { 692 613 if (period <= ads1015_comp_queue[i] * 693 - USEC_PER_SEC / data->data_rate[dr]) 614 + USEC_PER_SEC / data_rate[dr]) 694 615 break; 695 616 } 696 617 data->thresh_data[chan->address].comp_queue = i; ··· 881 802 .validate_scan_mask = &iio_validate_scan_mask_onehot, 882 803 }; 883 804 884 - static IIO_CONST_ATTR_NAMED(ads1015_scale_available, scale_available, 885 - "3 2 1 0.5 0.25 0.125"); 886 - static IIO_CONST_ATTR_NAMED(ads1115_scale_available, scale_available, 887 - "0.1875 0.125 0.0625 0.03125 0.015625 0.007813"); 888 - 889 - static IIO_CONST_ATTR_NAMED(ads1015_sampling_frequency_available, 890 - sampling_frequency_available, "128 250 490 920 1600 2400 3300"); 891 - static IIO_CONST_ATTR_NAMED(ads1115_sampling_frequency_available, 892 - sampling_frequency_available, "8 16 32 64 128 250 475 860"); 893 - 894 - static struct attribute *ads1015_attributes[] = { 895 - &iio_const_attr_ads1015_scale_available.dev_attr.attr, 896 - &iio_const_attr_ads1015_sampling_frequency_available.dev_attr.attr, 897 - NULL, 898 - }; 899 - 900 - static const struct attribute_group ads1015_attribute_group = { 901 - .attrs = ads1015_attributes, 902 - }; 903 - 904 - static struct attribute *ads1115_attributes[] = { 905 - &iio_const_attr_ads1115_scale_available.dev_attr.attr, 906 - &iio_const_attr_ads1115_sampling_frequency_available.dev_attr.attr, 907 - NULL, 908 - }; 909 - 910 - static const struct attribute_group ads1115_attribute_group = { 911 - .attrs = ads1115_attributes, 912 - }; 913 - 914 805 static const struct iio_info ads1015_info = { 806 + .read_avail = ads1015_read_avail, 915 807 .read_raw = ads1015_read_raw, 916 808 .write_raw = ads1015_write_raw, 917 809 .read_event_value = ads1015_read_event, 918 810 .write_event_value = ads1015_write_event, 919 811 .read_event_config = ads1015_read_event_config, 920 812 .write_event_config = ads1015_write_event_config, 921 - .attrs = &ads1015_attribute_group, 922 813 }; 923 814 924 - static const struct iio_info ads1115_info = { 815 + static const struct iio_info tla2024_info = { 816 + .read_avail = ads1015_read_avail, 925 817 .read_raw = ads1015_read_raw, 926 818 .write_raw = ads1015_write_raw, 927 - .read_event_value = ads1015_read_event, 928 - .write_event_value = ads1015_write_event, 929 - .read_event_config = ads1015_read_event_config, 930 - .write_event_config = ads1015_write_event_config, 931 - .attrs = &ads1115_attribute_group, 932 819 }; 933 820 934 821 static int ads1015_client_get_channels_config(struct i2c_client *client) ··· 977 932 static int ads1015_probe(struct i2c_client *client, 978 933 const struct i2c_device_id *id) 979 934 { 935 + const struct ads1015_chip_data *chip; 980 936 struct iio_dev *indio_dev; 981 937 struct ads1015_data *data; 982 938 int ret; 983 - enum chip_ids chip; 984 939 int i; 940 + 941 + chip = device_get_match_data(&client->dev); 942 + if (!chip) 943 + chip = (const struct ads1015_chip_data *)id->driver_data; 944 + if (!chip) 945 + return dev_err_probe(&client->dev, -EINVAL, "Unknown chip\n"); 985 946 986 947 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 987 948 if (!indio_dev) ··· 1001 950 indio_dev->name = ADS1015_DRV_NAME; 1002 951 indio_dev->modes = INDIO_DIRECT_MODE; 1003 952 1004 - chip = (uintptr_t)device_get_match_data(&client->dev); 1005 - if (chip == ADSXXXX) 1006 - chip = id->driver_data; 1007 - switch (chip) { 1008 - case ADS1015: 1009 - indio_dev->channels = ads1015_channels; 1010 - indio_dev->num_channels = ARRAY_SIZE(ads1015_channels); 1011 - indio_dev->info = &ads1015_info; 1012 - data->data_rate = (unsigned int *) &ads1015_data_rate; 1013 - break; 1014 - case ADS1115: 1015 - indio_dev->channels = ads1115_channels; 1016 - indio_dev->num_channels = ARRAY_SIZE(ads1115_channels); 1017 - indio_dev->info = &ads1115_info; 1018 - data->data_rate = (unsigned int *) &ads1115_data_rate; 1019 - break; 1020 - default: 1021 - dev_err(&client->dev, "Unknown chip %d\n", chip); 1022 - return -EINVAL; 1023 - } 1024 - 953 + indio_dev->channels = chip->channels; 954 + indio_dev->num_channels = chip->num_channels; 955 + indio_dev->info = chip->info; 956 + data->chip = chip; 1025 957 data->event_channel = ADS1015_CHANNELS; 958 + 1026 959 /* 1027 960 * Set default lower and upper threshold to min and max value 1028 961 * respectively. ··· 1021 986 /* we need to keep this ABI the same as used by hwmon ADS1015 driver */ 1022 987 ads1015_get_channels_config(client); 1023 988 1024 - data->regmap = devm_regmap_init_i2c(client, &ads1015_regmap_config); 989 + data->regmap = devm_regmap_init_i2c(client, chip->has_comparator ? 990 + &ads1015_regmap_config : 991 + &tla2024_regmap_config); 1025 992 if (IS_ERR(data->regmap)) { 1026 993 dev_err(&client->dev, "Failed to allocate register map\n"); 1027 994 return PTR_ERR(data->regmap); ··· 1037 1000 return ret; 1038 1001 } 1039 1002 1040 - if (client->irq) { 1003 + if (client->irq && chip->has_comparator) { 1041 1004 unsigned long irq_trig = 1042 1005 irqd_get_trigger_type(irq_get_irq_data(client->irq)); 1043 1006 unsigned int cfg_comp_mask = ADS1015_CFG_COMP_QUE_MASK | ··· 1136 1099 ads1015_runtime_resume, NULL) 1137 1100 }; 1138 1101 1102 + static const struct ads1015_chip_data ads1015_data = { 1103 + .channels = ads1015_channels, 1104 + .num_channels = ARRAY_SIZE(ads1015_channels), 1105 + .info = &ads1015_info, 1106 + .data_rate = ads1015_data_rate, 1107 + .data_rate_len = ARRAY_SIZE(ads1015_data_rate), 1108 + .scale = ads1015_scale, 1109 + .scale_len = ARRAY_SIZE(ads1015_scale), 1110 + .has_comparator = true, 1111 + }; 1112 + 1113 + static const struct ads1015_chip_data ads1115_data = { 1114 + .channels = ads1115_channels, 1115 + .num_channels = ARRAY_SIZE(ads1115_channels), 1116 + .info = &ads1015_info, 1117 + .data_rate = ads1115_data_rate, 1118 + .data_rate_len = ARRAY_SIZE(ads1115_data_rate), 1119 + .scale = ads1115_scale, 1120 + .scale_len = ARRAY_SIZE(ads1115_scale), 1121 + .has_comparator = true, 1122 + }; 1123 + 1124 + static const struct ads1015_chip_data tla2024_data = { 1125 + .channels = tla2024_channels, 1126 + .num_channels = ARRAY_SIZE(tla2024_channels), 1127 + .info = &tla2024_info, 1128 + .data_rate = ads1015_data_rate, 1129 + .data_rate_len = ARRAY_SIZE(ads1015_data_rate), 1130 + .scale = ads1015_scale, 1131 + .scale_len = ARRAY_SIZE(ads1015_scale), 1132 + .has_comparator = false, 1133 + }; 1134 + 1139 1135 static const struct i2c_device_id ads1015_id[] = { 1140 - {"ads1015", ADS1015}, 1141 - {"ads1115", ADS1115}, 1136 + { "ads1015", (kernel_ulong_t)&ads1015_data }, 1137 + { "ads1115", (kernel_ulong_t)&ads1115_data }, 1138 + { "tla2024", (kernel_ulong_t)&tla2024_data }, 1142 1139 {} 1143 1140 }; 1144 1141 MODULE_DEVICE_TABLE(i2c, ads1015_id); 1145 1142 1146 1143 static const struct of_device_id ads1015_of_match[] = { 1147 - { 1148 - .compatible = "ti,ads1015", 1149 - .data = (void *)ADS1015 1150 - }, 1151 - { 1152 - .compatible = "ti,ads1115", 1153 - .data = (void *)ADS1115 1154 - }, 1144 + { .compatible = "ti,ads1015", .data = &ads1015_data }, 1145 + { .compatible = "ti,ads1115", .data = &ads1115_data }, 1146 + { .compatible = "ti,tla2024", .data = &tla2024_data }, 1155 1147 {} 1156 1148 }; 1157 1149 MODULE_DEVICE_TABLE(of, ads1015_of_match);
+1
drivers/iio/adc/ti-ads8688.c
··· 508 508 static struct spi_driver ads8688_driver = { 509 509 .driver = { 510 510 .name = "ads8688", 511 + .of_match_table = ads8688_of_match, 511 512 }, 512 513 .probe = ads8688_probe, 513 514 .remove = ads8688_remove,
+1 -3
drivers/iio/adc/ti_am335x_adc.c
··· 376 376 { 377 377 int ret; 378 378 379 - ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, 380 - INDIO_BUFFER_SOFTWARE, 381 - setup_ops); 379 + ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, setup_ops); 382 380 if (ret) 383 381 return ret; 384 382
-1
drivers/iio/afe/Kconfig
··· 8 8 9 9 config IIO_RESCALE 10 10 tristate "IIO rescale" 11 - depends on OF || COMPILE_TEST 12 11 help 13 12 Say yes here to build support for the IIO rescaling 14 13 that handles voltage dividers, current sense shunts and
+2 -3
drivers/iio/afe/iio-rescale.c
··· 10 10 11 11 #include <linux/err.h> 12 12 #include <linux/gcd.h> 13 + #include <linux/mod_devicetable.h> 13 14 #include <linux/module.h> 14 - #include <linux/of.h> 15 - #include <linux/of_device.h> 16 15 #include <linux/platform_device.h> 17 16 #include <linux/property.h> 18 17 ··· 535 536 536 537 rescale = iio_priv(indio_dev); 537 538 538 - rescale->cfg = of_device_get_match_data(dev); 539 + rescale->cfg = device_get_match_data(dev); 539 540 rescale->numerator = 1; 540 541 rescale->denominator = 1; 541 542 rescale->offset = 0;
+1 -9
drivers/iio/buffer/kfifo_buf.c
··· 259 259 * devm_iio_kfifo_buffer_setup_ext - Allocate a kfifo buffer & attach it to an IIO device 260 260 * @dev: Device object to which to attach the life-time of this kfifo buffer 261 261 * @indio_dev: The device the buffer should be attached to 262 - * @mode_flags: The mode flags for this buffer (INDIO_BUFFER_SOFTWARE and/or 263 - * INDIO_BUFFER_TRIGGERED). 264 262 * @setup_ops: The setup_ops required to configure the HW part of the buffer (optional) 265 263 * @buffer_attrs: Extra sysfs buffer attributes for this IIO buffer 266 264 * ··· 269 271 */ 270 272 int devm_iio_kfifo_buffer_setup_ext(struct device *dev, 271 273 struct iio_dev *indio_dev, 272 - int mode_flags, 273 274 const struct iio_buffer_setup_ops *setup_ops, 274 275 const struct attribute **buffer_attrs) 275 276 { 276 277 struct iio_buffer *buffer; 277 278 278 - if (!mode_flags) 279 - return -EINVAL; 280 - 281 279 buffer = devm_iio_kfifo_allocate(dev); 282 280 if (!buffer) 283 281 return -ENOMEM; 284 282 285 - mode_flags &= kfifo_access_funcs.modes; 286 - 287 - indio_dev->modes |= mode_flags; 283 + indio_dev->modes |= INDIO_BUFFER_SOFTWARE; 288 284 indio_dev->setup_ops = setup_ops; 289 285 290 286 buffer->attrs = buffer_attrs;
+2 -3
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
··· 333 333 * We can not use trigger here, as events are generated 334 334 * as soon as sample_frequency is set. 335 335 */ 336 - ret = devm_iio_kfifo_buffer_setup_ext(dev, indio_dev, 337 - INDIO_BUFFER_SOFTWARE, NULL, 336 + ret = devm_iio_kfifo_buffer_setup_ext(dev, indio_dev, NULL, 338 337 cros_ec_sensor_fifo_attributes); 339 338 if (ret) 340 339 return ret; ··· 412 413 int ret, i; 413 414 bool calibrate; 414 415 415 - ret = strtobool(buf, &calibrate); 416 + ret = kstrtobool(buf, &calibrate); 416 417 if (ret < 0) 417 418 return ret; 418 419 if (!calibrate)
-1
drivers/iio/common/scmi_sensors/scmi_iio.c
··· 686 686 687 687 err = devm_iio_kfifo_buffer_setup(&scmi_iio_dev->dev, 688 688 scmi_iio_dev, 689 - INDIO_BUFFER_SOFTWARE, 690 689 &scmi_iio_buffer_ops); 691 690 if (err < 0) { 692 691 dev_err(dev,
+6 -7
drivers/iio/common/ssp_sensors/ssp_spi.c
··· 331 331 /* threaded irq */ 332 332 int ssp_irq_msg(struct ssp_data *data) 333 333 { 334 - bool found = false; 335 334 char *buffer; 336 335 u8 msg_type; 337 336 int ret; 338 337 u16 length, msg_options; 339 - struct ssp_msg *msg, *n; 338 + struct ssp_msg *msg = NULL, *iter, *n; 340 339 341 340 ret = spi_read(data->spi, data->header_buffer, SSP_HEADER_BUFFER_SIZE); 342 341 if (ret < 0) { ··· 361 362 * received with no order 362 363 */ 363 364 mutex_lock(&data->pending_lock); 364 - list_for_each_entry_safe(msg, n, &data->pending_list, list) { 365 - if (msg->options == msg_options) { 366 - list_del(&msg->list); 367 - found = true; 365 + list_for_each_entry_safe(iter, n, &data->pending_list, list) { 366 + if (iter->options == msg_options) { 367 + list_del(&iter->list); 368 + msg = iter; 368 369 break; 369 370 } 370 371 } 371 372 372 - if (!found) { 373 + if (!msg) { 373 374 /* 374 375 * here can be implemented dead messages handling 375 376 * but the slave should not send such ones - it is to
+27 -23
drivers/iio/common/st_sensors/st_sensors_core.c
··· 71 71 72 72 int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr) 73 73 { 74 - int err; 74 + int err = 0; 75 75 struct st_sensor_odr_avl odr_out = {0, 0}; 76 76 struct st_sensor_data *sdata = iio_priv(indio_dev); 77 77 78 + mutex_lock(&sdata->odr_lock); 79 + 78 80 if (!sdata->sensor_settings->odr.mask) 79 - return 0; 81 + goto unlock_mutex; 80 82 81 83 err = st_sensors_match_odr(sdata->sensor_settings, odr, &odr_out); 82 84 if (err < 0) 83 - goto st_sensors_match_odr_error; 85 + goto unlock_mutex; 84 86 85 87 if ((sdata->sensor_settings->odr.addr == 86 88 sdata->sensor_settings->pw.addr) && ··· 105 103 if (err >= 0) 106 104 sdata->odr = odr_out.hz; 107 105 108 - st_sensors_match_odr_error: 106 + unlock_mutex: 107 + mutex_unlock(&sdata->odr_lock); 108 + 109 109 return err; 110 110 } 111 111 EXPORT_SYMBOL_NS(st_sensors_set_odr, IIO_ST_SENSORS); ··· 365 361 struct st_sensors_platform_data *of_pdata; 366 362 int err = 0; 367 363 364 + mutex_init(&sdata->odr_lock); 365 + 368 366 /* If OF/DT pdata exists, it will take precedence of anything else */ 369 367 of_pdata = st_sensors_dev_probe(indio_dev->dev.parent, pdata); 370 368 if (IS_ERR(of_pdata)) ··· 555 549 int err; 556 550 struct st_sensor_data *sdata = iio_priv(indio_dev); 557 551 558 - mutex_lock(&indio_dev->mlock); 559 - if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { 560 - err = -EBUSY; 552 + err = iio_device_claim_direct_mode(indio_dev); 553 + if (err) 554 + return err; 555 + 556 + mutex_lock(&sdata->odr_lock); 557 + 558 + err = st_sensors_set_enable(indio_dev, true); 559 + if (err < 0) 561 560 goto out; 562 - } else { 563 - err = st_sensors_set_enable(indio_dev, true); 564 - if (err < 0) 565 - goto out; 566 561 567 - msleep((sdata->sensor_settings->bootime * 1000) / sdata->odr); 568 - err = st_sensors_read_axis_data(indio_dev, ch, val); 569 - if (err < 0) 570 - goto out; 562 + msleep((sdata->sensor_settings->bootime * 1000) / sdata->odr); 563 + err = st_sensors_read_axis_data(indio_dev, ch, val); 564 + if (err < 0) 565 + goto out; 571 566 572 - *val = *val >> ch->scan_type.shift; 567 + *val = *val >> ch->scan_type.shift; 573 568 574 - err = st_sensors_set_enable(indio_dev, false); 575 - } 569 + err = st_sensors_set_enable(indio_dev, false); 570 + 576 571 out: 577 - mutex_unlock(&indio_dev->mlock); 572 + mutex_unlock(&sdata->odr_lock); 573 + iio_device_release_direct_mode(indio_dev); 578 574 579 575 return err; 580 576 } ··· 649 641 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 650 642 struct st_sensor_data *sdata = iio_priv(indio_dev); 651 643 652 - mutex_lock(&indio_dev->mlock); 653 644 for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) { 654 645 if (sdata->sensor_settings->odr.odr_avl[i].hz == 0) 655 646 break; ··· 656 649 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", 657 650 sdata->sensor_settings->odr.odr_avl[i].hz); 658 651 } 659 - mutex_unlock(&indio_dev->mlock); 660 652 buf[len - 1] = '\n'; 661 653 662 654 return len; ··· 669 663 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 670 664 struct st_sensor_data *sdata = iio_priv(indio_dev); 671 665 672 - mutex_lock(&indio_dev->mlock); 673 666 for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) { 674 667 if (sdata->sensor_settings->fs.fs_avl[i].num == 0) 675 668 break; ··· 678 673 679 674 len += scnprintf(buf + len, PAGE_SIZE - len, "%u.%06u ", q, r); 680 675 } 681 - mutex_unlock(&indio_dev->mlock); 682 676 buf[len - 1] = '\n'; 683 677 684 678 return len;
+1 -3
drivers/iio/dac/Kconfig
··· 285 285 286 286 config DPOT_DAC 287 287 tristate "DAC emulation using a DPOT" 288 - depends on OF 289 288 help 290 289 Say yes here to build support for DAC emulation using a digital 291 290 potentiometer. ··· 304 305 config LPC18XX_DAC 305 306 tristate "NXP LPC18xx DAC driver" 306 307 depends on ARCH_LPC18XX || COMPILE_TEST 307 - depends on OF && HAS_IOMEM 308 + depends on HAS_IOMEM 308 309 help 309 310 Say yes here to build support for NXP LPC18XX DAC. 310 311 ··· 441 442 442 443 config VF610_DAC 443 444 tristate "Vybrid vf610 DAC driver" 444 - depends on OF 445 445 depends on HAS_IOMEM 446 446 help 447 447 Say yes here to support Vybrid board digital-to-analog converter.
+1 -1
drivers/iio/dac/ad5064.c
··· 288 288 bool pwr_down; 289 289 int ret; 290 290 291 - ret = strtobool(buf, &pwr_down); 291 + ret = kstrtobool(buf, &pwr_down); 292 292 if (ret) 293 293 return ret; 294 294
+1 -1
drivers/iio/dac/ad5360.c
··· 284 284 bool pwr_down; 285 285 int ret; 286 286 287 - ret = strtobool(buf, &pwr_down); 287 + ret = kstrtobool(buf, &pwr_down); 288 288 if (ret) 289 289 return ret; 290 290
+1 -1
drivers/iio/dac/ad5380.c
··· 96 96 bool pwr_down; 97 97 int ret; 98 98 99 - ret = strtobool(buf, &pwr_down); 99 + ret = kstrtobool(buf, &pwr_down); 100 100 if (ret) 101 101 return ret; 102 102
+1 -1
drivers/iio/dac/ad5446.c
··· 114 114 bool powerdown; 115 115 int ret; 116 116 117 - ret = strtobool(buf, &powerdown); 117 + ret = kstrtobool(buf, &powerdown); 118 118 if (ret) 119 119 return ret; 120 120
+1 -1
drivers/iio/dac/ad5504.c
··· 182 182 int ret; 183 183 struct ad5504_state *st = iio_priv(indio_dev); 184 184 185 - ret = strtobool(buf, &pwr_down); 185 + ret = kstrtobool(buf, &pwr_down); 186 186 if (ret) 187 187 return ret; 188 188
+1 -1
drivers/iio/dac/ad5624r_spi.c
··· 129 129 int ret; 130 130 struct ad5624r_state *st = iio_priv(indio_dev); 131 131 132 - ret = strtobool(buf, &pwr_down); 132 + ret = kstrtobool(buf, &pwr_down); 133 133 if (ret) 134 134 return ret; 135 135
+1 -1
drivers/iio/dac/ad5686.c
··· 73 73 unsigned int val, ref_bit_msk; 74 74 u8 shift, address = 0; 75 75 76 - ret = strtobool(buf, &readin); 76 + ret = kstrtobool(buf, &readin); 77 77 if (ret) 78 78 return ret; 79 79
+1 -1
drivers/iio/dac/ad5755.c
··· 502 502 bool pwr_down; 503 503 int ret; 504 504 505 - ret = strtobool(buf, &pwr_down); 505 + ret = kstrtobool(buf, &pwr_down); 506 506 if (ret) 507 507 return ret; 508 508
+1 -1
drivers/iio/dac/ad5791.c
··· 188 188 int ret; 189 189 struct ad5791_state *st = iio_priv(indio_dev); 190 190 191 - ret = strtobool(buf, &pwr_down); 191 + ret = kstrtobool(buf, &pwr_down); 192 192 if (ret) 193 193 return ret; 194 194
+1 -1
drivers/iio/dac/ad7303.c
··· 77 77 bool pwr_down; 78 78 int ret; 79 79 80 - ret = strtobool(buf, &pwr_down); 80 + ret = kstrtobool(buf, &pwr_down); 81 81 if (ret) 82 82 return ret; 83 83
+4 -4
drivers/iio/dac/ltc2632.c
··· 10 10 #include <linux/spi/spi.h> 11 11 #include <linux/module.h> 12 12 #include <linux/iio/iio.h> 13 + #include <linux/property.h> 13 14 #include <linux/regulator/consumer.h> 14 15 15 16 #include <asm/unaligned.h> ··· 150 149 int ret; 151 150 struct ltc2632_state *st = iio_priv(indio_dev); 152 151 153 - ret = strtobool(buf, &pwr_down); 152 + ret = kstrtobool(buf, &pwr_down); 154 153 if (ret) 155 154 return ret; 156 155 ··· 363 362 } 364 363 } 365 364 366 - indio_dev->name = dev_of_node(&spi->dev) ? dev_of_node(&spi->dev)->name 367 - : spi_get_device_id(spi)->name; 365 + indio_dev->name = fwnode_get_name(dev_fwnode(&spi->dev)) ?: spi_get_device_id(spi)->name; 368 366 indio_dev->info = &ltc2632_info; 369 367 indio_dev->modes = INDIO_DIRECT_MODE; 370 368 indio_dev->channels = chip_info->channels; ··· 469 469 static struct spi_driver ltc2632_driver = { 470 470 .driver = { 471 471 .name = "ltc2632", 472 - .of_match_table = of_match_ptr(ltc2632_of_match), 472 + .of_match_table = ltc2632_of_match, 473 473 }, 474 474 .probe = ltc2632_probe, 475 475 .remove = ltc2632_remove,
+9 -10
drivers/iio/dac/ltc2688.c
··· 703 703 struct ltc2688_chan *chan, 704 704 struct fwnode_handle *node, int tgp) 705 705 { 706 + struct device *dev = &st->spi->dev; 706 707 unsigned long rate; 707 708 struct clk *clk; 708 709 int ret, f; 709 710 710 - clk = devm_get_clk_from_child(&st->spi->dev, to_of_node(node), NULL); 711 + clk = devm_get_clk_from_child(dev, to_of_node(node), NULL); 711 712 if (IS_ERR(clk)) 712 - return dev_err_probe(&st->spi->dev, PTR_ERR(clk), 713 - "failed to get tgp clk.\n"); 713 + return dev_err_probe(dev, PTR_ERR(clk), "failed to get tgp clk.\n"); 714 714 715 715 ret = clk_prepare_enable(clk); 716 716 if (ret) 717 - return dev_err_probe(&st->spi->dev, ret, 718 - "failed to enable tgp clk.\n"); 717 + return dev_err_probe(dev, ret, "failed to enable tgp clk.\n"); 719 718 720 - ret = devm_add_action_or_reset(&st->spi->dev, ltc2688_clk_disable, clk); 719 + ret = devm_add_action_or_reset(dev, ltc2688_clk_disable, clk); 721 720 if (ret) 722 721 return ret; 723 722 ··· 857 858 858 859 static int ltc2688_setup(struct ltc2688_state *st, struct regulator *vref) 859 860 { 861 + struct device *dev = &st->spi->dev; 860 862 struct gpio_desc *gpio; 861 863 int ret; 862 864 ··· 865 865 * If we have a reset pin, use that to reset the board, If not, use 866 866 * the reset bit. 867 867 */ 868 - gpio = devm_gpiod_get_optional(&st->spi->dev, "clr", GPIOD_OUT_HIGH); 868 + gpio = devm_gpiod_get_optional(dev, "clr", GPIOD_OUT_HIGH); 869 869 if (IS_ERR(gpio)) 870 - return dev_err_probe(&st->spi->dev, PTR_ERR(gpio), 871 - "Failed to get reset gpio"); 870 + return dev_err_probe(dev, PTR_ERR(gpio), "Failed to get reset gpio"); 872 871 if (gpio) { 873 872 usleep_range(1000, 1200); 874 873 /* bring device out of reset */ ··· 886 887 * Duplicate the default channel configuration as it can change during 887 888 * @ltc2688_channel_config() 888 889 */ 889 - st->iio_chan = devm_kmemdup(&st->spi->dev, ltc2688_channels, 890 + st->iio_chan = devm_kmemdup(dev, ltc2688_channels, 890 891 sizeof(ltc2688_channels), GFP_KERNEL); 891 892 if (!st->iio_chan) 892 893 return -ENOMEM;
+1 -1
drivers/iio/dac/max5821.c
··· 116 116 bool powerdown; 117 117 int ret; 118 118 119 - ret = strtobool(buf, &powerdown); 119 + ret = kstrtobool(buf, &powerdown); 120 120 if (ret) 121 121 return ret; 122 122
+2 -2
drivers/iio/dac/mcp4725.c
··· 80 80 bool state; 81 81 int ret; 82 82 83 - ret = strtobool(buf, &state); 83 + ret = kstrtobool(buf, &state); 84 84 if (ret < 0) 85 85 return ret; 86 86 ··· 178 178 bool state; 179 179 int ret; 180 180 181 - ret = strtobool(buf, &state); 181 + ret = kstrtobool(buf, &state); 182 182 if (ret) 183 183 return ret; 184 184
+1 -1
drivers/iio/dac/stm32-dac.c
··· 220 220 bool powerdown; 221 221 int ret; 222 222 223 - ret = strtobool(buf, &powerdown); 223 + ret = kstrtobool(buf, &powerdown); 224 224 if (ret) 225 225 return ret; 226 226
+1 -1
drivers/iio/dac/ti-dac082s085.c
··· 133 133 bool powerdown; 134 134 int ret; 135 135 136 - ret = strtobool(buf, &powerdown); 136 + ret = kstrtobool(buf, &powerdown); 137 137 if (ret) 138 138 return ret; 139 139
+1 -1
drivers/iio/dac/ti-dac5571.c
··· 179 179 bool powerdown; 180 180 int ret; 181 181 182 - ret = strtobool(buf, &powerdown); 182 + ret = kstrtobool(buf, &powerdown); 183 183 if (ret) 184 184 return ret; 185 185
+1 -1
drivers/iio/dac/ti-dac7311.c
··· 123 123 u8 power; 124 124 int ret; 125 125 126 - ret = strtobool(buf, &powerdown); 126 + ret = kstrtobool(buf, &powerdown); 127 127 if (ret) 128 128 return ret; 129 129
+12 -8
drivers/iio/dummy/iio_simple_dummy.c
··· 575 575 */ 576 576 577 577 swd = kzalloc(sizeof(*swd), GFP_KERNEL); 578 - if (!swd) { 579 - ret = -ENOMEM; 580 - goto error_kzalloc; 581 - } 578 + if (!swd) 579 + return ERR_PTR(-ENOMEM); 580 + 582 581 /* 583 582 * Allocate an IIO device. 584 583 * ··· 589 590 indio_dev = iio_device_alloc(parent, sizeof(*st)); 590 591 if (!indio_dev) { 591 592 ret = -ENOMEM; 592 - goto error_ret; 593 + goto error_free_swd; 593 594 } 594 595 595 596 st = iio_priv(indio_dev); ··· 615 616 * indio_dev->name = spi_get_device_id(spi)->name; 616 617 */ 617 618 indio_dev->name = kstrdup(name, GFP_KERNEL); 619 + if (!indio_dev->name) { 620 + ret = -ENOMEM; 621 + goto error_free_device; 622 + } 618 623 619 624 /* Provide description of available channels */ 620 625 indio_dev->channels = iio_dummy_channels; ··· 635 632 636 633 ret = iio_simple_dummy_events_register(indio_dev); 637 634 if (ret < 0) 638 - goto error_free_device; 635 + goto error_free_name; 639 636 640 637 ret = iio_simple_dummy_configure_buffer(indio_dev); 641 638 if (ret < 0) ··· 652 649 iio_simple_dummy_unconfigure_buffer(indio_dev); 653 650 error_unregister_events: 654 651 iio_simple_dummy_events_unregister(indio_dev); 652 + error_free_name: 653 + kfree(indio_dev->name); 655 654 error_free_device: 656 655 iio_device_free(indio_dev); 657 - error_ret: 656 + error_free_swd: 658 657 kfree(swd); 659 - error_kzalloc: 660 658 return ERR_PTR(ret); 661 659 } 662 660
+1 -1
drivers/iio/frequency/ad9523.c
··· 516 516 bool state; 517 517 int ret; 518 518 519 - ret = strtobool(buf, &state); 519 + ret = kstrtobool(buf, &state); 520 520 if (ret < 0) 521 521 return ret; 522 522
+3 -5
drivers/iio/gyro/fxas21002c_core.c
··· 7 7 8 8 #include <linux/interrupt.h> 9 9 #include <linux/module.h> 10 - #include <linux/of_irq.h> 11 10 #include <linux/pm.h> 12 11 #include <linux/pm_runtime.h> 12 + #include <linux/property.h> 13 13 #include <linux/regmap.h> 14 14 #include <linux/regulator/consumer.h> 15 15 ··· 822 822 { 823 823 struct device *dev = regmap_get_device(data->regmap); 824 824 struct iio_dev *indio_dev = dev_get_drvdata(dev); 825 - struct device_node *np = indio_dev->dev.of_node; 826 825 unsigned long irq_trig; 827 826 bool irq_open_drain; 828 827 int irq1; ··· 830 831 if (!data->irq) 831 832 return 0; 832 833 833 - irq1 = of_irq_get_byname(np, "INT1"); 834 - 834 + irq1 = fwnode_irq_get_byname(dev_fwnode(dev), "INT1"); 835 835 if (irq1 == data->irq) { 836 836 dev_info(dev, "using interrupt line INT1\n"); 837 837 ret = regmap_field_write(data->regmap_fields[F_INT_CFG_DRDY], ··· 841 843 842 844 dev_info(dev, "using interrupt line INT2\n"); 843 845 844 - irq_open_drain = of_property_read_bool(np, "drive-open-drain"); 846 + irq_open_drain = device_property_read_bool(dev, "drive-open-drain"); 845 847 846 848 data->dready_trig = devm_iio_trigger_alloc(dev, "%s-dev%d", 847 849 indio_dev->name,
+6 -8
drivers/iio/gyro/mpu3050-core.c
··· 26 26 #include <linux/interrupt.h> 27 27 #include <linux/module.h> 28 28 #include <linux/pm_runtime.h> 29 + #include <linux/property.h> 29 30 #include <linux/random.h> 30 31 #include <linux/slab.h> 31 32 ··· 1051 1050 static int mpu3050_trigger_probe(struct iio_dev *indio_dev, int irq) 1052 1051 { 1053 1052 struct mpu3050 *mpu3050 = iio_priv(indio_dev); 1053 + struct device *dev = mpu3050->dev; 1054 1054 unsigned long irq_trig; 1055 1055 int ret; 1056 1056 ··· 1063 1061 return -ENOMEM; 1064 1062 1065 1063 /* Check if IRQ is open drain */ 1066 - if (of_property_read_bool(mpu3050->dev->of_node, "drive-open-drain")) 1067 - mpu3050->irq_opendrain = true; 1064 + mpu3050->irq_opendrain = device_property_read_bool(dev, "drive-open-drain"); 1068 1065 1069 1066 irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq)); 1070 1067 /* ··· 1119 1118 mpu3050->trig->name, 1120 1119 mpu3050->trig); 1121 1120 if (ret) { 1122 - dev_err(mpu3050->dev, 1123 - "can't get IRQ %d, error %d\n", irq, ret); 1121 + dev_err(dev, "can't get IRQ %d, error %d\n", irq, ret); 1124 1122 return ret; 1125 1123 } 1126 1124 1127 1125 mpu3050->irq = irq; 1128 - mpu3050->trig->dev.parent = mpu3050->dev; 1126 + mpu3050->trig->dev.parent = dev; 1129 1127 mpu3050->trig->ops = &mpu3050_trigger_ops; 1130 1128 iio_trigger_set_drvdata(mpu3050->trig, indio_dev); 1131 1129 ··· 1263 1263 } 1264 1264 EXPORT_SYMBOL(mpu3050_common_probe); 1265 1265 1266 - int mpu3050_common_remove(struct device *dev) 1266 + void mpu3050_common_remove(struct device *dev) 1267 1267 { 1268 1268 struct iio_dev *indio_dev = dev_get_drvdata(dev); 1269 1269 struct mpu3050 *mpu3050 = iio_priv(indio_dev); ··· 1276 1276 free_irq(mpu3050->irq, mpu3050); 1277 1277 iio_device_unregister(indio_dev); 1278 1278 mpu3050_power_down(mpu3050); 1279 - 1280 - return 0; 1281 1279 } 1282 1280 EXPORT_SYMBOL(mpu3050_common_remove); 1283 1281
+3 -1
drivers/iio/gyro/mpu3050-i2c.c
··· 86 86 if (mpu3050->i2cmux) 87 87 i2c_mux_del_adapters(mpu3050->i2cmux); 88 88 89 - return mpu3050_common_remove(&client->dev); 89 + mpu3050_common_remove(&client->dev); 90 + 91 + return 0; 90 92 } 91 93 92 94 /*
+1 -1
drivers/iio/gyro/mpu3050.h
··· 91 91 struct regmap *map, 92 92 int irq, 93 93 const char *name); 94 - int mpu3050_common_remove(struct device *dev); 94 + void mpu3050_common_remove(struct device *dev); 95 95 96 96 /* PM ops */ 97 97 extern const struct dev_pm_ops mpu3050_dev_pm_ops;
-1
drivers/iio/gyro/ssp_gyro_sensor.c
··· 113 113 indio_dev->available_scan_masks = ssp_gyro_scan_mask; 114 114 115 115 ret = devm_iio_kfifo_buffer_setup(&pdev->dev, indio_dev, 116 - INDIO_BUFFER_SOFTWARE, 117 116 &ssp_gyro_buffer_ops); 118 117 if (ret) 119 118 return ret;
+5 -12
drivers/iio/gyro/st_gyro_core.c
··· 406 406 static int st_gyro_write_raw(struct iio_dev *indio_dev, 407 407 struct iio_chan_spec const *chan, int val, int val2, long mask) 408 408 { 409 - int err; 410 - 411 409 switch (mask) { 412 410 case IIO_CHAN_INFO_SCALE: 413 - err = st_sensors_set_fullscale_by_gain(indio_dev, val2); 414 - break; 411 + return st_sensors_set_fullscale_by_gain(indio_dev, val2); 415 412 case IIO_CHAN_INFO_SAMP_FREQ: 416 413 if (val2) 417 414 return -EINVAL; 418 - mutex_lock(&indio_dev->mlock); 419 - err = st_sensors_set_odr(indio_dev, val); 420 - mutex_unlock(&indio_dev->mlock); 421 - return err; 422 - default: 423 - err = -EINVAL; 424 - } 425 415 426 - return err; 416 + return st_sensors_set_odr(indio_dev, val); 417 + default: 418 + return -EINVAL; 419 + } 427 420 } 428 421 429 422 static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
-1
drivers/iio/health/max30100.c
··· 433 433 indio_dev->modes = INDIO_DIRECT_MODE; 434 434 435 435 ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev, 436 - INDIO_BUFFER_SOFTWARE, 437 436 &max30100_buffer_setup_ops); 438 437 if (ret) 439 438 return ret;
-1
drivers/iio/health/max30102.c
··· 542 542 } 543 543 544 544 ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev, 545 - INDIO_BUFFER_SOFTWARE, 546 545 &max30102_buffer_setup_ops); 547 546 if (ret) 548 547 return ret;
+43 -48
drivers/iio/imu/adis16480.c
··· 7 7 8 8 #include <linux/clk.h> 9 9 #include <linux/bitfield.h> 10 - #include <linux/of_irq.h> 11 10 #include <linux/interrupt.h> 11 + #include <linux/irq.h> 12 12 #include <linux/math.h> 13 13 #include <linux/device.h> 14 14 #include <linux/kernel.h> 15 15 #include <linux/spi/spi.h> 16 + #include <linux/mod_devicetable.h> 16 17 #include <linux/module.h> 17 18 #include <linux/lcm.h> 19 + #include <linux/property.h> 18 20 #include <linux/swab.h> 19 21 #include <linux/crc32.h> 20 22 ··· 1121 1119 struct iio_dev *indio_dev = pf->indio_dev; 1122 1120 struct adis16480 *st = iio_priv(indio_dev); 1123 1121 struct adis *adis = &st->adis; 1122 + struct device *dev = &adis->spi->dev; 1124 1123 int ret, bit, offset, i = 0; 1125 1124 __be16 *buffer; 1126 1125 u32 crc; ··· 1133 1130 adis->tx[1] = 0; 1134 1131 ret = spi_write(adis->spi, adis->tx, 2); 1135 1132 if (ret) { 1136 - dev_err(&adis->spi->dev, "Failed to change device page: %d\n", ret); 1133 + dev_err(dev, "Failed to change device page: %d\n", ret); 1137 1134 adis_dev_unlock(adis); 1138 1135 goto irq_done; 1139 1136 } ··· 1143 1140 1144 1141 ret = spi_sync(adis->spi, &adis->msg); 1145 1142 if (ret) { 1146 - dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret); 1143 + dev_err(dev, "Failed to read data: %d\n", ret); 1147 1144 adis_dev_unlock(adis); 1148 1145 goto irq_done; 1149 1146 } ··· 1171 1168 } 1172 1169 1173 1170 if (offset == 4) { 1174 - dev_err(&adis->spi->dev, "Invalid burst data\n"); 1171 + dev_err(dev, "Invalid burst data\n"); 1175 1172 goto irq_done; 1176 1173 } 1177 1174 1178 1175 crc = be16_to_cpu(buffer[offset + 16]) << 16 | be16_to_cpu(buffer[offset + 15]); 1179 1176 valid = adis16480_validate_crc((u16 *)&buffer[offset], 15, crc); 1180 1177 if (!valid) { 1181 - dev_err(&adis->spi->dev, "Invalid crc\n"); 1178 + dev_err(dev, "Invalid crc\n"); 1182 1179 goto irq_done; 1183 1180 } 1184 1181 ··· 1217 1214 static int adis16480_stop_device(struct iio_dev *indio_dev) 1218 1215 { 1219 1216 struct adis16480 *st = iio_priv(indio_dev); 1217 + struct device *dev = &st->adis.spi->dev; 1220 1218 int ret; 1221 1219 1222 1220 ret = adis_write_reg_16(&st->adis, ADIS16480_REG_SLP_CNT, BIT(9)); 1223 1221 if (ret) 1224 - dev_err(&indio_dev->dev, 1225 - "Could not power down device: %d\n", ret); 1222 + dev_err(dev, "Could not power down device: %d\n", ret); 1226 1223 1227 1224 return ret; 1228 1225 } ··· 1242 1239 return __adis_write_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL, val); 1243 1240 } 1244 1241 1245 - static int adis16480_config_irq_pin(struct device_node *of_node, 1246 - struct adis16480 *st) 1242 + static int adis16480_config_irq_pin(struct adis16480 *st) 1247 1243 { 1244 + struct device *dev = &st->adis.spi->dev; 1245 + struct fwnode_handle *fwnode = dev_fwnode(dev); 1248 1246 struct irq_data *desc; 1249 1247 enum adis16480_int_pin pin; 1250 1248 unsigned int irq_type; ··· 1254 1250 1255 1251 desc = irq_get_irq_data(st->adis.spi->irq); 1256 1252 if (!desc) { 1257 - dev_err(&st->adis.spi->dev, "Could not find IRQ %d\n", irq); 1253 + dev_err(dev, "Could not find IRQ %d\n", irq); 1258 1254 return -EINVAL; 1259 1255 } 1260 1256 ··· 1271 1267 */ 1272 1268 pin = ADIS16480_PIN_DIO1; 1273 1269 for (i = 0; i < ARRAY_SIZE(adis16480_int_pin_names); i++) { 1274 - irq = of_irq_get_byname(of_node, adis16480_int_pin_names[i]); 1270 + irq = fwnode_irq_get_byname(fwnode, adis16480_int_pin_names[i]); 1275 1271 if (irq > 0) { 1276 1272 pin = i; 1277 1273 break; ··· 1291 1287 } else if (irq_type == IRQ_TYPE_EDGE_FALLING) { 1292 1288 val |= ADIS16480_DRDY_POL(0); 1293 1289 } else { 1294 - dev_err(&st->adis.spi->dev, 1295 - "Invalid interrupt type 0x%x specified\n", irq_type); 1290 + dev_err(dev, "Invalid interrupt type 0x%x specified\n", irq_type); 1296 1291 return -EINVAL; 1297 1292 } 1298 1293 /* Write the data ready configuration to the FNCTIO_CTRL register */ 1299 1294 return adis_write_reg_16(&st->adis, ADIS16480_REG_FNCTIO_CTRL, val); 1300 1295 } 1301 1296 1302 - static int adis16480_of_get_ext_clk_pin(struct adis16480 *st, 1303 - struct device_node *of_node) 1297 + static int adis16480_fw_get_ext_clk_pin(struct adis16480 *st) 1304 1298 { 1299 + struct device *dev = &st->adis.spi->dev; 1305 1300 const char *ext_clk_pin; 1306 1301 enum adis16480_int_pin pin; 1307 1302 int i; 1308 1303 1309 1304 pin = ADIS16480_PIN_DIO2; 1310 - if (of_property_read_string(of_node, "adi,ext-clk-pin", &ext_clk_pin)) 1305 + if (device_property_read_string(dev, "adi,ext-clk-pin", &ext_clk_pin)) 1311 1306 goto clk_input_not_found; 1312 1307 1313 1308 for (i = 0; i < ARRAY_SIZE(adis16480_int_pin_names); i++) { ··· 1315 1312 } 1316 1313 1317 1314 clk_input_not_found: 1318 - dev_info(&st->adis.spi->dev, 1319 - "clk input line not specified, using DIO2\n"); 1315 + dev_info(dev, "clk input line not specified, using DIO2\n"); 1320 1316 return pin; 1321 1317 } 1322 1318 1323 - static int adis16480_ext_clk_config(struct adis16480 *st, 1324 - struct device_node *of_node, 1325 - bool enable) 1319 + static int adis16480_ext_clk_config(struct adis16480 *st, bool enable) 1326 1320 { 1321 + struct device *dev = &st->adis.spi->dev; 1327 1322 unsigned int mode, mask; 1328 1323 enum adis16480_int_pin pin; 1329 1324 uint16_t val; ··· 1331 1330 if (ret) 1332 1331 return ret; 1333 1332 1334 - pin = adis16480_of_get_ext_clk_pin(st, of_node); 1333 + pin = adis16480_fw_get_ext_clk_pin(st); 1335 1334 /* 1336 1335 * Each DIOx pin supports only one function at a time. When a single pin 1337 1336 * has two assignments, the enable bit for a lower priority function 1338 1337 * automatically resets to zero (disabling the lower priority function). 1339 1338 */ 1340 1339 if (pin == ADIS16480_DRDY_SEL(val)) 1341 - dev_warn(&st->adis.spi->dev, 1342 - "DIO%x pin supports only one function at a time\n", 1343 - pin + 1); 1340 + dev_warn(dev, "DIO%x pin supports only one function at a time\n", pin + 1); 1344 1341 1345 1342 mode = ADIS16480_SYNC_EN(enable) | ADIS16480_SYNC_SEL(pin); 1346 1343 mask = ADIS16480_SYNC_EN_MSK | ADIS16480_SYNC_SEL_MSK; ··· 1360 1361 1361 1362 static int adis16480_get_ext_clocks(struct adis16480 *st) 1362 1363 { 1363 - st->clk_mode = ADIS16480_CLK_INT; 1364 - st->ext_clk = devm_clk_get(&st->adis.spi->dev, "sync"); 1365 - if (!IS_ERR_OR_NULL(st->ext_clk)) { 1364 + struct device *dev = &st->adis.spi->dev; 1365 + 1366 + st->ext_clk = devm_clk_get_optional(dev, "sync"); 1367 + if (IS_ERR(st->ext_clk)) 1368 + return dev_err_probe(dev, PTR_ERR(st->ext_clk), "failed to get ext clk\n"); 1369 + if (st->ext_clk) { 1366 1370 st->clk_mode = ADIS16480_CLK_SYNC; 1367 1371 return 0; 1368 1372 } 1369 1373 1370 - if (PTR_ERR(st->ext_clk) != -ENOENT) { 1371 - dev_err(&st->adis.spi->dev, "failed to get ext clk\n"); 1372 - return PTR_ERR(st->ext_clk); 1373 - } 1374 - 1375 1374 if (st->chip_info->has_pps_clk_mode) { 1376 - st->ext_clk = devm_clk_get(&st->adis.spi->dev, "pps"); 1377 - if (!IS_ERR_OR_NULL(st->ext_clk)) { 1375 + st->ext_clk = devm_clk_get_optional(dev, "pps"); 1376 + if (IS_ERR(st->ext_clk)) 1377 + return dev_err_probe(dev, PTR_ERR(st->ext_clk), "failed to get ext clk\n"); 1378 + if (st->ext_clk) { 1378 1379 st->clk_mode = ADIS16480_CLK_PPS; 1379 1380 return 0; 1380 1381 } 1381 - 1382 - if (PTR_ERR(st->ext_clk) != -ENOENT) { 1383 - dev_err(&st->adis.spi->dev, "failed to get ext clk\n"); 1384 - return PTR_ERR(st->ext_clk); 1385 - } 1386 1382 } 1387 1383 1384 + st->clk_mode = ADIS16480_CLK_INT; 1388 1385 return 0; 1389 1386 } 1390 1387 ··· 1399 1404 const struct spi_device_id *id = spi_get_device_id(spi); 1400 1405 const struct adis_data *adis16480_data; 1401 1406 irq_handler_t trigger_handler = NULL; 1407 + struct device *dev = &spi->dev; 1402 1408 struct iio_dev *indio_dev; 1403 1409 struct adis16480 *st; 1404 1410 int ret; 1405 1411 1406 - indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 1412 + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 1407 1413 if (indio_dev == NULL) 1408 1414 return -ENOMEM; 1409 1415 ··· 1428 1432 return ret; 1429 1433 1430 1434 if (st->chip_info->has_sleep_cnt) { 1431 - ret = devm_add_action_or_reset(&spi->dev, adis16480_stop, 1432 - indio_dev); 1435 + ret = devm_add_action_or_reset(dev, adis16480_stop, indio_dev); 1433 1436 if (ret) 1434 1437 return ret; 1435 1438 } 1436 1439 1437 - ret = adis16480_config_irq_pin(spi->dev.of_node, st); 1440 + ret = adis16480_config_irq_pin(st); 1438 1441 if (ret) 1439 1442 return ret; 1440 1443 ··· 1441 1446 if (ret) 1442 1447 return ret; 1443 1448 1444 - if (!IS_ERR_OR_NULL(st->ext_clk)) { 1445 - ret = adis16480_ext_clk_config(st, spi->dev.of_node, true); 1449 + if (st->ext_clk) { 1450 + ret = adis16480_ext_clk_config(st, true); 1446 1451 if (ret) 1447 1452 return ret; 1448 1453 1449 - ret = devm_add_action_or_reset(&spi->dev, adis16480_clk_disable, st->ext_clk); 1454 + ret = devm_add_action_or_reset(dev, adis16480_clk_disable, st->ext_clk); 1450 1455 if (ret) 1451 1456 return ret; 1452 1457 ··· 1479 1484 if (ret) 1480 1485 return ret; 1481 1486 1482 - ret = devm_iio_device_register(&spi->dev, indio_dev); 1487 + ret = devm_iio_device_register(dev, indio_dev); 1483 1488 if (ret) 1484 1489 return ret; 1485 1490
+6 -21
drivers/iio/imu/bmi160/bmi160_core.c
··· 11 11 */ 12 12 #include <linux/module.h> 13 13 #include <linux/regmap.h> 14 - #include <linux/acpi.h> 15 14 #include <linux/delay.h> 16 15 #include <linux/irq.h> 17 - #include <linux/of_irq.h> 16 + #include <linux/property.h> 18 17 #include <linux/regulator/consumer.h> 19 18 20 19 #include <linux/iio/iio.h> ··· 524 525 .attrs = &bmi160_attrs_group, 525 526 }; 526 527 527 - static const char *bmi160_match_acpi_device(struct device *dev) 528 - { 529 - const struct acpi_device_id *id; 530 - 531 - id = acpi_match_device(dev->driver->acpi_match_table, dev); 532 - if (!id) 533 - return NULL; 534 - 535 - return dev_name(dev); 536 - } 537 - 538 528 static int bmi160_write_conf_reg(struct regmap *regmap, unsigned int reg, 539 529 unsigned int mask, unsigned int bits, 540 530 unsigned int write_usleep) ··· 635 647 } 636 648 EXPORT_SYMBOL(bmi160_enable_irq); 637 649 638 - static int bmi160_get_irq(struct device_node *of_node, enum bmi160_int_pin *pin) 650 + static int bmi160_get_irq(struct fwnode_handle *fwnode, enum bmi160_int_pin *pin) 639 651 { 640 652 int irq; 641 653 642 654 /* Use INT1 if possible, otherwise fall back to INT2. */ 643 - irq = of_irq_get_byname(of_node, "INT1"); 655 + irq = fwnode_irq_get_byname(fwnode, "INT1"); 644 656 if (irq > 0) { 645 657 *pin = BMI160_PIN_INT1; 646 658 return irq; 647 659 } 648 660 649 - irq = of_irq_get_byname(of_node, "INT2"); 661 + irq = fwnode_irq_get_byname(fwnode, "INT2"); 650 662 if (irq > 0) 651 663 *pin = BMI160_PIN_INT2; 652 664 ··· 676 688 return -EINVAL; 677 689 } 678 690 679 - open_drain = of_property_read_bool(dev->of_node, "drive-open-drain"); 691 + open_drain = device_property_read_bool(dev, "drive-open-drain"); 680 692 681 693 return bmi160_config_pin(data->regmap, pin, open_drain, irq_mask, 682 694 BMI160_NORMAL_WRITE_USLEEP); ··· 860 872 if (ret) 861 873 return ret; 862 874 863 - if (!name && ACPI_HANDLE(dev)) 864 - name = bmi160_match_acpi_device(dev); 865 - 866 875 indio_dev->channels = bmi160_channels; 867 876 indio_dev->num_channels = ARRAY_SIZE(bmi160_channels); 868 877 indio_dev->name = name; ··· 872 887 if (ret) 873 888 return ret; 874 889 875 - irq = bmi160_get_irq(dev->of_node, &int_pin); 890 + irq = bmi160_get_irq(dev_fwnode(dev), &int_pin); 876 891 if (irq > 0) { 877 892 ret = bmi160_setup_irq(indio_dev, irq, int_pin); 878 893 if (ret)
+6 -7
drivers/iio/imu/bmi160/bmi160_i2c.c
··· 8 8 * - 0x68 if SDO is pulled to GND 9 9 * - 0x69 if SDO is pulled to VDDIO 10 10 */ 11 - #include <linux/acpi.h> 12 11 #include <linux/i2c.h> 12 + #include <linux/mod_devicetable.h> 13 13 #include <linux/module.h> 14 - #include <linux/of.h> 15 14 #include <linux/regmap.h> 16 15 17 16 #include "bmi160.h" ··· 19 20 const struct i2c_device_id *id) 20 21 { 21 22 struct regmap *regmap; 22 - const char *name = NULL; 23 + const char *name; 23 24 24 25 regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config); 25 26 if (IS_ERR(regmap)) { ··· 30 31 31 32 if (id) 32 33 name = id->name; 34 + else 35 + name = dev_name(&client->dev); 33 36 34 37 return bmi160_core_probe(&client->dev, regmap, name, false); 35 38 } ··· 48 47 }; 49 48 MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match); 50 49 51 - #ifdef CONFIG_OF 52 50 static const struct of_device_id bmi160_of_match[] = { 53 51 { .compatible = "bosch,bmi160" }, 54 52 { }, 55 53 }; 56 54 MODULE_DEVICE_TABLE(of, bmi160_of_match); 57 - #endif 58 55 59 56 static struct i2c_driver bmi160_i2c_driver = { 60 57 .driver = { 61 58 .name = "bmi160_i2c", 62 - .acpi_match_table = ACPI_PTR(bmi160_acpi_match), 63 - .of_match_table = of_match_ptr(bmi160_of_match), 59 + .acpi_match_table = bmi160_acpi_match, 60 + .of_match_table = bmi160_of_match, 64 61 }, 65 62 .probe = bmi160_i2c_probe, 66 63 .id_table = bmi160_i2c_id,
+11 -7
drivers/iio/imu/bmi160/bmi160_spi.c
··· 5 5 * Copyright (c) 2016, Intel Corporation. 6 6 * 7 7 */ 8 - #include <linux/acpi.h> 8 + #include <linux/mod_devicetable.h> 9 9 #include <linux/module.h> 10 - #include <linux/of.h> 11 10 #include <linux/regmap.h> 12 11 #include <linux/spi/spi.h> 13 12 ··· 16 17 { 17 18 struct regmap *regmap; 18 19 const struct spi_device_id *id = spi_get_device_id(spi); 20 + const char *name; 19 21 20 22 regmap = devm_regmap_init_spi(spi, &bmi160_regmap_config); 21 23 if (IS_ERR(regmap)) { ··· 24 24 regmap); 25 25 return PTR_ERR(regmap); 26 26 } 27 - return bmi160_core_probe(&spi->dev, regmap, id->name, true); 27 + 28 + if (id) 29 + name = id->name; 30 + else 31 + name = dev_name(&spi->dev); 32 + 33 + return bmi160_core_probe(&spi->dev, regmap, name, true); 28 34 } 29 35 30 36 static const struct spi_device_id bmi160_spi_id[] = { ··· 45 39 }; 46 40 MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match); 47 41 48 - #ifdef CONFIG_OF 49 42 static const struct of_device_id bmi160_of_match[] = { 50 43 { .compatible = "bosch,bmi160" }, 51 44 { }, 52 45 }; 53 46 MODULE_DEVICE_TABLE(of, bmi160_of_match); 54 - #endif 55 47 56 48 static struct spi_driver bmi160_spi_driver = { 57 49 .probe = bmi160_spi_probe, 58 50 .id_table = bmi160_spi_id, 59 51 .driver = { 60 - .acpi_match_table = ACPI_PTR(bmi160_acpi_match), 61 - .of_match_table = of_match_ptr(bmi160_of_match), 52 + .acpi_match_table = bmi160_acpi_match, 53 + .of_match_table = bmi160_of_match, 62 54 .name = "bmi160_spi", 63 55 }, 64 56 };
-1
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
··· 731 731 indio_dev->available_scan_masks = inv_icm42600_accel_scan_masks; 732 732 733 733 ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, 734 - INDIO_BUFFER_SOFTWARE, 735 734 &inv_icm42600_buffer_ops); 736 735 if (ret) 737 736 return ERR_PTR(ret);
-1
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
··· 743 743 indio_dev->setup_ops = &inv_icm42600_buffer_ops; 744 744 745 745 ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, 746 - INDIO_BUFFER_SOFTWARE, 747 746 &inv_icm42600_buffer_ops); 748 747 if (ret) 749 748 return ERR_PTR(ret);
+2 -2
drivers/iio/imu/inv_mpu6050/Kconfig
··· 16 16 select REGMAP_I2C 17 17 help 18 18 This driver supports the Invensense MPU6050/9150, 19 - MPU6500/6515/6880/9250/9255, ICM20608/20609/20689, ICM20602/ICM20690 19 + MPU6500/6515/6880/9250/9255, ICM20608(D)/20609/20689, ICM20602/ICM20690 20 20 and IAM20680 motion tracking devices over I2C. 21 21 This driver can be built as a module. The module will be called 22 22 inv-mpu6050-i2c. ··· 28 28 select REGMAP_SPI 29 29 help 30 30 This driver supports the Invensense MPU6000, 31 - MPU6500/6515/6880/9250/9255, ICM20608/20609/20689, ICM20602/ICM20690 31 + MPU6500/6515/6880/9250/9255, ICM20608(D)/20609/20689, ICM20602/ICM20690 32 32 and IAM20680 motion tracking devices over SPI. 33 33 This driver can be built as a module. The module will be called 34 34 inv-mpu6050-spi.
+9
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 218 218 .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 219 219 }, 220 220 { 221 + .whoami = INV_ICM20608D_WHOAMI_VALUE, 222 + .name = "ICM20608D", 223 + .reg = &reg_set_6500, 224 + .config = &chip_config_6500, 225 + .fifo_size = 512, 226 + .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, 227 + .startup_time = {INV_MPU6500_GYRO_STARTUP_TIME, INV_MPU6500_ACCEL_STARTUP_TIME}, 228 + }, 229 + { 221 230 .whoami = INV_ICM20609_WHOAMI_VALUE, 222 231 .name = "ICM20609", 223 232 .reg = &reg_set_6500,
+6
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
··· 29 29 30 30 switch (st->chip_type) { 31 31 case INV_ICM20608: 32 + case INV_ICM20608D: 32 33 case INV_ICM20609: 33 34 case INV_ICM20689: 34 35 case INV_ICM20602: ··· 183 182 {"mpu9250", INV_MPU9250}, 184 183 {"mpu9255", INV_MPU9255}, 185 184 {"icm20608", INV_ICM20608}, 185 + {"icm20608d", INV_ICM20608D}, 186 186 {"icm20609", INV_ICM20609}, 187 187 {"icm20689", INV_ICM20689}, 188 188 {"icm20602", INV_ICM20602}, ··· 226 224 { 227 225 .compatible = "invensense,icm20608", 228 226 .data = (void *)INV_ICM20608 227 + }, 228 + { 229 + .compatible = "invensense,icm20608d", 230 + .data = (void *)INV_ICM20608D 229 231 }, 230 232 { 231 233 .compatible = "invensense,icm20609",
+2
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
··· 76 76 INV_MPU9250, 77 77 INV_MPU9255, 78 78 INV_ICM20608, 79 + INV_ICM20608D, 79 80 INV_ICM20609, 80 81 INV_ICM20689, 81 82 INV_ICM20602, ··· 395 394 #define INV_MPU9255_WHOAMI_VALUE 0x73 396 395 #define INV_MPU6515_WHOAMI_VALUE 0x74 397 396 #define INV_ICM20608_WHOAMI_VALUE 0xAF 397 + #define INV_ICM20608D_WHOAMI_VALUE 0xAE 398 398 #define INV_ICM20609_WHOAMI_VALUE 0xA6 399 399 #define INV_ICM20689_WHOAMI_VALUE 0x98 400 400 #define INV_ICM20602_WHOAMI_VALUE 0x12
+5
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
··· 73 73 {"mpu9250", INV_MPU9250}, 74 74 {"mpu9255", INV_MPU9255}, 75 75 {"icm20608", INV_ICM20608}, 76 + {"icm20608d", INV_ICM20608D}, 76 77 {"icm20609", INV_ICM20609}, 77 78 {"icm20689", INV_ICM20689}, 78 79 {"icm20602", INV_ICM20602}, ··· 112 111 { 113 112 .compatible = "invensense,icm20608", 114 113 .data = (void *)INV_ICM20608 114 + }, 115 + { 116 + .compatible = "invensense,icm20608d", 117 + .data = (void *)INV_ICM20608D 115 118 }, 116 119 { 117 120 .compatible = "invensense,icm20609",
+3 -3
drivers/iio/imu/st_lsm6dsx/Kconfig
··· 11 11 help 12 12 Say yes here to build support for STMicroelectronics LSM6DSx imu 13 13 sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm, 14 - ism330dlc, lsm6dso, lsm6dsox, asm330lhh, lsm6dsr, lsm6ds3tr-c, 15 - ism330dhcx, lsm6dsrx, lsm6ds0, lsm6dsop, the accelerometer/gyroscope 16 - of lsm9ds1 and lsm6dst. 14 + ism330dlc, lsm6dso, lsm6dsox, asm330lhh, asm330lhhx, lsm6dsr, 15 + lsm6ds3tr-c, ism330dhcx, lsm6dsrx, lsm6ds0, lsm6dsop, 16 + the accelerometer/gyroscope of lsm9ds1 and lsm6dst. 17 17 18 18 To compile this driver as a module, choose M here: the module 19 19 will be called st_lsm6dsx.
+2
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
··· 31 31 #define ST_LSM6DSRX_DEV_NAME "lsm6dsrx" 32 32 #define ST_LSM6DST_DEV_NAME "lsm6dst" 33 33 #define ST_LSM6DSOP_DEV_NAME "lsm6dsop" 34 + #define ST_ASM330LHHX_DEV_NAME "asm330lhhx" 34 35 35 36 enum st_lsm6dsx_hw_id { 36 37 ST_LSM6DS3_ID, ··· 50 49 ST_LSM6DSRX_ID, 51 50 ST_LSM6DST_ID, 52 51 ST_LSM6DSOP_ID, 52 + ST_ASM330LHHX_ID, 53 53 ST_LSM6DSX_MAX_ID, 54 54 }; 55 55
+2 -2
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
··· 14 14 * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated depending on the 15 15 * value of the decimation factor and ODR set for each FIFO data set. 16 16 * 17 - * LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR/LSM6DSRX/ISM330DHCX/LSM6DST/LSM6DSOP: 17 + * LSM6DSO/LSM6DSOX/ASM330LHH/ASM330LHHX/LSM6DSR/LSM6DSRX/ISM330DHCX/ 18 + * LSM6DST/LSM6DSOP: 18 19 * The FIFO buffer can be configured to store data from gyroscope and 19 20 * accelerometer. Each sample is queued with a tag (1B) indicating data 20 21 * source (gyroscope, accelerometer, hw timer). ··· 747 746 continue; 748 747 749 748 ret = devm_iio_kfifo_buffer_setup(hw->dev, hw->iio_devs[i], 750 - INDIO_BUFFER_SOFTWARE, 751 749 &st_lsm6dsx_buffer_ops); 752 750 if (ret) 753 751 return ret;
+5 -1
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 26 26 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 27 27 * - FIFO size: 4KB 28 28 * 29 - * - LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR/ISM330DHCX/LSM6DST/LSM6DSOP: 29 + * - LSM6DSO/LSM6DSOX/ASM330LHH/ASM330LHHX/LSM6DSR/ISM330DHCX/LSM6DST/LSM6DSOP: 30 30 * - Accelerometer/Gyroscope supported ODR [Hz]: 12.5, 26, 52, 104, 208, 416, 31 31 * 833 32 32 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 ··· 786 786 .hw_id = ST_LSM6DST_ID, 787 787 .name = ST_LSM6DST_DEV_NAME, 788 788 .wai = 0x6d, 789 + }, { 790 + .hw_id = ST_ASM330LHHX_ID, 791 + .name = ST_ASM330LHHX_DEV_NAME, 792 + .wai = 0x6b, 789 793 }, 790 794 }, 791 795 .channels = {
+5
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
··· 101 101 .compatible = "st,lsm6dsop", 102 102 .data = (void *)ST_LSM6DSOP_ID, 103 103 }, 104 + { 105 + .compatible = "st,asm330lhhx", 106 + .data = (void *)ST_ASM330LHHX_ID, 107 + }, 104 108 {}, 105 109 }; 106 110 MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match); ··· 126 122 { ST_LSM6DSRX_DEV_NAME, ST_LSM6DSRX_ID }, 127 123 { ST_LSM6DST_DEV_NAME, ST_LSM6DST_ID }, 128 124 { ST_LSM6DSOP_DEV_NAME, ST_LSM6DSOP_ID }, 125 + { ST_ASM330LHHX_DEV_NAME, ST_ASM330LHHX_ID }, 129 126 {}, 130 127 }; 131 128 MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
+5
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
··· 101 101 .compatible = "st,lsm6dsop", 102 102 .data = (void *)ST_LSM6DSOP_ID, 103 103 }, 104 + { 105 + .compatible = "st,asm330lhhx", 106 + .data = (void *)ST_ASM330LHHX_ID, 107 + }, 104 108 {}, 105 109 }; 106 110 MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match); ··· 126 122 { ST_LSM6DSRX_DEV_NAME, ST_LSM6DSRX_ID }, 127 123 { ST_LSM6DST_DEV_NAME, ST_LSM6DST_ID }, 128 124 { ST_LSM6DSOP_DEV_NAME, ST_LSM6DSOP_ID }, 125 + { ST_ASM330LHHX_DEV_NAME, ST_ASM330LHHX_ID }, 129 126 {}, 130 127 }; 131 128 MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
+29 -13
drivers/iio/industrialio-buffer.c
··· 510 510 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 511 511 struct iio_buffer *buffer = this_attr->buffer; 512 512 513 - ret = strtobool(buf, &state); 513 + ret = kstrtobool(buf, &state); 514 514 if (ret < 0) 515 515 return ret; 516 516 mutex_lock(&indio_dev->mlock); ··· 557 557 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 558 558 bool state; 559 559 560 - ret = strtobool(buf, &state); 560 + ret = kstrtobool(buf, &state); 561 561 if (ret < 0) 562 562 return ret; 563 563 ··· 915 915 if (scan_mask == NULL) 916 916 return -EINVAL; 917 917 } else { 918 - scan_mask = compound_mask; 918 + scan_mask = compound_mask; 919 919 } 920 920 921 921 config->scan_bytes = iio_compute_scan_bytes(indio_dev, ··· 1059 1059 struct iio_device_config *config) 1060 1060 { 1061 1061 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 1062 - struct iio_buffer *buffer; 1062 + struct iio_buffer *buffer, *tmp = NULL; 1063 1063 int ret; 1064 1064 1065 1065 indio_dev->active_scan_mask = config->scan_mask; 1066 1066 indio_dev->scan_timestamp = config->scan_timestamp; 1067 1067 indio_dev->scan_bytes = config->scan_bytes; 1068 - indio_dev->currentmode = config->mode; 1068 + iio_dev_opaque->currentmode = config->mode; 1069 1069 1070 1070 iio_update_demux(indio_dev); 1071 1071 ··· 1097 1097 1098 1098 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { 1099 1099 ret = iio_buffer_enable(buffer, indio_dev); 1100 - if (ret) 1100 + if (ret) { 1101 + tmp = buffer; 1101 1102 goto err_disable_buffers; 1103 + } 1102 1104 } 1103 1105 1104 - if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { 1106 + if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) { 1105 1107 ret = iio_trigger_attach_poll_func(indio_dev->trig, 1106 1108 indio_dev->pollfunc); 1107 1109 if (ret) ··· 1122 1120 return 0; 1123 1121 1124 1122 err_detach_pollfunc: 1125 - if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { 1123 + if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) { 1126 1124 iio_trigger_detach_poll_func(indio_dev->trig, 1127 1125 indio_dev->pollfunc); 1128 1126 } 1129 1127 err_disable_buffers: 1128 + buffer = list_prepare_entry(tmp, &iio_dev_opaque->buffer_list, buffer_list); 1130 1129 list_for_each_entry_continue_reverse(buffer, &iio_dev_opaque->buffer_list, 1131 1130 buffer_list) 1132 1131 iio_buffer_disable(buffer, indio_dev); ··· 1135 1132 if (indio_dev->setup_ops->postdisable) 1136 1133 indio_dev->setup_ops->postdisable(indio_dev); 1137 1134 err_undo_config: 1138 - indio_dev->currentmode = INDIO_DIRECT_MODE; 1135 + iio_dev_opaque->currentmode = INDIO_DIRECT_MODE; 1139 1136 indio_dev->active_scan_mask = NULL; 1140 1137 1141 1138 return ret; ··· 1165 1162 ret = ret2; 1166 1163 } 1167 1164 1168 - if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { 1165 + if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) { 1169 1166 iio_trigger_detach_poll_func(indio_dev->trig, 1170 1167 indio_dev->pollfunc); 1171 1168 } ··· 1184 1181 1185 1182 iio_free_scan_mask(indio_dev, indio_dev->active_scan_mask); 1186 1183 indio_dev->active_scan_mask = NULL; 1187 - indio_dev->currentmode = INDIO_DIRECT_MODE; 1184 + iio_dev_opaque->currentmode = INDIO_DIRECT_MODE; 1188 1185 1189 1186 return ret; 1190 1187 } ··· 1303 1300 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 1304 1301 bool inlist; 1305 1302 1306 - ret = strtobool(buf, &requested_state); 1303 + ret = kstrtobool(buf, &requested_state); 1307 1304 if (ret < 0) 1308 1305 return ret; 1309 1306 ··· 1632 1629 if (channels[i].scan_index < 0) 1633 1630 continue; 1634 1631 1632 + /* Verify that sample bits fit into storage */ 1633 + if (channels[i].scan_type.storagebits < 1634 + channels[i].scan_type.realbits + 1635 + channels[i].scan_type.shift) { 1636 + dev_err(&indio_dev->dev, 1637 + "Channel %d storagebits (%d) < shifted realbits (%d + %d)\n", 1638 + i, channels[i].scan_type.storagebits, 1639 + channels[i].scan_type.realbits, 1640 + channels[i].scan_type.shift); 1641 + ret = -EINVAL; 1642 + goto error_cleanup_dynamic; 1643 + } 1644 + 1635 1645 ret = iio_buffer_add_channel_sysfs(indio_dev, buffer, 1636 1646 &channels[i]); 1637 1647 if (ret < 0) ··· 1665 1649 } 1666 1650 1667 1651 attrn = buffer_attrcount + scan_el_attrcount + ARRAY_SIZE(iio_buffer_attrs); 1668 - attr = kcalloc(attrn + 1, sizeof(* attr), GFP_KERNEL); 1652 + attr = kcalloc(attrn + 1, sizeof(*attr), GFP_KERNEL); 1669 1653 if (!attr) { 1670 1654 ret = -ENOMEM; 1671 1655 goto error_free_scan_mask;
+37 -9
drivers/iio/industrialio-core.c
··· 185 185 EXPORT_SYMBOL_GPL(iio_device_id); 186 186 187 187 /** 188 + * iio_buffer_enabled() - helper function to test if the buffer is enabled 189 + * @indio_dev: IIO device structure for device 190 + */ 191 + bool iio_buffer_enabled(struct iio_dev *indio_dev) 192 + { 193 + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 194 + 195 + return iio_dev_opaque->currentmode 196 + & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE | 197 + INDIO_BUFFER_SOFTWARE); 198 + } 199 + EXPORT_SYMBOL_GPL(iio_buffer_enabled); 200 + 201 + /** 188 202 * iio_sysfs_match_string_with_gaps - matches given string in an array with gaps 189 203 * @array: array of strings 190 204 * @n: number of strings in the array ··· 906 892 } else if (*str == '\n') { 907 893 if (*(str + 1) == '\0') 908 894 break; 909 - else 910 - return -EINVAL; 895 + return -EINVAL; 911 896 } else if (!strncmp(str, " dB", sizeof(" dB") - 1) && scale_db) { 912 897 /* Ignore the dB suffix */ 913 898 str += sizeof(" dB") - 1; ··· 1907 1894 int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) 1908 1895 { 1909 1896 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 1910 - const char *label; 1897 + struct fwnode_handle *fwnode; 1911 1898 int ret; 1912 1899 1913 1900 if (!indio_dev->info) 1914 1901 return -EINVAL; 1915 1902 1916 1903 iio_dev_opaque->driver_module = this_mod; 1917 - /* If the calling driver did not initialize of_node, do it here */ 1918 - if (!indio_dev->dev.of_node && indio_dev->dev.parent) 1919 - indio_dev->dev.of_node = indio_dev->dev.parent->of_node; 1920 1904 1921 - label = of_get_property(indio_dev->dev.of_node, "label", NULL); 1922 - if (label) 1923 - indio_dev->label = label; 1905 + /* If the calling driver did not initialize firmware node, do it here */ 1906 + if (dev_fwnode(&indio_dev->dev)) 1907 + fwnode = dev_fwnode(&indio_dev->dev); 1908 + else 1909 + fwnode = dev_fwnode(indio_dev->dev.parent); 1910 + device_set_node(&indio_dev->dev, fwnode); 1911 + 1912 + fwnode_property_read_string(fwnode, "label", &indio_dev->label); 1924 1913 1925 1914 ret = iio_check_unique_scan_index(indio_dev); 1926 1915 if (ret < 0) ··· 2073 2058 mutex_unlock(&indio_dev->mlock); 2074 2059 } 2075 2060 EXPORT_SYMBOL_GPL(iio_device_release_direct_mode); 2061 + 2062 + /** 2063 + * iio_device_get_current_mode() - helper function providing read-only access to 2064 + * the opaque @currentmode variable 2065 + * @indio_dev: IIO device structure for device 2066 + */ 2067 + int iio_device_get_current_mode(struct iio_dev *indio_dev) 2068 + { 2069 + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 2070 + 2071 + return iio_dev_opaque->currentmode; 2072 + } 2073 + EXPORT_SYMBOL_GPL(iio_device_get_current_mode); 2076 2074 2077 2075 subsys_initcall(iio_init); 2078 2076 module_exit(iio_exit);
+1 -1
drivers/iio/industrialio-event.c
··· 274 274 int ret; 275 275 bool val; 276 276 277 - ret = strtobool(buf, &val); 277 + ret = kstrtobool(buf, &val); 278 278 if (ret < 0) 279 279 return ret; 280 280
+1 -1
drivers/iio/industrialio-trigger.c
··· 444 444 int ret; 445 445 446 446 mutex_lock(&indio_dev->mlock); 447 - if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { 447 + if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) { 448 448 mutex_unlock(&indio_dev->mlock); 449 449 return -EBUSY; 450 450 }
-1
drivers/iio/light/Kconfig
··· 155 155 156 156 config CM3605 157 157 tristate "Capella CM3605 ambient light and proximity sensor" 158 - depends on OF 159 158 help 160 159 Say Y here if you want to build a driver for Capella CM3605 161 160 ambient light and short range proximity sensor.
-1
drivers/iio/light/apds9960.c
··· 1003 1003 indio_dev->modes = INDIO_DIRECT_MODE; 1004 1004 1005 1005 ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev, 1006 - INDIO_BUFFER_SOFTWARE, 1007 1006 &apds9960_buffer_setup_ops); 1008 1007 if (ret) 1009 1008 return ret;
+25
drivers/iio/light/stk3310.c
··· 106 106 struct mutex lock; 107 107 bool als_enabled; 108 108 bool ps_enabled; 109 + uint32_t ps_near_level; 109 110 u64 timestamp; 110 111 struct regmap *regmap; 111 112 struct regmap_field *reg_state; ··· 136 135 }, 137 136 }; 138 137 138 + static ssize_t stk3310_read_near_level(struct iio_dev *indio_dev, 139 + uintptr_t priv, 140 + const struct iio_chan_spec *chan, 141 + char *buf) 142 + { 143 + struct stk3310_data *data = iio_priv(indio_dev); 144 + 145 + return sprintf(buf, "%u\n", data->ps_near_level); 146 + } 147 + 148 + static const struct iio_chan_spec_ext_info stk3310_ext_info[] = { 149 + { 150 + .name = "nearlevel", 151 + .shared = IIO_SEPARATE, 152 + .read = stk3310_read_near_level, 153 + }, 154 + { /* sentinel */ } 155 + }; 156 + 139 157 static const struct iio_chan_spec stk3310_channels[] = { 140 158 { 141 159 .type = IIO_LIGHT, ··· 171 151 BIT(IIO_CHAN_INFO_INT_TIME), 172 152 .event_spec = stk3310_events, 173 153 .num_event_specs = ARRAY_SIZE(stk3310_events), 154 + .ext_info = stk3310_ext_info, 174 155 } 175 156 }; 176 157 ··· 602 581 data = iio_priv(indio_dev); 603 582 data->client = client; 604 583 i2c_set_clientdata(client, indio_dev); 584 + 585 + device_property_read_u32(&client->dev, "proximity-near-level", 586 + &data->ps_near_level); 587 + 605 588 mutex_init(&data->lock); 606 589 607 590 ret = stk3310_regmap_init(data);
+10 -15
drivers/iio/light/tsl2772.c
··· 15 15 #include <linux/kernel.h> 16 16 #include <linux/module.h> 17 17 #include <linux/mutex.h> 18 + #include <linux/property.h> 18 19 #include <linux/slab.h> 20 + 19 21 #include <linux/iio/events.h> 20 22 #include <linux/iio/iio.h> 21 23 #include <linux/iio/sysfs.h> ··· 551 549 552 550 static int tsl2772_read_prox_led_current(struct tsl2772_chip *chip) 553 551 { 554 - struct device_node *of_node = chip->client->dev.of_node; 552 + struct device *dev = &chip->client->dev; 555 553 int ret, tmp, i; 556 554 557 - ret = of_property_read_u32(of_node, "led-max-microamp", &tmp); 555 + ret = device_property_read_u32(dev, "led-max-microamp", &tmp); 558 556 if (ret < 0) 559 557 return ret; 560 558 ··· 565 563 } 566 564 } 567 565 568 - dev_err(&chip->client->dev, "Invalid value %d for led-max-microamp\n", 569 - tmp); 566 + dev_err(dev, "Invalid value %d for led-max-microamp\n", tmp); 570 567 571 568 return -EINVAL; 572 - 573 569 } 574 570 575 571 static int tsl2772_read_prox_diodes(struct tsl2772_chip *chip) 576 572 { 577 - struct device_node *of_node = chip->client->dev.of_node; 573 + struct device *dev = &chip->client->dev; 578 574 int i, ret, num_leds, prox_diode_mask; 579 575 u32 leds[TSL2772_MAX_PROX_LEDS]; 580 576 581 - ret = of_property_count_u32_elems(of_node, "amstaos,proximity-diodes"); 577 + ret = device_property_count_u32(dev, "amstaos,proximity-diodes"); 582 578 if (ret < 0) 583 579 return ret; 584 580 ··· 584 584 if (num_leds > TSL2772_MAX_PROX_LEDS) 585 585 num_leds = TSL2772_MAX_PROX_LEDS; 586 586 587 - ret = of_property_read_u32_array(of_node, "amstaos,proximity-diodes", 588 - leds, num_leds); 587 + ret = device_property_read_u32_array(dev, "amstaos,proximity-diodes", leds, num_leds); 589 588 if (ret < 0) { 590 - dev_err(&chip->client->dev, 591 - "Invalid value for amstaos,proximity-diodes: %d.\n", 592 - ret); 589 + dev_err(dev, "Invalid value for amstaos,proximity-diodes: %d.\n", ret); 593 590 return ret; 594 591 } 595 592 ··· 597 600 else if (leds[i] == 1) 598 601 prox_diode_mask |= TSL2772_DIODE1; 599 602 else { 600 - dev_err(&chip->client->dev, 601 - "Invalid value %d in amstaos,proximity-diodes.\n", 602 - leds[i]); 603 + dev_err(dev, "Invalid value %d in amstaos,proximity-diodes.\n", leds[i]); 603 604 return -EINVAL; 604 605 } 605 606 }
-1
drivers/iio/magnetometer/Kconfig
··· 9 9 config AK8974 10 10 tristate "Asahi Kasei AK8974 3-Axis Magnetometer" 11 11 depends on I2C 12 - depends on OF 13 12 select REGMAP_I2C 14 13 select IIO_BUFFER 15 14 select IIO_TRIGGERED_BUFFER
+3 -12
drivers/iio/magnetometer/rm3100-core.c
··· 141 141 struct iio_dev *indio_dev = d; 142 142 struct rm3100_data *data = iio_priv(indio_dev); 143 143 144 - switch (indio_dev->currentmode) { 145 - case INDIO_DIRECT_MODE: 144 + if (!iio_buffer_enabled(indio_dev)) 146 145 complete(&data->measuring_done); 147 - break; 148 - case INDIO_BUFFER_TRIGGERED: 146 + else 149 147 iio_trigger_poll(data->drdy_trig); 150 - break; 151 - default: 152 - dev_err(indio_dev->dev.parent, 153 - "device mode out of control, current mode: %d", 154 - indio_dev->currentmode); 155 - } 156 148 157 149 return IRQ_WAKE_THREAD; 158 150 } ··· 369 377 goto unlock_return; 370 378 } 371 379 372 - if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { 380 + if (iio_buffer_enabled(indio_dev)) { 373 381 /* Writing TMRC registers requires CMM reset. */ 374 382 ret = regmap_write(regmap, RM3100_REG_CMM, 0); 375 383 if (ret < 0) ··· 545 553 indio_dev->channels = rm3100_channels; 546 554 indio_dev->num_channels = ARRAY_SIZE(rm3100_channels); 547 555 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_TRIGGERED; 548 - indio_dev->currentmode = INDIO_DIRECT_MODE; 549 556 550 557 if (!irq) 551 558 data->use_interrupt = false;
+5 -12
drivers/iio/magnetometer/st_magn_core.c
··· 540 540 static int st_magn_write_raw(struct iio_dev *indio_dev, 541 541 struct iio_chan_spec const *chan, int val, int val2, long mask) 542 542 { 543 - int err; 544 - 545 543 switch (mask) { 546 544 case IIO_CHAN_INFO_SCALE: 547 - err = st_sensors_set_fullscale_by_gain(indio_dev, val2); 548 - break; 545 + return st_sensors_set_fullscale_by_gain(indio_dev, val2); 549 546 case IIO_CHAN_INFO_SAMP_FREQ: 550 547 if (val2) 551 548 return -EINVAL; 552 - mutex_lock(&indio_dev->mlock); 553 - err = st_sensors_set_odr(indio_dev, val); 554 - mutex_unlock(&indio_dev->mlock); 555 - return err; 556 - default: 557 - err = -EINVAL; 558 - } 559 549 560 - return err; 550 + return st_sensors_set_odr(indio_dev, val); 551 + default: 552 + return -EINVAL; 553 + } 561 554 } 562 555 563 556 static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
-1
drivers/iio/multiplexer/Kconfig
··· 9 9 config IIO_MUX 10 10 tristate "IIO multiplexer driver" 11 11 select MULTIPLEXER 12 - depends on OF || COMPILE_TEST 13 12 help 14 13 Say yes here to build support for the IIO multiplexer. 15 14
+23 -26
drivers/iio/multiplexer/iio-mux.c
··· 10 10 #include <linux/err.h> 11 11 #include <linux/iio/consumer.h> 12 12 #include <linux/iio/iio.h> 13 + #include <linux/mod_devicetable.h> 13 14 #include <linux/module.h> 14 15 #include <linux/mutex.h> 15 16 #include <linux/mux/consumer.h> 16 - #include <linux/of.h> 17 17 #include <linux/platform_device.h> 18 + #include <linux/property.h> 18 19 19 20 struct mux_ext_info_cache { 20 21 char *data; ··· 325 324 return 0; 326 325 } 327 326 328 - /* 329 - * Same as of_property_for_each_string(), but also keeps track of the 330 - * index of each string. 331 - */ 332 - #define of_property_for_each_string_index(np, propname, prop, s, i) \ 333 - for (prop = of_find_property(np, propname, NULL), \ 334 - s = of_prop_next_string(prop, NULL), \ 335 - i = 0; \ 336 - s; \ 337 - s = of_prop_next_string(prop, s), \ 338 - i++) 339 - 340 327 static int mux_probe(struct platform_device *pdev) 341 328 { 342 329 struct device *dev = &pdev->dev; 343 - struct device_node *np = pdev->dev.of_node; 344 330 struct iio_dev *indio_dev; 345 331 struct iio_channel *parent; 346 332 struct mux *mux; 347 - struct property *prop; 348 - const char *label; 333 + const char **labels; 334 + int all_children; 335 + int children; 349 336 u32 state; 350 337 int sizeof_ext_info; 351 - int children; 352 338 int sizeof_priv; 353 339 int i; 354 340 int ret; 355 - 356 - if (!np) 357 - return -ENODEV; 358 341 359 342 parent = devm_iio_channel_get(dev, "parent"); 360 343 if (IS_ERR(parent)) ··· 351 366 sizeof_ext_info *= sizeof(*mux->ext_info); 352 367 } 353 368 369 + all_children = device_property_string_array_count(dev, "channels"); 370 + if (all_children < 0) 371 + return all_children; 372 + 373 + labels = devm_kmalloc_array(dev, all_children, sizeof(*labels), GFP_KERNEL); 374 + if (!labels) 375 + return -ENOMEM; 376 + 377 + ret = device_property_read_string_array(dev, "channels", labels, all_children); 378 + if (ret < 0) 379 + return ret; 380 + 354 381 children = 0; 355 - of_property_for_each_string(np, "channels", prop, label) { 356 - if (*label) 382 + for (state = 0; state < all_children; state++) { 383 + if (*labels[state]) 357 384 children++; 358 385 } 359 386 if (children <= 0) { ··· 392 395 mux->cached_state = -1; 393 396 394 397 mux->delay_us = 0; 395 - of_property_read_u32(np, "settle-time-us", &mux->delay_us); 398 + device_property_read_u32(dev, "settle-time-us", &mux->delay_us); 396 399 397 400 indio_dev->name = dev_name(dev); 398 401 indio_dev->info = &mux_info; ··· 423 426 } 424 427 425 428 i = 0; 426 - of_property_for_each_string_index(np, "channels", prop, label, state) { 427 - if (!*label) 429 + for (state = 0; state < all_children; state++) { 430 + if (!*labels[state]) 428 431 continue; 429 432 430 - ret = mux_configure_channel(dev, mux, state, label, i++); 433 + ret = mux_configure_channel(dev, mux, state, labels[state], i++); 431 434 if (ret < 0) 432 435 return ret; 433 436 }
+2 -6
drivers/iio/pressure/st_pressure_core.c
··· 560 560 int val2, 561 561 long mask) 562 562 { 563 - int err; 564 - 565 563 switch (mask) { 566 564 case IIO_CHAN_INFO_SAMP_FREQ: 567 565 if (val2) 568 566 return -EINVAL; 569 - mutex_lock(&indio_dev->mlock); 570 - err = st_sensors_set_odr(indio_dev, val); 571 - mutex_unlock(&indio_dev->mlock); 572 - return err; 567 + 568 + return st_sensors_set_odr(indio_dev, val); 573 569 default: 574 570 return -EINVAL; 575 571 }
+5 -3
drivers/iio/proximity/mb1232.c
··· 10 10 * https://www.maxbotix.com/documents/I2CXL-MaxSonar-EZ_Datasheet.pdf 11 11 */ 12 12 13 + #include <linux/bitops.h> 13 14 #include <linux/err.h> 14 15 #include <linux/i2c.h> 15 - #include <linux/of_irq.h> 16 16 #include <linux/delay.h> 17 + #include <linux/mod_devicetable.h> 17 18 #include <linux/module.h> 18 - #include <linux/bitops.h> 19 + #include <linux/property.h> 20 + 19 21 #include <linux/iio/iio.h> 20 22 #include <linux/iio/sysfs.h> 21 23 #include <linux/iio/buffer.h> ··· 211 209 212 210 init_completion(&data->ranging); 213 211 214 - data->irqnr = irq_of_parse_and_map(dev->of_node, 0); 212 + data->irqnr = fwnode_irq_get(dev_fwnode(&client->dev), 0); 215 213 if (data->irqnr <= 0) { 216 214 /* usage of interrupt is optional */ 217 215 data->irqnr = -1;
+2 -3
drivers/iio/proximity/ping.c
··· 29 29 #include <linux/err.h> 30 30 #include <linux/gpio/consumer.h> 31 31 #include <linux/kernel.h> 32 + #include <linux/mod_devicetable.h> 32 33 #include <linux/module.h> 33 - #include <linux/of.h> 34 - #include <linux/of_device.h> 35 34 #include <linux/platform_device.h> 36 35 #include <linux/property.h> 37 36 #include <linux/sched.h> ··· 287 288 288 289 data = iio_priv(indio_dev); 289 290 data->dev = dev; 290 - data->cfg = of_device_get_match_data(dev); 291 + data->cfg = device_get_match_data(dev); 291 292 292 293 mutex_init(&data->lock); 293 294 init_completion(&data->rising);
+3 -4
drivers/iio/proximity/vl53l0x-i2c.c
··· 104 104 u16 tries = 20; 105 105 u8 buffer[12]; 106 106 int ret; 107 + unsigned long time_left; 107 108 108 109 ret = i2c_smbus_write_byte_data(client, VL_REG_SYSRANGE_START, 1); 109 110 if (ret < 0) ··· 113 112 if (data->client->irq) { 114 113 reinit_completion(&data->completion); 115 114 116 - ret = wait_for_completion_timeout(&data->completion, HZ/10); 117 - if (ret < 0) 118 - return ret; 119 - else if (ret == 0) 115 + time_left = wait_for_completion_timeout(&data->completion, HZ/10); 116 + if (time_left == 0) 120 117 return -ETIMEDOUT; 121 118 122 119 vl53l0x_clear_irq(data);
+120 -116
drivers/iio/temperature/ltc2983.c
··· 12 12 #include <linux/iio/iio.h> 13 13 #include <linux/interrupt.h> 14 14 #include <linux/list.h> 15 + #include <linux/mod_devicetable.h> 15 16 #include <linux/module.h> 16 - #include <linux/of_gpio.h> 17 + #include <linux/property.h> 17 18 #include <linux/regmap.h> 18 19 #include <linux/spi/spi.h> 20 + 21 + #include <asm/byteorder.h> 22 + #include <asm/unaligned.h> 19 23 20 24 /* register map */ 21 25 #define LTC2983_STATUS_REG 0x0000 ··· 223 219 224 220 struct ltc2983_custom_sensor { 225 221 /* raw table sensor data */ 226 - u8 *table; 222 + void *table; 227 223 size_t size; 228 224 /* address offset */ 229 225 s8 offset; ··· 381 377 return regmap_bulk_write(st->regmap, reg, custom->table, custom->size); 382 378 } 383 379 384 - static struct ltc2983_custom_sensor *__ltc2983_custom_sensor_new( 385 - struct ltc2983_data *st, 386 - const struct device_node *np, 387 - const char *propname, 388 - const bool is_steinhart, 389 - const u32 resolution, 390 - const bool has_signed) 380 + static struct ltc2983_custom_sensor * 381 + __ltc2983_custom_sensor_new(struct ltc2983_data *st, const struct fwnode_handle *fn, 382 + const char *propname, const bool is_steinhart, 383 + const u32 resolution, const bool has_signed) 391 384 { 392 385 struct ltc2983_custom_sensor *new_custom; 393 - u8 index, n_entries, tbl = 0; 394 386 struct device *dev = &st->spi->dev; 395 387 /* 396 388 * For custom steinhart, the full u32 is taken. For all the others 397 389 * the MSB is discarded. 398 390 */ 399 391 const u8 n_size = is_steinhart ? 4 : 3; 400 - const u8 e_size = is_steinhart ? sizeof(u32) : sizeof(u64); 392 + u8 index, n_entries; 393 + int ret; 401 394 402 - n_entries = of_property_count_elems_of_size(np, propname, e_size); 395 + if (is_steinhart) 396 + n_entries = fwnode_property_count_u32(fn, propname); 397 + else 398 + n_entries = fwnode_property_count_u64(fn, propname); 403 399 /* n_entries must be an even number */ 404 400 if (!n_entries || (n_entries % 2) != 0) { 405 401 dev_err(dev, "Number of entries either 0 or not even\n"); ··· 413 409 new_custom->size = n_entries * n_size; 414 410 /* check Steinhart size */ 415 411 if (is_steinhart && new_custom->size != LTC2983_CUSTOM_STEINHART_SIZE) { 416 - dev_err(dev, "Steinhart sensors size(%zu) must be 24", 417 - new_custom->size); 412 + dev_err(dev, "Steinhart sensors size(%zu) must be %u\n", new_custom->size, 413 + LTC2983_CUSTOM_STEINHART_SIZE); 418 414 return ERR_PTR(-EINVAL); 419 415 } 420 416 /* Check space on the table. */ ··· 427 423 } 428 424 429 425 /* allocate the table */ 430 - new_custom->table = devm_kzalloc(dev, new_custom->size, GFP_KERNEL); 426 + if (is_steinhart) 427 + new_custom->table = devm_kcalloc(dev, n_entries, sizeof(u32), GFP_KERNEL); 428 + else 429 + new_custom->table = devm_kcalloc(dev, n_entries, sizeof(u64), GFP_KERNEL); 431 430 if (!new_custom->table) 432 431 return ERR_PTR(-ENOMEM); 433 432 434 - for (index = 0; index < n_entries; index++) { 435 - u64 temp = 0, j; 436 - /* 437 - * Steinhart sensors are configured with raw values in the 438 - * devicetree. For the other sensors we must convert the 439 - * value to raw. The odd index's correspond to temperarures 440 - * and always have 1/1024 of resolution. Temperatures also 441 - * come in kelvin, so signed values is not possible 442 - */ 443 - if (!is_steinhart) { 444 - of_property_read_u64_index(np, propname, index, &temp); 433 + /* 434 + * Steinhart sensors are configured with raw values in the firmware 435 + * node. For the other sensors we must convert the value to raw. 436 + * The odd index's correspond to temperatures and always have 1/1024 437 + * of resolution. Temperatures also come in Kelvin, so signed values 438 + * are not possible. 439 + */ 440 + if (is_steinhart) { 441 + ret = fwnode_property_read_u32_array(fn, propname, new_custom->table, n_entries); 442 + if (ret < 0) 443 + return ERR_PTR(ret); 444 + 445 + cpu_to_be32_array(new_custom->table, new_custom->table, n_entries); 446 + } else { 447 + ret = fwnode_property_read_u64_array(fn, propname, new_custom->table, n_entries); 448 + if (ret < 0) 449 + return ERR_PTR(ret); 450 + 451 + for (index = 0; index < n_entries; index++) { 452 + u64 temp = ((u64 *)new_custom->table)[index]; 445 453 446 454 if ((index % 2) != 0) 447 455 temp = __convert_to_raw(temp, 1024); ··· 461 445 temp = __convert_to_raw_sign(temp, resolution); 462 446 else 463 447 temp = __convert_to_raw(temp, resolution); 464 - } else { 465 - u32 t32; 466 448 467 - of_property_read_u32_index(np, propname, index, &t32); 468 - temp = t32; 449 + put_unaligned_be24(temp, new_custom->table + index * 3); 469 450 } 470 - 471 - for (j = 0; j < n_size; j++) 472 - new_custom->table[tbl++] = 473 - temp >> (8 * (n_size - j - 1)); 474 451 } 475 452 476 453 new_custom->is_steinhart = is_steinhart; ··· 606 597 return __ltc2983_chan_assign_common(st, sensor, chan_val); 607 598 } 608 599 609 - static struct ltc2983_sensor *ltc2983_thermocouple_new( 610 - const struct device_node *child, 611 - struct ltc2983_data *st, 612 - const struct ltc2983_sensor *sensor) 600 + static struct ltc2983_sensor * 601 + ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data *st, 602 + const struct ltc2983_sensor *sensor) 613 603 { 614 604 struct ltc2983_thermocouple *thermo; 615 - struct device_node *phandle; 605 + struct fwnode_handle *ref; 616 606 u32 oc_current; 617 607 int ret; 618 608 ··· 619 611 if (!thermo) 620 612 return ERR_PTR(-ENOMEM); 621 613 622 - if (of_property_read_bool(child, "adi,single-ended")) 614 + if (fwnode_property_read_bool(child, "adi,single-ended")) 623 615 thermo->sensor_config = LTC2983_THERMOCOUPLE_SGL(1); 624 616 625 - ret = of_property_read_u32(child, "adi,sensor-oc-current-microamp", 626 - &oc_current); 617 + ret = fwnode_property_read_u32(child, "adi,sensor-oc-current-microamp", &oc_current); 627 618 if (!ret) { 628 619 switch (oc_current) { 629 620 case 10: ··· 658 651 return ERR_PTR(-EINVAL); 659 652 } 660 653 661 - phandle = of_parse_phandle(child, "adi,cold-junction-handle", 0); 662 - if (phandle) { 663 - int ret; 664 - 665 - ret = of_property_read_u32(phandle, "reg", 666 - &thermo->cold_junction_chan); 654 + ref = fwnode_find_reference(child, "adi,cold-junction-handle", 0); 655 + if (IS_ERR(ref)) { 656 + ref = NULL; 657 + } else { 658 + ret = fwnode_property_read_u32(ref, "reg", &thermo->cold_junction_chan); 667 659 if (ret) { 668 660 /* 669 661 * This would be catched later but we can just return 670 662 * the error right away. 671 663 */ 672 664 dev_err(&st->spi->dev, "Property reg must be given\n"); 673 - of_node_put(phandle); 674 - return ERR_PTR(-EINVAL); 665 + goto fail; 675 666 } 676 667 } 677 668 ··· 681 676 propname, false, 682 677 16384, true); 683 678 if (IS_ERR(thermo->custom)) { 684 - of_node_put(phandle); 685 - return ERR_CAST(thermo->custom); 679 + ret = PTR_ERR(thermo->custom); 680 + goto fail; 686 681 } 687 682 } 688 683 ··· 690 685 thermo->sensor.fault_handler = ltc2983_thermocouple_fault_handler; 691 686 thermo->sensor.assign_chan = ltc2983_thermocouple_assign_chan; 692 687 693 - of_node_put(phandle); 688 + fwnode_handle_put(ref); 694 689 return &thermo->sensor; 690 + 691 + fail: 692 + fwnode_handle_put(ref); 693 + return ERR_PTR(ret); 695 694 } 696 695 697 - static struct ltc2983_sensor *ltc2983_rtd_new(const struct device_node *child, 698 - struct ltc2983_data *st, 699 - const struct ltc2983_sensor *sensor) 696 + static struct ltc2983_sensor * 697 + ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, 698 + const struct ltc2983_sensor *sensor) 700 699 { 701 700 struct ltc2983_rtd *rtd; 702 701 int ret = 0; 703 702 struct device *dev = &st->spi->dev; 704 - struct device_node *phandle; 703 + struct fwnode_handle *ref; 705 704 u32 excitation_current = 0, n_wires = 0; 706 705 707 706 rtd = devm_kzalloc(dev, sizeof(*rtd), GFP_KERNEL); 708 707 if (!rtd) 709 708 return ERR_PTR(-ENOMEM); 710 709 711 - phandle = of_parse_phandle(child, "adi,rsense-handle", 0); 712 - if (!phandle) { 710 + ref = fwnode_find_reference(child, "adi,rsense-handle", 0); 711 + if (IS_ERR(ref)) { 713 712 dev_err(dev, "Property adi,rsense-handle missing or invalid"); 714 - return ERR_PTR(-EINVAL); 713 + return ERR_CAST(ref); 715 714 } 716 715 717 - ret = of_property_read_u32(phandle, "reg", &rtd->r_sense_chan); 716 + ret = fwnode_property_read_u32(ref, "reg", &rtd->r_sense_chan); 718 717 if (ret) { 719 718 dev_err(dev, "Property reg must be given\n"); 720 719 goto fail; 721 720 } 722 721 723 - ret = of_property_read_u32(child, "adi,number-of-wires", &n_wires); 722 + ret = fwnode_property_read_u32(child, "adi,number-of-wires", &n_wires); 724 723 if (!ret) { 725 724 switch (n_wires) { 726 725 case 2: ··· 747 738 } 748 739 } 749 740 750 - if (of_property_read_bool(child, "adi,rsense-share")) { 741 + if (fwnode_property_read_bool(child, "adi,rsense-share")) { 751 742 /* Current rotation is only available with rsense sharing */ 752 - if (of_property_read_bool(child, "adi,current-rotate")) { 743 + if (fwnode_property_read_bool(child, "adi,current-rotate")) { 753 744 if (n_wires == 2 || n_wires == 3) { 754 745 dev_err(dev, 755 746 "Rotation not allowed for 2/3 Wire RTDs"); ··· 812 803 "adi,custom-rtd", 813 804 false, 2048, false); 814 805 if (IS_ERR(rtd->custom)) { 815 - of_node_put(phandle); 816 - return ERR_CAST(rtd->custom); 806 + ret = PTR_ERR(rtd->custom); 807 + goto fail; 817 808 } 818 809 } 819 810 ··· 821 812 rtd->sensor.fault_handler = ltc2983_common_fault_handler; 822 813 rtd->sensor.assign_chan = ltc2983_rtd_assign_chan; 823 814 824 - ret = of_property_read_u32(child, "adi,excitation-current-microamp", 825 - &excitation_current); 815 + ret = fwnode_property_read_u32(child, "adi,excitation-current-microamp", 816 + &excitation_current); 826 817 if (ret) { 827 818 /* default to 5uA */ 828 819 rtd->excitation_current = 1; ··· 861 852 } 862 853 } 863 854 864 - of_property_read_u32(child, "adi,rtd-curve", &rtd->rtd_curve); 855 + fwnode_property_read_u32(child, "adi,rtd-curve", &rtd->rtd_curve); 865 856 866 - of_node_put(phandle); 857 + fwnode_handle_put(ref); 867 858 return &rtd->sensor; 868 859 fail: 869 - of_node_put(phandle); 860 + fwnode_handle_put(ref); 870 861 return ERR_PTR(ret); 871 862 } 872 863 873 - static struct ltc2983_sensor *ltc2983_thermistor_new( 874 - const struct device_node *child, 875 - struct ltc2983_data *st, 876 - const struct ltc2983_sensor *sensor) 864 + static struct ltc2983_sensor * 865 + ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *st, 866 + const struct ltc2983_sensor *sensor) 877 867 { 878 868 struct ltc2983_thermistor *thermistor; 879 869 struct device *dev = &st->spi->dev; 880 - struct device_node *phandle; 870 + struct fwnode_handle *ref; 881 871 u32 excitation_current = 0; 882 872 int ret = 0; 883 873 ··· 884 876 if (!thermistor) 885 877 return ERR_PTR(-ENOMEM); 886 878 887 - phandle = of_parse_phandle(child, "adi,rsense-handle", 0); 888 - if (!phandle) { 879 + ref = fwnode_find_reference(child, "adi,rsense-handle", 0); 880 + if (IS_ERR(ref)) { 889 881 dev_err(dev, "Property adi,rsense-handle missing or invalid"); 890 - return ERR_PTR(-EINVAL); 882 + return ERR_CAST(ref); 891 883 } 892 884 893 - ret = of_property_read_u32(phandle, "reg", &thermistor->r_sense_chan); 885 + ret = fwnode_property_read_u32(ref, "reg", &thermistor->r_sense_chan); 894 886 if (ret) { 895 887 dev_err(dev, "rsense channel must be configured...\n"); 896 888 goto fail; 897 889 } 898 890 899 - if (of_property_read_bool(child, "adi,single-ended")) { 891 + if (fwnode_property_read_bool(child, "adi,single-ended")) { 900 892 thermistor->sensor_config = LTC2983_THERMISTOR_SGL(1); 901 - } else if (of_property_read_bool(child, "adi,rsense-share")) { 893 + } else if (fwnode_property_read_bool(child, "adi,rsense-share")) { 902 894 /* rotation is only possible if sharing rsense */ 903 - if (of_property_read_bool(child, "adi,current-rotate")) 895 + if (fwnode_property_read_bool(child, "adi,current-rotate")) 904 896 thermistor->sensor_config = 905 897 LTC2983_THERMISTOR_C_ROTATE(1); 906 898 else ··· 934 926 steinhart, 935 927 64, false); 936 928 if (IS_ERR(thermistor->custom)) { 937 - of_node_put(phandle); 938 - return ERR_CAST(thermistor->custom); 929 + ret = PTR_ERR(thermistor->custom); 930 + goto fail; 939 931 } 940 932 } 941 933 /* set common parameters */ 942 934 thermistor->sensor.fault_handler = ltc2983_common_fault_handler; 943 935 thermistor->sensor.assign_chan = ltc2983_thermistor_assign_chan; 944 936 945 - ret = of_property_read_u32(child, "adi,excitation-current-nanoamp", 946 - &excitation_current); 937 + ret = fwnode_property_read_u32(child, "adi,excitation-current-nanoamp", 938 + &excitation_current); 947 939 if (ret) { 948 940 /* Auto range is not allowed for custom sensors */ 949 941 if (sensor->type >= LTC2983_SENSOR_THERMISTOR_STEINHART) ··· 1007 999 } 1008 1000 } 1009 1001 1010 - of_node_put(phandle); 1002 + fwnode_handle_put(ref); 1011 1003 return &thermistor->sensor; 1012 1004 fail: 1013 - of_node_put(phandle); 1005 + fwnode_handle_put(ref); 1014 1006 return ERR_PTR(ret); 1015 1007 } 1016 1008 1017 - static struct ltc2983_sensor *ltc2983_diode_new( 1018 - const struct device_node *child, 1019 - const struct ltc2983_data *st, 1020 - const struct ltc2983_sensor *sensor) 1009 + static struct ltc2983_sensor * 1010 + ltc2983_diode_new(const struct fwnode_handle *child, const struct ltc2983_data *st, 1011 + const struct ltc2983_sensor *sensor) 1021 1012 { 1022 1013 struct ltc2983_diode *diode; 1023 1014 u32 temp = 0, excitation_current = 0; ··· 1026 1019 if (!diode) 1027 1020 return ERR_PTR(-ENOMEM); 1028 1021 1029 - if (of_property_read_bool(child, "adi,single-ended")) 1022 + if (fwnode_property_read_bool(child, "adi,single-ended")) 1030 1023 diode->sensor_config = LTC2983_DIODE_SGL(1); 1031 1024 1032 - if (of_property_read_bool(child, "adi,three-conversion-cycles")) 1025 + if (fwnode_property_read_bool(child, "adi,three-conversion-cycles")) 1033 1026 diode->sensor_config |= LTC2983_DIODE_3_CONV_CYCLE(1); 1034 1027 1035 - if (of_property_read_bool(child, "adi,average-on")) 1028 + if (fwnode_property_read_bool(child, "adi,average-on")) 1036 1029 diode->sensor_config |= LTC2983_DIODE_AVERAGE_ON(1); 1037 1030 1038 1031 /* validate channel index */ ··· 1047 1040 diode->sensor.fault_handler = ltc2983_common_fault_handler; 1048 1041 diode->sensor.assign_chan = ltc2983_diode_assign_chan; 1049 1042 1050 - ret = of_property_read_u32(child, "adi,excitation-current-microamp", 1051 - &excitation_current); 1043 + ret = fwnode_property_read_u32(child, "adi,excitation-current-microamp", 1044 + &excitation_current); 1052 1045 if (!ret) { 1053 1046 switch (excitation_current) { 1054 1047 case 10: ··· 1071 1064 } 1072 1065 } 1073 1066 1074 - of_property_read_u32(child, "adi,ideal-factor-value", &temp); 1067 + fwnode_property_read_u32(child, "adi,ideal-factor-value", &temp); 1075 1068 1076 1069 /* 2^20 resolution */ 1077 1070 diode->ideal_factor_value = __convert_to_raw(temp, 1048576); ··· 1079 1072 return &diode->sensor; 1080 1073 } 1081 1074 1082 - static struct ltc2983_sensor *ltc2983_r_sense_new(struct device_node *child, 1075 + static struct ltc2983_sensor *ltc2983_r_sense_new(struct fwnode_handle *child, 1083 1076 struct ltc2983_data *st, 1084 1077 const struct ltc2983_sensor *sensor) 1085 1078 { ··· 1098 1091 return ERR_PTR(-EINVAL); 1099 1092 } 1100 1093 1101 - ret = of_property_read_u32(child, "adi,rsense-val-milli-ohms", &temp); 1094 + ret = fwnode_property_read_u32(child, "adi,rsense-val-milli-ohms", &temp); 1102 1095 if (ret) { 1103 1096 dev_err(&st->spi->dev, "Property adi,rsense-val-milli-ohms missing\n"); 1104 1097 return ERR_PTR(-EINVAL); ··· 1117 1110 return &rsense->sensor; 1118 1111 } 1119 1112 1120 - static struct ltc2983_sensor *ltc2983_adc_new(struct device_node *child, 1113 + static struct ltc2983_sensor *ltc2983_adc_new(struct fwnode_handle *child, 1121 1114 struct ltc2983_data *st, 1122 1115 const struct ltc2983_sensor *sensor) 1123 1116 { ··· 1127 1120 if (!adc) 1128 1121 return ERR_PTR(-ENOMEM); 1129 1122 1130 - if (of_property_read_bool(child, "adi,single-ended")) 1123 + if (fwnode_property_read_bool(child, "adi,single-ended")) 1131 1124 adc->single_ended = true; 1132 1125 1133 1126 if (!adc->single_ended && ··· 1271 1264 1272 1265 static int ltc2983_parse_dt(struct ltc2983_data *st) 1273 1266 { 1274 - struct device_node *child; 1275 1267 struct device *dev = &st->spi->dev; 1268 + struct fwnode_handle *child; 1276 1269 int ret = 0, chan = 0, channel_avail_mask = 0; 1277 1270 1278 - of_property_read_u32(dev->of_node, "adi,mux-delay-config-us", 1279 - &st->mux_delay_config); 1271 + device_property_read_u32(dev, "adi,mux-delay-config-us", &st->mux_delay_config); 1280 1272 1281 - of_property_read_u32(dev->of_node, "adi,filter-notch-freq", 1282 - &st->filter_notch_freq); 1273 + device_property_read_u32(dev, "adi,filter-notch-freq", &st->filter_notch_freq); 1283 1274 1284 - st->num_channels = of_get_available_child_count(dev->of_node); 1275 + st->num_channels = device_get_child_node_count(dev); 1285 1276 if (!st->num_channels) { 1286 1277 dev_err(&st->spi->dev, "At least one channel must be given!"); 1287 1278 return -EINVAL; ··· 1291 1286 return -ENOMEM; 1292 1287 1293 1288 st->iio_channels = st->num_channels; 1294 - for_each_available_child_of_node(dev->of_node, child) { 1289 + device_for_each_child_node(dev, child) { 1295 1290 struct ltc2983_sensor sensor; 1296 1291 1297 - ret = of_property_read_u32(child, "reg", &sensor.chan); 1292 + ret = fwnode_property_read_u32(child, "reg", &sensor.chan); 1298 1293 if (ret) { 1299 1294 dev_err(dev, "reg property must given for child nodes\n"); 1300 1295 goto put_child; ··· 1304 1299 if (sensor.chan < LTC2983_MIN_CHANNELS_NR || 1305 1300 sensor.chan > LTC2983_MAX_CHANNELS_NR) { 1306 1301 ret = -EINVAL; 1307 - dev_err(dev, 1308 - "chan:%d must be from 1 to 20\n", sensor.chan); 1302 + dev_err(dev, "chan:%d must be from %u to %u\n", sensor.chan, 1303 + LTC2983_MIN_CHANNELS_NR, LTC2983_MAX_CHANNELS_NR); 1309 1304 goto put_child; 1310 1305 } else if (channel_avail_mask & BIT(sensor.chan)) { 1311 1306 ret = -EINVAL; ··· 1313 1308 goto put_child; 1314 1309 } 1315 1310 1316 - ret = of_property_read_u32(child, "adi,sensor-type", 1317 - &sensor.type); 1311 + ret = fwnode_property_read_u32(child, "adi,sensor-type", &sensor.type); 1318 1312 if (ret) { 1319 1313 dev_err(dev, 1320 1314 "adi,sensor-type property must given for child nodes\n"); ··· 1367 1363 1368 1364 return 0; 1369 1365 put_child: 1370 - of_node_put(child); 1366 + fwnode_handle_put(child); 1371 1367 return ret; 1372 1368 } 1373 1369
+3 -3
drivers/iio/temperature/max31856.c
··· 7 7 */ 8 8 9 9 #include <linux/ctype.h> 10 + #include <linux/mod_devicetable.h> 10 11 #include <linux/module.h> 11 12 #include <linux/init.h> 12 13 #include <linux/err.h> 14 + #include <linux/property.h> 13 15 #include <linux/spi/spi.h> 14 16 #include <linux/iio/iio.h> 15 17 #include <linux/iio/sysfs.h> ··· 424 422 indio_dev->channels = max31856_channels; 425 423 indio_dev->num_channels = ARRAY_SIZE(max31856_channels); 426 424 427 - ret = of_property_read_u32(spi->dev.of_node, "thermocouple-type", 428 - &data->thermocouple_type); 429 - 425 + ret = device_property_read_u32(&spi->dev, "thermocouple-type", &data->thermocouple_type); 430 426 if (ret) { 431 427 dev_info(&spi->dev, 432 428 "Could not read thermocouple type DT property, configuring as a K-Type\n");
+3 -1
drivers/iio/temperature/max31865.c
··· 12 12 #include <linux/delay.h> 13 13 #include <linux/err.h> 14 14 #include <linux/init.h> 15 + #include <linux/mod_devicetable.h> 15 16 #include <linux/module.h> 16 17 #include <linux/iio/iio.h> 17 18 #include <linux/iio/sysfs.h> 19 + #include <linux/property.h> 18 20 #include <linux/spi/spi.h> 19 21 #include <asm/unaligned.h> 20 22 ··· 307 305 indio_dev->channels = max31865_channels; 308 306 indio_dev->num_channels = ARRAY_SIZE(max31865_channels); 309 307 310 - if (of_property_read_bool(spi->dev.of_node, "maxim,3-wire")) { 308 + if (device_property_read_bool(&spi->dev, "maxim,3-wire")) { 311 309 /* select 3 wire */ 312 310 data->three_wire = 1; 313 311 } else {
+5 -6
drivers/iio/trigger/iio-trig-sysfs.c
··· 176 176 177 177 static int iio_sysfs_trigger_remove(int id) 178 178 { 179 - bool foundit = false; 180 - struct iio_sysfs_trig *t; 179 + struct iio_sysfs_trig *t = NULL, *iter; 181 180 182 181 mutex_lock(&iio_sysfs_trig_list_mut); 183 - list_for_each_entry(t, &iio_sysfs_trig_list, l) 184 - if (id == t->id) { 185 - foundit = true; 182 + list_for_each_entry(iter, &iio_sysfs_trig_list, l) 183 + if (id == iter->id) { 184 + t = iter; 186 185 break; 187 186 } 188 - if (!foundit) { 187 + if (!t) { 189 188 mutex_unlock(&iio_sysfs_trig_list_mut); 190 189 return -EINVAL; 191 190 }
+1 -1
drivers/staging/iio/cdc/ad7746.c
··· 290 290 int ret, timeout = 10; 291 291 bool doit; 292 292 293 - ret = strtobool(buf, &doit); 293 + ret = kstrtobool(buf, &doit); 294 294 if (ret < 0) 295 295 return ret; 296 296
-1
drivers/staging/iio/impedance-analyzer/ad5933.c
··· 749 749 indio_dev->num_channels = ARRAY_SIZE(ad5933_channels); 750 750 751 751 ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev, 752 - INDIO_BUFFER_SOFTWARE, 753 752 &ad5933_ring_setup_ops); 754 753 if (ret) 755 754 return ret;
-1
drivers/staging/iio/resolver/ad2s1210.c
··· 499 499 ret = IIO_VAL_INT; 500 500 break; 501 501 case IIO_ANGL_VEL: 502 - negative = st->rx[0] & 0x80; 503 502 vel = be16_to_cpup((__be16 *)st->rx); 504 503 vel >>= 16 - st->resolution; 505 504 if (vel & 0x8000) {
+38
include/linux/iio/adc/ad_sigma_delta.h
··· 32 32 /** 33 33 * struct ad_sigma_delta_info - Sigma Delta driver specific callbacks and options 34 34 * @set_channel: Will be called to select the current channel, may be NULL. 35 + * @append_status: Will be called to enable status append at the end of the sample, may be NULL. 35 36 * @set_mode: Will be called to select the current mode, may be NULL. 37 + * @disable_all: Will be called to disable all channels, may be NULL. 36 38 * @postprocess_sample: Is called for each sampled data word, can be used to 37 39 * modify or drop the sample data, it, may be NULL. 38 40 * @has_registers: true if the device has writable and readable registers, false 39 41 * if there is just one read-only sample data shift register. 40 42 * @addr_shift: Shift of the register address in the communications register. 41 43 * @read_mask: Mask for the communications register having the read bit set. 44 + * @status_ch_mask: Mask for the channel number stored in status register. 42 45 * @data_reg: Address of the data register, if 0 the default address of 0x3 will 43 46 * be used. 44 47 * @irq_flags: flags for the interrupt used by the triggered buffer 48 + * @num_slots: Number of sequencer slots 45 49 */ 46 50 struct ad_sigma_delta_info { 47 51 int (*set_channel)(struct ad_sigma_delta *, unsigned int channel); 52 + int (*append_status)(struct ad_sigma_delta *, bool append); 48 53 int (*set_mode)(struct ad_sigma_delta *, enum ad_sigma_delta_mode mode); 54 + int (*disable_all)(struct ad_sigma_delta *); 49 55 int (*postprocess_sample)(struct ad_sigma_delta *, unsigned int raw_sample); 50 56 bool has_registers; 51 57 unsigned int addr_shift; 52 58 unsigned int read_mask; 59 + unsigned int status_ch_mask; 53 60 unsigned int data_reg; 54 61 unsigned long irq_flags; 62 + unsigned int num_slots; 55 63 }; 56 64 57 65 /** ··· 84 76 uint8_t comm; 85 77 86 78 const struct ad_sigma_delta_info *info; 79 + unsigned int active_slots; 80 + unsigned int current_slot; 81 + unsigned int num_slots; 82 + bool status_appended; 83 + /* map slots to channels in order to know what to expect from devices */ 84 + unsigned int *slots; 85 + uint8_t *samples_buf; 87 86 88 87 /* 89 88 * DMA (thus cache coherency maintenance) requires the ··· 108 93 { 109 94 if (sd->info->set_channel) 110 95 return sd->info->set_channel(sd, channel); 96 + 97 + return 0; 98 + } 99 + 100 + static inline int ad_sigma_delta_append_status(struct ad_sigma_delta *sd, bool append) 101 + { 102 + int ret; 103 + 104 + if (sd->info->append_status) { 105 + ret = sd->info->append_status(sd, append); 106 + if (ret < 0) 107 + return ret; 108 + 109 + sd->status_appended = append; 110 + } 111 + 112 + return 0; 113 + } 114 + 115 + static inline int ad_sigma_delta_disable_all(struct ad_sigma_delta *sd) 116 + { 117 + if (sd->info->disable_all) 118 + return sd->info->disable_all(sd); 111 119 112 120 return 0; 113 121 }
+3
include/linux/iio/common/st_sensors.h
··· 237 237 * @hw_irq_trigger: if we're using the hardware interrupt on the sensor. 238 238 * @hw_timestamp: Latest timestamp from the interrupt handler, when in use. 239 239 * @buffer_data: Data used by buffer part. 240 + * @odr_lock: Local lock for preventing concurrent ODR accesses/changes 240 241 */ 241 242 struct st_sensor_data { 242 243 struct iio_trigger *trig; ··· 262 261 s64 hw_timestamp; 263 262 264 263 char buffer_data[ST_SENSORS_MAX_BUFFER_SIZE] ____cacheline_aligned; 264 + 265 + struct mutex odr_lock; 265 266 }; 266 267 267 268 #ifdef CONFIG_IIO_BUFFER
+4
include/linux/iio/iio-opaque.h
··· 7 7 * struct iio_dev_opaque - industrial I/O device opaque information 8 8 * @indio_dev: public industrial I/O device information 9 9 * @id: used to identify device internally 10 + * @currentmode: operating mode currently in use, may be eventually 11 + * checked by device drivers but should be considered 12 + * read-only as this is a core internal bit 10 13 * @driver_module: used to make it harder to undercut users 11 14 * @info_exist_lock: lock to prevent use during removal 12 15 * @trig_readonly: mark the current trigger immutable ··· 39 36 */ 40 37 struct iio_dev_opaque { 41 38 struct iio_dev indio_dev; 39 + int currentmode; 42 40 int id; 43 41 struct module *driver_module; 44 42 struct mutex info_exist_lock;
+56 -14
include/linux/iio/iio.h
··· 315 315 s64 iio_get_time_ns(const struct iio_dev *indio_dev); 316 316 unsigned int iio_get_time_res(const struct iio_dev *indio_dev); 317 317 318 - /* Device operating modes */ 318 + /* 319 + * Device operating modes 320 + * @INDIO_DIRECT_MODE: There is an access to either: 321 + * a) The last single value available for devices that do not provide 322 + * on-demand reads. 323 + * b) A new value after performing an on-demand read otherwise. 324 + * On most devices, this is a single-shot read. On some devices with data 325 + * streams without an 'on-demand' function, this might also be the 'last value' 326 + * feature. Above all, this mode internally means that we are not in any of the 327 + * other modes, and sysfs reads should work. 328 + * Device drivers should inform the core if they support this mode. 329 + * @INDIO_BUFFER_TRIGGERED: Common mode when dealing with kfifo buffers. 330 + * It indicates that an explicit trigger is required. This requests the core to 331 + * attach a poll function when enabling the buffer, which is indicated by the 332 + * _TRIGGERED suffix. 333 + * The core will ensure this mode is set when registering a triggered buffer 334 + * with iio_triggered_buffer_setup(). 335 + * @INDIO_BUFFER_SOFTWARE: Another kfifo buffer mode, but not event triggered. 336 + * No poll function can be attached because there is no triggered infrastructure 337 + * we can use to cause capture. There is a kfifo that the driver will fill, but 338 + * not "only one scan at a time". Typically, hardware will have a buffer that 339 + * can hold multiple scans. Software may read one or more scans at a single time 340 + * and push the available data to a Kfifo. This means the core will not attach 341 + * any poll function when enabling the buffer. 342 + * The core will ensure this mode is set when registering a simple kfifo buffer 343 + * with devm_iio_kfifo_buffer_setup(). 344 + * @INDIO_BUFFER_HARDWARE: For specific hardware, if unsure do not use this mode. 345 + * Same as above but this time the buffer is not a kfifo where we have direct 346 + * access to the data. Instead, the consumer driver must access the data through 347 + * non software visible channels (or DMA when there is no demux possible in 348 + * software) 349 + * The core will ensure this mode is set when registering a dmaengine buffer 350 + * with devm_iio_dmaengine_buffer_setup(). 351 + * @INDIO_EVENT_TRIGGERED: Very unusual mode. 352 + * Triggers usually refer to an external event which will start data capture. 353 + * Here it is kind of the opposite as, a particular state of the data might 354 + * produce an event which can be considered as an event. We don't necessarily 355 + * have access to the data itself, but to the event produced. For example, this 356 + * can be a threshold detector. The internal path of this mode is very close to 357 + * the INDIO_BUFFER_TRIGGERED mode. 358 + * The core will ensure this mode is set when registering a triggered event. 359 + * @INDIO_HARDWARE_TRIGGERED: Very unusual mode. 360 + * Here, triggers can result in data capture and can be routed to multiple 361 + * hardware components, which make them close to regular triggers in the way 362 + * they must be managed by the core, but without the entire interrupts/poll 363 + * functions burden. Interrupts are irrelevant as the data flow is hardware 364 + * mediated and distributed. 365 + */ 319 366 #define INDIO_DIRECT_MODE 0x01 320 367 #define INDIO_BUFFER_TRIGGERED 0x02 321 368 #define INDIO_BUFFER_SOFTWARE 0x04 ··· 535 488 536 489 /** 537 490 * struct iio_dev - industrial I/O device 538 - * @modes: [DRIVER] operating modes supported by device 539 - * @currentmode: [INTERN] current operating mode 491 + * @modes: [DRIVER] bitmask listing all the operating modes 492 + * supported by the IIO device. This list should be 493 + * initialized before registering the IIO device. It can 494 + * also be filed up by the IIO core, as a result of 495 + * enabling particular features in the driver 496 + * (see iio_triggered_event_setup()). 540 497 * @dev: [DRIVER] device structure, should be assigned a parent 541 498 * and owner 542 499 * @buffer: [DRIVER] any buffer present ··· 567 516 */ 568 517 struct iio_dev { 569 518 int modes; 570 - int currentmode; 571 519 struct device dev; 572 520 573 521 struct iio_buffer *buffer; ··· 593 543 }; 594 544 595 545 int iio_device_id(struct iio_dev *indio_dev); 546 + int iio_device_get_current_mode(struct iio_dev *indio_dev); 547 + bool iio_buffer_enabled(struct iio_dev *indio_dev); 596 548 597 549 const struct iio_chan_spec 598 550 *iio_find_channel_from_si(struct iio_dev *indio_dev, int si); ··· 724 672 __printf(2, 3) 725 673 struct iio_trigger *devm_iio_trigger_alloc(struct device *parent, 726 674 const char *fmt, ...); 727 - /** 728 - * iio_buffer_enabled() - helper function to test if the buffer is enabled 729 - * @indio_dev: IIO device structure for device 730 - **/ 731 - static inline bool iio_buffer_enabled(struct iio_dev *indio_dev) 732 - { 733 - return indio_dev->currentmode 734 - & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE | 735 - INDIO_BUFFER_SOFTWARE); 736 - } 737 675 738 676 /** 739 677 * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry
+2 -3
include/linux/iio/kfifo_buf.h
··· 12 12 13 13 int devm_iio_kfifo_buffer_setup_ext(struct device *dev, 14 14 struct iio_dev *indio_dev, 15 - int mode_flags, 16 15 const struct iio_buffer_setup_ops *setup_ops, 17 16 const struct attribute **buffer_attrs); 18 17 19 - #define devm_iio_kfifo_buffer_setup(dev, indio_dev, mode_flags, setup_ops) \ 20 - devm_iio_kfifo_buffer_setup_ext((dev), (indio_dev), (mode_flags), (setup_ops), NULL) 18 + #define devm_iio_kfifo_buffer_setup(dev, indio_dev, setup_ops) \ 19 + devm_iio_kfifo_buffer_setup_ext((dev), (indio_dev), (setup_ops), NULL) 21 20 22 21 #endif