aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/adc')
-rw-r--r--drivers/iio/adc/ad7266.c21
-rw-r--r--drivers/iio/adc/ad7887.c16
-rw-r--r--drivers/iio/adc/max1363.c8
-rw-r--r--drivers/iio/adc/mcp3422.c9
-rw-r--r--drivers/iio/adc/ti_am335x_adc.c68
-rw-r--r--drivers/iio/adc/viperboard_adc.c20
6 files changed, 82 insertions, 60 deletions
diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
index 58e945594c7b..70f78c3062a7 100644
--- a/drivers/iio/adc/ad7266.c
+++ b/drivers/iio/adc/ad7266.c
@@ -43,19 +43,22 @@ struct ad7266_state {
43 * The buffer needs to be large enough to hold two samples (4 bytes) and 43 * The buffer needs to be large enough to hold two samples (4 bytes) and
44 * the naturally aligned timestamp (8 bytes). 44 * the naturally aligned timestamp (8 bytes).
45 */ 45 */
46 uint8_t data[ALIGN(4, sizeof(s64)) + sizeof(s64)] ____cacheline_aligned; 46 struct {
47 __be16 sample[2];
48 s64 timestamp;
49 } data ____cacheline_aligned;
47}; 50};
48 51
49static int ad7266_wakeup(struct ad7266_state *st) 52static int ad7266_wakeup(struct ad7266_state *st)
50{ 53{
51 /* Any read with >= 2 bytes will wake the device */ 54 /* Any read with >= 2 bytes will wake the device */
52 return spi_read(st->spi, st->data, 2); 55 return spi_read(st->spi, &st->data.sample[0], 2);
53} 56}
54 57
55static int ad7266_powerdown(struct ad7266_state *st) 58static int ad7266_powerdown(struct ad7266_state *st)
56{ 59{
57 /* Any read with < 2 bytes will powerdown the device */ 60 /* Any read with < 2 bytes will powerdown the device */
58 return spi_read(st->spi, st->data, 1); 61 return spi_read(st->spi, &st->data.sample[0], 1);
59} 62}
60 63
61static int ad7266_preenable(struct iio_dev *indio_dev) 64static int ad7266_preenable(struct iio_dev *indio_dev)
@@ -84,9 +87,9 @@ static irqreturn_t ad7266_trigger_handler(int irq, void *p)
84 struct ad7266_state *st = iio_priv(indio_dev); 87 struct ad7266_state *st = iio_priv(indio_dev);
85 int ret; 88 int ret;
86 89
87 ret = spi_read(st->spi, st->data, 4); 90 ret = spi_read(st->spi, st->data.sample, 4);
88 if (ret == 0) { 91 if (ret == 0) {
89 iio_push_to_buffers_with_timestamp(indio_dev, st->data, 92 iio_push_to_buffers_with_timestamp(indio_dev, &st->data,
90 pf->timestamp); 93 pf->timestamp);
91 } 94 }
92 95
@@ -137,7 +140,7 @@ static int ad7266_read_single(struct ad7266_state *st, int *val,
137 ad7266_select_input(st, address); 140 ad7266_select_input(st, address);
138 141
139 ret = spi_sync(st->spi, &st->single_msg); 142 ret = spi_sync(st->spi, &st->single_msg);
140 *val = be16_to_cpu(st->data[address % 2]); 143 *val = be16_to_cpu(st->data.sample[address % 2]);
141 144
142 return ret; 145 return ret;
143} 146}
@@ -442,15 +445,15 @@ static int ad7266_probe(struct spi_device *spi)
442 ad7266_init_channels(indio_dev); 445 ad7266_init_channels(indio_dev);
443 446
444 /* wakeup */ 447 /* wakeup */
445 st->single_xfer[0].rx_buf = &st->data; 448 st->single_xfer[0].rx_buf = &st->data.sample[0];
446 st->single_xfer[0].len = 2; 449 st->single_xfer[0].len = 2;
447 st->single_xfer[0].cs_change = 1; 450 st->single_xfer[0].cs_change = 1;
448 /* conversion */ 451 /* conversion */
449 st->single_xfer[1].rx_buf = &st->data; 452 st->single_xfer[1].rx_buf = st->data.sample;
450 st->single_xfer[1].len = 4; 453 st->single_xfer[1].len = 4;
451 st->single_xfer[1].cs_change = 1; 454 st->single_xfer[1].cs_change = 1;
452 /* powerdown */ 455 /* powerdown */
453 st->single_xfer[2].tx_buf = &st->data; 456 st->single_xfer[2].tx_buf = &st->data.sample[0];
454 st->single_xfer[2].len = 1; 457 st->single_xfer[2].len = 1;
455 458
456 spi_message_init(&st->single_msg); 459 spi_message_init(&st->single_msg);
diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c
index acb7f90359a3..749a6cadab8b 100644
--- a/drivers/iio/adc/ad7887.c
+++ b/drivers/iio/adc/ad7887.c
@@ -200,7 +200,13 @@ static const struct ad7887_chip_info ad7887_chip_info_tbl[] = {
200 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 200 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
201 .address = 1, 201 .address = 1,
202 .scan_index = 1, 202 .scan_index = 1,
203 .scan_type = IIO_ST('u', 12, 16, 0), 203 .scan_type = {
204 .sign = 'u',
205 .realbits = 12,
206 .storagebits = 16,
207 .shift = 0,
208 .endianness = IIO_BE,
209 },
204 }, 210 },
205 .channel[1] = { 211 .channel[1] = {
206 .type = IIO_VOLTAGE, 212 .type = IIO_VOLTAGE,
@@ -210,7 +216,13 @@ static const struct ad7887_chip_info ad7887_chip_info_tbl[] = {
210 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 216 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
211 .address = 0, 217 .address = 0,
212 .scan_index = 0, 218 .scan_index = 0,
213 .scan_type = IIO_ST('u', 12, 16, 0), 219 .scan_type = {
220 .sign = 'u',
221 .realbits = 12,
222 .storagebits = 16,
223 .shift = 0,
224 .endianness = IIO_BE,
225 },
214 }, 226 },
215 .channel[2] = IIO_CHAN_SOFT_TIMESTAMP(2), 227 .channel[2] = IIO_CHAN_SOFT_TIMESTAMP(2),
216 .int_vref_mv = 2500, 228 .int_vref_mv = 2500,
diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index 6118dced02b6..e283f2f2ee2f 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -1039,10 +1039,10 @@ static const struct iio_info max1238_info = {
1039}; 1039};
1040 1040
1041static const struct iio_info max1363_info = { 1041static const struct iio_info max1363_info = {
1042 .read_event_value_new = &max1363_read_thresh, 1042 .read_event_value = &max1363_read_thresh,
1043 .write_event_value_new = &max1363_write_thresh, 1043 .write_event_value = &max1363_write_thresh,
1044 .read_event_config_new = &max1363_read_event_config, 1044 .read_event_config = &max1363_read_event_config,
1045 .write_event_config_new = &max1363_write_event_config, 1045 .write_event_config = &max1363_write_event_config,
1046 .read_raw = &max1363_read_raw, 1046 .read_raw = &max1363_read_raw,
1047 .update_scan_mode = &max1363_update_scan_mode, 1047 .update_scan_mode = &max1363_update_scan_mode,
1048 .driver_module = THIS_MODULE, 1048 .driver_module = THIS_MODULE,
diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c
index c8c1baaec6c1..47dcb34ff44c 100644
--- a/drivers/iio/adc/mcp3422.c
+++ b/drivers/iio/adc/mcp3422.c
@@ -362,7 +362,7 @@ static int mcp3422_probe(struct i2c_client *client,
362 | MCP3422_SAMPLE_RATE_VALUE(MCP3422_SRATE_240)); 362 | MCP3422_SAMPLE_RATE_VALUE(MCP3422_SRATE_240));
363 mcp3422_update_config(adc, config); 363 mcp3422_update_config(adc, config);
364 364
365 err = iio_device_register(indio_dev); 365 err = devm_iio_device_register(&client->dev, indio_dev);
366 if (err < 0) 366 if (err < 0)
367 return err; 367 return err;
368 368
@@ -371,12 +371,6 @@ static int mcp3422_probe(struct i2c_client *client,
371 return 0; 371 return 0;
372} 372}
373 373
374static int mcp3422_remove(struct i2c_client *client)
375{
376 iio_device_unregister(i2c_get_clientdata(client));
377 return 0;
378}
379
380static const struct i2c_device_id mcp3422_id[] = { 374static const struct i2c_device_id mcp3422_id[] = {
381 { "mcp3422", 2 }, 375 { "mcp3422", 2 },
382 { "mcp3423", 3 }, 376 { "mcp3423", 3 },
@@ -400,7 +394,6 @@ static struct i2c_driver mcp3422_driver = {
400 .of_match_table = of_match_ptr(mcp3422_of_match), 394 .of_match_table = of_match_ptr(mcp3422_of_match),
401 }, 395 },
402 .probe = mcp3422_probe, 396 .probe = mcp3422_probe,
403 .remove = mcp3422_remove,
404 .id_table = mcp3422_id, 397 .id_table = mcp3422_id,
405}; 398};
406module_i2c_driver(mcp3422_driver); 399module_i2c_driver(mcp3422_driver);
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index d4d748214e4b..31e786e3999b 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -60,6 +60,24 @@ static u32 get_adc_step_mask(struct tiadc_device *adc_dev)
60 return step_en; 60 return step_en;
61} 61}
62 62
63static u32 get_adc_chan_step_mask(struct tiadc_device *adc_dev,
64 struct iio_chan_spec const *chan)
65{
66 int i;
67
68 for (i = 0; i < ARRAY_SIZE(adc_dev->channel_step); i++) {
69 if (chan->channel == adc_dev->channel_line[i]) {
70 u32 step;
71
72 step = adc_dev->channel_step[i];
73 /* +1 for the charger */
74 return 1 << (step + 1);
75 }
76 }
77 WARN_ON(1);
78 return 0;
79}
80
63static u32 get_adc_step_bit(struct tiadc_device *adc_dev, int chan) 81static u32 get_adc_step_bit(struct tiadc_device *adc_dev, int chan)
64{ 82{
65 return 1 << adc_dev->channel_step[chan]; 83 return 1 << adc_dev->channel_step[chan];
@@ -181,7 +199,7 @@ static int tiadc_buffer_postenable(struct iio_dev *indio_dev)
181 enb |= (get_adc_step_bit(adc_dev, bit) << 1); 199 enb |= (get_adc_step_bit(adc_dev, bit) << 1);
182 adc_dev->buffer_en_ch_steps = enb; 200 adc_dev->buffer_en_ch_steps = enb;
183 201
184 am335x_tsc_se_set(adc_dev->mfd_tscadc, enb); 202 am335x_tsc_se_set_cache(adc_dev->mfd_tscadc, enb);
185 203
186 tiadc_writel(adc_dev, REG_IRQSTATUS, IRQENB_FIFO1THRES 204 tiadc_writel(adc_dev, REG_IRQSTATUS, IRQENB_FIFO1THRES
187 | IRQENB_FIFO1OVRRUN | IRQENB_FIFO1UNDRFLW); 205 | IRQENB_FIFO1OVRRUN | IRQENB_FIFO1UNDRFLW);
@@ -199,6 +217,7 @@ static int tiadc_buffer_predisable(struct iio_dev *indio_dev)
199 tiadc_writel(adc_dev, REG_IRQCLR, (IRQENB_FIFO1THRES | 217 tiadc_writel(adc_dev, REG_IRQCLR, (IRQENB_FIFO1THRES |
200 IRQENB_FIFO1OVRRUN | IRQENB_FIFO1UNDRFLW)); 218 IRQENB_FIFO1OVRRUN | IRQENB_FIFO1UNDRFLW));
201 am335x_tsc_se_clr(adc_dev->mfd_tscadc, adc_dev->buffer_en_ch_steps); 219 am335x_tsc_se_clr(adc_dev->mfd_tscadc, adc_dev->buffer_en_ch_steps);
220 adc_dev->buffer_en_ch_steps = 0;
202 221
203 /* Flush FIFO of leftover data in the time it takes to disable adc */ 222 /* Flush FIFO of leftover data in the time it takes to disable adc */
204 fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); 223 fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
@@ -328,34 +347,43 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
328 unsigned int fifo1count, read, stepid; 347 unsigned int fifo1count, read, stepid;
329 bool found = false; 348 bool found = false;
330 u32 step_en; 349 u32 step_en;
331 unsigned long timeout = jiffies + usecs_to_jiffies 350 unsigned long timeout;
332 (IDLE_TIMEOUT * adc_dev->channels);
333 351
334 if (iio_buffer_enabled(indio_dev)) 352 if (iio_buffer_enabled(indio_dev))
335 return -EBUSY; 353 return -EBUSY;
336 354
337 step_en = get_adc_step_mask(adc_dev); 355 step_en = get_adc_chan_step_mask(adc_dev, chan);
338 am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en); 356 if (!step_en)
357 return -EINVAL;
358
359 fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
360 while (fifo1count--)
361 tiadc_readl(adc_dev, REG_FIFO1);
362
363 am335x_tsc_se_set_once(adc_dev->mfd_tscadc, step_en);
339 364
340 /* Wait for ADC sequencer to complete sampling */ 365 timeout = jiffies + usecs_to_jiffies
341 while (tiadc_readl(adc_dev, REG_ADCFSM) & SEQ_STATUS) { 366 (IDLE_TIMEOUT * adc_dev->channels);
342 if (time_after(jiffies, timeout)) 367 /* Wait for Fifo threshold interrupt */
368 while (1) {
369 fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
370 if (fifo1count)
371 break;
372
373 if (time_after(jiffies, timeout)) {
374 am335x_tsc_se_adc_done(adc_dev->mfd_tscadc);
343 return -EAGAIN; 375 return -EAGAIN;
344 } 376 }
377 }
345 map_val = chan->channel + TOTAL_CHANNELS; 378 map_val = chan->channel + TOTAL_CHANNELS;
346 379
347 /* 380 /*
348 * When the sub-system is first enabled, 381 * We check the complete FIFO. We programmed just one entry but in case
349 * the sequencer will always start with the 382 * something went wrong we left empty handed (-EAGAIN previously) and
350 * lowest step (1) and continue until step (16). 383 * then the value apeared somehow in the FIFO we would have two entries.
351 * For ex: If we have enabled 4 ADC channels and 384 * Therefore we read every item and keep only the latest version of the
352 * currently use only 1 out of them, the 385 * requested channel.
353 * sequencer still configures all the 4 steps,
354 * leading to 3 unwanted data.
355 * Hence we need to flush out this data.
356 */ 386 */
357
358 fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
359 for (i = 0; i < fifo1count; i++) { 387 for (i = 0; i < fifo1count; i++) {
360 read = tiadc_readl(adc_dev, REG_FIFO1); 388 read = tiadc_readl(adc_dev, REG_FIFO1);
361 stepid = read & FIFOREAD_CHNLID_MASK; 389 stepid = read & FIFOREAD_CHNLID_MASK;
@@ -367,6 +395,7 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
367 *val = (u16) read; 395 *val = (u16) read;
368 } 396 }
369 } 397 }
398 am335x_tsc_se_adc_done(adc_dev->mfd_tscadc);
370 399
371 if (found == false) 400 if (found == false)
372 return -EBUSY; 401 return -EBUSY;
@@ -494,7 +523,8 @@ static int tiadc_resume(struct device *dev)
494 tiadc_writel(adc_dev, REG_CTRL, restore); 523 tiadc_writel(adc_dev, REG_CTRL, restore);
495 524
496 tiadc_step_config(indio_dev); 525 tiadc_step_config(indio_dev);
497 526 am335x_tsc_se_set_cache(adc_dev->mfd_tscadc,
527 adc_dev->buffer_en_ch_steps);
498 return 0; 528 return 0;
499} 529}
500 530
diff --git a/drivers/iio/adc/viperboard_adc.c b/drivers/iio/adc/viperboard_adc.c
index 09727a71e9fa..d0add8f9416b 100644
--- a/drivers/iio/adc/viperboard_adc.c
+++ b/drivers/iio/adc/viperboard_adc.c
@@ -42,12 +42,6 @@ struct vprbrd_adc {
42 .indexed = 1, \ 42 .indexed = 1, \
43 .channel = _index, \ 43 .channel = _index, \
44 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 44 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
45 .scan_index = _index, \
46 .scan_type = { \
47 .sign = 'u', \
48 .realbits = 8, \
49 .storagebits = 8, \
50 }, \
51} 45}
52 46
53static struct iio_chan_spec const vprbrd_adc_iio_channels[] = { 47static struct iio_chan_spec const vprbrd_adc_iio_channels[] = {
@@ -73,7 +67,7 @@ static int vprbrd_iio_read_raw(struct iio_dev *iio_dev,
73 mutex_lock(&vb->lock); 67 mutex_lock(&vb->lock);
74 68
75 admsg->cmd = VPRBRD_ADC_CMD_GET; 69 admsg->cmd = VPRBRD_ADC_CMD_GET;
76 admsg->chan = chan->scan_index; 70 admsg->chan = chan->channel;
77 admsg->val = 0x00; 71 admsg->val = 0x00;
78 72
79 ret = usb_control_msg(vb->usb_dev, 73 ret = usb_control_msg(vb->usb_dev,
@@ -139,7 +133,7 @@ static int vprbrd_adc_probe(struct platform_device *pdev)
139 indio_dev->channels = vprbrd_adc_iio_channels; 133 indio_dev->channels = vprbrd_adc_iio_channels;
140 indio_dev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels); 134 indio_dev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels);
141 135
142 ret = iio_device_register(indio_dev); 136 ret = devm_iio_device_register(&pdev->dev, indio_dev);
143 if (ret) { 137 if (ret) {
144 dev_err(&pdev->dev, "could not register iio (adc)"); 138 dev_err(&pdev->dev, "could not register iio (adc)");
145 return ret; 139 return ret;
@@ -150,22 +144,12 @@ static int vprbrd_adc_probe(struct platform_device *pdev)
150 return 0; 144 return 0;
151} 145}
152 146
153static int vprbrd_adc_remove(struct platform_device *pdev)
154{
155 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
156
157 iio_device_unregister(indio_dev);
158
159 return 0;
160}
161
162static struct platform_driver vprbrd_adc_driver = { 147static struct platform_driver vprbrd_adc_driver = {
163 .driver = { 148 .driver = {
164 .name = "viperboard-adc", 149 .name = "viperboard-adc",
165 .owner = THIS_MODULE, 150 .owner = THIS_MODULE,
166 }, 151 },
167 .probe = vprbrd_adc_probe, 152 .probe = vprbrd_adc_probe,
168 .remove = vprbrd_adc_remove,
169}; 153};
170 154
171module_platform_driver(vprbrd_adc_driver); 155module_platform_driver(vprbrd_adc_driver);