[PATCH v1 5/5] First approach to sample time writing method

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

 



From: Iker Perez del Palomar Sustatxa <iker.perez@xxxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxxx>
---
 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);
+				}
+			}
 			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;
 	}
-- 
2.11.0




[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