Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Add an extremely rough SMBus handler and RTC driver...



details:   https://anonhg.NetBSD.org/src/rev/ef8de841e1f8
branches:  trunk
changeset: 532259:ef8de841e1f8
user:      simonb <simonb%NetBSD.org@localhost>
date:      Tue Jun 04 08:32:41 2002 +0000

description:
Add an extremely rough SMBus handler and RTC driver.  This will be
cleaned up significantly when we have an MI SMBus framework, but at
least we can see the RTC on the swarm now.

diffstat:

 sys/arch/mips/conf/files.sibyte       |   14 +
 sys/arch/mips/sibyte/dev/sbsmbus.c    |  121 +++++++
 sys/arch/mips/sibyte/dev/sbsmbusvar.h |   41 ++
 sys/arch/sbmips/sbmips/rtc.c          |  564 ++++++++++++++++++++++++++++++++++
 4 files changed, 740 insertions(+), 0 deletions(-)

diffs (truncated from 759 to 300 lines):

diff -r 5110157b4373 -r ef8de841e1f8 sys/arch/mips/conf/files.sibyte
--- a/sys/arch/mips/conf/files.sibyte   Tue Jun 04 05:53:31 2002 +0000
+++ b/sys/arch/mips/conf/files.sibyte   Tue Jun 04 08:32:41 2002 +0000
@@ -55,3 +55,17 @@
 attach sbscn at sbobio
 file   arch/mips/sibyte/dev/sbscn.c            sbscn   needs-flag
 
+# XXX XXX
+# need to think about SMBus more, just hack something together
+# temporariliy so we can use the RTC.
+
+# SB1250 SMBus
+device smbus {[chan = -1], [dev = -1]}
+attach smbus at sbobio
+file   arch/mips/sibyte/dev/sbsmbus.c          smbus
+
+# XXX XXX
+# Bogus RTC attachment
+device rtc
+attach rtc at smbus
+file   arch/sbmips/sbmips/rtc.c
diff -r 5110157b4373 -r ef8de841e1f8 sys/arch/mips/sibyte/dev/sbsmbus.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/mips/sibyte/dev/sbsmbus.c        Tue Jun 04 08:32:41 2002 +0000
@@ -0,0 +1,121 @@
+/* $NetBSD: sbsmbus.c,v 1.1 2002/06/04 08:32:41 simonb Exp $ */
+
+/*
+ * Copyright 2002 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Simon Burge for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed for the NetBSD Project by
+ *      Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ *    or promote products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+
+#include <machine/swarm.h>
+#include <mips/sibyte/dev/sbsmbusvar.h>
+
+#include "locators.h"
+
+static int smbus_match(struct device *, struct cfdata *, void *);
+static void smbus_attach(struct device *, struct device *, void *);
+static int smbus_print(void *, const char *);
+static int smbus_submatch(struct device *, struct cfdata *, void *);
+
+struct cfattach smbus_ca = {
+       sizeof(struct device), smbus_match, smbus_attach
+};
+
+/* autoconfiguration match information for zbbus children */
+struct smbus_attach_locs {
+       int     sa_interface;
+       int     sa_device;
+};
+
+/* XXX XXX this table should be imported from machine-specific code XXX XXX */
+static const struct smbus_attach_locs smbus_devs[] = {
+       { X1240_SMBUS_CHAN,     X1240_RTC_SMBUS_DEV },
+};
+static const int smbus_dev_count = sizeof smbus_devs / sizeof smbus_devs[0];
+
+static int found = 0;
+
+static int
+smbus_match(struct device *parent, struct cfdata *match, void *aux)
+{
+
+       /* 2 SMBus's on the BCM112x and BCM1250 */
+       return (found < 2);
+}
+
+static void
+smbus_attach(struct device *parent, struct device *self, void *aux)
+{
+       struct smbus_attach_args sa;
+       int i;
+
+       found++;
+       printf("\n");
+
+       for (i = 0; i < smbus_dev_count; i++) {
+               if (self->dv_unit != smbus_devs[i].sa_interface)
+                       continue;
+
+               memset(&sa, 0, sizeof sa);
+               sa.sa_interface = smbus_devs[i].sa_interface;
+               sa.sa_device = smbus_devs[i].sa_device;
+               config_found_sm(self, &sa, smbus_print, smbus_submatch);
+       }
+}
+
+
+static int
+smbus_print(void *aux, const char *pnp)
+{
+       struct smbus_attach_args *sa = aux;
+
+       if (pnp)
+               printf("rtc0 at %s", pnp);      /* XXX! */
+       printf(" device 0x%x", sa->sa_device);
+
+       return (UNCONF);
+}
+
+static int
+smbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
+{
+       struct smbus_attach_args *sa = aux;
+
+       if (cf->cf_loc[SMBUSCF_DEV] != SMBUSCF_DEV_DEFAULT &&
+           cf->cf_loc[SMBUSCF_DEV] != sa->sa_device)
+               return (0);
+
+       return ((*cf->cf_attach->ca_match)(parent, cf, aux));
+}
diff -r 5110157b4373 -r ef8de841e1f8 sys/arch/mips/sibyte/dev/sbsmbusvar.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/mips/sibyte/dev/sbsmbusvar.h     Tue Jun 04 08:32:41 2002 +0000
@@ -0,0 +1,41 @@
+/* $NetBSD: sbsmbusvar.h,v 1.1 2002/06/04 08:32:42 simonb Exp $ */
+
+/*
+ * Copyright 2002 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Simon Burge for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed for the NetBSD Project by
+ *      Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ *    or promote products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+struct smbus_attach_args {
+       int     sa_interface;
+       int     sa_device;
+};
diff -r 5110157b4373 -r ef8de841e1f8 sys/arch/sbmips/sbmips/rtc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sbmips/sbmips/rtc.c      Tue Jun 04 08:32:41 2002 +0000
@@ -0,0 +1,564 @@
+/* $NetBSD: rtc.c,v 1.1 2002/06/04 08:32:42 simonb Exp $ */
+
+/*
+ * Copyright 2002 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Simon Burge for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed for the NetBSD Project by
+ *      Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ *    or promote products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+
+#include <dev/clock_subr.h>
+
+#include <machine/systemsw.h>
+
+#include <mips/locore.h>
+#include <mips/sibyte/dev/sbsmbusvar.h>
+
+/* XXX should be in an x1241.h header */
+#define        X1241REG_BL             0x10    /* block protect bits */
+#define        X1241REG_SC             0x30    /* Seconds */
+#define        X1241REG_MN             0x31    /* Minutes */
+#define        X1241REG_HR             0x32    /* Hours */
+#define        X1241REG_DT             0x33    /* Day of month */
+#define        X1241REG_MO             0x34    /* Month */
+#define        X1241REG_YR             0x35    /* Year */
+#define        X1241REG_DW             0x36    /* Day of Week */
+#define        X1241REG_Y2K            0x37    /* Year 2K */
+#define        X1241REG_SR             0x3f    /* Status register */
+
+/* Register bits for the status register */
+#define        X1241REG_SR_BAT         0x80    /* currently on battery power */
+#define        X1241REG_SR_RWEL        0x04    /* r/w latch is enabled, can write RTC */
+#define        X1241REG_SR_WEL         0x02    /* r/w latch is unlocked, can enable r/w now */
+#define        X1241REG_SR_RTCF        0x01    /* clock failed */
+
+/* Register bits for the block protect register */
+#define        X1241REG_BL_BP2         0x80    /* block protect 2 */
+#define        X1241REG_BL_BP1         0x40    /* block protect 1 */
+#define        X1241REG_BL_BP0         0x20    /* block protect 0 */
+#define        X1241REG_BL_WD1         0x10
+#define        X1241REG_BL_WD0         0x08
+
+/* Register bits for the hours register */
+#define        X1241REG_HR_MIL         0x80    /* military time format */
+
+struct rtc_softc {
+       struct device           sc_dev;
+       int                     sc_smbus_chan;
+       int                     sc_smbus_addr;
+       struct todr_chip_handle sc_ct;
+};
+
+static int rtc_match(struct device *, struct cfdata *, void *);
+static void rtc_attach(struct device *, struct device *, void *);
+static int rtc_gettime(todr_chip_handle_t, struct timeval *);
+static int rtc_settime(todr_chip_handle_t, struct timeval *);
+static int rtc_getcal(todr_chip_handle_t, int *);
+static int rtc_setcal(todr_chip_handle_t, int);
+static void rtc_inittodr(void *, time_t base);
+static void rtc_resettodr(void *);
+static void rtc_cal_timer(void);
+
+static void time_smbus_init(int);
+static int time_waitready(int);
+static int time_readrtc(int, int, int);
+static int time_writertc(int, int, int, int);
+
+#define        WRITERTC(sc, dev, val)  \
+       time_writertc((sc)->sc_smbus_chan, (sc)->sc_smbus_addr, (dev), (val))
+#define        READRTC(sc, dev)        \
+       time_readrtc((sc)->sc_smbus_chan, (sc)->sc_smbus_addr, (dev))
+
+



Home | Main Index | Thread Index | Old Index