Home | History | Annotate | Line # | Download | only in s3c2xx0
sscom_var.h revision 1.2
      1 /* $NetBSD: sscom_var.h,v 1.2 2003/05/13 06:26:57 bsh Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2002 Fujitsu Component Limited
      5  * Copyright (c) 2002 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 <sys/param.h>
     70 #include <sys/systm.h>
     71 #include <sys/device.h>
     72 #include <sys/termios.h>
     73 #include <sys/callout.h>
     74 #include <machine/bus.h>
     75 
     76 /* Hardware flag masks */
     77 #define	SSCOM_HW_FLOW		0x02
     78 #define	SSCOM_HW_DEV_OK		0x04
     79 #define	SSCOM_HW_CONSOLE	0x08
     80 #define	SSCOM_HW_KGDB		0x10
     81 #define SSCOM_HW_TXINT		0x20
     82 #define SSCOM_HW_RXINT		0x40
     83 
     84 /* Buffer size for character buffer */
     85 #define	SSCOM_RING_SIZE	2048
     86 
     87 struct sscom_softc {
     88 	struct device sc_dev;
     89 	void *sc_si;
     90 	struct tty *sc_tty;
     91 
     92 	struct callout sc_diag_callout;
     93 
     94 	int sc_unit;			/* UART0/UART1 */
     95 	int sc_frequency;
     96 
     97 	bus_space_tag_t sc_iot;
     98 	bus_space_handle_t sc_ioh;
     99 
    100 	u_int sc_overflows,
    101 	      sc_floods,
    102 	      sc_errors;
    103 
    104 	int sc_hwflags,
    105 	    sc_swflags;
    106 
    107 	u_int sc_r_hiwat,
    108 	      sc_r_lowat;
    109 	u_char *volatile sc_rbget,
    110 	       *volatile sc_rbput;
    111  	volatile u_int sc_rbavail;
    112 	u_char *sc_rbuf,
    113 	       *sc_ebuf;
    114 
    115  	u_char *sc_tba;
    116  	u_int sc_tbc,
    117 	      sc_heldtbc;
    118 
    119 	volatile u_char sc_rx_flags,
    120 #define	RX_TTY_BLOCKED		0x01
    121 #define	RX_TTY_OVERFLOWED	0x02
    122 #define	RX_IBUF_BLOCKED		0x04
    123 #define	RX_IBUF_OVERFLOWED	0x08
    124 #define	RX_ANY_BLOCK		0x0f
    125 			sc_tx_busy,
    126 			sc_tx_done,
    127 			sc_tx_stopped,
    128 			sc_st_check,
    129 			sc_rx_ready;
    130 
    131 	/* data to stored in UART registers.
    132 	   actual write to UART register is pended while sc_tx_busy */
    133 	uint16_t sc_ucon;		/* control register */
    134 	uint16_t sc_ubrdiv;		/* baudrate register */
    135 	uint8_t  sc_heldchange;		/* register changes are pended */
    136 	uint8_t  sc_ulcon;		/* line control */
    137 	uint8_t  sc_umcon;		/* modem control */
    138 #define  UMCON_HW_MASK	(UMCON_RTS)
    139 #define  UMCON_DTR  (1<<4)		/* provided by other means such as GPIO */
    140 	uint8_t  sc_msts;		/* modem status */
    141 #define  MSTS_CTS   UMSTAT_CTS		/* bit0 */
    142 #define  MSTS_DCD   (1<<1)
    143 #define  MSTS_DSR   (1<<2)
    144 
    145 	uint8_t sc_msr_dcd;		/* DCD or 0 */
    146 	uint8_t sc_mcr_dtr;		/* DTR or 0 or DTR|RTS*/
    147 	uint8_t sc_mcr_rts;		/* RTS or DTR in sc_umcon */
    148 	uint8_t sc_msr_cts;		/* CTS or DCD in sc_msts */
    149 
    150 	uint8_t sc_msr_mask;		/* sc_msr_cts|sc_msr_dcd */
    151 	uint8_t sc_mcr_active;
    152 	uint8_t sc_msr_delta;
    153 
    154 	uint8_t sc_rx_irqno, sc_tx_irqno;
    155 
    156 #if 0
    157 	/* PPS signal on DCD, with or without inkernel clock disciplining */
    158 	u_char	sc_ppsmask;			/* pps signal mask */
    159 	u_char	sc_ppsassert;			/* pps leading edge */
    160 	u_char	sc_ppsclear;			/* pps trailing edge */
    161 	pps_info_t ppsinfo;
    162 	pps_params_t ppsparam;
    163 #endif
    164 
    165 #if NRND > 0 && defined(RND_COM)
    166 	rndsource_element_t  rnd_source;
    167 #endif
    168 #if (defined(MULTIPROCESSOR) || defined(LOCKDEBUG)) && defined(SSCOM_MPLOCK)
    169 	struct simplelock	sc_lock;
    170 #endif
    171 
    172 	/*
    173 	 * S3C2XX0's UART doesn't have modem control/status pins.
    174 	 * On platforms with S3C2XX0, those pins are simply unavailable
    175 	 * or provided by other means such as GPIO.  Platform specific attach routine
    176 	 * have to provide functions to read/write modem control/status pins.
    177 	 */
    178 	int	(* read_modem_status)( struct sscom_softc * );
    179 	void	(* set_modem_control)( struct sscom_softc * );
    180 };
    181 
    182 /* Macros to clear/set/test flags. */
    183 #define SET(t, f)	(t) |= (f)
    184 #define CLR(t, f)	(t) &= ~(f)
    185 #define ISSET(t, f)	((t) & (f))
    186 
    187 /* UART register address, etc. */
    188 struct sscom_uart_info {
    189 	int		unit;
    190 	char		tx_int, rx_int, err_int;
    191 	bus_addr_t	iobase;
    192 };
    193 
    194 #define sscom_rxrdy(iot,ioh) \
    195 	(bus_space_read_1((iot), (ioh), SSCOM_UTRSTAT) & UTRSTAT_RXREADY)
    196 #define sscom_getc(iot,ioh) bus_space_read_1((iot), (ioh), SSCOM_URXH)
    197 #define sscom_geterr(iot,ioh) bus_space_read_1((iot), (ioh), SSCOM_UERSTAT)
    198 
    199 #define sscom_enable_rxint(sc)	(s3c2xx0_unmask_interrupts(1<<sc->sc_rx_irqno), \
    200 				    (sc->sc_hwflags |= SSCOM_HW_RXINT))
    201 #define sscom_disable_rxint(sc)	(s3c2xx0_mask_interrupts(1<<sc->sc_rx_irqno), \
    202 				    (sc->sc_hwflags &= ~SSCOM_HW_RXINT))
    203 #define sscom_enable_txint(sc)	(s3c2xx0_unmask_interrupts(1<<sc->sc_tx_irqno), \
    204 				    (sc->sc_hwflags |= SSCOM_HW_TXINT))
    205 #define sscom_disable_txint(sc)	(s3c2xx0_mask_interrupts(1<<sc->sc_tx_irqno), \
    206 				    (sc->sc_hwflags &= ~SSCOM_HW_TXINT))
    207 #define sscom_enable_txrxint(sc)	\
    208 	(s3c2xx0_unmask_interrupts((1<<sc->sc_tx_irqno)|(1<<sc->sc_rx_irqno)), \
    209 		    (sc->sc_hwflags |= (SSCOM_HW_TXINT|SSCOM_HW_RXINT)))
    210 #define sscom_disable_txrxint(sc)		\
    211 	(s3c2xx0_mask_interrupts((1<<sc->sc_tx_irqno)|(1<<sc->sc_rx_irqno)), \
    212 		    (sc->sc_hwflags &= ~(SSCOM_HW_TXINT|SSCOM_HW_RXINT)))
    213 
    214 
    215 int	sscomspeed(long, long);
    216 void	sscom_attach_subr(struct sscom_softc *);
    217 
    218 int	sscom_detach(struct device *, int);
    219 int	sscom_activate(struct device *, enum devact);
    220 void	sscom_shutdown(struct sscom_softc *);
    221 void	sscomdiag		(void *);
    222 void	sscomstart(struct tty *);
    223 int	sscomparam(struct tty *, struct termios *);
    224 int	sscomread(dev_t, struct uio *, int);
    225 void	sscom_config(struct sscom_softc *);
    226 
    227 int	sscomintr(void *);
    228 
    229 int	sscom_cnattach(bus_space_tag_t, const struct sscom_uart_info *,
    230 	    int, int, tcflag_t);
    231 void	sscom_cndetach(void);
    232 int	sscom_is_console(bus_space_tag_t, int, bus_space_handle_t *);
    233 
    234 #ifdef KGDB
    235 int	sscom_kgdb_attach(bus_space_tag_t, const struct sscom_uart_info *,
    236 	    int, int, tcflag_t);
    237 #endif
    238 
    239 #endif /* _ARM_S3C2XX0_SSCOM_VAR_H */
    240