1/*	$NetBSD: cd18xxvar.h,v 1.4 2012/10/27 17:18:19 chs Exp $	*/
2
3/*
4 * Copyright (c) 1998, 2001 Matthew R. Green
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29/*
30 * cd18xxvar.h:  header file for cirrus-logic CL-CD180/CD1864/CD1865 8
31 * port serial chip.
32 */
33
34#include <sys/tty.h>
35
36/* allocated per-serial port */
37struct cdtty_port {
38	struct	tty		*p_tty;
39
40	int			p_swflags;	/* TIOCFLAG_SOFTCAR, etc. */
41	int			p_defspeed;	/* default speed */
42	int			p_defcflag;	/* default termios cflag */
43
44	u_int			p_r_hiwat;	/* high water mark */
45	u_int			p_r_lowat;	/* low water mark */
46	u_char *volatile	p_rbget;	/* ring buffer get ptr */
47	u_char *volatile	p_rbput;	/* ring buffer put ptr */
48	volatile u_int		p_rbavail;	/* size available */
49	u_char			*p_rbuf;	/* ring buffer */
50	u_char			*p_ebuf;	/* end of ring buffer */
51
52	u_char *		p_tba;		/* transmit buffer address */
53	u_int			p_tbc,		/* transmit byte count */
54				p_heldtbc;	/* held tbc; waiting for tx */
55#define CDTTY_RING_SIZE	2048
56
57	u_int			p_parityerr,	/* number of parity errors */
58				p_frameerr,	/* number of framing errors */
59				p_overflows,	/* number of overruns */
60				p_floods;	/* number of rbuf floods */
61
62	volatile u_char		p_break,	/* current break status */
63				p_needbreak,	/* need to generate a break */
64				p_rx_flags,	/* software state */
65#define	RX_TTY_BLOCKED		0x01
66#define	RX_TTY_OVERFLOWED	0x02
67#define	RX_IBUF_BLOCKED		0x04
68#define	RX_IBUF_OVERFLOWED	0x08
69#define	RX_ANY_BLOCK		0x0f
70				p_rx_ready,	/* soft rx interrupt ready */
71				p_rx_busy,
72				p_tx_done,	/* soft tx interrupt ready */
73				p_tx_busy,
74				p_tx_stopped,
75				p_st_check,	/* soft modem interrupt ready */
76				p_heldchange;	/* waiting to update regs */
77
78	/*
79	 * cd18xx channel registers we keep a copy of, for writing in
80	 * loadchannelregs().
81	 */
82	u_char			p_srer,		/* service request enable */
83				p_msvr,		/* modem signal value */
84				p_msvr_cts, p_msvr_rts, p_msvr_dcd,
85				p_msvr_mask, p_msvr_active, p_msvr_delta,
86				p_cor1,		/* channel option reg 1 */
87				p_cor2,		/* channel option reg 2 */
88				p_cor3,		/* channel option reg 3 */
89				p_mcor1,	/* modem option reg 1 */
90				p_mcor1_dtr,
91				p_rbprh,	/* recv bps high */
92				p_rbprl,	/* recv bps low */
93				p_tbprh,	/* xmit bps high */
94				p_tbprl,	/* xmit bps low */
95				p_chanctl;	/* chanctl command */
96};
97
98/* softc allocated per-cd18xx */
99struct cd18xx_softc {
100	device_t		sc_dev;
101
102	/* tag and handle for our registers (128 bytes) */
103	bus_space_tag_t		sc_tag;
104	bus_space_handle_t	sc_handle;
105
106	/*
107	 * cd18xx has weird interrupt acknowledgement and configuration,
108	 * so we have to defer this to our parent.  this function must
109	 * do whatever is required to genereate *iack signals that are
110	 * required for the cd180.  this probably also depends on the
111	 * values of the sc_rsmr, sc_tsmr and sc_msmr variables.  the
112	 * function is called with the provided argument, and with any
113	 * of the 4 #defines below, depending on the ack needing to be
114	 * generated.
115	 */
116	u_char			(*sc_ackfunc)(void *, int);
117#define CD18xx_INTRACK_MxINT	0x01		/* modem interrupt */
118#define CD18xx_INTRACK_TxINT	0x02		/* tx interrupt */
119#define CD18xx_INTRACK_RxINT	0x04		/* rx (good data) interrupt */
120#define CD18xx_INTRACK_REINT	0x08		/* rx (exception) interrupt */
121	void			*sc_ackfunc_arg;
122
123	u_char			sc_rsmr;
124	u_char			sc_tsmr;
125	u_char			sc_msmr;
126
127	u_int			sc_osc;
128
129	/*
130	 * everything above here needs to be setup by our caller, and
131	 * everything below here is setup by the generic cd18xx code.
132	 */
133	u_int			sc_chip_id;	/* unique per-cd18xx value */
134	void			*sc_si;		/* softintr(9) cookie */
135
136	struct cdtty_port	sc_ports[8];
137
138	u_char			sc_pprh;
139	u_char			sc_pprl;
140};
141
142/* hard interrupt, to be configured by our caller */
143int cd18xx_hardintr(void *);
144
145/* main attach routine called by the high level driver */
146void cd18xx_attach(struct cd18xx_softc *);
147
148/*
149 * device minor layout has bit 19 for dialout and bits 0..18 for the unit.
150 * the first 3 bits of the unit are the channel number inside a single
151 * cd18xx instance, and the remaining bits indicate the instance number.
152 */
153#define CD18XX_TTY(x)		TTUNIT(x)
154#define CD18XX_CHANNEL(x)	(TTUNIT(x) & 7)
155#define CD18XX_INSTANCE(x)	(TTUNIT(x) >> 3)
156#define CD18XX_DIALOUT(x)	TTDIALOUT(x)
157
158/* short helpers for read/write */
159#define cd18xx_read(sc, o)		\
160	bus_space_read_1((sc)->sc_tag, (sc)->sc_handle, o)
161#define cd18xx_read_multi(sc, o, b, c)	\
162	bus_space_read_multi_1((sc)->sc_tag, (sc)->sc_handle, o, b, c)
163
164#define cd18xx_write(sc, o, v)		\
165	bus_space_write_1((sc)->sc_tag, (sc)->sc_handle, o, v)
166#define cd18xx_write_multi(sc, o, b, c)	\
167	bus_space_write_multi_1((sc)->sc_tag, (sc)->sc_handle, o, b, c)
168
169/* set the current channel */
170#define cd18xx_set_car(sc, c)		\
171do { \
172	bus_space_write_1((sc)->sc_tag, (sc)->sc_handle, CD18xx_CAR, c); \
173	delay(1); \
174} while (0)
175
176/* get the current channel */
177#define cd18xx_get_gscr1_channel(sc)	\
178	((bus_space_read_1((sc)->sc_tag, (sc)->sc_handle, CD18xx_GSCR1) >> 2)&7)
179