Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc64 Use the mk48txx driver for time-of-day cloc...



details:   https://anonhg.NetBSD.org/src/rev/f1e92084a31b
branches:  trunk
changeset: 495345:f1e92084a31b
user:      pk <pk%NetBSD.org@localhost>
date:      Wed Jul 26 13:39:36 2000 +0000

description:
Use the mk48txx driver for time-of-day clock access.

diffstat:

 sys/arch/sparc64/conf/files.sparc64 |    5 +-
 sys/arch/sparc64/sparc64/clock.c    |  205 ++++++-----------------------------
 sys/arch/sparc64/sparc64/clockreg.h |   96 ----------------
 3 files changed, 40 insertions(+), 266 deletions(-)

diffs (truncated from 497 to 300 lines):

diff -r 402eec73226c -r f1e92084a31b sys/arch/sparc64/conf/files.sparc64
--- a/sys/arch/sparc64/conf/files.sparc64       Wed Jul 26 12:41:40 2000 +0000
+++ b/sys/arch/sparc64/conf/files.sparc64       Wed Jul 26 13:39:36 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.sparc64,v 1.33 2000/06/18 07:03:35 mrg Exp $
+#      $NetBSD: files.sparc64,v 1.34 2000/07/26 13:39:39 pk Exp $
 
 # @(#)files.sparc64    8.1 (Berkeley) 7/19/93
 # sparc64-specific configuration info
@@ -59,7 +59,7 @@
 # network devices MII bus
 include "dev/mii/files.mii"
 
-device clock
+device clock: mk48txx
 attach clock at mainbus, sbus with clock_sbus
 attach clock at ebus with clock_ebus
 
@@ -69,6 +69,7 @@
 device eeprom
 attach eeprom at sbus, ebus
 file   arch/sparc64/sparc64/clock.c
+file   dev/clock_subr.c
 
 device power
 attach power at sbus, ebus
diff -r 402eec73226c -r f1e92084a31b sys/arch/sparc64/sparc64/clock.c
--- a/sys/arch/sparc64/sparc64/clock.c  Wed Jul 26 12:41:40 2000 +0000
+++ b/sys/arch/sparc64/sparc64/clock.c  Wed Jul 26 13:39:36 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clock.c,v 1.27 2000/07/26 12:39:20 pk Exp $ */
+/*     $NetBSD: clock.c,v 1.28 2000/07/26 13:39:36 pk Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -79,10 +79,11 @@
 #include <machine/autoconf.h>
 #include <machine/eeprom.h>
 #include <machine/cpu.h>
+#include <machine/idprom.h>
 
 #include <dev/clock_subr.h>
+#include <dev/ic/mk48txxreg.h>
 
-#include <sparc64/sparc64/clockreg.h>
 #include <sparc64/sparc64/intreg.h>
 #include <sparc64/sparc64/timerreg.h>
 #include <sparc64/dev/iommureg.h>
@@ -117,9 +118,8 @@
 static void    clockattach_sbus __P((struct device *, struct device *, void *));
 static int     clockmatch_ebus __P((struct device *, struct cfdata *, void *));
 static void    clockattach_ebus __P((struct device *, struct device *, void *));
-static void    clockattach __P((int, bus_space_handle_t));
+static void    clockattach __P((int, bus_space_tag_t, bus_space_handle_t));
 
-static struct clockreg *clock_map __P((bus_space_handle_t, char *));
 
 struct cfattach clock_sbus_ca = {
        sizeof(struct device), clockmatch_sbus, clockattach_sbus
@@ -131,6 +131,10 @@
 
 extern struct cfdriver clock_cd;
 
+/* Global TOD clock handle & idprom pointer */
+static todr_chip_handle_t todr_handle;
+static struct idprom *idprom;
+
 static int     timermatch __P((struct device *, struct cfdata *, void *));
 static void    timerattach __P((struct device *, struct device *, void *));
 
@@ -175,24 +179,6 @@
        return (strcmp("eeprom", ea->ea_name) == 0);
 }
 
-static struct clockreg *
-clock_map(bh, model)
-       bus_space_handle_t bh;
-       char *model;
-{
-       struct clockreg *cl;
-#if 0
-       paddr_t pa;
-
-       (void) pmap_extract(pmap_kernel(), (vaddr_t)bh, &pa);
-       pmap_enter(pmap_kernel(), (vaddr_t)bh, pa, VM_PROT_READ,
-           VM_PROT_READ|PMAP_WIRED);
-#endif
-       cl = (struct clockreg *)((long)bh + CLK_MK48T08_OFF);
-
-       return (cl);
-}
-
 /*
  * Attach a clock (really `eeprom') to the sbus or ebus.
  *
@@ -222,13 +208,14 @@
        void *aux;
 {
        struct sbus_attach_args *sa = aux;
+       bus_space_tag_t bt = sa->sa_bustag;
        bus_space_handle_t bh;
        int sz;
 
        /* use sa->sa_regs[0].size? */
        sz = 8192;
 
-       if (sbus_bus_map(sa->sa_bustag,
+       if (sbus_bus_map(bt,
                         sa->sa_slot,
                         (sa->sa_offset & ~NBPG),
                         sz,
@@ -238,7 +225,7 @@
                printf("%s: can't map register\n", self->dv_xname);
                return;
        }
-       clockattach(sa->sa_node, bh);
+       clockattach(sa->sa_node, bt, bh);
 }
 
 /* ARGSUSED */
@@ -248,13 +235,14 @@
        void *aux;
 {
        struct ebus_attach_args *ea = aux;
+       bus_space_tag_t bt = ea->ea_bustag;
        bus_space_handle_t bh;
        int sz;
 
        /* hard code to 8K? */
        sz = ea->ea_regs[0].size;
 
-       if (ebus_bus_map(ea->ea_bustag,
+       if (ebus_bus_map(bt,
                         0,
                         EBUS_PADDR_FROM_REG(&ea->ea_regs[0]),
                         sz,
@@ -264,36 +252,41 @@
                printf("%s: can't map register\n", self->dv_xname);
                return;
        }
-       clockattach(ea->ea_node, bh);
+       clockattach(ea->ea_node, bt, bh);
 }
 
 static void
-clockattach(node, bh)
+clockattach(node, bt, bh)
        int node;
+       bus_space_tag_t bt;
        bus_space_handle_t bh;
 {
        char *model;
-       struct clockreg *cl;
        struct idprom *idp;
        int h;
 
        model = getpropstring(node, "model");
+
 #ifdef DIAGNOSTIC
        if (model == NULL)
-               panic("no model");
+               panic("clockattach: no model property");
 #endif
-       printf(": %s (eeprom)", model);
 
-       cl = clock_map(bh, model);
-       idp = &cl->cl_idprom;
+       /* Our TOD clock year 0 is 1968 */
+       if ((todr_handle = mk48txx_attach(bt, bh, model, 1968)) == NULL)
+               panic("Can't attach %s tod clock", model);
+
+#define IDPROM_OFFSET (8*1024 - 40)    /* XXX - get nvram sz from driver */
+       idp = (struct idprom *)((u_long)bh + IDPROM_OFFSET);
 
        h = idp->id_machine << 24;
        h |= idp->id_hostid[0] << 16;
        h |= idp->id_hostid[1] << 8;
        h |= idp->id_hostid[2];
        hostid = h;
-       printf(" hostid %lx\n", (long)hostid);
-       clockreg = cl;
+       printf(": hostid %lx\n", (long)hostid);
+
+       idprom = idp;
 }
 
 /*
@@ -433,22 +426,19 @@
 myetheraddr(cp)
        u_char *cp;
 {
-       struct clockreg *cl = clockreg;
        struct idprom *idp;
 
-       if (!cl) {
+       if ((idp = idprom) == NULL) {
                int node, n;
 
                node = findroot();
-               idp = NULL;
                if (getprop(node, "idprom", sizeof *idp, &n, (void **)&idp) ||
                    n != 1) {
                        printf("\nmyetheraddr: clock not setup yet, "
                               "and no idprom property in /\n");
                        return;
                }
-       } else
-               idp = &cl->cl_idprom;
+       }
 
        cp[0] = idp->id_ether[0];
        cp[1] = idp->id_ether[1];
@@ -456,7 +446,7 @@
        cp[3] = idp->id_ether[3];
        cp[4] = idp->id_ether[4];
        cp[5] = idp->id_ether[5];
-       if (idp != &cl->cl_idprom)
+       if (idprom == NULL)
                free(idp, M_DEVBUF);
 }
 
@@ -469,7 +459,7 @@
 void
 cpu_initclocks()
 {
-       register int statint, minint;
+       int statint, minint;
 #ifdef DEBUG
        extern int intrdebug;
 #endif
@@ -684,110 +674,12 @@
 }
 
 /*
- * should use something like
- * #define LEAPYEAR(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
- * but it's unlikely that we'll still be around in 2100.
- */
-#define        LEAPYEAR(y)     (((y) & 3) == 0)
-
-/*
- * This code is defunct after 2068.
- * Will Unix still be here then??
- */
-const short dayyr[12] =
-    { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
-
-int
-chiptotime(sec, min, hour, day, mon, year)
-       register int sec, min, hour, day, mon, year;
-{
-       register int days, yr;
-
-       sec = FROMBCD(sec);
-       min = FROMBCD(min);
-       hour = FROMBCD(hour);
-       day = FROMBCD(day);
-       mon = FROMBCD(mon);
-       year = FROMBCD(year) + YEAR0;
-
-       /* simple sanity checks */
-       if (year < 70 || mon < 1 || mon > 12 || day < 1 || day > 31)
-               return (0);
-       days = 0;
-       for (yr = 70; yr < year; yr++)
-               days += LEAPYEAR(yr) ? 366 : 365;
-       days += dayyr[mon - 1] + day - 1;
-       if (LEAPYEAR(yr) && mon > 2)
-               days++;
-       /* now have days since Jan 1, 1970; the rest is easy... */
-       return (days * SECDAY + hour * 3600 + min * 60 + sec);
-}
-
-struct chiptime {
-       int     sec;
-       int     min;
-       int     hour;
-       int     wday;
-       int     day;
-       int     mon;
-       int     year;
-};
-
-void
-timetochip(c)
-       register struct chiptime *c;
-{
-       register int t, t2, t3, now = time.tv_sec;
-
-       /* compute the year */
-       t2 = now / SECDAY;
-       t3 = (t2 + 2) % 7;      /* day of week */
-       c->wday = TOBCD(t3 + 1);
-
-       t = 69;
-       while (t2 >= 0) {       /* whittle off years */
-               t3 = t2;
-               t++;
-               t2 -= LEAPYEAR(t) ? 366 : 365;
-       }



Home | Main Index | Thread Index | Old Index