Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio:adxl372: Add filter bandwidth support

This patch adds the option for the user to select the filter bandwidth. The
user can also read the available bandwidths which are always adjusted to be
at most half of the sampling frequency. Furthermore, the currently selected
bandwidth can be read via the read_raw function, while the write_raw sets a
new bandwidth value.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Stefan Popa and committed by
Jonathan Cameron
7ec040af 5e605a4d

+36 -2
+36 -2
drivers/iio/accel/adxl372.c
··· 202 202 400, 800, 1600, 3200, 6400, 203 203 }; 204 204 205 + static const int adxl372_bw_freq_tbl[5] = { 206 + 200, 400, 800, 1600, 3200, 207 + }; 208 + 205 209 struct adxl372_axis_lookup { 206 210 unsigned int bits; 207 211 enum adxl372_fifo_format fifo_format; ··· 228 224 .channel2 = IIO_MOD_##axis, \ 229 225 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 230 226 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 231 - BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 227 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ 228 + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ 232 229 .scan_index = index, \ 233 230 .scan_type = { \ 234 231 .sign = 's', \ ··· 653 648 case IIO_CHAN_INFO_SAMP_FREQ: 654 649 *val = adxl372_samp_freq_tbl[st->odr]; 655 650 return IIO_VAL_INT; 651 + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 652 + *val = adxl372_bw_freq_tbl[st->bw]; 653 + return IIO_VAL_INT; 656 654 } 657 655 658 656 return -EINVAL; ··· 666 658 int val, int val2, long info) 667 659 { 668 660 struct adxl372_state *st = iio_priv(indio_dev); 669 - int odr_index, ret; 661 + int odr_index, bw_index, ret; 670 662 671 663 switch (info) { 672 664 case IIO_CHAN_INFO_SAMP_FREQ: ··· 698 690 ret = adxl372_set_bandwidth(st, odr_index); 699 691 700 692 return ret; 693 + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 694 + bw_index = adxl372_find_closest_match(adxl372_bw_freq_tbl, 695 + ARRAY_SIZE(adxl372_bw_freq_tbl), 696 + val); 697 + return adxl372_set_bandwidth(st, bw_index); 701 698 default: 702 699 return -EINVAL; 703 700 } 701 + } 702 + 703 + static ssize_t adxl372_show_filter_freq_avail(struct device *dev, 704 + struct device_attribute *attr, 705 + char *buf) 706 + { 707 + struct iio_dev *indio_dev = dev_to_iio_dev(dev); 708 + struct adxl372_state *st = iio_priv(indio_dev); 709 + int i; 710 + size_t len = 0; 711 + 712 + for (i = 0; i <= st->odr; i++) 713 + len += scnprintf(buf + len, PAGE_SIZE - len, 714 + "%d ", adxl372_bw_freq_tbl[i]); 715 + 716 + buf[len - 1] = '\n'; 717 + 718 + return len; 704 719 } 705 720 706 721 static ssize_t adxl372_get_fifo_enabled(struct device *dev, ··· 869 838 }; 870 839 871 840 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("400 800 1600 3200 6400"); 841 + static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available, 842 + 0444, adxl372_show_filter_freq_avail, NULL, 0); 872 843 873 844 static struct attribute *adxl372_attributes[] = { 874 845 &iio_const_attr_sampling_frequency_available.dev_attr.attr, 846 + &iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr, 875 847 NULL, 876 848 }; 877 849