drivers/platform/chrome/cros_typec_vdm.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_typec_vdm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/cros_typec_vdm.c- Extension
.c- Size
- 4255 bytes
- Lines
- 149
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/platform_data/cros_ec_commands.hlinux/usb/pd_vdo.hcros_ec_typec.hcros_typec_vdm.h
Detected Declarations
function Messagefunction cros_typec_handle_vdm_responsefunction cros_typec_port_amode_enterfunction cros_typec_port_amode_vdm
Annotated Snippet
if (ret < 0) {
dev_warn(typec->dev, "Failed VDM response fetch, port: %d\n", port_num);
return;
}
hdr = resp.vdm_response[0];
svid = PD_VDO_VID(hdr);
dev_dbg(typec->dev, "Received VDM Attention header: %x, port: %d\n", hdr, port_num);
amode = typec_match_altmode(typec->ports[port_num]->port_altmode,
CROS_EC_ALTMODE_MAX, svid, PD_VDO_OPOS(hdr));
if (!amode) {
dev_err(typec->dev,
"Received VDM for unregistered altmode (SVID:%x), port: %d\n",
svid, port_num);
return;
}
typec_altmode_attention(amode, resp.vdm_attention[1]);
} while (resp.vdm_attention_left);
}
/*
* Retrieves a VDM response from the EC and forwards it to the altmode driver based on SVID.
*/
void cros_typec_handle_vdm_response(struct cros_typec_data *typec, int port_num)
{
struct ec_response_typec_vdm_response resp;
struct ec_params_typec_vdm_response req = {
.port = port_num,
};
struct typec_altmode *amode;
u16 svid;
u32 hdr;
int ret;
ret = cros_ec_cmd(typec->ec, 0, EC_CMD_TYPEC_VDM_RESPONSE, &req,
sizeof(req), &resp, sizeof(resp));
if (ret < 0) {
dev_warn(typec->dev, "Failed VDM response fetch, port: %d\n", port_num);
return;
}
hdr = resp.vdm_response[0];
svid = PD_VDO_VID(hdr);
dev_dbg(typec->dev, "Received VDM header: %x, port: %d\n", hdr, port_num);
amode = typec_match_altmode(typec->ports[port_num]->port_altmode, CROS_EC_ALTMODE_MAX,
svid, PD_VDO_OPOS(hdr));
if (!amode) {
dev_err(typec->dev, "Received VDM for unregistered altmode (SVID:%x), port: %d\n",
svid, port_num);
return;
}
ret = typec_altmode_vdm(amode, hdr, &resp.vdm_response[1], resp.vdm_data_objects);
if (ret)
dev_err(typec->dev, "Failed to forward VDM to altmode (SVID:%x), port: %d\n",
svid, port_num);
}
static int cros_typec_port_amode_enter(struct typec_altmode *amode, u32 *vdo)
{
struct cros_typec_port *port = typec_altmode_get_drvdata(amode);
struct ec_params_typec_control req = {
.port = port->port_num,
.command = TYPEC_CONTROL_COMMAND_SEND_VDM_REQ,
};
struct typec_vdm_req vdm_req = {};
u32 hdr;
hdr = VDO(amode->svid, 1, SVDM_VER_2_0, CMD_ENTER_MODE);
hdr |= VDO_OPOS(amode->mode);
vdm_req.vdm_data[0] = hdr;
vdm_req.vdm_data_objects = 1;
vdm_req.partner_type = TYPEC_PARTNER_SOP;
req.vdm_req_params = vdm_req;
dev_dbg(port->typec_data->dev, "Sending EnterMode VDM, hdr: %x, port: %d\n",
hdr, port->port_num);
return cros_ec_cmd(port->typec_data->ec, 0, EC_CMD_TYPEC_CONTROL, &req,
sizeof(req), NULL, 0);
}
static int cros_typec_port_amode_vdm(struct typec_altmode *amode, const u32 hdr,
const u32 *vdo, int cnt)
{
struct cros_typec_port *port = typec_altmode_get_drvdata(amode);
Annotation
- Immediate include surface: `linux/module.h`, `linux/platform_data/cros_ec_commands.h`, `linux/usb/pd_vdo.h`, `cros_ec_typec.h`, `cros_typec_vdm.h`.
- Detected declarations: `function Message`, `function cros_typec_handle_vdm_response`, `function cros_typec_port_amode_enter`, `function cros_typec_port_amode_vdm`.
- 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.