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