Home | History | Annotate | Line # | Download | only in ic
comvar.h revision 1.52.2.1
      1 /*	$NetBSD: comvar.h,v 1.52.2.1 2006/06/15 16:30:26 gdamore 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 "rnd.h"
     34 #include "opt_multiprocessor.h"
     35 #include "opt_lockdebug.h"
     36 #include "opt_com.h"
     37 #include "opt_kgdb.h"
     38 
     39 #if NRND > 0 && defined(RND_COM)
     40 #include <sys/rnd.h>
     41 #endif
     42 
     43 #include <sys/callout.h>
     44 #include <sys/timepps.h>
     45 #include <sys/lock.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 
     72 /* Buffer size for character buffer */
     73 #define	COM_RING_SIZE	2048
     74 
     75 #ifdef	COM_REGMAP
     76 #define	COM_REG_RXDATA		0
     77 #define	COM_REG_TXDATA		1
     78 #define	COM_REG_DLBL		2
     79 #define	COM_REG_DLBH		3
     80 #define	COM_REG_IER		4
     81 #define	COM_REG_IIR		5
     82 #define	COM_REG_FIFO		6
     83 #define	COM_REG_EFR		7
     84 #define	COM_REG_LCR		8
     85 #define	COM_REG_MCR		9
     86 #define	COM_REG_LSR		10
     87 #define	COM_REG_MSR		11
     88 
     89 struct com_regs {
     90 	bus_space_tag_t		iot;
     91 	bus_space_handle_t	ioh;
     92 	bus_addr_t		iobase;
     93 	bus_size_t		nports;
     94 	bus_size_t		map[16];
     95 };
     96 
     97 extern const bus_size_t com_std_map[16];
     98 
     99 #define	COM_INIT_REGS(regs, tag, hdl, addr)	\
    100 	regs.iot = tag; \
    101 	regs.ioh = hdl; \
    102 	regs.iobase = addr; \
    103 	regs.nports = COM_NPORTS; \
    104 	memcpy(regs.map, com_std_map, sizeof (regs.map))
    105 
    106 
    107 #else
    108 #define	COM_REG_RXDATA		com_data
    109 #define	COM_REG_TXDATA		com_data
    110 #define	COM_REG_DLBL		com_dlbl
    111 #define	COM_REG_DLBH		com_dlbh
    112 #define	COM_REG_IER		com_ier
    113 #define	COM_REG_IIR		com_iir
    114 #define	COM_REG_FIFO		com_fifo
    115 #define	COM_REG_EFR		com_efr
    116 #define	COM_REG_LCR		com_lctl
    117 #define	COM_REG_MCR		com_mcr
    118 #define	COM_REG_LSR		com_lsr
    119 #define	COM_REG_MSR		com_msr
    120 
    121 struct com_regs {
    122 	bus_space_tag_t		iot;
    123 	bus_space_handle_t	ioh;
    124 	bus_addr_t		iobase;
    125 	bus_size_t		nports;
    126 };
    127 
    128 #define	COM_INIT_REGS(regs, tag, hdl, addr)	\
    129 	regs.iot = tag; \
    130 	regs.ioh = hdl; \
    131 	regs.iobase = addr; \
    132 	regs.nports = COM_NPORTS
    133 
    134 #endif
    135 
    136 struct com_softc {
    137 	struct device sc_dev;
    138 	void *sc_si;
    139 	struct tty *sc_tty;
    140 
    141 	struct callout sc_diag_callout;
    142 
    143 	int sc_frequency;
    144 
    145 	struct com_regs sc_regs;
    146 	bus_space_handle_t sc_hayespioh;
    147 
    148 
    149 	u_int sc_overflows,
    150 	      sc_floods,
    151 	      sc_errors;
    152 
    153 	int sc_hwflags,
    154 	    sc_swflags;
    155 	u_int sc_fifolen;
    156 
    157 	u_int sc_r_hiwat,
    158 	      sc_r_lowat;
    159 	u_char *volatile sc_rbget,
    160 	       *volatile sc_rbput;
    161  	volatile u_int sc_rbavail;
    162 	u_char *sc_rbuf,
    163 	       *sc_ebuf;
    164 
    165  	u_char *sc_tba;
    166  	u_int sc_tbc,
    167 	      sc_heldtbc;
    168 
    169 	volatile u_char sc_rx_flags,
    170 #define	RX_TTY_BLOCKED		0x01
    171 #define	RX_TTY_OVERFLOWED	0x02
    172 #define	RX_IBUF_BLOCKED		0x04
    173 #define	RX_IBUF_OVERFLOWED	0x08
    174 #define	RX_ANY_BLOCK		0x0f
    175 			sc_tx_busy,
    176 			sc_tx_done,
    177 			sc_tx_stopped,
    178 			sc_st_check,
    179 			sc_rx_ready;
    180 
    181 	volatile u_char sc_heldchange;
    182 	volatile u_char sc_msr, sc_msr_delta, sc_msr_mask, sc_mcr,
    183 	    sc_mcr_active, sc_lcr, sc_ier, sc_fifo, sc_dlbl, sc_dlbh, sc_efr;
    184 	u_char sc_mcr_dtr, sc_mcr_rts, sc_msr_cts, sc_msr_dcd;
    185 
    186 #ifdef COM_HAYESP
    187 	u_char sc_prescaler;
    188 #endif
    189 
    190 	/*
    191 	 * There are a great many almost-ns16550-compatible UARTs out
    192 	 * there, which have minor differences.  The type field here
    193 	 * lets us distinguish between them.
    194 	 */
    195 	int sc_type;
    196 #define	COM_TYPE_NORMAL		0	/* normal 16x50 */
    197 #define	COM_TYPE_HAYESP		1	/* Hayes ESP modem */
    198 #define	COM_TYPE_PXA2x0		2	/* Intel PXA2x0 processor built-in */
    199 #define	COM_TYPE_AU1x00		3	/* AMD/Alchemy Au1x000 proc. built-in */
    200 
    201 	/* power management hooks */
    202 	int (*enable)(struct com_softc *);
    203 	void (*disable)(struct com_softc *);
    204 	int enabled;
    205 
    206 #ifdef __HAVE_TIMECOUNTER
    207 	struct pps_state sc_pps_state;	/* pps state */
    208 #else /* !__HAVE_TIMECOUNTER */
    209 	/* PPS signal on DCD, with or without inkernel clock disciplining */
    210 	u_char	sc_ppsmask;			/* pps signal mask */
    211 	u_char	sc_ppsassert;			/* pps leading edge */
    212 	u_char	sc_ppsclear;			/* pps trailing edge */
    213 	pps_info_t ppsinfo;
    214 	pps_params_t ppsparam;
    215 #endif /* !__HAVE_TIMECOUNTER */
    216 
    217 #if NRND > 0 && defined(RND_COM)
    218 	rndsource_element_t  rnd_source;
    219 #endif
    220 	struct simplelock	sc_lock;
    221 };
    222 
    223 int comprobe1(bus_space_tag_t, bus_space_handle_t);
    224 int comintr(void *);
    225 void com_attach_subr(struct com_softc *);
    226 int com_probe_subr(struct com_regs *);
    227 int com_detach(struct device *, int);
    228 int com_activate(struct device *, enum devact);
    229 
    230 #ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
    231 #ifdef __NO_SOFT_SERIAL_INTERRUPT
    232 #define	IPL_SERIAL	IPL_TTY
    233 #define	splserial()	spltty()
    234 #define	IPL_SOFTSERIAL	IPL_TTY
    235 #define	splsoftserial()	spltty()
    236 #endif
    237 #endif
    238