aboutsummaryrefslogtreecommitdiff
path: root/sys/i386
diff options
context:
space:
mode:
Diffstat (limited to 'sys/i386')
-rw-r--r--sys/i386/i386/trap.c4
-rw-r--r--sys/i386/include/clock.h8
-rw-r--r--sys/i386/include/timerreg.h11
-rw-r--r--sys/i386/isa/clock.c55
4 files changed, 26 insertions, 52 deletions
diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c
index 88750d47b436..acc972e2f10d 100644
--- a/sys/i386/i386/trap.c
+++ b/sys/i386/i386/trap.c
@@ -417,7 +417,7 @@ trap(struct trapframe *frame)
mtx_lock(&Giant);
if (time_second - lastalert > 10) {
log(LOG_WARNING, "NMI: power fail\n");
- sysbeep(TIMER_FREQ/880, hz);
+ sysbeep(880, hz);
lastalert = time_second;
}
mtx_unlock(&Giant);
@@ -651,7 +651,7 @@ trap(struct trapframe *frame)
mtx_lock(&Giant);
if (time_second - lastalert > 10) {
log(LOG_WARNING, "NMI: power fail\n");
- sysbeep(TIMER_FREQ/880, hz);
+ sysbeep(880, hz);
lastalert = time_second;
}
mtx_unlock(&Giant);
diff --git a/sys/i386/include/clock.h b/sys/i386/include/clock.h
index 11d89a4e2e87..f938e5869308 100644
--- a/sys/i386/include/clock.h
+++ b/sys/i386/include/clock.h
@@ -27,15 +27,17 @@ void i8254_init(void);
* Driver to clock driver interface.
*/
-int acquire_timer2(int mode);
-int release_timer2(void);
int rtcin(int reg);
void writertc(int reg, unsigned char val);
-int sysbeep(int pitch, int period);
void timer_restore(void);
void init_TSC(void);
void init_TSC_tc(void);
+#define HAS_TIMER_SPKR 1
+int timer_spkr_acquire(void);
+int timer_spkr_release(void);
+void timer_spkr_setfreq(int freq);
+
#endif /* _KERNEL */
#endif /* !_MACHINE_CLOCK_H_ */
diff --git a/sys/i386/include/timerreg.h b/sys/i386/include/timerreg.h
index 0ab7d40510a7..cf5f281c0aa1 100644
--- a/sys/i386/include/timerreg.h
+++ b/sys/i386/include/timerreg.h
@@ -49,17 +49,6 @@
#define TIMER_CNTR2 (IO_TIMER1 + TIMER_REG_CNTR2)
#define TIMER_MODE (IO_TIMER1 + TIMER_REG_MODE)
-#define timer_spkr_acquire() \
- acquire_timer2(TIMER_SEL2 | TIMER_SQWAVE | TIMER_16BIT)
-#define timer_spkr_release() \
- release_timer2()
-
-#define spkr_set_pitch(pitch) \
- do { \
- outb(TIMER_CNTR2, (pitch) & 0xff); \
- outb(TIMER_CNTR2, (pitch) >> 8); \
- } while(0)
-
#endif /* _KERNEL */
#endif /* _MACHINE_TIMERREG_H_ */
diff --git a/sys/i386/isa/clock.c b/sys/i386/isa/clock.c
index 76a654959dc0..d5aa1189cce4 100644
--- a/sys/i386/isa/clock.c
+++ b/sys/i386/isa/clock.c
@@ -113,7 +113,6 @@ static int i8254_real_max_count;
#define RTC_LOCK mtx_lock_spin(&clock_lock)
#define RTC_UNLOCK mtx_unlock_spin(&clock_lock)
-static int beeping = 0;
static struct mtx clock_lock;
static struct intsrc *i8254_intsrc;
static u_int32_t i8254_lastcount;
@@ -172,8 +171,11 @@ clkintr(struct trapframe *frame)
}
int
-acquire_timer2(int mode)
+timer_spkr_acquire(void)
{
+ int mode;
+
+ mode = TIMER_SEL2 | TIMER_SQWAVE | TIMER_16BIT;
if (timer2_state != RELEASED)
return (-1);
@@ -187,21 +189,34 @@ acquire_timer2(int mode)
* careful with it as with timer0.
*/
outb(TIMER_MODE, TIMER_SEL2 | (mode & 0x3f));
-
+ ppi_spkr_on(); /* enable counter2 output to speaker */
return (0);
}
int
-release_timer2()
+timer_spkr_release(void)
{
if (timer2_state != ACQUIRED)
return (-1);
timer2_state = RELEASED;
outb(TIMER_MODE, TIMER_SEL2 | TIMER_SQWAVE | TIMER_16BIT);
+ ppi_spkr_off(); /* disable counter2 output to speaker */
return (0);
}
+void
+timer_spkr_setfreq(int freq)
+{
+
+ freq = i8254_freq / freq;
+ mtx_lock_spin(&clock_lock);
+ outb(TIMER_CNTR2, freq & 0xff);
+ outb(TIMER_CNTR2, freq >> 8);
+ mtx_unlock_spin(&clock_lock);
+}
+
+
/*
* This routine receives statistical clock interrupts from the RTC.
* As explained above, these occur at 128 interrupts per second.
@@ -386,38 +401,6 @@ DELAY(int n)
#endif
}
-static void
-sysbeepstop(void *chan)
-{
- ppi_spkr_off(); /* disable counter2 output to speaker */
- timer_spkr_release();
- beeping = 0;
-}
-
-int
-sysbeep(int pitch, int period)
-{
- int x = splclock();
-
- if (timer_spkr_acquire())
- if (!beeping) {
- /* Something else owns it. */
- splx(x);
- return (-1); /* XXX Should be EBUSY, but nobody cares anyway. */
- }
- mtx_lock_spin(&clock_lock);
- spkr_set_pitch(pitch);
- mtx_unlock_spin(&clock_lock);
- if (!beeping) {
- /* enable counter2 output to speaker */
- ppi_spkr_on();
- beeping = period;
- timeout(sysbeepstop, (void *)NULL, period);
- }
- splx(x);
- return (0);
-}
-
/*
* RTC support routines
*/