From patchwork Tue Nov 5 20:33:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentine Barshak X-Patchwork-Id: 3143811 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 713F8BEEB2 for ; Tue, 5 Nov 2013 20:33:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4A08B205CA for ; Tue, 5 Nov 2013 20:33:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3C0EB20588 for ; Tue, 5 Nov 2013 20:33:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755521Ab3KEUde (ORCPT ); Tue, 5 Nov 2013 15:33:34 -0500 Received: from mail-la0-f48.google.com ([209.85.215.48]:59386 "EHLO mail-la0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755514Ab3KEUdc (ORCPT ); Tue, 5 Nov 2013 15:33:32 -0500 Received: by mail-la0-f48.google.com with SMTP id ec20so3020837lab.7 for ; Tue, 05 Nov 2013 12:33:31 -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=OlgZfDXUG226vWktpsebj7dNK6nV5K1NCk69gdrwtqjKiGv2/i3p8CICOVsBJ2e+MF ZxpaW1T2Gq+fhjCbrXA5a67M5sOxbO5Si36p+mTw3MiM3tfsbBogtOQosSirbyayXSke UtqfQeBJw5YwHgAIIt5ESrJfWIJRO+Atl/wn//5OddXlDY/jp9Q3NVye1JJLCtZaBhNM yjQbK526Fyh9OivVNbHQG5aOqj/SqmQlbgVTRKIr6PHLtgSSvi+ZzJKD/LyL4Ma3D+y4 5sY+quELXDcUn9U/CfhVie3a5kLTyHNvVquQwLXwlRZgAegpAi8Qk/TYWuqU5HHGfIAk eh2w== X-Gm-Message-State: ALoCoQkIjSCT0hT6mMByRsLnG9baVbY859qwIS1SMAz5SAqtu/oDjLzdIO0F1pK/8kJiBUsOps1R X-Received: by 10.112.145.105 with SMTP id st9mr114588lbb.46.1383683610942; Tue, 05 Nov 2013 12:33:30 -0800 (PST) Received: from black.localnet ([93.100.122.208]) by mx.google.com with ESMTPSA id 8sm29568034laq.5.2013.11.05.12.33.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Nov 2013 12:33:30 -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 PATCH 1/2] usb: hcd: Remove USB phy if needed Date: Wed, 6 Nov 2013 00:33:26 +0400 Message-Id: <1383683607-28119-2-git-send-email-valentine.barshak@cogentembedded.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1383683607-28119-1-git-send-email-valentine.barshak@cogentembedded.com> References: <1383683607-28119-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 --- 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. */