aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-08-23 17:39:31 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-08-23 17:39:31 -0400
commiteafe5cfe718926c1ed8b3dacd2191c189b3cdcd2 (patch)
tree0297efe4a906d650fad0e162a1b450418de3979a
parentc0678b2d6648ab65b68703044709e367799ba9f9 (diff)
parent3d4267a5a3a4b7619b80ad1839d8b3bedd8b7a8d (diff)
Merge tag 'iio-fixes-for-4.8a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into work-linus
Jonathan writes: First round of IIO fixes for the 4.8 cycle. This is somewhat of a bumper set due to my unavailabilty earlier in the month. The only slightly unusual ones are the dts updates for the rockchip adc reset. The fix in the driver only makes sense with these and the rockchip maintainer is happy with them going through IIO to reach mainline. Core stuff * Fix an issue with a blocking op when !TASK_RUNNING. This been there a while and snuck in with seemingly minor additions to some core code paths. * Tools - generic_buffer failed to initialize the channel array pointer thus in the case of no channels blows up trying to free a random memory address. * sw-trigger: - Fix config group initialization when configfs is built as a module. Drivers * ad5933 - Fix an incorrect overwrite of an error value. * ad799x - A missed assignment of the update_scan_mode callback means buffered mode doesn't work on the ad7991, ad7995 or ad7999. * ads1015 - wrong pointer returned from i2c_get_clientdata (missmatch of assumptions) * am2315 - Timestamps are reported, but never actually acquired from anywhere (so always 0) - missing buffer selects in Kconfig * am335x adc - Protect fifo1 from concurrent access. - Increase timeout waiting for ADC to be long enough in all cases. * as3935 - Timestamps are reported, but never actually acquired from anywhere (so always 0) * at91 - Fix reading of channel 3. * atlas-ph-sensor - Typo means that the scale of electrical conductivity readings is way off. * bma220 - Timestamps are reported, but never actually acquired from anywhere (so always 0) - Missing buffer selects in Kconfig * bmp280 - pass the write pointer to PTR_ERR (i.e. the one that was just checked with IS_ERR). - suspend /resume crash due to wrong assumption about what dev_get_drvdata would return. * hdc100x - It superficially appeared that smbus_read_byte commands would allow reading of the outputs in two goes. In reality it doesn't work, but instead returns the same for the upper and lower bytes (nice catch from Alison!) * kxsd9 - Fix raw read return value to ensure it actually reports the value rather than a blank string. * max44000 - Missing buffer selects in Kconfig * rockchip_saradc - Add use of reset controller to enforce a clean state of the ADC. Some bootloaders can leave it in an 'intersting' state and effectively frozen without this. A couple of associated dts updates. * stk8ba50 - Missing buffer selects in Kconfig * stx104 - Fix a possible race due to use of devm_iio_device_register when there was other stuff in the remove function.
-rw-r--r--Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt7
-rw-r--r--arch/arm/boot/dts/rk3066a.dtsi2
-rw-r--r--arch/arm/boot/dts/rk3288.dtsi2
-rw-r--r--arch/arm/boot/dts/rk3xxx.dtsi2
-rw-r--r--arch/arm64/boot/dts/rockchip/rk3368.dtsi2
-rw-r--r--drivers/iio/accel/Kconfig5
-rw-r--r--drivers/iio/accel/bma220_spi.c2
-rw-r--r--drivers/iio/accel/kxsd9.c1
-rw-r--r--drivers/iio/adc/Kconfig1
-rw-r--r--drivers/iio/adc/ad799x.c1
-rw-r--r--drivers/iio/adc/at91_adc.c4
-rw-r--r--drivers/iio/adc/rockchip_saradc.c30
-rw-r--r--drivers/iio/adc/ti-ads1015.c3
-rw-r--r--drivers/iio/adc/ti_am335x_adc.c16
-rw-r--r--drivers/iio/chemical/atlas-ph-sensor.c2
-rw-r--r--drivers/iio/dac/stx104.c38
-rw-r--r--drivers/iio/humidity/Kconfig2
-rw-r--r--drivers/iio/humidity/am2315.c2
-rw-r--r--drivers/iio/humidity/hdc100x.c27
-rw-r--r--drivers/iio/industrialio-buffer.c23
-rw-r--r--drivers/iio/light/Kconfig2
-rw-r--r--drivers/iio/pressure/bmp280-core.c8
-rw-r--r--drivers/iio/proximity/as3935.c2
-rw-r--r--drivers/staging/iio/impedance-analyzer/ad5933.c2
-rw-r--r--include/linux/iio/sw_trigger.h2
-rw-r--r--include/linux/mfd/ti_am335x_tscadc.h8
-rw-r--r--tools/iio/iio_generic_buffer.c2
27 files changed, 141 insertions, 57 deletions
diff --git a/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt b/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt
index bf99e2f24788..205593f56fe7 100644
--- a/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt
@@ -16,6 +16,11 @@ Required properties:
16- vref-supply: The regulator supply ADC reference voltage. 16- vref-supply: The regulator supply ADC reference voltage.
17- #io-channel-cells: Should be 1, see ../iio-bindings.txt 17- #io-channel-cells: Should be 1, see ../iio-bindings.txt
18 18
19Optional properties:
20- resets: Must contain an entry for each entry in reset-names if need support
21 this option. See ../reset/reset.txt for details.
22- reset-names: Must include the name "saradc-apb".
23
19Example: 24Example:
20 saradc: saradc@2006c000 { 25 saradc: saradc@2006c000 {
21 compatible = "rockchip,saradc"; 26 compatible = "rockchip,saradc";
@@ -23,6 +28,8 @@ Example:
23 interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>; 28 interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
24 clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>; 29 clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>;
25 clock-names = "saradc", "apb_pclk"; 30 clock-names = "saradc", "apb_pclk";
31 resets = <&cru SRST_SARADC>;
32 reset-names = "saradc-apb";
26 #io-channel-cells = <1>; 33 #io-channel-cells = <1>;
27 vref-supply = <&vcc18>; 34 vref-supply = <&vcc18>;
28 }; 35 };
diff --git a/arch/arm/boot/dts/rk3066a.dtsi b/arch/arm/boot/dts/rk3066a.dtsi
index c0ba86c3a2ab..0d0dae3a1694 100644
--- a/arch/arm/boot/dts/rk3066a.dtsi
+++ b/arch/arm/boot/dts/rk3066a.dtsi
@@ -197,6 +197,8 @@
197 clock-names = "saradc", "apb_pclk"; 197 clock-names = "saradc", "apb_pclk";
198 interrupts = <GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH>; 198 interrupts = <GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH>;
199 #io-channel-cells = <1>; 199 #io-channel-cells = <1>;
200 resets = <&cru SRST_SARADC>;
201 reset-names = "saradc-apb";
200 status = "disabled"; 202 status = "disabled";
201 }; 203 };
202 204
diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index cd33f0170890..91c4b3c7a8d5 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -279,6 +279,8 @@
279 #io-channel-cells = <1>; 279 #io-channel-cells = <1>;
280 clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>; 280 clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>;
281 clock-names = "saradc", "apb_pclk"; 281 clock-names = "saradc", "apb_pclk";
282 resets = <&cru SRST_SARADC>;
283 reset-names = "saradc-apb";
282 status = "disabled"; 284 status = "disabled";
283 }; 285 };
284 286
diff --git a/arch/arm/boot/dts/rk3xxx.dtsi b/arch/arm/boot/dts/rk3xxx.dtsi
index 99bbcc2c9b89..e2cd683b4e4b 100644
--- a/arch/arm/boot/dts/rk3xxx.dtsi
+++ b/arch/arm/boot/dts/rk3xxx.dtsi
@@ -399,6 +399,8 @@
399 #io-channel-cells = <1>; 399 #io-channel-cells = <1>;
400 clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>; 400 clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>;
401 clock-names = "saradc", "apb_pclk"; 401 clock-names = "saradc", "apb_pclk";
402 resets = <&cru SRST_SARADC>;
403 reset-names = "saradc-apb";
402 status = "disabled"; 404 status = "disabled";
403 }; 405 };
404 406
diff --git a/arch/arm64/boot/dts/rockchip/rk3368.dtsi b/arch/arm64/boot/dts/rockchip/rk3368.dtsi
index d02a900378e1..4f44d1191bfd 100644
--- a/arch/arm64/boot/dts/rockchip/rk3368.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3368.dtsi
@@ -270,6 +270,8 @@
270 #io-channel-cells = <1>; 270 #io-channel-cells = <1>;
271 clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>; 271 clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>;
272 clock-names = "saradc", "apb_pclk"; 272 clock-names = "saradc", "apb_pclk";
273 resets = <&cru SRST_SARADC>;
274 reset-names = "saradc-apb";
273 status = "disabled"; 275 status = "disabled";
274 }; 276 };
275 277
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 89d78208de3f..78f148ea9d9f 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -20,6 +20,8 @@ config BMA180
20config BMA220 20config BMA220
21 tristate "Bosch BMA220 3-Axis Accelerometer Driver" 21 tristate "Bosch BMA220 3-Axis Accelerometer Driver"
22 depends on SPI 22 depends on SPI
23 select IIO_BUFFER
24 select IIO_TRIGGERED_BUFFER
23 help 25 help
24 Say yes here to add support for the Bosch BMA220 triaxial 26 Say yes here to add support for the Bosch BMA220 triaxial
25 acceleration sensor. 27 acceleration sensor.
@@ -234,7 +236,8 @@ config STK8312
234config STK8BA50 236config STK8BA50
235 tristate "Sensortek STK8BA50 3-Axis Accelerometer Driver" 237 tristate "Sensortek STK8BA50 3-Axis Accelerometer Driver"
236 depends on I2C 238 depends on I2C
237 depends on IIO_TRIGGER 239 select IIO_BUFFER
240 select IIO_TRIGGERED_BUFFER
238 help 241 help
239 Say yes here to get support for the Sensortek STK8BA50 3-axis 242 Say yes here to get support for the Sensortek STK8BA50 3-axis
240 accelerometer. 243 accelerometer.
diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
index 1098d10df8e8..5099f295dd37 100644
--- a/drivers/iio/accel/bma220_spi.c
+++ b/drivers/iio/accel/bma220_spi.c
@@ -253,7 +253,7 @@ static int bma220_probe(struct spi_device *spi)
253 if (ret < 0) 253 if (ret < 0)
254 return ret; 254 return ret;
255 255
256 ret = iio_triggered_buffer_setup(indio_dev, NULL, 256 ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time,
257 bma220_trigger_handler, NULL); 257 bma220_trigger_handler, NULL);
258 if (ret < 0) { 258 if (ret < 0) {
259 dev_err(&spi->dev, "iio triggered buffer setup failed\n"); 259 dev_err(&spi->dev, "iio triggered buffer setup failed\n");
diff --git a/drivers/iio/accel/kxsd9.c b/drivers/iio/accel/kxsd9.c
index 3a9f106787d2..da5fb67ecb34 100644
--- a/drivers/iio/accel/kxsd9.c
+++ b/drivers/iio/accel/kxsd9.c
@@ -160,6 +160,7 @@ static int kxsd9_read_raw(struct iio_dev *indio_dev,
160 if (ret < 0) 160 if (ret < 0)
161 goto error_ret; 161 goto error_ret;
162 *val = ret; 162 *val = ret;
163 ret = IIO_VAL_INT;
163 break; 164 break;
164 case IIO_CHAN_INFO_SCALE: 165 case IIO_CHAN_INFO_SCALE:
165 ret = spi_w8r8(st->us, KXSD9_READ(KXSD9_REG_CTRL_C)); 166 ret = spi_w8r8(st->us, KXSD9_READ(KXSD9_REG_CTRL_C));
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 1de31bdd4ce4..767577298ee3 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -389,6 +389,7 @@ config QCOM_SPMI_VADC
389config ROCKCHIP_SARADC 389config ROCKCHIP_SARADC
390 tristate "Rockchip SARADC driver" 390 tristate "Rockchip SARADC driver"
391 depends on ARCH_ROCKCHIP || (ARM && COMPILE_TEST) 391 depends on ARCH_ROCKCHIP || (ARM && COMPILE_TEST)
392 depends on RESET_CONTROLLER
392 help 393 help
393 Say yes here to build support for the SARADC found in SoCs from 394 Say yes here to build support for the SARADC found in SoCs from
394 Rockchip. 395 Rockchip.
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index b6163764489c..9704090b7908 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -527,6 +527,7 @@ static struct attribute_group ad799x_event_attrs_group = {
527static const struct iio_info ad7991_info = { 527static const struct iio_info ad7991_info = {
528 .read_raw = &ad799x_read_raw, 528 .read_raw = &ad799x_read_raw,
529 .driver_module = THIS_MODULE, 529 .driver_module = THIS_MODULE,
530 .update_scan_mode = ad799x_update_scan_mode,
530}; 531};
531 532
532static const struct iio_info ad7993_4_7_8_noirq_info = { 533static const struct iio_info ad7993_4_7_8_noirq_info = {
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 52430ba171f3..0438c68015e8 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -381,8 +381,8 @@ static irqreturn_t at91_adc_rl_interrupt(int irq, void *private)
381 st->ts_bufferedmeasure = false; 381 st->ts_bufferedmeasure = false;
382 input_report_key(st->ts_input, BTN_TOUCH, 0); 382 input_report_key(st->ts_input, BTN_TOUCH, 0);
383 input_sync(st->ts_input); 383 input_sync(st->ts_input);
384 } else if (status & AT91_ADC_EOC(3)) { 384 } else if (status & AT91_ADC_EOC(3) && st->ts_input) {
385 /* Conversion finished */ 385 /* Conversion finished and we've a touchscreen */
386 if (st->ts_bufferedmeasure) { 386 if (st->ts_bufferedmeasure) {
387 /* 387 /*
388 * Last measurement is always discarded, since it can 388 * Last measurement is always discarded, since it can
diff --git a/drivers/iio/adc/rockchip_saradc.c b/drivers/iio/adc/rockchip_saradc.c
index f9ad6c2d6821..85d701291654 100644
--- a/drivers/iio/adc/rockchip_saradc.c
+++ b/drivers/iio/adc/rockchip_saradc.c
@@ -21,6 +21,8 @@
21#include <linux/of_device.h> 21#include <linux/of_device.h>
22#include <linux/clk.h> 22#include <linux/clk.h>
23#include <linux/completion.h> 23#include <linux/completion.h>
24#include <linux/delay.h>
25#include <linux/reset.h>
24#include <linux/regulator/consumer.h> 26#include <linux/regulator/consumer.h>
25#include <linux/iio/iio.h> 27#include <linux/iio/iio.h>
26 28
@@ -53,6 +55,7 @@ struct rockchip_saradc {
53 struct clk *clk; 55 struct clk *clk;
54 struct completion completion; 56 struct completion completion;
55 struct regulator *vref; 57 struct regulator *vref;
58 struct reset_control *reset;
56 const struct rockchip_saradc_data *data; 59 const struct rockchip_saradc_data *data;
57 u16 last_val; 60 u16 last_val;
58}; 61};
@@ -190,6 +193,16 @@ static const struct of_device_id rockchip_saradc_match[] = {
190}; 193};
191MODULE_DEVICE_TABLE(of, rockchip_saradc_match); 194MODULE_DEVICE_TABLE(of, rockchip_saradc_match);
192 195
196/**
197 * Reset SARADC Controller.
198 */
199static void rockchip_saradc_reset_controller(struct reset_control *reset)
200{
201 reset_control_assert(reset);
202 usleep_range(10, 20);
203 reset_control_deassert(reset);
204}
205
193static int rockchip_saradc_probe(struct platform_device *pdev) 206static int rockchip_saradc_probe(struct platform_device *pdev)
194{ 207{
195 struct rockchip_saradc *info = NULL; 208 struct rockchip_saradc *info = NULL;
@@ -218,6 +231,20 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
218 if (IS_ERR(info->regs)) 231 if (IS_ERR(info->regs))
219 return PTR_ERR(info->regs); 232 return PTR_ERR(info->regs);
220 233
234 /*
235 * The reset should be an optional property, as it should work
236 * with old devicetrees as well
237 */
238 info->reset = devm_reset_control_get(&pdev->dev, "saradc-apb");
239 if (IS_ERR(info->reset)) {
240 ret = PTR_ERR(info->reset);
241 if (ret != -ENOENT)
242 return ret;
243
244 dev_dbg(&pdev->dev, "no reset control found\n");
245 info->reset = NULL;
246 }
247
221 init_completion(&info->completion); 248 init_completion(&info->completion);
222 249
223 irq = platform_get_irq(pdev, 0); 250 irq = platform_get_irq(pdev, 0);
@@ -252,6 +279,9 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
252 return PTR_ERR(info->vref); 279 return PTR_ERR(info->vref);
253 } 280 }
254 281
282 if (info->reset)
283 rockchip_saradc_reset_controller(info->reset);
284
255 /* 285 /*
256 * Use a default value for the converter clock. 286 * Use a default value for the converter clock.
257 * This may become user-configurable in the future. 287 * This may become user-configurable in the future.
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 1ef398770a1f..066abaf80201 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -489,7 +489,8 @@ static struct iio_info ads1115_info = {
489#ifdef CONFIG_OF 489#ifdef CONFIG_OF
490static int ads1015_get_channels_config_of(struct i2c_client *client) 490static int ads1015_get_channels_config_of(struct i2c_client *client)
491{ 491{
492 struct ads1015_data *data = i2c_get_clientdata(client); 492 struct iio_dev *indio_dev = i2c_get_clientdata(client);
493 struct ads1015_data *data = iio_priv(indio_dev);
493 struct device_node *node; 494 struct device_node *node;
494 495
495 if (!client->dev.of_node || 496 if (!client->dev.of_node ||
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 8a368756881b..c3cfacca2541 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -32,6 +32,7 @@
32 32
33struct tiadc_device { 33struct tiadc_device {
34 struct ti_tscadc_dev *mfd_tscadc; 34 struct ti_tscadc_dev *mfd_tscadc;
35 struct mutex fifo1_lock; /* to protect fifo access */
35 int channels; 36 int channels;
36 u8 channel_line[8]; 37 u8 channel_line[8];
37 u8 channel_step[8]; 38 u8 channel_step[8];
@@ -359,6 +360,7 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
359 int *val, int *val2, long mask) 360 int *val, int *val2, long mask)
360{ 361{
361 struct tiadc_device *adc_dev = iio_priv(indio_dev); 362 struct tiadc_device *adc_dev = iio_priv(indio_dev);
363 int ret = IIO_VAL_INT;
362 int i, map_val; 364 int i, map_val;
363 unsigned int fifo1count, read, stepid; 365 unsigned int fifo1count, read, stepid;
364 bool found = false; 366 bool found = false;
@@ -372,13 +374,14 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
372 if (!step_en) 374 if (!step_en)
373 return -EINVAL; 375 return -EINVAL;
374 376
377 mutex_lock(&adc_dev->fifo1_lock);
375 fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); 378 fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
376 while (fifo1count--) 379 while (fifo1count--)
377 tiadc_readl(adc_dev, REG_FIFO1); 380 tiadc_readl(adc_dev, REG_FIFO1);
378 381
379 am335x_tsc_se_set_once(adc_dev->mfd_tscadc, step_en); 382 am335x_tsc_se_set_once(adc_dev->mfd_tscadc, step_en);
380 383
381 timeout = jiffies + usecs_to_jiffies 384 timeout = jiffies + msecs_to_jiffies
382 (IDLE_TIMEOUT * adc_dev->channels); 385 (IDLE_TIMEOUT * adc_dev->channels);
383 /* Wait for Fifo threshold interrupt */ 386 /* Wait for Fifo threshold interrupt */
384 while (1) { 387 while (1) {
@@ -388,7 +391,8 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
388 391
389 if (time_after(jiffies, timeout)) { 392 if (time_after(jiffies, timeout)) {
390 am335x_tsc_se_adc_done(adc_dev->mfd_tscadc); 393 am335x_tsc_se_adc_done(adc_dev->mfd_tscadc);
391 return -EAGAIN; 394 ret = -EAGAIN;
395 goto err_unlock;
392 } 396 }
393 } 397 }
394 map_val = adc_dev->channel_step[chan->scan_index]; 398 map_val = adc_dev->channel_step[chan->scan_index];
@@ -414,8 +418,11 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
414 am335x_tsc_se_adc_done(adc_dev->mfd_tscadc); 418 am335x_tsc_se_adc_done(adc_dev->mfd_tscadc);
415 419
416 if (found == false) 420 if (found == false)
417 return -EBUSY; 421 ret = -EBUSY;
418 return IIO_VAL_INT; 422
423err_unlock:
424 mutex_unlock(&adc_dev->fifo1_lock);
425 return ret;
419} 426}
420 427
421static const struct iio_info tiadc_info = { 428static const struct iio_info tiadc_info = {
@@ -483,6 +490,7 @@ static int tiadc_probe(struct platform_device *pdev)
483 490
484 tiadc_step_config(indio_dev); 491 tiadc_step_config(indio_dev);
485 tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD); 492 tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD);
493 mutex_init(&adc_dev->fifo1_lock);
486 494
487 err = tiadc_channel_init(indio_dev, adc_dev->channels); 495 err = tiadc_channel_init(indio_dev, adc_dev->channels);
488 if (err < 0) 496 if (err < 0)
diff --git a/drivers/iio/chemical/atlas-ph-sensor.c b/drivers/iio/chemical/atlas-ph-sensor.c
index ae038a59d256..407f141a1eee 100644
--- a/drivers/iio/chemical/atlas-ph-sensor.c
+++ b/drivers/iio/chemical/atlas-ph-sensor.c
@@ -434,7 +434,7 @@ static int atlas_read_raw(struct iio_dev *indio_dev,
434 break; 434 break;
435 case IIO_ELECTRICALCONDUCTIVITY: 435 case IIO_ELECTRICALCONDUCTIVITY:
436 *val = 1; /* 0.00001 */ 436 *val = 1; /* 0.00001 */
437 *val = 100000; 437 *val2 = 100000;
438 break; 438 break;
439 case IIO_CONCENTRATION: 439 case IIO_CONCENTRATION:
440 *val = 0; /* 0.000000001 */ 440 *val = 0; /* 0.000000001 */
diff --git a/drivers/iio/dac/stx104.c b/drivers/iio/dac/stx104.c
index 792a97164cb2..bebbd00304ce 100644
--- a/drivers/iio/dac/stx104.c
+++ b/drivers/iio/dac/stx104.c
@@ -65,6 +65,16 @@ struct stx104_gpio {
65 unsigned int out_state; 65 unsigned int out_state;
66}; 66};
67 67
68/**
69 * struct stx104_dev - STX104 device private data structure
70 * @indio_dev: IIO device
71 * @chip: instance of the gpio_chip
72 */
73struct stx104_dev {
74 struct iio_dev *indio_dev;
75 struct gpio_chip *chip;
76};
77
68static int stx104_read_raw(struct iio_dev *indio_dev, 78static int stx104_read_raw(struct iio_dev *indio_dev,
69 struct iio_chan_spec const *chan, int *val, int *val2, long mask) 79 struct iio_chan_spec const *chan, int *val, int *val2, long mask)
70{ 80{
@@ -107,6 +117,7 @@ static const struct iio_chan_spec stx104_channels[STX104_NUM_CHAN] = {
107static int stx104_gpio_get_direction(struct gpio_chip *chip, 117static int stx104_gpio_get_direction(struct gpio_chip *chip,
108 unsigned int offset) 118 unsigned int offset)
109{ 119{
120 /* GPIO 0-3 are input only, while the rest are output only */
110 if (offset < 4) 121 if (offset < 4)
111 return 1; 122 return 1;
112 123
@@ -169,6 +180,7 @@ static int stx104_probe(struct device *dev, unsigned int id)
169 struct iio_dev *indio_dev; 180 struct iio_dev *indio_dev;
170 struct stx104_iio *priv; 181 struct stx104_iio *priv;
171 struct stx104_gpio *stx104gpio; 182 struct stx104_gpio *stx104gpio;
183 struct stx104_dev *stx104dev;
172 int err; 184 int err;
173 185
174 indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); 186 indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
@@ -179,6 +191,10 @@ static int stx104_probe(struct device *dev, unsigned int id)
179 if (!stx104gpio) 191 if (!stx104gpio)
180 return -ENOMEM; 192 return -ENOMEM;
181 193
194 stx104dev = devm_kzalloc(dev, sizeof(*stx104dev), GFP_KERNEL);
195 if (!stx104dev)
196 return -ENOMEM;
197
182 if (!devm_request_region(dev, base[id], STX104_EXTENT, 198 if (!devm_request_region(dev, base[id], STX104_EXTENT,
183 dev_name(dev))) { 199 dev_name(dev))) {
184 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", 200 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n",
@@ -199,12 +215,6 @@ static int stx104_probe(struct device *dev, unsigned int id)
199 outw(0, base[id] + 4); 215 outw(0, base[id] + 4);
200 outw(0, base[id] + 6); 216 outw(0, base[id] + 6);
201 217
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); 218 stx104gpio->chip.label = dev_name(dev);
209 stx104gpio->chip.parent = dev; 219 stx104gpio->chip.parent = dev;
210 stx104gpio->chip.owner = THIS_MODULE; 220 stx104gpio->chip.owner = THIS_MODULE;
@@ -220,7 +230,9 @@ static int stx104_probe(struct device *dev, unsigned int id)
220 230
221 spin_lock_init(&stx104gpio->lock); 231 spin_lock_init(&stx104gpio->lock);
222 232
223 dev_set_drvdata(dev, stx104gpio); 233 stx104dev->indio_dev = indio_dev;
234 stx104dev->chip = &stx104gpio->chip;
235 dev_set_drvdata(dev, stx104dev);
224 236
225 err = gpiochip_add_data(&stx104gpio->chip, stx104gpio); 237 err = gpiochip_add_data(&stx104gpio->chip, stx104gpio);
226 if (err) { 238 if (err) {
@@ -228,14 +240,22 @@ static int stx104_probe(struct device *dev, unsigned int id)
228 return err; 240 return err;
229 } 241 }
230 242
243 err = iio_device_register(indio_dev);
244 if (err) {
245 dev_err(dev, "IIO device registering failed (%d)\n", err);
246 gpiochip_remove(&stx104gpio->chip);
247 return err;
248 }
249
231 return 0; 250 return 0;
232} 251}
233 252
234static int stx104_remove(struct device *dev, unsigned int id) 253static int stx104_remove(struct device *dev, unsigned int id)
235{ 254{
236 struct stx104_gpio *const stx104gpio = dev_get_drvdata(dev); 255 struct stx104_dev *const stx104dev = dev_get_drvdata(dev);
237 256
238 gpiochip_remove(&stx104gpio->chip); 257 iio_device_unregister(stx104dev->indio_dev);
258 gpiochip_remove(stx104dev->chip);
239 259
240 return 0; 260 return 0;
241} 261}
diff --git a/drivers/iio/humidity/Kconfig b/drivers/iio/humidity/Kconfig
index 738a86d9e4a9..d04124345992 100644
--- a/drivers/iio/humidity/Kconfig
+++ b/drivers/iio/humidity/Kconfig
@@ -6,6 +6,8 @@ menu "Humidity sensors"
6config AM2315 6config AM2315
7 tristate "Aosong AM2315 relative humidity and temperature sensor" 7 tristate "Aosong AM2315 relative humidity and temperature sensor"
8 depends on I2C 8 depends on I2C
9 select IIO_BUFFER
10 select IIO_TRIGGERED_BUFFER
9 help 11 help
10 If you say yes here you get support for the Aosong AM2315 12 If you say yes here you get support for the Aosong AM2315
11 relative humidity and ambient temperature sensor. 13 relative humidity and ambient temperature sensor.
diff --git a/drivers/iio/humidity/am2315.c b/drivers/iio/humidity/am2315.c
index 3e200f69e886..ff96b6d0fdae 100644
--- a/drivers/iio/humidity/am2315.c
+++ b/drivers/iio/humidity/am2315.c
@@ -244,7 +244,7 @@ static int am2315_probe(struct i2c_client *client,
244 indio_dev->channels = am2315_channels; 244 indio_dev->channels = am2315_channels;
245 indio_dev->num_channels = ARRAY_SIZE(am2315_channels); 245 indio_dev->num_channels = ARRAY_SIZE(am2315_channels);
246 246
247 ret = iio_triggered_buffer_setup(indio_dev, NULL, 247 ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time,
248 am2315_trigger_handler, NULL); 248 am2315_trigger_handler, NULL);
249 if (ret < 0) { 249 if (ret < 0) {
250 dev_err(&client->dev, "iio triggered buffer setup failed\n"); 250 dev_err(&client->dev, "iio triggered buffer setup failed\n");
diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
index a03832a5fc95..e0c9c70c2a4a 100644
--- a/drivers/iio/humidity/hdc100x.c
+++ b/drivers/iio/humidity/hdc100x.c
@@ -142,7 +142,7 @@ static int hdc100x_get_measurement(struct hdc100x_data *data,
142 struct i2c_client *client = data->client; 142 struct i2c_client *client = data->client;
143 int delay = data->adc_int_us[chan->address]; 143 int delay = data->adc_int_us[chan->address];
144 int ret; 144 int ret;
145 int val; 145 __be16 val;
146 146
147 /* start measurement */ 147 /* start measurement */
148 ret = i2c_smbus_write_byte(client, chan->address); 148 ret = i2c_smbus_write_byte(client, chan->address);
@@ -154,26 +154,13 @@ static int hdc100x_get_measurement(struct hdc100x_data *data,
154 /* wait for integration time to pass */ 154 /* wait for integration time to pass */
155 usleep_range(delay, delay + 1000); 155 usleep_range(delay, delay + 1000);
156 156
157 /* 157 /* read measurement */
158 * i2c_smbus_read_word_data cannot() be used here due to the command 158 ret = i2c_master_recv(data->client, (char *)&val, sizeof(val));
159 * value not being understood and causes NAKs preventing any reading
160 * from being accessed.
161 */
162 ret = i2c_smbus_read_byte(client);
163 if (ret < 0) { 159 if (ret < 0) {
164 dev_err(&client->dev, "cannot read high byte measurement"); 160 dev_err(&client->dev, "cannot read sensor data\n");
165 return ret; 161 return ret;
166 } 162 }
167 val = ret << 8; 163 return be16_to_cpu(val);
168
169 ret = i2c_smbus_read_byte(client);
170 if (ret < 0) {
171 dev_err(&client->dev, "cannot read low byte measurement");
172 return ret;
173 }
174 val |= ret;
175
176 return val;
177} 164}
178 165
179static int hdc100x_get_heater_status(struct hdc100x_data *data) 166static int hdc100x_get_heater_status(struct hdc100x_data *data)
@@ -272,8 +259,8 @@ static int hdc100x_probe(struct i2c_client *client,
272 struct iio_dev *indio_dev; 259 struct iio_dev *indio_dev;
273 struct hdc100x_data *data; 260 struct hdc100x_data *data;
274 261
275 if (!i2c_check_functionality(client->adapter, 262 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA |
276 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BYTE)) 263 I2C_FUNC_SMBUS_BYTE | I2C_FUNC_I2C))
277 return -EOPNOTSUPP; 264 return -EOPNOTSUPP;
278 265
279 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 266 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 90462fcf5436..49bf9c59f117 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -107,6 +107,7 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
107{ 107{
108 struct iio_dev *indio_dev = filp->private_data; 108 struct iio_dev *indio_dev = filp->private_data;
109 struct iio_buffer *rb = indio_dev->buffer; 109 struct iio_buffer *rb = indio_dev->buffer;
110 DEFINE_WAIT_FUNC(wait, woken_wake_function);
110 size_t datum_size; 111 size_t datum_size;
111 size_t to_wait; 112 size_t to_wait;
112 int ret; 113 int ret;
@@ -131,19 +132,29 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
131 else 132 else
132 to_wait = min_t(size_t, n / datum_size, rb->watermark); 133 to_wait = min_t(size_t, n / datum_size, rb->watermark);
133 134
135 add_wait_queue(&rb->pollq, &wait);
134 do { 136 do {
135 ret = wait_event_interruptible(rb->pollq, 137 if (!indio_dev->info) {
136 iio_buffer_ready(indio_dev, rb, to_wait, n / datum_size)); 138 ret = -ENODEV;
137 if (ret) 139 break;
138 return ret; 140 }
139 141
140 if (!indio_dev->info) 142 if (!iio_buffer_ready(indio_dev, rb, to_wait, n / datum_size)) {
141 return -ENODEV; 143 if (signal_pending(current)) {
144 ret = -ERESTARTSYS;
145 break;
146 }
147
148 wait_woken(&wait, TASK_INTERRUPTIBLE,
149 MAX_SCHEDULE_TIMEOUT);
150 continue;
151 }
142 152
143 ret = rb->access->read_first_n(rb, n, buf); 153 ret = rb->access->read_first_n(rb, n, buf);
144 if (ret == 0 && (filp->f_flags & O_NONBLOCK)) 154 if (ret == 0 && (filp->f_flags & O_NONBLOCK))
145 ret = -EAGAIN; 155 ret = -EAGAIN;
146 } while (ret == 0); 156 } while (ret == 0);
157 remove_wait_queue(&rb->pollq, &wait);
147 158
148 return ret; 159 return ret;
149} 160}
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 7c566f516572..12ceb11bc7c5 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -238,6 +238,8 @@ config MAX44000
238 tristate "MAX44000 Ambient and Infrared Proximity Sensor" 238 tristate "MAX44000 Ambient and Infrared Proximity Sensor"
239 depends on I2C 239 depends on I2C
240 select REGMAP_I2C 240 select REGMAP_I2C
241 select IIO_BUFFER
242 select IIO_TRIGGERED_BUFFER
241 help 243 help
242 Say Y here if you want to build support for Maxim Integrated's 244 Say Y here if you want to build support for Maxim Integrated's
243 MAX44000 ambient and infrared proximity sensor device. 245 MAX44000 ambient and infrared proximity sensor device.
diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index 6943688e66df..e5a533cbd53f 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -970,7 +970,7 @@ int bmp280_common_probe(struct device *dev,
970 data->vdda = devm_regulator_get(dev, "vdda"); 970 data->vdda = devm_regulator_get(dev, "vdda");
971 if (IS_ERR(data->vdda)) { 971 if (IS_ERR(data->vdda)) {
972 dev_err(dev, "failed to get VDDA regulator\n"); 972 dev_err(dev, "failed to get VDDA regulator\n");
973 ret = PTR_ERR(data->vddd); 973 ret = PTR_ERR(data->vdda);
974 goto out_disable_vddd; 974 goto out_disable_vddd;
975 } 975 }
976 ret = regulator_enable(data->vdda); 976 ret = regulator_enable(data->vdda);
@@ -1079,7 +1079,8 @@ EXPORT_SYMBOL(bmp280_common_remove);
1079#ifdef CONFIG_PM 1079#ifdef CONFIG_PM
1080static int bmp280_runtime_suspend(struct device *dev) 1080static int bmp280_runtime_suspend(struct device *dev)
1081{ 1081{
1082 struct bmp280_data *data = dev_get_drvdata(dev); 1082 struct iio_dev *indio_dev = dev_get_drvdata(dev);
1083 struct bmp280_data *data = iio_priv(indio_dev);
1083 int ret; 1084 int ret;
1084 1085
1085 ret = regulator_disable(data->vdda); 1086 ret = regulator_disable(data->vdda);
@@ -1090,7 +1091,8 @@ static int bmp280_runtime_suspend(struct device *dev)
1090 1091
1091static int bmp280_runtime_resume(struct device *dev) 1092static int bmp280_runtime_resume(struct device *dev)
1092{ 1093{
1093 struct bmp280_data *data = dev_get_drvdata(dev); 1094 struct iio_dev *indio_dev = dev_get_drvdata(dev);
1095 struct bmp280_data *data = iio_priv(indio_dev);
1094 int ret; 1096 int ret;
1095 1097
1096 ret = regulator_enable(data->vddd); 1098 ret = regulator_enable(data->vddd);
diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
index 2e3a70e1b245..5656deb17261 100644
--- a/drivers/iio/proximity/as3935.c
+++ b/drivers/iio/proximity/as3935.c
@@ -397,7 +397,7 @@ static int as3935_probe(struct spi_device *spi)
397 return ret; 397 return ret;
398 } 398 }
399 399
400 ret = iio_triggered_buffer_setup(indio_dev, NULL, 400 ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time,
401 &as3935_trigger_handler, NULL); 401 &as3935_trigger_handler, NULL);
402 402
403 if (ret) { 403 if (ret) {
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 170ac980abcb..24c348d2f5bb 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -419,6 +419,7 @@ static ssize_t ad5933_store(struct device *dev,
419 mutex_lock(&indio_dev->mlock); 419 mutex_lock(&indio_dev->mlock);
420 switch ((u32)this_attr->address) { 420 switch ((u32)this_attr->address) {
421 case AD5933_OUT_RANGE: 421 case AD5933_OUT_RANGE:
422 ret = -EINVAL;
422 for (i = 0; i < 4; i++) 423 for (i = 0; i < 4; i++)
423 if (val == st->range_avail[i]) { 424 if (val == st->range_avail[i]) {
424 st->ctrl_hb &= ~AD5933_CTRL_RANGE(0x3); 425 st->ctrl_hb &= ~AD5933_CTRL_RANGE(0x3);
@@ -426,7 +427,6 @@ static ssize_t ad5933_store(struct device *dev,
426 ret = ad5933_cmd(st, 0); 427 ret = ad5933_cmd(st, 0);
427 break; 428 break;
428 } 429 }
429 ret = -EINVAL;
430 break; 430 break;
431 case AD5933_IN_PGA_GAIN: 431 case AD5933_IN_PGA_GAIN:
432 if (sysfs_streq(buf, "1")) { 432 if (sysfs_streq(buf, "1")) {
diff --git a/include/linux/iio/sw_trigger.h b/include/linux/iio/sw_trigger.h
index 5198f8ed08a4..c97eab67558f 100644
--- a/include/linux/iio/sw_trigger.h
+++ b/include/linux/iio/sw_trigger.h
@@ -62,7 +62,7 @@ void iio_swt_group_init_type_name(struct iio_sw_trigger *t,
62 const char *name, 62 const char *name,
63 struct config_item_type *type) 63 struct config_item_type *type)
64{ 64{
65#ifdef CONFIG_CONFIGFS_FS 65#if IS_ENABLED(CONFIG_CONFIGFS_FS)
66 config_group_init_type_name(&t->group, name, type); 66 config_group_init_type_name(&t->group, name, type);
67#endif 67#endif
68} 68}
diff --git a/include/linux/mfd/ti_am335x_tscadc.h b/include/linux/mfd/ti_am335x_tscadc.h
index 2567a87872b0..7f55b8b41032 100644
--- a/include/linux/mfd/ti_am335x_tscadc.h
+++ b/include/linux/mfd/ti_am335x_tscadc.h
@@ -138,16 +138,16 @@
138/* 138/*
139 * time in us for processing a single channel, calculated as follows: 139 * time in us for processing a single channel, calculated as follows:
140 * 140 *
141 * num cycles = open delay + (sample delay + conv time) * averaging 141 * max num cycles = open delay + (sample delay + conv time) * averaging
142 * 142 *
143 * num cycles: 152 + (1 + 13) * 16 = 376 143 * max num cycles: 262143 + (255 + 13) * 16 = 266431
144 * 144 *
145 * clock frequency: 26MHz / 8 = 3.25MHz 145 * clock frequency: 26MHz / 8 = 3.25MHz
146 * clock period: 1 / 3.25MHz = 308ns 146 * clock period: 1 / 3.25MHz = 308ns
147 * 147 *
148 * processing time: 376 * 308ns = 116us 148 * max processing time: 266431 * 308ns = 83ms(approx)
149 */ 149 */
150#define IDLE_TIMEOUT 116 /* microsec */ 150#define IDLE_TIMEOUT 83 /* milliseconds */
151 151
152#define TSCADC_CELLS 2 152#define TSCADC_CELLS 2
153 153
diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c
index 0e8a1f7a292d..ae68bf0e2d51 100644
--- a/tools/iio/iio_generic_buffer.c
+++ b/tools/iio/iio_generic_buffer.c
@@ -348,7 +348,7 @@ int main(int argc, char **argv)
348 int notrigger = 0; 348 int notrigger = 0;
349 char *dummy; 349 char *dummy;
350 350
351 struct iio_channel_info *channels; 351 struct iio_channel_info *channels = NULL;
352 352
353 register_cleanup(); 353 register_cleanup();
354 354