Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/isa Add Riscom/N2 isa driver, most of the probe code...



details:   https://anonhg.NetBSD.org/src/rev/3915e5b497c5
branches:  trunk
changeset: 480106:3915e5b497c5
user:      chopps <chopps%NetBSD.org@localhost>
date:      Tue Jan 04 06:29:21 2000 +0000

description:
Add Riscom/N2 isa driver, most of the probe code was adapted from the
freebsd if_sr.c driver.

diffstat:

 sys/dev/isa/if_ntwoc_isa.c    |  795 ++++++++++++++++++++++++++++++++++++++++++
 sys/dev/isa/if_ntwoc_isareg.h |  117 ++++++
 2 files changed, 912 insertions(+), 0 deletions(-)

diffs (truncated from 920 to 300 lines):

diff -r 70af271bea41 -r 3915e5b497c5 sys/dev/isa/if_ntwoc_isa.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/isa/if_ntwoc_isa.c        Tue Jan 04 06:29:21 2000 +0000
@@ -0,0 +1,795 @@
+/*     $NetBSD: if_ntwoc_isa.c,v 1.1 2000/01/04 06:29:21 chopps Exp $  */
+/* 
+ * Copyright (c) 1999 Christian E. Hopps
+ * Copyright (c) 1996 John Hay.
+ * Copyright (c) 1996 SDL Communications, Inc.
+ * All rights reserved.
+ * 
+ * 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. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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.
+ *
+ * $Id: if_ntwoc_isa.c,v 1.1 2000/01/04 06:29:21 chopps Exp $
+ */
+
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+
+#include <net/if.h>
+
+#include <machine/cpu.h>
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <dev/isa/isavar.h>
+
+#include <dev/ic/hd64570reg.h>
+#include <dev/ic/hd64570var.h>
+
+#include <dev/isa/if_ntwoc_isareg.h>
+
+#if 1
+#define NTWO_DEBUG
+#endif
+
+#ifdef NTWO_DEBUG
+#define NTWO_DPRINTF(x) printf x
+#else
+#define NTWO_DPRINTF(x)
+#endif
+
+#if __NetBSD_Version__ >= 104160000
+static void ntwoc_isa_config_interrupts __P((struct device *));
+#else
+#define        SCA_BASECLOCK   9830400
+#endif
+
+/* hard core 16k for now */
+#define        NTWOC_WIN_SIZE  0x4000
+
+struct ntwoc_isa_softc {
+       /* Generic device stuff */
+       struct device sc_dev;           /* Common to all devices */
+
+       /* PCI chipset glue */
+       void            *sc_ih; /* Interrupt handler */
+       isa_chipset_tag_t sc_ic;        /* ISA chipset handle */
+
+       struct sca_softc sc_sca;        /* the SCA itself */
+};
+
+static  int ntwoc_isa_probe __P((struct device *, struct cfdata *, void *));
+static  void ntwoc_isa_attach __P((struct device *, struct device *, void *));
+
+static void ntwoc_isa_clock_callback __P((void *, int, int));
+static void ntwoc_isa_dtr_callback __P((void *, int, int));
+static int ntwoc_isa_intr __P((void *));
+static void ntwoc_isa_get_clock __P((struct sca_port *, u_int8_t, u_int8_t,
+    u_int8_t, u_int8_t));
+static void ntwoc_isa_setup_memory(struct sca_softc *sc);
+static void ntwoc_isa_shutdown __P((void *sc));
+
+struct cfattach ntwoc_isa_ca = {
+       sizeof(struct ntwoc_isa_softc), ntwoc_isa_probe, ntwoc_isa_attach,
+};
+
+/*
+ * Names for daughter card types.  These match the NTWOC_DB_* defines.
+ */
+char *ntwoc_db_names[] = {
+       "V.35", "Unknown 0x01", "Test", "Unknown 0x03",
+       "RS232", "Unknown 0x05", "RS422", "None"
+};
+
+/* some weird offset XXX */
+#define SCA_REG(r)     (((r) & 0xf) + (((r) & 0xf0) << 6))
+
+/*
+ * functions that read and write to the sca registers
+ */
+static void
+ntwoc_isa_sca_write_1(struct sca_softc *sc, u_int reg, u_int8_t val)
+{
+       bus_space_write_1(sc->sc_iot, sc->scu_sca_ioh[(reg & 0xf0) >> 4],
+           (reg & 0xf), val);
+}
+
+static void
+ntwoc_isa_sca_write_2(struct sca_softc *sc, u_int reg, u_int16_t val)
+{
+       bus_space_write_2(sc->sc_iot, sc->scu_sca_ioh[(reg & 0xf0) >> 4],
+           (reg & 0xf), val);
+}
+
+static u_int8_t
+ntwoc_isa_sca_read_1(struct sca_softc *sc, u_int reg)
+{
+       return
+           bus_space_read_1(sc->sc_iot, sc->scu_sca_ioh[(reg & 0xf0) >> 4],
+           (reg & 0xf));
+}
+
+static u_int16_t
+ntwoc_isa_sca_read_2(struct sca_softc *sc, u_int reg)
+{
+       return
+           bus_space_read_2(sc->sc_iot, sc->scu_sca_ioh[(reg & 0xf0) >> 4],
+           (reg & 0xf));
+}
+
+/*
+ * set the correct window/page
+ */
+static void
+ntwoc_isa_set_page(struct sca_softc *sca, bus_addr_t addr)
+{
+       u_int8_t psr;
+
+       /* get old psr value replace old window with new */
+       psr = bus_space_read_1(sca->sc_iot, sca->sc_ioh, NTWOC_PSR);
+       psr &= ~NTWOC_PG_MSK;
+       psr |= ((addr >> sca->scu_pageshift) & NTWOC_PG_MSK);
+       bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_PSR, psr);
+}
+
+/*
+ * enable the memory window
+ */
+static void
+ntwoc_isa_set_on(struct sca_softc *sca)
+{
+       u_int8_t pcr;
+
+       /* get old value and add window enable */
+       pcr = bus_space_read_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR);
+       pcr |= NTWOC_PCR_MEM_WIN;
+       bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR, pcr);
+}
+
+/*
+ * turn off memory window
+ */
+static void
+ntwoc_isa_set_off(struct sca_softc *sca)
+{
+       u_int8_t pcr;
+
+       /* get old value and remove window enable */
+       pcr = bus_space_read_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR);
+       pcr &= ~NTWOC_PCR_MEM_WIN;
+       bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR, pcr);
+}
+
+static int
+ntwoc_isa_probe(struct device *parent, struct cfdata *match, void *aux)
+{
+       struct isa_attach_args *ia;
+       bus_space_tag_t iot, memt;
+       bus_space_handle_t ioh, memh, sca_ioh[16];
+       int i, tmp, dbg, rv;
+       int gotmem, gotsca[16];
+       u_int32_t ioport;
+
+       ia = (struct isa_attach_args *)aux;
+       iot = ia->ia_iot;
+       memt = ia->ia_memt;
+
+       memset(gotsca, 0, sizeof(gotsca));
+       gotmem = rv = 0;
+       dbg = 0;
+
+       /* disallow wildcarded I/O base */
+       if (ia->ia_iobase == ISACF_PORT_DEFAULT) {
+               printf("ntwoc_isa_probe: must specify port address\n");
+               return (0);
+       }
+
+       if (ia->ia_irq == ISACF_IRQ_DEFAULT) {
+               printf("ntwoc_isa_probe: must specify irq\n");
+               return (0);
+       }
+
+       if (ia->ia_maddr == ISACF_IOMEM_DEFAULT) {
+               printf("ntwoc_isa_probe: must specify iomem\n");
+               return (0);
+       }
+
+       tmp = (match->cf_flags & NTWOC_FLAGS_NPORT_MASK) + 1;
+       if (tmp < 1 || tmp > 2) {
+               printf("ntwoc_isa_probe: only 1 or 2 ports allowed\n");
+               return (0);
+       }
+
+       /* map the isa io addresses */
+       if ((tmp = bus_space_map(iot, ia->ia_iobase, NTWOC_SRC_IOPORT_SIZE, 0,
+           &ioh))) {
+               printf("ntwoc_isa_probe: mapping port 0x%x sz %d failed: %d\n",
+                   ia->ia_iobase, NTWOC_SRC_IOPORT_SIZE, tmp);
+               return (0);
+       }
+
+       ioport = ia->ia_iobase + 0x8000;
+       for (i = 0; i < 16; ioport += (0x10 << 6), i++) {
+               /* map the isa io addresses */
+               if ((tmp = bus_space_map(iot, ioport, 16, 0, &sca_ioh[i]))) {
+                       printf(
+                        "ntwoc_isa_probe: mapping sca 0x%x sz %d failed: %d\n",
+                           ioport, 16, tmp);
+                       goto out;
+               }
+               gotsca[i] = 1;
+       }
+
+       /* map the isa memory addresses */
+       /* XXX we really want the user to select this */
+       if ((tmp = bus_space_map(ia->ia_memt, ia->ia_maddr, NTWOC_WIN_SIZE, 0,
+           &memh))) {
+               printf("ntwoc_isa_probe: mapping mem 0x%x sz %d failed: %d\n",
+                   ia->ia_maddr, NTWOC_WIN_SIZE, tmp);
+               goto out;
+       }
+       gotmem = 1;
+
+       /* turn off the card */
+       bus_space_write_1(iot, ioh, NTWOC_PCR, 0);
+
+       /*
+        * Next, we'll test the Base Address Register to retension of
+        * data... ... seeing if we're *really* talking to an N2.
+        */
+       for (i = 0; i < 0x100; i++) {
+               bus_space_write_1(iot, ioh, NTWOC_BAR, i);
+               (void)bus_space_read_1(iot, ioh, NTWOC_PCR);
+               if (bus_space_read_1(iot, ioh, NTWOC_BAR) != i) {
+                       printf("ntwoc_isa_probe failed (BAR %x, %x)\n", i, tmp);
+                       goto out;
+               }
+       }
+
+       /* XXX XXX update the calls to SCA_REG to use our mapping */
+
+       /*
+        * Now see if we can see the SCA.
+        */
+       bus_space_write_1(iot, ioh, NTWOC_PCR,
+            NTWOC_PCR_SCARUN | bus_space_read_1(iot, ioh, NTWOC_PCR));
+       bus_space_write_1(iot, sca_ioh[0], SCA_REG(SCA_WCRL), 0);
+       bus_space_write_1(iot, sca_ioh[0], SCA_REG(SCA_WCRM), 0);
+       bus_space_write_1(iot, sca_ioh[0], SCA_REG(SCA_WCRH), 0);
+       bus_space_write_1(iot, sca_ioh[0], SCA_REG(SCA_PCR), 0);
+
+       bus_space_write_1(iot, sca_ioh[0], SCA_REG(SCA_TMC0), 0);
+       (void)bus_space_read_1(iot, ioh, 0);
+       if ((tmp = bus_space_read_1(iot, sca_ioh[0], SCA_REG(SCA_TMC0))) != 0) {
+               printf("ntwoc_isa_probe: Error reading SCA (TMC0 0, %x)\n",
+                  tmp);
+               goto out;
+       }
+
+       bus_space_write_1(iot, sca_ioh[0], SCA_REG(SCA_TMC0), 0x5A);
+       (void)bus_space_read_1(iot, ioh, 0);
+
+       tmp = bus_space_read_1(iot, sca_ioh[0], SCA_REG(SCA_TMC0));



Home | Main Index | Thread Index | Old Index