Skip to content

Commit b80a674

Browse files
larsclausenjic23
authored andcommitted
staging:iio:ad7291: Switch to new event config interface
Switch the ad7291 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 129c3f6 commit b80a674

1 file changed

Lines changed: 59 additions & 37 deletions

File tree

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

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,14 @@ static struct attribute *ad7291_event_attributes[] = {
248248
NULL,
249249
};
250250

251-
static unsigned int ad7291_threshold_reg(u64 event_code)
251+
static unsigned int ad7291_threshold_reg(const struct iio_chan_spec *chan,
252+
enum iio_event_direction dir)
252253
{
253254
unsigned int offset;
254255

255-
switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
256+
switch (chan->type) {
256257
case IIO_VOLTAGE:
257-
offset = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
258+
offset = chan->channel;
258259
break;
259260
case IIO_TEMP:
260261
offset = 8;
@@ -263,43 +264,49 @@ static unsigned int ad7291_threshold_reg(u64 event_code)
263264
return 0;
264265
}
265266

266-
if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING)
267+
if (dir == IIO_EV_DIR_FALLING)
267268
return AD7291_DATA_LOW(offset);
268269
else
269270
return AD7291_DATA_HIGH(offset);
270271
}
271272

272273
static int ad7291_read_event_value(struct iio_dev *indio_dev,
273-
u64 event_code,
274-
int *val)
274+
const struct iio_chan_spec *chan,
275+
enum iio_event_type type,
276+
enum iio_event_direction dir,
277+
enum iio_event_info info,
278+
int *val, int *val2)
275279
{
276280
struct ad7291_chip_info *chip = iio_priv(indio_dev);
277281
int ret;
278282
u16 uval;
279283

280-
ret = ad7291_i2c_read(chip, ad7291_threshold_reg(event_code), &uval);
284+
ret = ad7291_i2c_read(chip, ad7291_threshold_reg(chan, dir), &uval);
281285
if (ret < 0)
282286
return ret;
283287

284-
switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
288+
switch (chan->type) {
285289
case IIO_VOLTAGE:
286290
*val = uval & AD7291_VALUE_MASK;
287-
return 0;
291+
return IIO_VAL_INT;
288292
case IIO_TEMP:
289293
*val = sign_extend32(uval, 11);
290-
return 0;
294+
return IIO_VAL_INT;
291295
default:
292296
return -EINVAL;
293297
};
294298
}
295299

296300
static int ad7291_write_event_value(struct iio_dev *indio_dev,
297-
u64 event_code,
298-
int val)
301+
const struct iio_chan_spec *chan,
302+
enum iio_event_type type,
303+
enum iio_event_direction dir,
304+
enum iio_event_info info,
305+
int val, int val2)
299306
{
300307
struct ad7291_chip_info *chip = iio_priv(indio_dev);
301308

302-
switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
309+
switch (chan->type) {
303310
case IIO_VOLTAGE:
304311
if (val > AD7291_VALUE_MASK || val < 0)
305312
return -EINVAL;
@@ -312,20 +319,21 @@ static int ad7291_write_event_value(struct iio_dev *indio_dev,
312319
return -EINVAL;
313320
}
314321

315-
return ad7291_i2c_write(chip, ad7291_threshold_reg(event_code), val);
322+
return ad7291_i2c_write(chip, ad7291_threshold_reg(chan, dir), val);
316323
}
317324

318325
static int ad7291_read_event_config(struct iio_dev *indio_dev,
319-
u64 event_code)
326+
const struct iio_chan_spec *chan,
327+
enum iio_event_type type,
328+
enum iio_event_direction dir)
320329
{
321330
struct ad7291_chip_info *chip = iio_priv(indio_dev);
322331
/* To be enabled the channel must simply be on. If any are enabled
323332
we are in continuous sampling mode */
324333

325-
switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
334+
switch (chan->type) {
326335
case IIO_VOLTAGE:
327-
if (chip->c_mask &
328-
(1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN(event_code))))
336+
if (chip->c_mask & (1 << (15 - chan->channel)))
329337
return 1;
330338
else
331339
return 0;
@@ -339,11 +347,14 @@ static int ad7291_read_event_config(struct iio_dev *indio_dev,
339347
}
340348

341349
static int ad7291_write_event_config(struct iio_dev *indio_dev,
342-
u64 event_code,
350+
const struct iio_chan_spec *chan,
351+
enum iio_event_type type,
352+
enum iio_event_direction dir,
343353
int state)
344354
{
345355
int ret = 0;
346356
struct ad7291_chip_info *chip = iio_priv(indio_dev);
357+
unsigned int mask;
347358
u16 regval;
348359

349360
mutex_lock(&chip->state_lock);
@@ -354,16 +365,14 @@ static int ad7291_write_event_config(struct iio_dev *indio_dev,
354365
* Possible to disable temp as well but that makes single read tricky.
355366
*/
356367

357-
switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
368+
mask = BIT(15 - chan->channel);
369+
370+
switch (chan->type) {
358371
case IIO_VOLTAGE:
359-
if ((!state) && (chip->c_mask & (1 << (15 -
360-
IIO_EVENT_CODE_EXTRACT_CHAN(event_code)))))
361-
chip->c_mask &= ~(1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN
362-
(event_code)));
363-
else if (state && (!(chip->c_mask & (1 << (15 -
364-
IIO_EVENT_CODE_EXTRACT_CHAN(event_code))))))
365-
chip->c_mask |= (1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN
366-
(event_code)));
372+
if ((!state) && (chip->c_mask & mask))
373+
chip->c_mask &= ~mask;
374+
else if (state && (!(chip->c_mask & mask)))
375+
chip->c_mask |= mask;
367376
else
368377
break;
369378

@@ -473,15 +482,29 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
473482
}
474483
}
475484

485+
static const struct iio_event_spec ad7291_events[] = {
486+
{
487+
.type = IIO_EV_TYPE_THRESH,
488+
.dir = IIO_EV_DIR_RISING,
489+
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
490+
BIT(IIO_EV_INFO_ENABLE),
491+
}, {
492+
.type = IIO_EV_TYPE_THRESH,
493+
.dir = IIO_EV_DIR_FALLING,
494+
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
495+
BIT(IIO_EV_INFO_ENABLE),
496+
},
497+
};
498+
476499
#define AD7291_VOLTAGE_CHAN(_chan) \
477500
{ \
478501
.type = IIO_VOLTAGE, \
479502
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
480503
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
481504
.indexed = 1, \
482505
.channel = _chan, \
483-
.event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)|\
484-
IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) \
506+
.event_spec = ad7291_events, \
507+
.num_event_specs = ARRAY_SIZE(ad7291_events), \
485508
}
486509

487510
static const struct iio_chan_spec ad7291_channels[] = {
@@ -500,9 +523,8 @@ static const struct iio_chan_spec ad7291_channels[] = {
500523
BIT(IIO_CHAN_INFO_SCALE),
501524
.indexed = 1,
502525
.channel = 0,
503-
.event_mask =
504-
IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)|
505-
IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)
526+
.event_spec = ad7291_events,
527+
.num_event_specs = ARRAY_SIZE(ad7291_events),
506528
}
507529
};
508530

@@ -512,10 +534,10 @@ static struct attribute_group ad7291_event_attribute_group = {
512534

513535
static const struct iio_info ad7291_info = {
514536
.read_raw = &ad7291_read_raw,
515-
.read_event_config = &ad7291_read_event_config,
516-
.write_event_config = &ad7291_write_event_config,
517-
.read_event_value = &ad7291_read_event_value,
518-
.write_event_value = &ad7291_write_event_value,
537+
.read_event_config_new = &ad7291_read_event_config,
538+
.write_event_config_new = &ad7291_write_event_config,
539+
.read_event_value_new = &ad7291_read_event_value,
540+
.write_event_value_new = &ad7291_write_event_value,
519541
.event_attrs = &ad7291_event_attribute_group,
520542
.driver_module = THIS_MODULE,
521543
};

0 commit comments

Comments
 (0)