From patchwork Wed Nov 20 17:37:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Hecht X-Patchwork-Id: 3213991 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 3189BC045B for ; Wed, 20 Nov 2013 17:39:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0EBB22075F for ; Wed, 20 Nov 2013 17:39:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D65E2076C for ; Wed, 20 Nov 2013 17:39:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753942Ab3KTRjM (ORCPT ); Wed, 20 Nov 2013 12:39:12 -0500 Received: from mail-bk0-f49.google.com ([209.85.214.49]:65505 "EHLO mail-bk0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753698Ab3KTRjL (ORCPT ); Wed, 20 Nov 2013 12:39:11 -0500 Received: by mail-bk0-f49.google.com with SMTP id my13so1395415bkb.22 for ; Wed, 20 Nov 2013 09:39:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UEzA3BtbTgZ6ok18ecaPOa15xFsNaO19vw+Y+UEQ5ow=; b=fq1hes16iA3QX4jc+zlP86w0tglKh5hVNmV6tGye7cUpaa4V2HhcEbNFaxRP4VHQlt yq86WrwY+HXY0p+YgVkDFZ0u7NuEY8MAPBx/1Q/P3sBafClpCgRCjT7L6im8xmlaZl+9 8lNot75xCo3FoB8WlsWI2nTtk7vqgiH920JkfSpQ1OBJsTAgr2Q+QhwCseXY18Ahq2vQ GVosYCYfHXoWreJ6wqTPV0sTSv8o6lbr+k19b0Mg7ILcdJ+p3S5Mhf3MC9E6zZfVYT8m 06YrwQsJiiSV+1wFIipU7WIDNK+qUvDGa34vXKyj6FHvkZO5AcRZcZmB0cwMJiPSPcBV dGIg== X-Received: by 10.204.171.142 with SMTP id h14mr771594bkz.30.1384969149778; Wed, 20 Nov 2013 09:39:09 -0800 (PST) Received: from groucho.site ([109.201.152.7]) by mx.google.com with ESMTPSA id no2sm24117885bkb.15.2013.11.20.09.39.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Nov 2013 09:39:09 -0800 (PST) From: Ulrich Hecht To: Simon Horman Cc: linux-sh@vger.kernel.org, Magnus Damm , Kuninori Morimoto , Laurent Pinchart , Valentine Barshak , linux-usb@vger.kernel.org, Felipe Balbi , Alan Stern Subject: [PATCH 2/9] usb: hcd: Remove USB phy if needed Date: Wed, 20 Nov 2013 18:37:59 +0100 Message-Id: <1384969086-8920-3-git-send-email-ulrich.hecht@gmail.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1384969086-8920-1-git-send-email-ulrich.hecht@gmail.com> References: <1384969086-8920-1-git-send-email-ulrich.hecht@gmail.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=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 From: Valentine Barshak 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. */