Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / mainboard / technexion / tim5690 / speaker.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2009 Libra Li <libra.li@technexion.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21
22 #ifdef __PRE_RAM__
23
24 #include <arch/cpu.h>
25 #include "southbridge/amd/sb600/sb600.h"
26
27 #else
28
29 #include <arch/io.h>
30 #include <device/pci.h>
31 #include <device/pci_ids.h>
32 #include <../southbridge/amd/sb600/sb600.h>
33 #include <delay.h>
34
35 #endif /* __PRE_RAM__ */
36
37 #include "speaker.h"
38
39 void speaker_init(uint8_t time) {
40    /* SB600 RRG.
41     * Options_0 - RW - 8 bits - [PM_Reg: 60h].
42     * SpkrEn, bit[5]=1b, Setting this bit will configure GPIO2 to be speaker output.
43     */
44 #ifdef __PRE_RAM__
45    pmio_write(0x60, (pmio_read(0x60) | (1<<5)));
46 #else
47    pm_iowrite(0x60, (pm_ioread(0x60) | (1<<5)));
48 #endif /* __PRE_RAM__ */
49
50    /* SB600 RRG.
51     * Tmr1CntrlWord - RW - 8 bits - [IO_Reg: 43h].
52     * ModeSelect, bit[3:1]=011b, Square wave output.
53     * CmmandSelect, bit[5:4]=11b, Read/write least, and then most significant byte.
54     * CounterSelect, bit[7:6]=10b, Select counter 2.
55     */
56    outb(0xb6, 0x43);
57
58
59    /* SB600 RRG.
60     * TimerCh2- RW - 8 bits - [IO_Reg: 42h].
61     */
62    outb(time, 0x42);
63 }
64
65 void speaker_on_nodelay(void) {
66    /* SB600 RRG.
67     * Nmi_Status - RW - 8 bits - [IO_Reg: 61h].
68     * SpkrEnable, bit[0]=1b, Enable counter 2
69     * SpkrTmrEnable, bit[1]=1b, Speaker timer on
70     */
71    outb(inb(0x61) | 0x03, 0x61);
72 }
73
74 void speaker_on_delay(void) {
75    speaker_on_nodelay();
76    mdelay(100);
77 }
78
79 void speaker_off_nodelay(void) {
80    /* SB600 RRG.
81     * Nmi_Status - RW - 8 bits - [IO_Reg: 61h].
82     * SpkrEnable, bit[0]=0b, Disable counter 2
83     * SpkrTmrEnable, bit[1]=0b, Speaker timer off
84     */
85    outb(inb(0x61) & ~0x03, 0x61);
86 }
87
88 void speaker_off_delay(void) {
89    speaker_off_nodelay();
90    mdelay(100);
91 }