drivers/hwmon/spd5118.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/spd5118.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/spd5118.c- Extension
.c- Size
- 20235 bytes
- Lines
- 779
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/bitops.hlinux/bits.hlinux/err.hlinux/i2c.hlinux/hwmon.hlinux/module.hlinux/mutex.hlinux/nvmem-provider.hlinux/pm.hlinux/regmap.hlinux/units.h
Detected Declarations
struct spd5118_datafunction spd5118_temp_from_regfunction spd5118_temp_to_regfunction spd5118_read_tempfunction spd5118_read_alarmfunction spd5118_read_enablefunction spd5118_readfunction spd5118_write_tempfunction spd5118_write_enablefunction spd5118_temp_writefunction spd5118_writefunction spd5118_is_visiblefunction spd5118_vendor_validfunction spd5118_nvmem_read_pagefunction spd5118_nvmem_readfunction spd5118_nvmem_initfunction spd5118_writeable_regfunction spd5118_volatile_regfunction spd5118_suspendfunction spd5118_resumefunction spd5118_common_probefunction spd5118_detectfunction spd5118_i2c_initfunction i2c_smbus_read_byte
Annotated Snippet
struct spd5118_data {
struct regmap *regmap;
struct mutex nvmem_lock;
bool is_16bit;
};
/* hwmon */
static int spd5118_temp_from_reg(u16 reg)
{
int temp = sign_extend32(reg >> 2, 10);
return temp * SPD5118_TEMP_UNIT;
}
static u16 spd5118_temp_to_reg(long temp)
{
temp = clamp_val(temp, SPD5118_TEMP_RANGE_MIN, SPD5118_TEMP_RANGE_MAX);
return (DIV_ROUND_CLOSEST(temp, SPD5118_TEMP_UNIT) & 0x7ff) << 2;
}
static int spd5118_read_temp(struct regmap *regmap, u32 attr, long *val)
{
int reg, err;
u8 regval[2];
u16 temp;
switch (attr) {
case hwmon_temp_input:
reg = SPD5118_REG_TEMP;
break;
case hwmon_temp_max:
reg = SPD5118_REG_TEMP_MAX;
break;
case hwmon_temp_min:
reg = SPD5118_REG_TEMP_MIN;
break;
case hwmon_temp_crit:
reg = SPD5118_REG_TEMP_CRIT;
break;
case hwmon_temp_lcrit:
reg = SPD5118_REG_TEMP_LCRIT;
break;
default:
return -EOPNOTSUPP;
}
err = regmap_bulk_read(regmap, reg, regval, 2);
if (err)
return err;
temp = (regval[1] << 8) | regval[0];
*val = spd5118_temp_from_reg(temp);
return 0;
}
static int spd5118_read_alarm(struct regmap *regmap, u32 attr, long *val)
{
unsigned int mask, regval;
int err;
switch (attr) {
case hwmon_temp_max_alarm:
mask = SPD5118_TEMP_STATUS_HIGH;
break;
case hwmon_temp_min_alarm:
mask = SPD5118_TEMP_STATUS_LOW;
break;
case hwmon_temp_crit_alarm:
mask = SPD5118_TEMP_STATUS_CRIT;
break;
case hwmon_temp_lcrit_alarm:
mask = SPD5118_TEMP_STATUS_LCRIT;
break;
default:
return -EOPNOTSUPP;
}
err = regmap_read(regmap, SPD5118_REG_TEMP_STATUS, ®val);
if (err < 0)
return err;
*val = !!(regval & mask);
if (*val)
return regmap_write(regmap, SPD5118_REG_TEMP_CLR, mask);
return 0;
}
static int spd5118_read_enable(struct regmap *regmap, long *val)
{
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/bits.h`, `linux/err.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/module.h`, `linux/mutex.h`, `linux/nvmem-provider.h`.
- Detected declarations: `struct spd5118_data`, `function spd5118_temp_from_reg`, `function spd5118_temp_to_reg`, `function spd5118_read_temp`, `function spd5118_read_alarm`, `function spd5118_read_enable`, `function spd5118_read`, `function spd5118_write_temp`, `function spd5118_write_enable`, `function spd5118_temp_write`.
- Atlas domain: Driver Families / drivers/hwmon.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.