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