Home | History | Annotate | Line # | Download | only in ofisa
      1 /*	$NetBSD: lpt_ofisa.c,v 1.19 2021/01/27 03:10:21 thorpej 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 'lpt' parallel port driver
     38  */
     39 
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: lpt_ofisa.c,v 1.19 2021/01/27 03:10:21 thorpej 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 <sys/intr.h>
     49 #include <sys/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/lptreg.h>
     56 #include <dev/ic/lptvar.h>
     57 
     58 struct lpt_ofisa_softc {
     59 	struct	lpt_softc sc_lpt;	/* real "lpt" softc */
     60 
     61 	/* OFW ISA-specific goo. */
     62 	void	*sc_ih;			/* interrupt handler */
     63 };
     64 
     65 int lpt_ofisa_probe(device_t, cfdata_t , void *);
     66 void lpt_ofisa_attach(device_t, device_t, void *);
     67 
     68 CFATTACH_DECL_NEW(lpt_ofisa, sizeof(struct lpt_ofisa_softc),
     69     lpt_ofisa_probe, lpt_ofisa_attach, NULL, NULL);
     70 
     71 static const struct device_compatible_entry compat_data[] = {
     72 	{ .compat = "pnpPNP,401" },
     73 	DEVICE_COMPAT_EOL
     74 };
     75 
     76 int
     77 lpt_ofisa_probe(device_t parent, cfdata_t cf, void *aux)
     78 {
     79 	struct ofisa_attach_args *aa = aux;
     80 	int rv;
     81 
     82 	rv = of_compatible_match(aa->oba.oba_phandle, compat_data) ? 5 : 0;
     83 #ifdef _LPT_OFISA_MD_MATCH
     84 	if (!rv)
     85 		rv = lpt_ofisa_md_match(parent, cf, aux);
     86 #endif
     87 	return (rv);
     88 }
     89 
     90 void
     91 lpt_ofisa_attach(device_t parent, device_t self, void *aux)
     92 {
     93 	struct lpt_ofisa_softc *osc = device_private(self);
     94         struct lpt_softc *sc = &osc->sc_lpt;
     95 	struct ofisa_attach_args *aa = aux;
     96 	struct ofisa_reg_desc reg;
     97 	struct ofisa_intr_desc intr;
     98 	int n;
     99 
    100 	/*
    101 	 * We're living on an ofw.  We have to ask the OFW what our
    102 	 * registers and interrupts properties look like.
    103 	 *
    104 	 * We expect exactly one register region and one interrupt.
    105 	 */
    106 
    107 	sc->sc_dev = self;
    108 
    109 	n = ofisa_reg_get(aa->oba.oba_phandle, &reg, 1);
    110 #ifdef _LPT_OFISA_MD_REG_FIXUP
    111 	n = lpt_ofisa_md_reg_fixup(parent, self, aux, &reg, 1, n);
    112 #endif
    113 	if (n != 1) {
    114 		aprint_error(": error getting register data\n");
    115 		return;
    116 	}
    117 	if (reg.len != 4 && reg.len != 8) {
    118 		aprint_error(": weird register size (%lu, expected 4 or 8)\n",
    119 		    (unsigned long)reg.len);
    120 		return;
    121 	}
    122 
    123 	n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
    124 #ifdef _LPT_OFISA_MD_INTR_FIXUP
    125 	n = lpt_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
    126 #endif
    127 	if (n != 1) {
    128 		aprint_error(": error getting interrupt data\n");
    129 		return;
    130 	}
    131 
    132 	sc->sc_iot = (reg.type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
    133 	if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0, &sc->sc_ioh)) {
    134 		aprint_error(": can't map register space\n");
    135                 return;
    136         }
    137 
    138 	osc->sc_ih = isa_intr_establish(aa->ic, intr.irq, intr.share,
    139 	    IPL_TTY, lptintr, sc);
    140 
    141 	aprint_normal("\n");
    142 
    143 	lpt_attach_subr(sc);
    144 
    145 #if 0
    146 	printf("%s: registers: ", device_xname(sc->sc_dev));
    147 	ofisa_reg_print(&reg, 1);
    148 	printf("\n");
    149 	printf("%s: interrupts: ", device_xname(sc->sc_dev));
    150 	ofisa_intr_print(&intr, 1);
    151 	printf("\n");
    152 #endif
    153 }
    154