timer_isa.c revision 1.8 1 /* $NetBSD: timer_isa.c,v 1.8 2004/09/14 20:32:48 drochner Exp $ */
2 /* $OpenBSD: clock_mc.c,v 1.9 1998/03/16 09:38:26 pefo Exp $ */
3 /* NetBSD: clock_mc.c,v 1.2 1995/06/28 04:30:30 cgd Exp */
4
5 /*
6 * Copyright (c) 1992, 1993
7 * The Regents of the University of California. All rights reserved.
8 *
9 * This code is derived from software contributed to Berkeley by
10 * the Systems Programming Group of the University of Utah Computer
11 * Science Department and Ralph Campbell.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * from: Utah Hdr: clock.c 1.18 91/01/21
38 *
39 * @(#)clock.c 8.1 (Berkeley) 6/10/93
40 */
41 /*
42 * Copyright (c) 1988 University of Utah.
43 *
44 * This code is derived from software contributed to Berkeley by
45 * the Systems Programming Group of the University of Utah Computer
46 * Science Department and Ralph Campbell.
47 *
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
50 * are met:
51 * 1. Redistributions of source code must retain the above copyright
52 * notice, this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright
54 * notice, this list of conditions and the following disclaimer in the
55 * documentation and/or other materials provided with the distribution.
56 * 3. All advertising materials mentioning features or use of this software
57 * must display the following acknowledgement:
58 * This product includes software developed by the University of
59 * California, Berkeley and its contributors.
60 * 4. Neither the name of the University nor the names of its contributors
61 * may be used to endorse or promote products derived from this software
62 * without specific prior written permission.
63 *
64 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 * SUCH DAMAGE.
75 *
76 * from: Utah Hdr: clock.c 1.18 91/01/21
77 *
78 * @(#)clock.c 8.1 (Berkeley) 6/10/93
79 */
80
81 #include <sys/cdefs.h>
82 __KERNEL_RCSID(0, "$NetBSD: timer_isa.c,v 1.8 2004/09/14 20:32:48 drochner Exp $");
83
84 #include <sys/param.h>
85 #include <sys/kernel.h>
86 #include <sys/systm.h>
87 #include <sys/device.h>
88
89 #include <machine/bus.h>
90
91 #include <dev/isa/isareg.h>
92 #include <dev/isa/isavar.h>
93
94 #include <dev/isa/isareg.h>
95 #include <dev/ic/i8253reg.h>
96
97 #include <arc/arc/timervar.h>
98 #include <arc/isa/timer_isavar.h>
99
100 #define TIMER_IOSIZE 4
101 #define TIMER_IRQ 0
102
103 struct timer_isa_softc {
104 struct device sc_dev;
105
106 bus_space_tag_t sc_iot;
107 bus_space_handle_t sc_ioh;
108 };
109
110 /* Definition of the driver for autoconfig. */
111 int timer_isa_match __P((struct device *, struct cfdata *, void *));
112 void timer_isa_attach __P((struct device *, struct device *, void *));
113
114 CFATTACH_DECL(timer_isa, sizeof(struct timer_isa_softc),
115 timer_isa_match, timer_isa_attach, NULL, NULL);
116
117 /* ISA timer access code */
118 void timer_isa_init __P((struct device *));
119
120 struct timerfns timerfns_isa = {
121 timer_isa_init
122 };
123
124 int timer_isa_conf = 0;
125
126 int
127 timer_isa_match(parent, match, aux)
128 struct device *parent;
129 struct cfdata *match;
130 void *aux;
131 {
132 struct isa_attach_args *ia = aux;
133 bus_space_handle_t ioh;
134
135 if (ia->ia_nio < 1 ||
136 (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT &&
137 ia->ia_io[0].ir_addr != IO_TIMER1))
138 return (0);
139
140 if (ia->ia_niomem > 0 &&
141 (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM))
142 return (0);
143
144 if (ia->ia_nirq > 0 &&
145 (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
146 ia->ia_irq[0].ir_irq != TIMER_IRQ))
147 return (0);
148
149 if (ia->ia_ndrq > 0 &&
150 (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ))
151 return (0);
152
153 if (!timer_isa_conf)
154 return (0);
155
156 if (bus_space_map(ia->ia_iot, IO_TIMER1, TIMER_IOSIZE, 0, &ioh))
157 return (0);
158
159 bus_space_unmap(ia->ia_iot, ioh, TIMER_IOSIZE);
160
161 ia->ia_nio = 1;
162 ia->ia_io[0].ir_addr = IO_TIMER1;
163 ia->ia_io[0].ir_size = TIMER_IOSIZE;
164
165 ia->ia_niomem = 0;
166 ia->ia_nirq = 0;
167 ia->ia_ndrq = 0;
168
169 return (1);
170 }
171
172 void
173 timer_isa_attach(parent, self, aux)
174 struct device *parent;
175 struct device *self;
176 void *aux;
177 {
178 struct timer_isa_softc *sc = (struct timer_isa_softc *)self;
179 struct isa_attach_args *ia = aux;
180 void *ih;
181
182 printf("\n");
183
184 sc->sc_iot = ia->ia_iot;
185 if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
186 ia->ia_io[0].ir_size, 0, &sc->sc_ioh))
187 panic("timer_isa_attach: couldn't map clock I/O space");
188
189 ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, IST_PULSE,
190 IPL_CLOCK, (int (*)(void *))hardclock,
191 NULL /* clockframe is hardcoded */);
192 if (ih == NULL)
193 printf("%s: can't establish interrupt\n", sc->sc_dev.dv_xname);
194
195 timerattach(&sc->sc_dev, &timerfns_isa);
196 }
197
198 void
199 timer_isa_init(self)
200 struct device *self;
201 {
202 struct timer_isa_softc *sc = (struct timer_isa_softc *)self;
203
204 bus_space_write_1(sc->sc_iot, sc->sc_ioh, TIMER_MODE,
205 TIMER_SEL0 | TIMER_16BIT | TIMER_RATEGEN);
206 bus_space_write_1(sc->sc_iot, sc->sc_ioh, TIMER_CNTR0,
207 TIMER_DIV(hz) % 256);
208 bus_space_write_1(sc->sc_iot, sc->sc_ioh, TIMER_CNTR0,
209 TIMER_DIV(hz) / 256);
210 }
211