Home | History | Annotate | Line # | Download | only in ofisa
com_ofisa.c revision 1.11
      1 /*	$NetBSD: com_ofisa.c,v 1.11 2006/07/13 22:56:02 gdamore 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/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: com_ofisa.c,v 1.11 2006/07/13 22:56:02 gdamore Exp $");
     42 
     43 #include <sys/param.h>
     44 #include <sys/device.h>
     45 #include <sys/systm.h>
     46 #include <sys/tty.h>
     47 
     48 #include <machine/intr.h>
     49 #include <machine/bus.h>
     50 
     51 #include <dev/ofw/openfirm.h>
     52 #include <dev/isa/isavar.h>
     53 #include <dev/ofisa/ofisavar.h>
     54 
     55 #include <dev/ic/comreg.h>
     56 #include <dev/ic/comvar.h>
     57 
     58 struct com_ofisa_softc {
     59 	struct	com_softc sc_com;	/* real "com" softc */
     60 
     61 	/* OFW ISA-specific goo. */
     62 	void	*sc_ih;			/* interrupt handler */
     63 };
     64 
     65 int com_ofisa_probe(struct device *, struct cfdata *, void *);
     66 void com_ofisa_attach(struct device *, struct device *, void *);
     67 
     68 CFATTACH_DECL(com_ofisa, sizeof(struct com_ofisa_softc),
     69     com_ofisa_probe, com_ofisa_attach, NULL, NULL);
     70 
     71 int
     72 com_ofisa_probe(parent, cf, aux)
     73 	struct device *parent;
     74 	struct cfdata *cf;
     75 	void *aux;
     76 {
     77 	struct ofisa_attach_args *aa = aux;
     78 	static const char *const compatible_strings[] = { "pnpPNP,501", NULL };
     79 	int rv = 0;
     80 
     81 	if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
     82 		rv = 5;
     83 #ifdef _COM_OFISA_MD_MATCH
     84 	if (!rv)
     85 		rv = com_ofisa_md_match(parent, cf, aux);
     86 #endif
     87 	return (rv);
     88 }
     89 
     90 void
     91 com_ofisa_attach(parent, self, aux)
     92 	struct device *parent, *self;
     93 	void *aux;
     94 {
     95 	struct com_ofisa_softc *osc = device_private(self);
     96         struct com_softc *sc = &osc->sc_com;
     97 	struct ofisa_attach_args *aa = aux;
     98 	struct ofisa_reg_desc reg;
     99 	struct ofisa_intr_desc intr;
    100 	bus_space_handle_t ioh;
    101 	bus_space_tag_t iot;
    102 	bus_addr_t iobase;
    103 	int freq;
    104 	char freqbuf[4];
    105 	int n;
    106 
    107 	/*
    108 	 * We're living on an ofw.  We have to ask the OFW what our
    109 	 * registers and interrupts properties look like.
    110 	 *
    111 	 * We expect exactly one register region and one interrupt.
    112 	 */
    113 
    114 	n = ofisa_reg_get(aa->oba.oba_phandle, &reg, 1);
    115 #ifdef _COM_OFISA_MD_REG_FIXUP
    116 	n = com_ofisa_md_reg_fixup(parent, self, aux, &reg, 1, n);
    117 #endif
    118 	if (n != 1) {
    119 		printf(": error getting register data\n");
    120 		return;
    121 	}
    122 	if (reg.len != 8) {
    123 		printf(": weird register size (%lu, expected 8)\n",
    124 		    (unsigned long)reg.len);
    125 		return;
    126 	}
    127 
    128 	n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
    129 #ifdef _COM_OFISA_MD_INTR_FIXUP
    130 	n = com_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
    131 #endif
    132 	if (n != 1) {
    133 		printf(": error getting interrupt data\n");
    134 		return;
    135 	}
    136 
    137 	if (OF_getproplen(aa->oba.oba_phandle, "clock-frequency") != 4 ||
    138 	    OF_getprop(aa->oba.oba_phandle, "clock-frequency", freqbuf,
    139 	      sizeof freqbuf) != 4)
    140 		freq = COM_FREQ;
    141 	else
    142 		freq = of_decode_int(&freqbuf[0]);
    143 
    144 	iot = (reg.type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
    145 	iobase = reg.addr;
    146 	sc->sc_frequency = freq;
    147 
    148 	if (!com_is_console(iot, iobase, &ioh) &&
    149 	    bus_space_map(iot, iobase, reg.len, 0, &ioh)) {
    150 		printf(": can't map register space\n");
    151                 return;
    152         }
    153 	COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
    154 
    155 	osc->sc_ih = isa_intr_establish(aa->ic, intr.irq, intr.share,
    156 	    IPL_SERIAL, comintr, sc);
    157 
    158 	com_attach_subr(sc);
    159 
    160 #if 0
    161 	printf("%s: registers: ", sc->sc_dev.dv_xname);
    162 	ofisa_reg_print(&reg, 1);
    163 	printf("\n");
    164 	printf("%s: interrupts: ", sc->sc_dev.dv_xname);
    165 	ofisa_intr_print(&intr, 1);
    166 	printf("\n");
    167 #endif
    168 }
    169