pcl720.h revision 82498
154359Sroberto/* Copyright (c) 1995 Vixie Enterprises 254359Sroberto * 354359Sroberto * Permission to use, copy, modify, and distribute this software for any 454359Sroberto * purpose with or without fee is hereby granted, provided that the above 554359Sroberto * copyright notice and this permission notice appear in all copies, and that 654359Sroberto * the name of Vixie Enterprises not be used in advertising or publicity 754359Sroberto * pertaining to distribution of the document or software without specific, 854359Sroberto * written prior permission. 954359Sroberto * 1054359Sroberto * THE SOFTWARE IS PROVIDED "AS IS" AND VIXIE ENTERPRISES DISCLAIMS ALL 1154359Sroberto * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 1254359Sroberto * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VIXIE ENTERPRISES 1354359Sroberto * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES 1454359Sroberto * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 1554359Sroberto * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 1654359Sroberto * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 1754359Sroberto * SOFTWARE. 1854359Sroberto */ 1954359Sroberto 2054359Sroberto#ifndef _PCL720_DEFINED 2154359Sroberto#define _PCL720_DEFINED 2254359Sroberto 2354359Sroberto#define pcl720_data(base,bit) (base+(bit>>3)) 2454359Sroberto#define pcl720_data_0_7(base) (base+0) 2554359Sroberto#define pcl720_data_8_15(base) (base+1) 2654359Sroberto#define pcl720_data_16_23(base) (base+2) 2754359Sroberto#define pcl720_data_24_31(base) (base+3) 2854359Sroberto#define pcl720_cntr(base,cntr) (base+4+cntr) /* cntr: 0..2 */ 2954359Sroberto#define pcl720_cntr_0(base) (base+4) 3054359Sroberto#define pcl720_cntr_1(base) (base+5) 3154359Sroberto#define pcl720_cntr_2(base) (base+6) 3254359Sroberto#define pcl720_ctrl(base) (base+7) 3354359Sroberto 3454359Sroberto#ifndef DEBUG_PCL720 3554359Sroberto#define pcl720_inb(x) inb(x) 3654359Sroberto#define pcl720_outb(x,y) outb(x,y) 3754359Sroberto#else 3854359Srobertostatic unsigned char pcl720_inb(int addr) { 3954359Sroberto unsigned char x = inb(addr); 4054359Sroberto fprintf(DEBUG_PCL720, "inb(0x%x) -> 0x%x\n", addr, x); 4154359Sroberto return (x); 4254359Sroberto} 4354359Srobertostatic void pcl720_outb(int addr, unsigned char x) { 4454359Sroberto outb(addr, x); 4554359Sroberto fprintf(DEBUG_PCL720, "outb(0x%x, 0x%x)\n", addr, x); 4654359Sroberto} 4754359Sroberto#endif 4854359Sroberto 4954359Sroberto#define pcl720_load(Base,Cntr,Mode,Val) \ 5054359Sroberto ({ register unsigned int b = Base, c = Cntr, v = Val; \ 5154359Sroberto i8253_ctrl ctrl; \ 5254359Sroberto \ 5354359Sroberto ctrl.s.bcd = i8253_binary; \ 5454359Sroberto ctrl.s.mode = Mode; \ 5554359Sroberto ctrl.s.rl = i8253_lmb; \ 5654359Sroberto ctrl.s.cntr = c; \ 5754359Sroberto pcl720_outb(pcl720_ctrl(b), ctrl.i); \ 5854359Sroberto pcl720_outb(pcl720_cntr(b,c), v); \ 5954359Sroberto pcl720_outb(pcl720_cntr(b,c), v >> 8); \ 6054359Sroberto v; \ 6154359Sroberto }) 6254359Sroberto 6354359Sroberto#define pcl720_read(Base,Cntr) \ 6482498Sroberto ({ register unsigned int b = Base, v; \ 6554359Sroberto i8253_ctrl ctrl; \ 6654359Sroberto \ 6754359Sroberto ctrl.s.rl = i8253_latch; \ 6854359Sroberto ctrl.s.cntr = i8253_cntr_0; \ 6954359Sroberto pcl720_outb(pcl720_ctrl(b), ctrl.i); \ 7054359Sroberto v = pcl720_inb(pcl720_cntr_0(b)); \ 7154359Sroberto v |= (pcl720_inb(pcl720_cntr_0(b)) << 8); \ 7254359Sroberto v; \ 7354359Sroberto }) 7454359Sroberto 7554359Sroberto#define pcl720_input(Base) \ 7654359Sroberto ({ register unsigned int b = Base, v; \ 7754359Sroberto \ 7854359Sroberto v = pcl720_inb(pcl720_data_0_7(b)); \ 7954359Sroberto v |= (pcl720_inb(pcl720_data_8_15(b)) << 8); \ 8054359Sroberto v |= (pcl720_inb(pcl720_data_16_23(b)) << 16); \ 8154359Sroberto v |= (pcl720_inb(pcl720_data_24_31(b)) << 24); \ 8254359Sroberto v; \ 8354359Sroberto }) 8454359Sroberto 8554359Sroberto#define pcl720_output(Base,Value) \ 8654359Sroberto ({ register unsigned int b = Base, v = Value; \ 8754359Sroberto \ 8854359Sroberto pcl720_outb(pcl720_data_0_7(b), v); \ 8954359Sroberto pcl720_outb(pcl720_data_8_15(b), v << 8); \ 9054359Sroberto pcl720_outb(pcl720_data_16_23(b), v << 16); \ 9154359Sroberto pcl720_outb(pcl720_data_24_31(b), v << 24); \ 9254359Sroberto v; \ 9354359Sroberto }) 9454359Sroberto 9554359Sroberto#endif /*_PCL720_DEFINED*/ 96