drivers/hwmon/adt7475.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/adt7475.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/adt7475.c- Extension
.c- Size
- 58185 bytes
- Lines
- 2219
- 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/init.hlinux/slab.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/hwmon-vid.hlinux/err.hlinux/jiffies.hlinux/of.hlinux/mod_devicetable.hlinux/property.hlinux/util_macros.hdt-bindings/pwm/pwm.h
Detected Declarations
struct adt7475_datastruct adt7475_pwm_configenum adt_sysfs_idenum chipsfunction temp2regfunction reg2tempfunction tach2rpmfunction rpm2tachfunction reg2voltfunction volt2regfunction adt7475_read_wordfunction adt7475_write_wordfunction voltage_showfunction voltage_storefunction temp_showfunction temp_storefunction temp_st_showfunction temp_st_storefunction point2_showfunction point2_storefunction tach_showfunction tach_storefunction pwm_showfunction pwmchan_showfunction pwmctrl_showfunction pwm_storefunction stall_disable_showfunction stall_disable_storefunction hw_set_pwmfunction pwmchan_storefunction pwmctrl_storefunction pwmfreq_showfunction pwmfreq_storefunction pwm_use_point2_pwm_at_crit_showfunction pwm_use_point2_pwm_at_crit_storefunction vrm_showfunction vrm_storefunction cpu0_vid_showfunction adt7475_detectfunction adt7475_update_limitsfunction load_config3function load_config4function load_configfunction set_property_bitfunction load_attenuatorsfunction adt7475_set_pwm_polarityfunction _adt7475_pwm_properties_parse_argsfunction adt7475_pwm_properties_parse_reference_args
Annotated Snippet
struct adt7475_data {
struct i2c_client *client;
struct mutex lock;
unsigned long measure_updated;
bool valid;
u8 config2;
u8 config4;
u8 config5;
u8 has_voltage;
u8 bypass_attn; /* Bypass voltage attenuator */
u8 has_pwm2:1;
u8 has_fan4:1;
u8 has_vid:1;
u32 alarms;
u16 voltage[3][7];
u16 temp[7][3];
u16 tach[2][4];
u8 pwm[4][3];
u8 range[3];
u8 pwmctl[3];
u8 pwmchan[3];
u8 enh_acoustics[2];
u8 vid;
u8 vrm;
const struct attribute_group *groups[10];
};
static struct i2c_driver adt7475_driver;
static struct adt7475_data *adt7475_update_device(struct device *dev);
static void adt7475_read_hystersis(struct i2c_client *client);
static void adt7475_read_pwm(struct i2c_client *client, int index);
/* Given a temp value, convert it to register value */
static inline u16 temp2reg(struct adt7475_data *data, long val)
{
u16 ret;
if (!(data->config5 & CONFIG5_TWOSCOMP)) {
val = clamp_val(val, -64000, 191000);
ret = (val + 64500) / 1000;
} else {
val = clamp_val(val, -128000, 127000);
if (val < -500)
ret = (256500 + val) / 1000;
else
ret = (val + 500) / 1000;
}
return ret << 2;
}
/* Given a register value, convert it to a real temp value */
static inline int reg2temp(struct adt7475_data *data, u16 reg)
{
if (data->config5 & CONFIG5_TWOSCOMP) {
if (reg >= 512)
return (reg - 1024) * 250;
else
return reg * 250;
} else
return (reg - 256) * 250;
}
static inline int tach2rpm(u16 tach)
{
if (tach == 0 || tach == 0xFFFF)
return 0;
return (90000 * 60) / tach;
}
static inline u16 rpm2tach(unsigned long rpm)
{
if (rpm == 0)
return 0;
return clamp_val((90000 * 60) / rpm, 1, 0xFFFF);
}
/* Scaling factors for voltage inputs, taken from the ADT7490 datasheet */
static const int adt7473_in_scaling[ADT7475_VOLTAGE_COUNT + 2][2] = {
{ 45, 94 }, /* +2.5V */
{ 175, 525 }, /* Vccp */
{ 68, 71 }, /* Vcc */
{ 93, 47 }, /* +5V */
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/hwmon-vid.h`, `linux/err.h`.
- Detected declarations: `struct adt7475_data`, `struct adt7475_pwm_config`, `enum adt_sysfs_id`, `enum chips`, `function temp2reg`, `function reg2temp`, `function tach2rpm`, `function rpm2tach`, `function reg2volt`, `function volt2reg`.
- 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.