lm_isa.c revision 1.19 1 1.19 xtraeme /* $NetBSD: lm_isa.c,v 1.19 2008/03/05 15:41:31 xtraeme 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.4 lukem
39 1.4 lukem #include <sys/cdefs.h>
40 1.19 xtraeme __KERNEL_RCSID(0, "$NetBSD: lm_isa.c,v 1.19 2008/03/05 15:41:31 xtraeme Exp $");
41 1.1 groo
42 1.1 groo #include <sys/param.h>
43 1.1 groo #include <sys/systm.h>
44 1.1 groo #include <sys/kernel.h>
45 1.1 groo #include <sys/device.h>
46 1.1 groo #include <sys/conf.h>
47 1.1 groo
48 1.18 ad #include <sys/bus.h>
49 1.1 groo
50 1.1 groo #include <dev/isa/isareg.h>
51 1.1 groo #include <dev/isa/isavar.h>
52 1.1 groo
53 1.3 thorpej #include <dev/sysmon/sysmonvar.h>
54 1.1 groo
55 1.1 groo #include <dev/ic/nslm7xvar.h>
56 1.1 groo
57 1.19 xtraeme int lm_isa_match(device_t, cfdata_t, void *);
58 1.19 xtraeme void lm_isa_attach(device_t, device_t, void *);
59 1.19 xtraeme int lm_isa_detach(device_t, int);
60 1.1 groo
61 1.16 xtraeme uint8_t lm_isa_readreg(struct lm_softc *, int);
62 1.19 xtraeme void lm_isa_writereg(struct lm_softc *, int, int);
63 1.1 groo
64 1.19 xtraeme CFATTACH_DECL_NEW(lm_isa, sizeof(struct lm_softc),
65 1.17 xtraeme lm_isa_match, lm_isa_attach, lm_isa_detach, NULL);
66 1.1 groo
67 1.1 groo int
68 1.19 xtraeme lm_isa_match(device_t parent, cfdata_t match, void *aux)
69 1.1 groo {
70 1.1 groo bus_space_handle_t ioh;
71 1.1 groo struct isa_attach_args *ia = aux;
72 1.1 groo int rv;
73 1.1 groo
74 1.1 groo /* Must supply an address */
75 1.5 thorpej if (ia->ia_nio < 1)
76 1.16 xtraeme return 0;
77 1.5 thorpej
78 1.5 thorpej if (ISA_DIRECT_CONFIG(ia))
79 1.16 xtraeme return 0;
80 1.5 thorpej
81 1.10 drochner if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
82 1.16 xtraeme return 0;
83 1.1 groo
84 1.16 xtraeme if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &ioh))
85 1.16 xtraeme return 0;
86 1.1 groo
87 1.1 groo
88 1.2 groo /* Bus independent probe */
89 1.16 xtraeme rv = lm_probe(ia->ia_iot, ioh);
90 1.1 groo
91 1.16 xtraeme bus_space_unmap(ia->ia_iot, ioh, 8);
92 1.1 groo
93 1.1 groo if (rv) {
94 1.5 thorpej ia->ia_nio = 1;
95 1.5 thorpej ia->ia_io[0].ir_size = 8;
96 1.5 thorpej
97 1.5 thorpej ia->ia_niomem = 0;
98 1.5 thorpej ia->ia_nirq = 0;
99 1.5 thorpej ia->ia_ndrq = 0;
100 1.1 groo }
101 1.1 groo
102 1.16 xtraeme return rv;
103 1.1 groo }
104 1.1 groo
105 1.1 groo
106 1.1 groo void
107 1.19 xtraeme lm_isa_attach(device_t parent, device_t self, void *aux)
108 1.1 groo {
109 1.19 xtraeme struct lm_softc *lmsc = device_private(self);
110 1.1 groo struct isa_attach_args *ia = aux;
111 1.1 groo
112 1.16 xtraeme lmsc->lm_iot = ia->ia_iot;
113 1.1 groo
114 1.16 xtraeme if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0,
115 1.16 xtraeme &lmsc->lm_ioh)) {
116 1.16 xtraeme aprint_error(": can't map i/o space\n");
117 1.1 groo return;
118 1.1 groo }
119 1.1 groo
120 1.14 wiz /* Bus-independent attachment */
121 1.19 xtraeme lmsc->sc_dev = self;
122 1.9 ad lmsc->lm_writereg = lm_isa_writereg;
123 1.9 ad lmsc->lm_readreg = lm_isa_readreg;
124 1.9 ad
125 1.1 groo lm_attach(lmsc);
126 1.9 ad }
127 1.9 ad
128 1.19 xtraeme int
129 1.19 xtraeme lm_isa_detach(device_t self, int flags)
130 1.19 xtraeme {
131 1.19 xtraeme struct lm_softc *lmsc = device_private(self);
132 1.19 xtraeme
133 1.19 xtraeme lm_detach(lmsc);
134 1.19 xtraeme bus_space_unmap(lmsc->lm_iot, lmsc->lm_ioh, 8);
135 1.19 xtraeme return 0;
136 1.19 xtraeme }
137 1.9 ad
138 1.16 xtraeme uint8_t
139 1.16 xtraeme lm_isa_readreg(struct lm_softc *sc, int reg)
140 1.9 ad {
141 1.9 ad bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
142 1.16 xtraeme return bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA);
143 1.9 ad }
144 1.9 ad
145 1.9 ad
146 1.9 ad void
147 1.16 xtraeme lm_isa_writereg(struct lm_softc *sc, int reg, int val)
148 1.9 ad {
149 1.9 ad bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
150 1.9 ad bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);
151 1.1 groo }
152 1.17 xtraeme
153