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.
Unified · Split
| @@ -3054,6 +3054,7 @@ D: PLX USB338x driver · 3053 unmodified lines | ||
| 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 |
| @@ -497,7 +497,9 @@ Description: · 496 unmodified lines | ||
| 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 |
| @@ -1491,3 +1493,10 @@ Description: · 987 unmodified lines | ||
| 1491 | 1493 | This ABI is especially applicable for humidity sensors |
| 1492 | 1494 | to heatup the device and get rid of any condensation |
| 1493 | 1495 | in some humidity environment |
| 1496 | + | |
| 1497 | +What: /sys/bus/iio/devices/iio:deviceX/in_ph_raw | |
| 1498 | +KernelVersion: 4.5 | |
| 1499 | +Contact: linux-iio@vger.kernel.org | |
| 1500 | +Description: | |
| 1501 | + Raw (unscaled no offset etc.) pH reading of a substance as a negative | |
| 1502 | + base-10 logarithm of hydrodium ions in a litre of water. | |
| @@ -1,8 +1,10 @@ | ||
| 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" |
| @@ -0,0 +1,28 @@ | ||
| 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 | +} | |
| @@ -6,6 +6,7 @@ Required properties: · 5 unmodified lines | ||
| 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" |
| @@ -0,0 +1,22 @@ | ||
| 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 | +}; | |
| @@ -11,11 +11,19 @@ Required properties: · 10 unmodified lines | ||
| 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 | }; |
| @@ -0,0 +1,26 @@ | ||
| 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 | +}; | |
| @@ -28,6 +28,7 @@ arm ARM Ltd. · 27 unmodified lines | ||
| 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 |
| @@ -1945,6 +1945,12 @@ M: Nicolas Ferre <nicolas.ferre@atmel.com> · 1944 unmodified lines | ||
| 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) |
| @@ -143,7 +143,7 @@ config MMA8452 · 142 unmodified lines | ||
| 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. |
| @@ -1,6 +1,7 @@ | ||
| 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) |
| @@ -15,7 +16,7 @@ · 8 unmodified lines | ||
| 15 | 16 | * |
| 16 | 17 | * 7-bit I2C slave address 0x1c/0x1d (pin selectable) |
| 17 | 18 | * |
| 18 | − * TODO: orientation / freefall events, autosleep | |
| 19 | + * TODO: orientation events, autosleep | |
| 19 | 20 | */ |
| 20 | 21 | |
| 21 | 22 | #include <linux/module.h> |
| @@ -85,8 +86,9 @@ · 63 unmodified lines | ||
| 85 | 86 | #define MMA8452_INT_FF_MT BIT(2) |
| 86 | 87 | #define MMA8452_INT_TRANS BIT(5) |
| 87 | 88 | |
| 88 | −#define MMA8452_DEVICE_ID 0x2a | |
| 89 | −#define MMA8453_DEVICE_ID 0x3a | |
| 89 | +#define MMA8451_DEVICE_ID 0x1a | |
| 90 | +#define MMA8452_DEVICE_ID 0x2a | |
| 91 | +#define MMA8453_DEVICE_ID 0x3a | |
| 90 | 92 | #define MMA8652_DEVICE_ID 0x4a |
| 91 | 93 | #define MMA8653_DEVICE_ID 0x5a |
| 92 | 94 | |
| @@ -416,6 +418,51 @@ fail: · 323 unmodified lines | ||
| 416 | 418 | return ret; |
| 417 | 419 | } |
| 418 | 420 | |
| 421 | +/* returns >0 if in freefall mode, 0 if not or <0 if an error occured */ | |
| 422 | +static int mma8452_freefall_mode_enabled(struct mma8452_data *data) | |
| 423 | +{ | |
| 424 | + int val; | |
| 425 | + const struct mma_chip_info *chip = data->chip_info; | |
| 426 | + | |
| 427 | + val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg); | |
| 428 | + if (val < 0) | |
| 429 | + return val; | |
| 430 | + | |
| 431 | + return !(val & MMA8452_FF_MT_CFG_OAE); | |
| 432 | +} | |
| 433 | + | |
| 434 | +static int mma8452_set_freefall_mode(struct mma8452_data *data, bool state) | |
| 435 | +{ | |
| 436 | + int val; | |
| 437 | + const struct mma_chip_info *chip = data->chip_info; | |
| 438 | + | |
| 439 | + if ((state && mma8452_freefall_mode_enabled(data)) || | |
| 440 | + (!state && !(mma8452_freefall_mode_enabled(data)))) | |
| 441 | + return 0; | |
| 442 | + | |
| 443 | + val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg); | |
| 444 | + if (val < 0) | |
| 445 | + return val; | |
| 446 | + | |
| 447 | + if (state) { | |
| 448 | + val |= BIT(idx_x + chip->ev_cfg_chan_shift); | |
| 449 | + val |= BIT(idx_y + chip->ev_cfg_chan_shift); | |
| 450 | + val |= BIT(idx_z + chip->ev_cfg_chan_shift); | |
| 451 | + val &= ~MMA8452_FF_MT_CFG_OAE; | |
| 452 | + } else { | |
| 453 | + val &= ~BIT(idx_x + chip->ev_cfg_chan_shift); | |
| 454 | + val &= ~BIT(idx_y + chip->ev_cfg_chan_shift); | |
| 455 | + val &= ~BIT(idx_z + chip->ev_cfg_chan_shift); | |
| 456 | + val |= MMA8452_FF_MT_CFG_OAE; | |
| 457 | + } | |
| 458 | + | |
| 459 | + val = mma8452_change_config(data, chip->ev_cfg, val); | |
| 460 | + if (val) | |
| 461 | + return val; | |
| 462 | + | |
| 463 | + return 0; | |
| 464 | +} | |
| 465 | + | |
| 419 | 466 | static int mma8452_set_hp_filter_frequency(struct mma8452_data *data, |
| 420 | 467 | int val, int val2) |
| 421 | 468 | { |
| @@ -609,12 +656,22 @@ static int mma8452_read_event_config(struct iio_dev *indio_dev, · 187 unmodified lines | ||
| 609 | 656 | const struct mma_chip_info *chip = data->chip_info; |
| 610 | 657 | int ret; |
| 611 | 658 | |
| 612 | − ret = i2c_smbus_read_byte_data(data->client, | |
| 613 | − data->chip_info->ev_cfg); | |
| 614 | − if (ret < 0) | |
| 615 | − return ret; | |
| 659 | + switch (dir) { | |
| 660 | + case IIO_EV_DIR_FALLING: | |
| 661 | + return mma8452_freefall_mode_enabled(data); | |
| 662 | + case IIO_EV_DIR_RISING: | |
| 663 | + if (mma8452_freefall_mode_enabled(data)) | |
| 664 | + return 0; | |
| 665 | + | |
| 666 | + ret = i2c_smbus_read_byte_data(data->client, | |
| 667 | + data->chip_info->ev_cfg); | |
| 668 | + if (ret < 0) | |
| 669 | + return ret; | |
| 616 | 670 | |
| 617 | − return !!(ret & BIT(chan->scan_index + chip->ev_cfg_chan_shift)); | |
| 671 | + return !!(ret & BIT(chan->scan_index + chip->ev_cfg_chan_shift)); | |
| 672 | + default: | |
| 673 | + return -EINVAL; | |
| 674 | + } | |
| 618 | 675 | } |
| 619 | 676 | |
| 620 | 677 | static int mma8452_write_event_config(struct iio_dev *indio_dev, |
| @@ -627,19 +684,35 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev, · 6 unmodified lines | ||
| 627 | 684 | const struct mma_chip_info *chip = data->chip_info; |
| 628 | 685 | int val; |
| 629 | 686 | |
| 630 | − val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg); | |
| 631 | − if (val < 0) | |
| 632 | − return val; | |
| 687 | + switch (dir) { | |
| 688 | + case IIO_EV_DIR_FALLING: | |
| 689 | + return mma8452_set_freefall_mode(data, state); | |
| 690 | + case IIO_EV_DIR_RISING: | |
| 691 | + val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg); | |
| 692 | + if (val < 0) | |
| 693 | + return val; | |
| 694 | + | |
| 695 | + if (state) { | |
| 696 | + if (mma8452_freefall_mode_enabled(data)) { | |
| 697 | + val &= ~BIT(idx_x + chip->ev_cfg_chan_shift); | |
| 698 | + val &= ~BIT(idx_y + chip->ev_cfg_chan_shift); | |
| 699 | + val &= ~BIT(idx_z + chip->ev_cfg_chan_shift); | |
| 700 | + val |= MMA8452_FF_MT_CFG_OAE; | |
| 701 | + } | |
| 702 | + val |= BIT(chan->scan_index + chip->ev_cfg_chan_shift); | |
| 703 | + } else { | |
| 704 | + if (mma8452_freefall_mode_enabled(data)) | |
| 705 | + return 0; | |
| 633 | 706 | |
| 634 | − if (state) | |
| 635 | − val |= BIT(chan->scan_index + chip->ev_cfg_chan_shift); | |
| 636 | − else | |
| 637 | − val &= ~BIT(chan->scan_index + chip->ev_cfg_chan_shift); | |
| 707 | + val &= ~BIT(chan->scan_index + chip->ev_cfg_chan_shift); | |
| 708 | + } | |
| 638 | 709 | |
| 639 | − val |= chip->ev_cfg_ele; | |
| 640 | − val |= MMA8452_FF_MT_CFG_OAE; | |
| 710 | + val |= chip->ev_cfg_ele; | |
| 641 | 711 | |
| 642 | − return mma8452_change_config(data, chip->ev_cfg, val); | |
| 712 | + return mma8452_change_config(data, chip->ev_cfg, val); | |
| 713 | + default: | |
| 714 | + return -EINVAL; | |
| 715 | + } | |
| 643 | 716 | } |
| 644 | 717 | |
| 645 | 718 | static void mma8452_transient_interrupt(struct iio_dev *indio_dev) |
| @@ -652,6 +725,16 @@ static void mma8452_transient_interrupt(struct iio_dev *indio_dev) · 6 unmodified lines | ||
| 652 | 725 | if (src < 0) |
| 653 | 726 | return; |
| 654 | 727 | |
| 728 | + if (mma8452_freefall_mode_enabled(data)) { | |
| 729 | + iio_push_event(indio_dev, | |
| 730 | + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, | |
| 731 | + IIO_MOD_X_AND_Y_AND_Z, | |
| 732 | + IIO_EV_TYPE_MAG, | |
| 733 | + IIO_EV_DIR_FALLING), | |
| 734 | + ts); | |
| 735 | + return; | |
| 736 | + } | |
| 737 | + | |
| 655 | 738 | if (src & data->chip_info->ev_src_xe) |
| 656 | 739 | iio_push_event(indio_dev, |
| 657 | 740 | IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X, |
| @@ -745,6 +828,27 @@ static int mma8452_reg_access_dbg(struct iio_dev *indio_dev, · 87 unmodified lines | ||
| 745 | 828 | return 0; |
| 746 | 829 | } |
| 747 | 830 | |
| 831 | +static const struct iio_event_spec mma8452_freefall_event[] = { | |
| 832 | + { | |
| 833 | + .type = IIO_EV_TYPE_MAG, | |
| 834 | + .dir = IIO_EV_DIR_FALLING, | |
| 835 | + .mask_separate = BIT(IIO_EV_INFO_ENABLE), | |
| 836 | + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | | |
| 837 | + BIT(IIO_EV_INFO_PERIOD) | | |
| 838 | + BIT(IIO_EV_INFO_HIGH_PASS_FILTER_3DB) | |
| 839 | + }, | |
| 840 | +}; | |
| 841 | + | |
| 842 | +static const struct iio_event_spec mma8652_freefall_event[] = { | |
| 843 | + { | |
| 844 | + .type = IIO_EV_TYPE_MAG, | |
| 845 | + .dir = IIO_EV_DIR_FALLING, | |
| 846 | + .mask_separate = BIT(IIO_EV_INFO_ENABLE), | |
| 847 | + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | | |
| 848 | + BIT(IIO_EV_INFO_PERIOD) | |
| 849 | + }, | |
| 850 | +}; | |
| 851 | + | |
| 748 | 852 | static const struct iio_event_spec mma8452_transient_event[] = { |
| 749 | 853 | { |
| 750 | 854 | .type = IIO_EV_TYPE_MAG, |
| @@ -781,6 +885,24 @@ static struct attribute_group mma8452_event_attribute_group = { · 30 unmodified lines | ||
| 781 | 885 | .attrs = mma8452_event_attributes, |
| 782 | 886 | }; |
| 783 | 887 | |
| 888 | +#define MMA8452_FREEFALL_CHANNEL(modifier) { \ | |
| 889 | + .type = IIO_ACCEL, \ | |
| 890 | + .modified = 1, \ | |
| 891 | + .channel2 = modifier, \ | |
| 892 | + .scan_index = -1, \ | |
| 893 | + .event_spec = mma8452_freefall_event, \ | |
| 894 | + .num_event_specs = ARRAY_SIZE(mma8452_freefall_event), \ | |
| 895 | +} | |
| 896 | + | |
| 897 | +#define MMA8652_FREEFALL_CHANNEL(modifier) { \ | |
| 898 | + .type = IIO_ACCEL, \ | |
| 899 | + .modified = 1, \ | |
| 900 | + .channel2 = modifier, \ | |
| 901 | + .scan_index = -1, \ | |
| 902 | + .event_spec = mma8652_freefall_event, \ | |
| 903 | + .num_event_specs = ARRAY_SIZE(mma8652_freefall_event), \ | |
| 904 | +} | |
| 905 | + | |
| 784 | 906 | #define MMA8452_CHANNEL(axis, idx, bits) { \ |
| 785 | 907 | .type = IIO_ACCEL, \ |
| 786 | 908 | .modified = 1, \ |
| @@ -822,11 +944,20 @@ static struct attribute_group mma8452_event_attribute_group = { · 35 unmodified lines | ||
| 822 | 944 | .num_event_specs = ARRAY_SIZE(mma8452_motion_event), \ |
| 823 | 945 | } |
| 824 | 946 | |
| 947 | +static const struct iio_chan_spec mma8451_channels[] = { | |
| 948 | + MMA8452_CHANNEL(X, idx_x, 14), | |
| 949 | + MMA8452_CHANNEL(Y, idx_y, 14), | |
| 950 | + MMA8452_CHANNEL(Z, idx_z, 14), | |
| 951 | + IIO_CHAN_SOFT_TIMESTAMP(idx_ts), | |
| 952 | + MMA8452_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z), | |
| 953 | +}; | |
| 954 | + | |
| 825 | 955 | static const struct iio_chan_spec mma8452_channels[] = { |
| 826 | 956 | MMA8452_CHANNEL(X, idx_x, 12), |
| 827 | 957 | MMA8452_CHANNEL(Y, idx_y, 12), |
| 828 | 958 | MMA8452_CHANNEL(Z, idx_z, 12), |
| 829 | 959 | IIO_CHAN_SOFT_TIMESTAMP(idx_ts), |
| 960 | + MMA8452_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z), | |
| 830 | 961 | }; |
| 831 | 962 | |
| 832 | 963 | static const struct iio_chan_spec mma8453_channels[] = { |
| @@ -834,6 +965,7 @@ static const struct iio_chan_spec mma8453_channels[] = { · 1 unmodified line | ||
| 834 | 965 | MMA8452_CHANNEL(Y, idx_y, 10), |
| 835 | 966 | MMA8452_CHANNEL(Z, idx_z, 10), |
| 836 | 967 | IIO_CHAN_SOFT_TIMESTAMP(idx_ts), |
| 968 | + MMA8452_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z), | |
| 837 | 969 | }; |
| 838 | 970 | |
| 839 | 971 | static const struct iio_chan_spec mma8652_channels[] = { |
| @@ -841,6 +973,7 @@ static const struct iio_chan_spec mma8652_channels[] = { · 1 unmodified line | ||
| 841 | 973 | MMA8652_CHANNEL(Y, idx_y, 12), |
| 842 | 974 | MMA8652_CHANNEL(Z, idx_z, 12), |
| 843 | 975 | IIO_CHAN_SOFT_TIMESTAMP(idx_ts), |
| 976 | + MMA8652_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z), | |
| 844 | 977 | }; |
| 845 | 978 | |
| 846 | 979 | static const struct iio_chan_spec mma8653_channels[] = { |
| @@ -848,9 +981,11 @@ static const struct iio_chan_spec mma8653_channels[] = { · 1 unmodified line | ||
| 848 | 981 | MMA8652_CHANNEL(Y, idx_y, 10), |
| 849 | 982 | MMA8652_CHANNEL(Z, idx_z, 10), |
| 850 | 983 | IIO_CHAN_SOFT_TIMESTAMP(idx_ts), |
| 984 | + MMA8652_FREEFALL_CHANNEL(IIO_MOD_X_AND_Y_AND_Z), | |
| 851 | 985 | }; |
| 852 | 986 | |
| 853 | 987 | enum { |
| 988 | + mma8451, | |
| 854 | 989 | mma8452, |
| 855 | 990 | mma8453, |
| 856 | 991 | mma8652, |
| @@ -858,17 +993,34 @@ enum { · 1 unmodified line | ||
| 858 | 993 | }; |
| 859 | 994 | |
| 860 | 995 | static const struct mma_chip_info mma_chip_info_table[] = { |
| 861 | − [mma8452] = { | |
| 862 | − .chip_id = MMA8452_DEVICE_ID, | |
| 863 | − .channels = mma8452_channels, | |
| 864 | − .num_channels = ARRAY_SIZE(mma8452_channels), | |
| 996 | + [mma8451] = { | |
| 997 | + .chip_id = MMA8451_DEVICE_ID, | |
| 998 | + .channels = mma8451_channels, | |
| 999 | + .num_channels = ARRAY_SIZE(mma8451_channels), | |
| 865 | 1000 | /* |
| 866 | 1001 | * Hardware has fullscale of -2G, -4G, -8G corresponding to |
| 867 | − * raw value -2048 for 12 bit or -512 for 10 bit. | |
| 1002 | + * raw value -8192 for 14 bit, -2048 for 12 bit or -512 for 10 | |
| 1003 | + * bit. | |
| 868 | 1004 | * The userspace interface uses m/s^2 and we declare micro units |
| 869 | 1005 | * So scale factor for 12 bit here is given by: |
| 870 | − * g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.80665 | |
| 1006 | + * g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.80665 | |
| 871 | 1007 | */ |
| 1008 | + .mma_scales = { {0, 2394}, {0, 4788}, {0, 9577} }, | |
| 1009 | + .ev_cfg = MMA8452_TRANSIENT_CFG, | |
| 1010 | + .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE, | |
| 1011 | + .ev_cfg_chan_shift = 1, | |
| 1012 | + .ev_src = MMA8452_TRANSIENT_SRC, | |
| 1013 | + .ev_src_xe = MMA8452_TRANSIENT_SRC_XTRANSE, | |
| 1014 | + .ev_src_ye = MMA8452_TRANSIENT_SRC_YTRANSE, | |
| 1015 | + .ev_src_ze = MMA8452_TRANSIENT_SRC_ZTRANSE, | |
| 1016 | + .ev_ths = MMA8452_TRANSIENT_THS, | |
| 1017 | + .ev_ths_mask = MMA8452_TRANSIENT_THS_MASK, | |
| 1018 | + .ev_count = MMA8452_TRANSIENT_COUNT, | |
| 1019 | + }, | |
| 1020 | + [mma8452] = { | |
| 1021 | + .chip_id = MMA8452_DEVICE_ID, | |
| 1022 | + .channels = mma8452_channels, | |
| 1023 | + .num_channels = ARRAY_SIZE(mma8452_channels), | |
| 872 | 1024 | .mma_scales = { {0, 9577}, {0, 19154}, {0, 38307} }, |
| 873 | 1025 | .ev_cfg = MMA8452_TRANSIENT_CFG, |
| 874 | 1026 | .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE, |
| @@ -1049,6 +1201,7 @@ static int mma8452_reset(struct i2c_client *client) · 174 unmodified lines | ||
| 1049 | 1201 | } |
| 1050 | 1202 | |
| 1051 | 1203 | static const struct of_device_id mma8452_dt_ids[] = { |
| 1204 | + { .compatible = "fsl,mma8451", .data = &mma_chip_info_table[mma8451] }, | |
| 1052 | 1205 | { .compatible = "fsl,mma8452", .data = &mma_chip_info_table[mma8452] }, |
| 1053 | 1206 | { .compatible = "fsl,mma8453", .data = &mma_chip_info_table[mma8453] }, |
| 1054 | 1207 | { .compatible = "fsl,mma8652", .data = &mma_chip_info_table[mma8652] }, |
| @@ -1085,6 +1238,7 @@ static int mma8452_probe(struct i2c_client *client, · 30 unmodified lines | ||
| 1085 | 1238 | return ret; |
| 1086 | 1239 | |
| 1087 | 1240 | switch (ret) { |
| 1241 | + case MMA8451_DEVICE_ID: | |
| 1088 | 1242 | case MMA8452_DEVICE_ID: |
| 1089 | 1243 | case MMA8453_DEVICE_ID: |
| 1090 | 1244 | case MMA8652_DEVICE_ID: |
| @@ -1190,6 +1344,10 @@ static int mma8452_probe(struct i2c_client *client, · 99 unmodified lines | ||
| 1190 | 1344 | if (ret < 0) |
| 1191 | 1345 | goto buffer_cleanup; |
| 1192 | 1346 | |
| 1347 | + ret = mma8452_set_freefall_mode(data, false); | |
| 1348 | + if (ret) | |
| 1349 | + return ret; | |
| 1350 | + | |
| 1193 | 1351 | return 0; |
| 1194 | 1352 | |
| 1195 | 1353 | buffer_cleanup: |
| @@ -67,6 +67,8 @@ · 66 unmodified lines | ||
| 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 */ |
| @@ -92,6 +94,8 @@ · 19 unmodified lines | ||
| 92 | 94 | #define ST_ACCEL_2_DRDY_IRQ_ADDR 0x22 |
| 93 | 95 | #define ST_ACCEL_2_DRDY_IRQ_INT1_MASK 0x02 |
| 94 | 96 | #define ST_ACCEL_2_DRDY_IRQ_INT2_MASK 0x10 |
| 97 | +#define ST_ACCEL_2_IHL_IRQ_ADDR 0x22 | |
| 98 | +#define ST_ACCEL_2_IHL_IRQ_MASK 0x80 | |
| 95 | 99 | #define ST_ACCEL_2_MULTIREAD_BIT true |
| 96 | 100 | |
| 97 | 101 | /* CUSTOM VALUES FOR SENSOR 3 */ |
| @@ -125,6 +129,8 @@ · 27 unmodified lines | ||
| 125 | 129 | #define ST_ACCEL_3_DRDY_IRQ_ADDR 0x23 |
| 126 | 130 | #define ST_ACCEL_3_DRDY_IRQ_INT1_MASK 0x80 |
| 127 | 131 | #define ST_ACCEL_3_DRDY_IRQ_INT2_MASK 0x00 |
| 132 | +#define ST_ACCEL_3_IHL_IRQ_ADDR 0x23 | |
| 133 | +#define ST_ACCEL_3_IHL_IRQ_MASK 0x40 | |
| 128 | 134 | #define ST_ACCEL_3_IG1_EN_ADDR 0x23 |
| 129 | 135 | #define ST_ACCEL_3_IG1_EN_MASK 0x08 |
| 130 | 136 | #define ST_ACCEL_3_MULTIREAD_BIT false |
| @@ -169,6 +175,8 @@ · 38 unmodified lines | ||
| 169 | 175 | #define ST_ACCEL_5_DRDY_IRQ_ADDR 0x22 |
| 170 | 176 | #define ST_ACCEL_5_DRDY_IRQ_INT1_MASK 0x04 |
| 171 | 177 | #define ST_ACCEL_5_DRDY_IRQ_INT2_MASK 0x20 |
| 178 | +#define ST_ACCEL_5_IHL_IRQ_ADDR 0x22 | |
| 179 | +#define ST_ACCEL_5_IHL_IRQ_MASK 0x80 | |
| 172 | 180 | #define ST_ACCEL_5_IG1_EN_ADDR 0x21 |
| 173 | 181 | #define ST_ACCEL_5_IG1_EN_MASK 0x08 |
| 174 | 182 | #define ST_ACCEL_5_MULTIREAD_BIT false |
| @@ -292,6 +300,8 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { · 117 unmodified lines | ||
| 292 | 300 | .addr = ST_ACCEL_1_DRDY_IRQ_ADDR, |
| 293 | 301 | .mask_int1 = ST_ACCEL_1_DRDY_IRQ_INT1_MASK, |
| 294 | 302 | .mask_int2 = ST_ACCEL_1_DRDY_IRQ_INT2_MASK, |
| 303 | + .addr_ihl = ST_ACCEL_1_IHL_IRQ_ADDR, | |
| 304 | + .mask_ihl = ST_ACCEL_1_IHL_IRQ_MASK, | |
| 295 | 305 | }, |
| 296 | 306 | .multi_read_bit = ST_ACCEL_1_MULTIREAD_BIT, |
| 297 | 307 | .bootime = 2, |
| @@ -355,6 +365,8 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { · 57 unmodified lines | ||
| 355 | 365 | .addr = ST_ACCEL_2_DRDY_IRQ_ADDR, |
| 356 | 366 | .mask_int1 = ST_ACCEL_2_DRDY_IRQ_INT1_MASK, |
| 357 | 367 | .mask_int2 = ST_ACCEL_2_DRDY_IRQ_INT2_MASK, |
| 368 | + .addr_ihl = ST_ACCEL_2_IHL_IRQ_ADDR, | |
| 369 | + .mask_ihl = ST_ACCEL_2_IHL_IRQ_MASK, | |
| 358 | 370 | }, |
| 359 | 371 | .multi_read_bit = ST_ACCEL_2_MULTIREAD_BIT, |
| 360 | 372 | .bootime = 2, |
| @@ -430,6 +442,8 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { · 69 unmodified lines | ||
| 430 | 442 | .addr = ST_ACCEL_3_DRDY_IRQ_ADDR, |
| 431 | 443 | .mask_int1 = ST_ACCEL_3_DRDY_IRQ_INT1_MASK, |
| 432 | 444 | .mask_int2 = ST_ACCEL_3_DRDY_IRQ_INT2_MASK, |
| 445 | + .addr_ihl = ST_ACCEL_3_IHL_IRQ_ADDR, | |
| 446 | + .mask_ihl = ST_ACCEL_3_IHL_IRQ_MASK, | |
| 433 | 447 | .ig1 = { |
| 434 | 448 | .en_addr = ST_ACCEL_3_IG1_EN_ADDR, |
| 435 | 449 | .en_mask = ST_ACCEL_3_IG1_EN_MASK, |
| @@ -537,6 +551,8 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { · 101 unmodified lines | ||
| 537 | 551 | .addr = ST_ACCEL_5_DRDY_IRQ_ADDR, |
| 538 | 552 | .mask_int1 = ST_ACCEL_5_DRDY_IRQ_INT1_MASK, |
| 539 | 553 | .mask_int2 = ST_ACCEL_5_DRDY_IRQ_INT2_MASK, |
| 554 | + .addr_ihl = ST_ACCEL_5_IHL_IRQ_ADDR, | |
| 555 | + .mask_ihl = ST_ACCEL_5_IHL_IRQ_MASK, | |
| 540 | 556 | }, |
| 541 | 557 | .multi_read_bit = ST_ACCEL_5_MULTIREAD_BIT, |
| 542 | 558 | .bootime = 2, /* guess */ |
| @@ -131,6 +131,16 @@ config AT91_ADC · 130 unmodified lines | ||
| 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 |
| @@ -265,11 +275,11 @@ config MCP320X · 128 unmodified lines | ||
| 265 | 275 | called mcp320x. |
| 266 | 276 | |
| 267 | 277 | config MCP3422 |
| 268 | − tristate "Microchip Technology MCP3422/3/4/6/7/8 driver" | |
| 278 | + tristate "Microchip Technology MCP3421/2/3/4/5/6/7/8 driver" | |
| 269 | 279 | depends on I2C |
| 270 | 280 | help |
| 271 | − Say yes here to build support for Microchip Technology's | |
| 272 | − MCP3422, MCP3423, MCP3424, MCP3426, MCP3427 or MCP3428 | |
| 281 | + Say yes here to build support for Microchip Technology's MCP3421 | |
| 282 | + MCP3422, MCP3423, MCP3424, MCP3425, MCP3426, MCP3427 or MCP3428 | |
| 273 | 283 | analog to digital converters. |
| 274 | 284 | |
| 275 | 285 | This driver can also be built as a module. If so, the module will be |
| @@ -14,6 +14,7 @@ obj-$(CONFIG_AD7793) += ad7793.o · 13 unmodified lines | ||
| 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 |
| @@ -0,0 +1,508 @@ | ||
| 1 | +/* | |
| 2 | + * Atmel ADC driver for SAMA5D2 devices and compatible. | |
| 3 | + * | |
| 4 | + * Copyright (C) 2015 Atmel, | |
| 5 | + * 2015 Ludovic Desroches <ludovic.desroches@atmel.com> | |
| 6 | + * | |
| 7 | + * This software is licensed under the terms of the GNU General Public | |
| 8 | + * License version 2, as published by the Free Software Foundation, and | |
| 9 | + * may be copied, distributed, and modified under those terms. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + */ | |
| 16 | + | |
| 17 | +#include <linux/bitops.h> | |
| 18 | +#include <linux/clk.h> | |
| 19 | +#include <linux/interrupt.h> | |
| 20 | +#include <linux/io.h> | |
| 21 | +#include <linux/module.h> | |
| 22 | +#include <linux/of_device.h> | |
| 23 | +#include <linux/platform_device.h> | |
| 24 | +#include <linux/sched.h> | |
| 25 | +#include <linux/wait.h> | |
| 26 | +#include <linux/iio/iio.h> | |
| 27 | +#include <linux/iio/sysfs.h> | |
| 28 | +#include <linux/regulator/consumer.h> | |
| 29 | + | |
| 30 | +/* Control Register */ | |
| 31 | +#define AT91_SAMA5D2_CR 0x00 | |
| 32 | +/* Software Reset */ | |
| 33 | +#define AT91_SAMA5D2_CR_SWRST BIT(0) | |
| 34 | +/* Start Conversion */ | |
| 35 | +#define AT91_SAMA5D2_CR_START BIT(1) | |
| 36 | +/* Touchscreen Calibration */ | |
| 37 | +#define AT91_SAMA5D2_CR_TSCALIB BIT(2) | |
| 38 | +/* Comparison Restart */ | |
| 39 | +#define AT91_SAMA5D2_CR_CMPRST BIT(4) | |
| 40 | + | |
| 41 | +/* Mode Register */ | |
| 42 | +#define AT91_SAMA5D2_MR 0x04 | |
| 43 | +/* Trigger Selection */ | |
| 44 | +#define AT91_SAMA5D2_MR_TRGSEL(v) ((v) << 1) | |
| 45 | +/* ADTRG */ | |
| 46 | +#define AT91_SAMA5D2_MR_TRGSEL_TRIG0 0 | |
| 47 | +/* TIOA0 */ | |
| 48 | +#define AT91_SAMA5D2_MR_TRGSEL_TRIG1 1 | |
| 49 | +/* TIOA1 */ | |
| 50 | +#define AT91_SAMA5D2_MR_TRGSEL_TRIG2 2 | |
| 51 | +/* TIOA2 */ | |
| 52 | +#define AT91_SAMA5D2_MR_TRGSEL_TRIG3 3 | |
| 53 | +/* PWM event line 0 */ | |
| 54 | +#define AT91_SAMA5D2_MR_TRGSEL_TRIG4 4 | |
| 55 | +/* PWM event line 1 */ | |
| 56 | +#define AT91_SAMA5D2_MR_TRGSEL_TRIG5 5 | |
| 57 | +/* TIOA3 */ | |
| 58 | +#define AT91_SAMA5D2_MR_TRGSEL_TRIG6 6 | |
| 59 | +/* RTCOUT0 */ | |
| 60 | +#define AT91_SAMA5D2_MR_TRGSEL_TRIG7 7 | |
| 61 | +/* Sleep Mode */ | |
| 62 | +#define AT91_SAMA5D2_MR_SLEEP BIT(5) | |
| 63 | +/* Fast Wake Up */ | |
| 64 | +#define AT91_SAMA5D2_MR_FWUP BIT(6) | |
| 65 | +/* Prescaler Rate Selection */ | |
| 66 | +#define AT91_SAMA5D2_MR_PRESCAL(v) ((v) << AT91_SAMA5D2_MR_PRESCAL_OFFSET) | |
| 67 | +#define AT91_SAMA5D2_MR_PRESCAL_OFFSET 8 | |
| 68 | +#define AT91_SAMA5D2_MR_PRESCAL_MAX 0xff | |
| 69 | +/* Startup Time */ | |
| 70 | +#define AT91_SAMA5D2_MR_STARTUP(v) ((v) << 16) | |
| 71 | +/* Analog Change */ | |
| 72 | +#define AT91_SAMA5D2_MR_ANACH BIT(23) | |
| 73 | +/* Tracking Time */ | |
| 74 | +#define AT91_SAMA5D2_MR_TRACKTIM(v) ((v) << 24) | |
| 75 | +#define AT91_SAMA5D2_MR_TRACKTIM_MAX 0xff | |
| 76 | +/* Transfer Time */ | |
| 77 | +#define AT91_SAMA5D2_MR_TRANSFER(v) ((v) << 28) | |
| 78 | +#define AT91_SAMA5D2_MR_TRANSFER_MAX 0x3 | |
| 79 | +/* Use Sequence Enable */ | |
| 80 | +#define AT91_SAMA5D2_MR_USEQ BIT(31) | |
| 81 | + | |
| 82 | +/* Channel Sequence Register 1 */ | |
| 83 | +#define AT91_SAMA5D2_SEQR1 0x08 | |
| 84 | +/* Channel Sequence Register 2 */ | |
| 85 | +#define AT91_SAMA5D2_SEQR2 0x0c | |
| 86 | +/* Channel Enable Register */ | |
| 87 | +#define AT91_SAMA5D2_CHER 0x10 | |
| 88 | +/* Channel Disable Register */ | |
| 89 | +#define AT91_SAMA5D2_CHDR 0x14 | |
| 90 | +/* Channel Status Register */ | |
| 91 | +#define AT91_SAMA5D2_CHSR 0x18 | |
| 92 | +/* Last Converted Data Register */ | |
| 93 | +#define AT91_SAMA5D2_LCDR 0x20 | |
| 94 | +/* Interrupt Enable Register */ | |
| 95 | +#define AT91_SAMA5D2_IER 0x24 | |
| 96 | +/* Interrupt Disable Register */ | |
| 97 | +#define AT91_SAMA5D2_IDR 0x28 | |
| 98 | +/* Interrupt Mask Register */ | |
| 99 | +#define AT91_SAMA5D2_IMR 0x2c | |
| 100 | +/* Interrupt Status Register */ | |
| 101 | +#define AT91_SAMA5D2_ISR 0x30 | |
| 102 | +/* Last Channel Trigger Mode Register */ | |
| 103 | +#define AT91_SAMA5D2_LCTMR 0x34 | |
| 104 | +/* Last Channel Compare Window Register */ | |
| 105 | +#define AT91_SAMA5D2_LCCWR 0x38 | |
| 106 | +/* Overrun Status Register */ | |
| 107 | +#define AT91_SAMA5D2_OVER 0x3c | |
| 108 | +/* Extended Mode Register */ | |
| 109 | +#define AT91_SAMA5D2_EMR 0x40 | |
| 110 | +/* Compare Window Register */ | |
| 111 | +#define AT91_SAMA5D2_CWR 0x44 | |
| 112 | +/* Channel Gain Register */ | |
| 113 | +#define AT91_SAMA5D2_CGR 0x48 | |
| 114 | +/* Channel Offset Register */ | |
| 115 | +#define AT91_SAMA5D2_COR 0x4c | |
| 116 | +/* Channel Data Register 0 */ | |
| 117 | +#define AT91_SAMA5D2_CDR0 0x50 | |
| 118 | +/* Analog Control Register */ | |
| 119 | +#define AT91_SAMA5D2_ACR 0x94 | |
| 120 | +/* Touchscreen Mode Register */ | |
| 121 | +#define AT91_SAMA5D2_TSMR 0xb0 | |
| 122 | +/* Touchscreen X Position Register */ | |
| 123 | +#define AT91_SAMA5D2_XPOSR 0xb4 | |
| 124 | +/* Touchscreen Y Position Register */ | |
| 125 | +#define AT91_SAMA5D2_YPOSR 0xb8 | |
| 126 | +/* Touchscreen Pressure Register */ | |
| 127 | +#define AT91_SAMA5D2_PRESSR 0xbc | |
| 128 | +/* Trigger Register */ | |
| 129 | +#define AT91_SAMA5D2_TRGR 0xc0 | |
| 130 | +/* Correction Select Register */ | |
| 131 | +#define AT91_SAMA5D2_COSR 0xd0 | |
| 132 | +/* Correction Value Register */ | |
| 133 | +#define AT91_SAMA5D2_CVR 0xd4 | |
| 134 | +/* Channel Error Correction Register */ | |
| 135 | +#define AT91_SAMA5D2_CECR 0xd8 | |
| 136 | +/* Write Protection Mode Register */ | |
| 137 | +#define AT91_SAMA5D2_WPMR 0xe4 | |
| 138 | +/* Write Protection Status Register */ | |
| 139 | +#define AT91_SAMA5D2_WPSR 0xe8 | |
| 140 | +/* Version Register */ | |
| 141 | +#define AT91_SAMA5D2_VERSION 0xfc | |
| 142 | + | |
| 143 | +#define AT91_AT91_SAMA5D2_CHAN(num, addr) \ | |
| 144 | + { \ | |
| 145 | + .type = IIO_VOLTAGE, \ | |
| 146 | + .channel = num, \ | |
| 147 | + .address = addr, \ | |
| 148 | + .scan_type = { \ | |
| 149 | + .sign = 'u', \ | |
| 150 | + .realbits = 12, \ | |
| 151 | + }, \ | |
| 152 | + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | |
| 153 | + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ | |
| 154 | + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\ | |
| 155 | + .datasheet_name = "CH"#num, \ | |
| 156 | + .indexed = 1, \ | |
| 157 | + } | |
| 158 | + | |
| 159 | +#define at91_adc_readl(st, reg) readl_relaxed(st->base + reg) | |
| 160 | +#define at91_adc_writel(st, reg, val) writel_relaxed(val, st->base + reg) | |
| 161 | + | |
| 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"); | |
| @@ -46,7 +46,7 @@ struct axp288_adc_info { · 45 unmodified lines | ||
| 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, |
| @@ -187,26 +187,27 @@ out: · 186 unmodified lines | ||
| 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[] = { |
| @@ -214,8 +215,10 @@ static const struct iio_chan_spec mcp3204_channels[] = { · 1 unmodified line | ||
| 214 | 215 | MCP320X_VOLTAGE_CHANNEL(1), |
| 215 | 216 | MCP320X_VOLTAGE_CHANNEL(2), |
| 216 | 217 | MCP320X_VOLTAGE_CHANNEL(3), |
| 217 | − MCP320X_VOLTAGE_CHANNEL_DIFF(0), | |
| 218 | − MCP320X_VOLTAGE_CHANNEL_DIFF(1), | |
| 218 | + MCP320X_VOLTAGE_CHANNEL_DIFF(0, 1), | |
| 219 | + MCP320X_VOLTAGE_CHANNEL_DIFF(1, 0), | |
| 220 | + MCP320X_VOLTAGE_CHANNEL_DIFF(2, 3), | |
| 221 | + MCP320X_VOLTAGE_CHANNEL_DIFF(3, 2), | |
| 219 | 222 | }; |
| 220 | 223 | |
| 221 | 224 | static const struct iio_chan_spec mcp3208_channels[] = { |
| @@ -227,10 +230,14 @@ static const struct iio_chan_spec mcp3208_channels[] = { · 5 unmodified lines | ||
| 227 | 230 | MCP320X_VOLTAGE_CHANNEL(5), |
| 228 | 231 | MCP320X_VOLTAGE_CHANNEL(6), |
| 229 | 232 | MCP320X_VOLTAGE_CHANNEL(7), |
| 230 | − MCP320X_VOLTAGE_CHANNEL_DIFF(0), | |
| 231 | − MCP320X_VOLTAGE_CHANNEL_DIFF(1), | |
| 232 | − MCP320X_VOLTAGE_CHANNEL_DIFF(2), | |
| 233 | − MCP320X_VOLTAGE_CHANNEL_DIFF(3), | |
| 233 | + MCP320X_VOLTAGE_CHANNEL_DIFF(0, 1), | |
| 234 | + MCP320X_VOLTAGE_CHANNEL_DIFF(1, 0), | |
| 235 | + MCP320X_VOLTAGE_CHANNEL_DIFF(2, 3), | |
| 236 | + MCP320X_VOLTAGE_CHANNEL_DIFF(3, 2), | |
| 237 | + MCP320X_VOLTAGE_CHANNEL_DIFF(4, 5), | |
| 238 | + MCP320X_VOLTAGE_CHANNEL_DIFF(5, 4), | |
| 239 | + MCP320X_VOLTAGE_CHANNEL_DIFF(6, 7), | |
| 240 | + MCP320X_VOLTAGE_CHANNEL_DIFF(7, 6), | |
| 234 | 241 | }; |
| 235 | 242 | |
| 236 | 243 | static const struct iio_info mcp320x_info = { |
| @@ -1,11 +1,12 @@ | ||
| 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. |
| @@ -357,6 +358,7 @@ static int mcp3422_probe(struct i2c_client *client, · 345 unmodified lines | ||
| 357 | 358 | |
| 358 | 359 | switch (adc->id) { |
| 359 | 360 | case 1: |
| 361 | + case 5: | |
| 360 | 362 | indio_dev->channels = mcp3421_channels; |
| 361 | 363 | indio_dev->num_channels = ARRAY_SIZE(mcp3421_channels); |
| 362 | 364 | break; |
| @@ -395,6 +397,7 @@ static const struct i2c_device_id mcp3422_id[] = { · 32 unmodified lines | ||
| 395 | 397 | { "mcp3422", 2 }, |
| 396 | 398 | { "mcp3423", 3 }, |
| 397 | 399 | { "mcp3424", 4 }, |
| 400 | + { "mcp3425", 5 }, | |
| 398 | 401 | { "mcp3426", 6 }, |
| 399 | 402 | { "mcp3427", 7 }, |
| 400 | 403 | { "mcp3428", 8 }, |
| @@ -421,5 +424,5 @@ static struct i2c_driver mcp3422_driver = { · 20 unmodified lines | ||
| 421 | 424 | module_i2c_driver(mcp3422_driver); |
| 422 | 425 | |
| 423 | 426 | MODULE_AUTHOR("Angelo Compagnucci <angelo.compagnucci@gmail.com>"); |
| 424 | −MODULE_DESCRIPTION("Microchip mcp3422/3/4/6/7/8 driver"); | |
| 427 | +MODULE_DESCRIPTION("Microchip mcp3421/2/3/4/5/6/7/8 driver"); | |
| 425 | 428 | MODULE_LICENSE("GPL v2"); |
| @@ -4,6 +4,19 @@ · 3 unmodified lines | ||
| 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 |
| @@ -3,5 +3,6 @@ · 2 unmodified lines | ||
| 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 |
| @@ -0,0 +1,511 @@ | ||
| 1 | +/* | |
| 2 | + * atlas-ph-sensor.c - Support for Atlas Scientific OEM pH-SM sensor | |
| 3 | + * | |
| 4 | + * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com> | |
| 5 | + * | |
| 6 | + * This program is free software; you can redistribute it and/or modify | |
| 7 | + * it under the terms of the GNU General Public License as published by | |
| 8 | + * the Free Software Foundation; either version 2 of the License, or | |
| 9 | + * (at your option) any later version. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + */ | |
| 16 | + | |
| 17 | +#include <linux/module.h> | |
| 18 | +#include <linux/init.h> | |
| 19 | +#include <linux/interrupt.h> | |
| 20 | +#include <linux/delay.h> | |
| 21 | +#include <linux/mutex.h> | |
| 22 | +#include <linux/err.h> | |
| 23 | +#include <linux/irq.h> | |
| 24 | +#include <linux/irq_work.h> | |
| 25 | +#include <linux/gpio.h> | |
| 26 | +#include <linux/i2c.h> | |
| 27 | +#include <linux/regmap.h> | |
| 28 | +#include <linux/iio/iio.h> | |
| 29 | +#include <linux/iio/buffer.h> | |
| 30 | +#include <linux/iio/trigger.h> | |
| 31 | +#include <linux/iio/trigger_consumer.h> | |
| 32 | +#include <linux/iio/triggered_buffer.h> | |
| 33 | +#include <linux/pm_runtime.h> | |
| 34 | + | |
| 35 | +#define ATLAS_REGMAP_NAME "atlas_ph_regmap" | |
| 36 | +#define ATLAS_DRV_NAME "atlas_ph" | |
| 37 | + | |
| 38 | +#define ATLAS_REG_DEV_TYPE 0x00 | |
| 39 | +#define ATLAS_REG_DEV_VERSION 0x01 | |
| 40 | + | |
| 41 | +#define ATLAS_REG_INT_CONTROL 0x04 | |
| 42 | +#define ATLAS_REG_INT_CONTROL_EN BIT(3) | |
| 43 | + | |
| 44 | +#define ATLAS_REG_PWR_CONTROL 0x06 | |
| 45 | + | |
| 46 | +#define ATLAS_REG_CALIB_STATUS 0x0d | |
| 47 | +#define ATLAS_REG_CALIB_STATUS_MASK 0x07 | |
| 48 | +#define ATLAS_REG_CALIB_STATUS_LOW BIT(0) | |
| 49 | +#define ATLAS_REG_CALIB_STATUS_MID BIT(1) | |
| 50 | +#define ATLAS_REG_CALIB_STATUS_HIGH BIT(2) | |
| 51 | + | |
| 52 | +#define ATLAS_REG_TEMP_DATA 0x0e | |
| 53 | +#define ATLAS_REG_PH_DATA 0x16 | |
| 54 | + | |
| 55 | +#define ATLAS_PH_INT_TIME_IN_US 450000 | |
| 56 | + | |
| 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 *) ®, 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, ®); | |
| 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 | + ®, 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"); | |
| @@ -18,13 +18,15 @@ · 17 unmodified lines | ||
| 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; |
| @@ -0,0 +1,8 @@ | ||
| 1 | +/* | |
| 2 | + * Local functions in the ST Sensors core | |
| 3 | + */ | |
| 4 | +#ifndef __ST_SENSORS_CORE_H | |
| 5 | +#define __ST_SENSORS_CORE_H | |
| 6 | +int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, | |
| 7 | + u8 reg_addr, u8 mask, u8 data); | |
| 8 | +#endif | |
| @@ -14,32 +14,65 @@ · 13 unmodified lines | ||
| 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); |
| @@ -57,9 +90,8 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev, · 11 unmodified lines | ||
| 57 | 90 | |
| 58 | 91 | iio_trigger_register_error: |
| 59 | 92 | free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig); |
| 60 | −request_irq_error: | |
| 93 | +iio_trigger_free: | |
| 61 | 94 | iio_trigger_free(sdata->trig); |
| 62 | −iio_trigger_alloc_error: | |
| 63 | 95 | return err; |
| 64 | 96 | } |
| 65 | 97 | EXPORT_SYMBOL(st_sensors_allocate_trigger); |
| @@ -111,6 +111,16 @@ config AD5755 · 110 unmodified lines | ||
| 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 |
| @@ -176,11 +186,11 @@ config MAX5821 · 59 unmodified lines | ||
| 176 | 186 | 10 bits DAC. |
| 177 | 187 | |
| 178 | 188 | config MCP4725 |
| 179 | − tristate "MCP4725 DAC driver" | |
| 189 | + tristate "MCP4725/6 DAC driver" | |
| 180 | 190 | depends on I2C |
| 181 | 191 | ---help--- |
| 182 | 192 | Say Y here if you want to build a driver for the Microchip |
| 183 | − MCP 4725 12-bit digital-to-analog converter (DAC) with I2C | |
| 193 | + MCP 4725/6 12-bit digital-to-analog converter (DAC) with I2C | |
| 184 | 194 | interface. |
| 185 | 195 | |
| 186 | 196 | To compile this driver as a module, choose M here: the module |
| @@ -12,6 +12,7 @@ obj-$(CONFIG_AD5504) += ad5504.o · 11 unmodified lines | ||
| 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 |
| @@ -0,0 +1,430 @@ | ||
| 1 | +/* | |
| 2 | + * AD5721, AD5721R, AD5761, AD5761R, Voltage Output Digital to Analog Converter | |
| 3 | + * | |
| 4 | + * Copyright 2016 Qtechnology A/S | |
| 5 | + * 2016 Ricardo Ribalda <ricardo.ribalda@gmail.com> | |
| 6 | + * | |
| 7 | + * Licensed under the GPL-2. | |
| 8 | + */ | |
| 9 | +#include <linux/kernel.h> | |
| 10 | +#include <linux/module.h> | |
| 11 | +#include <linux/spi/spi.h> | |
| 12 | +#include <linux/bitops.h> | |
| 13 | +#include <linux/iio/iio.h> | |
| 14 | +#include <linux/iio/sysfs.h> | |
| 15 | +#include <linux/regulator/consumer.h> | |
| 16 | +#include <linux/platform_data/ad5761.h> | |
| 17 | + | |
| 18 | +#define AD5761_ADDR(addr) ((addr & 0xf) << 16) | |
| 19 | +#define AD5761_ADDR_NOOP 0x0 | |
| 20 | +#define AD5761_ADDR_DAC_WRITE 0x3 | |
| 21 | +#define AD5761_ADDR_CTRL_WRITE_REG 0x4 | |
| 22 | +#define AD5761_ADDR_SW_DATA_RESET 0x7 | |
| 23 | +#define AD5761_ADDR_DAC_READ 0xb | |
| 24 | +#define AD5761_ADDR_CTRL_READ_REG 0xc | |
| 25 | +#define AD5761_ADDR_SW_FULL_RESET 0xf | |
| 26 | + | |
| 27 | +#define AD5761_CTRL_USE_INTVREF BIT(5) | |
| 28 | +#define AD5761_CTRL_ETS BIT(6) | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * struct ad5761_chip_info - chip specific information | |
| 32 | + * @int_vref: Value of the internal reference voltage in mV - 0 if external | |
| 33 | + * reference voltage is used | |
| 34 | + * @channel: channel specification | |
| 35 | +*/ | |
| 36 | + | |
| 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"); | |
| @@ -1,5 +1,5 @@ | ||
| 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,6 +134,12 @@ static const char * const mcp4725_powerdown_modes[] = { · 128 unmodified lines | ||
| 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 | { |
| @@ -182,11 +188,24 @@ static ssize_t mcp4725_write_powerdown(struct iio_dev *indio_dev, · 42 unmodified lines | ||
| 182 | 188 | return len; |
| 183 | 189 | } |
| 184 | 190 | |
| 185 | −static const struct iio_enum mcp4725_powerdown_mode_enum = { | |
| 186 | − .items = mcp4725_powerdown_modes, | |
| 187 | − .num_items = ARRAY_SIZE(mcp4725_powerdown_modes), | |
| 188 | − .get = mcp4725_get_powerdown_mode, | |
| 189 | − .set = mcp4725_set_powerdown_mode, | |
| 191 | +enum { | |
| 192 | + MCP4725, | |
| 193 | + MCP4726, | |
| 194 | +}; | |
| 195 | + | |
| 196 | +static const struct iio_enum mcp472x_powerdown_mode_enum[] = { | |
| 197 | + [MCP4725] = { | |
| 198 | + .items = mcp4725_powerdown_modes, | |
| 199 | + .num_items = ARRAY_SIZE(mcp4725_powerdown_modes), | |
| 200 | + .get = mcp4725_get_powerdown_mode, | |
| 201 | + .set = mcp4725_set_powerdown_mode, | |
| 202 | + }, | |
| 203 | + [MCP4726] = { | |
| 204 | + .items = mcp4726_powerdown_modes, | |
| 205 | + .num_items = ARRAY_SIZE(mcp4726_powerdown_modes), | |
| 206 | + .get = mcp4725_get_powerdown_mode, | |
| 207 | + .set = mcp4725_set_powerdown_mode, | |
| 208 | + }, | |
| 190 | 209 | }; |
| 191 | 210 | |
| 192 | 211 | static const struct iio_chan_spec_ext_info mcp4725_ext_info[] = { |
| @@ -196,19 +215,46 @@ static const struct iio_chan_spec_ext_info mcp4725_ext_info[] = { · 3 unmodified lines | ||
| 196 | 215 | .write = mcp4725_write_powerdown, |
| 197 | 216 | .shared = IIO_SEPARATE, |
| 198 | 217 | }, |
| 199 | − IIO_ENUM("powerdown_mode", IIO_SEPARATE, &mcp4725_powerdown_mode_enum), | |
| 200 | − IIO_ENUM_AVAILABLE("powerdown_mode", &mcp4725_powerdown_mode_enum), | |
| 218 | + IIO_ENUM("powerdown_mode", IIO_SEPARATE, | |
| 219 | + &mcp472x_powerdown_mode_enum[MCP4725]), | |
| 220 | + IIO_ENUM_AVAILABLE("powerdown_mode", | |
| 221 | + &mcp472x_powerdown_mode_enum[MCP4725]), | |
| 222 | + { }, | |
| 223 | +}; | |
| 224 | + | |
| 225 | +static const struct iio_chan_spec_ext_info mcp4726_ext_info[] = { | |
| 226 | + { | |
| 227 | + .name = "powerdown", | |
| 228 | + .read = mcp4725_read_powerdown, | |
| 229 | + .write = mcp4725_write_powerdown, | |
| 230 | + .shared = IIO_SEPARATE, | |
| 231 | + }, | |
| 232 | + IIO_ENUM("powerdown_mode", IIO_SEPARATE, | |
| 233 | + &mcp472x_powerdown_mode_enum[MCP4726]), | |
| 234 | + IIO_ENUM_AVAILABLE("powerdown_mode", | |
| 235 | + &mcp472x_powerdown_mode_enum[MCP4726]), | |
| 201 | 236 | { }, |
| 202 | 237 | }; |
| 203 | 238 | |
| 204 | −static const struct iio_chan_spec mcp4725_channel = { | |
| 205 | − .type = IIO_VOLTAGE, | |
| 206 | − .indexed = 1, | |
| 207 | − .output = 1, | |
| 208 | − .channel = 0, | |
| 209 | − .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), | |
| 210 | − .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), | |
| 211 | − .ext_info = mcp4725_ext_info, | |
| 239 | +static const struct iio_chan_spec mcp472x_channel[] = { | |
| 240 | + [MCP4725] = { | |
| 241 | + .type = IIO_VOLTAGE, | |
| 242 | + .indexed = 1, | |
| 243 | + .output = 1, | |
| 244 | + .channel = 0, | |
| 245 | + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), | |
| 246 | + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), | |
| 247 | + .ext_info = mcp4725_ext_info, | |
| 248 | + }, | |
| 249 | + [MCP4726] = { | |
| 250 | + .type = IIO_VOLTAGE, | |
| 251 | + .indexed = 1, | |
| 252 | + .output = 1, | |
| 253 | + .channel = 0, | |
| 254 | + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), | |
| 255 | + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), | |
| 256 | + .ext_info = mcp4726_ext_info, | |
| 257 | + }, | |
| 212 | 258 | }; |
| 213 | 259 | |
| 214 | 260 | static int mcp4725_set_value(struct iio_dev *indio_dev, int val) |
| @@ -301,7 +347,7 @@ static int mcp4725_probe(struct i2c_client *client, · 86 unmodified lines | ||
| 301 | 347 | |
| 302 | 348 | indio_dev->dev.parent = &client->dev; |
| 303 | 349 | indio_dev->info = &mcp4725_info; |
| 304 | − indio_dev->channels = &mcp4725_channel; | |
| 350 | + indio_dev->channels = &mcp472x_channel[id->driver_data]; | |
| 305 | 351 | indio_dev->num_channels = 1; |
| 306 | 352 | indio_dev->modes = INDIO_DIRECT_MODE; |
| 307 | 353 | |
| @@ -315,7 +361,7 @@ static int mcp4725_probe(struct i2c_client *client, · 7 unmodified lines | ||
| 315 | 361 | } |
| 316 | 362 | pd = (inbuf[0] >> 1) & 0x3; |
| 317 | 363 | data->powerdown = pd > 0 ? true : false; |
| 318 | − data->powerdown_mode = pd ? pd-1 : 2; /* 500kohm_to_gnd */ | |
| 364 | + data->powerdown_mode = pd ? pd - 1 : 2; /* largest register to gnd */ | |
| 319 | 365 | data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4); |
| 320 | 366 | |
| 321 | 367 | return iio_device_register(indio_dev); |
| @@ -328,7 +374,8 @@ static int mcp4725_remove(struct i2c_client *client) · 6 unmodified lines | ||
| 328 | 374 | } |
| 329 | 375 | |
| 330 | 376 | static const struct i2c_device_id mcp4725_id[] = { |
| 331 | − { "mcp4725", 0 }, | |
| 377 | + { "mcp4725", MCP4725 }, | |
| 378 | + { "mcp4726", MCP4726 }, | |
| 332 | 379 | { } |
| 333 | 380 | }; |
| 334 | 381 | MODULE_DEVICE_TABLE(i2c, mcp4725_id); |
| @@ -345,5 +392,5 @@ static struct i2c_driver mcp4725_driver = { · 10 unmodified lines | ||
| 345 | 392 | module_i2c_driver(mcp4725_driver); |
| 346 | 393 | |
| 347 | 394 | MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>"); |
| 348 | −MODULE_DESCRIPTION("MCP4725 12-bit DAC"); | |
| 395 | +MODULE_DESCRIPTION("MCP4725/6 12-bit DAC"); | |
| 349 | 396 | MODULE_LICENSE("GPL"); |
| @@ -185,6 +185,11 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { · 184 unmodified lines | ||
| 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, |
| @@ -248,6 +253,11 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { · 57 unmodified lines | ||
| 248 | 253 | .drdy_irq = { |
| 249 | 254 | .addr = ST_GYRO_2_DRDY_IRQ_ADDR, |
| 250 | 255 | .mask_int2 = ST_GYRO_2_DRDY_IRQ_INT2_MASK, |
| 256 | + /* | |
| 257 | + * The sensor has IHL (active low) and open | |
| 258 | + * drain settings, but only for INT1 and not | |
| 259 | + * for the DRDY line on INT2. | |
| 260 | + */ | |
| 251 | 261 | }, |
| 252 | 262 | .multi_read_bit = ST_GYRO_2_MULTIREAD_BIT, |
| 253 | 263 | .bootime = 2, |
| @@ -307,6 +317,11 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { · 53 unmodified lines | ||
| 307 | 317 | .drdy_irq = { |
| 308 | 318 | .addr = ST_GYRO_3_DRDY_IRQ_ADDR, |
| 309 | 319 | .mask_int2 = ST_GYRO_3_DRDY_IRQ_INT2_MASK, |
| 320 | + /* | |
| 321 | + * The sensor has IHL (active low) and open | |
| 322 | + * drain settings, but only for INT1 and not | |
| 323 | + * for the DRDY line on INT2. | |
| 324 | + */ | |
| 310 | 325 | }, |
| 311 | 326 | .multi_read_bit = ST_GYRO_3_MULTIREAD_BIT, |
| 312 | 327 | .bootime = 2, |
| @@ -13,7 +13,7 @@ · 12 unmodified lines | ||
| 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,6 +24,7 @@ · 4 unmodified lines | ||
| 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> |
| @@ -65,6 +66,7 @@ · 35 unmodified lines | ||
| 65 | 66 | #define MAX30100_REG_SPO2_CONFIG_1600US 0x3 |
| 66 | 67 | |
| 67 | 68 | #define MAX30100_REG_LED_CONFIG 0x09 |
| 69 | +#define MAX30100_REG_LED_CONFIG_LED_MASK 0x0f | |
| 68 | 70 | #define MAX30100_REG_LED_CONFIG_RED_LED_SHIFT 4 |
| 69 | 71 | |
| 70 | 72 | #define MAX30100_REG_LED_CONFIG_24MA 0x07 |
| @@ -111,6 +113,12 @@ static const struct regmap_config max30100_regmap_config = { · 40 unmodified lines | ||
| 111 | 113 | .volatile_reg = max30100_is_volatile_reg, |
| 112 | 114 | }; |
| 113 | 115 | |
| 116 | +static const unsigned int max30100_led_current_mapping[] = { | |
| 117 | + 4400, 7600, 11000, 14200, 17400, | |
| 118 | + 20800, 24000, 27100, 30600, 33800, | |
| 119 | + 37000, 40200, 43600, 46800, 50000 | |
| 120 | +}; | |
| 121 | + | |
| 114 | 122 | static const unsigned long max30100_scan_masks[] = {0x3, 0}; |
| 115 | 123 | |
| 116 | 124 | static const struct iio_chan_spec max30100_channels[] = { |
| @@ -243,15 +251,76 @@ static irqreturn_t max30100_interrupt_handler(int irq, void *private) · 126 unmodified lines | ||
| 243 | 251 | return IRQ_HANDLED; |
| 244 | 252 | } |
| 245 | 253 | |
| 254 | +static int max30100_get_current_idx(unsigned int val, int *reg) | |
| 255 | +{ | |
| 256 | + int idx; | |
| 257 | + | |
| 258 | + /* LED turned off */ | |
| 259 | + if (val == 0) { | |
| 260 | + *reg = 0; | |
| 261 | + return 0; | |
| 262 | + } | |
| 263 | + | |
| 264 | + for (idx = 0; idx < ARRAY_SIZE(max30100_led_current_mapping); idx++) { | |
| 265 | + if (max30100_led_current_mapping[idx] == val) { | |
| 266 | + *reg = idx + 1; | |
| 267 | + return 0; | |
| 268 | + } | |
| 269 | + } | |
| 270 | + | |
| 271 | + return -EINVAL; | |
| 272 | +} | |
| 273 | + | |
| 274 | +static int max30100_led_init(struct max30100_data *data) | |
| 275 | +{ | |
| 276 | + struct device *dev = &data->client->dev; | |
| 277 | + struct device_node *np = dev->of_node; | |
| 278 | + unsigned int val[2]; | |
| 279 | + int reg, ret; | |
| 280 | + | |
| 281 | + ret = of_property_read_u32_array(np, "maxim,led-current-microamp", | |
| 282 | + (unsigned int *) &val, 2); | |
| 283 | + if (ret) { | |
| 284 | + /* Default to 24 mA RED LED, 50 mA IR LED */ | |
| 285 | + reg = (MAX30100_REG_LED_CONFIG_24MA << | |
| 286 | + MAX30100_REG_LED_CONFIG_RED_LED_SHIFT) | | |
| 287 | + MAX30100_REG_LED_CONFIG_50MA; | |
| 288 | + dev_warn(dev, "no led-current-microamp set"); | |
| 289 | + | |
| 290 | + return regmap_write(data->regmap, MAX30100_REG_LED_CONFIG, reg); | |
| 291 | + } | |
| 292 | + | |
| 293 | + /* RED LED current */ | |
| 294 | + ret = max30100_get_current_idx(val[0], ®); | |
| 295 | + if (ret) { | |
| 296 | + dev_err(dev, "invalid RED current setting %d", val[0]); | |
| 297 | + return ret; | |
| 298 | + } | |
| 299 | + | |
| 300 | + ret = regmap_update_bits(data->regmap, MAX30100_REG_LED_CONFIG, | |
| 301 | + MAX30100_REG_LED_CONFIG_LED_MASK << | |
| 302 | + MAX30100_REG_LED_CONFIG_RED_LED_SHIFT, | |
| 303 | + reg << MAX30100_REG_LED_CONFIG_RED_LED_SHIFT); | |
| 304 | + if (ret) | |
| 305 | + return ret; | |
| 306 | + | |
| 307 | + /* IR LED current */ | |
| 308 | + ret = max30100_get_current_idx(val[1], ®); | |
| 309 | + if (ret) { | |
| 310 | + dev_err(dev, "invalid IR current setting %d", val[1]); | |
| 311 | + return ret; | |
| 312 | + } | |
| 313 | + | |
| 314 | + return regmap_update_bits(data->regmap, MAX30100_REG_LED_CONFIG, | |
| 315 | + MAX30100_REG_LED_CONFIG_LED_MASK, reg); | |
| 316 | +} | |
| 317 | + | |
| 246 | 318 | static int max30100_chip_init(struct max30100_data *data) |
| 247 | 319 | { |
| 248 | 320 | int ret; |
| 249 | 321 | |
| 250 | − /* RED IR LED = 24mA, IR LED = 50mA */ | |
| 251 | − ret = regmap_write(data->regmap, MAX30100_REG_LED_CONFIG, | |
| 252 | − (MAX30100_REG_LED_CONFIG_24MA << | |
| 253 | − MAX30100_REG_LED_CONFIG_RED_LED_SHIFT) | | |
| 254 | − MAX30100_REG_LED_CONFIG_50MA); | |
| 322 | + /* setup LED current settings */ | |
| 323 | + ret = max30100_led_init(data); | |
| 255 | 324 | if (ret) |
| 256 | 325 | return ret; |
| 257 | 326 | |
| @@ -43,14 +43,16 @@ config SI7005 · 42 unmodified lines | ||
| 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,12 +50,32 @@ · 49 unmodified lines | ||
| 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; |
| @@ -76,43 +96,39 @@ struct dht11 { · 14 unmodified lines | ||
| 76 | 96 | struct {s64 ts; int value; } edges[DHT11_EDGES_PER_READ]; |
| 77 | 97 | }; |
| 78 | 98 | |
| 79 | −static unsigned char dht11_decode_byte(int *timing, int threshold) | |
| 99 | +static unsigned char dht11_decode_byte(char *bits) | |
| 80 | 100 | { |
| 81 | 101 | unsigned char ret = 0; |
| 82 | 102 | int i; |
| 83 | 103 | |
| 84 | 104 | for (i = 0; i < 8; ++i) { |
| 85 | 105 | ret <<= 1; |
| 86 | − if (timing[i] >= threshold) | |
| 106 | + if (bits[i]) | |
| 87 | 107 | ++ret; |
| 88 | 108 | } |
| 89 | 109 | |
| 90 | 110 | return ret; |
| 91 | 111 | } |
| 92 | 112 | |
| 93 | −static int dht11_decode(struct dht11 *dht11, int offset, int timeres) | |
| 113 | +static int dht11_decode(struct dht11 *dht11, int offset) | |
| 94 | 114 | { |
| 95 | − int i, t, timing[DHT11_BITS_PER_READ], threshold; | |
| 115 | + int i, t; | |
| 116 | + char bits[DHT11_BITS_PER_READ]; | |
| 96 | 117 | unsigned char temp_int, temp_dec, hum_int, hum_dec, checksum; |
| 97 | 118 | |
| 98 | − threshold = DHT11_DATA_BIT_HIGH / timeres; | |
| 99 | − if (DHT11_DATA_BIT_LOW / timeres + 1 >= threshold) | |
| 100 | − pr_err("dht11: WARNING: decoding ambiguous\n"); | |
| 101 | − | |
| 102 | − /* scale down with timeres and check validity */ | |
| 103 | 119 | for (i = 0; i < DHT11_BITS_PER_READ; ++i) { |
| 104 | 120 | t = dht11->edges[offset + 2 * i + 2].ts - |
| 105 | 121 | dht11->edges[offset + 2 * i + 1].ts; |
| 106 | 122 | if (!dht11->edges[offset + 2 * i + 1].value) |
| 107 | 123 | return -EIO; /* lost synchronisation */ |
| 108 | − timing[i] = t / timeres; | |
| 124 | + bits[i] = t > DHT11_THRESHOLD; | |
| 109 | 125 | } |
| 110 | 126 | |
| 111 | − hum_int = dht11_decode_byte(timing, threshold); | |
| 112 | − hum_dec = dht11_decode_byte(&timing[8], threshold); | |
| 113 | − temp_int = dht11_decode_byte(&timing[16], threshold); | |
| 114 | − temp_dec = dht11_decode_byte(&timing[24], threshold); | |
| 115 | − checksum = dht11_decode_byte(&timing[32], threshold); | |
| 127 | + hum_int = dht11_decode_byte(bits); | |
| 128 | + hum_dec = dht11_decode_byte(&bits[8]); | |
| 129 | + temp_int = dht11_decode_byte(&bits[16]); | |
| 130 | + temp_dec = dht11_decode_byte(&bits[24]); | |
| 131 | + checksum = dht11_decode_byte(&bits[32]); | |
| 116 | 132 | |
| 117 | 133 | if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum) |
| 118 | 134 | return -EIO; |
| @@ -161,12 +177,12 @@ static int dht11_read_raw(struct iio_dev *iio_dev, · 42 unmodified lines | ||
| 161 | 177 | int *val, int *val2, long m) |
| 162 | 178 | { |
| 163 | 179 | struct dht11 *dht11 = iio_priv(iio_dev); |
| 164 | − int ret, timeres; | |
| 180 | + int ret, timeres, offset; | |
| 165 | 181 | |
| 166 | 182 | mutex_lock(&dht11->lock); |
| 167 | 183 | if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_real_ns()) { |
| 168 | 184 | timeres = ktime_get_resolution_ns(); |
| 169 | − if (DHT11_DATA_BIT_HIGH < 2 * timeres) { | |
| 185 | + if (timeres > DHT11_MIN_TIMERES) { | |
| 170 | 186 | dev_err(dht11->dev, "timeresolution %dns too low\n", |
| 171 | 187 | timeres); |
| 172 | 188 | /* In theory a better clock could become available |
| @@ -176,6 +192,10 @@ static int dht11_read_raw(struct iio_dev *iio_dev, · 3 unmodified lines | ||
| 176 | 192 | ret = -EAGAIN; |
| 177 | 193 | goto err; |
| 178 | 194 | } |
| 195 | + if (timeres > DHT11_AMBIG_LOW && timeres < DHT11_AMBIG_HIGH) | |
| 196 | + dev_warn(dht11->dev, | |
| 197 | + "timeresolution: %dns - decoding ambiguous\n", | |
| 198 | + timeres); | |
| 179 | 199 | |
| 180 | 200 | reinit_completion(&dht11->completion); |
| 181 | 201 | |
| @@ -208,11 +228,14 @@ static int dht11_read_raw(struct iio_dev *iio_dev, · 26 unmodified lines | ||
| 208 | 228 | if (ret < 0) |
| 209 | 229 | goto err; |
| 210 | 230 | |
| 211 | − ret = dht11_decode(dht11, | |
| 212 | − dht11->num_edges == DHT11_EDGES_PER_READ ? | |
| 213 | − DHT11_EDGES_PREAMBLE : | |
| 214 | − DHT11_EDGES_PREAMBLE - 2, | |
| 215 | − timeres); | |
| 231 | + offset = DHT11_EDGES_PREAMBLE + | |
| 232 | + dht11->num_edges - DHT11_EDGES_PER_READ; | |
| 233 | + for (; offset >= 0; --offset) { | |
| 234 | + ret = dht11_decode(dht11, offset); | |
| 235 | + if (!ret) | |
| 236 | + break; | |
| 237 | + } | |
| 238 | + | |
| 216 | 239 | if (ret) |
| 217 | 240 | goto err; |
| 218 | 241 | } |
| @@ -170,6 +170,7 @@ static int si7005_probe(struct i2c_client *client, · 169 unmodified lines | ||
| 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); |
| @@ -149,6 +149,7 @@ static int si7020_probe(struct i2c_client *client, · 148 unmodified lines | ||
| 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); |
| @@ -727,8 +727,7 @@ static const struct iio_info mpu_info = { · 726 unmodified lines | ||
| 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 | |
| @@ -795,7 +794,7 @@ static int inv_mpu_probe(struct i2c_client *client, · 60 unmodified lines | ||
| 795 | 794 | if (pdata) |
| 796 | 795 | st->plat_data = *pdata; |
| 797 | 796 | /* power is turned on inside check chip type*/ |
| 798 | − result = inv_check_and_setup_chip(st, id); | |
| 797 | + result = inv_check_and_setup_chip(st); | |
| 799 | 798 | if (result) |
| 800 | 799 | return result; |
| 801 | 800 | |
| @@ -77,6 +77,7 @@ static const char * const iio_chan_type_name_spec[] = { · 76 unmodified lines | ||
| 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[] = { |
| @@ -65,19 +65,25 @@ · 64 unmodified lines | ||
| 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 | |
| @@ -89,6 +95,8 @@ struct opt3001 { · 5 unmodified lines | ||
| 89 | 95 | |
| 90 | 96 | u8 high_thresh_exp; |
| 91 | 97 | u8 low_thresh_exp; |
| 98 | + | |
| 99 | + bool use_irq; | |
| 92 | 100 | }; |
| 93 | 101 | |
| 94 | 102 | struct opt3001_scale { |
| @@ -227,26 +235,30 @@ static int opt3001_get_lux(struct opt3001 *opt, int *val, int *val2) · 132 unmodified lines | ||
| 227 | 235 | u16 reg; |
| 228 | 236 | u8 exponent; |
| 229 | 237 | u16 value; |
| 238 | + long timeout; | |
| 230 | 239 | |
| 231 | − /* | |
| 232 | − * Enable the end-of-conversion interrupt mechanism. Note that doing | |
| 233 | − * so will overwrite the low-level limit value however we will restore | |
| 234 | − * this value later on. | |
| 235 | − */ | |
| 236 | − ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_LOW_LIMIT, | |
| 237 | − OPT3001_LOW_LIMIT_EOC_ENABLE); | |
| 238 | − if (ret < 0) { | |
| 239 | − dev_err(opt->dev, "failed to write register %02x\n", | |
| 240 | − OPT3001_LOW_LIMIT); | |
| 241 | − return ret; | |
| 240 | + if (opt->use_irq) { | |
| 241 | + /* | |
| 242 | + * Enable the end-of-conversion interrupt mechanism. Note that | |
| 243 | + * doing so will overwrite the low-level limit value however we | |
| 244 | + * will restore this value later on. | |
| 245 | + */ | |
| 246 | + ret = i2c_smbus_write_word_swapped(opt->client, | |
| 247 | + OPT3001_LOW_LIMIT, | |
| 248 | + OPT3001_LOW_LIMIT_EOC_ENABLE); | |
| 249 | + if (ret < 0) { | |
| 250 | + dev_err(opt->dev, "failed to write register %02x\n", | |
| 251 | + OPT3001_LOW_LIMIT); | |
| 252 | + return ret; | |
| 253 | + } | |
| 254 | + | |
| 255 | + /* Allow IRQ to access the device despite lock being set */ | |
| 256 | + opt->ok_to_ignore_lock = true; | |
| 242 | 257 | } |
| 243 | 258 | |
| 244 | − /* Reset data-ready indicator flag (will be set in the IRQ routine) */ | |
| 259 | + /* Reset data-ready indicator flag */ | |
| 245 | 260 | opt->result_ready = false; |
| 246 | 261 | |
| 247 | − /* Allow IRQ to access the device despite lock being set */ | |
| 248 | − opt->ok_to_ignore_lock = true; | |
| 249 | − | |
| 250 | 262 | /* Configure for single-conversion mode and start a new conversion */ |
| 251 | 263 | ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); |
| 252 | 264 | if (ret < 0) { |
| @@ -266,32 +278,69 @@ static int opt3001_get_lux(struct opt3001 *opt, int *val, int *val2) · 13 unmodified lines | ||
| 266 | 278 | goto err; |
| 267 | 279 | } |
| 268 | 280 | |
| 269 | − /* Wait for the IRQ to indicate the conversion is complete */ | |
| 270 | − ret = wait_event_timeout(opt->result_ready_queue, opt->result_ready, | |
| 271 | − OPT3001_RESULT_READY_TIMEOUT); | |
| 281 | + if (opt->use_irq) { | |
| 282 | + /* Wait for the IRQ to indicate the conversion is complete */ | |
| 283 | + ret = wait_event_timeout(opt->result_ready_queue, | |
| 284 | + opt->result_ready, | |
| 285 | + msecs_to_jiffies(OPT3001_RESULT_READY_LONG)); | |
| 286 | + } else { | |
| 287 | + /* Sleep for result ready time */ | |
| 288 | + timeout = (opt->int_time == OPT3001_INT_TIME_SHORT) ? | |
| 289 | + OPT3001_RESULT_READY_SHORT : OPT3001_RESULT_READY_LONG; | |
| 290 | + msleep(timeout); | |
| 291 | + | |
| 292 | + /* Check result ready flag */ | |
| 293 | + ret = i2c_smbus_read_word_swapped(opt->client, | |
| 294 | + OPT3001_CONFIGURATION); | |
| 295 | + if (ret < 0) { | |
| 296 | + dev_err(opt->dev, "failed to read register %02x\n", | |
| 297 | + OPT3001_CONFIGURATION); | |
| 298 | + goto err; | |
| 299 | + } | |
| 300 | + | |
| 301 | + if (!(ret & OPT3001_CONFIGURATION_CRF)) { | |
| 302 | + ret = -ETIMEDOUT; | |
| 303 | + goto err; | |
| 304 | + } | |
| 305 | + | |
| 306 | + /* Obtain value */ | |
| 307 | + ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_RESULT); | |
| 308 | + if (ret < 0) { | |
| 309 | + dev_err(opt->dev, "failed to read register %02x\n", | |
| 310 | + OPT3001_RESULT); | |
| 311 | + goto err; | |
| 312 | + } | |
| 313 | + opt->result = ret; | |
| 314 | + opt->result_ready = true; | |
| 315 | + } | |
| 272 | 316 | |
| 273 | 317 | err: |
| 274 | − /* Disallow IRQ to access the device while lock is active */ | |
| 275 | − opt->ok_to_ignore_lock = false; | |
| 318 | + if (opt->use_irq) | |
| 319 | + /* Disallow IRQ to access the device while lock is active */ | |
| 320 | + opt->ok_to_ignore_lock = false; | |
| 276 | 321 | |
| 277 | 322 | if (ret == 0) |
| 278 | 323 | return -ETIMEDOUT; |
| 279 | 324 | else if (ret < 0) |
| 280 | 325 | return ret; |
| 281 | 326 | |
| 282 | − /* | |
| 283 | − * Disable the end-of-conversion interrupt mechanism by restoring the | |
| 284 | − * low-level limit value (clearing OPT3001_LOW_LIMIT_EOC_ENABLE). Note | |
| 285 | − * that selectively clearing those enable bits would affect the actual | |
| 286 | − * limit value due to bit-overlap and therefore can't be done. | |
| 287 | − */ | |
| 288 | − value = (opt->low_thresh_exp << 12) | opt->low_thresh_mantissa; | |
| 289 | − ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_LOW_LIMIT, | |
| 290 | − value); | |
| 291 | − if (ret < 0) { | |
| 292 | − dev_err(opt->dev, "failed to write register %02x\n", | |
| 293 | − OPT3001_LOW_LIMIT); | |
| 294 | − return ret; | |
| 327 | + if (opt->use_irq) { | |
| 328 | + /* | |
| 329 | + * Disable the end-of-conversion interrupt mechanism by | |
| 330 | + * restoring the low-level limit value (clearing | |
| 331 | + * OPT3001_LOW_LIMIT_EOC_ENABLE). Note that selectively clearing | |
| 332 | + * those enable bits would affect the actual limit value due to | |
| 333 | + * bit-overlap and therefore can't be done. | |
| 334 | + */ | |
| 335 | + value = (opt->low_thresh_exp << 12) | opt->low_thresh_mantissa; | |
| 336 | + ret = i2c_smbus_write_word_swapped(opt->client, | |
| 337 | + OPT3001_LOW_LIMIT, | |
| 338 | + value); | |
| 339 | + if (ret < 0) { | |
| 340 | + dev_err(opt->dev, "failed to write register %02x\n", | |
| 341 | + OPT3001_LOW_LIMIT); | |
| 342 | + return ret; | |
| 343 | + } | |
| 295 | 344 | } |
| 296 | 345 | |
| 297 | 346 | exponent = OPT3001_REG_EXPONENT(opt->result); |
| @@ -325,13 +374,13 @@ static int opt3001_set_int_time(struct opt3001 *opt, int time) · 27 unmodified lines | ||
| 325 | 374 | reg = ret; |
| 326 | 375 | |
| 327 | 376 | switch (time) { |
| 328 | − case 100000: | |
| 377 | + case OPT3001_INT_TIME_SHORT: | |
| 329 | 378 | reg &= ~OPT3001_CONFIGURATION_CT; |
| 330 | − opt->int_time = 100000; | |
| 379 | + opt->int_time = OPT3001_INT_TIME_SHORT; | |
| 331 | 380 | break; |
| 332 | − case 800000: | |
| 381 | + case OPT3001_INT_TIME_LONG: | |
| 333 | 382 | reg |= OPT3001_CONFIGURATION_CT; |
| 334 | − opt->int_time = 800000; | |
| 383 | + opt->int_time = OPT3001_INT_TIME_LONG; | |
| 335 | 384 | break; |
| 336 | 385 | default: |
| 337 | 386 | return -EINVAL; |
| @@ -597,9 +646,9 @@ static int opt3001_configure(struct opt3001 *opt) · 259 unmodified lines | ||
| 597 | 646 | |
| 598 | 647 | /* Reflect status of the device's integration time setting */ |
| 599 | 648 | if (reg & OPT3001_CONFIGURATION_CT) |
| 600 | − opt->int_time = 800000; | |
| 649 | + opt->int_time = OPT3001_INT_TIME_LONG; | |
| 601 | 650 | else |
| 602 | − opt->int_time = 100000; | |
| 651 | + opt->int_time = OPT3001_INT_TIME_SHORT; | |
| 603 | 652 | |
| 604 | 653 | /* Ensure device is in shutdown initially */ |
| 605 | 654 | opt3001_set_mode(opt, ®, OPT3001_CONFIGURATION_M_SHUTDOWN); |
| @@ -733,12 +782,18 @@ static int opt3001_probe(struct i2c_client *client, · 127 unmodified lines | ||
| 733 | 782 | return ret; |
| 734 | 783 | } |
| 735 | 784 | |
| 736 | − ret = request_threaded_irq(irq, NULL, opt3001_irq, | |
| 737 | − IRQF_TRIGGER_FALLING | IRQF_ONESHOT, | |
| 738 | − "opt3001", iio); | |
| 739 | − if (ret) { | |
| 740 | − dev_err(dev, "failed to request IRQ #%d\n", irq); | |
| 741 | − return ret; | |
| 785 | + /* Make use of INT pin only if valid IRQ no. is given */ | |
| 786 | + if (irq > 0) { | |
| 787 | + ret = request_threaded_irq(irq, NULL, opt3001_irq, | |
| 788 | + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, | |
| 789 | + "opt3001", iio); | |
| 790 | + if (ret) { | |
| 791 | + dev_err(dev, "failed to request IRQ #%d\n", irq); | |
| 792 | + return ret; | |
| 793 | + } | |
| 794 | + opt->use_irq = true; | |
| 795 | + } else { | |
| 796 | + dev_dbg(opt->dev, "enabling interrupt-less operation\n"); | |
| 742 | 797 | } |
| 743 | 798 | |
| 744 | 799 | return 0; |
| @@ -751,7 +806,8 @@ static int opt3001_remove(struct i2c_client *client) · 6 unmodified lines | ||
| 751 | 806 | int ret; |
| 752 | 807 | u16 reg; |
| 753 | 808 | |
| 754 | − free_irq(client->irq, iio); | |
| 809 | + if (opt->use_irq) | |
| 810 | + free_irq(client->irq, iio); | |
| 755 | 811 | |
| 756 | 812 | ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); |
| 757 | 813 | if (ret < 0) { |
| @@ -252,7 +252,7 @@ struct ak_def { · 251 unmodified lines | ||
| 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,7 +360,7 @@ static struct ak_def ak_def_array[AK_MAX_TYPE] = { · 101 unmodified lines | ||
| 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]; |
| @@ -175,6 +175,8 @@ · 174 unmodified lines | ||
| 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 |
| @@ -480,6 +482,8 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = { · 299 unmodified lines | ||
| 480 | 482 | .drdy_irq = { |
| 481 | 483 | .addr = ST_MAGN_3_DRDY_IRQ_ADDR, |
| 482 | 484 | .mask_int1 = ST_MAGN_3_DRDY_INT_MASK, |
| 485 | + .addr_ihl = ST_MAGN_3_IHL_IRQ_ADDR, | |
| 486 | + .mask_ihl = ST_MAGN_3_IHL_IRQ_MASK, | |
| 483 | 487 | }, |
| 484 | 488 | .multi_read_bit = ST_MAGN_3_MULTIREAD_BIT, |
| 485 | 489 | .bootime = 2, |
| @@ -10,11 +10,11 @@ config BMP280 · 9 unmodified lines | ||
| 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,18 +27,33 @@ config HID_SENSOR_PRESS · 6 unmodified lines | ||
| 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" |
| @@ -49,8 +64,8 @@ config MPL3115 · 4 unmodified lines | ||
| 49 | 64 | Say yes here to build support for the Freescale MPL3115A2 |
| 50 | 65 | pressure sensor / altimeter. |
| 51 | 66 | |
| 52 | − To compile this driver as a module, choose M here: the module | |
| 53 | − will be called mpl3115. | |
| 67 | + To compile this driver as a module, choose M here: the module | |
| 68 | + will be called mpl3115. | |
| 54 | 69 | |
| 55 | 70 | config MS5611 |
| 56 | 71 | tristate "Measurement Specialties MS5611 pressure sensor driver" |
| @@ -82,7 +97,7 @@ config MS5611_SPI · 25 unmodified lines | ||
| 82 | 97 | config MS5637 |
| 83 | 98 | tristate "Measurement Specialties MS5637 pressure & temperature sensor" |
| 84 | 99 | depends on I2C |
| 85 | − select IIO_MS_SENSORS_I2C | |
| 100 | + select IIO_MS_SENSORS_I2C | |
| 86 | 101 | help |
| 87 | 102 | If you say yes here you get support for the Measurement Specialties |
| 88 | 103 | MS5637 pressure and temperature sensor. |
| @@ -128,7 +143,7 @@ config T5403 · 39 unmodified lines | ||
| 128 | 143 | Say yes here to build support for the EPCOS T5403 pressure sensor |
| 129 | 144 | connected via I2C. |
| 130 | 145 | |
| 131 | − To compile this driver as a module, choose M here: the module | |
| 132 | − will be called t5403. | |
| 146 | + To compile this driver as a module, choose M here: the module | |
| 147 | + will be called t5403. | |
| 133 | 148 | |
| 134 | 149 | endmenu |
| @@ -6,6 +6,8 @@ · 5 unmodified lines | ||
| 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 |
| @@ -1,5 +1,5 @@ | ||
| 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,17 +7,16 @@ · 1 unmodified line | ||
| 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> |
| 20 | 17 | |
| 18 | +#include "mpl115.h" | |
| 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 */ |
| 23 | 22 | #define MPL115_A0 0x04 /* 12 bit integer, 3 bit fraction */ |
| @@ -27,16 +26,18 @@ · 3 unmodified lines | ||
| 27 | 26 | #define MPL115_CONVERT 0x12 /* convert temperature and pressure */ |
| 28 | 27 | |
| 29 | 28 | struct mpl115_data { |
| 30 | − struct i2c_client *client; | |
| 29 | + struct device *dev; | |
| 31 | 30 | struct mutex lock; |
| 32 | 31 | s16 a0; |
| 33 | 32 | s16 b1, b2; |
| 34 | 33 | s16 c12; |
| 34 | + const struct mpl115_ops *ops; | |
| 35 | 35 | }; |
| 36 | 36 | |
| 37 | 37 | static int mpl115_request(struct mpl115_data *data) |
| 38 | 38 | { |
| 39 | − int ret = i2c_smbus_write_byte_data(data->client, MPL115_CONVERT, 0); | |
| 39 | + int ret = data->ops->write(data->dev, MPL115_CONVERT, 0); | |
| 40 | + | |
| 40 | 41 | if (ret < 0) |
| 41 | 42 | return ret; |
| 42 | 43 | |
| @@ -57,12 +58,12 @@ static int mpl115_comp_pressure(struct mpl115_data *data, int *val, int *val2) · 14 unmodified lines | ||
| 57 | 58 | if (ret < 0) |
| 58 | 59 | goto done; |
| 59 | 60 | |
| 60 | − ret = i2c_smbus_read_word_swapped(data->client, MPL115_PADC); | |
| 61 | + ret = data->ops->read(data->dev, MPL115_PADC); | |
| 61 | 62 | if (ret < 0) |
| 62 | 63 | goto done; |
| 63 | 64 | padc = ret >> 6; |
| 64 | 65 | |
| 65 | − ret = i2c_smbus_read_word_swapped(data->client, MPL115_TADC); | |
| 66 | + ret = data->ops->read(data->dev, MPL115_TADC); | |
| 66 | 67 | if (ret < 0) |
| 67 | 68 | goto done; |
| 68 | 69 | tadc = ret >> 6; |
| @@ -90,7 +91,7 @@ static int mpl115_read_temp(struct mpl115_data *data) · 21 unmodified lines | ||
| 90 | 91 | ret = mpl115_request(data); |
| 91 | 92 | if (ret < 0) |
| 92 | 93 | goto done; |
| 93 | − ret = i2c_smbus_read_word_swapped(data->client, MPL115_TADC); | |
| 94 | + ret = data->ops->read(data->dev, MPL115_TADC); | |
| 94 | 95 | done: |
| 95 | 96 | mutex_unlock(&data->lock); |
| 96 | 97 | return ret; |
| @@ -145,66 +146,53 @@ static const struct iio_info mpl115_info = { · 48 unmodified lines | ||
| 145 | 146 | .driver_module = THIS_MODULE, |
| 146 | 147 | }; |
| 147 | 148 | |
| 148 | −static int mpl115_probe(struct i2c_client *client, | |
| 149 | − const struct i2c_device_id *id) | |
| 149 | +int mpl115_probe(struct device *dev, const char *name, | |
| 150 | + const struct mpl115_ops *ops) | |
| 150 | 151 | { |
| 151 | 152 | struct mpl115_data *data; |
| 152 | 153 | struct iio_dev *indio_dev; |
| 153 | 154 | int ret; |
| 154 | 155 | |
| 155 | − if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) | |
| 156 | − return -ENODEV; | |
| 157 | − | |
| 158 | − indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); | |
| 156 | + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); | |
| 159 | 157 | if (!indio_dev) |
| 160 | 158 | return -ENOMEM; |
| 161 | 159 | |
| 162 | 160 | data = iio_priv(indio_dev); |
| 163 | − data->client = client; | |
| 161 | + data->dev = dev; | |
| 162 | + data->ops = ops; | |
| 164 | 163 | mutex_init(&data->lock); |
| 165 | 164 | |
| 166 | − i2c_set_clientdata(client, indio_dev); | |
| 167 | 165 | indio_dev->info = &mpl115_info; |
| 168 | − indio_dev->name = id->name; | |
| 169 | − indio_dev->dev.parent = &client->dev; | |
| 166 | + indio_dev->name = name; | |
| 167 | + indio_dev->dev.parent = dev; | |
| 170 | 168 | indio_dev->modes = INDIO_DIRECT_MODE; |
| 171 | 169 | indio_dev->channels = mpl115_channels; |
| 172 | 170 | indio_dev->num_channels = ARRAY_SIZE(mpl115_channels); |
| 173 | 171 | |
| 174 | − ret = i2c_smbus_read_word_swapped(data->client, MPL115_A0); | |
| 172 | + ret = data->ops->init(data->dev); | |
| 173 | + if (ret) | |
| 174 | + return ret; | |
| 175 | + | |
| 176 | + ret = data->ops->read(data->dev, MPL115_A0); | |
| 175 | 177 | if (ret < 0) |
| 176 | 178 | return ret; |
| 177 | 179 | data->a0 = ret; |
| 178 | − ret = i2c_smbus_read_word_swapped(data->client, MPL115_B1); | |
| 180 | + ret = data->ops->read(data->dev, MPL115_B1); | |
| 179 | 181 | if (ret < 0) |
| 180 | 182 | return ret; |
| 181 | 183 | data->b1 = ret; |
| 182 | − ret = i2c_smbus_read_word_swapped(data->client, MPL115_B2); | |
| 184 | + ret = data->ops->read(data->dev, MPL115_B2); | |
| 183 | 185 | if (ret < 0) |
| 184 | 186 | return ret; |
| 185 | 187 | data->b2 = ret; |
| 186 | − ret = i2c_smbus_read_word_swapped(data->client, MPL115_C12); | |
| 188 | + ret = data->ops->read(data->dev, MPL115_C12); | |
| 187 | 189 | if (ret < 0) |
| 188 | 190 | return ret; |
| 189 | 191 | data->c12 = ret; |
| 190 | 192 | |
| 191 | − return devm_iio_device_register(&client->dev, indio_dev); | |
| 193 | + return devm_iio_device_register(dev, indio_dev); | |
| 192 | 194 | } |
| 193 | − | |
| 194 | −static const struct i2c_device_id mpl115_id[] = { | |
| 195 | − { "mpl115", 0 }, | |
| 196 | − { } | |
| 197 | −}; | |
| 198 | −MODULE_DEVICE_TABLE(i2c, mpl115_id); | |
| 199 | − | |
| 200 | −static struct i2c_driver mpl115_driver = { | |
| 201 | − .driver = { | |
| 202 | − .name = "mpl115", | |
| 203 | − }, | |
| 204 | − .probe = mpl115_probe, | |
| 205 | − .id_table = mpl115_id, | |
| 206 | −}; | |
| 207 | −module_i2c_driver(mpl115_driver); | |
| 195 | +EXPORT_SYMBOL_GPL(mpl115_probe); | |
| 208 | 196 | |
| 209 | 197 | MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>"); |
| 210 | 198 | MODULE_DESCRIPTION("Freescale MPL115 pressure/temperature driver"); |
| @@ -0,0 +1,24 @@ | ||
| 1 | +/* | |
| 2 | + * Freescale MPL115A pressure/temperature sensor | |
| 3 | + * | |
| 4 | + * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net> | |
| 5 | + * Copyright (c) 2016 Akinobu Mita <akinobu.mita@gmail.com> | |
| 6 | + * | |
| 7 | + * This file is subject to the terms and conditions of version 2 of | |
| 8 | + * the GNU General Public License. See the file COPYING in the main | |
| 9 | + * directory of this archive for more details. | |
| 10 | + */ | |
| 11 | + | |
| 12 | +#ifndef _MPL115_H_ | |
| 13 | +#define _MPL115_H_ | |
| 14 | + | |
| 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 | |
| @@ -0,0 +1,67 @@ | ||
| 1 | +/* | |
| 2 | + * Freescale MPL115A2 pressure/temperature sensor | |
| 3 | + * | |
| 4 | + * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net> | |
| 5 | + * | |
| 6 | + * This file is subject to the terms and conditions of version 2 of | |
| 7 | + * the GNU General Public License. See the file COPYING in the main | |
| 8 | + * directory of this archive for more details. | |
| 9 | + * | |
| 10 | + * (7-bit I2C slave address 0x60) | |
| 11 | + * | |
| 12 | + * Datasheet: http://www.nxp.com/files/sensors/doc/data_sheet/MPL115A2.pdf | |
| 13 | + */ | |
| 14 | + | |
| 15 | +#include <linux/module.h> | |
| 16 | +#include <linux/i2c.h> | |
| 17 | + | |
| 18 | +#include "mpl115.h" | |
| 19 | + | |
| 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"); | |
| @@ -0,0 +1,106 @@ | ||
| 1 | +/* | |
| 2 | + * Freescale MPL115A1 pressure/temperature sensor | |
| 3 | + * | |
| 4 | + * Copyright (c) 2016 Akinobu Mita <akinobu.mita@gmail.com> | |
| 5 | + * | |
| 6 | + * This file is subject to the terms and conditions of version 2 of | |
| 7 | + * the GNU General Public License. See the file COPYING in the main | |
| 8 | + * directory of this archive for more details. | |
| 9 | + * | |
| 10 | + * Datasheet: http://www.nxp.com/files/sensors/doc/data_sheet/MPL115A1.pdf | |
| 11 | + */ | |
| 12 | + | |
| 13 | +#include <linux/module.h> | |
| 14 | +#include <linux/spi/spi.h> | |
| 15 | + | |
| 16 | +#include "mpl115.h" | |
| 17 | + | |
| 18 | +#define MPL115_SPI_WRITE(address) ((address) << 1) | |
| 19 | +#define MPL115_SPI_READ(address) (0x80 | (address) << 1) | |
| 20 | + | |
| 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"); | |
| @@ -62,6 +62,8 @@ · 61 unmodified lines | ||
| 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 | |
| @@ -100,6 +102,8 @@ · 32 unmodified lines | ||
| 100 | 102 | #define ST_PRESS_LPS25H_DRDY_IRQ_ADDR 0x23 |
| 101 | 103 | #define ST_PRESS_LPS25H_DRDY_IRQ_INT1_MASK 0x01 |
| 102 | 104 | #define ST_PRESS_LPS25H_DRDY_IRQ_INT2_MASK 0x10 |
| 105 | +#define ST_PRESS_LPS25H_IHL_IRQ_ADDR 0x22 | |
| 106 | +#define ST_PRESS_LPS25H_IHL_IRQ_MASK 0x80 | |
| 103 | 107 | #define ST_PRESS_LPS25H_MULTIREAD_BIT true |
| 104 | 108 | #define ST_PRESS_LPS25H_TEMP_OFFSET 42500 |
| 105 | 109 | #define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28 |
| @@ -220,6 +224,8 @@ static const struct st_sensor_settings st_press_sensors_settings[] = { · 114 unmodified lines | ||
| 220 | 224 | .addr = ST_PRESS_LPS331AP_DRDY_IRQ_ADDR, |
| 221 | 225 | .mask_int1 = ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK, |
| 222 | 226 | .mask_int2 = ST_PRESS_LPS331AP_DRDY_IRQ_INT2_MASK, |
| 227 | + .addr_ihl = ST_PRESS_LPS331AP_IHL_IRQ_ADDR, | |
| 228 | + .mask_ihl = ST_PRESS_LPS331AP_IHL_IRQ_MASK, | |
| 223 | 229 | }, |
| 224 | 230 | .multi_read_bit = ST_PRESS_LPS331AP_MULTIREAD_BIT, |
| 225 | 231 | .bootime = 2, |
| @@ -304,6 +310,8 @@ static const struct st_sensor_settings st_press_sensors_settings[] = { · 78 unmodified lines | ||
| 304 | 310 | .addr = ST_PRESS_LPS25H_DRDY_IRQ_ADDR, |
| 305 | 311 | .mask_int1 = ST_PRESS_LPS25H_DRDY_IRQ_INT1_MASK, |
| 306 | 312 | .mask_int2 = ST_PRESS_LPS25H_DRDY_IRQ_INT2_MASK, |
| 313 | + .addr_ihl = ST_PRESS_LPS25H_IHL_IRQ_ADDR, | |
| 314 | + .mask_ihl = ST_PRESS_LPS25H_IHL_IRQ_MASK, | |
| 307 | 315 | }, |
| 308 | 316 | .multi_read_bit = ST_PRESS_LPS25H_MULTIREAD_BIT, |
| 309 | 317 | .bootime = 2, |
| @@ -1,31 +1,3 @@ | ||
| 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 |
| @@ -236,7 +236,7 @@ static int ad7192_setup(struct ad7192_state *st, · 235 unmodified lines | ||
| 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; |
| @@ -21,8 +21,8 @@ · 20 unmodified lines | ||
| 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,7 +36,7 @@ · 7 unmodified lines | ||
| 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,8 +160,9 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev, · 117 unmodified lines | ||
| 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; |
| @@ -209,8 +210,9 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, · 41 unmodified lines | ||
| 209 | 210 | } |
| 210 | 211 | |
| 211 | 212 | static int ad7150_write_event_config(struct iio_dev *indio_dev, |
| 212 | − const struct iio_chan_spec *chan, enum iio_event_type type, | |
| 213 | − enum iio_event_direction dir, int state) | |
| 213 | + const struct iio_chan_spec *chan, | |
| 214 | + enum iio_event_type type, | |
| 215 | + enum iio_event_direction dir, int state) | |
| 214 | 216 | { |
| 215 | 217 | u8 thresh_type, cfg, adaptive; |
| 216 | 218 | int ret; |
| @@ -302,11 +304,11 @@ static int ad7150_read_event_value(struct iio_dev *indio_dev, · 85 unmodified lines | ||
| 302 | 304 | } |
| 303 | 305 | |
| 304 | 306 | static int ad7150_write_event_value(struct iio_dev *indio_dev, |
| 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) | |
| 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) | |
| 310 | 312 | { |
| 311 | 313 | int ret; |
| 312 | 314 | struct ad7150_chip_info *chip = iio_priv(indio_dev); |
| @@ -365,9 +367,9 @@ static ssize_t ad7150_show_timeout(struct device *dev, · 52 unmodified lines | ||
| 365 | 367 | } |
| 366 | 368 | |
| 367 | 369 | static ssize_t ad7150_store_timeout(struct device *dev, |
| 368 | − struct device_attribute *attr, | |
| 369 | − const char *buf, | |
| 370 | − size_t len) | |
| 370 | + struct device_attribute *attr, | |
| 371 | + const char *buf, | |
| 372 | + size_t len) | |
| 371 | 373 | { |
| 372 | 374 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
| 373 | 375 | struct ad7150_chip_info *chip = iio_priv(indio_dev); |
| @@ -580,7 +582,7 @@ static const struct iio_info ad7150_info = { · 206 unmodified lines | ||
| 580 | 582 | */ |
| 581 | 583 | |
| 582 | 584 | static int ad7150_probe(struct i2c_client *client, |
| 583 | − const struct i2c_device_id *id) | |
| 585 | + const struct i2c_device_id *id) | |
| 584 | 586 | { |
| 585 | 587 | int ret; |
| 586 | 588 | struct ad7150_chip_info *chip; |
| @@ -119,6 +119,8 @@ struct st_sensor_bdu { · 118 unmodified lines | ||
| 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. |
| @@ -127,6 +129,8 @@ struct st_sensor_data_ready_irq { · 2 unmodified lines | ||
| 127 | 129 | u8 addr; |
| 128 | 130 | u8 mask_int1; |
| 129 | 131 | u8 mask_int2; |
| 132 | + u8 addr_ihl; | |
| 133 | + u8 mask_ihl; | |
| 130 | 134 | struct { |
| 131 | 135 | u8 en_addr; |
| 132 | 136 | u8 en_mask; |
| @@ -0,0 +1,44 @@ | ||
| 1 | +/* | |
| 2 | + * AD5721, AD5721R, AD5761, AD5761R, Voltage Output Digital to Analog Converter | |
| 3 | + * | |
| 4 | + * Copyright 2016 Qtechnology A/S | |
| 5 | + * 2016 Ricardo Ribalda <ricardo.ribalda@gmail.com> | |
| 6 | + * | |
| 7 | + * Licensed under the GPL-2. | |
| 8 | + */ | |
| 9 | +#ifndef __LINUX_PLATFORM_DATA_AD5761_H__ | |
| 10 | +#define __LINUX_PLATFORM_DATA_AD5761_H__ | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * enum ad5761_voltage_range - Voltage range the AD5761 is configured for. | |
| 14 | + * @AD5761_VOLTAGE_RANGE_M10V_10V: -10V to 10V | |
| 15 | + * @AD5761_VOLTAGE_RANGE_0V_10V: 0V to 10V | |
| 16 | + * @AD5761_VOLTAGE_RANGE_M5V_5V: -5V to 5V | |
| 17 | + * @AD5761_VOLTAGE_RANGE_0V_5V: 0V to 5V | |
| 18 | + * @AD5761_VOLTAGE_RANGE_M2V5_7V5: -2.5V to 7.5V | |
| 19 | + * @AD5761_VOLTAGE_RANGE_M3V_3V: -3V to 3V | |
| 20 | + * @AD5761_VOLTAGE_RANGE_0V_16V: 0V to 16V | |
| 21 | + * @AD5761_VOLTAGE_RANGE_0V_20V: 0V to 20V | |
| 22 | + */ | |
| 23 | + | |
| 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 | |
| @@ -37,6 +37,7 @@ enum iio_chan_type { · 36 unmodified lines | ||
| 37 | 37 | IIO_VELOCITY, |
| 38 | 38 | IIO_CONCENTRATION, |
| 39 | 39 | IIO_RESISTANCE, |
| 40 | + IIO_PH, | |
| 40 | 41 | }; |
| 41 | 42 | |
| 42 | 43 | enum iio_modifier { |