Sync usage with man page.
[netbsd-mini2440.git] / sys / dev / ofisa / com_ofisa.c
blob2cd2c5cbf5f54df16a022155bdb048bad6eaafe2
1 /* $NetBSD: com_ofisa.c,v 1.13 2008/03/14 15:09:11 cube Exp $ */
3 /*
4 * Copyright 1997, 1998
5 * Digital Equipment Corporation. All rights reserved.
7 * This software is furnished under license and may be used and
8 * copied only in accordance with the following terms and conditions.
9 * Subject to these conditions, you may download, copy, install,
10 * use, modify and distribute this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
13 * 1) Any source code used, modified or distributed must reproduce
14 * and retain this copyright notice and list of conditions as
15 * they appear in the source file.
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Digital Equipment Corporation. Neither the "Digital Equipment
19 * Corporation" name nor any trademark or logo of Digital Equipment
20 * Corporation may be used to endorse or promote products derived
21 * from this software without the prior written permission of
22 * Digital Equipment Corporation.
24 * 3) This software is provided "AS-IS" and any express or implied
25 * warranties, including but not limited to, any implied warranties
26 * of merchantability, fitness for a particular purpose, or
27 * non-infringement are disclaimed. In no event shall DIGITAL be
28 * liable for any damages whatsoever, and in particular, DIGITAL
29 * shall not be liable for special, indirect, consequential, or
30 * incidental damages or damages for lost profits, loss of
31 * revenue or loss of use, whether such damages arise in contract,
32 * negligence, tort, under statute, in equity, at law or otherwise,
33 * even if advised of the possibility of such damage.
37 * OFW Attachment for 'com' serial driver
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: com_ofisa.c,v 1.13 2008/03/14 15:09:11 cube Exp $");
43 #include <sys/param.h>
44 #include <sys/device.h>
45 #include <sys/systm.h>
46 #include <sys/tty.h>
48 #include <sys/intr.h>
49 #include <sys/bus.h>
51 #include <dev/ofw/openfirm.h>
52 #include <dev/isa/isavar.h>
53 #include <dev/ofisa/ofisavar.h>
55 #include <dev/ic/comreg.h>
56 #include <dev/ic/comvar.h>
58 struct com_ofisa_softc {
59 struct com_softc sc_com; /* real "com" softc */
61 /* OFW ISA-specific goo. */
62 void *sc_ih; /* interrupt handler */
65 int com_ofisa_probe(device_t, cfdata_t , void *);
66 void com_ofisa_attach(device_t, device_t, void *);
68 CFATTACH_DECL_NEW(com_ofisa, sizeof(struct com_ofisa_softc),
69 com_ofisa_probe, com_ofisa_attach, NULL, NULL);
71 int
72 com_ofisa_probe(device_t parent, cfdata_t cf, void *aux)
74 struct ofisa_attach_args *aa = aux;
75 static const char *const compatible_strings[] = { "pnpPNP,501", NULL };
76 int rv = 0;
78 if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
79 rv = 5;
80 #ifdef _COM_OFISA_MD_MATCH
81 if (!rv)
82 rv = com_ofisa_md_match(parent, cf, aux);
83 #endif
84 return (rv);
87 void
88 com_ofisa_attach(device_t parent, device_t self, void *aux)
90 struct com_ofisa_softc *osc = device_private(self);
91 struct com_softc *sc = &osc->sc_com;
92 struct ofisa_attach_args *aa = aux;
93 struct ofisa_reg_desc reg;
94 struct ofisa_intr_desc intr;
95 bus_space_handle_t ioh;
96 bus_space_tag_t iot;
97 bus_addr_t iobase;
98 int freq;
99 char freqbuf[4];
100 int n;
102 sc->sc_dev = self;
105 * We're living on an ofw. We have to ask the OFW what our
106 * registers and interrupts properties look like.
108 * We expect exactly one register region and one interrupt.
111 n = ofisa_reg_get(aa->oba.oba_phandle, &reg, 1);
112 #ifdef _COM_OFISA_MD_REG_FIXUP
113 n = com_ofisa_md_reg_fixup(parent, self, aux, &reg, 1, n);
114 #endif
115 if (n != 1) {
116 aprint_error(": error getting register data\n");
117 return;
119 if (reg.len != 8) {
120 aprint_error(": weird register size (%lu, expected 8)\n",
121 (unsigned long)reg.len);
122 return;
125 n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
126 #ifdef _COM_OFISA_MD_INTR_FIXUP
127 n = com_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
128 #endif
129 if (n != 1) {
130 aprint_error(": error getting interrupt data\n");
131 return;
134 if (OF_getproplen(aa->oba.oba_phandle, "clock-frequency") != 4 ||
135 OF_getprop(aa->oba.oba_phandle, "clock-frequency", freqbuf,
136 sizeof freqbuf) != 4)
137 freq = COM_FREQ;
138 else
139 freq = of_decode_int(&freqbuf[0]);
141 iot = (reg.type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
142 iobase = reg.addr;
143 sc->sc_frequency = freq;
145 if (!com_is_console(iot, iobase, &ioh) &&
146 bus_space_map(iot, iobase, reg.len, 0, &ioh)) {
147 aprint_error(": can't map register space\n");
148 return;
150 COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
152 osc->sc_ih = isa_intr_establish(aa->ic, intr.irq, intr.share,
153 IPL_SERIAL, comintr, sc);
155 com_attach_subr(sc);
157 #if 0
158 printf("%s: registers: ", device_xname(&sc->sc_dev));
159 ofisa_reg_print(&reg, 1);
160 printf("\n");
161 printf("%s: interrupts: ", device_xname(&sc->sc_dev));
162 ofisa_intr_print(&intr, 1);
163 printf("\n");
164 #endif