Jonathan writes: Second set of IIO new device support, features and cleanup for the 5.2 cycle. New device suport * ad7606 - Support the AD7616 16 channel, 12bit ADC. * fxas21002c - New driver for this gyroscope with I2C and SPI support. * lsm6dsx - Support the lsm6dsr, new device information structure and dt bindings. * srf04 - Addition device IDs for mb1000, mb1010, mb1020, mb1030 and mb1040 + support of different required trigger pulse lengths. * st-accel - Support the ls2de12, new device info and dt bindings. * ti-ads8344 - New driver for this 8 channel, 16 bit SPI ADC. Binding conversions to yaml - we have started doing these in general for IIO. * avia-hx711 * bmp085 Cleanups and minor fixes / additions * ad5758 - Fixup for some changes between preproduction parts and final part. * ad7606 - Refactor handling of oversampling to make it easy to vary between supported devices. * ad9832 - Organise includes. - Clock framework to handle clocks. * ad9834 - Drop unnecessary parenthesis. * bmc150 - Use __func__ rather than hardcoding. * dummy_evgen. - Fix a memleak on error in probe. * kxcjk1013 - Add KXCJ91008 ACPI ID as seen in the wild. - Use __func__ rather than hardcoding. * imx7d - Local dev variable to simplify code a bit. - dev_err replaces pr_err to give more info. - devm_platform_ioremap_resource for small reduction in boilerplate. - Simplify probe and remove by sharing suspend / resume logic. - Devm for iio_device_register as remove only contains the unregister. * lsm6dsx - Remove a variable that was never read. - Open code values where they are effectively described by what is assigned to them rather than using uninformative defines. * max31856 - Avoid an unintialized ret variable in a path that can't actually occur but is hard for a static checker to know. * max9611 - White space * mpu3050 - Reduce a sleep worst case by switching from msleep to usleep_range. * qcom-spmi-adc5 - Add MODULE_DEVICE_TABLE to assist autoloading of this as a module. * stm32-dfsdm - Fix missing dependencies. * stm32-timer trigger - Fix a build issue when disabled. * ti-ads7950 - Fix mising dependency on CONFIG_GPIOLIB. * tag 'iio-for-5.2b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (42 commits) iio: adc: qcom-spmi-adc5: Fix of-based module autoloading iio: dummy_evgen: fix possible memleak in evgen init iio:accel:Switch hardcoded function name with a reference to __func__ making the code more maintainable iio: adc: stm32-dfsdm: fix triggered buffer build dependency iio: adc: stm32-dfsdm: fix unmet direct dependencies detected iio: trigger: stm32-timer: fix build issue when disabled iio: imx7d_adc: Use devm_iio_device_register() iio: imx7d_adc: Simplify imx7d_adc_remove() with imx7d_adc_suspend() iio: imx7d_adc: Simplify imx7d_adc_probe() with imx7d_adc_resume() drivers/iio/gyro/mpu3050-core.c: This patch fix the following checkpatch warning. iio: dac: ad5758: Modifications for new revision iio: imu: st_lsm6dsx: inline per-sensor data iio: adc: Add driver for the TI ADS8344 A/DC chips dt-bindings: iio: adc: Add bindings for TI ADS8344 A/DC chips MAINTAINERS: add entry for fxas21002c gyro driver iio: gyro: fxas21002c: add spi driver iio: gyro: fxas21002c: add i2c driver iio: gyro: add core driver for fxas21002c iio: gyro: add DT bindings to fxas21002c Kconfig: change configuration of srf04 ultrasonic iio sensor ...
Unified · Split
| @@ -7,6 +7,7 @@ Required properties for the AD7606: · 6 unmodified lines | |||
| 7 | * "adi,ad7606-8" | 7 | * "adi,ad7606-8" |
| 8 | * "adi,ad7606-6" | 8 | * "adi,ad7606-6" |
| 9 | * "adi,ad7606-4" | 9 | * "adi,ad7606-4" |
| 10 | * "adi,ad7616" | ||
| 10 | - reg: SPI chip select number for the device | 11 | - reg: SPI chip select number for the device |
| 11 | - spi-max-frequency: Max SPI frequency to use | 12 | - spi-max-frequency: Max SPI frequency to use |
| 12 | see: Documentation/devicetree/bindings/spi/spi-bus.txt | 13 | see: Documentation/devicetree/bindings/spi/spi-bus.txt |
| @@ -1,24 +0,0 @@ | |||
| 1 | * AVIA HX711 ADC chip for weight cells | ||
| 2 | Bit-banging driver | ||
| 3 | |||
| 4 | Required properties: | ||
| 5 | - compatible: Should be "avia,hx711" | ||
| 6 | - sck-gpios: Definition of the GPIO for the clock | ||
| 7 | - dout-gpios: Definition of the GPIO for data-out | ||
| 8 | See Documentation/devicetree/bindings/gpio/gpio.txt | ||
| 9 | - avdd-supply: Definition of the regulator used as analog supply | ||
| 10 | |||
| 11 | Optional properties: | ||
| 12 | - clock-frequency: Frequency of PD_SCK in Hz | ||
| 13 | Minimum value allowed is 10 kHz because of maximum | ||
| 14 | high time of 50 microseconds. | ||
| 15 | |||
| 16 | Example: | ||
| 17 | weight { | ||
| 18 | compatible = "avia,hx711"; | ||
| 19 | sck-gpios = <&gpio3 10 GPIO_ACTIVE_HIGH>; | ||
| 20 | dout-gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>; | ||
| 21 | avdd-suppy = <&avdd>; | ||
| 22 | clock-frequency = <100000>; | ||
| 23 | }; | ||
| 24 | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | # SPDX-License-Identifier: GPL-2.0 | ||
| 2 | %YAML 1.2 | ||
| 3 | --- | ||
| 4 | $id: "http://devicetree.org/schemas/iio/adc/avia-hx711.yaml#" | ||
| 5 | $schema: "http://devicetree.org/meta-schemas/core.yaml#" | ||
| 6 | |||
| 7 | title: AVIA HX711 ADC chip for weight cells | ||
| 8 | |||
| 9 | maintainers: | ||
| 10 | - Andreas Klinger <ak@it-klinger.de> | ||
| 11 | |||
| 12 | description: | | ||
| 13 | Bit-banging driver using two GPIOs: | ||
| 14 | - sck-gpio gives a clock to the sensor with 24 cycles for data retrieval | ||
| 15 | and up to 3 cycles for selection of the input channel and gain for the | ||
| 16 | next measurement | ||
| 17 | - dout-gpio is the sensor data the sensor responds to the clock | ||
| 18 | |||
| 19 | Specifications about the driver can be found at: | ||
| 20 | http://www.aviaic.com/ENProducts.aspx | ||
| 21 | |||
| 22 | properties: | ||
| 23 | compatible: | ||
| 24 | enum: | ||
| 25 | - avia,hx711 | ||
| 26 | |||
| 27 | sck-gpios: | ||
| 28 | description: | ||
| 29 | Definition of the GPIO for the clock (output). In the datasheet it is | ||
| 30 | named PD_SCK | ||
| 31 | maxItems: 1 | ||
| 32 | |||
| 33 | dout-gpios: | ||
| 34 | description: | ||
| 35 | Definition of the GPIO for the data-out sent by the sensor in | ||
| 36 | response to the clock (input). | ||
| 37 | See Documentation/devicetree/bindings/gpio/gpio.txt for information | ||
| 38 | on how to specify a consumer gpio. | ||
| 39 | maxItems: 1 | ||
| 40 | |||
| 41 | avdd-supply: | ||
| 42 | description: | ||
| 43 | Definition of the regulator used as analog supply | ||
| 44 | maxItems: 1 | ||
| 45 | |||
| 46 | clock-frequency: | ||
| 47 | minimum: 20000 | ||
| 48 | maximum: 2500000 | ||
| 49 | default: 400000 | ||
| 50 | |||
| 51 | required: | ||
| 52 | - compatible | ||
| 53 | - sck-gpios | ||
| 54 | - dout-gpios | ||
| 55 | - avdd-supply | ||
| 56 | |||
| 57 | examples: | ||
| 58 | - | | ||
| 59 | #include <dt-bindings/gpio/gpio.h> | ||
| 60 | weight { | ||
| 61 | compatible = "avia,hx711"; | ||
| 62 | sck-gpios = <&gpio3 10 GPIO_ACTIVE_HIGH>; | ||
| 63 | dout-gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>; | ||
| 64 | avdd-suppy = <&avdd>; | ||
| 65 | clock-frequency = <100000>; | ||
| 66 | }; | ||
| @@ -0,0 +1,19 @@ | |||
| 1 | * Texas Instruments ADS8344 A/DC chip | ||
| 2 | |||
| 3 | Required properties: | ||
| 4 | - compatible: Must be "ti,ads8344" | ||
| 5 | - reg: SPI chip select number for the device | ||
| 6 | - vref-supply: phandle to a regulator node that supplies the | ||
| 7 | reference voltage | ||
| 8 | |||
| 9 | Recommended properties: | ||
| 10 | - spi-max-frequency: Definition as per | ||
| 11 | Documentation/devicetree/bindings/spi/spi-bus.txt | ||
| 12 | |||
| 13 | Example: | ||
| 14 | adc@0 { | ||
| 15 | compatible = "ti,ads8344"; | ||
| 16 | reg = <0>; | ||
| 17 | vref-supply = <&refin_supply>; | ||
| 18 | spi-max-frequency = <10000000>; | ||
| 19 | }; | ||
| @@ -0,0 +1,31 @@ | |||
| 1 | * NXP FXAS21002C Gyroscope device tree bindings | ||
| 2 | |||
| 3 | http://www.nxp.com/products/sensors/gyroscopes/3-axis-digital-gyroscope:FXAS21002C | ||
| 4 | |||
| 5 | Required properties: | ||
| 6 | - compatible : should be "nxp,fxas21002c" | ||
| 7 | - reg : the I2C address of the sensor or SPI chip select number for the | ||
| 8 | device. | ||
| 9 | - vdd-supply: phandle to the regulator that provides power to the sensor. | ||
| 10 | - vddio-supply: phandle to the regulator that provides power to the bus. | ||
| 11 | |||
| 12 | Optional properties: | ||
| 13 | - reset-gpios : gpio used to reset the device, see gpio/gpio.txt | ||
| 14 | - interrupts : device support 2 interrupts, INT1 and INT2, | ||
| 15 | the interrupts can be triggered on rising or falling edges. | ||
| 16 | See interrupt-controller/interrupts.txt | ||
| 17 | - interrupt-names: should contain "INT1" or "INT2", the gyroscope interrupt | ||
| 18 | line in use. | ||
| 19 | - drive-open-drain: the interrupt/data ready line will be configured | ||
| 20 | as open drain, which is useful if several sensors share | ||
| 21 | the same interrupt line. This is a boolean property. | ||
| 22 | (This binding is taken from pinctrl/pinctrl-bindings.txt) | ||
| 23 | |||
| 24 | Example: | ||
| 25 | |||
| 26 | gyroscope@20 { | ||
| 27 | compatible = "nxp,fxas21002c"; | ||
| 28 | reg = <0x20>; | ||
| 29 | vdd-supply = <®_peri_3p15v>; | ||
| 30 | vddio-supply = <®_peri_3p15v>; | ||
| 31 | }; | ||
| @@ -10,6 +10,7 @@ Required properties: · 9 unmodified lines | |||
| 10 | "st,lsm6dso" | 10 | "st,lsm6dso" |
| 11 | "st,asm330lhh" | 11 | "st,asm330lhh" |
| 12 | "st,lsm6dsox" | 12 | "st,lsm6dsox" |
| 13 | "st,lsm6dsr" | ||
| 13 | - reg: i2c address of the sensor / spi cs line | 14 | - reg: i2c address of the sensor / spi cs line |
| 14 | 15 | ||
| 15 | Optional properties: | 16 | Optional properties: |
| @@ -1,27 +0,0 @@ | |||
| 1 | BMP085/BMP18x/BMP28x digital pressure sensors | ||
| 2 | |||
| 3 | Required properties: | ||
| 4 | - compatible: must be one of: | ||
| 5 | "bosch,bmp085" | ||
| 6 | "bosch,bmp180" | ||
| 7 | "bosch,bmp280" | ||
| 8 | "bosch,bme280" | ||
| 9 | |||
| 10 | Optional properties: | ||
| 11 | - interrupts: interrupt mapping for IRQ | ||
| 12 | - reset-gpios: a GPIO line handling reset of the sensor: as the line is | ||
| 13 | active low, it should be marked GPIO_ACTIVE_LOW (see gpio/gpio.txt) | ||
| 14 | - vddd-supply: digital voltage regulator (see regulator/regulator.txt) | ||
| 15 | - vdda-supply: analog voltage regulator (see regulator/regulator.txt) | ||
| 16 | |||
| 17 | Example: | ||
| 18 | |||
| 19 | pressure@77 { | ||
| 20 | compatible = "bosch,bmp085"; | ||
| 21 | reg = <0x77>; | ||
| 22 | interrupt-parent = <&gpio0>; | ||
| 23 | interrupts = <25 IRQ_TYPE_EDGE_RISING>; | ||
| 24 | reset-gpios = <&gpio0 26 GPIO_ACTIVE_LOW>; | ||
| 25 | vddd-supply = <&foo>; | ||
| 26 | vdda-supply = <&bar>; | ||
| 27 | }; | ||
| @@ -0,0 +1,70 @@ | |||
| 1 | # SPDX-License-Identifier: GPL-2.0 | ||
| 2 | %YAML 1.2 | ||
| 3 | --- | ||
| 4 | $id: http://devicetree.org/schemas/iio/pressure/bmp085.yaml# | ||
| 5 | $schema: http://devicetree.org/meta-schemas/core.yaml# | ||
| 6 | |||
| 7 | title: BMP085/BMP180/BMP280/BME280 pressure iio sensors | ||
| 8 | |||
| 9 | maintainers: | ||
| 10 | - Andreas Klinger <ak@it-klinger.de> | ||
| 11 | |||
| 12 | description: | | ||
| 13 | Pressure, temperature and humidity iio sensors with i2c and spi interfaces | ||
| 14 | |||
| 15 | Specifications about the sensor can be found at: | ||
| 16 | https://www.bosch-sensortec.com/bst/products/all_products/bmp180 | ||
| 17 | https://www.bosch-sensortec.com/bst/products/all_products/bmp280 | ||
| 18 | https://www.bosch-sensortec.com/bst/products/all_products/bme280 | ||
| 19 | |||
| 20 | properties: | ||
| 21 | compatible: | ||
| 22 | enum: | ||
| 23 | - bosch,bmp085 | ||
| 24 | - bosch,bmp180 | ||
| 25 | - bosch,bmp280 | ||
| 26 | - bosch,bme280 | ||
| 27 | |||
| 28 | vddd-supply: | ||
| 29 | description: | ||
| 30 | digital voltage regulator (see regulator/regulator.txt) | ||
| 31 | maxItems: 1 | ||
| 32 | |||
| 33 | vdda-supply: | ||
| 34 | description: | ||
| 35 | analog voltage regulator (see regulator/regulator.txt) | ||
| 36 | maxItems: 1 | ||
| 37 | |||
| 38 | reset-gpios: | ||
| 39 | description: | ||
| 40 | A GPIO line handling reset of the sensor. As the line is active low, | ||
| 41 | it should be marked GPIO_ACTIVE_LOW (see gpio/gpio.txt) | ||
| 42 | maxItems: 1 | ||
| 43 | |||
| 44 | interrupts: | ||
| 45 | description: | ||
| 46 | interrupt mapping for IRQ (BMP085 only) | ||
| 47 | maxItems: 1 | ||
| 48 | |||
| 49 | required: | ||
| 50 | - compatible | ||
| 51 | - vddd-supply | ||
| 52 | - vdda-supply | ||
| 53 | |||
| 54 | examples: | ||
| 55 | - | | ||
| 56 | #include <dt-bindings/gpio/gpio.h> | ||
| 57 | #include <dt-bindings/interrupt-controller/irq.h> | ||
| 58 | i2c0 { | ||
| 59 | #address-cells = <1>; | ||
| 60 | #size-cells = <0>; | ||
| 61 | pressure@77 { | ||
| 62 | compatible = "bosch,bmp085"; | ||
| 63 | reg = <0x77>; | ||
| 64 | interrupt-parent = <&gpio0>; | ||
| 65 | interrupts = <25 IRQ_TYPE_EDGE_RISING>; | ||
| 66 | reset-gpios = <&gpio0 26 GPIO_ACTIVE_LOW>; | ||
| 67 | vddd-supply = <&foo>; | ||
| 68 | vdda-supply = <&bar>; | ||
| 69 | }; | ||
| 70 | }; | ||
| @@ -4,7 +4,7 @@ · 3 unmodified lines | |||
| 4 | $id: http://devicetree.org/schemas/iio/proximity/devantech-srf04.yaml# | 4 | $id: http://devicetree.org/schemas/iio/proximity/devantech-srf04.yaml# |
| 5 | $schema: http://devicetree.org/meta-schemas/core.yaml# | 5 | $schema: http://devicetree.org/meta-schemas/core.yaml# |
| 6 | 6 | ||
| 7 | title: Devantech SRF04 ultrasonic range finder | 7 | title: Devantech SRF04 and Maxbotix mb1000 ultrasonic range finder |
| 8 | 8 | ||
| 9 | maintainers: | 9 | maintainers: |
| 10 | - Andreas Klinger <ak@it-klinger.de> | 10 | - Andreas Klinger <ak@it-klinger.de> |
| @@ -16,19 +16,28 @@ description: | · 5 unmodified lines | |||
| 16 | - echo-gpio is held high by the sensor after sending ultrasonic burst | 16 | - echo-gpio is held high by the sensor after sending ultrasonic burst |
| 17 | until it is received once again | 17 | until it is received once again |
| 18 | 18 | ||
| 19 | Specifications about the driver can be found at: | 19 | Specifications about the devices can be found at: |
| 20 | http://www.robot-electronics.co.uk/htm/srf04tech.htm | 20 | http://www.robot-electronics.co.uk/htm/srf04tech.htm |
| 21 | 21 | ||
| 22 | http://www.maxbotix.com/documents/LV-MaxSonar-EZ_Datasheet.pdf | ||
| 23 | |||
| 22 | properties: | 24 | properties: |
| 23 | compatible: | 25 | compatible: |
| 24 | items: | 26 | enum: |
| 25 | - const: devantech,srf04 | 27 | - devantech,srf04 |
| 28 | - maxbotix,mb1000 | ||
| 29 | - maxbotix,mb1010 | ||
| 30 | - maxbotix,mb1020 | ||
| 31 | - maxbotix,mb1030 | ||
| 32 | - maxbotix,mb1040 | ||
| 26 | 33 | ||
| 27 | trig-gpios: | 34 | trig-gpios: |
| 28 | description: | 35 | description: |
| 29 | Definition of the GPIO for the triggering (output) This GPIO is set | 36 | Definition of the GPIO for the triggering (output) |
| 30 | for about 10 us by the driver to tell the device it should initiate | 37 | This GPIO is set for about 10 us by the driver to tell the device it |
| 31 | the measurement cycle. | 38 | should initiate the measurement cycle. |
| 39 | See Documentation/devicetree/bindings/gpio/gpio.txt for information | ||
| 40 | on how to specify a consumer gpio. | ||
| 32 | maxItems: 1 | 41 | maxItems: 1 |
| 33 | 42 | ||
| 34 | echo-gpios: | 43 | echo-gpios: |
| @@ -40,8 +49,6 @@ properties: · 5 unmodified lines | |||
| 40 | trip. | 49 | trip. |
| 41 | It needs to be an GPIO which is able to deliver an interrupt because | 50 | It needs to be an GPIO which is able to deliver an interrupt because |
| 42 | the time between two interrupts is measured in the driver. | 51 | the time between two interrupts is measured in the driver. |
| 43 | See Documentation/devicetree/bindings/gpio/gpio.txt for information | ||
| 44 | on how to specify a consumer gpio. | ||
| 45 | maxItems: 1 | 52 | maxItems: 1 |
| 46 | 53 | ||
| 47 | required: | 54 | required: |
| @@ -49,6 +49,7 @@ Accelerometers: · 48 unmodified lines | |||
| 49 | - st,lis2dw12 | 49 | - st,lis2dw12 |
| 50 | - st,lis3dhh | 50 | - st,lis3dhh |
| 51 | - st,lis3de | 51 | - st,lis3de |
| 52 | - st,lis2de12 | ||
| 52 | 53 | ||
| 53 | Gyroscopes: | 54 | Gyroscopes: |
| 54 | - st,l3g4200d-gyro | 55 | - st,l3g4200d-gyro |
| @@ -11124,6 +11124,16 @@ F: Documentation/ABI/stable/sysfs-bus-nvmem · 11123 unmodified lines | |||
| 11124 | F: include/linux/nvmem-consumer.h | 11124 | F: include/linux/nvmem-consumer.h |
| 11125 | F: include/linux/nvmem-provider.h | 11125 | F: include/linux/nvmem-provider.h |
| 11126 | 11126 | ||
| 11127 | NXP FXAS21002C DRIVER | ||
| 11128 | M: Rui Miguel Silva <rmfrfs@gmail.com> | ||
| 11129 | L: linux-iio@vger.kernel.org | ||
| 11130 | S: Maintained | ||
| 11131 | F: Documentation/devicetree/bindings/iio/gyroscope/fxas21002c.txt | ||
| 11132 | F: drivers/iio/gyro/fxas21002c_core.c | ||
| 11133 | F: drivers/iio/gyro/fxas21002c.h | ||
| 11134 | F: drivers/iio/gyro/fxas21002c_i2c.c | ||
| 11135 | F: drivers/iio/gyro/fxas21002c_spi.c | ||
| 11136 | |||
| 11127 | NXP SGTL5000 DRIVER | 11137 | NXP SGTL5000 DRIVER |
| 11128 | M: Fabio Estevam <festevam@gmail.com> | 11138 | M: Fabio Estevam <festevam@gmail.com> |
| 11129 | L: alsa-devel@alsa-project.org (moderated for non-subscribers) | 11139 | L: alsa-devel@alsa-project.org (moderated for non-subscribers) |
| @@ -223,7 +223,7 @@ config IIO_ST_ACCEL_3AXIS · 222 unmodified lines | |||
| 223 | Say yes here to build support for STMicroelectronics accelerometers: | 223 | Say yes here to build support for STMicroelectronics accelerometers: |
| 224 | LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC, | 224 | LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC, |
| 225 | LIS331DLH, LSM303DL, LSM303DLM, LSM330, LIS2DH12, H3LIS331DL, | 225 | LIS331DLH, LSM303DL, LSM303DLM, LSM330, LIS2DH12, H3LIS331DL, |
| 226 | LNG2DM, LIS3DE | 226 | LNG2DM, LIS3DE, LIS2DE12 |
| 227 | 227 | ||
| 228 | This driver can also be built as a module. If so, these modules | 228 | This driver can also be built as a module. If so, these modules |
| 229 | will be created: | 229 | will be created: |
| @@ -394,7 +394,7 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on) · 393 unmodified lines | |||
| 394 | 394 | ||
| 395 | if (ret < 0) { | 395 | if (ret < 0) { |
| 396 | dev_err(dev, | 396 | dev_err(dev, |
| 397 | "Failed: bmc150_accel_set_power_state for %d\n", on); | 397 | "Failed: %s for %d\n", __func__, on); |
| 398 | if (on) | 398 | if (on) |
| 399 | pm_runtime_put_noidle(dev); | 399 | pm_runtime_put_noidle(dev); |
| 400 | 400 | ||
| @@ -451,7 +451,7 @@ static int kxcjk1013_set_power_state(struct kxcjk1013_data *data, bool on) · 450 unmodified lines | |||
| 451 | } | 451 | } |
| 452 | if (ret < 0) { | 452 | if (ret < 0) { |
| 453 | dev_err(&data->client->dev, | 453 | dev_err(&data->client->dev, |
| 454 | "Failed: kxcjk1013_set_power_state for %d\n", on); | 454 | "Failed: %s for %d\n", __func__, on); |
| 455 | if (on) | 455 | if (on) |
| 456 | pm_runtime_put_noidle(&data->client->dev); | 456 | pm_runtime_put_noidle(&data->client->dev); |
| 457 | return ret; | 457 | return ret; |
| @@ -1491,6 +1491,7 @@ static const struct acpi_device_id kx_acpi_match[] = { · 1033 unmodified lines | |||
| 1491 | {"KXCJ1013", KXCJK1013}, | 1491 | {"KXCJ1013", KXCJK1013}, |
| 1492 | {"KXCJ1008", KXCJ91008}, | 1492 | {"KXCJ1008", KXCJ91008}, |
| 1493 | {"KXCJ9000", KXCJ91008}, | 1493 | {"KXCJ9000", KXCJ91008}, |
| 1494 | {"KIOX0008", KXCJ91008}, | ||
| 1494 | {"KIOX0009", KXTJ21009}, | 1495 | {"KIOX0009", KXTJ21009}, |
| 1495 | {"KIOX000A", KXCJ91008}, | 1496 | {"KIOX000A", KXCJ91008}, |
| 1496 | {"KIOX010A", KXCJ91008}, /* KXCJ91008 inside the display of a 2-in-1 */ | 1497 | {"KIOX010A", KXCJ91008}, /* KXCJ91008 inside the display of a 2-in-1 */ |
| @@ -34,6 +34,7 @@ enum st_accel_type { · 33 unmodified lines | |||
| 34 | LIS3LV02DL, | 34 | LIS3LV02DL, |
| 35 | LIS2DW12, | 35 | LIS2DW12, |
| 36 | LIS3DHH, | 36 | LIS3DHH, |
| 37 | LIS2DE12, | ||
| 37 | ST_ACCEL_MAX, | 38 | ST_ACCEL_MAX, |
| 38 | }; | 39 | }; |
| 39 | 40 | ||
| @@ -57,6 +58,7 @@ enum st_accel_type { · 17 unmodified lines | |||
| 57 | #define LIS2DW12_ACCEL_DEV_NAME "lis2dw12" | 58 | #define LIS2DW12_ACCEL_DEV_NAME "lis2dw12" |
| 58 | #define LIS3DHH_ACCEL_DEV_NAME "lis3dhh" | 59 | #define LIS3DHH_ACCEL_DEV_NAME "lis3dhh" |
| 59 | #define LIS3DE_ACCEL_DEV_NAME "lis3de" | 60 | #define LIS3DE_ACCEL_DEV_NAME "lis3de" |
| 61 | #define LIS2DE12_ACCEL_DEV_NAME "lis2de12" | ||
| 60 | 62 | ||
| 61 | /** | 63 | /** |
| 62 | * struct st_sensors_platform_data - default accel platform data | 64 | * struct st_sensors_platform_data - default accel platform data |
| @@ -831,6 +831,82 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { · 830 unmodified lines | |||
| 831 | .multi_read_bit = false, | 831 | .multi_read_bit = false, |
| 832 | .bootime = 2, | 832 | .bootime = 2, |
| 833 | }, | 833 | }, |
| 834 | { | ||
| 835 | .wai = 0x33, | ||
| 836 | .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, | ||
| 837 | .sensors_supported = { | ||
| 838 | [0] = LIS2DE12_ACCEL_DEV_NAME, | ||
| 839 | }, | ||
| 840 | .ch = (struct iio_chan_spec *)st_accel_8bit_channels, | ||
| 841 | .odr = { | ||
| 842 | .addr = 0x20, | ||
| 843 | .mask = 0xf0, | ||
| 844 | .odr_avl = { | ||
| 845 | { .hz = 1, .value = 0x01, }, | ||
| 846 | { .hz = 10, .value = 0x02, }, | ||
| 847 | { .hz = 25, .value = 0x03, }, | ||
| 848 | { .hz = 50, .value = 0x04, }, | ||
| 849 | { .hz = 100, .value = 0x05, }, | ||
| 850 | { .hz = 200, .value = 0x06, }, | ||
| 851 | { .hz = 400, .value = 0x07, }, | ||
| 852 | { .hz = 1620, .value = 0x08, }, | ||
| 853 | { .hz = 5376, .value = 0x09, }, | ||
| 854 | }, | ||
| 855 | }, | ||
| 856 | .pw = { | ||
| 857 | .addr = 0x20, | ||
| 858 | .mask = 0xf0, | ||
| 859 | .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, | ||
| 860 | }, | ||
| 861 | .enable_axis = { | ||
| 862 | .addr = ST_SENSORS_DEFAULT_AXIS_ADDR, | ||
| 863 | .mask = ST_SENSORS_DEFAULT_AXIS_MASK, | ||
| 864 | }, | ||
| 865 | .fs = { | ||
| 866 | .addr = 0x23, | ||
| 867 | .mask = 0x30, | ||
| 868 | .fs_avl = { | ||
| 869 | [0] = { | ||
| 870 | .num = ST_ACCEL_FS_AVL_2G, | ||
| 871 | .value = 0x00, | ||
| 872 | .gain = IIO_G_TO_M_S_2(15600), | ||
| 873 | }, | ||
| 874 | [1] = { | ||
| 875 | .num = ST_ACCEL_FS_AVL_4G, | ||
| 876 | .value = 0x01, | ||
| 877 | .gain = IIO_G_TO_M_S_2(31200), | ||
| 878 | }, | ||
| 879 | [2] = { | ||
| 880 | .num = ST_ACCEL_FS_AVL_8G, | ||
| 881 | .value = 0x02, | ||
| 882 | .gain = IIO_G_TO_M_S_2(62500), | ||
| 883 | }, | ||
| 884 | [3] = { | ||
| 885 | .num = ST_ACCEL_FS_AVL_16G, | ||
| 886 | .value = 0x03, | ||
| 887 | .gain = IIO_G_TO_M_S_2(187500), | ||
| 888 | }, | ||
| 889 | }, | ||
| 890 | }, | ||
| 891 | .drdy_irq = { | ||
| 892 | .int1 = { | ||
| 893 | .addr = 0x22, | ||
| 894 | .mask = 0x10, | ||
| 895 | }, | ||
| 896 | .addr_ihl = 0x25, | ||
| 897 | .mask_ihl = 0x02, | ||
| 898 | .stat_drdy = { | ||
| 899 | .addr = ST_SENSORS_DEFAULT_STAT_ADDR, | ||
| 900 | .mask = 0x07, | ||
| 901 | }, | ||
| 902 | }, | ||
| 903 | .sim = { | ||
| 904 | .addr = 0x23, | ||
| 905 | .value = BIT(0), | ||
| 906 | }, | ||
| 907 | .multi_read_bit = true, | ||
| 908 | .bootime = 2, | ||
| 909 | }, | ||
| 834 | }; | 910 | }; |
| 835 | 911 | ||
| 836 | static int st_accel_read_raw(struct iio_dev *indio_dev, | 912 | static int st_accel_read_raw(struct iio_dev *indio_dev, |
| @@ -102,6 +102,10 @@ static const struct of_device_id st_accel_of_match[] = { · 101 unmodified lines | |||
| 102 | .compatible = "st,lis3de", | 102 | .compatible = "st,lis3de", |
| 103 | .data = LIS3DE_ACCEL_DEV_NAME, | 103 | .data = LIS3DE_ACCEL_DEV_NAME, |
| 104 | }, | 104 | }, |
| 105 | { | ||
| 106 | .compatible = "st,lis2de12", | ||
| 107 | .data = LIS2DE12_ACCEL_DEV_NAME, | ||
| 108 | }, | ||
| 105 | {}, | 109 | {}, |
| 106 | }; | 110 | }; |
| 107 | MODULE_DEVICE_TABLE(of, st_accel_of_match); | 111 | MODULE_DEVICE_TABLE(of, st_accel_of_match); |
| @@ -140,6 +144,7 @@ static const struct i2c_device_id st_accel_id_table[] = { · 32 unmodified lines | |||
| 140 | { LIS3LV02DL_ACCEL_DEV_NAME }, | 144 | { LIS3LV02DL_ACCEL_DEV_NAME }, |
| 141 | { LIS2DW12_ACCEL_DEV_NAME }, | 145 | { LIS2DW12_ACCEL_DEV_NAME }, |
| 142 | { LIS3DE_ACCEL_DEV_NAME }, | 146 | { LIS3DE_ACCEL_DEV_NAME }, |
| 147 | { LIS2DE12_ACCEL_DEV_NAME }, | ||
| 143 | {}, | 148 | {}, |
| 144 | }; | 149 | }; |
| 145 | MODULE_DEVICE_TABLE(i2c, st_accel_id_table); | 150 | MODULE_DEVICE_TABLE(i2c, st_accel_id_table); |
| @@ -553,7 +553,7 @@ config MAX1363 · 552 unmodified lines | |||
| 553 | To compile this driver as a module, choose M here: the module will be | 553 | To compile this driver as a module, choose M here: the module will be |
| 554 | called max1363. | 554 | called max1363. |
| 555 | 555 | ||
| 556 | config MAX9611 | 556 | config MAX9611 |
| 557 | tristate "Maxim max9611/max9612 ADC driver" | 557 | tristate "Maxim max9611/max9612 ADC driver" |
| 558 | depends on I2C | 558 | depends on I2C |
| 559 | help | 559 | help |
| @@ -821,7 +821,9 @@ config STM32_DFSDM_ADC · 261 unmodified lines | |||
| 821 | depends on (ARCH_STM32 && OF) || COMPILE_TEST | 821 | depends on (ARCH_STM32 && OF) || COMPILE_TEST |
| 822 | select STM32_DFSDM_CORE | 822 | select STM32_DFSDM_CORE |
| 823 | select REGMAP_MMIO | 823 | select REGMAP_MMIO |
| 824 | select IIO_BUFFER | ||
| 824 | select IIO_BUFFER_HW_CONSUMER | 825 | select IIO_BUFFER_HW_CONSUMER |
| 826 | select IIO_TRIGGERED_BUFFER | ||
| 825 | help | 827 | help |
| 826 | Select this option to support ADCSigma delta modulator for | 828 | Select this option to support ADCSigma delta modulator for |
| 827 | STMicroelectronics STM32 digital filter for sigma delta converter. | 829 | STMicroelectronics STM32 digital filter for sigma delta converter. |
| @@ -968,7 +970,7 @@ config TI_ADS1015 · 140 unmodified lines | |||
| 968 | 970 | ||
| 969 | config TI_ADS7950 | 971 | config TI_ADS7950 |
| 970 | tristate "Texas Instruments ADS7950 ADC driver" | 972 | tristate "Texas Instruments ADS7950 ADC driver" |
| 971 | depends on SPI | 973 | depends on SPI && GPIOLIB |
| 972 | select IIO_BUFFER | 974 | select IIO_BUFFER |
| 973 | select IIO_TRIGGERED_BUFFER | 975 | select IIO_TRIGGERED_BUFFER |
| 974 | help | 976 | help |
| @@ -979,6 +981,16 @@ config TI_ADS7950 · 4 unmodified lines | |||
| 979 | To compile this driver as a module, choose M here: the | 981 | To compile this driver as a module, choose M here: the |
| 980 | module will be called ti-ads7950. | 982 | module will be called ti-ads7950. |
| 981 | 983 | ||
| 984 | config TI_ADS8344 | ||
| 985 | tristate "Texas Instruments ADS8344" | ||
| 986 | depends on SPI && OF | ||
| 987 | help | ||
| 988 | If you say yes here you get support for Texas Instruments ADS8344 | ||
| 989 | ADC chips | ||
| 990 | |||
| 991 | This driver can also be built as a module. If so, the module will be | ||
| 992 | called ti-ads8344. | ||
| 993 | |||
| 982 | config TI_ADS8688 | 994 | config TI_ADS8688 |
| 983 | tristate "Texas Instruments ADS8688" | 995 | tristate "Texas Instruments ADS8688" |
| 984 | depends on SPI && OF | 996 | depends on SPI && OF |
| @@ -88,6 +88,7 @@ obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o · 87 unmodified lines | |||
| 88 | obj-$(CONFIG_TI_ADC161S626) += ti-adc161s626.o | 88 | obj-$(CONFIG_TI_ADC161S626) += ti-adc161s626.o |
| 89 | obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o | 89 | obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o |
| 90 | obj-$(CONFIG_TI_ADS7950) += ti-ads7950.o | 90 | obj-$(CONFIG_TI_ADS7950) += ti-ads7950.o |
| 91 | obj-$(CONFIG_TI_ADS8344) += ti-ads8344.o | ||
| 91 | obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o | 92 | obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o |
| 92 | obj-$(CONFIG_TI_ADS124S08) += ti-ads124s08.o | 93 | obj-$(CONFIG_TI_ADS124S08) += ti-ads124s08.o |
| 93 | obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o | 94 | obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o |
| @@ -31,7 +31,7 @@ · 30 unmodified lines | |||
| 31 | * Scales are computed as 5000/32768 and 10000/32768 respectively, | 31 | * Scales are computed as 5000/32768 and 10000/32768 respectively, |
| 32 | * so that when applied to the raw values they provide mV values | 32 | * so that when applied to the raw values they provide mV values |
| 33 | */ | 33 | */ |
| 34 | static const unsigned int scale_avail[2] = { | 34 | static const unsigned int ad7606_scale_avail[2] = { |
| 35 | 152588, 305176 | 35 | 152588, 305176 |
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| @@ -39,6 +39,10 @@ static const unsigned int ad7606_oversampling_avail[7] = { · 1 unmodified line | |||
| 39 | 1, 2, 4, 8, 16, 32, 64, | 39 | 1, 2, 4, 8, 16, 32, 64, |
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | static const unsigned int ad7616_oversampling_avail[8] = { | ||
| 43 | 1, 2, 4, 8, 16, 32, 64, 128, | ||
| 44 | }; | ||
| 45 | |||
| 42 | static int ad7606_reset(struct ad7606_state *st) | 46 | static int ad7606_reset(struct ad7606_state *st) |
| 43 | { | 47 | { |
| 44 | if (st->gpio_reset) { | 48 | if (st->gpio_reset) { |
| @@ -154,7 +158,7 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, · 109 unmodified lines | |||
| 154 | return IIO_VAL_INT; | 158 | return IIO_VAL_INT; |
| 155 | case IIO_CHAN_INFO_SCALE: | 159 | case IIO_CHAN_INFO_SCALE: |
| 156 | *val = 0; | 160 | *val = 0; |
| 157 | *val2 = scale_avail[st->range]; | 161 | *val2 = st->scale_avail[st->range]; |
| 158 | return IIO_VAL_INT_PLUS_MICRO; | 162 | return IIO_VAL_INT_PLUS_MICRO; |
| 159 | case IIO_CHAN_INFO_OVERSAMPLING_RATIO: | 163 | case IIO_CHAN_INFO_OVERSAMPLING_RATIO: |
| 160 | *val = st->oversampling; | 164 | *val = st->oversampling; |
| @@ -163,21 +167,31 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, · 2 unmodified lines | |||
| 163 | return -EINVAL; | 167 | return -EINVAL; |
| 164 | } | 168 | } |
| 165 | 169 | ||
| 166 | static ssize_t in_voltage_scale_available_show(struct device *dev, | 170 | static ssize_t ad7606_show_avail(char *buf, const unsigned int *vals, |
| 167 | struct device_attribute *attr, | 171 | unsigned int n, bool micros) |
| 168 | char *buf) | ||
| 169 | { | 172 | { |
| 170 | int i, len = 0; | 173 | size_t len = 0; |
| 171 | 174 | int i; | |
| 172 | for (i = 0; i < ARRAY_SIZE(scale_avail); i++) | ||
| 173 | len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", | ||
| 174 | scale_avail[i]); | ||
| 175 | 175 | ||
| 176 | for (i = 0; i < n; i++) { | ||
| 177 | len += scnprintf(buf + len, PAGE_SIZE - len, | ||
| 178 | micros ? "0.%06u " : "%u ", vals[i]); | ||
| 179 | } | ||
| 176 | buf[len - 1] = '\n'; | 180 | buf[len - 1] = '\n'; |
| 177 | 181 | ||
| 178 | return len; | 182 | return len; |
| 179 | } | 183 | } |
| 180 | 184 | ||
| 185 | static ssize_t in_voltage_scale_available_show(struct device *dev, | ||
| 186 | struct device_attribute *attr, | ||
| 187 | char *buf) | ||
| 188 | { | ||
| 189 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); | ||
| 190 | struct ad7606_state *st = iio_priv(indio_dev); | ||
| 191 | |||
| 192 | return ad7606_show_avail(buf, st->scale_avail, st->num_scales, true); | ||
| 193 | } | ||
| 194 | |||
| 181 | static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0); | 195 | static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0); |
| 182 | 196 | ||
| 183 | static int ad7606_write_raw(struct iio_dev *indio_dev, | 197 | static int ad7606_write_raw(struct iio_dev *indio_dev, |
| @@ -193,7 +207,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, · 9 unmodified lines | |||
| 193 | switch (mask) { | 207 | switch (mask) { |
| 194 | case IIO_CHAN_INFO_SCALE: | 208 | case IIO_CHAN_INFO_SCALE: |
| 195 | mutex_lock(&st->lock); | 209 | mutex_lock(&st->lock); |
| 196 | i = find_closest(val2, scale_avail, ARRAY_SIZE(scale_avail)); | 210 | i = find_closest(val2, st->scale_avail, st->num_scales); |
| 197 | gpiod_set_value(st->gpio_range, i); | 211 | gpiod_set_value(st->gpio_range, i); |
| 198 | st->range = i; | 212 | st->range = i; |
| 199 | mutex_unlock(&st->lock); | 213 | mutex_unlock(&st->lock); |
| @@ -202,15 +216,20 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, · 2 unmodified lines | |||
| 202 | case IIO_CHAN_INFO_OVERSAMPLING_RATIO: | 216 | case IIO_CHAN_INFO_OVERSAMPLING_RATIO: |
| 203 | if (val2) | 217 | if (val2) |
| 204 | return -EINVAL; | 218 | return -EINVAL; |
| 205 | i = find_closest(val, ad7606_oversampling_avail, | 219 | i = find_closest(val, st->oversampling_avail, |
| 206 | ARRAY_SIZE(ad7606_oversampling_avail)); | 220 | st->num_os_ratios); |
| 207 | 221 | ||
| 208 | values[0] = i; | 222 | values[0] = i; |
| 209 | 223 | ||
| 210 | mutex_lock(&st->lock); | 224 | mutex_lock(&st->lock); |
| 211 | gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc, | 225 | gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc, |
| 212 | st->gpio_os->info, values); | 226 | st->gpio_os->info, values); |
| 213 | st->oversampling = ad7606_oversampling_avail[i]; | 227 | |
| 228 | /* AD7616 requires a reset to update value */ | ||
| 229 | if (st->chip_info->os_req_reset) | ||
| 230 | ad7606_reset(st); | ||
| 231 | |||
| 232 | st->oversampling = st->oversampling_avail[i]; | ||
| 214 | mutex_unlock(&st->lock); | 233 | mutex_unlock(&st->lock); |
| 215 | 234 | ||
| 216 | return 0; | 235 | return 0; |
| @@ -219,11 +238,23 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, · 2 unmodified lines | |||
| 219 | } | 238 | } |
| 220 | } | 239 | } |
| 221 | 240 | ||
| 222 | static IIO_CONST_ATTR(oversampling_ratio_available, "1 2 4 8 16 32 64"); | 241 | static ssize_t ad7606_oversampling_ratio_avail(struct device *dev, |
| 242 | struct device_attribute *attr, | ||
| 243 | char *buf) | ||
| 244 | { | ||
| 245 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); | ||
| 246 | struct ad7606_state *st = iio_priv(indio_dev); | ||
| 247 | |||
| 248 | return ad7606_show_avail(buf, st->oversampling_avail, | ||
| 249 | st->num_os_ratios, false); | ||
| 250 | } | ||
| 251 | |||
| 252 | static IIO_DEVICE_ATTR(oversampling_ratio_available, 0444, | ||
| 253 | ad7606_oversampling_ratio_avail, NULL, 0); | ||
| 223 | 254 | ||
| 224 | static struct attribute *ad7606_attributes_os_and_range[] = { | 255 | static struct attribute *ad7606_attributes_os_and_range[] = { |
| 225 | &iio_dev_attr_in_voltage_scale_available.dev_attr.attr, | 256 | &iio_dev_attr_in_voltage_scale_available.dev_attr.attr, |
| 226 | &iio_const_attr_oversampling_ratio_available.dev_attr.attr, | 257 | &iio_dev_attr_oversampling_ratio_available.dev_attr.attr, |
| 227 | NULL, | 258 | NULL, |
| 228 | }; | 259 | }; |
| 229 | 260 | ||
| @@ -232,7 +263,7 @@ static const struct attribute_group ad7606_attribute_group_os_and_range = { · 2 unmodified lines | |||
| 232 | }; | 263 | }; |
| 233 | 264 | ||
| 234 | static struct attribute *ad7606_attributes_os[] = { | 265 | static struct attribute *ad7606_attributes_os[] = { |
| 235 | &iio_const_attr_oversampling_ratio_available.dev_attr.attr, | 266 | &iio_dev_attr_oversampling_ratio_available.dev_attr.attr, |
| 236 | NULL, | 267 | NULL, |
| 237 | }; | 268 | }; |
| 238 | 269 | ||
| @@ -292,6 +323,36 @@ static const struct iio_chan_spec ad7606_channels[] = { · 53 unmodified lines | |||
| 292 | AD7606_CHANNEL(7), | 323 | AD7606_CHANNEL(7), |
| 293 | }; | 324 | }; |
| 294 | 325 | ||
| 326 | /* | ||
| 327 | * The current assumption that this driver makes for AD7616, is that it's | ||
| 328 | * working in Hardware Mode with Serial, Burst and Sequencer modes activated. | ||
| 329 | * To activate them, following pins must be pulled high: | ||
| 330 | * -SER/PAR | ||
| 331 | * -SEQEN | ||
| 332 | * And following pins must be pulled low: | ||
| 333 | * -WR/BURST | ||
| 334 | * -DB4/SER1W | ||
| 335 | */ | ||
| 336 | static const struct iio_chan_spec ad7616_channels[] = { | ||
| 337 | IIO_CHAN_SOFT_TIMESTAMP(16), | ||
| 338 | AD7606_CHANNEL(0), | ||
| 339 | AD7606_CHANNEL(1), | ||
| 340 | AD7606_CHANNEL(2), | ||
| 341 | AD7606_CHANNEL(3), | ||
| 342 | AD7606_CHANNEL(4), | ||
| 343 | AD7606_CHANNEL(5), | ||
| 344 | AD7606_CHANNEL(6), | ||
| 345 | AD7606_CHANNEL(7), | ||
| 346 | AD7606_CHANNEL(8), | ||
| 347 | AD7606_CHANNEL(9), | ||
| 348 | AD7606_CHANNEL(10), | ||
| 349 | AD7606_CHANNEL(11), | ||
| 350 | AD7606_CHANNEL(12), | ||
| 351 | AD7606_CHANNEL(13), | ||
| 352 | AD7606_CHANNEL(14), | ||
| 353 | AD7606_CHANNEL(15), | ||
| 354 | }; | ||
| 355 | |||
| 295 | static const struct ad7606_chip_info ad7606_chip_info_tbl[] = { | 356 | static const struct ad7606_chip_info ad7606_chip_info_tbl[] = { |
| 296 | /* More devices added in future */ | 357 | /* More devices added in future */ |
| 297 | [ID_AD7605_4] = { | 358 | [ID_AD7605_4] = { |
| @@ -301,17 +362,27 @@ static const struct ad7606_chip_info ad7606_chip_info_tbl[] = { · 3 unmodified lines | |||
| 301 | [ID_AD7606_8] = { | 362 | [ID_AD7606_8] = { |
| 302 | .channels = ad7606_channels, | 363 | .channels = ad7606_channels, |
| 303 | .num_channels = 9, | 364 | .num_channels = 9, |
| 304 | .has_oversampling = true, | 365 | .oversampling_avail = ad7606_oversampling_avail, |
| 366 | .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), | ||
| 305 | }, | 367 | }, |
| 306 | [ID_AD7606_6] = { | 368 | [ID_AD7606_6] = { |
| 307 | .channels = ad7606_channels, | 369 | .channels = ad7606_channels, |
| 308 | .num_channels = 7, | 370 | .num_channels = 7, |
| 309 | .has_oversampling = true, | 371 | .oversampling_avail = ad7606_oversampling_avail, |
| 372 | .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), | ||
| 310 | }, | 373 | }, |
| 311 | [ID_AD7606_4] = { | 374 | [ID_AD7606_4] = { |
| 312 | .channels = ad7606_channels, | 375 | .channels = ad7606_channels, |
| 313 | .num_channels = 5, | 376 | .num_channels = 5, |
| 314 | .has_oversampling = true, | 377 | .oversampling_avail = ad7606_oversampling_avail, |
| 378 | .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), | ||
| 379 | }, | ||
| 380 | [ID_AD7616] = { | ||
| 381 | .channels = ad7616_channels, | ||
| 382 | .num_channels = 17, | ||
| 383 | .oversampling_avail = ad7616_oversampling_avail, | ||
| 384 | .oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail), | ||
| 385 | .os_req_reset = true, | ||
| 315 | }, | 386 | }, |
| 316 | }; | 387 | }; |
| 317 | 388 | ||
| @@ -343,7 +414,7 @@ static int ad7606_request_gpios(struct ad7606_state *st) · 25 unmodified lines | |||
| 343 | if (IS_ERR(st->gpio_frstdata)) | 414 | if (IS_ERR(st->gpio_frstdata)) |
| 344 | return PTR_ERR(st->gpio_frstdata); | 415 | return PTR_ERR(st->gpio_frstdata); |
| 345 | 416 | ||
| 346 | if (!st->chip_info->has_oversampling) | 417 | if (!st->chip_info->oversampling_num) |
| 347 | return 0; | 418 | return 0; |
| 348 | 419 | ||
| 349 | st->gpio_os = devm_gpiod_get_array_optional(dev, | 420 | st->gpio_os = devm_gpiod_get_array_optional(dev, |
| @@ -467,6 +538,8 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, · 117 unmodified lines | |||
| 467 | /* tied to logic low, analog input range is +/- 5V */ | 538 | /* tied to logic low, analog input range is +/- 5V */ |
| 468 | st->range = 0; | 539 | st->range = 0; |
| 469 | st->oversampling = 1; | 540 | st->oversampling = 1; |
| 541 | st->scale_avail = ad7606_scale_avail; | ||
| 542 | st->num_scales = ARRAY_SIZE(ad7606_scale_avail); | ||
| 470 | 543 | ||
| 471 | st->reg = devm_regulator_get(dev, "avcc"); | 544 | st->reg = devm_regulator_get(dev, "avcc"); |
| 472 | if (IS_ERR(st->reg)) | 545 | if (IS_ERR(st->reg)) |
| @@ -484,6 +557,11 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, · 11 unmodified lines | |||
| 484 | 557 | ||
| 485 | st->chip_info = &ad7606_chip_info_tbl[id]; | 558 | st->chip_info = &ad7606_chip_info_tbl[id]; |
| 486 | 559 | ||
| 560 | if (st->chip_info->oversampling_num) { | ||
| 561 | st->oversampling_avail = st->chip_info->oversampling_avail; | ||
| 562 | st->num_os_ratios = st->chip_info->oversampling_num; | ||
| 563 | } | ||
| 564 | |||
| 487 | ret = ad7606_request_gpios(st); | 565 | ret = ad7606_request_gpios(st); |
| 488 | if (ret) | 566 | if (ret) |
| 489 | return ret; | 567 | return ret; |
| @@ -12,12 +12,17 @@ · 11 unmodified lines | |||
| 12 | * struct ad7606_chip_info - chip specific information | 12 | * struct ad7606_chip_info - chip specific information |
| 13 | * @channels: channel specification | 13 | * @channels: channel specification |
| 14 | * @num_channels: number of channels | 14 | * @num_channels: number of channels |
| 15 | * @has_oversampling: whether the device has oversampling support | 15 | * @oversampling_avail pointer to the array which stores the available |
| 16 | * oversampling ratios. | ||
| 17 | * @oversampling_num number of elements stored in oversampling_avail array | ||
| 18 | * @os_req_reset some devices require a reset to update oversampling | ||
| 16 | */ | 19 | */ |
| 17 | struct ad7606_chip_info { | 20 | struct ad7606_chip_info { |
| 18 | const struct iio_chan_spec *channels; | 21 | const struct iio_chan_spec *channels; |
| 19 | unsigned int num_channels; | 22 | unsigned int num_channels; |
| 20 | bool has_oversampling; | 23 | const unsigned int *oversampling_avail; |
| 24 | unsigned int oversampling_num; | ||
| 25 | bool os_req_reset; | ||
| 21 | }; | 26 | }; |
| 22 | 27 | ||
| 23 | /** | 28 | /** |
| @@ -29,6 +34,11 @@ struct ad7606_chip_info { · 5 unmodified lines | |||
| 29 | * @range voltage range selection, selects which scale to apply | 34 | * @range voltage range selection, selects which scale to apply |
| 30 | * @oversampling oversampling selection | 35 | * @oversampling oversampling selection |
| 31 | * @base_address address from where to read data in parallel operation | 36 | * @base_address address from where to read data in parallel operation |
| 37 | * @scale_avail pointer to the array which stores the available scales | ||
| 38 | * @num_scales number of elements stored in the scale_avail array | ||
| 39 | * @oversampling_avail pointer to the array which stores the available | ||
| 40 | * oversampling ratios. | ||
| 41 | * @num_os_ratios number of elements stored in oversampling_avail array | ||
| 32 | * @lock protect sensor state from concurrent accesses to GPIOs | 42 | * @lock protect sensor state from concurrent accesses to GPIOs |
| 33 | * @gpio_convst GPIO descriptor for conversion start signal (CONVST) | 43 | * @gpio_convst GPIO descriptor for conversion start signal (CONVST) |
| 34 | * @gpio_reset GPIO descriptor for device hard-reset | 44 | * @gpio_reset GPIO descriptor for device hard-reset |
| @@ -50,6 +60,10 @@ struct ad7606_state { · 15 unmodified lines | |||
| 50 | unsigned int range; | 60 | unsigned int range; |
| 51 | unsigned int oversampling; | 61 | unsigned int oversampling; |
| 52 | void __iomem *base_address; | 62 | void __iomem *base_address; |
| 63 | const unsigned int *scale_avail; | ||
| 64 | unsigned int num_scales; | ||
| 65 | const unsigned int *oversampling_avail; | ||
| 66 | unsigned int num_os_ratios; | ||
| 53 | 67 | ||
| 54 | struct mutex lock; /* protect sensor state */ | 68 | struct mutex lock; /* protect sensor state */ |
| 55 | struct gpio_desc *gpio_convst; | 69 | struct gpio_desc *gpio_convst; |
| @@ -64,9 +78,9 @@ struct ad7606_state { · 8 unmodified lines | |||
| 64 | /* | 78 | /* |
| 65 | * DMA (thus cache coherency maintenance) requires the | 79 | * DMA (thus cache coherency maintenance) requires the |
| 66 | * transfer buffers to live in their own cache lines. | 80 | * transfer buffers to live in their own cache lines. |
| 67 | * 8 * 16-bit samples + 64-bit timestamp | 81 | * 16 * 16-bit samples + 64-bit timestamp |
| 68 | */ | 82 | */ |
| 69 | unsigned short data[12] ____cacheline_aligned; | 83 | unsigned short data[20] ____cacheline_aligned; |
| 70 | }; | 84 | }; |
| 71 | 85 | ||
| 72 | /** | 86 | /** |
| @@ -86,7 +100,8 @@ enum ad7606_supported_device_ids { · 13 unmodified lines | |||
| 86 | ID_AD7605_4, | 100 | ID_AD7605_4, |
| 87 | ID_AD7606_8, | 101 | ID_AD7606_8, |
| 88 | ID_AD7606_6, | 102 | ID_AD7606_6, |
| 89 | ID_AD7606_4 | 103 | ID_AD7606_4, |
| 104 | ID_AD7616, | ||
| 90 | }; | 105 | }; |
| 91 | 106 | ||
| 92 | #ifdef CONFIG_PM_SLEEP | 107 | #ifdef CONFIG_PM_SLEEP |
| @@ -53,6 +53,7 @@ static const struct spi_device_id ad7606_id_table[] = { · 52 unmodified lines | |||
| 53 | { "ad7606-4", ID_AD7606_4 }, | 53 | { "ad7606-4", ID_AD7606_4 }, |
| 54 | { "ad7606-6", ID_AD7606_6 }, | 54 | { "ad7606-6", ID_AD7606_6 }, |
| 55 | { "ad7606-8", ID_AD7606_8 }, | 55 | { "ad7606-8", ID_AD7606_8 }, |
| 56 | { "ad7616", ID_AD7616 }, | ||
| 56 | {} | 57 | {} |
| 57 | }; | 58 | }; |
| 58 | MODULE_DEVICE_TABLE(spi, ad7606_id_table); | 59 | MODULE_DEVICE_TABLE(spi, ad7606_id_table); |
| @@ -62,6 +63,7 @@ static const struct of_device_id ad7606_of_match[] = { · 3 unmodified lines | |||
| 62 | { .compatible = "adi,ad7606-4" }, | 63 | { .compatible = "adi,ad7606-4" }, |
| 63 | { .compatible = "adi,ad7606-6" }, | 64 | { .compatible = "adi,ad7606-6" }, |
| 64 | { .compatible = "adi,ad7606-8" }, | 65 | { .compatible = "adi,ad7606-8" }, |
| 66 | { .compatible = "adi,ad7616" }, | ||
| 65 | { }, | 67 | { }, |
| 66 | }; | 68 | }; |
| 67 | MODULE_DEVICE_TABLE(of, ad7606_of_match); | 69 | MODULE_DEVICE_TABLE(of, ad7606_of_match); |
| @@ -388,8 +388,9 @@ static irqreturn_t imx7d_adc_isr(int irq, void *dev_id) · 387 unmodified lines | |||
| 388 | * timeout flags. | 388 | * timeout flags. |
| 389 | */ | 389 | */ |
| 390 | if (status & IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT) { | 390 | if (status & IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT) { |
| 391 | pr_err("%s: ADC got conversion time out interrupt: 0x%08x\n", | 391 | dev_err(info->dev, |
| 392 | dev_name(info->dev), status); | 392 | "ADC got conversion time out interrupt: 0x%08x\n", |
| 393 | status); | ||
| 393 | status &= ~IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT; | 394 | status &= ~IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT; |
| 394 | writel(status, info->regs + IMX7D_REG_ADC_INT_STATUS); | 395 | writel(status, info->regs + IMX7D_REG_ADC_INT_STATUS); |
| 395 | } | 396 | } |
| @@ -433,167 +434,139 @@ static void imx7d_adc_power_down(struct imx7d_adc *info) · 37 unmodified lines | |||
| 433 | writel(adc_cfg, info->regs + IMX7D_REG_ADC_ADC_CFG); | 434 | writel(adc_cfg, info->regs + IMX7D_REG_ADC_ADC_CFG); |
| 434 | } | 435 | } |
| 435 | 436 | ||
| 437 | static int imx7d_adc_enable(struct device *dev) | ||
| 438 | { | ||
| 439 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | ||
| 440 | struct imx7d_adc *info = iio_priv(indio_dev); | ||
| 441 | int ret; | ||
| 442 | |||
| 443 | ret = regulator_enable(info->vref); | ||
| 444 | if (ret) { | ||
| 445 | dev_err(info->dev, | ||
| 446 | "Can't enable adc reference top voltage, err = %d\n", | ||
| 447 | ret); | ||
| 448 | return ret; | ||
| 449 | } | ||
| 450 | |||
| 451 | ret = clk_prepare_enable(info->clk); | ||
| 452 | if (ret) { | ||
| 453 | dev_err(info->dev, | ||
| 454 | "Could not prepare or enable clock.\n"); | ||
| 455 | regulator_disable(info->vref); | ||
| 456 | return ret; | ||
| 457 | } | ||
| 458 | |||
| 459 | imx7d_adc_hw_init(info); | ||
| 460 | |||
| 461 | return 0; | ||
| 462 | } | ||
| 463 | |||
| 464 | static int imx7d_adc_disable(struct device *dev) | ||
| 465 | { | ||
| 466 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | ||
| 467 | struct imx7d_adc *info = iio_priv(indio_dev); | ||
| 468 | |||
| 469 | imx7d_adc_power_down(info); | ||
| 470 | |||
| 471 | clk_disable_unprepare(info->clk); | ||
| 472 | regulator_disable(info->vref); | ||
| 473 | |||
| 474 | return 0; | ||
| 475 | } | ||
| 476 | |||
| 477 | static void __imx7d_adc_disable(void *data) | ||
| 478 | { | ||
| 479 | imx7d_adc_disable(data); | ||
| 480 | } | ||
| 481 | |||
| 436 | static int imx7d_adc_probe(struct platform_device *pdev) | 482 | static int imx7d_adc_probe(struct platform_device *pdev) |
| 437 | { | 483 | { |
| 438 | struct imx7d_adc *info; | 484 | struct imx7d_adc *info; |
| 439 | struct iio_dev *indio_dev; | 485 | struct iio_dev *indio_dev; |
| 440 | struct resource *mem; | 486 | struct device *dev = &pdev->dev; |
| 441 | int irq; | 487 | int irq; |
| 442 | int ret; | 488 | int ret; |
| 443 | 489 | ||
| 444 | indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); | 490 | indio_dev = devm_iio_device_alloc(dev, sizeof(*info)); |
| 445 | if (!indio_dev) { | 491 | if (!indio_dev) { |
| 446 | dev_err(&pdev->dev, "Failed allocating iio device\n"); | 492 | dev_err(&pdev->dev, "Failed allocating iio device\n"); |
| 447 | return -ENOMEM; | 493 | return -ENOMEM; |
| 448 | } | 494 | } |
| 449 | 495 | ||
| 450 | info = iio_priv(indio_dev); | 496 | info = iio_priv(indio_dev); |
| 451 | info->dev = &pdev->dev; | 497 | info->dev = dev; |
| 452 | 498 | ||
| 453 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 499 | info->regs = devm_platform_ioremap_resource(pdev, 0); |
| 454 | info->regs = devm_ioremap_resource(&pdev->dev, mem); | ||
| 455 | if (IS_ERR(info->regs)) { | 500 | if (IS_ERR(info->regs)) { |
| 456 | ret = PTR_ERR(info->regs); | 501 | ret = PTR_ERR(info->regs); |
| 457 | dev_err(&pdev->dev, | 502 | dev_err(dev, "Failed to remap adc memory, err = %d\n", ret); |
| 458 | "Failed to remap adc memory, err = %d\n", ret); | ||
| 459 | return ret; | 503 | return ret; |
| 460 | } | 504 | } |
| 461 | 505 | ||
| 462 | irq = platform_get_irq(pdev, 0); | 506 | irq = platform_get_irq(pdev, 0); |
| 463 | if (irq < 0) { | 507 | if (irq < 0) { |
| 464 | dev_err(&pdev->dev, "No irq resource?\n"); | 508 | dev_err(dev, "No irq resource?\n"); |
| 465 | return irq; | 509 | return irq; |
| 466 | } | 510 | } |
| 467 | 511 | ||
| 468 | info->clk = devm_clk_get(&pdev->dev, "adc"); | 512 | info->clk = devm_clk_get(dev, "adc"); |
| 469 | if (IS_ERR(info->clk)) { | 513 | if (IS_ERR(info->clk)) { |
| 470 | ret = PTR_ERR(info->clk); | 514 | ret = PTR_ERR(info->clk); |
| 471 | dev_err(&pdev->dev, "Failed getting clock, err = %d\n", ret); | 515 | dev_err(dev, "Failed getting clock, err = %d\n", ret); |
| 472 | return ret; | 516 | return ret; |
| 473 | } | 517 | } |
| 474 | 518 | ||
| 475 | info->vref = devm_regulator_get(&pdev->dev, "vref"); | 519 | info->vref = devm_regulator_get(dev, "vref"); |
| 476 | if (IS_ERR(info->vref)) { | 520 | if (IS_ERR(info->vref)) { |
| 477 | ret = PTR_ERR(info->vref); | 521 | ret = PTR_ERR(info->vref); |
| 478 | dev_err(&pdev->dev, | 522 | dev_err(dev, |
| 479 | "Failed getting reference voltage, err = %d\n", ret); | 523 | "Failed getting reference voltage, err = %d\n", ret); |
| 480 | return ret; | 524 | return ret; |
| 481 | } | 525 | } |
| 482 | 526 | ||
| 483 | ret = regulator_enable(info->vref); | ||
| 484 | if (ret) { | ||
| 485 | dev_err(&pdev->dev, | ||
| 486 | "Can't enable adc reference top voltage, err = %d\n", | ||
| 487 | ret); | ||
| 488 | return ret; | ||
| 489 | } | ||
| 490 | |||
| 491 | platform_set_drvdata(pdev, indio_dev); | 527 | platform_set_drvdata(pdev, indio_dev); |
| 492 | 528 | ||
| 493 | init_completion(&info->completion); | 529 | init_completion(&info->completion); |
| 494 | 530 | ||
| 495 | indio_dev->name = dev_name(&pdev->dev); | 531 | indio_dev->name = dev_name(dev); |
| 496 | indio_dev->dev.parent = &pdev->dev; | 532 | indio_dev->dev.parent = dev; |
| 497 | indio_dev->info = &imx7d_adc_iio_info; | 533 | indio_dev->info = &imx7d_adc_iio_info; |
| 498 | indio_dev->modes = INDIO_DIRECT_MODE; | 534 | indio_dev->modes = INDIO_DIRECT_MODE; |
| 499 | indio_dev->channels = imx7d_adc_iio_channels; | 535 | indio_dev->channels = imx7d_adc_iio_channels; |
| 500 | indio_dev->num_channels = ARRAY_SIZE(imx7d_adc_iio_channels); | 536 | indio_dev->num_channels = ARRAY_SIZE(imx7d_adc_iio_channels); |
| 501 | 537 | ||
| 502 | ret = clk_prepare_enable(info->clk); | 538 | ret = devm_request_irq(dev, irq, |
| 503 | if (ret) { | 539 | imx7d_adc_isr, 0, |
| 504 | dev_err(&pdev->dev, | 540 | dev_name(dev), info); |
| 505 | "Could not prepare or enable the clock.\n"); | ||
| 506 | goto error_adc_clk_enable; | ||
| 507 | } | ||
| 508 | |||
| 509 | ret = devm_request_irq(info->dev, irq, | ||
| 510 | imx7d_adc_isr, 0, | ||
| 511 | dev_name(&pdev->dev), info); | ||
| 512 | if (ret < 0) { | 541 | if (ret < 0) { |
| 513 | dev_err(&pdev->dev, "Failed requesting irq, irq = %d\n", irq); | 542 | dev_err(dev, "Failed requesting irq, irq = %d\n", irq); |
| 514 | goto error_iio_device_register; | 543 | return ret; |
| 515 | } | 544 | } |
| 516 | 545 | ||
| 517 | imx7d_adc_feature_config(info); | 546 | imx7d_adc_feature_config(info); |
| 518 | imx7d_adc_hw_init(info); | ||
| 519 | |||
| 520 | ret = iio_device_register(indio_dev); | ||
| 521 | if (ret) { | ||
| 522 | imx7d_adc_power_down(info); | ||
| 523 | dev_err(&pdev->dev, "Couldn't register the device.\n"); | ||
| 524 | goto error_iio_device_register; | ||
| 525 | } | ||
| 526 | |||
| 527 | return 0; | ||
| 528 | |||
| 529 | error_iio_device_register: | ||
| 530 | clk_disable_unprepare(info->clk); | ||
| 531 | error_adc_clk_enable: | ||
| 532 | regulator_disable(info->vref); | ||
| 533 | |||
| 534 | return ret; | ||
| 535 | } | ||
| 536 | |||
| 537 | static int imx7d_adc_remove(struct platform_device *pdev) | ||
| 538 | { | ||
| 539 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); | ||
| 540 | struct imx7d_adc *info = iio_priv(indio_dev); | ||
| 541 | |||
| 542 | iio_device_unregister(indio_dev); | ||
| 543 | |||
| 544 | imx7d_adc_power_down(info); | ||
| 545 | |||
| 546 | clk_disable_unprepare(info->clk); | ||
| 547 | regulator_disable(info->vref); | ||
| 548 | |||
| 549 | return 0; | ||
| 550 | } | ||
| 551 | |||
| 552 | static int __maybe_unused imx7d_adc_suspend(struct device *dev) | ||
| 553 | { | ||
| 554 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | ||
| 555 | struct imx7d_adc *info = iio_priv(indio_dev); | ||
| 556 | |||
| 557 | imx7d_adc_power_down(info); | ||
| 558 | |||
| 559 | clk_disable_unprepare(info->clk); | ||
| 560 | regulator_disable(info->vref); | ||
| 561 | |||
| 562 | return 0; | ||
| 563 | } | ||
| 564 | 547 | ||
| 565 | static int __maybe_unused imx7d_adc_resume(struct device *dev) | 548 | ret = imx7d_adc_enable(&indio_dev->dev); |
| 566 | { | 549 | if (ret) |
| 567 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | 550 | return ret; |
| 568 | struct imx7d_adc *info = iio_priv(indio_dev); | ||
| 569 | int ret; | ||
| 570 | 551 | ||
| 571 | ret = regulator_enable(info->vref); | 552 | ret = devm_add_action_or_reset(dev, __imx7d_adc_disable, |
| 572 | if (ret) { | 553 | &indio_dev->dev); |
| 573 | dev_err(info->dev, | 554 | if (ret) |
| 574 | "Can't enable adc reference top voltage, err = %d\n", | ||
| 575 | ret); | ||
| 576 | return ret; | 555 | return ret; |
| 577 | } | ||
| 578 | 556 | ||
| 579 | ret = clk_prepare_enable(info->clk); | 557 | ret = devm_iio_device_register(dev, indio_dev); |
| 580 | if (ret) { | 558 | if (ret) { |
| 581 | dev_err(info->dev, | 559 | dev_err(&pdev->dev, "Couldn't register the device.\n"); |
| 582 | "Could not prepare or enable clock.\n"); | ||
| 583 | regulator_disable(info->vref); | ||
| 584 | return ret; | 560 | return ret; |
| 585 | } | 561 | } |
| 586 | 562 | ||
| 587 | imx7d_adc_hw_init(info); | ||
| 588 | |||
| 589 | return 0; | 563 | return 0; |
| 590 | } | 564 | } |
| 591 | 565 | ||
| 592 | static SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_suspend, imx7d_adc_resume); | 566 | static SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_disable, imx7d_adc_enable); |
| 593 | 567 | ||
| 594 | static struct platform_driver imx7d_adc_driver = { | 568 | static struct platform_driver imx7d_adc_driver = { |
| 595 | .probe = imx7d_adc_probe, | 569 | .probe = imx7d_adc_probe, |
| 596 | .remove = imx7d_adc_remove, | ||
| 597 | .driver = { | 570 | .driver = { |
| 598 | .name = "imx7d_adc", | 571 | .name = "imx7d_adc", |
| 599 | .of_match_table = imx7d_adc_match, | 572 | .of_match_table = imx7d_adc_match, |
| @@ -664,6 +664,7 @@ static const struct of_device_id adc5_match_table[] = { · 663 unmodified lines | |||
| 664 | }, | 664 | }, |
| 665 | { } | 665 | { } |
| 666 | }; | 666 | }; |
| 667 | MODULE_DEVICE_TABLE(of, adc5_match_table); | ||
| 667 | 668 | ||
| 668 | static int adc5_get_dt_data(struct adc5_chip *adc, struct device_node *node) | 669 | static int adc5_get_dt_data(struct adc5_chip *adc, struct device_node *node) |
| 669 | { | 670 | { |
| @@ -0,0 +1,204 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | /* | ||
| 3 | * ADS8344 16-bit 8-Channel ADC driver | ||
| 4 | * | ||
| 5 | * Author: Gregory CLEMENT <gregory.clement@bootlin.com> | ||
| 6 | * | ||
| 7 | * Datasheet: http://www.ti.com/lit/ds/symlink/ads8344.pdf | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include <linux/delay.h> | ||
| 11 | #include <linux/iio/buffer.h> | ||
| 12 | #include <linux/iio/iio.h> | ||
| 13 | #include <linux/module.h> | ||
| 14 | #include <linux/regulator/consumer.h> | ||
| 15 | #include <linux/spi/spi.h> | ||
| 16 | |||
| 17 | #define ADS8344_START BIT(7) | ||
| 18 | #define ADS8344_SINGLE_END BIT(2) | ||
| 19 | #define ADS8344_CHANNEL(channel) ((channel) << 4) | ||
| 20 | #define ADS8344_CLOCK_INTERNAL 0x2 /* PD1 = 1 and PD0 = 0 */ | ||
| 21 | |||
| 22 | struct ads8344 { | ||
| 23 | struct spi_device *spi; | ||
| 24 | struct regulator *reg; | ||
| 25 | /* | ||
| 26 | * Lock protecting access to adc->tx_buff and rx_buff, | ||
| 27 | * especially from concurrent read on sysfs file. | ||
| 28 | */ | ||
| 29 | struct mutex lock; | ||
| 30 | |||
| 31 | u8 tx_buf ____cacheline_aligned; | ||
| 32 | u16 rx_buf; | ||
| 33 | }; | ||
| 34 | |||
| 35 | #define ADS8344_VOLTAGE_CHANNEL(chan, si) \ | ||
| 36 | { \ | ||
| 37 | .type = IIO_VOLTAGE, \ | ||
| 38 | .indexed = 1, \ | ||
| 39 | .channel = chan, \ | ||
| 40 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
| 41 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ | ||
| 42 | } | ||
| 43 | |||
| 44 | #define ADS8344_VOLTAGE_CHANNEL_DIFF(chan1, chan2, si) \ | ||
| 45 | { \ | ||
| 46 | .type = IIO_VOLTAGE, \ | ||
| 47 | .indexed = 1, \ | ||
| 48 | .channel = (chan1), \ | ||
| 49 | .channel2 = (chan2), \ | ||
| 50 | .differential = 1, \ | ||
| 51 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
| 52 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ | ||
| 53 | } | ||
| 54 | |||
| 55 | static const struct iio_chan_spec ads8344_channels[] = { | ||
| 56 | ADS8344_VOLTAGE_CHANNEL(0, 0), | ||
| 57 | ADS8344_VOLTAGE_CHANNEL(1, 4), | ||
| 58 | ADS8344_VOLTAGE_CHANNEL(2, 1), | ||
| 59 | ADS8344_VOLTAGE_CHANNEL(3, 5), | ||
| 60 | ADS8344_VOLTAGE_CHANNEL(4, 2), | ||
| 61 | ADS8344_VOLTAGE_CHANNEL(5, 6), | ||
| 62 | ADS8344_VOLTAGE_CHANNEL(6, 3), | ||
| 63 | ADS8344_VOLTAGE_CHANNEL(7, 7), | ||
| 64 | ADS8344_VOLTAGE_CHANNEL_DIFF(0, 1, 8), | ||
| 65 | ADS8344_VOLTAGE_CHANNEL_DIFF(2, 3, 9), | ||
| 66 | ADS8344_VOLTAGE_CHANNEL_DIFF(4, 5, 10), | ||
| 67 | ADS8344_VOLTAGE_CHANNEL_DIFF(6, 7, 11), | ||
| 68 | ADS8344_VOLTAGE_CHANNEL_DIFF(1, 0, 12), | ||
| 69 | ADS8344_VOLTAGE_CHANNEL_DIFF(3, 2, 13), | ||
| 70 | ADS8344_VOLTAGE_CHANNEL_DIFF(5, 4, 14), | ||
| 71 | ADS8344_VOLTAGE_CHANNEL_DIFF(7, 6, 15), | ||
| 72 | }; | ||
| 73 | |||
| 74 | static int ads8344_adc_conversion(struct ads8344 *adc, int channel, | ||
| 75 | bool differential) | ||
| 76 | { | ||
| 77 | struct spi_device *spi = adc->spi; | ||
| 78 | int ret; | ||
| 79 | |||
| 80 | adc->tx_buf = ADS8344_START; | ||
| 81 | if (!differential) | ||
| 82 | adc->tx_buf |= ADS8344_SINGLE_END; | ||
| 83 | adc->tx_buf |= ADS8344_CHANNEL(channel); | ||
| 84 | adc->tx_buf |= ADS8344_CLOCK_INTERNAL; | ||
| 85 | |||
| 86 | ret = spi_write(spi, &adc->tx_buf, 1); | ||
| 87 | if (ret) | ||
| 88 | return ret; | ||
| 89 | |||
| 90 | udelay(9); | ||
| 91 | |||
| 92 | ret = spi_read(spi, &adc->rx_buf, 2); | ||
| 93 | if (ret) | ||
| 94 | return ret; | ||
| 95 | |||
| 96 | return adc->rx_buf; | ||
| 97 | } | ||
| 98 | |||
| 99 | static int ads8344_read_raw(struct iio_dev *iio, | ||
| 100 | struct iio_chan_spec const *channel, int *value, | ||
| 101 | int *shift, long mask) | ||
| 102 | { | ||
| 103 | struct ads8344 *adc = iio_priv(iio); | ||
| 104 | |||
| 105 | switch (mask) { | ||
| 106 | case IIO_CHAN_INFO_RAW: | ||
| 107 | mutex_lock(&adc->lock); | ||
| 108 | *value = ads8344_adc_conversion(adc, channel->scan_index, | ||
| 109 | channel->differential); | ||
| 110 | mutex_unlock(&adc->lock); | ||
| 111 | if (*value < 0) | ||
| 112 | return *value; | ||
| 113 | |||
| 114 | return IIO_VAL_INT; | ||
| 115 | case IIO_CHAN_INFO_SCALE: | ||
| 116 | *value = regulator_get_voltage(adc->reg); | ||
| 117 | if (*value < 0) | ||
| 118 | return *value; | ||
| 119 | |||
| 120 | /* convert regulator output voltage to mV */ | ||
| 121 | *value /= 1000; | ||
| 122 | *shift = 16; | ||
| 123 | |||
| 124 | return IIO_VAL_FRACTIONAL_LOG2; | ||
| 125 | default: | ||
| 126 | return -EINVAL; | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | static const struct iio_info ads8344_info = { | ||
| 131 | .read_raw = ads8344_read_raw, | ||
| 132 | }; | ||
| 133 | |||
| 134 | static int ads8344_probe(struct spi_device *spi) | ||
| 135 | { | ||
| 136 | struct iio_dev *indio_dev; | ||
| 137 | struct ads8344 *adc; | ||
| 138 | int ret; | ||
| 139 | |||
| 140 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); | ||
| 141 | if (!indio_dev) | ||
| 142 | return -ENOMEM; | ||
| 143 | |||
| 144 | adc = iio_priv(indio_dev); | ||
| 145 | adc->spi = spi; | ||
| 146 | mutex_init(&adc->lock); | ||
| 147 | |||
| 148 | indio_dev->name = dev_name(&spi->dev); | ||
| 149 | indio_dev->dev.parent = &spi->dev; | ||
| 150 | indio_dev->dev.of_node = spi->dev.of_node; | ||
| 151 | indio_dev->info = &ads8344_info; | ||
| 152 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
| 153 | indio_dev->channels = ads8344_channels; | ||
| 154 | indio_dev->num_channels = ARRAY_SIZE(ads8344_channels); | ||
| 155 | |||
| 156 | adc->reg = devm_regulator_get(&spi->dev, "vref"); | ||
| 157 | if (IS_ERR(adc->reg)) | ||
| 158 | return PTR_ERR(adc->reg); | ||
| 159 | |||
| 160 | ret = regulator_enable(adc->reg); | ||
| 161 | if (ret) | ||
| 162 | return ret; | ||
| 163 | |||
| 164 | spi_set_drvdata(spi, indio_dev); | ||
| 165 | |||
| 166 | ret = iio_device_register(indio_dev); | ||
| 167 | if (ret) { | ||
| 168 | regulator_disable(adc->reg); | ||
| 169 | return ret; | ||
| 170 | } | ||
| 171 | |||
| 172 | return 0; | ||
| 173 | } | ||
| 174 | |||
| 175 | static int ads8344_remove(struct spi_device *spi) | ||
| 176 | { | ||
| 177 | struct iio_dev *indio_dev = spi_get_drvdata(spi); | ||
| 178 | struct ads8344 *adc = iio_priv(indio_dev); | ||
| 179 | |||
| 180 | iio_device_unregister(indio_dev); | ||
| 181 | regulator_disable(adc->reg); | ||
| 182 | |||
| 183 | return 0; | ||
| 184 | } | ||
| 185 | |||
| 186 | static const struct of_device_id ads8344_of_match[] = { | ||
| 187 | { .compatible = "ti,ads8344", }, | ||
| 188 | {} | ||
| 189 | }; | ||
| 190 | MODULE_DEVICE_TABLE(of, ads8344_of_match); | ||
| 191 | |||
| 192 | static struct spi_driver ads8344_driver = { | ||
| 193 | .driver = { | ||
| 194 | .name = "ads8344", | ||
| 195 | .of_match_table = ads8344_of_match, | ||
| 196 | }, | ||
| 197 | .probe = ads8344_probe, | ||
| 198 | .remove = ads8344_remove, | ||
| 199 | }; | ||
| 200 | module_spi_driver(ads8344_driver); | ||
| 201 | |||
| 202 | MODULE_AUTHOR("Gregory CLEMENT <gregory.clement@bootlin.com>"); | ||
| 203 | MODULE_DESCRIPTION("ADS8344 driver"); | ||
| 204 | MODULE_LICENSE("GPL"); | ||
| @@ -72,8 +72,6 @@ · 71 unmodified lines | |||
| 72 | #define AD5758_DCDC_CONFIG1_DCDC_VPROG_MODE(x) (((x) & 0x1F) << 0) | 72 | #define AD5758_DCDC_CONFIG1_DCDC_VPROG_MODE(x) (((x) & 0x1F) << 0) |
| 73 | #define AD5758_DCDC_CONFIG1_DCDC_MODE_MSK GENMASK(6, 5) | 73 | #define AD5758_DCDC_CONFIG1_DCDC_MODE_MSK GENMASK(6, 5) |
| 74 | #define AD5758_DCDC_CONFIG1_DCDC_MODE_MODE(x) (((x) & 0x3) << 5) | 74 | #define AD5758_DCDC_CONFIG1_DCDC_MODE_MODE(x) (((x) & 0x3) << 5) |
| 75 | #define AD5758_DCDC_CONFIG1_PROT_SW_EN_MSK BIT(7) | ||
| 76 | #define AD5758_DCDC_CONFIG1_PROT_SW_EN_MODE(x) (((x) & 0x1) << 7) | ||
| 77 | 75 | ||
| 78 | /* AD5758_DCDC_CONFIG2 */ | 76 | /* AD5758_DCDC_CONFIG2 */ |
| 79 | #define AD5758_DCDC_CONFIG2_ILIMIT_MSK GENMASK(3, 1) | 77 | #define AD5758_DCDC_CONFIG2_ILIMIT_MSK GENMASK(3, 1) |
| @@ -84,6 +82,10 @@ · 4 unmodified lines | |||
| 84 | /* AD5758_DIGITAL_DIAG_RESULTS */ | 82 | /* AD5758_DIGITAL_DIAG_RESULTS */ |
| 85 | #define AD5758_CAL_MEM_UNREFRESHED_MSK BIT(15) | 83 | #define AD5758_CAL_MEM_UNREFRESHED_MSK BIT(15) |
| 86 | 84 | ||
| 85 | /* AD5758_ADC_CONFIG */ | ||
| 86 | #define AD5758_ADC_CONFIG_PPC_BUF_EN(x) (((x) & 0x1) << 11) | ||
| 87 | #define AD5758_ADC_CONFIG_PPC_BUF_MSK BIT(11) | ||
| 88 | |||
| 87 | #define AD5758_WR_FLAG_MSK(x) (0x80 | ((x) & 0x1F)) | 89 | #define AD5758_WR_FLAG_MSK(x) (0x80 | ((x) & 0x1F)) |
| 88 | 90 | ||
| 89 | #define AD5758_FULL_SCALE_MICRO 65535000000ULL | 91 | #define AD5758_FULL_SCALE_MICRO 65535000000ULL |
| @@ -315,6 +317,18 @@ static int ad5758_set_dc_dc_conv_mode(struct ad5758_state *st, · 225 unmodified lines | |||
| 315 | { | 317 | { |
| 316 | int ret; | 318 | int ret; |
| 317 | 319 | ||
| 320 | /* | ||
| 321 | * The ENABLE_PPC_BUFFERS bit must be set prior to enabling PPC current | ||
| 322 | * mode. | ||
| 323 | */ | ||
| 324 | if (mode == AD5758_DCDC_MODE_PPC_CURRENT) { | ||
| 325 | ret = ad5758_spi_write_mask(st, AD5758_ADC_CONFIG, | ||
| 326 | AD5758_ADC_CONFIG_PPC_BUF_MSK, | ||
| 327 | AD5758_ADC_CONFIG_PPC_BUF_EN(1)); | ||
| 328 | if (ret < 0) | ||
| 329 | return ret; | ||
| 330 | } | ||
| 331 | |||
| 318 | ret = ad5758_spi_write_mask(st, AD5758_DCDC_CONFIG1, | 332 | ret = ad5758_spi_write_mask(st, AD5758_DCDC_CONFIG1, |
| 319 | AD5758_DCDC_CONFIG1_DCDC_MODE_MSK, | 333 | AD5758_DCDC_CONFIG1_DCDC_MODE_MSK, |
| 320 | AD5758_DCDC_CONFIG1_DCDC_MODE_MODE(mode)); | 334 | AD5758_DCDC_CONFIG1_DCDC_MODE_MODE(mode)); |
| @@ -444,23 +458,6 @@ static int ad5758_set_out_range(struct ad5758_state *st, int range) · 123 unmodified lines | |||
| 444 | AD5758_CAL_MEM_UNREFRESHED_MSK); | 458 | AD5758_CAL_MEM_UNREFRESHED_MSK); |
| 445 | } | 459 | } |
| 446 | 460 | ||
| 447 | static int ad5758_fault_prot_switch_en(struct ad5758_state *st, bool enable) | ||
| 448 | { | ||
| 449 | int ret; | ||
| 450 | |||
| 451 | ret = ad5758_spi_write_mask(st, AD5758_DCDC_CONFIG1, | ||
| 452 | AD5758_DCDC_CONFIG1_PROT_SW_EN_MSK, | ||
| 453 | AD5758_DCDC_CONFIG1_PROT_SW_EN_MODE(enable)); | ||
| 454 | if (ret < 0) | ||
| 455 | return ret; | ||
| 456 | /* | ||
| 457 | * Poll the BUSY_3WI bit in the DCDC_CONFIG2 register until it is 0. | ||
| 458 | * This allows the 3-wire interface communication to complete. | ||
| 459 | */ | ||
| 460 | return ad5758_wait_for_task_complete(st, AD5758_DCDC_CONFIG2, | ||
| 461 | AD5758_DCDC_CONFIG2_BUSY_3WI_MSK); | ||
| 462 | } | ||
| 463 | |||
| 464 | static int ad5758_internal_buffers_en(struct ad5758_state *st, bool enable) | 461 | static int ad5758_internal_buffers_en(struct ad5758_state *st, bool enable) |
| 465 | { | 462 | { |
| 466 | int ret; | 463 | int ret; |
| @@ -585,8 +582,8 @@ static ssize_t ad5758_write_powerdown(struct iio_dev *indio_dev, · 118 unmodified lines | |||
| 585 | { | 582 | { |
| 586 | struct ad5758_state *st = iio_priv(indio_dev); | 583 | struct ad5758_state *st = iio_priv(indio_dev); |
| 587 | bool pwr_down; | 584 | bool pwr_down; |
| 588 | unsigned int dcdc_config1_mode, dc_dc_mode, dac_config_mode, val; | 585 | unsigned int dc_dc_mode, dac_config_mode, val; |
| 589 | unsigned long int dcdc_config1_msk, dac_config_msk; | 586 | unsigned long int dac_config_msk; |
| 590 | int ret; | 587 | int ret; |
| 591 | 588 | ||
| 592 | ret = kstrtobool(buf, &pwr_down); | 589 | ret = kstrtobool(buf, &pwr_down); |
| @@ -602,17 +599,6 @@ static ssize_t ad5758_write_powerdown(struct iio_dev *indio_dev, · 9 unmodified lines | |||
| 602 | val = 1; | 599 | val = 1; |
| 603 | } | 600 | } |
| 604 | 601 | ||
| 605 | dcdc_config1_mode = AD5758_DCDC_CONFIG1_DCDC_MODE_MODE(dc_dc_mode) | | ||
| 606 | AD5758_DCDC_CONFIG1_PROT_SW_EN_MODE(val); | ||
| 607 | dcdc_config1_msk = AD5758_DCDC_CONFIG1_DCDC_MODE_MSK | | ||
| 608 | AD5758_DCDC_CONFIG1_PROT_SW_EN_MSK; | ||
| 609 | |||
| 610 | ret = ad5758_spi_write_mask(st, AD5758_DCDC_CONFIG1, | ||
| 611 | dcdc_config1_msk, | ||
| 612 | dcdc_config1_mode); | ||
| 613 | if (ret < 0) | ||
| 614 | goto err_unlock; | ||
| 615 | |||
| 616 | dac_config_mode = AD5758_DAC_CONFIG_OUT_EN_MODE(val) | | 602 | dac_config_mode = AD5758_DAC_CONFIG_OUT_EN_MODE(val) | |
| 617 | AD5758_DAC_CONFIG_INT_EN_MODE(val); | 603 | AD5758_DAC_CONFIG_INT_EN_MODE(val); |
| 618 | dac_config_msk = AD5758_DAC_CONFIG_OUT_EN_MSK | | 604 | dac_config_msk = AD5758_DAC_CONFIG_OUT_EN_MSK | |
| @@ -841,11 +827,6 @@ static int ad5758_init(struct ad5758_state *st) · 222 unmodified lines | |||
| 841 | return ret; | 827 | return ret; |
| 842 | } | 828 | } |
| 843 | 829 | ||
| 844 | /* Enable the VIOUT fault protection switch (FPS is closed) */ | ||
| 845 | ret = ad5758_fault_prot_switch_en(st, 1); | ||
| 846 | if (ret < 0) | ||
| 847 | return ret; | ||
| 848 | |||
| 849 | /* Power up the DAC and internal (INT) amplifiers */ | 830 | /* Power up the DAC and internal (INT) amplifiers */ |
| 850 | ret = ad5758_internal_buffers_en(st, 1); | 831 | ret = ad5758_internal_buffers_en(st, 1); |
| 851 | if (ret < 0) | 832 | if (ret < 0) |
| @@ -196,7 +196,10 @@ static __init int iio_dummy_evgen_init(void) · 195 unmodified lines | |||
| 196 | return ret; | 196 | return ret; |
| 197 | device_initialize(&iio_evgen_dev); | 197 | device_initialize(&iio_evgen_dev); |
| 198 | dev_set_name(&iio_evgen_dev, "iio_evgen"); | 198 | dev_set_name(&iio_evgen_dev, "iio_evgen"); |
| 199 | return device_add(&iio_evgen_dev); | 199 | ret = device_add(&iio_evgen_dev); |
| 200 | if (ret) | ||
| 201 | put_device(&iio_evgen_dev); | ||
| 202 | return ret; | ||
| 200 | } | 203 | } |
| 201 | module_init(iio_dummy_evgen_init); | 204 | module_init(iio_dummy_evgen_init); |
| 202 | 205 | ||
| @@ -73,6 +73,28 @@ config BMG160_SPI · 72 unmodified lines | |||
| 73 | tristate | 73 | tristate |
| 74 | select REGMAP_SPI | 74 | select REGMAP_SPI |
| 75 | 75 | ||
| 76 | config FXAS21002C | ||
| 77 | tristate "NXP FXAS21002C Gyro Sensor" | ||
| 78 | select IIO_BUFFER | ||
| 79 | select IIO_TRIGGERED_BUFFER | ||
| 80 | select FXAS21002C_I2C if (I2C) | ||
| 81 | select FXAS21002C_SPI if (SPI) | ||
| 82 | depends on (I2C || SPI_MASTER) | ||
| 83 | help | ||
| 84 | Say yes here to build support for NXP FXAS21002C Tri-axis Gyro | ||
| 85 | Sensor driver connected via I2C or SPI. | ||
| 86 | |||
| 87 | This driver can also be built as a module. If so, the module | ||
| 88 | will be called fxas21002c_i2c or fxas21002c_spi. | ||
| 89 | |||
| 90 | config FXAS21002C_I2C | ||
| 91 | tristate | ||
| 92 | select REGMAP_I2C | ||
| 93 | |||
| 94 | config FXAS21002C_SPI | ||
| 95 | tristate | ||
| 96 | select REGMAP_SPI | ||
| 97 | |||
| 76 | config HID_SENSOR_GYRO_3D | 98 | config HID_SENSOR_GYRO_3D |
| 77 | depends on HID_SENSOR_HUB | 99 | depends on HID_SENSOR_HUB |
| 78 | select IIO_BUFFER | 100 | select IIO_BUFFER |
| @@ -12,6 +12,9 @@ obj-$(CONFIG_ADXRS450) += adxrs450.o · 11 unmodified lines | |||
| 12 | obj-$(CONFIG_BMG160) += bmg160_core.o | 12 | obj-$(CONFIG_BMG160) += bmg160_core.o |
| 13 | obj-$(CONFIG_BMG160_I2C) += bmg160_i2c.o | 13 | obj-$(CONFIG_BMG160_I2C) += bmg160_i2c.o |
| 14 | obj-$(CONFIG_BMG160_SPI) += bmg160_spi.o | 14 | obj-$(CONFIG_BMG160_SPI) += bmg160_spi.o |
| 15 | obj-$(CONFIG_FXAS21002C) += fxas21002c_core.o | ||
| 16 | obj-$(CONFIG_FXAS21002C_I2C) += fxas21002c_i2c.o | ||
| 17 | obj-$(CONFIG_FXAS21002C_SPI) += fxas21002c_spi.o | ||
| 15 | 18 | ||
| 16 | obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o | 19 | obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o |
| 17 | 20 | ||
| @@ -0,0 +1,150 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Driver for NXP FXAS21002C Gyroscope - Header | ||
| 4 | * | ||
| 5 | * Copyright (C) 2019 Linaro Ltd. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef FXAS21002C_H_ | ||
| 9 | #define FXAS21002C_H_ | ||
| 10 | |||
| 11 | #include <linux/regmap.h> | ||
| 12 | |||
| 13 | #define FXAS21002C_REG_STATUS 0x00 | ||
| 14 | #define FXAS21002C_REG_OUT_X_MSB 0x01 | ||
| 15 | #define FXAS21002C_REG_OUT_X_LSB 0x02 | ||
| 16 | #define FXAS21002C_REG_OUT_Y_MSB 0x03 | ||
| 17 | #define FXAS21002C_REG_OUT_Y_LSB 0x04 | ||
| 18 | #define FXAS21002C_REG_OUT_Z_MSB 0x05 | ||
| 19 | #define FXAS21002C_REG_OUT_Z_LSB 0x06 | ||
| 20 | #define FXAS21002C_REG_DR_STATUS 0x07 | ||
| 21 | #define FXAS21002C_REG_F_STATUS 0x08 | ||
| 22 | #define FXAS21002C_REG_F_SETUP 0x09 | ||
| 23 | #define FXAS21002C_REG_F_EVENT 0x0A | ||
| 24 | #define FXAS21002C_REG_INT_SRC_FLAG 0x0B | ||
| 25 | #define FXAS21002C_REG_WHO_AM_I 0x0C | ||
| 26 | #define FXAS21002C_REG_CTRL0 0x0D | ||
| 27 | #define FXAS21002C_REG_RT_CFG 0x0E | ||
| 28 | #define FXAS21002C_REG_RT_SRC 0x0F | ||
| 29 | #define FXAS21002C_REG_RT_THS 0x10 | ||
| 30 | #define FXAS21002C_REG_RT_COUNT 0x11 | ||
| 31 | #define FXAS21002C_REG_TEMP 0x12 | ||
| 32 | #define FXAS21002C_REG_CTRL1 0x13 | ||
| 33 | #define FXAS21002C_REG_CTRL2 0x14 | ||
| 34 | #define FXAS21002C_REG_CTRL3 0x15 | ||
| 35 | |||
| 36 | enum fxas21002c_fields { | ||
| 37 | F_DR_STATUS, | ||
| 38 | F_OUT_X_MSB, | ||
| 39 | F_OUT_X_LSB, | ||
| 40 | F_OUT_Y_MSB, | ||
| 41 | F_OUT_Y_LSB, | ||
| 42 | F_OUT_Z_MSB, | ||
| 43 | F_OUT_Z_LSB, | ||
| 44 | /* DR_STATUS */ | ||
| 45 | F_ZYX_OW, F_Z_OW, F_Y_OW, F_X_OW, F_ZYX_DR, F_Z_DR, F_Y_DR, F_X_DR, | ||
| 46 | /* F_STATUS */ | ||
| 47 | F_OVF, F_WMKF, F_CNT, | ||
| 48 | /* F_SETUP */ | ||
| 49 | F_MODE, F_WMRK, | ||
| 50 | /* F_EVENT */ | ||
| 51 | F_EVENT, FE_TIME, | ||
| 52 | /* INT_SOURCE_FLAG */ | ||
| 53 | F_BOOTEND, F_SRC_FIFO, F_SRC_RT, F_SRC_DRDY, | ||
| 54 | /* WHO_AM_I */ | ||
| 55 | F_WHO_AM_I, | ||
| 56 | /* CTRL_REG0 */ | ||
| 57 | F_BW, F_SPIW, F_SEL, F_HPF_EN, F_FS, | ||
| 58 | /* RT_CFG */ | ||
| 59 | F_ELE, F_ZTEFE, F_YTEFE, F_XTEFE, | ||
| 60 | /* RT_SRC */ | ||
| 61 | F_EA, F_ZRT, F_ZRT_POL, F_YRT, F_YRT_POL, F_XRT, F_XRT_POL, | ||
| 62 | /* RT_THS */ | ||
| 63 | F_DBCNTM, F_THS, | ||
| 64 | /* RT_COUNT */ | ||
| 65 | F_RT_COUNT, | ||
| 66 | /* TEMP */ | ||
| 67 | F_TEMP, | ||
| 68 | /* CTRL_REG1 */ | ||
| 69 | F_RST, F_ST, F_DR, F_ACTIVE, F_READY, | ||
| 70 | /* CTRL_REG2 */ | ||
| 71 | F_INT_CFG_FIFO, F_INT_EN_FIFO, F_INT_CFG_RT, F_INT_EN_RT, | ||
| 72 | F_INT_CFG_DRDY, F_INT_EN_DRDY, F_IPOL, F_PP_OD, | ||
| 73 | /* CTRL_REG3 */ | ||
| 74 | F_WRAPTOONE, F_EXTCTRLEN, F_FS_DOUBLE, | ||
| 75 | /* MAX FIELDS */ | ||
| 76 | F_MAX_FIELDS, | ||
| 77 | }; | ||
| 78 | |||
| 79 | static const struct reg_field fxas21002c_reg_fields[] = { | ||
| 80 | [F_DR_STATUS] = REG_FIELD(FXAS21002C_REG_STATUS, 0, 7), | ||
| 81 | [F_OUT_X_MSB] = REG_FIELD(FXAS21002C_REG_OUT_X_MSB, 0, 7), | ||
| 82 | [F_OUT_X_LSB] = REG_FIELD(FXAS21002C_REG_OUT_X_LSB, 0, 7), | ||
| 83 | [F_OUT_Y_MSB] = REG_FIELD(FXAS21002C_REG_OUT_Y_MSB, 0, 7), | ||
| 84 | [F_OUT_Y_LSB] = REG_FIELD(FXAS21002C_REG_OUT_Y_LSB, 0, 7), | ||
| 85 | [F_OUT_Z_MSB] = REG_FIELD(FXAS21002C_REG_OUT_Z_MSB, 0, 7), | ||
| 86 | [F_OUT_Z_LSB] = REG_FIELD(FXAS21002C_REG_OUT_Z_LSB, 0, 7), | ||
| 87 | [F_ZYX_OW] = REG_FIELD(FXAS21002C_REG_DR_STATUS, 7, 7), | ||
| 88 | [F_Z_OW] = REG_FIELD(FXAS21002C_REG_DR_STATUS, 6, 6), | ||
| 89 | [F_Y_OW] = REG_FIELD(FXAS21002C_REG_DR_STATUS, 5, 5), | ||
| 90 | [F_X_OW] = REG_FIELD(FXAS21002C_REG_DR_STATUS, 4, 4), | ||
| 91 | [F_ZYX_DR] = REG_FIELD(FXAS21002C_REG_DR_STATUS, 3, 3), | ||
| 92 | [F_Z_DR] = REG_FIELD(FXAS21002C_REG_DR_STATUS, 2, 2), | ||
| 93 | [F_Y_DR] = REG_FIELD(FXAS21002C_REG_DR_STATUS, 1, 1), | ||
| 94 | [F_X_DR] = REG_FIELD(FXAS21002C_REG_DR_STATUS, 0, 0), | ||
| 95 | [F_OVF] = REG_FIELD(FXAS21002C_REG_F_STATUS, 7, 7), | ||
| 96 | [F_WMKF] = REG_FIELD(FXAS21002C_REG_F_STATUS, 6, 6), | ||
| 97 | [F_CNT] = REG_FIELD(FXAS21002C_REG_F_STATUS, 0, 5), | ||
| 98 | [F_MODE] = REG_FIELD(FXAS21002C_REG_F_SETUP, 6, 7), | ||
| 99 | [F_WMRK] = REG_FIELD(FXAS21002C_REG_F_SETUP, 0, 5), | ||
| 100 | [F_EVENT] = REG_FIELD(FXAS21002C_REG_F_EVENT, 5, 5), | ||
| 101 | [FE_TIME] = REG_FIELD(FXAS21002C_REG_F_EVENT, 0, 4), | ||
| 102 | [F_BOOTEND] = REG_FIELD(FXAS21002C_REG_INT_SRC_FLAG, 3, 3), | ||
| 103 | [F_SRC_FIFO] = REG_FIELD(FXAS21002C_REG_INT_SRC_FLAG, 2, 2), | ||
| 104 | [F_SRC_RT] = REG_FIELD(FXAS21002C_REG_INT_SRC_FLAG, 1, 1), | ||
| 105 | [F_SRC_DRDY] = REG_FIELD(FXAS21002C_REG_INT_SRC_FLAG, 0, 0), | ||
| 106 | [F_WHO_AM_I] = REG_FIELD(FXAS21002C_REG_WHO_AM_I, 0, 7), | ||
| 107 | [F_BW] = REG_FIELD(FXAS21002C_REG_CTRL0, 6, 7), | ||
| 108 | [F_SPIW] = REG_FIELD(FXAS21002C_REG_CTRL0, 5, 5), | ||
| 109 | [F_SEL] = REG_FIELD(FXAS21002C_REG_CTRL0, 3, 4), | ||
| 110 | [F_HPF_EN] = REG_FIELD(FXAS21002C_REG_CTRL0, 2, 2), | ||
| 111 | [F_FS] = REG_FIELD(FXAS21002C_REG_CTRL0, 0, 1), | ||
| 112 | [F_ELE] = REG_FIELD(FXAS21002C_REG_RT_CFG, 3, 3), | ||
| 113 | [F_ZTEFE] = REG_FIELD(FXAS21002C_REG_RT_CFG, 2, 2), | ||
| 114 | [F_YTEFE] = REG_FIELD(FXAS21002C_REG_RT_CFG, 1, 1), | ||
| 115 | [F_XTEFE] = REG_FIELD(FXAS21002C_REG_RT_CFG, 0, 0), | ||
| 116 | [F_EA] = REG_FIELD(FXAS21002C_REG_RT_SRC, 6, 6), | ||
| 117 | [F_ZRT] = REG_FIELD(FXAS21002C_REG_RT_SRC, 5, 5), | ||
| 118 | [F_ZRT_POL] = REG_FIELD(FXAS21002C_REG_RT_SRC, 4, 4), | ||
| 119 | [F_YRT] = REG_FIELD(FXAS21002C_REG_RT_SRC, 3, 3), | ||
| 120 | [F_YRT_POL] = REG_FIELD(FXAS21002C_REG_RT_SRC, 2, 2), | ||
| 121 | [F_XRT] = REG_FIELD(FXAS21002C_REG_RT_SRC, 1, 1), | ||
| 122 | [F_XRT_POL] = REG_FIELD(FXAS21002C_REG_RT_SRC, 0, 0), | ||
| 123 | [F_DBCNTM] = REG_FIELD(FXAS21002C_REG_RT_THS, 7, 7), | ||
| 124 | [F_THS] = REG_FIELD(FXAS21002C_REG_RT_SRC, 0, 6), | ||
| 125 | [F_RT_COUNT] = REG_FIELD(FXAS21002C_REG_RT_COUNT, 0, 7), | ||
| 126 | [F_TEMP] = REG_FIELD(FXAS21002C_REG_TEMP, 0, 7), | ||
| 127 | [F_RST] = REG_FIELD(FXAS21002C_REG_CTRL1, 6, 6), | ||
| 128 | [F_ST] = REG_FIELD(FXAS21002C_REG_CTRL1, 5, 5), | ||
| 129 | [F_DR] = REG_FIELD(FXAS21002C_REG_CTRL1, 2, 4), | ||
| 130 | [F_ACTIVE] = REG_FIELD(FXAS21002C_REG_CTRL1, 1, 1), | ||
| 131 | [F_READY] = REG_FIELD(FXAS21002C_REG_CTRL1, 0, 0), | ||
| 132 | [F_INT_CFG_FIFO] = REG_FIELD(FXAS21002C_REG_CTRL2, 7, 7), | ||
| 133 | [F_INT_EN_FIFO] = REG_FIELD(FXAS21002C_REG_CTRL2, 6, 6), | ||
| 134 | [F_INT_CFG_RT] = REG_FIELD(FXAS21002C_REG_CTRL2, 5, 5), | ||
| 135 | [F_INT_EN_RT] = REG_FIELD(FXAS21002C_REG_CTRL2, 4, 4), | ||
| 136 | [F_INT_CFG_DRDY] = REG_FIELD(FXAS21002C_REG_CTRL2, 3, 3), | ||
| 137 | [F_INT_EN_DRDY] = REG_FIELD(FXAS21002C_REG_CTRL2, 2, 2), | ||
| 138 | [F_IPOL] = REG_FIELD(FXAS21002C_REG_CTRL2, 1, 1), | ||
| 139 | [F_PP_OD] = REG_FIELD(FXAS21002C_REG_CTRL2, 0, 0), | ||
| 140 | [F_WRAPTOONE] = REG_FIELD(FXAS21002C_REG_CTRL3, 3, 3), | ||
| 141 | [F_EXTCTRLEN] = REG_FIELD(FXAS21002C_REG_CTRL3, 2, 2), | ||
| 142 | [F_FS_DOUBLE] = REG_FIELD(FXAS21002C_REG_CTRL3, 0, 0), | ||
| 143 | }; | ||
| 144 | |||
| 145 | extern const struct dev_pm_ops fxas21002c_pm_ops; | ||
| 146 | |||
| 147 | int fxas21002c_core_probe(struct device *dev, struct regmap *regmap, int irq, | ||
| 148 | const char *name); | ||
| 149 | void fxas21002c_core_remove(struct device *dev); | ||
| 150 | #endif | ||
| @@ -0,0 +1,1004 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Driver for NXP FXAS21002C Gyroscope - Core | ||
| 4 | * | ||
| 5 | * Copyright (C) 2019 Linaro Ltd. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <linux/interrupt.h> | ||
| 9 | #include <linux/module.h> | ||
| 10 | #include <linux/of_irq.h> | ||
| 11 | #include <linux/pm.h> | ||
| 12 | #include <linux/pm_runtime.h> | ||
| 13 | #include <linux/regmap.h> | ||
| 14 | #include <linux/regulator/consumer.h> | ||
| 15 | |||
| 16 | #include <linux/iio/events.h> | ||
| 17 | #include <linux/iio/iio.h> | ||
| 18 | #include <linux/iio/buffer.h> | ||
| 19 | #include <linux/iio/sysfs.h> | ||
| 20 | #include <linux/iio/trigger.h> | ||
| 21 | #include <linux/iio/trigger_consumer.h> | ||
| 22 | #include <linux/iio/triggered_buffer.h> | ||
| 23 | |||
| 24 | #include "fxas21002c.h" | ||
| 25 | |||
| 26 | #define FXAS21002C_CHIP_ID_1 0xD6 | ||
| 27 | #define FXAS21002C_CHIP_ID_2 0xD7 | ||
| 28 | |||
| 29 | enum fxas21002c_mode_state { | ||
| 30 | FXAS21002C_MODE_STANDBY, | ||
| 31 | FXAS21002C_MODE_READY, | ||
| 32 | FXAS21002C_MODE_ACTIVE, | ||
| 33 | }; | ||
| 34 | |||
| 35 | #define FXAS21002C_STANDBY_ACTIVE_TIME_MS 62 | ||
| 36 | #define FXAS21002C_READY_ACTIVE_TIME_MS 7 | ||
| 37 | |||
| 38 | #define FXAS21002C_ODR_LIST_MAX 10 | ||
| 39 | |||
| 40 | #define FXAS21002C_SCALE_FRACTIONAL 32 | ||
| 41 | #define FXAS21002C_RANGE_LIMIT_DOUBLE 2000 | ||
| 42 | |||
| 43 | #define FXAS21002C_AXIS_TO_REG(axis) (FXAS21002C_REG_OUT_X_MSB + ((axis) * 2)) | ||
| 44 | |||
| 45 | static const int fxas21002c_odr_values[] = { | ||
| 46 | 800, 400, 200, 100, 50, 25, 12, 12 | ||
| 47 | }; | ||
| 48 | |||
| 49 | /* | ||
| 50 | * These values are taken from the low-pass filter cutoff frequency calculated | ||
| 51 | * ODR * 0.lpf_values. So, for ODR = 800Hz with a lpf value = 0.32 | ||
| 52 | * => LPF cutoff frequency = 800 * 0.32 = 256 Hz | ||
| 53 | */ | ||
| 54 | static const int fxas21002c_lpf_values[] = { | ||
| 55 | 32, 16, 8 | ||
| 56 | }; | ||
| 57 | |||
| 58 | /* | ||
| 59 | * These values are taken from the high-pass filter cutoff frequency calculated | ||
| 60 | * ODR * 0.0hpf_values. So, for ODR = 800Hz with a hpf value = 0.018750 | ||
| 61 | * => HPF cutoff frequency = 800 * 0.018750 = 15 Hz | ||
| 62 | */ | ||
| 63 | static const int fxas21002c_hpf_values[] = { | ||
| 64 | 18750, 9625, 4875, 2475 | ||
| 65 | }; | ||
| 66 | |||
| 67 | static const int fxas21002c_range_values[] = { | ||
| 68 | 4000, 2000, 1000, 500, 250 | ||
| 69 | }; | ||
| 70 | |||
| 71 | struct fxas21002c_data { | ||
| 72 | u8 chip_id; | ||
| 73 | enum fxas21002c_mode_state mode; | ||
| 74 | enum fxas21002c_mode_state prev_mode; | ||
| 75 | |||
| 76 | struct mutex lock; /* serialize data access */ | ||
| 77 | struct regmap *regmap; | ||
| 78 | struct regmap_field *regmap_fields[F_MAX_FIELDS]; | ||
| 79 | struct iio_trigger *dready_trig; | ||
| 80 | s64 timestamp; | ||
| 81 | int irq; | ||
| 82 | |||
| 83 | struct regulator *vdd; | ||
| 84 | struct regulator *vddio; | ||
| 85 | |||
| 86 | /* | ||
| 87 | * DMA (thus cache coherency maintenance) requires the | ||
| 88 | * transfer buffers to live in their own cache lines. | ||
| 89 | */ | ||
| 90 | s16 buffer[8] ____cacheline_aligned; | ||
| 91 | }; | ||
| 92 | |||
| 93 | enum fxas21002c_channel_index { | ||
| 94 | CHANNEL_SCAN_INDEX_X, | ||
| 95 | CHANNEL_SCAN_INDEX_Y, | ||
| 96 | CHANNEL_SCAN_INDEX_Z, | ||
| 97 | CHANNEL_SCAN_MAX, | ||
| 98 | }; | ||
| 99 | |||
| 100 | static int fxas21002c_odr_hz_from_value(struct fxas21002c_data *data, u8 value) | ||
| 101 | { | ||
| 102 | int odr_value_max = ARRAY_SIZE(fxas21002c_odr_values) - 1; | ||
| 103 | |||
| 104 | value = min_t(u8, value, odr_value_max); | ||
| 105 | |||
| 106 | return fxas21002c_odr_values[value]; | ||
| 107 | } | ||
| 108 | |||
| 109 | static int fxas21002c_odr_value_from_hz(struct fxas21002c_data *data, | ||
| 110 | unsigned int hz) | ||
| 111 | { | ||
| 112 | int odr_table_size = ARRAY_SIZE(fxas21002c_odr_values); | ||
| 113 | int i; | ||
| 114 | |||
| 115 | for (i = 0; i < odr_table_size; i++) | ||
| 116 | if (fxas21002c_odr_values[i] == hz) | ||
| 117 | return i; | ||
| 118 | |||
| 119 | return -EINVAL; | ||
| 120 | } | ||
| 121 | |||
| 122 | static int fxas21002c_lpf_bw_from_value(struct fxas21002c_data *data, u8 value) | ||
| 123 | { | ||
| 124 | int lpf_value_max = ARRAY_SIZE(fxas21002c_lpf_values) - 1; | ||
| 125 | |||
| 126 | value = min_t(u8, value, lpf_value_max); | ||
| 127 | |||
| 128 | return fxas21002c_lpf_values[value]; | ||
| 129 | } | ||
| 130 | |||
| 131 | static int fxas21002c_lpf_value_from_bw(struct fxas21002c_data *data, | ||
| 132 | unsigned int hz) | ||
| 133 | { | ||
| 134 | int lpf_table_size = ARRAY_SIZE(fxas21002c_lpf_values); | ||
| 135 | int i; | ||
| 136 | |||
| 137 | for (i = 0; i < lpf_table_size; i++) | ||
| 138 | if (fxas21002c_lpf_values[i] == hz) | ||
| 139 | return i; | ||
| 140 | |||
| 141 | return -EINVAL; | ||
| 142 | } | ||
| 143 | |||
| 144 | static int fxas21002c_hpf_sel_from_value(struct fxas21002c_data *data, u8 value) | ||
| 145 | { | ||
| 146 | int hpf_value_max = ARRAY_SIZE(fxas21002c_hpf_values) - 1; | ||
| 147 | |||
| 148 | value = min_t(u8, value, hpf_value_max); | ||
| 149 | |||
| 150 | return fxas21002c_hpf_values[value]; | ||
| 151 | } | ||
| 152 | |||
| 153 | static int fxas21002c_hpf_value_from_sel(struct fxas21002c_data *data, | ||
| 154 | unsigned int hz) | ||
| 155 | { | ||
| 156 | int hpf_table_size = ARRAY_SIZE(fxas21002c_hpf_values); | ||
| 157 | int i; | ||
| 158 | |||
| 159 | for (i = 0; i < hpf_table_size; i++) | ||
| 160 | if (fxas21002c_hpf_values[i] == hz) | ||
| 161 | return i; | ||
| 162 | |||
| 163 | return -EINVAL; | ||
| 164 | } | ||
| 165 | |||
| 166 | static int fxas21002c_range_fs_from_value(struct fxas21002c_data *data, | ||
| 167 | u8 value) | ||
| 168 | { | ||
| 169 | int range_value_max = ARRAY_SIZE(fxas21002c_range_values) - 1; | ||
| 170 | unsigned int fs_double; | ||
| 171 | int ret; | ||
| 172 | |||
| 173 | /* We need to check if FS_DOUBLE is enabled to offset the value */ | ||
| 174 | ret = regmap_field_read(data->regmap_fields[F_FS_DOUBLE], &fs_double); | ||
| 175 | if (ret < 0) | ||
| 176 | return ret; | ||
| 177 | |||
| 178 | if (!fs_double) | ||
| 179 | value += 1; | ||
| 180 | |||
| 181 | value = min_t(u8, value, range_value_max); | ||
| 182 | |||
| 183 | return fxas21002c_range_values[value]; | ||
| 184 | } | ||
| 185 | |||
| 186 | static int fxas21002c_range_value_from_fs(struct fxas21002c_data *data, | ||
| 187 | unsigned int range) | ||
| 188 | { | ||
| 189 | int range_table_size = ARRAY_SIZE(fxas21002c_range_values); | ||
| 190 | bool found = false; | ||
| 191 | int fs_double = 0; | ||
| 192 | int ret; | ||
| 193 | int i; | ||
| 194 | |||
| 195 | for (i = 0; i < range_table_size; i++) | ||
| 196 | if (fxas21002c_range_values[i] == range) { | ||
| 197 | found = true; | ||
| 198 | break; | ||
| 199 | } | ||
| 200 | |||
| 201 | if (!found) | ||
| 202 | return -EINVAL; | ||
| 203 | |||
| 204 | if (range > FXAS21002C_RANGE_LIMIT_DOUBLE) | ||
| 205 | fs_double = 1; | ||
| 206 | |||
| 207 | ret = regmap_field_write(data->regmap_fields[F_FS_DOUBLE], fs_double); | ||
| 208 | if (ret < 0) | ||
| 209 | return ret; | ||
| 210 | |||
| 211 | return i; | ||
| 212 | } | ||
| 213 | |||
| 214 | static int fxas21002c_mode_get(struct fxas21002c_data *data) | ||
| 215 | { | ||
| 216 | unsigned int active; | ||
| 217 | unsigned int ready; | ||
| 218 | int ret; | ||
| 219 | |||
| 220 | ret = regmap_field_read(data->regmap_fields[F_ACTIVE], &active); | ||
| 221 | if (ret < 0) | ||
| 222 | return ret; | ||
| 223 | if (active) | ||
| 224 | return FXAS21002C_MODE_ACTIVE; | ||
| 225 | |||
| 226 | ret = regmap_field_read(data->regmap_fields[F_READY], &ready); | ||
| 227 | if (ret < 0) | ||
| 228 | return ret; | ||
| 229 | if (ready) | ||
| 230 | return FXAS21002C_MODE_READY; | ||
| 231 | |||
| 232 | return FXAS21002C_MODE_STANDBY; | ||
| 233 | } | ||
| 234 | |||
| 235 | static int fxas21002c_mode_set(struct fxas21002c_data *data, | ||
| 236 | enum fxas21002c_mode_state mode) | ||
| 237 | { | ||
| 238 | int ret; | ||
| 239 | |||
| 240 | if (mode == data->mode) | ||
| 241 | return 0; | ||
| 242 | |||
| 243 | if (mode == FXAS21002C_MODE_READY) | ||
| 244 | ret = regmap_field_write(data->regmap_fields[F_READY], 1); | ||
| 245 | else | ||
| 246 | ret = regmap_field_write(data->regmap_fields[F_READY], 0); | ||
| 247 | if (ret < 0) | ||
| 248 | return ret; | ||
| 249 | |||
| 250 | if (mode == FXAS21002C_MODE_ACTIVE) | ||
| 251 | ret = regmap_field_write(data->regmap_fields[F_ACTIVE], 1); | ||
| 252 | else | ||
| 253 | ret = regmap_field_write(data->regmap_fields[F_ACTIVE], 0); | ||
| 254 | if (ret < 0) | ||
| 255 | return ret; | ||
| 256 | |||
| 257 | /* if going to active wait the setup times */ | ||
| 258 | if (mode == FXAS21002C_MODE_ACTIVE && | ||
| 259 | data->mode == FXAS21002C_MODE_STANDBY) | ||
| 260 | msleep_interruptible(FXAS21002C_STANDBY_ACTIVE_TIME_MS); | ||
| 261 | |||
| 262 | if (data->mode == FXAS21002C_MODE_READY) | ||
| 263 | msleep_interruptible(FXAS21002C_READY_ACTIVE_TIME_MS); | ||
| 264 | |||
| 265 | data->prev_mode = data->mode; | ||
| 266 | data->mode = mode; | ||
| 267 | |||
| 268 | return ret; | ||
| 269 | } | ||
| 270 | |||
| 271 | static int fxas21002c_write(struct fxas21002c_data *data, | ||
| 272 | enum fxas21002c_fields field, int bits) | ||
| 273 | { | ||
| 274 | int actual_mode; | ||
| 275 | int ret; | ||
| 276 | |||
| 277 | mutex_lock(&data->lock); | ||
| 278 | |||
| 279 | actual_mode = fxas21002c_mode_get(data); | ||
| 280 | if (actual_mode < 0) { | ||
| 281 | ret = actual_mode; | ||
| 282 | goto out_unlock; | ||
| 283 | } | ||
| 284 | |||
| 285 | ret = fxas21002c_mode_set(data, FXAS21002C_MODE_READY); | ||
| 286 | if (ret < 0) | ||
| 287 | goto out_unlock; | ||
| 288 | |||
| 289 | ret = regmap_field_write(data->regmap_fields[field], bits); | ||
| 290 | if (ret < 0) | ||
| 291 | goto out_unlock; | ||
| 292 | |||
| 293 | ret = fxas21002c_mode_set(data, data->prev_mode); | ||
| 294 | |||
| 295 | out_unlock: | ||
| 296 | mutex_unlock(&data->lock); | ||
| 297 | |||
| 298 | return ret; | ||
| 299 | } | ||
| 300 | |||
| 301 | static int fxas21002c_pm_get(struct fxas21002c_data *data) | ||
| 302 | { | ||
| 303 | struct device *dev = regmap_get_device(data->regmap); | ||
| 304 | int ret; | ||
| 305 | |||
| 306 | ret = pm_runtime_get_sync(dev); | ||
| 307 | if (ret < 0) | ||
| 308 | pm_runtime_put_noidle(dev); | ||
| 309 | |||
| 310 | return ret; | ||
| 311 | } | ||
| 312 | |||
| 313 | static int fxas21002c_pm_put(struct fxas21002c_data *data) | ||
| 314 | { | ||
| 315 | struct device *dev = regmap_get_device(data->regmap); | ||
| 316 | |||
| 317 | pm_runtime_mark_last_busy(dev); | ||
| 318 | |||
| 319 | return pm_runtime_put_autosuspend(dev); | ||
| 320 | } | ||
| 321 | |||
| 322 | static int fxas21002c_temp_get(struct fxas21002c_data *data, int *val) | ||
| 323 | { | ||
| 324 | struct device *dev = regmap_get_device(data->regmap); | ||
| 325 | unsigned int temp; | ||
| 326 | int ret; | ||
| 327 | |||
| 328 | mutex_lock(&data->lock); | ||
| 329 | ret = fxas21002c_pm_get(data); | ||
| 330 | if (ret < 0) | ||
| 331 | goto data_unlock; | ||
| 332 | |||
| 333 | ret = regmap_field_read(data->regmap_fields[F_TEMP], &temp); | ||
| 334 | if (ret < 0) { | ||
| 335 | dev_err(dev, "failed to read temp: %d\n", ret); | ||
| 336 | goto data_unlock; | ||
| 337 | } | ||
| 338 | |||
| 339 | *val = sign_extend32(temp, 7); | ||
| 340 | |||
| 341 | ret = fxas21002c_pm_put(data); | ||
| 342 | if (ret < 0) | ||
| 343 | goto data_unlock; | ||
| 344 | |||
| 345 | ret = IIO_VAL_INT; | ||
| 346 | |||
| 347 | data_unlock: | ||
| 348 | mutex_unlock(&data->lock); | ||
| 349 | |||
| 350 | return ret; | ||
| 351 | } | ||
| 352 | |||
| 353 | static int fxas21002c_axis_get(struct fxas21002c_data *data, | ||
| 354 | int index, int *val) | ||
| 355 | { | ||
| 356 | struct device *dev = regmap_get_device(data->regmap); | ||
| 357 | __be16 axis_be; | ||
| 358 | int ret; | ||
| 359 | |||
| 360 | mutex_lock(&data->lock); | ||
| 361 | ret = fxas21002c_pm_get(data); | ||
| 362 | if (ret < 0) | ||
| 363 | goto data_unlock; | ||
| 364 | |||
| 365 | ret = regmap_bulk_read(data->regmap, FXAS21002C_AXIS_TO_REG(index), | ||
| 366 | &axis_be, sizeof(axis_be)); | ||
| 367 | if (ret < 0) { | ||
| 368 | dev_err(dev, "failed to read axis: %d: %d\n", index, ret); | ||
| 369 | goto data_unlock; | ||
| 370 | } | ||
| 371 | |||
| 372 | *val = sign_extend32(be16_to_cpu(axis_be), 15); | ||
| 373 | |||
| 374 | ret = fxas21002c_pm_put(data); | ||
| 375 | if (ret < 0) | ||
| 376 | goto data_unlock; | ||
| 377 | |||
| 378 | ret = IIO_VAL_INT; | ||
| 379 | |||
| 380 | data_unlock: | ||
| 381 | mutex_unlock(&data->lock); | ||
| 382 | |||
| 383 | return ret; | ||
| 384 | } | ||
| 385 | |||
| 386 | static int fxas21002c_odr_get(struct fxas21002c_data *data, int *odr) | ||
| 387 | { | ||
| 388 | unsigned int odr_bits; | ||
| 389 | int ret; | ||
| 390 | |||
| 391 | mutex_lock(&data->lock); | ||
| 392 | ret = regmap_field_read(data->regmap_fields[F_DR], &odr_bits); | ||
| 393 | if (ret < 0) | ||
| 394 | goto data_unlock; | ||
| 395 | |||
| 396 | *odr = fxas21002c_odr_hz_from_value(data, odr_bits); | ||
| 397 | |||
| 398 | ret = IIO_VAL_INT; | ||
| 399 | |||
| 400 | data_unlock: | ||
| 401 | mutex_unlock(&data->lock); | ||
| 402 | |||
| 403 | return ret; | ||
| 404 | } | ||
| 405 | |||
| 406 | static int fxas21002c_odr_set(struct fxas21002c_data *data, int odr) | ||
| 407 | { | ||
| 408 | int odr_bits; | ||
| 409 | |||
| 410 | odr_bits = fxas21002c_odr_value_from_hz(data, odr); | ||
| 411 | if (odr_bits < 0) | ||
| 412 | return odr_bits; | ||
| 413 | |||
| 414 | return fxas21002c_write(data, F_DR, odr_bits); | ||
| 415 | } | ||
| 416 | |||
| 417 | static int fxas21002c_lpf_get(struct fxas21002c_data *data, int *val2) | ||
| 418 | { | ||
| 419 | unsigned int bw_bits; | ||
| 420 | int ret; | ||
| 421 | |||
| 422 | mutex_lock(&data->lock); | ||
| 423 | ret = regmap_field_read(data->regmap_fields[F_BW], &bw_bits); | ||
| 424 | if (ret < 0) | ||
| 425 | goto data_unlock; | ||
| 426 | |||
| 427 | *val2 = fxas21002c_lpf_bw_from_value(data, bw_bits) * 10000; | ||
| 428 | |||
| 429 | ret = IIO_VAL_INT_PLUS_MICRO; | ||
| 430 | |||
| 431 | data_unlock: | ||
| 432 | mutex_unlock(&data->lock); | ||
| 433 | |||
| 434 | return ret; | ||
| 435 | } | ||
| 436 | |||
| 437 | static int fxas21002c_lpf_set(struct fxas21002c_data *data, int bw) | ||
| 438 | { | ||
| 439 | int bw_bits; | ||
| 440 | int odr; | ||
| 441 | int ret; | ||
| 442 | |||
| 443 | bw_bits = fxas21002c_lpf_value_from_bw(data, bw); | ||
| 444 | if (bw_bits < 0) | ||
| 445 | return bw_bits; | ||
| 446 | |||
| 447 | /* | ||
| 448 | * From table 33 of the device spec, for ODR = 25Hz and 12.5 value 0.08 | ||
| 449 | * is not allowed and for ODR = 12.5 value 0.16 is also not allowed | ||
| 450 | */ | ||
| 451 | ret = fxas21002c_odr_get(data, &odr); | ||
| 452 | if (ret < 0) | ||
| 453 | return -EINVAL; | ||
| 454 | |||
| 455 | if ((odr == 25 && bw_bits > 0x01) || (odr == 12 && bw_bits > 0)) | ||
| 456 | return -EINVAL; | ||
| 457 | |||
| 458 | return fxas21002c_write(data, F_BW, bw_bits); | ||
| 459 | } | ||
| 460 | |||
| 461 | static int fxas21002c_hpf_get(struct fxas21002c_data *data, int *val2) | ||
| 462 | { | ||
| 463 | unsigned int sel_bits; | ||
| 464 | int ret; | ||
| 465 | |||
| 466 | mutex_lock(&data->lock); | ||
| 467 | ret = regmap_field_read(data->regmap_fields[F_SEL], &sel_bits); | ||
| 468 | if (ret < 0) | ||
| 469 | goto data_unlock; | ||
| 470 | |||
| 471 | *val2 = fxas21002c_hpf_sel_from_value(data, sel_bits); | ||
| 472 | |||
| 473 | ret = IIO_VAL_INT_PLUS_MICRO; | ||
| 474 | |||
| 475 | data_unlock: | ||
| 476 | mutex_unlock(&data->lock); | ||
| 477 | |||
| 478 | return ret; | ||
| 479 | } | ||
| 480 | |||
| 481 | static int fxas21002c_hpf_set(struct fxas21002c_data *data, int sel) | ||
| 482 | { | ||
| 483 | int sel_bits; | ||
| 484 | |||
| 485 | sel_bits = fxas21002c_hpf_value_from_sel(data, sel); | ||
| 486 | if (sel_bits < 0) | ||
| 487 | return sel_bits; | ||
| 488 | |||
| 489 | return fxas21002c_write(data, F_SEL, sel_bits); | ||
| 490 | } | ||
| 491 | |||
| 492 | static int fxas21002c_scale_get(struct fxas21002c_data *data, int *val) | ||
| 493 | { | ||
| 494 | int fs_bits; | ||
| 495 | int scale; | ||
| 496 | int ret; | ||
| 497 | |||
| 498 | mutex_lock(&data->lock); | ||
| 499 | ret = regmap_field_read(data->regmap_fields[F_FS], &fs_bits); | ||
| 500 | if (ret < 0) | ||
| 501 | goto data_unlock; | ||
| 502 | |||
| 503 | scale = fxas21002c_range_fs_from_value(data, fs_bits); | ||
| 504 | if (scale < 0) { | ||
| 505 | ret = scale; | ||
| 506 | goto data_unlock; | ||
| 507 | } | ||
| 508 | |||
| 509 | *val = scale; | ||
| 510 | |||
| 511 | data_unlock: | ||
| 512 | mutex_unlock(&data->lock); | ||
| 513 | |||
| 514 | return ret; | ||
| 515 | } | ||
| 516 | |||
| 517 | static int fxas21002c_scale_set(struct fxas21002c_data *data, int range) | ||
| 518 | { | ||
| 519 | int fs_bits; | ||
| 520 | |||
| 521 | fs_bits = fxas21002c_range_value_from_fs(data, range); | ||
| 522 | if (fs_bits < 0) | ||
| 523 | return fs_bits; | ||
| 524 | |||
| 525 | return fxas21002c_write(data, F_FS, fs_bits); | ||
| 526 | } | ||
| 527 | |||
| 528 | static int fxas21002c_read_raw(struct iio_dev *indio_dev, | ||
| 529 | struct iio_chan_spec const *chan, int *val, | ||
| 530 | int *val2, long mask) | ||
| 531 | { | ||
| 532 | struct fxas21002c_data *data = iio_priv(indio_dev); | ||
| 533 | int ret; | ||
| 534 | |||
| 535 | switch (mask) { | ||
| 536 | case IIO_CHAN_INFO_RAW: | ||
| 537 | switch (chan->type) { | ||
| 538 | case IIO_TEMP: | ||
| 539 | return fxas21002c_temp_get(data, val); | ||
| 540 | case IIO_ANGL_VEL: | ||
| 541 | return fxas21002c_axis_get(data, chan->scan_index, val); | ||
| 542 | default: | ||
| 543 | return -EINVAL; | ||
| 544 | } | ||
| 545 | case IIO_CHAN_INFO_SCALE: | ||
| 546 | switch (chan->type) { | ||
| 547 | case IIO_ANGL_VEL: | ||
| 548 | *val2 = FXAS21002C_SCALE_FRACTIONAL; | ||
| 549 | ret = fxas21002c_scale_get(data, val); | ||
| 550 | if (ret < 0) | ||
| 551 | return ret; | ||
| 552 | |||
| 553 | return IIO_VAL_FRACTIONAL; | ||
| 554 | default: | ||
| 555 | return -EINVAL; | ||
| 556 | } | ||
| 557 | case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: | ||
| 558 | *val = 0; | ||
| 559 | return fxas21002c_lpf_get(data, val2); | ||
| 560 | case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: | ||
| 561 | *val = 0; | ||
| 562 | return fxas21002c_hpf_get(data, val2); | ||
| 563 | case IIO_CHAN_INFO_SAMP_FREQ: | ||
| 564 | *val2 = 0; | ||
| 565 | return fxas21002c_odr_get(data, val); | ||
| 566 | default: | ||
| 567 | return -EINVAL; | ||
| 568 | } | ||
| 569 | } | ||
| 570 | |||
| 571 | static int fxas21002c_write_raw(struct iio_dev *indio_dev, | ||
| 572 | struct iio_chan_spec const *chan, int val, | ||
| 573 | int val2, long mask) | ||
| 574 | { | ||
| 575 | struct fxas21002c_data *data = iio_priv(indio_dev); | ||
| 576 | int range; | ||
| 577 | |||
| 578 | switch (mask) { | ||
| 579 | case IIO_CHAN_INFO_SAMP_FREQ: | ||
| 580 | if (val2) | ||
| 581 | return -EINVAL; | ||
| 582 | |||
| 583 | return fxas21002c_odr_set(data, val); | ||
| 584 | case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: | ||
| 585 | if (val) | ||
| 586 | return -EINVAL; | ||
| 587 | |||
| 588 | val2 = val2 / 10000; | ||
| 589 | return fxas21002c_lpf_set(data, val2); | ||
| 590 | case IIO_CHAN_INFO_SCALE: | ||
| 591 | switch (chan->type) { | ||
| 592 | case IIO_ANGL_VEL: | ||
| 593 | range = (((val * 1000 + val2 / 1000) * | ||
| 594 | FXAS21002C_SCALE_FRACTIONAL) / 1000); | ||
| 595 | return fxas21002c_scale_set(data, range); | ||
| 596 | default: | ||
| 597 | return -EINVAL; | ||
| 598 | } | ||
| 599 | case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: | ||
| 600 | return fxas21002c_hpf_set(data, val2); | ||
| 601 | default: | ||
| 602 | return -EINVAL; | ||
| 603 | } | ||
| 604 | } | ||
| 605 | |||
| 606 | static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("12.5 25 50 100 200 400 800"); | ||
| 607 | |||
| 608 | static IIO_CONST_ATTR(in_anglvel_filter_low_pass_3db_frequency_available, | ||
| 609 | "0.32 0.16 0.08"); | ||
| 610 | |||
| 611 | static IIO_CONST_ATTR(in_anglvel_filter_high_pass_3db_frequency_available, | ||
| 612 | "0.018750 0.009625 0.004875 0.002475"); | ||
| 613 | |||
| 614 | static IIO_CONST_ATTR(in_anglvel_scale_available, | ||
| 615 | "125.0 62.5 31.25 15.625 7.8125"); | ||
| 616 | |||
| 617 | static struct attribute *fxas21002c_attributes[] = { | ||
| 618 | &iio_const_attr_sampling_frequency_available.dev_attr.attr, | ||
| 619 | &iio_const_attr_in_anglvel_filter_low_pass_3db_frequency_available.dev_attr.attr, | ||
| 620 | &iio_const_attr_in_anglvel_filter_high_pass_3db_frequency_available.dev_attr.attr, | ||
| 621 | &iio_const_attr_in_anglvel_scale_available.dev_attr.attr, | ||
| 622 | NULL, | ||
| 623 | }; | ||
| 624 | |||
| 625 | static const struct attribute_group fxas21002c_attrs_group = { | ||
| 626 | .attrs = fxas21002c_attributes, | ||
| 627 | }; | ||
| 628 | |||
| 629 | #define FXAS21002C_CHANNEL(_axis) { \ | ||
| 630 | .type = IIO_ANGL_VEL, \ | ||
| 631 | .modified = 1, \ | ||
| 632 | .channel2 = IIO_MOD_##_axis, \ | ||
| 633 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
| 634 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ | ||
| 635 | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | \ | ||
| 636 | BIT(IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY) | \ | ||
| 637 | BIT(IIO_CHAN_INFO_SAMP_FREQ), \ | ||
| 638 | .scan_index = CHANNEL_SCAN_INDEX_##_axis, \ | ||
| 639 | .scan_type = { \ | ||
| 640 | .sign = 's', \ | ||
| 641 | .realbits = 16, \ | ||
| 642 | .storagebits = 16, \ | ||
| 643 | .endianness = IIO_BE, \ | ||
| 644 | }, \ | ||
| 645 | } | ||
| 646 | |||
| 647 | static const struct iio_chan_spec fxas21002c_channels[] = { | ||
| 648 | { | ||
| 649 | .type = IIO_TEMP, | ||
| 650 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), | ||
| 651 | .scan_index = -1, | ||
| 652 | }, | ||
| 653 | FXAS21002C_CHANNEL(X), | ||
| 654 | FXAS21002C_CHANNEL(Y), | ||
| 655 | FXAS21002C_CHANNEL(Z), | ||
| 656 | }; | ||
| 657 | |||
| 658 | static const struct iio_info fxas21002c_info = { | ||
| 659 | .attrs = &fxas21002c_attrs_group, | ||
| 660 | .read_raw = &fxas21002c_read_raw, | ||
| 661 | .write_raw = &fxas21002c_write_raw, | ||
| 662 | }; | ||
| 663 | |||
| 664 | static irqreturn_t fxas21002c_trigger_handler(int irq, void *p) | ||
| 665 | { | ||
| 666 | struct iio_poll_func *pf = p; | ||
| 667 | struct iio_dev *indio_dev = pf->indio_dev; | ||
| 668 | struct fxas21002c_data *data = iio_priv(indio_dev); | ||
| 669 | int ret; | ||
| 670 | |||
| 671 | mutex_lock(&data->lock); | ||
| 672 | ret = regmap_bulk_read(data->regmap, FXAS21002C_REG_OUT_X_MSB, | ||
| 673 | data->buffer, CHANNEL_SCAN_MAX * sizeof(s16)); | ||
| 674 | if (ret < 0) | ||
| 675 | goto out_unlock; | ||
| 676 | |||
| 677 | iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, | ||
| 678 | data->timestamp); | ||
| 679 | |||
| 680 | out_unlock: | ||
| 681 | mutex_unlock(&data->lock); | ||
| 682 | |||
| 683 | iio_trigger_notify_done(indio_dev->trig); | ||
| 684 | |||
| 685 | return IRQ_HANDLED; | ||
| 686 | } | ||
| 687 | |||
| 688 | static int fxas21002c_chip_init(struct fxas21002c_data *data) | ||
| 689 | { | ||
| 690 | struct device *dev = regmap_get_device(data->regmap); | ||
| 691 | unsigned int chip_id; | ||
| 692 | int ret; | ||
| 693 | |||
| 694 | ret = regmap_field_read(data->regmap_fields[F_WHO_AM_I], &chip_id); | ||
| 695 | if (ret < 0) | ||
| 696 | return ret; | ||
| 697 | |||
| 698 | if (chip_id != FXAS21002C_CHIP_ID_1 && | ||
| 699 | chip_id != FXAS21002C_CHIP_ID_2) { | ||
| 700 | dev_err(dev, "chip id 0x%02x is not supported\n", chip_id); | ||
| 701 | return -EINVAL; | ||
| 702 | } | ||
| 703 | |||
| 704 | data->chip_id = chip_id; | ||
| 705 | |||
| 706 | ret = fxas21002c_mode_set(data, FXAS21002C_MODE_STANDBY); | ||
| 707 | if (ret < 0) | ||
| 708 | return ret; | ||
| 709 | |||
| 710 | /* Set ODR to 200HZ as default */ | ||
| 711 | ret = fxas21002c_odr_set(data, 200); | ||
| 712 | if (ret < 0) | ||
| 713 | dev_err(dev, "failed to set ODR: %d\n", ret); | ||
| 714 | |||
| 715 | return ret; | ||
| 716 | } | ||
| 717 | |||
| 718 | static int fxas21002c_data_rdy_trigger_set_state(struct iio_trigger *trig, | ||
| 719 | bool state) | ||
| 720 | { | ||
| 721 | struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); | ||
| 722 | struct fxas21002c_data *data = iio_priv(indio_dev); | ||
| 723 | |||
| 724 | return regmap_field_write(data->regmap_fields[F_INT_EN_DRDY], state); | ||
| 725 | } | ||
| 726 | |||
| 727 | static const struct iio_trigger_ops fxas21002c_trigger_ops = { | ||
| 728 | .set_trigger_state = &fxas21002c_data_rdy_trigger_set_state, | ||
| 729 | }; | ||
| 730 | |||
| 731 | static irqreturn_t fxas21002c_data_rdy_handler(int irq, void *private) | ||
| 732 | { | ||
| 733 | struct iio_dev *indio_dev = private; | ||
| 734 | struct fxas21002c_data *data = iio_priv(indio_dev); | ||
| 735 | |||
| 736 | data->timestamp = iio_get_time_ns(indio_dev); | ||
| 737 | |||
| 738 | return IRQ_WAKE_THREAD; | ||
| 739 | } | ||
| 740 | |||
| 741 | static irqreturn_t fxas21002c_data_rdy_thread(int irq, void *private) | ||
| 742 | { | ||
| 743 | struct iio_dev *indio_dev = private; | ||
| 744 | struct fxas21002c_data *data = iio_priv(indio_dev); | ||
| 745 | unsigned int data_ready; | ||
| 746 | int ret; | ||
| 747 | |||
| 748 | ret = regmap_field_read(data->regmap_fields[F_SRC_DRDY], &data_ready); | ||
| 749 | if (ret < 0) | ||
| 750 | return IRQ_NONE; | ||
| 751 | |||
| 752 | if (!data_ready) | ||
| 753 | return IRQ_NONE; | ||
| 754 | |||
| 755 | iio_trigger_poll_chained(data->dready_trig); | ||
| 756 | |||
| 757 | return IRQ_HANDLED; | ||
| 758 | } | ||
| 759 | |||
| 760 | static int fxas21002c_trigger_probe(struct fxas21002c_data *data) | ||
| 761 | { | ||
| 762 | struct device *dev = regmap_get_device(data->regmap); | ||
| 763 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | ||
| 764 | struct device_node *np = indio_dev->dev.of_node; | ||
| 765 | unsigned long irq_trig; | ||
| 766 | bool irq_open_drain; | ||
| 767 | int irq1; | ||
| 768 | int ret; | ||
| 769 | |||
| 770 | if (!data->irq) | ||
| 771 | return 0; | ||
| 772 | |||
| 773 | irq1 = of_irq_get_byname(np, "INT1"); | ||
| 774 | |||
| 775 | if (irq1 == data->irq) { | ||
| 776 | dev_info(dev, "using interrupt line INT1\n"); | ||
| 777 | ret = regmap_field_write(data->regmap_fields[F_INT_CFG_DRDY], | ||
| 778 | 1); | ||
| 779 | if (ret < 0) | ||
| 780 | return ret; | ||
| 781 | } | ||
| 782 | |||
| 783 | dev_info(dev, "using interrupt line INT2\n"); | ||
| 784 | |||
| 785 | irq_open_drain = of_property_read_bool(np, "drive-open-drain"); | ||
| 786 | |||
| 787 | data->dready_trig = devm_iio_trigger_alloc(dev, "%s-dev%d", | ||
| 788 | indio_dev->name, | ||
| 789 | indio_dev->id); | ||
| 790 | if (!data->dready_trig) | ||
| 791 | return -ENOMEM; | ||
| 792 | |||
| 793 | irq_trig = irqd_get_trigger_type(irq_get_irq_data(data->irq)); | ||
| 794 | |||
| 795 | if (irq_trig == IRQF_TRIGGER_RISING) { | ||
| 796 | ret = regmap_field_write(data->regmap_fields[F_IPOL], 1); | ||
| 797 | if (ret < 0) | ||
| 798 | return ret; | ||
| 799 | } | ||
| 800 | |||
| 801 | if (irq_open_drain) | ||
| 802 | irq_trig |= IRQF_SHARED; | ||
| 803 | |||
| 804 | ret = devm_request_threaded_irq(dev, data->irq, | ||
| 805 | fxas21002c_data_rdy_handler, | ||
| 806 | fxas21002c_data_rdy_thread, | ||
| 807 | irq_trig, "fxas21002c_data_ready", | ||
| 808 | indio_dev); | ||
| 809 | if (ret < 0) | ||
| 810 | return ret; | ||
| 811 | |||
| 812 | data->dready_trig->dev.parent = dev; | ||
| 813 | data->dready_trig->ops = &fxas21002c_trigger_ops; | ||
| 814 | iio_trigger_set_drvdata(data->dready_trig, indio_dev); | ||
| 815 | |||
| 816 | return devm_iio_trigger_register(dev, data->dready_trig); | ||
| 817 | } | ||
| 818 | |||
| 819 | static int fxas21002c_power_enable(struct fxas21002c_data *data) | ||
| 820 | { | ||
| 821 | int ret; | ||
| 822 | |||
| 823 | ret = regulator_enable(data->vdd); | ||
| 824 | if (ret < 0) | ||
| 825 | return ret; | ||
| 826 | |||
| 827 | ret = regulator_enable(data->vddio); | ||
| 828 | if (ret < 0) { | ||
| 829 | regulator_disable(data->vdd); | ||
| 830 | return ret; | ||
| 831 | } | ||
| 832 | |||
| 833 | return 0; | ||
| 834 | } | ||
| 835 | |||
| 836 | static void fxas21002c_power_disable(struct fxas21002c_data *data) | ||
| 837 | { | ||
| 838 | regulator_disable(data->vdd); | ||
| 839 | regulator_disable(data->vddio); | ||
| 840 | } | ||
| 841 | |||
| 842 | static void fxas21002c_power_disable_action(void *_data) | ||
| 843 | { | ||
| 844 | struct fxas21002c_data *data = _data; | ||
| 845 | |||
| 846 | fxas21002c_power_disable(data); | ||
| 847 | } | ||
| 848 | |||
| 849 | static int fxas21002c_regulators_get(struct fxas21002c_data *data) | ||
| 850 | { | ||
| 851 | struct device *dev = regmap_get_device(data->regmap); | ||
| 852 | |||
| 853 | data->vdd = devm_regulator_get(dev->parent, "vdd"); | ||
| 854 | if (IS_ERR(data->vdd)) | ||
| 855 | return PTR_ERR(data->vdd); | ||
| 856 | |||
| 857 | data->vddio = devm_regulator_get(dev->parent, "vddio"); | ||
| 858 | |||
| 859 | return PTR_ERR_OR_ZERO(data->vddio); | ||
| 860 | } | ||
| 861 | |||
| 862 | int fxas21002c_core_probe(struct device *dev, struct regmap *regmap, int irq, | ||
| 863 | const char *name) | ||
| 864 | { | ||
| 865 | struct fxas21002c_data *data; | ||
| 866 | struct iio_dev *indio_dev; | ||
| 867 | struct regmap_field *f; | ||
| 868 | int i; | ||
| 869 | int ret; | ||
| 870 | |||
| 871 | indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); | ||
| 872 | if (!indio_dev) | ||
| 873 | return -ENOMEM; | ||
| 874 | |||
| 875 | data = iio_priv(indio_dev); | ||
| 876 | dev_set_drvdata(dev, indio_dev); | ||
| 877 | data->irq = irq; | ||
| 878 | data->regmap = regmap; | ||
| 879 | |||
| 880 | for (i = 0; i < F_MAX_FIELDS; i++) { | ||
| 881 | f = devm_regmap_field_alloc(dev, data->regmap, | ||
| 882 | fxas21002c_reg_fields[i]); | ||
| 883 | if (IS_ERR(f)) | ||
| 884 | return PTR_ERR(f); | ||
| 885 | |||
| 886 | data->regmap_fields[i] = f; | ||
| 887 | } | ||
| 888 | |||
| 889 | mutex_init(&data->lock); | ||
| 890 | |||
| 891 | ret = fxas21002c_regulators_get(data); | ||
| 892 | if (ret < 0) | ||
| 893 | return ret; | ||
| 894 | |||
| 895 | ret = fxas21002c_power_enable(data); | ||
| 896 | if (ret < 0) | ||
| 897 | return ret; | ||
| 898 | |||
| 899 | ret = devm_add_action_or_reset(dev, fxas21002c_power_disable_action, | ||
| 900 | data); | ||
| 901 | if (ret < 0) | ||
| 902 | return ret; | ||
| 903 | |||
| 904 | ret = fxas21002c_chip_init(data); | ||
| 905 | if (ret < 0) | ||
| 906 | return ret; | ||
| 907 | |||
| 908 | indio_dev->dev.parent = dev; | ||
| 909 | indio_dev->channels = fxas21002c_channels; | ||
| 910 | indio_dev->num_channels = ARRAY_SIZE(fxas21002c_channels); | ||
| 911 | indio_dev->name = name; | ||
| 912 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
| 913 | indio_dev->info = &fxas21002c_info; | ||
| 914 | |||
| 915 | ret = fxas21002c_trigger_probe(data); | ||
| 916 | if (ret < 0) | ||
| 917 | return ret; | ||
| 918 | |||
| 919 | ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, | ||
| 920 | fxas21002c_trigger_handler, NULL); | ||
| 921 | if (ret < 0) | ||
| 922 | return ret; | ||
| 923 | |||
| 924 | ret = pm_runtime_set_active(dev); | ||
| 925 | if (ret) | ||
| 926 | return ret; | ||
| 927 | |||
| 928 | pm_runtime_enable(dev); | ||
| 929 | pm_runtime_set_autosuspend_delay(dev, 2000); | ||
| 930 | pm_runtime_use_autosuspend(dev); | ||
| 931 | |||
| 932 | ret = iio_device_register(indio_dev); | ||
| 933 | if (ret < 0) | ||
| 934 | goto pm_disable; | ||
| 935 | |||
| 936 | return 0; | ||
| 937 | |||
| 938 | pm_disable: | ||
| 939 | pm_runtime_disable(dev); | ||
| 940 | pm_runtime_set_suspended(dev); | ||
| 941 | pm_runtime_put_noidle(dev); | ||
| 942 | |||
| 943 | return ret; | ||
| 944 | } | ||
| 945 | EXPORT_SYMBOL_GPL(fxas21002c_core_probe); | ||
| 946 | |||
| 947 | void fxas21002c_core_remove(struct device *dev) | ||
| 948 | { | ||
| 949 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | ||
| 950 | |||
| 951 | iio_device_unregister(indio_dev); | ||
| 952 | |||
| 953 | pm_runtime_disable(dev); | ||
| 954 | pm_runtime_set_suspended(dev); | ||
| 955 | pm_runtime_put_noidle(dev); | ||
| 956 | } | ||
| 957 | EXPORT_SYMBOL_GPL(fxas21002c_core_remove); | ||
| 958 | |||
| 959 | static int __maybe_unused fxas21002c_suspend(struct device *dev) | ||
| 960 | { | ||
| 961 | struct fxas21002c_data *data = iio_priv(dev_get_drvdata(dev)); | ||
| 962 | |||
| 963 | fxas21002c_mode_set(data, FXAS21002C_MODE_STANDBY); | ||
| 964 | fxas21002c_power_disable(data); | ||
| 965 | |||
| 966 | return 0; | ||
| 967 | } | ||
| 968 | |||
| 969 | static int __maybe_unused fxas21002c_resume(struct device *dev) | ||
| 970 | { | ||
| 971 | struct fxas21002c_data *data = iio_priv(dev_get_drvdata(dev)); | ||
| 972 | int ret; | ||
| 973 | |||
| 974 | ret = fxas21002c_power_enable(data); | ||
| 975 | if (ret < 0) | ||
| 976 | return ret; | ||
| 977 | |||
| 978 | return fxas21002c_mode_set(data, data->prev_mode); | ||
| 979 | } | ||
| 980 | |||
| 981 | static int __maybe_unused fxas21002c_runtime_suspend(struct device *dev) | ||
| 982 | { | ||
| 983 | struct fxas21002c_data *data = iio_priv(dev_get_drvdata(dev)); | ||
| 984 | |||
| 985 | return fxas21002c_mode_set(data, FXAS21002C_MODE_READY); | ||
| 986 | } | ||
| 987 | |||
| 988 | static int __maybe_unused fxas21002c_runtime_resume(struct device *dev) | ||
| 989 | { | ||
| 990 | struct fxas21002c_data *data = iio_priv(dev_get_drvdata(dev)); | ||
| 991 | |||
| 992 | return fxas21002c_mode_set(data, FXAS21002C_MODE_ACTIVE); | ||
| 993 | } | ||
| 994 | |||
| 995 | const struct dev_pm_ops fxas21002c_pm_ops = { | ||
| 996 | SET_SYSTEM_SLEEP_PM_OPS(fxas21002c_suspend, fxas21002c_resume) | ||
| 997 | SET_RUNTIME_PM_OPS(fxas21002c_runtime_suspend, | ||
| 998 | fxas21002c_runtime_resume, NULL) | ||
| 999 | }; | ||
| 1000 | EXPORT_SYMBOL_GPL(fxas21002c_pm_ops); | ||
| 1001 | |||
| 1002 | MODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>"); | ||
| 1003 | MODULE_LICENSE("GPL v2"); | ||
| 1004 | MODULE_DESCRIPTION("FXAS21002C Gyro driver"); | ||
| @@ -0,0 +1,69 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Driver for NXP FXAS21002C Gyroscope - I2C | ||
| 4 | * | ||
| 5 | * Copyright (C) 2018 Linaro Ltd. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <linux/err.h> | ||
| 9 | #include <linux/i2c.h> | ||
| 10 | #include <linux/mod_devicetable.h> | ||
| 11 | #include <linux/module.h> | ||
| 12 | #include <linux/regmap.h> | ||
| 13 | |||
| 14 | #include "fxas21002c.h" | ||
| 15 | |||
| 16 | static const struct regmap_config fxas21002c_regmap_i2c_conf = { | ||
| 17 | .reg_bits = 8, | ||
| 18 | .val_bits = 8, | ||
| 19 | .max_register = FXAS21002C_REG_CTRL3, | ||
| 20 | }; | ||
| 21 | |||
| 22 | static int fxas21002c_i2c_probe(struct i2c_client *i2c) | ||
| 23 | { | ||
| 24 | struct regmap *regmap; | ||
| 25 | |||
| 26 | regmap = devm_regmap_init_i2c(i2c, &fxas21002c_regmap_i2c_conf); | ||
| 27 | if (IS_ERR(regmap)) { | ||
| 28 | dev_err(&i2c->dev, "Failed to register i2c regmap: %ld\n", | ||
| 29 | PTR_ERR(regmap)); | ||
| 30 | return PTR_ERR(regmap); | ||
| 31 | } | ||
| 32 | |||
| 33 | return fxas21002c_core_probe(&i2c->dev, regmap, i2c->irq, i2c->name); | ||
| 34 | } | ||
| 35 | |||
| 36 | static int fxas21002c_i2c_remove(struct i2c_client *i2c) | ||
| 37 | { | ||
| 38 | fxas21002c_core_remove(&i2c->dev); | ||
| 39 | |||
| 40 | return 0; | ||
| 41 | } | ||
| 42 | |||
| 43 | static const struct i2c_device_id fxas21002c_i2c_id[] = { | ||
| 44 | { "fxas21002c", 0 }, | ||
| 45 | { } | ||
| 46 | }; | ||
| 47 | MODULE_DEVICE_TABLE(i2c, fxas21002c_i2c_id); | ||
| 48 | |||
| 49 | static const struct of_device_id fxas21002c_i2c_of_match[] = { | ||
| 50 | { .compatible = "nxp,fxas21002c", }, | ||
| 51 | { } | ||
| 52 | }; | ||
| 53 | MODULE_DEVICE_TABLE(of, fxas21002c_i2c_of_match); | ||
| 54 | |||
| 55 | static struct i2c_driver fxas21002c_i2c_driver = { | ||
| 56 | .driver = { | ||
| 57 | .name = "fxas21002c_i2c", | ||
| 58 | .pm = &fxas21002c_pm_ops, | ||
| 59 | .of_match_table = fxas21002c_i2c_of_match, | ||
| 60 | }, | ||
| 61 | .probe_new = fxas21002c_i2c_probe, | ||
| 62 | .remove = fxas21002c_i2c_remove, | ||
| 63 | .id_table = fxas21002c_i2c_id, | ||
| 64 | }; | ||
| 65 | module_i2c_driver(fxas21002c_i2c_driver); | ||
| 66 | |||
| 67 | MODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>"); | ||
| 68 | MODULE_LICENSE("GPL v2"); | ||
| 69 | MODULE_DESCRIPTION("FXAS21002C I2C Gyro driver"); | ||
| @@ -0,0 +1,70 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Driver for NXP Fxas21002c Gyroscope - SPI | ||
| 4 | * | ||
| 5 | * Copyright (C) 2019 Linaro Ltd. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <linux/err.h> | ||
| 9 | #include <linux/mod_devicetable.h> | ||
| 10 | #include <linux/module.h> | ||
| 11 | #include <linux/regmap.h> | ||
| 12 | #include <linux/spi/spi.h> | ||
| 13 | |||
| 14 | #include "fxas21002c.h" | ||
| 15 | |||
| 16 | static const struct regmap_config fxas21002c_regmap_spi_conf = { | ||
| 17 | .reg_bits = 8, | ||
| 18 | .val_bits = 8, | ||
| 19 | .max_register = FXAS21002C_REG_CTRL3, | ||
| 20 | }; | ||
| 21 | |||
| 22 | static int fxas21002c_spi_probe(struct spi_device *spi) | ||
| 23 | { | ||
| 24 | const struct spi_device_id *id = spi_get_device_id(spi); | ||
| 25 | struct regmap *regmap; | ||
| 26 | |||
| 27 | regmap = devm_regmap_init_spi(spi, &fxas21002c_regmap_spi_conf); | ||
| 28 | if (IS_ERR(regmap)) { | ||
| 29 | dev_err(&spi->dev, "Failed to register spi regmap: %ld\n", | ||
| 30 | PTR_ERR(regmap)); | ||
| 31 | return PTR_ERR(regmap); | ||
| 32 | } | ||
| 33 | |||
| 34 | return fxas21002c_core_probe(&spi->dev, regmap, spi->irq, id->name); | ||
| 35 | } | ||
| 36 | |||
| 37 | static int fxas21002c_spi_remove(struct spi_device *spi) | ||
| 38 | { | ||
| 39 | fxas21002c_core_remove(&spi->dev); | ||
| 40 | |||
| 41 | return 0; | ||
| 42 | } | ||
| 43 | |||
| 44 | static const struct spi_device_id fxas21002c_spi_id[] = { | ||
| 45 | { "fxas21002c", 0 }, | ||
| 46 | { } | ||
| 47 | }; | ||
| 48 | MODULE_DEVICE_TABLE(spi, fxas21002c_spi_id); | ||
| 49 | |||
| 50 | static const struct of_device_id fxas21002c_spi_of_match[] = { | ||
| 51 | { .compatible = "nxp,fxas21002c", }, | ||
| 52 | { } | ||
| 53 | }; | ||
| 54 | MODULE_DEVICE_TABLE(of, fxas21002c_spi_of_match); | ||
| 55 | |||
| 56 | static struct spi_driver fxas21002c_spi_driver = { | ||
| 57 | .driver = { | ||
| 58 | .name = "fxas21002c_spi", | ||
| 59 | .pm = &fxas21002c_pm_ops, | ||
| 60 | .of_match_table = fxas21002c_spi_of_match, | ||
| 61 | }, | ||
| 62 | .probe = fxas21002c_spi_probe, | ||
| 63 | .remove = fxas21002c_spi_remove, | ||
| 64 | .id_table = fxas21002c_spi_id, | ||
| 65 | }; | ||
| 66 | module_spi_driver(fxas21002c_spi_driver); | ||
| 67 | |||
| 68 | MODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>"); | ||
| 69 | MODULE_LICENSE("GPL v2"); | ||
| 70 | MODULE_DESCRIPTION("FXAS21002C SPI Gyro driver"); | ||
| @@ -865,7 +865,7 @@ static int mpu3050_power_up(struct mpu3050 *mpu3050) · 864 unmodified lines | |||
| 865 | dev_err(mpu3050->dev, "error setting power mode\n"); | 865 | dev_err(mpu3050->dev, "error setting power mode\n"); |
| 866 | return ret; | 866 | return ret; |
| 867 | } | 867 | } |
| 868 | msleep(10); | 868 | usleep_range(10000, 20000); |
| 869 | 869 | ||
| 870 | return 0; | 870 | return 0; |
| 871 | } | 871 | } |
| @@ -9,7 +9,7 @@ config IIO_ST_LSM6DSX · 8 unmodified lines | |||
| 9 | help | 9 | help |
| 10 | Say yes here to build support for STMicroelectronics LSM6DSx imu | 10 | Say yes here to build support for STMicroelectronics LSM6DSx imu |
| 11 | sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm, | 11 | sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm, |
| 12 | ism330dlc, lsm6dso, lsm6dsox, asm330lhh | 12 | ism330dlc, lsm6dso, lsm6dsox, asm330lhh, lsm6dsr |
| 13 | 13 | ||
| 14 | To compile this driver as a module, choose M here: the module | 14 | To compile this driver as a module, choose M here: the module |
| 15 | will be called st_lsm6dsx. | 15 | will be called st_lsm6dsx. |
| @@ -22,6 +22,7 @@ · 21 unmodified lines | |||
| 22 | #define ST_LSM6DSO_DEV_NAME "lsm6dso" | 22 | #define ST_LSM6DSO_DEV_NAME "lsm6dso" |
| 23 | #define ST_ASM330LHH_DEV_NAME "asm330lhh" | 23 | #define ST_ASM330LHH_DEV_NAME "asm330lhh" |
| 24 | #define ST_LSM6DSOX_DEV_NAME "lsm6dsox" | 24 | #define ST_LSM6DSOX_DEV_NAME "lsm6dsox" |
| 25 | #define ST_LSM6DSR_DEV_NAME "lsm6dsr" | ||
| 25 | 26 | ||
| 26 | enum st_lsm6dsx_hw_id { | 27 | enum st_lsm6dsx_hw_id { |
| 27 | ST_LSM6DS3_ID, | 28 | ST_LSM6DS3_ID, |
| @@ -32,6 +33,7 @@ enum st_lsm6dsx_hw_id { · 4 unmodified lines | |||
| 32 | ST_LSM6DSO_ID, | 33 | ST_LSM6DSO_ID, |
| 33 | ST_ASM330LHH_ID, | 34 | ST_ASM330LHH_ID, |
| 34 | ST_LSM6DSOX_ID, | 35 | ST_LSM6DSOX_ID, |
| 36 | ST_LSM6DSR_ID, | ||
| 35 | ST_LSM6DSX_MAX_ID, | 37 | ST_LSM6DSX_MAX_ID, |
| 36 | }; | 38 | }; |
| 37 | 39 | ||
| @@ -13,9 +13,9 @@ · 12 unmodified lines | |||
| 13 | * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated depending on the | 13 | * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated depending on the |
| 14 | * value of the decimation factor and ODR set for each FIFO data set. | 14 | * value of the decimation factor and ODR set for each FIFO data set. |
| 15 | * | 15 | * |
| 16 | * LSM6DSO/LSM6DSOX/ASM330LHH: The FIFO buffer can be configured to store data | 16 | * LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR: The FIFO buffer can be configured to |
| 17 | * from gyroscope and accelerometer. Each sample is queued with a tag (1B) | 17 | * store data from gyroscope and accelerometer. Each sample is queued with |
| 18 | * indicating data source (gyroscope, accelerometer, hw timer). | 18 | * a tag (1B) indicating data source (gyroscope, accelerometer, hw timer). |
| 19 | * | 19 | * |
| 20 | * FIFO supported modes: | 20 | * FIFO supported modes: |
| 21 | * - BYPASS: FIFO disabled | 21 | * - BYPASS: FIFO disabled |
| @@ -506,7 +506,7 @@ st_lsm6dsx_push_tagged_data(struct st_lsm6dsx_hw *hw, u8 tag, · 484 unmodified lines | |||
| 506 | } | 506 | } |
| 507 | 507 | ||
| 508 | /** | 508 | /** |
| 509 | * st_lsm6dsx_read_tagged_fifo() - LSM6DSO/LSM6DSOX/ASM330LHH read FIFO routine | 509 | * st_lsm6dsx_read_tagged_fifo() - tagged hw FIFO read routine |
| 510 | * @hw: Pointer to instance of struct st_lsm6dsx_hw. | 510 | * @hw: Pointer to instance of struct st_lsm6dsx_hw. |
| 511 | * | 511 | * |
| 512 | * Read samples from the hw FIFO and push them to IIO buffers. | 512 | * Read samples from the hw FIFO and push them to IIO buffers. |
| @@ -517,7 +517,6 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw) · 4 unmodified lines | |||
| 517 | { | 517 | { |
| 518 | u16 pattern_len = hw->sip * ST_LSM6DSX_TAGGED_SAMPLE_SIZE; | 518 | u16 pattern_len = hw->sip * ST_LSM6DSX_TAGGED_SAMPLE_SIZE; |
| 519 | u16 fifo_len, fifo_diff_mask; | 519 | u16 fifo_len, fifo_diff_mask; |
| 520 | struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor; | ||
| 521 | u8 iio_buff[ST_LSM6DSX_IIO_BUFF_SIZE], tag; | 520 | u8 iio_buff[ST_LSM6DSX_IIO_BUFF_SIZE], tag; |
| 522 | bool reset_ts = false; | 521 | bool reset_ts = false; |
| 523 | int i, err, read_len; | 522 | int i, err, read_len; |
| @@ -539,9 +538,6 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw) · 15 unmodified lines | |||
| 539 | if (!fifo_len) | 538 | if (!fifo_len) |
| 540 | return 0; | 539 | return 0; |
| 541 | 540 | ||
| 542 | acc_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]); | ||
| 543 | gyro_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_GYRO]); | ||
| 544 | |||
| 545 | for (read_len = 0; read_len < fifo_len; read_len += pattern_len) { | 541 | for (read_len = 0; read_len < fifo_len; read_len += pattern_len) { |
| 546 | err = st_lsm6dsx_read_block(hw, | 542 | err = st_lsm6dsx_read_block(hw, |
| 547 | ST_LSM6DSX_REG_FIFO_OUT_TAG_ADDR, | 543 | ST_LSM6DSX_REG_FIFO_OUT_TAG_ADDR, |
| @@ -23,7 +23,7 @@ · 22 unmodified lines | |||
| 23 | * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 | 23 | * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 |
| 24 | * - FIFO size: 4KB | 24 | * - FIFO size: 4KB |
| 25 | * | 25 | * |
| 26 | * - LSM6DSO/LSM6DSOX/ASM330LHH | 26 | * - LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR |
| 27 | * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416 | 27 | * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416 |
| 28 | * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 | 28 | * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 |
| 29 | * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 | 29 | * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 |
| @@ -62,37 +62,19 @@ · 32 unmodified lines | |||
| 62 | #define ST_LSM6DSX_REG_INT2_ON_INT1_ADDR 0x13 | 62 | #define ST_LSM6DSX_REG_INT2_ON_INT1_ADDR 0x13 |
| 63 | #define ST_LSM6DSX_REG_INT2_ON_INT1_MASK BIT(5) | 63 | #define ST_LSM6DSX_REG_INT2_ON_INT1_MASK BIT(5) |
| 64 | 64 | ||
| 65 | #define ST_LSM6DSX_REG_ACC_ODR_ADDR 0x10 | ||
| 66 | #define ST_LSM6DSX_REG_ACC_ODR_MASK GENMASK(7, 4) | ||
| 67 | #define ST_LSM6DSX_REG_ACC_FS_ADDR 0x10 | ||
| 68 | #define ST_LSM6DSX_REG_ACC_FS_MASK GENMASK(3, 2) | ||
| 69 | #define ST_LSM6DSX_REG_ACC_OUT_X_L_ADDR 0x28 | 65 | #define ST_LSM6DSX_REG_ACC_OUT_X_L_ADDR 0x28 |
| 70 | #define ST_LSM6DSX_REG_ACC_OUT_Y_L_ADDR 0x2a | 66 | #define ST_LSM6DSX_REG_ACC_OUT_Y_L_ADDR 0x2a |
| 71 | #define ST_LSM6DSX_REG_ACC_OUT_Z_L_ADDR 0x2c | 67 | #define ST_LSM6DSX_REG_ACC_OUT_Z_L_ADDR 0x2c |
| 72 | 68 | ||
| 73 | #define ST_LSM6DSX_REG_GYRO_ODR_ADDR 0x11 | ||
| 74 | #define ST_LSM6DSX_REG_GYRO_ODR_MASK GENMASK(7, 4) | ||
| 75 | #define ST_LSM6DSX_REG_GYRO_FS_ADDR 0x11 | ||
| 76 | #define ST_LSM6DSX_REG_GYRO_FS_MASK GENMASK(3, 2) | ||
| 77 | #define ST_LSM6DSX_REG_GYRO_OUT_X_L_ADDR 0x22 | 69 | #define ST_LSM6DSX_REG_GYRO_OUT_X_L_ADDR 0x22 |
| 78 | #define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR 0x24 | 70 | #define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR 0x24 |
| 79 | #define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR 0x26 | 71 | #define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR 0x26 |
| 80 | 72 | ||
| 81 | #define ST_LSM6DSX_ACC_FS_2G_GAIN IIO_G_TO_M_S_2(61) | ||
| 82 | #define ST_LSM6DSX_ACC_FS_4G_GAIN IIO_G_TO_M_S_2(122) | ||
| 83 | #define ST_LSM6DSX_ACC_FS_8G_GAIN IIO_G_TO_M_S_2(244) | ||
| 84 | #define ST_LSM6DSX_ACC_FS_16G_GAIN IIO_G_TO_M_S_2(488) | ||
| 85 | |||
| 86 | #define ST_LSM6DSX_GYRO_FS_245_GAIN IIO_DEGREE_TO_RAD(8750) | ||
| 87 | #define ST_LSM6DSX_GYRO_FS_500_GAIN IIO_DEGREE_TO_RAD(17500) | ||
| 88 | #define ST_LSM6DSX_GYRO_FS_1000_GAIN IIO_DEGREE_TO_RAD(35000) | ||
| 89 | #define ST_LSM6DSX_GYRO_FS_2000_GAIN IIO_DEGREE_TO_RAD(70000) | ||
| 90 | |||
| 91 | static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = { | 73 | static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = { |
| 92 | [ST_LSM6DSX_ID_ACC] = { | 74 | [ST_LSM6DSX_ID_ACC] = { |
| 93 | .reg = { | 75 | .reg = { |
| 94 | .addr = ST_LSM6DSX_REG_ACC_ODR_ADDR, | 76 | .addr = 0x10, |
| 95 | .mask = ST_LSM6DSX_REG_ACC_ODR_MASK, | 77 | .mask = GENMASK(7, 4), |
| 96 | }, | 78 | }, |
| 97 | .odr_avl[0] = { 13, 0x01 }, | 79 | .odr_avl[0] = { 13, 0x01 }, |
| 98 | .odr_avl[1] = { 26, 0x02 }, | 80 | .odr_avl[1] = { 26, 0x02 }, |
| @@ -103,8 +85,8 @@ static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = { · 4 unmodified lines | |||
| 103 | }, | 85 | }, |
| 104 | [ST_LSM6DSX_ID_GYRO] = { | 86 | [ST_LSM6DSX_ID_GYRO] = { |
| 105 | .reg = { | 87 | .reg = { |
| 106 | .addr = ST_LSM6DSX_REG_GYRO_ODR_ADDR, | 88 | .addr = 0x11, |
| 107 | .mask = ST_LSM6DSX_REG_GYRO_ODR_MASK, | 89 | .mask = GENMASK(7, 4), |
| 108 | }, | 90 | }, |
| 109 | .odr_avl[0] = { 13, 0x01 }, | 91 | .odr_avl[0] = { 13, 0x01 }, |
| 110 | .odr_avl[1] = { 26, 0x02 }, | 92 | .odr_avl[1] = { 26, 0x02 }, |
| @@ -118,23 +100,23 @@ static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = { · 7 unmodified lines | |||
| 118 | static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = { | 100 | static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = { |
| 119 | [ST_LSM6DSX_ID_ACC] = { | 101 | [ST_LSM6DSX_ID_ACC] = { |
| 120 | .reg = { | 102 | .reg = { |
| 121 | .addr = ST_LSM6DSX_REG_ACC_FS_ADDR, | 103 | .addr = 0x10, |
| 122 | .mask = ST_LSM6DSX_REG_ACC_FS_MASK, | 104 | .mask = GENMASK(3, 2), |
| 123 | }, | 105 | }, |
| 124 | .fs_avl[0] = { ST_LSM6DSX_ACC_FS_2G_GAIN, 0x0 }, | 106 | .fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 }, |
| 125 | .fs_avl[1] = { ST_LSM6DSX_ACC_FS_4G_GAIN, 0x2 }, | 107 | .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, |
| 126 | .fs_avl[2] = { ST_LSM6DSX_ACC_FS_8G_GAIN, 0x3 }, | 108 | .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, |
| 127 | .fs_avl[3] = { ST_LSM6DSX_ACC_FS_16G_GAIN, 0x1 }, | 109 | .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, |
| 128 | }, | 110 | }, |
| 129 | [ST_LSM6DSX_ID_GYRO] = { | 111 | [ST_LSM6DSX_ID_GYRO] = { |
| 130 | .reg = { | 112 | .reg = { |
| 131 | .addr = ST_LSM6DSX_REG_GYRO_FS_ADDR, | 113 | .addr = 0x11, |
| 132 | .mask = ST_LSM6DSX_REG_GYRO_FS_MASK, | 114 | .mask = GENMASK(3, 2), |
| 133 | }, | 115 | }, |
| 134 | .fs_avl[0] = { ST_LSM6DSX_GYRO_FS_245_GAIN, 0x0 }, | 116 | .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 }, |
| 135 | .fs_avl[1] = { ST_LSM6DSX_GYRO_FS_500_GAIN, 0x1 }, | 117 | .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, |
| 136 | .fs_avl[2] = { ST_LSM6DSX_GYRO_FS_1000_GAIN, 0x2 }, | 118 | .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, |
| 137 | .fs_avl[3] = { ST_LSM6DSX_GYRO_FS_2000_GAIN, 0x3 }, | 119 | .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, |
| 138 | } | 120 | } |
| 139 | }; | 121 | }; |
| 140 | 122 | ||
| @@ -387,6 +369,71 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { · 246 unmodified lines | |||
| 387 | }, | 369 | }, |
| 388 | }, | 370 | }, |
| 389 | }, | 371 | }, |
| 372 | { | ||
| 373 | .wai = 0x6b, | ||
| 374 | .max_fifo_size = 512, | ||
| 375 | .id = { | ||
| 376 | [0] = ST_LSM6DSR_ID, | ||
| 377 | }, | ||
| 378 | .batch = { | ||
| 379 | [ST_LSM6DSX_ID_ACC] = { | ||
| 380 | .addr = 0x09, | ||
| 381 | .mask = GENMASK(3, 0), | ||
| 382 | }, | ||
| 383 | [ST_LSM6DSX_ID_GYRO] = { | ||
| 384 | .addr = 0x09, | ||
| 385 | .mask = GENMASK(7, 4), | ||
| 386 | }, | ||
| 387 | }, | ||
| 388 | .fifo_ops = { | ||
| 389 | .read_fifo = st_lsm6dsx_read_tagged_fifo, | ||
| 390 | .fifo_th = { | ||
| 391 | .addr = 0x07, | ||
| 392 | .mask = GENMASK(8, 0), | ||
| 393 | }, | ||
| 394 | .fifo_diff = { | ||
| 395 | .addr = 0x3a, | ||
| 396 | .mask = GENMASK(8, 0), | ||
| 397 | }, | ||
| 398 | .th_wl = 1, | ||
| 399 | }, | ||
| 400 | .ts_settings = { | ||
| 401 | .timer_en = { | ||
| 402 | .addr = 0x19, | ||
| 403 | .mask = BIT(5), | ||
| 404 | }, | ||
| 405 | .decimator = { | ||
| 406 | .addr = 0x0a, | ||
| 407 | .mask = GENMASK(7, 6), | ||
| 408 | }, | ||
| 409 | }, | ||
| 410 | .shub_settings = { | ||
| 411 | .page_mux = { | ||
| 412 | .addr = 0x01, | ||
| 413 | .mask = BIT(6), | ||
| 414 | }, | ||
| 415 | .master_en = { | ||
| 416 | .addr = 0x14, | ||
| 417 | .mask = BIT(2), | ||
| 418 | }, | ||
| 419 | .pullup_en = { | ||
| 420 | .addr = 0x14, | ||
| 421 | .mask = BIT(3), | ||
| 422 | }, | ||
| 423 | .aux_sens = { | ||
| 424 | .addr = 0x14, | ||
| 425 | .mask = GENMASK(1, 0), | ||
| 426 | }, | ||
| 427 | .wr_once = { | ||
| 428 | .addr = 0x14, | ||
| 429 | .mask = BIT(6), | ||
| 430 | }, | ||
| 431 | .shub_out = 0x02, | ||
| 432 | .slv0_addr = 0x15, | ||
| 433 | .dw_slv0_addr = 0x21, | ||
| 434 | .batch_en = BIT(3), | ||
| 435 | } | ||
| 436 | }, | ||
| 390 | }; | 437 | }; |
| 391 | 438 | ||
| 392 | static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = { | 439 | static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = { |
| @@ -73,6 +73,10 @@ static const struct of_device_id st_lsm6dsx_i2c_of_match[] = { · 72 unmodified lines | |||
| 73 | .compatible = "st,lsm6dsox", | 73 | .compatible = "st,lsm6dsox", |
| 74 | .data = (void *)ST_LSM6DSOX_ID, | 74 | .data = (void *)ST_LSM6DSOX_ID, |
| 75 | }, | 75 | }, |
| 76 | { | ||
| 77 | .compatible = "st,lsm6dsr", | ||
| 78 | .data = (void *)ST_LSM6DSR_ID, | ||
| 79 | }, | ||
| 76 | {}, | 80 | {}, |
| 77 | }; | 81 | }; |
| 78 | MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match); | 82 | MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match); |
| @@ -86,6 +90,7 @@ static const struct i2c_device_id st_lsm6dsx_i2c_id_table[] = { · 7 unmodified lines | |||
| 86 | { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID }, | 90 | { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID }, |
| 87 | { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID }, | 91 | { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID }, |
| 88 | { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID }, | 92 | { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID }, |
| 93 | { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID }, | ||
| 89 | {}, | 94 | {}, |
| 90 | }; | 95 | }; |
| 91 | MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table); | 96 | MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table); |
| @@ -73,6 +73,10 @@ static const struct of_device_id st_lsm6dsx_spi_of_match[] = { · 72 unmodified lines | |||
| 73 | .compatible = "st,lsm6dsox", | 73 | .compatible = "st,lsm6dsox", |
| 74 | .data = (void *)ST_LSM6DSOX_ID, | 74 | .data = (void *)ST_LSM6DSOX_ID, |
| 75 | }, | 75 | }, |
| 76 | { | ||
| 77 | .compatible = "st,lsm6dsr", | ||
| 78 | .data = (void *)ST_LSM6DSR_ID, | ||
| 79 | }, | ||
| 76 | {}, | 80 | {}, |
| 77 | }; | 81 | }; |
| 78 | MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match); | 82 | MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match); |
| @@ -86,6 +90,7 @@ static const struct spi_device_id st_lsm6dsx_spi_id_table[] = { · 7 unmodified lines | |||
| 86 | { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID }, | 90 | { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID }, |
| 87 | { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID }, | 91 | { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID }, |
| 88 | { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID }, | 92 | { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID }, |
| 93 | { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID }, | ||
| 89 | {}, | 94 | {}, |
| 90 | }; | 95 | }; |
| 91 | MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table); | 96 | MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table); |
| @@ -68,12 +68,19 @@ config RFD77402 · 67 unmodified lines | |||
| 68 | module will be called rfd77402. | 68 | module will be called rfd77402. |
| 69 | 69 | ||
| 70 | config SRF04 | 70 | config SRF04 |
| 71 | tristate "Devantech SRF04 ultrasonic ranger sensor" | 71 | tristate "GPIO bitbanged ultrasonic ranger sensor (SRF04, MB1000)" |
| 72 | depends on GPIOLIB | 72 | depends on GPIOLIB |
| 73 | help | 73 | help |
| 74 | Say Y here to build a driver for Devantech SRF04 ultrasonic | 74 | Say Y here to build a driver for GPIO bitbanged ultrasonic |
| 75 | ranger sensor. This driver can be used to measure the distance | 75 | ranger sensor. This driver can be used to measure the distance |
| 76 | of objects. It is using two GPIOs. | 76 | of objects. It is using two GPIOs. |
| 77 | Actually Supported types are: | ||
| 78 | - Devantech SRF04 | ||
| 79 | - Maxbotix mb1000 | ||
| 80 | - Maxbotix mb1010 | ||
| 81 | - Maxbotix mb1020 | ||
| 82 | - Maxbotix mb1030 | ||
| 83 | - Maxbotix mb1040 | ||
| 77 | 84 | ||
| 78 | To compile this driver as a module, choose M here: the | 85 | To compile this driver as a module, choose M here: the |
| 79 | module will be called srf04. | 86 | module will be called srf04. |
| @@ -23,7 +23,7 @@ · 22 unmodified lines | |||
| 23 | * trig: --+ +------------------------------------------------------ | 23 | * trig: --+ +------------------------------------------------------ |
| 24 | * ^ ^ | 24 | * ^ ^ |
| 25 | * |<->| | 25 | * |<->| |
| 26 | * udelay(10) | 26 | * udelay(trigger_pulse_us) |
| 27 | * | 27 | * |
| 28 | * ultra +-+ +-+ +-+ | 28 | * ultra +-+ +-+ +-+ |
| 29 | * sonic | | | | | | | 29 | * sonic | | | | | | |
| @@ -48,6 +48,7 @@ · 18 unmodified lines | |||
| 48 | #include <linux/kernel.h> | 48 | #include <linux/kernel.h> |
| 49 | #include <linux/module.h> | 49 | #include <linux/module.h> |
| 50 | #include <linux/of.h> | 50 | #include <linux/of.h> |
| 51 | #include <linux/of_device.h> | ||
| 51 | #include <linux/platform_device.h> | 52 | #include <linux/platform_device.h> |
| 52 | #include <linux/property.h> | 53 | #include <linux/property.h> |
| 53 | #include <linux/sched.h> | 54 | #include <linux/sched.h> |
| @@ -56,6 +57,10 @@ · 2 unmodified lines | |||
| 56 | #include <linux/iio/iio.h> | 57 | #include <linux/iio/iio.h> |
| 57 | #include <linux/iio/sysfs.h> | 58 | #include <linux/iio/sysfs.h> |
| 58 | 59 | ||
| 60 | struct srf04_cfg { | ||
| 61 | unsigned long trigger_pulse_us; | ||
| 62 | }; | ||
| 63 | |||
| 59 | struct srf04_data { | 64 | struct srf04_data { |
| 60 | struct device *dev; | 65 | struct device *dev; |
| 61 | struct gpio_desc *gpiod_trig; | 66 | struct gpio_desc *gpiod_trig; |
| @@ -66,6 +71,15 @@ struct srf04_data { · 4 unmodified lines | |||
| 66 | ktime_t ts_falling; | 71 | ktime_t ts_falling; |
| 67 | struct completion rising; | 72 | struct completion rising; |
| 68 | struct completion falling; | 73 | struct completion falling; |
| 74 | const struct srf04_cfg *cfg; | ||
| 75 | }; | ||
| 76 | |||
| 77 | static const struct srf04_cfg srf04_cfg = { | ||
| 78 | .trigger_pulse_us = 10, | ||
| 79 | }; | ||
| 80 | |||
| 81 | static const struct srf04_cfg mb_lv_cfg = { | ||
| 82 | .trigger_pulse_us = 20, | ||
| 69 | }; | 83 | }; |
| 70 | 84 | ||
| 71 | static irqreturn_t srf04_handle_irq(int irq, void *dev_id) | 85 | static irqreturn_t srf04_handle_irq(int irq, void *dev_id) |
| @@ -102,7 +116,7 @@ static int srf04_read(struct srf04_data *data) · 30 unmodified lines | |||
| 102 | reinit_completion(&data->falling); | 116 | reinit_completion(&data->falling); |
| 103 | 117 | ||
| 104 | gpiod_set_value(data->gpiod_trig, 1); | 118 | gpiod_set_value(data->gpiod_trig, 1); |
| 105 | udelay(10); | 119 | udelay(data->cfg->trigger_pulse_us); |
| 106 | gpiod_set_value(data->gpiod_trig, 0); | 120 | gpiod_set_value(data->gpiod_trig, 0); |
| 107 | 121 | ||
| 108 | /* it cannot take more than 20 ms */ | 122 | /* it cannot take more than 20 ms */ |
| @@ -215,6 +229,18 @@ static const struct iio_chan_spec srf04_chan_spec[] = { · 106 unmodified lines | |||
| 215 | }, | 229 | }, |
| 216 | }; | 230 | }; |
| 217 | 231 | ||
| 232 | static const struct of_device_id of_srf04_match[] = { | ||
| 233 | { .compatible = "devantech,srf04", .data = &srf04_cfg}, | ||
| 234 | { .compatible = "maxbotix,mb1000", .data = &mb_lv_cfg}, | ||
| 235 | { .compatible = "maxbotix,mb1010", .data = &mb_lv_cfg}, | ||
| 236 | { .compatible = "maxbotix,mb1020", .data = &mb_lv_cfg}, | ||
| 237 | { .compatible = "maxbotix,mb1030", .data = &mb_lv_cfg}, | ||
| 238 | { .compatible = "maxbotix,mb1040", .data = &mb_lv_cfg}, | ||
| 239 | {}, | ||
| 240 | }; | ||
| 241 | |||
| 242 | MODULE_DEVICE_TABLE(of, of_srf04_match); | ||
| 243 | |||
| 218 | static int srf04_probe(struct platform_device *pdev) | 244 | static int srf04_probe(struct platform_device *pdev) |
| 219 | { | 245 | { |
| 220 | struct device *dev = &pdev->dev; | 246 | struct device *dev = &pdev->dev; |
| @@ -230,6 +256,7 @@ static int srf04_probe(struct platform_device *pdev) · 9 unmodified lines | |||
| 230 | 256 | ||
| 231 | data = iio_priv(indio_dev); | 257 | data = iio_priv(indio_dev); |
| 232 | data->dev = dev; | 258 | data->dev = dev; |
| 259 | data->cfg = of_match_device(of_srf04_match, dev)->data; | ||
| 233 | 260 | ||
| 234 | mutex_init(&data->lock); | 261 | mutex_init(&data->lock); |
| 235 | init_completion(&data->rising); | 262 | init_completion(&data->rising); |
| @@ -280,13 +307,6 @@ static int srf04_probe(struct platform_device *pdev) · 44 unmodified lines | |||
| 280 | return devm_iio_device_register(dev, indio_dev); | 307 | return devm_iio_device_register(dev, indio_dev); |
| 281 | } | 308 | } |
| 282 | 309 | ||
| 283 | static const struct of_device_id of_srf04_match[] = { | ||
| 284 | { .compatible = "devantech,srf04", }, | ||
| 285 | {}, | ||
| 286 | }; | ||
| 287 | |||
| 288 | MODULE_DEVICE_TABLE(of, of_srf04_match); | ||
| 289 | |||
| 290 | static struct platform_driver srf04_driver = { | 310 | static struct platform_driver srf04_driver = { |
| 291 | .probe = srf04_probe, | 311 | .probe = srf04_probe, |
| 292 | .driver = { | 312 | .driver = { |
| @@ -210,6 +210,9 @@ static int max31856_read_raw(struct iio_dev *indio_dev, · 209 unmodified lines | |||
| 210 | return IIO_VAL_INT_PLUS_MICRO; | 210 | return IIO_VAL_INT_PLUS_MICRO; |
| 211 | } | 211 | } |
| 212 | break; | 212 | break; |
| 213 | default: | ||
| 214 | ret = -EINVAL; | ||
| 215 | break; | ||
| 213 | } | 216 | } |
| 214 | 217 | ||
| 215 | return ret; | 218 | return ret; |
| @@ -5,22 +5,25 @@ · 4 unmodified lines | |||
| 5 | * Copyright 2011 Analog Devices Inc. | 5 | * Copyright 2011 Analog Devices Inc. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #include <asm/div64.h> | ||
| 9 | |||
| 10 | #include <linux/clk.h> | ||
| 8 | #include <linux/device.h> | 11 | #include <linux/device.h> |
| 12 | #include <linux/err.h> | ||
| 9 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/regulator/consumer.h> | ||
| 10 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
| 11 | #include <linux/sysfs.h> | ||
| 12 | #include <linux/spi/spi.h> | 17 | #include <linux/spi/spi.h> |
| 13 | #include <linux/regulator/consumer.h> | 18 | #include <linux/sysfs.h> |
| 14 | #include <linux/err.h> | ||
| 15 | #include <linux/module.h> | ||
| 16 | #include <asm/div64.h> | ||
| 17 | 19 | ||
| 18 | #include <linux/iio/iio.h> | 20 | #include <linux/iio/iio.h> |
| 19 | #include <linux/iio/sysfs.h> | 21 | #include <linux/iio/sysfs.h> |
| 20 | #include "dds.h" | ||
| 21 | 22 | ||
| 22 | #include "ad9832.h" | 23 | #include "ad9832.h" |
| 23 | 24 | ||
| 25 | #include "dds.h" | ||
| 26 | |||
| 24 | /* Registers */ | 27 | /* Registers */ |
| 25 | 28 | ||
| 26 | #define AD9832_FREQ0LL 0x0 | 29 | #define AD9832_FREQ0LL 0x0 |
| @@ -93,7 +96,7 @@ struct ad9832_state { · 66 unmodified lines | |||
| 93 | struct spi_device *spi; | 96 | struct spi_device *spi; |
| 94 | struct regulator *avdd; | 97 | struct regulator *avdd; |
| 95 | struct regulator *dvdd; | 98 | struct regulator *dvdd; |
| 96 | unsigned long mclk; | 99 | struct clk *mclk; |
| 97 | unsigned short ctrl_fp; | 100 | unsigned short ctrl_fp; |
| 98 | unsigned short ctrl_ss; | 101 | unsigned short ctrl_ss; |
| 99 | unsigned short ctrl_src; | 102 | unsigned short ctrl_src; |
| @@ -128,10 +131,10 @@ static int ad9832_write_frequency(struct ad9832_state *st, · 28 unmodified lines | |||
| 128 | { | 131 | { |
| 129 | unsigned long regval; | 132 | unsigned long regval; |
| 130 | 133 | ||
| 131 | if (fout > (st->mclk / 2)) | 134 | if (fout > (clk_get_rate(st->mclk) / 2)) |
| 132 | return -EINVAL; | 135 | return -EINVAL; |
| 133 | 136 | ||
| 134 | regval = ad9832_calc_freqreg(st->mclk, fout); | 137 | regval = ad9832_calc_freqreg(clk_get_rate(st->mclk), fout); |
| 135 | 138 | ||
| 136 | st->freq_data[0] = cpu_to_be16((AD9832_CMD_FRE8BITSW << CMD_SHIFT) | | 139 | st->freq_data[0] = cpu_to_be16((AD9832_CMD_FRE8BITSW << CMD_SHIFT) | |
| 137 | (addr << ADD_SHIFT) | | 140 | (addr << ADD_SHIFT) | |
| @@ -332,7 +335,16 @@ static int ad9832_probe(struct spi_device *spi) · 194 unmodified lines | |||
| 332 | goto error_disable_avdd; | 335 | goto error_disable_avdd; |
| 333 | } | 336 | } |
| 334 | 337 | ||
| 335 | st->mclk = pdata->mclk; | 338 | st->mclk = devm_clk_get(&spi->dev, "mclk"); |
| 339 | if (IS_ERR(st->mclk)) { | ||
| 340 | ret = PTR_ERR(st->mclk); | ||
| 341 | goto error_disable_dvdd; | ||
| 342 | } | ||
| 343 | |||
| 344 | ret = clk_prepare_enable(st->mclk); | ||
| 345 | if (ret < 0) | ||
| 346 | goto error_disable_dvdd; | ||
| 347 | |||
| 336 | st->spi = spi; | 348 | st->spi = spi; |
| 337 | mutex_init(&st->lock); | 349 | mutex_init(&st->lock); |
| 338 | 350 | ||
| @@ -383,39 +395,41 @@ static int ad9832_probe(struct spi_device *spi) · 44 unmodified lines | |||
| 383 | ret = spi_sync(st->spi, &st->msg); | 395 | ret = spi_sync(st->spi, &st->msg); |
| 384 | if (ret) { | 396 | if (ret) { |
| 385 | dev_err(&spi->dev, "device init failed\n"); | 397 | dev_err(&spi->dev, "device init failed\n"); |
| 386 | goto error_disable_dvdd; | 398 | goto error_unprepare_mclk; |
| 387 | } | 399 | } |
| 388 | 400 | ||
| 389 | ret = ad9832_write_frequency(st, AD9832_FREQ0HM, pdata->freq0); | 401 | ret = ad9832_write_frequency(st, AD9832_FREQ0HM, pdata->freq0); |
| 390 | if (ret) | 402 | if (ret) |
| 391 | goto error_disable_dvdd; | 403 | goto error_unprepare_mclk; |
| 392 | 404 | ||
| 393 | ret = ad9832_write_frequency(st, AD9832_FREQ1HM, pdata->freq1); | 405 | ret = ad9832_write_frequency(st, AD9832_FREQ1HM, pdata->freq1); |
| 394 | if (ret) | 406 | if (ret) |
| 395 | goto error_disable_dvdd; | 407 | goto error_unprepare_mclk; |
| 396 | 408 | ||
| 397 | ret = ad9832_write_phase(st, AD9832_PHASE0H, pdata->phase0); | 409 | ret = ad9832_write_phase(st, AD9832_PHASE0H, pdata->phase0); |
| 398 | if (ret) | 410 | if (ret) |
| 399 | goto error_disable_dvdd; | 411 | goto error_unprepare_mclk; |
| 400 | 412 | ||
| 401 | ret = ad9832_write_phase(st, AD9832_PHASE1H, pdata->phase1); | 413 | ret = ad9832_write_phase(st, AD9832_PHASE1H, pdata->phase1); |
| 402 | if (ret) | 414 | if (ret) |
| 403 | goto error_disable_dvdd; | 415 | goto error_unprepare_mclk; |
| 404 | 416 | ||
| 405 | ret = ad9832_write_phase(st, AD9832_PHASE2H, pdata->phase2); | 417 | ret = ad9832_write_phase(st, AD9832_PHASE2H, pdata->phase2); |
| 406 | if (ret) | 418 | if (ret) |
| 407 | goto error_disable_dvdd; | 419 | goto error_unprepare_mclk; |
| 408 | 420 | ||
| 409 | ret = ad9832_write_phase(st, AD9832_PHASE3H, pdata->phase3); | 421 | ret = ad9832_write_phase(st, AD9832_PHASE3H, pdata->phase3); |
| 410 | if (ret) | 422 | if (ret) |
| 411 | goto error_disable_dvdd; | 423 | goto error_unprepare_mclk; |
| 412 | 424 | ||
| 413 | ret = iio_device_register(indio_dev); | 425 | ret = iio_device_register(indio_dev); |
| 414 | if (ret) | 426 | if (ret) |
| 415 | goto error_disable_dvdd; | 427 | goto error_unprepare_mclk; |
| 416 | 428 | ||
| 417 | return 0; | 429 | return 0; |
| 418 | 430 | ||
| 431 | error_unprepare_mclk: | ||
| 432 | clk_disable_unprepare(st->mclk); | ||
| 419 | error_disable_dvdd: | 433 | error_disable_dvdd: |
| 420 | regulator_disable(st->dvdd); | 434 | regulator_disable(st->dvdd); |
| 421 | error_disable_avdd: | 435 | error_disable_avdd: |
| @@ -430,6 +444,7 @@ static int ad9832_remove(struct spi_device *spi) · 8 unmodified lines | |||
| 430 | struct ad9832_state *st = iio_priv(indio_dev); | 444 | struct ad9832_state *st = iio_priv(indio_dev); |
| 431 | 445 | ||
| 432 | iio_device_unregister(indio_dev); | 446 | iio_device_unregister(indio_dev); |
| 447 | clk_disable_unprepare(st->mclk); | ||
| 433 | regulator_disable(st->dvdd); | 448 | regulator_disable(st->dvdd); |
| 434 | regulator_disable(st->avdd); | 449 | regulator_disable(st->avdd); |
| 435 | 450 | ||
| @@ -23,7 +23,6 @@ · 22 unmodified lines | |||
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | struct ad9832_platform_data { | 25 | struct ad9832_platform_data { |
| 26 | unsigned long mclk; | ||
| 27 | unsigned long freq0; | 26 | unsigned long freq0; |
| 28 | unsigned long freq1; | 27 | unsigned long freq1; |
| 29 | unsigned short phase0; | 28 | unsigned short phase0; |
| @@ -285,7 +285,7 @@ ssize_t ad9834_show_out0_wavetype_available(struct device *dev, · 284 unmodified lines | |||
| 285 | struct ad9834_state *st = iio_priv(indio_dev); | 285 | struct ad9834_state *st = iio_priv(indio_dev); |
| 286 | char *str; | 286 | char *str; |
| 287 | 287 | ||
| 288 | if ((st->devid == ID_AD9833) || (st->devid == ID_AD9837)) | 288 | if (st->devid == ID_AD9833 || st->devid == ID_AD9837) |
| 289 | str = "sine triangle square"; | 289 | str = "sine triangle square"; |
| 290 | else if (st->control & AD9834_OPBITEN) | 290 | else if (st->control & AD9834_OPBITEN) |
| 291 | str = "sine"; | 291 | str = "sine"; |
| @@ -73,6 +73,15 @@ · 72 unmodified lines | |||
| 73 | 73 | ||
| 74 | #define TIM17_OC1 "tim17_oc1" | 74 | #define TIM17_OC1 "tim17_oc1" |
| 75 | 75 | ||
| 76 | #if IS_REACHABLE(CONFIG_IIO_STM32_TIMER_TRIGGER) | ||
| 76 | bool is_stm32_timer_trigger(struct iio_trigger *trig); | 77 | bool is_stm32_timer_trigger(struct iio_trigger *trig); |
| 77 | 78 | #else | |
| 79 | static inline bool is_stm32_timer_trigger(struct iio_trigger *trig) | ||
| 80 | { | ||
| 81 | #if IS_ENABLED(CONFIG_IIO_STM32_TIMER_TRIGGER) | ||
| 82 | pr_warn_once("stm32-timer-trigger not linked in\n"); | ||
| 83 | #endif | ||
| 84 | return false; | ||
| 85 | } | ||
| 86 | #endif | ||
| 78 | #endif | 87 | #endif |