diff mbox series

[v1,2/5] hwmon: (lm75) Include hwmon_chip in the permitted types to be writen

Message ID 20190709095052.7964-3-iker.perez@codethink.co.uk (mailing list archive)
State Changes Requested
Headers show
Series Help with lm75.c changes | expand

Commit Message

Iker Perez July 9, 2019, 9:50 a.m. UTC
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.

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(-)

Comments

Guenter Roeck July 9, 2019, 1:26 p.m. UTC | #1
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,
>
diff mbox series

Patch

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;
 	}
 
-	/*
-	 * 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,