aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/adc')
-rw-r--r--drivers/iio/adc/Kconfig6
-rw-r--r--drivers/iio/adc/ad799x.c2
-rw-r--r--drivers/iio/adc/at91_adc.c8
-rw-r--r--drivers/iio/adc/mcp3422.c6
-rw-r--r--drivers/iio/adc/mxs-lradc.c37
-rw-r--r--drivers/iio/adc/ti-adc081c.c118
-rw-r--r--drivers/iio/adc/vf610_adc.c24
7 files changed, 146 insertions, 55 deletions
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 5937030f0444..25378c5882e2 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -385,11 +385,11 @@ config ROCKCHIP_SARADC
385 module will be called rockchip_saradc. 385 module will be called rockchip_saradc.
386 386
387config TI_ADC081C 387config TI_ADC081C
388 tristate "Texas Instruments ADC081C021/027" 388 tristate "Texas Instruments ADC081C/ADC101C/ADC121C family"
389 depends on I2C 389 depends on I2C
390 help 390 help
391 If you say yes here you get support for Texas Instruments ADC081C021 391 If you say yes here you get support for Texas Instruments ADC081C,
392 and ADC081C027 ADC chips. 392 ADC101C and ADC121C ADC chips.
393 393
394 This driver can also be built as a module. If so, the module will be 394 This driver can also be built as a module. If so, the module will be
395 called ti-adc081c. 395 called ti-adc081c.
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 01d71588d752..a3f5254f4e51 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -477,7 +477,7 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
477 if (ret < 0) 477 if (ret < 0)
478 return ret; 478 return ret;
479 *val = (ret >> chan->scan_type.shift) & 479 *val = (ret >> chan->scan_type.shift) &
480 GENMASK(chan->scan_type.realbits - 1 , 0); 480 GENMASK(chan->scan_type.realbits - 1, 0);
481 481
482 return IIO_VAL_INT; 482 return IIO_VAL_INT;
483} 483}
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index f284cd6a93d6..52430ba171f3 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -797,8 +797,8 @@ static u32 calc_startup_ticks_9x5(u32 startup_time, u32 adc_clk_khz)
797 * Startup Time = <lookup_table_value> / ADC Clock 797 * Startup Time = <lookup_table_value> / ADC Clock
798 */ 798 */
799 const int startup_lookup[] = { 799 const int startup_lookup[] = {
800 0 , 8 , 16 , 24 , 800 0, 8, 16, 24,
801 64 , 80 , 96 , 112, 801 64, 80, 96, 112,
802 512, 576, 640, 704, 802 512, 576, 640, 704,
803 768, 832, 896, 960 803 768, 832, 896, 960
804 }; 804 };
@@ -924,14 +924,14 @@ static int at91_adc_probe_dt(struct at91_adc_state *st,
924 ret = -EINVAL; 924 ret = -EINVAL;
925 goto error_ret; 925 goto error_ret;
926 } 926 }
927 trig->name = name; 927 trig->name = name;
928 928
929 if (of_property_read_u32(trig_node, "trigger-value", &prop)) { 929 if (of_property_read_u32(trig_node, "trigger-value", &prop)) {
930 dev_err(&idev->dev, "Missing trigger-value property in the DT.\n"); 930 dev_err(&idev->dev, "Missing trigger-value property in the DT.\n");
931 ret = -EINVAL; 931 ret = -EINVAL;
932 goto error_ret; 932 goto error_ret;
933 } 933 }
934 trig->value = prop; 934 trig->value = prop;
935 trig->is_external = of_property_read_bool(trig_node, "trigger-external"); 935 trig->is_external = of_property_read_bool(trig_node, "trigger-external");
936 i++; 936 i++;
937 } 937 }
diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c
index d7b36efd2f3c..d1172dc1e8e2 100644
--- a/drivers/iio/adc/mcp3422.c
+++ b/drivers/iio/adc/mcp3422.c
@@ -61,9 +61,9 @@
61 61
62static const int mcp3422_scales[4][4] = { 62static const int mcp3422_scales[4][4] = {
63 { 1000000, 500000, 250000, 125000 }, 63 { 1000000, 500000, 250000, 125000 },
64 { 250000 , 125000, 62500 , 31250 }, 64 { 250000, 125000, 62500, 31250 },
65 { 62500 , 31250 , 15625 , 7812 }, 65 { 62500, 31250, 15625, 7812 },
66 { 15625 , 7812 , 3906 , 1953 } }; 66 { 15625, 7812, 3906, 1953 } };
67 67
68/* Constant msleep times for data acquisitions */ 68/* Constant msleep times for data acquisitions */
69static const int mcp3422_read_times[4] = { 69static const int mcp3422_read_times[4] = {
diff --git a/drivers/iio/adc/mxs-lradc.c b/drivers/iio/adc/mxs-lradc.c
index 33051b87aac2..ad26da1edbee 100644
--- a/drivers/iio/adc/mxs-lradc.c
+++ b/drivers/iio/adc/mxs-lradc.c
@@ -686,6 +686,17 @@ static void mxs_lradc_prepare_pressure(struct mxs_lradc *lradc)
686 686
687static void mxs_lradc_enable_touch_detection(struct mxs_lradc *lradc) 687static void mxs_lradc_enable_touch_detection(struct mxs_lradc *lradc)
688{ 688{
689 /* Configure the touchscreen type */
690 if (lradc->soc == IMX28_LRADC) {
691 mxs_lradc_reg_clear(lradc, LRADC_CTRL0_MX28_TOUCH_SCREEN_TYPE,
692 LRADC_CTRL0);
693
694 if (lradc->use_touchscreen == MXS_LRADC_TOUCHSCREEN_5WIRE)
695 mxs_lradc_reg_set(lradc,
696 LRADC_CTRL0_MX28_TOUCH_SCREEN_TYPE,
697 LRADC_CTRL0);
698 }
699
689 mxs_lradc_setup_touch_detection(lradc); 700 mxs_lradc_setup_touch_detection(lradc);
690 701
691 lradc->cur_plate = LRADC_TOUCH; 702 lradc->cur_plate = LRADC_TOUCH;
@@ -1127,6 +1138,7 @@ static int mxs_lradc_ts_register(struct mxs_lradc *lradc)
1127 __set_bit(EV_ABS, input->evbit); 1138 __set_bit(EV_ABS, input->evbit);
1128 __set_bit(EV_KEY, input->evbit); 1139 __set_bit(EV_KEY, input->evbit);
1129 __set_bit(BTN_TOUCH, input->keybit); 1140 __set_bit(BTN_TOUCH, input->keybit);
1141 __set_bit(INPUT_PROP_DIRECT, input->propbit);
1130 input_set_abs_params(input, ABS_X, 0, LRADC_SINGLE_SAMPLE_MASK, 0, 0); 1142 input_set_abs_params(input, ABS_X, 0, LRADC_SINGLE_SAMPLE_MASK, 0, 0);
1131 input_set_abs_params(input, ABS_Y, 0, LRADC_SINGLE_SAMPLE_MASK, 0, 0); 1143 input_set_abs_params(input, ABS_Y, 0, LRADC_SINGLE_SAMPLE_MASK, 0, 0);
1132 input_set_abs_params(input, ABS_PRESSURE, 0, LRADC_SINGLE_SAMPLE_MASK, 1144 input_set_abs_params(input, ABS_PRESSURE, 0, LRADC_SINGLE_SAMPLE_MASK,
@@ -1475,18 +1487,13 @@ static const struct iio_chan_spec mx28_lradc_chan_spec[] = {
1475 MXS_ADC_CHAN(15, IIO_VOLTAGE, "VDD5V"), 1487 MXS_ADC_CHAN(15, IIO_VOLTAGE, "VDD5V"),
1476}; 1488};
1477 1489
1478static int mxs_lradc_hw_init(struct mxs_lradc *lradc) 1490static void mxs_lradc_hw_init(struct mxs_lradc *lradc)
1479{ 1491{
1480 /* The ADC always uses DELAY CHANNEL 0. */ 1492 /* The ADC always uses DELAY CHANNEL 0. */
1481 const u32 adc_cfg = 1493 const u32 adc_cfg =
1482 (1 << (LRADC_DELAY_TRIGGER_DELAYS_OFFSET + 0)) | 1494 (1 << (LRADC_DELAY_TRIGGER_DELAYS_OFFSET + 0)) |
1483 (LRADC_DELAY_TIMER_PER << LRADC_DELAY_DELAY_OFFSET); 1495 (LRADC_DELAY_TIMER_PER << LRADC_DELAY_DELAY_OFFSET);
1484 1496
1485 int ret = stmp_reset_block(lradc->base);
1486
1487 if (ret)
1488 return ret;
1489
1490 /* Configure DELAY CHANNEL 0 for generic ADC sampling. */ 1497 /* Configure DELAY CHANNEL 0 for generic ADC sampling. */
1491 mxs_lradc_reg_wrt(lradc, adc_cfg, LRADC_DELAY(0)); 1498 mxs_lradc_reg_wrt(lradc, adc_cfg, LRADC_DELAY(0));
1492 1499
@@ -1495,20 +1502,8 @@ static int mxs_lradc_hw_init(struct mxs_lradc *lradc)
1495 mxs_lradc_reg_wrt(lradc, 0, LRADC_DELAY(2)); 1502 mxs_lradc_reg_wrt(lradc, 0, LRADC_DELAY(2));
1496 mxs_lradc_reg_wrt(lradc, 0, LRADC_DELAY(3)); 1503 mxs_lradc_reg_wrt(lradc, 0, LRADC_DELAY(3));
1497 1504
1498 /* Configure the touchscreen type */
1499 if (lradc->soc == IMX28_LRADC) {
1500 mxs_lradc_reg_clear(lradc, LRADC_CTRL0_MX28_TOUCH_SCREEN_TYPE,
1501 LRADC_CTRL0);
1502
1503 if (lradc->use_touchscreen == MXS_LRADC_TOUCHSCREEN_5WIRE)
1504 mxs_lradc_reg_set(lradc, LRADC_CTRL0_MX28_TOUCH_SCREEN_TYPE,
1505 LRADC_CTRL0);
1506 }
1507
1508 /* Start internal temperature sensing. */ 1505 /* Start internal temperature sensing. */
1509 mxs_lradc_reg_wrt(lradc, 0, LRADC_CTRL2); 1506 mxs_lradc_reg_wrt(lradc, 0, LRADC_CTRL2);
1510
1511 return 0;
1512} 1507}
1513 1508
1514static void mxs_lradc_hw_stop(struct mxs_lradc *lradc) 1509static void mxs_lradc_hw_stop(struct mxs_lradc *lradc)
@@ -1708,11 +1703,13 @@ static int mxs_lradc_probe(struct platform_device *pdev)
1708 } 1703 }
1709 } 1704 }
1710 1705
1711 /* Configure the hardware. */ 1706 ret = stmp_reset_block(lradc->base);
1712 ret = mxs_lradc_hw_init(lradc);
1713 if (ret) 1707 if (ret)
1714 goto err_dev; 1708 goto err_dev;
1715 1709
1710 /* Configure the hardware. */
1711 mxs_lradc_hw_init(lradc);
1712
1716 /* Register the touchscreen input device. */ 1713 /* Register the touchscreen input device. */
1717 if (touch_ret == 0) { 1714 if (touch_ret == 0) {
1718 ret = mxs_lradc_ts_register(lradc); 1715 ret = mxs_lradc_ts_register(lradc);
diff --git a/drivers/iio/adc/ti-adc081c.c b/drivers/iio/adc/ti-adc081c.c
index ecbc12138d58..9fd032d9f402 100644
--- a/drivers/iio/adc/ti-adc081c.c
+++ b/drivers/iio/adc/ti-adc081c.c
@@ -1,9 +1,21 @@
1/* 1/*
2 * TI ADC081C/ADC101C/ADC121C 8/10/12-bit ADC driver
3 *
2 * Copyright (C) 2012 Avionic Design GmbH 4 * Copyright (C) 2012 Avionic Design GmbH
5 * Copyright (C) 2016 Intel
3 * 6 *
4 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 *
11 * Datasheets:
12 * http://www.ti.com/lit/ds/symlink/adc081c021.pdf
13 * http://www.ti.com/lit/ds/symlink/adc101c021.pdf
14 * http://www.ti.com/lit/ds/symlink/adc121c021.pdf
15 *
16 * The devices have a very similar interface and differ mostly in the number of
17 * bits handled. For the 8-bit and 10-bit models the least-significant 4 or 2
18 * bits of value registers are reserved.
7 */ 19 */
8 20
9#include <linux/err.h> 21#include <linux/err.h>
@@ -12,11 +24,17 @@
12#include <linux/of.h> 24#include <linux/of.h>
13 25
14#include <linux/iio/iio.h> 26#include <linux/iio/iio.h>
27#include <linux/iio/buffer.h>
28#include <linux/iio/trigger_consumer.h>
29#include <linux/iio/triggered_buffer.h>
15#include <linux/regulator/consumer.h> 30#include <linux/regulator/consumer.h>
16 31
17struct adc081c { 32struct adc081c {
18 struct i2c_client *i2c; 33 struct i2c_client *i2c;
19 struct regulator *ref; 34 struct regulator *ref;
35
36 /* 8, 10 or 12 */
37 int bits;
20}; 38};
21 39
22#define REG_CONV_RES 0x00 40#define REG_CONV_RES 0x00
@@ -34,7 +52,7 @@ static int adc081c_read_raw(struct iio_dev *iio,
34 if (err < 0) 52 if (err < 0)
35 return err; 53 return err;
36 54
37 *value = (err >> 4) & 0xff; 55 *value = (err & 0xFFF) >> (12 - adc->bits);
38 return IIO_VAL_INT; 56 return IIO_VAL_INT;
39 57
40 case IIO_CHAN_INFO_SCALE: 58 case IIO_CHAN_INFO_SCALE:
@@ -43,7 +61,7 @@ static int adc081c_read_raw(struct iio_dev *iio,
43 return err; 61 return err;
44 62
45 *value = err / 1000; 63 *value = err / 1000;
46 *shift = 8; 64 *shift = adc->bits;
47 65
48 return IIO_VAL_FRACTIONAL_LOG2; 66 return IIO_VAL_FRACTIONAL_LOG2;
49 67
@@ -54,10 +72,53 @@ static int adc081c_read_raw(struct iio_dev *iio,
54 return -EINVAL; 72 return -EINVAL;
55} 73}
56 74
57static const struct iio_chan_spec adc081c_channel = { 75#define ADCxx1C_CHAN(_bits) { \
58 .type = IIO_VOLTAGE, 76 .type = IIO_VOLTAGE, \
59 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 77 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
60 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 78 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
79 .scan_type = { \
80 .sign = 'u', \
81 .realbits = (_bits), \
82 .storagebits = 16, \
83 .shift = 12 - (_bits), \
84 .endianness = IIO_CPU, \
85 }, \
86}
87
88#define DEFINE_ADCxx1C_CHANNELS(_name, _bits) \
89 static const struct iio_chan_spec _name ## _channels[] = { \
90 ADCxx1C_CHAN((_bits)), \
91 IIO_CHAN_SOFT_TIMESTAMP(1), \
92 }; \
93
94#define ADC081C_NUM_CHANNELS 2
95
96struct adcxx1c_model {
97 const struct iio_chan_spec* channels;
98 int bits;
99};
100
101#define ADCxx1C_MODEL(_name, _bits) \
102 { \
103 .channels = _name ## _channels, \
104 .bits = (_bits), \
105 }
106
107DEFINE_ADCxx1C_CHANNELS(adc081c, 8);
108DEFINE_ADCxx1C_CHANNELS(adc101c, 10);
109DEFINE_ADCxx1C_CHANNELS(adc121c, 12);
110
111/* Model ids are indexes in _models array */
112enum adcxx1c_model_id {
113 ADC081C = 0,
114 ADC101C = 1,
115 ADC121C = 2,
116};
117
118static struct adcxx1c_model adcxx1c_models[] = {
119 ADCxx1C_MODEL(adc081c, 8),
120 ADCxx1C_MODEL(adc101c, 10),
121 ADCxx1C_MODEL(adc121c, 12),
61}; 122};
62 123
63static const struct iio_info adc081c_info = { 124static const struct iio_info adc081c_info = {
@@ -65,11 +126,30 @@ static const struct iio_info adc081c_info = {
65 .driver_module = THIS_MODULE, 126 .driver_module = THIS_MODULE,
66}; 127};
67 128
129static irqreturn_t adc081c_trigger_handler(int irq, void *p)
130{
131 struct iio_poll_func *pf = p;
132 struct iio_dev *indio_dev = pf->indio_dev;
133 struct adc081c *data = iio_priv(indio_dev);
134 u16 buf[8]; /* 2 bytes data + 6 bytes padding + 8 bytes timestamp */
135 int ret;
136
137 ret = i2c_smbus_read_word_swapped(data->i2c, REG_CONV_RES);
138 if (ret < 0)
139 goto out;
140 buf[0] = ret;
141 iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
142out:
143 iio_trigger_notify_done(indio_dev->trig);
144 return IRQ_HANDLED;
145}
146
68static int adc081c_probe(struct i2c_client *client, 147static int adc081c_probe(struct i2c_client *client,
69 const struct i2c_device_id *id) 148 const struct i2c_device_id *id)
70{ 149{
71 struct iio_dev *iio; 150 struct iio_dev *iio;
72 struct adc081c *adc; 151 struct adc081c *adc;
152 struct adcxx1c_model *model = &adcxx1c_models[id->driver_data];
73 int err; 153 int err;
74 154
75 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 155 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))
@@ -81,6 +161,7 @@ static int adc081c_probe(struct i2c_client *client,
81 161
82 adc = iio_priv(iio); 162 adc = iio_priv(iio);
83 adc->i2c = client; 163 adc->i2c = client;
164 adc->bits = model->bits;
84 165
85 adc->ref = devm_regulator_get(&client->dev, "vref"); 166 adc->ref = devm_regulator_get(&client->dev, "vref");
86 if (IS_ERR(adc->ref)) 167 if (IS_ERR(adc->ref))
@@ -95,18 +176,26 @@ static int adc081c_probe(struct i2c_client *client,
95 iio->modes = INDIO_DIRECT_MODE; 176 iio->modes = INDIO_DIRECT_MODE;
96 iio->info = &adc081c_info; 177 iio->info = &adc081c_info;
97 178
98 iio->channels = &adc081c_channel; 179 iio->channels = model->channels;
99 iio->num_channels = 1; 180 iio->num_channels = ADC081C_NUM_CHANNELS;
181
182 err = iio_triggered_buffer_setup(iio, NULL, adc081c_trigger_handler, NULL);
183 if (err < 0) {
184 dev_err(&client->dev, "iio triggered buffer setup failed\n");
185 goto err_regulator_disable;
186 }
100 187
101 err = iio_device_register(iio); 188 err = iio_device_register(iio);
102 if (err < 0) 189 if (err < 0)
103 goto regulator_disable; 190 goto err_buffer_cleanup;
104 191
105 i2c_set_clientdata(client, iio); 192 i2c_set_clientdata(client, iio);
106 193
107 return 0; 194 return 0;
108 195
109regulator_disable: 196err_buffer_cleanup:
197 iio_triggered_buffer_cleanup(iio);
198err_regulator_disable:
110 regulator_disable(adc->ref); 199 regulator_disable(adc->ref);
111 200
112 return err; 201 return err;
@@ -118,13 +207,16 @@ static int adc081c_remove(struct i2c_client *client)
118 struct adc081c *adc = iio_priv(iio); 207 struct adc081c *adc = iio_priv(iio);
119 208
120 iio_device_unregister(iio); 209 iio_device_unregister(iio);
210 iio_triggered_buffer_cleanup(iio);
121 regulator_disable(adc->ref); 211 regulator_disable(adc->ref);
122 212
123 return 0; 213 return 0;
124} 214}
125 215
126static const struct i2c_device_id adc081c_id[] = { 216static const struct i2c_device_id adc081c_id[] = {
127 { "adc081c", 0 }, 217 { "adc081c", ADC081C },
218 { "adc101c", ADC101C },
219 { "adc121c", ADC121C },
128 { } 220 { }
129}; 221};
130MODULE_DEVICE_TABLE(i2c, adc081c_id); 222MODULE_DEVICE_TABLE(i2c, adc081c_id);
@@ -132,6 +224,8 @@ MODULE_DEVICE_TABLE(i2c, adc081c_id);
132#ifdef CONFIG_OF 224#ifdef CONFIG_OF
133static const struct of_device_id adc081c_of_match[] = { 225static const struct of_device_id adc081c_of_match[] = {
134 { .compatible = "ti,adc081c" }, 226 { .compatible = "ti,adc081c" },
227 { .compatible = "ti,adc101c" },
228 { .compatible = "ti,adc121c" },
135 { } 229 { }
136}; 230};
137MODULE_DEVICE_TABLE(of, adc081c_of_match); 231MODULE_DEVICE_TABLE(of, adc081c_of_match);
@@ -149,5 +243,5 @@ static struct i2c_driver adc081c_driver = {
149module_i2c_driver(adc081c_driver); 243module_i2c_driver(adc081c_driver);
150 244
151MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>"); 245MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
152MODULE_DESCRIPTION("Texas Instruments ADC081C021/027 driver"); 246MODULE_DESCRIPTION("Texas Instruments ADC081C/ADC101C/ADC121C driver");
153MODULE_LICENSE("GPL v2"); 247MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c
index b10f629cc44b..653bf1379d2e 100644
--- a/drivers/iio/adc/vf610_adc.c
+++ b/drivers/iio/adc/vf610_adc.c
@@ -714,19 +714,19 @@ static int vf610_write_raw(struct iio_dev *indio_dev,
714 int i; 714 int i;
715 715
716 switch (mask) { 716 switch (mask) {
717 case IIO_CHAN_INFO_SAMP_FREQ: 717 case IIO_CHAN_INFO_SAMP_FREQ:
718 for (i = 0; 718 for (i = 0;
719 i < ARRAY_SIZE(info->sample_freq_avail); 719 i < ARRAY_SIZE(info->sample_freq_avail);
720 i++) 720 i++)
721 if (val == info->sample_freq_avail[i]) { 721 if (val == info->sample_freq_avail[i]) {
722 info->adc_feature.sample_rate = i; 722 info->adc_feature.sample_rate = i;
723 vf610_adc_sample_set(info); 723 vf610_adc_sample_set(info);
724 return 0; 724 return 0;
725 } 725 }
726 break; 726 break;
727 727
728 default: 728 default:
729 break; 729 break;
730 } 730 }
731 731
732 return -EINVAL; 732 return -EINVAL;