ug_isa.c revision 1.1.2.3 1 1.1.2.3 pavel /* $NetBSD: ug_isa.c,v 1.1.2.3 2007/05/13 22:13:28 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.3 pavel __KERNEL_RCSID(0, "$NetBSD: ug_isa.c,v 1.1.2.3 2007/05/13 22:13:28 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