2007-11-16 11:00:11 +03:00
|
|
|
/* $NetBSD: ug_isa.c,v 1.5 2007/11/16 08:00:15 xtraeme Exp $ */
|
2007-05-08 20:48:37 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Mihai Chelaru <kefren@netbsd.ro>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Driver for Abit uGuru (interface is inspired from it.c and nslm7x.c)
|
|
|
|
* Inspired by olle sandberg linux driver as Abit didn't care to release docs
|
|
|
|
* Support for uGuru 2005 from Louis Kruger and Hans de Goede linux driver
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2007-11-16 11:00:11 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ug_isa.c,v 1.5 2007/11/16 08:00:15 xtraeme Exp $");
|
2007-05-08 20:48:37 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/envsys.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/intr.h>
|
2007-05-08 20:48:37 +04:00
|
|
|
|
|
|
|
#include <dev/isa/isareg.h>
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
|
|
|
|
#include <dev/sysmon/sysmonvar.h>
|
|
|
|
|
|
|
|
#include <dev/ic/ugreg.h>
|
|
|
|
#include <dev/ic/ugvar.h>
|
|
|
|
|
|
|
|
/* autoconf(9) functions */
|
|
|
|
static int ug_isa_match(struct device *, struct cfdata *, void *);
|
|
|
|
static void ug_isa_attach(struct device *, struct device *, void *);
|
2007-09-09 09:39:10 +04:00
|
|
|
static int ug_isa_detach(struct device *, int);
|
2007-05-08 20:48:37 +04:00
|
|
|
|
|
|
|
CFATTACH_DECL(ug_isa, sizeof(struct ug_softc),
|
2007-09-09 09:39:10 +04:00
|
|
|
ug_isa_match, ug_isa_attach, ug_isa_detach, NULL);
|
2007-05-08 20:48:37 +04:00
|
|
|
|
|
|
|
extern uint8_t ug_ver;
|
|
|
|
|
|
|
|
static int
|
|
|
|
ug_isa_match(struct device *parent, struct cfdata *match, void *aux)
|
|
|
|
{
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
struct ug_softc wrap_sc;
|
|
|
|
bus_space_handle_t bsh;
|
|
|
|
uint8_t valc, vald;
|
|
|
|
|
|
|
|
if (ia->ia_nio < 1) /* need base addr */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ISA_DIRECT_CONFIG(ia))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &bsh))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
valc = bus_space_read_1(ia->ia_iot, bsh, UG_CMD);
|
|
|
|
vald = bus_space_read_1(ia->ia_iot, bsh, UG_DATA);
|
|
|
|
|
|
|
|
ug_ver = 0;
|
|
|
|
|
|
|
|
/* Check for uGuru 2003 */
|
|
|
|
|
|
|
|
if (((vald == 0) || (vald == 8)) && (valc == 0xAC))
|
|
|
|
ug_ver = 1;
|
|
|
|
|
|
|
|
/* Check for uGuru 2005 */
|
|
|
|
|
|
|
|
wrap_sc.sc_iot = ia->ia_iot;
|
|
|
|
wrap_sc.sc_ioh = bsh;
|
|
|
|
|
|
|
|
if (ug2_sync(&wrap_sc) == 1)
|
|
|
|
ug_ver = 2;
|
|
|
|
|
|
|
|
/* unmap, prepare ia and bye */
|
|
|
|
bus_space_unmap(ia->ia_iot, bsh, 8);
|
|
|
|
|
|
|
|
if (ug_ver != 0) {
|
|
|
|
ia->ia_nio = 1;
|
|
|
|
ia->ia_io[0].ir_size = 8;
|
|
|
|
ia->ia_niomem = 0;
|
|
|
|
ia->ia_nirq = 0;
|
|
|
|
ia->ia_ndrq = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ug_isa_attach(struct device *parent, struct device *self, void *aux)
|
|
|
|
{
|
|
|
|
struct ug_softc *sc = (void *)self;
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
|
|
|
|
8, 0, &sc->sc_ioh)) {
|
|
|
|
aprint_error(": can't map i/o space\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ia->ia_iot = sc->sc_iot;
|
|
|
|
sc->version = ug_ver;
|
|
|
|
|
|
|
|
if (sc->version == 2) {
|
|
|
|
ug2_attach(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aprint_normal(": Abit uGuru system monitor\n");
|
|
|
|
|
|
|
|
if (!ug_reset(sc))
|
|
|
|
aprint_error("%s: reset failed.\n", sc->sc_dev.dv_xname);
|
|
|
|
|
|
|
|
ug_setup_sensors(sc);
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sme = sysmon_envsys_create();
|
2007-05-08 20:48:37 +04:00
|
|
|
|
|
|
|
for (i = 0; i < UG_NUM_SENSORS; i++) {
|
2007-11-16 11:00:11 +03:00
|
|
|
if (sysmon_envsys_sensor_attach(sc->sc_sme,
|
|
|
|
&sc->sc_sensor[i])) {
|
|
|
|
sysmon_envsys_destroy(sc->sc_sme);
|
|
|
|
return;
|
|
|
|
}
|
2007-05-08 20:48:37 +04:00
|
|
|
}
|
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sme->sme_cookie = sc;
|
|
|
|
sc->sc_sme->sme_refresh = ug_refresh;
|
2007-05-08 20:48:37 +04:00
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
if (sysmon_envsys_register(sc->sc_sme)) {
|
2007-05-08 20:48:37 +04:00
|
|
|
aprint_error("%s: unable to register with sysmon\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
2007-11-16 11:00:11 +03:00
|
|
|
sysmon_envsys_destroy(sc->sc_sme);
|
|
|
|
}
|
2007-05-08 20:48:37 +04:00
|
|
|
|
|
|
|
}
|
2007-09-09 09:39:10 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
ug_isa_detach(struct device *self, int flags)
|
|
|
|
{
|
|
|
|
struct ug_softc *sc = device_private(self);
|
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
sysmon_envsys_unregister(sc->sc_sme);
|
2007-09-09 09:39:10 +04:00
|
|
|
bus_space_unmap(sc->sc_iot, sc->sc_ioh, 8);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|