ug_isa.c revision 1.2.12.3 1 1.2.12.3 yamt /* $NetBSD: ug_isa.c,v 1.2.12.3 2007/10/27 11:31:59 yamt Exp $ */
2 1.2.12.2 yamt
3 1.2.12.2 yamt /*
4 1.2.12.2 yamt * Copyright (c) 2007 Mihai Chelaru <kefren (at) netbsd.ro>
5 1.2.12.2 yamt * All rights reserved.
6 1.2.12.2 yamt *
7 1.2.12.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.2.12.2 yamt * modification, are permitted provided that the following conditions
9 1.2.12.2 yamt * are met:
10 1.2.12.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.2.12.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.2.12.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.12.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.2.12.2 yamt * documentation and/or other materials provided with the distribution.
15 1.2.12.2 yamt *
16 1.2.12.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.2.12.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.2.12.2 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.2.12.2 yamt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.2.12.2 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.2.12.2 yamt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.2.12.2 yamt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.2.12.2 yamt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.2.12.2 yamt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.2.12.2 yamt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.2.12.2 yamt */
27 1.2.12.2 yamt
28 1.2.12.2 yamt /*
29 1.2.12.2 yamt * Driver for Abit uGuru (interface is inspired from it.c and nslm7x.c)
30 1.2.12.2 yamt * Inspired by olle sandberg linux driver as Abit didn't care to release docs
31 1.2.12.2 yamt * Support for uGuru 2005 from Louis Kruger and Hans de Goede linux driver
32 1.2.12.2 yamt */
33 1.2.12.2 yamt
34 1.2.12.2 yamt #include <sys/cdefs.h>
35 1.2.12.3 yamt __KERNEL_RCSID(0, "$NetBSD: ug_isa.c,v 1.2.12.3 2007/10/27 11:31:59 yamt Exp $");
36 1.2.12.2 yamt
37 1.2.12.2 yamt #include <sys/param.h>
38 1.2.12.2 yamt #include <sys/systm.h>
39 1.2.12.2 yamt #include <sys/kernel.h>
40 1.2.12.2 yamt #include <sys/proc.h>
41 1.2.12.2 yamt #include <sys/device.h>
42 1.2.12.2 yamt #include <sys/malloc.h>
43 1.2.12.2 yamt #include <sys/errno.h>
44 1.2.12.2 yamt #include <sys/conf.h>
45 1.2.12.2 yamt #include <sys/envsys.h>
46 1.2.12.2 yamt #include <sys/time.h>
47 1.2.12.2 yamt
48 1.2.12.3 yamt #include <sys/bus.h>
49 1.2.12.3 yamt #include <sys/intr.h>
50 1.2.12.2 yamt
51 1.2.12.2 yamt #include <dev/isa/isareg.h>
52 1.2.12.2 yamt #include <dev/isa/isavar.h>
53 1.2.12.2 yamt
54 1.2.12.2 yamt #include <dev/sysmon/sysmonvar.h>
55 1.2.12.2 yamt
56 1.2.12.2 yamt #include <dev/ic/ugreg.h>
57 1.2.12.2 yamt #include <dev/ic/ugvar.h>
58 1.2.12.2 yamt
59 1.2.12.2 yamt /* autoconf(9) functions */
60 1.2.12.2 yamt static int ug_isa_match(struct device *, struct cfdata *, void *);
61 1.2.12.2 yamt static void ug_isa_attach(struct device *, struct device *, void *);
62 1.2.12.3 yamt static int ug_isa_detach(struct device *, int);
63 1.2.12.2 yamt
64 1.2.12.2 yamt CFATTACH_DECL(ug_isa, sizeof(struct ug_softc),
65 1.2.12.3 yamt ug_isa_match, ug_isa_attach, ug_isa_detach, NULL);
66 1.2.12.2 yamt
67 1.2.12.2 yamt extern uint8_t ug_ver;
68 1.2.12.2 yamt
69 1.2.12.2 yamt static int
70 1.2.12.2 yamt ug_isa_match(struct device *parent, struct cfdata *match, void *aux)
71 1.2.12.2 yamt {
72 1.2.12.2 yamt struct isa_attach_args *ia = aux;
73 1.2.12.2 yamt struct ug_softc wrap_sc;
74 1.2.12.2 yamt bus_space_handle_t bsh;
75 1.2.12.2 yamt uint8_t valc, vald;
76 1.2.12.2 yamt
77 1.2.12.2 yamt if (ia->ia_nio < 1) /* need base addr */
78 1.2.12.2 yamt return 0;
79 1.2.12.2 yamt
80 1.2.12.2 yamt if (ISA_DIRECT_CONFIG(ia))
81 1.2.12.2 yamt return 0;
82 1.2.12.2 yamt
83 1.2.12.2 yamt if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
84 1.2.12.2 yamt return 0;
85 1.2.12.2 yamt
86 1.2.12.2 yamt if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &bsh))
87 1.2.12.2 yamt return 0;
88 1.2.12.2 yamt
89 1.2.12.2 yamt valc = bus_space_read_1(ia->ia_iot, bsh, UG_CMD);
90 1.2.12.2 yamt vald = bus_space_read_1(ia->ia_iot, bsh, UG_DATA);
91 1.2.12.2 yamt
92 1.2.12.2 yamt ug_ver = 0;
93 1.2.12.2 yamt
94 1.2.12.2 yamt /* Check for uGuru 2003 */
95 1.2.12.2 yamt
96 1.2.12.2 yamt if (((vald == 0) || (vald == 8)) && (valc == 0xAC))
97 1.2.12.2 yamt ug_ver = 1;
98 1.2.12.2 yamt
99 1.2.12.2 yamt /* Check for uGuru 2005 */
100 1.2.12.2 yamt
101 1.2.12.2 yamt wrap_sc.sc_iot = ia->ia_iot;
102 1.2.12.2 yamt wrap_sc.sc_ioh = bsh;
103 1.2.12.2 yamt
104 1.2.12.2 yamt if (ug2_sync(&wrap_sc) == 1)
105 1.2.12.2 yamt ug_ver = 2;
106 1.2.12.2 yamt
107 1.2.12.2 yamt /* unmap, prepare ia and bye */
108 1.2.12.2 yamt bus_space_unmap(ia->ia_iot, bsh, 8);
109 1.2.12.2 yamt
110 1.2.12.2 yamt if (ug_ver != 0) {
111 1.2.12.2 yamt ia->ia_nio = 1;
112 1.2.12.2 yamt ia->ia_io[0].ir_size = 8;
113 1.2.12.2 yamt ia->ia_niomem = 0;
114 1.2.12.2 yamt ia->ia_nirq = 0;
115 1.2.12.2 yamt ia->ia_ndrq = 0;
116 1.2.12.2 yamt return 1;
117 1.2.12.2 yamt }
118 1.2.12.2 yamt
119 1.2.12.2 yamt return 0;
120 1.2.12.2 yamt
121 1.2.12.2 yamt }
122 1.2.12.2 yamt
123 1.2.12.2 yamt static void
124 1.2.12.2 yamt ug_isa_attach(struct device *parent, struct device *self, void *aux)
125 1.2.12.2 yamt {
126 1.2.12.2 yamt struct ug_softc *sc = (void *)self;
127 1.2.12.2 yamt struct isa_attach_args *ia = aux;
128 1.2.12.2 yamt int i;
129 1.2.12.2 yamt
130 1.2.12.2 yamt if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
131 1.2.12.2 yamt 8, 0, &sc->sc_ioh)) {
132 1.2.12.2 yamt aprint_error(": can't map i/o space\n");
133 1.2.12.2 yamt return;
134 1.2.12.2 yamt }
135 1.2.12.2 yamt
136 1.2.12.2 yamt ia->ia_iot = sc->sc_iot;
137 1.2.12.2 yamt sc->version = ug_ver;
138 1.2.12.2 yamt
139 1.2.12.2 yamt if (sc->version == 2) {
140 1.2.12.2 yamt ug2_attach(sc);
141 1.2.12.2 yamt return;
142 1.2.12.2 yamt }
143 1.2.12.2 yamt
144 1.2.12.2 yamt aprint_normal(": Abit uGuru system monitor\n");
145 1.2.12.2 yamt
146 1.2.12.2 yamt if (!ug_reset(sc))
147 1.2.12.2 yamt aprint_error("%s: reset failed.\n", sc->sc_dev.dv_xname);
148 1.2.12.2 yamt
149 1.2.12.2 yamt ug_setup_sensors(sc);
150 1.2.12.2 yamt
151 1.2.12.2 yamt for (i = 0; i < UG_NUM_SENSORS; i++) {
152 1.2.12.2 yamt sc->sc_data[i].sensor = i;
153 1.2.12.2 yamt sc->sc_data[i].state = ENVSYS_SVALID;
154 1.2.12.2 yamt }
155 1.2.12.2 yamt
156 1.2.12.2 yamt sc->sc_sysmon.sme_sensor_data = sc->sc_data;
157 1.2.12.2 yamt sc->sc_sysmon.sme_cookie = sc;
158 1.2.12.2 yamt sc->sc_sysmon.sme_gtredata = ug_gtredata;
159 1.2.12.2 yamt sc->sc_sysmon.sme_nsensors = UG_NUM_SENSORS;
160 1.2.12.2 yamt
161 1.2.12.2 yamt if (sysmon_envsys_register(&sc->sc_sysmon))
162 1.2.12.2 yamt aprint_error("%s: unable to register with sysmon\n",
163 1.2.12.2 yamt sc->sc_dev.dv_xname);
164 1.2.12.2 yamt
165 1.2.12.2 yamt }
166 1.2.12.3 yamt
167 1.2.12.3 yamt static int
168 1.2.12.3 yamt ug_isa_detach(struct device *self, int flags)
169 1.2.12.3 yamt {
170 1.2.12.3 yamt struct ug_softc *sc = device_private(self);
171 1.2.12.3 yamt
172 1.2.12.3 yamt sysmon_envsys_unregister(&sc->sc_sysmon);
173 1.2.12.3 yamt bus_space_unmap(sc->sc_iot, sc->sc_ioh, 8);
174 1.2.12.3 yamt return 0;
175 1.2.12.3 yamt }
176 1.2.12.3 yamt
177