acemidi.c revision 1.15
11.15Sthorpej/* $NetBSD: acemidi.c,v 1.15 2018/12/08 17:46:14 thorpej Exp $ */ 21.1Sbjh21 31.1Sbjh21/*- 41.1Sbjh21 * Copyright (c) 2001 Ben Harris 51.1Sbjh21 * All rights reserved. 61.1Sbjh21 * 71.1Sbjh21 * Redistribution and use in source and binary forms, with or without 81.1Sbjh21 * modification, are permitted provided that the following conditions 91.1Sbjh21 * are met: 101.1Sbjh21 * 1. Redistributions of source code must retain the above copyright 111.1Sbjh21 * notice, this list of conditions and the following disclaimer. 121.1Sbjh21 * 2. Redistributions in binary form must reproduce the above copyright 131.1Sbjh21 * notice, this list of conditions and the following disclaimer in the 141.1Sbjh21 * documentation and/or other materials provided with the distribution. 151.1Sbjh21 * 3. The name of the author may not be used to endorse or promote products 161.1Sbjh21 * derived from this software without specific prior written permission. 171.9Sperry * 181.1Sbjh21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 191.1Sbjh21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 201.1Sbjh21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 211.1Sbjh21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 221.1Sbjh21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 231.1Sbjh21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 241.1Sbjh21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 251.1Sbjh21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 261.1Sbjh21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 271.1Sbjh21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 281.1Sbjh21 */ 291.1Sbjh21 301.3Slukem#include <sys/cdefs.h> 311.15Sthorpej__KERNEL_RCSID(0, "$NetBSD: acemidi.c,v 1.15 2018/12/08 17:46:14 thorpej Exp $"); 321.3Slukem 331.1Sbjh21#include <sys/param.h> 341.1Sbjh21 351.1Sbjh21#include <sys/device.h> 361.1Sbjh21#include <sys/systm.h> 371.1Sbjh21 381.13Sad#include <sys/bus.h> 391.1Sbjh21 401.1Sbjh21#include <dev/podulebus/podulebus.h> 411.1Sbjh21#include <dev/podulebus/podules.h> 421.1Sbjh21#include <dev/podulebus/acemidireg.h> 431.1Sbjh21 441.1Sbjh21#include <sys/termios.h> 451.1Sbjh21#include <dev/ic/comvar.h> 461.1Sbjh21#include <dev/ic/comreg.h> 471.1Sbjh21 481.1Sbjh21struct com_acemidi_softc { 491.1Sbjh21 struct com_softc sc_com; 501.1Sbjh21 struct evcnt sc_intrcnt; 511.1Sbjh21}; 521.1Sbjh21 531.14Scubestatic int acemidi_match(device_t, cfdata_t , void *); 541.14Scubestatic void acemidi_attach(device_t, device_t, void *); 551.14Scubestatic int com_acemidi_match(device_t, cfdata_t, void *); 561.14Scubestatic void com_acemidi_attach(device_t, device_t, void *); 571.1Sbjh21 581.14ScubeCFATTACH_DECL_NEW(acemidi, 0, 591.7Sthorpej acemidi_match, acemidi_attach, NULL, NULL); 601.1Sbjh21 611.14ScubeCFATTACH_DECL_NEW(com_acemidi, sizeof(struct com_acemidi_softc), 621.7Sthorpej com_acemidi_match, com_acemidi_attach, NULL, NULL); 631.1Sbjh21 641.1Sbjh21static int 651.14Scubeacemidi_match(device_t parent, cfdata_t cf, void *aux) 661.1Sbjh21{ 671.1Sbjh21 struct podulebus_attach_args *pa = aux; 681.1Sbjh21 691.4Sbjh21 if (pa->pa_product == PODULE_MIDICONNECT) 701.1Sbjh21 return 1; 711.1Sbjh21 return 0; 721.1Sbjh21} 731.1Sbjh21 741.1Sbjh21static void 751.14Scubeacemidi_attach(device_t parent, device_t self, void *aux) 761.1Sbjh21{ 771.11Sthorpej/* struct acemidi_softc *sc = device_private(self); */ 781.1Sbjh21/* struct podulebus_attach_args *pa = aux; */ 791.1Sbjh21 801.1Sbjh21 printf("\n"); 811.8Sdrochner config_found_ia(self, "acemidi", aux, NULL); 821.1Sbjh21} 831.1Sbjh21 841.1Sbjh21static int 851.14Scubecom_acemidi_match(device_t parent, cfdata_t cf, void *aux) 861.1Sbjh21{ 871.1Sbjh21 881.1Sbjh21 return 1; 891.1Sbjh21} 901.1Sbjh21 911.1Sbjh21static void 921.14Scubecom_acemidi_attach(device_t parent, device_t self, void *aux) 931.1Sbjh21{ 941.11Sthorpej struct com_acemidi_softc *sc = device_private(self); 951.1Sbjh21 struct com_softc *csc = &sc->sc_com; 961.1Sbjh21 struct podulebus_attach_args *pa = aux; 971.12Sgdamore bus_space_handle_t ioh; 981.12Sgdamore bus_space_tag_t iot; 991.12Sgdamore bus_addr_t iobase; 1001.12Sgdamore 1011.12Sgdamore iot = pa->pa_fast_t; 1021.12Sgdamore iobase = pa->pa_fast_base + ACEMIDI_16550_BASE; 1031.12Sgdamore 1041.12Sgdamore bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh); 1051.15Sthorpej com_init_regs(&csc->sc_regs, iot, ioh, iobase); 1061.1Sbjh21 1071.1Sbjh21 csc->sc_frequency = ACEMIDI_16550_FREQ; 1081.1Sbjh21 1091.1Sbjh21 com_attach_subr(csc); 1101.1Sbjh21 1111.1Sbjh21 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL, 1121.14Scube device_xname(self), "intr"); 1131.1Sbjh21 podulebus_irq_establish(pa->pa_ih, IPL_SERIAL, comintr, sc, 1141.1Sbjh21 &sc->sc_intrcnt); 1151.1Sbjh21} 1161.2Sbjh21 1171.2Sbjh21/* 1181.2Sbjh21 * Stray IRQ bug: 1191.9Sperry * 1201.2Sbjh21 * Occasionally, when receiving, we get a stray IRQ. Sometimes, the interrupt 1211.2Sbjh21 * bit on the unixbp reads as clear. In any case, comintr() gets an IIR 1221.2Sbjh21 * of 0xc1 (no interrupts pending). 1231.2Sbjh21 * 1241.2Sbjh21 * The behaviour can be observed with a logic probe: 1251.2Sbjh21 * 1261.2Sbjh21 * Channel 1 to PIRQ* (pin 19 on IC3 on A540 backplane) 1271.2Sbjh21 * Channel 2 to INTR on 16550 1281.2Sbjh21 * trigger on ch1 low, ch2 falling 1291.2Sbjh21 * 2 us/div 1301.2Sbjh21 * 1311.2Sbjh21 * This catches cases where the 16550 de-asserts the interrupt before 1321.2Sbjh21 * irq_handler is entered and disables the interrupt at unixbp (by calling 1331.2Sbjh21 * splhigh()). 1341.2Sbjh21 * 1351.2Sbjh21 * This gets us 5us pulses on INTR and PIRQ*. Now to work out why. 1361.2Sbjh21 * 1371.2Sbjh21 * Connecting channel 3 to the CS2* pin on the 16550 shows it high throughout, 1381.2Sbjh21 * so the interrupt isn't being cleared by the host. MR, similarly, is low 1391.2Sbjh21 * throughout, so it's not being cleared by a reset. 1401.2Sbjh21 */ 141