drivers/hwmon/nct7802.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/nct7802.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/nct7802.c- Extension
.c- Size
- 39017 bytes
- Lines
- 1308
- 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/err.hlinux/i2c.hlinux/init.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/jiffies.hlinux/module.hlinux/mutex.hlinux/regmap.hlinux/slab.h
Detected Declarations
struct nct7802_datafunction temp_type_showfunction temp_type_storefunction pwm_mode_showfunction pwm_showfunction pwm_storefunction pwm_enable_showfunction pwm_enable_storefunction nct7802_read_tempfunction nct7802_read_fanfunction nct7802_read_fan_minfunction nct7802_write_fan_minfunction nct7802_read_voltagefunction nct7802_write_voltagefunction in_showfunction in_storefunction in_alarm_showfunction temp_showfunction temp_storefunction fan_showfunction fan_min_showfunction fan_min_storefunction alarm_showfunction beep_showfunction beep_storefunction step_time_showfunction step_up_time_showfunction step_down_time_showfunction step_time_storefunction step_up_time_storefunction step_down_time_storefunction nct7802_temp_is_visiblefunction nct7802_in_is_visiblefunction nct7802_fan_is_visiblefunction nct7802_detectfunction nct7802_regmap_is_volatilefunction nct7802_get_channel_configfunction nct7802_configure_channelsfunction nct7802_init_chipfunction nct7802_probe
Annotated Snippet
struct nct7802_data {
struct regmap *regmap;
struct mutex access_lock; /* for multi-byte read and write operations */
u8 in_status;
struct mutex in_alarm_lock;
};
static ssize_t temp_type_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct nct7802_data *data = dev_get_drvdata(dev);
struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
unsigned int mode;
int ret;
ret = regmap_read(data->regmap, REG_MODE, &mode);
if (ret < 0)
return ret;
return sprintf(buf, "%u\n", (mode >> (2 * sattr->index) & 3) + 2);
}
static ssize_t temp_type_store(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{
struct nct7802_data *data = dev_get_drvdata(dev);
struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
unsigned int type;
int err;
err = kstrtouint(buf, 0, &type);
if (err < 0)
return err;
if (sattr->index == 2 && type != 4) /* RD3 */
return -EINVAL;
if (type < 3 || type > 4)
return -EINVAL;
err = regmap_update_bits(data->regmap, REG_MODE,
3 << 2 * sattr->index, (type - 2) << 2 * sattr->index);
return err ? : count;
}
static ssize_t pwm_mode_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
struct nct7802_data *data = dev_get_drvdata(dev);
unsigned int regval;
int ret;
if (sattr->index > 1)
return sprintf(buf, "1\n");
ret = regmap_read(data->regmap, 0x5E, ®val);
if (ret < 0)
return ret;
return sprintf(buf, "%u\n", !(regval & (1 << sattr->index)));
}
static ssize_t pwm_show(struct device *dev, struct device_attribute *devattr,
char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct nct7802_data *data = dev_get_drvdata(dev);
unsigned int val;
int ret;
if (!attr->index)
return sprintf(buf, "255\n");
ret = regmap_read(data->regmap, attr->index, &val);
if (ret < 0)
return ret;
return sprintf(buf, "%d\n", val);
}
static ssize_t pwm_store(struct device *dev, struct device_attribute *devattr,
const char *buf, size_t count)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct nct7802_data *data = dev_get_drvdata(dev);
int err;
u8 val;
err = kstrtou8(buf, 0, &val);
if (err < 0)
return err;
Annotation
- Immediate include surface: `linux/err.h`, `linux/i2c.h`, `linux/init.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/jiffies.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct nct7802_data`, `function temp_type_show`, `function temp_type_store`, `function pwm_mode_show`, `function pwm_show`, `function pwm_store`, `function pwm_enable_show`, `function pwm_enable_store`, `function nct7802_read_temp`, `function nct7802_read_fan`.
- 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.