diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-09-14 14:42:03 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-09-14 14:42:03 -0400 |
commit | 552edf8d79096c7458cdc2a7b1f9936e7925e2aa (patch) | |
tree | e069ed3ec2fc7ef77a98645aa0f5ef84e1c83881 /drivers/iio | |
parent | d2f3e1058c7ff9dc18d14548f6263dcf13af67f7 (diff) | |
parent | 1696566f995cfd4ddf3f167b4097cdc83f1458f2 (diff) |
Merge tag 'iio-for-4.9b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes:
Second set of iio new device support, features and cleanups for the 4.9 cycle.
New device support
* ad8801 dac
- new driver supporting ad8801 and ad8803 DACs.
* adc12138
- new driver supporting TI adc12130/adc12132 and adc12138 ADCs.
* ltc2485 adc
- new driver
* mxc6255
- add support for the mxc6225 part name and fixup the ID check so it works.
* vz89x VOC sensor
- add support for the vz89te part which drops the voc_short channel and adds
CRCs compared to other supported parts.
New features
* core
- immutable triggers. These effectively grant exclusive control over a
trigger. The typical usecase is a device representing an analog part
(perhaps a MUX) that needs to control the sampling of a downstream
ADC.
- resource managed trigger registration and triggered_buffer_init.
- iio_push_event now protected against case of the event interface
registration not having yet occured. Only matters if an interrupt
can occur during this window - might happen on shared interrupt lines.
- helper to let a driver query if the trigger it is using is provided by
itself (using the convention of both device and trigger having the same
parent).
* tools
- iio-utils. Used channel modifier scaling in preference to generic scaling
when both exist.
* at91-adc
- Add support for touchscreen switches closure time needed by some newer
parts.
* stx104
- support the ADC channels on this ADC/DAC board. As these are the primary
feature of the board also move the driver to the iio/adc directory.
* sx9500
- device tree bindings.
Cleanups / Fixes
* ad5755
- fix an off-by-one on devnr limit check (introduced earlier this cycle)
* ad7266
- drop NULL check on devm_regulator_get_optional as it can't return NULL.
* ak8974
- avoid an unused functional warning due to rework in PM core code.
- remove .owner field setting as done by i2c_core.
* ina2xx
- clear out a left over debug field from chip global data.
* hid-sensors
- avoid an unused functional warning due to rework in PM core code.
* maxim-thermocouple
- fix non static symbol warnings.
* ms5611
- fetch and enable regulators unconditionally when they aren't optional.
* sca3000
- whitespace cleanup.
* st_sensors
- fetch and enable regulators unconditionally rather than having them
supported as optional regulators (missunderstanding on my part amongst
others a while back)
- followup to previous patch fixes error checking on the regulators.
- mark symbols static where possible.
- use the 'is it my trigger' help function. This prevents the odd case
of another device triggering from the st-sensors trigger whilst the
st-sensors trigger is itself not using it but rather using say an hrtimer.
* ti-ads1015
- add missing of_node_put.
* vz89x
- rework to all support of new devices.
- prevent reading of a corrupted buffer.
- fixup a return value of 0/1 in a bool returning function.
Address updates
- Vlad Dogaru email address change.
Diffstat (limited to 'drivers/iio')
28 files changed, 1497 insertions, 133 deletions
diff --git a/drivers/iio/accel/mxc6255.c b/drivers/iio/accel/mxc6255.c index 97ccde722e7b..0abad6948201 100644 --- a/drivers/iio/accel/mxc6255.c +++ b/drivers/iio/accel/mxc6255.c | |||
@@ -154,7 +154,7 @@ static int mxc6255_probe(struct i2c_client *client, | |||
154 | return ret; | 154 | return ret; |
155 | } | 155 | } |
156 | 156 | ||
157 | if (chip_id != MXC6255_CHIP_ID) { | 157 | if ((chip_id & 0x1f) != MXC6255_CHIP_ID) { |
158 | dev_err(&client->dev, "Invalid chip id %x\n", chip_id); | 158 | dev_err(&client->dev, "Invalid chip id %x\n", chip_id); |
159 | return -ENODEV; | 159 | return -ENODEV; |
160 | } | 160 | } |
@@ -171,12 +171,14 @@ static int mxc6255_probe(struct i2c_client *client, | |||
171 | } | 171 | } |
172 | 172 | ||
173 | static const struct acpi_device_id mxc6255_acpi_match[] = { | 173 | static const struct acpi_device_id mxc6255_acpi_match[] = { |
174 | {"MXC6225", 0}, | ||
174 | {"MXC6255", 0}, | 175 | {"MXC6255", 0}, |
175 | { } | 176 | { } |
176 | }; | 177 | }; |
177 | MODULE_DEVICE_TABLE(acpi, mxc6255_acpi_match); | 178 | MODULE_DEVICE_TABLE(acpi, mxc6255_acpi_match); |
178 | 179 | ||
179 | static const struct i2c_device_id mxc6255_id[] = { | 180 | static const struct i2c_device_id mxc6255_id[] = { |
181 | {"mxc6225", 0}, | ||
180 | {"mxc6255", 0}, | 182 | {"mxc6255", 0}, |
181 | { } | 183 | { } |
182 | }; | 184 | }; |
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 586830ec8800..7edcf3238620 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig | |||
@@ -264,6 +264,15 @@ config LPC18XX_ADC | |||
264 | To compile this driver as a module, choose M here: the module will be | 264 | To compile this driver as a module, choose M here: the module will be |
265 | called lpc18xx_adc. | 265 | called lpc18xx_adc. |
266 | 266 | ||
267 | config LTC2485 | ||
268 | tristate "Linear Technology LTC2485 ADC driver" | ||
269 | depends on I2C | ||
270 | help | ||
271 | Say yes here to build support for Linear Technology LTC2485 ADC. | ||
272 | |||
273 | To compile this driver as a module, choose M here: the module will be | ||
274 | called ltc2485. | ||
275 | |||
267 | config MAX1027 | 276 | config MAX1027 |
268 | tristate "Maxim max1027 ADC driver" | 277 | tristate "Maxim max1027 ADC driver" |
269 | depends on SPI | 278 | depends on SPI |
@@ -410,6 +419,21 @@ config ROCKCHIP_SARADC | |||
410 | To compile this driver as a module, choose M here: the | 419 | To compile this driver as a module, choose M here: the |
411 | module will be called rockchip_saradc. | 420 | module will be called rockchip_saradc. |
412 | 421 | ||
422 | config STX104 | ||
423 | tristate "Apex Embedded Systems STX104 driver" | ||
424 | depends on X86 && ISA_BUS_API | ||
425 | select GPIOLIB | ||
426 | help | ||
427 | Say yes here to build support for the Apex Embedded Systems STX104 | ||
428 | integrated analog PC/104 card. | ||
429 | |||
430 | This driver supports the 16 channels of single-ended (8 channels of | ||
431 | differential) analog inputs, 2 channels of analog output, 4 digital | ||
432 | inputs, and 4 digital outputs provided by the STX104. | ||
433 | |||
434 | The base port addresses for the devices may be configured via the base | ||
435 | array module parameter. | ||
436 | |||
413 | config TI_ADC081C | 437 | config TI_ADC081C |
414 | tristate "Texas Instruments ADC081C/ADC101C/ADC121C family" | 438 | tristate "Texas Instruments ADC081C/ADC101C/ADC121C family" |
415 | depends on I2C | 439 | depends on I2C |
@@ -430,6 +454,18 @@ config TI_ADC0832 | |||
430 | This driver can also be built as a module. If so, the module will be | 454 | This driver can also be built as a module. If so, the module will be |
431 | called ti-adc0832. | 455 | called ti-adc0832. |
432 | 456 | ||
457 | config TI_ADC12138 | ||
458 | tristate "Texas Instruments ADC12130/ADC12132/ADC12138" | ||
459 | depends on SPI | ||
460 | select IIO_BUFFER | ||
461 | select IIO_TRIGGERED_BUFFER | ||
462 | help | ||
463 | If you say yes here you get support for Texas Instruments ADC12130, | ||
464 | ADC12132 and ADC12138 chips. | ||
465 | |||
466 | This driver can also be built as a module. If so, the module will be | ||
467 | called ti-adc12138. | ||
468 | |||
433 | config TI_ADC128S052 | 469 | config TI_ADC128S052 |
434 | tristate "Texas Instruments ADC128S052/ADC122S021/ADC124S021" | 470 | tristate "Texas Instruments ADC128S052/ADC122S021/ADC124S021" |
435 | depends on SPI | 471 | depends on SPI |
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 33254eb96bec..7a40c04c311f 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile | |||
@@ -27,6 +27,7 @@ obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o | |||
27 | obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o | 27 | obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o |
28 | obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o | 28 | obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o |
29 | obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o | 29 | obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o |
30 | obj-$(CONFIG_LTC2485) += ltc2485.o | ||
30 | obj-$(CONFIG_MAX1027) += max1027.o | 31 | obj-$(CONFIG_MAX1027) += max1027.o |
31 | obj-$(CONFIG_MAX1363) += max1363.o | 32 | obj-$(CONFIG_MAX1363) += max1363.o |
32 | obj-$(CONFIG_MCP320X) += mcp320x.o | 33 | obj-$(CONFIG_MCP320X) += mcp320x.o |
@@ -39,8 +40,10 @@ obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o | |||
39 | obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o | 40 | obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o |
40 | obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o | 41 | obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o |
41 | obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o | 42 | obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o |
43 | obj-$(CONFIG_STX104) += stx104.o | ||
42 | obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o | 44 | obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o |
43 | obj-$(CONFIG_TI_ADC0832) += ti-adc0832.o | 45 | obj-$(CONFIG_TI_ADC0832) += ti-adc0832.o |
46 | obj-$(CONFIG_TI_ADC12138) += ti-adc12138.o | ||
44 | obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o | 47 | obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o |
45 | obj-$(CONFIG_TI_ADC161S626) += ti-adc161s626.o | 48 | obj-$(CONFIG_TI_ADC161S626) += ti-adc161s626.o |
46 | obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o | 49 | obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o |
diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c index c0f6a98fd9bd..b8d5cfd57ec4 100644 --- a/drivers/iio/adc/ad7266.c +++ b/drivers/iio/adc/ad7266.c | |||
@@ -481,7 +481,7 @@ error_free_gpios: | |||
481 | if (!st->fixed_addr) | 481 | if (!st->fixed_addr) |
482 | gpio_free_array(st->gpios, ARRAY_SIZE(st->gpios)); | 482 | gpio_free_array(st->gpios, ARRAY_SIZE(st->gpios)); |
483 | error_disable_reg: | 483 | error_disable_reg: |
484 | if (!IS_ERR_OR_NULL(st->reg)) | 484 | if (!IS_ERR(st->reg)) |
485 | regulator_disable(st->reg); | 485 | regulator_disable(st->reg); |
486 | 486 | ||
487 | return ret; | 487 | return ret; |
@@ -496,7 +496,7 @@ static int ad7266_remove(struct spi_device *spi) | |||
496 | iio_triggered_buffer_cleanup(indio_dev); | 496 | iio_triggered_buffer_cleanup(indio_dev); |
497 | if (!st->fixed_addr) | 497 | if (!st->fixed_addr) |
498 | gpio_free_array(st->gpios, ARRAY_SIZE(st->gpios)); | 498 | gpio_free_array(st->gpios, ARRAY_SIZE(st->gpios)); |
499 | if (!IS_ERR_OR_NULL(st->reg)) | 499 | if (!IS_ERR(st->reg)) |
500 | regulator_disable(st->reg); | 500 | regulator_disable(st->reg); |
501 | 501 | ||
502 | return 0; | 502 | return 0; |
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c index 0438c68015e8..bbdac07f4aaa 100644 --- a/drivers/iio/adc/at91_adc.c +++ b/drivers/iio/adc/at91_adc.c | |||
@@ -113,6 +113,7 @@ | |||
113 | #define AT91_ADC_TSMR_TSAV (3 << 4) /* Averages samples */ | 113 | #define AT91_ADC_TSMR_TSAV (3 << 4) /* Averages samples */ |
114 | #define AT91_ADC_TSMR_TSAV_(x) ((x) << 4) | 114 | #define AT91_ADC_TSMR_TSAV_(x) ((x) << 4) |
115 | #define AT91_ADC_TSMR_SCTIM (0x0f << 16) /* Switch closure time */ | 115 | #define AT91_ADC_TSMR_SCTIM (0x0f << 16) /* Switch closure time */ |
116 | #define AT91_ADC_TSMR_SCTIM_(x) ((x) << 16) | ||
116 | #define AT91_ADC_TSMR_PENDBC (0x0f << 28) /* Pen Debounce time */ | 117 | #define AT91_ADC_TSMR_PENDBC (0x0f << 28) /* Pen Debounce time */ |
117 | #define AT91_ADC_TSMR_PENDBC_(x) ((x) << 28) | 118 | #define AT91_ADC_TSMR_PENDBC_(x) ((x) << 28) |
118 | #define AT91_ADC_TSMR_NOTSDMA (1 << 22) /* No Touchscreen DMA */ | 119 | #define AT91_ADC_TSMR_NOTSDMA (1 << 22) /* No Touchscreen DMA */ |
@@ -150,6 +151,7 @@ | |||
150 | #define MAX_RLPOS_BITS 10 | 151 | #define MAX_RLPOS_BITS 10 |
151 | #define TOUCH_SAMPLE_PERIOD_US_RL 10000 /* 10ms, the SoC can't keep up with 2ms */ | 152 | #define TOUCH_SAMPLE_PERIOD_US_RL 10000 /* 10ms, the SoC can't keep up with 2ms */ |
152 | #define TOUCH_SHTIM 0xa | 153 | #define TOUCH_SHTIM 0xa |
154 | #define TOUCH_SCTIM_US 10 /* 10us for the Touchscreen Switches Closure Time */ | ||
153 | 155 | ||
154 | /** | 156 | /** |
155 | * struct at91_adc_reg_desc - Various informations relative to registers | 157 | * struct at91_adc_reg_desc - Various informations relative to registers |
@@ -1001,7 +1003,9 @@ static void atmel_ts_close(struct input_dev *dev) | |||
1001 | 1003 | ||
1002 | static int at91_ts_hw_init(struct at91_adc_state *st, u32 adc_clk_khz) | 1004 | static int at91_ts_hw_init(struct at91_adc_state *st, u32 adc_clk_khz) |
1003 | { | 1005 | { |
1006 | struct iio_dev *idev = iio_priv_to_dev(st); | ||
1004 | u32 reg = 0; | 1007 | u32 reg = 0; |
1008 | u32 tssctim = 0; | ||
1005 | int i = 0; | 1009 | int i = 0; |
1006 | 1010 | ||
1007 | /* a Pen Detect Debounce Time is necessary for the ADC Touch to avoid | 1011 | /* a Pen Detect Debounce Time is necessary for the ADC Touch to avoid |
@@ -1034,11 +1038,20 @@ static int at91_ts_hw_init(struct at91_adc_state *st, u32 adc_clk_khz) | |||
1034 | return 0; | 1038 | return 0; |
1035 | } | 1039 | } |
1036 | 1040 | ||
1041 | /* Touchscreen Switches Closure time needed for allowing the value to | ||
1042 | * stabilize. | ||
1043 | * Switch Closure Time = (TSSCTIM * 4) ADCClock periods | ||
1044 | */ | ||
1045 | tssctim = DIV_ROUND_UP(TOUCH_SCTIM_US * adc_clk_khz / 1000, 4); | ||
1046 | dev_dbg(&idev->dev, "adc_clk at: %d KHz, tssctim at: %d\n", | ||
1047 | adc_clk_khz, tssctim); | ||
1048 | |||
1037 | if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE) | 1049 | if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE) |
1038 | reg = AT91_ADC_TSMR_TSMODE_4WIRE_PRESS; | 1050 | reg = AT91_ADC_TSMR_TSMODE_4WIRE_PRESS; |
1039 | else | 1051 | else |
1040 | reg = AT91_ADC_TSMR_TSMODE_5WIRE; | 1052 | reg = AT91_ADC_TSMR_TSMODE_5WIRE; |
1041 | 1053 | ||
1054 | reg |= AT91_ADC_TSMR_SCTIM_(tssctim) & AT91_ADC_TSMR_SCTIM; | ||
1042 | reg |= AT91_ADC_TSMR_TSAV_(st->caps->ts_filter_average) | 1055 | reg |= AT91_ADC_TSMR_TSAV_(st->caps->ts_filter_average) |
1043 | & AT91_ADC_TSMR_TSAV; | 1056 | & AT91_ADC_TSMR_TSAV; |
1044 | reg |= AT91_ADC_TSMR_PENDBC_(st->ts_pendbc) & AT91_ADC_TSMR_PENDBC; | 1057 | reg |= AT91_ADC_TSMR_PENDBC_(st->ts_pendbc) & AT91_ADC_TSMR_PENDBC; |
diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c index 955f3fdaf519..59b7d76e1ad2 100644 --- a/drivers/iio/adc/ina2xx-adc.c +++ b/drivers/iio/adc/ina2xx-adc.c | |||
@@ -114,7 +114,6 @@ struct ina2xx_chip_info { | |||
114 | struct mutex state_lock; | 114 | struct mutex state_lock; |
115 | unsigned int shunt_resistor; | 115 | unsigned int shunt_resistor; |
116 | int avg; | 116 | int avg; |
117 | s64 prev_ns; /* track buffer capture time, check for underruns */ | ||
118 | int int_time_vbus; /* Bus voltage integration time uS */ | 117 | int int_time_vbus; /* Bus voltage integration time uS */ |
119 | int int_time_vshunt; /* Shunt voltage integration time uS */ | 118 | int int_time_vshunt; /* Shunt voltage integration time uS */ |
120 | bool allow_async_readout; | 119 | bool allow_async_readout; |
@@ -509,8 +508,6 @@ static int ina2xx_work_buffer(struct iio_dev *indio_dev) | |||
509 | iio_push_to_buffers_with_timestamp(indio_dev, | 508 | iio_push_to_buffers_with_timestamp(indio_dev, |
510 | (unsigned int *)data, time_a); | 509 | (unsigned int *)data, time_a); |
511 | 510 | ||
512 | chip->prev_ns = time_a; | ||
513 | |||
514 | return (unsigned long)(time_b - time_a) / 1000; | 511 | return (unsigned long)(time_b - time_a) / 1000; |
515 | }; | 512 | }; |
516 | 513 | ||
@@ -554,8 +551,6 @@ static int ina2xx_buffer_enable(struct iio_dev *indio_dev) | |||
554 | dev_dbg(&indio_dev->dev, "Async readout mode: %d\n", | 551 | dev_dbg(&indio_dev->dev, "Async readout mode: %d\n", |
555 | chip->allow_async_readout); | 552 | chip->allow_async_readout); |
556 | 553 | ||
557 | chip->prev_ns = iio_get_time_ns(indio_dev); | ||
558 | |||
559 | chip->task = kthread_run(ina2xx_capture_thread, (void *)indio_dev, | 554 | chip->task = kthread_run(ina2xx_capture_thread, (void *)indio_dev, |
560 | "%s:%d-%uus", indio_dev->name, indio_dev->id, | 555 | "%s:%d-%uus", indio_dev->name, indio_dev->id, |
561 | sampling_us); | 556 | sampling_us); |
diff --git a/drivers/iio/adc/ltc2485.c b/drivers/iio/adc/ltc2485.c new file mode 100644 index 000000000000..eab91f12454a --- /dev/null +++ b/drivers/iio/adc/ltc2485.c | |||
@@ -0,0 +1,148 @@ | |||
1 | /* | ||
2 | * ltc2485.c - Driver for Linear Technology LTC2485 ADC | ||
3 | * | ||
4 | * Copyright (C) 2016 Alison Schofield <amsfield22@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * Datasheet: http://cds.linear.com/docs/en/datasheet/2485fd.pdf | ||
11 | */ | ||
12 | |||
13 | #include <linux/delay.h> | ||
14 | #include <linux/i2c.h> | ||
15 | #include <linux/module.h> | ||
16 | |||
17 | #include <linux/iio/iio.h> | ||
18 | #include <linux/iio/sysfs.h> | ||
19 | |||
20 | /* Power-on configuration: rejects both 50/60Hz, operates at 1x speed */ | ||
21 | #define LTC2485_CONFIG_DEFAULT 0 | ||
22 | |||
23 | struct ltc2485_data { | ||
24 | struct i2c_client *client; | ||
25 | ktime_t time_prev; /* last conversion */ | ||
26 | }; | ||
27 | |||
28 | static void ltc2485_wait_conv(struct ltc2485_data *data) | ||
29 | { | ||
30 | const unsigned int conv_time = 147; /* conversion time ms */ | ||
31 | unsigned int time_elapsed; | ||
32 | |||
33 | /* delay if conversion time not passed since last read or write */ | ||
34 | time_elapsed = ktime_ms_delta(ktime_get(), data->time_prev); | ||
35 | |||
36 | if (time_elapsed < conv_time) | ||
37 | msleep(conv_time - time_elapsed); | ||
38 | } | ||
39 | |||
40 | static int ltc2485_read(struct ltc2485_data *data, int *val) | ||
41 | { | ||
42 | struct i2c_client *client = data->client; | ||
43 | __be32 buf = 0; | ||
44 | int ret; | ||
45 | |||
46 | ltc2485_wait_conv(data); | ||
47 | |||
48 | ret = i2c_master_recv(client, (char *)&buf, 4); | ||
49 | if (ret < 0) { | ||
50 | dev_err(&client->dev, "i2c_master_recv failed\n"); | ||
51 | return ret; | ||
52 | } | ||
53 | data->time_prev = ktime_get(); | ||
54 | *val = sign_extend32(be32_to_cpu(buf) >> 6, 24); | ||
55 | |||
56 | return ret; | ||
57 | } | ||
58 | |||
59 | static int ltc2485_read_raw(struct iio_dev *indio_dev, | ||
60 | struct iio_chan_spec const *chan, | ||
61 | int *val, int *val2, long mask) | ||
62 | { | ||
63 | struct ltc2485_data *data = iio_priv(indio_dev); | ||
64 | int ret; | ||
65 | |||
66 | if (mask == IIO_CHAN_INFO_RAW) { | ||
67 | ret = ltc2485_read(data, val); | ||
68 | if (ret < 0) | ||
69 | return ret; | ||
70 | |||
71 | return IIO_VAL_INT; | ||
72 | |||
73 | } else if (mask == IIO_CHAN_INFO_SCALE) { | ||
74 | *val = 5000; /* on board vref millivolts */ | ||
75 | *val2 = 25; /* 25 (24 + sign) data bits */ | ||
76 | return IIO_VAL_FRACTIONAL_LOG2; | ||
77 | |||
78 | } else { | ||
79 | return -EINVAL; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | static const struct iio_chan_spec ltc2485_channel[] = { | ||
84 | { | ||
85 | .type = IIO_VOLTAGE, | ||
86 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), | ||
87 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | ||
88 | }, | ||
89 | }; | ||
90 | |||
91 | static const struct iio_info ltc2485_info = { | ||
92 | .read_raw = ltc2485_read_raw, | ||
93 | .driver_module = THIS_MODULE, | ||
94 | }; | ||
95 | |||
96 | static int ltc2485_probe(struct i2c_client *client, | ||
97 | const struct i2c_device_id *id) | ||
98 | { | ||
99 | struct iio_dev *indio_dev; | ||
100 | struct ltc2485_data *data; | ||
101 | int ret; | ||
102 | |||
103 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | | ||
104 | I2C_FUNC_SMBUS_WRITE_BYTE)) | ||
105 | return -EOPNOTSUPP; | ||
106 | |||
107 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); | ||
108 | if (!indio_dev) | ||
109 | return -ENOMEM; | ||
110 | |||
111 | data = iio_priv(indio_dev); | ||
112 | i2c_set_clientdata(client, indio_dev); | ||
113 | data->client = client; | ||
114 | |||
115 | indio_dev->dev.parent = &client->dev; | ||
116 | indio_dev->name = id->name; | ||
117 | indio_dev->info = <c2485_info; | ||
118 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
119 | indio_dev->channels = ltc2485_channel; | ||
120 | indio_dev->num_channels = ARRAY_SIZE(ltc2485_channel); | ||
121 | |||
122 | ret = i2c_smbus_write_byte(data->client, LTC2485_CONFIG_DEFAULT); | ||
123 | if (ret < 0) | ||
124 | return ret; | ||
125 | |||
126 | data->time_prev = ktime_get(); | ||
127 | |||
128 | return devm_iio_device_register(&client->dev, indio_dev); | ||
129 | } | ||
130 | |||
131 | static const struct i2c_device_id ltc2485_id[] = { | ||
132 | { "ltc2485", 0 }, | ||
133 | { } | ||
134 | }; | ||
135 | MODULE_DEVICE_TABLE(i2c, ltc2485_id); | ||
136 | |||
137 | static struct i2c_driver ltc2485_driver = { | ||
138 | .driver = { | ||
139 | .name = "ltc2485", | ||
140 | }, | ||
141 | .probe = ltc2485_probe, | ||
142 | .id_table = ltc2485_id, | ||
143 | }; | ||
144 | module_i2c_driver(ltc2485_driver); | ||
145 | |||
146 | MODULE_AUTHOR("Alison Schofield <amsfield22@gmail.com>"); | ||
147 | MODULE_DESCRIPTION("Linear Technology LTC2485 ADC driver"); | ||
148 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/iio/dac/stx104.c b/drivers/iio/adc/stx104.c index bebbd00304ce..7e3645749eaf 100644 --- a/drivers/iio/dac/stx104.c +++ b/drivers/iio/adc/stx104.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * DAC driver for the Apex Embedded Systems STX104 | 2 | * IIO driver for the Apex Embedded Systems STX104 |
3 | * Copyright (C) 2016 William Breathitt Gray | 3 | * Copyright (C) 2016 William Breathitt Gray |
4 | * | 4 | * |
5 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
@@ -20,19 +20,30 @@ | |||
20 | #include <linux/io.h> | 20 | #include <linux/io.h> |
21 | #include <linux/ioport.h> | 21 | #include <linux/ioport.h> |
22 | #include <linux/isa.h> | 22 | #include <linux/isa.h> |
23 | #include <linux/kernel.h> | ||
23 | #include <linux/module.h> | 24 | #include <linux/module.h> |
24 | #include <linux/moduleparam.h> | 25 | #include <linux/moduleparam.h> |
25 | #include <linux/spinlock.h> | 26 | #include <linux/spinlock.h> |
26 | 27 | ||
27 | #define STX104_NUM_CHAN 2 | 28 | #define STX104_OUT_CHAN(chan) { \ |
28 | |||
29 | #define STX104_CHAN(chan) { \ | ||
30 | .type = IIO_VOLTAGE, \ | 29 | .type = IIO_VOLTAGE, \ |
31 | .channel = chan, \ | 30 | .channel = chan, \ |
32 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | 31 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ |
33 | .indexed = 1, \ | 32 | .indexed = 1, \ |
34 | .output = 1 \ | 33 | .output = 1 \ |
35 | } | 34 | } |
35 | #define STX104_IN_CHAN(chan, diff) { \ | ||
36 | .type = IIO_VOLTAGE, \ | ||
37 | .channel = chan, \ | ||
38 | .channel2 = chan, \ | ||
39 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_HARDWAREGAIN) | \ | ||
40 | BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_SCALE), \ | ||
41 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
42 | .indexed = 1, \ | ||
43 | .differential = diff \ | ||
44 | } | ||
45 | |||
46 | #define STX104_NUM_OUT_CHAN 2 | ||
36 | 47 | ||
37 | #define STX104_EXTENT 16 | 48 | #define STX104_EXTENT 16 |
38 | 49 | ||
@@ -47,8 +58,8 @@ MODULE_PARM_DESC(base, "Apex Embedded Systems STX104 base addresses"); | |||
47 | * @base: base port address of the IIO device | 58 | * @base: base port address of the IIO device |
48 | */ | 59 | */ |
49 | struct stx104_iio { | 60 | struct stx104_iio { |
50 | unsigned chan_out_states[STX104_NUM_CHAN]; | 61 | unsigned int chan_out_states[STX104_NUM_OUT_CHAN]; |
51 | unsigned base; | 62 | unsigned int base; |
52 | }; | 63 | }; |
53 | 64 | ||
54 | /** | 65 | /** |
@@ -79,28 +90,95 @@ static int stx104_read_raw(struct iio_dev *indio_dev, | |||
79 | struct iio_chan_spec const *chan, int *val, int *val2, long mask) | 90 | struct iio_chan_spec const *chan, int *val, int *val2, long mask) |
80 | { | 91 | { |
81 | struct stx104_iio *const priv = iio_priv(indio_dev); | 92 | struct stx104_iio *const priv = iio_priv(indio_dev); |
93 | unsigned int adc_config; | ||
94 | int adbu; | ||
95 | int gain; | ||
96 | |||
97 | switch (mask) { | ||
98 | case IIO_CHAN_INFO_HARDWAREGAIN: | ||
99 | /* get gain configuration */ | ||
100 | adc_config = inb(priv->base + 11); | ||
101 | gain = adc_config & 0x3; | ||
102 | |||
103 | *val = 1 << gain; | ||
104 | return IIO_VAL_INT; | ||
105 | case IIO_CHAN_INFO_RAW: | ||
106 | if (chan->output) { | ||
107 | *val = priv->chan_out_states[chan->channel]; | ||
108 | return IIO_VAL_INT; | ||
109 | } | ||
110 | |||
111 | /* select ADC channel */ | ||
112 | outb(chan->channel | (chan->channel << 4), priv->base + 2); | ||
113 | |||
114 | /* trigger ADC sample capture and wait for completion */ | ||
115 | outb(0, priv->base); | ||
116 | while (inb(priv->base + 8) & BIT(7)); | ||
117 | |||
118 | *val = inw(priv->base); | ||
119 | return IIO_VAL_INT; | ||
120 | case IIO_CHAN_INFO_OFFSET: | ||
121 | /* get ADC bipolar/unipolar configuration */ | ||
122 | adc_config = inb(priv->base + 11); | ||
123 | adbu = !(adc_config & BIT(2)); | ||
124 | |||
125 | *val = -32768 * adbu; | ||
126 | return IIO_VAL_INT; | ||
127 | case IIO_CHAN_INFO_SCALE: | ||
128 | /* get ADC bipolar/unipolar and gain configuration */ | ||
129 | adc_config = inb(priv->base + 11); | ||
130 | adbu = !(adc_config & BIT(2)); | ||
131 | gain = adc_config & 0x3; | ||
132 | |||
133 | *val = 5; | ||
134 | *val2 = 15 - adbu + gain; | ||
135 | return IIO_VAL_FRACTIONAL_LOG2; | ||
136 | } | ||
82 | 137 | ||
83 | if (mask != IIO_CHAN_INFO_RAW) | 138 | return -EINVAL; |
84 | return -EINVAL; | ||
85 | |||
86 | *val = priv->chan_out_states[chan->channel]; | ||
87 | |||
88 | return IIO_VAL_INT; | ||
89 | } | 139 | } |
90 | 140 | ||
91 | static int stx104_write_raw(struct iio_dev *indio_dev, | 141 | static int stx104_write_raw(struct iio_dev *indio_dev, |
92 | struct iio_chan_spec const *chan, int val, int val2, long mask) | 142 | struct iio_chan_spec const *chan, int val, int val2, long mask) |
93 | { | 143 | { |
94 | struct stx104_iio *const priv = iio_priv(indio_dev); | 144 | struct stx104_iio *const priv = iio_priv(indio_dev); |
95 | const unsigned chan_addr_offset = 2 * chan->channel; | ||
96 | 145 | ||
97 | if (mask != IIO_CHAN_INFO_RAW) | 146 | switch (mask) { |
147 | case IIO_CHAN_INFO_HARDWAREGAIN: | ||
148 | /* Only four gain states (x1, x2, x4, x8) */ | ||
149 | switch (val) { | ||
150 | case 1: | ||
151 | outb(0, priv->base + 11); | ||
152 | break; | ||
153 | case 2: | ||
154 | outb(1, priv->base + 11); | ||
155 | break; | ||
156 | case 4: | ||
157 | outb(2, priv->base + 11); | ||
158 | break; | ||
159 | case 8: | ||
160 | outb(3, priv->base + 11); | ||
161 | break; | ||
162 | default: | ||
163 | return -EINVAL; | ||
164 | } | ||
165 | |||
166 | return 0; | ||
167 | case IIO_CHAN_INFO_RAW: | ||
168 | if (chan->output) { | ||
169 | /* DAC can only accept up to a 16-bit value */ | ||
170 | if ((unsigned int)val > 65535) | ||
171 | return -EINVAL; | ||
172 | |||
173 | priv->chan_out_states[chan->channel] = val; | ||
174 | outw(val, priv->base + 4 + 2 * chan->channel); | ||
175 | |||
176 | return 0; | ||
177 | } | ||
98 | return -EINVAL; | 178 | return -EINVAL; |
179 | } | ||
99 | 180 | ||
100 | priv->chan_out_states[chan->channel] = val; | 181 | return -EINVAL; |
101 | outw(val, priv->base + 4 + chan_addr_offset); | ||
102 | |||
103 | return 0; | ||
104 | } | 182 | } |
105 | 183 | ||
106 | static const struct iio_info stx104_info = { | 184 | static const struct iio_info stx104_info = { |
@@ -109,9 +187,22 @@ static const struct iio_info stx104_info = { | |||
109 | .write_raw = stx104_write_raw | 187 | .write_raw = stx104_write_raw |
110 | }; | 188 | }; |
111 | 189 | ||
112 | static const struct iio_chan_spec stx104_channels[STX104_NUM_CHAN] = { | 190 | /* single-ended input channels configuration */ |
113 | STX104_CHAN(0), | 191 | static const struct iio_chan_spec stx104_channels_sing[] = { |
114 | STX104_CHAN(1) | 192 | STX104_OUT_CHAN(0), STX104_OUT_CHAN(1), |
193 | STX104_IN_CHAN(0, 0), STX104_IN_CHAN(1, 0), STX104_IN_CHAN(2, 0), | ||
194 | STX104_IN_CHAN(3, 0), STX104_IN_CHAN(4, 0), STX104_IN_CHAN(5, 0), | ||
195 | STX104_IN_CHAN(6, 0), STX104_IN_CHAN(7, 0), STX104_IN_CHAN(8, 0), | ||
196 | STX104_IN_CHAN(9, 0), STX104_IN_CHAN(10, 0), STX104_IN_CHAN(11, 0), | ||
197 | STX104_IN_CHAN(12, 0), STX104_IN_CHAN(13, 0), STX104_IN_CHAN(14, 0), | ||
198 | STX104_IN_CHAN(15, 0) | ||
199 | }; | ||
200 | /* differential input channels configuration */ | ||
201 | static const struct iio_chan_spec stx104_channels_diff[] = { | ||
202 | STX104_OUT_CHAN(0), STX104_OUT_CHAN(1), | ||
203 | STX104_IN_CHAN(0, 1), STX104_IN_CHAN(1, 1), STX104_IN_CHAN(2, 1), | ||
204 | STX104_IN_CHAN(3, 1), STX104_IN_CHAN(4, 1), STX104_IN_CHAN(5, 1), | ||
205 | STX104_IN_CHAN(6, 1), STX104_IN_CHAN(7, 1) | ||
115 | }; | 206 | }; |
116 | 207 | ||
117 | static int stx104_gpio_get_direction(struct gpio_chip *chip, | 208 | static int stx104_gpio_get_direction(struct gpio_chip *chip, |
@@ -204,13 +295,27 @@ static int stx104_probe(struct device *dev, unsigned int id) | |||
204 | 295 | ||
205 | indio_dev->info = &stx104_info; | 296 | indio_dev->info = &stx104_info; |
206 | indio_dev->modes = INDIO_DIRECT_MODE; | 297 | indio_dev->modes = INDIO_DIRECT_MODE; |
207 | indio_dev->channels = stx104_channels; | 298 | |
208 | indio_dev->num_channels = STX104_NUM_CHAN; | 299 | /* determine if differential inputs */ |
300 | if (inb(base[id] + 8) & BIT(5)) { | ||
301 | indio_dev->num_channels = ARRAY_SIZE(stx104_channels_diff); | ||
302 | indio_dev->channels = stx104_channels_diff; | ||
303 | } else { | ||
304 | indio_dev->num_channels = ARRAY_SIZE(stx104_channels_sing); | ||
305 | indio_dev->channels = stx104_channels_sing; | ||
306 | } | ||
307 | |||
209 | indio_dev->name = dev_name(dev); | 308 | indio_dev->name = dev_name(dev); |
210 | 309 | ||
211 | priv = iio_priv(indio_dev); | 310 | priv = iio_priv(indio_dev); |
212 | priv->base = base[id]; | 311 | priv->base = base[id]; |
213 | 312 | ||
313 | /* configure device for software trigger operation */ | ||
314 | outb(0, base[id] + 9); | ||
315 | |||
316 | /* initialize gain setting to x1 */ | ||
317 | outb(0, base[id] + 11); | ||
318 | |||
214 | /* initialize DAC output to 0V */ | 319 | /* initialize DAC output to 0V */ |
215 | outw(0, base[id] + 4); | 320 | outw(0, base[id] + 4); |
216 | outw(0, base[id] + 6); | 321 | outw(0, base[id] + 6); |
@@ -271,5 +376,5 @@ static struct isa_driver stx104_driver = { | |||
271 | module_isa_driver(stx104_driver, num_stx104); | 376 | module_isa_driver(stx104_driver, num_stx104); |
272 | 377 | ||
273 | MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); | 378 | MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); |
274 | MODULE_DESCRIPTION("Apex Embedded Systems STX104 DAC driver"); | 379 | MODULE_DESCRIPTION("Apex Embedded Systems STX104 IIO driver"); |
275 | MODULE_LICENSE("GPL v2"); | 380 | MODULE_LICENSE("GPL v2"); |
diff --git a/drivers/iio/adc/ti-adc12138.c b/drivers/iio/adc/ti-adc12138.c new file mode 100644 index 000000000000..072f03bfe6a0 --- /dev/null +++ b/drivers/iio/adc/ti-adc12138.c | |||
@@ -0,0 +1,552 @@ | |||
1 | /* | ||
2 | * ADC12130/ADC12132/ADC12138 12-bit plus sign ADC driver | ||
3 | * | ||
4 | * Copyright (c) 2016 Akinobu Mita <akinobu.mita@gmail.com> | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of version 2 of | ||
7 | * the GNU General Public License. See the file COPYING in the main | ||
8 | * directory of this archive for more details. | ||
9 | * | ||
10 | * Datasheet: http://www.ti.com/lit/ds/symlink/adc12138.pdf | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/interrupt.h> | ||
15 | #include <linux/completion.h> | ||
16 | #include <linux/clk.h> | ||
17 | #include <linux/spi/spi.h> | ||
18 | #include <linux/iio/iio.h> | ||
19 | #include <linux/iio/buffer.h> | ||
20 | #include <linux/iio/trigger.h> | ||
21 | #include <linux/iio/triggered_buffer.h> | ||
22 | #include <linux/iio/trigger_consumer.h> | ||
23 | #include <linux/regulator/consumer.h> | ||
24 | |||
25 | #define ADC12138_MODE_AUTO_CAL 0x08 | ||
26 | #define ADC12138_MODE_READ_STATUS 0x0c | ||
27 | #define ADC12138_MODE_ACQUISITION_TIME_6 0x0e | ||
28 | #define ADC12138_MODE_ACQUISITION_TIME_10 0x4e | ||
29 | #define ADC12138_MODE_ACQUISITION_TIME_18 0x8e | ||
30 | #define ADC12138_MODE_ACQUISITION_TIME_34 0xce | ||
31 | |||
32 | #define ADC12138_STATUS_CAL BIT(6) | ||
33 | |||
34 | enum { | ||
35 | adc12130, | ||
36 | adc12132, | ||
37 | adc12138, | ||
38 | }; | ||
39 | |||
40 | struct adc12138 { | ||
41 | struct spi_device *spi; | ||
42 | unsigned int id; | ||
43 | /* conversion clock */ | ||
44 | struct clk *cclk; | ||
45 | /* positive analog voltage reference */ | ||
46 | struct regulator *vref_p; | ||
47 | /* negative analog voltage reference */ | ||
48 | struct regulator *vref_n; | ||
49 | struct mutex lock; | ||
50 | struct completion complete; | ||
51 | /* The number of cclk periods for the S/H's acquisition time */ | ||
52 | unsigned int acquisition_time; | ||
53 | |||
54 | u8 tx_buf[2] ____cacheline_aligned; | ||
55 | u8 rx_buf[2]; | ||
56 | }; | ||
57 | |||
58 | #define ADC12138_VOLTAGE_CHANNEL(chan) \ | ||
59 | { \ | ||
60 | .type = IIO_VOLTAGE, \ | ||
61 | .indexed = 1, \ | ||
62 | .channel = chan, \ | ||
63 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
64 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \ | ||
65 | | BIT(IIO_CHAN_INFO_OFFSET), \ | ||
66 | .scan_index = chan, \ | ||
67 | .scan_type = { \ | ||
68 | .sign = 's', \ | ||
69 | .realbits = 13, \ | ||
70 | .storagebits = 16, \ | ||
71 | .shift = 3, \ | ||
72 | .endianness = IIO_BE, \ | ||
73 | }, \ | ||
74 | } | ||
75 | |||
76 | #define ADC12138_VOLTAGE_CHANNEL_DIFF(chan1, chan2, si) \ | ||
77 | { \ | ||
78 | .type = IIO_VOLTAGE, \ | ||
79 | .indexed = 1, \ | ||
80 | .channel = (chan1), \ | ||
81 | .channel2 = (chan2), \ | ||
82 | .differential = 1, \ | ||
83 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
84 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \ | ||
85 | | BIT(IIO_CHAN_INFO_OFFSET), \ | ||
86 | .scan_index = si, \ | ||
87 | .scan_type = { \ | ||
88 | .sign = 's', \ | ||
89 | .realbits = 13, \ | ||
90 | .storagebits = 16, \ | ||
91 | .shift = 3, \ | ||
92 | .endianness = IIO_BE, \ | ||
93 | }, \ | ||
94 | } | ||
95 | |||
96 | static const struct iio_chan_spec adc12132_channels[] = { | ||
97 | ADC12138_VOLTAGE_CHANNEL(0), | ||
98 | ADC12138_VOLTAGE_CHANNEL(1), | ||
99 | ADC12138_VOLTAGE_CHANNEL_DIFF(0, 1, 2), | ||
100 | ADC12138_VOLTAGE_CHANNEL_DIFF(1, 0, 3), | ||
101 | IIO_CHAN_SOFT_TIMESTAMP(4), | ||
102 | }; | ||
103 | |||
104 | static const struct iio_chan_spec adc12138_channels[] = { | ||
105 | ADC12138_VOLTAGE_CHANNEL(0), | ||
106 | ADC12138_VOLTAGE_CHANNEL(1), | ||
107 | ADC12138_VOLTAGE_CHANNEL(2), | ||
108 | ADC12138_VOLTAGE_CHANNEL(3), | ||
109 | ADC12138_VOLTAGE_CHANNEL(4), | ||
110 | ADC12138_VOLTAGE_CHANNEL(5), | ||
111 | ADC12138_VOLTAGE_CHANNEL(6), | ||
112 | ADC12138_VOLTAGE_CHANNEL(7), | ||
113 | ADC12138_VOLTAGE_CHANNEL_DIFF(0, 1, 8), | ||
114 | ADC12138_VOLTAGE_CHANNEL_DIFF(1, 0, 9), | ||
115 | ADC12138_VOLTAGE_CHANNEL_DIFF(2, 3, 10), | ||
116 | ADC12138_VOLTAGE_CHANNEL_DIFF(3, 2, 11), | ||
117 | ADC12138_VOLTAGE_CHANNEL_DIFF(4, 5, 12), | ||
118 | ADC12138_VOLTAGE_CHANNEL_DIFF(5, 4, 13), | ||
119 | ADC12138_VOLTAGE_CHANNEL_DIFF(6, 7, 14), | ||
120 | ADC12138_VOLTAGE_CHANNEL_DIFF(7, 6, 15), | ||
121 | IIO_CHAN_SOFT_TIMESTAMP(16), | ||
122 | }; | ||
123 | |||
124 | static int adc12138_mode_programming(struct adc12138 *adc, u8 mode, | ||
125 | void *rx_buf, int len) | ||
126 | { | ||
127 | struct spi_transfer xfer = { | ||
128 | .tx_buf = adc->tx_buf, | ||
129 | .rx_buf = adc->rx_buf, | ||
130 | .len = len, | ||
131 | }; | ||
132 | int ret; | ||
133 | |||
134 | /* Skip unused bits for ADC12130 and ADC12132 */ | ||
135 | if (adc->id != adc12138) | ||
136 | mode = (mode & 0xc0) | ((mode & 0x0f) << 2); | ||
137 | |||
138 | adc->tx_buf[0] = mode; | ||
139 | |||
140 | ret = spi_sync_transfer(adc->spi, &xfer, 1); | ||
141 | if (ret) | ||
142 | return ret; | ||
143 | |||
144 | memcpy(rx_buf, adc->rx_buf, len); | ||
145 | |||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | static int adc12138_read_status(struct adc12138 *adc) | ||
150 | { | ||
151 | u8 rx_buf[2]; | ||
152 | int ret; | ||
153 | |||
154 | ret = adc12138_mode_programming(adc, ADC12138_MODE_READ_STATUS, | ||
155 | rx_buf, 2); | ||
156 | if (ret) | ||
157 | return ret; | ||
158 | |||
159 | return (rx_buf[0] << 1) | (rx_buf[1] >> 7); | ||
160 | } | ||
161 | |||
162 | static int __adc12138_start_conv(struct adc12138 *adc, | ||
163 | struct iio_chan_spec const *channel, | ||
164 | void *data, int len) | ||
165 | |||
166 | { | ||
167 | const u8 ch_to_mux[] = { 0, 4, 1, 5, 2, 6, 3, 7 }; | ||
168 | u8 mode = (ch_to_mux[channel->channel] << 4) | | ||
169 | (channel->differential ? 0 : 0x80); | ||
170 | |||
171 | return adc12138_mode_programming(adc, mode, data, len); | ||
172 | } | ||
173 | |||
174 | static int adc12138_start_conv(struct adc12138 *adc, | ||
175 | struct iio_chan_spec const *channel) | ||
176 | { | ||
177 | u8 trash; | ||
178 | |||
179 | return __adc12138_start_conv(adc, channel, &trash, 1); | ||
180 | } | ||
181 | |||
182 | static int adc12138_start_and_read_conv(struct adc12138 *adc, | ||
183 | struct iio_chan_spec const *channel, | ||
184 | __be16 *data) | ||
185 | { | ||
186 | return __adc12138_start_conv(adc, channel, data, 2); | ||
187 | } | ||
188 | |||
189 | static int adc12138_read_conv_data(struct adc12138 *adc, __be16 *value) | ||
190 | { | ||
191 | /* Issue a read status instruction and read previous conversion data */ | ||
192 | return adc12138_mode_programming(adc, ADC12138_MODE_READ_STATUS, | ||
193 | value, sizeof(*value)); | ||
194 | } | ||
195 | |||
196 | static int adc12138_wait_eoc(struct adc12138 *adc, unsigned long timeout) | ||
197 | { | ||
198 | if (!wait_for_completion_timeout(&adc->complete, timeout)) | ||
199 | return -ETIMEDOUT; | ||
200 | |||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | static int adc12138_adc_conversion(struct adc12138 *adc, | ||
205 | struct iio_chan_spec const *channel, | ||
206 | __be16 *value) | ||
207 | { | ||
208 | int ret; | ||
209 | |||
210 | reinit_completion(&adc->complete); | ||
211 | |||
212 | ret = adc12138_start_conv(adc, channel); | ||
213 | if (ret) | ||
214 | return ret; | ||
215 | |||
216 | ret = adc12138_wait_eoc(adc, msecs_to_jiffies(100)); | ||
217 | if (ret) | ||
218 | return ret; | ||
219 | |||
220 | return adc12138_read_conv_data(adc, value); | ||
221 | } | ||
222 | |||
223 | static int adc12138_read_raw(struct iio_dev *iio, | ||
224 | struct iio_chan_spec const *channel, int *value, | ||
225 | int *shift, long mask) | ||
226 | { | ||
227 | struct adc12138 *adc = iio_priv(iio); | ||
228 | int ret; | ||
229 | __be16 data; | ||
230 | |||
231 | switch (mask) { | ||
232 | case IIO_CHAN_INFO_RAW: | ||
233 | mutex_lock(&adc->lock); | ||
234 | ret = adc12138_adc_conversion(adc, channel, &data); | ||
235 | mutex_unlock(&adc->lock); | ||
236 | if (ret) | ||
237 | return ret; | ||
238 | |||
239 | *value = sign_extend32(be16_to_cpu(data) >> 3, 12); | ||
240 | |||
241 | return IIO_VAL_INT; | ||
242 | case IIO_CHAN_INFO_SCALE: | ||
243 | ret = regulator_get_voltage(adc->vref_p); | ||
244 | if (ret < 0) | ||
245 | return ret; | ||
246 | *value = ret; | ||
247 | |||
248 | if (!IS_ERR(adc->vref_n)) { | ||
249 | ret = regulator_get_voltage(adc->vref_n); | ||
250 | if (ret < 0) | ||
251 | return ret; | ||
252 | *value -= ret; | ||
253 | } | ||
254 | |||
255 | /* convert regulator output voltage to mV */ | ||
256 | *value /= 1000; | ||
257 | *shift = channel->scan_type.realbits - 1; | ||
258 | |||
259 | return IIO_VAL_FRACTIONAL_LOG2; | ||
260 | case IIO_CHAN_INFO_OFFSET: | ||
261 | if (!IS_ERR(adc->vref_n)) { | ||
262 | *value = regulator_get_voltage(adc->vref_n); | ||
263 | if (*value < 0) | ||
264 | return *value; | ||
265 | } else { | ||
266 | *value = 0; | ||
267 | } | ||
268 | |||
269 | /* convert regulator output voltage to mV */ | ||
270 | *value /= 1000; | ||
271 | |||
272 | return IIO_VAL_INT; | ||
273 | } | ||
274 | |||
275 | return -EINVAL; | ||
276 | } | ||
277 | |||
278 | static const struct iio_info adc12138_info = { | ||
279 | .read_raw = adc12138_read_raw, | ||
280 | .driver_module = THIS_MODULE, | ||
281 | }; | ||
282 | |||
283 | static int adc12138_init(struct adc12138 *adc) | ||
284 | { | ||
285 | int ret; | ||
286 | int status; | ||
287 | u8 mode; | ||
288 | u8 trash; | ||
289 | |||
290 | reinit_completion(&adc->complete); | ||
291 | |||
292 | ret = adc12138_mode_programming(adc, ADC12138_MODE_AUTO_CAL, &trash, 1); | ||
293 | if (ret) | ||
294 | return ret; | ||
295 | |||
296 | /* data output at this time has no significance */ | ||
297 | status = adc12138_read_status(adc); | ||
298 | if (status < 0) | ||
299 | return status; | ||
300 | |||
301 | adc12138_wait_eoc(adc, msecs_to_jiffies(100)); | ||
302 | |||
303 | status = adc12138_read_status(adc); | ||
304 | if (status & ADC12138_STATUS_CAL) { | ||
305 | dev_warn(&adc->spi->dev, | ||
306 | "Auto Cal sequence is still in progress: %#x\n", | ||
307 | status); | ||
308 | return -EIO; | ||
309 | } | ||
310 | |||
311 | switch (adc->acquisition_time) { | ||
312 | case 6: | ||
313 | mode = ADC12138_MODE_ACQUISITION_TIME_6; | ||
314 | break; | ||
315 | case 10: | ||
316 | mode = ADC12138_MODE_ACQUISITION_TIME_10; | ||
317 | break; | ||
318 | case 18: | ||
319 | mode = ADC12138_MODE_ACQUISITION_TIME_18; | ||
320 | break; | ||
321 | case 34: | ||
322 | mode = ADC12138_MODE_ACQUISITION_TIME_34; | ||
323 | break; | ||
324 | default: | ||
325 | return -EINVAL; | ||
326 | } | ||
327 | |||
328 | return adc12138_mode_programming(adc, mode, &trash, 1); | ||
329 | } | ||
330 | |||
331 | static irqreturn_t adc12138_trigger_handler(int irq, void *p) | ||
332 | { | ||
333 | struct iio_poll_func *pf = p; | ||
334 | struct iio_dev *indio_dev = pf->indio_dev; | ||
335 | struct adc12138 *adc = iio_priv(indio_dev); | ||
336 | __be16 data[20] = { }; /* 16x 2 bytes ADC data + 8 bytes timestamp */ | ||
337 | __be16 trash; | ||
338 | int ret; | ||
339 | int scan_index; | ||
340 | int i = 0; | ||
341 | |||
342 | mutex_lock(&adc->lock); | ||
343 | |||
344 | for_each_set_bit(scan_index, indio_dev->active_scan_mask, | ||
345 | indio_dev->masklength) { | ||
346 | const struct iio_chan_spec *scan_chan = | ||
347 | &indio_dev->channels[scan_index]; | ||
348 | |||
349 | reinit_completion(&adc->complete); | ||
350 | |||
351 | ret = adc12138_start_and_read_conv(adc, scan_chan, | ||
352 | i ? &data[i - 1] : &trash); | ||
353 | if (ret) { | ||
354 | dev_warn(&adc->spi->dev, | ||
355 | "failed to start conversion\n"); | ||
356 | goto out; | ||
357 | } | ||
358 | |||
359 | ret = adc12138_wait_eoc(adc, msecs_to_jiffies(100)); | ||
360 | if (ret) { | ||
361 | dev_warn(&adc->spi->dev, "wait eoc timeout\n"); | ||
362 | goto out; | ||
363 | } | ||
364 | |||
365 | i++; | ||
366 | } | ||
367 | |||
368 | if (i) { | ||
369 | ret = adc12138_read_conv_data(adc, &data[i - 1]); | ||
370 | if (ret) { | ||
371 | dev_warn(&adc->spi->dev, | ||
372 | "failed to get conversion data\n"); | ||
373 | goto out; | ||
374 | } | ||
375 | } | ||
376 | |||
377 | iio_push_to_buffers_with_timestamp(indio_dev, data, | ||
378 | iio_get_time_ns(indio_dev)); | ||
379 | out: | ||
380 | mutex_unlock(&adc->lock); | ||
381 | |||
382 | iio_trigger_notify_done(indio_dev->trig); | ||
383 | |||
384 | return IRQ_HANDLED; | ||
385 | } | ||
386 | |||
387 | static irqreturn_t adc12138_eoc_handler(int irq, void *p) | ||
388 | { | ||
389 | struct iio_dev *indio_dev = p; | ||
390 | struct adc12138 *adc = iio_priv(indio_dev); | ||
391 | |||
392 | complete(&adc->complete); | ||
393 | |||
394 | return IRQ_HANDLED; | ||
395 | } | ||
396 | |||
397 | static int adc12138_probe(struct spi_device *spi) | ||
398 | { | ||
399 | struct iio_dev *indio_dev; | ||
400 | struct adc12138 *adc; | ||
401 | int ret; | ||
402 | |||
403 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); | ||
404 | if (!indio_dev) | ||
405 | return -ENOMEM; | ||
406 | |||
407 | adc = iio_priv(indio_dev); | ||
408 | adc->spi = spi; | ||
409 | adc->id = spi_get_device_id(spi)->driver_data; | ||
410 | mutex_init(&adc->lock); | ||
411 | init_completion(&adc->complete); | ||
412 | |||
413 | indio_dev->name = spi_get_device_id(spi)->name; | ||
414 | indio_dev->dev.parent = &spi->dev; | ||
415 | indio_dev->info = &adc12138_info; | ||
416 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
417 | |||
418 | switch (adc->id) { | ||
419 | case adc12130: | ||
420 | case adc12132: | ||
421 | indio_dev->channels = adc12132_channels; | ||
422 | indio_dev->num_channels = ARRAY_SIZE(adc12132_channels); | ||
423 | break; | ||
424 | case adc12138: | ||
425 | indio_dev->channels = adc12138_channels; | ||
426 | indio_dev->num_channels = ARRAY_SIZE(adc12138_channels); | ||
427 | break; | ||
428 | default: | ||
429 | return -EINVAL; | ||
430 | } | ||
431 | |||
432 | ret = of_property_read_u32(spi->dev.of_node, "ti,acquisition-time", | ||
433 | &adc->acquisition_time); | ||
434 | if (ret) | ||
435 | adc->acquisition_time = 10; | ||
436 | |||
437 | adc->cclk = devm_clk_get(&spi->dev, NULL); | ||
438 | if (IS_ERR(adc->cclk)) | ||
439 | return PTR_ERR(adc->cclk); | ||
440 | |||
441 | adc->vref_p = devm_regulator_get(&spi->dev, "vref-p"); | ||
442 | if (IS_ERR(adc->vref_p)) | ||
443 | return PTR_ERR(adc->vref_p); | ||
444 | |||
445 | adc->vref_n = devm_regulator_get_optional(&spi->dev, "vref-n"); | ||
446 | if (IS_ERR(adc->vref_n)) { | ||
447 | /* | ||
448 | * Assume vref_n is 0V if an optional regulator is not | ||
449 | * specified, otherwise return the error code. | ||
450 | */ | ||
451 | ret = PTR_ERR(adc->vref_n); | ||
452 | if (ret != -ENODEV) | ||
453 | return ret; | ||
454 | } | ||
455 | |||
456 | ret = devm_request_irq(&spi->dev, spi->irq, adc12138_eoc_handler, | ||
457 | IRQF_TRIGGER_RISING, indio_dev->name, indio_dev); | ||
458 | if (ret) | ||
459 | return ret; | ||
460 | |||
461 | ret = clk_prepare_enable(adc->cclk); | ||
462 | if (ret) | ||
463 | return ret; | ||
464 | |||
465 | ret = regulator_enable(adc->vref_p); | ||
466 | if (ret) | ||
467 | goto err_clk_disable; | ||
468 | |||
469 | if (!IS_ERR(adc->vref_n)) { | ||
470 | ret = regulator_enable(adc->vref_n); | ||
471 | if (ret) | ||
472 | goto err_vref_p_disable; | ||
473 | } | ||
474 | |||
475 | ret = adc12138_init(adc); | ||
476 | if (ret) | ||
477 | goto err_vref_n_disable; | ||
478 | |||
479 | spi_set_drvdata(spi, indio_dev); | ||
480 | |||
481 | ret = iio_triggered_buffer_setup(indio_dev, NULL, | ||
482 | adc12138_trigger_handler, NULL); | ||
483 | if (ret) | ||
484 | goto err_vref_n_disable; | ||
485 | |||
486 | ret = iio_device_register(indio_dev); | ||
487 | if (ret) | ||
488 | goto err_buffer_cleanup; | ||
489 | |||
490 | return 0; | ||
491 | err_buffer_cleanup: | ||
492 | iio_triggered_buffer_cleanup(indio_dev); | ||
493 | err_vref_n_disable: | ||
494 | if (!IS_ERR(adc->vref_n)) | ||
495 | regulator_disable(adc->vref_n); | ||
496 | err_vref_p_disable: | ||
497 | regulator_disable(adc->vref_p); | ||
498 | err_clk_disable: | ||
499 | clk_disable_unprepare(adc->cclk); | ||
500 | |||
501 | return ret; | ||
502 | } | ||
503 | |||
504 | static int adc12138_remove(struct spi_device *spi) | ||
505 | { | ||
506 | struct iio_dev *indio_dev = spi_get_drvdata(spi); | ||
507 | struct adc12138 *adc = iio_priv(indio_dev); | ||
508 | |||
509 | iio_device_unregister(indio_dev); | ||
510 | iio_triggered_buffer_cleanup(indio_dev); | ||
511 | if (!IS_ERR(adc->vref_n)) | ||
512 | regulator_disable(adc->vref_n); | ||
513 | regulator_disable(adc->vref_p); | ||
514 | clk_disable_unprepare(adc->cclk); | ||
515 | |||
516 | return 0; | ||
517 | } | ||
518 | |||
519 | #ifdef CONFIG_OF | ||
520 | |||
521 | static const struct of_device_id adc12138_dt_ids[] = { | ||
522 | { .compatible = "ti,adc12130", }, | ||
523 | { .compatible = "ti,adc12132", }, | ||
524 | { .compatible = "ti,adc12138", }, | ||
525 | {} | ||
526 | }; | ||
527 | MODULE_DEVICE_TABLE(of, adc12138_dt_ids); | ||
528 | |||
529 | #endif | ||
530 | |||
531 | static const struct spi_device_id adc12138_id[] = { | ||
532 | { "adc12130", adc12130 }, | ||
533 | { "adc12132", adc12132 }, | ||
534 | { "adc12138", adc12138 }, | ||
535 | {} | ||
536 | }; | ||
537 | MODULE_DEVICE_TABLE(spi, adc12138_id); | ||
538 | |||
539 | static struct spi_driver adc12138_driver = { | ||
540 | .driver = { | ||
541 | .name = "adc12138", | ||
542 | .of_match_table = of_match_ptr(adc12138_dt_ids), | ||
543 | }, | ||
544 | .probe = adc12138_probe, | ||
545 | .remove = adc12138_remove, | ||
546 | .id_table = adc12138_id, | ||
547 | }; | ||
548 | module_spi_driver(adc12138_driver); | ||
549 | |||
550 | MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>"); | ||
551 | MODULE_DESCRIPTION("ADC12130/ADC12132/ADC12138 driver"); | ||
552 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index 066abaf80201..cde6f130a99a 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c | |||
@@ -522,6 +522,7 @@ static int ads1015_get_channels_config_of(struct i2c_client *client) | |||
522 | if (pga > 6) { | 522 | if (pga > 6) { |
523 | dev_err(&client->dev, "invalid gain on %s\n", | 523 | dev_err(&client->dev, "invalid gain on %s\n", |
524 | node->full_name); | 524 | node->full_name); |
525 | of_node_put(node); | ||
525 | return -EINVAL; | 526 | return -EINVAL; |
526 | } | 527 | } |
527 | } | 528 | } |
@@ -532,6 +533,7 @@ static int ads1015_get_channels_config_of(struct i2c_client *client) | |||
532 | dev_err(&client->dev, | 533 | dev_err(&client->dev, |
533 | "invalid data_rate on %s\n", | 534 | "invalid data_rate on %s\n", |
534 | node->full_name); | 535 | node->full_name); |
536 | of_node_put(node); | ||
535 | return -EINVAL; | 537 | return -EINVAL; |
536 | } | 538 | } |
537 | } | 539 | } |
diff --git a/drivers/iio/adc/ti-ads8688.c b/drivers/iio/adc/ti-ads8688.c index c400439900af..4a163496d9e4 100644 --- a/drivers/iio/adc/ti-ads8688.c +++ b/drivers/iio/adc/ti-ads8688.c | |||
@@ -438,7 +438,7 @@ static int ads8688_probe(struct spi_device *spi) | |||
438 | return 0; | 438 | return 0; |
439 | 439 | ||
440 | error_out: | 440 | error_out: |
441 | if (!IS_ERR_OR_NULL(st->reg)) | 441 | if (!IS_ERR(st->reg)) |
442 | regulator_disable(st->reg); | 442 | regulator_disable(st->reg); |
443 | 443 | ||
444 | return ret; | 444 | return ret; |
@@ -451,7 +451,7 @@ static int ads8688_remove(struct spi_device *spi) | |||
451 | 451 | ||
452 | iio_device_unregister(indio_dev); | 452 | iio_device_unregister(indio_dev); |
453 | 453 | ||
454 | if (!IS_ERR_OR_NULL(st->reg)) | 454 | if (!IS_ERR(st->reg)) |
455 | regulator_disable(st->reg); | 455 | regulator_disable(st->reg); |
456 | 456 | ||
457 | return 0; | 457 | return 0; |
diff --git a/drivers/iio/buffer/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c index 4b2858ba1fd6..d3db1fce54d2 100644 --- a/drivers/iio/buffer/industrialio-triggered-buffer.c +++ b/drivers/iio/buffer/industrialio-triggered-buffer.c | |||
@@ -98,6 +98,48 @@ void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev) | |||
98 | } | 98 | } |
99 | EXPORT_SYMBOL(iio_triggered_buffer_cleanup); | 99 | EXPORT_SYMBOL(iio_triggered_buffer_cleanup); |
100 | 100 | ||
101 | static void devm_iio_triggered_buffer_clean(struct device *dev, void *res) | ||
102 | { | ||
103 | iio_triggered_buffer_cleanup(*(struct iio_dev **)res); | ||
104 | } | ||
105 | |||
106 | int devm_iio_triggered_buffer_setup(struct device *dev, | ||
107 | struct iio_dev *indio_dev, | ||
108 | irqreturn_t (*h)(int irq, void *p), | ||
109 | irqreturn_t (*thread)(int irq, void *p), | ||
110 | const struct iio_buffer_setup_ops *ops) | ||
111 | { | ||
112 | struct iio_dev **ptr; | ||
113 | int ret; | ||
114 | |||
115 | ptr = devres_alloc(devm_iio_triggered_buffer_clean, sizeof(*ptr), | ||
116 | GFP_KERNEL); | ||
117 | if (!ptr) | ||
118 | return -ENOMEM; | ||
119 | |||
120 | *ptr = indio_dev; | ||
121 | |||
122 | ret = iio_triggered_buffer_setup(indio_dev, h, thread, ops); | ||
123 | if (!ret) | ||
124 | devres_add(dev, ptr); | ||
125 | else | ||
126 | devres_free(ptr); | ||
127 | |||
128 | return ret; | ||
129 | } | ||
130 | EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_setup); | ||
131 | |||
132 | void devm_iio_triggered_buffer_cleanup(struct device *dev, | ||
133 | struct iio_dev *indio_dev) | ||
134 | { | ||
135 | int rc; | ||
136 | |||
137 | rc = devres_release(dev, devm_iio_triggered_buffer_clean, | ||
138 | devm_iio_device_match, indio_dev); | ||
139 | WARN_ON(rc); | ||
140 | } | ||
141 | EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_cleanup); | ||
142 | |||
101 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); | 143 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |
102 | MODULE_DESCRIPTION("IIO helper functions for setting up triggered buffers"); | 144 | MODULE_DESCRIPTION("IIO helper functions for setting up triggered buffers"); |
103 | MODULE_LICENSE("GPL"); | 145 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c index 652649da500f..8e0e4415c161 100644 --- a/drivers/iio/chemical/vz89x.c +++ b/drivers/iio/chemical/vz89x.c | |||
@@ -19,25 +19,55 @@ | |||
19 | #include <linux/mutex.h> | 19 | #include <linux/mutex.h> |
20 | #include <linux/init.h> | 20 | #include <linux/init.h> |
21 | #include <linux/i2c.h> | 21 | #include <linux/i2c.h> |
22 | #include <linux/of.h> | ||
23 | #include <linux/of_device.h> | ||
22 | 24 | ||
23 | #include <linux/iio/iio.h> | 25 | #include <linux/iio/iio.h> |
24 | #include <linux/iio/sysfs.h> | 26 | #include <linux/iio/sysfs.h> |
25 | 27 | ||
26 | #define VZ89X_REG_MEASUREMENT 0x09 | 28 | #define VZ89X_REG_MEASUREMENT 0x09 |
27 | #define VZ89X_REG_MEASUREMENT_SIZE 6 | 29 | #define VZ89X_REG_MEASUREMENT_RD_SIZE 6 |
30 | #define VZ89X_REG_MEASUREMENT_WR_SIZE 3 | ||
28 | 31 | ||
29 | #define VZ89X_VOC_CO2_IDX 0 | 32 | #define VZ89X_VOC_CO2_IDX 0 |
30 | #define VZ89X_VOC_SHORT_IDX 1 | 33 | #define VZ89X_VOC_SHORT_IDX 1 |
31 | #define VZ89X_VOC_TVOC_IDX 2 | 34 | #define VZ89X_VOC_TVOC_IDX 2 |
32 | #define VZ89X_VOC_RESISTANCE_IDX 3 | 35 | #define VZ89X_VOC_RESISTANCE_IDX 3 |
33 | 36 | ||
37 | #define VZ89TE_REG_MEASUREMENT 0x0c | ||
38 | #define VZ89TE_REG_MEASUREMENT_RD_SIZE 7 | ||
39 | #define VZ89TE_REG_MEASUREMENT_WR_SIZE 6 | ||
40 | |||
41 | #define VZ89TE_VOC_TVOC_IDX 0 | ||
42 | #define VZ89TE_VOC_CO2_IDX 1 | ||
43 | #define VZ89TE_VOC_RESISTANCE_IDX 2 | ||
44 | |||
45 | enum { | ||
46 | VZ89X, | ||
47 | VZ89TE, | ||
48 | }; | ||
49 | |||
50 | struct vz89x_chip_data; | ||
51 | |||
34 | struct vz89x_data { | 52 | struct vz89x_data { |
35 | struct i2c_client *client; | 53 | struct i2c_client *client; |
54 | const struct vz89x_chip_data *chip; | ||
36 | struct mutex lock; | 55 | struct mutex lock; |
37 | int (*xfer)(struct vz89x_data *data, u8 cmd); | 56 | int (*xfer)(struct vz89x_data *data, u8 cmd); |
38 | 57 | ||
58 | bool is_valid; | ||
39 | unsigned long last_update; | 59 | unsigned long last_update; |
40 | u8 buffer[VZ89X_REG_MEASUREMENT_SIZE]; | 60 | u8 buffer[VZ89TE_REG_MEASUREMENT_RD_SIZE]; |
61 | }; | ||
62 | |||
63 | struct vz89x_chip_data { | ||
64 | bool (*valid)(struct vz89x_data *data); | ||
65 | const struct iio_chan_spec *channels; | ||
66 | u8 num_channels; | ||
67 | |||
68 | u8 cmd; | ||
69 | u8 read_size; | ||
70 | u8 write_size; | ||
41 | }; | 71 | }; |
42 | 72 | ||
43 | static const struct iio_chan_spec vz89x_channels[] = { | 73 | static const struct iio_chan_spec vz89x_channels[] = { |
@@ -70,6 +100,40 @@ static const struct iio_chan_spec vz89x_channels[] = { | |||
70 | .info_mask_separate = | 100 | .info_mask_separate = |
71 | BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), | 101 | BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), |
72 | .address = VZ89X_VOC_RESISTANCE_IDX, | 102 | .address = VZ89X_VOC_RESISTANCE_IDX, |
103 | .scan_index = -1, | ||
104 | .scan_type = { | ||
105 | .endianness = IIO_LE, | ||
106 | }, | ||
107 | }, | ||
108 | }; | ||
109 | |||
110 | static const struct iio_chan_spec vz89te_channels[] = { | ||
111 | { | ||
112 | .type = IIO_CONCENTRATION, | ||
113 | .channel2 = IIO_MOD_VOC, | ||
114 | .modified = 1, | ||
115 | .info_mask_separate = | ||
116 | BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW), | ||
117 | .address = VZ89TE_VOC_TVOC_IDX, | ||
118 | }, | ||
119 | |||
120 | { | ||
121 | .type = IIO_CONCENTRATION, | ||
122 | .channel2 = IIO_MOD_CO2, | ||
123 | .modified = 1, | ||
124 | .info_mask_separate = | ||
125 | BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW), | ||
126 | .address = VZ89TE_VOC_CO2_IDX, | ||
127 | }, | ||
128 | { | ||
129 | .type = IIO_RESISTANCE, | ||
130 | .info_mask_separate = | ||
131 | BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), | ||
132 | .address = VZ89TE_VOC_RESISTANCE_IDX, | ||
133 | .scan_index = -1, | ||
134 | .scan_type = { | ||
135 | .endianness = IIO_BE, | ||
136 | }, | ||
73 | }, | 137 | }, |
74 | }; | 138 | }; |
75 | 139 | ||
@@ -93,29 +157,45 @@ static const struct attribute_group vz89x_attrs_group = { | |||
93 | * always zero, and by also confirming the VOC_short isn't zero. | 157 | * always zero, and by also confirming the VOC_short isn't zero. |
94 | */ | 158 | */ |
95 | 159 | ||
96 | static int vz89x_measurement_is_valid(struct vz89x_data *data) | 160 | static bool vz89x_measurement_is_valid(struct vz89x_data *data) |
97 | { | 161 | { |
98 | if (data->buffer[VZ89X_VOC_SHORT_IDX] == 0) | 162 | if (data->buffer[VZ89X_VOC_SHORT_IDX] == 0) |
99 | return 1; | 163 | return true; |
100 | 164 | ||
101 | return !!(data->buffer[VZ89X_REG_MEASUREMENT_SIZE - 1] > 0); | 165 | return !!(data->buffer[data->chip->read_size - 1] > 0); |
166 | } | ||
167 | |||
168 | /* VZ89TE device has a modified CRC-8 two complement check */ | ||
169 | static bool vz89te_measurement_is_valid(struct vz89x_data *data) | ||
170 | { | ||
171 | u8 crc = 0; | ||
172 | int i, sum = 0; | ||
173 | |||
174 | for (i = 0; i < (data->chip->read_size - 1); i++) { | ||
175 | sum = crc + data->buffer[i]; | ||
176 | crc = sum; | ||
177 | crc += sum / 256; | ||
178 | } | ||
179 | |||
180 | return !((0xff - crc) == data->buffer[data->chip->read_size - 1]); | ||
102 | } | 181 | } |
103 | 182 | ||
104 | static int vz89x_i2c_xfer(struct vz89x_data *data, u8 cmd) | 183 | static int vz89x_i2c_xfer(struct vz89x_data *data, u8 cmd) |
105 | { | 184 | { |
185 | const struct vz89x_chip_data *chip = data->chip; | ||
106 | struct i2c_client *client = data->client; | 186 | struct i2c_client *client = data->client; |
107 | struct i2c_msg msg[2]; | 187 | struct i2c_msg msg[2]; |
108 | int ret; | 188 | int ret; |
109 | u8 buf[3] = { cmd, 0, 0}; | 189 | u8 buf[6] = { cmd, 0, 0, 0, 0, 0xf3 }; |
110 | 190 | ||
111 | msg[0].addr = client->addr; | 191 | msg[0].addr = client->addr; |
112 | msg[0].flags = client->flags; | 192 | msg[0].flags = client->flags; |
113 | msg[0].len = 3; | 193 | msg[0].len = chip->write_size; |
114 | msg[0].buf = (char *) &buf; | 194 | msg[0].buf = (char *) &buf; |
115 | 195 | ||
116 | msg[1].addr = client->addr; | 196 | msg[1].addr = client->addr; |
117 | msg[1].flags = client->flags | I2C_M_RD; | 197 | msg[1].flags = client->flags | I2C_M_RD; |
118 | msg[1].len = VZ89X_REG_MEASUREMENT_SIZE; | 198 | msg[1].len = chip->read_size; |
119 | msg[1].buf = (char *) &data->buffer; | 199 | msg[1].buf = (char *) &data->buffer; |
120 | 200 | ||
121 | ret = i2c_transfer(client->adapter, msg, 2); | 201 | ret = i2c_transfer(client->adapter, msg, 2); |
@@ -133,7 +213,7 @@ static int vz89x_smbus_xfer(struct vz89x_data *data, u8 cmd) | |||
133 | if (ret < 0) | 213 | if (ret < 0) |
134 | return ret; | 214 | return ret; |
135 | 215 | ||
136 | for (i = 0; i < VZ89X_REG_MEASUREMENT_SIZE; i++) { | 216 | for (i = 0; i < data->chip->read_size; i++) { |
137 | ret = i2c_smbus_read_byte(client); | 217 | ret = i2c_smbus_read_byte(client); |
138 | if (ret < 0) | 218 | if (ret < 0) |
139 | return ret; | 219 | return ret; |
@@ -145,30 +225,47 @@ static int vz89x_smbus_xfer(struct vz89x_data *data, u8 cmd) | |||
145 | 225 | ||
146 | static int vz89x_get_measurement(struct vz89x_data *data) | 226 | static int vz89x_get_measurement(struct vz89x_data *data) |
147 | { | 227 | { |
228 | const struct vz89x_chip_data *chip = data->chip; | ||
148 | int ret; | 229 | int ret; |
149 | 230 | ||
150 | /* sensor can only be polled once a second max per datasheet */ | 231 | /* sensor can only be polled once a second max per datasheet */ |
151 | if (!time_after(jiffies, data->last_update + HZ)) | 232 | if (!time_after(jiffies, data->last_update + HZ)) |
152 | return 0; | 233 | return data->is_valid ? 0 : -EAGAIN; |
234 | |||
235 | data->is_valid = false; | ||
236 | data->last_update = jiffies; | ||
153 | 237 | ||
154 | ret = data->xfer(data, VZ89X_REG_MEASUREMENT); | 238 | ret = data->xfer(data, chip->cmd); |
155 | if (ret < 0) | 239 | if (ret < 0) |
156 | return ret; | 240 | return ret; |
157 | 241 | ||
158 | ret = vz89x_measurement_is_valid(data); | 242 | ret = chip->valid(data); |
159 | if (ret) | 243 | if (ret) |
160 | return -EAGAIN; | 244 | return -EAGAIN; |
161 | 245 | ||
162 | data->last_update = jiffies; | 246 | data->is_valid = true; |
163 | 247 | ||
164 | return 0; | 248 | return 0; |
165 | } | 249 | } |
166 | 250 | ||
167 | static int vz89x_get_resistance_reading(struct vz89x_data *data) | 251 | static int vz89x_get_resistance_reading(struct vz89x_data *data, |
252 | struct iio_chan_spec const *chan, | ||
253 | int *val) | ||
168 | { | 254 | { |
169 | u8 *buf = &data->buffer[VZ89X_VOC_RESISTANCE_IDX]; | 255 | u8 *tmp = (u8 *) &data->buffer[chan->address]; |
170 | 256 | ||
171 | return buf[0] | (buf[1] << 8); | 257 | switch (chan->scan_type.endianness) { |
258 | case IIO_LE: | ||
259 | *val = le32_to_cpup((__le32 *) tmp) & GENMASK(23, 0); | ||
260 | break; | ||
261 | case IIO_BE: | ||
262 | *val = be32_to_cpup((__be32 *) tmp) >> 8; | ||
263 | break; | ||
264 | default: | ||
265 | return -EINVAL; | ||
266 | } | ||
267 | |||
268 | return 0; | ||
172 | } | 269 | } |
173 | 270 | ||
174 | static int vz89x_read_raw(struct iio_dev *indio_dev, | 271 | static int vz89x_read_raw(struct iio_dev *indio_dev, |
@@ -187,15 +284,15 @@ static int vz89x_read_raw(struct iio_dev *indio_dev, | |||
187 | if (ret) | 284 | if (ret) |
188 | return ret; | 285 | return ret; |
189 | 286 | ||
190 | switch (chan->address) { | 287 | switch (chan->type) { |
191 | case VZ89X_VOC_CO2_IDX: | 288 | case IIO_CONCENTRATION: |
192 | case VZ89X_VOC_SHORT_IDX: | ||
193 | case VZ89X_VOC_TVOC_IDX: | ||
194 | *val = data->buffer[chan->address]; | 289 | *val = data->buffer[chan->address]; |
195 | return IIO_VAL_INT; | 290 | return IIO_VAL_INT; |
196 | case VZ89X_VOC_RESISTANCE_IDX: | 291 | case IIO_RESISTANCE: |
197 | *val = vz89x_get_resistance_reading(data); | 292 | ret = vz89x_get_resistance_reading(data, chan, val); |
198 | return IIO_VAL_INT; | 293 | if (!ret) |
294 | return IIO_VAL_INT; | ||
295 | break; | ||
199 | default: | 296 | default: |
200 | return -EINVAL; | 297 | return -EINVAL; |
201 | } | 298 | } |
@@ -210,12 +307,12 @@ static int vz89x_read_raw(struct iio_dev *indio_dev, | |||
210 | } | 307 | } |
211 | break; | 308 | break; |
212 | case IIO_CHAN_INFO_OFFSET: | 309 | case IIO_CHAN_INFO_OFFSET: |
213 | switch (chan->address) { | 310 | switch (chan->channel2) { |
214 | case VZ89X_VOC_CO2_IDX: | 311 | case IIO_MOD_CO2: |
215 | *val = 44; | 312 | *val = 44; |
216 | *val2 = 250000; | 313 | *val2 = 250000; |
217 | return IIO_VAL_INT_PLUS_MICRO; | 314 | return IIO_VAL_INT_PLUS_MICRO; |
218 | case VZ89X_VOC_TVOC_IDX: | 315 | case IIO_MOD_VOC: |
219 | *val = -13; | 316 | *val = -13; |
220 | return IIO_VAL_INT; | 317 | return IIO_VAL_INT; |
221 | default: | 318 | default: |
@@ -232,11 +329,43 @@ static const struct iio_info vz89x_info = { | |||
232 | .driver_module = THIS_MODULE, | 329 | .driver_module = THIS_MODULE, |
233 | }; | 330 | }; |
234 | 331 | ||
332 | static const struct vz89x_chip_data vz89x_chips[] = { | ||
333 | { | ||
334 | .valid = vz89x_measurement_is_valid, | ||
335 | |||
336 | .cmd = VZ89X_REG_MEASUREMENT, | ||
337 | .read_size = VZ89X_REG_MEASUREMENT_RD_SIZE, | ||
338 | .write_size = VZ89X_REG_MEASUREMENT_WR_SIZE, | ||
339 | |||
340 | .channels = vz89x_channels, | ||
341 | .num_channels = ARRAY_SIZE(vz89x_channels), | ||
342 | }, | ||
343 | { | ||
344 | .valid = vz89te_measurement_is_valid, | ||
345 | |||
346 | .cmd = VZ89TE_REG_MEASUREMENT, | ||
347 | .read_size = VZ89TE_REG_MEASUREMENT_RD_SIZE, | ||
348 | .write_size = VZ89TE_REG_MEASUREMENT_WR_SIZE, | ||
349 | |||
350 | .channels = vz89te_channels, | ||
351 | .num_channels = ARRAY_SIZE(vz89te_channels), | ||
352 | }, | ||
353 | }; | ||
354 | |||
355 | static const struct of_device_id vz89x_dt_ids[] = { | ||
356 | { .compatible = "sgx,vz89x", .data = (void *) VZ89X }, | ||
357 | { .compatible = "sgx,vz89te", .data = (void *) VZ89TE }, | ||
358 | { } | ||
359 | }; | ||
360 | MODULE_DEVICE_TABLE(of, vz89x_dt_ids); | ||
361 | |||
235 | static int vz89x_probe(struct i2c_client *client, | 362 | static int vz89x_probe(struct i2c_client *client, |
236 | const struct i2c_device_id *id) | 363 | const struct i2c_device_id *id) |
237 | { | 364 | { |
238 | struct iio_dev *indio_dev; | 365 | struct iio_dev *indio_dev; |
239 | struct vz89x_data *data; | 366 | struct vz89x_data *data; |
367 | const struct of_device_id *of_id; | ||
368 | int chip_id; | ||
240 | 369 | ||
241 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); | 370 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); |
242 | if (!indio_dev) | 371 | if (!indio_dev) |
@@ -251,8 +380,15 @@ static int vz89x_probe(struct i2c_client *client, | |||
251 | else | 380 | else |
252 | return -EOPNOTSUPP; | 381 | return -EOPNOTSUPP; |
253 | 382 | ||
383 | of_id = of_match_device(vz89x_dt_ids, &client->dev); | ||
384 | if (!of_id) | ||
385 | chip_id = id->driver_data; | ||
386 | else | ||
387 | chip_id = (unsigned long)of_id->data; | ||
388 | |||
254 | i2c_set_clientdata(client, indio_dev); | 389 | i2c_set_clientdata(client, indio_dev); |
255 | data->client = client; | 390 | data->client = client; |
391 | data->chip = &vz89x_chips[chip_id]; | ||
256 | data->last_update = jiffies - HZ; | 392 | data->last_update = jiffies - HZ; |
257 | mutex_init(&data->lock); | 393 | mutex_init(&data->lock); |
258 | 394 | ||
@@ -261,24 +397,19 @@ static int vz89x_probe(struct i2c_client *client, | |||
261 | indio_dev->name = dev_name(&client->dev); | 397 | indio_dev->name = dev_name(&client->dev); |
262 | indio_dev->modes = INDIO_DIRECT_MODE; | 398 | indio_dev->modes = INDIO_DIRECT_MODE; |
263 | 399 | ||
264 | indio_dev->channels = vz89x_channels; | 400 | indio_dev->channels = data->chip->channels; |
265 | indio_dev->num_channels = ARRAY_SIZE(vz89x_channels); | 401 | indio_dev->num_channels = data->chip->num_channels; |
266 | 402 | ||
267 | return devm_iio_device_register(&client->dev, indio_dev); | 403 | return devm_iio_device_register(&client->dev, indio_dev); |
268 | } | 404 | } |
269 | 405 | ||
270 | static const struct i2c_device_id vz89x_id[] = { | 406 | static const struct i2c_device_id vz89x_id[] = { |
271 | { "vz89x", 0 }, | 407 | { "vz89x", VZ89X }, |
408 | { "vz89te", VZ89TE }, | ||
272 | { } | 409 | { } |
273 | }; | 410 | }; |
274 | MODULE_DEVICE_TABLE(i2c, vz89x_id); | 411 | MODULE_DEVICE_TABLE(i2c, vz89x_id); |
275 | 412 | ||
276 | static const struct of_device_id vz89x_dt_ids[] = { | ||
277 | { .compatible = "sgx,vz89x" }, | ||
278 | { } | ||
279 | }; | ||
280 | MODULE_DEVICE_TABLE(of, vz89x_dt_ids); | ||
281 | |||
282 | static struct i2c_driver vz89x_driver = { | 413 | static struct i2c_driver vz89x_driver = { |
283 | .driver = { | 414 | .driver = { |
284 | .name = "vz89x", | 415 | .name = "vz89x", |
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index 5264ed6e03e5..a3cce3a38300 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c | |||
@@ -199,8 +199,7 @@ error_ret: | |||
199 | } | 199 | } |
200 | EXPORT_SYMBOL(hid_sensor_setup_trigger); | 200 | EXPORT_SYMBOL(hid_sensor_setup_trigger); |
201 | 201 | ||
202 | #ifdef CONFIG_PM | 202 | static int __maybe_unused hid_sensor_suspend(struct device *dev) |
203 | static int hid_sensor_suspend(struct device *dev) | ||
204 | { | 203 | { |
205 | struct platform_device *pdev = to_platform_device(dev); | 204 | struct platform_device *pdev = to_platform_device(dev); |
206 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); | 205 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); |
@@ -209,7 +208,7 @@ static int hid_sensor_suspend(struct device *dev) | |||
209 | return _hid_sensor_power_state(attrb, false); | 208 | return _hid_sensor_power_state(attrb, false); |
210 | } | 209 | } |
211 | 210 | ||
212 | static int hid_sensor_resume(struct device *dev) | 211 | static int __maybe_unused hid_sensor_resume(struct device *dev) |
213 | { | 212 | { |
214 | struct platform_device *pdev = to_platform_device(dev); | 213 | struct platform_device *pdev = to_platform_device(dev); |
215 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); | 214 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); |
@@ -218,7 +217,7 @@ static int hid_sensor_resume(struct device *dev) | |||
218 | return 0; | 217 | return 0; |
219 | } | 218 | } |
220 | 219 | ||
221 | static int hid_sensor_runtime_resume(struct device *dev) | 220 | static int __maybe_unused hid_sensor_runtime_resume(struct device *dev) |
222 | { | 221 | { |
223 | struct platform_device *pdev = to_platform_device(dev); | 222 | struct platform_device *pdev = to_platform_device(dev); |
224 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); | 223 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); |
@@ -226,8 +225,6 @@ static int hid_sensor_runtime_resume(struct device *dev) | |||
226 | return _hid_sensor_power_state(attrb, true); | 225 | return _hid_sensor_power_state(attrb, true); |
227 | } | 226 | } |
228 | 227 | ||
229 | #endif | ||
230 | |||
231 | const struct dev_pm_ops hid_sensor_pm_ops = { | 228 | const struct dev_pm_ops hid_sensor_pm_ops = { |
232 | SET_SYSTEM_SLEEP_PM_OPS(hid_sensor_suspend, hid_sensor_resume) | 229 | SET_SYSTEM_SLEEP_PM_OPS(hid_sensor_suspend, hid_sensor_resume) |
233 | SET_RUNTIME_PM_OPS(hid_sensor_suspend, | 230 | SET_RUNTIME_PM_OPS(hid_sensor_suspend, |
diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c index d06e728cea37..fe7775bb3740 100644 --- a/drivers/iio/common/st_sensors/st_sensors_buffer.c +++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c | |||
@@ -63,7 +63,7 @@ irqreturn_t st_sensors_trigger_handler(int irq, void *p) | |||
63 | * the hardware trigger) and the hw_timestamp may get updated. | 63 | * the hardware trigger) and the hw_timestamp may get updated. |
64 | * By storing it in a local variable first, we are safe. | 64 | * By storing it in a local variable first, we are safe. |
65 | */ | 65 | */ |
66 | if (sdata->hw_irq_trigger) | 66 | if (iio_trigger_using_own(indio_dev)) |
67 | timestamp = sdata->hw_timestamp; | 67 | timestamp = sdata->hw_timestamp; |
68 | else | 68 | else |
69 | timestamp = iio_get_time_ns(indio_dev); | 69 | timestamp = iio_get_time_ns(indio_dev); |
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index 2d5282e05482..285a64a589d7 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c | |||
@@ -234,39 +234,35 @@ int st_sensors_power_enable(struct iio_dev *indio_dev) | |||
234 | int err; | 234 | int err; |
235 | 235 | ||
236 | /* Regulators not mandatory, but if requested we should enable them. */ | 236 | /* Regulators not mandatory, but if requested we should enable them. */ |
237 | pdata->vdd = devm_regulator_get_optional(indio_dev->dev.parent, "vdd"); | 237 | pdata->vdd = devm_regulator_get(indio_dev->dev.parent, "vdd"); |
238 | if (!IS_ERR(pdata->vdd)) { | 238 | if (IS_ERR(pdata->vdd)) { |
239 | err = regulator_enable(pdata->vdd); | 239 | dev_err(&indio_dev->dev, "unable to get Vdd supply\n"); |
240 | if (err != 0) { | 240 | return PTR_ERR(pdata->vdd); |
241 | dev_warn(&indio_dev->dev, | 241 | } |
242 | "Failed to enable specified Vdd supply\n"); | 242 | err = regulator_enable(pdata->vdd); |
243 | return err; | 243 | if (err != 0) { |
244 | } | 244 | dev_warn(&indio_dev->dev, |
245 | } else { | 245 | "Failed to enable specified Vdd supply\n"); |
246 | err = PTR_ERR(pdata->vdd); | 246 | return err; |
247 | if (err != -ENODEV) | ||
248 | return err; | ||
249 | } | 247 | } |
250 | 248 | ||
251 | pdata->vdd_io = devm_regulator_get_optional(indio_dev->dev.parent, "vddio"); | 249 | pdata->vdd_io = devm_regulator_get(indio_dev->dev.parent, "vddio"); |
252 | if (!IS_ERR(pdata->vdd_io)) { | 250 | if (IS_ERR(pdata->vdd_io)) { |
253 | err = regulator_enable(pdata->vdd_io); | 251 | dev_err(&indio_dev->dev, "unable to get Vdd_IO supply\n"); |
254 | if (err != 0) { | ||
255 | dev_warn(&indio_dev->dev, | ||
256 | "Failed to enable specified Vdd_IO supply\n"); | ||
257 | goto st_sensors_disable_vdd; | ||
258 | } | ||
259 | } else { | ||
260 | err = PTR_ERR(pdata->vdd_io); | 252 | err = PTR_ERR(pdata->vdd_io); |
261 | if (err != -ENODEV) | 253 | goto st_sensors_disable_vdd; |
262 | goto st_sensors_disable_vdd; | 254 | } |
255 | err = regulator_enable(pdata->vdd_io); | ||
256 | if (err != 0) { | ||
257 | dev_warn(&indio_dev->dev, | ||
258 | "Failed to enable specified Vdd_IO supply\n"); | ||
259 | goto st_sensors_disable_vdd; | ||
263 | } | 260 | } |
264 | 261 | ||
265 | return 0; | 262 | return 0; |
266 | 263 | ||
267 | st_sensors_disable_vdd: | 264 | st_sensors_disable_vdd: |
268 | if (!IS_ERR_OR_NULL(pdata->vdd)) | 265 | regulator_disable(pdata->vdd); |
269 | regulator_disable(pdata->vdd); | ||
270 | return err; | 266 | return err; |
271 | } | 267 | } |
272 | EXPORT_SYMBOL(st_sensors_power_enable); | 268 | EXPORT_SYMBOL(st_sensors_power_enable); |
@@ -275,11 +271,8 @@ void st_sensors_power_disable(struct iio_dev *indio_dev) | |||
275 | { | 271 | { |
276 | struct st_sensor_data *pdata = iio_priv(indio_dev); | 272 | struct st_sensor_data *pdata = iio_priv(indio_dev); |
277 | 273 | ||
278 | if (!IS_ERR_OR_NULL(pdata->vdd)) | 274 | regulator_disable(pdata->vdd); |
279 | regulator_disable(pdata->vdd); | 275 | regulator_disable(pdata->vdd_io); |
280 | |||
281 | if (!IS_ERR_OR_NULL(pdata->vdd_io)) | ||
282 | regulator_disable(pdata->vdd_io); | ||
283 | } | 276 | } |
284 | EXPORT_SYMBOL(st_sensors_power_disable); | 277 | EXPORT_SYMBOL(st_sensors_power_disable); |
285 | 278 | ||
diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c index e66f12ee8a55..fa73e6795359 100644 --- a/drivers/iio/common/st_sensors/st_sensors_trigger.c +++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c | |||
@@ -66,7 +66,7 @@ static int st_sensors_new_samples_available(struct iio_dev *indio_dev, | |||
66 | * @irq: irq number | 66 | * @irq: irq number |
67 | * @p: private handler data | 67 | * @p: private handler data |
68 | */ | 68 | */ |
69 | irqreturn_t st_sensors_irq_handler(int irq, void *p) | 69 | static irqreturn_t st_sensors_irq_handler(int irq, void *p) |
70 | { | 70 | { |
71 | struct iio_trigger *trig = p; | 71 | struct iio_trigger *trig = p; |
72 | struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); | 72 | struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); |
@@ -82,7 +82,7 @@ irqreturn_t st_sensors_irq_handler(int irq, void *p) | |||
82 | * @irq: irq number | 82 | * @irq: irq number |
83 | * @p: private handler data | 83 | * @p: private handler data |
84 | */ | 84 | */ |
85 | irqreturn_t st_sensors_irq_thread(int irq, void *p) | 85 | static irqreturn_t st_sensors_irq_thread(int irq, void *p) |
86 | { | 86 | { |
87 | struct iio_trigger *trig = p; | 87 | struct iio_trigger *trig = p; |
88 | struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); | 88 | struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); |
diff --git a/drivers/iio/dac/Kconfig b/drivers/iio/dac/Kconfig index b9f044249194..120b24478469 100644 --- a/drivers/iio/dac/Kconfig +++ b/drivers/iio/dac/Kconfig | |||
@@ -190,6 +190,16 @@ config CIO_DAC | |||
190 | base port addresses for the devices may be configured via the base | 190 | base port addresses for the devices may be configured via the base |
191 | array module parameter. | 191 | array module parameter. |
192 | 192 | ||
193 | config AD8801 | ||
194 | tristate "Analog Devices AD8801/AD8803 DAC driver" | ||
195 | depends on SPI_MASTER | ||
196 | help | ||
197 | Say yes here to build support for Analog Devices AD8801, AD8803 Digital to | ||
198 | Analog Converters (DAC). | ||
199 | |||
200 | To compile this driver as a module choose M here: the module will be called | ||
201 | ad8801. | ||
202 | |||
193 | config LPC18XX_DAC | 203 | config LPC18XX_DAC |
194 | tristate "NXP LPC18xx DAC driver" | 204 | tristate "NXP LPC18xx DAC driver" |
195 | depends on ARCH_LPC18XX || COMPILE_TEST | 205 | depends on ARCH_LPC18XX || COMPILE_TEST |
@@ -254,16 +264,6 @@ config MCP4922 | |||
254 | To compile this driver as a module, choose M here: the module | 264 | To compile this driver as a module, choose M here: the module |
255 | will be called mcp4922. | 265 | will be called mcp4922. |
256 | 266 | ||
257 | config STX104 | ||
258 | tristate "Apex Embedded Systems STX104 DAC driver" | ||
259 | depends on X86 && ISA_BUS_API | ||
260 | select GPIOLIB | ||
261 | help | ||
262 | Say yes here to build support for the 2-channel DAC and GPIO on the | ||
263 | Apex Embedded Systems STX104 integrated analog PC/104 card. The base | ||
264 | port addresses for the devices may be configured via the base array | ||
265 | module parameter. | ||
266 | |||
267 | config VF610_DAC | 267 | config VF610_DAC |
268 | tristate "Vybrid vf610 DAC driver" | 268 | tristate "Vybrid vf610 DAC driver" |
269 | depends on OF | 269 | depends on OF |
diff --git a/drivers/iio/dac/Makefile b/drivers/iio/dac/Makefile index b1a120612462..27642bbf75f2 100644 --- a/drivers/iio/dac/Makefile +++ b/drivers/iio/dac/Makefile | |||
@@ -20,6 +20,7 @@ obj-$(CONFIG_AD5764) += ad5764.o | |||
20 | obj-$(CONFIG_AD5791) += ad5791.o | 20 | obj-$(CONFIG_AD5791) += ad5791.o |
21 | obj-$(CONFIG_AD5686) += ad5686.o | 21 | obj-$(CONFIG_AD5686) += ad5686.o |
22 | obj-$(CONFIG_AD7303) += ad7303.o | 22 | obj-$(CONFIG_AD7303) += ad7303.o |
23 | obj-$(CONFIG_AD8801) += ad8801.o | ||
23 | obj-$(CONFIG_CIO_DAC) += cio-dac.o | 24 | obj-$(CONFIG_CIO_DAC) += cio-dac.o |
24 | obj-$(CONFIG_LPC18XX_DAC) += lpc18xx_dac.o | 25 | obj-$(CONFIG_LPC18XX_DAC) += lpc18xx_dac.o |
25 | obj-$(CONFIG_M62332) += m62332.o | 26 | obj-$(CONFIG_M62332) += m62332.o |
@@ -27,5 +28,4 @@ obj-$(CONFIG_MAX517) += max517.o | |||
27 | obj-$(CONFIG_MAX5821) += max5821.o | 28 | obj-$(CONFIG_MAX5821) += max5821.o |
28 | obj-$(CONFIG_MCP4725) += mcp4725.o | 29 | obj-$(CONFIG_MCP4725) += mcp4725.o |
29 | obj-$(CONFIG_MCP4922) += mcp4922.o | 30 | obj-$(CONFIG_MCP4922) += mcp4922.o |
30 | obj-$(CONFIG_STX104) += stx104.o | ||
31 | obj-$(CONFIG_VF610_DAC) += vf610_dac.o | 31 | obj-$(CONFIG_VF610_DAC) += vf610_dac.o |
diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c index 0fde593ec0d9..5f7968232564 100644 --- a/drivers/iio/dac/ad5755.c +++ b/drivers/iio/dac/ad5755.c | |||
@@ -655,7 +655,7 @@ static struct ad5755_platform_data *ad5755_parse_dt(struct device *dev) | |||
655 | 655 | ||
656 | devnr = 0; | 656 | devnr = 0; |
657 | for_each_child_of_node(np, pp) { | 657 | for_each_child_of_node(np, pp) { |
658 | if (devnr > AD5755_NUM_CHANNELS) { | 658 | if (devnr >= AD5755_NUM_CHANNELS) { |
659 | dev_err(dev, | 659 | dev_err(dev, |
660 | "There is to many channels defined in DT\n"); | 660 | "There is to many channels defined in DT\n"); |
661 | goto error_out; | 661 | goto error_out; |
diff --git a/drivers/iio/dac/ad8801.c b/drivers/iio/dac/ad8801.c new file mode 100644 index 000000000000..f06faa1aec09 --- /dev/null +++ b/drivers/iio/dac/ad8801.c | |||
@@ -0,0 +1,239 @@ | |||
1 | /* | ||
2 | * IIO DAC driver for Analog Devices AD8801 DAC | ||
3 | * | ||
4 | * Copyright (C) 2016 Gwenhael Goavec-Merou | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License, version 2, as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but | ||
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * General Public License for more details. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #include <linux/iio/iio.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/regulator/consumer.h> | ||
19 | #include <linux/spi/spi.h> | ||
20 | #include <linux/sysfs.h> | ||
21 | |||
22 | #define AD8801_CFG_ADDR_OFFSET 8 | ||
23 | |||
24 | enum ad8801_device_ids { | ||
25 | ID_AD8801, | ||
26 | ID_AD8803, | ||
27 | }; | ||
28 | |||
29 | struct ad8801_state { | ||
30 | struct spi_device *spi; | ||
31 | unsigned char dac_cache[8]; /* Value write on each channel */ | ||
32 | unsigned int vrefh_mv; | ||
33 | unsigned int vrefl_mv; | ||
34 | struct regulator *vrefh_reg; | ||
35 | struct regulator *vrefl_reg; | ||
36 | |||
37 | __be16 data ____cacheline_aligned; | ||
38 | }; | ||
39 | |||
40 | static int ad8801_spi_write(struct ad8801_state *state, | ||
41 | u8 channel, unsigned char value) | ||
42 | { | ||
43 | state->data = cpu_to_be16((channel << AD8801_CFG_ADDR_OFFSET) | value); | ||
44 | return spi_write(state->spi, &state->data, sizeof(state->data)); | ||
45 | } | ||
46 | |||
47 | static int ad8801_write_raw(struct iio_dev *indio_dev, | ||
48 | struct iio_chan_spec const *chan, int val, int val2, long mask) | ||
49 | { | ||
50 | struct ad8801_state *state = iio_priv(indio_dev); | ||
51 | int ret; | ||
52 | |||
53 | switch (mask) { | ||
54 | case IIO_CHAN_INFO_RAW: | ||
55 | if (val >= 256 || val < 0) | ||
56 | return -EINVAL; | ||
57 | |||
58 | ret = ad8801_spi_write(state, chan->channel, val); | ||
59 | if (ret == 0) | ||
60 | state->dac_cache[chan->channel] = val; | ||
61 | break; | ||
62 | default: | ||
63 | ret = -EINVAL; | ||
64 | } | ||
65 | |||
66 | return ret; | ||
67 | } | ||
68 | |||
69 | static int ad8801_read_raw(struct iio_dev *indio_dev, | ||
70 | struct iio_chan_spec const *chan, int *val, int *val2, long info) | ||
71 | { | ||
72 | struct ad8801_state *state = iio_priv(indio_dev); | ||
73 | |||
74 | switch (info) { | ||
75 | case IIO_CHAN_INFO_RAW: | ||
76 | *val = state->dac_cache[chan->channel]; | ||
77 | return IIO_VAL_INT; | ||
78 | case IIO_CHAN_INFO_SCALE: | ||
79 | *val = state->vrefh_mv - state->vrefl_mv; | ||
80 | *val2 = 8; | ||
81 | return IIO_VAL_FRACTIONAL_LOG2; | ||
82 | case IIO_CHAN_INFO_OFFSET: | ||
83 | *val = state->vrefl_mv; | ||
84 | return IIO_VAL_INT; | ||
85 | default: | ||
86 | return -EINVAL; | ||
87 | } | ||
88 | |||
89 | return -EINVAL; | ||
90 | } | ||
91 | |||
92 | static const struct iio_info ad8801_info = { | ||
93 | .read_raw = ad8801_read_raw, | ||
94 | .write_raw = ad8801_write_raw, | ||
95 | .driver_module = THIS_MODULE, | ||
96 | }; | ||
97 | |||
98 | #define AD8801_CHANNEL(chan) { \ | ||
99 | .type = IIO_VOLTAGE, \ | ||
100 | .indexed = 1, \ | ||
101 | .output = 1, \ | ||
102 | .channel = chan, \ | ||
103 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
104 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ | ||
105 | BIT(IIO_CHAN_INFO_OFFSET), \ | ||
106 | } | ||
107 | |||
108 | static const struct iio_chan_spec ad8801_channels[] = { | ||
109 | AD8801_CHANNEL(0), | ||
110 | AD8801_CHANNEL(1), | ||
111 | AD8801_CHANNEL(2), | ||
112 | AD8801_CHANNEL(3), | ||
113 | AD8801_CHANNEL(4), | ||
114 | AD8801_CHANNEL(5), | ||
115 | AD8801_CHANNEL(6), | ||
116 | AD8801_CHANNEL(7), | ||
117 | }; | ||
118 | |||
119 | static int ad8801_probe(struct spi_device *spi) | ||
120 | { | ||
121 | struct iio_dev *indio_dev; | ||
122 | struct ad8801_state *state; | ||
123 | const struct spi_device_id *id; | ||
124 | int ret; | ||
125 | |||
126 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*state)); | ||
127 | if (indio_dev == NULL) | ||
128 | return -ENOMEM; | ||
129 | |||
130 | state = iio_priv(indio_dev); | ||
131 | state->spi = spi; | ||
132 | id = spi_get_device_id(spi); | ||
133 | |||
134 | state->vrefh_reg = devm_regulator_get(&spi->dev, "vrefh"); | ||
135 | if (IS_ERR(state->vrefh_reg)) { | ||
136 | dev_err(&spi->dev, "Vrefh regulator not specified\n"); | ||
137 | return PTR_ERR(state->vrefh_reg); | ||
138 | } | ||
139 | |||
140 | ret = regulator_enable(state->vrefh_reg); | ||
141 | if (ret) { | ||
142 | dev_err(&spi->dev, "Failed to enable vrefh regulator: %d\n", | ||
143 | ret); | ||
144 | return ret; | ||
145 | } | ||
146 | |||
147 | ret = regulator_get_voltage(state->vrefh_reg); | ||
148 | if (ret < 0) { | ||
149 | dev_err(&spi->dev, "Failed to read vrefh regulator: %d\n", | ||
150 | ret); | ||
151 | goto error_disable_vrefh_reg; | ||
152 | } | ||
153 | state->vrefh_mv = ret / 1000; | ||
154 | |||
155 | if (id->driver_data == ID_AD8803) { | ||
156 | state->vrefl_reg = devm_regulator_get(&spi->dev, "vrefl"); | ||
157 | if (IS_ERR(state->vrefl_reg)) { | ||
158 | dev_err(&spi->dev, "Vrefl regulator not specified\n"); | ||
159 | ret = PTR_ERR(state->vrefl_reg); | ||
160 | goto error_disable_vrefh_reg; | ||
161 | } | ||
162 | |||
163 | ret = regulator_enable(state->vrefl_reg); | ||
164 | if (ret) { | ||
165 | dev_err(&spi->dev, "Failed to enable vrefl regulator: %d\n", | ||
166 | ret); | ||
167 | goto error_disable_vrefh_reg; | ||
168 | } | ||
169 | |||
170 | ret = regulator_get_voltage(state->vrefl_reg); | ||
171 | if (ret < 0) { | ||
172 | dev_err(&spi->dev, "Failed to read vrefl regulator: %d\n", | ||
173 | ret); | ||
174 | goto error_disable_vrefl_reg; | ||
175 | } | ||
176 | state->vrefl_mv = ret / 1000; | ||
177 | } else { | ||
178 | state->vrefl_mv = 0; | ||
179 | state->vrefl_reg = NULL; | ||
180 | } | ||
181 | |||
182 | spi_set_drvdata(spi, indio_dev); | ||
183 | indio_dev->dev.parent = &spi->dev; | ||
184 | indio_dev->info = &ad8801_info; | ||
185 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
186 | indio_dev->channels = ad8801_channels; | ||
187 | indio_dev->num_channels = ARRAY_SIZE(ad8801_channels); | ||
188 | indio_dev->name = id->name; | ||
189 | |||
190 | ret = iio_device_register(indio_dev); | ||
191 | if (ret) { | ||
192 | dev_err(&spi->dev, "Failed to register iio device: %d\n", | ||
193 | ret); | ||
194 | goto error_disable_vrefl_reg; | ||
195 | } | ||
196 | |||
197 | return 0; | ||
198 | |||
199 | error_disable_vrefl_reg: | ||
200 | if (state->vrefl_reg) | ||
201 | regulator_disable(state->vrefl_reg); | ||
202 | error_disable_vrefh_reg: | ||
203 | regulator_disable(state->vrefh_reg); | ||
204 | return ret; | ||
205 | } | ||
206 | |||
207 | static int ad8801_remove(struct spi_device *spi) | ||
208 | { | ||
209 | struct iio_dev *indio_dev = spi_get_drvdata(spi); | ||
210 | struct ad8801_state *state = iio_priv(indio_dev); | ||
211 | |||
212 | iio_device_unregister(indio_dev); | ||
213 | if (state->vrefl_reg) | ||
214 | regulator_disable(state->vrefl_reg); | ||
215 | regulator_disable(state->vrefh_reg); | ||
216 | |||
217 | return 0; | ||
218 | } | ||
219 | |||
220 | static const struct spi_device_id ad8801_ids[] = { | ||
221 | {"ad8801", ID_AD8801}, | ||
222 | {"ad8803", ID_AD8803}, | ||
223 | {} | ||
224 | }; | ||
225 | MODULE_DEVICE_TABLE(spi, ad8801_ids); | ||
226 | |||
227 | static struct spi_driver ad8801_driver = { | ||
228 | .driver = { | ||
229 | .name = "ad8801", | ||
230 | }, | ||
231 | .probe = ad8801_probe, | ||
232 | .remove = ad8801_remove, | ||
233 | .id_table = ad8801_ids, | ||
234 | }; | ||
235 | module_spi_driver(ad8801_driver); | ||
236 | |||
237 | MODULE_AUTHOR("Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>"); | ||
238 | MODULE_DESCRIPTION("Analog Devices AD8801/AD8803 DAC"); | ||
239 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index d2b889918c3e..fc340ed3dca1 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c | |||
@@ -1308,7 +1308,7 @@ static void devm_iio_device_release(struct device *dev, void *res) | |||
1308 | iio_device_free(*(struct iio_dev **)res); | 1308 | iio_device_free(*(struct iio_dev **)res); |
1309 | } | 1309 | } |
1310 | 1310 | ||
1311 | static int devm_iio_device_match(struct device *dev, void *res, void *data) | 1311 | int devm_iio_device_match(struct device *dev, void *res, void *data) |
1312 | { | 1312 | { |
1313 | struct iio_dev **r = res; | 1313 | struct iio_dev **r = res; |
1314 | if (!r || !*r) { | 1314 | if (!r || !*r) { |
@@ -1317,6 +1317,7 @@ static int devm_iio_device_match(struct device *dev, void *res, void *data) | |||
1317 | } | 1317 | } |
1318 | return *r == data; | 1318 | return *r == data; |
1319 | } | 1319 | } |
1320 | EXPORT_SYMBOL_GPL(devm_iio_device_match); | ||
1320 | 1321 | ||
1321 | /** | 1322 | /** |
1322 | * devm_iio_device_alloc - Resource-managed iio_device_alloc() | 1323 | * devm_iio_device_alloc - Resource-managed iio_device_alloc() |
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c index 0ebfc923a997..90fac8ec63c9 100644 --- a/drivers/iio/industrialio-event.c +++ b/drivers/iio/industrialio-event.c | |||
@@ -57,6 +57,11 @@ bool iio_event_enabled(const struct iio_event_interface *ev_int) | |||
57 | * | 57 | * |
58 | * Note: The caller must make sure that this function is not running | 58 | * Note: The caller must make sure that this function is not running |
59 | * concurrently for the same indio_dev more than once. | 59 | * concurrently for the same indio_dev more than once. |
60 | * | ||
61 | * This function may be safely used as soon as a valid reference to iio_dev has | ||
62 | * been obtained via iio_device_alloc(), but any events that are submitted | ||
63 | * before iio_device_register() has successfully completed will be silently | ||
64 | * discarded. | ||
60 | **/ | 65 | **/ |
61 | int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp) | 66 | int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp) |
62 | { | 67 | { |
@@ -64,6 +69,9 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp) | |||
64 | struct iio_event_data ev; | 69 | struct iio_event_data ev; |
65 | int copied; | 70 | int copied; |
66 | 71 | ||
72 | if (!ev_int) | ||
73 | return 0; | ||
74 | |||
67 | /* Does anyone care? */ | 75 | /* Does anyone care? */ |
68 | if (iio_event_enabled(ev_int)) { | 76 | if (iio_event_enabled(ev_int)) { |
69 | 77 | ||
diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index 7ad82fdd3e5b..e1e104845e38 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c | |||
@@ -119,6 +119,22 @@ void iio_trigger_unregister(struct iio_trigger *trig_info) | |||
119 | } | 119 | } |
120 | EXPORT_SYMBOL(iio_trigger_unregister); | 120 | EXPORT_SYMBOL(iio_trigger_unregister); |
121 | 121 | ||
122 | int iio_trigger_set_immutable(struct iio_dev *indio_dev, struct iio_trigger *trig) | ||
123 | { | ||
124 | if (!indio_dev || !trig) | ||
125 | return -EINVAL; | ||
126 | |||
127 | mutex_lock(&indio_dev->mlock); | ||
128 | WARN_ON(indio_dev->trig_readonly); | ||
129 | |||
130 | indio_dev->trig = iio_trigger_get(trig); | ||
131 | indio_dev->trig_readonly = true; | ||
132 | mutex_unlock(&indio_dev->mlock); | ||
133 | |||
134 | return 0; | ||
135 | } | ||
136 | EXPORT_SYMBOL(iio_trigger_set_immutable); | ||
137 | |||
122 | /* Search for trigger by name, assuming iio_trigger_list_lock held */ | 138 | /* Search for trigger by name, assuming iio_trigger_list_lock held */ |
123 | static struct iio_trigger *__iio_trigger_find_by_name(const char *name) | 139 | static struct iio_trigger *__iio_trigger_find_by_name(const char *name) |
124 | { | 140 | { |
@@ -255,6 +271,14 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig, | |||
255 | goto out_free_irq; | 271 | goto out_free_irq; |
256 | } | 272 | } |
257 | 273 | ||
274 | /* | ||
275 | * Check if we just registered to our own trigger: we determine that | ||
276 | * this is the case if the IIO device and the trigger device share the | ||
277 | * same parent device. | ||
278 | */ | ||
279 | if (pf->indio_dev->dev.parent == trig->dev.parent) | ||
280 | trig->attached_own_device = true; | ||
281 | |||
258 | return ret; | 282 | return ret; |
259 | 283 | ||
260 | out_free_irq: | 284 | out_free_irq: |
@@ -279,6 +303,8 @@ static int iio_trigger_detach_poll_func(struct iio_trigger *trig, | |||
279 | if (ret) | 303 | if (ret) |
280 | return ret; | 304 | return ret; |
281 | } | 305 | } |
306 | if (pf->indio_dev->dev.parent == trig->dev.parent) | ||
307 | trig->attached_own_device = false; | ||
282 | iio_trigger_put_irq(trig, pf->irq); | 308 | iio_trigger_put_irq(trig, pf->irq); |
283 | free_irq(pf->irq, pf); | 309 | free_irq(pf->irq, pf); |
284 | module_put(pf->indio_dev->info->driver_module); | 310 | module_put(pf->indio_dev->info->driver_module); |
@@ -384,6 +410,10 @@ static ssize_t iio_trigger_write_current(struct device *dev, | |||
384 | mutex_unlock(&indio_dev->mlock); | 410 | mutex_unlock(&indio_dev->mlock); |
385 | return -EBUSY; | 411 | return -EBUSY; |
386 | } | 412 | } |
413 | if (indio_dev->trig_readonly) { | ||
414 | mutex_unlock(&indio_dev->mlock); | ||
415 | return -EPERM; | ||
416 | } | ||
387 | mutex_unlock(&indio_dev->mlock); | 417 | mutex_unlock(&indio_dev->mlock); |
388 | 418 | ||
389 | trig = iio_trigger_find_by_name(buf, len); | 419 | trig = iio_trigger_find_by_name(buf, len); |
@@ -622,6 +652,71 @@ void devm_iio_trigger_free(struct device *dev, struct iio_trigger *iio_trig) | |||
622 | } | 652 | } |
623 | EXPORT_SYMBOL_GPL(devm_iio_trigger_free); | 653 | EXPORT_SYMBOL_GPL(devm_iio_trigger_free); |
624 | 654 | ||
655 | static void devm_iio_trigger_unreg(struct device *dev, void *res) | ||
656 | { | ||
657 | iio_trigger_unregister(*(struct iio_trigger **)res); | ||
658 | } | ||
659 | |||
660 | /** | ||
661 | * devm_iio_trigger_register - Resource-managed iio_trigger_register() | ||
662 | * @dev: device this trigger was allocated for | ||
663 | * @trig_info: trigger to register | ||
664 | * | ||
665 | * Managed iio_trigger_register(). The IIO trigger registered with this | ||
666 | * function is automatically unregistered on driver detach. This function | ||
667 | * calls iio_trigger_register() internally. Refer to that function for more | ||
668 | * information. | ||
669 | * | ||
670 | * If an iio_trigger registered with this function needs to be unregistered | ||
671 | * separately, devm_iio_trigger_unregister() must be used. | ||
672 | * | ||
673 | * RETURNS: | ||
674 | * 0 on success, negative error number on failure. | ||
675 | */ | ||
676 | int devm_iio_trigger_register(struct device *dev, struct iio_trigger *trig_info) | ||
677 | { | ||
678 | struct iio_trigger **ptr; | ||
679 | int ret; | ||
680 | |||
681 | ptr = devres_alloc(devm_iio_trigger_unreg, sizeof(*ptr), GFP_KERNEL); | ||
682 | if (!ptr) | ||
683 | return -ENOMEM; | ||
684 | |||
685 | *ptr = trig_info; | ||
686 | ret = iio_trigger_register(trig_info); | ||
687 | if (!ret) | ||
688 | devres_add(dev, ptr); | ||
689 | else | ||
690 | devres_free(ptr); | ||
691 | |||
692 | return ret; | ||
693 | } | ||
694 | EXPORT_SYMBOL_GPL(devm_iio_trigger_register); | ||
695 | |||
696 | /** | ||
697 | * devm_iio_trigger_unregister - Resource-managed iio_trigger_unregister() | ||
698 | * @dev: device this iio_trigger belongs to | ||
699 | * @trig_info: the trigger associated with the device | ||
700 | * | ||
701 | * Unregister trigger registered with devm_iio_trigger_register(). | ||
702 | */ | ||
703 | void devm_iio_trigger_unregister(struct device *dev, | ||
704 | struct iio_trigger *trig_info) | ||
705 | { | ||
706 | int rc; | ||
707 | |||
708 | rc = devres_release(dev, devm_iio_trigger_unreg, devm_iio_trigger_match, | ||
709 | trig_info); | ||
710 | WARN_ON(rc); | ||
711 | } | ||
712 | EXPORT_SYMBOL_GPL(devm_iio_trigger_unregister); | ||
713 | |||
714 | bool iio_trigger_using_own(struct iio_dev *indio_dev) | ||
715 | { | ||
716 | return indio_dev->trig->attached_own_device; | ||
717 | } | ||
718 | EXPORT_SYMBOL(iio_trigger_using_own); | ||
719 | |||
625 | void iio_device_register_trigger_consumer(struct iio_dev *indio_dev) | 720 | void iio_device_register_trigger_consumer(struct iio_dev *indio_dev) |
626 | { | 721 | { |
627 | indio_dev->groups[indio_dev->groupcounter++] = | 722 | indio_dev->groups[indio_dev->groupcounter++] = |
diff --git a/drivers/iio/magnetometer/ak8974.c b/drivers/iio/magnetometer/ak8974.c index e70e4e22b72c..217353145676 100644 --- a/drivers/iio/magnetometer/ak8974.c +++ b/drivers/iio/magnetometer/ak8974.c | |||
@@ -783,8 +783,7 @@ static int __exit ak8974_remove(struct i2c_client *i2c) | |||
783 | return 0; | 783 | return 0; |
784 | } | 784 | } |
785 | 785 | ||
786 | #ifdef CONFIG_PM | 786 | static int __maybe_unused ak8974_runtime_suspend(struct device *dev) |
787 | static int ak8974_runtime_suspend(struct device *dev) | ||
788 | { | 787 | { |
789 | struct ak8974 *ak8974 = | 788 | struct ak8974 *ak8974 = |
790 | iio_priv(i2c_get_clientdata(to_i2c_client(dev))); | 789 | iio_priv(i2c_get_clientdata(to_i2c_client(dev))); |
@@ -795,7 +794,7 @@ static int ak8974_runtime_suspend(struct device *dev) | |||
795 | return 0; | 794 | return 0; |
796 | } | 795 | } |
797 | 796 | ||
798 | static int ak8974_runtime_resume(struct device *dev) | 797 | static int __maybe_unused ak8974_runtime_resume(struct device *dev) |
799 | { | 798 | { |
800 | struct ak8974 *ak8974 = | 799 | struct ak8974 *ak8974 = |
801 | iio_priv(i2c_get_clientdata(to_i2c_client(dev))); | 800 | iio_priv(i2c_get_clientdata(to_i2c_client(dev))); |
@@ -822,7 +821,6 @@ out_regulator_disable: | |||
822 | 821 | ||
823 | return ret; | 822 | return ret; |
824 | } | 823 | } |
825 | #endif /* CONFIG_PM */ | ||
826 | 824 | ||
827 | static const struct dev_pm_ops ak8974_dev_pm_ops = { | 825 | static const struct dev_pm_ops ak8974_dev_pm_ops = { |
828 | SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, | 826 | SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, |
@@ -847,7 +845,6 @@ MODULE_DEVICE_TABLE(of, ak8974_of_match); | |||
847 | static struct i2c_driver ak8974_driver = { | 845 | static struct i2c_driver ak8974_driver = { |
848 | .driver = { | 846 | .driver = { |
849 | .name = "ak8974", | 847 | .name = "ak8974", |
850 | .owner = THIS_MODULE, | ||
851 | .pm = &ak8974_dev_pm_ops, | 848 | .pm = &ak8974_dev_pm_ops, |
852 | .of_match_table = of_match_ptr(ak8974_of_match), | 849 | .of_match_table = of_match_ptr(ak8974_of_match), |
853 | }, | 850 | }, |
diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c index feb41f82c64a..a74ed1f0c880 100644 --- a/drivers/iio/pressure/ms5611_core.c +++ b/drivers/iio/pressure/ms5611_core.c | |||
@@ -416,8 +416,7 @@ static int ms5611_init(struct iio_dev *indio_dev) | |||
416 | return 0; | 416 | return 0; |
417 | 417 | ||
418 | err_regulator_disable: | 418 | err_regulator_disable: |
419 | if (!IS_ERR_OR_NULL(st->vdd)) | 419 | regulator_disable(st->vdd); |
420 | regulator_disable(st->vdd); | ||
421 | return ret; | 420 | return ret; |
422 | } | 421 | } |
423 | 422 | ||
@@ -425,8 +424,7 @@ static void ms5611_fini(const struct iio_dev *indio_dev) | |||
425 | { | 424 | { |
426 | const struct ms5611_state *st = iio_priv(indio_dev); | 425 | const struct ms5611_state *st = iio_priv(indio_dev); |
427 | 426 | ||
428 | if (!IS_ERR_OR_NULL(st->vdd)) | 427 | regulator_disable(st->vdd); |
429 | regulator_disable(st->vdd); | ||
430 | } | 428 | } |
431 | 429 | ||
432 | int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, | 430 | int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, |
diff --git a/drivers/iio/proximity/sx9500.c b/drivers/iio/proximity/sx9500.c index 6f84f53dfe54..1f06282ec793 100644 --- a/drivers/iio/proximity/sx9500.c +++ b/drivers/iio/proximity/sx9500.c | |||
@@ -1025,6 +1025,12 @@ static const struct acpi_device_id sx9500_acpi_match[] = { | |||
1025 | }; | 1025 | }; |
1026 | MODULE_DEVICE_TABLE(acpi, sx9500_acpi_match); | 1026 | MODULE_DEVICE_TABLE(acpi, sx9500_acpi_match); |
1027 | 1027 | ||
1028 | static const struct of_device_id sx9500_of_match[] = { | ||
1029 | { .compatible = "semtech,sx9500", }, | ||
1030 | { } | ||
1031 | }; | ||
1032 | MODULE_DEVICE_TABLE(of, sx9500_of_match); | ||
1033 | |||
1028 | static const struct i2c_device_id sx9500_id[] = { | 1034 | static const struct i2c_device_id sx9500_id[] = { |
1029 | {"sx9500", 0}, | 1035 | {"sx9500", 0}, |
1030 | { }, | 1036 | { }, |
@@ -1035,6 +1041,7 @@ static struct i2c_driver sx9500_driver = { | |||
1035 | .driver = { | 1041 | .driver = { |
1036 | .name = SX9500_DRIVER_NAME, | 1042 | .name = SX9500_DRIVER_NAME, |
1037 | .acpi_match_table = ACPI_PTR(sx9500_acpi_match), | 1043 | .acpi_match_table = ACPI_PTR(sx9500_acpi_match), |
1044 | .of_match_table = of_match_ptr(sx9500_of_match), | ||
1038 | .pm = &sx9500_pm_ops, | 1045 | .pm = &sx9500_pm_ops, |
1039 | }, | 1046 | }, |
1040 | .probe = sx9500_probe, | 1047 | .probe = sx9500_probe, |
diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c index 030827ec8f3a..39dd2026ccc9 100644 --- a/drivers/iio/temperature/maxim_thermocouple.c +++ b/drivers/iio/temperature/maxim_thermocouple.c | |||
@@ -32,7 +32,7 @@ enum { | |||
32 | MAX31855, | 32 | MAX31855, |
33 | }; | 33 | }; |
34 | 34 | ||
35 | const struct iio_chan_spec max6675_channels[] = { | 35 | static const struct iio_chan_spec max6675_channels[] = { |
36 | { /* thermocouple temperature */ | 36 | { /* thermocouple temperature */ |
37 | .type = IIO_TEMP, | 37 | .type = IIO_TEMP, |
38 | .info_mask_separate = | 38 | .info_mask_separate = |
@@ -49,7 +49,7 @@ const struct iio_chan_spec max6675_channels[] = { | |||
49 | IIO_CHAN_SOFT_TIMESTAMP(1), | 49 | IIO_CHAN_SOFT_TIMESTAMP(1), |
50 | }; | 50 | }; |
51 | 51 | ||
52 | const struct iio_chan_spec max31855_channels[] = { | 52 | static const struct iio_chan_spec max31855_channels[] = { |
53 | { /* thermocouple temperature */ | 53 | { /* thermocouple temperature */ |
54 | .type = IIO_TEMP, | 54 | .type = IIO_TEMP, |
55 | .address = 2, | 55 | .address = 2, |
@@ -95,7 +95,7 @@ struct maxim_thermocouple_chip { | |||
95 | u32 status_bit; | 95 | u32 status_bit; |
96 | }; | 96 | }; |
97 | 97 | ||
98 | const struct maxim_thermocouple_chip maxim_thermocouple_chips[] = { | 98 | static const struct maxim_thermocouple_chip maxim_thermocouple_chips[] = { |
99 | [MAX6675] = { | 99 | [MAX6675] = { |
100 | .channels = max6675_channels, | 100 | .channels = max6675_channels, |
101 | .num_channels = ARRAY_SIZE(max6675_channels), | 101 | .num_channels = ARRAY_SIZE(max6675_channels), |