attimer_isa.c revision 1.3 1 /* $NetBSD: attimer_isa.c,v 1.3 2006/10/12 01:31:16 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 (at) 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.3 2006/10/12 01:31:16 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 __unused, struct cfdata *match __unused,
95 void *aux)
96 {
97 struct isa_attach_args *ia = aux;
98 bus_space_handle_t att_ioh;
99
100 if (ISA_DIRECT_CONFIG(ia))
101 return (0);
102
103 /* If values are hardwired to something that they can't be, punt. */
104 if (ia->ia_nio < 1 ||
105 (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT &&
106 ia->ia_io[0].ir_addr != IO_TIMER1))
107 return (0);
108
109 if (ia->ia_niomem > 0 &&
110 (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM))
111 return (0);
112
113 if (ia->ia_nirq > 0 &&
114 (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ))
115 return (0);
116
117 if (ia->ia_ndrq > 0 &&
118 (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ))
119 return (0);
120
121 if (bus_space_map(ia->ia_iot, IO_TIMER1, 4, 0, &att_ioh))
122 return 0;
123 bus_space_unmap(ia->ia_iot, att_ioh, 4);
124
125 ia->ia_io[0].ir_addr = IO_TIMER1;
126 ia->ia_io[0].ir_size = 4;
127 ia->ia_nio = 1;
128
129 ia->ia_niomem = 0;
130 ia->ia_nirq = 0;
131 ia->ia_ndrq = 0;
132
133 return 1;
134 }
135
136 static void
137 attimer_isa_attach(struct device *parent __unused, struct device *self,
138 void *aux)
139 {
140 struct attimer_softc *sc = (struct attimer_softc *)self;
141 struct isa_attach_args *ia = aux;
142
143 sc->sc_iot = ia->ia_iot;
144
145 aprint_normal(": AT Timer\n");
146
147 if (bus_space_map(sc->sc_iot, IO_TIMER1, 4, 0, &sc->sc_ioh) != 0)
148 aprint_error("%s: could not map registers\n",
149 sc->sc_dev.dv_xname);
150 else
151 attimer_attach(sc);
152 }
153