NetBSD/sys/arch/i386/pnpbios/lm_pnpbios.c
ad 5a728ace12 Changes for SMBus/I2C:
- Move lm_readreg/lm_writereg into the front-ends. Add/use function pointers
  in the softc.
- Add a bank select function pointer to the softc and provide a generic
  version. WinBond chips accessed over serial bus present three addresses,
  two of which are used to access bank 1/2 registers.
- Mark TSENS2/3 sensor data as invalid if the the corresponding bank select
  fails.
2002-11-15 14:55:41 +00:00

184 lines
4.9 KiB
C

/* $NetBSD: lm_pnpbios.c,v 1.8 2002/11/15 14:55:45 ad Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Bill Squier.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lm_pnpbios.c,v 1.8 2002/11/15 14:55:45 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/syslog.h>
#include <sys/device.h>
#include <sys/proc.h>
#include <machine/bus.h>
#include <dev/isa/isavar.h>
#include <dev/isa/isadmavar.h>
#include <i386/pnpbios/pnpbiosvar.h>
#include <dev/sysmon/sysmonvar.h>
#include <dev/ic/nslm7xvar.h>
int lm_pnpbios_match __P((struct device *, struct cfdata *, void *));
void lm_pnpbios_attach __P((struct device *, struct device *, void *));
int lm_pnpbios_hints_index __P((const char *));
u_int8_t lm_pnpbios_readreg(struct lm_softc *, int);
void lm_pnpbios_writereg(struct lm_softc *, int, int);
CFATTACH_DECL(lm_pnpbios, sizeof(struct lm_softc),
lm_pnpbios_match, lm_pnpbios_attach, NULL, NULL);
/*
* XXX - no known pnpbios ids for lm series chips.
*/
struct lm_pnpbios_hint {
char idstr[8];
int io_region_idx_lm7x;
};
/*
* Currently no known valid pnpbios id's - PNP0C02 is
* for reserved motherboard resources, probing it is bad.
*/
struct lm_pnpbios_hint lm_pnpbios_hints[] = {
{ { 0 }, 0 }
};
int
lm_pnpbios_hints_index(idstr)
const char *idstr;
{
int idx = 0;
while (lm_pnpbios_hints[idx].idstr[0] != 0) {
if (!strcmp(lm_pnpbios_hints[idx].idstr, idstr))
return idx;
++idx;
}
return -1;
}
int
lm_pnpbios_match(parent, match, aux)
struct device *parent;
struct cfdata *match;
void *aux;
{
struct pnpbiosdev_attach_args *aa = aux;
struct lm_pnpbios_hint *wph;
bus_space_tag_t iot;
bus_space_handle_t ioh;
int rv;
int wphi;
if ((wphi = lm_pnpbios_hints_index(aa->idstr)) == -1)
return (0);
wph = &lm_pnpbios_hints[wphi];
if (pnpbios_io_map(aa->pbt, aa->resc, wph->io_region_idx_lm7x,
&iot, &ioh)) {
return (0);
}
rv = lm_probe(iot, ioh);
pnpbios_io_unmap(aa->pbt, aa->resc, wph->io_region_idx_lm7x,
iot, ioh);
return (rv);
}
void
lm_pnpbios_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct lm_softc *sc = (void *)self;
struct pnpbiosdev_attach_args *aa = aux;
struct lm_pnpbios_hint *wph;
wph = &lm_pnpbios_hints[lm_pnpbios_hints_index(aa->idstr)];
if (pnpbios_io_map(aa->pbt, aa->resc, wph->io_region_idx_lm7x,
&sc->lm_iot, &sc->lm_ioh)) {
printf(": can't map i/o space\n");
return;
}
printf("\n");
pnpbios_print_devres(self, aa);
printf("%s", self->dv_xname);
/* Bus-independant attach */
sc->lm_writereg = lm_pnpbios_writereg;
sc->lm_readreg = lm_pnpbios_readreg;
lm_attach(sc);
}
u_int8_t
lm_pnpbios_readreg(sc, reg)
struct lm_softc *sc;
int reg;
{
bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
return (bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA));
}
void
lm_pnpbios_writereg(sc, reg, val)
struct lm_softc *sc;
int reg;
int val;
{
bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);
}