diff --git a/Kconfig b/Kconfig index e9a22b5e4b..908c9b90d4 100644 --- a/Kconfig +++ b/Kconfig @@ -30,6 +30,13 @@ config LOCALVERSION help Append an extra string to the end of the LinuxBIOS version. +config BEEPS + bool "Enable beeps upon certain LinuxBIOS events." + depends EXPERT + default n + help + Enable this option to make LinuxBIOS beep upon certain events. + endmenu source mainboard/Kconfig diff --git a/arch/x86/Makefile b/arch/x86/Makefile index aa06db159f..0dd257ff45 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -62,8 +62,8 @@ $(obj)/linuxbios.bootblock: $(obj)/linuxbios.vpd $(obj)/stage0.init # STAGE0_CONSOLE_OBJ = vtxprintf.o vsprintf.o console.o -STAGE0_LIB_OBJ = uart8250.o mem.o elfboot.o lar.o -STAGE0_ARCH_X86_OBJ = cachemain.o serial.o archelfboot.o +STAGE0_LIB_OBJ = uart8250.o mem.o elfboot.o lar.o delay.o +STAGE0_ARCH_X86_OBJ = cachemain.o serial.o archelfboot.o speaker.o udelay_io.o ifeq ($(CONFIG_CAR_TYPE_I586),y) STAGE0_CAR_OBJ = stage0_i586.o diff --git a/arch/x86/cachemain.c b/arch/x86/cachemain.c index 99e56732dc..5b0a309a89 100644 --- a/arch/x86/cachemain.c +++ b/arch/x86/cachemain.c @@ -22,6 +22,7 @@ #include #include #include +#include /* these prototypes should go into headers */ void uart_init(void); @@ -47,7 +48,9 @@ static void stop_ap(void) static void enable_superio(void) { // nothing yet + beep_short(); // FIXME post_code(0xf1); + beep_long(); // FIXME } static void enable_rom(void) diff --git a/arch/x86/speaker.c b/arch/x86/speaker.c new file mode 100644 index 0000000000..39f4e02c4f --- /dev/null +++ b/arch/x86/speaker.c @@ -0,0 +1,113 @@ +/* + * This file is part of the LinuxBIOS project. + * + * Copyright (C) 2007 Uwe Hermann + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + * Datasheet: + * - Name: 82C54 CHMOS Programmable Interval Timer + * - PDF: http://www.intel.com/design/archives/periphrl/docs/23124406.pdf + * - Order number: 231244-006 + */ + +#include +#include + +#define I82C54_CONTROL_WORD_REGISTER 0x43 /* Write-only. */ + +#define I82C54_COUNTER0 0x40 +#define I82C54_COUNTER1 0x41 +#define I82C54_COUNTER2 0x42 + +#define PC_SPEAKER_PORT 0x61 + +/** + * Use the PC speaker to create a tone/sound of the specified frequency. + * + * The Intel 82C54 CHMOS Programmable Interval Timer (PIT) provides a + * superset of the functions of the original Intel 8253/8254 PIT. It has + * three programmable counters/timers (counter 0, 1, and 2). Counter 2 can + * be used to generate tones/sounds of various frequencies and duration. + * + * See also: + * - http://en.wikipedia.org/wiki/Pc_speaker + * - http://en.wikipedia.org/wiki/Intel_8253 + * + * @param The frequency of the tone. + */ +void speaker_enable(u16 freq) +{ + /* Select counter 2. Read/write LSB first, then MSB. Use mode 3 + (square wave generator). Use a 16bit binary counter. */ + outb(0xb6, I82C54_CONTROL_WORD_REGISTER); + + /* Set the desired tone frequency. */ + outb((u8)(freq & 0x00ff), I82C54_COUNTER2); /* LSB. */ + outb((u8)(freq >> 8), I82C54_COUNTER2); /* MSB. */ + + /* Enable the PC speaker (set bits 0 and 1). */ + outb(inb(PC_SPEAKER_PORT) | 0x03, PC_SPEAKER_PORT); +} + +/** + * Disable the PC speaker. + */ +void speaker_disable(void) +{ + /* Disable the PC speaker (clear bits 0 and 1). */ + outb(inb(PC_SPEAKER_PORT) & 0xfc, PC_SPEAKER_PORT); +} + +/** + * Use the PC speaker to create a tone/beep of the specified frequency + * and duration. + * + * Wait for a short amount of time after the beep to make it distinguishable + * from the next beep (if any). + * + * @param The frequency of the tone/beep. + * @param The duration of the tone/beep in milliseconds. + */ +void speaker_tone(u16 freq, unsigned int duration) +{ + speaker_enable(freq); + mdelay(duration); + speaker_disable(); + delay(10); +} + +/** + * Use the PC speaker to create a short tone/beep. + */ +void beep_short(void) +{ +#if defined(CONFIG_BEEPS) && (CONFIG_BEEPS == 1) + speaker_tone(1760, 500); /* 1760 == note A6. */ +#endif +} + +/** + * Use the PC speaker to create a long tone/beep. + */ +void beep_long(void) +{ +#if defined(CONFIG_BEEPS) && (CONFIG_BEEPS == 1) + speaker_tone(1760, 2000); /* 1760 == note A6. */ +#endif +} + diff --git a/include/lib.h b/include/lib.h index 1bce5f9eb7..00f8730748 100644 --- a/include/lib.h +++ b/include/lib.h @@ -27,4 +27,7 @@ void udelay(unsigned int usecs); void mdelay(unsigned int msecs); void delay(unsigned int secs); +void beep_short(void); +void beep_long(void); + #endif