On Mon, Nov 23, 2009 at 12:01:26PM +0800, Bao, Zheng wrote: > Should the spkr.c be in the folder sb600, or more public folders like > pc80?
It looks generic to me, I'd put it into lib or src/arch/i386/lib as it might be x86-specific. I wrote a similar function for v3 a while ago, see attached file. Feel free to use that one or merge the best parts of both. svn co svn://coreboot.org/repository/coreboot-v3 File: arch/x86/speaker.c However, in your file spkr.c (please rename to speaker.c for better readability) there is no license header, so we cannot commit it. Please add the usual GPL header and/or reuse my code (if it works, don't remember how much of it was tested in v3). Thanks! Uwe. -- http://www.hermann-uwe.de | http://www.randomprojects.org http://www.crazy-hacks.org | http://www.unmaintained-free-software.org
/* * This file is part of the coreboot project. * * Copyright (C) 2007 Uwe Hermann <[email protected]> * * 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 <io.h> #include <lib.h> #include <legacy.h> #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 freq 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 freq The frequency of the tone/beep. * @param duration 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) { #ifdef CONFIG_BEEPS speaker_tone(1760, 500); /* 1760 == note A6. */ #endif } /** * Use the PC speaker to create a long tone/beep. */ void beep_long(void) { #ifdef CONFIG_BEEPS speaker_tone(1760, 2000); /* 1760 == note A6. */ #endif }
-- coreboot mailing list: [email protected] http://www.coreboot.org/mailman/listinfo/coreboot

