com_mainbus.c revision 1.4
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.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.3Scubeint com_mainbus_probe(device_t, cfdata_t , void *);
571.3Scubevoid com_mainbus_attach(device_t, device_t, void *);
581.1Ssanjayl
591.3ScubeCFATTACH_DECL_NEW(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.3Scubecom_mainbus_probe(device_t parent, cfdata_t match, void *aux)
651.1Ssanjayl{
661.1Ssanjayl    struct confargs *ca = aux;
671.1Ssanjayl
681.1Ssanjayl    if (strcmp(ca->ca_name, "com") != 0)
691.1Ssanjayl        return 0;
701.1Ssanjayl
711.1Ssanjayl    if (!com_mainbus_attached) {
721.1Ssanjayl        com_mainbus_attached = 1;
731.1Ssanjayl        return (1);
741.1Ssanjayl    }
751.1Ssanjayl    else
761.1Ssanjayl        return 0;
771.1Ssanjayl}
781.1Ssanjayl
791.1Ssanjaylvoid
801.3Scubecom_mainbus_attach(device_t parent, device_t self, void *aux)
811.1Ssanjayl{
821.3Scube    struct com_mainbus_softc *msc = device_private(self);
831.1Ssanjayl    struct com_softc *sc = &msc->sc_com;
841.1Ssanjayl    int serial, interrupt_length;
851.1Ssanjayl    int interrupts[8];
861.2Smatt    bus_space_tag_t iot;
871.2Smatt    bus_space_handle_t ioh;
881.2Smatt    bus_addr_t iobase;
891.1Ssanjayl
901.3Scube    sc->sc_dev = self;
911.3Scube
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
981.1Ssanjayl
991.2Smatt    iot = (bus_space_tag_t)0xf4000000;
1001.2Smatt    iobase = 0x3f8;
1011.2Smatt    comcnattach(iot, iobase, 9600, 1843200, COM_TYPE_NORMAL, (CREAD | CS8));
1021.2Smatt    bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh);
1031.2Smatt    COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
1041.2Smatt
1051.1Ssanjayl    sc->sc_frequency = 1843200;
1061.1Ssanjayl
1071.1Ssanjayl    com_attach_subr(sc);
1081.1Ssanjayl#if 1
1091.1Ssanjayl    msc->sc_ih =
1101.1Ssanjayl        intr_establish(interrupts[0], IST_LEVEL, IPL_SERIAL, comintr, sc);
1111.1Ssanjayl
1121.1Ssanjayl    if (msc->sc_ih == NULL)
1131.1Ssanjayl        panic("failed to establish int handler");
1141.1Ssanjayl#endif
1151.1Ssanjayl
1161.1Ssanjayl
1171.1Ssanjayl}
118