ug_isa.c revision 1.1.2.2 1 1.1.2.2 pavel /* $NetBSD: ug_isa.c,v 1.1.2.2 2007/05/13 06:52:54 pavel Exp $ */
2 1.1.2.2 pavel
3 1.1.2.2 pavel /*
4 1.1.2.2 pavel * Copyright (c) 2007 Mihai Chelaru <kefren (at) netbsd.ro>
5 1.1.2.2 pavel * All rights reserved.
6 1.1.2.2 pavel *
7 1.1.2.2 pavel * Redistribution and use in source and binary forms, with or without
8 1.1.2.2 pavel * modification, are permitted provided that the following conditions
9 1.1.2.2 pavel * are met:
10 1.1.2.2 pavel * 1. Redistributions of source code must retain the above copyright
11 1.1.2.2 pavel * notice, this list of conditions and the following disclaimer.
12 1.1.2.2 pavel * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.2.2 pavel * notice, this list of conditions and the following disclaimer in the
14 1.1.2.2 pavel * documentation and/or other materials provided with the distribution.
15 1.1.2.2 pavel *
16 1.1.2.2 pavel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1.2.2 pavel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1.2.2 pavel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1.2.2 pavel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1.2.2 pavel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1.2.2 pavel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1.2.2 pavel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1.2.2 pavel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1.2.2 pavel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1.2.2 pavel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1.2.2 pavel */
27 1.1.2.2 pavel
28 1.1.2.2 pavel /*
29 1.1.2.2 pavel * Driver for Abit uGuru (interface is inspired from it.c and nslm7x.c)
30 1.1.2.2 pavel * Inspired by olle sandberg linux driver as Abit didn't care to release docs
31 1.1.2.2 pavel * Support for uGuru 2005 from Louis Kruger and Hans de Goede linux driver
32 1.1.2.2 pavel */
33 1.1.2.2 pavel
34 1.1.2.2 pavel #include <sys/cdefs.h>
35 1.1.2.2 pavel __KERNEL_RCSID(0, "$NetBSD: ug_isa.c,v 1.1.2.2 2007/05/13 06:52:54 pavel Exp $");
36 1.1.2.2 pavel
37 1.1.2.2 pavel #include <sys/param.h>
38 1.1.2.2 pavel #include <sys/systm.h>
39 1.1.2.2 pavel #include <sys/kernel.h>
40 1.1.2.2 pavel #include <sys/proc.h>
41 1.1.2.2 pavel #include <sys/device.h>
42 1.1.2.2 pavel #include <sys/malloc.h>
43 1.1.2.2 pavel #include <sys/errno.h>
44 1.1.2.2 pavel #include <sys/conf.h>
45 1.1.2.2 pavel #include <sys/envsys.h>
46 1.1.2.2 pavel #include <sys/time.h>
47 1.1.2.2 pavel
48 1.1.2.2 pavel #include <machine/bus.h>
49 1.1.2.2 pavel #include <machine/intr.h>
50 1.1.2.2 pavel
51 1.1.2.2 pavel #include <dev/isa/isareg.h>
52 1.1.2.2 pavel #include <dev/isa/isavar.h>
53 1.1.2.2 pavel
54 1.1.2.2 pavel #include <dev/sysmon/sysmonvar.h>
55 1.1.2.2 pavel
56 1.1.2.2 pavel #include <dev/ic/ugreg.h>
57 1.1.2.2 pavel #include <dev/ic/ugvar.h>
58 1.1.2.2 pavel
59 1.1.2.2 pavel /* autoconf(9) functions */
60 1.1.2.2 pavel static int ug_isa_match(struct device *, struct cfdata *, void *);
61 1.1.2.2 pavel static void ug_isa_attach(struct device *, struct device *, void *);
62 1.1.2.2 pavel
63 1.1.2.2 pavel CFATTACH_DECL(ug_isa, sizeof(struct ug_softc),
64 1.1.2.2 pavel ug_isa_match, ug_isa_attach, NULL, NULL);
65 1.1.2.2 pavel
66 1.1.2.2 pavel extern uint8_t ug_ver;
67 1.1.2.2 pavel
68 1.1.2.2 pavel static int
69 1.1.2.2 pavel ug_isa_match(struct device *parent, struct cfdata *match, void *aux)
70 1.1.2.2 pavel {
71 1.1.2.2 pavel struct isa_attach_args *ia = aux;
72 1.1.2.2 pavel struct ug_softc wrap_sc;
73 1.1.2.2 pavel bus_space_handle_t bsh;
74 1.1.2.2 pavel uint8_t valc, vald;
75 1.1.2.2 pavel
76 1.1.2.2 pavel if (ia->ia_nio < 1) /* need base addr */
77 1.1.2.2 pavel return 0;
78 1.1.2.2 pavel
79 1.1.2.2 pavel if (ISA_DIRECT_CONFIG(ia))
80 1.1.2.2 pavel return 0;
81 1.1.2.2 pavel
82 1.1.2.2 pavel if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
83 1.1.2.2 pavel return 0;
84 1.1.2.2 pavel
85 1.1.2.2 pavel if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &bsh))
86 1.1.2.2 pavel return 0;
87 1.1.2.2 pavel
88 1.1.2.2 pavel valc = bus_space_read_1(ia->ia_iot, bsh, UG_CMD);
89 1.1.2.2 pavel vald = bus_space_read_1(ia->ia_iot, bsh, UG_DATA);
90 1.1.2.2 pavel
91 1.1.2.2 pavel ug_ver = 0;
92 1.1.2.2 pavel
93 1.1.2.2 pavel /* Check for uGuru 2003 */
94 1.1.2.2 pavel
95 1.1.2.2 pavel if (((vald == 0) || (vald == 8)) && (valc == 0xAC))
96 1.1.2.2 pavel ug_ver = 1;
97 1.1.2.2 pavel
98 1.1.2.2 pavel /* Check for uGuru 2005 */
99 1.1.2.2 pavel
100 1.1.2.2 pavel wrap_sc.sc_iot = ia->ia_iot;
101 1.1.2.2 pavel wrap_sc.sc_ioh = bsh;
102 1.1.2.2 pavel
103 1.1.2.2 pavel if (ug2_sync(&wrap_sc) == 1)
104 1.1.2.2 pavel ug_ver = 2;
105 1.1.2.2 pavel
106 1.1.2.2 pavel /* unmap, prepare ia and bye */
107 1.1.2.2 pavel bus_space_unmap(ia->ia_iot, bsh, 8);
108 1.1.2.2 pavel
109 1.1.2.2 pavel if (ug_ver != 0) {
110 1.1.2.2 pavel ia->ia_nio = 1;
111 1.1.2.2 pavel ia->ia_io[0].ir_size = 8;
112 1.1.2.2 pavel ia->ia_niomem = 0;
113 1.1.2.2 pavel ia->ia_nirq = 0;
114 1.1.2.2 pavel ia->ia_ndrq = 0;
115 1.1.2.2 pavel return 1;
116 1.1.2.2 pavel }
117 1.1.2.2 pavel
118 1.1.2.2 pavel return 0;
119 1.1.2.2 pavel
120 1.1.2.2 pavel }
121 1.1.2.2 pavel
122 1.1.2.2 pavel static void
123 1.1.2.2 pavel ug_isa_attach(struct device *parent, struct device *self, void *aux)
124 1.1.2.2 pavel {
125 1.1.2.2 pavel struct ug_softc *sc = (void *)self;
126 1.1.2.2 pavel struct isa_attach_args *ia = aux;
127 1.1.2.2 pavel int i;
128 1.1.2.2 pavel
129 1.1.2.2 pavel if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
130 1.1.2.2 pavel 8, 0, &sc->sc_ioh)) {
131 1.1.2.2 pavel aprint_error(": can't map i/o space\n");
132 1.1.2.2 pavel return;
133 1.1.2.2 pavel }
134 1.1.2.2 pavel
135 1.1.2.2 pavel ia->ia_iot = sc->sc_iot;
136 1.1.2.2 pavel sc->version = ug_ver;
137 1.1.2.2 pavel
138 1.1.2.2 pavel if (sc->version == 2) {
139 1.1.2.2 pavel ug2_attach(sc);
140 1.1.2.2 pavel return;
141 1.1.2.2 pavel }
142 1.1.2.2 pavel
143 1.1.2.2 pavel aprint_normal(": Abit uGuru system monitor\n");
144 1.1.2.2 pavel
145 1.1.2.2 pavel if (!ug_reset(sc))
146 1.1.2.2 pavel aprint_error("%s: reset failed.\n", sc->sc_dev.dv_xname);
147 1.1.2.2 pavel
148 1.1.2.2 pavel ug_setup_sensors(sc);
149 1.1.2.2 pavel
150 1.1.2.2 pavel for (i = 0; i < UG_NUM_SENSORS; i++) {
151 1.1.2.2 pavel sc->sc_data[i].sensor = sc->sc_info[i].sensor = i;
152 1.1.2.2 pavel sc->sc_data[i].validflags = (ENVSYS_FVALID|ENVSYS_FCURVALID);
153 1.1.2.2 pavel sc->sc_info[i].validflags = ENVSYS_FVALID;
154 1.1.2.2 pavel sc->sc_data[i].warnflags = ENVSYS_WARN_OK;
155 1.1.2.2 pavel }
156 1.1.2.2 pavel
157 1.1.2.2 pavel sc->sc_sysmon.sme_ranges = ug_ranges;
158 1.1.2.2 pavel sc->sc_sysmon.sme_sensor_info = sc->sc_info;
159 1.1.2.2 pavel sc->sc_sysmon.sme_sensor_data = sc->sc_data;
160 1.1.2.2 pavel sc->sc_sysmon.sme_cookie = sc;
161 1.1.2.2 pavel sc->sc_sysmon.sme_gtredata = ug_gtredata;
162 1.1.2.2 pavel sc->sc_sysmon.sme_streinfo = ug_streinfo_ni;
163 1.1.2.2 pavel sc->sc_sysmon.sme_nsensors = UG_NUM_SENSORS;
164 1.1.2.2 pavel sc->sc_sysmon.sme_envsys_version = UG_DRV_VERSION;
165 1.1.2.2 pavel sc->sc_sysmon.sme_flags = 0;
166 1.1.2.2 pavel
167 1.1.2.2 pavel if (sysmon_envsys_register(&sc->sc_sysmon))
168 1.1.2.2 pavel aprint_error("%s: unable to register with sysmon\n",
169 1.1.2.2 pavel sc->sc_dev.dv_xname);
170 1.1.2.2 pavel
171 1.1.2.2 pavel }
172 1.1.2.2 pavel /* $NetBSD: ug_isa.c,v 1.1.2.2 2007/05/13 06:52:54 pavel Exp $ */
173 1.1.2.2 pavel
174 1.1.2.2 pavel /*
175 1.1.2.2 pavel * Copyright (c) 2007 Mihai Chelaru <kefren (at) netbsd.ro>
176 1.1.2.2 pavel * All rights reserved.
177 1.1.2.2 pavel *
178 1.1.2.2 pavel * Redistribution and use in source and binary forms, with or without
179 1.1.2.2 pavel * modification, are permitted provided that the following conditions
180 1.1.2.2 pavel * are met:
181 1.1.2.2 pavel * 1. Redistributions of source code must retain the above copyright
182 1.1.2.2 pavel * notice, this list of conditions and the following disclaimer.
183 1.1.2.2 pavel * 2. Redistributions in binary form must reproduce the above copyright
184 1.1.2.2 pavel * notice, this list of conditions and the following disclaimer in the
185 1.1.2.2 pavel * documentation and/or other materials provided with the distribution.
186 1.1.2.2 pavel *
187 1.1.2.2 pavel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
188 1.1.2.2 pavel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
189 1.1.2.2 pavel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
190 1.1.2.2 pavel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
191 1.1.2.2 pavel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
192 1.1.2.2 pavel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
193 1.1.2.2 pavel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
194 1.1.2.2 pavel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
195 1.1.2.2 pavel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
196 1.1.2.2 pavel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
197 1.1.2.2 pavel */
198 1.1.2.2 pavel
199 1.1.2.2 pavel /*
200 1.1.2.2 pavel * Driver for Abit uGuru (interface is inspired from it.c and nslm7x.c)
201 1.1.2.2 pavel * Inspired by olle sandberg linux driver as Abit didn't care to release docs
202 1.1.2.2 pavel * Support for uGuru 2005 from Louis Kruger and Hans de Goede linux driver
203 1.1.2.2 pavel */
204 1.1.2.2 pavel
205 1.1.2.2 pavel #include <sys/cdefs.h>
206 1.1.2.2 pavel __KERNEL_RCSID(0, "$NetBSD: ug_isa.c,v 1.1.2.2 2007/05/13 06:52:54 pavel Exp $");
207 1.1.2.2 pavel
208 1.1.2.2 pavel #include <sys/param.h>
209 1.1.2.2 pavel #include <sys/systm.h>
210 1.1.2.2 pavel #include <sys/kernel.h>
211 1.1.2.2 pavel #include <sys/proc.h>
212 1.1.2.2 pavel #include <sys/device.h>
213 1.1.2.2 pavel #include <sys/malloc.h>
214 1.1.2.2 pavel #include <sys/errno.h>
215 1.1.2.2 pavel #include <sys/conf.h>
216 1.1.2.2 pavel #include <sys/envsys.h>
217 1.1.2.2 pavel #include <sys/time.h>
218 1.1.2.2 pavel
219 1.1.2.2 pavel #include <machine/bus.h>
220 1.1.2.2 pavel #include <machine/intr.h>
221 1.1.2.2 pavel
222 1.1.2.2 pavel #include <dev/isa/isareg.h>
223 1.1.2.2 pavel #include <dev/isa/isavar.h>
224 1.1.2.2 pavel
225 1.1.2.2 pavel #include <dev/sysmon/sysmonvar.h>
226 1.1.2.2 pavel
227 1.1.2.2 pavel #include <dev/ic/ugreg.h>
228 1.1.2.2 pavel #include <dev/ic/ugvar.h>
229 1.1.2.2 pavel
230 1.1.2.2 pavel /* autoconf(9) functions */
231 1.1.2.2 pavel static int ug_isa_match(struct device *, struct cfdata *, void *);
232 1.1.2.2 pavel static void ug_isa_attach(struct device *, struct device *, void *);
233 1.1.2.2 pavel
234 1.1.2.2 pavel CFATTACH_DECL(ug_isa, sizeof(struct ug_softc),
235 1.1.2.2 pavel ug_isa_match, ug_isa_attach, NULL, NULL);
236 1.1.2.2 pavel
237 1.1.2.2 pavel extern uint8_t ug_ver;
238 1.1.2.2 pavel
239 1.1.2.2 pavel static int
240 1.1.2.2 pavel ug_isa_match(struct device *parent, struct cfdata *match, void *aux)
241 1.1.2.2 pavel {
242 1.1.2.2 pavel struct isa_attach_args *ia = aux;
243 1.1.2.2 pavel struct ug_softc wrap_sc;
244 1.1.2.2 pavel bus_space_handle_t bsh;
245 1.1.2.2 pavel uint8_t valc, vald;
246 1.1.2.2 pavel
247 1.1.2.2 pavel if (ia->ia_nio < 1) /* need base addr */
248 1.1.2.2 pavel return 0;
249 1.1.2.2 pavel
250 1.1.2.2 pavel if (ISA_DIRECT_CONFIG(ia))
251 1.1.2.2 pavel return 0;
252 1.1.2.2 pavel
253 1.1.2.2 pavel if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
254 1.1.2.2 pavel return 0;
255 1.1.2.2 pavel
256 1.1.2.2 pavel if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &bsh))
257 1.1.2.2 pavel return 0;
258 1.1.2.2 pavel
259 1.1.2.2 pavel valc = bus_space_read_1(ia->ia_iot, bsh, UG_CMD);
260 1.1.2.2 pavel vald = bus_space_read_1(ia->ia_iot, bsh, UG_DATA);
261 1.1.2.2 pavel
262 1.1.2.2 pavel ug_ver = 0;
263 1.1.2.2 pavel
264 1.1.2.2 pavel /* Check for uGuru 2003 */
265 1.1.2.2 pavel
266 1.1.2.2 pavel if (((vald == 0) || (vald == 8)) && (valc == 0xAC))
267 1.1.2.2 pavel ug_ver = 1;
268 1.1.2.2 pavel
269 1.1.2.2 pavel /* Check for uGuru 2005 */
270 1.1.2.2 pavel
271 1.1.2.2 pavel wrap_sc.sc_iot = ia->ia_iot;
272 1.1.2.2 pavel wrap_sc.sc_ioh = bsh;
273 1.1.2.2 pavel
274 1.1.2.2 pavel if (ug2_sync(&wrap_sc) == 1)
275 1.1.2.2 pavel ug_ver = 2;
276 1.1.2.2 pavel
277 1.1.2.2 pavel /* unmap, prepare ia and bye */
278 1.1.2.2 pavel bus_space_unmap(ia->ia_iot, bsh, 8);
279 1.1.2.2 pavel
280 1.1.2.2 pavel if (ug_ver != 0) {
281 1.1.2.2 pavel ia->ia_nio = 1;
282 1.1.2.2 pavel ia->ia_io[0].ir_size = 8;
283 1.1.2.2 pavel ia->ia_niomem = 0;
284 1.1.2.2 pavel ia->ia_nirq = 0;
285 1.1.2.2 pavel ia->ia_ndrq = 0;
286 1.1.2.2 pavel return 1;
287 1.1.2.2 pavel }
288 1.1.2.2 pavel
289 1.1.2.2 pavel return 0;
290 1.1.2.2 pavel
291 1.1.2.2 pavel }
292 1.1.2.2 pavel
293 1.1.2.2 pavel static void
294 1.1.2.2 pavel ug_isa_attach(struct device *parent, struct device *self, void *aux)
295 1.1.2.2 pavel {
296 1.1.2.2 pavel struct ug_softc *sc = (void *)self;
297 1.1.2.2 pavel struct isa_attach_args *ia = aux;
298 1.1.2.2 pavel int i;
299 1.1.2.2 pavel
300 1.1.2.2 pavel if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
301 1.1.2.2 pavel 8, 0, &sc->sc_ioh)) {
302 1.1.2.2 pavel aprint_error(": can't map i/o space\n");
303 1.1.2.2 pavel return;
304 1.1.2.2 pavel }
305 1.1.2.2 pavel
306 1.1.2.2 pavel ia->ia_iot = sc->sc_iot;
307 1.1.2.2 pavel sc->version = ug_ver;
308 1.1.2.2 pavel
309 1.1.2.2 pavel if (sc->version == 2) {
310 1.1.2.2 pavel ug2_attach(sc);
311 1.1.2.2 pavel return;
312 1.1.2.2 pavel }
313 1.1.2.2 pavel
314 1.1.2.2 pavel aprint_normal(": Abit uGuru system monitor\n");
315 1.1.2.2 pavel
316 1.1.2.2 pavel if (!ug_reset(sc))
317 1.1.2.2 pavel aprint_error("%s: reset failed.\n", sc->sc_dev.dv_xname);
318 1.1.2.2 pavel
319 1.1.2.2 pavel ug_setup_sensors(sc);
320 1.1.2.2 pavel
321 1.1.2.2 pavel for (i = 0; i < UG_NUM_SENSORS; i++) {
322 1.1.2.2 pavel sc->sc_data[i].sensor = sc->sc_info[i].sensor = i;
323 1.1.2.2 pavel sc->sc_data[i].validflags = (ENVSYS_FVALID|ENVSYS_FCURVALID);
324 1.1.2.2 pavel sc->sc_info[i].validflags = ENVSYS_FVALID;
325 1.1.2.2 pavel sc->sc_data[i].warnflags = ENVSYS_WARN_OK;
326 1.1.2.2 pavel }
327 1.1.2.2 pavel
328 1.1.2.2 pavel sc->sc_sysmon.sme_ranges = ug_ranges;
329 1.1.2.2 pavel sc->sc_sysmon.sme_sensor_info = sc->sc_info;
330 1.1.2.2 pavel sc->sc_sysmon.sme_sensor_data = sc->sc_data;
331 1.1.2.2 pavel sc->sc_sysmon.sme_cookie = sc;
332 1.1.2.2 pavel sc->sc_sysmon.sme_gtredata = ug_gtredata;
333 1.1.2.2 pavel sc->sc_sysmon.sme_streinfo = ug_streinfo_ni;
334 1.1.2.2 pavel sc->sc_sysmon.sme_nsensors = UG_NUM_SENSORS;
335 1.1.2.2 pavel sc->sc_sysmon.sme_envsys_version = UG_DRV_VERSION;
336 1.1.2.2 pavel sc->sc_sysmon.sme_flags = 0;
337 1.1.2.2 pavel
338 1.1.2.2 pavel if (sysmon_envsys_register(&sc->sc_sysmon))
339 1.1.2.2 pavel aprint_error("%s: unable to register with sysmon\n",
340 1.1.2.2 pavel sc->sc_dev.dv_xname);
341 1.1.2.2 pavel
342 1.1.2.2 pavel }
343