lm_isa.c revision 1.1 1 1.1 groo /* $NetBSD: lm_isa.c,v 1.1 2000/02/25 02:17:44 groo Exp $ */
2 1.1 groo
3 1.1 groo /*-
4 1.1 groo * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1 groo * All rights reserved.
6 1.1 groo *
7 1.1 groo * This code is derived from software contributed to The NetBSD Foundation
8 1.1 groo * by Bill Squier.
9 1.1 groo *
10 1.1 groo * Redistribution and use in source and binary forms, with or without
11 1.1 groo * modification, are permitted provided that the following conditions
12 1.1 groo * are met:
13 1.1 groo * 1. Redistributions of source code must retain the above copyright
14 1.1 groo * notice, this list of conditions and the following disclaimer.
15 1.1 groo * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 groo * notice, this list of conditions and the following disclaimer in the
17 1.1 groo * documentation and/or other materials provided with the distribution.
18 1.1 groo * 3. All advertising materials mentioning features or use of this software
19 1.1 groo * must display the following acknowledgement:
20 1.1 groo * This product includes software developed by the NetBSD
21 1.1 groo * Foundation, Inc. and its contributors.
22 1.1 groo * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 groo * contributors may be used to endorse or promote products derived
24 1.1 groo * from this software without specific prior written permission.
25 1.1 groo *
26 1.1 groo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 groo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 groo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 groo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 groo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 groo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 groo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 groo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 groo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 groo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 groo * POSSIBILITY OF SUCH DAMAGE.
37 1.1 groo */
38 1.1 groo
39 1.1 groo #include <sys/param.h>
40 1.1 groo #include <sys/systm.h>
41 1.1 groo #include <sys/kernel.h>
42 1.1 groo #include <sys/proc.h>
43 1.1 groo #include <sys/device.h>
44 1.1 groo #include <sys/malloc.h>
45 1.1 groo #include <sys/errno.h>
46 1.1 groo #include <sys/conf.h>
47 1.1 groo
48 1.1 groo #include <sys/envsys.h>
49 1.1 groo
50 1.1 groo #include <machine/bus.h>
51 1.1 groo
52 1.1 groo #include <dev/isa/isareg.h>
53 1.1 groo #include <dev/isa/isavar.h>
54 1.1 groo
55 1.1 groo #include <machine/intr.h>
56 1.1 groo #include <machine/bus.h>
57 1.1 groo
58 1.1 groo #include <dev/ic/nslm7xvar.h>
59 1.1 groo
60 1.1 groo #if defined(LMDEBUG)
61 1.1 groo #define DPRINTF(x) do { printf x; } while (0)
62 1.1 groo #else
63 1.1 groo #define DPRINTF(x)
64 1.1 groo #endif
65 1.1 groo
66 1.1 groo
67 1.1 groo int lm_isa_match __P((struct device *, struct cfdata *, void *));
68 1.1 groo void lm_isa_attach __P((struct device *, struct device *, void *));
69 1.1 groo
70 1.1 groo struct cfattach lm_isa_ca = {
71 1.1 groo sizeof(struct lm_softc), lm_isa_match, lm_isa_attach
72 1.1 groo };
73 1.1 groo
74 1.1 groo
75 1.1 groo int
76 1.1 groo lm_isa_match(parent, match, aux)
77 1.1 groo struct device *parent;
78 1.1 groo struct cfdata *match;
79 1.1 groo void *aux;
80 1.1 groo {
81 1.1 groo bus_space_tag_t iot;
82 1.1 groo bus_space_handle_t ioh;
83 1.1 groo struct isa_attach_args *ia = aux;
84 1.1 groo int iobase;
85 1.1 groo int rv;
86 1.1 groo u_int8_t cr;
87 1.1 groo
88 1.1 groo /* Must supply an address */
89 1.1 groo if (ia->ia_iobase == ISACF_PORT_DEFAULT)
90 1.1 groo return 0;
91 1.1 groo
92 1.1 groo iot = ia->ia_iot;
93 1.1 groo iobase = ia->ia_iobase;
94 1.1 groo
95 1.1 groo if (bus_space_map(iot, iobase, 8, 0, &ioh))
96 1.1 groo return (0);
97 1.1 groo
98 1.1 groo /* Check for some power-on defaults */
99 1.1 groo bus_space_write_1(iot, ioh, LMC_ADDR, LMD_CONFIG);
100 1.1 groo
101 1.1 groo /* Perform LM78 reset */
102 1.1 groo bus_space_write_1(iot, ioh, LMC_DATA, 0x80);
103 1.1 groo
104 1.1 groo /* XXX - Why do I have to reselect the register? */
105 1.1 groo bus_space_write_1(iot, ioh, LMC_ADDR, LMD_CONFIG);
106 1.1 groo cr = bus_space_read_1(iot, ioh, LMC_DATA);
107 1.1 groo
108 1.1 groo /* XXX - spec says *only* 0x08! */
109 1.1 groo if ((cr == 0x08) || (cr == 0x01))
110 1.1 groo rv = 1;
111 1.1 groo else
112 1.1 groo rv = 0;
113 1.1 groo
114 1.1 groo DPRINTF(("lm: rv = %d, cr = %x\n", rv, cr));
115 1.1 groo
116 1.1 groo bus_space_unmap(iot, ioh, 8);
117 1.1 groo
118 1.1 groo if (rv) {
119 1.1 groo ia->ia_iosize = 8;
120 1.1 groo ia->ia_msize = 0;
121 1.1 groo }
122 1.1 groo
123 1.1 groo return (rv);
124 1.1 groo }
125 1.1 groo
126 1.1 groo
127 1.1 groo void
128 1.1 groo lm_isa_attach(parent, self, aux)
129 1.1 groo struct device *parent, *self;
130 1.1 groo void *aux;
131 1.1 groo {
132 1.1 groo struct lm_softc *lmsc = (void *)self;
133 1.1 groo int iobase;
134 1.1 groo bus_space_tag_t iot;
135 1.1 groo struct isa_attach_args *ia = aux;
136 1.1 groo
137 1.1 groo iobase = ia->ia_iobase;
138 1.1 groo iot = lmsc->lm_iot = ia->ia_iot;
139 1.1 groo
140 1.1 groo if (bus_space_map(iot, iobase, 8, 0, &lmsc->lm_ioh)) {
141 1.1 groo printf(": can't map i/o space\n");
142 1.1 groo return;
143 1.1 groo }
144 1.1 groo
145 1.1 groo /* Bus-independant attachment */
146 1.1 groo lm_attach(lmsc);
147 1.1 groo }
148