@@ -231,6 +231,7 @@ struct otg_switch_mtk {
* @u3p_dis_msk: mask of disabling usb3 ports, for example, bit0==1 to
* disable u3port0, bit1==1 to disable u3port1,... etc
* @dbgfs_root: only used when supports manual dual-role switch via debugfs
+ * @force_vbus: without Vbus PIN, SW need set force_vbus state for device
* @uwk_en: it's true when supports remote wakeup in host mode
* @uwk: syscon including usb wakeup glue layer between SSUSB IP and SPM
* @uwk_reg_base: the base address of the wakeup glue layer in @uwk
@@ -257,6 +258,7 @@ struct ssusb_mtk {
int u3_ports;
int u3p_dis_msk;
struct dentry *dbgfs_root;
+ bool force_vbus;
/* usb wakeup for host mode */
bool uwk_en;
struct regmap *uwk;
@@ -415,6 +417,7 @@ static inline void mtu3_clrbits(void __iomem *base, u32 offset, u32 bits)
}
int ssusb_check_clocks(struct ssusb_mtk *ssusb, u32 ex_clks);
+void ssusb_set_force_vbus(struct ssusb_mtk *ssusb, bool vbus_on);
struct usb_request *mtu3_alloc_request(struct usb_ep *ep, gfp_t gfp_flags);
void mtu3_free_request(struct usb_ep *ep, struct usb_request *req);
void mtu3_req_complete(struct mtu3_ep *mep,
@@ -604,6 +604,7 @@ static void mtu3_regs_init(struct mtu3 *mtu)
/* enable automatical HWRW from L1 */
mtu3_setbits(mbase, U3D_POWER_MANAGEMENT, LPM_HRWE);
+ ssusb_set_force_vbus(mtu->ssusb, true);
/* use new QMU format when HW version >= 0x1003 */
if (mtu->gen2cp)
mtu3_writel(mbase, U3D_QFCR, ~0x0);
@@ -173,8 +173,10 @@ static void ssusb_set_mailbox(struct otg_switch_mtk *otg_sx,
case MTU3_VBUS_OFF:
mtu3_stop(mtu);
pm_relax(ssusb->dev);
+ ssusb_set_force_vbus(ssusb, false);
break;
case MTU3_VBUS_VALID:
+ ssusb_set_force_vbus(ssusb, true);
/* avoid suspend when works as device */
pm_stay_awake(ssusb->dev);
mtu3_start(mtu);
@@ -205,6 +205,7 @@ static void ssusb_host_setup(struct ssusb_mtk *ssusb)
ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_HOST);
/* if port0 supports dual-role, works as host mode by default */
+ ssusb_set_force_vbus(ssusb, false);
ssusb_set_vbus(&ssusb->otg_switch, 1);
}
@@ -45,6 +45,27 @@ int ssusb_check_clocks(struct ssusb_mtk *ssusb, u32 ex_clks)
return 0;
}
+void ssusb_set_force_vbus(struct ssusb_mtk *ssusb, bool vbus_on)
+{
+ u32 u2ctl;
+ u32 misc;
+
+ if (!ssusb->force_vbus)
+ return;
+
+ u2ctl = mtu3_readl(ssusb->ippc_base, SSUSB_U2_CTRL(0));
+ misc = mtu3_readl(ssusb->mac_base, U3D_MISC_CTRL);
+ if (vbus_on) {
+ u2ctl &= ~SSUSB_U2_PORT_OTG_SEL;
+ misc |= VBUS_FRC_EN | VBUS_ON;
+ } else {
+ u2ctl |= SSUSB_U2_PORT_OTG_SEL;
+ misc &= ~(VBUS_FRC_EN | VBUS_ON);
+ }
+ mtu3_writel(ssusb->ippc_base, SSUSB_U2_CTRL(0), u2ctl);
+ mtu3_writel(ssusb->mac_base, U3D_MISC_CTRL, misc);
+}
+
static int ssusb_phy_init(struct ssusb_mtk *ssusb)
{
int i;
@@ -268,6 +289,8 @@ static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb)
if (IS_ERR(ssusb->ippc_base))
return PTR_ERR(ssusb->ippc_base);
+ ssusb->force_vbus = of_property_read_bool(node, "mediatek,force-vbus");
+
ssusb->dr_mode = usb_get_dr_mode(dev);
if (ssusb->dr_mode == USB_DR_MODE_UNKNOWN)
ssusb->dr_mode = USB_DR_MODE_OTG;
Some SoCs don't support Vbus detection due to non-exist Vbus PIN, so software need set force_vbus state when the controller works as device mode. Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com> --- drivers/usb/mtu3/mtu3.h | 3 +++ drivers/usb/mtu3/mtu3_core.c | 1 + drivers/usb/mtu3/mtu3_dr.c | 2 ++ drivers/usb/mtu3/mtu3_host.c | 1 + drivers/usb/mtu3/mtu3_plat.c | 23 +++++++++++++++++++++++ 5 files changed, 30 insertions(+)