Rather than calling acpi_setfan() again would it make
sense to remove the cached state value and move
the state reading to just before the method is called?

That said I'm not familiar with the acpitz code and
haven't gone off to look at the spec.

Index: acpitz.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpitz.c,v
retrieving revision 1.47
diff -u -p -r1.47 acpitz.c
--- acpitz.c    12 Jul 2014 02:44:49 -0000      1.47
+++ acpitz.c    26 Aug 2014 16:27:29 -0000
@@ -49,7 +49,6 @@ struct acpitz_softc {
        int                     sc_crt;
        int                     sc_hot;
        int                     sc_ac[ACPITZ_MAX_AC];
-       int                     sc_ac_stat[ACPITZ_MAX_AC];
        int                     sc_pse;
        int                     sc_psv;
        int                     sc_tc1;
@@ -140,7 +139,6 @@ acpitz_init(struct acpitz_softc *sc, int
                for (i = 0; i < ACPITZ_MAX_AC; i++) {
                        snprintf(name, sizeof(name), "_AC%d", i);
                        sc->sc_ac[i] = acpitz_getreading(sc, name);
-                       sc->sc_ac_stat[i] = -1;
                }
        }
 
@@ -317,18 +315,20 @@ acpitz_setfan(struct acpitz_softc *sc, i
                                    DEVNAME(sc), name, x, y);
                                continue;
                        }
-                       if (aml_evalname(sc->sc_acpi, ref->node, method, 0,
-                           NULL, NULL))
-                               printf("%s: %s[%d.%d] %s fails\n",
-                                   DEVNAME(sc), name, x, y, method);
 
-                       /* save off status of fan */
                        if (aml_evalinteger(sc->sc_acpi, ref->node, "_STA", 0,
-                           NULL, &sta))
+                           NULL, &sta)) {
                                printf("%s: %s[%d.%d] _STA fails\n",
                                    DEVNAME(sc), name, x, y);
-                       else {
-                               sc->sc_ac_stat[i] = sta;
+                               sta = -1;
+                       }
+
+                       if ((sta <= 0 && !strcmp(method, "_ON_")) ||
+                           (sta > 0 && !strcmp(method, "_OFF"))) {
+                               if (aml_evalname(sc->sc_acpi, ref->node, method,
+                                   0, NULL, NULL))
+                                       printf("%s: %s[%d.%d] %s fails\n",
+                                           DEVNAME(sc), name, x, y, method);
                        }
                }
                aml_freevalue(&res1);
@@ -420,12 +420,10 @@ acpitz_refresh(void *arg)
        for (i = 0; i < ACPITZ_MAX_AC; i++) {
                if (sc->sc_ac[i] != -1 && sc->sc_ac[i] <= sc->sc_tmp) {
                        /* turn on fan i */
-                       if (sc->sc_ac_stat[i] <= 0)
-                               acpitz_setfan(sc, i, "_ON_");
+                       acpitz_setfan(sc, i, "_ON_");
                } else if (sc->sc_ac[i] != -1) {
                        /* turn off fan i */
-                       if (sc->sc_ac_stat[i] > 0)
-                               acpitz_setfan(sc, i, "_OFF");
+                       acpitz_setfan(sc, i, "_OFF");
                }
        }
        sc->sc_sens.value = sc->sc_tmp * 100000 - 50000;

Reply via email to