drivers/hwmon/tmp102.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/tmp102.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/tmp102.c- Extension
.c- Size
- 10069 bytes
- Lines
- 423
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/module.hlinux/init.hlinux/slab.hlinux/i2c.hlinux/hwmon.hlinux/err.hlinux/device.hlinux/jiffies.hlinux/regmap.hlinux/regulator/consumer.hlinux/mod_devicetable.hlinux/property.h
Detected Declarations
struct tmp102function Copyrightfunction tmp102_reg_to_mCfunction tmp102_mC_to_regfunction tmp102_read_stringfunction tmp102_read_chipfunction tmp102_read_tempfunction tmp102_readfunction tmp102_update_intervalfunction tmp102_write_chipfunction tmp102_write_tempfunction tmp102_writefunction tmp102_is_visiblefunction tmp102_restore_configfunction tmp102_is_writeable_regfunction tmp102_is_volatile_regfunction tmp102_probefunction tmp102_suspendfunction tmp102_resume
Annotated Snippet
struct tmp102 {
const char *label;
struct regmap *regmap;
u16 config_orig;
unsigned long ready_time;
u16 sample_time;
};
/* convert left adjusted 13-bit TMP102 register value to milliCelsius */
static inline int tmp102_reg_to_mC(s16 val)
{
return ((val & ~0x01) * 1000) / 128;
}
/* convert milliCelsius to left adjusted 13-bit TMP102 register value */
static inline u16 tmp102_mC_to_reg(int val)
{
return (val * 128) / 1000;
}
static int tmp102_read_string(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, const char **str)
{
struct tmp102 *tmp102 = dev_get_drvdata(dev);
*str = tmp102->label;
return 0;
}
static int tmp102_read_chip(struct device *dev, u32 attr, long *val)
{
struct tmp102 *tmp102 = dev_get_drvdata(dev);
switch (attr) {
case hwmon_chip_update_interval:
*val = tmp102->sample_time;
return 0;
default:
return -EOPNOTSUPP;
}
}
static int tmp102_read_temp(struct device *dev, u32 attr, long *val)
{
struct tmp102 *tmp102 = dev_get_drvdata(dev);
unsigned int regval;
int err, reg;
switch (attr) {
case hwmon_temp_input:
/* Is it too early to return a conversion ? */
if (time_before(jiffies, tmp102->ready_time)) {
dev_dbg(dev, "%s: Conversion not ready yet..\n", __func__);
return -EAGAIN;
}
reg = TMP102_TEMP_REG;
break;
case hwmon_temp_max_hyst:
reg = TMP102_TLOW_REG;
break;
case hwmon_temp_max:
reg = TMP102_THIGH_REG;
break;
default:
return -EOPNOTSUPP;
}
err = regmap_read(tmp102->regmap, reg, ®val);
if (err < 0)
return err;
*val = tmp102_reg_to_mC(regval);
return 0;
}
static int tmp102_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
switch (type) {
case hwmon_chip:
return tmp102_read_chip(dev, attr, val);
case hwmon_temp:
return tmp102_read_temp(dev, attr, val);
default:
return -EOPNOTSUPP;
}
}
Annotation
- Immediate include surface: `linux/delay.h`, `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/err.h`, `linux/device.h`.
- Detected declarations: `struct tmp102`, `function Copyright`, `function tmp102_reg_to_mC`, `function tmp102_mC_to_reg`, `function tmp102_read_string`, `function tmp102_read_chip`, `function tmp102_read_temp`, `function tmp102_read`, `function tmp102_update_interval`, `function tmp102_write_chip`.
- 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.