NetBSD/sys/dev/pci/viapm.c

154 lines
4.1 KiB
C
Raw Normal View History

2000-05-12 20:42:41 +04:00
/* $NetBSD: viapm.c,v 1.2 2000/05/12 16:42:42 thorpej Exp $ */
2000-05-08 20:40:42 +04:00
/*
* Copyright (c) 2000 Johan Danielsson
* All rights reserved.
*
2000-05-12 20:42:41 +04:00
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
2000-05-08 20:40:42 +04:00
*
2000-05-12 20:42:41 +04:00
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
2000-05-08 20:40:42 +04:00
*
2000-05-12 20:42:41 +04:00
* 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.
2000-05-08 20:40:42 +04:00
*
* 3. Neither the name of author nor the names of any contributors may
* be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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.
*/
2000-05-12 20:42:41 +04:00
/*
* frontend for the power management device in the VIA VT82C686a South
* Bridge. It (the chip) has three functions, power management, hardware
* monitoring, and an SMBus controller. A driver for the hardware monitoring
* is provided by the viaenv driver
*/
2000-05-08 20:40:42 +04:00
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcidevs.h>
#include <dev/pci/viapmvar.h>
struct viapm_softc {
2000-05-12 20:42:41 +04:00
struct device sc_dev;
2000-05-08 20:40:42 +04:00
2000-05-12 20:42:41 +04:00
pci_chipset_tag_t sc_pc;
pcitag_t sc_tag;
bus_space_tag_t sc_iot;
2000-05-08 20:40:42 +04:00
};
static int
2000-05-12 20:42:41 +04:00
viapm_match(struct device * parent, struct cfdata * match, void *aux)
2000-05-08 20:40:42 +04:00
{
2000-05-12 20:42:41 +04:00
struct pci_attach_args *pa = aux;
if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH &&
PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_VIATECH_VT82C686A_SMB)
return 1;
return 0;
2000-05-08 20:40:42 +04:00
}
static const char *
viapm_device_name(enum vapm_devtype type)
{
2000-05-12 20:42:41 +04:00
switch (type) {
case VIAPM_POWER:
return "power management";
case VIAPM_HWMON:
return "hardware monitor";
case VIAPM_SMBUS:
return "SMBus controller";
default:
panic("viapm_device_name: unknown type");
}
2000-05-08 20:40:42 +04:00
}
static int
viapm_print(void *aux, const char *pnp)
{
2000-05-12 20:42:41 +04:00
struct viapm_attach_args *vaa = aux;
if (pnp)
printf("%s at %s", viapm_device_name(vaa->va_type), pnp);
return UNCONF;
2000-05-08 20:40:42 +04:00
}
static int
2000-05-12 20:42:41 +04:00
viapm_submatch(struct device * parent, struct cfdata * cf, void *aux)
2000-05-08 20:40:42 +04:00
{
2000-05-12 20:42:41 +04:00
return (*cf->cf_attach->ca_match) (parent, cf, aux);
2000-05-08 20:40:42 +04:00
}
static void
2000-05-12 20:42:41 +04:00
viapm_config_defer(struct device * self)
2000-05-08 20:40:42 +04:00
{
2000-05-12 20:42:41 +04:00
struct viapm_softc *sc = (struct viapm_softc *) self;
struct viapm_attach_args vaa;
vaa.va_pc = sc->sc_pc;
vaa.va_tag = sc->sc_tag;
vaa.va_iot = sc->sc_iot;
2000-05-08 20:40:42 +04:00
#if 0
2000-05-12 20:42:41 +04:00
/*
* no point in confusing people with these until there are drivers for
* them
*/
vaa.va_type = VIAPM_POWER;
vaa.va_offset = 0x40;
config_found_sm(self, &vaa, viapm_print, viapm_submatch);
2000-05-08 20:40:42 +04:00
#endif
2000-05-12 20:42:41 +04:00
vaa.va_type = VIAPM_HWMON;
vaa.va_offset = 0x70;
config_found_sm(self, &vaa, viapm_print, viapm_submatch);
2000-05-08 20:40:42 +04:00
#if 0
2000-05-12 20:42:41 +04:00
vaa.va_type = VIAPM_SMBUS;
vaa.va_offset = 0x93;
config_found_sm(self, &vaa, viapm_print, viapm_submatch);
2000-05-08 20:40:42 +04:00
#endif
}
static void
2000-05-12 20:42:41 +04:00
viapm_attach(struct device * parent, struct device * self, void *aux)
2000-05-08 20:40:42 +04:00
{
2000-05-12 20:42:41 +04:00
struct viapm_softc *sc = (struct viapm_softc *) self;
struct pci_attach_args *pa = aux;
2000-05-08 20:40:42 +04:00
2000-05-12 20:42:41 +04:00
printf("\n");
2000-05-08 20:40:42 +04:00
2000-05-12 20:42:41 +04:00
sc->sc_pc = pa->pa_pc;
sc->sc_tag = pa->pa_tag;
sc->sc_iot = pa->pa_iot;
2000-05-08 20:40:42 +04:00
2000-05-12 20:42:41 +04:00
config_defer(self, viapm_config_defer);
2000-05-08 20:40:42 +04:00
}
struct cfattach viapm_ca = {
2000-05-12 20:42:41 +04:00
sizeof(struct viapm_softc), viapm_match, viapm_attach
2000-05-08 20:40:42 +04:00
};