acemidi.c revision 1.8
11.8Sdrochner/* $NetBSD: acemidi.c,v 1.8 2004/09/13 12:55:48 drochner 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.1Sbjh21 *
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.8Sdrochner__KERNEL_RCSID(0, "$NetBSD: acemidi.c,v 1.8 2004/09/13 12:55:48 drochner 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.1Sbjh21#include <machine/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.1Sbjh21/*	struct acemidi_softc *sc = (void *)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.1Sbjh21	struct com_acemidi_softc *sc = (void *)self;
991.1Sbjh21	struct com_softc *csc = &sc->sc_com;
1001.1Sbjh21	struct podulebus_attach_args *pa = aux;
1011.1Sbjh21
1021.1Sbjh21	csc->sc_iobase = pa->pa_fast_base + ACEMIDI_16550_BASE;
1031.1Sbjh21	csc->sc_iot = pa->pa_fast_t;
1041.1Sbjh21	bus_space_map(csc->sc_iot, csc->sc_iobase, COM_NPORTS, 0,
1051.1Sbjh21	    &csc->sc_ioh);
1061.1Sbjh21	csc->sc_frequency = ACEMIDI_16550_FREQ;
1071.1Sbjh21
1081.1Sbjh21	com_attach_subr(csc);
1091.1Sbjh21
1101.1Sbjh21	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
1111.1Sbjh21	    self->dv_xname, "intr");
1121.1Sbjh21	podulebus_irq_establish(pa->pa_ih, IPL_SERIAL, comintr, sc,
1131.1Sbjh21	    &sc->sc_intrcnt);
1141.1Sbjh21}
1151.2Sbjh21
1161.2Sbjh21/*
1171.2Sbjh21 * Stray IRQ bug:
1181.2Sbjh21 *
1191.2Sbjh21 * Occasionally, when receiving, we get a stray IRQ.  Sometimes, the interrupt
1201.2Sbjh21 * bit on the unixbp reads as clear.  In any case, comintr() gets an IIR
1211.2Sbjh21 * of 0xc1 (no interrupts pending).
1221.2Sbjh21 *
1231.2Sbjh21 * The behaviour can be observed with a logic probe:
1241.2Sbjh21 *
1251.2Sbjh21 * Channel 1 to PIRQ* (pin 19 on IC3 on A540 backplane)
1261.2Sbjh21 * Channel 2 to INTR on 16550
1271.2Sbjh21 * trigger on ch1 low, ch2 falling
1281.2Sbjh21 * 2 us/div
1291.2Sbjh21 *
1301.2Sbjh21 * This catches cases where the 16550 de-asserts the interrupt before
1311.2Sbjh21 * irq_handler is entered and disables the interrupt at unixbp (by calling
1321.2Sbjh21 * splhigh()).
1331.2Sbjh21 *
1341.2Sbjh21 * This gets us 5us pulses on INTR and PIRQ*.  Now to work out why.
1351.2Sbjh21 *
1361.2Sbjh21 * Connecting channel 3 to the CS2* pin on the 16550 shows it high throughout,
1371.2Sbjh21 * so the interrupt isn't being cleared by the host.  MR, similarly, is low
1381.2Sbjh21 * throughout, so it's not being cleared by a reset.
1391.2Sbjh21 */
140