aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.mailmap3
-rw-r--r--Documentation/devicetree/bindings/iio/dac/ad5755.txt124
-rw-r--r--drivers/iio/accel/Kconfig4
-rw-r--r--drivers/iio/accel/mma8452.c24
-rw-r--r--drivers/iio/adc/ti-adc081c.c26
-rw-r--r--drivers/iio/buffer/industrialio-buffer-dma.c4
-rw-r--r--drivers/iio/dac/Kconfig9
-rw-r--r--drivers/iio/dac/ad5755.c188
-rw-r--r--drivers/iio/dac/stx104.c125
-rw-r--r--drivers/iio/industrialio-trigger.c22
-rw-r--r--drivers/iio/light/gp2ap020a00f.c18
-rw-r--r--drivers/iio/light/isl29125.c10
-rw-r--r--drivers/iio/light/tcs3414.c12
-rw-r--r--drivers/iio/light/tcs3472.c13
-rw-r--r--drivers/iio/pressure/ms5637.c12
-rw-r--r--drivers/iio/proximity/as3935.c11
-rw-r--r--drivers/iio/proximity/pulsedlight-lidar-lite-v2.c14
-rw-r--r--drivers/staging/iio/accel/sca3000_core.c2
-rw-r--r--tools/iio/iio_generic_buffer.c4
19 files changed, 549 insertions, 76 deletions
diff --git a/.mailmap b/.mailmap
index 779a9caadc7f..6c3d82dae24a 100644
--- a/.mailmap
+++ b/.mailmap
@@ -11,6 +11,7 @@ Aaron Durbin <adurbin@google.com>
11Adam Oldham <oldhamca@gmail.com> 11Adam Oldham <oldhamca@gmail.com>
12Adam Radford <aradford@gmail.com> 12Adam Radford <aradford@gmail.com>
13Adrian Bunk <bunk@stusta.de> 13Adrian Bunk <bunk@stusta.de>
14Adriana Reus <adi.reus@gmail.com> <adriana.reus@intel.com>
14Alan Cox <alan@lxorguk.ukuu.org.uk> 15Alan Cox <alan@lxorguk.ukuu.org.uk>
15Alan Cox <root@hraefn.swansea.linux.org.uk> 16Alan Cox <root@hraefn.swansea.linux.org.uk>
16Aleksey Gorelov <aleksey_gorelov@phoenix.com> 17Aleksey Gorelov <aleksey_gorelov@phoenix.com>
@@ -90,6 +91,8 @@ Linas Vepstas <linas@austin.ibm.com>
90Mark Brown <broonie@sirena.org.uk> 91Mark Brown <broonie@sirena.org.uk>
91Matthieu CASTET <castet.matthieu@free.fr> 92Matthieu CASTET <castet.matthieu@free.fr>
92Mauro Carvalho Chehab <mchehab@kernel.org> <maurochehab@gmail.com> <mchehab@infradead.org> <mchehab@redhat.com> <m.chehab@samsung.com> <mchehab@osg.samsung.com> <mchehab@s-opensource.com> 93Mauro Carvalho Chehab <mchehab@kernel.org> <maurochehab@gmail.com> <mchehab@infradead.org> <mchehab@redhat.com> <m.chehab@samsung.com> <mchehab@osg.samsung.com> <mchehab@s-opensource.com>
94Matt Ranostay <mranostay@gmail.com> Matthew Ranostay <mranostay@embeddedalley.com>
95Matt Ranostay <mranostay@gmail.com> <matt.ranostay@intel.com>
93Mayuresh Janorkar <mayur@ti.com> 96Mayuresh Janorkar <mayur@ti.com>
94Michael Buesch <m@bues.ch> 97Michael Buesch <m@bues.ch>
95Michel Dänzer <michel@tungstengraphics.com> 98Michel Dänzer <michel@tungstengraphics.com>
diff --git a/Documentation/devicetree/bindings/iio/dac/ad5755.txt b/Documentation/devicetree/bindings/iio/dac/ad5755.txt
new file mode 100644
index 000000000000..f0bbd7e1029b
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/dac/ad5755.txt
@@ -0,0 +1,124 @@
1* Analog Device AD5755 IIO Multi-Channel DAC Linux Driver
2
3Required properties:
4 - compatible: Has to contain one of the following:
5 adi,ad5755
6 adi,ad5755-1
7 adi,ad5757
8 adi,ad5735
9 adi,ad5737
10
11 - reg: spi chip select number for the device
12 - spi-cpha or spi-cpol: is the only modes that is supported
13
14Recommended properties:
15 - spi-max-frequency: Definition as per
16 Documentation/devicetree/bindings/spi/spi-bus.txt
17
18Optional properties:
19See include/dt-bindings/iio/ad5755.h
20 - adi,ext-dc-dc-compenstation-resistor: boolean set if the hardware have an
21 external resistor and thereby bypasses
22 the internal compensation resistor.
23 - adi,dc-dc-phase:
24 Valid values for DC DC Phase control is:
25 0: All dc-to-dc converters clock on the same edge.
26 1: Channel A and Channel B clock on the same edge,
27 Channel C and Channel D clock on opposite edges.
28 2: Channel A and Channel C clock on the same edge,
29 Channel B and Channel D clock on opposite edges.
30 3: Channel A, Channel B, Channel C, and Channel D
31 clock 90 degrees out of phase from each other.
32 - adi,dc-dc-freq-hz:
33 Valid values for DC DC frequency is [Hz]:
34 250000
35 410000
36 650000
37 - adi,dc-dc-max-microvolt:
38 Valid values for the maximum allowed Vboost voltage supplied by
39 the dc-to-dc converter is:
40 23000000
41 24500000
42 27000000
43 29500000
44
45Optional for every channel:
46 - adi,mode:
47 Valid values for DAC modes is:
48 0: 0 V to 5 V voltage range.
49 1: 0 V to 10 V voltage range.
50 2: Plus minus 5 V voltage range.
51 3: Plus minus 10 V voltage range.
52 4: 4 mA to 20 mA current range.
53 5: 0 mA to 20 mA current range.
54 6: 0 mA to 24 mA current range.
55 - adi,ext-current-sense-resistor: boolean set if the hardware a external
56 current sense resistor.
57 - adi,enable-voltage-overrange: boolean enable voltage overrange
58 - adi,slew: Array of slewrate settings should contain 3 fields:
59 1: Should be either 0 or 1 in order to enable or disable slewrate.
60 2: Slew rate settings:
61 Valid values for the slew rate update frequency:
62 64000
63 32000
64 16000
65 8000
66 4000
67 2000
68 1000
69 500
70 250
71 125
72 64
73 32
74 16
75 8
76 4
77 0
78 3: Slew step size:
79 Valid values for the step size LSBs:
80 1
81 2
82 4
83 16
84 32
85 64
86 128
87 256
88
89Example:
90dac@0 {
91 #address-cells = <1>;
92 #size-cells = <0>;
93 compatible = "adi,ad5755";
94 reg = <0>;
95 spi-max-frequency = <1000000>;
96 spi-cpha;
97 adi,dc-dc-phase = <0>;
98 adi,dc-dc-freq-hz = <410000>;
99 adi,dc-dc-max-microvolt = <23000000>;
100 channel@0 {
101 reg = <0>;
102 adi,mode = <4>;
103 adi,ext-current-sense-resistor;
104 adi,slew = <0 64000 1>;
105 };
106 channel@1 {
107 reg = <1>;
108 adi,mode = <4>;
109 adi,ext-current-sense-resistor;
110 adi,slew = <0 64000 1>;
111 };
112 channel@2 {
113 reg = <2>;
114 adi,mode = <4>;
115 adi,ext-current-sense-resistor;
116 adi,slew = <0 64000 1>;
117 };
118 channel@3 {
119 reg = <3>;
120 adi,mode = <4>;
121 adi,ext-current-sense-resistor;
122 adi,slew = <0 64000 1>;
123 };
124};
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 31325870a9ef..89d78208de3f 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -157,12 +157,12 @@ config MMA7660
157 will be called mma7660. 157 will be called mma7660.
158 158
159config MMA8452 159config MMA8452
160 tristate "Freescale MMA8452Q and similar Accelerometers Driver" 160 tristate "Freescale / NXP MMA8452Q and similar Accelerometers Driver"
161 depends on I2C 161 depends on I2C
162 select IIO_BUFFER 162 select IIO_BUFFER
163 select IIO_TRIGGERED_BUFFER 163 select IIO_TRIGGERED_BUFFER
164 help 164 help
165 Say yes here to build support for the following Freescale 3-axis 165 Say yes here to build support for the following Freescale / NXP 3-axis
166 accelerometers: MMA8451Q, MMA8452Q, MMA8453Q, MMA8652FC, MMA8653FC, 166 accelerometers: MMA8451Q, MMA8452Q, MMA8453Q, MMA8652FC, MMA8653FC,
167 FXLS8471Q. 167 FXLS8471Q.
168 168
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 458c82715427..799fe64fc286 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1,22 +1,22 @@
1/* 1/*
2 * mma8452.c - Support for following Freescale 3-axis accelerometers: 2 * mma8452.c - Support for following Freescale / NXP 3-axis accelerometers:
3 * 3 *
4 * MMA8451Q (14 bit) 4 * device name digital output 7-bit I2C slave address (pin selectable)
5 * MMA8452Q (12 bit) 5 * ---------------------------------------------------------------------
6 * MMA8453Q (10 bit) 6 * MMA8451Q 14 bit 0x1c / 0x1d
7 * MMA8652FC (12 bit) 7 * MMA8452Q 12 bit 0x1c / 0x1d
8 * MMA8653FC (10 bit) 8 * MMA8453Q 10 bit 0x1c / 0x1d
9 * FXLS8471Q (14 bit) 9 * MMA8652FC 12 bit 0x1d
10 * MMA8653FC 10 bit 0x1d
11 * FXLS8471Q 14 bit 0x1e / 0x1d / 0x1c / 0x1f
10 * 12 *
11 * Copyright 2015 Martin Kepplinger <martin.kepplinger@theobroma-systems.com> 13 * Copyright 2015 Martin Kepplinger <martink@posteo.de>
12 * Copyright 2014 Peter Meerwald <pmeerw@pmeerw.net> 14 * Copyright 2014 Peter Meerwald <pmeerw@pmeerw.net>
13 * 15 *
14 * This file is subject to the terms and conditions of version 2 of 16 * This file is subject to the terms and conditions of version 2 of
15 * the GNU General Public License. See the file COPYING in the main 17 * the GNU General Public License. See the file COPYING in the main
16 * directory of this archive for more details. 18 * directory of this archive for more details.
17 * 19 *
18 * 7-bit I2C slave address 0x1c/0x1d (pin selectable)
19 *
20 * TODO: orientation events 20 * TODO: orientation events
21 */ 21 */
22 22
@@ -108,7 +108,7 @@ struct mma8452_data {
108}; 108};
109 109
110/** 110/**
111 * struct mma_chip_info - chip specific data for Freescale's accelerometers 111 * struct mma_chip_info - chip specific data
112 * @chip_id: WHO_AM_I register's value 112 * @chip_id: WHO_AM_I register's value
113 * @channels: struct iio_chan_spec matching the device's 113 * @channels: struct iio_chan_spec matching the device's
114 * capabilities 114 * capabilities
@@ -1693,5 +1693,5 @@ static struct i2c_driver mma8452_driver = {
1693module_i2c_driver(mma8452_driver); 1693module_i2c_driver(mma8452_driver);
1694 1694
1695MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>"); 1695MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
1696MODULE_DESCRIPTION("Freescale MMA8452 accelerometer driver"); 1696MODULE_DESCRIPTION("Freescale / NXP MMA8452 accelerometer driver");
1697MODULE_LICENSE("GPL"); 1697MODULE_LICENSE("GPL");
diff --git a/drivers/iio/adc/ti-adc081c.c b/drivers/iio/adc/ti-adc081c.c
index 9fd032d9f402..f8807adc08c4 100644
--- a/drivers/iio/adc/ti-adc081c.c
+++ b/drivers/iio/adc/ti-adc081c.c
@@ -22,6 +22,7 @@
22#include <linux/i2c.h> 22#include <linux/i2c.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/of.h> 24#include <linux/of.h>
25#include <linux/acpi.h>
25 26
26#include <linux/iio/iio.h> 27#include <linux/iio/iio.h>
27#include <linux/iio/buffer.h> 28#include <linux/iio/buffer.h>
@@ -149,12 +150,24 @@ static int adc081c_probe(struct i2c_client *client,
149{ 150{
150 struct iio_dev *iio; 151 struct iio_dev *iio;
151 struct adc081c *adc; 152 struct adc081c *adc;
152 struct adcxx1c_model *model = &adcxx1c_models[id->driver_data]; 153 struct adcxx1c_model *model;
153 int err; 154 int err;
154 155
155 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 156 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))
156 return -EOPNOTSUPP; 157 return -EOPNOTSUPP;
157 158
159 if (ACPI_COMPANION(&client->dev)) {
160 const struct acpi_device_id *ad_id;
161
162 ad_id = acpi_match_device(client->dev.driver->acpi_match_table,
163 &client->dev);
164 if (!ad_id)
165 return -ENODEV;
166 model = &adcxx1c_models[ad_id->driver_data];
167 } else {
168 model = &adcxx1c_models[id->driver_data];
169 }
170
158 iio = devm_iio_device_alloc(&client->dev, sizeof(*adc)); 171 iio = devm_iio_device_alloc(&client->dev, sizeof(*adc));
159 if (!iio) 172 if (!iio)
160 return -ENOMEM; 173 return -ENOMEM;
@@ -231,10 +244,21 @@ static const struct of_device_id adc081c_of_match[] = {
231MODULE_DEVICE_TABLE(of, adc081c_of_match); 244MODULE_DEVICE_TABLE(of, adc081c_of_match);
232#endif 245#endif
233 246
247#ifdef CONFIG_ACPI
248static const struct acpi_device_id adc081c_acpi_match[] = {
249 { "ADC081C", ADC081C },
250 { "ADC101C", ADC101C },
251 { "ADC121C", ADC121C },
252 { }
253};
254MODULE_DEVICE_TABLE(acpi, adc081c_acpi_match);
255#endif
256
234static struct i2c_driver adc081c_driver = { 257static struct i2c_driver adc081c_driver = {
235 .driver = { 258 .driver = {
236 .name = "adc081c", 259 .name = "adc081c",
237 .of_match_table = of_match_ptr(adc081c_of_match), 260 .of_match_table = of_match_ptr(adc081c_of_match),
261 .acpi_match_table = ACPI_PTR(adc081c_acpi_match),
238 }, 262 },
239 .probe = adc081c_probe, 263 .probe = adc081c_probe,
240 .remove = adc081c_remove, 264 .remove = adc081c_remove,
diff --git a/drivers/iio/buffer/industrialio-buffer-dma.c b/drivers/iio/buffer/industrialio-buffer-dma.c
index 212cbedc7abb..dd99d273bae9 100644
--- a/drivers/iio/buffer/industrialio-buffer-dma.c
+++ b/drivers/iio/buffer/industrialio-buffer-dma.c
@@ -305,7 +305,7 @@ int iio_dma_buffer_request_update(struct iio_buffer *buffer)
305 queue->fileio.active_block = NULL; 305 queue->fileio.active_block = NULL;
306 306
307 spin_lock_irq(&queue->list_lock); 307 spin_lock_irq(&queue->list_lock);
308 for (i = 0; i < 2; i++) { 308 for (i = 0; i < ARRAY_SIZE(queue->fileio.blocks); i++) {
309 block = queue->fileio.blocks[i]; 309 block = queue->fileio.blocks[i];
310 310
311 /* If we can't re-use it free it */ 311 /* If we can't re-use it free it */
@@ -323,7 +323,7 @@ int iio_dma_buffer_request_update(struct iio_buffer *buffer)
323 323
324 INIT_LIST_HEAD(&queue->incoming); 324 INIT_LIST_HEAD(&queue->incoming);
325 325
326 for (i = 0; i < 2; i++) { 326 for (i = 0; i < ARRAY_SIZE(queue->fileio.blocks); i++) {
327 if (queue->fileio.blocks[i]) { 327 if (queue->fileio.blocks[i]) {
328 block = queue->fileio.blocks[i]; 328 block = queue->fileio.blocks[i];
329 if (block->state == IIO_BLOCK_STATE_DEAD) { 329 if (block->state == IIO_BLOCK_STATE_DEAD) {
diff --git a/drivers/iio/dac/Kconfig b/drivers/iio/dac/Kconfig
index f7c71da42f15..ca814479fadf 100644
--- a/drivers/iio/dac/Kconfig
+++ b/drivers/iio/dac/Kconfig
@@ -248,11 +248,12 @@ config MCP4922
248config STX104 248config STX104
249 tristate "Apex Embedded Systems STX104 DAC driver" 249 tristate "Apex Embedded Systems STX104 DAC driver"
250 depends on X86 && ISA_BUS_API 250 depends on X86 && ISA_BUS_API
251 select GPIOLIB
251 help 252 help
252 Say yes here to build support for the 2-channel DAC on the Apex 253 Say yes here to build support for the 2-channel DAC and GPIO on the
253 Embedded Systems STX104 integrated analog PC/104 card. The base port 254 Apex Embedded Systems STX104 integrated analog PC/104 card. The base
254 addresses for the devices may be configured via the "base" module 255 port addresses for the devices may be configured via the base array
255 parameter array. 256 module parameter.
256 257
257config VF610_DAC 258config VF610_DAC
258 tristate "Vybrid vf610 DAC driver" 259 tristate "Vybrid vf610 DAC driver"
diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c
index bfb350a85a16..0fde593ec0d9 100644
--- a/drivers/iio/dac/ad5755.c
+++ b/drivers/iio/dac/ad5755.c
@@ -14,6 +14,7 @@
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/sysfs.h> 15#include <linux/sysfs.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/of.h>
17#include <linux/iio/iio.h> 18#include <linux/iio/iio.h>
18#include <linux/iio/sysfs.h> 19#include <linux/iio/sysfs.h>
19#include <linux/platform_data/ad5755.h> 20#include <linux/platform_data/ad5755.h>
@@ -109,6 +110,51 @@ enum ad5755_type {
109 ID_AD5737, 110 ID_AD5737,
110}; 111};
111 112
113#ifdef CONFIG_OF
114static const int ad5755_dcdc_freq_table[][2] = {
115 { 250000, AD5755_DC_DC_FREQ_250kHZ },
116 { 410000, AD5755_DC_DC_FREQ_410kHZ },
117 { 650000, AD5755_DC_DC_FREQ_650kHZ }
118};
119
120static const int ad5755_dcdc_maxv_table[][2] = {
121 { 23000000, AD5755_DC_DC_MAXV_23V },
122 { 24500000, AD5755_DC_DC_MAXV_24V5 },
123 { 27000000, AD5755_DC_DC_MAXV_27V },
124 { 29500000, AD5755_DC_DC_MAXV_29V5 },
125};
126
127static const int ad5755_slew_rate_table[][2] = {
128 { 64000, AD5755_SLEW_RATE_64k },
129 { 32000, AD5755_SLEW_RATE_32k },
130 { 16000, AD5755_SLEW_RATE_16k },
131 { 8000, AD5755_SLEW_RATE_8k },
132 { 4000, AD5755_SLEW_RATE_4k },
133 { 2000, AD5755_SLEW_RATE_2k },
134 { 1000, AD5755_SLEW_RATE_1k },
135 { 500, AD5755_SLEW_RATE_500 },
136 { 250, AD5755_SLEW_RATE_250 },
137 { 125, AD5755_SLEW_RATE_125 },
138 { 64, AD5755_SLEW_RATE_64 },
139 { 32, AD5755_SLEW_RATE_32 },
140 { 16, AD5755_SLEW_RATE_16 },
141 { 8, AD5755_SLEW_RATE_8 },
142 { 4, AD5755_SLEW_RATE_4 },
143 { 0, AD5755_SLEW_RATE_0_5 },
144};
145
146static const int ad5755_slew_step_table[][2] = {
147 { 256, AD5755_SLEW_STEP_SIZE_256 },
148 { 128, AD5755_SLEW_STEP_SIZE_128 },
149 { 64, AD5755_SLEW_STEP_SIZE_64 },
150 { 32, AD5755_SLEW_STEP_SIZE_32 },
151 { 16, AD5755_SLEW_STEP_SIZE_16 },
152 { 4, AD5755_SLEW_STEP_SIZE_4 },
153 { 2, AD5755_SLEW_STEP_SIZE_2 },
154 { 1, AD5755_SLEW_STEP_SIZE_1 },
155};
156#endif
157
112static int ad5755_write_unlocked(struct iio_dev *indio_dev, 158static int ad5755_write_unlocked(struct iio_dev *indio_dev,
113 unsigned int reg, unsigned int val) 159 unsigned int reg, unsigned int val)
114{ 160{
@@ -556,6 +602,129 @@ static const struct ad5755_platform_data ad5755_default_pdata = {
556 }, 602 },
557}; 603};
558 604
605#ifdef CONFIG_OF
606static struct ad5755_platform_data *ad5755_parse_dt(struct device *dev)
607{
608 struct device_node *np = dev->of_node;
609 struct device_node *pp;
610 struct ad5755_platform_data *pdata;
611 unsigned int tmp;
612 unsigned int tmparray[3];
613 int devnr, i;
614
615 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
616 if (!pdata)
617 return NULL;
618
619 pdata->ext_dc_dc_compenstation_resistor =
620 of_property_read_bool(np, "adi,ext-dc-dc-compenstation-resistor");
621
622 if (!of_property_read_u32(np, "adi,dc-dc-phase", &tmp))
623 pdata->dc_dc_phase = tmp;
624 else
625 pdata->dc_dc_phase = AD5755_DC_DC_PHASE_ALL_SAME_EDGE;
626
627 pdata->dc_dc_freq = AD5755_DC_DC_FREQ_410kHZ;
628 if (!of_property_read_u32(np, "adi,dc-dc-freq-hz", &tmp)) {
629 for (i = 0; i < ARRAY_SIZE(ad5755_dcdc_freq_table); i++) {
630 if (tmp == ad5755_dcdc_freq_table[i][0]) {
631 pdata->dc_dc_freq = ad5755_dcdc_freq_table[i][1];
632 break;
633 }
634 }
635
636 if (i == ARRAY_SIZE(ad5755_dcdc_freq_table)) {
637 dev_err(dev,
638 "adi,dc-dc-freq out of range selecting 410kHz");
639 }
640 }
641
642 pdata->dc_dc_maxv = AD5755_DC_DC_MAXV_23V;
643 if (!of_property_read_u32(np, "adi,dc-dc-max-microvolt", &tmp)) {
644 for (i = 0; i < ARRAY_SIZE(ad5755_dcdc_maxv_table); i++) {
645 if (tmp == ad5755_dcdc_maxv_table[i][0]) {
646 pdata->dc_dc_maxv = ad5755_dcdc_maxv_table[i][1];
647 break;
648 }
649 }
650 if (i == ARRAY_SIZE(ad5755_dcdc_maxv_table)) {
651 dev_err(dev,
652 "adi,dc-dc-maxv out of range selecting 23V");
653 }
654 }
655
656 devnr = 0;
657 for_each_child_of_node(np, pp) {
658 if (devnr > AD5755_NUM_CHANNELS) {
659 dev_err(dev,
660 "There is to many channels defined in DT\n");
661 goto error_out;
662 }
663
664 if (!of_property_read_u32(pp, "adi,mode", &tmp))
665 pdata->dac[devnr].mode = tmp;
666 else
667 pdata->dac[devnr].mode = AD5755_MODE_CURRENT_4mA_20mA;
668
669 pdata->dac[devnr].ext_current_sense_resistor =
670 of_property_read_bool(pp, "adi,ext-current-sense-resistor");
671
672 pdata->dac[devnr].enable_voltage_overrange =
673 of_property_read_bool(pp, "adi,enable-voltage-overrange");
674
675 if (!of_property_read_u32_array(pp, "adi,slew", tmparray, 3)) {
676 pdata->dac[devnr].slew.enable = tmparray[0];
677
678 pdata->dac[devnr].slew.rate = AD5755_SLEW_RATE_64k;
679 for (i = 0; i < ARRAY_SIZE(ad5755_slew_rate_table); i++) {
680 if (tmparray[1] == ad5755_slew_rate_table[i][0]) {
681 pdata->dac[devnr].slew.rate =
682 ad5755_slew_rate_table[i][1];
683 break;
684 }
685 }
686 if (i == ARRAY_SIZE(ad5755_slew_rate_table)) {
687 dev_err(dev,
688 "channel %d slew rate out of range selecting 64kHz",
689 devnr);
690 }
691
692 pdata->dac[devnr].slew.step_size = AD5755_SLEW_STEP_SIZE_1;
693 for (i = 0; i < ARRAY_SIZE(ad5755_slew_step_table); i++) {
694 if (tmparray[2] == ad5755_slew_step_table[i][0]) {
695 pdata->dac[devnr].slew.step_size =
696 ad5755_slew_step_table[i][1];
697 break;
698 }
699 }
700 if (i == ARRAY_SIZE(ad5755_slew_step_table)) {
701 dev_err(dev,
702 "channel %d slew step size out of range selecting 1 LSB",
703 devnr);
704 }
705 } else {
706 pdata->dac[devnr].slew.enable = false;
707 pdata->dac[devnr].slew.rate = AD5755_SLEW_RATE_64k;
708 pdata->dac[devnr].slew.step_size =
709 AD5755_SLEW_STEP_SIZE_1;
710 }
711 devnr++;
712 }
713
714 return pdata;
715
716 error_out:
717 devm_kfree(dev, pdata);
718 return NULL;
719}
720#else
721static
722struct ad5755_platform_data *ad5755_parse_dt(struct device *dev)
723{
724 return NULL;
725}
726#endif
727
559static int ad5755_probe(struct spi_device *spi) 728static int ad5755_probe(struct spi_device *spi)
560{ 729{
561 enum ad5755_type type = spi_get_device_id(spi)->driver_data; 730 enum ad5755_type type = spi_get_device_id(spi)->driver_data;
@@ -583,8 +752,15 @@ static int ad5755_probe(struct spi_device *spi)
583 indio_dev->modes = INDIO_DIRECT_MODE; 752 indio_dev->modes = INDIO_DIRECT_MODE;
584 indio_dev->num_channels = AD5755_NUM_CHANNELS; 753 indio_dev->num_channels = AD5755_NUM_CHANNELS;
585 754
586 if (!pdata) 755 if (spi->dev.of_node)
756 pdata = ad5755_parse_dt(&spi->dev);
757 else
758 pdata = spi->dev.platform_data;
759
760 if (!pdata) {
761 dev_warn(&spi->dev, "no platform data? using default\n");
587 pdata = &ad5755_default_pdata; 762 pdata = &ad5755_default_pdata;
763 }
588 764
589 ret = ad5755_init_channels(indio_dev, pdata); 765 ret = ad5755_init_channels(indio_dev, pdata);
590 if (ret) 766 if (ret)
@@ -607,6 +783,16 @@ static const struct spi_device_id ad5755_id[] = {
607}; 783};
608MODULE_DEVICE_TABLE(spi, ad5755_id); 784MODULE_DEVICE_TABLE(spi, ad5755_id);
609 785
786static const struct of_device_id ad5755_of_match[] = {
787 { .compatible = "adi,ad5755" },
788 { .compatible = "adi,ad5755-1" },
789 { .compatible = "adi,ad5757" },
790 { .compatible = "adi,ad5735" },
791 { .compatible = "adi,ad5737" },
792 { }
793};
794MODULE_DEVICE_TABLE(of, ad5755_of_match);
795
610static struct spi_driver ad5755_driver = { 796static struct spi_driver ad5755_driver = {
611 .driver = { 797 .driver = {
612 .name = "ad5755", 798 .name = "ad5755",
diff --git a/drivers/iio/dac/stx104.c b/drivers/iio/dac/stx104.c
index 27941220872f..792a97164cb2 100644
--- a/drivers/iio/dac/stx104.c
+++ b/drivers/iio/dac/stx104.c
@@ -14,6 +14,7 @@
14#include <linux/bitops.h> 14#include <linux/bitops.h>
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/errno.h> 16#include <linux/errno.h>
17#include <linux/gpio/driver.h>
17#include <linux/iio/iio.h> 18#include <linux/iio/iio.h>
18#include <linux/iio/types.h> 19#include <linux/iio/types.h>
19#include <linux/io.h> 20#include <linux/io.h>
@@ -21,6 +22,7 @@
21#include <linux/isa.h> 22#include <linux/isa.h>
22#include <linux/module.h> 23#include <linux/module.h>
23#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/spinlock.h>
24 26
25#define STX104_NUM_CHAN 2 27#define STX104_NUM_CHAN 2
26 28
@@ -49,6 +51,20 @@ struct stx104_iio {
49 unsigned base; 51 unsigned base;
50}; 52};
51 53
54/**
55 * struct stx104_gpio - GPIO device private data structure
56 * @chip: instance of the gpio_chip
57 * @lock: synchronization lock to prevent I/O race conditions
58 * @base: base port address of the GPIO device
59 * @out_state: output bits state
60 */
61struct stx104_gpio {
62 struct gpio_chip chip;
63 spinlock_t lock;
64 unsigned int base;
65 unsigned int out_state;
66};
67
52static int stx104_read_raw(struct iio_dev *indio_dev, 68static int stx104_read_raw(struct iio_dev *indio_dev,
53 struct iio_chan_spec const *chan, int *val, int *val2, long mask) 69 struct iio_chan_spec const *chan, int *val, int *val2, long mask)
54{ 70{
@@ -88,15 +104,81 @@ static const struct iio_chan_spec stx104_channels[STX104_NUM_CHAN] = {
88 STX104_CHAN(1) 104 STX104_CHAN(1)
89}; 105};
90 106
107static int stx104_gpio_get_direction(struct gpio_chip *chip,
108 unsigned int offset)
109{
110 if (offset < 4)
111 return 1;
112
113 return 0;
114}
115
116static int stx104_gpio_direction_input(struct gpio_chip *chip,
117 unsigned int offset)
118{
119 if (offset >= 4)
120 return -EINVAL;
121
122 return 0;
123}
124
125static int stx104_gpio_direction_output(struct gpio_chip *chip,
126 unsigned int offset, int value)
127{
128 if (offset < 4)
129 return -EINVAL;
130
131 chip->set(chip, offset, value);
132 return 0;
133}
134
135static int stx104_gpio_get(struct gpio_chip *chip, unsigned int offset)
136{
137 struct stx104_gpio *const stx104gpio = gpiochip_get_data(chip);
138
139 if (offset >= 4)
140 return -EINVAL;
141
142 return !!(inb(stx104gpio->base) & BIT(offset));
143}
144
145static void stx104_gpio_set(struct gpio_chip *chip, unsigned int offset,
146 int value)
147{
148 struct stx104_gpio *const stx104gpio = gpiochip_get_data(chip);
149 const unsigned int mask = BIT(offset) >> 4;
150 unsigned long flags;
151
152 if (offset < 4)
153 return;
154
155 spin_lock_irqsave(&stx104gpio->lock, flags);
156
157 if (value)
158 stx104gpio->out_state |= mask;
159 else
160 stx104gpio->out_state &= ~mask;
161
162 outb(stx104gpio->out_state, stx104gpio->base);
163
164 spin_unlock_irqrestore(&stx104gpio->lock, flags);
165}
166
91static int stx104_probe(struct device *dev, unsigned int id) 167static int stx104_probe(struct device *dev, unsigned int id)
92{ 168{
93 struct iio_dev *indio_dev; 169 struct iio_dev *indio_dev;
94 struct stx104_iio *priv; 170 struct stx104_iio *priv;
171 struct stx104_gpio *stx104gpio;
172 int err;
95 173
96 indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); 174 indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
97 if (!indio_dev) 175 if (!indio_dev)
98 return -ENOMEM; 176 return -ENOMEM;
99 177
178 stx104gpio = devm_kzalloc(dev, sizeof(*stx104gpio), GFP_KERNEL);
179 if (!stx104gpio)
180 return -ENOMEM;
181
100 if (!devm_request_region(dev, base[id], STX104_EXTENT, 182 if (!devm_request_region(dev, base[id], STX104_EXTENT,
101 dev_name(dev))) { 183 dev_name(dev))) {
102 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", 184 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n",
@@ -117,14 +199,53 @@ static int stx104_probe(struct device *dev, unsigned int id)
117 outw(0, base[id] + 4); 199 outw(0, base[id] + 4);
118 outw(0, base[id] + 6); 200 outw(0, base[id] + 6);
119 201
120 return devm_iio_device_register(dev, indio_dev); 202 err = devm_iio_device_register(dev, indio_dev);
203 if (err) {
204 dev_err(dev, "IIO device registering failed (%d)\n", err);
205 return err;
206 }
207
208 stx104gpio->chip.label = dev_name(dev);
209 stx104gpio->chip.parent = dev;
210 stx104gpio->chip.owner = THIS_MODULE;
211 stx104gpio->chip.base = -1;
212 stx104gpio->chip.ngpio = 8;
213 stx104gpio->chip.get_direction = stx104_gpio_get_direction;
214 stx104gpio->chip.direction_input = stx104_gpio_direction_input;
215 stx104gpio->chip.direction_output = stx104_gpio_direction_output;
216 stx104gpio->chip.get = stx104_gpio_get;
217 stx104gpio->chip.set = stx104_gpio_set;
218 stx104gpio->base = base[id] + 3;
219 stx104gpio->out_state = 0x0;
220
221 spin_lock_init(&stx104gpio->lock);
222
223 dev_set_drvdata(dev, stx104gpio);
224
225 err = gpiochip_add_data(&stx104gpio->chip, stx104gpio);
226 if (err) {
227 dev_err(dev, "GPIO registering failed (%d)\n", err);
228 return err;
229 }
230
231 return 0;
232}
233
234static int stx104_remove(struct device *dev, unsigned int id)
235{
236 struct stx104_gpio *const stx104gpio = dev_get_drvdata(dev);
237
238 gpiochip_remove(&stx104gpio->chip);
239
240 return 0;
121} 241}
122 242
123static struct isa_driver stx104_driver = { 243static struct isa_driver stx104_driver = {
124 .probe = stx104_probe, 244 .probe = stx104_probe,
125 .driver = { 245 .driver = {
126 .name = "stx104" 246 .name = "stx104"
127 } 247 },
248 .remove = stx104_remove
128}; 249};
129 250
130module_isa_driver(stx104_driver, num_stx104); 251module_isa_driver(stx104_driver, num_stx104);
diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 7c15c3092d5d..98457f044aa5 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -64,6 +64,8 @@ static struct attribute *iio_trig_dev_attrs[] = {
64}; 64};
65ATTRIBUTE_GROUPS(iio_trig_dev); 65ATTRIBUTE_GROUPS(iio_trig_dev);
66 66
67static struct iio_trigger *__iio_trigger_find_by_name(const char *name);
68
67int iio_trigger_register(struct iio_trigger *trig_info) 69int iio_trigger_register(struct iio_trigger *trig_info)
68{ 70{
69 int ret; 71 int ret;
@@ -86,11 +88,19 @@ int iio_trigger_register(struct iio_trigger *trig_info)
86 88
87 /* Add to list of available triggers held by the IIO core */ 89 /* Add to list of available triggers held by the IIO core */
88 mutex_lock(&iio_trigger_list_lock); 90 mutex_lock(&iio_trigger_list_lock);
91 if (__iio_trigger_find_by_name(trig_info->name)) {
92 pr_err("Duplicate trigger name '%s'\n", trig_info->name);
93 ret = -EEXIST;
94 goto error_device_del;
95 }
89 list_add_tail(&trig_info->list, &iio_trigger_list); 96 list_add_tail(&trig_info->list, &iio_trigger_list);
90 mutex_unlock(&iio_trigger_list_lock); 97 mutex_unlock(&iio_trigger_list_lock);
91 98
92 return 0; 99 return 0;
93 100
101error_device_del:
102 mutex_unlock(&iio_trigger_list_lock);
103 device_del(&trig_info->dev);
94error_unregister_id: 104error_unregister_id:
95 ida_simple_remove(&iio_trigger_ida, trig_info->id); 105 ida_simple_remove(&iio_trigger_ida, trig_info->id);
96 return ret; 106 return ret;
@@ -109,6 +119,18 @@ void iio_trigger_unregister(struct iio_trigger *trig_info)
109} 119}
110EXPORT_SYMBOL(iio_trigger_unregister); 120EXPORT_SYMBOL(iio_trigger_unregister);
111 121
122/* Search for trigger by name, assuming iio_trigger_list_lock held */
123static struct iio_trigger *__iio_trigger_find_by_name(const char *name)
124{
125 struct iio_trigger *iter;
126
127 list_for_each_entry(iter, &iio_trigger_list, list)
128 if (!strcmp(iter->name, name))
129 return iter;
130
131 return NULL;
132}
133
112static struct iio_trigger *iio_trigger_find_by_name(const char *name, 134static struct iio_trigger *iio_trigger_find_by_name(const char *name,
113 size_t len) 135 size_t len)
114{ 136{
diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
index 6d41086f7c64..af73af3586a9 100644
--- a/drivers/iio/light/gp2ap020a00f.c
+++ b/drivers/iio/light/gp2ap020a00f.c
@@ -1287,22 +1287,14 @@ static int gp2ap020a00f_read_raw(struct iio_dev *indio_dev,
1287 struct gp2ap020a00f_data *data = iio_priv(indio_dev); 1287 struct gp2ap020a00f_data *data = iio_priv(indio_dev);
1288 int err = -EINVAL; 1288 int err = -EINVAL;
1289 1289
1290 mutex_lock(&data->lock); 1290 if (mask == IIO_CHAN_INFO_RAW) {
1291 1291 err = iio_device_claim_direct_mode(indio_dev);
1292 switch (mask) { 1292 if (err)
1293 case IIO_CHAN_INFO_RAW: 1293 return err;
1294 if (iio_buffer_enabled(indio_dev)) {
1295 err = -EBUSY;
1296 goto error_unlock;
1297 }
1298 1294
1299 err = gp2ap020a00f_read_channel(data, chan, val); 1295 err = gp2ap020a00f_read_channel(data, chan, val);
1300 break; 1296 iio_device_release_direct_mode(indio_dev);
1301 } 1297 }
1302
1303error_unlock:
1304 mutex_unlock(&data->lock);
1305
1306 return err < 0 ? err : IIO_VAL_INT; 1298 return err < 0 ? err : IIO_VAL_INT;
1307} 1299}
1308 1300
diff --git a/drivers/iio/light/isl29125.c b/drivers/iio/light/isl29125.c
index e2945a20e5f6..a6b9d66233d5 100644
--- a/drivers/iio/light/isl29125.c
+++ b/drivers/iio/light/isl29125.c
@@ -50,7 +50,6 @@
50 50
51struct isl29125_data { 51struct isl29125_data {
52 struct i2c_client *client; 52 struct i2c_client *client;
53 struct mutex lock;
54 u8 conf1; 53 u8 conf1;
55 u16 buffer[8]; /* 3x 16-bit, padding, 8 bytes timestamp */ 54 u16 buffer[8]; /* 3x 16-bit, padding, 8 bytes timestamp */
56}; 55};
@@ -128,11 +127,11 @@ static int isl29125_read_raw(struct iio_dev *indio_dev,
128 127
129 switch (mask) { 128 switch (mask) {
130 case IIO_CHAN_INFO_RAW: 129 case IIO_CHAN_INFO_RAW:
131 if (iio_buffer_enabled(indio_dev)) 130 ret = iio_device_claim_direct_mode(indio_dev);
132 return -EBUSY; 131 if (ret)
133 mutex_lock(&data->lock); 132 return ret;
134 ret = isl29125_read_data(data, chan->scan_index); 133 ret = isl29125_read_data(data, chan->scan_index);
135 mutex_unlock(&data->lock); 134 iio_device_release_direct_mode(indio_dev);
136 if (ret < 0) 135 if (ret < 0)
137 return ret; 136 return ret;
138 *val = ret; 137 *val = ret;
@@ -259,7 +258,6 @@ static int isl29125_probe(struct i2c_client *client,
259 data = iio_priv(indio_dev); 258 data = iio_priv(indio_dev);
260 i2c_set_clientdata(client, indio_dev); 259 i2c_set_clientdata(client, indio_dev);
261 data->client = client; 260 data->client = client;
262 mutex_init(&data->lock);
263 261
264 indio_dev->dev.parent = &client->dev; 262 indio_dev->dev.parent = &client->dev;
265 indio_dev->info = &isl29125_info; 263 indio_dev->info = &isl29125_info;
diff --git a/drivers/iio/light/tcs3414.c b/drivers/iio/light/tcs3414.c
index f90f8c5919fe..8a15fb541dc3 100644
--- a/drivers/iio/light/tcs3414.c
+++ b/drivers/iio/light/tcs3414.c
@@ -53,7 +53,6 @@
53 53
54struct tcs3414_data { 54struct tcs3414_data {
55 struct i2c_client *client; 55 struct i2c_client *client;
56 struct mutex lock;
57 u8 control; 56 u8 control;
58 u8 gain; 57 u8 gain;
59 u8 timing; 58 u8 timing;
@@ -134,16 +133,16 @@ static int tcs3414_read_raw(struct iio_dev *indio_dev,
134 133
135 switch (mask) { 134 switch (mask) {
136 case IIO_CHAN_INFO_RAW: 135 case IIO_CHAN_INFO_RAW:
137 if (iio_buffer_enabled(indio_dev)) 136 ret = iio_device_claim_direct_mode(indio_dev);
138 return -EBUSY; 137 if (ret)
139 mutex_lock(&data->lock); 138 return ret;
140 ret = tcs3414_req_data(data); 139 ret = tcs3414_req_data(data);
141 if (ret < 0) { 140 if (ret < 0) {
142 mutex_unlock(&data->lock); 141 iio_device_release_direct_mode(indio_dev);
143 return ret; 142 return ret;
144 } 143 }
145 ret = i2c_smbus_read_word_data(data->client, chan->address); 144 ret = i2c_smbus_read_word_data(data->client, chan->address);
146 mutex_unlock(&data->lock); 145 iio_device_release_direct_mode(indio_dev);
147 if (ret < 0) 146 if (ret < 0)
148 return ret; 147 return ret;
149 *val = ret; 148 *val = ret;
@@ -288,7 +287,6 @@ static int tcs3414_probe(struct i2c_client *client,
288 data = iio_priv(indio_dev); 287 data = iio_priv(indio_dev);
289 i2c_set_clientdata(client, indio_dev); 288 i2c_set_clientdata(client, indio_dev);
290 data->client = client; 289 data->client = client;
291 mutex_init(&data->lock);
292 290
293 indio_dev->dev.parent = &client->dev; 291 indio_dev->dev.parent = &client->dev;
294 indio_dev->info = &tcs3414_info; 292 indio_dev->info = &tcs3414_info;
diff --git a/drivers/iio/light/tcs3472.c b/drivers/iio/light/tcs3472.c
index 1b530bf04c89..b29312f99077 100644
--- a/drivers/iio/light/tcs3472.c
+++ b/drivers/iio/light/tcs3472.c
@@ -52,7 +52,6 @@
52 52
53struct tcs3472_data { 53struct tcs3472_data {
54 struct i2c_client *client; 54 struct i2c_client *client;
55 struct mutex lock;
56 u8 enable; 55 u8 enable;
57 u8 control; 56 u8 control;
58 u8 atime; 57 u8 atime;
@@ -117,17 +116,16 @@ static int tcs3472_read_raw(struct iio_dev *indio_dev,
117 116
118 switch (mask) { 117 switch (mask) {
119 case IIO_CHAN_INFO_RAW: 118 case IIO_CHAN_INFO_RAW:
120 if (iio_buffer_enabled(indio_dev)) 119 ret = iio_device_claim_direct_mode(indio_dev);
121 return -EBUSY; 120 if (ret)
122 121 return ret;
123 mutex_lock(&data->lock);
124 ret = tcs3472_req_data(data); 122 ret = tcs3472_req_data(data);
125 if (ret < 0) { 123 if (ret < 0) {
126 mutex_unlock(&data->lock); 124 iio_device_release_direct_mode(indio_dev);
127 return ret; 125 return ret;
128 } 126 }
129 ret = i2c_smbus_read_word_data(data->client, chan->address); 127 ret = i2c_smbus_read_word_data(data->client, chan->address);
130 mutex_unlock(&data->lock); 128 iio_device_release_direct_mode(indio_dev);
131 if (ret < 0) 129 if (ret < 0)
132 return ret; 130 return ret;
133 *val = ret; 131 *val = ret;
@@ -263,7 +261,6 @@ static int tcs3472_probe(struct i2c_client *client,
263 data = iio_priv(indio_dev); 261 data = iio_priv(indio_dev);
264 i2c_set_clientdata(client, indio_dev); 262 i2c_set_clientdata(client, indio_dev);
265 data->client = client; 263 data->client = client;
266 mutex_init(&data->lock);
267 264
268 indio_dev->dev.parent = &client->dev; 265 indio_dev->dev.parent = &client->dev;
269 indio_dev->info = &tcs3472_info; 266 indio_dev->info = &tcs3472_info;
diff --git a/drivers/iio/pressure/ms5637.c b/drivers/iio/pressure/ms5637.c
index 8fb6f7ab97e4..953ffbc0ef96 100644
--- a/drivers/iio/pressure/ms5637.c
+++ b/drivers/iio/pressure/ms5637.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * ms5637.c - Support for Measurement-Specialties ms5637 and ms8607 2 * ms5637.c - Support for Measurement-Specialties MS5637, MS5805
3 * pressure & temperature sensor 3 * MS5837 and MS8607 pressure & temperature sensor
4 * 4 *
5 * Copyright (c) 2015 Measurement-Specialties 5 * Copyright (c) 2015 Measurement-Specialties
6 * 6 *
@@ -11,6 +11,10 @@
11 * Datasheet: 11 * Datasheet:
12 * http://www.meas-spec.com/downloads/MS5637-02BA03.pdf 12 * http://www.meas-spec.com/downloads/MS5637-02BA03.pdf
13 * Datasheet: 13 * Datasheet:
14 * http://www.meas-spec.com/downloads/MS5805-02BA01.pdf
15 * Datasheet:
16 * http://www.meas-spec.com/downloads/MS5837-30BA.pdf
17 * Datasheet:
14 * http://www.meas-spec.com/downloads/MS8607-02BA01.pdf 18 * http://www.meas-spec.com/downloads/MS8607-02BA01.pdf
15 */ 19 */
16 20
@@ -170,7 +174,9 @@ static int ms5637_probe(struct i2c_client *client,
170 174
171static const struct i2c_device_id ms5637_id[] = { 175static const struct i2c_device_id ms5637_id[] = {
172 {"ms5637", 0}, 176 {"ms5637", 0},
173 {"ms8607-temppressure", 1}, 177 {"ms5805", 0},
178 {"ms5837", 0},
179 {"ms8607-temppressure", 0},
174 {} 180 {}
175}; 181};
176MODULE_DEVICE_TABLE(i2c, ms5637_id); 182MODULE_DEVICE_TABLE(i2c, ms5637_id);
diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
index 9aa2ce551ba8..2e3a70e1b245 100644
--- a/drivers/iio/proximity/as3935.c
+++ b/drivers/iio/proximity/as3935.c
@@ -231,10 +231,16 @@ static void as3935_event_work(struct work_struct *work)
231{ 231{
232 struct as3935_state *st; 232 struct as3935_state *st;
233 int val; 233 int val;
234 int ret;
234 235
235 st = container_of(work, struct as3935_state, work.work); 236 st = container_of(work, struct as3935_state, work.work);
236 237
237 as3935_read(st, AS3935_INT, &val); 238 ret = as3935_read(st, AS3935_INT, &val);
239 if (ret) {
240 dev_warn(&st->spi->dev, "read error\n");
241 return;
242 }
243
238 val &= AS3935_INT_MASK; 244 val &= AS3935_INT_MASK;
239 245
240 switch (val) { 246 switch (val) {
@@ -242,7 +248,7 @@ static void as3935_event_work(struct work_struct *work)
242 iio_trigger_poll(st->trig); 248 iio_trigger_poll(st->trig);
243 break; 249 break;
244 case AS3935_NOISE_INT: 250 case AS3935_NOISE_INT:
245 dev_warn(&st->spi->dev, "noise level is too high"); 251 dev_warn(&st->spi->dev, "noise level is too high\n");
246 break; 252 break;
247 } 253 }
248} 254}
@@ -346,7 +352,6 @@ static int as3935_probe(struct spi_device *spi)
346 352
347 st = iio_priv(indio_dev); 353 st = iio_priv(indio_dev);
348 st->spi = spi; 354 st->spi = spi;
349 st->tune_cap = 0;
350 355
351 spi_set_drvdata(spi, indio_dev); 356 spi_set_drvdata(spi, indio_dev);
352 mutex_init(&st->lock); 357 mutex_init(&st->lock);
diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
index 4f502386aa86..c0b0e82abf94 100644
--- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
+++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
@@ -203,22 +203,19 @@ static int lidar_read_raw(struct iio_dev *indio_dev,
203 struct lidar_data *data = iio_priv(indio_dev); 203 struct lidar_data *data = iio_priv(indio_dev);
204 int ret = -EINVAL; 204 int ret = -EINVAL;
205 205
206 mutex_lock(&indio_dev->mlock);
207
208 if (iio_buffer_enabled(indio_dev) && mask == IIO_CHAN_INFO_RAW) {
209 ret = -EBUSY;
210 goto error_busy;
211 }
212
213 switch (mask) { 206 switch (mask) {
214 case IIO_CHAN_INFO_RAW: { 207 case IIO_CHAN_INFO_RAW: {
215 u16 reg; 208 u16 reg;
216 209
210 if (iio_device_claim_direct_mode(indio_dev))
211 return -EBUSY;
212
217 ret = lidar_get_measurement(data, &reg); 213 ret = lidar_get_measurement(data, &reg);
218 if (!ret) { 214 if (!ret) {
219 *val = reg; 215 *val = reg;
220 ret = IIO_VAL_INT; 216 ret = IIO_VAL_INT;
221 } 217 }
218 iio_device_release_direct_mode(indio_dev);
222 break; 219 break;
223 } 220 }
224 case IIO_CHAN_INFO_SCALE: 221 case IIO_CHAN_INFO_SCALE:
@@ -228,9 +225,6 @@ static int lidar_read_raw(struct iio_dev *indio_dev,
228 break; 225 break;
229 } 226 }
230 227
231error_busy:
232 mutex_unlock(&indio_dev->mlock);
233
234 return ret; 228 return ret;
235} 229}
236 230
diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
index a8f533af9eca..53c5425d02b3 100644
--- a/drivers/staging/iio/accel/sca3000_core.c
+++ b/drivers/staging/iio/accel/sca3000_core.c
@@ -1046,6 +1046,8 @@ static int sca3000_clean_setup(struct sca3000_state *st)
1046 1046
1047 /* Disable ring buffer */ 1047 /* Disable ring buffer */
1048 ret = sca3000_read_ctrl_reg(st, SCA3000_REG_CTRL_SEL_OUT_CTRL); 1048 ret = sca3000_read_ctrl_reg(st, SCA3000_REG_CTRL_SEL_OUT_CTRL);
1049 if (ret < 0)
1050 goto error_ret;
1049 ret = sca3000_write_ctrl_reg(st, SCA3000_REG_CTRL_SEL_OUT_CTRL, 1051 ret = sca3000_write_ctrl_reg(st, SCA3000_REG_CTRL_SEL_OUT_CTRL,
1050 (ret & SCA3000_OUT_CTRL_PROT_MASK) 1052 (ret & SCA3000_OUT_CTRL_PROT_MASK)
1051 | SCA3000_OUT_CTRL_BUF_X_EN 1053 | SCA3000_OUT_CTRL_BUF_X_EN
diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c
index e8c30521e99c..0e8a1f7a292d 100644
--- a/tools/iio/iio_generic_buffer.c
+++ b/tools/iio/iio_generic_buffer.c
@@ -341,7 +341,7 @@ int main(int argc, char **argv)
341 341
342 char *data = NULL; 342 char *data = NULL;
343 ssize_t read_size; 343 ssize_t read_size;
344 int dev_num = -1, trig_num; 344 int dev_num = -1, trig_num = -1;
345 char *buffer_access = NULL; 345 char *buffer_access = NULL;
346 int scan_size; 346 int scan_size;
347 int noevents = 0; 347 int noevents = 0;
@@ -456,7 +456,7 @@ int main(int argc, char **argv)
456 456
457 if (notrigger) { 457 if (notrigger) {
458 printf("trigger-less mode selected\n"); 458 printf("trigger-less mode selected\n");
459 } if (trig_num > 0) { 459 } if (trig_num >= 0) {
460 char *trig_dev_name; 460 char *trig_dev_name;
461 ret = asprintf(&trig_dev_name, "%strigger%d", iio_dir, trig_num); 461 ret = asprintf(&trig_dev_name, "%strigger%d", iio_dir, trig_num);
462 if (ret < 0) { 462 if (ret < 0) {