public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Dhruva Gole <d-gole@ti.com>
To: Kevin Hilman <khilman@baylibre.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>, <linux-pm@vger.kernel.org>,
	Nishanth Menon <nm@ti.com>, Akashdeep Kaur <a-kaur@ti.com>,
	Sebin Francis <sebin.francis@ti.com>,
	Markus Schneider-Pargmann <msp@baylibre.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6 1/3] pmdomain: ti_sci: add per-device latency constraint management
Date: Tue, 10 Dec 2024 16:17:35 +0530	[thread overview]
Message-ID: <20241210104735.dtzdhdds6l7yjvgk@lcpd911> (raw)
In-Reply-To: <20241206-lpm-v6-10-constraints-pmdomain-v6-1-833980158c68@baylibre.com>

On Dec 06, 2024 at 14:12:50 -0800, Kevin Hilman wrote:
> For each device in a TI SCI PM domain, check whether the device has
> any resume latency constraints set via per-device PM QoS.  If
> constraints are set, send them to DM via the new SCI constraints API.
> 
> Checking for constraints happen for each device before system-wide
> suspend (via ->suspend() hook.)
> 
> An important detail here is that the PM domain driver inserts itself
> into the path of both the ->suspend() and ->resume() hook path
> of *all* devices in the PM domain.  This allows generic PM domain code
> to handle the constraint management and communication with TI SCI.
> 
> Further, this allows device drivers to use existing PM QoS APIs to
> add/update constraints.
> 
> DM firmware clears constraints during its resume, so Linux has
> to check/update/send constraints each time system suspends.
> 
> Also note that the PM QoS framework uses usecs as the units for
> latency whereas the TI SCI firmware uses msecs, so a conversion is
> needed before passing to TI SCI.
> 
> Co-developed-by: Vibhore Vardhan <vibhore@ti.com>
> Signed-off-by: Vibhore Vardhan <vibhore@ti.com>
> Reviewed-by: Markus Schneider-Pargmann <msp@baylibre.com>
> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
> Tested-by: Dhruva Gole <d-gole@ti.com>
> Signed-off-by: Kevin Hilman <khilman@baylibre.com>
> ---
>  drivers/pmdomain/ti/ti_sci_pm_domains.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 55 insertions(+)
> 
> diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c
> index 0e4bd749d067309654307484c5bb98711bf06daf..963fe1901c959197d5d8b5d34fd8420dfb180087 100644
> --- a/drivers/pmdomain/ti/ti_sci_pm_domains.c
> +++ b/drivers/pmdomain/ti/ti_sci_pm_domains.c
> @@ -13,6 +13,8 @@
>  #include <linux/platform_device.h>
>  #include <linux/pm_domain.h>
>  #include <linux/slab.h>
> +#include <linux/pm_qos.h>
> +#include <linux/pm_runtime.h>

nit: Do we not need to sort these includes alphabetically?

>  #include <linux/soc/ti/ti_sci_protocol.h>
>  #include <dt-bindings/soc/ti,sci_pm_domain.h>
>  
> @@ -51,6 +53,32 @@ struct ti_sci_pm_domain {
>  
>  #define genpd_to_ti_sci_pd(gpd) container_of(gpd, struct ti_sci_pm_domain, pd)
>  
> +static inline bool ti_sci_pd_is_valid_constraint(s32 val)
> +{
> +	return val != PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
> +}
> +
> +#ifdef CONFIG_PM_SLEEP
> +static void ti_sci_pd_set_lat_constraint(struct device *dev, s32 val)
> +{
> +	struct generic_pm_domain *genpd = pd_to_genpd(dev->pm_domain);
> +	struct ti_sci_pm_domain *pd = genpd_to_ti_sci_pd(genpd);
> +	const struct ti_sci_handle *ti_sci = pd->parent->ti_sci;
> +	u16 val_ms;
> +	int ret;
> +
> +	/* PM QoS latency unit is usecs, TI SCI uses msecs */
> +	val_ms = val / USEC_PER_MSEC;
> +	ret = ti_sci->ops.pm_ops.set_latency_constraint(ti_sci, val_ms, TISCI_MSG_CONSTRAINT_SET);
> +	if (ret)
> +		dev_err(dev, "ti_sci_pd: set latency constraint failed: ret=%d\n",
> +			ret);
> +	else
> +		dev_dbg(dev, "ti_sci_pd: ID:%d set latency constraint %d\n",
> +			pd->idx, val);
> +}
> +#endif
> +
>  /*
>   * ti_sci_pd_power_off(): genpd power down hook
>   * @domain: pointer to the powerdomain to power off
> @@ -79,6 +107,26 @@ static int ti_sci_pd_power_on(struct generic_pm_domain *domain)
>  		return ti_sci->ops.dev_ops.get_device(ti_sci, pd->idx);
>  }
>  
> +#ifdef CONFIG_PM_SLEEP
> +static int ti_sci_pd_suspend(struct device *dev)
> +{
> +	int ret;
> +	s32 val;
> +
> +	ret = pm_generic_suspend(dev);
> +	if (ret)
> +		return ret;
> +
> +	val = dev_pm_qos_read_value(dev, DEV_PM_QOS_RESUME_LATENCY);
> +	if (ti_sci_pd_is_valid_constraint(val))
> +		ti_sci_pd_set_lat_constraint(dev, val);
> +
> +	return 0;
> +}
> +#else
> +#define ti_sci_pd_suspend		NULL
> +#endif
> +
>  /*
>   * ti_sci_pd_xlate(): translation service for TI SCI genpds
>   * @genpdspec: DT identification data for the genpd
> @@ -182,6 +230,13 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev)
>  				pd->pd.flags |= GENPD_FLAG_ACTIVE_WAKEUP;
>  				pd->idx = args.args[0];
>  				pd->parent = pd_provider;
> +				/*
> +				 * If SCI constraint functions are present, then firmware
> +				 * supports the constraints API.
> +				 */
> +				if (pd_provider->ti_sci->ops.pm_ops.set_device_constraint &&
> +				    pd_provider->ti_sci->ops.pm_ops.set_latency_constraint)
> +					pd->pd.domain.ops.suspend = ti_sci_pd_suspend;

Rest looks good.
Reviewed-by: Dhruva Gole <d-gole@ti.com>

-- 
Best regards,
Dhruva Gole
Texas Instruments Incorporated


  reply	other threads:[~2024-12-10 10:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-06 22:12 [PATCH v6 0/3] pmdomain: ti_sci: collect and send low-power mode constraints Kevin Hilman
2024-12-06 22:12 ` [PATCH v6 1/3] pmdomain: ti_sci: add per-device latency constraint management Kevin Hilman
2024-12-10 10:47   ` Dhruva Gole [this message]
2024-12-06 22:12 ` [PATCH v6 2/3] pmdomain: ti_sci: add wakeup " Kevin Hilman
2024-12-10 10:54   ` Dhruva Gole
2024-12-06 22:12 ` [PATCH v6 3/3] pmdomain: ti_sci: handle wake IRQs for IO daisy chain wakeups Kevin Hilman
2024-12-10 10:55   ` Dhruva Gole
2024-12-10 14:02 ` [PATCH v6 0/3] pmdomain: ti_sci: collect and send low-power mode constraints Ulf Hansson
2024-12-11 15:41   ` Kevin Hilman

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=20241210104735.dtzdhdds6l7yjvgk@lcpd911 \
    --to=d-gole@ti.com \
    --cc=a-kaur@ti.com \
    --cc=khilman@baylibre.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=msp@baylibre.com \
    --cc=nm@ti.com \
    --cc=sebin.francis@ti.com \
    --cc=ulf.hansson@linaro.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