From patchwork Tue Dec 3 21:42:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentine Barshak X-Patchwork-Id: 3278781 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 517369F37A for ; Tue, 3 Dec 2013 21:42:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 78E3720452 for ; Tue, 3 Dec 2013 21:42:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8EFFF20439 for ; Tue, 3 Dec 2013 21:42:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755234Ab3LCVma (ORCPT ); Tue, 3 Dec 2013 16:42:30 -0500 Received: from mail-lb0-f170.google.com ([209.85.217.170]:61939 "EHLO mail-lb0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755171Ab3LCVm1 (ORCPT ); Tue, 3 Dec 2013 16:42:27 -0500 Received: by mail-lb0-f170.google.com with SMTP id w7so8998404lbi.15 for ; Tue, 03 Dec 2013 13:42:26 -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=ZywEVy3HxoOxpvdi8FBeIfSJSt4A09/VI+6fNECphLE=; b=JLwjFIWR2zXUvcQPQ6BWR0S8tGANSfp2+g36MdF58yv8/JgJyf4W+G8gslP8akKQ7k Slx3mC7g2YMftPDkqOqij6Ei30n2hCtyzDHeMl/UVFPYgUrR181veFI2wx9ObCvfd4Xe grAMYQ/30KrXix15dQeLdmz04Vf5YOBUwLWOlA8E2ZiLNig6Pyam9Aqb94DYzPOKC+Nq C7sSwYBK99gIMOaZVEL6aNJqjzQ8UHKpOhYCHMRv4ek9lQjEiFwjDzlH4LIqtl9HvjTX pwvZ0ccdsxzyHEb3kRtLhZLwKpv1CCoKqlKOOVtzuLNqPz6XbFTsj/dSszgfqrl50q0+ PDBA== X-Gm-Message-State: ALoCoQnrm4r6VQCtO3tDEOyHRrW8i8s9KXqyDUITLfZMkRvhP92h51G+iDXcENJ3fjOwA4NsLMo0 X-Received: by 10.112.172.69 with SMTP id ba5mr18269lbc.55.1386106946555; Tue, 03 Dec 2013 13:42:26 -0800 (PST) Received: from black.localnet ([93.100.122.208]) by mx.google.com with ESMTPSA id m5sm88888118laj.4.2013.12.03.13.42.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Dec 2013 13:42:25 -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: [PATCH 1/2] usb: hcd: Remove USB phy if needed Date: Wed, 4 Dec 2013 01:42:21 +0400 Message-Id: <1386106942-13730-2-git-send-email-valentine.barshak@cogentembedded.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1386106942-13730-1-git-send-email-valentine.barshak@cogentembedded.com> References: <1386106942-13730-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 6bffb8c..7527c8e 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -44,6 +44,7 @@ #include #include +#include #include "usb.h" @@ -2603,7 +2604,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) @@ -2734,6 +2735,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); @@ -2806,6 +2813,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 b8aba19..758ce80 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -134,6 +134,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. */