1 /* $NetBSD: tsdio.c,v 1.6 2008/04/28 20:23:52 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 2005 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jesse Off 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: tsdio.c,v 1.6 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/bus.h> 40 #include <sys/intr.h> 41 42 #include <dev/isa/isareg.h> 43 #include <dev/isa/isavar.h> 44 #include <dev/isa/isadmavar.h> 45 #include <dev/isa/tsdiovar.h> 46 47 int tsdio_probe(struct device *, struct cfdata *, void *); 48 void tsdio_attach(struct device *, struct device *, void *); 49 int tsdio_search(struct device *, struct cfdata *, const int *, void *); 50 int tsdio_print(void *, const char *); 51 52 CFATTACH_DECL(tsdio, sizeof(struct tsdio_softc), 53 tsdio_probe, tsdio_attach, NULL, NULL); 54 55 int 56 tsdio_probe(parent, cf, aux) 57 struct device *parent; 58 struct cfdata *cf; 59 void *aux; 60 { 61 struct isa_attach_args *ia = aux; 62 bus_space_tag_t iot = ia->ia_iot; 63 bus_space_handle_t dioh; 64 int rv = 0, have_io = 0; 65 66 if (ia->ia_nio < 1) 67 return (0); 68 if (ia->ia_nirq < 1) 69 return (0); 70 71 if (ISA_DIRECT_CONFIG(ia)) 72 return (0); 73 74 /* 75 * Disallow wildcarded I/O base. 76 */ 77 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT) 78 return (0); 79 80 /* 81 * Map the I/O space. 82 */ 83 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 84 0, &dioh)) 85 goto out; 86 have_io = 1; 87 88 if (bus_space_read_1(ia->ia_iot, dioh, 0) != 0x54) { 89 goto out; 90 } 91 92 rv = 1; 93 ia->ia_nio = 1; 94 ia->ia_io[0].ir_size = 8; 95 ia->ia_niomem = 0; 96 ia->ia_nirq = 0; 97 ia->ia_ndrq = 0; 98 99 out: 100 if (have_io) 101 bus_space_unmap(iot, dioh, 8); 102 103 return (rv); 104 } 105 106 void 107 tsdio_attach(parent, self, aux) 108 struct device *parent, *self; 109 void *aux; 110 { 111 struct tsdio_softc *sc = (struct tsdio_softc *) self; 112 struct isa_attach_args *ia = aux; 113 114 sc->sc_iot = ia->ia_iot; 115 116 aprint_normal(": Technologic Systems TS-DIO24\n"); 117 118 /* 119 * Map the device. 120 */ 121 if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, 8, 122 0, &sc->sc_ioh)) { 123 aprint_error_dev(&sc->sc_dev, "unable to map i/o space\n"); 124 return; 125 } 126 127 /* 128 * Attach sub-devices 129 */ 130 config_search_ia(tsdio_search, self, "tsdio", NULL); 131 } 132 133 int 134 tsdio_search(parent, cf, l, aux) 135 struct device *parent; 136 struct cfdata *cf; 137 const int *l; 138 void *aux; 139 { 140 struct tsdio_softc *sc = (struct tsdio_softc *)parent; 141 struct tsdio_attach_args sa; 142 143 sa.ta_iot = sc->sc_iot; 144 sa.ta_ioh = sc->sc_ioh; 145 146 if (config_match(parent, cf, &sa) > 0) 147 config_attach(parent, cf, &sa, tsdio_print); 148 149 return (0); 150 } 151 152 int 153 tsdio_print(aux, name) 154 void *aux; 155 const char *name; 156 { 157 158 return (UNCONF); 159 } 160