On 14 May 2011 c. 02:38:32 Owain Ainsworth wrote:
> No actual comment on the diff right now, but please spell
> ``disengaged'' correctly.

Fixed version, including man page update purpose, is below.

--
  Best wishes,
    Vadim Zhukov

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?


Index: sys/dev/acpi/acpithinkpad.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpithinkpad.c,v
retrieving revision 1.26
diff -u -p -r1.26 acpithinkpad.c
--- sys/dev/acpi/acpithinkpad.c 27 Apr 2011 20:55:42 -0000      1.26
+++ sys/dev/acpi/acpithinkpad.c 14 May 2011 06:43:22 -0000
@@ -71,11 +71,21 @@
 #define        THINKPAD_POWER_CHANGED          0x6030
 #define        THINKPAD_SWITCH_WIRELESS        0x7000

-#define THINKPAD_NSENSORS 9
-#define THINKPAD_NTEMPSENSORS 8
+#define THINKPAD_NSENSORS      10
+#define THINKPAD_NTEMPSENSORS   8
+
+#define THINKPAD_SENSOR_FANRPM (THINKPAD_NTEMPSENSORS + 0)
+#define THINKPAD_SENSOR_FANMODE        (THINKPAD_NTEMPSENSORS + 1)

 #define THINKPAD_ECOFFSET_FANLO                0x84
 #define THINKPAD_ECOFFSET_FANHI                0x85
+#define THINKPAD_ECOFFSET_FANMODE      0x2f
+
+#define THINKPAD_FANMODE_AUTO          0x80
+#define THINKPAD_FANMODE_DISENGAGED    0x40
+
+/* critical temperature mark, in Celsius */
+#define THINKPAD_TEMP_OUCH             80

 struct acpithinkpad_softc {
        struct device            sc_dev;
@@ -103,7 +113,7 @@ int thinkpad_volume_mute(struct acpithin
 int    thinkpad_brightness_up(struct acpithinkpad_softc *);
 int    thinkpad_brightness_down(struct acpithinkpad_softc *);

-void    thinkpad_sensor_attach(struct acpithinkpad_softc *sc);
+void    thinkpad_sensor_attach(struct acpithinkpad_softc *);
 void    thinkpad_sensor_refresh(void *);

 struct cfattach acpithinkpad_ca = {
@@ -156,8 +166,12 @@ thinkpad_sensor_attach(struct acpithinkp
        }

        /* Add fan probe */
-       sc->sc_sens[i].type = SENSOR_FANRPM;
-       sensor_attach(&sc->sc_sensdev, &sc->sc_sens[i]);
+       sc->sc_sens[THINKPAD_SENSOR_FANRPM].type = SENSOR_FANRPM;
+       sensor_attach(&sc->sc_sensdev, &sc->sc_sens[THINKPAD_SENSOR_FANRPM]);
+
+       /* Add fan mode indicator */
+       sc->sc_sens[THINKPAD_SENSOR_FANMODE].type = SENSOR_INTEGER;
+       sensor_attach(&sc->sc_sensdev, &sc->sc_sens[THINKPAD_SENSOR_FANMODE]);

        sensordev_install(&sc->sc_sensdev);
 }
@@ -166,9 +180,11 @@ void
 thinkpad_sensor_refresh(void *arg)
 {
        struct acpithinkpad_softc *sc = arg;
-       u_int8_t lo, hi, i;
-       int64_t tmp;
+       u_int8_t lo, hi, i, mode;
+       int64_t tmp, maxtmp = -127;    /* minimal correct value, see below */
+       enum sensor_status ss;
        char sname[5];
+       const char *desc;

        /* Refresh sensor readings */
        for (i=0; i<THINKPAD_NTEMPSENSORS; i++) {
@@ -176,14 +192,41 @@ thinkpad_sensor_refresh(void *arg)
                aml_evalinteger(sc->sc_acpi, sc->sc_ec->sc_devnode,
                    sname, 0, 0, &tmp);
                sc->sc_sens[i].value = (tmp * 1000000) + 273150000;
-               if (tmp > 127 || tmp < -127)
+               if (tmp > 127 || tmp < -127) {
                        sc->sc_sens[i].flags = SENSOR_FINVALID;
+                       sc->sc_sens[i].status = SENSOR_S_UNKNOWN;
+               }
+               if ((sc->sc_sens[i].flags & SENSOR_FINVALID) == SENSOR_FINVALID)
+                       continue;
+               if (tmp > maxtmp)
+                       maxtmp = tmp;
+               if (tmp > THINKPAD_TEMP_OUCH)
+                       sc->sc_sens[i].status = SENSOR_S_CRIT;
+               else
+                       sc->sc_sens[i].status = SENSOR_S_OK;
        }

        /* Read fan RPM */
        acpiec_read(sc->sc_ec, THINKPAD_ECOFFSET_FANLO, 1, &lo);
        acpiec_read(sc->sc_ec, THINKPAD_ECOFFSET_FANHI, 1, &hi);
-       sc->sc_sens[i].value = ((hi << 8L) + lo);
+       sc->sc_sens[THINKPAD_SENSOR_FANRPM].value = ((hi << 8L) + lo);
+
+       /* Update fan mode based on max temperature seen */
+       if (maxtmp > THINKPAD_TEMP_OUCH) {
+               mode = THINKPAD_FANMODE_DISENGAGED;
+               desc = "disengaged";
+               ss = SENSOR_S_CRIT;
+       } else {
+               mode = THINKPAD_FANMODE_AUTO;
+               desc = "auto";
+               ss = SENSOR_S_OK;
+       }
+       acpiec_write(sc->sc_ec, THINKPAD_ECOFFSET_FANMODE, 1, &mode);
+       sc->sc_sens[THINKPAD_SENSOR_FANMODE].value = mode;
+       sc->sc_sens[THINKPAD_SENSOR_FANMODE].status = ss;
+       snprintf(sc->sc_sens[THINKPAD_SENSOR_FANMODE].desc,
+           sizeof(sc->sc_sens[THINKPAD_SENSOR_FANMODE]),
+           "fan mode: %s", desc);
 }

 void
Index: share/man/man4/acpithinkpad.4
===================================================================
RCS file: /cvs/src/share/man/man4/acpithinkpad.4,v
retrieving revision 1.2
diff -u -p -r1.2 acpithinkpad.4
--- share/man/man4/acpithinkpad.4       31 May 2008 22:02:03 -0000      1.2
+++ share/man/man4/acpithinkpad.4       14 May 2011 06:43:22 -0000
@@ -28,6 +28,16 @@ The
 driver provides ACPI support for IBM/Lenovo ThinkPad laptops.
 It responds to various hotkey button presses such as the brightness
adjustment
 and wireless toggle keys.
+.Pp
+Also
+.Nm
+monitors temperature and when it goes too high (current limit is set to
80C),
+fan mode is changed to so called
+.Dq disengaged
+mode.
+When temperature goes back, fan mode control is returned to firmware.
+This prevents laptops like X201, with hot CPUs, from being shooted down by
+.Xr acpitz 4 .
 .Sh SEE ALSO
 .Xr acpi 4 ,
 .Xr intro 4

Reply via email to