From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: Fei Shao <fshao@chromium.org>
Cc: linux-mediatek@lists.infradead.org, robh@kernel.org,
krzk+dt@kernel.org, conor+dt@kernel.org, matthias.bgg@gmail.com,
ulf.hansson@linaro.org, y.oudjana@protonmail.com,
wenst@chromium.org, lihongbo22@huawei.com,
mandyjh.liu@mediatek.com, mbrugger@suse.com,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org,
kernel@collabora.com
Subject: Re: [PATCH v1 02/13] pmdomain: mediatek: Refactor bus protection regmaps retrieval
Date: Mon, 30 Jun 2025 11:32:45 +0200 [thread overview]
Message-ID: <e958afe7-b338-47dc-905e-f3223b4f3cdb@collabora.com> (raw)
In-Reply-To: <CAC=S1njT6ygGuZDPU5KDW94Nu-TbM21DM-6HdR7Pio=WTD_eQA@mail.gmail.com>
Il 27/06/25 14:12, Fei Shao ha scritto:
> On Mon, Jun 23, 2025 at 8:02 PM AngeloGioacchino Del Regno
> <angelogioacchino.delregno@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@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>
next prev parent reply other threads:[~2025-06-30 9:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-23 12:01 [PATCH v1 00/13] pmdomain: Partial refactor, add MT8196 support AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 01/13] dt-bindings: power: mediatek: Document mediatek,bus-protection AngeloGioacchino Del Regno
2025-06-27 20:15 ` Rob Herring
2025-06-30 9:36 ` AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 02/13] pmdomain: mediatek: Refactor bus protection regmaps retrieval AngeloGioacchino Del Regno
2025-06-27 12:12 ` Fei Shao
2025-06-30 9:32 ` AngeloGioacchino Del Regno [this message]
2025-06-23 12:01 ` [PATCH v1 03/13] pmdomain: mediatek: Handle SoCs with inverted SRAM power-down bits AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 04/13] pmdomain: mediatek: Move ctl sequences out of power_on/off functions AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 05/13] pmdomain: mediatek: Add support for modem power sequences AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 06/13] pmdomain: mediatek: Add support for RTFF Hardware in MT8196/MT6991 AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 07/13] pmdomain: mediatek: Add support for Hardware Voter power domains AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 08/13] pmdomain: mediatek: Add support for secure HWCCF infra power on AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 09/13] pmdomain: mediatek: Convert all SoCs to new style regmap retrieval AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 10/13] arm64: dts: mediatek: Convert all SoCs to use mediatek,bus-protection AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 11/13] dt-bindings: power: Add support for MT8196 power controllers AngeloGioacchino Del Regno
2025-06-30 22:09 ` Rob Herring (Arm)
2025-06-23 12:01 ` [PATCH v1 12/13] pmdomain: mediatek: Add support for MT8196 SCPSYS power domains AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 13/13] pmdomain: mediatek: Add support for MT8196 HFRPSYS " AngeloGioacchino Del Regno
2025-06-24 14:24 ` [PATCH v1 00/13] pmdomain: Partial refactor, add MT8196 support Nícolas F. R. A. Prado
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e958afe7-b338-47dc-905e-f3223b4f3cdb@collabora.com \
--to=angelogioacchino.delregno@collabora.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=fshao@chromium.org \
--cc=kernel@collabora.com \
--cc=krzk+dt@kernel.org \
--cc=lihongbo22@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=mandyjh.liu@mediatek.com \
--cc=matthias.bgg@gmail.com \
--cc=mbrugger@suse.com \
--cc=robh@kernel.org \
--cc=ulf.hansson@linaro.org \
--cc=wenst@chromium.org \
--cc=y.oudjana@protonmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox