drivers/platform/chrome/wilco_ec/mailbox.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/wilco_ec/mailbox.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/wilco_ec/mailbox.c- Extension
.c- Size
- 6116 bytes
- Lines
- 222
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/device.hlinux/io.hlinux/platform_data/wilco-ec.hlinux/platform_device.h../cros_ec_lpc_mec.h
Detected Declarations
function wilco_ec_response_timed_outfunction wilco_ec_checksumfunction wilco_ec_preparefunction wilco_ec_transferfunction wilco_ec_mailboxexport wilco_ec_mailbox
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Mailbox interface for Wilco Embedded Controller
*
* Copyright 2018 Google LLC
*
* The Wilco EC is similar to a typical ChromeOS embedded controller.
* It uses the same MEC based low-level communication and a similar
* protocol, but with some important differences. The EC firmware does
* not support the same mailbox commands so it is not registered as a
* cros_ec device type.
*
* Most messages follow a standard format, but there are some exceptions
* and an interface is provided to do direct/raw transactions that do not
* make assumptions about byte placement.
*/
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/io.h>
#include <linux/platform_data/wilco-ec.h>
#include <linux/platform_device.h>
#include "../cros_ec_lpc_mec.h"
/* Version of mailbox interface */
#define EC_MAILBOX_VERSION 0
/* Command to start mailbox transaction */
#define EC_MAILBOX_START_COMMAND 0xda
/* Version of EC protocol */
#define EC_MAILBOX_PROTO_VERSION 3
/* Number of header bytes to be counted as data bytes */
#define EC_MAILBOX_DATA_EXTRA 2
/* Maximum timeout */
#define EC_MAILBOX_TIMEOUT HZ
/* EC response flags */
#define EC_CMDR_DATA BIT(0) /* Data ready for host to read */
#define EC_CMDR_PENDING BIT(1) /* Write pending to EC */
#define EC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
#define EC_CMDR_CMD BIT(3) /* Last host write was a command */
/**
* wilco_ec_response_timed_out() - Wait for EC response.
* @ec: EC device.
*
* Return: true if EC timed out, false if EC did not time out.
*/
static bool wilco_ec_response_timed_out(struct wilco_ec_device *ec)
{
unsigned long timeout = jiffies + EC_MAILBOX_TIMEOUT;
do {
if (!(inb(ec->io_command->start) &
(EC_CMDR_PENDING | EC_CMDR_BUSY)))
return false;
usleep_range(100, 200);
} while (time_before(jiffies, timeout));
return true;
}
/**
* wilco_ec_checksum() - Compute 8-bit checksum over data range.
* @data: Data to checksum.
* @size: Number of bytes to checksum.
*
* Return: 8-bit checksum of provided data.
*/
static u8 wilco_ec_checksum(const void *data, size_t size)
{
u8 *data_bytes = (u8 *)data;
u8 checksum = 0;
size_t i;
for (i = 0; i < size; i++)
checksum += data_bytes[i];
return checksum;
}
/**
* wilco_ec_prepare() - Prepare the request structure for the EC.
* @msg: EC message with request information.
* @rq: EC request structure to fill.
*/
Annotation
- Immediate include surface: `linux/delay.h`, `linux/device.h`, `linux/io.h`, `linux/platform_data/wilco-ec.h`, `linux/platform_device.h`, `../cros_ec_lpc_mec.h`.
- Detected declarations: `function wilco_ec_response_timed_out`, `function wilco_ec_checksum`, `function wilco_ec_prepare`, `function wilco_ec_transfer`, `function wilco_ec_mailbox`, `export wilco_ec_mailbox`.
- 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.
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.