xref: /netbsd-src/sys/arch/evbarm/dev/plcomvar.h (revision e89934bbf778a6d6d6894877c4da59d0c7835b0f)
1 /*	$NetBSD: plcomvar.h,v 1.16 2015/04/13 21:18:41 riastradh 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_plcom.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 
45 struct plcom_instance;
46 
47 int  plcomcnattach	(struct plcom_instance *, int, int, tcflag_t, int);
48 void plcomcndetach	(void);
49 
50 #ifdef KGDB
51 int  plcom_kgdb_attach	(struct plcom_instance *, int, int, tcflag_t, int);
52 #endif
53 
54 int  plcom_is_console	(bus_space_tag_t, bus_addr_t, bus_space_handle_t *);
55 
56 /* Hardware flag masks */
57 #define	PLCOM_HW_NOIEN		0x01
58 #define	PLCOM_HW_FIFO		0x02
59 #define	PLCOM_HW_HAYESP		0x04
60 #define	PLCOM_HW_FLOW		0x08
61 #define	PLCOM_HW_DEV_OK		0x20
62 #define	PLCOM_HW_CONSOLE	0x40
63 #define	PLCOM_HW_KGDB		0x80
64 #define	PLCOM_HW_TXFIFO_DISABLE	0x100
65 
66 /* Buffer size for character buffer */
67 #define	PLCOM_RING_SIZE		2048
68 
69 struct plcom_instance {
70 	u_int			pi_type;
71 #define	PLCOM_TYPE_PL010 0
72 #define	PLCOM_TYPE_PL011 1
73 
74 	uint32_t		pi_flags;	/* flags for this PLCOM */
75 #define	PLC_FLAG_USE_DMA		0x0001
76 #define	PLC_FLAG_32BIT_ACCESS		0x0002
77 
78 	void 			*pi_cookie;
79 
80 	bus_space_tag_t		pi_iot;
81 	bus_space_handle_t	pi_ioh;
82 	bus_addr_t		pi_iobase;
83 	bus_addr_t		pi_size;
84 	struct plcom_registers	*pi_regs;
85 };
86 
87 struct plcomcons_info {
88 	int	rate;
89 	int	frequency;
90 	int	type;
91 
92 	tcflag_t	cflag;
93 };
94 
95 struct plcom_softc {
96 	device_t sc_dev;
97 
98 	struct tty *sc_tty;
99 	void *sc_si;
100 
101 	struct callout sc_diag_callout;
102 
103  	int sc_frequency;
104 
105 	struct plcom_instance sc_pi;
106 
107 	u_int sc_overflows,
108 	      sc_floods,
109 	      sc_errors;
110 
111 	int sc_hwflags,
112 	    sc_swflags;
113 	u_int sc_fifolen;
114 
115 	u_int sc_r_hiwat,
116 	      sc_r_lowat;
117 	u_char *volatile sc_rbget,
118 	       *volatile sc_rbput;
119  	volatile u_int sc_rbavail;
120 	u_char *sc_rbuf,
121 	       *sc_ebuf;
122 
123  	u_char *sc_tba;
124  	u_int sc_tbc,
125 	      sc_heldtbc;
126 
127 	volatile u_char sc_rx_flags,
128 #define	RX_TTY_BLOCKED		0x01
129 #define	RX_TTY_OVERFLOWED	0x02
130 #define	RX_IBUF_BLOCKED		0x04
131 #define	RX_IBUF_OVERFLOWED	0x08
132 #define	RX_ANY_BLOCK		0x0f
133 			sc_tx_busy,
134 			sc_tx_done,
135 			sc_tx_stopped,
136 			sc_st_check,
137 			sc_rx_ready;
138 
139 	volatile u_char sc_heldchange;
140 	volatile u_int sc_cr, sc_ratel, sc_rateh, sc_imsc;
141 	volatile u_int sc_msr, sc_msr_delta, sc_msr_mask;
142 	volatile u_char sc_mcr, sc_mcr_active, sc_lcr;
143 	u_char sc_mcr_dtr, sc_mcr_rts, sc_msr_cts, sc_msr_dcd;
144 	u_int sc_fifo;
145 
146 	/* Support routine to program mcr lines for PL010, if present.  */
147 	void	(*sc_set_mcr)(void *, int, u_int);
148 	void	*sc_set_mcr_arg;
149 
150 	/* power management hooks */
151 	int (*enable) (struct plcom_softc *);
152 	void (*disable) (struct plcom_softc *);
153 	int enabled;
154 
155 	/* PPS signal on DCD, with or without inkernel clock disciplining */
156 	u_char	sc_ppsmask;			/* pps signal mask */
157 	u_char	sc_ppsassert;			/* pps leading edge */
158 	u_char	sc_ppsclear;			/* pps trailing edge */
159 	pps_info_t ppsinfo;
160 	pps_params_t ppsparam;
161 
162 #ifdef RND_COM
163 	krndsource_t  rnd_source;
164 #endif
165 	kmutex_t		sc_lock;
166 };
167 
168 #if 0
169 int  plcomprobe1	(bus_space_tag_t, bus_space_handle_t);
170 #endif
171 int  plcomintr		(void *);
172 void plcom_attach_subr	(struct plcom_softc *);
173 int  plcom_detach	(device_t, int);
174 int  plcom_activate	(device_t, enum devact);
175 
176