Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc64/dev Port Jason L. Wright's sab82532 driver....



details:   https://anonhg.NetBSD.org/src/rev/b11f8bed3af9
branches:  trunk
changeset: 535352:b11f8bed3af9
user:      petrov <petrov%NetBSD.org@localhost>
date:      Fri Aug 16 08:47:13 2002 +0000

description:
Port Jason L. Wright's sab82532 driver. From OpenBSD.

diffstat:

 sys/arch/sparc64/dev/sab.c         |  1350 ++++++++++++++++++++++++++++++++++++
 sys/arch/sparc64/dev/sab82532reg.h |   320 ++++++++
 2 files changed, 1670 insertions(+), 0 deletions(-)

diffs (truncated from 1678 to 300 lines):

diff -r 8d850384ad38 -r b11f8bed3af9 sys/arch/sparc64/dev/sab.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sparc64/dev/sab.c        Fri Aug 16 08:47:13 2002 +0000
@@ -0,0 +1,1350 @@
+/*     $NetBSD: sab.c,v 1.1 2002/08/16 08:47:13 petrov Exp $   */
+/*     $OpenBSD: sab.c,v 1.7 2002/04/08 17:49:42 jason Exp $   */
+
+/*
+ * Copyright (c) 2001 Jason L. Wright (jason%thought.net@localhost)
+ * 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 Jason L. Wright
+ * 4. 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.
+ *
+ * Effort sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F30602-01-2-0537.
+ *
+ */
+
+/*
+ * SAB82532 Dual UART driver
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/conf.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/tty.h>
+#include <sys/syslog.h>
+
+#include <machine/autoconf.h>
+#include <machine/openfirm.h>
+#include <machine/conf.h>
+
+#include <dev/cons.h>
+
+#include <dev/ebus/ebusreg.h>
+#include <dev/ebus/ebusvar.h>
+#include <sparc64/dev/sab82532reg.h>
+
+#define SABUNIT(x)             (minor(x) & 0x7ffff)
+#define SABDIALOUT(x)          (minor(x) & 0x80000)
+
+#define        SABTTY_RBUF_SIZE        1024    /* must be divisible by 2 */
+
+struct sab_softc {
+       struct device           sc_dv;
+       struct intrhand *       sc_ih;
+       bus_space_tag_t         sc_bt;
+       bus_space_handle_t      sc_bh;
+       struct sabtty_softc *   sc_child[SAB_NCHAN];
+       u_int                   sc_nchild;
+       void *                  sc_softintr;
+       int                     sc_node;
+};
+
+struct sabtty_attach_args {
+       u_int sbt_portno;
+};
+
+struct sabtty_softc {
+       struct device           sc_dv;
+       struct sab_softc *      sc_parent;
+       bus_space_tag_t         sc_bt;
+       bus_space_handle_t      sc_bh;
+       struct tty *            sc_tty;
+       u_int                   sc_portno;
+       u_int8_t                sc_pvr_dtr, sc_pvr_dsr;
+       u_int8_t                sc_imr0, sc_imr1;
+       int                     sc_openflags;
+       u_char *                sc_txp;
+       int                     sc_txc;
+       int                     sc_flags;
+#define SABTTYF_STOP           0x01
+#define        SABTTYF_DONE            0x02
+#define        SABTTYF_RINGOVERFLOW    0x04
+#define        SABTTYF_CDCHG           0x08
+#define        SABTTYF_CONS_IN         0x10
+#define        SABTTYF_CONS_OUT        0x20
+#define        SABTTYF_TXDRAIN         0x40
+#define        SABTTYF_DONTDDB         0x80
+       u_int8_t                sc_rbuf[SABTTY_RBUF_SIZE];
+       u_int8_t                *sc_rend, *sc_rput, *sc_rget;
+       u_int8_t                sc_polling, sc_pollrfc;
+};
+
+struct sabtty_softc *sabtty_cons_input;
+struct sabtty_softc *sabtty_cons_output;
+
+#define        SAB_READ(sc,r)          \
+    bus_space_read_1((sc)->sc_bt, (sc)->sc_bh, (r))
+#define        SAB_WRITE(sc,r,v)       \
+    bus_space_write_1((sc)->sc_bt, (sc)->sc_bh, (r), (v))
+
+int sab_match(struct device *, struct cfdata *, void *);
+void sab_attach(struct device *, struct device *, void *);
+int sab_print(void *, const char *);
+int sab_intr(void *);
+
+void sab_softintr(void *);
+void sab_cnputc(dev_t, int);
+int sab_cngetc(dev_t);
+void sab_cnpollc(dev_t, int);
+
+int sabtty_match(struct device *, struct cfdata *, void *);
+void sabtty_attach(struct device *, struct device *, void *);
+void sabtty_start(struct tty *);
+int sabtty_param(struct tty *, struct termios *);
+int sabtty_intr(struct sabtty_softc *, int *);
+void sabtty_softintr(struct sabtty_softc *);
+int sabtty_mdmctrl(struct sabtty_softc *, int, int);
+void sabtty_cec_wait(struct sabtty_softc *);
+void sabtty_tec_wait(struct sabtty_softc *);
+void sabtty_reset(struct sabtty_softc *);
+void sabtty_flush(struct sabtty_softc *);
+int sabtty_speed(int);
+void sabtty_console_flags(struct sabtty_softc *);
+void sabtty_cnpollc(struct sabtty_softc *, int);
+void sabtty_shutdown(void *);
+int sabttyparam(struct sabtty_softc *, struct tty *, struct termios *);
+
+int sabopen(dev_t, int, int, struct proc *);
+int sabclose(dev_t, int, int, struct proc *);
+int sabread(dev_t, struct uio *, int);
+int sabwrite(dev_t, struct uio *, int);
+int sabioctl(dev_t, u_long, caddr_t, int, struct proc *);
+void sabstop(struct tty *, int);
+struct tty *sabtty(dev_t);
+void sabtty_cnputc(struct sabtty_softc *, int);
+int sabtty_cngetc(struct sabtty_softc *);
+void sabtty_abort(struct sabtty_softc *);
+
+struct cfattach sab_ca = {
+       sizeof(struct sab_softc), sab_match, sab_attach
+};
+
+extern struct cfdriver sab_cd;
+
+
+struct cfattach sabtty_ca = {
+       sizeof(struct sabtty_softc), sabtty_match, sabtty_attach
+};
+
+extern struct cfdriver sabtty_cd;
+
+struct sabtty_rate {
+       int baud;
+       int n, m;
+};
+
+struct sabtty_rate sabtty_baudtable[] = {
+       {      50,      35,     10 },
+       {      75,      47,     9 },
+       {     110,      32,     9 },
+       {     134,      53,     8 },
+       {     150,      47,     8 },
+       {     200,      35,     8 },
+       {     300,      47,     7 },
+       {     600,      47,     6 },
+       {    1200,      47,     5 },
+       {    1800,      31,     5 },
+       {    2400,      47,     4 },
+       {    4800,      47,     3 },
+       {    9600,      47,     2 },
+       {   19200,      47,     1 },
+       {   38400,      23,     1 },
+       {   57600,      15,     1 },
+       {  115200,       7,     1 },
+       {  230400,       3,     1 },
+       {  460800,       1,     1 },
+       {   76800,      11,     1 },
+       {  153600,       5,     1 },
+       {  307200,       3,     1 },
+       {  614400,       3,     0 },
+       {  921600,       0,     1 },
+};
+
+int
+sab_match(parent, match, aux)
+       struct device *parent;
+       struct cfdata *match;
+       void *aux;
+{
+       struct ebus_attach_args *ea = aux;
+       char *compat;
+
+       if (strcmp(ea->ea_name, "se") == 0)
+               return (1);
+
+       compat = PROM_getpropstring(ea->ea_node, "compatible");
+       if (compat != NULL && !strcmp(compat, "sab82532"))
+               return (1);
+
+       return (0);
+}
+
+void
+sab_attach(parent, self, aux)
+       struct device *parent;
+       struct device *self;
+       void *aux;
+{
+       struct sab_softc *sc = (struct sab_softc *)self;
+       struct ebus_attach_args *ea = aux;
+       u_int8_t r;
+       u_int i;
+
+       sc->sc_bt = ea->ea_bustag;
+       sc->sc_node = ea->ea_node;
+
+       /* Use prom mapping, if available. */
+       if (ea->ea_nvaddr)
+               sparc_promaddr_to_handle(sc->sc_bt, ea->ea_vaddr[0], &sc->sc_bh);
+       else if (bus_space_map(sc->sc_bt, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
+                                ea->ea_reg[0].size, 0, &sc->sc_bh) != 0) {
+               printf(": can't map register space\n");
+               return;
+       }
+
+       sc->sc_ih = bus_intr_establish(ea->ea_bustag, ea->ea_intr[0],
+           IPL_TTY, 0, sab_intr, sc);
+       if (sc->sc_ih == NULL) {
+               printf(": can't map interrupt\n");
+               return;
+       }
+
+       sc->sc_softintr = softintr_establish(IPL_TTY, sab_softintr, sc);
+       if (sc->sc_softintr == NULL) {
+               printf(": can't get soft intr\n");
+               return;
+       }
+
+       printf(": rev ");
+       r = SAB_READ(sc, SAB_VSTR) & SAB_VSTR_VMASK;
+       switch (r) {
+       case SAB_VSTR_V_1:
+               printf("1");
+               break;
+       case SAB_VSTR_V_2:
+               printf("2");
+               break;
+       case SAB_VSTR_V_32:
+               printf("3.2");
+               break;
+       default:
+               printf("unknown(0x%x)", r);
+               break;
+       }
+       printf("\n");
+
+       /* Set all pins, except DTR pins to be inputs */
+       SAB_WRITE(sc, SAB_PCR, ~(SAB_PVR_DTR_A | SAB_PVR_DTR_B));
+       /* Disable port interrupts */
+       SAB_WRITE(sc, SAB_PIM, 0xff);
+       SAB_WRITE(sc, SAB_PVR, SAB_PVR_DTR_A | SAB_PVR_DTR_B | SAB_PVR_MAGIC);
+       SAB_WRITE(sc, SAB_IPC, SAB_IPC_ICPL);
+
+       for (i = 0; i < SAB_NCHAN; i++) {
+               struct sabtty_attach_args sta;
+
+               sta.sbt_portno = i;
+               sc->sc_child[i] = (struct sabtty_softc *)config_found_sm(self,
+                   &sta, sab_print, sabtty_match);
+               if (sc->sc_child[i] != NULL)
+                       sc->sc_nchild++;
+       }
+}
+
+int
+sab_print(args, name)
+       void *args;



Home | Main Index | Thread Index | Old Index