Skip to contentSkip to conversation

clk: qcom: rpmh: Block system suspend if XO is enabled

PATCH/RFC Stephen Boyd 2 participants 3 messages Jun 28, 2022 – Jul 7, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Tracking down what RPMh resource is blocking XO shutdown in suspend is hard. Largely because we need external debug tools to dump the RPMh internal state to figure out what resource is enabled. Instead of doing that, let's just block system wide suspend in the kernel if the RPMh XO resource is enabled by something in the kernel. This will help us narrow down XO shutdown failures to the XO clk, and not something else like an interconnect or regulator RPMh resource.

I'm sending this as an RFC because it breaks suspend for me on Trogdor boards. I found out that the XO resource is always enabled on these devices because the audio driver leaves an audio clk always on. This means that the XO resource must not be used to determine if XO shutdown is achievable, or we're leaving power savings on the table.

Cc Taniya Das <[email protected]>
Cc Mike Tipton <[email protected]>

---

Please don't apply. It will break suspend on Trogdor boards.

 drivers/clk/qcom/clk-rpmh.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/clk/qcom/clk-rpmh.c +15 -0
index aed907982344..ba0e0e4b9cf2 100644
@@ -70,6 +70,14 @@ struct clk_rpmh_desc {
 
 static DEFINE_MUTEX(rpmh_clk_lock);
 
+/* XO shutdown will fail if XO is enabled across suspend */
+static int clk_rpmh_suspend(struct device *dev)
+{
+	struct clk_rpmh *xo = dev_get_drvdata(dev);
+
+	return xo && xo->state ? -EBUSY : 0;
+}
+
 #define __DEFINE_CLK_RPMH(_platform, _name, _name_active, _res_name,	\
 			  _res_en_offset, _res_on, _div)		\
 	static struct clk_rpmh _platform##_##_name_active;		\
@@ -690,6 +698,10 @@ static int clk_rpmh_probe(struct platform_device *pdev)
 			dev_err(&pdev->dev, "failed to register %s\n", name);
 			return ret;
 		}
+
+		/* Stash CXO clk for XO shutdown tracking */
+		if (i == RPMH_CXO_CLK)
+			platform_set_drvdata(pdev, rpmh_clk);
 	}
 
 	/* typecast to silence compiler warning */
@@ -722,9 +734,12 @@ static const struct of_device_id clk_rpmh_match_table[] = {
 };
 MODULE_DEVICE_TABLE(of, clk_rpmh_match_table);
 
+static SIMPLE_DEV_PM_OPS(clk_rpmh_pm_ops, clk_rpmh_suspend, NULL);
+
 static struct platform_driver clk_rpmh_driver = {
 	.probe		= clk_rpmh_probe,
 	.driver		= {
+		.pm	= pm_ptr(&clk_rpmh_pm_ops),
 		.name	= "clk-rpmh",
 		.of_match_table = clk_rpmh_match_table,
 	},

base-commit: f2906aa863381afb0015a9eb7fefad885d4e5a56

Signature · 1 line
https://chromeos.dev
Reviewed-by
#1 lore raw
Quoted 14 lines · Stephen Boyd

Tracking down what RPMh resource is blocking XO shutdown in suspend is hard. Largely because we need external debug tools to dump the RPMh internal state to figure out what resource is enabled. Instead of doing that, let's just block system wide suspend in the kernel if the RPMh XO resource is enabled by something in the kernel. This will help us narrow down XO shutdown failures to the XO clk, and not something else like an interconnect or regulator RPMh resource.

I'm sending this as an RFC because it breaks suspend for me on Trogdor boards. I found out that the XO resource is always enabled on these devices because the audio driver leaves an audio clk always on. This means that the XO resource must not be used to determine if XO shutdown is achievable, or we're leaving power savings on the table.

Quoted 3 lines
Cc Taniya Das <[email protected]>
Cc Mike Tipton <[email protected]>
Quoted 4 lines

---

Please don't apply. It will break suspend on Trogdor boards.

This seems like a useful debug feature for people outside of Qualcomm, so I assume you're saying that we shouldn't merge it until someone has fixed the audio driver? Or did you post it just as a debug tool?

Regards,
Bjorn

Quoted 51 lines
 drivers/clk/qcom/clk-rpmh.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/clk/qcom/clk-rpmh.c +15 -0
index aed907982344..ba0e0e4b9cf2 100644
@@ -70,6 +70,14 @@ struct clk_rpmh_desc {
 
 static DEFINE_MUTEX(rpmh_clk_lock);
 
+/* XO shutdown will fail if XO is enabled across suspend */
+static int clk_rpmh_suspend(struct device *dev)
+{
+	struct clk_rpmh *xo = dev_get_drvdata(dev);
+
+	return xo && xo->state ? -EBUSY : 0;
+}
+
 #define __DEFINE_CLK_RPMH(_platform, _name, _name_active, _res_name,	\
 			  _res_en_offset, _res_on, _div)		\
 	static struct clk_rpmh _platform##_##_name_active;		\
@@ -690,6 +698,10 @@ static int clk_rpmh_probe(struct platform_device *pdev)
 			dev_err(&pdev->dev, "failed to register %s\n", name);
 			return ret;
 		}
+
+		/* Stash CXO clk for XO shutdown tracking */
+		if (i == RPMH_CXO_CLK)
+			platform_set_drvdata(pdev, rpmh_clk);
 	}
 
 	/* typecast to silence compiler warning */
@@ -722,9 +734,12 @@ static const struct of_device_id clk_rpmh_match_table[] = {
 };
 MODULE_DEVICE_TABLE(of, clk_rpmh_match_table);
 
+static SIMPLE_DEV_PM_OPS(clk_rpmh_pm_ops, clk_rpmh_suspend, NULL);
+
 static struct platform_driver clk_rpmh_driver = {
 	.probe		= clk_rpmh_probe,
 	.driver		= {
+		.pm	= pm_ptr(&clk_rpmh_pm_ops),
 		.name	= "clk-rpmh",
 		.of_match_table = clk_rpmh_match_table,
 	},

base-commit: f2906aa863381afb0015a9eb7fefad885d4e5a56

Signature · 1 line
https://chromeos.dev
#2 lore raw

Quoting Bjorn Andersson (2022-06-30 21:00:11)

Quoted 22 lines · Stephen Boyd
Quoted 15 lines

Tracking down what RPMh resource is blocking XO shutdown in suspend is hard. Largely because we need external debug tools to dump the RPMh internal state to figure out what resource is enabled. Instead of doing that, let's just block system wide suspend in the kernel if the RPMh XO resource is enabled by something in the kernel. This will help us narrow down XO shutdown failures to the XO clk, and not something else like an interconnect or regulator RPMh resource.

I'm sending this as an RFC because it breaks suspend for me on Trogdor boards. I found out that the XO resource is always enabled on these devices because the audio driver leaves an audio clk always on. This means that the XO resource must not be used to determine if XO shutdown is achievable, or we're leaving power savings on the table.

Quoted 3 lines
Cc Taniya Das <[email protected]>
Cc Mike Tipton <[email protected]>
Quoted 9 lines
Quoted 4 lines

---

Please don't apply. It will break suspend on Trogdor boards.

This seems like a useful debug feature for people outside of Qualcomm, so I assume you're saying that we shouldn't merge it until someone has fixed the audio driver? Or did you post it just as a debug tool?

I mainly posted it to get a response from Qualcomm on what's going on. I haven't tried to fix the audio driver so far, but I can certainly look into it. The audio clk driver keeping XO on doesn't seem to matter for power because we're hitting the deepest of sleeps on Trogdor boards.

I also realized that due to clk adoption logic we can't be certain that this driver's suspend function will be called after other clk providers that consume XO run their suspend functions. We can probably assume clk consumers that aren't providers will probe after clk-rpmh, so this check is generally safe because we don't have clk providers disabling clks during their suspend functions. It's just not totally safe.

Maybe this is a good reason to add some sort of suspend op to clk_ops and then call that during system wide suspend.