2021-01-25 16:30:20 +03:00
|
|
|
/* $NetBSD: adm1021.c,v 1.24 2021/01/25 13:30:20 thorpej Exp $ */
|
2008-10-29 20:26:56 +03:00
|
|
|
/* $OpenBSD: adm1021.c,v 1.27 2007/06/24 05:34:35 dlg Exp $ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 Theo de Raadt
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-01-03 20:27:26 +03:00
|
|
|
/*
|
|
|
|
* Driver for ADM1021 and compatible temperature sensors, including ADM1021,
|
|
|
|
* ADM1021A, ADM1023, ADM1032, GL523SM, G781, LM84, MAX1617, MAX1617A,
|
2017-09-01 23:11:59 +03:00
|
|
|
* NE1617A, MAX6642 and Xeon embedded temperature sensors.
|
2016-01-03 20:27:26 +03:00
|
|
|
*
|
|
|
|
* Some sensors differ from the ADM1021/MAX1617/NE1617A:
|
2017-09-01 23:11:59 +03:00
|
|
|
* ADM1021A ADM1023 ADM1032 G781 LM84 MAX1617A MAX6642
|
|
|
|
* company/revision reg X X X X X X
|
|
|
|
* no negative temps X X X X
|
|
|
|
* 11-bit remote temp X X X X
|
2017-09-14 00:15:11 +03:00
|
|
|
* no low limits X X
|
2017-09-01 23:11:59 +03:00
|
|
|
* therm (high) limits X X X
|
2016-01-03 20:27:26 +03:00
|
|
|
*
|
|
|
|
* Registers 0x00 to 0x0f have separate read/write addresses, but
|
|
|
|
* registers 0x10 and above have the same read/write address.
|
|
|
|
* The 11-bit (extended) temperature consists of a separate register with
|
|
|
|
* 3 valid bits that are always added to the external temperature (even if
|
|
|
|
* the temperature is negative).
|
|
|
|
*/
|
|
|
|
|
2008-10-29 20:26:56 +03:00
|
|
|
#include <sys/cdefs.h>
|
2021-01-25 16:30:20 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.24 2021/01/25 13:30:20 thorpej Exp $");
|
2008-10-29 20:26:56 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <dev/sysmon/sysmonvar.h>
|
|
|
|
|
|
|
|
#include <dev/i2c/i2cvar.h>
|
|
|
|
|
2016-01-03 20:27:26 +03:00
|
|
|
/* Registers */
|
|
|
|
#define ADM1021_INT_TEMP 0x00 /* Internal temperature value */
|
|
|
|
#define ADM1021_EXT_TEMP 0x01 /* External temperature value */
|
|
|
|
#define ADM1021_STATUS 0x02 /* Status */
|
|
|
|
#define ADM1021_CONFIG_READ 0x03 /* Read configuration */
|
|
|
|
#define ADM1021_CONV_RATE_READ 0x04 /* Read conversion rate */
|
|
|
|
#define ADM1021_INT_HIGH_READ 0x05 /* Read internal high limit */
|
|
|
|
#define ADM1021_INT_LOW_READ 0x06 /* Read internal low limit */
|
|
|
|
#define ADM1021_EXT_HIGH_READ 0x07 /* Read external high limit */
|
|
|
|
#define ADM1021_EXT_LOW_READ 0x08 /* Read external low limit */
|
|
|
|
#define ADM1021_CONFIG_WRITE 0x09 /* Write configuration */
|
|
|
|
#define ADM1021_CONV_RATE_WRITE 0x0a /* Write conversion rate */
|
|
|
|
#define ADM1021_INT_HIGH_WRITE 0x0b /* Write internal high limit */
|
|
|
|
#define ADM1021_INT_LOW_WRITE 0x0c /* Write internal low limit */
|
|
|
|
#define ADM1021_EXT_HIGH_WRITE 0x0d /* Write external high limit */
|
|
|
|
#define ADM1021_EXT_LOW_WRITE 0x0e /* Write external low limit */
|
|
|
|
#define ADM1021_ONE_SHOT 0x0f /* One shot command */
|
|
|
|
#define ADM1023_EXT_TEMP2 0x10 /* R/W external temp low byte */
|
|
|
|
#define ADM1023_EXT_TEMP_OFF 0x11 /* R/W external temp offset */
|
|
|
|
#define ADM1023_EXT_TEMP_OFF2 0x12 /* R/W external temp off low byte */
|
|
|
|
#define ADM1023_EXT_HIGH2 0x13 /* R/W external high lim low byte */
|
|
|
|
#define ADM1023_EXT_LOW2 0x14 /* R/W external low lim low byte */
|
|
|
|
#define ADM1032_EXT_THERM 0x19 /* R/W external Therm (high) limit */
|
|
|
|
#define ADM1032_INT_THERM 0x20 /* R/W internal Therm (high) limit */
|
|
|
|
#define ADM1032_THERM_HYST 0x21 /* R/W Therm hysteris */
|
|
|
|
#define ADM1032_ALERT_QUEUE 0x22 /* R/W consecutive alert queue */
|
|
|
|
#define ADM1021_COMPANY 0xfe /* Company ID */
|
|
|
|
#define ADM1021_DIE_REVISION 0xff /* Die revision code */
|
2008-10-29 20:26:56 +03:00
|
|
|
|
2016-01-03 20:27:26 +03:00
|
|
|
/* Register values */
|
2008-10-29 20:26:56 +03:00
|
|
|
#define ADM1021_CONFIG_RUN 0x40
|
2016-01-03 20:27:26 +03:00
|
|
|
|
|
|
|
#define ADM1021_STATUS_INVAL 0x7f
|
|
|
|
#define ADM1021_STATUS_NOEXT 0x40 /* External diode is open-circuit */
|
|
|
|
|
|
|
|
#define ADM1023_EXT2_SHIFT 5
|
|
|
|
#define ADM1023_EXT2_MASK 0x07
|
|
|
|
|
|
|
|
#define ADM1021_COMPANY_ADM 0x41 /* 'A' */
|
|
|
|
#define ADM1021_COMPANY_GMT 0x47 /* 'G' */
|
|
|
|
#define ADM1021_COMPANY_MAXIM 0x4d /* 'M' */
|
|
|
|
|
|
|
|
#define ADM1021_REV_1021 0x00
|
|
|
|
#define ADM1021_REV_1021A 0x30
|
|
|
|
#define ADM1021_REV_MASK 0xf0
|
2008-10-29 20:26:56 +03:00
|
|
|
|
|
|
|
/* Sensors */
|
|
|
|
#define ADMTEMP_INT 0
|
|
|
|
#define ADMTEMP_EXT 1
|
|
|
|
#define ADMTEMP_NUM_SENSORS 2
|
|
|
|
|
2016-01-03 20:27:26 +03:00
|
|
|
#define ADMTEMP_MAX_NEG -65
|
|
|
|
#define ADMTEMP_MAX_POS 127
|
|
|
|
#define ADMTEMP_LOW_DEFAULT 0xc9 /* (-55) */
|
|
|
|
|
|
|
|
/* Limit registers might read 0xff, so we ignore them if they do */
|
|
|
|
#define ADMTEMP_LIM_INVAL -1 /* 0xff */
|
|
|
|
|
|
|
|
#define ADMTEMP_NAMELEN 9 /* Maximum name length + 1 */
|
|
|
|
|
2008-10-29 20:26:56 +03:00
|
|
|
struct admtemp_softc {
|
|
|
|
i2c_tag_t sc_tag;
|
|
|
|
i2c_addr_t sc_addr;
|
2020-08-21 23:44:38 +03:00
|
|
|
prop_dictionary_t sc_prop;
|
2008-10-29 20:26:56 +03:00
|
|
|
|
2016-01-03 20:27:26 +03:00
|
|
|
int sc_flags;
|
|
|
|
int sc_noexternal, sc_noneg, sc_nolow;
|
|
|
|
int sc_ext11, sc_therm;
|
2008-10-29 20:26:56 +03:00
|
|
|
struct sysmon_envsys *sc_sme;
|
|
|
|
envsys_data_t sc_sensor[ADMTEMP_NUM_SENSORS];
|
2016-01-03 20:27:26 +03:00
|
|
|
int sc_setdef[ADMTEMP_NUM_SENSORS];
|
2016-01-04 22:24:15 +03:00
|
|
|
uint8_t sc_highlim[ADMTEMP_NUM_SENSORS];
|
|
|
|
uint8_t sc_lowlim[ADMTEMP_NUM_SENSORS];
|
|
|
|
uint8_t sc_highlim2, sc_lowlim2;
|
|
|
|
uint8_t sc_thermlim[ADMTEMP_NUM_SENSORS];
|
2008-10-29 20:26:56 +03:00
|
|
|
};
|
|
|
|
|
2009-05-12 18:16:35 +04:00
|
|
|
int admtemp_match(device_t, cfdata_t, void *);
|
|
|
|
void admtemp_attach(device_t, device_t, void *);
|
2008-10-29 20:26:56 +03:00
|
|
|
void admtemp_refresh(struct sysmon_envsys *, envsys_data_t *);
|
2016-01-03 20:27:26 +03:00
|
|
|
void admtemp_getlim_1021(struct sysmon_envsys *, envsys_data_t *,
|
|
|
|
sysmon_envsys_lim_t *, uint32_t *);
|
|
|
|
void admtemp_getlim_1023(struct sysmon_envsys *, envsys_data_t *,
|
|
|
|
sysmon_envsys_lim_t *, uint32_t *);
|
|
|
|
void admtemp_getlim_1032(struct sysmon_envsys *, envsys_data_t *,
|
|
|
|
sysmon_envsys_lim_t *, uint32_t *);
|
|
|
|
void admtemp_setlim_1021(struct sysmon_envsys *, envsys_data_t *,
|
|
|
|
sysmon_envsys_lim_t *, uint32_t *);
|
|
|
|
void admtemp_setlim_1023(struct sysmon_envsys *, envsys_data_t *,
|
|
|
|
sysmon_envsys_lim_t *, uint32_t *);
|
|
|
|
void admtemp_setlim_1032(struct sysmon_envsys *, envsys_data_t *,
|
|
|
|
sysmon_envsys_lim_t *, uint32_t *);
|
2008-10-29 20:26:56 +03:00
|
|
|
|
|
|
|
CFATTACH_DECL_NEW(admtemp, sizeof(struct admtemp_softc),
|
|
|
|
admtemp_match, admtemp_attach, NULL, NULL);
|
|
|
|
|
2016-01-03 20:27:26 +03:00
|
|
|
/* XXX: add flags for compats to admtemp_setflags() */
|
2018-06-26 09:03:57 +03:00
|
|
|
static const struct device_compatible_entry compat_data[] = {
|
2021-01-18 00:42:35 +03:00
|
|
|
{ .compat = "i2c-max1617" },
|
|
|
|
{ .compat = "max6642" },
|
|
|
|
{ .compat = "max6690" },
|
2021-01-25 16:30:20 +03:00
|
|
|
{ }
|
2018-06-18 20:07:07 +03:00
|
|
|
};
|
|
|
|
|
2008-10-29 20:26:56 +03:00
|
|
|
int
|
2009-05-12 18:16:35 +04:00
|
|
|
admtemp_match(device_t parent, cfdata_t match, void *aux)
|
2008-10-29 20:26:56 +03:00
|
|
|
{
|
|
|
|
struct i2c_attach_args *ia = aux;
|
2018-06-17 00:22:13 +03:00
|
|
|
int match_result;
|
|
|
|
|
2018-06-26 09:03:57 +03:00
|
|
|
if (iic_use_direct_match(ia, match, compat_data, &match_result))
|
2018-06-17 00:22:13 +03:00
|
|
|
return match_result;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Indirect config - not much we can do!
|
|
|
|
* Check typical addresses.
|
|
|
|
*/
|
|
|
|
if (((ia->ia_addr >= 0x18) && (ia->ia_addr <= 0x1a)) ||
|
|
|
|
((ia->ia_addr >= 0x29) && (ia->ia_addr <= 0x2b)) ||
|
|
|
|
((ia->ia_addr >= 0x48) && (ia->ia_addr <= 0x4e)))
|
|
|
|
return I2C_MATCH_ADDRESS_ONLY;
|
2010-02-28 14:36:27 +03:00
|
|
|
|
|
|
|
return 0;
|
2008-10-29 20:26:56 +03:00
|
|
|
}
|
|
|
|
|
2016-01-04 22:24:15 +03:00
|
|
|
static int
|
|
|
|
admtemp_exec(struct admtemp_softc *sc, i2c_op_t op, uint8_t *cmd,
|
|
|
|
uint8_t *data)
|
|
|
|
{
|
|
|
|
return iic_exec(sc->sc_tag, op, sc->sc_addr, cmd, sizeof(*cmd), data,
|
|
|
|
sizeof(*data), 0);
|
|
|
|
}
|
|
|
|
|
2016-01-03 20:27:26 +03:00
|
|
|
/*
|
|
|
|
* Set flags based on chip type for direct config, or by testing for
|
|
|
|
* indirect config.
|
|
|
|
*
|
|
|
|
* LM84, MAX1617, and NE1617A don't have company/revision registers.
|
|
|
|
* If we can't read the company register, we'll check the
|
|
|
|
* internal low limit to see if we have an LM84.
|
|
|
|
*
|
|
|
|
* To check if an ADM chip has 11-bit sensors, we'll write 0.125
|
|
|
|
* to the external temperature limit low byte register and read it
|
|
|
|
* back (because we can't tell from the id/rev).
|
|
|
|
*
|
|
|
|
* To check if an ADM chip has a Therm output, we check that we
|
|
|
|
* read 0x55 (default value) from the external therm limit.
|
|
|
|
*
|
|
|
|
* If an ADM chip doesn't have 11-bit sensors, check the revision to
|
|
|
|
* determine if it handles negative temperatures.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
admtemp_setflags(struct admtemp_softc *sc, struct i2c_attach_args *ia,
|
2016-01-04 22:24:15 +03:00
|
|
|
uint8_t* comp, uint8_t *rev, char* name)
|
2016-01-03 20:27:26 +03:00
|
|
|
{
|
2016-01-04 22:24:15 +03:00
|
|
|
uint8_t cmd, data, tmp;
|
2016-01-03 20:27:26 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
*comp = 0;
|
|
|
|
*rev = 0;
|
|
|
|
|
|
|
|
cmd = ADM1021_COMPANY;
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, comp);
|
2016-01-03 20:27:26 +03:00
|
|
|
|
|
|
|
cmd = ADM1021_DIE_REVISION;
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, rev);
|
2016-01-03 20:27:26 +03:00
|
|
|
|
|
|
|
sc->sc_noneg = 1;
|
|
|
|
sc->sc_nolow = 0;
|
|
|
|
sc->sc_ext11 = 0;
|
|
|
|
sc->sc_therm = 0;
|
|
|
|
|
|
|
|
/* Direct config */
|
|
|
|
for (i = 0; i < ia->ia_ncompat; i++) {
|
|
|
|
if (strcmp("i2c-max1617", ia->ia_compat[i]) == 0) {
|
|
|
|
sc->sc_noneg = 0;
|
|
|
|
strlcpy(name, "MAX1617A", ADMTEMP_NAMELEN);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-01 23:11:59 +03:00
|
|
|
if (strcmp("max6642", ia->ia_compat[i]) == 0) {
|
|
|
|
sc->sc_noneg = 0;
|
2017-09-14 00:15:11 +03:00
|
|
|
sc->sc_nolow = 1;
|
2017-09-01 23:11:59 +03:00
|
|
|
strlcpy(name, "MAX6642", ADMTEMP_NAMELEN);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-21 01:44:28 +03:00
|
|
|
if (strcmp("max6690", ia->ia_compat[i]) == 0) {
|
|
|
|
sc->sc_noneg = 0;
|
|
|
|
sc->sc_ext11 = 1;
|
|
|
|
strlcpy(name, "MAX6690", ADMTEMP_NAMELEN);
|
|
|
|
return;
|
|
|
|
}
|
2016-01-03 20:27:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Indirect config */
|
|
|
|
if (*comp == 0) {
|
|
|
|
sc->sc_noneg = 0;
|
|
|
|
cmd = ADM1021_INT_LOW_READ;
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, comp) == 0 &&
|
|
|
|
*comp != ADMTEMP_LOW_DEFAULT) {
|
2016-01-03 20:27:26 +03:00
|
|
|
sc->sc_nolow = 1;
|
|
|
|
strlcpy(name, "LM84", ADMTEMP_NAMELEN);
|
|
|
|
} else
|
|
|
|
strlcpy(name, "MAX1617", ADMTEMP_NAMELEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*comp == ADM1021_COMPANY_MAXIM) {
|
|
|
|
sc->sc_noneg = 0;
|
2017-09-01 23:11:59 +03:00
|
|
|
/*
|
|
|
|
* MAX6642 doesn't have a revision register
|
|
|
|
* XXX this works only on macppc with iic at pmu because the
|
|
|
|
* pmu doesn't return an error for nonexistant registers, it
|
|
|
|
* just repeats previous data
|
|
|
|
*/
|
|
|
|
if (*comp == *rev) {
|
|
|
|
sc->sc_therm = 0; /* */
|
2017-09-14 00:15:11 +03:00
|
|
|
sc->sc_nolow = 1;
|
2017-09-01 23:11:59 +03:00
|
|
|
strlcpy(name, "MAX6642", ADMTEMP_NAMELEN);
|
2017-09-21 01:44:28 +03:00
|
|
|
} else if (*rev == 0) {
|
|
|
|
strlcpy(name, "MAX6690", ADMTEMP_NAMELEN);
|
|
|
|
sc->sc_ext11 = 1;
|
2017-09-01 23:11:59 +03:00
|
|
|
} else {
|
|
|
|
strlcpy(name, "MAX1617A", ADMTEMP_NAMELEN);
|
|
|
|
}
|
2016-01-03 20:27:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*comp == ADM1021_COMPANY_GMT) {
|
|
|
|
sc->sc_ext11 = 1;
|
|
|
|
sc->sc_therm = 1;
|
|
|
|
strlcpy(name, "G781", ADMTEMP_NAMELEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*comp == ADM1021_COMPANY_ADM) {
|
|
|
|
cmd = ADM1023_EXT_HIGH2;
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &data) == 0) {
|
2016-01-03 20:27:26 +03:00
|
|
|
tmp = 1 << ADM1023_EXT2_SHIFT;
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &tmp);
|
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd,
|
|
|
|
&tmp) == 0 && tmp == 1 << ADM1023_EXT2_SHIFT) {
|
2016-01-03 20:27:26 +03:00
|
|
|
sc->sc_ext11 = 1;
|
|
|
|
strlcpy(name, "ADM1023", ADMTEMP_NAMELEN);
|
|
|
|
}
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &data);
|
2016-01-03 20:27:26 +03:00
|
|
|
}
|
|
|
|
cmd = ADM1032_EXT_THERM;
|
|
|
|
if (sc->sc_ext11 &&
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &data) == 0
|
|
|
|
&& data == 0x55) {
|
2016-01-03 20:27:26 +03:00
|
|
|
sc->sc_therm = 1;
|
|
|
|
strlcpy(name, "ADM1032", ADMTEMP_NAMELEN);
|
|
|
|
}
|
|
|
|
if (!sc->sc_ext11 &&
|
|
|
|
(*rev & ADM1021_REV_MASK) == ADM1021_REV_1021A) {
|
|
|
|
sc->sc_noneg = 0;
|
|
|
|
strlcpy(name, "ADM1021A", ADMTEMP_NAMELEN);
|
|
|
|
} else
|
|
|
|
strlcpy(name, "ADM1021", ADMTEMP_NAMELEN);
|
|
|
|
}
|
|
|
|
}
|
2008-10-29 20:26:56 +03:00
|
|
|
|
|
|
|
void
|
2009-05-12 18:16:35 +04:00
|
|
|
admtemp_attach(device_t parent, device_t self, void *aux)
|
2008-10-29 20:26:56 +03:00
|
|
|
{
|
|
|
|
struct admtemp_softc *sc = device_private(self);
|
|
|
|
struct i2c_attach_args *ia = aux;
|
2016-01-04 22:24:15 +03:00
|
|
|
uint8_t cmd, data, stat, comp, rev;
|
2016-01-03 20:27:26 +03:00
|
|
|
char name[ADMTEMP_NAMELEN];
|
2020-08-21 23:44:38 +03:00
|
|
|
char ename[64] = "external", iname[64] = "internal";
|
|
|
|
const char *desc;
|
|
|
|
|
2008-10-29 20:26:56 +03:00
|
|
|
sc->sc_tag = ia->ia_tag;
|
|
|
|
sc->sc_addr = ia->ia_addr;
|
2020-08-21 23:44:38 +03:00
|
|
|
sc->sc_prop = ia->ia_prop;
|
2008-10-29 20:26:56 +03:00
|
|
|
|
|
|
|
iic_acquire_bus(sc->sc_tag, 0);
|
|
|
|
cmd = ADM1021_CONFIG_READ;
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &data) != 0) {
|
2008-10-29 20:26:56 +03:00
|
|
|
iic_release_bus(sc->sc_tag, 0);
|
2012-10-27 21:17:22 +04:00
|
|
|
aprint_error_dev(self, "cannot get control register\n");
|
2008-10-29 20:26:56 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (data & ADM1021_CONFIG_RUN) {
|
|
|
|
cmd = ADM1021_STATUS;
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &stat)) {
|
2008-10-29 20:26:56 +03:00
|
|
|
iic_release_bus(sc->sc_tag, 0);
|
2012-10-27 21:17:22 +04:00
|
|
|
aprint_error_dev(self,
|
2008-10-29 20:26:56 +03:00
|
|
|
"cannot read status register\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((stat & ADM1021_STATUS_INVAL) == ADM1021_STATUS_INVAL) {
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd,
|
|
|
|
&stat)) {
|
2008-10-29 20:26:56 +03:00
|
|
|
iic_release_bus(sc->sc_tag, 0);
|
2012-10-27 21:17:22 +04:00
|
|
|
aprint_error_dev(self,
|
2008-10-29 20:26:56 +03:00
|
|
|
"cannot read status register\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* means external is dead */
|
|
|
|
if ((stat & ADM1021_STATUS_INVAL) != ADM1021_STATUS_INVAL &&
|
|
|
|
(stat & ADM1021_STATUS_NOEXT))
|
|
|
|
sc->sc_noexternal = 1;
|
|
|
|
|
|
|
|
data &= ~ADM1021_CONFIG_RUN;
|
|
|
|
cmd = ADM1021_CONFIG_WRITE;
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &data)) {
|
2008-10-29 20:26:56 +03:00
|
|
|
iic_release_bus(sc->sc_tag, 0);
|
2012-10-27 21:17:22 +04:00
|
|
|
aprint_error_dev(self,
|
2008-10-29 20:26:56 +03:00
|
|
|
"cannot set control register\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-01-03 20:27:26 +03:00
|
|
|
|
|
|
|
admtemp_setflags(sc, ia, &comp, &rev, name);
|
|
|
|
|
2008-10-29 20:26:56 +03:00
|
|
|
iic_release_bus(sc->sc_tag, 0);
|
|
|
|
|
2016-01-03 20:27:26 +03:00
|
|
|
aprint_normal(": %s temperature sensor", name);
|
|
|
|
if (comp)
|
|
|
|
aprint_normal(": id. 0x%02x, rev. 0x%02x\n", comp, rev);
|
|
|
|
else
|
|
|
|
aprint_normal("\n");
|
|
|
|
aprint_naive(": Temperature sensor\n");
|
|
|
|
|
2008-10-29 20:26:56 +03:00
|
|
|
/* Initialize sensor data. */
|
2011-06-19 15:44:03 +04:00
|
|
|
sc->sc_sensor[ADMTEMP_INT].state = ENVSYS_SINVALID;
|
2008-10-29 20:26:56 +03:00
|
|
|
sc->sc_sensor[ADMTEMP_INT].units = ENVSYS_STEMP;
|
2011-06-19 15:44:03 +04:00
|
|
|
sc->sc_sensor[ADMTEMP_EXT].state = ENVSYS_SINVALID;
|
2008-10-29 20:26:56 +03:00
|
|
|
sc->sc_sensor[ADMTEMP_EXT].units = ENVSYS_STEMP;
|
2021-01-24 08:30:05 +03:00
|
|
|
sc->sc_sensor[ADMTEMP_INT].flags =
|
|
|
|
ENVSYS_FMONLIMITS | ENVSYS_FHAS_ENTROPY;
|
|
|
|
sc->sc_sensor[ADMTEMP_EXT].flags =
|
|
|
|
ENVSYS_FMONLIMITS | ENVSYS_FHAS_ENTROPY;
|
2020-08-21 23:44:38 +03:00
|
|
|
|
|
|
|
if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "s00", &desc)) {
|
|
|
|
strncpy(iname, desc, 64);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prop_dictionary_get_cstring_nocopy(sc->sc_prop, "s01", &desc)) {
|
|
|
|
strncpy(ename, desc, 64);
|
|
|
|
}
|
|
|
|
|
2017-09-29 17:17:47 +03:00
|
|
|
strlcpy(sc->sc_sensor[ADMTEMP_INT].desc, iname,
|
|
|
|
sizeof(sc->sc_sensor[ADMTEMP_INT].desc));
|
|
|
|
strlcpy(sc->sc_sensor[ADMTEMP_EXT].desc, ename,
|
|
|
|
sizeof(sc->sc_sensor[ADMTEMP_EXT].desc));
|
2020-08-21 23:44:38 +03:00
|
|
|
|
2008-10-29 20:26:56 +03:00
|
|
|
sc->sc_sme = sysmon_envsys_create();
|
|
|
|
if (sysmon_envsys_sensor_attach(
|
|
|
|
sc->sc_sme, &sc->sc_sensor[ADMTEMP_INT])) {
|
|
|
|
sysmon_envsys_destroy(sc->sc_sme);
|
2020-12-10 20:02:51 +03:00
|
|
|
sc->sc_sme = NULL;
|
2012-10-27 21:17:22 +04:00
|
|
|
aprint_error_dev(self,
|
2008-10-29 20:26:56 +03:00
|
|
|
"unable to attach internal at sysmon\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sc->sc_noexternal == 0 &&
|
|
|
|
sysmon_envsys_sensor_attach(
|
|
|
|
sc->sc_sme, &sc->sc_sensor[ADMTEMP_EXT])) {
|
|
|
|
sysmon_envsys_destroy(sc->sc_sme);
|
2020-12-10 20:02:51 +03:00
|
|
|
sc->sc_sme = NULL;
|
2012-10-27 21:17:22 +04:00
|
|
|
aprint_error_dev(self,
|
2008-10-29 20:26:56 +03:00
|
|
|
"unable to attach external at sysmon\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sc->sc_sme->sme_name = device_xname(self);
|
|
|
|
sc->sc_sme->sme_cookie = sc;
|
|
|
|
sc->sc_sme->sme_refresh = admtemp_refresh;
|
2016-01-03 20:27:26 +03:00
|
|
|
if (sc->sc_therm) {
|
|
|
|
sc->sc_sme->sme_get_limits = admtemp_getlim_1032;
|
|
|
|
sc->sc_sme->sme_set_limits = admtemp_setlim_1032;
|
|
|
|
} else if (sc->sc_ext11) {
|
|
|
|
sc->sc_sme->sme_get_limits = admtemp_getlim_1023;
|
|
|
|
sc->sc_sme->sme_set_limits = admtemp_setlim_1023;
|
|
|
|
} else {
|
|
|
|
sc->sc_sme->sme_get_limits = admtemp_getlim_1021;
|
|
|
|
sc->sc_sme->sme_set_limits = admtemp_setlim_1021;
|
|
|
|
}
|
2008-10-29 20:26:56 +03:00
|
|
|
if (sysmon_envsys_register(sc->sc_sme)) {
|
2012-10-27 21:17:22 +04:00
|
|
|
aprint_error_dev(self,
|
2008-10-29 20:26:56 +03:00
|
|
|
"unable to register with sysmon\n");
|
|
|
|
sysmon_envsys_destroy(sc->sc_sme);
|
2020-12-10 20:02:51 +03:00
|
|
|
sc->sc_sme = NULL;
|
2008-10-29 20:26:56 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
admtemp_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
|
|
|
|
{
|
|
|
|
struct admtemp_softc *sc = sme->sme_cookie;
|
2016-01-04 22:24:15 +03:00
|
|
|
uint8_t cmd, xdata;
|
2008-10-29 20:26:56 +03:00
|
|
|
int8_t sdata;
|
|
|
|
|
2020-12-10 20:02:51 +03:00
|
|
|
if (iic_acquire_bus(sc->sc_tag, 0)) {
|
|
|
|
edata->state = ENVSYS_SINVALID;
|
|
|
|
return;
|
|
|
|
}
|
2008-10-29 20:26:56 +03:00
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_TEMP;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_TEMP;
|
2016-01-03 20:27:26 +03:00
|
|
|
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &sdata) == 0) {
|
2008-10-29 20:26:56 +03:00
|
|
|
if (sdata == ADM1021_STATUS_INVAL) {
|
|
|
|
edata->state = ENVSYS_SINVALID;
|
|
|
|
} else {
|
|
|
|
edata->value_cur = 273150000 + 1000000 * sdata;
|
|
|
|
edata->state = ENVSYS_SVALID;
|
|
|
|
}
|
|
|
|
}
|
2016-01-03 20:27:26 +03:00
|
|
|
if (edata->sensor == ADMTEMP_EXT && sc->sc_ext11) {
|
|
|
|
cmd = ADM1023_EXT_TEMP2;
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &xdata);
|
2016-01-03 20:27:26 +03:00
|
|
|
edata->value_cur +=
|
|
|
|
(xdata >> ADM1023_EXT2_SHIFT & ADM1023_EXT2_MASK) * 125000;
|
|
|
|
}
|
|
|
|
|
|
|
|
iic_release_bus(sc->sc_tag, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
admtemp_getlim_1021(struct sysmon_envsys *sme, envsys_data_t *edata,
|
|
|
|
sysmon_envsys_lim_t *limits, uint32_t *props)
|
|
|
|
{
|
|
|
|
struct admtemp_softc *sc = sme->sme_cookie;
|
2016-01-04 22:24:15 +03:00
|
|
|
uint8_t cmd;
|
2016-01-03 20:27:26 +03:00
|
|
|
int8_t hdata = 0x7f, ldata = 0xc9;
|
|
|
|
|
|
|
|
*props &= ~(PROP_CRITMAX | PROP_CRITMIN);
|
|
|
|
|
2020-12-10 20:02:51 +03:00
|
|
|
if (iic_acquire_bus(sc->sc_tag, 0))
|
|
|
|
return;
|
2016-01-03 20:27:26 +03:00
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_HIGH_READ;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_HIGH_READ;
|
|
|
|
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &hdata) == 0 &&
|
2016-01-03 20:27:26 +03:00
|
|
|
hdata != ADMTEMP_LIM_INVAL) {
|
|
|
|
limits->sel_critmax = 273150000 + 1000000 * hdata;
|
|
|
|
*props |= PROP_CRITMAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_nolow == 1) {
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_LOW_READ;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_LOW_READ;
|
|
|
|
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &ldata) == 0 &&
|
2016-01-03 20:27:26 +03:00
|
|
|
ldata != ADMTEMP_LIM_INVAL) {
|
|
|
|
limits->sel_critmin = 273150000 + 1000000 * ldata;
|
|
|
|
*props |= PROP_CRITMIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
release:
|
|
|
|
iic_release_bus(sc->sc_tag, 0);
|
|
|
|
|
|
|
|
/* Save the values if this is the first time through. */
|
|
|
|
if (sc->sc_setdef[edata->sensor] == 0) {
|
|
|
|
sc->sc_setdef[edata->sensor] = 1;
|
|
|
|
sc->sc_highlim[edata->sensor] = hdata;
|
|
|
|
sc->sc_lowlim[edata->sensor] = ldata;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
admtemp_getlim_1023(struct sysmon_envsys *sme, envsys_data_t *edata,
|
|
|
|
sysmon_envsys_lim_t *limits, uint32_t *props)
|
|
|
|
{
|
|
|
|
struct admtemp_softc *sc = sme->sme_cookie;
|
2016-01-04 22:24:15 +03:00
|
|
|
uint8_t cmd, xhdata = 0, xldata = 0;
|
2016-01-03 20:27:26 +03:00
|
|
|
int8_t hdata = 0x7f, ldata = 0xc9;
|
|
|
|
|
|
|
|
*props &= ~(PROP_CRITMAX | PROP_CRITMIN);
|
|
|
|
|
2020-12-10 20:02:51 +03:00
|
|
|
if (iic_acquire_bus(sc->sc_tag, 0))
|
|
|
|
return;
|
2016-01-03 20:27:26 +03:00
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_HIGH_READ;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_HIGH_READ;
|
|
|
|
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &hdata) == 0 &&
|
2016-01-03 20:27:26 +03:00
|
|
|
hdata != ADMTEMP_LIM_INVAL) {
|
|
|
|
limits->sel_critmax = 273150000 + 1000000 * hdata;
|
|
|
|
*props |= PROP_CRITMAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_EXT) {
|
|
|
|
cmd = ADM1023_EXT_HIGH2;
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &xhdata) == 0)
|
2016-01-03 20:27:26 +03:00
|
|
|
limits->sel_critmax +=
|
|
|
|
(xhdata >> ADM1023_EXT2_SHIFT & ADM1023_EXT2_MASK)
|
|
|
|
* 125000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_LOW_READ;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_LOW_READ;
|
|
|
|
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &ldata) == 0 &&
|
2016-01-03 20:27:26 +03:00
|
|
|
ldata != ADMTEMP_LIM_INVAL) {
|
|
|
|
limits->sel_critmin = 273150000 + 1000000 * ldata;
|
|
|
|
*props |= PROP_CRITMIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_EXT) {
|
|
|
|
cmd = ADM1023_EXT_LOW2;
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &xldata) == 0)
|
2016-01-03 20:27:26 +03:00
|
|
|
limits->sel_critmin +=
|
|
|
|
(xldata >> ADM1023_EXT2_SHIFT & ADM1023_EXT2_MASK)
|
|
|
|
* 125000;
|
|
|
|
}
|
|
|
|
|
|
|
|
iic_release_bus(sc->sc_tag, 0);
|
|
|
|
|
|
|
|
/* Save the values if this is the first time through. */
|
|
|
|
if (sc->sc_setdef[edata->sensor] == 0) {
|
|
|
|
sc->sc_setdef[edata->sensor] = 1;
|
|
|
|
sc->sc_highlim[edata->sensor] = hdata;
|
|
|
|
sc->sc_lowlim[edata->sensor] = ldata;
|
|
|
|
if (edata->sensor == ADMTEMP_EXT) {
|
|
|
|
sc->sc_highlim2 = xhdata;
|
|
|
|
sc->sc_lowlim2 = xldata;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
admtemp_getlim_1032(struct sysmon_envsys *sme, envsys_data_t *edata,
|
|
|
|
sysmon_envsys_lim_t *limits, uint32_t *props)
|
|
|
|
{
|
|
|
|
struct admtemp_softc *sc = sme->sme_cookie;
|
2016-01-04 22:24:15 +03:00
|
|
|
uint8_t cmd, xhdata = 0, xldata = 0;
|
2016-01-03 20:27:26 +03:00
|
|
|
int8_t tdata = 0x55, hdata = 0x55, ldata = 0;
|
|
|
|
|
|
|
|
*props &= ~(PROP_WARNMAX | PROP_CRITMAX | PROP_WARNMIN);
|
|
|
|
|
2020-12-10 20:02:51 +03:00
|
|
|
if (iic_acquire_bus(sc->sc_tag, 0))
|
|
|
|
return;
|
2016-01-03 20:27:26 +03:00
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1032_INT_THERM;
|
|
|
|
else
|
|
|
|
cmd = ADM1032_EXT_THERM;
|
|
|
|
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &tdata) == 0 &&
|
2016-01-03 20:27:26 +03:00
|
|
|
tdata != ADMTEMP_LIM_INVAL) {
|
|
|
|
limits->sel_critmax = 273150000 + 1000000 * tdata;
|
|
|
|
*props |= PROP_CRITMAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_HIGH_READ;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_HIGH_READ;
|
|
|
|
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &hdata) == 0 &&
|
2016-01-03 20:27:26 +03:00
|
|
|
hdata != ADMTEMP_LIM_INVAL) {
|
|
|
|
limits->sel_warnmax = 273150000 + 1000000 * hdata;
|
|
|
|
*props |= PROP_WARNMAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_EXT) {
|
|
|
|
cmd = ADM1023_EXT_HIGH2;
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &xhdata) == 0)
|
2016-01-03 20:27:26 +03:00
|
|
|
limits->sel_warnmax +=
|
|
|
|
(xhdata >> ADM1023_EXT2_SHIFT & ADM1023_EXT2_MASK)
|
|
|
|
* 125000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_LOW_READ;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_LOW_READ;
|
|
|
|
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &ldata) == 0 &&
|
2016-01-03 20:27:26 +03:00
|
|
|
ldata != ADMTEMP_LIM_INVAL) {
|
|
|
|
limits->sel_warnmin = 273150000 + 1000000 * ldata;
|
|
|
|
*props |= PROP_WARNMIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_EXT) {
|
|
|
|
cmd = ADM1023_EXT_LOW2;
|
2016-01-04 22:24:15 +03:00
|
|
|
if (admtemp_exec(sc, I2C_OP_READ_WITH_STOP, &cmd, &xldata) == 0)
|
2016-01-03 20:27:26 +03:00
|
|
|
limits->sel_warnmin +=
|
|
|
|
(xldata >> ADM1023_EXT2_SHIFT & ADM1023_EXT2_MASK)
|
|
|
|
* 125000;
|
|
|
|
}
|
|
|
|
|
|
|
|
iic_release_bus(sc->sc_tag, 0);
|
|
|
|
|
|
|
|
/* Save the values if this is the first time through. */
|
|
|
|
if (sc->sc_setdef[edata->sensor] == 0) {
|
|
|
|
sc->sc_setdef[edata->sensor] = 1;
|
|
|
|
sc->sc_thermlim[edata->sensor] = tdata;
|
|
|
|
sc->sc_highlim[edata->sensor] = hdata;
|
|
|
|
sc->sc_lowlim[edata->sensor] = ldata;
|
|
|
|
if (edata->sensor == ADMTEMP_EXT) {
|
|
|
|
sc->sc_highlim2 = xhdata;
|
|
|
|
sc->sc_lowlim2 = xldata;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
admtemp_setlim_1021(struct sysmon_envsys *sme, envsys_data_t *edata,
|
|
|
|
sysmon_envsys_lim_t *limits, uint32_t *props)
|
|
|
|
{
|
|
|
|
struct admtemp_softc *sc = sme->sme_cookie;
|
2016-01-04 22:24:15 +03:00
|
|
|
uint8_t cmd;
|
2016-01-03 20:27:26 +03:00
|
|
|
int tmp;
|
|
|
|
int8_t sdata;
|
|
|
|
|
2020-12-10 20:02:51 +03:00
|
|
|
if (iic_acquire_bus(sc->sc_tag, 0))
|
|
|
|
return;
|
2016-01-03 20:27:26 +03:00
|
|
|
|
|
|
|
if (*props & PROP_CRITMAX) {
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_HIGH_WRITE;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_HIGH_WRITE;
|
|
|
|
|
|
|
|
if (limits == NULL) /* Restore defaults */
|
|
|
|
sdata = sc->sc_highlim[edata->sensor];
|
|
|
|
else {
|
|
|
|
tmp = (limits->sel_critmax - 273150000) / 1000000;
|
|
|
|
if (tmp > ADMTEMP_MAX_POS)
|
|
|
|
sdata = ADMTEMP_MAX_POS;
|
|
|
|
else if (tmp < 0 && sc->sc_noneg)
|
|
|
|
sdata = 0;
|
|
|
|
else if (tmp < ADMTEMP_MAX_NEG)
|
|
|
|
sdata = ADMTEMP_MAX_NEG;
|
|
|
|
else
|
|
|
|
sdata = tmp & 0xff;
|
|
|
|
}
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &sdata);
|
2016-01-03 20:27:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*props & PROP_CRITMIN && sc->sc_nolow == 0) {
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_LOW_WRITE;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_LOW_WRITE;
|
|
|
|
if (limits == NULL)
|
|
|
|
sdata = sc->sc_lowlim[edata->sensor];
|
|
|
|
else {
|
|
|
|
tmp = (limits->sel_critmin - 273150000) / 1000000;
|
|
|
|
if (tmp > ADMTEMP_MAX_POS)
|
|
|
|
sdata = ADMTEMP_MAX_POS;
|
|
|
|
else if (tmp < 0 && sc->sc_noneg)
|
|
|
|
sdata = 0;
|
|
|
|
else if (tmp < ADMTEMP_MAX_NEG)
|
|
|
|
sdata = ADMTEMP_MAX_NEG;
|
|
|
|
else
|
|
|
|
sdata = tmp & 0xff;
|
|
|
|
}
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &sdata);
|
2016-01-03 20:27:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
iic_release_bus(sc->sc_tag, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_encode_temp(const uint32_t val, int8_t *sdata, uint8_t *xdata,
|
2016-01-03 20:27:26 +03:00
|
|
|
const int ext11)
|
|
|
|
{
|
|
|
|
int32_t tmp;
|
|
|
|
|
|
|
|
if (ext11) {
|
|
|
|
/* Split temperature into high and low bytes */
|
|
|
|
tmp = (val - 273150000) / 125000;
|
|
|
|
*xdata = (tmp & ADM1023_EXT2_MASK) << ADM1023_EXT2_SHIFT;
|
|
|
|
tmp -= (int32_t) (*xdata >> ADM1023_EXT2_SHIFT);
|
|
|
|
tmp /= 8; /* 1000000 / 125000 */
|
|
|
|
} else {
|
|
|
|
*xdata = 0;
|
|
|
|
tmp = (val - 273150000) / 1000000;
|
|
|
|
}
|
|
|
|
if (tmp > ADMTEMP_MAX_POS)
|
|
|
|
*sdata = ADMTEMP_MAX_POS;
|
|
|
|
else if (tmp < 0)
|
|
|
|
*sdata = 0;
|
|
|
|
else
|
|
|
|
*sdata = tmp & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
admtemp_setlim_1023(struct sysmon_envsys *sme, envsys_data_t *edata,
|
|
|
|
sysmon_envsys_lim_t *limits, uint32_t *props)
|
|
|
|
{
|
|
|
|
struct admtemp_softc *sc = sme->sme_cookie;
|
|
|
|
int ext11;
|
2016-01-04 22:24:15 +03:00
|
|
|
uint8_t cmd, xdata;
|
2016-01-03 20:27:26 +03:00
|
|
|
int8_t sdata;
|
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
ext11 = 0;
|
|
|
|
else
|
|
|
|
ext11 = 1;
|
|
|
|
|
2020-12-10 20:02:51 +03:00
|
|
|
if (iic_acquire_bus(sc->sc_tag, 0))
|
|
|
|
return;
|
2016-01-03 20:27:26 +03:00
|
|
|
|
|
|
|
if (*props & PROP_CRITMAX) {
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_HIGH_WRITE;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_HIGH_WRITE;
|
|
|
|
|
|
|
|
if (limits == NULL) { /* Restore defaults */
|
|
|
|
sdata = sc->sc_highlim[edata->sensor];
|
|
|
|
xdata = sc->sc_highlim2;
|
|
|
|
} else
|
|
|
|
admtemp_encode_temp(limits->sel_critmax, &sdata,
|
|
|
|
&xdata, ext11);
|
|
|
|
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &sdata);
|
2016-01-03 20:27:26 +03:00
|
|
|
if (ext11) {
|
|
|
|
cmd = ADM1023_EXT_HIGH2;
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &xdata);
|
2016-01-03 20:27:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*props & PROP_CRITMIN) {
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_LOW_WRITE;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_LOW_WRITE;
|
|
|
|
if (limits == NULL) {
|
|
|
|
sdata = sc->sc_lowlim[edata->sensor];
|
|
|
|
xdata = sc->sc_lowlim2;
|
|
|
|
} else
|
|
|
|
admtemp_encode_temp(limits->sel_critmax, &sdata,
|
|
|
|
&xdata, ext11);
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &sdata);
|
2016-01-03 20:27:26 +03:00
|
|
|
if (ext11) {
|
|
|
|
cmd = ADM1023_EXT_LOW2;
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &xdata);
|
2016-01-03 20:27:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iic_release_bus(sc->sc_tag, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
admtemp_setlim_1032(struct sysmon_envsys *sme, envsys_data_t *edata,
|
|
|
|
sysmon_envsys_lim_t *limits, uint32_t *props)
|
|
|
|
{
|
|
|
|
struct admtemp_softc *sc = sme->sme_cookie;
|
|
|
|
int ext11;
|
2016-01-04 22:24:15 +03:00
|
|
|
uint8_t cmd, xdata;
|
2016-01-03 20:27:26 +03:00
|
|
|
int8_t sdata;
|
|
|
|
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
ext11 = 0;
|
|
|
|
else
|
|
|
|
ext11 = 1;
|
|
|
|
|
2020-12-10 20:02:51 +03:00
|
|
|
if (iic_acquire_bus(sc->sc_tag, 0))
|
|
|
|
return;
|
2016-01-03 20:27:26 +03:00
|
|
|
|
|
|
|
if (*props & PROP_CRITMAX) {
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1032_INT_THERM;
|
|
|
|
else
|
|
|
|
cmd = ADM1032_EXT_THERM;
|
|
|
|
if (limits == NULL) /* Restore default */
|
|
|
|
sdata = sc->sc_thermlim[edata->sensor];
|
|
|
|
else
|
|
|
|
admtemp_encode_temp(limits->sel_critmax, &sdata,
|
|
|
|
&xdata, 0);
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &sdata);
|
2016-01-03 20:27:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*props & PROP_WARNMAX) {
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_HIGH_WRITE;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_HIGH_WRITE;
|
|
|
|
|
|
|
|
if (limits == NULL) { /* Restore defaults */
|
|
|
|
sdata = sc->sc_highlim[edata->sensor];
|
|
|
|
xdata = sc->sc_highlim2;
|
|
|
|
} else
|
|
|
|
admtemp_encode_temp(limits->sel_warnmax, &sdata,
|
|
|
|
&xdata, ext11);
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &sdata);
|
2016-01-03 20:27:26 +03:00
|
|
|
|
|
|
|
if (ext11) {
|
|
|
|
cmd = ADM1023_EXT_HIGH2;
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &xdata);
|
2016-01-03 20:27:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*props & PROP_WARNMIN) {
|
|
|
|
if (edata->sensor == ADMTEMP_INT)
|
|
|
|
cmd = ADM1021_INT_LOW_WRITE;
|
|
|
|
else
|
|
|
|
cmd = ADM1021_EXT_LOW_WRITE;
|
|
|
|
if (limits == NULL) {
|
|
|
|
sdata = sc->sc_lowlim[edata->sensor];
|
|
|
|
xdata = sc->sc_lowlim2;
|
|
|
|
} else
|
|
|
|
admtemp_encode_temp(limits->sel_warnmin, &sdata,
|
|
|
|
&xdata, ext11);
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &sdata);
|
2016-01-03 20:27:26 +03:00
|
|
|
|
|
|
|
if (ext11) {
|
|
|
|
cmd = ADM1023_EXT_LOW2;
|
2016-01-04 22:24:15 +03:00
|
|
|
admtemp_exec(sc, I2C_OP_WRITE_WITH_STOP, &cmd, &xdata);
|
2016-01-03 20:27:26 +03:00
|
|
|
}
|
|
|
|
}
|
2008-10-29 20:26:56 +03:00
|
|
|
|
|
|
|
iic_release_bus(sc->sc_tag, 0);
|
|
|
|
}
|