1 /* $NetBSD: attimer_isa.c,v 1.2 2005/12/11 12:22:02 christos Exp $ */ 2 3 /* 4 * Copyright (c) 2005 The NetBSD Foundation. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to the NetBSD Foundation 8 * by Quentin Garnier. 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Copyright (c) 1996 Carnegie-Mellon University. 41 * All rights reserved. 42 * 43 * Author: Chris G. Demetriou 44 * 45 * Permission to use, copy, modify and distribute this software and 46 * its documentation is hereby granted, provided that both the copyright 47 * notice and this permission notice appear in all copies of the 48 * software, derivative works or modified versions, and any portions 49 * thereof, and that both notices appear in supporting documentation. 50 * 51 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 52 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 53 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 54 * 55 * Carnegie Mellon requests users of this software to return to 56 * 57 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 58 * School of Computer Science 59 * Carnegie Mellon University 60 * Pittsburgh PA 15213-3890 61 * 62 * any improvements or extensions that they make and grant Carnegie the 63 * rights to redistribute these changes. 64 */ 65 66 /* 67 * ISA attachment for attimer(4) 68 */ 69 70 #include <sys/cdefs.h> 71 __KERNEL_RCSID(0, "$NetBSD: attimer_isa.c,v 1.2 2005/12/11 12:22:02 christos Exp $"); 72 73 #include <sys/param.h> 74 #include <sys/systm.h> 75 #include <sys/errno.h> 76 #include <sys/ioctl.h> 77 #include <sys/device.h> 78 #include <sys/proc.h> 79 80 #include <machine/bus.h> 81 82 #include <dev/ic/attimervar.h> 83 84 #include <dev/isa/isareg.h> 85 #include <dev/isa/isavar.h> 86 87 static int attimer_isa_match(struct device *, struct cfdata *, void *); 88 static void attimer_isa_attach(struct device *, struct device *, void *); 89 90 CFATTACH_DECL(attimer_isa, sizeof(struct attimer_softc), 91 attimer_isa_match, attimer_isa_attach, NULL, NULL); 92 93 static int 94 attimer_isa_match(struct device *parent, struct cfdata *match, void *aux) 95 { 96 struct isa_attach_args *ia = aux; 97 bus_space_handle_t att_ioh; 98 99 if (ISA_DIRECT_CONFIG(ia)) 100 return (0); 101 102 /* If values are hardwired to something that they can't be, punt. */ 103 if (ia->ia_nio < 1 || 104 (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT && 105 ia->ia_io[0].ir_addr != IO_TIMER1)) 106 return (0); 107 108 if (ia->ia_niomem > 0 && 109 (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM)) 110 return (0); 111 112 if (ia->ia_nirq > 0 && 113 (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ)) 114 return (0); 115 116 if (ia->ia_ndrq > 0 && 117 (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ)) 118 return (0); 119 120 if (bus_space_map(ia->ia_iot, IO_TIMER1, 4, 0, &att_ioh)) 121 return 0; 122 bus_space_unmap(ia->ia_iot, att_ioh, 4); 123 124 ia->ia_io[0].ir_addr = IO_TIMER1; 125 ia->ia_io[0].ir_size = 4; 126 ia->ia_nio = 1; 127 128 ia->ia_niomem = 0; 129 ia->ia_nirq = 0; 130 ia->ia_ndrq = 0; 131 132 return 1; 133 } 134 135 static void 136 attimer_isa_attach(struct device *parent, struct device *self, void *aux) 137 { 138 struct attimer_softc *sc = (struct attimer_softc *)self; 139 struct isa_attach_args *ia = aux; 140 141 sc->sc_iot = ia->ia_iot; 142 143 aprint_normal(": AT Timer\n"); 144 145 if (bus_space_map(sc->sc_iot, IO_TIMER1, 4, 0, &sc->sc_ioh) != 0) 146 aprint_error("%s: could not map registers\n", 147 sc->sc_dev.dv_xname); 148 else 149 attimer_attach(sc); 150 } 151