drivers/usb/dwc3/dwc3-imx.c

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

File Facts

System
Linux kernel
Corpus path
drivers/usb/dwc3/dwc3-imx.c
Extension
.c
Size
11449 bytes
Lines
449
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct dwc3_imx {
	struct dwc3	dwc;
	struct device	*dev;
	void __iomem	*blkctl_base;
	void __iomem	*glue_base;
	struct clk	*hsio_clk;
	struct clk	*suspend_clk;
	int		irq;
	bool		pm_suspended;
	bool		wakeup_pending;
	unsigned	permanent_attached:1;
	unsigned	disable_pwr_ctrl:1;
	unsigned	overcur_active_low:1;
	unsigned	power_active_low:1;
};

#define to_dwc3_imx(d) container_of((d), struct dwc3_imx, dwc)

static void dwc3_imx_get_property(struct dwc3_imx *dwc_imx)
{
	struct device	*dev = dwc_imx->dev;

	dwc_imx->permanent_attached =
		device_property_read_bool(dev, "fsl,permanently-attached");
	dwc_imx->disable_pwr_ctrl =
		device_property_read_bool(dev, "fsl,disable-port-power-control");
	dwc_imx->overcur_active_low =
		device_property_read_bool(dev, "fsl,over-current-active-low");
	dwc_imx->power_active_low =
		device_property_read_bool(dev, "fsl,power-active-low");
}

static void dwc3_imx_configure_glue(struct dwc3_imx *dwc_imx)
{
	u32		value;

	if (!dwc_imx->glue_base)
		return;

	value = readl(dwc_imx->glue_base + USB_CTRL0);

	if (dwc_imx->permanent_attached)
		value |= USB_CTRL0_USB2_FIXED | USB_CTRL0_USB3_FIXED;
	else
		value &= ~(USB_CTRL0_USB2_FIXED | USB_CTRL0_USB3_FIXED);

	if (dwc_imx->disable_pwr_ctrl)
		value &= ~USB_CTRL0_PORTPWR_EN;
	else
		value |= USB_CTRL0_PORTPWR_EN;

	writel(value, dwc_imx->glue_base + USB_CTRL0);

	value = readl(dwc_imx->glue_base + USB_CTRL1);
	if (dwc_imx->overcur_active_low)
		value |= USB_CTRL1_OC_POLARITY;
	else
		value &= ~USB_CTRL1_OC_POLARITY;

	if (dwc_imx->power_active_low)
		value |= USB_CTRL1_PWR_POLARITY;
	else
		value &= ~USB_CTRL1_PWR_POLARITY;

	writel(value, dwc_imx->glue_base + USB_CTRL1);
}

static void dwc3_imx_wakeup_enable(struct dwc3_imx *dwc_imx, pm_message_t msg)
{
	struct dwc3	*dwc = &dwc_imx->dwc;
	u32		val;

	val = readl(dwc_imx->blkctl_base + USB_WAKEUP_CTRL);

	if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && dwc->xhci) {
		val |= USB_WAKEUP_EN | USB_WAKEUP_DPDM_EN;
		if (PMSG_IS_AUTO(msg))
			val |= USB_WAKEUP_SS_CONN | USB_WAKEUP_U3_EN;
	} else {
		val |= USB_WAKEUP_EN | USB_WAKEUP_VBUS_EN |
		       USB_WAKEUP_VBUS_SRC_SESS_VAL;
	}

	writel(val, dwc_imx->blkctl_base + USB_WAKEUP_CTRL);
}

static void dwc3_imx_wakeup_disable(struct dwc3_imx *dwc_imx)
{
	u32	val;

Annotation

Implementation Notes