zs_pcctwo.c revision 1.5 1 1.5 scw /* $NetBSD: zs_pcctwo.c,v 1.5 2002/02/12 20:38:34 scw Exp $ */
2 1.1 scw
3 1.1 scw /*-
4 1.1 scw * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1 scw * All rights reserved.
6 1.1 scw *
7 1.1 scw * This code is derived from software contributed to The NetBSD Foundation
8 1.1 scw * by Gordon W. Ross, Jason R. Thorpe and Steve C. Woodford.
9 1.1 scw *
10 1.1 scw * Redistribution and use in source and binary forms, with or without
11 1.1 scw * modification, are permitted provided that the following conditions
12 1.1 scw * are met:
13 1.1 scw * 1. Redistributions of source code must retain the above copyright
14 1.1 scw * notice, this list of conditions and the following disclaimer.
15 1.1 scw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 scw * notice, this list of conditions and the following disclaimer in the
17 1.1 scw * documentation and/or other materials provided with the distribution.
18 1.1 scw * 3. All advertising materials mentioning features or use of this software
19 1.1 scw * must display the following acknowledgement:
20 1.1 scw * This product includes software developed by the NetBSD
21 1.1 scw * Foundation, Inc. and its contributors.
22 1.1 scw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 scw * contributors may be used to endorse or promote products derived
24 1.1 scw * from this software without specific prior written permission.
25 1.1 scw *
26 1.1 scw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 scw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 scw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 scw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 scw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 scw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 scw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 scw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 scw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 scw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 scw * POSSIBILITY OF SUCH DAMAGE.
37 1.1 scw */
38 1.1 scw
39 1.1 scw /*
40 1.1 scw * Zilog Z8530 Dual UART driver (machine-dependent part)
41 1.1 scw *
42 1.1 scw * Runs two serial lines per chip using slave drivers.
43 1.1 scw * Plain tty/async lines use the zs_async slave.
44 1.1 scw *
45 1.1 scw * Modified for NetBSD/mvme68k by Jason R. Thorpe <thorpej (at) NetBSD.ORG>
46 1.1 scw *
47 1.1 scw * Modified to attach to the PCCchip2/MCchip backend by Steve Woodford.
48 1.1 scw */
49 1.1 scw
50 1.1 scw #include <sys/param.h>
51 1.1 scw #include <sys/systm.h>
52 1.1 scw #include <sys/proc.h>
53 1.1 scw #include <sys/device.h>
54 1.1 scw #include <sys/conf.h>
55 1.1 scw #include <sys/file.h>
56 1.1 scw #include <sys/ioctl.h>
57 1.1 scw #include <sys/tty.h>
58 1.1 scw #include <sys/time.h>
59 1.1 scw #include <sys/kernel.h>
60 1.1 scw #include <sys/syslog.h>
61 1.1 scw
62 1.1 scw #include <dev/cons.h>
63 1.1 scw #include <dev/ic/z8530reg.h>
64 1.1 scw #include <machine/z8530var.h>
65 1.1 scw
66 1.1 scw #include <machine/cpu.h>
67 1.1 scw #include <machine/bus.h>
68 1.1 scw
69 1.5 scw #include <dev/mvme/pcctworeg.h>
70 1.5 scw #include <dev/mvme/pcctwovar.h>
71 1.5 scw
72 1.1 scw #include <mvme68k/dev/mainbus.h>
73 1.1 scw #include <mvme68k/dev/zsvar.h>
74 1.1 scw
75 1.1 scw
76 1.1 scw /* Definition of the driver for autoconfig. */
77 1.1 scw static int zsc_pcctwo_match(struct device *, struct cfdata *, void *);
78 1.1 scw static void zsc_pcctwo_attach(struct device *, struct device *, void *);
79 1.1 scw
80 1.1 scw struct cfattach zsc_pcctwo_ca = {
81 1.1 scw sizeof(struct zsc_softc), zsc_pcctwo_match, zsc_pcctwo_attach
82 1.1 scw };
83 1.1 scw
84 1.1 scw extern struct cfdriver zsc_cd;
85 1.1 scw
86 1.1 scw cons_decl(zsc_pcctwo);
87 1.1 scw
88 1.1 scw
89 1.1 scw /*
90 1.1 scw * Is the zs chip present?
91 1.1 scw */
92 1.1 scw static int
93 1.1 scw zsc_pcctwo_match(parent, cf, aux)
94 1.1 scw struct device *parent;
95 1.1 scw struct cfdata *cf;
96 1.1 scw void *aux;
97 1.1 scw {
98 1.1 scw struct pcctwo_attach_args *pa = aux;
99 1.1 scw
100 1.2 scw if (strcmp(pa->pa_name, zsc_cd.cd_name) ||
101 1.2 scw (machineid != MVME_162 && machineid != MVME_172))
102 1.1 scw return (0);
103 1.1 scw
104 1.1 scw pa->pa_ipl = cf->pcctwocf_ipl;
105 1.1 scw if (pa->pa_ipl == -1)
106 1.1 scw pa->pa_ipl = ZSHARD_PRI;
107 1.1 scw return (1);
108 1.1 scw }
109 1.1 scw
110 1.1 scw /*
111 1.1 scw * Attach a found zs.
112 1.1 scw */
113 1.1 scw static void
114 1.1 scw zsc_pcctwo_attach(parent, self, aux)
115 1.1 scw struct device *parent;
116 1.1 scw struct device *self;
117 1.1 scw void *aux;
118 1.1 scw {
119 1.1 scw struct zsc_softc *zsc = (void *) self;
120 1.1 scw struct pcctwo_attach_args *pa = aux;
121 1.1 scw struct zsdevice zs;
122 1.1 scw bus_space_handle_t bush;
123 1.1 scw int zs_level;
124 1.1 scw static int vector = MCCHIPV_ZS0;
125 1.1 scw
126 1.1 scw /* Map the device's registers */
127 1.1 scw bus_space_map(pa->pa_bust, pa->pa_offset, 8, 0, &bush);
128 1.1 scw
129 1.1 scw zs_level = pa->pa_ipl;
130 1.1 scw
131 1.1 scw /* XXX: This is a gross hack. I need to bus-space zs.c ... */
132 1.1 scw zs.zs_chan_b.zc_csr = (volatile u_char *) bush + 1;
133 1.1 scw zs.zs_chan_b.zc_data = (volatile u_char *) bush + 3;
134 1.1 scw zs.zs_chan_a.zc_csr = (volatile u_char *) bush + 5;
135 1.1 scw zs.zs_chan_a.zc_data = (volatile u_char *) bush + 7;
136 1.1 scw
137 1.1 scw /* Do common parts of SCC configuration. */
138 1.1 scw zs_config(zsc, &zs, vector + PCCTWO_VECBASE, PCLK_162);
139 1.1 scw
140 1.4 scw evcnt_attach_dynamic(&zsc->zsc_evcnt, EVCNT_TYPE_INTR,
141 1.4 scw pcctwointr_evcnt(zs_level), "rs232", zsc->zsc_dev.dv_xname);
142 1.4 scw
143 1.1 scw /*
144 1.1 scw * Now safe to install interrupt handlers.
145 1.1 scw */
146 1.4 scw pcctwointr_establish(vector++, zshard_unshared, zs_level, zsc, NULL);
147 1.1 scw
148 1.1 scw /*
149 1.1 scw * Set master interrupt enable.
150 1.1 scw */
151 1.1 scw zs_write_reg(zsc->zsc_cs[0], 9, zs_init_reg[9]);
152 1.1 scw }
153 1.1 scw
154 1.1 scw /****************************************************************
155 1.1 scw * Console support functions (MVME PCC specific!)
156 1.1 scw ****************************************************************/
157 1.1 scw
158 1.1 scw /*
159 1.2 scw * Check for SCC console. The MVME-1x2 always uses unit 0 chan 0.
160 1.1 scw */
161 1.1 scw void
162 1.1 scw zsc_pcctwocnprobe(cp)
163 1.1 scw struct consdev *cp;
164 1.1 scw {
165 1.2 scw if (machineid != MVME_162 && machineid != MVME_172) {
166 1.1 scw cp->cn_pri = CN_DEAD;
167 1.1 scw return;
168 1.1 scw }
169 1.1 scw
170 1.1 scw /* Initialize required fields. */
171 1.1 scw cp->cn_dev = makedev(zs_major, 0);
172 1.1 scw cp->cn_pri = CN_NORMAL;
173 1.1 scw }
174 1.1 scw
175 1.1 scw void
176 1.1 scw zsc_pcctwocninit(cp)
177 1.1 scw struct consdev *cp;
178 1.1 scw {
179 1.1 scw bus_space_handle_t bush;
180 1.1 scw struct zsdevice zs;
181 1.1 scw
182 1.3 scw bus_space_map(&_mainbus_space_tag,
183 1.3 scw intiobase_phys + MAINBUS_PCCTWO_OFFSET + MCCHIP_ZS0_OFF, 8, 0,&bush);
184 1.1 scw
185 1.1 scw /* XXX: This is a gross hack. I need to bus-space zs.c ... */
186 1.1 scw zs.zs_chan_b.zc_csr = (volatile u_char *) bush + 1;
187 1.1 scw zs.zs_chan_b.zc_data = (volatile u_char *) bush + 3;
188 1.1 scw zs.zs_chan_a.zc_csr = (volatile u_char *) bush + 5;
189 1.1 scw zs.zs_chan_a.zc_data = (volatile u_char *) bush + 7;
190 1.1 scw
191 1.1 scw /* Do common parts of console init. */
192 1.1 scw zs_cnconfig(0, 0, &zs, PCLK_162);
193 1.1 scw }
194