/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Brett Lymn.
*
* 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 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.
*/
/*
* This is a driver for the Standard Microsystems Corp (SMSC)
* LPC47B397 "super i/o" chip. This driver only handles the environment
* monitoring capabilities of the chip, the other functions will be
* probed/matched as "normal" PC hardware devices (serial ports, fdc, so on).
* SMSC has not deigned to release a datasheet for this particular chip
* (though they do for others they make) so this driver was written from
* information contained in the comment block for the Linux driver.
*/
/*
* Get the base address for the monitoring registers and set up the
* sysmon_envsys(9) framework.
*/
static void
smsc_attach(device_t parent, device_t self, void *aux)
{
struct smsc_softc *sc = device_private(self);
struct isa_attach_args *ia = aux;
bus_space_handle_t ioh;
uint8_t rev, msb, lsb, chipid;
unsigned address;
int i;
sc->sc_iot = ia->ia_iot;
aprint_naive("\n");
/*
* To attach we need to find the actual Hardware Monitor
* I/O address space.
*/
if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 2, 0,
&ioh)) {
aprint_error(": can't map base i/o space\n");
return;
}
/* Enter config mode */
bus_space_write_1(ia->ia_iot, ioh, SMSC_ADDR, SMSC_CONFIG_START);
/*
* While we have the base registers mapped, grab the chip
* revision and device ID.
*/
rev = smsc_readreg(ia->ia_iot, ioh, SMSC_DEVICE_REVISION);
chipid = smsc_readreg(ia->ia_iot, ioh, SMSC_DEVICE_ID);
if ((i = sysmon_envsys_register(sc->sc_sme)) != 0) {
aprint_error(": unable to register with sysmon (%d)\n", i);
sysmon_envsys_destroy(sc->sc_sme);
sc->sc_sme = NULL;
bus_space_unmap(sc->sc_iot, sc->sc_ioh, 2);
return;
}
switch (chipid) {
case SMSC_ID_47B397:
aprint_normal(": SMSC LPC47B397 Super I/O");
break;
case SMSC_ID_SCH5307NS:
aprint_normal(": SMSC SCH5307-NS Super I/O");
break;
case SMSC_ID_SCH5317:
aprint_normal(": SMSC SCH5317 Super I/O");
break;
}
/*
* Read the value of the given register
*/
static uint8_t
smsc_readreg(bus_space_tag_t iot, bus_space_handle_t ioh, int reg)
{
bus_space_write_1(iot, ioh, SMSC_ADDR, reg);
return bus_space_read_1(iot, ioh, SMSC_DATA);
}
/*
* Write the given value to the given register.
*/
static void
smsc_writereg(bus_space_tag_t iot, bus_space_handle_t ioh, int reg, int val)
{
bus_space_write_1(iot, ioh, SMSC_ADDR, reg);
bus_space_write_1(iot, ioh, SMSC_DATA, val);
}
/* convert temperature read from the chip to micro kelvin */
static inline int
smsc_temp2muk(uint8_t t)
{
int temp=t;
return temp * 1000000 + 273150000U;
}
/*
* convert register value read from chip into rpm using:
*
* RPM = 60/(Count * 11.111us)
*
* 1/1.1111us = 90kHz
*
*/
static inline int
smsc_reg2rpm(unsigned int r)
{
unsigned long rpm;
/* min and max temperatures in uK */
#define SMSC_MIN_TEMP_UK ((-127 * 1000000) + 273150000)
#define SMSC_MAX_TEMP_UK ((127 * 1000000) + 273150000)
/*
* Get the data for the requested sensor, update the sysmon structure
* with the retrieved value.
*/
static void
smsc_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
{
struct smsc_softc *sc = sme->sme_cookie;
int reg;
unsigned int rpm;
uint8_t msb, lsb;