aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2012-11-21 11:27:00 -0500
committerJonathan Cameron <jic23@kernel.org>2012-11-30 07:57:09 -0500
commitfd1a8b9128410c2ea7da69180788e5d144c6ef46 (patch)
tree9d67c4fa79c7cddb955562e4a282dccf71cfa215 /drivers/iio/adc
parent2edb769d246e6b549ba1c5e9b283bfd058584cbb (diff)
iio:ad7793: Add support for the ad7796 and ad7797
The ad7796 and ad7797 are similar to the ad7792 and ad7793 but only have a single differential input instead of two. Also some other features are missing like the programmable gain amplifier and also not all sampling frequencies supported by the ad7792/ad7793 are supported by the ad7796/ad7797. This patch adds new feature flags for the features not present in the ad7796/ad7797. The patch also adds a struct iio_info field to the chip_info struct, this becomes necessary since the ad7796/ad7797 needs a special set of sysfs attributes. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/adc')
-rw-r--r--drivers/iio/adc/ad7793.c121
1 files changed, 109 insertions, 12 deletions
diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
index 91a5f7aa1ef1..334e31ff7a4e 100644
--- a/drivers/iio/adc/ad7793.c
+++ b/drivers/iio/adc/ad7793.c
@@ -106,6 +106,8 @@
106#define AD7793_ID 0xB 106#define AD7793_ID 0xB
107#define AD7794_ID 0xF 107#define AD7794_ID 0xF
108#define AD7795_ID 0xF 108#define AD7795_ID 0xF
109#define AD7796_ID 0xA
110#define AD7797_ID 0xB
109#define AD7798_ID 0x8 111#define AD7798_ID 0x8
110#define AD7799_ID 0x9 112#define AD7799_ID 0x9
111#define AD7793_ID_MASK 0xF 113#define AD7793_ID_MASK 0xF
@@ -136,12 +138,17 @@
136#define AD7793_FLAG_HAS_REFSEL BIT(1) 138#define AD7793_FLAG_HAS_REFSEL BIT(1)
137#define AD7793_FLAG_HAS_VBIAS BIT(2) 139#define AD7793_FLAG_HAS_VBIAS BIT(2)
138#define AD7793_HAS_EXITATION_CURRENT BIT(3) 140#define AD7793_HAS_EXITATION_CURRENT BIT(3)
141#define AD7793_FLAG_HAS_GAIN BIT(4)
142#define AD7793_FLAG_HAS_BUFFER BIT(5)
139 143
140struct ad7793_chip_info { 144struct ad7793_chip_info {
141 unsigned int id; 145 unsigned int id;
142 const struct iio_chan_spec *channels; 146 const struct iio_chan_spec *channels;
143 unsigned int num_channels; 147 unsigned int num_channels;
144 unsigned int flags; 148 unsigned int flags;
149
150 const struct iio_info *iio_info;
151 const u16 *sample_freq_avail;
145}; 152};
146 153
147struct ad7793_state { 154struct ad7793_state {
@@ -162,6 +169,8 @@ enum ad7793_supported_device_ids {
162 ID_AD7793, 169 ID_AD7793,
163 ID_AD7794, 170 ID_AD7794,
164 ID_AD7795, 171 ID_AD7795,
172 ID_AD7796,
173 ID_AD7797,
165 ID_AD7798, 174 ID_AD7798,
166 ID_AD7799, 175 ID_AD7799,
167}; 176};
@@ -283,7 +292,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
283 st->conf |= AD7793_CONF_REFSEL(pdata->refsel); 292 st->conf |= AD7793_CONF_REFSEL(pdata->refsel);
284 if (st->chip_info->flags & AD7793_FLAG_HAS_VBIAS) 293 if (st->chip_info->flags & AD7793_FLAG_HAS_VBIAS)
285 st->conf |= AD7793_CONF_VBIAS(pdata->bias_voltage); 294 st->conf |= AD7793_CONF_VBIAS(pdata->bias_voltage);
286 if (pdata->buffered) 295 if (pdata->buffered || !(st->chip_info->flags & AD7793_FLAG_HAS_BUFFER))
287 st->conf |= AD7793_CONF_BUF; 296 st->conf |= AD7793_CONF_BUF;
288 if (pdata->boost_enable && 297 if (pdata->boost_enable &&
289 (st->chip_info->flags & AD7793_FLAG_HAS_VBIAS)) 298 (st->chip_info->flags & AD7793_FLAG_HAS_VBIAS))
@@ -293,6 +302,9 @@ static int ad7793_setup(struct iio_dev *indio_dev,
293 if (pdata->unipolar) 302 if (pdata->unipolar)
294 st->conf |= AD7793_CONF_UNIPOLAR; 303 st->conf |= AD7793_CONF_UNIPOLAR;
295 304
305 if (!(st->chip_info->flags & AD7793_FLAG_HAS_GAIN))
306 st->conf |= AD7793_CONF_GAIN(7);
307
296 ret = ad7793_set_mode(&st->sd, AD_SD_MODE_IDLE); 308 ret = ad7793_set_mode(&st->sd, AD_SD_MODE_IDLE);
297 if (ret) 309 if (ret)
298 goto out; 310 goto out;
@@ -330,8 +342,11 @@ out:
330 return ret; 342 return ret;
331} 343}
332 344
333static const u16 sample_freq_avail[16] = {0, 470, 242, 123, 62, 50, 39, 33, 19, 345static const u16 ad7793_sample_freq_avail[16] = {0, 470, 242, 123, 62, 50, 39,
334 17, 16, 12, 10, 8, 6, 4}; 346 33, 19, 17, 16, 12, 10, 8, 6, 4};
347
348static const u16 ad7797_sample_freq_avail[16] = {0, 0, 0, 123, 62, 50, 0,
349 33, 0, 17, 16, 12, 10, 8, 6, 4};
335 350
336static ssize_t ad7793_read_frequency(struct device *dev, 351static ssize_t ad7793_read_frequency(struct device *dev,
337 struct device_attribute *attr, 352 struct device_attribute *attr,
@@ -341,7 +356,7 @@ static ssize_t ad7793_read_frequency(struct device *dev,
341 struct ad7793_state *st = iio_priv(indio_dev); 356 struct ad7793_state *st = iio_priv(indio_dev);
342 357
343 return sprintf(buf, "%d\n", 358 return sprintf(buf, "%d\n",
344 sample_freq_avail[AD7793_MODE_RATE(st->mode)]); 359 st->chip_info->sample_freq_avail[AD7793_MODE_RATE(st->mode)]);
345} 360}
346 361
347static ssize_t ad7793_write_frequency(struct device *dev, 362static ssize_t ad7793_write_frequency(struct device *dev,
@@ -365,10 +380,13 @@ static ssize_t ad7793_write_frequency(struct device *dev,
365 if (ret) 380 if (ret)
366 return ret; 381 return ret;
367 382
383 if (lval == 0)
384 return -EINVAL;
385
368 ret = -EINVAL; 386 ret = -EINVAL;
369 387
370 for (i = 0; i < ARRAY_SIZE(sample_freq_avail); i++) 388 for (i = 0; i < 16; i++)
371 if (lval == sample_freq_avail[i]) { 389 if (lval == st->chip_info->sample_freq_avail[i]) {
372 mutex_lock(&indio_dev->mlock); 390 mutex_lock(&indio_dev->mlock);
373 st->mode &= ~AD7793_MODE_RATE(-1); 391 st->mode &= ~AD7793_MODE_RATE(-1);
374 st->mode |= AD7793_MODE_RATE(i); 392 st->mode |= AD7793_MODE_RATE(i);
@@ -388,6 +406,9 @@ static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
388static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( 406static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(
389 "470 242 123 62 50 39 33 19 17 16 12 10 8 6 4"); 407 "470 242 123 62 50 39 33 19 17 16 12 10 8 6 4");
390 408
409static IIO_CONST_ATTR_NAMED(sampling_frequency_available_ad7797,
410 sampling_frequency_available, "123 62 50 33 17 16 12 10 8 6 4");
411
391static ssize_t ad7793_show_scale_available(struct device *dev, 412static ssize_t ad7793_show_scale_available(struct device *dev,
392 struct device_attribute *attr, char *buf) 413 struct device_attribute *attr, char *buf)
393{ 414{
@@ -419,6 +440,16 @@ static const struct attribute_group ad7793_attribute_group = {
419 .attrs = ad7793_attributes, 440 .attrs = ad7793_attributes,
420}; 441};
421 442
443static struct attribute *ad7797_attributes[] = {
444 &iio_dev_attr_sampling_frequency.dev_attr.attr,
445 &iio_const_attr_sampling_frequency_available_ad7797.dev_attr.attr,
446 NULL
447};
448
449static const struct attribute_group ad7797_attribute_group = {
450 .attrs = ad7797_attributes,
451};
452
422static int ad7793_read_raw(struct iio_dev *indio_dev, 453static int ad7793_read_raw(struct iio_dev *indio_dev,
423 struct iio_chan_spec const *chan, 454 struct iio_chan_spec const *chan,
424 int *val, 455 int *val,
@@ -544,6 +575,15 @@ static const struct iio_info ad7793_info = {
544 .driver_module = THIS_MODULE, 575 .driver_module = THIS_MODULE,
545}; 576};
546 577
578static const struct iio_info ad7797_info = {
579 .read_raw = &ad7793_read_raw,
580 .write_raw = &ad7793_write_raw,
581 .write_raw_get_fmt = &ad7793_write_raw_get_fmt,
582 .attrs = &ad7793_attribute_group,
583 .validate_trigger = ad_sd_validate_trigger,
584 .driver_module = THIS_MODULE,
585};
586
547#define DECLARE_AD7793_CHANNELS(_name, _b, _sb, _s) \ 587#define DECLARE_AD7793_CHANNELS(_name, _b, _sb, _s) \
548const struct iio_chan_spec _name##_channels[] = { \ 588const struct iio_chan_spec _name##_channels[] = { \
549 AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), (_s)), \ 589 AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), (_s)), \
@@ -569,6 +609,15 @@ const struct iio_chan_spec _name##_channels[] = { \
569 IIO_CHAN_SOFT_TIMESTAMP(9), \ 609 IIO_CHAN_SOFT_TIMESTAMP(9), \
570} 610}
571 611
612#define DECLARE_AD7797_CHANNELS(_name, _b, _sb) \
613const struct iio_chan_spec _name##_channels[] = { \
614 AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \
615 AD_SD_SHORTED_CHANNEL(1, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), 0), \
616 AD_SD_TEMP_CHANNEL(2, AD7793_CH_TEMP, (_b), (_sb), 0), \
617 AD_SD_SUPPLY_CHANNEL(3, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \
618 IIO_CHAN_SOFT_TIMESTAMP(4), \
619}
620
572#define DECLARE_AD7799_CHANNELS(_name, _b, _sb) \ 621#define DECLARE_AD7799_CHANNELS(_name, _b, _sb) \
573const struct iio_chan_spec _name##_channels[] = { \ 622const struct iio_chan_spec _name##_channels[] = { \
574 AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \ 623 AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \
@@ -584,6 +633,8 @@ static DECLARE_AD7793_CHANNELS(ad7792, 16, 32, 0);
584static DECLARE_AD7793_CHANNELS(ad7793, 24, 32, 0); 633static DECLARE_AD7793_CHANNELS(ad7793, 24, 32, 0);
585static DECLARE_AD7795_CHANNELS(ad7794, 16, 32); 634static DECLARE_AD7795_CHANNELS(ad7794, 16, 32);
586static DECLARE_AD7795_CHANNELS(ad7795, 24, 32); 635static DECLARE_AD7795_CHANNELS(ad7795, 24, 32);
636static DECLARE_AD7797_CHANNELS(ad7796, 16, 16);
637static DECLARE_AD7797_CHANNELS(ad7797, 24, 32);
587static DECLARE_AD7799_CHANNELS(ad7798, 16, 16); 638static DECLARE_AD7799_CHANNELS(ad7798, 16, 16);
588static DECLARE_AD7799_CHANNELS(ad7799, 24, 32); 639static DECLARE_AD7799_CHANNELS(ad7799, 24, 32);
589 640
@@ -592,56 +643,100 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
592 .id = AD7785_ID, 643 .id = AD7785_ID,
593 .channels = ad7785_channels, 644 .channels = ad7785_channels,
594 .num_channels = ARRAY_SIZE(ad7785_channels), 645 .num_channels = ARRAY_SIZE(ad7785_channels),
646 .iio_info = &ad7793_info,
647 .sample_freq_avail = ad7793_sample_freq_avail,
595 .flags = AD7793_FLAG_HAS_CLKSEL | 648 .flags = AD7793_FLAG_HAS_CLKSEL |
596 AD7793_FLAG_HAS_REFSEL | 649 AD7793_FLAG_HAS_REFSEL |
597 AD7793_FLAG_HAS_VBIAS | 650 AD7793_FLAG_HAS_VBIAS |
598 AD7793_HAS_EXITATION_CURRENT, 651 AD7793_HAS_EXITATION_CURRENT |
652 AD7793_FLAG_HAS_GAIN |
653 AD7793_FLAG_HAS_BUFFER,
599 }, 654 },
600 [ID_AD7792] = { 655 [ID_AD7792] = {
601 .id = AD7792_ID, 656 .id = AD7792_ID,
602 .channels = ad7792_channels, 657 .channels = ad7792_channels,
603 .num_channels = ARRAY_SIZE(ad7792_channels), 658 .num_channels = ARRAY_SIZE(ad7792_channels),
659 .iio_info = &ad7793_info,
660 .sample_freq_avail = ad7793_sample_freq_avail,
604 .flags = AD7793_FLAG_HAS_CLKSEL | 661 .flags = AD7793_FLAG_HAS_CLKSEL |
605 AD7793_FLAG_HAS_REFSEL | 662 AD7793_FLAG_HAS_REFSEL |
606 AD7793_FLAG_HAS_VBIAS | 663 AD7793_FLAG_HAS_VBIAS |
607 AD7793_HAS_EXITATION_CURRENT, 664 AD7793_HAS_EXITATION_CURRENT |
665 AD7793_FLAG_HAS_GAIN |
666 AD7793_FLAG_HAS_BUFFER,
608 }, 667 },
609 [ID_AD7793] = { 668 [ID_AD7793] = {
610 .id = AD7793_ID, 669 .id = AD7793_ID,
611 .channels = ad7793_channels, 670 .channels = ad7793_channels,
612 .num_channels = ARRAY_SIZE(ad7793_channels), 671 .num_channels = ARRAY_SIZE(ad7793_channels),
672 .iio_info = &ad7793_info,
673 .sample_freq_avail = ad7793_sample_freq_avail,
613 .flags = AD7793_FLAG_HAS_CLKSEL | 674 .flags = AD7793_FLAG_HAS_CLKSEL |
614 AD7793_FLAG_HAS_REFSEL | 675 AD7793_FLAG_HAS_REFSEL |
615 AD7793_FLAG_HAS_VBIAS | 676 AD7793_FLAG_HAS_VBIAS |
616 AD7793_HAS_EXITATION_CURRENT, 677 AD7793_HAS_EXITATION_CURRENT |
678 AD7793_FLAG_HAS_GAIN |
679 AD7793_FLAG_HAS_BUFFER,
617 }, 680 },
618 [ID_AD7794] = { 681 [ID_AD7794] = {
619 .id = AD7794_ID, 682 .id = AD7794_ID,
620 .channels = ad7794_channels, 683 .channels = ad7794_channels,
621 .num_channels = ARRAY_SIZE(ad7794_channels), 684 .num_channels = ARRAY_SIZE(ad7794_channels),
685 .iio_info = &ad7793_info,
686 .sample_freq_avail = ad7793_sample_freq_avail,
622 .flags = AD7793_FLAG_HAS_CLKSEL | 687 .flags = AD7793_FLAG_HAS_CLKSEL |
623 AD7793_FLAG_HAS_REFSEL | 688 AD7793_FLAG_HAS_REFSEL |
624 AD7793_FLAG_HAS_VBIAS | 689 AD7793_FLAG_HAS_VBIAS |
625 AD7793_HAS_EXITATION_CURRENT, 690 AD7793_HAS_EXITATION_CURRENT |
691 AD7793_FLAG_HAS_GAIN |
692 AD7793_FLAG_HAS_BUFFER,
626 }, 693 },
627 [ID_AD7795] = { 694 [ID_AD7795] = {
628 .id = AD7795_ID, 695 .id = AD7795_ID,
629 .channels = ad7795_channels, 696 .channels = ad7795_channels,
630 .num_channels = ARRAY_SIZE(ad7795_channels), 697 .num_channels = ARRAY_SIZE(ad7795_channels),
698 .iio_info = &ad7793_info,
699 .sample_freq_avail = ad7793_sample_freq_avail,
631 .flags = AD7793_FLAG_HAS_CLKSEL | 700 .flags = AD7793_FLAG_HAS_CLKSEL |
632 AD7793_FLAG_HAS_REFSEL | 701 AD7793_FLAG_HAS_REFSEL |
633 AD7793_FLAG_HAS_VBIAS | 702 AD7793_FLAG_HAS_VBIAS |
634 AD7793_HAS_EXITATION_CURRENT, 703 AD7793_HAS_EXITATION_CURRENT |
704 AD7793_FLAG_HAS_GAIN |
705 AD7793_FLAG_HAS_BUFFER,
706 },
707 [ID_AD7796] = {
708 .id = AD7796_ID,
709 .channels = ad7796_channels,
710 .num_channels = ARRAY_SIZE(ad7796_channels),
711 .iio_info = &ad7797_info,
712 .sample_freq_avail = ad7797_sample_freq_avail,
713 .flags = AD7793_FLAG_HAS_CLKSEL,
714 },
715 [ID_AD7797] = {
716 .id = AD7797_ID,
717 .channels = ad7797_channels,
718 .num_channels = ARRAY_SIZE(ad7797_channels),
719 .iio_info = &ad7797_info,
720 .sample_freq_avail = ad7797_sample_freq_avail,
721 .flags = AD7793_FLAG_HAS_CLKSEL,
635 }, 722 },
636 [ID_AD7798] = { 723 [ID_AD7798] = {
637 .id = AD7798_ID, 724 .id = AD7798_ID,
638 .channels = ad7798_channels, 725 .channels = ad7798_channels,
639 .num_channels = ARRAY_SIZE(ad7798_channels), 726 .num_channels = ARRAY_SIZE(ad7798_channels),
727 .iio_info = &ad7793_info,
728 .sample_freq_avail = ad7793_sample_freq_avail,
729 .flags = AD7793_FLAG_HAS_GAIN |
730 AD7793_FLAG_HAS_BUFFER,
640 }, 731 },
641 [ID_AD7799] = { 732 [ID_AD7799] = {
642 .id = AD7799_ID, 733 .id = AD7799_ID,
643 .channels = ad7799_channels, 734 .channels = ad7799_channels,
644 .num_channels = ARRAY_SIZE(ad7799_channels), 735 .num_channels = ARRAY_SIZE(ad7799_channels),
736 .iio_info = &ad7793_info,
737 .sample_freq_avail = ad7793_sample_freq_avail,
738 .flags = AD7793_FLAG_HAS_GAIN |
739 AD7793_FLAG_HAS_BUFFER,
645 }, 740 },
646}; 741};
647 742
@@ -702,7 +797,7 @@ static int ad7793_probe(struct spi_device *spi)
702 indio_dev->modes = INDIO_DIRECT_MODE; 797 indio_dev->modes = INDIO_DIRECT_MODE;
703 indio_dev->channels = st->chip_info->channels; 798 indio_dev->channels = st->chip_info->channels;
704 indio_dev->num_channels = st->chip_info->num_channels; 799 indio_dev->num_channels = st->chip_info->num_channels;
705 indio_dev->info = &ad7793_info; 800 indio_dev->info = st->chip_info->iio_info;
706 801
707 ret = ad_sd_setup_buffer_and_trigger(indio_dev); 802 ret = ad_sd_setup_buffer_and_trigger(indio_dev);
708 if (ret) 803 if (ret)
@@ -757,6 +852,8 @@ static const struct spi_device_id ad7793_id[] = {
757 {"ad7793", ID_AD7793}, 852 {"ad7793", ID_AD7793},
758 {"ad7794", ID_AD7794}, 853 {"ad7794", ID_AD7794},
759 {"ad7795", ID_AD7795}, 854 {"ad7795", ID_AD7795},
855 {"ad7796", ID_AD7796},
856 {"ad7797", ID_AD7797},
760 {"ad7798", ID_AD7798}, 857 {"ad7798", ID_AD7798},
761 {"ad7799", ID_AD7799}, 858 {"ad7799", ID_AD7799},
762 {} 859 {}