From 6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 18:29:51 +0200 Subject: Adding upstream version 2.06. Signed-off-by: Daniel Baumann --- include/grub/speaker.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 include/grub/speaker.h (limited to 'include/grub/speaker.h') diff --git a/include/grub/speaker.h b/include/grub/speaker.h new file mode 100644 index 0000000..a076fcf --- /dev/null +++ b/include/grub/speaker.h @@ -0,0 +1,47 @@ +#ifndef GRUB_SPEAKER_HEADER +#define GRUB_SPEAKER_HEADER 1 + +#include +#include + +/* The frequency of the PIT clock. */ +#define GRUB_SPEAKER_PIT_FREQUENCY 0x1234dd + +static inline void +grub_speaker_beep_off (void) +{ + unsigned char status; + + status = grub_inb (GRUB_PIT_SPEAKER_PORT); + grub_outb (status & ~(GRUB_PIT_SPK_TMR2 | GRUB_PIT_SPK_DATA), + GRUB_PIT_SPEAKER_PORT); +} + +static inline void +grub_speaker_beep_on (grub_uint16_t pitch) +{ + unsigned char status; + unsigned int counter; + + if (pitch < 20) + pitch = 20; + else if (pitch > 20000) + pitch = 20000; + + counter = GRUB_SPEAKER_PIT_FREQUENCY / pitch; + + /* Program timer 2. */ + grub_outb (GRUB_PIT_CTRL_SELECT_2 + | GRUB_PIT_CTRL_READLOAD_WORD + | GRUB_PIT_CTRL_SQUAREWAVE_GEN + | GRUB_PIT_CTRL_COUNT_BINARY, GRUB_PIT_CTRL); + grub_outb (counter & 0xff, GRUB_PIT_COUNTER_2); /* LSB */ + grub_outb ((counter >> 8) & 0xff, GRUB_PIT_COUNTER_2); /* MSB */ + + /* Start speaker. */ + status = grub_inb (GRUB_PIT_SPEAKER_PORT); + grub_outb (status | GRUB_PIT_SPK_TMR2 | GRUB_PIT_SPK_DATA, + GRUB_PIT_SPEAKER_PORT); +} + +#endif -- cgit v1.2.3