/*
 * Copyright (c) 1996-2003 MIPS Technologies, Inc.
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above
 *      copyright
 *        notice, this list of conditions and the following disclaimer
 *        in the documentation and/or other materials provided with
 *        the distribution.
 *      * Neither the name of MIPS Technologies Inc. nor the names of its
 *        contributors may be used to endorse or promote products derived
 *        from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * i8254.h: Definitions for RS385 i8254 programmable interval timer
 */


/*
 * Counter0 is used as timer #0
 * Counter1 is used as timer #1
 * Counter2 is prescaler
 */

#define PT_TIMER0	0
#define PT_TIMER1	1
#define PT_PRESCALER	2

#ifndef __ASSEMBLER__
struct i8254 {
    	unsigned int	pt_counter0;
    	unsigned int	pt_counter1;
    	unsigned int	pt_counter2;
    	unsigned int	pt_control;
    	unsigned int	pt_cint0ack;
    	unsigned int	pt_cint1ack;
};

#define pt_timer0	pt_counter0
#define pt_timer1	pt_counter1
#define pt_prescaler	pt_counter2
#define pt_t0ack	pt_cint0ack
#define pt_t1act	pt_cint1ack

#else

#define PT_REG(x)	((x) * 4)

#endif

/*
 * control word definitions
 */
#define	PTCW_RBCMD	(3<<6)		/* read-back command */
 #define  PTCW_RB_NCNT	 0x20		   /* rb: no count */
 #define  PTCW_RB_NSTAT	 0x10		   /* rb: no status */
 #define  PTCW_RB_SC(x)	 (0x02<<(x))	   /* rb: select counter x */
#define	PTCW_SC(x)	((x)<<6)	/* select counter x */
#define	PTCW_CLCMD	(0<<4)		/* counter latch command */
#define	PTCW_LSB	(1<<4)		/* r/w least signif. byte only */
#define	PTCW_MSB	(2<<4)		/* r/w most signif. byte only */
#define	PTCW_16B	(3<<4)		/* r/w 16 bits, lsb then msb */
#define	PTCW_MODE(x)	((x)<<1)	/* set mode to x */
#define	PTCW_BCD	0x1		/* operate in BCD mode */

/*
 * Status word definitions
 */
#define PTSW_OUTPUT	0x80		/* output pin active */
#define PTSW_NULL	0x40		/* null count */

/*
 * Mode definitions
 */
#define	MODE_ITC	0		/* interrupt on terminal count */
#define	MODE_HROS	1		/* hw retriggerable one-shot */
#define	MODE_RG		2		/* rate generator */
#define	MODE_SQW	3		/* square wave generator */
#define	MODE_STS	4		/* software triggered strobe */
#define	MODE_HTS	5		/* hardware triggered strobe */

#define PT_CRYSTAL	3686400		/* timer crystal hz (ticks/sec) */
