ug_isa.c revision 1.3 1 /* $NetBSD: ug_isa.c,v 1.3 2007/09/09 05:39:10 xtraeme Exp $ */
2
3 /*
4 * Copyright (c) 2007 Mihai Chelaru <kefren (at) netbsd.ro>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
15 *
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.
26 */
27
28 /*
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
32 */
33
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: ug_isa.c,v 1.3 2007/09/09 05:39:10 xtraeme Exp $");
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/proc.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
43 #include <sys/errno.h>
44 #include <sys/conf.h>
45 #include <sys/envsys.h>
46 #include <sys/time.h>
47
48 #include <machine/bus.h>
49 #include <machine/intr.h>
50
51 #include <dev/isa/isareg.h>
52 #include <dev/isa/isavar.h>
53
54 #include <dev/sysmon/sysmonvar.h>
55
56 #include <dev/ic/ugreg.h>
57 #include <dev/ic/ugvar.h>
58
59 /* autoconf(9) functions */
60 static int ug_isa_match(struct device *, struct cfdata *, void *);
61 static void ug_isa_attach(struct device *, struct device *, void *);
62 static int ug_isa_detach(struct device *, int);
63
64 CFATTACH_DECL(ug_isa, sizeof(struct ug_softc),
65 ug_isa_match, ug_isa_attach, ug_isa_detach, NULL);
66
67 extern uint8_t ug_ver;
68
69 static int
70 ug_isa_match(struct device *parent, struct cfdata *match, void *aux)
71 {
72 struct isa_attach_args *ia = aux;
73 struct ug_softc wrap_sc;
74 bus_space_handle_t bsh;
75 uint8_t valc, vald;
76
77 if (ia->ia_nio < 1) /* need base addr */
78 return 0;
79
80 if (ISA_DIRECT_CONFIG(ia))
81 return 0;
82
83 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
84 return 0;
85
86 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &bsh))
87 return 0;
88
89 valc = bus_space_read_1(ia->ia_iot, bsh, UG_CMD);
90 vald = bus_space_read_1(ia->ia_iot, bsh, UG_DATA);
91
92 ug_ver = 0;
93
94 /* Check for uGuru 2003 */
95
96 if (((vald == 0) || (vald == 8)) && (valc == 0xAC))
97 ug_ver = 1;
98
99 /* Check for uGuru 2005 */
100
101 wrap_sc.sc_iot = ia->ia_iot;
102 wrap_sc.sc_ioh = bsh;
103
104 if (ug2_sync(&wrap_sc) == 1)
105 ug_ver = 2;
106
107 /* unmap, prepare ia and bye */
108 bus_space_unmap(ia->ia_iot, bsh, 8);
109
110 if (ug_ver != 0) {
111 ia->ia_nio = 1;
112 ia->ia_io[0].ir_size = 8;
113 ia->ia_niomem = 0;
114 ia->ia_nirq = 0;
115 ia->ia_ndrq = 0;
116 return 1;
117 }
118
119 return 0;
120
121 }
122
123 static void
124 ug_isa_attach(struct device *parent, struct device *self, void *aux)
125 {
126 struct ug_softc *sc = (void *)self;
127 struct isa_attach_args *ia = aux;
128 int i;
129
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");
133 return;
134 }
135
136 ia->ia_iot = sc->sc_iot;
137 sc->version = ug_ver;
138
139 if (sc->version == 2) {
140 ug2_attach(sc);
141 return;
142 }
143
144 aprint_normal(": Abit uGuru system monitor\n");
145
146 if (!ug_reset(sc))
147 aprint_error("%s: reset failed.\n", sc->sc_dev.dv_xname);
148
149 ug_setup_sensors(sc);
150
151 for (i = 0; i < UG_NUM_SENSORS; i++) {
152 sc->sc_data[i].sensor = i;
153 sc->sc_data[i].state = ENVSYS_SVALID;
154 }
155
156 sc->sc_sysmon.sme_sensor_data = sc->sc_data;
157 sc->sc_sysmon.sme_cookie = sc;
158 sc->sc_sysmon.sme_gtredata = ug_gtredata;
159 sc->sc_sysmon.sme_nsensors = UG_NUM_SENSORS;
160
161 if (sysmon_envsys_register(&sc->sc_sysmon))
162 aprint_error("%s: unable to register with sysmon\n",
163 sc->sc_dev.dv_xname);
164
165 }
166
167 static int
168 ug_isa_detach(struct device *self, int flags)
169 {
170 struct ug_softc *sc = device_private(self);
171
172 sysmon_envsys_unregister(&sc->sc_sysmon);
173 bus_space_unmap(sc->sc_iot, sc->sc_ioh, 8);
174 return 0;
175 }
176
177