diff mbox series

[1/3] usb: dwc2: Add default param to control power optimization.

Message ID 66bad10fd0f3ff939413981ae7c179f49a542501.1537451080.git.arturp@synopsys.com (mailing list archive)
State New, archived
Headers show
Series usb: dwc2: Fix hibernation for switching between host and device modes. | expand

Commit Message

Artur Petrosyan Sept. 20, 2018, 1:49 p.m. UTC
- Added a default param "power_saving" to enable or
  disable hibernation or partial power down features.

- Printed hibernation param in hw_params_show and
  power_saving param in params_show.

Signed-off-by: Artur Petrosyan <arturp@synopsys.com>
Signed-off-by: Minas Harutyunyan <hminas@synopsys.com>
---
 drivers/usb/dwc2/core.h    |  3 +++
 drivers/usb/dwc2/debugfs.c |  2 ++
 drivers/usb/dwc2/params.c  | 19 +++++++++++++------
 3 files changed, 18 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index cc9c93affa14..2cf5e128cb75 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -373,6 +373,8 @@  enum dwc2_ep0_state {
  *                      case.
  *                      0 - No (default)
  *                      1 - Yes
+ * @power_saving:	Specifies if power saving is enabled or not. If it is
+ *			enabled power_down functionality will be enabled.
  * @power_down:         Specifies whether the controller support power_down.
  *			If power_down is enabled, the controller will enter
  *			power_down in both peripheral and host mode when
@@ -452,6 +454,7 @@  struct dwc2_core_params {
 	bool uframe_sched;
 	bool external_id_pin_ctl;
 
+	unsigned int power_saving:1;
 	int power_down;
 #define DWC2_POWER_DOWN_PARAM_NONE		0
 #define DWC2_POWER_DOWN_PARAM_PARTIAL		1
diff --git a/drivers/usb/dwc2/debugfs.c b/drivers/usb/dwc2/debugfs.c
index 22d015b0424f..9f663d42dfe8 100644
--- a/drivers/usb/dwc2/debugfs.c
+++ b/drivers/usb/dwc2/debugfs.c
@@ -695,6 +695,7 @@  static int params_show(struct seq_file *seq, void *v)
 	print_param_hex(seq, p, ahbcfg);
 	print_param(seq, p, uframe_sched);
 	print_param(seq, p, external_id_pin_ctl);
+	print_param(seq, p, power_saving);
 	print_param(seq, p, power_down);
 	print_param(seq, p, lpm);
 	print_param(seq, p, lpm_clock_gating);
@@ -745,6 +746,7 @@  static int hw_params_show(struct seq_file *seq, void *v)
 	print_param(seq, hw, num_dev_perio_in_ep);
 	print_param(seq, hw, total_fifo_size);
 	print_param(seq, hw, power_optimized);
+	print_param(seq, hw, hibernation);
 	print_param(seq, hw, utmi_phy_data_width);
 	print_param_hex(seq, hw, snpsid);
 	print_param_hex(seq, hw, dev_ep_dirs);
diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
index bf7052e037d6..f51b3659511b 100644
--- a/drivers/usb/dwc2/params.c
+++ b/drivers/usb/dwc2/params.c
@@ -253,12 +253,18 @@  static void dwc2_set_param_power_down(struct dwc2_hsotg *hsotg)
 {
 	int val;
 
-	if (hsotg->hw_params.hibernation)
-		val = 2;
-	else if (hsotg->hw_params.power_optimized)
-		val = 1;
-	else
-		val = 0;
+	if (!hsotg->params.power_saving) {
+		val = DWC2_POWER_DOWN_PARAM_NONE;
+		dev_dbg(hsotg->dev, "%s: Power saving is disabled.\n",
+			__func__);
+	} else {
+		if (hsotg->hw_params.hibernation)
+			val = DWC2_POWER_DOWN_PARAM_HIBERNATION;
+		else if (hsotg->hw_params.power_optimized)
+			val = DWC2_POWER_DOWN_PARAM_PARTIAL;
+		else
+			val = DWC2_POWER_DOWN_PARAM_NONE;
+	}
 
 	hsotg->params.power_down = val;
 }
@@ -280,6 +286,7 @@  static void dwc2_set_default_params(struct dwc2_hsotg *hsotg)
 	dwc2_set_param_phy_type(hsotg);
 	dwc2_set_param_speed(hsotg);
 	dwc2_set_param_phy_utmi_width(hsotg);
+	p->power_saving = true;
 	dwc2_set_param_power_down(hsotg);
 	p->phy_ulpi_ddr = false;
 	p->phy_ulpi_ext_vbus = false;