From patchwork Wed Jun 8 09:03:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 69593 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2383501qgf; Wed, 8 Jun 2016 02:05:20 -0700 (PDT) X-Received: by 10.98.91.7 with SMTP id p7mr4678177pfb.8.1465376711959; Wed, 08 Jun 2016 02:05:11 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m8si310457pfa.242.2016.06.08.02.05.05; Wed, 08 Jun 2016 02:05:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423352AbcFHJEz (ORCPT + 31 others); Wed, 8 Jun 2016 05:04:55 -0400 Received: from arroyo.ext.ti.com ([198.47.19.12]:59224 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161659AbcFHJEv (ORCPT ); Wed, 8 Jun 2016 05:04:51 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id u5894gQL001974; Wed, 8 Jun 2016 04:04:42 -0500 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id u5894gPT020548; Wed, 8 Jun 2016 04:04:42 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.294.0; Wed, 8 Jun 2016 04:04:41 -0500 Received: from lta0400828d.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id u5893q5X001659; Wed, 8 Jun 2016 04:04:37 -0500 From: Roger Quadros To: CC: , , , , , , , , , , , , , , , , , Roger Quadros Subject: [PATCH v9 09/14] usb: of: add an API to get OTG device from USB controller node Date: Wed, 8 Jun 2016 12:03:41 +0300 Message-ID: <1465376626-30122-10-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1465376626-30122-1-git-send-email-rogerq@ti.com> References: <1465376626-30122-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 Acked-by: Rob Herring --- Documentation/devicetree/bindings/usb/generic.txt | 3 +++ drivers/usb/common/common.c | 27 +++++++++++++++++++++++ include/linux/usb/of.h | 9 ++++++++ 3 files changed, 39 insertions(+) -- 2.7.4 diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt index bba8257..f6866c1 100644 --- a/Documentation/devicetree/bindings/usb/generic.txt +++ b/Documentation/devicetree/bindings/usb/generic.txt @@ -24,6 +24,9 @@ Optional properties: optional for OTG device. - adp-disable: tells OTG controllers we want to disable OTG ADP, ADP is optional for OTG device. + - 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: 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