xref: /netbsd/sys/arch/mvme68k/dev/zs_pcctwo.c (revision c4a72b64)
1 /*	$NetBSD: zs_pcctwo.c,v 1.8 2002/10/02 05:28:16 thorpej Exp $	*/
2 
3 /*-
4  * Copyright (c) 2000 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, Jason R. Thorpe and Steve C. Woodford.
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  * Modified to attach to the PCCchip2/MCchip backend by Steve Woodford.
48  */
49 
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/proc.h>
53 #include <sys/device.h>
54 #include <sys/conf.h>
55 #include <sys/file.h>
56 #include <sys/ioctl.h>
57 #include <sys/tty.h>
58 #include <sys/time.h>
59 #include <sys/kernel.h>
60 #include <sys/syslog.h>
61 
62 #include <dev/cons.h>
63 #include <dev/ic/z8530reg.h>
64 #include <machine/z8530var.h>
65 
66 #include <machine/cpu.h>
67 #include <machine/bus.h>
68 
69 #include <dev/mvme/pcctworeg.h>
70 #include <dev/mvme/pcctwovar.h>
71 
72 #include <mvme68k/dev/mainbus.h>
73 #include <mvme68k/dev/zsvar.h>
74 
75 
76 /* Definition of the driver for autoconfig. */
77 static int	zsc_pcctwo_match(struct device *, struct cfdata *, void *);
78 static void	zsc_pcctwo_attach(struct device *, struct device *, void *);
79 
80 CFATTACH_DECL(zsc_pcctwo, sizeof(struct zsc_softc),
81     zsc_pcctwo_match, zsc_pcctwo_attach, NULL, NULL);
82 
83 extern struct cfdriver zsc_cd;
84 
85 cons_decl(zsc_pcctwo);
86 
87 
88 /*
89  * Is the zs chip present?
90  */
91 static int
92 zsc_pcctwo_match(parent, cf, aux)
93 	struct device *parent;
94 	struct cfdata *cf;
95 	void *aux;
96 {
97 	struct pcctwo_attach_args *pa = aux;
98 
99 	if (strcmp(pa->pa_name, zsc_cd.cd_name) ||
100 	    (machineid != MVME_162 && machineid != MVME_172))
101 		return (0);
102 
103 	pa->pa_ipl = cf->pcctwocf_ipl;
104 	if (pa->pa_ipl == -1)
105 		pa->pa_ipl = ZSHARD_PRI;
106 	return (1);
107 }
108 
109 /*
110  * Attach a found zs.
111  */
112 static void
113 zsc_pcctwo_attach(parent, self, aux)
114 	struct device *parent;
115 	struct device *self;
116 	void *aux;
117 {
118 	struct zsc_softc *zsc = (void *) self;
119 	struct pcctwo_attach_args *pa = aux;
120 	struct zsdevice zs;
121 	bus_space_handle_t bush;
122 	int zs_level;
123 	static int vector = MCCHIPV_ZS0;
124 
125 	/* Map the device's registers */
126 	bus_space_map(pa->pa_bust, pa->pa_offset, 8, 0, &bush);
127 
128 	zs_level = pa->pa_ipl;
129 
130 	/* XXX: This is a gross hack. I need to bus-space zs.c ... */
131 	zs.zs_chan_b.zc_csr = (volatile u_char *) bush + 1;
132 	zs.zs_chan_b.zc_data = (volatile u_char *) bush + 3;
133 	zs.zs_chan_a.zc_csr = (volatile u_char *) bush + 5;
134 	zs.zs_chan_a.zc_data = (volatile u_char *) bush + 7;
135 
136 	/* Do common parts of SCC configuration. */
137 	zs_config(zsc, &zs, vector + PCCTWO_VECBASE, PCLK_162);
138 
139 	evcnt_attach_dynamic(&zsc->zsc_evcnt, EVCNT_TYPE_INTR,
140 	    pcctwointr_evcnt(zs_level), "rs232", zsc->zsc_dev.dv_xname);
141 
142 	/*
143 	 * Now safe to install interrupt handlers.
144 	 */
145 	pcctwointr_establish(vector++, zshard_unshared, zs_level, zsc, NULL);
146 
147 	/*
148 	 * Set master interrupt enable.
149 	 */
150 	zs_write_reg(zsc->zsc_cs[0], 9, zs_init_reg[9]);
151 }
152 
153 /****************************************************************
154  * Console support functions (MVME PCC specific!)
155  ****************************************************************/
156 
157 /*
158  * Check for SCC console.  The MVME-1x2 always uses unit 0 chan 0.
159  */
160 void
161 zsc_pcctwocnprobe(cp)
162 	struct consdev *cp;
163 {
164 	extern const struct cdevsw zstty_cdevsw;
165 
166 	if (machineid != MVME_162 && machineid != MVME_172) {
167 		cp->cn_pri = CN_DEAD;
168 		return;
169 	}
170 
171 	/* Initialize required fields. */
172 	cp->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0);
173 	cp->cn_pri = CN_NORMAL;
174 }
175 
176 void
177 zsc_pcctwocninit(cp)
178 	struct consdev *cp;
179 {
180 	bus_space_handle_t bush;
181 	struct zsdevice zs;
182 
183 	bus_space_map(&_mainbus_space_tag,
184 	    intiobase_phys + MAINBUS_PCCTWO_OFFSET + MCCHIP_ZS0_OFF, 8, 0,&bush);
185 
186 	/* XXX: This is a gross hack. I need to bus-space zs.c ... */
187 	zs.zs_chan_b.zc_csr = (volatile u_char *) bush + 1;
188 	zs.zs_chan_b.zc_data = (volatile u_char *) bush + 3;
189 	zs.zs_chan_a.zc_csr = (volatile u_char *) bush + 5;
190 	zs.zs_chan_a.zc_data = (volatile u_char *) bush + 7;
191 
192 	/* Do common parts of console init. */
193 	zs_cnconfig(0, 0, &zs, PCLK_162);
194 }
195