1 /* $NetBSD: zs_pcctwo.c,v 1.13 2008/03/29 19:15:35 tsutsui Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross, Jason R. Thorpe and Steve C. Woodford.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Zilog Z8530 Dual UART driver (machine-dependent part)
35 * Runs two serial lines per chip using slave drivers.
36 * Plain tty/async lines use the zs_async slave.
38 * Modified for NetBSD/mvme68k by Jason R. Thorpe <thorpej@NetBSD.org>
40 * Modified to attach to the PCCchip2/MCchip backend by Steve Woodford.
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: zs_pcctwo.c,v 1.13 2008/03/29 19:15:35 tsutsui Exp $");
46 #include <sys/param.h>
47 #include <sys/systm.h>
49 #include <sys/device.h>
52 #include <sys/ioctl.h>
55 #include <sys/kernel.h>
56 #include <sys/syslog.h>
59 #include <dev/ic/z8530reg.h>
60 #include <machine/z8530var.h>
62 #include <machine/cpu.h>
63 #include <machine/bus.h>
65 #include <dev/mvme/pcctworeg.h>
66 #include <dev/mvme/pcctwovar.h>
68 #include <mvme68k/dev/mainbus.h>
69 #include <mvme68k/dev/zsvar.h>
73 /* Definition of the driver for autoconfig. */
74 static int zsc_pcctwo_match(device_t
, cfdata_t
, void *);
75 static void zsc_pcctwo_attach(device_t
, device_t
, void *);
77 CFATTACH_DECL_NEW(zsc_pcctwo
, sizeof(struct zsc_softc
),
78 zsc_pcctwo_match
, zsc_pcctwo_attach
, NULL
, NULL
);
80 cons_decl(zsc_pcctwo
);
84 * Is the zs chip present?
87 zsc_pcctwo_match(device_t parent
, cfdata_t cf
, void *aux
)
89 struct pcctwo_attach_args
*pa
= aux
;
91 if (strcmp(pa
->pa_name
, zsc_cd
.cd_name
) ||
92 (machineid
!= MVME_162
&& machineid
!= MVME_172
))
95 pa
->pa_ipl
= cf
->pcctwocf_ipl
;
97 pa
->pa_ipl
= ZSHARD_PRI
;
105 zsc_pcctwo_attach(device_t parent
, device_t self
, void *aux
)
107 struct zsc_softc
*zsc
= device_private(self
);
108 struct pcctwo_attach_args
*pa
= aux
;
110 bus_space_handle_t bush
;
112 static int vector
= MCCHIPV_ZS0
;
116 /* Map the device's registers */
117 bus_space_map(pa
->pa_bust
, pa
->pa_offset
, 8, 0, &bush
);
119 zs_level
= pa
->pa_ipl
;
121 /* XXX: This is a gross hack. I need to bus-space zs.c ... */
122 zs
.zs_chan_b
.zc_csr
= (volatile uint8_t *)bush
+ 1;
123 zs
.zs_chan_b
.zc_data
= (volatile uint8_t *)bush
+ 3;
124 zs
.zs_chan_a
.zc_csr
= (volatile uint8_t *)bush
+ 5;
125 zs
.zs_chan_a
.zc_data
= (volatile uint8_t *)bush
+ 7;
127 /* Do common parts of SCC configuration. */
128 zs_config(zsc
, &zs
, vector
+ PCCTWO_VECBASE
, PCLK_162
);
130 evcnt_attach_dynamic(&zsc
->zsc_evcnt
, EVCNT_TYPE_INTR
,
131 pcctwointr_evcnt(zs_level
), "rs232", device_xname(zsc
->zsc_dev
));
134 * Now safe to install interrupt handlers.
136 pcctwointr_establish(vector
++, zshard_unshared
, zs_level
, zsc
, NULL
);
139 * Set master interrupt enable.
141 zs_write_reg(zsc
->zsc_cs
[0], 9, zs_init_reg
[9]);
144 /****************************************************************
145 * Console support functions (MVME PCC specific!)
146 ****************************************************************/
149 * Check for SCC console. The MVME-1x2 always uses unit 0 chan 0.
152 zsc_pcctwocnprobe(struct consdev
*cp
)
154 extern const struct cdevsw zstty_cdevsw
;
156 if (machineid
!= MVME_162
&& machineid
!= MVME_172
) {
157 cp
->cn_pri
= CN_DEAD
;
161 /* Initialize required fields. */
162 cp
->cn_dev
= makedev(cdevsw_lookup_major(&zstty_cdevsw
), 0);
163 cp
->cn_pri
= CN_NORMAL
;
167 zsc_pcctwocninit(struct consdev
*cp
)
169 bus_space_handle_t bush
;
172 bus_space_map(&_mainbus_space_tag
,
173 intiobase_phys
+ MAINBUS_PCCTWO_OFFSET
+ MCCHIP_ZS0_OFF
, 8, 0,
176 /* XXX: This is a gross hack. I need to bus-space zs.c ... */
177 zs
.zs_chan_b
.zc_csr
= (volatile uint8_t *)bush
+ 1;
178 zs
.zs_chan_b
.zc_data
= (volatile uint8_t *)bush
+ 3;
179 zs
.zs_chan_a
.zc_csr
= (volatile uint8_t *)bush
+ 5;
180 zs
.zs_chan_a
.zc_data
= (volatile uint8_t *)bush
+ 7;
182 /* Do common parts of console init. */
183 zs_cnconfig(0, 0, &zs
, PCLK_162
);