drivers/usb/typec/tcpm/fusb302.c
Source file repositories/reference/linux-study-clean/drivers/usb/typec/tcpm/fusb302.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/typec/tcpm/fusb302.c- Extension
.c- Size
- 49802 bytes
- Lines
- 1869
- 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.
- 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
drm/bridge/aux-bridge.hlinux/debugfs.hlinux/delay.hlinux/errno.hlinux/extcon.hlinux/gpio/consumer.hlinux/i2c.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/mutex.hlinux/of.hlinux/pinctrl/consumer.hlinux/proc_fs.hlinux/regulator/consumer.hlinux/sched/clock.hlinux/seq_file.hlinux/slab.hlinux/spinlock.hlinux/string.hlinux/string_choices.hlinux/types.hlinux/usb.hlinux/usb/typec.hlinux/usb/tcpm.hlinux/usb/pd.hlinux/workqueue.hfusb302_reg.h
Detected Declarations
struct fusb302_chipenum toggling_modeenum src_current_statusfunction fusb302_log_fullfunction _fusb302_logfunction fusb302_logfunction fusb302_debug_showfunction fusb302_debugfs_initfunction fusb302_debugfs_exitfunction fusb302_logfunction fusb302_i2c_block_writefunction fusb302_i2c_readfunction fusb302_i2c_block_readfunction fusb302_i2c_mask_writefunction fusb302_i2c_set_bitsfunction fusb302_i2c_clear_bitsfunction fusb302_sw_resetfunction fusb302_enable_tx_auto_retriesfunction fusb302_init_interruptfunction fusb302_set_power_modefunction tcpm_initfunction tcpm_get_vbusfunction tcpm_get_current_limitfunction fusb302_set_src_currentfunction fusb302_set_togglingfunction tcpm_set_ccfunction tcpm_get_ccfunction tcpm_set_polarityfunction tcpm_set_vconnfunction tcpm_set_vbusfunction fusb302_pd_tx_flushfunction fusb302_pd_rx_flushfunction fusb302_pd_set_auto_goodcrcfunction fusb302_pd_set_interruptsfunction tcpm_set_pd_rxfunction tcpm_set_rolesfunction tcpm_start_togglingfunction fusb302_pd_send_messagefunction fusb302_pd_send_hardresetfunction tcpm_pd_transmitfunction fusb302_bc_lvl_to_ccfunction fusb302_bc_lvl_handler_workfunction init_tcpc_devfunction fusb302_set_cc_polarity_and_pullfunction fusb302_handle_togdone_snkfunction fusb302_get_src_cc_statusfunction fusb302_handle_togdone_srcfunction fusb302_handle_togdone
Annotated Snippet
struct fusb302_chip {
struct device *dev;
struct i2c_client *i2c_client;
struct tcpm_port *tcpm_port;
struct tcpc_dev tcpc_dev;
struct regulator *vbus;
spinlock_t irq_lock;
struct work_struct irq_work;
bool irq_suspended;
bool irq_while_suspended;
struct gpio_desc *gpio_int_n;
int gpio_int_n_irq;
struct extcon_dev *extcon;
struct workqueue_struct *wq;
struct delayed_work bc_lvl_handler;
/* lock for sharing chip states */
struct mutex lock;
/* chip status */
enum toggling_mode toggling_mode;
enum src_current_status src_current_status;
bool intr_togdone;
bool intr_bc_lvl;
bool intr_comp_chng;
/* port status */
bool vconn_on;
bool vbus_on;
bool charge_on;
bool pd_rx_on;
bool vbus_present;
enum typec_cc_polarity cc_polarity;
enum typec_cc_status cc1;
enum typec_cc_status cc2;
u32 snk_pdo[PDO_MAX_OBJECTS];
#ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
/* lock for log buffer access */
struct mutex logbuffer_lock;
int logbuffer_head;
int logbuffer_tail;
u8 *logbuffer[LOG_BUFFER_ENTRIES];
#endif
};
/*
* Logging
*/
#ifdef CONFIG_DEBUG_FS
static bool fusb302_log_full(struct fusb302_chip *chip)
{
return chip->logbuffer_tail ==
(chip->logbuffer_head + 1) % LOG_BUFFER_ENTRIES;
}
__printf(2, 0)
static void _fusb302_log(struct fusb302_chip *chip, const char *fmt,
va_list args)
{
char tmpbuffer[LOG_BUFFER_ENTRY_SIZE];
u64 ts_nsec = local_clock();
unsigned long rem_nsec;
if (!chip->logbuffer[chip->logbuffer_head]) {
chip->logbuffer[chip->logbuffer_head] =
kzalloc(LOG_BUFFER_ENTRY_SIZE, GFP_KERNEL);
if (!chip->logbuffer[chip->logbuffer_head])
return;
}
vsnprintf(tmpbuffer, sizeof(tmpbuffer), fmt, args);
mutex_lock(&chip->logbuffer_lock);
if (fusb302_log_full(chip)) {
chip->logbuffer_head = max(chip->logbuffer_head - 1, 0);
strscpy(tmpbuffer, "overflow", sizeof(tmpbuffer));
}
if (chip->logbuffer_head < 0 ||
chip->logbuffer_head >= LOG_BUFFER_ENTRIES) {
dev_warn(chip->dev,
"Bad log buffer index %d\n", chip->logbuffer_head);
goto abort;
Annotation
- Immediate include surface: `drm/bridge/aux-bridge.h`, `linux/debugfs.h`, `linux/delay.h`, `linux/errno.h`, `linux/extcon.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/interrupt.h`.
- Detected declarations: `struct fusb302_chip`, `enum toggling_mode`, `enum src_current_status`, `function fusb302_log_full`, `function _fusb302_log`, `function fusb302_log`, `function fusb302_debug_show`, `function fusb302_debugfs_init`, `function fusb302_debugfs_exit`, `function fusb302_log`.
- 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.
- 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.