drivers/usb/typec/ucsi/ucsi_glink.c
Source file repositories/reference/linux-study-clean/drivers/usb/typec/ucsi/ucsi_glink.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/typec/ucsi/ucsi_glink.c- Extension
.c- Size
- 13552 bytes
- Lines
- 491
- 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.
- 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
linux/auxiliary_bus.hlinux/module.hlinux/mutex.hlinux/of_device.hlinux/property.hlinux/soc/qcom/pdr.hlinux/usb/typec_mux.hlinux/gpio/consumer.hlinux/soc/qcom/pmic_glink.hucsi.h
Detected Declarations
struct ucsi_read_buf_req_msgstruct pmic_glink_ucsifunction pmic_glink_ucsi_readfunction pmic_glink_ucsi_read_versionfunction pmic_glink_ucsi_read_ccifunction pmic_glink_ucsi_read_message_infunction pmic_glink_ucsi_locked_writefunction pmic_glink_ucsi_async_controlfunction pmic_glink_ucsi_update_connectorfunction pmic_glink_ucsi_connector_statusfunction pmic_glink_ucsi_read_ackfunction pmic_glink_ucsi_write_ackfunction pmic_glink_ucsi_notifyfunction pmic_glink_ucsi_registerfunction pmic_glink_ucsi_callbackfunction pmic_glink_ucsi_pdr_notifyfunction pmic_glink_ucsi_destroyfunction pmic_glink_ucsi_probefunction device_for_each_child_node_scopedfunction pmic_glink_ucsi_remove
Annotated Snippet
struct ucsi_read_buf_req_msg {
struct pmic_glink_hdr hdr;
};
struct __packed ucsi_read_buf_resp_msg {
struct pmic_glink_hdr hdr;
union {
u8 v2_buf[UCSI_BUF_V2_SIZE];
u8 v1_buf[UCSI_BUF_V1_SIZE];
} buf;
u32 ret_code;
};
struct __packed ucsi_write_buf_req_msg {
struct pmic_glink_hdr hdr;
union {
u8 v2_buf[UCSI_BUF_V2_SIZE];
u8 v1_buf[UCSI_BUF_V1_SIZE];
} buf;
u32 reserved;
};
struct __packed ucsi_write_buf_resp_msg {
struct pmic_glink_hdr hdr;
u32 ret_code;
};
struct __packed ucsi_notify_ind_msg {
struct pmic_glink_hdr hdr;
u32 notification;
u32 receiver;
u32 reserved;
};
struct pmic_glink_ucsi {
struct device *dev;
struct gpio_desc *port_orientation[PMIC_GLINK_MAX_PORTS];
struct pmic_glink_client *client;
struct ucsi *ucsi;
struct completion read_ack;
struct completion write_ack;
struct mutex lock; /* protects concurrent access to PMIC Glink interface */
struct work_struct notify_work;
struct work_struct register_work;
spinlock_t state_lock;
bool ucsi_registered;
bool pd_running;
u8 read_buf[UCSI_BUF_V2_SIZE];
};
static int pmic_glink_ucsi_read(struct ucsi *__ucsi, unsigned int offset,
void *val, size_t val_len)
{
struct pmic_glink_ucsi *ucsi = ucsi_get_drvdata(__ucsi);
struct ucsi_read_buf_req_msg req = {};
unsigned long left;
int ret;
req.hdr.owner = PMIC_GLINK_OWNER_USBC;
req.hdr.type = MSG_TYPE_REQ_RESP;
req.hdr.opcode = UC_UCSI_READ_BUF_REQ;
mutex_lock(&ucsi->lock);
memset(ucsi->read_buf, 0, sizeof(ucsi->read_buf));
reinit_completion(&ucsi->read_ack);
ret = pmic_glink_send(ucsi->client, &req, sizeof(req));
if (ret < 0) {
dev_err(ucsi->dev, "failed to send UCSI read request: %d\n", ret);
goto out_unlock;
}
left = wait_for_completion_timeout(&ucsi->read_ack, 5 * HZ);
if (!left) {
dev_err(ucsi->dev, "timeout waiting for UCSI read response\n");
ret = -ETIMEDOUT;
goto out_unlock;
}
memcpy(val, &ucsi->read_buf[offset], val_len);
ret = 0;
out_unlock:
mutex_unlock(&ucsi->lock);
Annotation
- Immediate include surface: `linux/auxiliary_bus.h`, `linux/module.h`, `linux/mutex.h`, `linux/of_device.h`, `linux/property.h`, `linux/soc/qcom/pdr.h`, `linux/usb/typec_mux.h`, `linux/gpio/consumer.h`.
- Detected declarations: `struct ucsi_read_buf_req_msg`, `struct pmic_glink_ucsi`, `function pmic_glink_ucsi_read`, `function pmic_glink_ucsi_read_version`, `function pmic_glink_ucsi_read_cci`, `function pmic_glink_ucsi_read_message_in`, `function pmic_glink_ucsi_locked_write`, `function pmic_glink_ucsi_async_control`, `function pmic_glink_ucsi_update_connector`, `function pmic_glink_ucsi_connector_status`.
- Atlas domain: Driver Families / drivers/usb.
- 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.