iio: backend: add API for interface get
Subsystems (6)
Antoniu Miclaus
reviewerPATCH v4 1/6 iio: backend: add API for interface get
Add backend support for obtaining the interface type used.
---
no changes in v4.
drivers/iio/industrialio-backend.c | 24 ++++++++++++++++++++++++ include/linux/iio/backend.h | 13 +++++++++++++ 2 files changed, 37 insertions(+)
drivers/iio/industrialio-backend.c +24 -0
@@ -449,6 +449,30 @@ ssize_t iio_backend_ext_info_set(struct iio_dev *indio_dev, uintptr_t private, }EXPORT_SYMBOL_NS_GPL (iio_backend_ext_info_set,IIO_BACKEND ); +/** +* iio_backend_interface_type_get - get the interface type used. +* @back: Backend device +* @type: Interface type +* +* RETURNS: +* 0 on success, negative error number on failure. +*/ +int iio_backend_interface_type_get (struct iio_backend *back, +enum iio_backend_interface_type *type) +{ +int ret; + + ret =iio_backend_op_call (back, interface_type_get, type); +if (ret) +return ret; + +if (*type >=IIO_BACKEND_INTERFACE_MAX ) +return -EINVAL ; + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (iio_backend_interface_type_get,IIO_BACKEND ); +/** * iio_backend_extend_chan_spec - Extend an IIO channel * @indio_dev: IIO device
include/linux/iio/backend.h +13 -0
@@ -63,6 +63,14 @@ enum iio_backend_sample_trigger { IIO_BACKEND_SAMPLE_TRIGGER_MAX }; +enum iio_backend_interface_type { +IIO_BACKEND_INTERFACE_LVDS , +IIO_BACKEND_INTERFACE_CMOS , +IIO_BACKEND_INTERFACE_SERIAL_LVDS , +IIO_BACKEND_INTERFACE_SERIAL_CMOS , +IIO_BACKEND_INTERFACE_MAX +}; +/** * struct iio_backend_ops - operations structure for an iio_backend * @enable: Enable backend.
@@ -81,6 +89,7 @@ enum iio_backend_sample_trigger {* @extend_chan_spec: Extend an IIO channel. * @ext_info_set: Extended info setter. * @ext_info_get: Extended info getter. +* @interface_type_get: Interface type. **/ struct iio_backend_ops {int (*enable)(struct iio_backend *back);
@@ -113,6 +122,8 @@ struct iio_backend_ops { const char *buf, size_t len);int (*ext_info_get)(struct iio_backend *back,uintptr_t private,const struct iio_chan_spec *chan,char *buf); +int (*interface_type_get)(struct iio_backend *back, +enum iio_backend_interface_type *type); };int iio_backend_chan_enable (struct iio_backend *back,unsigned int chan);
@@ -142,6 +153,8 @@ ssize_t iio_backend_ext_info_set(struct iio_dev *indio_dev, uintptr_t private,ssize_t iio_backend_ext_info_get (struct iio_dev *indio_dev,uintptr_t private,const struct iio_chan_spec *chan,char *buf); +int iio_backend_interface_type_get (struct iio_backend *back, +enum iio_backend_interface_type *type);int iio_backend_extend_chan_spec (struct iio_dev *indio_dev,struct iio_backend *back,struct iio_chan_spec *chan);
Signature · 1 line
2.46.2
Antoniu Miclaus
reviewerPATCH v4 2/6 iio: backend: add support for data size set
Add backend support for setting the data size used.
This setting can be adjusted within the IP cores interfacing devices.
---
no changes in v4.
drivers/iio/industrialio-backend.c | 21 +++++++++++++++++++++ include/linux/iio/backend.h | 3 +++ 2 files changed, 24 insertions(+)
drivers/iio/industrialio-backend.c +21 -0
@@ -473,6 +473,27 @@ int iio_backend_interface_type_get(struct iio_backend *back, }EXPORT_SYMBOL_NS_GPL (iio_backend_interface_type_get,IIO_BACKEND ); +/** +* iio_backend_data_size_set - set the data width/size in the data bus. +* @back: Backend device +* @size: Size in bits +* +* Some frontend devices can dynamically control the word/data size on the +* interface/data bus. Hence, the backend device needs to be aware of it so +* data can be correctly transferred. +* +* Return: +* 0 on success, negative error number on failure. +*/ +size_t iio_backend_data_size_set (struct iio_backend *back,size_t size) +{ +if (!size) +return -EINVAL ; + +return iio_backend_op_call (back, data_size_set, size); +} +EXPORT_SYMBOL_NS_GPL (iio_backend_data_size_set,IIO_BACKEND ); +/** * iio_backend_extend_chan_spec - Extend an IIO channel * @indio_dev: IIO device
include/linux/iio/backend.h +3 -0
@@ -90,6 +90,7 @@ enum iio_backend_interface_type {* @ext_info_set: Extended info setter. * @ext_info_get: Extended info getter. * @interface_type_get: Interface type. +* @data_size_set: Data size. **/ struct iio_backend_ops {int (*enable)(struct iio_backend *back);
@@ -124,6 +125,7 @@ struct iio_backend_ops { const struct iio_chan_spec *chan, char *buf);int (*interface_type_get)(struct iio_backend *back,enum iio_backend_interface_type *type); +int (*data_size_set)(struct iio_backend *back,ssize_t size); };int iio_backend_chan_enable (struct iio_backend *back,unsigned int chan);
@@ -155,6 +157,7 @@ ssize_t iio_backend_ext_info_get(struct iio_dev *indio_dev, uintptr_t private,int iio_backend_interface_type_get (struct iio_backend *back,enum iio_backend_interface_type *type); +size_t iio_backend_data_size_set (struct iio_backend *back,size_t size);int iio_backend_extend_chan_spec (struct iio_dev *indio_dev,struct iio_backend *back,struct iio_chan_spec *chan);
Signature · 1 line
2.46.2
Antoniu Miclaus
reviewerPATCH v4 3/6 iio: adc: adi-axi-adc: add interface type
In reply to Antoniu MiclausAdd support for getting the interface (CMOS or LVDS) used by the AXI ADC IP.
---
changes in v4:
- minor typo in commit message.
drivers/iio/adc/adi-axi-adc.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/iio/adc/adi-axi-adc.c +23 -0
@@ -39,6 +39,9 @@#define ADI_AXI_REG_RSTN_MMCM_RSTN BIT(1)#define ADI_AXI_REG_RSTN_RSTN BIT(0) +#define ADI_AXI_ADC_REG_CONFIG 0x000c +#define ADI_AXI_ADC_REG_CONFIG_CMOS_OR_LVDS_N BIT(7) +#define ADI_AXI_ADC_REG_CTRL 0x0044#define ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK BIT(1)
@@ -249,6 +252,25 @@ static int axi_adc_chan_disable(struct iio_backend *back, unsigned int chan) ADI_AXI_REG_CHAN_CTRL_ENABLE); } +static int axi_adc_interface_type_get (struct iio_backend *back, +enum iio_backend_interface_type *type) +{ +struct adi_axi_adc_state *st =iio_backend_get_priv (back); +unsigned int val; +int ret; + + ret =regmap_read (st->regmap,ADI_AXI_ADC_REG_CONFIG , &val); +if (ret) +return ret; + +if (val &ADI_AXI_ADC_REG_CONFIG_CMOS_OR_LVDS_N ) + *type =IIO_BACKEND_INTERFACE_CMOS ; +else + *type =IIO_BACKEND_INTERFACE_LVDS ; + +return 0 ; +} +static struct iio_buffer *axi_adc_request_buffer (struct iio_backend *back,struct iio_dev *indio_dev) {
@@ -285,6 +307,7 @@ static const struct iio_backend_ops adi_axi_adc_generic = { .iodelay_set = axi_adc_iodelays_set, .test_pattern_set = axi_adc_test_pattern_set, .chan_status = axi_adc_chan_status, + .interface_type_get = axi_adc_interface_type_get, };static int adi_axi_adc_probe (struct platform_device *pdev)
Signature · 1 line
2.46.2
David Lechner
reviewerRe: [PATCH v4 3/6] iio: adc: adi-axi-adc: add interface type
Quoted 5 lines · Antoniu Miclaus
Add support for getting the interface (CMOS or LVDS) used by the AXI ADC IP.
Signed-off-by Antoniu Miclaus <[email protected]>---
...
Quoted 5 lines
drivers/iio/adc/adi-axi-adc.c +5
-0+static int axi_adc_interface_type_get (struct iio_backend *back, +enum iio_backend_interface_type *type) +{ +struct adi_axi_adc_state *st =iio_backend_get_priv (back); +unsigned int val;
drivers/iio/adc/adi-axi-adc.c static int axi_adc_chan_disable(struct iio_backend *back, unsigned int chan) · line 269
Quoted 10 lines
drivers/iio/adc/adi-axi-adc.c +10
-0+int ret; + + ret =regmap_read (st->regmap,ADI_AXI_ADC_REG_CONFIG , &val); +if (ret) +return ret; + +if (val &ADI_AXI_ADC_REG_CONFIG_CMOS_OR_LVDS_N ) + *type =IIO_BACKEND_INTERFACE_CMOS ; +else + *type =IIO_BACKEND_INTERFACE_LVDS ;
These should be the more specific IIO_BACKEND_INTERFACE_SERIAL_CMOS and IIO_BACKEND_INTERFACE_SERIAL_LVDS.
Quoted 15 lines
drivers/iio/adc/adi-axi-adc.c +5
-0+ +return 0 ; +} +static struct iio_buffer *axi_adc_request_buffer (struct iio_backend *back,struct iio_dev *indio_dev) {@@ -285,6 +307,7 @@ static const struct iio_backend_ops adi_axi_adc_generic = { .iodelay_set = axi_adc_iodelays_set, .test_pattern_set = axi_adc_test_pattern_set, .chan_status = axi_adc_chan_status, + .interface_type_get = axi_adc_interface_type_get, };static int adi_axi_adc_probe (struct platform_device *pdev)
Antoniu Miclaus
reviewerPATCH v4 4/6 iio: adc: adi-axi-adc: set data format
In reply to Antoniu MiclausAdd support for selecting the data format within the AXI ADC ip.
---
changes in v4:
- update indentation to match the rest of the driver.
- shrink axi_adc_data_size_set in one line.
drivers/iio/adc/adi-axi-adc.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/iio/adc/adi-axi-adc.c +22 -0
@@ -45,6 +45,9 @@#define ADI_AXI_ADC_REG_CTRL 0x0044#define ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK BIT(1) +#define ADI_AXI_ADC_REG_CNTRL_3 0x004c +#define ADI_AXI_ADC_CNTRL_3_CUSTOM_CTRL_MSK GENMASK(7, 0) +#define ADI_AXI_ADC_REG_DRP_STATUS 0x0074#define ADI_AXI_ADC_DRP_LOCKED BIT(17)
@@ -271,6 +274,24 @@ static int axi_adc_interface_type_get(struct iio_backend *back,return 0 ; } +static int axi_adc_data_size_set (struct iio_backend *back,ssize_t size) +{ +struct adi_axi_adc_state *st =iio_backend_get_priv (back); +unsigned int val; + +if (size <=20 ) + val =0 ; +else if (size <=24 ) + val =1 ; +else if (size <=32 ) + val =3 ; +else +return -EINVAL ; + +return regmap_update_bits (st->regmap,ADI_AXI_ADC_REG_CNTRL_3 , +ADI_AXI_ADC_CNTRL_3_CUSTOM_CONTROL_MSK , val); +} +static struct iio_buffer *axi_adc_request_buffer (struct iio_backend *back,struct iio_dev *indio_dev) {
@@ -308,6 +329,7 @@ static const struct iio_backend_ops adi_axi_adc_generic = { .test_pattern_set = axi_adc_test_pattern_set, .chan_status = axi_adc_chan_status, .interface_type_get = axi_adc_interface_type_get, + .data_size_set = axi_adc_data_size_set, };static int adi_axi_adc_probe (struct platform_device *pdev)
Signature · 1 line
2.46.2
Antoniu Miclaus
reviewerPATCH v4 5/6 dt-bindings: iio: adc: add ad4851
In reply to Antoniu MiclausAdd devicetree bindings for ad485x family.
---
no changes in v4.
.../bindings/iio/adc/adi,ad4851.yaml | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad4851.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad4851.yaml new file +103 -0
@@ -0,0 +1,103 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2024 Analog Devices Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,ad4851.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD485X family + +maintainers: + - Sergiu Cuciurean <[email protected]> + - Dragos Bogdan <[email protected]> + - Antoniu Miclaus <[email protected]> + +description: | + Analog Devices AD485X fully buffered, 8-channel simultaneous sampling, + 16/20-bit, 1 MSPS data acquisition system (DAS) with differential, wide + common-mode range inputs. + + https://www.analog.com/media/en/technical-documentation/data-sheets/ad4855.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad4856.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad4857.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad4858.pdf + +$ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + enum: + - adi,ad4851 + - adi,ad4852 + - adi,ad4853 + - adi,ad4854 + - adi,ad4855 + - adi,ad4856 + - adi,ad4857 + - adi,ad4858 + - adi,ad4858i + + reg: + maxItems: 1 + + vcc-supply: true + + vee-supply: true + + vdd-supply: true + + vddh-supply: true + + vddl-supply: true + + vio-supply: true + + vrefbuf-supply: true + + vrefio-supply: true + + pwms: + description: PWM connected to the CNV pin. + maxItems: 1 + + io-backends: + maxItems: 1 + + pd-gpios: + maxItems: 1 + + spi-max-frequency: + maximum: 25000000 + +required: + - compatible + - reg + - vcc-supply + - vee-supply + - vdd-supply + - vio-supply + - pwms + +unevaluatedProperties: false + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + adc@0{ + compatible = "adi,ad4858"; + reg = <0>; + spi-max-frequency = <10000000>; + vcc-supply = <&vcc>; + vdd-supply = <&vdd>; + vee-supply = <&vee>; + vddh-supply = <&vddh>; + vddl-supply = <&vddh>; + vio-supply = <&vio>; + pwms = <&pwm_gen 0 0>; + io-backends = <&iio_backend>; + }; + }; +...
Signature · 1 line
2.46.2
Jonathan Cameron
maintainerRe: [PATCH v4 5/6] dt-bindings: iio: adc: add ad4851
Quoted 4 lines · On Fri, 18 Oct 2024 13:42:09 +0300 Antoniu Miclaus…
Add devicetree bindings for ad485x family.
Reviewed-by Conor Dooley <[email protected]>Signed-off-by Antoniu Miclaus <[email protected]>
One question inline.
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4851.yaml new file +5
-0+examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>;
Documentation/devicetree/bindings/iio/adc/adi,ad4851.yaml line 97
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4851.yaml new file +10
-0+ + adc@0{ + compatible = "adi,ad4858"; + reg = <0>; + spi-max-frequency = <10000000>; + vcc-supply = <&vcc>; + vdd-supply = <&vdd>; + vee-supply = <&vee>; + vddh-supply = <&vddh>; + vddl-supply = <&vddh>;
I was curious what these supplies are giving h and l naming. Seems vddh is the supply for an LDO and vddhl is a way of supplying an alternative 1.8V to the output from that LDO.
Superficially it looks like an either or situation. I'm not that worried if the binding enforces that detail though it would be nice to do so. However this example seems misleading as I don't think you would ever connect them to the same supply.
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4851.yaml new file +6
-0+ vio-supply = <&vio>; + pwms = <&pwm_gen 0 0>; + io-backends = <&iio_backend>; + }; + }; +...
Antoniu Miclaus
reviewerPATCH v4 6/6 iio: adc: ad4851: add ad485x driver
In reply to Antoniu MiclausAdd support for the AD485X a fully buffered, 8-channel simultaneous sampling, 16/20-bit, 1 MSPS data acquisition system (DAS) with differential, wide common-mode range inputs.
---
changes in v4:
- shrink ad4851_oversampling_ratios into 8 per line.
- add osr 0 case in ad4851_set_oversampling_ratio
- use if..else statement for setting packet format
- add comment inside "ad4851_find_opt"
- use ROUND_CLOSEST
- use NSEC_PER_SEC
- change the handling of regulators vrefbuf and vrefio and update afferent registers
- {} -> { }
- fix compatible strings order.
drivers/iio/adc/Kconfig | 13 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ad4851.c | 1155 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 1169 insertions(+) create mode 100644 drivers/iio/adc/ad4851.c
drivers/iio/adc/Kconfig +13 -0
@@ -36,6 +36,19 @@ config AD4130 To compile this driver as a module, choose M here: the module will be called ad4130. +config AD4851 + tristate "Analog Device AD4851 DAS Driver" + depends on SPI + select REGMAP_SPI + select IIO_BACKEND + help + Say yes here to build support for Analog Devices AD4851, AD4852, + AD4853, AD4854, AD4855, AD4856, AD4857, AD4858, AD4858I high speed + data acquisition system (DAS). + + To compile this driver as a module, choose M here: the module will be + called ad4851. + config AD7091R tristate
drivers/iio/adc/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o obj-$(CONFIG_AD4130) += ad4130.o +obj-$(CONFIG_AD4851) += ad4851.o obj-$(CONFIG_AD7091R) += ad7091r-base.o obj-$(CONFIG_AD7091R5) += ad7091r5.o obj-$(CONFIG_AD7091R8) += ad7091r8.o
drivers/iio/adc/ad4851.c new file +1155 -0
1,155 lines not on this page · raw message
Signature · 1 line
2.46.2
Jonathan Cameron
maintainerRe: [PATCH v4 6/6] iio: adc: ad4851: add ad485x driver
Quoted 5 lines · On Fri, 18 Oct 2024 13:42:10 +0300 Antoniu Miclaus…
Add support for the AD485X a fully buffered, 8-channel simultaneous sampling, 16/20-bit, 1 MSPS data acquisition system (DAS) with differential, wide common-mode range inputs.
Signed-off-by Antoniu Miclaus <[email protected]>
A few minor things from me that I could fix whilst applying, but David gave a much more detailed review of v3, so I'll wait for his feedback on this. I haven't dug into datasheets much and may well have missed other things.
Quoted 25 lines
obj-$(CONFIG_AD7091R8) += ad7091r8.o
drivers/iio/adc/ad4851.c new file +18
-0@@ -0,0 +1,1155 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Analog Devices AD4851 DAS driver +* +* Copyright 2024 Analog Devices Inc. +*/ + +#include <linux/array_size.h> +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/minmax.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/pwm.h>
drivers/iio/adc/ad4851.c line 28
Quoted 10 lines
drivers/iio/adc/ad4851.c new file +10
-0+#include <linux/regmap.h> +#include <linux/regulator/consumer.h> +#include <linux/spi/spi.h> +#include <linux/types.h> +#include <linux/units.h> + +#include <linux/iio/backend.h> +#include <linux/iio/iio.h> + +#include <asm/unaligned.h>
This moved. I can fix up whilst applying but it is now at linux/unaligned.h as of rc2.
Quoted 4 lines
drivers/iio/adc/ad4851.c new file +4
-0+static int ad4851_get_calibscale (struct ad4851_state *st,int ch,int *val,int *val2) +{ +unsigned int reg_val; +int gain;
drivers/iio/adc/ad4851.c line 504
Quoted 10 lines
drivers/iio/adc/ad4851.c new file +10
-0+int ret; + +guard (mutex)(&st->lock); + + ret =regmap_read (st->regmap,AD4851_REG_CHX_GAIN_MSB (ch), + ®_val); +if (ret) +return ret; + + gain = (reg_val &0xFF ) <<8 ;
The register size is 8 bits, so I'm not sure what that masking is adding.
gain = reg_val << 8; should be fine. Maybe the compiler or some
static analysis is wrong?
drivers/iio/adc/ad4851.c line 511
Quoted 7 lines
drivers/iio/adc/ad4851.c new file +7
-0+ + ret =regmap_read (st->regmap,AD4851_REG_CHX_GAIN_LSB (ch), + ®_val); +if (ret) +return ret; + + gain |= reg_val &0xFF ;
same here.
Quoted 7 lines
drivers/iio/adc/ad4851.c new file +7
-0+ + *val = gain; + *val2 =32768 ; + +return IIO_VAL_FRACTIONAL ; +} +
David Lechner
reviewerRe: [PATCH v4 6/6] iio: adc: ad4851: add ad485x driver
Quoted 7 lines · Jonathan Cameron
Quoted 4 lines · On Fri, 18 Oct 2024 13:42:10 +0300 Antoniu Miclaus…
Add support for the AD485X a fully buffered, 8-channel simultaneous sampling, 16/20-bit, 1 MSPS data acquisition system (DAS) with differential, wide common-mode range inputs.
Quoted 7 lines
Quoted 1 line
Signed-off-by Antoniu Miclaus <[email protected]>A few minor things from me that I could fix whilst applying, but David gave a much more detailed review of v3, so I'll wait for his feedback on this. I haven't dug into datasheets much and may well have missed other things.
Many of my review comments were not addressed at all. :-(
Plus one addressed incorrectly (rounding PWM period down instead of the suggested rounding up).
I still have major concerns about userspace-facing things like the questionable use of the offset attribute and fixing how oversampling interacts with the scan_type.
David Lechner
reviewerQuoted 4 lines · Antoniu Miclaus
Add backend support for obtaining the interface type used.
Signed-off-by Antoniu Miclaus <[email protected]>---
...
Quoted 8 lines
/**
*iio_backend_extend_chan_spec- Extend an IIO channel
* @indio_dev: IIO deviceinclude/linux/iio/backend.h +0
-0
include/linux/iio/backend.h enum iio_backend_sample_trigger { · line 68
Quoted 6 lines
include/linux/iio/backend.h +3
-0@@ -63,6 +63,14 @@ enum iio_backend_sample_trigger {IIO_BACKEND_SAMPLE_TRIGGER_MAX }; +enum iio_backend_interface_type { +IIO_BACKEND_INTERFACE_LVDS , +IIO_BACKEND_INTERFACE_CMOS ,
I think IIO_BACKEND_INTERFACE_LVDS and IIO_BACKEND_INTERFACE_CMOS should be removed. They are ambiguous and overlap with the SERIAL_ versions.
Quoted 5 lines
include/linux/iio/backend.h +5
-0+IIO_BACKEND_INTERFACE_SERIAL_LVDS , +IIO_BACKEND_INTERFACE_SERIAL_CMOS , +IIO_BACKEND_INTERFACE_MAX +}; + struct iio_chan_spec *chan);