2 * This file is part of the coreboot project.
4 * Copyright (C) 2009 coresystems GmbH
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; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <pc80/i8254.h>
22 #include <console/console.h>
24 /* Initialize i8254 timers */
26 void setup_i8254(void)
28 /* Timer 0 (taken from biosemu) */
29 outb(TIMER0_SEL|WORD_ACCESS|MODE3|BINARY_COUNT, TIMER_MODE_PORT);
30 outb(0x00, TIMER0_PORT);
31 outb(0x00, TIMER0_PORT);
34 outb(TIMER1_SEL|LOBYTE_ACCESS|MODE3|BINARY_COUNT, TIMER_MODE_PORT);
35 outb(0x12, TIMER1_PORT);
38 #if defined(CONFIG_UDELAY_TIMER2) && CONFIG_UDELAY_TIMER2
39 static void load_timer2(unsigned int ticks)
41 /* Set up the timer gate, turn off the speaker */
42 outb((inb(PPC_PORTB) & ~PPCB_SPKR) | PPCB_T2GATE, PPC_PORTB);
43 outb(TIMER2_SEL|WORD_ACCESS|MODE0|BINARY_COUNT, TIMER_MODE_PORT);
44 outb(ticks & 0xFF, TIMER2_PORT);
45 outb(ticks >> 8, TIMER2_PORT);
49 void udelay(int usecs)
51 load_timer2((usecs*TICKS_PER_MS)/1000);
52 while ((inb(PPC_PORTB) & PPCB_T2OUT) == 0)