From patchwork Thu Jan 10 16:51:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 1961261 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 709393FC85 for ; Thu, 10 Jan 2013 16:55:58 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TtLMM-0005Zc-AU; Thu, 10 Jan 2013 16:52:06 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TtLM3-0005Ut-0M for linux-arm-kernel@lists.infradead.org; Thu, 10 Jan 2013 16:51:48 +0000 Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id r0AGpfIZ028032; Thu, 10 Jan 2013 10:51:41 -0600 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id r0AGpfPR029715; Thu, 10 Jan 2013 10:51:41 -0600 Received: from dlelxv22.itg.ti.com (172.17.1.197) by dfle73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.1.323.3; Thu, 10 Jan 2013 10:51:41 -0600 Received: from rockdesk.itg.ti.com (h113-58.vpn.ti.com [172.24.113.58]) by dlelxv22.itg.ti.com (8.13.8/8.13.8) with ESMTP id r0AGpYI0023935; Thu, 10 Jan 2013 10:51:39 -0600 From: Roger Quadros To: Subject: [PATCH 02/14] usb: phy: Add new API usb_get_phy_from_dev() Date: Thu, 10 Jan 2013 18:51:22 +0200 Message-ID: <1357836694-30788-3-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1357836694-30788-1-git-send-email-rogerq@ti.com> References: <1357836694-30788-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130110_115147_241708_8903CB87 X-CRM114-Status: GOOD ( 11.32 ) X-Spam-Score: -7.6 (-------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-7.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [198.47.26.153 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: sameo@linux.intel.com, tony@atomide.com, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kishon@ti.com, linux-arm-kernel@lists.infradead.org, rogerq@ti.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This API allows PHY users to get the usb_phy data structure from a device handle. Signed-off-by: Roger Quadros --- drivers/usb/otg/otg.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/usb/phy.h | 6 ++++++ 2 files changed, 42 insertions(+), 0 deletions(-) diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c index a30c041..ba3a568 100644 --- a/drivers/usb/otg/otg.c +++ b/drivers/usb/otg/otg.c @@ -35,6 +35,21 @@ static struct usb_phy *__usb_find_phy(struct list_head *list, return ERR_PTR(-ENODEV); } +static struct usb_phy *__usb_find_phy_dev(struct list_head *list, + struct device *dev) +{ + struct usb_phy *phy; + + list_for_each_entry(phy, list, head) { + if (phy->dev != dev) + 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; @@ -77,6 +92,27 @@ struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type) } EXPORT_SYMBOL(devm_usb_get_phy); +struct usb_phy *usb_get_phy_from_dev(struct device *dev) +{ + struct usb_phy *phy = NULL; + unsigned long flags; + + spin_lock_irqsave(&phy_lock, flags); + + phy = __usb_find_phy_dev(&phy_list, dev); + if (IS_ERR(phy)) { + dev_err(dev, "%s: unable to find PHY\n", __func__); + goto done; + } + + get_device(phy->dev); + +done: + spin_unlock_irqrestore(&phy_lock, flags); + return phy; +} +EXPORT_SYMBOL(usb_get_phy_from_dev); + /** * usb_get_phy - find the USB PHY * @type - the type of the phy the controller requires diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index a29ae1e..cd798c4 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -147,6 +147,7 @@ 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 *usb_get_phy_from_dev(struct device *dev); extern struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type); extern void usb_put_phy(struct usb_phy *); @@ -157,6 +158,11 @@ static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) return NULL; } +static inline struct usb_phy *usb_get_phy_from_dev(struct device *dev) +{ + return NULL; +} + static inline struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type) {