drivers/usb/typec/ucsi/ucsi_stm32g0.c
Source file repositories/reference/linux-study-clean/drivers/usb/typec/ucsi/ucsi_stm32g0.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/typec/ucsi/ucsi_stm32g0.c- Extension
.c- Size
- 18680 bytes
- Lines
- 761
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/delay.hlinux/firmware.hlinux/i2c.hlinux/interrupt.hlinux/minmax.hlinux/module.hlinux/platform_device.hlinux/unaligned.hucsi.h
Detected Declarations
struct ucsi_stm32g0_fw_infostruct ucsi_stm32g0function ucsi_stm32g0_bl_check_ackfunction ucsi_stm32g0_bl_cmd_check_ackfunction ucsi_stm32g0_bl_cmdfunction ucsi_stm32g0_bl_rcv_check_ackfunction ucsi_stm32g0_bl_rcvfunction ucsi_stm32g0_bl_rcv_woackfunction ucsi_stm32g0_bl_sendfunction ucsi_stm32g0_bl_get_versionfunction ucsi_stm32g0_bl_send_addrfunction ucsi_stm32g0_bl_global_mass_erasefunction ucsi_stm32g0_bl_writefunction ucsi_stm32g0_bl_readfunction ucsi_stm32g0_fw_cmdfunction ucsi_stm32g0_fw_rcvfunction ucsi_stm32g0_readfunction ucsi_stm32g0_read_versionfunction ucsi_stm32g0_read_ccifunction ucsi_stm32g0_read_message_infunction ucsi_stm32g0_async_controlfunction ucsi_stm32g0_irq_handlerfunction ucsi_stm32g0_registerfunction ucsi_stm32g0_unregisterfunction ucsi_stm32g0_fw_cbfunction ucsi_stm32g0_probe_bootloaderfunction ucsi_stm32g0_probefunction ucsi_stm32g0_removefunction ucsi_stm32g0_suspendfunction ucsi_stm32g0_resume
Annotated Snippet
struct ucsi_stm32g0_fw_info {
u32 version;
u32 keyword;
};
struct ucsi_stm32g0 {
struct i2c_client *client;
struct i2c_client *i2c_bl;
bool in_bootloader;
u8 bl_version;
struct device *dev;
const char *fw_name;
struct ucsi *ucsi;
bool suspended;
bool wakeup_event;
};
/*
* Bootloader commands helpers:
* - send command (2 bytes)
* - check ack
* Then either:
* - receive data
* - receive data + check ack
* - send data + check ack
* These operations depends on the command and have various length.
*/
static int ucsi_stm32g0_bl_check_ack(struct ucsi *ucsi)
{
struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi);
struct i2c_client *client = g0->i2c_bl;
unsigned char ack;
struct i2c_msg msg[] = {
{
.addr = client->addr,
.flags = I2C_M_RD,
.len = 1,
.buf = &ack,
},
};
int ret;
ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
if (ret != ARRAY_SIZE(msg)) {
dev_err(g0->dev, "i2c bl ack (%02x), error: %d\n", client->addr, ret);
return ret < 0 ? ret : -EIO;
}
/* The 'ack' byte should contain bootloader answer: ack/nack/busy */
switch (ack) {
case STM32G0_I2C_BL_ACK:
return 0;
case STM32G0_I2C_BL_NACK:
return -ENOENT;
case STM32G0_I2C_BL_BUSY:
return -EBUSY;
default:
dev_err(g0->dev, "i2c bl ack (%02x), invalid byte: %02x\n",
client->addr, ack);
return -EINVAL;
}
}
static int ucsi_stm32g0_bl_cmd_check_ack(struct ucsi *ucsi, unsigned int cmd, bool check_ack)
{
struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi);
struct i2c_client *client = g0->i2c_bl;
unsigned char buf[2];
struct i2c_msg msg[] = {
{
.addr = client->addr,
.flags = 0,
.len = sizeof(buf),
.buf = buf,
},
};
int ret;
/*
* Send STM32 bootloader command format is two bytes:
* - command code
* - XOR'ed command code
*/
buf[0] = cmd;
buf[1] = cmd ^ 0xff;
ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
if (ret != ARRAY_SIZE(msg)) {
dev_dbg(g0->dev, "i2c bl cmd %d (%02x), error: %d\n", cmd, client->addr, ret);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/firmware.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/minmax.h`, `linux/module.h`, `linux/platform_device.h`, `linux/unaligned.h`.
- Detected declarations: `struct ucsi_stm32g0_fw_info`, `struct ucsi_stm32g0`, `function ucsi_stm32g0_bl_check_ack`, `function ucsi_stm32g0_bl_cmd_check_ack`, `function ucsi_stm32g0_bl_cmd`, `function ucsi_stm32g0_bl_rcv_check_ack`, `function ucsi_stm32g0_bl_rcv`, `function ucsi_stm32g0_bl_rcv_woack`, `function ucsi_stm32g0_bl_send`, `function ucsi_stm32g0_bl_get_version`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.