zs_pcctwo.c revision 1.4 1 1.4 scw /* $NetBSD: zs_pcctwo.c,v 1.4 2001/05/31 18:46:09 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.1 scw #include <mvme68k/dev/mainbus.h>
70 1.1 scw #include <mvme68k/dev/pcctworeg.h>
71 1.1 scw #include <mvme68k/dev/pcctwovar.h>
72 1.1 scw #include <mvme68k/dev/zsvar.h>
73 1.1 scw
74 1.1 scw
75 1.1 scw /* Definition of the driver for autoconfig. */
76 1.1 scw static int zsc_pcctwo_match(struct device *, struct cfdata *, void *);
77 1.1 scw static void zsc_pcctwo_attach(struct device *, struct device *, void *);
78 1.1 scw
79 1.1 scw struct cfattach zsc_pcctwo_ca = {
80 1.1 scw sizeof(struct zsc_softc), zsc_pcctwo_match, zsc_pcctwo_attach
81 1.1 scw };
82 1.1 scw
83 1.1 scw extern struct cfdriver zsc_cd;
84 1.1 scw
85 1.1 scw cons_decl(zsc_pcctwo);
86 1.1 scw
87 1.1 scw
88 1.1 scw /*
89 1.1 scw * Is the zs chip present?
90 1.1 scw */
91 1.1 scw static int
92 1.1 scw zsc_pcctwo_match(parent, cf, aux)
93 1.1 scw struct device *parent;
94 1.1 scw struct cfdata *cf;
95 1.1 scw void *aux;
96 1.1 scw {
97 1.1 scw struct pcctwo_attach_args *pa = aux;
98 1.1 scw
99 1.2 scw if (strcmp(pa->pa_name, zsc_cd.cd_name) ||
100 1.2 scw (machineid != MVME_162 && machineid != MVME_172))
101 1.1 scw return (0);
102 1.1 scw
103 1.1 scw pa->pa_ipl = cf->pcctwocf_ipl;
104 1.1 scw if (pa->pa_ipl == -1)
105 1.1 scw pa->pa_ipl = ZSHARD_PRI;
106 1.1 scw return (1);
107 1.1 scw }
108 1.1 scw
109 1.1 scw /*
110 1.1 scw * Attach a found zs.
111 1.1 scw */
112 1.1 scw static void
113 1.1 scw zsc_pcctwo_attach(parent, self, aux)
114 1.1 scw struct device *parent;
115 1.1 scw struct device *self;
116 1.1 scw void *aux;
117 1.1 scw {
118 1.1 scw struct zsc_softc *zsc = (void *) self;
119 1.1 scw struct pcctwo_attach_args *pa = aux;
120 1.1 scw struct zsdevice zs;
121 1.1 scw bus_space_handle_t bush;
122 1.1 scw int zs_level;
123 1.1 scw static int vector = MCCHIPV_ZS0;
124 1.1 scw
125 1.1 scw /* Map the device's registers */
126 1.1 scw bus_space_map(pa->pa_bust, pa->pa_offset, 8, 0, &bush);
127 1.1 scw
128 1.1 scw zs_level = pa->pa_ipl;
129 1.1 scw
130 1.1 scw /* XXX: This is a gross hack. I need to bus-space zs.c ... */
131 1.1 scw zs.zs_chan_b.zc_csr = (volatile u_char *) bush + 1;
132 1.1 scw zs.zs_chan_b.zc_data = (volatile u_char *) bush + 3;
133 1.1 scw zs.zs_chan_a.zc_csr = (volatile u_char *) bush + 5;
134 1.1 scw zs.zs_chan_a.zc_data = (volatile u_char *) bush + 7;
135 1.1 scw
136 1.1 scw /* Do common parts of SCC configuration. */
137 1.1 scw zs_config(zsc, &zs, vector + PCCTWO_VECBASE, PCLK_162);
138 1.1 scw
139 1.4 scw evcnt_attach_dynamic(&zsc->zsc_evcnt, EVCNT_TYPE_INTR,
140 1.4 scw pcctwointr_evcnt(zs_level), "rs232", zsc->zsc_dev.dv_xname);
141 1.4 scw
142 1.1 scw /*
143 1.1 scw * Now safe to install interrupt handlers.
144 1.1 scw */
145 1.4 scw pcctwointr_establish(vector++, zshard_unshared, zs_level, zsc, NULL);
146 1.1 scw
147 1.1 scw /*
148 1.1 scw * Set master interrupt enable.
149 1.1 scw */
150 1.1 scw zs_write_reg(zsc->zsc_cs[0], 9, zs_init_reg[9]);
151 1.1 scw }
152 1.1 scw
153 1.1 scw /****************************************************************
154 1.1 scw * Console support functions (MVME PCC specific!)
155 1.1 scw ****************************************************************/
156 1.1 scw
157 1.1 scw /*
158 1.2 scw * Check for SCC console. The MVME-1x2 always uses unit 0 chan 0.
159 1.1 scw */
160 1.1 scw void
161 1.1 scw zsc_pcctwocnprobe(cp)
162 1.1 scw struct consdev *cp;
163 1.1 scw {
164 1.2 scw if (machineid != MVME_162 && machineid != MVME_172) {
165 1.1 scw cp->cn_pri = CN_DEAD;
166 1.1 scw return;
167 1.1 scw }
168 1.1 scw
169 1.1 scw /* Initialize required fields. */
170 1.1 scw cp->cn_dev = makedev(zs_major, 0);
171 1.1 scw cp->cn_pri = CN_NORMAL;
172 1.1 scw }
173 1.1 scw
174 1.1 scw void
175 1.1 scw zsc_pcctwocninit(cp)
176 1.1 scw struct consdev *cp;
177 1.1 scw {
178 1.1 scw bus_space_handle_t bush;
179 1.1 scw struct zsdevice zs;
180 1.1 scw
181 1.3 scw bus_space_map(&_mainbus_space_tag,
182 1.3 scw intiobase_phys + MAINBUS_PCCTWO_OFFSET + MCCHIP_ZS0_OFF, 8, 0,&bush);
183 1.1 scw
184 1.1 scw /* XXX: This is a gross hack. I need to bus-space zs.c ... */
185 1.1 scw zs.zs_chan_b.zc_csr = (volatile u_char *) bush + 1;
186 1.1 scw zs.zs_chan_b.zc_data = (volatile u_char *) bush + 3;
187 1.1 scw zs.zs_chan_a.zc_csr = (volatile u_char *) bush + 5;
188 1.1 scw zs.zs_chan_a.zc_data = (volatile u_char *) bush + 7;
189 1.1 scw
190 1.1 scw /* Do common parts of console init. */
191 1.1 scw zs_cnconfig(0, 0, &zs, PCLK_162);
192 1.1 scw }
193