hwmod: (pmbus) disable PEC if not enabled
PATCH 1/1 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.
--- drivers/hwmon/pmbus/pmbus_core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hwmon/pmbus/pmbus_core.c +2 -0
@@ -2014,6 +2014,8 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, ret =i2c_smbus_read_byte_data (client,PMBUS_CAPABILITY );if (ret >=0 && (ret &PB_CAPABILITY_ERROR_CHECK )) client->flags |=I2C_CLIENT_PEC ; +else + client->flags &= ~I2C_CLIENT_PEC ;pmbus_clear_faults (client);
--
2.17.1
Guenter Roeck
maintainerQuoted 6 lines · Adam Wujek
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 ofclient->flagswhich contains theI2C_CLIENT_PECflag. As a consequence the PEC is used when it should not.
How can that happen ? I would assume the I2C device gets deleted and re-created in that case, which should clear the PEC flag.
Guenter
Quoted 22 lines
Signed-off-by Adam Wujek <[email protected]>--- drivers/hwmon/pmbus/pmbus_core.c | 2 ++ 1 file changed, 2 insertions(+)drivers/hwmon/pmbus/pmbus_core.c +2
-1@@ -2014,6 +2014,8 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, ret =i2c_smbus_read_byte_data (client,PMBUS_CAPABILITY );if (ret >=0 && (ret &PB_CAPABILITY_ERROR_CHECK )) client->flags |=I2C_CLIENT_PEC ; +else + client->flags &= ~I2C_CLIENT_PEC ;pmbus_clear_faults (client); --2.17.1
------- Original Message -------
Quoted 11 lines · Guenter Roeck
Quoted 5 lines · Adam Wujek
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 ofclient->flagswhich contains theI2C_CLIENT_PECflag. As a consequence the PEC is used when it should not.
Quoted 4 lines
How can that happen ? I would assume the I2C device gets deleted and re-created in that case, which should clear the PEC flag.
Guenter
In my case it was when I unloaded the driver for the I2C slave, changed the advertised PEC value in PMBUS_CAPABILITY register on slave. Then loaded the driver. When the switch was from disable->enable it worked as expected (this case was already covered), but when the PEC was set in the slave from enabled->disabled it was still using PEC to communicate.
Adam
Quoted 21 lines
Quoted 21 lines
Signed-off-by Adam Wujek [email protected]---
drivers/hwmon/pmbus/pmbus_core.c| 2 ++1 file changed, 2 insertions(+)drivers/hwmon/pmbus/pmbus_core.c +2
-1@@ -2014,6 +2014,8 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, ret =i2c_smbus_read_byte_data (client,PMBUS_CAPABILITY );if (ret >=0 && (ret &PB_CAPABILITY_ERROR_CHECK )) client->flags |=I2C_CLIENT_PEC ; +else + client->flags &= ~I2C_CLIENT_PEC ;pmbus_clear_faults (client); --2.17.1
Guenter Roeck
maintainerQuoted 13 lines · wujek dev
------- Original Message -------
Quoted 11 lines · Guenter Roeck
Quoted 5 lines · Adam Wujek
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 ofclient->flagswhich contains theI2C_CLIENT_PECflag. As a consequence the PEC is used when it should not.
Quoted 5 lines
Quoted 4 lines
How can that happen ? I would assume the I2C device gets deleted and re-created in that case, which should clear the PEC flag.
Guenter
In my case it was when I unloaded the driver for the I2C slave, changed the advertised PEC value in
PMBUS_CAPABILITYregister on slave. Then loaded the driver. When the switch was fromdisable->enableit worked as expected (this case was already covered), but when the PEC was set in the slave fromenabled->disabledit was still using PEC to communicate.
So it is really the same device, only you unload the driver, change the device configuration (presumably with i2cset commands), and load it again. Please explain that in more detail in the commit description.
Thanks,
Guenter
Guenter Roeck
maintainerQuoted 16 lines · Adam Wujek
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 ofclient->flagswhich contains theI2C_CLIENT_PECflag. As a consequence the PEC is used when it should not.Signed-off-by Adam Wujek <[email protected]>--- drivers/hwmon/pmbus/pmbus_core.c | 2 ++ 1 file changed, 2 insertions(+)drivers/hwmon/pmbus/pmbus_core.c +0
-0
drivers/hwmon/pmbus/pmbus_core.c static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, · line 2019
Quoted 6 lines
drivers/hwmon/pmbus/pmbus_core.c +2
-0@@ -2014,6 +2014,8 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, ret =i2c_smbus_read_byte_data (client,PMBUS_CAPABILITY );if (ret >=0 && (ret &PB_CAPABILITY_ERROR_CHECK )) client->flags |=I2C_CLIENT_PEC ; +else + client->flags &= ~I2C_CLIENT_PEC ;
I just realized that this patch is not based on the latest kernel version. Please rebase.
Guenter
PATCH 1/1 hwmod: (pmbus) disable PEC if not enabled
Explicitly disable PEC when the client does not support it. The problematic scenario is the following. A device with enabled PEC support is up and running, a kernel driver 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 a new code, at the second load of the driver (or bind) the "flags" variable is not updated to avoid PEC usage. As a consequence the further communication with the device is done with the PEC enabled, which is wrong.
--- drivers/hwmon/pmbus/pmbus_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/pmbus_core.c +2 -1
@@ -2334,7 +2334,8 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, client->flags |=I2C_CLIENT_PEC ; } } - } + }else + client->flags &= ~I2C_CLIENT_PEC ;/* * Check if the chip is write protected. If it is, we can not clear
--
2.25.1
Guenter Roeck
maintainerQuoted 11 lines · Adam Wujek
Explicitly disable PEC when the client does not support it. The problematic scenario is the following. A device with enabled PEC support is up and running, a kernel driver 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 a new code, at the second load of the driver (or bind) the "flags" variable is not updated to avoid PEC usage. As a consequence the further communication with the device is done with the PEC enabled, which is wrong.Signed-off-by Adam Wujek <[email protected]>
Subject should start with hwmon:. Please version your patches, and provide change logs.
Quoted 9 lines
--- drivers/hwmon/pmbus/pmbus_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/hwmon/pmbus/pmbus_core.c +0
-0
drivers/hwmon/pmbus/pmbus_core.c static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, · line 2338
Quoted 6 lines
drivers/hwmon/pmbus/pmbus_core.c +2
-1@@ -2334,7 +2334,8 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, client->flags |=I2C_CLIENT_PEC ; } } - } + }else + client->flags &= ~I2C_CLIENT_PEC ;
Since if() is in {}, else should be in {} as well.
Guenter
Quoted 7 lines
drivers/hwmon/pmbus/pmbus_core.c +0
-1/* * Check if the chip is write protected. If it is, we can not clear -- 2.25.1
PATCH v3 1/1 hwmon: (pmbus) disable PEC if not enabled
Explicitly disable PEC when the client does not support it. 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 a new code, at the second load of the driver (or bind) the "flags" variable is not updated to avoid PEC usage. As a consequence the further communication with the device is done with the PEC enabled, which is wrong and may fail.
The implementation first disable the I2C_CLIENT_PEC flag, then the old code enable it if needed.
---
Notes:
Changes in v2:
- Rebase to the latest kernel
- Update commit message
Changes in v3:
- Rework the patch, disable the flag first, then enable if needed. Adding three else statements to disable the flag will make the code less readable.
- Update commit message
drivers/hwmon/pmbus/pmbus_core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hwmon/pmbus/pmbus_core.c +3 -0
@@ -2326,6 +2326,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 and bus supports it */ if (!(data->flags &PMBUS_NO_CAPABILITY )) { ret =i2c_smbus_read_byte_data (client,PMBUS_CAPABILITY );
--
2.25.1