linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Chu Lin <linchuyuan@google.com>
Cc: jdelvare@suse.com, linux-hwmon@vger.kernel.org,
	linux-kernel@vger.kernel.org, jasonling@google.com,
	belgaied@google.com, zhongqil@google.com
Subject: Re: [PATCH] hwmon:max6697: Allow max6581 to set temperature read offset
Date: Tue, 30 Jun 2020 10:59:08 -0700	[thread overview]
Message-ID: <20200630175908.GG629@roeck-us.net> (raw)
In-Reply-To: <20200630174350.2842555-1-linchuyuan@google.com>

On Tue, Jun 30, 2020 at 05:43:50PM +0000, Chu Lin wrote:
> Per max6581, reg 4d and reg 4e is used for temperature read offset.
> This patch will let the user specify the temperature read offset for
> max6581. This patch is tested on max6581 and only applies to max6581.
> 
> Testing:
> dts: temperature-read-offset = <0xde 0x0>;

This should not be implemented this way. Instead, the standard tempX_offset
attribute should be used, with appropriate code to determine affected
channels (since there is only one offset value, and since it can be enabled
per channel). A secondary question is if and how to set the temperature
offset via devicetree; that will have to be documented and approved by a
DT maintainer.  I would think, though, that the offset should be specified
in milli-degrees C and not as raw chip data.

Thanks,
Guenter

> 
> verify: iotools smbus_read8 <vbus> 0x4d 0x4e
> 0x6F
> 
> Signed-off-by: Chu Lin <linchuyuan@google.com>
> ---
>  drivers/hwmon/max6697.c               | 19 +++++++++++++++++--
>  include/linux/platform_data/max6697.h |  4 ++++
>  2 files changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/max6697.c b/drivers/hwmon/max6697.c
> index 743752a2467a..16c0f0995a12 100644
> --- a/drivers/hwmon/max6697.c
> +++ b/drivers/hwmon/max6697.c
> @@ -493,8 +493,13 @@ static void max6697_get_config_of(struct device_node *node,
>  	}
>  	prop = of_get_property(node, "transistor-ideality", &len);
>  	if (prop && len == 2 * sizeof(u32)) {
> -			pdata->ideality_mask = be32_to_cpu(prop[0]);
> -			pdata->ideality_value = be32_to_cpu(prop[1]);
> +		pdata->ideality_mask = be32_to_cpu(prop[0]);
> +		pdata->ideality_value = be32_to_cpu(prop[1]);
> +	}
> +	prop = of_get_property(node, "temperature-read-offset", &len);
> +	if  (prop && len == 2 * sizeof(u32)) {
> +		pdata->offset_mask = be32_to_cpu(prop[0]);
> +		pdata->offset_value = be32_to_cpu(prop[1]);
>  	}
>  }
>  
> @@ -586,6 +591,16 @@ static int max6697_init_chip(struct max6697_data *data,
>  						pdata->ideality_mask >> 1);
>  		if (ret < 0)
>  			return ret;
> +		ret = i2c_smbus_write_byte_data(client,
> +						MAX6581_REG_OFFSET,
> +						pdata->offset_value);
> +		if (ret < 0)
> +			return ret;
> +		ret = i2c_smbus_write_byte_data(client,
> +						MAX6581_REG_OFFSET_SELECT,
> +						pdata->offset_mask >> 1);
> +		if (ret < 0)
> +			return ret;
>  	}
>  done:
>  	data->update_interval = factor * MAX6697_CONV_TIME;
> diff --git a/include/linux/platform_data/max6697.h b/include/linux/platform_data/max6697.h
> index 6fbb70005541..ff98adfe9d8d 100644
> --- a/include/linux/platform_data/max6697.h
> +++ b/include/linux/platform_data/max6697.h
> @@ -28,6 +28,10 @@ struct max6697_platform_data {
>  	u8 ideality_value;		/* transistor ideality as per
>  					 * MAX6581 datasheet
>  					 */
> +	u8 offset_mask;			/* set bit to 0 to disable */
> +	u8 offset_value;		/* temperature read offset as
> +					 * MAX6581 datasheet
> +					 */
>  };
>  
>  #endif /* MAX6697_H */
> -- 
> 2.27.0.212.ge8ba1cc988-goog
> 

  reply	other threads:[~2020-06-30 17:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-30 17:43 [PATCH] hwmon:max6697: Allow max6581 to set temperature read offset Chu Lin
2020-06-30 17:59 ` Guenter Roeck [this message]
2020-07-01 18:43 ` Chu Lin
2020-07-01 18:45 ` Chu Lin
2020-07-02  1:42 ` [PATCH] hwmon:max6697: Allow max6581 to create tempX_offset attributes Chu Lin
2020-07-02  5:14   ` Guenter Roeck
2020-07-02 16:38     ` Chu Lin
2020-07-03  1:06   ` Guenter Roeck
2020-07-06 17:54     ` [PATCH] hwmon:max6697: Allow max6581 to create tempX_offset Chu Lin
2020-07-06 19:32       ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200630175908.GG629@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=belgaied@google.com \
    --cc=jasonling@google.com \
    --cc=jdelvare@suse.com \
    --cc=linchuyuan@google.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zhongqil@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).