From patchwork Fri May 20 09:29:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 68229 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp3668084qge; Fri, 20 May 2016 02:30:22 -0700 (PDT) X-Received: by 10.98.26.18 with SMTP id a18mr3232308pfa.39.1463736621999; Fri, 20 May 2016 02:30:21 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x124si2875888pfx.231.2016.05.20.02.30.21; Fri, 20 May 2016 02:30:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753553AbcETJaU (ORCPT + 7 others); Fri, 20 May 2016 05:30:20 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:42739 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752668AbcETJaT (ORCPT ); Fri, 20 May 2016 05:30:19 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id u4K9U8Fl017481; Fri, 20 May 2016 04:30:08 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id u4K9U7Ih022798; Fri, 20 May 2016 04:30:08 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.294.0; Fri, 20 May 2016 04:30:04 -0500 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id u4K9U0MG028658; Fri, 20 May 2016 04:30:00 -0500 Subject: [PATCH v9 09/14] usb: of: add an API to get OTG device from USB controller node To: , References: <1463133808-10630-1-git-send-email-rogerq@ti.com> <1463133808-10630-10-git-send-email-rogerq@ti.com> CC: , , , , , , , , , , , , , , , From: Roger Quadros Message-ID: <573ED917.6090803@ti.com> Date: Fri, 20 May 2016 12:29:59 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <1463133808-10630-10-git-send-email-rogerq@ti.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The OTG controller and the USB controller can be linked via the 'otg-controller' property in the USB controller's device node. of_usb_get_otg() can be used to get the OTG controller device from the USB controller's device node. Signed-off-by: Roger Quadros Acked-by: Peter Chen --- v9: Clearly indicate which properties are for OTG controller and which ones are for host/device controllers Documentation/devicetree/bindings/usb/generic.txt | 7 ++++++ drivers/usb/common/common.c | 27 +++++++++++++++++++++++ include/linux/usb/of.h | 9 ++++++++ 3 files changed, 43 insertions(+) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt index bba8257..0887d6e 100644 --- a/Documentation/devicetree/bindings/usb/generic.txt +++ b/Documentation/devicetree/bindings/usb/generic.txt @@ -11,6 +11,8 @@ Optional properties: "peripheral" and "otg". In case this attribute isn't passed via DT, USB DRD controllers should default to OTG. + +Optional properties for OTG controllers: - otg-rev: tells usb driver the release number of the OTG and EH supplement with which the device and its descriptors are compliant, in binary-coded decimal (i.e. 2.0 is 0200H). This @@ -25,6 +27,11 @@ Optional properties: - adp-disable: tells OTG controllers we want to disable OTG ADP, ADP is optional for OTG device. +Optional properties for host/device controllers: + - otg-controller: phandle to otg controller. Host or gadget controllers can + contain this property to link it to a particular OTG + controller. + This is an attribute to a USB controller such as: dwc3@4a030000 { diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index e3d0161..d7ec471 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -238,6 +238,33 @@ int of_usb_update_otg_caps(struct device_node *np, } EXPORT_SYMBOL_GPL(of_usb_update_otg_caps); +#ifdef CONFIG_USB_OTG +/** + * of_usb_get_otg - get the OTG controller linked to the USB controller + * @np: Pointer to the device_node of the USB controller + * @otg_caps: Pointer to the target usb_otg_caps to be set + * + * Returns the OTG controller device or NULL on error. + */ +struct device *of_usb_get_otg(struct device_node *np) +{ + struct device_node *otg_np; + struct platform_device *pdev; + + otg_np = of_parse_phandle(np, "otg-controller", 0); + if (!otg_np) + return NULL; + + pdev = of_find_device_by_node(otg_np); + of_node_put(otg_np); + if (!pdev) + return NULL; + + return &pdev->dev; +} +EXPORT_SYMBOL_GPL(of_usb_get_otg); +#endif + #endif MODULE_LICENSE("GPL"); diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h index de3237f..499a4e8 100644 --- a/include/linux/usb/of.h +++ b/include/linux/usb/of.h @@ -40,6 +40,15 @@ static inline struct device_node *usb_of_get_child_node } #endif +#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_OTG) +struct device *of_usb_get_otg(struct device_node *np); +#else +static inline struct device *of_usb_get_otg(struct device_node *np) +{ + return NULL; +} +#endif + #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT) enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np); #else