[ltp] [PATCH] ibm-acpi extended fan control compatible with the new thermal patches

Henrique de Moraes Holschuh linux-thinkpad@linux-thinkpad.org
Sat, 16 Sep 2006 14:09:32 -0300


--yRA+Bmk8aPhU85Qt
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Here's a version of the extended fan-control patches that will work with a
ibm-acpi that had my version of the extra thermal sensors patch applied.

I am not the author of the extended fan-control patches, I just messed with
them enough for them to apply cleanly.  So, no signed-off-by on this one.

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

--yRA+Bmk8aPhU85Qt
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="ibm-acpi_fan-control.patch"

 ibm_acpi.c |   36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)
--- a/drivers/acpi/ibm_acpi.c	2006-09-16 14:00:34.000000000 -0300
+++ b/drivers/acpi/ibm_acpi.c	2006-09-03 15:10:26.000000000 -0300
@@ -1506,6 +1506,7 @@
 {
 	int len = 0;
 	int s;
+	char status_read = 0;
 	u8 lo, hi, status;
 
 	if (gfan_handle) {
@@ -1518,9 +1519,11 @@
 		/* all except 570, 600e/x, 770e, 770x */
 		if (!acpi_ec_read(fan_status_offset, &status))
 			len += sprintf(p + len, "status:\t\tunreadable\n");
-		else
+		else {
 			len += sprintf(p + len, "status:\t\t%s\n",
-				       enabled(status, 7));
+				       status ? "enabled" : "disabled" );
+			status_read = 1;
+		}
 
 		if (!acpi_ec_read(fan_rpm_offset, &lo) ||
 		    !acpi_ec_read(fan_rpm_offset + 1, &hi))
@@ -1528,6 +1531,15 @@
 		else
 			len += sprintf(p + len, "speed:\t\t%d\n",
 				       (hi << 8) + lo);
+
+		if (status_read) {
+			if (status & 0x40)
+				len += sprintf(p + len, "level:\t\tdisengaged\n");
+			else if (status & 0x80)
+				len += sprintf(p + len, "level:\t\tauto\n");
+			else
+				len += sprintf(p + len, "level:\t\t%d\n", status);
+		}
 	}
 
 	if (sfan_handle)
@@ -1536,7 +1548,11 @@
 			       " (<level> is 0-7)\n");
 	if (!gfan_handle)
 		/* all except 570, 600e/x, 770e, 770x */
-		len += sprintf(p + len, "commands:\tenable, disable\n");
+		len += sprintf(p + len, 
+			"commands:\tenable, disable, level <level>\n"
+			"         \t(<level> is 0-7, auto "
+			"or disengaged)\n");
+
 	if (fans_handle)
 		/* X31, X40 */
 		len += sprintf(p + len, "commands:\tspeed <speed>"
@@ -1557,7 +1573,8 @@
 			/* 570, 770x-JL */
 			if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
 				return -EIO;
-		} else if (!gfan_handle && strlencmp(cmd, "enable") == 0) {
+		} else if (!gfan_handle && ( (strlencmp(cmd, "enable") == 0) ||
+				(strlencmp(cmd, "level auto") == 0) ) ) {
 			/* all except 570, 600e/x, 770e, 770x */
 			if (!acpi_ec_write(fan_status_offset, 0x80))
 				return -EIO;
@@ -1565,6 +1582,17 @@
 			/* all except 570, 600e/x, 770e, 770x */
 			if (!acpi_ec_write(fan_status_offset, 0x00))
 				return -EIO;
+		} else if (!gfan_handle &&
+			    strlencmp(cmd, "level disengaged") == 0) {
+			/* all except 570, 600e/x, 770e, 770x */
+			if (!acpi_ec_write(fan_status_offset, 0x40))
+				return -EIO;
+		} else if (!gfan_handle &&
+			   sscanf(cmd, "level %d", &level) == 1 &&
+			   level >=0 && level <= 7) {
+			/* all except 570, 600e/x, 770e, 770x */
+			if (!acpi_ec_write(fan_status_offset, level))
+				return -EIO;
 		} else if (fans_handle &&
 			   sscanf(cmd, "speed %d", &speed) == 1 &&
 			   speed >= 0 && speed <= 65535) {

--yRA+Bmk8aPhU85Qt--