summaryrefslogtreecommitdiffstats
path: root/include/grub/speaker.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 16:29:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 16:29:51 +0000
commit6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e (patch)
tree32451fa3cdd9321fb2591fada9891b2cb70a9cd1 /include/grub/speaker.h
parentInitial commit. (diff)
downloadgrub2-6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e.tar.xz
grub2-6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e.zip
Adding upstream version 2.06.upstream/2.06upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/grub/speaker.h')
-rw-r--r--include/grub/speaker.h47
1 files changed, 47 insertions, 0 deletions
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 <grub/cpu/io.h>
+#include <grub/i386/pit.h>
+
+/* 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