drivers/platform/chrome/cros_typec_altmode.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_typec_altmode.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/cros_typec_altmode.c- Extension
.c- Size
- 9102 bytes
- Lines
- 375
- 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.
- 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
cros_ec_typec.hlinux/mutex.hlinux/workqueue.hlinux/usb/typec_dp.hlinux/usb/typec_tbt.hlinux/usb/pd_vdo.hcros_typec_altmode.h
Detected Declarations
struct cros_typec_altmode_datastruct cros_typec_dp_datafunction cros_typec_altmode_workfunction cros_typec_altmode_enterfunction cros_typec_altmode_exitfunction cros_typec_displayport_vdmfunction cros_typec_thunderbolt_vdmfunction cros_typec_altmode_vdmfunction cros_typec_displayport_status_updatefunction cros_typec_register_displayportfunction cros_typec_register_thunderbolt
Annotated Snippet
struct cros_typec_altmode_data {
struct work_struct work;
struct cros_typec_port *port;
struct typec_altmode *alt;
bool ap_mode_entry;
struct mutex lock;
u32 header;
u32 *vdo_data;
u8 vdo_size;
u16 sid;
u8 mode;
};
struct cros_typec_dp_data {
struct cros_typec_altmode_data adata;
struct typec_displayport_data data;
bool configured;
bool pending_status_update;
};
static void cros_typec_altmode_work(struct work_struct *work)
{
struct cros_typec_altmode_data *data =
container_of(work, struct cros_typec_altmode_data, work);
mutex_lock(&data->lock);
if (typec_altmode_vdm(data->alt, data->header, data->vdo_data,
data->vdo_size))
dev_err(&data->alt->dev, "VDM 0x%x failed\n", data->header);
data->header = 0;
data->vdo_data = NULL;
data->vdo_size = 0;
mutex_unlock(&data->lock);
}
static int cros_typec_altmode_enter(struct typec_altmode *alt, u32 *vdo)
{
struct cros_typec_altmode_data *adata = typec_altmode_get_drvdata(alt);
struct ec_params_typec_control req = {
.port = adata->port->port_num,
.command = TYPEC_CONTROL_COMMAND_ENTER_MODE,
};
int svdm_version;
int ret;
if (!adata->ap_mode_entry) {
dev_warn(&alt->dev,
"EC does not support AP driven mode entry\n");
return -EOPNOTSUPP;
}
if (adata->sid == USB_TYPEC_DP_SID)
req.mode_to_enter = CROS_EC_ALTMODE_DP;
else if (adata->sid == USB_TYPEC_TBT_SID)
req.mode_to_enter = CROS_EC_ALTMODE_TBT;
else
return -EOPNOTSUPP;
ret = cros_ec_cmd(adata->port->typec_data->ec, 0, EC_CMD_TYPEC_CONTROL,
&req, sizeof(req), NULL, 0);
if (ret < 0)
return ret;
svdm_version = typec_altmode_get_svdm_version(alt);
if (svdm_version < 0)
return svdm_version;
mutex_lock(&adata->lock);
adata->header = VDO(adata->sid, 1, svdm_version, CMD_ENTER_MODE);
adata->header |= VDO_OPOS(adata->mode);
adata->header |= VDO_CMDT(CMDT_RSP_ACK);
adata->vdo_data = NULL;
adata->vdo_size = 1;
schedule_work(&adata->work);
mutex_unlock(&adata->lock);
return ret;
}
static int cros_typec_altmode_exit(struct typec_altmode *alt)
{
struct cros_typec_altmode_data *adata = typec_altmode_get_drvdata(alt);
struct ec_params_typec_control req = {
.port = adata->port->port_num,
Annotation
- Immediate include surface: `cros_ec_typec.h`, `linux/mutex.h`, `linux/workqueue.h`, `linux/usb/typec_dp.h`, `linux/usb/typec_tbt.h`, `linux/usb/pd_vdo.h`, `cros_typec_altmode.h`.
- Detected declarations: `struct cros_typec_altmode_data`, `struct cros_typec_dp_data`, `function cros_typec_altmode_work`, `function cros_typec_altmode_enter`, `function cros_typec_altmode_exit`, `function cros_typec_displayport_vdm`, `function cros_typec_thunderbolt_vdm`, `function cros_typec_altmode_vdm`, `function cros_typec_displayport_status_update`, `function cros_typec_register_displayport`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: source 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.