summaryrefslogtreecommitdiffstats
path: root/sys/pc98/cbus
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2008-03-26 20:09:21 +0000
committerphk <phk@FreeBSD.org>2008-03-26 20:09:21 +0000
commitfa71439e44b745e751add3bebee1fdf492212897 (patch)
treee91c04a22676482787a397cde06c51737c92138e /sys/pc98/cbus
parentf5a614e94615c27d79bb9bac74fcc58341eb8884 (diff)
downloadFreeBSD-src-fa71439e44b745e751add3bebee1fdf492212897.zip
FreeBSD-src-fa71439e44b745e751add3bebee1fdf492212897.tar.gz
The "free-lance" timer in the i8254 is only used for the speaker
these days, so de-generalize the acquire_timer/release_timer api to just deal with speakers. The new (optional) MD functions are: timer_spkr_acquire() timer_spkr_release() and timer_spkr_setfreq() the last of which configures the timer to generate a tone of a given frequency, in Hz instead of 1/1193182th of seconds. Drop entirely timer2 on pc98, it is not used anywhere at all. Move sysbeep() to kern/tty_cons.c and use the timer_spkr*() if they exist, and do nothing otherwise. Remove prototypes and empty acquire-/release-timer() and sysbeep() functions from the non-beeping archs. This eliminate the need for the speaker driver to know about i8254frequency at all. In theory this makes the speaker driver MI, contingent on the timer_spkr_*() functions existing but the driver does not know this yet and still attaches to the ISA bus. Syscons is more tricky, in one function, sc_tone(), it knows the hz and things are just fine. In the other function, sc_bell() it seems to get the period from the KDMKTONE ioctl in terms if 1/1193182th second, so we hardcode the 1193182 and leave it at that. It's probably not important. Change a few other sysbeep() uses which obviously knew that the argument was in terms of i8254 frequency, and leave alone those that look like people thought sysbeep() took frequency in hertz. This eliminates the knowledge of i8254_freq from all but the actual clock.c code and the prof_machdep.c on amd64 and i386, where I think it would be smart to ask for help from the timecounters anyway [TBD].
Diffstat (limited to 'sys/pc98/cbus')
-rw-r--r--sys/pc98/cbus/clock.c77
-rw-r--r--sys/pc98/cbus/pcrtc.c77
-rw-r--r--sys/pc98/cbus/syscons_cbus.c2
3 files changed, 29 insertions, 127 deletions
diff --git a/sys/pc98/cbus/clock.c b/sys/pc98/cbus/clock.c
index fcacda5..38f9854 100644
--- a/sys/pc98/cbus/clock.c
+++ b/sys/pc98/cbus/clock.c
@@ -105,7 +105,6 @@ TUNABLE_INT("hw.i8254.freq", &i8254_freq);
int i8254_max_count;
static int i8254_real_max_count;
-static int beeping = 0;
static struct mtx clock_lock;
static struct intsrc *i8254_intsrc;
static u_int32_t i8254_lastcount;
@@ -121,7 +120,6 @@ static int using_lapic_timer;
#define ACQUIRE_PENDING 3
static u_char timer1_state;
-static u_char timer2_state;
static void rtc_serialcombit(int);
static void rtc_serialcom(int);
static int rtc_inb(void);
@@ -161,8 +159,11 @@ clkintr(struct trapframe *frame)
}
int
-acquire_timer1(int mode)
+timer_spkr_acquire(void)
{
+ int mode;
+
+ mode = TIMER_SEL1 | TIMER_SQWAVE | TIMER_16BIT;
if (timer1_state != RELEASED)
return (-1);
@@ -176,50 +177,32 @@ acquire_timer1(int mode)
* careful with it as with timer0.
*/
outb(TIMER_MODE, TIMER_SEL1 | (mode & 0x3f));
+ ppi_spkr_on(); /* enable counter1 output to speaker */
return (0);
}
int
-acquire_timer2(int mode)
-{
-
- if (timer2_state != RELEASED)
- return (-1);
- timer2_state = ACQUIRED;
-
- /*
- * This access to the timer registers is as atomic as possible
- * because it is a single instruction. We could do better if we
- * knew the rate. Use of splclock() limits glitches to 10-100us,
- * and this is probably good enough for timer2, so we aren't as
- * careful with it as with timer0.
- */
- outb(TIMER_MODE, TIMER_SEL2 | (mode & 0x3f));
-
- return (0);
-}
-
-int
-release_timer1()
+timer_spkr_release(void)
{
if (timer1_state != ACQUIRED)
return (-1);
timer1_state = RELEASED;
outb(TIMER_MODE, TIMER_SEL1 | TIMER_SQWAVE | TIMER_16BIT);
+ ppi_spkr_off(); /* disable counter1 output to speaker */
return (0);
}
-int
-release_timer2()
+void
+timer_spkr_setfreq(int freq)
{
- if (timer2_state != ACQUIRED)
- return (-1);
- timer2_state = RELEASED;
- outb(TIMER_MODE, TIMER_SEL2 | TIMER_SQWAVE | TIMER_16BIT);
- return (0);
+ freq = i8254_freq / freq;
+ mtx_lock_spin(&clock_lock);
+ outb(TIMER_CNTR1, (freq) & 0xff);
+ outb(TIMER_CNTR1, (freq) >> 8);
+ mtx_unlock_spin(&clock_lock);
}
@@ -342,38 +325,6 @@ DELAY(int n)
#endif
}
-static void
-sysbeepstop(void *chan)
-{
- ppi_spkr_off(); /* disable counter1 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 counter1 output to speaker */
- ppi_spkr_on();
- beeping = period;
- timeout(sysbeepstop, (void *)NULL, period);
- }
- splx(x);
- return (0);
-}
-
static u_int
calibrate_clocks(void)
{
diff --git a/sys/pc98/cbus/pcrtc.c b/sys/pc98/cbus/pcrtc.c
index fcacda5..38f9854 100644
--- a/sys/pc98/cbus/pcrtc.c
+++ b/sys/pc98/cbus/pcrtc.c
@@ -105,7 +105,6 @@ TUNABLE_INT("hw.i8254.freq", &i8254_freq);
int i8254_max_count;
static int i8254_real_max_count;
-static int beeping = 0;
static struct mtx clock_lock;
static struct intsrc *i8254_intsrc;
static u_int32_t i8254_lastcount;
@@ -121,7 +120,6 @@ static int using_lapic_timer;
#define ACQUIRE_PENDING 3
static u_char timer1_state;
-static u_char timer2_state;
static void rtc_serialcombit(int);
static void rtc_serialcom(int);
static int rtc_inb(void);
@@ -161,8 +159,11 @@ clkintr(struct trapframe *frame)
}
int
-acquire_timer1(int mode)
+timer_spkr_acquire(void)
{
+ int mode;
+
+ mode = TIMER_SEL1 | TIMER_SQWAVE | TIMER_16BIT;
if (timer1_state != RELEASED)
return (-1);
@@ -176,50 +177,32 @@ acquire_timer1(int mode)
* careful with it as with timer0.
*/
outb(TIMER_MODE, TIMER_SEL1 | (mode & 0x3f));
+ ppi_spkr_on(); /* enable counter1 output to speaker */
return (0);
}
int
-acquire_timer2(int mode)
-{
-
- if (timer2_state != RELEASED)
- return (-1);
- timer2_state = ACQUIRED;
-
- /*
- * This access to the timer registers is as atomic as possible
- * because it is a single instruction. We could do better if we
- * knew the rate. Use of splclock() limits glitches to 10-100us,
- * and this is probably good enough for timer2, so we aren't as
- * careful with it as with timer0.
- */
- outb(TIMER_MODE, TIMER_SEL2 | (mode & 0x3f));
-
- return (0);
-}
-
-int
-release_timer1()
+timer_spkr_release(void)
{
if (timer1_state != ACQUIRED)
return (-1);
timer1_state = RELEASED;
outb(TIMER_MODE, TIMER_SEL1 | TIMER_SQWAVE | TIMER_16BIT);
+ ppi_spkr_off(); /* disable counter1 output to speaker */
return (0);
}
-int
-release_timer2()
+void
+timer_spkr_setfreq(int freq)
{
- if (timer2_state != ACQUIRED)
- return (-1);
- timer2_state = RELEASED;
- outb(TIMER_MODE, TIMER_SEL2 | TIMER_SQWAVE | TIMER_16BIT);
- return (0);
+ freq = i8254_freq / freq;
+ mtx_lock_spin(&clock_lock);
+ outb(TIMER_CNTR1, (freq) & 0xff);
+ outb(TIMER_CNTR1, (freq) >> 8);
+ mtx_unlock_spin(&clock_lock);
}
@@ -342,38 +325,6 @@ DELAY(int n)
#endif
}
-static void
-sysbeepstop(void *chan)
-{
- ppi_spkr_off(); /* disable counter1 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 counter1 output to speaker */
- ppi_spkr_on();
- beeping = period;
- timeout(sysbeepstop, (void *)NULL, period);
- }
- splx(x);
- return (0);
-}
-
static u_int
calibrate_clocks(void)
{
diff --git a/sys/pc98/cbus/syscons_cbus.c b/sys/pc98/cbus/syscons_cbus.c
index 19415a2..c23fbc4 100644
--- a/sys/pc98/cbus/syscons_cbus.c
+++ b/sys/pc98/cbus/syscons_cbus.c
@@ -233,7 +233,7 @@ sc_tone(int herz)
if (timer_spkr_acquire())
return EBUSY;
/* set pitch */
- spkr_set_pitch(i8254_freq / herz);
+ timer_spkr_setfreq(herz);
} else {
/* disable counter 1 */
ppi_spkr_off();
OpenPOWER on IntegriCloud