/*
 * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. 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.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
 *
 *	@(#)dcareg.h	7.3 (Berkeley) 5/7/91
 *
 *    - modified to ql.h by zik 93/12/07
 */

#define	NUMLINES 7		/* number of lines per card */
#define	IOBUFLEN 256		/* number of bytes per buffer */
#define	IOBUFLENMASK 0xff	/* mask for maximum number of bytes */
#define IOBUFHIGHWATER 192	/* point at which to enable output */
#define IOBUFLOWWATER 128	/* point at which to wake output */

#define QL_VBL_PRIORITY 1	/* priority of vbl interrupt handler */

struct qlstatus
    {
    u_char InHead;	/* input queue head - note no tail */
    u_char InEvent;	/* event on input (one of QLEVENT_) */
    u_char InSync;	/* input character to wake client */
    u_char OutDisable;	/* disables output */
    u_char OutHead;	/* output queue head */
    u_char OutTail;	/* output queue tail */
    u_char OutTandem;	/* soft flow control character to send */
    u_char OutFlush;	/* flushes output buffer */
    u_char Setup;	/* causes reconfiguration */
    u_char Param;	/* parameter byte - see QLPARAM */
    u_char Command;	/* command byte - see QLCMD */
    u_char SoftFlow;	/* enables xon/xoff flow control */
    };

struct qlmemory
{
    struct qlstatus Status[NUMLINES];	/* 0x0000-0x0053 status areas */
    u_char Dummy1[0x01ac];		/* 0x0054-0x01ff */
    u_char OutBuf[NUMLINES][IOBUFLEN];	/* 0x0200-0x08ff output buffers */
    u_char InBuf[NUMLINES][IOBUFLEN];	/* 0x0900-0x0fff input buffers */
    u_char Dummy2[0x2000];		/* 0x1000-0x2fff */
    u_char Code[0x1000];		/* 0x3000-0x3fff code area */
    u_char InterruptAck;		/* 0x4000        interrupt ack */
    u_char Dummy3[0x7fff];		/* 0x4001-0xbfff */
    u_char ResetBoard;			/* 0xc000        reset board & run */
};

struct qldevice
{
    volatile struct qlmemory *board;	/* where the board is located */
    int flags;				/* modem control flags */
    u_char port;			/* which port on the board (0-6) */
    u_char InTail;			/* software tail for in queue */
    u_char active;			/* does this port have hardware? */
    u_char closing;			/* are we flushing before close? */
};

#define	QLEVENT_Break 1		/* break set */
#define	QLEVENT_CarrierOn 2	/* carrier raised */
#define	QLEVENT_CarrierOff 3	/* carrier dropped */
#define	QLEVENT_Sync 4

#define QLCMD_Enable 0x1	/* enable/DTR bit */
#define QLCMD_Close 0x2		/* close the device */
#define QLCMD_Open 0xb		/* open the device */
#define QLCMD_CMask 0xf		/* command mask */
#define QLCMD_RTSOff 0x0  	/* turn off RTS */
#define QLCMD_RTSOn 0x8		/* turn on RTS */
#define QLCMD_Break 0xc		/* transmit a break */
#define QLCMD_RTSMask 0xc	/* mask for RTS stuff */
#define QLCMD_NoParity 0x00	/* don't use parity */
#define QLCMD_OddParity 0x20	/* odd parity */
#define QLCMD_EvenParity 0x60	/* even parity */
#define QLCMD_ParityMask 0xe0	/* parity mask */

#define QLPARAM_B115200 0x0	/* baud rates */
#define QLPARAM_B50 0x1
#define QLPARAM_B75 0x2
#define QLPARAM_B110 0x3
#define QLPARAM_B134 0x4
#define QLPARAM_B150 0x5
#define QLPARAM_B300 0x6
#define QLPARAM_B600 0x7
#define QLPARAM_B1200 0x8
#define QLPARAM_B1800 0x9
#define QLPARAM_B2400 0xa
#define QLPARAM_B3600 0xb
#define QLPARAM_B4800 0xc
#define QLPARAM_B7200 0xd
#define QLPARAM_B9600 0xe
#define QLPARAM_B19200 0xf
#define QLPARAM_BaudMask 0xf	/* baud rate mask */
#define QLPARAM_RcvBaud 0x10	/* enable receive baud rate */
#define QLPARAM_8Bit 0x00	/* numbers of bits */
#define QLPARAM_7Bit 0x20
#define QLPARAM_6Bit 0x40
#define QLPARAM_5Bit 0x60
#define QLPARAM_BitMask 0x60	/* numbers of bits mask */

				/* tty number from device */
#define QLTTY(dev) (minor(dev) & 0x7e)
				/* slot number from device */
#define QLSLOT(dev) ((minor(dev) & 0x7e)>>1)
				/* dialin mode from device */
#define QLDIALIN(dev) (minor(dev) & 0x01)
				/* board number from device */
#define	QLBOARD(dev) ((minor(dev))>>4)
				/* line number from device */
#define	QLLINE(dev) (((minor(dev)) & 0xe)>>1)
				/* number of slots */
#define QLSLOTS ((NQL-1)*8+7)
				/* number of ttys */
#define QLTTYS (QLSLOTS*2)
				/* board number given slot number */
#define QLUNIT(slot) ((slot)>>3)
				/* slot number given unit and line */
#define QLSLOTUL(unit,line) (((unit)<<3)+(line))
				/* tty number given slot */
#define QLTTYSLOT(slot) ((slot)<<1)

#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
