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