xref: /netbsd-src/sys/dev/ic/comvar.h (revision c2f76ff004a2cb67efe5b12d97bd3ef7fe89e18d)
1 /*	$NetBSD: comvar.h,v 1.71 2010/11/13 15:35:50 uebayasi Exp $	*/
2 
3 /*
4  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Christopher G. Demetriou
17  *	for the NetBSD Project.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include "rnd.h"
34 #include "opt_multiprocessor.h"
35 #include "opt_lockdebug.h"
36 #include "opt_com.h"
37 #include "opt_kgdb.h"
38 
39 #if NRND > 0 && defined(RND_COM)
40 #include <sys/rnd.h>
41 #endif
42 
43 #include <sys/callout.h>
44 #include <sys/timepps.h>
45 #include <sys/mutex.h>
46 #include <sys/device.h>
47 
48 #include <dev/ic/comreg.h>	/* for COM_NPORTS */
49 
50 struct com_regs;
51 
52 int comcnattach(bus_space_tag_t, bus_addr_t, int, int, int, tcflag_t);
53 int comcnattach1(struct com_regs *, int, int, int, tcflag_t);
54 
55 #ifdef KGDB
56 int com_kgdb_attach(bus_space_tag_t, bus_addr_t, int, int, int, tcflag_t);
57 int com_kgdb_attach1(struct com_regs *, int, int, int, tcflag_t);
58 #endif
59 
60 int com_is_console(bus_space_tag_t, bus_addr_t, bus_space_handle_t *);
61 
62 /* Hardware flag masks */
63 #define	COM_HW_NOIEN	0x01
64 #define	COM_HW_FIFO	0x02
65 		/*	0x04	free for use */
66 #define	COM_HW_FLOW	0x08
67 #define	COM_HW_DEV_OK	0x20
68 #define	COM_HW_CONSOLE	0x40
69 #define	COM_HW_KGDB	0x80
70 #define	COM_HW_TXFIFO_DISABLE	0x100
71 #define	COM_HW_NO_TXPRELOAD	0x200
72 
73 /* Buffer size for character buffer */
74 #ifndef COM_RING_SIZE
75 #define	COM_RING_SIZE	2048
76 #endif
77 
78 #ifdef	COM_REGMAP
79 #define	COM_REG_RXDATA		0
80 #define	COM_REG_TXDATA		1
81 #define	COM_REG_DLBL		2
82 #define	COM_REG_DLBH		3
83 #define	COM_REG_IER		4
84 #define	COM_REG_IIR		5
85 #define	COM_REG_FIFO		6
86 #define	COM_REG_TCR		6
87 #define	COM_REG_EFR		7
88 #define	COM_REG_TLR		7
89 #define	COM_REG_LCR		8
90 #define	COM_REG_MDR1		8
91 #define	COM_REG_MCR		9
92 #define	COM_REG_LSR		10
93 #define	COM_REG_MSR		11
94 
95 struct com_regs {
96 	bus_space_tag_t		cr_iot;
97 	bus_space_handle_t	cr_ioh;
98 	bus_addr_t		cr_iobase;
99 	bus_size_t		cr_nports;
100 	bus_size_t		cr_map[16];
101 };
102 
103 extern const bus_size_t com_std_map[16];
104 
105 #define	COM_INIT_REGS(regs, tag, hdl, addr)				\
106 	do {								\
107 		regs.cr_iot = tag;					\
108 		regs.cr_ioh = hdl;					\
109 		regs.cr_iobase = addr;					\
110 		regs.cr_nports = COM_NPORTS;				\
111 		memcpy(regs.cr_map, com_std_map, sizeof (regs.cr_map));	\
112 	} while (0)
113 
114 #else
115 #define	COM_REG_RXDATA		com_data
116 #define	COM_REG_TXDATA		com_data
117 #define	COM_REG_DLBL		com_dlbl
118 #define	COM_REG_DLBH		com_dlbh
119 #define	COM_REG_IER		com_ier
120 #define	COM_REG_IIR		com_iir
121 #define	COM_REG_FIFO		com_fifo
122 #define	COM_REG_EFR		com_efr
123 #define	COM_REG_LCR		com_lctl
124 #define	COM_REG_MCR		com_mcr
125 #define	COM_REG_LSR		com_lsr
126 #define	COM_REG_MSR		com_msr
127 #define	COM_REG_TCR		com_msr
128 #define	COM_REG_TLR		com_scratch
129 #define	COM_REG_MDR1		8
130 
131 struct com_regs {
132 	bus_space_tag_t		cr_iot;
133 	bus_space_handle_t	cr_ioh;
134 	bus_addr_t		cr_iobase;
135 	bus_size_t		cr_nports;
136 };
137 
138 #define	COM_INIT_REGS(regs, tag, hdl, addr)		\
139 	do {						\
140 		regs.cr_iot = tag;			\
141 		regs.cr_ioh = hdl;			\
142 		regs.cr_iobase = addr;			\
143 		regs.cr_nports = COM_NPORTS;		\
144 	} while (0)
145 
146 #endif
147 
148 struct comcons_info {
149 	struct com_regs regs;
150 	int rate;
151 	int frequency;
152 	int type;
153 	tcflag_t cflag;
154 };
155 
156 struct com_softc {
157 	device_t sc_dev;
158 	void *sc_si;
159 	struct tty *sc_tty;
160 
161 	struct callout sc_diag_callout;
162 
163 	int sc_frequency;
164 
165 	struct com_regs sc_regs;
166 	bus_space_handle_t sc_hayespioh;
167 
168 
169 	u_int sc_overflows,
170 	      sc_floods,
171 	      sc_errors;
172 
173 	int sc_hwflags,
174 	    sc_swflags;
175 	u_int sc_fifolen;
176 
177 	u_int sc_r_hiwat,
178 	      sc_r_lowat;
179 	u_char *volatile sc_rbget,
180 	       *volatile sc_rbput;
181  	volatile u_int sc_rbavail;
182 	u_char *sc_rbuf,
183 	       *sc_ebuf;
184 
185  	u_char *sc_tba;
186  	u_int sc_tbc,
187 	      sc_heldtbc;
188 
189 	volatile u_char sc_rx_flags,
190 #define	RX_TTY_BLOCKED		0x01
191 #define	RX_TTY_OVERFLOWED	0x02
192 #define	RX_IBUF_BLOCKED		0x04
193 #define	RX_IBUF_OVERFLOWED	0x08
194 #define	RX_ANY_BLOCK		0x0f
195 			sc_tx_busy,
196 			sc_tx_done,
197 			sc_tx_stopped,
198 			sc_st_check,
199 			sc_rx_ready;
200 
201 	volatile u_char sc_heldchange;
202 	volatile u_char sc_msr, sc_msr_delta, sc_msr_mask, sc_mcr,
203 	    sc_mcr_active, sc_lcr, sc_ier, sc_fifo, sc_dlbl, sc_dlbh, sc_efr;
204 	u_char sc_mcr_dtr, sc_mcr_rts, sc_msr_cts, sc_msr_dcd;
205 
206 #ifdef COM_HAYESP
207 	u_char sc_prescaler;
208 #endif
209 
210 	/*
211 	 * There are a great many almost-ns16550-compatible UARTs out
212 	 * there, which have minor differences.  The type field here
213 	 * lets us distinguish between them.
214 	 */
215 	int sc_type;
216 #define	COM_TYPE_NORMAL		0	/* normal 16x50 */
217 #define	COM_TYPE_HAYESP		1	/* Hayes ESP modem */
218 #define	COM_TYPE_PXA2x0		2	/* Intel PXA2x0 processor built-in */
219 #define	COM_TYPE_AU1x00		3	/* AMD/Alchemy Au1x000 proc. built-in */
220 #define	COM_TYPE_OMAP		4	/* TI OMAP processor built-in */
221 #define	COM_TYPE_16550_NOERS	5	/* like a 16550, no ERS */
222 
223 	/* power management hooks */
224 	int (*enable)(struct com_softc *);
225 	void (*disable)(struct com_softc *);
226 	int enabled;
227 
228 	struct pps_state sc_pps_state;	/* pps state */
229 
230 #if NRND > 0 && defined(RND_COM)
231 	rndsource_element_t  rnd_source;
232 #endif
233 	kmutex_t		sc_lock;
234 };
235 
236 int comprobe1(bus_space_tag_t, bus_space_handle_t);
237 int comintr(void *);
238 void com_attach_subr(struct com_softc *);
239 int com_probe_subr(struct com_regs *);
240 int com_detach(device_t, int);
241 bool com_resume(device_t, const pmf_qual_t *);
242 bool com_cleanup(device_t, int);
243 bool com_suspend(device_t, const pmf_qual_t *);
244 
245 #ifndef IPL_SERIAL
246 #define	IPL_SERIAL	IPL_TTY
247 #define	splserial()	spltty()
248 #endif
249