Home | History | Annotate | Line # | Download | only in isa
ug_isa.c revision 1.2
      1 /* $NetBSD: ug_isa.c,v 1.2 2007/07/01 07:37:20 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.2 2007/07/01 07:37:20 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 
     63 CFATTACH_DECL(ug_isa, sizeof(struct ug_softc),
     64     ug_isa_match, ug_isa_attach, NULL, NULL);
     65 
     66 extern uint8_t ug_ver;
     67 
     68 static int
     69 ug_isa_match(struct device *parent, struct cfdata *match, void *aux)
     70 {
     71 	struct isa_attach_args *ia = aux;
     72 	struct ug_softc wrap_sc;
     73 	bus_space_handle_t bsh;
     74 	uint8_t valc, vald;
     75 
     76 	if (ia->ia_nio < 1)     /* need base addr */
     77 		return 0;
     78 
     79 	if (ISA_DIRECT_CONFIG(ia))
     80 		return 0;
     81 
     82 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
     83 		return 0;
     84 
     85 	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &bsh))
     86 		return 0;
     87 
     88 	valc = bus_space_read_1(ia->ia_iot, bsh, UG_CMD);
     89 	vald = bus_space_read_1(ia->ia_iot, bsh, UG_DATA);
     90 
     91 	ug_ver = 0;
     92 
     93 	/* Check for uGuru 2003 */
     94 
     95 	if (((vald == 0) || (vald == 8)) && (valc == 0xAC))
     96 		ug_ver = 1;
     97 
     98 	/* Check for uGuru 2005 */
     99 
    100 	wrap_sc.sc_iot = ia->ia_iot;
    101 	wrap_sc.sc_ioh = bsh;
    102 
    103 	if (ug2_sync(&wrap_sc) == 1)
    104 		ug_ver = 2;
    105 
    106 	/* unmap, prepare ia and bye */
    107 	bus_space_unmap(ia->ia_iot, bsh, 8);
    108 
    109 	if (ug_ver != 0) {
    110 		ia->ia_nio = 1;
    111 		ia->ia_io[0].ir_size = 8;
    112 		ia->ia_niomem = 0;
    113 		ia->ia_nirq = 0;
    114 		ia->ia_ndrq = 0;
    115 		return 1;
    116 	}
    117 
    118 	return 0;
    119 
    120 }
    121 
    122 static void
    123 ug_isa_attach(struct device *parent, struct device *self, void *aux)
    124 {
    125 	struct ug_softc *sc = (void *)self;
    126 	struct isa_attach_args *ia = aux;
    127 	int i;
    128 
    129 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
    130 	    8, 0, &sc->sc_ioh)) {
    131 		aprint_error(": can't map i/o space\n");
    132 		return;
    133 	}
    134 
    135 	ia->ia_iot = sc->sc_iot;
    136 	sc->version = ug_ver;
    137 
    138 	if (sc->version == 2) {
    139 		ug2_attach(sc);
    140 		return;
    141 	}
    142 
    143 	aprint_normal(": Abit uGuru system monitor\n");
    144 
    145 	if (!ug_reset(sc))
    146 		aprint_error("%s: reset failed.\n", sc->sc_dev.dv_xname);
    147 
    148 	ug_setup_sensors(sc);
    149 
    150 	for (i = 0; i < UG_NUM_SENSORS; i++) {
    151 		sc->sc_data[i].sensor = i;
    152 		sc->sc_data[i].state = ENVSYS_SVALID;
    153 	}
    154 
    155 	sc->sc_sysmon.sme_sensor_data = sc->sc_data;
    156 	sc->sc_sysmon.sme_cookie = sc;
    157 	sc->sc_sysmon.sme_gtredata = ug_gtredata;
    158 	sc->sc_sysmon.sme_nsensors = UG_NUM_SENSORS;
    159 
    160 	if (sysmon_envsys_register(&sc->sc_sysmon))
    161 		aprint_error("%s: unable to register with sysmon\n",
    162 		    sc->sc_dev.dv_xname);
    163 
    164 }
    165