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

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.

+2532 -266
+1
CREDITS
··· 3054 3054 D: PCA9634 driver 3055 3055 D: Option GTM671WFS 3056 3056 D: Fintek F81216A 3057 + D: AD5761 iio driver 3057 3058 D: Various kernel hacks 3058 3059 S: Qtechnology A/S 3059 3060 S: Valby Langgade 142
+9
Documentation/ABI/testing/sysfs-bus-iio
··· 497 497 6kohm_to_gnd: connected to ground via a 6kOhm resistor, 498 498 20kohm_to_gnd: connected to ground via a 20kOhm resistor, 499 499 100kohm_to_gnd: connected to ground via an 100kOhm resistor, 500 + 125kohm_to_gnd: connected to ground via an 125kOhm resistor, 500 501 500kohm_to_gnd: connected to ground via a 500kOhm resistor, 502 + 640kohm_to_gnd: connected to ground via a 640kOhm resistor, 501 503 three_state: left floating. 502 504 For a list of available output power down options read 503 505 outX_powerdown_mode_available. If Y is not present the ··· 1493 1491 This ABI is especially applicable for humidity sensors 1494 1492 to heatup the device and get rid of any condensation 1495 1493 in some humidity environment 1494 + 1495 + What: /sys/bus/iio/devices/iio:deviceX/in_ph_raw 1496 + KernelVersion: 4.5 1497 + Contact: linux-iio@vger.kernel.org 1498 + Description: 1499 + Raw (unscaled no offset etc.) pH reading of a substance as a negative 1500 + base-10 logarithm of hydrodium ions in a litre of water.
+3 -1
Documentation/devicetree/bindings/iio/accel/mma8452.txt
··· 1 - Freescale MMA8452Q, MMA8453Q, MMA8652FC or MMA8653FC triaxial accelerometer 1 + Freescale MMA8451Q, MMA8452Q, MMA8453Q, MMA8652FC or MMA8653FC 2 + triaxial accelerometer 2 3 3 4 Required properties: 4 5 5 6 - compatible: should contain one of 7 + * "fsl,mma8451" 6 8 * "fsl,mma8452" 7 9 * "fsl,mma8453" 8 10 * "fsl,mma8652"
+28
Documentation/devicetree/bindings/iio/adc/at91-sama5d2_adc.txt
··· 1 + * AT91 SAMA5D2 Analog to Digital Converter (ADC) 2 + 3 + Required 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 + 15 + Example: 16 + 17 + adc: 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 + }
+1
Documentation/devicetree/bindings/iio/adc/mcp3422.txt
··· 6 6 "microchip,mcp3422" or 7 7 "microchip,mcp3423" or 8 8 "microchip,mcp3424" or 9 + "microchip,mcp3425" or 9 10 "microchip,mcp3426" or 10 11 "microchip,mcp3427" or 11 12 "microchip,mcp3428"
+22
Documentation/devicetree/bindings/iio/chemical/atlas,ph-sm.txt
··· 1 + * Atlas Scientific pH-SM OEM sensor 2 + 3 + http://www.atlas-scientific.com/_files/_datasheets/_oem/pH_oem_datasheet.pdf 4 + 5 + Required 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 + 15 + Example: 16 + 17 + atlas@65 { 18 + compatible = "atlas,ph-sm"; 19 + reg = <0x65>; 20 + interrupt-parent = <&gpio1>; 21 + interrupts = <16 2>; 22 + };
+8
Documentation/devicetree/bindings/iio/health/max30100.txt
··· 11 11 Refer to interrupt-controller/interrupts.txt for generic 12 12 interrupt client node bindings. 13 13 14 + Optional 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 + 14 21 Example: 15 22 16 23 max30100@057 { 17 24 compatible = "maxim,max30100"; 18 25 reg = <57>; 26 + maxim,led-current-microamp = <24000 50000>; 19 27 interrupt-parent = <&gpio1>; 20 28 interrupts = <16 2>; 21 29 };
+26
Documentation/devicetree/bindings/iio/light/opt3001.txt
··· 1 + * Texas Instruments OPT3001 Ambient Light Sensor 2 + 3 + The driver supports interrupt-driven and interrupt-less operation, depending 4 + on whether an interrupt property has been populated into the DT. Note that 5 + the optional generation of IIO events on rising/falling light threshold changes 6 + requires the use of interrupts. Without interrupts, only the simple reading 7 + of the current light value is supported through the IIO API. 8 + 9 + http://www.ti.com/product/opt3001 10 + 11 + Required properties: 12 + - compatible: should be "ti,opt3001" 13 + - reg: the I2C address of the sensor 14 + 15 + Optional properties: 16 + - interrupt-parent: should be the phandle for the interrupt controller 17 + - interrupts: interrupt mapping for GPIO IRQ (configure for falling edge) 18 + 19 + Example: 20 + 21 + opt3001@44 { 22 + compatible = "ti,opt3001"; 23 + reg = <0x44>; 24 + interrupt-parent = <&gpio1>; 25 + interrupts = <28 IRQ_TYPE_EDGE_FALLING>; 26 + };
+1
Documentation/devicetree/bindings/vendor-prefixes.txt
··· 28 28 armadeus ARMadeus Systems SARL 29 29 artesyn Artesyn Embedded Technologies Inc. 30 30 asahi-kasei Asahi Kasei Corp. 31 + atlas Atlas Scientific LLC 31 32 atmel Atmel Corporation 32 33 auo AU Optronics Corporation 33 34 avago Avago Technologies
+6
MAINTAINERS
··· 1945 1945 S: Supported 1946 1946 F: drivers/tty/serial/atmel_serial.c 1947 1947 1948 + ATMEL SAMA5D2 ADC DRIVER 1949 + M: Ludovic Desroches <ludovic.desroches@atmel.com> 1950 + L: linux-iio@vger.kernel.org 1951 + S: Supported 1952 + F: drivers/iio/adc/at91-sama5d2_adc.c 1953 + 1948 1954 ATMEL Audio ALSA driver 1949 1955 M: Nicolas Ferre <nicolas.ferre@atmel.com> 1950 1956 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
+1 -1
drivers/iio/accel/Kconfig
··· 143 143 select IIO_TRIGGERED_BUFFER 144 144 help 145 145 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 148 To compile this driver as a module, choose M here: the module 149 149 will be called mma8452.
+183 -25
drivers/iio/accel/mma8452.c
··· 1 1 /* 2 2 * mma8452.c - Support for following Freescale 3-axis accelerometers: 3 3 * 4 + * MMA8451Q (14 bit) 4 5 * MMA8452Q (12 bit) 5 6 * MMA8453Q (10 bit) 6 7 * MMA8652FC (12 bit) ··· 16 15 * 17 16 * 7-bit I2C slave address 0x1c/0x1d (pin selectable) 18 17 * 19 - * TODO: orientation / freefall events, autosleep 18 + * TODO: orientation events, autosleep 20 19 */ 21 20 22 21 #include <linux/module.h> ··· 86 85 #define MMA8452_INT_FF_MT BIT(2) 87 86 #define MMA8452_INT_TRANS BIT(5) 88 87 89 - #define MMA8452_DEVICE_ID 0x2a 90 - #define MMA8453_DEVICE_ID 0x3a 88 + #define MMA8451_DEVICE_ID 0x1a 89 + #define MMA8452_DEVICE_ID 0x2a 90 + #define MMA8453_DEVICE_ID 0x3a 91 91 #define MMA8652_DEVICE_ID 0x4a 92 92 #define MMA8653_DEVICE_ID 0x5a 93 93 ··· 418 416 return ret; 419 417 } 420 418 419 + /* returns >0 if in freefall mode, 0 if not or <0 if an error occured */ 420 + static int mma8452_freefall_mode_enabled(struct mma8452_data *data) 421 + { 422 + int val; 423 + const struct mma_chip_info *chip = data->chip_info; 424 + 425 + val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg); 426 + if (val < 0) 427 + return val; 428 + 429 + return !(val & MMA8452_FF_MT_CFG_OAE); 430 + } 431 + 432 + static int mma8452_set_freefall_mode(struct mma8452_data *data, bool state) 433 + { 434 + int val; 435 + const struct mma_chip_info *chip = data->chip_info; 436 + 437 + if ((state && mma8452_freefall_mode_enabled(data)) || 438 + (!state && !(mma8452_freefall_mode_enabled(data)))) 439 + return 0; 440 + 441 + val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg); 442 + if (val < 0) 443 + return val; 444 + 445 + if (state) { 446 + val |= BIT(idx_x + chip->ev_cfg_chan_shift); 447 + val |= BIT(idx_y + chip->ev_cfg_chan_shift); 448 + val |= BIT(idx_z + chip->ev_cfg_chan_shift); 449 + val &= ~MMA8452_FF_MT_CFG_OAE; 450 + } else { 451 + val &= ~BIT(idx_x + chip->ev_cfg_chan_shift); 452 + val &= ~BIT(idx_y + chip->ev_cfg_chan_shift); 453 + val &= ~BIT(idx_z + chip->ev_cfg_chan_shift); 454 + val |= MMA8452_FF_MT_CFG_OAE; 455 + } 456 + 457 + val = mma8452_change_config(data, chip->ev_cfg, val); 458 + if (val) 459 + return val; 460 + 461 + return 0; 462 + } 463 + 421 464 static int mma8452_set_hp_filter_frequency(struct mma8452_data *data, 422 465 int val, int val2) 423 466 { ··· 656 609 const struct mma_chip_info *chip = data->chip_info; 657 610 int ret; 658 611 659 - ret = i2c_smbus_read_byte_data(data->client, 660 - data->chip_info->ev_cfg); 661 - if (ret < 0) 662 - return ret; 612 + switch (dir) { 613 + case IIO_EV_DIR_FALLING: 614 + return mma8452_freefall_mode_enabled(data); 615 + case IIO_EV_DIR_RISING: 616 + if (mma8452_freefall_mode_enabled(data)) 617 + return 0; 663 618 664 - return !!(ret & BIT(chan->scan_index + chip->ev_cfg_chan_shift)); 619 + ret = i2c_smbus_read_byte_data(data->client, 620 + data->chip_info->ev_cfg); 621 + if (ret < 0) 622 + return ret; 623 + 624 + return !!(ret & BIT(chan->scan_index + chip->ev_cfg_chan_shift)); 625 + default: 626 + return -EINVAL; 627 + } 665 628 } 666 629 667 630 static int mma8452_write_event_config(struct iio_dev *indio_dev, ··· 684 627 const struct mma_chip_info *chip = data->chip_info; 685 628 int val; 686 629 687 - val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg); 688 - if (val < 0) 689 - return val; 630 + switch (dir) { 631 + case IIO_EV_DIR_FALLING: 632 + return mma8452_set_freefall_mode(data, state); 633 + case IIO_EV_DIR_RISING: 634 + val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg); 635 + if (val < 0) 636 + return val; 690 637 691 - if (state) 692 - val |= BIT(chan->scan_index + chip->ev_cfg_chan_shift); 693 - else 694 - val &= ~BIT(chan->scan_index + chip->ev_cfg_chan_shift); 638 + if (state) { 639 + if (mma8452_freefall_mode_enabled(data)) { 640 + val &= ~BIT(idx_x + chip->ev_cfg_chan_shift); 641 + val &= ~BIT(idx_y + chip->ev_cfg_chan_shift); 642 + val &= ~BIT(idx_z + chip->ev_cfg_chan_shift); 643 + val |= MMA8452_FF_MT_CFG_OAE; 644 + } 645 + val |= BIT(chan->scan_index + chip->ev_cfg_chan_shift); 646 + } else { 647 + if (mma8452_freefall_mode_enabled(data)) 648 + return 0; 695 649 696 - val |= chip->ev_cfg_ele; 697 - val |= MMA8452_FF_MT_CFG_OAE; 650 + val &= ~BIT(chan->scan_index + chip->ev_cfg_chan_shift); 651 + } 698 652 699 - return mma8452_change_config(data, chip->ev_cfg, val); 653 + val |= chip->ev_cfg_ele; 654 + 655 + return mma8452_change_config(data, chip->ev_cfg, val); 656 + default: 657 + return -EINVAL; 658 + } 700 659 } 701 660 702 661 static void mma8452_transient_interrupt(struct iio_dev *indio_dev) ··· 724 651 src = i2c_smbus_read_byte_data(data->client, data->chip_info->ev_src); 725 652 if (src < 0) 726 653 return; 654 + 655 + if (mma8452_freefall_mode_enabled(data)) { 656 + iio_push_event(indio_dev, 657 + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, 658 + IIO_MOD_X_AND_Y_AND_Z, 659 + IIO_EV_TYPE_MAG, 660 + IIO_EV_DIR_FALLING), 661 + ts); 662 + return; 663 + } 727 664 728 665 if (src & data->chip_info->ev_src_xe) 729 666 iio_push_event(indio_dev, ··· 828 745 return 0; 829 746 } 830 747 748 + static const struct iio_event_spec mma8452_freefall_event[] = { 749 + { 750 + .type = IIO_EV_TYPE_MAG, 751 + .dir = IIO_EV_DIR_FALLING, 752 + .mask_separate = BIT(IIO_EV_INFO_ENABLE), 753 + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | 754 + BIT(IIO_EV_INFO_PERIOD) | 755 + BIT(IIO_EV_INFO_HIGH_PASS_FILTER_3DB) 756 + }, 757 + }; 758 + 759 + static const struct iio_event_spec mma8652_freefall_event[] = { 760 + { 761 + .type = IIO_EV_TYPE_MAG, 762 + .dir = IIO_EV_DIR_FALLING, 763 + .mask_separate = BIT(IIO_EV_INFO_ENABLE), 764 + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | 765 + BIT(IIO_EV_INFO_PERIOD) 766 + }, 767 + }; 768 + 831 769 static const struct iio_event_spec mma8452_transient_event[] = { 832 770 { 833 771 .type = IIO_EV_TYPE_MAG, ··· 884 780 static struct attribute_group mma8452_event_attribute_group = { 885 781 .attrs = mma8452_event_attributes, 886 782 }; 783 + 784 + #define MMA8452_FREEFALL_CHANNEL(modifier) { \ 785 + .type = IIO_ACCEL, \ 786 + .modified = 1, \ 787 + .channel2 = modifier, \ 788 + .scan_index = -1, \ 789 + .event_spec = mma8452_freefall_event, \ 790 + .num_event_specs = ARRAY_SIZE(mma8452_freefall_event), \ 791 + } 792 + 793 + #define MMA8652_FREEFALL_CHANNEL(modifier) { \ 794 + .type = IIO_ACCEL, \ 795 + .modified = 1, \ 796 + .channel2 = modifier, \ 797 + .scan_index = -1, \ 798 + .event_spec = mma8652_freefall_event, \ 799 + .num_event_specs = ARRAY_SIZE(mma8652_freefall_event), \ 800 + } 887 801 888 802 #define MMA8452_CHANNEL(axis, idx, bits) { \ 889 803 .type = IIO_ACCEL, \ ··· 944 822 .num_event_specs = ARRAY_SIZE(mma8452_motion_event), \ 945 823 } 946 824 825 + static const struct iio_chan_spec mma8451_channels[] = { 826 + MMA8452_CHANNEL(X, idx_x, 14), 827 + MMA8452_CHANNEL(Y, idx_y, 14), 828 + MMA8452_CHANNEL(Z, idx_z, 14), 829 + IIO_CHAN_SOFT_TIMESTAMP(idx_ts), 830 + MMA8452_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z), 831 + }; 832 + 947 833 static const struct iio_chan_spec mma8452_channels[] = { 948 834 MMA8452_CHANNEL(X, idx_x, 12), 949 835 MMA8452_CHANNEL(Y, idx_y, 12), 950 836 MMA8452_CHANNEL(Z, idx_z, 12), 951 837 IIO_CHAN_SOFT_TIMESTAMP(idx_ts), 838 + MMA8452_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z), 952 839 }; 953 840 954 841 static const struct iio_chan_spec mma8453_channels[] = { ··· 965 834 MMA8452_CHANNEL(Y, idx_y, 10), 966 835 MMA8452_CHANNEL(Z, idx_z, 10), 967 836 IIO_CHAN_SOFT_TIMESTAMP(idx_ts), 837 + MMA8452_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z), 968 838 }; 969 839 970 840 static const struct iio_chan_spec mma8652_channels[] = { ··· 973 841 MMA8652_CHANNEL(Y, idx_y, 12), 974 842 MMA8652_CHANNEL(Z, idx_z, 12), 975 843 IIO_CHAN_SOFT_TIMESTAMP(idx_ts), 844 + MMA8652_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z), 976 845 }; 977 846 978 847 static const struct iio_chan_spec mma8653_channels[] = { ··· 981 848 MMA8652_CHANNEL(Y, idx_y, 10), 982 849 MMA8652_CHANNEL(Z, idx_z, 10), 983 850 IIO_CHAN_SOFT_TIMESTAMP(idx_ts), 851 + MMA8652_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z), 984 852 }; 985 853 986 854 enum { 855 + mma8451, 987 856 mma8452, 988 857 mma8453, 989 858 mma8652, ··· 993 858 }; 994 859 995 860 static const struct mma_chip_info mma_chip_info_table[] = { 861 + [mma8451] = { 862 + .chip_id = MMA8451_DEVICE_ID, 863 + .channels = mma8451_channels, 864 + .num_channels = ARRAY_SIZE(mma8451_channels), 865 + /* 866 + * Hardware has fullscale of -2G, -4G, -8G corresponding to 867 + * raw value -8192 for 14 bit, -2048 for 12 bit or -512 for 10 868 + * bit. 869 + * The userspace interface uses m/s^2 and we declare micro units 870 + * So scale factor for 12 bit here is given by: 871 + * g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.80665 872 + */ 873 + .mma_scales = { {0, 2394}, {0, 4788}, {0, 9577} }, 874 + .ev_cfg = MMA8452_TRANSIENT_CFG, 875 + .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE, 876 + .ev_cfg_chan_shift = 1, 877 + .ev_src = MMA8452_TRANSIENT_SRC, 878 + .ev_src_xe = MMA8452_TRANSIENT_SRC_XTRANSE, 879 + .ev_src_ye = MMA8452_TRANSIENT_SRC_YTRANSE, 880 + .ev_src_ze = MMA8452_TRANSIENT_SRC_ZTRANSE, 881 + .ev_ths = MMA8452_TRANSIENT_THS, 882 + .ev_ths_mask = MMA8452_TRANSIENT_THS_MASK, 883 + .ev_count = MMA8452_TRANSIENT_COUNT, 884 + }, 996 885 [mma8452] = { 997 886 .chip_id = MMA8452_DEVICE_ID, 998 887 .channels = mma8452_channels, 999 888 .num_channels = ARRAY_SIZE(mma8452_channels), 1000 - /* 1001 - * Hardware has fullscale of -2G, -4G, -8G corresponding to 1002 - * raw value -2048 for 12 bit or -512 for 10 bit. 1003 - * The userspace interface uses m/s^2 and we declare micro units 1004 - * So scale factor for 12 bit here is given by: 1005 - * g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.80665 1006 - */ 1007 889 .mma_scales = { {0, 9577}, {0, 19154}, {0, 38307} }, 1008 890 .ev_cfg = MMA8452_TRANSIENT_CFG, 1009 891 .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE, ··· 1201 1049 } 1202 1050 1203 1051 static const struct of_device_id mma8452_dt_ids[] = { 1052 + { .compatible = "fsl,mma8451", .data = &mma_chip_info_table[mma8451] }, 1204 1053 { .compatible = "fsl,mma8452", .data = &mma_chip_info_table[mma8452] }, 1205 1054 { .compatible = "fsl,mma8453", .data = &mma_chip_info_table[mma8453] }, 1206 1055 { .compatible = "fsl,mma8652", .data = &mma_chip_info_table[mma8652] }, ··· 1238 1085 return ret; 1239 1086 1240 1087 switch (ret) { 1088 + case MMA8451_DEVICE_ID: 1241 1089 case MMA8452_DEVICE_ID: 1242 1090 case MMA8453_DEVICE_ID: 1243 1091 case MMA8652_DEVICE_ID: ··· 1343 1189 ret = iio_device_register(indio_dev); 1344 1190 if (ret < 0) 1345 1191 goto buffer_cleanup; 1192 + 1193 + ret = mma8452_set_freefall_mode(data, false); 1194 + if (ret) 1195 + return ret; 1346 1196 1347 1197 return 0; 1348 1198
+16
drivers/iio/accel/st_accel_core.c
··· 67 67 #define ST_ACCEL_1_DRDY_IRQ_ADDR 0x22 68 68 #define ST_ACCEL_1_DRDY_IRQ_INT1_MASK 0x10 69 69 #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 72 #define ST_ACCEL_1_MULTIREAD_BIT true 71 73 72 74 /* CUSTOM VALUES FOR SENSOR 2 */ ··· 94 92 #define ST_ACCEL_2_DRDY_IRQ_ADDR 0x22 95 93 #define ST_ACCEL_2_DRDY_IRQ_INT1_MASK 0x02 96 94 #define ST_ACCEL_2_DRDY_IRQ_INT2_MASK 0x10 95 + #define ST_ACCEL_2_IHL_IRQ_ADDR 0x22 96 + #define ST_ACCEL_2_IHL_IRQ_MASK 0x80 97 97 #define ST_ACCEL_2_MULTIREAD_BIT true 98 98 99 99 /* CUSTOM VALUES FOR SENSOR 3 */ ··· 129 125 #define ST_ACCEL_3_DRDY_IRQ_ADDR 0x23 130 126 #define ST_ACCEL_3_DRDY_IRQ_INT1_MASK 0x80 131 127 #define ST_ACCEL_3_DRDY_IRQ_INT2_MASK 0x00 128 + #define ST_ACCEL_3_IHL_IRQ_ADDR 0x23 129 + #define ST_ACCEL_3_IHL_IRQ_MASK 0x40 132 130 #define ST_ACCEL_3_IG1_EN_ADDR 0x23 133 131 #define ST_ACCEL_3_IG1_EN_MASK 0x08 134 132 #define ST_ACCEL_3_MULTIREAD_BIT false ··· 175 169 #define ST_ACCEL_5_DRDY_IRQ_ADDR 0x22 176 170 #define ST_ACCEL_5_DRDY_IRQ_INT1_MASK 0x04 177 171 #define ST_ACCEL_5_DRDY_IRQ_INT2_MASK 0x20 172 + #define ST_ACCEL_5_IHL_IRQ_ADDR 0x22 173 + #define ST_ACCEL_5_IHL_IRQ_MASK 0x80 178 174 #define ST_ACCEL_5_IG1_EN_ADDR 0x21 179 175 #define ST_ACCEL_5_IG1_EN_MASK 0x08 180 176 #define ST_ACCEL_5_MULTIREAD_BIT false ··· 300 292 .addr = ST_ACCEL_1_DRDY_IRQ_ADDR, 301 293 .mask_int1 = ST_ACCEL_1_DRDY_IRQ_INT1_MASK, 302 294 .mask_int2 = ST_ACCEL_1_DRDY_IRQ_INT2_MASK, 295 + .addr_ihl = ST_ACCEL_1_IHL_IRQ_ADDR, 296 + .mask_ihl = ST_ACCEL_1_IHL_IRQ_MASK, 303 297 }, 304 298 .multi_read_bit = ST_ACCEL_1_MULTIREAD_BIT, 305 299 .bootime = 2, ··· 365 355 .addr = ST_ACCEL_2_DRDY_IRQ_ADDR, 366 356 .mask_int1 = ST_ACCEL_2_DRDY_IRQ_INT1_MASK, 367 357 .mask_int2 = ST_ACCEL_2_DRDY_IRQ_INT2_MASK, 358 + .addr_ihl = ST_ACCEL_2_IHL_IRQ_ADDR, 359 + .mask_ihl = ST_ACCEL_2_IHL_IRQ_MASK, 368 360 }, 369 361 .multi_read_bit = ST_ACCEL_2_MULTIREAD_BIT, 370 362 .bootime = 2, ··· 442 430 .addr = ST_ACCEL_3_DRDY_IRQ_ADDR, 443 431 .mask_int1 = ST_ACCEL_3_DRDY_IRQ_INT1_MASK, 444 432 .mask_int2 = ST_ACCEL_3_DRDY_IRQ_INT2_MASK, 433 + .addr_ihl = ST_ACCEL_3_IHL_IRQ_ADDR, 434 + .mask_ihl = ST_ACCEL_3_IHL_IRQ_MASK, 445 435 .ig1 = { 446 436 .en_addr = ST_ACCEL_3_IG1_EN_ADDR, 447 437 .en_mask = ST_ACCEL_3_IG1_EN_MASK, ··· 551 537 .addr = ST_ACCEL_5_DRDY_IRQ_ADDR, 552 538 .mask_int1 = ST_ACCEL_5_DRDY_IRQ_INT1_MASK, 553 539 .mask_int2 = ST_ACCEL_5_DRDY_IRQ_INT2_MASK, 540 + .addr_ihl = ST_ACCEL_5_IHL_IRQ_ADDR, 541 + .mask_ihl = ST_ACCEL_5_IHL_IRQ_MASK, 554 542 }, 555 543 .multi_read_bit = ST_ACCEL_5_MULTIREAD_BIT, 556 544 .bootime = 2, /* guess */
+13 -3
drivers/iio/adc/Kconfig
··· 131 131 To compile this driver as a module, choose M here: the module will be 132 132 called at91_adc. 133 133 134 + config 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 + 134 144 config AXP288_ADC 135 145 tristate "X-Powers AXP288 ADC driver" 136 146 depends on MFD_AXP20X ··· 275 265 called mcp320x. 276 266 277 267 config MCP3422 278 - tristate "Microchip Technology MCP3422/3/4/6/7/8 driver" 268 + tristate "Microchip Technology MCP3421/2/3/4/5/6/7/8 driver" 279 269 depends on I2C 280 270 help 281 - Say yes here to build support for Microchip Technology's 282 - MCP3422, MCP3423, MCP3424, MCP3426, MCP3427 or MCP3428 271 + Say yes here to build support for Microchip Technology's MCP3421 272 + MCP3422, MCP3423, MCP3424, MCP3425, MCP3426, MCP3427 or MCP3428 283 273 analog to digital converters. 284 274 285 275 This driver can also be built as a module. If so, the module will be
+1
drivers/iio/adc/Makefile
··· 14 14 obj-$(CONFIG_AD7887) += ad7887.o 15 15 obj-$(CONFIG_AD799X) += ad799x.o 16 16 obj-$(CONFIG_AT91_ADC) += at91_adc.o 17 + obj-$(CONFIG_AT91_SAMA5D2_ADC) += at91-sama5d2_adc.o 17 18 obj-$(CONFIG_AXP288_ADC) += axp288_adc.o 18 19 obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o 19 20 obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
+508
drivers/iio/adc/at91-sama5d2_adc.c
··· 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 + 162 + struct at91_adc_soc_info { 163 + unsigned startup_time; 164 + unsigned min_sample_rate; 165 + unsigned max_sample_rate; 166 + }; 167 + 168 + struct 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 + 187 + static 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 + 202 + static 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 + 226 + static 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 + 246 + static 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 + 259 + static 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 + 276 + static 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 + 325 + static 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 + 343 + static 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 + 349 + static 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 + 463 + per_clk_disable_unprepare: 464 + clk_disable_unprepare(st->per_clk); 465 + vref_disable: 466 + regulator_disable(st->vref); 467 + reg_disable: 468 + regulator_disable(st->reg); 469 + return ret; 470 + } 471 + 472 + static 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 + 487 + static const struct of_device_id at91_adc_dt_match[] = { 488 + { 489 + .compatible = "atmel,sama5d2-adc", 490 + }, { 491 + /* sentinel */ 492 + } 493 + }; 494 + MODULE_DEVICE_TABLE(of, at91_adc_dt_match); 495 + 496 + static 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 + }; 504 + module_platform_driver(at91_adc_driver) 505 + 506 + MODULE_AUTHOR("Ludovic Desroches <ludovic.desroches@atmel.com>"); 507 + MODULE_DESCRIPTION("Atmel AT91 SAMA5D2 ADC"); 508 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/iio/adc/axp288_adc.c
··· 46 46 struct regmap *regmap; 47 47 }; 48 48 49 - static const struct iio_chan_spec const axp288_adc_channels[] = { 49 + static const struct iio_chan_spec axp288_adc_channels[] = { 50 50 { 51 51 .indexed = 1, 52 52 .type = IIO_TEMP,
+19 -12
drivers/iio/adc/mcp320x.c
··· 187 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 192 .type = IIO_VOLTAGE, \ 193 193 .indexed = 1, \ 194 - .channel = (num * 2), \ 195 - .channel2 = (num * 2 + 1), \ 196 - .address = (num * 2), \ 194 + .channel = (chan1), \ 195 + .channel2 = (chan2), \ 196 + .address = (chan1), \ 197 197 .differential = 1, \ 198 198 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 199 199 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \ 200 200 } 201 201 202 202 static const struct iio_chan_spec mcp3201_channels[] = { 203 - MCP320X_VOLTAGE_CHANNEL_DIFF(0), 203 + MCP320X_VOLTAGE_CHANNEL_DIFF(0, 1), 204 204 }; 205 205 206 206 static const struct iio_chan_spec mcp3202_channels[] = { 207 207 MCP320X_VOLTAGE_CHANNEL(0), 208 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 212 213 static const struct iio_chan_spec mcp3204_channels[] = { ··· 215 214 MCP320X_VOLTAGE_CHANNEL(1), 216 215 MCP320X_VOLTAGE_CHANNEL(2), 217 216 MCP320X_VOLTAGE_CHANNEL(3), 218 - MCP320X_VOLTAGE_CHANNEL_DIFF(0), 219 - MCP320X_VOLTAGE_CHANNEL_DIFF(1), 217 + MCP320X_VOLTAGE_CHANNEL_DIFF(0, 1), 218 + MCP320X_VOLTAGE_CHANNEL_DIFF(1, 0), 219 + MCP320X_VOLTAGE_CHANNEL_DIFF(2, 3), 220 + MCP320X_VOLTAGE_CHANNEL_DIFF(3, 2), 220 221 }; 221 222 222 223 static const struct iio_chan_spec mcp3208_channels[] = { ··· 230 227 MCP320X_VOLTAGE_CHANNEL(5), 231 228 MCP320X_VOLTAGE_CHANNEL(6), 232 229 MCP320X_VOLTAGE_CHANNEL(7), 233 - MCP320X_VOLTAGE_CHANNEL_DIFF(0), 234 - MCP320X_VOLTAGE_CHANNEL_DIFF(1), 235 - MCP320X_VOLTAGE_CHANNEL_DIFF(2), 236 - MCP320X_VOLTAGE_CHANNEL_DIFF(3), 230 + MCP320X_VOLTAGE_CHANNEL_DIFF(0, 1), 231 + MCP320X_VOLTAGE_CHANNEL_DIFF(1, 0), 232 + MCP320X_VOLTAGE_CHANNEL_DIFF(2, 3), 233 + MCP320X_VOLTAGE_CHANNEL_DIFF(3, 2), 234 + MCP320X_VOLTAGE_CHANNEL_DIFF(4, 5), 235 + MCP320X_VOLTAGE_CHANNEL_DIFF(5, 4), 236 + MCP320X_VOLTAGE_CHANNEL_DIFF(6, 7), 237 + MCP320X_VOLTAGE_CHANNEL_DIFF(7, 6), 237 238 }; 238 239 239 240 static const struct iio_info mcp320x_info = {
+5 -2
drivers/iio/adc/mcp3422.c
··· 1 1 /* 2 - * mcp3422.c - driver for the Microchip mcp3422/3/4/6/7/8 chip family 2 + * mcp3422.c - driver for the Microchip mcp3421/2/3/4/5/6/7/8 chip family 3 3 * 4 4 * Copyright (C) 2013, Angelo Compagnucci 5 5 * Author: Angelo Compagnucci <angelo.compagnucci@gmail.com> 6 6 * 7 7 * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/22088b.pdf 8 8 * http://ww1.microchip.com/downloads/en/DeviceDoc/22226a.pdf 9 + * http://ww1.microchip.com/downloads/en/DeviceDoc/22072b.pdf 9 10 * 10 11 * This driver exports the value of analog input voltage to sysfs, the 11 12 * voltage unit is nV. ··· 358 357 359 358 switch (adc->id) { 360 359 case 1: 360 + case 5: 361 361 indio_dev->channels = mcp3421_channels; 362 362 indio_dev->num_channels = ARRAY_SIZE(mcp3421_channels); 363 363 break; ··· 397 395 { "mcp3422", 2 }, 398 396 { "mcp3423", 3 }, 399 397 { "mcp3424", 4 }, 398 + { "mcp3425", 5 }, 400 399 { "mcp3426", 6 }, 401 400 { "mcp3427", 7 }, 402 401 { "mcp3428", 8 }, ··· 424 421 module_i2c_driver(mcp3422_driver); 425 422 426 423 MODULE_AUTHOR("Angelo Compagnucci <angelo.compagnucci@gmail.com>"); 427 - MODULE_DESCRIPTION("Microchip mcp3422/3/4/6/7/8 driver"); 424 + MODULE_DESCRIPTION("Microchip mcp3421/2/3/4/5/6/7/8 driver"); 428 425 MODULE_LICENSE("GPL v2");
+13
drivers/iio/chemical/Kconfig
··· 4 4 5 5 menu "Chemical Sensors" 6 6 7 + config 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 + 7 20 config IAQCORE 8 21 tristate "AMS iAQ-Core VOC sensors" 9 22 depends on I2C
+1
drivers/iio/chemical/Makefile
··· 3 3 # 4 4 5 5 # When adding new entries keep the list in alphabetical order 6 + obj-$(CONFIG_ATLAS_PH_SENSOR) += atlas-ph-sensor.o 6 7 obj-$(CONFIG_IAQCORE) += ams-iaq-core.o 7 8 obj-$(CONFIG_VZ89X) += vz89x.o
+511
drivers/iio/chemical/atlas-ph-sensor.c
··· 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 + 57 + struct 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 + 66 + static 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 + 73 + static 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 + 78 + static 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 + 89 + static 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 + 113 + static int atlas_set_powermode(struct atlas_data *data, int on) 114 + { 115 + return regmap_write(data->regmap, ATLAS_REG_PWR_CONTROL, on); 116 + } 117 + 118 + static 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 + 125 + static 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 + 143 + static 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 + 160 + static const struct iio_trigger_ops atlas_interrupt_trigger_ops = { 161 + .owner = THIS_MODULE, 162 + }; 163 + 164 + static const struct iio_buffer_setup_ops atlas_buffer_setup_ops = { 165 + .postenable = atlas_buffer_postenable, 166 + .predisable = atlas_buffer_predisable, 167 + }; 168 + 169 + static 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 + 176 + static 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 + 195 + static 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 + 205 + static 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 + 230 + static 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 + 285 + static 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 + 302 + static 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 + 308 + static 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 + 335 + static 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 + 433 + unregister_pm: 434 + pm_runtime_disable(&client->dev); 435 + atlas_set_powermode(data, 0); 436 + 437 + unregister_buffer: 438 + iio_triggered_buffer_cleanup(indio_dev); 439 + 440 + unregister_trigger: 441 + iio_trigger_unregister(data->trig); 442 + 443 + return ret; 444 + } 445 + 446 + static 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 463 + static 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 + 471 + static 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 + 480 + static const struct dev_pm_ops atlas_pm_ops = { 481 + SET_RUNTIME_PM_OPS(atlas_runtime_suspend, 482 + atlas_runtime_resume, NULL) 483 + }; 484 + 485 + static const struct i2c_device_id atlas_id[] = { 486 + { "atlas-ph-sm", 0 }, 487 + {} 488 + }; 489 + MODULE_DEVICE_TABLE(i2c, atlas_id); 490 + 491 + static const struct of_device_id atlas_dt_ids[] = { 492 + { .compatible = "atlas,ph-sm" }, 493 + { } 494 + }; 495 + MODULE_DEVICE_TABLE(of, atlas_dt_ids); 496 + 497 + static 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 + }; 507 + module_i2c_driver(atlas_driver); 508 + 509 + MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>"); 510 + MODULE_DESCRIPTION("Atlas Scientific pH-SM sensor"); 511 + MODULE_LICENSE("GPL");
+4 -2
drivers/iio/common/st_sensors/st_sensors_core.c
··· 18 18 #include <asm/unaligned.h> 19 19 #include <linux/iio/common/st_sensors.h> 20 20 21 + #include "st_sensors_core.h" 22 + 21 23 static inline u32 st_sensors_get_unaligned_le24(const u8 *p) 22 24 { 23 25 return (s32)((p[0] | p[1] << 8 | p[2] << 16) << 8) >> 8; 24 26 } 25 27 26 - static int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, 27 - u8 reg_addr, u8 mask, u8 data) 28 + int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, 29 + u8 reg_addr, u8 mask, u8 data) 28 30 { 29 31 int err; 30 32 u8 new_data;
+8
drivers/iio/common/st_sensors/st_sensors_core.h
··· 1 + /* 2 + * Local functions in the ST Sensors core 3 + */ 4 + #ifndef __ST_SENSORS_CORE_H 5 + #define __ST_SENSORS_CORE_H 6 + int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, 7 + u8 reg_addr, u8 mask, u8 data); 8 + #endif
+42 -10
drivers/iio/common/st_sensors/st_sensors_trigger.c
··· 14 14 #include <linux/iio/iio.h> 15 15 #include <linux/iio/trigger.h> 16 16 #include <linux/interrupt.h> 17 - 18 17 #include <linux/iio/common/st_sensors.h> 19 - 18 + #include "st_sensors_core.h" 20 19 21 20 int st_sensors_allocate_trigger(struct iio_dev *indio_dev, 22 21 const struct iio_trigger_ops *trigger_ops) 23 22 { 24 - int err; 23 + int err, irq; 25 24 struct st_sensor_data *sdata = iio_priv(indio_dev); 25 + unsigned long irq_trig; 26 26 27 27 sdata->trig = iio_trigger_alloc("%s-trigger", indio_dev->name); 28 28 if (sdata->trig == NULL) { 29 - err = -ENOMEM; 30 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 68 iio_trigger_generic_data_rdy_poll, 36 69 NULL, 37 - IRQF_TRIGGER_RISING, 70 + irq_trig, 38 71 sdata->trig->name, 39 72 sdata->trig); 40 73 if (err) { 41 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 78 iio_trigger_set_drvdata(sdata->trig, indio_dev); ··· 90 57 91 58 iio_trigger_register_error: 92 59 free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig); 93 - request_irq_error: 60 + iio_trigger_free: 94 61 iio_trigger_free(sdata->trig); 95 - iio_trigger_alloc_error: 96 62 return err; 97 63 } 98 64 EXPORT_SYMBOL(st_sensors_allocate_trigger);
+12 -2
drivers/iio/dac/Kconfig
··· 111 111 To compile this driver as a module, choose M here: the 112 112 module will be called ad5755. 113 113 114 + config 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 + 114 124 config AD5764 115 125 tristate "Analog Devices AD5764/64R/44/44R DAC driver" 116 126 depends on SPI_MASTER ··· 186 176 10 bits DAC. 187 177 188 178 config MCP4725 189 - tristate "MCP4725 DAC driver" 179 + tristate "MCP4725/6 DAC driver" 190 180 depends on I2C 191 181 ---help--- 192 182 Say Y here if you want to build a driver for the Microchip 193 - MCP 4725 12-bit digital-to-analog converter (DAC) with I2C 183 + MCP 4725/6 12-bit digital-to-analog converter (DAC) with I2C 194 184 interface. 195 185 196 186 To compile this driver as a module, choose M here: the module
+1
drivers/iio/dac/Makefile
··· 12 12 obj-$(CONFIG_AD5446) += ad5446.o 13 13 obj-$(CONFIG_AD5449) += ad5449.o 14 14 obj-$(CONFIG_AD5755) += ad5755.o 15 + obj-$(CONFIG_AD5761) += ad5761.o 15 16 obj-$(CONFIG_AD5764) += ad5764.o 16 17 obj-$(CONFIG_AD5791) += ad5791.o 17 18 obj-$(CONFIG_AD5686) += ad5686.o
+430
drivers/iio/dac/ad5761.c
··· 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 + 37 + struct ad5761_chip_info { 38 + unsigned long int_vref; 39 + const struct iio_chan_spec channel; 40 + }; 41 + 42 + struct ad5761_range_params { 43 + int m; 44 + int c; 45 + }; 46 + 47 + enum 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 + */ 63 + struct 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 + 81 + static 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 + 116 + static 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 + 123 + static 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 + 135 + static 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 + 162 + static 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 + 174 + static 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 + 198 + static 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 + 232 + static 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 + 251 + static 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 + 271 + static 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 + 290 + static 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 + 341 + disable_regulator_vref: 342 + regulator_disable(st->vref_reg); 343 + st->vref_reg = NULL; 344 + return ret; 345 + } 346 + 347 + static 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 + 389 + disable_regulator_err: 390 + if (!IS_ERR_OR_NULL(st->vref_reg)) 391 + regulator_disable(st->vref_reg); 392 + 393 + return ret; 394 + } 395 + 396 + static 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 + 409 + static 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 + }; 416 + MODULE_DEVICE_TABLE(spi, ad5761_id); 417 + 418 + static 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 + }; 426 + module_spi_driver(ad5761_driver); 427 + 428 + MODULE_AUTHOR("Ricardo Ribalda <ricardo.ribalda@gmail.com>"); 429 + MODULE_DESCRIPTION("Analog Devices AD5721, AD5721R, AD5761, AD5761R driver"); 430 + MODULE_LICENSE("GPL v2");
+67 -20
drivers/iio/dac/mcp4725.c
··· 1 1 /* 2 - * mcp4725.c - Support for Microchip MCP4725 2 + * mcp4725.c - Support for Microchip MCP4725/6 3 3 * 4 4 * Copyright (C) 2012 Peter Meerwald <pmeerw@pmeerw.net> 5 5 * ··· 134 134 "500kohm_to_gnd" 135 135 }; 136 136 137 + static const char * const mcp4726_powerdown_modes[] = { 138 + "1kohm_to_gnd", 139 + "125kohm_to_gnd", 140 + "640kohm_to_gnd" 141 + }; 142 + 137 143 static int mcp4725_get_powerdown_mode(struct iio_dev *indio_dev, 138 144 const struct iio_chan_spec *chan) 139 145 { ··· 188 182 return len; 189 183 } 190 184 191 - static const struct iio_enum mcp4725_powerdown_mode_enum = { 192 - .items = mcp4725_powerdown_modes, 193 - .num_items = ARRAY_SIZE(mcp4725_powerdown_modes), 194 - .get = mcp4725_get_powerdown_mode, 195 - .set = mcp4725_set_powerdown_mode, 185 + enum { 186 + MCP4725, 187 + MCP4726, 188 + }; 189 + 190 + static const struct iio_enum mcp472x_powerdown_mode_enum[] = { 191 + [MCP4725] = { 192 + .items = mcp4725_powerdown_modes, 193 + .num_items = ARRAY_SIZE(mcp4725_powerdown_modes), 194 + .get = mcp4725_get_powerdown_mode, 195 + .set = mcp4725_set_powerdown_mode, 196 + }, 197 + [MCP4726] = { 198 + .items = mcp4726_powerdown_modes, 199 + .num_items = ARRAY_SIZE(mcp4726_powerdown_modes), 200 + .get = mcp4725_get_powerdown_mode, 201 + .set = mcp4725_set_powerdown_mode, 202 + }, 196 203 }; 197 204 198 205 static const struct iio_chan_spec_ext_info mcp4725_ext_info[] = { ··· 215 196 .write = mcp4725_write_powerdown, 216 197 .shared = IIO_SEPARATE, 217 198 }, 218 - IIO_ENUM("powerdown_mode", IIO_SEPARATE, &mcp4725_powerdown_mode_enum), 219 - IIO_ENUM_AVAILABLE("powerdown_mode", &mcp4725_powerdown_mode_enum), 199 + IIO_ENUM("powerdown_mode", IIO_SEPARATE, 200 + &mcp472x_powerdown_mode_enum[MCP4725]), 201 + IIO_ENUM_AVAILABLE("powerdown_mode", 202 + &mcp472x_powerdown_mode_enum[MCP4725]), 220 203 { }, 221 204 }; 222 205 223 - static const struct iio_chan_spec mcp4725_channel = { 224 - .type = IIO_VOLTAGE, 225 - .indexed = 1, 226 - .output = 1, 227 - .channel = 0, 228 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 229 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 230 - .ext_info = mcp4725_ext_info, 206 + static const struct iio_chan_spec_ext_info mcp4726_ext_info[] = { 207 + { 208 + .name = "powerdown", 209 + .read = mcp4725_read_powerdown, 210 + .write = mcp4725_write_powerdown, 211 + .shared = IIO_SEPARATE, 212 + }, 213 + IIO_ENUM("powerdown_mode", IIO_SEPARATE, 214 + &mcp472x_powerdown_mode_enum[MCP4726]), 215 + IIO_ENUM_AVAILABLE("powerdown_mode", 216 + &mcp472x_powerdown_mode_enum[MCP4726]), 217 + { }, 218 + }; 219 + 220 + static const struct iio_chan_spec mcp472x_channel[] = { 221 + [MCP4725] = { 222 + .type = IIO_VOLTAGE, 223 + .indexed = 1, 224 + .output = 1, 225 + .channel = 0, 226 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 227 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 228 + .ext_info = mcp4725_ext_info, 229 + }, 230 + [MCP4726] = { 231 + .type = IIO_VOLTAGE, 232 + .indexed = 1, 233 + .output = 1, 234 + .channel = 0, 235 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 236 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 237 + .ext_info = mcp4726_ext_info, 238 + }, 231 239 }; 232 240 233 241 static int mcp4725_set_value(struct iio_dev *indio_dev, int val) ··· 347 301 348 302 indio_dev->dev.parent = &client->dev; 349 303 indio_dev->info = &mcp4725_info; 350 - indio_dev->channels = &mcp4725_channel; 304 + indio_dev->channels = &mcp472x_channel[id->driver_data]; 351 305 indio_dev->num_channels = 1; 352 306 indio_dev->modes = INDIO_DIRECT_MODE; 353 307 ··· 361 315 } 362 316 pd = (inbuf[0] >> 1) & 0x3; 363 317 data->powerdown = pd > 0 ? true : false; 364 - data->powerdown_mode = pd ? pd-1 : 2; /* 500kohm_to_gnd */ 318 + data->powerdown_mode = pd ? pd - 1 : 2; /* largest register to gnd */ 365 319 data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4); 366 320 367 321 return iio_device_register(indio_dev); ··· 374 328 } 375 329 376 330 static const struct i2c_device_id mcp4725_id[] = { 377 - { "mcp4725", 0 }, 331 + { "mcp4725", MCP4725 }, 332 + { "mcp4726", MCP4726 }, 378 333 { } 379 334 }; 380 335 MODULE_DEVICE_TABLE(i2c, mcp4725_id); ··· 392 345 module_i2c_driver(mcp4725_driver); 393 346 394 347 MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>"); 395 - MODULE_DESCRIPTION("MCP4725 12-bit DAC"); 348 + MODULE_DESCRIPTION("MCP4725/6 12-bit DAC"); 396 349 MODULE_LICENSE("GPL");
+15
drivers/iio/gyro/st_gyro_core.c
··· 185 185 .drdy_irq = { 186 186 .addr = ST_GYRO_1_DRDY_IRQ_ADDR, 187 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 194 .multi_read_bit = ST_GYRO_1_MULTIREAD_BIT, 190 195 .bootime = 2, ··· 253 248 .drdy_irq = { 254 249 .addr = ST_GYRO_2_DRDY_IRQ_ADDR, 255 250 .mask_int2 = ST_GYRO_2_DRDY_IRQ_INT2_MASK, 251 + /* 252 + * The sensor has IHL (active low) and open 253 + * drain settings, but only for INT1 and not 254 + * for the DRDY line on INT2. 255 + */ 256 256 }, 257 257 .multi_read_bit = ST_GYRO_2_MULTIREAD_BIT, 258 258 .bootime = 2, ··· 317 307 .drdy_irq = { 318 308 .addr = ST_GYRO_3_DRDY_IRQ_ADDR, 319 309 .mask_int2 = ST_GYRO_3_DRDY_IRQ_INT2_MASK, 310 + /* 311 + * The sensor has IHL (active low) and open 312 + * drain settings, but only for INT1 and not 313 + * for the DRDY line on INT2. 314 + */ 320 315 }, 321 316 .multi_read_bit = ST_GYRO_3_MULTIREAD_BIT, 322 317 .bootime = 2,
+75 -6
drivers/iio/health/max30100.c
··· 13 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 * GNU General Public License for more details. 15 15 * 16 - * TODO: allow LED current and pulse length controls via device tree properties 16 + * TODO: enable pulse length controls via device tree properties 17 17 */ 18 18 19 19 #include <linux/module.h> ··· 24 24 #include <linux/irq.h> 25 25 #include <linux/i2c.h> 26 26 #include <linux/mutex.h> 27 + #include <linux/of.h> 27 28 #include <linux/regmap.h> 28 29 #include <linux/iio/iio.h> 29 30 #include <linux/iio/buffer.h> ··· 66 65 #define MAX30100_REG_SPO2_CONFIG_1600US 0x3 67 66 68 67 #define MAX30100_REG_LED_CONFIG 0x09 68 + #define MAX30100_REG_LED_CONFIG_LED_MASK 0x0f 69 69 #define MAX30100_REG_LED_CONFIG_RED_LED_SHIFT 4 70 70 71 71 #define MAX30100_REG_LED_CONFIG_24MA 0x07 ··· 111 109 .cache_type = REGCACHE_FLAT, 112 110 113 111 .volatile_reg = max30100_is_volatile_reg, 112 + }; 113 + 114 + static const unsigned int max30100_led_current_mapping[] = { 115 + 4400, 7600, 11000, 14200, 17400, 116 + 20800, 24000, 27100, 30600, 33800, 117 + 37000, 40200, 43600, 46800, 50000 114 118 }; 115 119 116 120 static const unsigned long max30100_scan_masks[] = {0x3, 0}; ··· 251 243 return IRQ_HANDLED; 252 244 } 253 245 246 + static int max30100_get_current_idx(unsigned int val, int *reg) 247 + { 248 + int idx; 249 + 250 + /* LED turned off */ 251 + if (val == 0) { 252 + *reg = 0; 253 + return 0; 254 + } 255 + 256 + for (idx = 0; idx < ARRAY_SIZE(max30100_led_current_mapping); idx++) { 257 + if (max30100_led_current_mapping[idx] == val) { 258 + *reg = idx + 1; 259 + return 0; 260 + } 261 + } 262 + 263 + return -EINVAL; 264 + } 265 + 266 + static int max30100_led_init(struct max30100_data *data) 267 + { 268 + struct device *dev = &data->client->dev; 269 + struct device_node *np = dev->of_node; 270 + unsigned int val[2]; 271 + int reg, ret; 272 + 273 + ret = of_property_read_u32_array(np, "maxim,led-current-microamp", 274 + (unsigned int *) &val, 2); 275 + if (ret) { 276 + /* Default to 24 mA RED LED, 50 mA IR LED */ 277 + reg = (MAX30100_REG_LED_CONFIG_24MA << 278 + MAX30100_REG_LED_CONFIG_RED_LED_SHIFT) | 279 + MAX30100_REG_LED_CONFIG_50MA; 280 + dev_warn(dev, "no led-current-microamp set"); 281 + 282 + return regmap_write(data->regmap, MAX30100_REG_LED_CONFIG, reg); 283 + } 284 + 285 + /* RED LED current */ 286 + ret = max30100_get_current_idx(val[0], &reg); 287 + if (ret) { 288 + dev_err(dev, "invalid RED current setting %d", val[0]); 289 + return ret; 290 + } 291 + 292 + ret = regmap_update_bits(data->regmap, MAX30100_REG_LED_CONFIG, 293 + MAX30100_REG_LED_CONFIG_LED_MASK << 294 + MAX30100_REG_LED_CONFIG_RED_LED_SHIFT, 295 + reg << MAX30100_REG_LED_CONFIG_RED_LED_SHIFT); 296 + if (ret) 297 + return ret; 298 + 299 + /* IR LED current */ 300 + ret = max30100_get_current_idx(val[1], &reg); 301 + if (ret) { 302 + dev_err(dev, "invalid IR current setting %d", val[1]); 303 + return ret; 304 + } 305 + 306 + return regmap_update_bits(data->regmap, MAX30100_REG_LED_CONFIG, 307 + MAX30100_REG_LED_CONFIG_LED_MASK, reg); 308 + } 309 + 254 310 static int max30100_chip_init(struct max30100_data *data) 255 311 { 256 312 int ret; 257 313 258 - /* RED IR LED = 24mA, IR LED = 50mA */ 259 - ret = regmap_write(data->regmap, MAX30100_REG_LED_CONFIG, 260 - (MAX30100_REG_LED_CONFIG_24MA << 261 - MAX30100_REG_LED_CONFIG_RED_LED_SHIFT) | 262 - MAX30100_REG_LED_CONFIG_50MA); 314 + /* setup LED current settings */ 315 + ret = max30100_led_init(data); 263 316 if (ret) 264 317 return ret; 265 318
+4 -2
drivers/iio/humidity/Kconfig
··· 43 43 humidity and temperature sensor. 44 44 45 45 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 48 49 config SI7020 49 50 tristate "Si7013/20/21 Relative Humidity and Temperature Sensors" 50 51 depends on I2C 51 52 help 52 53 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 57 To compile this driver as a module, choose M here: the module 56 58 will be called si7020.
+50 -27
drivers/iio/humidity/dht11.c
··· 50 50 #define DHT11_EDGES_PER_READ (2 * DHT11_BITS_PER_READ + \ 51 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 74 #define DHT11_START_TRANSMISSION 18 /* ms */ 55 - #define DHT11_SENSOR_RESPONSE 80000 56 - #define DHT11_START_BIT 50000 57 - #define DHT11_DATA_BIT_LOW 27000 58 - #define DHT11_DATA_BIT_HIGH 70000 75 + #define DHT11_MIN_TIMERES 34000 /* ns */ 76 + #define DHT11_THRESHOLD 49000 /* ns */ 77 + #define DHT11_AMBIG_LOW 23000 /* ns */ 78 + #define DHT11_AMBIG_HIGH 30000 /* ns */ 59 79 60 80 struct dht11 { 61 81 struct device *dev; ··· 96 76 struct {s64 ts; int value; } edges[DHT11_EDGES_PER_READ]; 97 77 }; 98 78 99 - static unsigned char dht11_decode_byte(int *timing, int threshold) 79 + static unsigned char dht11_decode_byte(char *bits) 100 80 { 101 81 unsigned char ret = 0; 102 82 int i; 103 83 104 84 for (i = 0; i < 8; ++i) { 105 85 ret <<= 1; 106 - if (timing[i] >= threshold) 86 + if (bits[i]) 107 87 ++ret; 108 88 } 109 89 110 90 return ret; 111 91 } 112 92 113 - static int dht11_decode(struct dht11 *dht11, int offset, int timeres) 93 + static int dht11_decode(struct dht11 *dht11, int offset) 114 94 { 115 - int i, t, timing[DHT11_BITS_PER_READ], threshold; 95 + int i, t; 96 + char bits[DHT11_BITS_PER_READ]; 116 97 unsigned char temp_int, temp_dec, hum_int, hum_dec, checksum; 117 98 118 - threshold = DHT11_DATA_BIT_HIGH / timeres; 119 - if (DHT11_DATA_BIT_LOW / timeres + 1 >= threshold) 120 - pr_err("dht11: WARNING: decoding ambiguous\n"); 121 - 122 - /* scale down with timeres and check validity */ 123 99 for (i = 0; i < DHT11_BITS_PER_READ; ++i) { 124 100 t = dht11->edges[offset + 2 * i + 2].ts - 125 101 dht11->edges[offset + 2 * i + 1].ts; 126 102 if (!dht11->edges[offset + 2 * i + 1].value) 127 103 return -EIO; /* lost synchronisation */ 128 - timing[i] = t / timeres; 104 + bits[i] = t > DHT11_THRESHOLD; 129 105 } 130 106 131 - hum_int = dht11_decode_byte(timing, threshold); 132 - hum_dec = dht11_decode_byte(&timing[8], threshold); 133 - temp_int = dht11_decode_byte(&timing[16], threshold); 134 - temp_dec = dht11_decode_byte(&timing[24], threshold); 135 - checksum = dht11_decode_byte(&timing[32], threshold); 107 + hum_int = dht11_decode_byte(bits); 108 + hum_dec = dht11_decode_byte(&bits[8]); 109 + temp_int = dht11_decode_byte(&bits[16]); 110 + temp_dec = dht11_decode_byte(&bits[24]); 111 + checksum = dht11_decode_byte(&bits[32]); 136 112 137 113 if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum) 138 114 return -EIO; ··· 177 161 int *val, int *val2, long m) 178 162 { 179 163 struct dht11 *dht11 = iio_priv(iio_dev); 180 - int ret, timeres; 164 + int ret, timeres, offset; 181 165 182 166 mutex_lock(&dht11->lock); 183 167 if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_real_ns()) { 184 168 timeres = ktime_get_resolution_ns(); 185 - if (DHT11_DATA_BIT_HIGH < 2 * timeres) { 169 + if (timeres > DHT11_MIN_TIMERES) { 186 170 dev_err(dht11->dev, "timeresolution %dns too low\n", 187 171 timeres); 188 172 /* In theory a better clock could become available ··· 192 176 ret = -EAGAIN; 193 177 goto err; 194 178 } 179 + if (timeres > DHT11_AMBIG_LOW && timeres < DHT11_AMBIG_HIGH) 180 + dev_warn(dht11->dev, 181 + "timeresolution: %dns - decoding ambiguous\n", 182 + timeres); 195 183 196 184 reinit_completion(&dht11->completion); 197 185 ··· 228 208 if (ret < 0) 229 209 goto err; 230 210 231 - ret = dht11_decode(dht11, 232 - dht11->num_edges == DHT11_EDGES_PER_READ ? 233 - DHT11_EDGES_PREAMBLE : 234 - DHT11_EDGES_PREAMBLE - 2, 235 - timeres); 211 + offset = DHT11_EDGES_PREAMBLE + 212 + dht11->num_edges - DHT11_EDGES_PER_READ; 213 + for (; offset >= 0; --offset) { 214 + ret = dht11_decode(dht11, offset); 215 + if (!ret) 216 + break; 217 + } 218 + 236 219 if (ret) 237 220 goto err; 238 221 }
+1
drivers/iio/humidity/si7005.c
··· 170 170 171 171 static const struct i2c_device_id si7005_id[] = { 172 172 { "si7005", 0 }, 173 + { "th02", 0 }, 173 174 { } 174 175 }; 175 176 MODULE_DEVICE_TABLE(i2c, si7005_id);
+1
drivers/iio/humidity/si7020.c
··· 149 149 150 150 static const struct i2c_device_id si7020_id[] = { 151 151 { "si7020", 0 }, 152 + { "th06", 0 }, 152 153 { } 153 154 }; 154 155 MODULE_DEVICE_TABLE(i2c, si7020_id);
+2 -3
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 727 727 /** 728 728 * inv_check_and_setup_chip() - check and setup chip. 729 729 */ 730 - static int inv_check_and_setup_chip(struct inv_mpu6050_state *st, 731 - const struct i2c_device_id *id) 730 + static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) 732 731 { 733 732 int result; 734 733 ··· 794 795 if (pdata) 795 796 st->plat_data = *pdata; 796 797 /* power is turned on inside check chip type*/ 797 - result = inv_check_and_setup_chip(st, id); 798 + result = inv_check_and_setup_chip(st); 798 799 if (result) 799 800 return result; 800 801
+1
drivers/iio/industrialio-core.c
··· 77 77 [IIO_VELOCITY] = "velocity", 78 78 [IIO_CONCENTRATION] = "concentration", 79 79 [IIO_RESISTANCE] = "resistance", 80 + [IIO_PH] = "ph", 80 81 }; 81 82 82 83 static const char * const iio_modifier_names[] = {
+106 -50
drivers/iio/light/opt3001.c
··· 65 65 #define OPT3001_REG_EXPONENT(n) ((n) >> 12) 66 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 72 * 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 74 80 struct opt3001 { 75 81 struct i2c_client *client; 76 82 struct device *dev; 77 83 78 84 struct mutex lock; 79 - u16 ok_to_ignore_lock:1; 80 - u16 result_ready:1; 85 + bool ok_to_ignore_lock; 86 + bool result_ready; 81 87 wait_queue_head_t result_ready_queue; 82 88 u16 result; 83 89 ··· 95 89 96 90 u8 high_thresh_exp; 97 91 u8 low_thresh_exp; 92 + 93 + bool use_irq; 98 94 }; 99 95 100 96 struct opt3001_scale { ··· 235 227 u16 reg; 236 228 u8 exponent; 237 229 u16 value; 230 + long timeout; 238 231 239 - /* 240 - * Enable the end-of-conversion interrupt mechanism. Note that doing 241 - * so will overwrite the low-level limit value however we will restore 242 - * this value later on. 243 - */ 244 - ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_LOW_LIMIT, 245 - OPT3001_LOW_LIMIT_EOC_ENABLE); 246 - if (ret < 0) { 247 - dev_err(opt->dev, "failed to write register %02x\n", 248 - OPT3001_LOW_LIMIT); 249 - return ret; 232 + if (opt->use_irq) { 233 + /* 234 + * Enable the end-of-conversion interrupt mechanism. Note that 235 + * doing so will overwrite the low-level limit value however we 236 + * will restore this value later on. 237 + */ 238 + ret = i2c_smbus_write_word_swapped(opt->client, 239 + OPT3001_LOW_LIMIT, 240 + OPT3001_LOW_LIMIT_EOC_ENABLE); 241 + if (ret < 0) { 242 + dev_err(opt->dev, "failed to write register %02x\n", 243 + OPT3001_LOW_LIMIT); 244 + return ret; 245 + } 246 + 247 + /* Allow IRQ to access the device despite lock being set */ 248 + opt->ok_to_ignore_lock = true; 250 249 } 251 250 252 - /* Reset data-ready indicator flag (will be set in the IRQ routine) */ 251 + /* Reset data-ready indicator flag */ 253 252 opt->result_ready = false; 254 - 255 - /* Allow IRQ to access the device despite lock being set */ 256 - opt->ok_to_ignore_lock = true; 257 253 258 254 /* Configure for single-conversion mode and start a new conversion */ 259 255 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); ··· 278 266 goto err; 279 267 } 280 268 281 - /* Wait for the IRQ to indicate the conversion is complete */ 282 - ret = wait_event_timeout(opt->result_ready_queue, opt->result_ready, 283 - OPT3001_RESULT_READY_TIMEOUT); 269 + if (opt->use_irq) { 270 + /* Wait for the IRQ to indicate the conversion is complete */ 271 + ret = wait_event_timeout(opt->result_ready_queue, 272 + opt->result_ready, 273 + msecs_to_jiffies(OPT3001_RESULT_READY_LONG)); 274 + } else { 275 + /* Sleep for result ready time */ 276 + timeout = (opt->int_time == OPT3001_INT_TIME_SHORT) ? 277 + OPT3001_RESULT_READY_SHORT : OPT3001_RESULT_READY_LONG; 278 + msleep(timeout); 279 + 280 + /* Check result ready flag */ 281 + ret = i2c_smbus_read_word_swapped(opt->client, 282 + OPT3001_CONFIGURATION); 283 + if (ret < 0) { 284 + dev_err(opt->dev, "failed to read register %02x\n", 285 + OPT3001_CONFIGURATION); 286 + goto err; 287 + } 288 + 289 + if (!(ret & OPT3001_CONFIGURATION_CRF)) { 290 + ret = -ETIMEDOUT; 291 + goto err; 292 + } 293 + 294 + /* Obtain value */ 295 + ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_RESULT); 296 + if (ret < 0) { 297 + dev_err(opt->dev, "failed to read register %02x\n", 298 + OPT3001_RESULT); 299 + goto err; 300 + } 301 + opt->result = ret; 302 + opt->result_ready = true; 303 + } 284 304 285 305 err: 286 - /* Disallow IRQ to access the device while lock is active */ 287 - opt->ok_to_ignore_lock = false; 306 + if (opt->use_irq) 307 + /* Disallow IRQ to access the device while lock is active */ 308 + opt->ok_to_ignore_lock = false; 288 309 289 310 if (ret == 0) 290 311 return -ETIMEDOUT; 291 312 else if (ret < 0) 292 313 return ret; 293 314 294 - /* 295 - * Disable the end-of-conversion interrupt mechanism by restoring the 296 - * low-level limit value (clearing OPT3001_LOW_LIMIT_EOC_ENABLE). Note 297 - * that selectively clearing those enable bits would affect the actual 298 - * limit value due to bit-overlap and therefore can't be done. 299 - */ 300 - value = (opt->low_thresh_exp << 12) | opt->low_thresh_mantissa; 301 - ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_LOW_LIMIT, 302 - value); 303 - if (ret < 0) { 304 - dev_err(opt->dev, "failed to write register %02x\n", 305 - OPT3001_LOW_LIMIT); 306 - return ret; 315 + if (opt->use_irq) { 316 + /* 317 + * Disable the end-of-conversion interrupt mechanism by 318 + * restoring the low-level limit value (clearing 319 + * OPT3001_LOW_LIMIT_EOC_ENABLE). Note that selectively clearing 320 + * those enable bits would affect the actual limit value due to 321 + * bit-overlap and therefore can't be done. 322 + */ 323 + value = (opt->low_thresh_exp << 12) | opt->low_thresh_mantissa; 324 + ret = i2c_smbus_write_word_swapped(opt->client, 325 + OPT3001_LOW_LIMIT, 326 + value); 327 + if (ret < 0) { 328 + dev_err(opt->dev, "failed to write register %02x\n", 329 + OPT3001_LOW_LIMIT); 330 + return ret; 331 + } 307 332 } 308 333 309 334 exponent = OPT3001_REG_EXPONENT(opt->result); ··· 374 325 reg = ret; 375 326 376 327 switch (time) { 377 - case 100000: 328 + case OPT3001_INT_TIME_SHORT: 378 329 reg &= ~OPT3001_CONFIGURATION_CT; 379 - opt->int_time = 100000; 330 + opt->int_time = OPT3001_INT_TIME_SHORT; 380 331 break; 381 - case 800000: 332 + case OPT3001_INT_TIME_LONG: 382 333 reg |= OPT3001_CONFIGURATION_CT; 383 - opt->int_time = 800000; 334 + opt->int_time = OPT3001_INT_TIME_LONG; 384 335 break; 385 336 default: 386 337 return -EINVAL; ··· 646 597 647 598 /* Reflect status of the device's integration time setting */ 648 599 if (reg & OPT3001_CONFIGURATION_CT) 649 - opt->int_time = 800000; 600 + opt->int_time = OPT3001_INT_TIME_LONG; 650 601 else 651 - opt->int_time = 100000; 602 + opt->int_time = OPT3001_INT_TIME_SHORT; 652 603 653 604 /* Ensure device is in shutdown initially */ 654 605 opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SHUTDOWN); ··· 782 733 return ret; 783 734 } 784 735 785 - ret = request_threaded_irq(irq, NULL, opt3001_irq, 786 - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 787 - "opt3001", iio); 788 - if (ret) { 789 - dev_err(dev, "failed to request IRQ #%d\n", irq); 790 - return ret; 736 + /* Make use of INT pin only if valid IRQ no. is given */ 737 + if (irq > 0) { 738 + ret = request_threaded_irq(irq, NULL, opt3001_irq, 739 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 740 + "opt3001", iio); 741 + if (ret) { 742 + dev_err(dev, "failed to request IRQ #%d\n", irq); 743 + return ret; 744 + } 745 + opt->use_irq = true; 746 + } else { 747 + dev_dbg(opt->dev, "enabling interrupt-less operation\n"); 791 748 } 792 749 793 750 return 0; ··· 806 751 int ret; 807 752 u16 reg; 808 753 809 - free_irq(client->irq, iio); 754 + if (opt->use_irq) 755 + free_irq(client->irq, iio); 810 756 811 757 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); 812 758 if (ret < 0) {
+2 -2
drivers/iio/magnetometer/ak8975.c
··· 252 252 u8 data_regs[3]; 253 253 }; 254 254 255 - static struct ak_def ak_def_array[AK_MAX_TYPE] = { 255 + static const struct ak_def ak_def_array[AK_MAX_TYPE] = { 256 256 { 257 257 .type = AK8975, 258 258 .raw_to_gauss = ak8975_raw_to_gauss, ··· 360 360 */ 361 361 struct ak8975_data { 362 362 struct i2c_client *client; 363 - struct ak_def *def; 363 + const struct ak_def *def; 364 364 struct attribute_group attrs; 365 365 struct mutex lock; 366 366 u8 asa[3];
+4
drivers/iio/magnetometer/st_magn_core.c
··· 175 175 #define ST_MAGN_3_BDU_MASK 0x10 176 176 #define ST_MAGN_3_DRDY_IRQ_ADDR 0x62 177 177 #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 180 #define ST_MAGN_3_FS_AVL_15000_GAIN 1500 179 181 #define ST_MAGN_3_MULTIREAD_BIT false 180 182 #define ST_MAGN_3_OUT_X_L_ADDR 0x68 ··· 482 480 .drdy_irq = { 483 481 .addr = ST_MAGN_3_DRDY_IRQ_ADDR, 484 482 .mask_int1 = ST_MAGN_3_DRDY_INT_MASK, 483 + .addr_ihl = ST_MAGN_3_IHL_IRQ_ADDR, 484 + .mask_ihl = ST_MAGN_3_IHL_IRQ_MASK, 485 485 }, 486 486 .multi_read_bit = ST_MAGN_3_MULTIREAD_BIT, 487 487 .bootime = 2,
+28 -13
drivers/iio/pressure/Kconfig
··· 10 10 depends on I2C 11 11 select REGMAP_I2C 12 12 help 13 - Say yes here to build support for Bosch Sensortec BMP280 14 - pressure and temperature sensor. 13 + Say yes here to build support for Bosch Sensortec BMP280 14 + pressure and temperature sensor. 15 15 16 - To compile this driver as a module, choose M here: the module 17 - will be called bmp280. 16 + To compile this driver as a module, choose M here: the module 17 + will be called bmp280. 18 18 19 19 config HID_SENSOR_PRESS 20 20 depends on HID_SENSOR_HUB ··· 27 27 Say yes here to build support for the HID SENSOR 28 28 Pressure driver 29 29 30 - To compile this driver as a module, choose M here: the module 31 - will be called hid-sensor-press. 30 + To compile this driver as a module, choose M here: the module 31 + will be called hid-sensor-press. 32 32 33 33 config MPL115 34 + tristate 35 + 36 + config MPL115_I2C 34 37 tristate "Freescale MPL115A2 pressure sensor driver" 35 38 depends on I2C 39 + select MPL115 36 40 help 37 41 Say yes here to build support for the Freescale MPL115A2 38 42 pressure sensor connected via I2C. 39 43 40 - To compile this driver as a module, choose M here: the module 41 - will be called mpl115. 44 + To compile this driver as a module, choose M here: the module 45 + will be called mpl115_i2c. 46 + 47 + config 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 43 58 config MPL3115 44 59 tristate "Freescale MPL3115A2 pressure sensor driver" ··· 64 49 Say yes here to build support for the Freescale MPL3115A2 65 50 pressure sensor / altimeter. 66 51 67 - To compile this driver as a module, choose M here: the module 68 - will be called mpl3115. 52 + To compile this driver as a module, choose M here: the module 53 + will be called mpl3115. 69 54 70 55 config MS5611 71 56 tristate "Measurement Specialties MS5611 pressure sensor driver" ··· 97 82 config MS5637 98 83 tristate "Measurement Specialties MS5637 pressure & temperature sensor" 99 84 depends on I2C 100 - select IIO_MS_SENSORS_I2C 85 + select IIO_MS_SENSORS_I2C 101 86 help 102 87 If you say yes here you get support for the Measurement Specialties 103 88 MS5637 pressure and temperature sensor. ··· 143 128 Say yes here to build support for the EPCOS T5403 pressure sensor 144 129 connected via I2C. 145 130 146 - To compile this driver as a module, choose M here: the module 147 - will be called t5403. 131 + To compile this driver as a module, choose M here: the module 132 + will be called t5403. 148 133 149 134 endmenu
+2
drivers/iio/pressure/Makefile
··· 6 6 obj-$(CONFIG_BMP280) += bmp280.o 7 7 obj-$(CONFIG_HID_SENSOR_PRESS) += hid-sensor-press.o 8 8 obj-$(CONFIG_MPL115) += mpl115.o 9 + obj-$(CONFIG_MPL115_I2C) += mpl115_i2c.o 10 + obj-$(CONFIG_MPL115_SPI) += mpl115_spi.o 9 11 obj-$(CONFIG_MPL3115) += mpl3115.o 10 12 obj-$(CONFIG_MS5611) += ms5611_core.o 11 13 obj-$(CONFIG_MS5611_I2C) += ms5611_i2c.o
+27 -39
drivers/iio/pressure/mpl115.c
··· 1 1 /* 2 - * mpl115.c - Support for Freescale MPL115A2 pressure/temperature sensor 2 + * mpl115.c - Support for Freescale MPL115A pressure/temperature sensor 3 3 * 4 4 * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net> 5 5 * ··· 7 7 * the GNU General Public License. See the file COPYING in the main 8 8 * directory of this archive for more details. 9 9 * 10 - * (7-bit I2C slave address 0x60) 11 - * 12 10 * TODO: shutdown pin 13 11 * 14 12 */ 15 13 16 14 #include <linux/module.h> 17 - #include <linux/i2c.h> 18 15 #include <linux/iio/iio.h> 19 16 #include <linux/delay.h> 17 + 18 + #include "mpl115.h" 20 19 21 20 #define MPL115_PADC 0x00 /* pressure ADC output value, MSB first, 10 bit */ 22 21 #define MPL115_TADC 0x02 /* temperature ADC output value, MSB first, 10 bit */ ··· 26 27 #define MPL115_CONVERT 0x12 /* convert temperature and pressure */ 27 28 28 29 struct mpl115_data { 29 - struct i2c_client *client; 30 + struct device *dev; 30 31 struct mutex lock; 31 32 s16 a0; 32 33 s16 b1, b2; 33 34 s16 c12; 35 + const struct mpl115_ops *ops; 34 36 }; 35 37 36 38 static int mpl115_request(struct mpl115_data *data) 37 39 { 38 - int ret = i2c_smbus_write_byte_data(data->client, MPL115_CONVERT, 0); 40 + int ret = data->ops->write(data->dev, MPL115_CONVERT, 0); 41 + 39 42 if (ret < 0) 40 43 return ret; 41 44 ··· 58 57 if (ret < 0) 59 58 goto done; 60 59 61 - ret = i2c_smbus_read_word_swapped(data->client, MPL115_PADC); 60 + ret = data->ops->read(data->dev, MPL115_PADC); 62 61 if (ret < 0) 63 62 goto done; 64 63 padc = ret >> 6; 65 64 66 - ret = i2c_smbus_read_word_swapped(data->client, MPL115_TADC); 65 + ret = data->ops->read(data->dev, MPL115_TADC); 67 66 if (ret < 0) 68 67 goto done; 69 68 tadc = ret >> 6; ··· 91 90 ret = mpl115_request(data); 92 91 if (ret < 0) 93 92 goto done; 94 - ret = i2c_smbus_read_word_swapped(data->client, MPL115_TADC); 93 + ret = data->ops->read(data->dev, MPL115_TADC); 95 94 done: 96 95 mutex_unlock(&data->lock); 97 96 return ret; ··· 146 145 .driver_module = THIS_MODULE, 147 146 }; 148 147 149 - static int mpl115_probe(struct i2c_client *client, 150 - const struct i2c_device_id *id) 148 + int mpl115_probe(struct device *dev, const char *name, 149 + const struct mpl115_ops *ops) 151 150 { 152 151 struct mpl115_data *data; 153 152 struct iio_dev *indio_dev; 154 153 int ret; 155 154 156 - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 157 - return -ENODEV; 158 - 159 - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 155 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 160 156 if (!indio_dev) 161 157 return -ENOMEM; 162 158 163 159 data = iio_priv(indio_dev); 164 - data->client = client; 160 + data->dev = dev; 161 + data->ops = ops; 165 162 mutex_init(&data->lock); 166 163 167 - i2c_set_clientdata(client, indio_dev); 168 164 indio_dev->info = &mpl115_info; 169 - indio_dev->name = id->name; 170 - indio_dev->dev.parent = &client->dev; 165 + indio_dev->name = name; 166 + indio_dev->dev.parent = dev; 171 167 indio_dev->modes = INDIO_DIRECT_MODE; 172 168 indio_dev->channels = mpl115_channels; 173 169 indio_dev->num_channels = ARRAY_SIZE(mpl115_channels); 174 170 175 - ret = i2c_smbus_read_word_swapped(data->client, MPL115_A0); 171 + ret = data->ops->init(data->dev); 172 + if (ret) 173 + return ret; 174 + 175 + ret = data->ops->read(data->dev, MPL115_A0); 176 176 if (ret < 0) 177 177 return ret; 178 178 data->a0 = ret; 179 - ret = i2c_smbus_read_word_swapped(data->client, MPL115_B1); 179 + ret = data->ops->read(data->dev, MPL115_B1); 180 180 if (ret < 0) 181 181 return ret; 182 182 data->b1 = ret; 183 - ret = i2c_smbus_read_word_swapped(data->client, MPL115_B2); 183 + ret = data->ops->read(data->dev, MPL115_B2); 184 184 if (ret < 0) 185 185 return ret; 186 186 data->b2 = ret; 187 - ret = i2c_smbus_read_word_swapped(data->client, MPL115_C12); 187 + ret = data->ops->read(data->dev, MPL115_C12); 188 188 if (ret < 0) 189 189 return ret; 190 190 data->c12 = ret; 191 191 192 - return devm_iio_device_register(&client->dev, indio_dev); 192 + return devm_iio_device_register(dev, indio_dev); 193 193 } 194 - 195 - static const struct i2c_device_id mpl115_id[] = { 196 - { "mpl115", 0 }, 197 - { } 198 - }; 199 - MODULE_DEVICE_TABLE(i2c, mpl115_id); 200 - 201 - static struct i2c_driver mpl115_driver = { 202 - .driver = { 203 - .name = "mpl115", 204 - }, 205 - .probe = mpl115_probe, 206 - .id_table = mpl115_id, 207 - }; 208 - module_i2c_driver(mpl115_driver); 194 + EXPORT_SYMBOL_GPL(mpl115_probe); 209 195 210 196 MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>"); 211 197 MODULE_DESCRIPTION("Freescale MPL115 pressure/temperature driver");
+24
drivers/iio/pressure/mpl115.h
··· 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 + 15 + struct mpl115_ops { 16 + int (*init)(struct device *); 17 + int (*read)(struct device *, u8); 18 + int (*write)(struct device *, u8, u8); 19 + }; 20 + 21 + int mpl115_probe(struct device *dev, const char *name, 22 + const struct mpl115_ops *ops); 23 + 24 + #endif
+67
drivers/iio/pressure/mpl115_i2c.c
··· 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 + 20 + static int mpl115_i2c_init(struct device *dev) 21 + { 22 + return 0; 23 + } 24 + 25 + static int mpl115_i2c_read(struct device *dev, u8 address) 26 + { 27 + return i2c_smbus_read_word_swapped(to_i2c_client(dev), address); 28 + } 29 + 30 + static 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 + 35 + static const struct mpl115_ops mpl115_i2c_ops = { 36 + .init = mpl115_i2c_init, 37 + .read = mpl115_i2c_read, 38 + .write = mpl115_i2c_write, 39 + }; 40 + 41 + static 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 + 50 + static const struct i2c_device_id mpl115_i2c_id[] = { 51 + { "mpl115", 0 }, 52 + { } 53 + }; 54 + MODULE_DEVICE_TABLE(i2c, mpl115_i2c_id); 55 + 56 + static struct i2c_driver mpl115_i2c_driver = { 57 + .driver = { 58 + .name = "mpl115", 59 + }, 60 + .probe = mpl115_i2c_probe, 61 + .id_table = mpl115_i2c_id, 62 + }; 63 + module_i2c_driver(mpl115_i2c_driver); 64 + 65 + MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>"); 66 + MODULE_DESCRIPTION("Freescale MPL115A2 pressure/temperature driver"); 67 + MODULE_LICENSE("GPL");
+106
drivers/iio/pressure/mpl115_spi.c
··· 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 + 21 + struct mpl115_spi_buf { 22 + u8 tx[4]; 23 + u8 rx[4]; 24 + }; 25 + 26 + static 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 + 40 + static 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 + 61 + static 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 + 76 + static const struct mpl115_ops mpl115_spi_ops = { 77 + .init = mpl115_spi_init, 78 + .read = mpl115_spi_read, 79 + .write = mpl115_spi_write, 80 + }; 81 + 82 + static 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 + 89 + static const struct spi_device_id mpl115_spi_ids[] = { 90 + { "mpl115", 0 }, 91 + {} 92 + }; 93 + MODULE_DEVICE_TABLE(spi, mpl115_spi_ids); 94 + 95 + static struct spi_driver mpl115_spi_driver = { 96 + .driver = { 97 + .name = "mpl115", 98 + }, 99 + .probe = mpl115_spi_probe, 100 + .id_table = mpl115_spi_ids, 101 + }; 102 + module_spi_driver(mpl115_spi_driver); 103 + 104 + MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>"); 105 + MODULE_DESCRIPTION("Freescale MPL115A1 pressure/temperature driver"); 106 + MODULE_LICENSE("GPL");
+8
drivers/iio/pressure/st_pressure_core.c
··· 62 62 #define ST_PRESS_LPS331AP_DRDY_IRQ_ADDR 0x22 63 63 #define ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK 0x04 64 64 #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 67 #define ST_PRESS_LPS331AP_MULTIREAD_BIT true 66 68 #define ST_PRESS_LPS331AP_TEMP_OFFSET 42500 67 69 ··· 102 100 #define ST_PRESS_LPS25H_DRDY_IRQ_ADDR 0x23 103 101 #define ST_PRESS_LPS25H_DRDY_IRQ_INT1_MASK 0x01 104 102 #define ST_PRESS_LPS25H_DRDY_IRQ_INT2_MASK 0x10 103 + #define ST_PRESS_LPS25H_IHL_IRQ_ADDR 0x22 104 + #define ST_PRESS_LPS25H_IHL_IRQ_MASK 0x80 105 105 #define ST_PRESS_LPS25H_MULTIREAD_BIT true 106 106 #define ST_PRESS_LPS25H_TEMP_OFFSET 42500 107 107 #define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28 ··· 224 220 .addr = ST_PRESS_LPS331AP_DRDY_IRQ_ADDR, 225 221 .mask_int1 = ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK, 226 222 .mask_int2 = ST_PRESS_LPS331AP_DRDY_IRQ_INT2_MASK, 223 + .addr_ihl = ST_PRESS_LPS331AP_IHL_IRQ_ADDR, 224 + .mask_ihl = ST_PRESS_LPS331AP_IHL_IRQ_MASK, 227 225 }, 228 226 .multi_read_bit = ST_PRESS_LPS331AP_MULTIREAD_BIT, 229 227 .bootime = 2, ··· 310 304 .addr = ST_PRESS_LPS25H_DRDY_IRQ_ADDR, 311 305 .mask_int1 = ST_PRESS_LPS25H_DRDY_IRQ_INT1_MASK, 312 306 .mask_int2 = ST_PRESS_LPS25H_DRDY_IRQ_INT2_MASK, 307 + .addr_ihl = ST_PRESS_LPS25H_IHL_IRQ_ADDR, 308 + .mask_ihl = ST_PRESS_LPS25H_IHL_IRQ_MASK, 313 309 }, 314 310 .multi_read_bit = ST_PRESS_LPS25H_MULTIREAD_BIT, 315 311 .bootime = 2,
-28
drivers/staging/iio/Documentation/sysfs-bus-iio-light
··· 1 - 2 - What: /sys/bus/iio/devices/device[n]/range 3 - KernelVersion: 2.6.37 4 - Contact: linux-iio@vger.kernel.org 5 - Description: 6 - Hardware dependent ADC Full Scale Range used for some ambient 7 - light sensors in calculating lux. 8 - 9 - What: /sys/bus/iio/devices/device[n]/range_available 10 - KernelVersion: 2.6.37 11 - Contact: linux-iio@vger.kernel.org 12 - Description: 13 - Hardware dependent supported vales for ADC Full Scale Range. 14 - 15 - What: /sys/bus/iio/devices/device[n]/adc_resolution 16 - KernelVersion: 2.6.37 17 - Contact: linux-iio@vger.kernel.org 18 - Description: 19 - Hardware dependent ADC resolution of the ambient light sensor 20 - used in calculating the lux. 21 - 22 - What: /sys/bus/iio/devices/device[n]/adc_resolution_available 23 - KernelVersion: 2.6.37 24 - Contact: linux-iio@vger.kernel.org 25 - Description: 26 - Hardware dependent list of possible values supported for the 27 - adc_resolution of the given sensor. 28 - 29 1 What: /sys/bus/iio/devices/device[n]/in_illuminance0[_input|_raw] 30 2 KernelVersion: 2.6.35 31 3 Contact: linux-iio@vger.kernel.org
+1 -1
drivers/staging/iio/adc/ad7192.c
··· 236 236 st->mclk = pdata->ext_clk_hz; 237 237 else 238 238 st->mclk = AD7192_INT_FREQ_MHZ; 239 - break; 239 + break; 240 240 default: 241 241 ret = -EINVAL; 242 242 goto out;
+18 -16
drivers/staging/iio/cdc/ad7150.c
··· 21 21 */ 22 22 23 23 #define AD7150_STATUS 0 24 - #define AD7150_STATUS_OUT1 (1 << 3) 25 - #define AD7150_STATUS_OUT2 (1 << 5) 24 + #define AD7150_STATUS_OUT1 BIT(3) 25 + #define AD7150_STATUS_OUT2 BIT(5) 26 26 #define AD7150_CH1_DATA_HIGH 1 27 27 #define AD7150_CH2_DATA_HIGH 3 28 28 #define AD7150_CH1_AVG_HIGH 5 ··· 36 36 #define AD7150_CH2_TIMEOUT 13 37 37 #define AD7150_CH2_SETUP 14 38 38 #define AD7150_CFG 15 39 - #define AD7150_CFG_FIX (1 << 7) 39 + #define AD7150_CFG_FIX BIT(7) 40 40 #define AD7150_PD_TIMER 16 41 41 #define AD7150_CH1_CAPDAC 17 42 42 #define AD7150_CH2_CAPDAC 18 ··· 160 160 161 161 /* lock should be held */ 162 162 static int ad7150_write_event_params(struct iio_dev *indio_dev, 163 - unsigned int chan, enum iio_event_type type, 164 - enum iio_event_direction dir) 163 + unsigned int chan, 164 + enum iio_event_type type, 165 + enum iio_event_direction dir) 165 166 { 166 167 int ret; 167 168 u16 value; ··· 210 209 } 211 210 212 211 static int ad7150_write_event_config(struct iio_dev *indio_dev, 213 - const struct iio_chan_spec *chan, enum iio_event_type type, 214 - enum iio_event_direction dir, int state) 212 + const struct iio_chan_spec *chan, 213 + enum iio_event_type type, 214 + enum iio_event_direction dir, int state) 215 215 { 216 216 u8 thresh_type, cfg, adaptive; 217 217 int ret; ··· 304 302 } 305 303 306 304 static int ad7150_write_event_value(struct iio_dev *indio_dev, 307 - const struct iio_chan_spec *chan, 308 - enum iio_event_type type, 309 - enum iio_event_direction dir, 310 - enum iio_event_info info, 311 - int val, int val2) 305 + const struct iio_chan_spec *chan, 306 + enum iio_event_type type, 307 + enum iio_event_direction dir, 308 + enum iio_event_info info, 309 + int val, int val2) 312 310 { 313 311 int ret; 314 312 struct ad7150_chip_info *chip = iio_priv(indio_dev); ··· 367 365 } 368 366 369 367 static ssize_t ad7150_store_timeout(struct device *dev, 370 - struct device_attribute *attr, 371 - const char *buf, 372 - size_t len) 368 + struct device_attribute *attr, 369 + const char *buf, 370 + size_t len) 373 371 { 374 372 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 375 373 struct ad7150_chip_info *chip = iio_priv(indio_dev); ··· 582 580 */ 583 581 584 582 static int ad7150_probe(struct i2c_client *client, 585 - const struct i2c_device_id *id) 583 + const struct i2c_device_id *id) 586 584 { 587 585 int ret; 588 586 struct ad7150_chip_info *chip;
+4
include/linux/iio/common/st_sensors.h
··· 119 119 * @addr: address of the register. 120 120 * @mask_int1: mask to enable/disable IRQ on INT1 pin. 121 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 124 * struct ig1 - represents the Interrupt Generator 1 of sensors. 123 125 * @en_addr: address of the enable ig1 register. 124 126 * @en_mask: mask to write the on/off value for enable. ··· 129 127 u8 addr; 130 128 u8 mask_int1; 131 129 u8 mask_int2; 130 + u8 addr_ihl; 131 + u8 mask_ihl; 132 132 struct { 133 133 u8 en_addr; 134 134 u8 en_mask;
+44
include/linux/platform_data/ad5761.h
··· 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 + 24 + enum 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 + 40 + struct ad5761_platform_data { 41 + enum ad5761_voltage_range voltage_range; 42 + }; 43 + 44 + #endif
+1
include/uapi/linux/iio/types.h
··· 37 37 IIO_VELOCITY, 38 38 IIO_CONCENTRATION, 39 39 IIO_RESISTANCE, 40 + IIO_PH, 40 41 }; 41 42 42 43 enum iio_modifier {