No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / isa / lm_isa.c
blob0c4757c6a6891d63b4d60b7344ad63348e8d1efe
1 /* $NetBSD: lm_isa.c,v 1.21 2008/10/12 13:17:28 pgoyette Exp $ */
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Bill Squier.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: lm_isa.c,v 1.21 2008/10/12 13:17:28 pgoyette Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/device.h>
39 #include <sys/conf.h>
41 #include <sys/bus.h>
43 #include <dev/isa/isareg.h>
44 #include <dev/isa/isavar.h>
46 #include <dev/sysmon/sysmonvar.h>
48 #include <dev/ic/nslm7xvar.h>
50 int lm_isa_match(device_t, cfdata_t, void *);
51 void lm_isa_attach(device_t, device_t, void *);
52 int lm_isa_detach(device_t, int);
54 uint8_t lm_isa_readreg(struct lm_softc *, int);
55 void lm_isa_writereg(struct lm_softc *, int, int);
57 struct lm_isa_softc {
58 struct lm_softc lmsc;
59 bus_space_tag_t lm_iot;
60 bus_space_handle_t lm_ioh;
63 CFATTACH_DECL_NEW(lm_isa, sizeof(struct lm_isa_softc),
64 lm_isa_match, lm_isa_attach, lm_isa_detach, NULL);
66 int
67 lm_isa_match(device_t parent, cfdata_t match, void *aux)
69 bus_space_handle_t ioh;
70 struct isa_attach_args *ia = aux;
71 struct lm_isa_softc sc;
72 int rv;
74 /* Must supply an address */
75 if (ia->ia_nio < 1)
76 return 0;
78 if (ISA_DIRECT_CONFIG(ia))
79 return 0;
81 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
82 return 0;
84 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &ioh))
85 return 0;
88 /* Bus independent probe */
89 sc.lm_iot = ia->ia_iot;
90 sc.lm_ioh = ioh;
91 sc.lmsc.lm_writereg = lm_isa_writereg;
92 sc.lmsc.lm_readreg = lm_isa_readreg;
93 rv = lm_probe(&sc.lmsc);
95 bus_space_unmap(ia->ia_iot, ioh, 8);
97 if (rv) {
98 ia->ia_nio = 1;
99 ia->ia_io[0].ir_size = 8;
101 ia->ia_niomem = 0;
102 ia->ia_nirq = 0;
103 ia->ia_ndrq = 0;
106 return rv;
110 void
111 lm_isa_attach(device_t parent, device_t self, void *aux)
113 struct lm_isa_softc *sc = device_private(self);
114 struct isa_attach_args *ia = aux;
116 sc->lm_iot = ia->ia_iot;
118 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0,
119 &sc->lm_ioh)) {
120 aprint_error(": can't map i/o space\n");
121 return;
124 /* Bus-independent attachment */
125 sc->lmsc.sc_dev = self;
126 sc->lmsc.lm_writereg = lm_isa_writereg;
127 sc->lmsc.lm_readreg = lm_isa_readreg;
129 lm_attach(&sc->lmsc);
133 lm_isa_detach(device_t self, int flags)
135 struct lm_isa_softc *sc = device_private(self);
137 lm_detach(&sc->lmsc);
138 bus_space_unmap(sc->lm_iot, sc->lm_ioh, 8);
139 return 0;
142 uint8_t
143 lm_isa_readreg(struct lm_softc *lmsc, int reg)
145 struct lm_isa_softc *sc = (struct lm_isa_softc *)lmsc;
147 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
148 return bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA);
152 void
153 lm_isa_writereg(struct lm_softc *lmsc, int reg, int val)
155 struct lm_isa_softc *sc = (struct lm_isa_softc *)lmsc;
157 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
158 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);