drivers/hwmon/nct7363.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/nct7363.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/nct7363.c- Extension
.c- Size
- 10536 bytes
- Lines
- 444
- 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/bitfield.hlinux/bits.hlinux/err.hlinux/hwmon.hlinux/i2c.hlinux/module.hlinux/regmap.hlinux/slab.h
Detected Declarations
struct nct7363_datafunction fan_from_regfunction nct7363_read_fanfunction nct7363_write_fanfunction nct7363_fan_is_visiblefunction nct7363_read_pwmfunction nct7363_write_pwmfunction nct7363_pwm_is_visiblefunction nct7363_readfunction nct7363_writefunction nct7363_is_visiblefunction nct7363_init_chipfunction nct7363_present_pwm_faninfunction nct7363_regmap_is_volatilefunction nct7363_probefunction for_each_child_of_node_scoped
Annotated Snippet
struct nct7363_data {
struct regmap *regmap;
u16 fanin_mask;
u16 pwm_mask;
};
static int nct7363_read_fan(struct device *dev, u32 attr, int channel,
long *val)
{
struct nct7363_data *data = dev_get_drvdata(dev);
unsigned int reg;
u8 regval[2];
int ret;
u16 cnt;
switch (attr) {
case hwmon_fan_input:
/*
* High-byte register should be read first to latch
* synchronous low-byte value
*/
ret = regmap_bulk_read(data->regmap,
NCT7363_REG_FANINX_HVAL(channel),
®val, 2);
if (ret)
return ret;
cnt = (regval[0] << 5) | (regval[1] & NCT7363_FANINX_LVAL_MASK);
*val = fan_from_reg(cnt);
return 0;
case hwmon_fan_min:
ret = regmap_bulk_read(data->regmap,
NCT7363_REG_FANINX_HL(channel),
®val, 2);
if (ret)
return ret;
cnt = (regval[0] << 5) | (regval[1] & NCT7363_FANINX_LVAL_MASK);
*val = fan_from_reg(cnt);
return 0;
case hwmon_fan_alarm:
ret = regmap_read(data->regmap,
NCT7363_REG_LSRS(channel), ®);
if (ret)
return ret;
*val = (long)ALARM_SEL(reg, channel) > 0 ? 1 : 0;
return 0;
default:
return -EOPNOTSUPP;
}
}
static int nct7363_write_fan(struct device *dev, u32 attr, int channel,
long val)
{
struct nct7363_data *data = dev_get_drvdata(dev);
u8 regval[2];
int ret;
if (val <= 0)
return -EINVAL;
switch (attr) {
case hwmon_fan_min:
val = clamp_val(DIV_ROUND_CLOSEST(1350000, val),
1, NCT7363_FANIN_MASK);
regval[0] = val >> 5;
regval[1] = val & NCT7363_FANINX_LVAL_MASK;
ret = regmap_bulk_write(data->regmap,
NCT7363_REG_FANINX_HL(channel),
regval, 2);
return ret;
default:
return -EOPNOTSUPP;
}
}
static umode_t nct7363_fan_is_visible(const void *_data, u32 attr, int channel)
{
const struct nct7363_data *data = _data;
switch (attr) {
case hwmon_fan_input:
case hwmon_fan_alarm:
if (data->fanin_mask & BIT(channel))
return 0444;
break;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bits.h`, `linux/err.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/module.h`, `linux/regmap.h`, `linux/slab.h`.
- Detected declarations: `struct nct7363_data`, `function fan_from_reg`, `function nct7363_read_fan`, `function nct7363_write_fan`, `function nct7363_fan_is_visible`, `function nct7363_read_pwm`, `function nct7363_write_pwm`, `function nct7363_pwm_is_visible`, `function nct7363_read`, `function nct7363_write`.
- 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.