1c8fe38aeSMatthew Dillon /*- 2c8fe38aeSMatthew Dillon * Copyright (c) 1993 The Regents of the University of California. 3c8fe38aeSMatthew Dillon * Copyright (c) 2008 The DragonFly Project. 4c8fe38aeSMatthew Dillon * All rights reserved. 5c8fe38aeSMatthew Dillon * 6c8fe38aeSMatthew Dillon * Redistribution and use in source and binary forms, with or without 7c8fe38aeSMatthew Dillon * modification, are permitted provided that the following conditions 8c8fe38aeSMatthew Dillon * are met: 9c8fe38aeSMatthew Dillon * 1. Redistributions of source code must retain the above copyright 10c8fe38aeSMatthew Dillon * notice, this list of conditions and the following disclaimer. 11c8fe38aeSMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright 12c8fe38aeSMatthew Dillon * notice, this list of conditions and the following disclaimer in the 13c8fe38aeSMatthew Dillon * documentation and/or other materials provided with the distribution. 14*2c64e990Szrj * 3. Neither the name of the University nor the names of its contributors 15c8fe38aeSMatthew Dillon * may be used to endorse or promote products derived from this software 16c8fe38aeSMatthew Dillon * without specific prior written permission. 17c8fe38aeSMatthew Dillon * 18c8fe38aeSMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19c8fe38aeSMatthew Dillon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20c8fe38aeSMatthew Dillon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21c8fe38aeSMatthew Dillon * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22c8fe38aeSMatthew Dillon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23c8fe38aeSMatthew Dillon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24c8fe38aeSMatthew Dillon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25c8fe38aeSMatthew Dillon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26c8fe38aeSMatthew Dillon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27c8fe38aeSMatthew Dillon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28c8fe38aeSMatthew Dillon * SUCH DAMAGE. 29c8fe38aeSMatthew Dillon * 30c8fe38aeSMatthew Dillon * from: Header: timerreg.h,v 1.2 93/02/28 15:08:58 mccanne Exp 31c8fe38aeSMatthew Dillon * $FreeBSD: src/sys/i386/isa/timerreg.h,v 1.6 1999/08/28 00:45:04 peter Exp $ 32c8fe38aeSMatthew Dillon * $DragonFly: src/sys/platform/pc64/isa/timerreg.h,v 1.1 2008/08/29 17:07:20 dillon Exp $ 33c8fe38aeSMatthew Dillon */ 34c8fe38aeSMatthew Dillon 35c8fe38aeSMatthew Dillon /* 36c8fe38aeSMatthew Dillon * 37c8fe38aeSMatthew Dillon * Register definitions for the Intel 8253 Programmable Interval Timer. 38c8fe38aeSMatthew Dillon * 39c8fe38aeSMatthew Dillon * This chip has three independent 16-bit down counters that can be 40c8fe38aeSMatthew Dillon * read on the fly. There are three mode registers and three countdown 41c8fe38aeSMatthew Dillon * registers. The countdown registers are addressed directly, via the 42c8fe38aeSMatthew Dillon * first three I/O ports. The three mode registers are accessed via 43c8fe38aeSMatthew Dillon * the fourth I/O port, with two bits in the mode byte indicating the 44c8fe38aeSMatthew Dillon * register. (Why are hardware interfaces always so braindead?). 45c8fe38aeSMatthew Dillon * 46c8fe38aeSMatthew Dillon * To write a value into the countdown register, the mode register 47c8fe38aeSMatthew Dillon * is first programmed with a command indicating the which byte of 48c8fe38aeSMatthew Dillon * the two byte register is to be modified. The three possibilities 49c8fe38aeSMatthew Dillon * are load msb (TMR_MR_MSB), load lsb (TMR_MR_LSB), or load lsb then 50c8fe38aeSMatthew Dillon * msb (TMR_MR_BOTH). 51c8fe38aeSMatthew Dillon * 52c8fe38aeSMatthew Dillon * To read the current value ("on the fly") from the countdown register, 53c8fe38aeSMatthew Dillon * you write a "latch" command into the mode register, then read the stable 54c8fe38aeSMatthew Dillon * value from the corresponding I/O port. For example, you write 55c8fe38aeSMatthew Dillon * TMR_MR_LATCH into the corresponding mode register. Presumably, 56c8fe38aeSMatthew Dillon * after doing this, a write operation to the I/O port would result 57c8fe38aeSMatthew Dillon * in undefined behavior (but hopefully not fry the chip). 58c8fe38aeSMatthew Dillon * Reading in this manner has no side effects. 59c8fe38aeSMatthew Dillon * 60c8fe38aeSMatthew Dillon * [IBM-PC] 61c8fe38aeSMatthew Dillon * The outputs of the three timers are connected as follows: 62c8fe38aeSMatthew Dillon * 63c8fe38aeSMatthew Dillon * timer 0 -> irq 0 64c8fe38aeSMatthew Dillon * timer 1 -> dma chan 0 (for dram refresh) 65c8fe38aeSMatthew Dillon * timer 2 -> speaker (via keyboard controller) 66c8fe38aeSMatthew Dillon * 67c8fe38aeSMatthew Dillon * Timer 0 is used to call hardclock. 68c8fe38aeSMatthew Dillon * Timer 2 is used to generate console beeps. 69c8fe38aeSMatthew Dillon * 70c8fe38aeSMatthew Dillon * [PC-9801] 71c8fe38aeSMatthew Dillon * The outputs of the three timers are connected as follows: 72c8fe38aeSMatthew Dillon * 73c8fe38aeSMatthew Dillon * timer 0 -> irq 0 74c8fe38aeSMatthew Dillon * timer 1 -> speaker (via keyboard controller) 75c8fe38aeSMatthew Dillon * timer 2 -> RS232C 76c8fe38aeSMatthew Dillon * 77c8fe38aeSMatthew Dillon * Timer 0 is used to call hardclock. 78c8fe38aeSMatthew Dillon * Timer 1 is used to generate console beeps. 79c8fe38aeSMatthew Dillon * 80c8fe38aeSMatthew Dillon * TIMER_INTTC: Interrupt on Terminal Count. OUT initially low, 81c8fe38aeSMatthew Dillon * goes high on terminal count and remains 82c8fe38aeSMatthew Dillon * high until a new count or a mode 0 control 83c8fe38aeSMatthew Dillon * word is written. 84c8fe38aeSMatthew Dillon * 85c8fe38aeSMatthew Dillon * TIMER_ONESHOT: Hardware Retriggerable One Shot. Out initially high, 86c8fe38aeSMatthew Dillon * out goes low following the trigger and remains low 87c8fe38aeSMatthew Dillon * until terminal count, then goes high and remains 88c8fe38aeSMatthew Dillon * high until the next trigger. 89c8fe38aeSMatthew Dillon * 90c8fe38aeSMatthew Dillon * TIMER_RATEGEN: Rate Generator. OUT is initially high. When the 91c8fe38aeSMatthew Dillon * count has decremented to 1 OUT goes low for one CLK 92c8fe38aeSMatthew Dillon * pulse, then goes high again. Counter reloads and 93c8fe38aeSMatthew Dillon * the sequence is repeated. 94c8fe38aeSMatthew Dillon * 95c8fe38aeSMatthew Dillon * TIMER_SQWAVE: Square Wave Generator. OUT is initially high. When 96c8fe38aeSMatthew Dillon * half the count is expired, OUT goes low. Counter 97c8fe38aeSMatthew Dillon * reloads, OUT goes high, and the sequence repepats. 98c8fe38aeSMatthew Dillon * 99c8fe38aeSMatthew Dillon * TIMER_SWSTROBE: S/W Triggered Strobe. OUT initially high. On 100c8fe38aeSMatthew Dillon * terminal count OUT goes low for one CLK pulse 101c8fe38aeSMatthew Dillon * and then goes high again. Counting stops. 102c8fe38aeSMatthew Dillon * The counting sequence is 'triggered' by writing 103c8fe38aeSMatthew Dillon * the initial count. Writing a control word and 104c8fe38aeSMatthew Dillon * initial count resets and reloads the counter. 105c8fe38aeSMatthew Dillon * 106c8fe38aeSMatthew Dillon * TIMER_HWSTROBE: H/W Triggered Strobe. OUT initially high. A rising 107c8fe38aeSMatthew Dillon * edge on GATE loads the counter and counting begins. 108c8fe38aeSMatthew Dillon * On terminal count OUT goes low for one CLK and then 109c8fe38aeSMatthew Dillon * high again. 110c8fe38aeSMatthew Dillon * 111c8fe38aeSMatthew Dillon * NOTE: the largest possible initial count is 0x0000. This is equivalent 112c8fe38aeSMatthew Dillon * to 2^16 binary and 10^4 BCD counts. The counter does not stop when it 113c8fe38aeSMatthew Dillon * reaches zero. In Modes INTTC, ONESHOT, SWSTROBE, and HWSTROBE the 114c8fe38aeSMatthew Dillon * counter wraps aroudn to the highest count (0xFFFF or 9999bcd) and 115c8fe38aeSMatthew Dillon * continues counting. In MODES RATEGEN and SQWAVE (which are periodic) 116c8fe38aeSMatthew Dillon * the counter reloads itself with the initial count and continues counting 117c8fe38aeSMatthew Dillon * from there. 118c8fe38aeSMatthew Dillon */ 119c8fe38aeSMatthew Dillon 120c8fe38aeSMatthew Dillon /* 121c8fe38aeSMatthew Dillon * Macros for specifying values to be written into a mode register. 122c8fe38aeSMatthew Dillon */ 123c8fe38aeSMatthew Dillon #define TIMER_CNTR0 (IO_TIMER1 + 0) /* timer 0 counter port */ 124c8fe38aeSMatthew Dillon #define TIMER_CNTR1 (IO_TIMER1 + 1) /* timer 1 counter port */ 125c8fe38aeSMatthew Dillon #define TIMER_CNTR2 (IO_TIMER1 + 2) /* timer 2 counter port */ 126c8fe38aeSMatthew Dillon #define TIMER_MODE (IO_TIMER1 + 3) /* timer mode port */ 127c8fe38aeSMatthew Dillon #define TIMER_SEL0 0x00 /* select counter 0 */ 128c8fe38aeSMatthew Dillon #define TIMER_SEL1 0x40 /* select counter 1 */ 129c8fe38aeSMatthew Dillon #define TIMER_SEL2 0x80 /* select counter 2 */ 130c8fe38aeSMatthew Dillon #define TIMER_INTTC 0x00 /* mode 0, intr on terminal cnt */ 131c8fe38aeSMatthew Dillon #define TIMER_ONESHOT 0x02 /* mode 1, one shot */ 132c8fe38aeSMatthew Dillon #define TIMER_RATEGEN 0x04 /* mode 2, rate generator */ 133c8fe38aeSMatthew Dillon #define TIMER_SQWAVE 0x06 /* mode 3, square wave */ 134c8fe38aeSMatthew Dillon #define TIMER_SWSTROBE 0x08 /* mode 4, s/w triggered strobe */ 135c8fe38aeSMatthew Dillon #define TIMER_HWSTROBE 0x0a /* mode 5, h/w triggered strobe */ 136c8fe38aeSMatthew Dillon #define TIMER_LATCH 0x00 /* latch counter for reading */ 137c8fe38aeSMatthew Dillon #define TIMER_LSB 0x10 /* r/w counter LSB */ 138c8fe38aeSMatthew Dillon #define TIMER_MSB 0x20 /* r/w counter MSB */ 139c8fe38aeSMatthew Dillon #define TIMER_16BIT 0x30 /* r/w counter 16 bits, LSB first */ 140c8fe38aeSMatthew Dillon #define TIMER_BCD 0x01 /* count in BCD */ 141c8fe38aeSMatthew Dillon 142