drivers/hwmon/lm85.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/lm85.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/lm85.c- Extension
.c- Size
- 50249 bytes
- Lines
- 1709
- 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/module.hlinux/of.hlinux/init.hlinux/slab.hlinux/jiffies.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-vid.hlinux/hwmon-sysfs.hlinux/err.hlinux/mutex.hlinux/util_macros.h
Detected Declarations
struct lm85_zonestruct lm85_autofanstruct lm85_dataenum chipsfunction SCALEfunction RANGE_TO_REGfunction FREQ_TO_REGfunction FREQ_FROM_REGfunction ZONE_TO_REGfunction lm85_read_valuefunction lm85_write_valuefunction fan_showfunction fan_min_showfunction fan_min_storefunction cpu0_vid_showfunction vrm_showfunction vrm_storefunction alarms_showfunction alarm_showfunction pwm_showfunction pwm_storefunction pwm_enable_showfunction pwm_enable_storefunction pwm_freq_showfunction pwm_freq_storefunction in_showfunction in_min_showfunction in_min_storefunction in_max_showfunction in_max_storefunction temp_showfunction temp_min_showfunction temp_min_storefunction temp_max_showfunction temp_max_storefunction pwm_auto_channels_showfunction pwm_auto_channels_storefunction pwm_auto_pwm_min_showfunction pwm_auto_pwm_min_storefunction pwm_auto_pwm_minctl_showfunction pwm_auto_pwm_minctl_storefunction temp_auto_temp_off_showfunction temp_auto_temp_off_storefunction temp_auto_temp_min_showfunction temp_auto_temp_min_storefunction temp_auto_temp_max_showfunction temp_auto_temp_max_storefunction temp_auto_temp_crit_show
Annotated Snippet
struct lm85_zone {
s8 limit; /* Low temp limit */
u8 hyst; /* Low limit hysteresis. (0-15) */
u8 range; /* Temp range, encoded */
s8 critical; /* "All fans ON" temp limit */
u8 max_desired; /*
* Actual "max" temperature specified. Preserved
* to prevent "drift" as other autofan control
* values change.
*/
};
struct lm85_autofan {
u8 config; /* Register value */
u8 min_pwm; /* Minimum PWM value, encoded */
u8 min_off; /* Min PWM or OFF below "limit", flag */
};
/*
* For each registered chip, we need to keep some data in memory.
* The structure is dynamically allocated.
*/
struct lm85_data {
struct i2c_client *client;
const struct attribute_group *groups[6];
const int *freq_map;
unsigned int freq_map_size;
enum chips type;
bool has_vid5; /* true if VID5 is configured for ADT7463 or ADT7468 */
struct mutex update_lock;
bool valid; /* true if following fields are valid */
unsigned long last_reading; /* In jiffies */
unsigned long last_config; /* In jiffies */
u8 in[8]; /* Register value */
u8 in_max[8]; /* Register value */
u8 in_min[8]; /* Register value */
s8 temp[3]; /* Register value */
s8 temp_min[3]; /* Register value */
s8 temp_max[3]; /* Register value */
u16 fan[4]; /* Register value */
u16 fan_min[4]; /* Register value */
u8 pwm[3]; /* Register value */
u8 pwm_freq[3]; /* Register encoding */
u8 temp_ext[3]; /* Decoded values */
u8 in_ext[8]; /* Decoded values */
u8 vid; /* Register value */
u8 vrm; /* VRM version */
u32 alarms; /* Register encoding, combined */
u8 cfg5; /* Config Register 5 on ADT7468 */
struct lm85_autofan autofan[3];
struct lm85_zone zone[3];
};
static int lm85_read_value(struct i2c_client *client, u8 reg)
{
int res;
/* What size location is it? */
switch (reg) {
case LM85_REG_FAN(0): /* Read WORD data */
case LM85_REG_FAN(1):
case LM85_REG_FAN(2):
case LM85_REG_FAN(3):
case LM85_REG_FAN_MIN(0):
case LM85_REG_FAN_MIN(1):
case LM85_REG_FAN_MIN(2):
case LM85_REG_FAN_MIN(3):
case LM85_REG_ALARM1: /* Read both bytes at once */
res = i2c_smbus_read_byte_data(client, reg) & 0xff;
res |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
break;
default: /* Read BYTE data */
res = i2c_smbus_read_byte_data(client, reg);
break;
}
return res;
}
static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
{
switch (reg) {
case LM85_REG_FAN(0): /* Write WORD data */
case LM85_REG_FAN(1):
case LM85_REG_FAN(2):
case LM85_REG_FAN(3):
Annotation
- Immediate include surface: `linux/module.h`, `linux/of.h`, `linux/init.h`, `linux/slab.h`, `linux/jiffies.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-vid.h`.
- Detected declarations: `struct lm85_zone`, `struct lm85_autofan`, `struct lm85_data`, `enum chips`, `function SCALE`, `function RANGE_TO_REG`, `function FREQ_TO_REG`, `function FREQ_FROM_REG`, `function ZONE_TO_REG`, `function lm85_read_value`.
- 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.