All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [PATCH] adm1026: fix setting fan_div
@ 2010-11-30  1:49 Gabriele Gorla
  2010-11-30  2:29 ` Phil Pokorny
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: Gabriele Gorla @ 2010-11-30  1:49 UTC (permalink / raw)
  To: lm-sensors

Prevent setting fan_div from stomping on other fans that share the same i2c register. 
Also allow div=1 (this is allowed in the ADM1026 datasheet) and prevent the mutex lock 
when no update is necessary.

Signed-off-by: Gabriele Gorla <gorlik at penguintown.net>
---


diff -r -U 5 linux-source-2.6.26_orig/drivers/hwmon/adm1026.c linux-source-2.6.26/drivers/hwmon/adm1026.c
--- linux-source-2.6.26_orig/drivers/hwmon/adm1026.c	2008-07-13 14:51:29.000000000 -0700
+++ linux-source-2.6.26/drivers/hwmon/adm1026.c	2010-11-29 17:21:06.000000000 -0800
@@ -918,37 +918,42 @@
 {
 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
 	int nr = sensor_attr->index;
 	struct i2c_client *client = to_i2c_client(dev);
 	struct adm1026_data *data = i2c_get_clientdata(client);
-	int val, orig_div, new_div, shift;
+	int val, orig_div, new_div;
 
 	val = simple_strtol(buf, NULL, 10);
-	new_div = DIV_TO_REG(val);
-	if (new_div = 0) {
-		return -EINVAL;
-	}
-	mutex_lock(&data->update_lock);
-	orig_div = data->fan_div[nr];
-	data->fan_div[nr] = DIV_FROM_REG(new_div);
 
-	if (nr < 4) { /* 0 <= nr < 4 */
-		shift = 2 * nr;
-		adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
-			((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
-			(new_div << shift)));
-	} else { /* 3 < nr < 8 */
-		shift = 2 * (nr - 4);
-		adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
-			((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
-			(new_div << shift)));
+	if(val<1 || val>8) {
+	        return -EINVAL;
 	}
 
-	if (data->fan_div[nr] != orig_div) {
+	new_div = DIV_TO_REG(val);
+	if(data->fan_div[nr]!=DIV_FROM_REG(new_div)) {
+
+	        mutex_lock(&data->update_lock);
+		orig_div = data->fan_div[nr];
+		data->fan_div[nr] = DIV_FROM_REG(new_div);
+
+		if (nr < 4) { /* 0 <= nr < 4 */
+		        adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
+				    (DIV_TO_REG(data->fan_div[0]) << 0) |
+				    (DIV_TO_REG(data->fan_div[1]) << 2) |
+				    (DIV_TO_REG(data->fan_div[2]) << 4) |
+				    (DIV_TO_REG(data->fan_div[3]) << 6) );
+		} else { /* 3 < nr < 8 */
+		        adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
+				    (DIV_TO_REG(data->fan_div[4]) << 0) |
+				    (DIV_TO_REG(data->fan_div[5]) << 2) |
+				    (DIV_TO_REG(data->fan_div[6]) << 4) |
+				    (DIV_TO_REG(data->fan_div[7]) << 6) );
+		}
+		
 		fixup_fan_min(dev, nr, orig_div);
+		mutex_unlock(&data->update_lock);
 	}
-	mutex_unlock(&data->update_lock);
 	return count;
 }
 
 #define fan_offset_div(offset)						\
 static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR,		\

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2010-12-01  8:55 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-30  1:49 [lm-sensors] [PATCH] adm1026: fix setting fan_div Gabriele Gorla
2010-11-30  2:29 ` Phil Pokorny
2010-11-30  8:04 ` Gabriele Gorla
2010-11-30  9:17 ` Jean Delvare
2010-11-30 15:50 ` Guenter Roeck
2010-11-30 19:05 ` Phil Pokorny
2010-11-30 19:10 ` Gabriele Gorla
2010-11-30 19:19 ` Phil Pokorny
2010-11-30 19:44 ` Jean Delvare
2010-11-30 20:30 ` Jean Delvare
2010-12-01  1:05 ` Gabriele Gorla
2010-12-01  2:46 ` Phil Pokorny
2010-12-01  8:18 ` Jean Delvare
2010-12-01  8:55 ` Jean Delvare

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.