1 /* $NetBSD: zs_pcc.c,v 1.20 2008/03/29 19:15:35 tsutsui Exp $ */
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross and Jason R. Thorpe.
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>
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: zs_pcc.c,v 1.20 2008/03/29 19:15:35 tsutsui Exp $");
44 #include <sys/param.h>
45 #include <sys/systm.h>
47 #include <sys/device.h>
50 #include <sys/ioctl.h>
53 #include <sys/kernel.h>
54 #include <sys/syslog.h>
57 #include <dev/ic/z8530reg.h>
58 #include <machine/z8530var.h>
60 #include <machine/cpu.h>
61 #include <machine/bus.h>
63 #include <mvme68k/dev/mainbus.h>
64 #include <mvme68k/dev/pccreg.h>
65 #include <mvme68k/dev/pccvar.h>
66 #include <mvme68k/dev/zsvar.h>
70 /* Definition of the driver for autoconfig. */
71 static int zsc_pcc_match(device_t
, cfdata_t
, void *);
72 static void zsc_pcc_attach(device_t
, device_t
, void *);
74 CFATTACH_DECL_NEW(zsc_pcc
, sizeof(struct zsc_softc
),
75 zsc_pcc_match
, zsc_pcc_attach
, NULL
, NULL
);
81 * Is the zs chip present?
84 zsc_pcc_match(device_t parent
, cfdata_t cf
, void *aux
)
86 struct pcc_attach_args
*pa
= aux
;
88 if (strcmp(pa
->pa_name
, zsc_cd
.cd_name
))
91 pa
->pa_ipl
= cf
->pcccf_ipl
;
93 pa
->pa_ipl
= ZSHARD_PRI
;
100 * Match slave number to zs unit number, so that misconfiguration will
101 * not set up the keyboard as ttya, etc.
104 zsc_pcc_attach(device_t parent
, device_t self
, void *aux
)
106 struct zsc_softc
*zsc
= device_private(self
);
107 struct pcc_attach_args
*pa
= aux
;
109 bus_space_handle_t bush
;
115 /* Map the device's registers */
116 bus_space_map(pa
->pa_bust
, pa
->pa_offset
, 4, 0, &bush
);
118 zs_level
= pa
->pa_ipl
;
120 /* XXX: This is a gross hack. I need to bus-space zs.c ... */
121 zs
.zs_chan_b
.zc_csr
= (volatile uint8_t *)bush
;
122 zs
.zs_chan_b
.zc_data
= (volatile uint8_t *)bush
+ 1;
123 zs
.zs_chan_a
.zc_csr
= (volatile uint8_t *)bush
+ 2;
124 zs
.zs_chan_a
.zc_data
= (volatile uint8_t *)bush
+ 3;
127 * Do common parts of SCC configuration.
128 * Note that the vector is not actually used by the ZS chip on
129 * MVME-147. We set up the PCC so that it provides the vector.
130 * This is just here so the real vector is printed at config time.
132 zs_config(zsc
, &zs
, PCC_VECBASE
+ PCCV_ZS
, PCLK_147
);
134 evcnt_attach_dynamic(&zsc
->zsc_evcnt
, EVCNT_TYPE_INTR
,
135 pccintr_evcnt(zs_level
), "rs232", device_xname(zsc
->zsc_dev
));
138 * Now safe to install interrupt handlers. Note the arguments
139 * to the interrupt handlers aren't used. Note, we only do this
140 * once since both SCCs interrupt at the same level and vector.
144 pccintr_establish(PCCV_ZS
, zshard_shared
, zs_level
, zsc
, NULL
);
147 /* Sanity check the interrupt levels. */
148 ir
= pcc_reg_read(sys_pcc
, PCCREG_SERIAL_INTR_CTRL
);
149 if (((ir
& PCC_IMASK
) != 0) &&
150 ((ir
& PCC_IMASK
) != zs_level
))
151 panic("%s: zs configured at different IPLs", __func__
);
154 * Set master interrupt enable. Vector is supplied by the PCC.
156 pcc_reg_write(sys_pcc
, PCCREG_SERIAL_INTR_CTRL
,
157 zs_level
| PCC_IENABLE
| PCC_ZSEXTERN
);
158 zs_write_reg(zsc
->zsc_cs
[0], 2, PCC_VECBASE
+ PCCV_ZS
);
159 zs_write_reg(zsc
->zsc_cs
[0], 9, zs_init_reg
[9]);
162 /****************************************************************
163 * Console support functions (MVME PCC specific!)
164 ****************************************************************/
167 * Check for SCC console. The MVME-147 always uses unit 0 chan 0.
170 zsc_pcccnprobe(struct consdev
*cp
)
172 extern const struct cdevsw zstty_cdevsw
;
174 if (machineid
!= MVME_147
) {
175 cp
->cn_pri
= CN_DEAD
;
179 /* Initialize required fields. */
180 cp
->cn_dev
= makedev(cdevsw_lookup_major(&zstty_cdevsw
), 0);
181 cp
->cn_pri
= CN_NORMAL
;
185 zsc_pcccninit(struct consdev
*cp
)
187 bus_space_handle_t bush
;
190 bus_space_map(&_mainbus_space_tag
,
191 intiobase_phys
+ MAINBUS_PCC_OFFSET
+ PCC_ZS0_OFF
, 4, 0, &bush
);
193 /* XXX: This is a gross hack. I need to bus-space zs.c ... */
194 zs
.zs_chan_b
.zc_csr
= (volatile uint8_t *)bush
;
195 zs
.zs_chan_b
.zc_data
= (volatile uint8_t *)bush
+ 1;
196 zs
.zs_chan_a
.zc_csr
= (volatile uint8_t *)bush
+ 2;
197 zs
.zs_chan_a
.zc_data
= (volatile uint8_t *)bush
+ 3;
199 /* Do common parts of console init. */
200 zs_cnconfig(0, 0, &zs
, PCLK_147
);