drivers/hwmon/w83l786ng.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/w83l786ng.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/w83l786ng.c- Extension
.c- Size
- 20736 bytes
- Lines
- 775
- 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/err.hlinux/mutex.hlinux/jiffies.h
Detected Declarations
struct w83l786ng_datafunction FAN_TO_REGfunction fan_from_regfunction temp_from_regfunction DIV_TO_REGfunction w83l786ng_read_valuefunction w83l786ng_write_valuefunction store_fan_minfunction show_fan_divfunction store_fan_divfunction show_tempfunction store_tempfunction store_pwm_modefunction store_pwmfunction store_pwm_enablefunction show_tolerancefunction store_tolerancefunction w83l786ng_detectfunction w83l786ng_init_clientfunction w83l786ng_probe
Annotated Snippet
struct w83l786ng_data {
struct i2c_client *client;
struct mutex update_lock;
bool valid; /* true if following fields are valid */
unsigned long last_updated; /* In jiffies */
unsigned long last_nonvolatile; /* In jiffies, last time we update the
* nonvolatile registers */
u8 in[3];
u8 in_max[3];
u8 in_min[3];
u8 fan[2];
u8 fan_div[2];
u8 fan_min[2];
u8 temp_type[2];
u8 temp[2][3];
u8 pwm[2];
u8 pwm_mode[2]; /* 0->DC variable voltage
* 1->PWM variable duty cycle */
u8 pwm_enable[2]; /* 1->manual
* 2->thermal cruise (also called SmartFan I) */
u8 tolerance[2];
};
static u8
w83l786ng_read_value(struct i2c_client *client, u8 reg)
{
return i2c_smbus_read_byte_data(client, reg);
}
static int
w83l786ng_write_value(struct i2c_client *client, u8 reg, u8 value)
{
return i2c_smbus_write_byte_data(client, reg, value);
}
static struct w83l786ng_data *w83l786ng_update_device(struct device *dev)
{
struct w83l786ng_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
int i, j;
u8 reg_tmp, pwmcfg;
mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) {
dev_dbg(&client->dev, "Updating w83l786ng data.\n");
/* Update the voltages measured value and limits */
for (i = 0; i < 3; i++) {
data->in[i] = w83l786ng_read_value(client,
W83L786NG_REG_IN(i));
data->in_min[i] = w83l786ng_read_value(client,
W83L786NG_REG_IN_MIN(i));
data->in_max[i] = w83l786ng_read_value(client,
W83L786NG_REG_IN_MAX(i));
}
/* Update the fan counts and limits */
for (i = 0; i < 2; i++) {
data->fan[i] = w83l786ng_read_value(client,
W83L786NG_REG_FAN(i));
data->fan_min[i] = w83l786ng_read_value(client,
W83L786NG_REG_FAN_MIN(i));
}
/* Update the fan divisor */
reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_FAN_DIV);
data->fan_div[0] = reg_tmp & 0x07;
data->fan_div[1] = (reg_tmp >> 4) & 0x07;
pwmcfg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG);
for (i = 0; i < 2; i++) {
data->pwm_mode[i] =
((pwmcfg >> W83L786NG_PWM_MODE_SHIFT[i]) & 1)
? 0 : 1;
data->pwm_enable[i] =
((pwmcfg >> W83L786NG_PWM_ENABLE_SHIFT[i]) & 3) + 1;
data->pwm[i] =
(w83l786ng_read_value(client, W83L786NG_REG_PWM[i])
& 0x0f) * 0x11;
}
/* Update the temperature sensors */
for (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) {
data->temp[i][j] = w83l786ng_read_value(client,
W83L786NG_REG_TEMP[i][j]);
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/err.h`, `linux/mutex.h`.
- Detected declarations: `struct w83l786ng_data`, `function FAN_TO_REG`, `function fan_from_reg`, `function temp_from_reg`, `function DIV_TO_REG`, `function w83l786ng_read_value`, `function w83l786ng_write_value`, `function store_fan_min`, `function show_fan_div`, `function store_fan_div`.
- 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.