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

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: ad7768-1: add low pass -3dB cutoff attribute

Ad7768-1 has a different -3db frequency multiplier depending on
the filter type configured. The cutoff frequency also varies according
to the current ODR.

Add a readonly low pass -3dB frequency cutoff attribute to clarify to
the user which bandwidth is being allowed depending on the filter
configurations.

Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
Link: https://patch.msgid.link/804d66f1858014d7278aec3344d81c223661e878.1749569957.git.Jonathan.Santos@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Jonathan Santos and committed by
Jonathan Cameron
00a468c9 5eef68d6

+17 -1
+17 -1
drivers/iio/adc/ad7768-1.c
··· 22 22 #include <linux/sysfs.h> 23 23 #include <linux/spi/spi.h> 24 24 #include <linux/unaligned.h> 25 + #include <linux/units.h> 25 26 #include <linux/util_macros.h> 26 27 27 28 #include <linux/iio/buffer.h> ··· 151 150 enum ad7768_scan_type { 152 151 AD7768_SCAN_TYPE_NORMAL, 153 152 AD7768_SCAN_TYPE_HIGH_SPEED, 153 + }; 154 + 155 + /* -3dB cutoff frequency multipliers (relative to ODR) for each filter type. */ 156 + static const int ad7768_filter_3db_odr_multiplier[] = { 157 + [AD7768_FILTER_SINC5] = 204, /* 0.204 */ 158 + [AD7768_FILTER_SINC3] = 262, /* 0.2617 */ 159 + [AD7768_FILTER_SINC3_REJ60] = 262, /* 0.2617 */ 160 + [AD7768_FILTER_WIDEBAND] = 433, /* 0.433 */ 154 161 }; 155 162 156 163 static const int ad7768_mclk_div_rates[] = { ··· 755 746 .type = IIO_VOLTAGE, 756 747 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 757 748 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | 749 + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | 758 750 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 759 751 .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 760 752 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), ··· 776 766 { 777 767 struct ad7768_state *st = iio_priv(indio_dev); 778 768 const struct iio_scan_type *scan_type; 779 - int scale_uv, ret; 769 + int scale_uv, ret, temp; 780 770 781 771 scan_type = iio_get_current_scan_type(indio_dev, chan); 782 772 if (IS_ERR(scan_type)) ··· 813 803 814 804 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 815 805 *val = st->oversampling_ratio; 806 + 807 + return IIO_VAL_INT; 808 + 809 + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: 810 + temp = st->samp_freq * ad7768_filter_3db_odr_multiplier[st->filter_type]; 811 + *val = DIV_ROUND_CLOSEST(temp, MILLI); 816 812 817 813 return IIO_VAL_INT; 818 814 }