Re: [PATCH -next] usb: mtu3: fix dbginfo in qmu_tx_zlp_error_handler

2018-12-06 Thread Chunfeng Yun
Hi Haibing,

On Fri, 2018-12-07 at 03:52 +, YueHaibing wrote:
> Fixes gcc '-Wunused-but-set-variable' warning:
> 
> drivers/usb/mtu3/mtu3_qmu.c: In function 'qmu_tx_zlp_error_handler':
> drivers/usb/mtu3/mtu3_qmu.c:385:22: warning:
>  variable 'req' set but not used [-Wunused-but-set-variable]
> 
> It seems dbginfo original intention is print 'req' other than 'mreq'
> 
> Signed-off-by: YueHaibing 
> ---
>  drivers/usb/mtu3/mtu3_qmu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/mtu3/mtu3_qmu.c b/drivers/usb/mtu3/mtu3_qmu.c
> index 73ac042..09f19f7 100644
> --- a/drivers/usb/mtu3/mtu3_qmu.c
> +++ b/drivers/usb/mtu3/mtu3_qmu.c
> @@ -402,7 +402,7 @@ static void qmu_tx_zlp_error_handler(struct mtu3 *mtu, u8 
> epnum)
>   return;
>   }
>  
> - dev_dbg(mtu->dev, "%s send ZLP for req=%p\n", __func__, mreq);
> + dev_dbg(mtu->dev, "%s send ZLP for req=%p\n", __func__, req);
>  
>   mtu3_clrbits(mbase, MU3D_EP_TXCR0(mep->epnum), TX_DMAREQEN);
> 
Acked-by: Chunfeng Yun 

Thanks a lot
> 
> 




Re: [RFT PATCH 1/2] xhci: Fix leaking USB3 shared_hcd at xhci removal

2018-09-27 Thread Chunfeng Yun
On Thu, 2018-09-27 at 19:26 +0300, Mathias Nyman wrote:
> Ensure that the shared_hcd pointer is valid when calling usb_put_hcd()
> 
> The shared_hcd is removed and freed in xhci by first calling
> usb_remove_hcd(xhci->shared_hcd), and later
> usb_put_hcd(xhci->shared_hcd)
> 
> Afer commit fe190ed0d602 ("xhci: Do not halt the host until both HCD have
> disconnected their devices.") the shared_hcd was never properly put as
> xhci->shared_hcd was set to NULL before usb_put_hcd(xhci->shared_hcd) was
> called.
> 
> shared_hcd (USB3) is removed before primary hcd (USB2).
> While removing the primary hcd we might need to handle xhci interrupts
> to cleanly remove last USB2 devices, therefore we need to set
> xhci->shared_hcd to NULL before removing the primary hcd to let xhci
> interrupt handler know shared_hcd is no longer available.
> 
> xhci-plat.c, xhci-histb.c and xhci-mtk first create both their hcd's before
> adding them. so to keep the correct reverse removal order use a temporary
> shared_hcd variable for them.
> For more details see commit 4ac53087d6d4 ("usb: xhci: plat: Create both
> HCDs before adding them")
> 
> Fixes: fe190ed0d602 ("xhci: Do not halt the host until both HCD have 
> disconnected their devices.")
> Cc: Joel Stanley 
> Cc: Chunfeng Yun 
> Cc: Thierry Reding 
> Cc: Jianguo Sun 
> Cc: 
> Reported-by: Jack Pham 
> Signed-off-by: Mathias Nyman 
> ---
>  drivers/usb/host/xhci-histb.c | 6 --
>  drivers/usb/host/xhci-mtk.c   | 6 --
>  drivers/usb/host/xhci-pci.c   | 1 +
>  drivers/usb/host/xhci-plat.c  | 6 --
>  drivers/usb/host/xhci-tegra.c | 1 +
>  drivers/usb/host/xhci.c   | 2 --
>  6 files changed, 14 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci-histb.c b/drivers/usb/host/xhci-histb.c
> index 27f0016..3c4abb5 100644
> --- a/drivers/usb/host/xhci-histb.c
> +++ b/drivers/usb/host/xhci-histb.c
> @@ -325,14 +325,16 @@ static int xhci_histb_remove(struct platform_device 
> *dev)
>   struct xhci_hcd_histb *histb = platform_get_drvdata(dev);
>   struct usb_hcd *hcd = histb->hcd;
>   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
> + struct usb_hcd *shared_hcd = xhci->shared_hcd;
>  
>   xhci->xhc_state |= XHCI_STATE_REMOVING;
>  
> - usb_remove_hcd(xhci->shared_hcd);
> + usb_remove_hcd(shared_hcd);
> + xhci->shared_hcd = NULL;
>   device_wakeup_disable(>dev);
>  
>   usb_remove_hcd(hcd);
> - usb_put_hcd(xhci->shared_hcd);
> + usb_put_hcd(shared_hcd);
>  
>   xhci_histb_host_disable(histb);
>   usb_put_hcd(hcd);
> diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
> index 71d0d33..60987c7 100644
> --- a/drivers/usb/host/xhci-mtk.c
> +++ b/drivers/usb/host/xhci-mtk.c
> @@ -590,12 +590,14 @@ static int xhci_mtk_remove(struct platform_device *dev)
>   struct xhci_hcd_mtk *mtk = platform_get_drvdata(dev);
>   struct usb_hcd  *hcd = mtk->hcd;
>   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
> + struct usb_hcd  *shared_hcd = xhci->shared_hcd;
>  
> - usb_remove_hcd(xhci->shared_hcd);
> + usb_remove_hcd(shared_hcd);
> + xhci->shared_hcd = NULL;
>   device_init_wakeup(>dev, false);
>  
>   usb_remove_hcd(hcd);
> - usb_put_hcd(xhci->shared_hcd);
> + usb_put_hcd(shared_hcd);
>   usb_put_hcd(hcd);
>   xhci_mtk_sch_exit(mtk);
>   xhci_mtk_clks_disable(mtk);
> diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
> index 51dd8e0..92fd6b6 100644
> --- a/drivers/usb/host/xhci-pci.c
> +++ b/drivers/usb/host/xhci-pci.c
> @@ -356,6 +356,7 @@ static void xhci_pci_remove(struct pci_dev *dev)
>   if (xhci->shared_hcd) {
>   usb_remove_hcd(xhci->shared_hcd);
>   usb_put_hcd(xhci->shared_hcd);
> + xhci->shared_hcd = NULL;
>   }
>  
>   /* Workaround for spurious wakeups at shutdown with HSW */
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index 94e9392..e5da8ce 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -359,14 +359,16 @@ static int xhci_plat_remove(struct platform_device *dev)
>   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
>   struct clk *clk = xhci->clk;
>   struct clk *reg_clk = xhci->reg_clk;
> + struct usb_hcd *shared_hcd = xhci->shared_hcd;
>  
>   xhci->xhc_state |= XHCI_STATE_REMOVING;
>  
> - usb_remove_hcd(xhci->shared_hcd);
> + usb_remove_hcd(shared_hcd);
> + xhci->shared_hcd = NULL;
>   usb_phy_shutdown(hcd->usb_p

[PATCH] usb: gadget: composite: fix delayed_status race condition when set_interface

2018-05-25 Thread Chunfeng Yun
It happens when enable debug log, if set_alt() returns
USB_GADGET_DELAYED_STATUS and usb_composite_setup_continue()
is called before increasing count of @delayed_status,
so fix it by using spinlock of @cdev->lock.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
Tested-by: Jay Hsu <shih-chieh@mediatek.com>
---
 drivers/usb/gadget/composite.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index f242c2b..d2fa071 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1719,6 +1719,8 @@ static int fill_ext_prop(struct usb_configuration *c, int 
interface, u8 *buf)
 */
if (w_value && !f->get_alt)
break;
+
+   spin_lock(>lock);
value = f->set_alt(f, w_index, w_value);
if (value == USB_GADGET_DELAYED_STATUS) {
DBG(cdev,
@@ -1728,6 +1730,7 @@ static int fill_ext_prop(struct usb_configuration *c, int 
interface, u8 *buf)
DBG(cdev, "delayed_status count %d\n",
cdev->delayed_status);
}
+   spin_unlock(>lock);
break;
case USB_REQ_GET_INTERFACE:
if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[next, PATCH 4/6] usb: mtu3: avoid sleep in atomic context when enter test mode

2018-05-23 Thread Chunfeng Yun
Use readl_poll_timeout_atomic() instead of readl_poll_timeout()
in atomic context

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_gadget_ep0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c 
b/drivers/usb/mtu3/mtu3_gadget_ep0.c
index 0d2b1cf..25216e7 100644
--- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
+++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
@@ -299,7 +299,7 @@ static int handle_test_mode(struct mtu3 *mtu, struct 
usb_ctrlrequest *setup)
mtu3_writel(mbase, U3D_EP0CSR, value | EP0_SETUPPKTRDY | EP0_DATAEND);
 
/* wait for ACK status sent by host */
-   readl_poll_timeout(mbase + U3D_EP0CSR, value,
+   readl_poll_timeout_atomic(mbase + U3D_EP0CSR, value,
!(value & EP0_DATAEND), 100, 5000);
 
mtu3_writel(mbase, U3D_USB2_TEST_MODE, mtu->test_mode_nr);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[next, PATCH 3/6] usb: mtu3: clear test_mode flag when reset

2018-05-23 Thread Chunfeng Yun
Clear test_mode flag when the gadget is reset by host, otherwise
will affect the next test item.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_gadget.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
index de0de01..5c60a8c 100644
--- a/drivers/usb/mtu3/mtu3_gadget.c
+++ b/drivers/usb/mtu3/mtu3_gadget.c
@@ -719,4 +719,5 @@ void mtu3_gadget_reset(struct mtu3 *mtu)
mtu->u1_enable = 0;
mtu->u2_enable = 0;
mtu->delayed_status = false;
+   mtu->test_mode = false;
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[next, PATCH 1/6] usb: mtu3: re-enable controller to accept LPM request after LPM resume

2018-05-23 Thread Chunfeng Yun
After the controller receives a LPM request, it will reject the LPM
request, and need software to re-enable it after LPM resume if the
controller doesn't remote wakeup from L1 automatically

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_core.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c
index b1b99a8..65ff53a 100644
--- a/drivers/usb/mtu3/mtu3_core.c
+++ b/drivers/usb/mtu3/mtu3_core.c
@@ -176,7 +176,7 @@ static void mtu3_intr_enable(struct mtu3 *mtu)
mtu3_writel(mbase, U3D_LV1IESR, value);
 
/* Enable U2 common USB interrupts */
-   value = SUSPEND_INTR | RESUME_INTR | RESET_INTR;
+   value = SUSPEND_INTR | RESUME_INTR | RESET_INTR | LPM_RESUME_INTR;
mtu3_writel(mbase, U3D_COMMON_USB_INTR_ENABLE, value);
 
if (mtu->is_u3_ip) {
@@ -692,6 +692,12 @@ static irqreturn_t mtu3_u2_common_isr(struct mtu3 *mtu)
if (u2comm & RESET_INTR)
mtu3_gadget_reset(mtu);
 
+   if (u2comm & LPM_RESUME_INTR) {
+   if (!(mtu3_readl(mbase, U3D_POWER_MANAGEMENT) & LPM_HRWE))
+   mtu3_setbits(mbase, U3D_USB20_MISC_CONTROL,
+LPM_U3_ACK_EN);
+   }
+
return IRQ_HANDLED;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[next, PATCH 6/6] usb: mtu3: fix warning of sleep in atomic context in notifier callback

2018-05-23 Thread Chunfeng Yun
The notifier callbacks of extcon are called in atomic context, but the
callbacks will call regulator_enable()/regulator_disable() which may
sleep caused by mutex, so use work queue to call the sleep functions.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3.h| 11 ++-
 drivers/usb/mtu3/mtu3_dr.c | 44 
 2 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index a56fee0..87823ac 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -196,7 +196,12 @@ struct mtu3_gpd_ring {
 * @vbus: vbus 5V used by host mode
 * @edev: external connector used to detect vbus and iddig changes
 * @vbus_nb: notifier for vbus detection
-* @vbus_nb: notifier for iddig(idpin) detection
+* @vbus_work : work of vbus detection notifier, used to avoid sleep in
+*  notifier callback which is atomic context
+* @vbus_event : event of vbus detecion notifier
+* @id_nb : notifier for iddig(idpin) detection
+* @id_work : work of iddig detection notifier
+* @id_event : event of iddig detecion notifier
 * @is_u3_drd: whether port0 supports usb3.0 dual-role device or not
 * @manual_drd_enabled: it's true when supports dual-role device by debugfs
 *  to switch host/device modes depending on user input.
@@ -205,7 +210,11 @@ struct otg_switch_mtk {
struct regulator *vbus;
struct extcon_dev *edev;
struct notifier_block vbus_nb;
+   struct work_struct vbus_work;
+   unsigned long vbus_event;
struct notifier_block id_nb;
+   struct work_struct id_work;
+   unsigned long id_event;
bool is_u3_drd;
bool manual_drd_enabled;
 };
diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c
index 80083e0..8c3bbf7 100644
--- a/drivers/usb/mtu3/mtu3_dr.c
+++ b/drivers/usb/mtu3/mtu3_dr.c
@@ -174,16 +174,40 @@ static void ssusb_set_mailbox(struct otg_switch_mtk 
*otg_sx,
}
 }
 
-static int ssusb_id_notifier(struct notifier_block *nb,
-   unsigned long event, void *ptr)
+static void ssusb_id_work(struct work_struct *work)
 {
struct otg_switch_mtk *otg_sx =
-   container_of(nb, struct otg_switch_mtk, id_nb);
+   container_of(work, struct otg_switch_mtk, id_work);
 
-   if (event)
+   if (otg_sx->id_event)
ssusb_set_mailbox(otg_sx, MTU3_ID_GROUND);
else
ssusb_set_mailbox(otg_sx, MTU3_ID_FLOAT);
+}
+
+static void ssusb_vbus_work(struct work_struct *work)
+{
+   struct otg_switch_mtk *otg_sx =
+   container_of(work, struct otg_switch_mtk, vbus_work);
+
+   if (otg_sx->vbus_event)
+   ssusb_set_mailbox(otg_sx, MTU3_VBUS_VALID);
+   else
+   ssusb_set_mailbox(otg_sx, MTU3_VBUS_OFF);
+}
+
+/*
+ * @ssusb_id_notifier is called in atomic context, but @ssusb_set_mailbox
+ * may sleep, so use work queue here
+ */
+static int ssusb_id_notifier(struct notifier_block *nb,
+   unsigned long event, void *ptr)
+{
+   struct otg_switch_mtk *otg_sx =
+   container_of(nb, struct otg_switch_mtk, id_nb);
+
+   otg_sx->id_event = event;
+   schedule_work(_sx->id_work);
 
return NOTIFY_DONE;
 }
@@ -194,10 +218,8 @@ static int ssusb_vbus_notifier(struct notifier_block *nb,
struct otg_switch_mtk *otg_sx =
container_of(nb, struct otg_switch_mtk, vbus_nb);
 
-   if (event)
-   ssusb_set_mailbox(otg_sx, MTU3_VBUS_VALID);
-   else
-   ssusb_set_mailbox(otg_sx, MTU3_VBUS_OFF);
+   otg_sx->vbus_event = event;
+   schedule_work(_sx->vbus_work);
 
return NOTIFY_DONE;
 }
@@ -398,6 +420,9 @@ int ssusb_otg_switch_init(struct ssusb_mtk *ssusb)
 {
struct otg_switch_mtk *otg_sx = >otg_switch;
 
+   INIT_WORK(_sx->id_work, ssusb_id_work);
+   INIT_WORK(_sx->vbus_work, ssusb_vbus_work);
+
if (otg_sx->manual_drd_enabled)
ssusb_debugfs_init(ssusb);
else
@@ -412,4 +437,7 @@ void ssusb_otg_switch_exit(struct ssusb_mtk *ssusb)
 
if (otg_sx->manual_drd_enabled)
ssusb_debugfs_exit(ssusb);
+
+   cancel_work_sync(_sx->id_work);
+   cancel_work_sync(_sx->vbus_work);
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[next, PATCH 5/6] usb: mtu3: reset gadget when VBUS_FALL interrupt arises

2018-05-23 Thread Chunfeng Yun
When VBUS_FALL interrupt arises, it means U3 device is disconnected
with host, so need reset status of gadget

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c
index 279f9cd..eecfd06 100644
--- a/drivers/usb/mtu3/mtu3_core.c
+++ b/drivers/usb/mtu3/mtu3_core.c
@@ -668,8 +668,10 @@ static irqreturn_t mtu3_u3_ltssm_isr(struct mtu3 *mtu)
if (ltssm & (HOT_RST_INTR | WARM_RST_INTR))
mtu3_gadget_reset(mtu);
 
-   if (ltssm & VBUS_FALL_INTR)
+   if (ltssm & VBUS_FALL_INTR) {
mtu3_ss_func_set(mtu, false);
+   mtu3_gadget_reset(mtu);
+   }
 
if (ltssm & VBUS_RISE_INTR)
mtu3_ss_func_set(mtu, true);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[next, PATCH 2/6] usb: mtu3: fix uncontinuous SeqN issue after disable EP

2018-05-23 Thread Chunfeng Yun
Reset EP when disable it to reset data toggle for U2 EP, and
SeqN, flow control status etc for U3 EP, this can avoid
issue of uncontinuous SeqN

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_core.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c
index 65ff53a..279f9cd 100644
--- a/drivers/usb/mtu3/mtu3_core.c
+++ b/drivers/usb/mtu3/mtu3_core.c
@@ -195,6 +195,16 @@ static void mtu3_intr_enable(struct mtu3 *mtu)
mtu3_writel(mbase, U3D_DEV_LINK_INTR_ENABLE, SSUSB_DEV_SPEED_CHG_INTR);
 }
 
+/* reset: u2 - data toggle, u3 - SeqN, flow control status etc */
+static void mtu3_ep_reset(struct mtu3_ep *mep)
+{
+   struct mtu3 *mtu = mep->mtu;
+   u32 rst_bit = EP_RST(mep->is_in, mep->epnum);
+
+   mtu3_setbits(mtu->mac_base, U3D_EP_RST, rst_bit);
+   mtu3_clrbits(mtu->mac_base, U3D_EP_RST, rst_bit);
+}
+
 /* set/clear the stall and toggle bits for non-ep0 */
 void mtu3_ep_stall_set(struct mtu3_ep *mep, bool set)
 {
@@ -220,8 +230,7 @@ void mtu3_ep_stall_set(struct mtu3_ep *mep, bool set)
}
 
if (!set) {
-   mtu3_setbits(mbase, U3D_EP_RST, EP_RST(mep->is_in, epnum));
-   mtu3_clrbits(mbase, U3D_EP_RST, EP_RST(mep->is_in, epnum));
+   mtu3_ep_reset(mep);
mep->flags &= ~MTU3_EP_STALL;
} else {
mep->flags |= MTU3_EP_STALL;
@@ -400,6 +409,7 @@ void mtu3_deconfig_ep(struct mtu3 *mtu, struct mtu3_ep *mep)
mtu3_setbits(mbase, U3D_QIECR0, QMU_RX_DONE_INT(epnum));
}
 
+   mtu3_ep_reset(mep);
ep_fifo_free(mep);
 
dev_dbg(mtu->dev, "%s: %s\n", __func__, mep->name);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 1/2] dt-bindings: add MediaTek XS-PHY binding

2018-05-10 Thread Chunfeng Yun
Add a DT binding documentation of XS-PHY for MediaTek SoCs
with USB3.1 GEN2 controller

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 .../devicetree/bindings/phy/phy-mtk-xsphy.txt  |  110 
 1 file changed, 110 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt

diff --git a/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt 
b/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
new file mode 100644
index 000..7f2b16f
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
@@ -0,0 +1,110 @@
+MediaTek XS-PHY binding
+--
+
+The XS-PHY controller supports physical layer functionality for USB3.1
+GEN2 controller on MediaTek SoCs.
+
+Required properties (controller (parent) node):
+ - compatible  : should be "mediatek,-xsphy", "mediatek,xsphy",
+ soc-model is the name of SoC, such as mt3611 etc;
+ when using "mediatek,xsphy" compatible string, you need SoC 
specific
+ ones in addition, one of:
+ - "mediatek,mt3611-xsphy"
+
+ - #address-cells, #size-cells : should use the same values as the root node
+ - ranges: must be present
+
+Optional properties (controller (parent) node):
+ - reg : offset and length of register shared by multiple U3 ports,
+ exclude port's private register, if only U2 ports provided,
+ shouldn't use the property.
+ - mediatek,src-ref-clk-mhz: u32, frequency of reference clock for slew 
rate
+ calibrate
+ - mediatek,src-coef   : u32, coefficient for slew rate calibrate, depends on
+ SoC process
+
+Required nodes : a sub-node is required for each port the controller
+ provides. Address range information including the usual
+ 'reg' property is used inside these nodes to describe
+ the controller's topology.
+
+Required properties (port (child) node):
+- reg  : address and length of the register set for the port.
+- clocks   : a list of phandle + clock-specifier pairs, one for each
+ entry in clock-names
+- clock-names  : must contain
+ "ref": 48M reference clock for HighSpeed analog phy; and 26M
+   reference clock for SuperSpeedPlus analog phy, 
sometimes is
+   24M, 25M or 27M, depended on platform.
+- #phy-cells   : should be 1
+ cell after port phandle is phy type from:
+   - PHY_TYPE_USB2
+   - PHY_TYPE_USB3
+
+The following optional properties are only for debug or HQA test
+Optional properties (PHY_TYPE_USB2 port (child) node):
+- mediatek,eye-src : u32, the value of slew rate calibrate
+- mediatek,eye-vrt : u32, the selection of VRT reference voltage
+- mediatek,eye-term: u32, the selection of HS_TX TERM reference voltage
+- mediatek,efuse-intr  : u32, the selection of Internal Resistor
+
+Optional properties (PHY_TYPE_USB3 port (child) node):
+- mediatek,efuse-intr  : u32, the selection of Internal Resistor
+- mediatek,efuse-tx-imp: u32, the selection of TX Impedance
+- mediatek,efuse-rx-imp: u32, the selection of RX Impedance
+
+Banks layout of xsphy
+-
+portoffsetbank
+u2 port00xMISC
+0x0100FMREG
+0x0300U2PHY_COM
+u2 port10x1000MISC
+0x1100FMREG
+0x1300U2PHY_COM
+u2 port20x2000MISC
+...
+u31 common  0x3000DIG_GLB
+0x3100PHYA_GLB
+u31 port0   0x3400DIG_LN_TOP
+0x3500DIG_LN_TX0
+0x3600DIG_LN_RX0
+0x3700DIG_LN_DAIF
+0x3800PHYA_LN
+u31 port1   0x3a00DIG_LN_TOP
+0x3b00DIG_LN_TX0
+0x3c00DIG_LN_RX0
+0x3d00DIG_LN_DAIF
+0x3e00PHYA_LN
+...
+
+DIG_GLB & PHYA_GLB are shared by U31 ports.
+
+Example:
+
+u3phy: usb-phy@11c4 {
+   compatible = "mediatek,mt3611-xsphy", "mediatek,xsphy";
+   reg = <0 0x11c43000 0 0x0200>;
+   mediatek,src-ref-clk-mhz = <26>;
+   mediatek,src-coef = <17>;
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   u2port0: usb-phy@11c4 {
+   reg = <0 0x11c4 0 0x0400>;
+   clocks = <>;
+   clock-names = "ref";
+   mediatek,eye-src = <4>;
+   #phy-cells = <1>;
+   };
+
+   u3port0: usb-phy@11c43000 {
+   reg = <0 0x11c43400 0 0x0500>;
+   clocks = <>;
+   clock-names = "ref";
+   mediatek,efuse-intr = <28>

Add MediaTek XS-PHY driver

2018-05-10 Thread Chunfeng Yun
>From 2ca1243f228633ca9dd96d3e4068af9e2936cd51 Mon Sep 17 00:00:00 2001
From: Chunfeng Yun <chunfeng@mediatek.com>
Date: Thu, 10 May 2018 13:55:52 +0800
Subject: [PATCH v3 0/2]  Add MediaTek XS-PHY driver

This patch series support the SuperSpeedPlus XS-PHY transceiver for
USB3.1 GEN2 controller on MediaTek chips. The driver supports multiple
USB2.0, USB3.1 GEN2 ports.

v3: changes in binding (suggested by Rob)
1. use the correct name of SoC as soc-model's example

v2: changes in binding (suggested by Rob)
1. list all valid SoCs for compatible
2. move required child nodes after parent optional ones
3. remove status property in example
4. move banks layout example before dts one
5. remove phy binding example
6. add #address-cells, #size-cells, ranges properties for parent node


Chunfeng Yun (2):
  dt-bindings: add MediaTek XS-PHY binding
  phy: mediatek: add XS-PHY driver

 .../devicetree/bindings/phy/phy-mtk-xsphy.txt  | 110 
 drivers/phy/mediatek/Kconfig   |   9 +
 drivers/phy/mediatek/Makefile  |   1 +
 drivers/phy/mediatek/phy-mtk-xsphy.c   | 600 +
 4 files changed, 720 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
 create mode 100644 drivers/phy/mediatek/phy-mtk-xsphy.c

--
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 2/2] phy: mediatek: add XS-PHY driver

2018-05-10 Thread Chunfeng Yun
Support XS-PHY for MediaTek SoCs with USB3.1 GEN2 controller

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/phy/mediatek/Kconfig |9 +
 drivers/phy/mediatek/Makefile|1 +
 drivers/phy/mediatek/phy-mtk-xsphy.c |  600 ++
 3 files changed, 610 insertions(+)
 create mode 100644 drivers/phy/mediatek/phy-mtk-xsphy.c

diff --git a/drivers/phy/mediatek/Kconfig b/drivers/phy/mediatek/Kconfig
index 88ab4e2..8857d00 100644
--- a/drivers/phy/mediatek/Kconfig
+++ b/drivers/phy/mediatek/Kconfig
@@ -12,3 +12,12 @@ config PHY_MTK_TPHY
  different banks layout, the T-PHY with shared banks between
  multi-ports is first version, otherwise is second veriosn,
  so you can easily distinguish them by banks layout.
+
+config PHY_MTK_XSPHY
+tristate "MediaTek XS-PHY Driver"
+depends on ARCH_MEDIATEK && OF
+select GENERIC_PHY
+help
+ Enable this to support the SuperSpeedPlus XS-PHY transceiver for
+ USB3.1 GEN2 controllers on MediaTek chips. The driver supports
+ multiple USB2.0, USB3.1 GEN2 ports.
diff --git a/drivers/phy/mediatek/Makefile b/drivers/phy/mediatek/Makefile
index 1bdab14..ee49edc 100644
--- a/drivers/phy/mediatek/Makefile
+++ b/drivers/phy/mediatek/Makefile
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o
+obj-$(CONFIG_PHY_MTK_XSPHY)+= phy-mtk-xsphy.o
diff --git a/drivers/phy/mediatek/phy-mtk-xsphy.c 
b/drivers/phy/mediatek/phy-mtk-xsphy.c
new file mode 100644
index 000..020cd02
--- /dev/null
+++ b/drivers/phy/mediatek/phy-mtk-xsphy.c
@@ -0,0 +1,600 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MediaTek USB3.1 gen2 xsphy Driver
+ *
+ * Copyright (c) 2018 MediaTek Inc.
+ * Author: Chunfeng Yun <chunfeng@mediatek.com>
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* u2 phy banks */
+#define SSUSB_SIFSLV_MISC  0x000
+#define SSUSB_SIFSLV_U2FREQ0x100
+#define SSUSB_SIFSLV_U2PHY_COM 0x300
+
+/* u3 phy shared banks */
+#define SSPXTP_SIFSLV_DIG_GLB  0x000
+#define SSPXTP_SIFSLV_PHYA_GLB 0x100
+
+/* u3 phy banks */
+#define SSPXTP_SIFSLV_DIG_LN_TOP   0x000
+#define SSPXTP_SIFSLV_DIG_LN_TX0   0x100
+#define SSPXTP_SIFSLV_DIG_LN_RX0   0x200
+#define SSPXTP_SIFSLV_DIG_LN_DAIF  0x300
+#define SSPXTP_SIFSLV_PHYA_LN  0x400
+
+#define XSP_U2FREQ_FMCR0   ((SSUSB_SIFSLV_U2FREQ) + 0x00)
+#define P2F_RG_FREQDET_EN  BIT(24)
+#define P2F_RG_CYCLECNTGENMASK(23, 0)
+#define P2F_RG_CYCLECNT_VAL(x) ((P2F_RG_CYCLECNT) & (x))
+
+#define XSP_U2FREQ_MMONR0  ((SSUSB_SIFSLV_U2FREQ) + 0x0c)
+
+#define XSP_U2FREQ_FMMONR1 ((SSUSB_SIFSLV_U2FREQ) + 0x10)
+#define P2F_RG_FRCK_EN BIT(8)
+#define P2F_USB_FM_VALID   BIT(0)
+
+#define XSP_USBPHYACR0 ((SSUSB_SIFSLV_U2PHY_COM) + 0x00)
+#define P2A0_RG_INTR_ENBIT(5)
+
+#define XSP_USBPHYACR1 ((SSUSB_SIFSLV_U2PHY_COM) + 0x04)
+#define P2A1_RG_INTR_CAL   GENMASK(23, 19)
+#define P2A1_RG_INTR_CAL_VAL(x)((0x1f & (x)) << 19)
+#define P2A1_RG_VRT_SELGENMASK(14, 12)
+#define P2A1_RG_VRT_SEL_VAL(x) ((0x7 & (x)) << 12)
+#define P2A1_RG_TERM_SEL   GENMASK(10, 8)
+#define P2A1_RG_TERM_SEL_VAL(x)((0x7 & (x)) << 8)
+
+#define XSP_USBPHYACR5 ((SSUSB_SIFSLV_U2PHY_COM) + 0x014)
+#define P2A5_RG_HSTX_SRCAL_EN  BIT(15)
+#define P2A5_RG_HSTX_SRCTRLGENMASK(14, 12)
+#define P2A5_RG_HSTX_SRCTRL_VAL(x) ((0x7 & (x)) << 12)
+
+#define XSP_USBPHYACR6 ((SSUSB_SIFSLV_U2PHY_COM) + 0x018)
+#define P2A6_RG_BC11_SW_EN BIT(23)
+#define P2A6_RG_OTG_VBUSCMP_EN BIT(20)
+
+#define XSP_U2PHYDTM1  ((SSUSB_SIFSLV_U2PHY_COM) + 0x06C)
+#define P2D_FORCE_IDDIGBIT(9)
+#define P2D_RG_VBUSVALID   BIT(5)
+#define P2D_RG_SESSEND BIT(4)
+#define P2D_RG_AVALID  BIT(2)
+#define P2D_RG_IDDIG   BIT(1)
+
+#define SSPXTP_PHYA_GLB_00 ((SSPXTP_SIFSLV_PHYA_GLB) + 0x00)
+#define RG_XTP_GLB_BIAS_INTR_CTRL  GENMASK(21, 16)
+#define RG_XTP_GLB_BIAS_INTR_CTRL_VAL(x)   ((0x3f & (x)) << 16)
+
+#define SSPXTP_PHYA_LN_04  ((SSPXTP_SIFSLV_PHYA_LN) + 0x04)
+#define RG_XTP_LN0_TX_IMPSEL   GENMASK(4, 0)
+#define RG_XTP_LN0_TX_IMPSEL_VAL(x)(0x1f & (x))
+
+#define SSPXTP_PHYA_LN_14  ((SSPXTP_SIFSLV_PHYA_LN) + 0x014)
+#define RG_XTP_LN0_RX_IMPSEL   GENMASK(4, 0)
+#define RG_XTP_LN0_RX_IMPSEL_VAL(x)(0x1f & (x))
+
+#define XSP_REF_CLK26  /* MHZ */
+#define XSP_SLEW_RATE_COEF 17
+#define XSP_SR_COEF_DIVISOR1000
+#define XSP_FM_DET_CYCLE_CNT   1024
+
+struct xsphy_instance {
+   struct phy *phy;
+   void __iomem *port_base;
+   struct clk *ref_clk;/* reference clock of an

[PATCH v2 5/7] usb: mtu3: make USB_MTU3_DUAL_ROLE depend on EXTCON but not USB_MTU3

2018-05-09 Thread Chunfeng Yun
In fact the driver depends on EXTCON only when it's configed as
USB_MTU3_DUAL_ROLE, so make USB_MTU3_DUAL_ROLE depend on EXTCON but
not USB_MTU3.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/mtu3/Kconfig b/drivers/usb/mtu3/Kconfig
index 25cd619..8daf277 100644
--- a/drivers/usb/mtu3/Kconfig
+++ b/drivers/usb/mtu3/Kconfig
@@ -2,7 +2,7 @@
 
 config USB_MTU3
tristate "MediaTek USB3 Dual Role controller"
-   depends on EXTCON && (USB || USB_GADGET) && HAS_DMA
+   depends on (USB || USB_GADGET) && HAS_DMA
depends on ARCH_MEDIATEK || COMPILE_TEST
select USB_XHCI_MTK if USB_SUPPORT && USB_XHCI_HCD
help
@@ -40,6 +40,7 @@ config USB_MTU3_GADGET
 config USB_MTU3_DUAL_ROLE
bool "Dual Role mode"
depends on ((USB=y || USB=USB_MTU3) && (USB_GADGET=y || 
USB_GADGET=USB_MTU3))
+   depends on (EXTCON=y || EXTCON=USB_MTU3)
help
  This is the default mode of working of MTU3 controller where
  both host and gadget features are enabled.
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/7] usb: mtu3: avoid TX data length truncated in SS/SSP mode

2018-05-09 Thread Chunfeng Yun
The variable of 'count' is declared as u8, this will cause an issue
due to value truncated when works in SS or SSP mode and data length
is greater than 255, so change it as u32.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_gadget_ep0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c 
b/drivers/usb/mtu3/mtu3_gadget_ep0.c
index ebdcf7a..d67b540 100644
--- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
+++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
@@ -546,7 +546,7 @@ static void ep0_tx_state(struct mtu3 *mtu)
struct usb_request *req;
u32 csr;
u8 *src;
-   u8 count;
+   u32 count;
u32 maxp;
 
dev_dbg(mtu->dev, "%s\n", __func__);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 4/7] usb: mtu3: fix operation failure when test TEST_J/K

2018-05-09 Thread Chunfeng Yun
There is an error dialog popped up in PC when test TEST_J/K
by EHSETT tool, due to not waiting for the completion of
control transfer. Here fix it by entering test mode after
Status Stage finish.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
v2:
1. reset test_mode as default value when controller is reset
2. use readl_poll_timeout_atomic()
---
 drivers/usb/mtu3/mtu3_gadget.c |  1 +
 drivers/usb/mtu3/mtu3_gadget_ep0.c | 10 ++
 2 files changed, 11 insertions(+)

diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
index de0de01..5c60a8c 100644
--- a/drivers/usb/mtu3/mtu3_gadget.c
+++ b/drivers/usb/mtu3/mtu3_gadget.c
@@ -719,4 +719,5 @@ void mtu3_gadget_reset(struct mtu3 *mtu)
mtu->u1_enable = 0;
mtu->u2_enable = 0;
mtu->delayed_status = false;
+   mtu->test_mode = false;
 }
diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c 
b/drivers/usb/mtu3/mtu3_gadget_ep0.c
index d67b540..d3fc51b 100644
--- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
+++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
@@ -7,6 +7,7 @@
  * Author:  Chunfeng.Yun <chunfeng@mediatek.com>
  */
 
+#include 
 #include 
 
 #include "mtu3.h"
@@ -263,6 +264,7 @@ static int handle_test_mode(struct mtu3 *mtu, struct 
usb_ctrlrequest *setup)
 {
void __iomem *mbase = mtu->mac_base;
int handled = 1;
+   u32 value;
 
switch (le16_to_cpu(setup->wIndex) >> 8) {
case TEST_J:
@@ -292,6 +294,14 @@ static int handle_test_mode(struct mtu3 *mtu, struct 
usb_ctrlrequest *setup)
if (mtu->test_mode_nr == TEST_PACKET_MODE)
ep0_load_test_packet(mtu);
 
+   /* send status before entering test mode. */
+   value = mtu3_readl(mbase, U3D_EP0CSR) & EP0_W1C_BITS;
+   mtu3_writel(mbase, U3D_EP0CSR, value | EP0_SETUPPKTRDY | EP0_DATAEND);
+
+   /* wait for ACK status sent by host, ignore timeout error */
+   readl_poll_timeout_atomic(mbase + U3D_EP0CSR, value,
+   !(value & EP0_DATAEND), 100, 5000);
+
mtu3_writel(mbase, U3D_USB2_TEST_MODE, mtu->test_mode_nr);
 
mtu->ep0_state = MU3D_EP0_STATE_SETUP;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 7/7] usb: mtu3: fix uncontinuous SeqN issue after disable EP

2018-05-09 Thread Chunfeng Yun
Reset EP when disable it to reset data toggle for U2 EP, and
SeqN, flow control status etc for U3 EP, this can avoid
issue of uncontinuous SeqN

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
v2:
add this patch
---
 drivers/usb/mtu3/mtu3_core.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c
index 65ff53a..0bc2b39 100644
--- a/drivers/usb/mtu3/mtu3_core.c
+++ b/drivers/usb/mtu3/mtu3_core.c
@@ -400,6 +400,10 @@ void mtu3_deconfig_ep(struct mtu3 *mtu, struct mtu3_ep 
*mep)
mtu3_setbits(mbase, U3D_QIECR0, QMU_RX_DONE_INT(epnum));
}
 
+   /* reset: u2 - data toggle, u3 - SeqN, flow control status etc */
+   mtu3_setbits(mbase, U3D_EP_RST, EP_RST(mep->is_in, epnum));
+   mtu3_clrbits(mbase, U3D_EP_RST, EP_RST(mep->is_in, epnum));
+
ep_fifo_free(mep);
 
dev_dbg(mtu->dev, "%s: %s\n", __func__, mep->name);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/7] usb: mtu3: remove repeated setting of gadget state

2018-05-09 Thread Chunfeng Yun
The usb_add_gadget_udc() will set the gadget state as
USB_STATE_NOTATTACHED, so we needn't set it again.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_gadget.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
index f05f10f..de0de01 100644
--- a/drivers/usb/mtu3/mtu3_gadget.c
+++ b/drivers/usb/mtu3/mtu3_gadget.c
@@ -660,14 +660,10 @@ int mtu3_gadget_setup(struct mtu3 *mtu)
mtu3_gadget_init_eps(mtu);
 
ret = usb_add_gadget_udc(mtu->dev, >g);
-   if (ret) {
+   if (ret)
dev_err(mtu->dev, "failed to register udc\n");
-   return ret;
-   }
 
-   usb_gadget_set_state(>g, USB_STATE_NOTATTACHED);
-
-   return 0;
+   return ret;
 }
 
 void mtu3_gadget_cleanup(struct mtu3 *mtu)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/7] usb: mtu3: fix an unrecognized issue when connected with PC

2018-05-09 Thread Chunfeng Yun
When boot on the platform with the USB cable connected to Win7,
the Win7 will pop up an error dialog: "USB Device not recognized",
but finally the Win7 can enumerate it successfully.
The root cause is as the following:
When the xHCI driver set PORT_POWER of the OTG port, and if both
IDPIN and VBUS_VALID are high at the same time, the MTU3 controller
will set SESSION and pull up DP, so the Win7 can detect existence
of USB device, but if the mtu3 driver can't switch to device mode
during the debounce time, the Win7 can not enumerate it.
Here to fix it by removing the 1s delayed EXTCON register to speed up
mode switch.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3.h|  4 
 drivers/usb/mtu3/mtu3_dr.c | 25 +++--
 2 files changed, 3 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index 2cd00a2..a56fee0 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -197,9 +197,6 @@ struct mtu3_gpd_ring {
 * @edev: external connector used to detect vbus and iddig changes
 * @vbus_nb: notifier for vbus detection
 * @vbus_nb: notifier for iddig(idpin) detection
-* @extcon_reg_dwork: delay work for extcon notifier register, waiting for
-*  xHCI driver initialization, it's necessary for system bootup
-*  as device.
 * @is_u3_drd: whether port0 supports usb3.0 dual-role device or not
 * @manual_drd_enabled: it's true when supports dual-role device by debugfs
 *  to switch host/device modes depending on user input.
@@ -209,7 +206,6 @@ struct otg_switch_mtk {
struct extcon_dev *edev;
struct notifier_block vbus_nb;
struct notifier_block id_nb;
-   struct delayed_work extcon_reg_dwork;
bool is_u3_drd;
bool manual_drd_enabled;
 };
diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c
index db7562d..80083e0 100644
--- a/drivers/usb/mtu3/mtu3_dr.c
+++ b/drivers/usb/mtu3/mtu3_dr.c
@@ -238,15 +238,6 @@ static int ssusb_extcon_register(struct otg_switch_mtk 
*otg_sx)
return 0;
 }
 
-static void extcon_register_dwork(struct work_struct *work)
-{
-   struct delayed_work *dwork = to_delayed_work(work);
-   struct otg_switch_mtk *otg_sx =
-   container_of(dwork, struct otg_switch_mtk, extcon_reg_dwork);
-
-   ssusb_extcon_register(otg_sx);
-}
-
 /*
  * We provide an interface via debugfs to switch between host and device modes
  * depending on user input.
@@ -407,18 +398,10 @@ int ssusb_otg_switch_init(struct ssusb_mtk *ssusb)
 {
struct otg_switch_mtk *otg_sx = >otg_switch;
 
-   if (otg_sx->manual_drd_enabled) {
+   if (otg_sx->manual_drd_enabled)
ssusb_debugfs_init(ssusb);
-   } else {
-   INIT_DELAYED_WORK(_sx->extcon_reg_dwork,
- extcon_register_dwork);
-
-   /*
-* It is enough to delay 1s for waiting for
-* host initialization
-*/
-   schedule_delayed_work(_sx->extcon_reg_dwork, HZ);
-   }
+   else
+   ssusb_extcon_register(otg_sx);
 
return 0;
 }
@@ -429,6 +412,4 @@ void ssusb_otg_switch_exit(struct ssusb_mtk *ssusb)
 
if (otg_sx->manual_drd_enabled)
ssusb_debugfs_exit(ssusb);
-   else
-   cancel_delayed_work(_sx->extcon_reg_dwork);
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 6/7] usb: mtu3: re-enable controller to accept LPM request after LPM resume

2018-05-09 Thread Chunfeng Yun
After the controller receives a LPM request, it will reject the LPM
request, and need software to re-enable it after LPM resume if the
controller doesn't remote wakeup from L1 automatically

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
v2:
add this patch
---
 drivers/usb/mtu3/mtu3_core.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c
index b1b99a8..65ff53a 100644
--- a/drivers/usb/mtu3/mtu3_core.c
+++ b/drivers/usb/mtu3/mtu3_core.c
@@ -176,7 +176,7 @@ static void mtu3_intr_enable(struct mtu3 *mtu)
mtu3_writel(mbase, U3D_LV1IESR, value);
 
/* Enable U2 common USB interrupts */
-   value = SUSPEND_INTR | RESUME_INTR | RESET_INTR;
+   value = SUSPEND_INTR | RESUME_INTR | RESET_INTR | LPM_RESUME_INTR;
mtu3_writel(mbase, U3D_COMMON_USB_INTR_ENABLE, value);
 
if (mtu->is_u3_ip) {
@@ -692,6 +692,12 @@ static irqreturn_t mtu3_u2_common_isr(struct mtu3 *mtu)
if (u2comm & RESET_INTR)
mtu3_gadget_reset(mtu);
 
+   if (u2comm & LPM_RESUME_INTR) {
+   if (!(mtu3_readl(mbase, U3D_POWER_MANAGEMENT) & LPM_HRWE))
+   mtu3_setbits(mbase, U3D_USB20_MISC_CONTROL,
+LPM_U3_ACK_EN);
+   }
+
return IRQ_HANDLED;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RESEND PATCH 1/5] usb: mtu3: avoid TX data length truncated in SS/SSP mode

2018-05-09 Thread Chunfeng Yun
Hi, Greg
On Thu, 2018-05-10 at 10:16 +0800, Chunfeng Yun wrote:
> Hi, Greg
> 
>Could you please pick up the series of patches, thanks a lot
Please ignore it, I find a problem in [RESEND PATCH 4/5], and need send
a new version.

Very sorry

>  
> On Sat, 2018-05-05 at 10:21 +0800, Chunfeng Yun wrote:
> > The variable of 'count' is declared as u8, this will cause an issue
> > due to value truncated when works in SS or SSP mode and data length
> > is greater than 255, so change it as u32.
> > 
> > Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
> > ---
> >  drivers/usb/mtu3/mtu3_gadget_ep0.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c 
> > b/drivers/usb/mtu3/mtu3_gadget_ep0.c
> > index ebdcf7a..d67b540 100644
> > --- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
> > +++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
> > @@ -546,7 +546,7 @@ static void ep0_tx_state(struct mtu3 *mtu)
> > struct usb_request *req;
> > u32 csr;
> > u8 *src;
> > -   u8 count;
> > +   u32 count;
> > u32 maxp;
> >  
> > dev_dbg(mtu->dev, "%s\n", __func__);
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RESEND PATCH 1/5] usb: mtu3: avoid TX data length truncated in SS/SSP mode

2018-05-09 Thread Chunfeng Yun
Hi, Greg

   Could you please pick up the series of patches, thanks a lot
 
On Sat, 2018-05-05 at 10:21 +0800, Chunfeng Yun wrote:
> The variable of 'count' is declared as u8, this will cause an issue
> due to value truncated when works in SS or SSP mode and data length
> is greater than 255, so change it as u32.
> 
> Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
> ---
>  drivers/usb/mtu3/mtu3_gadget_ep0.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c 
> b/drivers/usb/mtu3/mtu3_gadget_ep0.c
> index ebdcf7a..d67b540 100644
> --- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
> +++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
> @@ -546,7 +546,7 @@ static void ep0_tx_state(struct mtu3 *mtu)
>   struct usb_request *req;
>   u32 csr;
>   u8 *src;
> - u8 count;
> + u32 count;
>   u32 maxp;
>  
>   dev_dbg(mtu->dev, "%s\n", __func__);


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: gadget: composite: fill bcdUSB as 0x0320 for SuperSpeed or higher speeds

2018-05-09 Thread Chunfeng Yun
Hi,

On Wed, 2018-05-09 at 14:33 +0300, Felipe Balbi wrote:
> Hi,
> 
> Chunfeng Yun <chunfeng@mediatek.com> writes:
> > The USB3CV version 2.1.80 (March 26, 2018) requires all devices
> > ( gen1, gen2, single lane, dual lane) to return the value of 0x0320
> > in the bcdUSB field
> 
> this sounds really odd. What happens when I get a USB 3.1 compliant
> device off-the-shelf and run it through USB3CV? will it fail now?
It will fail, the last version require it 0x0310
> 
> Care to share a screenshot or the raw html of the test result?
A screenshot is attached
> 



[PATCH] usb: gadget: composite: fill bcdUSB as 0x0320 for SuperSpeed or higher speeds

2018-05-09 Thread Chunfeng Yun
The USB3CV version 2.1.80 (March 26, 2018) requires all devices
( gen1, gen2, single lane, dual lane) to return the value of 0x0320
in the bcdUSB field

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/gadget/composite.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 63a7cb8..f242c2b 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1601,7 +1601,7 @@ static int fill_ext_prop(struct usb_configuration *c, int 
interface, u8 *buf)
cdev->gadget->ep0->maxpacket;
if (gadget_is_superspeed(gadget)) {
if (gadget->speed >= USB_SPEED_SUPER) {
-   cdev->desc.bcdUSB = cpu_to_le16(0x0310);
+   cdev->desc.bcdUSB = cpu_to_le16(0x0320);
cdev->desc.bMaxPacketSize0 = 9;
} else {
cdev->desc.bcdUSB = cpu_to_le16(0x0210);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/2] dt-bindings: add MediaTek XS-PHY binding

2018-05-07 Thread Chunfeng Yun
On Mon, 2018-05-07 at 12:04 -0500, Rob Herring wrote:
> On Sat, May 05, 2018 at 10:15:05AM +0800, Chunfeng Yun wrote:
> > Add a DT binding documentation of XS-PHY for MediaTek SoCs
> > with USB3.1 GEN2 controller
> > 
> > Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
> > ---
> >  .../devicetree/bindings/phy/phy-mtk-xsphy.txt  |  110 
> > 
> >  1 file changed, 110 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt 
> > b/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
> > new file mode 100644
> > index 000..9a95fab
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
> > @@ -0,0 +1,110 @@
> > +MediaTek XS-PHY binding
> > +--
> > +
> > +The XS-PHY controller supports physical layer functionality for USB3.1
> > +GEN2 controller on MediaTek SoCs.
> > +
> > +Required properties (controller (parent) node):
> > + - compatible  : should be "mediatek,-xsphy", 
> > "mediatek,xsphy",
> > + soc-model is the name of SoC, such as mt2712 etc;
> > + when using "mediatek,xsphy" compatible string, you need SoC 
> > specific
> > + ones in addition, one of:
> > + - "mediatek,mt3611-xsphy"
> 
> What about mt2712 you mention above?
Sorry, forgot to modify it



--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH 1/5] usb: mtu3: avoid TX data length truncated in SS/SSP mode

2018-05-04 Thread Chunfeng Yun
The variable of 'count' is declared as u8, this will cause an issue
due to value truncated when works in SS or SSP mode and data length
is greater than 255, so change it as u32.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_gadget_ep0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c 
b/drivers/usb/mtu3/mtu3_gadget_ep0.c
index ebdcf7a..d67b540 100644
--- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
+++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
@@ -546,7 +546,7 @@ static void ep0_tx_state(struct mtu3 *mtu)
struct usb_request *req;
u32 csr;
u8 *src;
-   u8 count;
+   u32 count;
u32 maxp;
 
dev_dbg(mtu->dev, "%s\n", __func__);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH 3/5] usb: mtu3: fix an unrecognized issue when connected with PC

2018-05-04 Thread Chunfeng Yun
When boot on the platform with the USB cable connected to Win7,
the Win7 will pop up an error dialog: "USB Device not recognized",
but finally the Win7 can enumerate it successfully.
The root cause is as the following:
When the xHCI driver set PORT_POWER of the OTG port, and if both
IDPIN and VBUS_VALID are high at the same time, the MTU3 controller
will set SESSION and pull up DP, so the Win7 can detect existence
of USB device, but if the mtu3 driver can't switch to device mode
during the debounce time, the Win7 can not enumerate it.
Here to fix it by removing the 1s delayed EXTCON register to speed up
mode switch.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3.h|  4 
 drivers/usb/mtu3/mtu3_dr.c | 25 +++--
 2 files changed, 3 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index 2cd00a2..a56fee0 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -197,9 +197,6 @@ struct mtu3_gpd_ring {
 * @edev: external connector used to detect vbus and iddig changes
 * @vbus_nb: notifier for vbus detection
 * @vbus_nb: notifier for iddig(idpin) detection
-* @extcon_reg_dwork: delay work for extcon notifier register, waiting for
-*  xHCI driver initialization, it's necessary for system bootup
-*  as device.
 * @is_u3_drd: whether port0 supports usb3.0 dual-role device or not
 * @manual_drd_enabled: it's true when supports dual-role device by debugfs
 *  to switch host/device modes depending on user input.
@@ -209,7 +206,6 @@ struct otg_switch_mtk {
struct extcon_dev *edev;
struct notifier_block vbus_nb;
struct notifier_block id_nb;
-   struct delayed_work extcon_reg_dwork;
bool is_u3_drd;
bool manual_drd_enabled;
 };
diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c
index db7562d..80083e0 100644
--- a/drivers/usb/mtu3/mtu3_dr.c
+++ b/drivers/usb/mtu3/mtu3_dr.c
@@ -238,15 +238,6 @@ static int ssusb_extcon_register(struct otg_switch_mtk 
*otg_sx)
return 0;
 }
 
-static void extcon_register_dwork(struct work_struct *work)
-{
-   struct delayed_work *dwork = to_delayed_work(work);
-   struct otg_switch_mtk *otg_sx =
-   container_of(dwork, struct otg_switch_mtk, extcon_reg_dwork);
-
-   ssusb_extcon_register(otg_sx);
-}
-
 /*
  * We provide an interface via debugfs to switch between host and device modes
  * depending on user input.
@@ -407,18 +398,10 @@ int ssusb_otg_switch_init(struct ssusb_mtk *ssusb)
 {
struct otg_switch_mtk *otg_sx = >otg_switch;
 
-   if (otg_sx->manual_drd_enabled) {
+   if (otg_sx->manual_drd_enabled)
ssusb_debugfs_init(ssusb);
-   } else {
-   INIT_DELAYED_WORK(_sx->extcon_reg_dwork,
- extcon_register_dwork);
-
-   /*
-* It is enough to delay 1s for waiting for
-* host initialization
-*/
-   schedule_delayed_work(_sx->extcon_reg_dwork, HZ);
-   }
+   else
+   ssusb_extcon_register(otg_sx);
 
return 0;
 }
@@ -429,6 +412,4 @@ void ssusb_otg_switch_exit(struct ssusb_mtk *ssusb)
 
if (otg_sx->manual_drd_enabled)
ssusb_debugfs_exit(ssusb);
-   else
-   cancel_delayed_work(_sx->extcon_reg_dwork);
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH 5/5] usb: mtu3: make USB_MTU3_DUAL_ROLE depend on EXTCON but not USB_MTU3

2018-05-04 Thread Chunfeng Yun
In fact the driver depends on EXTCON only when it's configed as
USB_MTU3_DUAL_ROLE, so make USB_MTU3_DUAL_ROLE depend on EXTCON but
not USB_MTU3.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/mtu3/Kconfig b/drivers/usb/mtu3/Kconfig
index 25cd619..8daf277 100644
--- a/drivers/usb/mtu3/Kconfig
+++ b/drivers/usb/mtu3/Kconfig
@@ -2,7 +2,7 @@
 
 config USB_MTU3
tristate "MediaTek USB3 Dual Role controller"
-   depends on EXTCON && (USB || USB_GADGET) && HAS_DMA
+   depends on (USB || USB_GADGET) && HAS_DMA
depends on ARCH_MEDIATEK || COMPILE_TEST
select USB_XHCI_MTK if USB_SUPPORT && USB_XHCI_HCD
help
@@ -40,6 +40,7 @@ config USB_MTU3_GADGET
 config USB_MTU3_DUAL_ROLE
bool "Dual Role mode"
depends on ((USB=y || USB=USB_MTU3) && (USB_GADGET=y || 
USB_GADGET=USB_MTU3))
+   depends on (EXTCON=y || EXTCON=USB_MTU3)
help
  This is the default mode of working of MTU3 controller where
  both host and gadget features are enabled.
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH 4/5] usb: mtu3: fix operation failure when test TEST_J/K

2018-05-04 Thread Chunfeng Yun
There is an error dialog popped up in PC when test TEST_J/K
by EHSETT tool, due to not waiting for the completion of
control transfer. Here fix it by entering test mode after
Status Stage finish.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_gadget_ep0.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c 
b/drivers/usb/mtu3/mtu3_gadget_ep0.c
index d67b540..0d2b1cf 100644
--- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
+++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
@@ -7,6 +7,7 @@
  * Author:  Chunfeng.Yun <chunfeng@mediatek.com>
  */
 
+#include 
 #include 
 
 #include "mtu3.h"
@@ -263,6 +264,7 @@ static int handle_test_mode(struct mtu3 *mtu, struct 
usb_ctrlrequest *setup)
 {
void __iomem *mbase = mtu->mac_base;
int handled = 1;
+   u32 value;
 
switch (le16_to_cpu(setup->wIndex) >> 8) {
case TEST_J:
@@ -292,6 +294,14 @@ static int handle_test_mode(struct mtu3 *mtu, struct 
usb_ctrlrequest *setup)
if (mtu->test_mode_nr == TEST_PACKET_MODE)
ep0_load_test_packet(mtu);
 
+   /* send status before entering test mode. */
+   value = mtu3_readl(mbase, U3D_EP0CSR) & EP0_W1C_BITS;
+   mtu3_writel(mbase, U3D_EP0CSR, value | EP0_SETUPPKTRDY | EP0_DATAEND);
+
+   /* wait for ACK status sent by host */
+   readl_poll_timeout(mbase + U3D_EP0CSR, value,
+   !(value & EP0_DATAEND), 100, 5000);
+
mtu3_writel(mbase, U3D_USB2_TEST_MODE, mtu->test_mode_nr);
 
mtu->ep0_state = MU3D_EP0_STATE_SETUP;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH 2/5] usb: mtu3: remove repeated setting of gadget state

2018-05-04 Thread Chunfeng Yun
The usb_add_gadget_udc() will set the gadget state as
USB_STATE_NOTATTACHED, so we needn't set it again.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_gadget.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
index f05f10f..de0de01 100644
--- a/drivers/usb/mtu3/mtu3_gadget.c
+++ b/drivers/usb/mtu3/mtu3_gadget.c
@@ -660,14 +660,10 @@ int mtu3_gadget_setup(struct mtu3 *mtu)
mtu3_gadget_init_eps(mtu);
 
ret = usb_add_gadget_udc(mtu->dev, >g);
-   if (ret) {
+   if (ret)
dev_err(mtu->dev, "failed to register udc\n");
-   return ret;
-   }
 
-   usb_gadget_set_state(>g, USB_STATE_NOTATTACHED);
-
-   return 0;
+   return ret;
 }
 
 void mtu3_gadget_cleanup(struct mtu3 *mtu)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/2] phy: mediatek: add XS-PHY driver

2018-05-04 Thread Chunfeng Yun
Support XS-PHY for MediaTek SoCs with USB3.1 GEN2 controller

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/phy/mediatek/Kconfig |9 +
 drivers/phy/mediatek/Makefile|1 +
 drivers/phy/mediatek/phy-mtk-xsphy.c |  600 ++
 3 files changed, 610 insertions(+)
 create mode 100644 drivers/phy/mediatek/phy-mtk-xsphy.c

diff --git a/drivers/phy/mediatek/Kconfig b/drivers/phy/mediatek/Kconfig
index 88ab4e2..8857d00 100644
--- a/drivers/phy/mediatek/Kconfig
+++ b/drivers/phy/mediatek/Kconfig
@@ -12,3 +12,12 @@ config PHY_MTK_TPHY
  different banks layout, the T-PHY with shared banks between
  multi-ports is first version, otherwise is second veriosn,
  so you can easily distinguish them by banks layout.
+
+config PHY_MTK_XSPHY
+tristate "MediaTek XS-PHY Driver"
+depends on ARCH_MEDIATEK && OF
+select GENERIC_PHY
+help
+ Enable this to support the SuperSpeedPlus XS-PHY transceiver for
+ USB3.1 GEN2 controllers on MediaTek chips. The driver supports
+ multiple USB2.0, USB3.1 GEN2 ports.
diff --git a/drivers/phy/mediatek/Makefile b/drivers/phy/mediatek/Makefile
index 1bdab14..ee49edc 100644
--- a/drivers/phy/mediatek/Makefile
+++ b/drivers/phy/mediatek/Makefile
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o
+obj-$(CONFIG_PHY_MTK_XSPHY)+= phy-mtk-xsphy.o
diff --git a/drivers/phy/mediatek/phy-mtk-xsphy.c 
b/drivers/phy/mediatek/phy-mtk-xsphy.c
new file mode 100644
index 000..020cd02
--- /dev/null
+++ b/drivers/phy/mediatek/phy-mtk-xsphy.c
@@ -0,0 +1,600 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MediaTek USB3.1 gen2 xsphy Driver
+ *
+ * Copyright (c) 2018 MediaTek Inc.
+ * Author: Chunfeng Yun <chunfeng@mediatek.com>
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* u2 phy banks */
+#define SSUSB_SIFSLV_MISC  0x000
+#define SSUSB_SIFSLV_U2FREQ0x100
+#define SSUSB_SIFSLV_U2PHY_COM 0x300
+
+/* u3 phy shared banks */
+#define SSPXTP_SIFSLV_DIG_GLB  0x000
+#define SSPXTP_SIFSLV_PHYA_GLB 0x100
+
+/* u3 phy banks */
+#define SSPXTP_SIFSLV_DIG_LN_TOP   0x000
+#define SSPXTP_SIFSLV_DIG_LN_TX0   0x100
+#define SSPXTP_SIFSLV_DIG_LN_RX0   0x200
+#define SSPXTP_SIFSLV_DIG_LN_DAIF  0x300
+#define SSPXTP_SIFSLV_PHYA_LN  0x400
+
+#define XSP_U2FREQ_FMCR0   ((SSUSB_SIFSLV_U2FREQ) + 0x00)
+#define P2F_RG_FREQDET_EN  BIT(24)
+#define P2F_RG_CYCLECNTGENMASK(23, 0)
+#define P2F_RG_CYCLECNT_VAL(x) ((P2F_RG_CYCLECNT) & (x))
+
+#define XSP_U2FREQ_MMONR0  ((SSUSB_SIFSLV_U2FREQ) + 0x0c)
+
+#define XSP_U2FREQ_FMMONR1 ((SSUSB_SIFSLV_U2FREQ) + 0x10)
+#define P2F_RG_FRCK_EN BIT(8)
+#define P2F_USB_FM_VALID   BIT(0)
+
+#define XSP_USBPHYACR0 ((SSUSB_SIFSLV_U2PHY_COM) + 0x00)
+#define P2A0_RG_INTR_ENBIT(5)
+
+#define XSP_USBPHYACR1 ((SSUSB_SIFSLV_U2PHY_COM) + 0x04)
+#define P2A1_RG_INTR_CAL   GENMASK(23, 19)
+#define P2A1_RG_INTR_CAL_VAL(x)((0x1f & (x)) << 19)
+#define P2A1_RG_VRT_SELGENMASK(14, 12)
+#define P2A1_RG_VRT_SEL_VAL(x) ((0x7 & (x)) << 12)
+#define P2A1_RG_TERM_SEL   GENMASK(10, 8)
+#define P2A1_RG_TERM_SEL_VAL(x)((0x7 & (x)) << 8)
+
+#define XSP_USBPHYACR5 ((SSUSB_SIFSLV_U2PHY_COM) + 0x014)
+#define P2A5_RG_HSTX_SRCAL_EN  BIT(15)
+#define P2A5_RG_HSTX_SRCTRLGENMASK(14, 12)
+#define P2A5_RG_HSTX_SRCTRL_VAL(x) ((0x7 & (x)) << 12)
+
+#define XSP_USBPHYACR6 ((SSUSB_SIFSLV_U2PHY_COM) + 0x018)
+#define P2A6_RG_BC11_SW_EN BIT(23)
+#define P2A6_RG_OTG_VBUSCMP_EN BIT(20)
+
+#define XSP_U2PHYDTM1  ((SSUSB_SIFSLV_U2PHY_COM) + 0x06C)
+#define P2D_FORCE_IDDIGBIT(9)
+#define P2D_RG_VBUSVALID   BIT(5)
+#define P2D_RG_SESSEND BIT(4)
+#define P2D_RG_AVALID  BIT(2)
+#define P2D_RG_IDDIG   BIT(1)
+
+#define SSPXTP_PHYA_GLB_00 ((SSPXTP_SIFSLV_PHYA_GLB) + 0x00)
+#define RG_XTP_GLB_BIAS_INTR_CTRL  GENMASK(21, 16)
+#define RG_XTP_GLB_BIAS_INTR_CTRL_VAL(x)   ((0x3f & (x)) << 16)
+
+#define SSPXTP_PHYA_LN_04  ((SSPXTP_SIFSLV_PHYA_LN) + 0x04)
+#define RG_XTP_LN0_TX_IMPSEL   GENMASK(4, 0)
+#define RG_XTP_LN0_TX_IMPSEL_VAL(x)(0x1f & (x))
+
+#define SSPXTP_PHYA_LN_14  ((SSPXTP_SIFSLV_PHYA_LN) + 0x014)
+#define RG_XTP_LN0_RX_IMPSEL   GENMASK(4, 0)
+#define RG_XTP_LN0_RX_IMPSEL_VAL(x)(0x1f & (x))
+
+#define XSP_REF_CLK26  /* MHZ */
+#define XSP_SLEW_RATE_COEF 17
+#define XSP_SR_COEF_DIVISOR1000
+#define XSP_FM_DET_CYCLE_CNT   1024
+
+struct xsphy_instance {
+   struct phy *phy;
+   void __iomem *port_base;
+   struct clk *ref_clk;/* reference clock of an

[PATCH v2 1/2] dt-bindings: add MediaTek XS-PHY binding

2018-05-04 Thread Chunfeng Yun
Add a DT binding documentation of XS-PHY for MediaTek SoCs
with USB3.1 GEN2 controller

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 .../devicetree/bindings/phy/phy-mtk-xsphy.txt  |  110 
 1 file changed, 110 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt

diff --git a/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt 
b/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
new file mode 100644
index 000..9a95fab
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
@@ -0,0 +1,110 @@
+MediaTek XS-PHY binding
+--
+
+The XS-PHY controller supports physical layer functionality for USB3.1
+GEN2 controller on MediaTek SoCs.
+
+Required properties (controller (parent) node):
+ - compatible  : should be "mediatek,-xsphy", "mediatek,xsphy",
+ soc-model is the name of SoC, such as mt2712 etc;
+ when using "mediatek,xsphy" compatible string, you need SoC 
specific
+ ones in addition, one of:
+ - "mediatek,mt3611-xsphy"
+
+ - #address-cells, #size-cells : should use the same values as the root node
+ - ranges: must be present
+
+Optional properties (controller (parent) node):
+ - reg : offset and length of register shared by multiple U3 ports,
+ exclude port's private register, if only U2 ports provided,
+ shouldn't use the property.
+ - mediatek,src-ref-clk-mhz: u32, frequency of reference clock for slew 
rate
+ calibrate
+ - mediatek,src-coef   : u32, coefficient for slew rate calibrate, depends on
+ SoC process
+
+Required nodes : a sub-node is required for each port the controller
+ provides. Address range information including the usual
+ 'reg' property is used inside these nodes to describe
+ the controller's topology.
+
+Required properties (port (child) node):
+- reg  : address and length of the register set for the port.
+- clocks   : a list of phandle + clock-specifier pairs, one for each
+ entry in clock-names
+- clock-names  : must contain
+ "ref": 48M reference clock for HighSpeed analog phy; and 26M
+   reference clock for SuperSpeedPlus analog phy, 
sometimes is
+   24M, 25M or 27M, depended on platform.
+- #phy-cells   : should be 1
+ cell after port phandle is phy type from:
+   - PHY_TYPE_USB2
+   - PHY_TYPE_USB3
+
+The following optional properties are only for debug or HQA test
+Optional properties (PHY_TYPE_USB2 port (child) node):
+- mediatek,eye-src : u32, the value of slew rate calibrate
+- mediatek,eye-vrt : u32, the selection of VRT reference voltage
+- mediatek,eye-term: u32, the selection of HS_TX TERM reference voltage
+- mediatek,efuse-intr  : u32, the selection of Internal Resistor
+
+Optional properties (PHY_TYPE_USB3 port (child) node):
+- mediatek,efuse-intr  : u32, the selection of Internal Resistor
+- mediatek,efuse-tx-imp: u32, the selection of TX Impedance
+- mediatek,efuse-rx-imp: u32, the selection of RX Impedance
+
+Banks layout of xsphy
+-
+portoffsetbank
+u2 port00xMISC
+0x0100FMREG
+0x0300U2PHY_COM
+u2 port10x1000MISC
+0x1100FMREG
+0x1300U2PHY_COM
+u2 port20x2000MISC
+...
+u31 common  0x3000DIG_GLB
+0x3100PHYA_GLB
+u31 port0   0x3400DIG_LN_TOP
+0x3500DIG_LN_TX0
+0x3600DIG_LN_RX0
+0x3700DIG_LN_DAIF
+0x3800PHYA_LN
+u31 port1   0x3a00DIG_LN_TOP
+0x3b00DIG_LN_TX0
+0x3c00DIG_LN_RX0
+0x3d00DIG_LN_DAIF
+0x3e00PHYA_LN
+...
+
+DIG_GLB & PHYA_GLB are shared by U31 ports.
+
+Example:
+
+u3phy: usb-phy@11c4 {
+   compatible = "mediatek,mt3611-xsphy", "mediatek,xsphy";
+   reg = <0 0x11c43000 0 0x0200>;
+   mediatek,src-ref-clk-mhz = <26>;
+   mediatek,src-coef = <17>;
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   u2port0: usb-phy@11c4 {
+   reg = <0 0x11c4 0 0x0400>;
+   clocks = <>;
+   clock-names = "ref";
+   mediatek,eye-src = <4>;
+   #phy-cells = <1>;
+   };
+
+   u3port0: usb-phy@11c43000 {
+   reg = <0 0x11c43400 0 0x0500>;
+   clocks = <>;
+   clock-names = "ref";
+   mediatek,efuse-intr = <28>

[PATCH v2 0/2] Add MediaTek XS-PHY driver

2018-05-04 Thread Chunfeng Yun
>From a0814ad7725587a06d273997e0fdf5161f916fd8 Mon Sep 17 00:00:00 2001
From: Chunfeng Yun <chunfeng@mediatek.com>
Date: Sat, 5 May 2018 09:56:59 +0800
Subject: [PATCH v2 0/2] Add MediaTek XS-PHY driver

This patch series support the SuperSpeedPlus XS-PHY transceiver for
USB3.1 GEN2 controller on MediaTek chips. The driver supports multiple
USB2.0, USB3.1 GEN2 ports.

v2: changes in binding (suggested by Rob)
1. list all valid SoCs for compatible
2. move required child nodes after parent optional ones
3. remove status property in example
4. move banks layout example before dts one
5. remove phy binding example
6. add #address-cells, #size-cells, ranges properties for parent node

Chunfeng Yun (2):
  dt-bindings: add MediaTek XS-PHY binding
  phy: mediatek: add XS-PHY driver

 .../devicetree/bindings/phy/phy-mtk-xsphy.txt  | 110 
 drivers/phy/mediatek/Kconfig   |   9 +
 drivers/phy/mediatek/Makefile  |   1 +
 drivers/phy/mediatek/phy-mtk-xsphy.c   | 600 +
 4 files changed, 720 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
 create mode 100644 drivers/phy/mediatek/phy-mtk-xsphy.c

-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] phy: phy-mtk-tphy: use SPDX license tag

2018-05-04 Thread Chunfeng Yun
Use SPDX-License-Identifier tag instead of the GPL license text

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
v2: change subject line to fix checkpatch warning:
"A patch subject line should describe the change not
the tool that found it"
---
 drivers/phy/mediatek/Makefile   |  1 +
 drivers/phy/mediatek/phy-mtk-tphy.c | 10 +-
 2 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/phy/mediatek/Makefile b/drivers/phy/mediatek/Makefile
index 763a92e..1bdab14 100644
--- a/drivers/phy/mediatek/Makefile
+++ b/drivers/phy/mediatek/Makefile
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
 #
 # Makefile for the phy drivers.
 #
diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c 
b/drivers/phy/mediatek/phy-mtk-tphy.c
index 38c281b..b962339 100644
--- a/drivers/phy/mediatek/phy-mtk-tphy.c
+++ b/drivers/phy/mediatek/phy-mtk-tphy.c
@@ -1,16 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2015 MediaTek Inc.
  * Author: Chunfeng Yun <chunfeng@mediatek.com>
  *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
  */
 
 #include 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] xhci: hisilicon: support HiSilicon STB xHCI host controller

2018-05-04 Thread Chunfeng Yun
Hi Jianguo,

On Fri, 2018-05-04 at 17:20 +0800, sunj...@163.com wrote:
> From: Jianguo Sun 
> 
> This commit adds support for HiSilicon STB xHCI host controller.
> 
> Signed-off-by: Jianguo Sun 
> ---
>  drivers/usb/host/Kconfig  |   7 +
>  drivers/usb/host/Makefile |   1 +
>  drivers/usb/host/xhci-histb.c | 409 
> ++
>  3 files changed, 417 insertions(+)
>  create mode 100644 drivers/usb/host/xhci-histb.c
> 
> diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
> index 5d958da..c813fc4 100644
> --- a/drivers/usb/host/Kconfig
> +++ b/drivers/usb/host/Kconfig
> @@ -52,6 +52,13 @@ config USB_XHCI_PLATFORM
>  
> If unsure, say N.
>  
> +config USB_XHCI_HISTB
> + tristate "xHCI support for HiSilicon STB SoCs"
> + depends on USB_XHCI_PLATFORM && (ARCH_HISI || COMPILE_TEST)
> + help
> +   Say 'Y' to enable the support for the xHCI host controller
> +   found in HiSilicon STB SoCs.
> +
>  config USB_XHCI_MTK
>   tristate "xHCI support for MediaTek SoCs"
>   select MFD_SYSCON
> diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
> index 8a8cffe..9b669c9 100644
> --- a/drivers/usb/host/Makefile
> +++ b/drivers/usb/host/Makefile
> @@ -74,6 +74,7 @@ obj-$(CONFIG_USB_FHCI_HCD)  += fhci.o
>  obj-$(CONFIG_USB_XHCI_HCD)   += xhci-hcd.o
>  obj-$(CONFIG_USB_XHCI_PCI)   += xhci-pci.o
>  obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o
> +obj-$(CONFIG_USB_XHCI_HISTB) += xhci-histb.o
>  obj-$(CONFIG_USB_XHCI_MTK)   += xhci-mtk.o
>  obj-$(CONFIG_USB_XHCI_TEGRA) += xhci-tegra.o
>  obj-$(CONFIG_USB_SL811_HCD)  += sl811-hcd.o
> diff --git a/drivers/usb/host/xhci-histb.c b/drivers/usb/host/xhci-histb.c
> new file mode 100644
> index 000..5ec549f
> --- /dev/null
> +++ b/drivers/usb/host/xhci-histb.c
> @@ -0,0 +1,409 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * xHCI host controller driver for HiSilicon STB SoCs
> + *
> + * Copyright (C) 2017-2018 HiSilicon Co., Ltd. http://www.hisilicon.com
> + *
> + * Authors: Jianguo Sun 
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
No need anymore if SPDX-License-Identifier is provided
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
Not used
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
ditto
> +#include 
> +
> +#include "xhci.h"
> +
> +#define GTXTHRCFG0xc108
> +#define GRXTHRCFG0xc10c
> +#define REG_GUSB2PHYCFG0 0xc200
> +#define BIT_UTMI_8_16BIT(3)
> +#define BIT_UTMI_ULPIBIT(4)
> +#define BIT_FREECLK_EXISTBIT(30)
> +
> +#define REG_GUSB3PIPECTL00xc2c0
> +#define USB3_DEEMPHASIS_MASK GENMASK(2, 1)
> +#define USB3_DEEMPHASIS0 BIT(1)
> +#define USB3_TX_MARGIN1  BIT(4)
> +
> +struct xhci_hcd_histb {
> + struct device   *dev;
> + struct usb_hcd  *hcd;
> + void __iomem*ctrl;
> + struct clk  *bus_clk;
> + struct clk  *utmi_clk;
> + struct clk  *pipe_clk;
> + struct clk  *suspend_clk;
> + struct reset_control*soft_reset;
> +};
> +
> +static inline struct xhci_hcd_histb *hcd_to_histb(struct usb_hcd *hcd)
> +{
> + return dev_get_drvdata(hcd->self.controller);
> +}
> +
> +static int xhci_histb_config(struct xhci_hcd_histb *histb)
> +{
> + struct device_node *np = histb->dev->of_node;
> + u32 regval;
> +
> + if (of_property_match_string(np, "phys-names", "inno") >= 0) {
> + /* USB2 PHY chose ulpi 8bit interface */
> + regval = readl(histb->ctrl + REG_GUSB2PHYCFG0);
> + regval &= ~BIT_UTMI_ULPI;
> + regval &= ~(BIT_UTMI_8_16);
> + regval &= ~BIT_FREECLK_EXIST;
> + writel(regval, histb->ctrl + REG_GUSB2PHYCFG0);
> + }
> +
> + if (of_property_match_string(np, "phys-names", "combo") >= 0) {
> + /*
> +  * write 0x010c0012 to GUSB3PIPECTL0
> +  * GUSB3PIPECTL0[5:3] = 010 : Tx Margin = 900mV ,
> +  * decrease TX voltage
> +  * GUSB3PIPECTL0[2:1] = 01 : Tx Deemphasis = -3.5dB,
> +  * refer to xHCI spec
> +  */
> + regval = readl(histb->ctrl + REG_GUSB3PIPECTL0);
> + regval &= ~USB3_DEEMPHASIS_MASK;
> + regval |= USB3_DEEMPHASIS0;
> + regval |= USB3_TX_MARGIN1;
> + writel(regval, histb->ctrl + REG_GUSB3PIPECTL0);
> + }
> +
> + writel(0x2310, histb->ctrl + GTXTHRCFG);
> + writel(0x2310, histb->ctrl + GRXTHRCFG);
> +
> + return 0;
> +}
> +
> +static int xhci_histb_clks_get(struct xhci_hcd_histb *histb)
> +{
> + struct device *dev = histb->dev;
> +
> + histb->bus_clk = 

Re: [PATCH 1/2] dt-bindings: add MediaTek XS-PHY binding

2018-05-02 Thread Chunfeng Yun
On Wed, 2018-05-02 at 07:41 -0500, Rob Herring wrote:
> On Wed, May 2, 2018 at 2:04 AM, Chunfeng Yun <chunfeng@mediatek.com> 
> wrote:
> > Hi Rob,
> > On Tue, 2018-05-01 at 09:24 -0500, Rob Herring wrote:
> >> On Wed, Apr 25, 2018 at 03:45:28PM +0800, Chunfeng Yun wrote:
> >> > Add a DT binding documentation of XS-PHY for MediaTek SoCs
> >> > with USB3.1 GEN2 controller
> 
> [...]
> 
> >> > +   reg = <0 0x11c43000 0 0x0200>;
> >> > +   mediatek,src-ref-clk-mhz = <26>;
> >> > +   mediatek,src-coef = <17>;
> >> > +   #address-cells = <2>;
> >> > +   #size-cells = <2>;
> >>
> >> Really need 64-bit sizes?
> > Just an example, 32-bit is also ok, but it's better to use the same
> > value as the root node
> 
> Why is it better?
> 
> It is unnecessary bloat and it is better to limit the range of child
> nodes using ranges.
I agree with you.
And here the parent and child address space is identical, and no address
translate is required, so use the same value as the root node, if the
root node uses 64-bit sizes, we will use 64-bit sizes as well,  if it
uses 32-bit sizes, we use 32-bit sizes too, in order to keep consistent.
> 
> Rob


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] dt-bindings: add MediaTek XS-PHY binding

2018-05-02 Thread Chunfeng Yun
Hi Rob,
On Tue, 2018-05-01 at 09:24 -0500, Rob Herring wrote:
> On Wed, Apr 25, 2018 at 03:45:28PM +0800, Chunfeng Yun wrote:
> > Add a DT binding documentation of XS-PHY for MediaTek SoCs
> > with USB3.1 GEN2 controller
> > 
> > Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
> > ---
> >  .../devicetree/bindings/phy/phy-mtk-xsphy.txt  |  127 
> > 
> >  1 file changed, 127 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt 
> > b/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
> > new file mode 100644
> > index 000..23c51a0
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
> > @@ -0,0 +1,127 @@
> > +MediaTek XS-PHY binding
> > +--
> > +
> > +The XS-PHY controller supports physical layer functionality for USB3.1
> > +GEN2 controller on MediaTek SoCs.
> > +
> > +Required properties (controller (parent) node):
> > + - compatible  : should be "mediatek,-xsphy", 
> > "mediatek,xsphy",
> > + soc-model is the name of SoC, such as mt2712 etc;
> 
> Please list all valid SoCs.
Ok
> 
> > + when using "mediatek,xsphy" compatible string, you need SoC 
> > specific
> > + ones in addition.
> > +
> > +Required nodes : a sub-node is required for each port the controller
> > + provides. Address range information including the usual
> > + 'reg' property is used inside these nodes to describe
> > + the controller's topology.
> 
> This should go afer the parent optional properties.
Ok
> 
> > +
> > +Optional properties (controller (parent) node):
> > + - reg : offset and length of register shared by multiple U3 
> > ports,
> > + exclude port's private register, if only U2 ports provided,
> > + shouldn't use the property.
> > + - mediatek,src-ref-clk-mhz: u32, frequency of reference clock for 
> > slew rate
> > + calibrate
> > + - mediatek,src-coef   : u32, coefficient for slew rate calibrate, 
> > depends on
> > + SoC process
> > +
> > +Required properties (port (child) node):
> > +- reg  : address and length of the register set for the port.
> > +- clocks   : a list of phandle + clock-specifier pairs, one for each
> > + entry in clock-names
> > +- clock-names  : must contain
> > + "ref": 48M reference clock for HighSpeed analog phy; and 26M
> > +   reference clock for SuperSpeedPlus analog phy, 
> > sometimes is
> > +   24M, 25M or 27M, depended on platform.
> > +- #phy-cells   : should be 1 (See second example)
> > + cell after port phandle is phy type from:
> > +   - PHY_TYPE_USB2
> > +   - PHY_TYPE_USB3
> 
> Is the type a property of the connection to the host? If not, this 
> shouldn't be part of the phy cells. I would add compatible strings to 
> the child nodes to define this. I think that would simplify the driver 
> too as then you can parse DT properties in probe rather than phy_init.
Yes, it is.
It's parsed when the phy is got by the host driver.
> 
> > +
> > +The following optional properties are only for debug or HQA test
> > +Optional properties (PHY_TYPE_USB2 port (child) node):
> > +- mediatek,eye-src : u32, the value of slew rate calibrate
> > +- mediatek,eye-vrt : u32, the selection of VRT reference voltage
> > +- mediatek,eye-term: u32, the selection of HS_TX TERM reference 
> > voltage
> > +- mediatek,efuse-intr  : u32, the selection of Internal Resistor
> > +
> > +Optional properties (PHY_TYPE_USB3 port (child) node):
> > +- mediatek,efuse-intr  : u32, the selection of Internal Resistor
> > +- mediatek,efuse-tx-imp: u32, the selection of TX Impedance
> > +- mediatek,efuse-rx-imp: u32, the selection of RX Impedance
> > +
> > +Example:
> > +
> > +u3phy: usb-phy@11c4 {
> > +   compatible = "mediatek,mt36xx-xsphy", "mediatek,xsphy";
> 
> Is mt36xx a specific SoC? Don't use wildcards in compatible strings.
No, will use a specific one

> 
> > +   reg = <0 0x11c43000 0 0x0200>;
> > +   mediatek,src-ref-clk-mhz = <26>;
> > +   mediatek,src-coef = <17>;
> > +   #address-c

[PATCH 1/2] dt-bindings: add MediaTek XS-PHY binding

2018-04-25 Thread Chunfeng Yun
Add a DT binding documentation of XS-PHY for MediaTek SoCs
with USB3.1 GEN2 controller

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 .../devicetree/bindings/phy/phy-mtk-xsphy.txt  |  127 
 1 file changed, 127 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt

diff --git a/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt 
b/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
new file mode 100644
index 000..23c51a0
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
@@ -0,0 +1,127 @@
+MediaTek XS-PHY binding
+--
+
+The XS-PHY controller supports physical layer functionality for USB3.1
+GEN2 controller on MediaTek SoCs.
+
+Required properties (controller (parent) node):
+ - compatible  : should be "mediatek,-xsphy", "mediatek,xsphy",
+ soc-model is the name of SoC, such as mt2712 etc;
+ when using "mediatek,xsphy" compatible string, you need SoC 
specific
+ ones in addition.
+
+Required nodes : a sub-node is required for each port the controller
+ provides. Address range information including the usual
+ 'reg' property is used inside these nodes to describe
+ the controller's topology.
+
+Optional properties (controller (parent) node):
+ - reg : offset and length of register shared by multiple U3 ports,
+ exclude port's private register, if only U2 ports provided,
+ shouldn't use the property.
+ - mediatek,src-ref-clk-mhz: u32, frequency of reference clock for slew 
rate
+ calibrate
+ - mediatek,src-coef   : u32, coefficient for slew rate calibrate, depends on
+ SoC process
+
+Required properties (port (child) node):
+- reg  : address and length of the register set for the port.
+- clocks   : a list of phandle + clock-specifier pairs, one for each
+ entry in clock-names
+- clock-names  : must contain
+ "ref": 48M reference clock for HighSpeed analog phy; and 26M
+   reference clock for SuperSpeedPlus analog phy, 
sometimes is
+   24M, 25M or 27M, depended on platform.
+- #phy-cells   : should be 1 (See second example)
+ cell after port phandle is phy type from:
+   - PHY_TYPE_USB2
+   - PHY_TYPE_USB3
+
+The following optional properties are only for debug or HQA test
+Optional properties (PHY_TYPE_USB2 port (child) node):
+- mediatek,eye-src : u32, the value of slew rate calibrate
+- mediatek,eye-vrt : u32, the selection of VRT reference voltage
+- mediatek,eye-term: u32, the selection of HS_TX TERM reference voltage
+- mediatek,efuse-intr  : u32, the selection of Internal Resistor
+
+Optional properties (PHY_TYPE_USB3 port (child) node):
+- mediatek,efuse-intr  : u32, the selection of Internal Resistor
+- mediatek,efuse-tx-imp: u32, the selection of TX Impedance
+- mediatek,efuse-rx-imp: u32, the selection of RX Impedance
+
+Example:
+
+u3phy: usb-phy@11c4 {
+   compatible = "mediatek,mt36xx-xsphy", "mediatek,xsphy";
+   reg = <0 0x11c43000 0 0x0200>;
+   mediatek,src-ref-clk-mhz = <26>;
+   mediatek,src-coef = <17>;
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+   status = "disabled";
+
+   u2port0: usb-phy@11c4 {
+   reg = <0 0x11c4 0 0x0400>;
+   clocks = <>;
+   clock-names = "ref";
+   mediatek,eye-src = <4>;
+   #phy-cells = <1>;
+   status = "okay";
+   };
+
+   u3port0: usb-phy@11c43000 {
+   reg = <0 0x11c43400 0 0x0500>;
+   clocks = <>;
+   clock-names = "ref";
+   mediatek,efuse-intr = <28>;
+   #phy-cells = <1>;
+   status = "okay";
+   };
+};
+
+Specifying phy control of devices
+-
+
+Device nodes should specify the configuration required in their "phys"
+property, containing a phandle to the phy port node and a device type;
+phy-names for each port are optional.
+
+Example:
+
+#include 
+
+ssusb: usb@112a {
+   ...
+   phys = < PHY_TYPE_USB2>, < PHY_TYPE_USB3>;
+   phy-names = "usb2-0", "usb3-0";
+   ...
+};
+
+
+Banks layout of xsphy
+-
+portoffsetbank
+u2 port00xMISC
+0x0100FMREG
+0x0300U2PHY_COM
+u2 port10x1000MISC
+0x1100FMREG
+0x1300U2PHY_COM
+u2 port

[PATCH 2/2] phy: mediatek: add XS-PHY driver

2018-04-25 Thread Chunfeng Yun
Support XS-PHY for MediaTek SoCs with USB3.1 GEN2 controller

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/phy/mediatek/Kconfig |9 +
 drivers/phy/mediatek/Makefile|1 +
 drivers/phy/mediatek/phy-mtk-xsphy.c |  600 ++
 3 files changed, 610 insertions(+)
 create mode 100644 drivers/phy/mediatek/phy-mtk-xsphy.c

diff --git a/drivers/phy/mediatek/Kconfig b/drivers/phy/mediatek/Kconfig
index 88ab4e2..8857d00 100644
--- a/drivers/phy/mediatek/Kconfig
+++ b/drivers/phy/mediatek/Kconfig
@@ -12,3 +12,12 @@ config PHY_MTK_TPHY
  different banks layout, the T-PHY with shared banks between
  multi-ports is first version, otherwise is second veriosn,
  so you can easily distinguish them by banks layout.
+
+config PHY_MTK_XSPHY
+tristate "MediaTek XS-PHY Driver"
+depends on ARCH_MEDIATEK && OF
+select GENERIC_PHY
+help
+ Enable this to support the SuperSpeedPlus XS-PHY transceiver for
+ USB3.1 GEN2 controllers on MediaTek chips. The driver supports
+ multiple USB2.0, USB3.1 GEN2 ports.
diff --git a/drivers/phy/mediatek/Makefile b/drivers/phy/mediatek/Makefile
index 1bdab14..ee49edc 100644
--- a/drivers/phy/mediatek/Makefile
+++ b/drivers/phy/mediatek/Makefile
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o
+obj-$(CONFIG_PHY_MTK_XSPHY)+= phy-mtk-xsphy.o
diff --git a/drivers/phy/mediatek/phy-mtk-xsphy.c 
b/drivers/phy/mediatek/phy-mtk-xsphy.c
new file mode 100644
index 000..020cd02
--- /dev/null
+++ b/drivers/phy/mediatek/phy-mtk-xsphy.c
@@ -0,0 +1,600 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MediaTek USB3.1 gen2 xsphy Driver
+ *
+ * Copyright (c) 2018 MediaTek Inc.
+ * Author: Chunfeng Yun <chunfeng@mediatek.com>
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* u2 phy banks */
+#define SSUSB_SIFSLV_MISC  0x000
+#define SSUSB_SIFSLV_U2FREQ0x100
+#define SSUSB_SIFSLV_U2PHY_COM 0x300
+
+/* u3 phy shared banks */
+#define SSPXTP_SIFSLV_DIG_GLB  0x000
+#define SSPXTP_SIFSLV_PHYA_GLB 0x100
+
+/* u3 phy banks */
+#define SSPXTP_SIFSLV_DIG_LN_TOP   0x000
+#define SSPXTP_SIFSLV_DIG_LN_TX0   0x100
+#define SSPXTP_SIFSLV_DIG_LN_RX0   0x200
+#define SSPXTP_SIFSLV_DIG_LN_DAIF  0x300
+#define SSPXTP_SIFSLV_PHYA_LN  0x400
+
+#define XSP_U2FREQ_FMCR0   ((SSUSB_SIFSLV_U2FREQ) + 0x00)
+#define P2F_RG_FREQDET_EN  BIT(24)
+#define P2F_RG_CYCLECNTGENMASK(23, 0)
+#define P2F_RG_CYCLECNT_VAL(x) ((P2F_RG_CYCLECNT) & (x))
+
+#define XSP_U2FREQ_MMONR0  ((SSUSB_SIFSLV_U2FREQ) + 0x0c)
+
+#define XSP_U2FREQ_FMMONR1 ((SSUSB_SIFSLV_U2FREQ) + 0x10)
+#define P2F_RG_FRCK_EN BIT(8)
+#define P2F_USB_FM_VALID   BIT(0)
+
+#define XSP_USBPHYACR0 ((SSUSB_SIFSLV_U2PHY_COM) + 0x00)
+#define P2A0_RG_INTR_ENBIT(5)
+
+#define XSP_USBPHYACR1 ((SSUSB_SIFSLV_U2PHY_COM) + 0x04)
+#define P2A1_RG_INTR_CAL   GENMASK(23, 19)
+#define P2A1_RG_INTR_CAL_VAL(x)((0x1f & (x)) << 19)
+#define P2A1_RG_VRT_SELGENMASK(14, 12)
+#define P2A1_RG_VRT_SEL_VAL(x) ((0x7 & (x)) << 12)
+#define P2A1_RG_TERM_SEL   GENMASK(10, 8)
+#define P2A1_RG_TERM_SEL_VAL(x)((0x7 & (x)) << 8)
+
+#define XSP_USBPHYACR5 ((SSUSB_SIFSLV_U2PHY_COM) + 0x014)
+#define P2A5_RG_HSTX_SRCAL_EN  BIT(15)
+#define P2A5_RG_HSTX_SRCTRLGENMASK(14, 12)
+#define P2A5_RG_HSTX_SRCTRL_VAL(x) ((0x7 & (x)) << 12)
+
+#define XSP_USBPHYACR6 ((SSUSB_SIFSLV_U2PHY_COM) + 0x018)
+#define P2A6_RG_BC11_SW_EN BIT(23)
+#define P2A6_RG_OTG_VBUSCMP_EN BIT(20)
+
+#define XSP_U2PHYDTM1  ((SSUSB_SIFSLV_U2PHY_COM) + 0x06C)
+#define P2D_FORCE_IDDIGBIT(9)
+#define P2D_RG_VBUSVALID   BIT(5)
+#define P2D_RG_SESSEND BIT(4)
+#define P2D_RG_AVALID  BIT(2)
+#define P2D_RG_IDDIG   BIT(1)
+
+#define SSPXTP_PHYA_GLB_00 ((SSPXTP_SIFSLV_PHYA_GLB) + 0x00)
+#define RG_XTP_GLB_BIAS_INTR_CTRL  GENMASK(21, 16)
+#define RG_XTP_GLB_BIAS_INTR_CTRL_VAL(x)   ((0x3f & (x)) << 16)
+
+#define SSPXTP_PHYA_LN_04  ((SSPXTP_SIFSLV_PHYA_LN) + 0x04)
+#define RG_XTP_LN0_TX_IMPSEL   GENMASK(4, 0)
+#define RG_XTP_LN0_TX_IMPSEL_VAL(x)(0x1f & (x))
+
+#define SSPXTP_PHYA_LN_14  ((SSPXTP_SIFSLV_PHYA_LN) + 0x014)
+#define RG_XTP_LN0_RX_IMPSEL   GENMASK(4, 0)
+#define RG_XTP_LN0_RX_IMPSEL_VAL(x)(0x1f & (x))
+
+#define XSP_REF_CLK26  /* MHZ */
+#define XSP_SLEW_RATE_COEF 17
+#define XSP_SR_COEF_DIVISOR1000
+#define XSP_FM_DET_CYCLE_CNT   1024
+
+struct xsphy_instance {
+   struct phy *phy;
+   void __iomem *port_base;
+   struct clk *ref_clk;/* reference clock of an

Add MediaTek XS-PHY driver

2018-04-25 Thread Chunfeng Yun
>From dfce031e29c5fddbd1ea46bb2db0cde0ba62bcb0 Mon Sep 17 00:00:00 2001
From: Chunfeng Yun <chunfeng@mediatek.com>
Date: Wed, 25 Apr 2018 15:24:40 +0800
Subject: [PATCH 0/2] Add MediaTek XS-PHY driver

This patch series support the SuperSpeedPlus XS-PHY transceiver for
USB3.1 GEN2 controller on MediaTek chips. The driver supports multiple
USB2.0, USB3.1 GEN2 ports.

Chunfeng Yun (2):
  dt-bindings: add MediaTek XS-PHY binding
  phy: mediatek: add XS-PHY driver

 .../devicetree/bindings/phy/phy-mtk-xsphy.txt  | 127 +
 drivers/phy/mediatek/Kconfig   |   9 +
 drivers/phy/mediatek/Makefile  |   1 +
 drivers/phy/mediatek/phy-mtk-xsphy.c   | 600 +
 4 files changed, 737 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-mtk-xsphy.txt
 create mode 100644 drivers/phy/mediatek/phy-mtk-xsphy.c

-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] phy: phy-mtk-tphy: fix checkpatch.pl warning about SPDX_LICENSE_TAG

2018-04-25 Thread Chunfeng Yun
Use SPDX-License-Identifier tag instead of the GPL license text

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/phy/mediatek/Makefile   |  1 +
 drivers/phy/mediatek/phy-mtk-tphy.c | 10 +-
 2 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/phy/mediatek/Makefile b/drivers/phy/mediatek/Makefile
index 763a92e..1bdab14 100644
--- a/drivers/phy/mediatek/Makefile
+++ b/drivers/phy/mediatek/Makefile
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
 #
 # Makefile for the phy drivers.
 #
diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c 
b/drivers/phy/mediatek/phy-mtk-tphy.c
index 38c281b..b962339 100644
--- a/drivers/phy/mediatek/phy-mtk-tphy.c
+++ b/drivers/phy/mediatek/phy-mtk-tphy.c
@@ -1,16 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2015 MediaTek Inc.
  * Author: Chunfeng Yun <chunfeng@mediatek.com>
  *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
  */
 
 #include 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/5] usb: mtu3: avoid TX data length truncated in SS/SSP mode

2018-04-23 Thread Chunfeng Yun
The variable of 'count' is declared as u8, this will cause an issue
due to value truncated when works in SS or SSP mode and data length
is greater than 255, so change it as u32.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_gadget_ep0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c 
b/drivers/usb/mtu3/mtu3_gadget_ep0.c
index ebdcf7a..d67b540 100644
--- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
+++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
@@ -546,7 +546,7 @@ static void ep0_tx_state(struct mtu3 *mtu)
struct usb_request *req;
u32 csr;
u8 *src;
-   u8 count;
+   u32 count;
u32 maxp;
 
dev_dbg(mtu->dev, "%s\n", __func__);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/5] usb: mtu3: fix an unrecognized issue when connected with PC

2018-04-23 Thread Chunfeng Yun
When boot on the platform with the USB cable connected to Win7,
the Win7 will pop up an error dialog: "USB Device not recognized",
but finally the Win7 can enumerate it successfully.
The root cause is as the following:
When the xHCI driver set PORT_POWER of the OTG port, and if both
IDPIN and VBUS_VALID are high at the same time, the MTU3 controller
will set SESSION and pull up DP, so the Win7 can detect existence
of USB device, but if the mtu3 driver can't switch to device mode
during the debounce time, the Win7 can not enumerate it.
Here to fix it by removing the 1s delayed EXTCON register to speed up
mode switch.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3.h|  4 
 drivers/usb/mtu3/mtu3_dr.c | 25 +++--
 2 files changed, 3 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index 2cd00a2..a56fee0 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -197,9 +197,6 @@ struct mtu3_gpd_ring {
 * @edev: external connector used to detect vbus and iddig changes
 * @vbus_nb: notifier for vbus detection
 * @vbus_nb: notifier for iddig(idpin) detection
-* @extcon_reg_dwork: delay work for extcon notifier register, waiting for
-*  xHCI driver initialization, it's necessary for system bootup
-*  as device.
 * @is_u3_drd: whether port0 supports usb3.0 dual-role device or not
 * @manual_drd_enabled: it's true when supports dual-role device by debugfs
 *  to switch host/device modes depending on user input.
@@ -209,7 +206,6 @@ struct otg_switch_mtk {
struct extcon_dev *edev;
struct notifier_block vbus_nb;
struct notifier_block id_nb;
-   struct delayed_work extcon_reg_dwork;
bool is_u3_drd;
bool manual_drd_enabled;
 };
diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c
index db7562d..80083e0 100644
--- a/drivers/usb/mtu3/mtu3_dr.c
+++ b/drivers/usb/mtu3/mtu3_dr.c
@@ -238,15 +238,6 @@ static int ssusb_extcon_register(struct otg_switch_mtk 
*otg_sx)
return 0;
 }
 
-static void extcon_register_dwork(struct work_struct *work)
-{
-   struct delayed_work *dwork = to_delayed_work(work);
-   struct otg_switch_mtk *otg_sx =
-   container_of(dwork, struct otg_switch_mtk, extcon_reg_dwork);
-
-   ssusb_extcon_register(otg_sx);
-}
-
 /*
  * We provide an interface via debugfs to switch between host and device modes
  * depending on user input.
@@ -407,18 +398,10 @@ int ssusb_otg_switch_init(struct ssusb_mtk *ssusb)
 {
struct otg_switch_mtk *otg_sx = >otg_switch;
 
-   if (otg_sx->manual_drd_enabled) {
+   if (otg_sx->manual_drd_enabled)
ssusb_debugfs_init(ssusb);
-   } else {
-   INIT_DELAYED_WORK(_sx->extcon_reg_dwork,
- extcon_register_dwork);
-
-   /*
-* It is enough to delay 1s for waiting for
-* host initialization
-*/
-   schedule_delayed_work(_sx->extcon_reg_dwork, HZ);
-   }
+   else
+   ssusb_extcon_register(otg_sx);
 
return 0;
 }
@@ -429,6 +412,4 @@ void ssusb_otg_switch_exit(struct ssusb_mtk *ssusb)
 
if (otg_sx->manual_drd_enabled)
ssusb_debugfs_exit(ssusb);
-   else
-   cancel_delayed_work(_sx->extcon_reg_dwork);
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/5] usb: mtu3: make USB_MTU3_DUAL_ROLE depend on EXTCON but not USB_MTU3

2018-04-23 Thread Chunfeng Yun
In fact the driver depends on EXTCON only when it's configed as
USB_MTU3_DUAL_ROLE, so make USB_MTU3_DUAL_ROLE depend on EXTCON but
not USB_MTU3.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/mtu3/Kconfig b/drivers/usb/mtu3/Kconfig
index 25cd619..8daf277 100644
--- a/drivers/usb/mtu3/Kconfig
+++ b/drivers/usb/mtu3/Kconfig
@@ -2,7 +2,7 @@
 
 config USB_MTU3
tristate "MediaTek USB3 Dual Role controller"
-   depends on EXTCON && (USB || USB_GADGET) && HAS_DMA
+   depends on (USB || USB_GADGET) && HAS_DMA
depends on ARCH_MEDIATEK || COMPILE_TEST
select USB_XHCI_MTK if USB_SUPPORT && USB_XHCI_HCD
help
@@ -40,6 +40,7 @@ config USB_MTU3_GADGET
 config USB_MTU3_DUAL_ROLE
bool "Dual Role mode"
depends on ((USB=y || USB=USB_MTU3) && (USB_GADGET=y || 
USB_GADGET=USB_MTU3))
+   depends on (EXTCON=y || EXTCON=USB_MTU3)
help
  This is the default mode of working of MTU3 controller where
  both host and gadget features are enabled.
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/5] usb: mtu3: fix operation failure when test TEST_J/K

2018-04-23 Thread Chunfeng Yun
There is an error dialog popped up in PC when test TEST_J/K
by EHSETT tool, due to not waiting for the completion of
control transfer. Here fix it by entering test mode after
Status Stage finish.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_gadget_ep0.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c 
b/drivers/usb/mtu3/mtu3_gadget_ep0.c
index d67b540..0d2b1cf 100644
--- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
+++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
@@ -7,6 +7,7 @@
  * Author:  Chunfeng.Yun <chunfeng@mediatek.com>
  */
 
+#include 
 #include 
 
 #include "mtu3.h"
@@ -263,6 +264,7 @@ static int handle_test_mode(struct mtu3 *mtu, struct 
usb_ctrlrequest *setup)
 {
void __iomem *mbase = mtu->mac_base;
int handled = 1;
+   u32 value;
 
switch (le16_to_cpu(setup->wIndex) >> 8) {
case TEST_J:
@@ -292,6 +294,14 @@ static int handle_test_mode(struct mtu3 *mtu, struct 
usb_ctrlrequest *setup)
if (mtu->test_mode_nr == TEST_PACKET_MODE)
ep0_load_test_packet(mtu);
 
+   /* send status before entering test mode. */
+   value = mtu3_readl(mbase, U3D_EP0CSR) & EP0_W1C_BITS;
+   mtu3_writel(mbase, U3D_EP0CSR, value | EP0_SETUPPKTRDY | EP0_DATAEND);
+
+   /* wait for ACK status sent by host */
+   readl_poll_timeout(mbase + U3D_EP0CSR, value,
+   !(value & EP0_DATAEND), 100, 5000);
+
mtu3_writel(mbase, U3D_USB2_TEST_MODE, mtu->test_mode_nr);
 
mtu->ep0_state = MU3D_EP0_STATE_SETUP;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/5] usb: mtu3: remove repeated setting of gadget state

2018-04-23 Thread Chunfeng Yun
The usb_add_gadget_udc() will set the gadget state as
USB_STATE_NOTATTACHED, so we needn't set it again.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_gadget.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
index f05f10f..de0de01 100644
--- a/drivers/usb/mtu3/mtu3_gadget.c
+++ b/drivers/usb/mtu3/mtu3_gadget.c
@@ -660,14 +660,10 @@ int mtu3_gadget_setup(struct mtu3 *mtu)
mtu3_gadget_init_eps(mtu);
 
ret = usb_add_gadget_udc(mtu->dev, >g);
-   if (ret) {
+   if (ret)
dev_err(mtu->dev, "failed to register udc\n");
-   return ret;
-   }
 
-   usb_gadget_set_state(>g, USB_STATE_NOTATTACHED);
-
-   return 0;
+   return ret;
 }
 
 void mtu3_gadget_cleanup(struct mtu3 *mtu)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 55/61] usb: mtu3: simplify getting .drvdata

2018-04-20 Thread Chunfeng Yun
hi,

On Thu, 2018-04-19 at 16:06 +0200, Wolfram Sang wrote:
> We should get drvdata from struct device directly. Going via
> platform_device is an unneeded step back and forth.
> 
> Signed-off-by: Wolfram Sang <wsa+rene...@sang-engineering.com>
> ---
> 
> Build tested only. buildbot is happy. Please apply individually.
> 
>  drivers/usb/mtu3/mtu3_plat.c | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
> index 628d5ce356ca..46551f6d16fd 100644
> --- a/drivers/usb/mtu3/mtu3_plat.c
> +++ b/drivers/usb/mtu3/mtu3_plat.c
> @@ -447,8 +447,7 @@ static int mtu3_remove(struct platform_device *pdev)
>   */
>  static int __maybe_unused mtu3_suspend(struct device *dev)
>  {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct ssusb_mtk *ssusb = platform_get_drvdata(pdev);
> + struct ssusb_mtk *ssusb = dev_get_drvdata(dev);
>  
>   dev_dbg(dev, "%s\n", __func__);
>  
> @@ -466,8 +465,7 @@ static int __maybe_unused mtu3_suspend(struct device *dev)
>  
>  static int __maybe_unused mtu3_resume(struct device *dev)
>  {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct ssusb_mtk *ssusb = platform_get_drvdata(pdev);
> + struct ssusb_mtk *ssusb = dev_get_drvdata(dev);
>   int ret;
>  
>   dev_dbg(dev, "%s\n", __func__);

Acked-by: Chunfeng Yun <chunfeng@mediatek.com>

Thanks



--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC usb-next v3 2/2] usb: core: use phy_exit during suspend if wake up is not supported

2018-03-26 Thread Chunfeng Yun
hi,
On Mon, 2018-03-26 at 22:38 +0200, Martin Blumenstingl wrote:
> If the USB controller can wake up the system (which is the case for
> example with the Mediatek USB3 IP) then we must not call phy_exit during
> suspend to ensure that the USB controller doesn't have to re-enumerate
> the devices during resume.
> However, if the USB controller cannot wake up the system (which is the
> case for example on various TI platforms using a dwc3 controller) then
> we must call phy_exit during suspend. Otherwise the PHY driver keeps the
> clocks enabled, which prevents the system from reaching the lowest power
> levels in the suspend state.
> 
> Solve this by introducing two new functions in the PHY wrapper which are
> dedicated to the suspend and resume handling.
> If the controller can wake up the system the new usb_phy_roothub_suspend
> function will simply call usb_phy_roothub_power_off. However, if wake up
> is not supported by the controller it will also call
> usb_phy_roothub_exit.
> The also new usb_phy_roothub_resume function takes care of calling
> usb_phy_roothub_init (if the controller can't wake up the system) in
> addition to usb_phy_roothub_power_on.
> 
> Fixes: 07dbff0ddbd86c ("usb: core: add a wrapper for the USB PHYs on the HCD")
> Fixes: 178a0bce05cbc1 ("usb: core: hcd: integrate the PHY wrapper into the 
> HCD core")
> Reported-by: Roger Quadros <rog...@ti.com>
> Suggested-by: Roger Quadros <rog...@ti.com>
> Suggested-by: Chunfeng Yun <chunfeng@mediatek.com>
> Signed-off-by: Martin Blumenstingl <martin.blumensti...@googlemail.com>
> ---
>  drivers/usb/core/hcd.c |  8 +---
>  drivers/usb/core/phy.c | 35 +++
>  drivers/usb/core/phy.h |  5 +
>  3 files changed, 45 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index 15b0418e3b6a..78bae4ecd68b 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -2262,7 +2262,8 @@ int hcd_bus_suspend(struct usb_device *rhdev, 
> pm_message_t msg)
>   hcd->state = HC_STATE_SUSPENDED;
>  
>   if (!PMSG_IS_AUTO(msg))
> - usb_phy_roothub_power_off(hcd->phy_roothub);
> + usb_phy_roothub_suspend(hcd->self.sysdev,
> + hcd->phy_roothub);
>  
>   /* Did we race with a root-hub wakeup event? */
>   if (rhdev->do_remote_wakeup) {
> @@ -2302,7 +2303,8 @@ int hcd_bus_resume(struct usb_device *rhdev, 
> pm_message_t msg)
>   }
>  
>   if (!PMSG_IS_AUTO(msg)) {
> - status = usb_phy_roothub_power_on(hcd->phy_roothub);
> + status = usb_phy_roothub_resume(hcd->self.sysdev,
> + hcd->phy_roothub);
>   if (status)
>   return status;
>   }
> @@ -2344,7 +2346,7 @@ int hcd_bus_resume(struct usb_device *rhdev, 
> pm_message_t msg)
>   }
>   } else {
>   hcd->state = old_state;
> - usb_phy_roothub_power_off(hcd->phy_roothub);
> + usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub);
>   dev_dbg(>dev, "bus %s fail, err %d\n",
>   "resume", status);
>   if (status != -ESHUTDOWN)
> diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> index 44f008cda7a8..a39d9bb26a4f 100644
> --- a/drivers/usb/core/phy.c
> +++ b/drivers/usb/core/phy.c
> @@ -157,3 +157,38 @@ void usb_phy_roothub_power_off(struct usb_phy_roothub 
> *phy_roothub)
>   phy_power_off(roothub_entry->phy);
>  }
>  EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off);
> +
> +int usb_phy_roothub_suspend(struct device *controller_dev,
> + struct usb_phy_roothub *phy_roothub)
> +{
> + usb_phy_roothub_power_off(phy_roothub);
> +
> + /* keep the PHYs initialized so the device can wake up the system */
> + if (device_may_wakeup(controller_dev))
> + return 0;
> +
> + return usb_phy_roothub_exit(phy_roothub);
> +}
> +EXPORT_SYMBOL_GPL(usb_phy_roothub_suspend);
> +
> +int usb_phy_roothub_resume(struct device *controller_dev,
> +struct usb_phy_roothub *phy_roothub)
> +{
> + int err;
> +
> + /* if the device can't wake up the system _exit was called */
> + if (!device_may_wakeup(controller_dev)) {
> + err = usb_phy_roothub_init(phy_roothub);
> + if (err)
> + return err;
> + }
> +
> + err = usb_phy_roothub_power_on(phy_

Re: [RFC usb-next v3 1/2] usb: core: split usb_phy_roothub_{init,alloc}

2018-03-26 Thread Chunfeng Yun
(phy_roothub))
> - return phy_roothub;
> + phy_roothub = devm_kzalloc(dev, sizeof(*phy_roothub), GFP_KERNEL);
> + if (!phy_roothub)
> + return ERR_PTR(-ENOMEM);
> +
> + INIT_LIST_HEAD(_roothub->list);
>  
>   for (i = 0; i < num_phys; i++) {
>   err = usb_phy_roothub_add_phy(dev, i, _roothub->list);
>   if (err)
> - goto err_out;
> + return ERR_PTR(err);
>   }
>  
> + return phy_roothub;
> +}
> +EXPORT_SYMBOL_GPL(usb_phy_roothub_alloc);
> +
> +int usb_phy_roothub_init(struct usb_phy_roothub *phy_roothub)
> +{
> + struct usb_phy_roothub *roothub_entry;
> + struct list_head *head;
> + int err;
> +
> + if (!phy_roothub)
> + return 0;
> +
>   head = _roothub->list;
>  
>   list_for_each_entry(roothub_entry, head, list) {
> @@ -86,14 +88,13 @@ struct usb_phy_roothub *usb_phy_roothub_init(struct 
> device *dev)
>   goto err_exit_phys;
>   }
>  
> - return phy_roothub;
> + return 0;
>  
>  err_exit_phys:
>   list_for_each_entry_continue_reverse(roothub_entry, head, list)
>   phy_exit(roothub_entry->phy);
>  
> -err_out:
> - return ERR_PTR(err);
> + return err;
>  }
>  EXPORT_SYMBOL_GPL(usb_phy_roothub_init);
>  
> diff --git a/drivers/usb/core/phy.h b/drivers/usb/core/phy.h
> index 6fde59bfbff8..eb31253201ad 100644
> --- a/drivers/usb/core/phy.h
> +++ b/drivers/usb/core/phy.h
> @@ -1,6 +1,8 @@
>  struct usb_phy_roothub;
>  
> -struct usb_phy_roothub *usb_phy_roothub_init(struct device *dev);
> +struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev);
> +
> +int usb_phy_roothub_init(struct usb_phy_roothub *phy_roothub);
>  int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub);
>  
>  int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub);

Tested-by: Chunfeng Yun <chunfeng@mediatek.com>



--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH usb-next v1] usb: core: phy: fix return value of usb_phy_roothub_exit()

2018-03-26 Thread Chunfeng Yun
Hi,
On Mon, 2018-03-26 at 22:12 +0200, Martin Blumenstingl wrote:
> Hi Chunfeng,
> 
> On Mon, Mar 26, 2018 at 5:43 AM, Chunfeng Yun <chunfeng@mediatek.com> 
> wrote:
> > On Sat, 2018-03-24 at 14:56 +0100, Martin Blumenstingl wrote:
> >> usb_phy_roothub_exit() should return the error code from the phy_exit()
> >> call if exiting the PHY failed.
> >> However, since a wrong variable is used usb_phy_roothub_exit() currently
> >> always returns 0, even if one of the phy_exit calls returned an error.
> >> Fix this by assigning the error code from phy_exit() to the "ret"
> >> variable to propagate the error correctly.
> >>
> >> Fixes: 07dbff0ddbd86c ("usb: core: add a wrapper for the USB PHYs on the 
> >> HCD")
> >> Signed-off-by: Martin Blumenstingl <martin.blumensti...@googlemail.com>
> >> ---
> >>  drivers/usb/core/phy.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> >> index 09b7c43c0ea4..f19aaa3c899c 100644
> >> --- a/drivers/usb/core/phy.c
> >> +++ b/drivers/usb/core/phy.c
> >> @@ -111,7 +111,7 @@ int usb_phy_roothub_exit(struct usb_phy_roothub 
> >> *phy_roothub)
> >>   list_for_each_entry(roothub_entry, head, list) {
> >>   err = phy_exit(roothub_entry->phy);
> >>   if (err)
> >> - ret = ret;
> >> + ret = err;
> > Need break the loop?
> in the original implementation I decided not to break the loop here so
> phy_exit is called for all PHYs -> only the problematic ones will
> remain initialized
> (in the _power_on implementation we can try to fix the state by adding
> a break and then calling _power_off for all PHYs before the "broken"
> one where _power_on failed)
> 
got it
> also if phy_exit fails then something is probably very wrong
> 
> do you have any specific use-case in mind where the missing break
> could be a problem?
No
> 
> >>   }
> >>
> >>   return ret;
> >
> >
> 
> 
> Regards
> Martin


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC usb-next v2 1/2] usb: core: split usb_phy_roothub_{init,alloc}

2018-03-26 Thread Chunfeng Yun
On Mon, 2018-03-26 at 22:31 +0200, Martin Blumenstingl wrote:
> Hi Chunfeng,
> 
> On Mon, Mar 26, 2018 at 5:37 AM, Chunfeng Yun <chunfeng@mediatek.com> 
> wrote:
> > On Sat, 2018-03-24 at 15:21 +0100, Martin Blumenstingl wrote:
> >> Before this patch usb_phy_roothub_init served two purposes (from a
> >> caller's point of view - like hcd.c):
> >> - parsing the PHYs and allocating the list entries
> >> - calling phy_init on each list entry
> >>
> >> While this worked so far it has one disadvantage: if we need to call
> >> phy_init for each PHY instance then the existing code cannot be re-used.
> >> Solve this by splitting off usb_phy_roothub_alloc which only parses the
> >> PHYs and allocates the list entries.
> >> usb_phy_roothub_init then gets a struct usb_phy_roothub and only calls
> >> phy_init on each PHY instance (along with the corresponding cleanup if
> >> that failed somewhere).
> >>
> >> This is a preparation step for adding proper suspend support for some
> >> hardware that requires phy_exit to be called during suspend and phy_init
> >> to be called during resume.
> >>
> >> Signed-off-by: Martin Blumenstingl <martin.blumensti...@googlemail.com>
> >> ---
> >>  drivers/usb/core/hcd.c | 10 +++---
> >>  drivers/usb/core/phy.c | 51 
> >> +-
> >>  drivers/usb/core/phy.h |  4 +++-
> >>  3 files changed, 35 insertions(+), 30 deletions(-)
> >>
> >> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> >> index 777036ae6367..15b0418e3b6a 100644
> >> --- a/drivers/usb/core/hcd.c
> >> +++ b/drivers/usb/core/hcd.c
> >> @@ -2758,12 +2758,16 @@ int usb_add_hcd(struct usb_hcd *hcd,
> >>   }
> >>
> >>   if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
> >> - hcd->phy_roothub = usb_phy_roothub_init(hcd->self.sysdev);
> >> + hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev);
> >>   if (IS_ERR(hcd->phy_roothub)) {
> >>   retval = PTR_ERR(hcd->phy_roothub);
> >> - goto err_phy_roothub_init;
> >> + goto err_phy_roothub_alloc;
> >>   }
> >>
> >> + retval = usb_phy_roothub_init(hcd->phy_roothub);
> >> + if (retval)
> >> + goto err_phy_roothub_alloc;
> >> +
> >>   retval = usb_phy_roothub_power_on(hcd->phy_roothub);
> >>   if (retval)
> >>   goto err_usb_phy_roothub_power_on;
> >> @@ -2936,7 +2940,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
> >>   usb_phy_roothub_power_off(hcd->phy_roothub);
> >>  err_usb_phy_roothub_power_on:
> >>   usb_phy_roothub_exit(hcd->phy_roothub);
> >> -err_phy_roothub_init:
> >> +err_phy_roothub_alloc:
> >>   if (hcd->remove_phy && hcd->usb_phy) {
> >>   usb_phy_shutdown(hcd->usb_phy);
> >>   usb_put_phy(hcd->usb_phy);
> >> diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> >> index f19aaa3c899c..d1861c5a74de 100644
> >> --- a/drivers/usb/core/phy.c
> >> +++ b/drivers/usb/core/phy.c
> >> @@ -19,19 +19,6 @@ struct usb_phy_roothub {
> >>   struct list_headlist;
> >>  };
> >>
> >> -static struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)
> >> -{
> >> - struct usb_phy_roothub *roothub_entry;
> >> -
> >> - roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), 
> >> GFP_KERNEL);
> >> - if (!roothub_entry)
> >> - return ERR_PTR(-ENOMEM);
> >> -
> >> - INIT_LIST_HEAD(_entry->list);
> >> -
> >> - return roothub_entry;
> >> -}
> >> -
> >>  static int usb_phy_roothub_add_phy(struct device *dev, int index,
> >>  struct list_head *list)
> >>  {
> >> @@ -45,9 +32,9 @@ static int usb_phy_roothub_add_phy(struct device *dev, 
> >> int index,
> >>   return PTR_ERR(phy);
> >>   }
> >
> >>
> >> - roothub_entry = usb_phy_roothub_alloc(dev);
> >> - if (IS_ERR(roothub_entry))
> >> - return PTR_ERR(roothub_entry);
> >> + roothub

Re: [PATCH usb-next v1] usb: core: phy: fix return value of usb_phy_roothub_exit()

2018-03-25 Thread Chunfeng Yun
On Sat, 2018-03-24 at 14:56 +0100, Martin Blumenstingl wrote:
> usb_phy_roothub_exit() should return the error code from the phy_exit()
> call if exiting the PHY failed.
> However, since a wrong variable is used usb_phy_roothub_exit() currently
> always returns 0, even if one of the phy_exit calls returned an error.
> Fix this by assigning the error code from phy_exit() to the "ret"
> variable to propagate the error correctly.
> 
> Fixes: 07dbff0ddbd86c ("usb: core: add a wrapper for the USB PHYs on the HCD")
> Signed-off-by: Martin Blumenstingl 
> ---
>  drivers/usb/core/phy.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> index 09b7c43c0ea4..f19aaa3c899c 100644
> --- a/drivers/usb/core/phy.c
> +++ b/drivers/usb/core/phy.c
> @@ -111,7 +111,7 @@ int usb_phy_roothub_exit(struct usb_phy_roothub 
> *phy_roothub)
>   list_for_each_entry(roothub_entry, head, list) {
>   err = phy_exit(roothub_entry->phy);
>   if (err)
> - ret = ret;
> + ret = err;
Need break the loop?
>   }
>  
>   return ret;


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC usb-next v2 1/2] usb: core: split usb_phy_roothub_{init,alloc}

2018-03-25 Thread Chunfeng Yun
On Sat, 2018-03-24 at 15:21 +0100, Martin Blumenstingl wrote:
> Before this patch usb_phy_roothub_init served two purposes (from a
> caller's point of view - like hcd.c):
> - parsing the PHYs and allocating the list entries
> - calling phy_init on each list entry
> 
> While this worked so far it has one disadvantage: if we need to call
> phy_init for each PHY instance then the existing code cannot be re-used.
> Solve this by splitting off usb_phy_roothub_alloc which only parses the
> PHYs and allocates the list entries.
> usb_phy_roothub_init then gets a struct usb_phy_roothub and only calls
> phy_init on each PHY instance (along with the corresponding cleanup if
> that failed somewhere).
> 
> This is a preparation step for adding proper suspend support for some
> hardware that requires phy_exit to be called during suspend and phy_init
> to be called during resume.
> 
> Signed-off-by: Martin Blumenstingl 
> ---
>  drivers/usb/core/hcd.c | 10 +++---
>  drivers/usb/core/phy.c | 51 
> +-
>  drivers/usb/core/phy.h |  4 +++-
>  3 files changed, 35 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index 777036ae6367..15b0418e3b6a 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -2758,12 +2758,16 @@ int usb_add_hcd(struct usb_hcd *hcd,
>   }
>  
>   if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
> - hcd->phy_roothub = usb_phy_roothub_init(hcd->self.sysdev);
> + hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev);
>   if (IS_ERR(hcd->phy_roothub)) {
>   retval = PTR_ERR(hcd->phy_roothub);
> - goto err_phy_roothub_init;
> + goto err_phy_roothub_alloc;
>   }
>  
> + retval = usb_phy_roothub_init(hcd->phy_roothub);
> + if (retval)
> + goto err_phy_roothub_alloc;
> +
>   retval = usb_phy_roothub_power_on(hcd->phy_roothub);
>   if (retval)
>   goto err_usb_phy_roothub_power_on;
> @@ -2936,7 +2940,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
>   usb_phy_roothub_power_off(hcd->phy_roothub);
>  err_usb_phy_roothub_power_on:
>   usb_phy_roothub_exit(hcd->phy_roothub);
> -err_phy_roothub_init:
> +err_phy_roothub_alloc:
>   if (hcd->remove_phy && hcd->usb_phy) {
>   usb_phy_shutdown(hcd->usb_phy);
>   usb_put_phy(hcd->usb_phy);
> diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> index f19aaa3c899c..d1861c5a74de 100644
> --- a/drivers/usb/core/phy.c
> +++ b/drivers/usb/core/phy.c
> @@ -19,19 +19,6 @@ struct usb_phy_roothub {
>   struct list_headlist;
>  };
>  
> -static struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)
> -{
> - struct usb_phy_roothub *roothub_entry;
> -
> - roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL);
> - if (!roothub_entry)
> - return ERR_PTR(-ENOMEM);
> -
> - INIT_LIST_HEAD(_entry->list);
> -
> - return roothub_entry;
> -}
> -
>  static int usb_phy_roothub_add_phy(struct device *dev, int index,
>  struct list_head *list)
>  {
> @@ -45,9 +32,9 @@ static int usb_phy_roothub_add_phy(struct device *dev, int 
> index,
>   return PTR_ERR(phy);
>   }

>  
> - roothub_entry = usb_phy_roothub_alloc(dev);
> - if (IS_ERR(roothub_entry))
> - return PTR_ERR(roothub_entry);
> + roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL);
> + if (!roothub_entry)
> + return -ENOMEM;
>  
>   roothub_entry->phy = phy;
>  
> @@ -56,11 +43,9 @@ static int usb_phy_roothub_add_phy(struct device *dev, int 
> index,
>   return 0;
>  }
>  
> -struct usb_phy_roothub *usb_phy_roothub_init(struct device *dev)
> +struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)
>  {
>   struct usb_phy_roothub *phy_roothub;
> - struct usb_phy_roothub *roothub_entry;
> - struct list_head *head;
>   int i, num_phys, err;
>  
>   num_phys = of_count_phandle_with_args(dev->of_node, "phys",
> @@ -68,16 +53,31 @@ struct usb_phy_roothub *usb_phy_roothub_init(struct 
> device *dev)
>   if (num_phys <= 0)
>   return NULL;
>  
> - phy_roothub = usb_phy_roothub_alloc(dev);
> - if (IS_ERR(phy_roothub))
> - return phy_roothub;
> + phy_roothub = devm_kzalloc(dev, sizeof(*phy_roothub), GFP_KERNEL);
> + if (!phy_roothub)
> + return ERR_PTR(-ENOMEM);
> +
> + INIT_LIST_HEAD(_roothub->list);
>  
>   for (i = 0; i < num_phys; i++) {
>   err = usb_phy_roothub_add_phy(dev, i, _roothub->list);
BTW:

static int usb_phy_roothub_add_phy(struct device *dev, int index,
   struct list_head *list)
{
struct usb_phy_roothub 

Re: [RFC usb-next v2 2/2] usb: core: use phy_exit during suspend if wake up is not supported

2018-03-25 Thread Chunfeng Yun
On Sat, 2018-03-24 at 15:21 +0100, Martin Blumenstingl wrote:
> If the USB controller can wake up the system (which is the case for
> example with the Mediatek USB3 IP) then we must not call phy_exit during
> suspend to ensure that the USB controller doesn't have to re-enumerate
> the devices during resume.
> However, if the USB controller cannot wake up the system (which is the
> case for example on various TI platforms using a dwc3 controller) then
> we must call phy_exit during suspend. Otherwise the PHY driver keeps the
> clocks enabled, which prevents the system from entering the suspend
> state.
> 
> Solve this by introducing two new functions in the PHY wrapper which are
> dedicated to the suspend and resume handling.
> If the controller can wake up the system the new usb_phy_roothub_suspend
> function will simply call usb_phy_roothub_power_off. However, if wake up
> is not supported by the controller it will also call
> usb_phy_roothub_exit.
> The also new usb_phy_roothub_resume function takes care of calling
> usb_phy_roothub_init (if the controller can't wake up the system) in
> addition to usb_phy_roothub_power_on.
> 
> Fixes: 07dbff0ddbd86c ("usb: core: add a wrapper for the USB PHYs on the HCD")
> Fixes: 178a0bce05cbc1 ("usb: core: hcd: integrate the PHY wrapper into the 
> HCD core")
> Reported-by: Roger Quadros <rog...@ti.com>
> Suggested-by: Roger Quadros <rog...@ti.com>
> Suggested-by: Chunfeng Yun <chunfeng@mediatek.com>
> Signed-off-by: Martin Blumenstingl <martin.blumensti...@googlemail.com>
> ---
>  drivers/usb/core/hcd.c |  8 +---
>  drivers/usb/core/phy.c | 37 +
>  drivers/usb/core/phy.h |  5 +
>  3 files changed, 47 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index 15b0418e3b6a..78bae4ecd68b 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -2262,7 +2262,8 @@ int hcd_bus_suspend(struct usb_device *rhdev, 
> pm_message_t msg)
>   hcd->state = HC_STATE_SUSPENDED;
>  
>   if (!PMSG_IS_AUTO(msg))
> - usb_phy_roothub_power_off(hcd->phy_roothub);
> + usb_phy_roothub_suspend(hcd->self.sysdev,
> + hcd->phy_roothub);
>  
>   /* Did we race with a root-hub wakeup event? */
>   if (rhdev->do_remote_wakeup) {
> @@ -2302,7 +2303,8 @@ int hcd_bus_resume(struct usb_device *rhdev, 
> pm_message_t msg)
>   }
>  
>   if (!PMSG_IS_AUTO(msg)) {
> - status = usb_phy_roothub_power_on(hcd->phy_roothub);
> + status = usb_phy_roothub_resume(hcd->self.sysdev,
> + hcd->phy_roothub);
>   if (status)
>   return status;
>   }
> @@ -2344,7 +2346,7 @@ int hcd_bus_resume(struct usb_device *rhdev, 
> pm_message_t msg)
>   }
>   } else {
>   hcd->state = old_state;
> - usb_phy_roothub_power_off(hcd->phy_roothub);
> + usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub);
>   dev_dbg(>dev, "bus %s fail, err %d\n",
>   "resume", status);
>   if (status != -ESHUTDOWN)
> diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> index d1861c5a74de..e794cbee97e9 100644
> --- a/drivers/usb/core/phy.c
> +++ b/drivers/usb/core/phy.c
> @@ -155,3 +155,40 @@ void usb_phy_roothub_power_off(struct usb_phy_roothub 
> *phy_roothub)
>   phy_power_off(roothub_entry->phy);
>  }
>  EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off);
> +
> +int usb_phy_roothub_suspend(struct device *controller_dev,
> + struct usb_phy_roothub *phy_roothub)
> +{
> + usb_phy_roothub_power_off(phy_roothub);
> +
> + /* keep the PHYs initialized so the device can wake up the system */
> + if (device_may_wakeup(controller_dev))
> + return 0;
> +
> + return usb_phy_roothub_exit(phy_roothub);
> +}
> +EXPORT_SYMBOL_GPL(usb_phy_roothub_suspend);
> +
> +int usb_phy_roothub_resume(struct device *controller_dev,
> +struct usb_phy_roothub *phy_roothub)
> +{
> + int err;
> +
> + /* if the device can't wake up the system _exit was called */
> + if (device_may_wakeup(controller_dev)) {
fix it as Roger suggested before:

if (!device_may_wakeup(controller_dev)) {


> + err = usb_phy_roothub_init(phy_roothub);
> + if (err)
> + return err;
> + }
> +

Re: [usb-next, v3 PATCH] usb: xhci: skip phys initialization of shared hcd

2018-03-22 Thread Chunfeng Yun
On Thu, 2018-03-22 at 13:53 +0100, Greg Kroah-Hartman wrote:
> On Thu, Mar 22, 2018 at 08:12:50PM +0800, Chunfeng Yun wrote:
> > The phys has already been initialized when add primary hcd,
> > including usb2 phys and usb3 phys also if exist, so needn't
> > re-parse "phys" property again.
> 
> Wait, why does the subject say "xhci", when this is in USB core code?
> 
> I'll go edit that by hand...
Thanks


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH usb-next v10 3/8] usb: core: add a wrapper for the USB PHYs on the HCD

2018-03-22 Thread Chunfeng Yun
On Thu, 2018-03-22 at 14:41 +0200, Roger Quadros wrote:
> On 22/03/18 10:10, Chunfeng Yun wrote:
> > Hi,
> > On Wed, 2018-03-21 at 13:30 +0200, Roger Quadros wrote:
> >> Martin,
> >>
> >> On 21/03/18 00:01, Martin Blumenstingl wrote:
> >>> Hi Roger, Hi Chunfeng,
> >>>
> >>> On Tue, Mar 20, 2018 at 1:04 PM, Chunfeng Yun <chunfeng@mediatek.com> 
> >>> wrote:
> >>>> Hi Martin & Roger:
> >>>>
> >>>> On Mon, 2018-03-19 at 17:12 +0100, Martin Blumenstingl wrote:
> >>>>> Hi Roger,
> >>>>>
> >>>>> On Mon, Mar 19, 2018 at 9:49 AM, Roger Quadros <rog...@ti.com> wrote:
> >>>>>> Hi,
> >>>>>>
> >>>>>> On 19/03/18 00:29, Martin Blumenstingl wrote:
> >>>>>>> Hi Roger,
> >>>>>>>
> >>>>>>> On Fri, Mar 16, 2018 at 3:32 PM, Roger Quadros <rog...@ti.com> wrote:
> >>>>>>>> +some TI folks
> >>>>>>>>
> >>>>>>>> Hi Martin,
> >>>>>>>>
> >>>>>>>> On 18/02/18 20:44, Martin Blumenstingl wrote:
> >>>>>>>>> Many SoC platforms have separate devices for the USB PHY which are
> >>>>>>>>> registered through the generic PHY framework. These PHYs have to be
> >>>>>>>>> enabled to make the USB controller actually work. They also have to 
> >>>>>>>>> be
> >>>>>>>>> disabled again on shutdown/suspend.
> >>>>>>>>>
> >>>>>>>>> Currently (at least) the following HCI platform drivers are using 
> >>>>>>>>> custom
> >>>>>>>>> code to obtain all PHYs via devicetree for the roothub/controller 
> >>>>>>>>> and
> >>>>>>>>> disable/enable them when required:
> >>>>>>>>> - ehci-platform.c has ehci_platform_power_{on,off}
> >>>>>>>>> - xhci-mtk.c has xhci_mtk_phy_{init,exit,power_on,power_off}
> >>>>>>>>> - ohci-platform.c has ohci_platform_power_{on,off}
> >>>>>>>>>
> >>>>>>>>> With this new wrapper the USB PHYs can be specified directly in the
> >>>>>>>>> USB controller's devicetree node (just like on the drivers listed
> >>>>>>>>> above). This allows SoCs like the Amlogic Meson GXL family to 
> >>>>>>>>> operate
> >>>>>>>>> correctly once this is wired up correctly. These SoCs use a dwc3
> >>>>>>>>> controller and require all USB PHYs to be initialized (if one of 
> >>>>>>>>> the USB
> >>>>>>>>> PHYs it not initialized then none of USB port works at all).
> >>>>>>>>>
> >>>>>>>>> Signed-off-by: Martin Blumenstingl 
> >>>>>>>>> <martin.blumensti...@googlemail.com>
> >>>>>>>>> Tested-by: Yixun Lan <yixun@amlogic.com>
> >>>>>>>>> Cc: Neil Armstrong <narmstr...@baylibre.com>
> >>>>>>>>> Cc: Chunfeng Yun <chunfeng@mediatek.com>
> >>>>>>>>
> >>>>>>>> This patch is breaking low power cases on TI SoCs when USB is in 
> >>>>>>>> host mode.
> >>>>>>>> I'll explain why below.
> >>>>>>> based on your explanation and reading the TI PHY drivers I am assuming
> >>>>>>> that the affected SoCs are using the "phy-omap-usb2" driver
> >>>>>>>
> >>>>>> yes and phy-ti-pipe3 as well i.e. "ti,phy-usb3" and "ti,omap-usb3"
> >>>>> I missed that, thanks
> >>>>>
> >>>>>>>>> ---
> >>>>>>>>>  drivers/usb/core/Makefile |   2 +-
> >>>>>>>>>  drivers/usb/core/phy.c| 158 
> >>>>>>>>> ++
> >>>>>>>>>  drivers/usb/core/phy.h|   7 ++
> >>>>>>>>>  3 files changed, 166 insertions(+), 1 deletion(-)
> >>>>>>&g

Re: [usb-next, v2 PATCH] usb: xhci: skip phys initialization of shared hcd

2018-03-22 Thread Chunfeng Yun
hi, 
On Thu, 2018-03-22 at 10:01 +0100, Greg Kroah-Hartman wrote:
> On Thu, Mar 22, 2018 at 04:39:20PM +0800, Chunfeng Yun wrote:
> > The phys has already been initialized when add primary hcd,
> > including usb2 phys and usb3 phys also if exist, so needn't
> > re-parse "phys" property again.
> > 
> > Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
> > ---
> >  drivers/usb/core/hcd.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> What changed from version 1?
V1: skip phys initialization when add shared HCD by setting
xhci->shared_hcd->skip_phy_initialization=1;
for both xhci-plat.c & xhci-mtk.c files.

V2: fix it in hcd.c suggested by Roger
> 
> Always put that below the --- line like the kernel documentation asks
> you to do.
> 
> v3?
> 
> thanks,
> 
> greg k-h


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[usb-next, v2 PATCH] usb: xhci: skip phys initialization of shared hcd

2018-03-22 Thread Chunfeng Yun
The phys has already been initialized when add primary hcd,
including usb2 phys and usb3 phys also if exist, so needn't
re-parse "phys" property again.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/core/hcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 5a92d8f..777036a 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2757,7 +2757,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
}
}
 
-   if (!hcd->skip_phy_initialization) {
+   if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
hcd->phy_roothub = usb_phy_roothub_init(hcd->self.sysdev);
if (IS_ERR(hcd->phy_roothub)) {
retval = PTR_ERR(hcd->phy_roothub);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [usb-next PATCH] usb: xhci: skip phys initialization of shared hcd

2018-03-22 Thread Chunfeng Yun
hi,

On Wed, 2018-03-21 at 14:27 +0200, Roger Quadros wrote:
> On 21/03/18 13:50, Chunfeng Yun wrote:
> > Hi Roger,
> > 
> > On Wed, 2018-03-21 at 11:05 +0200, Roger Quadros wrote:
> >> Hi Chunfeng,
> >>
> >> On 21/03/18 08:12, Chunfeng Yun wrote:
> >>> The phys has already been initialized when add primary hcd,
> >>> including usb2 phys and usb3 phys also if exist, so needn't
> >>> re-parse "phys" property again.
> >>>
> >>> Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
> >>> ---
> >>>  drivers/usb/host/xhci-mtk.c  | 1 +
> >>>  drivers/usb/host/xhci-plat.c | 1 +
> >>>  2 files changed, 2 insertions(+)
> >>>
> >>> diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
> >>> index 7334da9..6bb23fb 100644
> >>> --- a/drivers/usb/host/xhci-mtk.c
> >>> +++ b/drivers/usb/host/xhci-mtk.c
> >>> @@ -554,6 +554,7 @@ static int xhci_mtk_probe(struct platform_device 
> >>> *pdev)
> >>>   if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
> >>>   xhci->shared_hcd->can_do_streams = 1;
> >>>  
> >>> + xhci->shared_hcd->skip_phy_initialization = 1;
> >>>   ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
> >>>   if (ret)
> >>>   goto dealloc_usb2_hcd;
> >>> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> >>> index 6700e5e..65a4294 100644
> >>> --- a/drivers/usb/host/xhci-plat.c
> >>> +++ b/drivers/usb/host/xhci-plat.c
> >>> @@ -294,6 +294,7 @@ static int xhci_plat_probe(struct platform_device 
> >>> *pdev)
> >>>   if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
> >>>   xhci->shared_hcd->can_do_streams = 1;
> >>>  
> >>> + xhci->shared_hcd->skip_phy_initialization = 1;
> >>
> >> I think this is unnecessary.
> >> There aren't separate PHYs for the primary and shared HCDs right?
> > Yes, the primary and shared HCDs will get the same PHYs provided by
> > "phys" property.
> > 
> >>
> >> Also how can you be sure that phy_init() has been done for all platform 
> >> HCD users?
> > Here I assume that "phys" and "usb-phy" properties are not used at the
> > same time. There are two cases:
> > 1. Using "usb-phy": no "phys" to be got by shared HCD.
> > 2. Using "phys": the primary HCD will get those phys, so shared HCD can
> > skip them.
> 
> Now I see the problem.
> But the right fix should be in core/hcd.c
> 
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index 2884607..1d1da12 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -2757,7 +2757,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
>   }
>   }
>  
> - if (!hcd->skip_phy_initialization) {
> + if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
It's a better way.
Thanks
>   hcd->phy_roothub = usb_phy_roothub_init(hcd->self.sysdev);
>   if (IS_ERR(hcd->phy_roothub)) {
>   retval = PTR_ERR(hcd->phy_roothub);
> 
> > 
> >>
> >>>   ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
> >>>   if (ret)
> >>>   goto dealloc_usb2_hcd;
> >>>
> >>
> > 
> > 
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH usb-next v10 3/8] usb: core: add a wrapper for the USB PHYs on the HCD

2018-03-22 Thread Chunfeng Yun
Hi,
On Wed, 2018-03-21 at 13:30 +0200, Roger Quadros wrote:
> Martin,
> 
> On 21/03/18 00:01, Martin Blumenstingl wrote:
> > Hi Roger, Hi Chunfeng,
> > 
> > On Tue, Mar 20, 2018 at 1:04 PM, Chunfeng Yun <chunfeng@mediatek.com> 
> > wrote:
> >> Hi Martin & Roger:
> >>
> >> On Mon, 2018-03-19 at 17:12 +0100, Martin Blumenstingl wrote:
> >>> Hi Roger,
> >>>
> >>> On Mon, Mar 19, 2018 at 9:49 AM, Roger Quadros <rog...@ti.com> wrote:
> >>>> Hi,
> >>>>
> >>>> On 19/03/18 00:29, Martin Blumenstingl wrote:
> >>>>> Hi Roger,
> >>>>>
> >>>>> On Fri, Mar 16, 2018 at 3:32 PM, Roger Quadros <rog...@ti.com> wrote:
> >>>>>> +some TI folks
> >>>>>>
> >>>>>> Hi Martin,
> >>>>>>
> >>>>>> On 18/02/18 20:44, Martin Blumenstingl wrote:
> >>>>>>> Many SoC platforms have separate devices for the USB PHY which are
> >>>>>>> registered through the generic PHY framework. These PHYs have to be
> >>>>>>> enabled to make the USB controller actually work. They also have to be
> >>>>>>> disabled again on shutdown/suspend.
> >>>>>>>
> >>>>>>> Currently (at least) the following HCI platform drivers are using 
> >>>>>>> custom
> >>>>>>> code to obtain all PHYs via devicetree for the roothub/controller and
> >>>>>>> disable/enable them when required:
> >>>>>>> - ehci-platform.c has ehci_platform_power_{on,off}
> >>>>>>> - xhci-mtk.c has xhci_mtk_phy_{init,exit,power_on,power_off}
> >>>>>>> - ohci-platform.c has ohci_platform_power_{on,off}
> >>>>>>>
> >>>>>>> With this new wrapper the USB PHYs can be specified directly in the
> >>>>>>> USB controller's devicetree node (just like on the drivers listed
> >>>>>>> above). This allows SoCs like the Amlogic Meson GXL family to operate
> >>>>>>> correctly once this is wired up correctly. These SoCs use a dwc3
> >>>>>>> controller and require all USB PHYs to be initialized (if one of the 
> >>>>>>> USB
> >>>>>>> PHYs it not initialized then none of USB port works at all).
> >>>>>>>
> >>>>>>> Signed-off-by: Martin Blumenstingl 
> >>>>>>> <martin.blumensti...@googlemail.com>
> >>>>>>> Tested-by: Yixun Lan <yixun@amlogic.com>
> >>>>>>> Cc: Neil Armstrong <narmstr...@baylibre.com>
> >>>>>>> Cc: Chunfeng Yun <chunfeng@mediatek.com>
> >>>>>>
> >>>>>> This patch is breaking low power cases on TI SoCs when USB is in host 
> >>>>>> mode.
> >>>>>> I'll explain why below.
> >>>>> based on your explanation and reading the TI PHY drivers I am assuming
> >>>>> that the affected SoCs are using the "phy-omap-usb2" driver
> >>>>>
> >>>> yes and phy-ti-pipe3 as well i.e. "ti,phy-usb3" and "ti,omap-usb3"
> >>> I missed that, thanks
> >>>
> >>>>>>> ---
> >>>>>>>  drivers/usb/core/Makefile |   2 +-
> >>>>>>>  drivers/usb/core/phy.c| 158 
> >>>>>>> ++
> >>>>>>>  drivers/usb/core/phy.h|   7 ++
> >>>>>>>  3 files changed, 166 insertions(+), 1 deletion(-)
> >>>>>>>  create mode 100644 drivers/usb/core/phy.c
> >>>>>>>  create mode 100644 drivers/usb/core/phy.h
> >>>>>>>
> >>>>>>> diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
> >>>>>>> index 92c9cefb4317..18e874b0441e 100644
> >>>>>>> --- a/drivers/usb/core/Makefile
> >>>>>>> +++ b/drivers/usb/core/Makefile
> >>>>>>> @@ -6,7 +6,7 @@
> >>>>>>>  usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o
> >>>>>>>  usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o
> >>>>>>>  usbcore-y += devio.o notify.o generic.o quirks.o devices.o

Re: [usb-next PATCH] usb: xhci: skip phys initialization of shared hcd

2018-03-21 Thread Chunfeng Yun
Hi Roger,

On Wed, 2018-03-21 at 11:05 +0200, Roger Quadros wrote:
> Hi Chunfeng,
> 
> On 21/03/18 08:12, Chunfeng Yun wrote:
> > The phys has already been initialized when add primary hcd,
> > including usb2 phys and usb3 phys also if exist, so needn't
> > re-parse "phys" property again.
> > 
> > Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
> > ---
> >  drivers/usb/host/xhci-mtk.c  | 1 +
> >  drivers/usb/host/xhci-plat.c | 1 +
> >  2 files changed, 2 insertions(+)
> > 
> > diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
> > index 7334da9..6bb23fb 100644
> > --- a/drivers/usb/host/xhci-mtk.c
> > +++ b/drivers/usb/host/xhci-mtk.c
> > @@ -554,6 +554,7 @@ static int xhci_mtk_probe(struct platform_device *pdev)
> > if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
> > xhci->shared_hcd->can_do_streams = 1;
> >  
> > +   xhci->shared_hcd->skip_phy_initialization = 1;
> > ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
> > if (ret)
> > goto dealloc_usb2_hcd;
> > diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> > index 6700e5e..65a4294 100644
> > --- a/drivers/usb/host/xhci-plat.c
> > +++ b/drivers/usb/host/xhci-plat.c
> > @@ -294,6 +294,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
> > if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
> > xhci->shared_hcd->can_do_streams = 1;
> >  
> > +   xhci->shared_hcd->skip_phy_initialization = 1;
> 
> I think this is unnecessary.
> There aren't separate PHYs for the primary and shared HCDs right?
Yes, the primary and shared HCDs will get the same PHYs provided by
"phys" property.

> 
> Also how can you be sure that phy_init() has been done for all platform HCD 
> users?
Here I assume that "phys" and "usb-phy" properties are not used at the
same time. There are two cases:
1. Using "usb-phy": no "phys" to be got by shared HCD.
2. Using "phys": the primary HCD will get those phys, so shared HCD can
skip them.

> 
> > ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
> > if (ret)
> > goto dealloc_usb2_hcd;
> > 
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[usb-next PATCH] usb: xhci: skip phys initialization of shared hcd

2018-03-21 Thread Chunfeng Yun
The phys has already been initialized when add primary hcd,
including usb2 phys and usb3 phys also if exist, so needn't
re-parse "phys" property again.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/host/xhci-mtk.c  | 1 +
 drivers/usb/host/xhci-plat.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 7334da9..6bb23fb 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -554,6 +554,7 @@ static int xhci_mtk_probe(struct platform_device *pdev)
if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
xhci->shared_hcd->can_do_streams = 1;
 
+   xhci->shared_hcd->skip_phy_initialization = 1;
ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
if (ret)
goto dealloc_usb2_hcd;
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 6700e5e..65a4294 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -294,6 +294,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
xhci->shared_hcd->can_do_streams = 1;
 
+   xhci->shared_hcd->skip_phy_initialization = 1;
ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
if (ret)
goto dealloc_usb2_hcd;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH usb-next v10 3/8] usb: core: add a wrapper for the USB PHYs on the HCD

2018-03-20 Thread Chunfeng Yun
Hi Martin,

On Tue, 2018-03-20 at 22:57 +0100, Martin Blumenstingl wrote:
> Hello Kishon,
> 
> On Tue, Mar 20, 2018 at 12:27 PM, Kishon Vijay Abraham I <kis...@ti.com> 
> wrote:
> > Hi,
> >
> > On Monday 19 March 2018 09:42 PM, Martin Blumenstingl wrote:
> >> Hi Roger,
> >>
> >> On Mon, Mar 19, 2018 at 9:49 AM, Roger Quadros <rog...@ti.com> wrote:
> >>> Hi,
> >>>
> >>> On 19/03/18 00:29, Martin Blumenstingl wrote:
> >>>> Hi Roger,
> >>>>
> >>>> On Fri, Mar 16, 2018 at 3:32 PM, Roger Quadros <rog...@ti.com> wrote:
> >>>>> +some TI folks
> >>>>>
> >>>>> Hi Martin,
> >>>>>
> >>>>> On 18/02/18 20:44, Martin Blumenstingl wrote:
> >>>>>> Many SoC platforms have separate devices for the USB PHY which are
> >>>>>> registered through the generic PHY framework. These PHYs have to be
> >>>>>> enabled to make the USB controller actually work. They also have to be
> >>>>>> disabled again on shutdown/suspend.
> >>>>>>
> >>>>>> Currently (at least) the following HCI platform drivers are using 
> >>>>>> custom
> >>>>>> code to obtain all PHYs via devicetree for the roothub/controller and
> >>>>>> disable/enable them when required:
> >>>>>> - ehci-platform.c has ehci_platform_power_{on,off}
> >>>>>> - xhci-mtk.c has xhci_mtk_phy_{init,exit,power_on,power_off}
> >>>>>> - ohci-platform.c has ohci_platform_power_{on,off}
> >>>>>>
> >>>>>> With this new wrapper the USB PHYs can be specified directly in the
> >>>>>> USB controller's devicetree node (just like on the drivers listed
> >>>>>> above). This allows SoCs like the Amlogic Meson GXL family to operate
> >>>>>> correctly once this is wired up correctly. These SoCs use a dwc3
> >>>>>> controller and require all USB PHYs to be initialized (if one of the 
> >>>>>> USB
> >>>>>> PHYs it not initialized then none of USB port works at all).
> >>>>>>
> >>>>>> Signed-off-by: Martin Blumenstingl <martin.blumensti...@googlemail.com>
> >>>>>> Tested-by: Yixun Lan <yixun@amlogic.com>
> >>>>>> Cc: Neil Armstrong <narmstr...@baylibre.com>
> >>>>>> Cc: Chunfeng Yun <chunfeng@mediatek.com>
> >>>>>
> >>>>> This patch is breaking low power cases on TI SoCs when USB is in host 
> >>>>> mode.
> >>>>> I'll explain why below.
> >>>> based on your explanation and reading the TI PHY drivers I am assuming
> >>>> that the affected SoCs are using the "phy-omap-usb2" driver
> >>>>
> >>> yes and phy-ti-pipe3 as well i.e. "ti,phy-usb3" and "ti,omap-usb3"
> >> I missed that, thanks
> >>
> >>>>>> ---
> >>>>>>  drivers/usb/core/Makefile |   2 +-
> >>>>>>  drivers/usb/core/phy.c| 158 
> >>>>>> ++
> >>>>>>  drivers/usb/core/phy.h|   7 ++
> >>>>>>  3 files changed, 166 insertions(+), 1 deletion(-)
> >>>>>>  create mode 100644 drivers/usb/core/phy.c
> >>>>>>  create mode 100644 drivers/usb/core/phy.h
> >>>>>>
> >>>>>> diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
> >>>>>> index 92c9cefb4317..18e874b0441e 100644
> >>>>>> --- a/drivers/usb/core/Makefile
> >>>>>> +++ b/drivers/usb/core/Makefile
> >>>>>> @@ -6,7 +6,7 @@
> >>>>>>  usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o
> >>>>>>  usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o
> >>>>>>  usbcore-y += devio.o notify.o generic.o quirks.o devices.o
> >>>>>> -usbcore-y += port.o
> >>>>>> +usbcore-y += phy.o port.o
> >>>>>>
> >>>>>>  usbcore-$(CONFIG_OF) += of.o
> >>>>>>  usbcore-$(CONFIG_USB_PCI)+= hcd-pci.o
> >>>>>> diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> >>>>>> new f

Re: [PATCH usb-next v10 3/8] usb: core: add a wrapper for the USB PHYs on the HCD

2018-03-20 Thread Chunfeng Yun
Hi Martin & Roger:

On Mon, 2018-03-19 at 17:12 +0100, Martin Blumenstingl wrote:
> Hi Roger,
> 
> On Mon, Mar 19, 2018 at 9:49 AM, Roger Quadros <rog...@ti.com> wrote:
> > Hi,
> >
> > On 19/03/18 00:29, Martin Blumenstingl wrote:
> >> Hi Roger,
> >>
> >> On Fri, Mar 16, 2018 at 3:32 PM, Roger Quadros <rog...@ti.com> wrote:
> >>> +some TI folks
> >>>
> >>> Hi Martin,
> >>>
> >>> On 18/02/18 20:44, Martin Blumenstingl wrote:
> >>>> Many SoC platforms have separate devices for the USB PHY which are
> >>>> registered through the generic PHY framework. These PHYs have to be
> >>>> enabled to make the USB controller actually work. They also have to be
> >>>> disabled again on shutdown/suspend.
> >>>>
> >>>> Currently (at least) the following HCI platform drivers are using custom
> >>>> code to obtain all PHYs via devicetree for the roothub/controller and
> >>>> disable/enable them when required:
> >>>> - ehci-platform.c has ehci_platform_power_{on,off}
> >>>> - xhci-mtk.c has xhci_mtk_phy_{init,exit,power_on,power_off}
> >>>> - ohci-platform.c has ohci_platform_power_{on,off}
> >>>>
> >>>> With this new wrapper the USB PHYs can be specified directly in the
> >>>> USB controller's devicetree node (just like on the drivers listed
> >>>> above). This allows SoCs like the Amlogic Meson GXL family to operate
> >>>> correctly once this is wired up correctly. These SoCs use a dwc3
> >>>> controller and require all USB PHYs to be initialized (if one of the USB
> >>>> PHYs it not initialized then none of USB port works at all).
> >>>>
> >>>> Signed-off-by: Martin Blumenstingl <martin.blumensti...@googlemail.com>
> >>>> Tested-by: Yixun Lan <yixun@amlogic.com>
> >>>> Cc: Neil Armstrong <narmstr...@baylibre.com>
> >>>> Cc: Chunfeng Yun <chunfeng@mediatek.com>
> >>>
> >>> This patch is breaking low power cases on TI SoCs when USB is in host 
> >>> mode.
> >>> I'll explain why below.
> >> based on your explanation and reading the TI PHY drivers I am assuming
> >> that the affected SoCs are using the "phy-omap-usb2" driver
> >>
> > yes and phy-ti-pipe3 as well i.e. "ti,phy-usb3" and "ti,omap-usb3"
> I missed that, thanks
> 
> >>>> ---
> >>>>  drivers/usb/core/Makefile |   2 +-
> >>>>  drivers/usb/core/phy.c| 158 
> >>>> ++
> >>>>  drivers/usb/core/phy.h|   7 ++
> >>>>  3 files changed, 166 insertions(+), 1 deletion(-)
> >>>>  create mode 100644 drivers/usb/core/phy.c
> >>>>  create mode 100644 drivers/usb/core/phy.h
> >>>>
> >>>> diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
> >>>> index 92c9cefb4317..18e874b0441e 100644
> >>>> --- a/drivers/usb/core/Makefile
> >>>> +++ b/drivers/usb/core/Makefile
> >>>> @@ -6,7 +6,7 @@
> >>>>  usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o
> >>>>  usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o
> >>>>  usbcore-y += devio.o notify.o generic.o quirks.o devices.o
> >>>> -usbcore-y += port.o
> >>>> +usbcore-y += phy.o port.o
> >>>>
> >>>>  usbcore-$(CONFIG_OF) += of.o
> >>>>  usbcore-$(CONFIG_USB_PCI)+= hcd-pci.o
> >>>> diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> >>>> new file mode 100644
> >>>> index ..09b7c43c0ea4
> >>>> --- /dev/null
> >>>> +++ b/drivers/usb/core/phy.c
> >>>> @@ -0,0 +1,158 @@
> >>>> +// SPDX-License-Identifier: GPL-2.0+
> >>>> +/*
> >>>> + * A wrapper for multiple PHYs which passes all phy_* function calls to
> >>>> + * multiple (actual) PHY devices. This is comes handy when initializing
> >>>> + * all PHYs on a HCD and to keep them all in the same state.
> >>>> + *
> >>>> + * Copyright (C) 2018 Martin Blumenstingl 
> >>>> <martin.blumensti...@googlemail.com>
> >>>> + */
> >>>> +
> >>>> +#include 
> >>>> +#includ

Re: [PATCH usb-next v10 3/8] usb: core: add a wrapper for the USB PHYs on the HCD

2018-03-20 Thread Chunfeng Yun
Hi Martin,

On Mon, 2018-03-19 at 17:12 +0100, Martin Blumenstingl wrote:
> Hi Roger,
> 
> On Mon, Mar 19, 2018 at 9:49 AM, Roger Quadros <rog...@ti.com> wrote:
> > Hi,
> >
> > On 19/03/18 00:29, Martin Blumenstingl wrote:
> >> Hi Roger,
> >>
> >> On Fri, Mar 16, 2018 at 3:32 PM, Roger Quadros <rog...@ti.com> wrote:
> >>> +some TI folks
> >>>
> >>> Hi Martin,
> >>>
> >>> On 18/02/18 20:44, Martin Blumenstingl wrote:
> >>>> Many SoC platforms have separate devices for the USB PHY which are
> >>>> registered through the generic PHY framework. These PHYs have to be
> >>>> enabled to make the USB controller actually work. They also have to be
> >>>> disabled again on shutdown/suspend.
> >>>>
> >>>> Currently (at least) the following HCI platform drivers are using custom
> >>>> code to obtain all PHYs via devicetree for the roothub/controller and
> >>>> disable/enable them when required:
> >>>> - ehci-platform.c has ehci_platform_power_{on,off}
> >>>> - xhci-mtk.c has xhci_mtk_phy_{init,exit,power_on,power_off}
> >>>> - ohci-platform.c has ohci_platform_power_{on,off}
> >>>>
> >>>> With this new wrapper the USB PHYs can be specified directly in the
> >>>> USB controller's devicetree node (just like on the drivers listed
> >>>> above). This allows SoCs like the Amlogic Meson GXL family to operate
> >>>> correctly once this is wired up correctly. These SoCs use a dwc3
> >>>> controller and require all USB PHYs to be initialized (if one of the USB
> >>>> PHYs it not initialized then none of USB port works at all).
> >>>>
> >>>> Signed-off-by: Martin Blumenstingl <martin.blumensti...@googlemail.com>
> >>>> Tested-by: Yixun Lan <yixun@amlogic.com>
> >>>> Cc: Neil Armstrong <narmstr...@baylibre.com>
> >>>> Cc: Chunfeng Yun <chunfeng@mediatek.com>
> >>>
> >>> This patch is breaking low power cases on TI SoCs when USB is in host 
> >>> mode.
> >>> I'll explain why below.
> >> based on your explanation and reading the TI PHY drivers I am assuming
> >> that the affected SoCs are using the "phy-omap-usb2" driver
> >>
> > yes and phy-ti-pipe3 as well i.e. "ti,phy-usb3" and "ti,omap-usb3"
> I missed that, thanks
> 
> >>>> ---
> >>>>  drivers/usb/core/Makefile |   2 +-
> >>>>  drivers/usb/core/phy.c| 158 
> >>>> ++
> >>>>  drivers/usb/core/phy.h|   7 ++
> >>>>  3 files changed, 166 insertions(+), 1 deletion(-)
> >>>>  create mode 100644 drivers/usb/core/phy.c
> >>>>  create mode 100644 drivers/usb/core/phy.h
> >>>>
> >>>> diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
> >>>> index 92c9cefb4317..18e874b0441e 100644
> >>>> --- a/drivers/usb/core/Makefile
> >>>> +++ b/drivers/usb/core/Makefile
> >>>> @@ -6,7 +6,7 @@
> >>>>  usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o
> >>>>  usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o
> >>>>  usbcore-y += devio.o notify.o generic.o quirks.o devices.o
> >>>> -usbcore-y += port.o
> >>>> +usbcore-y += phy.o port.o
> >>>>
> >>>>  usbcore-$(CONFIG_OF) += of.o
> >>>>  usbcore-$(CONFIG_USB_PCI)+= hcd-pci.o
> >>>> diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> >>>> new file mode 100644
> >>>> index ..09b7c43c0ea4
> >>>> --- /dev/null
> >>>> +++ b/drivers/usb/core/phy.c
> >>>> @@ -0,0 +1,158 @@
> >>>> +// SPDX-License-Identifier: GPL-2.0+
> >>>> +/*
> >>>> + * A wrapper for multiple PHYs which passes all phy_* function calls to
> >>>> + * multiple (actual) PHY devices. This is comes handy when initializing
> >>>> + * all PHYs on a HCD and to keep them all in the same state.
> >>>> + *
> >>>> + * Copyright (C) 2018 Martin Blumenstingl 
> >>>> <martin.blumensti...@googlemail.com>
> >>>> + */
> >>>> +
> >>>> +#include 
> >>>> +#include 
&

Re: [PATCH usb-next v10 3/8] usb: core: add a wrapper for the USB PHYs on the HCD

2018-03-19 Thread Chunfeng Yun
Hi,
On Sun, 2018-03-18 at 23:29 +0100, Martin Blumenstingl wrote:
> Hi Roger,
> 
> On Fri, Mar 16, 2018 at 3:32 PM, Roger Quadros <rog...@ti.com> wrote:
> > +some TI folks
> >
> > Hi Martin,
> >
> > On 18/02/18 20:44, Martin Blumenstingl wrote:
> >> Many SoC platforms have separate devices for the USB PHY which are
> >> registered through the generic PHY framework. These PHYs have to be
> >> enabled to make the USB controller actually work. They also have to be
> >> disabled again on shutdown/suspend.
> >>
> >> Currently (at least) the following HCI platform drivers are using custom
> >> code to obtain all PHYs via devicetree for the roothub/controller and
> >> disable/enable them when required:
> >> - ehci-platform.c has ehci_platform_power_{on,off}
> >> - xhci-mtk.c has xhci_mtk_phy_{init,exit,power_on,power_off}
> >> - ohci-platform.c has ohci_platform_power_{on,off}
> >>
> >> With this new wrapper the USB PHYs can be specified directly in the
> >> USB controller's devicetree node (just like on the drivers listed
> >> above). This allows SoCs like the Amlogic Meson GXL family to operate
> >> correctly once this is wired up correctly. These SoCs use a dwc3
> >> controller and require all USB PHYs to be initialized (if one of the USB
> >> PHYs it not initialized then none of USB port works at all).
> >>
> >> Signed-off-by: Martin Blumenstingl <martin.blumensti...@googlemail.com>
> >> Tested-by: Yixun Lan <yixun@amlogic.com>
> >> Cc: Neil Armstrong <narmstr...@baylibre.com>
> >> Cc: Chunfeng Yun <chunfeng@mediatek.com>
> >
> > This patch is breaking low power cases on TI SoCs when USB is in host mode.
> > I'll explain why below.
> based on your explanation and reading the TI PHY drivers I am assuming
> that the affected SoCs are using the "phy-omap-usb2" driver
> 
[...]
> >> +
> >> +struct usb_phy_roothub *usb_phy_roothub_init(struct device *dev)
> >> +{
> >> + struct usb_phy_roothub *phy_roothub;
> >> + struct usb_phy_roothub *roothub_entry;
> >> + struct list_head *head;
> >> + int i, num_phys, err;
> >> +
> >> + num_phys = of_count_phandle_with_args(dev->of_node, "phys",
> >> +   "#phy-cells");
> >> + if (num_phys <= 0)
> >> + return NULL;
> >> +
> >> + phy_roothub = usb_phy_roothub_alloc(dev);
> >> + if (IS_ERR(phy_roothub))
> >> + return phy_roothub;
> >> +
> >> + for (i = 0; i < num_phys; i++) {
> >> + err = usb_phy_roothub_add_phy(dev, i, _roothub->list);
> >> + if (err)
> >> + goto err_out;
> >> + }
> >> +
> >> + head = _roothub->list;
> >> +
> >> + list_for_each_entry(roothub_entry, head, list) {
> >> + err = phy_init(roothub_entry->phy);
> >
> > The phy_init() function actually enables the PHY clocks.
> > It should be moved to the usb_phy_roothub_exit() routine just before 
> > calling phy_power_on().
> do you mean that phy_init should be moved to usb_phy_roothub_power_on
> (just before phy_power_on is called within usb_phy_roothub_power_on)?
> 
> an earlier version of my patch did exactly this, but it caused
> problems during a suspend/resume cycle on Mediatek devices
> Chunfeng Yun reported that issue here [0], quote from that mail for
> easier reading:
> "In order to keep link state on mt8173, we just power off all phys(not
> exit) when system enter suspend, then power on them again (needn't
> init, otherwise device will be disconnected) when system resume, this
> can avoid re-enumerating device."
> 
> >> + if (err)
> >> + goto err_exit_phys;
> >> + }
> >> +
> >> + return phy_roothub;
> >> +
> >> +err_exit_phys:
> >> + list_for_each_entry_continue_reverse(roothub_entry, head, list)
> >> + phy_exit(roothub_entry->phy);
> >> +
> >> +err_out:
> >> + return ERR_PTR(err);
> >> +}
> >> +EXPORT_SYMBOL_GPL(usb_phy_roothub_init);
> >> +
> >> +int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub)
> >> +{
> >> + struct usb_phy_roothub *roothub_entry;
> >> + struct list_head *head;
> >> + int err, r

Re: [PATCH usb-next v10 3/8] usb: core: add a wrapper for the USB PHYs on the HCD

2018-03-18 Thread Chunfeng Yun
On Fri, 2018-03-16 at 16:32 +0200, Roger Quadros wrote:
> +some TI folks
> 
> Hi Martin,
> 
> On 18/02/18 20:44, Martin Blumenstingl wrote:
> > Many SoC platforms have separate devices for the USB PHY which are
> > registered through the generic PHY framework. These PHYs have to be
> > enabled to make the USB controller actually work. They also have to be
> > disabled again on shutdown/suspend.
> > 
> > Currently (at least) the following HCI platform drivers are using custom
> > code to obtain all PHYs via devicetree for the roothub/controller and
> > disable/enable them when required:
> > - ehci-platform.c has ehci_platform_power_{on,off}
> > - xhci-mtk.c has xhci_mtk_phy_{init,exit,power_on,power_off}
> > - ohci-platform.c has ohci_platform_power_{on,off}
> > 
> > With this new wrapper the USB PHYs can be specified directly in the
> > USB controller's devicetree node (just like on the drivers listed
> > above). This allows SoCs like the Amlogic Meson GXL family to operate
> > correctly once this is wired up correctly. These SoCs use a dwc3
> > controller and require all USB PHYs to be initialized (if one of the USB
> > PHYs it not initialized then none of USB port works at all).
> > 
> > Signed-off-by: Martin Blumenstingl <martin.blumensti...@googlemail.com>
> > Tested-by: Yixun Lan <yixun@amlogic.com>
> > Cc: Neil Armstrong <narmstr...@baylibre.com>
> > Cc: Chunfeng Yun <chunfeng@mediatek.com>
> 
> This patch is breaking low power cases on TI SoCs when USB is in host mode.
> I'll explain why below.
> 
> > ---
> >  drivers/usb/core/Makefile |   2 +-
> >  drivers/usb/core/phy.c| 158 
> > ++
> >  drivers/usb/core/phy.h|   7 ++
> >  3 files changed, 166 insertions(+), 1 deletion(-)
> >  create mode 100644 drivers/usb/core/phy.c
> >  create mode 100644 drivers/usb/core/phy.h
> > 
> > diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
> > index 92c9cefb4317..18e874b0441e 100644
> > --- a/drivers/usb/core/Makefile
> > +++ b/drivers/usb/core/Makefile
> > @@ -6,7 +6,7 @@
> >  usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o
> >  usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o
> >  usbcore-y += devio.o notify.o generic.o quirks.o devices.o
> > -usbcore-y += port.o
> > +usbcore-y += phy.o port.o
> >  
> >  usbcore-$(CONFIG_OF)   += of.o
> >  usbcore-$(CONFIG_USB_PCI)  += hcd-pci.o
> > diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
> > new file mode 100644
> > index ..09b7c43c0ea4
> > --- /dev/null
> > +++ b/drivers/usb/core/phy.c
> > @@ -0,0 +1,158 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * A wrapper for multiple PHYs which passes all phy_* function calls to
> > + * multiple (actual) PHY devices. This is comes handy when initializing
> > + * all PHYs on a HCD and to keep them all in the same state.
> > + *
> > + * Copyright (C) 2018 Martin Blumenstingl 
> > <martin.blumensti...@googlemail.com>
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "phy.h"
> > +
> > +struct usb_phy_roothub {
> > +   struct phy  *phy;
> > +   struct list_headlist;
> > +};
> > +
> > +static struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)
> > +{
> > +   struct usb_phy_roothub *roothub_entry;
> > +
> > +   roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL);
> > +   if (!roothub_entry)
> > +   return ERR_PTR(-ENOMEM);
> > +
> > +   INIT_LIST_HEAD(_entry->list);
> > +
> > +   return roothub_entry;
> > +}
> > +
> > +static int usb_phy_roothub_add_phy(struct device *dev, int index,
> > +  struct list_head *list)
> > +{
> > +   struct usb_phy_roothub *roothub_entry;
> > +   struct phy *phy = devm_of_phy_get_by_index(dev, dev->of_node, index);
> > +
> > +   if (IS_ERR_OR_NULL(phy)) {
> > +   if (!phy || PTR_ERR(phy) == -ENODEV)
> > +   return 0;
> > +   else
> > +   return PTR_ERR(phy);
> > +   }
> > +
> > +   roothub_entry = usb_phy_roothub_alloc(dev);
> > +   if (IS_ERR(roothub_entry))
> > +   return PTR_ERR(roothub_entry);
> > +
> > +   roothub_entry->phy = phy;
> > +
> > +   list_add_tail(_entry-&

Re: [PATCH v2 3/3] dt-bindings: phy-mtk-tphy: add properties for U2 slew rate calibrate

2018-03-18 Thread Chunfeng Yun
On Sun, 2018-03-18 at 07:48 -0500, Rob Herring wrote:
> On Mon, Mar 12, 2018 at 01:25:40PM +0800, Chunfeng Yun wrote:
> > Add two properties of ref_clk and coefficient used by U2 slew rate
> > calibrate which may vary on different SoCs
> > 
> > Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
> > ---
> >  Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt | 4 
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt 
> > b/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
> > index 41e09ed..0d34b2b 100644
> > --- a/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
> > +++ b/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
> > @@ -27,6 +27,10 @@ Optional properties (controller (parent) node):
> >   - reg : offset and length of register shared by multiple 
> > ports,
> >   exclude port's private register. It is needed on mt2701
> >   and mt8173, but not on mt2712.
> > + - mediatek,src-ref-clk-mhz: frequency of reference clock for slew 
> > rate
> > + calibrate
> > + - mediatek,src-coef   : coefficient for slew rate calibrate, depends 
> > on
> > + SoC process
> 
> What are valid values? This is one cell?
Yes, one cell, integer type. If need, I'll send a new patch

Thanks
> 
> >  
> >  Required properties (port (child) node):
> >  - reg  : address and length of the register set for the port.
> > -- 
> > 1.9.1
> > 


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: misc: supports Apple Carplay driver

2018-03-14 Thread Chunfeng Yun
On Wed, 2018-03-14 at 07:16 +0100, Greg Kroah-Hartman wrote:
> On Wed, Mar 14, 2018 at 02:02:36PM +0800, Chunfeng Yun wrote:
> > The driver is used to support Apple carplay feature by a debugfs
> > interface which can force the driver to send a USB Vendor Request
> > of "Apple Device to Host Mode Switch" to switch Apple Device
> > into host mode.
> 
> While I am all for crazy debugfs interfaces, I would _strongly_ suggest
> not doing that here for the main API to the device.  I know Android is
> trying to prevent any new devices from even enabling debugfs, and as the
> file system requires root permissions by default, you are forcing any
> user of your new api to run as root, which is not a good idea either.
> 
> Given that all you are doing here is a single usb control message, why
> does this even need to be a kernel driver at all?  Can't you do the same
> thing from userspace with a simple libusb/usbfs program?  Or even a
> simple script?
Ok, I'll abandon this patch, and do it by libusb

Thanks a lot

> 
> thanks,
> 
> greg k-h


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Add Apple Carplay driver

2018-03-14 Thread Chunfeng Yun
On Tue, 2018-03-13 at 23:53 -0700, Matthew Dharm wrote:
> Why is this a kernel-level driver, rather than a userspace application
> that uses libusb to send the single vendor-specific command required?
> Since this command would be applicable to many CarPlay devices, with
> many different VID/PIDs, it would seem to make more sense as a
> userspace app that took a reference to a USB device or VID/PID.
Sorry, I'm not familiar with libusb.
But after I roughly read a simple example using libusb, it indeed can be
realized by a userspace driver.

Thanks for your useful comments

> 
> Matt
> 
> On Tue, Mar 13, 2018 at 11:02 PM, Chunfeng Yun
> <chunfeng@mediatek.com> wrote:
> > From bf48dcd9cb254576cfea373c9a5d2ab996408895 Mon Sep 17 00:00:00 2001
> > From: Chunfeng Yun <chunfeng@mediatek.com>
> > Date: Tue, 13 Mar 2018 11:47:38 +0800
> > Subject: [PATCH] Add Apple Carplay driver
> >
> > Some Apple devices which support Carplay can enter USB Host Mode from USB
> > Device Mode after receiving a specific USB Vendor Request. There is a
> > requirement apply to accesssories that support the USB dual role switch
> > feature, and must have a USB-A receptacle that is capable of functioning
> > in both USB Host and USB Device roles.
> > It means that the driver should supports manual Dual-Role switch, due to
> > no IDDIG pin is avaliable.
> >
> > There is no suitable place to add this spicific USB Vendor Request, so
> > here I extract a single driver which allow user force to send it by a debug
> > interface when need it, and keep it independent on USB Dual-Role Controller
> > Drivers.
> > But to implement carplay feature, there are some requirments for USB 
> > Dual-Role
> > Driver:
> > 1. supports manual dual-role switch, such as, by a debug interface;
> > 2. keep vbus alive even when switch host into device mode;
> >
> > More information please refer to "Chapter 46. USB Role Switch" in
> > MFI Accessroy Interface Specification.pdf
> >
> > Chunfeng Yun (1):
> >   usb: misc: supports Apple Carplay driver
> >
> >  drivers/usb/misc/Kconfig   |9 +++
> >  drivers/usb/misc/Makefile  |1 +
> >  drivers/usb/misc/carplay.c |  193 
> > 
> >  3 files changed, 203 insertions(+)
> >  create mode 100644 drivers/usb/misc/carplay.c
> >
> > --
> > 1.7.9.5
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> > the body of a message to majord...@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 3/3] dt-bindings: phy-mtk-tphy: add properties for U2 slew rate calibrate

2018-03-14 Thread Chunfeng Yun
On Wed, 2018-03-14 at 00:21 +0100, Matthias Brugger wrote:
> 
> On 03/12/2018 06:25 AM, Chunfeng Yun wrote:
> > Add two properties of ref_clk and coefficient used by U2 slew rate
> > calibrate which may vary on different SoCs
> > 
> > Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
> 
> Reviewed-by: Matthias Brugger <matthias@gmail.com>
> 
Thanks again

> > ---
> >  Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt | 4 
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt 
> > b/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
> > index 41e09ed..0d34b2b 100644
> > --- a/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
> > +++ b/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
> > @@ -27,6 +27,10 @@ Optional properties (controller (parent) node):
> >   - reg : offset and length of register shared by multiple 
> > ports,
> >   exclude port's private register. It is needed on mt2701
> >   and mt8173, but not on mt2712.
> > + - mediatek,src-ref-clk-mhz: frequency of reference clock for slew 
> > rate
> > + calibrate
> > + - mediatek,src-coef   : coefficient for slew rate calibrate, depends 
> > on
> > + SoC process
> >  
> >  Required properties (port (child) node):
> >  - reg  : address and length of the register set for the port.
> > 


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/3] phy: phy-mtk-tphy: add configurable parameters for slew rate calibrate

2018-03-14 Thread Chunfeng Yun
On Wed, 2018-03-14 at 00:21 +0100, Matthias Brugger wrote:
> 
> On 03/12/2018 06:25 AM, Chunfeng Yun wrote:
> > There are two parameters, ref_clk and coefficient, for U2 slew rate
> > calibrate which may vary on different SoCs, here allow them to be
> > configurable
> > 
> > Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
> 
> Reviewed-by: Matthias Brugger <matthias@gmail.com>
> 
Thanks
> 
> > ---
> >  drivers/phy/mediatek/phy-mtk-tphy.c | 20 +++-
> >  1 file changed, 15 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c 
> > b/drivers/phy/mediatek/phy-mtk-tphy.c
> > index 6073c25..38c281b 100644
> > --- a/drivers/phy/mediatek/phy-mtk-tphy.c
> > +++ b/drivers/phy/mediatek/phy-mtk-tphy.c
> > @@ -306,6 +306,8 @@ struct mtk_tphy {
> > const struct mtk_phy_pdata *pdata;
> > struct mtk_phy_instance **phys;
> > int nphys;
> > +   int src_ref_clk; /* MHZ, reference clock for slew rate calibrate */
> > +   int src_coef; /* coefficient for slew rate calibrate */
> >  };
> >  
> >  static void hs_slew_rate_calibrate(struct mtk_tphy *tphy,
> > @@ -360,16 +362,17 @@ static void hs_slew_rate_calibrate(struct mtk_tphy 
> > *tphy,
> > writel(tmp, fmreg + U3P_U2FREQ_FMMONR1);
> >  
> > if (fm_out) {
> > -   /* ( 1024 / FM_OUT ) x reference clock frequency x 0.028 */
> > -   tmp = U3P_FM_DET_CYCLE_CNT * U3P_REF_CLK * U3P_SLEW_RATE_COEF;
> > -   tmp /= fm_out;
> > +   /* ( 1024 / FM_OUT ) x reference clock frequency x coef */
> > +   tmp = tphy->src_ref_clk * tphy->src_coef;
> > +   tmp = (tmp * U3P_FM_DET_CYCLE_CNT) / fm_out;
> > calibration_val = DIV_ROUND_CLOSEST(tmp, U3P_SR_COEF_DIVISOR);
> > } else {
> > /* if FM detection fail, set default value */
> > calibration_val = 4;
> > }
> > -   dev_dbg(tphy->dev, "phy:%d, fm_out:%d, calib:%d\n",
> > -   instance->index, fm_out, calibration_val);
> > +   dev_dbg(tphy->dev, "phy:%d, fm_out:%d, calib:%d (clk:%d, coef:%d)\n",
> > +   instance->index, fm_out, calibration_val,
> > +   tphy->src_ref_clk, tphy->src_coef);
> >  
> > /* set HS slew rate */
> > tmp = readl(com + U3P_USBPHYACR5);
> > @@ -1041,6 +1044,13 @@ static int mtk_tphy_probe(struct platform_device 
> > *pdev)
> > tphy->u3phya_ref = NULL;
> > }
> >  
> > +   tphy->src_ref_clk = U3P_REF_CLK;
> > +   tphy->src_coef = U3P_SLEW_RATE_COEF;
> > +   /* update parameters of slew rate calibrate if exist */
> > +   device_property_read_u32(dev, "mediatek,src-ref-clk-mhz",
> > +   >src_ref_clk);
> > +   device_property_read_u32(dev, "mediatek,src-coef", >src_coef);
> > +
> > port = 0;
> > for_each_child_of_node(np, child_np) {
> > struct mtk_phy_instance *instance;
> > 


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Add Apple Carplay driver

2018-03-14 Thread Chunfeng Yun
>From bf48dcd9cb254576cfea373c9a5d2ab996408895 Mon Sep 17 00:00:00 2001
From: Chunfeng Yun <chunfeng@mediatek.com>
Date: Tue, 13 Mar 2018 11:47:38 +0800
Subject: [PATCH] Add Apple Carplay driver

Some Apple devices which support Carplay can enter USB Host Mode from USB
Device Mode after receiving a specific USB Vendor Request. There is a
requirement apply to accesssories that support the USB dual role switch
feature, and must have a USB-A receptacle that is capable of functioning
in both USB Host and USB Device roles.
It means that the driver should supports manual Dual-Role switch, due to
no IDDIG pin is avaliable.

There is no suitable place to add this spicific USB Vendor Request, so
here I extract a single driver which allow user force to send it by a debug
interface when need it, and keep it independent on USB Dual-Role Controller
Drivers.
But to implement carplay feature, there are some requirments for USB Dual-Role
Driver:
1. supports manual dual-role switch, such as, by a debug interface;
2. keep vbus alive even when switch host into device mode;

More information please refer to "Chapter 46. USB Role Switch" in
MFI Accessroy Interface Specification.pdf

Chunfeng Yun (1):
  usb: misc: supports Apple Carplay driver

 drivers/usb/misc/Kconfig   |9 +++
 drivers/usb/misc/Makefile  |1 +
 drivers/usb/misc/carplay.c |  193 
 3 files changed, 203 insertions(+)
 create mode 100644 drivers/usb/misc/carplay.c

-- 
1.7.9.5


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] usb: misc: supports Apple Carplay driver

2018-03-14 Thread Chunfeng Yun
The driver is used to support Apple carplay feature by a debugfs
interface which can force the driver to send a USB Vendor Request
of "Apple Device to Host Mode Switch" to switch Apple Device
into host mode.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/misc/Kconfig   |9 ++
 drivers/usb/misc/Makefile  |1 +
 drivers/usb/misc/carplay.c |  205 
 3 files changed, 215 insertions(+)
 create mode 100644 drivers/usb/misc/carplay.c

diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index 68d2f2c..c010c95 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -275,3 +275,12 @@ config USB_CHAOSKEY
 
  To compile this driver as a module, choose M here: the
  module will be called chaoskey.
+
+config USB_CARPLAY
+   tristate "USB carplay driver support"
+   help
+ The driver is used to support Apple carplay feature.
+ It is realized by sending a USB Vendor Request of "Apple Device to
+ Host Mode Switch" to switch Apple Device into host mode.
+ When the users want to use carplay, they can force the driver to send
+ this Vendor Request by a debugfs interface.
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 109f54f..94380e7 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -29,5 +29,6 @@ obj-$(CONFIG_USB_HSIC_USB3503)+= usb3503.o
 obj-$(CONFIG_USB_HSIC_USB4604) += usb4604.o
 obj-$(CONFIG_USB_CHAOSKEY) += chaoskey.o
 
+obj-$(CONFIG_USB_CARPLAY)  += carplay.o
 obj-$(CONFIG_USB_SISUSBVGA)+= sisusbvga/
 obj-$(CONFIG_USB_LINK_LAYER_TEST)  += lvstest.o
diff --git a/drivers/usb/misc/carplay.c b/drivers/usb/misc/carplay.c
new file mode 100644
index 000..bfd41f3
--- /dev/null
+++ b/drivers/usb/misc/carplay.c
@@ -0,0 +1,205 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * carplay.c - carplay usb driver
+ *
+ * Copyright (C) 2018 MediaTek Inc.
+ *
+ * Author: Chunfeng Yun <chunfeng@mediatek.com>
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * usage:
+ * The requirement for the platform using Carplay feature is that support
+ * the USB Dual Role Switch feature, and must have a USB-A receptacle
+ * that is capable of functioning in both USB Host and USB Device roles.
+ *
+ * 1. Apple iphone is enumerated as a usb device
+ * 2. switch Apple iphone to host mode, by, e.g.
+ *echo host > /sys/kernel/debug/usb/carplay.1-1/mode
+ * 3. switch the platform to device mode, but meanwhile should keep vbus alive;
+ * 4. use carplay feature after the platform is enumerated as a usb device;
+ * 5. when unplug usb cable, switch the platform back to host mode.
+ *
+ * step 2 is supported by this driver;
+ * step 1, 3, 4, 5 should be supported by the USB Dual-Role Controller Driver
+ *on the platform.
+ *
+ * For more detailed information, please refer to "Chapter 46. USB Role Switch"
+ * in MFI Accessroy Interface Specification.pdf
+ */
+
+#define CARPLAY_NAME "carplay"
+#define VENDER_REQ_DEV_TO_HOST 0x51
+
+struct usb_carplay {
+   struct usb_interface *intf;
+   struct usb_device *udev;
+   struct dentry *droot;
+   struct device *idev;
+   bool is_host;
+};
+
+static int carplay_switch_to_host(struct usb_carplay *ucp)
+{
+   struct usb_device *udev = ucp->udev;
+   int retval;
+
+   if (!ucp->udev)
+   return -ENODEV;
+
+   retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
+   VENDER_REQ_DEV_TO_HOST, USB_TYPE_VENDOR,
+   1, 0, NULL, 0, USB_CTRL_GET_TIMEOUT);
+
+   dev_dbg(ucp->idev, "%s retval = %d\n", __func__, retval);
+
+   if (retval != 0) {
+   dev_err(ucp->idev, "%s fail retval = %d\n", __func__, retval);
+   return retval;
+   }
+   ucp->is_host = true;
+
+   return 0;
+}
+
+static int carplay_mode_show(struct seq_file *sf, void *unused)
+{
+   struct usb_carplay *ucp = sf->private;
+
+   seq_printf(sf, "current mode: %s\n(usage: echo host > mode)\n",
+   ucp->is_host ? "host" : "device");
+
+   return 0;
+}
+
+static int carplay_mode_open(struct inode *inode, struct file *file)
+{
+   return single_open(file, carplay_mode_show, inode->i_private);
+}
+
+static ssize_t carplay_mode_write(struct file *file,
+   const char __user *ubuf, size_t count, loff_t *ppos)
+{
+   struct seq_file *sf = file->private_data;
+   struct usb_carplay *ucp = sf->private;
+   char buf[16];
+
+   if (copy_from_user(, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+   return -EFAULT;
+
+   if (!strncmp(b

[PATCH v2 3/3] dt-bindings: phy-mtk-tphy: add properties for U2 slew rate calibrate

2018-03-11 Thread Chunfeng Yun
Add two properties of ref_clk and coefficient used by U2 slew rate
calibrate which may vary on different SoCs

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt | 4 
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt 
b/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
index 41e09ed..0d34b2b 100644
--- a/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
+++ b/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
@@ -27,6 +27,10 @@ Optional properties (controller (parent) node):
  - reg : offset and length of register shared by multiple ports,
  exclude port's private register. It is needed on mt2701
  and mt8173, but not on mt2712.
+ - mediatek,src-ref-clk-mhz: frequency of reference clock for slew rate
+ calibrate
+ - mediatek,src-coef   : coefficient for slew rate calibrate, depends on
+ SoC process
 
 Required properties (port (child) node):
 - reg  : address and length of the register set for the port.
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/3] phy: phy-mtk-tphy: add configurable parameters for slew rate calibrate

2018-03-11 Thread Chunfeng Yun
There are two parameters, ref_clk and coefficient, for U2 slew rate
calibrate which may vary on different SoCs, here allow them to be
configurable

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/phy/mediatek/phy-mtk-tphy.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c 
b/drivers/phy/mediatek/phy-mtk-tphy.c
index 6073c25..38c281b 100644
--- a/drivers/phy/mediatek/phy-mtk-tphy.c
+++ b/drivers/phy/mediatek/phy-mtk-tphy.c
@@ -306,6 +306,8 @@ struct mtk_tphy {
const struct mtk_phy_pdata *pdata;
struct mtk_phy_instance **phys;
int nphys;
+   int src_ref_clk; /* MHZ, reference clock for slew rate calibrate */
+   int src_coef; /* coefficient for slew rate calibrate */
 };
 
 static void hs_slew_rate_calibrate(struct mtk_tphy *tphy,
@@ -360,16 +362,17 @@ static void hs_slew_rate_calibrate(struct mtk_tphy *tphy,
writel(tmp, fmreg + U3P_U2FREQ_FMMONR1);
 
if (fm_out) {
-   /* ( 1024 / FM_OUT ) x reference clock frequency x 0.028 */
-   tmp = U3P_FM_DET_CYCLE_CNT * U3P_REF_CLK * U3P_SLEW_RATE_COEF;
-   tmp /= fm_out;
+   /* ( 1024 / FM_OUT ) x reference clock frequency x coef */
+   tmp = tphy->src_ref_clk * tphy->src_coef;
+   tmp = (tmp * U3P_FM_DET_CYCLE_CNT) / fm_out;
calibration_val = DIV_ROUND_CLOSEST(tmp, U3P_SR_COEF_DIVISOR);
} else {
/* if FM detection fail, set default value */
calibration_val = 4;
}
-   dev_dbg(tphy->dev, "phy:%d, fm_out:%d, calib:%d\n",
-   instance->index, fm_out, calibration_val);
+   dev_dbg(tphy->dev, "phy:%d, fm_out:%d, calib:%d (clk:%d, coef:%d)\n",
+   instance->index, fm_out, calibration_val,
+   tphy->src_ref_clk, tphy->src_coef);
 
/* set HS slew rate */
tmp = readl(com + U3P_USBPHYACR5);
@@ -1041,6 +1044,13 @@ static int mtk_tphy_probe(struct platform_device *pdev)
tphy->u3phya_ref = NULL;
}
 
+   tphy->src_ref_clk = U3P_REF_CLK;
+   tphy->src_coef = U3P_SLEW_RATE_COEF;
+   /* update parameters of slew rate calibrate if exist */
+   device_property_read_u32(dev, "mediatek,src-ref-clk-mhz",
+   >src_ref_clk);
+   device_property_read_u32(dev, "mediatek,src-coef", >src_coef);
+
port = 0;
for_each_child_of_node(np, child_np) {
struct mtk_phy_instance *instance;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/3] phy: phy-mtk-tphy: keep default value of mcu_bus_ck_gate_en

2018-03-11 Thread Chunfeng Yun
The default value of mcu_bus_ck_gate_en is 1, if clear it, will
prevent system to enter deep idle mode, so keep its default value
and without affecting PCIe function.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/phy/mediatek/phy-mtk-tphy.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c 
b/drivers/phy/mediatek/phy-mtk-tphy.c
index 1e96d07..6073c25 100644
--- a/drivers/phy/mediatek/phy-mtk-tphy.c
+++ b/drivers/phy/mediatek/phy-mtk-tphy.c
@@ -688,8 +688,7 @@ static void pcie_phy_instance_power_on(struct mtk_tphy 
*tphy,
u32 tmp;
 
tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLD);
-   tmp &= ~(P3C_FORCE_IP_SW_RST | P3C_MCU_BUS_CK_GATE_EN |
-   P3C_REG_IP_SW_RST);
+   tmp &= ~(P3C_FORCE_IP_SW_RST | P3C_REG_IP_SW_RST);
writel(tmp, bank->chip + U3P_U3_CHIP_GPIO_CTLD);
 
tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLE);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] phy: phy-mtk-tphy: add configurable parameters for slew rate calibrate

2018-03-11 Thread Chunfeng Yun
There are two parameters, ref_clk and coefficient, for U2 slew rate
calibrate which may vary on different SoCs, here allow them to be
configurable

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/phy/mediatek/phy-mtk-tphy.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c 
b/drivers/phy/mediatek/phy-mtk-tphy.c
index 6073c25..38c281b 100644
--- a/drivers/phy/mediatek/phy-mtk-tphy.c
+++ b/drivers/phy/mediatek/phy-mtk-tphy.c
@@ -306,6 +306,8 @@ struct mtk_tphy {
const struct mtk_phy_pdata *pdata;
struct mtk_phy_instance **phys;
int nphys;
+   int src_ref_clk; /* MHZ, reference clock for slew rate calibrate */
+   int src_coef; /* coefficient for slew rate calibrate */
 };
 
 static void hs_slew_rate_calibrate(struct mtk_tphy *tphy,
@@ -360,16 +362,17 @@ static void hs_slew_rate_calibrate(struct mtk_tphy *tphy,
writel(tmp, fmreg + U3P_U2FREQ_FMMONR1);
 
if (fm_out) {
-   /* ( 1024 / FM_OUT ) x reference clock frequency x 0.028 */
-   tmp = U3P_FM_DET_CYCLE_CNT * U3P_REF_CLK * U3P_SLEW_RATE_COEF;
-   tmp /= fm_out;
+   /* ( 1024 / FM_OUT ) x reference clock frequency x coef */
+   tmp = tphy->src_ref_clk * tphy->src_coef;
+   tmp = (tmp * U3P_FM_DET_CYCLE_CNT) / fm_out;
calibration_val = DIV_ROUND_CLOSEST(tmp, U3P_SR_COEF_DIVISOR);
} else {
/* if FM detection fail, set default value */
calibration_val = 4;
}
-   dev_dbg(tphy->dev, "phy:%d, fm_out:%d, calib:%d\n",
-   instance->index, fm_out, calibration_val);
+   dev_dbg(tphy->dev, "phy:%d, fm_out:%d, calib:%d (clk:%d, coef:%d)\n",
+   instance->index, fm_out, calibration_val,
+   tphy->src_ref_clk, tphy->src_coef);
 
/* set HS slew rate */
tmp = readl(com + U3P_USBPHYACR5);
@@ -1041,6 +1044,13 @@ static int mtk_tphy_probe(struct platform_device *pdev)
tphy->u3phya_ref = NULL;
}
 
+   tphy->src_ref_clk = U3P_REF_CLK;
+   tphy->src_coef = U3P_SLEW_RATE_COEF;
+   /* update parameters of slew rate calibrate if exist */
+   device_property_read_u32(dev, "mediatek,src-ref-clk-mhz",
+   >src_ref_clk);
+   device_property_read_u32(dev, "mediatek,src-coef", >src_coef);
+
port = 0;
for_each_child_of_node(np, child_np) {
struct mtk_phy_instance *instance;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/3] phy: phy-mtk-tphy: keep default value of mcu_bus_ck_gate_en

2018-03-11 Thread Chunfeng Yun
The default value of mcu_bus_ck_gate_en is 1, if clear it, will
prevent system to enter deep idle mode, so keep its default value
and without affecting PCIe function.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/phy/mediatek/phy-mtk-tphy.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c 
b/drivers/phy/mediatek/phy-mtk-tphy.c
index 1e96d07..6073c25 100644
--- a/drivers/phy/mediatek/phy-mtk-tphy.c
+++ b/drivers/phy/mediatek/phy-mtk-tphy.c
@@ -688,8 +688,7 @@ static void pcie_phy_instance_power_on(struct mtk_tphy 
*tphy,
u32 tmp;
 
tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLD);
-   tmp &= ~(P3C_FORCE_IP_SW_RST | P3C_MCU_BUS_CK_GATE_EN |
-   P3C_REG_IP_SW_RST);
+   tmp &= ~(P3C_FORCE_IP_SW_RST | P3C_REG_IP_SW_RST);
writel(tmp, bank->chip + U3P_U3_CHIP_GPIO_CTLD);
 
tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLE);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] phy: phy-mtk-tphy: add properties for U2 slew rate calibrate

2018-03-11 Thread Chunfeng Yun
Add two properties of ref_clk and coefficient used by U2 slew rate
calibrate which may vary on different SoCs

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt | 4 
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt 
b/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
index 41e09ed..0d34b2b 100644
--- a/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
+++ b/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
@@ -27,6 +27,10 @@ Optional properties (controller (parent) node):
  - reg : offset and length of register shared by multiple ports,
  exclude port's private register. It is needed on mt2701
  and mt8173, but not on mt2712.
+ - mediatek,src-ref-clk-mhz: frequency of reference clock for slew rate
+ calibrate
+ - mediatek,src-coef   : coefficient for slew rate calibrate, depends on
+ SoC process
 
 Required properties (port (child) node):
 - reg  : address and length of the register set for the port.
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: how to disable a xhci logical port?

2018-01-29 Thread Chunfeng Yun
Hi Bin,

On Mon, 2018-01-29 at 08:32 -0600, Bin Liu wrote:
> On Sat, Jan 27, 2018 at 09:20:56AM +0100, Greg KH wrote:
> > On Fri, Jan 26, 2018 at 12:56:26PM -0600, Bin Liu wrote:
> > > Hi,
> > > 
> > > A xHCI controller has two logical ports, hs and ss port. Is it
> > > possible to disable one port, for example the ss port? If so, how?
> > 
> > Why would you want to do that?
> 
> On the device I have (TI AM57x), PCIe and USB share the ss PHY. Now I am
> trying to figure out how to let PCIe use the ss PHY and disable it in
> USB.
> 
> Simply removing the ss PHY nodes from USB in devicetree causes kernel
> crashes at boot (but the crash log doesn't directly link to USB
> subsystem), so I wanted to ask how to disable the xhci ss roothub before
> I dig into the crash.
Maybe it's helpful to disable u3port with shared PHY but not SS roothub.

> 
> > 
> > > By disable, I meant the xHCI driver doesn't see the port when the xHCI
> > > driver is loaded and doesn't create that usb bus.
> > 
> > That goes against the spec for the hardware from what I can tell.
> 
> Okay, I will look into it from a different direction - focus on the
> crash log.
> 
> Thanks,
> -Bin.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/RFT usb-next v1 1/6] usb: mtu3: remove custom USB PHY handling

2018-01-24 Thread Chunfeng Yun
Hi,

On Thu, 2018-01-25 at 01:16 +0100, Martin Blumenstingl wrote:
> The new PHY wrapper is now wired up in the core HCD code. This means
> that PHYs are now controlled (initialized, enabled, disabled, exited)
> without requiring any host-driver specific code.
> Remove the custom USB PHY handling from the mtu3 driver as the core HCD
> code now handles this.
> 
> Signed-off-by: Martin Blumenstingl 
> ---
>  drivers/usb/mtu3/mtu3_plat.c | 101 
> ---
>  1 file changed, 101 deletions(-)
> 
> diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
> index 628d5ce356ca..a894ddf25bcd 100644
> --- a/drivers/usb/mtu3/mtu3_plat.c
> +++ b/drivers/usb/mtu3/mtu3_plat.c
> @@ -44,62 +44,6 @@ int ssusb_check_clocks(struct ssusb_mtk *ssusb, u32 
> ex_clks)
>   return 0;
>  }
>  
> -static int ssusb_phy_init(struct ssusb_mtk *ssusb)
> -{
> - int i;
> - int ret;
> -
> - for (i = 0; i < ssusb->num_phys; i++) {
> - ret = phy_init(ssusb->phys[i]);
> - if (ret)
> - goto exit_phy;
> - }
> - return 0;
> -
> -exit_phy:
> - for (; i > 0; i--)
> - phy_exit(ssusb->phys[i - 1]);
> -
> - return ret;
> -}
> -
> -static int ssusb_phy_exit(struct ssusb_mtk *ssusb)
> -{
> - int i;
> -
> - for (i = 0; i < ssusb->num_phys; i++)
> - phy_exit(ssusb->phys[i]);
> -
> - return 0;
> -}
> -
> -static int ssusb_phy_power_on(struct ssusb_mtk *ssusb)
> -{
> - int i;
> - int ret;
> -
> - for (i = 0; i < ssusb->num_phys; i++) {
> - ret = phy_power_on(ssusb->phys[i]);
> - if (ret)
> - goto power_off_phy;
> - }
> - return 0;
> -
> -power_off_phy:
> - for (; i > 0; i--)
> - phy_power_off(ssusb->phys[i - 1]);
> -
> - return ret;
> -}
> -
> -static void ssusb_phy_power_off(struct ssusb_mtk *ssusb)
> -{
> - unsigned int i;
> -
> - for (i = 0; i < ssusb->num_phys; i++)
> - phy_power_off(ssusb->phys[i]);
> -}
> -
>  static int ssusb_clks_enable(struct ssusb_mtk *ssusb)
>  {
>   int ret;
> @@ -162,24 +106,8 @@ static int ssusb_rscs_init(struct ssusb_mtk *ssusb)
>   if (ret)
>   goto clks_err;
>  
> - ret = ssusb_phy_init(ssusb);
> - if (ret) {
> - dev_err(ssusb->dev, "failed to init phy\n");
> - goto phy_init_err;
> - }
> -
> - ret = ssusb_phy_power_on(ssusb);
> - if (ret) {
> - dev_err(ssusb->dev, "failed to power on phy\n");
> - goto phy_err;
> - }
> -
>   return 0;
>  
> -phy_err:
> - ssusb_phy_exit(ssusb);
> -phy_init_err:
> - ssusb_clks_disable(ssusb);
>  clks_err:
>   regulator_disable(ssusb->vusb33);
>  vusb33_err:
> @@ -190,8 +118,6 @@ static void ssusb_rscs_exit(struct ssusb_mtk *ssusb)
>  {
>   ssusb_clks_disable(ssusb);
>   regulator_disable(ssusb->vusb33);
> - ssusb_phy_power_off(ssusb);
> - ssusb_phy_exit(ssusb);
>  }
>  
>  static void ssusb_ip_sw_reset(struct ssusb_mtk *ssusb)
> @@ -222,7 +148,6 @@ static int get_ssusb_rscs(struct platform_device *pdev, 
> struct ssusb_mtk *ssusb)
>   struct device *dev = >dev;
>   struct regulator *vbus;
>   struct resource *res;
> - int i;
>   int ret;
>  
>   ssusb->vusb33 = devm_regulator_get(>dev, "vusb33");
> @@ -249,25 +174,6 @@ static int get_ssusb_rscs(struct platform_device *pdev, 
> struct ssusb_mtk *ssusb)
>   if (IS_ERR(ssusb->dma_clk))
>   return PTR_ERR(ssusb->dma_clk);
>  
> - ssusb->num_phys = of_count_phandle_with_args(node,
> - "phys", "#phy-cells");
> - if (ssusb->num_phys > 0) {
> - ssusb->phys = devm_kcalloc(dev, ssusb->num_phys,
> - sizeof(*ssusb->phys), GFP_KERNEL);
> - if (!ssusb->phys)
> - return -ENOMEM;
> - } else {
> - ssusb->num_phys = 0;
> - }
> -
> - for (i = 0; i < ssusb->num_phys; i++) {
> - ssusb->phys[i] = devm_of_phy_get_by_index(dev, node, i);
> - if (IS_ERR(ssusb->phys[i])) {
> - dev_err(dev, "failed to get phy-%d\n", i);
> - return PTR_ERR(ssusb->phys[i]);
> - }
> - }
> -
>   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ippc");
>   ssusb->ippc_base = devm_ioremap_resource(dev, res);
>   if (IS_ERR(ssusb->ippc_base))
> @@ -457,7 +363,6 @@ static int __maybe_unused mtu3_suspend(struct device *dev)
>   return 0;
>  
>   ssusb_host_disable(ssusb, true);
> - ssusb_phy_power_off(ssusb);
>   ssusb_clks_disable(ssusb);
>   ssusb_wakeup_set(ssusb, true);
>  
> @@ -480,16 +385,10 @@ static int __maybe_unused mtu3_resume(struct device 
> *dev)
>   if (ret)
>   goto clks_err;
>  
> - ret = ssusb_phy_power_on(ssusb);
> - if (ret)
> -

Re: linux-next: Tree for Jan 15 (drivers/usb/mtu3/)

2018-01-15 Thread Chunfeng Yun
Hi,

Arnd had sent a patch to fix this issue,

please refer to : https://patchwork.kernel.org/patch/10155685

thanks

On Mon, 2018-01-15 at 11:34 -0800, Randy Dunlap wrote:
> On 01/14/2018 09:44 PM, Stephen Rothwell wrote:
> > Hi all,
> > 
> > Changes since 20180112:
> > 
> 
> on i386:
> 
> ../drivers/usb/mtu3/mtu3_plat.c: In function 'mtu3_suspend':
> ../drivers/usb/mtu3/mtu3_plat.c:462:2: error: implicit declaration of 
> function 'ssusb_wakeup_set' [-Werror=implicit-function-declaration]
>   ssusb_wakeup_set(ssusb, true);
>   ^
> 
> when:
> CONFIG_USB_MTU3=y
> # CONFIG_USB_MTU3_HOST is not set
> CONFIG_USB_MTU3_GADGET=y
> # CONFIG_USB_MTU3_DUAL_ROLE is not set
> # CONFIG_USB_MTU3_DEBUG is not set
> 
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: xhci-mtk: fix semicolon.cocci warnings

2018-01-12 Thread Chunfeng Yun
On Sat, 2018-01-13 at 01:46 +0800, kbuild test robot wrote:
> From: Fengguang Wu <fengguang...@intel.com>
> 
> drivers/usb/host/xhci-mtk.c:311:2-3: Unneeded semicolon
> 
> 
>  Remove unneeded semicolon.
> 
> Generated by: scripts/coccinelle/misc/semicolon.cocci
> 
> Fixes: a2ecc4df9f84 ("usb: xhci-mtk: supports remote wakeup for mt2712 with 
> two xHCI IPs")
> CC: Chunfeng Yun <chunfeng@mediatek.com>
> Signed-off-by: Fengguang Wu <fengguang...@intel.com>
> ---
> 
>  xhci-mtk.c |2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/drivers/usb/host/xhci-mtk.c
> +++ b/drivers/usb/host/xhci-mtk.c
> @@ -308,7 +308,7 @@ static void usb_wakeup_ip_sleep_set(stru
>   break;
>   default:
>   return;
> -     };
> + }
>   regmap_update_bits(mtk->uwk, reg, msk, val);
>  }
>  
Thanks

Acked-by: Chunfeng Yun <chunfeng@mediatek.com>


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: mtu3: fix semicolon.cocci warnings

2018-01-12 Thread Chunfeng Yun
On Sat, 2018-01-13 at 01:18 +0800, kbuild test robot wrote:
> From: Fengguang Wu <fengguang...@intel.com>
> 
> drivers/usb/mtu3/mtu3_host.c:58:2-3: Unneeded semicolon
> 
> 
>  Remove unneeded semicolon.
> 
> Generated by: scripts/coccinelle/misc/semicolon.cocci
> 
> Fixes: f0ede2c6282b ("usb: mtu3: supports remote wakeup for mt2712 with two 
> SSUSB IPs")
> CC: Chunfeng Yun <chunfeng@mediatek.com>
> Signed-off-by: Fengguang Wu <fengguang...@intel.com>
> ---
> 
>  mtu3_host.c |2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/drivers/usb/mtu3/mtu3_host.c
> +++ b/drivers/usb/mtu3/mtu3_host.c
> @@ -55,7 +55,7 @@ static void ssusb_wakeup_ip_sleep_set(st
>   break;
>   default:
>   return;
> - };
> +     }
>   regmap_update_bits(ssusb->uwk, reg, msk, val);
>  }
>  
Thanks a lot.

Acked-by: Chunfeng Yun <chunfeng@mediatek.com>


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: mtu3: fix ssusb_wakeup_set dummy

2018-01-10 Thread Chunfeng Yun
On Wed, 2018-01-10 at 17:45 +0100, Arnd Bergmann wrote:
> Changing from ssusb_wakeup_enable/disable to ssusb_wakeup_set was done
> in only one of two places in the kernel, the other one now causes a
> build failure:
> 
> drivers/usb/mtu3/mtu3_plat.c: In function 'mtu3_suspend':
> drivers/usb/mtu3/mtu3_plat.c:462:2: error: implicit declaration of function 
> 'ssusb_wakeup_set'; did you mean 'ssusb_wakeup_disable'? 
> [-Werror=implicit-function-declaration]
> 
> This adapts the dummy helpers the same way that the extern declarations
> were.
> 
> Fixes: f0ede2c6282b ("usb: mtu3: supports remote wakeup for mt2712 with two 
> SSUSB IPs")
> Signed-off-by: Arnd Bergmann <a...@arndb.de>
> ---
>  drivers/usb/mtu3/mtu3_dr.h | 7 +--
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/usb/mtu3/mtu3_dr.h b/drivers/usb/mtu3/mtu3_dr.h
> index ae1598d76e02..50702fdcde28 100644
> --- a/drivers/usb/mtu3/mtu3_dr.h
> +++ b/drivers/usb/mtu3/mtu3_dr.h
> @@ -48,12 +48,7 @@ static inline int ssusb_host_disable(struct ssusb_mtk 
> *ssusb, bool suspend)
>   return 0;
>  }
>  
> -static inline int ssusb_wakeup_enable(struct ssusb_mtk *ssusb)
> -{
> - return 0;
> -}
> -
> -static inline void ssusb_wakeup_disable(struct ssusb_mtk *ssusb)
> +static inline void ssusb_wakeup_set(struct ssusb_mtk *ssusb, bool enable)
>  {}
>  
>  #endif
Forgot to make it change,

Acked-by: Chunfeng Yun <chunfeng@mediatek.com>

Thanks a lot


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[v2 PATCH 5/6] dt-bindings: usb: mtk-xhci: update USB wakeup properties

2018-01-03 Thread Chunfeng Yun
Add two arguments in "mediatek,syscon-wakeup" to support multi
wakeup glue layer between SSUSB and SPM, and use standard property
"wakeup-source" to replace the private "mediatek,wakeup-src"

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 .../devicetree/bindings/usb/mediatek,mtk-xhci.txt| 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
index 3059596..5842868 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
@@ -35,10 +35,14 @@ Required properties:
  - phys : a list of phandle + phy specifier pairs
 
 Optional properties:
- - mediatek,wakeup-src : 1: ip sleep wakeup mode; 2: line state wakeup
-   mode;
- - mediatek,syscon-wakeup : phandle to syscon used to access USB wakeup
-   control register, it depends on "mediatek,wakeup-src".
+ - wakeup-source : enable USB remote wakeup;
+ - mediatek,syscon-wakeup : phandle to syscon used to access the register
+   of the USB wakeup glue layer between xHCI and SPM; it depends on
+   "wakeup-source", and has two arguments:
+   - the first one : register base address of the glue layer in syscon;
+   - the second one : hardware version of the glue layer
+   - 1 : used by mt8173 etc
+   - 2 : used by mt2712 etc
  - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
bit1 for u3port1, ... etc;
  - vbus-supply : reference to the VBUS regulator;
@@ -64,8 +68,8 @@ usb30: usb@1127 {
vusb33-supply = <_vusb_reg>;
vbus-supply = <_p1_vbus>;
usb3-lpm-capable;
-   mediatek,syscon-wakeup = <>;
-   mediatek,wakeup-src = <1>;
+   mediatek,syscon-wakeup = < 0x400 1>;
+   wakeup-source;
 };
 
 2nd: dual-role mode with xHCI driver
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[v2 PATCH 4/6] usb: xhci-mtk: supports remote wakeup for mt2712 with two xHCI IPs

2018-01-03 Thread Chunfeng Yun
The old way of usb wakeup only supports platform with single xHCI IP,
such as mt8173, but mt2712 has two xHCI IPs, so rebuild its flow and
supports the new glue layer of usb wakeup on mt2712 which is different
from mt8173.
Due to there is a hardware bug with the LINE STATE wakeup mode on
mt8173 which causes wakeup failure by low speed devices, and also
because IP SLEEP mode can cover all functions of LINE STATE mode,
it is unused in fact, and will not support it later, so remove it at
the same time.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/host/xhci-mtk.c | 177 +++-
 drivers/usb/host/xhci-mtk.h |   6 +-
 2 files changed, 65 insertions(+), 118 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index b62a1d2..53187ff 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -57,26 +57,21 @@
 /* u2_phy_pll register */
 #define CTRL_U2_FORCE_PLL_STB  BIT(28)
 
-#define PERI_WK_CTRL0  0x400
-#define UWK_CTR0_0P_LS_PE  BIT(8)  /* posedge */
-#define UWK_CTR0_0P_LS_NE  BIT(7)  /* negedge for 0p linestate*/
-#define UWK_CTL1_1P_LS_C(x)(((x) & 0xf) << 1)
-#define UWK_CTL1_1P_LS_E   BIT(0)
-
-#define PERI_WK_CTRL1  0x404
-#define UWK_CTL1_IS_C(x)   (((x) & 0xf) << 26)
-#define UWK_CTL1_IS_E  BIT(25)
-#define UWK_CTL1_0P_LS_C(x)(((x) & 0xf) << 21)
-#define UWK_CTL1_0P_LS_E   BIT(20)
-#define UWK_CTL1_IDDIG_C(x)(((x) & 0xf) << 11)  /* cycle debounce */
-#define UWK_CTL1_IDDIG_E   BIT(10) /* enable debounce */
-#define UWK_CTL1_IDDIG_P   BIT(9)  /* polarity */
-#define UWK_CTL1_0P_LS_P   BIT(7)
-#define UWK_CTL1_IS_P  BIT(6)  /* polarity for ip sleep */
-
-enum ssusb_wakeup_src {
-   SSUSB_WK_IP_SLEEP = 1,
-   SSUSB_WK_LINE_STATE = 2,
+/* usb remote wakeup registers in syscon */
+/* mt8173 etc */
+#define PERI_WK_CTRL1  0x4
+#define WC1_IS_C(x)(((x) & 0xf) << 26)  /* cycle debounce */
+#define WC1_IS_EN  BIT(25)
+#define WC1_IS_P   BIT(6)  /* polarity for ip sleep */
+
+/* mt2712 etc */
+#define PERI_SSUSB_SPM_CTRL0x0
+#define SSC_IP_SLEEP_ENBIT(4)
+#define SSC_SPM_INT_EN BIT(1)
+
+enum ssusb_uwk_vers {
+   SSUSB_UWK_V1 = 1,
+   SSUSB_UWK_V2,
 };
 
 static int xhci_mtk_host_enable(struct xhci_hcd_mtk *mtk)
@@ -296,112 +291,58 @@ static void xhci_mtk_clks_disable(struct xhci_hcd_mtk 
*mtk)
 }
 
 /* only clocks can be turn off for ip-sleep wakeup mode */
-static void usb_wakeup_ip_sleep_en(struct xhci_hcd_mtk *mtk)
+static void usb_wakeup_ip_sleep_set(struct xhci_hcd_mtk *mtk, bool enable)
 {
-   u32 tmp;
-   struct regmap *pericfg = mtk->pericfg;
-
-   regmap_read(pericfg, PERI_WK_CTRL1, );
-   tmp &= ~UWK_CTL1_IS_P;
-   tmp &= ~(UWK_CTL1_IS_C(0xf));
-   tmp |= UWK_CTL1_IS_C(0x8);
-   regmap_write(pericfg, PERI_WK_CTRL1, tmp);
-   regmap_write(pericfg, PERI_WK_CTRL1, tmp | UWK_CTL1_IS_E);
-
-   regmap_read(pericfg, PERI_WK_CTRL1, );
-   dev_dbg(mtk->dev, "%s(): WK_CTRL1[P6,E25,C26:29]=%#x\n",
-   __func__, tmp);
+   u32 reg, msk, val;
+
+   switch (mtk->uwk_vers) {
+   case SSUSB_UWK_V1:
+   reg = mtk->uwk_reg_base + PERI_WK_CTRL1;
+   msk = WC1_IS_EN | WC1_IS_C(0xf) | WC1_IS_P;
+   val = enable ? (WC1_IS_EN | WC1_IS_C(0x8)) : 0;
+   break;
+   case SSUSB_UWK_V2:
+   reg = mtk->uwk_reg_base + PERI_SSUSB_SPM_CTRL;
+   msk = SSC_IP_SLEEP_EN | SSC_SPM_INT_EN;
+   val = enable ? msk : 0;
+   break;
+   default:
+   return;
+   };
+   regmap_update_bits(mtk->uwk, reg, msk, val);
 }
 
-static void usb_wakeup_ip_sleep_dis(struct xhci_hcd_mtk *mtk)
+static int usb_wakeup_of_property_parse(struct xhci_hcd_mtk *mtk,
+   struct device_node *dn)
 {
-   u32 tmp;
+   struct of_phandle_args args;
+   int ret;
 
-   regmap_read(mtk->pericfg, PERI_WK_CTRL1, );
-   tmp &= ~UWK_CTL1_IS_E;
-   regmap_write(mtk->pericfg, PERI_WK_CTRL1, tmp);
-}
+   /* Wakeup function is optional */
+   mtk->uwk_en = of_property_read_bool(dn, "wakeup-source");
+   if (!mtk->uwk_en)
+   return 0;
 
-/*
-* for line-state wakeup mode, phy's power should not power-down
-* and only support cable plug in/out
-*/
-static void usb_wakeup_line_state_en(struct xhci_hcd_mtk *mtk)
-{
-   u32 tmp;
-   struct regmap *pericfg = mtk->pericfg;
-
-   /* line-state of u2-port0 */
-   regmap_read(pericfg, PERI_WK_CTRL1, );
-   tmp &= ~UWK_CTL1_0P_LS_P;
-   tmp &= ~(UWK_CTL1_0P_LS_C(0xf));
-   tmp |= UWK_CTL1_0P_LS_C(0x8);
-   regmap_write(pericfg, PERI_WK_CTRL1, tmp);
-   regmap_read(pericfg, PERI_WK_CTRL1, );

[v2 PATCH 1/6] usb: mtu3: fix error code for getting extcon device

2018-01-03 Thread Chunfeng Yun
When failing to get extcon device, extcon_get_edev_by_phandle()
may return different error codes, but not only -EPROBE_DEFER,
so can't always return -EPROBE_DEFER, and fix it.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3_plat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
index 3650fd1..5b2110b 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -308,7 +308,7 @@ static int get_ssusb_rscs(struct platform_device *pdev, 
struct ssusb_mtk *ssusb)
otg_sx->edev = extcon_get_edev_by_phandle(ssusb->dev, 0);
if (IS_ERR(otg_sx->edev)) {
dev_err(ssusb->dev, "couldn't get extcon device\n");
-   return -EPROBE_DEFER;
+   return PTR_ERR(otg_sx->edev);
}
}
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[v2 PATCH 2/6] usb: mtu3: supports remote wakeup for mt2712 with two SSUSB IPs

2018-01-03 Thread Chunfeng Yun
The old way of usb wakeup only supports platform with single SSUSB IP,
such as mt8173, but mt2712 has two SSUSB IPs, so rebuild its flow and
also supports the new glue layer of usb wakeup on mt2712 which is
different from mt8173.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3.h  |  11 +++--
 drivers/usb/mtu3/mtu3_dr.h   |   3 +-
 drivers/usb/mtu3/mtu3_host.c | 115 +--
 drivers/usb/mtu3/mtu3_plat.c |   8 +--
 4 files changed, 70 insertions(+), 67 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index 3c888d9..2cd00a2 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -229,7 +229,10 @@ 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
- * @wakeup_en: it's true when supports remote wakeup in host mode
+ * @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
+ * @uwk_vers: the version of the wakeup glue layer
  */
 struct ssusb_mtk {
struct device *dev;
@@ -253,8 +256,10 @@ struct ssusb_mtk {
int u3p_dis_msk;
struct dentry *dbgfs_root;
/* usb wakeup for host mode */
-   bool wakeup_en;
-   struct regmap *pericfg;
+   bool uwk_en;
+   struct regmap *uwk;
+   u32 uwk_reg_base;
+   u32 uwk_vers;
 };
 
 /**
diff --git a/drivers/usb/mtu3/mtu3_dr.h b/drivers/usb/mtu3/mtu3_dr.h
index c179192..ae1598d 100644
--- a/drivers/usb/mtu3/mtu3_dr.h
+++ b/drivers/usb/mtu3/mtu3_dr.h
@@ -18,8 +18,7 @@ int ssusb_wakeup_of_property_parse(struct ssusb_mtk *ssusb,
struct device_node *dn);
 int ssusb_host_enable(struct ssusb_mtk *ssusb);
 int ssusb_host_disable(struct ssusb_mtk *ssusb, bool suspend);
-int ssusb_wakeup_enable(struct ssusb_mtk *ssusb);
-void ssusb_wakeup_disable(struct ssusb_mtk *ssusb);
+void ssusb_wakeup_set(struct ssusb_mtk *ssusb, bool enable);
 
 #else
 
diff --git a/drivers/usb/mtu3/mtu3_host.c b/drivers/usb/mtu3/mtu3_host.c
index d237d7e..259beef 100644
--- a/drivers/usb/mtu3/mtu3_host.c
+++ b/drivers/usb/mtu3/mtu3_host.c
@@ -18,66 +18,77 @@
 #include "mtu3.h"
 #include "mtu3_dr.h"
 
-#define PERI_WK_CTRL1  0x404
-#define UWK_CTL1_IS_C(x)   (((x) & 0xf) << 26)
-#define UWK_CTL1_IS_E  BIT(25)
-#define UWK_CTL1_IDDIG_C(x)(((x) & 0xf) << 11)  /* cycle debounce */
-#define UWK_CTL1_IDDIG_E   BIT(10) /* enable debounce */
-#define UWK_CTL1_IDDIG_P   BIT(9)  /* polarity */
-#define UWK_CTL1_IS_P  BIT(6)  /* polarity for ip sleep */
+/* mt8173 etc */
+#define PERI_WK_CTRL1  0x4
+#define WC1_IS_C(x)(((x) & 0xf) << 26)  /* cycle debounce */
+#define WC1_IS_EN  BIT(25)
+#define WC1_IS_P   BIT(6)  /* polarity for ip sleep */
+
+/* mt2712 etc */
+#define PERI_SSUSB_SPM_CTRL0x0
+#define SSC_IP_SLEEP_ENBIT(4)
+#define SSC_SPM_INT_EN BIT(1)
+
+enum ssusb_uwk_vers {
+   SSUSB_UWK_V1 = 1,
+   SSUSB_UWK_V2,
+};
 
 /*
  * ip-sleep wakeup mode:
  * all clocks can be turn off, but power domain should be kept on
  */
-static void ssusb_wakeup_ip_sleep_en(struct ssusb_mtk *ssusb)
+static void ssusb_wakeup_ip_sleep_set(struct ssusb_mtk *ssusb, bool enable)
 {
-   u32 tmp;
-   struct regmap *pericfg = ssusb->pericfg;
-
-   regmap_read(pericfg, PERI_WK_CTRL1, );
-   tmp &= ~UWK_CTL1_IS_P;
-   tmp &= ~(UWK_CTL1_IS_C(0xf));
-   tmp |= UWK_CTL1_IS_C(0x8);
-   regmap_write(pericfg, PERI_WK_CTRL1, tmp);
-   regmap_write(pericfg, PERI_WK_CTRL1, tmp | UWK_CTL1_IS_E);
-
-   regmap_read(pericfg, PERI_WK_CTRL1, );
-   dev_dbg(ssusb->dev, "%s(): WK_CTRL1[P6,E25,C26:29]=%#x\n",
-   __func__, tmp);
-}
-
-static void ssusb_wakeup_ip_sleep_dis(struct ssusb_mtk *ssusb)
-{
-   u32 tmp;
-
-   regmap_read(ssusb->pericfg, PERI_WK_CTRL1, );
-   tmp &= ~UWK_CTL1_IS_E;
-   regmap_write(ssusb->pericfg, PERI_WK_CTRL1, tmp);
+   u32 reg, msk, val;
+
+   switch (ssusb->uwk_vers) {
+   case SSUSB_UWK_V1:
+   reg = ssusb->uwk_reg_base + PERI_WK_CTRL1;
+   msk = WC1_IS_EN | WC1_IS_C(0xf) | WC1_IS_P;
+   val = enable ? (WC1_IS_EN | WC1_IS_C(0x8)) : 0;
+   break;
+   case SSUSB_UWK_V2:
+   reg = ssusb->uwk_reg_base + PERI_SSUSB_SPM_CTRL;
+   msk = SSC_IP_SLEEP_EN | SSC_SPM_INT_EN;
+   val = enable ? msk : 0;
+   break;
+   default:
+   return;
+   };
+   regmap_update_bits(ssusb->uwk, reg, msk, val);
 }
 
 int ssusb_wakeup_of_property_pa

[v2 PATCH 3/6] dt-bindings: usb: mtu3: update USB wakeup properties

2018-01-03 Thread Chunfeng Yun
Add two arguments in "mediatek,syscon-wakeup" to support multi
wakeup glue layer between SSUSB and SPM, and use standard property
"wakeup-source" to replace the private "mediatek,enable-wakeup"

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 Documentation/devicetree/bindings/usb/mediatek,mtu3.txt | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
index b2271d8..d589a1e 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
@@ -42,9 +42,14 @@ Optional properties:
  - enable-manual-drd : supports manual dual-role switch via debugfs; usually
used when receptacle is TYPE-A and also wants to support dual-role
mode.
- - mediatek,enable-wakeup : supports ip sleep wakeup used by host mode
- - mediatek,syscon-wakeup : phandle to syscon used to access USB wakeup
-   control register, it depends on "mediatek,enable-wakeup".
+ - wakeup-source: enable USB remote wakeup of host mode.
+ - mediatek,syscon-wakeup : phandle to syscon used to access the register
+   of the USB wakeup glue layer between SSUSB and SPM; it depends on
+   "wakeup-source", and has two arguments:
+   - the first one : register base address of the glue layer in syscon;
+   - the second one : hardware version of the glue layer
+   - 1 : used by mt8173 etc
+   - 2 : used by mt2712 etc
  - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
bit1 for u3port1, ... etc;
 
@@ -71,8 +76,8 @@ ssusb: usb@11271000 {
vbus-supply = <_p0_vbus>;
extcon = <_usb>;
dr_mode = "otg";
-   mediatek,enable-wakeup;
-   mediatek,syscon-wakeup = <>;
+   wakeup-source;
+   mediatek,syscon-wakeup = < 0x400 1>;
#address-cells = <2>;
#size-cells = <2>;
ranges;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[v2 PATCH 6/6] arm64: dts: mt8173: update properties about USB wakeup

2018-01-03 Thread Chunfeng Yun
Use new binding about USB wakeup which now supports multi USB
wakeup glue layer between SSUSB and SPM.
Meanwhile remove dummy clocks of USB wakeup.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 arch/arm64/boot/dts/mediatek/mt8173-evb.dts |  2 +-
 arch/arm64/boot/dts/mediatek/mt8173.dtsi| 12 +++-
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173-evb.dts 
b/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
index 1c3634f..0acba1f 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
+++ b/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
@@ -505,7 +505,7 @@
vbus-supply = <_p0_vbus>;
extcon = <_usb>;
dr_mode = "otg";
-   mediatek,enable-wakeup;
+   wakeup-source;
pinctrl-names = "default", "id_float", "id_ground";
pinctrl-0 = <_id_pins_float>;
pinctrl-1 = <_id_pins_float>;
diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 26396ef..9263d9f 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -731,15 +731,9 @@
   < PHY_TYPE_USB3>,
   < PHY_TYPE_USB2>;
power-domains = < MT8173_POWER_DOMAIN_USB>;
-   clocks = < CLK_TOP_USB30_SEL>,
-<>,
-< CLK_PERI_USB0>,
-< CLK_PERI_USB1>;
-   clock-names = "sys_ck",
- "ref_ck",
- "wakeup_deb_p0",
- "wakeup_deb_p1";
-   mediatek,syscon-wakeup = <>;
+   clocks = < CLK_TOP_USB30_SEL>, <>;
+   clock-names = "sys_ck", "ref_ck";
+   mediatek,syscon-wakeup = < 0x400 1>;
#address-cells = <2>;
#size-cells = <2>;
ranges;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3] phy: phy-mtk-tphy: use auto instead of force to bypass utmi signals

2018-01-01 Thread Chunfeng Yun
On Thu, 2017-12-28 at 16:44 +0530, Kishon Vijay Abraham I wrote:
> 
> On Thursday 07 December 2017 05:23 PM, Chunfeng Yun wrote:
> > When system is running, if usb2 phy is forced to bypass utmi signals,
> > all PLL will be turned off, and it can't detect device connection
> > anymore, so replace force mode with auto mode which can bypass utmi
> > signals automatically if no device attached for normal flow.
> > But keep the force mode to fix RX sensitivity degradation issue.
> > 
> > Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
> 
> merged this series.
Thanks a lot
> 
> Thanks
> Kishon
> > ---
> >  drivers/phy/mediatek/phy-mtk-tphy.c | 19 +++
> >  1 file changed, 7 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c 
> > b/drivers/phy/mediatek/phy-mtk-tphy.c
> > index fb8aba4..5d9d7f3 100644
> > --- a/drivers/phy/mediatek/phy-mtk-tphy.c
> > +++ b/drivers/phy/mediatek/phy-mtk-tphy.c
> > @@ -440,9 +440,9 @@ static void u2_phy_instance_init(struct mtk_tphy *tphy,
> > u32 index = instance->index;
> > u32 tmp;
> >  
> > -   /* switch to USB function. (system register, force ip into usb mode) */
> > +   /* switch to USB function, and enable usb pll */
> > tmp = readl(com + U3P_U2PHYDTM0);
> > -   tmp &= ~P2C_FORCE_UART_EN;
> > +   tmp &= ~(P2C_FORCE_UART_EN | P2C_FORCE_SUSPENDM);
> > tmp |= P2C_RG_XCVRSEL_VAL(1) | P2C_RG_DATAIN_VAL(0);
> > writel(tmp, com + U3P_U2PHYDTM0);
> >  
> > @@ -502,10 +502,8 @@ static void u2_phy_instance_power_on(struct mtk_tphy 
> > *tphy,
> > u32 index = instance->index;
> > u32 tmp;
> >  
> > -   /* (force_suspendm=0) (let suspendm=1, enable usb 480MHz pll) */
> > tmp = readl(com + U3P_U2PHYDTM0);
> > -   tmp &= ~(P2C_FORCE_SUSPENDM | P2C_RG_XCVRSEL);
> > -   tmp &= ~(P2C_RG_DATAIN | P2C_DTM0_PART_MASK);
> > +   tmp &= ~(P2C_RG_XCVRSEL | P2C_RG_DATAIN | P2C_DTM0_PART_MASK);
> > writel(tmp, com + U3P_U2PHYDTM0);
> >  
> > /* OTG Enable */
> > @@ -540,7 +538,6 @@ static void u2_phy_instance_power_off(struct mtk_tphy 
> > *tphy,
> >  
> > tmp = readl(com + U3P_U2PHYDTM0);
> > tmp &= ~(P2C_RG_XCVRSEL | P2C_RG_DATAIN);
> > -   tmp |= P2C_FORCE_SUSPENDM;
> > writel(tmp, com + U3P_U2PHYDTM0);
> >  
> > /* OTG Disable */
> > @@ -548,18 +545,16 @@ static void u2_phy_instance_power_off(struct mtk_tphy 
> > *tphy,
> > tmp &= ~PA6_RG_U2_OTG_VBUSCMP_EN;
> > writel(tmp, com + U3P_USBPHYACR6);
> >  
> > -   /* let suspendm=0, set utmi into analog power down */
> > -   tmp = readl(com + U3P_U2PHYDTM0);
> > -   tmp &= ~P2C_RG_SUSPENDM;
> > -   writel(tmp, com + U3P_U2PHYDTM0);
> > -   udelay(1);
> > -
> > tmp = readl(com + U3P_U2PHYDTM1);
> > tmp &= ~(P2C_RG_VBUSVALID | P2C_RG_AVALID);
> > tmp |= P2C_RG_SESSEND;
> > writel(tmp, com + U3P_U2PHYDTM1);
> >  
> > if (tphy->pdata->avoid_rx_sen_degradation && index) {
> > +   tmp = readl(com + U3P_U2PHYDTM0);
> > +   tmp &= ~(P2C_RG_SUSPENDM | P2C_FORCE_SUSPENDM);
> > +   writel(tmp, com + U3P_U2PHYDTM0);
> > +
> > tmp = readl(com + U3D_U2PHYDCR0);
> > tmp &= ~P2C_RG_SIF_U2PLL_FORCE_ON;
> > writel(tmp, com + U3D_U2PHYDCR0);
> > 


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/7] soc: mediatek: Add USB wakeup driver

2017-12-20 Thread Chunfeng Yun
On Fri, 2017-12-15 at 14:55 -0600, Rob Herring wrote:
> On Sat, Dec 09, 2017 at 04:45:30PM +0800, Chunfeng Yun wrote:
> > This driver is used to support usb wakeup which is controlled by
> > the glue layer between SSUSB and SPM. Usually the glue layer is put
> > into a system controller, such as pericfg module, which is
> > represented by a syscon node in DTS.
> > Due to the glue layer may vary on different SoCs, it's useful to
> > extract a separated driver to simplify usb controller drivers.
> > 
> > Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
> > ---
> >  drivers/soc/mediatek/Kconfig  |   8 +
> >  drivers/soc/mediatek/Makefile |   1 +
> >  drivers/soc/mediatek/mtk-usb-wakeup.c | 519 
> > ++
> >  include/dt-bindings/soc/mediatek,usb-wakeup.h |  15 +
> 
> This belongs in the binding patch and that should come first.
> 
> >  include/linux/soc/mediatek/usb-wakeup.h   |  88 +
> >  5 files changed, 631 insertions(+)
> >  create mode 100644 drivers/soc/mediatek/mtk-usb-wakeup.c
> >  create mode 100644 include/dt-bindings/soc/mediatek,usb-wakeup.h
> >  create mode 100644 include/linux/soc/mediatek/usb-wakeup.h
> 
> > +++ b/drivers/soc/mediatek/mtk-usb-wakeup.c
> > @@ -0,0 +1,519 @@
> > +/*
> > + * Copyright (c) 2017 MediaTek Inc.
> > + * Author: Chunfeng Yun <chunfeng@mediatek.com>
> > + *
> > + * SPDX-License-Identifier: GPL-2.0
> 
> This should be the first line of the file and use a // style comment.
> 
> [...]
> 
> > diff --git a/include/dt-bindings/soc/mediatek,usb-wakeup.h 
> > b/include/dt-bindings/soc/mediatek,usb-wakeup.h
> > new file mode 100644
> > index 000..2461795
> > --- /dev/null
> > +++ b/include/dt-bindings/soc/mediatek,usb-wakeup.h
> > @@ -0,0 +1,15 @@
> > +/*
> > + * Copyright (c) 2017 MediaTek Inc.
> > + * Author: Chunfeng Yun <chunfeng@mediatek.com>
> > + *
> > + * SPDX-License-Identifier: GPL-2.0
> 
> ditto. Except headers use /* */ comments...
modify it next version. Thanks


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/7] Add USB remote wakeup driver

2017-12-20 Thread Chunfeng Yun
On Fri, 2017-12-15 at 14:55 -0600, Rob Herring wrote:
> On Sat, Dec 09, 2017 at 04:45:29PM +0800, Chunfeng Yun wrote:
> > These patches introduce the SSUSB and SPM glue layer driver which is
> > used to support usb remote wakeup. Usually the glue layer is put into
> > a system controller, such as PERICFG module.
> > The old way to support usb wakeup is put into SSUSB controller drivers,
> > including xhci-mtk driver and mtu3 driver, but there are some problems:
> > 1. can't disdinguish the relation between glue layer and SSUSB IP
> >when SoCs supports multi SSUSB IPs;
> > 2. duplicated code for wakeup are put into both xhci-mtk and mtu3
> >drivers;
> > 3. the glue layer may vary on different SoCs with SSUSB IP, and will
> >make SSUSB controller drivers complicated;
> > In order to resolve these problems, it's useful to make the glue layer
> > transparent by extracting a seperated driver, meanwhile to reduce the
> > duplicated code and simplify SSUSB controller drivers.
> 
> Both the driver and binding look overly complicated to me when it looks 
> like you just have 2 versions of enable/disable functions which modify 
> a single register. The complexity may be justified if this was a common 
> binding and driver, but it is not.
> 
> You already have a phandle to the system controller. Can't you add cells 
> to it to handle any differences between instances? That and SoC specific 
> compatible strings should be enough to handle differences.
Yes, adding cells will also work well, I'll try it, thanks a lot
> 
> Rob


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/7] usb: mtu3: use APIs of mtu_wakeup to support remote wakeup

2017-12-09 Thread Chunfeng Yun
On some platforms, there are two SSUSB IPs, but the old way of
usb wakeup doesn't support it, so use the new APIs of mtu_wakeup
to support it.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/mtu3/mtu3.h  |  2 ++
 drivers/usb/mtu3/mtu3_host.c | 39 +++
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index 3c888d9..9f3eb79 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -255,6 +255,8 @@ struct ssusb_mtk {
/* usb wakeup for host mode */
bool wakeup_en;
struct regmap *pericfg;
+   struct mtu_wakeup *uwk;
+   bool new_wakeup;
 };
 
 /**
diff --git a/drivers/usb/mtu3/mtu3_host.c b/drivers/usb/mtu3/mtu3_host.c
index 7e948c0..f769b65 100644
--- a/drivers/usb/mtu3/mtu3_host.c
+++ b/drivers/usb/mtu3/mtu3_host.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "mtu3.h"
 #include "mtu3_dr.h"
@@ -56,24 +57,26 @@ static void ssusb_wakeup_ip_sleep_dis(struct ssusb_mtk 
*ssusb)
 int ssusb_wakeup_of_property_parse(struct ssusb_mtk *ssusb,
struct device_node *dn)
 {
-   struct device *dev = ssusb->dev;
+   /* try the new way first */
+   ssusb->new_wakeup = of_property_read_bool(dn, "wakeup-source");
+   if (ssusb->new_wakeup) {
+   ssusb->uwk = devm_of_uwk_get_by_index(ssusb->dev, dn, 0);
+   if (IS_ERR(ssusb->uwk))
+   dev_err(ssusb->dev, "fail to get mtu_wakeup\n");
+
+   return PTR_ERR_OR_ZERO(ssusb->uwk);
+   }
 
-   /*
-* Wakeup function is optional, so it is not an error if this property
-* does not exist, and in such case, no need to get relative
-* properties anymore.
-*/
+   /* Wakeup function is optional. (deprecated, use the new way instead) */
ssusb->wakeup_en = of_property_read_bool(dn, "mediatek,enable-wakeup");
-   if (!ssusb->wakeup_en)
-   return 0;
-
-   ssusb->pericfg = syscon_regmap_lookup_by_phandle(dn,
+   if (ssusb->wakeup_en) {
+   ssusb->pericfg = syscon_regmap_lookup_by_phandle(dn,
"mediatek,syscon-wakeup");
-   if (IS_ERR(ssusb->pericfg)) {
-   dev_err(dev, "fail to get pericfg regs\n");
-   return PTR_ERR(ssusb->pericfg);
+   if (IS_ERR(ssusb->pericfg)) {
+   dev_err(ssusb->dev, "fail to get pericfg regs\n");
+   return PTR_ERR(ssusb->pericfg);
+   }
}
-
return 0;
 }
 
@@ -235,7 +238,9 @@ void ssusb_host_exit(struct ssusb_mtk *ssusb)
 
 int ssusb_wakeup_enable(struct ssusb_mtk *ssusb)
 {
-   if (ssusb->wakeup_en)
+   if (ssusb->new_wakeup)
+   mtu_wakeup_enable(ssusb->uwk);
+   else if (ssusb->wakeup_en)
ssusb_wakeup_ip_sleep_en(ssusb);
 
return 0;
@@ -243,6 +248,8 @@ int ssusb_wakeup_enable(struct ssusb_mtk *ssusb)
 
 void ssusb_wakeup_disable(struct ssusb_mtk *ssusb)
 {
-   if (ssusb->wakeup_en)
+   if (ssusb->new_wakeup)
+   mtu_wakeup_disable(ssusb->uwk);
+   else if (ssusb->wakeup_en)
ssusb_wakeup_ip_sleep_dis(ssusb);
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/7] usb: xhci-mtk: use APIs of mtu_wakeup to support remote wakeup

2017-12-09 Thread Chunfeng Yun
On some platforms, there are two xHCI IPs, but the old way of
usb wakeup doesn't support it, so use the new APIs of mtu_wakeup
to support it.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 drivers/usb/host/xhci-mtk.c | 39 +++
 drivers/usb/host/xhci-mtk.h |  2 ++
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index b62a1d2..3176a10 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "xhci.h"
 #include "xhci-mtk.h"
@@ -366,7 +367,9 @@ static void usb_wakeup_line_state_dis(struct xhci_hcd_mtk 
*mtk)
 
 static void usb_wakeup_enable(struct xhci_hcd_mtk *mtk)
 {
-   if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP)
+   if (mtk->wakeup)
+   mtu_wakeup_enable(mtk->uwk);
+   else if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP)
usb_wakeup_ip_sleep_en(mtk);
else if (mtk->wakeup_src == SSUSB_WK_LINE_STATE)
usb_wakeup_line_state_en(mtk);
@@ -374,7 +377,9 @@ static void usb_wakeup_enable(struct xhci_hcd_mtk *mtk)
 
 static void usb_wakeup_disable(struct xhci_hcd_mtk *mtk)
 {
-   if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP)
+   if (mtk->wakeup)
+   mtu_wakeup_disable(mtk->uwk);
+   else if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP)
usb_wakeup_ip_sleep_dis(mtk);
else if (mtk->wakeup_src == SSUSB_WK_LINE_STATE)
usb_wakeup_line_state_dis(mtk);
@@ -383,24 +388,26 @@ static void usb_wakeup_disable(struct xhci_hcd_mtk *mtk)
 static int usb_wakeup_of_property_parse(struct xhci_hcd_mtk *mtk,
struct device_node *dn)
 {
-   struct device *dev = mtk->dev;
+   /* try the new way first */
+   mtk->wakeup = of_property_read_bool(dn, "wakeup-source");
+   if (mtk->wakeup) {
+   mtk->uwk = devm_of_uwk_get_by_index(mtk->dev, dn, 0);
+   if (IS_ERR(mtk->uwk))
+   dev_err(mtk->dev, "fail to get uwk\n");
+
+   return PTR_ERR_OR_ZERO(mtk->uwk);
+   }
 
-   /*
-   * wakeup function is optional, so it is not an error if this property
-   * does not exist, and in such case, no need to get relative
-   * properties anymore.
-   */
+   /* wakeup function is optional (deprecated, use the new way instead) */
of_property_read_u32(dn, "mediatek,wakeup-src", >wakeup_src);
-   if (!mtk->wakeup_src)
-   return 0;
-
-   mtk->pericfg = syscon_regmap_lookup_by_phandle(dn,
+   if (mtk->wakeup_src) {
+   mtk->pericfg = syscon_regmap_lookup_by_phandle(dn,
"mediatek,syscon-wakeup");
-   if (IS_ERR(mtk->pericfg)) {
-   dev_err(dev, "fail to get pericfg regs\n");
-   return PTR_ERR(mtk->pericfg);
+   if (IS_ERR(mtk->pericfg)) {
+   dev_err(mtk->dev, "fail to get pericfg regs\n");
+   return PTR_ERR(mtk->pericfg);
+   }
}
-
return 0;
 }
 
diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h
index 6b74ce5..95bd6ca 100644
--- a/drivers/usb/host/xhci-mtk.h
+++ b/drivers/usb/host/xhci-mtk.h
@@ -124,6 +124,8 @@ struct xhci_hcd_mtk {
int num_phys;
int wakeup_src;
bool lpm_support;
+   struct mtu_wakeup *uwk;
+   bool wakeup;
 };
 
 static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/7] dt-bindings: soc: mediatek: add bindings document for USB wakeup

2017-12-09 Thread Chunfeng Yun
This adds bindings document for the SSUSB-SPM glue layer driver found
in MediaTek SoCs which is used to support usb remote wakeup.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 .../bindings/soc/mediatek/usb-wakeup.txt   | 77 ++
 1 file changed, 77 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt

diff --git a/Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt 
b/Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt
new file mode 100644
index 000..313d927
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt
@@ -0,0 +1,77 @@
+MediaTek USB Wakeup binding
+-
+
+The SSUSB-SPM glue layer is used to control some signals of USB
+wakeup, such as IP-SLEEP, LINE-STATE, IDDIG etc, which are mutually
+exclusive.
+
+Required properties (controller (parent) node):
+- compatible: Should be one of:
+   - "mediatek,-uwk","mediatek,usb-wk-v1"
+   soc-model is the name of SoC, supports one of:
+   - mt8173, mt8176
+   - "mediatek,-uwk","mediatek,usb-wk-v2"
+   soc-model is the name of SoC, supports one of:
+   - mt2712
+
+- mediatek,wkc: must contain a syscon phandle, such as pericfg controller
+- #address-cells : should be '1'
+- #size-cells : should be '1'
+
+Required nodes: a sub-node is required for each glue layer provided for
+   each SSUSB IP. Address range information including the usual 'reg'
+   property is used inside these nodes to describe the controller's
+   topology.
+
+Required properties (glue layer (child) node):
+- reg: address and length of the register set within the syscon which is
+   assigned to @mediatek,wkc.
+- #mediatek,uwk-cells: should be 1 (see the second example), cell after
+   glue layer phandle is wakeup type from:
+   - MTU_WK_IP_SLEEP
+   - MTU_WK_LINE_STATE
+   The wakeup types defined in
+   - include/dt-bindings/soc/mediatek,usb-wakeup.h
+
+
+Example:
+
+usb_wakeup: uwk@0 {
+   compatible = "mediatek,mt2712-uwk","mediatek,usb-wk-v2";
+   mediatek,wkc = <>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   status = "okay";
+
+   usb_wk0: uwk@510 {
+   reg = <0x510 0x4>;
+   #mediatek,uwk-cells = <1>;
+   status = "okay";
+   };
+
+   usb_wk1: uwk@514 {
+   reg = <0x514 0x4>;
+   #mediatek,uwk-cells = <1>;
+   status = "okay";
+   };
+};
+
+
+Specifying wakeup control of devices
+-
+
+Device nodes should specify the configuration required in their
+"mediatek,uwks" property, containing a phandle to the glue layer
+node and a wakeup type, because each USB controller has just one
+glue layer for wakeup, so only one phandle is supported;
+
+Example:
+
+#include 
+
+usb_host1: xhci@112c {
+   ...
+   mediatek,uwks = <_wk2 MTU_WK_IP_SLEEP>;
+   ...
+};
+
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 6/7] dt-bindings: usb: mtu3: add USB wakeup properties

2017-12-09 Thread Chunfeng Yun
Modify the properties of usb wakeup, and use the new way of mtu_wakeup
which is extracted from SSUSB controller dirver as a new driver.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 Documentation/devicetree/bindings/usb/mediatek,mtu3.txt | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
index b2271d8..2ed546d 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
@@ -42,9 +42,17 @@ Optional properties:
  - enable-manual-drd : supports manual dual-role switch via debugfs; usually
used when receptacle is TYPE-A and also wants to support dual-role
mode.
- - mediatek,enable-wakeup : supports ip sleep wakeup used by host mode
- - mediatek,syscon-wakeup : phandle to syscon used to access USB wakeup
-   control register, it depends on "mediatek,enable-wakeup".
+ - mediatek,uwks : a phandle to USB-Wakeup node to control the type of wakeup,
+   it's used to replace the old way which is realized by the property of
+   "mediatek,wakeup-wakeup" and "mediatek,syscon-wakeup",
+   see: Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt
+ - wakeup-source : Decides if the new way of USB wakeup is supported or
+   not, it depends on "mediatek,uwks" property.
+ - mediatek,enable-wakeup : (deprecated) supports ip sleep wakeup used by
+   host mode, only supports mt8173 platform, use the property of
+   "mediatek,uwks" instead on other SoCs.
+ - mediatek,syscon-wakeup : (deprecated) phandle to syscon used to access
+   USB wakeup control register, it depends on "mediatek,enable-wakeup".
  - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
bit1 for u3port1, ... etc;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/7] dt-bindings: usb: mtk-xhci: add USB wakeup properties

2017-12-09 Thread Chunfeng Yun
Modify the properties of usb wakeup, and use the new way of mtu_wakeup
which is extracted from SSUSB controller dirver as a new one.

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 .../devicetree/bindings/usb/mediatek,mtk-xhci.txt | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
index 3059596..88984d8 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
@@ -35,10 +35,17 @@ Required properties:
  - phys : a list of phandle + phy specifier pairs
 
 Optional properties:
- - mediatek,wakeup-src : 1: ip sleep wakeup mode; 2: line state wakeup
-   mode;
- - mediatek,syscon-wakeup : phandle to syscon used to access USB wakeup
-   control register, it depends on "mediatek,wakeup-src".
+ - mediatek,uwks : a phandle to USB-Wakeup node to control the type of
+   wakeup, it's used to replace the old way which is realized by the
+   property of "mediatek,wakeup-src" and "mediatek,syscon-wakeup",
+   see: Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt
+ - wakeup-source : Decides if the new way of USB wakeup is supported or
+   not, it depends on "mediatek,uwks" property.
+ - mediatek,wakeup-src : (deprecated) 1: ip sleep wakeup mode; 2: line
+   state wakeup mode; only supports mt8173 platform, use the property
+   of "mediatek,uwks" instead on other SoCs.
+ - mediatek,syscon-wakeup : (deprecated) phandle to syscon used to access
+   USB wakeup control register, depends on "mediatek,wakeup-src".
  - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
bit1 for u3port1, ... etc;
  - vbus-supply : reference to the VBUS regulator;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 7/7] arm64: dts: mt8173: add uwk node and remove unused usb property

2017-12-09 Thread Chunfeng Yun
Add uwk node for new way of usb remote wakeup instead of old one,
and modify some usb properties according binding documents
of mediatek,mtu3.txt and mediatek,mtk-xhci.txt

Signed-off-by: Chunfeng Yun <chunfeng@mediatek.com>
---
 arch/arm64/boot/dts/mediatek/mt8173-evb.dts | 28 ++--
 arch/arm64/boot/dts/mediatek/mt8173.dtsi| 16 +---
 2 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173-evb.dts 
b/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
index 1c3634f..08a323b 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
+++ b/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
@@ -14,6 +14,7 @@
 
 /dts-v1/;
 #include 
+#include 
 #include "mt8173.dtsi"
 
 / {
@@ -68,6 +69,20 @@
gpio = < 9 GPIO_ACTIVE_HIGH>;
enable-active-high;
};
+
+   usb_wakeup: uwk@0 {
+   compatible = "mediatek,mt8173-uwk","mediatek,usb-wk-v1";
+   mediatek,wkc = <>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   status = "okay";
+
+   usb_wk0: uwk@400 {
+   reg = <0x400 0x8>;
+   #mediatek,uwk-cells = <1>;
+   status = "okay";
+   };
+   };
 };
 
  {
@@ -268,12 +283,6 @@
};
};
 
-   usb_id_pins_ground: usb_iddig_pull_down {
-   pins_iddig {
-   pinmux = ;
-   bias-pull-down;
-   };
-   };
 };
 
  {
@@ -501,15 +510,14 @@
 };
 
  {
+   mediatek,uwks = <_wk0 MTU_WK_IP_SLEEP>;
vusb33-supply = <_vusb_reg>;
vbus-supply = <_p0_vbus>;
extcon = <_usb>;
dr_mode = "otg";
-   mediatek,enable-wakeup;
-   pinctrl-names = "default", "id_float", "id_ground";
+   wakeup-source;
+   pinctrl-names = "default";
pinctrl-0 = <_id_pins_float>;
-   pinctrl-1 = <_id_pins_float>;
-   pinctrl-2 = <_id_pins_ground>;
status = "okay";
 };
 
diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 26396ef..818ead7 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -722,7 +722,7 @@
};
 
ssusb: usb@11271000 {
-   compatible = "mediatek,mt8173-mtu3";
+   compatible = "mediatek,mt8173-mtu3", "mediatek,mtu3";
reg = <0 0x11271000 0 0x3000>,
  <0 0x11280700 0 0x0100>;
reg-names = "mac", "ippc";
@@ -731,22 +731,16 @@
   < PHY_TYPE_USB3>,
   < PHY_TYPE_USB2>;
power-domains = < MT8173_POWER_DOMAIN_USB>;
-   clocks = < CLK_TOP_USB30_SEL>,
-<>,
-< CLK_PERI_USB0>,
-< CLK_PERI_USB1>;
-   clock-names = "sys_ck",
- "ref_ck",
- "wakeup_deb_p0",
- "wakeup_deb_p1";
-   mediatek,syscon-wakeup = <>;
+   clocks = < CLK_TOP_USB30_SEL>, <>;
+   clock-names = "sys_ck", "ref_ck";
#address-cells = <2>;
#size-cells = <2>;
ranges;
status = "disabled";
 
usb_host: xhci@1127 {
-   compatible = "mediatek,mt8173-xhci";
+   compatible = "mediatek,mt8173-xhci",
+"mediatek,mtk-xhci";
reg = <0 0x1127 0 0x1000>;
reg-names = "mac";
interrupts = ;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   3   4   5   6   >