Skip to contentSkip to conversation

usb: dwc2: Add device clock gating support functions

PATCH Superseded Artur Petrosyan 3 participants 31 messages Apr 13, 2021 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/12 usb: dwc2: Add device clock gating support functions

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()

---
 drivers/usb/dwc2/core.h   | 10 ++++--
 drivers/usb/dwc2/gadget.c | 71 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 2 deletions(-)
drivers/usb/dwc2/core.h +8 -2
index 5a7850482e57..e5597796dca4 100644
@@ -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)
drivers/usb/dwc2/gadget.c +71 -0

74 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/12 usb: dwc2: Add host clock gating support functions

In reply to a message not in the archive

Added host clock gating support functions according programming guide.

Added function names:
dwc2_host_enter_clock_gating()
dwc2_host_exit_clock_gating()

---
 drivers/usb/dwc2/core.h |  5 +++
 drivers/usb/dwc2/hcd.c  | 86 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)
drivers/usb/dwc2/core.h +5 -0
index e5597796dca4..8c12b3061f7f 100644
@@ -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) {}
drivers/usb/dwc2/hcd.c +86 -0

89 lines not on this page · raw message

Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/12 usb: dwc2: Allow entering clock gating from USB_SUSPEND interrupt

In reply to a message not in the archive

If core doesn't support hibernation or partial power down power saving options, power can still be saved using clock gating on all the clocks.

- Added entering clock gating state from USB_SUSPEND interrupt.

---
 drivers/usb/dwc2/core_intr.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/usb/dwc2/core_intr.c +7 -3
index 8c0152b514be..ab7fe303c0f9 100644
@@ -529,14 +529,18 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg)
 				/* Ask phy to be suspended */
 				if (!IS_ERR_OR_NULL(hsotg->uphy))
 					usb_phy_set_suspend(hsotg->uphy, true);
-			}
-
-			if (hsotg->hw_params.hibernation) {
+			} else if (hsotg->hw_params.hibernation) {
 				ret = dwc2_enter_hibernation(hsotg, 0);
 				if (ret && ret != -ENOTSUPP)
 					dev_err(hsotg->dev,
 						"%s: enter hibernation failed\n",
 						__func__);
+			} else {
+				/*
+				 * If not hibernation nor partial power down are supported,
+				 * clock gating is used to save power.
+				 */
+				dwc2_gadget_enter_clock_gating(hsotg);
 			}
 skip_power_saving:
 			/*
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH 03/12] usb: dwc2: Allow entering clock gating from USB_SUSPEND interrupt

Quoted 23 lines · Artur Petrosyan

If core doesn't support hibernation or partial power down power saving options, power can still be saved using clock gating on all the clocks.

- Added entering clock gating state from USB_SUSPEND interrupt.

---
  drivers/usb/dwc2/core_intr.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/usb/dwc2/core_intr.c +0 -2
index 8c0152b514be..ab7fe303c0f9 100644
@@ -529,14 +529,18 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg)
  				/* Ask phy to be suspended */
  				if (!IS_ERR_OR_NULL(hsotg->uphy))
  					usb_phy_set_suspend(hsotg->uphy, true);
-			}
-

drivers/usb/dwc2/core_intr.c static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg) · line 540

Quoted 10 lines
drivers/usb/dwc2/core_intr.c +4 -1
-			if (hsotg->hw_params.hibernation) {
+			} else if (hsotg->hw_params.hibernation) {
  				ret = dwc2_enter_hibernation(hsotg, 0);
  				if (ret && ret != -ENOTSUPP)
  					dev_err(hsotg->dev,
  						"%s: enter hibernation failed\n",
  						__func__);
+			} else {
+				/*
+				 * If not hibernation nor partial power down are supported,

s/not/neither/?

[...]

MBR, Sergei

#5 lore raw

PATCH 4/12 usb: dwc2: Add exit clock gating from wakeup interrupt

In reply to a message not in the archive

Added exit from clock gating mode when wakeup interrupt is detected. To exit from the clock gating
in device mode "dwc2_gadget_exit_clock_gating()" function is used with rem_wakeup parameter 0. To exit clock gating in host mode "dwc2_host_exit_clock_gating()" with rem_wakeup parameter 1.

---
 drivers/usb/dwc2/core_intr.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)
drivers/usb/dwc2/core_intr.c +22 -11
index ab7fe303c0f9..c764407e7633 100644
@@ -415,17 +415,24 @@ static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg)
 	if (dwc2_is_device_mode(hsotg)) {
 		dev_dbg(hsotg->dev, "DSTS=0x%0x\n",
 			dwc2_readl(hsotg, DSTS));
-		if (hsotg->lx_state == DWC2_L2 && hsotg->in_ppd) {
-			u32 dctl = dwc2_readl(hsotg, DCTL);
-			/* Clear Remote Wakeup Signaling */
-			dctl &= ~DCTL_RMTWKUPSIG;
-			dwc2_writel(hsotg, dctl, DCTL);
-			ret = dwc2_exit_partial_power_down(hsotg, 1,
-							   true);
-			if (ret)
-				dev_err(hsotg->dev,
-					"exit partial_power_down failed\n");
-			call_gadget(hsotg, resume);
+		if (hsotg->lx_state == DWC2_L2) {
+			if (hsotg->in_ppd) {
+				u32 dctl = dwc2_readl(hsotg, DCTL);
+				/* Clear Remote Wakeup Signaling */
+				dctl &= ~DCTL_RMTWKUPSIG;
+				dwc2_writel(hsotg, dctl, DCTL);
+				ret = dwc2_exit_partial_power_down(hsotg, 1,
+								   true);
+				if (ret)
+					dev_err(hsotg->dev,
+						"exit partial_power_down failed\n");
+				call_gadget(hsotg, resume);
+			}
+
+			/* Exit gadget mode clock gating. */
+			if (hsotg->params.power_down ==
+			    DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended)
+				dwc2_gadget_exit_clock_gating(hsotg, 0);
 		} else {
 			/* Change to L0 state */
 			hsotg->lx_state = DWC2_L0;
@@ -440,6 +447,10 @@ static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg)
 						"exit partial_power_down failed\n");
 			}
 
+			if (hsotg->params.power_down ==
+			    DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended)
+				dwc2_host_exit_clock_gating(hsotg, 1);
+
 			/*
 			 * If we've got this quirk then the PHY is stuck upon
 			 * wakeup.  Assert reset.  This will propagate out and
Signature · 1 line
2.25.1
#6 lore raw

PATCH 5/12 usb: dwc2: Add exit clock gating from session request interrupt

In reply to a message not in the archive

Added clock gating exit flow from session request interrupt handler according programming guide.

---
 drivers/usb/dwc2/core_intr.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/usb/dwc2/core_intr.c +13 -6
index c764407e7633..550c52c1a0c7 100644
@@ -316,12 +316,19 @@ static void dwc2_handle_session_req_intr(struct dwc2_hsotg *hsotg)
 		hsotg->lx_state);
 
 	if (dwc2_is_device_mode(hsotg)) {
-		if (hsotg->lx_state == DWC2_L2 && hsotg->in_ppd) {
-			ret = dwc2_exit_partial_power_down(hsotg, 0,
-							   true);
-			if (ret)
-				dev_err(hsotg->dev,
-					"exit power_down failed\n");
+		if (hsotg->lx_state == DWC2_L2) {
+			if (hsotg->in_ppd) {
+				ret = dwc2_exit_partial_power_down(hsotg, 0,
+								   true);
+				if (ret)
+					dev_err(hsotg->dev,
+						"exit power_down failed\n");
+			}
+
+			/* Exit gadget mode clock gating. */
+			if (hsotg->params.power_down ==
+			    DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended)
+				dwc2_gadget_exit_clock_gating(hsotg, 0);
 		}
 
 		/*
Signature · 1 line
2.25.1
#7 lore raw

PATCH 6/12 usb: dwc2: Add exit clock gating when port reset is asserted

In reply to a message not in the archive

Adds clock gating exit flow when set port feature
reset is received in suspended state.

---
 drivers/usb/dwc2/hcd.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/dwc2/hcd.c +4 -0
index f1c24c15d185..27f030d5de54 100644
@@ -3712,6 +3712,10 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq,
 						"exit partial_power_down failed\n");
 			}
 
+			if (hsotg->params.power_down ==
+			    DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended)
+				dwc2_host_exit_clock_gating(hsotg, 0);
+
 			hprt0 = dwc2_read_hprt0(hsotg);
 			dev_dbg(hsotg->dev,
 				"SetPortFeature - USB_PORT_FEAT_RESET\n");
Signature · 1 line
2.25.1
#8 lore raw

PATCH 7/12 usb: dwc2: Update enter clock gating when port is suspended

In reply to a message not in the archive

Updates the implementation of entering clock gating mode when core receives port suspend.
Instead of setting the required bit fields of the registers inline, called the "dwc2_host_enter_clock_gating()" function.

---
 drivers/usb/dwc2/hcd.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)
drivers/usb/dwc2/hcd.c +4 -15
index 27f030d5de54..e1225fe6c61a 100644
@@ -3298,7 +3298,6 @@ static int dwc2_host_is_b_hnp_enabled(struct dwc2_hsotg *hsotg)
 int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
 {
 	unsigned long flags;
-	u32 hprt0;
 	u32 pcgctl;
 	u32 gotgctl;
 	int ret = 0;
@@ -3323,22 +3322,12 @@ int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
 		break;
 	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
 	case DWC2_POWER_DOWN_PARAM_NONE:
-	default:
-		hprt0 = dwc2_read_hprt0(hsotg);
-		hprt0 |= HPRT0_SUSP;
-		dwc2_writel(hsotg, hprt0, HPRT0);
-		hsotg->bus_suspended = true;
 		/*
-		 * If power_down is supported, Phy clock will be suspended
-		 * after registers are backuped.
+		 * If not hibernation nor partial power down are supported,
+		 * clock gating is used to save power.
 		 */
-		if (!hsotg->params.power_down) {
-			/* Suspend the Phy Clock */
-			pcgctl = dwc2_readl(hsotg, PCGCTL);
-			pcgctl |= PCGCTL_STOPPCLK;
-			dwc2_writel(hsotg, pcgctl, PCGCTL);
-			udelay(10);
-		}
+		dwc2_host_enter_clock_gating(hsotg);
+		break;
 	}
 
 	/* For HNP the bus must be suspended for at least 200ms */
Signature · 1 line
2.25.1
#9 lore raw

Re: [PATCH 07/12] usb: dwc2: Update enter clock gating when port is suspended

Hello!

Quoted 14 lines · Artur Petrosyan

Updates the implementation of entering clock gating mode when core receives port suspend.
Instead of setting the required bit fields of the registers inline, called the "dwc2_host_enter_clock_gating()" function.

---
  drivers/usb/dwc2/hcd.c | 19 ++++---------------
  1 file changed, 4 insertions(+), 15 deletions(-)
drivers/usb/dwc2/hcd.c +0 -0
index 27f030d5de54..e1225fe6c61a 100644

[...]

drivers/usb/dwc2/hcd.c int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex) · line 3326

Quoted 13 lines
drivers/usb/dwc2/hcd.c +1 -7
@@ -3323,22 +3322,12 @@ int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
  		break;
  	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
  	case DWC2_POWER_DOWN_PARAM_NONE:
-	default:
-		hprt0 = dwc2_read_hprt0(hsotg);
-		hprt0 |= HPRT0_SUSP;
-		dwc2_writel(hsotg, hprt0, HPRT0);
-		hsotg->bus_suspended = true;
  		/*
-		 * If power_down is supported, Phy clock will be suspended
-		 * after registers are backuped.
+		 * If not hibernation nor partial power down are supported,

s/not/neither/?

MBR, Sergei

#10 lore raw

Re: [PATCH 07/12] usb: dwc2: Update enter clock gating when port is suspended

Quoted 19 lines · Sergei Shtylyov

Hello!

Quoted 14 lines · Artur Petrosyan

Updates the implementation of entering clock gating mode when core receives port suspend.
Instead of setting the required bit fields of the registers inline, called the "dwc2_host_enter_clock_gating()" function.

---
  drivers/usb/dwc2/hcd.c | 19 ++++---------------
  1 file changed, 4 insertions(+), 15 deletions(-)
drivers/usb/dwc2/hcd.c +0 -0
index 27f030d5de54..e1225fe6c61a 100644

[...]

Quoted 15 lines

drivers/usb/dwc2/hcd.c int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex) · line 3326

Quoted 13 lines
drivers/usb/dwc2/hcd.c +1 -7
@@ -3323,22 +3322,12 @@ int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
  		break;
  	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
  	case DWC2_POWER_DOWN_PARAM_NONE:
-	default:
-		hprt0 = dwc2_read_hprt0(hsotg);
-		hprt0 |= HPRT0_SUSP;
-		dwc2_writel(hsotg, hprt0, HPRT0);
-		hsotg->bus_suspended = true;
  		/*
-		 * If power_down is supported, Phy clock will be suspended
-		 * after registers are backuped.
+		 * If not hibernation nor partial power down are supported,
   s/not/neither/?

It's fine, not a big deal at all.

greg k-h

#11 lore raw

PATCH 8/12 usb: dwc2: Update exit clock gating when port is resumed

In reply to a message not in the archive

Updates the implementation of exiting clock gating mode when core receives port resume.
Instead of setting the required bit fields of the registers inline, called the "dwc2_host_exit_clock_gating()" function.

---
 drivers/usb/dwc2/hcd.c | 29 ++++-------------------------
 1 file changed, 4 insertions(+), 25 deletions(-)
drivers/usb/dwc2/hcd.c +4 -25
index e1225fe6c61a..8a42675ab94e 100644
@@ -3359,8 +3359,6 @@ int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
 int dwc2_port_resume(struct dwc2_hsotg *hsotg)
 {
 	unsigned long flags;
-	u32 hprt0;
-	u32 pcgctl;
 	int ret = 0;
 
 	spin_lock_irqsave(&hsotg->lock, flags);
@@ -3374,33 +3372,14 @@ int dwc2_port_resume(struct dwc2_hsotg *hsotg)
 		break;
 	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
 	case DWC2_POWER_DOWN_PARAM_NONE:
-	default:
 		/*
-		 * If power_down is supported, Phy clock is already resumed
-		 * after registers restore.
+		 * If not hibernation nor partial power down are supported,
+		 * port resume is done using the clock gating programming flow.
 		 */
-		if (!hsotg->params.power_down) {
-			pcgctl = dwc2_readl(hsotg, PCGCTL);
-			pcgctl &= ~PCGCTL_STOPPCLK;
-			dwc2_writel(hsotg, pcgctl, PCGCTL);
-			spin_unlock_irqrestore(&hsotg->lock, flags);
-			msleep(20);
-			spin_lock_irqsave(&hsotg->lock, flags);
-		}
-
-		hprt0 = dwc2_read_hprt0(hsotg);
-		hprt0 |= HPRT0_RES;
-		hprt0 &= ~HPRT0_SUSP;
-		dwc2_writel(hsotg, hprt0, HPRT0);
 		spin_unlock_irqrestore(&hsotg->lock, flags);
-
-		msleep(USB_RESUME_TIMEOUT);
-
+		dwc2_host_exit_clock_gating(hsotg, 0);
 		spin_lock_irqsave(&hsotg->lock, flags);
-		hprt0 = dwc2_read_hprt0(hsotg);
-		hprt0 &= ~(HPRT0_RES | HPRT0_SUSP);
-		dwc2_writel(hsotg, hprt0, HPRT0);
-		hsotg->bus_suspended = false;
+		break;
 	}
 
 	spin_unlock_irqrestore(&hsotg->lock, flags);
Signature · 1 line
2.25.1
#12 lore raw

PATCH 9/12 usb: dwc2: Allow exit clock gating in urb enqueue

In reply to a message not in the archive

When core is in clock gating state and an external hub is connected, upper layer sends URB enqueue request, which results in port reset issue.

Added exit from clock gating state to avoid port reset issue and process upper layer request properly.

---
 drivers/usb/dwc2/hcd.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/usb/dwc2/hcd.c +8 -0
index 8a42675ab94e..31d6a1b87228 100644
@@ -4597,6 +4597,14 @@ static int _dwc2_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
 				"exit partial_power_down failed\n");
 	}
 
+	if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE &&
+	    hsotg->bus_suspended) {
+		if (dwc2_is_device_mode(hsotg))
+			dwc2_gadget_exit_clock_gating(hsotg, 0);
+		else
+			dwc2_host_exit_clock_gating(hsotg, 0);
+	}
+
 	if (!ep)
 		return -EINVAL;
 
Signature · 1 line
2.25.1
#13 lore raw

PATCH 10/12 usb: dwc2: Add clock gating entering flow by system suspend

In reply to a message not in the archive

If not hibernation nor partial power down are supported, clock gating is used to save power.

Adds a new flow of entering clock gating when PC is suspended.

---
 drivers/usb/dwc2/hcd.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/usb/dwc2/hcd.c +9 -0
index 31d6a1b87228..09dcd37b9ef8 100644
@@ -4372,6 +4372,15 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
 		break;
 	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
 	case DWC2_POWER_DOWN_PARAM_NONE:
+		/*
+		 * If not hibernation nor partial power down are supported,
+		 * clock gating is used to save power.
+		 */
+		dwc2_host_enter_clock_gating(hsotg);
+
+		/* After entering suspend, hardware is not accessible */
+		clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
+		break;
 	default:
 		goto skip_power_saving;
 	}
Signature · 1 line
2.25.1
#14 lore raw

PATCH 11/12 usb: dwc2: Add clock gating exiting flow by system resume

In reply to a message not in the archive

If not hibernation nor partial power down are supported, port resume is done using the clock gating programming flow.

Adds a new flow of exiting clock gating when PC is resumed.

---
 drivers/usb/dwc2/hcd.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/usb/dwc2/hcd.c +22 -0
index 09dcd37b9ef8..04a1b53d65af 100644
@@ -4445,6 +4445,28 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
 		break;
 	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
 	case DWC2_POWER_DOWN_PARAM_NONE:
+		/*
+		 * If not hibernation nor partial power down are supported,
+		 * port resume is done using the clock gating programming flow.
+		 */
+		spin_unlock_irqrestore(&hsotg->lock, flags);
+		dwc2_host_exit_clock_gating(hsotg, 0);
+
+		/*
+		 * Initialize the Core for Host mode, as after system resume
+		 * the global interrupts are disabled.
+		 */
+		dwc2_core_init(hsotg, false);
+		dwc2_enable_global_interrupts(hsotg);
+		dwc2_hcd_reinit(hsotg);
+		spin_lock_irqsave(&hsotg->lock, flags);
+
+		/*
+		 * Set HW accessible bit before powering on the controller
+		 * since an interrupt may rise.
+		 */
+		set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
+		break;
 	default:
 		hsotg->lx_state = DWC2_L0;
 		goto unlock;
Signature · 1 line
2.25.1
#15 lore raw

PATCH 12/12 usb: dwc2: Add exit clock gating before removing driver

In reply to a message not in the archive

When dwc2 core is in clock gating mode loading driver again causes driver fail. Because in that mode registers are not accessible.

Added a flow of exiting clock gating mode
to avoid the driver reload failure.

---
 drivers/usb/dwc2/platform.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/usb/dwc2/platform.c +9 -0
index b28b8cd45799..f8b819cfa80e 100644
@@ -326,6 +326,15 @@ static int dwc2_driver_remove(struct platform_device *dev)
 				"exit partial_power_down failed\n");
 	}
 
+	/* Exit clock gating when driver is removed. */
+	if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE &&
+	    hsotg->bus_suspended) {
+		if (dwc2_is_device_mode(hsotg))
+			dwc2_gadget_exit_clock_gating(hsotg, 0);
+		else
+			dwc2_host_exit_clock_gating(hsotg, 0);
+	}
+
 	dwc2_debugfs_exit(hsotg);
 	if (hsotg->hcd_enabled)
 		dwc2_hcd_remove(hsotg);
Signature · 1 line
2.25.1
#16 lore raw

PATCH v2 1/12 usb: dwc2: Add device clock gating support functions

In reply to a message not in the archive

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()

---
 drivers/usb/dwc2/core.h   | 10 ++++--
 drivers/usb/dwc2/gadget.c | 71 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 2 deletions(-)
drivers/usb/dwc2/core.h +8 -2
index 5a7850482e57..e5597796dca4 100644
@@ -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)
drivers/usb/dwc2/gadget.c +71 -0

74 lines not on this page · raw message

Signature · 1 line
2.25.1
#17 lore raw

PATCH v2 2/12 usb: dwc2: Add host clock gating support functions

In reply to a message not in the archive

Added host clock gating support functions according programming guide.

Added function names:
dwc2_host_enter_clock_gating()
dwc2_host_exit_clock_gating()

---
 drivers/usb/dwc2/core.h |  5 +++
 drivers/usb/dwc2/hcd.c  | 86 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)
drivers/usb/dwc2/core.h +5 -0
index e5597796dca4..8c12b3061f7f 100644
@@ -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) {}
drivers/usb/dwc2/hcd.c +86 -0

89 lines not on this page · raw message

Signature · 1 line
2.25.1
#18 lore raw

PATCH v2 3/12 usb: dwc2: Allow entering clock gating from USB_SUSPEND interrupt

In reply to a message not in the archive

If core doesn't support hibernation or partial power down power saving options, power can still be saved using clock gating on all the clocks.

- Added entering clock gating state from USB_SUSPEND interrupt.

---
 drivers/usb/dwc2/core_intr.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/usb/dwc2/core_intr.c +7 -3
index 8c0152b514be..ab7fe303c0f9 100644
@@ -529,14 +529,18 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg)
 				/* Ask phy to be suspended */
 				if (!IS_ERR_OR_NULL(hsotg->uphy))
 					usb_phy_set_suspend(hsotg->uphy, true);
-			}
-
-			if (hsotg->hw_params.hibernation) {
+			} else if (hsotg->hw_params.hibernation) {
 				ret = dwc2_enter_hibernation(hsotg, 0);
 				if (ret && ret != -ENOTSUPP)
 					dev_err(hsotg->dev,
 						"%s: enter hibernation failed\n",
 						__func__);
+			} else {
+				/*
+				 * If not hibernation nor partial power down are supported,
+				 * clock gating is used to save power.
+				 */
+				dwc2_gadget_enter_clock_gating(hsotg);
 			}
 skip_power_saving:
 			/*
Signature · 1 line
2.25.1
#19 lore raw

PATCH v2 4/12 usb: dwc2: Add exit clock gating from wakeup interrupt

In reply to a message not in the archive

Added exit from clock gating mode when wakeup interrupt is detected. To exit from the clock gating
in device mode "dwc2_gadget_exit_clock_gating()" function is used with rem_wakeup parameter 0. To exit clock gating in host mode "dwc2_host_exit_clock_gating()" with rem_wakeup parameter 1.

---
 drivers/usb/dwc2/core_intr.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)
drivers/usb/dwc2/core_intr.c +22 -11
index ab7fe303c0f9..c764407e7633 100644
@@ -415,17 +415,24 @@ static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg)
 	if (dwc2_is_device_mode(hsotg)) {
 		dev_dbg(hsotg->dev, "DSTS=0x%0x\n",
 			dwc2_readl(hsotg, DSTS));
-		if (hsotg->lx_state == DWC2_L2 && hsotg->in_ppd) {
-			u32 dctl = dwc2_readl(hsotg, DCTL);
-			/* Clear Remote Wakeup Signaling */
-			dctl &= ~DCTL_RMTWKUPSIG;
-			dwc2_writel(hsotg, dctl, DCTL);
-			ret = dwc2_exit_partial_power_down(hsotg, 1,
-							   true);
-			if (ret)
-				dev_err(hsotg->dev,
-					"exit partial_power_down failed\n");
-			call_gadget(hsotg, resume);
+		if (hsotg->lx_state == DWC2_L2) {
+			if (hsotg->in_ppd) {
+				u32 dctl = dwc2_readl(hsotg, DCTL);
+				/* Clear Remote Wakeup Signaling */
+				dctl &= ~DCTL_RMTWKUPSIG;
+				dwc2_writel(hsotg, dctl, DCTL);
+				ret = dwc2_exit_partial_power_down(hsotg, 1,
+								   true);
+				if (ret)
+					dev_err(hsotg->dev,
+						"exit partial_power_down failed\n");
+				call_gadget(hsotg, resume);
+			}
+
+			/* Exit gadget mode clock gating. */
+			if (hsotg->params.power_down ==
+			    DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended)
+				dwc2_gadget_exit_clock_gating(hsotg, 0);
 		} else {
 			/* Change to L0 state */
 			hsotg->lx_state = DWC2_L0;
@@ -440,6 +447,10 @@ static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg)
 						"exit partial_power_down failed\n");
 			}
 
+			if (hsotg->params.power_down ==
+			    DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended)
+				dwc2_host_exit_clock_gating(hsotg, 1);
+
 			/*
 			 * If we've got this quirk then the PHY is stuck upon
 			 * wakeup.  Assert reset.  This will propagate out and
Signature · 1 line
2.25.1
#20 lore raw

PATCH v2 5/12 usb: dwc2: Add exit clock gating from session request interrupt

In reply to a message not in the archive

Added clock gating exit flow from session request interrupt handler according programming guide.

---
Changes in v2:
- None

 drivers/usb/dwc2/core_intr.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/usb/dwc2/core_intr.c +13 -6
index c764407e7633..550c52c1a0c7 100644
@@ -316,12 +316,19 @@ static void dwc2_handle_session_req_intr(struct dwc2_hsotg *hsotg)
 		hsotg->lx_state);
 
 	if (dwc2_is_device_mode(hsotg)) {
-		if (hsotg->lx_state == DWC2_L2 && hsotg->in_ppd) {
-			ret = dwc2_exit_partial_power_down(hsotg, 0,
-							   true);
-			if (ret)
-				dev_err(hsotg->dev,
-					"exit power_down failed\n");
+		if (hsotg->lx_state == DWC2_L2) {
+			if (hsotg->in_ppd) {
+				ret = dwc2_exit_partial_power_down(hsotg, 0,
+								   true);
+				if (ret)
+					dev_err(hsotg->dev,
+						"exit power_down failed\n");
+			}
+
+			/* Exit gadget mode clock gating. */
+			if (hsotg->params.power_down ==
+			    DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended)
+				dwc2_gadget_exit_clock_gating(hsotg, 0);
 		}
 
 		/*
Signature · 1 line
2.25.1
#21 lore raw

PATCH v2 6/12 usb: dwc2: Add exit clock gating when port reset is asserted

In reply to a message not in the archive

Adds clock gating exit flow when set port feature
reset is received in suspended state.

---
Changes in v2:
- None

 drivers/usb/dwc2/hcd.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/dwc2/hcd.c +4 -0
index f1c24c15d185..27f030d5de54 100644
@@ -3712,6 +3712,10 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq,
 						"exit partial_power_down failed\n");
 			}
 
+			if (hsotg->params.power_down ==
+			    DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended)
+				dwc2_host_exit_clock_gating(hsotg, 0);
+
 			hprt0 = dwc2_read_hprt0(hsotg);
 			dev_dbg(hsotg->dev,
 				"SetPortFeature - USB_PORT_FEAT_RESET\n");
Signature · 1 line
2.25.1
#22 lore raw

PATCH v2 7/12 usb: dwc2: Update enter clock gating when port is suspended

In reply to a message not in the archive

Updates the implementation of entering clock gating mode when core receives port suspend.
Instead of setting the required bit fields of the registers inline, called the "dwc2_host_enter_clock_gating()" function.

---
Changes in v2:
- None

 drivers/usb/dwc2/hcd.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)
drivers/usb/dwc2/hcd.c +4 -15
index 27f030d5de54..e1225fe6c61a 100644
@@ -3298,7 +3298,6 @@ static int dwc2_host_is_b_hnp_enabled(struct dwc2_hsotg *hsotg)
 int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
 {
 	unsigned long flags;
-	u32 hprt0;
 	u32 pcgctl;
 	u32 gotgctl;
 	int ret = 0;
@@ -3323,22 +3322,12 @@ int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
 		break;
 	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
 	case DWC2_POWER_DOWN_PARAM_NONE:
-	default:
-		hprt0 = dwc2_read_hprt0(hsotg);
-		hprt0 |= HPRT0_SUSP;
-		dwc2_writel(hsotg, hprt0, HPRT0);
-		hsotg->bus_suspended = true;
 		/*
-		 * If power_down is supported, Phy clock will be suspended
-		 * after registers are backuped.
+		 * If not hibernation nor partial power down are supported,
+		 * clock gating is used to save power.
 		 */
-		if (!hsotg->params.power_down) {
-			/* Suspend the Phy Clock */
-			pcgctl = dwc2_readl(hsotg, PCGCTL);
-			pcgctl |= PCGCTL_STOPPCLK;
-			dwc2_writel(hsotg, pcgctl, PCGCTL);
-			udelay(10);
-		}
+		dwc2_host_enter_clock_gating(hsotg);
+		break;
 	}
 
 	/* For HNP the bus must be suspended for at least 200ms */
Signature · 1 line
2.25.1
#23 lore raw

PATCH v2 8/12 usb: dwc2: Update exit clock gating when port is resumed

In reply to a message not in the archive

Updates the implementation of exiting clock gating mode when core receives port resume.
Instead of setting the required bit fields of the registers inline, called the "dwc2_host_exit_clock_gating()" function.

---
Changes in v2:
- None

 drivers/usb/dwc2/hcd.c | 29 ++++-------------------------
 1 file changed, 4 insertions(+), 25 deletions(-)
drivers/usb/dwc2/hcd.c +4 -25
index e1225fe6c61a..8a42675ab94e 100644
@@ -3359,8 +3359,6 @@ int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
 int dwc2_port_resume(struct dwc2_hsotg *hsotg)
 {
 	unsigned long flags;
-	u32 hprt0;
-	u32 pcgctl;
 	int ret = 0;
 
 	spin_lock_irqsave(&hsotg->lock, flags);
@@ -3374,33 +3372,14 @@ int dwc2_port_resume(struct dwc2_hsotg *hsotg)
 		break;
 	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
 	case DWC2_POWER_DOWN_PARAM_NONE:
-	default:
 		/*
-		 * If power_down is supported, Phy clock is already resumed
-		 * after registers restore.
+		 * If not hibernation nor partial power down are supported,
+		 * port resume is done using the clock gating programming flow.
 		 */
-		if (!hsotg->params.power_down) {
-			pcgctl = dwc2_readl(hsotg, PCGCTL);
-			pcgctl &= ~PCGCTL_STOPPCLK;
-			dwc2_writel(hsotg, pcgctl, PCGCTL);
-			spin_unlock_irqrestore(&hsotg->lock, flags);
-			msleep(20);
-			spin_lock_irqsave(&hsotg->lock, flags);
-		}
-
-		hprt0 = dwc2_read_hprt0(hsotg);
-		hprt0 |= HPRT0_RES;
-		hprt0 &= ~HPRT0_SUSP;
-		dwc2_writel(hsotg, hprt0, HPRT0);
 		spin_unlock_irqrestore(&hsotg->lock, flags);
-
-		msleep(USB_RESUME_TIMEOUT);
-
+		dwc2_host_exit_clock_gating(hsotg, 0);
 		spin_lock_irqsave(&hsotg->lock, flags);
-		hprt0 = dwc2_read_hprt0(hsotg);
-		hprt0 &= ~(HPRT0_RES | HPRT0_SUSP);
-		dwc2_writel(hsotg, hprt0, HPRT0);
-		hsotg->bus_suspended = false;
+		break;
 	}
 
 	spin_unlock_irqrestore(&hsotg->lock, flags);
Signature · 1 line
2.25.1
#24 lore raw

PATCH v2 9/12 usb: dwc2: Allow exit clock gating in urb enqueue

In reply to a message not in the archive

When core is in clock gating state and an external hub is connected, upper layer sends URB enqueue request, which results in port reset issue.

Added exit from clock gating state to avoid port reset issue and process upper layer request properly.

---
Changes in v2:
- None

 drivers/usb/dwc2/hcd.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/usb/dwc2/hcd.c +8 -0
index 8a42675ab94e..31d6a1b87228 100644
@@ -4597,6 +4597,14 @@ static int _dwc2_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
 				"exit partial_power_down failed\n");
 	}
 
+	if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE &&
+	    hsotg->bus_suspended) {
+		if (dwc2_is_device_mode(hsotg))
+			dwc2_gadget_exit_clock_gating(hsotg, 0);
+		else
+			dwc2_host_exit_clock_gating(hsotg, 0);
+	}
+
 	if (!ep)
 		return -EINVAL;
 
Signature · 1 line
2.25.1
#25 lore raw

PATCH v2 10/12 usb: dwc2: Add clock gating entering flow by system suspend

In reply to a message not in the archive

If not hibernation nor partial power down are supported, clock gating is used to save power.

Adds a new flow of entering clock gating when PC is suspended.

---
Changes in v2:
- None

 drivers/usb/dwc2/hcd.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/usb/dwc2/hcd.c +9 -0
index 31d6a1b87228..09dcd37b9ef8 100644
@@ -4372,6 +4372,15 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
 		break;
 	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
 	case DWC2_POWER_DOWN_PARAM_NONE:
+		/*
+		 * If not hibernation nor partial power down are supported,
+		 * clock gating is used to save power.
+		 */
+		dwc2_host_enter_clock_gating(hsotg);
+
+		/* After entering suspend, hardware is not accessible */
+		clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
+		break;
 	default:
 		goto skip_power_saving;
 	}
Signature · 1 line
2.25.1
#26 lore raw

Re: [PATCH v2 10/12] usb: dwc2: Add clock gating entering flow by system suspend

Quoted 1 line · Artur Petrosyan

If not hibernation nor partial power down are supported,

s/not/neither/?

Quoted 18 lines

clock gating is used to save power.

Adds a new flow of entering clock gating when PC is suspended.

---
Changes in v2:
- None

  drivers/usb/dwc2/hcd.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/usb/dwc2/hcd.c +0 -0
index 31d6a1b87228..09dcd37b9ef8 100644

drivers/usb/dwc2/hcd.c static int _dwc2_hcd_suspend(struct usb_hcd *hcd) · line 4376

Quoted 5 lines
drivers/usb/dwc2/hcd.c +2 -0
@@ -4372,6 +4372,15 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
  		break;
  	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
  	case DWC2_POWER_DOWN_PARAM_NONE:
+		/*
+		 * If not hibernation nor partial power down are supported,

s/not/neither/?

drivers/usb/dwc2/hcd.c static int _dwc2_hcd_suspend(struct usb_hcd *hcd) · line 4386

Quoted 10 lines
drivers/usb/dwc2/hcd.c +7 -0
+		 * clock gating is used to save power.
+		 */
+		dwc2_host_enter_clock_gating(hsotg);
+
+		/* After entering suspend, hardware is not accessible */
+		clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
+		break;
  	default:
  		goto skip_power_saving;
  	}

MBR, Sergei

#27 lore raw

PATCH v2 11/12 usb: dwc2: Add clock gating exiting flow by system resume

In reply to a message not in the archive

If not hibernation nor partial power down are supported, port resume is done using the clock gating programming flow.

Adds a new flow of exiting clock gating when PC is resumed.

---
Changes in v2:
- None

 drivers/usb/dwc2/hcd.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/usb/dwc2/hcd.c +22 -0
index 09dcd37b9ef8..04a1b53d65af 100644
@@ -4445,6 +4445,28 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
 		break;
 	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
 	case DWC2_POWER_DOWN_PARAM_NONE:
+		/*
+		 * If not hibernation nor partial power down are supported,
+		 * port resume is done using the clock gating programming flow.
+		 */
+		spin_unlock_irqrestore(&hsotg->lock, flags);
+		dwc2_host_exit_clock_gating(hsotg, 0);
+
+		/*
+		 * Initialize the Core for Host mode, as after system resume
+		 * the global interrupts are disabled.
+		 */
+		dwc2_core_init(hsotg, false);
+		dwc2_enable_global_interrupts(hsotg);
+		dwc2_hcd_reinit(hsotg);
+		spin_lock_irqsave(&hsotg->lock, flags);
+
+		/*
+		 * Set HW accessible bit before powering on the controller
+		 * since an interrupt may rise.
+		 */
+		set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
+		break;
 	default:
 		hsotg->lx_state = DWC2_L0;
 		goto unlock;
Signature · 1 line
2.25.1
#28 lore raw

Re: [PATCH v2 11/12] usb: dwc2: Add clock gating exiting flow by system resume

Quoted 1 line · Artur Petrosyan

If not hibernation nor partial power down are supported,

s/not/neither/?

Quoted 18 lines

port resume is done using the clock gating programming flow.

Adds a new flow of exiting clock gating when PC is resumed.

---
Changes in v2:
- None

  drivers/usb/dwc2/hcd.c | 22 ++++++++++++++++++++++
  1 file changed, 22 insertions(+)
drivers/usb/dwc2/hcd.c +0 -0
index 09dcd37b9ef8..04a1b53d65af 100644

drivers/usb/dwc2/hcd.c static int _dwc2_hcd_resume(struct usb_hcd *hcd) · line 4449

Quoted 5 lines
drivers/usb/dwc2/hcd.c +2 -0
@@ -4445,6 +4445,28 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
  		break;
  	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
  	case DWC2_POWER_DOWN_PARAM_NONE:
+		/*
+		 * If not hibernation nor partial power down are supported,

s/not/neither/?

[...]

MBR, Sergei

#29 lore raw

PATCH v2 12/12 usb: dwc2: Add exit clock gating before removing driver

In reply to a message not in the archive

When dwc2 core is in clock gating mode loading driver again causes driver fail. Because in that mode registers are not accessible.

Added a flow of exiting clock gating mode
to avoid the driver reload failure.

---
Changes in v2:
- None

 drivers/usb/dwc2/platform.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/usb/dwc2/platform.c +9 -0
index b28b8cd45799..f8b819cfa80e 100644
@@ -326,6 +326,15 @@ static int dwc2_driver_remove(struct platform_device *dev)
 				"exit partial_power_down failed\n");
 	}
 
+	/* Exit clock gating when driver is removed. */
+	if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE &&
+	    hsotg->bus_suspended) {
+		if (dwc2_is_device_mode(hsotg))
+			dwc2_gadget_exit_clock_gating(hsotg, 0);
+		else
+			dwc2_host_exit_clock_gating(hsotg, 0);
+	}
+
 	dwc2_debugfs_exit(hsotg);
 	if (hsotg->hcd_enabled)
 		dwc2_hcd_remove(hsotg);
Signature · 1 line
2.25.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#31 lore raw

Re: [PATCH v2 00/12] usb: dwc2: Add clock gating support.

Hi Greg,

Quoted 59 lines · Artur Petrosyan

This patch set adds clock gating power saving support for dwc2 core.
It adds support for the following cases described by programming guide.
1. Enter to clock gating from USB_SUSPEND interrupt.
2. Clock gating entering flow by system suspend.
3. Clock gating exiting flow by system resume.
4. Exit clock gating from wakeup interrupt.
5. Exit clock gating from session request interrupt.
6. Exit clock gating when port reset is asserted.

Additional cases to exit form clock gating were needed which are not described in clock gating programming guide.
1. Added clock gating exit flow before removing driver
2. Exit clock gating in urb enqueue.

It updates the implementation of dwc2 entering and exiting clock gating when a port is suspended or resumed.

The patch set also adds the implementation of function handlers for entering and exiting host or device clock gating.

NOTE: This is the third patch set in the power saving mode fixes series.
This patch set is part of multiple series and is continuation of the "usb: dwc2: Fix and improve power saving modes" patch set. (Patch set link: https://marc.info/?l=linux-usb&m=160379622403975&w=2).
The patches that were included in the "usb: dwc2:
Fix and improve power saving modes" which was submitted earlier was too large and needed to be split up into
smaller patch sets.

Changes since V1:
Re sending the patch set as v1 because vger.kernel.org rejected the cover letter. With error code "550 5.7.1 Content-Policy" No changes in the patches or the source code.

Artur Petrosyan (12):
usb: dwc2: Add device clock gating support functions
usb: dwc2: Add host clock gating support functions
usb: dwc2: Allow entering clock gating from USB_SUSPEND interrupt
usb: dwc2: Add exit clock gating from wakeup interrupt
usb: dwc2: Add exit clock gating from session request interrupt
usb: dwc2: Add exit clock gating when port reset is asserted
usb: dwc2: Update enter clock gating when port is suspended
usb: dwc2: Update exit clock gating when port is resumed
usb: dwc2: Allow exit clock gating in urb enqueue
usb: dwc2: Add clock gating entering flow by system suspend
usb: dwc2: Add clock gating exiting flow by system resume
usb: dwc2: Add exit clock gating before removing driver

  drivers/usb/dwc2/core.h      |  15 ++-
  drivers/usb/dwc2/core_intr.c |  62 ++++++++----
  drivers/usb/dwc2/gadget.c    |  71 ++++++++++++++
  drivers/usb/dwc2/hcd.c       | 177 +++++++++++++++++++++++++++--------
  drivers/usb/dwc2/platform.c  |   9 ++
  5 files changed, 272 insertions(+), 62 deletions(-)
Quoted 2 lines

base-commit: 9bc46a12c53d8268392774172742aa9e5dd6953d

This cover letter for the clock gating patches is being rejected by "vger.kernel.org". I have tried to send one more time as v2 but again it is rejected.
The error message is "vger.kernel.org
Remote Server returned '554 5.7.1 <vger.kernel.org #5.7.1 smtp; 550 5.7.1 Content-Policy accept-into-freezer-1"

Could you please suggest any solution to this?

Regards,
Artur

#32 lore raw

Re: [PATCH v2 00/12] usb: dwc2: Add clock gating support.

Quoted 64 lines · Artur Petrosyan

Hi Greg,

Quoted 59 lines · Artur Petrosyan

This patch set adds clock gating power saving support for dwc2 core.
It adds support for the following cases described by programming guide.
1. Enter to clock gating from USB_SUSPEND interrupt.
2. Clock gating entering flow by system suspend.
3. Clock gating exiting flow by system resume.
4. Exit clock gating from wakeup interrupt.
5. Exit clock gating from session request interrupt.
6. Exit clock gating when port reset is asserted.

Additional cases to exit form clock gating were needed which are not described in clock gating programming guide.
1. Added clock gating exit flow before removing driver
2. Exit clock gating in urb enqueue.

It updates the implementation of dwc2 entering and exiting clock gating when a port is suspended or resumed.

The patch set also adds the implementation of function handlers for entering and exiting host or device clock gating.

NOTE: This is the third patch set in the power saving mode fixes series.
This patch set is part of multiple series and is continuation of the "usb: dwc2: Fix and improve power saving modes" patch set. (Patch set link: https://marc.info/?l=linux-usb&m=160379622403975&w=2).
The patches that were included in the "usb: dwc2:
Fix and improve power saving modes" which was submitted earlier was too large and needed to be split up into
smaller patch sets.

Changes since V1:
Re sending the patch set as v1 because vger.kernel.org rejected the cover letter. With error code "550 5.7.1 Content-Policy" No changes in the patches or the source code.

Artur Petrosyan (12):
usb: dwc2: Add device clock gating support functions
usb: dwc2: Add host clock gating support functions
usb: dwc2: Allow entering clock gating from USB_SUSPEND interrupt
usb: dwc2: Add exit clock gating from wakeup interrupt
usb: dwc2: Add exit clock gating from session request interrupt
usb: dwc2: Add exit clock gating when port reset is asserted
usb: dwc2: Update enter clock gating when port is suspended
usb: dwc2: Update exit clock gating when port is resumed
usb: dwc2: Allow exit clock gating in urb enqueue
usb: dwc2: Add clock gating entering flow by system suspend
usb: dwc2: Add clock gating exiting flow by system resume
usb: dwc2: Add exit clock gating before removing driver

  drivers/usb/dwc2/core.h      |  15 ++-
  drivers/usb/dwc2/core_intr.c |  62 ++++++++----
  drivers/usb/dwc2/gadget.c    |  71 ++++++++++++++
  drivers/usb/dwc2/hcd.c       | 177 +++++++++++++++++++++++++++--------
  drivers/usb/dwc2/platform.c  |   9 ++
  5 files changed, 272 insertions(+), 62 deletions(-)
Quoted 2 lines

base-commit: 9bc46a12c53d8268392774172742aa9e5dd6953d

Quoted 8 lines

This cover letter for the clock gating patches is being rejected by "vger.kernel.org". I have tried to send one more time as v2 but again it is rejected.
The error message is "vger.kernel.org
Remote Server returned '554 5.7.1 <vger.kernel.org #5.7.1 smtp; 550 5.7.1 Content-Policy accept-into-freezer-1"

Could you please suggest any solution to this?

No idea, sorry, vger is fickle when it comes to odd rules it has for things it has to deal with. Looks like your patches came through just fine, so all is good.

thanks,

greg k-h