attimer_isa.c revision 1.9 1 /* $NetBSD: attimer_isa.c,v 1.9 2008/01/03 01:21:45 dyoung 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 * 3. Neither the name of The NetBSD Foundation nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
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 /*
33 * Copyright (c) 1996 Carnegie-Mellon University.
34 * All rights reserved.
35 *
36 * Author: Chris G. Demetriou
37 *
38 * Permission to use, copy, modify and distribute this software and
39 * its documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
43 *
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
46 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47 *
48 * Carnegie Mellon requests users of this software to return to
49 *
50 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie the
56 * rights to redistribute these changes.
57 */
58
59 /*
60 * ISA attachment for attimer(4)
61 */
62
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: attimer_isa.c,v 1.9 2008/01/03 01:21:45 dyoung Exp $");
65
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/errno.h>
69 #include <sys/ioctl.h>
70 #include <sys/device.h>
71 #include <sys/proc.h>
72
73 #include <sys/bus.h>
74
75 #include <dev/ic/attimervar.h>
76
77 #include <dev/isa/isareg.h>
78 #include <dev/isa/isavar.h>
79
80 static int attimer_isa_match(device_t, struct cfdata *, void *);
81 static void attimer_isa_attach(device_t, device_t, void *);
82
83 CFATTACH_DECL(attimer_isa, sizeof(struct attimer_softc),
84 attimer_isa_match, attimer_isa_attach, attimer_detach, NULL);
85
86 static int
87 attimer_isa_match(device_t parent, struct cfdata *match, void *aux)
88 {
89 struct isa_attach_args *ia = aux;
90 bus_space_handle_t att_ioh;
91
92 if (ISA_DIRECT_CONFIG(ia))
93 return (0);
94
95 /* If values are hardwired to something that they can't be, punt. */
96 if (ia->ia_nio < 1 ||
97 (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT &&
98 ia->ia_io[0].ir_addr != IO_TIMER1))
99 return (0);
100
101 if (ia->ia_niomem > 0 &&
102 (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM))
103 return (0);
104
105 if (ia->ia_nirq > 0 &&
106 (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ))
107 return (0);
108
109 if (ia->ia_ndrq > 0 &&
110 (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ))
111 return (0);
112
113 if (bus_space_map(ia->ia_iot, IO_TIMER1, 4, 0, &att_ioh))
114 return 0;
115 bus_space_unmap(ia->ia_iot, att_ioh, 4);
116
117 ia->ia_io[0].ir_addr = IO_TIMER1;
118 ia->ia_io[0].ir_size = 4;
119 ia->ia_nio = 1;
120
121 ia->ia_niomem = 0;
122 ia->ia_nirq = 0;
123 ia->ia_ndrq = 0;
124
125 return 1;
126 }
127
128 static void
129 attimer_isa_attach(device_t parent, device_t self, void *aux)
130 {
131 struct attimer_softc *sc = device_private(self);
132 struct isa_attach_args *ia = aux;
133
134 sc->sc_iot = ia->ia_iot;
135
136 aprint_naive(": AT Timer\n");
137 aprint_normal(": AT Timer\n");
138
139 sc->sc_size = 4;
140 if (bus_space_map(sc->sc_iot, IO_TIMER1, sc->sc_size, 0,
141 &sc->sc_ioh) != 0)
142 aprint_error_dev(&sc->sc_dev, "could not map registers\n");
143 else
144 attimer_attach(sc);
145 }
146