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