1 /* $NetBSD: atppc_pioc.c,v 1.7 2023/12/20 06:13:59 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 2001 Alcove - Nicolas Souchu 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * FreeBSD: src/sys/isa/ppc.c,v 1.26.2.5 2001/10/02 05:21:45 nsouch Exp 29 * 30 */ 31 32 #include "opt_atppc.h" 33 34 #include <sys/param.h> 35 __KERNEL_RCSID(0, "$NetBSD: atppc_pioc.c,v 1.7 2023/12/20 06:13:59 thorpej Exp $"); 36 37 #include <sys/systm.h> 38 #include <sys/kernel.h> 39 #include <sys/device.h> 40 #include <sys/bus.h> 41 42 #include <machine/intr.h> 43 44 #include <arch/acorn32/mainbus/piocvar.h> 45 46 #include <dev/ic/atppcreg.h> 47 #include <dev/ic/atppcvar.h> 48 49 #include "locators.h" 50 51 /* Probe and attach functions for a atppc device on the PIOC. */ 52 static int atppc_pioc_probe(device_t, cfdata_t, void *); 53 static void atppc_pioc_attach(device_t, device_t, void *); 54 55 CFATTACH_DECL_NEW(atppc_pioc, sizeof(struct atppc_softc), atppc_pioc_probe, 56 atppc_pioc_attach, NULL, NULL); 57 58 #define IO_LPTSIZE 8 59 60 /* 61 * Probe function: find parallel port controller on isa bus. Combined from 62 * lpt_isa_probe() in lpt.c and atppc_detect_port() from FreeBSD's ppc.c. 63 */ 64 static int 65 atppc_pioc_probe(device_t parent, cfdata_t cf, void *aux) 66 { 67 bus_space_handle_t ioh; 68 struct pioc_attach_args *pa = aux; 69 bus_space_tag_t iot = pa->pa_iot; 70 int addr = pa->pa_iobase + pa->pa_offset; 71 int rval = 0; 72 73 if (pa->pa_name && strcmp(pa->pa_name, "lpt") != 0) 74 return 0; 75 76 if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT) { 77 aprint_error_dev(parent, "(%s): io port unknown.\n", __func__); 78 } else if (bus_space_map(iot, addr, IO_LPTSIZE, 0, &ioh) == 0) { 79 if (atppc_detect_port(iot, ioh) == 0) 80 rval = 1; 81 else 82 aprint_error_dev(parent, 83 "(%s): unable to write/read I/O port.\n", 84 __func__); 85 bus_space_unmap(iot, ioh, IO_LPTSIZE); 86 } else { 87 aprint_error_dev(parent, "(%s): attempt to map bus space failed.\n", 88 __func__); 89 } 90 91 return rval; 92 } 93 94 /* Attach function: attach and configure parallel port controller on isa bus. */ 95 static void 96 atppc_pioc_attach(device_t parent, device_t self, void *aux) 97 { 98 struct atppc_softc *sc = device_private(self); 99 struct pioc_attach_args *pa = aux; 100 bus_addr_t iobase; 101 102 sc->sc_dev = self; 103 sc->sc_iot = pa->pa_iot; 104 sc->sc_has = 0; 105 iobase = pa->pa_iobase + pa->pa_offset; 106 107 if (bus_space_map(sc->sc_iot, iobase, IO_LPTSIZE, 0, 108 &sc->sc_ioh) != 0) { 109 aprint_error(": attempt to map bus space failed, device not " 110 "properly attached.\n"); 111 sc->sc_dev_ok = ATPPC_NOATTACH; 112 return; 113 } 114 sc->sc_dev_ok = ATPPC_ATTACHED; 115 116 /* Assign interrupt handler */ 117 if (!(device_cfdata(self)->cf_flags & ATPPC_FLAG_DISABLE_INTR)) { 118 if (pa->pa_irq != MAINBUSCF_IRQ_DEFAULT) { 119 /* Establish interrupt handler. */ 120 sc->sc_ieh = intr_claim(pa->pa_irq, IPL_TTY, "atppc", 121 atppcintr, sc); 122 sc->sc_has |= ATPPC_HAS_INTR; 123 } else 124 ATPPC_DPRINTF(("%s: IRQ not assigned or bad number of " 125 "IRQs.\n", device_xname(self))); 126 } else 127 ATPPC_VPRINTF(("%s: interrupts not configured due to flags.\n", 128 device_xname(self))); 129 130 /* Run soft configuration attach */ 131 atppc_sc_attach(sc); 132 } 133