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