Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/macppc switch smu to common fan control code



details:   https://anonhg.NetBSD.org/src/rev/4e1394a8bec1
branches:  trunk
changeset: 1023322:4e1394a8bec1
user:      macallan <macallan%NetBSD.org@localhost>
date:      Fri Sep 03 17:18:39 2021 +0000

description:
switch smu to common fan control code

diffstat:

 sys/arch/macppc/conf/files.macppc |    4 +-
 sys/arch/macppc/dev/smu.c         |  291 +++++++++++--------------------------
 2 files changed, 88 insertions(+), 207 deletions(-)

diffs (truncated from 493 to 300 lines):

diff -r c2b9a9f68965 -r 4e1394a8bec1 sys/arch/macppc/conf/files.macppc
--- a/sys/arch/macppc/conf/files.macppc Fri Sep 03 16:21:15 2021 +0000
+++ b/sys/arch/macppc/conf/files.macppc Fri Sep 03 17:18:39 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.macppc,v 1.121 2021/07/27 23:38:42 macallan Exp $
+#      $NetBSD: files.macppc,v 1.122 2021/09/03 17:18:39 macallan Exp $
 #
 # macppc-specific configuration info
 
@@ -180,7 +180,7 @@
 file arch/macppc/dev/fancontrol.c              fancontrol
 defflag        opt_fancontrol.h        FANCONTROL_DEBUG
 
-device smu { } : fancontrol
+device smu { } : sysmon_envsys, fancontrol
 attach smu at mainbus
 file arch/macppc/dev/smu.c                     smu needs-flag
 defflag        opt_smu.h       SMU_DEBUG
diff -r c2b9a9f68965 -r 4e1394a8bec1 sys/arch/macppc/dev/smu.c
--- a/sys/arch/macppc/dev/smu.c Fri Sep 03 16:21:15 2021 +0000
+++ b/sys/arch/macppc/dev/smu.c Fri Sep 03 17:18:39 2021 +0000
@@ -46,6 +46,7 @@
 
 #include <macppc/dev/obiovar.h>
 #include <macppc/dev/smuvar.h>
+#include <macppc/dev/fancontrolvar.h>
 
 #include "opt_smu.h"
 
@@ -67,7 +68,9 @@
        int min_rpm;
        int max_rpm;
        int default_rpm;
+       int wanted_rpm;
        int current_rpm;
+       int fault;
        time_t last_update;
 };
 
@@ -82,19 +85,11 @@
 #define SMU_MAX_IICBUS         3
 #define SMU_MAX_SME_SENSORS    (SMU_MAX_FANS + 8)
 
-struct smu_zone {
-       bool (*filter)(const envsys_data_t *);
-       int nfans;
-       int fans[SMU_MAX_FANS];
-       int threshold, step;
-       int duty;
-};
 
-
-#define SMU_ZONE_CPUS  0
-#define SMU_ZONE_DRIVES        1
-#define SMU_ZONE_SLOTS 2
-#define SMU_ZONES      3
+#define SMU_ZONE_CPU           0
+#define SMU_ZONE_CASE          1
+#define SMU_ZONE_DRIVEBAY      2
+#define SMU_ZONES              3
 
 #define C_TO_uK(n) (n * 1000000 + 273150000)
 
@@ -123,7 +118,7 @@
        uint32_t cpu_m;
        int32_t  cpu_b;
 
-       struct smu_zone sc_zones[SMU_ZONES];
+       fancontrol_zone_t sc_zones[SMU_ZONES];
        lwp_t *sc_thread;
        bool sc_dying;
 };
@@ -165,20 +160,19 @@
 static int smu_todr_gettime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *);
 static int smu_todr_settime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *);
 static int smu_fan_update_rpm(struct smu_fan *);
-static int smu_fan_get_rpm(struct smu_fan *, int *);
-static int smu_fan_set_rpm(struct smu_fan *, int);
 static int smu_read_adc(struct smu_softc *, int);
 
 static int smu_iicbus_exec(void *, i2c_op_t, i2c_addr_t, const void *,
     size_t, void *, size_t, int);
-static int smu_sysctl_fan_rpm(SYSCTLFN_ARGS);
 
 static void smu_setup_zones(struct smu_softc *);
-static void smu_adjust_zone(struct smu_softc *, int);
 static void smu_adjust(void *);
+
 static bool is_cpu_sensor(const envsys_data_t *);
 static bool is_drive_sensor(const envsys_data_t *);
 static bool is_slots_sensor(const envsys_data_t *);
+static int smu_fan_get_rpm(void *, int);
+static int smu_fan_set_rpm(void *, int, int);
 
 int smu_get_datablock(int, uint8_t *, size_t);
 
@@ -299,9 +293,8 @@
 smu_setup_fans(struct smu_softc *sc)
 {
        struct smu_fan *fan;
-       struct sysctlnode *sysctl_fans, *sysctl_fan, *sysctl_node;
-       char type[32], sysctl_fan_name[32];
-       int node, i, j;
+       char type[32];
+       int node, i;
        const char *fans[] = { "fans", "rpm-fans", 0 };
        int n = 0;
        
@@ -349,6 +342,8 @@
                            fan->location, fan->reg, fan->zone, fan->rpm_ctl,
                            fan->min_rpm, fan->max_rpm, fan->default_rpm);
 
+                       fan->wanted_rpm = fan->default_rpm;
+                       fan->fault = 0; 
                        sc->sc_num_fans++;
                }
                n++;
@@ -356,88 +351,8 @@
 
        for (i = 0; i < sc->sc_num_fans; i++) {
                fan = &sc->sc_fans[i];
-               smu_fan_set_rpm(fan, fan->default_rpm);
-               smu_fan_get_rpm(fan, &fan->current_rpm);
-       }
-
-       /* Create sysctl nodes for each fan */
-
-       sysctl_createv(NULL, 0, NULL, (void *) &sysctl_fans,
-           CTLFLAG_READWRITE | CTLFLAG_OWNDESC,
-           CTLTYPE_NODE, "fans", NULL,
-           NULL, 0, NULL, 0,
-           CTL_MACHDEP,
-           sc->sc_sysctl_me->sysctl_num,
-           CTL_CREATE, CTL_EOL);
-
-       for (i = 0; i < sc->sc_num_fans; i++) {
-               fan = &sc->sc_fans[i];
-
-               for (j = 0; j < strlen(fan->location); j++) {
-                       sysctl_fan_name[j] = tolower(fan->location[j]);
-                       if (sysctl_fan_name[j] == ' ')
-                               sysctl_fan_name[j] = '_';
-               }
-               sysctl_fan_name[j] = '\0';
-
-               sysctl_createv(NULL, 0, NULL, (void *) &sysctl_fan,
-                   CTLFLAG_READWRITE | CTLFLAG_OWNDESC,
-                   CTLTYPE_NODE, sysctl_fan_name, "fan information",
-                   NULL, 0, NULL, 0,
-                   CTL_MACHDEP,
-                   sc->sc_sysctl_me->sysctl_num,
-                   sysctl_fans->sysctl_num,
-                   CTL_CREATE, CTL_EOL);
-
-               sysctl_createv(NULL, 0, NULL, (void *) &sysctl_node,
-                   CTLFLAG_READONLY | CTLFLAG_OWNDESC,
-                   CTLTYPE_INT, "zone", "fan zone",
-                   NULL, 0, &fan->zone, 0,
-                   CTL_MACHDEP,
-                   sc->sc_sysctl_me->sysctl_num,
-                   sysctl_fans->sysctl_num,
-                   sysctl_fan->sysctl_num,
-                   CTL_CREATE, CTL_EOL);
-
-               sysctl_createv(NULL, 0, NULL, (void *) &sysctl_node,
-                   CTLFLAG_READONLY | CTLFLAG_OWNDESC,
-                   CTLTYPE_INT, "min_rpm", "fan minimum rpm",
-                   NULL, 0, &fan->min_rpm, 0,
-                   CTL_MACHDEP,
-                   sc->sc_sysctl_me->sysctl_num,
-                   sysctl_fans->sysctl_num,
-                   sysctl_fan->sysctl_num,
-                   CTL_CREATE, CTL_EOL);
-
-               sysctl_createv(NULL, 0, NULL, (void *) &sysctl_node,
-                   CTLFLAG_READONLY | CTLFLAG_OWNDESC,
-                   CTLTYPE_INT, "max_rpm", "fan maximum rpm",
-                   NULL, 0, &fan->max_rpm, 0,
-                   CTL_MACHDEP,
-                   sc->sc_sysctl_me->sysctl_num,
-                   sysctl_fans->sysctl_num,
-                   sysctl_fan->sysctl_num,
-                   CTL_CREATE, CTL_EOL);
-
-               sysctl_createv(NULL, 0, NULL, (void *) &sysctl_node,
-                   CTLFLAG_READONLY | CTLFLAG_OWNDESC,
-                   CTLTYPE_INT, "default_rpm", "fan default rpm",
-                   NULL, 0, &fan->default_rpm, 0,
-                   CTL_MACHDEP,
-                   sc->sc_sysctl_me->sysctl_num,
-                   sysctl_fans->sysctl_num,
-                   sysctl_fan->sysctl_num,
-                   CTL_CREATE, CTL_EOL);
-
-               sysctl_createv(NULL, 0, NULL, (void *) &sysctl_node,
-                   CTLFLAG_READWRITE | CTLFLAG_OWNDESC,
-                   CTLTYPE_INT, "rpm", "fan current rpm",
-                   smu_sysctl_fan_rpm, 0, (void *) fan, 0,
-                   CTL_MACHDEP,
-                   sc->sc_sysctl_me->sysctl_num,
-                   sysctl_fans->sysctl_num,
-                   sysctl_fan->sysctl_num,
-                   CTL_CREATE, CTL_EOL);
+               smu_fan_set_rpm(sc, i, fan->default_rpm);
+               smu_fan_update_rpm(fan);
        }
 }
 
@@ -554,18 +469,17 @@
 smu_sme_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
 {
        struct smu_softc *sc = sme->sme_cookie;
-       struct smu_fan *fan;
        int which = edata->sensor;
        int ret;
 
        edata->state = ENVSYS_SINVALID;
 
        if (which < sc->sc_num_fans) {
-               fan = &sc->sc_fans[which];
 
-               ret = smu_fan_get_rpm(fan, &fan->current_rpm);
-               if (ret == 0) {
-                       edata->value_cur = fan->current_rpm;
+               ret = smu_fan_get_rpm(sc, which);
+               if (ret != -1) {
+                       sc->sc_fans[which].current_rpm = ret;
+                       edata->value_cur = ret;
                        edata->state = ENVSYS_SVALID;
                }
        } else if (edata->private > 0) {
@@ -738,7 +652,7 @@
 {
        struct smu_softc *sc = fan->sc;
        struct smu_cmd cmd;
-       int ret;
+       int ret, diff;
 
        cmd.cmd = SMU_CMD_FAN;
        cmd.len = 2;
@@ -761,31 +675,35 @@
                            cmd.data[2 + fan->reg * 2];
                }
        }
-
+       diff = abs(fan->current_rpm - fan->wanted_rpm);
+       if (diff > fan->max_rpm >> 3) {
+               fan->fault++;
+       } else fan->fault = 0;
        return ret;
 }
 
 static int
-smu_fan_get_rpm(struct smu_fan *fan, int *rpm)
+smu_fan_get_rpm(void *cookie, int which)
 {
+       struct smu_softc *sc = cookie;
+       struct smu_fan *fan = &sc->sc_fans[which];
        int ret;
        ret = 0;
 
        if (time_uptime - fan->last_update > 1) {
                ret = smu_fan_update_rpm(fan);
                if (ret != 0)
-                       return ret;
+                       return -1;
        }
 
-       *rpm = fan->current_rpm;
-
-       return ret;
+       return fan->current_rpm;
 }
 
 static int
-smu_fan_set_rpm(struct smu_fan *fan, int rpm)
+smu_fan_set_rpm(void *cookie, int which, int rpm)
 {
-       struct smu_softc *sc = fan->sc;
+       struct smu_softc *sc = cookie;
+       struct smu_fan *fan = &sc->sc_fans[which];
        struct smu_cmd cmd;
        int ret;
 
@@ -794,6 +712,8 @@
        rpm = uimax(fan->min_rpm, rpm);
        rpm = uimin(fan->max_rpm, rpm);
 
+       fan->wanted_rpm = rpm;
+
        cmd.cmd = SMU_CMD_FAN;
        cmd.len = 4;
        cmd.data[0] = 0x30;
@@ -887,33 +807,6 @@
        return 0;
 }
 
-static int
-smu_sysctl_fan_rpm(SYSCTLFN_ARGS)
-{



Home | Main Index | Thread Index | Old Index