drivers/platform/chrome/cros_ec.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_ec.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/cros_ec.c- Extension
.c- Size
- 13867 bytes
- Lines
- 526
- Domain
- Driver Families
- Bucket
- drivers/platform
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/cleanup.hlinux/interrupt.hlinux/module.hlinux/of_platform.hlinux/platform_device.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/slab.hlinux/suspend.hcros_ec.h
Detected Declarations
function cros_ec_device_freefunction cros_ec_irq_handlerfunction cros_ec_handle_eventfunction cros_ec_irq_threadfunction cros_ec_sleep_eventfunction cros_ec_ready_eventfunction cros_ec_registerfunction cros_ec_unregisterfunction cros_ec_send_suspend_eventfunction cros_ec_suspend_preparefunction cros_ec_disable_irqfunction cros_ec_suspend_latefunction cros_ec_suspendfunction cros_ec_report_events_during_suspendfunction cros_ec_send_resume_eventfunction cros_ec_resume_completefunction cros_ec_enable_irqfunction cros_ec_resume_earlyfunction cros_ec_resumeexport cros_ec_device_allocexport cros_ec_irq_threadexport cros_ec_registerexport cros_ec_unregisterexport cros_ec_suspend_prepareexport cros_ec_suspend_lateexport cros_ec_suspendexport cros_ec_resume_completeexport cros_ec_resume_earlyexport cros_ec_resume
Annotated Snippet
if (err) {
dev_err(dev, "Failed to request IRQ %d: %d\n",
ec_dev->irq, err);
goto exit;
}
}
/* Register a platform device for the main EC instance */
ec_dev->ec = platform_device_register_data(ec_dev->dev, "cros-ec-dev",
PLATFORM_DEVID_AUTO, &ec_p,
sizeof(struct cros_ec_platform));
if (IS_ERR(ec_dev->ec)) {
dev_err(ec_dev->dev,
"Failed to create CrOS EC platform device\n");
err = PTR_ERR(ec_dev->ec);
goto exit;
}
if (ec_dev->max_passthru) {
/*
* Register a platform device for the PD behind the main EC.
* We make the following assumptions:
* - behind an EC, we have a pd
* - only one device added.
* - the EC is responsive at init time (it is not true for a
* sensor hub).
*/
ec_dev->pd = platform_device_register_data(ec_dev->dev,
"cros-ec-dev",
PLATFORM_DEVID_AUTO, &pd_p,
sizeof(struct cros_ec_platform));
if (IS_ERR(ec_dev->pd)) {
dev_err(ec_dev->dev,
"Failed to create CrOS PD platform device\n");
err = PTR_ERR(ec_dev->pd);
goto exit;
}
}
if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
err = devm_of_platform_populate(dev);
if (err) {
dev_err(dev, "Failed to register sub-devices\n");
goto exit;
}
}
/*
* Clear sleep event - this will fail harmlessly on platforms that
* don't implement the sleep event host command.
*/
err = cros_ec_sleep_event(ec_dev, 0);
if (err < 0)
dev_dbg(ec_dev->dev, "Error %d clearing sleep event to ec\n",
err);
if (ec_dev->mkbp_event_supported) {
/*
* Register the notifier for EC_HOST_EVENT_INTERFACE_READY
* event.
*/
ec_dev->notifier_ready.notifier_call = cros_ec_ready_event;
err = blocking_notifier_chain_register(&ec_dev->event_notifier,
&ec_dev->notifier_ready);
if (err)
goto exit;
}
scoped_guard(mutex, &ec_dev->lock)
ec_dev->registered = true;
dev_info(dev, "Chrome EC device registered\n");
/*
* Unlock EC that may be waiting for AP to process MKBP events.
* If the AP takes to long to answer, the EC would stop sending events.
*/
if (ec_dev->mkbp_event_supported)
cros_ec_irq_thread(0, ec_dev);
return 0;
exit:
platform_device_unregister(ec_dev->ec);
platform_device_unregister(ec_dev->pd);
return err;
}
EXPORT_SYMBOL(cros_ec_register);
/**
* cros_ec_unregister() - Remove a ChromeOS EC.
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/interrupt.h`, `linux/module.h`, `linux/of_platform.h`, `linux/platform_device.h`, `linux/platform_data/cros_ec_commands.h`, `linux/platform_data/cros_ec_proto.h`, `linux/slab.h`.
- Detected declarations: `function cros_ec_device_free`, `function cros_ec_irq_handler`, `function cros_ec_handle_event`, `function cros_ec_irq_thread`, `function cros_ec_sleep_event`, `function cros_ec_ready_event`, `function cros_ec_register`, `function cros_ec_unregister`, `function cros_ec_send_suspend_event`, `function cros_ec_suspend_prepare`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.