15b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project/* Defines for routines to implement a low-overhead timer for drivers */
25b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
35b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project /*
45b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project * This program is free software; you can redistribute it and/or
55b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project * modify it under the terms of the GNU General Public License as
65b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project * published by the Free Software Foundation; either version 2, or (at
75b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project * your option) any later version.
85b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project */
95b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
105b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#ifndef	TIMER_H
115b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define TIMER_H
125b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
135b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project/* Ports for the 8254 timer chip */
145b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	TIMER2_PORT	0x42
155b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	TIMER_MODE_PORT	0x43
165b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
175b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project/* Meaning of the mode bits */
185b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	TIMER0_SEL	0x00
195b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	TIMER1_SEL	0x40
205b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	TIMER2_SEL	0x80
215b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	READBACK_SEL	0xC0
225b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
235b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	LATCH_COUNT	0x00
245b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	LOBYTE_ACCESS	0x10
255b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	HIBYTE_ACCESS	0x20
265b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	WORD_ACCESS	0x30
275b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
285b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	MODE0		0x00
295b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	MODE1		0x02
305b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	MODE2		0x04
315b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	MODE3		0x06
325b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	MODE4		0x08
335b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	MODE5		0x0A
345b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
355b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	BINARY_COUNT	0x00
365b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	BCD_COUNT	0x01
375b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
385b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project/* Timers tick over at this rate */
395b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	TICKS_PER_MS	1193
405b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
415b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project/* Parallel Peripheral Controller Port B */
425b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	PPC_PORTB	0x61
435b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
445b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project/* Meaning of the port bits */
455b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	PPCB_T2OUT	0x20	/* Bit 5 */
465b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	PPCB_SPKR	0x02	/* Bit 1 */
475b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#define	PPCB_T2GATE	0x01	/* Bit 0 */
485b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
495b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project/* Ticks must be between 0 and 65535 (0 == 65536)
505b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project   because it is a 16 bit counter */
515b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Projectextern void load_timer2(unsigned int ticks);
525b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Projectextern inline int timer2_running(void)
535b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project{
545b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project	return ((inb(PPC_PORTB) & PPCB_T2OUT) == 0);
555b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project}
565b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
575b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Projectextern inline void waiton_timer2(unsigned int ticks)
585b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project{
595b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project	load_timer2(ticks);
605b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project	while ((inb(PPC_PORTB) & PPCB_T2OUT) == 0)
615b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project		;
625b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project}
635b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project
645b1eb061628a97aae48a9c0bcaa96eb0bfa07aa4The Android Open Source Project#endif	/* TIMER_H */
65