Home | History | Annotate | Line # | Download | only in isa
ug_isa.c revision 1.2.10.2
      1  1.2.10.2     matt /* $NetBSD: ug_isa.c,v 1.2.10.2 2008/01/09 01:53:15 matt 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.2.10.2     matt __KERNEL_RCSID(0, "$NetBSD: ug_isa.c,v 1.2.10.2 2008/01/09 01:53:15 matt 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/malloc.h>
     43       1.1  xtraeme #include <sys/errno.h>
     44       1.1  xtraeme #include <sys/conf.h>
     45       1.1  xtraeme #include <sys/envsys.h>
     46       1.1  xtraeme #include <sys/time.h>
     47       1.1  xtraeme 
     48  1.2.10.1     matt #include <sys/bus.h>
     49  1.2.10.1     matt #include <sys/intr.h>
     50       1.1  xtraeme 
     51       1.1  xtraeme #include <dev/isa/isareg.h>
     52       1.1  xtraeme #include <dev/isa/isavar.h>
     53       1.1  xtraeme 
     54       1.1  xtraeme #include <dev/sysmon/sysmonvar.h>
     55       1.1  xtraeme 
     56       1.1  xtraeme #include <dev/ic/ugreg.h>
     57       1.1  xtraeme #include <dev/ic/ugvar.h>
     58       1.1  xtraeme 
     59       1.1  xtraeme /* autoconf(9) functions */
     60       1.1  xtraeme static int  ug_isa_match(struct device *, struct cfdata *, void *);
     61       1.1  xtraeme static void ug_isa_attach(struct device *, struct device *, void *);
     62  1.2.10.1     matt static int  ug_isa_detach(struct device *, int);
     63       1.1  xtraeme 
     64       1.1  xtraeme CFATTACH_DECL(ug_isa, sizeof(struct ug_softc),
     65  1.2.10.1     matt     ug_isa_match, ug_isa_attach, ug_isa_detach, NULL);
     66       1.1  xtraeme 
     67       1.1  xtraeme extern uint8_t ug_ver;
     68       1.1  xtraeme 
     69       1.1  xtraeme static int
     70       1.1  xtraeme ug_isa_match(struct device *parent, struct cfdata *match, void *aux)
     71       1.1  xtraeme {
     72       1.1  xtraeme 	struct isa_attach_args *ia = aux;
     73       1.1  xtraeme 	struct ug_softc wrap_sc;
     74       1.1  xtraeme 	bus_space_handle_t bsh;
     75       1.1  xtraeme 	uint8_t valc, vald;
     76       1.1  xtraeme 
     77       1.1  xtraeme 	if (ia->ia_nio < 1)     /* need base addr */
     78       1.1  xtraeme 		return 0;
     79       1.1  xtraeme 
     80       1.1  xtraeme 	if (ISA_DIRECT_CONFIG(ia))
     81       1.1  xtraeme 		return 0;
     82       1.1  xtraeme 
     83       1.1  xtraeme 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
     84       1.1  xtraeme 		return 0;
     85       1.1  xtraeme 
     86       1.1  xtraeme 	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &bsh))
     87       1.1  xtraeme 		return 0;
     88       1.1  xtraeme 
     89       1.1  xtraeme 	valc = bus_space_read_1(ia->ia_iot, bsh, UG_CMD);
     90       1.1  xtraeme 	vald = bus_space_read_1(ia->ia_iot, bsh, UG_DATA);
     91       1.1  xtraeme 
     92       1.1  xtraeme 	ug_ver = 0;
     93       1.1  xtraeme 
     94       1.1  xtraeme 	/* Check for uGuru 2003 */
     95       1.1  xtraeme 
     96       1.1  xtraeme 	if (((vald == 0) || (vald == 8)) && (valc == 0xAC))
     97       1.1  xtraeme 		ug_ver = 1;
     98       1.1  xtraeme 
     99       1.1  xtraeme 	/* Check for uGuru 2005 */
    100       1.1  xtraeme 
    101       1.1  xtraeme 	wrap_sc.sc_iot = ia->ia_iot;
    102       1.1  xtraeme 	wrap_sc.sc_ioh = bsh;
    103       1.1  xtraeme 
    104       1.1  xtraeme 	if (ug2_sync(&wrap_sc) == 1)
    105       1.1  xtraeme 		ug_ver = 2;
    106       1.1  xtraeme 
    107       1.1  xtraeme 	/* unmap, prepare ia and bye */
    108       1.1  xtraeme 	bus_space_unmap(ia->ia_iot, bsh, 8);
    109       1.1  xtraeme 
    110       1.1  xtraeme 	if (ug_ver != 0) {
    111       1.1  xtraeme 		ia->ia_nio = 1;
    112       1.1  xtraeme 		ia->ia_io[0].ir_size = 8;
    113       1.1  xtraeme 		ia->ia_niomem = 0;
    114       1.1  xtraeme 		ia->ia_nirq = 0;
    115       1.1  xtraeme 		ia->ia_ndrq = 0;
    116       1.1  xtraeme 		return 1;
    117       1.1  xtraeme 	}
    118       1.1  xtraeme 
    119       1.1  xtraeme 	return 0;
    120       1.1  xtraeme 
    121       1.1  xtraeme }
    122       1.1  xtraeme 
    123       1.1  xtraeme static void
    124       1.1  xtraeme ug_isa_attach(struct device *parent, struct device *self, void *aux)
    125       1.1  xtraeme {
    126       1.1  xtraeme 	struct ug_softc *sc = (void *)self;
    127       1.1  xtraeme 	struct isa_attach_args *ia = aux;
    128       1.1  xtraeme 	int i;
    129       1.1  xtraeme 
    130       1.1  xtraeme 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
    131       1.1  xtraeme 	    8, 0, &sc->sc_ioh)) {
    132       1.1  xtraeme 		aprint_error(": can't map i/o space\n");
    133       1.1  xtraeme 		return;
    134       1.1  xtraeme 	}
    135       1.1  xtraeme 
    136       1.1  xtraeme 	ia->ia_iot = sc->sc_iot;
    137       1.1  xtraeme 	sc->version = ug_ver;
    138       1.1  xtraeme 
    139       1.1  xtraeme 	if (sc->version == 2) {
    140       1.1  xtraeme 		ug2_attach(sc);
    141       1.1  xtraeme 		return;
    142       1.1  xtraeme 	}
    143       1.1  xtraeme 
    144       1.1  xtraeme 	aprint_normal(": Abit uGuru system monitor\n");
    145       1.1  xtraeme 
    146       1.1  xtraeme 	if (!ug_reset(sc))
    147       1.1  xtraeme 		aprint_error("%s: reset failed.\n", sc->sc_dev.dv_xname);
    148       1.1  xtraeme 
    149       1.1  xtraeme 	ug_setup_sensors(sc);
    150  1.2.10.2     matt 	sc->sc_sme = sysmon_envsys_create();
    151       1.1  xtraeme 
    152       1.1  xtraeme 	for (i = 0; i < UG_NUM_SENSORS; i++) {
    153  1.2.10.2     matt 		if (sysmon_envsys_sensor_attach(sc->sc_sme,
    154  1.2.10.2     matt 						&sc->sc_sensor[i])) {
    155  1.2.10.2     matt 			sysmon_envsys_destroy(sc->sc_sme);
    156  1.2.10.2     matt 			return;
    157  1.2.10.2     matt 		}
    158       1.1  xtraeme 	}
    159       1.1  xtraeme 
    160  1.2.10.2     matt 	sc->sc_sme->sme_cookie = sc;
    161  1.2.10.2     matt 	sc->sc_sme->sme_refresh = ug_refresh;
    162       1.1  xtraeme 
    163  1.2.10.2     matt 	if (sysmon_envsys_register(sc->sc_sme)) {
    164       1.1  xtraeme 		aprint_error("%s: unable to register with sysmon\n",
    165       1.1  xtraeme 		    sc->sc_dev.dv_xname);
    166  1.2.10.2     matt 		sysmon_envsys_destroy(sc->sc_sme);
    167  1.2.10.2     matt 	}
    168       1.1  xtraeme 
    169       1.1  xtraeme }
    170  1.2.10.1     matt 
    171  1.2.10.1     matt static int
    172  1.2.10.1     matt ug_isa_detach(struct device *self, int flags)
    173  1.2.10.1     matt {
    174  1.2.10.1     matt 	struct ug_softc *sc = device_private(self);
    175  1.2.10.1     matt 
    176  1.2.10.2     matt 	sysmon_envsys_unregister(sc->sc_sme);
    177  1.2.10.1     matt 	bus_space_unmap(sc->sc_iot, sc->sc_ioh, 8);
    178  1.2.10.1     matt 	return 0;
    179  1.2.10.1     matt }
    180  1.2.10.1     matt 
    181