* [PATCH] hwmon: (pmbus) Fix vout margin caching
@ 2022-08-16 14:44 Vincent Whitchurch
2022-08-17 15:32 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Vincent Whitchurch @ 2022-08-16 14:44 UTC (permalink / raw)
To: Guenter Roeck, Jean Delvare
Cc: kernel, Vincent Whitchurch, Mårten Lindahl, linux-hwmon,
linux-kernel
The code currently uses a zero margin to mean not cached, but this
results in the cache being bypassed if the (low) margin is set to zero,
leading to lots of unnecessary SMBus transactions in that case. Use a
negative value instead.
Fixes: 07fb76273db89d93 ("hwmon: (pmbus) Introduce and use cached vout margins")
Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
drivers/hwmon/pmbus/pmbus_core.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index f10bac8860fc..d06b04543fd8 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2861,7 +2861,7 @@ static int pmbus_regulator_get_low_margin(struct i2c_client *client, int page)
.data = -1,
};
- if (!data->vout_low[page]) {
+ if (data->vout_low[page] < 0) {
if (pmbus_check_word_register(client, page, PMBUS_MFR_VOUT_MIN))
s.data = _pmbus_read_word_data(client, page, 0xff,
PMBUS_MFR_VOUT_MIN);
@@ -2887,7 +2887,7 @@ static int pmbus_regulator_get_high_margin(struct i2c_client *client, int page)
.data = -1,
};
- if (!data->vout_high[page]) {
+ if (data->vout_high[page] < 0) {
if (pmbus_check_word_register(client, page, PMBUS_MFR_VOUT_MAX))
s.data = _pmbus_read_word_data(client, page, 0xff,
PMBUS_MFR_VOUT_MAX);
@@ -3320,6 +3320,7 @@ int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info)
struct pmbus_data *data;
size_t groups_num = 0;
int ret;
+ int i;
char *name;
if (!info)
@@ -3353,6 +3354,11 @@ int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info)
data->currpage = -1;
data->currphase = -1;
+ for (i = 0; i < ARRAY_SIZE(data->vout_low); i++) {
+ data->vout_low[i] = -1;
+ data->vout_high[i] = -1;
+ }
+
ret = pmbus_init_common(client, data, info);
if (ret < 0)
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] hwmon: (pmbus) Fix vout margin caching
2022-08-16 14:44 [PATCH] hwmon: (pmbus) Fix vout margin caching Vincent Whitchurch
@ 2022-08-17 15:32 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2022-08-17 15:32 UTC (permalink / raw)
To: Vincent Whitchurch
Cc: Jean Delvare, kernel, Mårten Lindahl, linux-hwmon,
linux-kernel
On Tue, Aug 16, 2022 at 04:44:14PM +0200, Vincent Whitchurch wrote:
> The code currently uses a zero margin to mean not cached, but this
> results in the cache being bypassed if the (low) margin is set to zero,
> leading to lots of unnecessary SMBus transactions in that case. Use a
> negative value instead.
>
> Fixes: 07fb76273db89d93 ("hwmon: (pmbus) Introduce and use cached vout margins")
> Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
Applied.
Thanks,
Guenter
> ---
> drivers/hwmon/pmbus/pmbus_core.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index f10bac8860fc..d06b04543fd8 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -2861,7 +2861,7 @@ static int pmbus_regulator_get_low_margin(struct i2c_client *client, int page)
> .data = -1,
> };
>
> - if (!data->vout_low[page]) {
> + if (data->vout_low[page] < 0) {
> if (pmbus_check_word_register(client, page, PMBUS_MFR_VOUT_MIN))
> s.data = _pmbus_read_word_data(client, page, 0xff,
> PMBUS_MFR_VOUT_MIN);
> @@ -2887,7 +2887,7 @@ static int pmbus_regulator_get_high_margin(struct i2c_client *client, int page)
> .data = -1,
> };
>
> - if (!data->vout_high[page]) {
> + if (data->vout_high[page] < 0) {
> if (pmbus_check_word_register(client, page, PMBUS_MFR_VOUT_MAX))
> s.data = _pmbus_read_word_data(client, page, 0xff,
> PMBUS_MFR_VOUT_MAX);
> @@ -3320,6 +3320,7 @@ int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info)
> struct pmbus_data *data;
> size_t groups_num = 0;
> int ret;
> + int i;
> char *name;
>
> if (!info)
> @@ -3353,6 +3354,11 @@ int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info)
> data->currpage = -1;
> data->currphase = -1;
>
> + for (i = 0; i < ARRAY_SIZE(data->vout_low); i++) {
> + data->vout_low[i] = -1;
> + data->vout_high[i] = -1;
> + }
> +
> ret = pmbus_init_common(client, data, info);
> if (ret < 0)
> return ret;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-08-17 15:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-16 14:44 [PATCH] hwmon: (pmbus) Fix vout margin caching Vincent Whitchurch
2022-08-17 15:32 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox