1 /* $NetBSD: ug_isa.c,v 1.6 2008/03/26 16:09:37 xtraeme Exp $ */
4 * Copyright (c) 2007 Mihai Chelaru <kefren@netbsd.ro>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * Driver for Abit uGuru (interface is inspired from it.c and nslm7x.c)
30 * Inspired by olle sandberg linux driver as Abit didn't care to release docs
31 * Support for uGuru 2005 from Louis Kruger and Hans de Goede linux driver
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: ug_isa.c,v 1.6 2008/03/26 16:09:37 xtraeme Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
43 #include <sys/errno.h>
45 #include <sys/envsys.h>
51 #include <dev/isa/isareg.h>
52 #include <dev/isa/isavar.h>
54 #include <dev/sysmon/sysmonvar.h>
56 #include <dev/ic/ugreg.h>
57 #include <dev/ic/ugvar.h>
59 /* autoconf(9) functions */
60 static int ug_isa_match(device_t
, cfdata_t
, void *);
61 static void ug_isa_attach(device_t
, device_t
, void *);
62 static int ug_isa_detach(device_t
, int);
64 CFATTACH_DECL_NEW(ug_isa
, sizeof(struct ug_softc
),
65 ug_isa_match
, ug_isa_attach
, ug_isa_detach
, NULL
);
67 extern uint8_t ug_ver
;
70 ug_isa_match(device_t parent
, cfdata_t match
, void *aux
)
72 struct isa_attach_args
*ia
= aux
;
73 struct ug_softc wrap_sc
;
74 bus_space_handle_t bsh
;
77 if (ia
->ia_nio
< 1) /* need base addr */
80 if (ISA_DIRECT_CONFIG(ia
))
83 if (ia
->ia_io
[0].ir_addr
== ISA_UNKNOWN_PORT
)
86 if (bus_space_map(ia
->ia_iot
, ia
->ia_io
[0].ir_addr
, 8, 0, &bsh
))
89 valc
= bus_space_read_1(ia
->ia_iot
, bsh
, UG_CMD
);
90 vald
= bus_space_read_1(ia
->ia_iot
, bsh
, UG_DATA
);
94 /* Check for uGuru 2003 */
96 if (((vald
== 0) || (vald
== 8)) && (valc
== 0xAC))
99 /* Check for uGuru 2005 */
101 wrap_sc
.sc_iot
= ia
->ia_iot
;
102 wrap_sc
.sc_ioh
= bsh
;
104 if (ug2_sync(&wrap_sc
) == 1)
107 /* unmap, prepare ia and bye */
108 bus_space_unmap(ia
->ia_iot
, bsh
, 8);
112 ia
->ia_io
[0].ir_size
= 8;
124 ug_isa_attach(device_t parent
, device_t self
, void *aux
)
126 struct ug_softc
*sc
= device_private(self
);
127 struct isa_attach_args
*ia
= aux
;
130 if (bus_space_map(sc
->sc_iot
, ia
->ia_io
[0].ir_addr
,
131 8, 0, &sc
->sc_ioh
)) {
132 aprint_error(": can't map i/o space\n");
136 ia
->ia_iot
= sc
->sc_iot
;
137 sc
->version
= ug_ver
;
139 if (sc
->version
== 2) {
144 aprint_normal(": Abit uGuru system monitor\n");
147 aprint_error_dev(self
, "reset failed.\n");
149 ug_setup_sensors(sc
);
150 sc
->sc_sme
= sysmon_envsys_create();
152 for (i
= 0; i
< UG_NUM_SENSORS
; i
++) {
153 if (sysmon_envsys_sensor_attach(sc
->sc_sme
,
154 &sc
->sc_sensor
[i
])) {
155 sysmon_envsys_destroy(sc
->sc_sme
);
160 sc
->sc_sme
->sme_cookie
= sc
;
161 sc
->sc_sme
->sme_refresh
= ug_refresh
;
163 if (sysmon_envsys_register(sc
->sc_sme
)) {
164 aprint_error_dev(self
, "unable to register with sysmon\n");
165 sysmon_envsys_destroy(sc
->sc_sme
);
172 bus_space_unmap(sc
->sc_iot
, sc
->sc_ioh
, 8);
177 ug_isa_detach(device_t self
, int flags
)
179 struct ug_softc
*sc
= device_private(self
);
181 sysmon_envsys_unregister(sc
->sc_sme
);
182 bus_space_unmap(sc
->sc_iot
, sc
->sc_ioh
, 8);