Re: [PATCH 1/3] usb: phy: Add RCAR Gen2 USB phy

2013-10-07 Thread Valentine

On 10/08/2013 03:27 AM, Valentine Barshak wrote:

This adds RCAR Gen2 USB phy support. The driver configures
USB channels 0/2, which are shared between PCI USB hosts and
USBHS/USBSS devices. It also controls internal USBHS phy.


[snip]


diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c 
b/drivers/usb/phy/phy-rcar-gen2-usb.c
new file mode 100644
index 000..b7b2102
--- /dev/null
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -0,0 +1,271 @@


[snip]


+
+/* Low Power Status register */
+#define USBHS_LPSTS_REG0x02
+#define USBHS_LPSTS_SUSPM  (1 << 14)
+
+/* USB General control register */
+#define USBHS_UGCTRL_REG   0x80
+#define USBHS_UGCTRL_CONNECT   (1 << 2)
+#define USBHS_UGCTRL_PLLRESET  (1 << 0)
+
+/* USB General control register 2 */
+#define USBHS_UGCTRL2_REG  0x84
+#define USBHS_UGCTRL2_USB0_PCI (1 << 4)
+#define USBHS_UGCTRL2_USB0_HS  (3 << 4)
+#define USBHS_UGCTRL2_USB2_PCI (0 << 31)
+#define USBHS_UGCTRL2_USB2_SS  (1 << 31)
+
+/* USB General status register */
+#define USBHS_UGSTS_REG0x88
+#define USBHS_UGSTS_LOCK   (3 << 8)
+


Please, note that the latest H2/M2 hardware manuals have the USB General 
status register (UGSTS) at offset 0x190.


(The PHY driver uses offsets relative to USBHS base + 0x100)

The PLL LOCK is supposed to be in bits 0-1 of the UGSTS register.
However, I've found that this is not correct, and the value read
from 0x190 offset is always 0.

The PLL LOCK status is actually read from bits 8-9 at the offset
of 0x188.

So when UTMI is suspended, the value read from 0x188 is 0x0.
When PLL is taken out of reset and normal UTMI mode is selected in
the LPSTS register, the register at 0x188 reads 0x300.

Thanks,
Val.
--
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: phy: Add RCAR Gen2 USB phy

2013-10-08 Thread Valentine

On 10/08/2013 07:27 AM, Kuninori Morimoto wrote:


Hi Valentine


Hi Morimoto-san,



Thank you for your patch


Thanks for looking at it.




+/* Setup USB channels */
+static void __rcar_gen2_usb_phy_setup(struct rcar_gen2_usb_phy_priv *priv)
+{
+   u32 val;
+
+   clk_prepare_enable(priv->clk);
+
+   /* Set USB channels in the USBHS UGCTRL2 register */
+   val = ioread32(priv->base);
+   val &= ~(USBHS_UGCTRL2_USB0_HS | USBHS_UGCTRL2_USB2_SS);
+   val |= priv->ugctrl2;
+   iowrite32(val, priv->base);
+}


 From my point of view, if you use clk_enable() on setup(),
then, it is easy to read if it has exit() or similar name function
which calls clk_disable()


Since in this case all is needed is to disable the clocks, I've decided 
not to put it in a separate exit function. I'll add one for better 
readability.





+static int rcar_gen2_usb_phy_set_suspend(struct usb_phy *phy, int suspend)
+{
+   struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy);
+   unsigned long flags;
+   int retval;
+
+   spin_lock_irqsave(&priv->lock, flags);
+   if (suspend) {
+   /* Suspend USBHS internal phy */
+   retval = __rcar_gen2_usbhs_phy_disable(priv->base);
+   /*
+* If nothing else is using USB channel 0/2
+* disable the clocks as well
+*/
+   if (priv->usecount == 1) {
+   clk_disable_unprepare(priv->clk);
+   priv->usecount--;
+   }
+   } else {
+   /*
+* Enable the clock and setup USB channels
+* if needed.
+*/
+   if (!priv->usecount) {
+   priv->usecount++;
+   __rcar_gen2_usb_phy_setup(priv);
+   }
+   /* Resume USBHS internal phy */
+   retval = __rcar_gen2_usbhs_phy_enable(priv->base);
+   }


Are these usecount++/usecount-- position correct ?


The idea was to disable the clocks here if the phy is not used by other 
drivers (PCI USB host or USBSS), so that suspending the gadget would 
disable USBHS clocks. However, this needs phy enabled before the 
shutdown is called. I guess I'll drop the clock handling here and leave 
it solely to init/shutdown callbacks.





+static int rcar_gen2_usb_phy_probe(struct platform_device *pdev)
+{
+   struct device *dev = &pdev->dev;
+   struct rcar_gen2_phy_platform_data *pdata;
+   struct rcar_gen2_usb_phy_priv *priv;
+   struct resource *res;
+   void __iomem *base;
+   struct clk *clk;
+   int retval;
+
+   pdata = dev_get_platdata(&pdev->dev);
+   if (!pdata) {
+   dev_err(dev, "No platform data\n");
+   return -EINVAL;
+   }
+
+   clk = devm_clk_get(&pdev->dev, "usbhs");
+   if (IS_ERR(clk)) {
+   dev_err(&pdev->dev, "Can't get the clock\n");
+   return PTR_ERR(clk);
+   }


This case (if you use usb_phy_rcar_gen2 driver),
you can use pm_runtime_xxx instead of clk_get/enable/disable()



Yes, I could. The reason I did not is that I'm not sure that a phy 
driver should use runtime PM, since it is actually mastered by other 
drivers which are supposed to control its power via init/shutdown and 
set_suspend callbacks. Thus, looks like the phy driver can't really 
auto-suspend and doesn't really support runtime PM.


I think that handling clocks in the init/shutdown is a bit cleaner.
It gives us more control over the phy power, where pm_runtime_xxx will 
do nothing if CONFIG_PM_RUNTIME is disabled.


Thanks,
Val.
--
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 3/3] arm: shmobile: lager: Add USBHS support

2013-10-08 Thread Valentine

On 10/08/2013 07:31 AM, Kuninori Morimoto wrote:


Hi Valentine


This adds USBHS PHY and registers USBHS device if the driver is enabled.

Signed-off-by: Valentine Barshak 
---

(snip)

+/* USBHS */
+#if IS_ENABLED(CONFIG_USB_RENESAS_USBHS_UDC)
+static const struct resource usbhs_resources[] __initconst = {
+   DEFINE_RES_MEM(0xe659, 0x100),
+   DEFINE_RES_IRQ(gic_spi(107)),
+};


Why it needs #if IS_ENABLED() ?
I guess nothing happen if renesas_usbhs driver
registered without CONFIG_USB_RENESAS_USBHS_UDC.
But am I misunderstanding ?



Since USB channel 0 is shared between PCI USB host and USBHS
we'll still need it later to properly configure the channel.
Besides, is saves us some bits leaving all the unused callbacks and 
device structures out if we do not register the device when the driver 
is disabled.


Thanks,
Val.
--
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: phy: Add RCAR Gen2 USB phy

2013-10-09 Thread Valentine

On 10/10/2013 12:32 AM, Laurent Pinchart wrote:

Hi Valentine,



Hi Laurent,


Thank you for the patch.

On Tuesday 08 October 2013 23:43:25 Valentine Barshak wrote:

This adds RCAR Gen2 USB phy support. The driver configures
USB channels 0/2 which are shared between PCI USB hosts and
USBHS/USBSS devices. It also controls internal USBHS phy.

Signed-off-by: Valentine Barshak 
---
  drivers/usb/phy/Kconfig |  13 ++
  drivers/usb/phy/Makefile|   1 +
  drivers/usb/phy/phy-rcar-gen2-usb.c | 255 +
  include/linux/platform_data/usb-rcar-gen2-phy.h |  22 ++
  4 files changed, 291 insertions(+)
  create mode 100644 drivers/usb/phy/phy-rcar-gen2-usb.c
  create mode 100644 include/linux/platform_data/usb-rcar-gen2-phy.h

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index d5589f9..297062c 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -214,6 +214,19 @@ config USB_RCAR_PHY
  To compile this driver as a module, choose M here: the
  module will be called phy-rcar-usb.

+config USB_RCAR_GEN2_PHY
+   tristate "Renesas R-Car Gen2 USB PHY support"
+   depends on ARCH_R8A7790 || ARCH_R8A7791


 From a development point of view it's always nice to be able to compile the
driver for a wider range of devices, even if the device is only found in the
R8A779[01]. This allows catching compilation errors, for instance caused by
API changes that affect all drivers using the API being modified.


Compiling a dirver for an unsupported architecture also seems to be more 
error-prone.




I would use either

depends on ARM

or

depends on ARCH_R8A7790 || ARCH_R8A7791 || COMPILE_TEST

(assuming the driver can compile on non-ARM platforms, otherwise the above
line could be changed to ARCH_R8A7790 || ARCH_R8A7791 || (ARM &&
COMPILE_TEST)).


OK, I'll take a look.
Do all the drivers have to support COMPILE_TEST?




+   select USB_PHY
+   help
+ Say Y here to add support for the Renesas R-Car Gen2 USB PHY driver.
+ It is typically used to control internal USB PHY for USBHS,
+ and to configure shared USB channels 0 and 2.
+ This driver supports R8A7790 and R8A7791.
+
+ To compile this driver as a module, choose M here: the
+ module will be called phy-rcar-gen2-usb.
+
  config USB_ULPI
bool "Generic ULPI Transceiver Driver"
depends on ARM
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 2135e85..8c5b147 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -29,5 +29,6 @@ obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o
  obj-$(CONFIG_USB_MV_OTG)  += phy-mv-usb.o
  obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o
  obj-$(CONFIG_USB_RCAR_PHY)+= phy-rcar-usb.o
+obj-$(CONFIG_USB_RCAR_GEN2_PHY)+= phy-rcar-gen2-usb.o
  obj-$(CONFIG_USB_ULPI)+= phy-ulpi.o
  obj-$(CONFIG_USB_ULPI_VIEWPORT)   += phy-ulpi-viewport.o
diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c
b/drivers/usb/phy/phy-rcar-gen2-usb.c new file mode 100644
index 000..a2e6f9f
--- /dev/null
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -0,0 +1,255 @@
+/*
+ * Renesas R-Car Gen2 USB phy driver
+ *
+ * Copyright (C) 2013 Renesas Solutions Corp.
+ * Copyright (C) 2013 Cogent Embedded, Inc.
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 


Would you mind ordering the headers alphabetically ? This helps avoiding
duplicate includes, an existing include might not be noticed at first glance
when adding a new one if the list is long and not sorted.


OK.




+struct rcar_gen2_usb_phy_priv {
+   struct usb_phy phy;
+   void __iomem *base;
+   struct clk *clk;
+   spinlock_t lock;
+   int usecount;
+   u32 ugctrl2;
+};
+
+#define usb_phy_to_priv(p) container_of(p, struct rcar_gen2_usb_phy_priv,
phy) +
+/* Low Power Status register */
+#define USBHS_LPSTS_REG0x02
+#define USBHS_LPSTS_SUSPM  (1 << 14)
+
+/* USB General control register */
+#define USBHS_UGCTRL_REG   0x80
+#define USBHS_UGCTRL_CONNECT   (1 << 2)
+#define USBHS_UGCTRL_PLLRESET  (1 << 0)
+
+/* USB General control register 2 */
+#define USBHS_UGCTRL2_REG  0x84
+#define USBHS_UGCTRL2_USB0_PCI (1 << 4)
+#define USBHS_UGCTRL2_USB0_HS  (3 << 4)
+#define USBHS_UGCTRL2_USB2_PCI (0 << 31)
+#define USBHS_UGCTRL2_USB2_SS  (1 << 31)
+
+/* USB General status register */
+#define USBHS_UGSTS_REG0x88
+#define USBHS_

Re: [PATCH 1/3] usb: phy: Add RCAR Gen2 USB phy

2013-10-09 Thread Valentine

On 10/10/2013 01:28 AM, Laurent Pinchart wrote:

Hi Valentine,

On Thursday 10 October 2013 01:21:27 Valentine wrote:

On 10/10/2013 12:32 AM, Laurent Pinchart wrote:

Hi Valentine,


Hi Laurent,


Thank you for the patch.

On Tuesday 08 October 2013 23:43:25 Valentine Barshak wrote:

This adds RCAR Gen2 USB phy support. The driver configures
USB channels 0/2 which are shared between PCI USB hosts and
USBHS/USBSS devices. It also controls internal USBHS phy.

Signed-off-by: Valentine Barshak 
---

   drivers/usb/phy/Kconfig |  13 ++
   drivers/usb/phy/Makefile|   1 +
   drivers/usb/phy/phy-rcar-gen2-usb.c | 255 +
   include/linux/platform_data/usb-rcar-gen2-phy.h |  22 ++
   4 files changed, 291 insertions(+)
   create mode 100644 drivers/usb/phy/phy-rcar-gen2-usb.c
   create mode 100644 include/linux/platform_data/usb-rcar-gen2-phy.h

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index d5589f9..297062c 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -214,6 +214,19 @@ config USB_RCAR_PHY
  To compile this driver as a module, choose M here: the
  module will be called phy-rcar-usb.

+config USB_RCAR_GEN2_PHY
+   tristate "Renesas R-Car Gen2 USB PHY support"
+   depends on ARCH_R8A7790 || ARCH_R8A7791


 From a development point of view it's always nice to be able to compile
the driver for a wider range of devices, even if the device is only found
in the R8A779[01]. This allows catching compilation errors, for instance
caused by API changes that affect all drivers using the API being
modified.


Compiling a dirver for an unsupported architecture also seems to be more
error-prone.


It happened to me previously that a subsystem refactoring touching lots of
drivers forgot to update one of the drivers I was maintaining. This went
undetected as the driver could only be compiled for a very restricted set of
platforms, breaking compilation in mainline. It's easier to avoid this kind of
situation if the driver can be compiled for a larger number of platforms.


I would use either

depends on ARM

or

depends on ARCH_R8A7790 || ARCH_R8A7791 || COMPILE_TEST

(assuming the driver can compile on non-ARM platforms, otherwise the above
line could be changed to ARCH_R8A7790 || ARCH_R8A7791 || (ARM &&
COMPILE_TEST)).


OK, I'll take a look.
Do all the drivers have to support COMPILE_TEST?


There's currently no rule, but if the driver can only be compiled for a
restricted set of platforms, I would say that supporting COMPILE_TEST would be
a good practice. It of course needs to be restricted to the platforms on which
the driver will actually compile :-)


OK thanks.
I'll probably go with the safest option:
ARCH_R8A7790 || ARCH_R8A7791 || (ARM && COMPILE_TEST)

It does compile on x86 though, and may compile on other platforms as well.

Thanks,
Val.

--
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: phy: Add RCAR Gen2 USB phy

2013-10-10 Thread Valentine

On 10/10/2013 07:23 PM, Felipe Balbi wrote:

Hi,

On Thu, Oct 10, 2013 at 02:14:45AM +0400, Valentine Barshak wrote:

This adds RCAR Gen2 USB phy support. The driver configures
USB channels 0/2 which are shared between PCI USB hosts and
USBHS/USBSS devices. It also controls internal USBHS phy.

Signed-off-by: Valentine Barshak 
---
  drivers/usb/phy/Kconfig |  13 ++
  drivers/usb/phy/Makefile|   1 +
  drivers/usb/phy/phy-rcar-gen2-usb.c | 248 
  include/linux/platform_data/usb-rcar-gen2-phy.h |  22 +++
  4 files changed, 284 insertions(+)
  create mode 100644 drivers/usb/phy/phy-rcar-gen2-usb.c
  create mode 100644 include/linux/platform_data/usb-rcar-gen2-phy.h

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index d5589f9..bba7d29 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -214,6 +214,19 @@ config USB_RCAR_PHY
  To compile this driver as a module, choose M here: the
  module will be called phy-rcar-usb.

+config USB_RCAR_GEN2_PHY
+   tristate "Renesas R-Car Gen2 USB PHY support"
+   depends on ARCH_R8A7790 || ARCH_R8A7791 || (ARM && COMPILE_TEST)


see my question on other thread, why the forced ARM dependency ?



I just can't test building it architectures other than ARM and X86, 
though I guess it should probably build fine.

Just thought restricting to ARM would be safe enough.
I'll remove ARM dependency and resubmit just this patch in a bit.

Thanks,
Val.
--
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: Move R-Car Gen2 driver registration to postcore_inictall

2013-10-29 Thread Valentine

On 10/29/2013 09:00 PM, Laurent Pinchart wrote:

Hi Valentine,

Thank you for the patch.

On Tuesday 29 October 2013 20:21:06 Valentine Barshak wrote:

USB phy controls USB channels 0 and 2 which are shared between
PCI USB host controllers and USBHS/USBSS respectively.

This Initializes USB phy driver earlier because we need it
before PCI USB host controllers are initialized.


Can't you use deferred probing ?


No, unfortunately this doesn't work with PCI.
We need the USB PHY set up before the PCI driver starts.
PCI controllers should be initialized via subsys_initcall and can't be built as 
a module.
Deferred probing is done at late_initcall and that's far too late in this case.

The MXS USB phy uses the similar approach, initializing the driver via 
postcore_initcall.
I haven't observed any issues with it on R-Car Gen2 phy as well.

Thanks,
Val.




Signed-off-by: Valentine Barshak 
---
  drivers/usb/phy/phy-rcar-gen2-usb.c | 12 +++-
  1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c
b/drivers/usb/phy/phy-rcar-gen2-usb.c index db3ab34..32c8847 100644
--- a/drivers/usb/phy/phy-rcar-gen2-usb.c
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -241,7 +241,17 @@ static struct platform_driver rcar_gen2_usb_phy_driver
= { .remove = rcar_gen2_usb_phy_remove,
  };

-module_platform_driver(rcar_gen2_usb_phy_driver);
+static int __init rcar_gen2_usb_phy_mod_init(void)
+{
+   return platform_driver_register(&rcar_gen2_usb_phy_driver);
+}
+postcore_initcall(rcar_gen2_usb_phy_mod_init);
+
+static void __exit rcar_gen2_usb_phy_mod_exit(void)
+{
+   platform_driver_unregister(&rcar_gen2_usb_phy_driver);
+}
+module_exit(rcar_gen2_usb_phy_mod_exit);

  MODULE_LICENSE("GPL v2");
  MODULE_DESCRIPTION("Renesas R-Car Gen2 USB phy");


--
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: Move R-Car Gen2 driver registration to postcore_inictall

2013-10-30 Thread Valentine

On 10/30/2013 03:57 AM, Greg KH wrote:

On Tue, Oct 29, 2013 at 09:19:09PM +0400, Valentine wrote:

On 10/29/2013 09:00 PM, Laurent Pinchart wrote:

Hi Valentine,

Thank you for the patch.

On Tuesday 29 October 2013 20:21:06 Valentine Barshak wrote:

USB phy controls USB channels 0 and 2 which are shared between
PCI USB host controllers and USBHS/USBSS respectively.

This Initializes USB phy driver earlier because we need it
before PCI USB host controllers are initialized.


Can't you use deferred probing ?


No, unfortunately this doesn't work with PCI.
We need the USB PHY set up before the PCI driver starts.
PCI controllers should be initialized via subsys_initcall and can't be built as 
a module.
Deferred probing is done at late_initcall and that's far too late in this case.

The MXS USB phy uses the similar approach, initializing the driver via 
postcore_initcall.


I _HATE_ this "make this driver later than the others" mess.  I'll not


This is actually "make this driver before the others" mess.


take patches that move drivers to different initcalls, sorry.  Please
fix up the link order, or use deferred probing, as that is why it was
created.



This is needed for the PCI EHCI/OHCI drivers to operate correctly on R-Car Gen 
platform
since it has built-in PCI host controllers that share USB I/O with USBHS/USBSS 
devices.
The phy has to be configured before the PCI EHCI/OHCI devices are probed.

I'd really appreciate if you could give me a hint on how to fix the PCI 
EHCI/OHCI driver
to use deferred probing, or fix the link order without creating a bigger mess.


sorry,

greg k-h



Thanks,
Val.
--
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: Move R-Car Gen2 driver registration to postcore_inictall

2013-10-30 Thread Valentine

On 10/30/2013 06:12 PM, Greg KH wrote:

On Wed, Oct 30, 2013 at 01:56:25PM +0400, Valentine wrote:

On 10/30/2013 03:57 AM, Greg KH wrote:

On Tue, Oct 29, 2013 at 09:19:09PM +0400, Valentine wrote:

On 10/29/2013 09:00 PM, Laurent Pinchart wrote:

Hi Valentine,

Thank you for the patch.

On Tuesday 29 October 2013 20:21:06 Valentine Barshak wrote:

USB phy controls USB channels 0 and 2 which are shared between
PCI USB host controllers and USBHS/USBSS respectively.

This Initializes USB phy driver earlier because we need it
before PCI USB host controllers are initialized.


Can't you use deferred probing ?


No, unfortunately this doesn't work with PCI.
We need the USB PHY set up before the PCI driver starts.
PCI controllers should be initialized via subsys_initcall and can't be built as 
a module.
Deferred probing is done at late_initcall and that's far too late in this case.

The MXS USB phy uses the similar approach, initializing the driver via 
postcore_initcall.


I _HATE_ this "make this driver later than the others" mess.  I'll not


This is actually "make this driver before the others" mess.


take patches that move drivers to different initcalls, sorry.  Please
fix up the link order, or use deferred probing, as that is why it was
created.



This is needed for the PCI EHCI/OHCI drivers to operate correctly on R-Car Gen 
platform
since it has built-in PCI host controllers that share USB I/O with USBHS/USBSS 
devices.
The phy has to be configured before the PCI EHCI/OHCI devices are probed.

I'd really appreciate if you could give me a hint on how to fix the PCI 
EHCI/OHCI driver
to use deferred probing, or fix the link order without creating a bigger mess.


Just change the PCI driver to use deferred probing, it isn't that hard
to do so.



Do you mean to change usb_hcd_pci_probe() to return -EPROBE_DEFER if the phy is 
not ready?
Or should I defer the whole PCI subsystem initialization (pci_common_int)?


good luck,


Thanks,
Val.



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] usb: phy: Move R-Car Gen2 driver registration to postcore_inictall

2013-10-31 Thread Valentine

On 10/31/2013 03:36 AM, Valentine wrote:

On 10/30/2013 06:12 PM, Greg KH wrote:

On Wed, Oct 30, 2013 at 01:56:25PM +0400, Valentine wrote:

On 10/30/2013 03:57 AM, Greg KH wrote:

On Tue, Oct 29, 2013 at 09:19:09PM +0400, Valentine wrote:

On 10/29/2013 09:00 PM, Laurent Pinchart wrote:

Hi Valentine,

Thank you for the patch.

On Tuesday 29 October 2013 20:21:06 Valentine Barshak wrote:

USB phy controls USB channels 0 and 2 which are shared between
PCI USB host controllers and USBHS/USBSS respectively.

This Initializes USB phy driver earlier because we need it
before PCI USB host controllers are initialized.


Can't you use deferred probing ?


No, unfortunately this doesn't work with PCI.
We need the USB PHY set up before the PCI driver starts.
PCI controllers should be initialized via subsys_initcall and can't be built as 
a module.
Deferred probing is done at late_initcall and that's far too late in this case.

The MXS USB phy uses the similar approach, initializing the driver via 
postcore_initcall.


I _HATE_ this "make this driver later than the others" mess.  I'll not


This is actually "make this driver before the others" mess.


take patches that move drivers to different initcalls, sorry.  Please
fix up the link order, or use deferred probing, as that is why it was
created.



This is needed for the PCI EHCI/OHCI drivers to operate correctly on R-Car Gen 
platform
since it has built-in PCI host controllers that share USB I/O with USBHS/USBSS 
devices.
The phy has to be configured before the PCI EHCI/OHCI devices are probed.

I'd really appreciate if you could give me a hint on how to fix the PCI 
EHCI/OHCI driver
to use deferred probing, or fix the link order without creating a bigger mess.


Just change the PCI driver to use deferred probing, it isn't that hard
to do so.



Do you mean to change usb_hcd_pci_probe() to return -EPROBE_DEFER if the phy is 
not ready?
Or should I defer the whole PCI subsystem initialization (pci_common_int)?


Greg,
the reason I ask is that it doesn't seem that simple to me.

Here's some details:
The h/w is an ARM SoC that has 3 internal PCI controllers with a single 
EHCI/OHCI on each one.
This gives us 3 USB channels as this is called in the h/w manual.
Channel 0 is shared with USBHS (USB function) device.
Channel 2 is shared with USBSS (USB3.0 host).
Both channels are configured by a single USB phy.
USB PHY is a platform device, while EHCI/OCHI are located on the PCI busses.

If PCI USB host is probed before USB phy, the EHCI/OHCI device is detected, but 
nothing works.

We could change the USB HDC PCI driver and make usb_hcd_pci_probe() return 
-EPROBE_DEFER,
but I'm not sure how the condition for that should be phrased.
We could check the PCI vendor/device id, but there's no guarantee the same PCI 
device
is not used on other Renesas h/w which do not require any PHY setup. More over 
we only need
to setup the phy for the USB hosts connected to PCI controller 0/2.

We could try to defer the PCI driver and call pci_common_init() after the USB 
phy is initialized.
However, it seems that it's gonna be a bigger mess.

1. We need to add custom PCI bus scan callback to the hw_pci structure.
We can't use default (pci_scan_root_bus) because it will try to probe/enable 
pci devices before
their resources are fixed up when called late (after the PCI USB host drivers 
are registered).

2. All of the internal PCI controllers are initialized using a single call to 
the pci_common_init_dev().
So we can't easily defer just PCI controller 0/2. Even if we try to defer the 
whole PCI subsystem
initialization, we probably need some sort of a dummy device that will defer 
pci_common_init_dev call
untill USB phy is initialized.

3. The data structures and functions that are used to setup PCI are called at 
subsys_init() and
marked __initdata/__init, so that we can easily get rid of them once the PCI is 
registered.
Using deferred probe we'd need to keep them forever.

Using late_initcall() instead of subsys_initcall() for the PCI registration 
might work
if we implement custom PCI bus scan callback,
But that's just doing the same thing that I've tried to do with USB phy here
with additional PCI bus scan quirk.

On the other hand, postcore_initcall is used in drivers/usb/phy/phy-mxs-usb.c 
which is in your tree.
I agree that it's not that pretty, but it doesn't seem that bad considering 
other options we have.




good luck,


Thanks,
Val.



Please, let me know if you see better options.
Thanks,
Val.



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] usb: phy: Move R-Car Gen2 driver registration to postcore_inictall

2013-10-31 Thread Valentine

On 10/31/2013 08:12 PM, Ulrich Hecht wrote:

On Thu, Oct 31, 2013 at 12:43 PM, Valentine
 wrote:

Please, let me know if you see better options.


How about disregarding the whole PCI aspect? I mean, yes, those are
PCI busses, but they are internal, with a fixed set of devices
attached, and as far as I can tell there are no other PCI busses in
the system. So how about treating the USB host controllers as platform
devices the way it's done in the vendor kernel, saving us the trouble
of pulling in the entire PCI subsystem without any tangible benefit?


There's also a PCIe bus available on the SoC. It is not yet supported,
but we'll eventually need the entire PCI subsystem, which is not that huge as 
it may seem, btw.

Besides, the internal PCI driver has already been submitted to the PCI mailing 
list
and applied to Bjorn's tree.

I don't see how treating the PCI devices as platform devices is better than
adjusting the initialization order of the USB phy.



CU
Uli



Thanks,
Val.
--
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: Move R-Car Gen2 driver registration to postcore_inictall

2013-11-01 Thread Valentine

On 10/31/2013 08:54 PM, Alan Stern wrote:

On Thu, 31 Oct 2013, Valentine wrote:


Do you mean to change usb_hcd_pci_probe() to return -EPROBE_DEFER if the phy is 
not ready?
Or should I defer the whole PCI subsystem initialization (pci_common_int)?


Greg,
the reason I ask is that it doesn't seem that simple to me.

Here's some details:
The h/w is an ARM SoC that has 3 internal PCI controllers with a single 
EHCI/OHCI on each one.
This gives us 3 USB channels as this is called in the h/w manual.
Channel 0 is shared with USBHS (USB function) device.
Channel 2 is shared with USBSS (USB3.0 host).
Both channels are configured by a single USB phy.
USB PHY is a platform device, while EHCI/OCHI are located on the PCI busses.

If PCI USB host is probed before USB phy, the EHCI/OHCI device is
detected, but nothing works.

We could change the USB HDC PCI driver and make usb_hcd_pci_probe() return 
-EPROBE_DEFER,
but I'm not sure how the condition for that should be phrased.


You need to tell usb_hcd_pci_probe() to wait for the PHY.  That seems
to be the proper solution to your problem.

The difficulty is that you have a discoverable device (the PCI EHCI
controller) which needs to wait for a platform device (the PHY).  The
kernel doesn't have a good way to describe such a constraint between
two different kinds of device like that, as far as I know.


Thanks, unfortunately this doesn't help.
I'm not sure how this problem should be addressed using USB HCD PCI deferred 
probing.
However, at the same time I see that six usb phy drivers use subsys_initcall 
and one
uses postcore_initcall to adjust the initialization order.

The same approach is used with other drivers quite often. Take I2C, for example.
I'm not sure why we can't use it here with the R-Car Gen2 phy.
This driver is used only with R-Car SoC and the approach is trivial and  
working fine.

Why can't we use it instead of trying to create a bigger mess in the USB HCD 
PCI driver,
which is used on quite a number of platforms, to workaround the PHY 
initialization order
that is only relevant to R-Car Gen2 SoC?



This is similar to the problems facing Runtime Interpreted Power
Sequences, although not quite the same.

Alan Stern



Thanks,
Val.
--
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: Move R-Car Gen2 driver registration to postcore_inictall

2013-11-01 Thread Valentine

On 11/01/2013 06:17 PM, Alan Stern wrote:

On Fri, 1 Nov 2013, Valentine wrote:


You need to tell usb_hcd_pci_probe() to wait for the PHY.  That seems
to be the proper solution to your problem.

The difficulty is that you have a discoverable device (the PCI EHCI
controller) which needs to wait for a platform device (the PHY).  The
kernel doesn't have a good way to describe such a constraint between
two different kinds of device like that, as far as I know.


Thanks, unfortunately this doesn't help.
I'm not sure how this problem should be addressed using USB HCD PCI deferred 
probing.


I'm not sure either.  It requires further discussion, and it is an
important problem.  Not a trivial one, as you seem to think.


However, at the same time I see that six usb phy drivers use subsys_initcall 
and one
uses postcore_initcall to adjust the initialization order.

The same approach is used with other drivers quite often. Take I2C, for example.
I'm not sure why we can't use it here with the R-Car Gen2 phy.


The fact that other drivers do it doesn't mean it is the right thing to
do.  (Besides, I2C is different from PCI because it isn't discoverable,
right?)



I'm not using postcore_init with PCI. I'm doing it for a platform USB phy 
driver.
Anyway why can't we use postcore_initcall to register a driver for a 
discoverable device?


Greg KH can explain further, if you ask him.


Yes, I'd like to hear from Greg as well.
Explanaitions and suggestions are greatly appreciated.




This driver is used only with R-Car SoC and the approach is trivial and  
working fine.

Why can't we use it instead of trying to create a bigger mess in the USB HCD 
PCI driver,
which is used on quite a number of platforms, to workaround the PHY 
initialization order
that is only relevant to R-Car Gen2 SoC?


Because other platforms are likely to experience the same problem in
the future.  And as you pointed out, other platforms already _are_
experiencing this problem (although perhaps for other drivers).

We should implement a proper solution.  One that can be used
everywhere, not an initcall-order hack.


That would be great, but I don't think we can implement a universal solution 
for all of those drivers.
The solution that may suit R-Car may not be good for other USB phy drivers 
since most likely they have
their init order fixed-up for other reasons not related to PCI USB hosts.

Fixing all the drivers so that they all can use deferred probing is, in my 
opinion, a bit out of scope
here.

The USB HDC PCI deferred probing could be used on R-Car. But I'm not sure how 
to make a particular
PCI USB HDC device attached to a particular PCI host controller on a particular 
SoC defer its probing
while waiting for the USB phy. At the same time other identical PCI USB HCD 
devices (with the same PCI id)
on the same SoC should be probed as usual.

We can't use PCI ids here to distinguish between PCI USB HCD devices. Neither 
can we use PCI busses
to distinguish between PCI host controllers, since bus numbers are assigned 
dynamically.

It looks that it's quite hard to do that without bigger hacks in the PCI USB 
HCD driver that are
most likely not to be used on any other platforms except for R-Car.

I just can't see why changing init order is considered such a bad hack in this 
case,
while it is being used fine with other USB phy drivers.

Can't we use it for R-Car until a universal solution to the deferred probing is 
found?

Probably, moving the whole phy subsystem to the earlier initialization stage 
would be a good-enough
solution since that many PHY drivers have already been using it?
You know, just like the PCI host drivers are initialized at subsys_initcall, or 
is it considered wrong?



Alan Stern



Thanks,
Val.
--
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: Move R-Car Gen2 driver registration to postcore_inictall

2013-11-01 Thread Valentine

On 11/01/2013 06:32 PM, Greg KH wrote:

On Fri, Nov 01, 2013 at 05:59:40PM +0400, Valentine wrote:

I'm not sure how this problem should be addressed using USB HCD PCI deferred 
probing.
However, at the same time I see that six usb phy drivers use subsys_initcall 
and one
uses postcore_initcall to adjust the initialization order.


Then they are all wrong and should be fixed.  Again, this is _why_ we
created the deferred probing logic, and it should be used for this type
of thing, as trying to juggle init call levels is madness and you will
loose in the end (think multi-system kernel images, how is that going to
work?)


I'm sorry, I don't see how moving driver registration from
device_initcall to postcore_initcall alone breaks multi-system kernel image.



thanks,

greg k-h



Thanks,
Val.
--
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: Move R-Car Gen2 driver registration to postcore_inictall

2013-11-05 Thread Valentine

On 11/01/2013 07:55 PM, Alan Stern wrote:

On Fri, 1 Nov 2013, Valentine wrote:


The USB HDC PCI deferred probing could be used on R-Car. But I'm not sure how 
to make a particular
PCI USB HDC device attached to a particular PCI host controller on a particular 
SoC defer its probing
while waiting for the USB phy. At the same time other identical PCI USB HCD 
devices (with the same PCI id)
on the same SoC should be probed as usual.


That is the hard part.  That's what we need to discuss.

And not just on the linux-usb mailing list.  Get other people
(especially PCI people) involved too.


We can't use PCI ids here to distinguish between PCI USB HCD devices. Neither 
can we use PCI busses
to distinguish between PCI host controllers, since bus numbers are assigned 
dynamically.


There must be some way for you to tell which PCI devices use the PHY.
But I'm not a PCI expert, and I'm not familiar with your platform.


It looks that it's quite hard to do that without bigger hacks in the PCI USB 
HCD driver that are
most likely not to be used on any other platforms except for R-Car.


You never know what will happen in the future.  Besides, even if nobody
else needs to do this for a PCI device, you can be certain that the
same sort of thing will be needed for devices on other buses.  A
suitably general solution would help them too.

Alan Stern



OK, I've tried to come up with more or less universal solution to defer HCD 
probing
until the external USB phy is ready. I'll start a new thread with the RFC 
patches in a bit.

Thanks,
Val.
--
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 PATCH 1/2] usb: hcd: Remove USB phy if needed

2013-11-06 Thread Valentine

On 11/06/2013 07:45 PM, Felipe Balbi wrote:

Hi,

On Wed, Nov 06, 2013 at 12:33:26AM +0400, Valentine Barshak wrote:

This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This can be used by the HCD drivers to auto-remove
the external USB phy when it is no longer needed.

Signed-off-by: Valentine Barshak 
---
  drivers/usb/core/hcd.c  | 14 +-
  include/linux/usb/hcd.h |  1 +
  2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d6a8d23..d939521 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -43,6 +43,7 @@

  #include 
  #include 
+#include 

  #include "usb.h"

@@ -2611,7 +2612,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 */
if ((retval = hcd_buffer_create(hcd)) != 0) {
dev_dbg(hcd->self.controller, "pool alloc failed\n");
-   return retval;
+   goto err_remove_phy;
}

if ((retval = usb_register_bus(&hcd->self)) < 0)
@@ -2742,6 +2743,12 @@ err_allocate_root_hub:
usb_deregister_bus(&hcd->self);
  err_register_bus:
hcd_buffer_destroy(hcd);
+err_remove_phy:
+   if (hcd->remove_phy && hcd->phy) {
+   usb_phy_shutdown(hcd->phy);
+   usb_put_phy(hcd->phy);
+   hcd->phy = NULL;
+   }


why do you need the flag at all ? If hcd->phy is valid, just casll
usb_phy_shutdown() followed by usb_put_phy(). Did you find any issues
with that ?



I haven't been able to test it with other platforms.
However, some drivers use devm_usb_get_phy_dev() and we may face refcounter 
issues
if we call usb_put_phy unconditionally.
Adding this flag seems safe enough and we doesn't affect other drivers.

Thanks,
Val.

--
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 PATCH 2/2] usb: hcd: Introduce CONFIG_USB_HCD_EXTERNAL_PHY option

2013-11-06 Thread Valentine

On 11/06/2013 08:39 PM, Alan Stern wrote:

On Wed, 6 Nov 2013, Felipe Balbi wrote:


Hi,

On Wed, Nov 06, 2013 at 12:33:27AM +0400, Valentine Barshak wrote:

This adds external USB phy support to USB HCD driver that
allows to find and initialize external USB phy, bound to
the HCD when the HCD is added.
The usb_add_hcd function returns -EPROBE_DEFER if the USB
phy, bound to the HCD, is not ready.
If no USB phy is bound, the HCD is initialized as usual.

Signed-off-by: Valentine Barshak 
---
  drivers/usb/core/hcd.c   | 20 
  drivers/usb/host/Kconfig | 11 +++
  2 files changed, 31 insertions(+)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d939521..da9c4ba 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2597,6 +2597,26 @@ int usb_add_hcd(struct usb_hcd *hcd,
int retval;
struct usb_device *rhdev;

+#ifdef CONFIG_USB_HCD_EXTERNAL_PHY


I don't see any reason to add a new Kconfig symbol.  Just use "#ifdef
USB_PHY" instead.


I just thought that most of the drivers would not need this code,
so I added a config option which can be enabled only if necessary.
I'll remove and use USB_PHY instead. Thanks.




I think here would be a nicer location for a flag:

if (hcd->has_external_phy) {
phy = usb_get_phy_dev();


}

that flag would get set by the glue driver (ehci-omap, ehci-msm,
ohci-omap, etc), where necessary.


The problem Valentine is facing is that the glue driver doesn't know
whether or not to set the flag.  The way he set it up, the decision is
pushed down into usb_get_phy_dev, which ought to have enough
information.


Exactly.



Alan Stern



Thanks,
Val.
--
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 PATCH 1/2] usb: hcd: Remove USB phy if needed

2013-11-06 Thread Valentine

On 11/06/2013 09:04 PM, Felipe Balbi wrote:

Hi,

On Wed, Nov 06, 2013 at 08:43:36PM +0400, Valentine wrote:

On 11/06/2013 07:45 PM, Felipe Balbi wrote:

Hi,

On Wed, Nov 06, 2013 at 12:33:26AM +0400, Valentine Barshak wrote:

This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This can be used by the HCD drivers to auto-remove
the external USB phy when it is no longer needed.

Signed-off-by: Valentine Barshak 
---
  drivers/usb/core/hcd.c  | 14 +-
  include/linux/usb/hcd.h |  1 +
  2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d6a8d23..d939521 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -43,6 +43,7 @@

  #include 
  #include 
+#include 

  #include "usb.h"

@@ -2611,7 +2612,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 */
if ((retval = hcd_buffer_create(hcd)) != 0) {
dev_dbg(hcd->self.controller, "pool alloc failed\n");
-   return retval;
+   goto err_remove_phy;
}

if ((retval = usb_register_bus(&hcd->self)) < 0)
@@ -2742,6 +2743,12 @@ err_allocate_root_hub:
usb_deregister_bus(&hcd->self);
  err_register_bus:
hcd_buffer_destroy(hcd);
+err_remove_phy:
+   if (hcd->remove_phy && hcd->phy) {
+   usb_phy_shutdown(hcd->phy);
+   usb_put_phy(hcd->phy);
+   hcd->phy = NULL;
+   }


why do you need the flag at all ? If hcd->phy is valid, just casll
usb_phy_shutdown() followed by usb_put_phy(). Did you find any issues
with that ?



I haven't been able to test it with other platforms.
However, some drivers use devm_usb_get_phy_dev() and we may face refcounter 
issues
if we call usb_put_phy unconditionally.
Adding this flag seems safe enough and we doesn't affect other drivers.


then use devm_usb_get_phy_dev() here and remove the call from all other
drivers ;-)



The glue drivers may use different ways of getting the USB phy:
usb_get_phy; usb_get_phy_dev; devm_usb_get_phy_dev.
We can't consolidate phy getting here since usb_get_phy and usb_get_phy_dev are 
not equivalent.
So we let the glue drivers decide which way of getting/putting USB phy to use.

Thanks,
Val.
--
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 V2 PATCH 2/2] usb: hcd: Initialize USB phy if needed

2013-11-07 Thread Valentine

On 11/07/2013 05:06 PM, Peter Chen wrote:





+#ifdef CONFIG_USB_PHY
+   if (!hcd->phy) {
+   struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller,
0);
+
+   if (IS_ERR(phy)) {
+   retval = PTR_ERR(phy);
+   if (retval == -EPROBE_DEFER)
+   return retval;
+   } else {
+   retval = usb_phy_init(phy);
+   if (retval) {
+   usb_put_phy(phy);
+   return retval;
+   }
+   hcd->phy = phy;
+   hcd->remove_phy = 1;
+   }
+   }
+#endif
+


If the platform doesn't has phy driver, and with CONFIG_USB_PHY enabled, it
will have problem for above code.



It shouldn't have any problems since there's no phy bound to the HCD in this 
case.
Thus, usb_get_phy_dev returns -ENODEV and the HCD will be added as usual.


Peter


Thanks,
Val.

--
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/9] USB 2.0 host on Lager

2013-11-20 Thread Valentine

On 11/20/2013 09:37 PM, Ulrich Hecht wrote:

This is a collection of patches developed by Valentine Barshak towards
support of the PCI-attached USB 2.0 host controllers on Lager, with some
glue supplied by me:

- added missing PCI host clock (MSTP703)
- bound PCI USB HCIs to the USB phy
- added PCI host platform devices on Lager

I chose to do incremental patches on top of Valentine's stuff because his
patches are already in various states of upstream acceptance;


Why re-post them then?
In fact I was going to add USB Host support once USBHS support is commited.

> please tell me

if you need this packaged differently.

CU
Uli

Ulrich Hecht (4):
   pci: rcar-gen2: enable clock
   ARM: shmobile: r8a7790: add internal PCI clock
   usb: phy: rcar-gen2: register using usb_add_phy_dev()
   ARM: shmobile: lager: add PCI USB host controllers

Valentine Barshak (5):
   pci: Add R-Car Gen2 internal PCI support
   usb: hcd: Remove USB phy if needed
   usb: hcd: Initialize USB phy if needed
   usb: phy: Add RCAR Gen2 USB phy
   arm: shmobile: lager: Add USBHS support


You've missed one more patch here, which helps to initialize the PHY for PCI 
host correctly:
usb: phy: phy-rcar-gen2-usb: Fix phy initialization



  arch/arm/mach-shmobile/Kconfig  |   1 +
  arch/arm/mach-shmobile/board-lager.c| 138 ++
  arch/arm/mach-shmobile/clock-r8a7790.c  |   5 +-
  drivers/pci/host/Kconfig|   8 +
  drivers/pci/host/Makefile   |   1 +
  drivers/pci/host/pci-rcar-gen2.c| 347 
  drivers/usb/core/hcd.c  |  34 ++-
  drivers/usb/phy/Kconfig |  13 +
  drivers/usb/phy/Makefile|   1 +
  drivers/usb/phy/phy-rcar-gen2-usb.c | 249 +
  include/linux/platform_data/usb-rcar-gen2-phy.h |  22 ++
  include/linux/usb/hcd.h |   1 +
  12 files changed, 818 insertions(+), 2 deletions(-)
  create mode 100644 drivers/pci/host/pci-rcar-gen2.c
  create mode 100644 drivers/usb/phy/phy-rcar-gen2-usb.c
  create mode 100644 include/linux/platform_data/usb-rcar-gen2-phy.h



Thanks,
Val.
--
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 6/9] pci: rcar-gen2: enable clock

2013-11-20 Thread Valentine

On 11/20/2013 09:38 PM, Ulrich Hecht wrote:

Makes the PCI host controllers come alive.



This is not needed if you use CCLKDEV_DEV_ID in patch 7/9

Thanks,
Val.


Signed-off-by: Ulrich Hecht 
---
  drivers/pci/host/pci-rcar-gen2.c | 14 ++
  1 file changed, 14 insertions(+)

diff --git a/drivers/pci/host/pci-rcar-gen2.c b/drivers/pci/host/pci-rcar-gen2.c
index cbaa5c4..568ff8e 100644
--- a/drivers/pci/host/pci-rcar-gen2.c
+++ b/drivers/pci/host/pci-rcar-gen2.c
@@ -9,6 +9,7 @@
   * published by the Free Software Foundation.
   */

+#include 
  #include 
  #include 
  #include 
@@ -77,6 +78,7 @@
  #define RCAR_PCI_NR_CONTROLLERS   3

  struct rcar_pci_priv {
+   struct clk *clk;
void __iomem *reg;
struct resource io_res;
struct resource mem_res;
@@ -169,6 +171,9 @@ static int __init rcar_pci_setup(int nr, struct 
pci_sys_data *sys)
void __iomem *reg = priv->reg;
u32 val;

+   clk_prepare_enable(priv->clk);
+   udelay(4);
+
val = ioread32(reg + RCAR_PCI_UNIT_REV_REG);
pr_info("PCI: bus%u revision %x\n", sys->busnr, val);

@@ -273,6 +278,7 @@ static int __init rcar_pci_probe(struct platform_device 
*pdev)
struct resource *cfg_res, *mem_res;
struct rcar_pci_priv *priv;
void __iomem *reg;
+   struct clk *clk;

cfg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
reg = devm_ioremap_resource(&pdev->dev, cfg_res);
@@ -288,6 +294,12 @@ static int __init rcar_pci_probe(struct platform_device 
*pdev)
if (!priv)
return -ENOMEM;

+   clk = devm_clk_get(&pdev->dev, "usbpci");
+   if (IS_ERR(clk)) {
+   dev_err(&pdev->dev, "Can't get clock\n");
+   return PTR_ERR(clk);
+   }
+
priv->mem_res = *mem_res;
/*
 * The controller does not support/use port I/O,
@@ -302,6 +314,8 @@ static int __init rcar_pci_probe(struct platform_device 
*pdev)
priv->irq = platform_get_irq(pdev, 0);
priv->reg = reg;

+   priv->clk = clk;
+
return rcar_pci_add_controller(priv);
  }




--
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 8/9] usb: phy: rcar-gen2: register using usb_add_phy_dev()

2013-11-20 Thread Valentine

On 11/20/2013 09:38 PM, Ulrich Hecht wrote:

Allows binding of PCI USB host controllers to this phy.

Signed-off-by: Ulrich Hecht 
---
  drivers/usb/phy/phy-rcar-gen2-usb.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c 
b/drivers/usb/phy/phy-rcar-gen2-usb.c
index a99a695..25fdd91 100644
--- a/drivers/usb/phy/phy-rcar-gen2-usb.c
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -212,8 +212,9 @@ static int rcar_gen2_usb_phy_probe(struct platform_device 
*pdev)
priv->phy.init = rcar_gen2_usb_phy_init;
priv->phy.shutdown = rcar_gen2_usb_phy_shutdown;
priv->phy.set_suspend = rcar_gen2_usb_phy_set_suspend;
+   priv->phy.type = USB_PHY_TYPE_USB2;


The above line is not really needed.
I think we should switch to usb_bind_phy and bind USB phy to the renesas_usbhs 
device instead.
In this case usbhs device probe will be deferred unless usb phy is available.



-   retval = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2);
+   retval = usb_add_phy_dev(&priv->phy);
if (retval < 0) {
dev_err(dev, "Failed to add USB phy\n");
return retval;



Thanks,
Val.
--
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 7/9] ARM: shmobile: r8a7790: add internal PCI clock

2013-11-20 Thread Valentine

On 11/20/2013 09:38 PM, Ulrich Hecht wrote:

Adds clock for internal PCI host controllers.

Signed-off-by: Ulrich Hecht 
---
  arch/arm/mach-shmobile/clock-r8a7790.c | 5 -
  1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-shmobile/clock-r8a7790.c 
b/arch/arm/mach-shmobile/clock-r8a7790.c
index 6107571..5a84698 100644
--- a/arch/arm/mach-shmobile/clock-r8a7790.c
+++ b/arch/arm/mach-shmobile/clock-r8a7790.c
@@ -187,7 +187,7 @@ enum {
MSTP813,
MSTP726, MSTP725, MSTP724, MSTP723, MSTP722, MSTP721, MSTP720,
MSTP717, MSTP716,
-   MSTP704,
+   MSTP704, MSTP703,
MSTP522,
MSTP315, MSTP314, MSTP313, MSTP312, MSTP311, MSTP305, MSTP304,
MSTP216, MSTP207, MSTP206, MSTP204, MSTP203, MSTP202,
@@ -212,6 +212,7 @@ static struct clk mstp_clks[MSTP_NR] = {
[MSTP717] = SH_CLK_MSTP32(&zs_clk, SMSTPCR7, 17, 0), /* HSCIF0 */
[MSTP716] = SH_CLK_MSTP32(&zs_clk, SMSTPCR7, 16, 0), /* HSCIF1 */
[MSTP704] = SH_CLK_MSTP32(&mp_clk, SMSTPCR7, 4, 0), /* HSUSB */
+   [MSTP703] = SH_CLK_MSTP32(&mp_clk, SMSTPCR7, 3, 0), /* EHCI */


The comment to the above line is a bit misleading.


[MSTP522] = SH_CLK_MSTP32(&extal_clk, SMSTPCR5, 22, 0), /* Thermal */
[MSTP315] = SH_CLK_MSTP32(&div6_clks[DIV6_MMC0], SMSTPCR3, 15, 0), /* 
MMC0 */
[MSTP314] = SH_CLK_MSTP32(&div4_clks[DIV4_SD0], SMSTPCR3, 14, 0), /* 
SDHI0 */
@@ -303,6 +304,8 @@ static struct clk_lookup lookups[] = {
CLKDEV_DEV_ID("qspi.0", &mstp_clks[MSTP917]),
CLKDEV_DEV_ID("renesas_usbhs", &mstp_clks[MSTP704]),
CLKDEV_ICK_ID("usbhs", "usb_phy_rcar_gen2", &mstp_clks[MSTP704]),
+   CLKDEV_ICK_ID("usbpci", "pci-rcar-gen2.1", &mstp_clks[MSTP703]),
+   CLKDEV_ICK_ID("usbpci", "pci-rcar-gen2.2", &mstp_clks[MSTP703]),


The CLKDEV_DEV_ID should be used instead for both pci clocks.


  };

  #define R8A7790_CLOCK_ROOT(e, m, p0, p1, p30, p31)\



Thanks,
Val.
--
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 9/9] ARM: shmobile: lager: add PCI USB host controllers

2013-11-20 Thread Valentine

On 11/20/2013 09:38 PM, Ulrich Hecht wrote:

Adds USB1 and 2 as hosts and binds them to the USB phy.

Signed-off-by: Ulrich Hecht 
---
  arch/arm/mach-shmobile/Kconfig   |  1 +
  arch/arm/mach-shmobile/board-lager.c | 23 +++
  2 files changed, 24 insertions(+)

diff --git a/arch/arm/mach-shmobile/Kconfig b/arch/arm/mach-shmobile/Kconfig
index 557f55c..e93812f 100644
--- a/arch/arm/mach-shmobile/Kconfig
+++ b/arch/arm/mach-shmobile/Kconfig
@@ -244,6 +244,7 @@ config MACH_LAGER
bool "Lager board"
depends on ARCH_R8A7790
select USE_OF
+   select PCI

  config MACH_LAGER_REFERENCE
bool "Lager board - Reference Device Tree Implementation"
diff --git a/arch/arm/mach-shmobile/board-lager.c 
b/arch/arm/mach-shmobile/board-lager.c
index efe242d8..71d4482 100644
--- a/arch/arm/mach-shmobile/board-lager.c
+++ b/arch/arm/mach-shmobile/board-lager.c
@@ -271,6 +271,17 @@ static const struct resource usbhs_phy_resources[] 
__initconst = {
DEFINE_RES_MEM(0xe6590100, 0x100),
  };

+static const struct resource usbhs_pci1_resources[] __initconst = {
+   DEFINE_RES_MEM(0xee0b, 0xc00),
+   DEFINE_RES_MEM(0xee0a, 0x1100),
+   DEFINE_RES_IRQ(gic_spi(112)),
+};
+static const struct resource usbhs_pci2_resources[] __initconst = {
+   DEFINE_RES_MEM(0xee0d, 0xc00),
+   DEFINE_RES_MEM(0xee0c, 0x1100),
+   DEFINE_RES_IRQ(gic_spi(113)),
+};
+
  static const struct pinctrl_map lager_pinctrl_map[] = {
/* DU (CN10: ARGB0, CN13: LVDS) */
PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
@@ -337,6 +348,18 @@ static void __init lager_add_standard_devices(void)
  sizeof(usbhs_phy_pdata));
lager_register_usbhs();

+   usb_bind_phy(":00:01.0", 0, "usb_phy_rcar_gen2");
+   usb_bind_phy(":00:02.0", 0, "usb_phy_rcar_gen2");


You don't seem to register PCI controller 0 here. Thus, PCI bus 0 is the root 
bus of controller 1
which has nothing to do with the USB phy.


+   usb_bind_phy(":01:01.0", 0, "usb_phy_rcar_gen2");
+   usb_bind_phy(":01:02.0", 0, "usb_phy_rcar_gen2");
+
+   platform_device_register_simple("pci-rcar-gen2", 1,
+   usbhs_pci1_resources,
+   ARRAY_SIZE(usbhs_pci1_resources));
+   platform_device_register_simple("pci-rcar-gen2", 2,
+   usbhs_pci2_resources,
+   ARRAY_SIZE(usbhs_pci2_resources));
+
lager_add_du_device();
  }




Thanks,
Val.
--
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 3/9] usb: hcd: Initialize USB phy if needed

2013-11-20 Thread Valentine

On 11/20/2013 09:46 PM, Fabio Estevam wrote:

On Wed, Nov 20, 2013 at 3:38 PM, Ulrich Hecht  wrote:

From: Valentine Barshak 

This adds external USB phy support to USB HCD driver that
allows to find and initialize external USB phy, bound to
the HCD, when the HCD is added.
The usb_add_hcd function returns -EPROBE_DEFER if the USB
phy, bound to the HCD, is not ready.
If no USB phy is bound, the HCD is initialized as usual.

Signed-off-by: Valentine Barshak 
Acked-by: Alan Stern 
---
  drivers/usb/core/hcd.c | 20 
  1 file changed, 20 insertions(+)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d939521..fd09ec6 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2597,6 +2597,26 @@ int usb_add_hcd(struct usb_hcd *hcd,
 int retval;
 struct usb_device *rhdev;

+#ifdef CONFIG_USB_PHY
+   if (!hcd->phy) {
+   struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller, 0);


Wouldn't it be better to use the following instead?

   if (IS_ENABLED(CONFIG_USB_PHY) && !hcd->(phy) {


Since USB_PHY is a bool I don't see much of a difference.



Regards,

Fabio Estevam


Thanks,
Val.




+
+   if (IS_ERR(phy)) {
+   retval = PTR_ERR(phy);
+   if (retval == -EPROBE_DEFER)
+   return retval;
+   } else {
+   retval = usb_phy_init(phy);
+   if (retval) {
+   usb_put_phy(phy);
+   return retval;
+   }
+   hcd->phy = phy;
+   hcd->remove_phy = 1;
+   }
+   }
+#endif
+
 dev_info(hcd->self.controller, "%s\n", hcd->product_desc);

 /* Keep old behaviour if authorized_default is not in [0, 1]. */
--
1.8.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


--
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 V2 PATCH 0/2] Defer HCD init until the external PHY, bound to the HCD is ready

2013-11-26 Thread Valentine

On 11/07/2013 03:14 PM, Valentine Barshak wrote:

This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This also adds generic external phy support that allows
the HCD driver to search for a USB phy, bound to the HCD,
when the HC is being added.

If the USB PHY is found, it is initialized and the remove_phy flag
is set. In case PHY is not ready, the usb_add_hcd function returns
the -EPROBE_DEFER error code which defers HCD probing till the PHY
becomes ready.
If no PHY is bound to the HCD, or it has been initialized by
the glue-driver before calling usb_add_hcd(), the HCD is
added as usual.

This approach can be used to initialize the external PHY for
the R-Car PCI USB hosts, that share USB ports with USBHS/USBSS devices.
All we need to do is to make R-Car Gen2 platform code bind the
Gen2 USB phy device to the PCI HC devices, and make the phy-rcar-gen2-usb
driver register USB phy with usb_add_phy_dev() AOT usb_add_phy() callback.

Changes from previous version:
* Used #ifdef CONFIG_USB_PHY instead of introducing new config option.

Valentine Barshak (2):
   usb: hcd: Remove USB phy if needed
   usb: hcd: Initialize USB phy if needed

  drivers/usb/core/hcd.c  | 34 +-
  include/linux/usb/hcd.h |  1 +
  2 files changed, 34 insertions(+), 1 deletion(-)



Greg, are you going to take these or is there anything else I have to do?

Thanks,
Val.
--
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 V2 PATCH 0/2] Defer HCD init until the external PHY, bound to the HCD is ready

2013-11-26 Thread Valentine

On 11/27/2013 01:44 AM, Greg KH wrote:

On Wed, Nov 27, 2013 at 01:31:06AM +0400, Valentine wrote:

On 11/07/2013 03:14 PM, Valentine Barshak wrote:

This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This also adds generic external phy support that allows
the HCD driver to search for a USB phy, bound to the HCD,
when the HC is being added.

If the USB PHY is found, it is initialized and the remove_phy flag
is set. In case PHY is not ready, the usb_add_hcd function returns
the -EPROBE_DEFER error code which defers HCD probing till the PHY
becomes ready.
If no PHY is bound to the HCD, or it has been initialized by
the glue-driver before calling usb_add_hcd(), the HCD is
added as usual.

This approach can be used to initialize the external PHY for
the R-Car PCI USB hosts, that share USB ports with USBHS/USBSS devices.
All we need to do is to make R-Car Gen2 platform code bind the
Gen2 USB phy device to the PCI HC devices, and make the phy-rcar-gen2-usb
driver register USB phy with usb_add_phy_dev() AOT usb_add_phy() callback.

Changes from previous version:
* Used #ifdef CONFIG_USB_PHY instead of introducing new config option.

Valentine Barshak (2):
   usb: hcd: Remove USB phy if needed
   usb: hcd: Initialize USB phy if needed

  drivers/usb/core/hcd.c  | 34 +-
  include/linux/usb/hcd.h |  1 +
  2 files changed, 34 insertions(+), 1 deletion(-)



Greg, are you going to take these or is there anything else I have to do?


I don't see anything to "take" here, sorry.  You sent some patches with
"Request for Comments", which usually means, "don't apply them, I just
want people to look at them", so I don't apply them...

If you want me to apply them, please resend without that.

Also, I'd like to get Alan's ACK on these, as they touch the core HCD
code.

thanks,


Alan's ack is already there.
Just wanted to make sure you don't need anything else.



greg k-h



I'll resend in a bit.
Thanks,
Val.
--
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: R-Car Gen2: Use usb_phy_add_dev

2013-12-09 Thread Valentine

On 12/09/2013 04:35 PM, Valentine Barshak wrote:

Use add_phy_dev instead of usb_phy_add, so that devices can
be bound to the phy. This is needed to set up USB phy for
some internal PCI USB host controllers on R-Car Gen2.

Signed-off-by: Valentine Barshak 
---
  drivers/usb/phy/phy-rcar-gen2-usb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c 
b/drivers/usb/phy/phy-rcar-gen2-usb.c
index db3ab34..551e0a6 100644
--- a/drivers/usb/phy/phy-rcar-gen2-usb.c
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -213,7 +213,7 @@ static int rcar_gen2_usb_phy_probe(struct platform_device 
*pdev)
priv->phy.shutdown = rcar_gen2_usb_phy_shutdown;
priv->phy.set_suspend = rcar_gen2_usb_phy_set_suspend;

-   retval = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2);
+   retval = usb_add_phy_dev(&priv->phy);
if (retval < 0) {
dev_err(dev, "Failed to add USB phy\n");
return retval;



Please, disregard this one as it uses slightly incorrect function names in the 
commit log.
I'll update the log message and submit V2 in a bit.
Sorry for the noise.

Thanks,
Val.
--
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: phy: R-Car Gen2: Use usb_add_phy_dev

2013-12-09 Thread Valentine

On 12/09/2013 11:41 PM, Felipe Balbi wrote:

Hi,

On Mon, Dec 09, 2013 at 11:40:33PM +0400, Valentine Barshak wrote:

Use usb_add_phy_dev instead of usb_add_phy, so that devices can
be bound to the phy. This is needed to set up USB phy for
some internal PCI USB host controllers on R-Car Gen2.

Changes from previous version:
* Fixed function names in the commit log

Signed-off-by: Valentine Barshak 


Was this a regression on v3.13 or can it wait for v3.14 ?



I hope it's OK to have it on 3.13.

The major reason for the change is to use the USB HCD phy handling
updates that are available now in the usb-next branch of Greg's tree:
commit 1ae5799ef6: usb: hcd: Initialize USB phy if needed

Thanks,
Val.
--
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 0/3] Add USBHS support to Lager

2013-10-07 Thread Valentine Barshak
This patch set adds internal USB PHY support to RCAR Gen2 SoC, and
also enables USBHS for the Lager board.

The patches apply fine to the renesas-devel-20131004 tag of the renesas.git.

The first patch also applies fine to the usb.git at kernel.org.
It adds RCAR Gen2 phy driver, which is used to configure the shared USB
channels 0/2 and to control USBHS internal PHY.
All the drivers that use the shared USB channels (USBHS/USBSS/PCI USB host)
should acquire the USB phy first to set proper channel configuration.

The other two patches add USBHS support to Lager board, which requires
RCAR Gen2 phy driver.

Valentine Barshak (3):
  usb: phy: Add RCAR Gen2 USB phy
  arm: shmobile: r8a7790: Add USBHS clock support
  arm: shmobile: lager: Add USBHS support

 arch/arm/mach-shmobile/board-lager.c| 106 +
 arch/arm/mach-shmobile/clock-r8a7790.c  |   4 +
 drivers/usb/phy/Kconfig |  14 ++
 drivers/usb/phy/Makefile|   1 +
 drivers/usb/phy/phy-rcar-gen2-usb.c | 271 
 include/linux/platform_data/usb-rcar-gen2-phy.h |  22 ++
 6 files changed, 418 insertions(+)
 create mode 100644 drivers/usb/phy/phy-rcar-gen2-usb.c
 create mode 100644 include/linux/platform_data/usb-rcar-gen2-phy.h

-- 
1.8.3.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] usb: phy: Add RCAR Gen2 USB phy

2013-10-07 Thread Valentine Barshak
This adds RCAR Gen2 USB phy support. The driver configures
USB channels 0/2, which are shared between PCI USB hosts and
USBHS/USBSS devices. It also controls internal USBHS phy.

Signed-off-by: Valentine Barshak 
---
 drivers/usb/phy/Kconfig |  13 ++
 drivers/usb/phy/Makefile|   1 +
 drivers/usb/phy/phy-rcar-gen2-usb.c | 271 
 include/linux/platform_data/usb-rcar-gen2-phy.h |  22 ++
 4 files changed, 307 insertions(+)
 create mode 100644 drivers/usb/phy/phy-rcar-gen2-usb.c
 create mode 100644 include/linux/platform_data/usb-rcar-gen2-phy.h

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index d5589f9..297062c 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -214,6 +214,19 @@ config USB_RCAR_PHY
  To compile this driver as a module, choose M here: the
  module will be called phy-rcar-usb.
 
+config USB_RCAR_GEN2_PHY
+   tristate "Renesas R-Car Gen2 USB PHY support"
+   depends on ARCH_R8A7790 || ARCH_R8A7791
+   select USB_PHY
+   help
+ Say Y here to add support for the Renesas R-Car Gen2 USB PHY driver.
+ It is typically used to control internal USB PHY for USBHS,
+ and to configure shared USB channels 0 and 2.
+ This driver supports R8A7790 and R8A7791.
+
+ To compile this driver as a module, choose M here: the
+ module will be called phy-rcar-gen2-usb.
+
 config USB_ULPI
bool "Generic ULPI Transceiver Driver"
depends on ARM
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 2135e85..8c5b147 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -29,5 +29,6 @@ obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o
 obj-$(CONFIG_USB_MV_OTG)   += phy-mv-usb.o
 obj-$(CONFIG_USB_MXS_PHY)  += phy-mxs-usb.o
 obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o
+obj-$(CONFIG_USB_RCAR_GEN2_PHY)+= phy-rcar-gen2-usb.o
 obj-$(CONFIG_USB_ULPI) += phy-ulpi.o
 obj-$(CONFIG_USB_ULPI_VIEWPORT)+= phy-ulpi-viewport.o
diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c 
b/drivers/usb/phy/phy-rcar-gen2-usb.c
new file mode 100644
index 000..b7b2102
--- /dev/null
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -0,0 +1,271 @@
+/*
+ * Renesas R-Car Gen2 USB phy driver
+ *
+ * Copyright (C) 2013 Renesas Solutions Corp.
+ * Copyright (C) 2013 Cogent Embedded, Inc.
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct rcar_gen2_usb_phy_priv {
+   struct usb_phy phy;
+   void __iomem *base;
+   struct clk *clk;
+   spinlock_t lock;
+   int usecount;
+   u32 ugctrl2;
+};
+
+#define usb_phy_to_priv(p) container_of(p, struct rcar_gen2_usb_phy_priv, phy)
+
+/* Low Power Status register */
+#define USBHS_LPSTS_REG0x02
+#define USBHS_LPSTS_SUSPM  (1 << 14)
+
+/* USB General control register */
+#define USBHS_UGCTRL_REG   0x80
+#define USBHS_UGCTRL_CONNECT   (1 << 2)
+#define USBHS_UGCTRL_PLLRESET  (1 << 0)
+
+/* USB General control register 2 */
+#define USBHS_UGCTRL2_REG  0x84
+#define USBHS_UGCTRL2_USB0_PCI (1 << 4)
+#define USBHS_UGCTRL2_USB0_HS  (3 << 4)
+#define USBHS_UGCTRL2_USB2_PCI (0 << 31)
+#define USBHS_UGCTRL2_USB2_SS  (1 << 31)
+
+/* USB General status register */
+#define USBHS_UGSTS_REG0x88
+#define USBHS_UGSTS_LOCK   (3 << 8)
+
+/* Setup USB channels */
+static void __rcar_gen2_usb_phy_setup(struct rcar_gen2_usb_phy_priv *priv)
+{
+   u32 val;
+
+   clk_prepare_enable(priv->clk);
+
+   /* Set USB channels in the USBHS UGCTRL2 register */
+   val = ioread32(priv->base);
+   val &= ~(USBHS_UGCTRL2_USB0_HS | USBHS_UGCTRL2_USB2_SS);
+   val |= priv->ugctrl2;
+   iowrite32(val, priv->base);
+}
+
+/* Disable USBHS internal phy */
+static int __rcar_gen2_usbhs_phy_enable(void __iomem *base)
+{
+   u32 val;
+   int i;
+
+   /* USBHS PHY power on */
+   val = ioread32(base + USBHS_UGCTRL_REG);
+   val &= ~USBHS_UGCTRL_PLLRESET;
+   iowrite32(val, base + USBHS_UGCTRL_REG);
+
+   val = ioread16(base + USBHS_LPSTS_REG);
+   val |= USBHS_LPSTS_SUSPM;
+   iowrite16(val, base + USBHS_LPSTS_REG);
+
+   for (i = 0; i < 20; i++) {
+   val = ioread32(base + USBHS_UGSTS_REG);
+   if ((val & USBHS_UGSTS_LOCK) == USBHS_UGSTS_LOCK) {
+   val = ioread32(base + USBHS_UGCTRL_REG);
+   

[PATCH 2/3] arm: shmobile: r8a7790: Add USBHS clock support

2013-10-07 Thread Valentine Barshak
This adds USBHS clock support.

Signed-off-by: Valentine Barshak 
---
 arch/arm/mach-shmobile/clock-r8a7790.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/mach-shmobile/clock-r8a7790.c 
b/arch/arm/mach-shmobile/clock-r8a7790.c
index a64f965..7bb2796 100644
--- a/arch/arm/mach-shmobile/clock-r8a7790.c
+++ b/arch/arm/mach-shmobile/clock-r8a7790.c
@@ -186,6 +186,7 @@ enum {
MSTP813,
MSTP726, MSTP725, MSTP724, MSTP723, MSTP722, MSTP721, MSTP720,
MSTP717, MSTP716,
+   MSTP704,
MSTP522,
MSTP315, MSTP314, MSTP313, MSTP312, MSTP311, MSTP305, MSTP304,
MSTP216, MSTP207, MSTP206, MSTP204, MSTP203, MSTP202,
@@ -208,6 +209,7 @@ static struct clk mstp_clks[MSTP_NR] = {
[MSTP720] = SH_CLK_MSTP32(&p_clk, SMSTPCR7, 20, 0), /* SCIF1 */
[MSTP717] = SH_CLK_MSTP32(&zs_clk, SMSTPCR7, 17, 0), /* HSCIF0 */
[MSTP716] = SH_CLK_MSTP32(&zs_clk, SMSTPCR7, 16, 0), /* HSCIF1 */
+   [MSTP704] = SH_CLK_MSTP32(&mp_clk, SMSTPCR7, 4, 0), /* HSUSB */
[MSTP522] = SH_CLK_MSTP32(&extal_clk, SMSTPCR5, 22, 0), /* Thermal */
[MSTP315] = SH_CLK_MSTP32(&div6_clks[DIV6_MMC0], SMSTPCR3, 15, 0), /* 
MMC0 */
[MSTP314] = SH_CLK_MSTP32(&div4_clks[DIV4_SD0], SMSTPCR3, 14, 0), /* 
SDHI0 */
@@ -296,6 +298,8 @@ static struct clk_lookup lookups[] = {
CLKDEV_DEV_ID("ee22.mmcif", &mstp_clks[MSTP305]),
CLKDEV_DEV_ID("sh_mmcif.1", &mstp_clks[MSTP305]),
CLKDEV_DEV_ID("sh_cmt.0", &mstp_clks[MSTP124]),
+   CLKDEV_DEV_ID("renesas_usbhs", &mstp_clks[MSTP704]),
+   CLKDEV_ICK_ID("usbhs", "usb_phy_rcar_gen2", &mstp_clks[MSTP704]),
 };
 
 #define R8A7790_CLOCK_ROOT(e, m, p0, p1, p30, p31) \
-- 
1.8.3.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] arm: shmobile: lager: Add USBHS support

2013-10-07 Thread Valentine Barshak
This adds USBHS PHY and registers USBHS device if the driver is enabled.

Signed-off-by: Valentine Barshak 
---
 arch/arm/mach-shmobile/board-lager.c | 106 +++
 1 file changed, 106 insertions(+)

diff --git a/arch/arm/mach-shmobile/board-lager.c 
b/arch/arm/mach-shmobile/board-lager.c
index a8d3ce6..15a98ac 100644
--- a/arch/arm/mach-shmobile/board-lager.c
+++ b/arch/arm/mach-shmobile/board-lager.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -29,11 +30,14 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -165,6 +169,98 @@ static const struct resource ether_resources[] __initconst 
= {
DEFINE_RES_IRQ(gic_spi(162)),
 };
 
+/* USBHS */
+#if IS_ENABLED(CONFIG_USB_RENESAS_USBHS_UDC)
+static const struct resource usbhs_resources[] __initconst = {
+   DEFINE_RES_MEM(0xe659, 0x100),
+   DEFINE_RES_IRQ(gic_spi(107)),
+};
+
+struct usbhs_private {
+   struct renesas_usbhs_platform_info info;
+   struct usb_phy *phy;
+};
+
+#define usbhs_get_priv(pdev) \
+   container_of(renesas_usbhs_get_info(pdev), struct usbhs_private, info)
+
+static int usbhs_power_ctrl(struct platform_device *pdev,
+   void __iomem *base, int enable)
+{
+   struct usbhs_private *priv = usbhs_get_priv(pdev);
+
+   if (!priv->phy)
+   return -ENODEV;
+
+   return usb_phy_set_suspend(priv->phy, !enable);
+}
+
+static int usbhs_hardware_init(struct platform_device *pdev)
+{
+   struct usbhs_private *priv = usbhs_get_priv(pdev);
+   struct usb_phy *phy;
+
+   phy = usb_get_phy(USB_PHY_TYPE_USB2);
+   if (IS_ERR(phy))
+   return PTR_ERR(phy);
+
+   priv->phy = phy;
+   return usb_phy_init(priv->phy);
+}
+
+static int usbhs_hardware_exit(struct platform_device *pdev)
+{
+   struct usbhs_private *priv = usbhs_get_priv(pdev);
+
+   if (!priv->phy)
+   return 0;
+
+   usb_phy_shutdown(priv->phy);
+   usb_put_phy(priv->phy);
+   priv->phy = NULL;
+   return 0;
+}
+
+static int usbhs_get_id(struct platform_device *pdev)
+{
+   return USBHS_GADGET;
+}
+
+static struct usbhs_private usbhs_priv __initdata = {
+   .info = {
+   .platform_callback = {
+   .power_ctrl = usbhs_power_ctrl,
+   .hardware_init  = usbhs_hardware_init,
+   .hardware_exit  = usbhs_hardware_exit,
+   .get_id = usbhs_get_id,
+   },
+   .driver_param = {
+   .buswait_bwait  = 4,
+   },
+   }
+};
+
+#define lager_register_usbhs() \
+   platform_device_register_resndata(&platform_bus,\
+ "renesas_usbhs", -1,  \
+ usbhs_resources,  \
+ ARRAY_SIZE(usbhs_resources),  \
+ &usbhs_priv.info, \
+ sizeof(usbhs_priv.info))
+#else  /* CONFIG_USB_RENESAS_USBHS_UDC */
+#define lager_register_usbhs()
+#endif /* CONFIG_USB_RENESAS_USBHS_UDC */
+
+/* USBHS PHY */
+static const struct rcar_gen2_phy_platform_data usbhs_phy_pdata __initconst = {
+   .chan0_pci = 0, /* Channel 0 is USBHS */
+   .chan2_pci = 1, /* Channel 2 is PCI USB */
+};
+
+static const struct resource usbhs_phy_resources[] __initconst = {
+   DEFINE_RES_MEM(0xe6590100, 0x100),
+};
+
 static const struct pinctrl_map lager_pinctrl_map[] = {
/* DU (CN10: ARGB0, CN13: LVDS) */
PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
@@ -193,6 +289,9 @@ static const struct pinctrl_map lager_pinctrl_map[] = {
  "eth_rmii", "eth"),
PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
  "intc_irq0", "intc"),
+   /* USB0 */
+   PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs", "pfc-r8a7790",
+ "usb0", "usb0"),
 };
 
 static void __init lager_add_standard_devices(void)
@@ -221,6 +320,13 @@ static void __init lager_add_standard_devices(void)
  ARRAY_SIZE(ether_resources),
  ðer_pdata, sizeof(ether_pdata));
 
+   platform_device_register_resndata(&platform_bus, "usb_phy_rcar_gen2",
+ -1, usbhs_phy_resources,
+ ARRAY_SIZE(us

[PATCH 3/3] arm: shmobile: lager: Add USBHS support

2013-10-08 Thread Valentine Barshak
This adds USBHS PHY and registers USBHS device if the driver is enabled.

Signed-off-by: Valentine Barshak 
---
 arch/arm/mach-shmobile/board-lager.c | 115 +++
 1 file changed, 115 insertions(+)

diff --git a/arch/arm/mach-shmobile/board-lager.c 
b/arch/arm/mach-shmobile/board-lager.c
index a8d3ce6..f375eae 100644
--- a/arch/arm/mach-shmobile/board-lager.c
+++ b/arch/arm/mach-shmobile/board-lager.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -29,11 +30,14 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -165,6 +169,107 @@ static const struct resource ether_resources[] 
__initconst = {
DEFINE_RES_IRQ(gic_spi(162)),
 };
 
+/* USBHS */
+#if IS_ENABLED(CONFIG_USB_RENESAS_USBHS_UDC)
+static const struct resource usbhs_resources[] __initconst = {
+   DEFINE_RES_MEM(0xe659, 0x100),
+   DEFINE_RES_IRQ(gic_spi(107)),
+};
+
+struct usbhs_private {
+   struct renesas_usbhs_platform_info info;
+   struct usb_phy *phy;
+};
+
+#define usbhs_get_priv(pdev) \
+   container_of(renesas_usbhs_get_info(pdev), struct usbhs_private, info)
+
+static int usbhs_power_ctrl(struct platform_device *pdev,
+   void __iomem *base, int enable)
+{
+   struct usbhs_private *priv = usbhs_get_priv(pdev);
+
+   if (!priv->phy)
+   return -ENODEV;
+
+   if (enable) {
+   int retval = usb_phy_init(priv->phy);
+
+   if (!retval)
+   retval = usb_phy_set_suspend(priv->phy, 0);
+   return retval;
+   }
+
+   usb_phy_set_suspend(priv->phy, 1);
+   usb_phy_shutdown(priv->phy);
+   return 0;
+}
+
+static int usbhs_hardware_init(struct platform_device *pdev)
+{
+   struct usbhs_private *priv = usbhs_get_priv(pdev);
+   struct usb_phy *phy;
+
+   phy = usb_get_phy(USB_PHY_TYPE_USB2);
+   if (IS_ERR(phy))
+   return PTR_ERR(phy);
+
+   priv->phy = phy;
+   return 0;
+}
+
+static int usbhs_hardware_exit(struct platform_device *pdev)
+{
+   struct usbhs_private *priv = usbhs_get_priv(pdev);
+
+   if (!priv->phy)
+   return 0;
+
+   usb_put_phy(priv->phy);
+   priv->phy = NULL;
+   return 0;
+}
+
+static int usbhs_get_id(struct platform_device *pdev)
+{
+   return USBHS_GADGET;
+}
+
+static struct usbhs_private usbhs_priv __initdata = {
+   .info = {
+   .platform_callback = {
+   .power_ctrl = usbhs_power_ctrl,
+   .hardware_init  = usbhs_hardware_init,
+   .hardware_exit  = usbhs_hardware_exit,
+   .get_id = usbhs_get_id,
+   },
+   .driver_param = {
+   .buswait_bwait  = 4,
+   },
+   }
+};
+
+#define lager_register_usbhs() \
+   platform_device_register_resndata(&platform_bus,\
+ "renesas_usbhs", -1,  \
+ usbhs_resources,  \
+ ARRAY_SIZE(usbhs_resources),  \
+ &usbhs_priv.info, \
+ sizeof(usbhs_priv.info))
+#else  /* CONFIG_USB_RENESAS_USBHS_UDC */
+#define lager_register_usbhs()
+#endif /* CONFIG_USB_RENESAS_USBHS_UDC */
+
+/* USBHS PHY */
+static const struct rcar_gen2_phy_platform_data usbhs_phy_pdata __initconst = {
+   .chan0_pci = 0, /* Channel 0 is USBHS */
+   .chan2_pci = 1, /* Channel 2 is PCI USB */
+};
+
+static const struct resource usbhs_phy_resources[] __initconst = {
+   DEFINE_RES_MEM(0xe6590100, 0x100),
+};
+
 static const struct pinctrl_map lager_pinctrl_map[] = {
/* DU (CN10: ARGB0, CN13: LVDS) */
PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
@@ -193,6 +298,9 @@ static const struct pinctrl_map lager_pinctrl_map[] = {
  "eth_rmii", "eth"),
PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
  "intc_irq0", "intc"),
+   /* USB0 */
+   PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs", "pfc-r8a7790",
+ "usb0", "usb0"),
 };
 
 static void __init lager_add_standard_devices(void)
@@ -221,6 +329,13 @@ static void __init lager_add_standard_devices(void)
  ARRAY_SIZE(ether_resources),
  ðer_pdata, si

[PATCH 0/3] Add USBHS support to Lager (take 2)

2013-10-08 Thread Valentine Barshak
This patch set adds internal USB PHY support to RCAR Gen2 SoC, and
also enables USBHS for the Lager board. It has been updated, based
on the comments to the previous version.

The patches apply fine to the renesas-devel-20131008 tag of the renesas.git.
The first patch also applies fine to the usb.git at kernel.org.
It adds RCAR Gen2 phy driver which is used to configure the shared USB
channels 0/2 and to control USBHS internal PHY.
All the drivers that use the shared USB channels (USBHS/USBSS/PCI USB host)
should acquire the USB phy first to set proper channel configuration.

The other two patches add USBHS support to Lager board, which requires
RCAR Gen2 phy driver.

Changes from previous version:
* use-counting and clock handling done in the usb_phy_init/shutdown
  callbacks only;
* a minor typo in the comments fixed;
* phy clean up moved to __rcar_gen2_usb_phy_shutdown function;
* usb_phy_init/shutdown called from usbhs_power_ctrl callback
  to allow renesas_usbhs driver disable USB PHY completely
  when it is not needed.

Valentine Barshak (3):
  usb: phy: Add RCAR Gen2 USB phy
  arm: shmobile: r8a7790: Add USBHS clock support
  arm: shmobile: lager: Add USBHS support

 arch/arm/mach-shmobile/board-lager.c| 106 ++
 arch/arm/mach-shmobile/clock-r8a7790.c  |   4 +
 drivers/usb/phy/Kconfig |  13 ++
 drivers/usb/phy/Makefile|   1 +
 drivers/usb/phy/phy-rcar-gen2-usb.c | 255 
 include/linux/platform_data/usb-rcar-gen2-phy.h |  22 ++
 6 files changed, 401 insertions(+)
 create mode 100644 drivers/usb/phy/phy-rcar-gen2-usb.c
 create mode 100644 include/linux/platform_data/usb-rcar-gen2-phy.h

-- 
1.8.3.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] arm: shmobile: r8a7790: Add USBHS clock support

2013-10-08 Thread Valentine Barshak
This adds USBHS clock support.

Signed-off-by: Valentine Barshak 
---
 arch/arm/mach-shmobile/clock-r8a7790.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/mach-shmobile/clock-r8a7790.c 
b/arch/arm/mach-shmobile/clock-r8a7790.c
index a64f965..161d44e 100644
--- a/arch/arm/mach-shmobile/clock-r8a7790.c
+++ b/arch/arm/mach-shmobile/clock-r8a7790.c
@@ -186,6 +186,7 @@ enum {
MSTP813,
MSTP726, MSTP725, MSTP724, MSTP723, MSTP722, MSTP721, MSTP720,
MSTP717, MSTP716,
+   MSTP704,
MSTP522,
MSTP315, MSTP314, MSTP313, MSTP312, MSTP311, MSTP305, MSTP304,
MSTP216, MSTP207, MSTP206, MSTP204, MSTP203, MSTP202,
@@ -208,6 +209,7 @@ static struct clk mstp_clks[MSTP_NR] = {
[MSTP720] = SH_CLK_MSTP32(&p_clk, SMSTPCR7, 20, 0), /* SCIF1 */
[MSTP717] = SH_CLK_MSTP32(&zs_clk, SMSTPCR7, 17, 0), /* HSCIF0 */
[MSTP716] = SH_CLK_MSTP32(&zs_clk, SMSTPCR7, 16, 0), /* HSCIF1 */
+   [MSTP704] = SH_CLK_MSTP32(&mp_clk, SMSTPCR7, 4, 0), /* HSUSB */
[MSTP522] = SH_CLK_MSTP32(&extal_clk, SMSTPCR5, 22, 0), /* Thermal */
[MSTP315] = SH_CLK_MSTP32(&div6_clks[DIV6_MMC0], SMSTPCR3, 15, 0), /* 
MMC0 */
[MSTP314] = SH_CLK_MSTP32(&div4_clks[DIV4_SD0], SMSTPCR3, 14, 0), /* 
SDHI0 */
@@ -296,6 +298,8 @@ static struct clk_lookup lookups[] = {
CLKDEV_DEV_ID("ee22.mmcif", &mstp_clks[MSTP305]),
CLKDEV_DEV_ID("sh_mmcif.1", &mstp_clks[MSTP305]),
CLKDEV_DEV_ID("sh_cmt.0", &mstp_clks[MSTP124]),
+   CLKDEV_DEV_ID("renesas_usbhs", &mstp_clks[MSTP704]),
+   CLKDEV_ICK_ID("usbhs", "usb_phy_rcar_gen2", &mstp_clks[MSTP704]),
 };
 
 #define R8A7790_CLOCK_ROOT(e, m, p0, p1, p30, p31) \
-- 
1.8.3.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] usb: phy: Add RCAR Gen2 USB phy

2013-10-08 Thread Valentine Barshak
This adds RCAR Gen2 USB phy support. The driver configures
USB channels 0/2 which are shared between PCI USB hosts and
USBHS/USBSS devices. It also controls internal USBHS phy.

Signed-off-by: Valentine Barshak 
---
 drivers/usb/phy/Kconfig |  13 ++
 drivers/usb/phy/Makefile|   1 +
 drivers/usb/phy/phy-rcar-gen2-usb.c | 255 
 include/linux/platform_data/usb-rcar-gen2-phy.h |  22 ++
 4 files changed, 291 insertions(+)
 create mode 100644 drivers/usb/phy/phy-rcar-gen2-usb.c
 create mode 100644 include/linux/platform_data/usb-rcar-gen2-phy.h

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index d5589f9..297062c 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -214,6 +214,19 @@ config USB_RCAR_PHY
  To compile this driver as a module, choose M here: the
  module will be called phy-rcar-usb.
 
+config USB_RCAR_GEN2_PHY
+   tristate "Renesas R-Car Gen2 USB PHY support"
+   depends on ARCH_R8A7790 || ARCH_R8A7791
+   select USB_PHY
+   help
+ Say Y here to add support for the Renesas R-Car Gen2 USB PHY driver.
+ It is typically used to control internal USB PHY for USBHS,
+ and to configure shared USB channels 0 and 2.
+ This driver supports R8A7790 and R8A7791.
+
+ To compile this driver as a module, choose M here: the
+ module will be called phy-rcar-gen2-usb.
+
 config USB_ULPI
bool "Generic ULPI Transceiver Driver"
depends on ARM
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 2135e85..8c5b147 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -29,5 +29,6 @@ obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o
 obj-$(CONFIG_USB_MV_OTG)   += phy-mv-usb.o
 obj-$(CONFIG_USB_MXS_PHY)  += phy-mxs-usb.o
 obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o
+obj-$(CONFIG_USB_RCAR_GEN2_PHY)+= phy-rcar-gen2-usb.o
 obj-$(CONFIG_USB_ULPI) += phy-ulpi.o
 obj-$(CONFIG_USB_ULPI_VIEWPORT)+= phy-ulpi-viewport.o
diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c 
b/drivers/usb/phy/phy-rcar-gen2-usb.c
new file mode 100644
index 000..a2e6f9f
--- /dev/null
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -0,0 +1,255 @@
+/*
+ * Renesas R-Car Gen2 USB phy driver
+ *
+ * Copyright (C) 2013 Renesas Solutions Corp.
+ * Copyright (C) 2013 Cogent Embedded, Inc.
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct rcar_gen2_usb_phy_priv {
+   struct usb_phy phy;
+   void __iomem *base;
+   struct clk *clk;
+   spinlock_t lock;
+   int usecount;
+   u32 ugctrl2;
+};
+
+#define usb_phy_to_priv(p) container_of(p, struct rcar_gen2_usb_phy_priv, phy)
+
+/* Low Power Status register */
+#define USBHS_LPSTS_REG0x02
+#define USBHS_LPSTS_SUSPM  (1 << 14)
+
+/* USB General control register */
+#define USBHS_UGCTRL_REG   0x80
+#define USBHS_UGCTRL_CONNECT   (1 << 2)
+#define USBHS_UGCTRL_PLLRESET  (1 << 0)
+
+/* USB General control register 2 */
+#define USBHS_UGCTRL2_REG  0x84
+#define USBHS_UGCTRL2_USB0_PCI (1 << 4)
+#define USBHS_UGCTRL2_USB0_HS  (3 << 4)
+#define USBHS_UGCTRL2_USB2_PCI (0 << 31)
+#define USBHS_UGCTRL2_USB2_SS  (1 << 31)
+
+/* USB General status register */
+#define USBHS_UGSTS_REG0x88
+#define USBHS_UGSTS_LOCK   (3 << 8)
+
+/* Enable USBHS internal phy */
+static int __rcar_gen2_usbhs_phy_enable(void __iomem *base)
+{
+   u32 val;
+   int i;
+
+   /* USBHS PHY power on */
+   val = ioread32(base + USBHS_UGCTRL_REG);
+   val &= ~USBHS_UGCTRL_PLLRESET;
+   iowrite32(val, base + USBHS_UGCTRL_REG);
+
+   val = ioread16(base + USBHS_LPSTS_REG);
+   val |= USBHS_LPSTS_SUSPM;
+   iowrite16(val, base + USBHS_LPSTS_REG);
+
+   for (i = 0; i < 20; i++) {
+   val = ioread32(base + USBHS_UGSTS_REG);
+   if ((val & USBHS_UGSTS_LOCK) == USBHS_UGSTS_LOCK) {
+   val = ioread32(base + USBHS_UGCTRL_REG);
+   val |= USBHS_UGCTRL_CONNECT;
+   iowrite32(val, base + USBHS_UGCTRL_REG);
+   return 0;
+   }
+   udelay(1);
+   }
+
+   /* Timed out waiting for the PLL lock */
+   return -ETIMEDOUT;
+}
+
+/* Disable USBHS internal phy */
+static int __rcar_gen2_usbhs_phy_disable(void __iomem *base)
+{
+   u32 val;
+
+   /* USBHS PHY power off */
+ 

[PATCH 1/3] usb: phy: Add RCAR Gen2 USB phy

2013-10-09 Thread Valentine Barshak
This adds RCAR Gen2 USB phy support. The driver configures
USB channels 0/2 which are shared between PCI USB hosts and
USBHS/USBSS devices. It also controls internal USBHS phy.

Signed-off-by: Valentine Barshak 
---
 drivers/usb/phy/Kconfig |  13 ++
 drivers/usb/phy/Makefile|   1 +
 drivers/usb/phy/phy-rcar-gen2-usb.c | 248 
 include/linux/platform_data/usb-rcar-gen2-phy.h |  22 +++
 4 files changed, 284 insertions(+)
 create mode 100644 drivers/usb/phy/phy-rcar-gen2-usb.c
 create mode 100644 include/linux/platform_data/usb-rcar-gen2-phy.h

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index d5589f9..bba7d29 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -214,6 +214,19 @@ config USB_RCAR_PHY
  To compile this driver as a module, choose M here: the
  module will be called phy-rcar-usb.
 
+config USB_RCAR_GEN2_PHY
+   tristate "Renesas R-Car Gen2 USB PHY support"
+   depends on ARCH_R8A7790 || ARCH_R8A7791 || (ARM && COMPILE_TEST)
+   select USB_PHY
+   help
+ Say Y here to add support for the Renesas R-Car Gen2 USB PHY driver.
+ It is typically used to control internal USB PHY for USBHS,
+ and to configure shared USB channels 0 and 2.
+ This driver supports R8A7790 and R8A7791.
+
+ To compile this driver as a module, choose M here: the
+ module will be called phy-rcar-gen2-usb.
+
 config USB_ULPI
bool "Generic ULPI Transceiver Driver"
depends on ARM
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 2135e85..8c5b147 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -29,5 +29,6 @@ obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o
 obj-$(CONFIG_USB_MV_OTG)   += phy-mv-usb.o
 obj-$(CONFIG_USB_MXS_PHY)  += phy-mxs-usb.o
 obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o
+obj-$(CONFIG_USB_RCAR_GEN2_PHY)+= phy-rcar-gen2-usb.o
 obj-$(CONFIG_USB_ULPI) += phy-ulpi.o
 obj-$(CONFIG_USB_ULPI_VIEWPORT)+= phy-ulpi-viewport.o
diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c 
b/drivers/usb/phy/phy-rcar-gen2-usb.c
new file mode 100644
index 000..a99a695
--- /dev/null
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -0,0 +1,248 @@
+/*
+ * Renesas R-Car Gen2 USB phy driver
+ *
+ * Copyright (C) 2013 Renesas Solutions Corp.
+ * Copyright (C) 2013 Cogent Embedded, Inc.
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct rcar_gen2_usb_phy_priv {
+   struct usb_phy phy;
+   void __iomem *base;
+   struct clk *clk;
+   spinlock_t lock;
+   int usecount;
+   u32 ugctrl2;
+};
+
+#define usb_phy_to_priv(p) container_of(p, struct rcar_gen2_usb_phy_priv, phy)
+
+/* Low Power Status register */
+#define USBHS_LPSTS_REG0x02
+#define USBHS_LPSTS_SUSPM  (1 << 14)
+
+/* USB General control register */
+#define USBHS_UGCTRL_REG   0x80
+#define USBHS_UGCTRL_CONNECT   (1 << 2)
+#define USBHS_UGCTRL_PLLRESET  (1 << 0)
+
+/* USB General control register 2 */
+#define USBHS_UGCTRL2_REG  0x84
+#define USBHS_UGCTRL2_USB0_PCI (1 << 4)
+#define USBHS_UGCTRL2_USB0_HS  (3 << 4)
+#define USBHS_UGCTRL2_USB2_PCI (0 << 31)
+#define USBHS_UGCTRL2_USB2_SS  (1 << 31)
+
+/* USB General status register */
+#define USBHS_UGSTS_REG0x88
+#define USBHS_UGSTS_LOCK   (3 << 8)
+
+/* Enable USBHS internal phy */
+static int __rcar_gen2_usbhs_phy_enable(void __iomem *base)
+{
+   u32 val;
+   int i;
+
+   /* USBHS PHY power on */
+   val = ioread32(base + USBHS_UGCTRL_REG);
+   val &= ~USBHS_UGCTRL_PLLRESET;
+   iowrite32(val, base + USBHS_UGCTRL_REG);
+
+   val = ioread16(base + USBHS_LPSTS_REG);
+   val |= USBHS_LPSTS_SUSPM;
+   iowrite16(val, base + USBHS_LPSTS_REG);
+
+   for (i = 0; i < 20; i++) {
+   val = ioread32(base + USBHS_UGSTS_REG);
+   if ((val & USBHS_UGSTS_LOCK) == USBHS_UGSTS_LOCK) {
+   val = ioread32(base + USBHS_UGCTRL_REG);
+   val |= USBHS_UGCTRL_CONNECT;
+   iowrite32(val, base + USBHS_UGCTRL_REG);
+   return 0;
+   }
+   udelay(1);
+   }
+
+   /* Timed out waiting for the PLL lock */
+   return -ETIMEDOUT;
+}
+
+/* Disable USBHS internal phy */
+static int __rcar_gen2_usbhs_phy_disable(void __iomem *base)
+{
+   u32 val;
+
+  

[PATCH 3/3] arm: shmobile: lager: Add USBHS support

2013-10-09 Thread Valentine Barshak
This adds USBHS PHY and registers USBHS device if the driver is enabled.

Signed-off-by: Valentine Barshak 
Acked-by: Kuninori Morimoto 
---
 arch/arm/mach-shmobile/board-lager.c | 115 +++
 1 file changed, 115 insertions(+)

diff --git a/arch/arm/mach-shmobile/board-lager.c 
b/arch/arm/mach-shmobile/board-lager.c
index 78a31b6..0f07857 100644
--- a/arch/arm/mach-shmobile/board-lager.c
+++ b/arch/arm/mach-shmobile/board-lager.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -29,11 +30,14 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -165,6 +169,107 @@ static const struct resource ether_resources[] 
__initconst = {
DEFINE_RES_IRQ(gic_spi(162)),
 };
 
+/* USBHS */
+#if IS_ENABLED(CONFIG_USB_RENESAS_USBHS_UDC)
+static const struct resource usbhs_resources[] __initconst = {
+   DEFINE_RES_MEM(0xe659, 0x100),
+   DEFINE_RES_IRQ(gic_spi(107)),
+};
+
+struct usbhs_private {
+   struct renesas_usbhs_platform_info info;
+   struct usb_phy *phy;
+};
+
+#define usbhs_get_priv(pdev) \
+   container_of(renesas_usbhs_get_info(pdev), struct usbhs_private, info)
+
+static int usbhs_power_ctrl(struct platform_device *pdev,
+   void __iomem *base, int enable)
+{
+   struct usbhs_private *priv = usbhs_get_priv(pdev);
+
+   if (!priv->phy)
+   return -ENODEV;
+
+   if (enable) {
+   int retval = usb_phy_init(priv->phy);
+
+   if (!retval)
+   retval = usb_phy_set_suspend(priv->phy, 0);
+   return retval;
+   }
+
+   usb_phy_set_suspend(priv->phy, 1);
+   usb_phy_shutdown(priv->phy);
+   return 0;
+}
+
+static int usbhs_hardware_init(struct platform_device *pdev)
+{
+   struct usbhs_private *priv = usbhs_get_priv(pdev);
+   struct usb_phy *phy;
+
+   phy = usb_get_phy(USB_PHY_TYPE_USB2);
+   if (IS_ERR(phy))
+   return PTR_ERR(phy);
+
+   priv->phy = phy;
+   return 0;
+}
+
+static int usbhs_hardware_exit(struct platform_device *pdev)
+{
+   struct usbhs_private *priv = usbhs_get_priv(pdev);
+
+   if (!priv->phy)
+   return 0;
+
+   usb_put_phy(priv->phy);
+   priv->phy = NULL;
+   return 0;
+}
+
+static int usbhs_get_id(struct platform_device *pdev)
+{
+   return USBHS_GADGET;
+}
+
+static struct usbhs_private usbhs_priv __initdata = {
+   .info = {
+   .platform_callback = {
+   .power_ctrl = usbhs_power_ctrl,
+   .hardware_init  = usbhs_hardware_init,
+   .hardware_exit  = usbhs_hardware_exit,
+   .get_id = usbhs_get_id,
+   },
+   .driver_param = {
+   .buswait_bwait  = 4,
+   },
+   }
+};
+
+#define lager_register_usbhs() \
+   platform_device_register_resndata(&platform_bus,\
+ "renesas_usbhs", -1,  \
+ usbhs_resources,  \
+ ARRAY_SIZE(usbhs_resources),  \
+ &usbhs_priv.info, \
+ sizeof(usbhs_priv.info))
+#else  /* CONFIG_USB_RENESAS_USBHS_UDC */
+#define lager_register_usbhs()
+#endif /* CONFIG_USB_RENESAS_USBHS_UDC */
+
+/* USBHS PHY */
+static const struct rcar_gen2_phy_platform_data usbhs_phy_pdata __initconst = {
+   .chan0_pci = 0, /* Channel 0 is USBHS */
+   .chan2_pci = 1, /* Channel 2 is PCI USB */
+};
+
+static const struct resource usbhs_phy_resources[] __initconst = {
+   DEFINE_RES_MEM(0xe6590100, 0x100),
+};
+
 static const struct pinctrl_map lager_pinctrl_map[] = {
/* DU (CN10: ARGB0, CN13: LVDS) */
PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
@@ -193,6 +298,9 @@ static const struct pinctrl_map lager_pinctrl_map[] = {
  "eth_rmii", "eth"),
PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
  "intc_irq0", "intc"),
+   /* USB0 */
+   PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs", "pfc-r8a7790",
+ "usb0", "usb0"),
 };
 
 static void __init lager_add_standard_devices(void)
@@ -221,6 +329,13 @@ static void __init lager_add_standard_devices(void)
  ARRAY_SIZE(ether_resources),
  ðer_pdata, si

[PATCH 2/3] arm: shmobile: r8a7790: Add USBHS clock support

2013-10-09 Thread Valentine Barshak
This adds USBHS clock support.

Signed-off-by: Valentine Barshak 
Acked-by: Kuninori Morimoto 
---
 arch/arm/mach-shmobile/clock-r8a7790.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/mach-shmobile/clock-r8a7790.c 
b/arch/arm/mach-shmobile/clock-r8a7790.c
index a64f965..161d44e 100644
--- a/arch/arm/mach-shmobile/clock-r8a7790.c
+++ b/arch/arm/mach-shmobile/clock-r8a7790.c
@@ -186,6 +186,7 @@ enum {
MSTP813,
MSTP726, MSTP725, MSTP724, MSTP723, MSTP722, MSTP721, MSTP720,
MSTP717, MSTP716,
+   MSTP704,
MSTP522,
MSTP315, MSTP314, MSTP313, MSTP312, MSTP311, MSTP305, MSTP304,
MSTP216, MSTP207, MSTP206, MSTP204, MSTP203, MSTP202,
@@ -208,6 +209,7 @@ static struct clk mstp_clks[MSTP_NR] = {
[MSTP720] = SH_CLK_MSTP32(&p_clk, SMSTPCR7, 20, 0), /* SCIF1 */
[MSTP717] = SH_CLK_MSTP32(&zs_clk, SMSTPCR7, 17, 0), /* HSCIF0 */
[MSTP716] = SH_CLK_MSTP32(&zs_clk, SMSTPCR7, 16, 0), /* HSCIF1 */
+   [MSTP704] = SH_CLK_MSTP32(&mp_clk, SMSTPCR7, 4, 0), /* HSUSB */
[MSTP522] = SH_CLK_MSTP32(&extal_clk, SMSTPCR5, 22, 0), /* Thermal */
[MSTP315] = SH_CLK_MSTP32(&div6_clks[DIV6_MMC0], SMSTPCR3, 15, 0), /* 
MMC0 */
[MSTP314] = SH_CLK_MSTP32(&div4_clks[DIV4_SD0], SMSTPCR3, 14, 0), /* 
SDHI0 */
@@ -296,6 +298,8 @@ static struct clk_lookup lookups[] = {
CLKDEV_DEV_ID("ee22.mmcif", &mstp_clks[MSTP305]),
CLKDEV_DEV_ID("sh_mmcif.1", &mstp_clks[MSTP305]),
CLKDEV_DEV_ID("sh_cmt.0", &mstp_clks[MSTP124]),
+   CLKDEV_DEV_ID("renesas_usbhs", &mstp_clks[MSTP704]),
+   CLKDEV_ICK_ID("usbhs", "usb_phy_rcar_gen2", &mstp_clks[MSTP704]),
 };
 
 #define R8A7790_CLOCK_ROOT(e, m, p0, p1, p30, p31) \
-- 
1.8.3.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 0/3] Add USBHS support to Lager (take 3)

2013-10-09 Thread Valentine Barshak
This patch set adds internal USB PHY support to RCAR Gen2 SoC, and
also enables USBHS for the Lager board. It has been updated, based
on the comments to the previous version.

The patches apply fine to the renesas-devel-20131009v2 tag of the renesas.git.
The first patch also applies fine to the usb.git at kernel.org.
It adds RCAR Gen2 phy driver which is used to configure the shared USB
channels 0/2 and to control USBHS internal PHY.
All the drivers that use the shared USB channels (USBHS/USBSS/PCI USB host)
should acquire the USB phy first to set proper channel configuration.

The other two patches add USBHS support to Lager board, which requires
RCAR Gen2 phy driver.

Changes from version 2:
* added COMPILE_TEST support to phy-rcar-gen2-usb;
* sorted phy-rcar-gen2-usb.c includes in the alphabetical order;
* dropped unnecessary checks and error messages
  in the phy-rcar-gen2 probe callback.

Changes from version 1:
* use-counting and clock handling done in the usb_phy_init/shutdown
  callbacks only;
* a minor typo in the comments fixed;
* phy clean up moved to __rcar_gen2_usb_phy_shutdown function;
* usb_phy_init/shutdown called from usbhs_power_ctrl callback
  to allow renesas_usbhs driver disable USB PHY completely
  when it is not needed.

Valentine Barshak (3):
  usb: phy: Add RCAR Gen2 USB phy
  arm: shmobile: r8a7790: Add USBHS clock support
  arm: shmobile: lager: Add USBHS support

 arch/arm/mach-shmobile/board-lager.c| 106 ++
 arch/arm/mach-shmobile/clock-r8a7790.c  |   4 +
 drivers/usb/phy/Kconfig |  13 ++
 drivers/usb/phy/Makefile|   1 +
 drivers/usb/phy/phy-rcar-gen2-usb.c | 255 
 include/linux/platform_data/usb-rcar-gen2-phy.h |  22 ++
 6 files changed, 401 insertions(+)
 create mode 100644 drivers/usb/phy/phy-rcar-gen2-usb.c
 create mode 100644 include/linux/platform_data/usb-rcar-gen2-phy.h

-- 
1.8.3.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] usb: phy: Add RCAR Gen2 USB phy

2013-10-10 Thread Valentine Barshak
This adds RCAR Gen2 USB phy support. The driver configures
USB channels 0/2 which are shared between PCI USB hosts and
USBHS/USBSS devices. It also controls internal USBHS phy.

Signed-off-by: Valentine Barshak 
---
 drivers/usb/phy/Kconfig |  13 ++
 drivers/usb/phy/Makefile|   1 +
 drivers/usb/phy/phy-rcar-gen2-usb.c | 248 
 include/linux/platform_data/usb-rcar-gen2-phy.h |  22 +++
 4 files changed, 284 insertions(+)
 create mode 100644 drivers/usb/phy/phy-rcar-gen2-usb.c
 create mode 100644 include/linux/platform_data/usb-rcar-gen2-phy.h

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index d5589f9..c0c8cd3 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -214,6 +214,19 @@ config USB_RCAR_PHY
  To compile this driver as a module, choose M here: the
  module will be called phy-rcar-usb.
 
+config USB_RCAR_GEN2_PHY
+   tristate "Renesas R-Car Gen2 USB PHY support"
+   depends on ARCH_R8A7790 || ARCH_R8A7791 || COMPILE_TEST
+   select USB_PHY
+   help
+ Say Y here to add support for the Renesas R-Car Gen2 USB PHY driver.
+ It is typically used to control internal USB PHY for USBHS,
+ and to configure shared USB channels 0 and 2.
+ This driver supports R8A7790 and R8A7791.
+
+ To compile this driver as a module, choose M here: the
+ module will be called phy-rcar-gen2-usb.
+
 config USB_ULPI
bool "Generic ULPI Transceiver Driver"
depends on ARM
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 2135e85..8c5b147 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -29,5 +29,6 @@ obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o
 obj-$(CONFIG_USB_MV_OTG)   += phy-mv-usb.o
 obj-$(CONFIG_USB_MXS_PHY)  += phy-mxs-usb.o
 obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o
+obj-$(CONFIG_USB_RCAR_GEN2_PHY)+= phy-rcar-gen2-usb.o
 obj-$(CONFIG_USB_ULPI) += phy-ulpi.o
 obj-$(CONFIG_USB_ULPI_VIEWPORT)+= phy-ulpi-viewport.o
diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c 
b/drivers/usb/phy/phy-rcar-gen2-usb.c
new file mode 100644
index 000..a99a695
--- /dev/null
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -0,0 +1,248 @@
+/*
+ * Renesas R-Car Gen2 USB phy driver
+ *
+ * Copyright (C) 2013 Renesas Solutions Corp.
+ * Copyright (C) 2013 Cogent Embedded, Inc.
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct rcar_gen2_usb_phy_priv {
+   struct usb_phy phy;
+   void __iomem *base;
+   struct clk *clk;
+   spinlock_t lock;
+   int usecount;
+   u32 ugctrl2;
+};
+
+#define usb_phy_to_priv(p) container_of(p, struct rcar_gen2_usb_phy_priv, phy)
+
+/* Low Power Status register */
+#define USBHS_LPSTS_REG0x02
+#define USBHS_LPSTS_SUSPM  (1 << 14)
+
+/* USB General control register */
+#define USBHS_UGCTRL_REG   0x80
+#define USBHS_UGCTRL_CONNECT   (1 << 2)
+#define USBHS_UGCTRL_PLLRESET  (1 << 0)
+
+/* USB General control register 2 */
+#define USBHS_UGCTRL2_REG  0x84
+#define USBHS_UGCTRL2_USB0_PCI (1 << 4)
+#define USBHS_UGCTRL2_USB0_HS  (3 << 4)
+#define USBHS_UGCTRL2_USB2_PCI (0 << 31)
+#define USBHS_UGCTRL2_USB2_SS  (1 << 31)
+
+/* USB General status register */
+#define USBHS_UGSTS_REG0x88
+#define USBHS_UGSTS_LOCK   (3 << 8)
+
+/* Enable USBHS internal phy */
+static int __rcar_gen2_usbhs_phy_enable(void __iomem *base)
+{
+   u32 val;
+   int i;
+
+   /* USBHS PHY power on */
+   val = ioread32(base + USBHS_UGCTRL_REG);
+   val &= ~USBHS_UGCTRL_PLLRESET;
+   iowrite32(val, base + USBHS_UGCTRL_REG);
+
+   val = ioread16(base + USBHS_LPSTS_REG);
+   val |= USBHS_LPSTS_SUSPM;
+   iowrite16(val, base + USBHS_LPSTS_REG);
+
+   for (i = 0; i < 20; i++) {
+   val = ioread32(base + USBHS_UGSTS_REG);
+   if ((val & USBHS_UGSTS_LOCK) == USBHS_UGSTS_LOCK) {
+   val = ioread32(base + USBHS_UGCTRL_REG);
+   val |= USBHS_UGCTRL_CONNECT;
+   iowrite32(val, base + USBHS_UGCTRL_REG);
+   return 0;
+   }
+   udelay(1);
+   }
+
+   /* Timed out waiting for the PLL lock */
+   return -ETIMEDOUT;
+}
+
+/* Disable USBHS internal phy */
+static int __rcar_gen2_usbhs_phy_disable(void __iomem *base)
+{
+   u32 val;
+
+   /* USBH

[PATCH] usb: phy: phy-rcar-gen2-usb: Fix phy initialization

2013-10-25 Thread Valentine Barshak
Add missing USB UGCTRL2 register offset.

Signed-off-by: Valentine Barshak 
---
 drivers/usb/phy/phy-rcar-gen2-usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c 
b/drivers/usb/phy/phy-rcar-gen2-usb.c
index a99a695..db3ab34 100644
--- a/drivers/usb/phy/phy-rcar-gen2-usb.c
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -107,10 +107,10 @@ static void __rcar_gen2_usb_phy_init(struct 
rcar_gen2_usb_phy_priv *priv)
clk_prepare_enable(priv->clk);
 
/* Set USB channels in the USBHS UGCTRL2 register */
-   val = ioread32(priv->base);
+   val = ioread32(priv->base + USBHS_UGCTRL2_REG);
val &= ~(USBHS_UGCTRL2_USB0_HS | USBHS_UGCTRL2_USB2_SS);
val |= priv->ugctrl2;
-   iowrite32(val, priv->base);
+   iowrite32(val, priv->base + USBHS_UGCTRL2_REG);
 }
 
 /* Shutdown USB channels */
-- 
1.8.3.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] usb: phy: Move R-Car Gen2 driver registration to postcore_inictall

2013-10-29 Thread Valentine Barshak
USB phy controls USB channels 0 and 2 which are shared between
PCI USB host controllers and USBHS/USBSS respectively.

This Initializes USB phy driver earlier because we need it
before PCI USB host controllers are initialized.

Signed-off-by: Valentine Barshak 
---
 drivers/usb/phy/phy-rcar-gen2-usb.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c 
b/drivers/usb/phy/phy-rcar-gen2-usb.c
index db3ab34..32c8847 100644
--- a/drivers/usb/phy/phy-rcar-gen2-usb.c
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -241,7 +241,17 @@ static struct platform_driver rcar_gen2_usb_phy_driver = {
.remove = rcar_gen2_usb_phy_remove,
 };
 
-module_platform_driver(rcar_gen2_usb_phy_driver);
+static int __init rcar_gen2_usb_phy_mod_init(void)
+{
+   return platform_driver_register(&rcar_gen2_usb_phy_driver);
+}
+postcore_initcall(rcar_gen2_usb_phy_mod_init);
+
+static void __exit rcar_gen2_usb_phy_mod_exit(void)
+{
+   platform_driver_unregister(&rcar_gen2_usb_phy_driver);
+}
+module_exit(rcar_gen2_usb_phy_mod_exit);
 
 MODULE_LICENSE("GPL v2");
 MODULE_DESCRIPTION("Renesas R-Car Gen2 USB phy");
-- 
1.8.3.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


[RFC PATCH 1/2] usb: hcd: Remove USB phy if needed

2013-11-05 Thread Valentine Barshak
This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This can be used by the HCD drivers to auto-remove
the external USB phy when it is no longer needed.

Signed-off-by: Valentine Barshak 
---
 drivers/usb/core/hcd.c  | 14 +-
 include/linux/usb/hcd.h |  1 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d6a8d23..d939521 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -43,6 +43,7 @@
 
 #include 
 #include 
+#include 
 
 #include "usb.h"
 
@@ -2611,7 +2612,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 */
if ((retval = hcd_buffer_create(hcd)) != 0) {
dev_dbg(hcd->self.controller, "pool alloc failed\n");
-   return retval;
+   goto err_remove_phy;
}
 
if ((retval = usb_register_bus(&hcd->self)) < 0)
@@ -2742,6 +2743,12 @@ err_allocate_root_hub:
usb_deregister_bus(&hcd->self);
 err_register_bus:
hcd_buffer_destroy(hcd);
+err_remove_phy:
+   if (hcd->remove_phy && hcd->phy) {
+   usb_phy_shutdown(hcd->phy);
+   usb_put_phy(hcd->phy);
+   hcd->phy = NULL;
+   }
return retval;
 } 
 EXPORT_SYMBOL_GPL(usb_add_hcd);
@@ -2814,6 +2821,11 @@ void usb_remove_hcd(struct usb_hcd *hcd)
usb_put_dev(hcd->self.root_hub);
usb_deregister_bus(&hcd->self);
hcd_buffer_destroy(hcd);
+   if (hcd->remove_phy && hcd->phy) {
+   usb_phy_shutdown(hcd->phy);
+   usb_put_phy(hcd->phy);
+   hcd->phy = NULL;
+   }
 }
 EXPORT_SYMBOL_GPL(usb_remove_hcd);
 
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index 75efc45..9c2907b 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -133,6 +133,7 @@ struct usb_hcd {
unsignedrh_registered:1;/* is root hub registered? */
unsignedrh_pollable:1;  /* may we poll the root hub? */
unsignedmsix_enabled:1; /* driver has MSI-X enabled? */
+   unsignedremove_phy:1;   /* auto-remove USB phy */
 
/* The next flag is a stopgap, to be removed when all the HCDs
 * support the new root-hub polling mechanism. */
-- 
1.8.3.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


[RFC PATCH 2/2] usb: hcd: Introduce CONFIG_USB_HCD_EXTERNAL_PHY option

2013-11-05 Thread Valentine Barshak
This adds external USB phy support to USB HCD driver that
allows to find and initialize external USB phy, bound to
the HCD when the HCD is added.
The usb_add_hcd function returns -EPROBE_DEFER if the USB
phy, bound to the HCD, is not ready.
If no USB phy is bound, the HCD is initialized as usual.

Signed-off-by: Valentine Barshak 
---
 drivers/usb/core/hcd.c   | 20 
 drivers/usb/host/Kconfig | 11 +++
 2 files changed, 31 insertions(+)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d939521..da9c4ba 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2597,6 +2597,26 @@ int usb_add_hcd(struct usb_hcd *hcd,
int retval;
struct usb_device *rhdev;
 
+#ifdef CONFIG_USB_HCD_EXTERNAL_PHY
+   if (!hcd->phy) {
+   struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller, 0);
+
+   if (IS_ERR(phy)) {
+   retval = PTR_ERR(phy);
+   if (retval == -EPROBE_DEFER)
+   return retval;
+   } else {
+   retval = usb_phy_init(phy);
+   if (retval) {
+   usb_put_phy(phy);
+   return retval;
+   }
+   hcd->phy = phy;
+   hcd->remove_phy = 1;
+   }
+   }
+#endif
+
dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
 
/* Keep old behaviour if authorized_default is not in [0, 1]. */
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index b3f20d7..2e1f2b0 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -706,3 +706,14 @@ config USB_HCD_TEST_MODE
  This option is of interest only to developers who need to validate
  their USB hardware designs.  It is not needed for normal use.  If
  unsure, say N.
+
+config USB_HCD_EXTERNAL_PHY
+   bool "Set up external USB phy bound to the USB HCD"
+   select USB_PHY
+   ---help---
+ Some USB host controllers require an external USB phy.
+ This adds generic USB phy support to the USB HCD driver.
+ When the HCD is being initialized, the HC driver searches
+ for a USB phy, bound to the HCD. If no USB phy is bound
+ to the HCD, the HCD is initialized as usual.
+ If unsure, say N.
-- 
1.8.3.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


[RFC PATCH 0/2] Defer HCD init until the external PHY, bound to the HCD is ready

2013-11-05 Thread Valentine Barshak
This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This also adds CONFIG_USB_HCD_EXTERNAL_PHY option that allows
the HCD driver to search for a USB phy, bound to the HCD,
when the HC is being added.

If the USB PHY is found, it is initialized and the remove_phy flag
is set. In case PHY is not ready, the usb_add_hcd function returns
the -EPROBE_DEFER error code which defers HCD probing till the PHY
becomes ready.
If no PHY is bound to the HCD, or it has been initialized by
the low-level driver before calling usb_add_hcd(), the HCD is
added as usual.

This approach can be used to initialize the external PHY for
the R-Car PCI USB hosts, that share USB ports with USBHS/USBSS devices.
All we need to do is to make R-Car Gen2 platform code bind the
Gen2 USB phy device to the PCI HC devices, and make the phy-rcar-gen2-usb
driver register USB phy with usb_add_phy_dev() AOT usb_add_phy() callback.

Valentine Barshak (2):
  usb: hcd: Remove USB phy if needed
  usb: hcd: Introduce CONFIG_USB_HCD_EXTERNAL_PHY option

 drivers/usb/core/hcd.c   | 34 +-
 drivers/usb/host/Kconfig | 11 +++
 include/linux/usb/hcd.h  |  1 +
 3 files changed, 45 insertions(+), 1 deletion(-)

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


[RFC V2 PATCH 0/2] Defer HCD init until the external PHY, bound to the HCD is ready

2013-11-07 Thread Valentine Barshak
This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This also adds generic external phy support that allows
the HCD driver to search for a USB phy, bound to the HCD,
when the HC is being added.

If the USB PHY is found, it is initialized and the remove_phy flag
is set. In case PHY is not ready, the usb_add_hcd function returns
the -EPROBE_DEFER error code which defers HCD probing till the PHY
becomes ready.
If no PHY is bound to the HCD, or it has been initialized by
the glue-driver before calling usb_add_hcd(), the HCD is
added as usual.

This approach can be used to initialize the external PHY for
the R-Car PCI USB hosts, that share USB ports with USBHS/USBSS devices.
All we need to do is to make R-Car Gen2 platform code bind the
Gen2 USB phy device to the PCI HC devices, and make the phy-rcar-gen2-usb
driver register USB phy with usb_add_phy_dev() AOT usb_add_phy() callback.

Changes from previous version:
* Used #ifdef CONFIG_USB_PHY instead of introducing new config option.

Valentine Barshak (2):
  usb: hcd: Remove USB phy if needed
  usb: hcd: Initialize USB phy if needed

 drivers/usb/core/hcd.c  | 34 +-
 include/linux/usb/hcd.h |  1 +
 2 files changed, 34 insertions(+), 1 deletion(-)

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


[RFC V2 PATCH 1/2] usb: hcd: Remove USB phy if needed

2013-11-07 Thread Valentine Barshak
This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This can be used by the HCD drivers to auto-remove
the external USB phy when it is no longer needed.

Signed-off-by: Valentine Barshak 
---
 drivers/usb/core/hcd.c  | 14 +-
 include/linux/usb/hcd.h |  1 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d6a8d23..d939521 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -43,6 +43,7 @@
 
 #include 
 #include 
+#include 
 
 #include "usb.h"
 
@@ -2611,7 +2612,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 */
if ((retval = hcd_buffer_create(hcd)) != 0) {
dev_dbg(hcd->self.controller, "pool alloc failed\n");
-   return retval;
+   goto err_remove_phy;
}
 
if ((retval = usb_register_bus(&hcd->self)) < 0)
@@ -2742,6 +2743,12 @@ err_allocate_root_hub:
usb_deregister_bus(&hcd->self);
 err_register_bus:
hcd_buffer_destroy(hcd);
+err_remove_phy:
+   if (hcd->remove_phy && hcd->phy) {
+   usb_phy_shutdown(hcd->phy);
+   usb_put_phy(hcd->phy);
+   hcd->phy = NULL;
+   }
return retval;
 } 
 EXPORT_SYMBOL_GPL(usb_add_hcd);
@@ -2814,6 +2821,11 @@ void usb_remove_hcd(struct usb_hcd *hcd)
usb_put_dev(hcd->self.root_hub);
usb_deregister_bus(&hcd->self);
hcd_buffer_destroy(hcd);
+   if (hcd->remove_phy && hcd->phy) {
+   usb_phy_shutdown(hcd->phy);
+   usb_put_phy(hcd->phy);
+   hcd->phy = NULL;
+   }
 }
 EXPORT_SYMBOL_GPL(usb_remove_hcd);
 
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index 75efc45..9c2907b 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -133,6 +133,7 @@ struct usb_hcd {
unsignedrh_registered:1;/* is root hub registered? */
unsignedrh_pollable:1;  /* may we poll the root hub? */
unsignedmsix_enabled:1; /* driver has MSI-X enabled? */
+   unsignedremove_phy:1;   /* auto-remove USB phy */
 
/* The next flag is a stopgap, to be removed when all the HCDs
 * support the new root-hub polling mechanism. */
-- 
1.8.3.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


[RFC V2 PATCH 2/2] usb: hcd: Initialize USB phy if needed

2013-11-07 Thread Valentine Barshak
This adds external USB phy support to USB HCD driver that
allows to find and initialize external USB phy, bound to
the HCD, when the HCD is added.
The usb_add_hcd function returns -EPROBE_DEFER if the USB
phy, bound to the HCD, is not ready.
If no USB phy is bound, the HCD is initialized as usual.

Signed-off-by: Valentine Barshak 
---
 drivers/usb/core/hcd.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d939521..fd09ec6 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2597,6 +2597,26 @@ int usb_add_hcd(struct usb_hcd *hcd,
int retval;
struct usb_device *rhdev;
 
+#ifdef CONFIG_USB_PHY
+   if (!hcd->phy) {
+   struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller, 0);
+
+   if (IS_ERR(phy)) {
+   retval = PTR_ERR(phy);
+   if (retval == -EPROBE_DEFER)
+   return retval;
+   } else {
+   retval = usb_phy_init(phy);
+   if (retval) {
+   usb_put_phy(phy);
+   return retval;
+   }
+   hcd->phy = phy;
+   hcd->remove_phy = 1;
+   }
+   }
+#endif
+
dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
 
/* Keep old behaviour if authorized_default is not in [0, 1]. */
-- 
1.8.3.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 0/2] Defer HCD init until the external PHY, bound to the HCD is ready

2013-11-26 Thread Valentine Barshak
This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This also adds generic external phy support that allows
the HCD driver to search for a USB phy, bound to the HCD,
when the HC is being added.

If the USB PHY is found, it is initialized and the remove_phy flag
is set. In case PHY is not ready, the usb_add_hcd function returns
the -EPROBE_DEFER error code which defers HCD probing till the PHY
becomes ready.
If no PHY is bound to the HCD, or it has been initialized by
the glue-driver before calling usb_add_hcd(), the HCD is
added as usual.

This approach can be used to initialize the external PHY for
the R-Car PCI USB hosts, that share USB ports with USBHS/USBSS devices.
All we need to do is to make R-Car Gen2 platform code bind the
Gen2 USB phy device to the PCI HC devices, and make the phy-rcar-gen2-usb
driver register USB phy with usb_add_phy_dev() AOT usb_add_phy() callback.

Changes from previous version:
* Used #ifdef CONFIG_USB_PHY instead of introducing new config option.

Valentine Barshak (2):
  usb: hcd: Remove USB phy if needed
  usb: hcd: Initialize USB phy if needed

 drivers/usb/core/hcd.c  | 34 +-
 include/linux/usb/hcd.h |  1 +
 2 files changed, 34 insertions(+), 1 deletion(-)

-- 
1.8.3.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/2] usb: hcd: Remove USB phy if needed

2013-11-26 Thread Valentine Barshak
This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This can be used by the HCD drivers to auto-remove
the external USB phy when it is no longer needed.

Signed-off-by: Valentine Barshak 
Acked-by: Alan Stern 
---
 drivers/usb/core/hcd.c  | 14 +-
 include/linux/usb/hcd.h |  1 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 6bffb8c..7527c8e 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -44,6 +44,7 @@
 
 #include 
 #include 
+#include 
 
 #include "usb.h"
 
@@ -2603,7 +2604,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 */
if ((retval = hcd_buffer_create(hcd)) != 0) {
dev_dbg(hcd->self.controller, "pool alloc failed\n");
-   return retval;
+   goto err_remove_phy;
}
 
if ((retval = usb_register_bus(&hcd->self)) < 0)
@@ -2734,6 +2735,12 @@ err_allocate_root_hub:
usb_deregister_bus(&hcd->self);
 err_register_bus:
hcd_buffer_destroy(hcd);
+err_remove_phy:
+   if (hcd->remove_phy && hcd->phy) {
+   usb_phy_shutdown(hcd->phy);
+   usb_put_phy(hcd->phy);
+   hcd->phy = NULL;
+   }
return retval;
 }
 EXPORT_SYMBOL_GPL(usb_add_hcd);
@@ -2806,6 +2813,11 @@ void usb_remove_hcd(struct usb_hcd *hcd)
usb_put_dev(hcd->self.root_hub);
usb_deregister_bus(&hcd->self);
hcd_buffer_destroy(hcd);
+   if (hcd->remove_phy && hcd->phy) {
+   usb_phy_shutdown(hcd->phy);
+   usb_put_phy(hcd->phy);
+   hcd->phy = NULL;
+   }
 }
 EXPORT_SYMBOL_GPL(usb_remove_hcd);
 
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index b8aba19..758ce80 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -134,6 +134,7 @@ struct usb_hcd {
unsignedrh_registered:1;/* is root hub registered? */
unsignedrh_pollable:1;  /* may we poll the root hub? */
unsignedmsix_enabled:1; /* driver has MSI-X enabled? */
+   unsignedremove_phy:1;   /* auto-remove USB phy */
 
/* The next flag is a stopgap, to be removed when all the HCDs
 * support the new root-hub polling mechanism. */
-- 
1.8.3.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/2] usb: hcd: Initialize USB phy if needed

2013-11-26 Thread Valentine Barshak
This adds external USB phy support to USB HCD driver that
allows to find and initialize external USB phy, bound to
the HCD, when the HCD is added.
The usb_add_hcd function returns -EPROBE_DEFER if the USB
phy, bound to the HCD, is not ready.
If no USB phy is bound, the HCD is initialized as usual.

Signed-off-by: Valentine Barshak 
Acked-by: Alan Stern 
---
 drivers/usb/core/hcd.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 7527c8e..649506b 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2589,6 +2589,26 @@ int usb_add_hcd(struct usb_hcd *hcd,
int retval;
struct usb_device *rhdev;
 
+#ifdef CONFIG_USB_PHY
+   if (!hcd->phy) {
+   struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller, 0);
+
+   if (IS_ERR(phy)) {
+   retval = PTR_ERR(phy);
+   if (retval == -EPROBE_DEFER)
+   return retval;
+   } else {
+   retval = usb_phy_init(phy);
+   if (retval) {
+   usb_put_phy(phy);
+   return retval;
+   }
+   hcd->phy = phy;
+   hcd->remove_phy = 1;
+   }
+   }
+#endif
+
dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
 
/* Keep old behaviour if authorized_default is not in [0, 1]. */
-- 
1.8.3.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/2] usb: hcd: Remove USB phy if needed

2013-12-03 Thread Valentine Barshak
This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This can be used by the HCD drivers to auto-remove
the external USB phy when it is no longer needed.

Signed-off-by: Valentine Barshak 
Acked-by: Alan Stern 
---
 drivers/usb/core/hcd.c  | 14 +-
 include/linux/usb/hcd.h |  1 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 6bffb8c..7527c8e 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -44,6 +44,7 @@
 
 #include 
 #include 
+#include 
 
 #include "usb.h"
 
@@ -2603,7 +2604,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 */
if ((retval = hcd_buffer_create(hcd)) != 0) {
dev_dbg(hcd->self.controller, "pool alloc failed\n");
-   return retval;
+   goto err_remove_phy;
}
 
if ((retval = usb_register_bus(&hcd->self)) < 0)
@@ -2734,6 +2735,12 @@ err_allocate_root_hub:
usb_deregister_bus(&hcd->self);
 err_register_bus:
hcd_buffer_destroy(hcd);
+err_remove_phy:
+   if (hcd->remove_phy && hcd->phy) {
+   usb_phy_shutdown(hcd->phy);
+   usb_put_phy(hcd->phy);
+   hcd->phy = NULL;
+   }
return retval;
 }
 EXPORT_SYMBOL_GPL(usb_add_hcd);
@@ -2806,6 +2813,11 @@ void usb_remove_hcd(struct usb_hcd *hcd)
usb_put_dev(hcd->self.root_hub);
usb_deregister_bus(&hcd->self);
hcd_buffer_destroy(hcd);
+   if (hcd->remove_phy && hcd->phy) {
+   usb_phy_shutdown(hcd->phy);
+   usb_put_phy(hcd->phy);
+   hcd->phy = NULL;
+   }
 }
 EXPORT_SYMBOL_GPL(usb_remove_hcd);
 
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index b8aba19..758ce80 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -134,6 +134,7 @@ struct usb_hcd {
unsignedrh_registered:1;/* is root hub registered? */
unsignedrh_pollable:1;  /* may we poll the root hub? */
unsignedmsix_enabled:1; /* driver has MSI-X enabled? */
+   unsignedremove_phy:1;   /* auto-remove USB phy */
 
/* The next flag is a stopgap, to be removed when all the HCDs
 * support the new root-hub polling mechanism. */
-- 
1.8.3.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


[V3 PATCH 0/2] Defer HCD init until the external PHY, bound to the HCD is ready

2013-12-03 Thread Valentine Barshak
This adds remove_phy flag to the HCD structure. If the flag is
set and if hcd->phy is valid, the phy is shutdown and released
whenever usb_add_hcd fails or usb_hcd_remove is called.
This also adds generic external phy support that allows
the HCD driver to search for a USB phy, bound to the HCD,
when the HC is being added.

If the USB PHY is found, it is initialized and the remove_phy flag
is set. In case PHY is not ready, the usb_add_hcd function returns
the -EPROBE_DEFER error code which defers HCD probing till the PHY
becomes ready.
If no PHY is bound to the HCD, or it has been initialized by
the glue-driver before calling usb_add_hcd(), the HCD is
added as usual.

This approach can be used to initialize the external PHY for
the R-Car PCI USB hosts, that share USB ports with USBHS/USBSS devices.
All we need to do is to make R-Car Gen2 platform code bind the
Gen2 USB phy device to the PCI HC devices, and make the phy-rcar-gen2-usb
driver register USB phy with usb_add_phy_dev() AOT usb_add_phy() callback.

Changes in version 2:
* Used #ifdef CONFIG_USB_PHY instead of introducing new config option.

Changes in version 3:
* Used if (IS_ENABLED(CONFIG_USB_PHY)... instead of #ifdef CONFIG_USB_PHY.

Valentine Barshak (2):
  usb: hcd: Remove USB phy if needed
  usb: hcd: Initialize USB phy if needed

 drivers/usb/core/hcd.c  | 32 +++-
 include/linux/usb/hcd.h |  1 +
 2 files changed, 32 insertions(+), 1 deletion(-)

-- 
1.8.3.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/2] usb: hcd: Initialize USB phy if needed

2013-12-03 Thread Valentine Barshak
This adds external USB phy support to USB HCD driver that
allows to find and initialize external USB phy, bound to
the HCD, when the HCD is added.
The usb_add_hcd function returns -EPROBE_DEFER if the USB
phy, bound to the HCD, is not ready.
If no USB phy is bound, the HCD is initialized as usual.

Signed-off-by: Valentine Barshak 
---
 drivers/usb/core/hcd.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 7527c8e..d3a9bcd 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2589,6 +2589,24 @@ int usb_add_hcd(struct usb_hcd *hcd,
int retval;
struct usb_device *rhdev;
 
+   if (IS_ENABLED(CONFIG_USB_PHY) && !hcd->phy) {
+   struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller, 0);
+
+   if (IS_ERR(phy)) {
+   retval = PTR_ERR(phy);
+   if (retval == -EPROBE_DEFER)
+   return retval;
+   } else {
+   retval = usb_phy_init(phy);
+   if (retval) {
+   usb_put_phy(phy);
+   return retval;
+   }
+   hcd->phy = phy;
+   hcd->remove_phy = 1;
+   }
+   }
+
dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
 
/* Keep old behaviour if authorized_default is not in [0, 1]. */
-- 
1.8.3.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] usb: phy: R-Car Gen2: Use usb_phy_add_dev

2013-12-09 Thread Valentine Barshak
Use add_phy_dev instead of usb_phy_add, so that devices can
be bound to the phy. This is needed to set up USB phy for
some internal PCI USB host controllers on R-Car Gen2.

Signed-off-by: Valentine Barshak 
---
 drivers/usb/phy/phy-rcar-gen2-usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c 
b/drivers/usb/phy/phy-rcar-gen2-usb.c
index db3ab34..551e0a6 100644
--- a/drivers/usb/phy/phy-rcar-gen2-usb.c
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -213,7 +213,7 @@ static int rcar_gen2_usb_phy_probe(struct platform_device 
*pdev)
priv->phy.shutdown = rcar_gen2_usb_phy_shutdown;
priv->phy.set_suspend = rcar_gen2_usb_phy_set_suspend;
 
-   retval = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2);
+   retval = usb_add_phy_dev(&priv->phy);
if (retval < 0) {
dev_err(dev, "Failed to add USB phy\n");
return retval;
-- 
1.8.3.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] usb: phy: R-Car Gen2: Use usb_add_phy_dev

2013-12-09 Thread Valentine Barshak
Use usb_add_phy_dev instead of usb_add_phy, so that devices can
be bound to the phy. This is needed to set up USB phy for
some internal PCI USB host controllers on R-Car Gen2.

Changes from previous version:
* Fixed function names in the commit log

Signed-off-by: Valentine Barshak 
---
 drivers/usb/phy/phy-rcar-gen2-usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c 
b/drivers/usb/phy/phy-rcar-gen2-usb.c
index db3ab34..551e0a6 100644
--- a/drivers/usb/phy/phy-rcar-gen2-usb.c
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -213,7 +213,7 @@ static int rcar_gen2_usb_phy_probe(struct platform_device 
*pdev)
priv->phy.shutdown = rcar_gen2_usb_phy_shutdown;
priv->phy.set_suspend = rcar_gen2_usb_phy_set_suspend;
 
-   retval = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2);
+   retval = usb_add_phy_dev(&priv->phy);
if (retval < 0) {
dev_err(dev, "Failed to add USB phy\n");
return retval;
-- 
1.8.3.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