From patchwork Fri May 30 14:12:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 4271031 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 242B2BEEA7 for ; Fri, 30 May 2014 14:12:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3050620351 for ; Fri, 30 May 2014 14:12:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A920202E5 for ; Fri, 30 May 2014 14:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752856AbaE3OMx (ORCPT ); Fri, 30 May 2014 10:12:53 -0400 Received: from relmlor2.renesas.com ([210.160.252.172]:11805 "EHLO relmlie1.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752069AbaE3OMw (ORCPT ); Fri, 30 May 2014 10:12:52 -0400 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie1.idc.renesas.com with ESMTP; 30 May 2014 23:12:51 +0900 Received: from relmlac4.idc.renesas.com (relmlac4.idc.renesas.com [10.200.69.24]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 8AE2144AF0; Fri, 30 May 2014 23:12:51 +0900 (JST) Received: by relmlac4.idc.renesas.com (Postfix, from userid 0) id 89FEC480A6; Fri, 30 May 2014 23:12:51 +0900 (JST) Received: from relmlac4.idc.renesas.com (localhost [127.0.0.1]) by relmlac4.idc.renesas.com (Postfix) with ESMTP id 80313480A4; Fri, 30 May 2014 23:12:51 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac4.idc.renesas.com with ESMTP id ZAA27811; Fri, 30 May 2014 23:12:51 +0900 X-IronPort-AV: E=Sophos;i="4.98,941,1392130800"; d="scan'208,223";a="160989811" Received: from mail-hk1lp0123.outbound.protection.outlook.com (HELO APAC01-HK1-obe.outbound.protection.outlook.com) ([207.46.51.123]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES128-SHA; 30 May 2014 23:12:50 +0900 Received: from [10.161.20.55] (211.11.155.147) by SIXPR06MB333.apcprd06.prod.outlook.com (10.141.120.15) with Microsoft SMTP Server (TLS) id 15.0.949.11; Fri, 30 May 2014 14:12:49 +0000 Message-ID: <538891DC.605@renesas.com> Date: Fri, 30 May 2014 23:12:44 +0900 From: Yoshihiro Shimoda User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Greg Kroah-Hartman , "linux-usb@vger.kernel.org" , Sergei Shtylyov CC: SH-Linux , Magnus Damm Subject: [PATCH v3] usb: hcd: add generic PHY support X-Originating-IP: [211.11.155.147] X-ClientProxiedBy: SINPR06CA016.apcprd06.prod.outlook.com (10.141.109.46) To SIXPR06MB333.apcprd06.prod.outlook.com (10.141.120.15) X-Microsoft-Antispam: BL:0; ACTION:Default; RISK:Low; SCL:0; SPMLVL:NotSpam; PCL:0; RULEID: X-Forefront-PRVS: 02272225C5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(6049001)(6009001)(428001)(199002)(189002)(54356999)(19580405001)(81342001)(36756003)(74662001)(86362001)(47776003)(65956001)(74502001)(66066001)(92726001)(20776003)(42186004)(4396001)(65816999)(64706001)(33656002)(79102001)(102836001)(31966008)(85852003)(19580395003)(83506001)(83322001)(64126003)(76482001)(81542001)(99396002)(21056001)(101416001)(80022001)(23756003)(83072002)(50466002)(50986999)(87976001)(65806001)(77982001)(92566001)(46102001)(41533002); DIR:OUT; SFP:; SCL:1; SRVR:SIXPR06MB333; H:[10.161.20.55]; FPR:; MLV:nov; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=yoshihiro.shimoda.uh@renesas.com; X-OriginatorOrg: renesas.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.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 Sergei Shtylyov Add the generic PHY support, analogous to the USB PHY support. Intended it to be used with the PCI EHCI/OHCI drivers and the xHCI platform driver. Signed-off-by: Sergei Shtylyov Signed-off-by: Yoshihiro Shimoda --- This patch is against the 'usb-next' branch of Greg KH's 'usb.git' repo. (commit id = 70d2f61fc7559df3d5be32a9d01efdb9ee1b11d8) Changes in version 3: - rebased the current usb-next. - I tested this patch on my R-Car H2 USB 3.0 driver (not merged yet) drivers/usb/core/hcd.c | 42 ++++++++++++++++++++++++++++++++++++++++-- include/linux/usb/hcd.h | 3 ++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index bec31e2..2841149 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -2649,6 +2650,29 @@ int usb_add_hcd(struct usb_hcd *hcd, } } + if (IS_ENABLED(CONFIG_GENERIC_PHY)) { + struct phy *phy = phy_get(hcd->self.controller, "usb"); + + if (IS_ERR(phy)) { + retval = PTR_ERR(phy); + if (retval == -EPROBE_DEFER) + goto err_phy; + } else { + retval = phy_init(phy); + if (retval) { + phy_put(phy); + goto err_phy; + } + retval = phy_power_on(phy); + if (retval) { + phy_exit(phy); + phy_put(phy); + goto err_phy; + } + hcd->gen_phy = phy; + } + } + dev_info(hcd->self.controller, "%s\n", hcd->product_desc); /* Keep old behaviour if authorized_default is not in [0, 1]. */ @@ -2664,7 +2688,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"); - goto err_remove_phy; + goto err_create_buf; } if ((retval = usb_register_bus(&hcd->self)) < 0) @@ -2791,7 +2815,14 @@ err_allocate_root_hub: usb_deregister_bus(&hcd->self); err_register_bus: hcd_buffer_destroy(hcd); -err_remove_phy: +err_create_buf: + if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->gen_phy) { + phy_power_off(hcd->gen_phy); + phy_exit(hcd->gen_phy); + phy_put(hcd->gen_phy); + hcd->gen_phy = NULL; + } +err_phy: if (hcd->remove_phy && hcd->phy) { usb_phy_shutdown(hcd->phy); usb_put_phy(hcd->phy); @@ -2868,6 +2899,13 @@ void usb_remove_hcd(struct usb_hcd *hcd) usb_deregister_bus(&hcd->self); hcd_buffer_destroy(hcd); + + if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->gen_phy) { + phy_power_off(hcd->gen_phy); + phy_exit(hcd->gen_phy); + phy_put(hcd->gen_phy); + hcd->gen_phy = NULL; + } if (hcd->remove_phy && hcd->phy) { usb_phy_shutdown(hcd->phy); usb_put_phy(hcd->phy); diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index 485cd5e..2aefbcc 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -106,7 +106,8 @@ struct usb_hcd { * OTG and some Host controllers need software interaction with phys; * other external phys should be software-transparent */ - struct usb_phy *phy; + struct usb_phy *phy; + struct phy *gen_phy; /* Flags that need to be manipulated atomically because they can * change while the host controller is running. Always use