xref: /netbsd-src/sys/arch/macppc/dev/com_mainbus.c (revision cfe2093dadc7e1a4babcbbd408b815b407449711)
1265929b2Ssanjayl /*
2265929b2Ssanjayl  * Copyright 2006 Kyma Systems LLC.
3265929b2Ssanjayl  * All rights reserved.
4265929b2Ssanjayl  *
5265929b2Ssanjayl  * Written by Sanjay Lal <sanjayl@kymasys.com>
6265929b2Ssanjayl  *
7265929b2Ssanjayl  * Redistribution and use in source and binary forms, with or without
8265929b2Ssanjayl  * modification, are permitted provided that the following conditions
9265929b2Ssanjayl  * are met:
10265929b2Ssanjayl  * 1. Redistributions of source code must retain the above copyright
11265929b2Ssanjayl  *    notice, this list of conditions and the following disclaimer.
12265929b2Ssanjayl  * 2. Redistributions in binary form must reproduce the above copyright
13265929b2Ssanjayl  *    notice, this list of conditions and the following disclaimer in the
14265929b2Ssanjayl  *    documentation and/or other materials provided with the distribution.
15265929b2Ssanjayl  * 3. All advertising materials mentioning features or use of this software
16265929b2Ssanjayl  *    must display the following acknowledgement:
17265929b2Ssanjayl  *      This product includes software developed for the NetBSD Project by
18265929b2Ssanjayl  *      Kyma Systems LLC.
19265929b2Ssanjayl  * 4. The name of Kyma Systems LLC may not be used to endorse
20265929b2Ssanjayl  *    or promote products derived from this software without specific prior
21265929b2Ssanjayl  *    written permission.
22265929b2Ssanjayl  *
23265929b2Ssanjayl  * THIS SOFTWARE IS PROVIDED BY KYMA SYSTEMS LLC ``AS IS'' AND
24265929b2Ssanjayl  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25265929b2Ssanjayl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26265929b2Ssanjayl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL KYMA SYSTEMS LLC
27265929b2Ssanjayl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28265929b2Ssanjayl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29265929b2Ssanjayl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30265929b2Ssanjayl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31265929b2Ssanjayl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32265929b2Ssanjayl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33265929b2Ssanjayl  * POSSIBILITY OF SUCH DAMAGE.
34265929b2Ssanjayl  */
35265929b2Ssanjayl 
36265929b2Ssanjayl /* com device attachment to mainbus for MAMBO G5 simulator */
37265929b2Ssanjayl 
38265929b2Ssanjayl #include <sys/cdefs.h>
39265929b2Ssanjayl #include <sys/param.h>
40265929b2Ssanjayl #include <sys/systm.h>
41265929b2Ssanjayl #include <sys/device.h>
42265929b2Ssanjayl #include <sys/tty.h>
43265929b2Ssanjayl 
44b6584574Sdyoung #include <sys/bus.h>
45265929b2Ssanjayl #include <dev/ofw/openfirm.h>
46265929b2Ssanjayl 
47265929b2Ssanjayl #include <dev/ic/comreg.h>
48265929b2Ssanjayl #include <dev/ic/comvar.h>
49265929b2Ssanjayl 
50cbab9cadSchs #include <machine/autoconf.h>
51cbab9cadSchs 
52265929b2Ssanjayl struct com_mainbus_softc
53265929b2Ssanjayl {
54265929b2Ssanjayl     struct com_softc sc_com;    /* real "com" softc */
55265929b2Ssanjayl     void *sc_ih;                /* interrupt handler */
56265929b2Ssanjayl };
57265929b2Ssanjayl 
58607ead0eScube int com_mainbus_probe(device_t, cfdata_t , void *);
59607ead0eScube void com_mainbus_attach(device_t, device_t, void *);
60265929b2Ssanjayl 
61607ead0eScube CFATTACH_DECL_NEW(com_mainbus, sizeof(struct com_mainbus_softc),
62265929b2Ssanjayl               com_mainbus_probe, com_mainbus_attach, NULL, NULL);
63265929b2Ssanjayl 
64265929b2Ssanjayl int com_mainbus_attached = 0;
65265929b2Ssanjayl int
com_mainbus_probe(device_t parent,cfdata_t match,void * aux)66607ead0eScube com_mainbus_probe(device_t parent, cfdata_t match, void *aux)
67265929b2Ssanjayl {
68265929b2Ssanjayl     struct confargs *ca = aux;
69265929b2Ssanjayl 
70265929b2Ssanjayl     if (strcmp(ca->ca_name, "com") != 0)
71265929b2Ssanjayl         return 0;
72265929b2Ssanjayl 
73265929b2Ssanjayl     if (!com_mainbus_attached) {
74265929b2Ssanjayl         com_mainbus_attached = 1;
75265929b2Ssanjayl         return (1);
76265929b2Ssanjayl     }
77265929b2Ssanjayl     else
78265929b2Ssanjayl         return 0;
79265929b2Ssanjayl }
80265929b2Ssanjayl 
81265929b2Ssanjayl void
com_mainbus_attach(device_t parent,device_t self,void * aux)82607ead0eScube com_mainbus_attach(device_t parent, device_t self, void *aux)
83265929b2Ssanjayl {
84607ead0eScube     struct com_mainbus_softc *msc = device_private(self);
85265929b2Ssanjayl     struct com_softc *sc = &msc->sc_com;
866d487047Sthorpej     int serial;
87265929b2Ssanjayl     int interrupts[8];
8828ee68aeSmatt     bus_space_tag_t iot;
8928ee68aeSmatt     bus_space_handle_t ioh;
9028ee68aeSmatt     bus_addr_t iobase;
91265929b2Ssanjayl 
92607ead0eScube     sc->sc_dev = self;
93607ead0eScube 
94265929b2Ssanjayl     serial = OF_finddevice("/ht@0/isa@4/serial@0x3f8");
95265929b2Ssanjayl     if (serial != -1) {
966d487047Sthorpej         (void)OF_getprop(serial, "interrupts", interrupts, sizeof(interrupts));
97265929b2Ssanjayl     }
98265929b2Ssanjayl 
99265929b2Ssanjayl 
10028ee68aeSmatt     iot = (bus_space_tag_t)0xf4000000;
10128ee68aeSmatt     iobase = 0x3f8;
10228ee68aeSmatt     comcnattach(iot, iobase, 9600, 1843200, COM_TYPE_NORMAL, (CREAD | CS8));
10328ee68aeSmatt     bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh);
1046d487047Sthorpej     com_init_regs(&sc->sc_regs, iot, ioh, iobase);
10528ee68aeSmatt 
106265929b2Ssanjayl     sc->sc_frequency = 1843200;
107265929b2Ssanjayl 
108265929b2Ssanjayl     com_attach_subr(sc);
109265929b2Ssanjayl #if 1
110265929b2Ssanjayl     msc->sc_ih =
111*cfe2093dSrin         intr_establish_xname(interrupts[0], IST_LEVEL, IPL_SERIAL, comintr, sc,
112*cfe2093dSrin 	    device_xname(self));
113265929b2Ssanjayl 
114265929b2Ssanjayl     if (msc->sc_ih == NULL)
115265929b2Ssanjayl         panic("failed to establish int handler");
116265929b2Ssanjayl #endif
117265929b2Ssanjayl 
118265929b2Ssanjayl 
119265929b2Ssanjayl }
120