Home | History | Annotate | Line # | Download | only in ic
comvar.h revision 1.73.6.1
      1  1.73.6.1       tls /*	$NetBSD: comvar.h,v 1.73.6.1 2013/06/23 06:20:17 tls Exp $	*/
      2       1.1       cgd 
      3       1.1       cgd /*
      4       1.2       cgd  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
      5       1.1       cgd  *
      6       1.1       cgd  * Redistribution and use in source and binary forms, with or without
      7       1.1       cgd  * modification, are permitted provided that the following conditions
      8       1.1       cgd  * are met:
      9       1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     10       1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     11       1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     13       1.1       cgd  *    documentation and/or other materials provided with the distribution.
     14       1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     15       1.1       cgd  *    must display the following acknowledgement:
     16       1.1       cgd  *      This product includes software developed by Christopher G. Demetriou
     17       1.1       cgd  *	for the NetBSD Project.
     18       1.1       cgd  * 4. The name of the author may not be used to endorse or promote products
     19       1.1       cgd  *    derived from this software without specific prior written permission
     20       1.1       cgd  *
     21       1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22       1.1       cgd  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23       1.1       cgd  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24       1.1       cgd  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25       1.1       cgd  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26       1.1       cgd  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27       1.1       cgd  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28       1.1       cgd  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29       1.1       cgd  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30       1.1       cgd  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31       1.1       cgd  */
     32       1.1       cgd 
     33      1.17  explorer #include "rnd.h"
     34      1.38  sommerfe #include "opt_multiprocessor.h"
     35      1.38  sommerfe #include "opt_lockdebug.h"
     36      1.38  sommerfe #include "opt_com.h"
     37      1.40     lukem #include "opt_kgdb.h"
     38      1.38  sommerfe 
     39      1.73       tls #ifdef RND_COM
     40      1.17  explorer #include <sys/rnd.h>
     41      1.17  explorer #endif
     42      1.24   thorpej 
     43      1.32   thorpej #include <sys/callout.h>
     44      1.24   thorpej #include <sys/timepps.h>
     45      1.56        ad #include <sys/mutex.h>
     46      1.71  uebayasi #include <sys/device.h>
     47      1.17  explorer 
     48      1.54   gdamore #include <dev/ic/comreg.h>	/* for COM_NPORTS */
     49      1.54   gdamore 
     50      1.54   gdamore struct com_regs;
     51      1.54   gdamore 
     52      1.48     perry int comcnattach(bus_space_tag_t, bus_addr_t, int, int, int, tcflag_t);
     53      1.54   gdamore int comcnattach1(struct com_regs *, int, int, int, tcflag_t);
     54      1.12  drochner 
     55      1.12  drochner #ifdef KGDB
     56      1.48     perry int com_kgdb_attach(bus_space_tag_t, bus_addr_t, int, int, int, tcflag_t);
     57      1.54   gdamore int com_kgdb_attach1(struct com_regs *, int, int, int, tcflag_t);
     58      1.12  drochner #endif
     59       1.8   mycroft 
     60      1.48     perry int com_is_console(bus_space_tag_t, bus_addr_t, bus_space_handle_t *);
     61      1.14  drochner 
     62       1.8   mycroft /* Hardware flag masks */
     63       1.8   mycroft #define	COM_HW_NOIEN	0x01
     64       1.8   mycroft #define	COM_HW_FIFO	0x02
     65      1.45   thorpej 		/*	0x04	free for use */
     66      1.18      fvdl #define	COM_HW_FLOW	0x08
     67      1.21       cgd #define	COM_HW_DEV_OK	0x20
     68       1.8   mycroft #define	COM_HW_CONSOLE	0x40
     69      1.11   thorpej #define	COM_HW_KGDB	0x80
     70      1.31      soda #define	COM_HW_TXFIFO_DISABLE	0x100
     71      1.43   thorpej #define	COM_HW_NO_TXPRELOAD	0x200
     72       1.8   mycroft 
     73       1.8   mycroft /* Buffer size for character buffer */
     74      1.64   tsutsui #ifndef COM_RING_SIZE
     75      1.19   mycroft #define	COM_RING_SIZE	2048
     76      1.64   tsutsui #endif
     77       1.8   mycroft 
     78      1.54   gdamore #ifdef	COM_REGMAP
     79      1.54   gdamore #define	COM_REG_RXDATA		0
     80      1.54   gdamore #define	COM_REG_TXDATA		1
     81      1.54   gdamore #define	COM_REG_DLBL		2
     82      1.54   gdamore #define	COM_REG_DLBH		3
     83      1.54   gdamore #define	COM_REG_IER		4
     84      1.54   gdamore #define	COM_REG_IIR		5
     85      1.54   gdamore #define	COM_REG_FIFO		6
     86      1.62      matt #define	COM_REG_TCR		6
     87      1.54   gdamore #define	COM_REG_EFR		7
     88      1.62      matt #define	COM_REG_TLR		7
     89      1.54   gdamore #define	COM_REG_LCR		8
     90      1.62      matt #define	COM_REG_MDR1		8
     91      1.54   gdamore #define	COM_REG_MCR		9
     92      1.54   gdamore #define	COM_REG_LSR		10
     93      1.54   gdamore #define	COM_REG_MSR		11
     94  1.73.6.1       tls #ifdef	COM_16750
     95  1.73.6.1       tls #define COM_REG_USR		31
     96  1.73.6.1       tls #endif
     97      1.54   gdamore 
     98      1.54   gdamore struct com_regs {
     99      1.54   gdamore 	bus_space_tag_t		cr_iot;
    100      1.54   gdamore 	bus_space_handle_t	cr_ioh;
    101      1.54   gdamore 	bus_addr_t		cr_iobase;
    102      1.54   gdamore 	bus_size_t		cr_nports;
    103  1.73.6.1       tls #ifdef COM_16750
    104  1.73.6.1       tls 	bus_size_t		cr_map[32];
    105  1.73.6.1       tls #else
    106      1.54   gdamore 	bus_size_t		cr_map[16];
    107  1.73.6.1       tls #endif
    108      1.54   gdamore };
    109      1.54   gdamore 
    110  1.73.6.1       tls #ifdef COM_16750
    111  1.73.6.1       tls extern const bus_size_t com_std_map[32];
    112  1.73.6.1       tls #else
    113      1.54   gdamore extern const bus_size_t com_std_map[16];
    114  1.73.6.1       tls #endif
    115      1.54   gdamore 
    116      1.54   gdamore #define	COM_INIT_REGS(regs, tag, hdl, addr)				\
    117      1.54   gdamore 	do {								\
    118      1.54   gdamore 		regs.cr_iot = tag;					\
    119      1.54   gdamore 		regs.cr_ioh = hdl;					\
    120      1.54   gdamore 		regs.cr_iobase = addr;					\
    121      1.54   gdamore 		regs.cr_nports = COM_NPORTS;				\
    122      1.54   gdamore 		memcpy(regs.cr_map, com_std_map, sizeof (regs.cr_map));	\
    123      1.54   gdamore 	} while (0)
    124      1.54   gdamore 
    125      1.54   gdamore #else
    126      1.54   gdamore #define	COM_REG_RXDATA		com_data
    127      1.54   gdamore #define	COM_REG_TXDATA		com_data
    128      1.54   gdamore #define	COM_REG_DLBL		com_dlbl
    129      1.54   gdamore #define	COM_REG_DLBH		com_dlbh
    130      1.54   gdamore #define	COM_REG_IER		com_ier
    131      1.54   gdamore #define	COM_REG_IIR		com_iir
    132      1.54   gdamore #define	COM_REG_FIFO		com_fifo
    133      1.54   gdamore #define	COM_REG_EFR		com_efr
    134      1.54   gdamore #define	COM_REG_LCR		com_lctl
    135      1.54   gdamore #define	COM_REG_MCR		com_mcr
    136      1.54   gdamore #define	COM_REG_LSR		com_lsr
    137      1.54   gdamore #define	COM_REG_MSR		com_msr
    138      1.62      matt #define	COM_REG_TCR		com_msr
    139      1.62      matt #define	COM_REG_TLR		com_scratch
    140      1.62      matt #define	COM_REG_MDR1		8
    141      1.54   gdamore 
    142      1.54   gdamore struct com_regs {
    143      1.54   gdamore 	bus_space_tag_t		cr_iot;
    144      1.54   gdamore 	bus_space_handle_t	cr_ioh;
    145      1.54   gdamore 	bus_addr_t		cr_iobase;
    146      1.54   gdamore 	bus_size_t		cr_nports;
    147      1.54   gdamore };
    148      1.54   gdamore 
    149      1.54   gdamore #define	COM_INIT_REGS(regs, tag, hdl, addr)		\
    150      1.54   gdamore 	do {						\
    151      1.54   gdamore 		regs.cr_iot = tag;			\
    152      1.54   gdamore 		regs.cr_ioh = hdl;			\
    153      1.54   gdamore 		regs.cr_iobase = addr;			\
    154      1.54   gdamore 		regs.cr_nports = COM_NPORTS;		\
    155      1.54   gdamore 	} while (0)
    156      1.54   gdamore 
    157      1.54   gdamore #endif
    158      1.54   gdamore 
    159      1.67    dyoung struct comcons_info {
    160      1.67    dyoung 	struct com_regs regs;
    161      1.67    dyoung 	int rate;
    162      1.67    dyoung 	int frequency;
    163      1.67    dyoung 	int type;
    164      1.67    dyoung 	tcflag_t cflag;
    165      1.67    dyoung };
    166      1.67    dyoung 
    167       1.8   mycroft struct com_softc {
    168      1.61      cube 	device_t sc_dev;
    169       1.8   mycroft 	void *sc_si;
    170       1.8   mycroft 	struct tty *sc_tty;
    171      1.32   thorpej 
    172      1.32   thorpej 	struct callout sc_diag_callout;
    173       1.8   mycroft 
    174      1.15        is 	int sc_frequency;
    175       1.8   mycroft 
    176      1.54   gdamore 	struct com_regs sc_regs;
    177       1.8   mycroft 	bus_space_handle_t sc_hayespioh;
    178       1.8   mycroft 
    179      1.54   gdamore 
    180      1.19   mycroft 	u_int sc_overflows,
    181      1.19   mycroft 	      sc_floods,
    182      1.19   mycroft 	      sc_errors;
    183      1.19   mycroft 
    184      1.19   mycroft 	int sc_hwflags,
    185      1.19   mycroft 	    sc_swflags;
    186      1.19   mycroft 	u_int sc_fifolen;
    187      1.19   mycroft 
    188      1.19   mycroft 	u_int sc_r_hiwat,
    189      1.19   mycroft 	      sc_r_lowat;
    190      1.19   mycroft 	u_char *volatile sc_rbget,
    191      1.19   mycroft 	       *volatile sc_rbput;
    192      1.19   mycroft  	volatile u_int sc_rbavail;
    193      1.19   mycroft 	u_char *sc_rbuf,
    194      1.19   mycroft 	       *sc_ebuf;
    195       1.8   mycroft 
    196       1.8   mycroft  	u_char *sc_tba;
    197      1.19   mycroft  	u_int sc_tbc,
    198      1.19   mycroft 	      sc_heldtbc;
    199       1.8   mycroft 
    200      1.10   mycroft 	volatile u_char sc_rx_flags,
    201      1.10   mycroft #define	RX_TTY_BLOCKED		0x01
    202      1.10   mycroft #define	RX_TTY_OVERFLOWED	0x02
    203      1.10   mycroft #define	RX_IBUF_BLOCKED		0x04
    204      1.10   mycroft #define	RX_IBUF_OVERFLOWED	0x08
    205      1.10   mycroft #define	RX_ANY_BLOCK		0x0f
    206       1.8   mycroft 			sc_tx_busy,
    207       1.8   mycroft 			sc_tx_done,
    208       1.8   mycroft 			sc_tx_stopped,
    209       1.8   mycroft 			sc_st_check,
    210       1.8   mycroft 			sc_rx_ready;
    211       1.8   mycroft 
    212       1.8   mycroft 	volatile u_char sc_heldchange;
    213      1.19   mycroft 	volatile u_char sc_msr, sc_msr_delta, sc_msr_mask, sc_mcr,
    214      1.19   mycroft 	    sc_mcr_active, sc_lcr, sc_ier, sc_fifo, sc_dlbl, sc_dlbh, sc_efr;
    215      1.19   mycroft 	u_char sc_mcr_dtr, sc_mcr_rts, sc_msr_cts, sc_msr_dcd;
    216      1.42     enami 
    217      1.42     enami #ifdef COM_HAYESP
    218      1.42     enami 	u_char sc_prescaler;
    219      1.42     enami #endif
    220      1.45   thorpej 
    221      1.45   thorpej 	/*
    222      1.45   thorpej 	 * There are a great many almost-ns16550-compatible UARTs out
    223      1.45   thorpej 	 * there, which have minor differences.  The type field here
    224      1.45   thorpej 	 * lets us distinguish between them.
    225      1.45   thorpej 	 */
    226      1.45   thorpej 	int sc_type;
    227      1.45   thorpej #define	COM_TYPE_NORMAL		0	/* normal 16x50 */
    228      1.45   thorpej #define	COM_TYPE_HAYESP		1	/* Hayes ESP modem */
    229      1.45   thorpej #define	COM_TYPE_PXA2x0		2	/* Intel PXA2x0 processor built-in */
    230      1.47    simonb #define	COM_TYPE_AU1x00		3	/* AMD/Alchemy Au1x000 proc. built-in */
    231      1.62      matt #define	COM_TYPE_OMAP		4	/* TI OMAP processor built-in */
    232      1.63      matt #define	COM_TYPE_16550_NOERS	5	/* like a 16550, no ERS */
    233      1.20      marc 
    234      1.20      marc 	/* power management hooks */
    235      1.48     perry 	int (*enable)(struct com_softc *);
    236      1.48     perry 	void (*disable)(struct com_softc *);
    237      1.20      marc 	int enabled;
    238      1.23  jonathan 
    239      1.52    kardel 	struct pps_state sc_pps_state;	/* pps state */
    240      1.19   mycroft 
    241      1.73       tls #ifdef RND_COM
    242      1.72       tls 	krndsource_t  rnd_source;
    243      1.36  sommerfe #endif
    244      1.56        ad 	kmutex_t		sc_lock;
    245       1.1       cgd };
    246       1.1       cgd 
    247      1.48     perry int comprobe1(bus_space_tag_t, bus_space_handle_t);
    248      1.48     perry int comintr(void *);
    249      1.48     perry void com_attach_subr(struct com_softc *);
    250      1.54   gdamore int com_probe_subr(struct com_regs *);
    251      1.65    cegger int com_detach(device_t, int);
    252      1.70    dyoung bool com_resume(device_t, const pmf_qual_t *);
    253      1.60    dyoung bool com_cleanup(device_t, int);
    254      1.70    dyoung bool com_suspend(device_t, const pmf_qual_t *);
    255      1.56        ad 
    256      1.57        ad #ifndef IPL_SERIAL
    257      1.56        ad #define	IPL_SERIAL	IPL_TTY
    258      1.56        ad #define	splserial()	spltty()
    259      1.56        ad #endif
    260