History

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

Jonathan writes: First round of new IIO device support, features and cleanups for the 4.6 cycle. Device Support * ad5761 - new driver * at91_sama5d2 ADC. - new driver and MAINTAINERS entry. - minor cleanups followed. * atlas pH-SM - new driver (this has possibly the prettiest data sheet I've ever seen) * mcp3422 - mcp3425 ADC added. * mcp4725 - mcp4726 DAC added. * mma8452 - mma8451q accelerometer added. * mpl115 - mpl115a1 added (a lot bigger than it seems as this is an SPI part whereas previous parts were i2c). * si7005 - Hoperf th02 (seems to be a repackaged part) * si7020 - Hoperf th06 (seems to be a repackaged part) New features * Core - IIO_PH type. Does what it says on the tin. * max30100 - LED current configuration support. * mcp320x - more differential measurement combinations. * mma8452 - free fall deteciton - opt3001 - enable operation without a IRQ line. - device tree docs. Somehow the original docs have disappeared down a rabbit hole, so here is a new set. * st-sensors - Support active-low interrupts. Cleanups and minor / not so minor reworks * Documentation - drop some defunct ABI from the docs in staging. * presure / Kconfig - white space cleanup. * ad7150 - BIT macro usage - Alignment fixes * ad7192 - false indent fixed. * ak8975 - constify the ak_def structures * axp288 - drop a redundant double const. * dht11 - substantial reliability improvements by being more tolerant of missing start bits. - simplify the decoding algorithm * mma8452 - whitespace cleanup * mpl115 - don't bother setting i2c_client_data as nothing uses it. * mpu6050 - drop unused function parameter. * opt3001 - extract integration time as constants. - trivial refactoring.

Greg Kroah-Hartman committed 10 years ago

Commit fec2f332 parents 4cff7ad ea4570d53 files · +2531 −265Browse files

Unified · Split

53 files
  1. CREDITS +1 −0
  2. Documentation/ABI/testing/sysfs-bus-iio +9 −0
  3. Documentation/devicetree/bindings/iio/accel/mma8452.txt +3 −1
  4. Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt +28 −0
  5. Documentation/devicetree/bindings/iio/adc/mcp3422.txt +1 −0
  6. Documentation/devicetree/bindings/iio/chemical/atlas,ph-sm.txt +22 −0
  7. Documentation/devicetree/bindings/iio/health/max30100.txt +8 −0
  8. Documentation/devicetree/bindings/iio/light/opt3001.txt +26 −0
  9. Documentation/devicetree/bindings/vendor-prefixes.txt +1 −0
  10. MAINTAINERS +6 −0
  11. drivers/iio/accel/Kconfig +1 −1
  12. drivers/iio/accel/mma8452.c +182 −24
  13. drivers/iio/accel/st_accel_core.c +16 −0
  14. drivers/iio/adc/Kconfig +13 −3
  15. drivers/iio/adc/Makefile +1 −0
  16. drivers/iio/adc/at91-sama5d2_adc.c +508 −0
  17. drivers/iio/adc/axp288_adc.c +1 −1
  18. drivers/iio/adc/mcp320x.c +19 −12
  19. drivers/iio/adc/mcp3422.c +5 −2
  20. drivers/iio/chemical/Kconfig +13 −0
  21. drivers/iio/chemical/Makefile +1 −0
  22. drivers/iio/chemical/atlas-ph-sensor.c +511 −0
  23. drivers/iio/common/st_sensors/st_sensors_core.c +4 −2
  24. drivers/iio/common/st_sensors/st_sensors_core.h +8 −0
  25. drivers/iio/common/st_sensors/st_sensors_trigger.c +42 −10
  26. drivers/iio/dac/Kconfig +12 −2
  27. drivers/iio/dac/Makefile +1 −0
  28. drivers/iio/dac/ad5761.c +430 −0
  29. drivers/iio/dac/mcp4725.c +67 −20
  30. drivers/iio/gyro/st_gyro_core.c +15 −0
  31. drivers/iio/health/max30100.c +75 −6
  32. drivers/iio/humidity/Kconfig +4 −2
  33. drivers/iio/humidity/dht11.c +50 −27
  34. drivers/iio/humidity/si7005.c +1 −0
  35. drivers/iio/humidity/si7020.c +1 −0
  36. drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +2 −3
  37. drivers/iio/industrialio-core.c +1 −0
  38. drivers/iio/light/opt3001.c +106 −50
  39. drivers/iio/magnetometer/ak8975.c +2 −2
  40. drivers/iio/magnetometer/st_magn_core.c +4 −0
  41. drivers/iio/pressure/Kconfig +28 −13
  42. drivers/iio/pressure/Makefile +2 −0
  43. drivers/iio/pressure/mpl115.c +27 −39
  44. drivers/iio/pressure/mpl115.h +24 −0
  45. drivers/iio/pressure/mpl115_i2c.c +67 −0
  46. drivers/iio/pressure/mpl115_spi.c +106 −0
  47. drivers/iio/pressure/st_pressure_core.c +8 −0
  48. drivers/staging/iio/Documentation/sysfs-bus-iio-light +0 −28
  49. drivers/staging/iio/adc/ad7192.c +1 −1
  50. drivers/staging/iio/cdc/ad7150.c +18 −16
  51. include/linux/iio/common/st_sensors.h +4 −0
  52. include/linux/platform_data/ad5761.h +44 −0
  53. include/uapi/linux/iio/types.h +1 −0
CREDITS+1−0
@@ -3054,6 +3054,7 @@ D: PLX USB338x driver · 3053 unmodified lines
3054D: PCA9634 driver3054D: PCA9634 driver
3055D: Option GTM671WFS3055D: Option GTM671WFS
3056D: Fintek F81216A3056D: Fintek F81216A
3057D: AD5761 iio driver
3057D: Various kernel hacks3058D: Various kernel hacks
3058S: Qtechnology A/S3059S: Qtechnology A/S
3059S: Valby Langgade 1423060S: Valby Langgade 142
Documentation/ABI/testing/sysfs-bus-iio+9−0
@@ -497,7 +497,9 @@ Description: · 496 unmodified lines
497 6kohm_to_gnd: connected to ground via a 6kOhm resistor,497 6kohm_to_gnd: connected to ground via a 6kOhm resistor,
498 20kohm_to_gnd: connected to ground via a 20kOhm resistor,498 20kohm_to_gnd: connected to ground via a 20kOhm resistor,
499 100kohm_to_gnd: connected to ground via an 100kOhm resistor,499 100kohm_to_gnd: connected to ground via an 100kOhm resistor,
500 125kohm_to_gnd: connected to ground via an 125kOhm resistor,
500 500kohm_to_gnd: connected to ground via a 500kOhm resistor,501 500kohm_to_gnd: connected to ground via a 500kOhm resistor,
502 640kohm_to_gnd: connected to ground via a 640kOhm resistor,
501 three_state: left floating.503 three_state: left floating.
502 For a list of available output power down options read504 For a list of available output power down options read
503 outX_powerdown_mode_available. If Y is not present the505 outX_powerdown_mode_available. If Y is not present the
@@ -1491,3 +1493,10 @@ Description: · 987 unmodified lines
1491 This ABI is especially applicable for humidity sensors1493 This ABI is especially applicable for humidity sensors
1492 to heatup the device and get rid of any condensation1494 to heatup the device and get rid of any condensation
1493 in some humidity environment1495 in some humidity environment
1496
1497What: /sys/bus/iio/devices/iio:deviceX/in_ph_raw
1498KernelVersion: 4.5
1499Contact: linux-iio@vger.kernel.org
1500Description:
1501 Raw (unscaled no offset etc.) pH reading of a substance as a negative
1502 base-10 logarithm of hydrodium ions in a litre of water.
Documentation/devicetree/bindings/iio/accel/mma8452.txt+3−1
@@ -1,8 +1,10 @@
1Freescale MMA8452Q, MMA8453Q, MMA8652FC or MMA8653FC triaxial accelerometer1Freescale MMA8451Q, MMA8452Q, MMA8453Q, MMA8652FC or MMA8653FC
2triaxial accelerometer
2 3
3Required properties:4Required properties:
4 5
5 - compatible: should contain one of6 - compatible: should contain one of
7 * "fsl,mma8451"
6 * "fsl,mma8452"8 * "fsl,mma8452"
7 * "fsl,mma8453"9 * "fsl,mma8453"
8 * "fsl,mma8652"10 * "fsl,mma8652"
Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt+28−0
@@ -0,0 +1,28 @@
1* AT91 SAMA5D2 Analog to Digital Converter (ADC)
2
3Required properties:
4 - compatible: Should be "atmel,sama5d2-adc".
5 - reg: Should contain ADC registers location and length.
6 - interrupts: Should contain the IRQ line for the ADC.
7 - clocks: phandle to device clock.
8 - clock-names: Must be "adc_clk".
9 - vref-supply: Supply used as reference for conversions.
10 - vddana-supply: Supply for the adc device.
11 - atmel,min-sample-rate-hz: Minimum sampling rate, it depends on SoC.
12 - atmel,max-sample-rate-hz: Maximum sampling rate, it depends on SoC.
13 - atmel,startup-time-ms: Startup time expressed in ms, it depends on SoC.
14
15Example:
16
17adc: adc@fc030000 {
18 compatible = "atmel,sama5d2-adc";
19 reg = <0xfc030000 0x100>;
20 interrupts = <40 IRQ_TYPE_LEVEL_HIGH 7>;
21 clocks = <&adc_clk>;
22 clock-names = "adc_clk";
23 atmel,min-sample-rate-hz = <200000>;
24 atmel,max-sample-rate-hz = <20000000>;
25 atmel,startup-time-ms = <4>;
26 vddana-supply = <&vdd_3v3_lp_reg>;
27 vref-supply = <&vdd_3v3_lp_reg>;
28}
Documentation/devicetree/bindings/iio/adc/mcp3422.txt+1−0
@@ -6,6 +6,7 @@ Required properties: · 5 unmodified lines
6 "microchip,mcp3422" or6 "microchip,mcp3422" or
7 "microchip,mcp3423" or7 "microchip,mcp3423" or
8 "microchip,mcp3424" or8 "microchip,mcp3424" or
9 "microchip,mcp3425" or
9 "microchip,mcp3426" or10 "microchip,mcp3426" or
10 "microchip,mcp3427" or11 "microchip,mcp3427" or
11 "microchip,mcp3428"12 "microchip,mcp3428"
Documentation/devicetree/bindings/iio/chemical/atlas,ph-sm.txt+22−0
@@ -0,0 +1,22 @@
1* Atlas Scientific pH-SM OEM sensor
2
3http://www.atlas-scientific.com/_files/_datasheets/_oem/pH_oem_datasheet.pdf
4
5Required properties:
6
7 - compatible: must be "atlas,ph-sm"
8 - reg: the I2C address of the sensor
9 - interrupt-parent: should be the phandle for the interrupt controller
10 - interrupts: the sole interrupt generated by the device
11
12 Refer to interrupt-controller/interrupts.txt for generic interrupt client
13 node bindings.
14
15Example:
16
17atlas@65 {
18 compatible = "atlas,ph-sm";
19 reg = <0x65>;
20 interrupt-parent = <&gpio1>;
21 interrupts = <16 2>;
22};
Documentation/devicetree/bindings/iio/health/max30100.txt+8−0
@@ -11,11 +11,19 @@ Required properties: · 10 unmodified lines
11 Refer to interrupt-controller/interrupts.txt for generic11 Refer to interrupt-controller/interrupts.txt for generic
12 interrupt client node bindings.12 interrupt client node bindings.
13 13
14Optional properties:
15 - maxim,led-current-microamp: configuration for LED current in microamperes
16 while the engine is running. First indexed value is the configuration for
17 the RED LED, and second value is for the IR LED.
18
19 Refer to the datasheet for the allowed current values.
20
14Example:21Example:
15 22
16max30100@057 {23max30100@057 {
17 compatible = "maxim,max30100";24 compatible = "maxim,max30100";
18 reg = <57>;25 reg = <57>;
26 maxim,led-current-microamp = <24000 50000>;
19 interrupt-parent = <&gpio1>;27 interrupt-parent = <&gpio1>;
20 interrupts = <16 2>;28 interrupts = <16 2>;
21};29};
Documentation/devicetree/bindings/iio/light/opt3001.txt+26−0
@@ -0,0 +1,26 @@
1* Texas Instruments OPT3001 Ambient Light Sensor
2
3The driver supports interrupt-driven and interrupt-less operation, depending
4on whether an interrupt property has been populated into the DT. Note that
5the optional generation of IIO events on rising/falling light threshold changes
6requires the use of interrupts. Without interrupts, only the simple reading
7of the current light value is supported through the IIO API.
8
9http://www.ti.com/product/opt3001
10
11Required properties:
12 - compatible: should be "ti,opt3001"
13 - reg: the I2C address of the sensor
14
15Optional properties:
16 - interrupt-parent: should be the phandle for the interrupt controller
17 - interrupts: interrupt mapping for GPIO IRQ (configure for falling edge)
18
19Example:
20
21opt3001@44 {
22 compatible = "ti,opt3001";
23 reg = <0x44>;
24 interrupt-parent = <&gpio1>;
25 interrupts = <28 IRQ_TYPE_EDGE_FALLING>;
26};
Documentation/devicetree/bindings/vendor-prefixes.txt+1−0
@@ -28,6 +28,7 @@ arm ARM Ltd. · 27 unmodified lines
28armadeus ARMadeus Systems SARL28armadeus ARMadeus Systems SARL
29artesyn Artesyn Embedded Technologies Inc.29artesyn Artesyn Embedded Technologies Inc.
30asahi-kasei Asahi Kasei Corp.30asahi-kasei Asahi Kasei Corp.
31atlas Atlas Scientific LLC
31atmel Atmel Corporation32atmel Atmel Corporation
32auo AU Optronics Corporation33auo AU Optronics Corporation
33avago Avago Technologies34avago Avago Technologies
MAINTAINERS+6−0
@@ -1945,6 +1945,12 @@ M: Nicolas Ferre <nicolas.ferre@atmel.com> · 1944 unmodified lines
1945S: Supported1945S: Supported
1946F: drivers/tty/serial/atmel_serial.c1946F: drivers/tty/serial/atmel_serial.c
1947 1947
1948ATMEL SAMA5D2 ADC DRIVER
1949M: Ludovic Desroches <ludovic.desroches@atmel.com>
1950L: linux-iio@vger.kernel.org
1951S: Supported
1952F: drivers/iio/adc/at91-sama5d2_adc.c
1953
1948ATMEL Audio ALSA driver1954ATMEL Audio ALSA driver
1949M: Nicolas Ferre <nicolas.ferre@atmel.com>1955M: Nicolas Ferre <nicolas.ferre@atmel.com>
1950L: alsa-devel@alsa-project.org (moderated for non-subscribers)1956L: alsa-devel@alsa-project.org (moderated for non-subscribers)
drivers/iio/accel/Kconfig+1−1
@@ -143,7 +143,7 @@ config MMA8452 · 142 unmodified lines
143 select IIO_TRIGGERED_BUFFER143 select IIO_TRIGGERED_BUFFER
144 help144 help
145 Say yes here to build support for the following Freescale 3-axis145 Say yes here to build support for the following Freescale 3-axis
146 accelerometers: MMA8452Q, MMA8453Q, MMA8652FC, MMA8653FC.146 accelerometers: MMA8451Q, MMA8452Q, MMA8453Q, MMA8652FC, MMA8653FC.
147 147
148 To compile this driver as a module, choose M here: the module148 To compile this driver as a module, choose M here: the module
149 will be called mma8452.149 will be called mma8452.
drivers/iio/accel/mma8452.c+182−24
@@ -1,6 +1,7 @@
1/*1/*
2 * mma8452.c - Support for following Freescale 3-axis accelerometers:2 * mma8452.c - Support for following Freescale 3-axis accelerometers:
3 *3 *
4 * MMA8451Q (14 bit)
4 * MMA8452Q (12 bit)5 * MMA8452Q (12 bit)
5 * MMA8453Q (10 bit)6 * MMA8453Q (10 bit)
6 * MMA8652FC (12 bit)7 * MMA8652FC (12 bit)
@@ -15,7 +16,7 @@ · 8 unmodified lines
15 *16 *
16 * 7-bit I2C slave address 0x1c/0x1d (pin selectable)17 * 7-bit I2C slave address 0x1c/0x1d (pin selectable)
17 *18 *
18 * TODO: orientation / freefall events, autosleep19 * TODO: orientation events, autosleep
19 */20 */
20 21
21#include <linux/module.h>22#include <linux/module.h>
@@ -85,8 +86,9 @@ · 63 unmodified lines
85#define MMA8452_INT_FF_MT BIT(2)86#define MMA8452_INT_FF_MT BIT(2)
86#define MMA8452_INT_TRANS BIT(5)87#define MMA8452_INT_TRANS BIT(5)
87 88
88#define MMA8452_DEVICE_ID 0x2a89#define MMA8451_DEVICE_ID 0x1a
89#define MMA8453_DEVICE_ID 0x3a90#define MMA8452_DEVICE_ID 0x2a
91#define MMA8453_DEVICE_ID 0x3a
90#define MMA8652_DEVICE_ID 0x4a92#define MMA8652_DEVICE_ID 0x4a
91#define MMA8653_DEVICE_ID 0x5a93#define MMA8653_DEVICE_ID 0x5a
92 94
@@ -416,6 +418,51 @@ fail: · 323 unmodified lines
416 return ret;418 return ret;
417}419}
418 420
421/* returns >0 if in freefall mode, 0 if not or <0 if an error occured */
422static int mma8452_freefall_mode_enabled(struct mma8452_data *data)
423{
424 int val;
425 const struct mma_chip_info *chip = data->chip_info;
426
427 val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg);
428 if (val < 0)
429 return val;
430
431 return !(val & MMA8452_FF_MT_CFG_OAE);
432}
433
434static int mma8452_set_freefall_mode(struct mma8452_data *data, bool state)
435{
436 int val;
437 const struct mma_chip_info *chip = data->chip_info;
438
439 if ((state && mma8452_freefall_mode_enabled(data)) ||
440 (!state && !(mma8452_freefall_mode_enabled(data))))
441 return 0;
442
443 val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg);
444 if (val < 0)
445 return val;
446
447 if (state) {
448 val |= BIT(idx_x + chip->ev_cfg_chan_shift);
449 val |= BIT(idx_y + chip->ev_cfg_chan_shift);
450 val |= BIT(idx_z + chip->ev_cfg_chan_shift);
451 val &= ~MMA8452_FF_MT_CFG_OAE;
452 } else {
453 val &= ~BIT(idx_x + chip->ev_cfg_chan_shift);
454 val &= ~BIT(idx_y + chip->ev_cfg_chan_shift);
455 val &= ~BIT(idx_z + chip->ev_cfg_chan_shift);
456 val |= MMA8452_FF_MT_CFG_OAE;
457 }
458
459 val = mma8452_change_config(data, chip->ev_cfg, val);
460 if (val)
461 return val;
462
463 return 0;
464}
465
419static int mma8452_set_hp_filter_frequency(struct mma8452_data *data,466static int mma8452_set_hp_filter_frequency(struct mma8452_data *data,
420 int val, int val2)467 int val, int val2)
421{468{
@@ -609,12 +656,22 @@ static int mma8452_read_event_config(struct iio_dev *indio_dev, · 187 unmodified lines
609 const struct mma_chip_info *chip = data->chip_info;656 const struct mma_chip_info *chip = data->chip_info;
610 int ret;657 int ret;
611 658
612 ret = i2c_smbus_read_byte_data(data->client,659 switch (dir) {
613 data->chip_info->ev_cfg);660 case IIO_EV_DIR_FALLING:
614 if (ret < 0)661 return mma8452_freefall_mode_enabled(data);
615 return ret;662 case IIO_EV_DIR_RISING:
663 if (mma8452_freefall_mode_enabled(data))
664 return 0;
665
666 ret = i2c_smbus_read_byte_data(data->client,
667 data->chip_info->ev_cfg);
668 if (ret < 0)
669 return ret;
616 670
617 return !!(ret & BIT(chan->scan_index + chip->ev_cfg_chan_shift));671 return !!(ret & BIT(chan->scan_index + chip->ev_cfg_chan_shift));
672 default:
673 return -EINVAL;
674 }
618}675}
619 676
620static int mma8452_write_event_config(struct iio_dev *indio_dev,677static int mma8452_write_event_config(struct iio_dev *indio_dev,
@@ -627,19 +684,35 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev, · 6 unmodified lines
627 const struct mma_chip_info *chip = data->chip_info;684 const struct mma_chip_info *chip = data->chip_info;
628 int val;685 int val;
629 686
630 val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg);687 switch (dir) {
631 if (val < 0)688 case IIO_EV_DIR_FALLING:
632 return val;689 return mma8452_set_freefall_mode(data, state);
690 case IIO_EV_DIR_RISING:
691 val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg);
692 if (val < 0)
693 return val;
694
695 if (state) {
696 if (mma8452_freefall_mode_enabled(data)) {
697 val &= ~BIT(idx_x + chip->ev_cfg_chan_shift);
698 val &= ~BIT(idx_y + chip->ev_cfg_chan_shift);
699 val &= ~BIT(idx_z + chip->ev_cfg_chan_shift);
700 val |= MMA8452_FF_MT_CFG_OAE;
701 }
702 val |= BIT(chan->scan_index + chip->ev_cfg_chan_shift);
703 } else {
704 if (mma8452_freefall_mode_enabled(data))
705 return 0;
633 706
634 if (state)707 val &= ~BIT(chan->scan_index + chip->ev_cfg_chan_shift);
635 val |= BIT(chan->scan_index + chip->ev_cfg_chan_shift);708 }
636 else
637 val &= ~BIT(chan->scan_index + chip->ev_cfg_chan_shift);
638 709
639 val |= chip->ev_cfg_ele;710 val |= chip->ev_cfg_ele;
640 val |= MMA8452_FF_MT_CFG_OAE;
641 711
642 return mma8452_change_config(data, chip->ev_cfg, val);712 return mma8452_change_config(data, chip->ev_cfg, val);
713 default:
714 return -EINVAL;
715 }
643}716}
644 717
645static void mma8452_transient_interrupt(struct iio_dev *indio_dev)718static void mma8452_transient_interrupt(struct iio_dev *indio_dev)
@@ -652,6 +725,16 @@ static void mma8452_transient_interrupt(struct iio_dev *indio_dev) · 6 unmodified lines
652 if (src < 0)725 if (src < 0)
653 return;726 return;
654 727
728 if (mma8452_freefall_mode_enabled(data)) {
729 iio_push_event(indio_dev,
730 IIO_MOD_EVENT_CODE(IIO_ACCEL, 0,
731 IIO_MOD_X_AND_Y_AND_Z,
732 IIO_EV_TYPE_MAG,
733 IIO_EV_DIR_FALLING),
734 ts);
735 return;
736 }
737
655 if (src & data->chip_info->ev_src_xe)738 if (src & data->chip_info->ev_src_xe)
656 iio_push_event(indio_dev,739 iio_push_event(indio_dev,
657 IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X,740 IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X,
@@ -745,6 +828,27 @@ static int mma8452_reg_access_dbg(struct iio_dev *indio_dev, · 87 unmodified lines
745 return 0;828 return 0;
746}829}
747 830
831static const struct iio_event_spec mma8452_freefall_event[] = {
832 {
833 .type = IIO_EV_TYPE_MAG,
834 .dir = IIO_EV_DIR_FALLING,
835 .mask_separate = BIT(IIO_EV_INFO_ENABLE),
836 .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) |
837 BIT(IIO_EV_INFO_PERIOD) |
838 BIT(IIO_EV_INFO_HIGH_PASS_FILTER_3DB)
839 },
840};
841
842static const struct iio_event_spec mma8652_freefall_event[] = {
843 {
844 .type = IIO_EV_TYPE_MAG,
845 .dir = IIO_EV_DIR_FALLING,
846 .mask_separate = BIT(IIO_EV_INFO_ENABLE),
847 .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) |
848 BIT(IIO_EV_INFO_PERIOD)
849 },
850};
851
748static const struct iio_event_spec mma8452_transient_event[] = {852static const struct iio_event_spec mma8452_transient_event[] = {
749 {853 {
750 .type = IIO_EV_TYPE_MAG,854 .type = IIO_EV_TYPE_MAG,
@@ -781,6 +885,24 @@ static struct attribute_group mma8452_event_attribute_group = { · 30 unmodified lines
781 .attrs = mma8452_event_attributes,885 .attrs = mma8452_event_attributes,
782};886};
783 887
888#define MMA8452_FREEFALL_CHANNEL(modifier) { \
889 .type = IIO_ACCEL, \
890 .modified = 1, \
891 .channel2 = modifier, \
892 .scan_index = -1, \
893 .event_spec = mma8452_freefall_event, \
894 .num_event_specs = ARRAY_SIZE(mma8452_freefall_event), \
895}
896
897#define MMA8652_FREEFALL_CHANNEL(modifier) { \
898 .type = IIO_ACCEL, \
899 .modified = 1, \
900 .channel2 = modifier, \
901 .scan_index = -1, \
902 .event_spec = mma8652_freefall_event, \
903 .num_event_specs = ARRAY_SIZE(mma8652_freefall_event), \
904}
905
784#define MMA8452_CHANNEL(axis, idx, bits) { \906#define MMA8452_CHANNEL(axis, idx, bits) { \
785 .type = IIO_ACCEL, \907 .type = IIO_ACCEL, \
786 .modified = 1, \908 .modified = 1, \
@@ -822,11 +944,20 @@ static struct attribute_group mma8452_event_attribute_group = { · 35 unmodified lines
822 .num_event_specs = ARRAY_SIZE(mma8452_motion_event), \944 .num_event_specs = ARRAY_SIZE(mma8452_motion_event), \
823}945}
824 946
947static const struct iio_chan_spec mma8451_channels[] = {
948 MMA8452_CHANNEL(X, idx_x, 14),
949 MMA8452_CHANNEL(Y, idx_y, 14),
950 MMA8452_CHANNEL(Z, idx_z, 14),
951 IIO_CHAN_SOFT_TIMESTAMP(idx_ts),
952 MMA8452_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z),
953};
954
825static const struct iio_chan_spec mma8452_channels[] = {955static const struct iio_chan_spec mma8452_channels[] = {
826 MMA8452_CHANNEL(X, idx_x, 12),956 MMA8452_CHANNEL(X, idx_x, 12),
827 MMA8452_CHANNEL(Y, idx_y, 12),957 MMA8452_CHANNEL(Y, idx_y, 12),
828 MMA8452_CHANNEL(Z, idx_z, 12),958 MMA8452_CHANNEL(Z, idx_z, 12),
829 IIO_CHAN_SOFT_TIMESTAMP(idx_ts),959 IIO_CHAN_SOFT_TIMESTAMP(idx_ts),
960 MMA8452_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z),
830};961};
831 962
832static const struct iio_chan_spec mma8453_channels[] = {963static const struct iio_chan_spec mma8453_channels[] = {
@@ -834,6 +965,7 @@ static const struct iio_chan_spec mma8453_channels[] = { · 1 unmodified line
834 MMA8452_CHANNEL(Y, idx_y, 10),965 MMA8452_CHANNEL(Y, idx_y, 10),
835 MMA8452_CHANNEL(Z, idx_z, 10),966 MMA8452_CHANNEL(Z, idx_z, 10),
836 IIO_CHAN_SOFT_TIMESTAMP(idx_ts),967 IIO_CHAN_SOFT_TIMESTAMP(idx_ts),
968 MMA8452_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z),
837};969};
838 970
839static const struct iio_chan_spec mma8652_channels[] = {971static const struct iio_chan_spec mma8652_channels[] = {
@@ -841,6 +973,7 @@ static const struct iio_chan_spec mma8652_channels[] = { · 1 unmodified line
841 MMA8652_CHANNEL(Y, idx_y, 12),973 MMA8652_CHANNEL(Y, idx_y, 12),
842 MMA8652_CHANNEL(Z, idx_z, 12),974 MMA8652_CHANNEL(Z, idx_z, 12),
843 IIO_CHAN_SOFT_TIMESTAMP(idx_ts),975 IIO_CHAN_SOFT_TIMESTAMP(idx_ts),
976 MMA8652_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z),
844};977};
845 978
846static const struct iio_chan_spec mma8653_channels[] = {979static const struct iio_chan_spec mma8653_channels[] = {
@@ -848,9 +981,11 @@ static const struct iio_chan_spec mma8653_channels[] = { · 1 unmodified line
848 MMA8652_CHANNEL(Y, idx_y, 10),981 MMA8652_CHANNEL(Y, idx_y, 10),
849 MMA8652_CHANNEL(Z, idx_z, 10),982 MMA8652_CHANNEL(Z, idx_z, 10),
850 IIO_CHAN_SOFT_TIMESTAMP(idx_ts),983 IIO_CHAN_SOFT_TIMESTAMP(idx_ts),
984 MMA8652_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z),
851};985};
852 986
853enum {987enum {
988 mma8451,
854 mma8452,989 mma8452,
855 mma8453,990 mma8453,
856 mma8652,991 mma8652,
@@ -858,17 +993,34 @@ enum { · 1 unmodified line
858};993};
859 994
860static const struct mma_chip_info mma_chip_info_table[] = {995static const struct mma_chip_info mma_chip_info_table[] = {
861 [mma8452] = {996 [mma8451] = {
862 .chip_id = MMA8452_DEVICE_ID,997 .chip_id = MMA8451_DEVICE_ID,
863 .channels = mma8452_channels,998 .channels = mma8451_channels,
864 .num_channels = ARRAY_SIZE(mma8452_channels),999 .num_channels = ARRAY_SIZE(mma8451_channels),
865 /*1000 /*
866 * Hardware has fullscale of -2G, -4G, -8G corresponding to1001 * Hardware has fullscale of -2G, -4G, -8G corresponding to
867 * raw value -2048 for 12 bit or -512 for 10 bit.1002 * raw value -8192 for 14 bit, -2048 for 12 bit or -512 for 10
1003 * bit.
868 * The userspace interface uses m/s^2 and we declare micro units1004 * The userspace interface uses m/s^2 and we declare micro units
869 * So scale factor for 12 bit here is given by:1005 * So scale factor for 12 bit here is given by:
870 * g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.806651006 * g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.80665
871 */1007 */
1008 .mma_scales = { {0, 2394}, {0, 4788}, {0, 9577} },
1009 .ev_cfg = MMA8452_TRANSIENT_CFG,
1010 .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE,
1011 .ev_cfg_chan_shift = 1,
1012 .ev_src = MMA8452_TRANSIENT_SRC,
1013 .ev_src_xe = MMA8452_TRANSIENT_SRC_XTRANSE,
1014 .ev_src_ye = MMA8452_TRANSIENT_SRC_YTRANSE,
1015 .ev_src_ze = MMA8452_TRANSIENT_SRC_ZTRANSE,
1016 .ev_ths = MMA8452_TRANSIENT_THS,
1017 .ev_ths_mask = MMA8452_TRANSIENT_THS_MASK,
1018 .ev_count = MMA8452_TRANSIENT_COUNT,
1019 },
1020 [mma8452] = {
1021 .chip_id = MMA8452_DEVICE_ID,
1022 .channels = mma8452_channels,
1023 .num_channels = ARRAY_SIZE(mma8452_channels),
872 .mma_scales = { {0, 9577}, {0, 19154}, {0, 38307} },1024 .mma_scales = { {0, 9577}, {0, 19154}, {0, 38307} },
873 .ev_cfg = MMA8452_TRANSIENT_CFG,1025 .ev_cfg = MMA8452_TRANSIENT_CFG,
874 .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE,1026 .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE,
@@ -1049,6 +1201,7 @@ static int mma8452_reset(struct i2c_client *client) · 174 unmodified lines
1049}1201}
1050 1202
1051static const struct of_device_id mma8452_dt_ids[] = {1203static const struct of_device_id mma8452_dt_ids[] = {
1204 { .compatible = "fsl,mma8451", .data = &mma_chip_info_table[mma8451] },
1052 { .compatible = "fsl,mma8452", .data = &mma_chip_info_table[mma8452] },1205 { .compatible = "fsl,mma8452", .data = &mma_chip_info_table[mma8452] },
1053 { .compatible = "fsl,mma8453", .data = &mma_chip_info_table[mma8453] },1206 { .compatible = "fsl,mma8453", .data = &mma_chip_info_table[mma8453] },
1054 { .compatible = "fsl,mma8652", .data = &mma_chip_info_table[mma8652] },1207 { .compatible = "fsl,mma8652", .data = &mma_chip_info_table[mma8652] },
@@ -1085,6 +1238,7 @@ static int mma8452_probe(struct i2c_client *client, · 30 unmodified lines
1085 return ret;1238 return ret;
1086 1239
1087 switch (ret) {1240 switch (ret) {
1241 case MMA8451_DEVICE_ID:
1088 case MMA8452_DEVICE_ID:1242 case MMA8452_DEVICE_ID:
1089 case MMA8453_DEVICE_ID:1243 case MMA8453_DEVICE_ID:
1090 case MMA8652_DEVICE_ID:1244 case MMA8652_DEVICE_ID:
@@ -1190,6 +1344,10 @@ static int mma8452_probe(struct i2c_client *client, · 99 unmodified lines
1190 if (ret < 0)1344 if (ret < 0)
1191 goto buffer_cleanup;1345 goto buffer_cleanup;
1192 1346
1347 ret = mma8452_set_freefall_mode(data, false);
1348 if (ret)
1349 return ret;
1350
1193 return 0;1351 return 0;
1194 1352
1195buffer_cleanup:1353buffer_cleanup:
drivers/iio/accel/st_accel_core.c+16−0
@@ -67,6 +67,8 @@ · 66 unmodified lines
67#define ST_ACCEL_1_DRDY_IRQ_ADDR 0x2267#define ST_ACCEL_1_DRDY_IRQ_ADDR 0x22
68#define ST_ACCEL_1_DRDY_IRQ_INT1_MASK 0x1068#define ST_ACCEL_1_DRDY_IRQ_INT1_MASK 0x10
69#define ST_ACCEL_1_DRDY_IRQ_INT2_MASK 0x0869#define ST_ACCEL_1_DRDY_IRQ_INT2_MASK 0x08
70#define ST_ACCEL_1_IHL_IRQ_ADDR 0x25
71#define ST_ACCEL_1_IHL_IRQ_MASK 0x02
70#define ST_ACCEL_1_MULTIREAD_BIT true72#define ST_ACCEL_1_MULTIREAD_BIT true
71 73
72/* CUSTOM VALUES FOR SENSOR 2 */74/* CUSTOM VALUES FOR SENSOR 2 */
@@ -92,6 +94,8 @@ · 19 unmodified lines
92#define ST_ACCEL_2_DRDY_IRQ_ADDR 0x2294#define ST_ACCEL_2_DRDY_IRQ_ADDR 0x22
93#define ST_ACCEL_2_DRDY_IRQ_INT1_MASK 0x0295#define ST_ACCEL_2_DRDY_IRQ_INT1_MASK 0x02
94#define ST_ACCEL_2_DRDY_IRQ_INT2_MASK 0x1096#define ST_ACCEL_2_DRDY_IRQ_INT2_MASK 0x10
97#define ST_ACCEL_2_IHL_IRQ_ADDR 0x22
98#define ST_ACCEL_2_IHL_IRQ_MASK 0x80
95#define ST_ACCEL_2_MULTIREAD_BIT true99#define ST_ACCEL_2_MULTIREAD_BIT true
96 100
97/* CUSTOM VALUES FOR SENSOR 3 */101/* CUSTOM VALUES FOR SENSOR 3 */
@@ -125,6 +129,8 @@ · 27 unmodified lines
125#define ST_ACCEL_3_DRDY_IRQ_ADDR 0x23129#define ST_ACCEL_3_DRDY_IRQ_ADDR 0x23
126#define ST_ACCEL_3_DRDY_IRQ_INT1_MASK 0x80130#define ST_ACCEL_3_DRDY_IRQ_INT1_MASK 0x80
127#define ST_ACCEL_3_DRDY_IRQ_INT2_MASK 0x00131#define ST_ACCEL_3_DRDY_IRQ_INT2_MASK 0x00
132#define ST_ACCEL_3_IHL_IRQ_ADDR 0x23
133#define ST_ACCEL_3_IHL_IRQ_MASK 0x40
128#define ST_ACCEL_3_IG1_EN_ADDR 0x23134#define ST_ACCEL_3_IG1_EN_ADDR 0x23
129#define ST_ACCEL_3_IG1_EN_MASK 0x08135#define ST_ACCEL_3_IG1_EN_MASK 0x08
130#define ST_ACCEL_3_MULTIREAD_BIT false136#define ST_ACCEL_3_MULTIREAD_BIT false
@@ -169,6 +175,8 @@ · 38 unmodified lines
169#define ST_ACCEL_5_DRDY_IRQ_ADDR 0x22175#define ST_ACCEL_5_DRDY_IRQ_ADDR 0x22
170#define ST_ACCEL_5_DRDY_IRQ_INT1_MASK 0x04176#define ST_ACCEL_5_DRDY_IRQ_INT1_MASK 0x04
171#define ST_ACCEL_5_DRDY_IRQ_INT2_MASK 0x20177#define ST_ACCEL_5_DRDY_IRQ_INT2_MASK 0x20
178#define ST_ACCEL_5_IHL_IRQ_ADDR 0x22
179#define ST_ACCEL_5_IHL_IRQ_MASK 0x80
172#define ST_ACCEL_5_IG1_EN_ADDR 0x21180#define ST_ACCEL_5_IG1_EN_ADDR 0x21
173#define ST_ACCEL_5_IG1_EN_MASK 0x08181#define ST_ACCEL_5_IG1_EN_MASK 0x08
174#define ST_ACCEL_5_MULTIREAD_BIT false182#define ST_ACCEL_5_MULTIREAD_BIT false
@@ -292,6 +300,8 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { · 117 unmodified lines
292 .addr = ST_ACCEL_1_DRDY_IRQ_ADDR,300 .addr = ST_ACCEL_1_DRDY_IRQ_ADDR,
293 .mask_int1 = ST_ACCEL_1_DRDY_IRQ_INT1_MASK,301 .mask_int1 = ST_ACCEL_1_DRDY_IRQ_INT1_MASK,
294 .mask_int2 = ST_ACCEL_1_DRDY_IRQ_INT2_MASK,302 .mask_int2 = ST_ACCEL_1_DRDY_IRQ_INT2_MASK,
303 .addr_ihl = ST_ACCEL_1_IHL_IRQ_ADDR,
304 .mask_ihl = ST_ACCEL_1_IHL_IRQ_MASK,
295 },305 },
296 .multi_read_bit = ST_ACCEL_1_MULTIREAD_BIT,306 .multi_read_bit = ST_ACCEL_1_MULTIREAD_BIT,
297 .bootime = 2,307 .bootime = 2,
@@ -355,6 +365,8 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { · 57 unmodified lines
355 .addr = ST_ACCEL_2_DRDY_IRQ_ADDR,365 .addr = ST_ACCEL_2_DRDY_IRQ_ADDR,
356 .mask_int1 = ST_ACCEL_2_DRDY_IRQ_INT1_MASK,366 .mask_int1 = ST_ACCEL_2_DRDY_IRQ_INT1_MASK,
357 .mask_int2 = ST_ACCEL_2_DRDY_IRQ_INT2_MASK,367 .mask_int2 = ST_ACCEL_2_DRDY_IRQ_INT2_MASK,
368 .addr_ihl = ST_ACCEL_2_IHL_IRQ_ADDR,
369 .mask_ihl = ST_ACCEL_2_IHL_IRQ_MASK,
358 },370 },
359 .multi_read_bit = ST_ACCEL_2_MULTIREAD_BIT,371 .multi_read_bit = ST_ACCEL_2_MULTIREAD_BIT,
360 .bootime = 2,372 .bootime = 2,
@@ -430,6 +442,8 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { · 69 unmodified lines
430 .addr = ST_ACCEL_3_DRDY_IRQ_ADDR,442 .addr = ST_ACCEL_3_DRDY_IRQ_ADDR,
431 .mask_int1 = ST_ACCEL_3_DRDY_IRQ_INT1_MASK,443 .mask_int1 = ST_ACCEL_3_DRDY_IRQ_INT1_MASK,
432 .mask_int2 = ST_ACCEL_3_DRDY_IRQ_INT2_MASK,444 .mask_int2 = ST_ACCEL_3_DRDY_IRQ_INT2_MASK,
445 .addr_ihl = ST_ACCEL_3_IHL_IRQ_ADDR,
446 .mask_ihl = ST_ACCEL_3_IHL_IRQ_MASK,
433 .ig1 = {447 .ig1 = {
434 .en_addr = ST_ACCEL_3_IG1_EN_ADDR,448 .en_addr = ST_ACCEL_3_IG1_EN_ADDR,
435 .en_mask = ST_ACCEL_3_IG1_EN_MASK,449 .en_mask = ST_ACCEL_3_IG1_EN_MASK,
@@ -537,6 +551,8 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { · 101 unmodified lines
537 .addr = ST_ACCEL_5_DRDY_IRQ_ADDR,551 .addr = ST_ACCEL_5_DRDY_IRQ_ADDR,
538 .mask_int1 = ST_ACCEL_5_DRDY_IRQ_INT1_MASK,552 .mask_int1 = ST_ACCEL_5_DRDY_IRQ_INT1_MASK,
539 .mask_int2 = ST_ACCEL_5_DRDY_IRQ_INT2_MASK,553 .mask_int2 = ST_ACCEL_5_DRDY_IRQ_INT2_MASK,
554 .addr_ihl = ST_ACCEL_5_IHL_IRQ_ADDR,
555 .mask_ihl = ST_ACCEL_5_IHL_IRQ_MASK,
540 },556 },
541 .multi_read_bit = ST_ACCEL_5_MULTIREAD_BIT,557 .multi_read_bit = ST_ACCEL_5_MULTIREAD_BIT,
542 .bootime = 2, /* guess */558 .bootime = 2, /* guess */
drivers/iio/adc/Kconfig+13−3
@@ -131,6 +131,16 @@ config AT91_ADC · 130 unmodified lines
131 To compile this driver as a module, choose M here: the module will be131 To compile this driver as a module, choose M here: the module will be
132 called at91_adc.132 called at91_adc.
133 133
134config AT91_SAMA5D2_ADC
135 tristate "Atmel AT91 SAMA5D2 ADC"
136 depends on ARCH_AT91 || COMPILE_TEST
137 help
138 Say yes here to build support for Atmel SAMA5D2 ADC which is
139 available on SAMA5D2 SoC family.
140
141 To compile this driver as a module, choose M here: the module will be
142 called at91-sama5d2_adc.
143
134config AXP288_ADC144config AXP288_ADC
135 tristate "X-Powers AXP288 ADC driver"145 tristate "X-Powers AXP288 ADC driver"
136 depends on MFD_AXP20X146 depends on MFD_AXP20X
@@ -265,11 +275,11 @@ config MCP320X · 128 unmodified lines
265 called mcp320x.275 called mcp320x.
266 276
267config MCP3422277config MCP3422
268 tristate "Microchip Technology MCP3422/3/4/6/7/8 driver"278 tristate "Microchip Technology MCP3421/2/3/4/5/6/7/8 driver"
269 depends on I2C279 depends on I2C
270 help280 help
271 Say yes here to build support for Microchip Technology's281 Say yes here to build support for Microchip Technology's MCP3421
272 MCP3422, MCP3423, MCP3424, MCP3426, MCP3427 or MCP3428282 MCP3422, MCP3423, MCP3424, MCP3425, MCP3426, MCP3427 or MCP3428
273 analog to digital converters.283 analog to digital converters.
274 284
275 This driver can also be built as a module. If so, the module will be285 This driver can also be built as a module. If so, the module will be
drivers/iio/adc/Makefile+1−0
@@ -14,6 +14,7 @@ obj-$(CONFIG_AD7793) += ad7793.o · 13 unmodified lines
14obj-$(CONFIG_AD7887) += ad7887.o14obj-$(CONFIG_AD7887) += ad7887.o
15obj-$(CONFIG_AD799X) += ad799x.o15obj-$(CONFIG_AD799X) += ad799x.o
16obj-$(CONFIG_AT91_ADC) += at91_adc.o16obj-$(CONFIG_AT91_ADC) += at91_adc.o
17obj-$(CONFIG_AT91_SAMA5D2_ADC) += at91-sama5d2_adc.o
17obj-$(CONFIG_AXP288_ADC) += axp288_adc.o18obj-$(CONFIG_AXP288_ADC) += axp288_adc.o
18obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o19obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o
19obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o20obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
drivers/iio/adc/at91-sama5d2_adc.c+508−0
@@ -0,0 +1,508 @@
1/*
2 * Atmel ADC driver for SAMA5D2 devices and compatible.
3 *
4 * Copyright (C) 2015 Atmel,
5 * 2015 Ludovic Desroches <ludovic.desroches@atmel.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/bitops.h>
18#include <linux/clk.h>
19#include <linux/interrupt.h>
20#include <linux/io.h>
21#include <linux/module.h>
22#include <linux/of_device.h>
23#include <linux/platform_device.h>
24#include <linux/sched.h>
25#include <linux/wait.h>
26#include <linux/iio/iio.h>
27#include <linux/iio/sysfs.h>
28#include <linux/regulator/consumer.h>
29
30/* Control Register */
31#define AT91_SAMA5D2_CR 0x00
32/* Software Reset */
33#define AT91_SAMA5D2_CR_SWRST BIT(0)
34/* Start Conversion */
35#define AT91_SAMA5D2_CR_START BIT(1)
36/* Touchscreen Calibration */
37#define AT91_SAMA5D2_CR_TSCALIB BIT(2)
38/* Comparison Restart */
39#define AT91_SAMA5D2_CR_CMPRST BIT(4)
40
41/* Mode Register */
42#define AT91_SAMA5D2_MR 0x04
43/* Trigger Selection */
44#define AT91_SAMA5D2_MR_TRGSEL(v) ((v) << 1)
45/* ADTRG */
46#define AT91_SAMA5D2_MR_TRGSEL_TRIG0 0
47/* TIOA0 */
48#define AT91_SAMA5D2_MR_TRGSEL_TRIG1 1
49/* TIOA1 */
50#define AT91_SAMA5D2_MR_TRGSEL_TRIG2 2
51/* TIOA2 */
52#define AT91_SAMA5D2_MR_TRGSEL_TRIG3 3
53/* PWM event line 0 */
54#define AT91_SAMA5D2_MR_TRGSEL_TRIG4 4
55/* PWM event line 1 */
56#define AT91_SAMA5D2_MR_TRGSEL_TRIG5 5
57/* TIOA3 */
58#define AT91_SAMA5D2_MR_TRGSEL_TRIG6 6
59/* RTCOUT0 */
60#define AT91_SAMA5D2_MR_TRGSEL_TRIG7 7
61/* Sleep Mode */
62#define AT91_SAMA5D2_MR_SLEEP BIT(5)
63/* Fast Wake Up */
64#define AT91_SAMA5D2_MR_FWUP BIT(6)
65/* Prescaler Rate Selection */
66#define AT91_SAMA5D2_MR_PRESCAL(v) ((v) << AT91_SAMA5D2_MR_PRESCAL_OFFSET)
67#define AT91_SAMA5D2_MR_PRESCAL_OFFSET 8
68#define AT91_SAMA5D2_MR_PRESCAL_MAX 0xff
69/* Startup Time */
70#define AT91_SAMA5D2_MR_STARTUP(v) ((v) << 16)
71/* Analog Change */
72#define AT91_SAMA5D2_MR_ANACH BIT(23)
73/* Tracking Time */
74#define AT91_SAMA5D2_MR_TRACKTIM(v) ((v) << 24)
75#define AT91_SAMA5D2_MR_TRACKTIM_MAX 0xff
76/* Transfer Time */
77#define AT91_SAMA5D2_MR_TRANSFER(v) ((v) << 28)
78#define AT91_SAMA5D2_MR_TRANSFER_MAX 0x3
79/* Use Sequence Enable */
80#define AT91_SAMA5D2_MR_USEQ BIT(31)
81
82/* Channel Sequence Register 1 */
83#define AT91_SAMA5D2_SEQR1 0x08
84/* Channel Sequence Register 2 */
85#define AT91_SAMA5D2_SEQR2 0x0c
86/* Channel Enable Register */
87#define AT91_SAMA5D2_CHER 0x10
88/* Channel Disable Register */
89#define AT91_SAMA5D2_CHDR 0x14
90/* Channel Status Register */
91#define AT91_SAMA5D2_CHSR 0x18
92/* Last Converted Data Register */
93#define AT91_SAMA5D2_LCDR 0x20
94/* Interrupt Enable Register */
95#define AT91_SAMA5D2_IER 0x24
96/* Interrupt Disable Register */
97#define AT91_SAMA5D2_IDR 0x28
98/* Interrupt Mask Register */
99#define AT91_SAMA5D2_IMR 0x2c
100/* Interrupt Status Register */
101#define AT91_SAMA5D2_ISR 0x30
102/* Last Channel Trigger Mode Register */
103#define AT91_SAMA5D2_LCTMR 0x34
104/* Last Channel Compare Window Register */
105#define AT91_SAMA5D2_LCCWR 0x38
106/* Overrun Status Register */
107#define AT91_SAMA5D2_OVER 0x3c
108/* Extended Mode Register */
109#define AT91_SAMA5D2_EMR 0x40
110/* Compare Window Register */
111#define AT91_SAMA5D2_CWR 0x44
112/* Channel Gain Register */
113#define AT91_SAMA5D2_CGR 0x48
114/* Channel Offset Register */
115#define AT91_SAMA5D2_COR 0x4c
116/* Channel Data Register 0 */
117#define AT91_SAMA5D2_CDR0 0x50
118/* Analog Control Register */
119#define AT91_SAMA5D2_ACR 0x94
120/* Touchscreen Mode Register */
121#define AT91_SAMA5D2_TSMR 0xb0
122/* Touchscreen X Position Register */
123#define AT91_SAMA5D2_XPOSR 0xb4
124/* Touchscreen Y Position Register */
125#define AT91_SAMA5D2_YPOSR 0xb8
126/* Touchscreen Pressure Register */
127#define AT91_SAMA5D2_PRESSR 0xbc
128/* Trigger Register */
129#define AT91_SAMA5D2_TRGR 0xc0
130/* Correction Select Register */
131#define AT91_SAMA5D2_COSR 0xd0
132/* Correction Value Register */
133#define AT91_SAMA5D2_CVR 0xd4
134/* Channel Error Correction Register */
135#define AT91_SAMA5D2_CECR 0xd8
136/* Write Protection Mode Register */
137#define AT91_SAMA5D2_WPMR 0xe4
138/* Write Protection Status Register */
139#define AT91_SAMA5D2_WPSR 0xe8
140/* Version Register */
141#define AT91_SAMA5D2_VERSION 0xfc
142
143#define AT91_AT91_SAMA5D2_CHAN(num, addr) \
144 { \
145 .type = IIO_VOLTAGE, \
146 .channel = num, \
147 .address = addr, \
148 .scan_type = { \
149 .sign = 'u', \
150 .realbits = 12, \
151 }, \
152 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
153 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
154 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
155 .datasheet_name = "CH"#num, \
156 .indexed = 1, \
157 }
158
159#define at91_adc_readl(st, reg) readl_relaxed(st->base + reg)
160#define at91_adc_writel(st, reg, val) writel_relaxed(val, st->base + reg)
161
162struct at91_adc_soc_info {
163 unsigned startup_time;
164 unsigned min_sample_rate;
165 unsigned max_sample_rate;
166};
167
168struct at91_adc_state {
169 void __iomem *base;
170 int irq;
171 struct clk *per_clk;
172 struct regulator *reg;
173 struct regulator *vref;
174 int vref_uv;
175 const struct iio_chan_spec *chan;
176 bool conversion_done;
177 u32 conversion_value;
178 struct at91_adc_soc_info soc_info;
179 wait_queue_head_t wq_data_available;
180 /*
181 * lock to prevent concurrent 'single conversion' requests through
182 * sysfs.
183 */
184 struct mutex lock;
185};
186
187static const struct iio_chan_spec at91_adc_channels[] = {
188 AT91_AT91_SAMA5D2_CHAN(0, 0x50),
189 AT91_AT91_SAMA5D2_CHAN(1, 0x54),
190 AT91_AT91_SAMA5D2_CHAN(2, 0x58),
191 AT91_AT91_SAMA5D2_CHAN(3, 0x5c),
192 AT91_AT91_SAMA5D2_CHAN(4, 0x60),
193 AT91_AT91_SAMA5D2_CHAN(5, 0x64),
194 AT91_AT91_SAMA5D2_CHAN(6, 0x68),
195 AT91_AT91_SAMA5D2_CHAN(7, 0x6c),
196 AT91_AT91_SAMA5D2_CHAN(8, 0x70),
197 AT91_AT91_SAMA5D2_CHAN(9, 0x74),
198 AT91_AT91_SAMA5D2_CHAN(10, 0x78),
199 AT91_AT91_SAMA5D2_CHAN(11, 0x7c),
200};
201
202static unsigned at91_adc_startup_time(unsigned startup_time_min,
203 unsigned adc_clk_khz)
204{
205 const unsigned startup_lookup[] = {
206 0, 8, 16, 24,
207 64, 80, 96, 112,
208 512, 576, 640, 704,
209 768, 832, 896, 960
210 };
211 unsigned ticks_min, i;
212
213 /*
214 * Since the adc frequency is checked before, there is no reason
215 * to not meet the startup time constraint.
216 */
217
218 ticks_min = startup_time_min * adc_clk_khz / 1000;
219 for (i = 0; i < ARRAY_SIZE(startup_lookup); i++)
220 if (startup_lookup[i] > ticks_min)
221 break;
222
223 return i;
224}
225
226static void at91_adc_setup_samp_freq(struct at91_adc_state *st, unsigned freq)
227{
228 struct iio_dev *indio_dev = iio_priv_to_dev(st);
229 unsigned f_per, prescal, startup;
230
231 f_per = clk_get_rate(st->per_clk);
232 prescal = (f_per / (2 * freq)) - 1;
233
234 startup = at91_adc_startup_time(st->soc_info.startup_time,
235 freq / 1000);
236
237 at91_adc_writel(st, AT91_SAMA5D2_MR,
238 AT91_SAMA5D2_MR_TRANSFER(2)
239 | AT91_SAMA5D2_MR_STARTUP(startup)
240 | AT91_SAMA5D2_MR_PRESCAL(prescal));
241
242 dev_dbg(&indio_dev->dev, "freq: %u, startup: %u, prescal: %u\n",
243 freq, startup, prescal);
244}
245
246static unsigned at91_adc_get_sample_freq(struct at91_adc_state *st)
247{
248 unsigned f_adc, f_per = clk_get_rate(st->per_clk);
249 unsigned mr, prescal;
250
251 mr = at91_adc_readl(st, AT91_SAMA5D2_MR);
252 prescal = (mr >> AT91_SAMA5D2_MR_PRESCAL_OFFSET)
253 & AT91_SAMA5D2_MR_PRESCAL_MAX;
254 f_adc = f_per / (2 * (prescal + 1));
255
256 return f_adc;
257}
258
259static irqreturn_t at91_adc_interrupt(int irq, void *private)
260{
261 struct iio_dev *indio = private;
262 struct at91_adc_state *st = iio_priv(indio);
263 u32 status = at91_adc_readl(st, AT91_SAMA5D2_ISR);
264 u32 imr = at91_adc_readl(st, AT91_SAMA5D2_IMR);
265
266 if (status & imr) {
267 st->conversion_value = at91_adc_readl(st, st->chan->address);
268 st->conversion_done = true;
269 wake_up_interruptible(&st->wq_data_available);
270 return IRQ_HANDLED;
271 }
272
273 return IRQ_NONE;
274}
275
276static int at91_adc_read_raw(struct iio_dev *indio_dev,
277 struct iio_chan_spec const *chan,
278 int *val, int *val2, long mask)
279{
280 struct at91_adc_state *st = iio_priv(indio_dev);
281 int ret;
282
283 switch (mask) {
284 case IIO_CHAN_INFO_RAW:
285 mutex_lock(&st->lock);
286
287 st->chan = chan;
288
289 at91_adc_writel(st, AT91_SAMA5D2_CHER, BIT(chan->channel));
290 at91_adc_writel(st, AT91_SAMA5D2_IER, BIT(chan->channel));
291 at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_START);
292
293 ret = wait_event_interruptible_timeout(st->wq_data_available,
294 st->conversion_done,
295 msecs_to_jiffies(1000));
296 if (ret == 0)
297 ret = -ETIMEDOUT;
298
299 if (ret > 0) {
300 *val = st->conversion_value;
301 ret = IIO_VAL_INT;
302 st->conversion_done = false;
303 }
304
305 at91_adc_writel(st, AT91_SAMA5D2_IDR, BIT(chan->channel));
306 at91_adc_writel(st, AT91_SAMA5D2_CHDR, BIT(chan->channel));
307
308 mutex_unlock(&st->lock);
309 return ret;
310
311 case IIO_CHAN_INFO_SCALE:
312 *val = st->vref_uv / 1000;
313 *val2 = chan->scan_type.realbits;
314 return IIO_VAL_FRACTIONAL_LOG2;
315
316 case IIO_CHAN_INFO_SAMP_FREQ:
317 *val = at91_adc_get_sample_freq(st);
318 return IIO_VAL_INT;
319
320 default:
321 return -EINVAL;
322 }
323}
324
325static int at91_adc_write_raw(struct iio_dev *indio_dev,
326 struct iio_chan_spec const *chan,
327 int val, int val2, long mask)
328{
329 struct at91_adc_state *st = iio_priv(indio_dev);
330
331 if (mask != IIO_CHAN_INFO_SAMP_FREQ)
332 return -EINVAL;
333
334 if (val < st->soc_info.min_sample_rate ||
335 val > st->soc_info.max_sample_rate)
336 return -EINVAL;
337
338 at91_adc_setup_samp_freq(st, val);
339
340 return 0;
341}
342
343static const struct iio_info at91_adc_info = {
344 .read_raw = &at91_adc_read_raw,
345 .write_raw = &at91_adc_write_raw,
346 .driver_module = THIS_MODULE,
347};
348
349static int at91_adc_probe(struct platform_device *pdev)
350{
351 struct iio_dev *indio_dev;
352 struct at91_adc_state *st;
353 struct resource *res;
354 int ret;
355
356 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st));
357 if (!indio_dev)
358 return -ENOMEM;
359
360 indio_dev->dev.parent = &pdev->dev;
361 indio_dev->name = dev_name(&pdev->dev);
362 indio_dev->modes = INDIO_DIRECT_MODE;
363 indio_dev->info = &at91_adc_info;
364 indio_dev->channels = at91_adc_channels;
365 indio_dev->num_channels = ARRAY_SIZE(at91_adc_channels);
366
367 st = iio_priv(indio_dev);
368
369 ret = of_property_read_u32(pdev->dev.of_node,
370 "atmel,min-sample-rate-hz",
371 &st->soc_info.min_sample_rate);
372 if (ret) {
373 dev_err(&pdev->dev,
374 "invalid or missing value for atmel,min-sample-rate-hz\n");
375 return ret;
376 }
377
378 ret = of_property_read_u32(pdev->dev.of_node,
379 "atmel,max-sample-rate-hz",
380 &st->soc_info.max_sample_rate);
381 if (ret) {
382 dev_err(&pdev->dev,
383 "invalid or missing value for atmel,max-sample-rate-hz\n");
384 return ret;
385 }
386
387 ret = of_property_read_u32(pdev->dev.of_node, "atmel,startup-time-ms",
388 &st->soc_info.startup_time);
389 if (ret) {
390 dev_err(&pdev->dev,
391 "invalid or missing value for atmel,startup-time-ms\n");
392 return ret;
393 }
394
395 init_waitqueue_head(&st->wq_data_available);
396 mutex_init(&st->lock);
397
398 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
399 if (!res)
400 return -EINVAL;
401
402 st->base = devm_ioremap_resource(&pdev->dev, res);
403 if (IS_ERR(st->base))
404 return PTR_ERR(st->base);
405
406 st->irq = platform_get_irq(pdev, 0);
407 if (st->irq <= 0) {
408 if (!st->irq)
409 st->irq = -ENXIO;
410
411 return st->irq;
412 }
413
414 st->per_clk = devm_clk_get(&pdev->dev, "adc_clk");
415 if (IS_ERR(st->per_clk))
416 return PTR_ERR(st->per_clk);
417
418 st->reg = devm_regulator_get(&pdev->dev, "vddana");
419 if (IS_ERR(st->reg))
420 return PTR_ERR(st->reg);
421
422 st->vref = devm_regulator_get(&pdev->dev, "vref");
423 if (IS_ERR(st->vref))
424 return PTR_ERR(st->vref);
425
426 ret = devm_request_irq(&pdev->dev, st->irq, at91_adc_interrupt, 0,
427 pdev->dev.driver->name, indio_dev);
428 if (ret)
429 return ret;
430
431 ret = regulator_enable(st->reg);
432 if (ret)
433 return ret;
434
435 ret = regulator_enable(st->vref);
436 if (ret)
437 goto reg_disable;
438
439 st->vref_uv = regulator_get_voltage(st->vref);
440 if (st->vref_uv <= 0) {
441 ret = -EINVAL;
442 goto vref_disable;
443 }
444
445 at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST);
446 at91_adc_writel(st, AT91_SAMA5D2_IDR, 0xffffffff);
447
448 at91_adc_setup_samp_freq(st, st->soc_info.min_sample_rate);
449
450 ret = clk_prepare_enable(st->per_clk);
451 if (ret)
452 goto vref_disable;
453
454 ret = iio_device_register(indio_dev);
455 if (ret < 0)
456 goto per_clk_disable_unprepare;
457
458 dev_info(&pdev->dev, "version: %x\n",
459 readl_relaxed(st->base + AT91_SAMA5D2_VERSION));
460
461 return 0;
462
463per_clk_disable_unprepare:
464 clk_disable_unprepare(st->per_clk);
465vref_disable:
466 regulator_disable(st->vref);
467reg_disable:
468 regulator_disable(st->reg);
469 return ret;
470}
471
472static int at91_adc_remove(struct platform_device *pdev)
473{
474 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
475 struct at91_adc_state *st = iio_priv(indio_dev);
476
477 iio_device_unregister(indio_dev);
478
479 clk_disable_unprepare(st->per_clk);
480
481 regulator_disable(st->vref);
482 regulator_disable(st->reg);
483
484 return 0;
485}
486
487static const struct of_device_id at91_adc_dt_match[] = {
488 {
489 .compatible = "atmel,sama5d2-adc",
490 }, {
491 /* sentinel */
492 }
493};
494MODULE_DEVICE_TABLE(of, at91_adc_dt_match);
495
496static struct platform_driver at91_adc_driver = {
497 .probe = at91_adc_probe,
498 .remove = at91_adc_remove,
499 .driver = {
500 .name = "at91-sama5d2_adc",
501 .of_match_table = at91_adc_dt_match,
502 },
503};
504module_platform_driver(at91_adc_driver)
505
506MODULE_AUTHOR("Ludovic Desroches <ludovic.desroches@atmel.com>");
507MODULE_DESCRIPTION("Atmel AT91 SAMA5D2 ADC");
508MODULE_LICENSE("GPL v2");
drivers/iio/adc/axp288_adc.c+1−1
@@ -46,7 +46,7 @@ struct axp288_adc_info { · 45 unmodified lines
46 struct regmap *regmap;46 struct regmap *regmap;
47};47};
48 48
49static const struct iio_chan_spec const axp288_adc_channels[] = {49static const struct iio_chan_spec axp288_adc_channels[] = {
50 {50 {
51 .indexed = 1,51 .indexed = 1,
52 .type = IIO_TEMP,52 .type = IIO_TEMP,
drivers/iio/adc/mcp320x.c+19−12
@@ -187,26 +187,27 @@ out: · 186 unmodified lines
187 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \187 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \
188 }188 }
189 189
190#define MCP320X_VOLTAGE_CHANNEL_DIFF(num) \190#define MCP320X_VOLTAGE_CHANNEL_DIFF(chan1, chan2) \
191 { \191 { \
192 .type = IIO_VOLTAGE, \192 .type = IIO_VOLTAGE, \
193 .indexed = 1, \193 .indexed = 1, \
194 .channel = (num * 2), \194 .channel = (chan1), \
195 .channel2 = (num * 2 + 1), \195 .channel2 = (chan2), \
196 .address = (num * 2), \196 .address = (chan1), \
197 .differential = 1, \197 .differential = 1, \
198 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \198 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
199 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \199 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \
200 }200 }
201 201
202static const struct iio_chan_spec mcp3201_channels[] = {202static const struct iio_chan_spec mcp3201_channels[] = {
203 MCP320X_VOLTAGE_CHANNEL_DIFF(0),203 MCP320X_VOLTAGE_CHANNEL_DIFF(0, 1),
204};204};
205 205
206static const struct iio_chan_spec mcp3202_channels[] = {206static const struct iio_chan_spec mcp3202_channels[] = {
207 MCP320X_VOLTAGE_CHANNEL(0),207 MCP320X_VOLTAGE_CHANNEL(0),
208 MCP320X_VOLTAGE_CHANNEL(1),208 MCP320X_VOLTAGE_CHANNEL(1),
209 MCP320X_VOLTAGE_CHANNEL_DIFF(0),209 MCP320X_VOLTAGE_CHANNEL_DIFF(0, 1),
210 MCP320X_VOLTAGE_CHANNEL_DIFF(1, 0),
210};211};
211 212
212static const struct iio_chan_spec mcp3204_channels[] = {213static const struct iio_chan_spec mcp3204_channels[] = {
@@ -214,8 +215,10 @@ static const struct iio_chan_spec mcp3204_channels[] = { · 1 unmodified line
214 MCP320X_VOLTAGE_CHANNEL(1),215 MCP320X_VOLTAGE_CHANNEL(1),
215 MCP320X_VOLTAGE_CHANNEL(2),216 MCP320X_VOLTAGE_CHANNEL(2),
216 MCP320X_VOLTAGE_CHANNEL(3),217 MCP320X_VOLTAGE_CHANNEL(3),
217 MCP320X_VOLTAGE_CHANNEL_DIFF(0),218 MCP320X_VOLTAGE_CHANNEL_DIFF(0, 1),
218 MCP320X_VOLTAGE_CHANNEL_DIFF(1),219 MCP320X_VOLTAGE_CHANNEL_DIFF(1, 0),
220 MCP320X_VOLTAGE_CHANNEL_DIFF(2, 3),
221 MCP320X_VOLTAGE_CHANNEL_DIFF(3, 2),
219};222};
220 223
221static const struct iio_chan_spec mcp3208_channels[] = {224static const struct iio_chan_spec mcp3208_channels[] = {
@@ -227,10 +230,14 @@ static const struct iio_chan_spec mcp3208_channels[] = { · 5 unmodified lines
227 MCP320X_VOLTAGE_CHANNEL(5),230 MCP320X_VOLTAGE_CHANNEL(5),
228 MCP320X_VOLTAGE_CHANNEL(6),231 MCP320X_VOLTAGE_CHANNEL(6),
229 MCP320X_VOLTAGE_CHANNEL(7),232 MCP320X_VOLTAGE_CHANNEL(7),
230 MCP320X_VOLTAGE_CHANNEL_DIFF(0),233 MCP320X_VOLTAGE_CHANNEL_DIFF(0, 1),
231 MCP320X_VOLTAGE_CHANNEL_DIFF(1),234 MCP320X_VOLTAGE_CHANNEL_DIFF(1, 0),
232 MCP320X_VOLTAGE_CHANNEL_DIFF(2),235 MCP320X_VOLTAGE_CHANNEL_DIFF(2, 3),
233 MCP320X_VOLTAGE_CHANNEL_DIFF(3),236 MCP320X_VOLTAGE_CHANNEL_DIFF(3, 2),
237 MCP320X_VOLTAGE_CHANNEL_DIFF(4, 5),
238 MCP320X_VOLTAGE_CHANNEL_DIFF(5, 4),
239 MCP320X_VOLTAGE_CHANNEL_DIFF(6, 7),
240 MCP320X_VOLTAGE_CHANNEL_DIFF(7, 6),
234};241};
235 242
236static const struct iio_info mcp320x_info = {243static const struct iio_info mcp320x_info = {
drivers/iio/adc/mcp3422.c+5−2
@@ -1,11 +1,12 @@
1/*1/*
2 * mcp3422.c - driver for the Microchip mcp3422/3/4/6/7/8 chip family2 * mcp3422.c - driver for the Microchip mcp3421/2/3/4/5/6/7/8 chip family
3 *3 *
4 * Copyright (C) 2013, Angelo Compagnucci4 * Copyright (C) 2013, Angelo Compagnucci
5 * Author: Angelo Compagnucci <angelo.compagnucci@gmail.com>5 * Author: Angelo Compagnucci <angelo.compagnucci@gmail.com>
6 *6 *
7 * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/22088b.pdf7 * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/22088b.pdf
8 * http://ww1.microchip.com/downloads/en/DeviceDoc/22226a.pdf8 * http://ww1.microchip.com/downloads/en/DeviceDoc/22226a.pdf
9 * http://ww1.microchip.com/downloads/en/DeviceDoc/22072b.pdf
9 *10 *
10 * This driver exports the value of analog input voltage to sysfs, the11 * This driver exports the value of analog input voltage to sysfs, the
11 * voltage unit is nV.12 * voltage unit is nV.
@@ -357,6 +358,7 @@ static int mcp3422_probe(struct i2c_client *client, · 345 unmodified lines
357 358
358 switch (adc->id) {359 switch (adc->id) {
359 case 1:360 case 1:
361 case 5:
360 indio_dev->channels = mcp3421_channels;362 indio_dev->channels = mcp3421_channels;
361 indio_dev->num_channels = ARRAY_SIZE(mcp3421_channels);363 indio_dev->num_channels = ARRAY_SIZE(mcp3421_channels);
362 break;364 break;
@@ -395,6 +397,7 @@ static const struct i2c_device_id mcp3422_id[] = { · 32 unmodified lines
395 { "mcp3422", 2 },397 { "mcp3422", 2 },
396 { "mcp3423", 3 },398 { "mcp3423", 3 },
397 { "mcp3424", 4 },399 { "mcp3424", 4 },
400 { "mcp3425", 5 },
398 { "mcp3426", 6 },401 { "mcp3426", 6 },
399 { "mcp3427", 7 },402 { "mcp3427", 7 },
400 { "mcp3428", 8 },403 { "mcp3428", 8 },
@@ -421,5 +424,5 @@ static struct i2c_driver mcp3422_driver = { · 20 unmodified lines
421module_i2c_driver(mcp3422_driver);424module_i2c_driver(mcp3422_driver);
422 425
423MODULE_AUTHOR("Angelo Compagnucci <angelo.compagnucci@gmail.com>");426MODULE_AUTHOR("Angelo Compagnucci <angelo.compagnucci@gmail.com>");
424MODULE_DESCRIPTION("Microchip mcp3422/3/4/6/7/8 driver");427MODULE_DESCRIPTION("Microchip mcp3421/2/3/4/5/6/7/8 driver");
425MODULE_LICENSE("GPL v2");428MODULE_LICENSE("GPL v2");
drivers/iio/chemical/Kconfig+13−0
@@ -4,6 +4,19 @@ · 3 unmodified lines
4 4
5menu "Chemical Sensors"5menu "Chemical Sensors"
6 6
7config ATLAS_PH_SENSOR
8 tristate "Atlas Scientific OEM pH-SM sensor"
9 depends on I2C
10 select REGMAP_I2C
11 select IIO_BUFFER
12 select IIO_TRIGGERED_BUFFER
13 help
14 Say Y here to build I2C interface support for the Atlas
15 Scientific OEM pH-SM sensor.
16
17 To compile this driver as module, choose M here: the
18 module will be called atlas-ph-sensor.
19
7config IAQCORE20config IAQCORE
8 tristate "AMS iAQ-Core VOC sensors"21 tristate "AMS iAQ-Core VOC sensors"
9 depends on I2C22 depends on I2C
drivers/iio/chemical/Makefile+1−0
@@ -3,5 +3,6 @@ · 2 unmodified lines
3#3#
4 4
5# When adding new entries keep the list in alphabetical order5# When adding new entries keep the list in alphabetical order
6obj-$(CONFIG_ATLAS_PH_SENSOR) += atlas-ph-sensor.o
6obj-$(CONFIG_IAQCORE) += ams-iaq-core.o7obj-$(CONFIG_IAQCORE) += ams-iaq-core.o
7obj-$(CONFIG_VZ89X) += vz89x.o8obj-$(CONFIG_VZ89X) += vz89x.o
drivers/iio/chemical/atlas-ph-sensor.c+511−0
@@ -0,0 +1,511 @@
1/*
2 * atlas-ph-sensor.c - Support for Atlas Scientific OEM pH-SM sensor
3 *
4 * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/interrupt.h>
20#include <linux/delay.h>
21#include <linux/mutex.h>
22#include <linux/err.h>
23#include <linux/irq.h>
24#include <linux/irq_work.h>
25#include <linux/gpio.h>
26#include <linux/i2c.h>
27#include <linux/regmap.h>
28#include <linux/iio/iio.h>
29#include <linux/iio/buffer.h>
30#include <linux/iio/trigger.h>
31#include <linux/iio/trigger_consumer.h>
32#include <linux/iio/triggered_buffer.h>
33#include <linux/pm_runtime.h>
34
35#define ATLAS_REGMAP_NAME "atlas_ph_regmap"
36#define ATLAS_DRV_NAME "atlas_ph"
37
38#define ATLAS_REG_DEV_TYPE 0x00
39#define ATLAS_REG_DEV_VERSION 0x01
40
41#define ATLAS_REG_INT_CONTROL 0x04
42#define ATLAS_REG_INT_CONTROL_EN BIT(3)
43
44#define ATLAS_REG_PWR_CONTROL 0x06
45
46#define ATLAS_REG_CALIB_STATUS 0x0d
47#define ATLAS_REG_CALIB_STATUS_MASK 0x07
48#define ATLAS_REG_CALIB_STATUS_LOW BIT(0)
49#define ATLAS_REG_CALIB_STATUS_MID BIT(1)
50#define ATLAS_REG_CALIB_STATUS_HIGH BIT(2)
51
52#define ATLAS_REG_TEMP_DATA 0x0e
53#define ATLAS_REG_PH_DATA 0x16
54
55#define ATLAS_PH_INT_TIME_IN_US 450000
56
57struct atlas_data {
58 struct i2c_client *client;
59 struct iio_trigger *trig;
60 struct regmap *regmap;
61 struct irq_work work;
62
63 __be32 buffer[4]; /* 32-bit pH data + 32-bit pad + 64-bit timestamp */
64};
65
66static const struct regmap_range atlas_volatile_ranges[] = {
67 regmap_reg_range(ATLAS_REG_INT_CONTROL, ATLAS_REG_INT_CONTROL),
68 regmap_reg_range(ATLAS_REG_CALIB_STATUS, ATLAS_REG_CALIB_STATUS),
69 regmap_reg_range(ATLAS_REG_TEMP_DATA, ATLAS_REG_TEMP_DATA + 4),
70 regmap_reg_range(ATLAS_REG_PH_DATA, ATLAS_REG_PH_DATA + 4),
71};
72
73static const struct regmap_access_table atlas_volatile_table = {
74 .yes_ranges = atlas_volatile_ranges,
75 .n_yes_ranges = ARRAY_SIZE(atlas_volatile_ranges),
76};
77
78static const struct regmap_config atlas_regmap_config = {
79 .name = ATLAS_REGMAP_NAME,
80
81 .reg_bits = 8,
82 .val_bits = 8,
83
84 .volatile_table = &atlas_volatile_table,
85 .max_register = ATLAS_REG_PH_DATA + 4,
86 .cache_type = REGCACHE_FLAT,
87};
88
89static const struct iio_chan_spec atlas_channels[] = {
90 {
91 .type = IIO_PH,
92 .info_mask_separate =
93 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
94 .scan_index = 0,
95 .scan_type = {
96 .sign = 'u',
97 .realbits = 32,
98 .storagebits = 32,
99 .endianness = IIO_BE,
100 },
101 },
102 IIO_CHAN_SOFT_TIMESTAMP(1),
103 {
104 .type = IIO_TEMP,
105 .address = ATLAS_REG_TEMP_DATA,
106 .info_mask_separate =
107 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
108 .output = 1,
109 .scan_index = -1
110 },
111};
112
113static int atlas_set_powermode(struct atlas_data *data, int on)
114{
115 return regmap_write(data->regmap, ATLAS_REG_PWR_CONTROL, on);
116}
117
118static int atlas_set_interrupt(struct atlas_data *data, bool state)
119{
120 return regmap_update_bits(data->regmap, ATLAS_REG_INT_CONTROL,
121 ATLAS_REG_INT_CONTROL_EN,
122 state ? ATLAS_REG_INT_CONTROL_EN : 0);
123}
124
125static int atlas_buffer_postenable(struct iio_dev *indio_dev)
126{
127 struct atlas_data *data = iio_priv(indio_dev);
128 int ret;
129
130 ret = iio_triggered_buffer_postenable(indio_dev);
131 if (ret)
132 return ret;
133
134 ret = pm_runtime_get_sync(&data->client->dev);
135 if (ret < 0) {
136 pm_runtime_put_noidle(&data->client->dev);
137 return ret;
138 }
139
140 return atlas_set_interrupt(data, true);
141}
142
143static int atlas_buffer_predisable(struct iio_dev *indio_dev)
144{
145 struct atlas_data *data = iio_priv(indio_dev);
146 int ret;
147
148 ret = iio_triggered_buffer_predisable(indio_dev);
149 if (ret)
150 return ret;
151
152 ret = atlas_set_interrupt(data, false);
153 if (ret)
154 return ret;
155
156 pm_runtime_mark_last_busy(&data->client->dev);
157 return pm_runtime_put_autosuspend(&data->client->dev);
158}
159
160static const struct iio_trigger_ops atlas_interrupt_trigger_ops = {
161 .owner = THIS_MODULE,
162};
163
164static const struct iio_buffer_setup_ops atlas_buffer_setup_ops = {
165 .postenable = atlas_buffer_postenable,
166 .predisable = atlas_buffer_predisable,
167};
168
169static void atlas_work_handler(struct irq_work *work)
170{
171 struct atlas_data *data = container_of(work, struct atlas_data, work);
172
173 iio_trigger_poll(data->trig);
174}
175
176static irqreturn_t atlas_trigger_handler(int irq, void *private)
177{
178 struct iio_poll_func *pf = private;
179 struct iio_dev *indio_dev = pf->indio_dev;
180 struct atlas_data *data = iio_priv(indio_dev);
181 int ret;
182
183 ret = i2c_smbus_read_i2c_block_data(data->client, ATLAS_REG_PH_DATA,
184 sizeof(data->buffer[0]), (u8 *) &data->buffer);
185
186 if (ret > 0)
187 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
188 iio_get_time_ns());
189
190 iio_trigger_notify_done(indio_dev->trig);
191
192 return IRQ_HANDLED;
193}
194
195static irqreturn_t atlas_interrupt_handler(int irq, void *private)
196{
197 struct iio_dev *indio_dev = private;
198 struct atlas_data *data = iio_priv(indio_dev);
199
200 irq_work_queue(&data->work);
201
202 return IRQ_HANDLED;
203}
204
205static int atlas_read_ph_measurement(struct atlas_data *data, __be32 *val)
206{
207 struct device *dev = &data->client->dev;
208 int suspended = pm_runtime_suspended(dev);
209 int ret;
210
211 ret = pm_runtime_get_sync(dev);
212 if (ret < 0) {
213 pm_runtime_put_noidle(dev);
214 return ret;
215 }
216
217 if (suspended)
218 usleep_range(ATLAS_PH_INT_TIME_IN_US,
219 ATLAS_PH_INT_TIME_IN_US + 100000);
220
221 ret = regmap_bulk_read(data->regmap, ATLAS_REG_PH_DATA,
222 (u8 *) val, sizeof(*val));
223
224 pm_runtime_mark_last_busy(dev);
225 pm_runtime_put_autosuspend(dev);
226
227 return ret;
228}
229
230static int atlas_read_raw(struct iio_dev *indio_dev,
231 struct iio_chan_spec const *chan,
232 int *val, int *val2, long mask)
233{
234 struct atlas_data *data = iio_priv(indio_dev);
235
236 switch (mask) {
237 case IIO_CHAN_INFO_RAW: {
238 int ret;
239 __be32 reg;
240
241 switch (chan->type) {
242 case IIO_TEMP:
243 ret = regmap_bulk_read(data->regmap, chan->address,
244 (u8 *) &reg, sizeof(reg));
245 break;
246 case IIO_PH:
247 mutex_lock(&indio_dev->mlock);
248
249 if (iio_buffer_enabled(indio_dev))
250 ret = -EBUSY;
251 else
252 ret = atlas_read_ph_measurement(data, &reg);
253
254 mutex_unlock(&indio_dev->mlock);
255 break;
256 default:
257 ret = -EINVAL;
258 }
259
260 if (!ret) {
261 *val = be32_to_cpu(reg);
262 ret = IIO_VAL_INT;
263 }
264 return ret;
265 }
266 case IIO_CHAN_INFO_SCALE:
267 switch (chan->type) {
268 case IIO_TEMP:
269 *val = 1; /* 0.01 */
270 *val2 = 100;
271 break;
272 case IIO_PH:
273 *val = 1; /* 0.001 */
274 *val2 = 1000;
275 break;
276 default:
277 return -EINVAL;
278 }
279 return IIO_VAL_FRACTIONAL;
280 }
281
282 return -EINVAL;
283}
284
285static int atlas_write_raw(struct iio_dev *indio_dev,
286 struct iio_chan_spec const *chan,
287 int val, int val2, long mask)
288{
289 struct atlas_data *data = iio_priv(indio_dev);
290 __be32 reg = cpu_to_be32(val);
291
292 if (val2 != 0 || val < 0 || val > 20000)
293 return -EINVAL;
294
295 if (mask != IIO_CHAN_INFO_RAW || chan->type != IIO_TEMP)
296 return -EINVAL;
297
298 return regmap_bulk_write(data->regmap, chan->address,
299 &reg, sizeof(reg));
300}
301
302static const struct iio_info atlas_info = {
303 .driver_module = THIS_MODULE,
304 .read_raw = atlas_read_raw,
305 .write_raw = atlas_write_raw,
306};
307
308static int atlas_check_calibration(struct atlas_data *data)
309{
310 struct device *dev = &data->client->dev;
311 int ret;
312 unsigned int val;
313
314 ret = regmap_read(data->regmap, ATLAS_REG_CALIB_STATUS, &val);
315 if (ret)
316 return ret;
317
318 if (!(val & ATLAS_REG_CALIB_STATUS_MASK)) {
319 dev_warn(dev, "device has not been calibrated\n");
320 return 0;
321 }
322
323 if (!(val & ATLAS_REG_CALIB_STATUS_LOW))
324 dev_warn(dev, "device missing low point calibration\n");
325
326 if (!(val & ATLAS_REG_CALIB_STATUS_MID))
327 dev_warn(dev, "device missing mid point calibration\n");
328
329 if (!(val & ATLAS_REG_CALIB_STATUS_HIGH))
330 dev_warn(dev, "device missing high point calibration\n");
331
332 return 0;
333};
334
335static int atlas_probe(struct i2c_client *client,
336 const struct i2c_device_id *id)
337{
338 struct atlas_data *data;
339 struct iio_trigger *trig;
340 struct iio_dev *indio_dev;
341 int ret;
342
343 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
344 if (!indio_dev)
345 return -ENOMEM;
346
347 indio_dev->info = &atlas_info;
348 indio_dev->name = ATLAS_DRV_NAME;
349 indio_dev->channels = atlas_channels;
350 indio_dev->num_channels = ARRAY_SIZE(atlas_channels);
351 indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE;
352 indio_dev->dev.parent = &client->dev;
353
354 trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
355 indio_dev->name, indio_dev->id);
356
357 if (!trig)
358 return -ENOMEM;
359
360 data = iio_priv(indio_dev);
361 data->client = client;
362 data->trig = trig;
363 trig->dev.parent = indio_dev->dev.parent;
364 trig->ops = &atlas_interrupt_trigger_ops;
365 iio_trigger_set_drvdata(trig, indio_dev);
366
367 i2c_set_clientdata(client, indio_dev);
368
369 data->regmap = devm_regmap_init_i2c(client, &atlas_regmap_config);
370 if (IS_ERR(data->regmap)) {
371 dev_err(&client->dev, "regmap initialization failed\n");
372 return PTR_ERR(data->regmap);
373 }
374
375 ret = pm_runtime_set_active(&client->dev);
376 if (ret)
377 return ret;
378
379 if (client->irq <= 0) {
380 dev_err(&client->dev, "no valid irq defined\n");
381 return -EINVAL;
382 }
383
384 ret = atlas_check_calibration(data);
385 if (ret)
386 return ret;
387
388 ret = iio_trigger_register(trig);
389 if (ret) {
390 dev_err(&client->dev, "failed to register trigger\n");
391 return ret;
392 }
393
394 ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
395 &atlas_trigger_handler, &atlas_buffer_setup_ops);
396 if (ret) {
397 dev_err(&client->dev, "cannot setup iio trigger\n");
398 goto unregister_trigger;
399 }
400
401 init_irq_work(&data->work, atlas_work_handler);
402
403 /* interrupt pin toggles on new conversion */
404 ret = devm_request_threaded_irq(&client->dev, client->irq,
405 NULL, atlas_interrupt_handler,
406 IRQF_TRIGGER_RISING |
407 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
408 "atlas_irq",
409 indio_dev);
410 if (ret) {
411 dev_err(&client->dev, "request irq (%d) failed\n", client->irq);
412 goto unregister_buffer;
413 }
414
415 ret = atlas_set_powermode(data, 1);
416 if (ret) {
417 dev_err(&client->dev, "cannot power device on");
418 goto unregister_buffer;
419 }
420
421 pm_runtime_enable(&client->dev);
422 pm_runtime_set_autosuspend_delay(&client->dev, 2500);
423 pm_runtime_use_autosuspend(&client->dev);
424
425 ret = iio_device_register(indio_dev);
426 if (ret) {
427 dev_err(&client->dev, "unable to register device\n");
428 goto unregister_pm;
429 }
430
431 return 0;
432
433unregister_pm:
434 pm_runtime_disable(&client->dev);
435 atlas_set_powermode(data, 0);
436
437unregister_buffer:
438 iio_triggered_buffer_cleanup(indio_dev);
439
440unregister_trigger:
441 iio_trigger_unregister(data->trig);
442
443 return ret;
444}
445
446static int atlas_remove(struct i2c_client *client)
447{
448 struct iio_dev *indio_dev = i2c_get_clientdata(client);
449 struct atlas_data *data = iio_priv(indio_dev);
450
451 iio_device_unregister(indio_dev);
452 iio_triggered_buffer_cleanup(indio_dev);
453 iio_trigger_unregister(data->trig);
454
455 pm_runtime_disable(&client->dev);
456 pm_runtime_set_suspended(&client->dev);
457 pm_runtime_put_noidle(&client->dev);
458
459 return atlas_set_powermode(data, 0);
460}
461
462#ifdef CONFIG_PM
463static int atlas_runtime_suspend(struct device *dev)
464{
465 struct atlas_data *data =
466 iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
467
468 return atlas_set_powermode(data, 0);
469}
470
471static int atlas_runtime_resume(struct device *dev)
472{
473 struct atlas_data *data =
474 iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
475
476 return atlas_set_powermode(data, 1);
477}
478#endif
479
480static const struct dev_pm_ops atlas_pm_ops = {
481 SET_RUNTIME_PM_OPS(atlas_runtime_suspend,
482 atlas_runtime_resume, NULL)
483};
484
485static const struct i2c_device_id atlas_id[] = {
486 { "atlas-ph-sm", 0 },
487 {}
488};
489MODULE_DEVICE_TABLE(i2c, atlas_id);
490
491static const struct of_device_id atlas_dt_ids[] = {
492 { .compatible = "atlas,ph-sm" },
493 { }
494};
495MODULE_DEVICE_TABLE(of, atlas_dt_ids);
496
497static struct i2c_driver atlas_driver = {
498 .driver = {
499 .name = ATLAS_DRV_NAME,
500 .of_match_table = of_match_ptr(atlas_dt_ids),
501 .pm = &atlas_pm_ops,
502 },
503 .probe = atlas_probe,
504 .remove = atlas_remove,
505 .id_table = atlas_id,
506};
507module_i2c_driver(atlas_driver);
508
509MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
510MODULE_DESCRIPTION("Atlas Scientific pH-SM sensor");
511MODULE_LICENSE("GPL");
drivers/iio/common/st_sensors/st_sensors_core.c+4−2
@@ -18,13 +18,15 @@ · 17 unmodified lines
18#include <asm/unaligned.h>18#include <asm/unaligned.h>
19#include <linux/iio/common/st_sensors.h>19#include <linux/iio/common/st_sensors.h>
20 20
21#include "st_sensors_core.h"
22
21static inline u32 st_sensors_get_unaligned_le24(const u8 *p)23static inline u32 st_sensors_get_unaligned_le24(const u8 *p)
22{24{
23 return (s32)((p[0] | p[1] << 8 | p[2] << 16) << 8) >> 8;25 return (s32)((p[0] | p[1] << 8 | p[2] << 16) << 8) >> 8;
24}26}
25 27
26static int st_sensors_write_data_with_mask(struct iio_dev *indio_dev,28int st_sensors_write_data_with_mask(struct iio_dev *indio_dev,
27 u8 reg_addr, u8 mask, u8 data)29 u8 reg_addr, u8 mask, u8 data)
28{30{
29 int err;31 int err;
30 u8 new_data;32 u8 new_data;
drivers/iio/common/st_sensors/st_sensors_core.h+8−0
@@ -0,0 +1,8 @@
1/*
2 * Local functions in the ST Sensors core
3 */
4#ifndef __ST_SENSORS_CORE_H
5#define __ST_SENSORS_CORE_H
6int st_sensors_write_data_with_mask(struct iio_dev *indio_dev,
7 u8 reg_addr, u8 mask, u8 data);
8#endif
drivers/iio/common/st_sensors/st_sensors_trigger.c+42−10
@@ -14,32 +14,65 @@ · 13 unmodified lines
14#include <linux/iio/iio.h>14#include <linux/iio/iio.h>
15#include <linux/iio/trigger.h>15#include <linux/iio/trigger.h>
16#include <linux/interrupt.h>16#include <linux/interrupt.h>
17
18#include <linux/iio/common/st_sensors.h>17#include <linux/iio/common/st_sensors.h>
19 18#include "st_sensors_core.h"
20 19
21int st_sensors_allocate_trigger(struct iio_dev *indio_dev,20int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
22 const struct iio_trigger_ops *trigger_ops)21 const struct iio_trigger_ops *trigger_ops)
23{22{
24 int err;23 int err, irq;
25 struct st_sensor_data *sdata = iio_priv(indio_dev);24 struct st_sensor_data *sdata = iio_priv(indio_dev);
25 unsigned long irq_trig;
26 26
27 sdata->trig = iio_trigger_alloc("%s-trigger", indio_dev->name);27 sdata->trig = iio_trigger_alloc("%s-trigger", indio_dev->name);
28 if (sdata->trig == NULL) {28 if (sdata->trig == NULL) {
29 err = -ENOMEM;
30 dev_err(&indio_dev->dev, "failed to allocate iio trigger.\n");29 dev_err(&indio_dev->dev, "failed to allocate iio trigger.\n");
31 goto iio_trigger_alloc_error;30 return -ENOMEM;
32 }31 }
33 32
34 err = request_threaded_irq(sdata->get_irq_data_ready(indio_dev),33 irq = sdata->get_irq_data_ready(indio_dev);
34 irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq));
35 /*
36 * If the IRQ is triggered on falling edge, we need to mark the
37 * interrupt as active low, if the hardware supports this.
38 */
39 if (irq_trig == IRQF_TRIGGER_FALLING) {
40 if (!sdata->sensor_settings->drdy_irq.addr_ihl) {
41 dev_err(&indio_dev->dev,
42 "falling edge specified for IRQ but hardware "
43 "only support rising edge, will request "
44 "rising edge\n");
45 irq_trig = IRQF_TRIGGER_RISING;
46 } else {
47 /* Set up INT active low i.e. falling edge */
48 err = st_sensors_write_data_with_mask(indio_dev,
49 sdata->sensor_settings->drdy_irq.addr_ihl,
50 sdata->sensor_settings->drdy_irq.mask_ihl, 1);
51 if (err < 0)
52 goto iio_trigger_free;
53 dev_info(&indio_dev->dev,
54 "interrupts on the falling edge\n");
55 }
56 } else if (irq_trig == IRQF_TRIGGER_RISING) {
57 dev_info(&indio_dev->dev,
58 "interrupts on the rising edge\n");
59
60 } else {
61 dev_err(&indio_dev->dev,
62 "unsupported IRQ trigger specified (%lx), only "
63 "rising and falling edges supported, enforce "
64 "rising edge\n", irq_trig);
65 irq_trig = IRQF_TRIGGER_RISING;
66 }
67 err = request_threaded_irq(irq,
35 iio_trigger_generic_data_rdy_poll,68 iio_trigger_generic_data_rdy_poll,
36 NULL,69 NULL,
37 IRQF_TRIGGER_RISING,70 irq_trig,
38 sdata->trig->name,71 sdata->trig->name,
39 sdata->trig);72 sdata->trig);
40 if (err) {73 if (err) {
41 dev_err(&indio_dev->dev, "failed to request trigger IRQ.\n");74 dev_err(&indio_dev->dev, "failed to request trigger IRQ.\n");
42 goto request_irq_error;75 goto iio_trigger_free;
43 }76 }
44 77
45 iio_trigger_set_drvdata(sdata->trig, indio_dev);78 iio_trigger_set_drvdata(sdata->trig, indio_dev);
@@ -57,9 +90,8 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev, · 11 unmodified lines
57 90
58iio_trigger_register_error:91iio_trigger_register_error:
59 free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig);92 free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig);
60request_irq_error:93iio_trigger_free:
61 iio_trigger_free(sdata->trig);94 iio_trigger_free(sdata->trig);
62iio_trigger_alloc_error:
63 return err;95 return err;
64}96}
65EXPORT_SYMBOL(st_sensors_allocate_trigger);97EXPORT_SYMBOL(st_sensors_allocate_trigger);
drivers/iio/dac/Kconfig+12−2
@@ -111,6 +111,16 @@ config AD5755 · 110 unmodified lines
111 To compile this driver as a module, choose M here: the111 To compile this driver as a module, choose M here: the
112 module will be called ad5755.112 module will be called ad5755.
113 113
114config AD5761
115 tristate "Analog Devices AD5761/61R/21/21R DAC driver"
116 depends on SPI_MASTER
117 help
118 Say yes here to build support for Analog Devices AD5761, AD5761R, AD5721,
119 AD5721R Digital to Analog Converter.
120
121 To compile this driver as a module, choose M here: the
122 module will be called ad5761.
123
114config AD5764124config AD5764
115 tristate "Analog Devices AD5764/64R/44/44R DAC driver"125 tristate "Analog Devices AD5764/64R/44/44R DAC driver"
116 depends on SPI_MASTER126 depends on SPI_MASTER
@@ -176,11 +186,11 @@ config MAX5821 · 59 unmodified lines
176 10 bits DAC.186 10 bits DAC.
177 187
178config MCP4725188config MCP4725
179 tristate "MCP4725 DAC driver"189 tristate "MCP4725/6 DAC driver"
180 depends on I2C190 depends on I2C
181 ---help---191 ---help---
182 Say Y here if you want to build a driver for the Microchip192 Say Y here if you want to build a driver for the Microchip
183 MCP 4725 12-bit digital-to-analog converter (DAC) with I2C193 MCP 4725/6 12-bit digital-to-analog converter (DAC) with I2C
184 interface.194 interface.
185 195
186 To compile this driver as a module, choose M here: the module196 To compile this driver as a module, choose M here: the module
drivers/iio/dac/Makefile+1−0
@@ -12,6 +12,7 @@ obj-$(CONFIG_AD5504) += ad5504.o · 11 unmodified lines
12obj-$(CONFIG_AD5446) += ad5446.o12obj-$(CONFIG_AD5446) += ad5446.o
13obj-$(CONFIG_AD5449) += ad5449.o13obj-$(CONFIG_AD5449) += ad5449.o
14obj-$(CONFIG_AD5755) += ad5755.o14obj-$(CONFIG_AD5755) += ad5755.o
15obj-$(CONFIG_AD5761) += ad5761.o
15obj-$(CONFIG_AD5764) += ad5764.o16obj-$(CONFIG_AD5764) += ad5764.o
16obj-$(CONFIG_AD5791) += ad5791.o17obj-$(CONFIG_AD5791) += ad5791.o
17obj-$(CONFIG_AD5686) += ad5686.o18obj-$(CONFIG_AD5686) += ad5686.o
drivers/iio/dac/ad5761.c+430−0
@@ -0,0 +1,430 @@
1/*
2 * AD5721, AD5721R, AD5761, AD5761R, Voltage Output Digital to Analog Converter
3 *
4 * Copyright 2016 Qtechnology A/S
5 * 2016 Ricardo Ribalda <ricardo.ribalda@gmail.com>
6 *
7 * Licensed under the GPL-2.
8 */
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/spi/spi.h>
12#include <linux/bitops.h>
13#include <linux/iio/iio.h>
14#include <linux/iio/sysfs.h>
15#include <linux/regulator/consumer.h>
16#include <linux/platform_data/ad5761.h>
17
18#define AD5761_ADDR(addr) ((addr & 0xf) << 16)
19#define AD5761_ADDR_NOOP 0x0
20#define AD5761_ADDR_DAC_WRITE 0x3
21#define AD5761_ADDR_CTRL_WRITE_REG 0x4
22#define AD5761_ADDR_SW_DATA_RESET 0x7
23#define AD5761_ADDR_DAC_READ 0xb
24#define AD5761_ADDR_CTRL_READ_REG 0xc
25#define AD5761_ADDR_SW_FULL_RESET 0xf
26
27#define AD5761_CTRL_USE_INTVREF BIT(5)
28#define AD5761_CTRL_ETS BIT(6)
29
30/**
31 * struct ad5761_chip_info - chip specific information
32 * @int_vref: Value of the internal reference voltage in mV - 0 if external
33 * reference voltage is used
34 * @channel: channel specification
35*/
36
37struct ad5761_chip_info {
38 unsigned long int_vref;
39 const struct iio_chan_spec channel;
40};
41
42struct ad5761_range_params {
43 int m;
44 int c;
45};
46
47enum ad5761_supported_device_ids {
48 ID_AD5721,
49 ID_AD5721R,
50 ID_AD5761,
51 ID_AD5761R,
52};
53
54/**
55 * struct ad5761_state - driver instance specific data
56 * @spi: spi_device
57 * @vref_reg: reference voltage regulator
58 * @use_intref: true when the internal voltage reference is used
59 * @vref: actual voltage reference in mVolts
60 * @range: output range mode used
61 * @data: cache aligned spi buffer
62 */
63struct ad5761_state {
64 struct spi_device *spi;
65 struct regulator *vref_reg;
66
67 bool use_intref;
68 int vref;
69 enum ad5761_voltage_range range;
70
71 /*
72 * DMA (thus cache coherency maintenance) requires the
73 * transfer buffers to live in their own cache lines.
74 */
75 union {
76 __be32 d32;
77 u8 d8[4];
78 } data[3] ____cacheline_aligned;
79};
80
81static const struct ad5761_range_params ad5761_range_params[] = {
82 [AD5761_VOLTAGE_RANGE_M10V_10V] = {
83 .m = 80,
84 .c = 40,
85 },
86 [AD5761_VOLTAGE_RANGE_0V_10V] = {
87 .m = 40,
88 .c = 0,
89 },
90 [AD5761_VOLTAGE_RANGE_M5V_5V] = {
91 .m = 40,
92 .c = 20,
93 },
94 [AD5761_VOLTAGE_RANGE_0V_5V] = {
95 .m = 20,
96 .c = 0,
97 },
98 [AD5761_VOLTAGE_RANGE_M2V5_7V5] = {
99 .m = 40,
100 .c = 10,
101 },
102 [AD5761_VOLTAGE_RANGE_M3V_3V] = {
103 .m = 24,
104 .c = 12,
105 },
106 [AD5761_VOLTAGE_RANGE_0V_16V] = {
107 .m = 64,
108 .c = 0,
109 },
110 [AD5761_VOLTAGE_RANGE_0V_20V] = {
111 .m = 80,
112 .c = 0,
113 },
114};
115
116static int _ad5761_spi_write(struct ad5761_state *st, u8 addr, u16 val)
117{
118 st->data[0].d32 = cpu_to_be32(AD5761_ADDR(addr) | val);
119
120 return spi_write(st->spi, &st->data[0].d8[1], 3);
121}
122
123static int ad5761_spi_write(struct iio_dev *indio_dev, u8 addr, u16 val)
124{
125 struct ad5761_state *st = iio_priv(indio_dev);
126 int ret;
127
128 mutex_lock(&indio_dev->mlock);
129 ret = _ad5761_spi_write(st, addr, val);
130 mutex_unlock(&indio_dev->mlock);
131
132 return ret;
133}
134
135static int _ad5761_spi_read(struct ad5761_state *st, u8 addr, u16 *val)
136{
137 int ret;
138 struct spi_transfer xfers[] = {
139 {
140 .tx_buf = &st->data[0].d8[1],
141 .bits_per_word = 8,
142 .len = 3,
143 .cs_change = true,
144 }, {
145 .tx_buf = &st->data[1].d8[1],
146 .rx_buf = &st->data[2].d8[1],
147 .bits_per_word = 8,
148 .len = 3,
149 },
150 };
151
152 st->data[0].d32 = cpu_to_be32(AD5761_ADDR(addr));
153 st->data[1].d32 = cpu_to_be32(AD5761_ADDR(AD5761_ADDR_NOOP));
154
155 ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
156
157 *val = be32_to_cpu(st->data[2].d32);
158
159 return ret;
160}
161
162static int ad5761_spi_read(struct iio_dev *indio_dev, u8 addr, u16 *val)
163{
164 struct ad5761_state *st = iio_priv(indio_dev);
165 int ret;
166
167 mutex_lock(&indio_dev->mlock);
168 ret = _ad5761_spi_read(st, addr, val);
169 mutex_unlock(&indio_dev->mlock);
170
171 return ret;
172}
173
174static int ad5761_spi_set_range(struct ad5761_state *st,
175 enum ad5761_voltage_range range)
176{
177 u16 aux;
178 int ret;
179
180 aux = (range & 0x7) | AD5761_CTRL_ETS;
181
182 if (st->use_intref)
183 aux |= AD5761_CTRL_USE_INTVREF;
184
185 ret = _ad5761_spi_write(st, AD5761_ADDR_SW_FULL_RESET, 0);
186 if (ret)
187 return ret;
188
189 ret = _ad5761_spi_write(st, AD5761_ADDR_CTRL_WRITE_REG, aux);
190 if (ret)
191 return ret;
192
193 st->range = range;
194
195 return 0;
196}
197
198static int ad5761_read_raw(struct iio_dev *indio_dev,
199 struct iio_chan_spec const *chan,
200 int *val,
201 int *val2,
202 long mask)
203{
204 struct ad5761_state *st;
205 int ret;
206 u16 aux;
207
208 switch (mask) {
209 case IIO_CHAN_INFO_RAW:
210 ret = ad5761_spi_read(indio_dev, AD5761_ADDR_DAC_READ, &aux);
211 if (ret)
212 return ret;
213 *val = aux >> chan->scan_type.shift;
214 return IIO_VAL_INT;
215 case IIO_CHAN_INFO_SCALE:
216 st = iio_priv(indio_dev);
217 *val = st->vref * ad5761_range_params[st->range].m;
218 *val /= 10;
219 *val2 = chan->scan_type.realbits;
220 return IIO_VAL_FRACTIONAL_LOG2;
221 case IIO_CHAN_INFO_OFFSET:
222 st = iio_priv(indio_dev);
223 *val = -(1 << chan->scan_type.realbits);
224 *val *= ad5761_range_params[st->range].c;
225 *val /= ad5761_range_params[st->range].m;
226 return IIO_VAL_INT;
227 default:
228 return -EINVAL;
229 }
230}
231
232static int ad5761_write_raw(struct iio_dev *indio_dev,
233 struct iio_chan_spec const *chan,
234 int val,
235 int val2,
236 long mask)
237{
238 u16 aux;
239
240 if (mask != IIO_CHAN_INFO_RAW)
241 return -EINVAL;
242
243 if (val2 || (val << chan->scan_type.shift) > 0xffff || val < 0)
244 return -EINVAL;
245
246 aux = val << chan->scan_type.shift;
247
248 return ad5761_spi_write(indio_dev, AD5761_ADDR_DAC_WRITE, aux);
249}
250
251static const struct iio_info ad5761_info = {
252 .read_raw = &ad5761_read_raw,
253 .write_raw = &ad5761_write_raw,
254 .driver_module = THIS_MODULE,
255};
256
257#define AD5761_CHAN(_bits) { \
258 .type = IIO_VOLTAGE, \
259 .output = 1, \
260 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
261 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
262 BIT(IIO_CHAN_INFO_OFFSET), \
263 .scan_type = { \
264 .sign = 'u', \
265 .realbits = (_bits), \
266 .storagebits = 16, \
267 .shift = 16 - (_bits), \
268 }, \
269}
270
271static const struct ad5761_chip_info ad5761_chip_infos[] = {
272 [ID_AD5721] = {
273 .int_vref = 0,
274 .channel = AD5761_CHAN(12),
275 },
276 [ID_AD5721R] = {
277 .int_vref = 2500,
278 .channel = AD5761_CHAN(12),
279 },
280 [ID_AD5761] = {
281 .int_vref = 0,
282 .channel = AD5761_CHAN(16),
283 },
284 [ID_AD5761R] = {
285 .int_vref = 2500,
286 .channel = AD5761_CHAN(16),
287 },
288};
289
290static int ad5761_get_vref(struct ad5761_state *st,
291 const struct ad5761_chip_info *chip_info)
292{
293 int ret;
294
295 st->vref_reg = devm_regulator_get_optional(&st->spi->dev, "vref");
296 if (PTR_ERR(st->vref_reg) == -ENODEV) {
297 /* Use Internal regulator */
298 if (!chip_info->int_vref) {
299 dev_err(&st->spi->dev,
300 "Voltage reference not found\n");
301 return -EIO;
302 }
303
304 st->use_intref = true;
305 st->vref = chip_info->int_vref;
306 return 0;
307 }
308
309 if (IS_ERR(st->vref_reg)) {
310 dev_err(&st->spi->dev,
311 "Error getting voltage reference regulator\n");
312 return PTR_ERR(st->vref_reg);
313 }
314
315 ret = regulator_enable(st->vref_reg);
316 if (ret) {
317 dev_err(&st->spi->dev,
318 "Failed to enable voltage reference\n");
319 return ret;
320 }
321
322 ret = regulator_get_voltage(st->vref_reg);
323 if (ret < 0) {
324 dev_err(&st->spi->dev,
325 "Failed to get voltage reference value\n");
326 goto disable_regulator_vref;
327 }
328
329 if (ret < 2000000 || ret > 3000000) {
330 dev_warn(&st->spi->dev,
331 "Invalid external voltage ref. value %d uV\n", ret);
332 ret = -EIO;
333 goto disable_regulator_vref;
334 }
335
336 st->vref = ret / 1000;
337 st->use_intref = false;
338
339 return 0;
340
341disable_regulator_vref:
342 regulator_disable(st->vref_reg);
343 st->vref_reg = NULL;
344 return ret;
345}
346
347static int ad5761_probe(struct spi_device *spi)
348{
349 struct iio_dev *iio_dev;
350 struct ad5761_state *st;
351 int ret;
352 const struct ad5761_chip_info *chip_info =
353 &ad5761_chip_infos[spi_get_device_id(spi)->driver_data];
354 enum ad5761_voltage_range voltage_range = AD5761_VOLTAGE_RANGE_0V_5V;
355 struct ad5761_platform_data *pdata = dev_get_platdata(&spi->dev);
356
357 iio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
358 if (!iio_dev)
359 return -ENOMEM;
360
361 st = iio_priv(iio_dev);
362
363 st->spi = spi;
364 spi_set_drvdata(spi, iio_dev);
365
366 ret = ad5761_get_vref(st, chip_info);
367 if (ret)
368 return ret;
369
370 if (pdata)
371 voltage_range = pdata->voltage_range;
372
373 ret = ad5761_spi_set_range(st, voltage_range);
374 if (ret)
375 goto disable_regulator_err;
376
377 iio_dev->dev.parent = &spi->dev;
378 iio_dev->info = &ad5761_info;
379 iio_dev->modes = INDIO_DIRECT_MODE;
380 iio_dev->channels = &chip_info->channel;
381 iio_dev->num_channels = 1;
382 iio_dev->name = spi_get_device_id(st->spi)->name;
383 ret = iio_device_register(iio_dev);
384 if (ret)
385 goto disable_regulator_err;
386
387 return 0;
388
389disable_regulator_err:
390 if (!IS_ERR_OR_NULL(st->vref_reg))
391 regulator_disable(st->vref_reg);
392
393 return ret;
394}
395
396static int ad5761_remove(struct spi_device *spi)
397{
398 struct iio_dev *iio_dev = spi_get_drvdata(spi);
399 struct ad5761_state *st = iio_priv(iio_dev);
400
401 iio_device_unregister(iio_dev);
402
403 if (!IS_ERR_OR_NULL(st->vref_reg))
404 regulator_disable(st->vref_reg);
405
406 return 0;
407}
408
409static const struct spi_device_id ad5761_id[] = {
410 {"ad5721", ID_AD5721},
411 {"ad5721r", ID_AD5721R},
412 {"ad5761", ID_AD5761},
413 {"ad5761r", ID_AD5761R},
414 {}
415};
416MODULE_DEVICE_TABLE(spi, ad5761_id);
417
418static struct spi_driver ad5761_driver = {
419 .driver = {
420 .name = "ad5761",
421 },
422 .probe = ad5761_probe,
423 .remove = ad5761_remove,
424 .id_table = ad5761_id,
425};
426module_spi_driver(ad5761_driver);
427
428MODULE_AUTHOR("Ricardo Ribalda <ricardo.ribalda@gmail.com>");
429MODULE_DESCRIPTION("Analog Devices AD5721, AD5721R, AD5761, AD5761R driver");
430MODULE_LICENSE("GPL v2");
drivers/iio/dac/mcp4725.c+67−20
@@ -1,5 +1,5 @@
1/*1/*
2 * mcp4725.c - Support for Microchip MCP47252 * mcp4725.c - Support for Microchip MCP4725/6
3 *3 *
4 * Copyright (C) 2012 Peter Meerwald <pmeerw@pmeerw.net>4 * Copyright (C) 2012 Peter Meerwald <pmeerw@pmeerw.net>
5 *5 *
@@ -134,6 +134,12 @@ static const char * const mcp4725_powerdown_modes[] = { · 128 unmodified lines
134 "500kohm_to_gnd"134 "500kohm_to_gnd"
135};135};
136 136
137static const char * const mcp4726_powerdown_modes[] = {
138 "1kohm_to_gnd",
139 "125kohm_to_gnd",
140 "640kohm_to_gnd"
141};
142
137static int mcp4725_get_powerdown_mode(struct iio_dev *indio_dev,143static int mcp4725_get_powerdown_mode(struct iio_dev *indio_dev,
138 const struct iio_chan_spec *chan)144 const struct iio_chan_spec *chan)
139{145{
@@ -182,11 +188,24 @@ static ssize_t mcp4725_write_powerdown(struct iio_dev *indio_dev, · 42 unmodified lines
182 return len;188 return len;
183}189}
184 190
185static const struct iio_enum mcp4725_powerdown_mode_enum = {191enum {
186 .items = mcp4725_powerdown_modes,192 MCP4725,
187 .num_items = ARRAY_SIZE(mcp4725_powerdown_modes),193 MCP4726,
188 .get = mcp4725_get_powerdown_mode,194};
189 .set = mcp4725_set_powerdown_mode,195
196static const struct iio_enum mcp472x_powerdown_mode_enum[] = {
197 [MCP4725] = {
198 .items = mcp4725_powerdown_modes,
199 .num_items = ARRAY_SIZE(mcp4725_powerdown_modes),
200 .get = mcp4725_get_powerdown_mode,
201 .set = mcp4725_set_powerdown_mode,
202 },
203 [MCP4726] = {
204 .items = mcp4726_powerdown_modes,
205 .num_items = ARRAY_SIZE(mcp4726_powerdown_modes),
206 .get = mcp4725_get_powerdown_mode,
207 .set = mcp4725_set_powerdown_mode,
208 },
190};209};
191 210
192static const struct iio_chan_spec_ext_info mcp4725_ext_info[] = {211static const struct iio_chan_spec_ext_info mcp4725_ext_info[] = {
@@ -196,19 +215,46 @@ static const struct iio_chan_spec_ext_info mcp4725_ext_info[] = { · 3 unmodified lines
196 .write = mcp4725_write_powerdown,215 .write = mcp4725_write_powerdown,
197 .shared = IIO_SEPARATE,216 .shared = IIO_SEPARATE,
198 },217 },
199 IIO_ENUM("powerdown_mode", IIO_SEPARATE, &mcp4725_powerdown_mode_enum),218 IIO_ENUM("powerdown_mode", IIO_SEPARATE,
200 IIO_ENUM_AVAILABLE("powerdown_mode", &mcp4725_powerdown_mode_enum),219 &mcp472x_powerdown_mode_enum[MCP4725]),
220 IIO_ENUM_AVAILABLE("powerdown_mode",
221 &mcp472x_powerdown_mode_enum[MCP4725]),
222 { },
223};
224
225static const struct iio_chan_spec_ext_info mcp4726_ext_info[] = {
226 {
227 .name = "powerdown",
228 .read = mcp4725_read_powerdown,
229 .write = mcp4725_write_powerdown,
230 .shared = IIO_SEPARATE,
231 },
232 IIO_ENUM("powerdown_mode", IIO_SEPARATE,
233 &mcp472x_powerdown_mode_enum[MCP4726]),
234 IIO_ENUM_AVAILABLE("powerdown_mode",
235 &mcp472x_powerdown_mode_enum[MCP4726]),
201 { },236 { },
202};237};
203 238
204static const struct iio_chan_spec mcp4725_channel = {239static const struct iio_chan_spec mcp472x_channel[] = {
205 .type = IIO_VOLTAGE,240 [MCP4725] = {
206 .indexed = 1,241 .type = IIO_VOLTAGE,
207 .output = 1,242 .indexed = 1,
208 .channel = 0,243 .output = 1,
209 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),244 .channel = 0,
210 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),245 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
211 .ext_info = mcp4725_ext_info,246 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
247 .ext_info = mcp4725_ext_info,
248 },
249 [MCP4726] = {
250 .type = IIO_VOLTAGE,
251 .indexed = 1,
252 .output = 1,
253 .channel = 0,
254 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
255 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
256 .ext_info = mcp4726_ext_info,
257 },
212};258};
213 259
214static int mcp4725_set_value(struct iio_dev *indio_dev, int val)260static int mcp4725_set_value(struct iio_dev *indio_dev, int val)
@@ -301,7 +347,7 @@ static int mcp4725_probe(struct i2c_client *client, · 86 unmodified lines
301 347
302 indio_dev->dev.parent = &client->dev;348 indio_dev->dev.parent = &client->dev;
303 indio_dev->info = &mcp4725_info;349 indio_dev->info = &mcp4725_info;
304 indio_dev->channels = &mcp4725_channel;350 indio_dev->channels = &mcp472x_channel[id->driver_data];
305 indio_dev->num_channels = 1;351 indio_dev->num_channels = 1;
306 indio_dev->modes = INDIO_DIRECT_MODE;352 indio_dev->modes = INDIO_DIRECT_MODE;
307 353
@@ -315,7 +361,7 @@ static int mcp4725_probe(struct i2c_client *client, · 7 unmodified lines
315 }361 }
316 pd = (inbuf[0] >> 1) & 0x3;362 pd = (inbuf[0] >> 1) & 0x3;
317 data->powerdown = pd > 0 ? true : false;363 data->powerdown = pd > 0 ? true : false;
318 data->powerdown_mode = pd ? pd-1 : 2; /* 500kohm_to_gnd */364 data->powerdown_mode = pd ? pd - 1 : 2; /* largest register to gnd */
319 data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4);365 data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4);
320 366
321 return iio_device_register(indio_dev);367 return iio_device_register(indio_dev);
@@ -328,7 +374,8 @@ static int mcp4725_remove(struct i2c_client *client) · 6 unmodified lines
328}374}
329 375
330static const struct i2c_device_id mcp4725_id[] = {376static const struct i2c_device_id mcp4725_id[] = {
331 { "mcp4725", 0 },377 { "mcp4725", MCP4725 },
378 { "mcp4726", MCP4726 },
332 { }379 { }
333};380};
334MODULE_DEVICE_TABLE(i2c, mcp4725_id);381MODULE_DEVICE_TABLE(i2c, mcp4725_id);
@@ -345,5 +392,5 @@ static struct i2c_driver mcp4725_driver = { · 10 unmodified lines
345module_i2c_driver(mcp4725_driver);392module_i2c_driver(mcp4725_driver);
346 393
347MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");394MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
348MODULE_DESCRIPTION("MCP4725 12-bit DAC");395MODULE_DESCRIPTION("MCP4725/6 12-bit DAC");
349MODULE_LICENSE("GPL");396MODULE_LICENSE("GPL");
drivers/iio/gyro/st_gyro_core.c+15−0
@@ -185,6 +185,11 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { · 184 unmodified lines
185 .drdy_irq = {185 .drdy_irq = {
186 .addr = ST_GYRO_1_DRDY_IRQ_ADDR,186 .addr = ST_GYRO_1_DRDY_IRQ_ADDR,
187 .mask_int2 = ST_GYRO_1_DRDY_IRQ_INT2_MASK,187 .mask_int2 = ST_GYRO_1_DRDY_IRQ_INT2_MASK,
188 /*
189 * The sensor has IHL (active low) and open
190 * drain settings, but only for INT1 and not
191 * for the DRDY line on INT2.
192 */
188 },193 },
189 .multi_read_bit = ST_GYRO_1_MULTIREAD_BIT,194 .multi_read_bit = ST_GYRO_1_MULTIREAD_BIT,
190 .bootime = 2,195 .bootime = 2,
@@ -248,6 +253,11 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { · 57 unmodified lines
248 .drdy_irq = {253 .drdy_irq = {
249 .addr = ST_GYRO_2_DRDY_IRQ_ADDR,254 .addr = ST_GYRO_2_DRDY_IRQ_ADDR,
250 .mask_int2 = ST_GYRO_2_DRDY_IRQ_INT2_MASK,255 .mask_int2 = ST_GYRO_2_DRDY_IRQ_INT2_MASK,
256 /*
257 * The sensor has IHL (active low) and open
258 * drain settings, but only for INT1 and not
259 * for the DRDY line on INT2.
260 */
251 },261 },
252 .multi_read_bit = ST_GYRO_2_MULTIREAD_BIT,262 .multi_read_bit = ST_GYRO_2_MULTIREAD_BIT,
253 .bootime = 2,263 .bootime = 2,
@@ -307,6 +317,11 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { · 53 unmodified lines
307 .drdy_irq = {317 .drdy_irq = {
308 .addr = ST_GYRO_3_DRDY_IRQ_ADDR,318 .addr = ST_GYRO_3_DRDY_IRQ_ADDR,
309 .mask_int2 = ST_GYRO_3_DRDY_IRQ_INT2_MASK,319 .mask_int2 = ST_GYRO_3_DRDY_IRQ_INT2_MASK,
320 /*
321 * The sensor has IHL (active low) and open
322 * drain settings, but only for INT1 and not
323 * for the DRDY line on INT2.
324 */
310 },325 },
311 .multi_read_bit = ST_GYRO_3_MULTIREAD_BIT,326 .multi_read_bit = ST_GYRO_3_MULTIREAD_BIT,
312 .bootime = 2,327 .bootime = 2,
drivers/iio/health/max30100.c+75−6
@@ -13,7 +13,7 @@ · 12 unmodified lines
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.14 * GNU General Public License for more details.
15 *15 *
16 * TODO: allow LED current and pulse length controls via device tree properties16 * TODO: enable pulse length controls via device tree properties
17 */17 */
18 18
19#include <linux/module.h>19#include <linux/module.h>
@@ -24,6 +24,7 @@ · 4 unmodified lines
24#include <linux/irq.h>24#include <linux/irq.h>
25#include <linux/i2c.h>25#include <linux/i2c.h>
26#include <linux/mutex.h>26#include <linux/mutex.h>
27#include <linux/of.h>
27#include <linux/regmap.h>28#include <linux/regmap.h>
28#include <linux/iio/iio.h>29#include <linux/iio/iio.h>
29#include <linux/iio/buffer.h>30#include <linux/iio/buffer.h>
@@ -65,6 +66,7 @@ · 35 unmodified lines
65#define MAX30100_REG_SPO2_CONFIG_1600US 0x366#define MAX30100_REG_SPO2_CONFIG_1600US 0x3
66 67
67#define MAX30100_REG_LED_CONFIG 0x0968#define MAX30100_REG_LED_CONFIG 0x09
69#define MAX30100_REG_LED_CONFIG_LED_MASK 0x0f
68#define MAX30100_REG_LED_CONFIG_RED_LED_SHIFT 470#define MAX30100_REG_LED_CONFIG_RED_LED_SHIFT 4
69 71
70#define MAX30100_REG_LED_CONFIG_24MA 0x0772#define MAX30100_REG_LED_CONFIG_24MA 0x07
@@ -111,6 +113,12 @@ static const struct regmap_config max30100_regmap_config = { · 40 unmodified lines
111 .volatile_reg = max30100_is_volatile_reg,113 .volatile_reg = max30100_is_volatile_reg,
112};114};
113 115
116static const unsigned int max30100_led_current_mapping[] = {
117 4400, 7600, 11000, 14200, 17400,
118 20800, 24000, 27100, 30600, 33800,
119 37000, 40200, 43600, 46800, 50000
120};
121
114static const unsigned long max30100_scan_masks[] = {0x3, 0};122static const unsigned long max30100_scan_masks[] = {0x3, 0};
115 123
116static const struct iio_chan_spec max30100_channels[] = {124static const struct iio_chan_spec max30100_channels[] = {
@@ -243,15 +251,76 @@ static irqreturn_t max30100_interrupt_handler(int irq, void *private) · 126 unmodified lines
243 return IRQ_HANDLED;251 return IRQ_HANDLED;
244}252}
245 253
254static int max30100_get_current_idx(unsigned int val, int *reg)
255{
256 int idx;
257
258 /* LED turned off */
259 if (val == 0) {
260 *reg = 0;
261 return 0;
262 }
263
264 for (idx = 0; idx < ARRAY_SIZE(max30100_led_current_mapping); idx++) {
265 if (max30100_led_current_mapping[idx] == val) {
266 *reg = idx + 1;
267 return 0;
268 }
269 }
270
271 return -EINVAL;
272}
273
274static int max30100_led_init(struct max30100_data *data)
275{
276 struct device *dev = &data->client->dev;
277 struct device_node *np = dev->of_node;
278 unsigned int val[2];
279 int reg, ret;
280
281 ret = of_property_read_u32_array(np, "maxim,led-current-microamp",
282 (unsigned int *) &val, 2);
283 if (ret) {
284 /* Default to 24 mA RED LED, 50 mA IR LED */
285 reg = (MAX30100_REG_LED_CONFIG_24MA <<
286 MAX30100_REG_LED_CONFIG_RED_LED_SHIFT) |
287 MAX30100_REG_LED_CONFIG_50MA;
288 dev_warn(dev, "no led-current-microamp set");
289
290 return regmap_write(data->regmap, MAX30100_REG_LED_CONFIG, reg);
291 }
292
293 /* RED LED current */
294 ret = max30100_get_current_idx(val[0], &reg);
295 if (ret) {
296 dev_err(dev, "invalid RED current setting %d", val[0]);
297 return ret;
298 }
299
300 ret = regmap_update_bits(data->regmap, MAX30100_REG_LED_CONFIG,
301 MAX30100_REG_LED_CONFIG_LED_MASK <<
302 MAX30100_REG_LED_CONFIG_RED_LED_SHIFT,
303 reg << MAX30100_REG_LED_CONFIG_RED_LED_SHIFT);
304 if (ret)
305 return ret;
306
307 /* IR LED current */
308 ret = max30100_get_current_idx(val[1], &reg);
309 if (ret) {
310 dev_err(dev, "invalid IR current setting %d", val[1]);
311 return ret;
312 }
313
314 return regmap_update_bits(data->regmap, MAX30100_REG_LED_CONFIG,
315 MAX30100_REG_LED_CONFIG_LED_MASK, reg);
316}
317
246static int max30100_chip_init(struct max30100_data *data)318static int max30100_chip_init(struct max30100_data *data)
247{319{
248 int ret;320 int ret;
249 321
250 /* RED IR LED = 24mA, IR LED = 50mA */322 /* setup LED current settings */
251 ret = regmap_write(data->regmap, MAX30100_REG_LED_CONFIG,323 ret = max30100_led_init(data);
252 (MAX30100_REG_LED_CONFIG_24MA <<
253 MAX30100_REG_LED_CONFIG_RED_LED_SHIFT) |
254 MAX30100_REG_LED_CONFIG_50MA);
255 if (ret)324 if (ret)
256 return ret;325 return ret;
257 326
drivers/iio/humidity/Kconfig+4−2
@@ -43,14 +43,16 @@ config SI7005 · 42 unmodified lines
43 humidity and temperature sensor.43 humidity and temperature sensor.
44 44
45 To compile this driver as a module, choose M here: the module45 To compile this driver as a module, choose M here: the module
46 will be called si7005.46 will be called si7005. This driver also
47 supports Hoperf TH02 Humidity and Temperature Sensor.
47 48
48config SI702049config SI7020
49 tristate "Si7013/20/21 Relative Humidity and Temperature Sensors"50 tristate "Si7013/20/21 Relative Humidity and Temperature Sensors"
50 depends on I2C51 depends on I2C
51 help52 help
52 Say yes here to build support for the Silicon Labs Si7013/20/2153 Say yes here to build support for the Silicon Labs Si7013/20/21
53 Relative Humidity and Temperature Sensors.54 Relative Humidity and Temperature Sensors. This driver also
55 supports Hoperf TH06 Humidity and Temperature Sensor.
54 56
55 To compile this driver as a module, choose M here: the module57 To compile this driver as a module, choose M here: the module
56 will be called si7020.58 will be called si7020.
drivers/iio/humidity/dht11.c+50−27
@@ -50,12 +50,32 @@ · 49 unmodified lines
50#define DHT11_EDGES_PER_READ (2 * DHT11_BITS_PER_READ + \50#define DHT11_EDGES_PER_READ (2 * DHT11_BITS_PER_READ + \
51 DHT11_EDGES_PREAMBLE + 1)51 DHT11_EDGES_PREAMBLE + 1)
52 52
53/* Data transmission timing (nano seconds) */53/*
54 * Data transmission timing:
55 * Data bits are encoded as pulse length (high time) on the data line.
56 * 0-bit: 22-30uS -- typically 26uS (AM2302)
57 * 1-bit: 68-75uS -- typically 70uS (AM2302)
58 * The acutal timings also depend on the properties of the cable, with
59 * longer cables typically making pulses shorter.
60 *
61 * Our decoding depends on the time resolution of the system:
62 * timeres > 34uS ... don't know what a 1-tick pulse is
63 * 34uS > timeres > 30uS ... no problem (30kHz and 32kHz clocks)
64 * 30uS > timeres > 23uS ... don't know what a 2-tick pulse is
65 * timeres < 23uS ... no problem
66 *
67 * Luckily clocks in the 33-44kHz range are quite uncommon, so we can
68 * support most systems if the threshold for decoding a pulse as 1-bit
69 * is chosen carefully. If somebody really wants to support clocks around
70 * 40kHz, where this driver is most unreliable, there are two options.
71 * a) select an implementation using busy loop polling on those systems
72 * b) use the checksum to do some probabilistic decoding
73 */
54#define DHT11_START_TRANSMISSION 18 /* ms */74#define DHT11_START_TRANSMISSION 18 /* ms */
55#define DHT11_SENSOR_RESPONSE 8000075#define DHT11_MIN_TIMERES 34000 /* ns */
56#define DHT11_START_BIT 5000076#define DHT11_THRESHOLD 49000 /* ns */
57#define DHT11_DATA_BIT_LOW 2700077#define DHT11_AMBIG_LOW 23000 /* ns */
58#define DHT11_DATA_BIT_HIGH 7000078#define DHT11_AMBIG_HIGH 30000 /* ns */
59 79
60struct dht11 {80struct dht11 {
61 struct device *dev;81 struct device *dev;
@@ -76,43 +96,39 @@ struct dht11 { · 14 unmodified lines
76 struct {s64 ts; int value; } edges[DHT11_EDGES_PER_READ];96 struct {s64 ts; int value; } edges[DHT11_EDGES_PER_READ];
77};97};
78 98
79static unsigned char dht11_decode_byte(int *timing, int threshold)99static unsigned char dht11_decode_byte(char *bits)
80{100{
81 unsigned char ret = 0;101 unsigned char ret = 0;
82 int i;102 int i;
83 103
84 for (i = 0; i < 8; ++i) {104 for (i = 0; i < 8; ++i) {
85 ret <<= 1;105 ret <<= 1;
86 if (timing[i] >= threshold)106 if (bits[i])
87 ++ret;107 ++ret;
88 }108 }
89 109
90 return ret;110 return ret;
91}111}
92 112
93static int dht11_decode(struct dht11 *dht11, int offset, int timeres)113static int dht11_decode(struct dht11 *dht11, int offset)
94{114{
95 int i, t, timing[DHT11_BITS_PER_READ], threshold;115 int i, t;
116 char bits[DHT11_BITS_PER_READ];
96 unsigned char temp_int, temp_dec, hum_int, hum_dec, checksum;117 unsigned char temp_int, temp_dec, hum_int, hum_dec, checksum;
97 118
98 threshold = DHT11_DATA_BIT_HIGH / timeres;
99 if (DHT11_DATA_BIT_LOW / timeres + 1 >= threshold)
100 pr_err("dht11: WARNING: decoding ambiguous\n");
101
102 /* scale down with timeres and check validity */
103 for (i = 0; i < DHT11_BITS_PER_READ; ++i) {119 for (i = 0; i < DHT11_BITS_PER_READ; ++i) {
104 t = dht11->edges[offset + 2 * i + 2].ts -120 t = dht11->edges[offset + 2 * i + 2].ts -
105 dht11->edges[offset + 2 * i + 1].ts;121 dht11->edges[offset + 2 * i + 1].ts;
106 if (!dht11->edges[offset + 2 * i + 1].value)122 if (!dht11->edges[offset + 2 * i + 1].value)
107 return -EIO; /* lost synchronisation */123 return -EIO; /* lost synchronisation */
108 timing[i] = t / timeres;124 bits[i] = t > DHT11_THRESHOLD;
109 }125 }
110 126
111 hum_int = dht11_decode_byte(timing, threshold);127 hum_int = dht11_decode_byte(bits);
112 hum_dec = dht11_decode_byte(&timing[8], threshold);128 hum_dec = dht11_decode_byte(&bits[8]);
113 temp_int = dht11_decode_byte(&timing[16], threshold);129 temp_int = dht11_decode_byte(&bits[16]);
114 temp_dec = dht11_decode_byte(&timing[24], threshold);130 temp_dec = dht11_decode_byte(&bits[24]);
115 checksum = dht11_decode_byte(&timing[32], threshold);131 checksum = dht11_decode_byte(&bits[32]);
116 132
117 if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum)133 if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum)
118 return -EIO;134 return -EIO;
@@ -161,12 +177,12 @@ static int dht11_read_raw(struct iio_dev *iio_dev, · 42 unmodified lines
161 int *val, int *val2, long m)177 int *val, int *val2, long m)
162{178{
163 struct dht11 *dht11 = iio_priv(iio_dev);179 struct dht11 *dht11 = iio_priv(iio_dev);
164 int ret, timeres;180 int ret, timeres, offset;
165 181
166 mutex_lock(&dht11->lock);182 mutex_lock(&dht11->lock);
167 if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_real_ns()) {183 if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_real_ns()) {
168 timeres = ktime_get_resolution_ns();184 timeres = ktime_get_resolution_ns();
169 if (DHT11_DATA_BIT_HIGH < 2 * timeres) {185 if (timeres > DHT11_MIN_TIMERES) {
170 dev_err(dht11->dev, "timeresolution %dns too low\n",186 dev_err(dht11->dev, "timeresolution %dns too low\n",
171 timeres);187 timeres);
172 /* In theory a better clock could become available188 /* In theory a better clock could become available
@@ -176,6 +192,10 @@ static int dht11_read_raw(struct iio_dev *iio_dev, · 3 unmodified lines
176 ret = -EAGAIN;192 ret = -EAGAIN;
177 goto err;193 goto err;
178 }194 }
195 if (timeres > DHT11_AMBIG_LOW && timeres < DHT11_AMBIG_HIGH)
196 dev_warn(dht11->dev,
197 "timeresolution: %dns - decoding ambiguous\n",
198 timeres);
179 199
180 reinit_completion(&dht11->completion);200 reinit_completion(&dht11->completion);
181 201
@@ -208,11 +228,14 @@ static int dht11_read_raw(struct iio_dev *iio_dev, · 26 unmodified lines
208 if (ret < 0)228 if (ret < 0)
209 goto err;229 goto err;
210 230
211 ret = dht11_decode(dht11,231 offset = DHT11_EDGES_PREAMBLE +
212 dht11->num_edges == DHT11_EDGES_PER_READ ?232 dht11->num_edges - DHT11_EDGES_PER_READ;
213 DHT11_EDGES_PREAMBLE :233 for (; offset >= 0; --offset) {
214 DHT11_EDGES_PREAMBLE - 2,234 ret = dht11_decode(dht11, offset);
215 timeres);235 if (!ret)
236 break;
237 }
238
216 if (ret)239 if (ret)
217 goto err;240 goto err;
218 }241 }
drivers/iio/humidity/si7005.c+1−0
@@ -170,6 +170,7 @@ static int si7005_probe(struct i2c_client *client, · 169 unmodified lines
170 170
171static const struct i2c_device_id si7005_id[] = {171static const struct i2c_device_id si7005_id[] = {
172 { "si7005", 0 },172 { "si7005", 0 },
173 { "th02", 0 },
173 { }174 { }
174};175};
175MODULE_DEVICE_TABLE(i2c, si7005_id);176MODULE_DEVICE_TABLE(i2c, si7005_id);
drivers/iio/humidity/si7020.c+1−0
@@ -149,6 +149,7 @@ static int si7020_probe(struct i2c_client *client, · 148 unmodified lines
149 149
150static const struct i2c_device_id si7020_id[] = {150static const struct i2c_device_id si7020_id[] = {
151 { "si7020", 0 },151 { "si7020", 0 },
152 { "th06", 0 },
152 { }153 { }
153};154};
154MODULE_DEVICE_TABLE(i2c, si7020_id);155MODULE_DEVICE_TABLE(i2c, si7020_id);
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c+2−3
@@ -727,8 +727,7 @@ static const struct iio_info mpu_info = { · 726 unmodified lines
727/**727/**
728 * inv_check_and_setup_chip() - check and setup chip.728 * inv_check_and_setup_chip() - check and setup chip.
729 */729 */
730static int inv_check_and_setup_chip(struct inv_mpu6050_state *st,730static int inv_check_and_setup_chip(struct inv_mpu6050_state *st)
731 const struct i2c_device_id *id)
732{731{
733 int result;732 int result;
734 733
@@ -795,7 +794,7 @@ static int inv_mpu_probe(struct i2c_client *client, · 60 unmodified lines
795 if (pdata)794 if (pdata)
796 st->plat_data = *pdata;795 st->plat_data = *pdata;
797 /* power is turned on inside check chip type*/796 /* power is turned on inside check chip type*/
798 result = inv_check_and_setup_chip(st, id);797 result = inv_check_and_setup_chip(st);
799 if (result)798 if (result)
800 return result;799 return result;
801 800
drivers/iio/industrialio-core.c+1−0
@@ -77,6 +77,7 @@ static const char * const iio_chan_type_name_spec[] = { · 76 unmodified lines
77 [IIO_VELOCITY] = "velocity",77 [IIO_VELOCITY] = "velocity",
78 [IIO_CONCENTRATION] = "concentration",78 [IIO_CONCENTRATION] = "concentration",
79 [IIO_RESISTANCE] = "resistance",79 [IIO_RESISTANCE] = "resistance",
80 [IIO_PH] = "ph",
80};81};
81 82
82static const char * const iio_modifier_names[] = {83static const char * const iio_modifier_names[] = {
drivers/iio/light/opt3001.c+106−50
@@ -65,19 +65,25 @@ · 64 unmodified lines
65#define OPT3001_REG_EXPONENT(n) ((n) >> 12)65#define OPT3001_REG_EXPONENT(n) ((n) >> 12)
66#define OPT3001_REG_MANTISSA(n) ((n) & 0xfff)66#define OPT3001_REG_MANTISSA(n) ((n) & 0xfff)
67 67
68#define OPT3001_INT_TIME_LONG 800000
69#define OPT3001_INT_TIME_SHORT 100000
70
68/*71/*
69 * Time to wait for conversion result to be ready. The device datasheet72 * Time to wait for conversion result to be ready. The device datasheet
70 * worst-case max value is 880ms. Add some slack to be on the safe side.73 * sect. 6.5 states results are ready after total integration time plus 3ms.
74 * This results in worst-case max values of 113ms or 883ms, respectively.
75 * Add some slack to be on the safe side.
71 */76 */
72#define OPT3001_RESULT_READY_TIMEOUT msecs_to_jiffies(1000)77#define OPT3001_RESULT_READY_SHORT 150
78#define OPT3001_RESULT_READY_LONG 1000
73 79
74struct opt3001 {80struct opt3001 {
75 struct i2c_client *client;81 struct i2c_client *client;
76 struct device *dev;82 struct device *dev;
77 83
78 struct mutex lock;84 struct mutex lock;
79 u16 ok_to_ignore_lock:1;85 bool ok_to_ignore_lock;
80 u16 result_ready:1;86 bool result_ready;
81 wait_queue_head_t result_ready_queue;87 wait_queue_head_t result_ready_queue;
82 u16 result;88 u16 result;
83 89
@@ -89,6 +95,8 @@ struct opt3001 { · 5 unmodified lines
89 95
90 u8 high_thresh_exp;96 u8 high_thresh_exp;
91 u8 low_thresh_exp;97 u8 low_thresh_exp;
98
99 bool use_irq;
92};100};
93 101
94struct opt3001_scale {102struct opt3001_scale {
@@ -227,26 +235,30 @@ static int opt3001_get_lux(struct opt3001 *opt, int *val, int *val2) · 132 unmodified lines
227 u16 reg;235 u16 reg;
228 u8 exponent;236 u8 exponent;
229 u16 value;237 u16 value;
238 long timeout;
230 239
231 /*240 if (opt->use_irq) {
232 * Enable the end-of-conversion interrupt mechanism. Note that doing241 /*
233 * so will overwrite the low-level limit value however we will restore242 * Enable the end-of-conversion interrupt mechanism. Note that
234 * this value later on.243 * doing so will overwrite the low-level limit value however we
235 */244 * will restore this value later on.
236 ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_LOW_LIMIT,245 */
237 OPT3001_LOW_LIMIT_EOC_ENABLE);246 ret = i2c_smbus_write_word_swapped(opt->client,
238 if (ret < 0) {247 OPT3001_LOW_LIMIT,
239 dev_err(opt->dev, "failed to write register %02x\n",248 OPT3001_LOW_LIMIT_EOC_ENABLE);
240 OPT3001_LOW_LIMIT);249 if (ret < 0) {
241 return ret;250 dev_err(opt->dev, "failed to write register %02x\n",
251 OPT3001_LOW_LIMIT);
252 return ret;
253 }
254
255 /* Allow IRQ to access the device despite lock being set */
256 opt->ok_to_ignore_lock = true;
242 }257 }
243 258
244 /* Reset data-ready indicator flag (will be set in the IRQ routine) */259 /* Reset data-ready indicator flag */
245 opt->result_ready = false;260 opt->result_ready = false;
246 261
247 /* Allow IRQ to access the device despite lock being set */
248 opt->ok_to_ignore_lock = true;
249
250 /* Configure for single-conversion mode and start a new conversion */262 /* Configure for single-conversion mode and start a new conversion */
251 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);263 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
252 if (ret < 0) {264 if (ret < 0) {
@@ -266,32 +278,69 @@ static int opt3001_get_lux(struct opt3001 *opt, int *val, int *val2) · 13 unmodified lines
266 goto err;278 goto err;
267 }279 }
268 280
269 /* Wait for the IRQ to indicate the conversion is complete */281 if (opt->use_irq) {
270 ret = wait_event_timeout(opt->result_ready_queue, opt->result_ready,282 /* Wait for the IRQ to indicate the conversion is complete */
271 OPT3001_RESULT_READY_TIMEOUT);283 ret = wait_event_timeout(opt->result_ready_queue,
284 opt->result_ready,
285 msecs_to_jiffies(OPT3001_RESULT_READY_LONG));
286 } else {
287 /* Sleep for result ready time */
288 timeout = (opt->int_time == OPT3001_INT_TIME_SHORT) ?
289 OPT3001_RESULT_READY_SHORT : OPT3001_RESULT_READY_LONG;
290 msleep(timeout);
291
292 /* Check result ready flag */
293 ret = i2c_smbus_read_word_swapped(opt->client,
294 OPT3001_CONFIGURATION);
295 if (ret < 0) {
296 dev_err(opt->dev, "failed to read register %02x\n",
297 OPT3001_CONFIGURATION);
298 goto err;
299 }
300
301 if (!(ret & OPT3001_CONFIGURATION_CRF)) {
302 ret = -ETIMEDOUT;
303 goto err;
304 }
305
306 /* Obtain value */
307 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_RESULT);
308 if (ret < 0) {
309 dev_err(opt->dev, "failed to read register %02x\n",
310 OPT3001_RESULT);
311 goto err;
312 }
313 opt->result = ret;
314 opt->result_ready = true;
315 }
272 316
273err:317err:
274 /* Disallow IRQ to access the device while lock is active */318 if (opt->use_irq)
275 opt->ok_to_ignore_lock = false;319 /* Disallow IRQ to access the device while lock is active */
320 opt->ok_to_ignore_lock = false;
276 321
277 if (ret == 0)322 if (ret == 0)
278 return -ETIMEDOUT;323 return -ETIMEDOUT;
279 else if (ret < 0)324 else if (ret < 0)
280 return ret;325 return ret;
281 326
282 /*327 if (opt->use_irq) {
283 * Disable the end-of-conversion interrupt mechanism by restoring the328 /*
284 * low-level limit value (clearing OPT3001_LOW_LIMIT_EOC_ENABLE). Note329 * Disable the end-of-conversion interrupt mechanism by
285 * that selectively clearing those enable bits would affect the actual330 * restoring the low-level limit value (clearing
286 * limit value due to bit-overlap and therefore can't be done.331 * OPT3001_LOW_LIMIT_EOC_ENABLE). Note that selectively clearing
287 */332 * those enable bits would affect the actual limit value due to
288 value = (opt->low_thresh_exp << 12) | opt->low_thresh_mantissa;333 * bit-overlap and therefore can't be done.
289 ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_LOW_LIMIT,334 */
290 value);335 value = (opt->low_thresh_exp << 12) | opt->low_thresh_mantissa;
291 if (ret < 0) {336 ret = i2c_smbus_write_word_swapped(opt->client,
292 dev_err(opt->dev, "failed to write register %02x\n",337 OPT3001_LOW_LIMIT,
293 OPT3001_LOW_LIMIT);338 value);
294 return ret;339 if (ret < 0) {
340 dev_err(opt->dev, "failed to write register %02x\n",
341 OPT3001_LOW_LIMIT);
342 return ret;
343 }
295 }344 }
296 345
297 exponent = OPT3001_REG_EXPONENT(opt->result);346 exponent = OPT3001_REG_EXPONENT(opt->result);
@@ -325,13 +374,13 @@ static int opt3001_set_int_time(struct opt3001 *opt, int time) · 27 unmodified lines
325 reg = ret;374 reg = ret;
326 375
327 switch (time) {376 switch (time) {
328 case 100000:377 case OPT3001_INT_TIME_SHORT:
329 reg &= ~OPT3001_CONFIGURATION_CT;378 reg &= ~OPT3001_CONFIGURATION_CT;
330 opt->int_time = 100000;379 opt->int_time = OPT3001_INT_TIME_SHORT;
331 break;380 break;
332 case 800000:381 case OPT3001_INT_TIME_LONG:
333 reg |= OPT3001_CONFIGURATION_CT;382 reg |= OPT3001_CONFIGURATION_CT;
334 opt->int_time = 800000;383 opt->int_time = OPT3001_INT_TIME_LONG;
335 break;384 break;
336 default:385 default:
337 return -EINVAL;386 return -EINVAL;
@@ -597,9 +646,9 @@ static int opt3001_configure(struct opt3001 *opt) · 259 unmodified lines
597 646
598 /* Reflect status of the device's integration time setting */647 /* Reflect status of the device's integration time setting */
599 if (reg & OPT3001_CONFIGURATION_CT)648 if (reg & OPT3001_CONFIGURATION_CT)
600 opt->int_time = 800000;649 opt->int_time = OPT3001_INT_TIME_LONG;
601 else650 else
602 opt->int_time = 100000;651 opt->int_time = OPT3001_INT_TIME_SHORT;
603 652
604 /* Ensure device is in shutdown initially */653 /* Ensure device is in shutdown initially */
605 opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SHUTDOWN);654 opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SHUTDOWN);
@@ -733,12 +782,18 @@ static int opt3001_probe(struct i2c_client *client, · 127 unmodified lines
733 return ret;782 return ret;
734 }783 }
735 784
736 ret = request_threaded_irq(irq, NULL, opt3001_irq,785 /* Make use of INT pin only if valid IRQ no. is given */
737 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,786 if (irq > 0) {
738 "opt3001", iio);787 ret = request_threaded_irq(irq, NULL, opt3001_irq,
739 if (ret) {788 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
740 dev_err(dev, "failed to request IRQ #%d\n", irq);789 "opt3001", iio);
741 return ret;790 if (ret) {
791 dev_err(dev, "failed to request IRQ #%d\n", irq);
792 return ret;
793 }
794 opt->use_irq = true;
795 } else {
796 dev_dbg(opt->dev, "enabling interrupt-less operation\n");
742 }797 }
743 798
744 return 0;799 return 0;
@@ -751,7 +806,8 @@ static int opt3001_remove(struct i2c_client *client) · 6 unmodified lines
751 int ret;806 int ret;
752 u16 reg;807 u16 reg;
753 808
754 free_irq(client->irq, iio);809 if (opt->use_irq)
810 free_irq(client->irq, iio);
755 811
756 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);812 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
757 if (ret < 0) {813 if (ret < 0) {
drivers/iio/magnetometer/ak8975.c+2−2
@@ -252,7 +252,7 @@ struct ak_def { · 251 unmodified lines
252 u8 data_regs[3];252 u8 data_regs[3];
253};253};
254 254
255static struct ak_def ak_def_array[AK_MAX_TYPE] = {255static const struct ak_def ak_def_array[AK_MAX_TYPE] = {
256 {256 {
257 .type = AK8975,257 .type = AK8975,
258 .raw_to_gauss = ak8975_raw_to_gauss,258 .raw_to_gauss = ak8975_raw_to_gauss,
@@ -360,7 +360,7 @@ static struct ak_def ak_def_array[AK_MAX_TYPE] = { · 101 unmodified lines
360 */360 */
361struct ak8975_data {361struct ak8975_data {
362 struct i2c_client *client;362 struct i2c_client *client;
363 struct ak_def *def;363 const struct ak_def *def;
364 struct attribute_group attrs;364 struct attribute_group attrs;
365 struct mutex lock;365 struct mutex lock;
366 u8 asa[3];366 u8 asa[3];
drivers/iio/magnetometer/st_magn_core.c+4−0
@@ -175,6 +175,8 @@ · 174 unmodified lines
175#define ST_MAGN_3_BDU_MASK 0x10175#define ST_MAGN_3_BDU_MASK 0x10
176#define ST_MAGN_3_DRDY_IRQ_ADDR 0x62176#define ST_MAGN_3_DRDY_IRQ_ADDR 0x62
177#define ST_MAGN_3_DRDY_INT_MASK 0x01177#define ST_MAGN_3_DRDY_INT_MASK 0x01
178#define ST_MAGN_3_IHL_IRQ_ADDR 0x63
179#define ST_MAGN_3_IHL_IRQ_MASK 0x04
178#define ST_MAGN_3_FS_AVL_15000_GAIN 1500180#define ST_MAGN_3_FS_AVL_15000_GAIN 1500
179#define ST_MAGN_3_MULTIREAD_BIT false181#define ST_MAGN_3_MULTIREAD_BIT false
180#define ST_MAGN_3_OUT_X_L_ADDR 0x68182#define ST_MAGN_3_OUT_X_L_ADDR 0x68
@@ -480,6 +482,8 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = { · 299 unmodified lines
480 .drdy_irq = {482 .drdy_irq = {
481 .addr = ST_MAGN_3_DRDY_IRQ_ADDR,483 .addr = ST_MAGN_3_DRDY_IRQ_ADDR,
482 .mask_int1 = ST_MAGN_3_DRDY_INT_MASK,484 .mask_int1 = ST_MAGN_3_DRDY_INT_MASK,
485 .addr_ihl = ST_MAGN_3_IHL_IRQ_ADDR,
486 .mask_ihl = ST_MAGN_3_IHL_IRQ_MASK,
483 },487 },
484 .multi_read_bit = ST_MAGN_3_MULTIREAD_BIT,488 .multi_read_bit = ST_MAGN_3_MULTIREAD_BIT,
485 .bootime = 2,489 .bootime = 2,
drivers/iio/pressure/Kconfig+28−13
@@ -10,11 +10,11 @@ config BMP280 · 9 unmodified lines
10 depends on I2C10 depends on I2C
11 select REGMAP_I2C11 select REGMAP_I2C
12 help12 help
13 Say yes here to build support for Bosch Sensortec BMP28013 Say yes here to build support for Bosch Sensortec BMP280
14 pressure and temperature sensor.14 pressure and temperature sensor.
15 15
16 To compile this driver as a module, choose M here: the module16 To compile this driver as a module, choose M here: the module
17 will be called bmp280.17 will be called bmp280.
18 18
19config HID_SENSOR_PRESS19config HID_SENSOR_PRESS
20 depends on HID_SENSOR_HUB20 depends on HID_SENSOR_HUB
@@ -27,18 +27,33 @@ config HID_SENSOR_PRESS · 6 unmodified lines
27 Say yes here to build support for the HID SENSOR27 Say yes here to build support for the HID SENSOR
28 Pressure driver28 Pressure driver
29 29
30 To compile this driver as a module, choose M here: the module30 To compile this driver as a module, choose M here: the module
31 will be called hid-sensor-press.31 will be called hid-sensor-press.
32 32
33config MPL11533config MPL115
34 tristate
35
36config MPL115_I2C
34 tristate "Freescale MPL115A2 pressure sensor driver"37 tristate "Freescale MPL115A2 pressure sensor driver"
35 depends on I2C38 depends on I2C
39 select MPL115
36 help40 help
37 Say yes here to build support for the Freescale MPL115A241 Say yes here to build support for the Freescale MPL115A2
38 pressure sensor connected via I2C.42 pressure sensor connected via I2C.
39 43
40 To compile this driver as a module, choose M here: the module44 To compile this driver as a module, choose M here: the module
41 will be called mpl115.45 will be called mpl115_i2c.
46
47config MPL115_SPI
48 tristate "Freescale MPL115A1 pressure sensor driver"
49 depends on SPI_MASTER
50 select MPL115
51 help
52 Say yes here to build support for the Freescale MPL115A1
53 pressure sensor connected via SPI.
54
55 To compile this driver as a module, choose M here: the module
56 will be called mpl115_spi.
42 57
43config MPL311558config MPL3115
44 tristate "Freescale MPL3115A2 pressure sensor driver"59 tristate "Freescale MPL3115A2 pressure sensor driver"
@@ -49,8 +64,8 @@ config MPL3115 · 4 unmodified lines
49 Say yes here to build support for the Freescale MPL3115A264 Say yes here to build support for the Freescale MPL3115A2
50 pressure sensor / altimeter.65 pressure sensor / altimeter.
51 66
52 To compile this driver as a module, choose M here: the module67 To compile this driver as a module, choose M here: the module
53 will be called mpl3115.68 will be called mpl3115.
54 69
55config MS561170config MS5611
56 tristate "Measurement Specialties MS5611 pressure sensor driver"71 tristate "Measurement Specialties MS5611 pressure sensor driver"
@@ -82,7 +97,7 @@ config MS5611_SPI · 25 unmodified lines
82config MS563797config MS5637
83 tristate "Measurement Specialties MS5637 pressure & temperature sensor"98 tristate "Measurement Specialties MS5637 pressure & temperature sensor"
84 depends on I2C99 depends on I2C
85 select IIO_MS_SENSORS_I2C100 select IIO_MS_SENSORS_I2C
86 help101 help
87 If you say yes here you get support for the Measurement Specialties102 If you say yes here you get support for the Measurement Specialties
88 MS5637 pressure and temperature sensor.103 MS5637 pressure and temperature sensor.
@@ -128,7 +143,7 @@ config T5403 · 39 unmodified lines
128 Say yes here to build support for the EPCOS T5403 pressure sensor143 Say yes here to build support for the EPCOS T5403 pressure sensor
129 connected via I2C.144 connected via I2C.
130 145
131 To compile this driver as a module, choose M here: the module146 To compile this driver as a module, choose M here: the module
132 will be called t5403.147 will be called t5403.
133 148
134endmenu149endmenu
drivers/iio/pressure/Makefile+2−0
@@ -6,6 +6,8 @@ · 5 unmodified lines
6obj-$(CONFIG_BMP280) += bmp280.o6obj-$(CONFIG_BMP280) += bmp280.o
7obj-$(CONFIG_HID_SENSOR_PRESS) += hid-sensor-press.o7obj-$(CONFIG_HID_SENSOR_PRESS) += hid-sensor-press.o
8obj-$(CONFIG_MPL115) += mpl115.o8obj-$(CONFIG_MPL115) += mpl115.o
9obj-$(CONFIG_MPL115_I2C) += mpl115_i2c.o
10obj-$(CONFIG_MPL115_SPI) += mpl115_spi.o
9obj-$(CONFIG_MPL3115) += mpl3115.o11obj-$(CONFIG_MPL3115) += mpl3115.o
10obj-$(CONFIG_MS5611) += ms5611_core.o12obj-$(CONFIG_MS5611) += ms5611_core.o
11obj-$(CONFIG_MS5611_I2C) += ms5611_i2c.o13obj-$(CONFIG_MS5611_I2C) += ms5611_i2c.o
drivers/iio/pressure/mpl115.c+27−39
@@ -1,5 +1,5 @@
1/*1/*
2 * mpl115.c - Support for Freescale MPL115A2 pressure/temperature sensor2 * mpl115.c - Support for Freescale MPL115A pressure/temperature sensor
3 *3 *
4 * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>4 * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>
5 *5 *
@@ -7,17 +7,16 @@ · 1 unmodified line
7 * the GNU General Public License. See the file COPYING in the main7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.8 * directory of this archive for more details.
9 *9 *
10 * (7-bit I2C slave address 0x60)
11 *
12 * TODO: shutdown pin10 * TODO: shutdown pin
13 *11 *
14 */12 */
15 13
16#include <linux/module.h>14#include <linux/module.h>
17#include <linux/i2c.h>
18#include <linux/iio/iio.h>15#include <linux/iio/iio.h>
19#include <linux/delay.h>16#include <linux/delay.h>
20 17
18#include "mpl115.h"
19
21#define MPL115_PADC 0x00 /* pressure ADC output value, MSB first, 10 bit */20#define MPL115_PADC 0x00 /* pressure ADC output value, MSB first, 10 bit */
22#define MPL115_TADC 0x02 /* temperature ADC output value, MSB first, 10 bit */21#define MPL115_TADC 0x02 /* temperature ADC output value, MSB first, 10 bit */
23#define MPL115_A0 0x04 /* 12 bit integer, 3 bit fraction */22#define MPL115_A0 0x04 /* 12 bit integer, 3 bit fraction */
@@ -27,16 +26,18 @@ · 3 unmodified lines
27#define MPL115_CONVERT 0x12 /* convert temperature and pressure */26#define MPL115_CONVERT 0x12 /* convert temperature and pressure */
28 27
29struct mpl115_data {28struct mpl115_data {
30 struct i2c_client *client;29 struct device *dev;
31 struct mutex lock;30 struct mutex lock;
32 s16 a0;31 s16 a0;
33 s16 b1, b2;32 s16 b1, b2;
34 s16 c12;33 s16 c12;
34 const struct mpl115_ops *ops;
35};35};
36 36
37static int mpl115_request(struct mpl115_data *data)37static int mpl115_request(struct mpl115_data *data)
38{38{
39 int ret = i2c_smbus_write_byte_data(data->client, MPL115_CONVERT, 0);39 int ret = data->ops->write(data->dev, MPL115_CONVERT, 0);
40
40 if (ret < 0)41 if (ret < 0)
41 return ret;42 return ret;
42 43
@@ -57,12 +58,12 @@ static int mpl115_comp_pressure(struct mpl115_data *data, int *val, int *val2) · 14 unmodified lines
57 if (ret < 0)58 if (ret < 0)
58 goto done;59 goto done;
59 60
60 ret = i2c_smbus_read_word_swapped(data->client, MPL115_PADC);61 ret = data->ops->read(data->dev, MPL115_PADC);
61 if (ret < 0)62 if (ret < 0)
62 goto done;63 goto done;
63 padc = ret >> 6;64 padc = ret >> 6;
64 65
65 ret = i2c_smbus_read_word_swapped(data->client, MPL115_TADC);66 ret = data->ops->read(data->dev, MPL115_TADC);
66 if (ret < 0)67 if (ret < 0)
67 goto done;68 goto done;
68 tadc = ret >> 6;69 tadc = ret >> 6;
@@ -90,7 +91,7 @@ static int mpl115_read_temp(struct mpl115_data *data) · 21 unmodified lines
90 ret = mpl115_request(data);91 ret = mpl115_request(data);
91 if (ret < 0)92 if (ret < 0)
92 goto done;93 goto done;
93 ret = i2c_smbus_read_word_swapped(data->client, MPL115_TADC);94 ret = data->ops->read(data->dev, MPL115_TADC);
94done:95done:
95 mutex_unlock(&data->lock);96 mutex_unlock(&data->lock);
96 return ret;97 return ret;
@@ -145,66 +146,53 @@ static const struct iio_info mpl115_info = { · 48 unmodified lines
145 .driver_module = THIS_MODULE,146 .driver_module = THIS_MODULE,
146};147};
147 148
148static int mpl115_probe(struct i2c_client *client,149int mpl115_probe(struct device *dev, const char *name,
149 const struct i2c_device_id *id)150 const struct mpl115_ops *ops)
150{151{
151 struct mpl115_data *data;152 struct mpl115_data *data;
152 struct iio_dev *indio_dev;153 struct iio_dev *indio_dev;
153 int ret;154 int ret;
154 155
155 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))156 indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
156 return -ENODEV;
157
158 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
159 if (!indio_dev)157 if (!indio_dev)
160 return -ENOMEM;158 return -ENOMEM;
161 159
162 data = iio_priv(indio_dev);160 data = iio_priv(indio_dev);
163 data->client = client;161 data->dev = dev;
162 data->ops = ops;
164 mutex_init(&data->lock);163 mutex_init(&data->lock);
165 164
166 i2c_set_clientdata(client, indio_dev);
167 indio_dev->info = &mpl115_info;165 indio_dev->info = &mpl115_info;
168 indio_dev->name = id->name;166 indio_dev->name = name;
169 indio_dev->dev.parent = &client->dev;167 indio_dev->dev.parent = dev;
170 indio_dev->modes = INDIO_DIRECT_MODE;168 indio_dev->modes = INDIO_DIRECT_MODE;
171 indio_dev->channels = mpl115_channels;169 indio_dev->channels = mpl115_channels;
172 indio_dev->num_channels = ARRAY_SIZE(mpl115_channels);170 indio_dev->num_channels = ARRAY_SIZE(mpl115_channels);
173 171
174 ret = i2c_smbus_read_word_swapped(data->client, MPL115_A0);172 ret = data->ops->init(data->dev);
173 if (ret)
174 return ret;
175
176 ret = data->ops->read(data->dev, MPL115_A0);
175 if (ret < 0)177 if (ret < 0)
176 return ret;178 return ret;
177 data->a0 = ret;179 data->a0 = ret;
178 ret = i2c_smbus_read_word_swapped(data->client, MPL115_B1);180 ret = data->ops->read(data->dev, MPL115_B1);
179 if (ret < 0)181 if (ret < 0)
180 return ret;182 return ret;
181 data->b1 = ret;183 data->b1 = ret;
182 ret = i2c_smbus_read_word_swapped(data->client, MPL115_B2);184 ret = data->ops->read(data->dev, MPL115_B2);
183 if (ret < 0)185 if (ret < 0)
184 return ret;186 return ret;
185 data->b2 = ret;187 data->b2 = ret;
186 ret = i2c_smbus_read_word_swapped(data->client, MPL115_C12);188 ret = data->ops->read(data->dev, MPL115_C12);
187 if (ret < 0)189 if (ret < 0)
188 return ret;190 return ret;
189 data->c12 = ret;191 data->c12 = ret;
190 192
191 return devm_iio_device_register(&client->dev, indio_dev);193 return devm_iio_device_register(dev, indio_dev);
192}194}
193 195EXPORT_SYMBOL_GPL(mpl115_probe);
194static const struct i2c_device_id mpl115_id[] = {
195 { "mpl115", 0 },
196 { }
197};
198MODULE_DEVICE_TABLE(i2c, mpl115_id);
199
200static struct i2c_driver mpl115_driver = {
201 .driver = {
202 .name = "mpl115",
203 },
204 .probe = mpl115_probe,
205 .id_table = mpl115_id,
206};
207module_i2c_driver(mpl115_driver);
208 196
209MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");197MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
210MODULE_DESCRIPTION("Freescale MPL115 pressure/temperature driver");198MODULE_DESCRIPTION("Freescale MPL115 pressure/temperature driver");
drivers/iio/pressure/mpl115.h+24−0
@@ -0,0 +1,24 @@
1/*
2 * Freescale MPL115A pressure/temperature sensor
3 *
4 * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>
5 * Copyright (c) 2016 Akinobu Mita <akinobu.mita@gmail.com>
6 *
7 * This file is subject to the terms and conditions of version 2 of
8 * the GNU General Public License. See the file COPYING in the main
9 * directory of this archive for more details.
10 */
11
12#ifndef _MPL115_H_
13#define _MPL115_H_
14
15struct mpl115_ops {
16 int (*init)(struct device *);
17 int (*read)(struct device *, u8);
18 int (*write)(struct device *, u8, u8);
19};
20
21int mpl115_probe(struct device *dev, const char *name,
22 const struct mpl115_ops *ops);
23
24#endif
drivers/iio/pressure/mpl115_i2c.c+67−0
@@ -0,0 +1,67 @@
1/*
2 * Freescale MPL115A2 pressure/temperature sensor
3 *
4 * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>
5 *
6 * This file is subject to the terms and conditions of version 2 of
7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.
9 *
10 * (7-bit I2C slave address 0x60)
11 *
12 * Datasheet: http://www.nxp.com/files/sensors/doc/data_sheet/MPL115A2.pdf
13 */
14
15#include <linux/module.h>
16#include <linux/i2c.h>
17
18#include "mpl115.h"
19
20static int mpl115_i2c_init(struct device *dev)
21{
22 return 0;
23}
24
25static int mpl115_i2c_read(struct device *dev, u8 address)
26{
27 return i2c_smbus_read_word_swapped(to_i2c_client(dev), address);
28}
29
30static int mpl115_i2c_write(struct device *dev, u8 address, u8 value)
31{
32 return i2c_smbus_write_byte_data(to_i2c_client(dev), address, value);
33}
34
35static const struct mpl115_ops mpl115_i2c_ops = {
36 .init = mpl115_i2c_init,
37 .read = mpl115_i2c_read,
38 .write = mpl115_i2c_write,
39};
40
41static int mpl115_i2c_probe(struct i2c_client *client,
42 const struct i2c_device_id *id)
43{
44 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))
45 return -ENODEV;
46
47 return mpl115_probe(&client->dev, id->name, &mpl115_i2c_ops);
48}
49
50static const struct i2c_device_id mpl115_i2c_id[] = {
51 { "mpl115", 0 },
52 { }
53};
54MODULE_DEVICE_TABLE(i2c, mpl115_i2c_id);
55
56static struct i2c_driver mpl115_i2c_driver = {
57 .driver = {
58 .name = "mpl115",
59 },
60 .probe = mpl115_i2c_probe,
61 .id_table = mpl115_i2c_id,
62};
63module_i2c_driver(mpl115_i2c_driver);
64
65MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
66MODULE_DESCRIPTION("Freescale MPL115A2 pressure/temperature driver");
67MODULE_LICENSE("GPL");
drivers/iio/pressure/mpl115_spi.c+106−0
@@ -0,0 +1,106 @@
1/*
2 * Freescale MPL115A1 pressure/temperature sensor
3 *
4 * Copyright (c) 2016 Akinobu Mita <akinobu.mita@gmail.com>
5 *
6 * This file is subject to the terms and conditions of version 2 of
7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.
9 *
10 * Datasheet: http://www.nxp.com/files/sensors/doc/data_sheet/MPL115A1.pdf
11 */
12
13#include <linux/module.h>
14#include <linux/spi/spi.h>
15
16#include "mpl115.h"
17
18#define MPL115_SPI_WRITE(address) ((address) << 1)
19#define MPL115_SPI_READ(address) (0x80 | (address) << 1)
20
21struct mpl115_spi_buf {
22 u8 tx[4];
23 u8 rx[4];
24};
25
26static int mpl115_spi_init(struct device *dev)
27{
28 struct spi_device *spi = to_spi_device(dev);
29 struct mpl115_spi_buf *buf;
30
31 buf = devm_kzalloc(dev, sizeof(*buf), GFP_KERNEL);
32 if (!buf)
33 return -ENOMEM;
34
35 spi_set_drvdata(spi, buf);
36
37 return 0;
38}
39
40static int mpl115_spi_read(struct device *dev, u8 address)
41{
42 struct spi_device *spi = to_spi_device(dev);
43 struct mpl115_spi_buf *buf = spi_get_drvdata(spi);
44 struct spi_transfer xfer = {
45 .tx_buf = buf->tx,
46 .rx_buf = buf->rx,
47 .len = 4,
48 };
49 int ret;
50
51 buf->tx[0] = MPL115_SPI_READ(address);
52 buf->tx[2] = MPL115_SPI_READ(address + 1);
53
54 ret = spi_sync_transfer(spi, &xfer, 1);
55 if (ret)
56 return ret;
57
58 return (buf->rx[1] << 8) | buf->rx[3];
59}
60
61static int mpl115_spi_write(struct device *dev, u8 address, u8 value)
62{
63 struct spi_device *spi = to_spi_device(dev);
64 struct mpl115_spi_buf *buf = spi_get_drvdata(spi);
65 struct spi_transfer xfer = {
66 .tx_buf = buf->tx,
67 .len = 2,
68 };
69
70 buf->tx[0] = MPL115_SPI_WRITE(address);
71 buf->tx[1] = value;
72
73 return spi_sync_transfer(spi, &xfer, 1);
74}
75
76static const struct mpl115_ops mpl115_spi_ops = {
77 .init = mpl115_spi_init,
78 .read = mpl115_spi_read,
79 .write = mpl115_spi_write,
80};
81
82static int mpl115_spi_probe(struct spi_device *spi)
83{
84 const struct spi_device_id *id = spi_get_device_id(spi);
85
86 return mpl115_probe(&spi->dev, id->name, &mpl115_spi_ops);
87}
88
89static const struct spi_device_id mpl115_spi_ids[] = {
90 { "mpl115", 0 },
91 {}
92};
93MODULE_DEVICE_TABLE(spi, mpl115_spi_ids);
94
95static struct spi_driver mpl115_spi_driver = {
96 .driver = {
97 .name = "mpl115",
98 },
99 .probe = mpl115_spi_probe,
100 .id_table = mpl115_spi_ids,
101};
102module_spi_driver(mpl115_spi_driver);
103
104MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");
105MODULE_DESCRIPTION("Freescale MPL115A1 pressure/temperature driver");
106MODULE_LICENSE("GPL");
drivers/iio/pressure/st_pressure_core.c+8−0
@@ -62,6 +62,8 @@ · 61 unmodified lines
62#define ST_PRESS_LPS331AP_DRDY_IRQ_ADDR 0x2262#define ST_PRESS_LPS331AP_DRDY_IRQ_ADDR 0x22
63#define ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK 0x0463#define ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK 0x04
64#define ST_PRESS_LPS331AP_DRDY_IRQ_INT2_MASK 0x2064#define ST_PRESS_LPS331AP_DRDY_IRQ_INT2_MASK 0x20
65#define ST_PRESS_LPS331AP_IHL_IRQ_ADDR 0x22
66#define ST_PRESS_LPS331AP_IHL_IRQ_MASK 0x80
65#define ST_PRESS_LPS331AP_MULTIREAD_BIT true67#define ST_PRESS_LPS331AP_MULTIREAD_BIT true
66#define ST_PRESS_LPS331AP_TEMP_OFFSET 4250068#define ST_PRESS_LPS331AP_TEMP_OFFSET 42500
67 69
@@ -100,6 +102,8 @@ · 32 unmodified lines
100#define ST_PRESS_LPS25H_DRDY_IRQ_ADDR 0x23102#define ST_PRESS_LPS25H_DRDY_IRQ_ADDR 0x23
101#define ST_PRESS_LPS25H_DRDY_IRQ_INT1_MASK 0x01103#define ST_PRESS_LPS25H_DRDY_IRQ_INT1_MASK 0x01
102#define ST_PRESS_LPS25H_DRDY_IRQ_INT2_MASK 0x10104#define ST_PRESS_LPS25H_DRDY_IRQ_INT2_MASK 0x10
105#define ST_PRESS_LPS25H_IHL_IRQ_ADDR 0x22
106#define ST_PRESS_LPS25H_IHL_IRQ_MASK 0x80
103#define ST_PRESS_LPS25H_MULTIREAD_BIT true107#define ST_PRESS_LPS25H_MULTIREAD_BIT true
104#define ST_PRESS_LPS25H_TEMP_OFFSET 42500108#define ST_PRESS_LPS25H_TEMP_OFFSET 42500
105#define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28109#define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28
@@ -220,6 +224,8 @@ static const struct st_sensor_settings st_press_sensors_settings[] = { · 114 unmodified lines
220 .addr = ST_PRESS_LPS331AP_DRDY_IRQ_ADDR,224 .addr = ST_PRESS_LPS331AP_DRDY_IRQ_ADDR,
221 .mask_int1 = ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK,225 .mask_int1 = ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK,
222 .mask_int2 = ST_PRESS_LPS331AP_DRDY_IRQ_INT2_MASK,226 .mask_int2 = ST_PRESS_LPS331AP_DRDY_IRQ_INT2_MASK,
227 .addr_ihl = ST_PRESS_LPS331AP_IHL_IRQ_ADDR,
228 .mask_ihl = ST_PRESS_LPS331AP_IHL_IRQ_MASK,
223 },229 },
224 .multi_read_bit = ST_PRESS_LPS331AP_MULTIREAD_BIT,230 .multi_read_bit = ST_PRESS_LPS331AP_MULTIREAD_BIT,
225 .bootime = 2,231 .bootime = 2,
@@ -304,6 +310,8 @@ static const struct st_sensor_settings st_press_sensors_settings[] = { · 78 unmodified lines
304 .addr = ST_PRESS_LPS25H_DRDY_IRQ_ADDR,310 .addr = ST_PRESS_LPS25H_DRDY_IRQ_ADDR,
305 .mask_int1 = ST_PRESS_LPS25H_DRDY_IRQ_INT1_MASK,311 .mask_int1 = ST_PRESS_LPS25H_DRDY_IRQ_INT1_MASK,
306 .mask_int2 = ST_PRESS_LPS25H_DRDY_IRQ_INT2_MASK,312 .mask_int2 = ST_PRESS_LPS25H_DRDY_IRQ_INT2_MASK,
313 .addr_ihl = ST_PRESS_LPS25H_IHL_IRQ_ADDR,
314 .mask_ihl = ST_PRESS_LPS25H_IHL_IRQ_MASK,
307 },315 },
308 .multi_read_bit = ST_PRESS_LPS25H_MULTIREAD_BIT,316 .multi_read_bit = ST_PRESS_LPS25H_MULTIREAD_BIT,
309 .bootime = 2,317 .bootime = 2,
drivers/staging/iio/Documentation/sysfs-bus-iio-light+0−28
@@ -1,31 +1,3 @@
1
2What: /sys/bus/iio/devices/device[n]/range
3KernelVersion: 2.6.37
4Contact: linux-iio@vger.kernel.org
5Description:
6 Hardware dependent ADC Full Scale Range used for some ambient
7 light sensors in calculating lux.
8
9What: /sys/bus/iio/devices/device[n]/range_available
10KernelVersion: 2.6.37
11Contact: linux-iio@vger.kernel.org
12Description:
13 Hardware dependent supported vales for ADC Full Scale Range.
14
15What: /sys/bus/iio/devices/device[n]/adc_resolution
16KernelVersion: 2.6.37
17Contact: linux-iio@vger.kernel.org
18Description:
19 Hardware dependent ADC resolution of the ambient light sensor
20 used in calculating the lux.
21
22What: /sys/bus/iio/devices/device[n]/adc_resolution_available
23KernelVersion: 2.6.37
24Contact: linux-iio@vger.kernel.org
25Description:
26 Hardware dependent list of possible values supported for the
27 adc_resolution of the given sensor.
28
29What: /sys/bus/iio/devices/device[n]/in_illuminance0[_input|_raw]1What: /sys/bus/iio/devices/device[n]/in_illuminance0[_input|_raw]
30KernelVersion: 2.6.352KernelVersion: 2.6.35
31Contact: linux-iio@vger.kernel.org3Contact: linux-iio@vger.kernel.org
drivers/staging/iio/adc/ad7192.c+1−1
@@ -236,7 +236,7 @@ static int ad7192_setup(struct ad7192_state *st, · 235 unmodified lines
236 st->mclk = pdata->ext_clk_hz;236 st->mclk = pdata->ext_clk_hz;
237 else237 else
238 st->mclk = AD7192_INT_FREQ_MHZ;238 st->mclk = AD7192_INT_FREQ_MHZ;
239 break;239 break;
240 default:240 default:
241 ret = -EINVAL;241 ret = -EINVAL;
242 goto out;242 goto out;
drivers/staging/iio/cdc/ad7150.c+18−16
@@ -21,8 +21,8 @@ · 20 unmodified lines
21 */21 */
22 22
23#define AD7150_STATUS 023#define AD7150_STATUS 0
24#define AD7150_STATUS_OUT1 (1 << 3)24#define AD7150_STATUS_OUT1 BIT(3)
25#define AD7150_STATUS_OUT2 (1 << 5)25#define AD7150_STATUS_OUT2 BIT(5)
26#define AD7150_CH1_DATA_HIGH 126#define AD7150_CH1_DATA_HIGH 1
27#define AD7150_CH2_DATA_HIGH 327#define AD7150_CH2_DATA_HIGH 3
28#define AD7150_CH1_AVG_HIGH 528#define AD7150_CH1_AVG_HIGH 5
@@ -36,7 +36,7 @@ · 7 unmodified lines
36#define AD7150_CH2_TIMEOUT 1336#define AD7150_CH2_TIMEOUT 13
37#define AD7150_CH2_SETUP 1437#define AD7150_CH2_SETUP 14
38#define AD7150_CFG 1538#define AD7150_CFG 15
39#define AD7150_CFG_FIX (1 << 7)39#define AD7150_CFG_FIX BIT(7)
40#define AD7150_PD_TIMER 1640#define AD7150_PD_TIMER 16
41#define AD7150_CH1_CAPDAC 1741#define AD7150_CH1_CAPDAC 17
42#define AD7150_CH2_CAPDAC 1842#define AD7150_CH2_CAPDAC 18
@@ -160,8 +160,9 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev, · 117 unmodified lines
160 160
161/* lock should be held */161/* lock should be held */
162static int ad7150_write_event_params(struct iio_dev *indio_dev,162static int ad7150_write_event_params(struct iio_dev *indio_dev,
163 unsigned int chan, enum iio_event_type type,163 unsigned int chan,
164 enum iio_event_direction dir)164 enum iio_event_type type,
165 enum iio_event_direction dir)
165{166{
166 int ret;167 int ret;
167 u16 value;168 u16 value;
@@ -209,8 +210,9 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, · 41 unmodified lines
209}210}
210 211
211static int ad7150_write_event_config(struct iio_dev *indio_dev,212static int ad7150_write_event_config(struct iio_dev *indio_dev,
212 const struct iio_chan_spec *chan, enum iio_event_type type,213 const struct iio_chan_spec *chan,
213 enum iio_event_direction dir, int state)214 enum iio_event_type type,
215 enum iio_event_direction dir, int state)
214{216{
215 u8 thresh_type, cfg, adaptive;217 u8 thresh_type, cfg, adaptive;
216 int ret;218 int ret;
@@ -302,11 +304,11 @@ static int ad7150_read_event_value(struct iio_dev *indio_dev, · 85 unmodified lines
302}304}
303 305
304static int ad7150_write_event_value(struct iio_dev *indio_dev,306static int ad7150_write_event_value(struct iio_dev *indio_dev,
305 const struct iio_chan_spec *chan,307 const struct iio_chan_spec *chan,
306 enum iio_event_type type,308 enum iio_event_type type,
307 enum iio_event_direction dir,309 enum iio_event_direction dir,
308 enum iio_event_info info,310 enum iio_event_info info,
309 int val, int val2)311 int val, int val2)
310{312{
311 int ret;313 int ret;
312 struct ad7150_chip_info *chip = iio_priv(indio_dev);314 struct ad7150_chip_info *chip = iio_priv(indio_dev);
@@ -365,9 +367,9 @@ static ssize_t ad7150_show_timeout(struct device *dev, · 52 unmodified lines
365}367}
366 368
367static ssize_t ad7150_store_timeout(struct device *dev,369static ssize_t ad7150_store_timeout(struct device *dev,
368 struct device_attribute *attr,370 struct device_attribute *attr,
369 const char *buf,371 const char *buf,
370 size_t len)372 size_t len)
371{373{
372 struct iio_dev *indio_dev = dev_to_iio_dev(dev);374 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
373 struct ad7150_chip_info *chip = iio_priv(indio_dev);375 struct ad7150_chip_info *chip = iio_priv(indio_dev);
@@ -580,7 +582,7 @@ static const struct iio_info ad7150_info = { · 206 unmodified lines
580 */582 */
581 583
582static int ad7150_probe(struct i2c_client *client,584static int ad7150_probe(struct i2c_client *client,
583 const struct i2c_device_id *id)585 const struct i2c_device_id *id)
584{586{
585 int ret;587 int ret;
586 struct ad7150_chip_info *chip;588 struct ad7150_chip_info *chip;
include/linux/iio/common/st_sensors.h+4−0
@@ -119,6 +119,8 @@ struct st_sensor_bdu { · 118 unmodified lines
119 * @addr: address of the register.119 * @addr: address of the register.
120 * @mask_int1: mask to enable/disable IRQ on INT1 pin.120 * @mask_int1: mask to enable/disable IRQ on INT1 pin.
121 * @mask_int2: mask to enable/disable IRQ on INT2 pin.121 * @mask_int2: mask to enable/disable IRQ on INT2 pin.
122 * @addr_ihl: address to enable/disable active low on the INT lines.
123 * @mask_ihl: mask to enable/disable active low on the INT lines.
122 * struct ig1 - represents the Interrupt Generator 1 of sensors.124 * struct ig1 - represents the Interrupt Generator 1 of sensors.
123 * @en_addr: address of the enable ig1 register.125 * @en_addr: address of the enable ig1 register.
124 * @en_mask: mask to write the on/off value for enable.126 * @en_mask: mask to write the on/off value for enable.
@@ -127,6 +129,8 @@ struct st_sensor_data_ready_irq { · 2 unmodified lines
127 u8 addr;129 u8 addr;
128 u8 mask_int1;130 u8 mask_int1;
129 u8 mask_int2;131 u8 mask_int2;
132 u8 addr_ihl;
133 u8 mask_ihl;
130 struct {134 struct {
131 u8 en_addr;135 u8 en_addr;
132 u8 en_mask;136 u8 en_mask;
include/linux/platform_data/ad5761.h+44−0
@@ -0,0 +1,44 @@
1/*
2 * AD5721, AD5721R, AD5761, AD5761R, Voltage Output Digital to Analog Converter
3 *
4 * Copyright 2016 Qtechnology A/S
5 * 2016 Ricardo Ribalda <ricardo.ribalda@gmail.com>
6 *
7 * Licensed under the GPL-2.
8 */
9#ifndef __LINUX_PLATFORM_DATA_AD5761_H__
10#define __LINUX_PLATFORM_DATA_AD5761_H__
11
12/**
13 * enum ad5761_voltage_range - Voltage range the AD5761 is configured for.
14 * @AD5761_VOLTAGE_RANGE_M10V_10V: -10V to 10V
15 * @AD5761_VOLTAGE_RANGE_0V_10V: 0V to 10V
16 * @AD5761_VOLTAGE_RANGE_M5V_5V: -5V to 5V
17 * @AD5761_VOLTAGE_RANGE_0V_5V: 0V to 5V
18 * @AD5761_VOLTAGE_RANGE_M2V5_7V5: -2.5V to 7.5V
19 * @AD5761_VOLTAGE_RANGE_M3V_3V: -3V to 3V
20 * @AD5761_VOLTAGE_RANGE_0V_16V: 0V to 16V
21 * @AD5761_VOLTAGE_RANGE_0V_20V: 0V to 20V
22 */
23
24enum ad5761_voltage_range {
25 AD5761_VOLTAGE_RANGE_M10V_10V,
26 AD5761_VOLTAGE_RANGE_0V_10V,
27 AD5761_VOLTAGE_RANGE_M5V_5V,
28 AD5761_VOLTAGE_RANGE_0V_5V,
29 AD5761_VOLTAGE_RANGE_M2V5_7V5,
30 AD5761_VOLTAGE_RANGE_M3V_3V,
31 AD5761_VOLTAGE_RANGE_0V_16V,
32 AD5761_VOLTAGE_RANGE_0V_20V,
33};
34
35/**
36 * struct ad5761_platform_data - AD5761 DAC driver platform data
37 * @voltage_range: Voltage range the AD5761 is configured for
38 */
39
40struct ad5761_platform_data {
41 enum ad5761_voltage_range voltage_range;
42};
43
44#endif
include/uapi/linux/iio/types.h+1−0
@@ -37,6 +37,7 @@ enum iio_chan_type { · 36 unmodified lines
37 IIO_VELOCITY,37 IIO_VELOCITY,
38 IIO_CONCENTRATION,38 IIO_CONCENTRATION,
39 IIO_RESISTANCE,39 IIO_RESISTANCE,
40 IIO_PH,
40};41};
41 42
42enum iio_modifier {43enum iio_modifier {

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