drivers/hwmon/tmp103.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/tmp103.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/tmp103.c- Extension
.c- Size
- 5133 bytes
- Lines
- 223
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/init.hlinux/slab.hlinux/i2c.hlinux/hwmon.hlinux/err.hlinux/device.hlinux/regmap.h
Detected Declarations
function Copyrightfunction tmp103_mc_to_regfunction tmp103_readfunction tmp103_writefunction tmp103_is_visiblefunction tmp103_regmap_is_volatilefunction tmp103_probefunction tmp103_suspendfunction tmp103_resume
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Texas Instruments TMP103 SMBus temperature sensor driver
* Copyright (C) 2014 Heiko Schocher <hs@denx.de>
*
* Based on:
* Texas Instruments TMP102 SMBus temperature sensor driver
*
* Copyright (C) 2010 Steven King <sfking@fdwdc.com>
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/hwmon.h>
#include <linux/err.h>
#include <linux/device.h>
#include <linux/regmap.h>
#define TMP103_TEMP_REG 0x00
#define TMP103_CONF_REG 0x01
#define TMP103_TLOW_REG 0x02
#define TMP103_THIGH_REG 0x03
#define TMP103_CONF_M0 0x01
#define TMP103_CONF_M1 0x02
#define TMP103_CONF_LC 0x04
#define TMP103_CONF_FL 0x08
#define TMP103_CONF_FH 0x10
#define TMP103_CONF_CR0 0x20
#define TMP103_CONF_CR1 0x40
#define TMP103_CONF_ID 0x80
#define TMP103_CONF_SD (TMP103_CONF_M1)
#define TMP103_CONF_SD_MASK (TMP103_CONF_M0 | TMP103_CONF_M1)
#define TMP103_CONFIG (TMP103_CONF_CR1 | TMP103_CONF_M1)
#define TMP103_CONFIG_MASK (TMP103_CONF_CR0 | TMP103_CONF_CR1 | \
TMP103_CONF_M0 | TMP103_CONF_M1)
static inline int tmp103_reg_to_mc(s8 val)
{
return val * 1000;
}
static inline u8 tmp103_mc_to_reg(int val)
{
return DIV_ROUND_CLOSEST(val, 1000);
}
static int tmp103_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *temp)
{
struct regmap *regmap = dev_get_drvdata(dev);
unsigned int regval;
int err, reg;
switch (attr) {
case hwmon_temp_input:
reg = TMP103_TEMP_REG;
break;
case hwmon_temp_min:
reg = TMP103_TLOW_REG;
break;
case hwmon_temp_max:
reg = TMP103_THIGH_REG;
break;
default:
return -EOPNOTSUPP;
}
err = regmap_read(regmap, reg, ®val);
if (err < 0)
return err;
*temp = tmp103_reg_to_mc(regval);
return 0;
}
static int tmp103_write(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long temp)
{
struct regmap *regmap = dev_get_drvdata(dev);
int reg;
switch (attr) {
case hwmon_temp_min:
reg = TMP103_TLOW_REG;
break;
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/err.h`, `linux/device.h`, `linux/regmap.h`.
- Detected declarations: `function Copyright`, `function tmp103_mc_to_reg`, `function tmp103_read`, `function tmp103_write`, `function tmp103_is_visible`, `function tmp103_regmap_is_volatile`, `function tmp103_probe`, `function tmp103_suspend`, `function tmp103_resume`.
- Atlas domain: Driver Families / drivers/hwmon.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.