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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/9/19 2:50 AM, Iker Perez wrote:
From: Iker Perez del Palomar Sustatxa <iker.perez@xxxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxxx>
---
  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,





[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux