drivers/usb/dwc3/debugfs.c

Source file repositories/reference/linux-study-clean/drivers/usb/dwc3/debugfs.c

File Facts

System
Linux kernel
Corpus path
drivers/usb/dwc3/debugfs.c
Extension
.c
Size
25433 bytes
Lines
1040
Domain
Driver Families
Bucket
drivers/usb
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern 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.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations dwc3_lsp_fops = {
	.open			= dwc3_lsp_open,
	.write			= dwc3_lsp_write,
	.read			= seq_read,
	.llseek			= seq_lseek,
	.release		= single_release,
};

static int dwc3_mode_show(struct seq_file *s, void *unused)
{
	struct dwc3		*dwc = s->private;
	unsigned long		flags;
	u32			reg;
	u32			mode;
	int			ret;

	ret = pm_runtime_resume_and_get(dwc->dev);
	if (ret < 0)
		return ret;

	spin_lock_irqsave(&dwc->lock, flags);
	reg = dwc3_readl(dwc, DWC3_GCTL);
	spin_unlock_irqrestore(&dwc->lock, flags);

	mode = DWC3_GCTL_PRTCAP(reg);
	switch (mode) {
	case DWC3_GCTL_PRTCAP_HOST:
	case DWC3_GCTL_PRTCAP_DEVICE:
	case DWC3_GCTL_PRTCAP_OTG:
		seq_printf(s, "%s\n", dwc3_mode_string(mode));
		break;
	default:
		seq_printf(s, "UNKNOWN %08x\n", mode);
	}

	pm_runtime_put_sync(dwc->dev);

	return 0;
}

static int dwc3_mode_open(struct inode *inode, struct file *file)
{
	return single_open(file, dwc3_mode_show, inode->i_private);
}

static ssize_t dwc3_mode_write(struct file *file,
		const char __user *ubuf, size_t count, loff_t *ppos)
{
	struct seq_file		*s = file->private_data;
	struct dwc3		*dwc = s->private;
	u32			mode = 0;
	char			buf[32];

	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
		return -EFAULT;

	if (dwc->dr_mode != USB_DR_MODE_OTG)
		return count;

	if (!strncmp(buf, "host", 4))
		mode = DWC3_GCTL_PRTCAP_HOST;

	if (!strncmp(buf, "device", 6))
		mode = DWC3_GCTL_PRTCAP_DEVICE;

	if (!strncmp(buf, "otg", 3))
		mode = DWC3_GCTL_PRTCAP_OTG;

	dwc3_set_mode(dwc, mode);

	return count;
}

static const struct file_operations dwc3_mode_fops = {
	.open			= dwc3_mode_open,
	.write			= dwc3_mode_write,
	.read			= seq_read,
	.llseek			= seq_lseek,
	.release		= single_release,
};

static int dwc3_testmode_show(struct seq_file *s, void *unused)
{
	struct dwc3		*dwc = s->private;
	unsigned long		flags;
	u32			reg;
	int			ret;

	ret = pm_runtime_resume_and_get(dwc->dev);
	if (ret < 0)

Annotation

Implementation Notes