/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Julian Coleman.
*
* 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.
*/
/* Maximum number of each type of sensor */
#define ADM1026_MAX_FANS 8
#define ADM1026_MAX_TEMPS 3
#define ADM1026_MAX_VOLTS (sizeof(adm1026_volts_table) / \
sizeof (adm1026_volts_table[0]))
static int adm1026_setup_fans(struct adm1026_softc *sc, int div2_val);
static int adm1026_setup_temps(struct adm1026_softc *sc);
static int adm1026_setup_volts(struct adm1026_softc *sc);
/*
* We could stop (suspend/detach) and restart (resume) monitoring,
* but we don't do that because some machines have separate
* management hardware which can read the sensors.
*/
bool
adm1026_pmf_suspend(device_t dev, const pmf_qual_t *qual)
{
return true;
}
for (i = 0; i < ADM1026_MAX_FANS; i++) {
sc->sc_sensor[ADM1026_FAN_NUM(i)].state = ENVSYS_SINVALID;
/* Check configuration2 register to see which pins are fans. */
if (ADM1026_PIN_IS_FAN(sc->sc_cfg[1], i)) {
sc->sc_sensor[ADM1026_FAN_NUM(i)].units =
ENVSYS_SFANRPM;
snprintf(sc->sc_sensor[ADM1026_FAN_NUM(i)].desc,
sizeof(sc->sc_sensor[ADM1026_FAN_NUM(i)].desc),
"fan %d", ADM1026_FAN_NUM(i));
if (sysmon_envsys_sensor_attach(
sc->sc_sme, &sc->sc_sensor[ADM1026_FAN_NUM(i)])) {
aprint_error_dev(sc->sc_dev,
"unable to attach fan %d at sysmon\n", i);
return 1;
}
sc->sc_nfans++;
}
}
return 0;
}
static int
adm1026_setup_temps(struct adm1026_softc *sc)
{
int i;
uint8_t val;
strlcpy(sc->sc_sensor[ADM1026_TEMP_NUM(0)].desc, "internal",
sizeof(sc->sc_sensor[ADM1026_TEMP_NUM(0)].desc));
strlcpy(sc->sc_sensor[ADM1026_TEMP_NUM(1)].desc, "external 1",
sizeof(sc->sc_sensor[ADM1026_TEMP_NUM(1)].desc));
strlcpy(sc->sc_sensor[ADM1026_TEMP_NUM(2)].desc, "external 2",
sizeof(sc->sc_sensor[ADM1026_TEMP_NUM(2)].desc));
for (i = 0; i < ADM1026_MAX_TEMPS; i++) {
/* Check configuration1 register to see if TDM2 is configured */
if (i == 2 && !ADM1026_PIN_IS_TDM2(sc->sc_cfg[0]))
continue;
sc->sc_sensor[ADM1026_TEMP_NUM(i)].units = ENVSYS_STEMP;
sc->sc_sensor[ADM1026_TEMP_NUM(i)].state = ENVSYS_SINVALID;
if (sysmon_envsys_sensor_attach(
sc->sc_sme, &sc->sc_sensor[ADM1026_TEMP_NUM(i)])) {
aprint_error_dev(sc->sc_dev,
"unable to attach temp %d at sysmon\n", i);
return 1;
}
sc->sc_ntemps++;
}
return 0;
}
static int
adm1026_setup_volts(struct adm1026_softc *sc)
{
int i;
for (i = 0; i < ADM1026_MAX_VOLTS; i++) {
/* Check configuration1 register to see if TDM2 is configured */
if (adm1026_volts_table[i].check_tdm2 &&
ADM1026_PIN_IS_TDM2(sc->sc_cfg[0]))
continue;
strlcpy(sc->sc_sensor[ADM1026_VOLT_NUM(i)].desc,
adm1026_volts_table[i].desc,
sizeof(sc->sc_sensor[ADM1026_VOLT_NUM(i)].desc));
sc->sc_sensor[ADM1026_VOLT_NUM(i)].units = ENVSYS_SVOLTS_DC;
sc->sc_sensor[ADM1026_VOLT_NUM(i)].state = ENVSYS_SINVALID;
if (sysmon_envsys_sensor_attach(
sc->sc_sme, &sc->sc_sensor[ADM1026_VOLT_NUM(i)])) {
aprint_error_dev(sc->sc_dev,
"unable to attach volts %d at sysmon\n", i);
return 1;
}
}
return 0;
}