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.4Sdyoung#include <sys/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.5Schs#include <machine/autoconf.h>
511.5Schs
521.1Ssanjaylstruct com_mainbus_softc
531.1Ssanjayl{
541.1Ssanjayl    struct com_softc sc_com;    /* real "com" softc */
551.1Ssanjayl    void *sc_ih;                /* interrupt handler */
561.1Ssanjayl};
571.1Ssanjayl
581.3Scubeint com_mainbus_probe(device_t, cfdata_t , void *);
591.3Scubevoid com_mainbus_attach(device_t, device_t, void *);
601.1Ssanjayl
611.3ScubeCFATTACH_DECL_NEW(com_mainbus, sizeof(struct com_mainbus_softc),
621.1Ssanjayl              com_mainbus_probe, com_mainbus_attach, NULL, NULL);
631.1Ssanjayl
641.1Ssanjaylint com_mainbus_attached = 0;
651.1Ssanjaylint
661.3Scubecom_mainbus_probe(device_t parent, cfdata_t match, void *aux)
671.1Ssanjayl{
681.1Ssanjayl    struct confargs *ca = aux;
691.1Ssanjayl
701.1Ssanjayl    if (strcmp(ca->ca_name, "com") != 0)
711.1Ssanjayl        return 0;
721.1Ssanjayl
731.1Ssanjayl    if (!com_mainbus_attached) {
741.1Ssanjayl        com_mainbus_attached = 1;
751.1Ssanjayl        return (1);
761.1Ssanjayl    }
771.1Ssanjayl    else
781.1Ssanjayl        return 0;
791.1Ssanjayl}
801.1Ssanjayl
811.1Ssanjaylvoid
821.3Scubecom_mainbus_attach(device_t parent, device_t self, void *aux)
831.1Ssanjayl{
841.3Scube    struct com_mainbus_softc *msc = device_private(self);
851.1Ssanjayl    struct com_softc *sc = &msc->sc_com;
861.6Sthorpej    int serial;
871.1Ssanjayl    int interrupts[8];
881.2Smatt    bus_space_tag_t iot;
891.2Smatt    bus_space_handle_t ioh;
901.2Smatt    bus_addr_t iobase;
911.1Ssanjayl
921.3Scube    sc->sc_dev = self;
931.3Scube
941.1Ssanjayl    serial = OF_finddevice("/ht@0/isa@4/serial@0x3f8");
951.1Ssanjayl    if (serial != -1) {
961.6Sthorpej        (void)OF_getprop(serial, "interrupts", interrupts, sizeof(interrupts));
971.1Ssanjayl    }
981.1Ssanjayl
991.1Ssanjayl
1001.2Smatt    iot = (bus_space_tag_t)0xf4000000;
1011.2Smatt    iobase = 0x3f8;
1021.2Smatt    comcnattach(iot, iobase, 9600, 1843200, COM_TYPE_NORMAL, (CREAD | CS8));
1031.2Smatt    bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh);
1041.6Sthorpej    com_init_regs(&sc->sc_regs, iot, ioh, iobase);
1051.2Smatt
1061.1Ssanjayl    sc->sc_frequency = 1843200;
1071.1Ssanjayl
1081.1Ssanjayl    com_attach_subr(sc);
1091.1Ssanjayl#if 1
1101.1Ssanjayl    msc->sc_ih =
1111.7Srin        intr_establish_xname(interrupts[0], IST_LEVEL, IPL_SERIAL, comintr, sc,
1121.7Srin	    device_xname(self));
1131.1Ssanjayl
1141.1Ssanjayl    if (msc->sc_ih == NULL)
1151.1Ssanjayl        panic("failed to establish int handler");
1161.1Ssanjayl#endif
1171.1Ssanjayl
1181.1Ssanjayl
1191.1Ssanjayl}
120