drivers/hwmon/nct7904.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/nct7904.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/nct7904.c- Extension
.c- Size
- 31379 bytes
- Lines
- 1170
- 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/module.hlinux/device.hlinux/init.hlinux/i2c.hlinux/hwmon.hlinux/watchdog.h
Detected Declarations
struct nct7904_datafunction nct7904_bank_selectfunction nct7904_read_regfunction nct7904_read_reg16function nct7904_write_regfunction nct7904_read_fanfunction nct7904_fan_is_visiblefunction nct7904_read_infunction nct7904_in_is_visiblefunction nct7904_read_tempfunction nct7904_temp_is_visiblefunction nct7904_read_pwmfunction nct7904_write_tempfunction nct7904_write_fanfunction nct7904_write_infunction nct7904_write_pwmfunction nct7904_pwm_is_visiblefunction nct7904_readfunction nct7904_writefunction nct7904_is_visiblefunction nct7904_detectfunction nct7904_wdt_startfunction nct7904_wdt_stopfunction nct7904_wdt_set_timeoutfunction nct7904_wdt_pingfunction nct7904_wdt_get_timeleftfunction nct7904_probe
Annotated Snippet
struct nct7904_data {
struct i2c_client *client;
struct watchdog_device wdt;
int bank_sel;
u32 fanin_mask;
u32 vsen_mask;
u32 tcpu_mask;
u8 fan_mode[FANCTL_MAX];
u8 enable_dts;
u8 has_dts;
u8 temp_mode; /* 0: TR mode, 1: TD mode */
u8 fan_alarm[2];
u8 vsen_alarm[3];
};
/* Access functions */
static int nct7904_bank_select(struct nct7904_data *data, unsigned int bank)
{
int ret;
if (data->bank_sel == bank)
return 0;
ret = i2c_smbus_write_byte_data(data->client, BANK_SEL_REG, bank);
if (ret < 0) {
data->bank_sel = -1;
return ret;
}
data->bank_sel = bank;
return 0;
}
/* Read 1-byte register. Returns unsigned reg or -ERRNO on error. */
static int nct7904_read_reg(struct nct7904_data *data,
unsigned int bank, unsigned int reg)
{
struct i2c_client *client = data->client;
int ret;
ret = nct7904_bank_select(data, bank);
if (ret < 0)
return ret;
return i2c_smbus_read_byte_data(client, reg);
}
/*
* Read 2-byte register. Returns register in big-endian format or
* -ERRNO on error.
*/
static int nct7904_read_reg16(struct nct7904_data *data,
unsigned int bank, unsigned int reg)
{
struct i2c_client *client = data->client;
int ret, hi;
ret = nct7904_bank_select(data, bank);
if (ret < 0)
return ret;
hi = i2c_smbus_read_byte_data(client, reg);
if (hi < 0)
return hi;
ret = i2c_smbus_read_byte_data(client, reg + 1);
if (ret < 0)
return ret;
return ret | (hi << 8);
}
/* Write 1-byte register. Returns 0 or -ERRNO on error. */
static int nct7904_write_reg(struct nct7904_data *data,
unsigned int bank, unsigned int reg, u8 val)
{
struct i2c_client *client = data->client;
int ret;
ret = nct7904_bank_select(data, bank);
if (ret < 0)
return ret;
return i2c_smbus_write_byte_data(client, reg, val);
}
static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
long *val)
{
struct nct7904_data *data = dev_get_drvdata(dev);
unsigned int cnt, rpm;
int ret;
switch (attr) {
case hwmon_fan_input:
ret = nct7904_read_reg16(data, BANK_0,
FANIN1_HV_REG + channel * 2);
Annotation
- Immediate include surface: `linux/module.h`, `linux/device.h`, `linux/init.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/watchdog.h`.
- Detected declarations: `struct nct7904_data`, `function nct7904_bank_select`, `function nct7904_read_reg`, `function nct7904_read_reg16`, `function nct7904_write_reg`, `function nct7904_read_fan`, `function nct7904_fan_is_visible`, `function nct7904_read_in`, `function nct7904_in_is_visible`, `function nct7904_read_temp`.
- 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.