Hi,
On 09/18/2015 02:09 PM, Felipe Balbi wrote:
On Fri, Sep 18, 2015 at 01:45:56PM -0500, Bin Liu wrote:
Hi,
On 09/18/2015 01:41 PM, Felipe Balbi wrote:
On Tue, Sep 15, 2015 at 01:58:16PM -0500, Bin Liu wrote:
Some USB phy drivers have different handling for the controller in each
dr_mode. But the phy driver does not have visibility to the dr_mode of
the controller.
This adds an api to return the dr_mode of the controller which
associates the given phy node.
Signed-off-by: Bin Liu <b-liu@xxxxxx>
---
v2: move drivers/usb/phy/phy-am335x.c changes into patch 3/3.
drivers/usb/common/common.c | 27 +++++++++++++++++++++++++++
include/linux/usb/of.h | 6 ++++++
2 files changed, 33 insertions(+)
diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index b530fd4..3c7dee8 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -114,6 +114,33 @@ enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
/**
+ * of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device
+ * which is associated with the given phy device_node
+ * @np: Pointer to the given phy device_node
+ *
+ * In dts a usb controller associates with a phy device. The function gets
+ * the string from property 'dr_mode' of the controller associated with the
+ * given phy device node, and returns the correspondig enum usb_dr_mode.
+ */
+enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np)
+{
+ struct device_node *controller;
+ struct device_node *phy;
+
+ controller = of_get_parent(phy_np);
+ do {
+ controller = of_find_node_with_property(controller, "phys");
+ if (!controller)
+ return USB_DR_MODE_UNKNOWN;
+
+ phy = of_parse_phandle(controller, "phys", 0);
+ } while (phy != phy_np);
+
+ return of_usb_get_dr_mode(controller);
+}
+EXPORT_SYMBOL_GPL(of_usb_get_dr_mode_by_phy);
this assumes that the USB controller is described as a parent of
the PHY, but there's no requirement for this; this is merely a
function of how TI integrated the USB subsystem in HW.
Okay, then how about looking up the controller node from root? My first
draft of the patch was:
+enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np)
+{
+ struct device_node *controller = NULL;
+ struct device_node *phy;
+
+ do {
+ controller = of_find_node_with_property(controller, "phys");
......
if it works. No idea if there's a better way for doing this.
Yes, I tested it and it works. Then I thought only looking up from PHY's
parent would make the search quicker but forgot that the PHY node could
be at anywhere in dts.
Will send v3 soon.
Thanks,
-Bin.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html