Skip to content

Commit 9f195f3

Browse files
mtk-rogerlumbgg
authored andcommitted
soc: mediatek: mtk-svs: use svs get efuse common function
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. Signed-off-by: Roger Lu <roger.lu@mediatek.com> Link: https://lore.kernel.org/r/20230202124104.16504-2-roger.lu@mediatek.com Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
1 parent fe15c26 commit 9f195f3

1 file changed

Lines changed: 25 additions & 46 deletions

File tree

drivers/soc/mediatek/mtk-svs.c

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,26 +1729,28 @@ static int svs_bank_resource_setup(struct svs_platform *svsp)
17291729
return 0;
17301730
}
17311731

1732-
static int svs_thermal_efuse_get_data(struct svs_platform *svsp)
1732+
static int svs_get_efuse_data(struct svs_platform *svsp,
1733+
const char *nvmem_cell_name,
1734+
u32 **svsp_efuse, size_t *svsp_efuse_max)
17331735
{
17341736
struct nvmem_cell *cell;
17351737

1736-
/* Thermal efuse parsing */
1737-
cell = nvmem_cell_get(svsp->dev, "t-calibration-data");
1738+
cell = nvmem_cell_get(svsp->dev, nvmem_cell_name);
17381739
if (IS_ERR_OR_NULL(cell)) {
1739-
dev_err(svsp->dev, "no \"t-calibration-data\"? %ld\n", PTR_ERR(cell));
1740+
dev_err(svsp->dev, "no \"%s\"? %ld\n",
1741+
nvmem_cell_name, PTR_ERR(cell));
17401742
return PTR_ERR(cell);
17411743
}
17421744

1743-
svsp->tefuse = nvmem_cell_read(cell, &svsp->tefuse_max);
1744-
if (IS_ERR(svsp->tefuse)) {
1745-
dev_err(svsp->dev, "cannot read thermal efuse: %ld\n",
1746-
PTR_ERR(svsp->tefuse));
1745+
*svsp_efuse = nvmem_cell_read(cell, svsp_efuse_max);
1746+
if (IS_ERR(*svsp_efuse)) {
1747+
dev_err(svsp->dev, "cannot read \"%s\" efuse: %ld\n",
1748+
nvmem_cell_name, PTR_ERR(*svsp_efuse));
17471749
nvmem_cell_put(cell);
1748-
return PTR_ERR(svsp->tefuse);
1750+
return PTR_ERR(*svsp_efuse);
17491751
}
17501752

1751-
svsp->tefuse_max /= sizeof(u32);
1753+
*svsp_efuse_max /= sizeof(u32);
17521754
nvmem_cell_put(cell);
17531755

17541756
return 0;
@@ -1796,7 +1798,8 @@ static bool svs_mt8192_efuse_parsing(struct svs_platform *svsp)
17961798
svsb->vmax += svsb->dvt_fixed;
17971799
}
17981800

1799-
ret = svs_thermal_efuse_get_data(svsp);
1801+
ret = svs_get_efuse_data(svsp, "t-calibration-data",
1802+
&svsp->tefuse, &svsp->tefuse_max);
18001803
if (ret)
18011804
return false;
18021805

@@ -1901,7 +1904,8 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
19011904
}
19021905
}
19031906

1904-
ret = svs_thermal_efuse_get_data(svsp);
1907+
ret = svs_get_efuse_data(svsp, "t-calibration-data",
1908+
&svsp->tefuse, &svsp->tefuse_max);
19051909
if (ret)
19061910
return false;
19071911

@@ -2003,32 +2007,6 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
20032007
return true;
20042008
}
20052009

2006-
static bool svs_is_efuse_data_correct(struct svs_platform *svsp)
2007-
{
2008-
struct nvmem_cell *cell;
2009-
2010-
/* Get svs efuse by nvmem */
2011-
cell = nvmem_cell_get(svsp->dev, "svs-calibration-data");
2012-
if (IS_ERR(cell)) {
2013-
dev_err(svsp->dev, "no \"svs-calibration-data\"? %ld\n",
2014-
PTR_ERR(cell));
2015-
return false;
2016-
}
2017-
2018-
svsp->efuse = nvmem_cell_read(cell, &svsp->efuse_max);
2019-
if (IS_ERR(svsp->efuse)) {
2020-
dev_err(svsp->dev, "cannot read svs efuse: %ld\n",
2021-
PTR_ERR(svsp->efuse));
2022-
nvmem_cell_put(cell);
2023-
return false;
2024-
}
2025-
2026-
svsp->efuse_max /= sizeof(u32);
2027-
nvmem_cell_put(cell);
2028-
2029-
return true;
2030-
}
2031-
20322010
static struct device *svs_get_subsys_device(struct svs_platform *svsp,
20332011
const char *node_name)
20342012
{
@@ -2364,42 +2342,43 @@ static int svs_probe(struct platform_device *pdev)
23642342
if (ret)
23652343
return ret;
23662344

2367-
if (!svs_is_efuse_data_correct(svsp)) {
2368-
dev_notice(svsp->dev, "efuse data isn't correct\n");
2345+
ret = svs_get_efuse_data(svsp, "svs-calibration-data",
2346+
&svsp->efuse, &svsp->efuse_max);
2347+
if (ret) {
23692348
ret = -EPERM;
23702349
goto svs_probe_free_efuse;
23712350
}
23722351

23732352
if (!svsp_data->efuse_parsing(svsp)) {
23742353
dev_err(svsp->dev, "efuse data parsing failed\n");
23752354
ret = -EPERM;
2376-
goto svs_probe_free_resource;
2355+
goto svs_probe_free_tefuse;
23772356
}
23782357

23792358
ret = svs_bank_resource_setup(svsp);
23802359
if (ret) {
23812360
dev_err(svsp->dev, "svs bank resource setup fail: %d\n", ret);
2382-
goto svs_probe_free_resource;
2361+
goto svs_probe_free_tefuse;
23832362
}
23842363

23852364
svsp_irq = platform_get_irq(pdev, 0);
23862365
if (svsp_irq < 0) {
23872366
ret = svsp_irq;
2388-
goto svs_probe_free_resource;
2367+
goto svs_probe_free_tefuse;
23892368
}
23902369

23912370
svsp->main_clk = devm_clk_get(svsp->dev, "main");
23922371
if (IS_ERR(svsp->main_clk)) {
23932372
dev_err(svsp->dev, "failed to get clock: %ld\n",
23942373
PTR_ERR(svsp->main_clk));
23952374
ret = PTR_ERR(svsp->main_clk);
2396-
goto svs_probe_free_resource;
2375+
goto svs_probe_free_tefuse;
23972376
}
23982377

23992378
ret = clk_prepare_enable(svsp->main_clk);
24002379
if (ret) {
24012380
dev_err(svsp->dev, "cannot enable main clk: %d\n", ret);
2402-
goto svs_probe_free_resource;
2381+
goto svs_probe_free_tefuse;
24032382
}
24042383

24052384
svsp->base = of_iomap(svsp->dev->of_node, 0);
@@ -2439,7 +2418,7 @@ static int svs_probe(struct platform_device *pdev)
24392418
svs_probe_clk_disable:
24402419
clk_disable_unprepare(svsp->main_clk);
24412420

2442-
svs_probe_free_resource:
2421+
svs_probe_free_tefuse:
24432422
if (!IS_ERR_OR_NULL(svsp->tefuse))
24442423
kfree(svsp->tefuse);
24452424

0 commit comments

Comments
 (0)