Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp498890pxb; Wed, 14 Apr 2021 22:42:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWmV8WrmF2g2hLcu+fJ6CouJ/nSQh/3cN1sdM+9yA+fBkR6sjYiuCzNubhUpny/6pezmAK X-Received: by 2002:aa7:859a:0:b029:253:3fbc:16e1 with SMTP id w26-20020aa7859a0000b02902533fbc16e1mr1594227pfn.10.1618465342925; Wed, 14 Apr 2021 22:42:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618465342; cv=none; d=google.com; s=arc-20160816; b=TOzPaDrOjrJIhyBagGZplkyGzigC8cEg84IUvWALIsWDWRFI965Ot+XIkhvQlqIdBk qOcU+tqjeZ55KjYLhlw5eA13R0gqDnPY5NHaB3Dh2412hK/UWUvD0ENkBufgPcjkz65e xlsxNc9dZMRKwPhIeE45eVj8sMJgkj7/FtsHDrCsX3kR2RyM+iCqOr0CJb2iK9uc6zs/ YdkdAgY9lsW6Q4igDK/+bm5q99apVV3t7dACK63wU4uxiAzffwVpZnM0i5t4nUud4QY5 5yHxbDSAh5opTZMHS/RNPqjT5uYdW7V1/ojGZ2TdTQ9nS+K8NJdds0u+FwZYvYhk3Bpv xDVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:from:references:in-reply-to :message-id:date:dkim-signature; bh=8E/E8uOzHuSmmyxB3b7u49L7oQR10whcut3M3ZBT79Y=; b=T5w0l8Fp/AWokGGvrtpHxgpaV/kCGGMvIyV8mDpcAKzIckfcxYK5B/EDjWrs9Mop5S J42ZDe36io2yQcIKr/pwWZuifNJwbcW8Ja+IlwYa/FN3xKQ1HO/ppTLph2i7fKX52qUD yYUeD4kjBjShd1itbfD4cNnH4xoRIt/sFrFrf6yYNT2cjbssh2IxksURsMHqd8vxDkeX fZ6vKvpjy5ceLJdUnhf2tEo2/usg5F7zRH/Trb7HJfXoIGp3lMO5HIHDiyOkFKq7ksJ4 sCVSjFFS5a/efKHA9PtabjPPozi7QjWoK4Qyh1seuh4Zms8IADddH1l9bvPaMleXSG8D ofvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=ZupbC799; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z22si2271415pfc.159.2021.04.14.22.42.11; Wed, 14 Apr 2021 22:42:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=ZupbC799; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230308AbhDOFlc (ORCPT + 99 others); Thu, 15 Apr 2021 01:41:32 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:56518 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230090AbhDOFlb (ORCPT ); Thu, 15 Apr 2021 01:41:31 -0400 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (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 39637404B4; Thu, 15 Apr 2021 05:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1618465269; bh=sMYUcJjmu6mpKPzTc6LOGrbWk7P4Y2uZaj8qYVP7Nzo=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=ZupbC7992yJg9PJjU9XWNfboBKnb6zFoFvYOPIFlJB3Sg/TRMcmt5z6e4ArYn/2cf MN9WtATVDGXx6FWaZTn19CFlxS8D96IdZQlEI7E2YNONs/I68u5eyYmLO/IJh6RgGr qH6OMhI2hR1fohXpsxAiEda7yZIcWjcoeN1iyNRlfXaEeU6076t6kyrjqyseKUfSYx lCUWO/lrvVofS6JYWBSY90V13t01wFG+/mL43J4wvMjb6a2+IJ5XsIDw2CEO/Jynti IDbpRoK/0XhLy/7MuU+eYjXNPRGkYjDZYT3LqNOUF+4OLaPE0I6WjOruK73ZMUeMmo APnQXzJpPYGXA== Received: from razpc-HP (razpc-hp.internal.synopsys.com [10.116.126.207]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 3654DA005C; Thu, 15 Apr 2021 05:41:06 +0000 (UTC) Received: by razpc-HP (sSMTP sendmail emulation); Thu, 15 Apr 2021 09:41:04 +0400 Date: Thu, 15 Apr 2021 09:41:04 +0400 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Artur Petrosyan Subject: [PATCH 13/15] usb: dwc2: Add exit hibernation mode before removing drive To: Felipe Balbi , Greg Kroah-Hartman , Minas Harutyunyan , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: John Youn , Artur Petrosyan Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When dwc2 core is in hibernation mode loading driver again causes driver fail. Because in that mode registers are not accessible. In order to exit from hibernation checking dwc2 core power saving state in "dwc2_driver_remove()" function. If core is in hibernation, then checking the operational mode of the driver. To check whether dwc2 core is operating in host mode or device mode there is one way which is retrieving the backup value of "gotgctl" and compare the "CurMod" value. If previously core entered hibernation in host mode then the exit is performed for host if not then exit is performed for device mode. The introduced checking is because in hibernation state all registers are not accessible. Signed-off-by: Artur Petrosyan --- drivers/usb/dwc2/platform.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index f8b819cfa80e..2ae4748ed5ec 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -316,8 +316,24 @@ static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg) static int dwc2_driver_remove(struct platform_device *dev) { struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); + struct dwc2_gregs_backup *gr; int ret = 0; + /* Exit Hibernation when driver is removed. */ + if (hsotg->hibernated) { + if (gr->gotgctl & GOTGCTL_CURMODE_HOST) { + ret = dwc2_exit_hibernation(hsotg, 0, 0, 1); + if (ret) + dev_err(hsotg->dev, + "exit hibernation failed.\n"); + } else { + ret = dwc2_exit_hibernation(hsotg, 0, 0, 0); + if (ret) + dev_err(hsotg->dev, + "exit hibernation failed.\n"); + } + } + /* Exit Partial Power Down when driver is removed. */ if (hsotg->in_ppd) { ret = dwc2_exit_partial_power_down(hsotg, 0, true); -- 2.25.1