1256655Sjkim/* $NetBSD: lpt_ofisa.c,v 1.19 2021/01/27 03:10:21 thorpej Exp $ */ 2256655Sjkim 3256655Sjkim/* 4256655Sjkim * Copyright 1997, 1998 5256655Sjkim * Digital Equipment Corporation. All rights reserved. 6256655Sjkim * 7256655Sjkim * This software is furnished under license and may be used and 8281075Sdim * copied only in accordance with the following terms and conditions. 9256655Sjkim * Subject to these conditions, you may download, copy, install, 10256655Sjkim * use, modify and distribute this software in source and/or binary 11256655Sjkim * form. No title or ownership is transferred hereby. 12256655Sjkim * 13256655Sjkim * 1) Any source code used, modified or distributed must reproduce 14256655Sjkim * and retain this copyright notice and list of conditions as 15256655Sjkim * they appear in the source file. 16256655Sjkim * 17256655Sjkim * 2) No right is granted to use any trade name, trademark, or logo of 18256655Sjkim * Digital Equipment Corporation. Neither the "Digital Equipment 19256655Sjkim * Corporation" name nor any trademark or logo of Digital Equipment 20256655Sjkim * Corporation may be used to endorse or promote products derived 21256655Sjkim * from this software without the prior written permission of 22256655Sjkim * Digital Equipment Corporation. 23256655Sjkim * 24256655Sjkim * 3) This software is provided "AS-IS" and any express or implied 25256655Sjkim * warranties, including but not limited to, any implied warranties 26256655Sjkim * of merchantability, fitness for a particular purpose, or 27256655Sjkim * non-infringement are disclaimed. In no event shall DIGITAL be 28256655Sjkim * liable for any damages whatsoever, and in particular, DIGITAL 29256655Sjkim * shall not be liable for special, indirect, consequential, or 30256655Sjkim * incidental damages or damages for lost profits, loss of 31256655Sjkim * revenue or loss of use, whether such damages arise in contract, 32256655Sjkim * negligence, tort, under statute, in equity, at law or otherwise, 33256655Sjkim * even if advised of the possibility of such damage. 34256655Sjkim */ 35256655Sjkim 36256655Sjkim/* 37256655Sjkim * OFW Attachment for 'lpt' parallel port driver 38256655Sjkim */ 39256655Sjkim 40256655Sjkim#include <sys/cdefs.h> 41256655Sjkim__KERNEL_RCSID(0, "$NetBSD: lpt_ofisa.c,v 1.19 2021/01/27 03:10:21 thorpej Exp $"); 42256655Sjkim 43256655Sjkim#include <sys/param.h> 44272444Sjkim#include <sys/device.h> 45272444Sjkim#include <sys/systm.h> 46272444Sjkim#include <sys/tty.h> 47272444Sjkim 48272444Sjkim#include <sys/intr.h> 49256655Sjkim#include <sys/bus.h> 50256655Sjkim 51256655Sjkim#include <dev/ofw/openfirm.h> 52256655Sjkim#include <dev/isa/isavar.h> 53256655Sjkim#include <dev/ofisa/ofisavar.h> 54256655Sjkim 55256655Sjkim#include <dev/ic/lptreg.h> 56256655Sjkim#include <dev/ic/lptvar.h> 57256655Sjkim 58256655Sjkimstruct lpt_ofisa_softc { 59256655Sjkim struct lpt_softc sc_lpt; /* real "lpt" softc */ 60256655Sjkim 61256655Sjkim /* OFW ISA-specific goo. */ 62256655Sjkim void *sc_ih; /* interrupt handler */ 63256655Sjkim}; 64256655Sjkim 65256655Sjkimint lpt_ofisa_probe(device_t, cfdata_t , void *); 66256655Sjkimvoid lpt_ofisa_attach(device_t, device_t, void *); 67256655Sjkim 68256655SjkimCFATTACH_DECL_NEW(lpt_ofisa, sizeof(struct lpt_ofisa_softc), 69256655Sjkim lpt_ofisa_probe, lpt_ofisa_attach, NULL, NULL); 70256655Sjkim 71256655Sjkimstatic const struct device_compatible_entry compat_data[] = { 72256655Sjkim { .compat = "pnpPNP,401" }, 73256655Sjkim DEVICE_COMPAT_EOL 74256655Sjkim}; 75256655Sjkim 76256655Sjkimint 77256655Sjkimlpt_ofisa_probe(device_t parent, cfdata_t cf, void *aux) 78256655Sjkim{ 79256655Sjkim struct ofisa_attach_args *aa = aux; 80256655Sjkim int rv; 81256655Sjkim 82256655Sjkim rv = of_compatible_match(aa->oba.oba_phandle, compat_data) ? 5 : 0; 83256655Sjkim#ifdef _LPT_OFISA_MD_MATCH 84256655Sjkim if (!rv) 85256655Sjkim rv = lpt_ofisa_md_match(parent, cf, aux); 86256655Sjkim#endif 87256655Sjkim return (rv); 88256655Sjkim} 89256655Sjkim 90256655Sjkimvoid 91256655Sjkimlpt_ofisa_attach(device_t parent, device_t self, void *aux) 92256655Sjkim{ 93256655Sjkim struct lpt_ofisa_softc *osc = device_private(self); 94256655Sjkim struct lpt_softc *sc = &osc->sc_lpt; 95256655Sjkim struct ofisa_attach_args *aa = aux; 96256655Sjkim struct ofisa_reg_desc reg; 97256655Sjkim struct ofisa_intr_desc intr; 98256655Sjkim int n; 99256655Sjkim 100256655Sjkim /* 101256655Sjkim * We're living on an ofw. We have to ask the OFW what our 102256655Sjkim * registers and interrupts properties look like. 103256655Sjkim * 104256655Sjkim * We expect exactly one register region and one interrupt. 105256655Sjkim */ 106256655Sjkim 107256655Sjkim sc->sc_dev = self; 108256655Sjkim 109256655Sjkim n = ofisa_reg_get(aa->oba.oba_phandle, ®, 1); 110256655Sjkim#ifdef _LPT_OFISA_MD_REG_FIXUP 111256655Sjkim n = lpt_ofisa_md_reg_fixup(parent, self, aux, ®, 1, n); 112256655Sjkim#endif 113256655Sjkim if (n != 1) { 114256655Sjkim aprint_error(": error getting register data\n"); 115256655Sjkim return; 116256655Sjkim } 117256655Sjkim if (reg.len != 4 && reg.len != 8) { 118256655Sjkim aprint_error(": weird register size (%lu, expected 4 or 8)\n", 119256655Sjkim (unsigned long)reg.len); 120256655Sjkim return; 121256655Sjkim } 122256655Sjkim 123256655Sjkim n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1); 124256655Sjkim#ifdef _LPT_OFISA_MD_INTR_FIXUP 125256655Sjkim n = lpt_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n); 126256655Sjkim#endif 127256655Sjkim if (n != 1) { 128256655Sjkim aprint_error(": error getting interrupt data\n"); 129256655Sjkim return; 130256655Sjkim } 131256655Sjkim 132256655Sjkim sc->sc_iot = (reg.type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt; 133256655Sjkim if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0, &sc->sc_ioh)) { 134256655Sjkim aprint_error(": can't map register space\n"); 135256655Sjkim return; 136256655Sjkim } 137256655Sjkim 138256655Sjkim osc->sc_ih = isa_intr_establish(aa->ic, intr.irq, intr.share, 139256655Sjkim IPL_TTY, lptintr, sc); 140256655Sjkim 141256655Sjkim aprint_normal("\n"); 142256655Sjkim 143256655Sjkim lpt_attach_subr(sc); 144256655Sjkim 145256655Sjkim#if 0 146256655Sjkim printf("%s: registers: ", device_xname(sc->sc_dev)); 147256655Sjkim ofisa_reg_print(®, 1); 148256655Sjkim printf("\n"); 149256655Sjkim printf("%s: interrupts: ", device_xname(sc->sc_dev)); 150256655Sjkim ofisa_intr_print(&intr, 1); 151256655Sjkim printf("\n"); 152256655Sjkim#endif 153256655Sjkim} 154256655Sjkim