Skip to content

Commit 5b9e048

Browse files
larsclausenjic23
authored andcommitted
staging:iio:ad799x: Switch to new event config interface
Switch the ad799x driver to the new IIO event config interface as the old one is going to be removed. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent b80a674 commit 5b9e048

1 file changed

Lines changed: 85 additions & 60 deletions

File tree

‎drivers/staging/iio/adc/ad799x_core.c‎

Lines changed: 85 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ static ssize_t ad799x_write_frequency(struct device *dev,
252252
}
253253

254254
static int ad799x_read_event_config(struct iio_dev *indio_dev,
255-
u64 event_code)
255+
const struct iio_chan_spec *chan,
256+
enum iio_event_type type,
257+
enum iio_event_direction dir)
256258
{
257259
return 1;
258260
}
@@ -265,14 +267,16 @@ static const u8 ad799x_threshold_addresses[][2] = {
265267
};
266268

267269
static int ad799x_write_event_value(struct iio_dev *indio_dev,
268-
u64 event_code,
269-
int val)
270+
const struct iio_chan_spec *chan,
271+
enum iio_event_type type,
272+
enum iio_event_direction dir,
273+
enum iio_event_info info,
274+
int val, int val2)
270275
{
271276
int ret;
272277
struct ad799x_state *st = iio_priv(indio_dev);
273-
int direction = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
274-
IIO_EV_DIR_FALLING);
275-
int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
278+
int direction = dir == IIO_EV_DIR_FALLING;
279+
int number = chan->channel;
276280

277281
mutex_lock(&indio_dev->mlock);
278282
ret = ad799x_i2c_write16(st,
@@ -284,14 +288,16 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
284288
}
285289

286290
static int ad799x_read_event_value(struct iio_dev *indio_dev,
287-
u64 event_code,
288-
int *val)
291+
const struct iio_chan_spec *chan,
292+
enum iio_event_type type,
293+
enum iio_event_direction dir,
294+
enum iio_event_info info,
295+
int *val, int *val2)
289296
{
290297
int ret;
291298
struct ad799x_state *st = iio_priv(indio_dev);
292-
int direction = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
293-
IIO_EV_DIR_FALLING);
294-
int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
299+
int direction = dir == IIO_EV_DIR_FALLING;
300+
int number = chan->channel;
295301
u16 valin;
296302

297303
mutex_lock(&indio_dev->mlock);
@@ -303,7 +309,7 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
303309
return ret;
304310
*val = valin;
305311

306-
return 0;
312+
return IIO_VAL_INT;
307313
}
308314

309315
static ssize_t ad799x_read_channel_config(struct device *dev,
@@ -446,74 +452,93 @@ static const struct iio_info ad7991_info = {
446452
static const struct iio_info ad7992_info = {
447453
.read_raw = &ad799x_read_raw,
448454
.event_attrs = &ad7992_event_attrs_group,
449-
.read_event_config = &ad799x_read_event_config,
450-
.read_event_value = &ad799x_read_event_value,
451-
.write_event_value = &ad799x_write_event_value,
455+
.read_event_config_new = &ad799x_read_event_config,
456+
.read_event_value_new = &ad799x_read_event_value,
457+
.write_event_value_new = &ad799x_write_event_value,
452458
.driver_module = THIS_MODULE,
453459
};
454460

455461
static const struct iio_info ad7993_4_7_8_info = {
456462
.read_raw = &ad799x_read_raw,
457463
.event_attrs = &ad7993_4_7_8_event_attrs_group,
458-
.read_event_config = &ad799x_read_event_config,
459-
.read_event_value = &ad799x_read_event_value,
460-
.write_event_value = &ad799x_write_event_value,
464+
.read_event_config_new = &ad799x_read_event_config,
465+
.read_event_value_new = &ad799x_read_event_value,
466+
.write_event_value_new = &ad799x_write_event_value,
461467
.driver_module = THIS_MODULE,
462468
.update_scan_mode = ad7997_8_update_scan_mode,
463469
};
464470

465-
#define AD799X_EV_MASK (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \
466-
IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
471+
static const struct iio_event_spec ad799x_events[] = {
472+
{
473+
.type = IIO_EV_TYPE_THRESH,
474+
.dir = IIO_EV_DIR_RISING,
475+
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
476+
BIT(IIO_EV_INFO_ENABLE),
477+
}, {
478+
.type = IIO_EV_TYPE_THRESH,
479+
.dir = IIO_EV_DIR_FALLING,
480+
.mask_separate = BIT(IIO_EV_INFO_VALUE),
481+
BIT(IIO_EV_INFO_ENABLE),
482+
},
483+
};
467484

468-
#define AD799X_CHANNEL(_index, _realbits, _evmask) { \
485+
#define _AD799X_CHANNEL(_index, _realbits, _ev_spec, _num_ev_spec) { \
469486
.type = IIO_VOLTAGE, \
470487
.indexed = 1, \
471488
.channel = (_index), \
472489
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
473490
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
474491
.scan_index = (_index), \
475492
.scan_type = IIO_ST('u', _realbits, 16, 12 - (_realbits)), \
476-
.event_mask = (_evmask), \
493+
.event_spec = _ev_spec, \
494+
.num_event_specs = _num_ev_spec, \
477495
}
478496

497+
#define AD799X_CHANNEL(_index, _realbits) \
498+
_AD799X_CHANNEL(_index, _realbits, NULL, 0)
499+
500+
#define AD799X_CHANNEL_WITH_EVENTS(_index, _realbits) \
501+
_AD799X_CHANNEL(_index, _realbits, ad799x_events, \
502+
ARRAY_SIZE(ad799x_events))
503+
479504
static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
480505
[ad7991] = {
481506
.channel = {
482-
AD799X_CHANNEL(0, 12, 0),
483-
AD799X_CHANNEL(1, 12, 0),
484-
AD799X_CHANNEL(2, 12, 0),
485-
AD799X_CHANNEL(3, 12, 0),
507+
AD799X_CHANNEL(0, 12),
508+
AD799X_CHANNEL(1, 12),
509+
AD799X_CHANNEL(2, 12),
510+
AD799X_CHANNEL(3, 12),
486511
IIO_CHAN_SOFT_TIMESTAMP(4),
487512
},
488513
.num_channels = 5,
489514
.info = &ad7991_info,
490515
},
491516
[ad7995] = {
492517
.channel = {
493-
AD799X_CHANNEL(0, 10, 0),
494-
AD799X_CHANNEL(1, 10, 0),
495-
AD799X_CHANNEL(2, 10, 0),
496-
AD799X_CHANNEL(3, 10, 0),
518+
AD799X_CHANNEL(0, 10),
519+
AD799X_CHANNEL(1, 10),
520+
AD799X_CHANNEL(2, 10),
521+
AD799X_CHANNEL(3, 10),
497522
IIO_CHAN_SOFT_TIMESTAMP(4),
498523
},
499524
.num_channels = 5,
500525
.info = &ad7991_info,
501526
},
502527
[ad7999] = {
503528
.channel = {
504-
AD799X_CHANNEL(0, 8, 0),
505-
AD799X_CHANNEL(1, 8, 0),
506-
AD799X_CHANNEL(2, 8, 0),
507-
AD799X_CHANNEL(3, 8, 0),
529+
AD799X_CHANNEL(0, 8),
530+
AD799X_CHANNEL(1, 8),
531+
AD799X_CHANNEL(2, 8),
532+
AD799X_CHANNEL(3, 8),
508533
IIO_CHAN_SOFT_TIMESTAMP(4),
509534
},
510535
.num_channels = 5,
511536
.info = &ad7991_info,
512537
},
513538
[ad7992] = {
514539
.channel = {
515-
AD799X_CHANNEL(0, 12, AD799X_EV_MASK),
516-
AD799X_CHANNEL(1, 12, AD799X_EV_MASK),
540+
AD799X_CHANNEL_WITH_EVENTS(0, 12),
541+
AD799X_CHANNEL_WITH_EVENTS(1, 12),
517542
IIO_CHAN_SOFT_TIMESTAMP(3),
518543
},
519544
.num_channels = 3,
@@ -522,10 +547,10 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
522547
},
523548
[ad7993] = {
524549
.channel = {
525-
AD799X_CHANNEL(0, 10, AD799X_EV_MASK),
526-
AD799X_CHANNEL(1, 10, AD799X_EV_MASK),
527-
AD799X_CHANNEL(2, 10, AD799X_EV_MASK),
528-
AD799X_CHANNEL(3, 10, AD799X_EV_MASK),
550+
AD799X_CHANNEL_WITH_EVENTS(0, 10),
551+
AD799X_CHANNEL_WITH_EVENTS(1, 10),
552+
AD799X_CHANNEL_WITH_EVENTS(2, 10),
553+
AD799X_CHANNEL_WITH_EVENTS(3, 10),
529554
IIO_CHAN_SOFT_TIMESTAMP(4),
530555
},
531556
.num_channels = 5,
@@ -534,10 +559,10 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
534559
},
535560
[ad7994] = {
536561
.channel = {
537-
AD799X_CHANNEL(0, 12, AD799X_EV_MASK),
538-
AD799X_CHANNEL(1, 12, AD799X_EV_MASK),
539-
AD799X_CHANNEL(2, 12, AD799X_EV_MASK),
540-
AD799X_CHANNEL(3, 12, AD799X_EV_MASK),
562+
AD799X_CHANNEL_WITH_EVENTS(0, 12),
563+
AD799X_CHANNEL_WITH_EVENTS(1, 12),
564+
AD799X_CHANNEL_WITH_EVENTS(2, 12),
565+
AD799X_CHANNEL_WITH_EVENTS(3, 12),
541566
IIO_CHAN_SOFT_TIMESTAMP(4),
542567
},
543568
.num_channels = 5,
@@ -546,14 +571,14 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
546571
},
547572
[ad7997] = {
548573
.channel = {
549-
AD799X_CHANNEL(0, 10, AD799X_EV_MASK),
550-
AD799X_CHANNEL(1, 10, AD799X_EV_MASK),
551-
AD799X_CHANNEL(2, 10, AD799X_EV_MASK),
552-
AD799X_CHANNEL(3, 10, AD799X_EV_MASK),
553-
AD799X_CHANNEL(4, 10, 0),
554-
AD799X_CHANNEL(5, 10, 0),
555-
AD799X_CHANNEL(6, 10, 0),
556-
AD799X_CHANNEL(7, 10, 0),
574+
AD799X_CHANNEL_WITH_EVENTS(0, 10),
575+
AD799X_CHANNEL_WITH_EVENTS(1, 10),
576+
AD799X_CHANNEL_WITH_EVENTS(2, 10),
577+
AD799X_CHANNEL_WITH_EVENTS(3, 10),
578+
AD799X_CHANNEL(4, 10),
579+
AD799X_CHANNEL(5, 10),
580+
AD799X_CHANNEL(6, 10),
581+
AD799X_CHANNEL(7, 10),
557582
IIO_CHAN_SOFT_TIMESTAMP(8),
558583
},
559584
.num_channels = 9,
@@ -562,14 +587,14 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
562587
},
563588
[ad7998] = {
564589
.channel = {
565-
AD799X_CHANNEL(0, 12, AD799X_EV_MASK),
566-
AD799X_CHANNEL(1, 12, AD799X_EV_MASK),
567-
AD799X_CHANNEL(2, 12, AD799X_EV_MASK),
568-
AD799X_CHANNEL(3, 12, AD799X_EV_MASK),
569-
AD799X_CHANNEL(4, 12, 0),
570-
AD799X_CHANNEL(5, 12, 0),
571-
AD799X_CHANNEL(6, 12, 0),
572-
AD799X_CHANNEL(7, 12, 0),
590+
AD799X_CHANNEL_WITH_EVENTS(0, 12),
591+
AD799X_CHANNEL_WITH_EVENTS(1, 12),
592+
AD799X_CHANNEL_WITH_EVENTS(2, 12),
593+
AD799X_CHANNEL_WITH_EVENTS(3, 12),
594+
AD799X_CHANNEL(4, 12),
595+
AD799X_CHANNEL(5, 12),
596+
AD799X_CHANNEL(6, 12),
597+
AD799X_CHANNEL(7, 12),
573598
IIO_CHAN_SOFT_TIMESTAMP(8),
574599
},
575600
.num_channels = 9,

0 commit comments

Comments
 (0)