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