drivers/platform/chrome/cros_ec_proto.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_ec_proto.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/cros_ec_proto.c- Extension
.c- Size
- 31136 bytes
- Lines
- 1173
- 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.
- 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/delay.hlinux/device.hlinux/limits.hlinux/module.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/slab.hlinux/unaligned.hcros_ec_trace.h
Detected Declarations
function cros_ec_map_errorfunction prepare_txfunction prepare_tx_legacyfunction cros_ec_xfer_commandfunction cros_ec_wait_until_completefunction cros_ec_send_commandfunction cros_ec_prepare_txfunction cros_ec_check_resultfunction cros_ec_get_host_event_wake_maskfunction cros_ec_rwsig_continuefunction cros_ec_get_proto_infofunction cros_ec_get_proto_info_legacyfunction cros_ec_get_host_command_version_maskfunction cros_ec_query_allfunction cros_ec_cmd_xferfunction cros_ec_cmd_xfer_statusfunction get_next_event_xferfunction get_next_eventfunction get_keyboard_state_eventfunction receivedfunction devicefunction cros_ec_get_host_eventfunction cros_ec_check_featuresfunction cros_ec_get_sensor_countfunction cros_ec_cmdfunction cros_ec_cmd_readmemfunction cros_ec_get_cmd_versionsfunction cros_ec_device_registeredexport cros_ec_prepare_txexport cros_ec_check_resultexport cros_ec_rwsig_continueexport cros_ec_query_allexport cros_ec_cmd_xferexport cros_ec_cmd_xfer_statusexport cros_ec_get_next_eventexport cros_ec_get_host_eventexport cros_ec_check_featuresexport cros_ec_get_sensor_countexport cros_ec_cmdexport cros_ec_cmd_readmemexport cros_ec_get_cmd_versionsexport cros_ec_device_registered
Annotated Snippet
if (ret == 0) {
ret = -EPROTO;
break;
}
if (!(status->flags & EC_COMMS_STATUS_PROCESSING))
return ret;
}
if (i >= EC_COMMAND_RETRIES)
ret = -EAGAIN;
return ret;
}
static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
{
int ret = cros_ec_xfer_command(ec_dev, msg);
if (msg->result == EC_RES_IN_PROGRESS)
ret = cros_ec_wait_until_complete(ec_dev, &msg->result);
return ret;
}
/**
* cros_ec_prepare_tx() - Prepare an outgoing message in the output buffer.
* @ec_dev: Device to register.
* @msg: Message to write.
*
* This is used by all ChromeOS EC drivers to prepare the outgoing message
* according to different protocol versions.
*
* Return: number of prepared bytes on success or negative error code.
*/
int cros_ec_prepare_tx(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg)
{
if (ec_dev->proto_version > 2)
return prepare_tx(ec_dev, msg);
return prepare_tx_legacy(ec_dev, msg);
}
EXPORT_SYMBOL(cros_ec_prepare_tx);
/**
* cros_ec_check_result() - Check ec_msg->result.
* @ec_dev: EC device.
* @msg: Message to check.
*
* This is used by ChromeOS EC drivers to check the ec_msg->result for
* EC_RES_IN_PROGRESS and to warn about them.
*
* The function should not check for furthermore error codes. Otherwise,
* it would break the ABI.
*
* Return: -EAGAIN if ec_msg->result == EC_RES_IN_PROGRESS. Otherwise, 0.
*/
int cros_ec_check_result(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg)
{
switch (msg->result) {
case EC_RES_SUCCESS:
return 0;
case EC_RES_IN_PROGRESS:
dev_dbg(ec_dev->dev, "command 0x%02x in progress\n",
msg->command);
return -EAGAIN;
default:
dev_dbg(ec_dev->dev, "command 0x%02x returned %d\n",
msg->command, msg->result);
return 0;
}
}
EXPORT_SYMBOL(cros_ec_check_result);
/**
* cros_ec_get_host_event_wake_mask
*
* Get the mask of host events that cause wake from suspend.
*
* @ec_dev: EC device to call
* @mask: result when function returns 0.
*
* LOCKING:
* the caller has ec_dev->lock mutex, or the caller knows there is
* no other command in progress.
*/
static int cros_ec_get_host_event_wake_mask(struct cros_ec_device *ec_dev, uint32_t *mask)
{
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/delay.h`, `linux/device.h`, `linux/limits.h`, `linux/module.h`, `linux/platform_data/cros_ec_commands.h`, `linux/platform_data/cros_ec_proto.h`, `linux/slab.h`.
- Detected declarations: `function cros_ec_map_error`, `function prepare_tx`, `function prepare_tx_legacy`, `function cros_ec_xfer_command`, `function cros_ec_wait_until_complete`, `function cros_ec_send_command`, `function cros_ec_prepare_tx`, `function cros_ec_check_result`, `function cros_ec_get_host_event_wake_mask`, `function cros_ec_rwsig_continue`.
- 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.