Home | History | Annotate | Line # | Download | only in ic
comvar.h revision 1.92.14.1
      1  1.92.14.1   thorpej /*	$NetBSD: comvar.h,v 1.92.14.1 2021/04/03 21:44:51 thorpej 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.38  sommerfe #include "opt_multiprocessor.h"
     34       1.38  sommerfe #include "opt_lockdebug.h"
     35       1.38  sommerfe #include "opt_com.h"
     36       1.40     lukem #include "opt_kgdb.h"
     37       1.38  sommerfe 
     38       1.73       tls #ifdef RND_COM
     39       1.80  riastrad #include <sys/rndsource.h>
     40       1.17  explorer #endif
     41       1.24   thorpej 
     42       1.32   thorpej #include <sys/callout.h>
     43       1.24   thorpej #include <sys/timepps.h>
     44       1.56        ad #include <sys/mutex.h>
     45       1.71  uebayasi #include <sys/device.h>
     46       1.17  explorer 
     47       1.54   gdamore #include <dev/ic/comreg.h>	/* for COM_NPORTS */
     48       1.54   gdamore 
     49       1.54   gdamore struct com_regs;
     50       1.54   gdamore 
     51       1.48     perry int comcnattach(bus_space_tag_t, bus_addr_t, int, int, int, tcflag_t);
     52       1.54   gdamore int comcnattach1(struct com_regs *, int, int, int, tcflag_t);
     53       1.12  drochner 
     54       1.12  drochner #ifdef KGDB
     55       1.48     perry int com_kgdb_attach(bus_space_tag_t, bus_addr_t, int, int, int, tcflag_t);
     56       1.54   gdamore int com_kgdb_attach1(struct com_regs *, int, int, int, tcflag_t);
     57       1.12  drochner #endif
     58        1.8   mycroft 
     59       1.48     perry int com_is_console(bus_space_tag_t, bus_addr_t, bus_space_handle_t *);
     60       1.14  drochner 
     61        1.8   mycroft /* Hardware flag masks */
     62        1.8   mycroft #define	COM_HW_NOIEN	0x01
     63        1.8   mycroft #define	COM_HW_FIFO	0x02
     64  1.92.14.1   thorpej #define	COM_HW_BROKEN_ETXRDY	0x04
     65       1.18      fvdl #define	COM_HW_FLOW	0x08
     66       1.21       cgd #define	COM_HW_DEV_OK	0x20
     67        1.8   mycroft #define	COM_HW_CONSOLE	0x40
     68       1.11   thorpej #define	COM_HW_KGDB	0x80
     69       1.31      soda #define	COM_HW_TXFIFO_DISABLE	0x100
     70       1.43   thorpej #define	COM_HW_NO_TXPRELOAD	0x200
     71       1.77  jmcneill #define	COM_HW_AFE	0x400
     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 #define	COM_REG_RXDATA		0
     79       1.54   gdamore #define	COM_REG_TXDATA		1
     80       1.54   gdamore #define	COM_REG_DLBL		2
     81       1.54   gdamore #define	COM_REG_DLBH		3
     82       1.54   gdamore #define	COM_REG_IER		4
     83       1.54   gdamore #define	COM_REG_IIR		5
     84       1.54   gdamore #define	COM_REG_FIFO		6
     85       1.92   thorpej #define	COM_REG_TCR		7
     86       1.92   thorpej #define	COM_REG_EFR		8
     87       1.92   thorpej #define	COM_REG_TLR		9
     88       1.92   thorpej #define	COM_REG_LCR		10
     89       1.92   thorpej #define	COM_REG_MCR		11
     90       1.92   thorpej #define	COM_REG_LSR		12
     91       1.92   thorpej #define	COM_REG_MSR		13
     92       1.92   thorpej #define	COM_REG_MDR1		14		/* TI OMAP */
     93       1.92   thorpej #define	COM_REG_USR		15		/* 16750/DW APB */
     94       1.92   thorpej #define	COM_REG_TFL		16		/* DW APB */
     95       1.92   thorpej #define	COM_REG_RFL		17		/* DW APB */
     96       1.92   thorpej #define	COM_REG_HALT		18		/* DW APB */
     97       1.92   thorpej 
     98       1.92   thorpej #define	COM_REGMAP_NENTRIES	19
     99       1.54   gdamore 
    100       1.54   gdamore struct com_regs {
    101       1.54   gdamore 	bus_space_tag_t		cr_iot;
    102       1.54   gdamore 	bus_space_handle_t	cr_ioh;
    103       1.54   gdamore 	bus_addr_t		cr_iobase;
    104       1.54   gdamore 	bus_size_t		cr_nports;
    105       1.92   thorpej 	bus_size_t		cr_map[COM_REGMAP_NENTRIES];
    106       1.54   gdamore };
    107       1.54   gdamore 
    108       1.89   thorpej void	com_init_regs(struct com_regs *, bus_space_tag_t, bus_space_handle_t,
    109       1.89   thorpej 		      bus_addr_t);
    110       1.91   thorpej void	com_init_regs_stride(struct com_regs *, bus_space_tag_t,
    111       1.91   thorpej 			     bus_space_handle_t, bus_addr_t, u_int);
    112       1.54   gdamore 
    113       1.67    dyoung struct comcons_info {
    114       1.67    dyoung 	struct com_regs regs;
    115       1.67    dyoung 	int rate;
    116       1.67    dyoung 	int frequency;
    117       1.67    dyoung 	int type;
    118       1.67    dyoung 	tcflag_t cflag;
    119       1.67    dyoung };
    120       1.67    dyoung 
    121        1.8   mycroft struct com_softc {
    122       1.61      cube 	device_t sc_dev;
    123        1.8   mycroft 	void *sc_si;
    124        1.8   mycroft 	struct tty *sc_tty;
    125       1.32   thorpej 
    126       1.88  jmcneill 	callout_t sc_diag_callout;
    127       1.88  jmcneill 	callout_t sc_poll_callout;
    128        1.8   mycroft 
    129       1.15        is 	int sc_frequency;
    130        1.8   mycroft 
    131       1.54   gdamore 	struct com_regs sc_regs;
    132        1.8   mycroft 	bus_space_handle_t sc_hayespioh;
    133        1.8   mycroft 
    134       1.54   gdamore 
    135       1.19   mycroft 	u_int sc_overflows,
    136       1.19   mycroft 	      sc_floods,
    137       1.19   mycroft 	      sc_errors;
    138       1.19   mycroft 
    139       1.19   mycroft 	int sc_hwflags,
    140       1.19   mycroft 	    sc_swflags;
    141       1.19   mycroft 	u_int sc_fifolen;
    142       1.19   mycroft 
    143       1.19   mycroft 	u_int sc_r_hiwat,
    144       1.19   mycroft 	      sc_r_lowat;
    145       1.19   mycroft 	u_char *volatile sc_rbget,
    146       1.19   mycroft 	       *volatile sc_rbput;
    147       1.19   mycroft  	volatile u_int sc_rbavail;
    148       1.19   mycroft 	u_char *sc_rbuf,
    149       1.19   mycroft 	       *sc_ebuf;
    150        1.8   mycroft 
    151        1.8   mycroft  	u_char *sc_tba;
    152       1.19   mycroft  	u_int sc_tbc,
    153       1.19   mycroft 	      sc_heldtbc;
    154        1.8   mycroft 
    155       1.10   mycroft 	volatile u_char sc_rx_flags,
    156       1.10   mycroft #define	RX_TTY_BLOCKED		0x01
    157       1.10   mycroft #define	RX_TTY_OVERFLOWED	0x02
    158       1.10   mycroft #define	RX_IBUF_BLOCKED		0x04
    159       1.10   mycroft #define	RX_IBUF_OVERFLOWED	0x08
    160       1.10   mycroft #define	RX_ANY_BLOCK		0x0f
    161        1.8   mycroft 			sc_tx_busy,
    162        1.8   mycroft 			sc_tx_done,
    163        1.8   mycroft 			sc_tx_stopped,
    164        1.8   mycroft 			sc_st_check,
    165        1.8   mycroft 			sc_rx_ready;
    166        1.8   mycroft 
    167        1.8   mycroft 	volatile u_char sc_heldchange;
    168       1.19   mycroft 	volatile u_char sc_msr, sc_msr_delta, sc_msr_mask, sc_mcr,
    169       1.19   mycroft 	    sc_mcr_active, sc_lcr, sc_ier, sc_fifo, sc_dlbl, sc_dlbh, sc_efr;
    170       1.19   mycroft 	u_char sc_mcr_dtr, sc_mcr_rts, sc_msr_cts, sc_msr_dcd;
    171       1.42     enami 
    172       1.84  jmcneill 	u_char sc_prescaler;		/* for COM_TYPE_HAYESP */
    173       1.45   thorpej 
    174       1.45   thorpej 	/*
    175       1.45   thorpej 	 * There are a great many almost-ns16550-compatible UARTs out
    176       1.45   thorpej 	 * there, which have minor differences.  The type field here
    177       1.45   thorpej 	 * lets us distinguish between them.
    178       1.45   thorpej 	 */
    179       1.45   thorpej 	int sc_type;
    180       1.45   thorpej #define	COM_TYPE_NORMAL		0	/* normal 16x50 */
    181       1.45   thorpej #define	COM_TYPE_HAYESP		1	/* Hayes ESP modem */
    182       1.45   thorpej #define	COM_TYPE_PXA2x0		2	/* Intel PXA2x0 processor built-in */
    183       1.47    simonb #define	COM_TYPE_AU1x00		3	/* AMD/Alchemy Au1x000 proc. built-in */
    184       1.62      matt #define	COM_TYPE_OMAP		4	/* TI OMAP processor built-in */
    185       1.63      matt #define	COM_TYPE_16550_NOERS	5	/* like a 16550, no ERS */
    186       1.79  macallan #define	COM_TYPE_INGENIC	6	/* JZ4780 built-in */
    187       1.81  jmcneill #define	COM_TYPE_TEGRA		7	/* NVIDIA Tegra built-in */
    188       1.83  jmcneill #define	COM_TYPE_BCMAUXUART	8	/* BCM2835 AUX UART */
    189       1.84  jmcneill #define	COM_TYPE_16650		9
    190       1.84  jmcneill #define	COM_TYPE_16750		10
    191       1.87  jmcneill #define	COM_TYPE_DW_APB		11	/* DesignWare APB UART */
    192       1.20      marc 
    193  1.92.14.1   thorpej 	int sc_poll_ticks;
    194  1.92.14.1   thorpej 
    195       1.20      marc 	/* power management hooks */
    196       1.48     perry 	int (*enable)(struct com_softc *);
    197       1.48     perry 	void (*disable)(struct com_softc *);
    198       1.20      marc 	int enabled;
    199       1.23  jonathan 
    200       1.78  kiyohara 	/* XXXX: vendor workaround functions */
    201       1.78  kiyohara 	int (*sc_vendor_workaround)(struct com_softc *);
    202       1.78  kiyohara 
    203       1.52    kardel 	struct pps_state sc_pps_state;	/* pps state */
    204       1.19   mycroft 
    205       1.73       tls #ifdef RND_COM
    206       1.72       tls 	krndsource_t  rnd_source;
    207       1.36  sommerfe #endif
    208       1.56        ad 	kmutex_t		sc_lock;
    209        1.1       cgd };
    210        1.1       cgd 
    211       1.48     perry int comprobe1(bus_space_tag_t, bus_space_handle_t);
    212       1.48     perry int comintr(void *);
    213       1.48     perry void com_attach_subr(struct com_softc *);
    214       1.54   gdamore int com_probe_subr(struct com_regs *);
    215       1.65    cegger int com_detach(device_t, int);
    216       1.70    dyoung bool com_resume(device_t, const pmf_qual_t *);
    217       1.60    dyoung bool com_cleanup(device_t, int);
    218       1.70    dyoung bool com_suspend(device_t, const pmf_qual_t *);
    219       1.56        ad 
    220       1.57        ad #ifndef IPL_SERIAL
    221       1.56        ad #define	IPL_SERIAL	IPL_TTY
    222       1.56        ad #define	splserial()	spltty()
    223       1.56        ad #endif
    224