Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c Now that sysmon_envsys(8) has learned how to ret...



details:   https://anonhg.NetBSD.org/src/rev/ae722ab7e1cd
branches:  trunk
changeset: 752545:ae722ab7e1cd
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Mon Mar 01 03:14:49 2010 +0000

description:
Now that sysmon_envsys(8) has learned how to retrieve and update sensor
limit values from the device driver, remove the high_limit and low_limit
entries from the hw.dbcool<#>.<sensor> sysctl(8) tree.  These limits are
now directly accessible via envstat(8).  Simplify the remaining code
somewhat.

No objections raised on either tech-kern@ or current-users@

XXX The fan controllers's parameters (including those that are tied to
XXX temperature sensors) are still in sysctl, since there isn't any clean
XXX way to implement the fan controllers in sysmon_envsys yet.  It is on
XXX my To-Do list...

diffstat:

 sys/dev/i2c/dbcool.c     |  691 ++++++++++++++++++++++++++--------------------
 sys/dev/i2c/dbcool_var.h |    5 +-
 2 files changed, 387 insertions(+), 309 deletions(-)

diffs (truncated from 917 to 300 lines):

diff -r e6a33307077d -r ae722ab7e1cd sys/dev/i2c/dbcool.c
--- a/sys/dev/i2c/dbcool.c      Mon Mar 01 01:59:48 2010 +0000
+++ b/sys/dev/i2c/dbcool.c      Mon Mar 01 03:14:49 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dbcool.c,v 1.17 2010/02/26 18:16:18 pgoyette Exp $ */
+/*     $NetBSD: dbcool.c,v 1.18 2010/03/01 03:14:49 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.17 2010/02/26 18:16:18 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.18 2010/03/01 03:14:49 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -78,6 +78,25 @@
 static int dbcool_read_temp(struct dbcool_softc *, uint8_t, bool);
 static int dbcool_read_volt(struct dbcool_softc *, uint8_t, int, bool);
 
+/* Sensor get/set limit functions */
+static void dbcool_get_limits(struct sysmon_envsys *, envsys_data_t *,
+                             sysmon_envsys_lim_t *, uint32_t *);
+static void dbcool_get_temp_limits(struct dbcool_softc *, int,
+                                  sysmon_envsys_lim_t *, uint32_t *);
+static void dbcool_get_volt_limits(struct dbcool_softc *, int,
+                                  sysmon_envsys_lim_t *, uint32_t *);
+static void dbcool_get_fan_limits(struct dbcool_softc *, int,
+                                 sysmon_envsys_lim_t *, uint32_t *);
+
+static void dbcool_set_limits(struct sysmon_envsys *, envsys_data_t *,
+                             sysmon_envsys_lim_t *, uint32_t *);
+static void dbcool_set_temp_limits(struct dbcool_softc *, int,
+                                  sysmon_envsys_lim_t *, uint32_t *);
+static void dbcool_set_volt_limits(struct dbcool_softc *, int,
+                                  sysmon_envsys_lim_t *, uint32_t *);
+static void dbcool_set_fan_limits(struct dbcool_softc *, int,
+                                 sysmon_envsys_lim_t *, uint32_t *);
+
 /* SYSCTL Helpers */
 static int sysctl_dbcool_temp(SYSCTLFN_PROTO);
 static int sysctl_adm1030_temp(SYSCTLFN_PROTO);
@@ -85,18 +104,14 @@
 static int sysctl_dbcool_duty(SYSCTLFN_PROTO);
 static int sysctl_dbcool_behavior(SYSCTLFN_PROTO);
 static int sysctl_dbcool_slope(SYSCTLFN_PROTO);
-static int sysctl_dbcool_volt_limit(SYSCTLFN_PROTO);
-static int sysctl_dbcool_temp_limit(SYSCTLFN_PROTO);
-static int sysctl_dbcool_fan_limit(SYSCTLFN_PROTO);
 static int sysctl_dbcool_thyst(SYSCTLFN_PROTO);
 
 /* Set-up subroutines */
-static void dbcool_setup_controllers(struct dbcool_softc *,
-       const struct sysctlnode *, int, int);
-static int dbcool_setup_sensors(struct dbcool_softc *,
-       const struct sysctlnode *, int, int);
-static int dbcool_attach_sensor(struct dbcool_softc *,
-       const struct sysctlnode *, int, int (*)(SYSCTLFN_PROTO));
+static void dbcool_setup_controllers(struct dbcool_softc *);
+static int  dbcool_setup_sensors(struct dbcool_softc *);
+static int  dbcool_attach_sensor(struct dbcool_softc *, int);
+static int  dbcool_attach_temp_control(struct dbcool_softc *, int,
+       struct chip_id *);
 
 #ifdef DBCOOL_DEBUG
 static int sysctl_dbcool_reg_select(SYSCTLFN_PROTO);
@@ -1211,141 +1226,6 @@
 }
 
 static int
-sysctl_dbcool_volt_limit(SYSCTLFN_ARGS)
-{
-       struct sysctlnode node;
-       struct dbcool_softc *sc;
-       int reg, error;
-       int nom, sensor_index;
-       int64_t val, newval;
-       uint8_t chipreg, newreg;
-
-       node = *rnode;
-       sc = (struct dbcool_softc *)node.sysctl_data;
-       chipreg = node.sysctl_num & 0xff;
-
-       /*
-        * Retrieve the nominal value for the voltage sensor
-        */
-       sensor_index = (node.sysctl_num >> 8 ) & 0xff;
-       nom = nominal_voltages[sc->sc_dc.dc_chip->table[sensor_index].nom_volt_index];
-       if (nom < 0)
-               nom = dbcool_supply_voltage(sc);
-
-       /*
-        * Use int64_t for calculation to avoid overflow
-        */
-       val =  sc->sc_dc.dc_readreg(&sc->sc_dc, chipreg);
-       val *= nom;
-       val /= 0xc0;    /* values are scaled so 0xc0 == nominal voltage */
-       reg = val;
-       node.sysctl_data = &reg;
-       error = sysctl_lookup(SYSCTLFN_CALL(&node));
-
-       if (error || newp == NULL)
-               return error;
-
-       /*
-        * We were asked to update the value, so scale it and sanity
-        * check before writing
-        */
-       if (nom == 0)
-               return EINVAL;
-       newval =  *(int *)node.sysctl_data;
-       newval *= 0xc0;
-       newval /= nom;
-       if (newval < 0 || newval > 0xff)
-               return EINVAL;
-
-       newreg = newval;
-       sc->sc_dc.dc_writereg(&sc->sc_dc, chipreg, newreg);
-       return 0;
-}
-
-static int
-sysctl_dbcool_temp_limit(SYSCTLFN_ARGS)
-{
-       struct sysctlnode node;
-       struct dbcool_softc *sc;
-       int reg, error, newtemp;
-       uint8_t chipreg;
-
-       node = *rnode;
-       sc = (struct dbcool_softc *)node.sysctl_data;
-       chipreg = node.sysctl_num & 0xff;
-
-       /* If using offset mode, adjust, else treat as signed */
-       if (sc->sc_temp_offset) {
-               reg = sc->sc_dc.dc_readreg(&sc->sc_dc, chipreg);
-               reg -= sc->sc_temp_offset;
-        } else
-               reg = (int8_t)sc->sc_dc.dc_readreg(&sc->sc_dc, chipreg);
-
-       node.sysctl_data = &reg;
-       error = sysctl_lookup(SYSCTLFN_CALL(&node));
-
-       if (error || newp == NULL)
-               return error;
-
-       /* We were asked to update the value - sanity check before writing */   
-       newtemp = *(int *)node.sysctl_data + sc->sc_temp_offset;
-       if (newtemp < 0 || newtemp > 0xff)
-               return EINVAL;
-
-       sc->sc_dc.dc_writereg(&sc->sc_dc, chipreg, newtemp);
-       return 0;
-}
-
-static int
-sysctl_dbcool_fan_limit(SYSCTLFN_ARGS)
-{
-       struct sysctlnode node;
-       struct dbcool_softc *sc;
-       int reg, error, newrpm, dividend;
-       uint8_t chipreg;
-       uint8_t newreg;
-
-       node = *rnode;
-       sc = (struct dbcool_softc *)node.sysctl_data;
-       chipreg = node.sysctl_num & 0xff;
-
-       /* retrieve two-byte limit */
-       reg = dbcool_read_rpm(sc, chipreg);
-
-       node.sysctl_data = &reg;
-       error = sysctl_lookup(SYSCTLFN_CALL(&node));
-
-       if (error || newp == NULL)
-               return error;
-
-       /*
-        * We were asked to update the value.  Calculate the two-byte
-        * limit and validate it.  Due to the way fan RPM is calculated,
-        * the new value must be at least 83 RPM (331 RPM for ADM1030)!
-        * Allow a value of -1 or 0 to indicate no limit.
-        */
-       newrpm = *(int *)node.sysctl_data;
-       if (newrpm == 0 || newrpm == -1)
-               newrpm = 0xffff;
-       else {
-               if (sc->sc_dc.dc_chip->flags & DBCFLAG_ADM1030)
-                       dividend = 11250 * 60;
-               else
-                       dividend = 90000 * 60;
-               newrpm = dividend / newrpm;
-               if (newrpm & ~0xffff)
-                       return EINVAL;
-       }
-
-       /* Update the on-chip registers with new value */
-       newreg = newrpm & 0xff;
-       sc->sc_dc.dc_writereg(&sc->sc_dc, chipreg, newreg);
-       newreg = (newrpm >> 8) & 0xff;
-       sc->sc_dc.dc_writereg(&sc->sc_dc, chipreg + 1, newreg);
-       return 0;
-}
-
-static int
 sysctl_dbcool_thyst(SYSCTLFN_ARGS)
 {
        struct sysctlnode node;
@@ -1463,7 +1343,7 @@
        struct sysctlnode *node = NULL;
 #endif
        uint8_t cfg_val, cfg_reg;
-       int ro_flag, rw_flag, ret, error;
+       int ret, error;
 
        /*
         * Some chips are capable of reporting an extended temperature range
@@ -1487,44 +1367,46 @@
        /* Determine Vcc for this chip */
        sc->sc_supply_voltage = dbcool_supply_voltage(sc);
 
-       sc->sc_sme = sysmon_envsys_create();
-
-       ro_flag = dbcool_islocked(sc)?CTLFLAG_READONLY:CTLFLAG_READWRITE;
-       ro_flag |= CTLFLAG_OWNDESC;
-       rw_flag = CTLFLAG_READWRITE | CTLFLAG_OWNDESC;
        ret = sysctl_createv(NULL, 0, NULL, &me,
               CTLFLAG_READWRITE,
               CTLTYPE_NODE, device_xname(self), NULL,
               NULL, 0, NULL, 0,
               CTL_HW, CTL_CREATE, CTL_EOL);
+       if (ret == 0)
+               sc->sc_root_sysctl_num = me->sysctl_num;
+       else
+               sc->sc_root_sysctl_num = 0;
+
+       /* Create the sensors for this device */
+       sc->sc_sme = sysmon_envsys_create();
+       if (dbcool_setup_sensors(sc))
+               goto out;
+
+       if (sc->sc_root_sysctl_num != 0) {
+               /* If supported, create sysctl tree for fan PWM controllers */
+               if (sc->sc_dc.dc_chip->power != NULL)
+                       dbcool_setup_controllers(sc);
 
 #ifdef DBCOOL_DEBUG
-       ret = sysctl_createv(NULL, 0, NULL,
-               (const struct sysctlnode **)&node,
-               CTLFLAG_READWRITE, CTLTYPE_INT, "reg_select", NULL,
-               sysctl_dbcool_reg_select,
-               0, sc, sizeof(int),
-               CTL_HW, me->sysctl_num, CTL_CREATE, CTL_EOL);
-       if (node != NULL)
-               node->sysctl_data = sc;
+               ret = sysctl_createv(NULL, 0, NULL,
+                       (const struct sysctlnode **)&node,
+                       CTLFLAG_READWRITE, CTLTYPE_INT, "reg_select", NULL,
+                       sysctl_dbcool_reg_select,
+                       0, sc, sizeof(int),
+                       CTL_HW, me->sysctl_num, CTL_CREATE, CTL_EOL);
+               if (node != NULL)
+                       node->sysctl_data = sc;
 
-       ret = sysctl_createv(NULL, 0, NULL,
-               (const struct sysctlnode **)&node,
-               CTLFLAG_READWRITE, CTLTYPE_INT, "reg_access", NULL,
-               sysctl_dbcool_reg_access,
-               0, sc, sizeof(int),
-               CTL_HW, me->sysctl_num, CTL_CREATE, CTL_EOL);
-       if (node != NULL)
-               node->sysctl_data = sc;
+               ret = sysctl_createv(NULL, 0, NULL,
+                       (const struct sysctlnode **)&node,
+                       CTLFLAG_READWRITE, CTLTYPE_INT, "reg_access", NULL,
+                       sysctl_dbcool_reg_access,
+                       0, sc, sizeof(int),
+                       CTL_HW, me->sysctl_num, CTL_CREATE, CTL_EOL);
+               if (node != NULL)
+                       node->sysctl_data = sc;
 #endif /* DBCOOL_DEBUG */
-
-       /* Create the sensors for this device */
-       if (dbcool_setup_sensors(sc, me, rw_flag, ro_flag))
-               goto out;
-
-       /* If supported, create sysctl tree for fan PWM controllers */
-       if (sc->sc_dc.dc_chip->power != NULL)
-               dbcool_setup_controllers(sc, me, rw_flag, ro_flag);
+       }
 
        /*
         * Read and rewrite config register to activate device
@@ -1546,6 +1428,8 @@
        sc->sc_sme->sme_name = device_xname(self);
        sc->sc_sme->sme_cookie = sc;
        sc->sc_sme->sme_refresh = dbcool_refresh;
+       sc->sc_sme->sme_set_limits = dbcool_set_limits;



Home | Main Index | Thread Index | Old Index