[coreboot-gerrit] Change in coreboot[master]: [WIP]arch/x86: Add function to play a sound through PC speaker

Arthur Heymans (Code Review) gerrit at coreboot.org
Mon Jun 26 22:25:23 CEST 2017


Arthur Heymans has uploaded this change for review. ( https://review.coreboot.org/20379


Change subject: [WIP]arch/x86: Add function to play a sound through PC speaker
......................................................................

[WIP]arch/x86: Add function to play a sound through PC speaker

inspired by http://wiki.osdev.org/PC_Speaker (todo archive the link)

Change-Id: Iec31101892b109c52db279cc3a1c7f4c143a0f7b
Signed-off-by: Arthur Heymans <arthur at aheymans.xyz>
---
M src/arch/x86/Makefile.inc
A src/arch/x86/include/arch/pit.h
A src/arch/x86/pit.c
3 files changed, 62 insertions(+), 0 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/79/20379/1

diff --git a/src/arch/x86/Makefile.inc b/src/arch/x86/Makefile.inc
index 5f184c5..ae7f5b6 100644
--- a/src/arch/x86/Makefile.inc
+++ b/src/arch/x86/Makefile.inc
@@ -215,6 +215,7 @@
 romstage-$(CONFIG_X86_TOP4G_BOOTMEDIA_MAP) += mmap_boot.c
 romstage-y += postcar_loader.c
 romstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
+romstage-y += pit.c
 
 ifneq ($(CONFIG_ROMCC),y)
 
@@ -341,6 +342,7 @@
 ramstage-$(CONFIG_COOP_MULTITASKING) += thread_switch.S
 ramstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
 ramstage-$(CONFIG_HAVE_ACPI_RESUME) += wakeup.S
+ramstage-y += pit.c
 
 smm-y += memcpy.c
 smm-y += memmove.c
diff --git a/src/arch/x86/include/arch/pit.h b/src/arch/x86/include/arch/pit.h
new file mode 100644
index 0000000..6286bbf
--- /dev/null
+++ b/src/arch/x86/include/arch/pit.h
@@ -0,0 +1,21 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * 2017 Arthur Heymans <arthur at aheymans.xyz>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __INCLUDE_ARCH_PIT__
+#define __INCLUDE_ARCH_PIT__
+
+void play_sound(u32 frequency, u8 seconds);
+
+#endif /* __INCLUDE_ARCH_PIT__ */
diff --git a/src/arch/x86/pit.c b/src/arch/x86/pit.c
new file mode 100644
index 0000000..b90767e
--- /dev/null
+++ b/src/arch/x86/pit.c
@@ -0,0 +1,39 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * 2017 Arthur Heymans <arthur at aheymans.xyz>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <arch/io.h>
+#include <delay.h>
+#include <arch/pit.h>
+
+
+void play_sound(u32 frequency, u8 seconds)
+{
+	u32 div;
+	u8 reg8;
+
+	div = 1193180 / frequency;
+	outb(0xb6, 0x43);
+	outb((u8) (div), 0x42);
+	outb((u8) (div >> 8), 0x42);
+
+	reg8 = inb(0x61);
+	if (reg8!= (reg8 | 3))
+		outb(reg8 | 3, 0x61);
+
+	udelay(1000 * seconds);
+	
+	reg8 = inb(0x61) & ~3;
+	outb(reg8, 0x61);
+}

-- 
To view, visit https://review.coreboot.org/20379
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iec31101892b109c52db279cc3a1c7f4c143a0f7b
Gerrit-Change-Number: 20379
Gerrit-PatchSet: 1
Gerrit-Owner: Arthur Heymans <arthur at aheymans.xyz>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20170626/b7ae3069/attachment.html>


More information about the coreboot-gerrit mailing list