drivers/hwmon/max31790.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/max31790.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/max31790.c- Extension
.c- Size
- 13501 bytes
- Lines
- 538
- 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/err.hlinux/hwmon.hlinux/i2c.hlinux/init.hlinux/jiffies.hlinux/module.hlinux/slab.h
Detected Declarations
struct max31790_datafunction get_tach_periodfunction bits_for_tach_periodfunction max31790_read_fanfunction max31790_write_fanfunction max31790_fan_is_visiblefunction max31790_read_pwmfunction max31790_write_pwmfunction max31790_pwm_is_visiblefunction max31790_readfunction max31790_writefunction max31790_is_visiblefunction max31790_init_clientfunction max31790_probe
Annotated Snippet
struct max31790_data {
struct i2c_client *client;
bool valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */
/* register values */
u8 fan_config[NR_CHANNEL];
u8 fan_dynamics[NR_CHANNEL];
u16 fault_status;
u16 tach[NR_CHANNEL * 2];
u16 pwm[NR_CHANNEL];
u16 target_count[NR_CHANNEL];
};
static struct max31790_data *max31790_update_device(struct device *dev)
{
struct max31790_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
int i, rv;
if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
data->valid = false;
rv = i2c_smbus_read_byte_data(client,
MAX31790_REG_FAN_FAULT_STATUS1);
if (rv < 0)
return ERR_PTR(rv);
data->fault_status |= rv & 0x3F;
rv = i2c_smbus_read_byte_data(client,
MAX31790_REG_FAN_FAULT_STATUS2);
if (rv < 0)
return ERR_PTR(rv);
data->fault_status |= (rv & 0x3F) << 6;
for (i = 0; i < NR_CHANNEL; i++) {
rv = i2c_smbus_read_word_swapped(client,
MAX31790_REG_TACH_COUNT(i));
if (rv < 0)
return ERR_PTR(rv);
data->tach[i] = rv;
if (data->fan_config[i]
& MAX31790_FAN_CFG_TACH_INPUT) {
rv = i2c_smbus_read_word_swapped(client,
MAX31790_REG_TACH_COUNT(NR_CHANNEL
+ i));
if (rv < 0)
return ERR_PTR(rv);
data->tach[NR_CHANNEL + i] = rv;
} else {
rv = i2c_smbus_read_word_swapped(client,
MAX31790_REG_PWM_DUTY_CYCLE(i));
if (rv < 0)
return ERR_PTR(rv);
data->pwm[i] = rv;
rv = i2c_smbus_read_word_swapped(client,
MAX31790_REG_TARGET_COUNT(i));
if (rv < 0)
return ERR_PTR(rv);
data->target_count[i] = rv;
}
}
data->last_updated = jiffies;
data->valid = true;
}
return data;
}
static const u8 tach_period[8] = { 1, 2, 4, 8, 16, 32, 32, 32 };
static u8 get_tach_period(u8 fan_dynamics)
{
return tach_period[SR_FROM_REG(fan_dynamics)];
}
static u8 bits_for_tach_period(int rpm)
{
u8 bits;
if (rpm < 500)
bits = 0x0;
else if (rpm < 1000)
bits = 0x1;
else if (rpm < 2000)
bits = 0x2;
else if (rpm < 4000)
bits = 0x3;
else if (rpm < 8000)
Annotation
- Immediate include surface: `linux/err.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/init.h`, `linux/jiffies.h`, `linux/module.h`, `linux/slab.h`.
- Detected declarations: `struct max31790_data`, `function get_tach_period`, `function bits_for_tach_period`, `function max31790_read_fan`, `function max31790_write_fan`, `function max31790_fan_is_visible`, `function max31790_read_pwm`, `function max31790_write_pwm`, `function max31790_pwm_is_visible`, `function max31790_read`.
- 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.