Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2637365pxb; Tue, 13 Apr 2021 06:47:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9SnNBvt/LQZsR2mCvetpjGJGffdCgbWunN9xCwXTSgob1zqdWsgsnqWiM+tFkLVwzwGyW X-Received: by 2002:a63:ee02:: with SMTP id e2mr16094995pgi.280.1618321624744; Tue, 13 Apr 2021 06:47:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618321624; cv=none; d=google.com; s=arc-20160816; b=Mx/jKUIzfCr5HMlDwDjLyCDwrHZftjPMSsnqhkaXlKr69YzM/cTxQdEynvX4ZTGPTB 5n+4C3ELAytuX2dn+5uK8tlUF9PRTTfrhnYinLBNV0/EyFsXaKz7Nr7RwJMxHuRzMrj6 jg5bfQMNxj110vX0nGriZLjee/A8nmS1NEN6b+yLovKA8ThL1hs9YJay19ARRfu8xV+G lt85ubx5meXgwApW/qB3Y0OMzi/sq2RNH3qxGzCXVpQTxm12hrKtLZsllE90Z7ioeaWO GjeMKqKMIRxrpitkqVF2/Xj2kvpbh15RwPCCSgpoC6EARfVdL/S/xd0Xc+q+yorieT6A i5hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:cc:to:subject:from:references :in-reply-to:date:dkim-signature; bh=P0KXff+2nkaougikNjTmrqGgVX8Lx461JGcWU4aPXzA=; b=p7nNLadagPwRLrr5VeLxfZpJQXEUqbLlEyw0EymWrVaUvBx2HUWsMIjCvLZowSPTco o8XDTf1UJHW2Nft4IR2Pe/fUXTwhrxD5a4fQDqiR9D8lCBRUlUY/ZhuOS1WnNzHHCEUr QCBBDZHTojuRPohZpL5lpZRkMkPo0aERCltZgZLraG/RM7out3yiYWrBPz/XPx39Ebel F7VVm91bsOQeG9Cd+zH5cfJn78P1nQNpN+hRJavOnSejomSVGDTwI2kTFwWANcUdyhfe zlOYOQ5IGdmXnKhMhulGVbWSsOuPEk3z+07OlWnKNEf9p2De3P+rAol1F8cyppW11ryi DrdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=GC77akFH; 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 w1si3020143pjr.61.2021.04.13.06.46.52; Tue, 13 Apr 2021 06:47:04 -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=GC77akFH; 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 S240288AbhDMHgi (ORCPT + 99 others); Tue, 13 Apr 2021 03:36:38 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:36470 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239448AbhDMHgh (ORCPT ); Tue, 13 Apr 2021 03:36:37 -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 969204019F; Tue, 13 Apr 2021 07:36:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1618299378; bh=hST1iATIE6CPXmJo944SfVT7CgV9Q11nuNGznF/0Gs8=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=GC77akFH6cTf0MjnKw8XtWJfxb68sEVZwW5wtIEwm+o0bSJm2MkCgV6O5HRovjre9 U8xa4DB32veNltmjpw+Gbmp9o4uAY9BnU9eT7JuUkbvoNfK+98UA75TQVn1T1uVuD6 bxkxB05QJopdbtznOol5is6wU9ildz9EzPvWwNoocX6w4Czal29jT5DNWTfRUbf4KJ Ynb9jSOpVTsceB7RDqOlPXNChxltWBCNoS73EwZRYkjLgZyaXw9IgofNzBhm9y5XDB hAlJ1y+ipjcyHKGtjXqwMtKTcFelt5Ksxejge9LSDBdziQ4EGej7pACvMyJ3KPhxwG gFSWekT4LFxKw== 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 B3E84A022E; Tue, 13 Apr 2021 07:36:15 +0000 (UTC) Received: by razpc-HP (sSMTP sendmail emulation); Tue, 13 Apr 2021 11:36:14 +0400 Date: Tue, 13 Apr 2021 11:36:14 +0400 In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Artur Petrosyan Subject: [PATCH v2 02/12] usb: dwc2: Add host clock gating support functions To: Felipe Balbi , Greg Kroah-Hartman , Minas Harutyunyan , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: John Youn , Artur Petrosyan , Minas Harutyunyan Message-Id: <20210413073615.B3E84A022E@mailhost.synopsys.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Added host clock gating support functions according programming guide. Added function names: dwc2_host_enter_clock_gating() dwc2_host_exit_clock_gating() Signed-off-by: Artur Petrosyan Acked-by: Minas Harutyunyan --- drivers/usb/dwc2/core.h | 5 +++ drivers/usb/dwc2/hcd.c | 86 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index e5597796dca4..8c12b3061f7f 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -1486,6 +1486,8 @@ int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, int dwc2_host_enter_partial_power_down(struct dwc2_hsotg *hsotg); int dwc2_host_exit_partial_power_down(struct dwc2_hsotg *hsotg, int rem_wakeup, bool restore); +void dwc2_host_enter_clock_gating(struct dwc2_hsotg *hsotg); +void dwc2_host_exit_clock_gating(struct dwc2_hsotg *hsotg, int rem_wakeup); bool dwc2_host_can_poweroff_phy(struct dwc2_hsotg *dwc2); static inline void dwc2_host_schedule_phy_reset(struct dwc2_hsotg *hsotg) { schedule_work(&hsotg->phy_reset_work); } @@ -1521,6 +1523,9 @@ static inline int dwc2_host_enter_partial_power_down(struct dwc2_hsotg *hsotg) static inline int dwc2_host_exit_partial_power_down(struct dwc2_hsotg *hsotg, int rem_wakeup, bool restore) { return 0; } +static inline void dwc2_host_enter_clock_gating(struct dwc2_hsotg *hsotg) {} +static inline void dwc2_host_exit_clock_gating(struct dwc2_hsotg *hsotg, + int rem_wakeup) {} static inline bool dwc2_host_can_poweroff_phy(struct dwc2_hsotg *dwc2) { return false; } static inline void dwc2_host_schedule_phy_reset(struct dwc2_hsotg *hsotg) {} diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index f096006df96f..f1c24c15d185 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -5821,3 +5821,89 @@ int dwc2_host_exit_partial_power_down(struct dwc2_hsotg *hsotg, dev_dbg(hsotg->dev, "Exiting host partial power down completed.\n"); return ret; } + +/** + * dwc2_host_enter_clock_gating() - Put controller in clock gating. + * + * @hsotg: Programming view of the DWC_otg controller + * + * This function is for entering Host mode clock gating. + */ +void dwc2_host_enter_clock_gating(struct dwc2_hsotg *hsotg) +{ + u32 hprt0; + u32 pcgctl; + + dev_dbg(hsotg->dev, "Entering host clock gating.\n"); + + /* Put this port in suspend mode. */ + hprt0 = dwc2_read_hprt0(hsotg); + hprt0 |= HPRT0_SUSP; + dwc2_writel(hsotg, hprt0, HPRT0); + + /* Set the Phy Clock bit as suspend is received. */ + pcgctl = dwc2_readl(hsotg, PCGCTL); + pcgctl |= PCGCTL_STOPPCLK; + dwc2_writel(hsotg, pcgctl, PCGCTL); + udelay(5); + + /* Set the Gate hclk as suspend is received. */ + pcgctl = dwc2_readl(hsotg, PCGCTL); + pcgctl |= PCGCTL_GATEHCLK; + dwc2_writel(hsotg, pcgctl, PCGCTL); + udelay(5); + + hsotg->bus_suspended = true; + hsotg->lx_state = DWC2_L2; +} + +/** + * dwc2_host_exit_clock_gating() - Exit controller from clock gating. + * + * @hsotg: Programming view of the DWC_otg controller + * @rem_wakeup: indicates whether resume is initiated by remote wakeup + * + * This function is for exiting Host mode clock gating. + */ +void dwc2_host_exit_clock_gating(struct dwc2_hsotg *hsotg, int rem_wakeup) +{ + u32 hprt0; + u32 pcgctl; + + dev_dbg(hsotg->dev, "Exiting host clock gating.\n"); + + /* Clear the Gate hclk. */ + pcgctl = dwc2_readl(hsotg, PCGCTL); + pcgctl &= ~PCGCTL_GATEHCLK; + dwc2_writel(hsotg, pcgctl, PCGCTL); + udelay(5); + + /* Phy Clock bit. */ + pcgctl = dwc2_readl(hsotg, PCGCTL); + pcgctl &= ~PCGCTL_STOPPCLK; + dwc2_writel(hsotg, pcgctl, PCGCTL); + udelay(5); + + /* Drive resume signaling and exit suspend mode on the port. */ + hprt0 = dwc2_read_hprt0(hsotg); + hprt0 |= HPRT0_RES; + hprt0 &= ~HPRT0_SUSP; + dwc2_writel(hsotg, hprt0, HPRT0); + udelay(5); + + if (!rem_wakeup) { + /* In case of port resume need to wait for 40 ms */ + msleep(USB_RESUME_TIMEOUT); + + /* Stop driveing resume signaling on the port. */ + hprt0 = dwc2_read_hprt0(hsotg); + hprt0 &= ~HPRT0_RES; + dwc2_writel(hsotg, hprt0, HPRT0); + + hsotg->bus_suspended = false; + hsotg->lx_state = DWC2_L0; + } else { + mod_timer(&hsotg->wkp_timer, + jiffies + msecs_to_jiffies(71)); + } +} -- 2.25.1