Difference between revisions of "Patch for controlling fan speed"

From ThinkWiki
Jump to: navigation, search
(Hardware specs)
(Added disengaged mode to patch)
Line 4: Line 4:
  
 
When this patch is applied and the <tt>ibm-acpi</tt> module is loaded with the <tt>experimental=1</tt> module parameter, the following new capabilities are added to {{path|/proc/acpi/ibm/fan}}:
 
When this patch is applied and the <tt>ibm-acpi</tt> module is loaded with the <tt>experimental=1</tt> module parameter, the following new capabilities are added to {{path|/proc/acpi/ibm/fan}}:
* {{cmdroot|echo LEVEL > /proc/acpi/ibm/fan}} sets a fan speed level between 0 and 7, where <tt>LEVEL</TT>=0 means fan off and <tt>LEVEL</tt>=7 is the fastest speed.
+
* {{cmdroot|echo level LEVEL > /proc/acpi/ibm/fan}} sets a fan speed level between 0 and 7, where <tt>LEVEL</TT>=0 means fan off and <tt>LEVEL</tt>=7 is the fastest speed.
* {{cmdroot|echo auto > /proc/acpi/ibm/fan}} tells the embedded controller to set the fan speed automatically according to system temperatures (this is the default).
+
* {{cmdroot|echo level auto > /proc/acpi/ibm/fan}} tells the embedded controller to set the fan speed automatically according to system temperatures (this is the default).
 +
* {{cmdroot|echo level disengaged > /proc/acpi/ibm/fan}} tells the embedded controller to disengage fan speed control (see specs below).
 
* {{cmdroot|cat /proc/acpi/ibm/fan}} shows the current fan level (in addition to the fan speed in RPM).
 
* {{cmdroot|cat /proc/acpi/ibm/fan}} shows the current fan level (in addition to the fan speed in RPM).
  
Line 28: Line 29:
 
<pre>
 
<pre>
 
--- ibm-acpi-0.11-orig/ibm_acpi.c 2005-03-17 12:06:16.000000000 +0200
 
--- ibm-acpi-0.11-orig/ibm_acpi.c 2005-03-17 12:06:16.000000000 +0200
+++ ibm-acpi-0.11/ibm_acpi.c 2005-10-24 12:56:44.000000000 +0200
+
+++ ibm-acpi-0.11/ibm_acpi.c 2005-10-26 06:21:57.000000000 +0200
@@ -1488,11 +1488,16 @@ static int fan_read(char *p)
+
@@ -1488,11 +1488,18 @@ static int fan_read(char *p)
 
  } else {
 
  } else {
 
  /* all except 570, 600e/x, 770e, 770x */
 
  /* all except 570, 600e/x, 770e, 770x */
Line 38: Line 39:
 
  len += sprintf(p + len, "status:\t\t%s\n",
 
  len += sprintf(p + len, "status:\t\t%s\n",
 
-       enabled(status, 7));
 
-       enabled(status, 7));
+       status ? "enabled" : "disabled");
+
+               status ? "enabled" : "disabled");
+ if (status & 0x80)
+
+ if (status & 0x40)
 +
+ len += sprintf(p + len, "level:\t\tdisengaged\n");
 +
+ else if (status & 0x80)
 
+ len += sprintf(p + len, "level:\t\tauto\n");
 
+ len += sprintf(p + len, "level:\t\tauto\n");
 
+ else
 
+ else
Line 48: Line 51:
 
      !acpi_ec_read(fan_rpm_offset + 1, &hi))
 
      !acpi_ec_read(fan_rpm_offset + 1, &hi))
 
  len += sprintf(p + len, "speed:\t\tunreadable\n");
 
  len += sprintf(p + len, "speed:\t\tunreadable\n");
@@ -1506,9 +1511,10 @@ static int fan_read(char *p)
+
@@ -1506,9 +1513,12 @@ static int fan_read(char *p)
 
  len += sprintf(p + len, "commands:\tlevel <level>"
 
  len += sprintf(p + len, "commands:\tlevel <level>"
 
        " (<level> is 0-7)\n");
 
        " (<level> is 0-7)\n");
Line 54: Line 57:
 
  /* all except 570, 600e/x, 770e, 770x */
 
  /* all except 570, 600e/x, 770e, 770x */
 
- len += sprintf(p + len, "commands:\tenable, disable\n");
 
- len += sprintf(p + len, "commands:\tenable, disable\n");
+ len += sprintf(p + len, "commands:\tenable, disable, level <level>\n"
+
+ len += sprintf(p + len,  
+                 "        \t(<level> is 0-7 or auto)\n");
+
+               "commands:\tenable, disable, level <level>\n"
 +
+               "        \t(<level> is 0-7, auto"
 +
+               "or disengaged)\n");
 
  if (fans_handle)
 
  if (fans_handle)
 
  /* X31, X40 */
 
  /* X31, X40 */
 
  len += sprintf(p + len, "commands:\tspeed <speed>"
 
  len += sprintf(p + len, "commands:\tspeed <speed>"
 
        " (<speed> is 0-65535)\n");
 
        " (<speed> is 0-65535)\n");
@@ -1528,17 +1534,24 @@ static int fan_write(char *buf)
+
@@ -1528,17 +1538,29 @@ static int fan_write(char *buf)
 
  /* 570, 770x-JL */
 
  /* 570, 770x-JL */
 
  if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
 
  if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
Line 76: Line 81:
 
  if (!acpi_ec_write(fan_status_offset, 0x00))
 
  if (!acpi_ec_write(fan_status_offset, 0x00))
 
  return -EIO;
 
  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 &&
 
+ } else if (!gfan_handle &&
 
+     sscanf(cmd, "level %d", &level) == 1 &&
 
+     sscanf(cmd, "level %d", &level) == 1 &&
Line 86: Line 96:
 
      speed >= 0 && speed <= 65535) {
 
      speed >= 0 && speed <= 65535) {
 
  /* X31, X40 */
 
  /* X31, X40 */
@@ -1751,9 +1764,9 @@ static int __init setup_notify(struct ib
+
@@ -1751,9 +1773,9 @@ static int __init setup_notify(struct ib
 
   
 
   
 
  return 0;
 
  return 0;
Line 97: Line 107:
 
  }
 
  }
 
   
 
   
@@ -1769,9 +1782,9 @@ static int __init register_driver(struct
+
@@ -1769,9 +1791,9 @@ static int __init register_driver(struct
 
   
 
   
 
  memset(ibm->driver, 0, sizeof(struct acpi_driver));
 
  memset(ibm->driver, 0, sizeof(struct acpi_driver));

Revision as of 05:31, 26 October 2005

Overview

This patch extends the ibm-acpi Linux kernel module to control fan speed. It can be used to reduce fan noise and power consumption.

When this patch is applied and the ibm-acpi module is loaded with the experimental=1 module parameter, the following new capabilities are added to /proc/acpi/ibm/fan:

  • # echo level LEVEL > /proc/acpi/ibm/fan sets a fan speed level between 0 and 7, where LEVEL=0 means fan off and LEVEL=7 is the fastest speed.
  • # echo level auto > /proc/acpi/ibm/fan tells the embedded controller to set the fan speed automatically according to system temperatures (this is the default).
  • # echo level disengaged > /proc/acpi/ibm/fan tells the embedded controller to disengage fan speed control (see specs below).
  • # cat /proc/acpi/ibm/fan shows the current fan level (in addition to the fan speed in RPM).

This patch is best used with a program that monitors system temperature and sets the fan speed accordingly. The current scripts for fan control could serve as the basis of such program.

ATTENTION!
Overriding the system's automatic temperature control may cause permanent hardware damage. Even when using temperature monitoring software, it is not clear whether the software can access all temperature sensor accessible to the embedded controller and understand them correctly. Moreover, this patch relies on an undocumented hardware interface, and may thus have arbitrary effects (especially on models it wasn't tested on).

Models on which this patch works

  • ThinkPad T43, T43p
    (levels 1-2 = ~3300RPM, level 3-5 = ~4100RPM, level 6-7 = ~4700 RPM)

Probably many other models; please update this page with your results.

Models on which this patch doesn't work

The patch

This also includes a minor fix (rename of device_add) to make ibm-acpi 0.11 compile on kernel 2.6.13.

--- ibm-acpi-0.11-orig/ibm_acpi.c	2005-03-17 12:06:16.000000000 +0200
+++ ibm-acpi-0.11/ibm_acpi.c	2005-10-26 06:21:57.000000000 +0200
@@ -1488,11 +1488,18 @@ static int fan_read(char *p)
 	} else {
 		/* 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");
+			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 (!acpi_ec_read(fan_rpm_offset,     &lo) ||
 		    !acpi_ec_read(fan_rpm_offset + 1, &hi))
 			len += sprintf(p + len, "speed:\t\tunreadable\n");
@@ -1506,9 +1513,12 @@ static int fan_read(char *p)
 		len += sprintf(p + len, "commands:\tlevel <level>"
 			       " (<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>"
 			       " (<speed> is 0-65535)\n");
@@ -1528,17 +1538,29 @@ static int fan_write(char *buf)
 			/* 570, 770x-JL */
 			if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
 				return -EIO;
 		} else if (!gfan_handle &&
-			   strlencmp(cmd, "enable") == 0) {
+			   ( (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;
 		} else if (!gfan_handle &&
 			   strlencmp(cmd, "disable") == 0) {
 			/* 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) {
 			/* X31, X40 */
@@ -1751,9 +1773,9 @@ static int __init setup_notify(struct ib
 
 	return 0;
 }
 
-static int device_add(struct acpi_device *device)
+static int ibmacpi_device_add(struct acpi_device *device)
 {
 	return 0;
 }
 
@@ -1769,9 +1791,9 @@ static int __init register_driver(struct
 
 	memset(ibm->driver, 0, sizeof(struct acpi_driver));
 	sprintf(ibm->driver->name, "%s/%s", IBM_NAME, ibm->name);
 	ibm->driver->ids = ibm->hid;
-	ibm->driver->ops.add = &device_add;
+	ibm->driver->ops.add = &ibmacpi_device_add;
 
 	ret = acpi_bus_register_driver(ibm->driver);
 	if (ret < 0) {
 		printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",

Hardware specs

The patch relies on the following hardware behavior, discovered experimentally on a ThinkPad T43.

ACPI DSDT register _SB.PCI0.LPC.EC.HFSP (8 bits, offset 0x2F in the EmbeddedController address space) is read/writable and has the following meaning:

 7 6 5 4 3 2 1 0
 | | \_________/
 | |      |
 | |      +--------- manual fan speed level (0=disable, 1=min, ..., 7=max)
 | +---------------- disengage (0=normal, 1=disengaged, overrides all)
 +------------------ automatic fan speed control (0=manual, 1=automatic, overrides manual)

Manual speed levels 8-63 yield the same behavior as level 7, and the the ACPI DSDT uses level 7 for the emergency mode it enters upon critical CPU/GPU temperature, so apparently 7 is the real maximum level.

When bit 7 is on, the embedded controller sets the fan speed automatically according to system temperaturesand some unknown algorithm. This overrides manual control.

When bit 6 is on, the embedded controller does not read the fan RPM (hence EmbeddedController offset 0x84 is not updated), and does not maintain a stable fan speed. This overrides manual and automatic control. When disengaged mode is entered the fan speed is not immediately changed (except if the fan was disabed, in which case it is turned on at a low level). However, once in disengaged mode, fan speed will slowly increase to beyond the maximum manual level (this may cause hardware damage!).

Hint:
Initial experiments show that the the pulsing fan noise experienced by some users can be cured by repeatedly running 2 seconds of manual control followed by 1 second of disengaged mode. The pulse occurs when the the embedded controller computes the fan speed and adjusts the fan voltage adaptively every few seconds (~4.8sec for the ThinkPad T43); the aforementioned mode switching doesn't give it a chance to do so.