linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / 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 2/5] hwmon: (lm75) Include hwmon_chip in the permitted types to be writen
Date: Tue, 9 Jul 2019 06:26:52 -0700	[thread overview]
Message-ID: <9df1acf2-054c-6f25-2da2-888006d7d776@roeck-us.net> (raw)
In-Reply-To: <20190709095052.7964-3-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>
> 
> hwmon_chip needs to be allowed to be written because tmp75b's sample time
> can be configured. Allowing hwmon_chip to be written will allow to
> configure the update_interval from sysfs.
> 

You'll want to have separate functions for the different sensor types,
and not fold it all into one. lm75_write() should be something like

static int lm75_write(struct device *dev, enum hwmon_sensor_types type,
                       u32 attr, int channel, long val)
{
	switch(type) {
	case hwmon_temp:
		return lm75_write_temp(dev, attr, channel, val);
	case hwmon_chip:
		return lm75_write_chip(dev, attr, val);
	default:
		return -EINVAL;
	}
}

> Signed-off-by: Iker Perez del Palomar Sustatxa <iker.perez@codethink.co.uk>
> ---
>   drivers/hwmon/lm75.c | 62 ++++++++++++++++++++++++++++++++--------------------
>   1 file changed, 38 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
> index 0209e0719784..80a11c33db77 100644
> --- a/drivers/hwmon/lm75.c
> +++ b/drivers/hwmon/lm75.c
> @@ -128,34 +128,48 @@ static int lm75_write(struct device *dev, enum hwmon_sensor_types type,
>   	u8 resolution;
>   	int reg;
>   
> -	if (type != hwmon_temp)
> -		return -EINVAL;
> -
> -	switch (attr) {
> -	case hwmon_temp_max:
> -		reg = LM75_REG_MAX;
> -		break;
> -	case hwmon_temp_max_hyst:
> -		reg = LM75_REG_HYST;
> -		break;
> -	default:
> -		return -EINVAL;
> +	switch (type) {
> +	case hwmon_chip:
> +		switch (attr) {
> +		case hwmon_chip_update_interval:
> +			if (data->kind == tmp75b)
> +				pr_info("Iker inside write\n");
> +			else
> +				return -EINVAL;
> +			break;
> +		default:
> +			return -EINVAL;
> +		}
> +	case hwmon_temp:
> +		switch (attr) {
> +		case hwmon_temp_max:
> +			reg = LM75_REG_MAX;
> +			break;
> +		case hwmon_temp_max_hyst:
> +			reg = LM75_REG_HYST;
> +			break;
> +		default:
> +			return -EINVAL;
>   	}

Please watch out for indentation. Running checkpatch over your patches
would be highly recommended.

Guenter

>   
> -	/*
> -	 * Resolution of limit registers is assumed to be the same as the
> -	 * temperature input register resolution unless given explicitly.
> -	 */
> -	if (data->resolution_limits)
> -		resolution = data->resolution_limits;
> -	else
> -		resolution = data->resolution;
> +		/*
> +		* Resolution of limit registers is assumed to be the same as the
> +		* temperature input register resolution unless given explicitly.
> +		*/
> +		if (data->resolution_limits)
> +			resolution = data->resolution_limits;
> +		else
> +			resolution = data->resolution;
>   
> -	temp = clamp_val(temp, LM75_TEMP_MIN, LM75_TEMP_MAX);
> -	temp = DIV_ROUND_CLOSEST(temp  << (resolution - 8),
> -				 1000) << (16 - resolution);
> +		temp = clamp_val(temp, LM75_TEMP_MIN, LM75_TEMP_MAX);
> +		temp = DIV_ROUND_CLOSEST(temp  << (resolution - 8),
> +					 1000) << (16 - resolution);
>   
> -	return regmap_write(data->regmap, reg, temp);
> +		return regmap_write(data->regmap, reg, temp);
> +	default:
> +		return -EINVAL;
> +	}
> +	return 0;
>   }
>   
>   static umode_t lm75_is_visible(const void *data, enum hwmon_sensor_types type,
> 


  reply	other threads:[~2019-07-09 13:26 UTC|newest]

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 [this message]
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
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 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=9df1acf2-054c-6f25-2da2-888006d7d776@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
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).