xref: /netbsd/sys/arch/evbarm/dev/plcomvar.h (revision 69a922f7)
1 /*	$NetBSD: plcomvar.h,v 1.20 2023/04/11 12:56:07 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 #ifndef	_SYS_ARCH_EVBARM_DEV_PLCOMVAR_H_
34 #define	_SYS_ARCH_EVBARM_DEV_PLCOMVAR_H_
35 
36 #include "opt_multiprocessor.h"
37 #include "opt_lockdebug.h"
38 #include "opt_plcom.h"
39 #include "opt_kgdb.h"
40 
41 #ifdef RND_COM
42 #include <sys/rndsource.h>
43 #endif
44 
45 #include <sys/callout.h>
46 #include <sys/timepps.h>
47 
48 struct plcom_instance;
49 
50 int  plcomcnattach	(struct plcom_instance *, int, int, tcflag_t, int);
51 void plcomcndetach	(void);
52 
53 #ifdef KGDB
54 int  plcom_kgdb_attach	(struct plcom_instance *, int, int, tcflag_t, int);
55 #endif
56 
57 int  plcom_is_console	(bus_space_tag_t, bus_addr_t, bus_space_handle_t *);
58 
59 /* Hardware flag masks */
60 #define	PLCOM_HW_NOIEN		0x01
61 #define	PLCOM_HW_FIFO		0x02
62 #define	PLCOM_HW_HAYESP		0x04
63 #define	PLCOM_HW_FLOW		0x08
64 #define	PLCOM_HW_DEV_OK		0x20
65 #define	PLCOM_HW_CONSOLE	0x40
66 #define	PLCOM_HW_KGDB		0x80
67 #define	PLCOM_HW_TXFIFO_DISABLE	0x100
68 
69 /* Buffer size for character buffer */
70 #define	PLCOM_RING_SIZE		2048
71 
72 struct plcom_instance {
73 	u_int			pi_type;
74 #define	PLCOM_TYPE_PL010 0
75 #define	PLCOM_TYPE_PL011 1
76 #define	PLCOM_TYPE_GENERIC_UART 2		/* SBSA generic uart */
77 
78 	uint32_t		pi_flags;	/* flags for this PLCOM */
79 #define	PLC_FLAG_USE_DMA		0x0001
80 #define	PLC_FLAG_32BIT_ACCESS		0x0002
81 	uint32_t		pi_periphid;
82 
83 	void 			*pi_cookie;
84 
85 	bus_space_tag_t		pi_iot;
86 	bus_space_handle_t	pi_ioh;
87 	bus_addr_t		pi_iobase;
88 	bus_addr_t		pi_size;
89 	struct plcom_registers	*pi_regs;
90 };
91 
92 struct plcom_softc {
93 	device_t sc_dev;
94 
95 	struct tty *sc_tty;
96 	void *sc_si;
97 
98 	struct callout sc_diag_callout;
99 
100  	int sc_frequency;
101 
102 	struct plcom_instance sc_pi;
103 
104 	u_int sc_overflows,
105 	      sc_floods,
106 	      sc_errors;
107 
108 	int sc_hwflags,
109 	    sc_swflags;
110 	u_int sc_fifolen;
111 	u_int sc_burstlen;
112 
113 	struct timeval sc_hup_pending;
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 uint32_t sc_cr, sc_ratel, sc_rateh, sc_imsc;
141 	volatile uint32_t sc_msr, sc_msr_delta, sc_msr_mask;
142 	volatile uint32_t sc_lcr, sc_ifls;
143 	volatile u_char sc_mcr, sc_mcr_active;
144 	u_char sc_mcr_dtr, sc_mcr_rts, sc_msr_cts, sc_msr_dcd;
145 	u_int sc_fifo;
146 
147 	/* Support routine to program mcr lines for PL010, if present.  */
148 	void	(*sc_set_mcr)(void *, int, u_int);
149 	void	*sc_set_mcr_arg;
150 
151 	/* power management hooks */
152 	int (*enable) (struct plcom_softc *);
153 	void (*disable) (struct plcom_softc *);
154 	int enabled;
155 
156 	/* PPS signal on DCD, with or without inkernel clock disciplining */
157 	u_char	sc_ppsmask;			/* pps signal mask */
158 	u_char	sc_ppsassert;			/* pps leading edge */
159 	u_char	sc_ppsclear;			/* pps trailing edge */
160 	pps_info_t ppsinfo;
161 	pps_params_t ppsparam;
162 
163 #ifdef RND_COM
164 	krndsource_t  rnd_source;
165 #endif
166 	kmutex_t		sc_lock;
167 };
168 
169 #if 0
170 int  plcomprobe1	(bus_space_tag_t, bus_space_handle_t);
171 #endif
172 int  plcomintr		(void *);
173 void plcom_attach_subr	(struct plcom_softc *);
174 int  plcom_detach	(device_t, int);
175 int  plcom_activate	(device_t, enum devact);
176 
177 #endif	/* _SYS_ARCH_EVBARM_DEV_PLCOMVAR_H_ */
178