com_mainbus.c revision 1.1
11.1Ssanjayl/* 21.1Ssanjayl * Copyright 2006 Kyma Systems LLC. 31.1Ssanjayl * All rights reserved. 41.1Ssanjayl * 51.1Ssanjayl * Written by Sanjay Lal <sanjayl@kymasys.com> 61.1Ssanjayl * 71.1Ssanjayl * Redistribution and use in source and binary forms, with or without 81.1Ssanjayl * modification, are permitted provided that the following conditions 91.1Ssanjayl * are met: 101.1Ssanjayl * 1. Redistributions of source code must retain the above copyright 111.1Ssanjayl * notice, this list of conditions and the following disclaimer. 121.1Ssanjayl * 2. Redistributions in binary form must reproduce the above copyright 131.1Ssanjayl * notice, this list of conditions and the following disclaimer in the 141.1Ssanjayl * documentation and/or other materials provided with the distribution. 151.1Ssanjayl * 3. All advertising materials mentioning features or use of this software 161.1Ssanjayl * must display the following acknowledgement: 171.1Ssanjayl * This product includes software developed for the NetBSD Project by 181.1Ssanjayl * Kyma Systems LLC. 191.1Ssanjayl * 4. The name of Kyma Systems LLC may not be used to endorse 201.1Ssanjayl * or promote products derived from this software without specific prior 211.1Ssanjayl * written permission. 221.1Ssanjayl * 231.1Ssanjayl * THIS SOFTWARE IS PROVIDED BY KYMA SYSTEMS LLC ``AS IS'' AND 241.1Ssanjayl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 251.1Ssanjayl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 261.1Ssanjayl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KYMA SYSTEMS LLC 271.1Ssanjayl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 281.1Ssanjayl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 291.1Ssanjayl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 301.1Ssanjayl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 311.1Ssanjayl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 321.1Ssanjayl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 331.1Ssanjayl * POSSIBILITY OF SUCH DAMAGE. 341.1Ssanjayl */ 351.1Ssanjayl 361.1Ssanjayl/* com device attachment to mainbus for MAMBO G5 simulator */ 371.1Ssanjayl 381.1Ssanjayl#include <sys/cdefs.h> 391.1Ssanjayl#include <sys/param.h> 401.1Ssanjayl#include <sys/systm.h> 411.1Ssanjayl#include <sys/device.h> 421.1Ssanjayl#include <sys/tty.h> 431.1Ssanjayl 441.1Ssanjayl#include <machine/bus.h> 451.1Ssanjayl#include <dev/ofw/openfirm.h> 461.1Ssanjayl 471.1Ssanjayl#include <dev/ic/comreg.h> 481.1Ssanjayl#include <dev/ic/comvar.h> 491.1Ssanjayl 501.1Ssanjaylstruct com_mainbus_softc 511.1Ssanjayl{ 521.1Ssanjayl struct com_softc sc_com; /* real "com" softc */ 531.1Ssanjayl void *sc_ih; /* interrupt handler */ 541.1Ssanjayl}; 551.1Ssanjayl 561.1Ssanjaylint com_mainbus_probe(struct device *, struct cfdata *, void *); 571.1Ssanjaylvoid com_mainbus_attach(struct device *, struct device *, void *); 581.1Ssanjayl 591.1SsanjaylCFATTACH_DECL(com_mainbus, sizeof(struct com_mainbus_softc), 601.1Ssanjayl com_mainbus_probe, com_mainbus_attach, NULL, NULL); 611.1Ssanjayl 621.1Ssanjaylint com_mainbus_attached = 0; 631.1Ssanjaylint 641.1Ssanjaylcom_mainbus_probe(parent, match, aux) 651.1Ssanjayl struct device *parent; 661.1Ssanjayl struct cfdata *match; 671.1Ssanjayl void *aux; 681.1Ssanjayl{ 691.1Ssanjayl struct confargs *ca = aux; 701.1Ssanjayl 711.1Ssanjayl if (strcmp(ca->ca_name, "com") != 0) 721.1Ssanjayl return 0; 731.1Ssanjayl 741.1Ssanjayl if (!com_mainbus_attached) { 751.1Ssanjayl com_mainbus_attached = 1; 761.1Ssanjayl return (1); 771.1Ssanjayl } 781.1Ssanjayl else 791.1Ssanjayl return 0; 801.1Ssanjayl} 811.1Ssanjayl 821.1Ssanjaylvoid 831.1Ssanjaylcom_mainbus_attach(parent, self, aux) 841.1Ssanjayl struct device *parent, *self; 851.1Ssanjayl void *aux; 861.1Ssanjayl{ 871.1Ssanjayl struct com_mainbus_softc *msc = (void *) self; 881.1Ssanjayl struct com_softc *sc = &msc->sc_com; 891.1Ssanjayl int serial, interrupt_length; 901.1Ssanjayl int interrupts[8]; 911.1Ssanjayl 921.1Ssanjayl serial = OF_finddevice("/ht@0/isa@4/serial@0x3f8"); 931.1Ssanjayl if (serial != -1) { 941.1Ssanjayl interrupt_length = 951.1Ssanjayl OF_getprop(serial, "interrupts", interrupts, sizeof(interrupts)); 961.1Ssanjayl } 971.1Ssanjayl comcnattach(0xf4000000, 0x3f8, 9600, 1843200, COM_TYPE_NORMAL, 981.1Ssanjayl (CREAD | CS8)); 991.1Ssanjayl 1001.1Ssanjayl 1011.1Ssanjayl sc->sc_iobase = 0x3f8; 1021.1Ssanjayl sc->sc_iot = 0xf4000000; 1031.1Ssanjayl bus_space_map(sc->sc_iot, sc->sc_iobase, COM_NPORTS, 0, &sc->sc_ioh); 1041.1Ssanjayl sc->sc_frequency = 1843200; 1051.1Ssanjayl 1061.1Ssanjayl com_attach_subr(sc); 1071.1Ssanjayl#if 1 1081.1Ssanjayl msc->sc_ih = 1091.1Ssanjayl intr_establish(interrupts[0], IST_LEVEL, IPL_SERIAL, comintr, sc); 1101.1Ssanjayl 1111.1Ssanjayl if (msc->sc_ih == NULL) 1121.1Ssanjayl panic("failed to establish int handler"); 1131.1Ssanjayl#endif 1141.1Ssanjayl 1151.1Ssanjayl 1161.1Ssanjayl} 117