From patchwork Fri Apr 19 11:25:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Petrosyan X-Patchwork-Id: 10909743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F335C17EE for ; Fri, 19 Apr 2019 20:05:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5FEB1FF83 for ; Fri, 19 Apr 2019 20:05:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA2F025223; Fri, 19 Apr 2019 20:05:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58B2928A78 for ; Fri, 19 Apr 2019 20:05:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728115AbfDSUFx (ORCPT ); Fri, 19 Apr 2019 16:05:53 -0400 Received: from dc8-smtprelay2.synopsys.com ([198.182.47.102]:36794 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727722AbfDSUFw (ORCPT ); Fri, 19 Apr 2019 16:05:52 -0400 Received: from mailhost.synopsys.com (badc-mailhost2.synopsys.com [10.192.0.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 308E6C1208; Fri, 19 Apr 2019 11:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1555673152; bh=aKZOdZxlVugT7qhUL1bSwf30K2+a+aXa560JPFGWJ7k=; h=From:To:CC:Subject:Date:References:In-Reply-To:From; b=K8nWyjktBUE8RuEJCbGMqW7pMRVlkCVqSxgwydI01suKp/2wMnyWcDrwry3BFQFAM gi9uyG/lvFX/8TV+bfTIUYFDpGGkwSJoOAOpqiQntcwuEBqVZcCK4l2zR0feIez3+C gojvJEiZ1EfjKHNtHmNt/6IZO+0gGOpu26fsS1g93nIojFO1R9vwUHfUCY35S/wMho SOyUslsD3mTpefwD2cXkfcNiUBlOckdCAdy8mcbjUqJruYR+f7AuYYacZ2nn6LwN84 YzqpRQswRLB8b2PscXzRO+r/UisW5OKzQkz1oityN05QuGcMNH+zzYvliRAQD/2Oj3 gIlKnoaFc18ZA== Received: from US01WEHTC3.internal.synopsys.com (us01wehtc3.internal.synopsys.com [10.15.84.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPS id 7C261A0067; Fri, 19 Apr 2019 11:25:51 +0000 (UTC) Received: from US01HYBRID2.internal.synopsys.com (10.15.246.24) by US01WEHTC3.internal.synopsys.com (10.15.84.232) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 19 Apr 2019 04:25:51 -0700 Received: from NAM03-CO1-obe.outbound.protection.outlook.com (10.13.134.195) by mrs.synopsys.com (10.15.246.24) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 19 Apr 2019 04:25:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.onmicrosoft.com; s=selector1-synopsys-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aKZOdZxlVugT7qhUL1bSwf30K2+a+aXa560JPFGWJ7k=; b=cB1owIvbO0gws1lbxpkaJrWefhmJ5q6VoBYV8+Ofc9SfQrSXDtwIrrSrJTSRsjeoUyopk/0R1umHHTnp3EbiDNukbFarJDN6t4cnVDTE4hXcEvP2qRvHkv5OTkuK54HgQNxUQ2O88GTGz5A0Cy5seiVttnJ0YeaigJsHsymx5Vg= Received: from SN1PR12MB2431.namprd12.prod.outlook.com (52.132.195.146) by SN1PR12MB2383.namprd12.prod.outlook.com (52.132.194.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1813.14; Fri, 19 Apr 2019 11:25:49 +0000 Received: from SN1PR12MB2431.namprd12.prod.outlook.com ([fe80::5ca6:ee5f:1147:df5a]) by SN1PR12MB2431.namprd12.prod.outlook.com ([fe80::5ca6:ee5f:1147:df5a%4]) with mapi id 15.20.1813.013; Fri, 19 Apr 2019 11:25:49 +0000 From: Artur Petrosyan To: Felipe Balbi , Greg Kroah-Hartman , Minas Harutyunyan , "linux-usb@vger.kernel.org" CC: John Youn , Artur Petrosyan Subject: [PATCH v1 14/14] usb: dwc2: Add enter/exit hibernation from system issued suspend/resume Thread-Topic: [PATCH v1 14/14] usb: dwc2: Add enter/exit hibernation from system issued suspend/resume Thread-Index: AQHU9qKj4BXfhuera0qVm1faf23VEw== Date: Fri, 19 Apr 2019 11:25:49 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR0901CA0092.eurprd09.prod.outlook.com (2603:10a6:800:7e::18) To SN1PR12MB2431.namprd12.prod.outlook.com (2603:10b6:802:27::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=arturp@synopsys.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [84.53.141.185] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 410a0eb8-4cc2-4a5d-b02a-08d6c4b9c599 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600141)(711020)(4605104)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:SN1PR12MB2383; x-ms-traffictypediagnostic: SN1PR12MB2383: x-microsoft-antispam-prvs: x-forefront-prvs: 0012E6D357 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(136003)(39850400004)(396003)(376002)(346002)(189003)(199004)(6436002)(102836004)(486006)(26005)(186003)(386003)(4326008)(305945005)(2906002)(6506007)(446003)(76176011)(7736002)(97736004)(5660300002)(81156014)(66476007)(11346002)(81166006)(66556008)(6486002)(476003)(256004)(14444005)(53936002)(25786009)(107886003)(71190400001)(71200400001)(86362001)(6512007)(99286004)(15650500001)(54906003)(110136005)(316002)(2616005)(68736007)(8676002)(66066001)(6116002)(36756003)(14454004)(478600001)(2501003)(8936002)(118296001)(3846002)(66446008)(52116002)(64756008)(66946007)(73956011);DIR:OUT;SFP:1102;SCL:1;SRVR:SN1PR12MB2383;H:SN1PR12MB2431.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: synopsys.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 8X/Cuq8/aK3aXmLCxzfdAHQ1WpYi0ZgC1DUvOg4sGWjFyVeqlKPS+u7Bo+y9khf9yxdxKUtfGAc+9A2/BqWdsKdCLHg4afO4oHSDFZVQJiXqDzD7WyMGn94CSHi8mc6uWGN99S8x0d3et7h+3NlEnNRVrSd4UHSBzil7pN+qe8HMgAg8h/IHXukj2rTvrfr3JzyzW3jc0ZjPFvmSCtDfR3qxTgko9SjpP8kif18HcAIKD5iE02LyHuzjYRQqSlUeogV919mGTy63OctxKb7fn2tuQK+oPgVPVOyYQjIuoyjEk4+n5GF2z2zLzbaB8AsO2G8HDVlaYi6OBPDIbi7OUdpSJHvd64O2HqzC5SWH2nJcJxglK6vOYlRV/vpDMTpXuhc4aY4pdE62bZ/4vi89Q1lR3LQPfGg/OAq8HRFcxf0= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 410a0eb8-4cc2-4a5d-b02a-08d6c4b9c599 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Apr 2019 11:25:49.4520 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: c33c9f88-1eb7-4099-9700-16013fd9e8aa X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2383 X-OriginatorOrg: synopsys.com Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Added a new flow of entering and exiting hibernation when PC is hibernated or suspended. Signed-off-by: Artur Petrosyan --- drivers/usb/dwc2/hcd.c | 128 +++++++++++++++++++++++++++++++------------------ 1 file changed, 81 insertions(+), 47 deletions(-) diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 45d4a3e1ebd2..f1e92a287cb1 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -4510,35 +4510,54 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd) if (hsotg->op_state == OTG_STATE_B_PERIPHERAL) goto unlock; - if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_PARTIAL || + if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE || hsotg->flags.b.port_connect_status == 0) goto skip_power_saving; - /* - * Drive USB suspend and disable port Power - * if usb bus is not suspended. - */ - if (!hsotg->bus_suspended) { - hprt0 = dwc2_read_hprt0(hsotg); - hprt0 |= HPRT0_SUSP; - hprt0 &= ~HPRT0_PWR; - dwc2_writel(hsotg, hprt0, HPRT0); - spin_unlock_irqrestore(&hsotg->lock, flags); - dwc2_vbus_supply_exit(hsotg); - spin_lock_irqsave(&hsotg->lock, flags); - } + switch (hsotg->params.power_down) { + case DWC2_POWER_DOWN_PARAM_PARTIAL: + /* + * Drive USB suspend and disable port Power + * if usb bus is not suspended. + */ + if (!hsotg->bus_suspended) { + hprt0 = dwc2_read_hprt0(hsotg); + hprt0 |= HPRT0_SUSP; + hprt0 &= ~HPRT0_PWR; + dwc2_writel(hsotg, hprt0, HPRT0); + spin_unlock_irqrestore(&hsotg->lock, flags); + dwc2_vbus_supply_exit(hsotg); + spin_lock_irqsave(&hsotg->lock, flags); + } - /* Enter partial_power_down */ - ret = dwc2_enter_partial_power_down(hsotg); - if (ret) { - if (ret != -ENOTSUPP) - dev_err(hsotg->dev, - "enter partial_power_down failed\n"); + /* Enter partial_power_down */ + ret = dwc2_enter_partial_power_down(hsotg); + if (ret) { + if (ret != -ENOTSUPP) + dev_err(hsotg->dev, + "enter partial_power_down failed\n"); + goto skip_power_saving; + } + hsotg->bus_suspended = true; + break; + case DWC2_POWER_DOWN_PARAM_HIBERNATION: + if (!hsotg->bus_suspended) { + /* Enter hibernation */ + spin_unlock_irqrestore(&hsotg->lock, flags); + ret = dwc2_enter_hibernation(hsotg, 1); + spin_lock_irqsave(&hsotg->lock, flags); + if (ret && ret != -ENOTSUPP) + dev_err(hsotg->dev, + "%s: enter hibernation failed\n", + __func__); + } else { + goto skip_power_saving; + } + break; + default: goto skip_power_saving; } - hsotg->bus_suspended = true; - /* Ask phy to be suspended */ if (!IS_ERR_OR_NULL(hsotg->uphy)) { spin_unlock_irqrestore(&hsotg->lock, flags); @@ -4564,17 +4583,17 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd) int ret = 0; u32 hprt0; - hprt0 = dwc2_read_hprt0(hsotg); - spin_lock_irqsave(&hsotg->lock, flags); - if (dwc2_is_device_mode(hsotg)) + if (!hsotg->bus_suspended) goto unlock; if (hsotg->lx_state != DWC2_L2) goto unlock; - if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_PARTIAL || + hprt0 = dwc2_read_hprt0(hsotg); + + if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE || hprt0 & HPRT0_CONNSTS) { hsotg->lx_state = DWC2_L0; goto unlock; @@ -4597,36 +4616,51 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd) spin_lock_irqsave(&hsotg->lock, flags); } - /* Exit partial_power_down */ - ret = dwc2_exit_partial_power_down(hsotg, true); - if (ret && (ret != -ENOTSUPP)) - dev_err(hsotg->dev, "exit partial_power_down failed\n"); + switch (hsotg->params.power_down) { + case DWC2_POWER_DOWN_PARAM_PARTIAL: - hsotg->lx_state = DWC2_L0; + /* Exit partial_power_down */ + ret = dwc2_exit_partial_power_down(hsotg, true); + if (ret && (ret != -ENOTSUPP)) + dev_err(hsotg->dev, "exit partial_power_down failed\n"); - spin_unlock_irqrestore(&hsotg->lock, flags); + hsotg->lx_state = DWC2_L0; - if (hsotg->bus_suspended) { - spin_lock_irqsave(&hsotg->lock, flags); - hsotg->flags.b.port_suspend_change = 1; spin_unlock_irqrestore(&hsotg->lock, flags); - dwc2_port_resume(hsotg); - } else { - dwc2_vbus_supply_init(hsotg); - /* Wait for controller to correctly update D+/D- level */ - usleep_range(3000, 5000); + if (hsotg->bus_suspended) { + spin_lock_irqsave(&hsotg->lock, flags); + hsotg->flags.b.port_suspend_change = 1; + spin_unlock_irqrestore(&hsotg->lock, flags); + dwc2_port_resume(hsotg); + } else { + dwc2_vbus_supply_init(hsotg); - /* - * Clear Port Enable and Port Status changes. - * Enable Port Power. - */ - dwc2_writel(hsotg, HPRT0_PWR | HPRT0_CONNDET | + /* Wait for controller to correctly update D+/D- level */ + usleep_range(3000, 5000); + + /* + * Clear Port Enable and Port Status changes. + * Enable Port Power. + */ + dwc2_writel(hsotg, HPRT0_PWR | HPRT0_CONNDET | HPRT0_ENACHG, HPRT0); - /* Wait for controller to detect Port Connect */ - usleep_range(5000, 7000); + /* Wait for controller to detect Port Connect */ + usleep_range(5000, 7000); + } + break; + case DWC2_POWER_DOWN_PARAM_HIBERNATION: + + /* Exit host hibernation. */ + if (hsotg->hibernated) + dwc2_exit_hibernation(hsotg, 0, 0, 1); + break; + default: + goto unlock; } + spin_unlock_irqrestore(&hsotg->lock, flags); + return ret; unlock: spin_unlock_irqrestore(&hsotg->lock, flags);