mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Patrick DELAUNAY <patrick.delaunay@foss.st.com>
To: Ulf Hansson <ulf.hansson@oss.qualcomm.com>
Cc: Ulf Hansson <ulfh@kernel.org>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	<linux-pm@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>
Subject: Re: [PATCH v2 2/7] pmdomain: st: add STM32MP power domain
Date: Tue, 1 Dec 2026 16:10:15 +0100	[thread overview]
Message-ID: <a8cd82fa-feb2-440a-972f-2e9f21d186dc@foss.st.com> (raw)
In-Reply-To: <CAPx+jO-Dqw94c5xbT3f10bcwS5pzzsNcsT7RU43KCmp=STpDhQ@mail.gmail.com>

Hi,

On 12/1/26 11:03, Ulf Hansson wrote:
> On Fri, Nov 27, 2026 at 7:20 PM Patrick Delaunay
> <patrick.delaunay@foss.st.com> wrote:
>> Register the STM32MP D1 functional-dependency domain as a generic
>> power domain below the PSCI cluster domain.
>>
>> Devices attached to D1 require the cluster to remain active while they
>> need their RCC clocks. D1 has no hardware power-switch operations and
>> does not propagate active-wakeup constraints; wakeup routing is handled
>> separately by EXTI1 and the retention domain.
>>
>> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
>> ---
>>
>> Changes in v2:
>> - update commit message
>>
>>   drivers/pmdomain/st/Kconfig             |  14 +++
>>   drivers/pmdomain/st/Makefile            |   1 +
>>   drivers/pmdomain/st/stm32mp-pm-domain.c | 128 ++++++++++++++++++++++++
>>   3 files changed, 143 insertions(+)
>>   create mode 100644 drivers/pmdomain/st/stm32mp-pm-domain.c
>>
>> diff --git a/drivers/pmdomain/st/Kconfig b/drivers/pmdomain/st/Kconfig
>> index a77a70211f61..da8a54d44158 100644
>> --- a/drivers/pmdomain/st/Kconfig
>> +++ b/drivers/pmdomain/st/Kconfig
>> @@ -1,4 +1,18 @@
>>   # SPDX-License-Identifier: GPL-2.0-only
>> +
>> +config STM32MP_PM_DOMAIN
>> +       tristate "STM32MP PM domain"
>> +       depends on ARCH_STM32 || COMPILE_TEST
>> +       select PM_GENERIC_DOMAINS
>> +       default y
>> +       help
>> +         Enable support for the STM32MP Power Management (PM) domain driver.
>> +         This driver implements a generic PM domain for STM32MP SoCs, allowing
>> +         the kernel to manage power domains for various hardware blocks using
>> +         the generic power management framework. It is typically used to
>> +         control the power state of devices and peripherals on STM32MP
>> +         platforms. If unsure, say Y.
>> +
>>   config UX500_PM_DOMAIN
>>          bool "ST-Ericsson ux500 Power Domain"
>>          depends on ARCH_U8500 || COMPILE_TEST
>> diff --git a/drivers/pmdomain/st/Makefile b/drivers/pmdomain/st/Makefile
>> index 6d8b617eb834..0e8131b7fe9d 100644
>> --- a/drivers/pmdomain/st/Makefile
>> +++ b/drivers/pmdomain/st/Makefile
>> @@ -1,2 +1,3 @@
>>   # SPDX-License-Identifier: GPL-2.0-only
>> +obj-$(CONFIG_STM32MP_PM_DOMAIN)                += stm32mp-pm-domain.o
>>   obj-$(CONFIG_UX500_PM_DOMAIN)          += ste-ux500-pm-domain.o
>> diff --git a/drivers/pmdomain/st/stm32mp-pm-domain.c b/drivers/pmdomain/st/stm32mp-pm-domain.c
>> new file mode 100644
>> index 000000000000..1a6393840f56
>> --- /dev/null
>> +++ b/drivers/pmdomain/st/stm32mp-pm-domain.c
>> @@ -0,0 +1,128 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * Implements PM domain using the generic PM domain for STM32MP SoC.
>> + *
>> + * Copyright (C) STMicroelectronics 2026
>> + * Author(s): Patrick Delaunay <patrick.delaunay@foss.st.com>
>> + */
>> +
>> +#include <linux/device.h>
>> +#include <linux/module.h>
>> +#include <linux/of.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/pm_domain.h>
>> +#include <linux/pm_runtime.h>
>> +
>> +struct stm32mp_pm_subdomain_link {
>> +       struct generic_pm_domain *domain;
>> +       struct generic_pm_domain *subdomain;
>> +};
>> +
>> +static void stm32mp_pm_domain_genpd_remove(void *data)
>> +{
>> +       struct generic_pm_domain *genpd = data;
>> +
>> +       pm_genpd_remove(genpd);
>> +}
>> +
>> +static void stm32mp_pm_domain_release_subdomain(void *data)
>> +{
>> +       struct stm32mp_pm_subdomain_link *link = data;
>> +
>> +       pm_genpd_remove_subdomain(link->domain, link->subdomain);
>> +}
>> +
>> +static void stm32mp_pm_domain_release_genpd_provider(void *data)
>> +{
>> +       struct device_node *np = data;
>> +
>> +       of_genpd_del_provider(np);
>> +}
>> +
>> +static int stm32mp_pm_domain_probe(struct platform_device *pdev)
>> +{
>> +       struct device *dev = &pdev->dev;
>> +       struct device_node *np = dev->of_node;
>> +       struct generic_pm_domain *pd;
>> +       struct stm32mp_pm_subdomain_link *link;
>> +       int ret;
>> +
>> +       if (!np)
>> +               return -ENODEV;
>> +
>> +       /* The OF node must specify us as a power-domain provider. */
>> +       if (!of_property_present(np, "#power-domain-cells")) {
>> +               dev_warn(dev, "%pOF lacks #power-domain-cells\n", np);
>> +               return 0;
>> +       }
>> +
>> +       pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
>> +       if (!pd)
>> +               return -ENOMEM;
>> +
>> +       pd->name = dev_name(dev);
>> +
>> +       /*
>> +        * Domain based only on PM clk framework, no GENPD_FLAG_ACTIVE_WAKEUP
>> +        * support, the wake-up path is handled by interrupt driver with its
>> +        * power domain. GENPD_FLAG_NO_STAY_ON as domain no required sync state,
>> +        * domain allow low power modes even if devices are not probed
>> +        */
>> +       pd->flags = GENPD_FLAG_PM_CLK | GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_NO_STAY_ON;
> Do we really need to use all these flags? I can see that the
> GENPD_FLAG_NO_STAY_ON makes sense, but can you elaborate on why the
> rest are needed here?

GENPD_FLAG_PM_CLK: no more need, with dev_pm_domain_detach(), dropped in V3

GENPD_FLAG_IRQ_SAFE: just inform that the domain D1 can be switched off in IRQ context

it is requiredfor some IP (at least I2C and SPI) because the domain is not stopped if 
flag IRQ_SAFE is not set in D1 domain

>> +
>> +       ret = pm_genpd_init(pd, NULL, false);
>> +       if (ret)
>> +               return dev_err_probe(dev, ret, "failed to init power domain\n");
>> +
>> +       ret = devm_add_action_or_reset(dev, stm32mp_pm_domain_genpd_remove, pd);
>> +       if (ret)
>> +               return dev_err_probe(dev, ret, "failed to add action\n");
>> +
>> +       link = devm_kzalloc(dev, sizeof(*link), GFP_KERNEL);
>> +       if (!link)
>> +               return -ENOMEM;
>> +       link->domain = pd_to_genpd(dev->pm_domain);
>> +       link->subdomain = pd;
>> +
>> +       ret = pm_genpd_add_subdomain(link->domain, link->subdomain);
> Rather than using pm_genpd_add_subdomain(), I prefer if we could use
> of_genpd_add_subdomain() for cases like this.


OK


>
>> +       if (ret)
>> +               return dev_err_probe(dev, ret, "failed to add subdomain\n");
>> +
>> +       ret = devm_add_action_or_reset(dev, stm32mp_pm_domain_release_subdomain, link);
>> +       if (ret)
>> +               return dev_err_probe(dev, ret, "failed to add action\n");
>> +
>> +       ret = of_genpd_add_provider_simple(np, pd);
>> +       if (ret)
>> +               return dev_err_probe(dev, ret, "failed to add power domain provider\n");
>> +
>> +       ret = devm_add_action_or_reset(dev, stm32mp_pm_domain_release_genpd_provider, np);
>> +       if (ret)
>> +               return dev_err_probe(dev, ret, "failed to add action\n");
>> +
>> +       ret = devm_pm_runtime_enable(dev);
> Instead of enabling runtime PM, I suggest we call
> dev_pm_domain_detach() here instead.

I will do it in V3,

I lost this remark and associated update when I prepare the V2

>
>> +       if (ret)
>> +               return dev_err_probe(dev, ret, "failed to enable pm-runtime\n");
>> +
>> +       return 0;
>> +}
>> +
>> +static const struct of_device_id stm32mp_pm_domain_matches[] = {
>> +       { .compatible = "st,stm32mp-pm-domain", },
>> +       { }
>> +};
>> +MODULE_DEVICE_TABLE(of, stm32mp_pm_domain_matches);
>> +
>> +static struct platform_driver stm32mp_pm_domain_driver = {
>> +       .driver = {
>> +               .name = "stm32mp_pm_domain",
>> +               .of_match_table = stm32mp_pm_domain_matches,
>> +       },
>> +       .probe  = stm32mp_pm_domain_probe,
>> +};
>> +
>> +module_platform_driver(stm32mp_pm_domain_driver);
>> +
>> +MODULE_AUTHOR("Patrick Delaunay <patrick.delaunay@foss.st.com>");
>> +MODULE_DESCRIPTION("ST STM32MP power domain driver");
>> +MODULE_LICENSE("GPL");
>> --
>> 2.43.0
>>
> Kind regards
> Uffe

  reply	other threads:[~2026-12-01 15:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 18:18 [PATCH v2 0/7] arm64: dts: st: add STM32MP2 power domains Patrick Delaunay
2026-11-27 18:18 ` [PATCH v2 1/7] dt-bindings: power: st: add STM32MP PM domain Patrick Delaunay
2026-12-01 10:05   ` Ulf Hansson
2026-11-27 18:18 ` [PATCH v2 2/7] pmdomain: st: add STM32MP power domain Patrick Delaunay
2026-11-29  0:01   ` kernel test robot
2026-11-29  0:36   ` kernel test robot
2026-12-01 10:03   ` Ulf Hansson
2026-12-01 15:10     ` Patrick DELAUNAY [this message]
2026-11-27 18:18 ` [PATCH v2 3/7] MAINTAINERS: add entry for ST STM32 power domain driver Patrick Delaunay

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=a8cd82fa-feb2-440a-972f-2e9f21d186dc@foss.st.com \
    --to=patrick.delaunay@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=ulf.hansson@oss.qualcomm.com \
    --cc=ulfh@kernel.org \
    /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

all inboxes | Powered by JetHome®