Skip to content

Commit e2bd8c2

Browse files
robhancocksedjic23
authored andcommitted
iio: adc: xilinx-xadc: Correct temperature offset/scale for UltraScale
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: c2b7720 ("iio: xilinx-xadc: Add basic support for Ultrascale System Monitor") Signed-off-by: Robert Hancock <robert.hancock@calian.com> Acked-by: O'Griofa, Conall <conall.ogriofa@amd.com> Tested-by: O'Griofa, Conall <conall.ogriofa@amd.com> Link: https://lore.kernel.org/r/20230915001019.2862964-3-robert.hancock@calian.com Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 8d6b3ea commit e2bd8c2

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ static const struct xadc_ops xadc_zynq_ops = {
456456
.interrupt_handler = xadc_zynq_interrupt_handler,
457457
.update_alarm = xadc_zynq_update_alarm,
458458
.type = XADC_TYPE_S7,
459+
/* Temp in C = (val * 503.975) / 2**bits - 273.15 */
460+
.temp_scale = 503975,
461+
.temp_offset = 273150,
459462
};
460463

461464
static const unsigned int xadc_axi_reg_offsets[] = {
@@ -566,6 +569,9 @@ static const struct xadc_ops xadc_7s_axi_ops = {
566569
.interrupt_handler = xadc_axi_interrupt_handler,
567570
.flags = XADC_FLAGS_BUFFERED | XADC_FLAGS_IRQ_OPTIONAL,
568571
.type = XADC_TYPE_S7,
572+
/* Temp in C = (val * 503.975) / 2**bits - 273.15 */
573+
.temp_scale = 503975,
574+
.temp_offset = 273150,
569575
};
570576

571577
static const struct xadc_ops xadc_us_axi_ops = {
@@ -577,6 +583,12 @@ static const struct xadc_ops xadc_us_axi_ops = {
577583
.interrupt_handler = xadc_axi_interrupt_handler,
578584
.flags = XADC_FLAGS_BUFFERED | XADC_FLAGS_IRQ_OPTIONAL,
579585
.type = XADC_TYPE_US,
586+
/**
587+
* Values below are for UltraScale+ (SYSMONE4) using internal reference.
588+
* See https://docs.xilinx.com/v/u/en-US/ug580-ultrascale-sysmon
589+
*/
590+
.temp_scale = 509314,
591+
.temp_offset = 280231,
580592
};
581593

582594
static int _xadc_update_adc_reg(struct xadc *xadc, unsigned int reg,
@@ -945,16 +957,15 @@ static int xadc_read_raw(struct iio_dev *indio_dev,
945957
*val2 = bits;
946958
return IIO_VAL_FRACTIONAL_LOG2;
947959
case IIO_TEMP:
948-
/* Temp in C = (val * 503.975) / 2**bits - 273.15 */
949-
*val = 503975;
960+
*val = xadc->ops->temp_scale;
950961
*val2 = bits;
951962
return IIO_VAL_FRACTIONAL_LOG2;
952963
default:
953964
return -EINVAL;
954965
}
955966
case IIO_CHAN_INFO_OFFSET:
956967
/* Only the temperature channel has an offset */
957-
*val = -((273150 << bits) / 503975);
968+
*val = -((xadc->ops->temp_offset << bits) / xadc->ops->temp_scale);
958969
return IIO_VAL_INT;
959970
case IIO_CHAN_INFO_SAMP_FREQ:
960971
ret = xadc_read_samplerate(xadc);

drivers/iio/adc/xilinx-xadc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ struct xadc_ops {
8585

8686
unsigned int flags;
8787
enum xadc_type type;
88+
int temp_scale;
89+
int temp_offset;
8890
};
8991

9092
static inline int _xadc_read_adc_reg(struct xadc *xadc, unsigned int reg,

0 commit comments

Comments
 (0)