xref: /netbsd-src/sys/dev/ic/comvar.h (revision 63aea4bd5b445e491ff0389fe27ec78b3099dba3)
1 /*	$NetBSD: comvar.h,v 1.81 2015/05/03 17:22:54 jmcneill 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 "opt_multiprocessor.h"
34 #include "opt_lockdebug.h"
35 #include "opt_com.h"
36 #include "opt_kgdb.h"
37 
38 #ifdef RND_COM
39 #include <sys/rndsource.h>
40 #endif
41 
42 #include <sys/callout.h>
43 #include <sys/timepps.h>
44 #include <sys/mutex.h>
45 #include <sys/device.h>
46 
47 #include <dev/ic/comreg.h>	/* for COM_NPORTS */
48 
49 struct com_regs;
50 
51 int comcnattach(bus_space_tag_t, bus_addr_t, int, int, int, tcflag_t);
52 int comcnattach1(struct com_regs *, int, int, int, tcflag_t);
53 
54 #ifdef KGDB
55 int com_kgdb_attach(bus_space_tag_t, bus_addr_t, int, int, int, tcflag_t);
56 int com_kgdb_attach1(struct com_regs *, int, int, int, tcflag_t);
57 #endif
58 
59 int com_is_console(bus_space_tag_t, bus_addr_t, bus_space_handle_t *);
60 
61 /* Hardware flag masks */
62 #define	COM_HW_NOIEN	0x01
63 #define	COM_HW_FIFO	0x02
64 		/*	0x04	free for use */
65 #define	COM_HW_FLOW	0x08
66 #define	COM_HW_DEV_OK	0x20
67 #define	COM_HW_CONSOLE	0x40
68 #define	COM_HW_KGDB	0x80
69 #define	COM_HW_TXFIFO_DISABLE	0x100
70 #define	COM_HW_NO_TXPRELOAD	0x200
71 #define	COM_HW_AFE	0x400
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 #ifdef	COM_16750
95 #define	COM_REG_USR		31
96 #endif
97 
98 struct com_regs {
99 	bus_space_tag_t		cr_iot;
100 	bus_space_handle_t	cr_ioh;
101 	bus_addr_t		cr_iobase;
102 	bus_size_t		cr_nports;
103 #ifdef COM_16750
104 	bus_size_t		cr_map[32];
105 #else
106 	bus_size_t		cr_map[16];
107 #endif
108 };
109 
110 #ifdef COM_16750
111 extern const bus_size_t com_std_map[32];
112 #else
113 extern const bus_size_t com_std_map[16];
114 #endif
115 
116 #define	COM_INIT_REGS(regs, tag, hdl, addr)				\
117 	do {								\
118 		regs.cr_iot = tag;					\
119 		regs.cr_ioh = hdl;					\
120 		regs.cr_iobase = addr;					\
121 		regs.cr_nports = COM_NPORTS;				\
122 		memcpy(regs.cr_map, com_std_map, sizeof (regs.cr_map));	\
123 	} while (0)
124 
125 #else
126 #define	COM_REG_RXDATA		com_data
127 #define	COM_REG_TXDATA		com_data
128 #define	COM_REG_DLBL		com_dlbl
129 #define	COM_REG_DLBH		com_dlbh
130 #define	COM_REG_IER		com_ier
131 #define	COM_REG_IIR		com_iir
132 #define	COM_REG_FIFO		com_fifo
133 #define	COM_REG_EFR		com_efr
134 #define	COM_REG_LCR		com_lctl
135 #define	COM_REG_MCR		com_mcr
136 #define	COM_REG_LSR		com_lsr
137 #define	COM_REG_MSR		com_msr
138 #define	COM_REG_TCR		com_msr
139 #define	COM_REG_TLR		com_scratch
140 #define	COM_REG_MDR1		8
141 #ifdef	COM_16750
142 #define COM_REG_USR		com_usr
143 #endif
144 
145 struct com_regs {
146 	bus_space_tag_t		cr_iot;
147 	bus_space_handle_t	cr_ioh;
148 	bus_addr_t		cr_iobase;
149 	bus_size_t		cr_nports;
150 };
151 
152 #define	COM_INIT_REGS(regs, tag, hdl, addr)		\
153 	do {						\
154 		regs.cr_iot = tag;			\
155 		regs.cr_ioh = hdl;			\
156 		regs.cr_iobase = addr;			\
157 		regs.cr_nports = COM_NPORTS;		\
158 	} while (0)
159 
160 #endif
161 
162 struct comcons_info {
163 	struct com_regs regs;
164 	int rate;
165 	int frequency;
166 	int type;
167 	tcflag_t cflag;
168 };
169 
170 struct com_softc {
171 	device_t sc_dev;
172 	void *sc_si;
173 	struct tty *sc_tty;
174 
175 	struct callout sc_diag_callout;
176 
177 	int sc_frequency;
178 
179 	struct com_regs sc_regs;
180 	bus_space_handle_t sc_hayespioh;
181 
182 
183 	u_int sc_overflows,
184 	      sc_floods,
185 	      sc_errors;
186 
187 	int sc_hwflags,
188 	    sc_swflags;
189 	u_int sc_fifolen;
190 
191 	u_int sc_r_hiwat,
192 	      sc_r_lowat;
193 	u_char *volatile sc_rbget,
194 	       *volatile sc_rbput;
195  	volatile u_int sc_rbavail;
196 	u_char *sc_rbuf,
197 	       *sc_ebuf;
198 
199  	u_char *sc_tba;
200  	u_int sc_tbc,
201 	      sc_heldtbc;
202 
203 	volatile u_char sc_rx_flags,
204 #define	RX_TTY_BLOCKED		0x01
205 #define	RX_TTY_OVERFLOWED	0x02
206 #define	RX_IBUF_BLOCKED		0x04
207 #define	RX_IBUF_OVERFLOWED	0x08
208 #define	RX_ANY_BLOCK		0x0f
209 			sc_tx_busy,
210 			sc_tx_done,
211 			sc_tx_stopped,
212 			sc_st_check,
213 			sc_rx_ready;
214 
215 	volatile u_char sc_heldchange;
216 	volatile u_char sc_msr, sc_msr_delta, sc_msr_mask, sc_mcr,
217 	    sc_mcr_active, sc_lcr, sc_ier, sc_fifo, sc_dlbl, sc_dlbh, sc_efr;
218 	u_char sc_mcr_dtr, sc_mcr_rts, sc_msr_cts, sc_msr_dcd;
219 
220 #ifdef COM_HAYESP
221 	u_char sc_prescaler;
222 #endif
223 
224 	/*
225 	 * There are a great many almost-ns16550-compatible UARTs out
226 	 * there, which have minor differences.  The type field here
227 	 * lets us distinguish between them.
228 	 */
229 	int sc_type;
230 #define	COM_TYPE_NORMAL		0	/* normal 16x50 */
231 #define	COM_TYPE_HAYESP		1	/* Hayes ESP modem */
232 #define	COM_TYPE_PXA2x0		2	/* Intel PXA2x0 processor built-in */
233 #define	COM_TYPE_AU1x00		3	/* AMD/Alchemy Au1x000 proc. built-in */
234 #define	COM_TYPE_OMAP		4	/* TI OMAP processor built-in */
235 #define	COM_TYPE_16550_NOERS	5	/* like a 16550, no ERS */
236 #define	COM_TYPE_INGENIC	6	/* JZ4780 built-in */
237 #define	COM_TYPE_TEGRA		7	/* NVIDIA Tegra built-in */
238 
239 	/* power management hooks */
240 	int (*enable)(struct com_softc *);
241 	void (*disable)(struct com_softc *);
242 	int enabled;
243 
244 	/* XXXX: vendor workaround functions */
245 	int (*sc_vendor_workaround)(struct com_softc *);
246 
247 	struct pps_state sc_pps_state;	/* pps state */
248 
249 #ifdef RND_COM
250 	krndsource_t  rnd_source;
251 #endif
252 	kmutex_t		sc_lock;
253 };
254 
255 int comprobe1(bus_space_tag_t, bus_space_handle_t);
256 int comintr(void *);
257 void com_attach_subr(struct com_softc *);
258 int com_probe_subr(struct com_regs *);
259 int com_detach(device_t, int);
260 bool com_resume(device_t, const pmf_qual_t *);
261 bool com_cleanup(device_t, int);
262 bool com_suspend(device_t, const pmf_qual_t *);
263 
264 #ifndef IPL_SERIAL
265 #define	IPL_SERIAL	IPL_TTY
266 #define	splserial()	spltty()
267 #endif
268