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

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

Jonathan writes:

Second round of IIO new device support, cleanups and features for the 4.11 cycle

New device support:
* lsm6dsx imu
- new driver and bindings.
* max11100 adc
- new driver and bindings.
* tlc4541
- new driver
* tmp007 thermopile
- new driver.

Core
* in kernel interfaces
- pass through raw values if no scaling provided and a processed value is
requested.
* trigger
- close a race condition in acquiring trigger reference.
- constify device_type structures.
- rework the viio_trigger_alloc function to be much neater and easier to
read.
- free trigger resources correctly on some error paths. Avoids putting a
module we don't have.

Documentation
* ABI
- specify a unit for proximity measurements.

Cleanups and features
* ads1015
- constify iio_info structure.
* ads7950 cleanups following merge in previous pull
- Add device tree bindings
- Drop the ti prefix from the module name in common with other drivers.
- Change regulator name to vref to match datasheet and other drivers.
* ak8974
- remove a redundant zero timeout check.
* bmi160
- use variable names for sizeof instead of types.
* cm3605
- mark PM functions as __maybe_unused to avoid a build warning.
* isl29028 (on it's way towards moving out of staging).
- alignment fixes and newline improvements.
- combine proxim_get and read_proxim for simpler code.
- drop unused ISL29028_DEV_ATTR macro
- move some error logging into functions to cut out repitition.
- make error messages more consistent.
- tidy up some brackets.
- drop the enable flag that nothing uses.
- only set proximity rate and ALS scale when relevant channel type is enabled.
- runtime pm support.
* lsm6dsx
- fix wrong values for gyro sensitivitiy.
* mag3110
- claim direct mode during sysfs reads to avoid a race condition.
* max1363
- export OF device table IDs as module aliases.
* max30100
- use msleep for long uncritical delays.
* mcp4531
- export OF device table as module aliases.
* ms5611
- claim direct mode during sysfs reads to avoid a race condition.
* opt3001
- export OF device table as module aliases.
* sx9500
- claim direct mode during oversampling changes to avoid a race condition.

+2799 -214
+2 -1
Documentation/ABI/testing/sysfs-bus-iio
··· 1255 1255 reflectivity of infrared or ultrasound emitted. 1256 1256 Often these sensors are unit less and as such conversion 1257 1257 to SI units is not possible. Higher proximity measurements 1258 - indicate closer objects, and vice versa. 1258 + indicate closer objects, and vice versa. Units after 1259 + application of scale and offset are meters. 1259 1260 1260 1261 What: /sys/.../iio:deviceX/in_illuminance_input 1261 1262 What: /sys/.../iio:deviceX/in_illuminance_raw
+18
Documentation/devicetree/bindings/iio/adc/max11100.txt
··· 1 + * Maxim max11100 Analog to Digital Converter (ADC) 2 + 3 + Required properties: 4 + - compatible: Should be "maxim,max11100" 5 + - reg: the adc unit address 6 + - vref-supply: phandle to the regulator that provides reference voltage 7 + 8 + Optional properties: 9 + - spi-max-frequency: SPI maximum frequency 10 + 11 + Example: 12 + 13 + max11100: adc@0 { 14 + compatible = "maxim,max11100"; 15 + reg = <0>; 16 + vref-supply = <&adc0_vref>; 17 + spi-max-frequency = <240000>; 18 + };
+23
Documentation/devicetree/bindings/iio/adc/ti-ads7950.txt
··· 1 + * Texas Instruments ADS7950 family of A/DC chips 2 + 3 + Required properties: 4 + - compatible: Must be one of "ti,ads7950", "ti,ads7951", "ti,ads7952", 5 + "ti,ads7953", "ti,ads7954", "ti,ads7955", "ti,ads7956", "ti,ads7957", 6 + "ti,ads7958", "ti,ads7959", "ti,ads7960", or "ti,ads7961" 7 + - reg: SPI chip select number for the device 8 + - #io-channel-cells: Must be 1 as per ../iio-bindings.txt 9 + - vref-supply: phandle to a regulator node that supplies the 2.5V or 5V 10 + reference voltage 11 + 12 + Recommended properties: 13 + - spi-max-frequency: Definition as per 14 + Documentation/devicetree/bindings/spi/spi-bus.txt 15 + 16 + Example: 17 + adc@0 { 18 + compatible = "ti,ads7957"; 19 + reg = <0>; 20 + #io-channel-cells = <1>; 21 + vref-supply = <&refin_supply>; 22 + spi-max-frequency = <10000000>; 23 + };
+24
Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
··· 1 + * ST_LSM6DSx driver for STM 6-axis (acc + gyro) imu Mems sensors 2 + 3 + Required properties: 4 + - compatible: must be one of: 5 + "st,lsm6ds3" 6 + "st,lsm6dsm" 7 + - reg: i2c address of the sensor / spi cs line 8 + 9 + Optional properties: 10 + - interrupt-parent: should be the phandle for the interrupt controller 11 + - interrupts: interrupt mapping for IRQ. It should be configured with 12 + flags IRQ_TYPE_LEVEL_HIGH or IRQ_TYPE_EDGE_RISING. 13 + 14 + Refer to interrupt-controller/interrupts.txt for generic interrupt 15 + client node bindings. 16 + 17 + Example: 18 + 19 + lsm6dsm@6b { 20 + compatible = "st,lsm6dsm"; 21 + reg = <0x6b>; 22 + interrupt-parent = <&gpio0>; 23 + interrupts = <0 IRQ_TYPE_EDGE_RISING>; 24 + };
+27
Documentation/devicetree/bindings/iio/temperature/tmp007.txt
··· 1 + * TI TMP007 - IR thermopile sensor with integrated math engine 2 + 3 + Link to datasheet: http://www.ti.com/lit/ds/symlink/tmp007.pdf 4 + 5 + Required properties: 6 + 7 + - compatible: should be "ti,tmp007" 8 + - reg: the I2C address of the sensor (changeable via ADR pins) 9 + ------------------------------ 10 + |ADR1 | ADR0 | Device Address| 11 + ------------------------------ 12 + 0 0 0x40 13 + 0 1 0x41 14 + 0 SDA 0x42 15 + 0 SCL 0x43 16 + 1 0 0x44 17 + 1 1 0x45 18 + 1 SDA 0x46 19 + 1 SCL 0x47 20 + 21 + Example: 22 + 23 + tmp007@40 { 24 + compatible = "ti,tmp007"; 25 + reg = <0x40>; 26 + }; 27 +
+21
drivers/iio/adc/Kconfig
··· 326 326 To compile this driver as a module, choose M here: the module will be 327 327 called max1027. 328 328 329 + config MAX11100 330 + tristate "Maxim max11100 ADC driver" 331 + depends on SPI_MASTER 332 + help 333 + Say yes here to build support for Maxim max11100 SPI ADC 334 + 335 + To compile this driver as a module, choose M here: the module will be 336 + called max11100. 337 + 329 338 config MAX1363 330 339 tristate "Maxim max1363 ADC driver" 331 340 depends on I2C ··· 611 602 612 603 To compile this driver as a module, choose M here: the module will be 613 604 called ti_am335x_adc. 605 + 606 + config TI_TLC4541 607 + tristate "Texas Instruments TLC4541 ADC driver" 608 + depends on SPI 609 + select IIO_BUFFER 610 + select IIO_TRIGGERED_BUFFER 611 + help 612 + Say yes here to build support for Texas Instruments TLC4541 / TLC3541 613 + ADC chips. 614 + 615 + This driver can also be built as a module. If so, the module will be 616 + called ti-tlc4541. 614 617 615 618 config TWL4030_MADC 616 619 tristate "TWL4030 MADC (Monitoring A/D Converter)"
+2
drivers/iio/adc/Makefile
··· 32 32 obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o 33 33 obj-$(CONFIG_LTC2485) += ltc2485.o 34 34 obj-$(CONFIG_MAX1027) += max1027.o 35 + obj-$(CONFIG_MAX11100) += max11100.o 35 36 obj-$(CONFIG_MAX1363) += max1363.o 36 37 obj-$(CONFIG_MCP320X) += mcp320x.o 37 38 obj-$(CONFIG_MCP3422) += mcp3422.o ··· 56 55 obj-$(CONFIG_TI_ADS7950) += ti-ads7950.o 57 56 obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o 58 57 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o 58 + obj-$(CONFIG_TI_TLC4541) += ti-tlc4541.o 59 59 obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o 60 60 obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o 61 61 obj-$(CONFIG_VF610_ADC) += vf610_adc.o
+181
drivers/iio/adc/max11100.c
··· 1 + /* 2 + * iio/adc/max11100.c 3 + * Maxim max11100 ADC Driver with IIO interface 4 + * 5 + * Copyright (C) 2016-17 Renesas Electronics Corporation 6 + * Copyright (C) 2016-17 Jacopo Mondi 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 as 10 + * published by the Free Software Foundation. 11 + */ 12 + #include <linux/delay.h> 13 + #include <linux/kernel.h> 14 + #include <linux/module.h> 15 + #include <linux/regulator/consumer.h> 16 + #include <linux/spi/spi.h> 17 + 18 + #include <linux/iio/iio.h> 19 + #include <linux/iio/driver.h> 20 + 21 + /* 22 + * LSB is the ADC single digital step 23 + * 1 LSB = (vref_mv / 2 ^ 16) 24 + * 25 + * LSB is used to calculate analog voltage value 26 + * from the number of ADC steps count 27 + * 28 + * Ain = (count * LSB) 29 + */ 30 + #define MAX11100_LSB_DIV (1 << 16) 31 + 32 + struct max11100_state { 33 + struct regulator *vref_reg; 34 + struct spi_device *spi; 35 + 36 + /* 37 + * DMA (thus cache coherency maintenance) requires the 38 + * transfer buffers to live in their own cache lines. 39 + */ 40 + u8 buffer[3] ____cacheline_aligned; 41 + }; 42 + 43 + static struct iio_chan_spec max11100_channels[] = { 44 + { /* [0] */ 45 + .type = IIO_VOLTAGE, 46 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 47 + BIT(IIO_CHAN_INFO_SCALE), 48 + }, 49 + }; 50 + 51 + static int max11100_read_single(struct iio_dev *indio_dev, int *val) 52 + { 53 + int ret; 54 + struct max11100_state *state = iio_priv(indio_dev); 55 + 56 + ret = spi_read(state->spi, state->buffer, sizeof(state->buffer)); 57 + if (ret) { 58 + dev_err(&indio_dev->dev, "SPI transfer failed\n"); 59 + return ret; 60 + } 61 + 62 + /* the first 8 bits sent out from ADC must be 0s */ 63 + if (state->buffer[0]) { 64 + dev_err(&indio_dev->dev, "Invalid value: buffer[0] != 0\n"); 65 + return -EINVAL; 66 + } 67 + 68 + *val = (state->buffer[1] << 8) | state->buffer[2]; 69 + 70 + return 0; 71 + } 72 + 73 + static int max11100_read_raw(struct iio_dev *indio_dev, 74 + struct iio_chan_spec const *chan, 75 + int *val, int *val2, long info) 76 + { 77 + int ret, vref_uv; 78 + struct max11100_state *state = iio_priv(indio_dev); 79 + 80 + switch (info) { 81 + case IIO_CHAN_INFO_RAW: 82 + ret = max11100_read_single(indio_dev, val); 83 + if (ret) 84 + return ret; 85 + 86 + return IIO_VAL_INT; 87 + 88 + case IIO_CHAN_INFO_SCALE: 89 + vref_uv = regulator_get_voltage(state->vref_reg); 90 + if (vref_uv < 0) 91 + /* dummy regulator "get_voltage" returns -EINVAL */ 92 + return -EINVAL; 93 + 94 + *val = vref_uv / 1000; 95 + *val2 = MAX11100_LSB_DIV; 96 + return IIO_VAL_FRACTIONAL; 97 + } 98 + 99 + return -EINVAL; 100 + } 101 + 102 + static const struct iio_info max11100_info = { 103 + .driver_module = THIS_MODULE, 104 + .read_raw = max11100_read_raw, 105 + }; 106 + 107 + static int max11100_probe(struct spi_device *spi) 108 + { 109 + int ret; 110 + struct iio_dev *indio_dev; 111 + struct max11100_state *state; 112 + 113 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*state)); 114 + if (!indio_dev) 115 + return -ENOMEM; 116 + 117 + spi_set_drvdata(spi, indio_dev); 118 + 119 + state = iio_priv(indio_dev); 120 + state->spi = spi; 121 + 122 + indio_dev->dev.parent = &spi->dev; 123 + indio_dev->dev.of_node = spi->dev.of_node; 124 + indio_dev->name = "max11100"; 125 + indio_dev->info = &max11100_info; 126 + indio_dev->modes = INDIO_DIRECT_MODE; 127 + indio_dev->channels = max11100_channels, 128 + indio_dev->num_channels = ARRAY_SIZE(max11100_channels), 129 + 130 + state->vref_reg = devm_regulator_get(&spi->dev, "vref"); 131 + if (IS_ERR(state->vref_reg)) 132 + return PTR_ERR(state->vref_reg); 133 + 134 + ret = regulator_enable(state->vref_reg); 135 + if (ret) 136 + return ret; 137 + 138 + ret = iio_device_register(indio_dev); 139 + if (ret) 140 + goto disable_regulator; 141 + 142 + return 0; 143 + 144 + disable_regulator: 145 + regulator_disable(state->vref_reg); 146 + 147 + return ret; 148 + } 149 + 150 + static int max11100_remove(struct spi_device *spi) 151 + { 152 + struct iio_dev *indio_dev = spi_get_drvdata(spi); 153 + struct max11100_state *state = iio_priv(indio_dev); 154 + 155 + iio_device_unregister(indio_dev); 156 + regulator_disable(state->vref_reg); 157 + 158 + return 0; 159 + } 160 + 161 + static const struct of_device_id max11100_ids[] = { 162 + {.compatible = "maxim,max11100"}, 163 + { }, 164 + }; 165 + MODULE_DEVICE_TABLE(of, max11100_ids); 166 + 167 + static struct spi_driver max11100_driver = { 168 + .driver = { 169 + .name = "max11100", 170 + .owner = THIS_MODULE, 171 + .of_match_table = of_match_ptr(max11100_ids), 172 + }, 173 + .probe = max11100_probe, 174 + .remove = max11100_remove, 175 + }; 176 + 177 + module_spi_driver(max11100_driver); 178 + 179 + MODULE_AUTHOR("Jacopo Mondi <jacopo@jmondi.org>"); 180 + MODULE_DESCRIPTION("Maxim max11100 ADC Driver"); 181 + MODULE_LICENSE("GPL v2");
+1
drivers/iio/adc/max1363.c
··· 1567 1567 MAX1363_COMPATIBLE("maxim,max11647", max11647), 1568 1568 { /* sentinel */ } 1569 1569 }; 1570 + MODULE_DEVICE_TABLE(of, max1363_of_match); 1570 1571 #endif 1571 1572 1572 1573 static int max1363_probe(struct i2c_client *client,
+2 -2
drivers/iio/adc/ti-ads1015.c
··· 472 472 .attrs = ads1115_attributes, 473 473 }; 474 474 475 - static struct iio_info ads1015_info = { 475 + static const struct iio_info ads1015_info = { 476 476 .driver_module = THIS_MODULE, 477 477 .read_raw = ads1015_read_raw, 478 478 .write_raw = ads1015_write_raw, 479 479 .attrs = &ads1015_attribute_group, 480 480 }; 481 481 482 - static struct iio_info ads1115_info = { 482 + static const struct iio_info ads1115_info = { 483 483 .driver_module = THIS_MODULE, 484 484 .read_raw = ads1015_read_raw, 485 485 .write_raw = ads1015_write_raw,
+16 -16
drivers/iio/adc/ti-ads7950.c
··· 411 411 spi_message_init_with_transfers(&st->scan_single_msg, 412 412 st->scan_single_xfer, 3); 413 413 414 - st->reg = devm_regulator_get(&spi->dev, "refin"); 414 + st->reg = devm_regulator_get(&spi->dev, "vref"); 415 415 if (IS_ERR(st->reg)) { 416 - dev_err(&spi->dev, "Failed get get regulator \"refin\"\n"); 416 + dev_err(&spi->dev, "Failed get get regulator \"vref\"\n"); 417 417 return PTR_ERR(st->reg); 418 418 } 419 419 420 420 ret = regulator_enable(st->reg); 421 421 if (ret) { 422 - dev_err(&spi->dev, "Failed to enable regulator \"refin\"\n"); 422 + dev_err(&spi->dev, "Failed to enable regulator \"vref\"\n"); 423 423 return ret; 424 424 } 425 425 ··· 459 459 } 460 460 461 461 static const struct spi_device_id ti_ads7950_id[] = { 462 - {"ti-ads7950", TI_ADS7950}, 463 - {"ti-ads7951", TI_ADS7951}, 464 - {"ti-ads7952", TI_ADS7952}, 465 - {"ti-ads7953", TI_ADS7953}, 466 - {"ti-ads7954", TI_ADS7954}, 467 - {"ti-ads7955", TI_ADS7955}, 468 - {"ti-ads7956", TI_ADS7956}, 469 - {"ti-ads7957", TI_ADS7957}, 470 - {"ti-ads7958", TI_ADS7958}, 471 - {"ti-ads7959", TI_ADS7959}, 472 - {"ti-ads7960", TI_ADS7960}, 473 - {"ti-ads7961", TI_ADS7961}, 462 + { "ads7950", TI_ADS7950 }, 463 + { "ads7951", TI_ADS7951 }, 464 + { "ads7952", TI_ADS7952 }, 465 + { "ads7953", TI_ADS7953 }, 466 + { "ads7954", TI_ADS7954 }, 467 + { "ads7955", TI_ADS7955 }, 468 + { "ads7956", TI_ADS7956 }, 469 + { "ads7957", TI_ADS7957 }, 470 + { "ads7958", TI_ADS7958 }, 471 + { "ads7959", TI_ADS7959 }, 472 + { "ads7960", TI_ADS7960 }, 473 + { "ads7961", TI_ADS7961 }, 474 474 { } 475 475 }; 476 476 MODULE_DEVICE_TABLE(spi, ti_ads7950_id); 477 477 478 478 static struct spi_driver ti_ads7950_driver = { 479 479 .driver = { 480 - .name = "ti-ads7950", 480 + .name = "ads7950", 481 481 }, 482 482 .probe = ti_ads7950_probe, 483 483 .remove = ti_ads7950_remove,
+271
drivers/iio/adc/ti-tlc4541.c
··· 1 + /* 2 + * TI tlc4541 ADC Driver 3 + * 4 + * Copyright (C) 2017 Phil Reid 5 + * 6 + * Datasheets can be found here: 7 + * http://www.ti.com/lit/gpn/tlc3541 8 + * http://www.ti.com/lit/gpn/tlc4541 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License version 2 as 12 + * published by the Free Software Foundation. 13 + * 14 + * The tlc4541 requires 24 clock cycles to start a transfer. 15 + * Conversion then takes 2.94us to complete before data is ready 16 + * Data is returned MSB first. 17 + */ 18 + 19 + #include <linux/delay.h> 20 + #include <linux/device.h> 21 + #include <linux/err.h> 22 + #include <linux/interrupt.h> 23 + #include <linux/iio/iio.h> 24 + #include <linux/iio/sysfs.h> 25 + #include <linux/iio/buffer.h> 26 + #include <linux/iio/trigger_consumer.h> 27 + #include <linux/iio/triggered_buffer.h> 28 + #include <linux/kernel.h> 29 + #include <linux/module.h> 30 + #include <linux/regulator/consumer.h> 31 + #include <linux/slab.h> 32 + #include <linux/spi/spi.h> 33 + #include <linux/sysfs.h> 34 + 35 + struct tlc4541_state { 36 + struct spi_device *spi; 37 + struct regulator *reg; 38 + struct spi_transfer scan_single_xfer[3]; 39 + struct spi_message scan_single_msg; 40 + 41 + /* 42 + * DMA (thus cache coherency maintenance) requires the 43 + * transfer buffers to live in their own cache lines. 44 + * 2 bytes data + 6 bytes padding + 8 bytes timestamp when 45 + * call iio_push_to_buffers_with_timestamp. 46 + */ 47 + __be16 rx_buf[8] ____cacheline_aligned; 48 + }; 49 + 50 + struct tlc4541_chip_info { 51 + const struct iio_chan_spec *channels; 52 + unsigned int num_channels; 53 + }; 54 + 55 + enum tlc4541_id { 56 + TLC3541, 57 + TLC4541, 58 + }; 59 + 60 + #define TLC4541_V_CHAN(bits, bitshift) { \ 61 + .type = IIO_VOLTAGE, \ 62 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 63 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 64 + .scan_type = { \ 65 + .sign = 'u', \ 66 + .realbits = (bits), \ 67 + .storagebits = 16, \ 68 + .shift = (bitshift), \ 69 + .endianness = IIO_BE, \ 70 + }, \ 71 + } 72 + 73 + #define DECLARE_TLC4541_CHANNELS(name, bits, bitshift) \ 74 + const struct iio_chan_spec name ## _channels[] = { \ 75 + TLC4541_V_CHAN(bits, bitshift), \ 76 + IIO_CHAN_SOFT_TIMESTAMP(1), \ 77 + } 78 + 79 + static DECLARE_TLC4541_CHANNELS(tlc3541, 14, 2); 80 + static DECLARE_TLC4541_CHANNELS(tlc4541, 16, 0); 81 + 82 + static const struct tlc4541_chip_info tlc4541_chip_info[] = { 83 + [TLC3541] = { 84 + .channels = tlc3541_channels, 85 + .num_channels = ARRAY_SIZE(tlc3541_channels), 86 + }, 87 + [TLC4541] = { 88 + .channels = tlc4541_channels, 89 + .num_channels = ARRAY_SIZE(tlc4541_channels), 90 + }, 91 + }; 92 + 93 + static irqreturn_t tlc4541_trigger_handler(int irq, void *p) 94 + { 95 + struct iio_poll_func *pf = p; 96 + struct iio_dev *indio_dev = pf->indio_dev; 97 + struct tlc4541_state *st = iio_priv(indio_dev); 98 + int ret; 99 + 100 + ret = spi_sync(st->spi, &st->scan_single_msg); 101 + if (ret < 0) 102 + goto done; 103 + 104 + iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, 105 + iio_get_time_ns(indio_dev)); 106 + 107 + done: 108 + iio_trigger_notify_done(indio_dev->trig); 109 + return IRQ_HANDLED; 110 + } 111 + 112 + static int tlc4541_get_range(struct tlc4541_state *st) 113 + { 114 + int vref; 115 + 116 + vref = regulator_get_voltage(st->reg); 117 + if (vref < 0) 118 + return vref; 119 + 120 + vref /= 1000; 121 + 122 + return vref; 123 + } 124 + 125 + static int tlc4541_read_raw(struct iio_dev *indio_dev, 126 + struct iio_chan_spec const *chan, 127 + int *val, 128 + int *val2, 129 + long m) 130 + { 131 + int ret = 0; 132 + struct tlc4541_state *st = iio_priv(indio_dev); 133 + 134 + switch (m) { 135 + case IIO_CHAN_INFO_RAW: 136 + ret = iio_device_claim_direct_mode(indio_dev); 137 + if (ret) 138 + return ret; 139 + ret = spi_sync(st->spi, &st->scan_single_msg); 140 + iio_device_release_direct_mode(indio_dev); 141 + if (ret < 0) 142 + return ret; 143 + *val = be16_to_cpu(st->rx_buf[0]); 144 + *val = *val >> chan->scan_type.shift; 145 + *val &= GENMASK(chan->scan_type.realbits - 1, 0); 146 + return IIO_VAL_INT; 147 + case IIO_CHAN_INFO_SCALE: 148 + ret = tlc4541_get_range(st); 149 + if (ret < 0) 150 + return ret; 151 + *val = ret; 152 + *val2 = chan->scan_type.realbits; 153 + return IIO_VAL_FRACTIONAL_LOG2; 154 + } 155 + return -EINVAL; 156 + } 157 + 158 + static const struct iio_info tlc4541_info = { 159 + .read_raw = &tlc4541_read_raw, 160 + .driver_module = THIS_MODULE, 161 + }; 162 + 163 + static int tlc4541_probe(struct spi_device *spi) 164 + { 165 + struct tlc4541_state *st; 166 + struct iio_dev *indio_dev; 167 + const struct tlc4541_chip_info *info; 168 + int ret; 169 + int8_t device_init = 0; 170 + 171 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 172 + if (indio_dev == NULL) 173 + return -ENOMEM; 174 + 175 + st = iio_priv(indio_dev); 176 + 177 + spi_set_drvdata(spi, indio_dev); 178 + 179 + st->spi = spi; 180 + 181 + info = &tlc4541_chip_info[spi_get_device_id(spi)->driver_data]; 182 + 183 + indio_dev->name = spi_get_device_id(spi)->name; 184 + indio_dev->dev.parent = &spi->dev; 185 + indio_dev->modes = INDIO_DIRECT_MODE; 186 + indio_dev->channels = info->channels; 187 + indio_dev->num_channels = info->num_channels; 188 + indio_dev->info = &tlc4541_info; 189 + 190 + /* perform reset */ 191 + spi_write(spi, &device_init, 1); 192 + 193 + /* Setup default message */ 194 + st->scan_single_xfer[0].rx_buf = &st->rx_buf[0]; 195 + st->scan_single_xfer[0].len = 3; 196 + st->scan_single_xfer[1].delay_usecs = 3; 197 + st->scan_single_xfer[2].rx_buf = &st->rx_buf[0]; 198 + st->scan_single_xfer[2].len = 2; 199 + 200 + spi_message_init_with_transfers(&st->scan_single_msg, 201 + st->scan_single_xfer, 3); 202 + 203 + st->reg = devm_regulator_get(&spi->dev, "vref"); 204 + if (IS_ERR(st->reg)) 205 + return PTR_ERR(st->reg); 206 + 207 + ret = regulator_enable(st->reg); 208 + if (ret) 209 + return ret; 210 + 211 + ret = iio_triggered_buffer_setup(indio_dev, NULL, 212 + &tlc4541_trigger_handler, NULL); 213 + if (ret) 214 + goto error_disable_reg; 215 + 216 + ret = iio_device_register(indio_dev); 217 + if (ret) 218 + goto error_cleanup_buffer; 219 + 220 + return 0; 221 + 222 + error_cleanup_buffer: 223 + iio_triggered_buffer_cleanup(indio_dev); 224 + error_disable_reg: 225 + regulator_disable(st->reg); 226 + 227 + return ret; 228 + } 229 + 230 + static int tlc4541_remove(struct spi_device *spi) 231 + { 232 + struct iio_dev *indio_dev = spi_get_drvdata(spi); 233 + struct tlc4541_state *st = iio_priv(indio_dev); 234 + 235 + iio_device_unregister(indio_dev); 236 + iio_triggered_buffer_cleanup(indio_dev); 237 + regulator_disable(st->reg); 238 + 239 + return 0; 240 + } 241 + 242 + #ifdef CONFIG_OF 243 + static const struct of_device_id tlc4541_dt_ids[] = { 244 + { .compatible = "ti,tlc3541", }, 245 + { .compatible = "ti,tlc4541", }, 246 + {} 247 + }; 248 + MODULE_DEVICE_TABLE(of, tlc4541_dt_ids); 249 + #endif 250 + 251 + static const struct spi_device_id tlc4541_id[] = { 252 + {"tlc3541", TLC3541}, 253 + {"tlc4541", TLC4541}, 254 + {} 255 + }; 256 + MODULE_DEVICE_TABLE(spi, tlc4541_id); 257 + 258 + static struct spi_driver tlc4541_driver = { 259 + .driver = { 260 + .name = "tlc4541", 261 + .of_match_table = of_match_ptr(tlc4541_dt_ids), 262 + }, 263 + .probe = tlc4541_probe, 264 + .remove = tlc4541_remove, 265 + .id_table = tlc4541_id, 266 + }; 267 + module_spi_driver(tlc4541_driver); 268 + 269 + MODULE_AUTHOR("Phil Reid <preid@electromag.com.au>"); 270 + MODULE_DESCRIPTION("Texas Instruments TLC4541 ADC"); 271 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/iio/health/max30100.c
··· 378 378 if (ret) 379 379 return ret; 380 380 381 - usleep_range(35000, 50000); 381 + msleep(35); 382 382 383 383 return max30100_read_temp(data, val); 384 384 }
+1
drivers/iio/imu/Kconfig
··· 39 39 be called kmx61. 40 40 41 41 source "drivers/iio/imu/inv_mpu6050/Kconfig" 42 + source "drivers/iio/imu/st_lsm6dsx/Kconfig" 42 43 43 44 endmenu 44 45
+2
drivers/iio/imu/Makefile
··· 17 17 obj-y += inv_mpu6050/ 18 18 19 19 obj-$(CONFIG_KMX61) += kmx61.o 20 + 21 + obj-y += st_lsm6dsx/
+4 -4
drivers/iio/imu/bmi160/bmi160_core.c
··· 325 325 __le16 sample; 326 326 enum bmi160_sensor_type t = bmi160_to_sensor(chan_type); 327 327 328 - reg = bmi160_regs[t].data + (axis - IIO_MOD_X) * sizeof(__le16); 328 + reg = bmi160_regs[t].data + (axis - IIO_MOD_X) * sizeof(sample); 329 329 330 - ret = regmap_bulk_read(data->regmap, reg, &sample, sizeof(__le16)); 330 + ret = regmap_bulk_read(data->regmap, reg, &sample, sizeof(sample)); 331 331 if (ret < 0) 332 332 return ret; 333 333 ··· 392 392 393 393 for_each_set_bit(i, indio_dev->active_scan_mask, 394 394 indio_dev->masklength) { 395 - ret = regmap_bulk_read(data->regmap, base + i * sizeof(__le16), 396 - &sample, sizeof(__le16)); 395 + ret = regmap_bulk_read(data->regmap, base + i * sizeof(sample), 396 + &sample, sizeof(sample)); 397 397 if (ret < 0) 398 398 goto done; 399 399 buf[j++] = sample;
+22
drivers/iio/imu/st_lsm6dsx/Kconfig
··· 1 + 2 + config IIO_ST_LSM6DSX 3 + tristate "ST_LSM6DSx driver for STM 6-axis IMU MEMS sensors" 4 + depends on (I2C || SPI) 5 + select IIO_BUFFER 6 + select IIO_KFIFO_BUF 7 + select IIO_ST_LSM6DSX_I2C if (I2C) 8 + select IIO_ST_LSM6DSX_SPI if (SPI_MASTER) 9 + help 10 + Say yes here to build support for STMicroelectronics LSM6DSx imu 11 + sensor. Supported devices: lsm6ds3, lsm6dsm 12 + 13 + To compile this driver as a module, choose M here: the module 14 + will be called st_lsm6dsx. 15 + 16 + config IIO_ST_LSM6DSX_I2C 17 + tristate 18 + depends on IIO_ST_LSM6DSX 19 + 20 + config IIO_ST_LSM6DSX_SPI 21 + tristate 22 + depends on IIO_ST_LSM6DSX
+5
drivers/iio/imu/st_lsm6dsx/Makefile
··· 1 + st_lsm6dsx-y := st_lsm6dsx_core.o st_lsm6dsx_buffer.o 2 + 3 + obj-$(CONFIG_IIO_ST_LSM6DSX) += st_lsm6dsx.o 4 + obj-$(CONFIG_IIO_ST_LSM6DSX_I2C) += st_lsm6dsx_i2c.o 5 + obj-$(CONFIG_IIO_ST_LSM6DSX_SPI) += st_lsm6dsx_spi.o
+141
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
··· 1 + /* 2 + * STMicroelectronics st_lsm6dsx sensor driver 3 + * 4 + * Copyright 2016 STMicroelectronics Inc. 5 + * 6 + * Lorenzo Bianconi <lorenzo.bianconi@st.com> 7 + * Denis Ciocca <denis.ciocca@st.com> 8 + * 9 + * Licensed under the GPL-2. 10 + */ 11 + 12 + #ifndef ST_LSM6DSX_H 13 + #define ST_LSM6DSX_H 14 + 15 + #include <linux/device.h> 16 + 17 + #define ST_LSM6DS3_DEV_NAME "lsm6ds3" 18 + #define ST_LSM6DSM_DEV_NAME "lsm6dsm" 19 + 20 + enum st_lsm6dsx_hw_id { 21 + ST_LSM6DS3_ID, 22 + ST_LSM6DSM_ID, 23 + }; 24 + 25 + #define ST_LSM6DSX_CHAN_SIZE 2 26 + #define ST_LSM6DSX_SAMPLE_SIZE 6 27 + #define ST_LSM6DSX_SAMPLE_DEPTH (ST_LSM6DSX_SAMPLE_SIZE / \ 28 + ST_LSM6DSX_CHAN_SIZE) 29 + 30 + #if defined(CONFIG_SPI_MASTER) 31 + #define ST_LSM6DSX_RX_MAX_LENGTH 256 32 + #define ST_LSM6DSX_TX_MAX_LENGTH 8 33 + 34 + struct st_lsm6dsx_transfer_buffer { 35 + u8 rx_buf[ST_LSM6DSX_RX_MAX_LENGTH]; 36 + u8 tx_buf[ST_LSM6DSX_TX_MAX_LENGTH] ____cacheline_aligned; 37 + }; 38 + #endif /* CONFIG_SPI_MASTER */ 39 + 40 + struct st_lsm6dsx_transfer_function { 41 + int (*read)(struct device *dev, u8 addr, int len, u8 *data); 42 + int (*write)(struct device *dev, u8 addr, int len, u8 *data); 43 + }; 44 + 45 + struct st_lsm6dsx_reg { 46 + u8 addr; 47 + u8 mask; 48 + }; 49 + 50 + struct st_lsm6dsx_settings { 51 + u8 wai; 52 + u16 max_fifo_size; 53 + enum st_lsm6dsx_hw_id id; 54 + }; 55 + 56 + enum st_lsm6dsx_sensor_id { 57 + ST_LSM6DSX_ID_ACC, 58 + ST_LSM6DSX_ID_GYRO, 59 + ST_LSM6DSX_ID_MAX, 60 + }; 61 + 62 + enum st_lsm6dsx_fifo_mode { 63 + ST_LSM6DSX_FIFO_BYPASS = 0x0, 64 + ST_LSM6DSX_FIFO_CONT = 0x6, 65 + }; 66 + 67 + /** 68 + * struct st_lsm6dsx_sensor - ST IMU sensor instance 69 + * @id: Sensor identifier. 70 + * @hw: Pointer to instance of struct st_lsm6dsx_hw. 71 + * @gain: Configured sensor sensitivity. 72 + * @odr: Output data rate of the sensor [Hz]. 73 + * @watermark: Sensor watermark level. 74 + * @sip: Number of samples in a given pattern. 75 + * @decimator: FIFO decimation factor. 76 + * @decimator_mask: Sensor mask for decimation register. 77 + * @delta_ts: Delta time between two consecutive interrupts. 78 + * @ts: Latest timestamp from the interrupt handler. 79 + */ 80 + struct st_lsm6dsx_sensor { 81 + enum st_lsm6dsx_sensor_id id; 82 + struct st_lsm6dsx_hw *hw; 83 + 84 + u32 gain; 85 + u16 odr; 86 + 87 + u16 watermark; 88 + u8 sip; 89 + u8 decimator; 90 + u8 decimator_mask; 91 + 92 + s64 delta_ts; 93 + s64 ts; 94 + }; 95 + 96 + /** 97 + * struct st_lsm6dsx_hw - ST IMU MEMS hw instance 98 + * @dev: Pointer to instance of struct device (I2C or SPI). 99 + * @irq: Device interrupt line (I2C or SPI). 100 + * @lock: Mutex to protect read and write operations. 101 + * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO. 102 + * @fifo_mode: FIFO operating mode supported by the device. 103 + * @enable_mask: Enabled sensor bitmask. 104 + * @sip: Total number of samples (acc/gyro) in a given pattern. 105 + * @iio_devs: Pointers to acc/gyro iio_dev instances. 106 + * @settings: Pointer to the specific sensor settings in use. 107 + * @tf: Transfer function structure used by I/O operations. 108 + * @tb: Transfer buffers used by SPI I/O operations. 109 + */ 110 + struct st_lsm6dsx_hw { 111 + struct device *dev; 112 + int irq; 113 + 114 + struct mutex lock; 115 + struct mutex fifo_lock; 116 + 117 + enum st_lsm6dsx_fifo_mode fifo_mode; 118 + u8 enable_mask; 119 + u8 sip; 120 + 121 + struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX]; 122 + 123 + const struct st_lsm6dsx_settings *settings; 124 + 125 + const struct st_lsm6dsx_transfer_function *tf; 126 + #if defined(CONFIG_SPI_MASTER) 127 + struct st_lsm6dsx_transfer_buffer tb; 128 + #endif /* CONFIG_SPI_MASTER */ 129 + }; 130 + 131 + int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, 132 + const struct st_lsm6dsx_transfer_function *tf_ops); 133 + int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor); 134 + int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor); 135 + int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw); 136 + int st_lsm6dsx_write_with_mask(struct st_lsm6dsx_hw *hw, u8 addr, u8 mask, 137 + u8 val); 138 + int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, 139 + u16 watermark); 140 + 141 + #endif /* ST_LSM6DSX_H */
+454
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
··· 1 + /* 2 + * STMicroelectronics st_lsm6dsx FIFO buffer library driver 3 + * 4 + * LSM6DS3/LSM6DSM: The FIFO buffer can be configured to store data 5 + * from gyroscope and accelerometer. Samples are queued without any tag 6 + * according to a specific pattern based on 'FIFO data sets' (6 bytes each): 7 + * - 1st data set is reserved for gyroscope data 8 + * - 2nd data set is reserved for accelerometer data 9 + * The FIFO pattern changes depending on the ODRs and decimation factors 10 + * assigned to the FIFO data sets. The first sequence of data stored in FIFO 11 + * buffer contains the data of all the enabled FIFO data sets 12 + * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated depending on the 13 + * value of the decimation factor and ODR set for each FIFO data set. 14 + * FIFO supported modes: 15 + * - BYPASS: FIFO disabled 16 + * - CONTINUOUS: FIFO enabled. When the buffer is full, the FIFO index 17 + * restarts from the beginning and the oldest sample is overwritten 18 + * 19 + * Copyright 2016 STMicroelectronics Inc. 20 + * 21 + * Lorenzo Bianconi <lorenzo.bianconi@st.com> 22 + * Denis Ciocca <denis.ciocca@st.com> 23 + * 24 + * Licensed under the GPL-2. 25 + */ 26 + #include <linux/module.h> 27 + #include <linux/interrupt.h> 28 + #include <linux/irq.h> 29 + #include <linux/iio/kfifo_buf.h> 30 + #include <linux/iio/iio.h> 31 + #include <linux/iio/buffer.h> 32 + 33 + #include "st_lsm6dsx.h" 34 + 35 + #define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06 36 + #define ST_LSM6DSX_REG_FIFO_THH_ADDR 0x07 37 + #define ST_LSM6DSX_FIFO_TH_MASK GENMASK(11, 0) 38 + #define ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR 0x08 39 + #define ST_LSM6DSX_REG_FIFO_MODE_ADDR 0x0a 40 + #define ST_LSM6DSX_FIFO_MODE_MASK GENMASK(2, 0) 41 + #define ST_LSM6DSX_FIFO_ODR_MASK GENMASK(6, 3) 42 + #define ST_LSM6DSX_REG_FIFO_DIFFL_ADDR 0x3a 43 + #define ST_LSM6DSX_FIFO_DIFF_MASK GENMASK(11, 0) 44 + #define ST_LSM6DSX_FIFO_EMPTY_MASK BIT(12) 45 + #define ST_LSM6DSX_REG_FIFO_OUTL_ADDR 0x3e 46 + 47 + #define ST_LSM6DSX_MAX_FIFO_ODR_VAL 0x08 48 + 49 + struct st_lsm6dsx_decimator_entry { 50 + u8 decimator; 51 + u8 val; 52 + }; 53 + 54 + static const 55 + struct st_lsm6dsx_decimator_entry st_lsm6dsx_decimator_table[] = { 56 + { 0, 0x0 }, 57 + { 1, 0x1 }, 58 + { 2, 0x2 }, 59 + { 3, 0x3 }, 60 + { 4, 0x4 }, 61 + { 8, 0x5 }, 62 + { 16, 0x6 }, 63 + { 32, 0x7 }, 64 + }; 65 + 66 + static int st_lsm6dsx_get_decimator_val(u8 val) 67 + { 68 + const int max_size = ARRAY_SIZE(st_lsm6dsx_decimator_table); 69 + int i; 70 + 71 + for (i = 0; i < max_size; i++) 72 + if (st_lsm6dsx_decimator_table[i].decimator == val) 73 + break; 74 + 75 + return i == max_size ? 0 : st_lsm6dsx_decimator_table[i].val; 76 + } 77 + 78 + static void st_lsm6dsx_get_max_min_odr(struct st_lsm6dsx_hw *hw, 79 + u16 *max_odr, u16 *min_odr) 80 + { 81 + struct st_lsm6dsx_sensor *sensor; 82 + int i; 83 + 84 + *max_odr = 0, *min_odr = ~0; 85 + for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 86 + sensor = iio_priv(hw->iio_devs[i]); 87 + 88 + if (!(hw->enable_mask & BIT(sensor->id))) 89 + continue; 90 + 91 + *max_odr = max_t(u16, *max_odr, sensor->odr); 92 + *min_odr = min_t(u16, *min_odr, sensor->odr); 93 + } 94 + } 95 + 96 + static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw) 97 + { 98 + struct st_lsm6dsx_sensor *sensor; 99 + u16 max_odr, min_odr, sip = 0; 100 + int err, i; 101 + u8 data; 102 + 103 + st_lsm6dsx_get_max_min_odr(hw, &max_odr, &min_odr); 104 + 105 + for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 106 + sensor = iio_priv(hw->iio_devs[i]); 107 + 108 + /* update fifo decimators and sample in pattern */ 109 + if (hw->enable_mask & BIT(sensor->id)) { 110 + sensor->sip = sensor->odr / min_odr; 111 + sensor->decimator = max_odr / sensor->odr; 112 + data = st_lsm6dsx_get_decimator_val(sensor->decimator); 113 + } else { 114 + sensor->sip = 0; 115 + sensor->decimator = 0; 116 + data = 0; 117 + } 118 + 119 + err = st_lsm6dsx_write_with_mask(hw, 120 + ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR, 121 + sensor->decimator_mask, data); 122 + if (err < 0) 123 + return err; 124 + 125 + sip += sensor->sip; 126 + } 127 + hw->sip = sip; 128 + 129 + return 0; 130 + } 131 + 132 + static int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw, 133 + enum st_lsm6dsx_fifo_mode fifo_mode) 134 + { 135 + u8 data; 136 + int err; 137 + 138 + switch (fifo_mode) { 139 + case ST_LSM6DSX_FIFO_BYPASS: 140 + data = fifo_mode; 141 + break; 142 + case ST_LSM6DSX_FIFO_CONT: 143 + data = (ST_LSM6DSX_MAX_FIFO_ODR_VAL << 144 + __ffs(ST_LSM6DSX_FIFO_ODR_MASK)) | fifo_mode; 145 + break; 146 + default: 147 + return -EINVAL; 148 + } 149 + 150 + err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_FIFO_MODE_ADDR, 151 + sizeof(data), &data); 152 + if (err < 0) 153 + return err; 154 + 155 + hw->fifo_mode = fifo_mode; 156 + 157 + return 0; 158 + } 159 + 160 + int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark) 161 + { 162 + u16 fifo_watermark = ~0, cur_watermark, sip = 0; 163 + struct st_lsm6dsx_hw *hw = sensor->hw; 164 + struct st_lsm6dsx_sensor *cur_sensor; 165 + __le16 wdata; 166 + int i, err; 167 + u8 data; 168 + 169 + for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 170 + cur_sensor = iio_priv(hw->iio_devs[i]); 171 + 172 + if (!(hw->enable_mask & BIT(cur_sensor->id))) 173 + continue; 174 + 175 + cur_watermark = (cur_sensor == sensor) ? watermark 176 + : cur_sensor->watermark; 177 + 178 + fifo_watermark = min_t(u16, fifo_watermark, cur_watermark); 179 + sip += cur_sensor->sip; 180 + } 181 + 182 + if (!sip) 183 + return 0; 184 + 185 + fifo_watermark = max_t(u16, fifo_watermark, sip); 186 + fifo_watermark = (fifo_watermark / sip) * sip; 187 + fifo_watermark = fifo_watermark * ST_LSM6DSX_SAMPLE_DEPTH; 188 + 189 + mutex_lock(&hw->lock); 190 + 191 + err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_THH_ADDR, 192 + sizeof(data), &data); 193 + if (err < 0) 194 + goto out; 195 + 196 + fifo_watermark = ((data & ~ST_LSM6DSX_FIFO_TH_MASK) << 8) | 197 + (fifo_watermark & ST_LSM6DSX_FIFO_TH_MASK); 198 + 199 + wdata = cpu_to_le16(fifo_watermark); 200 + err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_FIFO_THL_ADDR, 201 + sizeof(wdata), (u8 *)&wdata); 202 + out: 203 + mutex_unlock(&hw->lock); 204 + 205 + return err < 0 ? err : 0; 206 + } 207 + 208 + /** 209 + * st_lsm6dsx_read_fifo() - LSM6DS3-LSM6DSM read FIFO routine 210 + * @hw: Pointer to instance of struct st_lsm6dsx_hw. 211 + * 212 + * Read samples from the hw FIFO and push them to IIO buffers. 213 + * 214 + * Return: Number of bytes read from the FIFO 215 + */ 216 + static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) 217 + { 218 + u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE; 219 + int err, acc_sip, gyro_sip, read_len, samples, offset; 220 + struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor; 221 + s64 acc_ts, acc_delta_ts, gyro_ts, gyro_delta_ts; 222 + u8 iio_buff[ALIGN(ST_LSM6DSX_SAMPLE_SIZE, sizeof(s64)) + sizeof(s64)]; 223 + u8 buff[pattern_len]; 224 + __le16 fifo_status; 225 + 226 + err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_DIFFL_ADDR, 227 + sizeof(fifo_status), (u8 *)&fifo_status); 228 + if (err < 0) 229 + return err; 230 + 231 + if (fifo_status & cpu_to_le16(ST_LSM6DSX_FIFO_EMPTY_MASK)) 232 + return 0; 233 + 234 + fifo_len = (le16_to_cpu(fifo_status) & ST_LSM6DSX_FIFO_DIFF_MASK) * 235 + ST_LSM6DSX_CHAN_SIZE; 236 + samples = fifo_len / ST_LSM6DSX_SAMPLE_SIZE; 237 + fifo_len = (fifo_len / pattern_len) * pattern_len; 238 + 239 + /* 240 + * compute delta timestamp between two consecutive samples 241 + * in order to estimate queueing time of data generated 242 + * by the sensor 243 + */ 244 + acc_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]); 245 + acc_ts = acc_sensor->ts - acc_sensor->delta_ts; 246 + acc_delta_ts = div_s64(acc_sensor->delta_ts * acc_sensor->decimator, 247 + samples); 248 + 249 + gyro_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_GYRO]); 250 + gyro_ts = gyro_sensor->ts - gyro_sensor->delta_ts; 251 + gyro_delta_ts = div_s64(gyro_sensor->delta_ts * gyro_sensor->decimator, 252 + samples); 253 + 254 + for (read_len = 0; read_len < fifo_len; read_len += pattern_len) { 255 + err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_OUTL_ADDR, 256 + sizeof(buff), buff); 257 + if (err < 0) 258 + return err; 259 + 260 + /* 261 + * Data are written to the FIFO with a specific pattern 262 + * depending on the configured ODRs. The first sequence of data 263 + * stored in FIFO contains the data of all enabled sensors 264 + * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated 265 + * depending on the value of the decimation factor set for each 266 + * sensor. 267 + * 268 + * Supposing the FIFO is storing data from gyroscope and 269 + * accelerometer at different ODRs: 270 + * - gyroscope ODR = 208Hz, accelerometer ODR = 104Hz 271 + * Since the gyroscope ODR is twice the accelerometer one, the 272 + * following pattern is repeated every 9 samples: 273 + * - Gx, Gy, Gz, Ax, Ay, Az, Gx, Gy, Gz 274 + */ 275 + gyro_sip = gyro_sensor->sip; 276 + acc_sip = acc_sensor->sip; 277 + offset = 0; 278 + 279 + while (acc_sip > 0 || gyro_sip > 0) { 280 + if (gyro_sip-- > 0) { 281 + memcpy(iio_buff, &buff[offset], 282 + ST_LSM6DSX_SAMPLE_SIZE); 283 + iio_push_to_buffers_with_timestamp( 284 + hw->iio_devs[ST_LSM6DSX_ID_GYRO], 285 + iio_buff, gyro_ts); 286 + offset += ST_LSM6DSX_SAMPLE_SIZE; 287 + gyro_ts += gyro_delta_ts; 288 + } 289 + 290 + if (acc_sip-- > 0) { 291 + memcpy(iio_buff, &buff[offset], 292 + ST_LSM6DSX_SAMPLE_SIZE); 293 + iio_push_to_buffers_with_timestamp( 294 + hw->iio_devs[ST_LSM6DSX_ID_ACC], 295 + iio_buff, acc_ts); 296 + offset += ST_LSM6DSX_SAMPLE_SIZE; 297 + acc_ts += acc_delta_ts; 298 + } 299 + } 300 + } 301 + 302 + return read_len; 303 + } 304 + 305 + static int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw) 306 + { 307 + int err; 308 + 309 + mutex_lock(&hw->fifo_lock); 310 + 311 + st_lsm6dsx_read_fifo(hw); 312 + err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_BYPASS); 313 + 314 + mutex_unlock(&hw->fifo_lock); 315 + 316 + return err; 317 + } 318 + 319 + static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable) 320 + { 321 + struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 322 + struct st_lsm6dsx_hw *hw = sensor->hw; 323 + int err; 324 + 325 + if (hw->fifo_mode != ST_LSM6DSX_FIFO_BYPASS) { 326 + err = st_lsm6dsx_flush_fifo(hw); 327 + if (err < 0) 328 + return err; 329 + } 330 + 331 + if (enable) { 332 + err = st_lsm6dsx_sensor_enable(sensor); 333 + if (err < 0) 334 + return err; 335 + } else { 336 + err = st_lsm6dsx_sensor_disable(sensor); 337 + if (err < 0) 338 + return err; 339 + } 340 + 341 + err = st_lsm6dsx_update_decimators(hw); 342 + if (err < 0) 343 + return err; 344 + 345 + err = st_lsm6dsx_update_watermark(sensor, sensor->watermark); 346 + if (err < 0) 347 + return err; 348 + 349 + if (hw->enable_mask) { 350 + err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_CONT); 351 + if (err < 0) 352 + return err; 353 + 354 + /* 355 + * store enable buffer timestamp as reference to compute 356 + * first delta timestamp 357 + */ 358 + sensor->ts = iio_get_time_ns(iio_dev); 359 + } 360 + 361 + return 0; 362 + } 363 + 364 + static irqreturn_t st_lsm6dsx_handler_irq(int irq, void *private) 365 + { 366 + struct st_lsm6dsx_hw *hw = (struct st_lsm6dsx_hw *)private; 367 + struct st_lsm6dsx_sensor *sensor; 368 + int i; 369 + 370 + if (!hw->sip) 371 + return IRQ_NONE; 372 + 373 + for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 374 + sensor = iio_priv(hw->iio_devs[i]); 375 + 376 + if (sensor->sip > 0) { 377 + s64 timestamp; 378 + 379 + timestamp = iio_get_time_ns(hw->iio_devs[i]); 380 + sensor->delta_ts = timestamp - sensor->ts; 381 + sensor->ts = timestamp; 382 + } 383 + } 384 + 385 + return IRQ_WAKE_THREAD; 386 + } 387 + 388 + static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private) 389 + { 390 + struct st_lsm6dsx_hw *hw = (struct st_lsm6dsx_hw *)private; 391 + int count; 392 + 393 + mutex_lock(&hw->fifo_lock); 394 + count = st_lsm6dsx_read_fifo(hw); 395 + mutex_unlock(&hw->fifo_lock); 396 + 397 + return !count ? IRQ_NONE : IRQ_HANDLED; 398 + } 399 + 400 + static int st_lsm6dsx_buffer_preenable(struct iio_dev *iio_dev) 401 + { 402 + return st_lsm6dsx_update_fifo(iio_dev, true); 403 + } 404 + 405 + static int st_lsm6dsx_buffer_postdisable(struct iio_dev *iio_dev) 406 + { 407 + return st_lsm6dsx_update_fifo(iio_dev, false); 408 + } 409 + 410 + static const struct iio_buffer_setup_ops st_lsm6dsx_buffer_ops = { 411 + .preenable = st_lsm6dsx_buffer_preenable, 412 + .postdisable = st_lsm6dsx_buffer_postdisable, 413 + }; 414 + 415 + int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw) 416 + { 417 + struct iio_buffer *buffer; 418 + unsigned long irq_type; 419 + int i, err; 420 + 421 + irq_type = irqd_get_trigger_type(irq_get_irq_data(hw->irq)); 422 + 423 + switch (irq_type) { 424 + case IRQF_TRIGGER_HIGH: 425 + case IRQF_TRIGGER_RISING: 426 + break; 427 + default: 428 + dev_info(hw->dev, "mode %lx unsupported\n", irq_type); 429 + return -EINVAL; 430 + } 431 + 432 + err = devm_request_threaded_irq(hw->dev, hw->irq, 433 + st_lsm6dsx_handler_irq, 434 + st_lsm6dsx_handler_thread, 435 + irq_type | IRQF_ONESHOT, 436 + "lsm6dsx", hw); 437 + if (err) { 438 + dev_err(hw->dev, "failed to request trigger irq %d\n", 439 + hw->irq); 440 + return err; 441 + } 442 + 443 + for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 444 + buffer = devm_iio_kfifo_allocate(hw->dev); 445 + if (!buffer) 446 + return -ENOMEM; 447 + 448 + iio_device_attach_buffer(hw->iio_devs[i], buffer); 449 + hw->iio_devs[i]->modes |= INDIO_BUFFER_SOFTWARE; 450 + hw->iio_devs[i]->setup_ops = &st_lsm6dsx_buffer_ops; 451 + } 452 + 453 + return 0; 454 + }
+673
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 1 + /* 2 + * STMicroelectronics st_lsm6dsx sensor driver 3 + * 4 + * The ST LSM6DSx IMU MEMS series consists of 3D digital accelerometer 5 + * and 3D digital gyroscope system-in-package with a digital I2C/SPI serial 6 + * interface standard output. 7 + * LSM6DSx IMU MEMS series has a dynamic user-selectable full-scale 8 + * acceleration range of +-2/+-4/+-8/+-16 g and an angular rate range of 9 + * +-125/+-245/+-500/+-1000/+-2000 dps 10 + * LSM6DSx series has an integrated First-In-First-Out (FIFO) buffer 11 + * allowing dynamic batching of sensor data. 12 + * 13 + * Supported sensors: 14 + * - LSM6DS3: 15 + * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416 16 + * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 17 + * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 18 + * - FIFO size: 8KB 19 + * 20 + * - LSM6DSM: 21 + * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416 22 + * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 23 + * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 24 + * - FIFO size: 4KB 25 + * 26 + * Copyright 2016 STMicroelectronics Inc. 27 + * 28 + * Lorenzo Bianconi <lorenzo.bianconi@st.com> 29 + * Denis Ciocca <denis.ciocca@st.com> 30 + * 31 + * Licensed under the GPL-2. 32 + */ 33 + 34 + #include <linux/kernel.h> 35 + #include <linux/module.h> 36 + #include <linux/delay.h> 37 + #include <linux/iio/iio.h> 38 + #include <linux/iio/sysfs.h> 39 + 40 + #include "st_lsm6dsx.h" 41 + 42 + #define ST_LSM6DSX_REG_ACC_DEC_MASK GENMASK(2, 0) 43 + #define ST_LSM6DSX_REG_GYRO_DEC_MASK GENMASK(5, 3) 44 + #define ST_LSM6DSX_REG_INT1_ADDR 0x0d 45 + #define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK BIT(3) 46 + #define ST_LSM6DSX_REG_WHOAMI_ADDR 0x0f 47 + #define ST_LSM6DSX_REG_RESET_ADDR 0x12 48 + #define ST_LSM6DSX_REG_RESET_MASK BIT(0) 49 + #define ST_LSM6DSX_REG_BDU_ADDR 0x12 50 + #define ST_LSM6DSX_REG_BDU_MASK BIT(6) 51 + #define ST_LSM6DSX_REG_INT2_ON_INT1_ADDR 0x13 52 + #define ST_LSM6DSX_REG_INT2_ON_INT1_MASK BIT(5) 53 + #define ST_LSM6DSX_REG_ROUNDING_ADDR 0x16 54 + #define ST_LSM6DSX_REG_ROUNDING_MASK BIT(2) 55 + #define ST_LSM6DSX_REG_LIR_ADDR 0x58 56 + #define ST_LSM6DSX_REG_LIR_MASK BIT(0) 57 + 58 + #define ST_LSM6DSX_REG_ACC_ODR_ADDR 0x10 59 + #define ST_LSM6DSX_REG_ACC_ODR_MASK GENMASK(7, 4) 60 + #define ST_LSM6DSX_REG_ACC_FS_ADDR 0x10 61 + #define ST_LSM6DSX_REG_ACC_FS_MASK GENMASK(3, 2) 62 + #define ST_LSM6DSX_REG_ACC_OUT_X_L_ADDR 0x28 63 + #define ST_LSM6DSX_REG_ACC_OUT_Y_L_ADDR 0x2a 64 + #define ST_LSM6DSX_REG_ACC_OUT_Z_L_ADDR 0x2c 65 + 66 + #define ST_LSM6DSX_REG_GYRO_ODR_ADDR 0x11 67 + #define ST_LSM6DSX_REG_GYRO_ODR_MASK GENMASK(7, 4) 68 + #define ST_LSM6DSX_REG_GYRO_FS_ADDR 0x11 69 + #define ST_LSM6DSX_REG_GYRO_FS_MASK GENMASK(3, 2) 70 + #define ST_LSM6DSX_REG_GYRO_OUT_X_L_ADDR 0x22 71 + #define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR 0x24 72 + #define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR 0x26 73 + 74 + #define ST_LSM6DS3_WHOAMI 0x69 75 + #define ST_LSM6DSM_WHOAMI 0x6a 76 + 77 + #define ST_LSM6DS3_MAX_FIFO_SIZE 8192 78 + #define ST_LSM6DSM_MAX_FIFO_SIZE 4096 79 + 80 + #define ST_LSM6DSX_ACC_FS_2G_GAIN IIO_G_TO_M_S_2(61) 81 + #define ST_LSM6DSX_ACC_FS_4G_GAIN IIO_G_TO_M_S_2(122) 82 + #define ST_LSM6DSX_ACC_FS_8G_GAIN IIO_G_TO_M_S_2(244) 83 + #define ST_LSM6DSX_ACC_FS_16G_GAIN IIO_G_TO_M_S_2(488) 84 + 85 + #define ST_LSM6DSX_GYRO_FS_245_GAIN IIO_DEGREE_TO_RAD(8750) 86 + #define ST_LSM6DSX_GYRO_FS_500_GAIN IIO_DEGREE_TO_RAD(17500) 87 + #define ST_LSM6DSX_GYRO_FS_1000_GAIN IIO_DEGREE_TO_RAD(35000) 88 + #define ST_LSM6DSX_GYRO_FS_2000_GAIN IIO_DEGREE_TO_RAD(70000) 89 + 90 + struct st_lsm6dsx_odr { 91 + u16 hz; 92 + u8 val; 93 + }; 94 + 95 + #define ST_LSM6DSX_ODR_LIST_SIZE 6 96 + struct st_lsm6dsx_odr_table_entry { 97 + struct st_lsm6dsx_reg reg; 98 + struct st_lsm6dsx_odr odr_avl[ST_LSM6DSX_ODR_LIST_SIZE]; 99 + }; 100 + 101 + static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = { 102 + [ST_LSM6DSX_ID_ACC] = { 103 + .reg = { 104 + .addr = ST_LSM6DSX_REG_ACC_ODR_ADDR, 105 + .mask = ST_LSM6DSX_REG_ACC_ODR_MASK, 106 + }, 107 + .odr_avl[0] = { 13, 0x01 }, 108 + .odr_avl[1] = { 26, 0x02 }, 109 + .odr_avl[2] = { 52, 0x03 }, 110 + .odr_avl[3] = { 104, 0x04 }, 111 + .odr_avl[4] = { 208, 0x05 }, 112 + .odr_avl[5] = { 416, 0x06 }, 113 + }, 114 + [ST_LSM6DSX_ID_GYRO] = { 115 + .reg = { 116 + .addr = ST_LSM6DSX_REG_GYRO_ODR_ADDR, 117 + .mask = ST_LSM6DSX_REG_GYRO_ODR_MASK, 118 + }, 119 + .odr_avl[0] = { 13, 0x01 }, 120 + .odr_avl[1] = { 26, 0x02 }, 121 + .odr_avl[2] = { 52, 0x03 }, 122 + .odr_avl[3] = { 104, 0x04 }, 123 + .odr_avl[4] = { 208, 0x05 }, 124 + .odr_avl[5] = { 416, 0x06 }, 125 + } 126 + }; 127 + 128 + struct st_lsm6dsx_fs { 129 + u32 gain; 130 + u8 val; 131 + }; 132 + 133 + #define ST_LSM6DSX_FS_LIST_SIZE 4 134 + struct st_lsm6dsx_fs_table_entry { 135 + struct st_lsm6dsx_reg reg; 136 + struct st_lsm6dsx_fs fs_avl[ST_LSM6DSX_FS_LIST_SIZE]; 137 + }; 138 + 139 + static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = { 140 + [ST_LSM6DSX_ID_ACC] = { 141 + .reg = { 142 + .addr = ST_LSM6DSX_REG_ACC_FS_ADDR, 143 + .mask = ST_LSM6DSX_REG_ACC_FS_MASK, 144 + }, 145 + .fs_avl[0] = { ST_LSM6DSX_ACC_FS_2G_GAIN, 0x0 }, 146 + .fs_avl[1] = { ST_LSM6DSX_ACC_FS_4G_GAIN, 0x2 }, 147 + .fs_avl[2] = { ST_LSM6DSX_ACC_FS_8G_GAIN, 0x3 }, 148 + .fs_avl[3] = { ST_LSM6DSX_ACC_FS_16G_GAIN, 0x1 }, 149 + }, 150 + [ST_LSM6DSX_ID_GYRO] = { 151 + .reg = { 152 + .addr = ST_LSM6DSX_REG_GYRO_FS_ADDR, 153 + .mask = ST_LSM6DSX_REG_GYRO_FS_MASK, 154 + }, 155 + .fs_avl[0] = { ST_LSM6DSX_GYRO_FS_245_GAIN, 0x0 }, 156 + .fs_avl[1] = { ST_LSM6DSX_GYRO_FS_500_GAIN, 0x1 }, 157 + .fs_avl[2] = { ST_LSM6DSX_GYRO_FS_1000_GAIN, 0x2 }, 158 + .fs_avl[3] = { ST_LSM6DSX_GYRO_FS_2000_GAIN, 0x3 }, 159 + } 160 + }; 161 + 162 + static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { 163 + { 164 + .wai = ST_LSM6DS3_WHOAMI, 165 + .max_fifo_size = ST_LSM6DS3_MAX_FIFO_SIZE, 166 + .id = ST_LSM6DS3_ID, 167 + }, 168 + { 169 + .wai = ST_LSM6DSM_WHOAMI, 170 + .max_fifo_size = ST_LSM6DSM_MAX_FIFO_SIZE, 171 + .id = ST_LSM6DSM_ID, 172 + }, 173 + }; 174 + 175 + #define ST_LSM6DSX_CHANNEL(chan_type, addr, mod, scan_idx) \ 176 + { \ 177 + .type = chan_type, \ 178 + .address = addr, \ 179 + .modified = 1, \ 180 + .channel2 = mod, \ 181 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 182 + BIT(IIO_CHAN_INFO_SCALE), \ 183 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 184 + .scan_index = scan_idx, \ 185 + .scan_type = { \ 186 + .sign = 's', \ 187 + .realbits = 16, \ 188 + .storagebits = 16, \ 189 + .endianness = IIO_LE, \ 190 + }, \ 191 + } 192 + 193 + static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = { 194 + ST_LSM6DSX_CHANNEL(IIO_ACCEL, ST_LSM6DSX_REG_ACC_OUT_X_L_ADDR, 195 + IIO_MOD_X, 0), 196 + ST_LSM6DSX_CHANNEL(IIO_ACCEL, ST_LSM6DSX_REG_ACC_OUT_Y_L_ADDR, 197 + IIO_MOD_Y, 1), 198 + ST_LSM6DSX_CHANNEL(IIO_ACCEL, ST_LSM6DSX_REG_ACC_OUT_Z_L_ADDR, 199 + IIO_MOD_Z, 2), 200 + IIO_CHAN_SOFT_TIMESTAMP(3), 201 + }; 202 + 203 + static const struct iio_chan_spec st_lsm6dsx_gyro_channels[] = { 204 + ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, ST_LSM6DSX_REG_GYRO_OUT_X_L_ADDR, 205 + IIO_MOD_X, 0), 206 + ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR, 207 + IIO_MOD_Y, 1), 208 + ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR, 209 + IIO_MOD_Z, 2), 210 + IIO_CHAN_SOFT_TIMESTAMP(3), 211 + }; 212 + 213 + int st_lsm6dsx_write_with_mask(struct st_lsm6dsx_hw *hw, u8 addr, u8 mask, 214 + u8 val) 215 + { 216 + u8 data; 217 + int err; 218 + 219 + mutex_lock(&hw->lock); 220 + 221 + err = hw->tf->read(hw->dev, addr, sizeof(data), &data); 222 + if (err < 0) { 223 + dev_err(hw->dev, "failed to read %02x register\n", addr); 224 + goto out; 225 + } 226 + 227 + data = (data & ~mask) | ((val << __ffs(mask)) & mask); 228 + 229 + err = hw->tf->write(hw->dev, addr, sizeof(data), &data); 230 + if (err < 0) 231 + dev_err(hw->dev, "failed to write %02x register\n", addr); 232 + 233 + out: 234 + mutex_unlock(&hw->lock); 235 + 236 + return err; 237 + } 238 + 239 + static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id) 240 + { 241 + int err, i; 242 + u8 data; 243 + 244 + for (i = 0; i < ARRAY_SIZE(st_lsm6dsx_sensor_settings); i++) { 245 + if (id == st_lsm6dsx_sensor_settings[i].id) 246 + break; 247 + } 248 + 249 + if (i == ARRAY_SIZE(st_lsm6dsx_sensor_settings)) { 250 + dev_err(hw->dev, "unsupported hw id [%02x]\n", id); 251 + return -ENODEV; 252 + } 253 + 254 + err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_WHOAMI_ADDR, sizeof(data), 255 + &data); 256 + if (err < 0) { 257 + dev_err(hw->dev, "failed to read whoami register\n"); 258 + return err; 259 + } 260 + 261 + if (data != st_lsm6dsx_sensor_settings[i].wai) { 262 + dev_err(hw->dev, "unsupported whoami [%02x]\n", data); 263 + return -ENODEV; 264 + } 265 + 266 + hw->settings = &st_lsm6dsx_sensor_settings[i]; 267 + 268 + return 0; 269 + } 270 + 271 + static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor, 272 + u32 gain) 273 + { 274 + enum st_lsm6dsx_sensor_id id = sensor->id; 275 + int i, err; 276 + u8 val; 277 + 278 + for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) 279 + if (st_lsm6dsx_fs_table[id].fs_avl[i].gain == gain) 280 + break; 281 + 282 + if (i == ST_LSM6DSX_FS_LIST_SIZE) 283 + return -EINVAL; 284 + 285 + val = st_lsm6dsx_fs_table[id].fs_avl[i].val; 286 + err = st_lsm6dsx_write_with_mask(sensor->hw, 287 + st_lsm6dsx_fs_table[id].reg.addr, 288 + st_lsm6dsx_fs_table[id].reg.mask, 289 + val); 290 + if (err < 0) 291 + return err; 292 + 293 + sensor->gain = gain; 294 + 295 + return 0; 296 + } 297 + 298 + static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr) 299 + { 300 + enum st_lsm6dsx_sensor_id id = sensor->id; 301 + int i, err; 302 + u8 val; 303 + 304 + for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++) 305 + if (st_lsm6dsx_odr_table[id].odr_avl[i].hz == odr) 306 + break; 307 + 308 + if (i == ST_LSM6DSX_ODR_LIST_SIZE) 309 + return -EINVAL; 310 + 311 + val = st_lsm6dsx_odr_table[id].odr_avl[i].val; 312 + err = st_lsm6dsx_write_with_mask(sensor->hw, 313 + st_lsm6dsx_odr_table[id].reg.addr, 314 + st_lsm6dsx_odr_table[id].reg.mask, 315 + val); 316 + if (err < 0) 317 + return err; 318 + 319 + sensor->odr = odr; 320 + 321 + return 0; 322 + } 323 + 324 + int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor) 325 + { 326 + int err; 327 + 328 + err = st_lsm6dsx_set_odr(sensor, sensor->odr); 329 + if (err < 0) 330 + return err; 331 + 332 + sensor->hw->enable_mask |= BIT(sensor->id); 333 + 334 + return 0; 335 + } 336 + 337 + int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor) 338 + { 339 + enum st_lsm6dsx_sensor_id id = sensor->id; 340 + int err; 341 + 342 + err = st_lsm6dsx_write_with_mask(sensor->hw, 343 + st_lsm6dsx_odr_table[id].reg.addr, 344 + st_lsm6dsx_odr_table[id].reg.mask, 0); 345 + if (err < 0) 346 + return err; 347 + 348 + sensor->hw->enable_mask &= ~BIT(id); 349 + 350 + return 0; 351 + } 352 + 353 + static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor, 354 + u8 addr, int *val) 355 + { 356 + int err, delay; 357 + __le16 data; 358 + 359 + err = st_lsm6dsx_sensor_enable(sensor); 360 + if (err < 0) 361 + return err; 362 + 363 + delay = 1000000 / sensor->odr; 364 + usleep_range(delay, 2 * delay); 365 + 366 + err = sensor->hw->tf->read(sensor->hw->dev, addr, sizeof(data), 367 + (u8 *)&data); 368 + if (err < 0) 369 + return err; 370 + 371 + st_lsm6dsx_sensor_disable(sensor); 372 + 373 + *val = (s16)data; 374 + 375 + return IIO_VAL_INT; 376 + } 377 + 378 + static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev, 379 + struct iio_chan_spec const *ch, 380 + int *val, int *val2, long mask) 381 + { 382 + struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 383 + int ret; 384 + 385 + switch (mask) { 386 + case IIO_CHAN_INFO_RAW: 387 + ret = iio_device_claim_direct_mode(iio_dev); 388 + if (ret) 389 + break; 390 + 391 + ret = st_lsm6dsx_read_oneshot(sensor, ch->address, val); 392 + iio_device_release_direct_mode(iio_dev); 393 + break; 394 + case IIO_CHAN_INFO_SAMP_FREQ: 395 + *val = sensor->odr; 396 + ret = IIO_VAL_INT; 397 + break; 398 + case IIO_CHAN_INFO_SCALE: 399 + *val = 0; 400 + *val2 = sensor->gain; 401 + ret = IIO_VAL_INT_PLUS_MICRO; 402 + break; 403 + default: 404 + ret = -EINVAL; 405 + break; 406 + } 407 + 408 + return ret; 409 + } 410 + 411 + static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev, 412 + struct iio_chan_spec const *chan, 413 + int val, int val2, long mask) 414 + { 415 + struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 416 + int err; 417 + 418 + err = iio_device_claim_direct_mode(iio_dev); 419 + if (err) 420 + return err; 421 + 422 + switch (mask) { 423 + case IIO_CHAN_INFO_SCALE: 424 + err = st_lsm6dsx_set_full_scale(sensor, val2); 425 + break; 426 + case IIO_CHAN_INFO_SAMP_FREQ: 427 + err = st_lsm6dsx_set_odr(sensor, val); 428 + break; 429 + default: 430 + err = -EINVAL; 431 + break; 432 + } 433 + 434 + iio_device_release_direct_mode(iio_dev); 435 + 436 + return err; 437 + } 438 + 439 + static int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val) 440 + { 441 + struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); 442 + struct st_lsm6dsx_hw *hw = sensor->hw; 443 + int err, max_fifo_len; 444 + 445 + max_fifo_len = hw->settings->max_fifo_size / ST_LSM6DSX_SAMPLE_SIZE; 446 + if (val < 1 || val > max_fifo_len) 447 + return -EINVAL; 448 + 449 + err = st_lsm6dsx_update_watermark(sensor, val); 450 + if (err < 0) 451 + return err; 452 + 453 + sensor->watermark = val; 454 + 455 + return 0; 456 + } 457 + 458 + static ssize_t 459 + st_lsm6dsx_sysfs_sampling_frequency_avail(struct device *dev, 460 + struct device_attribute *attr, 461 + char *buf) 462 + { 463 + struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev)); 464 + enum st_lsm6dsx_sensor_id id = sensor->id; 465 + int i, len = 0; 466 + 467 + for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++) 468 + len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", 469 + st_lsm6dsx_odr_table[id].odr_avl[i].hz); 470 + buf[len - 1] = '\n'; 471 + 472 + return len; 473 + } 474 + 475 + static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev, 476 + struct device_attribute *attr, 477 + char *buf) 478 + { 479 + struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev)); 480 + enum st_lsm6dsx_sensor_id id = sensor->id; 481 + int i, len = 0; 482 + 483 + for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) 484 + len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", 485 + st_lsm6dsx_fs_table[id].fs_avl[i].gain); 486 + buf[len - 1] = '\n'; 487 + 488 + return len; 489 + } 490 + 491 + static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(st_lsm6dsx_sysfs_sampling_frequency_avail); 492 + static IIO_DEVICE_ATTR(in_accel_scale_available, 0444, 493 + st_lsm6dsx_sysfs_scale_avail, NULL, 0); 494 + static IIO_DEVICE_ATTR(in_anglvel_scale_available, 0444, 495 + st_lsm6dsx_sysfs_scale_avail, NULL, 0); 496 + 497 + static struct attribute *st_lsm6dsx_acc_attributes[] = { 498 + &iio_dev_attr_sampling_frequency_available.dev_attr.attr, 499 + &iio_dev_attr_in_accel_scale_available.dev_attr.attr, 500 + NULL, 501 + }; 502 + 503 + static const struct attribute_group st_lsm6dsx_acc_attribute_group = { 504 + .attrs = st_lsm6dsx_acc_attributes, 505 + }; 506 + 507 + static const struct iio_info st_lsm6dsx_acc_info = { 508 + .driver_module = THIS_MODULE, 509 + .attrs = &st_lsm6dsx_acc_attribute_group, 510 + .read_raw = st_lsm6dsx_read_raw, 511 + .write_raw = st_lsm6dsx_write_raw, 512 + .hwfifo_set_watermark = st_lsm6dsx_set_watermark, 513 + }; 514 + 515 + static struct attribute *st_lsm6dsx_gyro_attributes[] = { 516 + &iio_dev_attr_sampling_frequency_available.dev_attr.attr, 517 + &iio_dev_attr_in_anglvel_scale_available.dev_attr.attr, 518 + NULL, 519 + }; 520 + 521 + static const struct attribute_group st_lsm6dsx_gyro_attribute_group = { 522 + .attrs = st_lsm6dsx_gyro_attributes, 523 + }; 524 + 525 + static const struct iio_info st_lsm6dsx_gyro_info = { 526 + .driver_module = THIS_MODULE, 527 + .attrs = &st_lsm6dsx_gyro_attribute_group, 528 + .read_raw = st_lsm6dsx_read_raw, 529 + .write_raw = st_lsm6dsx_write_raw, 530 + .hwfifo_set_watermark = st_lsm6dsx_set_watermark, 531 + }; 532 + 533 + static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7, 0x0}; 534 + 535 + static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw) 536 + { 537 + int err; 538 + u8 data; 539 + 540 + data = ST_LSM6DSX_REG_RESET_MASK; 541 + err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_RESET_ADDR, sizeof(data), 542 + &data); 543 + if (err < 0) 544 + return err; 545 + 546 + msleep(200); 547 + 548 + /* latch interrupts */ 549 + err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_LIR_ADDR, 550 + ST_LSM6DSX_REG_LIR_MASK, 1); 551 + if (err < 0) 552 + return err; 553 + 554 + /* enable Block Data Update */ 555 + err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_BDU_ADDR, 556 + ST_LSM6DSX_REG_BDU_MASK, 1); 557 + if (err < 0) 558 + return err; 559 + 560 + err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_ROUNDING_ADDR, 561 + ST_LSM6DSX_REG_ROUNDING_MASK, 1); 562 + if (err < 0) 563 + return err; 564 + 565 + /* enable FIFO watermak interrupt */ 566 + err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_INT1_ADDR, 567 + ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK, 1); 568 + if (err < 0) 569 + return err; 570 + 571 + /* redirect INT2 on INT1 */ 572 + return st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_INT2_ON_INT1_ADDR, 573 + ST_LSM6DSX_REG_INT2_ON_INT1_MASK, 1); 574 + } 575 + 576 + static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw, 577 + enum st_lsm6dsx_sensor_id id) 578 + { 579 + struct st_lsm6dsx_sensor *sensor; 580 + struct iio_dev *iio_dev; 581 + 582 + iio_dev = devm_iio_device_alloc(hw->dev, sizeof(*sensor)); 583 + if (!iio_dev) 584 + return NULL; 585 + 586 + iio_dev->modes = INDIO_DIRECT_MODE; 587 + iio_dev->dev.parent = hw->dev; 588 + iio_dev->available_scan_masks = st_lsm6dsx_available_scan_masks; 589 + 590 + sensor = iio_priv(iio_dev); 591 + sensor->id = id; 592 + sensor->hw = hw; 593 + sensor->odr = st_lsm6dsx_odr_table[id].odr_avl[0].hz; 594 + sensor->gain = st_lsm6dsx_fs_table[id].fs_avl[0].gain; 595 + sensor->watermark = 1; 596 + 597 + switch (id) { 598 + case ST_LSM6DSX_ID_ACC: 599 + iio_dev->channels = st_lsm6dsx_acc_channels; 600 + iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_acc_channels); 601 + iio_dev->name = "lsm6dsx_accel"; 602 + iio_dev->info = &st_lsm6dsx_acc_info; 603 + 604 + sensor->decimator_mask = ST_LSM6DSX_REG_ACC_DEC_MASK; 605 + break; 606 + case ST_LSM6DSX_ID_GYRO: 607 + iio_dev->channels = st_lsm6dsx_gyro_channels; 608 + iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_gyro_channels); 609 + iio_dev->name = "lsm6dsx_gyro"; 610 + iio_dev->info = &st_lsm6dsx_gyro_info; 611 + 612 + sensor->decimator_mask = ST_LSM6DSX_REG_GYRO_DEC_MASK; 613 + break; 614 + default: 615 + return NULL; 616 + } 617 + 618 + return iio_dev; 619 + } 620 + 621 + int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, 622 + const struct st_lsm6dsx_transfer_function *tf_ops) 623 + { 624 + struct st_lsm6dsx_hw *hw; 625 + int i, err; 626 + 627 + hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL); 628 + if (!hw) 629 + return -ENOMEM; 630 + 631 + dev_set_drvdata(dev, (void *)hw); 632 + 633 + mutex_init(&hw->lock); 634 + mutex_init(&hw->fifo_lock); 635 + 636 + hw->dev = dev; 637 + hw->irq = irq; 638 + hw->tf = tf_ops; 639 + 640 + err = st_lsm6dsx_check_whoami(hw, hw_id); 641 + if (err < 0) 642 + return err; 643 + 644 + for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 645 + hw->iio_devs[i] = st_lsm6dsx_alloc_iiodev(hw, i); 646 + if (!hw->iio_devs[i]) 647 + return -ENOMEM; 648 + } 649 + 650 + err = st_lsm6dsx_init_device(hw); 651 + if (err < 0) 652 + return err; 653 + 654 + if (hw->irq > 0) { 655 + err = st_lsm6dsx_fifo_setup(hw); 656 + if (err < 0) 657 + return err; 658 + } 659 + 660 + for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { 661 + err = devm_iio_device_register(hw->dev, hw->iio_devs[i]); 662 + if (err) 663 + return err; 664 + } 665 + 666 + return 0; 667 + } 668 + EXPORT_SYMBOL(st_lsm6dsx_probe); 669 + 670 + MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); 671 + MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 672 + MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx driver"); 673 + MODULE_LICENSE("GPL v2");
+101
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
··· 1 + /* 2 + * STMicroelectronics st_lsm6dsx i2c driver 3 + * 4 + * Copyright 2016 STMicroelectronics Inc. 5 + * 6 + * Lorenzo Bianconi <lorenzo.bianconi@st.com> 7 + * Denis Ciocca <denis.ciocca@st.com> 8 + * 9 + * Licensed under the GPL-2. 10 + */ 11 + 12 + #include <linux/kernel.h> 13 + #include <linux/module.h> 14 + #include <linux/i2c.h> 15 + #include <linux/slab.h> 16 + #include <linux/of.h> 17 + 18 + #include "st_lsm6dsx.h" 19 + 20 + static int st_lsm6dsx_i2c_read(struct device *dev, u8 addr, int len, u8 *data) 21 + { 22 + struct i2c_client *client = to_i2c_client(dev); 23 + struct i2c_msg msg[2]; 24 + 25 + msg[0].addr = client->addr; 26 + msg[0].flags = client->flags; 27 + msg[0].len = 1; 28 + msg[0].buf = &addr; 29 + 30 + msg[1].addr = client->addr; 31 + msg[1].flags = client->flags | I2C_M_RD; 32 + msg[1].len = len; 33 + msg[1].buf = data; 34 + 35 + return i2c_transfer(client->adapter, msg, 2); 36 + } 37 + 38 + static int st_lsm6dsx_i2c_write(struct device *dev, u8 addr, int len, u8 *data) 39 + { 40 + struct i2c_client *client = to_i2c_client(dev); 41 + struct i2c_msg msg; 42 + u8 send[len + 1]; 43 + 44 + send[0] = addr; 45 + memcpy(&send[1], data, len * sizeof(u8)); 46 + 47 + msg.addr = client->addr; 48 + msg.flags = client->flags; 49 + msg.len = len + 1; 50 + msg.buf = send; 51 + 52 + return i2c_transfer(client->adapter, &msg, 1); 53 + } 54 + 55 + static const struct st_lsm6dsx_transfer_function st_lsm6dsx_transfer_fn = { 56 + .read = st_lsm6dsx_i2c_read, 57 + .write = st_lsm6dsx_i2c_write, 58 + }; 59 + 60 + static int st_lsm6dsx_i2c_probe(struct i2c_client *client, 61 + const struct i2c_device_id *id) 62 + { 63 + return st_lsm6dsx_probe(&client->dev, client->irq, 64 + (int)id->driver_data, 65 + &st_lsm6dsx_transfer_fn); 66 + } 67 + 68 + static const struct of_device_id st_lsm6dsx_i2c_of_match[] = { 69 + { 70 + .compatible = "st,lsm6ds3", 71 + .data = (void *)ST_LSM6DS3_ID, 72 + }, 73 + { 74 + .compatible = "st,lsm6dsm", 75 + .data = (void *)ST_LSM6DSM_ID, 76 + }, 77 + {}, 78 + }; 79 + MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match); 80 + 81 + static const struct i2c_device_id st_lsm6dsx_i2c_id_table[] = { 82 + { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID }, 83 + { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID }, 84 + {}, 85 + }; 86 + MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table); 87 + 88 + static struct i2c_driver st_lsm6dsx_driver = { 89 + .driver = { 90 + .name = "st_lsm6dsx_i2c", 91 + .of_match_table = of_match_ptr(st_lsm6dsx_i2c_of_match), 92 + }, 93 + .probe = st_lsm6dsx_i2c_probe, 94 + .id_table = st_lsm6dsx_i2c_id_table, 95 + }; 96 + module_i2c_driver(st_lsm6dsx_driver); 97 + 98 + MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); 99 + MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 100 + MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i2c driver"); 101 + MODULE_LICENSE("GPL v2");
+118
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
··· 1 + /* 2 + * STMicroelectronics st_lsm6dsx spi driver 3 + * 4 + * Copyright 2016 STMicroelectronics Inc. 5 + * 6 + * Lorenzo Bianconi <lorenzo.bianconi@st.com> 7 + * Denis Ciocca <denis.ciocca@st.com> 8 + * 9 + * Licensed under the GPL-2. 10 + */ 11 + 12 + #include <linux/kernel.h> 13 + #include <linux/module.h> 14 + #include <linux/spi/spi.h> 15 + #include <linux/slab.h> 16 + #include <linux/of.h> 17 + 18 + #include "st_lsm6dsx.h" 19 + 20 + #define SENSORS_SPI_READ BIT(7) 21 + 22 + static int st_lsm6dsx_spi_read(struct device *dev, u8 addr, int len, 23 + u8 *data) 24 + { 25 + struct spi_device *spi = to_spi_device(dev); 26 + struct st_lsm6dsx_hw *hw = spi_get_drvdata(spi); 27 + int err; 28 + 29 + struct spi_transfer xfers[] = { 30 + { 31 + .tx_buf = hw->tb.tx_buf, 32 + .bits_per_word = 8, 33 + .len = 1, 34 + }, 35 + { 36 + .rx_buf = hw->tb.rx_buf, 37 + .bits_per_word = 8, 38 + .len = len, 39 + } 40 + }; 41 + 42 + hw->tb.tx_buf[0] = addr | SENSORS_SPI_READ; 43 + 44 + err = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers)); 45 + if (err < 0) 46 + return err; 47 + 48 + memcpy(data, hw->tb.rx_buf, len * sizeof(u8)); 49 + 50 + return len; 51 + } 52 + 53 + static int st_lsm6dsx_spi_write(struct device *dev, u8 addr, int len, 54 + u8 *data) 55 + { 56 + struct st_lsm6dsx_hw *hw; 57 + struct spi_device *spi; 58 + 59 + if (len >= ST_LSM6DSX_TX_MAX_LENGTH) 60 + return -ENOMEM; 61 + 62 + spi = to_spi_device(dev); 63 + hw = spi_get_drvdata(spi); 64 + 65 + hw->tb.tx_buf[0] = addr; 66 + memcpy(&hw->tb.tx_buf[1], data, len); 67 + 68 + return spi_write(spi, hw->tb.tx_buf, len + 1); 69 + } 70 + 71 + static const struct st_lsm6dsx_transfer_function st_lsm6dsx_transfer_fn = { 72 + .read = st_lsm6dsx_spi_read, 73 + .write = st_lsm6dsx_spi_write, 74 + }; 75 + 76 + static int st_lsm6dsx_spi_probe(struct spi_device *spi) 77 + { 78 + const struct spi_device_id *id = spi_get_device_id(spi); 79 + 80 + return st_lsm6dsx_probe(&spi->dev, spi->irq, 81 + (int)id->driver_data, 82 + &st_lsm6dsx_transfer_fn); 83 + } 84 + 85 + static const struct of_device_id st_lsm6dsx_spi_of_match[] = { 86 + { 87 + .compatible = "st,lsm6ds3", 88 + .data = (void *)ST_LSM6DS3_ID, 89 + }, 90 + { 91 + .compatible = "st,lsm6dsm", 92 + .data = (void *)ST_LSM6DSM_ID, 93 + }, 94 + {}, 95 + }; 96 + MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match); 97 + 98 + static const struct spi_device_id st_lsm6dsx_spi_id_table[] = { 99 + { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID }, 100 + { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID }, 101 + {}, 102 + }; 103 + MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table); 104 + 105 + static struct spi_driver st_lsm6dsx_driver = { 106 + .driver = { 107 + .name = "st_lsm6dsx_spi", 108 + .of_match_table = of_match_ptr(st_lsm6dsx_spi_of_match), 109 + }, 110 + .probe = st_lsm6dsx_spi_probe, 111 + .id_table = st_lsm6dsx_spi_id_table, 112 + }; 113 + module_spi_driver(st_lsm6dsx_driver); 114 + 115 + MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); 116 + MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 117 + MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx spi driver"); 118 + MODULE_LICENSE("GPL v2");
+47 -43
drivers/iio/industrialio-trigger.c
··· 147 147 return NULL; 148 148 } 149 149 150 - static struct iio_trigger *iio_trigger_find_by_name(const char *name, 151 - size_t len) 150 + static struct iio_trigger *iio_trigger_acquire_by_name(const char *name) 152 151 { 153 152 struct iio_trigger *trig = NULL, *iter; 154 153 ··· 155 156 list_for_each_entry(iter, &iio_trigger_list, list) 156 157 if (sysfs_streq(iter->name, name)) { 157 158 trig = iter; 159 + iio_trigger_get(trig); 158 160 break; 159 161 } 160 162 mutex_unlock(&iio_trigger_list_lock); ··· 416 416 } 417 417 mutex_unlock(&indio_dev->mlock); 418 418 419 - trig = iio_trigger_find_by_name(buf, len); 420 - if (oldtrig == trig) 421 - return len; 419 + trig = iio_trigger_acquire_by_name(buf); 420 + if (oldtrig == trig) { 421 + ret = len; 422 + goto out_trigger_put; 423 + } 422 424 423 425 if (trig && indio_dev->info->validate_trigger) { 424 426 ret = indio_dev->info->validate_trigger(indio_dev, trig); 425 427 if (ret) 426 - return ret; 428 + goto out_trigger_put; 427 429 } 428 430 429 431 if (trig && trig->ops->validate_device) { 430 432 ret = trig->ops->validate_device(trig, indio_dev); 431 433 if (ret) 432 - return ret; 434 + goto out_trigger_put; 433 435 } 434 436 435 437 indio_dev->trig = trig; ··· 443 441 iio_trigger_put(oldtrig); 444 442 } 445 443 if (indio_dev->trig) { 446 - iio_trigger_get(indio_dev->trig); 447 444 if (indio_dev->modes & INDIO_EVENT_TRIGGERED) 448 445 iio_trigger_attach_poll_func(indio_dev->trig, 449 446 indio_dev->pollfunc_event); 450 447 } 451 448 452 449 return len; 450 + 451 + out_trigger_put: 452 + iio_trigger_put(trig); 453 + return ret; 453 454 } 454 455 455 456 static DEVICE_ATTR(current_trigger, S_IRUGO | S_IWUSR, ··· 492 487 kfree(trig); 493 488 } 494 489 495 - static struct device_type iio_trig_type = { 490 + static const struct device_type iio_trig_type = { 496 491 .release = iio_trig_release, 497 492 .groups = iio_trig_dev_groups, 498 493 }; ··· 518 513 static struct iio_trigger *viio_trigger_alloc(const char *fmt, va_list vargs) 519 514 { 520 515 struct iio_trigger *trig; 516 + int i; 517 + 521 518 trig = kzalloc(sizeof *trig, GFP_KERNEL); 522 - if (trig) { 523 - int i; 524 - trig->dev.type = &iio_trig_type; 525 - trig->dev.bus = &iio_bus_type; 526 - device_initialize(&trig->dev); 519 + if (!trig) 520 + return NULL; 527 521 528 - mutex_init(&trig->pool_lock); 529 - trig->subirq_base 530 - = irq_alloc_descs(-1, 0, 531 - CONFIG_IIO_CONSUMERS_PER_TRIGGER, 532 - 0); 533 - if (trig->subirq_base < 0) { 534 - kfree(trig); 535 - return NULL; 536 - } 522 + trig->dev.type = &iio_trig_type; 523 + trig->dev.bus = &iio_bus_type; 524 + device_initialize(&trig->dev); 537 525 538 - trig->name = kvasprintf(GFP_KERNEL, fmt, vargs); 539 - if (trig->name == NULL) { 540 - irq_free_descs(trig->subirq_base, 541 - CONFIG_IIO_CONSUMERS_PER_TRIGGER); 542 - kfree(trig); 543 - return NULL; 544 - } 545 - trig->subirq_chip.name = trig->name; 546 - trig->subirq_chip.irq_mask = &iio_trig_subirqmask; 547 - trig->subirq_chip.irq_unmask = &iio_trig_subirqunmask; 548 - for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { 549 - irq_set_chip(trig->subirq_base + i, 550 - &trig->subirq_chip); 551 - irq_set_handler(trig->subirq_base + i, 552 - &handle_simple_irq); 553 - irq_modify_status(trig->subirq_base + i, 554 - IRQ_NOREQUEST | IRQ_NOAUTOEN, 555 - IRQ_NOPROBE); 556 - } 557 - get_device(&trig->dev); 526 + mutex_init(&trig->pool_lock); 527 + trig->subirq_base = irq_alloc_descs(-1, 0, 528 + CONFIG_IIO_CONSUMERS_PER_TRIGGER, 529 + 0); 530 + if (trig->subirq_base < 0) 531 + goto free_trig; 532 + 533 + trig->name = kvasprintf(GFP_KERNEL, fmt, vargs); 534 + if (trig->name == NULL) 535 + goto free_descs; 536 + 537 + trig->subirq_chip.name = trig->name; 538 + trig->subirq_chip.irq_mask = &iio_trig_subirqmask; 539 + trig->subirq_chip.irq_unmask = &iio_trig_subirqunmask; 540 + for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { 541 + irq_set_chip(trig->subirq_base + i, &trig->subirq_chip); 542 + irq_set_handler(trig->subirq_base + i, &handle_simple_irq); 543 + irq_modify_status(trig->subirq_base + i, 544 + IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE); 558 545 } 546 + get_device(&trig->dev); 559 547 560 548 return trig; 549 + 550 + free_descs: 551 + irq_free_descs(trig->subirq_base, CONFIG_IIO_CONSUMERS_PER_TRIGGER); 552 + free_trig: 553 + kfree(trig); 554 + return NULL; 561 555 } 562 556 563 557 struct iio_trigger *iio_trigger_alloc(const char *fmt, ...)
+8 -2
drivers/iio/inkern.c
··· 601 601 602 602 scale_type = iio_channel_read(chan, &scale_val, &scale_val2, 603 603 IIO_CHAN_INFO_SCALE); 604 - if (scale_type < 0) 605 - return scale_type; 604 + if (scale_type < 0) { 605 + /* 606 + * Just pass raw values as processed if no scaling is 607 + * available. 608 + */ 609 + *processed = raw; 610 + return 0; 611 + } 606 612 607 613 switch (scale_type) { 608 614 case IIO_VAL_INT:
+2 -2
drivers/iio/light/cm3605.c
··· 278 278 return 0; 279 279 } 280 280 281 - static int cm3605_pm_suspend(struct device *dev) 281 + static int __maybe_unused cm3605_pm_suspend(struct device *dev) 282 282 { 283 283 struct iio_dev *indio_dev = dev_get_drvdata(dev); 284 284 struct cm3605 *cm3605 = iio_priv(indio_dev); ··· 289 289 return 0; 290 290 } 291 291 292 - static int cm3605_pm_resume(struct device *dev) 292 + static int __maybe_unused cm3605_pm_resume(struct device *dev) 293 293 { 294 294 struct iio_dev *indio_dev = dev_get_drvdata(dev); 295 295 struct cm3605 *cm3605 = iio_priv(indio_dev);
+1
drivers/iio/light/opt3001.c
··· 840 840 { .compatible = "ti,opt3001" }, 841 841 { } 842 842 }; 843 + MODULE_DEVICE_TABLE(of, opt3001_of_match); 843 844 844 845 static struct i2c_driver opt3001_driver = { 845 846 .probe = opt3001_probe,
+2 -6
drivers/iio/magnetometer/ak8974.c
··· 278 278 if (val & AK8974_STATUS_DRDY) 279 279 return 0; 280 280 } while (--timeout); 281 - if (!timeout) { 282 - dev_err(&ak8974->i2c->dev, 283 - "timeout waiting for DRDY\n"); 284 - return -ETIMEDOUT; 285 - } 286 281 287 - return 0; 282 + dev_err(&ak8974->i2c->dev, "timeout waiting for DRDY\n"); 283 + return -ETIMEDOUT; 288 284 } 289 285 290 286 static int ak8974_getresult(struct ak8974 *ak8974, __le16 *result)
+20 -10
drivers/iio/magnetometer/mag3110.c
··· 222 222 int val, int val2, long mask) 223 223 { 224 224 struct mag3110_data *data = iio_priv(indio_dev); 225 - int rate; 225 + int rate, ret; 226 226 227 - if (iio_buffer_enabled(indio_dev)) 228 - return -EBUSY; 227 + ret = iio_device_claim_direct_mode(indio_dev); 228 + if (ret) 229 + return ret; 229 230 230 231 switch (mask) { 231 232 case IIO_CHAN_INFO_SAMP_FREQ: 232 233 rate = mag3110_get_samp_freq_index(data, val, val2); 233 - if (rate < 0) 234 - return -EINVAL; 234 + if (rate < 0) { 235 + ret = -EINVAL; 236 + break; 237 + } 235 238 236 239 data->ctrl_reg1 &= ~MAG3110_CTRL_DR_MASK; 237 240 data->ctrl_reg1 |= rate << MAG3110_CTRL_DR_SHIFT; 238 - return i2c_smbus_write_byte_data(data->client, 241 + ret = i2c_smbus_write_byte_data(data->client, 239 242 MAG3110_CTRL_REG1, data->ctrl_reg1); 243 + break; 240 244 case IIO_CHAN_INFO_CALIBBIAS: 241 - if (val < -10000 || val > 10000) 242 - return -EINVAL; 243 - return i2c_smbus_write_word_swapped(data->client, 245 + if (val < -10000 || val > 10000) { 246 + ret = -EINVAL; 247 + break; 248 + } 249 + ret = i2c_smbus_write_word_swapped(data->client, 244 250 MAG3110_OFF_X + 2 * chan->scan_index, val << 1); 251 + break; 245 252 default: 246 - return -EINVAL; 253 + ret = -EINVAL; 254 + break; 247 255 } 256 + iio_device_release_direct_mode(indio_dev); 257 + return ret; 248 258 } 249 259 250 260 static irqreturn_t mag3110_trigger_handler(int irq, void *p)
+1
drivers/iio/potentiometer/mcp4531.c
··· 284 284 MCP4531_COMPATIBLE("microchip,mcp4662-104", MCP466x_104), 285 285 { /* sentinel */ } 286 286 }; 287 + MODULE_DEVICE_TABLE(of, mcp4531_of_match); 287 288 #endif 288 289 289 290 static int mcp4531_probe(struct i2c_client *client,
+7 -5
drivers/iio/pressure/ms5611_core.c
··· 308 308 { 309 309 struct ms5611_state *st = iio_priv(indio_dev); 310 310 const struct ms5611_osr *osr = NULL; 311 + int ret; 311 312 312 313 if (mask != IIO_CHAN_INFO_OVERSAMPLING_RATIO) 313 314 return -EINVAL; ··· 322 321 if (!osr) 323 322 return -EINVAL; 324 323 325 - mutex_lock(&st->lock); 324 + ret = iio_device_claim_direct_mode(indio_dev); 325 + if (ret) 326 + return ret; 326 327 327 - if (iio_buffer_enabled(indio_dev)) { 328 - mutex_unlock(&st->lock); 329 - return -EBUSY; 330 - } 328 + mutex_lock(&st->lock); 331 329 332 330 if (chan->type == IIO_TEMP) 333 331 st->temp_osr = osr; ··· 334 334 st->pressure_osr = osr; 335 335 336 336 mutex_unlock(&st->lock); 337 + iio_device_release_direct_mode(indio_dev); 338 + 337 339 return 0; 338 340 } 339 341
+7 -3
drivers/iio/proximity/sx9500.c
··· 387 387 int *val, int *val2, long mask) 388 388 { 389 389 struct sx9500_data *data = iio_priv(indio_dev); 390 + int ret; 390 391 391 392 switch (chan->type) { 392 393 case IIO_PROXIMITY: 393 394 switch (mask) { 394 395 case IIO_CHAN_INFO_RAW: 395 - if (iio_buffer_enabled(indio_dev)) 396 - return -EBUSY; 397 - return sx9500_read_proximity(data, chan, val); 396 + ret = iio_device_claim_direct_mode(indio_dev); 397 + if (ret) 398 + return ret; 399 + ret = sx9500_read_proximity(data, chan, val); 400 + iio_device_release_direct_mode(indio_dev); 401 + return ret; 398 402 case IIO_CHAN_INFO_SAMP_FREQ: 399 403 return sx9500_read_samp_freq(data, val, val2); 400 404 default:
+10
drivers/iio/temperature/Kconfig
··· 39 39 This driver can also be built as a module. If so, the module will 40 40 be called tmp006. 41 41 42 + config TMP007 43 + tristate "TMP007 infrared thermopile sensor with Integrated Math Engine" 44 + depends on I2C 45 + help 46 + If you say yes here you get support for the Texas Instruments 47 + TMP007 infrared thermopile sensor with Integrated Math Engine. 48 + 49 + This driver can also be built as a module. If so, the module will 50 + be called tmp007. 51 + 42 52 config TSYS01 43 53 tristate "Measurement Specialties TSYS01 temperature sensor using I2C bus connection" 44 54 depends on I2C
+1
drivers/iio/temperature/Makefile
··· 5 5 obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o 6 6 obj-$(CONFIG_MLX90614) += mlx90614.o 7 7 obj-$(CONFIG_TMP006) += tmp006.o 8 + obj-$(CONFIG_TMP007) += tmp007.o 8 9 obj-$(CONFIG_TSYS01) += tsys01.o 9 10 obj-$(CONFIG_TSYS02D) += tsys02d.o
+345
drivers/iio/temperature/tmp007.c
··· 1 + /* 2 + * tmp007.c - Support for TI TMP007 IR thermopile sensor with integrated math engine 3 + * 4 + * Copyright (c) 2017 Manivannan Sadhasivam <manivannanece23@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 + * Driver for the Texas Instruments I2C 16-bit IR thermopile sensor 11 + * 12 + * (7-bit I2C slave address (0x40 - 0x47), changeable via ADR pins) 13 + * 14 + * Note: This driver assumes that the sensor has been calibrated beforehand 15 + * 16 + * TODO: ALERT irq, limit threshold events 17 + * 18 + */ 19 + 20 + #include <linux/err.h> 21 + #include <linux/i2c.h> 22 + #include <linux/delay.h> 23 + #include <linux/module.h> 24 + #include <linux/pm.h> 25 + #include <linux/bitops.h> 26 + #include <linux/of.h> 27 + 28 + #include <linux/iio/iio.h> 29 + #include <linux/iio/sysfs.h> 30 + 31 + #define TMP007_TDIE 0x01 32 + #define TMP007_CONFIG 0x02 33 + #define TMP007_TOBJECT 0x03 34 + #define TMP007_STATUS 0x04 35 + #define TMP007_STATUS_MASK 0x05 36 + #define TMP007_MANUFACTURER_ID 0x1e 37 + #define TMP007_DEVICE_ID 0x1f 38 + 39 + #define TMP007_CONFIG_CONV_EN BIT(12) 40 + #define TMP007_CONFIG_COMP_EN BIT(5) 41 + #define TMP007_CONFIG_TC_EN BIT(6) 42 + #define TMP007_CONFIG_CR_MASK GENMASK(11, 9) 43 + #define TMP007_CONFIG_CR_SHIFT 9 44 + 45 + #define TMP007_STATUS_CONV_READY BIT(14) 46 + #define TMP007_STATUS_DATA_VALID BIT(9) 47 + 48 + #define TMP007_MANUFACTURER_MAGIC 0x5449 49 + #define TMP007_DEVICE_MAGIC 0x0078 50 + 51 + #define TMP007_TEMP_SHIFT 2 52 + 53 + struct tmp007_data { 54 + struct i2c_client *client; 55 + u16 config; 56 + }; 57 + 58 + static const int tmp007_avgs[5][2] = { {4, 0}, {2, 0}, {1, 0}, 59 + {0, 500000}, {0, 250000} }; 60 + 61 + static int tmp007_read_temperature(struct tmp007_data *data, u8 reg) 62 + { 63 + s32 ret; 64 + int tries = 50; 65 + 66 + while (tries-- > 0) { 67 + ret = i2c_smbus_read_word_swapped(data->client, 68 + TMP007_STATUS); 69 + if (ret < 0) 70 + return ret; 71 + if ((ret & TMP007_STATUS_CONV_READY) && 72 + !(ret & TMP007_STATUS_DATA_VALID)) 73 + break; 74 + msleep(100); 75 + } 76 + 77 + if (tries < 0) 78 + return -EIO; 79 + 80 + return i2c_smbus_read_word_swapped(data->client, reg); 81 + } 82 + 83 + static int tmp007_powerdown(struct tmp007_data *data) 84 + { 85 + return i2c_smbus_write_word_swapped(data->client, TMP007_CONFIG, 86 + data->config & ~TMP007_CONFIG_CONV_EN); 87 + } 88 + 89 + static int tmp007_read_raw(struct iio_dev *indio_dev, 90 + struct iio_chan_spec const *channel, int *val, 91 + int *val2, long mask) 92 + { 93 + struct tmp007_data *data = iio_priv(indio_dev); 94 + s32 ret; 95 + int conv_rate; 96 + 97 + switch (mask) { 98 + case IIO_CHAN_INFO_RAW: 99 + switch (channel->channel2) { 100 + case IIO_MOD_TEMP_AMBIENT: /* LSB: 0.03125 degree Celsius */ 101 + ret = i2c_smbus_read_word_swapped(data->client, TMP007_TDIE); 102 + if (ret < 0) 103 + return ret; 104 + break; 105 + case IIO_MOD_TEMP_OBJECT: 106 + ret = tmp007_read_temperature(data, TMP007_TOBJECT); 107 + if (ret < 0) 108 + return ret; 109 + break; 110 + default: 111 + return -EINVAL; 112 + } 113 + 114 + *val = sign_extend32(ret, 15) >> TMP007_TEMP_SHIFT; 115 + 116 + return IIO_VAL_INT; 117 + case IIO_CHAN_INFO_SCALE: 118 + *val = 31; 119 + *val2 = 250000; 120 + 121 + return IIO_VAL_INT_PLUS_MICRO; 122 + case IIO_CHAN_INFO_SAMP_FREQ: 123 + conv_rate = (data->config & TMP007_CONFIG_CR_MASK) 124 + >> TMP007_CONFIG_CR_SHIFT; 125 + *val = tmp007_avgs[conv_rate][0]; 126 + *val2 = tmp007_avgs[conv_rate][1]; 127 + 128 + return IIO_VAL_INT_PLUS_MICRO; 129 + default: 130 + return -EINVAL; 131 + } 132 + } 133 + 134 + static int tmp007_write_raw(struct iio_dev *indio_dev, 135 + struct iio_chan_spec const *channel, int val, 136 + int val2, long mask) 137 + { 138 + struct tmp007_data *data = iio_priv(indio_dev); 139 + int i; 140 + u16 tmp; 141 + 142 + if (mask == IIO_CHAN_INFO_SAMP_FREQ) { 143 + for (i = 0; i < ARRAY_SIZE(tmp007_avgs); i++) { 144 + if ((val == tmp007_avgs[i][0]) && 145 + (val2 == tmp007_avgs[i][1])) { 146 + tmp = data->config & ~TMP007_CONFIG_CR_MASK; 147 + tmp |= (i << TMP007_CONFIG_CR_SHIFT); 148 + 149 + return i2c_smbus_write_word_swapped(data->client, 150 + TMP007_CONFIG, 151 + data->config = tmp); 152 + } 153 + } 154 + } 155 + 156 + return -EINVAL; 157 + } 158 + 159 + static IIO_CONST_ATTR(sampling_frequency_available, "4 2 1 0.5 0.25"); 160 + 161 + static struct attribute *tmp007_attributes[] = { 162 + &iio_const_attr_sampling_frequency_available.dev_attr.attr, 163 + NULL 164 + }; 165 + 166 + static const struct attribute_group tmp007_attribute_group = { 167 + .attrs = tmp007_attributes, 168 + }; 169 + 170 + static const struct iio_chan_spec tmp007_channels[] = { 171 + { 172 + .type = IIO_TEMP, 173 + .modified = 1, 174 + .channel2 = IIO_MOD_TEMP_AMBIENT, 175 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 176 + BIT(IIO_CHAN_INFO_SCALE), 177 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 178 + }, 179 + { 180 + .type = IIO_TEMP, 181 + .modified = 1, 182 + .channel2 = IIO_MOD_TEMP_OBJECT, 183 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 184 + BIT(IIO_CHAN_INFO_SCALE), 185 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 186 + } 187 + }; 188 + 189 + static const struct iio_info tmp007_info = { 190 + .read_raw = tmp007_read_raw, 191 + .write_raw = tmp007_write_raw, 192 + .attrs = &tmp007_attribute_group, 193 + .driver_module = THIS_MODULE, 194 + }; 195 + 196 + static bool tmp007_identify(struct i2c_client *client) 197 + { 198 + int manf_id, dev_id; 199 + 200 + manf_id = i2c_smbus_read_word_swapped(client, TMP007_MANUFACTURER_ID); 201 + if (manf_id < 0) 202 + return false; 203 + 204 + dev_id = i2c_smbus_read_word_swapped(client, TMP007_DEVICE_ID); 205 + if (dev_id < 0) 206 + return false; 207 + 208 + return (manf_id == TMP007_MANUFACTURER_MAGIC && dev_id == TMP007_DEVICE_MAGIC); 209 + } 210 + 211 + static int tmp007_probe(struct i2c_client *client, 212 + const struct i2c_device_id *tmp007_id) 213 + { 214 + struct tmp007_data *data; 215 + struct iio_dev *indio_dev; 216 + int ret; 217 + u16 status; 218 + 219 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 220 + return -EOPNOTSUPP; 221 + 222 + if (!tmp007_identify(client)) { 223 + dev_err(&client->dev, "TMP007 not found\n"); 224 + return -ENODEV; 225 + } 226 + 227 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 228 + if (!indio_dev) 229 + return -ENOMEM; 230 + 231 + data = iio_priv(indio_dev); 232 + i2c_set_clientdata(client, indio_dev); 233 + data->client = client; 234 + 235 + indio_dev->dev.parent = &client->dev; 236 + indio_dev->name = dev_name(&client->dev); 237 + indio_dev->modes = INDIO_DIRECT_MODE; 238 + indio_dev->info = &tmp007_info; 239 + 240 + indio_dev->channels = tmp007_channels; 241 + indio_dev->num_channels = ARRAY_SIZE(tmp007_channels); 242 + 243 + /* 244 + * Set Configuration register: 245 + * 1. Conversion ON 246 + * 2. Comparator mode 247 + * 3. Transient correction enable 248 + */ 249 + 250 + ret = i2c_smbus_read_word_swapped(data->client, TMP007_CONFIG); 251 + if (ret < 0) 252 + return ret; 253 + 254 + data->config = ret; 255 + data->config |= (TMP007_CONFIG_CONV_EN | TMP007_CONFIG_COMP_EN | TMP007_CONFIG_TC_EN); 256 + 257 + ret = i2c_smbus_write_word_swapped(data->client, TMP007_CONFIG, 258 + data->config); 259 + if (ret < 0) 260 + return ret; 261 + 262 + /* 263 + * Set Status Mask register: 264 + * 1. Conversion ready enable 265 + * 2. Data valid enable 266 + */ 267 + 268 + ret = i2c_smbus_read_word_swapped(data->client, TMP007_STATUS_MASK); 269 + if (ret < 0) 270 + goto error_powerdown; 271 + 272 + status = ret; 273 + status |= (TMP007_STATUS_CONV_READY | TMP007_STATUS_DATA_VALID); 274 + 275 + ret = i2c_smbus_write_word_swapped(data->client, TMP007_STATUS_MASK, status); 276 + if (ret < 0) 277 + goto error_powerdown; 278 + 279 + return iio_device_register(indio_dev); 280 + 281 + error_powerdown: 282 + tmp007_powerdown(data); 283 + 284 + return ret; 285 + } 286 + 287 + static int tmp007_remove(struct i2c_client *client) 288 + { 289 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 290 + struct tmp007_data *data = iio_priv(indio_dev); 291 + 292 + iio_device_unregister(indio_dev); 293 + tmp007_powerdown(data); 294 + 295 + return 0; 296 + } 297 + 298 + #ifdef CONFIG_PM_SLEEP 299 + static int tmp007_suspend(struct device *dev) 300 + { 301 + struct tmp007_data *data = iio_priv(i2c_get_clientdata( 302 + to_i2c_client(dev))); 303 + 304 + return tmp007_powerdown(data); 305 + } 306 + 307 + static int tmp007_resume(struct device *dev) 308 + { 309 + struct tmp007_data *data = iio_priv(i2c_get_clientdata( 310 + to_i2c_client(dev))); 311 + 312 + return i2c_smbus_write_word_swapped(data->client, TMP007_CONFIG, 313 + data->config | TMP007_CONFIG_CONV_EN); 314 + } 315 + #endif 316 + 317 + static SIMPLE_DEV_PM_OPS(tmp007_pm_ops, tmp007_suspend, tmp007_resume); 318 + 319 + static const struct of_device_id tmp007_of_match[] = { 320 + { .compatible = "ti,tmp007", }, 321 + { }, 322 + }; 323 + MODULE_DEVICE_TABLE(of, tmp007_of_match); 324 + 325 + static const struct i2c_device_id tmp007_id[] = { 326 + { "tmp007", 0 }, 327 + { } 328 + }; 329 + MODULE_DEVICE_TABLE(i2c, tmp007_id); 330 + 331 + static struct i2c_driver tmp007_driver = { 332 + .driver = { 333 + .name = "tmp007", 334 + .of_match_table = of_match_ptr(tmp007_of_match), 335 + .pm = &tmp007_pm_ops, 336 + }, 337 + .probe = tmp007_probe, 338 + .remove = tmp007_remove, 339 + .id_table = tmp007_id, 340 + }; 341 + module_i2c_driver(tmp007_driver); 342 + 343 + MODULE_AUTHOR("Manivannan Sadhasivam <manivannanece23@gmail.com>"); 344 + MODULE_DESCRIPTION("TI TMP007 IR thermopile sensor driver"); 345 + MODULE_LICENSE("GPL");
+4 -4
drivers/iio/trigger/iio-trig-interrupt.c
··· 58 58 trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL); 59 59 if (!trig_info) { 60 60 ret = -ENOMEM; 61 - goto error_put_trigger; 61 + goto error_free_trigger; 62 62 } 63 63 iio_trigger_set_drvdata(trig, trig_info); 64 64 trig_info->irq = irq; ··· 83 83 free_irq(irq, trig); 84 84 error_free_trig_info: 85 85 kfree(trig_info); 86 - error_put_trigger: 87 - iio_trigger_put(trig); 86 + error_free_trigger: 87 + iio_trigger_free(trig); 88 88 error_ret: 89 89 return ret; 90 90 } ··· 99 99 iio_trigger_unregister(trig); 100 100 free_irq(trig_info->irq, trig); 101 101 kfree(trig_info); 102 - iio_trigger_put(trig); 102 + iio_trigger_free(trig); 103 103 104 104 return 0; 105 105 }
+1 -1
drivers/iio/trigger/iio-trig-sysfs.c
··· 174 174 return 0; 175 175 176 176 out2: 177 - iio_trigger_put(t->trig); 177 + iio_trigger_free(t->trig); 178 178 free_t: 179 179 kfree(t); 180 180 out1:
+231 -112
drivers/staging/iio/light/isl29028.c
··· 26 26 #include <linux/regmap.h> 27 27 #include <linux/iio/iio.h> 28 28 #include <linux/iio/sysfs.h> 29 + #include <linux/pm_runtime.h> 29 30 30 31 #define ISL29028_CONV_TIME_MS 100 31 32 ··· 61 60 62 61 #define ISL29028_NUM_REGS (ISL29028_REG_TEST2_MODE + 1) 63 62 63 + #define ISL29028_POWER_OFF_DELAY_MS 2000 64 + 64 65 enum isl29028_als_ir_mode { 65 66 ISL29028_MODE_NONE = 0, 66 67 ISL29028_MODE_ALS, ··· 70 67 }; 71 68 72 69 struct isl29028_chip { 73 - struct mutex lock; 74 - struct regmap *regmap; 75 - 76 - unsigned int prox_sampling; 77 - bool enable_prox; 78 - 79 - int lux_scale; 70 + struct mutex lock; 71 + struct regmap *regmap; 72 + unsigned int prox_sampling; 73 + bool enable_prox; 74 + int lux_scale; 80 75 enum isl29028_als_ir_mode als_ir_mode; 81 76 }; 82 77 83 78 static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, 84 79 unsigned int sampling) 85 80 { 81 + struct device *dev = regmap_get_device(chip->regmap); 86 82 static unsigned int prox_period[] = {800, 400, 200, 100, 75, 50, 12, 0}; 87 - int sel; 88 83 unsigned int period = DIV_ROUND_UP(1000, sampling); 84 + int sel, ret; 89 85 90 86 for (sel = 0; sel < ARRAY_SIZE(prox_period); ++sel) { 91 87 if (period >= prox_period[sel]) 92 88 break; 93 89 } 94 - return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 95 - ISL29028_CONF_PROX_SLP_MASK, 96 - sel << ISL29028_CONF_PROX_SLP_SH); 90 + 91 + ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 92 + ISL29028_CONF_PROX_SLP_MASK, 93 + sel << ISL29028_CONF_PROX_SLP_SH); 94 + 95 + if (ret < 0) { 96 + dev_err(dev, "%s(): Error %d setting the proximity sampling\n", 97 + __func__, ret); 98 + return ret; 99 + } 100 + 101 + chip->prox_sampling = sampling; 102 + 103 + return ret; 97 104 } 98 105 99 - static int isl29028_enable_proximity(struct isl29028_chip *chip, bool enable) 106 + static int isl29028_enable_proximity(struct isl29028_chip *chip) 100 107 { 101 108 int ret; 102 - int val = 0; 103 109 104 - if (enable) 105 - val = ISL29028_CONF_PROX_EN; 110 + ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling); 111 + if (ret < 0) 112 + return ret; 113 + 106 114 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 107 - ISL29028_CONF_PROX_EN_MASK, val); 115 + ISL29028_CONF_PROX_EN_MASK, 116 + ISL29028_CONF_PROX_EN); 108 117 if (ret < 0) 109 118 return ret; 110 119 111 120 /* Wait for conversion to be complete for first sample */ 112 121 mdelay(DIV_ROUND_UP(1000, chip->prox_sampling)); 122 + 113 123 return 0; 114 124 } 115 125 116 126 static int isl29028_set_als_scale(struct isl29028_chip *chip, int lux_scale) 117 127 { 128 + struct device *dev = regmap_get_device(chip->regmap); 118 129 int val = (lux_scale == 2000) ? ISL29028_CONF_ALS_RANGE_HIGH_LUX : 119 130 ISL29028_CONF_ALS_RANGE_LOW_LUX; 131 + int ret; 120 132 121 - return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 122 - ISL29028_CONF_ALS_RANGE_MASK, val); 133 + ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 134 + ISL29028_CONF_ALS_RANGE_MASK, val); 135 + if (ret < 0) { 136 + dev_err(dev, "%s(): Error %d setting the ALS scale\n", __func__, 137 + ret); 138 + return ret; 139 + } 140 + 141 + chip->lux_scale = lux_scale; 142 + 143 + return ret; 123 144 } 124 145 125 146 static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, 126 147 enum isl29028_als_ir_mode mode) 127 148 { 128 - int ret = 0; 149 + int ret; 129 150 130 151 if (chip->als_ir_mode == mode) 131 152 return 0; 153 + 154 + ret = isl29028_set_als_scale(chip, chip->lux_scale); 155 + if (ret < 0) 156 + return ret; 132 157 133 158 switch (mode) { 134 159 case ISL29028_MODE_ALS: ··· 170 139 ISL29028_CONF_ALS_RANGE_MASK, 171 140 ISL29028_CONF_ALS_RANGE_HIGH_LUX); 172 141 break; 173 - 174 142 case ISL29028_MODE_IR: 175 143 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 176 144 ISL29028_CONF_ALS_IR_MODE_MASK, 177 145 ISL29028_CONF_ALS_IR_MODE_IR); 178 146 break; 179 - 180 147 case ISL29028_MODE_NONE: 181 148 return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 182 - ISL29028_CONF_ALS_EN_MASK, ISL29028_CONF_ALS_DIS); 149 + ISL29028_CONF_ALS_EN_MASK, 150 + ISL29028_CONF_ALS_DIS); 183 151 } 184 152 185 153 if (ret < 0) ··· 209 179 ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_L, &lsb); 210 180 if (ret < 0) { 211 181 dev_err(dev, 212 - "Error in reading register ALSIR_L err %d\n", ret); 182 + "%s(): Error %d reading register ALSIR_L\n", 183 + __func__, ret); 213 184 return ret; 214 185 } 215 186 216 187 ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_U, &msb); 217 188 if (ret < 0) { 218 189 dev_err(dev, 219 - "Error in reading register ALSIR_U err %d\n", ret); 190 + "%s(): Error %d reading register ALSIR_U\n", 191 + __func__, ret); 220 192 return ret; 221 193 } 222 194 223 195 *als_ir = ((msb & 0xF) << 8) | (lsb & 0xFF); 196 + 224 197 return 0; 225 198 } 226 199 ··· 233 200 unsigned int data; 234 201 int ret; 235 202 236 - ret = regmap_read(chip->regmap, ISL29028_REG_PROX_DATA, &data); 237 - if (ret < 0) { 238 - dev_err(dev, "Error in reading register %d, error %d\n", 239 - ISL29028_REG_PROX_DATA, ret); 240 - return ret; 241 - } 242 - *prox = data; 243 - return 0; 244 - } 245 - 246 - static int isl29028_proxim_get(struct isl29028_chip *chip, int *prox_data) 247 - { 248 - int ret; 249 - 250 203 if (!chip->enable_prox) { 251 - ret = isl29028_enable_proximity(chip, true); 204 + ret = isl29028_enable_proximity(chip); 252 205 if (ret < 0) 253 206 return ret; 207 + 254 208 chip->enable_prox = true; 255 209 } 256 - return isl29028_read_proxim(chip, prox_data); 210 + 211 + ret = regmap_read(chip->regmap, ISL29028_REG_PROX_DATA, &data); 212 + if (ret < 0) { 213 + dev_err(dev, "%s(): Error %d reading register PROX_DATA\n", 214 + __func__, ret); 215 + return ret; 216 + } 217 + 218 + *prox = data; 219 + 220 + return 0; 257 221 } 258 222 259 223 static int isl29028_als_get(struct isl29028_chip *chip, int *als_data) ··· 261 231 262 232 ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS); 263 233 if (ret < 0) { 264 - dev_err(dev, "Error in enabling ALS mode err %d\n", ret); 234 + dev_err(dev, "%s(): Error %d enabling ALS mode\n", __func__, 235 + ret); 265 236 return ret; 266 237 } 267 238 ··· 281 250 als_ir_data = (als_ir_data * 49) / 100; 282 251 283 252 *als_data = als_ir_data; 253 + 284 254 return 0; 285 255 } 286 256 ··· 292 260 293 261 ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR); 294 262 if (ret < 0) { 295 - dev_err(dev, "Error in enabling IR mode err %d\n", ret); 263 + dev_err(dev, "%s(): Error %d enabling IR mode\n", __func__, 264 + ret); 296 265 return ret; 297 266 } 267 + 298 268 return isl29028_read_als_ir(chip, ir_data); 269 + } 270 + 271 + static int isl29028_set_pm_runtime_busy(struct isl29028_chip *chip, bool on) 272 + { 273 + struct device *dev = regmap_get_device(chip->regmap); 274 + int ret; 275 + 276 + if (on) { 277 + ret = pm_runtime_get_sync(dev); 278 + if (ret < 0) 279 + pm_runtime_put_noidle(dev); 280 + } else { 281 + pm_runtime_mark_last_busy(dev); 282 + ret = pm_runtime_put_autosuspend(dev); 283 + } 284 + 285 + return ret; 299 286 } 300 287 301 288 /* Channel IO */ ··· 324 273 { 325 274 struct isl29028_chip *chip = iio_priv(indio_dev); 326 275 struct device *dev = regmap_get_device(chip->regmap); 327 - int ret = -EINVAL; 276 + int ret; 277 + 278 + ret = isl29028_set_pm_runtime_busy(chip, true); 279 + if (ret < 0) 280 + return ret; 328 281 329 282 mutex_lock(&chip->lock); 283 + 284 + ret = -EINVAL; 330 285 switch (chan->type) { 331 286 case IIO_PROXIMITY: 332 287 if (mask != IIO_CHAN_INFO_SAMP_FREQ) { 333 288 dev_err(dev, 334 - "proximity: mask value 0x%08lx not supported\n", 335 - mask); 289 + "%s(): proximity: Mask value 0x%08lx is not supported\n", 290 + __func__, mask); 336 291 break; 337 292 } 293 + 338 294 if (val < 1 || val > 100) { 339 295 dev_err(dev, 340 - "Samp_freq %d is not in range[1:100]\n", val); 296 + "%s(): proximity: Sampling frequency %d is not in the range [1:100]\n", 297 + __func__, val); 341 298 break; 342 299 } 343 - ret = isl29028_set_proxim_sampling(chip, val); 344 - if (ret < 0) { 345 - dev_err(dev, 346 - "Setting proximity samp_freq fail, err %d\n", 347 - ret); 348 - break; 349 - } 350 - chip->prox_sampling = val; 351 - break; 352 300 301 + ret = isl29028_set_proxim_sampling(chip, val); 302 + break; 353 303 case IIO_LIGHT: 354 304 if (mask != IIO_CHAN_INFO_SCALE) { 355 305 dev_err(dev, 356 - "light: mask value 0x%08lx not supported\n", 357 - mask); 306 + "%s(): light: Mask value 0x%08lx is not supported\n", 307 + __func__, mask); 358 308 break; 359 309 } 360 - if ((val != 125) && (val != 2000)) { 361 - dev_err(dev, 362 - "lux scale %d is invalid [125, 2000]\n", val); 363 - break; 364 - } 365 - ret = isl29028_set_als_scale(chip, val); 366 - if (ret < 0) { 367 - dev_err(dev, 368 - "Setting lux scale fail with error %d\n", ret); 369 - break; 370 - } 371 - chip->lux_scale = val; 372 - break; 373 310 311 + if (val != 125 && val != 2000) { 312 + dev_err(dev, 313 + "%s(): light: Lux scale %d is not in the set {125, 2000}\n", 314 + __func__, val); 315 + break; 316 + } 317 + 318 + ret = isl29028_set_als_scale(chip, val); 319 + break; 374 320 default: 375 - dev_err(dev, "Unsupported channel type\n"); 321 + dev_err(dev, "%s(): Unsupported channel type %x\n", 322 + __func__, chan->type); 376 323 break; 377 324 } 325 + 378 326 mutex_unlock(&chip->lock); 327 + 328 + if (ret < 0) 329 + return ret; 330 + 331 + ret = isl29028_set_pm_runtime_busy(chip, false); 332 + if (ret < 0) 333 + return ret; 334 + 379 335 return ret; 380 336 } 381 337 ··· 392 334 { 393 335 struct isl29028_chip *chip = iio_priv(indio_dev); 394 336 struct device *dev = regmap_get_device(chip->regmap); 395 - int ret = -EINVAL; 337 + int ret, pm_ret; 338 + 339 + ret = isl29028_set_pm_runtime_busy(chip, true); 340 + if (ret < 0) 341 + return ret; 396 342 397 343 mutex_lock(&chip->lock); 344 + 345 + ret = -EINVAL; 398 346 switch (mask) { 399 347 case IIO_CHAN_INFO_RAW: 400 348 case IIO_CHAN_INFO_PROCESSED: ··· 412 348 ret = isl29028_ir_get(chip, val); 413 349 break; 414 350 case IIO_PROXIMITY: 415 - ret = isl29028_proxim_get(chip, val); 351 + ret = isl29028_read_proxim(chip, val); 416 352 break; 417 353 default: 418 354 break; 419 355 } 356 + 420 357 if (ret < 0) 421 358 break; 359 + 422 360 ret = IIO_VAL_INT; 423 361 break; 424 - 425 362 case IIO_CHAN_INFO_SAMP_FREQ: 426 363 if (chan->type != IIO_PROXIMITY) 427 364 break; 365 + 428 366 *val = chip->prox_sampling; 429 367 ret = IIO_VAL_INT; 430 368 break; 431 - 432 369 case IIO_CHAN_INFO_SCALE: 433 370 if (chan->type != IIO_LIGHT) 434 371 break; 435 372 *val = chip->lux_scale; 436 373 ret = IIO_VAL_INT; 437 374 break; 438 - 439 375 default: 440 - dev_err(dev, "mask value 0x%08lx not supported\n", mask); 376 + dev_err(dev, "%s(): mask value 0x%08lx is not supported\n", 377 + __func__, mask); 441 378 break; 442 379 } 380 + 443 381 mutex_unlock(&chip->lock); 382 + 383 + if (ret < 0) 384 + return ret; 385 + 386 + /** 387 + * Preserve the ret variable if the call to 388 + * isl29028_set_pm_runtime_busy() is successful so the reading 389 + * (if applicable) is returned to user space. 390 + */ 391 + pm_ret = isl29028_set_pm_runtime_busy(chip, false); 392 + if (pm_ret < 0) 393 + return pm_ret; 394 + 444 395 return ret; 445 396 } 446 397 ··· 463 384 "1 3 5 10 13 20 83 100"); 464 385 static IIO_CONST_ATTR(in_illuminance_scale_available, "125 2000"); 465 386 466 - #define ISL29028_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr) 467 387 #define ISL29028_CONST_ATTR(name) (&iio_const_attr_##name.dev_attr.attr) 468 388 static struct attribute *isl29028_attributes[] = { 469 389 ISL29028_CONST_ATTR(in_proximity_sampling_frequency_available), ··· 496 418 .write_raw = isl29028_write_raw, 497 419 }; 498 420 499 - static int isl29028_chip_init_and_power_on(struct isl29028_chip *chip) 421 + static int isl29028_clear_configure_reg(struct isl29028_chip *chip) 500 422 { 501 423 struct device *dev = regmap_get_device(chip->regmap); 502 424 int ret; 503 425 504 426 ret = regmap_write(chip->regmap, ISL29028_REG_CONFIGURE, 0x0); 505 - if (ret < 0) { 506 - dev_err(dev, "%s(): write to reg %d failed, err = %d\n", 507 - __func__, ISL29028_REG_CONFIGURE, ret); 508 - return ret; 509 - } 510 - 511 - ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling); 512 - if (ret < 0) { 513 - dev_err(dev, "setting the proximity, err = %d\n", ret); 514 - return ret; 515 - } 516 - 517 - ret = isl29028_set_als_scale(chip, chip->lux_scale); 518 427 if (ret < 0) 519 - dev_err(dev, "setting als scale failed, err = %d\n", ret); 428 + dev_err(dev, "%s(): Error %d clearing the CONFIGURE register\n", 429 + __func__, ret); 430 + 431 + chip->als_ir_mode = ISL29028_MODE_NONE; 432 + chip->enable_prox = false; 433 + 520 434 return ret; 521 435 } 522 436 ··· 542 472 int ret; 543 473 544 474 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); 545 - if (!indio_dev) { 546 - dev_err(&client->dev, "iio allocation fails\n"); 475 + if (!indio_dev) 547 476 return -ENOMEM; 548 - } 549 477 550 478 chip = iio_priv(indio_dev); 551 479 ··· 553 485 chip->regmap = devm_regmap_init_i2c(client, &isl29028_regmap_config); 554 486 if (IS_ERR(chip->regmap)) { 555 487 ret = PTR_ERR(chip->regmap); 556 - dev_err(&client->dev, "regmap initialization failed: %d\n", 557 - ret); 488 + dev_err(&client->dev, "%s: Error %d initializing regmap\n", 489 + __func__, ret); 558 490 return ret; 559 491 } 560 492 561 493 chip->enable_prox = false; 562 494 chip->prox_sampling = 20; 563 495 chip->lux_scale = 2000; 564 - chip->als_ir_mode = ISL29028_MODE_NONE; 565 496 566 497 ret = regmap_write(chip->regmap, ISL29028_REG_TEST1_MODE, 0x0); 567 498 if (ret < 0) { 568 499 dev_err(&client->dev, 569 - "%s(): write to reg %d failed, err = %d\n", __func__, 570 - ISL29028_REG_TEST1_MODE, ret); 571 - return ret; 572 - } 573 - ret = regmap_write(chip->regmap, ISL29028_REG_TEST2_MODE, 0x0); 574 - if (ret < 0) { 575 - dev_err(&client->dev, 576 - "%s(): write to reg %d failed, err = %d\n", __func__, 577 - ISL29028_REG_TEST2_MODE, ret); 500 + "%s(): Error %d writing to TEST1_MODE register\n", 501 + __func__, ret); 578 502 return ret; 579 503 } 580 504 581 - ret = isl29028_chip_init_and_power_on(chip); 505 + ret = regmap_write(chip->regmap, ISL29028_REG_TEST2_MODE, 0x0); 582 506 if (ret < 0) { 583 - dev_err(&client->dev, "chip initialization failed: %d\n", ret); 507 + dev_err(&client->dev, 508 + "%s(): Error %d writing to TEST2_MODE register\n", 509 + __func__, ret); 584 510 return ret; 585 511 } 512 + 513 + ret = isl29028_clear_configure_reg(chip); 514 + if (ret < 0) 515 + return ret; 586 516 587 517 indio_dev->info = &isl29028_info; 588 518 indio_dev->channels = isl29028_channels; ··· 588 522 indio_dev->name = id->name; 589 523 indio_dev->dev.parent = &client->dev; 590 524 indio_dev->modes = INDIO_DIRECT_MODE; 525 + 526 + pm_runtime_enable(&client->dev); 527 + pm_runtime_set_autosuspend_delay(&client->dev, 528 + ISL29028_POWER_OFF_DELAY_MS); 529 + pm_runtime_use_autosuspend(&client->dev); 530 + 591 531 ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev); 592 532 if (ret < 0) { 593 533 dev_err(&client->dev, 594 - "iio registration fails with error %d\n", 595 - ret); 534 + "%s(): iio registration failed with error %d\n", 535 + __func__, ret); 596 536 return ret; 597 537 } 538 + 598 539 return 0; 599 540 } 541 + 542 + static int isl29028_remove(struct i2c_client *client) 543 + { 544 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 545 + struct isl29028_chip *chip = iio_priv(indio_dev); 546 + 547 + iio_device_unregister(indio_dev); 548 + 549 + pm_runtime_disable(&client->dev); 550 + pm_runtime_set_suspended(&client->dev); 551 + pm_runtime_put_noidle(&client->dev); 552 + 553 + return isl29028_clear_configure_reg(chip); 554 + } 555 + 556 + static int __maybe_unused isl29028_suspend(struct device *dev) 557 + { 558 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 559 + struct isl29028_chip *chip = iio_priv(indio_dev); 560 + int ret; 561 + 562 + mutex_lock(&chip->lock); 563 + 564 + ret = isl29028_clear_configure_reg(chip); 565 + 566 + mutex_unlock(&chip->lock); 567 + 568 + return ret; 569 + } 570 + 571 + static int __maybe_unused isl29028_resume(struct device *dev) 572 + { 573 + /** 574 + * The specific component (ALS/IR or proximity) will enable itself as 575 + * needed the next time that the user requests a reading. This is done 576 + * above in isl29028_set_als_ir_mode() and isl29028_enable_proximity(). 577 + */ 578 + return 0; 579 + } 580 + 581 + static const struct dev_pm_ops isl29028_pm_ops = { 582 + SET_SYSTEM_SLEEP_PM_OPS(isl29028_suspend, isl29028_resume) 583 + SET_RUNTIME_PM_OPS(isl29028_suspend, isl29028_resume, NULL) 584 + }; 600 585 601 586 static const struct i2c_device_id isl29028_id[] = { 602 587 {"isl29028", 0}, ··· 665 548 static struct i2c_driver isl29028_driver = { 666 549 .driver = { 667 550 .name = "isl29028", 551 + .pm = &isl29028_pm_ops, 668 552 .of_match_table = isl29028_of_match, 669 553 }, 670 554 .probe = isl29028_probe, 555 + .remove = isl29028_remove, 671 556 .id_table = isl29028_id, 672 557 }; 673 558
+2 -2
drivers/staging/iio/trigger/iio-trig-bfin-timer.c
··· 260 260 out1: 261 261 iio_trigger_unregister(st->trig); 262 262 out: 263 - iio_trigger_put(st->trig); 263 + iio_trigger_free(st->trig); 264 264 return ret; 265 265 } 266 266 ··· 273 273 peripheral_free(st->t->pin); 274 274 free_irq(st->irq, st); 275 275 iio_trigger_unregister(st->trig); 276 - iio_trigger_put(st->trig); 276 + iio_trigger_free(st->trig); 277 277 278 278 return 0; 279 279 }