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