1 /* $NetBSD: zs_pcc.c,v 1.21 2008/04/28 20:23:29 martin 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@NetBSD.org> 39 */ 40 41 #include <sys/cdefs.h> 42 __KERNEL_RCSID(0, "$NetBSD: zs_pcc.c,v 1.21 2008/04/28 20:23:29 martin Exp $"); 43 44 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/proc.h> 47 #include <sys/device.h> 48 #include <sys/conf.h> 49 #include <sys/file.h> 50 #include <sys/ioctl.h> 51 #include <sys/tty.h> 52 #include <sys/time.h> 53 #include <sys/kernel.h> 54 #include <sys/syslog.h> 55 56 #include <dev/cons.h> 57 #include <dev/ic/z8530reg.h> 58 #include <machine/z8530var.h> 59 60 #include <machine/cpu.h> 61 #include <machine/bus.h> 62 63 #include <mvme68k/dev/mainbus.h> 64 #include <mvme68k/dev/pccreg.h> 65 #include <mvme68k/dev/pccvar.h> 66 #include <mvme68k/dev/zsvar.h> 67 68 #include "ioconf.h" 69 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 *); 73 74 CFATTACH_DECL_NEW(zsc_pcc, sizeof(struct zsc_softc), 75 zsc_pcc_match, zsc_pcc_attach, NULL, NULL); 76 77 cons_decl(zsc_pcc); 78 79 80 /* 81 * Is the zs chip present? 82 */ 83 static int 84 zsc_pcc_match(device_t parent, cfdata_t cf, void *aux) 85 { 86 struct pcc_attach_args *pa = aux; 87 88 if (strcmp(pa->pa_name, zsc_cd.cd_name)) 89 return 0; 90 91 pa->pa_ipl = cf->pcccf_ipl; 92 if (pa->pa_ipl == -1) 93 pa->pa_ipl = ZSHARD_PRI; 94 return 1; 95 } 96 97 /* 98 * Attach a found zs. 99 * 100 * Match slave number to zs unit number, so that misconfiguration will 101 * not set up the keyboard as ttya, etc. 102 */ 103 static void 104 zsc_pcc_attach(device_t parent, device_t self, void *aux) 105 { 106 struct zsc_softc *zsc = device_private(self); 107 struct pcc_attach_args *pa = aux; 108 struct zsdevice zs; 109 bus_space_handle_t bush; 110 int zs_level, ir; 111 static int didintr; 112 113 zsc->zsc_dev = self; 114 115 /* Map the device's registers */ 116 bus_space_map(pa->pa_bust, pa->pa_offset, 4, 0, &bush); 117 118 zs_level = pa->pa_ipl; 119 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; 125 126 /* 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. 131 */ 132 zs_config(zsc, &zs, PCC_VECBASE + PCCV_ZS, PCLK_147); 133 134 evcnt_attach_dynamic(&zsc->zsc_evcnt, EVCNT_TYPE_INTR, 135 pccintr_evcnt(zs_level), "rs232", device_xname(zsc->zsc_dev)); 136 137 /* 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. 141 */ 142 if (didintr == 0) { 143 didintr = 1; 144 pccintr_establish(PCCV_ZS, zshard_shared, zs_level, zsc, NULL); 145 } 146 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__); 152 153 /* 154 * Set master interrupt enable. Vector is supplied by the PCC. 155 */ 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]); 160 } 161 162 /**************************************************************** 163 * Console support functions (MVME PCC specific!) 164 ****************************************************************/ 165 166 /* 167 * Check for SCC console. The MVME-147 always uses unit 0 chan 0. 168 */ 169 void 170 zsc_pcccnprobe(struct consdev *cp) 171 { 172 extern const struct cdevsw zstty_cdevsw; 173 174 if (machineid != MVME_147) { 175 cp->cn_pri = CN_DEAD; 176 return; 177 } 178 179 /* Initialize required fields. */ 180 cp->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0); 181 cp->cn_pri = CN_NORMAL; 182 } 183 184 void 185 zsc_pcccninit(struct consdev *cp) 186 { 187 bus_space_handle_t bush; 188 struct zsdevice zs; 189 190 bus_space_map(&_mainbus_space_tag, 191 intiobase_phys + MAINBUS_PCC_OFFSET + PCC_ZS0_OFF, 4, 0, &bush); 192 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; 198 199 /* Do common parts of console init. */ 200 zs_cnconfig(0, 0, &zs, PCLK_147); 201 } 202