soc: mediatek: mtk-svs: Commonize t-calibration-data fuse array read
authorAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Thu, 25 Aug 2022 18:46:15 +0000 (14:46 -0400)
committerMatthias Brugger <matthias.bgg@gmail.com>
Fri, 26 Aug 2022 15:32:12 +0000 (17:32 +0200)
Commonize the repeating pattern for reading the "t-calibration-data"
efuse data in a new function svs_thermal_efuse_get_data(), reducing
the size of this driver.

No functional changes.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: NĂ­colas F. R. A. Prado <nfraprado@collabora.com>
Link: https://lore.kernel.org/r/20220825184616.2118870-2-nfraprado@collabora.com
Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
drivers/soc/mediatek/mtk-svs.c

index d96b9d3f3a8300e8c22265eb3b81d6090ede57b5..63253e22abdd73ad562eeff08084e5853f464ba1 100644 (file)
@@ -1641,11 +1641,36 @@ static int svs_bank_resource_setup(struct svs_platform *svsp)
        return 0;
 }
 
+static int svs_thermal_efuse_get_data(struct svs_platform *svsp)
+{
+       struct nvmem_cell *cell;
+
+       /* Thermal efuse parsing */
+       cell = nvmem_cell_get(svsp->dev, "t-calibration-data");
+       if (IS_ERR_OR_NULL(cell)) {
+               dev_err(svsp->dev, "no \"t-calibration-data\"? %ld\n", 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));
+               nvmem_cell_put(cell);
+               return PTR_ERR(svsp->tefuse);
+       }
+
+       svsp->tefuse_max /= sizeof(u32);
+       nvmem_cell_put(cell);
+
+       return 0;
+}
+
 static bool svs_mt8192_efuse_parsing(struct svs_platform *svsp)
 {
        struct svs_bank *svsb;
-       struct nvmem_cell *cell;
        u32 idx, i, vmin, golden_temp;
+       int ret;
 
        for (i = 0; i < svsp->efuse_max; i++)
                if (svsp->efuse[i])
@@ -1683,24 +1708,9 @@ static bool svs_mt8192_efuse_parsing(struct svs_platform *svsp)
                svsb->vmax += svsb->dvt_fixed;
        }
 
-       /* Thermal efuse parsing */
-       cell = nvmem_cell_get(svsp->dev, "t-calibration-data");
-       if (IS_ERR_OR_NULL(cell)) {
-               dev_err(svsp->dev, "no \"t-calibration-data\"? %ld\n",
-                       PTR_ERR(cell));
-               return false;
-       }
-
-       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));
-               nvmem_cell_put(cell);
+       ret = svs_thermal_efuse_get_data(svsp);
+       if (ret)
                return false;
-       }
-
-       svsp->tefuse_max /= sizeof(u32);
-       nvmem_cell_put(cell);
 
        for (i = 0; i < svsp->tefuse_max; i++)
                if (svsp->tefuse[i] != 0)
@@ -1723,11 +1733,11 @@ static bool svs_mt8192_efuse_parsing(struct svs_platform *svsp)
 static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
 {
        struct svs_bank *svsb;
-       struct nvmem_cell *cell;
        int format[6], x_roomt[6], o_vtsmcu[5], o_vtsabb, tb_roomt = 0;
        int adc_ge_t, adc_oe_t, ge, oe, gain, degc_cali, adc_cali_en_t;
        int o_slope, o_slope_sign, ts_id;
        u32 idx, i, ft_pgm, mts, temp0, temp1, temp2;
+       int ret;
 
        for (i = 0; i < svsp->efuse_max; i++)
                if (svsp->efuse[i])
@@ -1803,24 +1813,9 @@ static bool svs_mt8183_efuse_parsing(struct svs_platform *svsp)
                }
        }
 
-       /* Get thermal efuse by nvmem */
-       cell = nvmem_cell_get(svsp->dev, "t-calibration-data");
-       if (IS_ERR(cell)) {
-               dev_err(svsp->dev, "no \"t-calibration-data\"? %ld\n",
-                       PTR_ERR(cell));
-               goto remove_mt8183_svsb_mon_mode;
-       }
-
-       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));
-               nvmem_cell_put(cell);
-               goto remove_mt8183_svsb_mon_mode;
-       }
-
-       svsp->tefuse_max /= sizeof(u32);
-       nvmem_cell_put(cell);
+       ret = svs_thermal_efuse_get_data(svsp);
+       if (ret)
+               return false;
 
        /* Thermal efuse parsing */
        adc_ge_t = (svsp->tefuse[1] >> 22) & GENMASK(9, 0);