1 /* $NetBSD: ess_isa.c,v 1.21 2008/04/28 20:23:52 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Nathan J. Williams. 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: ess_isa.c,v 1.21 2008/04/28 20:23:52 martin Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/device.h> 38 39 #include <sys/cpu.h> 40 #include <sys/bus.h> 41 42 #include <dev/isa/isavar.h> 43 44 #include <dev/isa/essreg.h> 45 #include <dev/isa/essvar.h> 46 47 #include "joy_ess.h" 48 49 #ifdef ESS_ISA_DEBUG 50 #define DPRINTF(x) printf x 51 #else 52 #define DPRINTF(x) {} 53 #endif 54 55 int ess_isa_probe(struct device *, struct cfdata *, void *); 56 void ess_isa_attach(struct device *, struct device *, void *); 57 58 CFATTACH_DECL(ess_isa, sizeof(struct ess_softc), 59 ess_isa_probe, ess_isa_attach, NULL, NULL); 60 61 int 62 ess_isa_probe(struct device *parent, struct cfdata *match, 63 void *aux) 64 { 65 int ret; 66 struct isa_attach_args *ia; 67 struct ess_softc probesc, *sc; 68 69 ia = aux; 70 sc= &probesc; 71 if (ia->ia_nio < 1) 72 return 0; 73 if (ia->ia_nirq < 1) 74 return 0; 75 if (ia->ia_ndrq < 1) 76 return 0; 77 78 if (ISA_DIRECT_CONFIG(ia)) 79 return 0; 80 81 memset(sc, 0, sizeof *sc); 82 83 sc->sc_ic = ia->ia_ic; 84 sc->sc_iot = ia->ia_iot; 85 sc->sc_iobase = ia->ia_io[0].ir_addr; 86 if (bus_space_map(sc->sc_iot, sc->sc_iobase, ESS_NPORT, 0, 87 &sc->sc_ioh)) { 88 DPRINTF(("ess_isa_probe: Couldn't map I/O region at %x, " 89 "size %x\n", sc->sc_iobase, ESS_NPORT)); 90 return 0; 91 } 92 93 sc->sc_audio1.irq = ia->ia_irq[0].ir_irq; 94 sc->sc_audio1.ist = IST_EDGE; 95 sc->sc_audio1.drq = ia->ia_drq[0].ir_drq; 96 sc->sc_audio2.irq = -1; 97 sc->sc_audio2.drq = (ia->ia_ndrq > 1) ? ia->ia_drq[1].ir_drq : -1; 98 99 ret = essmatch(sc); 100 101 bus_space_unmap(sc->sc_iot, sc->sc_ioh, ESS_NPORT); 102 103 if (ret) { 104 DPRINTF(("ess_isa_probe succeeded (score %d)\n", ret)); 105 ia->ia_nio = 1; 106 ia->ia_io[0].ir_size = ESS_NPORT; 107 108 ia->ia_nirq = 1; 109 110 if (ia->ia_ndrq > 1 && 111 ia->ia_drq[1].ir_drq != ISA_UNKNOWN_DRQ) 112 ia->ia_ndrq = 2; 113 else 114 ia->ia_ndrq = 1; 115 116 ia->ia_niomem = 0; 117 } else 118 DPRINTF(("ess_isa_probe failed\n")); 119 120 return ret; 121 } 122 123 void 124 ess_isa_attach(struct device *parent, struct device *self, void *aux) 125 { 126 struct ess_softc *sc; 127 struct isa_attach_args *ia; 128 int enablejoy; 129 130 sc = (void *)self; 131 ia = aux; 132 enablejoy = 0; 133 printf("\n"); 134 135 sc->sc_ic = ia->ia_ic; 136 sc->sc_iot = ia->ia_iot; 137 sc->sc_iobase = ia->ia_io[0].ir_addr; 138 if (bus_space_map(sc->sc_iot, sc->sc_iobase, ESS_NPORT, 0, 139 &sc->sc_ioh)) { 140 DPRINTF(("ess_isa_attach: Couldn't map I/O region at %x, " 141 "size %x\n", sc->sc_iobase, ESS_NPORT)); 142 return; 143 } 144 145 sc->sc_audio1.irq = ia->ia_irq[0].ir_irq; 146 sc->sc_audio1.ist = IST_EDGE; 147 sc->sc_audio1.drq = ia->ia_drq[0].ir_drq; 148 sc->sc_audio2.irq = -1; 149 sc->sc_audio2.drq = ia->ia_ndrq > 1 ? ia->ia_drq[1].ir_drq : -1; 150 151 #if NJOY_ESS > 0 152 if (device_cfdata(&sc->sc_dev)->cf_flags & 1) { 153 sc->sc_joy_iot = ia->ia_iot; 154 if (!bus_space_map(sc->sc_joy_iot, 0x201, 1, 0, 155 &sc->sc_joy_ioh)) 156 enablejoy = 1; 157 } 158 #endif 159 160 printf("%s", device_xname(&sc->sc_dev)); 161 162 essattach(sc, enablejoy); 163 } 164