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