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