linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] hwmon: adm1275: Make sure we are reading enough data for different chips
@ 2020-07-09  4:06 Chu Lin
  2020-07-09 14:05 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Chu Lin @ 2020-07-09  4:06 UTC (permalink / raw)
  To: linux
  Cc: belgaied, jasonling, jdelvare, linchuyuan, linux-hwmon,
	linux-kernel, zhongqil

Issue:
When PEC is enabled, binding adm1272 to the adm1275 would
fail due to PEC error. See below:
adm1275: probe of xxxx failed with error -74

Diagnosis:
Per the datasheet of adm1272, adm1278, adm1293 and amd1294,
PMON_CONFIG (0xd4) is 16bits wide. On the other hand,
PMON_CONFIG (0xd4) for adm1275 is 8bits wide. The driver should not
assume everything is 8bits wide and read only 8bits from it.

Solution:
If it is adm1272, adm1278, adm1293 and adm1294, use i2c_read_word.
Else, use i2c_read_byte

Testing:
Binding adm1272 to the driver.
The change is only tested on adm1272.

Signed-off-by: Chu Lin <linchuyuan@google.com>
---

ChangeLog v1 -> v2
  - Rename config_read_fn_ptr to config_read_fn
  - Move config_read_fn to the first line as it is the longest
    variable declaration
  - Include adm1293 and adm1294
  - Remove the inline comment as I think the purpose is obvious


 drivers/hwmon/pmbus/adm1275.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/pmbus/adm1275.c b/drivers/hwmon/pmbus/adm1275.c
index e25f541227da..19317575d1c6 100644
--- a/drivers/hwmon/pmbus/adm1275.c
+++ b/drivers/hwmon/pmbus/adm1275.c
@@ -465,6 +465,7 @@ MODULE_DEVICE_TABLE(i2c, adm1275_id);
 static int adm1275_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
+	s32 (*config_read_fn)(const struct i2c_client *client, u8 reg);
 	u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
 	int config, device_config;
 	int ret;
@@ -510,11 +511,16 @@ static int adm1275_probe(struct i2c_client *client,
 			   "Device mismatch: Configured %s, detected %s\n",
 			   id->name, mid->name);
 
-	config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG);
+	if (mid->driver_data == adm1272 || mid->driver_data == adm1278 ||
+	    mid->driver_data == adm1293 || mid->driver_data == adm1294)
+		config_read_fn = i2c_smbus_read_word_data;
+	else
+		config_read_fn = i2c_smbus_read_byte_data;
+	config = config_read_fn(client, ADM1275_PMON_CONFIG);
 	if (config < 0)
 		return config;
 
-	device_config = i2c_smbus_read_byte_data(client, ADM1275_DEVICE_CONFIG);
+	device_config = config_read_fn(client, ADM1275_DEVICE_CONFIG);
 	if (device_config < 0)
 		return device_config;
 
-- 
2.27.0.383.g050319c2ae-goog


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

* Re: [PATCH v2] hwmon: adm1275: Make sure we are reading enough data for different chips
  2020-07-09  4:06 [PATCH v2] hwmon: adm1275: Make sure we are reading enough data for different chips Chu Lin
@ 2020-07-09 14:05 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2020-07-09 14:05 UTC (permalink / raw)
  To: Chu Lin
  Cc: belgaied, jasonling, jdelvare, linux-hwmon, linux-kernel, zhongqil

On Thu, Jul 09, 2020 at 04:06:12AM +0000, Chu Lin wrote:
> Issue:
> When PEC is enabled, binding adm1272 to the adm1275 would
> fail due to PEC error. See below:
> adm1275: probe of xxxx failed with error -74
> 
> Diagnosis:
> Per the datasheet of adm1272, adm1278, adm1293 and amd1294,
> PMON_CONFIG (0xd4) is 16bits wide. On the other hand,
> PMON_CONFIG (0xd4) for adm1275 is 8bits wide. The driver should not
> assume everything is 8bits wide and read only 8bits from it.
> 
> Solution:
> If it is adm1272, adm1278, adm1293 and adm1294, use i2c_read_word.
> Else, use i2c_read_byte
> 
> Testing:
> Binding adm1272 to the driver.
> The change is only tested on adm1272.
> 
> Signed-off-by: Chu Lin <linchuyuan@google.com>

Applied.

Thanks a lot for analyzing and fixing the problem.

Guenter

> ---
> 
> ChangeLog v1 -> v2
>   - Rename config_read_fn_ptr to config_read_fn
>   - Move config_read_fn to the first line as it is the longest
>     variable declaration
>   - Include adm1293 and adm1294
>   - Remove the inline comment as I think the purpose is obvious
> 
> 
>  drivers/hwmon/pmbus/adm1275.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/pmbus/adm1275.c b/drivers/hwmon/pmbus/adm1275.c
> index e25f541227da..19317575d1c6 100644
> --- a/drivers/hwmon/pmbus/adm1275.c
> +++ b/drivers/hwmon/pmbus/adm1275.c
> @@ -465,6 +465,7 @@ MODULE_DEVICE_TABLE(i2c, adm1275_id);
>  static int adm1275_probe(struct i2c_client *client,
>  			 const struct i2c_device_id *id)
>  {
> +	s32 (*config_read_fn)(const struct i2c_client *client, u8 reg);
>  	u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
>  	int config, device_config;
>  	int ret;
> @@ -510,11 +511,16 @@ static int adm1275_probe(struct i2c_client *client,
>  			   "Device mismatch: Configured %s, detected %s\n",
>  			   id->name, mid->name);
>  
> -	config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG);
> +	if (mid->driver_data == adm1272 || mid->driver_data == adm1278 ||
> +	    mid->driver_data == adm1293 || mid->driver_data == adm1294)
> +		config_read_fn = i2c_smbus_read_word_data;
> +	else
> +		config_read_fn = i2c_smbus_read_byte_data;
> +	config = config_read_fn(client, ADM1275_PMON_CONFIG);
>  	if (config < 0)
>  		return config;
>  
> -	device_config = i2c_smbus_read_byte_data(client, ADM1275_DEVICE_CONFIG);
> +	device_config = config_read_fn(client, ADM1275_DEVICE_CONFIG);
>  	if (device_config < 0)
>  		return device_config;
>  

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

end of thread, other threads:[~2020-07-09 14:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-09  4:06 [PATCH v2] hwmon: adm1275: Make sure we are reading enough data for different chips Chu Lin
2020-07-09 14:05 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).