acemidi.c revision 1.13
11.13Sad/* $NetBSD: acemidi.c,v 1.13 2007/10/19 12:01:07 ad 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.13Sad__KERNEL_RCSID(0, "$NetBSD: acemidi.c,v 1.13 2007/10/19 12:01:07 ad 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 acemidi_softc { 491.1Sbjh21 struct device sc_dev; 501.1Sbjh21}; 511.1Sbjh21 521.1Sbjh21struct com_acemidi_softc { 531.1Sbjh21 struct com_softc sc_com; 541.1Sbjh21 struct evcnt sc_intrcnt; 551.1Sbjh21}; 561.1Sbjh21 571.1Sbjh21static int acemidi_match(struct device *, struct cfdata *, void *); 581.1Sbjh21static void acemidi_attach(struct device *, struct device *, void *); 591.1Sbjh21static int com_acemidi_match(struct device *, struct cfdata *, void *); 601.1Sbjh21static void com_acemidi_attach(struct device *, struct device *, void *); 611.1Sbjh21 621.6SthorpejCFATTACH_DECL(acemidi, sizeof(struct acemidi_softc), 631.7Sthorpej acemidi_match, acemidi_attach, NULL, NULL); 641.1Sbjh21 651.6SthorpejCFATTACH_DECL(com_acemidi, sizeof(struct com_acemidi_softc), 661.7Sthorpej com_acemidi_match, com_acemidi_attach, NULL, NULL); 671.1Sbjh21 681.1Sbjh21static int 691.1Sbjh21acemidi_match(struct device *parent, struct cfdata *cf, void *aux) 701.1Sbjh21{ 711.1Sbjh21 struct podulebus_attach_args *pa = aux; 721.1Sbjh21 731.4Sbjh21 if (pa->pa_product == PODULE_MIDICONNECT) 741.1Sbjh21 return 1; 751.1Sbjh21 return 0; 761.1Sbjh21} 771.1Sbjh21 781.1Sbjh21static void 791.1Sbjh21acemidi_attach(struct device *parent, struct device *self, void *aux) 801.1Sbjh21{ 811.11Sthorpej/* struct acemidi_softc *sc = device_private(self); */ 821.1Sbjh21/* struct podulebus_attach_args *pa = aux; */ 831.1Sbjh21 841.1Sbjh21 printf("\n"); 851.8Sdrochner config_found_ia(self, "acemidi", aux, NULL); 861.1Sbjh21} 871.1Sbjh21 881.1Sbjh21static int 891.1Sbjh21com_acemidi_match(struct device *parent, struct cfdata *cf, void *aux) 901.1Sbjh21{ 911.1Sbjh21 921.1Sbjh21 return 1; 931.1Sbjh21} 941.1Sbjh21 951.1Sbjh21static void 961.1Sbjh21com_acemidi_attach(struct device *parent, struct device *self, void *aux) 971.1Sbjh21{ 981.11Sthorpej struct com_acemidi_softc *sc = device_private(self); 991.1Sbjh21 struct com_softc *csc = &sc->sc_com; 1001.1Sbjh21 struct podulebus_attach_args *pa = aux; 1011.12Sgdamore bus_space_handle_t ioh; 1021.12Sgdamore bus_space_tag_t iot; 1031.12Sgdamore bus_addr_t iobase; 1041.12Sgdamore 1051.12Sgdamore iot = pa->pa_fast_t; 1061.12Sgdamore iobase = pa->pa_fast_base + ACEMIDI_16550_BASE; 1071.12Sgdamore 1081.12Sgdamore bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh); 1091.12Sgdamore COM_INIT_REGS(csc->sc_regs, iot, ioh, iobase); 1101.1Sbjh21 1111.1Sbjh21 csc->sc_frequency = ACEMIDI_16550_FREQ; 1121.1Sbjh21 1131.1Sbjh21 com_attach_subr(csc); 1141.1Sbjh21 1151.1Sbjh21 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL, 1161.1Sbjh21 self->dv_xname, "intr"); 1171.1Sbjh21 podulebus_irq_establish(pa->pa_ih, IPL_SERIAL, comintr, sc, 1181.1Sbjh21 &sc->sc_intrcnt); 1191.1Sbjh21} 1201.2Sbjh21 1211.2Sbjh21/* 1221.2Sbjh21 * Stray IRQ bug: 1231.9Sperry * 1241.2Sbjh21 * Occasionally, when receiving, we get a stray IRQ. Sometimes, the interrupt 1251.2Sbjh21 * bit on the unixbp reads as clear. In any case, comintr() gets an IIR 1261.2Sbjh21 * of 0xc1 (no interrupts pending). 1271.2Sbjh21 * 1281.2Sbjh21 * The behaviour can be observed with a logic probe: 1291.2Sbjh21 * 1301.2Sbjh21 * Channel 1 to PIRQ* (pin 19 on IC3 on A540 backplane) 1311.2Sbjh21 * Channel 2 to INTR on 16550 1321.2Sbjh21 * trigger on ch1 low, ch2 falling 1331.2Sbjh21 * 2 us/div 1341.2Sbjh21 * 1351.2Sbjh21 * This catches cases where the 16550 de-asserts the interrupt before 1361.2Sbjh21 * irq_handler is entered and disables the interrupt at unixbp (by calling 1371.2Sbjh21 * splhigh()). 1381.2Sbjh21 * 1391.2Sbjh21 * This gets us 5us pulses on INTR and PIRQ*. Now to work out why. 1401.2Sbjh21 * 1411.2Sbjh21 * Connecting channel 3 to the CS2* pin on the 16550 shows it high throughout, 1421.2Sbjh21 * so the interrupt isn't being cleared by the host. MR, similarly, is low 1431.2Sbjh21 * throughout, so it's not being cleared by a reset. 1441.2Sbjh21 */ 145