Skip to contentSkip to conversation

hwmon: (pmbus) Some questions about PMBUS_STATUS

RFC In review [email protected] 2 participants 2 messages Jun 24, 2021

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

RFC 1/1 hwmon: (pmbus) Some questions about PMBUS_STATUS

From: "Ainux.Wang" <[email protected]>

There are some questions about PMBUS_STATUS in core.

---
 drivers/hwmon/pmbus/pmbus_core.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/hwmon/pmbus/pmbus_core.c +13 -0
index bbd745178147..e16c85997148 100644
@@ -2200,6 +2200,19 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
 	 * Some PMBus chips don't support PMBUS_STATUS_WORD, so try
 	 * to use PMBUS_STATUS_BYTE instead if that is the case.
 	 * Bail out if both registers are not supported.
+	 *
+	 * Question 1:
+	 *  Why bail out if both registers are not supported?
+	 *  MP2949A both registers are not supported.
+	 *
+	 * Question 2:
+	 *  Use i2c_smbus_read_word_data() or i2c_smbus_read_byte_data
+	 *  to read, the MP2949A will return undetermined value, although
+	 *  we already known this chip do not support both registers.
+	 *  What should we do?
+	 *  Can we use pmbus_read_status_byte() or pmbus_read_status_word()?
+	 *  and in MP2949A driver's .read_byte_data and .read_word_data to
+	 *  filter out both registers?
 	 */
 	data->read_status = pmbus_read_status_word;
 	ret = i2c_smbus_read_word_data(client, PMBUS_STATUS_WORD);
Signature · 1 line
2.18.1
maintainer
#1 lore raw
Quoted 4 lines · On Thu, Jun 24, 2021 at 10:23:27AM +0800, [email protected] wrote:

From: "Ainux.Wang" <[email protected]>

There are some questions about PMBUS_STATUS in core.

I am curious - why do you think such questions would be appropriate as comment in the code ?

Quoted 10 lines
---
 drivers/hwmon/pmbus/pmbus_core.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/hwmon/pmbus/pmbus_core.c +0 -0
index bbd745178147..e16c85997148 100644

drivers/hwmon/pmbus/pmbus_core.c static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, · line 2207

Quoted 8 lines
drivers/hwmon/pmbus/pmbus_core.c +5 -0
@@ -2200,6 +2200,19 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
 	 * Some PMBus chips don't support PMBUS_STATUS_WORD, so try
 	 * to use PMBUS_STATUS_BYTE instead if that is the case.
 	 * Bail out if both registers are not supported.
+	 *
+	 * Question 1:
+	 *  Why bail out if both registers are not supported?
+	 *  MP2949A both registers are not supported.
+	 *

The status registers are essential for chip operation.

_Normally_ the chip should return an error when trying to access an unsupported command/register, and it should set an error bit in the status register. Obviusly the second part won't work here.

drivers/hwmon/pmbus/pmbus_core.c static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, · line 2212

Quoted 5 lines
drivers/hwmon/pmbus/pmbus_core.c +5 -0
+	 * Question 2:
+	 *  Use i2c_smbus_read_word_data() or i2c_smbus_read_byte_data
+	 *  to read, the MP2949A will return undetermined value, although
+	 *  we already known this chip do not support both registers.
+	 *  What should we do?

PMBus drivers should never call those functions directly but use the functions provided by the PMBUs core.

drivers/hwmon/pmbus/pmbus_core.c static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, · line 2215

Quoted 3 lines
drivers/hwmon/pmbus/pmbus_core.c +3 -0
+	 *  Can we use pmbus_read_status_byte() or pmbus_read_status_word()?
+	 *  and in MP2949A driver's .read_byte_data and .read_word_data to
+	 *  filter out both registers?

You would use those functions, but not to filter out both commands but to simulate one of them and filter out the other.

In general, it is acceptable to simulate or filter out a command if a chip doesn't support it but does not return an error when accessing it. If you may recall, I asked you several times why you wanted to filter out the PMBUS_VOUT_MODE command. You always answered with "the chip does not support it". Again, that is not a reason to filter out a command. However, if a chip does not support a command but does not return an error when accessing it either, it is perfectly valid (and even necessary) to filter out or simulate such unsupported commands. This is, however, only acceptable if a chip does not return an error when trying to access the unsupported registers. Such situations need to be documented in the code, which should include a comment such as "This chip does not support the following command(s) and returns random data when reading from them/it".

Quoted 6 lines
drivers/hwmon/pmbus/pmbus_core.c +0 -0
 	 */
 	data->read_status = pmbus_read_status_word;
 	ret = i2c_smbus_read_word_data(client, PMBUS_STATUS_WORD);
Signature · 1 line
2.18.1