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.

Dependency Surface

Detected Declarations

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

Implementation Notes