sscom_var.h revision 1.11 1 1.11 tls /* $NetBSD: sscom_var.h,v 1.11 2012/02/02 19:42:58 tls Exp $ */
2 1.1 bsh
3 1.1 bsh /*
4 1.4 bsh * Copyright (c) 2002, 2003 Fujitsu Component Limited
5 1.4 bsh * Copyright (c) 2002, 2003 Genetec Corporation
6 1.1 bsh * All rights reserved.
7 1.1 bsh *
8 1.1 bsh * Redistribution and use in source and binary forms, with or without
9 1.1 bsh * modification, are permitted provided that the following conditions
10 1.1 bsh * are met:
11 1.1 bsh * 1. Redistributions of source code must retain the above copyright
12 1.1 bsh * notice, this list of conditions and the following disclaimer.
13 1.1 bsh * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 bsh * notice, this list of conditions and the following disclaimer in the
15 1.1 bsh * documentation and/or other materials provided with the distribution.
16 1.1 bsh * 3. Neither the name of The Fujitsu Component Limited nor the name of
17 1.1 bsh * Genetec corporation may not be used to endorse or promote products
18 1.1 bsh * derived from this software without specific prior written permission.
19 1.1 bsh *
20 1.1 bsh * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
21 1.1 bsh * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 1.1 bsh * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 1.1 bsh * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 1.1 bsh * DISCLAIMED. IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
25 1.1 bsh * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1 bsh * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 1.1 bsh * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 1.1 bsh * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 1.1 bsh * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 1.1 bsh * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 1.1 bsh * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 bsh * SUCH DAMAGE.
33 1.1 bsh */
34 1.1 bsh /* derived from sys/dev/ic/comvar.h */
35 1.2 bsh
36 1.1 bsh /*
37 1.1 bsh * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
38 1.1 bsh *
39 1.1 bsh * Redistribution and use in source and binary forms, with or without
40 1.1 bsh * modification, are permitted provided that the following conditions
41 1.1 bsh * are met:
42 1.1 bsh * 1. Redistributions of source code must retain the above copyright
43 1.1 bsh * notice, this list of conditions and the following disclaimer.
44 1.1 bsh * 2. Redistributions in binary form must reproduce the above copyright
45 1.1 bsh * notice, this list of conditions and the following disclaimer in the
46 1.1 bsh * documentation and/or other materials provided with the distribution.
47 1.1 bsh * 3. All advertising materials mentioning features or use of this software
48 1.1 bsh * must display the following acknowledgement:
49 1.1 bsh * This product includes software developed by Christopher G. Demetriou
50 1.1 bsh * for the NetBSD Project.
51 1.1 bsh * 4. The name of the author may not be used to endorse or promote products
52 1.1 bsh * derived from this software without specific prior written permission
53 1.1 bsh *
54 1.1 bsh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
55 1.1 bsh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
56 1.1 bsh * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
57 1.1 bsh * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
58 1.1 bsh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
59 1.1 bsh * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 1.1 bsh * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 1.1 bsh * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 1.1 bsh * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
63 1.1 bsh * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 1.1 bsh */
65 1.1 bsh
66 1.1 bsh #ifndef _ARM_S3C2XX0_SSCOM_VAR_H
67 1.1 bsh #define _ARM_S3C2XX0_SSCOM_VAR_H
68 1.3 martin
69 1.3 martin #include "opt_multiprocessor.h"
70 1.3 martin #include "opt_lockdebug.h"
71 1.5 bsh #include "opt_sscom.h"
72 1.1 bsh
73 1.1 bsh #include <sys/param.h>
74 1.1 bsh #include <sys/systm.h>
75 1.1 bsh #include <sys/device.h>
76 1.1 bsh #include <sys/termios.h>
77 1.1 bsh #include <sys/callout.h>
78 1.8 dyoung #include <sys/bus.h>
79 1.1 bsh
80 1.5 bsh #ifdef SSCOM_S3C2410
81 1.5 bsh #include <arm/s3c2xx0/s3c2410reg.h>
82 1.5 bsh #include <arm/s3c2xx0/s3c2410var.h>
83 1.10 nisimura #elif defined(SSCOM_S3C2440)
84 1.10 nisimura #include <arm/s3c2xx0/s3c2440reg.h>
85 1.10 nisimura #include <arm/s3c2xx0/s3c2440var.h>
86 1.5 bsh #endif
87 1.5 bsh
88 1.1 bsh /* Hardware flag masks */
89 1.1 bsh #define SSCOM_HW_FLOW 0x02
90 1.1 bsh #define SSCOM_HW_DEV_OK 0x04
91 1.1 bsh #define SSCOM_HW_CONSOLE 0x08
92 1.1 bsh #define SSCOM_HW_KGDB 0x10
93 1.1 bsh #define SSCOM_HW_TXINT 0x20
94 1.1 bsh #define SSCOM_HW_RXINT 0x40
95 1.1 bsh
96 1.1 bsh /* Buffer size for character buffer */
97 1.1 bsh #define SSCOM_RING_SIZE 2048
98 1.1 bsh
99 1.1 bsh struct sscom_softc {
100 1.10 nisimura device_t sc_dev;
101 1.1 bsh void *sc_si;
102 1.1 bsh struct tty *sc_tty;
103 1.1 bsh
104 1.1 bsh struct callout sc_diag_callout;
105 1.1 bsh
106 1.1 bsh int sc_unit; /* UART0/UART1 */
107 1.1 bsh int sc_frequency;
108 1.1 bsh
109 1.1 bsh bus_space_tag_t sc_iot;
110 1.1 bsh bus_space_handle_t sc_ioh;
111 1.1 bsh
112 1.1 bsh u_int sc_overflows,
113 1.1 bsh sc_floods,
114 1.1 bsh sc_errors;
115 1.1 bsh
116 1.1 bsh int sc_hwflags,
117 1.1 bsh sc_swflags;
118 1.1 bsh
119 1.1 bsh u_int sc_r_hiwat,
120 1.1 bsh sc_r_lowat;
121 1.1 bsh u_char *volatile sc_rbget,
122 1.1 bsh *volatile sc_rbput;
123 1.1 bsh volatile u_int sc_rbavail;
124 1.1 bsh u_char *sc_rbuf,
125 1.1 bsh *sc_ebuf;
126 1.1 bsh
127 1.1 bsh u_char *sc_tba;
128 1.1 bsh u_int sc_tbc,
129 1.1 bsh sc_heldtbc;
130 1.1 bsh
131 1.1 bsh volatile u_char sc_rx_flags,
132 1.1 bsh #define RX_TTY_BLOCKED 0x01
133 1.1 bsh #define RX_TTY_OVERFLOWED 0x02
134 1.1 bsh #define RX_IBUF_BLOCKED 0x04
135 1.1 bsh #define RX_IBUF_OVERFLOWED 0x08
136 1.1 bsh #define RX_ANY_BLOCK 0x0f
137 1.1 bsh sc_tx_busy,
138 1.1 bsh sc_tx_done,
139 1.1 bsh sc_tx_stopped,
140 1.1 bsh sc_st_check,
141 1.1 bsh sc_rx_ready;
142 1.1 bsh
143 1.1 bsh /* data to stored in UART registers.
144 1.1 bsh actual write to UART register is pended while sc_tx_busy */
145 1.1 bsh uint16_t sc_ucon; /* control register */
146 1.1 bsh uint16_t sc_ubrdiv; /* baudrate register */
147 1.1 bsh uint8_t sc_heldchange; /* register changes are pended */
148 1.1 bsh uint8_t sc_ulcon; /* line control */
149 1.1 bsh uint8_t sc_umcon; /* modem control */
150 1.1 bsh #define UMCON_HW_MASK (UMCON_RTS)
151 1.1 bsh #define UMCON_DTR (1<<4) /* provided by other means such as GPIO */
152 1.1 bsh uint8_t sc_msts; /* modem status */
153 1.1 bsh #define MSTS_CTS UMSTAT_CTS /* bit0 */
154 1.1 bsh #define MSTS_DCD (1<<1)
155 1.1 bsh #define MSTS_DSR (1<<2)
156 1.1 bsh
157 1.1 bsh uint8_t sc_msr_dcd; /* DCD or 0 */
158 1.1 bsh uint8_t sc_mcr_dtr; /* DTR or 0 or DTR|RTS*/
159 1.1 bsh uint8_t sc_mcr_rts; /* RTS or DTR in sc_umcon */
160 1.1 bsh uint8_t sc_msr_cts; /* CTS or DCD in sc_msts */
161 1.1 bsh
162 1.1 bsh uint8_t sc_msr_mask; /* sc_msr_cts|sc_msr_dcd */
163 1.1 bsh uint8_t sc_mcr_active;
164 1.1 bsh uint8_t sc_msr_delta;
165 1.1 bsh
166 1.1 bsh uint8_t sc_rx_irqno, sc_tx_irqno;
167 1.1 bsh
168 1.1 bsh #if 0
169 1.1 bsh /* PPS signal on DCD, with or without inkernel clock disciplining */
170 1.1 bsh u_char sc_ppsmask; /* pps signal mask */
171 1.1 bsh u_char sc_ppsassert; /* pps leading edge */
172 1.1 bsh u_char sc_ppsclear; /* pps trailing edge */
173 1.1 bsh pps_info_t ppsinfo;
174 1.1 bsh pps_params_t ppsparam;
175 1.1 bsh #endif
176 1.1 bsh
177 1.11 tls #ifdef RND_COM
178 1.9 tls krndsource_t rnd_source;
179 1.1 bsh #endif
180 1.1 bsh #if (defined(MULTIPROCESSOR) || defined(LOCKDEBUG)) && defined(SSCOM_MPLOCK)
181 1.1 bsh struct simplelock sc_lock;
182 1.1 bsh #endif
183 1.1 bsh
184 1.1 bsh /*
185 1.1 bsh * S3C2XX0's UART doesn't have modem control/status pins.
186 1.1 bsh * On platforms with S3C2XX0, those pins are simply unavailable
187 1.1 bsh * or provided by other means such as GPIO. Platform specific attach routine
188 1.1 bsh * have to provide functions to read/write modem control/status pins.
189 1.1 bsh */
190 1.1 bsh int (* read_modem_status)( struct sscom_softc * );
191 1.1 bsh void (* set_modem_control)( struct sscom_softc * );
192 1.1 bsh };
193 1.1 bsh
194 1.1 bsh /* UART register address, etc. */
195 1.1 bsh struct sscom_uart_info {
196 1.1 bsh int unit;
197 1.1 bsh char tx_int, rx_int, err_int;
198 1.1 bsh bus_addr_t iobase;
199 1.1 bsh };
200 1.1 bsh
201 1.1 bsh #define sscom_rxrdy(iot,ioh) \
202 1.1 bsh (bus_space_read_1((iot), (ioh), SSCOM_UTRSTAT) & UTRSTAT_RXREADY)
203 1.1 bsh #define sscom_getc(iot,ioh) bus_space_read_1((iot), (ioh), SSCOM_URXH)
204 1.1 bsh #define sscom_geterr(iot,ioh) bus_space_read_1((iot), (ioh), SSCOM_UERSTAT)
205 1.1 bsh
206 1.5 bsh /*
207 1.5 bsh * we need to tweak interrupt controller to mask/unmask rxint and/or txint.
208 1.5 bsh */
209 1.5 bsh #ifdef SSCOM_S3C2410
210 1.5 bsh /* RXINTn, TXINTn and ERRn interrupts are cascaded to UARTn irq. */
211 1.5 bsh
212 1.5 bsh #define _sscom_intbit(irqno) (1<<((irqno)-S3C2410_SUBIRQ_MIN))
213 1.5 bsh
214 1.5 bsh #define sscom_unmask_rxint(sc) \
215 1.5 bsh s3c2410_unmask_subinterrupts(_sscom_intbit((sc)->sc_rx_irqno))
216 1.5 bsh #define sscom_mask_rxint(sc) \
217 1.5 bsh s3c2410_mask_subinterrupts(_sscom_intbit((sc)->sc_rx_irqno))
218 1.5 bsh #define sscom_unmask_txint(sc) \
219 1.5 bsh s3c2410_unmask_subinterrupts(_sscom_intbit((sc)->sc_tx_irqno))
220 1.5 bsh #define sscom_mask_txint(sc) \
221 1.5 bsh s3c2410_mask_subinterrupts(_sscom_intbit((sc)->sc_tx_irqno))
222 1.5 bsh #define sscom_unmask_txrxint(sc) \
223 1.5 bsh s3c2410_unmask_subinterrupts(_sscom_intbit((sc)->sc_tx_irqno) | \
224 1.5 bsh _sscom_intbit((sc)->sc_rx_irqno))
225 1.5 bsh #define sscom_mask_txrxint(sc) \
226 1.5 bsh s3c2410_mask_subinterrupts(_sscom_intbit((sc)->sc_tx_irqno) | \
227 1.5 bsh _sscom_intbit((sc)->sc_rx_irqno))
228 1.5 bsh
229 1.10 nisimura #elif defined(SSCOM_S3C2440)
230 1.10 nisimura /* RXINTn, TXINTn and ERRn interrupts are cascaded to UARTn irq. */
231 1.10 nisimura
232 1.10 nisimura #define _sscom_intbit(irqno) (1<<((irqno)-S3C2440_SUBIRQ_MIN))
233 1.10 nisimura
234 1.10 nisimura #define sscom_unmask_rxint(sc) \
235 1.10 nisimura s3c2440_unmask_subinterrupts(_sscom_intbit((sc)->sc_rx_irqno))
236 1.10 nisimura #define sscom_mask_rxint(sc) \
237 1.10 nisimura s3c2440_mask_subinterrupts(_sscom_intbit((sc)->sc_rx_irqno))
238 1.10 nisimura #define sscom_unmask_txint(sc) \
239 1.10 nisimura s3c2440_unmask_subinterrupts(_sscom_intbit((sc)->sc_tx_irqno))
240 1.10 nisimura #define sscom_mask_txint(sc) \
241 1.10 nisimura s3c2440_mask_subinterrupts(_sscom_intbit((sc)->sc_tx_irqno))
242 1.10 nisimura #define sscom_unmask_txrxint(sc) \
243 1.10 nisimura s3c2440_unmask_subinterrupts(_sscom_intbit((sc)->sc_tx_irqno) | \
244 1.10 nisimura _sscom_intbit((sc)->sc_rx_irqno))
245 1.10 nisimura #define sscom_mask_txrxint(sc) \
246 1.10 nisimura s3c2440_mask_subinterrupts(_sscom_intbit((sc)->sc_tx_irqno) | \
247 1.10 nisimura _sscom_intbit((sc)->sc_rx_irqno))
248 1.5 bsh #else
249 1.5 bsh
250 1.5 bsh /* for S3C2800 and S3C2400 */
251 1.5 bsh #define sscom_unmask_rxint(sc) s3c2xx0_unmask_interrupts(1<<(sc)->sc_rx_irqno)
252 1.5 bsh #define sscom_mask_rxint(sc) s3c2xx0_mask_interrupts(1<<(sc)->sc_rx_irqno)
253 1.5 bsh #define sscom_unmask_txint(sc) s3c2xx0_unmask_interrupts(1<<(sc)->sc_tx_irqno)
254 1.5 bsh #define sscom_mask_txint(sc) s3c2xx0_mask_interrupts(1<<(sc)->sc_tx_irqno)
255 1.5 bsh #define sscom_unmask_txrxint(sc) \
256 1.5 bsh s3c2xx0_unmask_interrupts((1<<(sc)->sc_tx_irqno)|(1<<(sc)->sc_rx_irqno))
257 1.5 bsh #define sscom_mask_txrxint(sc) \
258 1.5 bsh s3c2xx0_mask_interrupts((1<<(sc)->sc_tx_irqno)|(1<<(sc)->sc_rx_irqno))
259 1.5 bsh
260 1.5 bsh #endif /* SSCOM_S3C2410 */
261 1.5 bsh
262 1.5 bsh #define sscom_enable_rxint(sc) \
263 1.5 bsh (sscom_unmask_rxint(sc), ((sc)->sc_hwflags |= SSCOM_HW_RXINT))
264 1.5 bsh #define sscom_disable_rxint(sc) \
265 1.5 bsh (sscom_mask_rxint(sc), ((sc)->sc_hwflags &= ~SSCOM_HW_RXINT))
266 1.5 bsh #define sscom_enable_txint(sc) \
267 1.5 bsh (sscom_unmask_txint(sc), ((sc)->sc_hwflags |= SSCOM_HW_TXINT))
268 1.5 bsh #define sscom_disable_txint(sc) \
269 1.5 bsh (sscom_mask_txint(sc),((sc)->sc_hwflags &= ~SSCOM_HW_TXINT))
270 1.5 bsh #define sscom_enable_txrxint(sc) \
271 1.5 bsh (sscom_unmask_txrxint(sc),((sc)->sc_hwflags |= (SSCOM_HW_TXINT|SSCOM_HW_RXINT)))
272 1.5 bsh #define sscom_disable_txrxint(sc) \
273 1.5 bsh (sscom_mask_txrxint(sc),((sc)->sc_hwflags &= ~(SSCOM_HW_TXINT|SSCOM_HW_RXINT)))
274 1.1 bsh
275 1.1 bsh
276 1.1 bsh int sscomspeed(long, long);
277 1.1 bsh void sscom_attach_subr(struct sscom_softc *);
278 1.1 bsh
279 1.1 bsh int sscom_detach(struct device *, int);
280 1.1 bsh int sscom_activate(struct device *, enum devact);
281 1.1 bsh void sscom_shutdown(struct sscom_softc *);
282 1.1 bsh void sscomdiag (void *);
283 1.1 bsh void sscomstart(struct tty *);
284 1.1 bsh int sscomparam(struct tty *, struct termios *);
285 1.1 bsh int sscomread(dev_t, struct uio *, int);
286 1.1 bsh void sscom_config(struct sscom_softc *);
287 1.1 bsh
288 1.4 bsh int sscomtxintr(void *);
289 1.4 bsh int sscomrxintr(void *);
290 1.1 bsh
291 1.1 bsh int sscom_cnattach(bus_space_tag_t, const struct sscom_uart_info *,
292 1.1 bsh int, int, tcflag_t);
293 1.1 bsh void sscom_cndetach(void);
294 1.1 bsh int sscom_is_console(bus_space_tag_t, int, bus_space_handle_t *);
295 1.1 bsh
296 1.1 bsh #ifdef KGDB
297 1.1 bsh int sscom_kgdb_attach(bus_space_tag_t, const struct sscom_uart_info *,
298 1.1 bsh int, int, tcflag_t);
299 1.1 bsh #endif
300 1.1 bsh
301 1.1 bsh #endif /* _ARM_S3C2XX0_SSCOM_VAR_H */
302