Linux-Hwmon Archive on lore.kernel.org
 help / color / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Iker Perez <iker.perez@codethink.co.uk>,
	Jean Delvare <jdelvare@suse.com>,
	linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v1 5/5] First approach to sample time writing method
Date: Tue, 9 Jul 2019 06:33:53 -0700
Message-ID: <95484247-ff5e-8207-a682-ed641d5452b3@roeck-us.net> (raw)
In-Reply-To: <20190709095052.7964-6-iker.perez@codethink.co.uk>

On 7/9/19 2:50 AM, Iker Perez wrote:
> From: Iker Perez del Palomar Sustatxa <iker.perez@codethink.co.uk>
> 
> Switch between the possible update_time values and write into the
> configuration register the selected value.
> 
> Signed-off-by: Iker Perez del Palomar Sustatxa <iker.perez@codethink.co.uk>
> ---
>   drivers/hwmon/lm75.c | 43 ++++++++++++++++++++++++++++++++++---------
>   1 file changed, 34 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
> index 5ba7277dac69..9d48a85fd3e5 100644
> --- a/drivers/hwmon/lm75.c
> +++ b/drivers/hwmon/lm75.c
> @@ -156,21 +156,46 @@ static int lm75_read(struct device *dev, enum hwmon_sensor_types type,
>   }
>   
>   static int lm75_write(struct device *dev, enum hwmon_sensor_types type,
> -		      u32 attr, int channel, long temp)
> +		      u32 attr, int channel, long val)
>   {
>   	struct lm75_data *data = dev_get_drvdata(dev);
> -	u8 resolution;
> -	int reg;
> +	u8 resolution, set_mask, clr_mask;
> +	int reg, status;
> +
> +	// This are provisional changes, to be improved in case this approach works
> +	set_mask = 0;
> +	clr_mask = LM75_SHUTDOWN;
>   
>   	switch (type) {
>   	case hwmon_chip:
>   		switch (attr) {
>   		case hwmon_chip_update_interval:
> -			if (data->kind == tmp75b)
> -				pr_info("Iker inside write\n");
> +			if (data->kind == tmp75b) {
> +				clr_mask |= 1 << 15 | 0x3 << 13;
> +				switch (val) {
> +				case (27):
> +					set_mask |= 0x3 << 13;
> +					data->sample_time = MSEC_PER_SEC / 37;
> +						break;
> +				case (55):
> +					set_mask |= 0x2 << 13;
> +					data->sample_time = MSEC_PER_SEC / 18;
> +						break;
> +				case (111):
> +					set_mask |= 0x1 << 13;
> +					data->sample_time = MSEC_PER_SEC / 9;
> +						break;
> +				case (250):
> +					set_mask |= 0x0 << 13;
> +					data->sample_time = MSEC_PER_SEC / 4;
> +						break;
> +				default:
> +						return -EINVAL;
> +				status = configure_reg(set_mask, clr_mask, data, client);

You'll probably want to provide all the necessary variants (supported update times
as well as associated resolutions and set/clear masks) in the data structure,
to make it easy to support multiple chips. Either case, it is unacceptable to
only accept specific values: You can not expect the user to figure out individual
supported values on a per-chip basis. Please use something like find_closest()
to find the best match.

> +				}
> +			}
>   			else
>   				return -EINVAL;
> -			break;
>   		default:
>   			return -EINVAL;
>   		}
> @@ -195,11 +220,11 @@ static int lm75_write(struct device *dev, enum hwmon_sensor_types type,
>   		else
>   			resolution = data->resolution;
>   
> -		temp = clamp_val(temp, LM75_TEMP_MIN, LM75_TEMP_MAX);
> -		temp = DIV_ROUND_CLOSEST(temp  << (resolution - 8),
> +		val = clamp_val(val, LM75_TEMP_MIN, LM75_TEMP_MAX);
> +		val = DIV_ROUND_CLOSEST(val  << (resolution - 8),
>   					 1000) << (16 - resolution);
>   
> -		return regmap_write(data->regmap, reg, temp);
> +		return regmap_write(data->regmap, reg, val);
>   	default:
>   		return -EINVAL;
>   	}
> 


  reply index

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-09  9:50 [PATCH v1 0/5] Help with lm75.c changes Iker Perez
2019-07-09  9:50 ` [PATCH v1 1/5] hwmon: (lm75) Add kind field to struct lm75_data Iker Perez
2019-07-09 13:20   ` Guenter Roeck
2019-07-09  9:50 ` [PATCH v1 2/5] hwmon: (lm75) Include hwmon_chip in the permitted types to be writen Iker Perez
2019-07-09 13:26   ` Guenter Roeck
2019-07-09  9:50 ` [PATCH v1 3/5] hwmon: (lm75) Give write permission to hwmon_chip_update_interval Iker Perez
2019-07-09  9:50 ` [PATCH v1 4/5] hwmon: (lm75) Create function from code to write into registers Iker Perez
2019-07-09 13:39   ` Guenter Roeck
2019-07-09  9:50 ` [PATCH v1 5/5] First approach to sample time writing method Iker Perez
2019-07-09 13:33   ` Guenter Roeck [this message]
2019-07-09 13:43 ` [PATCH v1 0/5] Help with lm75.c changes Guenter Roeck
2019-07-09 15:11   ` Iker Perez del Palomar

Reply instructions:

You may reply publically 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=95484247-ff5e-8207-a682-ed641d5452b3@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=iker.perez@codethink.co.uk \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    /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

Linux-Hwmon Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hwmon/0 linux-hwmon/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hwmon linux-hwmon/ https://lore.kernel.org/linux-hwmon \
		linux-hwmon@vger.kernel.org linux-hwmon@archiver.kernel.org
	public-inbox-index linux-hwmon


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hwmon


AGPL code for this site: git clone https://public-inbox.org/ public-inbox