History

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

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 ...

Greg Kroah-Hartman committed 7 years ago

Commit bf402c02 parents 817de6b 447ccb447 files · +2242 −307Browse files

Unified · Split

47 files
  1. Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt +1 −0
  2. Documentation/devicetree/bindings/iio/adc/avia-hx711.txt +0 −24
  3. Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml +66 −0
  4. Documentation/devicetree/bindings/iio/adc/ti-ads8344.txt +19 −0
  5. Documentation/devicetree/bindings/iio/gyroscope/nxp,fxas21002c.txt +31 −0
  6. Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt +1 −0
  7. Documentation/devicetree/bindings/iio/pressure/bmp085.txt +0 −27
  8. Documentation/devicetree/bindings/iio/pressure/bmp085.yaml +70 −0
  9. Documentation/devicetree/bindings/iio/proximity/devantech-srf04.yaml +16 −9
  10. Documentation/devicetree/bindings/iio/st-sensors.txt +1 −0
  11. MAINTAINERS +10 −0
  12. drivers/iio/accel/Kconfig +1 −1
  13. drivers/iio/accel/bmc150-accel-core.c +1 −1
  14. drivers/iio/accel/kxcjk-1013.c +2 −1
  15. drivers/iio/accel/st_accel.h +2 −0
  16. drivers/iio/accel/st_accel_core.c +76 −0
  17. drivers/iio/accel/st_accel_i2c.c +5 −0
  18. drivers/iio/adc/Kconfig +14 −2
  19. drivers/iio/adc/Makefile +1 −0
  20. drivers/iio/adc/ad7606.c +99 −21
  21. drivers/iio/adc/ad7606.h +20 −5
  22. drivers/iio/adc/ad7606_spi.c +2 −0
  23. drivers/iio/adc/imx7d_adc.c +74 −101
  24. drivers/iio/adc/qcom-spmi-adc5.c +1 −0
  25. drivers/iio/adc/ti-ads8344.c +204 −0
  26. drivers/iio/dac/ad5758.c +18 −37
  27. drivers/iio/dummy/iio_dummy_evgen.c +4 −1
  28. drivers/iio/gyro/Kconfig +22 −0
  29. drivers/iio/gyro/Makefile +3 −0
  30. drivers/iio/gyro/fxas21002c.h +150 −0
  31. drivers/iio/gyro/fxas21002c_core.c +1004 −0
  32. drivers/iio/gyro/fxas21002c_i2c.c +69 −0
  33. drivers/iio/gyro/fxas21002c_spi.c +70 −0
  34. drivers/iio/gyro/mpu3050-core.c +1 −1
  35. drivers/iio/imu/st_lsm6dsx/Kconfig +1 −1
  36. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +2 −0
  37. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +4 −8
  38. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +82 −35
  39. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c +5 −0
  40. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c +5 −0
  41. drivers/iio/proximity/Kconfig +9 −2
  42. drivers/iio/proximity/srf04.c +29 −9
  43. drivers/iio/temperature/max31856.c +3 −0
  44. drivers/staging/iio/frequency/ad9832.c +33 −18
  45. drivers/staging/iio/frequency/ad9832.h +0 −1
  46. drivers/staging/iio/frequency/ad9834.c +1 −1
  47. include/linux/iio/timer/stm32-timer-trigger.h +10 −1
Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt+1−0
@@ -7,6 +7,7 @@ Required properties for the AD7606: · 6 unmodified lines
77 * "adi,ad7606-8"
88 * "adi,ad7606-6"
99 * "adi,ad7606-4"
10+ * "adi,ad7616"
1011 - reg: SPI chip select number for the device
1112 - spi-max-frequency: Max SPI frequency to use
1213 see: Documentation/devicetree/bindings/spi/spi-bus.txt
Documentation/devicetree/bindings/iio/adc/avia-hx711.txt+0−24
@@ -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−
Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml+66−0
@@ -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+ };
Documentation/devicetree/bindings/iio/adc/ti-ads8344.txt+19−0
@@ -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+};
Documentation/devicetree/bindings/iio/gyroscope/nxp,fxas21002c.txt+31−0
@@ -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 = <&reg_peri_3p15v>;
30+ vddio-supply = <&reg_peri_3p15v>;
31+};
Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt+1−0
@@ -10,6 +10,7 @@ Required properties: · 9 unmodified lines
1010 "st,lsm6dso"
1111 "st,asm330lhh"
1212 "st,lsm6dsox"
13+ "st,lsm6dsr"
1314 - reg: i2c address of the sensor / spi cs line
1415
1516 Optional properties:
Documentation/devicetree/bindings/iio/pressure/bmp085.txt+0−27
@@ -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−};
Documentation/devicetree/bindings/iio/pressure/bmp085.yaml+70−0
@@ -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+ };
Documentation/devicetree/bindings/iio/proximity/devantech-srf04.yaml+16−9
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 $id: http://devicetree.org/schemas/iio/proximity/devantech-srf04.yaml#
55 $schema: http://devicetree.org/meta-schemas/core.yaml#
66
7−title: Devantech SRF04 ultrasonic range finder
7+title: Devantech SRF04 and Maxbotix mb1000 ultrasonic range finder
88
99 maintainers:
1010 - Andreas Klinger <ak@it-klinger.de>
@@ -16,19 +16,28 @@ description: | · 5 unmodified lines
1616 - echo-gpio is held high by the sensor after sending ultrasonic burst
1717 until it is received once again
1818
19− Specifications about the driver can be found at:
19+ Specifications about the devices can be found at:
2020 http://www.robot-electronics.co.uk/htm/srf04tech.htm
2121
22+ http://www.maxbotix.com/documents/LV-MaxSonar-EZ_Datasheet.pdf
23+
2224 properties:
2325 compatible:
24− items:
25− - const: devantech,srf04
26+ enum:
27+ - devantech,srf04
28+ - maxbotix,mb1000
29+ - maxbotix,mb1010
30+ - maxbotix,mb1020
31+ - maxbotix,mb1030
32+ - maxbotix,mb1040
2633
2734 trig-gpios:
2835 description:
29− Definition of the GPIO for the triggering (output) This GPIO is set
30− for about 10 us by the driver to tell the device it should initiate
31− the measurement cycle.
36+ Definition of the GPIO for the triggering (output)
37+ This GPIO is set for about 10 us by the driver to tell the device it
38+ should initiate the measurement cycle.
39+ See Documentation/devicetree/bindings/gpio/gpio.txt for information
40+ on how to specify a consumer gpio.
3241 maxItems: 1
3342
3443 echo-gpios:
@@ -40,8 +49,6 @@ properties: · 5 unmodified lines
4049 trip.
4150 It needs to be an GPIO which is able to deliver an interrupt because
4251 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.
4552 maxItems: 1
4653
4754 required:
Documentation/devicetree/bindings/iio/st-sensors.txt+1−0
@@ -49,6 +49,7 @@ Accelerometers: · 48 unmodified lines
4949 - st,lis2dw12
5050 - st,lis3dhh
5151 - st,lis3de
52+- st,lis2de12
5253
5354 Gyroscopes:
5455 - st,l3g4200d-gyro
MAINTAINERS+10−0
@@ -11124,6 +11124,16 @@ F: Documentation/ABI/stable/sysfs-bus-nvmem · 11123 unmodified lines
1112411124 F: include/linux/nvmem-consumer.h
1112511125 F: include/linux/nvmem-provider.h
1112611126
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+
1112711137 NXP SGTL5000 DRIVER
1112811138 M: Fabio Estevam <festevam@gmail.com>
1112911139 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
drivers/iio/accel/Kconfig+1−1
@@ -223,7 +223,7 @@ config IIO_ST_ACCEL_3AXIS · 222 unmodified lines
223223 Say yes here to build support for STMicroelectronics accelerometers:
224224 LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC,
225225 LIS331DLH, LSM303DL, LSM303DLM, LSM330, LIS2DH12, H3LIS331DL,
226− LNG2DM, LIS3DE
226+ LNG2DM, LIS3DE, LIS2DE12
227227
228228 This driver can also be built as a module. If so, these modules
229229 will be created:
drivers/iio/accel/bmc150-accel-core.c+1−1
@@ -394,7 +394,7 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on) · 393 unmodified lines
394394
395395 if (ret < 0) {
396396 dev_err(dev,
397− "Failed: bmc150_accel_set_power_state for %d\n", on);
397+ "Failed: %s for %d\n", __func__, on);
398398 if (on)
399399 pm_runtime_put_noidle(dev);
400400
drivers/iio/accel/kxcjk-1013.c+2−1
@@ -451,7 +451,7 @@ static int kxcjk1013_set_power_state(struct kxcjk1013_data *data, bool on) · 450 unmodified lines
451451 }
452452 if (ret < 0) {
453453 dev_err(&data->client->dev,
454− "Failed: kxcjk1013_set_power_state for %d\n", on);
454+ "Failed: %s for %d\n", __func__, on);
455455 if (on)
456456 pm_runtime_put_noidle(&data->client->dev);
457457 return ret;
@@ -1491,6 +1491,7 @@ static const struct acpi_device_id kx_acpi_match[] = { · 1033 unmodified lines
14911491 {"KXCJ1013", KXCJK1013},
14921492 {"KXCJ1008", KXCJ91008},
14931493 {"KXCJ9000", KXCJ91008},
1494+ {"KIOX0008", KXCJ91008},
14941495 {"KIOX0009", KXTJ21009},
14951496 {"KIOX000A", KXCJ91008},
14961497 {"KIOX010A", KXCJ91008}, /* KXCJ91008 inside the display of a 2-in-1 */
drivers/iio/accel/st_accel.h+2−0
@@ -34,6 +34,7 @@ enum st_accel_type { · 33 unmodified lines
3434 LIS3LV02DL,
3535 LIS2DW12,
3636 LIS3DHH,
37+ LIS2DE12,
3738 ST_ACCEL_MAX,
3839 };
3940
@@ -57,6 +58,7 @@ enum st_accel_type { · 17 unmodified lines
5758 #define LIS2DW12_ACCEL_DEV_NAME "lis2dw12"
5859 #define LIS3DHH_ACCEL_DEV_NAME "lis3dhh"
5960 #define LIS3DE_ACCEL_DEV_NAME "lis3de"
61+#define LIS2DE12_ACCEL_DEV_NAME "lis2de12"
6062
6163 /**
6264 * struct st_sensors_platform_data - default accel platform data
drivers/iio/accel/st_accel_core.c+76−0
@@ -831,6 +831,82 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { · 830 unmodified lines
831831 .multi_read_bit = false,
832832 .bootime = 2,
833833 },
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+ },
834910 };
835911
836912 static int st_accel_read_raw(struct iio_dev *indio_dev,
drivers/iio/accel/st_accel_i2c.c+5−0
@@ -102,6 +102,10 @@ static const struct of_device_id st_accel_of_match[] = { · 101 unmodified lines
102102 .compatible = "st,lis3de",
103103 .data = LIS3DE_ACCEL_DEV_NAME,
104104 },
105+ {
106+ .compatible = "st,lis2de12",
107+ .data = LIS2DE12_ACCEL_DEV_NAME,
108+ },
105109 {},
106110 };
107111 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
140144 { LIS3LV02DL_ACCEL_DEV_NAME },
141145 { LIS2DW12_ACCEL_DEV_NAME },
142146 { LIS3DE_ACCEL_DEV_NAME },
147+ { LIS2DE12_ACCEL_DEV_NAME },
143148 {},
144149 };
145150 MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
drivers/iio/adc/Kconfig+14−2
@@ -553,7 +553,7 @@ config MAX1363 · 552 unmodified lines
553553 To compile this driver as a module, choose M here: the module will be
554554 called max1363.
555555
556−config MAX9611
556+config MAX9611
557557 tristate "Maxim max9611/max9612 ADC driver"
558558 depends on I2C
559559 help
@@ -821,7 +821,9 @@ config STM32_DFSDM_ADC · 261 unmodified lines
821821 depends on (ARCH_STM32 && OF) || COMPILE_TEST
822822 select STM32_DFSDM_CORE
823823 select REGMAP_MMIO
824+ select IIO_BUFFER
824825 select IIO_BUFFER_HW_CONSUMER
826+ select IIO_TRIGGERED_BUFFER
825827 help
826828 Select this option to support ADCSigma delta modulator for
827829 STMicroelectronics STM32 digital filter for sigma delta converter.
@@ -968,7 +970,7 @@ config TI_ADS1015 · 140 unmodified lines
968970
969971 config TI_ADS7950
970972 tristate "Texas Instruments ADS7950 ADC driver"
971− depends on SPI
973+ depends on SPI && GPIOLIB
972974 select IIO_BUFFER
973975 select IIO_TRIGGERED_BUFFER
974976 help
@@ -979,6 +981,16 @@ config TI_ADS7950 · 4 unmodified lines
979981 To compile this driver as a module, choose M here: the
980982 module will be called ti-ads7950.
981983
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+
982994 config TI_ADS8688
983995 tristate "Texas Instruments ADS8688"
984996 depends on SPI && OF
drivers/iio/adc/Makefile+1−0
@@ -88,6 +88,7 @@ obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o · 87 unmodified lines
8888 obj-$(CONFIG_TI_ADC161S626) += ti-adc161s626.o
8989 obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o
9090 obj-$(CONFIG_TI_ADS7950) += ti-ads7950.o
91+obj-$(CONFIG_TI_ADS8344) += ti-ads8344.o
9192 obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o
9293 obj-$(CONFIG_TI_ADS124S08) += ti-ads124s08.o
9394 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
drivers/iio/adc/ad7606.c+99−21
@@ -31,7 +31,7 @@ · 30 unmodified lines
3131 * Scales are computed as 5000/32768 and 10000/32768 respectively,
3232 * so that when applied to the raw values they provide mV values
3333 */
34−static const unsigned int scale_avail[2] = {
34+static const unsigned int ad7606_scale_avail[2] = {
3535 152588, 305176
3636 };
3737
@@ -39,6 +39,10 @@ static const unsigned int ad7606_oversampling_avail[7] = { · 1 unmodified line
3939 1, 2, 4, 8, 16, 32, 64,
4040 };
4141
42+static const unsigned int ad7616_oversampling_avail[8] = {
43+ 1, 2, 4, 8, 16, 32, 64, 128,
44+};
45+
4246 static int ad7606_reset(struct ad7606_state *st)
4347 {
4448 if (st->gpio_reset) {
@@ -154,7 +158,7 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, · 109 unmodified lines
154158 return IIO_VAL_INT;
155159 case IIO_CHAN_INFO_SCALE:
156160 *val = 0;
157− *val2 = scale_avail[st->range];
161+ *val2 = st->scale_avail[st->range];
158162 return IIO_VAL_INT_PLUS_MICRO;
159163 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
160164 *val = st->oversampling;
@@ -163,21 +167,31 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, · 2 unmodified lines
163167 return -EINVAL;
164168 }
165169
166−static ssize_t in_voltage_scale_available_show(struct device *dev,
167− struct device_attribute *attr,
168− char *buf)
170+static ssize_t ad7606_show_avail(char *buf, const unsigned int *vals,
171+ unsigned int n, bool micros)
169172 {
170− int i, len = 0;
171−
172− for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
173− len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
174− scale_avail[i]);
173+ size_t len = 0;
174+ int i;
175175
176+ for (i = 0; i < n; i++) {
177+ len += scnprintf(buf + len, PAGE_SIZE - len,
178+ micros ? "0.%06u " : "%u ", vals[i]);
179+ }
176180 buf[len - 1] = '\n';
177181
178182 return len;
179183 }
180184
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+
181195 static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0);
182196
183197 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
193207 switch (mask) {
194208 case IIO_CHAN_INFO_SCALE:
195209 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);
197211 gpiod_set_value(st->gpio_range, i);
198212 st->range = i;
199213 mutex_unlock(&st->lock);
@@ -202,15 +216,20 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, · 2 unmodified lines
202216 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
203217 if (val2)
204218 return -EINVAL;
205− i = find_closest(val, ad7606_oversampling_avail,
206− ARRAY_SIZE(ad7606_oversampling_avail));
219+ i = find_closest(val, st->oversampling_avail,
220+ st->num_os_ratios);
207221
208222 values[0] = i;
209223
210224 mutex_lock(&st->lock);
211225 gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
212226 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];
214233 mutex_unlock(&st->lock);
215234
216235 return 0;
@@ -219,11 +238,23 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, · 2 unmodified lines
219238 }
220239 }
221240
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);
223254
224255 static struct attribute *ad7606_attributes_os_and_range[] = {
225256 &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,
227258 NULL,
228259 };
229260
@@ -232,7 +263,7 @@ static const struct attribute_group ad7606_attribute_group_os_and_range = { · 2 unmodified lines
232263 };
233264
234265 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,
236267 NULL,
237268 };
238269
@@ -292,6 +323,36 @@ static const struct iio_chan_spec ad7606_channels[] = { · 53 unmodified lines
292323 AD7606_CHANNEL(7),
293324 };
294325
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+
295356 static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
296357 /* More devices added in future */
297358 [ID_AD7605_4] = {
@@ -301,17 +362,27 @@ static const struct ad7606_chip_info ad7606_chip_info_tbl[] = { · 3 unmodified lines
301362 [ID_AD7606_8] = {
302363 .channels = ad7606_channels,
303364 .num_channels = 9,
304− .has_oversampling = true,
365+ .oversampling_avail = ad7606_oversampling_avail,
366+ .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
305367 },
306368 [ID_AD7606_6] = {
307369 .channels = ad7606_channels,
308370 .num_channels = 7,
309− .has_oversampling = true,
371+ .oversampling_avail = ad7606_oversampling_avail,
372+ .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
310373 },
311374 [ID_AD7606_4] = {
312375 .channels = ad7606_channels,
313376 .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,
315386 },
316387 };
317388
@@ -343,7 +414,7 @@ static int ad7606_request_gpios(struct ad7606_state *st) · 25 unmodified lines
343414 if (IS_ERR(st->gpio_frstdata))
344415 return PTR_ERR(st->gpio_frstdata);
345416
346− if (!st->chip_info->has_oversampling)
417+ if (!st->chip_info->oversampling_num)
347418 return 0;
348419
349420 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
467538 /* tied to logic low, analog input range is +/- 5V */
468539 st->range = 0;
469540 st->oversampling = 1;
541+ st->scale_avail = ad7606_scale_avail;
542+ st->num_scales = ARRAY_SIZE(ad7606_scale_avail);
470543
471544 st->reg = devm_regulator_get(dev, "avcc");
472545 if (IS_ERR(st->reg))
@@ -484,6 +557,11 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, · 11 unmodified lines
484557
485558 st->chip_info = &ad7606_chip_info_tbl[id];
486559
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+
487565 ret = ad7606_request_gpios(st);
488566 if (ret)
489567 return ret;
drivers/iio/adc/ad7606.h+20−5
@@ -12,12 +12,17 @@ · 11 unmodified lines
1212 * struct ad7606_chip_info - chip specific information
1313 * @channels: channel specification
1414 * @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
1619 */
1720 struct ad7606_chip_info {
1821 const struct iio_chan_spec *channels;
1922 unsigned int num_channels;
20− bool has_oversampling;
23+ const unsigned int *oversampling_avail;
24+ unsigned int oversampling_num;
25+ bool os_req_reset;
2126 };
2227
2328 /**
@@ -29,6 +34,11 @@ struct ad7606_chip_info { · 5 unmodified lines
2934 * @range voltage range selection, selects which scale to apply
3035 * @oversampling oversampling selection
3136 * @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
3242 * @lock protect sensor state from concurrent accesses to GPIOs
3343 * @gpio_convst GPIO descriptor for conversion start signal (CONVST)
3444 * @gpio_reset GPIO descriptor for device hard-reset
@@ -50,6 +60,10 @@ struct ad7606_state { · 15 unmodified lines
5060 unsigned int range;
5161 unsigned int oversampling;
5262 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;
5367
5468 struct mutex lock; /* protect sensor state */
5569 struct gpio_desc *gpio_convst;
@@ -64,9 +78,9 @@ struct ad7606_state { · 8 unmodified lines
6478 /*
6579 * DMA (thus cache coherency maintenance) requires the
6680 * 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
6882 */
69− unsigned short data[12] ____cacheline_aligned;
83+ unsigned short data[20] ____cacheline_aligned;
7084 };
7185
7286 /**
@@ -86,7 +100,8 @@ enum ad7606_supported_device_ids { · 13 unmodified lines
86100 ID_AD7605_4,
87101 ID_AD7606_8,
88102 ID_AD7606_6,
89− ID_AD7606_4
103+ ID_AD7606_4,
104+ ID_AD7616,
90105 };
91106
92107 #ifdef CONFIG_PM_SLEEP
drivers/iio/adc/ad7606_spi.c+2−0
@@ -53,6 +53,7 @@ static const struct spi_device_id ad7606_id_table[] = { · 52 unmodified lines
5353 { "ad7606-4", ID_AD7606_4 },
5454 { "ad7606-6", ID_AD7606_6 },
5555 { "ad7606-8", ID_AD7606_8 },
56+ { "ad7616", ID_AD7616 },
5657 {}
5758 };
5859 MODULE_DEVICE_TABLE(spi, ad7606_id_table);
@@ -62,6 +63,7 @@ static const struct of_device_id ad7606_of_match[] = { · 3 unmodified lines
6263 { .compatible = "adi,ad7606-4" },
6364 { .compatible = "adi,ad7606-6" },
6465 { .compatible = "adi,ad7606-8" },
66+ { .compatible = "adi,ad7616" },
6567 { },
6668 };
6769 MODULE_DEVICE_TABLE(of, ad7606_of_match);
drivers/iio/adc/imx7d_adc.c+74−101
@@ -388,8 +388,9 @@ static irqreturn_t imx7d_adc_isr(int irq, void *dev_id) · 387 unmodified lines
388388 * timeout flags.
389389 */
390390 if (status & IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT) {
391− pr_err("%s: ADC got conversion time out interrupt: 0x%08x\n",
392− dev_name(info->dev), status);
391+ dev_err(info->dev,
392+ "ADC got conversion time out interrupt: 0x%08x\n",
393+ status);
393394 status &= ~IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT;
394395 writel(status, info->regs + IMX7D_REG_ADC_INT_STATUS);
395396 }
@@ -433,167 +434,139 @@ static void imx7d_adc_power_down(struct imx7d_adc *info) · 37 unmodified lines
433434 writel(adc_cfg, info->regs + IMX7D_REG_ADC_ADC_CFG);
434435 }
435436
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+
436482 static int imx7d_adc_probe(struct platform_device *pdev)
437483 {
438484 struct imx7d_adc *info;
439485 struct iio_dev *indio_dev;
440− struct resource *mem;
486+ struct device *dev = &pdev->dev;
441487 int irq;
442488 int ret;
443489
444− indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
490+ indio_dev = devm_iio_device_alloc(dev, sizeof(*info));
445491 if (!indio_dev) {
446492 dev_err(&pdev->dev, "Failed allocating iio device\n");
447493 return -ENOMEM;
448494 }
449495
450496 info = iio_priv(indio_dev);
451− info->dev = &pdev->dev;
497+ info->dev = dev;
452498
453− mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
454− info->regs = devm_ioremap_resource(&pdev->dev, mem);
499+ info->regs = devm_platform_ioremap_resource(pdev, 0);
455500 if (IS_ERR(info->regs)) {
456501 ret = PTR_ERR(info->regs);
457− dev_err(&pdev->dev,
458− "Failed to remap adc memory, err = %d\n", ret);
502+ dev_err(dev, "Failed to remap adc memory, err = %d\n", ret);
459503 return ret;
460504 }
461505
462506 irq = platform_get_irq(pdev, 0);
463507 if (irq < 0) {
464− dev_err(&pdev->dev, "No irq resource?\n");
508+ dev_err(dev, "No irq resource?\n");
465509 return irq;
466510 }
467511
468− info->clk = devm_clk_get(&pdev->dev, "adc");
512+ info->clk = devm_clk_get(dev, "adc");
469513 if (IS_ERR(info->clk)) {
470514 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);
472516 return ret;
473517 }
474518
475− info->vref = devm_regulator_get(&pdev->dev, "vref");
519+ info->vref = devm_regulator_get(dev, "vref");
476520 if (IS_ERR(info->vref)) {
477521 ret = PTR_ERR(info->vref);
478− dev_err(&pdev->dev,
522+ dev_err(dev,
479523 "Failed getting reference voltage, err = %d\n", ret);
480524 return ret;
481525 }
482526
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−
491527 platform_set_drvdata(pdev, indio_dev);
492528
493529 init_completion(&info->completion);
494530
495− indio_dev->name = dev_name(&pdev->dev);
496− indio_dev->dev.parent = &pdev->dev;
531+ indio_dev->name = dev_name(dev);
532+ indio_dev->dev.parent = dev;
497533 indio_dev->info = &imx7d_adc_iio_info;
498534 indio_dev->modes = INDIO_DIRECT_MODE;
499535 indio_dev->channels = imx7d_adc_iio_channels;
500536 indio_dev->num_channels = ARRAY_SIZE(imx7d_adc_iio_channels);
501537
502− ret = clk_prepare_enable(info->clk);
503− if (ret) {
504− dev_err(&pdev->dev,
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);
538+ ret = devm_request_irq(dev, irq,
539+ imx7d_adc_isr, 0,
540+ dev_name(dev), info);
512541 if (ret < 0) {
513− dev_err(&pdev->dev, "Failed requesting irq, irq = %d\n", irq);
514− goto error_iio_device_register;
542+ dev_err(dev, "Failed requesting irq, irq = %d\n", irq);
543+ return ret;
515544 }
516545
517546 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−}
564547
565−static int __maybe_unused imx7d_adc_resume(struct device *dev)
566−{
567− struct iio_dev *indio_dev = dev_get_drvdata(dev);
568− struct imx7d_adc *info = iio_priv(indio_dev);
569− int ret;
548+ ret = imx7d_adc_enable(&indio_dev->dev);
549+ if (ret)
550+ return ret;
570551
571− ret = regulator_enable(info->vref);
572− if (ret) {
573− dev_err(info->dev,
574− "Can't enable adc reference top voltage, err = %d\n",
575− ret);
552+ ret = devm_add_action_or_reset(dev, __imx7d_adc_disable,
553+ &indio_dev->dev);
554+ if (ret)
576555 return ret;
577− }
578556
579− ret = clk_prepare_enable(info->clk);
557+ ret = devm_iio_device_register(dev, indio_dev);
580558 if (ret) {
581− dev_err(info->dev,
582− "Could not prepare or enable clock.\n");
583− regulator_disable(info->vref);
559+ dev_err(&pdev->dev, "Couldn't register the device.\n");
584560 return ret;
585561 }
586562
587− imx7d_adc_hw_init(info);
588−
589563 return 0;
590564 }
591565
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);
593567
594568 static struct platform_driver imx7d_adc_driver = {
595569 .probe = imx7d_adc_probe,
596− .remove = imx7d_adc_remove,
597570 .driver = {
598571 .name = "imx7d_adc",
599572 .of_match_table = imx7d_adc_match,
drivers/iio/adc/qcom-spmi-adc5.c+1−0
@@ -664,6 +664,7 @@ static const struct of_device_id adc5_match_table[] = { · 663 unmodified lines
664664 },
665665 { }
666666 };
667+MODULE_DEVICE_TABLE(of, adc5_match_table);
667668
668669 static int adc5_get_dt_data(struct adc5_chip *adc, struct device_node *node)
669670 {
drivers/iio/adc/ti-ads8344.c+204−0
@@ -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");
drivers/iio/dac/ad5758.c+18−37
@@ -72,8 +72,6 @@ · 71 unmodified lines
7272 #define AD5758_DCDC_CONFIG1_DCDC_VPROG_MODE(x) (((x) & 0x1F) << 0)
7373 #define AD5758_DCDC_CONFIG1_DCDC_MODE_MSK GENMASK(6, 5)
7474 #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)
7775
7876 /* AD5758_DCDC_CONFIG2 */
7977 #define AD5758_DCDC_CONFIG2_ILIMIT_MSK GENMASK(3, 1)
@@ -84,6 +82,10 @@ · 4 unmodified lines
8482 /* AD5758_DIGITAL_DIAG_RESULTS */
8583 #define AD5758_CAL_MEM_UNREFRESHED_MSK BIT(15)
8684
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+
8789 #define AD5758_WR_FLAG_MSK(x) (0x80 | ((x) & 0x1F))
8890
8991 #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
315317 {
316318 int ret;
317319
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+
318332 ret = ad5758_spi_write_mask(st, AD5758_DCDC_CONFIG1,
319333 AD5758_DCDC_CONFIG1_DCDC_MODE_MSK,
320334 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
444458 AD5758_CAL_MEM_UNREFRESHED_MSK);
445459 }
446460
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−
464461 static int ad5758_internal_buffers_en(struct ad5758_state *st, bool enable)
465462 {
466463 int ret;
@@ -585,8 +582,8 @@ static ssize_t ad5758_write_powerdown(struct iio_dev *indio_dev, · 118 unmodified lines
585582 {
586583 struct ad5758_state *st = iio_priv(indio_dev);
587584 bool pwr_down;
588− unsigned int dcdc_config1_mode, dc_dc_mode, dac_config_mode, val;
589− unsigned long int dcdc_config1_msk, dac_config_msk;
585+ unsigned int dc_dc_mode, dac_config_mode, val;
586+ unsigned long int dac_config_msk;
590587 int ret;
591588
592589 ret = kstrtobool(buf, &pwr_down);
@@ -602,17 +599,6 @@ static ssize_t ad5758_write_powerdown(struct iio_dev *indio_dev, · 9 unmodified lines
602599 val = 1;
603600 }
604601
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−
616602 dac_config_mode = AD5758_DAC_CONFIG_OUT_EN_MODE(val) |
617603 AD5758_DAC_CONFIG_INT_EN_MODE(val);
618604 dac_config_msk = AD5758_DAC_CONFIG_OUT_EN_MSK |
@@ -841,11 +827,6 @@ static int ad5758_init(struct ad5758_state *st) · 222 unmodified lines
841827 return ret;
842828 }
843829
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−
849830 /* Power up the DAC and internal (INT) amplifiers */
850831 ret = ad5758_internal_buffers_en(st, 1);
851832 if (ret < 0)
drivers/iio/dummy/iio_dummy_evgen.c+4−1
@@ -196,7 +196,10 @@ static __init int iio_dummy_evgen_init(void) · 195 unmodified lines
196196 return ret;
197197 device_initialize(&iio_evgen_dev);
198198 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;
200203 }
201204 module_init(iio_dummy_evgen_init);
202205
drivers/iio/gyro/Kconfig+22−0
@@ -73,6 +73,28 @@ config BMG160_SPI · 72 unmodified lines
7373 tristate
7474 select REGMAP_SPI
7575
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+
7698 config HID_SENSOR_GYRO_3D
7799 depends on HID_SENSOR_HUB
78100 select IIO_BUFFER
drivers/iio/gyro/Makefile+3−0
@@ -12,6 +12,9 @@ obj-$(CONFIG_ADXRS450) += adxrs450.o · 11 unmodified lines
1212 obj-$(CONFIG_BMG160) += bmg160_core.o
1313 obj-$(CONFIG_BMG160_I2C) += bmg160_i2c.o
1414 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
1518
1619 obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o
1720
drivers/iio/gyro/fxas21002c.h+150−0
@@ -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
drivers/iio/gyro/fxas21002c_core.c+1004−0
@@ -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");
drivers/iio/gyro/fxas21002c_i2c.c+69−0
@@ -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");
drivers/iio/gyro/fxas21002c_spi.c+70−0
@@ -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");
drivers/iio/gyro/mpu3050-core.c+1−1
@@ -865,7 +865,7 @@ static int mpu3050_power_up(struct mpu3050 *mpu3050) · 864 unmodified lines
865865 dev_err(mpu3050->dev, "error setting power mode\n");
866866 return ret;
867867 }
868− msleep(10);
868+ usleep_range(10000, 20000);
869869
870870 return 0;
871871 }
drivers/iio/imu/st_lsm6dsx/Kconfig+1−1
@@ -9,7 +9,7 @@ config IIO_ST_LSM6DSX · 8 unmodified lines
99 help
1010 Say yes here to build support for STMicroelectronics LSM6DSx imu
1111 sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm,
12− ism330dlc, lsm6dso, lsm6dsox, asm330lhh
12+ ism330dlc, lsm6dso, lsm6dsox, asm330lhh, lsm6dsr
1313
1414 To compile this driver as a module, choose M here: the module
1515 will be called st_lsm6dsx.
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h+2−0
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 #define ST_LSM6DSO_DEV_NAME "lsm6dso"
2323 #define ST_ASM330LHH_DEV_NAME "asm330lhh"
2424 #define ST_LSM6DSOX_DEV_NAME "lsm6dsox"
25+#define ST_LSM6DSR_DEV_NAME "lsm6dsr"
2526
2627 enum st_lsm6dsx_hw_id {
2728 ST_LSM6DS3_ID,
@@ -32,6 +33,7 @@ enum st_lsm6dsx_hw_id { · 4 unmodified lines
3233 ST_LSM6DSO_ID,
3334 ST_ASM330LHH_ID,
3435 ST_LSM6DSOX_ID,
36+ ST_LSM6DSR_ID,
3537 ST_LSM6DSX_MAX_ID,
3638 };
3739
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c+4−8
@@ -13,9 +13,9 @@ · 12 unmodified lines
1313 * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated depending on the
1414 * value of the decimation factor and ODR set for each FIFO data set.
1515 *
16− * LSM6DSO/LSM6DSOX/ASM330LHH: The FIFO buffer can be configured to store data
17− * from gyroscope and accelerometer. Each sample is queued with a tag (1B)
18− * indicating data source (gyroscope, accelerometer, hw timer).
16+ * LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR: The FIFO buffer can be configured to
17+ * store data from gyroscope and accelerometer. Each sample is queued with
18+ * a tag (1B) indicating data source (gyroscope, accelerometer, hw timer).
1919 *
2020 * FIFO supported modes:
2121 * - BYPASS: FIFO disabled
@@ -506,7 +506,7 @@ st_lsm6dsx_push_tagged_data(struct st_lsm6dsx_hw *hw, u8 tag, · 484 unmodified lines
506506 }
507507
508508 /**
509− * st_lsm6dsx_read_tagged_fifo() - LSM6DSO/LSM6DSOX/ASM330LHH read FIFO routine
509+ * st_lsm6dsx_read_tagged_fifo() - tagged hw FIFO read routine
510510 * @hw: Pointer to instance of struct st_lsm6dsx_hw.
511511 *
512512 * 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
517517 {
518518 u16 pattern_len = hw->sip * ST_LSM6DSX_TAGGED_SAMPLE_SIZE;
519519 u16 fifo_len, fifo_diff_mask;
520− struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor;
521520 u8 iio_buff[ST_LSM6DSX_IIO_BUFF_SIZE], tag;
522521 bool reset_ts = false;
523522 int i, err, read_len;
@@ -539,9 +538,6 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw) · 15 unmodified lines
539538 if (!fifo_len)
540539 return 0;
541540
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−
545541 for (read_len = 0; read_len < fifo_len; read_len += pattern_len) {
546542 err = st_lsm6dsx_read_block(hw,
547543 ST_LSM6DSX_REG_FIFO_OUT_TAG_ADDR,
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c+82−35
@@ -23,7 +23,7 @@ · 22 unmodified lines
2323 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
2424 * - FIFO size: 4KB
2525 *
26− * - LSM6DSO/LSM6DSOX/ASM330LHH
26+ * - LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR
2727 * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416
2828 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
2929 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
@@ -62,37 +62,19 @@ · 32 unmodified lines
6262 #define ST_LSM6DSX_REG_INT2_ON_INT1_ADDR 0x13
6363 #define ST_LSM6DSX_REG_INT2_ON_INT1_MASK BIT(5)
6464
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)
6965 #define ST_LSM6DSX_REG_ACC_OUT_X_L_ADDR 0x28
7066 #define ST_LSM6DSX_REG_ACC_OUT_Y_L_ADDR 0x2a
7167 #define ST_LSM6DSX_REG_ACC_OUT_Z_L_ADDR 0x2c
7268
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)
7769 #define ST_LSM6DSX_REG_GYRO_OUT_X_L_ADDR 0x22
7870 #define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR 0x24
7971 #define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR 0x26
8072
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−
9173 static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = {
9274 [ST_LSM6DSX_ID_ACC] = {
9375 .reg = {
94− .addr = ST_LSM6DSX_REG_ACC_ODR_ADDR,
95− .mask = ST_LSM6DSX_REG_ACC_ODR_MASK,
76+ .addr = 0x10,
77+ .mask = GENMASK(7, 4),
9678 },
9779 .odr_avl[0] = { 13, 0x01 },
9880 .odr_avl[1] = { 26, 0x02 },
@@ -103,8 +85,8 @@ static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = { · 4 unmodified lines
10385 },
10486 [ST_LSM6DSX_ID_GYRO] = {
10587 .reg = {
106− .addr = ST_LSM6DSX_REG_GYRO_ODR_ADDR,
107− .mask = ST_LSM6DSX_REG_GYRO_ODR_MASK,
88+ .addr = 0x11,
89+ .mask = GENMASK(7, 4),
10890 },
10991 .odr_avl[0] = { 13, 0x01 },
11092 .odr_avl[1] = { 26, 0x02 },
@@ -118,23 +100,23 @@ static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = { · 7 unmodified lines
118100 static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = {
119101 [ST_LSM6DSX_ID_ACC] = {
120102 .reg = {
121− .addr = ST_LSM6DSX_REG_ACC_FS_ADDR,
122− .mask = ST_LSM6DSX_REG_ACC_FS_MASK,
103+ .addr = 0x10,
104+ .mask = GENMASK(3, 2),
123105 },
124− .fs_avl[0] = { ST_LSM6DSX_ACC_FS_2G_GAIN, 0x0 },
125− .fs_avl[1] = { ST_LSM6DSX_ACC_FS_4G_GAIN, 0x2 },
126− .fs_avl[2] = { ST_LSM6DSX_ACC_FS_8G_GAIN, 0x3 },
127− .fs_avl[3] = { ST_LSM6DSX_ACC_FS_16G_GAIN, 0x1 },
106+ .fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 },
107+ .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
108+ .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
109+ .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
128110 },
129111 [ST_LSM6DSX_ID_GYRO] = {
130112 .reg = {
131− .addr = ST_LSM6DSX_REG_GYRO_FS_ADDR,
132− .mask = ST_LSM6DSX_REG_GYRO_FS_MASK,
113+ .addr = 0x11,
114+ .mask = GENMASK(3, 2),
133115 },
134− .fs_avl[0] = { ST_LSM6DSX_GYRO_FS_245_GAIN, 0x0 },
135− .fs_avl[1] = { ST_LSM6DSX_GYRO_FS_500_GAIN, 0x1 },
136− .fs_avl[2] = { ST_LSM6DSX_GYRO_FS_1000_GAIN, 0x2 },
137− .fs_avl[3] = { ST_LSM6DSX_GYRO_FS_2000_GAIN, 0x3 },
116+ .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 },
117+ .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
118+ .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
119+ .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
138120 }
139121 };
140122
@@ -387,6 +369,71 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { · 246 unmodified lines
387369 },
388370 },
389371 },
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+ },
390437 };
391438
392439 static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c+5−0
@@ -73,6 +73,10 @@ static const struct of_device_id st_lsm6dsx_i2c_of_match[] = { · 72 unmodified lines
7373 .compatible = "st,lsm6dsox",
7474 .data = (void *)ST_LSM6DSOX_ID,
7575 },
76+ {
77+ .compatible = "st,lsm6dsr",
78+ .data = (void *)ST_LSM6DSR_ID,
79+ },
7680 {},
7781 };
7882 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
8690 { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID },
8791 { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID },
8892 { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID },
93+ { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID },
8994 {},
9095 };
9196 MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c+5−0
@@ -73,6 +73,10 @@ static const struct of_device_id st_lsm6dsx_spi_of_match[] = { · 72 unmodified lines
7373 .compatible = "st,lsm6dsox",
7474 .data = (void *)ST_LSM6DSOX_ID,
7575 },
76+ {
77+ .compatible = "st,lsm6dsr",
78+ .data = (void *)ST_LSM6DSR_ID,
79+ },
7680 {},
7781 };
7882 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
8690 { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID },
8791 { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID },
8892 { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID },
93+ { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID },
8994 {},
9095 };
9196 MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
drivers/iio/proximity/Kconfig+9−2
@@ -68,12 +68,19 @@ config RFD77402 · 67 unmodified lines
6868 module will be called rfd77402.
6969
7070 config SRF04
71− tristate "Devantech SRF04 ultrasonic ranger sensor"
71+ tristate "GPIO bitbanged ultrasonic ranger sensor (SRF04, MB1000)"
7272 depends on GPIOLIB
7373 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
7575 ranger sensor. This driver can be used to measure the distance
7676 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
7784
7885 To compile this driver as a module, choose M here: the
7986 module will be called srf04.
drivers/iio/proximity/srf04.c+29−9
@@ -23,7 +23,7 @@ · 22 unmodified lines
2323 * trig: --+ +------------------------------------------------------
2424 * ^ ^
2525 * |<->|
26− * udelay(10)
26+ * udelay(trigger_pulse_us)
2727 *
2828 * ultra +-+ +-+ +-+
2929 * sonic | | | | | |
@@ -48,6 +48,7 @@ · 18 unmodified lines
4848 #include <linux/kernel.h>
4949 #include <linux/module.h>
5050 #include <linux/of.h>
51+#include <linux/of_device.h>
5152 #include <linux/platform_device.h>
5253 #include <linux/property.h>
5354 #include <linux/sched.h>
@@ -56,6 +57,10 @@ · 2 unmodified lines
5657 #include <linux/iio/iio.h>
5758 #include <linux/iio/sysfs.h>
5859
60+struct srf04_cfg {
61+ unsigned long trigger_pulse_us;
62+};
63+
5964 struct srf04_data {
6065 struct device *dev;
6166 struct gpio_desc *gpiod_trig;
@@ -66,6 +71,15 @@ struct srf04_data { · 4 unmodified lines
6671 ktime_t ts_falling;
6772 struct completion rising;
6873 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,
6983 };
7084
7185 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
102116 reinit_completion(&data->falling);
103117
104118 gpiod_set_value(data->gpiod_trig, 1);
105− udelay(10);
119+ udelay(data->cfg->trigger_pulse_us);
106120 gpiod_set_value(data->gpiod_trig, 0);
107121
108122 /* it cannot take more than 20 ms */
@@ -215,6 +229,18 @@ static const struct iio_chan_spec srf04_chan_spec[] = { · 106 unmodified lines
215229 },
216230 };
217231
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+
218244 static int srf04_probe(struct platform_device *pdev)
219245 {
220246 struct device *dev = &pdev->dev;
@@ -230,6 +256,7 @@ static int srf04_probe(struct platform_device *pdev) · 9 unmodified lines
230256
231257 data = iio_priv(indio_dev);
232258 data->dev = dev;
259+ data->cfg = of_match_device(of_srf04_match, dev)->data;
233260
234261 mutex_init(&data->lock);
235262 init_completion(&data->rising);
@@ -280,13 +307,6 @@ static int srf04_probe(struct platform_device *pdev) · 44 unmodified lines
280307 return devm_iio_device_register(dev, indio_dev);
281308 }
282309
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−
290310 static struct platform_driver srf04_driver = {
291311 .probe = srf04_probe,
292312 .driver = {
drivers/iio/temperature/max31856.c+3−0
@@ -210,6 +210,9 @@ static int max31856_read_raw(struct iio_dev *indio_dev, · 209 unmodified lines
210210 return IIO_VAL_INT_PLUS_MICRO;
211211 }
212212 break;
213+ default:
214+ ret = -EINVAL;
215+ break;
213216 }
214217
215218 return ret;
drivers/staging/iio/frequency/ad9832.c+33−18
@@ -5,22 +5,25 @@ · 4 unmodified lines
55 * Copyright 2011 Analog Devices Inc.
66 */
77
8+#include <asm/div64.h>
9+
10+#include <linux/clk.h>
811 #include <linux/device.h>
12+#include <linux/err.h>
913 #include <linux/kernel.h>
14+#include <linux/module.h>
15+#include <linux/regulator/consumer.h>
1016 #include <linux/slab.h>
11−#include <linux/sysfs.h>
1217 #include <linux/spi/spi.h>
13−#include <linux/regulator/consumer.h>
14−#include <linux/err.h>
15−#include <linux/module.h>
16−#include <asm/div64.h>
18+#include <linux/sysfs.h>
1719
1820 #include <linux/iio/iio.h>
1921 #include <linux/iio/sysfs.h>
20−#include "dds.h"
2122
2223 #include "ad9832.h"
2324
25+#include "dds.h"
26+
2427 /* Registers */
2528
2629 #define AD9832_FREQ0LL 0x0
@@ -93,7 +96,7 @@ struct ad9832_state { · 66 unmodified lines
9396 struct spi_device *spi;
9497 struct regulator *avdd;
9598 struct regulator *dvdd;
96− unsigned long mclk;
99+ struct clk *mclk;
97100 unsigned short ctrl_fp;
98101 unsigned short ctrl_ss;
99102 unsigned short ctrl_src;
@@ -128,10 +131,10 @@ static int ad9832_write_frequency(struct ad9832_state *st, · 28 unmodified lines
128131 {
129132 unsigned long regval;
130133
131− if (fout > (st->mclk / 2))
134+ if (fout > (clk_get_rate(st->mclk) / 2))
132135 return -EINVAL;
133136
134− regval = ad9832_calc_freqreg(st->mclk, fout);
137+ regval = ad9832_calc_freqreg(clk_get_rate(st->mclk), fout);
135138
136139 st->freq_data[0] = cpu_to_be16((AD9832_CMD_FRE8BITSW << CMD_SHIFT) |
137140 (addr << ADD_SHIFT) |
@@ -332,7 +335,16 @@ static int ad9832_probe(struct spi_device *spi) · 194 unmodified lines
332335 goto error_disable_avdd;
333336 }
334337
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+
336348 st->spi = spi;
337349 mutex_init(&st->lock);
338350
@@ -383,39 +395,41 @@ static int ad9832_probe(struct spi_device *spi) · 44 unmodified lines
383395 ret = spi_sync(st->spi, &st->msg);
384396 if (ret) {
385397 dev_err(&spi->dev, "device init failed\n");
386− goto error_disable_dvdd;
398+ goto error_unprepare_mclk;
387399 }
388400
389401 ret = ad9832_write_frequency(st, AD9832_FREQ0HM, pdata->freq0);
390402 if (ret)
391− goto error_disable_dvdd;
403+ goto error_unprepare_mclk;
392404
393405 ret = ad9832_write_frequency(st, AD9832_FREQ1HM, pdata->freq1);
394406 if (ret)
395− goto error_disable_dvdd;
407+ goto error_unprepare_mclk;
396408
397409 ret = ad9832_write_phase(st, AD9832_PHASE0H, pdata->phase0);
398410 if (ret)
399− goto error_disable_dvdd;
411+ goto error_unprepare_mclk;
400412
401413 ret = ad9832_write_phase(st, AD9832_PHASE1H, pdata->phase1);
402414 if (ret)
403− goto error_disable_dvdd;
415+ goto error_unprepare_mclk;
404416
405417 ret = ad9832_write_phase(st, AD9832_PHASE2H, pdata->phase2);
406418 if (ret)
407− goto error_disable_dvdd;
419+ goto error_unprepare_mclk;
408420
409421 ret = ad9832_write_phase(st, AD9832_PHASE3H, pdata->phase3);
410422 if (ret)
411− goto error_disable_dvdd;
423+ goto error_unprepare_mclk;
412424
413425 ret = iio_device_register(indio_dev);
414426 if (ret)
415− goto error_disable_dvdd;
427+ goto error_unprepare_mclk;
416428
417429 return 0;
418430
431+error_unprepare_mclk:
432+ clk_disable_unprepare(st->mclk);
419433 error_disable_dvdd:
420434 regulator_disable(st->dvdd);
421435 error_disable_avdd:
@@ -430,6 +444,7 @@ static int ad9832_remove(struct spi_device *spi) · 8 unmodified lines
430444 struct ad9832_state *st = iio_priv(indio_dev);
431445
432446 iio_device_unregister(indio_dev);
447+ clk_disable_unprepare(st->mclk);
433448 regulator_disable(st->dvdd);
434449 regulator_disable(st->avdd);
435450
drivers/staging/iio/frequency/ad9832.h+0−1
@@ -23,7 +23,6 @@ · 22 unmodified lines
2323 */
2424
2525 struct ad9832_platform_data {
26− unsigned long mclk;
2726 unsigned long freq0;
2827 unsigned long freq1;
2928 unsigned short phase0;
drivers/staging/iio/frequency/ad9834.c+1−1
@@ -285,7 +285,7 @@ ssize_t ad9834_show_out0_wavetype_available(struct device *dev, · 284 unmodified lines
285285 struct ad9834_state *st = iio_priv(indio_dev);
286286 char *str;
287287
288− if ((st->devid == ID_AD9833) || (st->devid == ID_AD9837))
288+ if (st->devid == ID_AD9833 || st->devid == ID_AD9837)
289289 str = "sine triangle square";
290290 else if (st->control & AD9834_OPBITEN)
291291 str = "sine";
include/linux/iio/timer/stm32-timer-trigger.h+10−1
@@ -73,6 +73,15 @@ · 72 unmodified lines
7373
7474 #define TIM17_OC1 "tim17_oc1"
7575
76+#if IS_REACHABLE(CONFIG_IIO_STM32_TIMER_TRIGGER)
7677 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
7887 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

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

Repository code

Go to file
t