1/*	$NetBSD: pcl720.h,v 1.1.1.1 2009/12/13 16:54:57 kardel Exp $	*/
2
3/* Copyright (c) 1995 Vixie Enterprises
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies, and that
8 * the name of Vixie Enterprises not be used in advertising or publicity
9 * pertaining to distribution of the document or software without specific,
10 * written prior permission.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND VIXIE ENTERPRISES DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
14 * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL VIXIE ENTERPRISES
15 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
16 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
18 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
19 * SOFTWARE.
20 */
21
22#ifndef _PCL720_DEFINED
23#define _PCL720_DEFINED
24
25#define	pcl720_data(base,bit)	(base+(bit>>3))
26#define pcl720_data_0_7(base)	(base+0)
27#define pcl720_data_8_15(base)	(base+1)
28#define pcl720_data_16_23(base)	(base+2)
29#define pcl720_data_24_31(base)	(base+3)
30#define pcl720_cntr(base,cntr)	(base+4+cntr)	/* cntr: 0..2 */
31#define pcl720_cntr_0(base)	(base+4)
32#define pcl720_cntr_1(base)	(base+5)
33#define pcl720_cntr_2(base)	(base+6)
34#define pcl720_ctrl(base)	(base+7)
35
36#ifndef DEBUG_PCL720
37#define	pcl720_inb(x)		inb(x)
38#define	pcl720_outb(x,y)	outb(x,y)
39#else
40static unsigned char pcl720_inb(int addr) {
41	unsigned char x = inb(addr);
42	fprintf(DEBUG_PCL720, "inb(0x%x) -> 0x%x\n", addr, x);
43	return (x);
44}
45static void pcl720_outb(int addr, unsigned char x) {
46	outb(addr, x);
47	fprintf(DEBUG_PCL720, "outb(0x%x, 0x%x)\n", addr, x);
48}
49#endif
50
51#define	pcl720_load(Base,Cntr,Mode,Val) \
52	({	register unsigned int	b = Base, c = Cntr, v = Val; \
53		i8253_ctrl ctrl; \
54		\
55		ctrl.s.bcd = i8253_binary; \
56		ctrl.s.mode = Mode; \
57		ctrl.s.rl = i8253_lmb; \
58		ctrl.s.cntr = c; \
59		pcl720_outb(pcl720_ctrl(b), ctrl.i); \
60		pcl720_outb(pcl720_cntr(b,c), v); \
61		pcl720_outb(pcl720_cntr(b,c), v >> 8); \
62		v; \
63	})
64
65#define	pcl720_read(Base,Cntr) \
66	({	register unsigned int	b = Base, v; \
67		i8253_ctrl ctrl; \
68		\
69		ctrl.s.rl = i8253_latch; \
70		ctrl.s.cntr = i8253_cntr_0; \
71		pcl720_outb(pcl720_ctrl(b), ctrl.i); \
72		v = pcl720_inb(pcl720_cntr_0(b)); \
73		v |= (pcl720_inb(pcl720_cntr_0(b)) << 8); \
74		v; \
75	})
76
77#define	pcl720_input(Base) \
78	({	register unsigned int	b = Base, v; \
79		\
80		v = pcl720_inb(pcl720_data_0_7(b)); \
81		v |= (pcl720_inb(pcl720_data_8_15(b)) << 8); \
82		v |= (pcl720_inb(pcl720_data_16_23(b)) << 16); \
83		v |= (pcl720_inb(pcl720_data_24_31(b)) << 24); \
84		v; \
85	})
86
87#define	pcl720_output(Base,Value) \
88	({	register unsigned int	b = Base, v = Value; \
89		\
90		pcl720_outb(pcl720_data_0_7(b), v); \
91		pcl720_outb(pcl720_data_8_15(b), v << 8); \
92		pcl720_outb(pcl720_data_16_23(b), v << 16); \
93		pcl720_outb(pcl720_data_24_31(b), v << 24); \
94		v; \
95	})
96
97#endif /*_PCL720_DEFINED*/
98