2022-05-22 11:57:01

by Adam Wujek

[permalink] [raw]
Subject: [PATCH 1/3] hwmon: (pmbus) add a function to check the presence of a block register

Other functions (like pmbus_check_byte_register) cannot be used to check
the presence of a block register, because it will generate error when PEC
is used.

Signed-off-by: Adam Wujek <[email protected]>
---
drivers/hwmon/pmbus/pmbus_core.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 55153a71c170..2634ac1fa3d5 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -421,6 +421,18 @@ static int _pmbus_read_byte_data(struct i2c_client *client, int page, int reg)
return pmbus_read_byte_data(client, page, reg);
}

+static int pmbus_read_block_data(struct i2c_client *client, int page, u8 reg,
+ char *data_buf)
+{
+ int rv;
+
+ rv = pmbus_set_page(client, page);
+ if (rv < 0)
+ return rv;
+
+ return i2c_smbus_read_block_data(client, reg, data_buf);
+}
+
static struct pmbus_sensor *pmbus_find_sensor(struct pmbus_data *data, int page,
int reg)
{
@@ -558,6 +570,20 @@ bool pmbus_check_word_register(struct i2c_client *client, int page, int reg)
}
EXPORT_SYMBOL_NS_GPL(pmbus_check_word_register, PMBUS);

+static bool pmbus_check_block_register(struct i2c_client *client, int page,
+ int reg)
+{
+ int rv;
+ struct pmbus_data *data = i2c_get_clientdata(client);
+ char data_buf[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
+
+ rv = pmbus_read_block_data(client, page, reg, data_buf);
+ if (rv >= 0 && !(data->flags & PMBUS_SKIP_STATUS_CHECK))
+ rv = pmbus_check_status_cml(client);
+ pmbus_clear_fault_page(client, -1);
+ return rv >= 0;
+}
+
const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client *client)
{
struct pmbus_data *data = i2c_get_clientdata(client);
--
2.17.1




2022-05-22 19:51:56

by Adam Wujek

[permalink] [raw]
Subject: [PATCH 2/3] hwmon: (pmbus) use block presence checking for registers PMBUS_MFR_*

When PEC is enabled, using the function to check byte register presence
(pmbus_check_byte_register) for block register generates an error.
The second byte of a block is interpreted as PEC, which is usually wrong.

Signed-off-by: Adam Wujek <[email protected]>
---
Note:
- This commit requires commit which is accepted, but not yet in the kernel
tree:
hwmon: (pmbus) add MFR_* registers to debugfs

drivers/hwmon/pmbus/pmbus_core.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 2634ac1fa3d5..597cbe85df07 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2858,7 +2858,7 @@ static int pmbus_init_debugfs(struct i2c_client *client,
&pmbus_debugfs_ops);
}

- if (pmbus_check_byte_register(client, i, PMBUS_MFR_ID)) {
+ if (pmbus_check_block_register(client, i, PMBUS_MFR_ID)) {
entries[idx].client = client;
entries[idx].page = i;
entries[idx].reg = PMBUS_MFR_ID;
@@ -2868,7 +2868,7 @@ static int pmbus_init_debugfs(struct i2c_client *client,
&pmbus_debugfs_ops_mfr);
}

- if (pmbus_check_byte_register(client, i, PMBUS_MFR_MODEL)) {
+ if (pmbus_check_block_register(client, i, PMBUS_MFR_MODEL)) {
entries[idx].client = client;
entries[idx].page = i;
entries[idx].reg = PMBUS_MFR_MODEL;
@@ -2878,7 +2878,7 @@ static int pmbus_init_debugfs(struct i2c_client *client,
&pmbus_debugfs_ops_mfr);
}

- if (pmbus_check_byte_register(client, i, PMBUS_MFR_REVISION)) {
+ if (pmbus_check_block_register(client, i, PMBUS_MFR_REVISION)) {
entries[idx].client = client;
entries[idx].page = i;
entries[idx].reg = PMBUS_MFR_REVISION;
@@ -2888,7 +2888,7 @@ static int pmbus_init_debugfs(struct i2c_client *client,
&pmbus_debugfs_ops_mfr);
}

- if (pmbus_check_byte_register(client, i, PMBUS_MFR_LOCATION)) {
+ if (pmbus_check_block_register(client, i, PMBUS_MFR_LOCATION)) {
entries[idx].client = client;
entries[idx].page = i;
entries[idx].reg = PMBUS_MFR_LOCATION;
@@ -2898,7 +2898,7 @@ static int pmbus_init_debugfs(struct i2c_client *client,
&pmbus_debugfs_ops_mfr);
}

- if (pmbus_check_byte_register(client, i, PMBUS_MFR_DATE)) {
+ if (pmbus_check_block_register(client, i, PMBUS_MFR_DATE)) {
entries[idx].client = client;
entries[idx].page = i;
entries[idx].reg = PMBUS_MFR_DATE;
@@ -2908,7 +2908,7 @@ static int pmbus_init_debugfs(struct i2c_client *client,
&pmbus_debugfs_ops_mfr);
}

- if (pmbus_check_byte_register(client, i, PMBUS_MFR_SERIAL)) {
+ if (pmbus_check_block_register(client, i, PMBUS_MFR_SERIAL)) {
entries[idx].client = client;
entries[idx].page = i;
entries[idx].reg = PMBUS_MFR_SERIAL;
--
2.17.1