Home | History | Annotate | Line # | Download | only in ofisa
com_ofisa.c revision 1.1
      1 /*	$NetBSD: com_ofisa.c,v 1.1 1998/02/07 00:46:45 cgd Exp $	*/
      2 
      3 /*
      4  * Copyright 1997, 1998
      5  * Digital Equipment Corporation. All rights reserved.
      6  *
      7  * This software is furnished under license and may be used and
      8  * copied only in accordance with the following terms and conditions.
      9  * Subject to these conditions, you may download, copy, install,
     10  * use, modify and distribute this software in source and/or binary
     11  * form. No title or ownership is transferred hereby.
     12  *
     13  * 1) Any source code used, modified or distributed must reproduce
     14  *    and retain this copyright notice and list of conditions as
     15  *    they appear in the source file.
     16  *
     17  * 2) No right is granted to use any trade name, trademark, or logo of
     18  *    Digital Equipment Corporation. Neither the "Digital Equipment
     19  *    Corporation" name nor any trademark or logo of Digital Equipment
     20  *    Corporation may be used to endorse or promote products derived
     21  *    from this software without the prior written permission of
     22  *    Digital Equipment Corporation.
     23  *
     24  * 3) This software is provided "AS-IS" and any express or implied
     25  *    warranties, including but not limited to, any implied warranties
     26  *    of merchantability, fitness for a particular purpose, or
     27  *    non-infringement are disclaimed. In no event shall DIGITAL be
     28  *    liable for any damages whatsoever, and in particular, DIGITAL
     29  *    shall not be liable for special, indirect, consequential, or
     30  *    incidental damages or damages for lost profits, loss of
     31  *    revenue or loss of use, whether such damages arise in contract,
     32  *    negligence, tort, under statute, in equity, at law or otherwise,
     33  *    even if advised of the possibility of such damage.
     34  */
     35 
     36 /*
     37  * OFW Attachment for 'com' serial driver
     38  */
     39 
     40 #include <sys/param.h>
     41 #include <sys/device.h>
     42 #include <sys/socket.h>
     43 #include <sys/tty.h>
     44 
     45 #include <machine/intr.h>
     46 #include <machine/bus.h>
     47 
     48 #include <dev/ofw/openfirm.h>
     49 #include <dev/isa/isavar.h>
     50 #include <dev/ofisa/ofisavar.h>
     51 
     52 #include <dev/ic/comreg.h>
     53 #include <dev/ic/comvar.h>
     54 
     55 struct com_ofisa_softc {
     56 	struct	com_softc sc_com;	/* real "com" softc */
     57 
     58 	/* OFW ISA-specific goo. */
     59 	void	*sc_ih;			/* interrupt handler */
     60 };
     61 
     62 int com_ofisa_probe __P((struct device *, struct cfdata *, void *));
     63 void com_ofisa_attach __P((struct device *, struct device *, void *));
     64 
     65 struct cfattach com_ofisa_ca = {
     66 	sizeof(struct com_ofisa_softc), com_ofisa_probe, com_ofisa_attach
     67 };
     68 
     69 int
     70 com_ofisa_probe(parent, cf, aux)
     71 	struct device *parent;
     72 	struct cfdata *cf;
     73 	void *aux;
     74 {
     75 	struct ofisa_attach_args *aa = aux;
     76 	const char *compatible_strings[] = { "pnpPNP,501", NULL };
     77 	int rv = 0;
     78 
     79 	if (of_compatible(aa->ofp.phandle, compatible_strings) != -1)
     80 		rv = 5;
     81 #ifdef _COM_OFISA_MD_MATCH
     82 	if (!rv)
     83 		rv = com_ofisa_md_match(parent, cf, aux);
     84 #endif
     85 	return (rv);
     86 }
     87 
     88 void
     89 com_ofisa_attach(parent, self, aux)
     90 	struct device *parent, *self;
     91 	void *aux;
     92 {
     93 	struct com_ofisa_softc *osc = (void *)self;
     94         struct com_softc *sc = &osc->sc_com;
     95 	struct ofisa_attach_args *aa = aux;
     96 	struct ofisa_reg_desc reg;
     97 	struct ofisa_intr_desc intr;
     98 	int freq;
     99 	char freqbuf[4];
    100 	int n;
    101 
    102 	/*
    103 	 * We're living on an ofw.  We have to ask the OFW what our
    104 	 * registers and interrupts properties look like.
    105 	 *
    106 	 * We expect exactly one register region and one interrupt.
    107 	 */
    108 
    109 	n = ofisa_reg_get(aa->ofp.phandle, &reg, 1);
    110 #ifdef _COM_OFISA_MD_REG_FIXUP
    111 	n = com_ofisa_md_reg_fixup(parent, self, aux, &reg, 1, n);
    112 #endif
    113 	if (n != 1) {
    114 		printf(": error getting register data\n");
    115 		return;
    116 	}
    117 	if (reg.len != 8) {
    118 		printf(": weird register size (%d, expected 8)\n", reg.len);
    119 		return;
    120 	}
    121 
    122 	n = ofisa_intr_get(aa->ofp.phandle, &intr, 1);
    123 #ifdef _COM_OFISA_MD_INTR_FIXUP
    124 	n = com_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
    125 #endif
    126 	if (n != 1) {
    127 		printf(": error getting interrupt data\n");
    128 		return;
    129 	}
    130 
    131 	if (OF_getproplen(aa->ofp.phandle, "clock-frequency") != 4 ||
    132 	    OF_getprop(aa->ofp.phandle, "clock-frequency", freqbuf,
    133 	      sizeof freqbuf) != 4)
    134 		freq = COM_FREQ;
    135 	else
    136 		freq = of_decode_int(&freqbuf[0]);
    137 
    138 	sc->sc_iot = (reg.type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
    139 	sc->sc_iobase = reg.addr;
    140 	sc->sc_frequency = freq;
    141 
    142 	if (!com_is_console(sc->sc_iot, sc->sc_iobase, &sc->sc_ioh) &&
    143 	    bus_space_map(sc->sc_iot, sc->sc_iobase, reg.len, 0,
    144 	      &sc->sc_ioh)) {
    145 		printf(": can't map register space\n");
    146                 return;
    147         }
    148 
    149 	osc->sc_ih = isa_intr_establish(aa->ic, intr.irq, intr.share,
    150 	    IPL_SERIAL, comintr, sc);
    151 
    152 	com_attach_subr(sc);
    153 
    154 #if 0
    155 	printf("%s: registers: ", sc->sc_dev.dv_xname);
    156 	ofisa_reg_print(&reg, 1);
    157 	printf("\n");
    158 	printf("%s: interrupts: ", sc->sc_dev.dv_xname);
    159 	ofisa_intr_print(&intr, 1);
    160 	printf("\n");
    161 #endif
    162 }
    163