Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arc/dev Moved from /cvsroot/syssrc/sys/arch/pica/de...



details:   https://anonhg.NetBSD.org/src/rev/666f353b935b
branches:  trunk
changeset: 481082:666f353b935b
user:      soda <soda%NetBSD.org@localhost>
date:      Sun Jan 23 20:08:57 2000 +0000

description:
Moved from /cvsroot/syssrc/sys/arch/pica/dev/com.c,v

diffstat:

 sys/arch/arc/dev/com_lbus.c |  1037 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 1037 insertions(+), 0 deletions(-)

diffs (truncated from 1041 to 300 lines):

diff -r e9c019fd85c1 -r 666f353b935b sys/arch/arc/dev/com_lbus.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arc/dev/com_lbus.c       Sun Jan 23 20:08:57 2000 +0000
@@ -0,0 +1,1037 @@
+/*     $NetBSD: com_lbus.c,v 1.8 2000/01/23 20:08:57 soda Exp $        */
+
+/*-
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum.
+ *
+ * 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 by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ *     @(#)com.c       7.5 (Berkeley) 5/16/91
+ */
+
+/*
+ * COM driver, based on HP dca driver
+ * uses National Semiconductor NS16450/NS16550AF UART
+ */
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/ioctl.h>
+#include <sys/select.h>
+#include <sys/tty.h>
+#include <sys/proc.h>
+#include <sys/user.h>
+#include <sys/conf.h>
+#include <sys/file.h>
+#include <sys/uio.h>
+#include <sys/kernel.h>
+#include <sys/syslog.h>
+#include <sys/types.h>
+#include <sys/device.h>
+
+#include <machine/cpu.h>
+#include <machine/autoconf.h>
+#include <machine/pio.h>
+#include <pica/pica/pica.h>
+
+#include <dev/isa/comreg.h>
+#include <dev/ic/ns16550reg.h>
+
+#define        COM_IBUFSIZE    (2 * 256)
+#define        COM_IHIGHWATER  ((3 * COM_IBUFSIZE) / 4)
+
+struct com_softc {
+       struct device sc_dev;
+       struct tty *sc_tty;
+
+       int sc_overflows;
+       int sc_floods;
+       int sc_errors;
+
+       long    sc_iobase;
+       u_char sc_hwflags;
+#define        COM_HW_NOIEN    0x01
+#define        COM_HW_FIFO     0x02
+#define        COM_HW_CONSOLE  0x40
+       u_char sc_swflags;
+#define        COM_SW_SOFTCAR  0x01
+#define        COM_SW_CLOCAL   0x02
+#define        COM_SW_CRTSCTS  0x04
+#define        COM_SW_MDMBUF   0x08
+       u_char sc_msr, sc_mcr;
+       u_char sc_dtr;
+
+       u_char *sc_ibuf, *sc_ibufp, *sc_ibufhigh, *sc_ibufend;
+       u_char sc_ibufs[2][COM_IBUFSIZE];
+};
+
+int commatch __P((struct device *, void *, void *));
+void comattach __P((struct device *, struct device *, void *));
+int comopen __P((dev_t, int, int, struct proc *));
+int comclose __P((dev_t, int, int, struct proc *));
+void comdiag __P((void *));
+int comintr __P((void *));
+void compoll __P((void *));
+int comparam __P((struct tty *, struct termios *));
+void comstart __P((struct tty *));
+
+struct cfattach pcom_ca = {
+       sizeof(struct com_softc), commatch, comattach
+};
+
+extern struct cfdriver pcom_cd;
+
+int    comdefaultrate = TTYDEF_SPEED;
+#ifdef COMCONSOLE
+int    comconsole = COMCONSOLE;
+#else
+int    comconsole = -1;
+#endif
+int    comconsinit;
+int    commajor;
+int    comsopen = 0;
+int    comevents = 0;
+
+#ifdef KGDB
+#include <machine/remote-sl.h>
+extern int kgdb_dev;
+extern int kgdb_rate;
+extern int kgdb_debug_init;
+#endif
+
+#define        COMUNIT(x)      (minor(x))
+
+#define        bis(c, b)       do { const register int com_ad = (c); \
+                            outb(com_ad, inb(com_ad) | (b)); } while(0)
+#define        bic(c, b)       do { const register int com_ad = (c); \
+                            outb(com_ad, inb(com_ad) & ~(b)); } while(0)
+
+int
+comspeed(speed)
+       long speed;
+{
+#define        divrnd(n, q)    (((n)*2/(q)+1)/2)       /* divide and round off */
+
+       int x, err;
+
+       if (speed == 0)
+               return 0;
+       if (speed < 0)
+               return -1;
+       x = divrnd((COM_FREQ / 16), speed);
+       if (x <= 0)
+               return -1;
+       err = divrnd((COM_FREQ / 16) * 1000, speed * x) - 1000;
+       if (err < 0)
+               err = -err;
+       if (err > COM_TOLERANCE)
+               return -1;
+       return x;
+
+#undef divrnd(n, q)
+}
+
+int
+commatch1(iobase)
+       long iobase;
+{
+
+       /* force access to id reg */
+       outb(iobase + com_cfcr, 0);
+       outb(iobase + com_iir, 0);
+       if (inb(iobase + com_iir) & 0x38)
+               return 0;
+
+       return 1;
+}
+
+int
+commatch(parent, cfdata, aux)
+       struct device *parent;
+       void *cfdata, *aux;
+{
+       struct confargs *ca = aux;
+       long iobase;
+
+       /* Make shure that we're looking for this type of device. */
+       if(!BUS_MATCHNAME(ca, "com"))
+               return(0);
+
+       iobase = (long)BUS_CVTADDR(ca);
+       if (!commatch1(iobase))
+               return (0);
+
+       return (1);
+}
+
+void
+comattach(parent, self, aux)
+       struct device *parent, *self;
+       void *aux;
+{
+       struct com_softc *sc = (void *)self;
+       struct confargs *ca = aux;
+       struct cfdata *cf = sc->sc_dev.dv_cfdata;
+       long iobase;
+       struct tty *tp;
+
+       sc->sc_iobase = iobase = (long)BUS_CVTADDR(ca);
+       sc->sc_hwflags = cf->cf_flags & COM_HW_NOIEN;
+       sc->sc_swflags = 0;
+
+       if (sc->sc_dev.dv_unit == comconsole)
+               delay(1000);
+
+       /* look for a NS 16550AF UART with FIFOs */
+       outb(iobase + com_fifo,
+           FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_14);
+       delay(100);
+       if ((inb(iobase + com_iir) & IIR_FIFO_MASK) == IIR_FIFO_MASK)
+               if ((inb(iobase + com_fifo) & FIFO_TRIGGER_14) == FIFO_TRIGGER_14) {
+                       sc->sc_hwflags |= COM_HW_FIFO;
+                       printf(": ns16550a, working fifo\n");
+               } else
+                       printf(": ns16550, broken fifo\n");
+       else
+               printf(": ns8250 or ns16450, no fifo\n");
+       outb(iobase + com_fifo, 0);
+
+       /* disable interrupts */
+       outb(iobase + com_ier, 0);
+       outb(iobase + com_mcr, 0);
+
+       BUS_INTR_ESTABLISH(ca, comintr, (void *)(long)sc);
+
+#ifdef KGDB
+       if (kgdb_dev == makedev(commajor, unit)) {
+               if (comconsole == unit)
+                       kgdb_dev = -1;  /* can't debug over console port */
+               else {
+                       (void) cominit(unit, kgdb_rate);
+                       if (kgdb_debug_init) {
+                               /*
+                                * Print prefix of device name,
+                                * let kgdb_connect print the rest.
+                                */
+                               printf("%s: ", sc->sc_dev.dv_xname);
+                               kgdb_connect(1);
+                       } else
+                               printf("%s: kgdb enabled\n",
+                                   sc->sc_dev.dv_xname);
+               }
+       }
+#endif
+
+       if (sc->sc_dev.dv_unit == comconsole) {
+               /*
+                * Need to reset baud rate, etc. of next print so reset
+                * comconsinit.  Also make sure console is always "hardwired".
+                */
+               comconsinit = 0;
+               sc->sc_hwflags |= COM_HW_CONSOLE;
+               sc->sc_swflags |= COM_SW_SOFTCAR;
+       }
+}
+



Home | Main Index | Thread Index | Old Index