Skip to contentSkip to conversation

hwmon: (pmbus/xdpe12284) Add callback for vout limits conversion

PATCH Superseded Vadim Pasternak 2 participants 3 messages Feb 24, 2020 Hardware monitoring

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hwmon: (pmbus/xdpe12284) Add callback for vout limits conversion

Provide read_word_data() callback for overvoltage and undervoltage output readouts conversion. These registers are presented in 'slinear11' format, while default conversion for 'vout' class for the devices is 'vid'. It is resulted in wrong conversion in pmbus_reg2data() for in{3-4}_lcrit and in{3-4}_crit attributes.
)

Fixes aaafb7c8eb1c ("hwmon: (pmbus) Add support for Infineon Multi-phase xdpe122 family controllers")

---
v1->v2:
Comments pointed out by Guenter:
- Drop reg2data() callback, provide conversion through read_word_data() callback instead.

---
 drivers/hwmon/pmbus/xdpe12284.c | 51 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
drivers/hwmon/pmbus/xdpe12284.c +51 -0
index ecd9b65627ec..44b737d0bc24 100644
@@ -18,6 +18,56 @@
 #define XDPE122_AMD_625MV		0x10 /* AMD mode 6.25mV */
 #define XDPE122_PAGE_NUM		2
 
+static int xdpe122_read_word_data(struct i2c_client *client, int page,
+				  int phase, int reg)
+{
+	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+	long val;
+	s16 exponent;
+	s32 mantissa;
+	int ret;
+
+	switch (reg) {
+	case PMBUS_VOUT_OV_FAULT_LIMIT:
+	case PMBUS_VOUT_UV_FAULT_LIMIT:
+		ret = pmbus_read_word_data(client, page, phase, reg);
+		if (ret < 0)
+			return ret;
+
+		/* Convert register value to LINEAR11 data. */
+		exponent = ((s16)ret) >> 11;
+		mantissa = ((s16)((ret & GENMASK(10, 0)) << 5)) >> 5;
+		val = mantissa * 1000L;
+		if (exponent >= 0)
+			val <<= exponent;
+		else
+			val >>= -exponent;
+
+		/* Convert data to VID register. */
+		switch (info->vrm_version[page]) {
+		case vr13:
+			if (val >= 500)
+				return 1 + DIV_ROUND_CLOSEST(val - 500, 10);
+		case vr12:
+			if (val >= 250)
+				return 1 + DIV_ROUND_CLOSEST(val - 250, 5);
+		case imvp9:
+			if (val >= 200)
+				return 1 + DIV_ROUND_CLOSEST(val - 200, 10);
+		case amd625mv:
+			if (val >= 200 && val <= 968750)
+				return DIV_ROUND_CLOSEST((1550 - val) * 100,
+							 625);
+		default:
+			return -EINVAL;
+		}
+	default:
+		return -ENODATA;
+	}
+
+	return 0;
+}
+
 static int xdpe122_identify(struct i2c_client *client,
 			    struct pmbus_driver_info *info)
 {
@@ -70,6 +120,7 @@ static struct pmbus_driver_info xdpe122_info = {
 		PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
 		PMBUS_HAVE_POUT | PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
 	.identify = xdpe122_identify,
+	.read_word_data = xdpe122_read_word_data,
 };
 
 static int xdpe122_probe(struct i2c_client *client,
Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 45 lines · Vadim Pasternak

Provide read_word_data() callback for overvoltage and undervoltage output readouts conversion. These registers are presented in 'slinear11' format, while default conversion for 'vout' class for the devices is 'vid'. It is resulted in wrong conversion in pmbus_reg2data() for in{3-4}_lcrit and in{3-4}_crit attributes.
)

Fixes aaafb7c8eb1c ("hwmon: (pmbus) Add support for Infineon Multi-phase xdpe122 family controllers")

---
v1->v2:
Comments pointed out by Guenter:
- Drop reg2data() callback, provide conversion through read_word_data() callback instead.

---
 drivers/hwmon/pmbus/xdpe12284.c | 51 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
drivers/hwmon/pmbus/xdpe12284.c +20 -0
index ecd9b65627ec..44b737d0bc24 100644
@@ -18,6 +18,56 @@
 #define XDPE122_AMD_625MV		0x10 /* AMD mode 6.25mV */
 #define XDPE122_PAGE_NUM		2
 
+static int xdpe122_read_word_data(struct i2c_client *client, int page,
+				  int phase, int reg)
+{
+	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+	long val;
+	s16 exponent;
+	s32 mantissa;
+	int ret;
+
+	switch (reg) {
+	case PMBUS_VOUT_OV_FAULT_LIMIT:
+	case PMBUS_VOUT_UV_FAULT_LIMIT:
+		ret = pmbus_read_word_data(client, page, phase, reg);
+		if (ret < 0)
+			return ret;
+
+		/* Convert register value to LINEAR11 data. */
+		exponent = ((s16)ret) >> 11;
+		mantissa = ((s16)((ret & GENMASK(10, 0)) << 5)) >> 5;
+		val = mantissa * 1000L;

drivers/hwmon/pmbus/xdpe12284.c line 50

Quoted 10 lines
drivers/hwmon/pmbus/xdpe12284.c +10 -0
+		if (exponent >= 0)
+			val <<= exponent;
+		else
+			val >>= -exponent;
+
+		/* Convert data to VID register. */
+		switch (info->vrm_version[page]) {
+		case vr13:
+			if (val >= 500)
+				return 1 + DIV_ROUND_CLOSEST(val - 500, 10);
			return 0; ?

drivers/hwmon/pmbus/xdpe12284.c line 53

Quoted 3 lines
drivers/hwmon/pmbus/xdpe12284.c +3 -0
+		case vr12:
+			if (val >= 250)
+				return 1 + DIV_ROUND_CLOSEST(val - 250, 5);
			return 0; ?

drivers/hwmon/pmbus/xdpe12284.c line 56

Quoted 3 lines
drivers/hwmon/pmbus/xdpe12284.c +3 -0
+		case imvp9:
+			if (val >= 200)
+				return 1 + DIV_ROUND_CLOSEST(val - 200, 10);
			return 0; ?

drivers/hwmon/pmbus/xdpe12284.c line 60

Quoted 4 lines
drivers/hwmon/pmbus/xdpe12284.c +4 -0
+		case amd625mv:
+			if (val >= 200 && val <= 968750)
+				return DIV_ROUND_CLOSEST((1550 - val) * 100,
+							 625);
			return 0; ?

Also, are you sure that this calculation is correct ? 1550 - val is almost always negative.

Quoted 24 lines
drivers/hwmon/pmbus/xdpe12284.c +11 -0
+		default:
+			return -EINVAL;
+		}
+	default:
+		return -ENODATA;
+	}
+
+	return 0;
+}
+
 static int xdpe122_identify(struct i2c_client *client,
 			    struct pmbus_driver_info *info)
 {
@@ -70,6 +120,7 @@ static struct pmbus_driver_info xdpe122_info = {
 		PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
 		PMBUS_HAVE_POUT | PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
 	.identify = xdpe122_identify,
+	.read_word_data = xdpe122_read_word_data,
 };
 
 static int xdpe122_probe(struct i2c_client *client,
Signature · 1 line
2.11.0
#2 lore raw
Quoted 83 lines

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Tuesday, February 25, 2020 12:13 AM
To: Vadim Pasternak <[email protected]>
Cc: [email protected]
Subject: Re: [hwmon-next v2] hwmon: (pmbus/xdpe12284) Add callback for vout limits conversion

Quoted 48 lines · Vadim Pasternak

Provide read_word_data() callback for overvoltage and undervoltage output readouts conversion. These registers are presented in 'slinear11' format, while default conversion for 'vout' class for the devices is 'vid'. It is resulted in wrong conversion in pmbus_reg2data() for in{3-4}_lcrit and in{3-4}_crit attributes. )

Fixes aaafb7c8eb1c ("hwmon: (pmbus) Add support for Infineon

Multi-phase xdpe122 family controllers")

---
v1->v2:
Comments pointed out by Guenter:
- Drop reg2data() callback, provide conversion through read_word_data() callback instead.

---
 drivers/hwmon/pmbus/xdpe12284.c | 51
+++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
(quoted diff) +0 -0

b/drivers/hwmon/pmbus/xdpe12284.c index ecd9b65627ec..44b737d0bc24 100644

drivers/hwmon/pmbus/xdpe12284.c +20 -0
@@ -18,6 +18,56 @@
 #define XDPE122_AMD_625MV		0x10 /* AMD mode 6.25mV */
 #define XDPE122_PAGE_NUM		2
 
+static int xdpe122_read_word_data(struct i2c_client *client, int page,
+				  int phase, int reg)
+{
+	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+	long val;
+	s16 exponent;
+	s32 mantissa;
+	int ret;
+
+	switch (reg) {
+	case PMBUS_VOUT_OV_FAULT_LIMIT:
+	case PMBUS_VOUT_UV_FAULT_LIMIT:
+		ret = pmbus_read_word_data(client, page, phase, reg);
+		if (ret < 0)
+			return ret;
+
+		/* Convert register value to LINEAR11 data. */
+		exponent = ((s16)ret) >> 11;
+		mantissa = ((s16)((ret & GENMASK(10, 0)) << 5)) >> 5;
+		val = mantissa * 1000L;

drivers/hwmon/pmbus/xdpe12284.c line 50

Quoted 10 lines
drivers/hwmon/pmbus/xdpe12284.c +10 -0
+		if (exponent >= 0)
+			val <<= exponent;
+		else
+			val >>= -exponent;
+
+		/* Convert data to VID register. */
+		switch (info->vrm_version[page]) {
+		case vr13:
+			if (val >= 500)
+				return 1 + DIV_ROUND_CLOSEST(val - 500, 10);
			return 0; ?

drivers/hwmon/pmbus/xdpe12284.c line 53

Quoted 3 lines
drivers/hwmon/pmbus/xdpe12284.c +3 -0
+		case vr12:
+			if (val >= 250)
+				return 1 + DIV_ROUND_CLOSEST(val - 250, 5);
			return 0; ?

drivers/hwmon/pmbus/xdpe12284.c line 56

Quoted 3 lines
drivers/hwmon/pmbus/xdpe12284.c +3 -0
+		case imvp9:
+			if (val >= 200)
+				return 1 + DIV_ROUND_CLOSEST(val - 200, 10);
			return 0; ?
Quoted 5 lines

drivers/hwmon/pmbus/xdpe12284.c

Quoted 3 lines
drivers/hwmon/pmbus/xdpe12284.c +3 -0
+		case amd625mv:
+			if (val >= 200 && val <= 968750)
+				return DIV_ROUND_CLOSEST((1550 - val) *

100,

drivers/hwmon/pmbus/xdpe12284.c line 60

Quoted 1 line
drivers/hwmon/pmbus/xdpe12284.c +1 -0
+							 625);

Oh, it should be 1550.
(155000 - 0 * 625) / 100 = 1550.
Sorry.

Quoted 30 lines
			return 0; ?

Also, are you sure that this calculation is correct ? 1550 - val is almost always negative.

drivers/hwmon/pmbus/xdpe12284.c

Quoted 12 lines
drivers/hwmon/pmbus/xdpe12284.c +10 -0
+		default:
+			return -EINVAL;
+		}
+	default:
+		return -ENODATA;
+	}
+
+	return 0;
+}
+
 static int xdpe122_identify(struct i2c_client *client,
 			    struct pmbus_driver_info *info)  { @@ -70,6 +120,7

@@ static

drivers/hwmon/pmbus/xdpe12284.c

Quoted 3 lines
drivers/hwmon/pmbus/xdpe12284.c +0 -0
 struct pmbus_driver_info xdpe122_info = {
drivers/hwmon/pmbus/xdpe12284.c +0 -0
 		PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
 		PMBUS_HAVE_POUT | PMBUS_HAVE_PIN |

PMBUS_HAVE_STATUS_INPUT,

Quoted 8 lines
drivers/hwmon/pmbus/xdpe12284.c +1 -1
 	.identify = xdpe122_identify,
+	.read_word_data = xdpe122_read_word_data,
 };
 
 static int xdpe122_probe(struct i2c_client *client,
--

2.11.0