comvar.h revision 1.95 1 /* $NetBSD: comvar.h,v 1.95 2021/10/12 00:21:34 thorpej 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 #define COM_HW_BROKEN_ETXRDY 0x04
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 #define COM_REG_RXDATA 0
79 #define COM_REG_TXDATA 1
80 #define COM_REG_DLBL 2
81 #define COM_REG_DLBH 3
82 #define COM_REG_IER 4
83 #define COM_REG_IIR 5
84 #define COM_REG_FIFO 6
85 #define COM_REG_TCR 7
86 #define COM_REG_EFR 8
87 #define COM_REG_TLR 9
88 #define COM_REG_LCR 10
89 #define COM_REG_MCR 11
90 #define COM_REG_LSR 12
91 #define COM_REG_MSR 13
92 #define COM_REG_MDR1 14 /* TI OMAP */
93 #define COM_REG_USR 15 /* 16750/DW APB */
94 #define COM_REG_TFL 16 /* DW APB */
95 #define COM_REG_RFL 17 /* DW APB */
96 #define COM_REG_HALT 18 /* DW APB */
97
98 #define COM_REGMAP_NENTRIES 19
99
100 struct com_regs {
101 bus_space_tag_t cr_iot;
102 bus_space_handle_t cr_ioh;
103 bus_addr_t cr_iobase;
104 bus_size_t cr_nports;
105 bus_size_t cr_map[COM_REGMAP_NENTRIES];
106 };
107
108 void com_init_regs(struct com_regs *, bus_space_tag_t, bus_space_handle_t,
109 bus_addr_t);
110 void com_init_regs_stride(struct com_regs *, bus_space_tag_t,
111 bus_space_handle_t, bus_addr_t, u_int);
112
113 struct comcons_info {
114 struct com_regs regs;
115 int rate;
116 int frequency;
117 int type;
118 tcflag_t cflag;
119 };
120
121 struct com_softc {
122 device_t sc_dev;
123 void *sc_si;
124 struct tty *sc_tty;
125
126 callout_t sc_diag_callout;
127 callout_t sc_poll_callout;
128 struct timeval sc_hup_pending;
129
130 int sc_frequency;
131
132 struct com_regs sc_regs;
133 bus_space_handle_t sc_hayespioh;
134
135
136 u_int sc_overflows,
137 sc_floods,
138 sc_errors;
139
140 int sc_hwflags,
141 sc_swflags;
142 u_int sc_fifolen;
143
144 u_int sc_r_hiwat,
145 sc_r_lowat;
146 u_char *volatile sc_rbget,
147 *volatile sc_rbput;
148 volatile u_int sc_rbavail;
149 u_char *sc_rbuf,
150 *sc_ebuf;
151
152 u_char *sc_tba;
153 u_int sc_tbc,
154 sc_heldtbc;
155
156 volatile u_char sc_rx_flags,
157 #define RX_TTY_BLOCKED 0x01
158 #define RX_TTY_OVERFLOWED 0x02
159 #define RX_IBUF_BLOCKED 0x04
160 #define RX_IBUF_OVERFLOWED 0x08
161 #define RX_ANY_BLOCK 0x0f
162 sc_tx_busy,
163 sc_tx_done,
164 sc_tx_stopped,
165 sc_st_check,
166 sc_rx_ready;
167
168 volatile u_char sc_heldchange;
169 volatile u_char sc_msr, sc_msr_delta, sc_msr_mask, sc_mcr,
170 sc_mcr_active, sc_lcr, sc_ier, sc_fifo, sc_dlbl, sc_dlbh, sc_efr;
171 u_char sc_mcr_dtr, sc_mcr_rts, sc_msr_cts, sc_msr_dcd;
172
173 u_char sc_prescaler; /* for COM_TYPE_HAYESP */
174
175 /*
176 * There are a great many almost-ns16550-compatible UARTs out
177 * there, which have minor differences. The type field here
178 * lets us distinguish between them.
179 */
180 int sc_type;
181 #define COM_TYPE_NORMAL 0 /* normal 16x50 */
182 #define COM_TYPE_HAYESP 1 /* Hayes ESP modem */
183 #define COM_TYPE_PXA2x0 2 /* Intel PXA2x0 processor built-in */
184 #define COM_TYPE_AU1x00 3 /* AMD/Alchemy Au1x000 proc. built-in */
185 #define COM_TYPE_OMAP 4 /* TI OMAP processor built-in */
186 #define COM_TYPE_16550_NOERS 5 /* like a 16550, no ERS */
187 #define COM_TYPE_INGENIC 6 /* JZ4780 built-in */
188 #define COM_TYPE_TEGRA 7 /* NVIDIA Tegra built-in */
189 #define COM_TYPE_BCMAUXUART 8 /* BCM2835 AUX UART */
190 #define COM_TYPE_16650 9
191 #define COM_TYPE_16750 10
192 #define COM_TYPE_DW_APB 11 /* DesignWare APB UART */
193
194 int sc_poll_ticks;
195
196 /* power management hooks */
197 int (*enable)(struct com_softc *);
198 void (*disable)(struct com_softc *);
199 int enabled;
200
201 /* XXXX: vendor workaround functions */
202 int (*sc_vendor_workaround)(struct com_softc *);
203
204 struct pps_state sc_pps_state; /* pps state */
205
206 #ifdef RND_COM
207 krndsource_t rnd_source;
208 #endif
209 kmutex_t sc_lock;
210 };
211
212 int comprobe1(bus_space_tag_t, bus_space_handle_t);
213 int comintr(void *);
214 void com_attach_subr(struct com_softc *);
215 int com_probe_subr(struct com_regs *);
216 int com_detach(device_t, int);
217 bool com_resume(device_t, const pmf_qual_t *);
218 bool com_cleanup(device_t, int);
219 bool com_suspend(device_t, const pmf_qual_t *);
220
221 #ifndef IPL_SERIAL
222 #define IPL_SERIAL IPL_TTY
223 #define splserial() spltty()
224 #endif
225