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