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