aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc/ad7606.h
diff options
context:
space:
mode:
authorAlexandru Ardelean <aardelean@baylibre.com>2024-09-19 16:04:40 +0300
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2024-09-30 09:21:04 +0100
commit94aab7a0f5c77f1ee9be87fab3524807d78cf560 (patch)
treee9c0d6101d7c2deaa626e7ca82b775bf5d1f048d /drivers/iio/adc/ad7606.h
parentiio: adc: ad7606: wrap channel ranges & scales into struct (diff)
downloadlinux-94aab7a0f5c77f1ee9be87fab3524807d78cf560.tar.gz
linux-94aab7a0f5c77f1ee9be87fab3524807d78cf560.zip
iio: adc: ad7606: rework available attributes for SW channels
For SW mode, the oversampling and scales attributes are always present. So, they can be implemented via a 'read_avail' hook in iio_info. For HW mode, it's a bit tricky, as these attributes get assigned based on GPIO definitions. So, for SW mode, we define a separate AD7606_SW_CHANNEL() macro, and use that for the SW channels. And 'ad7606_info_os_range_and_debug' can be renamed to 'ad7606_info_sw_mode' as it is only used for SW mode. For the 'read_avail' hook, we'll need to allocate the SW scales, so that they are just returned userspace without any extra processing. The allocation will happen when then ad7606_state struct is allocated. The oversampling available parameters don't need any extra processing; they can just be passed back to userspace (as they are). Signed-off-by: Alexandru Ardelean <aardelean@baylibre.com> Link: https://patch.msgid.link/20240919130444.2100447-6-aardelean@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/adc/ad7606.h')
-rw-r--r--drivers/iio/adc/ad7606.h32
1 files changed, 28 insertions, 4 deletions
diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
index 2b90f52affba..25e84efd15c3 100644
--- a/drivers/iio/adc/ad7606.h
+++ b/drivers/iio/adc/ad7606.h
@@ -27,6 +27,29 @@
}, \
}
+#define AD7606_SW_CHANNEL(num, bits) { \
+ .type = IIO_VOLTAGE, \
+ .indexed = 1, \
+ .channel = num, \
+ .address = num, \
+ .info_mask_separate = \
+ BIT(IIO_CHAN_INFO_RAW) | \
+ BIT(IIO_CHAN_INFO_SCALE), \
+ .info_mask_separate_available = \
+ BIT(IIO_CHAN_INFO_SCALE), \
+ .info_mask_shared_by_all = \
+ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
+ .info_mask_shared_by_all_available = \
+ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
+ .scan_index = num, \
+ .scan_type = { \
+ .sign = 's', \
+ .realbits = (bits), \
+ .storagebits = (bits) > 16 ? 32 : 16, \
+ .endianness = IIO_CPU, \
+ }, \
+}
+
#define AD7605_CHANNEL(num) \
AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \
BIT(IIO_CHAN_INFO_SCALE), 0, 16)
@@ -36,10 +59,6 @@
BIT(IIO_CHAN_INFO_SCALE), \
BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits)
-#define AD7606_SW_CHANNEL(num, bits) \
- AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),\
- 0, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits)
-
#define AD7616_CHANNEL(num) AD7606_SW_CHANNEL(num, 16)
struct ad7606_state;
@@ -71,11 +90,16 @@ struct ad7606_chip_info {
/**
* struct ad7606_chan_scale - channel scale configuration
* @scale_avail pointer to the array which stores the available scales
+ * @scale_avail_show a duplicate of 'scale_avail' which is readily formatted
+ * such that it can be read via the 'read_avail' hook
* @num_scales number of elements stored in the scale_avail array
* @range voltage range selection, selects which scale to apply
*/
struct ad7606_chan_scale {
+#define AD760X_MAX_SCALES 16
+#define AD760X_MAX_SCALE_SHOW (AD760X_MAX_SCALES * 2)
const unsigned int *scale_avail;
+ int scale_avail_show[AD760X_MAX_SCALE_SHOW];
unsigned int num_scales;
unsigned int range;
};