lm_isa.c revision 1.23 1 1.23 cnst /* $NetBSD: lm_isa.c,v 1.23 2010/02/21 05:16:29 cnst 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 *
19 1.1 groo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 groo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 groo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 groo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 groo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 groo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 groo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 groo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 groo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 groo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 groo * POSSIBILITY OF SUCH DAMAGE.
30 1.1 groo */
31 1.4 lukem
32 1.4 lukem #include <sys/cdefs.h>
33 1.23 cnst __KERNEL_RCSID(0, "$NetBSD: lm_isa.c,v 1.23 2010/02/21 05:16:29 cnst Exp $");
34 1.1 groo
35 1.1 groo #include <sys/param.h>
36 1.1 groo #include <sys/systm.h>
37 1.1 groo #include <sys/kernel.h>
38 1.1 groo #include <sys/device.h>
39 1.1 groo #include <sys/conf.h>
40 1.1 groo
41 1.18 ad #include <sys/bus.h>
42 1.1 groo
43 1.1 groo #include <dev/isa/isareg.h>
44 1.1 groo #include <dev/isa/isavar.h>
45 1.1 groo
46 1.3 thorpej #include <dev/sysmon/sysmonvar.h>
47 1.1 groo
48 1.1 groo #include <dev/ic/nslm7xvar.h>
49 1.1 groo
50 1.19 xtraeme int lm_isa_match(device_t, cfdata_t, void *);
51 1.19 xtraeme void lm_isa_attach(device_t, device_t, void *);
52 1.19 xtraeme int lm_isa_detach(device_t, int);
53 1.1 groo
54 1.16 xtraeme uint8_t lm_isa_readreg(struct lm_softc *, int);
55 1.19 xtraeme void lm_isa_writereg(struct lm_softc *, int, int);
56 1.1 groo
57 1.21 pgoyette struct lm_isa_softc {
58 1.21 pgoyette struct lm_softc lmsc;
59 1.21 pgoyette bus_space_tag_t lm_iot;
60 1.21 pgoyette bus_space_handle_t lm_ioh;
61 1.21 pgoyette };
62 1.21 pgoyette
63 1.21 pgoyette CFATTACH_DECL_NEW(lm_isa, sizeof(struct lm_isa_softc),
64 1.17 xtraeme lm_isa_match, lm_isa_attach, lm_isa_detach, NULL);
65 1.1 groo
66 1.23 cnst CFATTACH_DECL_NEW(lm_wbsio, sizeof(struct lm_isa_softc),
67 1.23 cnst lm_isa_match, lm_isa_attach, lm_isa_detach, NULL);
68 1.23 cnst
69 1.1 groo int
70 1.19 xtraeme lm_isa_match(device_t parent, cfdata_t match, void *aux)
71 1.1 groo {
72 1.1 groo bus_space_handle_t ioh;
73 1.1 groo struct isa_attach_args *ia = aux;
74 1.21 pgoyette struct lm_isa_softc sc;
75 1.1 groo int rv;
76 1.1 groo
77 1.1 groo /* Must supply an address */
78 1.5 thorpej if (ia->ia_nio < 1)
79 1.16 xtraeme return 0;
80 1.5 thorpej
81 1.5 thorpej if (ISA_DIRECT_CONFIG(ia))
82 1.16 xtraeme return 0;
83 1.5 thorpej
84 1.10 drochner if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
85 1.16 xtraeme return 0;
86 1.1 groo
87 1.16 xtraeme if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &ioh))
88 1.16 xtraeme return 0;
89 1.1 groo
90 1.1 groo
91 1.2 groo /* Bus independent probe */
92 1.21 pgoyette sc.lm_iot = ia->ia_iot;
93 1.21 pgoyette sc.lm_ioh = ioh;
94 1.21 pgoyette sc.lmsc.lm_writereg = lm_isa_writereg;
95 1.21 pgoyette sc.lmsc.lm_readreg = lm_isa_readreg;
96 1.21 pgoyette rv = lm_probe(&sc.lmsc);
97 1.1 groo
98 1.16 xtraeme bus_space_unmap(ia->ia_iot, ioh, 8);
99 1.1 groo
100 1.1 groo if (rv) {
101 1.5 thorpej ia->ia_nio = 1;
102 1.5 thorpej ia->ia_io[0].ir_size = 8;
103 1.5 thorpej
104 1.5 thorpej ia->ia_niomem = 0;
105 1.5 thorpej ia->ia_nirq = 0;
106 1.5 thorpej ia->ia_ndrq = 0;
107 1.1 groo }
108 1.1 groo
109 1.16 xtraeme return rv;
110 1.1 groo }
111 1.1 groo
112 1.1 groo
113 1.1 groo void
114 1.19 xtraeme lm_isa_attach(device_t parent, device_t self, void *aux)
115 1.1 groo {
116 1.21 pgoyette struct lm_isa_softc *sc = device_private(self);
117 1.1 groo struct isa_attach_args *ia = aux;
118 1.1 groo
119 1.21 pgoyette sc->lm_iot = ia->ia_iot;
120 1.1 groo
121 1.16 xtraeme if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0,
122 1.21 pgoyette &sc->lm_ioh)) {
123 1.16 xtraeme aprint_error(": can't map i/o space\n");
124 1.1 groo return;
125 1.1 groo }
126 1.1 groo
127 1.14 wiz /* Bus-independent attachment */
128 1.21 pgoyette sc->lmsc.sc_dev = self;
129 1.21 pgoyette sc->lmsc.lm_writereg = lm_isa_writereg;
130 1.21 pgoyette sc->lmsc.lm_readreg = lm_isa_readreg;
131 1.9 ad
132 1.22 pgoyette lm_attach(&sc->lmsc);
133 1.9 ad }
134 1.9 ad
135 1.19 xtraeme int
136 1.19 xtraeme lm_isa_detach(device_t self, int flags)
137 1.19 xtraeme {
138 1.21 pgoyette struct lm_isa_softc *sc = device_private(self);
139 1.19 xtraeme
140 1.22 pgoyette lm_detach(&sc->lmsc);
141 1.21 pgoyette bus_space_unmap(sc->lm_iot, sc->lm_ioh, 8);
142 1.19 xtraeme return 0;
143 1.19 xtraeme }
144 1.9 ad
145 1.16 xtraeme uint8_t
146 1.21 pgoyette lm_isa_readreg(struct lm_softc *lmsc, int reg)
147 1.9 ad {
148 1.21 pgoyette struct lm_isa_softc *sc = (struct lm_isa_softc *)lmsc;
149 1.21 pgoyette
150 1.9 ad bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
151 1.16 xtraeme return bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA);
152 1.9 ad }
153 1.9 ad
154 1.9 ad
155 1.9 ad void
156 1.21 pgoyette lm_isa_writereg(struct lm_softc *lmsc, int reg, int val)
157 1.9 ad {
158 1.21 pgoyette struct lm_isa_softc *sc = (struct lm_isa_softc *)lmsc;
159 1.21 pgoyette
160 1.9 ad bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
161 1.9 ad bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);
162 1.1 groo }
163 1.17 xtraeme
164