Re: [PATCH v3] usb: of: add an api to get dr_mode by the phy node

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 09/18/2015 10:41 PM, Felipe Balbi wrote:
Hi,

On Fri, Sep 18, 2015 at 03:27:58PM -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>
---
v3: search controller node from dt root, as the phy and controller nodes
     might not have the same parent.

  drivers/usb/common/common.c | 26 ++++++++++++++++++++++++++
  include/linux/usb/of.h      |  6 ++++++
  2 files changed, 32 insertions(+)

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index b530fd4..fc32055 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -114,6 +114,32 @@ 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 = NULL;
+	struct device_node *phy;
+
+	do {
+		controller = of_find_node_with_property(controller, "phys");
+		if (!controller)
+			return USB_DR_MODE_UNKNOWN;
+
+		phy = of_parse_phandle(controller, "phys", 0);

another question: How do you know this is the USB PHY and not a SATA or
MII/GMII/RGMII, or anything else ?

Because you pass in the device_node pointer for the usb-phy and the function
checks that the controller's phys property points to the passed in device_node,

Regards,

Hans


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



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux