Re: [PATCH v2] usb: renesas_usbhs: Add compatible string for r8a7743/5

2017-10-13 Thread Rob Herring
On Fri, Oct 06, 2017 at 05:49:34PM +0100, Biju Das wrote:
> This patch adds support for r8a7743/5 SoCs. The Renesas RZ/G1[ME]
> (R8A7743/5) usbhs is identical to the R-Car Gen2 family.
> 
> No driver change is needed due to the fallback compatible value
> "renesas,rcar-gen2-usbhs".
> Adding the SoC-specific compatible values here has two purposes:
>   1. Document which SoCs have this hardware module,
>   2. Allow checkpatch to validate compatible values.
> 
> Signed-off-by: Biju Das 
> Signed-off-by: Chris Paterson 
> Reviewed-by: Yoshihiro Shimoda 
> Reviewed-by: Geert Uytterhoeven 
> ---
> v1-->v2
>* Modified the patch description
>* Rebased on the below R-Car D3 patch
>  https://patchwork.kernel.org/patch/9982267/
> 
> This patch is tested against Linux next tag next-20170929 +
>   https://patchwork.kernel.org/patch/9982267/
> 
>  Documentation/devicetree/bindings/usb/renesas_usbhs.txt | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Acked-by: Rob Herring 

--
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: phy: phy-generic: propagate clk_get error if clock is required

2017-10-13 Thread Lucas Stach
Am Freitag, den 18.08.2017, 18:32 +0200 schrieb Lucas Stach:
> If the clock handle is given in the DT, it means the clock is
> required
> for proper operation of the PHY. In that case a failure to obtain the
> clock must be propagated to stop the driver from probing. This fixes
> working with clocks, which request probe deferral.

Can we get this patch applied? It fixes a real issue and is pretty
straight forward.

Regards,
Lucas

> > Signed-off-by: Lucas Stach 
> ---
>  drivers/usb/phy/phy-generic.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
> index 89d6e7a5fdb7..1cc02eb3fc65 100644
> --- a/drivers/usb/phy/phy-generic.c
> +++ b/drivers/usb/phy/phy-generic.c
> @@ -224,7 +224,7 @@ int usb_phy_gen_create_phy(struct device *dev, struct 
> usb_phy_generic *nop,
> >     int err = 0;
>  
> >     u32 clk_rate = 0;
> > -   bool needs_vcc = false;
> > +   bool needs_vcc = false, needs_clk = false;
>  
> >     if (dev->of_node) {
> >     struct device_node *node = dev->of_node;
> @@ -233,6 +233,7 @@ int usb_phy_gen_create_phy(struct device *dev, struct 
> usb_phy_generic *nop,
> >     clk_rate = 0;
>  
> >     needs_vcc = of_property_read_bool(node, "vcc-supply");
> > +   needs_clk = of_property_read_bool(node, "clocks");
> >     nop->gpiod_reset = devm_gpiod_get_optional(dev, "reset",
> >        GPIOD_ASIS);
> >     err = PTR_ERR_OR_ZERO(nop->gpiod_reset);
> @@ -275,6 +276,8 @@ int usb_phy_gen_create_phy(struct device *dev, struct 
> usb_phy_generic *nop,
> >     if (IS_ERR(nop->clk)) {
> >     dev_dbg(dev, "Can't get phy clock: %ld\n",
> >     PTR_ERR(nop->clk));
> > +   if (needs_clk)
> > +   return PTR_ERR(nop->clk);
> >     }
>  
> >     if (!IS_ERR(nop->clk) && clk_rate) {
--
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] USB: Force disconnect Huawei 4G modem during suspend

2017-10-13 Thread Alan Stern
On Fri, 13 Oct 2017, Daniel Drake wrote:

> When going into S3 suspend, the Acer TravelMate P648-M and P648-G3
> laptops immediately wake up 3-4 seconds later for no obvious reason.
> 
> Unbinding the integrated Huawei 4G LTE modem before suspend avoids
> the issue, even though we are not using the modem at all (checked
> from rescue.target/runlevel1). The problem also occurs when the option
> and cdc-ether modem drivers aren't loaded; it reproduces just with the
> base usb driver. Under Windows the system can suspend fine.
> 
> Seeking a better fix, we've tried a lot of things, including:
>  - Check that the device's power/wakeup is disabled
>  - Check that remote wakeup is off at the USB level
>  - All the quirks in drivers/usb/core/quirks.c e.g. USB_QUIRK_RESET_RESUME,
>USB_QUIRK_RESET, USB_QUIRK_IGNORE_REMOTE_WAKEUP, USB_QUIRK_NO_LPM.
> 
> but none of that makes any difference.
> 
> There are no errors in the logs showing any suspend/resume-related issues.
> When the system wakes up due to the modem, log-wise it appears to be a
> normal resume.
> 
> Introduce a quirk to disable the port during suspend when the modem is
> detected.

> diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
> index eb87a259d55c..7c048afc9bfd 100644
> --- a/drivers/usb/core/driver.c
> +++ b/drivers/usb/core/driver.c
> @@ -1461,6 +1461,7 @@ static void choose_wakeup(struct usb_device *udev, 
> pm_message_t msg)
>  int usb_suspend(struct device *dev, pm_message_t msg)
>  {
>   struct usb_device   *udev = to_usb_device(dev);
> + int r;
>  
>   unbind_no_pm_drivers_interfaces(udev);
>  
> @@ -1469,7 +1470,14 @@ int usb_suspend(struct device *dev, pm_message_t msg)
>* so we may still need to unbind and rebind upon resume
>*/
>   choose_wakeup(udev, msg);
> - return usb_suspend_both(udev, msg);
> + r = usb_suspend_both(udev, msg);
> + if (r)
> + return r;
> +
> + if (udev->quirks & USB_QUIRK_DISCONNECT_SUSPEND)
> + r = usb_port_disable(udev);
> +
> + return r;

Here it's probably best to ignore the return value.  Even if 
usb_port_disable failed, you want the system suspend to move forward -- 
even if the system spontaneously wakes up a second later.

>  }
>  
>  /* The device lock is held by the PM core */
> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> index b5c733613823..9662eaa9c44d 100644
> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c
> @@ -4180,6 +4180,19 @@ static int hub_port_disable(struct usb_hub *hub, int 
> port1, int set_state)
>   return ret;
>  }
>  
> +/*
> + * usb_port_disable - disable a usb device's upstream port
> + * @udev: device to disable
> + * Context: must be able to sleep; device not locked; pm locks held

Actually the device _is_ locked when this routine gets called.  And the 
PM locks are not held.

> + *
> + * Disables a USB device that isn't in active use.
> + */
> +int usb_port_disable(struct usb_device *udev)
> +{
> + struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
> +
> + return hub_port_disable(hub, udev->portnum, 1);
> +}

You probably want the last argument to be 0, not 1.  The 1 will cause
the device to be marked as disconnected, so when the system wakes up it
will think that a new device has been plugged in rather than the old
device having been attached all along.

Alan Stern

--
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 v5 1/3] dt-bindings: usb: add the documentation for USB root-hub

2017-10-13 Thread Alan Stern
On Thu, 12 Oct 2017, Martin Blumenstingl wrote:

> Hi Alan,
> 
> On Thu, Oct 12, 2017 at 11:17 PM, Alan Stern  
> wrote:
> > On Thu, 12 Oct 2017, Martin Blumenstingl wrote:
> >
> >> I haven't tested the described use-case. however, this patch is not
> >> supposed to change the binding for actual devices.
> >> USB device numbering starts at 1, while 0 is reserved for the root-hub
> >> (at least from what I know).
> >
> > Actually 1 is reserved for the root hub.  External devices are numbered
> > starting from 2.  (We can't use 0 for the root hub because, as you
> > said, USB device numbering starts at 1!)
> I just had a look at lsusb again:
> $ lsusb -t
> /:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 5000M
> 
> however, for the devicetree bindings the devices are supposed to use 1-31: [0]
> 
> Alan: just to make sure I understood you correctly: do you agree with
> this patch?

I have no idea.  I haven't read the patch and I'm not familiar with the
details of DeviceTree.  I was just trying to clear up your
misunderstanding of USB device numbering.

Alan Stern

--
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 v5 3/3] usb: core: hcd: integrate the PHY roothub wrapper

2017-10-13 Thread Alan Stern
On Thu, 12 Oct 2017, Martin Blumenstingl wrote:

> Hi Alan,
> 
> On Mon, Oct 9, 2017 at 7:18 PM, Alan Stern  wrote:
> > On Sun, 8 Oct 2017, Martin Blumenstingl wrote:
> >
> >> This integrates the PHY roothub wrapper into the core hcd
> >> infrastructure. Multiple PHYs which are part of the roothub devicetree
> >> node (which is a sub-node of the sysdev's node) are now managed
> >> (= powered on/off when needed), by the new usb_phy_roothub code.
> >>
> >> One example where this is required is the Amlogic GXL and GXM SoCs:
> >> They are using a dwc3 USB controller with up to three ports enabled on
> >> the internal roothub. Using only the top-level "phy" properties does not
> >> work here since one can only specify one "usb2-phy" and one "usb3-phy",
> >> while actually at least two "usb2-phy" have to be specified.
> >>
> >> Signed-off-by: Martin Blumenstingl 
> >> ---
> >>  drivers/usb/core/hcd.c  | 30 +-
> >>  include/linux/usb/hcd.h |  1 +
> >>  2 files changed, 30 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> >> index 67aa3d039b9b..56704dd10c15 100644
> >> --- a/drivers/usb/core/hcd.c
> >> +++ b/drivers/usb/core/hcd.c
> >> @@ -50,6 +50,7 @@
> >>  #include 
> >>
> >>  #include "usb.h"
> >> +#include "phy.h"
> >>
> >>
> >>  
> >> /*-*/
> >> @@ -2292,7 +2293,11 @@ int hcd_bus_suspend(struct usb_device *rhdev, 
> >> pm_message_t msg)
> >>   dev_dbg(>dev, "bus %s fail, err %d\n",
> >>   "suspend", status);
> >>   }
> >> - return status;
> >> +
> >> + if (status == 0)
> >> + return usb_phy_roothub_power_off(hcd->phy_roothub);
> >
> > Is this really the right thing to do?  If usb_phy_roothub_power_off()
> > fails, what condition does this leave the bus in?  And what condition
> > does the kernel _think_ the bus is in?
> indeed, thank you for spotting this!
> 
> do you have any suggestions how to improve this?
> maybe I should move usb_phy_roothub_power_off a few lines up and only
> call it after the "rhdev->do_remote_wakeup" block if status is 0. if
> usb_phy_roothub_power_off then returns an error I could call
> "hcd_bus_resume(rhdev, PMSG_AUTO_RESUME);". what do you think about
> this?

Or you could just throw away the return code from 
usb_phy_roothub_power_off().  Maybe print it out in a warning message, 
but do not report it to the caller.

After all, given the choice between leaving the entire USB bus at full 
power and leaving just the phy at full power, which would you prefer?

Alan Stern

--
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 9/9] dt-bindings: usb: mtk-xhci: remove dummy clocks and add optional ones

2017-10-13 Thread Matthias Brugger



On 10/13/2017 10:26 AM, Chunfeng Yun wrote:

Remove dummy clocks for usb wakeup and add optional ones for
MCU_BUS_CK and DMA_BUS_CK.

Signed-off-by: Chunfeng Yun 
Acked-by: Rob Herring 
---


Reviewed-by: 


  .../devicetree/bindings/usb/mediatek,mtk-xhci.txt  |   18 --
  1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
index 2d9b459..3059596 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
@@ -26,10 +26,11 @@ Required properties:
   - clocks : a list of phandle + clock-specifier pairs, one for each
entry in clock-names
   - clock-names : must contain
-   "sys_ck": for clock of xHCI MAC
-   "ref_ck": for reference clock of xHCI MAC
-   "wakeup_deb_p0": for USB wakeup debounce clock of port0
-   "wakeup_deb_p1": for USB wakeup debounce clock of port1
+   "sys_ck": controller clock used by normal mode,
+   the following ones are optional:
+   "ref_ck": reference clock used by low power mode etc,
+   "mcu_ck": mcu_bus clock for register access,
+   "dma_ck": dma_bus clock for data transfer by DMA
  
   - phys : a list of phandle + phy specifier pairs
  
@@ -57,9 +58,7 @@ usb30: usb@1127 {

clocks = < CLK_TOP_USB30_SEL>, <>,
 < CLK_PERI_USB0>,
 < CLK_PERI_USB1>;
-   clock-names = "sys_ck", "ref_ck",
- "wakeup_deb_p0",
- "wakeup_deb_p1";
+   clock-names = "sys_ck", "ref_ck";
phys = <_port0 PHY_TYPE_USB3>,
   <_port1 PHY_TYPE_USB2>;
vusb33-supply = <_vusb_reg>;
@@ -91,9 +90,8 @@ Required properties:
  
   - clocks : a list of phandle + clock-specifier pairs, one for each

entry in clock-names
- - clock-names : must be
-   "sys_ck": for clock of xHCI MAC
-   "ref_ck": for reference clock of xHCI MAC
+ - clock-names : must contain "sys_ck", and the following ones are optional:
+   "ref_ck", "mcu_ck" and "dma_ck"
  
  Optional properties:

   - vbus-supply : reference to the VBUS regulator;


--
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 6/9] usb: xhci-mtk: add optional mcu and dma bus clocks

2017-10-13 Thread Matthias Brugger



On 10/13/2017 10:26 AM, Chunfeng Yun wrote:

There are mcu_bus and dma_bus clocks needed to be controlled by
driver on some SoCs, so add them as optional ones

Signed-off-by: Chunfeng Yun 
---


Reviewed-by: Matthias Brugger 


  drivers/usb/host/xhci-mtk.c |   79 ---
  drivers/usb/host/xhci-mtk.h |2 ++
  2 files changed, 62 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index d60463c..e5caabe 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -221,6 +221,44 @@ static int xhci_mtk_ssusb_config(struct xhci_hcd_mtk *mtk)
return xhci_mtk_host_enable(mtk);
  }
  
+/* ignore the error if the clock does not exist */

+static struct clk *optional_clk_get(struct device *dev, const char *id)
+{
+   struct clk *opt_clk;
+
+   opt_clk = devm_clk_get(dev, id);
+   /* ignore error number except EPROBE_DEFER */
+   if (IS_ERR(opt_clk) && (PTR_ERR(opt_clk) != -EPROBE_DEFER))
+   opt_clk = NULL;
+
+   return opt_clk;
+}
+
+static int xhci_mtk_clks_get(struct xhci_hcd_mtk *mtk)
+{
+   struct device *dev = mtk->dev;
+
+   mtk->sys_clk = devm_clk_get(dev, "sys_ck");
+   if (IS_ERR(mtk->sys_clk)) {
+   dev_err(dev, "fail to get sys_ck\n");
+   return PTR_ERR(mtk->sys_clk);
+   }
+
+   mtk->ref_clk = optional_clk_get(dev, "ref_ck");
+   if (IS_ERR(mtk->ref_clk))
+   return PTR_ERR(mtk->ref_clk);
+
+   mtk->mcu_clk = optional_clk_get(dev, "mcu_ck");
+   if (IS_ERR(mtk->mcu_clk))
+   return PTR_ERR(mtk->mcu_clk);
+
+   mtk->dma_clk = optional_clk_get(dev, "dma_ck");
+   if (IS_ERR(mtk->dma_clk))
+   return PTR_ERR(mtk->dma_clk);
+
+   return 0;
+}
+
  static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
  {
int ret;
@@ -237,16 +275,34 @@ static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
goto sys_clk_err;
}
  
+	ret = clk_prepare_enable(mtk->mcu_clk);

+   if (ret) {
+   dev_err(mtk->dev, "failed to enable mcu_clk\n");
+   goto mcu_clk_err;
+   }
+
+   ret = clk_prepare_enable(mtk->dma_clk);
+   if (ret) {
+   dev_err(mtk->dev, "failed to enable dma_clk\n");
+   goto dma_clk_err;
+   }
+
return 0;
  
+dma_clk_err:

+   clk_disable_unprepare(mtk->mcu_clk);
+mcu_clk_err:
+   clk_disable_unprepare(mtk->sys_clk);
  sys_clk_err:
clk_disable_unprepare(mtk->ref_clk);
  ref_clk_err:
-   return -EINVAL;
+   return ret;
  }
  
  static void xhci_mtk_clks_disable(struct xhci_hcd_mtk *mtk)

  {
+   clk_disable_unprepare(mtk->dma_clk);
+   clk_disable_unprepare(mtk->mcu_clk);
clk_disable_unprepare(mtk->sys_clk);
clk_disable_unprepare(mtk->ref_clk);
  }
@@ -529,24 +585,9 @@ static int xhci_mtk_probe(struct platform_device *pdev)
return PTR_ERR(mtk->vusb33);
}
  
-	mtk->sys_clk = devm_clk_get(dev, "sys_ck");

-   if (IS_ERR(mtk->sys_clk)) {
-   dev_err(dev, "fail to get sys_ck\n");
-   return PTR_ERR(mtk->sys_clk);
-   }
-
-   /*
-* reference clock is usually a "fixed-clock", make it optional
-* for backward compatibility and ignore the error if it does
-* not exist.
-*/
-   mtk->ref_clk = devm_clk_get(dev, "ref_ck");
-   if (IS_ERR(mtk->ref_clk)) {
-   if (PTR_ERR(mtk->ref_clk) == -EPROBE_DEFER)
-   return -EPROBE_DEFER;
-
-   mtk->ref_clk = NULL;
-   }
+   ret = xhci_mtk_clks_get(mtk);
+   if (ret)
+   return ret;
  
  	mtk->lpm_support = of_property_read_bool(node, "usb3-lpm-capable");

/* optional property, ignore the error if it does not exist */
diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h
index 67783a7..45ff5c6 100644
--- a/drivers/usb/host/xhci-mtk.h
+++ b/drivers/usb/host/xhci-mtk.h
@@ -126,6 +126,8 @@ struct xhci_hcd_mtk {
struct regulator *vbus;
struct clk *sys_clk;/* sys and mac clock */
struct clk *ref_clk;
+   struct clk *mcu_clk;
+   struct clk *dma_clk;
struct regmap *pericfg;
struct phy **phys;
int num_phys;


--
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 5/9] usb: xhci-mtk: remove dummy wakeup debounce clocks

2017-10-13 Thread Matthias Brugger



On 10/13/2017 10:26 AM, Chunfeng Yun wrote:

The wakeup debounce clocks for each ports in fact are not
needed, so remove them.

Signed-off-by: Chunfeng Yun 
---


Reviewed-by: Matthias Brugger 


  drivers/usb/host/xhci-mtk.c |   33 -
  drivers/usb/host/xhci-mtk.h |2 --
  2 files changed, 35 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 97ba51e..d60463c 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -237,25 +237,8 @@ static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
goto sys_clk_err;
}
  
-	if (mtk->wakeup_src) {

-   ret = clk_prepare_enable(mtk->wk_deb_p0);
-   if (ret) {
-   dev_err(mtk->dev, "failed to enable wk_deb_p0\n");
-   goto usb_p0_err;
-   }
-
-   ret = clk_prepare_enable(mtk->wk_deb_p1);
-   if (ret) {
-   dev_err(mtk->dev, "failed to enable wk_deb_p1\n");
-   goto usb_p1_err;
-   }
-   }
return 0;
  
-usb_p1_err:

-   clk_disable_unprepare(mtk->wk_deb_p0);
-usb_p0_err:
-   clk_disable_unprepare(mtk->sys_clk);
  sys_clk_err:
clk_disable_unprepare(mtk->ref_clk);
  ref_clk_err:
@@ -264,10 +247,6 @@ static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
  
  static void xhci_mtk_clks_disable(struct xhci_hcd_mtk *mtk)

  {
-   if (mtk->wakeup_src) {
-   clk_disable_unprepare(mtk->wk_deb_p1);
-   clk_disable_unprepare(mtk->wk_deb_p0);
-   }
clk_disable_unprepare(mtk->sys_clk);
clk_disable_unprepare(mtk->ref_clk);
  }
@@ -371,18 +350,6 @@ static int usb_wakeup_of_property_parse(struct 
xhci_hcd_mtk *mtk,
if (!mtk->wakeup_src)
return 0;
  
-	mtk->wk_deb_p0 = devm_clk_get(dev, "wakeup_deb_p0");

-   if (IS_ERR(mtk->wk_deb_p0)) {
-   dev_err(dev, "fail to get wakeup_deb_p0\n");
-   return PTR_ERR(mtk->wk_deb_p0);
-   }
-
-   mtk->wk_deb_p1 = devm_clk_get(dev, "wakeup_deb_p1");
-   if (IS_ERR(mtk->wk_deb_p1)) {
-   dev_err(dev, "fail to get wakeup_deb_p1\n");
-   return PTR_ERR(mtk->wk_deb_p1);
-   }
-
mtk->pericfg = syscon_regmap_lookup_by_phandle(dn,
"mediatek,syscon-wakeup");
if (IS_ERR(mtk->pericfg)) {
diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h
index db55a12..67783a7 100644
--- a/drivers/usb/host/xhci-mtk.h
+++ b/drivers/usb/host/xhci-mtk.h
@@ -126,8 +126,6 @@ struct xhci_hcd_mtk {
struct regulator *vbus;
struct clk *sys_clk;/* sys and mac clock */
struct clk *ref_clk;
-   struct clk *wk_deb_p0;  /* port0's wakeup debounce clock */
-   struct clk *wk_deb_p1;
struct regmap *pericfg;
struct phy **phys;
int num_phys;


--
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: xhci_hcd 0000:00:14.0: WARN Event TRB for slot 1 ep 2 with no TDs queued?

2017-10-13 Thread Yaroslav Isakov
Hello, Mathias! Did you get a chance to look into this bug?

2017-07-20 19:15 GMT+03:00 Yaroslav Isakov :
> Yes, I can definitely test the patch
>
> 2017-07-20 19:16 GMT+03:00 Mathias Nyman :
>> On 20.07.2017 18:07, Yaroslav Isakov wrote:
>>>
>>> Here it is
>>>
>>> 2017-07-20 18:06 GMT+03:00 Mathias Nyman :

 On 20.07.2017 17:43, Yaroslav Isakov wrote:
>
>
> Hello everyone! I saw this thread some months ago, but do not know how
> to properly reply to it. I have the same problem, and it's just not
> few messages - it was about 40k messages in 10 minutes. No functional
> of my USB device (which is CCID USB token) is broken, just enormous
> amount of spam in the logs. I'm on 4.12 kernel, but I've seen this
> error on 4.11 and 4.9. Could this problem be caused by a bug in e.g.
> libusb, not a device itself?
> --



 I'd start by looking at xhci, can you take xhci traces of this?

 mount -t debugfs none /sys/kernel/debug
 echo 81920 > /sys/kernel/debug/tracing/buffer_size_kb
 echo 1 > /sys/kernel/debug/tracing/events/xhci-hcd/enable

 and then send me the content of
 /sys/kernel/debug/tracing/trace

 I'll be away for a couple of weeks, so next response might take some time

 -Mathias


>>
>> Think I found something.   (details mostly for myself in to remember this)
>> A short transfer response on a bulk in transfer which is not the last TRB of
>> a TD
>>
>> According to specs xhci will issue short transfer events both on the short
>> TRB, _and_
>> on the last TRB of the TD in case any previous TRB in the TD was short
>> (see xhci 4.11.3.1)
>>
>> After the first short transfer event the driver fast forward past this TD.
>> (and the last TRB)
>> when we get the second short transfer event there are no TRBs queued and you
>> see the
>> warning.
>>
>> Warning should be harmless in this case, but annoying.
>> If I write a patch can you try it out?
>>
>> As a reference, a snippet when log when a 65556 byte transfer is queued,
>> split into 5 pieces (TRBS),
>> and we get short transfer events for first and last TRB
>>
>> * A URB asking for 65556 bytes is queues:
>> 2369.450362: xhci_urb_enqueue: ep1in-bulk: urb 8801398f6540 pipe
>> 3221258880 slot 1 length 0/65556 sgs 5/5 stream 0 flags 00040200
>> * split into 5 pieces ( TRBs at 0x0002169cb520, ..530, ..540, ..550 and
>> ..560)
>> 2369.450363: xhci_queue_trb: BULK: Buffer 00010a7dc000 length 16384 TD
>> size 31 intr 0 type 'Normal' flags b:i:i:C:s:I:e:C
>> 2369.450363: xhci_inc_enq: BULK 88021726c780: enq
>> 0x0002169cb530(0x0002169cb000) deq
>> 0x0002169cb520(0x0002169cb000) segs 2 stream 0 free_trbs 508 bounce
>> 6\
>> 2369.450363: xhci_queue_trb: BULK: Buffer 00011e97 length 16384 TD
>> size 31 intr 0 type 'Normal' flags b:i:i:C:s:I:e:c
>> 2369.450363: xhci_inc_enq: BULK 88021726c780: enq
>> 0x0002169cb540(0x0002169cb000) deq
>> 0x0002169cb520(0x0002169cb000) segs 2 stream 0 free_trbs 507 bounce
>> 6\
>> 2369.450363: xhci_queue_trb: BULK: Buffer 0001b63ac000 length 16384 TD
>> size 31 intr 0 type 'Normal' flags b:i:i:C:s:I:e:c
>> 2369.450363: xhci_inc_enq: BULK 88021726c780: enq
>> 0x0002169cb550(0x0002169cb000) deq
>> 0x0002169cb520(0x0002169cb000) segs 2 stream 0 free_trbs 506 bounce
>> 6\
>> 2369.450364: xhci_queue_trb: BULK: Buffer 00010a7ac000 length 16384 TD
>> size 1 intr 0 type 'Normal' flags b:i:i:C:s:I:e:c
>> 2369.450364: xhci_inc_enq: BULK 88021726c780: enq
>> 0x0002169cb560(0x0002169cb000) deq
>> 0x0002169cb520(0x0002169cb000) segs 2 stream 0 free_trbs 505 bounce
>> 6\
>> 2369.450364: xhci_queue_trb: BULK: Buffer 0001a26adf40 length 20 TD size
>> 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
>> 2369.450364: xhci_inc_enq: BULK 88021726c780: enq
>> 0x0002169cb570(0x0002169cb000) deq
>> 0x0002169cb520(0x0002169cb000) segs 2 stream 0 free_trbs 504 bounce
>> 6\
>> * short packet event for first TRB at ..520
>> 2369.450505: xhci_handle_event: EVENT: TRB 0002169cb520 status 'Short
>> Packet' len 16334 slot 1 ep 3 type 'Transfer Event' flags e:c
>> 2369.450506: xhci_handle_transfer: BULK: Buffer 00010a7dc000 length
>> 16384 TD size 31 intr 0 type 'Normal' flags b:i:i:C:s:I:e:c
>> * fast forward past this TD, move dequeue to ..570)
>> 2369.450506: xhci_inc_deq: BULK 88021726c780: enq
>> 0x0002169cb570(0x0002169cb000) deq
>> 0x0002169cb530(0x0002169cb000) segs 2 stream 0 free_trbs 505 bounce
>> 6\
>> 2369.450506: xhci_inc_deq: BULK 88021726c780: enq
>> 0x0002169cb570(0x0002169cb000) deq
>> 0x0002169cb540(0x0002169cb000) segs 2 stream 0 free_trbs 506 bounce
>> 6\
>> 2369.450506: xhci_inc_deq: BULK 88021726c780: enq
>> 0x0002169cb570(0x0002169cb000) deq
>> 

Re: [PATCH] xhci: Set DMA parameters appropriately

2017-10-13 Thread Robin Murphy
Hi Marek,

On 13/10/17 09:15, Marek Szyprowski wrote:
> Hi Robin,
> 
> On 2017-10-11 15:56, Robin Murphy wrote:
>> xHCI requires that data buffers do not cross 64KB boundaries (and are
>> thus at most 64KB long as well) - whilst xhci_queue_{bulk,isoc}_tx()
>> already split their input buffers into individual TRBs as necessary,
>> it's still a good idea to advertise the limitations via the standard DMA
>> API mechanism, so that most producers like the block layer and the DMA
>> mapping implementations can lay things out correctly to begin with.
>>
>> Signed-off-by: Robin Murphy 
>> ---
>>   drivers/usb/host/xhci.c | 4 
>>   drivers/usb/host/xhci.h | 3 +++
>>   2 files changed, 7 insertions(+)
>>
>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
>> index 74b4500641c2..1e7e1e3d8c48 100644
>> --- a/drivers/usb/host/xhci.c
>> +++ b/drivers/usb/host/xhci.c
>> @@ -4883,6 +4883,10 @@ int xhci_gen_setup(struct usb_hcd *hcd,
>> xhci_get_quirks_t get_quirks)
>>   dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
>>   }
>>   +    dev->dma_parms = >dma_parms;
>> +    dma_set_max_seg_size(dev, SZ_64K);
>> +    dma_set_seg_boundary(dev, SZ_64K - 1);
>> +
>>   xhci_dbg(xhci, "Calling HCD init\n");
>>   /* Initialize HCD and host controller data structures. */
>>   retval = xhci_init(hcd);
>> diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
>> index 7ef69ea0b480..afcae4cc908d 100644
>> --- a/drivers/usb/host/xhci.h
>> +++ b/drivers/usb/host/xhci.h
>> @@ -1767,6 +1767,9 @@ struct xhci_hcd {
>>   struct dma_pool    *small_streams_pool;
>>   struct dma_pool    *medium_streams_pool;
>>   +    /* DMA alignment restrictions */
>> +    struct device_dma_parameters dma_parms;
>> +
>>   /* Host controller watchdog timer structures */
>>   unsigned int    xhc_state;
>>   
> 
> Are you sure that xhci_hcd life time is proper to keep dma_parms? It looks
> that when driver gets removed and xhci_hcd is freed, the dma_parms will
> point to freed memory. Maybe it would make sense to clear dev->dma_parms
> somewhere or definitely change the way dma_parms are allocated?

AFAICS it lives until the last usb_put_hcd() call, which is pretty much
the last thing in the drivers' .remove paths, so it looks to follow the
standard paradigm evidenced by other dma_parms users. Any dangling
pointer after the driver has been unbound will be reinitialised by a
subsequent probe, and anyone using an unbound device for DMA API calls
is very wrong anyway.

> On the other hand 64K is the default segment size if no dma_parms are
> provided, so there is very little value added by this patch.

I prefer to explicitly set the segment size for cleanliness and to
emphasize the difference between "whatever the default value is is fine"
and "we have a real hardware limit of 64K". What really matters here
though is the non-default segment boundary mask - that's the motiviation
for the patch.

Robin.
--
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 7/9] usb: host: modify description for MTK xHCI config

2017-10-13 Thread Mathias Nyman

On 13.10.2017 11:26, Chunfeng Yun wrote:

Due to all MediaTek SoCs with xHCI host controller use this
driver, remove limitation for specific SoCs

Signed-off-by: Chunfeng Yun 
---


xHCI parts of series look good to me, If Rob Herring agrees with the
dt changes I can send it forward

-Mathias

--
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 02/13] usb: mtu3: support option to disable usb3 ports

2017-10-13 Thread Chunfeng Yun
Add support to disable specific usb3 ports, it's useful when
usb3 phy is shared with PCIe or SATA, because we should disable
the corresponding usb3 port if the phy is used by PCIe or SATA.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3.h  |3 +++
 drivers/usb/mtu3/mtu3_host.c |   16 +---
 drivers/usb/mtu3/mtu3_plat.c |8 ++--
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index b26fffc..112723d 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -210,6 +210,8 @@ struct otg_switch_mtk {
  * host only, device only or dual-role mode
  * @u2_ports: number of usb2.0 host ports
  * @u3_ports: number of usb3.0 host ports
+ * @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
  * @wk_deb_p0: port0's wakeup debounce clock
@@ -232,6 +234,7 @@ struct ssusb_mtk {
bool is_host;
int u2_ports;
int u3_ports;
+   int u3p_dis_msk;
struct dentry *dbgfs_root;
/* usb wakeup for host mode */
bool wakeup_en;
diff --git a/drivers/usb/mtu3/mtu3_host.c b/drivers/usb/mtu3/mtu3_host.c
index e42d308..4dd9508 100644
--- a/drivers/usb/mtu3/mtu3_host.c
+++ b/drivers/usb/mtu3/mtu3_host.c
@@ -151,6 +151,7 @@ int ssusb_host_enable(struct ssusb_mtk *ssusb)
void __iomem *ibase = ssusb->ippc_base;
int num_u3p = ssusb->u3_ports;
int num_u2p = ssusb->u2_ports;
+   int u3_ports_disabed;
u32 check_clk;
u32 value;
int i;
@@ -158,8 +159,14 @@ int ssusb_host_enable(struct ssusb_mtk *ssusb)
/* power on host ip */
mtu3_clrbits(ibase, U3D_SSUSB_IP_PW_CTRL1, SSUSB_IP_HOST_PDN);
 
-   /* power on and enable all u3 ports */
+   /* power on and enable u3 ports except skipped ones */
+   u3_ports_disabed = 0;
for (i = 0; i < num_u3p; i++) {
+   if ((0x1 << i) & ssusb->u3p_dis_msk) {
+   u3_ports_disabed++;
+   continue;
+   }
+
value = mtu3_readl(ibase, SSUSB_U3_CTRL(i));
value &= ~(SSUSB_U3_PORT_PDN | SSUSB_U3_PORT_DIS);
value |= SSUSB_U3_PORT_HOST_SEL;
@@ -175,7 +182,7 @@ int ssusb_host_enable(struct ssusb_mtk *ssusb)
}
 
check_clk = SSUSB_XHCI_RST_B_STS;
-   if (num_u3p)
+   if (num_u3p > u3_ports_disabed)
check_clk = SSUSB_U3_MAC_RST_B_STS;
 
return ssusb_check_clocks(ssusb, check_clk);
@@ -190,8 +197,11 @@ int ssusb_host_disable(struct ssusb_mtk *ssusb, bool 
suspend)
int ret;
int i;
 
-   /* power down and disable all u3 ports */
+   /* power down and disable u3 ports except skipped ones */
for (i = 0; i < num_u3p; i++) {
+   if ((0x1 << i) & ssusb->u3p_dis_msk)
+   continue;
+
value = mtu3_readl(ibase, SSUSB_U3_CTRL(i));
value |= SSUSB_U3_PORT_PDN;
value |= suspend ? 0 : SSUSB_U3_PORT_DIS;
diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
index 088e3e6..9edad30 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -276,6 +276,10 @@ static int get_ssusb_rscs(struct platform_device *pdev, 
struct ssusb_mtk *ssusb)
if (ret)
return ret;
 
+   /* optional property, ignore the error if it does not exist */
+   of_property_read_u32(node, "mediatek,u3p-dis-msk",
+>u3p_dis_msk);
+
if (ssusb->dr_mode != USB_DR_MODE_OTG)
return 0;
 
@@ -304,8 +308,8 @@ static int get_ssusb_rscs(struct platform_device *pdev, 
struct ssusb_mtk *ssusb)
}
}
 
-   dev_info(dev, "dr_mode: %d, is_u3_dr: %d\n",
-   ssusb->dr_mode, otg_sx->is_u3_drd);
+   dev_info(dev, "dr_mode: %d, is_u3_dr: %d, u3p_dis_msk:%x\n",
+   ssusb->dr_mode, otg_sx->is_u3_drd, ssusb->u3p_dis_msk);
 
return 0;
 }
-- 
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 v2 03/13] usb: mtu3: remove dummy wakeup debounce clocks

2017-10-13 Thread Chunfeng Yun
The wakeup debounce clocks for each ports in fact are not
needed, so remove them.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3.h  |4 ---
 drivers/usb/mtu3/mtu3_host.c |   57 +++---
 2 files changed, 4 insertions(+), 57 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index 112723d..6d3278e 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -214,8 +214,6 @@ struct otg_switch_mtk {
  * 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
- * @wk_deb_p0: port0's wakeup debounce clock
- * @wk_deb_p1: it's optional, and depends on port1 is supported or not
  */
 struct ssusb_mtk {
struct device *dev;
@@ -238,8 +236,6 @@ struct ssusb_mtk {
struct dentry *dbgfs_root;
/* usb wakeup for host mode */
bool wakeup_en;
-   struct clk *wk_deb_p0;
-   struct clk *wk_deb_p1;
struct regmap *pericfg;
 };
 
diff --git a/drivers/usb/mtu3/mtu3_host.c b/drivers/usb/mtu3/mtu3_host.c
index 4dd9508..edcc591 100644
--- a/drivers/usb/mtu3/mtu3_host.c
+++ b/drivers/usb/mtu3/mtu3_host.c
@@ -79,20 +79,6 @@ int ssusb_wakeup_of_property_parse(struct ssusb_mtk *ssusb,
if (!ssusb->wakeup_en)
return 0;
 
-   ssusb->wk_deb_p0 = devm_clk_get(dev, "wakeup_deb_p0");
-   if (IS_ERR(ssusb->wk_deb_p0)) {
-   dev_err(dev, "fail to get wakeup_deb_p0\n");
-   return PTR_ERR(ssusb->wk_deb_p0);
-   }
-
-   if (of_property_read_bool(dn, "wakeup_deb_p1")) {
-   ssusb->wk_deb_p1 = devm_clk_get(dev, "wakeup_deb_p1");
-   if (IS_ERR(ssusb->wk_deb_p1)) {
-   dev_err(dev, "fail to get wakeup_deb_p1\n");
-   return PTR_ERR(ssusb->wk_deb_p1);
-   }
-   }
-
ssusb->pericfg = syscon_regmap_lookup_by_phandle(dn,
"mediatek,syscon-wakeup");
if (IS_ERR(ssusb->pericfg)) {
@@ -103,36 +89,6 @@ int ssusb_wakeup_of_property_parse(struct ssusb_mtk *ssusb,
return 0;
 }
 
-static int ssusb_wakeup_clks_enable(struct ssusb_mtk *ssusb)
-{
-   int ret;
-
-   ret = clk_prepare_enable(ssusb->wk_deb_p0);
-   if (ret) {
-   dev_err(ssusb->dev, "failed to enable wk_deb_p0\n");
-   goto usb_p0_err;
-   }
-
-   ret = clk_prepare_enable(ssusb->wk_deb_p1);
-   if (ret) {
-   dev_err(ssusb->dev, "failed to enable wk_deb_p1\n");
-   goto usb_p1_err;
-   }
-
-   return 0;
-
-usb_p1_err:
-   clk_disable_unprepare(ssusb->wk_deb_p0);
-usb_p0_err:
-   return -EINVAL;
-}
-
-static void ssusb_wakeup_clks_disable(struct ssusb_mtk *ssusb)
-{
-   clk_disable_unprepare(ssusb->wk_deb_p1);
-   clk_disable_unprepare(ssusb->wk_deb_p0);
-}
-
 static void host_ports_num_get(struct ssusb_mtk *ssusb)
 {
u32 xhci_cap;
@@ -286,19 +242,14 @@ void ssusb_host_exit(struct ssusb_mtk *ssusb)
 
 int ssusb_wakeup_enable(struct ssusb_mtk *ssusb)
 {
-   int ret = 0;
-
-   if (ssusb->wakeup_en) {
-   ret = ssusb_wakeup_clks_enable(ssusb);
+   if (ssusb->wakeup_en)
ssusb_wakeup_ip_sleep_en(ssusb);
-   }
-   return ret;
+
+   return 0;
 }
 
 void ssusb_wakeup_disable(struct ssusb_mtk *ssusb)
 {
-   if (ssusb->wakeup_en) {
+   if (ssusb->wakeup_en)
ssusb_wakeup_ip_sleep_dis(ssusb);
-   ssusb_wakeup_clks_disable(ssusb);
-   }
 }
-- 
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 v2 01/13] usb: mtu3: fix error return code in ssusb_gadget_init()

2017-10-13 Thread Chunfeng Yun
When failing to get IRQ number, platform_get_irq() may return
-EPROBE_DEFER, but we ignore it and always return -ENODEV,
so fix it.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3_core.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c
index 99c65b0..9475798 100644
--- a/drivers/usb/mtu3/mtu3_core.c
+++ b/drivers/usb/mtu3/mtu3_core.c
@@ -774,9 +774,9 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb)
return -ENOMEM;
 
mtu->irq = platform_get_irq(pdev, 0);
-   if (mtu->irq <= 0) {
+   if (mtu->irq < 0) {
dev_err(dev, "fail to get irq number\n");
-   return -ENODEV;
+   return mtu->irq;
}
dev_info(dev, "irq %d\n", mtu->irq);
 
-- 
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 v2 04/13] usb: mtu3: add optional mcu and dma bus clocks

2017-10-13 Thread Chunfeng Yun
There are mcu_bus and dma_bus clocks needed to be turned on/off by
driver on some SoCs, so add them as optional ones

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3.h  |5 ++
 drivers/usb/mtu3/mtu3_plat.c |  121 --
 2 files changed, 86 insertions(+), 40 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index 6d3278e..2795294 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -206,6 +206,9 @@ struct otg_switch_mtk {
  * @ippc_base: register base address of IP Power and Clock interface (IPPC)
  * @vusb33: usb3.3V shared by device/host IP
  * @sys_clk: system clock of mtu3, shared by device/host IP
+ * @ref_clk: reference clock
+ * @mcu_clk: mcu_bus_ck clock for AHB bus etc
+ * @dma_clk: dma_bus_ck clock for AXI bus etc
  * @dr_mode: works in which mode:
  * host only, device only or dual-role mode
  * @u2_ports: number of usb2.0 host ports
@@ -226,6 +229,8 @@ struct ssusb_mtk {
struct regulator *vusb33;
struct clk *sys_clk;
struct clk *ref_clk;
+   struct clk *mcu_clk;
+   struct clk *dma_clk;
/* otg */
struct otg_switch_mtk otg_switch;
enum usb_dr_mode dr_mode;
diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
index 9edad30..fb89920 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -110,15 +110,9 @@ static void ssusb_phy_power_off(struct ssusb_mtk *ssusb)
phy_power_off(ssusb->phys[i]);
 }
 
-static int ssusb_rscs_init(struct ssusb_mtk *ssusb)
+static int ssusb_clks_enable(struct ssusb_mtk *ssusb)
 {
-   int ret = 0;
-
-   ret = regulator_enable(ssusb->vusb33);
-   if (ret) {
-   dev_err(ssusb->dev, "failed to enable vusb33\n");
-   goto vusb33_err;
-   }
+   int ret;
 
ret = clk_prepare_enable(ssusb->sys_clk);
if (ret) {
@@ -132,6 +126,52 @@ static int ssusb_rscs_init(struct ssusb_mtk *ssusb)
goto ref_clk_err;
}
 
+   ret = clk_prepare_enable(ssusb->mcu_clk);
+   if (ret) {
+   dev_err(ssusb->dev, "failed to enable mcu_clk\n");
+   goto mcu_clk_err;
+   }
+
+   ret = clk_prepare_enable(ssusb->dma_clk);
+   if (ret) {
+   dev_err(ssusb->dev, "failed to enable dma_clk\n");
+   goto dma_clk_err;
+   }
+
+   return 0;
+
+dma_clk_err:
+   clk_disable_unprepare(ssusb->mcu_clk);
+mcu_clk_err:
+   clk_disable_unprepare(ssusb->ref_clk);
+ref_clk_err:
+   clk_disable_unprepare(ssusb->sys_clk);
+sys_clk_err:
+   return ret;
+}
+
+static void ssusb_clks_disable(struct ssusb_mtk *ssusb)
+{
+   clk_disable_unprepare(ssusb->dma_clk);
+   clk_disable_unprepare(ssusb->mcu_clk);
+   clk_disable_unprepare(ssusb->ref_clk);
+   clk_disable_unprepare(ssusb->sys_clk);
+}
+
+static int ssusb_rscs_init(struct ssusb_mtk *ssusb)
+{
+   int ret = 0;
+
+   ret = regulator_enable(ssusb->vusb33);
+   if (ret) {
+   dev_err(ssusb->dev, "failed to enable vusb33\n");
+   goto vusb33_err;
+   }
+
+   ret = ssusb_clks_enable(ssusb);
+   if (ret)
+   goto clks_err;
+
ret = ssusb_phy_init(ssusb);
if (ret) {
dev_err(ssusb->dev, "failed to init phy\n");
@@ -149,20 +189,16 @@ static int ssusb_rscs_init(struct ssusb_mtk *ssusb)
 phy_err:
ssusb_phy_exit(ssusb);
 phy_init_err:
-   clk_disable_unprepare(ssusb->ref_clk);
-ref_clk_err:
-   clk_disable_unprepare(ssusb->sys_clk);
-sys_clk_err:
+   ssusb_clks_disable(ssusb);
+clks_err:
regulator_disable(ssusb->vusb33);
 vusb33_err:
-
return ret;
 }
 
 static void ssusb_rscs_exit(struct ssusb_mtk *ssusb)
 {
-   clk_disable_unprepare(ssusb->sys_clk);
-   clk_disable_unprepare(ssusb->ref_clk);
+   ssusb_clks_disable(ssusb);
regulator_disable(ssusb->vusb33);
ssusb_phy_power_off(ssusb);
ssusb_phy_exit(ssusb);
@@ -203,6 +239,19 @@ static int get_iddig_pinctrl(struct ssusb_mtk *ssusb)
return 0;
 }
 
+/* ignore the error if the clock does not exist */
+static struct clk *get_optional_clk(struct device *dev, const char *id)
+{
+   struct clk *opt_clk;
+
+   opt_clk = devm_clk_get(dev, id);
+   /* ignore error number except EPROBE_DEFER */
+   if (IS_ERR(opt_clk) && (PTR_ERR(opt_clk) != -EPROBE_DEFER))
+   opt_clk = NULL;
+
+   return opt_clk;
+}
+
 static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk 
*ssusb)
 {
struct device_node *node = pdev->dev.of_node;
@@ -225,18 +274,17 @@ static int get_ssusb_rscs(struct platform_device *pdev, 
struct ssusb_mtk *ssusb)
return PTR_ERR(ssusb->sys_clk);
}
 
-   /*
-* reference clock is usually a "fixed-clock", make it optional
-* for backward compatibility 

[PATCH v2 08/13] usb: mtu3: get optional vbus for host only mode

2017-10-13 Thread Chunfeng Yun
When dr_mode is set as USB_DR_MODE_HOST, it's better to try to
get optional vbus, this can increase flexibility, although we
can set vbus as always on for regulator or put it in host driver
to turn it on.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3_plat.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
index 1e473b0..7ca81f4e 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -300,10 +300,6 @@ static int get_ssusb_rscs(struct platform_device *pdev, 
struct ssusb_mtk *ssusb)
of_property_read_u32(node, "mediatek,u3p-dis-msk",
 >u3p_dis_msk);
 
-   if (ssusb->dr_mode != USB_DR_MODE_OTG)
-   return 0;
-
-   /* if dual-role mode is supported */
vbus = devm_regulator_get(>dev, "vbus");
if (IS_ERR(vbus)) {
dev_err(dev, "failed to get vbus\n");
@@ -311,6 +307,10 @@ static int get_ssusb_rscs(struct platform_device *pdev, 
struct ssusb_mtk *ssusb)
}
otg_sx->vbus = vbus;
 
+   if (ssusb->dr_mode == USB_DR_MODE_HOST)
+   return 0;
+
+   /* if dual-role mode is supported */
otg_sx->is_u3_drd = of_property_read_bool(node, "mediatek,usb3-drd");
otg_sx->manual_drd_enabled =
of_property_read_bool(node, "enable-manual-drd");
-- 
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 v2 09/13] usb: mtu3: set invalid dr_mode as dual-role mode

2017-10-13 Thread Chunfeng Yun
Treat dr_mode of USB_DR_MODE_UNKNOWN as USB_DR_MODE_OTG to
enhance functional robustness.

Signed-off-by: Chunfeng Yun 
---
 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 7ca81f4e..9ff3357 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -283,10 +283,8 @@ static int get_ssusb_rscs(struct platform_device *pdev, 
struct ssusb_mtk *ssusb)
return PTR_ERR(ssusb->ippc_base);
 
ssusb->dr_mode = usb_get_dr_mode(dev);
-   if (ssusb->dr_mode == USB_DR_MODE_UNKNOWN) {
-   dev_err(dev, "dr_mode is error\n");
-   return -EINVAL;
-   }
+   if (ssusb->dr_mode == USB_DR_MODE_UNKNOWN)
+   ssusb->dr_mode = USB_DR_MODE_OTG;
 
if (ssusb->dr_mode == USB_DR_MODE_PERIPHERAL)
return 0;
-- 
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 v2 05/13] usb: mtu3: support 36-bit DMA address

2017-10-13 Thread Chunfeng Yun
add support for 36-bit DMA address

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3.h |   17 ++-
 drivers/usb/mtu3/mtu3_core.c|   34 -
 drivers/usb/mtu3/mtu3_hw_regs.h |   10 
 drivers/usb/mtu3/mtu3_qmu.c |  102 ---
 4 files changed, 142 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index 2795294..ef2dc92 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -46,6 +46,9 @@
 #defineMU3D_EP_RXCR1(epnum)(U3D_RX1CSR1 + (((epnum) - 1) * 0x10))
 #defineMU3D_EP_RXCR2(epnum)(U3D_RX1CSR2 + (((epnum) - 1) * 0x10))
 
+#define USB_QMU_TQHIAR(epnum)  (U3D_TXQHIAR1 + (((epnum) - 1) * 0x4))
+#define USB_QMU_RQHIAR(epnum)  (U3D_RXQHIAR1 + (((epnum) - 1) * 0x4))
+
 #define USB_QMU_RQCSR(epnum)   (U3D_RXQCSR1 + (((epnum) - 1) * 0x10))
 #define USB_QMU_RQSAR(epnum)   (U3D_RXQSAR1 + (((epnum) - 1) * 0x10))
 #define USB_QMU_RQCPR(epnum)   (U3D_RXQCPR1 + (((epnum) - 1) * 0x10))
@@ -138,23 +141,33 @@ struct mtu3_fifo_info {
  * Checksum value is calculated over the 16 bytes of the GPD by default;
  * @data_buf_len (RX ONLY): This value indicates the length of
  * the assigned data buffer
+ * @tx_ext_addr (TX ONLY): [3:0] are 4 extension bits of @buffer,
+ * [7:4] are 4 extension bits of @next_gpd
  * @next_gpd: Physical address of the next GPD
  * @buffer: Physical address of the data buffer
  * @buf_len:
  * (TX): This value indicates the length of the assigned data buffer
  * (RX): The total length of data received
  * @ext_len: reserved
+ * @rx_ext_addr(RX ONLY): [3:0] are 4 extension bits of @buffer,
+ * [7:4] are 4 extension bits of @next_gpd
  * @ext_flag:
  * bit5 (TX ONLY): Zero Length Packet (ZLP),
  */
 struct qmu_gpd {
__u8 flag;
__u8 chksum;
-   __le16 data_buf_len;
+   union {
+   __le16 data_buf_len;
+   __le16 tx_ext_addr;
+   };
__le32 next_gpd;
__le32 buffer;
__le16 buf_len;
-   __u8 ext_len;
+   union {
+   __u8 ext_len;
+   __u8 rx_ext_addr;
+   };
__u8 ext_flag;
 } __packed;
 
diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c
index 9475798..cd4528f 100644
--- a/drivers/usb/mtu3/mtu3_core.c
+++ b/drivers/usb/mtu3/mtu3_core.c
@@ -17,6 +17,7 @@
  *
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -759,7 +760,31 @@ static void mtu3_hw_exit(struct mtu3 *mtu)
mtu3_mem_free(mtu);
 }
 
-/*-*/
+/**
+ * we set 32-bit DMA mask by default, here check whether the controller
+ * supports 36-bit DMA or not, if it does, set 36-bit DMA mask.
+ */
+static int mtu3_set_dma_mask(struct mtu3 *mtu)
+{
+   struct device *dev = mtu->dev;
+   bool is_36bit = false;
+   int ret = 0;
+   u32 value;
+
+   value = mtu3_readl(mtu->mac_base, U3D_MISC_CTRL);
+   if (value & DMA_ADDR_36BIT) {
+   is_36bit = true;
+   ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(36));
+   /* If set 36-bit DMA mask fails, fall back to 32-bit DMA mask */
+   if (ret) {
+   is_36bit = false;
+   ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
+   }
+   }
+   dev_info(dev, "dma mask: %s bits\n", is_36bit ? "36" : "32");
+
+   return ret;
+}
 
 int ssusb_gadget_init(struct ssusb_mtk *ssusb)
 {
@@ -820,6 +845,12 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb)
return ret;
}
 
+   ret = mtu3_set_dma_mask(mtu);
+   if (ret) {
+   dev_err(dev, "mtu3 set dma_mask failed:%d\n", ret);
+   goto dma_mask_err;
+   }
+
ret = devm_request_irq(dev, mtu->irq, mtu3_irq, 0, dev_name(dev), mtu);
if (ret) {
dev_err(dev, "request irq %d failed!\n", mtu->irq);
@@ -845,6 +876,7 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb)
 gadget_err:
device_init_wakeup(dev, false);
 
+dma_mask_err:
 irq_err:
mtu3_hw_exit(mtu);
ssusb->u3d = NULL;
diff --git a/drivers/usb/mtu3/mtu3_hw_regs.h b/drivers/usb/mtu3/mtu3_hw_regs.h
index 06b2966..b605975 100644
--- a/drivers/usb/mtu3/mtu3_hw_regs.h
+++ b/drivers/usb/mtu3/mtu3_hw_regs.h
@@ -58,6 +58,8 @@
 #define U3D_QCR1   (SSUSB_DEV_BASE + 0x0404)
 #define U3D_QCR2   (SSUSB_DEV_BASE + 0x0408)
 #define U3D_QCR3   (SSUSB_DEV_BASE + 0x040C)
+#define U3D_TXQHIAR1   (SSUSB_DEV_BASE + 0x0484)
+#define U3D_RXQHIAR1   (SSUSB_DEV_BASE + 0x04C4)
 
 #define U3D_TXQCSR1(SSUSB_DEV_BASE + 0x0510)
 #define U3D_TXQSAR1(SSUSB_DEV_BASE + 0x0514)
@@ -189,6 +191,13 @@
 #define QMU_RX_COZ(x)  (BIT(16) << (x))
 #define QMU_RX_ZLP(x)  (BIT(0) << (x))
 
+/* U3D_TXQHIAR1 */
+/* 

[PATCH v2 06/13] usb: mtu3: use FORCE/RG_IDDIG to implement manual DRD switch

2017-10-13 Thread Chunfeng Yun
In order to keep manual DRD switch independent on IDDIG interrupt,
make use of FORCE/RG_IDDIG instead of IDDIG EINT interrupt to
implement manual DRD switch function.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3.h |   18 
 drivers/usb/mtu3/mtu3_dr.c  |   61 +--
 drivers/usb/mtu3/mtu3_dr.h  |6 
 drivers/usb/mtu3/mtu3_host.c|5 
 drivers/usb/mtu3/mtu3_hw_regs.h |2 ++
 drivers/usb/mtu3/mtu3_plat.c|   38 ++--
 6 files changed, 74 insertions(+), 56 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index ef2dc92..b0c2b5d 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -115,6 +115,19 @@ enum mtu3_g_ep0_state {
 };
 
 /**
+ * MTU3_DR_FORCE_NONE: automatically switch host and periperal mode
+ * by IDPIN signal.
+ * MTU3_DR_FORCE_HOST: force to enter host mode and override OTG
+ * IDPIN signal.
+ * MTU3_DR_FORCE_DEVICE: force to enter peripheral mode.
+ */
+enum mtu3_dr_force_mode {
+   MTU3_DR_FORCE_NONE = 0,
+   MTU3_DR_FORCE_HOST,
+   MTU3_DR_FORCE_DEVICE,
+};
+
+/**
  * @base: the base address of fifo
  * @limit: the bitmap size in bits
  * @bitmap: fifo bitmap in unit of @MTU3_EP_FIFO_UNIT
@@ -196,7 +209,6 @@ struct mtu3_gpd_ring {
 *  xHCI driver initialization, it's necessary for system bootup
 *  as device.
 * @is_u3_drd: whether port0 supports usb3.0 dual-role device or not
-* @id_*: used to maually switch between host and device modes by idpin
 * @manual_drd_enabled: it's true when supports dual-role device by debugfs
 *  to switch host/device modes depending on user input.
 */
@@ -207,10 +219,6 @@ struct otg_switch_mtk {
struct notifier_block id_nb;
struct delayed_work extcon_reg_dwork;
bool is_u3_drd;
-   /* dual-role switch by debugfs */
-   struct pinctrl *id_pinctrl;
-   struct pinctrl_state *id_float;
-   struct pinctrl_state *id_ground;
bool manual_drd_enabled;
 };
 
diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c
index 5602561..ec442cd 100644
--- a/drivers/usb/mtu3/mtu3_dr.c
+++ b/drivers/usb/mtu3/mtu3_dr.c
@@ -261,21 +261,22 @@ static void extcon_register_dwork(struct work_struct 
*work)
  * depending on user input.
  * This is useful in special cases, such as uses TYPE-A receptacle but also
  * wants to support dual-role mode.
- * It generates cable state changes by pulling up/down IDPIN and
- * notifies driver to switch mode by "extcon-usb-gpio".
- * NOTE: when use MICRO receptacle, should not enable this interface.
  */
 static void ssusb_mode_manual_switch(struct ssusb_mtk *ssusb, int to_host)
 {
struct otg_switch_mtk *otg_sx = >otg_switch;
 
-   if (to_host)
-   pinctrl_select_state(otg_sx->id_pinctrl, otg_sx->id_ground);
-   else
-   pinctrl_select_state(otg_sx->id_pinctrl, otg_sx->id_float);
+   if (to_host) {
+   ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_HOST);
+   ssusb_set_mailbox(otg_sx, MTU3_VBUS_OFF);
+   ssusb_set_mailbox(otg_sx, MTU3_ID_GROUND);
+   } else {
+   ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_DEVICE);
+   ssusb_set_mailbox(otg_sx, MTU3_ID_FLOAT);
+   ssusb_set_mailbox(otg_sx, MTU3_VBUS_VALID);
+   }
 }
 
-
 static int ssusb_mode_show(struct seq_file *sf, void *unused)
 {
struct ssusb_mtk *ssusb = sf->private;
@@ -388,17 +389,45 @@ static void ssusb_debugfs_exit(struct ssusb_mtk *ssusb)
debugfs_remove_recursive(ssusb->dbgfs_root);
 }
 
+void ssusb_set_force_mode(struct ssusb_mtk *ssusb,
+ enum mtu3_dr_force_mode mode)
+{
+   u32 value;
+
+   value = mtu3_readl(ssusb->ippc_base, SSUSB_U2_CTRL(0));
+   switch (mode) {
+   case MTU3_DR_FORCE_DEVICE:
+   value |= SSUSB_U2_PORT_FORCE_IDDIG | SSUSB_U2_PORT_RG_IDDIG;
+   break;
+   case MTU3_DR_FORCE_HOST:
+   value |= SSUSB_U2_PORT_FORCE_IDDIG;
+   value &= ~SSUSB_U2_PORT_RG_IDDIG;
+   break;
+   case MTU3_DR_FORCE_NONE:
+   value &= ~(SSUSB_U2_PORT_FORCE_IDDIG | SSUSB_U2_PORT_RG_IDDIG);
+   break;
+   default:
+   return;
+   }
+   mtu3_writel(ssusb->ippc_base, SSUSB_U2_CTRL(0), value);
+}
+
 int ssusb_otg_switch_init(struct ssusb_mtk *ssusb)
 {
struct otg_switch_mtk *otg_sx = >otg_switch;
 
-   INIT_DELAYED_WORK(_sx->extcon_reg_dwork, extcon_register_dwork);
-
-   if (otg_sx->manual_drd_enabled)
+   if (otg_sx->manual_drd_enabled) {
ssusb_debugfs_init(ssusb);
-
-   /* It is enough to delay 1s for waiting for host initialization */
-   schedule_delayed_work(_sx->extcon_reg_dwork, HZ);
+   } else {
+   INIT_DELAYED_WORK(_sx->extcon_reg_dwork,
+  

[PATCH v2 07/13] usb: mtu3: add support for usb3.1 IP

2017-10-13 Thread Chunfeng Yun
Support SuperSpeedPlus for usb3.1 device IP

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3.h|1 +
 drivers/usb/mtu3/mtu3_core.c   |   14 +++---
 drivers/usb/mtu3/mtu3_gadget.c |3 ++-
 drivers/usb/mtu3/mtu3_gadget_ep0.c |   16 
 drivers/usb/mtu3/mtu3_hw_regs.h|1 +
 5 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index b0c2b5d..d80e4e8 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -94,6 +94,7 @@ enum mtu3_speed {
MTU3_SPEED_FULL = 1,
MTU3_SPEED_HIGH = 3,
MTU3_SPEED_SUPER = 4,
+   MTU3_SPEED_SUPER_PLUS = 5,
 };
 
 /**
diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c
index cd4528f..67f7a30 100644
--- a/drivers/usb/mtu3/mtu3_core.c
+++ b/drivers/usb/mtu3/mtu3_core.c
@@ -237,7 +237,7 @@ void mtu3_ep_stall_set(struct mtu3_ep *mep, bool set)
 
 void mtu3_dev_on_off(struct mtu3 *mtu, int is_on)
 {
-   if (mtu->is_u3_ip && (mtu->max_speed == USB_SPEED_SUPER))
+   if (mtu->is_u3_ip && mtu->max_speed >= USB_SPEED_SUPER)
mtu3_ss_func_set(mtu, is_on);
else
mtu3_hs_softconn_set(mtu, is_on);
@@ -547,6 +547,9 @@ static void mtu3_set_speed(struct mtu3 *mtu)
mtu3_clrbits(mbase, U3D_USB3_CONFIG, USB3_EN);
/* HS/FS detected by HW */
mtu3_setbits(mbase, U3D_POWER_MANAGEMENT, HS_ENABLE);
+   } else if (mtu->max_speed == USB_SPEED_SUPER) {
+   mtu3_clrbits(mtu->ippc_base, SSUSB_U3_CTRL(0),
+SSUSB_U3_PORT_SSP_SPEED);
}
 
dev_info(mtu->dev, "max_speed: %s\n",
@@ -624,6 +627,10 @@ static irqreturn_t mtu3_link_isr(struct mtu3 *mtu)
udev_speed = USB_SPEED_SUPER;
maxpkt = 512;
break;
+   case MTU3_SPEED_SUPER_PLUS:
+   udev_speed = USB_SPEED_SUPER_PLUS;
+   maxpkt = 512;
+   break;
default:
udev_speed = USB_SPEED_UNKNOWN;
break;
@@ -825,14 +832,15 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb)
case USB_SPEED_FULL:
case USB_SPEED_HIGH:
case USB_SPEED_SUPER:
+   case USB_SPEED_SUPER_PLUS:
break;
default:
dev_err(dev, "invalid max_speed: %s\n",
usb_speed_string(mtu->max_speed));
/* fall through */
case USB_SPEED_UNKNOWN:
-   /* default as SS */
-   mtu->max_speed = USB_SPEED_SUPER;
+   /* default as SSP */
+   mtu->max_speed = USB_SPEED_SUPER_PLUS;
break;
}
 
diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
index 434fca5..b495471 100644
--- a/drivers/usb/mtu3/mtu3_gadget.c
+++ b/drivers/usb/mtu3/mtu3_gadget.c
@@ -89,6 +89,7 @@ static int mtu3_ep_enable(struct mtu3_ep *mep)
 
switch (mtu->g.speed) {
case USB_SPEED_SUPER:
+   case USB_SPEED_SUPER_PLUS:
if (usb_endpoint_xfer_int(desc) ||
usb_endpoint_xfer_isoc(desc)) {
interval = desc->bInterval;
@@ -456,7 +457,7 @@ static int mtu3_gadget_wakeup(struct usb_gadget *gadget)
return  -EOPNOTSUPP;
 
spin_lock_irqsave(>lock, flags);
-   if (mtu->g.speed == USB_SPEED_SUPER) {
+   if (mtu->g.speed >= USB_SPEED_SUPER) {
mtu3_setbits(mtu->mac_base, U3D_LINK_POWER_CONTROL, UX_EXIT);
} else {
mtu3_setbits(mtu->mac_base, U3D_POWER_MANAGEMENT, RESUME);
diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c 
b/drivers/usb/mtu3/mtu3_gadget_ep0.c
index 958d74d..020b253 100644
--- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
+++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
@@ -212,8 +212,8 @@ static int ep0_set_sel(struct mtu3 *mtu, struct 
usb_ctrlrequest *setup)
case USB_RECIP_DEVICE:
result[0] = mtu->is_self_powered << USB_DEVICE_SELF_POWERED;
result[0] |= mtu->may_wakeup << USB_DEVICE_REMOTE_WAKEUP;
-   /* superspeed only */
-   if (mtu->g.speed == USB_SPEED_SUPER) {
+
+   if (mtu->g.speed >= USB_SPEED_SUPER) {
result[0] |= mtu->u1_enable << USB_DEV_STAT_U1_ENABLED;
result[0] |= mtu->u2_enable << USB_DEV_STAT_U2_ENABLED;
}
@@ -329,8 +329,8 @@ static int ep0_handle_feature_dev(struct mtu3 *mtu,
handled = handle_test_mode(mtu, setup);
break;
case USB_DEVICE_U1_ENABLE:
-   if (mtu->g.speed != USB_SPEED_SUPER ||
-   mtu->g.state != USB_STATE_CONFIGURED)
+   if (mtu->g.speed < USB_SPEED_SUPER ||
+   mtu->g.state != USB_STATE_CONFIGURED)
break;
 
lpc = mtu3_readl(mbase, 

[PATCH v2 10/13] usb: mtu3: set otg_sel for u2port only if works as dual-role mode

2017-10-13 Thread Chunfeng Yun
When set otg_sel(SSUSB_U2_PORT_OTG_SEL) for u2port which supports
dual-role mode, the controller will automatically switch mode
between host and device according to IDDIG signal. But if the
u2port only supports device mode, and no IDDIG pin is provided,
setting otg_sel may cause failure of detection by host.
So set it only for dual-role mode.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3_core.c |9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c
index 67f7a30..7c149a7 100644
--- a/drivers/usb/mtu3/mtu3_core.c
+++ b/drivers/usb/mtu3/mtu3_core.c
@@ -115,7 +115,9 @@ static int mtu3_device_enable(struct mtu3 *mtu)
mtu3_clrbits(ibase, SSUSB_U2_CTRL(0),
(SSUSB_U2_PORT_DIS | SSUSB_U2_PORT_PDN |
SSUSB_U2_PORT_HOST_SEL));
-   mtu3_setbits(ibase, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_OTG_SEL);
+
+   if (mtu->ssusb->dr_mode == USB_DR_MODE_OTG)
+   mtu3_setbits(ibase, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_OTG_SEL);
 
return ssusb_check_clocks(mtu->ssusb, check_clk);
 }
@@ -130,7 +132,10 @@ static void mtu3_device_disable(struct mtu3 *mtu)
 
mtu3_setbits(ibase, SSUSB_U2_CTRL(0),
SSUSB_U2_PORT_DIS | SSUSB_U2_PORT_PDN);
-   mtu3_clrbits(ibase, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_OTG_SEL);
+
+   if (mtu->ssusb->dr_mode == USB_DR_MODE_OTG)
+   mtu3_clrbits(ibase, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_OTG_SEL);
+
mtu3_setbits(ibase, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN);
 }
 
-- 
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 v2 13/13] dt-bindings: usb: mtu3: remove optional pinctrls

2017-10-13 Thread Chunfeng Yun
Remove optional pinctrls due to using FORCE/RG_IDDIG to implement
manual switch function.

Signed-off-by: Chunfeng Yun 
---
 .../devicetree/bindings/usb/mediatek,mtu3.txt  |7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
index 49c982b..b2271d8 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
@@ -30,9 +30,10 @@ Optional properties:
when supports dual-role mode.
  - vbus-supply : reference to the VBUS regulator, needed when supports
dual-role mode.
- - pinctl-names : a pinctrl state named "default" must be defined,
-   "id_float" and "id_ground" are optinal which depends on
-   "mediatek,enable-manual-drd"
+ - pinctrl-names : a pinctrl state named "default" is optional, and need be
+   defined if auto drd switch is enabled, that means the property dr_mode
+   is set as "otg", and meanwhile the property "mediatek,enable-manual-drd"
+   is not set.
  - pinctrl-0 : pin control group
See: Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt
 
-- 
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 v2 12/13] dt-bindings: usb: mtu3: remove dummy clocks and add optional ones

2017-10-13 Thread Chunfeng Yun
Remove dummy clocks for usb wakeup and add optional ones for
mcu_bus and dma_bus bus.

Signed-off-by: Chunfeng Yun 
---
 .../devicetree/bindings/usb/mediatek,mtu3.txt  |   10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
index 7c611d1..49c982b 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
@@ -14,9 +14,9 @@ Required properties:
  - vusb33-supply : regulator of USB avdd3.3v
  - clocks : a list of phandle + clock-specifier pairs, one for each
entry in clock-names
- - clock-names : must contain "sys_ck" and "ref_ck" for clock of controller;
-   "wakeup_deb_p0" and "wakeup_deb_p1" are optional, they are
-   depends on "mediatek,enable-wakeup"
+ - clock-names : must contain "sys_ck" for clock of controller,
+   the following clocks are optional:
+   "ref_ck", "mcu_ck" and "dam_ck";
  - phys : a list of phandle + phy specifier pairs
  - dr_mode : should be one of "host", "peripheral" or "otg",
refer to usb/generic.txt
@@ -65,9 +65,7 @@ ssusb: usb@11271000 {
clocks = < CLK_TOP_USB30_SEL>, <>,
 < CLK_PERI_USB0>,
 < CLK_PERI_USB1>;
-   clock-names = "sys_ck", "ref_ck",
- "wakeup_deb_p0",
- "wakeup_deb_p1";
+   clock-names = "sys_ck", "ref_ck";
vusb33-supply = <_vusb_reg>;
vbus-supply = <_p0_vbus>;
extcon = <_usb>;
-- 
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 v2 11/13] dt-bindings: usb: mtu3: add a optional property to disable u3ports

2017-10-13 Thread Chunfeng Yun
Add a new optional property to disable u3ports

Signed-off-by: Chunfeng Yun 
---
 .../devicetree/bindings/usb/mediatek,mtu3.txt  |2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
index 49f5476..7c611d1 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
@@ -44,6 +44,8 @@ Optional properties:
  - 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,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
+   bit1 for u3port1, ... etc;
 
 Sub-nodes:
 The xhci should be added as subnode to mtu3 as shown in the following example
-- 
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 v2 4/9] usb: xhci-mtk: support option to disable usb3 ports

2017-10-13 Thread Chunfeng Yun
Add support to disable specific usb3 ports, it's useful when
usb3 phy is shared with PCIe or SATA, because we should disable
the corresponding usb3 port if the phy is used by PCIe or SATA.
Sometimes it's helpful to analyse and solve problems.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/host/xhci-mtk.c |   18 +++---
 drivers/usb/host/xhci-mtk.h |1 +
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 7a92bb7..97ba51e 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -92,6 +92,7 @@ static int xhci_mtk_host_enable(struct xhci_hcd_mtk *mtk)
 {
struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs;
u32 value, check_val;
+   int u3_ports_disabed = 0;
int ret;
int i;
 
@@ -103,8 +104,13 @@ static int xhci_mtk_host_enable(struct xhci_hcd_mtk *mtk)
value &= ~CTRL1_IP_HOST_PDN;
writel(value, >ip_pw_ctr1);
 
-   /* power on and enable all u3 ports */
+   /* power on and enable u3 ports except skipped ones */
for (i = 0; i < mtk->num_u3_ports; i++) {
+   if ((0x1 << i) & mtk->u3p_dis_msk) {
+   u3_ports_disabed++;
+   continue;
+   }
+
value = readl(>u3_ctrl_p[i]);
value &= ~(CTRL_U3_PORT_PDN | CTRL_U3_PORT_DIS);
value |= CTRL_U3_PORT_HOST_SEL;
@@ -126,7 +132,7 @@ static int xhci_mtk_host_enable(struct xhci_hcd_mtk *mtk)
check_val = STS1_SYSPLL_STABLE | STS1_REF_RST |
STS1_SYS125_RST | STS1_XHCI_RST;
 
-   if (mtk->num_u3_ports)
+   if (mtk->num_u3_ports > u3_ports_disabed)
check_val |= STS1_U3_MAC_RST;
 
ret = readl_poll_timeout(>ip_pw_sts1, value,
@@ -149,8 +155,11 @@ static int xhci_mtk_host_disable(struct xhci_hcd_mtk *mtk)
if (!mtk->has_ippc)
return 0;
 
-   /* power down all u3 ports */
+   /* power down u3 ports except skipped ones */
for (i = 0; i < mtk->num_u3_ports; i++) {
+   if ((0x1 << i) & mtk->u3p_dis_msk)
+   continue;
+
value = readl(>u3_ctrl_p[i]);
value |= CTRL_U3_PORT_PDN;
writel(value, >u3_ctrl_p[i]);
@@ -573,6 +582,9 @@ static int xhci_mtk_probe(struct platform_device *pdev)
}
 
mtk->lpm_support = of_property_read_bool(node, "usb3-lpm-capable");
+   /* optional property, ignore the error if it does not exist */
+   of_property_read_u32(node, "mediatek,u3p-dis-msk",
+>u3p_dis_msk);
 
ret = usb_wakeup_of_property_parse(mtk, node);
if (ret)
diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h
index 3aa5e1d..db55a12 100644
--- a/drivers/usb/host/xhci-mtk.h
+++ b/drivers/usb/host/xhci-mtk.h
@@ -121,6 +121,7 @@ struct xhci_hcd_mtk {
bool has_ippc;
int num_u2_ports;
int num_u3_ports;
+   int u3p_dis_msk;
struct regulator *vusb33;
struct regulator *vbus;
struct clk *sys_clk;/* sys and mac clock */
-- 
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 v2 7/9] usb: host: modify description for MTK xHCI config

2017-10-13 Thread Chunfeng Yun
Due to all MediaTek SoCs with xHCI host controller use this
driver, remove limitation for specific SoCs

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/host/Kconfig |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index fa5692d..bc09a2e 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -45,12 +45,12 @@ config USB_XHCI_PLATFORM
  If unsure, say N.
 
 config USB_XHCI_MTK
-   tristate "xHCI support for Mediatek MT65xx/MT7621"
+   tristate "xHCI support for MediaTek SoCs"
select MFD_SYSCON
depends on (MIPS && SOC_MT7621) || ARCH_MEDIATEK || COMPILE_TEST
---help---
  Say 'Y' to enable the support for the xHCI host controller
- found in Mediatek MT65xx SoCs.
+ found in MediaTek SoCs.
  If unsure, say N.
 
 config USB_XHCI_MVEBU
-- 
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 v2 8/9] dt-bindings: usb: mtk-xhci: add a optional property to disable u3ports

2017-10-13 Thread Chunfeng Yun
Add a new optional property to disable u3ports

Signed-off-by: Chunfeng Yun 
---
 .../devicetree/bindings/usb/mediatek,mtk-xhci.txt  |2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
index 5611a2e..2d9b459 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
@@ -38,6 +38,8 @@ Optional properties:
mode;
  - mediatek,syscon-wakeup : phandle to syscon used to access USB wakeup
control register, it 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;
  - usb3-lpm-capable : supports USB3.0 LPM
  - pinctrl-names : a pinctrl state named "default" must be defined
-- 
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 v2 2/9] usb: xhci-mtk: use ports count from xhci in xhci_mtk_sch_init()

2017-10-13 Thread Chunfeng Yun
Make use of ports count from xhci but not from ippc in
xhci_mtk_sch_init()

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/host/xhci-mtk-sch.c |3 ++-
 drivers/usb/host/xhci-mtk.c |3 ---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
index 6e7ddf6..bfc51bc 100644
--- a/drivers/usb/host/xhci-mtk-sch.c
+++ b/drivers/usb/host/xhci-mtk-sch.c
@@ -287,12 +287,13 @@ static bool need_bw_sch(struct usb_host_endpoint *ep,
 
 int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk)
 {
+   struct xhci_hcd *xhci = hcd_to_xhci(mtk->hcd);
struct mu3h_sch_bw_info *sch_array;
int num_usb_bus;
int i;
 
/* ss IN and OUT are separated */
-   num_usb_bus = mtk->num_u3_ports * 2 + mtk->num_u2_ports;
+   num_usb_bus = xhci->num_usb3_ports * 2 + xhci->num_usb2_ports;
 
sch_array = kcalloc(num_usb_bus, sizeof(*sch_array), GFP_KERNEL);
if (sch_array == NULL)
diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index c197a6d..9502ca4 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -492,7 +492,6 @@ static void xhci_mtk_quirks(struct device *dev, struct 
xhci_hcd *xhci)
 /* called during probe() after chip reset completes */
 static int xhci_mtk_setup(struct usb_hcd *hcd)
 {
-   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
int ret;
 
@@ -507,8 +506,6 @@ static int xhci_mtk_setup(struct usb_hcd *hcd)
return ret;
 
if (usb_hcd_is_primary_hcd(hcd)) {
-   mtk->num_u3_ports = xhci->num_usb3_ports;
-   mtk->num_u2_ports = xhci->num_usb2_ports;
ret = xhci_mtk_sch_init(mtk);
if (ret)
return ret;
-- 
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 v2 9/9] dt-bindings: usb: mtk-xhci: remove dummy clocks and add optional ones

2017-10-13 Thread Chunfeng Yun
Remove dummy clocks for usb wakeup and add optional ones for
MCU_BUS_CK and DMA_BUS_CK.

Signed-off-by: Chunfeng Yun 
Acked-by: Rob Herring 
---
 .../devicetree/bindings/usb/mediatek,mtk-xhci.txt  |   18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
index 2d9b459..3059596 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
@@ -26,10 +26,11 @@ Required properties:
  - clocks : a list of phandle + clock-specifier pairs, one for each
entry in clock-names
  - clock-names : must contain
-   "sys_ck": for clock of xHCI MAC
-   "ref_ck": for reference clock of xHCI MAC
-   "wakeup_deb_p0": for USB wakeup debounce clock of port0
-   "wakeup_deb_p1": for USB wakeup debounce clock of port1
+   "sys_ck": controller clock used by normal mode,
+   the following ones are optional:
+   "ref_ck": reference clock used by low power mode etc,
+   "mcu_ck": mcu_bus clock for register access,
+   "dma_ck": dma_bus clock for data transfer by DMA
 
  - phys : a list of phandle + phy specifier pairs
 
@@ -57,9 +58,7 @@ usb30: usb@1127 {
clocks = < CLK_TOP_USB30_SEL>, <>,
 < CLK_PERI_USB0>,
 < CLK_PERI_USB1>;
-   clock-names = "sys_ck", "ref_ck",
- "wakeup_deb_p0",
- "wakeup_deb_p1";
+   clock-names = "sys_ck", "ref_ck";
phys = <_port0 PHY_TYPE_USB3>,
   <_port1 PHY_TYPE_USB2>;
vusb33-supply = <_vusb_reg>;
@@ -91,9 +90,8 @@ Required properties:
 
  - clocks : a list of phandle + clock-specifier pairs, one for each
entry in clock-names
- - clock-names : must be
-   "sys_ck": for clock of xHCI MAC
-   "ref_ck": for reference clock of xHCI MAC
+ - clock-names : must contain "sys_ck", and the following ones are optional:
+   "ref_ck", "mcu_ck" and "dma_ck"
 
 Optional properties:
  - vbus-supply : reference to the VBUS regulator;
-- 
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 v2 3/9] usb: xhci-mtk: check clock stability of U3_MAC

2017-10-13 Thread Chunfeng Yun
This is useful to find out the root cause when the Super Speed doesn't
work. Such as when the T-PHY is switched to PCIe or SATA, and affects
Super Speed function, the check will fail.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/host/xhci-mtk.c |4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 9502ca4..7a92bb7 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -43,6 +43,7 @@
 
 /* ip_pw_sts1 register */
 #define STS1_IP_SLEEP_STS  BIT(30)
+#define STS1_U3_MAC_RSTBIT(16)
 #define STS1_XHCI_RST  BIT(11)
 #define STS1_SYS125_RSTBIT(10)
 #define STS1_REF_RST   BIT(8)
@@ -125,6 +126,9 @@ static int xhci_mtk_host_enable(struct xhci_hcd_mtk *mtk)
check_val = STS1_SYSPLL_STABLE | STS1_REF_RST |
STS1_SYS125_RST | STS1_XHCI_RST;
 
+   if (mtk->num_u3_ports)
+   check_val |= STS1_U3_MAC_RST;
+
ret = readl_poll_timeout(>ip_pw_sts1, value,
  (check_val == (value & check_val)), 100, 2);
if (ret) {
-- 
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 v2 5/9] usb: xhci-mtk: remove dummy wakeup debounce clocks

2017-10-13 Thread Chunfeng Yun
The wakeup debounce clocks for each ports in fact are not
needed, so remove them.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/host/xhci-mtk.c |   33 -
 drivers/usb/host/xhci-mtk.h |2 --
 2 files changed, 35 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 97ba51e..d60463c 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -237,25 +237,8 @@ static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
goto sys_clk_err;
}
 
-   if (mtk->wakeup_src) {
-   ret = clk_prepare_enable(mtk->wk_deb_p0);
-   if (ret) {
-   dev_err(mtk->dev, "failed to enable wk_deb_p0\n");
-   goto usb_p0_err;
-   }
-
-   ret = clk_prepare_enable(mtk->wk_deb_p1);
-   if (ret) {
-   dev_err(mtk->dev, "failed to enable wk_deb_p1\n");
-   goto usb_p1_err;
-   }
-   }
return 0;
 
-usb_p1_err:
-   clk_disable_unprepare(mtk->wk_deb_p0);
-usb_p0_err:
-   clk_disable_unprepare(mtk->sys_clk);
 sys_clk_err:
clk_disable_unprepare(mtk->ref_clk);
 ref_clk_err:
@@ -264,10 +247,6 @@ static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
 
 static void xhci_mtk_clks_disable(struct xhci_hcd_mtk *mtk)
 {
-   if (mtk->wakeup_src) {
-   clk_disable_unprepare(mtk->wk_deb_p1);
-   clk_disable_unprepare(mtk->wk_deb_p0);
-   }
clk_disable_unprepare(mtk->sys_clk);
clk_disable_unprepare(mtk->ref_clk);
 }
@@ -371,18 +350,6 @@ static int usb_wakeup_of_property_parse(struct 
xhci_hcd_mtk *mtk,
if (!mtk->wakeup_src)
return 0;
 
-   mtk->wk_deb_p0 = devm_clk_get(dev, "wakeup_deb_p0");
-   if (IS_ERR(mtk->wk_deb_p0)) {
-   dev_err(dev, "fail to get wakeup_deb_p0\n");
-   return PTR_ERR(mtk->wk_deb_p0);
-   }
-
-   mtk->wk_deb_p1 = devm_clk_get(dev, "wakeup_deb_p1");
-   if (IS_ERR(mtk->wk_deb_p1)) {
-   dev_err(dev, "fail to get wakeup_deb_p1\n");
-   return PTR_ERR(mtk->wk_deb_p1);
-   }
-
mtk->pericfg = syscon_regmap_lookup_by_phandle(dn,
"mediatek,syscon-wakeup");
if (IS_ERR(mtk->pericfg)) {
diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h
index db55a12..67783a7 100644
--- a/drivers/usb/host/xhci-mtk.h
+++ b/drivers/usb/host/xhci-mtk.h
@@ -126,8 +126,6 @@ struct xhci_hcd_mtk {
struct regulator *vbus;
struct clk *sys_clk;/* sys and mac clock */
struct clk *ref_clk;
-   struct clk *wk_deb_p0;  /* port0's wakeup debounce clock */
-   struct clk *wk_deb_p1;
struct regmap *pericfg;
struct phy **phys;
int num_phys;
-- 
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 v2 6/9] usb: xhci-mtk: add optional mcu and dma bus clocks

2017-10-13 Thread Chunfeng Yun
There are mcu_bus and dma_bus clocks needed to be controlled by
driver on some SoCs, so add them as optional ones

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/host/xhci-mtk.c |   79 ---
 drivers/usb/host/xhci-mtk.h |2 ++
 2 files changed, 62 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index d60463c..e5caabe 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -221,6 +221,44 @@ static int xhci_mtk_ssusb_config(struct xhci_hcd_mtk *mtk)
return xhci_mtk_host_enable(mtk);
 }
 
+/* ignore the error if the clock does not exist */
+static struct clk *optional_clk_get(struct device *dev, const char *id)
+{
+   struct clk *opt_clk;
+
+   opt_clk = devm_clk_get(dev, id);
+   /* ignore error number except EPROBE_DEFER */
+   if (IS_ERR(opt_clk) && (PTR_ERR(opt_clk) != -EPROBE_DEFER))
+   opt_clk = NULL;
+
+   return opt_clk;
+}
+
+static int xhci_mtk_clks_get(struct xhci_hcd_mtk *mtk)
+{
+   struct device *dev = mtk->dev;
+
+   mtk->sys_clk = devm_clk_get(dev, "sys_ck");
+   if (IS_ERR(mtk->sys_clk)) {
+   dev_err(dev, "fail to get sys_ck\n");
+   return PTR_ERR(mtk->sys_clk);
+   }
+
+   mtk->ref_clk = optional_clk_get(dev, "ref_ck");
+   if (IS_ERR(mtk->ref_clk))
+   return PTR_ERR(mtk->ref_clk);
+
+   mtk->mcu_clk = optional_clk_get(dev, "mcu_ck");
+   if (IS_ERR(mtk->mcu_clk))
+   return PTR_ERR(mtk->mcu_clk);
+
+   mtk->dma_clk = optional_clk_get(dev, "dma_ck");
+   if (IS_ERR(mtk->dma_clk))
+   return PTR_ERR(mtk->dma_clk);
+
+   return 0;
+}
+
 static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
 {
int ret;
@@ -237,16 +275,34 @@ static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
goto sys_clk_err;
}
 
+   ret = clk_prepare_enable(mtk->mcu_clk);
+   if (ret) {
+   dev_err(mtk->dev, "failed to enable mcu_clk\n");
+   goto mcu_clk_err;
+   }
+
+   ret = clk_prepare_enable(mtk->dma_clk);
+   if (ret) {
+   dev_err(mtk->dev, "failed to enable dma_clk\n");
+   goto dma_clk_err;
+   }
+
return 0;
 
+dma_clk_err:
+   clk_disable_unprepare(mtk->mcu_clk);
+mcu_clk_err:
+   clk_disable_unprepare(mtk->sys_clk);
 sys_clk_err:
clk_disable_unprepare(mtk->ref_clk);
 ref_clk_err:
-   return -EINVAL;
+   return ret;
 }
 
 static void xhci_mtk_clks_disable(struct xhci_hcd_mtk *mtk)
 {
+   clk_disable_unprepare(mtk->dma_clk);
+   clk_disable_unprepare(mtk->mcu_clk);
clk_disable_unprepare(mtk->sys_clk);
clk_disable_unprepare(mtk->ref_clk);
 }
@@ -529,24 +585,9 @@ static int xhci_mtk_probe(struct platform_device *pdev)
return PTR_ERR(mtk->vusb33);
}
 
-   mtk->sys_clk = devm_clk_get(dev, "sys_ck");
-   if (IS_ERR(mtk->sys_clk)) {
-   dev_err(dev, "fail to get sys_ck\n");
-   return PTR_ERR(mtk->sys_clk);
-   }
-
-   /*
-* reference clock is usually a "fixed-clock", make it optional
-* for backward compatibility and ignore the error if it does
-* not exist.
-*/
-   mtk->ref_clk = devm_clk_get(dev, "ref_ck");
-   if (IS_ERR(mtk->ref_clk)) {
-   if (PTR_ERR(mtk->ref_clk) == -EPROBE_DEFER)
-   return -EPROBE_DEFER;
-
-   mtk->ref_clk = NULL;
-   }
+   ret = xhci_mtk_clks_get(mtk);
+   if (ret)
+   return ret;
 
mtk->lpm_support = of_property_read_bool(node, "usb3-lpm-capable");
/* optional property, ignore the error if it does not exist */
diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h
index 67783a7..45ff5c6 100644
--- a/drivers/usb/host/xhci-mtk.h
+++ b/drivers/usb/host/xhci-mtk.h
@@ -126,6 +126,8 @@ struct xhci_hcd_mtk {
struct regulator *vbus;
struct clk *sys_clk;/* sys and mac clock */
struct clk *ref_clk;
+   struct clk *mcu_clk;
+   struct clk *dma_clk;
struct regmap *pericfg;
struct phy **phys;
int num_phys;
-- 
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 v2 1/9] usb: xhci-mtk: use dma_set_mask_and_coherent() in probe function

2017-10-13 Thread Chunfeng Yun
This patch uses the simpler dma_set_mask_and_coherent() instead of
doing these as separate steps

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/host/xhci-mtk.c |7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 8fb6065..c197a6d 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -606,15 +606,10 @@ static int xhci_mtk_probe(struct platform_device *pdev)
}
 
/* Initialize dma_mask and coherent_dma_mask to 32-bits */
-   ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
+   ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
if (ret)
goto disable_clk;
 
-   if (!dev->dma_mask)
-   dev->dma_mask = >coherent_dma_mask;
-   else
-   dma_set_mask(dev, DMA_BIT_MASK(32));
-
hcd = usb_create_hcd(driver, dev, dev_name(dev));
if (!hcd) {
ret = -ENOMEM;
-- 
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


Re: [PATCH] xhci: Set DMA parameters appropriately

2017-10-13 Thread Marek Szyprowski

Hi Robin,

On 2017-10-11 15:56, Robin Murphy wrote:

xHCI requires that data buffers do not cross 64KB boundaries (and are
thus at most 64KB long as well) - whilst xhci_queue_{bulk,isoc}_tx()
already split their input buffers into individual TRBs as necessary,
it's still a good idea to advertise the limitations via the standard DMA
API mechanism, so that most producers like the block layer and the DMA
mapping implementations can lay things out correctly to begin with.

Signed-off-by: Robin Murphy 
---
  drivers/usb/host/xhci.c | 4 
  drivers/usb/host/xhci.h | 3 +++
  2 files changed, 7 insertions(+)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 74b4500641c2..1e7e1e3d8c48 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4883,6 +4883,10 @@ int xhci_gen_setup(struct usb_hcd *hcd, 
xhci_get_quirks_t get_quirks)
dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
}
  
+	dev->dma_parms = >dma_parms;

+   dma_set_max_seg_size(dev, SZ_64K);
+   dma_set_seg_boundary(dev, SZ_64K - 1);
+
xhci_dbg(xhci, "Calling HCD init\n");
/* Initialize HCD and host controller data structures. */
retval = xhci_init(hcd);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 7ef69ea0b480..afcae4cc908d 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1767,6 +1767,9 @@ struct xhci_hcd {
struct dma_pool *small_streams_pool;
struct dma_pool *medium_streams_pool;
  
+	/* DMA alignment restrictions */

+   struct device_dma_parameters dma_parms;
+
/* Host controller watchdog timer structures */
unsigned intxhc_state;
  


Are you sure that xhci_hcd life time is proper to keep dma_parms? It looks
that when driver gets removed and xhci_hcd is freed, the dma_parms will
point to freed memory. Maybe it would make sense to clear dev->dma_parms
somewhere or definitely change the way dma_parms are allocated?

On the other hand 64K is the default segment size if no dma_parms are
provided, so there is very little value added by this patch.

Best regards
--
Marek Szyprowski, PhD
Samsung R Institute Poland

--
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: serial: drop unused core USB driver

2017-10-13 Thread Johan Hovold
On Thu, Oct 12, 2017 at 05:48:19PM +0200, Greg Kroah-Hartman wrote:
> On Thu, Oct 12, 2017 at 05:22:28PM +0200, Johan Hovold wrote:
> > Drop the usb-serial-core USB driver that was registered at module init
> > but then never used.
> > 
> > This was a remnant dating back to 2004 (!) when this struct usb_driver
> > was used for the generic driver; see commit bbc53b7d7322 ("USB: fix bug
> > where removing usb-serial modules or usb serial devices could oops") in
> > the tglx bitkeeper-history archive.
> 
> Wow that's old, sorry about forgetting this could be removed.  Nice
> cleanup.

Heh, I'm just amazed that I haven't noticed this sooner.

> Reviewed-by: Greg Kroah-Hartman 

Thanks for reviewing. Applied for -next.

Johan
--
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] USB: serial: metro-usb: stop I/O after failed open

2017-10-13 Thread Johan Hovold
On Thu, Oct 12, 2017 at 11:34:52AM +0200, Greg Kroah-Hartman wrote:
> On Thu, Oct 12, 2017 at 10:54:21AM +0200, Johan Hovold wrote:
> > Make sure to kill the interrupt-in URB after a failed open request.
> > Apart from saving power (and avoiding stale input after a later
> > successful open), this also prevents a NULL-deref in the completion
> > handler if the port is manually unbound.
> > 
> > Signed-off-by: Johan Hovold 
> > ---
> >  drivers/usb/serial/metro-usb.c | 11 ---
> >  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> Reviewed-by: Greg Kroah-Hartman 

Thanks for the review, all three now applied.

I guess this one should go to stable, so I added the following:

Fixes: 704577861d5e ("USB: serial: metro-usb: get data from device in 
Uni-Directional mode.")
Cc: stable  # 3.5

Johan
--
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 v5 1/3] dt-bindings: usb: add the documentation for USB root-hub

2017-10-13 Thread Arnd Bergmann
On Thu, Oct 12, 2017 at 10:56 PM, Martin Blumenstingl
 wrote:
> Hi Arnd,
>
> thank you for reviewing this patch!
>
> On Mon, Oct 9, 2017 at 12:24 PM, Arnd Bergmann  wrote:
>> On Sun, Oct 8, 2017 at 11:17 PM, Martin Blumenstingl
>>  wrote:
>>> A USB root-hub may have several PHYs which need to be configured before
>>> the root-hub starts working.
>>> This adds the documentation for such a USB root-hub as well as a hint
>>> regarding the child-nodes on XHCI controllers which can include the
>>> roothub.
>>>
>>> Signed-off-by: Martin Blumenstingl 
>>> Acked-by: Rob Herring 
>>
>> Have you checked that this still works with DT properties on a USB device
>> that is listed in the DT? A common use-case is to provide the MAC address
>> of a soldered-down USB-ethernet that lacks its own eeprom, and it seems
>> you are changing the way the parent devices of that get represented,
>> so the dev->of_node pointer in the USB device might no longer refer
>> to the correct device.
> I haven't tested the described use-case. however, this patch is not
> supposed to change the binding for actual devices.
> USB device numbering starts at 1, while 0 is reserved for the root-hub
> (at least from what I know). before this patch there was no way to
> describe the root-hub via .dts. this however is required for some
> platforms that need to set up a PHY for each port on the root-hub
> (Amlogic Meson GXL platform is one example: there are two ports
> enabled on dwc3's root-hub with 2x USB2 and 1x USB3 PHYs) - so this
> patch uses a similar binding as we already have (to describe the
> devices) to describe the root-hub

My point is that the DT binding does depend on the hierarchy, there
is no way to find a particular device unless each parent up the
chain is described correctly in DT as well and has a valid of_node
pointer.

It's possible that this has never worked on XHCI because of the lack
of the root-hub in DT. Either way, we should ensure that it does work
now and you didn't break it, so please at least test it with your patches.

The patch below should be sufficient to see if any device has an
of_node pointer when you add it to your DT:

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 17681d5638ac..498d0aa0a5c0 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -647,6 +647,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
}
dev->dev.of_node = usb_of_get_child_node(parent->dev.of_node,
raw_port);
+   dev_info(>dev, "of_node %p parent %p\n",
dev->dev.of_node, parent->dev.of_node);

/* hub driver sets up TT records */
}


   Arnd
--
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/1] usb: Apply hardware LPM attributes to 3.1 device

2017-10-13 Thread Lu Baolu
The devices running at SuperSpeedPlus speed are also LPM capable.
Apply usb3 hardware LPM attributes to those devices as well.

Signed-off-by: Lu Baolu 
---
 drivers/usb/core/sysfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index d930bfd..fa5d47d 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -654,7 +654,8 @@ static int add_power_attributes(struct device *dev)
if (udev->usb2_hw_lpm_capable == 1)
rc = sysfs_merge_group(>kobj,
_hardware_lpm_attr_group);
-   if (udev->speed == USB_SPEED_SUPER &&
+   if ((udev->speed == USB_SPEED_SUPER ||
+udev->speed == USB_SPEED_SUPER_PLUS) &&
udev->lpm_capable == 1)
rc = sysfs_merge_group(>kobj,
_hardware_lpm_attr_group);
-- 
2.7.4

--
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