xref: /netbsd/sys/arch/mvme68k/dev/zs_pcc.c (revision ce099b40)
1*ce099b40Smartin /*	$NetBSD: zs_pcc.c,v 1.21 2008/04/28 20:23:29 martin Exp $	*/
2d80422cdSchuck 
366cbbf68Sthorpej /*-
466cbbf68Sthorpej  * Copyright (c) 1996 The NetBSD Foundation, Inc.
5d80422cdSchuck  * All rights reserved.
6d80422cdSchuck  *
766cbbf68Sthorpej  * This code is derived from software contributed to The NetBSD Foundation
866cbbf68Sthorpej  * by Gordon W. Ross and Jason R. Thorpe.
966cbbf68Sthorpej  *
10d80422cdSchuck  * Redistribution and use in source and binary forms, with or without
11d80422cdSchuck  * modification, are permitted provided that the following conditions
12d80422cdSchuck  * are met:
13d80422cdSchuck  * 1. Redistributions of source code must retain the above copyright
14d80422cdSchuck  *    notice, this list of conditions and the following disclaimer.
15d80422cdSchuck  * 2. Redistributions in binary form must reproduce the above copyright
16d80422cdSchuck  *    notice, this list of conditions and the following disclaimer in the
17d80422cdSchuck  *    documentation and/or other materials provided with the distribution.
18d80422cdSchuck  *
1966cbbf68Sthorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2066cbbf68Sthorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2166cbbf68Sthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
224229acf7Sjtc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
234229acf7Sjtc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2466cbbf68Sthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2566cbbf68Sthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2666cbbf68Sthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2766cbbf68Sthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2866cbbf68Sthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2966cbbf68Sthorpej  * POSSIBILITY OF SUCH DAMAGE.
30d80422cdSchuck  */
31d80422cdSchuck 
32d80422cdSchuck /*
33d80422cdSchuck  * Zilog Z8530 Dual UART driver (machine-dependent part)
34d80422cdSchuck  *
35d80422cdSchuck  * Runs two serial lines per chip using slave drivers.
36d80422cdSchuck  * Plain tty/async lines use the zs_async slave.
37d80422cdSchuck  *
388476e675Skeihan  * Modified for NetBSD/mvme68k by Jason R. Thorpe <thorpej@NetBSD.org>
39d80422cdSchuck  */
40d80422cdSchuck 
414b2744bfSlukem #include <sys/cdefs.h>
42*ce099b40Smartin __KERNEL_RCSID(0, "$NetBSD: zs_pcc.c,v 1.21 2008/04/28 20:23:29 martin Exp $");
434b2744bfSlukem 
44d80422cdSchuck #include <sys/param.h>
45d80422cdSchuck #include <sys/systm.h>
46d80422cdSchuck #include <sys/proc.h>
47d80422cdSchuck #include <sys/device.h>
48d80422cdSchuck #include <sys/conf.h>
49d80422cdSchuck #include <sys/file.h>
50d80422cdSchuck #include <sys/ioctl.h>
51d80422cdSchuck #include <sys/tty.h>
52d80422cdSchuck #include <sys/time.h>
53d80422cdSchuck #include <sys/kernel.h>
54d80422cdSchuck #include <sys/syslog.h>
55d80422cdSchuck 
56d80422cdSchuck #include <dev/cons.h>
57d80422cdSchuck #include <dev/ic/z8530reg.h>
58d80422cdSchuck #include <machine/z8530var.h>
59d80422cdSchuck 
60d80422cdSchuck #include <machine/cpu.h>
619c745dbdSscw #include <machine/bus.h>
62d80422cdSchuck 
639c745dbdSscw #include <mvme68k/dev/mainbus.h>
64d80422cdSchuck #include <mvme68k/dev/pccreg.h>
65d80422cdSchuck #include <mvme68k/dev/pccvar.h>
66d80422cdSchuck #include <mvme68k/dev/zsvar.h>
67d80422cdSchuck 
68a07f7c80Stsutsui #include "ioconf.h"
69d80422cdSchuck 
70d80422cdSchuck /* Definition of the driver for autoconfig. */
7102cb47caStsutsui static int	zsc_pcc_match(device_t, cfdata_t, void *);
7202cb47caStsutsui static void	zsc_pcc_attach(device_t, device_t, void *);
73d80422cdSchuck 
7402cb47caStsutsui CFATTACH_DECL_NEW(zsc_pcc, sizeof(struct zsc_softc),
75c5e91d44Sthorpej     zsc_pcc_match, zsc_pcc_attach, NULL, NULL);
76d80422cdSchuck 
779c745dbdSscw cons_decl(zsc_pcc);
789c745dbdSscw 
799c745dbdSscw 
80d80422cdSchuck /*
81d80422cdSchuck  * Is the zs chip present?
82d80422cdSchuck  */
83d80422cdSchuck static int
zsc_pcc_match(device_t parent,cfdata_t cf,void * aux)8402cb47caStsutsui zsc_pcc_match(device_t parent, cfdata_t cf, void *aux)
85d80422cdSchuck {
86d80422cdSchuck 	struct pcc_attach_args *pa = aux;
87d80422cdSchuck 
88d80422cdSchuck 	if (strcmp(pa->pa_name, zsc_cd.cd_name))
89a07f7c80Stsutsui 		return 0;
90d80422cdSchuck 
91d80422cdSchuck 	pa->pa_ipl = cf->pcccf_ipl;
92d80422cdSchuck 	if (pa->pa_ipl == -1)
93d80422cdSchuck 		pa->pa_ipl = ZSHARD_PRI;
94a07f7c80Stsutsui 	return 1;
95d80422cdSchuck }
96d80422cdSchuck 
97d80422cdSchuck /*
98d80422cdSchuck  * Attach a found zs.
99d80422cdSchuck  *
100d80422cdSchuck  * Match slave number to zs unit number, so that misconfiguration will
101d80422cdSchuck  * not set up the keyboard as ttya, etc.
102d80422cdSchuck  */
103d80422cdSchuck static void
zsc_pcc_attach(device_t parent,device_t self,void * aux)10402cb47caStsutsui zsc_pcc_attach(device_t parent, device_t self, void *aux)
105d80422cdSchuck {
10602cb47caStsutsui 	struct zsc_softc *zsc = device_private(self);
107d80422cdSchuck 	struct pcc_attach_args *pa = aux;
1087f3786d3Sscw 	struct zsdevice zs;
1099c745dbdSscw 	bus_space_handle_t bush;
110d80422cdSchuck 	int zs_level, ir;
111d80422cdSchuck 	static int didintr;
112d80422cdSchuck 
11302cb47caStsutsui 	zsc->zsc_dev = self;
11402cb47caStsutsui 
1159c745dbdSscw 	/* Map the device's registers */
1169c745dbdSscw 	bus_space_map(pa->pa_bust, pa->pa_offset, 4, 0, &bush);
1179c745dbdSscw 
118d80422cdSchuck 	zs_level = pa->pa_ipl;
119d80422cdSchuck 
1207f3786d3Sscw 	/* XXX: This is a gross hack. I need to bus-space zs.c ... */
12102cb47caStsutsui 	zs.zs_chan_b.zc_csr = (volatile uint8_t *)bush;
12202cb47caStsutsui 	zs.zs_chan_b.zc_data = (volatile uint8_t *)bush + 1;
12302cb47caStsutsui 	zs.zs_chan_a.zc_csr = (volatile uint8_t *)bush + 2;
12402cb47caStsutsui 	zs.zs_chan_a.zc_data = (volatile uint8_t *)bush + 3;
1257f3786d3Sscw 
1267f3786d3Sscw 	/*
1277f3786d3Sscw 	 * Do common parts of SCC configuration.
1287f3786d3Sscw 	 * Note that the vector is not actually used by the ZS chip on
1297f3786d3Sscw 	 * MVME-147. We set up the PCC so that it provides the vector.
1307f3786d3Sscw 	 * This is just here so the real vector is printed at config time.
1317f3786d3Sscw 	 */
1327f3786d3Sscw 	zs_config(zsc, &zs, PCC_VECBASE + PCCV_ZS, PCLK_147);
133d80422cdSchuck 
13459ba4788Sscw 	evcnt_attach_dynamic(&zsc->zsc_evcnt, EVCNT_TYPE_INTR,
13502cb47caStsutsui 	    pccintr_evcnt(zs_level), "rs232", device_xname(zsc->zsc_dev));
13659ba4788Sscw 
137d80422cdSchuck 	/*
138d80422cdSchuck 	 * Now safe to install interrupt handlers.  Note the arguments
139d80422cdSchuck 	 * to the interrupt handlers aren't used.  Note, we only do this
140d80422cdSchuck 	 * once since both SCCs interrupt at the same level and vector.
141d80422cdSchuck 	 */
142d80422cdSchuck 	if (didintr == 0) {
143d80422cdSchuck 		didintr = 1;
14459ba4788Sscw 		pccintr_establish(PCCV_ZS, zshard_shared, zs_level, zsc, NULL);
145d80422cdSchuck 	}
146d80422cdSchuck 
147d80422cdSchuck 	/* Sanity check the interrupt levels. */
1489c745dbdSscw 	ir = pcc_reg_read(sys_pcc, PCCREG_SERIAL_INTR_CTRL);
149d80422cdSchuck 	if (((ir & PCC_IMASK) != 0) &&
150d80422cdSchuck 	    ((ir & PCC_IMASK) != zs_level))
151a07f7c80Stsutsui 		panic("%s: zs configured at different IPLs", __func__);
152d80422cdSchuck 
153d80422cdSchuck 	/*
1547f3786d3Sscw 	 * Set master interrupt enable. Vector is supplied by the PCC.
155d80422cdSchuck 	 */
1569c745dbdSscw 	pcc_reg_write(sys_pcc, PCCREG_SERIAL_INTR_CTRL,
1579c745dbdSscw 	    zs_level | PCC_IENABLE | PCC_ZSEXTERN);
1587f3786d3Sscw 	zs_write_reg(zsc->zsc_cs[0], 2, PCC_VECBASE + PCCV_ZS);
1593da720dfSgwr 	zs_write_reg(zsc->zsc_cs[0], 9, zs_init_reg[9]);
160d80422cdSchuck }
161d80422cdSchuck 
162d80422cdSchuck /****************************************************************
163d80422cdSchuck  * Console support functions (MVME PCC specific!)
164d80422cdSchuck  ****************************************************************/
165d80422cdSchuck 
166d80422cdSchuck /*
167d80422cdSchuck  * Check for SCC console.  The MVME-147 always uses unit 0 chan 0.
168d80422cdSchuck  */
169d80422cdSchuck void
zsc_pcccnprobe(struct consdev * cp)170a07f7c80Stsutsui zsc_pcccnprobe(struct consdev *cp)
171d80422cdSchuck {
17277a6b82bSgehenna 	extern const struct cdevsw zstty_cdevsw;
17377a6b82bSgehenna 
174a72d37c4Sscw 	if (machineid != MVME_147) {
175d80422cdSchuck 		cp->cn_pri = CN_DEAD;
176d80422cdSchuck 		return;
177d80422cdSchuck 	}
178d80422cdSchuck 
179d80422cdSchuck 	/* Initialize required fields. */
18077a6b82bSgehenna 	cp->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0);
181d80422cdSchuck 	cp->cn_pri = CN_NORMAL;
182d80422cdSchuck }
183d80422cdSchuck 
184d80422cdSchuck void
zsc_pcccninit(struct consdev * cp)185a07f7c80Stsutsui zsc_pcccninit(struct consdev *cp)
186d80422cdSchuck {
1879c745dbdSscw 	bus_space_handle_t bush;
1887f3786d3Sscw 	struct zsdevice zs;
189d80422cdSchuck 
1907d191ffeSscw 	bus_space_map(&_mainbus_space_tag,
1917d191ffeSscw 	    intiobase_phys + MAINBUS_PCC_OFFSET + PCC_ZS0_OFF, 4, 0, &bush);
192d80422cdSchuck 
1937f3786d3Sscw 	/* XXX: This is a gross hack. I need to bus-space zs.c ... */
19402cb47caStsutsui 	zs.zs_chan_b.zc_csr = (volatile uint8_t *)bush;
19502cb47caStsutsui 	zs.zs_chan_b.zc_data = (volatile uint8_t *)bush + 1;
19602cb47caStsutsui 	zs.zs_chan_a.zc_csr = (volatile uint8_t *)bush + 2;
19702cb47caStsutsui 	zs.zs_chan_a.zc_data = (volatile uint8_t *)bush + 3;
1987f3786d3Sscw 
199d80422cdSchuck 	/* Do common parts of console init. */
2007f3786d3Sscw 	zs_cnconfig(0, 0, &zs, PCLK_147);
201d80422cdSchuck }
202