Re: [PATCH v2 1/2] usb: ohci-exynos: Add facility to use phy provided by the generic phy framework

2014-04-27 Thread Vivek Gautam
Hi,


On Fri, Apr 25, 2014 at 8:06 PM, Alan Stern st...@rowland.harvard.edu wrote:
 On Fri, 25 Apr 2014, Vivek Gautam wrote:

 Add support to consume phy provided by Generic phy framework.
 Keeping the support for older usb-phy intact right now, in order
 to prevent any functionality break in absence of relevant
 device tree side change for ohci-exynos.
 Once we move to new phy in the device nodes for ohci, we can
 remove the support for older phys.

 Signed-off-by: Vivek Gautam gautam.vi...@samsung.com
 Cc: Jingoo Han jg1@samsung.com
 Cc: Alan Stern st...@rowland.harvard.edu


 +static int exynos_ohci_phyg_on(struct phy *phy[])
 +{
 + int i;
 + int ret = 0;
 +
 + for (i = 0; ret == 0  i  PHY_NUMBER; i++)
 + if (phy[i])
 + ret = phy_power_on(phy[i]);
 + if (ret)
 + for (i--; i = 0; i--)
 + if (phy[i])
 + phy_power_off(phy[i]);
 +
 + return ret;
 +}
 +
 +static int exynos_ohci_phyg_off(struct phy *phy[])
 +{
 + int i;
 + int ret = 0;
 +
 + for (i = 0; ret == 0  i  PHY_NUMBER; i++)
 + if (phy[i])
 + ret = phy_power_off(phy[i]);
 +
 + return ret;
 +}

 You probably shouldn't break out of this loop if ret is nonzero; you
 should continue to power off the remaining phys.

ok, will remove the 'ret' check in for loop.


 I'd be inclined to put these two routines directly into
 exynos_ohci_phy_enable() and exynos_ohci_phy_disable(), since they
 aren't used anywhere else.

Sure, will make these routines as a part of exynos_ohci_phy_enable()
and exynos_ohci_phy_disable().


 @@ -151,6 +253,7 @@ skip_phy:

  fail_add_hcd:
   exynos_ohci_phy_disable(pdev);
 + exynos_ohci_phyg_off(exynos_ohci-phy_g);

 Why did you add this line?  It doesn't do anything useful, because
 exynos_ohci_phy_disable() already calls exynos_ohci_phyg_off().

Ah ! my bad, will remove this.


-- 
Best Regards
Vivek Gautam
Samsung RD Institute, Bangalore
India
--
To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/2] usb: ohci-exynos: Add facility to use phy provided by the generic phy framework

2014-04-25 Thread Vivek Gautam
Add support to consume phy provided by Generic phy framework.
Keeping the support for older usb-phy intact right now, in order
to prevent any functionality break in absence of relevant
device tree side change for ohci-exynos.
Once we move to new phy in the device nodes for ohci, we can
remove the support for older phys.

Signed-off-by: Vivek Gautam gautam.vi...@samsung.com
Cc: Jingoo Han jg1@samsung.com
Cc: Alan Stern st...@rowland.harvard.edu
---

Changes from v1:
 - Made two separate routines for exynos_ohci_phyg_on() and
   exynos_ohci_phyg_off().
 - Separated out the phy-get related code from probe() to separate function
   exynos_ehci_get_phy().
 - Using proper error labels in the code.

 .../devicetree/bindings/usb/exynos-usb.txt |   19 +++
 drivers/usb/host/ohci-exynos.c |  123 ++--
 2 files changed, 132 insertions(+), 10 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/exynos-usb.txt 
b/Documentation/devicetree/bindings/usb/exynos-usb.txt
index d967ba1..03b7e43 100644
--- a/Documentation/devicetree/bindings/usb/exynos-usb.txt
+++ b/Documentation/devicetree/bindings/usb/exynos-usb.txt
@@ -38,6 +38,15 @@ Required properties:
  - interrupts: interrupt number to the cpu.
  - clocks: from common clock binding: handle to usb clock.
  - clock-names: from common clock binding: Shall be usbhost.
+ - port: if in the SoC there are OHCI phys, they should be listed here.
+   One phy per port. Each port should have its 'reg' entry.
+   - reg: port number on OHCI controller, e.g
+  On Exynos5250, port 0 is USB2.0 otg phy
+ port 1 is HSIC phy0
+ port 2 is HSIC phy1
+   - phys: from the *Generic PHY* bindings specifying phy used by port.
+   - phy-names: from the *Generic PHY* bindings specifying name of phy
+used by the port.
 
 Example:
usb@1212 {
@@ -47,6 +56,16 @@ Example:
 
clocks = clock 285;
clock-names = usbhost;
+
+   #address-cells = 1;
+   #size-cells = 0;
+   port@0 {
+   reg = 0;
+   phys = usb2phy 1;
+   phy-names = host;
+   status = disabled;
+   };
+
};
 
 DWC3
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index 68588d8..eac47cb 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -18,6 +18,7 @@
 #include linux/module.h
 #include linux/of.h
 #include linux/platform_device.h
+#include linux/phy/phy.h
 #include linux/usb/phy.h
 #include linux/usb/samsung_usb_phy.h
 #include linux/usb.h
@@ -33,12 +34,111 @@ static struct hc_driver __read_mostly 
exynos_ohci_hc_driver;
 
 #define to_exynos_ohci(hcd) (struct exynos_ohci_hcd *)(hcd_to_ohci(hcd)-priv)
 
+#define PHY_NUMBER 3
 struct exynos_ohci_hcd {
struct clk *clk;
struct usb_phy *phy;
struct usb_otg *otg;
+   struct phy *phy_g[PHY_NUMBER];
 };
 
+static int exynos_ohci_get_phy(struct platform_device *pdev,
+   struct exynos_ohci_hcd *exynos_ohci)
+{
+   struct device_node *child;
+   struct phy *phy;
+   int phy_number;
+   int ret = 0;
+
+   exynos_ohci-phy = devm_usb_get_phy(pdev-dev, USB_PHY_TYPE_USB2);
+   if (IS_ERR(exynos_ohci-phy)) {
+   ret = PTR_ERR(exynos_ohci-phy);
+   /* This is the case when PHY config is disabled */
+   if (ret == -ENXIO || ret == -ENODEV) {
+   dev_dbg(pdev-dev, Failed to get usb2 phy\n);
+   exynos_ohci-phy = NULL;
+   ret = 0;
+   } else if (ret == -EPROBE_DEFER) {
+   goto fail_phy;
+   } else {
+   dev_err(pdev-dev, no usb2 phy configured\n);
+   goto fail_phy;
+   }
+   } else {
+   exynos_ohci-otg = exynos_ohci-phy-otg;
+   }
+
+   /* Getting generic phy:
+* We are keeping both types of phys as a part of transiting OHCI
+* to generic phy framework, so that in absence of supporting dts
+* changes the functionality doesn't break.
+* Once we move the ohci dt nodes to use new generic phys,
+* we can remove support for older PHY in this driver.
+*/
+   for_each_available_child_of_node(pdev-dev.of_node, child) {
+   ret = of_property_read_u32(child, reg, phy_number);
+   if (ret) {
+   dev_err(pdev-dev, Failed to parse device tree\n);
+   of_node_put(child);
+   goto fail_phy;
+   }
+   if (phy_number = PHY_NUMBER) {
+   dev_err(pdev-dev, Invalid number of PHYs\n);
+   of_node_put(child);
+   ret = -EINVAL;
+   

Re: [PATCH v2 1/2] usb: ohci-exynos: Add facility to use phy provided by the generic phy framework

2014-04-25 Thread Alan Stern
On Fri, 25 Apr 2014, Vivek Gautam wrote:

 Add support to consume phy provided by Generic phy framework.
 Keeping the support for older usb-phy intact right now, in order
 to prevent any functionality break in absence of relevant
 device tree side change for ohci-exynos.
 Once we move to new phy in the device nodes for ohci, we can
 remove the support for older phys.
 
 Signed-off-by: Vivek Gautam gautam.vi...@samsung.com
 Cc: Jingoo Han jg1@samsung.com
 Cc: Alan Stern st...@rowland.harvard.edu


 +static int exynos_ohci_phyg_on(struct phy *phy[])
 +{
 + int i;
 + int ret = 0;
 +
 + for (i = 0; ret == 0  i  PHY_NUMBER; i++)
 + if (phy[i])
 + ret = phy_power_on(phy[i]);
 + if (ret)
 + for (i--; i = 0; i--)
 + if (phy[i])
 + phy_power_off(phy[i]);
 +
 + return ret;
 +}
 +
 +static int exynos_ohci_phyg_off(struct phy *phy[])
 +{
 + int i;
 + int ret = 0;
 +
 + for (i = 0; ret == 0  i  PHY_NUMBER; i++)
 + if (phy[i])
 + ret = phy_power_off(phy[i]);
 +
 + return ret;
 +}

You probably shouldn't break out of this loop if ret is nonzero; you
should continue to power off the remaining phys.

I'd be inclined to put these two routines directly into 
exynos_ohci_phy_enable() and exynos_ohci_phy_disable(), since they 
aren't used anywhere else.

 @@ -151,6 +253,7 @@ skip_phy:
  
  fail_add_hcd:
   exynos_ohci_phy_disable(pdev);
 + exynos_ohci_phyg_off(exynos_ohci-phy_g);

Why did you add this line?  It doesn't do anything useful, because 
exynos_ohci_phy_disable() already calls exynos_ohci_phyg_off().

Alan Stern

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