Skip to content

Commit 490fba9

Browse files
Michael NosthoffJonathan Cameron
authored andcommitted
iio: ad7793: implement IIO_CHAN_INFO_SAMP_FREQ
This commit is a follow-up to changes made to ad_sigma_delta.h in staging: iio: ad7192: implement IIO_CHAN_INFO_SAMP_FREQ which broke ad7793 as it was not altered to match those changes. This driver predates the availability of IIO_CHAN_INFO_SAMP_FREQ attribute wherein usage has some advantages like it can be accessed by in-kernel consumers as well as reduces the code size. Therefore, use IIO_CHAN_INFO_SAMP_FREQ to implement the sampling_frequency attribute instead of using IIO_DEV_ATTR_SAMP_FREQ() macro. Move code from the functions associated with IIO_DEV_ATTR_SAMP_FREQ() into respective read and write hooks with the mask set to IIO_CHAN_INFO_SAMP_FREQ. Fixes: a13e831 ("staging: iio: ad7192: implement IIO_CHAN_INFO_SAMP_FREQ") Signed-off-by: Michael Nosthoff <committed@heine.so> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 8b43868 commit 490fba9

1 file changed

Lines changed: 24 additions & 51 deletions

File tree

‎drivers/iio/adc/ad7793.c‎

Lines changed: 24 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -348,55 +348,6 @@ static const u16 ad7793_sample_freq_avail[16] = {0, 470, 242, 123, 62, 50, 39,
348348
static const u16 ad7797_sample_freq_avail[16] = {0, 0, 0, 123, 62, 50, 0,
349349
33, 0, 17, 16, 12, 10, 8, 6, 4};
350350

351-
static ssize_t ad7793_read_frequency(struct device *dev,
352-
struct device_attribute *attr,
353-
char *buf)
354-
{
355-
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
356-
struct ad7793_state *st = iio_priv(indio_dev);
357-
358-
return sprintf(buf, "%d\n",
359-
st->chip_info->sample_freq_avail[AD7793_MODE_RATE(st->mode)]);
360-
}
361-
362-
static ssize_t ad7793_write_frequency(struct device *dev,
363-
struct device_attribute *attr,
364-
const char *buf,
365-
size_t len)
366-
{
367-
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
368-
struct ad7793_state *st = iio_priv(indio_dev);
369-
long lval;
370-
int i, ret;
371-
372-
ret = kstrtol(buf, 10, &lval);
373-
if (ret)
374-
return ret;
375-
376-
if (lval == 0)
377-
return -EINVAL;
378-
379-
for (i = 0; i < 16; i++)
380-
if (lval == st->chip_info->sample_freq_avail[i])
381-
break;
382-
if (i == 16)
383-
return -EINVAL;
384-
385-
ret = iio_device_claim_direct_mode(indio_dev);
386-
if (ret)
387-
return ret;
388-
st->mode &= ~AD7793_MODE_RATE(-1);
389-
st->mode |= AD7793_MODE_RATE(i);
390-
ad_sd_write_reg(&st->sd, AD7793_REG_MODE, sizeof(st->mode), st->mode);
391-
iio_device_release_direct_mode(indio_dev);
392-
393-
return len;
394-
}
395-
396-
static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
397-
ad7793_read_frequency,
398-
ad7793_write_frequency);
399-
400351
static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(
401352
"470 242 123 62 50 39 33 19 17 16 12 10 8 6 4");
402353

@@ -424,7 +375,6 @@ static IIO_DEVICE_ATTR_NAMED(in_m_in_scale_available,
424375
ad7793_show_scale_available, NULL, 0);
425376

426377
static struct attribute *ad7793_attributes[] = {
427-
&iio_dev_attr_sampling_frequency.dev_attr.attr,
428378
&iio_const_attr_sampling_frequency_available.dev_attr.attr,
429379
&iio_dev_attr_in_m_in_scale_available.dev_attr.attr,
430380
NULL
@@ -435,7 +385,6 @@ static const struct attribute_group ad7793_attribute_group = {
435385
};
436386

437387
static struct attribute *ad7797_attributes[] = {
438-
&iio_dev_attr_sampling_frequency.dev_attr.attr,
439388
&iio_const_attr_sampling_frequency_available_ad7797.dev_attr.attr,
440389
NULL
441390
};
@@ -505,6 +454,10 @@ static int ad7793_read_raw(struct iio_dev *indio_dev,
505454
*val -= offset;
506455
}
507456
return IIO_VAL_INT;
457+
case IIO_CHAN_INFO_SAMP_FREQ:
458+
*val = st->chip_info
459+
->sample_freq_avail[AD7793_MODE_RATE(st->mode)];
460+
return IIO_VAL_INT;
508461
}
509462
return -EINVAL;
510463
}
@@ -542,6 +495,26 @@ static int ad7793_write_raw(struct iio_dev *indio_dev,
542495
break;
543496
}
544497
break;
498+
case IIO_CHAN_INFO_SAMP_FREQ:
499+
if (!val) {
500+
ret = -EINVAL;
501+
break;
502+
}
503+
504+
for (i = 0; i < 16; i++)
505+
if (val == st->chip_info->sample_freq_avail[i])
506+
break;
507+
508+
if (i == 16) {
509+
ret = -EINVAL;
510+
break;
511+
}
512+
513+
st->mode &= ~AD7793_MODE_RATE(-1);
514+
st->mode |= AD7793_MODE_RATE(i);
515+
ad_sd_write_reg(&st->sd, AD7793_REG_MODE, sizeof(st->mode),
516+
st->mode);
517+
break;
545518
default:
546519
ret = -EINVAL;
547520
}

0 commit comments

Comments
 (0)