isaclock.c revision 1.9 1 1.9 ad /* $NetBSD: isaclock.c,v 1.9 2007/07/09 20:52:25 ad Exp $ */
2 1.1 briggs
3 1.1 briggs /*-
4 1.1 briggs * Copyright (c) 1990 The Regents of the University of California.
5 1.1 briggs * All rights reserved.
6 1.1 briggs *
7 1.1 briggs * This code is derived from software contributed to Berkeley by
8 1.1 briggs * William Jolitz and Don Ahn.
9 1.1 briggs *
10 1.1 briggs * Redistribution and use in source and binary forms, with or without
11 1.1 briggs * modification, are permitted provided that the following conditions
12 1.1 briggs * are met:
13 1.1 briggs * 1. Redistributions of source code must retain the above copyright
14 1.1 briggs * notice, this list of conditions and the following disclaimer.
15 1.1 briggs * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 briggs * notice, this list of conditions and the following disclaimer in the
17 1.1 briggs * documentation and/or other materials provided with the distribution.
18 1.4 agc * 3. Neither the name of the University nor the names of its contributors
19 1.4 agc * may be used to endorse or promote products derived from this software
20 1.4 agc * without specific prior written permission.
21 1.4 agc *
22 1.4 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.4 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.4 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.4 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.4 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.4 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.4 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.4 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.4 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.4 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.4 agc * SUCH DAMAGE.
33 1.4 agc *
34 1.4 agc * @(#)clock.c 7.2 (Berkeley) 5/12/91
35 1.4 agc */
36 1.4 agc /*-
37 1.4 agc * Copyright (c) 1993, 1994 Charles M. Hannum.
38 1.4 agc *
39 1.4 agc * This code is derived from software contributed to Berkeley by
40 1.4 agc * William Jolitz and Don Ahn.
41 1.4 agc *
42 1.4 agc * Redistribution and use in source and binary forms, with or without
43 1.4 agc * modification, are permitted provided that the following conditions
44 1.4 agc * are met:
45 1.4 agc * 1. Redistributions of source code must retain the above copyright
46 1.4 agc * notice, this list of conditions and the following disclaimer.
47 1.4 agc * 2. Redistributions in binary form must reproduce the above copyright
48 1.4 agc * notice, this list of conditions and the following disclaimer in the
49 1.4 agc * documentation and/or other materials provided with the distribution.
50 1.1 briggs * 3. All advertising materials mentioning features or use of this software
51 1.1 briggs * must display the following acknowledgement:
52 1.1 briggs * This product includes software developed by the University of
53 1.1 briggs * California, Berkeley and its contributors.
54 1.1 briggs * 4. Neither the name of the University nor the names of its contributors
55 1.1 briggs * may be used to endorse or promote products derived from this software
56 1.1 briggs * without specific prior written permission.
57 1.1 briggs *
58 1.1 briggs * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 1.1 briggs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 1.1 briggs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 1.1 briggs * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 1.1 briggs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.1 briggs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.1 briggs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.1 briggs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.1 briggs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.1 briggs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.1 briggs * SUCH DAMAGE.
69 1.1 briggs *
70 1.1 briggs * @(#)clock.c 7.2 (Berkeley) 5/12/91
71 1.1 briggs */
72 1.1 briggs /*
73 1.1 briggs * Mach Operating System
74 1.1 briggs * Copyright (c) 1991,1990,1989 Carnegie Mellon University
75 1.1 briggs * All Rights Reserved.
76 1.1 briggs *
77 1.1 briggs * Permission to use, copy, modify and distribute this software and its
78 1.1 briggs * documentation is hereby granted, provided that both the copyright
79 1.1 briggs * notice and this permission notice appear in all copies of the
80 1.1 briggs * software, derivative works or modified versions, and any portions
81 1.1 briggs * thereof, and that both notices appear in supporting documentation.
82 1.1 briggs *
83 1.1 briggs * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
84 1.1 briggs * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
85 1.1 briggs * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
86 1.1 briggs *
87 1.1 briggs * Carnegie Mellon requests users of this software to return to
88 1.1 briggs *
89 1.1 briggs * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
90 1.1 briggs * School of Computer Science
91 1.1 briggs * Carnegie Mellon University
92 1.1 briggs * Pittsburgh PA 15213-3890
93 1.1 briggs *
94 1.1 briggs * any improvements or extensions that they make and grant Carnegie Mellon
95 1.1 briggs * the rights to redistribute these changes.
96 1.1 briggs */
97 1.1 briggs /*
98 1.1 briggs Copyright 1988, 1989 by Intel Corporation, Santa Clara, California.
99 1.1 briggs
100 1.1 briggs All Rights Reserved
101 1.1 briggs
102 1.1 briggs Permission to use, copy, modify, and distribute this software and
103 1.1 briggs its documentation for any purpose and without fee is hereby
104 1.1 briggs granted, provided that the above copyright notice appears in all
105 1.1 briggs copies and that both the copyright notice and this permission notice
106 1.1 briggs appear in supporting documentation, and that the name of Intel
107 1.1 briggs not be used in advertising or publicity pertaining to distribution
108 1.1 briggs of the software without specific, written prior permission.
109 1.1 briggs
110 1.1 briggs INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
111 1.1 briggs INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
112 1.1 briggs IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
113 1.1 briggs CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
114 1.1 briggs LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
115 1.1 briggs NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
116 1.1 briggs WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
117 1.1 briggs */
118 1.1 briggs
119 1.1 briggs /*
120 1.1 briggs * Primitive clock interrupt routines.
121 1.1 briggs */
122 1.3 lukem
123 1.3 lukem #include <sys/cdefs.h>
124 1.9 ad __KERNEL_RCSID(0, "$NetBSD: isaclock.c,v 1.9 2007/07/09 20:52:25 ad Exp $");
125 1.3 lukem
126 1.1 briggs #include <sys/param.h>
127 1.1 briggs #include <sys/systm.h>
128 1.1 briggs #include <sys/callout.h>
129 1.1 briggs #include <sys/time.h>
130 1.1 briggs #include <sys/kernel.h>
131 1.1 briggs #include <sys/device.h>
132 1.1 briggs
133 1.1 briggs #include <machine/cpu.h>
134 1.1 briggs #include <machine/intr.h>
135 1.1 briggs #include <machine/pio.h>
136 1.1 briggs
137 1.1 briggs #include <dev/isa/isareg.h>
138 1.1 briggs #include <dev/isa/isavar.h>
139 1.1 briggs #include <dev/ic/i8253reg.h>
140 1.1 briggs #include <sandpoint/isa/nvram.h>
141 1.1 briggs #include <sandpoint/isa/spkrreg.h>
142 1.1 briggs
143 1.1 briggs extern void disable_intr(void); /* In locore.S */
144 1.1 briggs extern void enable_intr(void); /* In locore.S */
145 1.1 briggs
146 1.1 briggs void sysbeepstop __P((void *));
147 1.1 briggs void sysbeep __P((int, int));
148 1.1 briggs
149 1.1 briggs static int beeping;
150 1.1 briggs
151 1.1 briggs void
152 1.1 briggs sysbeepstop(arg)
153 1.1 briggs void *arg;
154 1.1 briggs {
155 1.1 briggs /* disable counter 2 */
156 1.1 briggs disable_intr();
157 1.1 briggs isa_outb(PITAUX_PORT, isa_inb(PITAUX_PORT) & ~PIT_SPKR);
158 1.1 briggs enable_intr();
159 1.1 briggs beeping = 0;
160 1.1 briggs }
161 1.1 briggs
162 1.1 briggs void
163 1.1 briggs sysbeep(pitch, period)
164 1.1 briggs int pitch, period;
165 1.1 briggs {
166 1.9 ad static callout_t sysbeep_ch;
167 1.1 briggs static int last_pitch;
168 1.9 ad static bool again;
169 1.9 ad
170 1.9 ad if (!again) {
171 1.9 ad callout_init(&sysbeep_ch, 0);
172 1.9 ad again = true;
173 1.9 ad }
174 1.1 briggs
175 1.1 briggs if (beeping)
176 1.1 briggs callout_stop(&sysbeep_ch);
177 1.1 briggs if (pitch == 0 || period == 0) {
178 1.1 briggs sysbeepstop(0);
179 1.1 briggs last_pitch = 0;
180 1.1 briggs return;
181 1.1 briggs }
182 1.1 briggs if (!beeping || last_pitch != pitch) {
183 1.1 briggs disable_intr();
184 1.1 briggs isa_outb(IO_TIMER1 + TIMER_MODE,
185 1.1 briggs TIMER_SEL2 | TIMER_16BIT | TIMER_SQWAVE);
186 1.1 briggs isa_outb(IO_TIMER1 + TIMER_CNTR2, TIMER_DIV(pitch) % 256);
187 1.1 briggs isa_outb(IO_TIMER1 + TIMER_CNTR2, TIMER_DIV(pitch) / 256);
188 1.1 briggs isa_outb(PITAUX_PORT, isa_inb(PITAUX_PORT) | PIT_SPKR); /* enable counter 2 */
189 1.1 briggs enable_intr();
190 1.1 briggs }
191 1.1 briggs last_pitch = pitch;
192 1.1 briggs beeping = 1;
193 1.1 briggs callout_reset(&sysbeep_ch, period, sysbeepstop, NULL);
194 1.1 briggs }
195