Home | History | Annotate | Line # | Download | only in ic
comvar.h revision 1.87
      1 /*	$NetBSD: comvar.h,v 1.87 2018/05/27 17:05:06 jmcneill 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 "opt_multiprocessor.h"
     34 #include "opt_lockdebug.h"
     35 #include "opt_com.h"
     36 #include "opt_kgdb.h"
     37 
     38 #ifdef RND_COM
     39 #include <sys/rndsource.h>
     40 #endif
     41 
     42 #include <sys/callout.h>
     43 #include <sys/timepps.h>
     44 #include <sys/mutex.h>
     45 #include <sys/device.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 #define	COM_HW_AFE	0x400
     72 
     73 /* Buffer size for character buffer */
     74 #ifndef COM_RING_SIZE
     75 #define	COM_RING_SIZE	2048
     76 #endif
     77 
     78 #ifdef	COM_REGMAP
     79 #define	COM_REG_RXDATA		0
     80 #define	COM_REG_TXDATA		1
     81 #define	COM_REG_DLBL		2
     82 #define	COM_REG_DLBH		3
     83 #define	COM_REG_IER		4
     84 #define	COM_REG_IIR		5
     85 #define	COM_REG_FIFO		6
     86 #define	COM_REG_TCR		6
     87 #define	COM_REG_EFR		7
     88 #define	COM_REG_TLR		7
     89 #define	COM_REG_LCR		8
     90 #define	COM_REG_MDR1		8
     91 #define	COM_REG_MCR		9
     92 #define	COM_REG_LSR		10
     93 #define	COM_REG_MSR		11
     94 #define	COM_REG_USR		31	/* 16750/DW APB */
     95 #define	COM_REG_TFL		com_tfl		/* DW APB */
     96 #define	COM_REG_RFL		com_rfl		/* DW APB */
     97 #define	COM_REG_HALT		com_halt	/* DW APB */
     98 
     99 struct com_regs {
    100 	bus_space_tag_t		cr_iot;
    101 	bus_space_handle_t	cr_ioh;
    102 	bus_addr_t		cr_iobase;
    103 	bus_size_t		cr_nports;
    104 	bus_size_t		cr_map[42];
    105 };
    106 
    107 extern const bus_size_t com_std_map[42];
    108 
    109 #define	COM_INIT_REGS(regs, tag, hdl, addr)				\
    110 	do {								\
    111 		regs.cr_iot = tag;					\
    112 		regs.cr_ioh = hdl;					\
    113 		regs.cr_iobase = addr;					\
    114 		regs.cr_nports = COM_NPORTS;				\
    115 		memcpy(regs.cr_map, com_std_map, sizeof (regs.cr_map));	\
    116 	} while (0)
    117 
    118 #else
    119 #define	COM_REG_RXDATA		com_data
    120 #define	COM_REG_TXDATA		com_data
    121 #define	COM_REG_DLBL		com_dlbl
    122 #define	COM_REG_DLBH		com_dlbh
    123 #define	COM_REG_IER		com_ier
    124 #define	COM_REG_IIR		com_iir
    125 #define	COM_REG_FIFO		com_fifo
    126 #define	COM_REG_EFR		com_efr
    127 #define	COM_REG_LCR		com_lctl
    128 #define	COM_REG_MCR		com_mcr
    129 #define	COM_REG_LSR		com_lsr
    130 #define	COM_REG_MSR		com_msr
    131 #define	COM_REG_TCR		com_msr
    132 #define	COM_REG_TLR		com_scratch
    133 #define	COM_REG_MDR1		8
    134 #define COM_REG_USR		com_usr		/* 16750/DW APB */
    135 #define	COM_REG_TFL		com_tfl		/* DW APB */
    136 #define	COM_REG_RFL		com_rfl		/* DW APB */
    137 #define	COM_REG_HALT		com_halt	/* DW APB */
    138 
    139 struct com_regs {
    140 	bus_space_tag_t		cr_iot;
    141 	bus_space_handle_t	cr_ioh;
    142 	bus_addr_t		cr_iobase;
    143 	bus_size_t		cr_nports;
    144 };
    145 
    146 #define	COM_INIT_REGS(regs, tag, hdl, addr)		\
    147 	do {						\
    148 		regs.cr_iot = tag;			\
    149 		regs.cr_ioh = hdl;			\
    150 		regs.cr_iobase = addr;			\
    151 		regs.cr_nports = COM_NPORTS;		\
    152 	} while (0)
    153 
    154 #endif
    155 
    156 struct comcons_info {
    157 	struct com_regs regs;
    158 	int rate;
    159 	int frequency;
    160 	int type;
    161 	tcflag_t cflag;
    162 };
    163 
    164 struct com_softc {
    165 	device_t sc_dev;
    166 	void *sc_si;
    167 	struct tty *sc_tty;
    168 
    169 	struct callout sc_diag_callout;
    170 
    171 	int sc_frequency;
    172 
    173 	struct com_regs sc_regs;
    174 	bus_space_handle_t sc_hayespioh;
    175 
    176 
    177 	u_int sc_overflows,
    178 	      sc_floods,
    179 	      sc_errors;
    180 
    181 	int sc_hwflags,
    182 	    sc_swflags;
    183 	u_int sc_fifolen;
    184 
    185 	u_int sc_r_hiwat,
    186 	      sc_r_lowat;
    187 	u_char *volatile sc_rbget,
    188 	       *volatile sc_rbput;
    189  	volatile u_int sc_rbavail;
    190 	u_char *sc_rbuf,
    191 	       *sc_ebuf;
    192 
    193  	u_char *sc_tba;
    194  	u_int sc_tbc,
    195 	      sc_heldtbc;
    196 
    197 	volatile u_char sc_rx_flags,
    198 #define	RX_TTY_BLOCKED		0x01
    199 #define	RX_TTY_OVERFLOWED	0x02
    200 #define	RX_IBUF_BLOCKED		0x04
    201 #define	RX_IBUF_OVERFLOWED	0x08
    202 #define	RX_ANY_BLOCK		0x0f
    203 			sc_tx_busy,
    204 			sc_tx_done,
    205 			sc_tx_stopped,
    206 			sc_st_check,
    207 			sc_rx_ready;
    208 
    209 	volatile u_char sc_heldchange;
    210 	volatile u_char sc_msr, sc_msr_delta, sc_msr_mask, sc_mcr,
    211 	    sc_mcr_active, sc_lcr, sc_ier, sc_fifo, sc_dlbl, sc_dlbh, sc_efr;
    212 	u_char sc_mcr_dtr, sc_mcr_rts, sc_msr_cts, sc_msr_dcd;
    213 
    214 	u_char sc_prescaler;		/* for COM_TYPE_HAYESP */
    215 
    216 	/*
    217 	 * There are a great many almost-ns16550-compatible UARTs out
    218 	 * there, which have minor differences.  The type field here
    219 	 * lets us distinguish between them.
    220 	 */
    221 	int sc_type;
    222 #define	COM_TYPE_NORMAL		0	/* normal 16x50 */
    223 #define	COM_TYPE_HAYESP		1	/* Hayes ESP modem */
    224 #define	COM_TYPE_PXA2x0		2	/* Intel PXA2x0 processor built-in */
    225 #define	COM_TYPE_AU1x00		3	/* AMD/Alchemy Au1x000 proc. built-in */
    226 #define	COM_TYPE_OMAP		4	/* TI OMAP processor built-in */
    227 #define	COM_TYPE_16550_NOERS	5	/* like a 16550, no ERS */
    228 #define	COM_TYPE_INGENIC	6	/* JZ4780 built-in */
    229 #define	COM_TYPE_TEGRA		7	/* NVIDIA Tegra built-in */
    230 #define	COM_TYPE_BCMAUXUART	8	/* BCM2835 AUX UART */
    231 #define	COM_TYPE_16650		9
    232 #define	COM_TYPE_16750		10
    233 #define	COM_TYPE_DW_APB		11	/* DesignWare APB UART */
    234 
    235 	/* power management hooks */
    236 	int (*enable)(struct com_softc *);
    237 	void (*disable)(struct com_softc *);
    238 	int enabled;
    239 
    240 	/* XXXX: vendor workaround functions */
    241 	int (*sc_vendor_workaround)(struct com_softc *);
    242 
    243 	struct pps_state sc_pps_state;	/* pps state */
    244 
    245 #ifdef RND_COM
    246 	krndsource_t  rnd_source;
    247 #endif
    248 	kmutex_t		sc_lock;
    249 };
    250 
    251 int comprobe1(bus_space_tag_t, bus_space_handle_t);
    252 int comintr(void *);
    253 void com_attach_subr(struct com_softc *);
    254 int com_probe_subr(struct com_regs *);
    255 int com_detach(device_t, int);
    256 bool com_resume(device_t, const pmf_qual_t *);
    257 bool com_cleanup(device_t, int);
    258 bool com_suspend(device_t, const pmf_qual_t *);
    259 
    260 #ifndef IPL_SERIAL
    261 #define	IPL_SERIAL	IPL_TTY
    262 #define	splserial()	spltty()
    263 #endif
    264