linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/6] USB: Add multiple PHYs of same type
@ 2013-01-16 15:00 Kishon Vijay Abraham I
  2013-01-16 15:00 ` [RFC PATCH 1/6] usb: otg: Add an API to bind the USB controller and PHY Kishon Vijay Abraham I
                   ` (6 more replies)
  0 siblings, 7 replies; 26+ messages in thread
From: Kishon Vijay Abraham I @ 2013-01-16 15:00 UTC (permalink / raw)
  To: devicetree-discuss, linux-doc, linux-kernel, linux-omap,
	linux-arm-kernel, linux-usb, linux-sh, linuxppc-dev, balbi
  Cc: linux, b-cousson, tony, gregkh, rob.herring, kishon, cbou,
	alexander.shishkin, horms, stern, haojian.zhuang, rob,
	eric.y.miao, dwmw2

New platforms are being added which has multiple PHY's (of same type) and
which has multiple USB controllers. The binding information has to be
present in the PHY library (otg.c) in order for it to return the
appropriate PHY whenever the USB controller request for the PHY. So
added a new API to pass the binding information. This API should be
called by platform specific initialization code.

So the binding should be done something like
usb_bind_phy("musb-hdrc.0.auto", 0, "omap-usb2.1.auto"); specifying the USB
controller device name, index, and the PHY device name.
I have done this binding for OMAP platforms, but it should be done for
all the platforms.

After this design, the phy can be got by passing the USB controller device
pointer and the index.

Developed this patch series on
git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git xceiv
after applying "usb: musb: add driver for control module" patch series.

Did basic enumeration testing in omap4 panda, omap4 sdp and omap3 beagle.

Kishon Vijay Abraham I (6):
  usb: otg: Add an API to bind the USB controller and PHY
  ARM: OMAP: USB: Add phy binding information
  usb: otg: utils: change the phy lib to support multiple PHYs of same
    type
  ARM: dts: OMAP: Add phandle to bind PHY with USB controller
  usb: otg: add device tree support to otg library
  USB: MUSB: OMAP: get PHY by phandle for dt boot

 Documentation/devicetree/bindings/usb/omap-usb.txt |    2 +
 arch/arm/boot/dts/omap3.dtsi                       |    1 +
 arch/arm/boot/dts/omap4.dtsi                       |    3 +-
 arch/arm/boot/dts/twl4030.dtsi                     |    2 +-
 arch/arm/mach-omap2/usb-musb.c                     |    7 +-
 arch/arm/mach-shmobile/board-marzen.c              |    2 +-
 drivers/power/ab8500_charger.c                     |    2 +-
 drivers/power/isp1704_charger.c                    |    2 +-
 drivers/power/pda_power.c                          |    2 +-
 drivers/power/twl4030_charger.c                    |    2 +-
 drivers/usb/chipidea/udc.c                         |    2 +-
 drivers/usb/dwc3/core.c                            |    4 +-
 drivers/usb/gadget/fsl_udc_core.c                  |    2 +-
 drivers/usb/gadget/mv_udc_core.c                   |    2 +-
 drivers/usb/gadget/omap_udc.c                      |    2 +-
 drivers/usb/gadget/pxa25x_udc.c                    |    2 +-
 drivers/usb/gadget/pxa27x_udc.c                    |    2 +-
 drivers/usb/gadget/s3c-hsudc.c                     |    2 +-
 drivers/usb/host/ehci-fsl.c                        |    2 +-
 drivers/usb/host/ehci-msm.c                        |    2 +-
 drivers/usb/host/ehci-mv.c                         |    2 +-
 drivers/usb/host/ehci-tegra.c                      |    2 +-
 drivers/usb/host/ohci-omap.c                       |    2 +-
 drivers/usb/musb/am35x.c                           |    2 +-
 drivers/usb/musb/blackfin.c                        |    2 +-
 drivers/usb/musb/da8xx.c                           |    2 +-
 drivers/usb/musb/davinci.c                         |    2 +-
 drivers/usb/musb/musb_dsps.c                       |    2 +-
 drivers/usb/musb/omap2430.c                        |    7 +-
 drivers/usb/musb/tusb6010.c                        |    2 +-
 drivers/usb/musb/ux500.c                           |    2 +-
 drivers/usb/otg/ab8500-usb.c                       |    3 +-
 drivers/usb/otg/fsl_otg.c                          |    5 +-
 drivers/usb/otg/gpio_vbus.c                        |    3 +-
 drivers/usb/otg/isp1301_omap.c                     |    3 +-
 drivers/usb/otg/msm_otg.c                          |    3 +-
 drivers/usb/otg/mv_otg.c                           |    3 +-
 drivers/usb/otg/nop-usb-xceiv.c                    |    3 +-
 drivers/usb/otg/otg.c                              |  175 ++++++++++++++++----
 drivers/usb/otg/twl4030-usb.c                      |    3 +-
 drivers/usb/phy/mv_u3d_phy.c                       |    3 +-
 drivers/usb/phy/omap-usb2.c                        |   11 +-
 drivers/usb/phy/rcar-phy.c                         |    3 +-
 include/linux/usb/phy.h                            |   42 ++++-
 44 files changed, 245 insertions(+), 89 deletions(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [RFC PATCH 1/6] usb: otg: Add an API to bind the USB controller and PHY
  2013-01-16 15:00 [RFC PATCH 0/6] USB: Add multiple PHYs of same type Kishon Vijay Abraham I
@ 2013-01-16 15:00 ` Kishon Vijay Abraham I
  2013-01-17  9:37   ` Roger Quadros
  2013-01-16 15:00 ` [RFC PATCH 2/6] ARM: OMAP: USB: Add phy binding information Kishon Vijay Abraham I
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 26+ messages in thread
From: Kishon Vijay Abraham I @ 2013-01-16 15:00 UTC (permalink / raw)
  To: devicetree-discuss, linux-doc, linux-kernel, linux-omap,
	linux-arm-kernel, linux-usb, linux-sh, linuxppc-dev, balbi
  Cc: linux, b-cousson, tony, gregkh, rob.herring, kishon, cbou,
	alexander.shishkin, horms, stern, haojian.zhuang, rob,
	eric.y.miao, dwmw2

New platforms are added which has multiple PHY's (of same type) and
which has multiple USB controllers. The binding information has to be
present in the PHY library (otg.c) in order for it to return the
appropriate PHY whenever the USB controller request for the PHY. So
added a new API to pass the binding information. This API should be
called by platform specific initialization code.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/otg/otg.c   |   37 +++++++++++++++++++++++++++++++++++++
 include/linux/usb/phy.h |   22 ++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index a30c041..492ba2f 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -18,6 +18,7 @@
 #include <linux/usb/otg.h>
 
 static LIST_HEAD(phy_list);
+static LIST_HEAD(phy_bind_list);
 static DEFINE_SPINLOCK(phy_lock);
 
 static struct usb_phy *__usb_find_phy(struct list_head *list,
@@ -201,6 +202,42 @@ void usb_remove_phy(struct usb_phy *x)
 }
 EXPORT_SYMBOL(usb_remove_phy);
 
+/**
+ * usb_bind_phy - bind the phy and the controller that uses the phy
+ * @dev_name: the device name of the device that will bind to the phy
+ * @index: index to specify the port number
+ * @phy_dev_name: the device name of the phy
+ *
+ * Fills the phy_bind structure with the dev_name and phy_dev_name. This will
+ * be used when the phy driver registers the phy and when the controller
+ * requests this phy.
+ *
+ * To be used by platform specific initialization code.
+ */
+struct usb_phy_bind __init *usb_bind_phy(const char *dev_name, u8 index,
+				const char *phy_dev_name)
+{
+	struct usb_phy_bind *phy_bind;
+	unsigned long flags;
+
+	phy_bind = kzalloc(sizeof(*phy_bind), GFP_KERNEL);
+	if (!phy_bind) {
+		pr_err("phy_bind(): No memory for phy_bind");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	phy_bind->dev_name = dev_name;
+	phy_bind->phy_dev_name = phy_dev_name;
+	phy_bind->index = index;
+
+	spin_lock_irqsave(&phy_lock, flags);
+	list_add_tail(&phy_bind->list, &phy_bind_list);
+	spin_unlock_irqrestore(&phy_lock, flags);
+
+	return phy_bind;
+}
+EXPORT_SYMBOL_GPL(usb_bind_phy);
+
 const char *otg_state_string(enum usb_otg_state state)
 {
 	switch (state) {
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index a29ae1e..fbeab1a 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -106,6 +106,21 @@ struct usb_phy {
 			enum usb_device_speed speed);
 };
 
+/**
+ * struct usb_phy_bind - represent the binding for the phy
+ * @dev_name: the device name of the device that will bind to the phy
+ * @phy_dev_name: the device name of the phy
+ * @index: used if a single controller uses multiple phys
+ * @phy: reference to the phy
+ * @list: to maintain a linked list of the binding information
+ */
+struct usb_phy_bind {
+	const char	*dev_name;
+	const char	*phy_dev_name;
+	u8		index;
+	struct usb_phy	*phy;
+	struct list_head list;
+};
 
 /* for board-specific init logic */
 extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type);
@@ -151,6 +166,8 @@ extern struct usb_phy *devm_usb_get_phy(struct device *dev,
 	enum usb_phy_type type);
 extern void usb_put_phy(struct usb_phy *);
 extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
+extern struct usb_phy_bind *usb_bind_phy(const char *dev_name, u8 index,
+				const char *phy_dev_name);
 #else
 static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
 {
@@ -171,6 +188,11 @@ static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
 {
 }
 
+static inline struct usb_phy_bind *usb_bind_phy(const char *dev_name, u8 index,
+				const char *phy_dev_name)
+{
+	return NULL;
+}
 #endif
 
 static inline int
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [RFC PATCH 2/6] ARM: OMAP: USB: Add phy binding information
  2013-01-16 15:00 [RFC PATCH 0/6] USB: Add multiple PHYs of same type Kishon Vijay Abraham I
  2013-01-16 15:00 ` [RFC PATCH 1/6] usb: otg: Add an API to bind the USB controller and PHY Kishon Vijay Abraham I
@ 2013-01-16 15:00 ` Kishon Vijay Abraham I
  2013-01-17  9:39   ` Roger Quadros
  2013-01-17 12:11   ` Vivek Gautam
  2013-01-16 15:00 ` [RFC PATCH 3/6] usb: otg: utils: change the phy lib to support multiple PHYs of same type Kishon Vijay Abraham I
                   ` (4 subsequent siblings)
  6 siblings, 2 replies; 26+ messages in thread
From: Kishon Vijay Abraham I @ 2013-01-16 15:00 UTC (permalink / raw)
  To: devicetree-discuss, linux-doc, linux-kernel, linux-omap,
	linux-arm-kernel, linux-usb, linux-sh, linuxppc-dev, balbi
  Cc: linux, b-cousson, tony, gregkh, rob.herring, kishon, cbou,
	alexander.shishkin, horms, stern, haojian.zhuang, rob,
	eric.y.miao, dwmw2

This is in preparation for the changes in PHY library to support adding
and getting multiple PHYs of the same type. In the new design, the
binding information between the PHY and the USB controller should be
specified in the platform specific initialization code. So it's been
done for OMAP platforms here.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
This kind-of binding should be done in all the platforms (I've done only
for OMAP platform). 
 arch/arm/mach-omap2/usb-musb.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-omap2/usb-musb.c b/arch/arm/mach-omap2/usb-musb.c
index 9d27e3f..bbe2fa5 100644
--- a/arch/arm/mach-omap2/usb-musb.c
+++ b/arch/arm/mach-omap2/usb-musb.c
@@ -24,6 +24,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/io.h>
 #include <linux/usb/musb.h>
+#include <linux/usb/phy.h>
 
 #include "omap_device.h"
 #include "soc.h"
@@ -85,8 +86,12 @@ void __init usb_musb_init(struct omap_musb_board_data *musb_board_data)
 	musb_plat.mode = board_data->mode;
 	musb_plat.extvbus = board_data->extvbus;
 
-	if (cpu_is_omap44xx())
+	if (cpu_is_omap44xx()) {
 		musb_plat.has_mailbox = true;
+		usb_bind_phy("musb-hdrc.0.auto", 0, "omap-usb2.1.auto");
+	} else if (cpu_is_omap34xx()) {
+		usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb");
+	}
 
 	if (soc_is_am35xx()) {
 		oh_name = "am35x_otg_hs";
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [RFC PATCH 3/6] usb: otg: utils: change the phy lib to support multiple PHYs of same type
  2013-01-16 15:00 [RFC PATCH 0/6] USB: Add multiple PHYs of same type Kishon Vijay Abraham I
  2013-01-16 15:00 ` [RFC PATCH 1/6] usb: otg: Add an API to bind the USB controller and PHY Kishon Vijay Abraham I
  2013-01-16 15:00 ` [RFC PATCH 2/6] ARM: OMAP: USB: Add phy binding information Kishon Vijay Abraham I
@ 2013-01-16 15:00 ` Kishon Vijay Abraham I
  2013-01-17  0:31   ` Simon Horman
  2013-01-17 16:07   ` Roger Quadros
  2013-01-16 15:01 ` [RFC PATCH 4/6] ARM: dts: OMAP: Add phandle to bind PHY with USB controller Kishon Vijay Abraham I
                   ` (3 subsequent siblings)
  6 siblings, 2 replies; 26+ messages in thread
From: Kishon Vijay Abraham I @ 2013-01-16 15:00 UTC (permalink / raw)
  To: devicetree-discuss, linux-doc, linux-kernel, linux-omap,
	linux-arm-kernel, linux-usb, linux-sh, linuxppc-dev, balbi
  Cc: linux, b-cousson, tony, gregkh, rob.herring, kishon, cbou,
	alexander.shishkin, horms, stern, haojian.zhuang, rob,
	eric.y.miao, dwmw2

In order to add support for multipe PHY's of the same type, the API's
for adding PHY and getting PHY has been changed. Now the binding
information of the PHY and controller should be done in platform file
using usb_bind_phy API. And for getting a PHY, the device pointer of the
USB controller and an index should be passed. Based on the binding
information that is added in the platform file, get_phy will return the
approappropriate PHY.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 arch/arm/mach-shmobile/board-marzen.c |    2 +-
 drivers/power/ab8500_charger.c        |    2 +-
 drivers/power/isp1704_charger.c       |    2 +-
 drivers/power/pda_power.c             |    2 +-
 drivers/power/twl4030_charger.c       |    2 +-
 drivers/usb/chipidea/udc.c            |    2 +-
 drivers/usb/dwc3/core.c               |    4 +-
 drivers/usb/gadget/fsl_udc_core.c     |    2 +-
 drivers/usb/gadget/mv_udc_core.c      |    2 +-
 drivers/usb/gadget/omap_udc.c         |    2 +-
 drivers/usb/gadget/pxa25x_udc.c       |    2 +-
 drivers/usb/gadget/pxa27x_udc.c       |    2 +-
 drivers/usb/gadget/s3c-hsudc.c        |    2 +-
 drivers/usb/host/ehci-fsl.c           |    2 +-
 drivers/usb/host/ehci-msm.c           |    2 +-
 drivers/usb/host/ehci-mv.c            |    2 +-
 drivers/usb/host/ehci-tegra.c         |    2 +-
 drivers/usb/host/ohci-omap.c          |    2 +-
 drivers/usb/musb/am35x.c              |    2 +-
 drivers/usb/musb/blackfin.c           |    2 +-
 drivers/usb/musb/da8xx.c              |    2 +-
 drivers/usb/musb/davinci.c            |    2 +-
 drivers/usb/musb/musb_dsps.c          |    2 +-
 drivers/usb/musb/omap2430.c           |    2 +-
 drivers/usb/musb/tusb6010.c           |    2 +-
 drivers/usb/musb/ux500.c              |    2 +-
 drivers/usb/otg/ab8500-usb.c          |    3 +-
 drivers/usb/otg/fsl_otg.c             |    5 ++-
 drivers/usb/otg/gpio_vbus.c           |    3 +-
 drivers/usb/otg/isp1301_omap.c        |    3 +-
 drivers/usb/otg/msm_otg.c             |    3 +-
 drivers/usb/otg/mv_otg.c              |    3 +-
 drivers/usb/otg/nop-usb-xceiv.c       |    3 +-
 drivers/usb/otg/otg.c                 |   67 +++++++++++++++------------------
 drivers/usb/otg/twl4030-usb.c         |    3 +-
 drivers/usb/phy/mv_u3d_phy.c          |    3 +-
 drivers/usb/phy/omap-usb2.c           |   11 ++----
 drivers/usb/phy/rcar-phy.c            |    3 +-
 include/linux/usb/phy.h               |   12 +++---
 39 files changed, 87 insertions(+), 89 deletions(-)

diff --git a/arch/arm/mach-shmobile/board-marzen.c b/arch/arm/mach-shmobile/board-marzen.c
index 449f928..abe482d 100644
--- a/arch/arm/mach-shmobile/board-marzen.c
+++ b/arch/arm/mach-shmobile/board-marzen.c
@@ -320,7 +320,7 @@ static struct platform_device *marzen_late_devices[] __initdata = {
 void __init marzen_init_late(void)
 {
 	/* get usb phy */
-	phy = usb_get_phy(USB_PHY_TYPE_USB2);
+	phy = usb_get_phy(&ehci0_device.dev, 0);
 
 	shmobile_init_late();
 	platform_add_devices(marzen_late_devices,
diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c
index 3be9c0e..d20561a 100644
--- a/drivers/power/ab8500_charger.c
+++ b/drivers/power/ab8500_charger.c
@@ -2694,7 +2694,7 @@ static int ab8500_charger_probe(struct platform_device *pdev)
 		goto free_ac;
 	}
 
-	di->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2);
+	di->usb_phy = usb_get_phy(di->dev, 0);
 	if (IS_ERR_OR_NULL(di->usb_phy)) {
 		dev_err(di->dev, "failed to get usb transceiver\n");
 		ret = -EINVAL;
diff --git a/drivers/power/isp1704_charger.c b/drivers/power/isp1704_charger.c
index 176ad59..dfbe597 100644
--- a/drivers/power/isp1704_charger.c
+++ b/drivers/power/isp1704_charger.c
@@ -415,7 +415,7 @@ static int isp1704_charger_probe(struct platform_device *pdev)
 	if (!isp)
 		return -ENOMEM;
 
-	isp->phy = usb_get_phy(USB_PHY_TYPE_USB2);
+	isp->phy = usb_get_phy(&pdev->dev, 0);
 	if (IS_ERR_OR_NULL(isp->phy))
 		goto fail0;
 
diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
index 7df7c5f..64d79f7 100644
--- a/drivers/power/pda_power.c
+++ b/drivers/power/pda_power.c
@@ -316,7 +316,7 @@ static int pda_power_probe(struct platform_device *pdev)
 	}
 
 #ifdef CONFIG_USB_OTG_UTILS
-	transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
+	transceiver = usb_get_phy(&pdev->dev, 0);
 	if (!IS_ERR_OR_NULL(transceiver)) {
 		if (!pdata->is_usb_online)
 			pdata->is_usb_online = otg_is_usb_online;
diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
index a69d0d1..f53b417 100644
--- a/drivers/power/twl4030_charger.c
+++ b/drivers/power/twl4030_charger.c
@@ -552,7 +552,7 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
 
 	INIT_WORK(&bci->work, twl4030_bci_usb_work);
 
-	bci->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
+	bci->transceiver = usb_get_phy(&pdev->dev, 0);
 	if (!IS_ERR_OR_NULL(bci->transceiver)) {
 		bci->usb_nb.notifier_call = twl4030_bci_usb_ncb;
 		usb_register_notifier(bci->transceiver, &bci->usb_nb);
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 2f45bba..ea6a109 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -1745,7 +1745,7 @@ static int udc_start(struct ci13xxx *ci)
 	ci->gadget.ep0 = &ci->ep0in->ep;
 
 	if (ci->global_phy)
-		ci->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
+		ci->transceiver = usb_get_phy(dev, 0);
 
 	if (ci->platdata->flags & CI13XXX_REQUIRE_TRANSCEIVER) {
 		if (ci->transceiver == NULL) {
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 3a4004a..574d4b7 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -420,13 +420,13 @@ static int dwc3_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
-	dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
+	dwc->usb2_phy = devm_usb_get_phy(dev, 0);
 	if (IS_ERR_OR_NULL(dwc->usb2_phy)) {
 		dev_err(dev, "no usb2 phy configured\n");
 		return -EPROBE_DEFER;
 	}
 
-	dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
+	dwc->usb3_phy = devm_usb_get_phy(dev, 1);
 	if (IS_ERR_OR_NULL(dwc->usb3_phy)) {
 		dev_err(dev, "no usb3 phy configured\n");
 		return -EPROBE_DEFER;
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index c19f7f1..9c1a7a6 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -2456,7 +2456,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 
 #ifdef CONFIG_USB_OTG
 	if (pdata->operating_mode == FSL_USB2_DR_OTG) {
-		udc_controller->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
+		udc_controller->transceiver = usb_get_phy(&pdev->dev, 0);
 		if (IS_ERR_OR_NULL(udc_controller->transceiver)) {
 			ERR("Can't find OTG driver!\n");
 			ret = -ENODEV;
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
index 379aac7..9aef556 100644
--- a/drivers/usb/gadget/mv_udc_core.c
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -2218,7 +2218,7 @@ static int mv_udc_probe(struct platform_device *dev)
 
 #ifdef CONFIG_USB_OTG_UTILS
 	if (pdata->mode == MV_USB_MODE_OTG)
-		udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
+		udc->transceiver = usb_get_phy(&dev->dev, 0);
 #endif
 
 	udc->clknum = pdata->clknum;
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 8bfe990..5352ede 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -2833,7 +2833,7 @@ static int omap_udc_probe(struct platform_device *pdev)
 		 * use it.  Except for OTG, we don't _need_ to talk to one;
 		 * but not having one probably means no VBUS detection.
 		 */
-		xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
+		xceiv = usb_get_phy(&pdev->dev, 0);
 		if (!IS_ERR_OR_NULL(xceiv))
 			type = xceiv->label;
 		else if (config->otg) {
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index d4ca9f1..666f2c0c 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -2157,7 +2157,7 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
 	dev->dev = &pdev->dev;
 	dev->mach = pdev->dev.platform_data;
 
-	dev->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
+	dev->transceiver = usb_get_phy(dev->dev, 0);
 
 	if (gpio_is_valid(dev->mach->gpio_pullup)) {
 		if ((retval = gpio_request(dev->mach->gpio_pullup,
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 2b3b01d..844138c 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -2465,7 +2465,7 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
 
 	udc->dev = &pdev->dev;
 	udc->mach = pdev->dev.platform_data;
-	udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
+	udc->transceiver = usb_get_phy(udc->dev, 0);
 
 	gpio = udc->mach->gpio_pullup;
 	if (gpio_is_valid(gpio)) {
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index 52379b1..c1ca9f4 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -1281,7 +1281,7 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
 	hsudc->dev = dev;
 	hsudc->pd = pdev->dev.platform_data;
 
-	hsudc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
+	hsudc->transceiver = usb_get_phy(hsudc->dev, 0);
 
 	for (i = 0; i < ARRAY_SIZE(hsudc->supplies); i++)
 		hsudc->supplies[i].supply = s3c_hsudc_supply_names[i];
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index fd9b542..517df2e 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -143,7 +143,7 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
 	if (pdata->operating_mode == FSL_USB2_DR_OTG) {
 		struct ehci_hcd *ehci = hcd_to_ehci(hcd);
 
-		hcd->phy = usb_get_phy(USB_PHY_TYPE_USB2);
+		hcd->phy = usb_get_phy(&pdev->dev, 0);
 		dev_dbg(&pdev->dev, "hcd=0x%p  ehci=0x%p, phy=0x%p\n",
 			hcd, ehci, hcd->phy);
 
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 88a49c8..39abbdb 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -144,7 +144,7 @@ static int ehci_msm_probe(struct platform_device *pdev)
 	 * powering up VBUS, mapping of registers address space and power
 	 * management.
 	 */
-	phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
+	phy = devm_usb_get_phy(&pdev->dev, 0);
 	if (IS_ERR_OR_NULL(phy)) {
 		dev_err(&pdev->dev, "unable to find transceiver\n");
 		ret = -ENODEV;
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c
index f7bfc0b..6316950 100644
--- a/drivers/usb/host/ehci-mv.c
+++ b/drivers/usb/host/ehci-mv.c
@@ -241,7 +241,7 @@ static int mv_ehci_probe(struct platform_device *pdev)
 	ehci_mv->mode = pdata->mode;
 	if (ehci_mv->mode == MV_USB_MODE_OTG) {
 #ifdef CONFIG_USB_OTG_UTILS
-		ehci_mv->otg = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
+		ehci_mv->otg = devm_usb_get_phy(&pdev->dev, 0);
 		if (IS_ERR_OR_NULL(ehci_mv->otg)) {
 			dev_err(&pdev->dev,
 				"unable to find transceiver\n");
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index acf1755..7a081df 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -733,7 +733,7 @@ static int tegra_ehci_probe(struct platform_device *pdev)
 #ifdef CONFIG_USB_OTG_UTILS
 	if (pdata->operating_mode == TEGRA_USB_OTG) {
 		tegra->transceiver =
-			devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
+			devm_usb_get_phy(&pdev->dev, 0);
 		if (!IS_ERR_OR_NULL(tegra->transceiver))
 			otg_set_host(tegra->transceiver->otg, &hcd->self);
 	}
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index b1d32fb..bd823d2 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -213,7 +213,7 @@ static int ohci_omap_init(struct usb_hcd *hcd)
 
 #ifdef	CONFIG_USB_OTG
 	if (need_transceiver) {
-		hcd->phy = usb_get_phy(USB_PHY_TYPE_USB2);
+		hcd->phy = usb_get_phy(hcd->self.controller, 0);
 		if (!IS_ERR_OR_NULL(hcd->phy)) {
 			int	status = otg_set_host(hcd->phy->otg,
 						&ohci_to_hcd(ohci)->self);
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index c107d7c..b7a8c94 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -363,7 +363,7 @@ static int am35x_musb_init(struct musb *musb)
 		return -ENODEV;
 
 	usb_nop_xceiv_register();
-	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
+	musb->xceiv = usb_get_phy(dev, 0);
 	if (IS_ERR_OR_NULL(musb->xceiv))
 		return -ENODEV;
 
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index 14dab9f..596bc5b 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -403,7 +403,7 @@ static int bfin_musb_init(struct musb *musb)
 	gpio_direction_output(musb->config->gpio_vrsel, 0);
 
 	usb_nop_xceiv_register();
-	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
+	musb->xceiv = usb_get_phy(musb->controller, 0);
 	if (IS_ERR_OR_NULL(musb->xceiv)) {
 		gpio_free(musb->config->gpio_vrsel);
 		return -ENODEV;
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 97996af..a01844e 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -419,7 +419,7 @@ static int da8xx_musb_init(struct musb *musb)
 		goto fail;
 
 	usb_nop_xceiv_register();
-	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
+	musb->xceiv = usb_get_phy(musb->controller, 0);
 	if (IS_ERR_OR_NULL(musb->xceiv))
 		goto fail;
 
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index b1c01ca..66aa3f0 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -382,7 +382,7 @@ static int davinci_musb_init(struct musb *musb)
 	u32		revision;
 
 	usb_nop_xceiv_register();
-	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
+	musb->xceiv = usb_get_phy(musb->controller, 0);
 	if (IS_ERR_OR_NULL(musb->xceiv))
 		goto unregister;
 
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index e6f2ae8..d71cbf5 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -412,7 +412,7 @@ static int dsps_musb_init(struct musb *musb)
 
 	/* NOP driver needs change if supporting dual instance */
 	usb_nop_xceiv_register();
-	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
+	musb->xceiv = usb_get_phy(dev, 0);
 	if (IS_ERR_OR_NULL(musb->xceiv))
 		return -ENODEV;
 
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 3e7ceef..3628a50 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -346,7 +346,7 @@ static int omap2430_musb_init(struct musb *musb)
 	 * up through ULPI.  TWL4030-family PMICs include one,
 	 * which needs a driver, drivers aren't always needed.
 	 */
-	musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
+	musb->xceiv = devm_usb_get_phy(dev, 0);
 	if (IS_ERR_OR_NULL(musb->xceiv)) {
 		pr_err("HS USB OTG: no transceiver configured\n");
 		return -ENODEV;
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index 3969813..02338f6 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -1067,7 +1067,7 @@ static int tusb_musb_init(struct musb *musb)
 	int			ret;
 
 	usb_nop_xceiv_register();
-	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
+	musb->xceiv = usb_get_phy(musb->controller, 0);
 	if (IS_ERR_OR_NULL(musb->xceiv))
 		return -ENODEV;
 
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c
index a27ca1a..5affcf7 100644
--- a/drivers/usb/musb/ux500.c
+++ b/drivers/usb/musb/ux500.c
@@ -58,7 +58,7 @@ static irqreturn_t ux500_musb_interrupt(int irq, void *__hci)
 
 static int ux500_musb_init(struct musb *musb)
 {
-	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
+	musb->xceiv = usb_get_phy(musb->controller, 0);
 	if (IS_ERR_OR_NULL(musb->xceiv)) {
 		pr_err("HS USB OTG: no transceiver configured\n");
 		return -ENODEV;
diff --git a/drivers/usb/otg/ab8500-usb.c b/drivers/usb/otg/ab8500-usb.c
index 2d86f26..07aeb8c 100644
--- a/drivers/usb/otg/ab8500-usb.c
+++ b/drivers/usb/otg/ab8500-usb.c
@@ -502,6 +502,7 @@ static int ab8500_usb_probe(struct platform_device *pdev)
 	ab->phy.set_suspend	= ab8500_usb_set_suspend;
 	ab->phy.set_power	= ab8500_usb_set_power;
 	ab->phy.state		= OTG_STATE_UNDEFINED;
+	ab->phy.type		= USB_PHY_TYPE_USB2;
 
 	otg->phy		= &ab->phy;
 	otg->set_host		= ab8500_usb_set_host;
@@ -529,7 +530,7 @@ static int ab8500_usb_probe(struct platform_device *pdev)
 	if (err < 0)
 		goto fail0;
 
-	err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2);
+	err = usb_add_phy(&ab->phy);
 	if (err) {
 		dev_err(&pdev->dev, "Can't register transceiver\n");
 		goto fail1;
diff --git a/drivers/usb/otg/fsl_otg.c b/drivers/usb/otg/fsl_otg.c
index d16adb4..ae6d3f5 100644
--- a/drivers/usb/otg/fsl_otg.c
+++ b/drivers/usb/otg/fsl_otg.c
@@ -810,6 +810,7 @@ static int fsl_otg_conf(struct platform_device *pdev)
 	/* initialize the otg structure */
 	fsl_otg_tc->phy.label = DRIVER_DESC;
 	fsl_otg_tc->phy.set_power = fsl_otg_set_power;
+	fsl_otg_tc->phy.type = USB_PHY_TYPE_USB2;
 
 	fsl_otg_tc->phy.otg->phy = &fsl_otg_tc->phy;
 	fsl_otg_tc->phy.otg->set_host = fsl_otg_set_host;
@@ -820,7 +821,7 @@ static int fsl_otg_conf(struct platform_device *pdev)
 	fsl_otg_dev = fsl_otg_tc;
 
 	/* Store the otg transceiver */
-	status = usb_add_phy(&fsl_otg_tc->phy, USB_PHY_TYPE_USB2);
+	status = usb_add_phy(&fsl_otg_tc->phy);
 	if (status) {
 		pr_warn(FSL_OTG_NAME ": unable to register OTG transceiver.\n");
 		goto err;
@@ -838,7 +839,7 @@ err:
 int usb_otg_start(struct platform_device *pdev)
 {
 	struct fsl_otg *p_otg;
-	struct usb_phy *otg_trans = usb_get_phy(USB_PHY_TYPE_USB2);
+	struct usb_phy *otg_trans = usb_get_phy(&pdev->dev, 0);
 	struct otg_fsm *fsm;
 	int status;
 	struct resource *res;
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/otg/gpio_vbus.c
index a67ffe2..815e8dc 100644
--- a/drivers/usb/otg/gpio_vbus.c
+++ b/drivers/usb/otg/gpio_vbus.c
@@ -264,6 +264,7 @@ static int __init gpio_vbus_probe(struct platform_device *pdev)
 	gpio_vbus->phy.set_power = gpio_vbus_set_power;
 	gpio_vbus->phy.set_suspend = gpio_vbus_set_suspend;
 	gpio_vbus->phy.state = OTG_STATE_UNDEFINED;
+	gpio_vbus->phy.type = USB_PHY_TYPE_USB2;
 
 	gpio_vbus->phy.otg->phy = &gpio_vbus->phy;
 	gpio_vbus->phy.otg->set_peripheral = gpio_vbus_set_peripheral;
@@ -320,7 +321,7 @@ static int __init gpio_vbus_probe(struct platform_device *pdev)
 	}
 
 	/* only active when a gadget is registered */
-	err = usb_add_phy(&gpio_vbus->phy, USB_PHY_TYPE_USB2);
+	err = usb_add_phy(&gpio_vbus->phy);
 	if (err) {
 		dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
 			err);
diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/otg/isp1301_omap.c
index af9cb11..c85b309 100644
--- a/drivers/usb/otg/isp1301_omap.c
+++ b/drivers/usb/otg/isp1301_omap.c
@@ -1587,6 +1587,7 @@ isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 	isp->phy.dev = &i2c->dev;
 	isp->phy.label = DRIVER_NAME;
 	isp->phy.set_power = isp1301_set_power,
+	isp->phy.type = USB_PHY_TYPE_USB2,
 
 	isp->phy.otg->phy = &isp->phy;
 	isp->phy.otg->set_host = isp1301_set_host,
@@ -1610,7 +1611,7 @@ isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 	dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES);
 #endif
 
-	status = usb_add_phy(&isp->phy, USB_PHY_TYPE_USB2);
+	status = usb_add_phy(&isp->phy);
 	if (status < 0)
 		dev_err(&i2c->dev, "can't register transceiver, %d\n",
 			status);
diff --git a/drivers/usb/otg/msm_otg.c b/drivers/usb/otg/msm_otg.c
index 3b9f0d9..5376d84 100644
--- a/drivers/usb/otg/msm_otg.c
+++ b/drivers/usb/otg/msm_otg.c
@@ -1548,6 +1548,7 @@ static int __init msm_otg_probe(struct platform_device *pdev)
 
 	phy->init = msm_otg_reset;
 	phy->set_power = msm_otg_set_power;
+	phy->phy_type = USB_PHY_TYPE_USB2;
 
 	phy->io_ops = &msm_otg_io_ops;
 
@@ -1555,7 +1556,7 @@ static int __init msm_otg_probe(struct platform_device *pdev)
 	phy->otg->set_host = msm_otg_set_host;
 	phy->otg->set_peripheral = msm_otg_set_peripheral;
 
-	ret = usb_add_phy(&motg->phy, USB_PHY_TYPE_USB2);
+	ret = usb_add_phy(&motg->phy);
 	if (ret) {
 		dev_err(&pdev->dev, "usb_add_phy failed\n");
 		goto free_irq;
diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/otg/mv_otg.c
index 1dd5750..2167e41 100644
--- a/drivers/usb/otg/mv_otg.c
+++ b/drivers/usb/otg/mv_otg.c
@@ -755,6 +755,7 @@ static int mv_otg_probe(struct platform_device *pdev)
 	mvotg->phy.otg = otg;
 	mvotg->phy.label = driver_name;
 	mvotg->phy.state = OTG_STATE_UNDEFINED;
+	mvotg->phy.type = USB_PHY_TYPE_USB2;
 
 	otg->phy = &mvotg->phy;
 	otg->set_host = mv_otg_set_host;
@@ -853,7 +854,7 @@ static int mv_otg_probe(struct platform_device *pdev)
 		goto err_disable_clk;
 	}
 
-	retval = usb_add_phy(&mvotg->phy, USB_PHY_TYPE_USB2);
+	retval = usb_add_phy(&mvotg->phy);
 	if (retval < 0) {
 		dev_err(&pdev->dev, "can't register transceiver, %d\n",
 			retval);
diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/otg/nop-usb-xceiv.c
index a3ce24b..d8d72f6 100644
--- a/drivers/usb/otg/nop-usb-xceiv.c
+++ b/drivers/usb/otg/nop-usb-xceiv.c
@@ -118,12 +118,13 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev)
 	nop->phy.label		= "nop-xceiv";
 	nop->phy.set_suspend	= nop_set_suspend;
 	nop->phy.state		= OTG_STATE_UNDEFINED;
+	nop->phy.type		= type;
 
 	nop->phy.otg->phy		= &nop->phy;
 	nop->phy.otg->set_host		= nop_set_host;
 	nop->phy.otg->set_peripheral	= nop_set_peripheral;
 
-	err = usb_add_phy(&nop->phy, type);
+	err = usb_add_phy(&nop->phy);
 	if (err) {
 		dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
 			err);
diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index 492ba2f..dbf2043 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -21,16 +21,14 @@ static LIST_HEAD(phy_list);
 static LIST_HEAD(phy_bind_list);
 static DEFINE_SPINLOCK(phy_lock);
 
-static struct usb_phy *__usb_find_phy(struct list_head *list,
-	enum usb_phy_type type)
+static struct usb_phy *__usb_find_phy(struct device *dev, u8 index)
 {
-	struct usb_phy  *phy = NULL;
+	struct usb_phy_bind *phy_bind = NULL;
 
-	list_for_each_entry(phy, list, head) {
-		if (phy->type != type)
-			continue;
-
-		return phy;
+	list_for_each_entry(phy_bind, &phy_bind_list, list) {
+		if (!(strcmp(phy_bind->dev_name, dev_name(dev))) &&
+				phy_bind->index == index)
+			return phy_bind->phy;
 	}
 
 	return ERR_PTR(-ENODEV);
@@ -51,7 +49,7 @@ static int devm_usb_phy_match(struct device *dev, void *res, void *match_data)
 /**
  * devm_usb_get_phy - find the USB PHY
  * @dev - device that requests this phy
- * @type - the type of the phy the controller requires
+ * @index - the index of the phy
  *
  * Gets the phy using usb_get_phy(), and associates a device with it using
  * devres. On driver detach, release function is invoked on the devres data,
@@ -59,7 +57,7 @@ static int devm_usb_phy_match(struct device *dev, void *res, void *match_data)
  *
  * For use by USB host and peripheral drivers.
  */
-struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
+struct usb_phy *devm_usb_get_phy(struct device *dev, u8 index)
 {
 	struct usb_phy **ptr, *phy;
 
@@ -67,7 +65,7 @@ struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
 	if (!ptr)
 		return NULL;
 
-	phy = usb_get_phy(type);
+	phy = usb_get_phy(dev, index);
 	if (!IS_ERR(phy)) {
 		*ptr = phy;
 		devres_add(dev, ptr);
@@ -80,7 +78,8 @@ EXPORT_SYMBOL(devm_usb_get_phy);
 
 /**
  * usb_get_phy - find the USB PHY
- * @type - the type of the phy the controller requires
+ * @dev - device that requests this phy
+ * @index - the index of the phy
  *
  * Returns the phy driver, after getting a refcount to it; or
  * -ENODEV if there is no such phy.  The caller is responsible for
@@ -88,17 +87,16 @@ EXPORT_SYMBOL(devm_usb_get_phy);
  *
  * For use by USB host and peripheral drivers.
  */
-struct usb_phy *usb_get_phy(enum usb_phy_type type)
+struct usb_phy *usb_get_phy(struct device *dev, u8 index)
 {
 	struct usb_phy	*phy = NULL;
 	unsigned long	flags;
 
 	spin_lock_irqsave(&phy_lock, flags);
 
-	phy = __usb_find_phy(&phy_list, type);
+	phy = __usb_find_phy(dev, index);
 	if (IS_ERR(phy)) {
-		pr_err("unable to find transceiver of type %s\n",
-			usb_phy_type_string(type));
+		pr_err("unable to find phy\n");
 		goto err0;
 	}
 
@@ -148,40 +146,30 @@ EXPORT_SYMBOL(usb_put_phy);
 /**
  * usb_add_phy - declare the USB PHY
  * @x: the USB phy to be used; or NULL
- * @type - the type of this PHY
  *
  * This call is exclusively for use by phy drivers, which
  * coordinate the activities of drivers for host and peripheral
  * controllers, and in some cases for VBUS current regulation.
  */
-int usb_add_phy(struct usb_phy *x, enum usb_phy_type type)
+int usb_add_phy(struct usb_phy *x)
 {
-	int		ret = 0;
-	unsigned long	flags;
-	struct usb_phy	*phy;
+	struct usb_phy_bind *phy_bind;
+	unsigned long flags;
 
-	if (x->type != USB_PHY_TYPE_UNDEFINED) {
-		dev_err(x->dev, "not accepting initialized PHY %s\n", x->label);
+	if (!x->dev) {
+		dev_err(x->dev, "no device provided for PHY\n");
 		return -EINVAL;
 	}
 
 	spin_lock_irqsave(&phy_lock, flags);
+	list_for_each_entry(phy_bind, &phy_bind_list, list)
+		if (!(strcmp(phy_bind->phy_dev_name, dev_name(x->dev))))
+			phy_bind->phy = x;
 
-	list_for_each_entry(phy, &phy_list, head) {
-		if (phy->type == type) {
-			ret = -EBUSY;
-			dev_err(x->dev, "transceiver type %s already exists\n",
-						usb_phy_type_string(type));
-			goto out;
-		}
-	}
-
-	x->type = type;
 	list_add_tail(&x->head, &phy_list);
-
-out:
 	spin_unlock_irqrestore(&phy_lock, flags);
-	return ret;
+
+	return 0;
 }
 EXPORT_SYMBOL(usb_add_phy);
 
@@ -194,10 +182,15 @@ EXPORT_SYMBOL(usb_add_phy);
 void usb_remove_phy(struct usb_phy *x)
 {
 	unsigned long	flags;
+	struct usb_phy_bind *phy_bind;
 
 	spin_lock_irqsave(&phy_lock, flags);
-	if (x)
+	if (x) {
+		list_for_each_entry(phy_bind, &phy_bind_list, list)
+			if (phy_bind->phy == x)
+				phy_bind->phy = NULL;
 		list_del(&x->head);
+	}
 	spin_unlock_irqrestore(&phy_lock, flags);
 }
 EXPORT_SYMBOL(usb_remove_phy);
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
index 0a70193..f6bdd75 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/otg/twl4030-usb.c
@@ -611,6 +611,7 @@ static int twl4030_usb_probe(struct platform_device *pdev)
 	twl->phy.label		= "twl4030";
 	twl->phy.otg		= otg;
 	twl->phy.set_suspend	= twl4030_set_suspend;
+	twl->phy.type		= USB_PHY_TYPE_USB2;
 
 	otg->phy		= &twl->phy;
 	otg->set_host		= twl4030_set_host;
@@ -624,7 +625,7 @@ static int twl4030_usb_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "ldo init failed\n");
 		return err;
 	}
-	usb_add_phy(&twl->phy, USB_PHY_TYPE_USB2);
+	usb_add_phy(&twl->phy);
 
 	platform_set_drvdata(pdev, twl);
 	if (device_create_file(&pdev->dev, &dev_attr_vbus))
diff --git a/drivers/usb/phy/mv_u3d_phy.c b/drivers/usb/phy/mv_u3d_phy.c
index eaddbe3..31a19a3 100644
--- a/drivers/usb/phy/mv_u3d_phy.c
+++ b/drivers/usb/phy/mv_u3d_phy.c
@@ -298,10 +298,11 @@ static int mv_u3d_phy_probe(struct platform_device *pdev)
 	mv_u3d_phy->base		= phy_base;
 	mv_u3d_phy->phy.dev		= mv_u3d_phy->dev;
 	mv_u3d_phy->phy.label		= "mv-u3d-phy";
+	mv_u3d_phy->phy.type		= USB_PHY_TYPE_USB3;
 	mv_u3d_phy->phy.init		= mv_u3d_phy_init;
 	mv_u3d_phy->phy.shutdown	= mv_u3d_phy_shutdown;
 
-	ret = usb_add_phy(&mv_u3d_phy->phy, USB_PHY_TYPE_USB3);
+	ret = usb_add_phy(&mv_u3d_phy->phy);
 	if (ret)
 		goto err;
 
diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/omap-usb2.c
index 2152ce4..0e7636f 100644
--- a/drivers/usb/phy/omap-usb2.c
+++ b/drivers/usb/phy/omap-usb2.c
@@ -29,6 +29,7 @@
 #include <linux/delay.h>
 #include <linux/usb/omap_control_usb.h>
 
+static struct omap_usb	*phy;
 /**
  * omap_usb2_set_comparator - links the comparator present in the sytem with
  *	this phy
@@ -41,13 +42,9 @@
  */
 int omap_usb2_set_comparator(struct phy_companion *comparator)
 {
-	struct omap_usb	*phy;
-	struct usb_phy	*x = usb_get_phy(USB_PHY_TYPE_USB2);
-
-	if (IS_ERR(x))
+	if (!phy)
 		return -ENODEV;
 
-	phy = phy_to_omapusb(x);
 	phy->comparator = comparator;
 	return 0;
 }
@@ -121,7 +118,6 @@ static int omap_usb2_suspend(struct usb_phy *x, int suspend)
 
 static int omap_usb2_probe(struct platform_device *pdev)
 {
-	struct omap_usb			*phy;
 	struct usb_otg			*otg;
 	struct resource			*res;
 
@@ -141,6 +137,7 @@ static int omap_usb2_probe(struct platform_device *pdev)
 
 	phy->phy.dev		= phy->dev;
 	phy->phy.label		= "omap-usb2";
+	phy->phy.type		= USB_PHY_TYPE_USB2;
 	phy->phy.set_suspend	= omap_usb2_suspend;
 	phy->phy.otg		= otg;
 
@@ -168,7 +165,7 @@ static int omap_usb2_probe(struct platform_device *pdev)
 	}
 	clk_prepare(phy->wkupclk);
 
-	usb_add_phy(&phy->phy, USB_PHY_TYPE_USB2);
+	usb_add_phy(&phy->phy);
 
 	platform_set_drvdata(pdev, phy);
 
diff --git a/drivers/usb/phy/rcar-phy.c b/drivers/usb/phy/rcar-phy.c
index a35681b..bd00fd9 100644
--- a/drivers/usb/phy/rcar-phy.c
+++ b/drivers/usb/phy/rcar-phy.c
@@ -181,11 +181,12 @@ static int rcar_usb_phy_probe(struct platform_device *pdev)
 	priv->counter		= 0;
 	priv->phy.dev		= dev;
 	priv->phy.label		= dev_name(dev);
+	priv->phy.type		= USB_PHY_TYPE_USB2;
 	priv->phy.init		= rcar_usb_phy_init;
 	priv->phy.shutdown	= rcar_usb_phy_shutdown;
 	spin_lock_init(&priv->lock);
 
-	ret = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2);
+	ret = usb_add_phy(&priv->phy);
 	if (ret < 0) {
 		dev_err(dev, "usb phy addition error\n");
 		return ret;
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index fbeab1a..d133c8b 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -123,7 +123,7 @@ struct usb_phy_bind {
 };
 
 /* for board-specific init logic */
-extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type);
+extern int usb_add_phy(struct usb_phy *);
 extern void usb_remove_phy(struct usb_phy *);
 
 /* helpers for direct access thru low-level io interface */
@@ -161,21 +161,19 @@ usb_phy_shutdown(struct usb_phy *x)
 
 /* for usb host and peripheral controller drivers */
 #ifdef CONFIG_USB_OTG_UTILS
-extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
-extern struct usb_phy *devm_usb_get_phy(struct device *dev,
-	enum usb_phy_type type);
+extern struct usb_phy *usb_get_phy(struct device *dev, u8 index);
+extern struct usb_phy *devm_usb_get_phy(struct device *dev, u8 index);
 extern void usb_put_phy(struct usb_phy *);
 extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
 extern struct usb_phy_bind *usb_bind_phy(const char *dev_name, u8 index,
 				const char *phy_dev_name);
 #else
-static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
+static inline struct usb_phy *usb_get_phy(struct device *dev, u8 index)
 {
 	return NULL;
 }
 
-static inline struct usb_phy *devm_usb_get_phy(struct device *dev,
-	enum usb_phy_type type)
+static inline struct usb_phy *devm_usb_get_phy(struct device *dev, u8 index)
 {
 	return NULL;
 }
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [RFC PATCH 4/6] ARM: dts: OMAP: Add phandle to bind PHY with USB controller
  2013-01-16 15:00 [RFC PATCH 0/6] USB: Add multiple PHYs of same type Kishon Vijay Abraham I
                   ` (2 preceding siblings ...)
  2013-01-16 15:00 ` [RFC PATCH 3/6] usb: otg: utils: change the phy lib to support multiple PHYs of same type Kishon Vijay Abraham I
@ 2013-01-16 15:01 ` Kishon Vijay Abraham I
  2013-01-16 15:01 ` [RFC PATCH 5/6] usb: otg: add device tree support to otg library Kishon Vijay Abraham I
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 26+ messages in thread
From: Kishon Vijay Abraham I @ 2013-01-16 15:01 UTC (permalink / raw)
  To: devicetree-discuss, linux-doc, linux-kernel, linux-omap,
	linux-arm-kernel, linux-usb, linux-sh, linuxppc-dev, balbi
  Cc: linux, b-cousson, tony, gregkh, rob.herring, kishon, cbou,
	alexander.shishkin, horms, stern, haojian.zhuang, rob,
	eric.y.miao, dwmw2

Added a phandle in the dt node for usb_otg to bind the PHY with the USB
controller and also updated the documentation with the binding information.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
I'll add this patch in this series "usb: musb: add driver for control module"
which contains the dt data to get MUSB working in dt boot in OMAP platforms.
 Documentation/devicetree/bindings/usb/omap-usb.txt |    2 ++
 arch/arm/boot/dts/omap3.dtsi                       |    1 +
 arch/arm/boot/dts/omap4.dtsi                       |    3 ++-
 arch/arm/boot/dts/twl4030.dtsi                     |    2 +-
 4 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt
index 3f0152b..591c4fc 100644
--- a/Documentation/devicetree/bindings/usb/omap-usb.txt
+++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
@@ -18,6 +18,7 @@ OMAP MUSB GLUE
    represents PERIPHERAL.
  - power : Should be "50". This signifies the controller can supply upto
    100mA when operating in host mode.
+ - usb_phy : the phandle for the PHY device
 
 SOC specific device node entry
 usb_otg_hs: usb_otg_hs@4a0ab000 {
@@ -27,6 +28,7 @@ usb_otg_hs: usb_otg_hs@4a0ab000 {
 	multipoint = <1>;
 	num_eps = <16>;
 	ram_bits = <12>;
+	usb_phy = <&phy>;
 };
 
 Board specific device node entry
diff --git a/arch/arm/boot/dts/omap3.dtsi b/arch/arm/boot/dts/omap3.dtsi
index 8d03736..ebbf596 100644
--- a/arch/arm/boot/dts/omap3.dtsi
+++ b/arch/arm/boot/dts/omap3.dtsi
@@ -404,6 +404,7 @@
 			interrupts = <0 92 0x4>, <0 93 0x4>;
 			interrupt-names = "mc", "dma";
 			ti,hwmods = "usb_otg_hs";
+			usb_phy = <&phy>;
 			multipoint = <1>;
 			num_eps = <16>;
 			ram_bits = <12>;
diff --git a/arch/arm/boot/dts/omap4.dtsi b/arch/arm/boot/dts/omap4.dtsi
index 5d770be..531cb2d 100644
--- a/arch/arm/boot/dts/omap4.dtsi
+++ b/arch/arm/boot/dts/omap4.dtsi
@@ -438,7 +438,7 @@
 			#size-cells = <1>;
 			ranges;
 			ti,hwmods = "ocp2scp_usb_phy";
-			usb2phy@4a0ad080 {
+			phy: usb2phy@4a0ad080 {
 				compatible = "ti,omap-usb2";
 				reg = <0x4a0ad080 0x58>;
 			};
@@ -540,6 +540,7 @@
 			interrupts = <0 92 0x4>, <0 93 0x4>;
 			interrupt-names = "mc", "dma";
 			ti,hwmods = "usb_otg_hs";
+			usb_phy = <&phy>;
 			multipoint = <1>;
 			num_eps = <16>;
 			ram_bits = <12>;
diff --git a/arch/arm/boot/dts/twl4030.dtsi b/arch/arm/boot/dts/twl4030.dtsi
index ed0bc95..80f7c2b 100644
--- a/arch/arm/boot/dts/twl4030.dtsi
+++ b/arch/arm/boot/dts/twl4030.dtsi
@@ -67,7 +67,7 @@
 		#interrupt-cells = <1>;
 	};
 
-	twl4030-usb {
+	phy: twl4030-usb {
 		compatible = "ti,twl4030-usb";
 		interrupts = <10>, <4>;
 		usb1v5-supply = <&vusb1v5>;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [RFC PATCH 5/6] usb: otg: add device tree support to otg library
  2013-01-16 15:00 [RFC PATCH 0/6] USB: Add multiple PHYs of same type Kishon Vijay Abraham I
                   ` (3 preceding siblings ...)
  2013-01-16 15:01 ` [RFC PATCH 4/6] ARM: dts: OMAP: Add phandle to bind PHY with USB controller Kishon Vijay Abraham I
@ 2013-01-16 15:01 ` Kishon Vijay Abraham I
  2013-01-21 13:21   ` Roger Quadros
  2013-01-16 15:01 ` [RFC PATCH 6/6] USB: MUSB: OMAP: get PHY by phandle for dt boot Kishon Vijay Abraham I
  2013-01-18 11:48 ` [RFC PATCH 0/6] USB: Add multiple PHYs of same type Felipe Balbi
  6 siblings, 1 reply; 26+ messages in thread
From: Kishon Vijay Abraham I @ 2013-01-16 15:01 UTC (permalink / raw)
  To: devicetree-discuss, linux-doc, linux-kernel, linux-omap,
	linux-arm-kernel, linux-usb, linux-sh, linuxppc-dev, balbi
  Cc: linux, b-cousson, tony, gregkh, rob.herring, kishon, cbou,
	alexander.shishkin, horms, stern, haojian.zhuang, rob,
	eric.y.miao, Marc Kleine-Budde, dwmw2

Added an API devm_usb_get_phy_by_phandle(), to get usb phy by passing a
device node phandle value. This function will return a pointer to
the phy on success, -EPROBE_DEFER if there is a device_node for the phandle,
but the phy has not been added, or a ERR_PTR() otherwise.

Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/otg/otg.c   |   77 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/usb/phy.h |    8 +++++
 2 files changed, 85 insertions(+)

diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index dbf2043..e9799bb 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -13,7 +13,9 @@
 #include <linux/export.h>
 #include <linux/err.h>
 #include <linux/device.h>
+#include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/of.h>
 
 #include <linux/usb/otg.h>
 
@@ -34,6 +36,20 @@ static struct usb_phy *__usb_find_phy(struct device *dev, u8 index)
 	return ERR_PTR(-ENODEV);
 }
 
+static struct usb_phy *__of_usb_find_phy(struct device_node *node)
+{
+	struct usb_phy  *phy;
+
+	list_for_each_entry(phy, &phy_list, head) {
+		if (node != phy->dev->of_node)
+			continue;
+
+		return phy;
+	}
+
+	return ERR_PTR(-ENODEV);
+}
+
 static void devm_usb_phy_release(struct device *dev, void *res)
 {
 	struct usb_phy *phy = *(struct usb_phy **)res;
@@ -109,6 +125,67 @@ err0:
 }
 EXPORT_SYMBOL(usb_get_phy);
 
+ /**
+ * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
+ * @dev - device that requests this phy
+ * @phandle - name of the property holding the phy phandle value
+ * @index - the index of the phy
+ *
+ * Returns the phy driver associated with the given phandle value,
+ * after getting a refcount to it, -ENODEV if there is no such phy or
+ * -EPROBE_DEFER if there is a phandle to the phy, but the device is
+ * not yet loaded. While at that, it also associates the device with
+ * the phy using devres. On driver detach, release function is invoked
+ * on the devres data, then, devres data is freed.
+ *
+ * For use by USB host and peripheral drivers.
+ */
+struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
+	const char *phandle, u8 index)
+{
+	struct usb_phy	*phy = NULL, **ptr;
+	unsigned long	flags;
+	struct device_node *node;
+
+	if (!dev->of_node) {
+		dev_dbg(dev, "device does not have a device node entry\n");
+		return ERR_PTR(-EINVAL);
+	}
+
+	node = of_parse_phandle(dev->of_node, phandle, index);
+	if (!node) {
+		dev_dbg(dev, "failed to get %s phandle in %s node\n", phandle,
+			dev->of_node->full_name);
+		return ERR_PTR(-ENODEV);
+	}
+
+	ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr) {
+		dev_dbg(dev, "failed to allocate memory for devres\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	spin_lock_irqsave(&phy_lock, flags);
+
+	phy = __of_usb_find_phy(node);
+	if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
+		phy = ERR_PTR(-EPROBE_DEFER);
+		devres_free(ptr);
+		goto err0;
+	}
+
+	*ptr = phy;
+	devres_add(dev, ptr);
+
+	get_device(phy->dev);
+
+err0:
+	spin_unlock_irqrestore(&phy_lock, flags);
+
+	return phy;
+}
+EXPORT_SYMBOL(devm_usb_get_phy_by_phandle);
+
 /**
  * devm_usb_put_phy - release the USB PHY
  * @dev - device that wants to release this phy
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index d133c8b..5836b6d 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -163,6 +163,8 @@ usb_phy_shutdown(struct usb_phy *x)
 #ifdef CONFIG_USB_OTG_UTILS
 extern struct usb_phy *usb_get_phy(struct device *dev, u8 index);
 extern struct usb_phy *devm_usb_get_phy(struct device *dev, u8 index);
+extern struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
+	const char *phandle, u8 index);
 extern void usb_put_phy(struct usb_phy *);
 extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
 extern struct usb_phy_bind *usb_bind_phy(const char *dev_name, u8 index,
@@ -178,6 +180,12 @@ static inline struct usb_phy *devm_usb_get_phy(struct device *dev, u8 index)
 	return NULL;
 }
 
+static inline struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
+	const char *phandle, u8 index)
+{
+	return NULL;
+}
+
 static inline void usb_put_phy(struct usb_phy *x)
 {
 }
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [RFC PATCH 6/6] USB: MUSB: OMAP: get PHY by phandle for dt boot
  2013-01-16 15:00 [RFC PATCH 0/6] USB: Add multiple PHYs of same type Kishon Vijay Abraham I
                   ` (4 preceding siblings ...)
  2013-01-16 15:01 ` [RFC PATCH 5/6] usb: otg: add device tree support to otg library Kishon Vijay Abraham I
@ 2013-01-16 15:01 ` Kishon Vijay Abraham I
  2013-01-21 13:18   ` Roger Quadros
  2013-01-18 11:48 ` [RFC PATCH 0/6] USB: Add multiple PHYs of same type Felipe Balbi
  6 siblings, 1 reply; 26+ messages in thread
From: Kishon Vijay Abraham I @ 2013-01-16 15:01 UTC (permalink / raw)
  To: devicetree-discuss, linux-doc, linux-kernel, linux-omap,
	linux-arm-kernel, linux-usb, linux-sh, linuxppc-dev, balbi
  Cc: linux, b-cousson, tony, gregkh, rob.herring, kishon, cbou,
	alexander.shishkin, horms, stern, haojian.zhuang, rob,
	eric.y.miao, dwmw2

The OMAP glue has been modified to get PHY by phandle for dt boot.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/musb/omap2430.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 3628a50..08709cf 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -346,7 +346,12 @@ static int omap2430_musb_init(struct musb *musb)
 	 * up through ULPI.  TWL4030-family PMICs include one,
 	 * which needs a driver, drivers aren't always needed.
 	 */
-	musb->xceiv = devm_usb_get_phy(dev, 0);
+	if (dev->parent->of_node)
+		musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent,
+		    "usb_phy", 0);
+	else
+		musb->xceiv = devm_usb_get_phy(dev, 0);
+
 	if (IS_ERR_OR_NULL(musb->xceiv)) {
 		pr_err("HS USB OTG: no transceiver configured\n");
 		return -ENODEV;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 3/6] usb: otg: utils: change the phy lib to support multiple PHYs of same type
  2013-01-16 15:00 ` [RFC PATCH 3/6] usb: otg: utils: change the phy lib to support multiple PHYs of same type Kishon Vijay Abraham I
@ 2013-01-17  0:31   ` Simon Horman
  2013-01-17 16:07   ` Roger Quadros
  1 sibling, 0 replies; 26+ messages in thread
From: Simon Horman @ 2013-01-17  0:31 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, haojian.zhuang,
	linux-omap, linux-arm-kernel, eric.y.miao, b-cousson, gregkh,
	linux-usb, linux-kernel, balbi, cbou, rob, dwmw2

On Wed, Jan 16, 2013 at 08:30:59PM +0530, Kishon Vijay Abraham I wrote:
> In order to add support for multipe PHY's of the same type, the API's
> for adding PHY and getting PHY has been changed. Now the binding
> information of the PHY and controller should be done in platform file
> using usb_bind_phy API. And for getting a PHY, the device pointer of the
> USB controller and an index should be passed. Based on the binding
> information that is added in the platform file, get_phy will return the
> approappropriate PHY.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  arch/arm/mach-shmobile/board-marzen.c |    2 +-

Modification to the above file:

Acked-by: Simon Horman <horms+renesas@verge.net.au>

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 1/6] usb: otg: Add an API to bind the USB controller and PHY
  2013-01-16 15:00 ` [RFC PATCH 1/6] usb: otg: Add an API to bind the USB controller and PHY Kishon Vijay Abraham I
@ 2013-01-17  9:37   ` Roger Quadros
  2013-01-17 11:14     ` kishon
  0 siblings, 1 reply; 26+ messages in thread
From: Roger Quadros @ 2013-01-17  9:37 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

On 01/16/2013 05:00 PM, Kishon Vijay Abraham I wrote:
> New platforms are added which has multiple PHY's (of same type) and
> which has multiple USB controllers. The binding information has to be
> present in the PHY library (otg.c) in order for it to return the
> appropriate PHY whenever the USB controller request for the PHY. So
> added a new API to pass the binding information. This API should be
> called by platform specific initialization code.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/otg/otg.c   |   37 +++++++++++++++++++++++++++++++++++++
>  include/linux/usb/phy.h |   22 ++++++++++++++++++++++
>  2 files changed, 59 insertions(+)
> 
> diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
> index a30c041..492ba2f 100644
> --- a/drivers/usb/otg/otg.c
> +++ b/drivers/usb/otg/otg.c
> @@ -18,6 +18,7 @@
>  #include <linux/usb/otg.h>
>  
>  static LIST_HEAD(phy_list);
> +static LIST_HEAD(phy_bind_list);
>  static DEFINE_SPINLOCK(phy_lock);
>  
>  static struct usb_phy *__usb_find_phy(struct list_head *list,
> @@ -201,6 +202,42 @@ void usb_remove_phy(struct usb_phy *x)
>  }
>  EXPORT_SYMBOL(usb_remove_phy);
>  
> +/**
> + * usb_bind_phy - bind the phy and the controller that uses the phy
> + * @dev_name: the device name of the device that will bind to the phy
> + * @index: index to specify the port number
> + * @phy_dev_name: the device name of the phy
> + *
> + * Fills the phy_bind structure with the dev_name and phy_dev_name. This will
> + * be used when the phy driver registers the phy and when the controller
> + * requests this phy.
> + *
> + * To be used by platform specific initialization code.
> + */
> +struct usb_phy_bind __init *usb_bind_phy(const char *dev_name, u8 index,
> +				const char *phy_dev_name)
> +{
> +	struct usb_phy_bind *phy_bind;
> +	unsigned long flags;
> +
> +	phy_bind = kzalloc(sizeof(*phy_bind), GFP_KERNEL);
> +	if (!phy_bind) {
> +		pr_err("phy_bind(): No memory for phy_bind");

Function name in comment doesn't match the actual.
Instead, you could use
	pr_err("%s ...", __func__);

> +		return ERR_PTR(-ENOMEM);
> +	}
> +
> +	phy_bind->dev_name = dev_name;
> +	phy_bind->phy_dev_name = phy_dev_name;
> +	phy_bind->index = index;
> +
> +	spin_lock_irqsave(&phy_lock, flags);
> +	list_add_tail(&phy_bind->list, &phy_bind_list);
> +	spin_unlock_irqrestore(&phy_lock, flags);
> +
> +	return phy_bind;
> +}
> +EXPORT_SYMBOL_GPL(usb_bind_phy);
> +
>  const char *otg_state_string(enum usb_otg_state state)
>  {
>  	switch (state) {
> diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
> index a29ae1e..fbeab1a 100644
> --- a/include/linux/usb/phy.h
> +++ b/include/linux/usb/phy.h
> @@ -106,6 +106,21 @@ struct usb_phy {
>  			enum usb_device_speed speed);
>  };
>  
> +/**
> + * struct usb_phy_bind - represent the binding for the phy
> + * @dev_name: the device name of the device that will bind to the phy
> + * @phy_dev_name: the device name of the phy
> + * @index: used if a single controller uses multiple phys
> + * @phy: reference to the phy
> + * @list: to maintain a linked list of the binding information
> + */
> +struct usb_phy_bind {
> +	const char	*dev_name;
> +	const char	*phy_dev_name;
> +	u8		index;
> +	struct usb_phy	*phy;
> +	struct list_head list;
> +};
>  
>  /* for board-specific init logic */
>  extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type);
> @@ -151,6 +166,8 @@ extern struct usb_phy *devm_usb_get_phy(struct device *dev,
>  	enum usb_phy_type type);
>  extern void usb_put_phy(struct usb_phy *);
>  extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
> +extern struct usb_phy_bind *usb_bind_phy(const char *dev_name, u8 index,
> +				const char *phy_dev_name);
>  #else
>  static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
>  {
> @@ -171,6 +188,11 @@ static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
>  {
>  }
>  
> +static inline struct usb_phy_bind *usb_bind_phy(const char *dev_name, u8 index,
> +				const char *phy_dev_name)
> +{
> +	return NULL;
> +}
>  #endif
>  
>  static inline int
> 

Controllers like ehci-omap which don't need OTG functionality would
benefit from this API. Can we make these PHY APIs not dependent on OTG /
OTG_UTILS?

cheers,
-roger

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 2/6] ARM: OMAP: USB: Add phy binding information
  2013-01-16 15:00 ` [RFC PATCH 2/6] ARM: OMAP: USB: Add phy binding information Kishon Vijay Abraham I
@ 2013-01-17  9:39   ` Roger Quadros
  2013-01-17 11:03     ` kishon
  2013-01-17 12:11   ` Vivek Gautam
  1 sibling, 1 reply; 26+ messages in thread
From: Roger Quadros @ 2013-01-17  9:39 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

On 01/16/2013 05:00 PM, Kishon Vijay Abraham I wrote:
> This is in preparation for the changes in PHY library to support adding
> and getting multiple PHYs of the same type. In the new design, the
> binding information between the PHY and the USB controller should be
> specified in the platform specific initialization code. So it's been
> done for OMAP platforms here.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
> This kind-of binding should be done in all the platforms (I've done only
> for OMAP platform). 
>  arch/arm/mach-omap2/usb-musb.c |    7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/mach-omap2/usb-musb.c b/arch/arm/mach-omap2/usb-musb.c
> index 9d27e3f..bbe2fa5 100644
> --- a/arch/arm/mach-omap2/usb-musb.c
> +++ b/arch/arm/mach-omap2/usb-musb.c
> @@ -24,6 +24,7 @@
>  #include <linux/dma-mapping.h>
>  #include <linux/io.h>
>  #include <linux/usb/musb.h>
> +#include <linux/usb/phy.h>
>  
>  #include "omap_device.h"
>  #include "soc.h"
> @@ -85,8 +86,12 @@ void __init usb_musb_init(struct omap_musb_board_data *musb_board_data)
>  	musb_plat.mode = board_data->mode;
>  	musb_plat.extvbus = board_data->extvbus;
>  
> -	if (cpu_is_omap44xx())
> +	if (cpu_is_omap44xx()) {
>  		musb_plat.has_mailbox = true;
> +		usb_bind_phy("musb-hdrc.0.auto", 0, "omap-usb2.1.auto");
> +	} else if (cpu_is_omap34xx()) {
> +		usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb");
> +	}

Are you sure than these OMAP platforms cannot be wired in any other way
to the PHY?

If they can be then this association must come from the board files or
device tree.

>  
>  	if (soc_is_am35xx()) {
>  		oh_name = "am35x_otg_hs";
> 

--
cheers,
-roger

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 2/6] ARM: OMAP: USB: Add phy binding information
  2013-01-17  9:39   ` Roger Quadros
@ 2013-01-17 11:03     ` kishon
  0 siblings, 0 replies; 26+ messages in thread
From: kishon @ 2013-01-17 11:03 UTC (permalink / raw)
  To: Roger Quadros
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

Hi,

On Thursday 17 January 2013 03:09 PM, Roger Quadros wrote:
> On 01/16/2013 05:00 PM, Kishon Vijay Abraham I wrote:
>> This is in preparation for the changes in PHY library to support adding
>> and getting multiple PHYs of the same type. In the new design, the
>> binding information between the PHY and the USB controller should be
>> specified in the platform specific initialization code. So it's been
>> done for OMAP platforms here.
>>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> ---
>> This kind-of binding should be done in all the platforms (I've done only
>> for OMAP platform).
>>   arch/arm/mach-omap2/usb-musb.c |    7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm/mach-omap2/usb-musb.c b/arch/arm/mach-omap2/usb-musb.c
>> index 9d27e3f..bbe2fa5 100644
>> --- a/arch/arm/mach-omap2/usb-musb.c
>> +++ b/arch/arm/mach-omap2/usb-musb.c
>> @@ -24,6 +24,7 @@
>>   #include <linux/dma-mapping.h>
>>   #include <linux/io.h>
>>   #include <linux/usb/musb.h>
>> +#include <linux/usb/phy.h>
>>
>>   #include "omap_device.h"
>>   #include "soc.h"
>> @@ -85,8 +86,12 @@ void __init usb_musb_init(struct omap_musb_board_data *musb_board_data)
>>   	musb_plat.mode = board_data->mode;
>>   	musb_plat.extvbus = board_data->extvbus;
>>
>> -	if (cpu_is_omap44xx())
>> +	if (cpu_is_omap44xx()) {
>>   		musb_plat.has_mailbox = true;
>> +		usb_bind_phy("musb-hdrc.0.auto", 0, "omap-usb2.1.auto");
>> +	} else if (cpu_is_omap34xx()) {
>> +		usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb");
>> +	}
>
> Are you sure than these OMAP platforms cannot be wired in any other way
> to the PHY?
>
> If they can be then this association must come from the board files or
> device tree.

I had given some thought about that and since all the existing OMAP 
platforms had it this way, I added it here.
You having pointed that out, I'll move these to board files.

Thanks
Kishon

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 1/6] usb: otg: Add an API to bind the USB controller and PHY
  2013-01-17  9:37   ` Roger Quadros
@ 2013-01-17 11:14     ` kishon
  2013-01-18 11:48       ` Felipe Balbi
  0 siblings, 1 reply; 26+ messages in thread
From: kishon @ 2013-01-17 11:14 UTC (permalink / raw)
  To: Roger Quadros
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

Hi,

On Thursday 17 January 2013 03:07 PM, Roger Quadros wrote:
> On 01/16/2013 05:00 PM, Kishon Vijay Abraham I wrote:
>> New platforms are added which has multiple PHY's (of same type) and
>> which has multiple USB controllers. The binding information has to be
>> present in the PHY library (otg.c) in order for it to return the
>> appropriate PHY whenever the USB controller request for the PHY. So
>> added a new API to pass the binding information. This API should be
>> called by platform specific initialization code.
>>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> ---
>>   drivers/usb/otg/otg.c   |   37 +++++++++++++++++++++++++++++++++++++
>>   include/linux/usb/phy.h |   22 ++++++++++++++++++++++
>>   2 files changed, 59 insertions(+)
>>
>> diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
>> index a30c041..492ba2f 100644
>> --- a/drivers/usb/otg/otg.c
>> +++ b/drivers/usb/otg/otg.c
>> @@ -18,6 +18,7 @@
>>   #include <linux/usb/otg.h>
>>
>>   static LIST_HEAD(phy_list);
>> +static LIST_HEAD(phy_bind_list);
>>   static DEFINE_SPINLOCK(phy_lock);
>>
>>   static struct usb_phy *__usb_find_phy(struct list_head *list,
>> @@ -201,6 +202,42 @@ void usb_remove_phy(struct usb_phy *x)
>>   }
>>   EXPORT_SYMBOL(usb_remove_phy);
>>
>> +/**
>> + * usb_bind_phy - bind the phy and the controller that uses the phy
>> + * @dev_name: the device name of the device that will bind to the phy
>> + * @index: index to specify the port number
>> + * @phy_dev_name: the device name of the phy
>> + *
>> + * Fills the phy_bind structure with the dev_name and phy_dev_name. This will
>> + * be used when the phy driver registers the phy and when the controller
>> + * requests this phy.
>> + *
>> + * To be used by platform specific initialization code.
>> + */
>> +struct usb_phy_bind __init *usb_bind_phy(const char *dev_name, u8 index,
>> +				const char *phy_dev_name)
>> +{
>> +	struct usb_phy_bind *phy_bind;
>> +	unsigned long flags;
>> +
>> +	phy_bind = kzalloc(sizeof(*phy_bind), GFP_KERNEL);
>> +	if (!phy_bind) {
>> +		pr_err("phy_bind(): No memory for phy_bind");
>
> Function name in comment doesn't match the actual.
> Instead, you could use
> 	pr_err("%s ...", __func__);
>
>> +		return ERR_PTR(-ENOMEM);
>> +	}
>> +
>> +	phy_bind->dev_name = dev_name;
>> +	phy_bind->phy_dev_name = phy_dev_name;
>> +	phy_bind->index = index;
>> +
>> +	spin_lock_irqsave(&phy_lock, flags);
>> +	list_add_tail(&phy_bind->list, &phy_bind_list);
>> +	spin_unlock_irqrestore(&phy_lock, flags);
>> +
>> +	return phy_bind;
>> +}
>> +EXPORT_SYMBOL_GPL(usb_bind_phy);
>> +
>>   const char *otg_state_string(enum usb_otg_state state)
>>   {
>>   	switch (state) {
>> diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
>> index a29ae1e..fbeab1a 100644
>> --- a/include/linux/usb/phy.h
>> +++ b/include/linux/usb/phy.h
>> @@ -106,6 +106,21 @@ struct usb_phy {
>>   			enum usb_device_speed speed);
>>   };
>>
>> +/**
>> + * struct usb_phy_bind - represent the binding for the phy
>> + * @dev_name: the device name of the device that will bind to the phy
>> + * @phy_dev_name: the device name of the phy
>> + * @index: used if a single controller uses multiple phys
>> + * @phy: reference to the phy
>> + * @list: to maintain a linked list of the binding information
>> + */
>> +struct usb_phy_bind {
>> +	const char	*dev_name;
>> +	const char	*phy_dev_name;
>> +	u8		index;
>> +	struct usb_phy	*phy;
>> +	struct list_head list;
>> +};
>>
>>   /* for board-specific init logic */
>>   extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type);
>> @@ -151,6 +166,8 @@ extern struct usb_phy *devm_usb_get_phy(struct device *dev,
>>   	enum usb_phy_type type);
>>   extern void usb_put_phy(struct usb_phy *);
>>   extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
>> +extern struct usb_phy_bind *usb_bind_phy(const char *dev_name, u8 index,
>> +				const char *phy_dev_name);
>>   #else
>>   static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
>>   {
>> @@ -171,6 +188,11 @@ static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
>>   {
>>   }
>>
>> +static inline struct usb_phy_bind *usb_bind_phy(const char *dev_name, u8 index,
>> +				const char *phy_dev_name)
>> +{
>> +	return NULL;
>> +}
>>   #endif
>>
>>   static inline int
>>
>
> Controllers like ehci-omap which don't need OTG functionality would
> benefit from this API. Can we make these PHY APIs not dependent on OTG /
> OTG_UTILS?

Actually much of whatever is in otg.c can be used by controllers which 
don't have OTG functionality (except otg_state_string). I vaguely 
remember, there was a patch that renamed otg.c to phy.c etc.. I'm not 
sure what happened to that.

Thanks
Kishon

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 2/6] ARM: OMAP: USB: Add phy binding information
  2013-01-16 15:00 ` [RFC PATCH 2/6] ARM: OMAP: USB: Add phy binding information Kishon Vijay Abraham I
  2013-01-17  9:39   ` Roger Quadros
@ 2013-01-17 12:11   ` Vivek Gautam
  2013-01-17 12:31     ` kishon
  1 sibling, 1 reply; 26+ messages in thread
From: Vivek Gautam @ 2013-01-17 12:11 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

Hi Kishon,


On Wed, Jan 16, 2013 at 8:30 PM, Kishon Vijay Abraham I <kishon@ti.com> wrote:
> This is in preparation for the changes in PHY library to support adding
> and getting multiple PHYs of the same type. In the new design, the
> binding information between the PHY and the USB controller should be
> specified in the platform specific initialization code. So it's been
> done for OMAP platforms here.
>
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
> This kind-of binding should be done in all the platforms (I've done only
> for OMAP platform).
>  arch/arm/mach-omap2/usb-musb.c |    7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/mach-omap2/usb-musb.c b/arch/arm/mach-omap2/usb-musb.c
> index 9d27e3f..bbe2fa5 100644
> --- a/arch/arm/mach-omap2/usb-musb.c
> +++ b/arch/arm/mach-omap2/usb-musb.c
> @@ -24,6 +24,7 @@
>  #include <linux/dma-mapping.h>
>  #include <linux/io.h>
>  #include <linux/usb/musb.h>
> +#include <linux/usb/phy.h>
>
>  #include "omap_device.h"
>  #include "soc.h"
> @@ -85,8 +86,12 @@ void __init usb_musb_init(struct omap_musb_board_data *musb_board_data)
>         musb_plat.mode = board_data->mode;
>         musb_plat.extvbus = board_data->extvbus;
>
> -       if (cpu_is_omap44xx())
> +       if (cpu_is_omap44xx()) {
>                 musb_plat.has_mailbox = true;
> +               usb_bind_phy("musb-hdrc.0.auto", 0, "omap-usb2.1.auto");
> +       } else if (cpu_is_omap34xx()) {
> +               usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb");
> +       }

Just trying to understand things here.
Is the device name we are using here the platform device name (pdev->name) ?
If i am not wrong then for devices added through device tree
the device name would actually include the device address in the string,
wouldn't that make things somewhat weird, since we will have to add
such bindings
using this address string.

one more doubt please :)
is it possible to bind phy in the controllers' driver somehow ?

>
>         if (soc_is_am35xx()) {
>                 oh_name = "am35x_otg_hs";
> --
> 1.7.9.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Thanks & Regards
Vivek

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 2/6] ARM: OMAP: USB: Add phy binding information
  2013-01-17 12:11   ` Vivek Gautam
@ 2013-01-17 12:31     ` kishon
  2013-01-17 13:11       ` Vivek Gautam
  0 siblings, 1 reply; 26+ messages in thread
From: kishon @ 2013-01-17 12:31 UTC (permalink / raw)
  To: Vivek Gautam
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

Hi,

On Thursday 17 January 2013 05:41 PM, Vivek Gautam wrote:
> Hi Kishon,
>
>
> On Wed, Jan 16, 2013 at 8:30 PM, Kishon Vijay Abraham I <kishon@ti.com> wrote:
>> This is in preparation for the changes in PHY library to support adding
>> and getting multiple PHYs of the same type. In the new design, the
>> binding information between the PHY and the USB controller should be
>> specified in the platform specific initialization code. So it's been
>> done for OMAP platforms here.
>>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> ---
>> This kind-of binding should be done in all the platforms (I've done only
>> for OMAP platform).
>>   arch/arm/mach-omap2/usb-musb.c |    7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm/mach-omap2/usb-musb.c b/arch/arm/mach-omap2/usb-musb.c
>> index 9d27e3f..bbe2fa5 100644
>> --- a/arch/arm/mach-omap2/usb-musb.c
>> +++ b/arch/arm/mach-omap2/usb-musb.c
>> @@ -24,6 +24,7 @@
>>   #include <linux/dma-mapping.h>
>>   #include <linux/io.h>
>>   #include <linux/usb/musb.h>
>> +#include <linux/usb/phy.h>
>>
>>   #include "omap_device.h"
>>   #include "soc.h"
>> @@ -85,8 +86,12 @@ void __init usb_musb_init(struct omap_musb_board_data *musb_board_data)
>>          musb_plat.mode = board_data->mode;
>>          musb_plat.extvbus = board_data->extvbus;
>>
>> -       if (cpu_is_omap44xx())
>> +       if (cpu_is_omap44xx()) {
>>                  musb_plat.has_mailbox = true;
>> +               usb_bind_phy("musb-hdrc.0.auto", 0, "omap-usb2.1.auto");
>> +       } else if (cpu_is_omap34xx()) {
>> +               usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb");
>> +       }
>
> Just trying to understand things here.
> Is the device name we are using here the platform device name (pdev->name) ?

it's pdev->dev.name.
> If i am not wrong then for devices added through device tree
> the device name would actually include the device address in the string,

Ideally for device tree, devm_usb_get_phy_by_phandle() introduced in the 
5th patch of this series should be used.
usb_bind_phy should be called from platform specific initialization 
files (like your board file), which won't get executed in dt boot.
> wouldn't that make things somewhat weird, since we will have to add
> such bindings
> using this address string.
>
> one more doubt please :)
> is it possible to bind phy in the controllers' driver somehow ?
Thats not going to be good. Why do you need to do that?

Thanks
Kishon

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 2/6] ARM: OMAP: USB: Add phy binding information
  2013-01-17 12:31     ` kishon
@ 2013-01-17 13:11       ` Vivek Gautam
  0 siblings, 0 replies; 26+ messages in thread
From: Vivek Gautam @ 2013-01-17 13:11 UTC (permalink / raw)
  To: kishon
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

Hi Kishon,


Thanks for the explanation.

On Thu, Jan 17, 2013 at 6:01 PM, kishon <kishon@ti.com> wrote:
> Hi,
>
>
> On Thursday 17 January 2013 05:41 PM, Vivek Gautam wrote:
>>
>> Hi Kishon,
>>
>>
>> On Wed, Jan 16, 2013 at 8:30 PM, Kishon Vijay Abraham I <kishon@ti.com>
>> wrote:
>>>
>>> This is in preparation for the changes in PHY library to support adding
>>> and getting multiple PHYs of the same type. In the new design, the
>>> binding information between the PHY and the USB controller should be
>>> specified in the platform specific initialization code. So it's been
>>> done for OMAP platforms here.
>>>
>>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>>> ---
>>> This kind-of binding should be done in all the platforms (I've done only
>>> for OMAP platform).
>>>   arch/arm/mach-omap2/usb-musb.c |    7 ++++++-
>>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/arch/arm/mach-omap2/usb-musb.c
>>> b/arch/arm/mach-omap2/usb-musb.c
>>> index 9d27e3f..bbe2fa5 100644
>>> --- a/arch/arm/mach-omap2/usb-musb.c
>>> +++ b/arch/arm/mach-omap2/usb-musb.c
>>> @@ -24,6 +24,7 @@
>>>   #include <linux/dma-mapping.h>
>>>   #include <linux/io.h>
>>>   #include <linux/usb/musb.h>
>>> +#include <linux/usb/phy.h>
>>>
>>>   #include "omap_device.h"
>>>   #include "soc.h"
>>> @@ -85,8 +86,12 @@ void __init usb_musb_init(struct omap_musb_board_data
>>> *musb_board_data)
>>>          musb_plat.mode = board_data->mode;
>>>          musb_plat.extvbus = board_data->extvbus;
>>>
>>> -       if (cpu_is_omap44xx())
>>> +       if (cpu_is_omap44xx()) {
>>>                  musb_plat.has_mailbox = true;
>>> +               usb_bind_phy("musb-hdrc.0.auto", 0, "omap-usb2.1.auto");
>>> +       } else if (cpu_is_omap34xx()) {
>>> +               usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb");
>>> +       }
>>
>>
>> Just trying to understand things here.
>> Is the device name we are using here the platform device name (pdev->name)
>> ?
>
>
> it's pdev->dev.name.
>
>> If i am not wrong then for devices added through device tree
>> the device name would actually include the device address in the string,
>
>
> Ideally for device tree, devm_usb_get_phy_by_phandle() introduced in the 5th
> patch of this series should be used.

Ok.
> usb_bind_phy should be called from platform specific initialization files
> (like your board file), which won't get executed in dt boot.
>
Right.

>> wouldn't that make things somewhat weird, since we will have to add
>> such bindings
>> using this address string.
>>
>> one more doubt please :)
>> is it possible to bind phy in the controllers' driver somehow ?
>
> Thats not going to be good. Why do you need to do that?
>
I was certainly missing something while understanding your patches.
That's why got some doubt on this. :)


> Thanks
> Kishon



-- 
Thanks & Regards
Vivek

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 3/6] usb: otg: utils: change the phy lib to support multiple PHYs of same type
  2013-01-16 15:00 ` [RFC PATCH 3/6] usb: otg: utils: change the phy lib to support multiple PHYs of same type Kishon Vijay Abraham I
  2013-01-17  0:31   ` Simon Horman
@ 2013-01-17 16:07   ` Roger Quadros
  2013-01-18  5:28     ` kishon
  1 sibling, 1 reply; 26+ messages in thread
From: Roger Quadros @ 2013-01-17 16:07 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

On 01/16/2013 05:00 PM, Kishon Vijay Abraham I wrote:
> In order to add support for multipe PHY's of the same type, the API's
> for adding PHY and getting PHY has been changed. Now the binding
> information of the PHY and controller should be done in platform file
> using usb_bind_phy API. And for getting a PHY, the device pointer of the
> USB controller and an index should be passed. Based on the binding
> information that is added in the platform file, get_phy will return the
> approappropriate PHY.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  arch/arm/mach-shmobile/board-marzen.c |    2 +-
>  drivers/power/ab8500_charger.c        |    2 +-
>  drivers/power/isp1704_charger.c       |    2 +-
>  drivers/power/pda_power.c             |    2 +-
>  drivers/power/twl4030_charger.c       |    2 +-
>  drivers/usb/chipidea/udc.c            |    2 +-
>  drivers/usb/dwc3/core.c               |    4 +-
>  drivers/usb/gadget/fsl_udc_core.c     |    2 +-
>  drivers/usb/gadget/mv_udc_core.c      |    2 +-
>  drivers/usb/gadget/omap_udc.c         |    2 +-
>  drivers/usb/gadget/pxa25x_udc.c       |    2 +-
>  drivers/usb/gadget/pxa27x_udc.c       |    2 +-
>  drivers/usb/gadget/s3c-hsudc.c        |    2 +-
>  drivers/usb/host/ehci-fsl.c           |    2 +-
>  drivers/usb/host/ehci-msm.c           |    2 +-
>  drivers/usb/host/ehci-mv.c            |    2 +-
>  drivers/usb/host/ehci-tegra.c         |    2 +-
>  drivers/usb/host/ohci-omap.c          |    2 +-
>  drivers/usb/musb/am35x.c              |    2 +-
>  drivers/usb/musb/blackfin.c           |    2 +-
>  drivers/usb/musb/da8xx.c              |    2 +-
>  drivers/usb/musb/davinci.c            |    2 +-
>  drivers/usb/musb/musb_dsps.c          |    2 +-
>  drivers/usb/musb/omap2430.c           |    2 +-
>  drivers/usb/musb/tusb6010.c           |    2 +-
>  drivers/usb/musb/ux500.c              |    2 +-
>  drivers/usb/otg/ab8500-usb.c          |    3 +-
>  drivers/usb/otg/fsl_otg.c             |    5 ++-
>  drivers/usb/otg/gpio_vbus.c           |    3 +-
>  drivers/usb/otg/isp1301_omap.c        |    3 +-
>  drivers/usb/otg/msm_otg.c             |    3 +-
>  drivers/usb/otg/mv_otg.c              |    3 +-
>  drivers/usb/otg/nop-usb-xceiv.c       |    3 +-
>  drivers/usb/otg/otg.c                 |   67 +++++++++++++++------------------
>  drivers/usb/otg/twl4030-usb.c         |    3 +-
>  drivers/usb/phy/mv_u3d_phy.c          |    3 +-
>  drivers/usb/phy/omap-usb2.c           |   11 ++----
>  drivers/usb/phy/rcar-phy.c            |    3 +-
>  include/linux/usb/phy.h               |   12 +++---
>  39 files changed, 87 insertions(+), 89 deletions(-)

I think it better to leave the existing add/get APIs as they are add add
new APIs that support multiple PHYs. You could probably mark the old
ones as deprecated.

That way you don't need to wait till all users are converted and tested.

e.g. you could name the new APIs as

usb_add_phy_dev(struct usb_phy *phy);
usb_get_phy_dev(struct device *dev, int index);

--
cheers,
-roger

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 3/6] usb: otg: utils: change the phy lib to support multiple PHYs of same type
  2013-01-17 16:07   ` Roger Quadros
@ 2013-01-18  5:28     ` kishon
  0 siblings, 0 replies; 26+ messages in thread
From: kishon @ 2013-01-18  5:28 UTC (permalink / raw)
  To: Roger Quadros
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

Hi,

On Thursday 17 January 2013 09:37 PM, Roger Quadros wrote:
> On 01/16/2013 05:00 PM, Kishon Vijay Abraham I wrote:
>> In order to add support for multipe PHY's of the same type, the API's
>> for adding PHY and getting PHY has been changed. Now the binding
>> information of the PHY and controller should be done in platform file
>> using usb_bind_phy API. And for getting a PHY, the device pointer of the
>> USB controller and an index should be passed. Based on the binding
>> information that is added in the platform file, get_phy will return the
>> approappropriate PHY.
>>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> ---
>>   arch/arm/mach-shmobile/board-marzen.c |    2 +-
>>   drivers/power/ab8500_charger.c        |    2 +-
>>   drivers/power/isp1704_charger.c       |    2 +-
>>   drivers/power/pda_power.c             |    2 +-
>>   drivers/power/twl4030_charger.c       |    2 +-
>>   drivers/usb/chipidea/udc.c            |    2 +-
>>   drivers/usb/dwc3/core.c               |    4 +-
>>   drivers/usb/gadget/fsl_udc_core.c     |    2 +-
>>   drivers/usb/gadget/mv_udc_core.c      |    2 +-
>>   drivers/usb/gadget/omap_udc.c         |    2 +-
>>   drivers/usb/gadget/pxa25x_udc.c       |    2 +-
>>   drivers/usb/gadget/pxa27x_udc.c       |    2 +-
>>   drivers/usb/gadget/s3c-hsudc.c        |    2 +-
>>   drivers/usb/host/ehci-fsl.c           |    2 +-
>>   drivers/usb/host/ehci-msm.c           |    2 +-
>>   drivers/usb/host/ehci-mv.c            |    2 +-
>>   drivers/usb/host/ehci-tegra.c         |    2 +-
>>   drivers/usb/host/ohci-omap.c          |    2 +-
>>   drivers/usb/musb/am35x.c              |    2 +-
>>   drivers/usb/musb/blackfin.c           |    2 +-
>>   drivers/usb/musb/da8xx.c              |    2 +-
>>   drivers/usb/musb/davinci.c            |    2 +-
>>   drivers/usb/musb/musb_dsps.c          |    2 +-
>>   drivers/usb/musb/omap2430.c           |    2 +-
>>   drivers/usb/musb/tusb6010.c           |    2 +-
>>   drivers/usb/musb/ux500.c              |    2 +-
>>   drivers/usb/otg/ab8500-usb.c          |    3 +-
>>   drivers/usb/otg/fsl_otg.c             |    5 ++-
>>   drivers/usb/otg/gpio_vbus.c           |    3 +-
>>   drivers/usb/otg/isp1301_omap.c        |    3 +-
>>   drivers/usb/otg/msm_otg.c             |    3 +-
>>   drivers/usb/otg/mv_otg.c              |    3 +-
>>   drivers/usb/otg/nop-usb-xceiv.c       |    3 +-
>>   drivers/usb/otg/otg.c                 |   67 +++++++++++++++------------------
>>   drivers/usb/otg/twl4030-usb.c         |    3 +-
>>   drivers/usb/phy/mv_u3d_phy.c          |    3 +-
>>   drivers/usb/phy/omap-usb2.c           |   11 ++----
>>   drivers/usb/phy/rcar-phy.c            |    3 +-
>>   include/linux/usb/phy.h               |   12 +++---
>>   39 files changed, 87 insertions(+), 89 deletions(-)
>
> I think it better to leave the existing add/get APIs as they are add add
> new APIs that support multiple PHYs. You could probably mark the old
> ones as deprecated.
>
> That way you don't need to wait till all users are converted and tested.

Makes sense. Will do that :-)

Thanks
Kishon

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 1/6] usb: otg: Add an API to bind the USB controller and PHY
  2013-01-17 11:14     ` kishon
@ 2013-01-18 11:48       ` Felipe Balbi
  0 siblings, 0 replies; 26+ messages in thread
From: Felipe Balbi @ 2013-01-18 11:48 UTC (permalink / raw)
  To: kishon
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, Roger Quadros,
	eric.y.miao, b-cousson, gregkh, linux-usb, linux-kernel, balbi,
	cbou, rob, dwmw2

[-- Attachment #1: Type: text/plain, Size: 870 bytes --]

On Thu, Jan 17, 2013 at 04:44:52PM +0530, kishon wrote:
> >>@@ -171,6 +188,11 @@ static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
> >>  {
> >>  }
> >>
> >>+static inline struct usb_phy_bind *usb_bind_phy(const char *dev_name, u8 index,
> >>+				const char *phy_dev_name)
> >>+{
> >>+	return NULL;
> >>+}
> >>  #endif
> >>
> >>  static inline int
> >>
> >
> >Controllers like ehci-omap which don't need OTG functionality would
> >benefit from this API. Can we make these PHY APIs not dependent on OTG /
> >OTG_UTILS?
> 
> Actually much of whatever is in otg.c can be used by controllers
> which don't have OTG functionality (except otg_state_string). I
> vaguely remember, there was a patch that renamed otg.c to phy.c etc..
> I'm not sure what happened to that.

right, that has to be done eventually ;-)

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 0/6] USB: Add multiple PHYs of same type
  2013-01-16 15:00 [RFC PATCH 0/6] USB: Add multiple PHYs of same type Kishon Vijay Abraham I
                   ` (5 preceding siblings ...)
  2013-01-16 15:01 ` [RFC PATCH 6/6] USB: MUSB: OMAP: get PHY by phandle for dt boot Kishon Vijay Abraham I
@ 2013-01-18 11:48 ` Felipe Balbi
  2013-01-18 11:54   ` kishon
  6 siblings, 1 reply; 26+ messages in thread
From: Felipe Balbi @ 2013-01-18 11:48 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

On Wed, Jan 16, 2013 at 08:30:56PM +0530, Kishon Vijay Abraham I wrote:
> New platforms are being added which has multiple PHY's (of same type) and
> which has multiple USB controllers. The binding information has to be
> present in the PHY library (otg.c) in order for it to return the
> appropriate PHY whenever the USB controller request for the PHY. So
> added a new API to pass the binding information. This API should be
> called by platform specific initialization code.
> 
> So the binding should be done something like
> usb_bind_phy("musb-hdrc.0.auto", 0, "omap-usb2.1.auto"); specifying the USB
> controller device name, index, and the PHY device name.
> I have done this binding for OMAP platforms, but it should be done for
> all the platforms.
> 
> After this design, the phy can be got by passing the USB controller device
> pointer and the index.
> 
> Developed this patch series on
> git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git xceiv
> after applying "usb: musb: add driver for control module" patch series.
> 
> Did basic enumeration testing in omap4 panda, omap4 sdp and omap3 beagle.

please resend without RFC so I can apply.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 0/6] USB: Add multiple PHYs of same type
  2013-01-18 11:48 ` [RFC PATCH 0/6] USB: Add multiple PHYs of same type Felipe Balbi
@ 2013-01-18 11:54   ` kishon
  0 siblings, 0 replies; 26+ messages in thread
From: kishon @ 2013-01-18 11:54 UTC (permalink / raw)
  To: balbi
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, cbou, rob, dwmw2

On Friday 18 January 2013 05:18 PM, Felipe Balbi wrote:
> On Wed, Jan 16, 2013 at 08:30:56PM +0530, Kishon Vijay Abraham I wrote:
>> New platforms are being added which has multiple PHY's (of same type) and
>> which has multiple USB controllers. The binding information has to be
>> present in the PHY library (otg.c) in order for it to return the
>> appropriate PHY whenever the USB controller request for the PHY. So
>> added a new API to pass the binding information. This API should be
>> called by platform specific initialization code.
>>
>> So the binding should be done something like
>> usb_bind_phy("musb-hdrc.0.auto", 0, "omap-usb2.1.auto"); specifying the USB
>> controller device name, index, and the PHY device name.
>> I have done this binding for OMAP platforms, but it should be done for
>> all the platforms.
>>
>> After this design, the phy can be got by passing the USB controller device
>> pointer and the index.
>>
>> Developed this patch series on
>> git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git xceiv
>> after applying "usb: musb: add driver for control module" patch series.
>>
>> Did basic enumeration testing in omap4 panda, omap4 sdp and omap3 beagle.
>
> please resend without RFC so I can apply.

I'll resend after addressing Roger's comments in a while.

Thanks
Kishon

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 6/6] USB: MUSB: OMAP: get PHY by phandle for dt boot
  2013-01-16 15:01 ` [RFC PATCH 6/6] USB: MUSB: OMAP: get PHY by phandle for dt boot Kishon Vijay Abraham I
@ 2013-01-21 13:18   ` Roger Quadros
  2013-01-21 13:41     ` kishon
  0 siblings, 1 reply; 26+ messages in thread
From: Roger Quadros @ 2013-01-21 13:18 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

On 01/16/2013 05:01 PM, Kishon Vijay Abraham I wrote:
> The OMAP glue has been modified to get PHY by phandle for dt boot.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/musb/omap2430.c |    7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
> index 3628a50..08709cf 100644
> --- a/drivers/usb/musb/omap2430.c
> +++ b/drivers/usb/musb/omap2430.c
> @@ -346,7 +346,12 @@ static int omap2430_musb_init(struct musb *musb)
>  	 * up through ULPI.  TWL4030-family PMICs include one,
>  	 * which needs a driver, drivers aren't always needed.
>  	 */
> -	musb->xceiv = devm_usb_get_phy(dev, 0);
> +	if (dev->parent->of_node)
> +		musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent,
> +		    "usb_phy", 0);

Why dev->parent and not just dev?

> +	else
> +		musb->xceiv = devm_usb_get_phy(dev, 0);
> +
>  	if (IS_ERR_OR_NULL(musb->xceiv)) {
>  		pr_err("HS USB OTG: no transceiver configured\n");
>  		return -ENODEV;
> 

--
cheers,
-roger

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 5/6] usb: otg: add device tree support to otg library
  2013-01-16 15:01 ` [RFC PATCH 5/6] usb: otg: add device tree support to otg library Kishon Vijay Abraham I
@ 2013-01-21 13:21   ` Roger Quadros
  2013-01-21 13:34     ` kishon
  0 siblings, 1 reply; 26+ messages in thread
From: Roger Quadros @ 2013-01-21 13:21 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	Marc Kleine-Budde, haojian.zhuang, linux-omap, linux-arm-kernel,
	eric.y.miao, b-cousson, gregkh, linux-usb, linux-kernel, balbi,
	cbou, rob, dwmw2

On 01/16/2013 05:01 PM, Kishon Vijay Abraham I wrote:
> Added an API devm_usb_get_phy_by_phandle(), to get usb phy by passing a
> device node phandle value. This function will return a pointer to
> the phy on success, -EPROBE_DEFER if there is a device_node for the phandle,
> but the phy has not been added, or a ERR_PTR() otherwise.
> 
> Cc: Marc Kleine-Budde <mkl@pengutronix.de>
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/otg/otg.c   |   77 +++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/usb/phy.h |    8 +++++
>  2 files changed, 85 insertions(+)
> 
> diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
> index dbf2043..e9799bb 100644
> --- a/drivers/usb/otg/otg.c
> +++ b/drivers/usb/otg/otg.c
> @@ -13,7 +13,9 @@
>  #include <linux/export.h>
>  #include <linux/err.h>
>  #include <linux/device.h>
> +#include <linux/module.h>
>  #include <linux/slab.h>
> +#include <linux/of.h>
>  
>  #include <linux/usb/otg.h>
>  
> @@ -34,6 +36,20 @@ static struct usb_phy *__usb_find_phy(struct device *dev, u8 index)
>  	return ERR_PTR(-ENODEV);
>  }
>  
> +static struct usb_phy *__of_usb_find_phy(struct device_node *node)
> +{
> +	struct usb_phy  *phy;
> +
> +	list_for_each_entry(phy, &phy_list, head) {
> +		if (node != phy->dev->of_node)
> +			continue;
> +
> +		return phy;
> +	}
> +
> +	return ERR_PTR(-ENODEV);
> +}
> +
>  static void devm_usb_phy_release(struct device *dev, void *res)
>  {
>  	struct usb_phy *phy = *(struct usb_phy **)res;
> @@ -109,6 +125,67 @@ err0:
>  }
>  EXPORT_SYMBOL(usb_get_phy);
>  
> + /**
> + * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
> + * @dev - device that requests this phy
> + * @phandle - name of the property holding the phy phandle value
> + * @index - the index of the phy
> + *
> + * Returns the phy driver associated with the given phandle value,
> + * after getting a refcount to it, -ENODEV if there is no such phy or
> + * -EPROBE_DEFER if there is a phandle to the phy, but the device is
> + * not yet loaded. While at that, it also associates the device with
> + * the phy using devres. On driver detach, release function is invoked
> + * on the devres data, then, devres data is freed.
> + *
> + * For use by USB host and peripheral drivers.
> + */
> +struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
> +	const char *phandle, u8 index)
> +{
> +	struct usb_phy	*phy = NULL, **ptr;
> +	unsigned long	flags;
> +	struct device_node *node;
> +
> +	if (!dev->of_node) {
> +		dev_dbg(dev, "device does not have a device node entry\n");
> +		return ERR_PTR(-EINVAL);
> +	}
> +
> +	node = of_parse_phandle(dev->of_node, phandle, index);
> +	if (!node) {
> +		dev_dbg(dev, "failed to get %s phandle in %s node\n", phandle,
> +			dev->of_node->full_name);
> +		return ERR_PTR(-ENODEV);
> +	}
> +
> +	ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
> +	if (!ptr) {
> +		dev_dbg(dev, "failed to allocate memory for devres\n");
> +		return ERR_PTR(-ENOMEM);
> +	}

I fail to understand why you need ptr at all and why do devres_alloc()
for it.

> +
> +	spin_lock_irqsave(&phy_lock, flags);
> +
> +	phy = __of_usb_find_phy(node);
> +	if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
> +		phy = ERR_PTR(-EPROBE_DEFER);
> +		devres_free(ptr);
> +		goto err0;
> +	}
> +
> +	*ptr = phy;
> +	devres_add(dev, ptr);
> +
> +	get_device(phy->dev);
> +
> +err0:
> +	spin_unlock_irqrestore(&phy_lock, flags);
> +
> +	return phy;
> +}
> +EXPORT_SYMBOL(devm_usb_get_phy_by_phandle);
> +

--
cheers,
-roger

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 5/6] usb: otg: add device tree support to otg library
  2013-01-21 13:21   ` Roger Quadros
@ 2013-01-21 13:34     ` kishon
  2013-01-21 14:23       ` Roger Quadros
  0 siblings, 1 reply; 26+ messages in thread
From: kishon @ 2013-01-21 13:34 UTC (permalink / raw)
  To: Roger Quadros
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	Marc Kleine-Budde, haojian.zhuang, linux-omap, linux-arm-kernel,
	eric.y.miao, b-cousson, gregkh, linux-usb, linux-kernel, balbi,
	cbou, rob, dwmw2

On Monday 21 January 2013 06:51 PM, Roger Quadros wrote:
> On 01/16/2013 05:01 PM, Kishon Vijay Abraham I wrote:
>> Added an API devm_usb_get_phy_by_phandle(), to get usb phy by passing a
>> device node phandle value. This function will return a pointer to
>> the phy on success, -EPROBE_DEFER if there is a device_node for the phandle,
>> but the phy has not been added, or a ERR_PTR() otherwise.
>>
>> Cc: Marc Kleine-Budde <mkl@pengutronix.de>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> ---
>>   drivers/usb/otg/otg.c   |   77 +++++++++++++++++++++++++++++++++++++++++++++++
>>   include/linux/usb/phy.h |    8 +++++
>>   2 files changed, 85 insertions(+)
>>
>> diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
>> index dbf2043..e9799bb 100644
>> --- a/drivers/usb/otg/otg.c
>> +++ b/drivers/usb/otg/otg.c
>> @@ -13,7 +13,9 @@
>>   #include <linux/export.h>
>>   #include <linux/err.h>
>>   #include <linux/device.h>
>> +#include <linux/module.h>
>>   #include <linux/slab.h>
>> +#include <linux/of.h>
>>
>>   #include <linux/usb/otg.h>
>>
>> @@ -34,6 +36,20 @@ static struct usb_phy *__usb_find_phy(struct device *dev, u8 index)
>>   	return ERR_PTR(-ENODEV);
>>   }
>>
>> +static struct usb_phy *__of_usb_find_phy(struct device_node *node)
>> +{
>> +	struct usb_phy  *phy;
>> +
>> +	list_for_each_entry(phy, &phy_list, head) {
>> +		if (node != phy->dev->of_node)
>> +			continue;
>> +
>> +		return phy;
>> +	}
>> +
>> +	return ERR_PTR(-ENODEV);
>> +}
>> +
>>   static void devm_usb_phy_release(struct device *dev, void *res)
>>   {
>>   	struct usb_phy *phy = *(struct usb_phy **)res;
>> @@ -109,6 +125,67 @@ err0:
>>   }
>>   EXPORT_SYMBOL(usb_get_phy);
>>
>> + /**
>> + * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
>> + * @dev - device that requests this phy
>> + * @phandle - name of the property holding the phy phandle value
>> + * @index - the index of the phy
>> + *
>> + * Returns the phy driver associated with the given phandle value,
>> + * after getting a refcount to it, -ENODEV if there is no such phy or
>> + * -EPROBE_DEFER if there is a phandle to the phy, but the device is
>> + * not yet loaded. While at that, it also associates the device with
>> + * the phy using devres. On driver detach, release function is invoked
>> + * on the devres data, then, devres data is freed.
>> + *
>> + * For use by USB host and peripheral drivers.
>> + */
>> +struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
>> +	const char *phandle, u8 index)
>> +{
>> +	struct usb_phy	*phy = NULL, **ptr;
>> +	unsigned long	flags;
>> +	struct device_node *node;
>> +
>> +	if (!dev->of_node) {
>> +		dev_dbg(dev, "device does not have a device node entry\n");
>> +		return ERR_PTR(-EINVAL);
>> +	}
>> +
>> +	node = of_parse_phandle(dev->of_node, phandle, index);
>> +	if (!node) {
>> +		dev_dbg(dev, "failed to get %s phandle in %s node\n", phandle,
>> +			dev->of_node->full_name);
>> +		return ERR_PTR(-ENODEV);
>> +	}
>> +
>> +	ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
>> +	if (!ptr) {
>> +		dev_dbg(dev, "failed to allocate memory for devres\n");
>> +		return ERR_PTR(-ENOMEM);
>> +	}
>
> I fail to understand why you need ptr at all and why do devres_alloc()
> for it.

Thats how we create a "managed device resource". You can have a look at 
Documentation/driver-model/devres.txt and drivers/base/devres.c.

I'm not sure if that is what you are looking for :-P

Thanks
Kishon

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 6/6] USB: MUSB: OMAP: get PHY by phandle for dt boot
  2013-01-21 13:18   ` Roger Quadros
@ 2013-01-21 13:41     ` kishon
  2013-01-21 14:24       ` Roger Quadros
  0 siblings, 1 reply; 26+ messages in thread
From: kishon @ 2013-01-21 13:41 UTC (permalink / raw)
  To: Roger Quadros
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

Hi,

On Monday 21 January 2013 06:48 PM, Roger Quadros wrote:
> On 01/16/2013 05:01 PM, Kishon Vijay Abraham I wrote:
>> The OMAP glue has been modified to get PHY by phandle for dt boot.
>>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> ---
>>   drivers/usb/musb/omap2430.c |    7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
>> index 3628a50..08709cf 100644
>> --- a/drivers/usb/musb/omap2430.c
>> +++ b/drivers/usb/musb/omap2430.c
>> @@ -346,7 +346,12 @@ static int omap2430_musb_init(struct musb *musb)
>>   	 * up through ULPI.  TWL4030-family PMICs include one,
>>   	 * which needs a driver, drivers aren't always needed.
>>   	 */
>> -	musb->xceiv = devm_usb_get_phy(dev, 0);
>> +	if (dev->parent->of_node)
>> +		musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent,
>> +		    "usb_phy", 0);
>
> Why dev->parent and not just dev?

Right now MUSB core is not converted to dt and hence we don't have 
separate dt node for MUSB core.
So the PHY information is added to the glue dt data.

Thanks
Kishon

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 5/6] usb: otg: add device tree support to otg library
  2013-01-21 13:34     ` kishon
@ 2013-01-21 14:23       ` Roger Quadros
  0 siblings, 0 replies; 26+ messages in thread
From: Roger Quadros @ 2013-01-21 14:23 UTC (permalink / raw)
  To: kishon
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	Marc Kleine-Budde, haojian.zhuang, linux-omap, linux-arm-kernel,
	eric.y.miao, b-cousson, gregkh, linux-usb, linux-kernel, balbi,
	cbou, rob, dwmw2

On 01/21/2013 03:34 PM, kishon wrote:
> On Monday 21 January 2013 06:51 PM, Roger Quadros wrote:
>> On 01/16/2013 05:01 PM, Kishon Vijay Abraham I wrote:
>>> Added an API devm_usb_get_phy_by_phandle(), to get usb phy by passing a
>>> device node phandle value. This function will return a pointer to
>>> the phy on success, -EPROBE_DEFER if there is a device_node for the
>>> phandle,
>>> but the phy has not been added, or a ERR_PTR() otherwise.
>>>
>>> Cc: Marc Kleine-Budde <mkl@pengutronix.de>
>>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>>> ---
>>>   drivers/usb/otg/otg.c   |   77
>>> +++++++++++++++++++++++++++++++++++++++++++++++
>>>   include/linux/usb/phy.h |    8 +++++
>>>   2 files changed, 85 insertions(+)
>>>
>>> diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
>>> index dbf2043..e9799bb 100644
>>> --- a/drivers/usb/otg/otg.c
>>> +++ b/drivers/usb/otg/otg.c
>>> @@ -13,7 +13,9 @@
>>>   #include <linux/export.h>
>>>   #include <linux/err.h>
>>>   #include <linux/device.h>
>>> +#include <linux/module.h>
>>>   #include <linux/slab.h>
>>> +#include <linux/of.h>
>>>
>>>   #include <linux/usb/otg.h>
>>>
>>> @@ -34,6 +36,20 @@ static struct usb_phy *__usb_find_phy(struct
>>> device *dev, u8 index)
>>>       return ERR_PTR(-ENODEV);
>>>   }
>>>
>>> +static struct usb_phy *__of_usb_find_phy(struct device_node *node)
>>> +{
>>> +    struct usb_phy  *phy;
>>> +
>>> +    list_for_each_entry(phy, &phy_list, head) {
>>> +        if (node != phy->dev->of_node)
>>> +            continue;
>>> +
>>> +        return phy;
>>> +    }
>>> +
>>> +    return ERR_PTR(-ENODEV);
>>> +}
>>> +
>>>   static void devm_usb_phy_release(struct device *dev, void *res)
>>>   {
>>>       struct usb_phy *phy = *(struct usb_phy **)res;
>>> @@ -109,6 +125,67 @@ err0:
>>>   }
>>>   EXPORT_SYMBOL(usb_get_phy);
>>>
>>> + /**
>>> + * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
>>> + * @dev - device that requests this phy
>>> + * @phandle - name of the property holding the phy phandle value
>>> + * @index - the index of the phy
>>> + *
>>> + * Returns the phy driver associated with the given phandle value,
>>> + * after getting a refcount to it, -ENODEV if there is no such phy or
>>> + * -EPROBE_DEFER if there is a phandle to the phy, but the device is
>>> + * not yet loaded. While at that, it also associates the device with
>>> + * the phy using devres. On driver detach, release function is invoked
>>> + * on the devres data, then, devres data is freed.
>>> + *
>>> + * For use by USB host and peripheral drivers.
>>> + */
>>> +struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
>>> +    const char *phandle, u8 index)
>>> +{
>>> +    struct usb_phy    *phy = NULL, **ptr;
>>> +    unsigned long    flags;
>>> +    struct device_node *node;
>>> +
>>> +    if (!dev->of_node) {
>>> +        dev_dbg(dev, "device does not have a device node entry\n");
>>> +        return ERR_PTR(-EINVAL);
>>> +    }
>>> +
>>> +    node = of_parse_phandle(dev->of_node, phandle, index);
>>> +    if (!node) {
>>> +        dev_dbg(dev, "failed to get %s phandle in %s node\n", phandle,
>>> +            dev->of_node->full_name);
>>> +        return ERR_PTR(-ENODEV);
>>> +    }
>>> +
>>> +    ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
>>> +    if (!ptr) {
>>> +        dev_dbg(dev, "failed to allocate memory for devres\n");
>>> +        return ERR_PTR(-ENOMEM);
>>> +    }
>>
>> I fail to understand why you need ptr at all and why do devres_alloc()
>> for it.
> 
> Thats how we create a "managed device resource". You can have a look at
> Documentation/driver-model/devres.txt and drivers/base/devres.c.

OK, I get it now. You might want to update the text file too since you
are adding a automagically managed interface.

regards,
-roger

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [RFC PATCH 6/6] USB: MUSB: OMAP: get PHY by phandle for dt boot
  2013-01-21 13:41     ` kishon
@ 2013-01-21 14:24       ` Roger Quadros
  0 siblings, 0 replies; 26+ messages in thread
From: Roger Quadros @ 2013-01-21 14:24 UTC (permalink / raw)
  To: kishon
  Cc: linux-doc, tony, linux, linux-sh, alexander.shishkin, stern,
	devicetree-discuss, linuxppc-dev, rob.herring, horms,
	haojian.zhuang, linux-omap, linux-arm-kernel, eric.y.miao,
	b-cousson, gregkh, linux-usb, linux-kernel, balbi, cbou, rob,
	dwmw2

On 01/21/2013 03:41 PM, kishon wrote:
> Hi,
> 
> On Monday 21 January 2013 06:48 PM, Roger Quadros wrote:
>> On 01/16/2013 05:01 PM, Kishon Vijay Abraham I wrote:
>>> The OMAP glue has been modified to get PHY by phandle for dt boot.
>>>
>>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>>> ---
>>>   drivers/usb/musb/omap2430.c |    7 ++++++-
>>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
>>> index 3628a50..08709cf 100644
>>> --- a/drivers/usb/musb/omap2430.c
>>> +++ b/drivers/usb/musb/omap2430.c
>>> @@ -346,7 +346,12 @@ static int omap2430_musb_init(struct musb *musb)
>>>        * up through ULPI.  TWL4030-family PMICs include one,
>>>        * which needs a driver, drivers aren't always needed.
>>>        */
>>> -    musb->xceiv = devm_usb_get_phy(dev, 0);
>>> +    if (dev->parent->of_node)
>>> +        musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent,
>>> +            "usb_phy", 0);
>>
>> Why dev->parent and not just dev?
> 
> Right now MUSB core is not converted to dt and hence we don't have
> separate dt node for MUSB core.
> So the PHY information is added to the glue dt data.
> 

OK. Got it :).

--
cheers,
-roger

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2013-01-21 14:24 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-16 15:00 [RFC PATCH 0/6] USB: Add multiple PHYs of same type Kishon Vijay Abraham I
2013-01-16 15:00 ` [RFC PATCH 1/6] usb: otg: Add an API to bind the USB controller and PHY Kishon Vijay Abraham I
2013-01-17  9:37   ` Roger Quadros
2013-01-17 11:14     ` kishon
2013-01-18 11:48       ` Felipe Balbi
2013-01-16 15:00 ` [RFC PATCH 2/6] ARM: OMAP: USB: Add phy binding information Kishon Vijay Abraham I
2013-01-17  9:39   ` Roger Quadros
2013-01-17 11:03     ` kishon
2013-01-17 12:11   ` Vivek Gautam
2013-01-17 12:31     ` kishon
2013-01-17 13:11       ` Vivek Gautam
2013-01-16 15:00 ` [RFC PATCH 3/6] usb: otg: utils: change the phy lib to support multiple PHYs of same type Kishon Vijay Abraham I
2013-01-17  0:31   ` Simon Horman
2013-01-17 16:07   ` Roger Quadros
2013-01-18  5:28     ` kishon
2013-01-16 15:01 ` [RFC PATCH 4/6] ARM: dts: OMAP: Add phandle to bind PHY with USB controller Kishon Vijay Abraham I
2013-01-16 15:01 ` [RFC PATCH 5/6] usb: otg: add device tree support to otg library Kishon Vijay Abraham I
2013-01-21 13:21   ` Roger Quadros
2013-01-21 13:34     ` kishon
2013-01-21 14:23       ` Roger Quadros
2013-01-16 15:01 ` [RFC PATCH 6/6] USB: MUSB: OMAP: get PHY by phandle for dt boot Kishon Vijay Abraham I
2013-01-21 13:18   ` Roger Quadros
2013-01-21 13:41     ` kishon
2013-01-21 14:24       ` Roger Quadros
2013-01-18 11:48 ` [RFC PATCH 0/6] USB: Add multiple PHYs of same type Felipe Balbi
2013-01-18 11:54   ` kishon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).