1 From 490fba90a90eb7b741f57fefd2bcf2c1e11eb471 Mon Sep 17 00:00:00 2001
2 From: Michael Nosthoff <committed@heine.so>
3 Date: Fri, 9 Mar 2018 16:13:52 +0100
4 Subject: iio: ad7793: implement IIO_CHAN_INFO_SAMP_FREQ
6 From: Michael Nosthoff <committed@heine.so>
8 commit 490fba90a90eb7b741f57fefd2bcf2c1e11eb471 upstream.
10 This commit is a follow-up to changes made to ad_sigma_delta.h
11 in staging: iio: ad7192: implement IIO_CHAN_INFO_SAMP_FREQ
12 which broke ad7793 as it was not altered to match those changes.
14 This driver predates the availability of IIO_CHAN_INFO_SAMP_FREQ
15 attribute wherein usage has some advantages like it can be accessed by
16 in-kernel consumers as well as reduces the code size.
18 Therefore, use IIO_CHAN_INFO_SAMP_FREQ to implement the
19 sampling_frequency attribute instead of using IIO_DEV_ATTR_SAMP_FREQ()
22 Move code from the functions associated with IIO_DEV_ATTR_SAMP_FREQ()
23 into respective read and write hooks with the mask set to
24 IIO_CHAN_INFO_SAMP_FREQ.
26 Fixes: a13e831fcaa7 ("staging: iio: ad7192: implement IIO_CHAN_INFO_SAMP_FREQ")
28 Signed-off-by: Michael Nosthoff <committed@heine.so>
29 Cc: <Stable@vger.kernel.org>
30 Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
31 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
34 drivers/iio/adc/ad7793.c | 75 +++++++++++++++--------------------------------
35 1 file changed, 24 insertions(+), 51 deletions(-)
37 --- a/drivers/iio/adc/ad7793.c
38 +++ b/drivers/iio/adc/ad7793.c
39 @@ -348,55 +348,6 @@ static const u16 ad7793_sample_freq_avai
40 static const u16 ad7797_sample_freq_avail[16] = {0, 0, 0, 123, 62, 50, 0,
41 33, 0, 17, 16, 12, 10, 8, 6, 4};
43 -static ssize_t ad7793_read_frequency(struct device *dev,
44 - struct device_attribute *attr,
47 - struct iio_dev *indio_dev = dev_to_iio_dev(dev);
48 - struct ad7793_state *st = iio_priv(indio_dev);
50 - return sprintf(buf, "%d\n",
51 - st->chip_info->sample_freq_avail[AD7793_MODE_RATE(st->mode)]);
54 -static ssize_t ad7793_write_frequency(struct device *dev,
55 - struct device_attribute *attr,
59 - struct iio_dev *indio_dev = dev_to_iio_dev(dev);
60 - struct ad7793_state *st = iio_priv(indio_dev);
64 - ret = kstrtol(buf, 10, &lval);
71 - for (i = 0; i < 16; i++)
72 - if (lval == st->chip_info->sample_freq_avail[i])
77 - ret = iio_device_claim_direct_mode(indio_dev);
80 - st->mode &= ~AD7793_MODE_RATE(-1);
81 - st->mode |= AD7793_MODE_RATE(i);
82 - ad_sd_write_reg(&st->sd, AD7793_REG_MODE, sizeof(st->mode), st->mode);
83 - iio_device_release_direct_mode(indio_dev);
88 -static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
89 - ad7793_read_frequency,
90 - ad7793_write_frequency);
92 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(
93 "470 242 123 62 50 39 33 19 17 16 12 10 8 6 4");
95 @@ -424,7 +375,6 @@ static IIO_DEVICE_ATTR_NAMED(in_m_in_sca
96 ad7793_show_scale_available, NULL, 0);
98 static struct attribute *ad7793_attributes[] = {
99 - &iio_dev_attr_sampling_frequency.dev_attr.attr,
100 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
101 &iio_dev_attr_in_m_in_scale_available.dev_attr.attr,
103 @@ -435,7 +385,6 @@ static const struct attribute_group ad77
106 static struct attribute *ad7797_attributes[] = {
107 - &iio_dev_attr_sampling_frequency.dev_attr.attr,
108 &iio_const_attr_sampling_frequency_available_ad7797.dev_attr.attr,
111 @@ -505,6 +454,10 @@ static int ad7793_read_raw(struct iio_de
115 + case IIO_CHAN_INFO_SAMP_FREQ:
116 + *val = st->chip_info
117 + ->sample_freq_avail[AD7793_MODE_RATE(st->mode)];
118 + return IIO_VAL_INT;
122 @@ -542,6 +495,26 @@ static int ad7793_write_raw(struct iio_d
126 + case IIO_CHAN_INFO_SAMP_FREQ:
132 + for (i = 0; i < 16; i++)
133 + if (val == st->chip_info->sample_freq_avail[i])
141 + st->mode &= ~AD7793_MODE_RATE(-1);
142 + st->mode |= AD7793_MODE_RATE(i);
143 + ad_sd_write_reg(&st->sd, AD7793_REG_MODE, sizeof(st->mode),