com_iop.c revision 1.2 1 /* $NetBSD: com_iop.c,v 1.2 2008/03/14 15:09:10 cube Exp $ */
2
3 /*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tim Rightnour
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: com_iop.c,v 1.2 2008/03/14 15:09:10 cube Exp $");
41
42 #include <sys/param.h>
43 #include <sys/device.h>
44 #include <sys/ioctl.h>
45 #include <sys/tty.h>
46
47 #include <machine/intr.h>
48 #include <machine/bus.h>
49
50 #include <dev/ic/comreg.h>
51 #include <dev/ic/comvar.h>
52
53 #include <dev/mca/mcavar.h>
54 #include <dev/mca/mcadevs.h>
55
56 #include <rs6000/ioplanar/ioplanarvar.h>
57
58 struct com_iop_softc {
59 struct com_softc sc_com; /* real com softc */
60 void *sc_ih;
61 };
62
63 int com_iop_probe(device_t, cfdata_t , void *);
64 void com_iop_attach(device_t, device_t, void *);
65
66 CFATTACH_DECL_NEW(com_iop, sizeof(struct com_iop_softc),
67 com_iop_probe, com_iop_attach, NULL, NULL);
68
69 #define COM_RAINBOW_FREQ 8000000
70
71 /*
72 * This probe is very unorthodox. Basically, we have no way to actually
73 * probe the device, so instead, we check that the specific device should
74 * exist on the ioplanar, and just return true.
75 */
76
77 int
78 com_iop_probe(device_t parent, cfdata_t match, void *aux)
79 {
80 struct ioplanar_dev_attach_args *idaa = aux;
81
82 if (idaa->idaa_devid == MCA_PRODUCT_IBM_SIO_RAINBOW &&
83 (idaa->idaa_device == IOP_COM0 || idaa->idaa_device == IOP_COM1))
84 return 1;
85
86 return 0;
87 }
88
89 void
90 com_iop_attach(device_t parent, device_t self, void *aux)
91 {
92 struct com_iop_softc *isc = device_private(self);
93 struct com_softc *sc = &isc->sc_com;
94 int iobase, irq;
95 struct ioplanar_dev_attach_args *idaa = aux;
96 bus_space_handle_t ioh;
97
98 sc->sc_dev = self;
99
100 switch (idaa->idaa_devid) {
101 case MCA_PRODUCT_IBM_SIO_RAINBOW:
102 switch (idaa->idaa_device) {
103 case IOP_COM0:
104 iobase = 0x30;
105 irq = 2; /* ??? */
106 sc->sc_frequency = COM_RAINBOW_FREQ;
107 break;
108 case IOP_COM1:
109 iobase = 0x38;
110 irq = 2; /* ??? */
111 sc->sc_frequency = COM_RAINBOW_FREQ;
112 break;
113 default:
114 return;
115 }
116 break;
117 default:
118 return;
119 }
120 if (!com_is_console(idaa->idaa_iot, iobase, &ioh) &&
121 bus_space_map(idaa->idaa_iot, iobase, COM_NPORTS, 0, &ioh)) {
122 aprint_error(": can't map i/o space\n");
123 return;
124 }
125
126 COM_INIT_REGS(sc->sc_regs, idaa->idaa_iot, ioh, iobase);
127
128 aprint_normal("i/o %#x-%#x irq %d", iobase, iobase + COM_NPORTS - 1,
129 irq);
130
131 com_attach_subr(sc);
132
133 isc->sc_ih = mca_intr_establish(idaa->idaa_mc, irq, IPL_SERIAL,
134 comintr, sc);
135
136 if (isc->sc_ih == NULL) {
137 aprint_error_dev(self,
138 "couldn't establish interrupt handler\n");
139 return;
140 }
141 }
142