zs_pcc.c revision 1.20 1 /* $NetBSD: zs_pcc.c,v 1.20 2008/03/29 19:15:35 tsutsui 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 (at) NetBSD.org>
46 */
47
48 #include <sys/cdefs.h>
49 __KERNEL_RCSID(0, "$NetBSD: zs_pcc.c,v 1.20 2008/03/29 19:15:35 tsutsui Exp $");
50
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/proc.h>
54 #include <sys/device.h>
55 #include <sys/conf.h>
56 #include <sys/file.h>
57 #include <sys/ioctl.h>
58 #include <sys/tty.h>
59 #include <sys/time.h>
60 #include <sys/kernel.h>
61 #include <sys/syslog.h>
62
63 #include <dev/cons.h>
64 #include <dev/ic/z8530reg.h>
65 #include <machine/z8530var.h>
66
67 #include <machine/cpu.h>
68 #include <machine/bus.h>
69
70 #include <mvme68k/dev/mainbus.h>
71 #include <mvme68k/dev/pccreg.h>
72 #include <mvme68k/dev/pccvar.h>
73 #include <mvme68k/dev/zsvar.h>
74
75 #include "ioconf.h"
76
77 /* Definition of the driver for autoconfig. */
78 static int zsc_pcc_match(device_t, cfdata_t, void *);
79 static void zsc_pcc_attach(device_t, device_t, void *);
80
81 CFATTACH_DECL_NEW(zsc_pcc, sizeof(struct zsc_softc),
82 zsc_pcc_match, zsc_pcc_attach, NULL, NULL);
83
84 cons_decl(zsc_pcc);
85
86
87 /*
88 * Is the zs chip present?
89 */
90 static int
91 zsc_pcc_match(device_t parent, cfdata_t cf, void *aux)
92 {
93 struct pcc_attach_args *pa = aux;
94
95 if (strcmp(pa->pa_name, zsc_cd.cd_name))
96 return 0;
97
98 pa->pa_ipl = cf->pcccf_ipl;
99 if (pa->pa_ipl == -1)
100 pa->pa_ipl = ZSHARD_PRI;
101 return 1;
102 }
103
104 /*
105 * Attach a found zs.
106 *
107 * Match slave number to zs unit number, so that misconfiguration will
108 * not set up the keyboard as ttya, etc.
109 */
110 static void
111 zsc_pcc_attach(device_t parent, device_t self, void *aux)
112 {
113 struct zsc_softc *zsc = device_private(self);
114 struct pcc_attach_args *pa = aux;
115 struct zsdevice zs;
116 bus_space_handle_t bush;
117 int zs_level, ir;
118 static int didintr;
119
120 zsc->zsc_dev = self;
121
122 /* Map the device's registers */
123 bus_space_map(pa->pa_bust, pa->pa_offset, 4, 0, &bush);
124
125 zs_level = pa->pa_ipl;
126
127 /* XXX: This is a gross hack. I need to bus-space zs.c ... */
128 zs.zs_chan_b.zc_csr = (volatile uint8_t *)bush;
129 zs.zs_chan_b.zc_data = (volatile uint8_t *)bush + 1;
130 zs.zs_chan_a.zc_csr = (volatile uint8_t *)bush + 2;
131 zs.zs_chan_a.zc_data = (volatile uint8_t *)bush + 3;
132
133 /*
134 * Do common parts of SCC configuration.
135 * Note that the vector is not actually used by the ZS chip on
136 * MVME-147. We set up the PCC so that it provides the vector.
137 * This is just here so the real vector is printed at config time.
138 */
139 zs_config(zsc, &zs, PCC_VECBASE + PCCV_ZS, PCLK_147);
140
141 evcnt_attach_dynamic(&zsc->zsc_evcnt, EVCNT_TYPE_INTR,
142 pccintr_evcnt(zs_level), "rs232", device_xname(zsc->zsc_dev));
143
144 /*
145 * Now safe to install interrupt handlers. Note the arguments
146 * to the interrupt handlers aren't used. Note, we only do this
147 * once since both SCCs interrupt at the same level and vector.
148 */
149 if (didintr == 0) {
150 didintr = 1;
151 pccintr_establish(PCCV_ZS, zshard_shared, zs_level, zsc, NULL);
152 }
153
154 /* Sanity check the interrupt levels. */
155 ir = pcc_reg_read(sys_pcc, PCCREG_SERIAL_INTR_CTRL);
156 if (((ir & PCC_IMASK) != 0) &&
157 ((ir & PCC_IMASK) != zs_level))
158 panic("%s: zs configured at different IPLs", __func__);
159
160 /*
161 * Set master interrupt enable. Vector is supplied by the PCC.
162 */
163 pcc_reg_write(sys_pcc, PCCREG_SERIAL_INTR_CTRL,
164 zs_level | PCC_IENABLE | PCC_ZSEXTERN);
165 zs_write_reg(zsc->zsc_cs[0], 2, PCC_VECBASE + PCCV_ZS);
166 zs_write_reg(zsc->zsc_cs[0], 9, zs_init_reg[9]);
167 }
168
169 /****************************************************************
170 * Console support functions (MVME PCC specific!)
171 ****************************************************************/
172
173 /*
174 * Check for SCC console. The MVME-147 always uses unit 0 chan 0.
175 */
176 void
177 zsc_pcccnprobe(struct consdev *cp)
178 {
179 extern const struct cdevsw zstty_cdevsw;
180
181 if (machineid != MVME_147) {
182 cp->cn_pri = CN_DEAD;
183 return;
184 }
185
186 /* Initialize required fields. */
187 cp->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0);
188 cp->cn_pri = CN_NORMAL;
189 }
190
191 void
192 zsc_pcccninit(struct consdev *cp)
193 {
194 bus_space_handle_t bush;
195 struct zsdevice zs;
196
197 bus_space_map(&_mainbus_space_tag,
198 intiobase_phys + MAINBUS_PCC_OFFSET + PCC_ZS0_OFF, 4, 0, &bush);
199
200 /* XXX: This is a gross hack. I need to bus-space zs.c ... */
201 zs.zs_chan_b.zc_csr = (volatile uint8_t *)bush;
202 zs.zs_chan_b.zc_data = (volatile uint8_t *)bush + 1;
203 zs.zs_chan_a.zc_csr = (volatile uint8_t *)bush + 2;
204 zs.zs_chan_a.zc_data = (volatile uint8_t *)bush + 3;
205
206 /* Do common parts of console init. */
207 zs_cnconfig(0, 0, &zs, PCLK_147);
208 }
209