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