drivers/usb/typec/ucsi/cros_ec_ucsi.c
Source file repositories/reference/linux-study-clean/drivers/usb/typec/ucsi/cros_ec_ucsi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/typec/ucsi/cros_ec_ucsi.c- Extension
.c- Size
- 10498 bytes
- Lines
- 387
- Domain
- Driver Families
- Bucket
- drivers/usb
- 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/container_of.hlinux/dev_printk.hlinux/jiffies.hlinux/mod_devicetable.hlinux/module.hlinux/of.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_usbpd_notify.hlinux/platform_data/cros_ec_proto.hlinux/platform_device.hlinux/slab.hlinux/wait.hlinux/usb/typec_altmode.hucsi.h
Detected Declarations
struct cros_ucsi_datafunction cros_ucsi_readfunction cros_ucsi_read_versionfunction cros_ucsi_read_ccifunction cros_ucsi_read_message_infunction cros_ucsi_async_controlfunction cros_ucsi_sync_controlfunction cros_ucsi_add_partner_altmodesfunction cros_ucsi_remove_partner_altmodesfunction cros_ucsi_workfunction cros_ucsi_write_timeoutfunction cros_ucsi_eventfunction cros_ucsi_destroyfunction cros_ucsi_probefunction cros_ucsi_removefunction cros_ucsi_suspendfunction cros_ucsi_complete
Annotated Snippet
struct cros_ucsi_data {
struct device *dev;
struct ucsi *ucsi;
struct cros_ec_device *ec;
struct notifier_block nb;
struct work_struct work;
struct delayed_work write_tmo;
int tmo_counter;
struct completion complete;
unsigned long flags;
};
static int cros_ucsi_read(struct ucsi *ucsi, unsigned int offset, void *val,
size_t val_len)
{
struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi);
struct ec_params_ucsi_ppm_get req = {
.offset = offset,
.size = val_len,
};
int ret;
if (val_len > MAX_EC_DATA_SIZE) {
dev_err(udata->dev, "Can't read %zu bytes. Too big.\n", val_len);
return -EINVAL;
}
ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_GET,
&req, sizeof(req), val, val_len);
if (ret < 0) {
dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_GET: error=%d\n", ret);
return ret;
}
return 0;
}
static int cros_ucsi_read_version(struct ucsi *ucsi, u16 *version)
{
return cros_ucsi_read(ucsi, UCSI_VERSION, version, sizeof(*version));
}
static int cros_ucsi_read_cci(struct ucsi *ucsi, u32 *cci)
{
return cros_ucsi_read(ucsi, UCSI_CCI, cci, sizeof(*cci));
}
static int cros_ucsi_read_message_in(struct ucsi *ucsi, void *val,
size_t val_len)
{
return cros_ucsi_read(ucsi, UCSI_MESSAGE_IN, val, val_len);
}
static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd)
{
struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi);
u8 ec_buf[sizeof(struct ec_params_ucsi_ppm_set) + sizeof(cmd)];
struct ec_params_ucsi_ppm_set *req = (struct ec_params_ucsi_ppm_set *) ec_buf;
int ret;
req->offset = UCSI_CONTROL;
memcpy(req->data, &cmd, sizeof(cmd));
ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_SET,
req, sizeof(ec_buf), NULL, 0);
if (ret < 0) {
dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_SET: error=%d\n", ret);
return ret;
}
return 0;
}
static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd, u32 *cci,
void *data, size_t size)
{
struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi);
int ret;
ret = ucsi_sync_control_common(ucsi, cmd, cci, data, size);
switch (ret) {
case -EBUSY:
/* EC may return -EBUSY if CCI.busy is set.
* Convert this to a timeout.
*/
case -ETIMEDOUT:
/* Schedule recovery attempt when we timeout
* or tried to send a command while still busy.
*/
cancel_delayed_work_sync(&udata->write_tmo);
schedule_delayed_work(&udata->write_tmo,
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/container_of.h`, `linux/dev_printk.h`, `linux/jiffies.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/of.h`, `linux/platform_data/cros_ec_commands.h`.
- Detected declarations: `struct cros_ucsi_data`, `function cros_ucsi_read`, `function cros_ucsi_read_version`, `function cros_ucsi_read_cci`, `function cros_ucsi_read_message_in`, `function cros_ucsi_async_control`, `function cros_ucsi_sync_control`, `function cros_ucsi_add_partner_altmodes`, `function cros_ucsi_remove_partner_altmodes`, `function cros_ucsi_work`.
- Atlas domain: Driver Families / drivers/usb.
- 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.