All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Set sensor->data to -ENODATA after write
@ 2021-02-01 19:59 Erik Rosen
  2021-02-01 19:59 ` [PATCH 1/2] Clear sensor data after chip write Erik Rosen
  2021-02-01 19:59 ` [PATCH 2/2] Remove unnecessary pmbus_clear_cache function call Erik Rosen
  0 siblings, 2 replies; 5+ messages in thread
From: Erik Rosen @ 2021-02-01 19:59 UTC (permalink / raw)
  To: linux-kernel, linux-hwmon, Guenter Roeck, Jean Delvare; +Cc: Erik Rosen

Problem:
When clear_cache() is called from within the pmbus_write_word_data()
callback, the sensor data is set _after_ the function returns to
pmbus_set_sensor(). The effect is that all sensor values are cleared
except the one just written to. This behaviour prevents reloading of
the sensor value as expected in the lm25066 driver.

Proposed solution:
Set the data field to -ENODATA after updates of the sensor value.
This will force a read from the chip next time the sensor value is
read. This will also ensure that the cached value matches the actual
value stored in the chip.
The impact would be that a sensor read after a write will always
trigger a chip access.


Erik Rosen (2):
  Clear sensor data after chip write
  Remove unnecessary pmbus_clear_cache function call

 drivers/hwmon/pmbus/lm25066.c    | 5 -----
 drivers/hwmon/pmbus/pmbus_core.c | 2 +-
 2 files changed, 1 insertion(+), 6 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] Clear sensor data after chip write
  2021-02-01 19:59 [PATCH 0/2] Set sensor->data to -ENODATA after write Erik Rosen
@ 2021-02-01 19:59 ` Erik Rosen
  2021-02-02  0:24   ` Guenter Roeck
  2021-02-01 19:59 ` [PATCH 2/2] Remove unnecessary pmbus_clear_cache function call Erik Rosen
  1 sibling, 1 reply; 5+ messages in thread
From: Erik Rosen @ 2021-02-01 19:59 UTC (permalink / raw)
  To: linux-kernel, linux-hwmon, Guenter Roeck, Jean Delvare; +Cc: Erik Rosen

Set the sensor->data field to -ENODATA to force a chip access next time
the sensor value is read.

Signed-off-by: Erik Rosen <erik.rosen@metormote.com>
---
 drivers/hwmon/pmbus/pmbus_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 192442b3b7a2..e27f23eee1e3 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -974,7 +974,7 @@ static ssize_t pmbus_set_sensor(struct device *dev,
 	if (ret < 0)
 		rv = ret;
 	else
-		sensor->data = regval;
+		sensor->data = -ENODATA;
 	mutex_unlock(&data->update_lock);
 	return rv;
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] Remove unnecessary pmbus_clear_cache function call
  2021-02-01 19:59 [PATCH 0/2] Set sensor->data to -ENODATA after write Erik Rosen
  2021-02-01 19:59 ` [PATCH 1/2] Clear sensor data after chip write Erik Rosen
@ 2021-02-01 19:59 ` Erik Rosen
  2021-02-02  0:26   ` Guenter Roeck
  1 sibling, 1 reply; 5+ messages in thread
From: Erik Rosen @ 2021-02-01 19:59 UTC (permalink / raw)
  To: linux-kernel, linux-hwmon, Guenter Roeck, Jean Delvare; +Cc: Erik Rosen

It is no longer necessary to clear the cache to update the sensor value
from the chip.

Signed-off-by: Erik Rosen <erik.rosen@metormote.com>
---
 drivers/hwmon/pmbus/lm25066.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
index c75a6bf39641..e9a66fd9e144 100644
--- a/drivers/hwmon/pmbus/lm25066.c
+++ b/drivers/hwmon/pmbus/lm25066.c
@@ -371,21 +371,18 @@ static int lm25066_write_word_data(struct i2c_client *client, int page, int reg,
 	case PMBUS_VIN_OV_WARN_LIMIT:
 		word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit);
 		ret = pmbus_write_word_data(client, 0, reg, word);
-		pmbus_clear_cache(client);
 		break;
 	case PMBUS_IIN_OC_WARN_LIMIT:
 		word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit);
 		ret = pmbus_write_word_data(client, 0,
 					    LM25066_MFR_IIN_OC_WARN_LIMIT,
 					    word);
-		pmbus_clear_cache(client);
 		break;
 	case PMBUS_PIN_OP_WARN_LIMIT:
 		word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit);
 		ret = pmbus_write_word_data(client, 0,
 					    LM25066_MFR_PIN_OP_WARN_LIMIT,
 					    word);
-		pmbus_clear_cache(client);
 		break;
 	case PMBUS_VIRT_VMON_UV_WARN_LIMIT:
 		/* Adjust from VIN coefficients (for LM25056) */
@@ -393,7 +390,6 @@ static int lm25066_write_word_data(struct i2c_client *client, int page, int reg,
 		word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit);
 		ret = pmbus_write_word_data(client, 0,
 					    LM25056_VAUX_UV_WARN_LIMIT, word);
-		pmbus_clear_cache(client);
 		break;
 	case PMBUS_VIRT_VMON_OV_WARN_LIMIT:
 		/* Adjust from VIN coefficients (for LM25056) */
@@ -401,7 +397,6 @@ static int lm25066_write_word_data(struct i2c_client *client, int page, int reg,
 		word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit);
 		ret = pmbus_write_word_data(client, 0,
 					    LM25056_VAUX_OV_WARN_LIMIT, word);
-		pmbus_clear_cache(client);
 		break;
 	case PMBUS_VIRT_RESET_PIN_HISTORY:
 		ret = pmbus_write_byte(client, 0, LM25066_CLEAR_PIN_PEAK);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] Clear sensor data after chip write
  2021-02-01 19:59 ` [PATCH 1/2] Clear sensor data after chip write Erik Rosen
@ 2021-02-02  0:24   ` Guenter Roeck
  0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2021-02-02  0:24 UTC (permalink / raw)
  To: Erik Rosen; +Cc: linux-kernel, linux-hwmon, Jean Delvare

On Mon, Feb 01, 2021 at 08:59:28PM +0100, Erik Rosen wrote:
> Set the sensor->data field to -ENODATA to force a chip access next time
> the sensor value is read.
> 
> Signed-off-by: Erik Rosen <erik.rosen@metormote.com>

Applied. Please remember to add subsystem and driver to future patches.
In this case, I added:

hwmon: (pmbus) ...

Thanks,
Guenter

> ---
>  drivers/hwmon/pmbus/pmbus_core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index 192442b3b7a2..e27f23eee1e3 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -974,7 +974,7 @@ static ssize_t pmbus_set_sensor(struct device *dev,
>  	if (ret < 0)
>  		rv = ret;
>  	else
> -		sensor->data = regval;
> +		sensor->data = -ENODATA;
>  	mutex_unlock(&data->update_lock);
>  	return rv;
>  }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] Remove unnecessary pmbus_clear_cache function call
  2021-02-01 19:59 ` [PATCH 2/2] Remove unnecessary pmbus_clear_cache function call Erik Rosen
@ 2021-02-02  0:26   ` Guenter Roeck
  0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2021-02-02  0:26 UTC (permalink / raw)
  To: Erik Rosen; +Cc: linux-kernel, linux-hwmon, Jean Delvare

On Mon, Feb 01, 2021 at 08:59:29PM +0100, Erik Rosen wrote:
> It is no longer necessary to clear the cache to update the sensor value
> from the chip.
> 
> Signed-off-by: Erik Rosen <erik.rosen@metormote.com>

Applied, after prepending subject with "hwmon: (pmbus/lm25066)".

Thanks,
Guenter

> ---
>  drivers/hwmon/pmbus/lm25066.c | 5 -----
>  1 file changed, 5 deletions(-)
> 
> diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
> index c75a6bf39641..e9a66fd9e144 100644
> --- a/drivers/hwmon/pmbus/lm25066.c
> +++ b/drivers/hwmon/pmbus/lm25066.c
> @@ -371,21 +371,18 @@ static int lm25066_write_word_data(struct i2c_client *client, int page, int reg,
>  	case PMBUS_VIN_OV_WARN_LIMIT:
>  		word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit);
>  		ret = pmbus_write_word_data(client, 0, reg, word);
> -		pmbus_clear_cache(client);
>  		break;
>  	case PMBUS_IIN_OC_WARN_LIMIT:
>  		word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit);
>  		ret = pmbus_write_word_data(client, 0,
>  					    LM25066_MFR_IIN_OC_WARN_LIMIT,
>  					    word);
> -		pmbus_clear_cache(client);
>  		break;
>  	case PMBUS_PIN_OP_WARN_LIMIT:
>  		word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit);
>  		ret = pmbus_write_word_data(client, 0,
>  					    LM25066_MFR_PIN_OP_WARN_LIMIT,
>  					    word);
> -		pmbus_clear_cache(client);
>  		break;
>  	case PMBUS_VIRT_VMON_UV_WARN_LIMIT:
>  		/* Adjust from VIN coefficients (for LM25056) */
> @@ -393,7 +390,6 @@ static int lm25066_write_word_data(struct i2c_client *client, int page, int reg,
>  		word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit);
>  		ret = pmbus_write_word_data(client, 0,
>  					    LM25056_VAUX_UV_WARN_LIMIT, word);
> -		pmbus_clear_cache(client);
>  		break;
>  	case PMBUS_VIRT_VMON_OV_WARN_LIMIT:
>  		/* Adjust from VIN coefficients (for LM25056) */
> @@ -401,7 +397,6 @@ static int lm25066_write_word_data(struct i2c_client *client, int page, int reg,
>  		word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit);
>  		ret = pmbus_write_word_data(client, 0,
>  					    LM25056_VAUX_OV_WARN_LIMIT, word);
> -		pmbus_clear_cache(client);
>  		break;
>  	case PMBUS_VIRT_RESET_PIN_HISTORY:
>  		ret = pmbus_write_byte(client, 0, LM25066_CLEAR_PIN_PEAK);

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-02  0:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-01 19:59 [PATCH 0/2] Set sensor->data to -ENODATA after write Erik Rosen
2021-02-01 19:59 ` [PATCH 1/2] Clear sensor data after chip write Erik Rosen
2021-02-02  0:24   ` Guenter Roeck
2021-02-01 19:59 ` [PATCH 2/2] Remove unnecessary pmbus_clear_cache function call Erik Rosen
2021-02-02  0:26   ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.