soc: mediatek: mtk-svs: Build bank name string dynamically

In svs_bank_resource_setup() there is a "big" switch assigning different
names depending on sw_id and type and this will surely grow: for example
MT8186 has got a two-line type (high/low) SVS bank for CPU_BIG, and this
would require more switch nesting.

Simplify all of this by changing that to a devm_kasprintf() call that
will concatenate the SW_ID string (e.g. SVSB_CPU_LITTLE) with the Type
string (e.g. _LOW), resulting in the expected full bank name (e.g.
SVSB_CPU_LITTLE_LOW).

This being a dynamic allocation can be slower, but this happens only
once in the life of this driver and it's not a performance path, so it's
totally acceptable.

Link: https://lore.kernel.org/r/20231121125044.78642-5-angelogioacchino.delregno@collabora.comSigned-off-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
parent 259919b3
...@@ -332,6 +332,14 @@ static const u32 svs_regs_v2[] = { ...@@ -332,6 +332,14 @@ static const u32 svs_regs_v2[] = {
[THSLPEVEB] = 0x330, [THSLPEVEB] = 0x330,
}; };
static const char * const svs_swid_names[SVSB_SWID_MAX] = {
"SVSB_CPU_LITTLE", "SVSB_CPU_BIG", "SVSB_CCI", "SVSB_GPU"
};
static const char * const svs_type_names[SVSB_TYPE_MAX] = {
"", "_LOW", "_HIGH"
};
/** /**
* struct svs_platform - svs platform control * struct svs_platform - svs platform control
* @base: svs platform register base * @base: svs platform register base
...@@ -1696,34 +1704,21 @@ static int svs_bank_resource_setup(struct svs_platform *svsp) ...@@ -1696,34 +1704,21 @@ static int svs_bank_resource_setup(struct svs_platform *svsp)
for (idx = 0; idx < svsp->bank_max; idx++) { for (idx = 0; idx < svsp->bank_max; idx++) {
svsb = &svsp->banks[idx]; svsb = &svsp->banks[idx];
switch (svsb->sw_id) { if (svsb->sw_id >= SVSB_SWID_MAX || svsb->type >= SVSB_TYPE_MAX) {
case SVSB_SWID_CPU_LITTLE: dev_err(svsb->dev, "unknown bank sw_id or type\n");
svsb->name = "SVSB_CPU_LITTLE";
break;
case SVSB_SWID_CPU_BIG:
svsb->name = "SVSB_CPU_BIG";
break;
case SVSB_SWID_CCI:
svsb->name = "SVSB_CCI";
break;
case SVSB_SWID_GPU:
if (svsb->type == SVSB_TYPE_HIGH)
svsb->name = "SVSB_GPU_HIGH";
else if (svsb->type == SVSB_TYPE_LOW)
svsb->name = "SVSB_GPU_LOW";
else
svsb->name = "SVSB_GPU";
break;
default:
dev_err(svsb->dev, "unknown sw_id: %u\n", svsb->sw_id);
return -EINVAL; return -EINVAL;
} }
svsb->dev = devm_kzalloc(svsp->dev, sizeof(*svsb->dev), svsb->dev = devm_kzalloc(svsp->dev, sizeof(*svsb->dev), GFP_KERNEL);
GFP_KERNEL);
if (!svsb->dev) if (!svsb->dev)
return -ENOMEM; return -ENOMEM;
svsb->name = devm_kasprintf(svsp->dev, GFP_KERNEL, "%s%s",
svs_swid_names[svsb->sw_id],
svs_type_names[svsb->type]);
if (!svsb->name)
return -ENOMEM;
ret = dev_set_name(svsb->dev, "%s", svsb->name); ret = dev_set_name(svsb->dev, "%s", svsb->name);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment