31#include "opt_platform.h"
35#include <sys/endian.h>
36#include <sys/kernel.h>
37#include <sys/module.h>
38#include <sys/sysctl.h>
41#include <machine/bus.h>
47#include <dev/ofw/openfirm.h>
48#include <dev/ofw/ofw_bus.h>
49#include <dev/ofw/ofw_bus_subr.h>
54#define LM75_TEMP_MASK 0xff80
55#define LM75A_TEMP_MASK 0xffe0
57#define LM75_CONF_FSHIFT 3
58#define LM75_CONF_FAULT 0x18
59#define LM75_CONF_POL 0x04
60#define LM75_CONF_MODE 0x02
61#define LM75_CONF_SHUTD 0x01
62#define LM75_CONF_MASK 0x1f
67#define LM75_TEST_PATTERN 0xa
68#define LM75_MIN_TEMP -55
69#define LM75_MAX_TEMP 125
70#define LM75_0500C 0x80
71#define LM75_0250C 0x40
72#define LM75_0125C 0x20
73#define LM75_MSB 0x8000
74#define LM75_NEG_BIT LM75_MSB
99static int lm75_read(device_t, uint32_t, uint8_t, uint8_t *,
size_t);
100static int lm75_write(device_t, uint32_t, uint8_t *,
size_t);
159 sc = device_get_softc(
dev);
162 if (!ofw_bus_is_compatible(
dev,
"national,lm75"))
165 device_set_desc(
dev,
"LM75 temperature sensor");
167 return (BUS_PROBE_GENERIC);
175 sc = device_get_softc(
dev);
186 if (config_intrhook_establish(&sc->
enum_hook) != 0)
228 for (i = 4; i <= 6; i++) {
230 &buf8,
sizeof(buf8)) < 0)
253 struct sysctl_ctx_list *ctx;
254 struct sysctl_oid *tree_node;
255 struct sysctl_oid_list *tree;
257 dev = (device_t)xdev;
258 sc = device_get_softc(
dev);
259 ctx = device_get_sysctl_ctx(
dev);
260 tree_node = device_get_sysctl_tree(
dev);
261 tree = SYSCTL_CHILDREN(tree_node);
263 config_intrhook_disestablish(&sc->
enum_hook);
270 device_printf(
dev,
"cannot read from sensor.\n");
275 "LM75A type sensor detected (11bits resolution).\n");
278 SYSCTL_ADD_PROC(ctx, tree, OID_AUTO,
"temperature",
279 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
dev,
LM75_TEMP,
281 SYSCTL_ADD_PROC(ctx, tree, OID_AUTO,
"thyst",
284 SYSCTL_ADD_PROC(ctx, tree, OID_AUTO,
"tos",
285 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
dev,
LM75_TOS,
289 SYSCTL_ADD_PROC(ctx, tree, OID_AUTO,
"faults",
290 CTLFLAG_RW | CTLTYPE_UINT | CTLFLAG_MPSAFE,
dev, 0,
292 SYSCTL_ADD_PROC(ctx, tree, OID_AUTO,
"mode",
293 CTLFLAG_RW | CTLTYPE_STRING | CTLFLAG_MPSAFE,
dev, 0,
295 SYSCTL_ADD_PROC(ctx, tree, OID_AUTO,
"polarity",
296 CTLFLAG_RW | CTLTYPE_STRING | CTLFLAG_MPSAFE,
dev, 0,
298 SYSCTL_ADD_PROC(ctx, tree, OID_AUTO,
"shutdown",
299 CTLFLAG_RW | CTLTYPE_UINT | CTLFLAG_MPSAFE,
dev, 0,
309 &buf8,
sizeof(buf8)) < 0)
338 buf = (uint16_t)((buf8[0] << 8) | (buf8[1] & 0xff));
352 *temp = ((int16_t)
buf >> 8) * 10;
383 buf = (uint16_t)temp;
388 buf8[2] =
buf & 0xff;
402 if (
len > 2 && strncasecmp(
"interrupt",
buf,
len) == 0)
404 else if (
len > 2 && strncasecmp(
"comparator",
buf,
len) == 0)
417 if (
len > 1 && strncasecmp(
"high",
buf,
len) == 0)
419 else if (
len > 1 && strncasecmp(
"low",
buf,
len) == 0)
421 else if (
len > 8 && strncasecmp(
"active-high",
buf,
len) == 0)
423 else if (
len > 8 && strncasecmp(
"active-low",
buf,
len) == 0)
437 dev = (device_t)arg1;
439 sc = device_get_softc(
dev);
444 error = sysctl_handle_int(oidp, &temp, 0, req);
445 if (error != 0 || req->newptr == NULL)
458 int lm75_faults[] = { 1, 2, 4, 6 };
459 int error, faults, i, newf, tmp;
462 dev = (device_t)arg1;
463 sc = device_get_softc(
dev);
465 if (tmp >= nitems(lm75_faults))
466 tmp = nitems(lm75_faults) - 1;
467 faults = lm75_faults[tmp];
469 error = sysctl_handle_int(oidp, &faults, 0, req);
470 if (error != 0 || req->newptr == NULL)
473 if (faults != lm75_faults[tmp]) {
475 for (i = 0; i < nitems(lm75_faults); i++)
476 if (faults >= lm75_faults[i])
478 sc->
sc_conf &= ~LM75_CONF_FAULT;
492 int error, mode, newm;
495 dev = (device_t)arg1;
496 sc = device_get_softc(
dev);
499 strlcpy(
buf,
"interrupt",
sizeof(
buf));
502 strlcpy(
buf,
"comparator",
sizeof(
buf));
505 error = sysctl_handle_string(oidp,
buf,
sizeof(
buf), req);
506 if (error != 0 || req->newptr == NULL)
510 if (newm != -1 && mode != newm) {
511 sc->
sc_conf &= ~LM75_CONF_MODE;
526 int error, newp, pol;
529 dev = (device_t)arg1;
530 sc = device_get_softc(
dev);
533 strlcpy(
buf,
"active-high",
sizeof(
buf));
536 strlcpy(
buf,
"active-low",
sizeof(
buf));
539 error = sysctl_handle_string(oidp,
buf,
sizeof(
buf), req);
540 if (error != 0 || req->newptr == NULL)
544 if (newp != -1 && pol != newp) {
559 int error, shutdown, tmp;
562 dev = (device_t)arg1;
563 sc = device_get_softc(
dev);
566 error = sysctl_handle_int(oidp, &shutdown, 0, req);
567 if (error != 0 || req->newptr == NULL)
570 if (shutdown != tmp) {
571 sc->
sc_conf &= ~LM75_CONF_SHUTD;
int iicbus_transfer(device_t bus, struct iic_msg *msgs, uint32_t nmsgs)
static int lm75_conf_read(struct lm75_softc *)
static int lm75_str_mode(char *)
DRIVER_MODULE(lm75, iicbus, lm75_driver, lm75_devclass, 0, 0)
static int lm75_mode_sysctl(SYSCTL_HANDLER_ARGS)
static int lm75_pol_sysctl(SYSCTL_HANDLER_ARGS)
static int lm75_write(device_t, uint32_t, uint8_t *, size_t)
static int lm75_temp_read(struct lm75_softc *, uint8_t, int *)
static devclass_t lm75_devclass
static int lm75_temp_write(struct lm75_softc *, uint8_t, int)
static int lm75_attach(device_t)
static int lm75_shutdown_sysctl(SYSCTL_HANDLER_ARGS)
static driver_t lm75_driver
static int lm75_temp_sysctl(SYSCTL_HANDLER_ARGS)
static int lm75_probe(device_t)
static device_method_t lm75_methods[]
static int lm75_faults_sysctl(SYSCTL_HANDLER_ARGS)
static int lm75_type_detect(struct lm75_softc *sc)
static int lm75_read(device_t, uint32_t, uint8_t, uint8_t *, size_t)
static int lm75_conf_write(struct lm75_softc *)
#define LM75_TEST_PATTERN
static void lm75_start(void *)
static int lm75_str_pol(char *)
struct intr_config_hook enum_hook