diff options
author | Michał Żygowski <michal.zygowski@3mdeb.com> | 2022-10-04 11:31:12 +0200 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2023-02-15 13:17:29 +0000 |
commit | 23b79483554f0a5bbd5e7212a21c8d780a158d3d (patch) | |
tree | 75425bb3ebd548cb18d7390e23704329589ecf87 /src/drivers/pc80/pc/i8254.c | |
parent | 53ee1bba7201f7eec249684b408f82caa4bec1aa (diff) |
pc80/i8254: Add speaker beep function
Some platforms have an onboard speaker which could be used as an
indicator of successful boot or critical error, e.g. in die_notify
function. The function assumes that SPKR GPIO is properly configured
by the platform code.
Signed-off-by: Michał Żygowski <michal.zygowski@3mdeb.com>
Change-Id: I8189b3462bb5140af352fa786db3a6a2a45076f2
Reviewed-on: https://review.coreboot.org/c/coreboot/+/68100
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Krystian Hebel <krystian.hebel@3mdeb.com>
Diffstat (limited to 'src/drivers/pc80/pc/i8254.c')
-rw-r--r-- | src/drivers/pc80/pc/i8254.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/drivers/pc80/pc/i8254.c b/src/drivers/pc80/pc/i8254.c index 914c9aed9c..e83f00e00f 100644 --- a/src/drivers/pc80/pc/i8254.c +++ b/src/drivers/pc80/pc/i8254.c @@ -3,6 +3,7 @@ #include <arch/io.h> #include <commonlib/helpers.h> #include <cpu/x86/tsc.h> +#include <delay.h> #include <pc80/i8254.h> /* Initialize i8254 timers */ @@ -110,3 +111,24 @@ unsigned long tsc_freq_mhz(void) return timer_tsc; } #endif + +void beep(unsigned int frequency_hz, unsigned int duration_msec) +{ + unsigned int count = CLOCK_TICK_RATE / frequency_hz; + + /* Set command for counter 2, 2 byte write, mode 3 */ + outb(TIMER2_SEL | WORD_ACCESS | MODE3, TIMER_MODE_PORT); + + /* Select desired Hz */ + outb(count & 0xff, TIMER2_PORT); + outb((count >> 8) & 0xff, TIMER2_PORT); + + /* Switch on the speaker */ + outb(inb(PPC_PORTB) | (PPCB_T2GATE | PPCB_SPKR), PPC_PORTB); + + /* Block for specified milliseconds */ + mdelay(duration_msec); + + /* Switch off the speaker */ + outb(inb(PPC_PORTB) & ~(PPCB_T2GATE | PPCB_SPKR), PPC_PORTB); +} |