17
17
#include <linux/of.h>
18
18
19
19
#include <linux/iio/iio.h>
20
+ #include <linux/iio/buffer.h>
21
+ #include <linux/iio/trigger_consumer.h>
22
+ #include <linux/iio/triggered_buffer.h>
20
23
#include <linux/iio/sysfs.h>
21
24
22
25
#define ADS8688_CMD_REG (x ) (x << 8)
@@ -155,6 +158,13 @@ static const struct attribute_group ads8688_attribute_group = {
155
158
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) \
156
159
| BIT(IIO_CHAN_INFO_SCALE) \
157
160
| BIT(IIO_CHAN_INFO_OFFSET), \
161
+ .scan_index = index, \
162
+ .scan_type = { \
163
+ .sign = 'u', \
164
+ .realbits = 16, \
165
+ .storagebits = 16, \
166
+ .endianness = IIO_BE, \
167
+ }, \
158
168
}
159
169
160
170
static const struct iio_chan_spec ads8684_channels [] = {
@@ -371,6 +381,28 @@ static const struct iio_info ads8688_info = {
371
381
.attrs = & ads8688_attribute_group ,
372
382
};
373
383
384
+ static irqreturn_t ads8688_trigger_handler (int irq , void * p )
385
+ {
386
+ struct iio_poll_func * pf = p ;
387
+ struct iio_dev * indio_dev = pf -> indio_dev ;
388
+ u16 buffer [8 ];
389
+ int i , j = 0 ;
390
+
391
+ for (i = 0 ; i < indio_dev -> masklength ; i ++ ) {
392
+ if (!test_bit (i , indio_dev -> active_scan_mask ))
393
+ continue ;
394
+ buffer [j ] = ads8688_read (indio_dev , i );
395
+ j ++ ;
396
+ }
397
+
398
+ iio_push_to_buffers_with_timestamp (indio_dev , buffer ,
399
+ pf -> timestamp );
400
+
401
+ iio_trigger_notify_done (indio_dev -> trig );
402
+
403
+ return IRQ_HANDLED ;
404
+ }
405
+
374
406
static const struct ads8688_chip_info ads8688_chip_info_tbl [] = {
375
407
[ID_ADS8684 ] = {
376
408
.channels = ads8684_channels ,
@@ -402,7 +434,7 @@ static int ads8688_probe(struct spi_device *spi)
402
434
403
435
ret = regulator_get_voltage (st -> reg );
404
436
if (ret < 0 )
405
- goto error_out ;
437
+ goto err_regulator_disable ;
406
438
407
439
st -> vref_mv = ret / 1000 ;
408
440
} else {
@@ -430,13 +462,22 @@ static int ads8688_probe(struct spi_device *spi)
430
462
431
463
mutex_init (& st -> lock );
432
464
465
+ ret = iio_triggered_buffer_setup (indio_dev , NULL , ads8688_trigger_handler , NULL );
466
+ if (ret < 0 ) {
467
+ dev_err (& spi -> dev , "iio triggered buffer setup failed\n" );
468
+ goto err_regulator_disable ;
469
+ }
470
+
433
471
ret = iio_device_register (indio_dev );
434
472
if (ret )
435
- goto error_out ;
473
+ goto err_buffer_cleanup ;
436
474
437
475
return 0 ;
438
476
439
- error_out :
477
+ err_buffer_cleanup :
478
+ iio_triggered_buffer_cleanup (indio_dev );
479
+
480
+ err_regulator_disable :
440
481
if (!IS_ERR (st -> reg ))
441
482
regulator_disable (st -> reg );
442
483
@@ -449,6 +490,7 @@ static int ads8688_remove(struct spi_device *spi)
449
490
struct ads8688_state * st = iio_priv (indio_dev );
450
491
451
492
iio_device_unregister (indio_dev );
493
+ iio_triggered_buffer_cleanup (indio_dev );
452
494
453
495
if (!IS_ERR (st -> reg ))
454
496
regulator_disable (st -> reg );
0 commit comments