Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/iicbus/lm75.c
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
#ifdef FDT | #ifdef FDT | ||||
#include <dev/ofw/openfirm.h> | #include <dev/ofw/openfirm.h> | ||||
#include <dev/ofw/ofw_bus.h> | #include <dev/ofw/ofw_bus.h> | ||||
#include <dev/ofw/ofw_bus_subr.h> | #include <dev/ofw/ofw_bus_subr.h> | ||||
#endif | #endif | ||||
/* LM75 registers. */ | /* LM75 registers. */ | ||||
#define LM75_TEMP 0x0 | #define LM75_TEMP 0x0 | ||||
#define LM75_TEMP_MASK 0xff80 | |||||
#define LM75A_TEMP_MASK 0xffe0 | |||||
#define LM75_CONF 0x1 | #define LM75_CONF 0x1 | ||||
#define LM75_CONF_FSHIFT 3 | #define LM75_CONF_FSHIFT 3 | ||||
#define LM75_CONF_FAULT 0x18 | #define LM75_CONF_FAULT 0x18 | ||||
#define LM75_CONF_POL 0x04 | #define LM75_CONF_POL 0x04 | ||||
#define LM75_CONF_MODE 0x02 | #define LM75_CONF_MODE 0x02 | ||||
#define LM75_CONF_SHUTD 0x01 | #define LM75_CONF_SHUTD 0x01 | ||||
#define LM75_CONF_MASK 0x1f | #define LM75_CONF_MASK 0x1f | ||||
#define LM75_THYST 0x2 | #define LM75_THYST 0x2 | ||||
#define LM75_TOS 0x3 | #define LM75_TOS 0x3 | ||||
/* LM75 constants. */ | /* LM75 constants. */ | ||||
#define LM75_TEST_PATTERN 0xa | #define LM75_TEST_PATTERN 0xa | ||||
#define LM75_MIN_TEMP -55 | #define LM75_MIN_TEMP -55 | ||||
#define LM75_MAX_TEMP 125 | #define LM75_MAX_TEMP 125 | ||||
#define LM75_0500C 0x80 | #define TZ_ZEROC 27315 | ||||
#define LM75_0250C 0x40 | #define TZ_ZEROC_DIVIDER 100 | ||||
#define LM75_0125C 0x20 | |||||
#define LM75_MSB 0x8000 | |||||
#define LM75_NEG_BIT LM75_MSB | |||||
#define TZ_ZEROC 2731 | |||||
/* LM75 supported models. */ | enum max_resolution{ | ||||
#define HWTYPE_LM75 1 | BITS_9 = 1, | ||||
#define HWTYPE_LM75A 2 | BITS_11 | ||||
}; | |||||
/* Regular bus attachment functions */ | /* Regular bus attachment functions */ | ||||
static int lm75_probe(device_t); | static int lm75_probe(device_t); | ||||
static int lm75_attach(device_t); | static int lm75_attach(device_t); | ||||
struct lm75_softc { | struct lm75_softc { | ||||
device_t sc_dev; | device_t sc_dev; | ||||
struct intr_config_hook enum_hook; | struct intr_config_hook enum_hook; | ||||
int32_t sc_hwtype; | |||||
uint32_t sc_addr; | uint32_t sc_addr; | ||||
uint32_t sc_conf; | uint32_t sc_conf; | ||||
uint8_t sc_resolution; | |||||
uint8_t sc_max_resolution; | |||||
uint16_t sc_multiplier; | |||||
}; | }; | ||||
/* Utility functions */ | /* Utility functions */ | ||||
static int lm75_conf_read(struct lm75_softc *); | static int lm75_conf_read(struct lm75_softc *); | ||||
static int lm75_conf_write(struct lm75_softc *); | static int lm75_conf_write(struct lm75_softc *); | ||||
static int lm75_temp_read(struct lm75_softc *, uint8_t, int *); | static int lm75_temp_read(struct lm75_softc *, uint8_t, int *); | ||||
static int lm75_temp_write(struct lm75_softc *, uint8_t, int); | static int lm75_temp_write(struct lm75_softc *, uint8_t, int); | ||||
static void lm75_start(void *); | static void lm75_start(void *); | ||||
static int lm75_read(device_t, uint32_t, uint8_t, uint8_t *, size_t); | static int lm75_read(device_t, uint32_t, uint8_t, uint8_t *, size_t); | ||||
static int lm75_write(device_t, uint32_t, uint8_t *, size_t); | static int lm75_write(device_t, uint32_t, uint8_t *, size_t); | ||||
static int lm75_str_mode(char *); | static int lm75_str_mode(char *); | ||||
static int lm75_str_pol(char *); | static int lm75_str_pol(char *); | ||||
static int lm75_temp_sysctl(SYSCTL_HANDLER_ARGS); | static int lm75_temp_sysctl(SYSCTL_HANDLER_ARGS); | ||||
static int lm75_faults_sysctl(SYSCTL_HANDLER_ARGS); | static int lm75_faults_sysctl(SYSCTL_HANDLER_ARGS); | ||||
static int lm75_mode_sysctl(SYSCTL_HANDLER_ARGS); | static int lm75_mode_sysctl(SYSCTL_HANDLER_ARGS); | ||||
static int lm75_pol_sysctl(SYSCTL_HANDLER_ARGS); | static int lm75_pol_sysctl(SYSCTL_HANDLER_ARGS); | ||||
static int lm75_shutdown_sysctl(SYSCTL_HANDLER_ARGS); | static int lm75_shutdown_sysctl(SYSCTL_HANDLER_ARGS); | ||||
static int lm75_resolution_sysctl(SYSCTL_HANDLER_ARGS); | |||||
static device_method_t lm75_methods[] = { | static device_method_t lm75_methods[] = { | ||||
/* Device interface */ | /* Device interface */ | ||||
DEVMETHOD(device_probe, lm75_probe), | DEVMETHOD(device_probe, lm75_probe), | ||||
DEVMETHOD(device_attach, lm75_attach), | DEVMETHOD(device_attach, lm75_attach), | ||||
DEVMETHOD_END | DEVMETHOD_END | ||||
}; | }; | ||||
static driver_t lm75_driver = { | static driver_t lm75_driver = { | ||||
"lm75", | "lm75", | ||||
lm75_methods, | lm75_methods, | ||||
sizeof(struct lm75_softc) | sizeof(struct lm75_softc) | ||||
}; | }; | ||||
#ifdef FDT | |||||
static struct ofw_compat_data compat_data[] = { | |||||
{"national,lm75", BITS_9}, | |||||
{"ti,lm75", BITS_9}, | |||||
{0,0} | |||||
}; | |||||
#endif | |||||
DRIVER_MODULE(lm75, iicbus, lm75_driver, 0, 0); | DRIVER_MODULE(lm75, iicbus, lm75_driver, 0, 0); | ||||
static int | static int | ||||
lm75_read(device_t dev, uint32_t addr, uint8_t reg, uint8_t *data, size_t len) | lm75_read(device_t dev, uint32_t addr, uint8_t reg, uint8_t *data, size_t len) | ||||
{ | { | ||||
struct iic_msg msg[2] = { | struct iic_msg msg[2] = { | ||||
{ addr, IIC_M_WR | IIC_M_NOSTOP, 1, ® }, | { addr, IIC_M_WR | IIC_M_NOSTOP, 1, ® }, | ||||
{ addr, IIC_M_RD, len, data }, | { addr, IIC_M_RD, len, data }, | ||||
Show All 16 Lines | if (iicbus_transfer(dev, msg, nitems(msg)) != 0) | ||||
return (-1); | return (-1); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
lm75_probe(device_t dev) | lm75_probe(device_t dev) | ||||
{ | { | ||||
#ifdef FDT | |||||
const struct ofw_compat_data *compat_ptr; | |||||
#endif | |||||
struct lm75_softc *sc; | struct lm75_softc *sc; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
sc->sc_hwtype = HWTYPE_LM75; | sc->sc_max_resolution = 9; | ||||
#ifdef FDT | #ifdef FDT | ||||
if (!ofw_bus_is_compatible(dev, "national,lm75")) | if (!ofw_bus_status_okay(dev)) | ||||
return (ENXIO); | return (ENXIO); | ||||
compat_ptr = ofw_bus_search_compatible(dev, compat_data); | |||||
switch (compat_ptr->ocd_data){ | |||||
case BITS_9: | |||||
sc->sc_max_resolution = 9; | |||||
break; | |||||
case BITS_11: | |||||
sc->sc_max_resolution = 11; | |||||
break; | |||||
default: | |||||
return (ENXIO); | |||||
} | |||||
#endif | #endif | ||||
device_set_desc(dev, "LM75 temperature sensor"); | device_set_desc(dev, "LM75 temperature sensor"); | ||||
return (BUS_PROBE_GENERIC); | return (BUS_PROBE_GENERIC); | ||||
} | } | ||||
static int | static int | ||||
lm75_attach(device_t dev) | lm75_attach(device_t dev) | ||||
{ | { | ||||
struct lm75_softc *sc; | struct lm75_softc *sc; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
sc->sc_dev = dev; | sc->sc_dev = dev; | ||||
sc->sc_addr = iicbus_get_addr(dev); | sc->sc_addr = iicbus_get_addr(dev); | ||||
sc->enum_hook.ich_func = lm75_start; | sc->enum_hook.ich_func = lm75_start; | ||||
sc->enum_hook.ich_arg = dev; | sc->enum_hook.ich_arg = dev; | ||||
switch (sc->sc_max_resolution) { | |||||
case 9: | |||||
sc->sc_resolution = 9; | |||||
sc->sc_max_resolution = 9; | |||||
sc->sc_multiplier = 10; | |||||
break; | |||||
case 11: | |||||
sc->sc_resolution = 11; | |||||
sc->sc_max_resolution = 11; | |||||
sc->sc_multiplier = 1000; | |||||
break; | |||||
default: | |||||
return (ENXIO); | |||||
} | |||||
/* | /* | ||||
* We have to wait until interrupts are enabled. Usually I2C read | * We have to wait until interrupts are enabled. Usually I2C read | ||||
* and write only works when the interrupts are available. | * and write only works when the interrupts are available. | ||||
*/ | */ | ||||
if (config_intrhook_establish(&sc->enum_hook) != 0) | if (config_intrhook_establish(&sc->enum_hook) != 0) | ||||
return (ENOMEM); | return (ENOMEM); | ||||
return (0); | return (0); | ||||
Show All 38 Lines | lm75_type_detect(struct lm75_softc *sc) | ||||
for (i = 4; i <= 6; i++) { | for (i = 4; i <= 6; i++) { | ||||
if (lm75_read(sc->sc_dev, sc->sc_addr, i, | if (lm75_read(sc->sc_dev, sc->sc_addr, i, | ||||
&buf8, sizeof(buf8)) < 0) | &buf8, sizeof(buf8)) < 0) | ||||
return (-1); | return (-1); | ||||
if (buf8 != LM75_TEST_PATTERN && buf8 != 0xff) | if (buf8 != LM75_TEST_PATTERN && buf8 != 0xff) | ||||
return (-1); | return (-1); | ||||
if (buf8 == 0xff) | if (buf8 == 0xff) | ||||
lm75a++; | lm75a++; | ||||
wma: blank line, remove | |||||
} | } | ||||
if (lm75a == 3) | if (lm75a == 3){ | ||||
sc->sc_hwtype = HWTYPE_LM75A; | sc->sc_multiplier = 1000; | ||||
sc->sc_resolution = 11; | |||||
sc->sc_max_resolution = 11; | |||||
} | |||||
/* Restore the configuration register. */ | /* Restore the configuration register. */ | ||||
sc->sc_conf = conf; | sc->sc_conf = conf; | ||||
if (lm75_conf_write(sc) != 0) | if (lm75_conf_write(sc) != 0) | ||||
return (-1); | return (-1); | ||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
lm75_start(void *xdev) | lm75_start(void *xdev) | ||||
{ | { | ||||
device_t dev; | device_t dev; | ||||
struct lm75_softc *sc; | struct lm75_softc *sc; | ||||
struct sysctl_ctx_list *ctx; | struct sysctl_ctx_list *ctx; | ||||
struct sysctl_oid *tree_node; | struct sysctl_oid *tree_node; | ||||
struct sysctl_oid_list *tree; | struct sysctl_oid_list *tree; | ||||
char *mult_format; | |||||
dev = (device_t)xdev; | dev = (device_t)xdev; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
ctx = device_get_sysctl_ctx(dev); | ctx = device_get_sysctl_ctx(dev); | ||||
tree_node = device_get_sysctl_tree(dev); | tree_node = device_get_sysctl_tree(dev); | ||||
tree = SYSCTL_CHILDREN(tree_node); | tree = SYSCTL_CHILDREN(tree_node); | ||||
config_intrhook_disestablish(&sc->enum_hook); | config_intrhook_disestablish(&sc->enum_hook); | ||||
/* | /* | ||||
* Detect the kind of chip we are attaching to. | * Detect the kind of chip we are attaching to. | ||||
* This may not work for LM75 clones. | * This may not work for LM75 clones. | ||||
*/ | */ | ||||
if (lm75_type_detect(sc) != 0) { | if (sc->sc_max_resolution == 9) | ||||
wmaUnsubmitted Not Done Inline ActionsI would invert logic here. If lm75_type_detect fails, use width guessed by fdt compat - that method is the one which we trust the least. If there is no fdt then fail immediately. wma: I would invert logic here. If lm75_type_detect fails, use width guessed by fdt compat - that… | |||||
device_printf(dev, "cannot read from sensor.\n"); | lm75_type_detect(sc); | ||||
return; | if (sc->sc_max_resolution == 11) | ||||
} | device_printf(dev,"11 bit resolution sensor detected.\n"); | ||||
wmaUnsubmitted Not Done Inline ActionsAnyway, I think it would be much more meaningful to always print number of bits detected. Right now we've got two ways of resolving that number (plus sysctl to change it) so the user should always know what had been set automatically. wma: Anyway, I think it would be much more meaningful to always print number of bits detected. Right… | |||||
if (sc->sc_hwtype == HWTYPE_LM75A) | |||||
device_printf(dev, | |||||
"LM75A type sensor detected (11bits resolution).\n"); | |||||
if (sc->sc_multiplier == 1000) | |||||
mult_format = "IK3"; | |||||
else | |||||
mult_format = "IK"; | |||||
/* Temperature. */ | /* Temperature. */ | ||||
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "temperature", | SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "temperature", | ||||
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, LM75_TEMP, | CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, LM75_TEMP, | ||||
lm75_temp_sysctl, "IK", "Current temperature"); | lm75_temp_sysctl, mult_format, "Current temperature"); | ||||
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "thyst", | SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "thyst", | ||||
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev, LM75_THYST, | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev, LM75_THYST, | ||||
lm75_temp_sysctl, "IK", "Hysteresis temperature"); | lm75_temp_sysctl, mult_format, "Hysteresis temperature"); | ||||
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "tos", | SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "tos", | ||||
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev, LM75_TOS, | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev, LM75_TOS, | ||||
lm75_temp_sysctl, "IK", "Overtemperature"); | lm75_temp_sysctl, mult_format, "Overtemperature"); | ||||
/* Configuration parameters. */ | /* Configuration parameters. */ | ||||
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "faults", | SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "faults", | ||||
CTLFLAG_RW | CTLTYPE_UINT | CTLFLAG_MPSAFE, dev, 0, | CTLFLAG_RW | CTLTYPE_UINT | CTLFLAG_MPSAFE, dev, 0, | ||||
lm75_faults_sysctl, "IU", "LM75 fault queue"); | lm75_faults_sysctl, "IU", "LM75 fault queue"); | ||||
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "mode", | SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "mode", | ||||
CTLFLAG_RW | CTLTYPE_STRING | CTLFLAG_MPSAFE, dev, 0, | CTLFLAG_RW | CTLTYPE_STRING | CTLFLAG_MPSAFE, dev, 0, | ||||
lm75_mode_sysctl, "A", "LM75 mode"); | lm75_mode_sysctl, "A", "LM75 mode"); | ||||
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "polarity", | SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "polarity", | ||||
CTLFLAG_RW | CTLTYPE_STRING | CTLFLAG_MPSAFE, dev, 0, | CTLFLAG_RW | CTLTYPE_STRING | CTLFLAG_MPSAFE, dev, 0, | ||||
lm75_pol_sysctl, "A", "LM75 OS polarity"); | lm75_pol_sysctl, "A", "LM75 OS polarity"); | ||||
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "shutdown", | SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "shutdown", | ||||
CTLFLAG_RW | CTLTYPE_UINT | CTLFLAG_MPSAFE, dev, 0, | CTLFLAG_RW | CTLTYPE_UINT | CTLFLAG_MPSAFE, dev, 0, | ||||
lm75_shutdown_sysctl, "IU", "LM75 shutdown"); | lm75_shutdown_sysctl, "IU", "LM75 shutdown"); | ||||
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "resolution", | |||||
CTLFLAG_RW | CTLTYPE_INT | CTLFLAG_MPSAFE, dev, 0, | |||||
lm75_resolution_sysctl, "IU", "LM75 resolution"); | |||||
} | } | ||||
static int | static int | ||||
lm75_conf_read(struct lm75_softc *sc) | lm75_conf_read(struct lm75_softc *sc) | ||||
{ | { | ||||
uint8_t buf8; | uint8_t buf8; | ||||
if (lm75_read(sc->sc_dev, sc->sc_addr, LM75_CONF, | if (lm75_read(sc->sc_dev, sc->sc_addr, LM75_CONF, | ||||
Show All 13 Lines | lm75_conf_write(struct lm75_softc *sc) | ||||
buf8[1] = (uint8_t)sc->sc_conf & LM75_CONF_MASK; | buf8[1] = (uint8_t)sc->sc_conf & LM75_CONF_MASK; | ||||
if (lm75_write(sc->sc_dev, sc->sc_addr, buf8, sizeof(buf8)) < 0) | if (lm75_write(sc->sc_dev, sc->sc_addr, buf8, sizeof(buf8)) < 0) | ||||
return (-1); | return (-1); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
lm75_temp_read(struct lm75_softc *sc, uint8_t reg, int *temp) | lm75_temp_read(struct lm75_softc *sc, uint8_t reg, int32_t *temp) | ||||
{ | { | ||||
int32_t buf; | |||||
uint8_t buf8[2]; | uint8_t buf8[2]; | ||||
uint16_t buf; | uint8_t resolution = sc->sc_resolution; | ||||
int neg, t; | uint16_t multiplier = sc->sc_multiplier; | ||||
if (lm75_read(sc->sc_dev, sc->sc_addr, reg, buf8, sizeof(buf8)) < 0) | if (lm75_read(sc->sc_dev, sc->sc_addr, reg, buf8, sizeof(buf8)) < 0) | ||||
return (-1); | return (-1); | ||||
buf = (uint16_t)((buf8[0] << 8) | (buf8[1] & 0xff)); | |||||
/* | |||||
* LM75 has a 9 bit ADC with resolution of 0.5 C per bit. | |||||
* LM75A has an 11 bit ADC with resolution of 0.125 C per bit. | |||||
* Temperature is stored with two's complement. | |||||
*/ | |||||
neg = 0; | |||||
if (buf & LM75_NEG_BIT) { | |||||
if (sc->sc_hwtype == HWTYPE_LM75A) | |||||
buf = ~(buf & LM75A_TEMP_MASK) + 1; | |||||
else | |||||
buf = ~(buf & LM75_TEMP_MASK) + 1; | |||||
neg = 1; | |||||
} | |||||
*temp = ((int16_t)buf >> 8) * 10; | |||||
t = 0; | |||||
if (sc->sc_hwtype == HWTYPE_LM75A) { | |||||
if (buf & LM75_0125C) | |||||
t += 125; | |||||
if (buf & LM75_0250C) | |||||
t += 250; | |||||
} | |||||
if (buf & LM75_0500C) | |||||
t += 500; | |||||
t /= 100; | |||||
*temp += t; | |||||
if (neg) | |||||
*temp = -(*temp); | |||||
*temp += TZ_ZEROC; | |||||
buf = (int16_t)((buf8[0] << 8) | buf8[1]); | |||||
*temp = ((buf >> (16 - resolution)) * multiplier) >> (resolution - 8); | |||||
*temp += TZ_ZEROC * sc->sc_multiplier / TZ_ZEROC_DIVIDER; | |||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
lm75_temp_write(struct lm75_softc *sc, uint8_t reg, int temp) | lm75_temp_write(struct lm75_softc *sc, uint8_t reg, int32_t temp) | ||||
{ | { | ||||
uint8_t buf8[3]; | int32_t buf; | ||||
uint16_t buf; | uint8_t buf8[3], resolution = sc->sc_resolution; | ||||
uint16_t multiplier = sc->sc_multiplier; | |||||
temp = (temp - TZ_ZEROC) / 10; | temp -= TZ_ZEROC * multiplier / TZ_ZEROC_DIVIDER; | ||||
if (temp > LM75_MAX_TEMP) | if (temp > LM75_MAX_TEMP * multiplier) | ||||
temp = LM75_MAX_TEMP; | temp = LM75_MAX_TEMP * multiplier; | ||||
if (temp < LM75_MIN_TEMP) | if (temp < LM75_MIN_TEMP * multiplier) | ||||
temp = LM75_MIN_TEMP; | temp = LM75_MIN_TEMP * multiplier; | ||||
buf = (uint16_t)temp; | buf = ((temp << (resolution - 8)) / multiplier) << (16 - resolution); | ||||
buf <<= 8; | |||||
buf8[0] = reg; | buf8[0] = reg; | ||||
buf8[1] = buf >> 8; | buf8[1] = (buf >> 8) & 0xff; | ||||
buf8[2] = buf & 0xff; | buf8[2] = buf & 0xff; | ||||
if (lm75_write(sc->sc_dev, sc->sc_addr, buf8, sizeof(buf8)) < 0) | if (lm75_write(sc->sc_dev, sc->sc_addr, buf8, sizeof(buf8)) < 0) | ||||
return (-1); | return (-1); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
lm75_str_mode(char *buf) | lm75_str_mode(char *buf) | ||||
Show All 28 Lines | lm75_str_pol(char *buf) | ||||
return (rtrn); | return (rtrn); | ||||
} | } | ||||
static int | static int | ||||
lm75_temp_sysctl(SYSCTL_HANDLER_ARGS) | lm75_temp_sysctl(SYSCTL_HANDLER_ARGS) | ||||
{ | { | ||||
device_t dev; | device_t dev; | ||||
int error, temp; | int error; | ||||
int32_t temp; | |||||
struct lm75_softc *sc; | struct lm75_softc *sc; | ||||
uint8_t reg; | uint8_t reg; | ||||
dev = (device_t)arg1; | dev = (device_t)arg1; | ||||
reg = (uint8_t)arg2; | reg = (uint8_t)arg2; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
if (lm75_temp_read(sc, reg, &temp) != 0) | if (lm75_temp_read(sc, reg, &temp) != 0) | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | if (shutdown != tmp) { | ||||
sc->sc_conf &= ~LM75_CONF_SHUTD; | sc->sc_conf &= ~LM75_CONF_SHUTD; | ||||
if (shutdown) | if (shutdown) | ||||
sc->sc_conf |= LM75_CONF_SHUTD; | sc->sc_conf |= LM75_CONF_SHUTD; | ||||
if (lm75_conf_write(sc) != 0) | if (lm75_conf_write(sc) != 0) | ||||
return (EIO); | return (EIO); | ||||
} | } | ||||
return (error); | return (error); | ||||
} | |||||
static int | |||||
lm75_resolution_sysctl(SYSCTL_HANDLER_ARGS) | |||||
{ | |||||
device_t dev; | |||||
int error; | |||||
struct lm75_softc *sc; | |||||
int resolution; | |||||
dev = (device_t)arg1; | |||||
sc = device_get_softc(dev); | |||||
resolution = sc->sc_resolution; | |||||
error = sysctl_handle_int(oidp, &resolution, 0, req); | |||||
if (error != 0 || req->newptr == NULL) | |||||
return (error); | |||||
if (resolution > sc->sc_max_resolution || resolution < 9) | |||||
return (EINVAL); | |||||
sc->sc_resolution = (uint8_t) resolution; | |||||
return (0); | |||||
} | } |
blank line, remove