Commit b203f70b authored by Adam Wujek's avatar Adam Wujek

sw/patches/linux: make PEC working for monimod

Note:
PEC is not enabled automatically in monimod.
Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent 00a98b7f
From de289a48724f90476146549751049edf1d255853 Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Wed, 20 Apr 2022 00:40:03 +0200
Subject: [PATCH] hwmod: (pmbus) disable PEC if not enabled
Explicitly disable PEC when the client does not support it.
Without the explicit disable, when the device with the PEC support is
removed later when a device without PEC support is inserted into the same
address, the driver uses the old value of client->flags which contains
the I2C_CLIENT_PEC flag. As a consequence the PEC is used when it should
not be used.
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/hwmon/pmbus/pmbus_core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 8db4f0c8b099..30e7facd97db 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2010,6 +2010,9 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
data->has_status_word = true;
}
+ /* Make sure PEC is disabled, will be enabled later if needed */
+ client->flags &= ~I2C_CLIENT_PEC;
+
/* Enable PEC if the controller supports it */
if (!(data->flags & PMBUS_NO_CAPABILITY)) {
ret = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
--
2.17.1
From 4c95a7eeeb7a38bfd37dade15e9decc9fadf08f9 Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Thu, 19 May 2022 04:10:33 +0200
Subject: [PATCH] hwmon: (pmbus) Check PEC support before reading other
registers
Make sure that the support of PEC is determined before the read of other
registers. Otherwise the validation of PEC can trigger an error on the read
of STATUS_BYTE.
The problematic scenario is the following. A device with enabled PEC
support is up and running and a kernel driver is loaded.
Then the driver is unloaded (or device unbound), the HW device
is reconfigured externally (e.g. by i2cset) to advertise itself as not
supporting PEC. Without the move of the code, at the second load of
the driver (or bind) the status byte or word register is always read with
PEC enabled, which is likely to cause a read error resulting with fail of
a driver load (or bind).
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/hwmon/pmbus/pmbus_core.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 30e7facd97db..947d3fa41373 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -1992,6 +1992,19 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
struct device *dev = &client->dev;
int page, ret;
+ /*
+ * Figure out if PEC is enabled before accessing any other register.
+ * Make sure PEC is disabled, will be enabled later if needed.
+ */
+ client->flags &= ~I2C_CLIENT_PEC;
+
+ /* Enable PEC if the controller supports it */
+ if (!(data->flags & PMBUS_NO_CAPABILITY)) {
+ ret = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
+ if (ret >= 0 && (ret & PB_CAPABILITY_ERROR_CHECK))
+ client->flags |= I2C_CLIENT_PEC;
+ }
+
/*
* Some PMBus chips don't support PMBUS_STATUS_WORD, so try
* to use PMBUS_STATUS_BYTE instead if that is the case.
@@ -2010,15 +2023,6 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
data->has_status_word = true;
}
- /* Make sure PEC is disabled, will be enabled later if needed */
- client->flags &= ~I2C_CLIENT_PEC;
-
- /* Enable PEC if the controller supports it */
- if (!(data->flags & PMBUS_NO_CAPABILITY)) {
- ret = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
- if (ret >= 0 && (ret & PB_CAPABILITY_ERROR_CHECK))
- client->flags |= I2C_CLIENT_PEC;
- }
pmbus_clear_faults(client);
--
2.17.1
From 26d8934faf2f84485f3739285897a2284f83f3bc Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Thu, 19 May 2022 04:03:02 +0200
Subject: [PATCH] i2c: busses: i2c-cadence: fix message length when receive
block message
Needed by hwmon/pmbus_core driver to calculate PEC correctly.
The hwmon/pmbus_core driver relies on bus drivers to update the message
length of receive block transfers. Only in this type of smbus transfer
the length is not known before the transfer is started.
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/i2c/busses/i2c-cadence.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 20ac432a37ea..677082e1b233 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -830,6 +830,13 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
return -ETIMEDOUT;
}
+ /*
+ * Update message len, as i2c/smbus driver (function
+ * i2c_smbus_xfer_emulated) relies on i2c device drivers to do this.
+ */
+ if ((msg->flags & I2C_M_RECV_LEN) && (msg->flags & I2C_M_RD))
+ msg->len = msg->buf[0] + 2; /* add len byte + PEC byte */
+
cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK,
CDNS_I2C_IDR_OFFSET);
--
2.17.1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment