xref: /netbsd/sys/arch/mvme68k/dev/zs_pcc.c (revision c4a72b64)
1 /*	$NetBSD: zs_pcc.c,v 1.15 2002/10/02 05:28:16 thorpej Exp $	*/
2 
3 /*-
4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Gordon W. Ross and Jason R. Thorpe.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Zilog Z8530 Dual UART driver (machine-dependent part)
41  *
42  * Runs two serial lines per chip using slave drivers.
43  * Plain tty/async lines use the zs_async slave.
44  *
45  * Modified for NetBSD/mvme68k by Jason R. Thorpe <thorpej@NetBSD.ORG>
46  */
47 
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/proc.h>
51 #include <sys/device.h>
52 #include <sys/conf.h>
53 #include <sys/file.h>
54 #include <sys/ioctl.h>
55 #include <sys/tty.h>
56 #include <sys/time.h>
57 #include <sys/kernel.h>
58 #include <sys/syslog.h>
59 
60 #include <dev/cons.h>
61 #include <dev/ic/z8530reg.h>
62 #include <machine/z8530var.h>
63 
64 #include <machine/cpu.h>
65 #include <machine/bus.h>
66 
67 #include <mvme68k/dev/mainbus.h>
68 #include <mvme68k/dev/pccreg.h>
69 #include <mvme68k/dev/pccvar.h>
70 #include <mvme68k/dev/zsvar.h>
71 
72 
73 /* Definition of the driver for autoconfig. */
74 static int	zsc_pcc_match  __P((struct device *, struct cfdata *, void *));
75 static void	zsc_pcc_attach __P((struct device *, struct device *, void *));
76 
77 CFATTACH_DECL(zsc_pcc, sizeof(struct zsc_softc),
78     zsc_pcc_match, zsc_pcc_attach, NULL, NULL);
79 
80 extern struct cfdriver zsc_cd;
81 
82 cons_decl(zsc_pcc);
83 
84 
85 /*
86  * Is the zs chip present?
87  */
88 static int
89 zsc_pcc_match(parent, cf, aux)
90 	struct device *parent;
91 	struct cfdata *cf;
92 	void *aux;
93 {
94 	struct pcc_attach_args *pa = aux;
95 
96 	if (strcmp(pa->pa_name, zsc_cd.cd_name))
97 		return (0);
98 
99 	pa->pa_ipl = cf->pcccf_ipl;
100 	if (pa->pa_ipl == -1)
101 		pa->pa_ipl = ZSHARD_PRI;
102 	return (1);
103 }
104 
105 /*
106  * Attach a found zs.
107  *
108  * Match slave number to zs unit number, so that misconfiguration will
109  * not set up the keyboard as ttya, etc.
110  */
111 static void
112 zsc_pcc_attach(parent, self, aux)
113 	struct device *parent;
114 	struct device *self;
115 	void *aux;
116 {
117 	struct zsc_softc *zsc = (void *) self;
118 	struct pcc_attach_args *pa = aux;
119 	struct zsdevice zs;
120 	bus_space_handle_t bush;
121 	int zs_level, ir;
122 	static int didintr;
123 
124 	/* Map the device's registers */
125 	bus_space_map(pa->pa_bust, pa->pa_offset, 4, 0, &bush);
126 
127 	zs_level = pa->pa_ipl;
128 
129 	/* XXX: This is a gross hack. I need to bus-space zs.c ... */
130 	zs.zs_chan_b.zc_csr = (volatile u_char *) bush;
131 	zs.zs_chan_b.zc_data = (volatile u_char *) bush + 1;
132 	zs.zs_chan_a.zc_csr = (volatile u_char *) bush + 2;
133 	zs.zs_chan_a.zc_data = (volatile u_char *) bush + 3;
134 
135 	/*
136 	 * Do common parts of SCC configuration.
137 	 * Note that the vector is not actually used by the ZS chip on
138 	 * MVME-147. We set up the PCC so that it provides the vector.
139 	 * This is just here so the real vector is printed at config time.
140 	 */
141 	zs_config(zsc, &zs, PCC_VECBASE + PCCV_ZS, PCLK_147);
142 
143 	evcnt_attach_dynamic(&zsc->zsc_evcnt, EVCNT_TYPE_INTR,
144 	    pccintr_evcnt(zs_level), "rs232", zsc->zsc_dev.dv_xname);
145 
146 	/*
147 	 * Now safe to install interrupt handlers.  Note the arguments
148 	 * to the interrupt handlers aren't used.  Note, we only do this
149 	 * once since both SCCs interrupt at the same level and vector.
150 	 */
151 	if (didintr == 0) {
152 		didintr = 1;
153 		pccintr_establish(PCCV_ZS, zshard_shared, zs_level, zsc, NULL);
154 	}
155 
156 	/* Sanity check the interrupt levels. */
157 	ir = pcc_reg_read(sys_pcc, PCCREG_SERIAL_INTR_CTRL);
158 	if (((ir & PCC_IMASK) != 0) &&
159 	    ((ir & PCC_IMASK) != zs_level))
160 		panic("zs_pcc_attach: zs configured at different IPLs");
161 
162 	/*
163 	 * Set master interrupt enable. Vector is supplied by the PCC.
164 	 */
165 	pcc_reg_write(sys_pcc, PCCREG_SERIAL_INTR_CTRL,
166 	    zs_level | PCC_IENABLE | PCC_ZSEXTERN);
167 	zs_write_reg(zsc->zsc_cs[0], 2, PCC_VECBASE + PCCV_ZS);
168 	zs_write_reg(zsc->zsc_cs[0], 9, zs_init_reg[9]);
169 }
170 
171 /****************************************************************
172  * Console support functions (MVME PCC specific!)
173  ****************************************************************/
174 
175 /*
176  * Check for SCC console.  The MVME-147 always uses unit 0 chan 0.
177  */
178 void
179 zsc_pcccnprobe(cp)
180 	struct consdev *cp;
181 {
182 	extern const struct cdevsw zstty_cdevsw;
183 
184 	if (machineid != MVME_147) {
185 		cp->cn_pri = CN_DEAD;
186 		return;
187 	}
188 
189 	/* Initialize required fields. */
190 	cp->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0);
191 	cp->cn_pri = CN_NORMAL;
192 }
193 
194 void
195 zsc_pcccninit(cp)
196 	struct consdev *cp;
197 {
198 	bus_space_handle_t bush;
199 	struct zsdevice zs;
200 
201 	bus_space_map(&_mainbus_space_tag,
202 	    intiobase_phys + MAINBUS_PCC_OFFSET + PCC_ZS0_OFF, 4, 0, &bush);
203 
204 	/* XXX: This is a gross hack. I need to bus-space zs.c ... */
205 	zs.zs_chan_b.zc_csr = (volatile u_char *) bush;
206 	zs.zs_chan_b.zc_data = (volatile u_char *) bush + 1;
207 	zs.zs_chan_a.zc_csr = (volatile u_char *) bush + 2;
208 	zs.zs_chan_a.zc_data = (volatile u_char *) bush + 3;
209 
210 	/* Do common parts of console init. */
211 	zs_cnconfig(0, 0, &zs, PCLK_147);
212 }
213