drivers/extcon/extcon-usbc-cros-ec.c
Source file repositories/reference/linux-study-clean/drivers/extcon/extcon-usbc-cros-ec.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/extcon/extcon-usbc-cros-ec.c- Extension
.c- Size
- 14409 bytes
- Lines
- 541
- Domain
- Driver Families
- Bucket
- drivers/extcon
- 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/extcon-provider.hlinux/kernel.hlinux/module.hlinux/notifier.hlinux/of.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/platform_device.hlinux/slab.hlinux/sched.h
Detected Declarations
struct cros_ec_extcon_infoenum usb_data_rolesfunction cros_ec_pd_commandfunction cros_ec_usb_get_power_typefunction cros_ec_usb_get_pd_mux_statefunction cros_ec_usb_get_rolefunction cros_ec_pd_get_num_portsfunction cros_ec_usb_power_type_is_wall_wartfunction extcon_cros_ec_detect_cablefunction extcon_cros_ec_eventfunction EC_HOST_EVENT_MASKfunction extcon_cros_ec_probefunction extcon_cros_ec_removefunction extcon_cros_ec_suspendfunction extcon_cros_ec_resume
Annotated Snippet
struct cros_ec_extcon_info {
struct device *dev;
struct extcon_dev *edev;
int port_id;
struct cros_ec_device *ec;
struct notifier_block notifier;
unsigned int dr; /* data role */
bool pr; /* power role (true if VBUS enabled) */
bool dp; /* DisplayPort enabled */
bool mux; /* SuperSpeed (usb3) enabled */
unsigned int power_type;
};
static const unsigned int usb_type_c_cable[] = {
EXTCON_USB,
EXTCON_USB_HOST,
EXTCON_DISP_DP,
EXTCON_NONE,
};
enum usb_data_roles {
DR_NONE,
DR_HOST,
DR_DEVICE,
};
/**
* cros_ec_pd_command() - Send a command to the EC.
* @info: pointer to struct cros_ec_extcon_info
* @command: EC command
* @version: EC command version
* @outdata: EC command output data
* @outsize: Size of outdata
* @indata: EC command input data
* @insize: Size of indata
*
* Return: 0 on success, <0 on failure.
*/
static int cros_ec_pd_command(struct cros_ec_extcon_info *info,
unsigned int command,
unsigned int version,
void *outdata,
unsigned int outsize,
void *indata,
unsigned int insize)
{
struct cros_ec_command *msg;
int ret;
msg = kzalloc_flex(*msg, data, max(outsize, insize));
if (!msg)
return -ENOMEM;
msg->version = version;
msg->command = command;
msg->outsize = outsize;
msg->insize = insize;
if (outsize)
memcpy(msg->data, outdata, outsize);
ret = cros_ec_cmd_xfer_status(info->ec, msg);
if (ret >= 0 && insize)
memcpy(indata, msg->data, insize);
kfree(msg);
return ret;
}
/**
* cros_ec_usb_get_power_type() - Get power type info about PD device attached
* to given port.
* @info: pointer to struct cros_ec_extcon_info
*
* Return: power type on success, <0 on failure.
*/
static int cros_ec_usb_get_power_type(struct cros_ec_extcon_info *info)
{
struct ec_params_usb_pd_power_info req;
struct ec_response_usb_pd_power_info resp;
int ret;
req.port = info->port_id;
ret = cros_ec_pd_command(info, EC_CMD_USB_PD_POWER_INFO, 0,
&req, sizeof(req), &resp, sizeof(resp));
if (ret < 0)
Annotation
- Immediate include surface: `linux/extcon-provider.h`, `linux/kernel.h`, `linux/module.h`, `linux/notifier.h`, `linux/of.h`, `linux/platform_data/cros_ec_commands.h`, `linux/platform_data/cros_ec_proto.h`, `linux/platform_device.h`.
- Detected declarations: `struct cros_ec_extcon_info`, `enum usb_data_roles`, `function cros_ec_pd_command`, `function cros_ec_usb_get_power_type`, `function cros_ec_usb_get_pd_mux_state`, `function cros_ec_usb_get_role`, `function cros_ec_pd_get_num_ports`, `function cros_ec_usb_power_type_is_wall_wart`, `function extcon_cros_ec_detect_cable`, `function extcon_cros_ec_event`.
- Atlas domain: Driver Families / drivers/extcon.
- 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.