aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/gyro
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@kernel.org>2014-06-22 15:59:00 -0400
committerJonathan Cameron <jic23@kernel.org>2014-07-07 04:44:17 -0400
commit82695ef549b5299d3d9e088d6648289bda8ef3d8 (patch)
treea9f29217a52350fb3000db4f112723e1249a2bec /drivers/iio/gyro
parent95bb8918f9bc87a69cb7a795b568e01afecff9cb (diff)
iio: adis: Switch sampling frequency attr to core support.
By using the info_mask_shared_by_all element of the channel spec, acce to the sampling frequency becomes available to in kernel users of the driver. It also shortens and simplifies the code. This particular conversion was made more complicated by the shared library and the fact that a number of the drivers do not actually have support for setting or reading the sampling frequency. The hardware, in those cases investigated supports it. It's just never been implemented. Signed-off-by: Jonathan Cameron <jic23@kernel.org> Reviewed-by: Hartmut Knaack <knaack.h@gmx.de> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Diffstat (limited to 'drivers/iio/gyro')
-rw-r--r--drivers/iio/gyro/adis16260.c124
1 files changed, 46 insertions, 78 deletions
diff --git a/drivers/iio/gyro/adis16260.c b/drivers/iio/gyro/adis16260.c
index 22b6fb80fa1a..75fe0edd3d0f 100644
--- a/drivers/iio/gyro/adis16260.c
+++ b/drivers/iio/gyro/adis16260.c
@@ -101,65 +101,6 @@
101#define ADIS16260_SCAN_TEMP 3 101#define ADIS16260_SCAN_TEMP 3
102#define ADIS16260_SCAN_ANGL 4 102#define ADIS16260_SCAN_ANGL 4
103 103
104static ssize_t adis16260_read_frequency(struct device *dev,
105 struct device_attribute *attr,
106 char *buf)
107{
108 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
109 struct adis *adis = iio_priv(indio_dev);
110 int ret, len = 0;
111 u16 t;
112 int sps;
113 ret = adis_read_reg_16(adis, ADIS16260_SMPL_PRD, &t);
114 if (ret)
115 return ret;
116
117 if (spi_get_device_id(adis->spi)->driver_data) /* If an adis16251 */
118 sps = (t & ADIS16260_SMPL_PRD_TIME_BASE) ? 8 : 256;
119 else
120 sps = (t & ADIS16260_SMPL_PRD_TIME_BASE) ? 66 : 2048;
121 sps /= (t & ADIS16260_SMPL_PRD_DIV_MASK) + 1;
122 len = sprintf(buf, "%d\n", sps);
123 return len;
124}
125
126static ssize_t adis16260_write_frequency(struct device *dev,
127 struct device_attribute *attr,
128 const char *buf,
129 size_t len)
130{
131 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
132 struct adis *adis = iio_priv(indio_dev);
133 unsigned int val;
134 int ret;
135 u8 t;
136
137 ret = kstrtouint(buf, 10, &val);
138 if (ret)
139 return ret;
140
141 mutex_lock(&indio_dev->mlock);
142 if (spi_get_device_id(adis->spi)->driver_data)
143 t = 256 / val;
144 else
145 t = 2048 / val;
146
147 if (t > ADIS16260_SMPL_PRD_DIV_MASK)
148 t = ADIS16260_SMPL_PRD_DIV_MASK;
149 else if (t > 0)
150 t--;
151
152 if (t >= 0x0A)
153 adis->spi->max_speed_hz = ADIS16260_SPI_SLOW;
154 else
155 adis->spi->max_speed_hz = ADIS16260_SPI_FAST;
156 ret = adis_write_reg_8(adis, ADIS16260_SMPL_PRD, t);
157
158 mutex_unlock(&indio_dev->mlock);
159
160 return ret ? ret : len;
161}
162
163/* Power down the device */ 104/* Power down the device */
164static int adis16260_stop_device(struct iio_dev *indio_dev) 105static int adis16260_stop_device(struct iio_dev *indio_dev)
165{ 106{
@@ -174,18 +115,19 @@ static int adis16260_stop_device(struct iio_dev *indio_dev)
174 return ret; 115 return ret;
175} 116}
176 117
177static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
178 adis16260_read_frequency,
179 adis16260_write_frequency);
180
181static const struct iio_chan_spec adis16260_channels[] = { 118static const struct iio_chan_spec adis16260_channels[] = {
182 ADIS_GYRO_CHAN(X, ADIS16260_GYRO_OUT, ADIS16260_SCAN_GYRO, 119 ADIS_GYRO_CHAN(X, ADIS16260_GYRO_OUT, ADIS16260_SCAN_GYRO,
183 BIT(IIO_CHAN_INFO_CALIBBIAS) | 120 BIT(IIO_CHAN_INFO_CALIBBIAS) |
184 BIT(IIO_CHAN_INFO_CALIBSCALE), 14), 121 BIT(IIO_CHAN_INFO_CALIBSCALE),
185 ADIS_INCLI_CHAN(X, ADIS16260_ANGL_OUT, ADIS16260_SCAN_ANGL, 0, 14), 122 BIT(IIO_CHAN_INFO_SAMP_FREQ), 14),
186 ADIS_TEMP_CHAN(ADIS16260_TEMP_OUT, ADIS16260_SCAN_TEMP, 12), 123 ADIS_INCLI_CHAN(X, ADIS16260_ANGL_OUT, ADIS16260_SCAN_ANGL, 0,
187 ADIS_SUPPLY_CHAN(ADIS16260_SUPPLY_OUT, ADIS16260_SCAN_SUPPLY, 12), 124 BIT(IIO_CHAN_INFO_SAMP_FREQ), 14),
188 ADIS_AUX_ADC_CHAN(ADIS16260_AUX_ADC, ADIS16260_SCAN_AUX_ADC, 12), 125 ADIS_TEMP_CHAN(ADIS16260_TEMP_OUT, ADIS16260_SCAN_TEMP,
126 BIT(IIO_CHAN_INFO_SAMP_FREQ), 12),
127 ADIS_SUPPLY_CHAN(ADIS16260_SUPPLY_OUT, ADIS16260_SCAN_SUPPLY,
128 BIT(IIO_CHAN_INFO_SAMP_FREQ), 12),
129 ADIS_AUX_ADC_CHAN(ADIS16260_AUX_ADC, ADIS16260_SCAN_AUX_ADC,
130 BIT(IIO_CHAN_INFO_SAMP_FREQ), 12),
189 IIO_CHAN_SOFT_TIMESTAMP(5), 131 IIO_CHAN_SOFT_TIMESTAMP(5),
190}; 132};
191 133
@@ -258,6 +200,20 @@ static int adis16260_read_raw(struct iio_dev *indio_dev,
258 200
259 *val = val16; 201 *val = val16;
260 return IIO_VAL_INT; 202 return IIO_VAL_INT;
203 case IIO_CHAN_INFO_SAMP_FREQ:
204 ret = adis_read_reg_16(adis, ADIS16260_SMPL_PRD, &val16);
205 if (ret)
206 return ret;
207
208 if (spi_get_device_id(adis->spi)->driver_data)
209 /* If an adis16251 */
210 *val = (val16 & ADIS16260_SMPL_PRD_TIME_BASE) ?
211 8 : 256;
212 else
213 *val = (val16 & ADIS16260_SMPL_PRD_TIME_BASE) ?
214 66 : 2048;
215 *val /= (val16 & ADIS16260_SMPL_PRD_DIV_MASK) + 1;
216 return IIO_VAL_INT;
261 } 217 }
262 return -EINVAL; 218 return -EINVAL;
263} 219}
@@ -269,7 +225,9 @@ static int adis16260_write_raw(struct iio_dev *indio_dev,
269 long mask) 225 long mask)
270{ 226{
271 struct adis *adis = iio_priv(indio_dev); 227 struct adis *adis = iio_priv(indio_dev);
228 int ret;
272 u8 addr; 229 u8 addr;
230 u8 t;
273 231
274 switch (mask) { 232 switch (mask) {
275 case IIO_CHAN_INFO_CALIBBIAS: 233 case IIO_CHAN_INFO_CALIBBIAS:
@@ -284,21 +242,31 @@ static int adis16260_write_raw(struct iio_dev *indio_dev,
284 242
285 addr = adis16260_addresses[chan->scan_index][1]; 243 addr = adis16260_addresses[chan->scan_index][1];
286 return adis_write_reg_16(adis, addr, val); 244 return adis_write_reg_16(adis, addr, val);
245 case IIO_CHAN_INFO_SAMP_FREQ:
246 mutex_lock(&indio_dev->mlock);
247 if (spi_get_device_id(adis->spi)->driver_data)
248 t = 256 / val;
249 else
250 t = 2048 / val;
251
252 if (t > ADIS16260_SMPL_PRD_DIV_MASK)
253 t = ADIS16260_SMPL_PRD_DIV_MASK;
254 else if (t > 0)
255 t--;
256
257 if (t >= 0x0A)
258 adis->spi->max_speed_hz = ADIS16260_SPI_SLOW;
259 else
260 adis->spi->max_speed_hz = ADIS16260_SPI_FAST;
261 ret = adis_write_reg_8(adis, ADIS16260_SMPL_PRD, t);
262
263 mutex_unlock(&indio_dev->mlock);
264 return ret;
287 } 265 }
288 return -EINVAL; 266 return -EINVAL;
289} 267}
290 268
291static struct attribute *adis16260_attributes[] = {
292 &iio_dev_attr_sampling_frequency.dev_attr.attr,
293 NULL
294};
295
296static const struct attribute_group adis16260_attribute_group = {
297 .attrs = adis16260_attributes,
298};
299
300static const struct iio_info adis16260_info = { 269static const struct iio_info adis16260_info = {
301 .attrs = &adis16260_attribute_group,
302 .read_raw = &adis16260_read_raw, 270 .read_raw = &adis16260_read_raw,
303 .write_raw = &adis16260_write_raw, 271 .write_raw = &adis16260_write_raw,
304 .update_scan_mode = adis_update_scan_mode, 272 .update_scan_mode = adis_update_scan_mode,