drivers/platform/chrome/wilco_ec/telemetry.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/wilco_ec/telemetry.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/wilco_ec/telemetry.c- Extension
.c- Size
- 13258 bytes
- Lines
- 476
- Domain
- Driver Families
- Bucket
- drivers/platform
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/cdev.hlinux/device.hlinux/fs.hlinux/mod_devicetable.hlinux/module.hlinux/platform_data/wilco-ec.hlinux/platform_device.hlinux/slab.hlinux/types.hlinux/uaccess.h
Detected Declarations
struct telem_args_get_logstruct telem_args_get_versionstruct telem_args_get_fan_infostruct telem_args_get_diag_infostruct telem_args_get_temp_infostruct telem_args_get_temp_readstruct telem_args_get_batt_ext_infostruct telem_args_get_batt_ppid_infostruct wilco_ec_telem_requeststruct telem_device_datastruct telem_session_datafunction check_telem_requestfunction telem_openfunction telem_writefunction telem_readfunction telem_releasefunction telem_device_freefunction telem_device_probefunction telem_device_removefunction telem_module_initfunction telem_module_exitmodule init telem_module_init
Annotated Snippet
static const struct file_operations telem_fops = {
.open = telem_open,
.write = telem_write,
.read = telem_read,
.release = telem_release,
.owner = THIS_MODULE,
};
/**
* telem_device_free() - Callback to free the telem_device_data structure.
* @d: The device embedded in our device data, which we have been ref counting.
*
* Once all open file descriptors are closed and the device has been removed,
* the refcount of the device will fall to 0 and this will be called.
*/
static void telem_device_free(struct device *d)
{
struct telem_device_data *dev_data;
dev_data = container_of(d, struct telem_device_data, dev);
kfree(dev_data);
}
/**
* telem_device_probe() - Callback when creating a new device.
* @pdev: platform device that we will be receiving telems from.
*
* This finds a free minor number for the device, allocates and initializes
* some device data, and creates a new device and char dev node.
*
* Return: 0 on success, negative error code on failure.
*/
static int telem_device_probe(struct platform_device *pdev)
{
struct telem_device_data *dev_data;
int error, minor;
/* Get the next available device number */
minor = ida_alloc_max(&telem_ida, TELEM_MAX_DEV-1, GFP_KERNEL);
if (minor < 0) {
error = minor;
dev_err(&pdev->dev, "Failed to find minor number: %d\n", error);
return error;
}
dev_data = kzalloc_obj(*dev_data);
if (!dev_data) {
ida_free(&telem_ida, minor);
return -ENOMEM;
}
/* Initialize the device data */
dev_data->ec = dev_get_platdata(&pdev->dev);
atomic_set(&dev_data->available, 1);
platform_set_drvdata(pdev, dev_data);
/* Initialize the device */
dev_data->dev.devt = MKDEV(telem_major, minor);
dev_data->dev.class = &telem_class;
dev_data->dev.release = telem_device_free;
dev_set_name(&dev_data->dev, TELEM_DEV_NAME_FMT, minor);
device_initialize(&dev_data->dev);
/* Initialize the character device and add it to userspace */
cdev_init(&dev_data->cdev, &telem_fops);
error = cdev_device_add(&dev_data->cdev, &dev_data->dev);
if (error) {
put_device(&dev_data->dev);
ida_free(&telem_ida, minor);
return error;
}
return 0;
}
static void telem_device_remove(struct platform_device *pdev)
{
struct telem_device_data *dev_data = platform_get_drvdata(pdev);
cdev_device_del(&dev_data->cdev, &dev_data->dev);
ida_free(&telem_ida, MINOR(dev_data->dev.devt));
put_device(&dev_data->dev);
}
static const struct platform_device_id telem_id[] = {
{ DRV_NAME, 0 },
{}
};
MODULE_DEVICE_TABLE(platform, telem_id);
Annotation
- Immediate include surface: `linux/cdev.h`, `linux/device.h`, `linux/fs.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_data/wilco-ec.h`, `linux/platform_device.h`, `linux/slab.h`.
- Detected declarations: `struct telem_args_get_log`, `struct telem_args_get_version`, `struct telem_args_get_fan_info`, `struct telem_args_get_diag_info`, `struct telem_args_get_temp_info`, `struct telem_args_get_temp_read`, `struct telem_args_get_batt_ext_info`, `struct telem_args_get_batt_ppid_info`, `struct wilco_ec_telem_request`, `struct telem_device_data`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.