aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
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:49:43 -0400
commita07a97d0493446566b25d4a966b5e4792c1ba8a3 (patch)
treee15a95fc3412f83dae1ff30c5460da7a0aa313a8 /drivers/iio
parent82695ef549b5299d3d9e088d6648289bda8ef3d8 (diff)
iio: imu: adis16400 switch sampling frequency attr to core support.
By using the info_mask_shared_by_all element of the channel spec, access to the sampling frequency becomes available to in kernel users of the driver. It also shortens and simplifies the code. 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')
-rw-r--r--drivers/iio/imu/adis16400_core.c78
1 files changed, 25 insertions, 53 deletions
diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
index 433583b6f800..b70873de04ea 100644
--- a/drivers/iio/imu/adis16400_core.c
+++ b/drivers/iio/imu/adis16400_core.c
@@ -214,21 +214,6 @@ static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq)
214 return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, val); 214 return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, val);
215} 215}
216 216
217static ssize_t adis16400_read_frequency(struct device *dev,
218 struct device_attribute *attr,
219 char *buf)
220{
221 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
222 struct adis16400_state *st = iio_priv(indio_dev);
223 int ret;
224
225 ret = st->variant->get_freq(st);
226 if (ret < 0)
227 return ret;
228
229 return sprintf(buf, "%d.%.3d\n", ret / 1000, ret % 1000);
230}
231
232static const unsigned adis16400_3db_divisors[] = { 217static const unsigned adis16400_3db_divisors[] = {
233 [0] = 2, /* Special case */ 218 [0] = 2, /* Special case */
234 [1] = 6, 219 [1] = 6,
@@ -260,30 +245,6 @@ static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val)
260 return ret; 245 return ret;
261} 246}
262 247
263static ssize_t adis16400_write_frequency(struct device *dev,
264 struct device_attribute *attr, const char *buf, size_t len)
265{
266 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
267 struct adis16400_state *st = iio_priv(indio_dev);
268 int i, f, val;
269 int ret;
270
271 ret = iio_str_to_fixpoint(buf, 100, &i, &f);
272 if (ret)
273 return ret;
274
275 val = i * 1000 + f;
276
277 if (val <= 0)
278 return -EINVAL;
279
280 mutex_lock(&indio_dev->mlock);
281 st->variant->set_freq(st, val);
282 mutex_unlock(&indio_dev->mlock);
283
284 return len;
285}
286
287/* Power down the device */ 248/* Power down the device */
288static int adis16400_stop_device(struct iio_dev *indio_dev) 249static int adis16400_stop_device(struct iio_dev *indio_dev)
289{ 250{
@@ -350,10 +311,6 @@ err_ret:
350 return ret; 311 return ret;
351} 312}
352 313
353static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
354 adis16400_read_frequency,
355 adis16400_write_frequency);
356
357static const uint8_t adis16400_addresses[] = { 314static const uint8_t adis16400_addresses[] = {
358 [ADIS16400_SCAN_GYRO_X] = ADIS16400_XGYRO_OFF, 315 [ADIS16400_SCAN_GYRO_X] = ADIS16400_XGYRO_OFF,
359 [ADIS16400_SCAN_GYRO_Y] = ADIS16400_YGYRO_OFF, 316 [ADIS16400_SCAN_GYRO_Y] = ADIS16400_YGYRO_OFF,
@@ -394,6 +351,16 @@ static int adis16400_write_raw(struct iio_dev *indio_dev,
394 val * 1000 + val2 / 1000); 351 val * 1000 + val2 / 1000);
395 mutex_unlock(&indio_dev->mlock); 352 mutex_unlock(&indio_dev->mlock);
396 return ret; 353 return ret;
354 case IIO_CHAN_INFO_SAMP_FREQ:
355 sps = val * 1000 + val2 / 1000;
356
357 if (sps <= 0)
358 return -EINVAL;
359
360 mutex_lock(&indio_dev->mlock);
361 ret = st->variant->set_freq(st, sps);
362 mutex_unlock(&indio_dev->mlock);
363 return ret;
397 default: 364 default:
398 return -EINVAL; 365 return -EINVAL;
399 } 366 }
@@ -474,6 +441,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
474 if (ret < 0) 441 if (ret < 0)
475 return ret; 442 return ret;
476 return IIO_VAL_INT_PLUS_MICRO; 443 return IIO_VAL_INT_PLUS_MICRO;
444 case IIO_CHAN_INFO_SAMP_FREQ:
445 ret = st->variant->get_freq(st);
446 if (ret < 0)
447 return ret;
448 *val = ret / 1000;
449 *val2 = (ret % 1000) * 1000;
450 return IIO_VAL_INT_PLUS_MICRO;
477 default: 451 default:
478 return -EINVAL; 452 return -EINVAL;
479 } 453 }
@@ -486,6 +460,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
486 .extend_name = name, \ 460 .extend_name = name, \
487 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 461 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
488 BIT(IIO_CHAN_INFO_SCALE), \ 462 BIT(IIO_CHAN_INFO_SCALE), \
463 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
489 .address = (addr), \ 464 .address = (addr), \
490 .scan_index = (si), \ 465 .scan_index = (si), \
491 .scan_type = { \ 466 .scan_type = { \
@@ -511,6 +486,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
511 BIT(IIO_CHAN_INFO_CALIBBIAS), \ 486 BIT(IIO_CHAN_INFO_CALIBBIAS), \
512 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 487 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
513 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ 488 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
489 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
514 .address = addr, \ 490 .address = addr, \
515 .scan_index = ADIS16400_SCAN_GYRO_ ## mod, \ 491 .scan_index = ADIS16400_SCAN_GYRO_ ## mod, \
516 .scan_type = { \ 492 .scan_type = { \
@@ -530,6 +506,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
530 BIT(IIO_CHAN_INFO_CALIBBIAS), \ 506 BIT(IIO_CHAN_INFO_CALIBBIAS), \
531 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 507 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
532 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ 508 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
509 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
533 .address = (addr), \ 510 .address = (addr), \
534 .scan_index = ADIS16400_SCAN_ACC_ ## mod, \ 511 .scan_index = ADIS16400_SCAN_ACC_ ## mod, \
535 .scan_type = { \ 512 .scan_type = { \
@@ -548,6 +525,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
548 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 525 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
549 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 526 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
550 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ 527 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
528 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
551 .address = (addr), \ 529 .address = (addr), \
552 .scan_index = ADIS16400_SCAN_MAGN_ ## mod, \ 530 .scan_index = ADIS16400_SCAN_MAGN_ ## mod, \
553 .scan_type = { \ 531 .scan_type = { \
@@ -573,6 +551,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
573 BIT(IIO_CHAN_INFO_SCALE), \ 551 BIT(IIO_CHAN_INFO_SCALE), \
574 .info_mask_shared_by_type = \ 552 .info_mask_shared_by_type = \
575 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ 553 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
554 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
576 .address = (addr), \ 555 .address = (addr), \
577 .scan_index = ADIS16350_SCAN_TEMP_ ## mod, \ 556 .scan_index = ADIS16350_SCAN_TEMP_ ## mod, \
578 .scan_type = { \ 557 .scan_type = { \
@@ -591,6 +570,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
591 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 570 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
592 BIT(IIO_CHAN_INFO_OFFSET) | \ 571 BIT(IIO_CHAN_INFO_OFFSET) | \
593 BIT(IIO_CHAN_INFO_SCALE), \ 572 BIT(IIO_CHAN_INFO_SCALE), \
573 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
594 .address = (addr), \ 574 .address = (addr), \
595 .scan_index = ADIS16350_SCAN_TEMP_X, \ 575 .scan_index = ADIS16350_SCAN_TEMP_X, \
596 .scan_type = { \ 576 .scan_type = { \
@@ -608,6 +588,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
608 .channel2 = IIO_MOD_ ## mod, \ 588 .channel2 = IIO_MOD_ ## mod, \
609 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 589 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
610 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 590 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
591 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
611 .address = (addr), \ 592 .address = (addr), \
612 .scan_index = ADIS16300_SCAN_INCLI_ ## mod, \ 593 .scan_index = ADIS16300_SCAN_INCLI_ ## mod, \
613 .scan_type = { \ 594 .scan_type = { \
@@ -649,6 +630,7 @@ static const struct iio_chan_spec adis16448_channels[] = {
649 .type = IIO_PRESSURE, 630 .type = IIO_PRESSURE,
650 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 631 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
651 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 632 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
633 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
652 .address = ADIS16448_BARO_OUT, 634 .address = ADIS16448_BARO_OUT,
653 .scan_index = ADIS16400_SCAN_BARO, 635 .scan_index = ADIS16400_SCAN_BARO,
654 .scan_type = { 636 .scan_type = {
@@ -704,15 +686,6 @@ static const struct iio_chan_spec adis16334_channels[] = {
704 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP), 686 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP),
705}; 687};
706 688
707static struct attribute *adis16400_attributes[] = {
708 &iio_dev_attr_sampling_frequency.dev_attr.attr,
709 NULL
710};
711
712static const struct attribute_group adis16400_attribute_group = {
713 .attrs = adis16400_attributes,
714};
715
716static struct adis16400_chip_info adis16400_chips[] = { 689static struct adis16400_chip_info adis16400_chips[] = {
717 [ADIS16300] = { 690 [ADIS16300] = {
718 .channels = adis16300_channels, 691 .channels = adis16300_channels,
@@ -813,7 +786,6 @@ static const struct iio_info adis16400_info = {
813 .driver_module = THIS_MODULE, 786 .driver_module = THIS_MODULE,
814 .read_raw = &adis16400_read_raw, 787 .read_raw = &adis16400_read_raw,
815 .write_raw = &adis16400_write_raw, 788 .write_raw = &adis16400_write_raw,
816 .attrs = &adis16400_attribute_group,
817 .update_scan_mode = adis16400_update_scan_mode, 789 .update_scan_mode = adis16400_update_scan_mode,
818 .debugfs_reg_access = adis_debugfs_reg_access, 790 .debugfs_reg_access = adis_debugfs_reg_access,
819}; 791};