From patchwork Thu Nov 7 11:14:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentine Barshak X-Patchwork-Id: 3152211 X-Patchwork-Delegate: lethal@linux-sh.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A0D1FBEEB2 for ; Thu, 7 Nov 2013 11:14:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 842AE204C9 for ; Thu, 7 Nov 2013 11:14:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9419F20443 for ; Thu, 7 Nov 2013 11:14:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754527Ab3KGLOg (ORCPT ); Thu, 7 Nov 2013 06:14:36 -0500 Received: from mail-la0-f41.google.com ([209.85.215.41]:54366 "EHLO mail-la0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754445Ab3KGLOe (ORCPT ); Thu, 7 Nov 2013 06:14:34 -0500 Received: by mail-la0-f41.google.com with SMTP id ea20so301210lab.14 for ; Thu, 07 Nov 2013 03:14:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uY2ikvCS/2tzVy4PRkWpG3cXwYAeMgnPN+BvF3m8lis=; b=ix4VQql6XDsVSfVsaMYQATUSsvDnGBCL4sonCDsnZZkLuVSQ2yluLO+5MzaAD1Ojdj oFWdvuROlG2Xi/NJiQ7/64hYC6wtg+E6JiXyRB1xChH54WLe9S7rYlDoxV3CnLTlO/3g 5oHwZHNTVWQ3GU85MSKvuKjHj7DSg/hnTSJCTCctikrxm5cdtZPHcoGF710JAWQGE6oN fZXjlHzTTjwAZJ9KjXLK6+tf4RInPifn+fol4VyGwWEm3pBJptW0U0778YxW4Kh7Wp1y xje/wdt4rdmkdZQ2idL+Eewo0H0SA+rUwwm+muk69yfd8RkBMj8Me/efUt/zFCA+mxEL lQ+A== X-Gm-Message-State: ALoCoQlJNu00sBQ/Mn8jtXt2EW3R3JUaDlRkCe3HL/itg5cANZg2Y1rul1k7ywhAWHA2MDLXAZR6 X-Received: by 10.112.150.103 with SMTP id uh7mr6125498lbb.34.1383822873399; Thu, 07 Nov 2013 03:14:33 -0800 (PST) Received: from black.localnet ([93.100.122.208]) by mx.google.com with ESMTPSA id vz9sm2479739lbb.17.2013.11.07.03.14.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Nov 2013 03:14:32 -0800 (PST) From: Valentine Barshak To: linux-usb@vger.kernel.org, linux-sh@vger.kernel.org Cc: Greg KH , Alan Stern , Felipe Balbi , NeilBrown , Mark Brown , Alex Courbot , Simon Horman , Magnus Damm , Kuninori Morimoto , Laurent Pinchart Subject: [RFC V2 PATCH 1/2] usb: hcd: Remove USB phy if needed Date: Thu, 7 Nov 2013 15:14:28 +0400 Message-Id: <1383822869-20283-2-git-send-email-valentine.barshak@cogentembedded.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1383822869-20283-1-git-send-email-valentine.barshak@cogentembedded.com> References: <1383822869-20283-1-git-send-email-valentine.barshak@cogentembedded.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds remove_phy flag to the HCD structure. If the flag is set and if hcd->phy is valid, the phy is shutdown and released whenever usb_add_hcd fails or usb_hcd_remove is called. This can be used by the HCD drivers to auto-remove the external USB phy when it is no longer needed. Signed-off-by: Valentine Barshak Acked-by: Alan Stern --- drivers/usb/core/hcd.c | 14 +++++++++++++- include/linux/usb/hcd.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index d6a8d23..d939521 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -43,6 +43,7 @@ #include #include +#include #include "usb.h" @@ -2611,7 +2612,7 @@ int usb_add_hcd(struct usb_hcd *hcd, */ if ((retval = hcd_buffer_create(hcd)) != 0) { dev_dbg(hcd->self.controller, "pool alloc failed\n"); - return retval; + goto err_remove_phy; } if ((retval = usb_register_bus(&hcd->self)) < 0) @@ -2742,6 +2743,12 @@ err_allocate_root_hub: usb_deregister_bus(&hcd->self); err_register_bus: hcd_buffer_destroy(hcd); +err_remove_phy: + if (hcd->remove_phy && hcd->phy) { + usb_phy_shutdown(hcd->phy); + usb_put_phy(hcd->phy); + hcd->phy = NULL; + } return retval; } EXPORT_SYMBOL_GPL(usb_add_hcd); @@ -2814,6 +2821,11 @@ void usb_remove_hcd(struct usb_hcd *hcd) usb_put_dev(hcd->self.root_hub); usb_deregister_bus(&hcd->self); hcd_buffer_destroy(hcd); + if (hcd->remove_phy && hcd->phy) { + usb_phy_shutdown(hcd->phy); + usb_put_phy(hcd->phy); + hcd->phy = NULL; + } } EXPORT_SYMBOL_GPL(usb_remove_hcd); diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index 75efc45..9c2907b 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -133,6 +133,7 @@ struct usb_hcd { unsigned rh_registered:1;/* is root hub registered? */ unsigned rh_pollable:1; /* may we poll the root hub? */ unsigned msix_enabled:1; /* driver has MSI-X enabled? */ + unsigned remove_phy:1; /* auto-remove USB phy */ /* The next flag is a stopgap, to be removed when all the HCDs * support the new root-hub polling mechanism. */