[PATCH v1 02/13] pmdomain: mediatek: Refactor bus protection regmaps retrieval
AngeloGioacchino Del Regno
angelogioacchino.delregno at collabora.com
Mon Jun 30 02:32:45 PDT 2025
Il 27/06/25 14:12, Fei Shao ha scritto:
> On Mon, Jun 23, 2025 at 8:02 PM AngeloGioacchino Del Regno
> <angelogioacchino.delregno at collabora.com> wrote:
>>
>> In preparation to add support for new generation SoCs like MT8196,
>> MT6991 and other variants, which require to set bus protection on
>> different busses than the ones found on legacy chips, and to also
>> simplify and reduce memory footprint of this driver, refactor the
>> mechanism to retrieve and use the bus protection regmaps.
>>
>> This is done by removing the three pointers to struct regmap from
>> struct scpsys_domain (allocated for each power domain) and moving
>> them to the main struct scpsys (allocated per driver instance) as
>> an array of pointers to regmap named **bus_prot.
>>
>> That deprecates the old devicetree properties to grab phandles to
>> the three predefined busses (infracfg, infracfg-nao and smi) and
>> replaces it with a new property "mediatek,bus-protection" that is
>> meant to be an array of phandles holding the same busses where
>> required (for now - for legacy SoCs).
>>
>> The new bus protection phandles are indexed by the bus_prot_index
>> member of struct scpsys, used to map "bus type" (ex.: infra, smi,
>> etc) to the specific *bus_prot[x] element.
>>
>> While the old per-power-domain regmap pointers were removed, the
>> support for old devicetree was retained by still checking if the
>> new property (in DT) and new-style declaration (in SoC specific
>> platform data) are both present at probe time.
>>
>> If those are not present, a lookup for the old properties will be
>> done in all of the children of the power controller, and pointers
>> to regmaps will be retrieved with the old properties, but then
>> will be internally remapped to follow the new style regmap anyway
>> as to let this driver benefit of the memory footprint reduction.
>>
>> Finally, it was necessary to change macros in mtk-pm-domains.h and
>> in mt8365-pm-domains.h to make use of the new style bus protection
>> declaration, as the actual HW block is now recognized not by flags
>> but by its own scpsys_bus_prot_block enumeration.
>>
>> The BUS_PROT_(STA)_COMPONENT_{INFRA,INFRA_NAO,SMI} flags were also
>> removed since they are now unused, and because that enumeration was
>> initially meant to vary the logic of bus protection and not the bus
>> where work is performed, anyway!
>>
>> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno at collabora.com>
>> ---
>
> <snip>
>
>>
>> +static int scpsys_get_bus_protection_legacy(struct device *dev, struct scpsys *scpsys)
>> +{
>> + const u8 bp_blocks[3] = {
>> + BUS_PROT_BLOCK_INFRA, BUS_PROT_BLOCK_SMI, BUS_PROT_BLOCK_INFRA_NAO
>> + };
>> + struct device_node *np = dev->of_node;
>> + struct device_node *node, *smi_np;
>> + int num_regmaps = 0, i, j;
>> + struct regmap *regmap[3];
>> +
>> + /*
>> + * Legacy code retrieves a maximum of three bus protection handles:
>> + * some may be optional, or may not be, so the array of bp blocks
>> + * that is normally passed in as platform data must be dynamically
>> + * built in this case.
>> + *
>> + * Here, try to retrieve all of the regmaps that the legacy code
>> + * supported and then count the number of the ones that are present,
>> + * this makes it then possible to allocate the array of bus_prot
>> + * regmaps and convert all to the new style handling.
>> + */
>> + node = of_find_node_with_property(np, "mediatek,infracfg");
>> + if (node) {
>> + regmap[0] = syscon_regmap_lookup_by_phandle(node, "mediatek,infracfg");
>> + of_node_put(node);
>> + num_regmaps++;
>> + if (IS_ERR(regmap[0]))
>> + return dev_err_probe(dev, PTR_ERR(regmap[0]),
>> + "%pOF: failed to get infracfg regmap\n",
>> + node);
>> + } else {
>> + regmap[0] = NULL;
>> + }
>> +
>> + node = of_find_node_with_property(np, "mediatek,smi");
>> + if (node) {
>> + smi_np = of_parse_phandle(node, "mediatek,smi", 0);
>> + of_node_put(node);
>> + if (!smi_np)
>> + return -ENODEV;
>> +
>> + regmap[1] = device_node_to_regmap(smi_np);
>> + num_regmaps++;
>> + of_node_put(smi_np);
>> + if (IS_ERR(regmap[1]))
>> + return dev_err_probe(dev, PTR_ERR(regmap[1]),
>> + "%pOF: failed to get SMI regmap\n",
>> + node);
>> + } else {
>> + regmap[1] = NULL;
>> + }
>> +
>> + node = of_find_node_with_property(np, "mediatek,infracfg-nao");
>> + if (node) {
>> + regmap[2] = syscon_regmap_lookup_by_phandle(node, "mediatek,infracfg-nao");
>> + num_regmaps++;
>> + of_node_put(node);
>> + if (IS_ERR(regmap[2]))
>> + return dev_err_probe(dev, PTR_ERR(regmap[2]),
>> + "%pOF: failed to get infracfg regmap\n",
>> + node);
>> + } else {
>> + regmap[2] = NULL;
>> + }
>> +
>> + scpsys->bus_prot = devm_kmalloc_array(dev, num_regmaps,
>> + sizeof(*scpsys->bus_prot), GFP_KERNEL);
>> + if (!scpsys->bus_prot)
>> + return -ENOMEM;
>> +
>> + for (i = 0, j = 0; i < num_regmaps; i++) {
>
> Did you mean BUS_PROT_BLOCK_COUNT?
> Consider a case where only regmap[2] is configured.
>
Yep. None of the many platforms that we have tested hit this issue, but it's as
bad as it sounds! :')
Thanks for spotting this one!
Cheers,
Angelo
> Regards,
> Fei
>
>> + enum scpsys_bus_prot_block bp_type;
>> +
>> + if (!regmap[i])
>> + continue;
>> +
>> + bp_type = bp_blocks[i];
>> + scpsys->bus_prot_index[bp_type] = j;
>> + scpsys->bus_prot[j] = regmap[i];
>> +
>> + j++;
>> + }
>> +
>> + return 0;
>> +}
>> +
>
> <snip>
More information about the Linux-mediatek
mailing list