acpi_thinkpad(4): make acpi_thinkpad sensors actually work
authorConstantine A. Murenin <cnst+dfly@bugmail.mojo.ru>
Thu, 18 Feb 2010 07:13:00 +0000 (02:13 -0500)
committerConstantine A. Murenin <cnst+dfly@bugmail.mojo.ru>
Thu, 18 Feb 2010 07:49:45 +0000 (02:49 -0500)
* After this patch on my ThinkPad R51:
  %sysctl hw.sensors.acpi_ibm0
  hw.sensors.acpi_ibm0.temp0: 69.00 degC
  hw.sensors.acpi_ibm0.temp1: 52.00 degC
  hw.sensors.acpi_ibm0.temp2: 41.00 degC
  hw.sensors.acpi_ibm0.temp3: 59.00 degC
  hw.sensors.acpi_ibm0.temp4: 36.00 degC
  hw.sensors.acpi_ibm0.temp5: invalid
  hw.sensors.acpi_ibm0.temp6: 26.00 degC
  hw.sensors.acpi_ibm0.temp7: invalid
  hw.sensors.acpi_ibm0.fan0: 3469 RPM

* Before this patch:
  o The temperature values were absolutely random, since
    the /data/ variable was never initialised from temp[i].
  o The braces were missing from the fan error path of
    an if statement.
  o Whitespaces were used instead of tabs.

sys/dev/acpica5/acpi_thinkpad/acpi_thinkpad.c

index 42507e0..48cf177 100644 (file)
@@ -919,48 +919,45 @@ acpi_ibm_sysctl_init(struct acpi_ibm_softc *sc, int method)
 void
 acpi_ibm_refresh(void *arg)
 {
-       struct acpi_ibm_softc   *sc;
+       struct acpi_ibm_softc   *sc = (struct acpi_ibm_softc *)arg;
        char                    temp_cmd[] = "TMP0";
        int                     i, data, temp[8];
        ACPI_INTEGER            speed;
 
        ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
-
-       sc = (struct acpi_ibm_softc *)arg;
-
        ACPI_SERIAL_BEGIN(ibm);
 
        for (i = 0; i < IBM_THERMAL_SENSORS; ++i) {
                temp_cmd[3] = '0' + i;
-               
-               /* 
+
+               /*
                 * The TMPx methods seem to return +/- 128 or 0
-                * when the respecting sensor is not available 
+                * when the respecting sensor is not available
                 */
                if (ACPI_FAILURE(acpi_GetInteger(sc->ec_handle, temp_cmd,
                    &temp[i])) || ABS(temp[i]) == 128 || temp[i] == 0) { 
                        sc->sensors[i].flags |= SENSOR_FINVALID;
-                       data = 0;
+                       continue;
                }
-               else if (sc->thermal_updt_supported) {
+               if (sc->thermal_updt_supported)
                        /* Temperature is reported in tenth of Kelvin */
-                       sc->sensors[i].value = data * 100000;
-               }
-               sc->sensors[i].value = data * 1000000 + 273150000;
+                       sc->sensors[i].value = temp[i] * 100000 - 50000;
+               else
+                       sc->sensors[i].value = temp[i] * 1000000 + 273150000;
+               sc->sensors[i].flags &= ~SENSOR_FINVALID;
        }
-       sc->sensors[i].flags &= ~SENSOR_FINVALID;
-        if (sc->fan_handle) {
-                if (ACPI_FAILURE(acpi_GetInteger(sc->fan_handle,
-                    NULL, &data)))
-                        sc->sensors[i].flags |= SENSOR_FINVALID;
-                        data = -1;
-        }
-        else {  
-                ACPI_EC_READ(sc->ec_dev, IBM_EC_FANSPEED, &speed, 2);
-                data = speed;
-        }
 
-       sc->sensors[i].value = data;
+       if (sc->fan_handle) {
+               if (ACPI_FAILURE(acpi_GetInteger(sc->fan_handle,
+                   NULL, &data)))
+                       sc->sensors[i].flags |= SENSOR_FINVALID;
+               sc->sensors[i].value = data;
+               sc->sensors[i].flags &= ~SENSOR_FINVALID;
+       } else {
+               ACPI_EC_READ(sc->ec_dev, IBM_EC_FANSPEED, &speed, 2);
+               sc->sensors[i].value = speed;
+               sc->sensors[i].flags &= ~SENSOR_FINVALID;
+       }
 
        ACPI_SERIAL_END(ibm);
 }