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