]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.48/iio-ad7793-implement-iio_chan_info_samp_freq.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.14.48 / iio-ad7793-implement-iio_chan_info_samp_freq.patch
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
5
6 From: Michael Nosthoff <committed@heine.so>
7
8 commit 490fba90a90eb7b741f57fefd2bcf2c1e11eb471 upstream.
9
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.
13
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.
17
18 Therefore, use IIO_CHAN_INFO_SAMP_FREQ to implement the
19 sampling_frequency attribute instead of using IIO_DEV_ATTR_SAMP_FREQ()
20 macro.
21
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.
25
26 Fixes: a13e831fcaa7 ("staging: iio: ad7192: implement IIO_CHAN_INFO_SAMP_FREQ")
27
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>
32
33 ---
34 drivers/iio/adc/ad7793.c | 75 +++++++++++++++--------------------------------
35 1 file changed, 24 insertions(+), 51 deletions(-)
36
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};
42
43 -static ssize_t ad7793_read_frequency(struct device *dev,
44 - struct device_attribute *attr,
45 - char *buf)
46 -{
47 - struct iio_dev *indio_dev = dev_to_iio_dev(dev);
48 - struct ad7793_state *st = iio_priv(indio_dev);
49 -
50 - return sprintf(buf, "%d\n",
51 - st->chip_info->sample_freq_avail[AD7793_MODE_RATE(st->mode)]);
52 -}
53 -
54 -static ssize_t ad7793_write_frequency(struct device *dev,
55 - struct device_attribute *attr,
56 - const char *buf,
57 - size_t len)
58 -{
59 - struct iio_dev *indio_dev = dev_to_iio_dev(dev);
60 - struct ad7793_state *st = iio_priv(indio_dev);
61 - long lval;
62 - int i, ret;
63 -
64 - ret = kstrtol(buf, 10, &lval);
65 - if (ret)
66 - return ret;
67 -
68 - if (lval == 0)
69 - return -EINVAL;
70 -
71 - for (i = 0; i < 16; i++)
72 - if (lval == st->chip_info->sample_freq_avail[i])
73 - break;
74 - if (i == 16)
75 - return -EINVAL;
76 -
77 - ret = iio_device_claim_direct_mode(indio_dev);
78 - if (ret)
79 - return ret;
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);
84 -
85 - return len;
86 -}
87 -
88 -static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
89 - ad7793_read_frequency,
90 - ad7793_write_frequency);
91 -
92 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(
93 "470 242 123 62 50 39 33 19 17 16 12 10 8 6 4");
94
95 @@ -424,7 +375,6 @@ static IIO_DEVICE_ATTR_NAMED(in_m_in_sca
96 ad7793_show_scale_available, NULL, 0);
97
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,
102 NULL
103 @@ -435,7 +385,6 @@ static const struct attribute_group ad77
104 };
105
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,
109 NULL
110 };
111 @@ -505,6 +454,10 @@ static int ad7793_read_raw(struct iio_de
112 *val -= offset;
113 }
114 return IIO_VAL_INT;
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;
119 }
120 return -EINVAL;
121 }
122 @@ -542,6 +495,26 @@ static int ad7793_write_raw(struct iio_d
123 break;
124 }
125 break;
126 + case IIO_CHAN_INFO_SAMP_FREQ:
127 + if (!val) {
128 + ret = -EINVAL;
129 + break;
130 + }
131 +
132 + for (i = 0; i < 16; i++)
133 + if (val == st->chip_info->sample_freq_avail[i])
134 + break;
135 +
136 + if (i == 16) {
137 + ret = -EINVAL;
138 + break;
139 + }
140 +
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),
144 + st->mode);
145 + break;
146 default:
147 ret = -EINVAL;
148 }