Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys add a backend serial driver for the cirrus logic CL-CD18...
details: https://anonhg.NetBSD.org/src/rev/e4347014a4d4
branches: trunk
changeset: 515709:e4347014a4d4
user: mrg <mrg%NetBSD.org@localhost>
date: Wed Oct 03 04:25:29 2001 +0000
description:
add a backend serial driver for the cirrus logic CL-CD180/1864/1865
8 port chip. this is used in several sbus (sparc) serial boards, as
well as an 8 port isa card from riscom. sio16 (sbus) frontend coming
shortly.
this is heavily based on the com and zs drivers.
diffstat:
sys/conf/files | 6 +-
sys/dev/ic/cd18xx.c | 1572 ++++++++++++++++++++++++++++++++++++++++++++++++
sys/dev/ic/cd18xxreg.h | 298 +++++++++
sys/dev/ic/cd18xxvar.h | 180 +++++
4 files changed, 2055 insertions(+), 1 deletions(-)
diffs (truncated from 2082 to 300 lines):
diff -r 131d2c0cd76a -r e4347014a4d4 sys/conf/files
--- a/sys/conf/files Wed Oct 03 00:12:17 2001 +0000
+++ b/sys/conf/files Wed Oct 03 04:25:29 2001 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.464 2001/09/28 02:06:17 thorpej Exp $
+# $NetBSD: files,v 1.465 2001/10/03 04:25:29 mrg Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@@ -519,6 +519,10 @@
define lsi64854
file dev/ic/lsi64854.c lsi64854
+# Cirrus Logic CL-CD180/1864/1865 multi port serial controller back-end
+define cd18xx
+file dev/ic/cd18xx.c cd18xx
+
# RealTek 8019/8029 NE2000-compatible network interface subroutines
define rtl80x9
file dev/ic/rtl80x9.c rtl80x9
diff -r 131d2c0cd76a -r e4347014a4d4 sys/dev/ic/cd18xx.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/cd18xx.c Wed Oct 03 04:25:29 2001 +0000
@@ -0,0 +1,1572 @@
+/* $NetBSD: cd18xx.c,v 1.1 2001/10/03 04:25:30 mrg Exp $ */
+
+/*
+ * Copyright (c) 1998, 2001 Matthew R. Green
+ * 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. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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) 1998, 1999 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
+ */
+
+/*
+ * cirrus logic CL-CD180/CD1864/CD1865 driver, based in (large) parts on
+ * the com and z8530 drivers. thanks charles.
+ */
+
+#include <sys/param.h>
+#include <sys/conf.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/proc.h>
+#include <sys/kernel.h>
+#include <sys/tty.h>
+#include <sys/fcntl.h>
+
+#include <machine/bus.h>
+
+#include <dev/ic/cd18xxvar.h>
+#include <dev/ic/cd18xxreg.h>
+
+#include "ioconf.h"
+
+/*
+ * some helpers
+ */
+
+/* macros to clear/set/test flags. */
+#define SET(t, f) (t) |= (f)
+#define CLR(t, f) (t) &= ~(f)
+#define ISSET(t, f) ((t) & (f))
+
+static void cdtty_attach(struct cd18xx_softc *, int);
+
+static __inline void cd18xx_rint(struct cd18xx_softc *, int *);
+static __inline void cd18xx_tint(struct cd18xx_softc *, int *);
+static __inline void cd18xx_mint(struct cd18xx_softc *, int *);
+
+void cdtty_rxsoft(struct cd18xx_softc *, struct cdtty_port *, struct tty *);
+void cdtty_txsoft(struct cd18xx_softc *, struct cdtty_port *, struct tty *);
+void cdtty_stsoft(struct cd18xx_softc *, struct cdtty_port *, struct tty *);
+void cd18xx_softintr(void *);
+
+cdev_decl(cdtty);
+
+static void cdtty_shutdown(struct cd18xx_softc *, struct cdtty_port*);
+static void cdttystart(struct tty *);
+static int cdttyparam(struct tty *, struct termios *);
+static void cdtty_break(struct cd18xx_softc *, struct cdtty_port *, int);
+static void cdtty_modem(struct cd18xx_softc *, struct cdtty_port *, int);
+static int cdttyhwiflow(struct tty *, int);
+static void cdtty_hwiflow(struct cd18xx_softc *, struct cdtty_port *);
+
+static void cdtty_loadchannelregs(struct cd18xx_softc *,
+ struct cdtty_port *);
+
+/* default read buffer size */
+u_int cdtty_rbuf_size = CDTTY_RING_SIZE;
+
+/* Stop input when 3/4 of the ring is full; restart when only 1/4 is full. */
+u_int cdtty_rbuf_hiwat = (CDTTY_RING_SIZE * 1) / 4;
+u_int cdtty_rbuf_lowat = (CDTTY_RING_SIZE * 3) / 4;
+
+#define CD18XXDEBUG
+#ifdef CD18XXDEBUG
+#define CDD_INFO 0x0001
+#define CDD_INTR 0x0002
+int cd18xx_debug = CDD_INTR|CDD_INFO;
+# define DPRINTF(l, x) if (cd18xx_debug & l) printf x
+#else
+# define DPRINTF(l, x) /* nothing */
+#endif
+
+/* Known supported revisions. */
+struct cd18xx_revs {
+ u_char revision;
+ u_char onehundred_pin;
+ char *name;
+} cd18xx_revs[] = {
+ { CD180_GFRCR_REV_B, 0, "CL-CD180 rev. B" },
+ { CD180_GFRCR_REV_C, 0, "CL-CD180 rev. C" },
+ { CD1864_GFRCR_REVISION_A, 1, "CL-CD1864 rev. A" },
+ { CD1865_GFRCR_REVISION_A, 1, "CL-CD1865 rev. A" },
+ { CD1865_GFRCR_REVISION_B, 1, "CL-CD1865 rev. B" },
+ { CD1865_GFRCR_REVISION_C, 1, "CL-CD1865 rev. C" },
+ { 0, 0, 0 }
+};
+
+/* wait for the CCR to go to zero */
+static __inline int cd18xx_wait_ccr(struct cd18xx_softc *);
+static __inline int
+cd18xx_wait_ccr(sc)
+ struct cd18xx_softc *sc;
+{
+ int i = 100000;
+
+ while (--i &&
+ bus_space_read_1(sc->sc_tag, sc->sc_handle, CD18xx_CCR) == 0)
+ break;
+ return (i == 0);
+}
+
+/*
+ * device attach routine, high-end portion
+ */
+void
+cd18xx_attach(sc)
+ struct cd18xx_softc *sc;
+{
+ static int chip_id_next = 1;
+ int onehundred_pin, revision, i, port;
+
+ /* read and print the revision */
+ revision = cd18xx_read(sc, CD18xx_GFRCR);
+ onehundred_pin = ISSET(cd18xx_read(sc, CD18xx_SRCR),CD18xx_SRCR_PKGTYP);
+ for (i = 0; cd18xx_revs[i].name; i++)
+ if (revision == cd18xx_revs[i].revision ||
+ onehundred_pin == cd18xx_revs[i].onehundred_pin) {
+ printf(": %s", cd18xx_revs[i].name);
+ break;
+ }
+
+ if (cd18xx_revs[i].name == NULL) {
+ printf("%s: unknown revision, bailing.\n", sc->sc_dev.dv_xname);
+ return;
+ }
+
+ /* prepare for reset */
+ cd18xx_set_car(sc, 0);
+ cd18xx_write(sc, CD18xx_GSVR, CD18xx_GSVR_CLEAR);
+
+ /* wait for CCR to go to zero */
+ if (cd18xx_wait_ccr(sc)) {
+ printf("cd18xx_attach: reset change command timed out\n");
+ return;
+ }
+
+ /* full reset of all channels */
+ cd18xx_write(sc, CD18xx_CCR,
+ CD18xx_CCR_RESET|CD18xx_CCR_RESET_HARD);
+
+ /* loop until the GSVR is ready */
+ i = 100000;
+ while (--i && cd18xx_read(sc, CD18xx_GSVR) == CD18xx_GSVR_READY)
+ ;
+ if (i == 0) {
+ printf("\n%s: did not reset!\n", sc->sc_dev.dv_xname);
+ return;
+ }
+
+ /* write the chip_id */
+ sc->sc_chip_id = chip_id_next++;
+#ifdef DIAGNOSTIC
+ if (sc->sc_chip_id > 31)
+ panic("more than 31 cd18xx's? help.");
+#endif
+ cd18xx_write(sc, CD18xx_GSVR, CD18xx_GSVR_SETID(sc));
+
+ /* rx/tx/modem service match vectors, initalised by higher level */
+ cd18xx_write(sc, CD18xx_MSMR, sc->sc_msmr | 0x80);
+ cd18xx_write(sc, CD18xx_TSMR, sc->sc_tsmr | 0x80);
+ cd18xx_write(sc, CD18xx_RSMR, sc->sc_rsmr | 0x80);
+
+ printf(", gsvr %x msmr %x tsmr %x rsmr %x",
+ cd18xx_read(sc, CD18xx_GSVR),
+ cd18xx_read(sc, CD18xx_MSMR),
+ cd18xx_read(sc, CD18xx_TSMR),
+ cd18xx_read(sc, CD18xx_RSMR));
+
+ /* prescale registers */
+ sc->sc_pprh = 0xf0;
+ sc->sc_pprl = 0;
+ cd18xx_write(sc, CD18xx_PPRH, sc->sc_pprh);
+ cd18xx_write(sc, CD18xx_PPRL, sc->sc_pprl);
+
+ /* establish our soft interrupt. */
Home |
Main Index |
Thread Index |
Old Index