1 /* $NetBSD: ug_isa.c,v 1.7 2008/04/04 09:30:55 xtraeme Exp $ */ 2 3 /* 4 * Copyright (c) 2007 Mihai Chelaru <kefren@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.7 2008/04/04 09:30:55 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 <sys/bus.h> 49 #include <sys/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(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); 63 64 CFATTACH_DECL_NEW(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(device_t parent, cfdata_t 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(device_t parent, device_t self, void *aux) 125 { 126 struct ug_softc *sc = device_private(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(self); 141 return; 142 } 143 144 aprint_normal(": Abit uGuru system monitor\n"); 145 146 if (!ug_reset(sc)) 147 aprint_error_dev(self, "reset failed.\n"); 148 149 ug_setup_sensors(sc); 150 sc->sc_sme = sysmon_envsys_create(); 151 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); 156 goto out; 157 } 158 } 159 160 sc->sc_sme->sme_cookie = sc; 161 sc->sc_sme->sme_refresh = ug_refresh; 162 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); 166 goto out; 167 } 168 169 return; 170 171 out: 172 bus_space_unmap(sc->sc_iot, sc->sc_ioh, 8); 173 174 } 175 176 static int 177 ug_isa_detach(device_t self, int flags) 178 { 179 struct ug_softc *sc = device_private(self); 180 181 sysmon_envsys_unregister(sc->sc_sme); 182 bus_space_unmap(sc->sc_iot, sc->sc_ioh, 8); 183 return 0; 184 } 185 186