Skip to contentSkip to conversation

Xilinx XADC fixes

PATCH Superseded Robert Hancock 1 participant 4 messages Sep 14, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#3 lore raw

PATCH 2/2 iio: adc: xilinx-xadc: Correct temperature offset/scale for UltraScale

In reply to Robert Hancock

The driver was previously using offset and scale values for the temperature sensor readings which were only valid for 7-series devices. Add per-device-type values for offset and scale and set them appropriately for each device type.

Note that the values used for the UltraScale family are for UltraScale+ (i.e. the SYSMONE4 primitive) using the internal reference, as that seems to be the most common configuration and the device tree values Xilinx's device tree generator produces don't seem to give us anything to tell us which configuration is used. However, the differences within the UltraScale family seem fairly minor and it's closer than using the 7-series values instead in any case.

Fixes c2b7720a7905 ("iio: xilinx-xadc: Add basic support for Ultrascale System Monitor")
---
 drivers/iio/adc/xilinx-xadc-core.c | 17 ++++++++++++++---
 drivers/iio/adc/xilinx-xadc.h      |  2 ++
 2 files changed, 16 insertions(+), 3 deletions(-)
drivers/iio/adc/xilinx-xadc-core.c +14 -3
index 88d523ac7881..1c6314dd4d1d 100644
@@ -456,6 +456,9 @@ static const struct xadc_ops xadc_zynq_ops = {
 	.interrupt_handler = xadc_zynq_interrupt_handler,
 	.update_alarm = xadc_zynq_update_alarm,
 	.type = XADC_TYPE_S7,
+	/* Temp in C = (val * 503.975) / 2**bits - 273.15 */
+	.temp_scale = 503975,
+	.temp_offset = 273150,
 };
 
 static const unsigned int xadc_axi_reg_offsets[] = {
@@ -566,6 +569,9 @@ static const struct xadc_ops xadc_7s_axi_ops = {
 	.interrupt_handler = xadc_axi_interrupt_handler,
 	.flags = XADC_FLAGS_BUFFERED | XADC_FLAGS_IRQ_OPTIONAL,
 	.type = XADC_TYPE_S7,
+	/* Temp in C = (val * 503.975) / 2**bits - 273.15 */
+	.temp_scale = 503975,
+	.temp_offset = 273150,
 };
 
 static const struct xadc_ops xadc_us_axi_ops = {
@@ -577,6 +583,12 @@ static const struct xadc_ops xadc_us_axi_ops = {
 	.interrupt_handler = xadc_axi_interrupt_handler,
 	.flags = XADC_FLAGS_BUFFERED | XADC_FLAGS_IRQ_OPTIONAL,
 	.type = XADC_TYPE_US,
+	/**
+	 * Values below are for UltraScale+ (SYSMONE4) using internal reference.
+	 * See https://docs.xilinx.com/v/u/en-US/ug580-ultrascale-sysmon
+	 */
+	.temp_scale = 509314,
+	.temp_offset = 280231,
 };
 
 static int _xadc_update_adc_reg(struct xadc *xadc, unsigned int reg,
@@ -945,8 +957,7 @@ static int xadc_read_raw(struct iio_dev *indio_dev,
 			*val2 = bits;
 			return IIO_VAL_FRACTIONAL_LOG2;
 		case IIO_TEMP:
-			/* Temp in C = (val * 503.975) / 2**bits - 273.15 */
-			*val = 503975;
+			*val = xadc->ops->temp_scale;
 			*val2 = bits;
 			return IIO_VAL_FRACTIONAL_LOG2;
 		default:
@@ -954,7 +965,7 @@ static int xadc_read_raw(struct iio_dev *indio_dev,
 		}
 	case IIO_CHAN_INFO_OFFSET:
 		/* Only the temperature channel has an offset */
-		*val = -((273150 << bits) / 503975);
+		*val = -((xadc->ops->temp_offset << bits) / xadc->ops->temp_scale);
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SAMP_FREQ:
 		ret = xadc_read_samplerate(xadc);
drivers/iio/adc/xilinx-xadc.h +2 -0
index 7d78ce698967..3036f4d613ff 100644
@@ -85,6 +85,8 @@ struct xadc_ops {
 
 	unsigned int flags;
 	enum xadc_type type;
+	int temp_scale;
+	int temp_offset;
 };
 
 static inline int _xadc_read_adc_reg(struct xadc *xadc, unsigned int reg,
Signature · 7 lines
2.41.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

PATCH 1/2 iio: adc: xilinx-xadc: Don't clobber preset voltage/temperature thresholds

In reply to Robert Hancock

In the probe function, the driver was reading out the thresholds already set in the core, which can be configured by the user in the Vivado tools when the FPGA image is built. However, it later clobbered those values with zero or maximum values. In particular, the overtemperature shutdown threshold register was overwritten with the max value, which effectively prevents the FPGA from shutting down when the desired threshold was eached, potentially risking hardware damage in that case.

Remove this code to leave the preconfigured default threshold values intact.

Fixes bdc8cda1d010 ("iio:adc: Add Xilinx XADC driver")
---
 drivers/iio/adc/xilinx-xadc-core.c | 16 ----------------
 1 file changed, 16 deletions(-)
drivers/iio/adc/xilinx-xadc-core.c +0 -16
index dba73300f894..88d523ac7881 100644
@@ -1429,22 +1429,6 @@ static int xadc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	/* Set thresholds to min/max */
-	for (i = 0; i < 16; i++) {
-		/*
-		 * Set max voltage threshold and both temperature thresholds to
-		 * 0xffff, min voltage threshold to 0.
-		 */
-		if (i % 8 < 4 || i == 7)
-			xadc->threshold[i] = 0xffff;
-		else
-			xadc->threshold[i] = 0;
-		ret = xadc_write_adc_reg(xadc, XADC_REG_THRESHOLD(i),
-			xadc->threshold[i]);
-		if (ret)
-			return ret;
-	}
-
 	/* Go to non-buffered mode */
 	xadc_postdisable(indio_dev);
 
Signature · 7 lines
2.41.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#0 lore raw

cover Xilinx XADC fixes

Fixes for a couple of issues in the Xilinx XADC driver: one where preconfigured temperature/voltage thresholds were being clobbered and potentially breaking overtemperature shutdown, and another for inaccurate temperature readings on UltraScale family devices.

Robert Hancock (2):
iio: adc: xilinx-xadc: Don't clobber preset voltage/temperature
thresholds
iio: adc: xilinx-xadc: Correct temperature offset/scale for UltraScale

 drivers/iio/adc/xilinx-xadc-core.c | 33 +++++++++++++-----------------
 drivers/iio/adc/xilinx-xadc.h      |  2 ++
 2 files changed, 16 insertions(+), 19 deletions(-)
Signature · 1 line
2.41.0
#2 lore raw

Re: [PATCH 1/2] iio: adc: xilinx-xadc: Don't clobber preset voltage/temperature thresholds

In reply to Robert Hancock
Quoted 13 lines · Robert Hancock

In the probe function, the driver was reading out the thresholds already
set in the core, which can be configured by the user in the Vivado tools
when the FPGA image is built. However, it later clobbered those values
with zero or maximum values. In particular, the overtemperature shutdown
threshold register was overwritten with the max value, which effectively
prevents the FPGA from shutting down when the desired threshold was eached, potentially risking hardware damage in that case.

Quoted 2 lines

Remove this code to leave the preconfigured default threshold values intact.

Apparently this change is necessary but not sufficient, as the driver is also disabling all the alarm bits which are needed for the overtemperature shutdown to actually function. Will follow up with a new version shortly.

Quoted 29 lines
Fixes bdc8cda1d010 ("iio:adc: Add Xilinx XADC driver")

---
 drivers/iio/adc/xilinx-xadc-core.c | 16 ----------------

 1 file changed, 16 deletions(-)
drivers/iio/adc/xilinx-xadc-core.c +0 -0
index dba73300f894..88d523ac7881 100644
@@ -1429,22 +1429,6 @@ static int xadc_probe(struct platform_device
 *pdev)
         if (ret)
                 return ret;


-       /* Set thresholds to min/max */
-       for (i = 0; i < 16; i++) {
-               /*
-                * Set max voltage threshold and both temperature thresholds to
-                * 0xffff, min voltage threshold to 0.
-                */
-               if (i % 8 < 4 || i == 7)
-                       xadc->threshold[i] = 0xffff;
-               else
-                       xadc->threshold[i] = 0;
-               ret = xadc_write_adc_reg(xadc, XADC_REG_THRESHOLD(i),

Quoted 8 lines

-                       xadc->threshold[i]);
-               if (ret)
-                       return ret;
-       }
-
        /* Go to non-buffered mode */
        xadc_postdisable(indio_dev);

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel