Skip to contentSkip to conversation

iio: adc: xilinx-xadc: Add I2C interface support for System Management Wizard

PATCH In review Sai Krishna Potthuri 6 participants 14 messages Mar 23 – Mar 27

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover iio: adc: xilinx-xadc: Add I2C interface support for System Management Wizard

The existing driver only supported AXI memory-mapped access to the System Management Wizard IP. This series extends the driver to support I2C-based access, which is particularly useful for System Controller usecases.

Key Changes:
- Split the xilinx-xadc-core.c file into two files(xilinx-xadc-core.c and xilinx-xadc-platform.c)
- Add required helper functions and callbacks
- Add channel configuration via callback mechanism
- New I2C driver for UltraScale+ System Management Wizard for basic voltage and temperature monitoring
- Converted text binding to YAML schema format

Note: We are working on x86 platform support where fixed channel configuration is used(no DT support). The .setup_channels() function pointer introduced in patch 2/4 enables different channel configuration approaches for various platforms.

Changes in v2:
-> 1/4 - Split the xilinx-xadc-core.c file into two files
xilinx-xadc-core.c and xilinx-xadc-platform.c(comments from Andy).
-> 2/4 - Referred as .setup_channels instead of setup_channels. -> 3/4 - Created separate functions for i2c read and write.
- Created separate file for i2c interface handling.
-> 4/4(comments from Krzysztof)
- Removed $defs and use it directly under xlnx,channels.
- Documented the error information in the commit message due to vendor prefix properties.
- Kept only one example as there is not much differences.

Sai Krishna Potthuri (4):
iio: adc: xilinx-xadc: Split driver into core and platform files
iio: adc: xilinx-xadc: Add .setup_channels() to struct xadc_ops
iio: adc: xilinx-xadc: Add I2C interface support
dt-bindings: iio: adc: xlnx,axi-xadc: convert to DT schema

 .../bindings/iio/adc/xilinx-xadc.txt          | 141 ---
 .../bindings/iio/adc/xlnx,axi-xadc.yaml       | 154 ++++
 drivers/iio/adc/Kconfig                       |  23 +-
 drivers/iio/adc/Makefile                      |   6 +-
 drivers/iio/adc/xilinx-xadc-core.c            | 814 +++---------------
 drivers/iio/adc/xilinx-xadc-i2c.c             | 215 +++++
 drivers/iio/adc/xilinx-xadc-platform.c        | 668 ++++++++++++++
 drivers/iio/adc/xilinx-xadc.h                 |  33 +
 8 files changed, 1193 insertions(+), 861 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/iio/adc/xilinx-xadc.txt
 create mode 100644 Documentation/devicetree/bindings/iio/adc/xlnx,axi-xadc.yaml
 create mode 100644 drivers/iio/adc/xilinx-xadc-i2c.c
 create mode 100644 drivers/iio/adc/xilinx-xadc-platform.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/4 iio: adc: xilinx-xadc: Split driver into core and platform files

Split the xilinx-xadc-core.c into separate core and platform specific files to prepare for I2C interface support.

xilinx-xadc-core.c is reorganized as follows:
xilinx-xadc-core.c:
- Platform-independent IIO/ADC operations
- Channel definitions and management
- Buffer and trigger management
- Device tree parsing

xilinx-xadc-platform.c:
- ZYNQ platform (FIFO-based) register access and interrupt handling
- AXI platform (memory-mapped) register access and interrupt handling
- Platform-specific setup and configuration
- Platform device probe function

Update Kconfig to introduce XILINX_XADC_CORE as a helper module selected by XILINX_XADC and update Makefile to build the split modules:
- xilinx-xadc-common.o (core + events)
- xilinx-xadc-platform.o (platform-specific)

Reorganized the code and No behavioral changes.

---
 drivers/iio/adc/Kconfig                |   8 +-
 drivers/iio/adc/Makefile               |   5 +-
 drivers/iio/adc/xilinx-xadc-core.c     | 790 +++----------------------
 drivers/iio/adc/xilinx-xadc-platform.c | 665 +++++++++++++++++++++
 drivers/iio/adc/xilinx-xadc.h          |  30 +
 5 files changed, 779 insertions(+), 719 deletions(-)
 create mode 100644 drivers/iio/adc/xilinx-xadc-platform.c
drivers/iio/adc/Kconfig +6 -2
index ea3ba1397392..a4a7556f4016 100644
@@ -1744,11 +1744,15 @@ config VIPERBOARD_ADC
 	  To compile this driver as a module, choose M here: the module will be
 	  called viperboard_adc.
 
+config XILINX_XADC_CORE
+	tristate
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+
 config XILINX_XADC
 	tristate "Xilinx XADC driver"
 	depends on HAS_IOMEM
-	select IIO_BUFFER
-	select IIO_TRIGGERED_BUFFER
+	select XILINX_XADC_CORE
 	help
 	  Say yes here to have support for the Xilinx 7 Series XADC or
 	  UltraScale/UltraScale+ System Management Wizard.
drivers/iio/adc/Makefile +3 -2
index 09ae6edb2650..1b05176f0098 100644
@@ -154,5 +154,6 @@ obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o
 obj-$(CONFIG_VF610_ADC) += vf610_adc.o
 obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
 obj-$(CONFIG_XILINX_AMS) += xilinx-ams.o
-xilinx-xadc-y := xilinx-xadc-core.o xilinx-xadc-events.o
-obj-$(CONFIG_XILINX_XADC) += xilinx-xadc.o
+xilinx-xadc-common-y := xilinx-xadc-core.o xilinx-xadc-events.o
+obj-$(CONFIG_XILINX_XADC_CORE) += xilinx-xadc-common.o
+obj-$(CONFIG_XILINX_XADC) += xilinx-xadc-platform.o
drivers/iio/adc/xilinx-xadc-core.c +75 -715

931 lines not on this page · raw message

drivers/iio/adc/xilinx-xadc-platform.c new file +665 -0

665 lines not on this page · raw message

drivers/iio/adc/xilinx-xadc.h +30 -0
index b4d9d4683117..a2d208fbd13b 100644
@@ -211,4 +211,34 @@ static inline int xadc_write_adc_reg(struct xadc *xadc, unsigned int reg,
 #define XADC_THRESHOLD_VCCPAUX_MIN	0xe
 #define XADC_THRESHOLD_VCCODDR_MIN	0xf
 
+/*
+ * The XADC hardware supports a samplerate of up to 1MSPS. Unfortunately it does
+ * not have a hardware FIFO. Which means an interrupt is generated for each
+ * conversion sequence. At 1MSPS sample rate the CPU in ZYNQ7000 is completely
+ * overloaded by the interrupts that it soft-lockups. For this reason the driver
+ * limits the maximum samplerate 150kSPS. At this rate the CPU is fairly busy,
+ * but still responsive.
+ */
+#define XADC_MAX_SAMPLERATE 150000
+
+#define XADC_FLAGS_BUFFERED BIT(0)
+#define XADC_FLAGS_IRQ_OPTIONAL BIT(1)
+
+/* AXI register definitions needed by core */
+#define XADC_AXI_REG_IPISR		0x60
+#define XADC_AXI_REG_IPIER		0x68
+#define XADC_AXI_INT_EOS		BIT(4)
+
+void xadc_write_reg(struct xadc *xadc, unsigned int reg, uint32_t val);
+void xadc_read_reg(struct xadc *xadc, unsigned int reg, uint32_t *val);
+struct iio_dev *xadc_device_setup(struct device *dev, int size,
+				  const struct xadc_ops **ops);
+int xadc_device_configure(struct device *dev, struct iio_dev *indio_dev,
+			  int irq, unsigned int *conf0, unsigned int *bipolar_mask);
+int xadc_read_samplerate(struct xadc *xadc);
+int xadc_write_samplerate(struct xadc *xadc, int val);
+int xadc_setup_buffer_and_triggers(struct device *dev, struct iio_dev *indio_dev,
+				   struct xadc *xadc, int irq);
+int xadc_postdisable(struct iio_dev *indio_dev);
+
 #endif
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v2 1/4] iio: adc: xilinx-xadc: Split driver into core and platform files

Quoted 22 lines · Sai Krishna Potthuri

Split the xilinx-xadc-core.c into separate core and platform specific files to prepare for I2C interface support.

xilinx-xadc-core.c is reorganized as follows:
xilinx-xadc-core.c:
- Platform-independent IIO/ADC operations
- Channel definitions and management
- Buffer and trigger management
- Device tree parsing

xilinx-xadc-platform.c:
- ZYNQ platform (FIFO-based) register access and interrupt handling
- AXI platform (memory-mapped) register access and interrupt handling
- Platform-specific setup and configuration
- Platform device probe function

Update Kconfig to introduce XILINX_XADC_CORE as a helper module selected by XILINX_XADC and update Makefile to build the split modules:
- xilinx-xadc-common.o (core + events)
- xilinx-xadc-platform.o (platform-specific)

Reorganized the code and No behavioral changes.

...

drivers/iio/adc/xilinx-xadc-core.c line 42

Quoted 13 lines
drivers/iio/adc/xilinx-xadc-core.c +4 -2
+void xadc_write_reg(struct xadc *xadc, unsigned int reg, uint32_t val)
 {
 	writel(val, xadc->base + reg);
 }
+EXPORT_SYMBOL_GPL(xadc_write_reg);
 
-static void xadc_read_reg(struct xadc *xadc, unsigned int reg,
-	uint32_t *val)
+void xadc_read_reg(struct xadc *xadc, unsigned int reg, uint32_t *val)
 {
 	*val = readl(xadc->base + reg);
 }
+EXPORT_SYMBOL_GPL(xadc_read_reg);

Use namespace.

...

drivers/iio/adc/xilinx-xadc-core.c line 44

Quoted 3 lines
drivers/iio/adc/xilinx-xadc-core.c +1 -2
-static int _xadc_update_adc_reg(struct xadc *xadc, unsigned int reg,
-	uint16_t mask, uint16_t val)
+static int _xadc_update_adc_reg(struct xadc *xadc, unsigned int reg, u16 mask, u16 val)

This is unrelated. Make it a separate change "Switch to use kernel types" or alike.

...

drivers/iio/adc/xilinx-xadc-core.c static unsigned long xadc_get_dclk_rate(struct xadc *xadc) · line 72

Quoted 3 lines
drivers/iio/adc/xilinx-xadc-core.c +1 -2
-static int xadc_update_scan_mode(struct iio_dev *indio_dev,
-	const unsigned long *mask)
+static int xadc_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *mask)

This is unrelated indentation change. Either drop or move to a separate patch.

...

drivers/iio/adc/xilinx-xadc-core.c static unsigned long xadc_get_dclk_rate(struct xadc *xadc) · line 76

Quoted 4 lines
drivers/iio/adc/xilinx-xadc-core.c +1 -1
 	struct xadc *xadc = iio_priv(indio_dev);
-	size_t n;
 	void *data;
+	size_t n;

Ditto.

...

drivers/iio/adc/xilinx-xadc-core.c static irqreturn_t xadc_trigger_handler(int irq, void *p) · line 150

Quoted 8 lines

static int xadc_trigger_set_state(struct iio_trigger *trigger, bool state) {

drivers/iio/adc/xilinx-xadc-core.c +1 -2
 	struct xadc *xadc = iio_trigger_get_drvdata(trigger);
+	unsigned int convst, val;
 	unsigned long flags;
-	unsigned int convst;
-	unsigned int val;
 	int ret = 0;

This shouldn't be done at all, one variable per line is fine and readable.

...

drivers/iio/adc/xilinx-xadc-core.c static int xadc_trigger_set_state(struct iio_trigger *trigger, bool state) · line 167

Quoted 3 lines
drivers/iio/adc/xilinx-xadc-core.c +1 -1
 		ret = _xadc_update_adc_reg(xadc, XADC_REG_CONF1, XADC_CONF0_EC,
-					convst);
+					   convst);

Separate patch for indentation.

...

drivers/iio/adc/xilinx-xadc-core.c static const struct iio_trigger_ops xadc_trigger_ops = { · line 194

Quoted 3 lines
drivers/iio/adc/xilinx-xadc-core.c +1 -2
-static struct iio_trigger *xadc_alloc_trigger(struct iio_dev *indio_dev,
-	const char *name)
+static struct iio_trigger *xadc_alloc_trigger(struct iio_dev *indio_dev, const char *name)

Ditto and anything similar should go to a separate patch.

...

drivers/iio/adc/xilinx-xadc-core.c static int xadc_get_seq_mode(struct xadc *xadc, unsigned long scan_mode)

Quoted 9 lines
drivers/iio/adc/xilinx-xadc-core.c +2 -2
-static int xadc_postdisable(struct iio_dev *indio_dev)
+int xadc_postdisable(struct iio_dev *indio_dev)
 {
 	struct xadc *xadc = iio_priv(indio_dev);
 	unsigned long scan_mask;
 	int ret;
 
-	int i;
+	u32 i;

Why?

Quoted 3 lines
drivers/iio/adc/xilinx-xadc-core.c +0 -0
 	scan_mask = 1; /* Run calibration as part of the sequence */
 	for (i = 0; i < indio_dev->num_channels; i++)

...

Quoted 1 line

+EXPORT_SYMBOL_GPL(xadc_postdisable);

Add namespace.

...

Quoted 1 line

+EXPORT_SYMBOL_GPL(xadc_read_samplerate);

Ditto and so on...

...

drivers/iio/adc/xilinx-xadc-core.c static int xadc_read_raw(struct iio_dev *indio_dev, · line 429

Quoted 3 lines
drivers/iio/adc/xilinx-xadc-core.c +2 -1
-static int xadc_write_samplerate(struct xadc *xadc, int val)
+int xadc_setup_buffer_and_triggers(struct device *dev, struct iio_dev *indio_dev,
+				   struct xadc *xadc, int irq)

At this time do you need all three first parameters? I think it may be two or even one.

Quoted 4 lines
drivers/iio/adc/xilinx-xadc-core.c +4 -0
+{
+	int ret;
+
+	if (!(xadc->ops->flags & XADC_FLAGS_BUFFERED))

drivers/iio/adc/xilinx-xadc-core.c static int xadc_read_raw(struct iio_dev *indio_dev, · line 443

Quoted 10 lines
drivers/iio/adc/xilinx-xadc-core.c +9 -0
+		return 0;
+
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      &iio_pollfunc_store_time,
+					      &xadc_trigger_handler,
+					      &xadc_buffer_ops);
+	if (ret)
+		return ret;
 
+	if (irq > 0) {
	/* The feature is optional */
	if (irq < 0)
		return 0;

drivers/iio/adc/xilinx-xadc-core.c static int xadc_read_raw(struct iio_dev *indio_dev, · line 456

Quoted 13 lines
drivers/iio/adc/xilinx-xadc-core.c +13 -0
+		xadc->convst_trigger = xadc_alloc_trigger(indio_dev, "convst");
+		if (IS_ERR(xadc->convst_trigger))
+			return PTR_ERR(xadc->convst_trigger);
+
+		xadc->samplerate_trigger = xadc_alloc_trigger(indio_dev,
+							      "samplerate");
+		if (IS_ERR(xadc->samplerate_trigger))
+			return PTR_ERR(xadc->samplerate_trigger);
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(xadc_setup_buffer_and_triggers);

Namespace.

...

drivers/iio/adc/xilinx-xadc-core.c static int xadc_parse_dt(struct iio_dev *indio_dev, unsigned int *conf, int irq) · line 767

Quoted 5 lines
drivers/iio/adc/xilinx-xadc-core.c +1 -1
-static const char * const xadc_type_names[] = {
+const char * const xadc_type_names[] = {
 	[XADC_TYPE_S7] = "xadc",
 	[XADC_TYPE_US] = "xilinx-system-monitor",
 };

Why this change without export? Is it fine?

...

drivers/iio/adc/xilinx-xadc-core.c static int xadc_parse_dt(struct iio_dev *indio_dev, unsigned int *conf, int irq) · line 776

Quoted 4 lines
drivers/iio/adc/xilinx-xadc-core.c +3 -0
+	*ops = device_get_match_data(dev);
 
+	if (!*ops)
+		return ERR_PTR(-ENODEV);

Just drop it. we expect driver to have it.

...

drivers/iio/adc/xilinx-xadc-platform.c line 19

Quoted 7 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +6 -0
+#include <linux/clk.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
 
+#include <linux/kernel.h>

No driver should use this header (there might be rare exceptions, but not here).

Quoted 3 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +3 -0
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>

...

Quoted 1 line

+static const unsigned int XADC_ZYNQ_UNMASK_TIMEOUT = 500;

Unit suffix?

...

drivers/iio/adc/xilinx-xadc-platform.c line 44

Quoted 3 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +2 -0
+#define XADC_ZYNQ_CFG_CFIFOTH_MASK	(0xf << 20)
 
+#define XADC_ZYNQ_CFG_DFIFOTH_MASK	(0xf << 16)

Yeah, these all _MASK (here and elsewhere) should use GENMASK().

...

Quoted 1 line

+static void xadc_zynq_write_fifo(struct xadc *xadc, uint32_t *cmd, unsigned int n)

Why not u32?

drivers/iio/adc/xilinx-xadc-platform.c line 112

Quoted 4 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +4 -0
+{
+	unsigned int i;
+
+	for (i = 0; i < n; i++)

Can be

for (unsigned int i = 0; i < n; i++)

Quoted 2 lines
(quoted diff) +2 -0
+		xadc_write_reg(xadc, XADC_ZYNQ_REG_CFIFO, cmd[i]);
+}

...

drivers/iio/adc/xilinx-xadc-platform.c line 120

Quoted 5 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +5 -0
+static void xadc_zynq_drain_fifo(struct xadc *xadc)
+{
+	u32 status, tmp;
+
+	xadc_read_reg(xadc, XADC_ZYNQ_REG_STATUS, &status);
	/* Needs a comment explaining why there will be no infinite loop */
Quoted 5 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +5 -0
+	while (!(status & XADC_ZYNQ_STATUS_DFIFOE)) {
+		xadc_read_reg(xadc, XADC_ZYNQ_REG_DFIFO, &tmp);
+		xadc_read_reg(xadc, XADC_ZYNQ_REG_STATUS, &status);
+	}
+}

...

drivers/iio/adc/xilinx-xadc-platform.c line 131

Quoted 4 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +4 -0
+static void xadc_zynq_update_intmsk(struct xadc *xadc, unsigned int mask, unsigned int val)
+{
+	xadc->zynq_intmask &= ~mask;
+	xadc->zynq_intmask |= val;

Standard pattern is to have it on a single line

	xadc->zynq_intmask = (xadc->zynq_intmask & ~mask) | (val & mask);
Quoted 2 lines
(quoted diff) +2 -0
+	xadc_write_reg(xadc, XADC_ZYNQ_REG_INTMSK, xadc->zynq_intmask | xadc->zynq_masked_alarm);
+}

...

drivers/iio/adc/xilinx-xadc-platform.c line 141

Quoted 6 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +6 -0
+static int xadc_zynq_write_adc_reg(struct xadc *xadc, unsigned int reg, uint16_t val)
+{
+	u32 cmd[1], tmp;
+	int ret;
+
+	spin_lock_irq(&xadc->lock);

Are you going to use cleanup.h?

Quoted 10 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +10 -0
+	xadc_zynq_update_intmsk(xadc, XADC_ZYNQ_INT_DFIFO_GTH, XADC_ZYNQ_INT_DFIFO_GTH);
+
+	reinit_completion(&xadc->completion);
+
+	cmd[0] = XADC_ZYNQ_CMD(XADC_ZYNQ_CMD_WRITE, reg, val);
+	xadc_zynq_write_fifo(xadc, cmd, ARRAY_SIZE(cmd));
+	xadc_read_reg(xadc, XADC_ZYNQ_REG_CFG, &tmp);
+	tmp &= ~XADC_ZYNQ_CFG_DFIFOTH_MASK;
+	tmp |= 0 << XADC_ZYNQ_CFG_DFIFOTH_OFFSET;
+	xadc_write_reg(xadc, XADC_ZYNQ_REG_CFG, tmp);

drivers/iio/adc/xilinx-xadc-platform.c line 160

Quoted 10 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +9 -0
+
+	xadc_zynq_update_intmsk(xadc, XADC_ZYNQ_INT_DFIFO_GTH, 0);
+	spin_unlock_irq(&xadc->lock);
+
+	ret = wait_for_completion_interruptible_timeout(&xadc->completion, HZ);
+	if (ret == 0)
+		ret = -EIO;
+	else
 
+		ret = 0;

This seems quite wrong. If you use interruptible version, why ignoring the error codes?

drivers/iio/adc/xilinx-xadc-platform.c line 167

Quoted 6 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +6 -0
+	xadc_read_reg(xadc, XADC_ZYNQ_REG_DFIFO, &tmp);
+
+	return ret;
+}
+
+static int xadc_zynq_read_adc_reg(struct xadc *xadc, unsigned int reg, uint16_t *val)

u16

Quoted 7 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +7 -0
+{
+	u32 cmd[2], resp, tmp;
+	int ret;
+
+	cmd[0] = XADC_ZYNQ_CMD(XADC_ZYNQ_CMD_READ, reg, 0);
+	cmd[1] = XADC_ZYNQ_CMD(XADC_ZYNQ_CMD_NOP, 0, 0);
+

drivers/iio/adc/xilinx-xadc-platform.c line 183

Quoted 10 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +9 -0
+	spin_lock_irq(&xadc->lock);
+	xadc_zynq_update_intmsk(xadc, XADC_ZYNQ_INT_DFIFO_GTH, XADC_ZYNQ_INT_DFIFO_GTH);
+	xadc_zynq_drain_fifo(xadc);
+	reinit_completion(&xadc->completion);
+
+	xadc_zynq_write_fifo(xadc, cmd, ARRAY_SIZE(cmd));
+	xadc_read_reg(xadc, XADC_ZYNQ_REG_CFG, &tmp);
 
+	tmp &= ~XADC_ZYNQ_CFG_DFIFOTH_MASK;
+	tmp |= 1 << XADC_ZYNQ_CFG_DFIFOTH_OFFSET;

Are you going to use bitfield.h?

drivers/iio/adc/xilinx-xadc-platform.c line 192

Quoted 9 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +9 -0
+	xadc_write_reg(xadc, XADC_ZYNQ_REG_CFG, tmp);
+
+	xadc_zynq_update_intmsk(xadc, XADC_ZYNQ_INT_DFIFO_GTH, 0);
+	spin_unlock_irq(&xadc->lock);
+	ret = wait_for_completion_interruptible_timeout(&xadc->completion, HZ);
+	if (ret == 0)
+		ret = -EIO;
+	if (ret < 0)
+		return ret;

As per above.

drivers/iio/adc/xilinx-xadc-platform.c line 197

Quoted 4 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +4 -0
+	xadc_read_reg(xadc, XADC_ZYNQ_REG_DFIFO, &resp);
+	xadc_read_reg(xadc, XADC_ZYNQ_REG_DFIFO, &resp);
+
+	*val = resp & 0xffff;

Unneeded mask.

drivers/iio/adc/xilinx-xadc-platform.c line 206

Quoted 8 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +7 -0
+	return 0;
+}
 
+static unsigned int xadc_zynq_transform_alarm(unsigned int alarm)
+{
+	return ((alarm & 0x80) >> 4) |
+		((alarm & 0x78) << 1) |
+		(alarm & 0x07);

One line. Also add a comment explaining this (perhaps with a reference to datasheet).

Quoted 1 line

+}

...

drivers/iio/adc/xilinx-xadc-platform.c line 293

Quoted 3 lines
drivers/iio/adc/xilinx-xadc-platform.c new file +3 -0
+#define XADC_ZYNQ_TCK_RATE_MAX 50000000
+#define XADC_ZYNQ_IGAP_DEFAULT 20
+#define XADC_ZYNQ_PCAP_RATE_MAX 200000000

Unit suffixes?

...

I stopped here. I think what you need is to clean up and modernize the driver first (see my comments above) and only when it's ready, start splitting it. The split itself can also be done in a few steps (you can try to prepare patches with ... -M -C --histogram ... to see when it will look better).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Re: [PATCH v2 1/4] iio: adc: xilinx-xadc: Split driver into core and platform files

In reply to Sai Krishna Potthuri
kernel test robot noticed the following build errors:

Hi Sai,

kernel test robot noticed the following build errors:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on robh/for-next linus/master v7.0-rc5 next-20260325] [cannot apply to xilinx-xlnx/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sai-Krishna-Potthuri/iio-adc-xilinx-xadc-Split-driver-into-core-and-platform-files/20260326-024045
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20260323074505.3853353-2-sai.krishna.potthuri%40amd.com
patch subject: [PATCH v2 1/4] iio: adc: xilinx-xadc: Split driver into core and platform files
config: i386-buildonly-randconfig-002-20260326 (https://download.01.org/0day-ci/archive/20260326/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260326/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "xadc_handle_events" [drivers/iio/adc/xilinx-xadc-platform.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

Re: [PATCH v2 1/4] iio: adc: xilinx-xadc: Split driver into core and platform files

In reply to Sai Krishna Potthuri
kernel test robot noticed the following build warnings:

Hi Sai,

kernel test robot noticed the following build warnings:

[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on robh/for-next linus/master v7.0-rc5 next-20260326] [cannot apply to xilinx-xlnx/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sai-Krishna-Potthuri/iio-adc-xilinx-xadc-Split-driver-into-core-and-platform-files/20260326-024045
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20260323074505.3853353-2-sai.krishna.potthuri%40amd.com
patch subject: [PATCH v2 1/4] iio: adc: xilinx-xadc: Split driver into core and platform files
config: hexagon-randconfig-r133-20260326 (https://download.01.org/0day-ci/archive/20260328/[email protected]/config)
compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 054e11d1a17e5ba88bb1a8ef32fad3346e80b186)
sparse: v0.6.5-rc1
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260328/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> drivers/iio/adc/xilinx-xadc-core.c:764:12: sparse: sparse: symbol 'xadc_type_names' was not declared. Should it be static?

vim +/xadc_type_names +764 drivers/iio/adc/xilinx-xadc-core.c

763

 > 764	const char * const xadc_type_names[] = {

765 [XADC_TYPE_S7] = "xadc",
766 [XADC_TYPE_US] = "xilinx-system-monitor",
767 };
768

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

PATCH v2 2/4 iio: adc: xilinx-xadc: Add .setup_channels() to struct xadc_ops

In reply to Sai Krishna Potthuri

Add .setup_channels() function pointer to struct xadc_ops to enable different interfaces to have custom channel setup logic.

---
 drivers/iio/adc/xilinx-xadc-core.c     | 6 ++++--
 drivers/iio/adc/xilinx-xadc-platform.c | 3 +++
 drivers/iio/adc/xilinx-xadc.h          | 2 ++
 3 files changed, 9 insertions(+), 2 deletions(-)
drivers/iio/adc/xilinx-xadc-core.c +4 -2
index 268e46e5349c..7fbf55f8e0bb 100644
@@ -653,7 +653,7 @@ static const struct iio_info xadc_info = {
 	.update_scan_mode = &xadc_update_scan_mode,
 };
 
-static int xadc_parse_dt(struct iio_dev *indio_dev, unsigned int *conf, int irq)
+int xadc_parse_dt(struct iio_dev *indio_dev, unsigned int *conf, int irq)
 {
 	struct device *dev = indio_dev->dev.parent;
 	struct xadc *xadc = iio_priv(indio_dev);
@@ -760,6 +760,7 @@ static int xadc_parse_dt(struct iio_dev *indio_dev, unsigned int *conf, int irq)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(xadc_parse_dt);
 
 const char * const xadc_type_names[] = {
 	[XADC_TYPE_S7] = "xadc",
@@ -791,10 +792,11 @@ int xadc_device_configure(struct device *dev, struct iio_dev *indio_dev,
 			  int irq, unsigned int *conf0,
 			  unsigned int *bipolar_mask)
 {
+	struct xadc *xadc = iio_priv(indio_dev);
 	int ret;
 	u32 i;
 
-	ret = xadc_parse_dt(indio_dev, conf0, irq);
+	ret = xadc->ops->setup_channels(indio_dev, conf0, irq);
 	if (ret)
 		return ret;
 
drivers/iio/adc/xilinx-xadc-platform.c +3 -0
index f1ffbf5cff42..9015b131daa3 100644
@@ -401,6 +401,7 @@ static const struct xadc_ops xadc_zynq_ops = {
 	.get_dclk_rate = xadc_zynq_get_dclk_rate,
 	.interrupt_handler = xadc_zynq_interrupt_handler,
 	.update_alarm = xadc_zynq_update_alarm,
+	.setup_channels = xadc_parse_dt,
 	.type = XADC_TYPE_S7,
 	/* Temp in C = (val * 503.975) / 2**bits - 273.15 */
 	.temp_scale = 503975,
@@ -508,6 +509,7 @@ static const struct xadc_ops xadc_7s_axi_ops = {
 	.get_dclk_rate = xadc_axi_get_dclk,
 	.update_alarm = xadc_axi_update_alarm,
 	.interrupt_handler = xadc_axi_interrupt_handler,
+	.setup_channels = xadc_parse_dt,
 	.flags = XADC_FLAGS_BUFFERED | XADC_FLAGS_IRQ_OPTIONAL,
 	.type = XADC_TYPE_S7,
 	/* Temp in C = (val * 503.975) / 2**bits - 273.15 */
@@ -522,6 +524,7 @@ static const struct xadc_ops xadc_us_axi_ops = {
 	.get_dclk_rate = xadc_axi_get_dclk,
 	.update_alarm = xadc_axi_update_alarm,
 	.interrupt_handler = xadc_axi_interrupt_handler,
+	.setup_channels = xadc_parse_dt,
 	.flags = XADC_FLAGS_BUFFERED | XADC_FLAGS_IRQ_OPTIONAL,
 	.type = XADC_TYPE_US,
 	/**
drivers/iio/adc/xilinx-xadc.h +2 -0
index a2d208fbd13b..feec8ef76e4f 100644
@@ -82,6 +82,7 @@ struct xadc_ops {
 	void (*update_alarm)(struct xadc *xadc, unsigned int alarm);
 	unsigned long (*get_dclk_rate)(struct xadc *xadc);
 	irqreturn_t (*interrupt_handler)(int irq, void *devid);
+	int (*setup_channels)(struct iio_dev *indio_dev, unsigned int *conf, int irq);
 
 	unsigned int flags;
 	enum xadc_type type;
@@ -233,6 +234,7 @@ void xadc_write_reg(struct xadc *xadc, unsigned int reg, uint32_t val);
 void xadc_read_reg(struct xadc *xadc, unsigned int reg, uint32_t *val);
 struct iio_dev *xadc_device_setup(struct device *dev, int size,
 				  const struct xadc_ops **ops);
+int xadc_parse_dt(struct iio_dev *indio_dev, unsigned int *conf, int irq);
 int xadc_device_configure(struct device *dev, struct iio_dev *indio_dev,
 			  int irq, unsigned int *conf0, unsigned int *bipolar_mask);
 int xadc_read_samplerate(struct xadc *xadc);
Signature · 1 line
2.25.1
#6 lore raw

PATCH v2 3/4 iio: adc: xilinx-xadc: Add I2C interface support

In reply to Sai Krishna Potthuri

Add I2C interface support for Xilinx System Management Wizard IP along with the existing AXI memory-mapped interface. This support enables monitoring the voltage and temperature on UltraScale+ devices where the System Management Wizard is connected via I2C.

Key changes:
- Implement 32-bit DRP(Dynamic Reconfiguration Port) packet format as per Xilinx PG185 specification.
- Add separate I2C probe with xadc_i2c_of_match_table to handle same compatible string("xlnx,system-management-wiz-1.3") on I2C bus.
- Implement delayed version of hardware initialization for I2C interface to handle the case where System Management Wizard IP is not ready during the I2C probe.
- Add NULL checks for get_dclk_rate callback function in sampling rate functions to support interfaces without clock control
- Create separate iio_info structure(xadc_i2c_info) without event callbacks for I2C devices
- Add xadc_i2c_transaction() function to handle I2C read/write operations
- Add XADC_TYPE_US_I2C type to distinguish I2C interface from AXI

---
 drivers/iio/adc/Kconfig            |  15 ++
 drivers/iio/adc/Makefile           |   1 +
 drivers/iio/adc/xilinx-xadc-core.c |  28 +++-
 drivers/iio/adc/xilinx-xadc-i2c.c  | 215 +++++++++++++++++++++++++++++
 drivers/iio/adc/xilinx-xadc.h      |   1 +
 5 files changed, 256 insertions(+), 4 deletions(-)
 create mode 100644 drivers/iio/adc/xilinx-xadc-i2c.c
drivers/iio/adc/Kconfig +15 -0
index a4a7556f4016..5a3956a5c086 100644
@@ -1767,6 +1767,21 @@ config XILINX_XADC
 	  The driver can also be build as a module. If so, the module will be called
 	  xilinx-xadc.
 
+config XILINX_XADC_I2C
+	tristate "Xilinx System Management Wizard I2C Interface support"
+	depends on I2C
+	select XILINX_XADC_CORE
+	help
+	  Say yes here to allow accessing the System Management
+	  Wizard on UltraScale+ devices via I2C.
+
+	  This provides voltage and temperature monitoring capabilities
+	  through the same IIO sysfs interface, but using I2C communication
+	  protocol.
+
+	  The driver can also be build as a module. If so, the module will be called
+	  xilinx-xadc-i2c.
+
 config XILINX_AMS
 	tristate "Xilinx AMS driver"
 	depends on ARCH_ZYNQMP || COMPILE_TEST
drivers/iio/adc/Makefile +1 -0
index 1b05176f0098..2dc08c9d82cc 100644
@@ -157,3 +157,4 @@ obj-$(CONFIG_XILINX_AMS) += xilinx-ams.o
 xilinx-xadc-common-y := xilinx-xadc-core.o xilinx-xadc-events.o
 obj-$(CONFIG_XILINX_XADC_CORE) += xilinx-xadc-common.o
 obj-$(CONFIG_XILINX_XADC) += xilinx-xadc-platform.o
+obj-$(CONFIG_XILINX_XADC_I2C) += xilinx-xadc-i2c.o
drivers/iio/adc/xilinx-xadc-core.c +24 -4
index 7fbf55f8e0bb..383bd93676ec 100644
@@ -222,7 +222,8 @@ static int xadc_power_adc_b(struct xadc *xadc, unsigned int seq_mode)
 	 * non-existing ADC-B powers down the main ADC, so just return and don't
 	 * do anything.
 	 */
-	if (xadc->ops->type == XADC_TYPE_US)
+	if (xadc->ops->type == XADC_TYPE_US ||
+	    xadc->ops->type == XADC_TYPE_US_I2C)
 		return 0;
 
 	/* Powerdown the ADC-B when it is not needed. */
@@ -245,7 +246,8 @@ static int xadc_get_seq_mode(struct xadc *xadc, unsigned long scan_mode)
 	unsigned int aux_scan_mode = scan_mode >> 16;
 
 	/* UltraScale has only one ADC and supports only continuous mode */
-	if (xadc->ops->type == XADC_TYPE_US)
+	if (xadc->ops->type == XADC_TYPE_US ||
+	    xadc->ops->type == XADC_TYPE_US_I2C)
 		return XADC_CONF1_SEQ_CONTINUOUS;
 
 	if (xadc->external_mux_mode == XADC_EXTERNAL_MUX_DUAL)
@@ -346,6 +348,9 @@ int xadc_read_samplerate(struct xadc *xadc)
 	uint16_t val16;
 	int ret;
 
+	if (!xadc->ops->get_dclk_rate)
+		return -EOPNOTSUPP;
+
 	ret = xadc_read_adc_reg(xadc, XADC_REG_CONF2, &val16);
 	if (ret)
 		return ret;
@@ -457,9 +462,14 @@ EXPORT_SYMBOL_GPL(xadc_setup_buffer_and_triggers);
 
 int xadc_write_samplerate(struct xadc *xadc, int val)
 {
-	unsigned long clk_rate = xadc_get_dclk_rate(xadc);
+	unsigned long clk_rate;
 	unsigned int div;
 
+	if (!xadc->ops->get_dclk_rate)
+		return -EOPNOTSUPP;
+
+	clk_rate = xadc_get_dclk_rate(xadc);
+
 	if (!clk_rate)
 		return -EINVAL;
 
@@ -653,6 +663,11 @@ static const struct iio_info xadc_info = {
 	.update_scan_mode = &xadc_update_scan_mode,
 };
 
+static const struct iio_info xadc_i2c_info = {
+	.read_raw = &xadc_read_raw,
+	.write_raw = &xadc_write_raw,
+};
+
 int xadc_parse_dt(struct iio_dev *indio_dev, unsigned int *conf, int irq)
 {
 	struct device *dev = indio_dev->dev.parent;
@@ -765,6 +780,7 @@ EXPORT_SYMBOL_GPL(xadc_parse_dt);
 const char * const xadc_type_names[] = {
 	[XADC_TYPE_S7] = "xadc",
 	[XADC_TYPE_US] = "xilinx-system-monitor",
+	[XADC_TYPE_US_I2C] = "xilinx-system-monitor",
 };
 
 struct iio_dev *xadc_device_setup(struct device *dev, int size,
@@ -781,7 +797,11 @@ struct iio_dev *xadc_device_setup(struct device *dev, int size,
 		return ERR_PTR(-ENOMEM);
 
 	indio_dev->name = xadc_type_names[(*ops)->type];
-	indio_dev->info = &xadc_info;
+	if ((*ops)->type == XADC_TYPE_US_I2C)
+		indio_dev->info = &xadc_i2c_info;
+	else
+		indio_dev->info = &xadc_info;
+
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
 	return indio_dev;
drivers/iio/adc/xilinx-xadc-i2c.c new file +215 -0

215 lines not on this page · raw message

drivers/iio/adc/xilinx-xadc.h +1 -0
index feec8ef76e4f..d0c64b5f55f1 100644
@@ -72,6 +72,7 @@ struct xadc {
 enum xadc_type {
 	XADC_TYPE_S7, /* Series 7 */
 	XADC_TYPE_US, /* UltraScale and UltraScale+ */
+	XADC_TYPE_US_I2C, /* UltraScale+ I2C interface */
 };
 
 struct xadc_ops {
Signature · 1 line
2.25.1
#7 lore raw

Re: [PATCH v2 3/4] iio: adc: xilinx-xadc: Add I2C interface support

Quoted 19 lines · Sai Krishna Potthuri

Add I2C interface support for Xilinx System Management Wizard IP along with the existing AXI memory-mapped interface. This support enables monitoring the voltage and temperature on UltraScale+ devices where the System Management Wizard is connected via I2C.

Key changes:
- Implement 32-bit DRP(Dynamic Reconfiguration Port) packet format as per Xilinx PG185 specification.
- Add separate I2C probe with xadc_i2c_of_match_table to handle same compatible string("xlnx,system-management-wiz-1.3") on I2C bus.
- Implement delayed version of hardware initialization for I2C interface to handle the case where System Management Wizard IP is not ready during the I2C probe.
- Add NULL checks for get_dclk_rate callback function in sampling rate functions to support interfaces without clock control
- Create separate iio_info structure(xadc_i2c_info) without event callbacks for I2C devices
- Add xadc_i2c_transaction() function to handle I2C read/write operations
- Add XADC_TYPE_US_I2C type to distinguish I2C interface from AXI

...

drivers/iio/adc/xilinx-xadc-core.c static int xadc_power_adc_b(struct xadc *xadc, unsigned int seq_mode) · line 226

Quoted 3 lines
drivers/iio/adc/xilinx-xadc-core.c +2 -1
-	if (xadc->ops->type == XADC_TYPE_US)
+	if (xadc->ops->type == XADC_TYPE_US ||
+	    xadc->ops->type == XADC_TYPE_US_I2C)

Can be one line.

Quoted 1 line

return 0;

...

drivers/iio/adc/xilinx-xadc-core.c static int xadc_get_seq_mode(struct xadc *xadc, unsigned long scan_mode) · line 250

Quoted 4 lines
drivers/iio/adc/xilinx-xadc-core.c +2 -1
 	/* UltraScale has only one ADC and supports only continuous mode */
-	if (xadc->ops->type == XADC_TYPE_US)
+	if (xadc->ops->type == XADC_TYPE_US ||
+	    xadc->ops->type == XADC_TYPE_US_I2C)

Ditto.

Quoted 1 line

return XADC_CONF1_SEQ_CONTINUOUS;

...

drivers/iio/adc/xilinx-xadc-core.c EXPORT_SYMBOL_GPL(xadc_setup_buffer_and_triggers);

Quoted 11 lines

int xadc_write_samplerate(struct xadc *xadc, int val) {

drivers/iio/adc/xilinx-xadc-core.c +5 -1
-	unsigned long clk_rate = xadc_get_dclk_rate(xadc);
+	unsigned long clk_rate;
 	unsigned int div;
 
+	if (!xadc->ops->get_dclk_rate)
+		return -EOPNOTSUPP;
 
+	clk_rate = xadc_get_dclk_rate(xadc);
+

Unneeded blank line.

Also, don't you asked for options?

Quoted 2 lines
drivers/iio/adc/xilinx-xadc-core.c +0 -0
 	if (!clk_rate)
 		return -EINVAL;

...

drivers/iio/adc/xilinx-xadc-i2c.c line 187

Quoted 1 line
drivers/iio/adc/xilinx-xadc-i2c.c new file +1 -0
+	i2c_set_clientdata(client, indio_dev);

Is it used?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Re: [PATCH v2 3/4] iio: adc: xilinx-xadc: Add I2C interface support

Hi Andy Shevchenko,

Quoted 70 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Monday, March 23, 2026 4:22 PM
To: Potthuri, Sai Krishna <[email protected]>
Cc: Jonathan Cameron <[email protected]>; David Lechner <[email protected]>; Nuno Sa <[email protected]>; Andy Shevchenko <[email protected]>; Simek, Michal <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; git (AMD-Xilinx) <[email protected]>
Subject: Re: [PATCH v2 3/4] iio: adc: xilinx-xadc: Add I2C interface support

Quoted 5 lines · Sai Krishna Potthuri

Add I2C interface support for Xilinx System Management Wizard IP along with the existing AXI memory-mapped interface. This support enables monitoring the voltage and temperature on UltraScale+ devices where the System Management Wizard is connected via I2C.

Quoted 7 lines

Key changes:
- Implement 32-bit DRP(Dynamic Reconfiguration Port) packet format as per Xilinx PG185 specification.
- Add separate I2C probe with xadc_i2c_of_match_table to handle same compatible string("xlnx,system-management-wiz-1.3") on I2C bus.
- Implement delayed version of hardware initialization for I2C interface to handle the case where System Management Wizard IP is not ready

during

Quoted 8 lines

the I2C probe.
- Add NULL checks for get_dclk_rate callback function in sampling rate functions to support interfaces without clock control
- Create separate iio_info structure(xadc_i2c_info) without event callbacks for I2C devices
- Add xadc_i2c_transaction() function to handle I2C read/write operations
- Add XADC_TYPE_US_I2C type to distinguish I2C interface from AXI

...

drivers/iio/adc/xilinx-xadc-core.c static int xadc_power_adc_b(struct xadc *xadc, unsigned int seq_mode) · line 226

Quoted 3 lines
drivers/iio/adc/xilinx-xadc-core.c +2 -1
-	if (xadc->ops->type == XADC_TYPE_US)
+	if (xadc->ops->type == XADC_TYPE_US ||
+	    xadc->ops->type == XADC_TYPE_US_I2C)

Can be one line.

Quoted 1 line

return 0;

...

Quoted 1 line

/* UltraScale has only one ADC and supports only continuous mode

*/

drivers/iio/adc/xilinx-xadc-core.c static int xadc_power_adc_b(struct xadc *xadc, unsigned int seq_mode) · line 226

Quoted 3 lines
drivers/iio/adc/xilinx-xadc-core.c +2 -1
-	if (xadc->ops->type == XADC_TYPE_US)
+	if (xadc->ops->type == XADC_TYPE_US ||
+	    xadc->ops->type == XADC_TYPE_US_I2C)

Ditto.

Quoted 1 line

return XADC_CONF1_SEQ_CONTINUOUS;

...

Quoted 7 lines

int xadc_write_samplerate(struct xadc *xadc, int val) {

drivers/iio/adc/xilinx-xadc-core.c +3 -1
-	unsigned long clk_rate = xadc_get_dclk_rate(xadc);
+	unsigned long clk_rate;
 	unsigned int div;
 
+	if (!xadc->ops->get_dclk_rate)
+		return -EOPNOTSUPP;
Quoted 6 lines

drivers/iio/adc/xilinx-xadc-core.c EXPORT_SYMBOL_GPL(xadc_setup_buffer_and_triggers); · line 472

Quoted 2 lines
drivers/iio/adc/xilinx-xadc-core.c +2 -0
+	clk_rate = xadc_get_dclk_rate(xadc);
+

Unneeded blank line.

Also, don't you asked for options?

This callback is defined for all other platforms except I2C. Currently for I2c interface we are not supporting any configuration, it is used only to read the channels.

Quoted 9 lines
Quoted 3 lines
drivers/iio/adc/xilinx-xadc-core.c +0 -0
 	if (!clk_rate)
 		return -EINVAL;

...

drivers/iio/adc/xilinx-xadc-i2c.c line 187

Quoted 1 line
drivers/iio/adc/xilinx-xadc-i2c.c new file +1 -0
+	i2c_set_clientdata(client, indio_dev);

Is it used?

No, will remove this one.

Regards
Sai Krishna

#9 lore raw

Re: [PATCH v2 3/4] iio: adc: xilinx-xadc: Add I2C interface support

Quoted 4 lines · Sai Krishna Potthuri
Quoted 4 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Monday, March 23, 2026 4:22 PM
On Mon, Mar 23, 2026 at 01:15:04PM +0530, Sai Krishna Potthuri wrote:

...

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

int xadc_write_samplerate(struct xadc *xadc, int val) {

drivers/iio/adc/xilinx-xadc-core.c +5 -1
-   unsigned long clk_rate = xadc_get_dclk_rate(xadc);
+   unsigned long clk_rate;
    unsigned int div;
 
+   if (!xadc->ops->get_dclk_rate)
+           return -EOPNOTSUPP;
 
+   clk_rate = xadc_get_dclk_rate(xadc);
+
Quoted 6 lines
Quoted 3 lines

Unneeded blank line.

Also, don't you asked for options?

This callback is defined for all other platforms except I2C. Currently for I2c interface we are not supporting any configuration, it is used only to read the channels.

If the callback defined you should use its value and not hardcoded one, right?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
    if (!clk_rate)
            return -EINVAL;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw

Re: [PATCH v2 3/4] iio: adc: xilinx-xadc: Add I2C interface support

Hi Andy Shevchenko,

Quoted 20 lines · Andy Shevchenko
Quoted 4 lines · Sai Krishna Potthuri
Quoted 4 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Monday, March 23, 2026 4:22 PM
On Mon, Mar 23, 2026 at 01:15:04PM +0530, Sai Krishna Potthuri wrote:

...

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
  int xadc_write_samplerate(struct xadc *xadc, int val)  {
drivers/iio/adc/xilinx-xadc-core.c +5 -1
-   unsigned long clk_rate = xadc_get_dclk_rate(xadc);
+   unsigned long clk_rate;
     unsigned int div;
 
+   if (!xadc->ops->get_dclk_rate)
+           return -EOPNOTSUPP;
 
+   clk_rate = xadc_get_dclk_rate(xadc);
+
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Unneeded blank line.

Also, don't you asked for options?

This callback is defined for all other platforms except I2C. Currently for I2c interface we are not supporting any configuration, it is used only to read the channels.

If the callback defined you should use its value and not hardcoded one, right?

Yes, that's the intention.
xadc_get_dclk_rate() - this is a wrapper function to call xadc->ops->get_dclk_rate(). May be i will remove the wrapper function or move the if (!xadc->ops->get_dclk_rate) check inside wrapper.

Regards
Sai Krishna

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
     if (!clk_rate)
             return -EINVAL;
maintainer
#11 lore raw

Re: [PATCH v2 3/4] iio: adc: xilinx-xadc: Add I2C interface support

In reply to Sai Krishna Potthuri
Quoted 20 lines · On Mon, 23 Mar 2026 13:15:04 +0530 Sai Krishna Potthuri…

Add I2C interface support for Xilinx System Management Wizard IP along with the existing AXI memory-mapped interface. This support enables monitoring the voltage and temperature on UltraScale+ devices where the System Management Wizard is connected via I2C.

Key changes:
- Implement 32-bit DRP(Dynamic Reconfiguration Port) packet format as per Xilinx PG185 specification.
- Add separate I2C probe with xadc_i2c_of_match_table to handle same compatible string("xlnx,system-management-wiz-1.3") on I2C bus.
- Implement delayed version of hardware initialization for I2C interface to handle the case where System Management Wizard IP is not ready during the I2C probe.
- Add NULL checks for get_dclk_rate callback function in sampling rate functions to support interfaces without clock control
- Create separate iio_info structure(xadc_i2c_info) without event callbacks for I2C devices
- Add xadc_i2c_transaction() function to handle I2C read/write operations
- Add XADC_TYPE_US_I2C type to distinguish I2C interface from AXI

Quoted 1 line

Hi.
A few minor things inline.

Thanks,

Jonathan

Quoted 20 lines
---
 drivers/iio/adc/Kconfig            |  15 ++
 drivers/iio/adc/Makefile           |   1 +
 drivers/iio/adc/xilinx-xadc-core.c |  28 +++-
 drivers/iio/adc/xilinx-xadc-i2c.c  | 215 +++++++++++++++++++++++++++++
 drivers/iio/adc/xilinx-xadc.h      |   1 +
 5 files changed, 256 insertions(+), 4 deletions(-)
 create mode 100644 drivers/iio/adc/xilinx-xadc-i2c.c
drivers/iio/adc/Kconfig +3 -0
index a4a7556f4016..5a3956a5c086 100644
@@ -1767,6 +1767,21 @@ config XILINX_XADC
 	  The driver can also be build as a module. If so, the module will be called
 	  xilinx-xadc.
 
+config XILINX_XADC_I2C
+	tristate "Xilinx System Management Wizard I2C Interface support"
+	depends on I2C

drivers/iio/adc/Kconfig config XILINX_XADC · line 1782

Quoted 10 lines
drivers/iio/adc/Kconfig +10 -0
+	select XILINX_XADC_CORE
+	help
+	  Say yes here to allow accessing the System Management
+	  Wizard on UltraScale+ devices via I2C.
+
+	  This provides voltage and temperature monitoring capabilities
+	  through the same IIO sysfs interface, but using I2C communication
+	  protocol.
+
+	  The driver can also be build as a module. If so, the module will be called

line is a little too long for Kconfig.

Quoted 34 lines
drivers/iio/adc/Kconfig +2 -0
+	  xilinx-xadc-i2c.
+
 
drivers/iio/adc/xilinx-xadc-i2c.c new file +24 -0
new file mode 100644
index 000000000000..3d802b907260
@@ -0,0 +1,215 @@
 
+static int xadc_i2c_read_transaction(struct xadc *xadc, unsigned int reg, u16 *val)
+{
+	struct xadc_i2c *xadc_i2c = container_of(xadc, struct xadc_i2c, xadc);
+	char write_buffer[XADC_I2C_WRITE_DATA_SIZE] = { 0 };
+	struct i2c_client *client = xadc_i2c->client;
+	char read_buffer[XADC_I2C_READ_DATA_SIZE];
+	int ret;
+
+	write_buffer[2] = FIELD_GET(XADC_I2C_DRP_ADDR_MASK, reg);
+	write_buffer[3] = XADC_I2C_INSTR_READ;
+
+	ret = i2c_master_send(client, write_buffer, XADC_I2C_WRITE_DATA_SIZE);
+	if (ret < 0)
+		return ret;
+
+	ret = i2c_master_recv(client, read_buffer, XADC_I2C_READ_DATA_SIZE);
+	if (ret < 0)
+		return ret;
+
+	*val = FIELD_PREP(XADC_I2C_DRP_DATA0_MASK, read_buffer[0]) |
+	       FIELD_PREP(XADC_I2C_DRP_DATA1_MASK, read_buffer[1]);
+
+	return 0;
+}

drivers/iio/adc/xilinx-xadc-i2c.c line 77

Quoted 10 lines
drivers/iio/adc/xilinx-xadc-i2c.c new file +10 -0
+
+static int xadc_i2c_write_transaction(struct xadc *xadc, unsigned int reg, u16 val)
+{
+	struct xadc_i2c *xadc_i2c = container_of(xadc, struct xadc_i2c, xadc);
+	struct i2c_client *client = xadc_i2c->client;
+	char write_buffer[XADC_I2C_WRITE_DATA_SIZE];
+	int ret;
+
+	write_buffer[0] = FIELD_GET(XADC_I2C_DRP_DATA0_MASK, val);
+	write_buffer[1] = FIELD_GET(XADC_I2C_DRP_DATA1_MASK, val);

This is odd enough it might be useful to have some comments. Why do we need to write the value to two places for instance?

Quoted 7 lines
drivers/iio/adc/xilinx-xadc-i2c.c new file +7 -0
+	write_buffer[2] = FIELD_GET(XADC_I2C_DRP_ADDR_MASK, reg);
+	write_buffer[3] = XADC_I2C_INSTR_WRITE;
+
+	ret = i2c_master_send(client, write_buffer, XADC_I2C_WRITE_DATA_SIZE);
+	if (ret < 0)
+		return ret;
+

drivers/iio/adc/xilinx-xadc-i2c.c line 94

Quoted 10 lines
drivers/iio/adc/xilinx-xadc-i2c.c new file +10 -0
+	return 0;
+}
+
+static int xadc_hardware_init(struct xadc *xadc)
+{
+	struct xadc_i2c *xadc_i2c = container_of(xadc, struct xadc_i2c, xadc);
+	int ret;
+	u32 i;
+
+	for (i = 0; i < ARRAY_SIZE(xadc->threshold); i++) {
	for (u32 i = 0;

Though why a u32? If size doesn't matter, convention is pretty much always use a unsigned int for the iterator.

Quoted 35 lines
drivers/iio/adc/xilinx-xadc-i2c.c new file +35 -0
+		ret = xadc_i2c_read_transaction(xadc, XADC_REG_THRESHOLD(i),
+						&xadc->threshold[i]);
+		if (ret)
+			return ret;
+	}
+
+	ret = xadc_i2c_write_transaction(xadc, XADC_REG_CONF0, xadc_i2c->conf0);
+	if (ret)
+		return ret;
+
+	ret = xadc_i2c_write_transaction(xadc, XADC_REG_INPUT_MODE(0),
+					 xadc_i2c->bipolar_mask);
+	if (ret)
+		return ret;
+
+	ret = xadc_i2c_write_transaction(xadc, XADC_REG_INPUT_MODE(1),
+					 xadc_i2c->bipolar_mask >> XADC_INPUT_MODE_BITS);
+	if (ret)
+		return ret;
+
+	xadc_i2c->hw_initialized = true;
+
+	return 0;
+}
+
+static int xadc_i2c_read_reg(struct xadc *xadc, unsigned int reg, u16 *val)
+{
+	struct xadc_i2c *xadc_i2c = container_of(xadc, struct xadc_i2c, xadc);
+
+	if (!xadc_i2c->hw_initialized) {
+		int ret;
+
+		ret = xadc_hardware_init(xadc);
+		if (ret)
+			return ret;

drivers/iio/adc/xilinx-xadc-i2c.c line 139

Quoted 10 lines
drivers/iio/adc/xilinx-xadc-i2c.c new file +10 -0
+	}
+
+	return xadc_i2c_read_transaction(xadc, reg, val);
+}
+
+static int xadc_i2c_write_reg(struct xadc *xadc, unsigned int reg, u16 val)
+{
+	struct xadc_i2c *xadc_i2c = container_of(xadc, struct xadc_i2c, xadc);
+
+	if (!xadc_i2c->hw_initialized) {

Seems like this is always called once on first access?
If so just do it form probe and simplify the read/ write_reg() functions.

Quoted 20 lines
drivers/iio/adc/xilinx-xadc-i2c.c new file +19 -0
+		int ret;
+
+		ret = xadc_hardware_init(xadc);
+		if (ret)
+			return ret;
+	}
+
+	return xadc_i2c_write_transaction(xadc, reg, val);
+}
 
+static int xadc_i2c_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	unsigned int conf0, bipolar_mask;
+	const struct xadc_ops *ops;
+	struct iio_dev *indio_dev;
+	struct xadc_i2c *xadc_i2c;
+	struct xadc *xadc;
+	int ret;
+

drivers/iio/adc/xilinx-xadc-i2c.c line 178

Quoted 10 lines
drivers/iio/adc/xilinx-xadc-i2c.c new file +10 -0
+	indio_dev = xadc_device_setup(dev, sizeof(*xadc_i2c), &ops);
+	if (IS_ERR(indio_dev))
+		return PTR_ERR(indio_dev);
+
+	xadc_i2c = iio_priv(indio_dev);
+	xadc_i2c->client = client;
+	xadc = &xadc_i2c->xadc;
+	xadc->clk = NULL;
+	xadc->ops = ops;
+	mutex_init(&xadc->mutex);

For new code (feel free to update the other code in a separate patch).

	ret = devm_mutex_init(xadc->mutex);
	if (ret)
		return ret;

As gives a small amount of lock debugging infrastructure and is now cheap to do. The devm form didn't used to exist.

drivers/iio/adc/xilinx-xadc-i2c.c line 184

Quoted 6 lines
drivers/iio/adc/xilinx-xadc-i2c.c new file +6 -0
+	spin_lock_init(&xadc->lock);
+
+	ret = xadc_device_configure(dev, indio_dev, 0, &conf0, &bipolar_mask);
+	if (ret) {
+		dev_err(dev, "Failed to setup the device: %d\n", ret);
+		return ret;
		return dev_err_probe(dev, "Failed to setup the device.\n");

Which will pretty print the error and hide it if -EPROBEDEFER (because that should be silent) or -ENOMEM (because memory allocation errors are very noisy anyway!)

Quoted 9 lines
drivers/iio/adc/xilinx-xadc-i2c.c new file +9 -0
+	}
+
+	i2c_set_clientdata(client, indio_dev);
+	xadc_i2c->conf0 = conf0;
+	xadc_i2c->bipolar_mask = bipolar_mask;
+	xadc_i2c->hw_initialized = false;
+
+	return devm_iio_device_register(dev, indio_dev);
+}
#12 lore raw

PATCH v2 4/4 dt-bindings: iio: adc: xlnx,axi-xadc: convert to DT schema

In reply to Sai Krishna Potthuri

Convert the xilinx-xadc.txt to DT schema and remove the old text binding. Update xilinx-xadc binding path to YAML format in MAINTAINERS file.

The 'xlnx,channels' property is a container node(type: object) with a vendor prefix, which triggers the below warning:
"properties:xlnx,channels:type: 'boolean' was expected"

This cannot be changed because the original text binding specified 'xlnx,channels' since 2014, driver explicitly looks up "xlnx,channels" using device_get_named_child_node() and removing the vendor prefix would break backward compatibility with existing device trees. Also, keep all vendor-prefixed properties from the original binding to maintain backward compatibility with existing devicetrees and driver code.

---
 .../bindings/iio/adc/xilinx-xadc.txt          | 141 ----------------
 .../bindings/iio/adc/xlnx,axi-xadc.yaml       | 154 ++++++++++++++++++
 2 files changed, 154 insertions(+), 141 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/iio/adc/xilinx-xadc.txt
 create mode 100644 Documentation/devicetree/bindings/iio/adc/xlnx,axi-xadc.yaml
Documentation/devicetree/bindings/iio/adc/xilinx-xadc.txt deleted +0 -141
deleted file mode 100644
index f42e18078376..000000000000
@@ -1,141 +0,0 @@
-Xilinx XADC device driver
-
-This binding document describes the bindings for the Xilinx 7 Series XADC as well
-as the UltraScale/UltraScale+ System Monitor.
-
-The Xilinx XADC is an ADC that can be found in the Series 7 FPGAs from Xilinx.
-The XADC has a DRP interface for communication. Currently two different
-frontends for the DRP interface exist. One that is only available on the ZYNQ
-family as a hardmacro in the SoC portion of the ZYNQ. The other one is available
-on all series 7 platforms and is a softmacro with a AXI interface. This binding
-document describes the bindings for both of them since the bindings are very
-similar.
-
-The Xilinx System Monitor is an ADC that is found in the UltraScale and
-UltraScale+ FPGAs from Xilinx. The System Monitor provides a DRP interface for
-communication. Xilinx provides a standard IP core that can be used to access the
-System Monitor through an AXI interface in the FPGA fabric. This IP core is
-called the Xilinx System Management Wizard. This document describes the bindings
-for this IP.
-
-Required properties:
-	- compatible: Should be one of
-		* "xlnx,zynq-xadc-1.00.a": When using the ZYNQ device
-		  configuration interface to interface to the XADC hardmacro.
-		* "xlnx,axi-xadc-1.00.a": When using the axi-xadc pcore to
-		  interface to the XADC hardmacro.
-		* "xlnx,system-management-wiz-1.3": When using the
-		  Xilinx System Management Wizard fabric IP core to access the
-		  UltraScale and UltraScale+ System Monitor.
-	- reg: Address and length of the register set for the device
-	- interrupts: Interrupt for the XADC control interface.
-	- clocks: When using the ZYNQ this must be the ZYNQ PCAP clock,
-	  when using the axi-xadc or the axi-system-management-wizard this must be
-	  the clock that provides the clock to the AXI bus interface of the core.
-
-Optional properties:
-	- xlnx,external-mux:
-		* "none": No external multiplexer is used, this is the default
-		  if the property is omitted.
-		* "single": External multiplexer mode is used with one
-		   multiplexer.
-		* "dual": External multiplexer mode is used with two
-		  multiplexers for simultaneous sampling.
-	- xlnx,external-mux-channel: Configures which pair of pins is used to
-	  sample data in external mux mode.
-	  Valid values for single external multiplexer mode are:
-		0: VP/VN
-		1: VAUXP[0]/VAUXN[0]
-		2: VAUXP[1]/VAUXN[1]
-		...
-		16: VAUXP[15]/VAUXN[15]
-	  Valid values for dual external multiplexer mode are:
-		1: VAUXP[0]/VAUXN[0] - VAUXP[8]/VAUXN[8]
-		2: VAUXP[1]/VAUXN[1] - VAUXP[9]/VAUXN[9]
-		...
-		8: VAUXP[7]/VAUXN[7] - VAUXP[15]/VAUXN[15]
-
-	  This property needs to be present if the device is configured for
-	  external multiplexer mode (either single or dual). If the device is
-	  not using external multiplexer mode the property is ignored.
-	- xnlx,channels: List of external channels that are connected to the ADC
-	  Required properties:
-		* #address-cells: Should be 1.
-		* #size-cells: Should be 0.
-
-	  The child nodes of this node represent the external channels which are
-	  connected to the ADC. If the property is no present no external
-	  channels will be assumed to be connected.
-
-	  Each child node represents one channel and has the following
-	  properties:
-		Required properties:
-			* reg: Pair of pins the channel is connected to.
-				0: VP/VN
-				1: VAUXP[0]/VAUXN[0]
-				2: VAUXP[1]/VAUXN[1]
-				...
-				16: VAUXP[15]/VAUXN[15]
-			  Note each channel number should only be used at most
-			  once.
-		Optional properties:
-			* xlnx,bipolar: If set the channel is used in bipolar
-			  mode.
-
-
-Examples:
-	xadc@f8007100 {
-		compatible = "xlnx,zynq-xadc-1.00.a";
-		reg = <0xf8007100 0x20>;
-		interrupts = <0 7 4>;
-		interrupt-parent = <&gic>;
-		clocks = <&pcap_clk>;
-
-		xlnx,channels {
-			#address-cells = <1>;
-			#size-cells = <0>;
-			channel@0 {
-				reg = <0>;
-			};
-			channel@1 {
-				reg = <1>;
-			};
-			channel@8 {
-				reg = <8>;
-			};
-		};
-	};
-
-	xadc@43200000 {
-		compatible = "xlnx,axi-xadc-1.00.a";
-		reg = <0x43200000 0x1000>;
-		interrupts = <0 53 4>;
-		interrupt-parent = <&gic>;
-		clocks = <&fpga1_clk>;
-
-		xlnx,channels {
-			#address-cells = <1>;
-			#size-cells = <0>;
-			channel@0 {
-				reg = <0>;
-				xlnx,bipolar;
-			};
-		};
-	};
-
-	adc@80000000 {
-		compatible = "xlnx,system-management-wiz-1.3";
-		reg = <0x80000000 0x1000>;
-		interrupts = <0 81 4>;
-		interrupt-parent = <&gic>;
-		clocks = <&fpga1_clk>;
-
-		xlnx,channels {
-			#address-cells = <1>;
-			#size-cells = <0>;
-			channel@0 {
-				reg = <0>;
-				xlnx,bipolar;
-			};
-		};
-	};
Documentation/devicetree/bindings/iio/adc/xlnx,axi-xadc.yaml new file +154 -0

154 lines not on this page · raw message

Signature · 1 line
2.25.1
#13 lore raw

Re: [PATCH v2 4/4] dt-bindings: iio: adc: xlnx,axi-xadc: convert to DT schema

Quoted 14 lines · Sai Krishna Potthuri

Convert the xilinx-xadc.txt to DT schema and remove the old text binding. Update xilinx-xadc binding path to YAML format in MAINTAINERS file.

The 'xlnx,channels' property is a container node(type: object) with a vendor prefix, which triggers the below warning:
"properties:xlnx,channels:type: 'boolean' was expected"

This cannot be changed because the original text binding specified 'xlnx,channels' since 2014, driver explicitly looks up "xlnx,channels" using device_get_named_child_node() and removing the vendor prefix would break backward compatibility with existing device trees. Also, keep all vendor-prefixed properties from the original binding to maintain backward compatibility with existing devicetrees and driver code.

Quoted 8 lines
---
 .../bindings/iio/adc/xilinx-xadc.txt          | 141 ----------------
 .../bindings/iio/adc/xlnx,axi-xadc.yaml       | 154 ++++++++++++++++++
 2 files changed, 154 insertions(+), 141 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/iio/adc/xilinx-xadc.txt
 create mode 100644 Documentation/devicetree/bindings/iio/adc/xlnx,axi-xadc.yaml

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/adc/xlnx,axi-xadc.yaml: properties:xlnx,channels:type: 'boolean' was expected
hint: A vendor boolean property can use "type: boolean"
from schema $id: http://devicetree.org/meta-schemas/vendor-props.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.kernel.org/project/devicetree/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.