lpt_ofisa.c revision 1.1 1 1.1 cgd /* $NetBSD: lpt_ofisa.c,v 1.1 1998/02/07 00:46:50 cgd Exp $ */
2 1.1 cgd
3 1.1 cgd /*
4 1.1 cgd * Copyright 1997, 1998
5 1.1 cgd * Digital Equipment Corporation. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * This software is furnished under license and may be used and
8 1.1 cgd * copied only in accordance with the following terms and conditions.
9 1.1 cgd * Subject to these conditions, you may download, copy, install,
10 1.1 cgd * use, modify and distribute this software in source and/or binary
11 1.1 cgd * form. No title or ownership is transferred hereby.
12 1.1 cgd *
13 1.1 cgd * 1) Any source code used, modified or distributed must reproduce
14 1.1 cgd * and retain this copyright notice and list of conditions as
15 1.1 cgd * they appear in the source file.
16 1.1 cgd *
17 1.1 cgd * 2) No right is granted to use any trade name, trademark, or logo of
18 1.1 cgd * Digital Equipment Corporation. Neither the "Digital Equipment
19 1.1 cgd * Corporation" name nor any trademark or logo of Digital Equipment
20 1.1 cgd * Corporation may be used to endorse or promote products derived
21 1.1 cgd * from this software without the prior written permission of
22 1.1 cgd * Digital Equipment Corporation.
23 1.1 cgd *
24 1.1 cgd * 3) This software is provided "AS-IS" and any express or implied
25 1.1 cgd * warranties, including but not limited to, any implied warranties
26 1.1 cgd * of merchantability, fitness for a particular purpose, or
27 1.1 cgd * non-infringement are disclaimed. In no event shall DIGITAL be
28 1.1 cgd * liable for any damages whatsoever, and in particular, DIGITAL
29 1.1 cgd * shall not be liable for special, indirect, consequential, or
30 1.1 cgd * incidental damages or damages for lost profits, loss of
31 1.1 cgd * revenue or loss of use, whether such damages arise in contract,
32 1.1 cgd * negligence, tort, under statute, in equity, at law or otherwise,
33 1.1 cgd * even if advised of the possibility of such damage.
34 1.1 cgd */
35 1.1 cgd
36 1.1 cgd /*
37 1.1 cgd * OFW Attachment for 'lpt' parallel port driver
38 1.1 cgd */
39 1.1 cgd
40 1.1 cgd #include <sys/param.h>
41 1.1 cgd #include <sys/device.h>
42 1.1 cgd #include <sys/socket.h>
43 1.1 cgd #include <sys/tty.h>
44 1.1 cgd
45 1.1 cgd #include <machine/intr.h>
46 1.1 cgd #include <machine/bus.h>
47 1.1 cgd
48 1.1 cgd #include <dev/ofw/openfirm.h>
49 1.1 cgd #include <dev/isa/isavar.h>
50 1.1 cgd #include <dev/ofisa/ofisavar.h>
51 1.1 cgd
52 1.1 cgd #include <dev/ic/lptreg.h>
53 1.1 cgd #include <dev/ic/lptvar.h>
54 1.1 cgd
55 1.1 cgd struct lpt_ofisa_softc {
56 1.1 cgd struct lpt_softc sc_lpt; /* real "lpt" softc */
57 1.1 cgd
58 1.1 cgd /* OFW ISA-specific goo. */
59 1.1 cgd void *sc_ih; /* interrupt handler */
60 1.1 cgd };
61 1.1 cgd
62 1.1 cgd int lpt_ofisa_probe __P((struct device *, struct cfdata *, void *));
63 1.1 cgd void lpt_ofisa_attach __P((struct device *, struct device *, void *));
64 1.1 cgd
65 1.1 cgd struct cfattach lpt_ofisa_ca = {
66 1.1 cgd sizeof(struct lpt_ofisa_softc), lpt_ofisa_probe, lpt_ofisa_attach
67 1.1 cgd };
68 1.1 cgd
69 1.1 cgd int
70 1.1 cgd lpt_ofisa_probe(parent, cf, aux)
71 1.1 cgd struct device *parent;
72 1.1 cgd struct cfdata *cf;
73 1.1 cgd void *aux;
74 1.1 cgd {
75 1.1 cgd struct ofisa_attach_args *aa = aux;
76 1.1 cgd const char *compatible_strings[] = { "pnpPNP,401", NULL };
77 1.1 cgd int rv = 0;
78 1.1 cgd
79 1.1 cgd if (of_compatible(aa->ofp.phandle, compatible_strings) != -1)
80 1.1 cgd rv = 5;
81 1.1 cgd #ifdef _LPT_OFISA_MD_MATCH
82 1.1 cgd if (!rv)
83 1.1 cgd rv = lpt_ofisa_md_match(parent, cf, aux);
84 1.1 cgd #endif
85 1.1 cgd return (rv);
86 1.1 cgd }
87 1.1 cgd
88 1.1 cgd void
89 1.1 cgd lpt_ofisa_attach(parent, self, aux)
90 1.1 cgd struct device *parent, *self;
91 1.1 cgd void *aux;
92 1.1 cgd {
93 1.1 cgd struct lpt_ofisa_softc *osc = (void *)self;
94 1.1 cgd struct lpt_softc *sc = &osc->sc_lpt;
95 1.1 cgd struct ofisa_attach_args *aa = aux;
96 1.1 cgd struct ofisa_reg_desc reg;
97 1.1 cgd struct ofisa_intr_desc intr;
98 1.1 cgd int n;
99 1.1 cgd
100 1.1 cgd /*
101 1.1 cgd * We're living on an ofw. We have to ask the OFW what our
102 1.1 cgd * registers and interrupts properties look like.
103 1.1 cgd *
104 1.1 cgd * We expect exactly one register region and one interrupt.
105 1.1 cgd */
106 1.1 cgd
107 1.1 cgd n = ofisa_reg_get(aa->ofp.phandle, ®, 1);
108 1.1 cgd #ifdef _LPT_OFISA_MD_REG_FIXUP
109 1.1 cgd n = lpt_ofisa_md_reg_fixup(parent, self, aux, ®, 1, n);
110 1.1 cgd #endif
111 1.1 cgd if (n != 1) {
112 1.1 cgd printf(": error getting register data\n");
113 1.1 cgd return;
114 1.1 cgd }
115 1.1 cgd if (reg.len != 4 && reg.len != 8) {
116 1.1 cgd printf(": weird register size (%d, expected 4 or 8)\n",
117 1.1 cgd reg.len);
118 1.1 cgd return;
119 1.1 cgd }
120 1.1 cgd
121 1.1 cgd n = ofisa_intr_get(aa->ofp.phandle, &intr, 1);
122 1.1 cgd #ifdef _LPT_OFISA_MD_INTR_FIXUP
123 1.1 cgd n = lpt_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
124 1.1 cgd #endif
125 1.1 cgd if (n != 1) {
126 1.1 cgd printf(": error getting interrupt data\n");
127 1.1 cgd return;
128 1.1 cgd }
129 1.1 cgd
130 1.1 cgd sc->sc_iot = (reg.type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
131 1.1 cgd if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0, &sc->sc_ioh)) {
132 1.1 cgd printf(": can't map register space\n");
133 1.1 cgd return;
134 1.1 cgd }
135 1.1 cgd
136 1.1 cgd osc->sc_ih = isa_intr_establish(aa->ic, intr.irq, intr.share,
137 1.1 cgd IPL_TTY, lptintr, sc);
138 1.1 cgd
139 1.1 cgd printf("\n");
140 1.1 cgd
141 1.1 cgd lpt_attach_subr(sc);
142 1.1 cgd
143 1.1 cgd #if 0
144 1.1 cgd printf("%s: registers: ", sc->sc_dev.dv_xname);
145 1.1 cgd ofisa_reg_print(®, 1);
146 1.1 cgd printf("\n");
147 1.1 cgd printf("%s: interrupts: ", sc->sc_dev.dv_xname);
148 1.1 cgd ofisa_intr_print(&intr, 1);
149 1.1 cgd printf("\n");
150 1.1 cgd #endif
151 1.1 cgd }
152