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