drivers/platform/chrome/cros_ec_sysfs.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_ec_sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/cros_ec_sysfs.c- Extension
.c- Size
- 12290 bytes
- Lines
- 442
- Domain
- Driver Families
- Bucket
- drivers/platform
- 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/ctype.hlinux/delay.hlinux/device.hlinux/fs.hlinux/kobject.hlinux/mod_devicetable.hlinux/module.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/platform_device.hlinux/printk.hlinux/slab.hlinux/stat.hlinux/types.hlinux/uaccess.h
Detected Declarations
function reboot_showfunction reboot_storefunction version_showfunction flashinfo_showfunction kb_wake_angle_showfunction kb_wake_angle_storefunction usbpdmuxinfo_showfunction ap_mode_entry_showfunction cros_ec_ctrl_visiblefunction cros_ec_sysfs_probefunction cros_ec_sysfs_remove
Annotated Snippet
strlen(words[i].str))) {
if (words[i].flags) {
param->flags |= words[i].flags;
} else {
param->cmd = words[i].cmd;
got_cmd = 1;
}
break;
}
}
/* On to the next word, if any */
while (buf[offset] && !isspace(buf[offset]))
offset++;
}
if (!got_cmd) {
count = -EINVAL;
goto exit;
}
msg->version = 0;
msg->command = EC_CMD_REBOOT_EC + ec->cmd_offset;
msg->outsize = sizeof(*param);
msg->insize = 0;
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0)
count = ret;
exit:
kfree(msg);
return count;
}
static ssize_t version_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
static const char * const image_names[] = {"unknown", "RO", "RW"};
struct ec_response_get_version *r_ver;
struct ec_response_get_chip_info *r_chip;
struct ec_response_board_version *r_board;
struct cros_ec_command *msg;
int ret;
int count = 0;
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
if (!msg)
return -ENOMEM;
/* Get versions. RW may change. */
msg->version = 0;
msg->command = EC_CMD_GET_VERSION + ec->cmd_offset;
msg->insize = sizeof(*r_ver);
msg->outsize = 0;
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0) {
count = ret;
goto exit;
}
r_ver = (struct ec_response_get_version *)msg->data;
/* Strings should be null-terminated, but let's be sure. */
r_ver->version_string_ro[sizeof(r_ver->version_string_ro) - 1] = '\0';
r_ver->version_string_rw[sizeof(r_ver->version_string_rw) - 1] = '\0';
count += sysfs_emit_at(buf, count, "RO version: %s\n", r_ver->version_string_ro);
count += sysfs_emit_at(buf, count, "RW version: %s\n", r_ver->version_string_rw);
count += sysfs_emit_at(buf, count, "Firmware copy: %s\n",
(r_ver->current_image < ARRAY_SIZE(image_names) ?
image_names[r_ver->current_image] : "?"));
/* Get build info. */
msg->command = EC_CMD_GET_BUILD_INFO + ec->cmd_offset;
msg->insize = EC_HOST_PARAM_SIZE;
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0) {
count += sysfs_emit_at(buf, count,
"Build info: XFER / EC ERROR %d / %d\n",
ret, msg->result);
} else {
msg->data[EC_HOST_PARAM_SIZE - 1] = '\0';
count += sysfs_emit_at(buf, count, "Build info: %s\n", msg->data);
}
/* Get chip info. */
msg->command = EC_CMD_GET_CHIP_INFO + ec->cmd_offset;
msg->insize = sizeof(*r_chip);
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0) {
count += sysfs_emit_at(buf, count,
"Chip info: XFER / EC ERROR %d / %d\n",
ret, msg->result);
Annotation
- Immediate include surface: `linux/ctype.h`, `linux/delay.h`, `linux/device.h`, `linux/fs.h`, `linux/kobject.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_data/cros_ec_commands.h`.
- Detected declarations: `function reboot_show`, `function reboot_store`, `function version_show`, `function flashinfo_show`, `function kb_wake_angle_show`, `function kb_wake_angle_store`, `function usbpdmuxinfo_show`, `function ap_mode_entry_show`, `function cros_ec_ctrl_visible`, `function cros_ec_sysfs_probe`.
- Atlas domain: Driver Families / drivers/platform.
- 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.