aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@cam.ac.uk>2011-02-26 12:27:17 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2011-02-28 20:48:49 -0500
commit03d1b7d3e4debbdbca4a676c749214b39025c8dd (patch)
tree076c0fbd26f1bced7eb14e670634951b9729f7dc
parent35d2b6f9b194ef99ceb6ea565c875af7cea34fa0 (diff)
staging:iio:gyro: add adis16251 support to adis16260 driver
These parts are very similar and the adis16260 driver supports a lot of additional functionality. Precursor to removal of adis16251 driver. Note that some supported devices were missing from Kconfig help text and are also added in this patch. Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk> Acked-by: Michael Hennerich <michael.hennerich@analog.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/staging/iio/gyro/Kconfig4
-rw-r--r--drivers/staging/iio/gyro/adis16260_core.c49
2 files changed, 41 insertions, 12 deletions
diff --git a/drivers/staging/iio/gyro/Kconfig b/drivers/staging/iio/gyro/Kconfig
index 236f15fdbfc..5bba4b05f96 100644
--- a/drivers/staging/iio/gyro/Kconfig
+++ b/drivers/staging/iio/gyro/Kconfig
@@ -25,13 +25,13 @@ config ADIS16130
25 Angular Rate Sensor driver. 25 Angular Rate Sensor driver.
26 26
27config ADIS16260 27config ADIS16260
28 tristate "Analog Devices ADIS16260 ADIS16265 Digital Gyroscope Sensor SPI driver" 28 tristate "Analog Devices ADIS16260 Digital Gyroscope Sensor SPI driver"
29 depends on SPI 29 depends on SPI
30 select IIO_TRIGGER if IIO_RING_BUFFER 30 select IIO_TRIGGER if IIO_RING_BUFFER
31 select IIO_SW_RING if IIO_RING_BUFFER 31 select IIO_SW_RING if IIO_RING_BUFFER
32 help 32 help
33 Say yes here to build support for Analog Devices ADIS16260 ADIS16265 33 Say yes here to build support for Analog Devices ADIS16260 ADIS16265
34 programmable digital gyroscope sensor. 34 ADIS16250 ADIS16255 and ADIS16251 programmable digital gyroscope sensors.
35 35
36 This driver can also be built as a module. If so, the module 36 This driver can also be built as a module. If so, the module
37 will be called adis16260. 37 will be called adis16260.
diff --git a/drivers/staging/iio/gyro/adis16260_core.c b/drivers/staging/iio/gyro/adis16260_core.c
index 045e27da980..69a29ec9310 100644
--- a/drivers/staging/iio/gyro/adis16260_core.c
+++ b/drivers/staging/iio/gyro/adis16260_core.c
@@ -238,10 +238,24 @@ error_ret:
238 return ret ? ret : len; 238 return ret ? ret : len;
239} 239}
240 240
241static ssize_t adis16260_read_frequency_available(struct device *dev,
242 struct device_attribute *attr,
243 char *buf)
244{
245 struct iio_dev *indio_dev = dev_get_drvdata(dev);
246 struct adis16260_state *st = iio_dev_get_devdata(indio_dev);
247 if (spi_get_device_id(st->us)->driver_data)
248 return sprintf(buf, "%s\n", "0.129 ~ 256");
249 else
250 return sprintf(buf, "%s\n", "256 2048");
251}
252
241static ssize_t adis16260_read_frequency(struct device *dev, 253static ssize_t adis16260_read_frequency(struct device *dev,
242 struct device_attribute *attr, 254 struct device_attribute *attr,
243 char *buf) 255 char *buf)
244{ 256{
257 struct iio_dev *indio_dev = dev_get_drvdata(dev);
258 struct adis16260_state *st = iio_dev_get_devdata(indio_dev);
245 int ret, len = 0; 259 int ret, len = 0;
246 u16 t; 260 u16 t;
247 int sps; 261 int sps;
@@ -250,7 +264,11 @@ static ssize_t adis16260_read_frequency(struct device *dev,
250 &t); 264 &t);
251 if (ret) 265 if (ret)
252 return ret; 266 return ret;
253 sps = (t & ADIS16260_SMPL_PRD_TIME_BASE) ? 66 : 2048; 267
268 if (spi_get_device_id(st->us)->driver_data) /* If an adis16251 */
269 sps = (t & ADIS16260_SMPL_PRD_TIME_BASE) ? 8 : 256;
270 else
271 sps = (t & ADIS16260_SMPL_PRD_TIME_BASE) ? 66 : 2048;
254 sps /= (t & ADIS16260_SMPL_PRD_DIV_MASK) + 1; 272 sps /= (t & ADIS16260_SMPL_PRD_DIV_MASK) + 1;
255 len = sprintf(buf, "%d SPS\n", sps); 273 len = sprintf(buf, "%d SPS\n", sps);
256 return len; 274 return len;
@@ -272,16 +290,21 @@ static ssize_t adis16260_write_frequency(struct device *dev,
272 return ret; 290 return ret;
273 291
274 mutex_lock(&indio_dev->mlock); 292 mutex_lock(&indio_dev->mlock);
275 293 if (spi_get_device_id(st->us)) {
276 t = (2048 / val); 294 t = (256 / val);
277 if (t > 0) 295 if (t > 0)
278 t--; 296 t--;
279 t &= ADIS16260_SMPL_PRD_DIV_MASK; 297 t &= ADIS16260_SMPL_PRD_DIV_MASK;
298 } else {
299 t = (2048 / val);
300 if (t > 0)
301 t--;
302 t &= ADIS16260_SMPL_PRD_DIV_MASK;
303 }
280 if ((t & ADIS16260_SMPL_PRD_DIV_MASK) >= 0x0A) 304 if ((t & ADIS16260_SMPL_PRD_DIV_MASK) >= 0x0A)
281 st->us->max_speed_hz = ADIS16260_SPI_SLOW; 305 st->us->max_speed_hz = ADIS16260_SPI_SLOW;
282 else 306 else
283 st->us->max_speed_hz = ADIS16260_SPI_FAST; 307 st->us->max_speed_hz = ADIS16260_SPI_FAST;
284
285 ret = adis16260_spi_write_reg_8(dev, 308 ret = adis16260_spi_write_reg_8(dev,
286 ADIS16260_SMPL_PRD, 309 ADIS16260_SMPL_PRD,
287 t); 310 t);
@@ -302,7 +325,10 @@ static ssize_t adis16260_read_gyro_scale(struct device *dev,
302 if (st->negate) 325 if (st->negate)
303 ret = sprintf(buf, "-"); 326 ret = sprintf(buf, "-");
304 /* Take the iio_dev status lock */ 327 /* Take the iio_dev status lock */
305 ret += sprintf(buf + ret, "%s\n", "0.00127862821"); 328 if (spi_get_device_id(st->us)->driver_data)
329 ret += sprintf(buf + ret, "%s\n", "0.00031974432");
330 else
331 ret += sprintf(buf + ret, "%s\n", "0.00127862821");
306 332
307 return ret; 333 return ret;
308} 334}
@@ -475,7 +501,9 @@ static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
475 501
476static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, adis16260_write_reset, 0); 502static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, adis16260_write_reset, 0);
477 503
478static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("256 2048"); 504
505static IIO_DEVICE_ATTR(sampling_frequency_available,
506 S_IRUGO, adis16260_read_frequency_available, NULL, 0);
479 507
480static IIO_CONST_ATTR_NAME("adis16260"); 508static IIO_CONST_ATTR_NAME("adis16260");
481 509
@@ -525,7 +553,7 @@ static ADIS16260_GYRO_ATTR_SET(_Z);
525 &iio_dev_attr_in1_raw.dev_attr.attr, \ 553 &iio_dev_attr_in1_raw.dev_attr.attr, \
526 &iio_const_attr_in1_scale.dev_attr.attr, \ 554 &iio_const_attr_in1_scale.dev_attr.attr, \
527 &iio_dev_attr_sampling_frequency.dev_attr.attr, \ 555 &iio_dev_attr_sampling_frequency.dev_attr.attr, \
528 &iio_const_attr_sampling_frequency_available.dev_attr.attr, \ 556 &iio_dev_attr_sampling_frequency_available.dev_attr.attr, \
529 &iio_dev_attr_reset.dev_attr.attr, \ 557 &iio_dev_attr_reset.dev_attr.attr, \
530 &iio_const_attr_name.dev_attr.attr, \ 558 &iio_const_attr_name.dev_attr.attr, \
531 NULL \ 559 NULL \
@@ -693,6 +721,7 @@ static const struct spi_device_id adis16260_id[] = {
693 {"adis16265", 0}, 721 {"adis16265", 0},
694 {"adis16250", 0}, 722 {"adis16250", 0},
695 {"adis16255", 0}, 723 {"adis16255", 0},
724 {"adis16251", 1},
696 {} 725 {}
697}; 726};
698 727