drivers/platform/chrome/wilco_ec/core.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/wilco_ec/core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/wilco_ec/core.c- Extension
.c- Size
- 4801 bytes
- Lines
- 176
- 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/acpi.hlinux/device.hlinux/ioport.hlinux/mod_devicetable.hlinux/module.hlinux/platform_data/wilco-ec.hlinux/platform_device.h../cros_ec_lpc_mec.h
Detected Declarations
function wilco_ec_probefunction wilco_ec_remove
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Core driver for Wilco Embedded Controller
*
* Copyright 2018 Google LLC
*
* This is the entry point for the drivers that control the Wilco EC.
*/
#include <linux/acpi.h>
#include <linux/device.h>
#include <linux/ioport.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/platform_data/wilco-ec.h>
#include <linux/platform_device.h>
#include "../cros_ec_lpc_mec.h"
#define DRV_NAME "wilco-ec"
static struct resource *wilco_get_resource(struct platform_device *pdev,
int index)
{
struct device *dev = &pdev->dev;
struct resource *res;
res = platform_get_resource(pdev, IORESOURCE_IO, index);
if (!res) {
dev_dbg(dev, "Couldn't find IO resource %d\n", index);
return res;
}
return devm_request_region(dev, res->start, resource_size(res),
dev_name(dev));
}
static int wilco_ec_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct wilco_ec_device *ec;
int ret;
ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL);
if (!ec)
return -ENOMEM;
platform_set_drvdata(pdev, ec);
ec->dev = dev;
mutex_init(&ec->mailbox_lock);
ec->data_size = sizeof(struct wilco_ec_response) + EC_MAILBOX_DATA_SIZE;
ec->data_buffer = devm_kzalloc(dev, ec->data_size, GFP_KERNEL);
if (!ec->data_buffer)
return -ENOMEM;
/* Prepare access to IO regions provided by ACPI */
ec->io_data = wilco_get_resource(pdev, 0); /* Host Data */
ec->io_command = wilco_get_resource(pdev, 1); /* Host Command */
ec->io_packet = wilco_get_resource(pdev, 2); /* MEC EMI */
if (!ec->io_data || !ec->io_command || !ec->io_packet)
return -ENODEV;
/* Initialize cros_ec register interface for communication */
cros_ec_lpc_mec_init(ec->io_packet->start,
ec->io_packet->start + EC_MAILBOX_DATA_SIZE);
/*
* Register a child device that will be found by the debugfs driver.
* Ignore failure.
*/
ec->debugfs_pdev = platform_device_register_data(dev,
"wilco-ec-debugfs",
PLATFORM_DEVID_AUTO,
NULL, 0);
/* Register a child device that will be found by the RTC driver. */
ec->rtc_pdev = platform_device_register_data(dev, "rtc-wilco-ec",
PLATFORM_DEVID_AUTO,
NULL, 0);
if (IS_ERR(ec->rtc_pdev)) {
dev_err(dev, "Failed to create RTC platform device\n");
ret = PTR_ERR(ec->rtc_pdev);
goto unregister_debugfs;
}
/* Set up the keyboard backlight LEDs. */
ret = wilco_keyboard_leds_init(ec);
if (ret < 0) {
dev_err(dev,
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/device.h`, `linux/ioport.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_data/wilco-ec.h`, `linux/platform_device.h`, `../cros_ec_lpc_mec.h`.
- Detected declarations: `function wilco_ec_probe`, `function wilco_ec_remove`.
- 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.