Home | History | Annotate | Line # | Download | only in dev
      1 /*	$NetBSD: zs_pcc.c,v 1.22 2026/04/26 18:02:57 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996 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 and Jason R. Thorpe.
      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  *
     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.
     30  */
     31 
     32 /*
     33  * Zilog Z8530 Dual UART driver (machine-dependent part)
     34  *
     35  * Runs two serial lines per chip using slave drivers.
     36  * Plain tty/async lines use the zs_async slave.
     37  *
     38  * Modified for NetBSD/mvme68k by Jason R. Thorpe <thorpej (at) NetBSD.org>
     39  */
     40 
     41 #include <sys/cdefs.h>
     42 __KERNEL_RCSID(0, "$NetBSD: zs_pcc.c,v 1.22 2026/04/26 18:02:57 thorpej Exp $");
     43 
     44 #define	_M68K_BUS_SPACE_PRIVATE
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/proc.h>
     49 #include <sys/device.h>
     50 #include <sys/conf.h>
     51 #include <sys/file.h>
     52 #include <sys/ioctl.h>
     53 #include <sys/tty.h>
     54 #include <sys/time.h>
     55 #include <sys/kernel.h>
     56 #include <sys/syslog.h>
     57 
     58 #include <dev/cons.h>
     59 #include <dev/ic/z8530reg.h>
     60 #include <machine/z8530var.h>
     61 
     62 #include <machine/cpu.h>
     63 #include <machine/bus.h>
     64 
     65 #include <mvme68k/dev/mainbus.h>
     66 #include <mvme68k/dev/pccreg.h>
     67 #include <mvme68k/dev/pccvar.h>
     68 #include <mvme68k/dev/zsvar.h>
     69 
     70 #include "ioconf.h"
     71 
     72 /* Definition of the driver for autoconfig. */
     73 static int	zsc_pcc_match(device_t, cfdata_t, void *);
     74 static void	zsc_pcc_attach(device_t, device_t, void *);
     75 
     76 CFATTACH_DECL_NEW(zsc_pcc, sizeof(struct zsc_softc),
     77     zsc_pcc_match, zsc_pcc_attach, NULL, NULL);
     78 
     79 cons_decl(zsc_pcc);
     80 
     81 
     82 /*
     83  * Is the zs chip present?
     84  */
     85 static int
     86 zsc_pcc_match(device_t parent, cfdata_t cf, void *aux)
     87 {
     88 	struct pcc_attach_args *pa = aux;
     89 
     90 	if (strcmp(pa->pa_name, zsc_cd.cd_name))
     91 		return 0;
     92 
     93 	pa->pa_ipl = cf->pcccf_ipl;
     94 	if (pa->pa_ipl == -1)
     95 		pa->pa_ipl = ZSHARD_PRI;
     96 	return 1;
     97 }
     98 
     99 /*
    100  * Attach a found zs.
    101  *
    102  * Match slave number to zs unit number, so that misconfiguration will
    103  * not set up the keyboard as ttya, etc.
    104  */
    105 static void
    106 zsc_pcc_attach(device_t parent, device_t self, void *aux)
    107 {
    108 	struct zsc_softc *zsc = device_private(self);
    109 	struct pcc_attach_args *pa = aux;
    110 	struct zsdevice zs;
    111 	bus_space_handle_t bush;
    112 	int zs_level, ir;
    113 	static int didintr;
    114 
    115 	zsc->zsc_dev = self;
    116 
    117 	/* Map the device's registers */
    118 	bus_space_map(pa->pa_bust, pa->pa_offset, 4, 0, &bush);
    119 
    120 	zs_level = pa->pa_ipl;
    121 
    122 	/* XXX: This is a gross hack. I need to bus-space zs.c ... */
    123 	zs.zs_chan_b.zc_csr = (volatile uint8_t *)bush;
    124 	zs.zs_chan_b.zc_data = (volatile uint8_t *)bush + 1;
    125 	zs.zs_chan_a.zc_csr = (volatile uint8_t *)bush + 2;
    126 	zs.zs_chan_a.zc_data = (volatile uint8_t *)bush + 3;
    127 
    128 	/*
    129 	 * Do common parts of SCC configuration.
    130 	 * Note that the vector is not actually used by the ZS chip on
    131 	 * MVME-147. We set up the PCC so that it provides the vector.
    132 	 * This is just here so the real vector is printed at config time.
    133 	 */
    134 	zs_config(zsc, &zs, PCC_VECBASE + PCCV_ZS, PCLK_147);
    135 
    136 	evcnt_attach_dynamic(&zsc->zsc_evcnt, EVCNT_TYPE_INTR,
    137 	    pccintr_evcnt(zs_level), "rs232", device_xname(zsc->zsc_dev));
    138 
    139 	/*
    140 	 * Now safe to install interrupt handlers.  Note the arguments
    141 	 * to the interrupt handlers aren't used.  Note, we only do this
    142 	 * once since both SCCs interrupt at the same level and vector.
    143 	 */
    144 	if (didintr == 0) {
    145 		didintr = 1;
    146 		pccintr_establish(PCCV_ZS, zshard_shared, zs_level, zsc, NULL);
    147 	}
    148 
    149 	/* Sanity check the interrupt levels. */
    150 	ir = pcc_reg_read(sys_pcc, PCCREG_SERIAL_INTR_CTRL);
    151 	if (((ir & PCC_IMASK) != 0) &&
    152 	    ((ir & PCC_IMASK) != zs_level))
    153 		panic("%s: zs configured at different IPLs", __func__);
    154 
    155 	/*
    156 	 * Set master interrupt enable. Vector is supplied by the PCC.
    157 	 */
    158 	pcc_reg_write(sys_pcc, PCCREG_SERIAL_INTR_CTRL,
    159 	    zs_level | PCC_IENABLE | PCC_ZSEXTERN);
    160 	zs_write_reg(zsc->zsc_cs[0], 2, PCC_VECBASE + PCCV_ZS);
    161 	zs_write_reg(zsc->zsc_cs[0], 9, zs_init_reg[9]);
    162 }
    163 
    164 /****************************************************************
    165  * Console support functions (MVME PCC specific!)
    166  ****************************************************************/
    167 
    168 /*
    169  * Check for SCC console.  The MVME-147 always uses unit 0 chan 0.
    170  */
    171 void
    172 zsc_pcccnprobe(struct consdev *cp)
    173 {
    174 	extern const struct cdevsw zstty_cdevsw;
    175 
    176 	if (machineid != MVME_147) {
    177 		cp->cn_pri = CN_DEAD;
    178 		return;
    179 	}
    180 
    181 	/* Initialize required fields. */
    182 	cp->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0);
    183 	cp->cn_pri = CN_NORMAL;
    184 }
    185 
    186 void
    187 zsc_pcccninit(struct consdev *cp)
    188 {
    189 	bus_space_handle_t bush;
    190 	struct zsdevice zs;
    191 
    192 	bus_space_map(&m68k_simple_bus_space,
    193 	    intiobase_phys + MAINBUS_PCC_OFFSET + PCC_ZS0_OFF, 4, 0, &bush);
    194 
    195 	/* XXX: This is a gross hack. I need to bus-space zs.c ... */
    196 	zs.zs_chan_b.zc_csr = (volatile uint8_t *)bush;
    197 	zs.zs_chan_b.zc_data = (volatile uint8_t *)bush + 1;
    198 	zs.zs_chan_a.zc_csr = (volatile uint8_t *)bush + 2;
    199 	zs.zs_chan_a.zc_data = (volatile uint8_t *)bush + 3;
    200 
    201 	/* Do common parts of console init. */
    202 	zs_cnconfig(0, 0, &zs, PCLK_147);
    203 }
    204