drivers/hwmon/pt5161l.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/pt5161l.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/pt5161l.c- Extension
.c- Size
- 15007 bytes
- Lines
- 640
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/debugfs.hlinux/delay.hlinux/err.hlinux/i2c.hlinux/init.hlinux/hwmon.hlinux/module.hlinux/mutex.h
Detected Declarations
struct pt5161l_fw_verstruct pt5161l_datafunction pt5161l_write_block_datafunction pt5161l_read_block_datafunction pt5161l_read_wide_regfunction multiplefunction pt5161l_fw_load_checkfunction pt5161l_heartbeat_checkfunction pt5161l_fwsts_checkfunction pt5161l_fw_is_at_leastfunction pt5161l_init_devfunction pt5161l_readfunction pt5161l_is_visiblefunction pt5161l_debugfs_read_fw_verfunction pt5161l_debugfs_read_fw_load_stsfunction pt5161l_debugfs_read_hb_stsfunction pt5161l_init_debugfsfunction pt5161l_probe
Annotated Snippet
static const struct file_operations pt5161l_debugfs_ops_fw_ver = {
.read = pt5161l_debugfs_read_fw_ver,
.open = simple_open,
};
static ssize_t pt5161l_debugfs_read_fw_load_sts(struct file *file,
char __user *buf, size_t count,
loff_t *ppos)
{
struct pt5161l_data *data = file->private_data;
int ret;
bool status = false;
char health[16];
mutex_lock(&data->lock);
ret = pt5161l_fw_load_check(data);
mutex_unlock(&data->lock);
if (ret == 0)
status = data->code_load_okay;
ret = snprintf(health, sizeof(health), "%s\n",
status ? "normal" : "abnormal");
return simple_read_from_buffer(buf, count, ppos, health, ret);
}
static const struct file_operations pt5161l_debugfs_ops_fw_load_sts = {
.read = pt5161l_debugfs_read_fw_load_sts,
.open = simple_open,
};
static ssize_t pt5161l_debugfs_read_hb_sts(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
struct pt5161l_data *data = file->private_data;
int ret;
bool status = false;
char health[16];
mutex_lock(&data->lock);
ret = pt5161l_heartbeat_check(data);
mutex_unlock(&data->lock);
if (ret == 0)
status = data->mm_heartbeat_okay;
ret = snprintf(health, sizeof(health), "%s\n",
status ? "normal" : "abnormal");
return simple_read_from_buffer(buf, count, ppos, health, ret);
}
static const struct file_operations pt5161l_debugfs_ops_hb_sts = {
.read = pt5161l_debugfs_read_hb_sts,
.open = simple_open,
};
static void pt5161l_init_debugfs(struct i2c_client *client, struct pt5161l_data *data)
{
debugfs_create_file("fw_ver", 0444, client->debugfs, data,
&pt5161l_debugfs_ops_fw_ver);
debugfs_create_file("fw_load_status", 0444, client->debugfs, data,
&pt5161l_debugfs_ops_fw_load_sts);
debugfs_create_file("heartbeat_status", 0444, client->debugfs, data,
&pt5161l_debugfs_ops_hb_sts);
}
static int pt5161l_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
struct device *hwmon_dev;
struct pt5161l_data *data;
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
data->client = client;
mutex_init(&data->lock);
pt5161l_init_dev(data);
dev_set_drvdata(dev, data);
hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
data,
&pt5161l_chip_info,
NULL);
if (IS_ERR(hwmon_dev))
return PTR_ERR(hwmon_dev);
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/delay.h`, `linux/err.h`, `linux/i2c.h`, `linux/init.h`, `linux/hwmon.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct pt5161l_fw_ver`, `struct pt5161l_data`, `function pt5161l_write_block_data`, `function pt5161l_read_block_data`, `function pt5161l_read_wide_reg`, `function multiple`, `function pt5161l_fw_load_check`, `function pt5161l_heartbeat_check`, `function pt5161l_fwsts_check`, `function pt5161l_fw_is_at_least`.
- Atlas domain: Driver Families / drivers/hwmon.
- Implementation status: pattern 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.