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 <sys/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(device_t, cfdata_t , void *);
57void com_mainbus_attach(device_t, device_t, void *);
58
59CFATTACH_DECL_NEW(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(device_t parent, cfdata_t match, void *aux)
65{
66    struct confargs *ca = aux;
67
68    if (strcmp(ca->ca_name, "com") != 0)
69        return 0;
70
71    if (!com_mainbus_attached) {
72        com_mainbus_attached = 1;
73        return (1);
74    }
75    else
76        return 0;
77}
78
79void
80com_mainbus_attach(device_t parent, device_t self, void *aux)
81{
82    struct com_mainbus_softc *msc = device_private(self);
83    struct com_softc *sc = &msc->sc_com;
84    int serial, interrupt_length;
85    int interrupts[8];
86    bus_space_tag_t iot;
87    bus_space_handle_t ioh;
88    bus_addr_t iobase;
89
90    sc->sc_dev = self;
91
92    serial = OF_finddevice("/ht@0/isa@4/serial@0x3f8");
93    if (serial != -1) {
94        interrupt_length =
95            OF_getprop(serial, "interrupts", interrupts, sizeof(interrupts));
96    }
97
98
99    iot = (bus_space_tag_t)0xf4000000;
100    iobase = 0x3f8;
101    comcnattach(iot, iobase, 9600, 1843200, COM_TYPE_NORMAL, (CREAD | CS8));
102    bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh);
103    COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
104
105    sc->sc_frequency = 1843200;
106
107    com_attach_subr(sc);
108#if 1
109    msc->sc_ih =
110        intr_establish(interrupts[0], IST_LEVEL, IPL_SERIAL, comintr, sc);
111
112    if (msc->sc_ih == NULL)
113        panic("failed to establish int handler");
114#endif
115
116
117}
118