1 1.14 martin /* $NetBSD: zs_pcctwo.c,v 1.14 2008/04/28 20:23:29 martin Exp $ */ 2 1.1 scw 3 1.1 scw /*- 4 1.1 scw * Copyright (c) 2000 The NetBSD Foundation, Inc. 5 1.1 scw * All rights reserved. 6 1.1 scw * 7 1.1 scw * This code is derived from software contributed to The NetBSD Foundation 8 1.1 scw * by Gordon W. Ross, Jason R. Thorpe and Steve C. Woodford. 9 1.1 scw * 10 1.1 scw * Redistribution and use in source and binary forms, with or without 11 1.1 scw * modification, are permitted provided that the following conditions 12 1.1 scw * are met: 13 1.1 scw * 1. Redistributions of source code must retain the above copyright 14 1.1 scw * notice, this list of conditions and the following disclaimer. 15 1.1 scw * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 scw * notice, this list of conditions and the following disclaimer in the 17 1.1 scw * documentation and/or other materials provided with the distribution. 18 1.1 scw * 19 1.1 scw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 scw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 scw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 scw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 scw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 scw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 scw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 scw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 scw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 scw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 scw * POSSIBILITY OF SUCH DAMAGE. 30 1.1 scw */ 31 1.1 scw 32 1.1 scw /* 33 1.1 scw * Zilog Z8530 Dual UART driver (machine-dependent part) 34 1.1 scw * 35 1.1 scw * Runs two serial lines per chip using slave drivers. 36 1.1 scw * Plain tty/async lines use the zs_async slave. 37 1.1 scw * 38 1.10 keihan * Modified for NetBSD/mvme68k by Jason R. Thorpe <thorpej (at) NetBSD.org> 39 1.1 scw * 40 1.1 scw * Modified to attach to the PCCchip2/MCchip backend by Steve Woodford. 41 1.1 scw */ 42 1.9 lukem 43 1.9 lukem #include <sys/cdefs.h> 44 1.14 martin __KERNEL_RCSID(0, "$NetBSD: zs_pcctwo.c,v 1.14 2008/04/28 20:23:29 martin Exp $"); 45 1.1 scw 46 1.1 scw #include <sys/param.h> 47 1.1 scw #include <sys/systm.h> 48 1.1 scw #include <sys/proc.h> 49 1.1 scw #include <sys/device.h> 50 1.1 scw #include <sys/conf.h> 51 1.1 scw #include <sys/file.h> 52 1.1 scw #include <sys/ioctl.h> 53 1.1 scw #include <sys/tty.h> 54 1.1 scw #include <sys/time.h> 55 1.1 scw #include <sys/kernel.h> 56 1.1 scw #include <sys/syslog.h> 57 1.1 scw 58 1.1 scw #include <dev/cons.h> 59 1.1 scw #include <dev/ic/z8530reg.h> 60 1.1 scw #include <machine/z8530var.h> 61 1.1 scw 62 1.1 scw #include <machine/cpu.h> 63 1.1 scw #include <machine/bus.h> 64 1.1 scw 65 1.5 scw #include <dev/mvme/pcctworeg.h> 66 1.5 scw #include <dev/mvme/pcctwovar.h> 67 1.5 scw 68 1.1 scw #include <mvme68k/dev/mainbus.h> 69 1.1 scw #include <mvme68k/dev/zsvar.h> 70 1.1 scw 71 1.12 tsutsui #include "ioconf.h" 72 1.1 scw 73 1.1 scw /* Definition of the driver for autoconfig. */ 74 1.13 tsutsui static int zsc_pcctwo_match(device_t, cfdata_t, void *); 75 1.13 tsutsui static void zsc_pcctwo_attach(device_t, device_t, void *); 76 1.1 scw 77 1.13 tsutsui CFATTACH_DECL_NEW(zsc_pcctwo, sizeof(struct zsc_softc), 78 1.8 thorpej zsc_pcctwo_match, zsc_pcctwo_attach, NULL, NULL); 79 1.1 scw 80 1.1 scw cons_decl(zsc_pcctwo); 81 1.1 scw 82 1.1 scw 83 1.1 scw /* 84 1.1 scw * Is the zs chip present? 85 1.1 scw */ 86 1.1 scw static int 87 1.13 tsutsui zsc_pcctwo_match(device_t parent, cfdata_t cf, void *aux) 88 1.1 scw { 89 1.1 scw struct pcctwo_attach_args *pa = aux; 90 1.1 scw 91 1.2 scw if (strcmp(pa->pa_name, zsc_cd.cd_name) || 92 1.2 scw (machineid != MVME_162 && machineid != MVME_172)) 93 1.12 tsutsui return 0; 94 1.1 scw 95 1.1 scw pa->pa_ipl = cf->pcctwocf_ipl; 96 1.1 scw if (pa->pa_ipl == -1) 97 1.1 scw pa->pa_ipl = ZSHARD_PRI; 98 1.12 tsutsui return 1; 99 1.1 scw } 100 1.1 scw 101 1.1 scw /* 102 1.1 scw * Attach a found zs. 103 1.1 scw */ 104 1.1 scw static void 105 1.13 tsutsui zsc_pcctwo_attach(device_t parent, device_t self, void *aux) 106 1.1 scw { 107 1.13 tsutsui struct zsc_softc *zsc = device_private(self); 108 1.1 scw struct pcctwo_attach_args *pa = aux; 109 1.1 scw struct zsdevice zs; 110 1.1 scw bus_space_handle_t bush; 111 1.1 scw int zs_level; 112 1.1 scw static int vector = MCCHIPV_ZS0; 113 1.1 scw 114 1.13 tsutsui zsc->zsc_dev = self; 115 1.13 tsutsui 116 1.1 scw /* Map the device's registers */ 117 1.1 scw bus_space_map(pa->pa_bust, pa->pa_offset, 8, 0, &bush); 118 1.1 scw 119 1.1 scw zs_level = pa->pa_ipl; 120 1.1 scw 121 1.1 scw /* XXX: This is a gross hack. I need to bus-space zs.c ... */ 122 1.13 tsutsui zs.zs_chan_b.zc_csr = (volatile uint8_t *)bush + 1; 123 1.13 tsutsui zs.zs_chan_b.zc_data = (volatile uint8_t *)bush + 3; 124 1.13 tsutsui zs.zs_chan_a.zc_csr = (volatile uint8_t *)bush + 5; 125 1.13 tsutsui zs.zs_chan_a.zc_data = (volatile uint8_t *)bush + 7; 126 1.1 scw 127 1.1 scw /* Do common parts of SCC configuration. */ 128 1.1 scw zs_config(zsc, &zs, vector + PCCTWO_VECBASE, PCLK_162); 129 1.1 scw 130 1.4 scw evcnt_attach_dynamic(&zsc->zsc_evcnt, EVCNT_TYPE_INTR, 131 1.13 tsutsui pcctwointr_evcnt(zs_level), "rs232", device_xname(zsc->zsc_dev)); 132 1.4 scw 133 1.1 scw /* 134 1.1 scw * Now safe to install interrupt handlers. 135 1.1 scw */ 136 1.4 scw pcctwointr_establish(vector++, zshard_unshared, zs_level, zsc, NULL); 137 1.1 scw 138 1.1 scw /* 139 1.1 scw * Set master interrupt enable. 140 1.1 scw */ 141 1.1 scw zs_write_reg(zsc->zsc_cs[0], 9, zs_init_reg[9]); 142 1.1 scw } 143 1.1 scw 144 1.1 scw /**************************************************************** 145 1.1 scw * Console support functions (MVME PCC specific!) 146 1.1 scw ****************************************************************/ 147 1.1 scw 148 1.1 scw /* 149 1.2 scw * Check for SCC console. The MVME-1x2 always uses unit 0 chan 0. 150 1.1 scw */ 151 1.1 scw void 152 1.12 tsutsui zsc_pcctwocnprobe(struct consdev *cp) 153 1.1 scw { 154 1.6 gehenna extern const struct cdevsw zstty_cdevsw; 155 1.6 gehenna 156 1.2 scw if (machineid != MVME_162 && machineid != MVME_172) { 157 1.1 scw cp->cn_pri = CN_DEAD; 158 1.1 scw return; 159 1.1 scw } 160 1.1 scw 161 1.1 scw /* Initialize required fields. */ 162 1.6 gehenna cp->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0); 163 1.1 scw cp->cn_pri = CN_NORMAL; 164 1.1 scw } 165 1.1 scw 166 1.1 scw void 167 1.12 tsutsui zsc_pcctwocninit(struct consdev *cp) 168 1.1 scw { 169 1.1 scw bus_space_handle_t bush; 170 1.1 scw struct zsdevice zs; 171 1.1 scw 172 1.3 scw bus_space_map(&_mainbus_space_tag, 173 1.12 tsutsui intiobase_phys + MAINBUS_PCCTWO_OFFSET + MCCHIP_ZS0_OFF, 8, 0, 174 1.12 tsutsui &bush); 175 1.1 scw 176 1.1 scw /* XXX: This is a gross hack. I need to bus-space zs.c ... */ 177 1.13 tsutsui zs.zs_chan_b.zc_csr = (volatile uint8_t *)bush + 1; 178 1.13 tsutsui zs.zs_chan_b.zc_data = (volatile uint8_t *)bush + 3; 179 1.13 tsutsui zs.zs_chan_a.zc_csr = (volatile uint8_t *)bush + 5; 180 1.13 tsutsui zs.zs_chan_a.zc_data = (volatile uint8_t *)bush + 7; 181 1.1 scw 182 1.1 scw /* Do common parts of console init. */ 183 1.1 scw zs_cnconfig(0, 0, &zs, PCLK_162); 184 1.1 scw } 185