31#include "opt_platform.h"
35#include <sys/module.h>
37#include <sys/kernel.h>
38#include <sys/libkern.h>
39#include <sys/sysctl.h>
44#include <dev/ofw/ofw_bus_subr.h>
45#include <dev/ofw/ofw_bus.h>
47#define BIT(x) (1UL << (x))
49#define TMP461_LOCAL_TEMP_REG_MSB 0x0
50#define TMP461_LOCAL_TEMP_REG_LSB 0x15
51#define TMP461_GLOBAL_TEMP_REG_MSB 0x1
52#define TMP461_GLOBAL_TEMP_REG_LSB 0x10
53#define TMP461_CONFIG_REG 0x3
54#define TMP461_CONFIG_REG_TEMP_RANGE_BIT BIT(2)
56#define TMP461_EXTENDED_TEMP_MODIFIER 64
58#define TMP461_C_TO_K_FIX 4370
59#define TMP461_TEMP_LSB 0
96 struct sysctl_oid *sensor_root_oid;
97 struct sysctl_ctx_list *ctx;
99 ctx = device_get_sysctl_ctx(
dev);
101 sensor_root_oid = SYSCTL_ADD_NODE(ctx, SYSCTL_STATIC_CHILDREN(_hw),
102 OID_AUTO,
"temperature", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL,
103 "TMP 461 Thermal Sensor Information");
104 if (sensor_root_oid == NULL)
107 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(sensor_root_oid), OID_AUTO,
108 "tmp461", CTLTYPE_INT | CTLFLAG_RD,
dev, 0,
118 if (!ofw_bus_status_okay(
dev))
124 device_set_desc(
dev,
"TMP461 Thermal Sensor");
126 return (BUS_PROBE_GENERIC);
143 device_printf(
dev,
"Failed to read from device\n");
192 return (sysctl_handle_int(oidp, &temp, 0, req));
int iicdev_readfrom(device_t slavedev, uint8_t regaddr, void *buffer, uint16_t buflen, int waithow)
static device_method_t tmp461_methods[]
static int tmp461_probe(device_t dev)
static int tmp461_read_1(device_t dev, uint8_t reg, uint8_t *data)
IICBUS_FDT_PNP_INFO(tmp461_compat_data)
#define TMP461_CONFIG_REG_TEMP_RANGE_BIT
static int tmp461_sensor_sysctl(SYSCTL_HANDLER_ARGS)
#define TMP461_LOCAL_TEMP_REG_LSB
static int tmp461_detach(device_t dev)
static struct ofw_compat_data tmp461_compat_data[]
#define TMP461_C_TO_K_FIX
#define TMP461_EXTENDED_TEMP_MODIFIER
DRIVER_MODULE(tmp461, iicbus, tmp461_driver, tmp461_devclass, 0, 0)
static int tmp461_read_temp(device_t dev, int32_t *temp)
static int tmp461_attach(device_t dev)
#define TMP461_CONFIG_REG
static int32_t tmp461_signed_extend32(uint32_t value, int sign_pos)
#define TMP461_LOCAL_TEMP_REG_MSB
static devclass_t tmp461_devclass
static driver_t tmp461_driver