drivers/platform/chrome/cros_ec_typec.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_ec_typec.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/cros_ec_typec.c- Extension
.c- Size
- 41587 bytes
- Lines
- 1469
- 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/module.hlinux/of.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_usbpd_notify.hlinux/platform_device.hlinux/usb/pd_vdo.hlinux/usb/typec_dp.hlinux/usb/typec_tbt.hcros_ec_typec.hcros_typec_vdm.hcros_typec_altmode.h
Detected Declarations
function DP_CONF_SET_PIN_ASSIGNfunction cros_typec_enter_usb_modefunction cros_typec_perform_role_swapfunction cros_typec_dr_swapfunction cros_typec_pr_swapfunction cros_typec_parse_port_propsfunction cros_typec_get_switch_handlesfunction cros_typec_add_partnerfunction cros_typec_unregister_altmodesfunction cros_typec_retimer_setfunction cros_typec_usb_disconnect_statefunction cros_typec_remove_partnerfunction cros_typec_remove_cablefunction cros_typec_unregister_port_altmodesfunction cros_unregister_portsfunction cros_typec_register_port_altmodesfunction cros_typec_init_portsfunction cros_typec_usb_safe_statefunction cros_typec_get_cable_vdofunction list_for_each_entryfunction cros_typec_enable_tbtfunction cros_typec_enable_dpfunction cros_typec_enable_usb4function cros_typec_configure_muxfunction cros_typec_set_port_params_v0function cros_typec_set_port_params_v1function cros_typec_register_altmodesfunction cros_typec_parse_pd_identityfunction cros_typec_handle_sop_prime_discfunction cros_typec_handle_sop_discfunction cros_typec_send_clear_eventfunction cros_typec_register_partner_pdosfunction cros_typec_handle_statusfunction cros_typec_port_updatefunction cros_typec_get_cmd_versionfunction cros_typec_port_workfunction cros_ec_typec_eventfunction cros_typec_probefunction cros_typec_removefunction cros_typec_suspendfunction cros_typec_resume
Annotated Snippet
if (role != target_role) {
dev_err(data->dev, "Data role swap failed despite EC returning success\n");
return -EIO;
}
typec_set_data_role(tc_port, target_role);
break;
case USB_PD_CTRL_SWAP_POWER:
role = resp.role & PD_CTRL_RESP_ROLE_POWER ? TYPEC_SOURCE : TYPEC_SINK;
if (role != target_role) {
dev_err(data->dev, "Power role swap failed despite EC returning success\n");
return -EIO;
}
typec_set_pwr_role(tc_port, target_role);
break;
default:
/* Should never execute */
break;
}
return 0;
}
static int cros_typec_dr_swap(struct typec_port *port, enum typec_data_role role)
{
return cros_typec_perform_role_swap(port, role, USB_PD_CTRL_SWAP_DATA);
}
static int cros_typec_pr_swap(struct typec_port *port, enum typec_role role)
{
return cros_typec_perform_role_swap(port, role, USB_PD_CTRL_SWAP_POWER);
}
static const struct typec_operations cros_typec_usb_mode_ops = {
.enter_usb_mode = cros_typec_enter_usb_mode,
.dr_set = cros_typec_dr_swap,
.pr_set = cros_typec_pr_swap,
};
static int cros_typec_parse_port_props(struct typec_capability *cap,
struct fwnode_handle *fwnode,
struct device *dev)
{
const char *buf;
int ret;
memset(cap, 0, sizeof(*cap));
ret = fwnode_property_read_string(fwnode, "power-role", &buf);
if (ret) {
dev_err(dev, "power-role not found: %d\n", ret);
return ret;
}
ret = typec_find_port_power_role(buf);
if (ret < 0)
return ret;
cap->type = ret;
ret = fwnode_property_read_string(fwnode, "data-role", &buf);
if (ret) {
dev_err(dev, "data-role not found: %d\n", ret);
return ret;
}
ret = typec_find_port_data_role(buf);
if (ret < 0)
return ret;
cap->data = ret;
/* Try-power-role is optional. */
ret = fwnode_property_read_string(fwnode, "try-power-role", &buf);
if (ret) {
dev_warn(dev, "try-power-role not found: %d\n", ret);
cap->prefer_role = TYPEC_NO_PREFERRED_ROLE;
} else {
ret = typec_find_power_role(buf);
if (ret < 0)
return ret;
cap->prefer_role = ret;
}
if (fwnode_property_present(fwnode, "usb2-port"))
cap->usb_capability |= USB_CAPABILITY_USB2;
if (fwnode_property_present(fwnode, "usb3-port"))
cap->usb_capability |= USB_CAPABILITY_USB3;
if (fwnode_property_present(fwnode, "usb4-port"))
cap->usb_capability |= USB_CAPABILITY_USB4;
cros_typec_role_switch_quirk(fwnode);
cap->fwnode = fwnode;
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/module.h`, `linux/of.h`, `linux/platform_data/cros_ec_commands.h`, `linux/platform_data/cros_usbpd_notify.h`, `linux/platform_device.h`, `linux/usb/pd_vdo.h`, `linux/usb/typec_dp.h`.
- Detected declarations: `function DP_CONF_SET_PIN_ASSIGN`, `function cros_typec_enter_usb_mode`, `function cros_typec_perform_role_swap`, `function cros_typec_dr_swap`, `function cros_typec_pr_swap`, `function cros_typec_parse_port_props`, `function cros_typec_get_switch_handles`, `function cros_typec_add_partner`, `function cros_typec_unregister_altmodes`, `function cros_typec_retimer_set`.
- 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.