1 /* $NetBSD: lpt_supio.c,v 1.12 2008/04/28 20:23:12 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Ignatios Souvatzis. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: lpt_supio.c,v 1.12 2008/04/28 20:23:12 martin Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/ioctl.h> 38 #include <sys/select.h> 39 #include <sys/tty.h> 40 #include <sys/proc.h> 41 #include <sys/user.h> 42 #include <sys/conf.h> 43 #include <sys/file.h> 44 #include <sys/uio.h> 45 #include <sys/kernel.h> 46 #include <sys/syslog.h> 47 #include <sys/types.h> 48 #include <sys/device.h> 49 50 #include <machine/intr.h> 51 #include <machine/bus.h> 52 53 #include <dev/ic/lptreg.h> 54 #include <dev/ic/lptvar.h> 55 56 #include <amiga/dev/supio.h> 57 58 struct lptsupio_softc { 59 struct lpt_softc sc_lpt; 60 struct isr sc_isr; 61 void (*sc_intack)(void *); 62 }; 63 64 int lpt_supio_match(device_t, cfdata_t , void *); 65 void lpt_supio_attach(device_t, device_t, void *); 66 int lpt_supio_intr(void *p); 67 68 CFATTACH_DECL_NEW(lpt_supio, sizeof(struct lptsupio_softc), 69 lpt_supio_match, lpt_supio_attach, NULL, NULL); 70 71 int 72 lpt_supio_match(device_t parent, cfdata_t match, void *aux) 73 { 74 struct supio_attach_args *supa = aux; 75 76 if (strcmp(supa->supio_name,"lpt")) 77 return 0; 78 79 return (1); 80 } 81 82 int 83 lpt_supio_intr(void *p) 84 { 85 struct lptsupio_softc *sc = (void *)p; 86 int rc; 87 88 rc = lptintr(&sc->sc_lpt); 89 if (sc->sc_intack) 90 (*sc->sc_intack)(p); 91 return (rc); 92 } 93 94 void 95 lpt_supio_attach(device_t parent, device_t self, void *aux) 96 { 97 struct lptsupio_softc *sc = device_private(self); 98 struct lpt_softc *lsc = &sc->sc_lpt; 99 int iobase; 100 bus_space_tag_t iot; 101 struct supio_attach_args *supa = aux; 102 103 /* 104 * We're living on a superio chip. 105 */ 106 lsc->sc_dev = self; 107 iobase = supa->supio_iobase; 108 iot = lsc->sc_iot = supa->supio_iot; 109 sc->sc_intack = (void *)supa->supio_arg; 110 111 aprint_normal(" port 0x%04x ipl %d\n", iobase, supa->supio_ipl); 112 if (bus_space_map(iot, iobase, LPT_NPORTS, 0, &lsc->sc_ioh)) { 113 aprint_error_dev(self, "io mapping failed\n"); 114 return; 115 } 116 117 lpt_attach_subr(lsc); 118 119 sc->sc_isr.isr_intr = lpt_supio_intr; 120 sc->sc_isr.isr_arg = sc; 121 sc->sc_isr.isr_ipl = supa->supio_ipl; 122 add_isr(&sc->sc_isr); 123 } 124