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