iio: adc: ad9467: add debugFS test mode support
Subsystems (5)
Nuno Sa
maintainerv2 cover iio: adc: ad9467: add debugFS test mode support
This is the second version of the series. I ended up trying the new directory route and think it does look nice and more future proof. Biggest change is the first patch where we now pass an info like structure to devm_iio_backend_register(). Again, this is likely also a more future proof approach and we would likely need it sooner or later (one usage I see is for backends to pass in some constant information that could be consumed from frontends when doing backend_get())
v1:
* https://lore.kernel.org/linux-iio/20240709-dev-iio-backend-add-debugfs-v1-0-fb4b8f2373c7@analog.com/
v2:
* Patch 1:
- New patch;
* Patch 2:
- Added backendY directory with the direct_reg_access and name
attributes;
- Get the backend name directly from the backend driver;
- Get the backend index from backend-names FW property;
- Added debugfs-iio-backend to the ABI docs.
---
Nuno Sa (8):
iio: backend: introduce struct iio_backend_info
iio: backend: add debugFs interface
iio: backend: add a modified prbs23 support
iio: adc: adi-axi-adc: support modified prbs23
iio: adc: adi-axi-adc: split axi_adc_chan_status()
iio: adc: adi-axi-adc: implement backend debugfs interface
iio: adc: ad9467: add backend test mode helpers
iio: adc: ad9467: add digital interface test to debugfs
Documentation/ABI/testing/debugfs-iio-backend | 20 ++ MAINTAINERS | 1 + drivers/iio/adc/ad9467.c | 255 +++++++++++++++++++++++--- drivers/iio/adc/adi-axi-adc.c | 71 ++++++- drivers/iio/dac/adi-axi-dac.c | 7 +- drivers/iio/industrialio-backend.c | 155 +++++++++++++++- include/linux/iio/backend.h | 28 ++- 7 files changed, 499 insertions(+), 38 deletions(-)
---
base-commit: 168bed989d651794d03638e1f7f7b5a800a6f425
change-id: 20240802-dev-iio-backend-add-debugfs-0b13bb5a5b37 --
Thanks!
- Nuno Sá
Nuno Sa
maintainerPATCH v2 1/8 iio: backend: introduce struct iio_backend_info
Instead of only passing the backend ops when calling devm_iio_backend_register(), pass an info like structure that will contains the ops and additional information. Fow now, the backend name is being added as that will be used by the debugFS interface introduced in a later patch.
It also opens the door for further customizations passed by backends.
All users of devm_iio_backend_register() were updated accordingly.
--- drivers/iio/adc/adi-axi-adc.c | 7 ++++++- drivers/iio/dac/adi-axi-dac.c | 7 ++++++- drivers/iio/industrialio-backend.c | 10 +++++----- include/linux/iio/backend.h | 12 +++++++++++- 4 files changed, 28 insertions(+), 8 deletions(-)
drivers/iio/adc/adi-axi-adc.c +6 -1
@@ -273,7 +273,7 @@ static const struct regmap_config axi_adc_regmap_config = { .reg_stride = 4, }; -static const struct iio_backend_ops adi_axi_adc_generic = { +static const struct iio_backend_ops adi_axi_adc_ops = { .enable = axi_adc_enable, .disable = axi_adc_disable, .data_format_set = axi_adc_data_format_set,
@@ -287,6 +287,11 @@ static const struct iio_backend_ops adi_axi_adc_generic = { .chan_status = axi_adc_chan_status, }; +static const struct iio_backend_info adi_axi_adc_generic = { + .name ="axi-adc" , + .ops = &adi_axi_adc_ops, +}; +static int adi_axi_adc_probe (struct platform_device *pdev) {const unsigned int *expected_ver;
drivers/iio/dac/adi-axi-dac.c +6 -1
@@ -507,7 +507,7 @@ static int axi_dac_set_sample_rate(struct iio_backend *back, unsigned int chan,return 0 ; } -static const struct iio_backend_ops axi_dac_generic = { +static const struct iio_backend_ops axi_dac_generic_ops = { .enable = axi_dac_enable, .disable = axi_dac_disable, .request_buffer = axi_dac_request_buffer,
@@ -519,6 +519,11 @@ static const struct iio_backend_ops axi_dac_generic = { .set_sample_rate = axi_dac_set_sample_rate, }; +static const struct iio_backend_info axi_dac_generic = { + .name ="axi-dac" , + .ops = &axi_dac_generic_ops, +}; +static const struct regmap_config axi_dac_regmap_config = { .val_bits =32 , .reg_bits =32 ,
drivers/iio/industrialio-backend.c +5 -5
@@ -641,20 +641,20 @@ static void iio_backend_unregister(void *arg)/** * devm_iio_backend_register - Device managed backend device register * @dev: Backend device being registered -* @ops: Backend ops +* @info: Backend info * @priv: Device private data * -* @ops is mandatory. Not providing it results in -EINVAL. +* @info is mandatory. Not providing it results in -EINVAL. * * RETURNS: * 0 on success, negative error number on failure. */ int devm_iio_backend_register (struct device *dev, -const struct iio_backend_ops *ops,void *priv) +const struct iio_backend_info *info,void *priv) {struct iio_backend *back; -if (!ops) +if (!info || !info->ops)return dev_err_probe (dev, -EINVAL ,"No backend ops given\n" );/*
@@ -667,7 +667,7 @@ int devm_iio_backend_register(struct device *dev,if (!back)return -ENOMEM ; - back->ops = ops; + back->ops = info->ops; back->owner = dev->driver->owner; back->dev = dev; back->priv = priv;
include/linux/iio/backend.h +11 -1
@@ -115,6 +115,16 @@ struct iio_backend_ops { const struct iio_chan_spec *chan, char *buf); }; +/** +* struct iio_backend_info - info structure for an iio_backend +* @name: Backend name. +* @ops: Backend operations. +*/ +struct iio_backend_info { +const char *name; +const struct iio_backend_ops *ops; +}; +int iio_backend_chan_enable (struct iio_backend *back,unsigned int chan);int iio_backend_chan_disable (struct iio_backend *back,unsigned int chan);int devm_iio_backend_enable (struct device *dev,struct iio_backend *back);
@@ -151,6 +161,6 @@ __devm_iio_backend_get_from_fwnode_lookup(struct device *dev, struct fwnode_handle *fwnode);int devm_iio_backend_register (struct device *dev, -const struct iio_backend_ops *ops,void *priv); +const struct iio_backend_info *info,void *priv);#endif
Signature · 1 line
2.45.2
Nuno Sa
maintainerPATCH v2 2/8 iio: backend: add debugFs interface
In reply to Nuno SaThis adds a basic debugfs interface for backends. Two new ops are being added:
* debugfs_reg_access: Analogous to the core IIO one but for backend devices.
* debugfs_print_chan_status: One useful usecase for this one is for testing test tones in a digital interface and "ask" the backend to dump more details on why a test tone might have errors.
--- Documentation/ABI/testing/debugfs-iio-backend | 20 ++++ MAINTAINERS | 1 + drivers/iio/industrialio-backend.c | 145 ++++++++++++++++++++++++++ include/linux/iio/backend.h | 14 +++ 4 files changed, 180 insertions(+)
Documentation/ABI/testing/debugfs-iio-backend new file +20 -0
@@ -0,0 +1,20 @@ +What: /sys/kernel/debug/iio/iio:deviceX/backendY/name +KernelVersion: 6.11 +Contact: [email protected] +Description: + Name of Backend Y connected to device X. + +What: /sys/kernel/debug/iio/iio:deviceX/backendY/direct_reg_access +KernelVersion: 6.11 +Contact: [email protected] +Description: + Directly access the registers of backend Y. Typical usage is: + + Reading address 0x50 + echo 0x50 > direct_reg_access + cat direct_reg_access + + Writing address 0x50 + echo 0x50 0x3 > direct_reg_access + //readback address 0x50 + cat direct_reg_access
MAINTAINERS +1 -0
@@ -10885,6 +10885,7 @@ M: Nuno Sa <[email protected]> R: Olivier Moysan <[email protected]> L: [email protected] S: Maintained +F: Documentation/ABI/testing/debugfs-iio-backend F: drivers/iio/industrialio-backend.c F: include/linux/iio/backend.h
drivers/iio/industrialio-backend.c +145 -0
175 lines not on this page · raw message
include/linux/iio/backend.h +14 -0
@@ -22,6 +22,8 @@ enum iio_backend_data_source { IIO_BACKEND_DATA_SOURCE_MAX }; +#define iio_backend_debugfs_ptr (ptr) PTR_IF(IS_ENABLED(CONFIG_DEBUG_FS), ptr) +/** * IIO_BACKEND_EX_INFO - Helper for an IIO extended channel attribute * @_name: Attribute name
@@ -81,6 +83,8 @@ enum iio_backend_sample_trigger {* @extend_chan_spec: Extend an IIO channel. * @ext_info_set: Extended info setter. * @ext_info_get: Extended info getter. +* @debugfs_print_chan_status: Print channel status into a buffer. +* @debugfs_reg_access: Read or write register value of backend. **/ struct iio_backend_ops {int (*enable)(struct iio_backend *back);
@@ -113,6 +117,11 @@ 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 (*debugfs_print_chan_status)(struct iio_backend *back, +unsigned int chan,char *buf, +size_t len); +int (*debugfs_reg_access)(struct iio_backend *back,unsigned int reg, +unsigned int writeval,unsigned int *readval); };/**
@@ -163,4 +172,9 @@ __devm_iio_backend_get_from_fwnode_lookup(struct device *dev,int devm_iio_backend_register (struct device *dev,const struct iio_backend_info *info,void *priv); +ssize_t iio_backend_debugfs_print_chan_status (struct iio_backend *back, +unsigned int chan,char *buf, +size_t len); +void iio_backend_debugfs_add (struct iio_backend *back, +struct iio_dev *indio_dev);#endif
Signature · 1 line
2.45.2
Nuno Sa
maintainerPATCH v2 3/8 iio: backend: add a modified prbs23 support
In reply to Nuno SaSupport ADI specific prb23 sequence that can be used both for calibrating or debugging digital interfaces.
--- include/linux/iio/backend.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/iio/backend.h +2 -0
@@ -56,6 +56,8 @@ enum iio_backend_test_pattern {IIO_BACKEND_NO_TEST_PATTERN ,/* modified prbs9 */ IIO_BACKEND_ADI_PRBS_9A =32 , +/* modified prbs23 */ +IIO_BACKEND_ADI_PRBS_23A , IIO_BACKEND_TEST_PATTERN_MAX };
Signature · 1 line
2.45.2
Nuno Sa
maintainerPATCH v2 4/8 iio: adc: adi-axi-adc: support modified prbs23
In reply to Nuno SaAdd support for configuring the prbs23 sequence.
--- drivers/iio/adc/adi-axi-adc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/iio/adc/adi-axi-adc.c +4 -0
@@ -199,6 +199,10 @@ static int axi_adc_test_pattern_set(struct iio_backend *back,return regmap_update_bits (st->regmap,ADI_AXI_ADC_REG_CHAN_CTRL_3 (chan),ADI_AXI_ADC_CHAN_PN_SEL_MASK ,FIELD_PREP (ADI_AXI_ADC_CHAN_PN_SEL_MASK ,0 )); +case IIO_BACKEND_ADI_PRBS_23A : +return regmap_update_bits (st->regmap,ADI_AXI_ADC_REG_CHAN_CTRL_3 (chan), +ADI_AXI_ADC_CHAN_PN_SEL_MASK , +FIELD_PREP (ADI_AXI_ADC_CHAN_PN_SEL_MASK ,1 ));default :return -EINVAL ; }
Signature · 1 line
2.45.2
Nuno Sa
maintainerPATCH v2 5/8 iio: adc: adi-axi-adc: split axi_adc_chan_status()
In reply to Nuno SaAdd a new axi_adc_read_chan_status() helper so we get the raw register value out of it.
This is in preparation of a future change where we really want to look into dedicated bits of the register.
--- drivers/iio/adc/adi-axi-adc.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/iio/adc/adi-axi-adc.c +14 -5
@@ -208,12 +208,10 @@ static int axi_adc_test_pattern_set(struct iio_backend *back, } } -static int axi_adc_chan_status (struct iio_backend *back,unsigned int chan, -bool *error) +static int axi_adc_read_chan_status (struct adi_axi_adc_state *st,unsigned int chan, +unsigned int *status) { -struct adi_axi_adc_state *st =iio_backend_get_priv (back);int ret; -u32 val;guard (mutex)(&st->lock);/* reset test bits by setting them */
@@ -225,7 +223,18 @@ static int axi_adc_chan_status(struct iio_backend *back, unsigned int chan,/* let's give enough time to validate or erroring the incoming pattern */ fsleep (1000 ); - ret =regmap_read (st->regmap,ADI_AXI_ADC_REG_CHAN_STATUS (chan), &val); +return regmap_read (st->regmap,ADI_AXI_ADC_REG_CHAN_STATUS (chan), + status); +} + +static int axi_adc_chan_status (struct iio_backend *back,unsigned int chan, +bool *error) +{ +struct adi_axi_adc_state *st =iio_backend_get_priv (back); +u32 val; +int ret; + + ret =axi_adc_read_chan_status (st, chan, &val);if (ret)return ret;
Signature · 1 line
2.45.2
Nuno Sa
maintainerPATCH v2 6/8 iio: adc: adi-axi-adc: implement backend debugfs interface
In reply to Nuno SaImplement debugfs options to read/write registers and print the channel status into a buffer (so we may know better the cause for errors) .
--- drivers/iio/adc/adi-axi-adc.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/iio/adc/adi-axi-adc.c +41 -0
@@ -61,6 +61,10 @@#define ADI_AXI_ADC_REG_CHAN_STATUS (c) (0x0404 + (c) * 0x40)#define ADI_AXI_ADC_CHAN_STAT_PN_MASK GENMASK(2, 1) +/* out of sync */ +#define ADI_AXI_ADC_CHAN_STAT_PN_OOS BIT(1) +/* spurious out of sync */ +#define ADI_AXI_ADC_CHAN_STAT_PN_ERR BIT(2)#define ADI_AXI_ADC_REG_CHAN_CTRL_3 (c) (0x0418 + (c) * 0x40)#define ADI_AXI_ADC_CHAN_PN_SEL_MASK GENMASK(19, 16)
@@ -246,6 +250,30 @@ static int axi_adc_chan_status(struct iio_backend *back, unsigned int chan,return 0 ; } +static int axi_adc_debugfs_print_chan_status (struct iio_backend *back, +unsigned int chan,char *buf, +size_t len) +{ +struct adi_axi_adc_state *st =iio_backend_get_priv (back); +u32 val; +int ret; + + ret =axi_adc_read_chan_status (st, chan, &val); +if (ret) +return ret; + +/* +* PN_ERR is cleared in case out of sync is set. Hence, no point in +* checking both bits. +*/ +if (val &ADI_AXI_ADC_CHAN_STAT_PN_OOS ) +return scnprintf (buf, len,"CH%u: Out of Sync.\n" , chan); +if (val &ADI_AXI_ADC_CHAN_STAT_PN_ERR ) +return scnprintf (buf, len,"CH%u: Spurious Out of Sync.\n" , chan); + +return scnprintf (buf, len,"CH%u: OK.\n" , chan); +} +static int axi_adc_chan_enable (struct iio_backend *back,unsigned int chan) {struct adi_axi_adc_state *st =iio_backend_get_priv (back);
@@ -280,6 +308,17 @@ static void axi_adc_free_buffer(struct iio_backend *back,iio_dmaengine_buffer_free (buffer); } +static int axi_adc_reg_access (struct iio_backend *back,unsigned int reg, +unsigned int writeval,unsigned int *readval) +{ +struct adi_axi_adc_state *st =iio_backend_get_priv (back); + +if (readval) +return regmap_read (st->regmap, reg, readval); + +return regmap_write (st->regmap, reg, writeval); +} +static const struct regmap_config axi_adc_regmap_config = { .val_bits =32 , .reg_bits =32 ,
@@ -298,6 +337,8 @@ static const struct iio_backend_ops adi_axi_adc_ops = { .iodelay_set = axi_adc_iodelays_set, .test_pattern_set = axi_adc_test_pattern_set, .chan_status = axi_adc_chan_status, + .debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access), + .debugfs_print_chan_status = iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status), };static const struct iio_backend_info adi_axi_adc_generic = {
Signature · 1 line
2.45.2
Nuno Sa
maintainerPATCH v2 7/8 iio: adc: ad9467: add backend test mode helpers
In reply to Nuno SaGroup the backend configurations to be done in preparing and stopping calibration in two new helpers analogous to ad9467_testmode_set(). This is in preparation for adding support for debugFS test_mode where we need similar configurations as in the calibration process.
--- drivers/iio/adc/ad9467.c | 67 ++++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 25 deletions(-)
drivers/iio/adc/ad9467.c +42 -25
@@ -494,11 +494,49 @@ static int ad9467_testmode_set(struct ad9467_state *st, unsigned int chan, AN877_ADC_TRANSFER_SYNC); } -static int ad9647_calibrate_prepare (struct ad9467_state *st) +static int ad9467_backend_testmode_on (struct ad9467_state *st, +unsigned int chan, +enum iio_backend_test_pattern pattern) {struct iio_backend_data_fmt data = { .enable = false, }; +int ret; + + ret =iio_backend_data_format_set (st->back, chan, &data); +if (ret) +return ret; + + ret =iio_backend_test_pattern_set (st->back, chan, pattern); +if (ret) +return ret; + +return iio_backend_chan_enable (st->back, chan); +} + +static int ad9467_backend_testmode_off (struct ad9467_state *st, +unsigned int chan) +{ +struct iio_backend_data_fmt data = { + .enable = true, + .sign_extend = true, + }; +int ret; + + ret =iio_backend_chan_disable (st->back, chan); +if (ret) +return ret; + + ret =iio_backend_test_pattern_set (st->back, chan, +IIO_BACKEND_NO_TEST_PATTERN ); +if (ret) +return ret; + +return iio_backend_data_format_set (st->back, chan, &data); +} + +static int ad9647_calibrate_prepare (struct ad9467_state *st) +{unsigned int c;int ret;
@@ -511,16 +549,8 @@ static int ad9647_calibrate_prepare(struct ad9467_state *st)if (ret)return ret; - ret =iio_backend_data_format_set (st->back, c, &data); -if (ret) -return ret; - - ret =iio_backend_test_pattern_set (st->back, c, -IIO_BACKEND_ADI_PRBS_9A ); -if (ret) -return ret; - - ret =iio_backend_chan_enable (st->back, c); + ret =ad9467_backend_testmode_on (st, c, +IIO_BACKEND_ADI_PRBS_9A );if (ret)return ret; }
@@ -601,24 +631,11 @@ static int ad9467_calibrate_apply(struct ad9467_state *st, unsigned int val)static int ad9647_calibrate_stop (struct ad9467_state *st) { -struct iio_backend_data_fmt data = { - .sign_extend = true, - .enable = true, - };unsigned int c, mode;int ret;for (c =0 ; c < st->info->num_channels; c++) { - ret =iio_backend_chan_disable (st->back, c); -if (ret) -return ret; - - ret =iio_backend_test_pattern_set (st->back, c, -IIO_BACKEND_NO_TEST_PATTERN ); -if (ret) -return ret; - - ret =iio_backend_data_format_set (st->back, c, &data); + ret =ad9467_backend_testmode_off (st, c);if (ret)return ret;
Signature · 1 line
2.45.2
Nuno Sa
maintainerPATCH v2 8/8 iio: adc: ad9467: add digital interface test to debugfs
In reply to Nuno SaOne useful thing to do (in case of problems) in this high speed devices with digital interfaces is to try different test patterns to see if the interface is working properly (and properly calibrated). Hence add this to debugfs.
On top of this, for some test patterns, the backend may have a matching validator block which can be helpful in identifying possible issues. For the other patterns some test equipment must be used so one can look into the signal and see how it looks like.
Hence, we also add the backend debugfs interface with iio_backend_debugfs_add().
--- drivers/iio/adc/ad9467.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+)
drivers/iio/adc/ad9467.c +188 -0
@@ -15,6 +15,7 @@#include <linux/kernel.h> #include <linux/slab.h> #include <linux/spi/spi.h> +#include <linux/seq_file.h> #include <linux/err.h> #include <linux/delay.h> #include <linux/gpio/consumer.h>
@@ -136,6 +137,8 @@ struct ad9467_chip_info {unsigned int num_channels;const unsigned int (*scale_table)[2 ];int num_scales; +unsigned long test_mask; +unsigned int test_mask_len;unsigned long max_rate;unsigned int default_output_mode;unsigned int vref_mask;
@@ -147,11 +150,19 @@ struct ad9467_chip_info {bool has_dco_invert; }; +struct ad9467_chan_test_mode { +struct ad9467_state *st; +unsigned int idx; +u8 mode; +}; +struct ad9467_state {const struct ad9467_chip_info *info;struct iio_backend *back;struct spi_device *spi;struct clk *clk; +/* used for debugfs */ +struct ad9467_chan_test_mode *chan_test;unsigned int output_mode;unsigned int (*scales)[2 ];/*
@@ -308,6 +319,23 @@ static const struct iio_chan_spec ad9652_channels[] = { AD9467_CHAN(1, BIT(IIO_CHAN_INFO_SCALE), 1, 16, 's'), }; +static const char *const ad9467_test_modes[] = { + [AN877_ADC_TESTMODE_OFF ] ="off" , + [AN877_ADC_TESTMODE_MIDSCALE_SHORT ] ="midscale_short" , + [AN877_ADC_TESTMODE_POS_FULLSCALE ] ="pos_fullscale" , + [AN877_ADC_TESTMODE_NEG_FULLSCALE ] ="neg_fullscale" , + [AN877_ADC_TESTMODE_ALT_CHECKERBOARD ] ="checkerboard" , + [AN877_ADC_TESTMODE_PN23_SEQ ] ="prbs23" , + [AN877_ADC_TESTMODE_PN9_SEQ ] ="prbs9" , + [AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE ] ="one_zero_toggle" , + [AN877_ADC_TESTMODE_USER ] ="user" , + [AN877_ADC_TESTMODE_BIT_TOGGLE ] ="bit_toggle" , + [AN877_ADC_TESTMODE_SYNC ] ="sync" , + [AN877_ADC_TESTMODE_ONE_BIT_HIGH ] ="one_bit_high" , + [AN877_ADC_TESTMODE_MIXED_BIT_FREQUENCY ] ="mixed_bit_frequency" , + [AN877_ADC_TESTMODE_RAMP ] ="ramp" , +}; +static const struct ad9467_chip_info ad9467_chip_tbl = { .name ="ad9467" , .id =CHIPID_AD9467 ,
@@ -317,6 +345,9 @@ static const struct ad9467_chip_info ad9467_chip_tbl = { .channels = ad9467_channels, .num_channels = ARRAY_SIZE(ad9467_channels), .test_points = AD9647_MAX_TEST_POINTS, + .test_mask =GENMASK (AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE , + AN877_ADC_TESTMODE_OFF), + .test_mask_len = AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE + 1, .default_output_mode = AD9467_DEF_OUTPUT_MODE, .vref_mask = AD9467_REG_VREF_MASK, .num_lanes = 8,
@@ -331,6 +362,8 @@ static const struct ad9467_chip_info ad9434_chip_tbl = { .channels = ad9434_channels, .num_channels = ARRAY_SIZE(ad9434_channels), .test_points = AD9647_MAX_TEST_POINTS, + .test_mask = GENMASK(AN877_ADC_TESTMODE_USER, AN877_ADC_TESTMODE_OFF), + .test_mask_len = AN877_ADC_TESTMODE_USER + 1, .default_output_mode = AD9434_DEF_OUTPUT_MODE, .vref_mask = AD9434_REG_VREF_MASK, .num_lanes = 6,
@@ -345,6 +378,9 @@ static const struct ad9467_chip_info ad9265_chip_tbl = { .channels = ad9467_channels, .num_channels = ARRAY_SIZE(ad9467_channels), .test_points = AD9647_MAX_TEST_POINTS, + .test_mask =GENMASK (AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE , + AN877_ADC_TESTMODE_OFF), + .test_mask_len = AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE + 1, .default_output_mode = AD9265_DEF_OUTPUT_MODE, .vref_mask = AD9265_REG_VREF_MASK, .has_dco = true,
@@ -360,6 +396,9 @@ static const struct ad9467_chip_info ad9643_chip_tbl = { .channels = ad9643_channels, .num_channels = ARRAY_SIZE(ad9643_channels), .test_points = AD9647_MAX_TEST_POINTS, + .test_mask =BIT (AN877_ADC_TESTMODE_RAMP ) | + GENMASK(AN877_ADC_TESTMODE_MIXED_BIT_FREQUENCY, AN877_ADC_TESTMODE_OFF), + .test_mask_len = AN877_ADC_TESTMODE_RAMP + 1, .vref_mask = AD9643_REG_VREF_MASK, .has_dco = true, .has_dco_invert = true,
@@ -375,6 +414,9 @@ static const struct ad9467_chip_info ad9649_chip_tbl = { .channels = ad9649_channels, .num_channels = ARRAY_SIZE(ad9649_channels), .test_points = AD9649_TEST_POINTS, + .test_mask =GENMASK (AN877_ADC_TESTMODE_MIXED_BIT_FREQUENCY , + AN877_ADC_TESTMODE_OFF), + .test_mask_len = AN877_ADC_TESTMODE_MIXED_BIT_FREQUENCY + 1, .has_dco = true, .has_dco_invert = true, .dco_en = AN877_ADC_DCO_DELAY_ENABLE,
@@ -389,6 +431,9 @@ static const struct ad9467_chip_info ad9652_chip_tbl = { .channels = ad9652_channels, .num_channels = ARRAY_SIZE(ad9652_channels), .test_points = AD9647_MAX_TEST_POINTS, + .test_mask = GENMASK(AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE, + AN877_ADC_TESTMODE_OFF), + .test_mask_len = AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE + 1, .vref_mask = AD9652_REG_VREF_MASK, .has_dco = true, };
@@ -933,6 +978,128 @@ static int ad9467_iio_backend_get(struct ad9467_state *st)return -ENODEV ; } +static int ad9467_test_mode_available_show (struct seq_file *s,void *ignored) +{ +struct ad9467_state *st = s->private; +unsigned int bit; + +for_each_set_bit (bit, &st->info->test_mask, st->info->test_mask_len) +seq_printf (s,"%s\n" , ad9467_test_modes[bit]); + +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (ad9467_test_mode_available); + +static ssize_t ad9467_chan_test_mode_read (struct file *file, +char __user *userbuf,size_t count, +loff_t *ppos) +{ +struct ad9467_chan_test_mode *chan = file->private_data; +struct ad9467_state *st = chan->st; +char buf[128 ] = {0 }; +size_t len; +int ret; + +if (chan->mode ==AN877_ADC_TESTMODE_PN9_SEQ || + chan->mode ==AN877_ADC_TESTMODE_PN23_SEQ ) { + len =scnprintf (buf,sizeof (buf),"Running \"%s\" Test:\n\t" , + ad9467_test_modes[chan->mode]); + + ret =iio_backend_debugfs_print_chan_status (st->back, chan->idx, + buf + len, +sizeof (buf) - len); +if (ret <0 ) +return ret; + len += ret; + }else if (chan->mode ==AN877_ADC_TESTMODE_OFF ) { + len =scnprintf (buf,sizeof (buf),"No test Running...\n" ); + }else { + len =scnprintf (buf,sizeof (buf),"Running \"%s\" Test on CH:%u\n" , + ad9467_test_modes[chan->mode], chan->idx); + } + +return simple_read_from_buffer (userbuf, count, ppos, buf, len); +} + +static ssize_t ad9467_chan_test_mode_write (struct file *file, +const char __user *userbuf, +size_t count,loff_t *ppos) +{ +struct ad9467_chan_test_mode *chan = file->private_data; +struct ad9467_state *st = chan->st; +char test_mode[32 ] = {0 }; +unsigned int mode; +int ret; + + ret =simple_write_to_buffer (test_mode,sizeof (test_mode) -1 , ppos, + userbuf, count); +if (ret <0 ) +return ret; + +for_each_set_bit (mode, &st->info->test_mask, st->info->test_mask_len) { +if (sysfs_streq (test_mode, ad9467_test_modes[mode])) +break ; + } + +if (mode == st->info->test_mask_len) +return -EINVAL ; + +guard (mutex)(&st->lock); + +if (mode ==AN877_ADC_TESTMODE_OFF ) { +unsigned int out_mode; + +if (chan->mode ==AN877_ADC_TESTMODE_PN9_SEQ || + chan->mode ==AN877_ADC_TESTMODE_PN23_SEQ ) { + ret =ad9467_backend_testmode_off (st, chan->idx); +if (ret) +return ret; + } + + ret =ad9467_testmode_set (st, chan->idx, mode); +if (ret) +return ret; + + out_mode = st->info->default_output_mode |AN877_ADC_OUTPUT_MODE_TWOS_COMPLEMENT ; + ret =ad9467_outputmode_set (st, out_mode); +if (ret) +return ret; + }else { + ret =ad9467_outputmode_set (st, st->info->default_output_mode); +if (ret) +return ret; + + ret =ad9467_testmode_set (st, chan->idx, mode); +if (ret) +return ret; + +/* some patterns have a backend matching monitoring block */ +if (mode ==AN877_ADC_TESTMODE_PN9_SEQ ) { + ret =ad9467_backend_testmode_on (st, chan->idx, +IIO_BACKEND_ADI_PRBS_9A ); +if (ret) +return ret; + }else if (mode ==AN877_ADC_TESTMODE_PN23_SEQ ) { + ret =ad9467_backend_testmode_on (st, chan->idx, +IIO_BACKEND_ADI_PRBS_23A ); +if (ret) +return ret; + } + } + + chan->mode = mode; + +return count; +} + +static const struct file_operations ad9467_chan_test_mode_fops = { + .open = simple_open, + .read = ad9467_chan_test_mode_read, + .write = ad9467_chan_test_mode_write, + .llseek = default_llseek, + .owner =THIS_MODULE , +}; +static ssize_t ad9467_dump_calib_table (struct file *file,char __user *userbuf,size_t count,loff_t *ppos)
@@ -971,12 +1138,33 @@ static void ad9467_debugfs_init(struct iio_dev *indio_dev) {struct dentry *d =iio_get_debugfs_dentry (indio_dev);struct ad9467_state *st =iio_priv (indio_dev); +char attr_name[32 ]; +unsigned int chan;if (!IS_ENABLED (CONFIG_DEBUG_FS ))return ; + st->chan_test =devm_kcalloc (&st->spi->dev, st->info->num_channels, +sizeof (*st->chan_test),GFP_KERNEL ); +if (!st->chan_test) +return ; +debugfs_create_file ("calibration_table_dump" ,0400 , d, st, &ad9467_calib_table_fops); + +for (chan =0 ; chan < st->info->num_channels; chan++) { +snprintf (attr_name,sizeof (attr_name),"in_voltage%u_test_mode" , + chan); + st->chan_test[chan].idx = chan; + st->chan_test[chan].st = st; +debugfs_create_file (attr_name,0600 , d, &st->chan_test[chan], + &ad9467_chan_test_mode_fops); + } + +debugfs_create_file ("in_voltage_test_mode_available" ,0400 , d, st, + &ad9467_test_mode_available_fops); + +iio_backend_debugfs_add (st->back, indio_dev); }static int ad9467_probe (struct spi_device *spi)
Signature · 1 line
2.45.2
Jonathan Cameron
maintainerRe: [PATCH v2 8/8] iio: adc: ad9467: add digital interface test to debugfs
Quoted 12 lines · On Fri, 02 Aug 2024 16:27:06 +0200 Nuno Sa via B4 Relay…
From: Nuno Sa <[email protected]>
One useful thing to do (in case of problems) in this high speed devices with digital interfaces is to try different test patterns to see if the interface is working properly (and properly calibrated). Hence add this to debugfs.
On top of this, for some test patterns, the backend may have a matching validator block which can be helpful in identifying possible issues. For the other patterns some test equipment must be used so one can look into the signal and see how it looks like.
Quoted 4 lines
Hence, we also add the backend debugfs interface with
iio_backend_debugfs_add().Signed-off-by Nuno Sa <[email protected]>
I'll apply the series, but I would like a docs update for the debugfs files this patch adds. That can be a follow up patch.
Jonathan
Re: [PATCH v2 8/8] iio: adc: ad9467: add digital interface test to debugfs
Quoted 15 lines · Jonathan Cameron
Quoted 12 lines · On Fri, 02 Aug 2024 16:27:06 +0200 Nuno Sa via B4 Relay…
From: Nuno Sa <[email protected]>
One useful thing to do (in case of problems) in this high speed devices with digital interfaces is to try different test patterns to see if the interface is working properly (and properly calibrated). Hence add this to debugfs.
On top of this, for some test patterns, the backend may have a matching validator block which can be helpful in identifying possible issues. For the other patterns some test equipment must be used so one can look into the signal and see how it looks like.
Quoted 8 lines
Quoted 4 lines
Hence, we also add the backend debugfs interface with
iio_backend_debugfs_add().Signed-off-by Nuno Sa <[email protected]>I'll apply the series, but I would like a docs update for the debugfs files this patch adds. That can be a follow up patch.
Jonathan
will do
- Nuno Sá
Quoted 15 lines · On Fri, 02 Aug 2024 16:26:58 +0200 Nuno Sa via B4 Relay…
This is the second version of the series. I ended up trying the new directory route and think it does look nice and more future proof. Biggest change is the first patch where we now pass an info like structure to
devm_iio_backend_register(). Again, this is likely also a more future proof approach and we would likely need it sooner or later (one usage I see is for backends to pass in some constant information that could be consumed from frontends when doingbackend_get())v1:
* https://lore.kernel.org/linux-iio/20240709-dev-iio-backend-add-debugfs-v1-0-fb4b8f2373c7@analog.com/v2:
* Patch 1:
- New patch;
Quoted 6 lines
* Patch 2:
- Added backendY directory with thedirect_reg_accessand nameattributes;- Get the backend name directly from the backend driver;
- Get the backend index from backend-names FW property;
- Added debugfs-iio-backend to the ABI docs.
Should also have docs for the ad9467 specific debugfs files.
Please add those in a follow up patch.
Applied to the togreg branch of iio.git and pushed out as testing for all the normal reasons.
Thanks,
Jonathan
Quoted 29 lines
---
Nuno Sa (8):
iio: backend: introduce structiio_backend_info
iio: backend: add debugFs interface
iio: backend: add a modified prbs23 support
iio: adc: adi-axi-adc: support modified prbs23
iio: adc: adi-axi-adc: splitaxi_adc_chan_status()
iio: adc: adi-axi-adc: implement backend debugfs interface
iio: adc: ad9467: add backend test mode helpers
iio: adc: ad9467: add digital interface test to debugfsDocumentation/ABI/testing/debugfs-iio-backend | 20 ++ MAINTAINERS | 1 + drivers/iio/adc/ad9467.c | 255 +++++++++++++++++++++++--- drivers/iio/adc/adi-axi-adc.c | 71 ++++++- drivers/iio/dac/adi-axi-dac.c | 7 +- drivers/iio/industrialio-backend.c | 155 +++++++++++++++- include/linux/iio/backend.h | 28 ++- 7 files changed, 499 insertions(+), 38 deletions(-)---
base-commit:168bed989d651794d03638e1f7f7b5a800a6f425
change-id: 20240802-dev-iio-backend-add-debugfs-0b13bb5a5b37 --Thanks!
- Nuno Sá