drivers/hwmon/max6650.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/max6650.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/max6650.c- Extension
.c- Size
- 19434 bytes
- Lines
- 830
- 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/jiffies.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/err.hlinux/of.hlinux/sysfs.hlinux/thermal.h
Detected Declarations
struct max6650_datafunction dac_to_pwmfunction pwm_to_dacfunction chipfunction RPMfunction alarm_showfunction max6650_attrs_visiblefunction max6650_init_clientfunction max6650_get_max_statefunction max6650_get_cur_statefunction max6650_set_cur_statefunction max6650_readfunction max6650_writefunction max6650_is_visiblefunction max6650_probe
Annotated Snippet
struct max6650_data {
struct i2c_client *client;
struct mutex update_lock; /* protect alarm register updates */
int nr_fans;
bool valid; /* false until following fields are valid */
unsigned long last_updated; /* in jiffies */
/* register values */
u8 speed;
u8 config;
u8 tach[4];
u8 count;
u8 dac;
u8 alarm;
u8 alarm_en;
unsigned long cooling_dev_state;
};
static const u8 tach_reg[] = {
MAX6650_REG_TACH0,
MAX6650_REG_TACH1,
MAX6650_REG_TACH2,
MAX6650_REG_TACH3,
};
static const struct of_device_id __maybe_unused max6650_dt_match[] = {
{
.compatible = "maxim,max6650",
.data = (void *)1
},
{
.compatible = "maxim,max6651",
.data = (void *)4
},
{ },
};
MODULE_DEVICE_TABLE(of, max6650_dt_match);
static int dac_to_pwm(int dac, bool v12)
{
/*
* Useful range for dac is 0-180 for 12V fans and 0-76 for 5V fans.
* Lower DAC values mean higher speeds.
*/
return clamp_val(255 - (255 * dac) / DAC_LIMIT(v12), 0, 255);
}
static u8 pwm_to_dac(unsigned int pwm, bool v12)
{
int limit = DAC_LIMIT(v12);
return limit - (limit * pwm) / 255;
}
static struct max6650_data *max6650_update_device(struct device *dev)
{
struct max6650_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
int reg, err = 0;
int i;
mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
for (i = 0; i < data->nr_fans; i++) {
reg = i2c_smbus_read_byte_data(client, tach_reg[i]);
if (reg < 0) {
err = reg;
goto error;
}
data->tach[i] = reg;
}
/*
* Alarms are cleared on read in case the condition that
* caused the alarm is removed. Keep the value latched here
* for providing the register through different alarm files.
*/
reg = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM);
if (reg < 0) {
err = reg;
goto error;
}
data->alarm |= reg;
data->last_updated = jiffies;
data->valid = true;
}
error:
mutex_unlock(&data->update_lock);
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/jiffies.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/err.h`.
- Detected declarations: `struct max6650_data`, `function dac_to_pwm`, `function pwm_to_dac`, `function chip`, `function RPM`, `function alarm_show`, `function max6650_attrs_visible`, `function max6650_init_client`, `function max6650_get_max_state`, `function max6650_get_cur_state`.
- 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.