Skip to contentSkip to conversation

Enahance SVS's robustness

PATCH Applied Roger Lu 2 participants 37 messages Jan 11, 2023 – Feb 11, 2023 Arm MediaTek

v4 of 5 Applied Latest is v5 →

lore
Share & tools
lore

Roger Lu

author
#0 lore raw

v4 cover Enahance SVS's robustness

SVS driver got accepted upstream but still has room to be improved. Therefore, we add these patches to fix issues and coding style.

Change since v3:
- Remove cleanup codes in patch [01/14] for letting it backport easily
- Enclose svs debug cmd codes with "CONFIG_DEBUG_FS" where needed
- Reorder patch sequenece to put fix up patch first

Tested on:
MT8183 Platform (kernel v5.10)
MT8192 Platform (kernel v5.4)

Matthias Brugger (4):
soc: mediatek: mtk-svs: clean up platform probing
soc: mediatek: mtk-svs: improve readability of platform_probe
soc: mediatek: mtk-svs: move svs_platform_probe into probe
soc: mediatek: mtk-svs: delete superfluous platform data entries

Ricardo Ribalda (1):
soc: mediatek: mtk-svs: enable the IRQ later

Roger Lu (8):
soc: mediatek: mtk-svs: restore default voltages when svs_init02()
fail
soc: mediatek: mtk-svs: reset svs when svs_resume() fail
soc: mediatek: mtk-svs: use svs clk control APIs
soc: mediatek: mtk-svs: add thermal voltage compensation if needed
soc: mediatek: mtk-svs: keep svs alive if CONFIG_DEBUG_FS not
supported
soc: mediatek: mtk-svs: use svs get efuse common function
soc: mediatek: mtk-svs: use common function to disable restore
voltages
soc: mtk-svs: mt8183: refactor o_slope calculation

Shang XiaoJing (1):
soc: mediatek: mtk-svs: Use pm_runtime_resume_and_get() in

    svs_init01()
 drivers/soc/mediatek/mtk-svs.c | 339 +++++++++++++++++----------------
 1 file changed, 173 insertions(+), 166 deletions(-)
author
#1 lore raw

PATCH v4 1/14 soc: mediatek: mtk-svs: restore default voltages when svs_init02() fail

If svs init02 fail, it means we cannot rely on svs bank voltages anymore. We need to disable svs function and restore DVFS opp voltages back to the default voltages for making sure we have enough DVFS voltages.

Fixes 681a02e95000 ("soc: mediatek: SVS: introduce MTK SVS engine")
Fixes 0bbb09b2af9d ("soc: mediatek: SVS: add mt8192 SVS GPU driver")
---
 drivers/soc/mediatek/mtk-svs.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/soc/mediatek/mtk-svs.c +22 -2
index 0469c9dfeb04..2df30a6bca28 100644
@@ -1461,6 +1461,7 @@ static int svs_init02(struct svs_platform *svsp)
 {
 	struct svs_bank *svsb;
 	unsigned long flags, time_left;
+	int ret;
 	u32 idx;
 
 	for (idx = 0; idx < svsp->bank_max; idx++) {
@@ -1479,7 +1480,8 @@ static int svs_init02(struct svs_platform *svsp)
 							msecs_to_jiffies(5000));
 		if (!time_left) {
 			dev_err(svsb->dev, "init02 completion timeout\n");
-			return -EBUSY;
+			ret = -EBUSY;
+			goto out_of_init02;
 		}
 	}
 
@@ -1497,12 +1499,30 @@ static int svs_init02(struct svs_platform *svsp)
 		if (svsb->type == SVSB_HIGH || svsb->type == SVSB_LOW) {
 			if (svs_sync_bank_volts_from_opp(svsb)) {
 				dev_err(svsb->dev, "sync volt fail\n");
-				return -EPERM;
+				ret = -EPERM;
+				goto out_of_init02;
 			}
 		}
 	}
 
 	return 0;
+
+out_of_init02:
+	for (idx = 0; idx < svsp->bank_max; idx++) {
+		svsb = &svsp->banks[idx];
+
+		spin_lock_irqsave(&svs_lock, flags);
+		svsp->pbank = svsb;
+		svs_switch_bank(svsp);
+		svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN);
+		svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS);
+		spin_unlock_irqrestore(&svs_lock, flags);
+
+		svsb->phase = SVSB_PHASE_ERROR;
+		svs_adjust_pm_opp_volts(svsb);
+	}
+
+	return ret;
 }
 
 static void svs_mon_mode(struct svs_platform *svsp)
Signature · 1 line
2.18.0
maintainer Applied
#2 lore raw

Re: [PATCH v4 01/14] soc: mediatek: mtk-svs: restore default voltages when svs_init02() fail

Quoted 7 lines · Roger Lu

If svs init02 fail, it means we cannot rely on svs bank voltages anymore. We need to disable svs function and restore DVFS opp voltages back to the default voltages for making sure we have enough DVFS voltages.

Fixes 681a02e95000 ("soc: mediatek: SVS: introduce MTK SVS engine")
Fixes 0bbb09b2af9d ("soc: mediatek: SVS: add mt8192 SVS GPU driver")

Applied, thanks!

Quoted 58 lines
---
  drivers/soc/mediatek/mtk-svs.c | 24 ++++++++++++++++++++++--
  1 file changed, 22 insertions(+), 2 deletions(-)
drivers/soc/mediatek/mtk-svs.c +22 -2
index 0469c9dfeb04..2df30a6bca28 100644
@@ -1461,6 +1461,7 @@ static int svs_init02(struct svs_platform *svsp)
  {
  	struct svs_bank *svsb;
  	unsigned long flags, time_left;
+	int ret;
  	u32 idx;
 
  	for (idx = 0; idx < svsp->bank_max; idx++) {
@@ -1479,7 +1480,8 @@ static int svs_init02(struct svs_platform *svsp)
  							msecs_to_jiffies(5000));
  		if (!time_left) {
  			dev_err(svsb->dev, "init02 completion timeout\n");
-			return -EBUSY;
+			ret = -EBUSY;
+			goto out_of_init02;
  		}
  	}
 
@@ -1497,12 +1499,30 @@ static int svs_init02(struct svs_platform *svsp)
  		if (svsb->type == SVSB_HIGH || svsb->type == SVSB_LOW) {
  			if (svs_sync_bank_volts_from_opp(svsb)) {
  				dev_err(svsb->dev, "sync volt fail\n");
-				return -EPERM;
+				ret = -EPERM;
+				goto out_of_init02;
  			}
  		}
  	}
 
  	return 0;
+
+out_of_init02:
+	for (idx = 0; idx < svsp->bank_max; idx++) {
+		svsb = &svsp->banks[idx];
+
+		spin_lock_irqsave(&svs_lock, flags);
+		svsp->pbank = svsb;
+		svs_switch_bank(svsp);
+		svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN);
+		svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS);
+		spin_unlock_irqrestore(&svs_lock, flags);
+
+		svsb->phase = SVSB_PHASE_ERROR;
+		svs_adjust_pm_opp_volts(svsb);
+	}
+
+	return ret;
  }
 
  static void svs_mon_mode(struct svs_platform *svsp)
author
#3 lore raw

PATCH v4 2/14 soc: mediatek: mtk-svs: reset svs when svs_resume() fail

In reply to Roger Lu

Add svs reset when svs_resume() fail.

Fixes a825d72f74a3 ("soc: mediatek: fix missing clk_disable_unprepare() on err in svs_resume()")
---
 drivers/soc/mediatek/mtk-svs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/soc/mediatek/mtk-svs.c +5 -1
index 2df30a6bca28..a803b92afc3d 100644
@@ -1614,12 +1614,16 @@ static int svs_resume(struct device *dev)
 
 	ret = svs_init02(svsp);
 	if (ret)
-		goto out_of_resume;
+		goto svs_resume_reset_assert;
 
 	svs_mon_mode(svsp);
 
 	return 0;
 
+svs_resume_reset_assert:
+	dev_err(svsp->dev, "assert reset: %d\n",
+		reset_control_assert(svsp->rst));
+
 out_of_resume:
 	clk_disable_unprepare(svsp->main_clk);
 	return ret;
Signature · 1 line
2.18.0
maintainer Applied
#4 lore raw

Re: [PATCH v4 02/14] soc: mediatek: mtk-svs: reset svs when svs_resume() fail

Quoted 4 lines · Roger Lu

Add svs reset when svs_resume() fail.

Fixes a825d72f74a3 ("soc: mediatek: fix missing clk_disable_unprepare() on err in svs_resume()")

Applied, thanks!

Quoted 26 lines
---
  drivers/soc/mediatek/mtk-svs.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/soc/mediatek/mtk-svs.c +5 -1
index 2df30a6bca28..a803b92afc3d 100644
@@ -1614,12 +1614,16 @@ static int svs_resume(struct device *dev)
 
  	ret = svs_init02(svsp);
  	if (ret)
-		goto out_of_resume;
+		goto svs_resume_reset_assert;
 
  	svs_mon_mode(svsp);
 
  	return 0;
 
+svs_resume_reset_assert:
+	dev_err(svsp->dev, "assert reset: %d\n",
+		reset_control_assert(svsp->rst));
+
  out_of_resume:
  	clk_disable_unprepare(svsp->main_clk);
  	return ret;
author
#5 lore raw

PATCH v4 3/14 soc: mediatek: mtk-svs: enable the IRQ later

In reply to Roger Lu

From: Ricardo Ribalda <[email protected]>

If the system does not come from reset (like when is booted via kexec(), the peripheral might trigger an IRQ before the data structures are initialized.

Fixes:

[    0.227710] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000f08
[    0.227913] Call trace:
[    0.227918]  svs_isr+0x8c/0x538
Fixes 681a02e95000 ("soc: mediatek: SVS: introduce MTK SVS engine")
---
 drivers/soc/mediatek/mtk-svs.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/soc/mediatek/mtk-svs.c +14 -14
index a803b92afc3d..64d4d03ab71c 100644
@@ -2403,20 +2403,6 @@ static int svs_probe(struct platform_device *pdev)
 		goto svs_probe_free_resource;
 	}
 
-	svsp_irq = platform_get_irq(pdev, 0);
-	if (svsp_irq < 0) {
-		ret = svsp_irq;
-		goto svs_probe_free_resource;
-	}
-
-	ret = devm_request_threaded_irq(svsp->dev, svsp_irq, NULL, svs_isr,
-					IRQF_ONESHOT, svsp->name, svsp);
-	if (ret) {
-		dev_err(svsp->dev, "register irq(%d) failed: %d\n",
-			svsp_irq, ret);
-		goto svs_probe_free_resource;
-	}
-
 	svsp->main_clk = devm_clk_get(svsp->dev, "main");
 	if (IS_ERR(svsp->main_clk)) {
 		dev_err(svsp->dev, "failed to get clock: %ld\n",
@@ -2438,6 +2424,20 @@ static int svs_probe(struct platform_device *pdev)
 		goto svs_probe_clk_disable;
 	}
 
+	svsp_irq = platform_get_irq(pdev, 0);
+	if (svsp_irq < 0) {
+		ret = svsp_irq;
+		goto svs_probe_iounmap;
+	}
+
+	ret = devm_request_threaded_irq(svsp->dev, svsp_irq, NULL, svs_isr,
+					IRQF_ONESHOT, svsp->name, svsp);
+	if (ret) {
+		dev_err(svsp->dev, "register irq(%d) failed: %d\n",
+			svsp_irq, ret);
+		goto svs_probe_iounmap;
+	}
+
 	ret = svs_start(svsp);
 	if (ret) {
 		dev_err(svsp->dev, "svs start fail: %d\n", ret);
Signature · 1 line
2.18.0
maintainer
#6 lore raw

Re: [PATCH v4 03/14] soc: mediatek: mtk-svs: enable the IRQ later

Quoted 6 lines · Roger Lu

From: Ricardo Ribalda <[email protected]>

If the system does not come from reset (like when is booted via kexec(), the peripheral might trigger an IRQ before the data structures are initialized.

Quoted 6 lines

Fixes:

[    0.227710] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000f08
[    0.227913] Call trace:
[    0.227918]  svs_isr+0x8c/0x538

This patch is different from
https://lore.kernel.org/r/[email protected]

If you think the patch from Ricardo is wrong, then you should have mentioned that in the review.

Regards,
Matthias

Quoted 53 lines
Fixes 681a02e95000 ("soc: mediatek: SVS: introduce MTK SVS engine")
---
  drivers/soc/mediatek/mtk-svs.c | 28 ++++++++++++++--------------
  1 file changed, 14 insertions(+), 14 deletions(-)
drivers/soc/mediatek/mtk-svs.c +14 -14
index a803b92afc3d..64d4d03ab71c 100644
@@ -2403,20 +2403,6 @@ static int svs_probe(struct platform_device *pdev)
  		goto svs_probe_free_resource;
  	}
 
-	svsp_irq = platform_get_irq(pdev, 0);
-	if (svsp_irq < 0) {
-		ret = svsp_irq;
-		goto svs_probe_free_resource;
-	}
-
-	ret = devm_request_threaded_irq(svsp->dev, svsp_irq, NULL, svs_isr,
-					IRQF_ONESHOT, svsp->name, svsp);
-	if (ret) {
-		dev_err(svsp->dev, "register irq(%d) failed: %d\n",
-			svsp_irq, ret);
-		goto svs_probe_free_resource;
-	}
-
  	svsp->main_clk = devm_clk_get(svsp->dev, "main");
  	if (IS_ERR(svsp->main_clk)) {
  		dev_err(svsp->dev, "failed to get clock: %ld\n",
@@ -2438,6 +2424,20 @@ static int svs_probe(struct platform_device *pdev)
  		goto svs_probe_clk_disable;
  	}
 
+	svsp_irq = platform_get_irq(pdev, 0);
+	if (svsp_irq < 0) {
+		ret = svsp_irq;
+		goto svs_probe_iounmap;
+	}
+
+	ret = devm_request_threaded_irq(svsp->dev, svsp_irq, NULL, svs_isr,
+					IRQF_ONESHOT, svsp->name, svsp);
+	if (ret) {
+		dev_err(svsp->dev, "register irq(%d) failed: %d\n",
+			svsp_irq, ret);
+		goto svs_probe_iounmap;
+	}
+
  	ret = svs_start(svsp);
  	if (ret) {
  		dev_err(svsp->dev, "svs start fail: %d\n", ret);
#7 lore raw

Re: [PATCH v4 03/14] soc: mediatek: mtk-svs: enable the IRQ later

Hi Matthias Sir,

Quoted 16 lines · Matthias Brugger
Quoted 6 lines · Roger Lu

From: Ricardo Ribalda <[email protected]>

If the system does not come from reset (like when is booted via kexec(), the peripheral might trigger an IRQ before the data structures are initialized.

Quoted 7 lines

Fixes:

[    0.227710] Unable to handle kernel NULL pointer dereference at virtual
address 0000000000000f08
[    0.227913] Call trace:
[    0.227918]  svs_isr+0x8c/0x538
Quoted 5 lines

This patch is different from
https://lore.kernel.org/r/[email protected]

If you think the patch from Ricardo is wrong, then you should have mentioned that in the review.

My bad. Ricardo's patch is correct. Moving platform_get_irq() brings no functional change and is for helping the svs probe readability as my preference.

Quoted 57 lines

Regards,
Matthias

Quoted 53 lines
Fixes 681a02e95000 ("soc: mediatek: SVS: introduce MTK SVS engine")
---
  drivers/soc/mediatek/mtk-svs.c | 28 ++++++++++++++--------------
  1 file changed, 14 insertions(+), 14 deletions(-)
drivers/soc/mediatek/mtk-svs.c +14 -14
index a803b92afc3d..64d4d03ab71c 100644
@@ -2403,20 +2403,6 @@ static int svs_probe(struct platform_device *pdev)
  		goto svs_probe_free_resource;
  	}
 
-	svsp_irq = platform_get_irq(pdev, 0);
-	if (svsp_irq < 0) {
-		ret = svsp_irq;
-		goto svs_probe_free_resource;
-	}
-
-	ret = devm_request_threaded_irq(svsp->dev, svsp_irq, NULL, svs_isr,
-					IRQF_ONESHOT, svsp->name, svsp);
-	if (ret) {
-		dev_err(svsp->dev, "register irq(%d) failed: %d\n",
-			svsp_irq, ret);
-		goto svs_probe_free_resource;
-	}
-
  	svsp->main_clk = devm_clk_get(svsp->dev, "main");
  	if (IS_ERR(svsp->main_clk)) {
  		dev_err(svsp->dev, "failed to get clock: %ld\n",
@@ -2438,6 +2424,20 @@ static int svs_probe(struct platform_device *pdev)
  		goto svs_probe_clk_disable;
  	}
 
+	svsp_irq = platform_get_irq(pdev, 0);
+	if (svsp_irq < 0) {
+		ret = svsp_irq;
+		goto svs_probe_iounmap;
+	}
+
+	ret = devm_request_threaded_irq(svsp->dev, svsp_irq, NULL, svs_isr,
+					IRQF_ONESHOT, svsp->name, svsp);
+	if (ret) {
+		dev_err(svsp->dev, "register irq(%d) failed: %d\n",
+			svsp_irq, ret);
+		goto svs_probe_iounmap;
+	}
+
  	ret = svs_start(svsp);
  	if (ret) {
  		dev_err(svsp->dev, "svs start fail: %d\n", ret);
maintainer
#8 lore raw

Re: [PATCH v4 03/14] soc: mediatek: mtk-svs: enable the IRQ later

Quoted 19 lines · Roger Lu (陸瑞傑)

Hi Matthias Sir,

Quoted 16 lines · Matthias Brugger
Quoted 13 lines · Roger Lu

From: Ricardo Ribalda <[email protected]>

If the system does not come from reset (like when is booted via kexec(), the peripheral might trigger an IRQ before the data structures are initialized.

Fixes:

[    0.227710] Unable to handle kernel NULL pointer dereference at virtual
address 0000000000000f08
[    0.227913] Call trace:
[    0.227918]  svs_isr+0x8c/0x538
Quoted 9 lines
Quoted 5 lines

This patch is different from
https://lore.kernel.org/r/[email protected]

If you think the patch from Ricardo is wrong, then you should have mentioned that in the review.

My bad. Ricardo's patch is correct. Moving platform_get_irq() brings no functional change and is for helping the svs probe readability as my preference.

Thanks for the confirmation!

Regards,
Matthias

Quoted 57 lines
Quoted 57 lines

Regards,
Matthias

Quoted 53 lines
Fixes 681a02e95000 ("soc: mediatek: SVS: introduce MTK SVS engine")
---
   drivers/soc/mediatek/mtk-svs.c | 28 ++++++++++++++--------------
   1 file changed, 14 insertions(+), 14 deletions(-)
drivers/soc/mediatek/mtk-svs.c +14 -14
index a803b92afc3d..64d4d03ab71c 100644
@@ -2403,20 +2403,6 @@ static int svs_probe(struct platform_device *pdev)
   		goto svs_probe_free_resource;
   	}
 
-	svsp_irq = platform_get_irq(pdev, 0);
-	if (svsp_irq < 0) {
-		ret = svsp_irq;
-		goto svs_probe_free_resource;
-	}
-
-	ret = devm_request_threaded_irq(svsp->dev, svsp_irq, NULL, svs_isr,
-					IRQF_ONESHOT, svsp->name, svsp);
-	if (ret) {
-		dev_err(svsp->dev, "register irq(%d) failed: %d\n",
-			svsp_irq, ret);
-		goto svs_probe_free_resource;
-	}
-
   	svsp->main_clk = devm_clk_get(svsp->dev, "main");
   	if (IS_ERR(svsp->main_clk)) {
   		dev_err(svsp->dev, "failed to get clock: %ld\n",
@@ -2438,6 +2424,20 @@ static int svs_probe(struct platform_device *pdev)
   		goto svs_probe_clk_disable;
   	}
 
+	svsp_irq = platform_get_irq(pdev, 0);
+	if (svsp_irq < 0) {
+		ret = svsp_irq;
+		goto svs_probe_iounmap;
+	}
+
+	ret = devm_request_threaded_irq(svsp->dev, svsp_irq, NULL, svs_isr,
+					IRQF_ONESHOT, svsp->name, svsp);
+	if (ret) {
+		dev_err(svsp->dev, "register irq(%d) failed: %d\n",
+			svsp_irq, ret);
+		goto svs_probe_iounmap;
+	}
+
   	ret = svs_start(svsp);
   	if (ret) {
   		dev_err(svsp->dev, "svs start fail: %d\n", ret);
author
#9 lore raw

PATCH v4 4/14 soc: mediatek: mtk-svs: Use pm_runtime_resume_and_get() in svs_init01()

In reply to Roger Lu

From: Shang XiaoJing <[email protected]>

svs_init01() calls pm_runtime_get_sync() and added fail path as svs_init01_finish to put usage_counter. However, pm_runtime_get_sync() will increment usage_counter even it failed. Fix it by replacing it with pm_runtime_resume_and_get() to keep usage counter balanced.

Fixes 681a02e95000 ("soc: mediatek: SVS: introduce MTK SVS engine")
---
 drivers/soc/mediatek/mtk-svs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/mediatek/mtk-svs.c +1 -1
index 64d4d03ab71c..9575aa645643 100644
@@ -1324,7 +1324,7 @@ static int svs_init01(struct svs_platform *svsp)
 				svsb->pm_runtime_enabled_count++;
 			}
 
-			ret = pm_runtime_get_sync(svsb->opp_dev);
+			ret = pm_runtime_resume_and_get(svsb->opp_dev);
 			if (ret < 0) {
 				dev_err(svsb->dev, "mtcmos on fail: %d\n", ret);
 				goto svs_init01_resume_cpuidle;
Signature · 1 line
2.18.0
maintainer Applied
#10 lore raw

Re: [PATCH v4 04/14] soc: mediatek: mtk-svs: Use pm_runtime_resume_and_get() in svs_init01()

Quoted 11 lines · Roger Lu

From: Shang XiaoJing <[email protected]>

svs_init01() calls pm_runtime_get_sync() and added fail path as svs_init01_finish to put usage_counter. However, pm_runtime_get_sync() will increment usage_counter even it failed. Fix it by replacing it with pm_runtime_resume_and_get() to keep usage counter balanced.

Fixes 681a02e95000 ("soc: mediatek: SVS: introduce MTK SVS engine")

Applied, thanks!

Quoted 17 lines
---
  drivers/soc/mediatek/mtk-svs.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/mediatek/mtk-svs.c +1 -1
index 64d4d03ab71c..9575aa645643 100644
@@ -1324,7 +1324,7 @@ static int svs_init01(struct svs_platform *svsp)
  				svsb->pm_runtime_enabled_count++;
  			}
 
-			ret = pm_runtime_get_sync(svsb->opp_dev);
+			ret = pm_runtime_resume_and_get(svsb->opp_dev);
  			if (ret < 0) {
  				dev_err(svsb->dev, "mtcmos on fail: %d\n", ret);
  				goto svs_init01_resume_cpuidle;
author
#11 lore raw

PATCH v4 5/14 soc: mediatek: mtk-svs: use svs clk control APIs

In reply to Roger Lu

In MediaTek HW design, svs and thermal both use the same clk source. It means that svs clk reference count from CCF includes thermal control counts. That makes svs driver confuse whether it disabled svs's main clk or not from CCF's perspective and lead to turn off their shared clk unexpectedly. Therefore, we add svs clk control APIs to make sure svs's main clk is controlled well by svs driver itself.

Here is a NG example. Rely on CCF's reference count and cause problem.

thermal probe (clk ref = 1)
-> svs probe (clk ref = 2)
-> svs suspend (clk ref = 1)

      -> thermal suspend (clk ref = 0)
      -> thermal resume (clk ref = 1)
   -> svs resume (encounter error, clk ref = 1)
   -> svs suspend (clk ref = 0)
      -> thermal suspend (Fail here, thermal HW control w/o clk)
Fixes a825d72f74a3 ("soc: mediatek: fix missing clk_disable_unprepare() on err in svs_resume()")
---
 drivers/soc/mediatek/mtk-svs.c | 57 ++++++++++++++++++++++++++--------
 1 file changed, 44 insertions(+), 13 deletions(-)
drivers/soc/mediatek/mtk-svs.c +44 -13
index 9575aa645643..830263bad81e 100644
@@ -326,6 +326,7 @@ static const u32 svs_regs_v2[] = {
  * @bank_max: total number of svs banks
  * @efuse: svs efuse data received from NVMEM framework
  * @tefuse: thermal efuse data received from NVMEM framework
+ * @clk_cnt: clock count shows the clk enable/disable times by svs driver
  */
 struct svs_platform {
 	char *name;
@@ -343,6 +344,7 @@ struct svs_platform {
 	u32 bank_max;
 	u32 *efuse;
 	u32 *tefuse;
+	s32 clk_cnt;
 };
 
 struct svs_platform_data {
@@ -502,6 +504,32 @@ static void svs_switch_bank(struct svs_platform *svsp)
 	svs_writel_relaxed(svsp, svsb->core_sel, CORESEL);
 }
 
+static bool svs_is_clk_enabled(struct svs_platform *svsp)
+{
+	return svsp->clk_cnt > 0 ? true : false;
+}
+
+static int svs_clk_enable(struct svs_platform *svsp)
+{
+	int ret;
+
+	ret = clk_prepare_enable(svsp->main_clk);
+	if (ret) {
+		dev_err(svsp->dev, "cannot enable main_clk: %d\n", ret);
+		return ret;
+	}
+
+	svsp->clk_cnt++;
+
+	return 0;
+}
+
+static void svs_clk_disable(struct svs_platform *svsp)
+{
+	clk_disable_unprepare(svsp->main_clk);
+	svsp->clk_cnt--;
+}
+
 static u32 svs_bank_volt_to_opp_volt(u32 svsb_volt, u32 svsb_volt_step,
 				     u32 svsb_volt_base)
 {
@@ -1569,6 +1597,12 @@ static int svs_suspend(struct device *dev)
 	int ret;
 	u32 idx;
 
+	if (!svs_is_clk_enabled(svsp)) {
+		dev_err(svsp->dev, "svs clk is disabled already (%d)\n",
+			svsp->clk_cnt);
+		return 0;
+	}
+
 	for (idx = 0; idx < svsp->bank_max; idx++) {
 		svsb = &svsp->banks[idx];
 
@@ -1590,7 +1624,7 @@ static int svs_suspend(struct device *dev)
 		return ret;
 	}
 
-	clk_disable_unprepare(svsp->main_clk);
+	svs_clk_disable(svsp);
 
 	return 0;
 }
@@ -1600,16 +1634,14 @@ static int svs_resume(struct device *dev)
 	struct svs_platform *svsp = dev_get_drvdata(dev);
 	int ret;
 
-	ret = clk_prepare_enable(svsp->main_clk);
-	if (ret) {
-		dev_err(svsp->dev, "cannot enable main_clk, disable svs\n");
+	ret = svs_clk_enable(svsp);
+	if (ret)
 		return ret;
-	}
 
 	ret = reset_control_deassert(svsp->rst);
 	if (ret) {
 		dev_err(svsp->dev, "cannot deassert reset %d\n", ret);
-		goto out_of_resume;
+		goto svs_resume_clk_disable;
 	}
 
 	ret = svs_init02(svsp);
@@ -1624,8 +1656,9 @@ static int svs_resume(struct device *dev)
 	dev_err(svsp->dev, "assert reset: %d\n",
 		reset_control_assert(svsp->rst));
 
-out_of_resume:
-	clk_disable_unprepare(svsp->main_clk);
+svs_resume_clk_disable:
+	svs_clk_disable(svsp);
+
 	return ret;
 }
 
@@ -2411,11 +2444,9 @@ static int svs_probe(struct platform_device *pdev)
 		goto svs_probe_free_resource;
 	}
 
-	ret = clk_prepare_enable(svsp->main_clk);
-	if (ret) {
-		dev_err(svsp->dev, "cannot enable main clk: %d\n", ret);
+	ret = svs_clk_enable(svsp);
+	if (ret)
 		goto svs_probe_free_resource;
-	}
 
 	svsp->base = of_iomap(svsp->dev->of_node, 0);
 	if (IS_ERR_OR_NULL(svsp->base)) {
@@ -2456,7 +2487,7 @@ static int svs_probe(struct platform_device *pdev)
 	iounmap(svsp->base);
 
 svs_probe_clk_disable:
-	clk_disable_unprepare(svsp->main_clk);
+	svs_clk_disable(svsp);
 
 svs_probe_free_resource:
 	if (!IS_ERR_OR_NULL(svsp->efuse))
Signature · 1 line
2.18.0
maintainer
#12 lore raw

Re: [PATCH v4 05/14] soc: mediatek: mtk-svs: use svs clk control APIs

Quoted 18 lines · Roger Lu

In MediaTek HW design, svs and thermal both use the same clk source. It means that svs clk reference count from CCF includes thermal control counts. That makes svs driver confuse whether it disabled svs's main clk or not from CCF's perspective and lead to turn off their shared clk unexpectedly. Therefore, we add svs clk control APIs to make sure svs's main clk is controlled well by svs driver itself.

Here is a NG example. Rely on CCF's reference count and cause problem.

thermal probe (clk ref = 1)
-> svs probe (clk ref = 2)

    -> svs suspend (clk ref = 1)
       -> thermal suspend (clk ref = 0)
       -> thermal resume (clk ref = 1)
    -> svs resume (encounter error, clk ref = 1)
    -> svs suspend (clk ref = 0)
       -> thermal suspend (Fail here, thermal HW control w/o clk)
Quoted 2 lines
Fixes a825d72f74a3 ("soc: mediatek: fix missing clk_disable_unprepare() on err in svs_resume()")

That looks wrong. Although I don't out of my mind, there should be a way to tell the clock framework that this clock is shared between several devices.

I wonder if using clk_enable and clk_disable in svs_resume/suspend wouldn't be enough.

Regards,
Matthias

Quoted 134 lines
---
  drivers/soc/mediatek/mtk-svs.c | 57 ++++++++++++++++++++++++++--------
  1 file changed, 44 insertions(+), 13 deletions(-)
drivers/soc/mediatek/mtk-svs.c +44 -13
index 9575aa645643..830263bad81e 100644
@@ -326,6 +326,7 @@ static const u32 svs_regs_v2[] = {
   * @bank_max: total number of svs banks
   * @efuse: svs efuse data received from NVMEM framework
   * @tefuse: thermal efuse data received from NVMEM framework
+ * @clk_cnt: clock count shows the clk enable/disable times by svs driver
   */
  struct svs_platform {
  	char *name;
@@ -343,6 +344,7 @@ struct svs_platform {
  	u32 bank_max;
  	u32 *efuse;
  	u32 *tefuse;
+	s32 clk_cnt;
  };
 
  struct svs_platform_data {
@@ -502,6 +504,32 @@ static void svs_switch_bank(struct svs_platform *svsp)
  	svs_writel_relaxed(svsp, svsb->core_sel, CORESEL);
  }
 
+static bool svs_is_clk_enabled(struct svs_platform *svsp)
+{
+	return svsp->clk_cnt > 0 ? true : false;
+}
+
+static int svs_clk_enable(struct svs_platform *svsp)
+{
+	int ret;
+
+	ret = clk_prepare_enable(svsp->main_clk);
+	if (ret) {
+		dev_err(svsp->dev, "cannot enable main_clk: %d\n", ret);
+		return ret;
+	}
+
+	svsp->clk_cnt++;
+
+	return 0;
+}
+
+static void svs_clk_disable(struct svs_platform *svsp)
+{
+	clk_disable_unprepare(svsp->main_clk);
+	svsp->clk_cnt--;
+}
+
  static u32 svs_bank_volt_to_opp_volt(u32 svsb_volt, u32 svsb_volt_step,
  				     u32 svsb_volt_base)
  {
@@ -1569,6 +1597,12 @@ static int svs_suspend(struct device *dev)
  	int ret;
  	u32 idx;
 
+	if (!svs_is_clk_enabled(svsp)) {
+		dev_err(svsp->dev, "svs clk is disabled already (%d)\n",
+			svsp->clk_cnt);
+		return 0;
+	}
+
  	for (idx = 0; idx < svsp->bank_max; idx++) {
  		svsb = &svsp->banks[idx];
 
@@ -1590,7 +1624,7 @@ static int svs_suspend(struct device *dev)
  		return ret;
  	}
 
-	clk_disable_unprepare(svsp->main_clk);
+	svs_clk_disable(svsp);
 
  	return 0;
  }
@@ -1600,16 +1634,14 @@ static int svs_resume(struct device *dev)
  	struct svs_platform *svsp = dev_get_drvdata(dev);
  	int ret;
 
-	ret = clk_prepare_enable(svsp->main_clk);
-	if (ret) {
-		dev_err(svsp->dev, "cannot enable main_clk, disable svs\n");
+	ret = svs_clk_enable(svsp);
+	if (ret)
  		return ret;
-	}
 
  	ret = reset_control_deassert(svsp->rst);
  	if (ret) {
  		dev_err(svsp->dev, "cannot deassert reset %d\n", ret);
-		goto out_of_resume;
+		goto svs_resume_clk_disable;
  	}
 
  	ret = svs_init02(svsp);
@@ -1624,8 +1656,9 @@ static int svs_resume(struct device *dev)
  	dev_err(svsp->dev, "assert reset: %d\n",
  		reset_control_assert(svsp->rst));
 
-out_of_resume:
-	clk_disable_unprepare(svsp->main_clk);
+svs_resume_clk_disable:
+	svs_clk_disable(svsp);
+
  	return ret;
  }
 
@@ -2411,11 +2444,9 @@ static int svs_probe(struct platform_device *pdev)
  		goto svs_probe_free_resource;
  	}
 
-	ret = clk_prepare_enable(svsp->main_clk);
-	if (ret) {
-		dev_err(svsp->dev, "cannot enable main clk: %d\n", ret);
+	ret = svs_clk_enable(svsp);
+	if (ret)
  		goto svs_probe_free_resource;
-	}
 
  	svsp->base = of_iomap(svsp->dev->of_node, 0);
  	if (IS_ERR_OR_NULL(svsp->base)) {
@@ -2456,7 +2487,7 @@ static int svs_probe(struct platform_device *pdev)
  	iounmap(svsp->base);
 
  svs_probe_clk_disable:
-	clk_disable_unprepare(svsp->main_clk);
+	svs_clk_disable(svsp);
 
  svs_probe_free_resource:
  	if (!IS_ERR_OR_NULL(svsp->efuse))
#13 lore raw

Re: [PATCH v4 05/14] soc: mediatek: mtk-svs: use svs clk control APIs

Hi Matthias Sir,

Quoted 24 lines · Matthias Brugger
Quoted 18 lines · Roger Lu

In MediaTek HW design, svs and thermal both use the same clk source. It means that svs clk reference count from CCF includes thermal control counts. That makes svs driver confuse whether it disabled svs's main clk or not from CCF's perspective and lead to turn off their shared clk unexpectedly. Therefore, we add svs clk control APIs to make sure svs's main clk is controlled well by svs driver itself.

Here is a NG example. Rely on CCF's reference count and cause problem.

thermal probe (clk ref = 1)
-> svs probe (clk ref = 2)

    -> svs suspend (clk ref = 1)
       -> thermal suspend (clk ref = 0)
       -> thermal resume (clk ref = 1)
    -> svs resume (encounter error, clk ref = 1)
    -> svs suspend (clk ref = 0)
       -> thermal suspend (Fail here, thermal HW control w/o clk)
Quoted 3 lines
Fixes a825d72f74a3 ("soc: mediatek: fix missing clk_disable_unprepare() on

err in svs_resume()")

Quoted 7 lines

That looks wrong. Although I don't out of my mind, there should be a way to tell
the clock framework that this clock is shared between several devices.

I wonder if using clk_enable and clk_disable in svs_resume/suspend wouldn't be
enough.

Oh yes, Common Clock Framework (CCF) knows the clock shared between several devices and maintains clock "on/off" by reference count.

We concern how to stop running svs_suspend() when svs clk is already disabled by svs_resume(). Take an example as below, if we refers to __clk_is_enabled() result for knowing svs clk status, it will return "true" all the time because thermal clk is still on. This causes the problem mentioned in commit message.

static int svs_suspend(struct device *dev)
{
...

	if (!__clk_is_enabled(svsp->main_clk)) //always get `true`
		return 0;

...
}

Quoted 3 lines

Regards,
Matthias

... [snip] ...

maintainer
#14 lore raw

Re: [PATCH v4 05/14] soc: mediatek: mtk-svs: use svs clk control APIs

你好,

Quoted 31 lines · Roger Lu (陸瑞傑)

Hi Matthias Sir,

Quoted 28 lines · Matthias Brugger
Quoted 18 lines · Roger Lu

In MediaTek HW design, svs and thermal both use the same clk source. It means that svs clk reference count from CCF includes thermal control counts. That makes svs driver confuse whether it disabled svs's main clk or not from CCF's perspective and lead to turn off their shared clk unexpectedly. Therefore, we add svs clk control APIs to make sure svs's main clk is controlled well by svs driver itself.

Here is a NG example. Rely on CCF's reference count and cause problem.

thermal probe (clk ref = 1)
-> svs probe (clk ref = 2)

     -> svs suspend (clk ref = 1)
        -> thermal suspend (clk ref = 0)
        -> thermal resume (clk ref = 1)
     -> svs resume (encounter error, clk ref = 1)
     -> svs suspend (clk ref = 0)
        -> thermal suspend (Fail here, thermal HW control w/o clk)
Quoted 3 lines
Fixes a825d72f74a3 ("soc: mediatek: fix missing clk_disable_unprepare() on

err in svs_resume()")

That looks wrong. Although I don't out of my mind, there should be a way to tell
the clock framework that this clock is shared between several devices.

Quoted 7 lines
Quoted 3 lines

I wonder if using clk_enable and clk_disable in svs_resume/suspend wouldn't be
enough.

Oh yes, Common Clock Framework (CCF) knows the clock shared between several devices and maintains clock "on/off" by reference count.

The thing is if you use clk_prepare_enable then the clock framework check's if the clock is already prepared, which could happen like you described in the svs_resume (encount error) case in the commit message. The question is, can't we just use clk_enable and clk_disable in resume/suspend and only prepare the clock in the probe function?

Quoted 5 lines

We concern how to stop running svs_suspend() when svs clk is already disabled by svs_resume(). Take an example as below, if we refers to __clk_is_enabled() result for knowing svs clk status, it will return "true" all the time because thermal clk is still on. This causes the problem mentioned in commit message.

I would expect that the kernel takes care that we can't enter a resume path for a device before the suspend path has finished. Honestly I don't really understand the problem here. It seems something different then what you described in the commit message.

Please help me understand better.

谢谢,再见

Matthias

Quoted 13 lines

static int svs_suspend(struct device *dev)
{
...

	if (!__clk_is_enabled(svsp->main_clk)) //always get `true`
		return 0;

...
}

Quoted 3 lines

Regards,
Matthias

... [snip] ...

#15 lore raw

Re: [PATCH v4 05/14] soc: mediatek: mtk-svs: use svs clk control APIs

Hi Matthias Sir,

Quoted 1 line · Matthias Brugger

你好,

I got shock and thought someone used your name to reply. However, your email account helps me clear my mind. Haha.. Nice and warm to see mandarin on patchwork. It's so fresh and exciting :-).

Quoted 44 lines · Roger Lu (陸瑞傑)
Quoted 33 lines

Hi Matthias Sir,

Quoted 30 lines · Matthias Brugger
Quoted 18 lines · Roger Lu

In MediaTek HW design, svs and thermal both use the same clk source. It means that svs clk reference count from CCF includes thermal control counts. That makes svs driver confuse whether it disabled svs's main clk or not from CCF's perspective and lead to turn off their shared clk unexpectedly. Therefore, we add svs clk control APIs to make sure svs's main clk is controlled well by svs driver itself.

Here is a NG example. Rely on CCF's reference count and cause problem.

thermal probe (clk ref = 1)
-> svs probe (clk ref = 2)

     -> svs suspend (clk ref = 1)
        -> thermal suspend (clk ref = 0)
        -> thermal resume (clk ref = 1)
     -> svs resume (encounter error, clk ref = 1)
     -> svs suspend (clk ref = 0)
        -> thermal suspend (Fail here, thermal HW control w/o clk)
Quoted 4 lines
Fixes a825d72f74a3 ("soc: mediatek: fix missing clk_disable_unprepare()

on
err in svs_resume()")

That looks wrong. Although I don't out of my mind, there should be a way to
tell
the clock framework that this clock is shared between several devices.

Quoted 8 lines
Quoted 4 lines

I wonder if using clk_enable and clk_disable in svs_resume/suspend wouldn't
be
enough.

Oh yes, Common Clock Framework (CCF) knows the clock shared between several devices and maintains clock "on/off" by reference count.

Quoted 8 lines

The thing is if you use clk_prepare_enable then the clock framework check's if
the clock is already prepared, which could happen like you described in the svs_resume (encount error) case in the commit message. The question is, can't we
just use clk_enable and clk_disable in resume/suspend and only prepare the clock
in the probe function?

We'll think if this can fix the problem. Thanks for the advice very much.

Quoted 10 lines
Quoted 9 lines

We concern how to stop running svs_suspend() when svs clk is already disabled by
svs_resume(). Take an example as below, if we refers to __clk_is_enabled() result for knowing svs clk status, it will return "true" all the time because
thermal clk is still on. This causes the problem mentioned in commit message.

Quoted 7 lines

I would expect that the kernel takes care that we can't enter a resume path for
a device before the suspend path has finished. Honestly I don't really understand the problem here. It seems something different then what you described in the commit message.

Please help me understand better.

I see. This patch title needs to be changed to "avoid turning off svs clk twice unexpectedly" for pointing out the problem precisely. We saw a loophole that svs clk might be turned off in svs_resume() first and in svs_suspend() again without enabling svs clk during these the process. Therefore, we try to fix it by this patch. Below is our thinking process to explain how we got here.

1. (abandoned) We add __clk_is_enabled() check in svs_suspend() to prevent svs clk from being turned off twice when svs_resume() turned off svs clk in the error-handling process. Nonetheless, we met the NG case in the commit message.
2. (current patch) We add svs clk control hint to understand if we need to run svs_suspend() or not if svs_resume() turned off svs clk before.

Quoted 2 lines

谢谢,再见

:-)

Sincerely,
Roger Lu

maintainer
#16 lore raw

Re: [PATCH v4 05/14] soc: mediatek: mtk-svs: use svs clk control APIs

Quoted 10 lines · Roger Lu (陸瑞傑)

Hi Matthias Sir,

Quoted 1 line · Matthias Brugger

你好,

I got shock and thought someone used your name to reply. However, your email account helps me clear my mind. Haha.. Nice and warm to see mandarin on patchwork. It's so fresh and exciting :-).

谢谢。 I'm learning mainland Chinese for a few month now, I also learned that you use different symbols in Taiwan, which I don't know. 对不起。

Quoted 79 lines
Quoted 44 lines · Roger Lu (陸瑞傑)
Quoted 33 lines

Hi Matthias Sir,

Quoted 30 lines · Matthias Brugger
Quoted 18 lines · Roger Lu

In MediaTek HW design, svs and thermal both use the same clk source. It means that svs clk reference count from CCF includes thermal control counts. That makes svs driver confuse whether it disabled svs's main clk or not from CCF's perspective and lead to turn off their shared clk unexpectedly. Therefore, we add svs clk control APIs to make sure svs's main clk is controlled well by svs driver itself.

Here is a NG example. Rely on CCF's reference count and cause problem.

thermal probe (clk ref = 1)
-> svs probe (clk ref = 2)

      -> svs suspend (clk ref = 1)
         -> thermal suspend (clk ref = 0)
         -> thermal resume (clk ref = 1)
      -> svs resume (encounter error, clk ref = 1)
      -> svs suspend (clk ref = 0)
         -> thermal suspend (Fail here, thermal HW control w/o clk)
Quoted 4 lines
Fixes a825d72f74a3 ("soc: mediatek: fix missing clk_disable_unprepare()

on
err in svs_resume()")

That looks wrong. Although I don't out of my mind, there should be a way to
tell
the clock framework that this clock is shared between several devices.

Quoted 8 lines
Quoted 4 lines

I wonder if using clk_enable and clk_disable in svs_resume/suspend wouldn't
be
enough.

Oh yes, Common Clock Framework (CCF) knows the clock shared between several devices and maintains clock "on/off" by reference count.

Quoted 8 lines

The thing is if you use clk_prepare_enable then the clock framework check's if
the clock is already prepared, which could happen like you described in the svs_resume (encount error) case in the commit message. The question is, can't we
just use clk_enable and clk_disable in resume/suspend and only prepare the clock
in the probe function?

We'll think if this can fix the problem. Thanks for the advice very much.

Quoted 10 lines
Quoted 9 lines

We concern how to stop running svs_suspend() when svs clk is already disabled by
svs_resume(). Take an example as below, if we refers to __clk_is_enabled() result for knowing svs clk status, it will return "true" all the time because
thermal clk is still on. This causes the problem mentioned in commit message.

Quoted 7 lines

I would expect that the kernel takes care that we can't enter a resume path for
a device before the suspend path has finished. Honestly I don't really understand the problem here. It seems something different then what you described in the commit message.

Please help me understand better.

I see. This patch title needs to be changed to "avoid turning off svs clk twice unexpectedly" for pointing out the problem precisely. We saw a loophole that svs clk might be turned off in svs_resume() first and in svs_suspend() again without enabling svs clk during these the process. Therefore, we try to fix it by this patch. Below is our thinking process to explain how we got here.

Quoted 6 lines

1. (abandoned) We add __clk_is_enabled() check in svs_suspend() to prevent svs clk from being turned off twice when svs_resume() turned off svs clk in the error-handling process. Nonetheless, we met the NG case in the commit message.
2. (current patch) We add svs clk control hint to understand if we need to run svs_suspend() or not if svs_resume() turned off svs clk before.

Did you had a look on the dev_pm_ops? Maybe we can use suspend_late, resume_early to make sure there is no race condition. I wonder also if we can't make sure that this does not happen using device links. Sorry, I can't give better guidance on how to use this technologies, but I have the feeling we can fix this with existing infrastructure.

再见。

Matthias

Quoted 8 lines
Quoted 2 lines

谢谢,再见

:-)

Sincerely,
Roger Lu

#17 lore raw

Re: [PATCH v4 05/14] soc: mediatek: mtk-svs: use svs clk control APIs

Hi Matthias Sir,

Quoted 14 lines · Matthias Brugger
Quoted 11 lines · Roger Lu (陸瑞傑)

Hi Matthias Sir,

Quoted 1 line · Matthias Brugger

你好,

I got shock and thought someone used your name to reply. However, your email account helps me clear my mind. Haha.. Nice and warm to see mandarin
on patchwork. It's so fresh and exciting :-).

Quoted 3 lines

谢谢。 I'm learning mainland Chinese for a few month now, I also learned that you
use different symbols in Taiwan, which I don't know. 对不起。

Ha. Both symbols are welcome to me. :-)

Quoted 106 lines
Quoted 96 lines
Quoted 52 lines · Roger Lu (陸瑞傑)
Quoted 39 lines

Hi Matthias Sir,

Quoted 36 lines · Matthias Brugger
Quoted 22 lines · Roger Lu

In MediaTek HW design, svs and thermal both use the same clk source. It means that svs clk reference count from CCF includes thermal control
counts. That makes svs driver confuse whether it disabled svs's main clk
or not from CCF's perspective and lead to turn off their shared clk unexpectedly. Therefore, we add svs clk control APIs to make sure svs's
main clk is controlled well by svs driver itself.

Here is a NG example. Rely on CCF's reference count and cause problem.

thermal probe (clk ref = 1)
-> svs probe (clk ref = 2)

      -> svs suspend (clk ref = 1)
         -> thermal suspend (clk ref = 0)
         -> thermal resume (clk ref = 1)
      -> svs resume (encounter error, clk ref = 1)
      -> svs suspend (clk ref = 0)
         -> thermal suspend (Fail here, thermal HW control w/o clk)
Quoted 5 lines
Fixes a825d72f74a3 ("soc: mediatek: fix missing

clk_disable_unprepare()
on
err in svs_resume()")

That looks wrong. Although I don't out of my mind, there should be a way
to
tell
the clock framework that this clock is shared between several devices.

Quoted 9 lines
Quoted 4 lines

I wonder if using clk_enable and clk_disable in svs_resume/suspend wouldn't
be
enough.

Oh yes, Common Clock Framework (CCF) knows the clock shared between several
devices and maintains clock "on/off" by reference count.

Quoted 11 lines

The thing is if you use clk_prepare_enable then the clock framework check's
if
the clock is already prepared, which could happen like you described in the
svs_resume (encount error) case in the commit message. The question is, can't
we
just use clk_enable and clk_disable in resume/suspend and only prepare the clock
in the probe function?

We'll think if this can fix the problem. Thanks for the advice very much.

Quoted 11 lines
Quoted 10 lines

We concern how to stop running svs_suspend() when svs clk is already disabled by
svs_resume(). Take an example as below, if we refers to __clk_is_enabled()
result for knowing svs clk status, it will return "true" all the time because
thermal clk is still on. This causes the problem mentioned in commit message.

Quoted 8 lines

I would expect that the kernel takes care that we can't enter a resume path
for
a device before the suspend path has finished. Honestly I don't really understand the problem here. It seems something different then what you described in the commit message.

Please help me understand better.

I see. This patch title needs to be changed to "avoid turning off svs clk twice
unexpectedly" for pointing out the problem precisely. We saw a loophole that svs
clk might be turned off in svs_resume() first and in svs_suspend() again without
enabling svs clk during these the process. Therefore, we try to fix it by this
patch. Below is our thinking process to explain how we got here.

Quoted 9 lines

1. (abandoned) We add __clk_is_enabled() check in svs_suspend() to prevent svs
clk from being turned off twice when svs_resume() turned off svs clk in the error-handling process. Nonetheless, we met the NG case in the commit message.
2. (current patch) We add svs clk control hint to understand if we need to run
svs_suspend() or not if svs_resume() turned off svs clk before.

Quoted 7 lines

Did you had a look on the dev_pm_ops? Maybe we can use suspend_late, resume_early to make sure there is no race condition. I wonder also if we can't
make sure that this does not happen using device links. Sorry, I can't give better guidance on how to use this technologies, but I have the feeling we can
fix this with existing infrastructure.

No, we didn't look on dev_pm_ops and it seems like another way to fix this issue with __clk_is_enabled() check in svs_suspend(). Thanks for the advice again. we'll keep looking for any possible answers to this issue.

Sincerely,
Roger Lu.

author
#18 lore raw

PATCH v4 6/14 soc: mediatek: mtk-svs: add thermal voltage compensation if needed

In reply to Roger Lu

Some extreme test environment may keep IC temperature very low or very high during system boot stage. For stability concern, we add thermal voltage compenstation if needed no matter svs bank phase is in init02 or mon mode.

---
 drivers/soc/mediatek/mtk-svs.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/soc/mediatek/mtk-svs.c +9 -8
index 830263bad81e..a3c84e819bc5 100644
@@ -590,7 +590,7 @@ static int svs_adjust_pm_opp_volts(struct svs_bank *svsb)
 	}
 
 	/* Get thermal effect */
-	if (svsb->phase == SVSB_PHASE_MON) {
+	if (!IS_ERR_OR_NULL(svsb->tzd)) {
 		ret = thermal_zone_get_temp(svsb->tzd, &tzone_temp);
 		if (ret || (svsb->temp > SVSB_TEMP_UPPER_BOUND &&
 			    svsb->temp < SVSB_TEMP_LOWER_BOUND)) {
@@ -605,7 +605,8 @@ static int svs_adjust_pm_opp_volts(struct svs_bank *svsb)
 			temp_voffset += svsb->tzone_ltemp_voffset;
 
 		/* 2-line bank update all opp volts when running mon mode */
-		if (svsb->type == SVSB_HIGH || svsb->type == SVSB_LOW) {
+		if (svsb->phase == SVSB_PHASE_MON && (svsb->type == SVSB_HIGH ||
+						      svsb->type == SVSB_LOW)) {
 			opp_start = 0;
 			opp_stop = svsb->opp_count;
 		}
@@ -621,11 +622,6 @@ static int svs_adjust_pm_opp_volts(struct svs_bank *svsb)
 			/* do nothing */
 			goto unlock_mutex;
 		case SVSB_PHASE_INIT02:
-			svsb_volt = max(svsb->volt[i], svsb->vmin);
-			opp_volt = svs_bank_volt_to_opp_volt(svsb_volt,
-							     svsb->volt_step,
-							     svsb->volt_base);
-			break;
 		case SVSB_PHASE_MON:
 			svsb_volt = max(svsb->volt[i] + temp_voffset, svsb->vmin);
 			opp_volt = svs_bank_volt_to_opp_volt(svsb_volt,
@@ -1728,7 +1724,7 @@ static int svs_bank_resource_setup(struct svs_platform *svsp)
 			}
 		}
 
-		if (svsb->mode_support & SVSB_MODE_MON) {
+		if (!IS_ERR_OR_NULL(svsb->tzone_name)) {
 			svsb->tzd = thermal_zone_get_zone_by_name(svsb->tzone_name);
 			if (IS_ERR(svsb->tzd)) {
 				dev_err(svsb->dev, "cannot get \"%s\" thermal zone\n",
@@ -2201,6 +2197,7 @@ static struct svs_bank svs_mt8192_banks[] = {
 		.type			= SVSB_LOW,
 		.set_freq_pct		= svs_set_bank_freq_pct_v3,
 		.get_volts		= svs_get_bank_volts_v3,
+		.tzone_name		= "gpu1",
 		.volt_flags		= SVSB_REMOVE_DVTFIXED_VOLT,
 		.mode_support		= SVSB_MODE_INIT02,
 		.opp_count		= MAX_OPP_ENTRIES,
@@ -2218,6 +2215,10 @@ static struct svs_bank svs_mt8192_banks[] = {
 		.core_sel		= 0x0fff0100,
 		.int_st			= BIT(0),
 		.ctl0			= 0x00540003,
+		.tzone_htemp		= 85000,
+		.tzone_htemp_voffset	= 0,
+		.tzone_ltemp		= 25000,
+		.tzone_ltemp_voffset	= 7,
 	},
 	{
 		.sw_id			= SVSB_GPU,
Signature · 1 line
2.18.0
author
#19 lore raw

PATCH v4 7/14 soc: mediatek: mtk-svs: keep svs alive if CONFIG_DEBUG_FS not supported

In reply to Roger Lu

Some projects might not support CONFIG_DEBUG_FS but still needs svs to be alive. Therefore, enclose debug cmd codes with CONFIG_DEBUG_FS to make sure svs can be alive when CONFIG_DEBUG_FS not supported.

---
 drivers/soc/mediatek/mtk-svs.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/soc/mediatek/mtk-svs.c +6 -0
index a3c84e819bc5..70ca9c9acae0 100644
@@ -138,6 +138,7 @@
 
 static DEFINE_SPINLOCK(svs_lock);
 
+#ifdef CONFIG_DEBUG_FS
 #define debug_fops_ro(name)						\
 	static int svs_##name##_debug_open(struct inode *inode,		\
 					   struct file *filp)		\
@@ -170,6 +171,7 @@ static DEFINE_SPINLOCK(svs_lock);
 	}
 
 #define svs_dentry_data(name)	{__stringify(name), &svs_##name##_debug_fops}
+#endif
 
 /**
  * enum svsb_phase - svs bank phase enumeration
@@ -652,6 +654,7 @@ static int svs_adjust_pm_opp_volts(struct svs_bank *svsb)
 	return ret;
 }
 
+#ifdef CONFIG_DEBUG_FS
 static int svs_dump_debug_show(struct seq_file *m, void *p)
 {
 	struct svs_platform *svsp = (struct svs_platform *)m->private;
@@ -867,6 +870,7 @@ static int svs_create_debug_cmds(struct svs_platform *svsp)
 
 	return 0;
 }
+#endif /* CONFIG_DEBUG_FS */
 
 static u32 interpolate(u32 f0, u32 f1, u32 v0, u32 v1, u32 fx)
 {
@@ -2476,11 +2480,13 @@ static int svs_probe(struct platform_device *pdev)
 		goto svs_probe_iounmap;
 	}
 
+#ifdef CONFIG_DEBUG_FS
 	ret = svs_create_debug_cmds(svsp);
 	if (ret) {
 		dev_err(svsp->dev, "svs create debug cmds fail: %d\n", ret);
 		goto svs_probe_iounmap;
 	}
+#endif
 
 	return 0;
 
Signature · 1 line
2.18.0
maintainer Applied
#20 lore raw

Re: [PATCH v4 07/14] soc: mediatek: mtk-svs: keep svs alive if CONFIG_DEBUG_FS not supported

Quoted 5 lines · Roger Lu

Some projects might not support CONFIG_DEBUG_FS but still needs svs to be alive. Therefore, enclose debug cmd codes with CONFIG_DEBUG_FS to make sure svs can be alive when CONFIG_DEBUG_FS not supported.

Applied, thanks!

Quoted 54 lines
---
  drivers/soc/mediatek/mtk-svs.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/soc/mediatek/mtk-svs.c +6 -0
index a3c84e819bc5..70ca9c9acae0 100644
@@ -138,6 +138,7 @@
 
  static DEFINE_SPINLOCK(svs_lock);
 
+#ifdef CONFIG_DEBUG_FS
  #define debug_fops_ro(name)						\
  	static int svs_##name##_debug_open(struct inode *inode,		\
  					   struct file *filp)		\
@@ -170,6 +171,7 @@ static DEFINE_SPINLOCK(svs_lock);
  	}
 
  #define svs_dentry_data(name)	{__stringify(name), &svs_##name##_debug_fops}
+#endif
 
  /**
   * enum svsb_phase - svs bank phase enumeration
@@ -652,6 +654,7 @@ static int svs_adjust_pm_opp_volts(struct svs_bank *svsb)
  	return ret;
  }
 
+#ifdef CONFIG_DEBUG_FS
  static int svs_dump_debug_show(struct seq_file *m, void *p)
  {
  	struct svs_platform *svsp = (struct svs_platform *)m->private;
@@ -867,6 +870,7 @@ static int svs_create_debug_cmds(struct svs_platform *svsp)
 
  	return 0;
  }
+#endif /* CONFIG_DEBUG_FS */
 
  static u32 interpolate(u32 f0, u32 f1, u32 v0, u32 v1, u32 fx)
  {
@@ -2476,11 +2480,13 @@ static int svs_probe(struct platform_device *pdev)
  		goto svs_probe_iounmap;
  	}
 
+#ifdef CONFIG_DEBUG_FS
  	ret = svs_create_debug_cmds(svsp);
  	if (ret) {
  		dev_err(svsp->dev, "svs create debug cmds fail: %d\n", ret);
  		goto svs_probe_iounmap;
  	}
+#endif
 
  	return 0;
 
author
#21 lore raw

PATCH v4 8/14 soc: mediatek: mtk-svs: clean up platform probing

In reply to Roger Lu

From: Matthias Brugger <[email protected]>

We only ever call the SoC specific probe function from svs_platform_probe. No need to carry that function in a global datastructure around.

---
 drivers/soc/mediatek/mtk-svs.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/soc/mediatek/mtk-svs.c +1 -4
index 70ca9c9acae0..41c0ac5ed8d3 100644
@@ -321,7 +321,6 @@ static const u32 svs_regs_v2[] = {
  * @banks: svs banks that svs platform supports
  * @rst: svs platform reset control
  * @efuse_parsing: svs platform efuse parsing function pointer
- * @probe: svs platform probe function pointer
  * @efuse_max: total number of svs efuse
  * @tefuse_max: total number of thermal efuse
  * @regs: svs platform registers map
@@ -339,7 +338,6 @@ struct svs_platform {
 	struct svs_bank *banks;
 	struct reset_control *rst;
 	bool (*efuse_parsing)(struct svs_platform *svsp);
-	int (*probe)(struct svs_platform *svsp);
 	size_t efuse_max;
 	size_t tefuse_max;
 	const u32 *regs;
@@ -2409,11 +2407,10 @@ static struct svs_platform *svs_platform_probe(struct platform_device *pdev)
 	svsp->name = svsp_data->name;
 	svsp->banks = svsp_data->banks;
 	svsp->efuse_parsing = svsp_data->efuse_parsing;
-	svsp->probe = svsp_data->probe;
 	svsp->regs = svsp_data->regs;
 	svsp->bank_max = svsp_data->bank_max;
 
-	ret = svsp->probe(svsp);
+	ret = svsp_data->probe(svsp);
 	if (ret)
 		return ERR_PTR(ret);
 
Signature · 1 line
2.18.0
maintainer Applied
#22 lore raw

Re: [PATCH v4 08/14] soc: mediatek: mtk-svs: clean up platform probing

Quoted 9 lines · Roger Lu

From: Matthias Brugger <[email protected]>

We only ever call the SoC specific probe function from svs_platform_probe. No need to carry that function in a global datastructure around.

Applied, thanks!

Quoted 37 lines
---
  drivers/soc/mediatek/mtk-svs.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
drivers/soc/mediatek/mtk-svs.c +1 -4
index 70ca9c9acae0..41c0ac5ed8d3 100644
@@ -321,7 +321,6 @@ static const u32 svs_regs_v2[] = {
   * @banks: svs banks that svs platform supports
   * @rst: svs platform reset control
   * @efuse_parsing: svs platform efuse parsing function pointer
- * @probe: svs platform probe function pointer
   * @efuse_max: total number of svs efuse
   * @tefuse_max: total number of thermal efuse
   * @regs: svs platform registers map
@@ -339,7 +338,6 @@ struct svs_platform {
  	struct svs_bank *banks;
  	struct reset_control *rst;
  	bool (*efuse_parsing)(struct svs_platform *svsp);
-	int (*probe)(struct svs_platform *svsp);
  	size_t efuse_max;
  	size_t tefuse_max;
  	const u32 *regs;
@@ -2409,11 +2407,10 @@ static struct svs_platform *svs_platform_probe(struct platform_device *pdev)
  	svsp->name = svsp_data->name;
  	svsp->banks = svsp_data->banks;
  	svsp->efuse_parsing = svsp_data->efuse_parsing;
-	svsp->probe = svsp_data->probe;
  	svsp->regs = svsp_data->regs;
  	svsp->bank_max = svsp_data->bank_max;
 
-	ret = svsp->probe(svsp);
+	ret = svsp_data->probe(svsp);
  	if (ret)
  		return ERR_PTR(ret);
 
author
#23 lore raw

PATCH v4 9/14 soc: mediatek: mtk-svs: improve readability of platform_probe

In reply to Roger Lu

From: Matthias Brugger <[email protected]>

If a compatible misses a match data entry, then something is wrong in the development phase, we don't need to check for that at runtime.

---
 drivers/soc/mediatek/mtk-svs.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/soc/mediatek/mtk-svs.c +0 -4
index 41c0ac5ed8d3..354582825082 100644
@@ -2394,10 +2394,6 @@ static struct svs_platform *svs_platform_probe(struct platform_device *pdev)
 	int ret;
 
 	svsp_data = of_device_get_match_data(&pdev->dev);
-	if (!svsp_data) {
-		dev_err(&pdev->dev, "no svs platform data?\n");
-		return ERR_PTR(-EPERM);
-	}
 
 	svsp = devm_kzalloc(&pdev->dev, sizeof(*svsp), GFP_KERNEL);
 	if (!svsp)
Signature · 1 line
2.18.0
maintainer Applied
#24 lore raw

Re: [PATCH v4 09/14] soc: mediatek: mtk-svs: improve readability of platform_probe

Quoted 8 lines · Roger Lu

From: Matthias Brugger <[email protected]>

If a compatible misses a match data entry, then something is wrong in the development phase, we don't need to check for that at runtime.

Applied, thanks!

Quoted 19 lines
---
  drivers/soc/mediatek/mtk-svs.c | 4 ----
  1 file changed, 4 deletions(-)
drivers/soc/mediatek/mtk-svs.c +0 -4
index 41c0ac5ed8d3..354582825082 100644
@@ -2394,10 +2394,6 @@ static struct svs_platform *svs_platform_probe(struct platform_device *pdev)
  	int ret;
 
  	svsp_data = of_device_get_match_data(&pdev->dev);
-	if (!svsp_data) {
-		dev_err(&pdev->dev, "no svs platform data?\n");
-		return ERR_PTR(-EPERM);
-	}
 
  	svsp = devm_kzalloc(&pdev->dev, sizeof(*svsp), GFP_KERNEL);
  	if (!svsp)
author
#25 lore raw

PATCH v4 10/14 soc: mediatek: mtk-svs: move svs_platform_probe into probe

In reply to Roger Lu

From: Matthias Brugger <[email protected]>

Moving svs_platform_probe into driver probe function will allow us to reduce svs_platform members. This will be done in a follow-up patch.

---
 drivers/soc/mediatek/mtk-svs.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
drivers/soc/mediatek/mtk-svs.c +4 -16
index 354582825082..9d9210c22289 100644
@@ -2387,17 +2387,17 @@ static const struct of_device_id svs_of_match[] = {
 	},
 };
 
-static struct svs_platform *svs_platform_probe(struct platform_device *pdev)
+static int svs_probe(struct platform_device *pdev)
 {
 	struct svs_platform *svsp;
 	const struct svs_platform_data *svsp_data;
-	int ret;
+	int ret, svsp_irq;
 
 	svsp_data = of_device_get_match_data(&pdev->dev);
 
 	svsp = devm_kzalloc(&pdev->dev, sizeof(*svsp), GFP_KERNEL);
 	if (!svsp)
-		return ERR_PTR(-ENOMEM);
+		return -ENOMEM;
 
 	svsp->dev = &pdev->dev;
 	svsp->name = svsp_data->name;
@@ -2408,19 +2408,7 @@ static struct svs_platform *svs_platform_probe(struct platform_device *pdev)
 
 	ret = svsp_data->probe(svsp);
 	if (ret)
-		return ERR_PTR(ret);
-
-	return svsp;
-}
-
-static int svs_probe(struct platform_device *pdev)
-{
-	struct svs_platform *svsp;
-	int svsp_irq, ret;
-
-	svsp = svs_platform_probe(pdev);
-	if (IS_ERR(svsp))
-		return PTR_ERR(svsp);
+		return ret;
 
 	if (!svs_is_efuse_data_correct(svsp)) {
 		dev_notice(svsp->dev, "efuse data isn't correct\n");
Signature · 1 line
2.18.0
maintainer Applied
#26 lore raw

Re: [PATCH v4 10/14] soc: mediatek: mtk-svs: move svs_platform_probe into probe

Quoted 8 lines · Roger Lu

From: Matthias Brugger <[email protected]>

Moving svs_platform_probe into driver probe function will allow us to reduce svs_platform members. This will be done in a follow-up patch.

Applied, thanks!

Quoted 50 lines
---
  drivers/soc/mediatek/mtk-svs.c | 20 ++++----------------
  1 file changed, 4 insertions(+), 16 deletions(-)
drivers/soc/mediatek/mtk-svs.c +4 -16
index 354582825082..9d9210c22289 100644
@@ -2387,17 +2387,17 @@ static const struct of_device_id svs_of_match[] = {
  	},
  };
 
-static struct svs_platform *svs_platform_probe(struct platform_device *pdev)
+static int svs_probe(struct platform_device *pdev)
  {
  	struct svs_platform *svsp;
  	const struct svs_platform_data *svsp_data;
-	int ret;
+	int ret, svsp_irq;
 
  	svsp_data = of_device_get_match_data(&pdev->dev);
 
  	svsp = devm_kzalloc(&pdev->dev, sizeof(*svsp), GFP_KERNEL);
  	if (!svsp)
-		return ERR_PTR(-ENOMEM);
+		return -ENOMEM;
 
  	svsp->dev = &pdev->dev;
  	svsp->name = svsp_data->name;
@@ -2408,19 +2408,7 @@ static struct svs_platform *svs_platform_probe(struct platform_device *pdev)
 
  	ret = svsp_data->probe(svsp);
  	if (ret)
-		return ERR_PTR(ret);
-
-	return svsp;
-}
-
-static int svs_probe(struct platform_device *pdev)
-{
-	struct svs_platform *svsp;
-	int svsp_irq, ret;
-
-	svsp = svs_platform_probe(pdev);
-	if (IS_ERR(svsp))
-		return PTR_ERR(svsp);
+		return ret;
 
  	if (!svs_is_efuse_data_correct(svsp)) {
  		dev_notice(svsp->dev, "efuse data isn't correct\n");
author
#27 lore raw

PATCH v4 11/14 soc: mediatek: mtk-svs: delete superfluous platform data entries

In reply to Roger Lu

From: Matthias Brugger <[email protected]>

The platform name and efuse parsing function pointer are only used while probing the device. Use them from the svs_platform_data struct instead.

---
 drivers/soc/mediatek/mtk-svs.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/soc/mediatek/mtk-svs.c +12 -10
index 9d9210c22289..bd23d1111d7b 100644
@@ -313,14 +313,12 @@ static const u32 svs_regs_v2[] = {
 
 /**
  * struct svs_platform - svs platform control
- * @name: svs platform name
  * @base: svs platform register base
  * @dev: svs platform device
  * @main_clk: main clock for svs bank
  * @pbank: svs bank pointer needing to be protected by spin_lock section
  * @banks: svs banks that svs platform supports
  * @rst: svs platform reset control
- * @efuse_parsing: svs platform efuse parsing function pointer
  * @efuse_max: total number of svs efuse
  * @tefuse_max: total number of thermal efuse
  * @regs: svs platform registers map
@@ -330,14 +328,12 @@ static const u32 svs_regs_v2[] = {
  * @clk_cnt: clock count shows the clk enable/disable times by svs driver
  */
 struct svs_platform {
-	char *name;
 	void __iomem *base;
 	struct device *dev;
 	struct clk *main_clk;
 	struct svs_bank *pbank;
 	struct svs_bank *banks;
 	struct reset_control *rst;
-	bool (*efuse_parsing)(struct svs_platform *svsp);
 	size_t efuse_max;
 	size_t tefuse_max;
 	const u32 *regs;
@@ -2066,7 +2062,7 @@ static bool svs_is_efuse_data_correct(struct svs_platform *svsp)
 	svsp->efuse_max /= sizeof(u32);
 	nvmem_cell_put(cell);
 
-	return svsp->efuse_parsing(svsp);
+	return true;
 }
 
 static struct device *svs_get_subsys_device(struct svs_platform *svsp,
@@ -2400,9 +2396,7 @@ static int svs_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	svsp->dev = &pdev->dev;
-	svsp->name = svsp_data->name;
 	svsp->banks = svsp_data->banks;
-	svsp->efuse_parsing = svsp_data->efuse_parsing;
 	svsp->regs = svsp_data->regs;
 	svsp->bank_max = svsp_data->bank_max;
 
@@ -2413,6 +2407,12 @@ static int svs_probe(struct platform_device *pdev)
 	if (!svs_is_efuse_data_correct(svsp)) {
 		dev_notice(svsp->dev, "efuse data isn't correct\n");
 		ret = -EPERM;
+		goto svs_probe_free_efuse;
+	}
+
+	if (!svsp_data->efuse_parsing(svsp)) {
+		dev_err(svsp->dev, "efuse data parsing failed\n");
+		ret = -EPERM;
 		goto svs_probe_free_resource;
 	}
 
@@ -2448,7 +2448,7 @@ static int svs_probe(struct platform_device *pdev)
 	}
 
 	ret = devm_request_threaded_irq(svsp->dev, svsp_irq, NULL, svs_isr,
-					IRQF_ONESHOT, svsp->name, svsp);
+					IRQF_ONESHOT, svsp_data->name, svsp);
 	if (ret) {
 		dev_err(svsp->dev, "register irq(%d) failed: %d\n",
 			svsp_irq, ret);
@@ -2478,11 +2478,13 @@ static int svs_probe(struct platform_device *pdev)
 	svs_clk_disable(svsp);
 
 svs_probe_free_resource:
-	if (!IS_ERR_OR_NULL(svsp->efuse))
-		kfree(svsp->efuse);
 	if (!IS_ERR_OR_NULL(svsp->tefuse))
 		kfree(svsp->tefuse);
 
+svs_probe_free_efuse:
+	if (!IS_ERR_OR_NULL(svsp->efuse))
+		kfree(svsp->efuse);
+
 	return ret;
 }
 
Signature · 1 line
2.18.0
maintainer Applied
#28 lore raw

Re: [PATCH v4 11/14] soc: mediatek: mtk-svs: delete superfluous platform data entries

Quoted 8 lines · Roger Lu

From: Matthias Brugger <[email protected]>

The platform name and efuse parsing function pointer are only used while probing the device. Use them from the svs_platform_data struct instead.

Applied, thanks!

Quoted 95 lines
---
  drivers/soc/mediatek/mtk-svs.c | 22 ++++++++++++----------
  1 file changed, 12 insertions(+), 10 deletions(-)
drivers/soc/mediatek/mtk-svs.c +12 -10
index 9d9210c22289..bd23d1111d7b 100644
@@ -313,14 +313,12 @@ static const u32 svs_regs_v2[] = {
 
  /**
   * struct svs_platform - svs platform control
- * @name: svs platform name
   * @base: svs platform register base
   * @dev: svs platform device
   * @main_clk: main clock for svs bank
   * @pbank: svs bank pointer needing to be protected by spin_lock section
   * @banks: svs banks that svs platform supports
   * @rst: svs platform reset control
- * @efuse_parsing: svs platform efuse parsing function pointer
   * @efuse_max: total number of svs efuse
   * @tefuse_max: total number of thermal efuse
   * @regs: svs platform registers map
@@ -330,14 +328,12 @@ static const u32 svs_regs_v2[] = {
   * @clk_cnt: clock count shows the clk enable/disable times by svs driver
   */
  struct svs_platform {
-	char *name;
  	void __iomem *base;
  	struct device *dev;
  	struct clk *main_clk;
  	struct svs_bank *pbank;
  	struct svs_bank *banks;
  	struct reset_control *rst;
-	bool (*efuse_parsing)(struct svs_platform *svsp);
  	size_t efuse_max;
  	size_t tefuse_max;
  	const u32 *regs;
@@ -2066,7 +2062,7 @@ static bool svs_is_efuse_data_correct(struct svs_platform *svsp)
  	svsp->efuse_max /= sizeof(u32);
  	nvmem_cell_put(cell);
 
-	return svsp->efuse_parsing(svsp);
+	return true;
  }
 
  static struct device *svs_get_subsys_device(struct svs_platform *svsp,
@@ -2400,9 +2396,7 @@ static int svs_probe(struct platform_device *pdev)
  		return -ENOMEM;
 
  	svsp->dev = &pdev->dev;
-	svsp->name = svsp_data->name;
  	svsp->banks = svsp_data->banks;
-	svsp->efuse_parsing = svsp_data->efuse_parsing;
  	svsp->regs = svsp_data->regs;
  	svsp->bank_max = svsp_data->bank_max;
 
@@ -2413,6 +2407,12 @@ static int svs_probe(struct platform_device *pdev)
  	if (!svs_is_efuse_data_correct(svsp)) {
  		dev_notice(svsp->dev, "efuse data isn't correct\n");
  		ret = -EPERM;
+		goto svs_probe_free_efuse;
+	}
+
+	if (!svsp_data->efuse_parsing(svsp)) {
+		dev_err(svsp->dev, "efuse data parsing failed\n");
+		ret = -EPERM;
  		goto svs_probe_free_resource;
  	}
 
@@ -2448,7 +2448,7 @@ static int svs_probe(struct platform_device *pdev)
  	}
 
  	ret = devm_request_threaded_irq(svsp->dev, svsp_irq, NULL, svs_isr,
-					IRQF_ONESHOT, svsp->name, svsp);
+					IRQF_ONESHOT, svsp_data->name, svsp);
  	if (ret) {
  		dev_err(svsp->dev, "register irq(%d) failed: %d\n",
  			svsp_irq, ret);
@@ -2478,11 +2478,13 @@ static int svs_probe(struct platform_device *pdev)
  	svs_clk_disable(svsp);
 
  svs_probe_free_resource:
-	if (!IS_ERR_OR_NULL(svsp->efuse))
-		kfree(svsp->efuse);
  	if (!IS_ERR_OR_NULL(svsp->tefuse))
  		kfree(svsp->tefuse);
 
+svs_probe_free_efuse:
+	if (!IS_ERR_OR_NULL(svsp->efuse))
+		kfree(svsp->efuse);
+
  	return ret;
  }
 
author
#29 lore raw

PATCH v4 12/14 soc: mediatek: mtk-svs: use svs get efuse common function

In reply to Roger Lu

SVS might need to read both svs efuse and thermal efuse on the probe flow. Therefore, add a common efuse read function to remove the superfluous codes.

---
 drivers/soc/mediatek/mtk-svs.c | 69 ++++++++++++----------------------
 1 file changed, 24 insertions(+), 45 deletions(-)
drivers/soc/mediatek/mtk-svs.c +24 -45
index bd23d1111d7b..a7f0a6f02d52 100644
@@ -1758,26 +1758,28 @@ static int svs_bank_resource_setup(struct svs_platform *svsp)
 	return 0;
 }
 
-static int svs_thermal_efuse_get_data(struct svs_platform *svsp)
+static int svs_get_efuse_data(struct svs_platform *svsp,
+			      const char *nvmem_cell_name,
+			      u32 **svsp_efuse, size_t *svsp_efuse_max)
 {
 	struct nvmem_cell *cell;
 
-	/* Thermal efuse parsing */
-	cell = nvmem_cell_get(svsp->dev, "t-calibration-data");
+	cell = nvmem_cell_get(svsp->dev, nvmem_cell_name);
 	if (IS_ERR_OR_NULL(cell)) {
-		dev_err(svsp->dev, "no \"t-calibration-data\"? %ld\n", PTR_ERR(cell));
+		dev_err(svsp->dev, "no \"%s\"? %ld\n",
+			nvmem_cell_name, PTR_ERR(cell));
 		return PTR_ERR(cell);
 	}
 
-	svsp->tefuse = nvmem_cell_read(cell, &svsp->tefuse_max);
-	if (IS_ERR(svsp->tefuse)) {
-		dev_err(svsp->dev, "cannot read thermal efuse: %ld\n",
-			PTR_ERR(svsp->tefuse));
+	*svsp_efuse = nvmem_cell_read(cell, svsp_efuse_max);
+	if (IS_ERR(*svsp_efuse)) {
+		dev_err(svsp->dev, "cannot read \"%s\" efuse: %ld\n",
+			nvmem_cell_name, PTR_ERR(*svsp_efuse));
 		nvmem_cell_put(cell);
-		return PTR_ERR(svsp->tefuse);
+		return PTR_ERR(*svsp_efuse);
 	}
 
-	svsp->tefuse_max /= sizeof(u32);
+	*svsp_efuse_max /= sizeof(u32);
 	nvmem_cell_put(cell);
 
 	return 0;
@@ -1825,7 +1827,8 @@ static bool svs_mt8192_efuse_parsing(struct svs_platform *svsp)
 		svsb->vmax += svsb->dvt_fixed;
 	}
 
-	ret = svs_thermal_efuse_get_data(svsp);
+	ret = svs_get_efuse_data(svsp, "t-calibration-data",
+				 &svsp->tefuse, &svsp->tefuse_max);
 	if (ret)
 		return false;
 
@@ -1930,7 +1933,8 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
 		}
 	}
 
-	ret = svs_thermal_efuse_get_data(svsp);
+	ret = svs_get_efuse_data(svsp, "t-calibration-data",
+				 &svsp->tefuse, &svsp->tefuse_max);
 	if (ret)
 		return false;
 
@@ -2039,32 +2043,6 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
 	return true;
 }
 
-static bool svs_is_efuse_data_correct(struct svs_platform *svsp)
-{
-	struct nvmem_cell *cell;
-
-	/* Get svs efuse by nvmem */
-	cell = nvmem_cell_get(svsp->dev, "svs-calibration-data");
-	if (IS_ERR(cell)) {
-		dev_err(svsp->dev, "no \"svs-calibration-data\"? %ld\n",
-			PTR_ERR(cell));
-		return false;
-	}
-
-	svsp->efuse = nvmem_cell_read(cell, &svsp->efuse_max);
-	if (IS_ERR(svsp->efuse)) {
-		dev_err(svsp->dev, "cannot read svs efuse: %ld\n",
-			PTR_ERR(svsp->efuse));
-		nvmem_cell_put(cell);
-		return false;
-	}
-
-	svsp->efuse_max /= sizeof(u32);
-	nvmem_cell_put(cell);
-
-	return true;
-}
-
 static struct device *svs_get_subsys_device(struct svs_platform *svsp,
 					    const char *node_name)
 {
@@ -2404,8 +2382,9 @@ static int svs_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	if (!svs_is_efuse_data_correct(svsp)) {
-		dev_notice(svsp->dev, "efuse data isn't correct\n");
+	ret = svs_get_efuse_data(svsp, "svs-calibration-data",
+				 &svsp->efuse, &svsp->efuse_max);
+	if (ret) {
 		ret = -EPERM;
 		goto svs_probe_free_efuse;
 	}
@@ -2413,13 +2392,13 @@ static int svs_probe(struct platform_device *pdev)
 	if (!svsp_data->efuse_parsing(svsp)) {
 		dev_err(svsp->dev, "efuse data parsing failed\n");
 		ret = -EPERM;
-		goto svs_probe_free_resource;
+		goto svs_probe_free_tefuse;
 	}
 
 	ret = svs_bank_resource_setup(svsp);
 	if (ret) {
 		dev_err(svsp->dev, "svs bank resource setup fail: %d\n", ret);
-		goto svs_probe_free_resource;
+		goto svs_probe_free_tefuse;
 	}
 
 	svsp->main_clk = devm_clk_get(svsp->dev, "main");
@@ -2427,12 +2406,12 @@ static int svs_probe(struct platform_device *pdev)
 		dev_err(svsp->dev, "failed to get clock: %ld\n",
 			PTR_ERR(svsp->main_clk));
 		ret = PTR_ERR(svsp->main_clk);
-		goto svs_probe_free_resource;
+		goto svs_probe_free_tefuse;
 	}
 
 	ret = svs_clk_enable(svsp);
 	if (ret)
-		goto svs_probe_free_resource;
+		goto svs_probe_free_tefuse;
 
 	svsp->base = of_iomap(svsp->dev->of_node, 0);
 	if (IS_ERR_OR_NULL(svsp->base)) {
@@ -2477,7 +2456,7 @@ static int svs_probe(struct platform_device *pdev)
 svs_probe_clk_disable:
 	svs_clk_disable(svsp);
 
-svs_probe_free_resource:
+svs_probe_free_tefuse:
 	if (!IS_ERR_OR_NULL(svsp->tefuse))
 		kfree(svsp->tefuse);
 
Signature · 1 line
2.18.0
maintainer Reviewed-by on v4 12/14
#30 lore raw

Re: [PATCH v4 12/14] soc: mediatek: mtk-svs: use svs get efuse common function

Quoted 5 lines · Roger Lu

SVS might need to read both svs efuse and thermal efuse on the probe flow. Therefore, add a common efuse read function to remove the superfluous codes.

Looks good to me, could you please rebase.

Quoted 152 lines
---
  drivers/soc/mediatek/mtk-svs.c | 69 ++++++++++++----------------------
  1 file changed, 24 insertions(+), 45 deletions(-)
drivers/soc/mediatek/mtk-svs.c +24 -45
index bd23d1111d7b..a7f0a6f02d52 100644
@@ -1758,26 +1758,28 @@ static int svs_bank_resource_setup(struct svs_platform *svsp)
  	return 0;
  }
 
-static int svs_thermal_efuse_get_data(struct svs_platform *svsp)
+static int svs_get_efuse_data(struct svs_platform *svsp,
+			      const char *nvmem_cell_name,
+			      u32 **svsp_efuse, size_t *svsp_efuse_max)
  {
  	struct nvmem_cell *cell;
 
-	/* Thermal efuse parsing */
-	cell = nvmem_cell_get(svsp->dev, "t-calibration-data");
+	cell = nvmem_cell_get(svsp->dev, nvmem_cell_name);
  	if (IS_ERR_OR_NULL(cell)) {
-		dev_err(svsp->dev, "no \"t-calibration-data\"? %ld\n", PTR_ERR(cell));
+		dev_err(svsp->dev, "no \"%s\"? %ld\n",
+			nvmem_cell_name, PTR_ERR(cell));
  		return PTR_ERR(cell);
  	}
 
-	svsp->tefuse = nvmem_cell_read(cell, &svsp->tefuse_max);
-	if (IS_ERR(svsp->tefuse)) {
-		dev_err(svsp->dev, "cannot read thermal efuse: %ld\n",
-			PTR_ERR(svsp->tefuse));
+	*svsp_efuse = nvmem_cell_read(cell, svsp_efuse_max);
+	if (IS_ERR(*svsp_efuse)) {
+		dev_err(svsp->dev, "cannot read \"%s\" efuse: %ld\n",
+			nvmem_cell_name, PTR_ERR(*svsp_efuse));
  		nvmem_cell_put(cell);
-		return PTR_ERR(svsp->tefuse);
+		return PTR_ERR(*svsp_efuse);
  	}
 
-	svsp->tefuse_max /= sizeof(u32);
+	*svsp_efuse_max /= sizeof(u32);
  	nvmem_cell_put(cell);
 
  	return 0;
@@ -1825,7 +1827,8 @@ static bool svs_mt8192_efuse_parsing(struct svs_platform *svsp)
  		svsb->vmax += svsb->dvt_fixed;
  	}
 
-	ret = svs_thermal_efuse_get_data(svsp);
+	ret = svs_get_efuse_data(svsp, "t-calibration-data",
+				 &svsp->tefuse, &svsp->tefuse_max);
  	if (ret)
  		return false;
 
@@ -1930,7 +1933,8 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
  		}
  	}
 
-	ret = svs_thermal_efuse_get_data(svsp);
+	ret = svs_get_efuse_data(svsp, "t-calibration-data",
+				 &svsp->tefuse, &svsp->tefuse_max);
  	if (ret)
  		return false;
 
@@ -2039,32 +2043,6 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
  	return true;
  }
 
-static bool svs_is_efuse_data_correct(struct svs_platform *svsp)
-{
-	struct nvmem_cell *cell;
-
-	/* Get svs efuse by nvmem */
-	cell = nvmem_cell_get(svsp->dev, "svs-calibration-data");
-	if (IS_ERR(cell)) {
-		dev_err(svsp->dev, "no \"svs-calibration-data\"? %ld\n",
-			PTR_ERR(cell));
-		return false;
-	}
-
-	svsp->efuse = nvmem_cell_read(cell, &svsp->efuse_max);
-	if (IS_ERR(svsp->efuse)) {
-		dev_err(svsp->dev, "cannot read svs efuse: %ld\n",
-			PTR_ERR(svsp->efuse));
-		nvmem_cell_put(cell);
-		return false;
-	}
-
-	svsp->efuse_max /= sizeof(u32);
-	nvmem_cell_put(cell);
-
-	return true;
-}
-
  static struct device *svs_get_subsys_device(struct svs_platform *svsp,
  					    const char *node_name)
  {
@@ -2404,8 +2382,9 @@ static int svs_probe(struct platform_device *pdev)
  	if (ret)
  		return ret;
 
-	if (!svs_is_efuse_data_correct(svsp)) {
-		dev_notice(svsp->dev, "efuse data isn't correct\n");
+	ret = svs_get_efuse_data(svsp, "svs-calibration-data",
+				 &svsp->efuse, &svsp->efuse_max);
+	if (ret) {
  		ret = -EPERM;
  		goto svs_probe_free_efuse;
  	}
@@ -2413,13 +2392,13 @@ static int svs_probe(struct platform_device *pdev)
  	if (!svsp_data->efuse_parsing(svsp)) {
  		dev_err(svsp->dev, "efuse data parsing failed\n");
  		ret = -EPERM;
-		goto svs_probe_free_resource;
+		goto svs_probe_free_tefuse;
  	}
 
  	ret = svs_bank_resource_setup(svsp);
  	if (ret) {
  		dev_err(svsp->dev, "svs bank resource setup fail: %d\n", ret);
-		goto svs_probe_free_resource;
+		goto svs_probe_free_tefuse;
  	}
 
  	svsp->main_clk = devm_clk_get(svsp->dev, "main");
@@ -2427,12 +2406,12 @@ static int svs_probe(struct platform_device *pdev)
  		dev_err(svsp->dev, "failed to get clock: %ld\n",
  			PTR_ERR(svsp->main_clk));
  		ret = PTR_ERR(svsp->main_clk);
-		goto svs_probe_free_resource;
+		goto svs_probe_free_tefuse;
  	}
 
  	ret = svs_clk_enable(svsp);
  	if (ret)
-		goto svs_probe_free_resource;
+		goto svs_probe_free_tefuse;
 
  	svsp->base = of_iomap(svsp->dev->of_node, 0);
  	if (IS_ERR_OR_NULL(svsp->base)) {
@@ -2477,7 +2456,7 @@ static int svs_probe(struct platform_device *pdev)
  svs_probe_clk_disable:
  	svs_clk_disable(svsp);
 
-svs_probe_free_resource:
+svs_probe_free_tefuse:
  	if (!IS_ERR_OR_NULL(svsp->tefuse))
  		kfree(svsp->tefuse);
 
#31 lore raw

Re: [PATCH v4 12/14] soc: mediatek: mtk-svs: use svs get efuse common function

Hi Matthias Sir,

Quoted 9 lines · Matthias Brugger
Quoted 5 lines · Roger Lu

SVS might need to read both svs efuse and thermal efuse on the probe flow. Therefore, add a common efuse read function to remove the superfluous codes.

Looks good to me, could you please rebase.

No Problem, I'll rebase and resend it. Thanks.

Quoted 2 lines

... [snip] ...

author
#32 lore raw

PATCH v4 13/14 soc: mediatek: mtk-svs: use common function to disable restore voltages

In reply to Roger Lu

The timing of disabling SVS bank and restore default voltage is more than one place. Therefore, add a common function to use for removing the superfluous codes.

---
 drivers/soc/mediatek/mtk-svs.c | 54 ++++++++++++++--------------------
 1 file changed, 22 insertions(+), 32 deletions(-)
drivers/soc/mediatek/mtk-svs.c +22 -32
index a7f0a6f02d52..89117807e85d 100644
@@ -648,6 +648,25 @@ static int svs_adjust_pm_opp_volts(struct svs_bank *svsb)
 	return ret;
 }
 
+static void svs_bank_disable_and_restore_default_volts(struct svs_platform *svsp,
+						       struct svs_bank *svsb)
+{
+	unsigned long flags;
+
+	if (svsb->mode_support == SVSB_MODE_ALL_DISABLE)
+		return;
+
+	spin_lock_irqsave(&svs_lock, flags);
+	svsp->pbank = svsb;
+	svs_switch_bank(svsp);
+	svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN);
+	svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS);
+	spin_unlock_irqrestore(&svs_lock, flags);
+
+	svsb->phase = SVSB_PHASE_ERROR;
+	svs_adjust_pm_opp_volts(svsb);
+}
+
 #ifdef CONFIG_DEBUG_FS
 static int svs_dump_debug_show(struct seq_file *m, void *p)
 {
@@ -724,7 +743,6 @@ static ssize_t svs_enable_debug_write(struct file *filp,
 {
 	struct svs_bank *svsb = file_inode(filp)->i_private;
 	struct svs_platform *svsp = dev_get_drvdata(svsb->dev);
-	unsigned long flags;
 	int enabled, ret;
 	char *buf = NULL;
 
@@ -740,16 +758,8 @@ static ssize_t svs_enable_debug_write(struct file *filp,
 		return ret;
 
 	if (!enabled) {
-		spin_lock_irqsave(&svs_lock, flags);
-		svsp->pbank = svsb;
+		svs_bank_disable_and_restore_default_volts(svsp, svsb);
 		svsb->mode_support = SVSB_MODE_ALL_DISABLE;
-		svs_switch_bank(svsp);
-		svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN);
-		svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS);
-		spin_unlock_irqrestore(&svs_lock, flags);
-
-		svsb->phase = SVSB_PHASE_ERROR;
-		svs_adjust_pm_opp_volts(svsb);
 	}
 
 	kfree(buf);
@@ -1532,16 +1542,7 @@ static int svs_init02(struct svs_platform *svsp)
 out_of_init02:
 	for (idx = 0; idx < svsp->bank_max; idx++) {
 		svsb = &svsp->banks[idx];
-
-		spin_lock_irqsave(&svs_lock, flags);
-		svsp->pbank = svsb;
-		svs_switch_bank(svsp);
-		svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN);
-		svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS);
-		spin_unlock_irqrestore(&svs_lock, flags);
-
-		svsb->phase = SVSB_PHASE_ERROR;
-		svs_adjust_pm_opp_volts(svsb);
+		svs_bank_disable_and_restore_default_volts(svsp, svsb);
 	}
 
 	return ret;
@@ -1587,7 +1588,6 @@ static int svs_suspend(struct device *dev)
 {
 	struct svs_platform *svsp = dev_get_drvdata(dev);
 	struct svs_bank *svsb;
-	unsigned long flags;
 	int ret;
 	u32 idx;
 
@@ -1599,17 +1599,7 @@ static int svs_suspend(struct device *dev)
 
 	for (idx = 0; idx < svsp->bank_max; idx++) {
 		svsb = &svsp->banks[idx];
-
-		/* This might wait for svs_isr() process */
-		spin_lock_irqsave(&svs_lock, flags);
-		svsp->pbank = svsb;
-		svs_switch_bank(svsp);
-		svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN);
-		svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS);
-		spin_unlock_irqrestore(&svs_lock, flags);
-
-		svsb->phase = SVSB_PHASE_ERROR;
-		svs_adjust_pm_opp_volts(svsb);
+		svs_bank_disable_and_restore_default_volts(svsp, svsb);
 	}
 
 	ret = reset_control_assert(svsp->rst);
Signature · 1 line
2.18.0
maintainer Reviewed-by on v4 13/14
#33 lore raw

Re: [PATCH v4 13/14] soc: mediatek: mtk-svs: use common function to disable restore voltages

Quoted 6 lines · Roger Lu

The timing of disabling SVS bank and restore default voltage is more than one place. Therefore, add a common function to use for removing the superfluous codes.

Same here, change looks good. Could you please rebase and resend:

Quoted 105 lines
---
  drivers/soc/mediatek/mtk-svs.c | 54 ++++++++++++++--------------------
  1 file changed, 22 insertions(+), 32 deletions(-)
drivers/soc/mediatek/mtk-svs.c +22 -32
index a7f0a6f02d52..89117807e85d 100644
@@ -648,6 +648,25 @@ static int svs_adjust_pm_opp_volts(struct svs_bank *svsb)
  	return ret;
  }
 
+static void svs_bank_disable_and_restore_default_volts(struct svs_platform *svsp,
+						       struct svs_bank *svsb)
+{
+	unsigned long flags;
+
+	if (svsb->mode_support == SVSB_MODE_ALL_DISABLE)
+		return;
+
+	spin_lock_irqsave(&svs_lock, flags);
+	svsp->pbank = svsb;
+	svs_switch_bank(svsp);
+	svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN);
+	svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS);
+	spin_unlock_irqrestore(&svs_lock, flags);
+
+	svsb->phase = SVSB_PHASE_ERROR;
+	svs_adjust_pm_opp_volts(svsb);
+}
+
  #ifdef CONFIG_DEBUG_FS
  static int svs_dump_debug_show(struct seq_file *m, void *p)
  {
@@ -724,7 +743,6 @@ static ssize_t svs_enable_debug_write(struct file *filp,
  {
  	struct svs_bank *svsb = file_inode(filp)->i_private;
  	struct svs_platform *svsp = dev_get_drvdata(svsb->dev);
-	unsigned long flags;
  	int enabled, ret;
  	char *buf = NULL;
 
@@ -740,16 +758,8 @@ static ssize_t svs_enable_debug_write(struct file *filp,
  		return ret;
 
  	if (!enabled) {
-		spin_lock_irqsave(&svs_lock, flags);
-		svsp->pbank = svsb;
+		svs_bank_disable_and_restore_default_volts(svsp, svsb);
  		svsb->mode_support = SVSB_MODE_ALL_DISABLE;
-		svs_switch_bank(svsp);
-		svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN);
-		svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS);
-		spin_unlock_irqrestore(&svs_lock, flags);
-
-		svsb->phase = SVSB_PHASE_ERROR;
-		svs_adjust_pm_opp_volts(svsb);
  	}
 
  	kfree(buf);
@@ -1532,16 +1542,7 @@ static int svs_init02(struct svs_platform *svsp)
  out_of_init02:
  	for (idx = 0; idx < svsp->bank_max; idx++) {
  		svsb = &svsp->banks[idx];
-
-		spin_lock_irqsave(&svs_lock, flags);
-		svsp->pbank = svsb;
-		svs_switch_bank(svsp);
-		svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN);
-		svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS);
-		spin_unlock_irqrestore(&svs_lock, flags);
-
-		svsb->phase = SVSB_PHASE_ERROR;
-		svs_adjust_pm_opp_volts(svsb);
+		svs_bank_disable_and_restore_default_volts(svsp, svsb);
  	}
 
  	return ret;
@@ -1587,7 +1588,6 @@ static int svs_suspend(struct device *dev)
  {
  	struct svs_platform *svsp = dev_get_drvdata(dev);
  	struct svs_bank *svsb;
-	unsigned long flags;
  	int ret;
  	u32 idx;
 
@@ -1599,17 +1599,7 @@ static int svs_suspend(struct device *dev)
 
  	for (idx = 0; idx < svsp->bank_max; idx++) {
  		svsb = &svsp->banks[idx];
-
-		/* This might wait for svs_isr() process */
-		spin_lock_irqsave(&svs_lock, flags);
-		svsp->pbank = svsb;
-		svs_switch_bank(svsp);
-		svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN);
-		svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS);
-		spin_unlock_irqrestore(&svs_lock, flags);
-
-		svsb->phase = SVSB_PHASE_ERROR;
-		svs_adjust_pm_opp_volts(svsb);
+		svs_bank_disable_and_restore_default_volts(svsp, svsb);
  	}
 
  	ret = reset_control_assert(svsp->rst);
#34 lore raw

Re: [PATCH v4 13/14] soc: mediatek: mtk-svs: use common function to disable restore voltages

Hi Matthias Sir,

Quoted 11 lines · Matthias Brugger
Quoted 7 lines · Roger Lu

The timing of disabling SVS bank and restore default voltage is more than one place. Therefore, add a common function to use for removing the superfluous codes.

Reviewed-by AngeloGioacchino Del Regno <

[email protected]>

Same here, change looks good. Could you please rebase and resend:

No Problem, I'll rebase and resend it. Thanks.

Quoted 2 lines

... [snip] ...

author
#35 lore raw

PATCH v4 14/14 soc: mtk-svs: mt8183: refactor o_slope calculation

In reply to Roger Lu

The o_slope value is dependent of the o_slope_sign, refactor code to get rid of unnecessary if constructs.

---
 drivers/soc/mediatek/mtk-svs.c | 51 +++++++++++++++-------------------
 1 file changed, 22 insertions(+), 29 deletions(-)
drivers/soc/mediatek/mtk-svs.c +22 -29
index 89117807e85d..8cfbf8ffb138 100644
@@ -1944,26 +1944,27 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
 	o_slope_sign = (svsp->tefuse[0] >> 7) & BIT(0);
 
 	ts_id = (svsp->tefuse[1] >> 9) & BIT(0);
-	o_slope = (svsp->tefuse[0] >> 26) & GENMASK(5, 0);
-
-	if (adc_cali_en_t == 1) {
-		if (!ts_id)
-			o_slope = 0;
-
-		if (adc_ge_t < 265 || adc_ge_t > 758 ||
-		    adc_oe_t < 265 || adc_oe_t > 758 ||
-		    o_vtsmcu[0] < -8 || o_vtsmcu[0] > 484 ||
-		    o_vtsmcu[1] < -8 || o_vtsmcu[1] > 484 ||
-		    o_vtsmcu[2] < -8 || o_vtsmcu[2] > 484 ||
-		    o_vtsmcu[3] < -8 || o_vtsmcu[3] > 484 ||
-		    o_vtsmcu[4] < -8 || o_vtsmcu[4] > 484 ||
-		    o_vtsabb < -8 || o_vtsabb > 484 ||
-		    degc_cali < 1 || degc_cali > 63) {
-			dev_err(svsp->dev, "bad thermal efuse, no mon mode\n");
-			goto remove_mt8183_svsb_mon_mode;
-		}
+	if (!ts_id) {
+		o_slope = 1534;
 	} else {
-		dev_err(svsp->dev, "no thermal efuse, no mon mode\n");
+		o_slope = (svsp->tefuse[0] >> 26) & GENMASK(5, 0);
+		if (!o_slope_sign)
+			o_slope = 1534 + o_slope * 10;
+		else
+			o_slope = 1534 - o_slope * 10;
+	}
+
+	if (adc_cali_en_t == 0 ||
+	    adc_ge_t < 265 || adc_ge_t > 758 ||
+	    adc_oe_t < 265 || adc_oe_t > 758 ||
+	    o_vtsmcu[0] < -8 || o_vtsmcu[0] > 484 ||
+	    o_vtsmcu[1] < -8 || o_vtsmcu[1] > 484 ||
+	    o_vtsmcu[2] < -8 || o_vtsmcu[2] > 484 ||
+	    o_vtsmcu[3] < -8 || o_vtsmcu[3] > 484 ||
+	    o_vtsmcu[4] < -8 || o_vtsmcu[4] > 484 ||
+	    o_vtsabb < -8 || o_vtsabb > 484 ||
+	    degc_cali < 1 || degc_cali > 63) {
+		dev_err(svsp->dev, "bad thermal efuse, no mon mode\n");
 		goto remove_mt8183_svsb_mon_mode;
 	}
 
@@ -1982,11 +1983,7 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
 		x_roomt[i] = (((format[i] * 10000) / 4096) * 10000) / gain;
 
 	temp0 = (10000 * 100000 / gain) * 15 / 18;
-
-	if (!o_slope_sign)
-		mts = (temp0 * 10) / (1534 + o_slope * 10);
-	else
-		mts = (temp0 * 10) / (1534 - o_slope * 10);
+	mts = (temp0 * 10) / o_slope;
 
 	for (idx = 0; idx < svsp->bank_max; idx++) {
 		svsb = &svsp->banks[idx];
@@ -2013,11 +2010,7 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
 		temp0 = (degc_cali * 10 / 2);
 		temp1 = ((10000 * 100000 / 4096 / gain) *
 			 oe + tb_roomt * 10) * 15 / 18;
-
-		if (!o_slope_sign)
-			temp2 = temp1 * 100 / (1534 + o_slope * 10);
-		else
-			temp2 = temp1 * 100 / (1534 - o_slope * 10);
+		temp2 = temp1 * 100 / o_slope;
 
 		svsb->bts = (temp0 + temp2 - 250) * 4 / 10;
 	}
Signature · 1 line
2.18.0
maintainer Applied
#36 lore raw

Re: [PATCH v4 14/14] soc: mtk-svs: mt8183: refactor o_slope calculation

Quoted 6 lines · Roger Lu

The o_slope value is dependent of the o_slope_sign, refactor code to get rid of unnecessary if constructs.

Applied, thanks!

Quoted 81 lines
---
  drivers/soc/mediatek/mtk-svs.c | 51 +++++++++++++++-------------------
  1 file changed, 22 insertions(+), 29 deletions(-)
drivers/soc/mediatek/mtk-svs.c +22 -29
index 89117807e85d..8cfbf8ffb138 100644
@@ -1944,26 +1944,27 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
  	o_slope_sign = (svsp->tefuse[0] >> 7) & BIT(0);
 
  	ts_id = (svsp->tefuse[1] >> 9) & BIT(0);
-	o_slope = (svsp->tefuse[0] >> 26) & GENMASK(5, 0);
-
-	if (adc_cali_en_t == 1) {
-		if (!ts_id)
-			o_slope = 0;
-
-		if (adc_ge_t < 265 || adc_ge_t > 758 ||
-		    adc_oe_t < 265 || adc_oe_t > 758 ||
-		    o_vtsmcu[0] < -8 || o_vtsmcu[0] > 484 ||
-		    o_vtsmcu[1] < -8 || o_vtsmcu[1] > 484 ||
-		    o_vtsmcu[2] < -8 || o_vtsmcu[2] > 484 ||
-		    o_vtsmcu[3] < -8 || o_vtsmcu[3] > 484 ||
-		    o_vtsmcu[4] < -8 || o_vtsmcu[4] > 484 ||
-		    o_vtsabb < -8 || o_vtsabb > 484 ||
-		    degc_cali < 1 || degc_cali > 63) {
-			dev_err(svsp->dev, "bad thermal efuse, no mon mode\n");
-			goto remove_mt8183_svsb_mon_mode;
-		}
+	if (!ts_id) {
+		o_slope = 1534;
  	} else {
-		dev_err(svsp->dev, "no thermal efuse, no mon mode\n");
+		o_slope = (svsp->tefuse[0] >> 26) & GENMASK(5, 0);
+		if (!o_slope_sign)
+			o_slope = 1534 + o_slope * 10;
+		else
+			o_slope = 1534 - o_slope * 10;
+	}
+
+	if (adc_cali_en_t == 0 ||
+	    adc_ge_t < 265 || adc_ge_t > 758 ||
+	    adc_oe_t < 265 || adc_oe_t > 758 ||
+	    o_vtsmcu[0] < -8 || o_vtsmcu[0] > 484 ||
+	    o_vtsmcu[1] < -8 || o_vtsmcu[1] > 484 ||
+	    o_vtsmcu[2] < -8 || o_vtsmcu[2] > 484 ||
+	    o_vtsmcu[3] < -8 || o_vtsmcu[3] > 484 ||
+	    o_vtsmcu[4] < -8 || o_vtsmcu[4] > 484 ||
+	    o_vtsabb < -8 || o_vtsabb > 484 ||
+	    degc_cali < 1 || degc_cali > 63) {
+		dev_err(svsp->dev, "bad thermal efuse, no mon mode\n");
  		goto remove_mt8183_svsb_mon_mode;
  	}
 
@@ -1982,11 +1983,7 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
  		x_roomt[i] = (((format[i] * 10000) / 4096) * 10000) / gain;
 
  	temp0 = (10000 * 100000 / gain) * 15 / 18;
-
-	if (!o_slope_sign)
-		mts = (temp0 * 10) / (1534 + o_slope * 10);
-	else
-		mts = (temp0 * 10) / (1534 - o_slope * 10);
+	mts = (temp0 * 10) / o_slope;
 
  	for (idx = 0; idx < svsp->bank_max; idx++) {
  		svsb = &svsp->banks[idx];
@@ -2013,11 +2010,7 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
  		temp0 = (degc_cali * 10 / 2);
  		temp1 = ((10000 * 100000 / 4096 / gain) *
  			 oe + tb_roomt * 10) * 15 / 18;
-
-		if (!o_slope_sign)
-			temp2 = temp1 * 100 / (1534 + o_slope * 10);
-		else
-			temp2 = temp1 * 100 / (1534 - o_slope * 10);
+		temp2 = temp1 * 100 / o_slope;
 
  		svsb->bts = (temp0 + temp2 - 250) * 4 / 10;
  	}