From: Artur Petrosyan <Arthur.Petrosyan@synopsys.com>
To: Felipe Balbi <balbi@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: John Youn <John.Youn@synopsys.com>,
Artur Petrosyan <Arthur.Petrosyan@synopsys.com>,
Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
Subject: [PATCH v2 01/12] usb: dwc2: Add device clock gating support functions
Date: Tue, 13 Apr 2021 11:36:07 +0400 [thread overview]
Message-ID: <20210413073607.F41E8A0094@mailhost.synopsys.com> (raw)
In-Reply-To: <cover.1618297800.git.Arthur.Petrosyan@synopsys.com>
Added device clock gating support functions according
programming guide.
Moved "bus_suspended" flag to "dwc2_hsotg" struct because
we need to set that flag while entering to clock gating
in case when the driver is built in peripheral mode.
Added function names:
dwc2_gadget_enter_clock_gating()
dwc2_gadget_exit_clock_gating()
Signed-off-by: Artur Petrosyan <Arthur.Petrosyan@synopsys.com>
Acked-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
---
drivers/usb/dwc2/core.h | 10 ++++--
drivers/usb/dwc2/gadget.c | 71 +++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 5a7850482e57..e5597796dca4 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -866,6 +866,7 @@ struct dwc2_hregs_backup {
* @ll_hw_enabled: Status of low-level hardware resources.
* @hibernated: True if core is hibernated
* @in_ppd: True if core is partial power down mode.
+ * @bus_suspended: True if bus is suspended
* @reset_phy_on_wake: Quirk saying that we should assert PHY reset on a
* remote wakeup.
* @phy_off_for_suspend: Status of whether we turned the PHY off at suspend.
@@ -1023,7 +1024,6 @@ struct dwc2_hregs_backup {
* a pointer to an array of register definitions, the
* array size and the base address where the register bank
* is to be found.
- * @bus_suspended: True if bus is suspended
* @last_frame_num: Number of last frame. Range from 0 to 32768
* @frame_num_array: Used only if CONFIG_USB_DWC2_TRACK_MISSED_SOFS is
* defined, for missed SOFs tracking. Array holds that
@@ -1062,6 +1062,7 @@ struct dwc2_hsotg {
unsigned int ll_hw_enabled:1;
unsigned int hibernated:1;
unsigned int in_ppd:1;
+ bool bus_suspended;
unsigned int reset_phy_on_wake:1;
unsigned int need_phy_for_wake:1;
unsigned int phy_off_for_suspend:1;
@@ -1145,7 +1146,6 @@ struct dwc2_hsotg {
unsigned long hs_periodic_bitmap[
DIV_ROUND_UP(DWC2_HS_SCHEDULE_US, BITS_PER_LONG)];
u16 periodic_qh_count;
- bool bus_suspended;
bool new_connection;
u16 last_frame_num;
@@ -1415,6 +1415,9 @@ int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg,
int dwc2_gadget_enter_partial_power_down(struct dwc2_hsotg *hsotg);
int dwc2_gadget_exit_partial_power_down(struct dwc2_hsotg *hsotg,
bool restore);
+void dwc2_gadget_enter_clock_gating(struct dwc2_hsotg *hsotg);
+void dwc2_gadget_exit_clock_gating(struct dwc2_hsotg *hsotg,
+ int rem_wakeup);
int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg);
int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg);
int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg);
@@ -1453,6 +1456,9 @@ static inline int dwc2_gadget_enter_partial_power_down(struct dwc2_hsotg *hsotg)
static inline int dwc2_gadget_exit_partial_power_down(struct dwc2_hsotg *hsotg,
bool restore)
{ return 0; }
+static inline void dwc2_gadget_enter_clock_gating(struct dwc2_hsotg *hsotg) {}
+static inline void dwc2_gadget_exit_clock_gating(struct dwc2_hsotg *hsotg,
+ int rem_wakeup) {}
static inline int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
{ return 0; }
static inline int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index e08baee4987b..2f50f3e62caa 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -5483,3 +5483,74 @@ int dwc2_gadget_exit_partial_power_down(struct dwc2_hsotg *hsotg,
dev_dbg(hsotg->dev, "Exiting device partial Power Down completed.\n");
return ret;
}
+
+/**
+ * dwc2_gadget_enter_clock_gating() - Put controller in clock gating.
+ *
+ * @hsotg: Programming view of the DWC_otg controller
+ *
+ * Return: non-zero if failed to enter device partial power down.
+ *
+ * This function is for entering device mode clock gating.
+ */
+void dwc2_gadget_enter_clock_gating(struct dwc2_hsotg *hsotg)
+{
+ u32 pcgctl;
+
+ dev_dbg(hsotg->dev, "Entering device clock gating.\n");
+
+ /* 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->lx_state = DWC2_L2;
+ hsotg->bus_suspended = true;
+}
+
+/*
+ * dwc2_gadget_exit_clock_gating() - Exit controller from device clock gating.
+ *
+ * @hsotg: Programming view of the DWC_otg controller
+ * @rem_wakeup: indicates whether remote wake up is enabled.
+ *
+ * This function is for exiting from device mode clock gating.
+ */
+void dwc2_gadget_exit_clock_gating(struct dwc2_hsotg *hsotg, int rem_wakeup)
+{
+ u32 pcgctl;
+ u32 dctl;
+
+ dev_dbg(hsotg->dev, "Exiting device 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);
+
+ if (rem_wakeup) {
+ /* Set Remote Wakeup Signaling */
+ dctl = dwc2_readl(hsotg, DCTL);
+ dctl |= DCTL_RMTWKUPSIG;
+ dwc2_writel(hsotg, dctl, DCTL);
+ }
+
+ /* Change to L0 state */
+ call_gadget(hsotg, resume);
+ hsotg->lx_state = DWC2_L0;
+ hsotg->bus_suspended = false;
+}
--
2.25.1
next prev parent reply other threads:[~2021-04-13 7:36 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1618297800.git.Arthur.Petrosyan@synopsys.com>
2021-04-13 7:16 ` [PATCH 01/12] usb: dwc2: Add device clock gating support functions Artur Petrosyan
2021-04-13 7:16 ` [PATCH 02/12] usb: dwc2: Add host " Artur Petrosyan
2021-04-13 7:16 ` [PATCH 03/12] usb: dwc2: Allow entering clock gating from USB_SUSPEND interrupt Artur Petrosyan
2021-04-13 9:25 ` Sergei Shtylyov
2021-04-13 7:16 ` [PATCH 04/12] usb: dwc2: Add exit clock gating from wakeup interrupt Artur Petrosyan
2021-04-13 7:16 ` [PATCH 05/12] usb: dwc2: Add exit clock gating from session request interrupt Artur Petrosyan
2021-04-13 7:16 ` [PATCH 06/12] usb: dwc2: Add exit clock gating when port reset is asserted Artur Petrosyan
2021-04-13 7:17 ` [PATCH 07/12] usb: dwc2: Update enter clock gating when port is suspended Artur Petrosyan
2021-04-13 9:22 ` Sergei Shtylyov
2021-04-13 10:24 ` Greg Kroah-Hartman
2021-04-13 7:17 ` [PATCH 08/12] usb: dwc2: Update exit clock gating when port is resumed Artur Petrosyan
2021-04-13 7:17 ` [PATCH 09/12] usb: dwc2: Allow exit clock gating in urb enqueue Artur Petrosyan
2021-04-13 7:17 ` [PATCH 10/12] usb: dwc2: Add clock gating entering flow by system suspend Artur Petrosyan
2021-04-13 7:17 ` [PATCH 11/12] usb: dwc2: Add clock gating exiting flow by system resume Artur Petrosyan
2021-04-13 7:17 ` [PATCH 12/12] usb: dwc2: Add exit clock gating before removing driver Artur Petrosyan
2021-04-13 7:36 ` Artur Petrosyan [this message]
2021-04-13 7:36 ` [PATCH v2 02/12] usb: dwc2: Add host clock gating support functions Artur Petrosyan
2021-04-13 7:36 ` [PATCH v2 03/12] usb: dwc2: Allow entering clock gating from USB_SUSPEND interrupt Artur Petrosyan
2021-04-13 7:36 ` [PATCH v2 04/12] usb: dwc2: Add exit clock gating from wakeup interrupt Artur Petrosyan
2021-04-13 7:36 ` [PATCH v2 05/12] usb: dwc2: Add exit clock gating from session request interrupt Artur Petrosyan
2021-04-13 7:36 ` [PATCH v2 06/12] usb: dwc2: Add exit clock gating when port reset is asserted Artur Petrosyan
2021-04-13 7:36 ` [PATCH v2 07/12] usb: dwc2: Update enter clock gating when port is suspended Artur Petrosyan
2021-04-13 7:37 ` [PATCH v2 08/12] usb: dwc2: Update exit clock gating when port is resumed Artur Petrosyan
2021-04-13 7:37 ` [PATCH v2 09/12] usb: dwc2: Allow exit clock gating in urb enqueue Artur Petrosyan
2021-04-13 7:37 ` [PATCH v2 10/12] usb: dwc2: Add clock gating entering flow by system suspend Artur Petrosyan
2021-04-13 9:29 ` Sergei Shtylyov
2021-04-13 7:37 ` [PATCH v2 11/12] usb: dwc2: Add clock gating exiting flow by system resume Artur Petrosyan
2021-04-13 9:30 ` Sergei Shtylyov
2021-04-13 7:37 ` [PATCH v2 12/12] usb: dwc2: Add exit clock gating before removing driver Artur Petrosyan
[not found] ` <20210413073600.57846A0094@mailhost.synopsys.com>
2021-04-13 8:03 ` [PATCH v2 00/12] usb: dwc2: Add clock gating support Artur Petrosyan
2021-04-13 10:26 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210413073607.F41E8A0094@mailhost.synopsys.com \
--to=arthur.petrosyan@synopsys.com \
--cc=John.Youn@synopsys.com \
--cc=Minas.Harutyunyan@synopsys.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.