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

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

Jonathan writes:

Third set of IIO new device support, features and cleanups for the 4.8 cycle.

New core features
- Selection of the clock source for IIO timestamps. This is done per device
as it makes little sense to have events in one timebase and data timestamped
on another. Biggest reason for this is that we currently use a clock
source which is non monotonic which can result in 'interesting' data sets.
(Includes export for get_monotonic_corse64 which Thomas Gleixner didn't mind
in an earlier version.)
- MAINTAINERS add the git tree to the list for IIO.

New device support + a kind of indirect staging graduation.
* Broadcom iproc-static-adc
- new driver
* mcp4531
- support for MCP454x, MCP456x, MCP464x and MCP466x potentiometers
* mpu6050
- support the IC20608 6 axis motion tracking device
* st-sensors
- support the lis3l02dq + drop the lis3l02dq driver from staging.
The general purpose driver is missing event support, but good to get
rid of this driver which was rather long in the tooth.

New driver features
* ak8975
- Add vid regulator support and refactor handling in general.
- Allow a delay after enabling regulators.
- Runtime and system PM.
* bmg160
- filter frequency control support.
* bmp280
- SPI device support.
- EOC interrupt support for the BMP085
- power management support.
- supply regulator support.
- reset gpio support
- dt bindings for reset gpio and regulators.
- of table to support device tree registration
* max1363
- Device tree bindings.
* mcp4531
- Device tree bindings.
* st-pressure
- temperature channels as part of triggered buffer (previously not due
probably to alignment issues - see below).
- lps22hb open drain interrupt support.
- lps22hb temperature channel support

Cleanups and reworkings.
* numerous ADC drivers
- ensure the iio_dev->dev.of_node is set to the parent dev.of_node so
as to allow client bindings to find the device.
* ak8975
- Fix incorrect handling of missing regulator
- make sure power is down and remove.
* bmp280
- read the calibration data only once as it doesn't change.
* isl29125
- Use a few macros to make code a touch more readable.
* mma8452
- fix a memory leak on error.
- drop an unecessary bit of return value handling.
* potentiometer kconfig
- typo fix.
* st-pressure
- drop some uninformative default assignments of elements of the channel
array structure (aids readability).
* st-sensors
- Harden interrupt handling considerably. These are actually all using
level interrupts, but at least two known boards have them wired to
edge only interrupt chips. Hence a slightly interesting bit of handling
is needed in which we first allow for the easy option (level triggered) and
secondly check the status registers before reenabling edge interrupts and
fall back to a tight loop in the thread until we successfully clear the
interrupt. No harm is done if we never succeed in doing so. It's an odd
patch that has been through a lot of revisions to reach a consensus on how
to handle what is basically broken hardware (which the previous defaults
allowed to kind of work).
- Fix alignment to defined storagebytes boundaries.
- Ensure alignment of power of 2 byte boundaries. This has always in theory
been part of the ABI of IIO, but we missed a few that snuck in that need
fixing. The effect was minor as they were only followed by timestamp
channels which were correctly aligned,
- Add some docs to explain the gain calculations.

+2709 -2040
+7
Documentation/ABI/testing/sysfs-bus-iio
··· 32 32 Description of the physical chip / device for device X. 33 33 Typically a part number. 34 34 35 + What: /sys/bus/iio/devices/iio:deviceX/timestamp_clock 36 + KernelVersion: 4.5 37 + Contact: linux-iio@vger.kernel.org 38 + Description: 39 + String identifying current posix clock used to timestamp 40 + buffered samples and events for device X. 41 + 35 42 What: /sys/bus/iio/devices/iio:deviceX/sampling_frequency 36 43 What: /sys/bus/iio/devices/iio:deviceX/buffer/sampling_frequency 37 44 What: /sys/bus/iio/devices/triggerX/sampling_frequency
+1 -1
Documentation/DocBook/iio.tmpl
··· 594 594 595 595 irqreturn_t sensor_iio_pollfunc(int irq, void *p) 596 596 { 597 - pf->timestamp = iio_get_time_ns(); 597 + pf->timestamp = iio_get_time_ns((struct indio_dev *)p); 598 598 return IRQ_WAKE_THREAD; 599 599 } 600 600
+64
Documentation/devicetree/bindings/i2c/trivial-devices.txt
··· 56 56 maxim,max1237 Low-Power, 4-/12-Channel, 2-Wire Serial, 12-Bit ADCs 57 57 maxim,max6625 9-Bit/12-Bit Temperature Sensors with I²C-Compatible Serial Interface 58 58 mc,rv3029c2 Real Time Clock Module with I2C-Bus 59 + microchip,mcp4531-502 Microchip 7-bit Single I2C Digital Potentiometer (5k) 60 + microchip,mcp4531-103 Microchip 7-bit Single I2C Digital Potentiometer (10k) 61 + microchip,mcp4531-503 Microchip 7-bit Single I2C Digital Potentiometer (50k) 62 + microchip,mcp4531-104 Microchip 7-bit Single I2C Digital Potentiometer (100k) 63 + microchip,mcp4532-502 Microchip 7-bit Single I2C Digital Potentiometer (5k) 64 + microchip,mcp4532-103 Microchip 7-bit Single I2C Digital Potentiometer (10k) 65 + microchip,mcp4532-503 Microchip 7-bit Single I2C Digital Potentiometer (50k) 66 + microchip,mcp4532-104 Microchip 7-bit Single I2C Digital Potentiometer (100k) 67 + microchip,mcp4541-502 Microchip 7-bit Single I2C Digital Potentiometer with NV Memory (5k) 68 + microchip,mcp4541-103 Microchip 7-bit Single I2C Digital Potentiometer with NV Memory (10k) 69 + microchip,mcp4541-503 Microchip 7-bit Single I2C Digital Potentiometer with NV Memory (50k) 70 + microchip,mcp4541-104 Microchip 7-bit Single I2C Digital Potentiometer with NV Memory (100k) 71 + microchip,mcp4542-502 Microchip 7-bit Single I2C Digital Potentiometer with NV Memory (5k) 72 + microchip,mcp4542-103 Microchip 7-bit Single I2C Digital Potentiometer with NV Memory (10k) 73 + microchip,mcp4542-503 Microchip 7-bit Single I2C Digital Potentiometer with NV Memory (50k) 74 + microchip,mcp4542-104 Microchip 7-bit Single I2C Digital Potentiometer with NV Memory (100k) 75 + microchip,mcp4551-502 Microchip 8-bit Single I2C Digital Potentiometer (5k) 76 + microchip,mcp4551-103 Microchip 8-bit Single I2C Digital Potentiometer (10k) 77 + microchip,mcp4551-503 Microchip 8-bit Single I2C Digital Potentiometer (50k) 78 + microchip,mcp4551-104 Microchip 8-bit Single I2C Digital Potentiometer (100k) 79 + microchip,mcp4552-502 Microchip 8-bit Single I2C Digital Potentiometer (5k) 80 + microchip,mcp4552-103 Microchip 8-bit Single I2C Digital Potentiometer (10k) 81 + microchip,mcp4552-503 Microchip 8-bit Single I2C Digital Potentiometer (50k) 82 + microchip,mcp4552-104 Microchip 8-bit Single I2C Digital Potentiometer (100k) 83 + microchip,mcp4561-502 Microchip 8-bit Single I2C Digital Potentiometer with NV Memory (5k) 84 + microchip,mcp4561-103 Microchip 8-bit Single I2C Digital Potentiometer with NV Memory (10k) 85 + microchip,mcp4561-503 Microchip 8-bit Single I2C Digital Potentiometer with NV Memory (50k) 86 + microchip,mcp4561-104 Microchip 8-bit Single I2C Digital Potentiometer with NV Memory (100k) 87 + microchip,mcp4562-502 Microchip 8-bit Single I2C Digital Potentiometer with NV Memory (5k) 88 + microchip,mcp4562-103 Microchip 8-bit Single I2C Digital Potentiometer with NV Memory (10k) 89 + microchip,mcp4562-503 Microchip 8-bit Single I2C Digital Potentiometer with NV Memory (50k) 90 + microchip,mcp4562-104 Microchip 8-bit Single I2C Digital Potentiometer with NV Memory (100k) 91 + microchip,mcp4631-502 Microchip 7-bit Dual I2C Digital Potentiometer (5k) 92 + microchip,mcp4631-103 Microchip 7-bit Dual I2C Digital Potentiometer (10k) 93 + microchip,mcp4631-503 Microchip 7-bit Dual I2C Digital Potentiometer (50k) 94 + microchip,mcp4631-104 Microchip 7-bit Dual I2C Digital Potentiometer (100k) 95 + microchip,mcp4632-502 Microchip 7-bit Dual I2C Digital Potentiometer (5k) 96 + microchip,mcp4632-103 Microchip 7-bit Dual I2C Digital Potentiometer (10k) 97 + microchip,mcp4632-503 Microchip 7-bit Dual I2C Digital Potentiometer (50k) 98 + microchip,mcp4632-104 Microchip 7-bit Dual I2C Digital Potentiometer (100k) 99 + microchip,mcp4641-502 Microchip 7-bit Dual I2C Digital Potentiometer with NV Memory (5k) 100 + microchip,mcp4641-103 Microchip 7-bit Dual I2C Digital Potentiometer with NV Memory (10k) 101 + microchip,mcp4641-503 Microchip 7-bit Dual I2C Digital Potentiometer with NV Memory (50k) 102 + microchip,mcp4641-104 Microchip 7-bit Dual I2C Digital Potentiometer with NV Memory (100k) 103 + microchip,mcp4642-502 Microchip 7-bit Dual I2C Digital Potentiometer with NV Memory (5k) 104 + microchip,mcp4642-103 Microchip 7-bit Dual I2C Digital Potentiometer with NV Memory (10k) 105 + microchip,mcp4642-503 Microchip 7-bit Dual I2C Digital Potentiometer with NV Memory (50k) 106 + microchip,mcp4642-104 Microchip 7-bit Dual I2C Digital Potentiometer with NV Memory (100k) 107 + microchip,mcp4651-502 Microchip 8-bit Dual I2C Digital Potentiometer (5k) 108 + microchip,mcp4651-103 Microchip 8-bit Dual I2C Digital Potentiometer (10k) 109 + microchip,mcp4651-503 Microchip 8-bit Dual I2C Digital Potentiometer (50k) 110 + microchip,mcp4651-104 Microchip 8-bit Dual I2C Digital Potentiometer (100k) 111 + microchip,mcp4652-502 Microchip 8-bit Dual I2C Digital Potentiometer (5k) 112 + microchip,mcp4652-103 Microchip 8-bit Dual I2C Digital Potentiometer (10k) 113 + microchip,mcp4652-503 Microchip 8-bit Dual I2C Digital Potentiometer (50k) 114 + microchip,mcp4652-104 Microchip 8-bit Dual I2C Digital Potentiometer (100k) 115 + microchip,mcp4661-502 Microchip 8-bit Dual I2C Digital Potentiometer with NV Memory (5k) 116 + microchip,mcp4661-103 Microchip 8-bit Dual I2C Digital Potentiometer with NV Memory (10k) 117 + microchip,mcp4661-503 Microchip 8-bit Dual I2C Digital Potentiometer with NV Memory (50k) 118 + microchip,mcp4661-104 Microchip 8-bit Dual I2C Digital Potentiometer with NV Memory (100k) 119 + microchip,mcp4662-502 Microchip 8-bit Dual I2C Digital Potentiometer with NV Memory (5k) 120 + microchip,mcp4662-103 Microchip 8-bit Dual I2C Digital Potentiometer with NV Memory (10k) 121 + microchip,mcp4662-503 Microchip 8-bit Dual I2C Digital Potentiometer with NV Memory (50k) 122 + microchip,mcp4662-104 Microchip 8-bit Dual I2C Digital Potentiometer with NV Memory (100k) 59 123 national,lm63 Temperature sensor with integrated fan control 60 124 national,lm75 I2C TEMP SENSOR 61 125 national,lm80 Serial Interface ACPI-Compatible Microprocessor System Hardware Monitor
+41
Documentation/devicetree/bindings/iio/adc/brcm,iproc-static-adc.txt
··· 1 + * Broadcom's IPROC Static ADC controller 2 + 3 + Broadcom iProc ADC controller has 8 channels 10bit ADC. 4 + Allows user to convert analog input voltage values to digital. 5 + 6 + Required properties: 7 + 8 + - compatible: Must be "brcm,iproc-static-adc" 9 + 10 + - adc-syscon: Handler of syscon node defining physical base address of the 11 + controller and length of memory mapped region. 12 + 13 + - #io-channel-cells = <1>; As ADC has multiple outputs 14 + refer to Documentation/devicetree/bindings/iio/iio-bindings.txt for details. 15 + 16 + - io-channel-ranges: 17 + refer to Documentation/devicetree/bindings/iio/iio-bindings.txt for details. 18 + 19 + - clocks: Clock used for this block. 20 + 21 + - clock-names: Clock name should be given as tsc_clk. 22 + 23 + - interrupts: interrupt line number. 24 + 25 + For example: 26 + 27 + ts_adc_syscon: ts_adc_syscon@180a6000 { 28 + compatible = "brcm,iproc-ts-adc-syscon","syscon"; 29 + reg = <0x180a6000 0xc30>; 30 + }; 31 + 32 + adc: adc@180a6000 { 33 + compatible = "brcm,iproc-static-adc"; 34 + adc-syscon = <&ts_adc_syscon>; 35 + #io-channel-cells = <1>; 36 + io-channel-ranges; 37 + clocks = <&asiu_clks BCM_CYGNUS_ASIU_ADC_CLK>; 38 + clock-names = "tsc_clk"; 39 + interrupts = <GIC_SPI 164 IRQ_TYPE_LEVEL_HIGH>; 40 + status = "disabled"; 41 + };
+63
Documentation/devicetree/bindings/iio/adc/max1363.txt
··· 1 + * Maxim 1x3x/136x/116xx Analog to Digital Converter (ADC) 2 + 3 + The node for this driver must be a child node of a I2C controller, hence 4 + all mandatory properties for your controller must be specified. See directory: 5 + 6 + Documentation/devicetree/bindings/i2c 7 + 8 + for more details. 9 + 10 + Required properties: 11 + - compatible: Should be one of 12 + "maxim,max1361" 13 + "maxim,max1362" 14 + "maxim,max1363" 15 + "maxim,max1364" 16 + "maxim,max1036" 17 + "maxim,max1037" 18 + "maxim,max1038" 19 + "maxim,max1039" 20 + "maxim,max1136" 21 + "maxim,max1137" 22 + "maxim,max1138" 23 + "maxim,max1139" 24 + "maxim,max1236" 25 + "maxim,max1237" 26 + "maxim,max1238" 27 + "maxim,max1239" 28 + "maxim,max11600" 29 + "maxim,max11601" 30 + "maxim,max11602" 31 + "maxim,max11603" 32 + "maxim,max11604" 33 + "maxim,max11605" 34 + "maxim,max11606" 35 + "maxim,max11607" 36 + "maxim,max11608" 37 + "maxim,max11609" 38 + "maxim,max11610" 39 + "maxim,max11611" 40 + "maxim,max11612" 41 + "maxim,max11613" 42 + "maxim,max11614" 43 + "maxim,max11615" 44 + "maxim,max11616" 45 + "maxim,max11617" 46 + "maxim,max11644" 47 + "maxim,max11645" 48 + "maxim,max11646" 49 + "maxim,max11647" 50 + - reg: Should contain the ADC I2C address 51 + 52 + Optional properties: 53 + - vcc-supply: phandle to the regulator that provides power to the ADC. 54 + - vref-supply: phandle to the regulator for ADC reference voltage. 55 + - interrupts: IRQ line for the ADC. If not used the driver will use 56 + polling. 57 + 58 + Example: 59 + adc: max11644@36 { 60 + compatible = "maxim,max11644"; 61 + reg = <0x36>; 62 + vref-supply = <&adc_vref>; 63 + };
+13 -2
Documentation/devicetree/bindings/iio/pressure/bmp085.txt
··· 1 - BMP085/BMP18x digital pressure sensors 1 + BMP085/BMP18x/BMP28x digital pressure sensors 2 2 3 3 Required properties: 4 - - compatible: bosch,bmp085 4 + - compatible: must be one of: 5 + "bosch,bmp085" 6 + "bosch,bmp180" 7 + "bosch,bmp280" 8 + "bosch,bme280" 5 9 6 10 Optional properties: 7 11 - chip-id: configurable chip id for non-default chip revisions ··· 14 10 value range is 0-3 with rising sensitivity. 15 11 - interrupt-parent: should be the phandle for the interrupt controller 16 12 - interrupts: interrupt mapping for IRQ 13 + - reset-gpios: a GPIO line handling reset of the sensor: as the line is 14 + active low, it should be marked GPIO_ACTIVE_LOW (see gpio/gpio.txt) 15 + - vddd-supply: digital voltage regulator (see regulator/regulator.txt) 16 + - vdda-supply: analog voltage regulator (see regulator/regulator.txt) 17 17 18 18 Example: 19 19 ··· 29 21 default-oversampling = <2>; 30 22 interrupt-parent = <&gpio0>; 31 23 interrupts = <25 IRQ_TYPE_EDGE_RISING>; 24 + reset-gpios = <&gpio0 26 GPIO_ACTIVE_LOW>; 25 + vddd-supply = <&foo>; 26 + vdda-supply = <&bar>; 32 27 };
+1
MAINTAINERS
··· 5789 5789 R: Lars-Peter Clausen <lars@metafoo.de> 5790 5790 R: Peter Meerwald-Stadler <pmeerw@pmeerw.net> 5791 5791 L: linux-iio@vger.kernel.org 5792 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git 5792 5793 S: Maintained 5793 5794 F: Documentation/devicetree/bindings/iio/ 5794 5795 F: drivers/iio/
+1 -1
drivers/iio/accel/bma180.c
··· 654 654 struct iio_poll_func *pf = p; 655 655 struct iio_dev *indio_dev = pf->indio_dev; 656 656 struct bma180_data *data = iio_priv(indio_dev); 657 - int64_t time_ns = iio_get_time_ns(); 657 + s64 time_ns = iio_get_time_ns(indio_dev); 658 658 int bit, ret, i = 0; 659 659 660 660 mutex_lock(&data->mutex);
+2 -2
drivers/iio/accel/bmc150-accel-core.c
··· 901 901 */ 902 902 if (!irq) { 903 903 data->old_timestamp = data->timestamp; 904 - data->timestamp = iio_get_time_ns(); 904 + data->timestamp = iio_get_time_ns(indio_dev); 905 905 } 906 906 907 907 /* ··· 1303 1303 int i; 1304 1304 1305 1305 data->old_timestamp = data->timestamp; 1306 - data->timestamp = iio_get_time_ns(); 1306 + data->timestamp = iio_get_time_ns(indio_dev); 1307 1307 1308 1308 for (i = 0; i < BMC150_ACCEL_TRIGGERS; i++) { 1309 1309 if (data->triggers[i].enabled) {
+1 -1
drivers/iio/accel/kxcjk-1013.c
··· 1129 1129 struct iio_dev *indio_dev = private; 1130 1130 struct kxcjk1013_data *data = iio_priv(indio_dev); 1131 1131 1132 - data->timestamp = iio_get_time_ns(); 1132 + data->timestamp = iio_get_time_ns(indio_dev); 1133 1133 1134 1134 if (data->dready_trigger_on) 1135 1135 iio_trigger_poll(data->dready_trig);
+2 -1
drivers/iio/accel/mma7455_core.c
··· 97 97 if (ret) 98 98 goto done; 99 99 100 - iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns()); 100 + iio_push_to_buffers_with_timestamp(indio_dev, buf, 101 + iio_get_time_ns(indio_dev)); 101 102 102 103 done: 103 104 iio_trigger_notify_done(indio_dev->trig);
+5 -9
drivers/iio/accel/mma8452.c
··· 634 634 val |= MMA8452_FF_MT_CFG_OAE; 635 635 } 636 636 637 - val = mma8452_change_config(data, chip->ev_cfg, val); 638 - if (val) 639 - return val; 640 - 641 - return 0; 637 + return mma8452_change_config(data, chip->ev_cfg, val); 642 638 } 643 639 644 640 static int mma8452_set_hp_filter_frequency(struct mma8452_data *data, ··· 913 917 static void mma8452_transient_interrupt(struct iio_dev *indio_dev) 914 918 { 915 919 struct mma8452_data *data = iio_priv(indio_dev); 916 - s64 ts = iio_get_time_ns(); 920 + s64 ts = iio_get_time_ns(indio_dev); 917 921 int src; 918 922 919 923 src = i2c_smbus_read_byte_data(data->client, data->chip_info->ev_src); ··· 993 997 goto done; 994 998 995 999 iio_push_to_buffers_with_timestamp(indio_dev, buffer, 996 - iio_get_time_ns()); 1000 + iio_get_time_ns(indio_dev)); 997 1001 998 1002 done: 999 1003 iio_trigger_notify_done(indio_dev->trig); ··· 1575 1579 goto buffer_cleanup; 1576 1580 1577 1581 ret = mma8452_set_freefall_mode(data, false); 1578 - if (ret) 1579 - return ret; 1582 + if (ret < 0) 1583 + goto buffer_cleanup; 1580 1584 1581 1585 return 0; 1582 1586
+1 -1
drivers/iio/accel/mma9551.c
··· 391 391 iio_push_event(indio_dev, 392 392 IIO_MOD_EVENT_CODE(IIO_INCLI, 0, (mma_axis + 1), 393 393 IIO_EV_TYPE_ROC, IIO_EV_DIR_RISING), 394 - iio_get_time_ns()); 394 + iio_get_time_ns(indio_dev)); 395 395 396 396 out: 397 397 mutex_unlock(&data->mutex);
+1 -1
drivers/iio/accel/mma9553.c
··· 1001 1001 struct iio_dev *indio_dev = private; 1002 1002 struct mma9553_data *data = iio_priv(indio_dev); 1003 1003 1004 - data->timestamp = iio_get_time_ns(); 1004 + data->timestamp = iio_get_time_ns(indio_dev); 1005 1005 /* 1006 1006 * Since we only configure the interrupt pin when an 1007 1007 * event is enabled, we are sure we have at least
+1
drivers/iio/accel/st_accel.h
··· 29 29 #define LSM330_ACCEL_DEV_NAME "lsm330_accel" 30 30 #define LSM303AGR_ACCEL_DEV_NAME "lsm303agr_accel" 31 31 #define LIS2DH12_ACCEL_DEV_NAME "lis2dh12_accel" 32 + #define LIS3L02DQ_ACCEL_DEV_NAME "lis3l02dq" 32 33 33 34 /** 34 35 * struct st_sensors_platform_data - default accel platform data
+64
drivers/iio/accel/st_accel_core.c
··· 215 215 #define ST_ACCEL_6_IHL_IRQ_MASK 0x80 216 216 #define ST_ACCEL_6_MULTIREAD_BIT true 217 217 218 + /* CUSTOM VALUES FOR SENSOR 7 */ 219 + #define ST_ACCEL_7_ODR_ADDR 0x20 220 + #define ST_ACCEL_7_ODR_MASK 0x30 221 + #define ST_ACCEL_7_ODR_AVL_280HZ_VAL 0x00 222 + #define ST_ACCEL_7_ODR_AVL_560HZ_VAL 0x01 223 + #define ST_ACCEL_7_ODR_AVL_1120HZ_VAL 0x02 224 + #define ST_ACCEL_7_ODR_AVL_4480HZ_VAL 0x03 225 + #define ST_ACCEL_7_PW_ADDR 0x20 226 + #define ST_ACCEL_7_PW_MASK 0xc0 227 + #define ST_ACCEL_7_FS_AVL_2_GAIN IIO_G_TO_M_S_2(488) 228 + #define ST_ACCEL_7_BDU_ADDR 0x21 229 + #define ST_ACCEL_7_BDU_MASK 0x40 230 + #define ST_ACCEL_7_DRDY_IRQ_ADDR 0x21 231 + #define ST_ACCEL_7_DRDY_IRQ_INT1_MASK 0x04 232 + #define ST_ACCEL_7_MULTIREAD_BIT false 233 + 218 234 static const struct iio_chan_spec st_accel_8bit_channels[] = { 219 235 ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, 220 236 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), ··· 676 660 .mask_ihl = ST_ACCEL_6_IHL_IRQ_MASK, 677 661 }, 678 662 .multi_read_bit = ST_ACCEL_6_MULTIREAD_BIT, 663 + .bootime = 2, 664 + }, 665 + { 666 + /* No WAI register present */ 667 + .sensors_supported = { 668 + [0] = LIS3L02DQ_ACCEL_DEV_NAME, 669 + }, 670 + .ch = (struct iio_chan_spec *)st_accel_12bit_channels, 671 + .odr = { 672 + .addr = ST_ACCEL_7_ODR_ADDR, 673 + .mask = ST_ACCEL_7_ODR_MASK, 674 + .odr_avl = { 675 + { 280, ST_ACCEL_7_ODR_AVL_280HZ_VAL, }, 676 + { 560, ST_ACCEL_7_ODR_AVL_560HZ_VAL, }, 677 + { 1120, ST_ACCEL_7_ODR_AVL_1120HZ_VAL, }, 678 + { 4480, ST_ACCEL_7_ODR_AVL_4480HZ_VAL, }, 679 + }, 680 + }, 681 + .pw = { 682 + .addr = ST_ACCEL_7_PW_ADDR, 683 + .mask = ST_ACCEL_7_PW_MASK, 684 + .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE, 685 + .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, 686 + }, 687 + .enable_axis = { 688 + .addr = ST_SENSORS_DEFAULT_AXIS_ADDR, 689 + .mask = ST_SENSORS_DEFAULT_AXIS_MASK, 690 + }, 691 + .fs = { 692 + .fs_avl = { 693 + [0] = { 694 + .num = ST_ACCEL_FS_AVL_2G, 695 + .gain = ST_ACCEL_7_FS_AVL_2_GAIN, 696 + }, 697 + }, 698 + }, 699 + /* 700 + * The part has a BDU bit but if set the data is never 701 + * updated so don't set it. 702 + */ 703 + .bdu = { 704 + }, 705 + .drdy_irq = { 706 + .addr = ST_ACCEL_7_DRDY_IRQ_ADDR, 707 + .mask_int1 = ST_ACCEL_7_DRDY_IRQ_INT1_MASK, 708 + .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, 709 + }, 710 + .multi_read_bit = ST_ACCEL_7_MULTIREAD_BIT, 679 711 .bootime = 2, 680 712 }, 681 713 };
+5
drivers/iio/accel/st_accel_i2c.c
··· 80 80 .compatible = "st,h3lis331dl-accel", 81 81 .data = H3LIS331DL_DRIVER_NAME, 82 82 }, 83 + { 84 + .compatible = "st,lis3l02dq", 85 + .data = LIS3L02DQ_ACCEL_DEV_NAME, 86 + }, 83 87 {}, 84 88 }; 85 89 MODULE_DEVICE_TABLE(of, st_accel_of_match); ··· 134 130 { LSM330_ACCEL_DEV_NAME }, 135 131 { LSM303AGR_ACCEL_DEV_NAME }, 136 132 { LIS2DH12_ACCEL_DEV_NAME }, 133 + { LIS3L02DQ_ACCEL_DEV_NAME }, 137 134 {}, 138 135 }; 139 136 MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
+1
drivers/iio/accel/st_accel_spi.c
··· 59 59 { LSM330_ACCEL_DEV_NAME }, 60 60 { LSM303AGR_ACCEL_DEV_NAME }, 61 61 { LIS2DH12_ACCEL_DEV_NAME }, 62 + { LIS3L02DQ_ACCEL_DEV_NAME }, 62 63 {}, 63 64 }; 64 65 MODULE_DEVICE_TABLE(spi, st_accel_id_table);
+12
drivers/iio/adc/Kconfig
··· 153 153 To compile this driver as a module, choose M here: the module will be 154 154 called axp288_adc. 155 155 156 + config BCM_IPROC_ADC 157 + tristate "Broadcom IPROC ADC driver" 158 + depends on ARCH_BCM_IPROC || COMPILE_TEST 159 + depends on MFD_SYSCON 160 + default ARCH_BCM_CYGNUS 161 + help 162 + Say Y here if you want to add support for the Broadcom static 163 + ADC driver. 164 + 165 + Broadcom iProc ADC driver. Broadcom iProc ADC controller has 8 166 + channels. The driver allows the user to read voltage values. 167 + 156 168 config BERLIN2_ADC 157 169 tristate "Marvell Berlin2 ADC driver" 158 170 depends on ARCH_BERLIN
+1
drivers/iio/adc/Makefile
··· 16 16 obj-$(CONFIG_AT91_ADC) += at91_adc.o 17 17 obj-$(CONFIG_AT91_SAMA5D2_ADC) += at91-sama5d2_adc.o 18 18 obj-$(CONFIG_AXP288_ADC) += axp288_adc.o 19 + obj-$(CONFIG_BCM_IPROC_ADC) += bcm_iproc_adc.o 19 20 obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o 20 21 obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o 21 22 obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
+1
drivers/iio/adc/ad7266.c
··· 440 440 st->spi = spi; 441 441 442 442 indio_dev->dev.parent = &spi->dev; 443 + indio_dev->dev.of_node = spi->dev.of_node; 443 444 indio_dev->name = spi_get_device_id(spi)->name; 444 445 indio_dev->modes = INDIO_DIRECT_MODE; 445 446 indio_dev->info = &ad7266_info;
+2 -1
drivers/iio/adc/ad7291.c
··· 115 115 u16 t_status, v_status; 116 116 u16 command; 117 117 int i; 118 - s64 timestamp = iio_get_time_ns(); 118 + s64 timestamp = iio_get_time_ns(indio_dev); 119 119 120 120 if (ad7291_i2c_read(chip, AD7291_T_ALERT_STATUS, &t_status)) 121 121 return IRQ_HANDLED; ··· 505 505 indio_dev->num_channels = ARRAY_SIZE(ad7291_channels); 506 506 507 507 indio_dev->dev.parent = &client->dev; 508 + indio_dev->dev.of_node = client->dev.of_node; 508 509 indio_dev->info = &ad7291_info; 509 510 indio_dev->modes = INDIO_DIRECT_MODE; 510 511
+2 -1
drivers/iio/adc/ad7298.c
··· 163 163 goto done; 164 164 165 165 iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, 166 - iio_get_time_ns()); 166 + iio_get_time_ns(indio_dev)); 167 167 168 168 done: 169 169 iio_trigger_notify_done(indio_dev->trig); ··· 315 315 316 316 indio_dev->name = spi_get_device_id(spi)->name; 317 317 indio_dev->dev.parent = &spi->dev; 318 + indio_dev->dev.of_node = spi->dev.of_node; 318 319 indio_dev->modes = INDIO_DIRECT_MODE; 319 320 indio_dev->channels = ad7298_channels; 320 321 indio_dev->num_channels = ARRAY_SIZE(ad7298_channels);
+2 -1
drivers/iio/adc/ad7476.c
··· 70 70 goto done; 71 71 72 72 iio_push_to_buffers_with_timestamp(indio_dev, st->data, 73 - iio_get_time_ns()); 73 + iio_get_time_ns(indio_dev)); 74 74 done: 75 75 iio_trigger_notify_done(indio_dev->trig); 76 76 ··· 227 227 228 228 /* Establish that the iio_dev is a child of the spi device */ 229 229 indio_dev->dev.parent = &spi->dev; 230 + indio_dev->dev.of_node = spi->dev.of_node; 230 231 indio_dev->name = spi_get_device_id(spi)->name; 231 232 indio_dev->modes = INDIO_DIRECT_MODE; 232 233 indio_dev->channels = st->chip_info->channel;
+1
drivers/iio/adc/ad7791.c
··· 375 375 spi_set_drvdata(spi, indio_dev); 376 376 377 377 indio_dev->dev.parent = &spi->dev; 378 + indio_dev->dev.of_node = spi->dev.of_node; 378 379 indio_dev->name = spi_get_device_id(spi)->name; 379 380 indio_dev->modes = INDIO_DIRECT_MODE; 380 381 indio_dev->channels = st->info->channels;
+1
drivers/iio/adc/ad7793.c
··· 784 784 spi_set_drvdata(spi, indio_dev); 785 785 786 786 indio_dev->dev.parent = &spi->dev; 787 + indio_dev->dev.of_node = spi->dev.of_node; 787 788 indio_dev->name = spi_get_device_id(spi)->name; 788 789 indio_dev->modes = INDIO_DIRECT_MODE; 789 790 indio_dev->channels = st->chip_info->channels;
+2 -1
drivers/iio/adc/ad7887.c
··· 122 122 goto done; 123 123 124 124 iio_push_to_buffers_with_timestamp(indio_dev, st->data, 125 - iio_get_time_ns()); 125 + iio_get_time_ns(indio_dev)); 126 126 done: 127 127 iio_trigger_notify_done(indio_dev->trig); 128 128 ··· 264 264 265 265 /* Estabilish that the iio_dev is a child of the spi device */ 266 266 indio_dev->dev.parent = &spi->dev; 267 + indio_dev->dev.of_node = spi->dev.of_node; 267 268 indio_dev->name = spi_get_device_id(spi)->name; 268 269 indio_dev->info = &ad7887_info; 269 270 indio_dev->modes = INDIO_DIRECT_MODE;
+2 -1
drivers/iio/adc/ad7923.c
··· 181 181 goto done; 182 182 183 183 iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, 184 - iio_get_time_ns()); 184 + iio_get_time_ns(indio_dev)); 185 185 186 186 done: 187 187 iio_trigger_notify_done(indio_dev->trig); ··· 288 288 289 289 indio_dev->name = spi_get_device_id(spi)->name; 290 290 indio_dev->dev.parent = &spi->dev; 291 + indio_dev->dev.of_node = spi->dev.of_node; 291 292 indio_dev->modes = INDIO_DIRECT_MODE; 292 293 indio_dev->channels = info->channels; 293 294 indio_dev->num_channels = info->num_channels;
+3 -2
drivers/iio/adc/ad799x.c
··· 212 212 goto out; 213 213 214 214 iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, 215 - iio_get_time_ns()); 215 + iio_get_time_ns(indio_dev)); 216 216 out: 217 217 iio_trigger_notify_done(indio_dev->trig); 218 218 ··· 502 502 (i >> 1), 503 503 IIO_EV_TYPE_THRESH, 504 504 IIO_EV_DIR_FALLING), 505 - iio_get_time_ns()); 505 + iio_get_time_ns(indio_dev)); 506 506 } 507 507 508 508 done: ··· 806 806 st->client = client; 807 807 808 808 indio_dev->dev.parent = &client->dev; 809 + indio_dev->dev.of_node = client->dev.of_node; 809 810 indio_dev->name = id->name; 810 811 indio_dev->info = st->chip_config->info; 811 812
+644
drivers/iio/adc/bcm_iproc_adc.c
··· 1 + /* 2 + * Copyright 2016 Broadcom 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License, version 2, as 6 + * published by the Free Software Foundation (the "GPL"). 7 + * 8 + * This program is distributed in the hope that it will be useful, but 9 + * WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 + * General Public License version 2 (GPLv2) for more details. 12 + * 13 + * You should have received a copy of the GNU General Public License 14 + * version 2 (GPLv2) along with this source code. 15 + */ 16 + 17 + #include <linux/module.h> 18 + #include <linux/of.h> 19 + #include <linux/io.h> 20 + #include <linux/clk.h> 21 + #include <linux/mfd/syscon.h> 22 + #include <linux/regmap.h> 23 + #include <linux/delay.h> 24 + #include <linux/interrupt.h> 25 + #include <linux/platform_device.h> 26 + 27 + #include <linux/iio/iio.h> 28 + 29 + /* Below Register's are common to IPROC ADC and Touchscreen IP */ 30 + #define IPROC_REGCTL1 0x00 31 + #define IPROC_REGCTL2 0x04 32 + #define IPROC_INTERRUPT_THRES 0x08 33 + #define IPROC_INTERRUPT_MASK 0x0c 34 + #define IPROC_INTERRUPT_STATUS 0x10 35 + #define IPROC_ANALOG_CONTROL 0x1c 36 + #define IPROC_CONTROLLER_STATUS 0x14 37 + #define IPROC_AUX_DATA 0x20 38 + #define IPROC_SOFT_BYPASS_CONTROL 0x38 39 + #define IPROC_SOFT_BYPASS_DATA 0x3C 40 + 41 + /* IPROC ADC Channel register offsets */ 42 + #define IPROC_ADC_CHANNEL_REGCTL1 0x800 43 + #define IPROC_ADC_CHANNEL_REGCTL2 0x804 44 + #define IPROC_ADC_CHANNEL_STATUS 0x808 45 + #define IPROC_ADC_CHANNEL_INTERRUPT_STATUS 0x80c 46 + #define IPROC_ADC_CHANNEL_INTERRUPT_MASK 0x810 47 + #define IPROC_ADC_CHANNEL_DATA 0x814 48 + #define IPROC_ADC_CHANNEL_OFFSET 0x20 49 + 50 + /* Bit definitions for IPROC_REGCTL2 */ 51 + #define IPROC_ADC_AUXIN_SCAN_ENA BIT(0) 52 + #define IPROC_ADC_PWR_LDO BIT(5) 53 + #define IPROC_ADC_PWR_ADC BIT(4) 54 + #define IPROC_ADC_PWR_BG BIT(3) 55 + #define IPROC_ADC_CONTROLLER_EN BIT(17) 56 + 57 + /* Bit definitions for IPROC_INTERRUPT_MASK and IPROC_INTERRUPT_STATUS */ 58 + #define IPROC_ADC_AUXDATA_RDY_INTR BIT(3) 59 + #define IPROC_ADC_INTR 9 60 + #define IPROC_ADC_INTR_MASK (0xFF << IPROC_ADC_INTR) 61 + 62 + /* Bit definitions for IPROC_ANALOG_CONTROL */ 63 + #define IPROC_ADC_CHANNEL_SEL 11 64 + #define IPROC_ADC_CHANNEL_SEL_MASK (0x7 << IPROC_ADC_CHANNEL_SEL) 65 + 66 + /* Bit definitions for IPROC_ADC_CHANNEL_REGCTL1 */ 67 + #define IPROC_ADC_CHANNEL_ROUNDS 0x2 68 + #define IPROC_ADC_CHANNEL_ROUNDS_MASK (0x3F << IPROC_ADC_CHANNEL_ROUNDS) 69 + #define IPROC_ADC_CHANNEL_MODE 0x1 70 + #define IPROC_ADC_CHANNEL_MODE_MASK (0x1 << IPROC_ADC_CHANNEL_MODE) 71 + #define IPROC_ADC_CHANNEL_MODE_TDM 0x1 72 + #define IPROC_ADC_CHANNEL_MODE_SNAPSHOT 0x0 73 + #define IPROC_ADC_CHANNEL_ENABLE 0x0 74 + #define IPROC_ADC_CHANNEL_ENABLE_MASK 0x1 75 + 76 + /* Bit definitions for IPROC_ADC_CHANNEL_REGCTL2 */ 77 + #define IPROC_ADC_CHANNEL_WATERMARK 0x0 78 + #define IPROC_ADC_CHANNEL_WATERMARK_MASK \ 79 + (0x3F << IPROC_ADC_CHANNEL_WATERMARK) 80 + 81 + #define IPROC_ADC_WATER_MARK_LEVEL 0x1 82 + 83 + /* Bit definitions for IPROC_ADC_CHANNEL_STATUS */ 84 + #define IPROC_ADC_CHANNEL_DATA_LOST 0x0 85 + #define IPROC_ADC_CHANNEL_DATA_LOST_MASK \ 86 + (0x0 << IPROC_ADC_CHANNEL_DATA_LOST) 87 + #define IPROC_ADC_CHANNEL_VALID_ENTERIES 0x1 88 + #define IPROC_ADC_CHANNEL_VALID_ENTERIES_MASK \ 89 + (0xFF << IPROC_ADC_CHANNEL_VALID_ENTERIES) 90 + #define IPROC_ADC_CHANNEL_TOTAL_ENTERIES 0x9 91 + #define IPROC_ADC_CHANNEL_TOTAL_ENTERIES_MASK \ 92 + (0xFF << IPROC_ADC_CHANNEL_TOTAL_ENTERIES) 93 + 94 + /* Bit definitions for IPROC_ADC_CHANNEL_INTERRUPT_MASK */ 95 + #define IPROC_ADC_CHANNEL_WTRMRK_INTR 0x0 96 + #define IPROC_ADC_CHANNEL_WTRMRK_INTR_MASK \ 97 + (0x1 << IPROC_ADC_CHANNEL_WTRMRK_INTR) 98 + #define IPROC_ADC_CHANNEL_FULL_INTR 0x1 99 + #define IPROC_ADC_CHANNEL_FULL_INTR_MASK \ 100 + (0x1 << IPROC_ADC_IPROC_ADC_CHANNEL_FULL_INTR) 101 + #define IPROC_ADC_CHANNEL_EMPTY_INTR 0x2 102 + #define IPROC_ADC_CHANNEL_EMPTY_INTR_MASK \ 103 + (0x1 << IPROC_ADC_CHANNEL_EMPTY_INTR) 104 + 105 + #define IPROC_ADC_WATER_MARK_INTR_ENABLE 0x1 106 + 107 + /* Number of time to retry a set of the interrupt mask reg */ 108 + #define IPROC_ADC_INTMASK_RETRY_ATTEMPTS 10 109 + 110 + #define IPROC_ADC_READ_TIMEOUT (HZ*2) 111 + 112 + #define iproc_adc_dbg_reg(dev, priv, reg) \ 113 + do { \ 114 + u32 val; \ 115 + regmap_read(priv->regmap, reg, &val); \ 116 + dev_dbg(dev, "%20s= 0x%08x\n", #reg, val); \ 117 + } while (0) 118 + 119 + struct iproc_adc_priv { 120 + struct regmap *regmap; 121 + struct clk *adc_clk; 122 + struct mutex mutex; 123 + int irqno; 124 + int chan_val; 125 + int chan_id; 126 + struct completion completion; 127 + }; 128 + 129 + static void iproc_adc_reg_dump(struct iio_dev *indio_dev) 130 + { 131 + struct device *dev = &indio_dev->dev; 132 + struct iproc_adc_priv *adc_priv = iio_priv(indio_dev); 133 + 134 + iproc_adc_dbg_reg(dev, adc_priv, IPROC_REGCTL1); 135 + iproc_adc_dbg_reg(dev, adc_priv, IPROC_REGCTL2); 136 + iproc_adc_dbg_reg(dev, adc_priv, IPROC_INTERRUPT_THRES); 137 + iproc_adc_dbg_reg(dev, adc_priv, IPROC_INTERRUPT_MASK); 138 + iproc_adc_dbg_reg(dev, adc_priv, IPROC_INTERRUPT_STATUS); 139 + iproc_adc_dbg_reg(dev, adc_priv, IPROC_CONTROLLER_STATUS); 140 + iproc_adc_dbg_reg(dev, adc_priv, IPROC_ANALOG_CONTROL); 141 + iproc_adc_dbg_reg(dev, adc_priv, IPROC_AUX_DATA); 142 + iproc_adc_dbg_reg(dev, adc_priv, IPROC_SOFT_BYPASS_CONTROL); 143 + iproc_adc_dbg_reg(dev, adc_priv, IPROC_SOFT_BYPASS_DATA); 144 + } 145 + 146 + static irqreturn_t iproc_adc_interrupt_handler(int irq, void *data) 147 + { 148 + u32 channel_intr_status; 149 + u32 intr_status; 150 + u32 intr_mask; 151 + struct iio_dev *indio_dev = data; 152 + struct iproc_adc_priv *adc_priv = iio_priv(indio_dev); 153 + 154 + /* 155 + * This interrupt is shared with the touchscreen driver. 156 + * Make sure this interrupt is intended for us. 157 + * Handle only ADC channel specific interrupts. 158 + */ 159 + regmap_read(adc_priv->regmap, IPROC_INTERRUPT_STATUS, &intr_status); 160 + regmap_read(adc_priv->regmap, IPROC_INTERRUPT_MASK, &intr_mask); 161 + intr_status = intr_status & intr_mask; 162 + channel_intr_status = (intr_status & IPROC_ADC_INTR_MASK) >> 163 + IPROC_ADC_INTR; 164 + if (channel_intr_status) 165 + return IRQ_WAKE_THREAD; 166 + 167 + return IRQ_NONE; 168 + } 169 + 170 + static irqreturn_t iproc_adc_interrupt_thread(int irq, void *data) 171 + { 172 + irqreturn_t retval = IRQ_NONE; 173 + struct iproc_adc_priv *adc_priv; 174 + struct iio_dev *indio_dev = data; 175 + unsigned int valid_entries; 176 + u32 intr_status; 177 + u32 intr_channels; 178 + u32 channel_status; 179 + u32 ch_intr_status; 180 + 181 + adc_priv = iio_priv(indio_dev); 182 + 183 + regmap_read(adc_priv->regmap, IPROC_INTERRUPT_STATUS, &intr_status); 184 + dev_dbg(&indio_dev->dev, "iproc_adc_interrupt_thread(),INTRPT_STS:%x\n", 185 + intr_status); 186 + 187 + intr_channels = (intr_status & IPROC_ADC_INTR_MASK) >> IPROC_ADC_INTR; 188 + if (intr_channels) { 189 + regmap_read(adc_priv->regmap, 190 + IPROC_ADC_CHANNEL_INTERRUPT_STATUS + 191 + IPROC_ADC_CHANNEL_OFFSET * adc_priv->chan_id, 192 + &ch_intr_status); 193 + 194 + if (ch_intr_status & IPROC_ADC_CHANNEL_WTRMRK_INTR_MASK) { 195 + regmap_read(adc_priv->regmap, 196 + IPROC_ADC_CHANNEL_STATUS + 197 + IPROC_ADC_CHANNEL_OFFSET * 198 + adc_priv->chan_id, 199 + &channel_status); 200 + 201 + valid_entries = ((channel_status & 202 + IPROC_ADC_CHANNEL_VALID_ENTERIES_MASK) >> 203 + IPROC_ADC_CHANNEL_VALID_ENTERIES); 204 + if (valid_entries >= 1) { 205 + regmap_read(adc_priv->regmap, 206 + IPROC_ADC_CHANNEL_DATA + 207 + IPROC_ADC_CHANNEL_OFFSET * 208 + adc_priv->chan_id, 209 + &adc_priv->chan_val); 210 + complete(&adc_priv->completion); 211 + } else { 212 + dev_err(&indio_dev->dev, 213 + "No data rcvd on channel %d\n", 214 + adc_priv->chan_id); 215 + } 216 + regmap_write(adc_priv->regmap, 217 + IPROC_ADC_CHANNEL_INTERRUPT_MASK + 218 + IPROC_ADC_CHANNEL_OFFSET * 219 + adc_priv->chan_id, 220 + (ch_intr_status & 221 + ~(IPROC_ADC_CHANNEL_WTRMRK_INTR_MASK))); 222 + } 223 + regmap_write(adc_priv->regmap, 224 + IPROC_ADC_CHANNEL_INTERRUPT_STATUS + 225 + IPROC_ADC_CHANNEL_OFFSET * adc_priv->chan_id, 226 + ch_intr_status); 227 + regmap_write(adc_priv->regmap, IPROC_INTERRUPT_STATUS, 228 + intr_channels); 229 + retval = IRQ_HANDLED; 230 + } 231 + 232 + return retval; 233 + } 234 + 235 + static int iproc_adc_do_read(struct iio_dev *indio_dev, 236 + int channel, 237 + u16 *p_adc_data) 238 + { 239 + int read_len = 0; 240 + u32 val; 241 + u32 mask; 242 + u32 val_check; 243 + int failed_cnt = 0; 244 + struct iproc_adc_priv *adc_priv = iio_priv(indio_dev); 245 + 246 + mutex_lock(&adc_priv->mutex); 247 + 248 + /* 249 + * After a read is complete the ADC interrupts will be disabled so 250 + * we can assume this section of code is safe from interrupts. 251 + */ 252 + adc_priv->chan_val = -1; 253 + adc_priv->chan_id = channel; 254 + 255 + reinit_completion(&adc_priv->completion); 256 + /* Clear any pending interrupt */ 257 + regmap_update_bits(adc_priv->regmap, IPROC_INTERRUPT_STATUS, 258 + IPROC_ADC_INTR_MASK | IPROC_ADC_AUXDATA_RDY_INTR, 259 + ((0x0 << channel) << IPROC_ADC_INTR) | 260 + IPROC_ADC_AUXDATA_RDY_INTR); 261 + 262 + /* Configure channel for snapshot mode and enable */ 263 + val = (BIT(IPROC_ADC_CHANNEL_ROUNDS) | 264 + (IPROC_ADC_CHANNEL_MODE_SNAPSHOT << IPROC_ADC_CHANNEL_MODE) | 265 + (0x1 << IPROC_ADC_CHANNEL_ENABLE)); 266 + 267 + mask = IPROC_ADC_CHANNEL_ROUNDS_MASK | IPROC_ADC_CHANNEL_MODE_MASK | 268 + IPROC_ADC_CHANNEL_ENABLE_MASK; 269 + regmap_update_bits(adc_priv->regmap, (IPROC_ADC_CHANNEL_REGCTL1 + 270 + IPROC_ADC_CHANNEL_OFFSET * channel), 271 + mask, val); 272 + 273 + /* Set the Watermark for a channel */ 274 + regmap_update_bits(adc_priv->regmap, (IPROC_ADC_CHANNEL_REGCTL2 + 275 + IPROC_ADC_CHANNEL_OFFSET * channel), 276 + IPROC_ADC_CHANNEL_WATERMARK_MASK, 277 + 0x1); 278 + 279 + /* Enable water mark interrupt */ 280 + regmap_update_bits(adc_priv->regmap, (IPROC_ADC_CHANNEL_INTERRUPT_MASK + 281 + IPROC_ADC_CHANNEL_OFFSET * 282 + channel), 283 + IPROC_ADC_CHANNEL_WTRMRK_INTR_MASK, 284 + IPROC_ADC_WATER_MARK_INTR_ENABLE); 285 + regmap_read(adc_priv->regmap, IPROC_INTERRUPT_MASK, &val); 286 + 287 + /* Enable ADC interrupt for a channel */ 288 + val |= (BIT(channel) << IPROC_ADC_INTR); 289 + regmap_write(adc_priv->regmap, IPROC_INTERRUPT_MASK, val); 290 + 291 + /* 292 + * There seems to be a very rare issue where writing to this register 293 + * does not take effect. To work around the issue we will try multiple 294 + * writes. In total we will spend about 10*10 = 100 us attempting this. 295 + * Testing has shown that this may loop a few time, but we have never 296 + * hit the full count. 297 + */ 298 + regmap_read(adc_priv->regmap, IPROC_INTERRUPT_MASK, &val_check); 299 + while (val_check != val) { 300 + failed_cnt++; 301 + 302 + if (failed_cnt > IPROC_ADC_INTMASK_RETRY_ATTEMPTS) 303 + break; 304 + 305 + udelay(10); 306 + regmap_update_bits(adc_priv->regmap, IPROC_INTERRUPT_MASK, 307 + IPROC_ADC_INTR_MASK, 308 + ((0x1 << channel) << 309 + IPROC_ADC_INTR)); 310 + 311 + regmap_read(adc_priv->regmap, IPROC_INTERRUPT_MASK, &val_check); 312 + } 313 + 314 + if (failed_cnt) { 315 + dev_dbg(&indio_dev->dev, 316 + "IntMask failed (%d times)", failed_cnt); 317 + if (failed_cnt > IPROC_ADC_INTMASK_RETRY_ATTEMPTS) { 318 + dev_err(&indio_dev->dev, 319 + "IntMask set failed. Read will likely fail."); 320 + read_len = -EIO; 321 + goto adc_err; 322 + }; 323 + } 324 + regmap_read(adc_priv->regmap, IPROC_INTERRUPT_MASK, &val_check); 325 + 326 + if (wait_for_completion_timeout(&adc_priv->completion, 327 + IPROC_ADC_READ_TIMEOUT) > 0) { 328 + 329 + /* Only the lower 16 bits are relevant */ 330 + *p_adc_data = adc_priv->chan_val & 0xFFFF; 331 + read_len = sizeof(*p_adc_data); 332 + 333 + } else { 334 + /* 335 + * We never got the interrupt, something went wrong. 336 + * Perhaps the interrupt may still be coming, we do not want 337 + * that now. Lets disable the ADC interrupt, and clear the 338 + * status to put it back in to normal state. 339 + */ 340 + read_len = -ETIMEDOUT; 341 + goto adc_err; 342 + } 343 + mutex_unlock(&adc_priv->mutex); 344 + 345 + return read_len; 346 + 347 + adc_err: 348 + regmap_update_bits(adc_priv->regmap, IPROC_INTERRUPT_MASK, 349 + IPROC_ADC_INTR_MASK, 350 + ((0x0 << channel) << IPROC_ADC_INTR)); 351 + 352 + regmap_update_bits(adc_priv->regmap, IPROC_INTERRUPT_STATUS, 353 + IPROC_ADC_INTR_MASK, 354 + ((0x0 << channel) << IPROC_ADC_INTR)); 355 + 356 + dev_err(&indio_dev->dev, "Timed out waiting for ADC data!\n"); 357 + iproc_adc_reg_dump(indio_dev); 358 + mutex_unlock(&adc_priv->mutex); 359 + 360 + return read_len; 361 + } 362 + 363 + static int iproc_adc_enable(struct iio_dev *indio_dev) 364 + { 365 + u32 val; 366 + u32 channel_id; 367 + struct iproc_adc_priv *adc_priv = iio_priv(indio_dev); 368 + int ret; 369 + 370 + /* Set i_amux = 3b'000, select channel 0 */ 371 + ret = regmap_update_bits(adc_priv->regmap, IPROC_ANALOG_CONTROL, 372 + IPROC_ADC_CHANNEL_SEL_MASK, 0); 373 + if (ret) { 374 + dev_err(&indio_dev->dev, 375 + "failed to write IPROC_ANALOG_CONTROL %d\n", ret); 376 + return ret; 377 + } 378 + adc_priv->chan_val = -1; 379 + 380 + /* 381 + * PWR up LDO, ADC, and Band Gap (0 to enable) 382 + * Also enable ADC controller (set high) 383 + */ 384 + ret = regmap_read(adc_priv->regmap, IPROC_REGCTL2, &val); 385 + if (ret) { 386 + dev_err(&indio_dev->dev, 387 + "failed to read IPROC_REGCTL2 %d\n", ret); 388 + return ret; 389 + } 390 + 391 + val &= ~(IPROC_ADC_PWR_LDO | IPROC_ADC_PWR_ADC | IPROC_ADC_PWR_BG); 392 + 393 + ret = regmap_write(adc_priv->regmap, IPROC_REGCTL2, val); 394 + if (ret) { 395 + dev_err(&indio_dev->dev, 396 + "failed to write IPROC_REGCTL2 %d\n", ret); 397 + return ret; 398 + } 399 + 400 + ret = regmap_read(adc_priv->regmap, IPROC_REGCTL2, &val); 401 + if (ret) { 402 + dev_err(&indio_dev->dev, 403 + "failed to read IPROC_REGCTL2 %d\n", ret); 404 + return ret; 405 + } 406 + 407 + val |= IPROC_ADC_CONTROLLER_EN; 408 + ret = regmap_write(adc_priv->regmap, IPROC_REGCTL2, val); 409 + if (ret) { 410 + dev_err(&indio_dev->dev, 411 + "failed to write IPROC_REGCTL2 %d\n", ret); 412 + return ret; 413 + } 414 + 415 + for (channel_id = 0; channel_id < indio_dev->num_channels; 416 + channel_id++) { 417 + ret = regmap_write(adc_priv->regmap, 418 + IPROC_ADC_CHANNEL_INTERRUPT_MASK + 419 + IPROC_ADC_CHANNEL_OFFSET * channel_id, 0); 420 + if (ret) { 421 + dev_err(&indio_dev->dev, 422 + "failed to write ADC_CHANNEL_INTERRUPT_MASK %d\n", 423 + ret); 424 + return ret; 425 + } 426 + 427 + ret = regmap_write(adc_priv->regmap, 428 + IPROC_ADC_CHANNEL_INTERRUPT_STATUS + 429 + IPROC_ADC_CHANNEL_OFFSET * channel_id, 0); 430 + if (ret) { 431 + dev_err(&indio_dev->dev, 432 + "failed to write ADC_CHANNEL_INTERRUPT_STATUS %d\n", 433 + ret); 434 + return ret; 435 + } 436 + } 437 + 438 + return 0; 439 + } 440 + 441 + static void iproc_adc_disable(struct iio_dev *indio_dev) 442 + { 443 + u32 val; 444 + int ret; 445 + struct iproc_adc_priv *adc_priv = iio_priv(indio_dev); 446 + 447 + ret = regmap_read(adc_priv->regmap, IPROC_REGCTL2, &val); 448 + if (ret) { 449 + dev_err(&indio_dev->dev, 450 + "failed to read IPROC_REGCTL2 %d\n", ret); 451 + return; 452 + } 453 + 454 + val &= ~IPROC_ADC_CONTROLLER_EN; 455 + ret = regmap_write(adc_priv->regmap, IPROC_REGCTL2, val); 456 + if (ret) { 457 + dev_err(&indio_dev->dev, 458 + "failed to write IPROC_REGCTL2 %d\n", ret); 459 + return; 460 + } 461 + } 462 + 463 + static int iproc_adc_read_raw(struct iio_dev *indio_dev, 464 + struct iio_chan_spec const *chan, 465 + int *val, 466 + int *val2, 467 + long mask) 468 + { 469 + u16 adc_data; 470 + int err; 471 + 472 + switch (mask) { 473 + case IIO_CHAN_INFO_RAW: 474 + err = iproc_adc_do_read(indio_dev, chan->channel, &adc_data); 475 + if (err < 0) 476 + return err; 477 + *val = adc_data; 478 + return IIO_VAL_INT; 479 + case IIO_CHAN_INFO_SCALE: 480 + switch (chan->type) { 481 + case IIO_VOLTAGE: 482 + *val = 1800; 483 + *val2 = 10; 484 + return IIO_VAL_FRACTIONAL_LOG2; 485 + default: 486 + return -EINVAL; 487 + } 488 + default: 489 + return -EINVAL; 490 + } 491 + } 492 + 493 + static const struct iio_info iproc_adc_iio_info = { 494 + .read_raw = &iproc_adc_read_raw, 495 + .driver_module = THIS_MODULE, 496 + }; 497 + 498 + #define IPROC_ADC_CHANNEL(_index, _id) { \ 499 + .type = IIO_VOLTAGE, \ 500 + .indexed = 1, \ 501 + .channel = _index, \ 502 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 503 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 504 + .datasheet_name = _id, \ 505 + } 506 + 507 + static const struct iio_chan_spec iproc_adc_iio_channels[] = { 508 + IPROC_ADC_CHANNEL(0, "adc0"), 509 + IPROC_ADC_CHANNEL(1, "adc1"), 510 + IPROC_ADC_CHANNEL(2, "adc2"), 511 + IPROC_ADC_CHANNEL(3, "adc3"), 512 + IPROC_ADC_CHANNEL(4, "adc4"), 513 + IPROC_ADC_CHANNEL(5, "adc5"), 514 + IPROC_ADC_CHANNEL(6, "adc6"), 515 + IPROC_ADC_CHANNEL(7, "adc7"), 516 + }; 517 + 518 + static int iproc_adc_probe(struct platform_device *pdev) 519 + { 520 + struct iproc_adc_priv *adc_priv; 521 + struct iio_dev *indio_dev = NULL; 522 + int ret; 523 + 524 + indio_dev = devm_iio_device_alloc(&pdev->dev, 525 + sizeof(*adc_priv)); 526 + if (!indio_dev) { 527 + dev_err(&pdev->dev, "failed to allocate iio device\n"); 528 + return -ENOMEM; 529 + } 530 + 531 + adc_priv = iio_priv(indio_dev); 532 + platform_set_drvdata(pdev, indio_dev); 533 + 534 + mutex_init(&adc_priv->mutex); 535 + 536 + init_completion(&adc_priv->completion); 537 + 538 + adc_priv->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, 539 + "adc-syscon"); 540 + if (IS_ERR(adc_priv->regmap)) { 541 + dev_err(&pdev->dev, "failed to get handle for tsc syscon\n"); 542 + ret = PTR_ERR(adc_priv->regmap); 543 + return ret; 544 + } 545 + 546 + adc_priv->adc_clk = devm_clk_get(&pdev->dev, "tsc_clk"); 547 + if (IS_ERR(adc_priv->adc_clk)) { 548 + dev_err(&pdev->dev, 549 + "failed getting clock tsc_clk\n"); 550 + ret = PTR_ERR(adc_priv->adc_clk); 551 + return ret; 552 + } 553 + 554 + adc_priv->irqno = platform_get_irq(pdev, 0); 555 + if (adc_priv->irqno <= 0) { 556 + dev_err(&pdev->dev, "platform_get_irq failed\n"); 557 + ret = -ENODEV; 558 + return ret; 559 + } 560 + 561 + ret = regmap_update_bits(adc_priv->regmap, IPROC_REGCTL2, 562 + IPROC_ADC_AUXIN_SCAN_ENA, 0); 563 + if (ret) { 564 + dev_err(&pdev->dev, "failed to write IPROC_REGCTL2 %d\n", ret); 565 + return ret; 566 + } 567 + 568 + ret = devm_request_threaded_irq(&pdev->dev, adc_priv->irqno, 569 + iproc_adc_interrupt_thread, 570 + iproc_adc_interrupt_handler, 571 + IRQF_SHARED, "iproc-adc", indio_dev); 572 + if (ret) { 573 + dev_err(&pdev->dev, "request_irq error %d\n", ret); 574 + return ret; 575 + } 576 + 577 + ret = clk_prepare_enable(adc_priv->adc_clk); 578 + if (ret) { 579 + dev_err(&pdev->dev, 580 + "clk_prepare_enable failed %d\n", ret); 581 + return ret; 582 + } 583 + 584 + ret = iproc_adc_enable(indio_dev); 585 + if (ret) { 586 + dev_err(&pdev->dev, "failed to enable adc %d\n", ret); 587 + goto err_adc_enable; 588 + } 589 + 590 + indio_dev->name = "iproc-static-adc"; 591 + indio_dev->dev.parent = &pdev->dev; 592 + indio_dev->dev.of_node = pdev->dev.of_node; 593 + indio_dev->info = &iproc_adc_iio_info; 594 + indio_dev->modes = INDIO_DIRECT_MODE; 595 + indio_dev->channels = iproc_adc_iio_channels; 596 + indio_dev->num_channels = ARRAY_SIZE(iproc_adc_iio_channels); 597 + 598 + ret = iio_device_register(indio_dev); 599 + if (ret) { 600 + dev_err(&pdev->dev, "iio_device_register failed:err %d\n", ret); 601 + goto err_clk; 602 + } 603 + 604 + return 0; 605 + 606 + err_clk: 607 + iproc_adc_disable(indio_dev); 608 + err_adc_enable: 609 + clk_disable_unprepare(adc_priv->adc_clk); 610 + 611 + return ret; 612 + } 613 + 614 + static int iproc_adc_remove(struct platform_device *pdev) 615 + { 616 + struct iio_dev *indio_dev = platform_get_drvdata(pdev); 617 + struct iproc_adc_priv *adc_priv = iio_priv(indio_dev); 618 + 619 + iio_device_unregister(indio_dev); 620 + iproc_adc_disable(indio_dev); 621 + clk_disable_unprepare(adc_priv->adc_clk); 622 + 623 + return 0; 624 + } 625 + 626 + static const struct of_device_id iproc_adc_of_match[] = { 627 + {.compatible = "brcm,iproc-static-adc", }, 628 + { }, 629 + }; 630 + MODULE_DEVICE_TABLE(of, iproc_adc_of_match); 631 + 632 + static struct platform_driver iproc_adc_driver = { 633 + .probe = iproc_adc_probe, 634 + .remove = iproc_adc_remove, 635 + .driver = { 636 + .name = "iproc-static-adc", 637 + .of_match_table = of_match_ptr(iproc_adc_of_match), 638 + }, 639 + }; 640 + module_platform_driver(iproc_adc_driver); 641 + 642 + MODULE_DESCRIPTION("Broadcom iProc ADC controller driver"); 643 + MODULE_AUTHOR("Raveendra Padasalagi <raveendra.padasalagi@broadcom.com>"); 644 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/iio/adc/cc10001_adc.c
··· 186 186 187 187 if (!sample_invalid) 188 188 iio_push_to_buffers_with_timestamp(indio_dev, data, 189 - iio_get_time_ns()); 189 + iio_get_time_ns(indio_dev)); 190 190 iio_trigger_notify_done(indio_dev->trig); 191 191 192 192 return IRQ_HANDLED;
+2 -1
drivers/iio/adc/hi8435.c
··· 400 400 iio_push_event(idev, 401 401 IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, i, 402 402 IIO_EV_TYPE_THRESH, dir), 403 - iio_get_time_ns()); 403 + iio_get_time_ns(idev)); 404 404 } 405 405 } 406 406 ··· 455 455 mutex_init(&priv->lock); 456 456 457 457 idev->dev.parent = &spi->dev; 458 + idev->dev.of_node = spi->dev.of_node; 458 459 idev->name = spi_get_device_id(spi)->name; 459 460 idev->modes = INDIO_DIRECT_MODE; 460 461 idev->info = &hi8435_info;
+4 -3
drivers/iio/adc/ina2xx-adc.c
··· 465 465 s64 time_a, time_b; 466 466 unsigned int alert; 467 467 468 - time_a = iio_get_time_ns(); 468 + time_a = iio_get_time_ns(indio_dev); 469 469 470 470 /* 471 471 * Because the timer thread and the chip conversion clock ··· 504 504 data[i++] = val; 505 505 } 506 506 507 - time_b = iio_get_time_ns(); 507 + time_b = iio_get_time_ns(indio_dev); 508 508 509 509 iio_push_to_buffers_with_timestamp(indio_dev, 510 510 (unsigned int *)data, time_a); ··· 554 554 dev_dbg(&indio_dev->dev, "Async readout mode: %d\n", 555 555 chip->allow_async_readout); 556 556 557 - chip->prev_ns = iio_get_time_ns(); 557 + chip->prev_ns = iio_get_time_ns(indio_dev); 558 558 559 559 chip->task = kthread_run(ina2xx_capture_thread, (void *)indio_dev, 560 560 "%s:%d-%uus", indio_dev->name, indio_dev->id, ··· 691 691 692 692 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; 693 693 indio_dev->dev.parent = &client->dev; 694 + indio_dev->dev.of_node = client->dev.of_node; 694 695 indio_dev->channels = ina2xx_channels; 695 696 indio_dev->num_channels = ARRAY_SIZE(ina2xx_channels); 696 697 indio_dev->name = id->name;
+1
drivers/iio/adc/max1027.c
··· 426 426 427 427 indio_dev->name = spi_get_device_id(spi)->name; 428 428 indio_dev->dev.parent = &spi->dev; 429 + indio_dev->dev.of_node = spi->dev.of_node; 429 430 indio_dev->info = &max1027_info; 430 431 indio_dev->modes = INDIO_DIRECT_MODE; 431 432 indio_dev->channels = st->info->channels;
+64 -3
drivers/iio/adc/max1363.c
··· 25 25 #include <linux/slab.h> 26 26 #include <linux/err.h> 27 27 #include <linux/module.h> 28 + #include <linux/of.h> 29 + #include <linux/of_device.h> 28 30 29 31 #include <linux/iio/iio.h> 30 32 #include <linux/iio/sysfs.h> ··· 790 788 { 791 789 struct iio_dev *indio_dev = private; 792 790 struct max1363_state *st = iio_priv(indio_dev); 793 - s64 timestamp = iio_get_time_ns(); 791 + s64 timestamp = iio_get_time_ns(indio_dev); 794 792 unsigned long mask, loc; 795 793 u8 rx; 796 794 u8 tx[2] = { st->setupbyte, ··· 1508 1506 if (b_sent < 0) 1509 1507 goto done_free; 1510 1508 1511 - iio_push_to_buffers_with_timestamp(indio_dev, rxbuf, iio_get_time_ns()); 1509 + iio_push_to_buffers_with_timestamp(indio_dev, rxbuf, 1510 + iio_get_time_ns(indio_dev)); 1512 1511 1513 1512 done_free: 1514 1513 kfree(rxbuf); ··· 1519 1516 return IRQ_HANDLED; 1520 1517 } 1521 1518 1519 + #ifdef CONFIG_OF 1520 + 1521 + #define MAX1363_COMPATIBLE(of_compatible, cfg) { \ 1522 + .compatible = of_compatible, \ 1523 + .data = &max1363_chip_info_tbl[cfg], \ 1524 + } 1525 + 1526 + static const struct of_device_id max1363_of_match[] = { 1527 + MAX1363_COMPATIBLE("maxim,max1361", max1361), 1528 + MAX1363_COMPATIBLE("maxim,max1362", max1362), 1529 + MAX1363_COMPATIBLE("maxim,max1363", max1363), 1530 + MAX1363_COMPATIBLE("maxim,max1364", max1364), 1531 + MAX1363_COMPATIBLE("maxim,max1036", max1036), 1532 + MAX1363_COMPATIBLE("maxim,max1037", max1037), 1533 + MAX1363_COMPATIBLE("maxim,max1038", max1038), 1534 + MAX1363_COMPATIBLE("maxim,max1039", max1039), 1535 + MAX1363_COMPATIBLE("maxim,max1136", max1136), 1536 + MAX1363_COMPATIBLE("maxim,max1137", max1137), 1537 + MAX1363_COMPATIBLE("maxim,max1138", max1138), 1538 + MAX1363_COMPATIBLE("maxim,max1139", max1139), 1539 + MAX1363_COMPATIBLE("maxim,max1236", max1236), 1540 + MAX1363_COMPATIBLE("maxim,max1237", max1237), 1541 + MAX1363_COMPATIBLE("maxim,max1238", max1238), 1542 + MAX1363_COMPATIBLE("maxim,max1239", max1239), 1543 + MAX1363_COMPATIBLE("maxim,max11600", max11600), 1544 + MAX1363_COMPATIBLE("maxim,max11601", max11601), 1545 + MAX1363_COMPATIBLE("maxim,max11602", max11602), 1546 + MAX1363_COMPATIBLE("maxim,max11603", max11603), 1547 + MAX1363_COMPATIBLE("maxim,max11604", max11604), 1548 + MAX1363_COMPATIBLE("maxim,max11605", max11605), 1549 + MAX1363_COMPATIBLE("maxim,max11606", max11606), 1550 + MAX1363_COMPATIBLE("maxim,max11607", max11607), 1551 + MAX1363_COMPATIBLE("maxim,max11608", max11608), 1552 + MAX1363_COMPATIBLE("maxim,max11609", max11609), 1553 + MAX1363_COMPATIBLE("maxim,max11610", max11610), 1554 + MAX1363_COMPATIBLE("maxim,max11611", max11611), 1555 + MAX1363_COMPATIBLE("maxim,max11612", max11612), 1556 + MAX1363_COMPATIBLE("maxim,max11613", max11613), 1557 + MAX1363_COMPATIBLE("maxim,max11614", max11614), 1558 + MAX1363_COMPATIBLE("maxim,max11615", max11615), 1559 + MAX1363_COMPATIBLE("maxim,max11616", max11616), 1560 + MAX1363_COMPATIBLE("maxim,max11617", max11617), 1561 + MAX1363_COMPATIBLE("maxim,max11644", max11644), 1562 + MAX1363_COMPATIBLE("maxim,max11645", max11645), 1563 + MAX1363_COMPATIBLE("maxim,max11646", max11646), 1564 + MAX1363_COMPATIBLE("maxim,max11647", max11647), 1565 + { /* sentinel */ } 1566 + }; 1567 + #endif 1568 + 1522 1569 static int max1363_probe(struct i2c_client *client, 1523 1570 const struct i2c_device_id *id) 1524 1571 { ··· 1576 1523 struct max1363_state *st; 1577 1524 struct iio_dev *indio_dev; 1578 1525 struct regulator *vref; 1526 + const struct of_device_id *match; 1579 1527 1580 1528 indio_dev = devm_iio_device_alloc(&client->dev, 1581 1529 sizeof(struct max1363_state)); ··· 1603 1549 /* this is only used for device removal purposes */ 1604 1550 i2c_set_clientdata(client, indio_dev); 1605 1551 1606 - st->chip_info = &max1363_chip_info_tbl[id->driver_data]; 1552 + match = of_match_device(of_match_ptr(max1363_of_match), 1553 + &client->dev); 1554 + if (match) 1555 + st->chip_info = of_device_get_match_data(&client->dev); 1556 + else 1557 + st->chip_info = &max1363_chip_info_tbl[id->driver_data]; 1607 1558 st->client = client; 1608 1559 1609 1560 st->vref_uv = st->chip_info->int_vref_mv * 1000; ··· 1646 1587 1647 1588 /* Establish that the iio_dev is a child of the i2c device */ 1648 1589 indio_dev->dev.parent = &client->dev; 1590 + indio_dev->dev.of_node = client->dev.of_node; 1649 1591 indio_dev->name = id->name; 1650 1592 indio_dev->channels = st->chip_info->channels; 1651 1593 indio_dev->num_channels = st->chip_info->num_channels; ··· 1752 1692 static struct i2c_driver max1363_driver = { 1753 1693 .driver = { 1754 1694 .name = "max1363", 1695 + .of_match_table = of_match_ptr(max1363_of_match), 1755 1696 }, 1756 1697 .probe = max1363_probe, 1757 1698 .remove = max1363_remove,
+1
drivers/iio/adc/mcp320x.c
··· 308 308 adc->spi = spi; 309 309 310 310 indio_dev->dev.parent = &spi->dev; 311 + indio_dev->dev.of_node = spi->dev.of_node; 311 312 indio_dev->name = spi_get_device_id(spi)->name; 312 313 indio_dev->modes = INDIO_DIRECT_MODE; 313 314 indio_dev->info = &mcp320x_info;
+1
drivers/iio/adc/mcp3422.c
··· 352 352 mutex_init(&adc->lock); 353 353 354 354 indio_dev->dev.parent = &client->dev; 355 + indio_dev->dev.of_node = client->dev.of_node; 355 356 indio_dev->name = dev_name(&client->dev); 356 357 indio_dev->modes = INDIO_DIRECT_MODE; 357 358 indio_dev->info = &mcp3422_info;
+1
drivers/iio/adc/nau7802.c
··· 433 433 i2c_set_clientdata(client, indio_dev); 434 434 435 435 indio_dev->dev.parent = &client->dev; 436 + indio_dev->dev.of_node = client->dev.of_node; 436 437 indio_dev->name = dev_name(&client->dev); 437 438 indio_dev->modes = INDIO_DIRECT_MODE; 438 439 indio_dev->info = &nau7802_info;
+3 -1
drivers/iio/adc/ti-adc081c.c
··· 139 139 if (ret < 0) 140 140 goto out; 141 141 buf[0] = ret; 142 - iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns()); 142 + iio_push_to_buffers_with_timestamp(indio_dev, buf, 143 + iio_get_time_ns(indio_dev)); 143 144 out: 144 145 iio_trigger_notify_done(indio_dev->trig); 145 146 return IRQ_HANDLED; ··· 186 185 return err; 187 186 188 187 iio->dev.parent = &client->dev; 188 + iio->dev.of_node = client->dev.of_node; 189 189 iio->name = dev_name(&client->dev); 190 190 iio->modes = INDIO_DIRECT_MODE; 191 191 iio->info = &adc081c_info;
+1
drivers/iio/adc/ti-adc0832.c
··· 194 194 195 195 indio_dev->name = spi_get_device_id(spi)->name; 196 196 indio_dev->dev.parent = &spi->dev; 197 + indio_dev->dev.of_node = spi->dev.of_node; 197 198 indio_dev->info = &adc0832_info; 198 199 indio_dev->modes = INDIO_DIRECT_MODE; 199 200
+1
drivers/iio/adc/ti-adc128s052.c
··· 150 150 spi_set_drvdata(spi, indio_dev); 151 151 152 152 indio_dev->dev.parent = &spi->dev; 153 + indio_dev->dev.of_node = spi->dev.of_node; 153 154 indio_dev->name = spi_get_device_id(spi)->name; 154 155 indio_dev->modes = INDIO_DIRECT_MODE; 155 156 indio_dev->info = &adc128_info;
+3 -1
drivers/iio/adc/ti-ads1015.c
··· 288 288 buf[0] = res; 289 289 mutex_unlock(&data->lock); 290 290 291 - iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns()); 291 + iio_push_to_buffers_with_timestamp(indio_dev, buf, 292 + iio_get_time_ns(indio_dev)); 292 293 293 294 err: 294 295 iio_trigger_notify_done(indio_dev->trig); ··· 586 585 mutex_init(&data->lock); 587 586 588 587 indio_dev->dev.parent = &client->dev; 588 + indio_dev->dev.of_node = client->dev.of_node; 589 589 indio_dev->name = ADS1015_DRV_NAME; 590 590 indio_dev->modes = INDIO_DIRECT_MODE; 591 591
+1
drivers/iio/adc/ti-ads8688.c
··· 421 421 422 422 indio_dev->name = spi_get_device_id(spi)->name; 423 423 indio_dev->dev.parent = &spi->dev; 424 + indio_dev->dev.of_node = spi->dev.of_node; 424 425 indio_dev->modes = INDIO_DIRECT_MODE; 425 426 indio_dev->channels = st->chip_info->channels; 426 427 indio_dev->num_channels = st->chip_info->num_channels;
+2 -1
drivers/iio/adc/vf610_adc.c
··· 594 594 if (iio_buffer_enabled(indio_dev)) { 595 595 info->buffer[0] = info->value; 596 596 iio_push_to_buffers_with_timestamp(indio_dev, 597 - info->buffer, iio_get_time_ns()); 597 + info->buffer, 598 + iio_get_time_ns(indio_dev)); 598 599 iio_trigger_notify_done(indio_dev->trig); 599 600 } else 600 601 complete(&info->completion);
+2 -2
drivers/iio/adc/xilinx-xadc-events.c
··· 46 46 iio_push_event(indio_dev, 47 47 IIO_UNMOD_EVENT_CODE(chan->type, chan->channel, 48 48 IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), 49 - iio_get_time_ns()); 49 + iio_get_time_ns(indio_dev)); 50 50 } else { 51 51 /* 52 52 * For other channels we don't know whether it is a upper or ··· 56 56 iio_push_event(indio_dev, 57 57 IIO_UNMOD_EVENT_CODE(chan->type, chan->channel, 58 58 IIO_EV_TYPE_THRESH, IIO_EV_DIR_EITHER), 59 - iio_get_time_ns()); 59 + iio_get_time_ns(indio_dev)); 60 60 } 61 61 } 62 62
+1 -1
drivers/iio/chemical/atlas-ph-sensor.c
··· 343 343 344 344 if (!ret) 345 345 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 346 - iio_get_time_ns()); 346 + iio_get_time_ns(indio_dev)); 347 347 348 348 iio_trigger_notify_done(indio_dev->trig); 349 349
+23 -19
drivers/iio/common/st_sensors/st_sensors_buffer.c
··· 24 24 25 25 static int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) 26 26 { 27 - int i, len; 28 - int total = 0; 27 + int i; 29 28 struct st_sensor_data *sdata = iio_priv(indio_dev); 30 29 unsigned int num_data_channels = sdata->num_data_channels; 31 30 32 - for (i = 0; i < num_data_channels; i++) { 33 - unsigned int bytes_to_read; 31 + for_each_set_bit(i, indio_dev->active_scan_mask, num_data_channels) { 32 + const struct iio_chan_spec *channel = &indio_dev->channels[i]; 33 + unsigned int bytes_to_read = channel->scan_type.realbits >> 3; 34 + unsigned int storage_bytes = 35 + channel->scan_type.storagebits >> 3; 34 36 35 - if (test_bit(i, indio_dev->active_scan_mask)) { 36 - bytes_to_read = indio_dev->channels[i].scan_type.storagebits >> 3; 37 - len = sdata->tf->read_multiple_byte(&sdata->tb, 38 - sdata->dev, indio_dev->channels[i].address, 39 - bytes_to_read, 40 - buf + total, sdata->multiread_bit); 37 + buf = PTR_ALIGN(buf, storage_bytes); 38 + if (sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, 39 + channel->address, 40 + bytes_to_read, buf, 41 + sdata->multiread_bit) < 42 + bytes_to_read) 43 + return -EIO; 41 44 42 - if (len < bytes_to_read) 43 - return -EIO; 44 - 45 - /* Advance the buffer pointer */ 46 - total += len; 47 - } 45 + /* Advance the buffer pointer */ 46 + buf += storage_bytes; 48 47 } 49 48 50 - return total; 49 + return 0; 51 50 } 52 51 53 52 irqreturn_t st_sensors_trigger_handler(int irq, void *p) ··· 57 58 struct st_sensor_data *sdata = iio_priv(indio_dev); 58 59 s64 timestamp; 59 60 60 - /* If we do timetamping here, do it before reading the values */ 61 + /* 62 + * If we do timetamping here, do it before reading the values, because 63 + * once we've read the values, new interrupts can occur (when using 64 + * the hardware trigger) and the hw_timestamp may get updated. 65 + * By storing it in a local variable first, we are safe. 66 + */ 61 67 if (sdata->hw_irq_trigger) 62 68 timestamp = sdata->hw_timestamp; 63 69 else 64 - timestamp = iio_get_time_ns(); 70 + timestamp = iio_get_time_ns(indio_dev); 65 71 66 72 len = st_sensors_get_buffer_element(indio_dev, sdata->buffer_data); 67 73 if (len < 0)
+16 -12
drivers/iio/common/st_sensors/st_sensors_core.c
··· 490 490 int err; 491 491 u8 *outdata; 492 492 struct st_sensor_data *sdata = iio_priv(indio_dev); 493 - unsigned int byte_for_channel = ch->scan_type.storagebits >> 3; 493 + unsigned int byte_for_channel = ch->scan_type.realbits >> 3; 494 494 495 495 outdata = kmalloc(byte_for_channel, GFP_KERNEL); 496 496 if (!outdata) ··· 550 550 int num_sensors_list, 551 551 const struct st_sensor_settings *sensor_settings) 552 552 { 553 - int i, n, err; 553 + int i, n, err = 0; 554 554 u8 wai; 555 555 struct st_sensor_data *sdata = iio_priv(indio_dev); 556 556 ··· 570 570 return -ENODEV; 571 571 } 572 572 573 - err = sdata->tf->read_byte(&sdata->tb, sdata->dev, 574 - sensor_settings[i].wai_addr, &wai); 575 - if (err < 0) { 576 - dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n"); 577 - return err; 578 - } 573 + if (sensor_settings[i].wai_addr) { 574 + err = sdata->tf->read_byte(&sdata->tb, sdata->dev, 575 + sensor_settings[i].wai_addr, &wai); 576 + if (err < 0) { 577 + dev_err(&indio_dev->dev, 578 + "failed to read Who-Am-I register.\n"); 579 + return err; 580 + } 579 581 580 - if (sensor_settings[i].wai != wai) { 581 - dev_err(&indio_dev->dev, "%s: WhoAmI mismatch (0x%x).\n", 582 - indio_dev->name, wai); 583 - return -EINVAL; 582 + if (sensor_settings[i].wai != wai) { 583 + dev_err(&indio_dev->dev, 584 + "%s: WhoAmI mismatch (0x%x).\n", 585 + indio_dev->name, wai); 586 + return -EINVAL; 587 + } 584 588 } 585 589 586 590 sdata->sensor_settings =
+111 -47
drivers/iio/common/st_sensors/st_sensors_trigger.c
··· 18 18 #include "st_sensors_core.h" 19 19 20 20 /** 21 + * st_sensors_new_samples_available() - check if more samples came in 22 + * returns: 23 + * 0 - no new samples available 24 + * 1 - new samples available 25 + * negative - error or unknown 26 + */ 27 + static int st_sensors_new_samples_available(struct iio_dev *indio_dev, 28 + struct st_sensor_data *sdata) 29 + { 30 + u8 status; 31 + int ret; 32 + 33 + /* How would I know if I can't check it? */ 34 + if (!sdata->sensor_settings->drdy_irq.addr_stat_drdy) 35 + return -EINVAL; 36 + 37 + /* No scan mask, no interrupt */ 38 + if (!indio_dev->active_scan_mask) 39 + return 0; 40 + 41 + ret = sdata->tf->read_byte(&sdata->tb, sdata->dev, 42 + sdata->sensor_settings->drdy_irq.addr_stat_drdy, 43 + &status); 44 + if (ret < 0) { 45 + dev_err(sdata->dev, 46 + "error checking samples available\n"); 47 + return ret; 48 + } 49 + /* 50 + * the lower bits of .active_scan_mask[0] is directly mapped 51 + * to the channels on the sensor: either bit 0 for 52 + * one-dimensional sensors, or e.g. x,y,z for accelerometers, 53 + * gyroscopes or magnetometers. No sensor use more than 3 54 + * channels, so cut the other status bits here. 55 + */ 56 + status &= 0x07; 57 + 58 + if (status & (u8)indio_dev->active_scan_mask[0]) 59 + return 1; 60 + 61 + return 0; 62 + } 63 + 64 + /** 21 65 * st_sensors_irq_handler() - top half of the IRQ-based triggers 22 66 * @irq: irq number 23 67 * @p: private handler data ··· 73 29 struct st_sensor_data *sdata = iio_priv(indio_dev); 74 30 75 31 /* Get the time stamp as close in time as possible */ 76 - sdata->hw_timestamp = iio_get_time_ns(); 32 + sdata->hw_timestamp = iio_get_time_ns(indio_dev); 77 33 return IRQ_WAKE_THREAD; 78 34 } 79 35 ··· 87 43 struct iio_trigger *trig = p; 88 44 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 89 45 struct st_sensor_data *sdata = iio_priv(indio_dev); 90 - int ret; 91 46 92 47 /* 93 48 * If this trigger is backed by a hardware interrupt and we have a 94 - * status register, check if this IRQ came from us 49 + * status register, check if this IRQ came from us. Notice that 50 + * we will process also if st_sensors_new_samples_available() 51 + * returns negative: if we can't check status, then poll 52 + * unconditionally. 95 53 */ 96 - if (sdata->sensor_settings->drdy_irq.addr_stat_drdy) { 97 - u8 status; 98 - 99 - ret = sdata->tf->read_byte(&sdata->tb, sdata->dev, 100 - sdata->sensor_settings->drdy_irq.addr_stat_drdy, 101 - &status); 102 - if (ret < 0) { 103 - dev_err(sdata->dev, "could not read channel status\n"); 104 - goto out_poll; 105 - } 106 - /* 107 - * the lower bits of .active_scan_mask[0] is directly mapped 108 - * to the channels on the sensor: either bit 0 for 109 - * one-dimensional sensors, or e.g. x,y,z for accelerometers, 110 - * gyroscopes or magnetometers. No sensor use more than 3 111 - * channels, so cut the other status bits here. 112 - */ 113 - status &= 0x07; 114 - 115 - /* 116 - * If this was not caused by any channels on this sensor, 117 - * return IRQ_NONE 118 - */ 119 - if (!indio_dev->active_scan_mask) 120 - return IRQ_NONE; 121 - if (!(status & (u8)indio_dev->active_scan_mask[0])) 122 - return IRQ_NONE; 54 + if (sdata->hw_irq_trigger && 55 + st_sensors_new_samples_available(indio_dev, sdata)) { 56 + iio_trigger_poll_chained(p); 57 + } else { 58 + dev_dbg(sdata->dev, "spurious IRQ\n"); 59 + return IRQ_NONE; 123 60 } 124 61 125 - out_poll: 126 - /* It's our IRQ: proceed to handle the register polling */ 127 - iio_trigger_poll_chained(p); 62 + /* 63 + * If we have proper level IRQs the handler will be re-entered if 64 + * the line is still active, so return here and come back in through 65 + * the top half if need be. 66 + */ 67 + if (!sdata->edge_irq) 68 + return IRQ_HANDLED; 69 + 70 + /* 71 + * If we are using egde IRQs, new samples arrived while processing 72 + * the IRQ and those may be missed unless we pick them here, so poll 73 + * again. If the sensor delivery frequency is very high, this thread 74 + * turns into a polled loop handler. 75 + */ 76 + while (sdata->hw_irq_trigger && 77 + st_sensors_new_samples_available(indio_dev, sdata)) { 78 + dev_dbg(sdata->dev, "more samples came in during polling\n"); 79 + sdata->hw_timestamp = iio_get_time_ns(indio_dev); 80 + iio_trigger_poll_chained(p); 81 + } 82 + 128 83 return IRQ_HANDLED; 129 84 } 130 85 ··· 150 107 * If the IRQ is triggered on falling edge, we need to mark the 151 108 * interrupt as active low, if the hardware supports this. 152 109 */ 153 - if (irq_trig == IRQF_TRIGGER_FALLING) { 110 + switch(irq_trig) { 111 + case IRQF_TRIGGER_FALLING: 112 + case IRQF_TRIGGER_LOW: 154 113 if (!sdata->sensor_settings->drdy_irq.addr_ihl) { 155 114 dev_err(&indio_dev->dev, 156 - "falling edge specified for IRQ but hardware " 157 - "only support rising edge, will request " 158 - "rising edge\n"); 159 - irq_trig = IRQF_TRIGGER_RISING; 115 + "falling/low specified for IRQ " 116 + "but hardware only support rising/high: " 117 + "will request rising/high\n"); 118 + if (irq_trig == IRQF_TRIGGER_FALLING) 119 + irq_trig = IRQF_TRIGGER_RISING; 120 + if (irq_trig == IRQF_TRIGGER_LOW) 121 + irq_trig = IRQF_TRIGGER_HIGH; 160 122 } else { 161 123 /* Set up INT active low i.e. falling edge */ 162 124 err = st_sensors_write_data_with_mask(indio_dev, ··· 170 122 if (err < 0) 171 123 goto iio_trigger_free; 172 124 dev_info(&indio_dev->dev, 173 - "interrupts on the falling edge\n"); 125 + "interrupts on the falling edge or " 126 + "active low level\n"); 174 127 } 175 - } else if (irq_trig == IRQF_TRIGGER_RISING) { 128 + break; 129 + case IRQF_TRIGGER_RISING: 176 130 dev_info(&indio_dev->dev, 177 131 "interrupts on the rising edge\n"); 178 - 179 - } else { 132 + break; 133 + case IRQF_TRIGGER_HIGH: 134 + dev_info(&indio_dev->dev, 135 + "interrupts active high level\n"); 136 + break; 137 + default: 138 + /* This is the most preferred mode, if possible */ 180 139 dev_err(&indio_dev->dev, 181 - "unsupported IRQ trigger specified (%lx), only " 182 - "rising and falling edges supported, enforce " 140 + "unsupported IRQ trigger specified (%lx), enforce " 183 141 "rising edge\n", irq_trig); 184 142 irq_trig = IRQF_TRIGGER_RISING; 185 143 } 144 + 145 + /* Tell the interrupt handler that we're dealing with edges */ 146 + if (irq_trig == IRQF_TRIGGER_FALLING || 147 + irq_trig == IRQF_TRIGGER_RISING) 148 + sdata->edge_irq = true; 149 + else 150 + /* 151 + * If we're not using edges (i.e. level interrupts) we 152 + * just mask off the IRQ, handle one interrupt, then 153 + * if the line is still low, we return to the 154 + * interrupt handler top half again and start over. 155 + */ 156 + irq_trig |= IRQF_ONESHOT; 186 157 187 158 /* 188 159 * If the interrupt pin is Open Drain, by definition this ··· 214 147 if (sdata->int_pin_open_drain && 215 148 sdata->sensor_settings->drdy_irq.addr_stat_drdy) 216 149 irq_trig |= IRQF_SHARED; 217 - 218 - /* Let's create an interrupt thread masking the hard IRQ here */ 219 - irq_trig |= IRQF_ONESHOT; 220 150 221 151 err = request_threaded_irq(sdata->get_irq_data_ready(indio_dev), 222 152 st_sensors_irq_handler,
+3 -3
drivers/iio/dac/ad5421.c
··· 242 242 0, 243 243 IIO_EV_TYPE_THRESH, 244 244 IIO_EV_DIR_RISING), 245 - iio_get_time_ns()); 245 + iio_get_time_ns(indio_dev)); 246 246 } 247 247 248 248 if (events & AD5421_FAULT_UNDER_CURRENT) { ··· 251 251 0, 252 252 IIO_EV_TYPE_THRESH, 253 253 IIO_EV_DIR_FALLING), 254 - iio_get_time_ns()); 254 + iio_get_time_ns(indio_dev)); 255 255 } 256 256 257 257 if (events & AD5421_FAULT_TEMP_OVER_140) { ··· 260 260 0, 261 261 IIO_EV_TYPE_MAG, 262 262 IIO_EV_DIR_RISING), 263 - iio_get_time_ns()); 263 + iio_get_time_ns(indio_dev)); 264 264 } 265 265 266 266 old_fault = fault;
+1 -1
drivers/iio/dac/ad5504.c
··· 223 223 0, 224 224 IIO_EV_TYPE_THRESH, 225 225 IIO_EV_DIR_RISING), 226 - iio_get_time_ns()); 226 + iio_get_time_ns((struct iio_dev *)private)); 227 227 228 228 return IRQ_HANDLED; 229 229 }
+2 -1
drivers/iio/dummy/iio_simple_dummy_buffer.c
··· 85 85 } 86 86 } 87 87 88 - iio_push_to_buffers_with_timestamp(indio_dev, data, iio_get_time_ns()); 88 + iio_push_to_buffers_with_timestamp(indio_dev, data, 89 + iio_get_time_ns(indio_dev)); 89 90 90 91 kfree(data); 91 92
+1 -1
drivers/iio/dummy/iio_simple_dummy_events.c
··· 158 158 struct iio_dev *indio_dev = private; 159 159 struct iio_dummy_state *st = iio_priv(indio_dev); 160 160 161 - st->event_timestamp = iio_get_time_ns(); 161 + st->event_timestamp = iio_get_time_ns(indio_dev); 162 162 return IRQ_WAKE_THREAD; 163 163 } 164 164
+111 -27
drivers/iio/gyro/bmg160_core.c
··· 50 50 #define BMG160_REG_PMU_BW 0x10 51 51 #define BMG160_NO_FILTER 0 52 52 #define BMG160_DEF_BW 100 53 + #define BMG160_REG_PMU_BW_RES BIT(7) 53 54 54 55 #define BMG160_REG_INT_MAP_0 0x17 55 56 #define BMG160_INT_MAP_0_BIT_ANY BIT(1) ··· 101 100 struct iio_trigger *motion_trig; 102 101 struct mutex mutex; 103 102 s16 buffer[8]; 104 - u8 bw_bits; 105 103 u32 dps_range; 106 104 int ev_enable_state; 107 105 int slope_thres; ··· 117 117 }; 118 118 119 119 static const struct { 120 - int val; 120 + int odr; 121 + int filter; 121 122 int bw_bits; 122 - } bmg160_samp_freq_table[] = { {100, 0x07}, 123 - {200, 0x06}, 124 - {400, 0x03}, 125 - {1000, 0x02}, 126 - {2000, 0x01} }; 123 + } bmg160_samp_freq_table[] = { {100, 32, 0x07}, 124 + {200, 64, 0x06}, 125 + {100, 12, 0x05}, 126 + {200, 23, 0x04}, 127 + {400, 47, 0x03}, 128 + {1000, 116, 0x02}, 129 + {2000, 230, 0x01} }; 127 130 128 131 static const struct { 129 132 int scale; ··· 156 153 int i; 157 154 158 155 for (i = 0; i < ARRAY_SIZE(bmg160_samp_freq_table); ++i) { 159 - if (bmg160_samp_freq_table[i].val == val) 156 + if (bmg160_samp_freq_table[i].odr == val) 160 157 return bmg160_samp_freq_table[i].bw_bits; 161 158 } 162 159 ··· 179 176 return ret; 180 177 } 181 178 182 - data->bw_bits = bw_bits; 179 + return 0; 180 + } 181 + 182 + static int bmg160_get_filter(struct bmg160_data *data, int *val) 183 + { 184 + struct device *dev = regmap_get_device(data->regmap); 185 + int ret; 186 + int i; 187 + unsigned int bw_bits; 188 + 189 + ret = regmap_read(data->regmap, BMG160_REG_PMU_BW, &bw_bits); 190 + if (ret < 0) { 191 + dev_err(dev, "Error reading reg_pmu_bw\n"); 192 + return ret; 193 + } 194 + 195 + /* Ignore the readonly reserved bit. */ 196 + bw_bits &= ~BMG160_REG_PMU_BW_RES; 197 + 198 + for (i = 0; i < ARRAY_SIZE(bmg160_samp_freq_table); ++i) { 199 + if (bmg160_samp_freq_table[i].bw_bits == bw_bits) 200 + break; 201 + } 202 + 203 + *val = bmg160_samp_freq_table[i].filter; 204 + 205 + return ret ? ret : IIO_VAL_INT; 206 + } 207 + 208 + 209 + static int bmg160_set_filter(struct bmg160_data *data, int val) 210 + { 211 + struct device *dev = regmap_get_device(data->regmap); 212 + int ret; 213 + int i; 214 + 215 + for (i = 0; i < ARRAY_SIZE(bmg160_samp_freq_table); ++i) { 216 + if (bmg160_samp_freq_table[i].filter == val) 217 + break; 218 + } 219 + 220 + ret = regmap_write(data->regmap, BMG160_REG_PMU_BW, 221 + bmg160_samp_freq_table[i].bw_bits); 222 + if (ret < 0) { 223 + dev_err(dev, "Error writing reg_pmu_bw\n"); 224 + return ret; 225 + } 183 226 184 227 return 0; 185 228 } ··· 435 386 436 387 static int bmg160_get_bw(struct bmg160_data *data, int *val) 437 388 { 389 + struct device *dev = regmap_get_device(data->regmap); 438 390 int i; 391 + unsigned int bw_bits; 392 + int ret; 393 + 394 + ret = regmap_read(data->regmap, BMG160_REG_PMU_BW, &bw_bits); 395 + if (ret < 0) { 396 + dev_err(dev, "Error reading reg_pmu_bw\n"); 397 + return ret; 398 + } 399 + 400 + /* Ignore the readonly reserved bit. */ 401 + bw_bits &= ~BMG160_REG_PMU_BW_RES; 439 402 440 403 for (i = 0; i < ARRAY_SIZE(bmg160_samp_freq_table); ++i) { 441 - if (bmg160_samp_freq_table[i].bw_bits == data->bw_bits) { 442 - *val = bmg160_samp_freq_table[i].val; 404 + if (bmg160_samp_freq_table[i].bw_bits == bw_bits) { 405 + *val = bmg160_samp_freq_table[i].odr; 443 406 return IIO_VAL_INT; 444 407 } 445 408 } ··· 568 507 return IIO_VAL_INT; 569 508 } else 570 509 return -EINVAL; 510 + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 511 + return bmg160_get_filter(data, val); 571 512 case IIO_CHAN_INFO_SCALE: 572 513 *val = 0; 573 514 switch (chan->type) { ··· 626 563 return ret; 627 564 } 628 565 ret = bmg160_set_bw(data, val); 566 + if (ret < 0) { 567 + bmg160_set_power_state(data, false); 568 + mutex_unlock(&data->mutex); 569 + return ret; 570 + } 571 + ret = bmg160_set_power_state(data, false); 572 + mutex_unlock(&data->mutex); 573 + return ret; 574 + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 575 + if (val2) 576 + return -EINVAL; 577 + 578 + mutex_lock(&data->mutex); 579 + ret = bmg160_set_power_state(data, true); 580 + if (ret < 0) { 581 + bmg160_set_power_state(data, false); 582 + mutex_unlock(&data->mutex); 583 + return ret; 584 + } 585 + ret = bmg160_set_filter(data, val); 629 586 if (ret < 0) { 630 587 bmg160_set_power_state(data, false); 631 588 mutex_unlock(&data->mutex); ··· 811 728 .channel2 = IIO_MOD_##_axis, \ 812 729 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 813 730 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 814 - BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 731 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ 732 + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ 815 733 .scan_index = AXIS_##_axis, \ 816 734 .scan_type = { \ 817 735 .sign = 's', \ ··· 969 885 970 886 if (val & BMG160_ANY_MOTION_BIT_X) 971 887 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL, 972 - 0, 973 - IIO_MOD_X, 974 - IIO_EV_TYPE_ROC, 975 - dir), 976 - iio_get_time_ns()); 888 + 0, 889 + IIO_MOD_X, 890 + IIO_EV_TYPE_ROC, 891 + dir), 892 + iio_get_time_ns(indio_dev)); 977 893 if (val & BMG160_ANY_MOTION_BIT_Y) 978 894 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL, 979 - 0, 980 - IIO_MOD_Y, 981 - IIO_EV_TYPE_ROC, 982 - dir), 983 - iio_get_time_ns()); 895 + 0, 896 + IIO_MOD_Y, 897 + IIO_EV_TYPE_ROC, 898 + dir), 899 + iio_get_time_ns(indio_dev)); 984 900 if (val & BMG160_ANY_MOTION_BIT_Z) 985 901 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL, 986 - 0, 987 - IIO_MOD_Z, 988 - IIO_EV_TYPE_ROC, 989 - dir), 990 - iio_get_time_ns()); 902 + 0, 903 + IIO_MOD_Z, 904 + IIO_EV_TYPE_ROC, 905 + dir), 906 + iio_get_time_ns(indio_dev)); 991 907 992 908 ack_intr_status: 993 909 if (!data->dready_trigger_on) {
+3
drivers/iio/iio_core.h
··· 79 79 void iio_device_wakeup_eventset(struct iio_dev *indio_dev); 80 80 int iio_event_getfd(struct iio_dev *indio_dev); 81 81 82 + struct iio_event_interface; 83 + bool iio_event_enabled(const struct iio_event_interface *ev_int); 84 + 82 85 #endif
+2 -1
drivers/iio/imu/bmi160/bmi160_core.c
··· 411 411 buf[j++] = sample; 412 412 } 413 413 414 - iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns()); 414 + iio_push_to_buffers_with_timestamp(indio_dev, buf, 415 + iio_get_time_ns(indio_dev)); 415 416 done: 416 417 iio_trigger_notify_done(indio_dev->trig); 417 418 return IRQ_HANDLED;
+4 -4
drivers/iio/imu/inv_mpu6050/Kconfig
··· 13 13 select INV_MPU6050_IIO 14 14 select REGMAP_I2C 15 15 help 16 - This driver supports the Invensense MPU6050/6500/9150 motion tracking 17 - devices over I2C. 16 + This driver supports the Invensense MPU6050/6500/9150 and ICM20608 17 + motion tracking devices over I2C. 18 18 This driver can be built as a module. The module will be called 19 19 inv-mpu6050-i2c. 20 20 ··· 24 24 select INV_MPU6050_IIO 25 25 select REGMAP_SPI 26 26 help 27 - This driver supports the Invensense MPU6000/6500/9150 motion tracking 28 - devices over SPI. 27 + This driver supports the Invensense MPU6050/6500/9150 and ICM20608 28 + motion tracking devices over SPI. 29 29 This driver can be built as a module. The module will be called 30 30 inv-mpu6050-spi.
+6
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 113 113 .reg = &reg_set_6050, 114 114 .config = &chip_config_6050, 115 115 }, 116 + { 117 + .whoami = INV_ICM20608_WHOAMI_VALUE, 118 + .name = "ICM20608", 119 + .reg = &reg_set_6500, 120 + .config = &chip_config_6050, 121 + }, 116 122 }; 117 123 118 124 int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask)
+1
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
··· 170 170 {"mpu6050", INV_MPU6050}, 171 171 {"mpu6500", INV_MPU6500}, 172 172 {"mpu9150", INV_MPU9150}, 173 + {"icm20608", INV_ICM20608}, 173 174 {} 174 175 }; 175 176
+2
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
··· 70 70 INV_MPU6500, 71 71 INV_MPU6000, 72 72 INV_MPU9150, 73 + INV_ICM20608, 73 74 INV_NUM_PARTS 74 75 }; 75 76 ··· 226 225 #define INV_MPU6050_WHOAMI_VALUE 0x68 227 226 #define INV_MPU6500_WHOAMI_VALUE 0x70 228 227 #define INV_MPU9150_WHOAMI_VALUE 0x68 228 + #define INV_ICM20608_WHOAMI_VALUE 0xAF 229 229 230 230 /* scan element definition */ 231 231 enum inv_mpu6050_scan {
+1 -1
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
··· 107 107 struct inv_mpu6050_state *st = iio_priv(indio_dev); 108 108 s64 timestamp; 109 109 110 - timestamp = iio_get_time_ns(); 110 + timestamp = iio_get_time_ns(indio_dev); 111 111 kfifo_in_spinlocked(&st->timestamps, &timestamp, 1, 112 112 &st->time_stamp_lock); 113 113
+1
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
··· 82 82 {"mpu6000", INV_MPU6000}, 83 83 {"mpu6500", INV_MPU6500}, 84 84 {"mpu9150", INV_MPU9150}, 85 + {"icm20608", INV_ICM20608}, 85 86 {} 86 87 }; 87 88
+175 -4
drivers/iio/industrialio-core.c
··· 178 178 } 179 179 EXPORT_SYMBOL(iio_read_const_attr); 180 180 181 + static int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id) 182 + { 183 + int ret; 184 + const struct iio_event_interface *ev_int = indio_dev->event_interface; 185 + 186 + ret = mutex_lock_interruptible(&indio_dev->mlock); 187 + if (ret) 188 + return ret; 189 + if ((ev_int && iio_event_enabled(ev_int)) || 190 + iio_buffer_enabled(indio_dev)) { 191 + mutex_unlock(&indio_dev->mlock); 192 + return -EBUSY; 193 + } 194 + indio_dev->clock_id = clock_id; 195 + mutex_unlock(&indio_dev->mlock); 196 + 197 + return 0; 198 + } 199 + 200 + /** 201 + * iio_get_time_ns() - utility function to get a time stamp for events etc 202 + * @indio_dev: device 203 + */ 204 + s64 iio_get_time_ns(const struct iio_dev *indio_dev) 205 + { 206 + struct timespec tp; 207 + 208 + switch (iio_device_get_clock(indio_dev)) { 209 + case CLOCK_REALTIME: 210 + ktime_get_real_ts(&tp); 211 + break; 212 + case CLOCK_MONOTONIC: 213 + ktime_get_ts(&tp); 214 + break; 215 + case CLOCK_MONOTONIC_RAW: 216 + getrawmonotonic(&tp); 217 + break; 218 + case CLOCK_REALTIME_COARSE: 219 + tp = current_kernel_time(); 220 + break; 221 + case CLOCK_MONOTONIC_COARSE: 222 + tp = get_monotonic_coarse(); 223 + break; 224 + case CLOCK_BOOTTIME: 225 + get_monotonic_boottime(&tp); 226 + break; 227 + case CLOCK_TAI: 228 + timekeeping_clocktai(&tp); 229 + break; 230 + default: 231 + BUG(); 232 + } 233 + 234 + return timespec_to_ns(&tp); 235 + } 236 + EXPORT_SYMBOL(iio_get_time_ns); 237 + 238 + /** 239 + * iio_get_time_res() - utility function to get time stamp clock resolution in 240 + * nano seconds. 241 + * @indio_dev: device 242 + */ 243 + unsigned int iio_get_time_res(const struct iio_dev *indio_dev) 244 + { 245 + switch (iio_device_get_clock(indio_dev)) { 246 + case CLOCK_REALTIME: 247 + case CLOCK_MONOTONIC: 248 + case CLOCK_MONOTONIC_RAW: 249 + case CLOCK_BOOTTIME: 250 + case CLOCK_TAI: 251 + return hrtimer_resolution; 252 + case CLOCK_REALTIME_COARSE: 253 + case CLOCK_MONOTONIC_COARSE: 254 + return LOW_RES_NSEC; 255 + default: 256 + BUG(); 257 + } 258 + } 259 + EXPORT_SYMBOL(iio_get_time_res); 260 + 181 261 static int __init iio_init(void) 182 262 { 183 263 int ret; ··· 1070 990 1071 991 static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL); 1072 992 993 + static ssize_t iio_show_timestamp_clock(struct device *dev, 994 + struct device_attribute *attr, 995 + char *buf) 996 + { 997 + const struct iio_dev *indio_dev = dev_to_iio_dev(dev); 998 + const clockid_t clk = iio_device_get_clock(indio_dev); 999 + const char *name; 1000 + ssize_t sz; 1001 + 1002 + switch (clk) { 1003 + case CLOCK_REALTIME: 1004 + name = "realtime\n"; 1005 + sz = sizeof("realtime\n"); 1006 + break; 1007 + case CLOCK_MONOTONIC: 1008 + name = "monotonic\n"; 1009 + sz = sizeof("monotonic\n"); 1010 + break; 1011 + case CLOCK_MONOTONIC_RAW: 1012 + name = "monotonic_raw\n"; 1013 + sz = sizeof("monotonic_raw\n"); 1014 + break; 1015 + case CLOCK_REALTIME_COARSE: 1016 + name = "realtime_coarse\n"; 1017 + sz = sizeof("realtime_coarse\n"); 1018 + break; 1019 + case CLOCK_MONOTONIC_COARSE: 1020 + name = "monotonic_coarse\n"; 1021 + sz = sizeof("monotonic_coarse\n"); 1022 + break; 1023 + case CLOCK_BOOTTIME: 1024 + name = "boottime\n"; 1025 + sz = sizeof("boottime\n"); 1026 + break; 1027 + case CLOCK_TAI: 1028 + name = "tai\n"; 1029 + sz = sizeof("tai\n"); 1030 + break; 1031 + default: 1032 + BUG(); 1033 + } 1034 + 1035 + memcpy(buf, name, sz); 1036 + return sz; 1037 + } 1038 + 1039 + static ssize_t iio_store_timestamp_clock(struct device *dev, 1040 + struct device_attribute *attr, 1041 + const char *buf, size_t len) 1042 + { 1043 + clockid_t clk; 1044 + int ret; 1045 + 1046 + if (sysfs_streq(buf, "realtime")) 1047 + clk = CLOCK_REALTIME; 1048 + else if (sysfs_streq(buf, "monotonic")) 1049 + clk = CLOCK_MONOTONIC; 1050 + else if (sysfs_streq(buf, "monotonic_raw")) 1051 + clk = CLOCK_MONOTONIC_RAW; 1052 + else if (sysfs_streq(buf, "realtime_coarse")) 1053 + clk = CLOCK_REALTIME_COARSE; 1054 + else if (sysfs_streq(buf, "monotonic_coarse")) 1055 + clk = CLOCK_MONOTONIC_COARSE; 1056 + else if (sysfs_streq(buf, "boottime")) 1057 + clk = CLOCK_BOOTTIME; 1058 + else if (sysfs_streq(buf, "tai")) 1059 + clk = CLOCK_TAI; 1060 + else 1061 + return -EINVAL; 1062 + 1063 + ret = iio_device_set_clock(dev_to_iio_dev(dev), clk); 1064 + if (ret) 1065 + return ret; 1066 + 1067 + return len; 1068 + } 1069 + 1070 + static DEVICE_ATTR(current_timestamp_clock, S_IRUGO | S_IWUSR, 1071 + iio_show_timestamp_clock, iio_store_timestamp_clock); 1072 + 1073 1073 static int iio_device_register_sysfs(struct iio_dev *indio_dev) 1074 1074 { 1075 1075 int i, ret = 0, attrcount, attrn, attrcount_orig = 0; 1076 1076 struct iio_dev_attr *p; 1077 - struct attribute **attr; 1077 + struct attribute **attr, *clk = NULL; 1078 1078 1079 1079 /* First count elements in any existing group */ 1080 1080 if (indio_dev->info->attrs) { ··· 1169 1009 */ 1170 1010 if (indio_dev->channels) 1171 1011 for (i = 0; i < indio_dev->num_channels; i++) { 1172 - ret = iio_device_add_channel_sysfs(indio_dev, 1173 - &indio_dev 1174 - ->channels[i]); 1012 + const struct iio_chan_spec *chan = 1013 + &indio_dev->channels[i]; 1014 + 1015 + if (chan->type == IIO_TIMESTAMP) 1016 + clk = &dev_attr_current_timestamp_clock.attr; 1017 + 1018 + ret = iio_device_add_channel_sysfs(indio_dev, chan); 1175 1019 if (ret < 0) 1176 1020 goto error_clear_attrs; 1177 1021 attrcount += ret; 1178 1022 } 1179 1023 1024 + if (indio_dev->event_interface) 1025 + clk = &dev_attr_current_timestamp_clock.attr; 1026 + 1180 1027 if (indio_dev->name) 1028 + attrcount++; 1029 + if (clk) 1181 1030 attrcount++; 1182 1031 1183 1032 indio_dev->chan_attr_group.attrs = kcalloc(attrcount + 1, ··· 1208 1039 indio_dev->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr; 1209 1040 if (indio_dev->name) 1210 1041 indio_dev->chan_attr_group.attrs[attrn++] = &dev_attr_name.attr; 1042 + if (clk) 1043 + indio_dev->chan_attr_group.attrs[attrn++] = clk; 1211 1044 1212 1045 indio_dev->groups[indio_dev->groupcounter++] = 1213 1046 &indio_dev->chan_attr_group;
+16 -3
drivers/iio/industrialio-event.c
··· 44 44 struct mutex read_lock; 45 45 }; 46 46 47 + bool iio_event_enabled(const struct iio_event_interface *ev_int) 48 + { 49 + return !!test_bit(IIO_BUSY_BIT_POS, &ev_int->flags); 50 + } 51 + 47 52 /** 48 53 * iio_push_event() - try to add event to the list for userspace reading 49 54 * @indio_dev: IIO device structure ··· 65 60 int copied; 66 61 67 62 /* Does anyone care? */ 68 - if (test_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) { 63 + if (iio_event_enabled(ev_int)) { 69 64 70 65 ev.id = ev_code; 71 66 ev.timestamp = timestamp; ··· 185 180 if (ev_int == NULL) 186 181 return -ENODEV; 187 182 188 - if (test_and_set_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) 189 - return -EBUSY; 183 + fd = mutex_lock_interruptible(&indio_dev->mlock); 184 + if (fd) 185 + return fd; 186 + 187 + if (test_and_set_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) { 188 + fd = -EBUSY; 189 + goto unlock; 190 + } 190 191 191 192 iio_device_get(indio_dev); 192 193 ··· 205 194 kfifo_reset_out(&ev_int->det_events); 206 195 } 207 196 197 + unlock: 198 + mutex_unlock(&indio_dev->mlock); 208 199 return fd; 209 200 } 210 201
+1 -1
drivers/iio/industrialio-trigger.c
··· 289 289 irqreturn_t iio_pollfunc_store_time(int irq, void *p) 290 290 { 291 291 struct iio_poll_func *pf = p; 292 - pf->timestamp = iio_get_time_ns(); 292 + pf->timestamp = iio_get_time_ns(pf->indio_dev); 293 293 return IRQ_WAKE_THREAD; 294 294 } 295 295 EXPORT_SYMBOL(iio_pollfunc_store_time);
+1 -1
drivers/iio/light/acpi-als.c
··· 118 118 struct iio_dev *indio_dev = acpi_driver_data(device); 119 119 struct acpi_als *als = iio_priv(indio_dev); 120 120 s32 *buffer = als->evt_buffer; 121 - s64 time_ns = iio_get_time_ns(); 121 + s64 time_ns = iio_get_time_ns(indio_dev); 122 122 s32 val; 123 123 int ret; 124 124
+1 -1
drivers/iio/light/adjd_s311.c
··· 118 118 struct iio_poll_func *pf = p; 119 119 struct iio_dev *indio_dev = pf->indio_dev; 120 120 struct adjd_s311_data *data = iio_priv(indio_dev); 121 - s64 time_ns = iio_get_time_ns(); 121 + s64 time_ns = iio_get_time_ns(indio_dev); 122 122 int i, j = 0; 123 123 124 124 int ret = adjd_s311_req_data(indio_dev);
+1 -1
drivers/iio/light/apds9300.c
··· 396 396 IIO_UNMOD_EVENT_CODE(IIO_INTENSITY, 0, 397 397 IIO_EV_TYPE_THRESH, 398 398 IIO_EV_DIR_EITHER), 399 - iio_get_time_ns()); 399 + iio_get_time_ns(dev_info)); 400 400 401 401 apds9300_clear_intr(data); 402 402
+2 -2
drivers/iio/light/apds9960.c
··· 807 807 IIO_UNMOD_EVENT_CODE(IIO_INTENSITY, 0, 808 808 IIO_EV_TYPE_THRESH, 809 809 IIO_EV_DIR_EITHER), 810 - iio_get_time_ns()); 810 + iio_get_time_ns(indio_dev)); 811 811 regmap_write(data->regmap, APDS9960_REG_CICLEAR, 1); 812 812 } 813 813 ··· 816 816 IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0, 817 817 IIO_EV_TYPE_THRESH, 818 818 IIO_EV_DIR_EITHER), 819 - iio_get_time_ns()); 819 + iio_get_time_ns(indio_dev)); 820 820 regmap_write(data->regmap, APDS9960_REG_PICLEAR, 1); 821 821 } 822 822
+1 -1
drivers/iio/light/cm36651.c
··· 268 268 CM36651_CMD_READ_RAW_PROXIMITY, 269 269 IIO_EV_TYPE_THRESH, ev_dir); 270 270 271 - iio_push_event(indio_dev, ev_code, iio_get_time_ns()); 271 + iio_push_event(indio_dev, ev_code, iio_get_time_ns(indio_dev)); 272 272 273 273 return IRQ_HANDLED; 274 274 }
+4 -4
drivers/iio/light/gp2ap020a00f.c
··· 851 851 GP2AP020A00F_SCAN_MODE_PROXIMITY, 852 852 IIO_EV_TYPE_ROC, 853 853 IIO_EV_DIR_RISING), 854 - iio_get_time_ns()); 854 + iio_get_time_ns(indio_dev)); 855 855 } else { 856 856 iio_push_event(indio_dev, 857 857 IIO_UNMOD_EVENT_CODE( ··· 859 859 GP2AP020A00F_SCAN_MODE_PROXIMITY, 860 860 IIO_EV_TYPE_ROC, 861 861 IIO_EV_DIR_FALLING), 862 - iio_get_time_ns()); 862 + iio_get_time_ns(indio_dev)); 863 863 } 864 864 } 865 865 ··· 925 925 IIO_MOD_LIGHT_CLEAR, 926 926 IIO_EV_TYPE_THRESH, 927 927 IIO_EV_DIR_RISING), 928 - iio_get_time_ns()); 928 + iio_get_time_ns(indio_dev)); 929 929 } 930 930 931 931 if (test_bit(GP2AP020A00F_FLAG_ALS_FALLING_EV, &priv->flags)) { ··· 939 939 IIO_MOD_LIGHT_CLEAR, 940 940 IIO_EV_TYPE_THRESH, 941 941 IIO_EV_DIR_FALLING), 942 - iio_get_time_ns()); 942 + iio_get_time_ns(indio_dev)); 943 943 } 944 944 } 945 945
+8 -5
drivers/iio/light/isl29125.c
··· 44 44 #define ISL29125_MODE_B 0x3 45 45 #define ISL29125_MODE_RGB 0x5 46 46 47 + #define ISL29125_SENSING_RANGE_0 5722 /* 375 lux full range */ 48 + #define ISL29125_SENSING_RANGE_1 152590 /* 10k lux full range */ 49 + 47 50 #define ISL29125_MODE_RANGE BIT(3) 48 51 49 52 #define ISL29125_STATUS_CONV BIT(1) ··· 142 139 case IIO_CHAN_INFO_SCALE: 143 140 *val = 0; 144 141 if (data->conf1 & ISL29125_MODE_RANGE) 145 - *val2 = 152590; /* 10k lux full range */ 142 + *val2 = ISL29125_SENSING_RANGE_1; /*10k lux full range*/ 146 143 else 147 - *val2 = 5722; /* 375 lux full range */ 144 + *val2 = ISL29125_SENSING_RANGE_0; /*375 lux full range*/ 148 145 return IIO_VAL_INT_PLUS_MICRO; 149 146 } 150 147 return -EINVAL; ··· 160 157 case IIO_CHAN_INFO_SCALE: 161 158 if (val != 0) 162 159 return -EINVAL; 163 - if (val2 == 152590) 160 + if (val2 == ISL29125_SENSING_RANGE_1) 164 161 data->conf1 |= ISL29125_MODE_RANGE; 165 - else if (val2 == 5722) 162 + else if (val2 == ISL29125_SENSING_RANGE_0) 166 163 data->conf1 &= ~ISL29125_MODE_RANGE; 167 164 else 168 165 return -EINVAL; ··· 191 188 } 192 189 193 190 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 194 - iio_get_time_ns()); 191 + iio_get_time_ns(indio_dev)); 195 192 196 193 done: 197 194 iio_trigger_notify_done(indio_dev->trig);
+1 -1
drivers/iio/light/lm3533-als.c
··· 267 267 0, 268 268 IIO_EV_TYPE_THRESH, 269 269 IIO_EV_DIR_EITHER), 270 - iio_get_time_ns()); 270 + iio_get_time_ns(indio_dev)); 271 271 out: 272 272 return IRQ_HANDLED; 273 273 }
+4 -3
drivers/iio/light/ltr501.c
··· 1256 1256 buf[j++] = psdata & LTR501_PS_DATA_MASK; 1257 1257 } 1258 1258 1259 - iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns()); 1259 + iio_push_to_buffers_with_timestamp(indio_dev, buf, 1260 + iio_get_time_ns(indio_dev)); 1260 1261 1261 1262 done: 1262 1263 iio_trigger_notify_done(indio_dev->trig); ··· 1283 1282 IIO_UNMOD_EVENT_CODE(IIO_INTENSITY, 0, 1284 1283 IIO_EV_TYPE_THRESH, 1285 1284 IIO_EV_DIR_EITHER), 1286 - iio_get_time_ns()); 1285 + iio_get_time_ns(indio_dev)); 1287 1286 1288 1287 if (status & LTR501_STATUS_PS_INTR) 1289 1288 iio_push_event(indio_dev, 1290 1289 IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0, 1291 1290 IIO_EV_TYPE_THRESH, 1292 1291 IIO_EV_DIR_EITHER), 1293 - iio_get_time_ns()); 1292 + iio_get_time_ns(indio_dev)); 1294 1293 1295 1294 return IRQ_HANDLED; 1296 1295 }
+2 -1
drivers/iio/light/max44000.c
··· 511 511 } 512 512 mutex_unlock(&data->lock); 513 513 514 - iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns()); 514 + iio_push_to_buffers_with_timestamp(indio_dev, buf, 515 + iio_get_time_ns(indio_dev)); 515 516 iio_trigger_notify_done(indio_dev->trig); 516 517 return IRQ_HANDLED; 517 518
+2 -2
drivers/iio/light/opt3001.c
··· 713 713 IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0, 714 714 IIO_EV_TYPE_THRESH, 715 715 IIO_EV_DIR_RISING), 716 - iio_get_time_ns()); 716 + iio_get_time_ns(iio)); 717 717 if (ret & OPT3001_CONFIGURATION_FL) 718 718 iio_push_event(iio, 719 719 IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0, 720 720 IIO_EV_TYPE_THRESH, 721 721 IIO_EV_DIR_FALLING), 722 - iio_get_time_ns()); 722 + iio_get_time_ns(iio)); 723 723 } else if (ret & OPT3001_CONFIGURATION_CRF) { 724 724 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_RESULT); 725 725 if (ret < 0) {
+1 -1
drivers/iio/light/stk3310.c
··· 528 528 struct iio_dev *indio_dev = private; 529 529 struct stk3310_data *data = iio_priv(indio_dev); 530 530 531 - data->timestamp = iio_get_time_ns(); 531 + data->timestamp = iio_get_time_ns(indio_dev); 532 532 533 533 return IRQ_WAKE_THREAD; 534 534 }
+1 -1
drivers/iio/light/tcs3414.c
··· 216 216 } 217 217 218 218 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 219 - iio_get_time_ns()); 219 + iio_get_time_ns(indio_dev)); 220 220 221 221 done: 222 222 iio_trigger_notify_done(indio_dev->trig);
+1 -1
drivers/iio/light/tcs3472.c
··· 202 202 } 203 203 204 204 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 205 - iio_get_time_ns()); 205 + iio_get_time_ns(indio_dev)); 206 206 207 207 done: 208 208 iio_trigger_notify_done(indio_dev->trig);
+1 -1
drivers/iio/light/tsl2563.c
··· 630 630 0, 631 631 IIO_EV_TYPE_THRESH, 632 632 IIO_EV_DIR_EITHER), 633 - iio_get_time_ns()); 633 + iio_get_time_ns(dev_info)); 634 634 635 635 /* clear the interrupt and push the event */ 636 636 i2c_smbus_write_byte(chip->client, TSL2563_CMD | TSL2563_CLEARINT);
+1 -1
drivers/iio/light/us5182d.c
··· 833 833 dir = ret & US5182D_CFG0_PROX ? IIO_EV_DIR_RISING : IIO_EV_DIR_FALLING; 834 834 ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 1, IIO_EV_TYPE_THRESH, dir); 835 835 836 - iio_push_event(indio_dev, ev, iio_get_time_ns()); 836 + iio_push_event(indio_dev, ev, iio_get_time_ns(indio_dev)); 837 837 838 838 ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, 839 839 ret & ~US5182D_CFG0_PX_IRQ);
+110 -24
drivers/iio/magnetometer/ak8975.c
··· 33 33 #include <linux/of_gpio.h> 34 34 #include <linux/acpi.h> 35 35 #include <linux/regulator/consumer.h> 36 + #include <linux/pm_runtime.h> 36 37 37 38 #include <linux/iio/iio.h> 38 39 #include <linux/iio/sysfs.h> ··· 380 379 u8 cntl_cache; 381 380 struct iio_mount_matrix orientation; 382 381 struct regulator *vdd; 382 + struct regulator *vid; 383 383 }; 384 384 385 385 /* Enable attached power regulator if any. */ 386 - static int ak8975_power_on(struct i2c_client *client) 386 + static int ak8975_power_on(const struct ak8975_data *data) 387 387 { 388 - const struct iio_dev *indio_dev = i2c_get_clientdata(client); 389 - struct ak8975_data *data = iio_priv(indio_dev); 390 388 int ret; 391 389 392 - data->vdd = devm_regulator_get(&client->dev, "vdd"); 393 - if (IS_ERR_OR_NULL(data->vdd)) { 394 - ret = PTR_ERR(data->vdd); 395 - if (ret == -ENODEV) 396 - ret = 0; 397 - } else { 398 - ret = regulator_enable(data->vdd); 390 + ret = regulator_enable(data->vdd); 391 + if (ret) { 392 + dev_warn(&data->client->dev, 393 + "Failed to enable specified Vdd supply\n"); 394 + return ret; 399 395 } 400 - 401 - if (ret) 402 - dev_err(&client->dev, "failed to enable Vdd supply: %d\n", ret); 403 - return ret; 396 + ret = regulator_enable(data->vid); 397 + if (ret) { 398 + dev_warn(&data->client->dev, 399 + "Failed to enable specified Vid supply\n"); 400 + return ret; 401 + } 402 + /* 403 + * According to the datasheet the power supply rise time i 200us 404 + * and the minimum wait time before mode setting is 100us, in 405 + * total 300 us. Add some margin and say minimum 500us here. 406 + */ 407 + usleep_range(500, 1000); 408 + return 0; 404 409 } 405 410 406 411 /* Disable attached power regulator if any. */ 407 - static void ak8975_power_off(const struct i2c_client *client) 412 + static void ak8975_power_off(const struct ak8975_data *data) 408 413 { 409 - const struct iio_dev *indio_dev = i2c_get_clientdata(client); 410 - const struct ak8975_data *data = iio_priv(indio_dev); 411 - 412 - if (!IS_ERR_OR_NULL(data->vdd)) 413 - regulator_disable(data->vdd); 414 + regulator_disable(data->vid); 415 + regulator_disable(data->vdd); 414 416 } 415 417 416 418 /* ··· 693 689 u16 buff; 694 690 int ret; 695 691 692 + pm_runtime_get_sync(&data->client->dev); 693 + 696 694 mutex_lock(&data->lock); 697 695 698 696 ret = ak8975_start_read_axis(data, client); ··· 708 702 goto exit; 709 703 710 704 mutex_unlock(&data->lock); 705 + 706 + pm_runtime_mark_last_busy(&data->client->dev); 707 + pm_runtime_put_autosuspend(&data->client->dev); 711 708 712 709 /* Swap bytes and convert to valid range. */ 713 710 buff = le16_to_cpu(buff); ··· 838 829 buff[1] = clamp_t(s16, le16_to_cpu(buff[1]), -def->range, def->range); 839 830 buff[2] = clamp_t(s16, le16_to_cpu(buff[2]), -def->range, def->range); 840 831 841 - iio_push_to_buffers_with_timestamp(indio_dev, buff, iio_get_time_ns()); 832 + iio_push_to_buffers_with_timestamp(indio_dev, buff, 833 + iio_get_time_ns(indio_dev)); 842 834 return; 843 835 844 836 unlock: ··· 933 923 934 924 data->def = &ak_def_array[chipset]; 935 925 936 - err = ak8975_power_on(client); 926 + /* Fetch the regulators */ 927 + data->vdd = devm_regulator_get(&client->dev, "vdd"); 928 + if (IS_ERR(data->vdd)) 929 + return PTR_ERR(data->vdd); 930 + data->vid = devm_regulator_get(&client->dev, "vid"); 931 + if (IS_ERR(data->vid)) 932 + return PTR_ERR(data->vid); 933 + 934 + err = ak8975_power_on(data); 937 935 if (err) 938 936 return err; 939 937 ··· 981 963 goto cleanup_buffer; 982 964 } 983 965 966 + /* Enable runtime PM */ 967 + pm_runtime_get_noresume(&client->dev); 968 + pm_runtime_set_active(&client->dev); 969 + pm_runtime_enable(&client->dev); 970 + /* 971 + * The device comes online in 500us, so add two orders of magnitude 972 + * of delay before autosuspending: 50 ms. 973 + */ 974 + pm_runtime_set_autosuspend_delay(&client->dev, 50); 975 + pm_runtime_use_autosuspend(&client->dev); 976 + pm_runtime_put(&client->dev); 977 + 984 978 return 0; 985 979 986 980 cleanup_buffer: 987 981 iio_triggered_buffer_cleanup(indio_dev); 988 982 power_off: 989 - ak8975_power_off(client); 983 + ak8975_power_off(data); 990 984 return err; 991 985 } 992 986 993 987 static int ak8975_remove(struct i2c_client *client) 994 988 { 995 989 struct iio_dev *indio_dev = i2c_get_clientdata(client); 990 + struct ak8975_data *data = iio_priv(indio_dev); 996 991 992 + pm_runtime_get_sync(&client->dev); 993 + pm_runtime_put_noidle(&client->dev); 994 + pm_runtime_disable(&client->dev); 997 995 iio_device_unregister(indio_dev); 998 996 iio_triggered_buffer_cleanup(indio_dev); 999 - ak8975_power_off(client); 997 + ak8975_set_mode(data, POWER_DOWN); 998 + ak8975_power_off(data); 1000 999 1001 1000 return 0; 1002 1001 } 1002 + 1003 + #ifdef CONFIG_PM 1004 + static int ak8975_runtime_suspend(struct device *dev) 1005 + { 1006 + struct i2c_client *client = to_i2c_client(dev); 1007 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 1008 + struct ak8975_data *data = iio_priv(indio_dev); 1009 + int ret; 1010 + 1011 + /* Set the device in power down if it wasn't already */ 1012 + ret = ak8975_set_mode(data, POWER_DOWN); 1013 + if (ret < 0) { 1014 + dev_err(&client->dev, "Error in setting power-down mode\n"); 1015 + return ret; 1016 + } 1017 + /* Next cut the regulators */ 1018 + ak8975_power_off(data); 1019 + 1020 + return 0; 1021 + } 1022 + 1023 + static int ak8975_runtime_resume(struct device *dev) 1024 + { 1025 + struct i2c_client *client = to_i2c_client(dev); 1026 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 1027 + struct ak8975_data *data = iio_priv(indio_dev); 1028 + int ret; 1029 + 1030 + /* Take up the regulators */ 1031 + ak8975_power_on(data); 1032 + /* 1033 + * We come up in powered down mode, the reading routines will 1034 + * put us in the mode to read values later. 1035 + */ 1036 + ret = ak8975_set_mode(data, POWER_DOWN); 1037 + if (ret < 0) { 1038 + dev_err(&client->dev, "Error in setting power-down mode\n"); 1039 + return ret; 1040 + } 1041 + 1042 + return 0; 1043 + } 1044 + #endif /* CONFIG_PM */ 1045 + 1046 + static const struct dev_pm_ops ak8975_dev_pm_ops = { 1047 + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 1048 + pm_runtime_force_resume) 1049 + SET_RUNTIME_PM_OPS(ak8975_runtime_suspend, 1050 + ak8975_runtime_resume, NULL) 1051 + }; 1003 1052 1004 1053 static const struct i2c_device_id ak8975_id[] = { 1005 1054 {"ak8975", AK8975}, ··· 1095 1010 static struct i2c_driver ak8975_driver = { 1096 1011 .driver = { 1097 1012 .name = "ak8975", 1013 + .pm = &ak8975_dev_pm_ops, 1098 1014 .of_match_table = of_match_ptr(ak8975_of_match), 1099 1015 .acpi_match_table = ACPI_PTR(ak_acpi_match), 1100 1016 },
+1 -1
drivers/iio/magnetometer/hmc5843_core.c
··· 451 451 goto done; 452 452 453 453 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 454 - iio_get_time_ns()); 454 + iio_get_time_ns(indio_dev)); 455 455 456 456 done: 457 457 iio_trigger_notify_done(indio_dev->trig);
+1 -1
drivers/iio/magnetometer/mag3110.c
··· 261 261 } 262 262 263 263 iio_push_to_buffers_with_timestamp(indio_dev, buffer, 264 - iio_get_time_ns()); 264 + iio_get_time_ns(indio_dev)); 265 265 266 266 done: 267 267 iio_trigger_notify_done(indio_dev->trig);
+7 -5
drivers/iio/potentiometer/Kconfig
··· 10 10 depends on I2C 11 11 help 12 12 Say yes here to build support for the Maxim Integrated DS1803 13 - digital potentiomenter chip. 13 + digital potentiometer chip. 14 14 15 15 To compile this driver as a module, choose M here: the 16 16 module will be called ds1803. ··· 39 39 MCP4241, MCP4242, 40 40 MCP4251, MCP4252, 41 41 MCP4261, MCP4262, 42 - digital potentiomenter chips. 42 + digital potentiometer chips. 43 43 44 44 To compile this driver as a module, choose M here: the 45 45 module will be called mcp4131. ··· 49 49 depends on I2C 50 50 help 51 51 Say yes here to build support for the Microchip 52 - MCP4531, MCP4532, MCP4551, MCP4552, 53 - MCP4631, MCP4632, MCP4651, MCP4652 54 - digital potentiomenter chips. 52 + MCP4531, MCP4532, MCP4541, MCP4542, 53 + MCP4551, MCP4552, MCP4561, MCP4562, 54 + MCP4631, MCP4632, MCP4641, MCP4642, 55 + MCP4651, MCP4652, MCP4661, MCP4662 56 + digital potentiometer chips. 55 57 56 58 To compile this driver as a module, choose M here: the 57 59 module will be called mcp4531.
+158 -1
drivers/iio/potentiometer/mcp4531.c
··· 8 8 * DEVID #Wipers #Positions Resistor Opts (kOhm) i2c address 9 9 * mcp4531 1 129 5, 10, 50, 100 010111x 10 10 * mcp4532 1 129 5, 10, 50, 100 01011xx 11 + * mcp4541 1 129 5, 10, 50, 100 010111x 12 + * mcp4542 1 129 5, 10, 50, 100 01011xx 11 13 * mcp4551 1 257 5, 10, 50, 100 010111x 12 14 * mcp4552 1 257 5, 10, 50, 100 01011xx 15 + * mcp4561 1 257 5, 10, 50, 100 010111x 16 + * mcp4562 1 257 5, 10, 50, 100 01011xx 13 17 * mcp4631 2 129 5, 10, 50, 100 0101xxx 14 18 * mcp4632 2 129 5, 10, 50, 100 01011xx 19 + * mcp4641 2 129 5, 10, 50, 100 0101xxx 20 + * mcp4642 2 129 5, 10, 50, 100 01011xx 15 21 * mcp4651 2 257 5, 10, 50, 100 0101xxx 16 22 * mcp4652 2 257 5, 10, 50, 100 01011xx 23 + * mcp4661 2 257 5, 10, 50, 100 0101xxx 24 + * mcp4662 2 257 5, 10, 50, 100 01011xx 17 25 * 18 26 * This program is free software; you can redistribute it and/or modify it 19 27 * under the terms of the GNU General Public License version 2 as published by ··· 31 23 #include <linux/module.h> 32 24 #include <linux/i2c.h> 33 25 #include <linux/err.h> 26 + #include <linux/of.h> 27 + #include <linux/of_device.h> 34 28 35 29 #include <linux/iio/iio.h> 36 30 ··· 47 37 MCP453x_103, 48 38 MCP453x_503, 49 39 MCP453x_104, 40 + MCP454x_502, 41 + MCP454x_103, 42 + MCP454x_503, 43 + MCP454x_104, 50 44 MCP455x_502, 51 45 MCP455x_103, 52 46 MCP455x_503, 53 47 MCP455x_104, 48 + MCP456x_502, 49 + MCP456x_103, 50 + MCP456x_503, 51 + MCP456x_104, 54 52 MCP463x_502, 55 53 MCP463x_103, 56 54 MCP463x_503, 57 55 MCP463x_104, 56 + MCP464x_502, 57 + MCP464x_103, 58 + MCP464x_503, 59 + MCP464x_104, 58 60 MCP465x_502, 59 61 MCP465x_103, 60 62 MCP465x_503, 61 63 MCP465x_104, 64 + MCP466x_502, 65 + MCP466x_103, 66 + MCP466x_503, 67 + MCP466x_104, 62 68 }; 63 69 64 70 static const struct mcp4531_cfg mcp4531_cfg[] = { ··· 82 56 [MCP453x_103] = { .wipers = 1, .max_pos = 128, .kohms = 10, }, 83 57 [MCP453x_503] = { .wipers = 1, .max_pos = 128, .kohms = 50, }, 84 58 [MCP453x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, }, 59 + [MCP454x_502] = { .wipers = 1, .max_pos = 128, .kohms = 5, }, 60 + [MCP454x_103] = { .wipers = 1, .max_pos = 128, .kohms = 10, }, 61 + [MCP454x_503] = { .wipers = 1, .max_pos = 128, .kohms = 50, }, 62 + [MCP454x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, }, 85 63 [MCP455x_502] = { .wipers = 1, .max_pos = 256, .kohms = 5, }, 86 64 [MCP455x_103] = { .wipers = 1, .max_pos = 256, .kohms = 10, }, 87 65 [MCP455x_503] = { .wipers = 1, .max_pos = 256, .kohms = 50, }, 88 66 [MCP455x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, }, 67 + [MCP456x_502] = { .wipers = 1, .max_pos = 256, .kohms = 5, }, 68 + [MCP456x_103] = { .wipers = 1, .max_pos = 256, .kohms = 10, }, 69 + [MCP456x_503] = { .wipers = 1, .max_pos = 256, .kohms = 50, }, 70 + [MCP456x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, }, 89 71 [MCP463x_502] = { .wipers = 2, .max_pos = 128, .kohms = 5, }, 90 72 [MCP463x_103] = { .wipers = 2, .max_pos = 128, .kohms = 10, }, 91 73 [MCP463x_503] = { .wipers = 2, .max_pos = 128, .kohms = 50, }, 92 74 [MCP463x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, }, 75 + [MCP464x_502] = { .wipers = 2, .max_pos = 128, .kohms = 5, }, 76 + [MCP464x_103] = { .wipers = 2, .max_pos = 128, .kohms = 10, }, 77 + [MCP464x_503] = { .wipers = 2, .max_pos = 128, .kohms = 50, }, 78 + [MCP464x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, }, 93 79 [MCP465x_502] = { .wipers = 2, .max_pos = 256, .kohms = 5, }, 94 80 [MCP465x_103] = { .wipers = 2, .max_pos = 256, .kohms = 10, }, 95 81 [MCP465x_503] = { .wipers = 2, .max_pos = 256, .kohms = 50, }, 96 82 [MCP465x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, }, 83 + [MCP466x_502] = { .wipers = 2, .max_pos = 256, .kohms = 5, }, 84 + [MCP466x_103] = { .wipers = 2, .max_pos = 256, .kohms = 10, }, 85 + [MCP466x_503] = { .wipers = 2, .max_pos = 256, .kohms = 50, }, 86 + [MCP466x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, }, 97 87 }; 98 88 99 89 #define MCP4531_WRITE (0 << 2) ··· 190 148 .driver_module = THIS_MODULE, 191 149 }; 192 150 151 + #ifdef CONFIG_OF 152 + 153 + #define MCP4531_COMPATIBLE(of_compatible, cfg) { \ 154 + .compatible = of_compatible, \ 155 + .data = &mcp4531_cfg[cfg], \ 156 + } 157 + 158 + static const struct of_device_id mcp4531_of_match[] = { 159 + MCP4531_COMPATIBLE("microchip,mcp4531-502", MCP453x_502), 160 + MCP4531_COMPATIBLE("microchip,mcp4531-103", MCP453x_103), 161 + MCP4531_COMPATIBLE("microchip,mcp4531-503", MCP453x_503), 162 + MCP4531_COMPATIBLE("microchip,mcp4531-104", MCP453x_104), 163 + MCP4531_COMPATIBLE("microchip,mcp4532-502", MCP453x_502), 164 + MCP4531_COMPATIBLE("microchip,mcp4532-103", MCP453x_103), 165 + MCP4531_COMPATIBLE("microchip,mcp4532-503", MCP453x_503), 166 + MCP4531_COMPATIBLE("microchip,mcp4532-104", MCP453x_104), 167 + MCP4531_COMPATIBLE("microchip,mcp4541-502", MCP454x_502), 168 + MCP4531_COMPATIBLE("microchip,mcp4541-103", MCP454x_103), 169 + MCP4531_COMPATIBLE("microchip,mcp4541-503", MCP454x_503), 170 + MCP4531_COMPATIBLE("microchip,mcp4541-104", MCP454x_104), 171 + MCP4531_COMPATIBLE("microchip,mcp4542-502", MCP454x_502), 172 + MCP4531_COMPATIBLE("microchip,mcp4542-103", MCP454x_103), 173 + MCP4531_COMPATIBLE("microchip,mcp4542-503", MCP454x_503), 174 + MCP4531_COMPATIBLE("microchip,mcp4542-104", MCP454x_104), 175 + MCP4531_COMPATIBLE("microchip,mcp4551-502", MCP455x_502), 176 + MCP4531_COMPATIBLE("microchip,mcp4551-103", MCP455x_103), 177 + MCP4531_COMPATIBLE("microchip,mcp4551-503", MCP455x_503), 178 + MCP4531_COMPATIBLE("microchip,mcp4551-104", MCP455x_104), 179 + MCP4531_COMPATIBLE("microchip,mcp4552-502", MCP455x_502), 180 + MCP4531_COMPATIBLE("microchip,mcp4552-103", MCP455x_103), 181 + MCP4531_COMPATIBLE("microchip,mcp4552-503", MCP455x_503), 182 + MCP4531_COMPATIBLE("microchip,mcp4552-104", MCP455x_104), 183 + MCP4531_COMPATIBLE("microchip,mcp4561-502", MCP456x_502), 184 + MCP4531_COMPATIBLE("microchip,mcp4561-103", MCP456x_103), 185 + MCP4531_COMPATIBLE("microchip,mcp4561-503", MCP456x_503), 186 + MCP4531_COMPATIBLE("microchip,mcp4561-104", MCP456x_104), 187 + MCP4531_COMPATIBLE("microchip,mcp4562-502", MCP456x_502), 188 + MCP4531_COMPATIBLE("microchip,mcp4562-103", MCP456x_103), 189 + MCP4531_COMPATIBLE("microchip,mcp4562-503", MCP456x_503), 190 + MCP4531_COMPATIBLE("microchip,mcp4562-104", MCP456x_104), 191 + MCP4531_COMPATIBLE("microchip,mcp4631-502", MCP463x_502), 192 + MCP4531_COMPATIBLE("microchip,mcp4631-103", MCP463x_103), 193 + MCP4531_COMPATIBLE("microchip,mcp4631-503", MCP463x_503), 194 + MCP4531_COMPATIBLE("microchip,mcp4631-104", MCP463x_104), 195 + MCP4531_COMPATIBLE("microchip,mcp4632-502", MCP463x_502), 196 + MCP4531_COMPATIBLE("microchip,mcp4632-103", MCP463x_103), 197 + MCP4531_COMPATIBLE("microchip,mcp4632-503", MCP463x_503), 198 + MCP4531_COMPATIBLE("microchip,mcp4632-104", MCP463x_104), 199 + MCP4531_COMPATIBLE("microchip,mcp4641-502", MCP464x_502), 200 + MCP4531_COMPATIBLE("microchip,mcp4641-103", MCP464x_103), 201 + MCP4531_COMPATIBLE("microchip,mcp4641-503", MCP464x_503), 202 + MCP4531_COMPATIBLE("microchip,mcp4641-104", MCP464x_104), 203 + MCP4531_COMPATIBLE("microchip,mcp4642-502", MCP464x_502), 204 + MCP4531_COMPATIBLE("microchip,mcp4642-103", MCP464x_103), 205 + MCP4531_COMPATIBLE("microchip,mcp4642-503", MCP464x_503), 206 + MCP4531_COMPATIBLE("microchip,mcp4642-104", MCP464x_104), 207 + MCP4531_COMPATIBLE("microchip,mcp4651-502", MCP465x_502), 208 + MCP4531_COMPATIBLE("microchip,mcp4651-103", MCP465x_103), 209 + MCP4531_COMPATIBLE("microchip,mcp4651-503", MCP465x_503), 210 + MCP4531_COMPATIBLE("microchip,mcp4651-104", MCP465x_104), 211 + MCP4531_COMPATIBLE("microchip,mcp4652-502", MCP465x_502), 212 + MCP4531_COMPATIBLE("microchip,mcp4652-103", MCP465x_103), 213 + MCP4531_COMPATIBLE("microchip,mcp4652-503", MCP465x_503), 214 + MCP4531_COMPATIBLE("microchip,mcp4652-104", MCP465x_104), 215 + MCP4531_COMPATIBLE("microchip,mcp4661-502", MCP466x_502), 216 + MCP4531_COMPATIBLE("microchip,mcp4661-103", MCP466x_103), 217 + MCP4531_COMPATIBLE("microchip,mcp4661-503", MCP466x_503), 218 + MCP4531_COMPATIBLE("microchip,mcp4661-104", MCP466x_104), 219 + MCP4531_COMPATIBLE("microchip,mcp4662-502", MCP466x_502), 220 + MCP4531_COMPATIBLE("microchip,mcp4662-103", MCP466x_103), 221 + MCP4531_COMPATIBLE("microchip,mcp4662-503", MCP466x_503), 222 + MCP4531_COMPATIBLE("microchip,mcp4662-104", MCP466x_104), 223 + { /* sentinel */ } 224 + }; 225 + #endif 226 + 193 227 static int mcp4531_probe(struct i2c_client *client, 194 228 const struct i2c_device_id *id) 195 229 { 196 230 struct device *dev = &client->dev; 197 231 struct mcp4531_data *data; 198 232 struct iio_dev *indio_dev; 233 + const struct of_device_id *match; 199 234 200 235 if (!i2c_check_functionality(client->adapter, 201 236 I2C_FUNC_SMBUS_WORD_DATA)) { ··· 286 167 data = iio_priv(indio_dev); 287 168 i2c_set_clientdata(client, indio_dev); 288 169 data->client = client; 289 - data->cfg = &mcp4531_cfg[id->driver_data]; 170 + 171 + match = of_match_device(of_match_ptr(mcp4531_of_match), dev); 172 + if (match) 173 + data->cfg = of_device_get_match_data(dev); 174 + else 175 + data->cfg = &mcp4531_cfg[id->driver_data]; 290 176 291 177 indio_dev->dev.parent = dev; 292 178 indio_dev->info = &mcp4531_info; ··· 311 187 { "mcp4532-103", MCP453x_103 }, 312 188 { "mcp4532-503", MCP453x_503 }, 313 189 { "mcp4532-104", MCP453x_104 }, 190 + { "mcp4541-502", MCP454x_502 }, 191 + { "mcp4541-103", MCP454x_103 }, 192 + { "mcp4541-503", MCP454x_503 }, 193 + { "mcp4541-104", MCP454x_104 }, 194 + { "mcp4542-502", MCP454x_502 }, 195 + { "mcp4542-103", MCP454x_103 }, 196 + { "mcp4542-503", MCP454x_503 }, 197 + { "mcp4542-104", MCP454x_104 }, 314 198 { "mcp4551-502", MCP455x_502 }, 315 199 { "mcp4551-103", MCP455x_103 }, 316 200 { "mcp4551-503", MCP455x_503 }, ··· 327 195 { "mcp4552-103", MCP455x_103 }, 328 196 { "mcp4552-503", MCP455x_503 }, 329 197 { "mcp4552-104", MCP455x_104 }, 198 + { "mcp4561-502", MCP456x_502 }, 199 + { "mcp4561-103", MCP456x_103 }, 200 + { "mcp4561-503", MCP456x_503 }, 201 + { "mcp4561-104", MCP456x_104 }, 202 + { "mcp4562-502", MCP456x_502 }, 203 + { "mcp4562-103", MCP456x_103 }, 204 + { "mcp4562-503", MCP456x_503 }, 205 + { "mcp4562-104", MCP456x_104 }, 330 206 { "mcp4631-502", MCP463x_502 }, 331 207 { "mcp4631-103", MCP463x_103 }, 332 208 { "mcp4631-503", MCP463x_503 }, ··· 343 203 { "mcp4632-103", MCP463x_103 }, 344 204 { "mcp4632-503", MCP463x_503 }, 345 205 { "mcp4632-104", MCP463x_104 }, 206 + { "mcp4641-502", MCP464x_502 }, 207 + { "mcp4641-103", MCP464x_103 }, 208 + { "mcp4641-503", MCP464x_503 }, 209 + { "mcp4641-104", MCP464x_104 }, 210 + { "mcp4642-502", MCP464x_502 }, 211 + { "mcp4642-103", MCP464x_103 }, 212 + { "mcp4642-503", MCP464x_503 }, 213 + { "mcp4642-104", MCP464x_104 }, 346 214 { "mcp4651-502", MCP465x_502 }, 347 215 { "mcp4651-103", MCP465x_103 }, 348 216 { "mcp4651-503", MCP465x_503 }, ··· 359 211 { "mcp4652-103", MCP465x_103 }, 360 212 { "mcp4652-503", MCP465x_503 }, 361 213 { "mcp4652-104", MCP465x_104 }, 214 + { "mcp4661-502", MCP466x_502 }, 215 + { "mcp4661-103", MCP466x_103 }, 216 + { "mcp4661-503", MCP466x_503 }, 217 + { "mcp4661-104", MCP466x_104 }, 218 + { "mcp4662-502", MCP466x_502 }, 219 + { "mcp4662-103", MCP466x_103 }, 220 + { "mcp4662-503", MCP466x_503 }, 221 + { "mcp4662-104", MCP466x_104 }, 362 222 {} 363 223 }; 364 224 MODULE_DEVICE_TABLE(i2c, mcp4531_id); ··· 374 218 static struct i2c_driver mcp4531_driver = { 375 219 .driver = { 376 220 .name = "mcp4531", 221 + .of_match_table = of_match_ptr(mcp4531_of_match), 377 222 }, 378 223 .probe = mcp4531_probe, 379 224 .id_table = mcp4531_id,
+22 -6
drivers/iio/pressure/Kconfig
··· 6 6 menu "Pressure sensors" 7 7 8 8 config BMP280 9 - tristate "Bosch Sensortec BMP180 and BMP280 pressure sensor driver" 10 - depends on I2C 9 + tristate "Bosch Sensortec BMP180/BMP280 pressure sensor I2C driver" 10 + depends on (I2C || SPI_MASTER) 11 11 depends on !(BMP085_I2C=y || BMP085_I2C=m) 12 - select REGMAP_I2C 12 + depends on !(BMP085_SPI=y || BMP085_SPI=m) 13 + select REGMAP 14 + select BMP280_I2C if (I2C) 15 + select BMP280_SPI if (SPI_MASTER) 13 16 help 14 17 Say yes here to build support for Bosch Sensortec BMP180 and BMP280 15 18 pressure and temperature sensors. Also supports the BE280 with 16 - an additional humidty sensor channel. 19 + an additional humidity sensor channel. 17 20 18 - To compile this driver as a module, choose M here: the module 19 - will be called bmp280. 21 + To compile this driver as a module, choose M here: the core module 22 + will be called bmp280 and you will also get bmp280-i2c for I2C 23 + and/or bmp280-spi for SPI support. 24 + 25 + config BMP280_I2C 26 + tristate 27 + depends on BMP280 28 + depends on I2C 29 + select REGMAP_I2C 30 + 31 + config BMP280_SPI 32 + tristate 33 + depends on BMP280 34 + depends on SPI_MASTER 35 + select REGMAP 20 36 21 37 config HID_SENSOR_PRESS 22 38 depends on HID_SENSOR_HUB
+3
drivers/iio/pressure/Makefile
··· 4 4 5 5 # When adding new entries keep the list in alphabetical order 6 6 obj-$(CONFIG_BMP280) += bmp280.o 7 + bmp280-objs := bmp280-core.o bmp280-regmap.o 8 + obj-$(CONFIG_BMP280_I2C) += bmp280-i2c.o 9 + obj-$(CONFIG_BMP280_SPI) += bmp280-spi.o 7 10 obj-$(CONFIG_HID_SENSOR_PRESS) += hid-sensor-press.o 8 11 obj-$(CONFIG_HP03) += hp03.o 9 12 obj-$(CONFIG_MPL115) += mpl115.o
+91
drivers/iio/pressure/bmp280-i2c.c
··· 1 + #include <linux/module.h> 2 + #include <linux/i2c.h> 3 + #include <linux/acpi.h> 4 + #include <linux/of.h> 5 + #include <linux/regmap.h> 6 + 7 + #include "bmp280.h" 8 + 9 + static int bmp280_i2c_probe(struct i2c_client *client, 10 + const struct i2c_device_id *id) 11 + { 12 + struct regmap *regmap; 13 + const struct regmap_config *regmap_config; 14 + 15 + switch (id->driver_data) { 16 + case BMP180_CHIP_ID: 17 + regmap_config = &bmp180_regmap_config; 18 + break; 19 + case BMP280_CHIP_ID: 20 + case BME280_CHIP_ID: 21 + regmap_config = &bmp280_regmap_config; 22 + break; 23 + default: 24 + return -EINVAL; 25 + } 26 + 27 + regmap = devm_regmap_init_i2c(client, regmap_config); 28 + if (IS_ERR(regmap)) { 29 + dev_err(&client->dev, "failed to allocate register map\n"); 30 + return PTR_ERR(regmap); 31 + } 32 + 33 + return bmp280_common_probe(&client->dev, 34 + regmap, 35 + id->driver_data, 36 + id->name, 37 + client->irq); 38 + } 39 + 40 + static int bmp280_i2c_remove(struct i2c_client *client) 41 + { 42 + return bmp280_common_remove(&client->dev); 43 + } 44 + 45 + static const struct acpi_device_id bmp280_acpi_i2c_match[] = { 46 + {"BMP0280", BMP280_CHIP_ID }, 47 + {"BMP0180", BMP180_CHIP_ID }, 48 + {"BMP0085", BMP180_CHIP_ID }, 49 + {"BME0280", BME280_CHIP_ID }, 50 + { }, 51 + }; 52 + MODULE_DEVICE_TABLE(acpi, bmp280_acpi_i2c_match); 53 + 54 + #ifdef CONFIG_OF 55 + static const struct of_device_id bmp280_of_i2c_match[] = { 56 + { .compatible = "bosch,bme280", .data = (void *)BME280_CHIP_ID }, 57 + { .compatible = "bosch,bmp280", .data = (void *)BMP280_CHIP_ID }, 58 + { .compatible = "bosch,bmp180", .data = (void *)BMP180_CHIP_ID }, 59 + { .compatible = "bosch,bmp085", .data = (void *)BMP180_CHIP_ID }, 60 + { }, 61 + }; 62 + MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match); 63 + #else 64 + #define bmp280_of_i2c_match NULL 65 + #endif 66 + 67 + static const struct i2c_device_id bmp280_i2c_id[] = { 68 + {"bmp280", BMP280_CHIP_ID }, 69 + {"bmp180", BMP180_CHIP_ID }, 70 + {"bmp085", BMP180_CHIP_ID }, 71 + {"bme280", BME280_CHIP_ID }, 72 + { }, 73 + }; 74 + MODULE_DEVICE_TABLE(i2c, bmp280_i2c_id); 75 + 76 + static struct i2c_driver bmp280_i2c_driver = { 77 + .driver = { 78 + .name = "bmp280", 79 + .acpi_match_table = ACPI_PTR(bmp280_acpi_i2c_match), 80 + .of_match_table = of_match_ptr(bmp280_of_i2c_match), 81 + .pm = &bmp280_dev_pm_ops, 82 + }, 83 + .probe = bmp280_i2c_probe, 84 + .remove = bmp280_i2c_remove, 85 + .id_table = bmp280_i2c_id, 86 + }; 87 + module_i2c_driver(bmp280_i2c_driver); 88 + 89 + MODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>"); 90 + MODULE_DESCRIPTION("Driver for Bosch Sensortec BMP180/BMP280 pressure and temperature sensor"); 91 + MODULE_LICENSE("GPL v2");
+84
drivers/iio/pressure/bmp280-regmap.c
··· 1 + #include <linux/device.h> 2 + #include <linux/module.h> 3 + #include <linux/regmap.h> 4 + 5 + #include "bmp280.h" 6 + 7 + static bool bmp180_is_writeable_reg(struct device *dev, unsigned int reg) 8 + { 9 + switch (reg) { 10 + case BMP280_REG_CTRL_MEAS: 11 + case BMP280_REG_RESET: 12 + return true; 13 + default: 14 + return false; 15 + }; 16 + } 17 + 18 + static bool bmp180_is_volatile_reg(struct device *dev, unsigned int reg) 19 + { 20 + switch (reg) { 21 + case BMP180_REG_OUT_XLSB: 22 + case BMP180_REG_OUT_LSB: 23 + case BMP180_REG_OUT_MSB: 24 + case BMP280_REG_CTRL_MEAS: 25 + return true; 26 + default: 27 + return false; 28 + } 29 + } 30 + 31 + const struct regmap_config bmp180_regmap_config = { 32 + .reg_bits = 8, 33 + .val_bits = 8, 34 + 35 + .max_register = BMP180_REG_OUT_XLSB, 36 + .cache_type = REGCACHE_RBTREE, 37 + 38 + .writeable_reg = bmp180_is_writeable_reg, 39 + .volatile_reg = bmp180_is_volatile_reg, 40 + }; 41 + EXPORT_SYMBOL(bmp180_regmap_config); 42 + 43 + static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg) 44 + { 45 + switch (reg) { 46 + case BMP280_REG_CONFIG: 47 + case BMP280_REG_CTRL_HUMIDITY: 48 + case BMP280_REG_CTRL_MEAS: 49 + case BMP280_REG_RESET: 50 + return true; 51 + default: 52 + return false; 53 + }; 54 + } 55 + 56 + static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg) 57 + { 58 + switch (reg) { 59 + case BMP280_REG_HUMIDITY_LSB: 60 + case BMP280_REG_HUMIDITY_MSB: 61 + case BMP280_REG_TEMP_XLSB: 62 + case BMP280_REG_TEMP_LSB: 63 + case BMP280_REG_TEMP_MSB: 64 + case BMP280_REG_PRESS_XLSB: 65 + case BMP280_REG_PRESS_LSB: 66 + case BMP280_REG_PRESS_MSB: 67 + case BMP280_REG_STATUS: 68 + return true; 69 + default: 70 + return false; 71 + } 72 + } 73 + 74 + const struct regmap_config bmp280_regmap_config = { 75 + .reg_bits = 8, 76 + .val_bits = 8, 77 + 78 + .max_register = BMP280_REG_HUMIDITY_LSB, 79 + .cache_type = REGCACHE_RBTREE, 80 + 81 + .writeable_reg = bmp280_is_writeable_reg, 82 + .volatile_reg = bmp280_is_volatile_reg, 83 + }; 84 + EXPORT_SYMBOL(bmp280_regmap_config);
+125
drivers/iio/pressure/bmp280-spi.c
··· 1 + /* 2 + * SPI interface for the BMP280 driver 3 + * 4 + * Inspired by the older BMP085 driver drivers/misc/bmp085-spi.c 5 + */ 6 + #include <linux/module.h> 7 + #include <linux/spi/spi.h> 8 + #include <linux/err.h> 9 + #include <linux/regmap.h> 10 + 11 + #include "bmp280.h" 12 + 13 + static int bmp280_regmap_spi_write(void *context, const void *data, 14 + size_t count) 15 + { 16 + struct device *dev = context; 17 + struct spi_device *spi = to_spi_device(dev); 18 + u8 buf[2]; 19 + 20 + memcpy(buf, data, 2); 21 + /* 22 + * The SPI register address (= full register address without bit 7) and 23 + * the write command (bit7 = RW = '0') 24 + */ 25 + buf[0] &= ~0x80; 26 + 27 + return spi_write_then_read(spi, buf, 2, NULL, 0); 28 + } 29 + 30 + static int bmp280_regmap_spi_read(void *context, const void *reg, 31 + size_t reg_size, void *val, size_t val_size) 32 + { 33 + struct device *dev = context; 34 + struct spi_device *spi = to_spi_device(dev); 35 + 36 + return spi_write_then_read(spi, reg, reg_size, val, val_size); 37 + } 38 + 39 + static struct regmap_bus bmp280_regmap_bus = { 40 + .write = bmp280_regmap_spi_write, 41 + .read = bmp280_regmap_spi_read, 42 + .reg_format_endian_default = REGMAP_ENDIAN_BIG, 43 + .val_format_endian_default = REGMAP_ENDIAN_BIG, 44 + }; 45 + 46 + static int bmp280_spi_probe(struct spi_device *spi) 47 + { 48 + const struct spi_device_id *id = spi_get_device_id(spi); 49 + struct regmap *regmap; 50 + const struct regmap_config *regmap_config; 51 + int ret; 52 + 53 + spi->bits_per_word = 8; 54 + ret = spi_setup(spi); 55 + if (ret < 0) { 56 + dev_err(&spi->dev, "spi_setup failed!\n"); 57 + return ret; 58 + } 59 + 60 + switch (id->driver_data) { 61 + case BMP180_CHIP_ID: 62 + regmap_config = &bmp180_regmap_config; 63 + break; 64 + case BMP280_CHIP_ID: 65 + case BME280_CHIP_ID: 66 + regmap_config = &bmp280_regmap_config; 67 + break; 68 + default: 69 + return -EINVAL; 70 + } 71 + 72 + regmap = devm_regmap_init(&spi->dev, 73 + &bmp280_regmap_bus, 74 + &spi->dev, 75 + regmap_config); 76 + if (IS_ERR(regmap)) { 77 + dev_err(&spi->dev, "failed to allocate register map\n"); 78 + return PTR_ERR(regmap); 79 + } 80 + 81 + return bmp280_common_probe(&spi->dev, 82 + regmap, 83 + id->driver_data, 84 + id->name, 85 + spi->irq); 86 + } 87 + 88 + static int bmp280_spi_remove(struct spi_device *spi) 89 + { 90 + return bmp280_common_remove(&spi->dev); 91 + } 92 + 93 + static const struct of_device_id bmp280_of_spi_match[] = { 94 + { .compatible = "bosch,bmp085", }, 95 + { .compatible = "bosch,bmp180", }, 96 + { .compatible = "bosch,bmp181", }, 97 + { .compatible = "bosch,bmp280", }, 98 + { .compatible = "bosch,bme280", }, 99 + { }, 100 + }; 101 + MODULE_DEVICE_TABLE(of, bmp280_of_spi_match); 102 + 103 + static const struct spi_device_id bmp280_spi_id[] = { 104 + { "bmp180", BMP180_CHIP_ID }, 105 + { "bmp181", BMP180_CHIP_ID }, 106 + { "bmp280", BMP280_CHIP_ID }, 107 + { "bme280", BME280_CHIP_ID }, 108 + { } 109 + }; 110 + MODULE_DEVICE_TABLE(spi, bmp280_spi_id); 111 + 112 + static struct spi_driver bmp280_spi_driver = { 113 + .driver = { 114 + .name = "bmp280", 115 + .of_match_table = bmp280_of_spi_match, 116 + .pm = &bmp280_dev_pm_ops, 117 + }, 118 + .id_table = bmp280_spi_id, 119 + .probe = bmp280_spi_probe, 120 + .remove = bmp280_spi_remove, 121 + }; 122 + module_spi_driver(bmp280_spi_driver); 123 + 124 + MODULE_DESCRIPTION("BMP280 SPI bus driver"); 125 + MODULE_LICENSE("GPL");
+282 -283
drivers/iio/pressure/bmp280.c drivers/iio/pressure/bmp280-core.c
··· 1 1 /* 2 + * Copyright (c) 2010 Christoph Mair <christoph.mair@gmail.com> 3 + * Copyright (c) 2012 Bosch Sensortec GmbH 4 + * Copyright (c) 2012 Unixphere AB 2 5 * Copyright (c) 2014 Intel Corporation 6 + * Copyright (c) 2016 Linus Walleij <linus.walleij@linaro.org> 3 7 * 4 8 * Driver for Bosch Sensortec BMP180 and BMP280 digital pressure sensor. 5 9 * ··· 19 15 20 16 #define pr_fmt(fmt) "bmp280: " fmt 21 17 18 + #include <linux/device.h> 22 19 #include <linux/module.h> 23 - #include <linux/i2c.h> 24 - #include <linux/acpi.h> 25 20 #include <linux/regmap.h> 26 21 #include <linux/delay.h> 27 22 #include <linux/iio/iio.h> 28 23 #include <linux/iio/sysfs.h> 24 + #include <linux/gpio/consumer.h> 25 + #include <linux/regulator/consumer.h> 26 + #include <linux/interrupt.h> 27 + #include <linux/irq.h> /* For irq_get_irq_data() */ 28 + #include <linux/completion.h> 29 + #include <linux/pm_runtime.h> 30 + #include <linux/random.h> 29 31 30 - /* BMP280 specific registers */ 31 - #define BMP280_REG_HUMIDITY_LSB 0xFE 32 - #define BMP280_REG_HUMIDITY_MSB 0xFD 33 - #define BMP280_REG_TEMP_XLSB 0xFC 34 - #define BMP280_REG_TEMP_LSB 0xFB 35 - #define BMP280_REG_TEMP_MSB 0xFA 36 - #define BMP280_REG_PRESS_XLSB 0xF9 37 - #define BMP280_REG_PRESS_LSB 0xF8 38 - #define BMP280_REG_PRESS_MSB 0xF7 32 + #include "bmp280.h" 39 33 40 - #define BMP280_REG_CONFIG 0xF5 41 - #define BMP280_REG_CTRL_MEAS 0xF4 42 - #define BMP280_REG_STATUS 0xF3 43 - #define BMP280_REG_CTRL_HUMIDITY 0xF2 34 + /* 35 + * These enums are used for indexing into the array of calibration 36 + * coefficients for BMP180. 37 + */ 38 + enum { AC1, AC2, AC3, AC4, AC5, AC6, B1, B2, MB, MC, MD }; 44 39 45 - /* Due to non linear mapping, and data sizes we can't do a bulk read */ 46 - #define BMP280_REG_COMP_H1 0xA1 47 - #define BMP280_REG_COMP_H2 0xE1 48 - #define BMP280_REG_COMP_H3 0xE3 49 - #define BMP280_REG_COMP_H4 0xE4 50 - #define BMP280_REG_COMP_H5 0xE5 51 - #define BMP280_REG_COMP_H6 0xE7 52 - 53 - #define BMP280_REG_COMP_TEMP_START 0x88 54 - #define BMP280_COMP_TEMP_REG_COUNT 6 55 - 56 - #define BMP280_REG_COMP_PRESS_START 0x8E 57 - #define BMP280_COMP_PRESS_REG_COUNT 18 58 - 59 - #define BMP280_FILTER_MASK (BIT(4) | BIT(3) | BIT(2)) 60 - #define BMP280_FILTER_OFF 0 61 - #define BMP280_FILTER_2X BIT(2) 62 - #define BMP280_FILTER_4X BIT(3) 63 - #define BMP280_FILTER_8X (BIT(3) | BIT(2)) 64 - #define BMP280_FILTER_16X BIT(4) 65 - 66 - #define BMP280_OSRS_HUMIDITY_MASK (BIT(2) | BIT(1) | BIT(0)) 67 - #define BMP280_OSRS_HUMIDITIY_X(osrs_h) ((osrs_h) << 0) 68 - #define BMP280_OSRS_HUMIDITY_SKIP 0 69 - #define BMP280_OSRS_HUMIDITY_1X BMP280_OSRS_HUMIDITIY_X(1) 70 - #define BMP280_OSRS_HUMIDITY_2X BMP280_OSRS_HUMIDITIY_X(2) 71 - #define BMP280_OSRS_HUMIDITY_4X BMP280_OSRS_HUMIDITIY_X(3) 72 - #define BMP280_OSRS_HUMIDITY_8X BMP280_OSRS_HUMIDITIY_X(4) 73 - #define BMP280_OSRS_HUMIDITY_16X BMP280_OSRS_HUMIDITIY_X(5) 74 - 75 - #define BMP280_OSRS_TEMP_MASK (BIT(7) | BIT(6) | BIT(5)) 76 - #define BMP280_OSRS_TEMP_SKIP 0 77 - #define BMP280_OSRS_TEMP_X(osrs_t) ((osrs_t) << 5) 78 - #define BMP280_OSRS_TEMP_1X BMP280_OSRS_TEMP_X(1) 79 - #define BMP280_OSRS_TEMP_2X BMP280_OSRS_TEMP_X(2) 80 - #define BMP280_OSRS_TEMP_4X BMP280_OSRS_TEMP_X(3) 81 - #define BMP280_OSRS_TEMP_8X BMP280_OSRS_TEMP_X(4) 82 - #define BMP280_OSRS_TEMP_16X BMP280_OSRS_TEMP_X(5) 83 - 84 - #define BMP280_OSRS_PRESS_MASK (BIT(4) | BIT(3) | BIT(2)) 85 - #define BMP280_OSRS_PRESS_SKIP 0 86 - #define BMP280_OSRS_PRESS_X(osrs_p) ((osrs_p) << 2) 87 - #define BMP280_OSRS_PRESS_1X BMP280_OSRS_PRESS_X(1) 88 - #define BMP280_OSRS_PRESS_2X BMP280_OSRS_PRESS_X(2) 89 - #define BMP280_OSRS_PRESS_4X BMP280_OSRS_PRESS_X(3) 90 - #define BMP280_OSRS_PRESS_8X BMP280_OSRS_PRESS_X(4) 91 - #define BMP280_OSRS_PRESS_16X BMP280_OSRS_PRESS_X(5) 92 - 93 - #define BMP280_MODE_MASK (BIT(1) | BIT(0)) 94 - #define BMP280_MODE_SLEEP 0 95 - #define BMP280_MODE_FORCED BIT(0) 96 - #define BMP280_MODE_NORMAL (BIT(1) | BIT(0)) 97 - 98 - /* BMP180 specific registers */ 99 - #define BMP180_REG_OUT_XLSB 0xF8 100 - #define BMP180_REG_OUT_LSB 0xF7 101 - #define BMP180_REG_OUT_MSB 0xF6 102 - 103 - #define BMP180_REG_CALIB_START 0xAA 104 - #define BMP180_REG_CALIB_COUNT 22 105 - 106 - #define BMP180_MEAS_SCO BIT(5) 107 - #define BMP180_MEAS_TEMP (0x0E | BMP180_MEAS_SCO) 108 - #define BMP180_MEAS_PRESS_X(oss) ((oss) << 6 | 0x14 | BMP180_MEAS_SCO) 109 - #define BMP180_MEAS_PRESS_1X BMP180_MEAS_PRESS_X(0) 110 - #define BMP180_MEAS_PRESS_2X BMP180_MEAS_PRESS_X(1) 111 - #define BMP180_MEAS_PRESS_4X BMP180_MEAS_PRESS_X(2) 112 - #define BMP180_MEAS_PRESS_8X BMP180_MEAS_PRESS_X(3) 113 - 114 - /* BMP180 and BMP280 common registers */ 115 - #define BMP280_REG_CTRL_MEAS 0xF4 116 - #define BMP280_REG_RESET 0xE0 117 - #define BMP280_REG_ID 0xD0 118 - 119 - #define BMP180_CHIP_ID 0x55 120 - #define BMP280_CHIP_ID 0x58 121 - #define BME280_CHIP_ID 0x60 122 - #define BMP280_SOFT_RESET_VAL 0xB6 40 + struct bmp180_calib { 41 + s16 AC1; 42 + s16 AC2; 43 + s16 AC3; 44 + u16 AC4; 45 + u16 AC5; 46 + u16 AC6; 47 + s16 B1; 48 + s16 B2; 49 + s16 MB; 50 + s16 MC; 51 + s16 MD; 52 + }; 123 53 124 54 struct bmp280_data { 125 - struct i2c_client *client; 55 + struct device *dev; 126 56 struct mutex lock; 127 57 struct regmap *regmap; 58 + struct completion done; 59 + bool use_eoc; 128 60 const struct bmp280_chip_info *chip_info; 61 + struct bmp180_calib calib; 62 + struct regulator *vddd; 63 + struct regulator *vdda; 64 + unsigned int start_up_time; /* in milliseconds */ 129 65 130 66 /* log of base 2 of oversampling rate */ 131 67 u8 oversampling_press; ··· 80 136 }; 81 137 82 138 struct bmp280_chip_info { 83 - const struct regmap_config *regmap_config; 84 - 85 139 const int *oversampling_temp_avail; 86 140 int num_oversampling_temp_avail; 87 141 ··· 120 178 }, 121 179 }; 122 180 123 - static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg) 124 - { 125 - switch (reg) { 126 - case BMP280_REG_CONFIG: 127 - case BMP280_REG_CTRL_HUMIDITY: 128 - case BMP280_REG_CTRL_MEAS: 129 - case BMP280_REG_RESET: 130 - return true; 131 - default: 132 - return false; 133 - }; 134 - } 135 - 136 - static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg) 137 - { 138 - switch (reg) { 139 - case BMP280_REG_HUMIDITY_LSB: 140 - case BMP280_REG_HUMIDITY_MSB: 141 - case BMP280_REG_TEMP_XLSB: 142 - case BMP280_REG_TEMP_LSB: 143 - case BMP280_REG_TEMP_MSB: 144 - case BMP280_REG_PRESS_XLSB: 145 - case BMP280_REG_PRESS_LSB: 146 - case BMP280_REG_PRESS_MSB: 147 - case BMP280_REG_STATUS: 148 - return true; 149 - default: 150 - return false; 151 - } 152 - } 153 - 154 - static const struct regmap_config bmp280_regmap_config = { 155 - .reg_bits = 8, 156 - .val_bits = 8, 157 - 158 - .max_register = BMP280_REG_HUMIDITY_LSB, 159 - .cache_type = REGCACHE_RBTREE, 160 - 161 - .writeable_reg = bmp280_is_writeable_reg, 162 - .volatile_reg = bmp280_is_volatile_reg, 163 - }; 164 - 165 181 /* 166 182 * Returns humidity in percent, resolution is 0.01 percent. Output value of 167 183 * "47445" represents 47445/1024 = 46.333 %RH. ··· 130 230 static u32 bmp280_compensate_humidity(struct bmp280_data *data, 131 231 s32 adc_humidity) 132 232 { 133 - struct device *dev = &data->client->dev; 233 + struct device *dev = data->dev; 134 234 unsigned int H1, H3, tmp; 135 235 int H2, H4, H5, H6, ret, var; 136 236 ··· 201 301 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_TEMP_START, 202 302 buf, BMP280_COMP_TEMP_REG_COUNT); 203 303 if (ret < 0) { 204 - dev_err(&data->client->dev, 304 + dev_err(data->dev, 205 305 "failed to read temperature calibration parameters\n"); 206 306 return ret; 207 307 } ··· 241 341 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_PRESS_START, 242 342 buf, BMP280_COMP_PRESS_REG_COUNT); 243 343 if (ret < 0) { 244 - dev_err(&data->client->dev, 344 + dev_err(data->dev, 245 345 "failed to read pressure calibration parameters\n"); 246 346 return ret; 247 347 } ··· 276 376 ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, 277 377 (u8 *) &tmp, 3); 278 378 if (ret < 0) { 279 - dev_err(&data->client->dev, "failed to read temperature\n"); 379 + dev_err(data->dev, "failed to read temperature\n"); 280 380 return ret; 281 381 } 282 382 ··· 311 411 ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, 312 412 (u8 *) &tmp, 3); 313 413 if (ret < 0) { 314 - dev_err(&data->client->dev, "failed to read pressure\n"); 414 + dev_err(data->dev, "failed to read pressure\n"); 315 415 return ret; 316 416 } 317 417 ··· 339 439 ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB, 340 440 (u8 *) &tmp, 2); 341 441 if (ret < 0) { 342 - dev_err(&data->client->dev, "failed to read humidity\n"); 442 + dev_err(data->dev, "failed to read humidity\n"); 343 443 return ret; 344 444 } 345 445 ··· 359 459 int ret; 360 460 struct bmp280_data *data = iio_priv(indio_dev); 361 461 462 + pm_runtime_get_sync(data->dev); 362 463 mutex_lock(&data->lock); 363 464 364 465 switch (mask) { ··· 404 503 } 405 504 406 505 mutex_unlock(&data->lock); 506 + pm_runtime_mark_last_busy(data->dev); 507 + pm_runtime_put_autosuspend(data->dev); 407 508 408 509 return ret; 409 510 } ··· 470 567 471 568 switch (mask) { 472 569 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 570 + pm_runtime_get_sync(data->dev); 473 571 mutex_lock(&data->lock); 474 572 switch (chan->type) { 475 573 case IIO_HUMIDITYRELATIVE: ··· 487 583 break; 488 584 } 489 585 mutex_unlock(&data->lock); 586 + pm_runtime_mark_last_busy(data->dev); 587 + pm_runtime_put_autosuspend(data->dev); 490 588 break; 491 589 default: 492 590 return -EINVAL; ··· 563 657 BMP280_MODE_MASK, 564 658 osrs | BMP280_MODE_NORMAL); 565 659 if (ret < 0) { 566 - dev_err(&data->client->dev, 660 + dev_err(data->dev, 567 661 "failed to write ctrl_meas register\n"); 568 662 return ret; 569 663 } ··· 572 666 BMP280_FILTER_MASK, 573 667 BMP280_FILTER_4X); 574 668 if (ret < 0) { 575 - dev_err(&data->client->dev, 669 + dev_err(data->dev, 576 670 "failed to write config register\n"); 577 671 return ret; 578 672 } ··· 583 677 static const int bmp280_oversampling_avail[] = { 1, 2, 4, 8, 16 }; 584 678 585 679 static const struct bmp280_chip_info bmp280_chip_info = { 586 - .regmap_config = &bmp280_regmap_config, 587 - 588 680 .oversampling_temp_avail = bmp280_oversampling_avail, 589 681 .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail), 590 682 ··· 607 703 } 608 704 609 705 static const struct bmp280_chip_info bme280_chip_info = { 610 - .regmap_config = &bmp280_regmap_config, 611 - 612 706 .oversampling_temp_avail = bmp280_oversampling_avail, 613 707 .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail), 614 708 ··· 622 720 .read_humid = bmp280_read_humid, 623 721 }; 624 722 625 - 626 - static bool bmp180_is_writeable_reg(struct device *dev, unsigned int reg) 627 - { 628 - switch (reg) { 629 - case BMP280_REG_CTRL_MEAS: 630 - case BMP280_REG_RESET: 631 - return true; 632 - default: 633 - return false; 634 - }; 635 - } 636 - 637 - static bool bmp180_is_volatile_reg(struct device *dev, unsigned int reg) 638 - { 639 - switch (reg) { 640 - case BMP180_REG_OUT_XLSB: 641 - case BMP180_REG_OUT_LSB: 642 - case BMP180_REG_OUT_MSB: 643 - case BMP280_REG_CTRL_MEAS: 644 - return true; 645 - default: 646 - return false; 647 - } 648 - } 649 - 650 - static const struct regmap_config bmp180_regmap_config = { 651 - .reg_bits = 8, 652 - .val_bits = 8, 653 - 654 - .max_register = BMP180_REG_OUT_XLSB, 655 - .cache_type = REGCACHE_RBTREE, 656 - 657 - .writeable_reg = bmp180_is_writeable_reg, 658 - .volatile_reg = bmp180_is_volatile_reg, 659 - }; 660 - 661 723 static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas) 662 724 { 663 725 int ret; ··· 629 763 unsigned int delay_us; 630 764 unsigned int ctrl; 631 765 766 + if (data->use_eoc) 767 + init_completion(&data->done); 768 + 632 769 ret = regmap_write(data->regmap, BMP280_REG_CTRL_MEAS, ctrl_meas); 633 770 if (ret) 634 771 return ret; 635 772 636 - if (ctrl_meas == BMP180_MEAS_TEMP) 637 - delay_us = 4500; 638 - else 639 - delay_us = conversion_time_max[data->oversampling_press]; 773 + if (data->use_eoc) { 774 + /* 775 + * If we have a completion interrupt, use it, wait up to 776 + * 100ms. The longest conversion time listed is 76.5 ms for 777 + * advanced resolution mode. 778 + */ 779 + ret = wait_for_completion_timeout(&data->done, 780 + 1 + msecs_to_jiffies(100)); 781 + if (!ret) 782 + dev_err(data->dev, "timeout waiting for completion\n"); 783 + } else { 784 + if (ctrl_meas == BMP180_MEAS_TEMP) 785 + delay_us = 4500; 786 + else 787 + delay_us = 788 + conversion_time_max[data->oversampling_press]; 640 789 641 - usleep_range(delay_us, delay_us + 1000); 790 + usleep_range(delay_us, delay_us + 1000); 791 + } 642 792 643 793 ret = regmap_read(data->regmap, BMP280_REG_CTRL_MEAS, &ctrl); 644 794 if (ret) ··· 685 803 return 0; 686 804 } 687 805 688 - /* 689 - * These enums are used for indexing into the array of calibration 690 - * coefficients for BMP180. 691 - */ 692 - enum { AC1, AC2, AC3, AC4, AC5, AC6, B1, B2, MB, MC, MD }; 693 - 694 - struct bmp180_calib { 695 - s16 AC1; 696 - s16 AC2; 697 - s16 AC3; 698 - u16 AC4; 699 - u16 AC5; 700 - u16 AC6; 701 - s16 B1; 702 - s16 B2; 703 - s16 MB; 704 - s16 MC; 705 - s16 MD; 706 - }; 707 - 708 806 static int bmp180_read_calib(struct bmp280_data *data, 709 807 struct bmp180_calib *calib) 710 808 { ··· 703 841 if (buf[i] == cpu_to_be16(0) || buf[i] == cpu_to_be16(0xffff)) 704 842 return -EIO; 705 843 } 844 + 845 + /* Toss the calibration data into the entropy pool */ 846 + add_device_randomness(buf, sizeof(buf)); 706 847 707 848 calib->AC1 = be16_to_cpu(buf[AC1]); 708 849 calib->AC2 = be16_to_cpu(buf[AC2]); ··· 730 865 */ 731 866 static s32 bmp180_compensate_temp(struct bmp280_data *data, s32 adc_temp) 732 867 { 733 - int ret; 734 868 s32 x1, x2; 735 - struct bmp180_calib calib; 869 + struct bmp180_calib *calib = &data->calib; 736 870 737 - ret = bmp180_read_calib(data, &calib); 738 - if (ret < 0) { 739 - dev_err(&data->client->dev, 740 - "failed to read calibration coefficients\n"); 741 - return ret; 742 - } 743 - 744 - x1 = ((adc_temp - calib.AC6) * calib.AC5) >> 15; 745 - x2 = (calib.MC << 11) / (x1 + calib.MD); 871 + x1 = ((adc_temp - calib->AC6) * calib->AC5) >> 15; 872 + x2 = (calib->MC << 11) / (x1 + calib->MD); 746 873 data->t_fine = x1 + x2; 747 874 748 875 return (data->t_fine + 8) >> 4; ··· 789 932 */ 790 933 static u32 bmp180_compensate_press(struct bmp280_data *data, s32 adc_press) 791 934 { 792 - int ret; 793 935 s32 x1, x2, x3, p; 794 936 s32 b3, b6; 795 937 u32 b4, b7; 796 938 s32 oss = data->oversampling_press; 797 - struct bmp180_calib calib; 798 - 799 - ret = bmp180_read_calib(data, &calib); 800 - if (ret < 0) { 801 - dev_err(&data->client->dev, 802 - "failed to read calibration coefficients\n"); 803 - return ret; 804 - } 939 + struct bmp180_calib *calib = &data->calib; 805 940 806 941 b6 = data->t_fine - 4000; 807 - x1 = (calib.B2 * (b6 * b6 >> 12)) >> 11; 808 - x2 = calib.AC2 * b6 >> 11; 942 + x1 = (calib->B2 * (b6 * b6 >> 12)) >> 11; 943 + x2 = calib->AC2 * b6 >> 11; 809 944 x3 = x1 + x2; 810 - b3 = ((((s32)calib.AC1 * 4 + x3) << oss) + 2) / 4; 811 - x1 = calib.AC3 * b6 >> 13; 812 - x2 = (calib.B1 * ((b6 * b6) >> 12)) >> 16; 945 + b3 = ((((s32)calib->AC1 * 4 + x3) << oss) + 2) / 4; 946 + x1 = calib->AC3 * b6 >> 13; 947 + x2 = (calib->B1 * ((b6 * b6) >> 12)) >> 16; 813 948 x3 = (x1 + x2 + 2) >> 2; 814 - b4 = calib.AC4 * (u32)(x3 + 32768) >> 15; 949 + b4 = calib->AC4 * (u32)(x3 + 32768) >> 15; 815 950 b7 = ((u32)adc_press - b3) * (50000 >> oss); 816 951 if (b7 < 0x80000000) 817 952 p = (b7 * 2) / b4; ··· 850 1001 static const int bmp180_oversampling_press_avail[] = { 1, 2, 4, 8 }; 851 1002 852 1003 static const struct bmp280_chip_info bmp180_chip_info = { 853 - .regmap_config = &bmp180_regmap_config, 854 - 855 1004 .oversampling_temp_avail = bmp180_oversampling_temp_avail, 856 1005 .num_oversampling_temp_avail = 857 1006 ARRAY_SIZE(bmp180_oversampling_temp_avail), ··· 863 1016 .read_press = bmp180_read_press, 864 1017 }; 865 1018 866 - static int bmp280_probe(struct i2c_client *client, 867 - const struct i2c_device_id *id) 1019 + static irqreturn_t bmp085_eoc_irq(int irq, void *d) 1020 + { 1021 + struct bmp280_data *data = d; 1022 + 1023 + complete(&data->done); 1024 + 1025 + return IRQ_HANDLED; 1026 + } 1027 + 1028 + static int bmp085_fetch_eoc_irq(struct device *dev, 1029 + const char *name, 1030 + int irq, 1031 + struct bmp280_data *data) 1032 + { 1033 + unsigned long irq_trig; 1034 + int ret; 1035 + 1036 + irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq)); 1037 + if (irq_trig != IRQF_TRIGGER_RISING) { 1038 + dev_err(dev, "non-rising trigger given for EOC interrupt, " 1039 + "trying to enforce it\n"); 1040 + irq_trig = IRQF_TRIGGER_RISING; 1041 + } 1042 + ret = devm_request_threaded_irq(dev, 1043 + irq, 1044 + bmp085_eoc_irq, 1045 + NULL, 1046 + irq_trig, 1047 + name, 1048 + data); 1049 + if (ret) { 1050 + /* Bail out without IRQ but keep the driver in place */ 1051 + dev_err(dev, "unable to request DRDY IRQ\n"); 1052 + return 0; 1053 + } 1054 + 1055 + data->use_eoc = true; 1056 + return 0; 1057 + } 1058 + 1059 + int bmp280_common_probe(struct device *dev, 1060 + struct regmap *regmap, 1061 + unsigned int chip, 1062 + const char *name, 1063 + int irq) 868 1064 { 869 1065 int ret; 870 1066 struct iio_dev *indio_dev; 871 1067 struct bmp280_data *data; 872 1068 unsigned int chip_id; 1069 + struct gpio_desc *gpiod; 873 1070 874 - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 1071 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 875 1072 if (!indio_dev) 876 1073 return -ENOMEM; 877 1074 878 1075 data = iio_priv(indio_dev); 879 1076 mutex_init(&data->lock); 880 - data->client = client; 1077 + data->dev = dev; 881 1078 882 - indio_dev->dev.parent = &client->dev; 883 - indio_dev->name = id->name; 1079 + indio_dev->dev.parent = dev; 1080 + indio_dev->name = name; 884 1081 indio_dev->channels = bmp280_channels; 885 1082 indio_dev->info = &bmp280_info; 886 1083 indio_dev->modes = INDIO_DIRECT_MODE; 887 1084 888 - switch (id->driver_data) { 1085 + switch (chip) { 889 1086 case BMP180_CHIP_ID: 890 1087 indio_dev->num_channels = 2; 891 1088 data->chip_info = &bmp180_chip_info; 892 1089 data->oversampling_press = ilog2(8); 893 1090 data->oversampling_temp = ilog2(1); 1091 + data->start_up_time = 10; 894 1092 break; 895 1093 case BMP280_CHIP_ID: 896 1094 indio_dev->num_channels = 2; 897 1095 data->chip_info = &bmp280_chip_info; 898 1096 data->oversampling_press = ilog2(16); 899 1097 data->oversampling_temp = ilog2(2); 1098 + data->start_up_time = 2; 900 1099 break; 901 1100 case BME280_CHIP_ID: 902 1101 indio_dev->num_channels = 3; ··· 950 1057 data->oversampling_press = ilog2(16); 951 1058 data->oversampling_humid = ilog2(16); 952 1059 data->oversampling_temp = ilog2(2); 1060 + data->start_up_time = 2; 953 1061 break; 954 1062 default: 955 1063 return -EINVAL; 956 1064 } 957 1065 958 - data->regmap = devm_regmap_init_i2c(client, 959 - data->chip_info->regmap_config); 960 - if (IS_ERR(data->regmap)) { 961 - dev_err(&client->dev, "failed to allocate register map\n"); 962 - return PTR_ERR(data->regmap); 1066 + /* Bring up regulators */ 1067 + data->vddd = devm_regulator_get(dev, "vddd"); 1068 + if (IS_ERR(data->vddd)) { 1069 + dev_err(dev, "failed to get VDDD regulator\n"); 1070 + return PTR_ERR(data->vddd); 1071 + } 1072 + ret = regulator_enable(data->vddd); 1073 + if (ret) { 1074 + dev_err(dev, "failed to enable VDDD regulator\n"); 1075 + return ret; 1076 + } 1077 + data->vdda = devm_regulator_get(dev, "vdda"); 1078 + if (IS_ERR(data->vdda)) { 1079 + dev_err(dev, "failed to get VDDA regulator\n"); 1080 + ret = PTR_ERR(data->vddd); 1081 + goto out_disable_vddd; 1082 + } 1083 + ret = regulator_enable(data->vdda); 1084 + if (ret) { 1085 + dev_err(dev, "failed to enable VDDA regulator\n"); 1086 + goto out_disable_vddd; 1087 + } 1088 + /* Wait to make sure we started up properly */ 1089 + mdelay(data->start_up_time); 1090 + 1091 + /* Bring chip out of reset if there is an assigned GPIO line */ 1092 + gpiod = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 1093 + /* Deassert the signal */ 1094 + if (!IS_ERR(gpiod)) { 1095 + dev_info(dev, "release reset\n"); 1096 + gpiod_set_value(gpiod, 0); 963 1097 } 964 1098 965 - ret = regmap_read(data->regmap, BMP280_REG_ID, &chip_id); 1099 + data->regmap = regmap; 1100 + ret = regmap_read(regmap, BMP280_REG_ID, &chip_id); 966 1101 if (ret < 0) 967 - return ret; 968 - if (chip_id != id->driver_data) { 969 - dev_err(&client->dev, "bad chip id. expected %lx got %x\n", 970 - id->driver_data, chip_id); 971 - return -EINVAL; 1102 + goto out_disable_vdda; 1103 + if (chip_id != chip) { 1104 + dev_err(dev, "bad chip id: expected %x got %x\n", 1105 + chip, chip_id); 1106 + ret = -EINVAL; 1107 + goto out_disable_vdda; 972 1108 } 973 1109 974 1110 ret = data->chip_info->chip_config(data); 975 1111 if (ret < 0) 976 - return ret; 1112 + goto out_disable_vdda; 977 1113 978 - return devm_iio_device_register(&client->dev, indio_dev); 1114 + dev_set_drvdata(dev, indio_dev); 1115 + 1116 + /* 1117 + * The BMP085 and BMP180 has calibration in an E2PROM, read it out 1118 + * at probe time. It will not change. 1119 + */ 1120 + if (chip_id == BMP180_CHIP_ID) { 1121 + ret = bmp180_read_calib(data, &data->calib); 1122 + if (ret < 0) { 1123 + dev_err(data->dev, 1124 + "failed to read calibration coefficients\n"); 1125 + goto out_disable_vdda; 1126 + } 1127 + } 1128 + 1129 + /* 1130 + * Attempt to grab an optional EOC IRQ - only the BMP085 has this 1131 + * however as it happens, the BMP085 shares the chip ID of BMP180 1132 + * so we look for an IRQ if we have that. 1133 + */ 1134 + if (irq > 0 || (chip_id == BMP180_CHIP_ID)) { 1135 + ret = bmp085_fetch_eoc_irq(dev, name, irq, data); 1136 + if (ret) 1137 + goto out_disable_vdda; 1138 + } 1139 + 1140 + /* Enable runtime PM */ 1141 + pm_runtime_get_noresume(dev); 1142 + pm_runtime_set_active(dev); 1143 + pm_runtime_enable(dev); 1144 + /* 1145 + * Set autosuspend to two orders of magnitude larger than the 1146 + * start-up time. 1147 + */ 1148 + pm_runtime_set_autosuspend_delay(dev, data->start_up_time *100); 1149 + pm_runtime_use_autosuspend(dev); 1150 + pm_runtime_put(dev); 1151 + 1152 + ret = iio_device_register(indio_dev); 1153 + if (ret) 1154 + goto out_runtime_pm_disable; 1155 + 1156 + 1157 + return 0; 1158 + 1159 + out_runtime_pm_disable: 1160 + pm_runtime_get_sync(data->dev); 1161 + pm_runtime_put_noidle(data->dev); 1162 + pm_runtime_disable(data->dev); 1163 + out_disable_vdda: 1164 + regulator_disable(data->vdda); 1165 + out_disable_vddd: 1166 + regulator_disable(data->vddd); 1167 + return ret; 1168 + } 1169 + EXPORT_SYMBOL(bmp280_common_probe); 1170 + 1171 + int bmp280_common_remove(struct device *dev) 1172 + { 1173 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 1174 + struct bmp280_data *data = iio_priv(indio_dev); 1175 + 1176 + iio_device_unregister(indio_dev); 1177 + pm_runtime_get_sync(data->dev); 1178 + pm_runtime_put_noidle(data->dev); 1179 + pm_runtime_disable(data->dev); 1180 + regulator_disable(data->vdda); 1181 + regulator_disable(data->vddd); 1182 + return 0; 1183 + } 1184 + EXPORT_SYMBOL(bmp280_common_remove); 1185 + 1186 + #ifdef CONFIG_PM 1187 + static int bmp280_runtime_suspend(struct device *dev) 1188 + { 1189 + struct bmp280_data *data = dev_get_drvdata(dev); 1190 + int ret; 1191 + 1192 + ret = regulator_disable(data->vdda); 1193 + if (ret) 1194 + return ret; 1195 + return regulator_disable(data->vddd); 979 1196 } 980 1197 981 - static const struct acpi_device_id bmp280_acpi_match[] = { 982 - {"BMP0280", BMP280_CHIP_ID }, 983 - {"BMP0180", BMP180_CHIP_ID }, 984 - {"BMP0085", BMP180_CHIP_ID }, 985 - {"BME0280", BME280_CHIP_ID }, 986 - { }, 987 - }; 988 - MODULE_DEVICE_TABLE(acpi, bmp280_acpi_match); 1198 + static int bmp280_runtime_resume(struct device *dev) 1199 + { 1200 + struct bmp280_data *data = dev_get_drvdata(dev); 1201 + int ret; 989 1202 990 - static const struct i2c_device_id bmp280_id[] = { 991 - {"bmp280", BMP280_CHIP_ID }, 992 - {"bmp180", BMP180_CHIP_ID }, 993 - {"bmp085", BMP180_CHIP_ID }, 994 - {"bme280", BME280_CHIP_ID }, 995 - { }, 996 - }; 997 - MODULE_DEVICE_TABLE(i2c, bmp280_id); 1203 + ret = regulator_enable(data->vddd); 1204 + if (ret) 1205 + return ret; 1206 + ret = regulator_enable(data->vdda); 1207 + if (ret) 1208 + return ret; 1209 + msleep(data->start_up_time); 1210 + return data->chip_info->chip_config(data); 1211 + } 1212 + #endif /* CONFIG_PM */ 998 1213 999 - static struct i2c_driver bmp280_driver = { 1000 - .driver = { 1001 - .name = "bmp280", 1002 - .acpi_match_table = ACPI_PTR(bmp280_acpi_match), 1003 - }, 1004 - .probe = bmp280_probe, 1005 - .id_table = bmp280_id, 1214 + const struct dev_pm_ops bmp280_dev_pm_ops = { 1215 + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 1216 + pm_runtime_force_resume) 1217 + SET_RUNTIME_PM_OPS(bmp280_runtime_suspend, 1218 + bmp280_runtime_resume, NULL) 1006 1219 }; 1007 - module_i2c_driver(bmp280_driver); 1220 + EXPORT_SYMBOL(bmp280_dev_pm_ops); 1008 1221 1009 1222 MODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>"); 1010 1223 MODULE_DESCRIPTION("Driver for Bosch Sensortec BMP180/BMP280 pressure and temperature sensor");
+112
drivers/iio/pressure/bmp280.h
··· 1 + #include <linux/bitops.h> 2 + #include <linux/device.h> 3 + #include <linux/regmap.h> 4 + 5 + /* BMP280 specific registers */ 6 + #define BMP280_REG_HUMIDITY_LSB 0xFE 7 + #define BMP280_REG_HUMIDITY_MSB 0xFD 8 + #define BMP280_REG_TEMP_XLSB 0xFC 9 + #define BMP280_REG_TEMP_LSB 0xFB 10 + #define BMP280_REG_TEMP_MSB 0xFA 11 + #define BMP280_REG_PRESS_XLSB 0xF9 12 + #define BMP280_REG_PRESS_LSB 0xF8 13 + #define BMP280_REG_PRESS_MSB 0xF7 14 + 15 + #define BMP280_REG_CONFIG 0xF5 16 + #define BMP280_REG_CTRL_MEAS 0xF4 17 + #define BMP280_REG_STATUS 0xF3 18 + #define BMP280_REG_CTRL_HUMIDITY 0xF2 19 + 20 + /* Due to non linear mapping, and data sizes we can't do a bulk read */ 21 + #define BMP280_REG_COMP_H1 0xA1 22 + #define BMP280_REG_COMP_H2 0xE1 23 + #define BMP280_REG_COMP_H3 0xE3 24 + #define BMP280_REG_COMP_H4 0xE4 25 + #define BMP280_REG_COMP_H5 0xE5 26 + #define BMP280_REG_COMP_H6 0xE7 27 + 28 + #define BMP280_REG_COMP_TEMP_START 0x88 29 + #define BMP280_COMP_TEMP_REG_COUNT 6 30 + 31 + #define BMP280_REG_COMP_PRESS_START 0x8E 32 + #define BMP280_COMP_PRESS_REG_COUNT 18 33 + 34 + #define BMP280_FILTER_MASK (BIT(4) | BIT(3) | BIT(2)) 35 + #define BMP280_FILTER_OFF 0 36 + #define BMP280_FILTER_2X BIT(2) 37 + #define BMP280_FILTER_4X BIT(3) 38 + #define BMP280_FILTER_8X (BIT(3) | BIT(2)) 39 + #define BMP280_FILTER_16X BIT(4) 40 + 41 + #define BMP280_OSRS_HUMIDITY_MASK (BIT(2) | BIT(1) | BIT(0)) 42 + #define BMP280_OSRS_HUMIDITIY_X(osrs_h) ((osrs_h) << 0) 43 + #define BMP280_OSRS_HUMIDITY_SKIP 0 44 + #define BMP280_OSRS_HUMIDITY_1X BMP280_OSRS_HUMIDITIY_X(1) 45 + #define BMP280_OSRS_HUMIDITY_2X BMP280_OSRS_HUMIDITIY_X(2) 46 + #define BMP280_OSRS_HUMIDITY_4X BMP280_OSRS_HUMIDITIY_X(3) 47 + #define BMP280_OSRS_HUMIDITY_8X BMP280_OSRS_HUMIDITIY_X(4) 48 + #define BMP280_OSRS_HUMIDITY_16X BMP280_OSRS_HUMIDITIY_X(5) 49 + 50 + #define BMP280_OSRS_TEMP_MASK (BIT(7) | BIT(6) | BIT(5)) 51 + #define BMP280_OSRS_TEMP_SKIP 0 52 + #define BMP280_OSRS_TEMP_X(osrs_t) ((osrs_t) << 5) 53 + #define BMP280_OSRS_TEMP_1X BMP280_OSRS_TEMP_X(1) 54 + #define BMP280_OSRS_TEMP_2X BMP280_OSRS_TEMP_X(2) 55 + #define BMP280_OSRS_TEMP_4X BMP280_OSRS_TEMP_X(3) 56 + #define BMP280_OSRS_TEMP_8X BMP280_OSRS_TEMP_X(4) 57 + #define BMP280_OSRS_TEMP_16X BMP280_OSRS_TEMP_X(5) 58 + 59 + #define BMP280_OSRS_PRESS_MASK (BIT(4) | BIT(3) | BIT(2)) 60 + #define BMP280_OSRS_PRESS_SKIP 0 61 + #define BMP280_OSRS_PRESS_X(osrs_p) ((osrs_p) << 2) 62 + #define BMP280_OSRS_PRESS_1X BMP280_OSRS_PRESS_X(1) 63 + #define BMP280_OSRS_PRESS_2X BMP280_OSRS_PRESS_X(2) 64 + #define BMP280_OSRS_PRESS_4X BMP280_OSRS_PRESS_X(3) 65 + #define BMP280_OSRS_PRESS_8X BMP280_OSRS_PRESS_X(4) 66 + #define BMP280_OSRS_PRESS_16X BMP280_OSRS_PRESS_X(5) 67 + 68 + #define BMP280_MODE_MASK (BIT(1) | BIT(0)) 69 + #define BMP280_MODE_SLEEP 0 70 + #define BMP280_MODE_FORCED BIT(0) 71 + #define BMP280_MODE_NORMAL (BIT(1) | BIT(0)) 72 + 73 + /* BMP180 specific registers */ 74 + #define BMP180_REG_OUT_XLSB 0xF8 75 + #define BMP180_REG_OUT_LSB 0xF7 76 + #define BMP180_REG_OUT_MSB 0xF6 77 + 78 + #define BMP180_REG_CALIB_START 0xAA 79 + #define BMP180_REG_CALIB_COUNT 22 80 + 81 + #define BMP180_MEAS_SCO BIT(5) 82 + #define BMP180_MEAS_TEMP (0x0E | BMP180_MEAS_SCO) 83 + #define BMP180_MEAS_PRESS_X(oss) ((oss) << 6 | 0x14 | BMP180_MEAS_SCO) 84 + #define BMP180_MEAS_PRESS_1X BMP180_MEAS_PRESS_X(0) 85 + #define BMP180_MEAS_PRESS_2X BMP180_MEAS_PRESS_X(1) 86 + #define BMP180_MEAS_PRESS_4X BMP180_MEAS_PRESS_X(2) 87 + #define BMP180_MEAS_PRESS_8X BMP180_MEAS_PRESS_X(3) 88 + 89 + /* BMP180 and BMP280 common registers */ 90 + #define BMP280_REG_CTRL_MEAS 0xF4 91 + #define BMP280_REG_RESET 0xE0 92 + #define BMP280_REG_ID 0xD0 93 + 94 + #define BMP180_CHIP_ID 0x55 95 + #define BMP280_CHIP_ID 0x58 96 + #define BME280_CHIP_ID 0x60 97 + #define BMP280_SOFT_RESET_VAL 0xB6 98 + 99 + /* Regmap configurations */ 100 + extern const struct regmap_config bmp180_regmap_config; 101 + extern const struct regmap_config bmp280_regmap_config; 102 + 103 + /* Probe called from different transports */ 104 + int bmp280_common_probe(struct device *dev, 105 + struct regmap *regmap, 106 + unsigned int chip, 107 + const char *name, 108 + int irq); 109 + int bmp280_common_remove(struct device *dev); 110 + 111 + /* PM ops */ 112 + extern const struct dev_pm_ops bmp280_dev_pm_ops;
+1 -1
drivers/iio/pressure/mpl3115.c
··· 171 171 mutex_unlock(&data->lock); 172 172 173 173 iio_push_to_buffers_with_timestamp(indio_dev, buffer, 174 - iio_get_time_ns()); 174 + iio_get_time_ns(indio_dev)); 175 175 176 176 done: 177 177 iio_trigger_notify_done(indio_dev->trig);
+2 -1
drivers/iio/pressure/ms5611_core.c
··· 224 224 if (ret < 0) 225 225 goto err; 226 226 227 - iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns()); 227 + iio_push_to_buffers_with_timestamp(indio_dev, buf, 228 + iio_get_time_ns(indio_dev)); 228 229 229 230 err: 230 231 iio_trigger_notify_done(indio_dev->trig);
+129 -26
drivers/iio/pressure/st_pressure_core.c
··· 28 28 #include <linux/iio/common/st_sensors.h> 29 29 #include "st_pressure.h" 30 30 31 + /* 32 + * About determining pressure scaling factors 33 + * ------------------------------------------ 34 + * 35 + * Datasheets specify typical pressure sensitivity so that pressure is computed 36 + * according to the following equation : 37 + * pressure[mBar] = raw / sensitivity 38 + * where : 39 + * raw the 24 bits long raw sampled pressure 40 + * sensitivity a scaling factor specified by the datasheet in LSB/mBar 41 + * 42 + * IIO ABI expects pressure to be expressed as kPascal, hence pressure should be 43 + * computed according to : 44 + * pressure[kPascal] = pressure[mBar] / 10 45 + * = raw / (sensitivity * 10) (1) 46 + * 47 + * Finally, st_press_read_raw() returns pressure scaling factor as an 48 + * IIO_VAL_INT_PLUS_NANO with a zero integral part and "gain" as decimal part. 49 + * Therefore, from (1), "gain" becomes : 50 + * gain = 10^9 / (sensitivity * 10) 51 + * = 10^8 / sensitivity 52 + * 53 + * About determining temperature scaling factors and offsets 54 + * --------------------------------------------------------- 55 + * 56 + * Datasheets specify typical temperature sensitivity and offset so that 57 + * temperature is computed according to the following equation : 58 + * temp[Celsius] = offset[Celsius] + (raw / sensitivity) 59 + * where : 60 + * raw the 16 bits long raw sampled temperature 61 + * offset a constant specified by the datasheet in degree Celsius 62 + * (sometimes zero) 63 + * sensitivity a scaling factor specified by the datasheet in LSB/Celsius 64 + * 65 + * IIO ABI expects temperature to be expressed as milli degree Celsius such as 66 + * user space should compute temperature according to : 67 + * temp[mCelsius] = temp[Celsius] * 10^3 68 + * = (offset[Celsius] + (raw / sensitivity)) * 10^3 69 + * = ((offset[Celsius] * sensitivity) + raw) * 70 + * (10^3 / sensitivity) (2) 71 + * 72 + * IIO ABI expects user space to apply offset and scaling factors to raw samples 73 + * according to : 74 + * temp[mCelsius] = (OFFSET + raw) * SCALE 75 + * where : 76 + * OFFSET an arbitrary constant exposed by device 77 + * SCALE an arbitrary scaling factor exposed by device 78 + * 79 + * Matching OFFSET and SCALE with members of (2) gives : 80 + * OFFSET = offset[Celsius] * sensitivity (3) 81 + * SCALE = 10^3 / sensitivity (4) 82 + * 83 + * st_press_read_raw() returns temperature scaling factor as an 84 + * IIO_VAL_FRACTIONAL with a 10^3 numerator and "gain2" as denominator. 85 + * Therefore, from (3), "gain2" becomes : 86 + * gain2 = sensitivity 87 + * 88 + * When declared within channel, i.e. for a non zero specified offset, 89 + * st_press_read_raw() will return the latter as an IIO_VAL_FRACTIONAL such as : 90 + * numerator = OFFSET * 10^3 91 + * denominator = 10^3 92 + * giving from (4): 93 + * numerator = offset[Celsius] * 10^3 * sensitivity 94 + * = offset[mCelsius] * gain2 95 + */ 96 + 31 97 #define MCELSIUS_PER_CELSIUS 1000 32 98 33 99 /* Default pressure sensitivity */ ··· 105 39 #define ST_PRESS_LSB_PER_CELSIUS 480UL 106 40 #define ST_PRESS_MILLI_CELSIUS_OFFSET 42500UL 107 41 108 - #define ST_PRESS_NUMBER_DATA_CHANNELS 1 109 - 110 42 /* FULLSCALE */ 111 43 #define ST_PRESS_FS_AVL_1100MB 1100 112 44 #define ST_PRESS_FS_AVL_1260MB 1260 ··· 112 48 #define ST_PRESS_1_OUT_XL_ADDR 0x28 113 49 #define ST_TEMP_1_OUT_L_ADDR 0x2b 114 50 115 - /* CUSTOM VALUES FOR LPS331AP SENSOR */ 51 + /* 52 + * CUSTOM VALUES FOR LPS331AP SENSOR 53 + * See LPS331AP datasheet: 54 + * http://www2.st.com/resource/en/datasheet/lps331ap.pdf 55 + */ 116 56 #define ST_PRESS_LPS331AP_WAI_EXP 0xbb 117 57 #define ST_PRESS_LPS331AP_ODR_ADDR 0x20 118 58 #define ST_PRESS_LPS331AP_ODR_MASK 0x70 ··· 139 71 #define ST_PRESS_LPS331AP_OD_IRQ_MASK 0x40 140 72 #define ST_PRESS_LPS331AP_MULTIREAD_BIT true 141 73 142 - /* CUSTOM VALUES FOR LPS001WP SENSOR */ 74 + /* 75 + * CUSTOM VALUES FOR THE OBSOLETE LPS001WP SENSOR 76 + */ 143 77 144 78 /* LPS001WP pressure resolution */ 145 79 #define ST_PRESS_LPS001WP_LSB_PER_MBAR 16UL ··· 164 94 #define ST_PRESS_LPS001WP_OUT_L_ADDR 0x28 165 95 #define ST_TEMP_LPS001WP_OUT_L_ADDR 0x2a 166 96 167 - /* CUSTOM VALUES FOR LPS25H SENSOR */ 97 + /* 98 + * CUSTOM VALUES FOR LPS25H SENSOR 99 + * See LPS25H datasheet: 100 + * http://www2.st.com/resource/en/datasheet/lps25h.pdf 101 + */ 168 102 #define ST_PRESS_LPS25H_WAI_EXP 0xbd 169 103 #define ST_PRESS_LPS25H_ODR_ADDR 0x20 170 104 #define ST_PRESS_LPS25H_ODR_MASK 0x70 ··· 191 117 #define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28 192 118 #define ST_TEMP_LPS25H_OUT_L_ADDR 0x2b 193 119 194 - /* CUSTOM VALUES FOR LPS22HB SENSOR */ 120 + /* 121 + * CUSTOM VALUES FOR LPS22HB SENSOR 122 + * See LPS22HB datasheet: 123 + * http://www2.st.com/resource/en/datasheet/lps22hb.pdf 124 + */ 125 + 126 + /* LPS22HB temperature sensitivity */ 127 + #define ST_PRESS_LPS22HB_LSB_PER_CELSIUS 100UL 128 + 195 129 #define ST_PRESS_LPS22HB_WAI_EXP 0xb1 196 130 #define ST_PRESS_LPS22HB_ODR_ADDR 0x10 197 131 #define ST_PRESS_LPS22HB_ODR_MASK 0x70 ··· 217 135 #define ST_PRESS_LPS22HB_DRDY_IRQ_INT2_MASK 0x08 218 136 #define ST_PRESS_LPS22HB_IHL_IRQ_ADDR 0x12 219 137 #define ST_PRESS_LPS22HB_IHL_IRQ_MASK 0x80 138 + #define ST_PRESS_LPS22HB_OD_IRQ_ADDR 0x12 139 + #define ST_PRESS_LPS22HB_OD_IRQ_MASK 0x40 220 140 #define ST_PRESS_LPS22HB_MULTIREAD_BIT true 221 141 222 142 static const struct iio_chan_spec st_press_1_channels[] = { 223 143 { 224 144 .type = IIO_PRESSURE, 225 - .channel2 = IIO_NO_MOD, 226 145 .address = ST_PRESS_1_OUT_XL_ADDR, 227 - .scan_index = ST_SENSORS_SCAN_X, 146 + .scan_index = 0, 228 147 .scan_type = { 229 148 .sign = 'u', 230 149 .realbits = 24, 231 - .storagebits = 24, 150 + .storagebits = 32, 232 151 .endianness = IIO_LE, 233 152 }, 234 153 .info_mask_separate = 235 154 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 236 - .modified = 0, 237 155 }, 238 156 { 239 157 .type = IIO_TEMP, 240 - .channel2 = IIO_NO_MOD, 241 158 .address = ST_TEMP_1_OUT_L_ADDR, 242 - .scan_index = -1, 159 + .scan_index = 1, 243 160 .scan_type = { 244 161 .sign = 'u', 245 162 .realbits = 16, ··· 249 168 BIT(IIO_CHAN_INFO_RAW) | 250 169 BIT(IIO_CHAN_INFO_SCALE) | 251 170 BIT(IIO_CHAN_INFO_OFFSET), 252 - .modified = 0, 253 171 }, 254 - IIO_CHAN_SOFT_TIMESTAMP(1) 172 + IIO_CHAN_SOFT_TIMESTAMP(2) 255 173 }; 256 174 257 175 static const struct iio_chan_spec st_press_lps001wp_channels[] = { 258 176 { 259 177 .type = IIO_PRESSURE, 260 - .channel2 = IIO_NO_MOD, 261 178 .address = ST_PRESS_LPS001WP_OUT_L_ADDR, 262 - .scan_index = ST_SENSORS_SCAN_X, 179 + .scan_index = 0, 263 180 .scan_type = { 264 181 .sign = 'u', 265 182 .realbits = 16, ··· 267 188 .info_mask_separate = 268 189 BIT(IIO_CHAN_INFO_RAW) | 269 190 BIT(IIO_CHAN_INFO_SCALE), 270 - .modified = 0, 271 191 }, 272 192 { 273 193 .type = IIO_TEMP, 274 - .channel2 = IIO_NO_MOD, 275 194 .address = ST_TEMP_LPS001WP_OUT_L_ADDR, 276 - .scan_index = -1, 195 + .scan_index = 1, 277 196 .scan_type = { 278 197 .sign = 'u', 279 198 .realbits = 16, ··· 281 204 .info_mask_separate = 282 205 BIT(IIO_CHAN_INFO_RAW) | 283 206 BIT(IIO_CHAN_INFO_SCALE), 284 - .modified = 0, 285 207 }, 286 - IIO_CHAN_SOFT_TIMESTAMP(1) 208 + IIO_CHAN_SOFT_TIMESTAMP(2) 287 209 }; 288 210 289 211 static const struct iio_chan_spec st_press_lps22hb_channels[] = { 290 212 { 291 213 .type = IIO_PRESSURE, 292 - .channel2 = IIO_NO_MOD, 293 214 .address = ST_PRESS_1_OUT_XL_ADDR, 294 215 .scan_index = 0, 295 216 .scan_type = { 296 217 .sign = 'u', 297 218 .realbits = 24, 298 - .storagebits = 24, 219 + .storagebits = 32, 299 220 .endianness = IIO_LE, 300 221 }, 301 222 .info_mask_separate = 302 223 BIT(IIO_CHAN_INFO_RAW) | 303 224 BIT(IIO_CHAN_INFO_SCALE), 304 225 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 305 - .modified = 0, 306 226 }, 307 - IIO_CHAN_SOFT_TIMESTAMP(1) 227 + { 228 + .type = IIO_TEMP, 229 + .address = ST_TEMP_1_OUT_L_ADDR, 230 + .scan_index = 1, 231 + .scan_type = { 232 + .sign = 's', 233 + .realbits = 16, 234 + .storagebits = 16, 235 + .endianness = IIO_LE, 236 + }, 237 + .info_mask_separate = 238 + BIT(IIO_CHAN_INFO_RAW) | 239 + BIT(IIO_CHAN_INFO_SCALE), 240 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 241 + }, 242 + IIO_CHAN_SOFT_TIMESTAMP(2) 308 243 }; 309 244 310 245 static const struct st_sensor_settings st_press_sensors_settings[] = { ··· 502 413 }, 503 414 .fs = { 504 415 .fs_avl = { 416 + /* 417 + * Pressure and temperature sensitivity values 418 + * as defined in table 3 of LPS22HB datasheet. 419 + */ 505 420 [0] = { 506 421 .num = ST_PRESS_FS_AVL_1260MB, 507 422 .gain = ST_PRESS_KPASCAL_NANO_SCALE, 423 + .gain2 = ST_PRESS_LPS22HB_LSB_PER_CELSIUS, 508 424 }, 509 425 }, 510 426 }, ··· 523 429 .mask_int2 = ST_PRESS_LPS22HB_DRDY_IRQ_INT2_MASK, 524 430 .addr_ihl = ST_PRESS_LPS22HB_IHL_IRQ_ADDR, 525 431 .mask_ihl = ST_PRESS_LPS22HB_IHL_IRQ_MASK, 432 + .addr_od = ST_PRESS_LPS22HB_OD_IRQ_ADDR, 433 + .mask_od = ST_PRESS_LPS22HB_OD_IRQ_MASK, 434 + .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, 526 435 }, 527 436 .multi_read_bit = ST_PRESS_LPS22HB_MULTIREAD_BIT, 528 437 }, ··· 655 558 if (err < 0) 656 559 goto st_press_power_off; 657 560 658 - press_data->num_data_channels = ST_PRESS_NUMBER_DATA_CHANNELS; 561 + /* 562 + * Skip timestamping channel while declaring available channels to 563 + * common st_sensor layer. Look at st_sensors_get_buffer_element() to 564 + * see how timestamps are explicitly pushed as last samples block 565 + * element. 566 + */ 567 + press_data->num_data_channels = press_data->sensor_settings->num_ch - 1; 659 568 press_data->multiread_bit = press_data->sensor_settings->multi_read_bit; 660 569 indio_dev->channels = press_data->sensor_settings->ch; 661 570 indio_dev->num_channels = press_data->sensor_settings->num_ch;
+1 -1
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
··· 238 238 ret = lidar_get_measurement(data, data->buffer); 239 239 if (!ret) { 240 240 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 241 - iio_get_time_ns()); 241 + iio_get_time_ns(indio_dev)); 242 242 } else if (ret != -EINVAL) { 243 243 dev_err(&data->client->dev, "cannot read LIDAR measurement"); 244 244 }
+2 -2
drivers/iio/proximity/sx9500.c
··· 492 492 dir = new_prox ? IIO_EV_DIR_FALLING : IIO_EV_DIR_RISING; 493 493 ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, chan, 494 494 IIO_EV_TYPE_THRESH, dir); 495 - iio_push_event(indio_dev, ev, iio_get_time_ns()); 495 + iio_push_event(indio_dev, ev, iio_get_time_ns(indio_dev)); 496 496 data->prox_stat[chan] = new_prox; 497 497 } 498 498 } ··· 669 669 } 670 670 671 671 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 672 - iio_get_time_ns()); 672 + iio_get_time_ns(indio_dev)); 673 673 674 674 out: 675 675 mutex_unlock(&data->mutex);
-14
drivers/staging/iio/accel/Kconfig
··· 51 51 To compile this driver as a module, say M here: the module will be 52 52 called adis16240. 53 53 54 - config LIS3L02DQ 55 - tristate "ST Microelectronics LIS3L02DQ Accelerometer Driver" 56 - depends on SPI 57 - select IIO_TRIGGER if IIO_BUFFER 58 - depends on !IIO_BUFFER || IIO_KFIFO_BUF 59 - depends on GPIOLIB || COMPILE_TEST 60 - help 61 - Say Y here to build SPI support for the ST microelectronics 62 - accelerometer. The driver supplies direct access via sysfs files 63 - and an event interface via a character device. 64 - 65 - To compile this driver as a module, say M here: the module will be 66 - called lis3l02dq. 67 - 68 54 config SCA3000 69 55 depends on IIO_BUFFER 70 56 depends on SPI
-4
drivers/staging/iio/accel/Makefile
··· 14 14 adis16240-y := adis16240_core.o 15 15 obj-$(CONFIG_ADIS16240) += adis16240.o 16 16 17 - lis3l02dq-y := lis3l02dq_core.o 18 - lis3l02dq-$(CONFIG_IIO_BUFFER) += lis3l02dq_ring.o 19 - obj-$(CONFIG_LIS3L02DQ) += lis3l02dq.o 20 - 21 17 sca3000-y := sca3000_core.o sca3000_ring.o 22 18 obj-$(CONFIG_SCA3000) += sca3000.o
-217
drivers/staging/iio/accel/lis3l02dq.h
··· 1 - /* 2 - * LISL02DQ.h -- support STMicroelectronics LISD02DQ 3 - * 3d 2g Linear Accelerometers via SPI 4 - * 5 - * Copyright (c) 2007 Jonathan Cameron <jic23@kernel.org> 6 - * 7 - * Loosely based upon tle62x0.c 8 - * 9 - * This program is free software; you can redistribute it and/or modify 10 - * it under the terms of the GNU General Public License version 2 as 11 - * published by the Free Software Foundation. 12 - */ 13 - 14 - #ifndef SPI_LIS3L02DQ_H_ 15 - #define SPI_LIS3L02DQ_H_ 16 - #define LIS3L02DQ_READ_REG(a) ((a) | 0x80) 17 - #define LIS3L02DQ_WRITE_REG(a) a 18 - 19 - /* Calibration parameters */ 20 - #define LIS3L02DQ_REG_OFFSET_X_ADDR 0x16 21 - #define LIS3L02DQ_REG_OFFSET_Y_ADDR 0x17 22 - #define LIS3L02DQ_REG_OFFSET_Z_ADDR 0x18 23 - 24 - #define LIS3L02DQ_REG_GAIN_X_ADDR 0x19 25 - #define LIS3L02DQ_REG_GAIN_Y_ADDR 0x1A 26 - #define LIS3L02DQ_REG_GAIN_Z_ADDR 0x1B 27 - 28 - /* Control Register (1 of 2) */ 29 - #define LIS3L02DQ_REG_CTRL_1_ADDR 0x20 30 - /* Power ctrl - either bit set corresponds to on*/ 31 - #define LIS3L02DQ_REG_CTRL_1_PD_ON 0xC0 32 - 33 - /* Decimation Factor */ 34 - #define LIS3L02DQ_DEC_MASK 0x30 35 - #define LIS3L02DQ_REG_CTRL_1_DF_128 0x00 36 - #define LIS3L02DQ_REG_CTRL_1_DF_64 0x10 37 - #define LIS3L02DQ_REG_CTRL_1_DF_32 0x20 38 - #define LIS3L02DQ_REG_CTRL_1_DF_8 (0x10 | 0x20) 39 - 40 - /* Self Test Enable */ 41 - #define LIS3L02DQ_REG_CTRL_1_SELF_TEST_ON 0x08 42 - 43 - /* Axes enable ctrls */ 44 - #define LIS3L02DQ_REG_CTRL_1_AXES_Z_ENABLE 0x04 45 - #define LIS3L02DQ_REG_CTRL_1_AXES_Y_ENABLE 0x02 46 - #define LIS3L02DQ_REG_CTRL_1_AXES_X_ENABLE 0x01 47 - 48 - /* Control Register (2 of 2) */ 49 - #define LIS3L02DQ_REG_CTRL_2_ADDR 0x21 50 - 51 - /* Block Data Update only after MSB and LSB read */ 52 - #define LIS3L02DQ_REG_CTRL_2_BLOCK_UPDATE 0x40 53 - 54 - /* Set to big endian output */ 55 - #define LIS3L02DQ_REG_CTRL_2_BIG_ENDIAN 0x20 56 - 57 - /* Reboot memory content */ 58 - #define LIS3L02DQ_REG_CTRL_2_REBOOT_MEMORY 0x10 59 - 60 - /* Interrupt Enable - applies data ready to the RDY pad */ 61 - #define LIS3L02DQ_REG_CTRL_2_ENABLE_INTERRUPT 0x08 62 - 63 - /* Enable Data Ready Generation - relationship with previous unclear in docs */ 64 - #define LIS3L02DQ_REG_CTRL_2_ENABLE_DATA_READY_GENERATION 0x04 65 - 66 - /* SPI 3 wire mode */ 67 - #define LIS3L02DQ_REG_CTRL_2_THREE_WIRE_SPI_MODE 0x02 68 - 69 - /* Data alignment, default is 12 bit right justified 70 - * - option for 16 bit left justified 71 - */ 72 - #define LIS3L02DQ_REG_CTRL_2_DATA_ALIGNMENT_16_BIT_LEFT_JUSTIFIED 0x01 73 - 74 - /* Interrupt related stuff */ 75 - #define LIS3L02DQ_REG_WAKE_UP_CFG_ADDR 0x23 76 - 77 - /* Switch from or combination of conditions to and */ 78 - #define LIS3L02DQ_REG_WAKE_UP_CFG_BOOLEAN_AND 0x80 79 - 80 - /* Latch interrupt request, 81 - * if on ack must be given by reading the ack register 82 - */ 83 - #define LIS3L02DQ_REG_WAKE_UP_CFG_LATCH_SRC 0x40 84 - 85 - /* Z Interrupt on High (above threshold) */ 86 - #define LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_Z_HIGH 0x20 87 - /* Z Interrupt on Low */ 88 - #define LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_Z_LOW 0x10 89 - /* Y Interrupt on High */ 90 - #define LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_Y_HIGH 0x08 91 - /* Y Interrupt on Low */ 92 - #define LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_Y_LOW 0x04 93 - /* X Interrupt on High */ 94 - #define LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_X_HIGH 0x02 95 - /* X Interrupt on Low */ 96 - #define LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_X_LOW 0x01 97 - 98 - /* Register that gives description of what caused interrupt 99 - * - latched if set in CFG_ADDRES 100 - */ 101 - #define LIS3L02DQ_REG_WAKE_UP_SRC_ADDR 0x24 102 - /* top bit ignored */ 103 - /* Interrupt Active */ 104 - #define LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_ACTIVATED 0x40 105 - /* Interupts that have been triggered */ 106 - #define LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Z_HIGH 0x20 107 - #define LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Z_LOW 0x10 108 - #define LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Y_HIGH 0x08 109 - #define LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Y_LOW 0x04 110 - #define LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_X_HIGH 0x02 111 - #define LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_X_LOW 0x01 112 - 113 - #define LIS3L02DQ_REG_WAKE_UP_ACK_ADDR 0x25 114 - 115 - /* Status register */ 116 - #define LIS3L02DQ_REG_STATUS_ADDR 0x27 117 - /* XYZ axis data overrun - first is all overrun? */ 118 - #define LIS3L02DQ_REG_STATUS_XYZ_OVERRUN 0x80 119 - #define LIS3L02DQ_REG_STATUS_Z_OVERRUN 0x40 120 - #define LIS3L02DQ_REG_STATUS_Y_OVERRUN 0x20 121 - #define LIS3L02DQ_REG_STATUS_X_OVERRUN 0x10 122 - /* XYZ new data available - first is all 3 available? */ 123 - #define LIS3L02DQ_REG_STATUS_XYZ_NEW_DATA 0x08 124 - #define LIS3L02DQ_REG_STATUS_Z_NEW_DATA 0x04 125 - #define LIS3L02DQ_REG_STATUS_Y_NEW_DATA 0x02 126 - #define LIS3L02DQ_REG_STATUS_X_NEW_DATA 0x01 127 - 128 - /* The accelerometer readings - low and high bytes. 129 - * Form of high byte dependent on justification set in ctrl reg 130 - */ 131 - #define LIS3L02DQ_REG_OUT_X_L_ADDR 0x28 132 - #define LIS3L02DQ_REG_OUT_X_H_ADDR 0x29 133 - #define LIS3L02DQ_REG_OUT_Y_L_ADDR 0x2A 134 - #define LIS3L02DQ_REG_OUT_Y_H_ADDR 0x2B 135 - #define LIS3L02DQ_REG_OUT_Z_L_ADDR 0x2C 136 - #define LIS3L02DQ_REG_OUT_Z_H_ADDR 0x2D 137 - 138 - /* Threshold values for all axes and both above and below thresholds 139 - * - i.e. there is only one value 140 - */ 141 - #define LIS3L02DQ_REG_THS_L_ADDR 0x2E 142 - #define LIS3L02DQ_REG_THS_H_ADDR 0x2F 143 - 144 - #define LIS3L02DQ_DEFAULT_CTRL1 (LIS3L02DQ_REG_CTRL_1_PD_ON \ 145 - | LIS3L02DQ_REG_CTRL_1_AXES_Z_ENABLE \ 146 - | LIS3L02DQ_REG_CTRL_1_AXES_Y_ENABLE \ 147 - | LIS3L02DQ_REG_CTRL_1_AXES_X_ENABLE \ 148 - | LIS3L02DQ_REG_CTRL_1_DF_128) 149 - 150 - #define LIS3L02DQ_DEFAULT_CTRL2 0 151 - 152 - #define LIS3L02DQ_MAX_TX 12 153 - #define LIS3L02DQ_MAX_RX 12 154 - /** 155 - * struct lis3l02dq_state - device instance specific data 156 - * @us: actual spi_device 157 - * @trig: data ready trigger registered with iio 158 - * @buf_lock: mutex to protect tx and rx 159 - * @tx: transmit buffer 160 - * @rx: receive buffer 161 - **/ 162 - struct lis3l02dq_state { 163 - struct spi_device *us; 164 - struct iio_trigger *trig; 165 - struct mutex buf_lock; 166 - int gpio; 167 - bool trigger_on; 168 - 169 - u8 tx[LIS3L02DQ_MAX_RX] ____cacheline_aligned; 170 - u8 rx[LIS3L02DQ_MAX_RX] ____cacheline_aligned; 171 - }; 172 - 173 - int lis3l02dq_spi_read_reg_8(struct iio_dev *indio_dev, 174 - u8 reg_address, 175 - u8 *val); 176 - 177 - int lis3l02dq_spi_write_reg_8(struct iio_dev *indio_dev, 178 - u8 reg_address, 179 - u8 val); 180 - 181 - int lis3l02dq_disable_all_events(struct iio_dev *indio_dev); 182 - 183 - #ifdef CONFIG_IIO_BUFFER 184 - /* At the moment triggers are only used for buffer 185 - * filling. This may change! 186 - */ 187 - void lis3l02dq_remove_trigger(struct iio_dev *indio_dev); 188 - int lis3l02dq_probe_trigger(struct iio_dev *indio_dev); 189 - 190 - int lis3l02dq_configure_buffer(struct iio_dev *indio_dev); 191 - void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev); 192 - 193 - irqreturn_t lis3l02dq_data_rdy_trig_poll(int irq, void *private); 194 - #define lis3l02dq_th lis3l02dq_data_rdy_trig_poll 195 - 196 - #else /* CONFIG_IIO_BUFFER */ 197 - #define lis3l02dq_th lis3l02dq_nobuffer 198 - 199 - static inline void lis3l02dq_remove_trigger(struct iio_dev *indio_dev) 200 - { 201 - } 202 - 203 - static inline int lis3l02dq_probe_trigger(struct iio_dev *indio_dev) 204 - { 205 - return 0; 206 - } 207 - 208 - static int lis3l02dq_configure_buffer(struct iio_dev *indio_dev) 209 - { 210 - return 0; 211 - } 212 - 213 - static inline void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev) 214 - { 215 - } 216 - #endif /* CONFIG_IIO_BUFFER */ 217 - #endif /* SPI_LIS3L02DQ_H_ */
-814
drivers/staging/iio/accel/lis3l02dq_core.c
··· 1 - /* 2 - * lis3l02dq.c support STMicroelectronics LISD02DQ 3 - * 3d 2g Linear Accelerometers via SPI 4 - * 5 - * Copyright (c) 2007 Jonathan Cameron <jic23@kernel.org> 6 - * 7 - * This program is free software; you can redistribute it and/or modify 8 - * it under the terms of the GNU General Public License version 2 as 9 - * published by the Free Software Foundation. 10 - * 11 - * Settings: 12 - * 16 bit left justified mode used. 13 - */ 14 - 15 - #include <linux/interrupt.h> 16 - #include <linux/irq.h> 17 - #include <linux/gpio.h> 18 - #include <linux/of_gpio.h> 19 - #include <linux/mutex.h> 20 - #include <linux/device.h> 21 - #include <linux/kernel.h> 22 - #include <linux/spi/spi.h> 23 - #include <linux/slab.h> 24 - #include <linux/sysfs.h> 25 - #include <linux/module.h> 26 - 27 - #include <linux/iio/iio.h> 28 - #include <linux/iio/sysfs.h> 29 - #include <linux/iio/events.h> 30 - #include <linux/iio/buffer.h> 31 - 32 - #include "lis3l02dq.h" 33 - 34 - /* At the moment the spi framework doesn't allow global setting of cs_change. 35 - * It's in the likely to be added comment at the top of spi.h. 36 - * This means that use cannot be made of spi_write etc. 37 - */ 38 - /* direct copy of the irq_default_primary_handler */ 39 - #ifndef CONFIG_IIO_BUFFER 40 - static irqreturn_t lis3l02dq_nobuffer(int irq, void *private) 41 - { 42 - return IRQ_WAKE_THREAD; 43 - } 44 - #endif 45 - 46 - /** 47 - * lis3l02dq_spi_read_reg_8() - read single byte from a single register 48 - * @indio_dev: iio_dev for this actual device 49 - * @reg_address: the address of the register to be read 50 - * @val: pass back the resulting value 51 - **/ 52 - int lis3l02dq_spi_read_reg_8(struct iio_dev *indio_dev, 53 - u8 reg_address, u8 *val) 54 - { 55 - struct lis3l02dq_state *st = iio_priv(indio_dev); 56 - int ret; 57 - struct spi_transfer xfer = { 58 - .tx_buf = st->tx, 59 - .rx_buf = st->rx, 60 - .bits_per_word = 8, 61 - .len = 2, 62 - }; 63 - 64 - mutex_lock(&st->buf_lock); 65 - st->tx[0] = LIS3L02DQ_READ_REG(reg_address); 66 - st->tx[1] = 0; 67 - 68 - ret = spi_sync_transfer(st->us, &xfer, 1); 69 - *val = st->rx[1]; 70 - mutex_unlock(&st->buf_lock); 71 - 72 - return ret; 73 - } 74 - 75 - /** 76 - * lis3l02dq_spi_write_reg_8() - write single byte to a register 77 - * @indio_dev: iio_dev for this device 78 - * @reg_address: the address of the register to be written 79 - * @val: the value to write 80 - **/ 81 - int lis3l02dq_spi_write_reg_8(struct iio_dev *indio_dev, 82 - u8 reg_address, 83 - u8 val) 84 - { 85 - int ret; 86 - struct lis3l02dq_state *st = iio_priv(indio_dev); 87 - 88 - mutex_lock(&st->buf_lock); 89 - st->tx[0] = LIS3L02DQ_WRITE_REG(reg_address); 90 - st->tx[1] = val; 91 - ret = spi_write(st->us, st->tx, 2); 92 - mutex_unlock(&st->buf_lock); 93 - 94 - return ret; 95 - } 96 - 97 - /** 98 - * lisl302dq_spi_write_reg_s16() - write 2 bytes to a pair of registers 99 - * @indio_dev: iio_dev for this device 100 - * @lower_reg_address: the address of the lower of the two registers. 101 - * Second register is assumed to have address one greater. 102 - * @value: value to be written 103 - **/ 104 - static int lis3l02dq_spi_write_reg_s16(struct iio_dev *indio_dev, 105 - u8 lower_reg_address, 106 - s16 value) 107 - { 108 - int ret; 109 - struct lis3l02dq_state *st = iio_priv(indio_dev); 110 - struct spi_transfer xfers[] = { { 111 - .tx_buf = st->tx, 112 - .bits_per_word = 8, 113 - .len = 2, 114 - .cs_change = 1, 115 - }, { 116 - .tx_buf = st->tx + 2, 117 - .bits_per_word = 8, 118 - .len = 2, 119 - }, 120 - }; 121 - 122 - mutex_lock(&st->buf_lock); 123 - st->tx[0] = LIS3L02DQ_WRITE_REG(lower_reg_address); 124 - st->tx[1] = value & 0xFF; 125 - st->tx[2] = LIS3L02DQ_WRITE_REG(lower_reg_address + 1); 126 - st->tx[3] = (value >> 8) & 0xFF; 127 - 128 - ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); 129 - mutex_unlock(&st->buf_lock); 130 - 131 - return ret; 132 - } 133 - 134 - static int lis3l02dq_read_reg_s16(struct iio_dev *indio_dev, 135 - u8 lower_reg_address, 136 - int *val) 137 - { 138 - struct lis3l02dq_state *st = iio_priv(indio_dev); 139 - int ret; 140 - s16 tempval; 141 - struct spi_transfer xfers[] = { { 142 - .tx_buf = st->tx, 143 - .rx_buf = st->rx, 144 - .bits_per_word = 8, 145 - .len = 2, 146 - .cs_change = 1, 147 - }, { 148 - .tx_buf = st->tx + 2, 149 - .rx_buf = st->rx + 2, 150 - .bits_per_word = 8, 151 - .len = 2, 152 - }, 153 - }; 154 - 155 - mutex_lock(&st->buf_lock); 156 - st->tx[0] = LIS3L02DQ_READ_REG(lower_reg_address); 157 - st->tx[1] = 0; 158 - st->tx[2] = LIS3L02DQ_READ_REG(lower_reg_address + 1); 159 - st->tx[3] = 0; 160 - 161 - ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); 162 - if (ret) { 163 - dev_err(&st->us->dev, "problem when reading 16 bit register"); 164 - goto error_ret; 165 - } 166 - tempval = (s16)(st->rx[1]) | ((s16)(st->rx[3]) << 8); 167 - 168 - *val = tempval; 169 - error_ret: 170 - mutex_unlock(&st->buf_lock); 171 - return ret; 172 - } 173 - 174 - enum lis3l02dq_rm_ind { 175 - LIS3L02DQ_ACCEL, 176 - LIS3L02DQ_GAIN, 177 - LIS3L02DQ_BIAS, 178 - }; 179 - 180 - static u8 lis3l02dq_axis_map[3][3] = { 181 - [LIS3L02DQ_ACCEL] = { LIS3L02DQ_REG_OUT_X_L_ADDR, 182 - LIS3L02DQ_REG_OUT_Y_L_ADDR, 183 - LIS3L02DQ_REG_OUT_Z_L_ADDR }, 184 - [LIS3L02DQ_GAIN] = { LIS3L02DQ_REG_GAIN_X_ADDR, 185 - LIS3L02DQ_REG_GAIN_Y_ADDR, 186 - LIS3L02DQ_REG_GAIN_Z_ADDR }, 187 - [LIS3L02DQ_BIAS] = { LIS3L02DQ_REG_OFFSET_X_ADDR, 188 - LIS3L02DQ_REG_OFFSET_Y_ADDR, 189 - LIS3L02DQ_REG_OFFSET_Z_ADDR } 190 - }; 191 - 192 - static int lis3l02dq_read_thresh(struct iio_dev *indio_dev, 193 - const struct iio_chan_spec *chan, 194 - enum iio_event_type type, 195 - enum iio_event_direction dir, 196 - enum iio_event_info info, 197 - int *val, int *val2) 198 - { 199 - int ret; 200 - 201 - ret = lis3l02dq_read_reg_s16(indio_dev, LIS3L02DQ_REG_THS_L_ADDR, val); 202 - if (ret) 203 - return ret; 204 - return IIO_VAL_INT; 205 - } 206 - 207 - static int lis3l02dq_write_thresh(struct iio_dev *indio_dev, 208 - const struct iio_chan_spec *chan, 209 - enum iio_event_type type, 210 - enum iio_event_direction dir, 211 - enum iio_event_info info, 212 - int val, int val2) 213 - { 214 - u16 value = val; 215 - 216 - return lis3l02dq_spi_write_reg_s16(indio_dev, 217 - LIS3L02DQ_REG_THS_L_ADDR, 218 - value); 219 - } 220 - 221 - static int lis3l02dq_write_raw(struct iio_dev *indio_dev, 222 - struct iio_chan_spec const *chan, 223 - int val, 224 - int val2, 225 - long mask) 226 - { 227 - int ret = -EINVAL, reg; 228 - u8 uval; 229 - s8 sval; 230 - 231 - switch (mask) { 232 - case IIO_CHAN_INFO_CALIBBIAS: 233 - if (val > 255 || val < -256) 234 - return -EINVAL; 235 - sval = val; 236 - reg = lis3l02dq_axis_map[LIS3L02DQ_BIAS][chan->address]; 237 - ret = lis3l02dq_spi_write_reg_8(indio_dev, reg, sval); 238 - break; 239 - case IIO_CHAN_INFO_CALIBSCALE: 240 - if (val & ~0xFF) 241 - return -EINVAL; 242 - uval = val; 243 - reg = lis3l02dq_axis_map[LIS3L02DQ_GAIN][chan->address]; 244 - ret = lis3l02dq_spi_write_reg_8(indio_dev, reg, uval); 245 - break; 246 - } 247 - return ret; 248 - } 249 - 250 - static int lis3l02dq_read_raw(struct iio_dev *indio_dev, 251 - struct iio_chan_spec const *chan, 252 - int *val, 253 - int *val2, 254 - long mask) 255 - { 256 - u8 utemp; 257 - s8 stemp; 258 - ssize_t ret = 0; 259 - u8 reg; 260 - 261 - switch (mask) { 262 - case IIO_CHAN_INFO_RAW: 263 - /* Take the iio_dev status lock */ 264 - mutex_lock(&indio_dev->mlock); 265 - if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { 266 - ret = -EBUSY; 267 - } else { 268 - reg = lis3l02dq_axis_map 269 - [LIS3L02DQ_ACCEL][chan->address]; 270 - ret = lis3l02dq_read_reg_s16(indio_dev, reg, val); 271 - } 272 - mutex_unlock(&indio_dev->mlock); 273 - if (ret < 0) 274 - goto error_ret; 275 - return IIO_VAL_INT; 276 - case IIO_CHAN_INFO_SCALE: 277 - *val = 0; 278 - *val2 = 9580; 279 - return IIO_VAL_INT_PLUS_MICRO; 280 - case IIO_CHAN_INFO_CALIBSCALE: 281 - reg = lis3l02dq_axis_map[LIS3L02DQ_GAIN][chan->address]; 282 - ret = lis3l02dq_spi_read_reg_8(indio_dev, reg, &utemp); 283 - if (ret) 284 - goto error_ret; 285 - /* to match with what previous code does */ 286 - *val = utemp; 287 - return IIO_VAL_INT; 288 - 289 - case IIO_CHAN_INFO_CALIBBIAS: 290 - reg = lis3l02dq_axis_map[LIS3L02DQ_BIAS][chan->address]; 291 - ret = lis3l02dq_spi_read_reg_8(indio_dev, reg, (u8 *)&stemp); 292 - /* to match with what previous code does */ 293 - *val = stemp; 294 - return IIO_VAL_INT; 295 - } 296 - error_ret: 297 - return ret; 298 - } 299 - 300 - static ssize_t lis3l02dq_read_frequency(struct device *dev, 301 - struct device_attribute *attr, 302 - char *buf) 303 - { 304 - struct iio_dev *indio_dev = dev_to_iio_dev(dev); 305 - int ret, len = 0; 306 - s8 t; 307 - 308 - ret = lis3l02dq_spi_read_reg_8(indio_dev, 309 - LIS3L02DQ_REG_CTRL_1_ADDR, 310 - (u8 *)&t); 311 - if (ret) 312 - return ret; 313 - t &= LIS3L02DQ_DEC_MASK; 314 - switch (t) { 315 - case LIS3L02DQ_REG_CTRL_1_DF_128: 316 - len = sprintf(buf, "280\n"); 317 - break; 318 - case LIS3L02DQ_REG_CTRL_1_DF_64: 319 - len = sprintf(buf, "560\n"); 320 - break; 321 - case LIS3L02DQ_REG_CTRL_1_DF_32: 322 - len = sprintf(buf, "1120\n"); 323 - break; 324 - case LIS3L02DQ_REG_CTRL_1_DF_8: 325 - len = sprintf(buf, "4480\n"); 326 - break; 327 - } 328 - return len; 329 - } 330 - 331 - static ssize_t lis3l02dq_write_frequency(struct device *dev, 332 - struct device_attribute *attr, 333 - const char *buf, 334 - size_t len) 335 - { 336 - struct iio_dev *indio_dev = dev_to_iio_dev(dev); 337 - unsigned long val; 338 - int ret; 339 - u8 t; 340 - 341 - ret = kstrtoul(buf, 10, &val); 342 - if (ret) 343 - return ret; 344 - 345 - mutex_lock(&indio_dev->mlock); 346 - ret = lis3l02dq_spi_read_reg_8(indio_dev, 347 - LIS3L02DQ_REG_CTRL_1_ADDR, 348 - &t); 349 - if (ret) 350 - goto error_ret_mutex; 351 - /* Wipe the bits clean */ 352 - t &= ~LIS3L02DQ_DEC_MASK; 353 - switch (val) { 354 - case 280: 355 - t |= LIS3L02DQ_REG_CTRL_1_DF_128; 356 - break; 357 - case 560: 358 - t |= LIS3L02DQ_REG_CTRL_1_DF_64; 359 - break; 360 - case 1120: 361 - t |= LIS3L02DQ_REG_CTRL_1_DF_32; 362 - break; 363 - case 4480: 364 - t |= LIS3L02DQ_REG_CTRL_1_DF_8; 365 - break; 366 - default: 367 - ret = -EINVAL; 368 - goto error_ret_mutex; 369 - } 370 - 371 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 372 - LIS3L02DQ_REG_CTRL_1_ADDR, 373 - t); 374 - 375 - error_ret_mutex: 376 - mutex_unlock(&indio_dev->mlock); 377 - 378 - return ret ? ret : len; 379 - } 380 - 381 - static int lis3l02dq_initial_setup(struct iio_dev *indio_dev) 382 - { 383 - struct lis3l02dq_state *st = iio_priv(indio_dev); 384 - int ret; 385 - u8 val, valtest; 386 - 387 - st->us->mode = SPI_MODE_3; 388 - 389 - spi_setup(st->us); 390 - 391 - val = LIS3L02DQ_DEFAULT_CTRL1; 392 - /* Write suitable defaults to ctrl1 */ 393 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 394 - LIS3L02DQ_REG_CTRL_1_ADDR, 395 - val); 396 - if (ret) { 397 - dev_err(&st->us->dev, "problem with setup control register 1"); 398 - goto err_ret; 399 - } 400 - /* Repeat as sometimes doesn't work first time? */ 401 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 402 - LIS3L02DQ_REG_CTRL_1_ADDR, 403 - val); 404 - if (ret) { 405 - dev_err(&st->us->dev, "problem with setup control register 1"); 406 - goto err_ret; 407 - } 408 - 409 - /* 410 - * Read back to check this has worked acts as loose test of correct 411 - * chip 412 - */ 413 - ret = lis3l02dq_spi_read_reg_8(indio_dev, 414 - LIS3L02DQ_REG_CTRL_1_ADDR, 415 - &valtest); 416 - if (ret || (valtest != val)) { 417 - dev_err(&indio_dev->dev, 418 - "device not playing ball %d %d\n", valtest, val); 419 - ret = -EINVAL; 420 - goto err_ret; 421 - } 422 - 423 - val = LIS3L02DQ_DEFAULT_CTRL2; 424 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 425 - LIS3L02DQ_REG_CTRL_2_ADDR, 426 - val); 427 - if (ret) { 428 - dev_err(&st->us->dev, "problem with setup control register 2"); 429 - goto err_ret; 430 - } 431 - 432 - val = LIS3L02DQ_REG_WAKE_UP_CFG_LATCH_SRC; 433 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 434 - LIS3L02DQ_REG_WAKE_UP_CFG_ADDR, 435 - val); 436 - if (ret) 437 - dev_err(&st->us->dev, "problem with interrupt cfg register"); 438 - err_ret: 439 - 440 - return ret; 441 - } 442 - 443 - static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, 444 - lis3l02dq_read_frequency, 445 - lis3l02dq_write_frequency); 446 - 447 - static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("280 560 1120 4480"); 448 - 449 - static irqreturn_t lis3l02dq_event_handler(int irq, void *private) 450 - { 451 - struct iio_dev *indio_dev = private; 452 - u8 t; 453 - 454 - s64 timestamp = iio_get_time_ns(); 455 - 456 - lis3l02dq_spi_read_reg_8(indio_dev, 457 - LIS3L02DQ_REG_WAKE_UP_SRC_ADDR, 458 - &t); 459 - 460 - if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Z_HIGH) 461 - iio_push_event(indio_dev, 462 - IIO_MOD_EVENT_CODE(IIO_ACCEL, 463 - 0, 464 - IIO_MOD_Z, 465 - IIO_EV_TYPE_THRESH, 466 - IIO_EV_DIR_RISING), 467 - timestamp); 468 - 469 - if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Z_LOW) 470 - iio_push_event(indio_dev, 471 - IIO_MOD_EVENT_CODE(IIO_ACCEL, 472 - 0, 473 - IIO_MOD_Z, 474 - IIO_EV_TYPE_THRESH, 475 - IIO_EV_DIR_FALLING), 476 - timestamp); 477 - 478 - if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Y_HIGH) 479 - iio_push_event(indio_dev, 480 - IIO_MOD_EVENT_CODE(IIO_ACCEL, 481 - 0, 482 - IIO_MOD_Y, 483 - IIO_EV_TYPE_THRESH, 484 - IIO_EV_DIR_RISING), 485 - timestamp); 486 - 487 - if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Y_LOW) 488 - iio_push_event(indio_dev, 489 - IIO_MOD_EVENT_CODE(IIO_ACCEL, 490 - 0, 491 - IIO_MOD_Y, 492 - IIO_EV_TYPE_THRESH, 493 - IIO_EV_DIR_FALLING), 494 - timestamp); 495 - 496 - if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_X_HIGH) 497 - iio_push_event(indio_dev, 498 - IIO_MOD_EVENT_CODE(IIO_ACCEL, 499 - 0, 500 - IIO_MOD_X, 501 - IIO_EV_TYPE_THRESH, 502 - IIO_EV_DIR_RISING), 503 - timestamp); 504 - 505 - if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_X_LOW) 506 - iio_push_event(indio_dev, 507 - IIO_MOD_EVENT_CODE(IIO_ACCEL, 508 - 0, 509 - IIO_MOD_X, 510 - IIO_EV_TYPE_THRESH, 511 - IIO_EV_DIR_FALLING), 512 - timestamp); 513 - 514 - /* Ack and allow for new interrupts */ 515 - lis3l02dq_spi_read_reg_8(indio_dev, 516 - LIS3L02DQ_REG_WAKE_UP_ACK_ADDR, 517 - &t); 518 - 519 - return IRQ_HANDLED; 520 - } 521 - 522 - static const struct iio_event_spec lis3l02dq_event[] = { 523 - { 524 - .type = IIO_EV_TYPE_THRESH, 525 - .dir = IIO_EV_DIR_RISING, 526 - .mask_separate = BIT(IIO_EV_INFO_ENABLE), 527 - .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE), 528 - }, { 529 - .type = IIO_EV_TYPE_THRESH, 530 - .dir = IIO_EV_DIR_FALLING, 531 - .mask_separate = BIT(IIO_EV_INFO_ENABLE), 532 - .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE), 533 - } 534 - }; 535 - 536 - #define LIS3L02DQ_CHAN(index, mod) \ 537 - { \ 538 - .type = IIO_ACCEL, \ 539 - .modified = 1, \ 540 - .channel2 = mod, \ 541 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 542 - BIT(IIO_CHAN_INFO_CALIBSCALE) | \ 543 - BIT(IIO_CHAN_INFO_CALIBBIAS), \ 544 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 545 - .address = index, \ 546 - .scan_index = index, \ 547 - .scan_type = { \ 548 - .sign = 's', \ 549 - .realbits = 12, \ 550 - .storagebits = 16, \ 551 - }, \ 552 - .event_spec = lis3l02dq_event, \ 553 - .num_event_specs = ARRAY_SIZE(lis3l02dq_event), \ 554 - } 555 - 556 - static const struct iio_chan_spec lis3l02dq_channels[] = { 557 - LIS3L02DQ_CHAN(0, IIO_MOD_X), 558 - LIS3L02DQ_CHAN(1, IIO_MOD_Y), 559 - LIS3L02DQ_CHAN(2, IIO_MOD_Z), 560 - IIO_CHAN_SOFT_TIMESTAMP(3) 561 - }; 562 - 563 - static int lis3l02dq_read_event_config(struct iio_dev *indio_dev, 564 - const struct iio_chan_spec *chan, 565 - enum iio_event_type type, 566 - enum iio_event_direction dir) 567 - { 568 - u8 val; 569 - int ret; 570 - u8 mask = 1 << (chan->channel2 * 2 + (dir == IIO_EV_DIR_RISING)); 571 - 572 - ret = lis3l02dq_spi_read_reg_8(indio_dev, 573 - LIS3L02DQ_REG_WAKE_UP_CFG_ADDR, 574 - &val); 575 - if (ret < 0) 576 - return ret; 577 - 578 - return !!(val & mask); 579 - } 580 - 581 - int lis3l02dq_disable_all_events(struct iio_dev *indio_dev) 582 - { 583 - int ret; 584 - u8 control, val; 585 - 586 - ret = lis3l02dq_spi_read_reg_8(indio_dev, 587 - LIS3L02DQ_REG_CTRL_2_ADDR, 588 - &control); 589 - 590 - control &= ~LIS3L02DQ_REG_CTRL_2_ENABLE_INTERRUPT; 591 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 592 - LIS3L02DQ_REG_CTRL_2_ADDR, 593 - control); 594 - if (ret) 595 - goto error_ret; 596 - /* Also for consistency clear the mask */ 597 - ret = lis3l02dq_spi_read_reg_8(indio_dev, 598 - LIS3L02DQ_REG_WAKE_UP_CFG_ADDR, 599 - &val); 600 - if (ret) 601 - goto error_ret; 602 - val &= ~0x3f; 603 - 604 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 605 - LIS3L02DQ_REG_WAKE_UP_CFG_ADDR, 606 - val); 607 - if (ret) 608 - goto error_ret; 609 - 610 - ret = control; 611 - error_ret: 612 - return ret; 613 - } 614 - 615 - static int lis3l02dq_write_event_config(struct iio_dev *indio_dev, 616 - const struct iio_chan_spec *chan, 617 - enum iio_event_type type, 618 - enum iio_event_direction dir, 619 - int state) 620 - { 621 - int ret = 0; 622 - u8 val, control; 623 - u8 currentlyset; 624 - bool changed = false; 625 - u8 mask = 1 << (chan->channel2 * 2 + (dir == IIO_EV_DIR_RISING)); 626 - 627 - mutex_lock(&indio_dev->mlock); 628 - /* read current control */ 629 - ret = lis3l02dq_spi_read_reg_8(indio_dev, 630 - LIS3L02DQ_REG_CTRL_2_ADDR, 631 - &control); 632 - if (ret) 633 - goto error_ret; 634 - ret = lis3l02dq_spi_read_reg_8(indio_dev, 635 - LIS3L02DQ_REG_WAKE_UP_CFG_ADDR, 636 - &val); 637 - if (ret < 0) 638 - goto error_ret; 639 - currentlyset = val & mask; 640 - 641 - if (!currentlyset && state) { 642 - changed = true; 643 - val |= mask; 644 - } else if (currentlyset && !state) { 645 - changed = true; 646 - val &= ~mask; 647 - } 648 - 649 - if (changed) { 650 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 651 - LIS3L02DQ_REG_WAKE_UP_CFG_ADDR, 652 - val); 653 - if (ret) 654 - goto error_ret; 655 - control = val & 0x3f ? 656 - (control | LIS3L02DQ_REG_CTRL_2_ENABLE_INTERRUPT) : 657 - (control & ~LIS3L02DQ_REG_CTRL_2_ENABLE_INTERRUPT); 658 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 659 - LIS3L02DQ_REG_CTRL_2_ADDR, 660 - control); 661 - if (ret) 662 - goto error_ret; 663 - } 664 - 665 - error_ret: 666 - mutex_unlock(&indio_dev->mlock); 667 - return ret; 668 - } 669 - 670 - static struct attribute *lis3l02dq_attributes[] = { 671 - &iio_dev_attr_sampling_frequency.dev_attr.attr, 672 - &iio_const_attr_sampling_frequency_available.dev_attr.attr, 673 - NULL 674 - }; 675 - 676 - static const struct attribute_group lis3l02dq_attribute_group = { 677 - .attrs = lis3l02dq_attributes, 678 - }; 679 - 680 - static const struct iio_info lis3l02dq_info = { 681 - .read_raw = &lis3l02dq_read_raw, 682 - .write_raw = &lis3l02dq_write_raw, 683 - .read_event_value = &lis3l02dq_read_thresh, 684 - .write_event_value = &lis3l02dq_write_thresh, 685 - .write_event_config = &lis3l02dq_write_event_config, 686 - .read_event_config = &lis3l02dq_read_event_config, 687 - .driver_module = THIS_MODULE, 688 - .attrs = &lis3l02dq_attribute_group, 689 - }; 690 - 691 - static int lis3l02dq_probe(struct spi_device *spi) 692 - { 693 - int ret; 694 - struct lis3l02dq_state *st; 695 - struct iio_dev *indio_dev; 696 - 697 - indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 698 - if (!indio_dev) 699 - return -ENOMEM; 700 - st = iio_priv(indio_dev); 701 - /* this is only used for removal purposes */ 702 - spi_set_drvdata(spi, indio_dev); 703 - 704 - st->us = spi; 705 - st->gpio = of_get_gpio(spi->dev.of_node, 0); 706 - mutex_init(&st->buf_lock); 707 - indio_dev->name = spi->dev.driver->name; 708 - indio_dev->dev.parent = &spi->dev; 709 - indio_dev->info = &lis3l02dq_info; 710 - indio_dev->channels = lis3l02dq_channels; 711 - indio_dev->num_channels = ARRAY_SIZE(lis3l02dq_channels); 712 - 713 - indio_dev->modes = INDIO_DIRECT_MODE; 714 - 715 - ret = lis3l02dq_configure_buffer(indio_dev); 716 - if (ret) 717 - return ret; 718 - 719 - if (spi->irq) { 720 - ret = request_threaded_irq(st->us->irq, 721 - &lis3l02dq_th, 722 - &lis3l02dq_event_handler, 723 - IRQF_TRIGGER_RISING, 724 - "lis3l02dq", 725 - indio_dev); 726 - if (ret) 727 - goto error_unreg_buffer_funcs; 728 - 729 - ret = lis3l02dq_probe_trigger(indio_dev); 730 - if (ret) 731 - goto error_free_interrupt; 732 - } 733 - 734 - /* Get the device into a sane initial state */ 735 - ret = lis3l02dq_initial_setup(indio_dev); 736 - if (ret) 737 - goto error_remove_trigger; 738 - 739 - ret = iio_device_register(indio_dev); 740 - if (ret) 741 - goto error_remove_trigger; 742 - 743 - return 0; 744 - 745 - error_remove_trigger: 746 - if (spi->irq) 747 - lis3l02dq_remove_trigger(indio_dev); 748 - error_free_interrupt: 749 - if (spi->irq) 750 - free_irq(st->us->irq, indio_dev); 751 - error_unreg_buffer_funcs: 752 - lis3l02dq_unconfigure_buffer(indio_dev); 753 - return ret; 754 - } 755 - 756 - /* Power down the device */ 757 - static int lis3l02dq_stop_device(struct iio_dev *indio_dev) 758 - { 759 - int ret; 760 - struct lis3l02dq_state *st = iio_priv(indio_dev); 761 - u8 val = 0; 762 - 763 - mutex_lock(&indio_dev->mlock); 764 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 765 - LIS3L02DQ_REG_CTRL_1_ADDR, 766 - val); 767 - if (ret) { 768 - dev_err(&st->us->dev, "problem with turning device off: ctrl1"); 769 - goto err_ret; 770 - } 771 - 772 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 773 - LIS3L02DQ_REG_CTRL_2_ADDR, 774 - val); 775 - if (ret) 776 - dev_err(&st->us->dev, "problem with turning device off: ctrl2"); 777 - err_ret: 778 - mutex_unlock(&indio_dev->mlock); 779 - return ret; 780 - } 781 - 782 - /* fixme, confirm ordering in this function */ 783 - static int lis3l02dq_remove(struct spi_device *spi) 784 - { 785 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 786 - struct lis3l02dq_state *st = iio_priv(indio_dev); 787 - 788 - iio_device_unregister(indio_dev); 789 - 790 - lis3l02dq_disable_all_events(indio_dev); 791 - lis3l02dq_stop_device(indio_dev); 792 - 793 - if (spi->irq) 794 - free_irq(st->us->irq, indio_dev); 795 - 796 - lis3l02dq_remove_trigger(indio_dev); 797 - lis3l02dq_unconfigure_buffer(indio_dev); 798 - 799 - return 0; 800 - } 801 - 802 - static struct spi_driver lis3l02dq_driver = { 803 - .driver = { 804 - .name = "lis3l02dq", 805 - }, 806 - .probe = lis3l02dq_probe, 807 - .remove = lis3l02dq_remove, 808 - }; 809 - module_spi_driver(lis3l02dq_driver); 810 - 811 - MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>"); 812 - MODULE_DESCRIPTION("ST LIS3L02DQ Accelerometer SPI driver"); 813 - MODULE_LICENSE("GPL v2"); 814 - MODULE_ALIAS("spi:lis3l02dq");
-428
drivers/staging/iio/accel/lis3l02dq_ring.c
··· 1 - #include <linux/interrupt.h> 2 - #include <linux/gpio.h> 3 - #include <linux/mutex.h> 4 - #include <linux/kernel.h> 5 - #include <linux/spi/spi.h> 6 - #include <linux/slab.h> 7 - #include <linux/export.h> 8 - 9 - #include <linux/iio/iio.h> 10 - #include <linux/iio/kfifo_buf.h> 11 - #include <linux/iio/trigger.h> 12 - #include <linux/iio/trigger_consumer.h> 13 - #include "lis3l02dq.h" 14 - 15 - /** 16 - * combine_8_to_16() utility function to munge two u8s into u16 17 - **/ 18 - static inline u16 combine_8_to_16(u8 lower, u8 upper) 19 - { 20 - u16 _lower = lower; 21 - u16 _upper = upper; 22 - 23 - return _lower | (_upper << 8); 24 - } 25 - 26 - /** 27 - * lis3l02dq_data_rdy_trig_poll() the event handler for the data rdy trig 28 - **/ 29 - irqreturn_t lis3l02dq_data_rdy_trig_poll(int irq, void *private) 30 - { 31 - struct iio_dev *indio_dev = private; 32 - struct lis3l02dq_state *st = iio_priv(indio_dev); 33 - 34 - if (st->trigger_on) { 35 - iio_trigger_poll(st->trig); 36 - return IRQ_HANDLED; 37 - } 38 - 39 - return IRQ_WAKE_THREAD; 40 - } 41 - 42 - static const u8 read_all_tx_array[] = { 43 - LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_X_L_ADDR), 0, 44 - LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_X_H_ADDR), 0, 45 - LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_Y_L_ADDR), 0, 46 - LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_Y_H_ADDR), 0, 47 - LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_Z_L_ADDR), 0, 48 - LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_Z_H_ADDR), 0, 49 - }; 50 - 51 - /** 52 - * lis3l02dq_read_all() Reads all channels currently selected 53 - * @indio_dev: IIO device state 54 - * @rx_array: (dma capable) receive array, must be at least 55 - * 4*number of channels 56 - **/ 57 - static int lis3l02dq_read_all(struct iio_dev *indio_dev, u8 *rx_array) 58 - { 59 - struct lis3l02dq_state *st = iio_priv(indio_dev); 60 - struct spi_transfer *xfers; 61 - struct spi_message msg; 62 - int ret, i, j = 0; 63 - 64 - xfers = kcalloc(bitmap_weight(indio_dev->active_scan_mask, 65 - indio_dev->masklength) * 2, 66 - sizeof(*xfers), GFP_KERNEL); 67 - if (!xfers) 68 - return -ENOMEM; 69 - 70 - mutex_lock(&st->buf_lock); 71 - 72 - for (i = 0; i < ARRAY_SIZE(read_all_tx_array) / 4; i++) 73 - if (test_bit(i, indio_dev->active_scan_mask)) { 74 - /* lower byte */ 75 - xfers[j].tx_buf = st->tx + (2 * j); 76 - st->tx[2 * j] = read_all_tx_array[i * 4]; 77 - st->tx[2 * j + 1] = 0; 78 - if (rx_array) 79 - xfers[j].rx_buf = rx_array + (j * 2); 80 - xfers[j].bits_per_word = 8; 81 - xfers[j].len = 2; 82 - xfers[j].cs_change = 1; 83 - j++; 84 - 85 - /* upper byte */ 86 - xfers[j].tx_buf = st->tx + (2 * j); 87 - st->tx[2 * j] = read_all_tx_array[i * 4 + 2]; 88 - st->tx[2 * j + 1] = 0; 89 - if (rx_array) 90 - xfers[j].rx_buf = rx_array + (j * 2); 91 - xfers[j].bits_per_word = 8; 92 - xfers[j].len = 2; 93 - xfers[j].cs_change = 1; 94 - j++; 95 - } 96 - 97 - /* After these are transmitted, the rx_buff should have 98 - * values in alternate bytes 99 - */ 100 - spi_message_init(&msg); 101 - for (j = 0; j < bitmap_weight(indio_dev->active_scan_mask, 102 - indio_dev->masklength) * 2; j++) 103 - spi_message_add_tail(&xfers[j], &msg); 104 - 105 - ret = spi_sync(st->us, &msg); 106 - mutex_unlock(&st->buf_lock); 107 - kfree(xfers); 108 - 109 - return ret; 110 - } 111 - 112 - static int lis3l02dq_get_buffer_element(struct iio_dev *indio_dev, 113 - u8 *buf) 114 - { 115 - int ret, i; 116 - u8 *rx_array; 117 - s16 *data = (s16 *)buf; 118 - int scan_count = bitmap_weight(indio_dev->active_scan_mask, 119 - indio_dev->masklength); 120 - 121 - rx_array = kcalloc(4, scan_count, GFP_KERNEL); 122 - if (!rx_array) 123 - return -ENOMEM; 124 - ret = lis3l02dq_read_all(indio_dev, rx_array); 125 - if (ret < 0) { 126 - kfree(rx_array); 127 - return ret; 128 - } 129 - for (i = 0; i < scan_count; i++) 130 - data[i] = combine_8_to_16(rx_array[i * 4 + 1], 131 - rx_array[i * 4 + 3]); 132 - kfree(rx_array); 133 - 134 - return i * sizeof(data[0]); 135 - } 136 - 137 - static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p) 138 - { 139 - struct iio_poll_func *pf = p; 140 - struct iio_dev *indio_dev = pf->indio_dev; 141 - int len = 0; 142 - char *data; 143 - 144 - data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); 145 - if (!data) 146 - goto done; 147 - 148 - if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) 149 - len = lis3l02dq_get_buffer_element(indio_dev, data); 150 - 151 - iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp); 152 - 153 - kfree(data); 154 - done: 155 - iio_trigger_notify_done(indio_dev->trig); 156 - return IRQ_HANDLED; 157 - } 158 - 159 - /* Caller responsible for locking as necessary. */ 160 - static int 161 - __lis3l02dq_write_data_ready_config(struct iio_dev *indio_dev, bool state) 162 - { 163 - int ret; 164 - u8 valold; 165 - bool currentlyset; 166 - struct lis3l02dq_state *st = iio_priv(indio_dev); 167 - 168 - /* Get the current event mask register */ 169 - ret = lis3l02dq_spi_read_reg_8(indio_dev, 170 - LIS3L02DQ_REG_CTRL_2_ADDR, 171 - &valold); 172 - if (ret) 173 - goto error_ret; 174 - /* Find out if data ready is already on */ 175 - currentlyset 176 - = valold & LIS3L02DQ_REG_CTRL_2_ENABLE_DATA_READY_GENERATION; 177 - 178 - /* Disable requested */ 179 - if (!state && currentlyset) { 180 - /* Disable the data ready signal */ 181 - valold &= ~LIS3L02DQ_REG_CTRL_2_ENABLE_DATA_READY_GENERATION; 182 - 183 - /* The double write is to overcome a hardware bug? */ 184 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 185 - LIS3L02DQ_REG_CTRL_2_ADDR, 186 - valold); 187 - if (ret) 188 - goto error_ret; 189 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 190 - LIS3L02DQ_REG_CTRL_2_ADDR, 191 - valold); 192 - if (ret) 193 - goto error_ret; 194 - st->trigger_on = false; 195 - /* Enable requested */ 196 - } else if (state && !currentlyset) { 197 - /* If not set, enable requested 198 - * first disable all events 199 - */ 200 - ret = lis3l02dq_disable_all_events(indio_dev); 201 - if (ret < 0) 202 - goto error_ret; 203 - 204 - valold = ret | 205 - LIS3L02DQ_REG_CTRL_2_ENABLE_DATA_READY_GENERATION; 206 - 207 - st->trigger_on = true; 208 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 209 - LIS3L02DQ_REG_CTRL_2_ADDR, 210 - valold); 211 - if (ret) 212 - goto error_ret; 213 - } 214 - 215 - return 0; 216 - error_ret: 217 - return ret; 218 - } 219 - 220 - /** 221 - * lis3l02dq_data_rdy_trigger_set_state() set datardy interrupt state 222 - * 223 - * If disabling the interrupt also does a final read to ensure it is clear. 224 - * This is only important in some cases where the scan enable elements are 225 - * switched before the buffer is reenabled. 226 - **/ 227 - static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig, 228 - bool state) 229 - { 230 - struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 231 - int ret = 0; 232 - u8 t; 233 - 234 - __lis3l02dq_write_data_ready_config(indio_dev, state); 235 - if (!state) { 236 - /* 237 - * A possible quirk with the handler is currently worked around 238 - * by ensuring outstanding read events are cleared. 239 - */ 240 - ret = lis3l02dq_read_all(indio_dev, NULL); 241 - } 242 - lis3l02dq_spi_read_reg_8(indio_dev, 243 - LIS3L02DQ_REG_WAKE_UP_SRC_ADDR, 244 - &t); 245 - return ret; 246 - } 247 - 248 - /** 249 - * lis3l02dq_trig_try_reen() try reenabling irq for data rdy trigger 250 - * @trig: the datardy trigger 251 - */ 252 - static int lis3l02dq_trig_try_reen(struct iio_trigger *trig) 253 - { 254 - struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 255 - struct lis3l02dq_state *st = iio_priv(indio_dev); 256 - int i; 257 - 258 - /* If gpio still high (or high again) 259 - * In theory possible we will need to do this several times 260 - */ 261 - for (i = 0; i < 5; i++) 262 - if (gpio_get_value(st->gpio)) 263 - lis3l02dq_read_all(indio_dev, NULL); 264 - else 265 - break; 266 - if (i == 5) 267 - pr_info("Failed to clear the interrupt for lis3l02dq\n"); 268 - 269 - /* irq reenabled so success! */ 270 - return 0; 271 - } 272 - 273 - static const struct iio_trigger_ops lis3l02dq_trigger_ops = { 274 - .owner = THIS_MODULE, 275 - .set_trigger_state = &lis3l02dq_data_rdy_trigger_set_state, 276 - .try_reenable = &lis3l02dq_trig_try_reen, 277 - }; 278 - 279 - int lis3l02dq_probe_trigger(struct iio_dev *indio_dev) 280 - { 281 - int ret; 282 - struct lis3l02dq_state *st = iio_priv(indio_dev); 283 - 284 - st->trig = iio_trigger_alloc("lis3l02dq-dev%d", indio_dev->id); 285 - if (!st->trig) { 286 - ret = -ENOMEM; 287 - goto error_ret; 288 - } 289 - 290 - st->trig->dev.parent = &st->us->dev; 291 - st->trig->ops = &lis3l02dq_trigger_ops; 292 - iio_trigger_set_drvdata(st->trig, indio_dev); 293 - ret = iio_trigger_register(st->trig); 294 - if (ret) 295 - goto error_free_trig; 296 - 297 - return 0; 298 - 299 - error_free_trig: 300 - iio_trigger_free(st->trig); 301 - error_ret: 302 - return ret; 303 - } 304 - 305 - void lis3l02dq_remove_trigger(struct iio_dev *indio_dev) 306 - { 307 - struct lis3l02dq_state *st = iio_priv(indio_dev); 308 - 309 - iio_trigger_unregister(st->trig); 310 - iio_trigger_free(st->trig); 311 - } 312 - 313 - void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev) 314 - { 315 - iio_dealloc_pollfunc(indio_dev->pollfunc); 316 - iio_kfifo_free(indio_dev->buffer); 317 - } 318 - 319 - static int lis3l02dq_buffer_postenable(struct iio_dev *indio_dev) 320 - { 321 - /* Disable unwanted channels otherwise the interrupt will not clear */ 322 - u8 t; 323 - int ret; 324 - bool oneenabled = false; 325 - 326 - ret = lis3l02dq_spi_read_reg_8(indio_dev, 327 - LIS3L02DQ_REG_CTRL_1_ADDR, 328 - &t); 329 - if (ret) 330 - goto error_ret; 331 - 332 - if (test_bit(0, indio_dev->active_scan_mask)) { 333 - t |= LIS3L02DQ_REG_CTRL_1_AXES_X_ENABLE; 334 - oneenabled = true; 335 - } else { 336 - t &= ~LIS3L02DQ_REG_CTRL_1_AXES_X_ENABLE; 337 - } 338 - if (test_bit(1, indio_dev->active_scan_mask)) { 339 - t |= LIS3L02DQ_REG_CTRL_1_AXES_Y_ENABLE; 340 - oneenabled = true; 341 - } else { 342 - t &= ~LIS3L02DQ_REG_CTRL_1_AXES_Y_ENABLE; 343 - } 344 - if (test_bit(2, indio_dev->active_scan_mask)) { 345 - t |= LIS3L02DQ_REG_CTRL_1_AXES_Z_ENABLE; 346 - oneenabled = true; 347 - } else { 348 - t &= ~LIS3L02DQ_REG_CTRL_1_AXES_Z_ENABLE; 349 - } 350 - if (!oneenabled) /* what happens in this case is unknown */ 351 - return -EINVAL; 352 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 353 - LIS3L02DQ_REG_CTRL_1_ADDR, 354 - t); 355 - if (ret) 356 - goto error_ret; 357 - 358 - return iio_triggered_buffer_postenable(indio_dev); 359 - error_ret: 360 - return ret; 361 - } 362 - 363 - /* Turn all channels on again */ 364 - static int lis3l02dq_buffer_predisable(struct iio_dev *indio_dev) 365 - { 366 - u8 t; 367 - int ret; 368 - 369 - ret = iio_triggered_buffer_predisable(indio_dev); 370 - if (ret) 371 - goto error_ret; 372 - 373 - ret = lis3l02dq_spi_read_reg_8(indio_dev, 374 - LIS3L02DQ_REG_CTRL_1_ADDR, 375 - &t); 376 - if (ret) 377 - goto error_ret; 378 - t |= LIS3L02DQ_REG_CTRL_1_AXES_X_ENABLE | 379 - LIS3L02DQ_REG_CTRL_1_AXES_Y_ENABLE | 380 - LIS3L02DQ_REG_CTRL_1_AXES_Z_ENABLE; 381 - 382 - ret = lis3l02dq_spi_write_reg_8(indio_dev, 383 - LIS3L02DQ_REG_CTRL_1_ADDR, 384 - t); 385 - 386 - error_ret: 387 - return ret; 388 - } 389 - 390 - static const struct iio_buffer_setup_ops lis3l02dq_buffer_setup_ops = { 391 - .postenable = &lis3l02dq_buffer_postenable, 392 - .predisable = &lis3l02dq_buffer_predisable, 393 - }; 394 - 395 - int lis3l02dq_configure_buffer(struct iio_dev *indio_dev) 396 - { 397 - int ret; 398 - struct iio_buffer *buffer; 399 - 400 - buffer = iio_kfifo_allocate(); 401 - if (!buffer) 402 - return -ENOMEM; 403 - 404 - iio_device_attach_buffer(indio_dev, buffer); 405 - 406 - buffer->scan_timestamp = true; 407 - indio_dev->setup_ops = &lis3l02dq_buffer_setup_ops; 408 - 409 - /* Functions are NULL as we set handler below */ 410 - indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time, 411 - &lis3l02dq_trigger_handler, 412 - 0, 413 - indio_dev, 414 - "lis3l02dq_consumer%d", 415 - indio_dev->id); 416 - 417 - if (!indio_dev->pollfunc) { 418 - ret = -ENOMEM; 419 - goto error_iio_sw_rb_free; 420 - } 421 - 422 - indio_dev->modes |= INDIO_BUFFER_TRIGGERED; 423 - return 0; 424 - 425 - error_iio_sw_rb_free: 426 - iio_kfifo_free(indio_dev->buffer); 427 - return ret; 428 - }
+1 -1
drivers/staging/iio/accel/sca3000_core.c
··· 774 774 struct iio_dev *indio_dev = private; 775 775 struct sca3000_state *st = iio_priv(indio_dev); 776 776 int ret, val; 777 - s64 last_timestamp = iio_get_time_ns(); 777 + s64 last_timestamp = iio_get_time_ns(indio_dev); 778 778 779 779 /* 780 780 * Could lead if badly timed to an extra read of status reg,
+4 -4
drivers/staging/iio/adc/ad7280a.c
··· 705 705 IIO_EV_DIR_RISING, 706 706 IIO_EV_TYPE_THRESH, 707 707 0, 0, 0), 708 - iio_get_time_ns()); 708 + iio_get_time_ns(indio_dev)); 709 709 else if (((channels[i] >> 11) & 0xFFF) <= 710 710 st->cell_threshlow) 711 711 iio_push_event(indio_dev, ··· 715 715 IIO_EV_DIR_FALLING, 716 716 IIO_EV_TYPE_THRESH, 717 717 0, 0, 0), 718 - iio_get_time_ns()); 718 + iio_get_time_ns(indio_dev)); 719 719 } else { 720 720 if (((channels[i] >> 11) & 0xFFF) >= st->aux_threshhigh) 721 721 iio_push_event(indio_dev, ··· 724 724 0, 725 725 IIO_EV_TYPE_THRESH, 726 726 IIO_EV_DIR_RISING), 727 - iio_get_time_ns()); 727 + iio_get_time_ns(indio_dev)); 728 728 else if (((channels[i] >> 11) & 0xFFF) <= 729 729 st->aux_threshlow) 730 730 iio_push_event(indio_dev, ··· 733 733 0, 734 734 IIO_EV_TYPE_THRESH, 735 735 IIO_EV_DIR_FALLING), 736 - iio_get_time_ns()); 736 + iio_get_time_ns(indio_dev)); 737 737 } 738 738 } 739 739
+2 -1
drivers/staging/iio/adc/ad7606_ring.c
··· 77 77 goto done; 78 78 } 79 79 80 - iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns()); 80 + iio_push_to_buffers_with_timestamp(indio_dev, buf, 81 + iio_get_time_ns(indio_dev)); 81 82 done: 82 83 gpio_set_value(st->pdata->gpio_convst, 0); 83 84 iio_trigger_notify_done(indio_dev->trig);
+2 -1
drivers/staging/iio/adc/ad7816.c
··· 253 253 254 254 static irqreturn_t ad7816_event_handler(int irq, void *private) 255 255 { 256 - iio_push_event(private, IIO_EVENT_CODE_AD7816_OTI, iio_get_time_ns()); 256 + iio_push_event(private, IIO_EVENT_CODE_AD7816_OTI, 257 + iio_get_time_ns((struct iio_dev *)private)); 257 258 return IRQ_HANDLED; 258 259 } 259 260
+2 -2
drivers/staging/iio/addac/adt7316.c
··· 1752 1752 if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX) 1753 1753 stat1 &= 0x1F; 1754 1754 1755 - time = iio_get_time_ns(); 1755 + time = iio_get_time_ns(indio_dev); 1756 1756 if (stat1 & BIT(0)) 1757 1757 iio_push_event(indio_dev, 1758 1758 IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0, ··· 1804 1804 0, 1805 1805 IIO_EV_TYPE_THRESH, 1806 1806 IIO_EV_DIR_RISING), 1807 - iio_get_time_ns()); 1807 + iio_get_time_ns(indio_dev)); 1808 1808 } 1809 1809 1810 1810 return IRQ_HANDLED;
+1 -1
drivers/staging/iio/cdc/ad7150.c
··· 493 493 struct iio_dev *indio_dev = private; 494 494 struct ad7150_chip_info *chip = iio_priv(indio_dev); 495 495 u8 int_status; 496 - s64 timestamp = iio_get_time_ns(); 496 + s64 timestamp = iio_get_time_ns(indio_dev); 497 497 int ret; 498 498 499 499 ret = i2c_smbus_read_byte_data(chip->client, AD7150_STATUS);
+1 -1
drivers/staging/iio/light/tsl2x7x_core.c
··· 1554 1554 { 1555 1555 struct iio_dev *indio_dev = private; 1556 1556 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 1557 - s64 timestamp = iio_get_time_ns(); 1557 + s64 timestamp = iio_get_time_ns(indio_dev); 1558 1558 int ret; 1559 1559 u8 value; 1560 1560
+2
include/linux/iio/common/st_sensors.h
··· 223 223 * @get_irq_data_ready: Function to get the IRQ used for data ready signal. 224 224 * @tf: Transfer function structure used by I/O operations. 225 225 * @tb: Transfer buffers and mutex used by I/O operations. 226 + * @edge_irq: the IRQ triggers on edges and need special handling. 226 227 * @hw_irq_trigger: if we're using the hardware interrupt on the sensor. 227 228 * @hw_timestamp: Latest timestamp from the interrupt handler, when in use. 228 229 */ ··· 251 250 const struct st_sensor_transfer_function *tf; 252 251 struct st_sensor_transfer_buffer tb; 253 252 253 + bool edge_irq; 254 254 bool hw_irq_trigger; 255 255 s64 hw_timestamp; 256 256 };
+14 -8
include/linux/iio/iio.h
··· 312 312 }, \ 313 313 } 314 314 315 - /** 316 - * iio_get_time_ns() - utility function to get a time stamp for events etc 317 - **/ 318 - static inline s64 iio_get_time_ns(void) 319 - { 320 - return ktime_get_real_ns(); 321 - } 315 + s64 iio_get_time_ns(const struct iio_dev *indio_dev); 316 + unsigned int iio_get_time_res(const struct iio_dev *indio_dev); 322 317 323 318 /* Device operating modes */ 324 319 #define INDIO_DIRECT_MODE 0x01 ··· 492 497 * @chan_attr_group: [INTERN] group for all attrs in base directory 493 498 * @name: [DRIVER] name of the device. 494 499 * @info: [DRIVER] callbacks and constant info from driver 500 + * @clock_id: [INTERN] timestamping clock posix identifier 495 501 * @info_exist_lock: [INTERN] lock to prevent use during removal 496 502 * @setup_ops: [DRIVER] callbacks to call before and after buffer 497 503 * enable/disable ··· 533 537 struct attribute_group chan_attr_group; 534 538 const char *name; 535 539 const struct iio_info *info; 540 + clockid_t clock_id; 536 541 struct mutex info_exist_lock; 537 542 const struct iio_buffer_setup_ops *setup_ops; 538 543 struct cdev chrdev; ··· 562 565 563 566 /** 564 567 * iio_device_put() - reference counted deallocation of struct device 565 - * @indio_dev: IIO device structure containing the device 568 + * @indio_dev: IIO device structure containing the device 566 569 **/ 567 570 static inline void iio_device_put(struct iio_dev *indio_dev) 568 571 { 569 572 if (indio_dev) 570 573 put_device(&indio_dev->dev); 574 + } 575 + 576 + /** 577 + * iio_device_get_clock() - Retrieve current timestamping clock for the device 578 + * @indio_dev: IIO device structure containing the device 579 + */ 580 + static inline clockid_t iio_device_get_clock(const struct iio_dev *indio_dev) 581 + { 582 + return indio_dev->clock_id; 571 583 } 572 584 573 585 /**
+1
kernel/time/timekeeping.c
··· 2186 2186 2187 2187 return now; 2188 2188 } 2189 + EXPORT_SYMBOL(get_monotonic_coarse64); 2189 2190 2190 2191 /* 2191 2192 * Must hold jiffies_lock