Michał Żygowski has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/68100 )
Change subject: pc80/i8254: Add speaker beep function ......................................................................
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 --- M src/drivers/pc80/pc/i8254.c M src/include/pc80/i8254.h 2 files changed, 38 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/00/68100/1
diff --git a/src/drivers/pc80/pc/i8254.c b/src/drivers/pc80/pc/i8254.c index 914c9ae..4721059 100644 --- a/src/drivers/pc80/pc/i8254.c +++ b/src/drivers/pc80/pc/i8254.c @@ -4,6 +4,7 @@ #include <commonlib/helpers.h> #include <cpu/x86/tsc.h> #include <pc80/i8254.h> +#include <delay.h>
/* Initialize i8254 timers */
@@ -110,3 +111,24 @@ return timer_tsc; } #endif + +void beep(unsigned int frequency, unsigned int duration_msec) +{ + unsigned int count = CLOCK_TICK_RATE / frequency; + + /* Switch on the speaker */ + outb(inb(PPC_PORTB) | (PPCB_T2GATE | PPCB_SPKR), PPC_PORTB); + + /* 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); + + /* Block for specified miliseconds */ + mdelay(duration_msec); + + /* Switch off the speaker */ + outb(inb(PPC_PORTB) & ~(PPCB_T2GATE | PPCB_SPKR), PPC_PORTB); +} diff --git a/src/include/pc80/i8254.h b/src/include/pc80/i8254.h index a9c0bae..bf4e990 100644 --- a/src/include/pc80/i8254.h +++ b/src/include/pc80/i8254.h @@ -43,5 +43,6 @@
void setup_i8254(void); unsigned long calibrate_tsc_with_pit(void); +void beep(unsigned int frequency, unsigned int duration_msec);
#endif /* PC80_I8254_H */