com_mainbus.c revision 1.2
1/*
2 * Copyright 2006 Kyma Systems LLC.
3 * All rights reserved.
4 *
5 * Written by Sanjay Lal <sanjayl@kymasys.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *      This product includes software developed for the NetBSD Project by
18 *      Kyma Systems LLC.
19 * 4. The name of Kyma Systems LLC may not be used to endorse
20 *    or promote products derived from this software without specific prior
21 *    written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY KYMA SYSTEMS LLC ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL KYMA SYSTEMS LLC
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36/* com device attachment to mainbus for MAMBO G5 simulator */
37
38#include <sys/cdefs.h>
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/device.h>
42#include <sys/tty.h>
43
44#include <machine/bus.h>
45#include <dev/ofw/openfirm.h>
46
47#include <dev/ic/comreg.h>
48#include <dev/ic/comvar.h>
49
50struct com_mainbus_softc
51{
52    struct com_softc sc_com;    /* real "com" softc */
53    void *sc_ih;                /* interrupt handler */
54};
55
56int com_mainbus_probe(struct device *, struct cfdata *, void *);
57void com_mainbus_attach(struct device *, struct device *, void *);
58
59CFATTACH_DECL(com_mainbus, sizeof(struct com_mainbus_softc),
60              com_mainbus_probe, com_mainbus_attach, NULL, NULL);
61
62int com_mainbus_attached = 0;
63int
64com_mainbus_probe(parent, match, aux)
65     struct device *parent;
66     struct cfdata *match;
67     void *aux;
68{
69    struct confargs *ca = aux;
70
71    if (strcmp(ca->ca_name, "com") != 0)
72        return 0;
73
74    if (!com_mainbus_attached) {
75        com_mainbus_attached = 1;
76        return (1);
77    }
78    else
79        return 0;
80}
81
82void
83com_mainbus_attach(parent, self, aux)
84     struct device *parent, *self;
85     void *aux;
86{
87    struct com_mainbus_softc *msc = (void *) self;
88    struct com_softc *sc = &msc->sc_com;
89    int serial, interrupt_length;
90    int interrupts[8];
91    bus_space_tag_t iot;
92    bus_space_handle_t ioh;
93    bus_addr_t iobase;
94
95    serial = OF_finddevice("/ht@0/isa@4/serial@0x3f8");
96    if (serial != -1) {
97        interrupt_length =
98            OF_getprop(serial, "interrupts", interrupts, sizeof(interrupts));
99    }
100
101
102    iot = (bus_space_tag_t)0xf4000000;
103    iobase = 0x3f8;
104    comcnattach(iot, iobase, 9600, 1843200, COM_TYPE_NORMAL, (CREAD | CS8));
105    bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh);
106    COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
107
108    sc->sc_frequency = 1843200;
109
110    com_attach_subr(sc);
111#if 1
112    msc->sc_ih =
113        intr_establish(interrupts[0], IST_LEVEL, IPL_SERIAL, comintr, sc);
114
115    if (msc->sc_ih == NULL)
116        panic("failed to establish int handler");
117#endif
118
119
120}
121