Skip to contentSkip to conversation

Enahance SVS's robustness

PATCH Superseded Roger Lu 2 participants 22 messages Dec 26, 2022 – Jan 10, 2023 Arm MediaTek

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
author
#7 lore raw

PATCH 7/13 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 477f5bd1e1d1..2c1fbf11b554 100644
@@ -1897,26 +1897,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;
 	}
 
@@ -1935,11 +1936,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];
@@ -1966,11 +1963,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
author
#19 lore raw

PATCH 13/13 soc: mediatek: mtk-svs: keep svs alive even though debug cmd create fail

In reply to Roger Lu

Some projects might not support DEBUG_FS but still needs svs to be supported. Therefore, keep svs alive even though debug cmd create fail.

---
 drivers/soc/mediatek/mtk-svs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/soc/mediatek/mtk-svs.c +1 -3
index af3a12e29e78..c780a115543e 100644
@@ -2390,10 +2390,8 @@ static int svs_probe(struct platform_device *pdev)
 	}
 
 	ret = svs_create_debug_cmds(svsp);
-	if (ret) {
+	if (ret)
 		dev_err(svsp->dev, "svs create debug cmds fail: %d\n", ret);
-		goto svs_probe_iounmap;
-	}
 
 	return 0;
 
Signature · 1 line
2.18.0
author
#1 lore raw

PATCH 1/13 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
---
 drivers/soc/mediatek/mtk-svs.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/soc/mediatek/mtk-svs.c +14 -14
index 0469c9dfeb04..91e06f43969d 100644
@@ -2379,20 +2379,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",
@@ -2414,6 +2400,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

Roger Lu

author
#0 lore raw

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.

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 (7):
soc: mediatek: mtk-svs: use svs get efuse common function
soc: mtk-svs: mt8183: refactor o_slope calculation
soc: mediatek: mtk-svs: add main_clk check during system-wide suspend
soc: mediatek: mtk-svs: use common function to disable restore
voltages
soc: mediatek: mtk-svs: restore default voltages when svs init02 fail
soc: mediatek: mtk-svs: add thermal voltage compensation if needed
soc: mediatek: mtk-svs: keep svs alive even though debug cmd create
fail

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

    svs_init01()
 drivers/soc/mediatek/mtk-svs.c | 279 +++++++++++++++------------------
 1 file changed, 124 insertions(+), 155 deletions(-)
author
#3 lore raw

PATCH 3/13 soc: mediatek: mtk-svs: improve readability of platform_probe

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 38dcee9c9c04..63ad9160a305 100644
@@ -2332,10 +2332,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
author
#6 lore raw

PATCH 6/13 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 5c9ca373e646..477f5bd1e1d1 100644
@@ -1701,26 +1701,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;
@@ -1768,7 +1770,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;
 
@@ -1873,7 +1876,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;
 
@@ -1982,32 +1986,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)
 {
@@ -2342,8 +2320,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;
 	}
@@ -2351,13 +2330,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");
@@ -2365,13 +2344,13 @@ 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 = clk_prepare_enable(svsp->main_clk);
 	if (ret) {
 		dev_err(svsp->dev, "cannot enable main clk: %d\n", ret);
-		goto svs_probe_free_resource;
+		goto svs_probe_free_tefuse;
 	}
 
 	svsp->base = of_iomap(svsp->dev->of_node, 0);
@@ -2415,7 +2394,7 @@ static int svs_probe(struct platform_device *pdev)
 svs_probe_clk_disable:
 	clk_disable_unprepare(svsp->main_clk);
 
-svs_probe_free_resource:
+svs_probe_free_tefuse:
 	if (!IS_ERR_OR_NULL(svsp->tefuse))
 		kfree(svsp->tefuse);
 
Signature · 1 line
2.18.0
author
#10 lore raw

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

In reply to Roger Lu

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

---
 drivers/soc/mediatek/mtk-svs.c | 44 +++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 22 deletions(-)
drivers/soc/mediatek/mtk-svs.c +22 -22
index 934e7ea976b0..c4b36c908eda 100644
@@ -623,6 +623,26 @@ 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;
+
+	/* This spinlock 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);
+}
+
 static int svs_dump_debug_show(struct seq_file *m, void *p)
 {
 	struct svs_platform *svsp = (struct svs_platform *)m->private;
@@ -698,7 +718,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;
 
@@ -714,16 +733,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);
@@ -1540,7 +1551,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;
 
@@ -1549,17 +1559,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
author
#17 lore raw

PATCH 12/13 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 dacfee4a0b32..af3a12e29e78 100644
@@ -1326,7 +1326,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
author
#12 lore raw

PATCH 10/13 soc: mediatek: mtk-svs: restore default voltages when svs init02 fail

In reply to 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.

---
 drivers/soc/mediatek/mtk-svs.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/soc/mediatek/mtk-svs.c +13 -2
index c4b36c908eda..3a2be5ced8e6 100644
@@ -1467,6 +1467,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++) {
@@ -1485,7 +1486,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;
 		}
 	}
 
@@ -1503,12 +1505,21 @@ 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];
+		svs_bank_disable_and_restore_default_volts(svsp, svsb);
+	}
+
+	return ret;
 }
 
 static void svs_mon_mode(struct svs_platform *svsp)
Signature · 1 line
2.18.0
author
#15 lore raw

PATCH 11/13 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 3a2be5ced8e6..dacfee4a0b32 100644
@@ -557,7 +557,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)) {
@@ -572,7 +572,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;
 		}
@@ -588,11 +589,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,
@@ -1680,7 +1676,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",
@@ -2124,6 +2120,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,
@@ -2141,6 +2138,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
#4 lore raw

PATCH 4/13 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 63ad9160a305..24d2d07d2d3d 100644
@@ -2325,17 +2325,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;
@@ -2346,19 +2346,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
author
#9 lore raw

PATCH 8/13 soc: mediatek: mtk-svs: add main_clk check during system-wide suspend

In reply to Roger Lu

SVS's main_clk might be disabled in svs_resume(). Therefore, if main_clk is disabled and svs_suspend() is called by system-wide suspend stage, return 0 directly.

---
 drivers/soc/mediatek/mtk-svs.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/soc/mediatek/mtk-svs.c +4 -0
index 2c1fbf11b554..934e7ea976b0 100644
@@ -6,6 +6,7 @@
 #include <linux/bitfield.h>
 #include <linux/bits.h>
 #include <linux/clk.h>
+#include <linux/clk-provider.h>
 #include <linux/completion.h>
 #include <linux/cpuidle.h>
 #include <linux/debugfs.h>
@@ -1543,6 +1544,9 @@ static int svs_suspend(struct device *dev)
 	int ret;
 	u32 idx;
 
+	if (!__clk_is_enabled(svsp->main_clk))
+		return 0;
+
 	for (idx = 0; idx < svsp->bank_max; idx++) {
 		svsb = &svsp->banks[idx];
 
Signature · 1 line
2.18.0
author
#2 lore raw

PATCH 2/13 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 91e06f43969d..38dcee9c9c04 100644
@@ -319,7 +319,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
@@ -336,7 +335,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;
@@ -2347,11 +2345,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
author
#5 lore raw

PATCH 5/13 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 24d2d07d2d3d..5c9ca373e646 100644
@@ -311,14 +311,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
@@ -327,14 +325,12 @@ static const u32 svs_regs_v2[] = {
  * @tefuse: thermal efuse data received from NVMEM framework
  */
 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;
@@ -2009,7 +2005,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,
@@ -2338,9 +2334,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;
 
@@ -2351,6 +2345,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;
 	}
 
@@ -2388,7 +2388,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);
@@ -2416,11 +2416,13 @@ static int svs_probe(struct platform_device *pdev)
 	clk_disable_unprepare(svsp->main_clk);
 
 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 Reviewed-by on v1 12/13
#18 lore raw

Re: [PATCH v1 12/13] soc: mediatek: mtk-svs: Use pm_runtime_resume_and_get() in svs_init01()

In reply to Roger Lu

Il 26/12/22 10:42, Roger Lu ha scritto:

Quoted 10 lines

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")
maintainer Reviewed-by on v1 11/13
#16 lore raw

Re: [PATCH v1 11/13] soc: mediatek: mtk-svs: add thermal voltage compensation if needed

In reply to Roger Lu

Il 26/12/22 10:42, Roger Lu ha scritto:

Quoted 5 lines

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.

maintainer Reviewed-by on v1 9/13
#11 lore raw

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

In reply to Roger Lu

Il 26/12/22 10:42, Roger Lu ha scritto:

Quoted 4 lines

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

maintainer Reviewed-by on v1 7/13
#8 lore raw

Re: [PATCH v1 07/13] soc: mtk-svs: mt8183: refactor o_slope calculation

In reply to Roger Lu

Il 26/12/22 10:42, Roger Lu ha scritto:

Quoted 5 lines

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

#13 lore raw

Re: [PATCH v1 10/13] soc: mediatek: mtk-svs: restore default voltages when svs init02 fail

In reply to Roger Lu

Il 26/12/22 10:42, Roger Lu ha scritto:

Quoted 5 lines

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.

This needs a Fixes tag... and it also needs to apply to older kernels, as MT8183 does use SVS in previous versions.

Perhaps you can send a different patch, without the cleanups, only for the backport?
Otherwise you'll have to duplicate svs_bank_disable_and_restore_default_volts() again before cleaning up...

I'll leave the choice to you.

Regards,
Angelo

#20 lore raw

Re: [PATCH v1 13/13] soc: mediatek: mtk-svs: keep svs alive even though debug cmd create fail

In reply to Roger Lu

Il 26/12/22 10:42, Roger Lu ha scritto:

Quoted 13 lines

Some projects might not support DEBUG_FS but still needs svs to be supported. Therefore, keep svs alive even though debug cmd create fail.

---
  drivers/soc/mediatek/mtk-svs.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
drivers/soc/mediatek/mtk-svs.c +0 -0
index af3a12e29e78..c780a115543e 100644

drivers/soc/mediatek/mtk-svs.c static int svs_probe(struct platform_device *pdev) · line 2391

Quoted 2 lines
drivers/soc/mediatek/mtk-svs.c +0 -0
@@ -2390,10 +2390,8 @@ static int svs_probe(struct platform_device *pdev)
  	}
 

Instead of ignoring a planned failure, it's sensible to not fail at all:
enclose this call and the svs_create_debug_cmds() function in an ifdef.

#ifdef CONFIG_DEBUG_FS

drivers/soc/mediatek/mtk-svs.c static int svs_probe(struct platform_device *pdev) · line 2396

Quoted 6 lines
drivers/soc/mediatek/mtk-svs.c +1 -3
  	ret = svs_create_debug_cmds(svsp);
-	if (ret) {
+	if (ret)
  		dev_err(svsp->dev, "svs create debug cmds fail: %d\n", ret);
-		goto svs_probe_iounmap;
-	}

#endif

drivers/soc/mediatek/mtk-svs.c static int svs_probe(struct platform_device *pdev)

Quoted 4 lines
drivers/soc/mediatek/mtk-svs.c +0 -0
  	return 0;
 
 

Regards,
Angelo

#14 lore raw

Re: [PATCH v1 10/13] soc: mediatek: mtk-svs: restore default voltages when svs init02 fail

In reply to AngeloGioacchino Del Regno

Hi AngeloGioacchino,

Sorry for the late reply and thanks for the advices always.

Quoted 9 lines · AngeloGioacchino Del Regno

Il 26/12/22 10:42, Roger Lu ha scritto:

Quoted 5 lines

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.

This needs a Fixes tag... and it also needs to apply to older kernels, as MT8183 does use SVS in previous versions.

No problem. I'll add a Fixes tag.

Quoted 8 lines

Perhaps you can send a different patch, without the cleanups, only for the backport?
Otherwise you'll have to duplicate svs_bank_disable_and_restore_default_volts()
again before cleaning up...

I'll leave the choice to you.

I'll reorder the patch to put cleanup patches first and fix patches next in the patchset. Thanks for the advice again.

Quoted 3 lines

Regards,
Angelo

#21 lore raw

Re: [PATCH v1 13/13] soc: mediatek: mtk-svs: keep svs alive even though debug cmd create fail

In reply to AngeloGioacchino Del Regno

Hi AngeloGioacchino,

Sorry for the late reply and thanks for the advices always.

Quoted 22 lines · AngeloGioacchino Del Regno

Il 26/12/22 10:42, Roger Lu ha scritto:

Quoted 13 lines

Some projects might not support DEBUG_FS but still needs svs to be supported. Therefore, keep svs alive even though debug cmd create fail.

---
  drivers/soc/mediatek/mtk-svs.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
drivers/soc/mediatek/mtk-svs.c +0 -0
index af3a12e29e78..c780a115543e 100644

drivers/soc/mediatek/mtk-svs.c static int svs_probe(struct platform_device *pdev) · line 2391

Quoted 2 lines
drivers/soc/mediatek/mtk-svs.c +0 -0
@@ -2390,10 +2390,8 @@ static int svs_probe(struct platform_device *pdev)
  	}
 

Instead of ignoring a planned failure, it's sensible to not fail at all:
enclose this call and the svs_create_debug_cmds() function in an ifdef.

#ifdef CONFIG_DEBUG_FS

Quoted 8 lines

drivers/soc/mediatek/mtk-svs.c static int svs_probe(struct platform_device *pdev) · line 2396

Quoted 6 lines
drivers/soc/mediatek/mtk-svs.c +1 -3
  	ret = svs_create_debug_cmds(svsp);
-	if (ret) {
+	if (ret)
  		dev_err(svsp->dev, "svs create debug cmds fail: %d\n", ret);
-		goto svs_probe_iounmap;
-	}

#endif

Okay. I got it and will add ifdef CONFIG_DEBUG_FS in mtk-svs.c to make sure no other side effects.

Quoted 10 lines

drivers/soc/mediatek/mtk-svs.c static int svs_probe(struct platform_device *pdev)

Quoted 5 lines
drivers/soc/mediatek/mtk-svs.c +0 -0
  	return 0;
 
 

Regards,
Angelo