Stefan Reinauer | 67fed69 | 2009-11-05 12:38:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2009 coresystems GmbH |
| 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; version 2 of the License. |
| 9 | * |
| 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. |
Stefan Reinauer | 67fed69 | 2009-11-05 12:38:34 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <arch/io.h> |
| 17 | #include <pc80/i8254.h> |
| 18 | #include <console/console.h> |
| 19 | |
| 20 | /* Initialize i8254 timers */ |
| 21 | |
| 22 | void setup_i8254(void) |
| 23 | { |
| 24 | /* Timer 0 (taken from biosemu) */ |
Paul Menzel | 7580b1a | 2015-06-07 11:11:23 +0200 | [diff] [blame] | 25 | outb(TIMER0_SEL | WORD_ACCESS | MODE3 | BINARY_COUNT, TIMER_MODE_PORT); |
Stefan Reinauer | 67fed69 | 2009-11-05 12:38:34 +0000 | [diff] [blame] | 26 | outb(0x00, TIMER0_PORT); |
| 27 | outb(0x00, TIMER0_PORT); |
| 28 | |
| 29 | /* Timer 1 */ |
Paul Menzel | 7580b1a | 2015-06-07 11:11:23 +0200 | [diff] [blame] | 30 | outb(TIMER1_SEL | LOBYTE_ACCESS | MODE3 | BINARY_COUNT, |
| 31 | TIMER_MODE_PORT); |
Stefan Reinauer | 67fed69 | 2009-11-05 12:38:34 +0000 | [diff] [blame] | 32 | outb(0x12, TIMER1_PORT); |
| 33 | } |
| 34 | |
Stefan Reinauer | 6f42976 | 2012-08-07 14:49:01 -0700 | [diff] [blame] | 35 | #if CONFIG_UDELAY_TIMER2 |
Stefan Reinauer | 67fed69 | 2009-11-05 12:38:34 +0000 | [diff] [blame] | 36 | static void load_timer2(unsigned int ticks) |
| 37 | { |
Paul Menzel | 7580b1a | 2015-06-07 11:11:23 +0200 | [diff] [blame] | 38 | /* Set up the timer gate, turn off the speaker */ |
| 39 | outb((inb(PPC_PORTB) & ~PPCB_SPKR) | PPCB_T2GATE, PPC_PORTB); |
| 40 | outb(TIMER2_SEL | WORD_ACCESS | MODE0 | BINARY_COUNT, TIMER_MODE_PORT); |
| 41 | outb(ticks & 0xFF, TIMER2_PORT); |
| 42 | outb(ticks >> 8, TIMER2_PORT); |
Stefan Reinauer | 67fed69 | 2009-11-05 12:38:34 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Stefan Reinauer | 67fed69 | 2009-11-05 12:38:34 +0000 | [diff] [blame] | 45 | void udelay(int usecs) |
| 46 | { |
Paul Menzel | 7580b1a | 2015-06-07 11:11:23 +0200 | [diff] [blame] | 47 | load_timer2((usecs * TICKS_PER_MS) / 1000); |
| 48 | while ((inb(PPC_PORTB) & PPCB_T2OUT) == 0) |
| 49 | ; |
Stefan Reinauer | 67fed69 | 2009-11-05 12:38:34 +0000 | [diff] [blame] | 50 | } |
| 51 | #endif |