diff mbox series

[2/3] pmdomain: ti_sci: add wakeup constraint management

Message ID 20240805-lpm-v6-10-constraints-pmdomain-v1-2-d186b68ded4c@baylibre.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series pmdomain: ti_sci: collect and send low-power mode constraints | expand

Commit Message

Kevin Hilman Aug. 5, 2024, 11:38 p.m. UTC
During system-wide suspend, check all devices connected to PM domain
to see if they are wakeup-enabled.  If so, set a TI SCI device
constraint.

Note: DM firmware clears all constraints on resume.

Co-developed-by: Vibhore Vardhan <vibhore@ti.com>
Signed-off-by: Vibhore Vardhan <vibhore@ti.com>
Signed-off-by: Kevin Hilman <khilman@baylibre.com>
Signed-off-by: Dhruva Gole <d-gole@ti.com>
---
 drivers/pmdomain/ti/ti_sci_pm_domains.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Markus Schneider-Pargmann Aug. 6, 2024, 8:18 a.m. UTC | #1
On Mon, Aug 05, 2024 at 04:38:40PM GMT, Kevin Hilman wrote:
> During system-wide suspend, check all devices connected to PM domain
> to see if they are wakeup-enabled.  If so, set a TI SCI device
> constraint.
> 
> Note: DM firmware clears all constraints on resume.
> 
> Co-developed-by: Vibhore Vardhan <vibhore@ti.com>
> Signed-off-by: Vibhore Vardhan <vibhore@ti.com>
> Signed-off-by: Kevin Hilman <khilman@baylibre.com>
> Signed-off-by: Dhruva Gole <d-gole@ti.com>
> ---
>  drivers/pmdomain/ti/ti_sci_pm_domains.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c
> index 4dc48a97f9b8..7cd6ae957289 100644
> --- a/drivers/pmdomain/ti/ti_sci_pm_domains.c
> +++ b/drivers/pmdomain/ti/ti_sci_pm_domains.c
> @@ -51,6 +51,7 @@ struct ti_sci_pm_domain {
>  	struct ti_sci_genpd_provider *parent;
>  	s32 lat_constraint;
>  	bool constraint_sent;
> +	bool wkup_constraint;
>  };
>  
>  #define genpd_to_ti_sci_pd(gpd) container_of(gpd, struct ti_sci_pm_domain, pd)
> @@ -87,6 +88,26 @@ static inline void ti_sci_pd_clear_constraints(struct device *dev)
>  
>  	pd->lat_constraint = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
>  	pd->constraint_sent = false;
> +	pd->wkup_constraint = false;
> +}
> +
> +static inline bool ti_sci_pd_check_wkup_constraint(struct device *dev)

'check' in the function name sounds like a passive function. Maybe
ti_sci_pd_send_wkup_constraint() would indicate its purpose better?

> +{
> +	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;
> +	int ret;
> +
> +	if (device_may_wakeup(dev)) {
> +		ret = ti_sci->ops.pm_ops.set_device_constraint(ti_sci, pd->idx,
> +							       TISCI_MSG_CONSTRAINT_SET);
> +		if (!ret) {
> +			pd->wkup_constraint = true;
> +			dev_dbg(dev, "ti_sci_pd: ID:%d set device constraint.\n", pd->idx);
> +		}
> +	}
> +
> +	return pd->wkup_constraint;

Is this return value used anywhere?

Best
Markus

>  }
>  
>  /*
> @@ -158,6 +179,8 @@ static int ti_sci_pd_suspend(struct device *dev)
>  	}
>  	pd->lat_constraint = val;
>  
> +	ti_sci_pd_check_wkup_constraint(dev);
> +
>  	return 0;
>  }
>  
> 
> -- 
> 2.46.0
>
diff mbox series

Patch

diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c
index 4dc48a97f9b8..7cd6ae957289 100644
--- a/drivers/pmdomain/ti/ti_sci_pm_domains.c
+++ b/drivers/pmdomain/ti/ti_sci_pm_domains.c
@@ -51,6 +51,7 @@  struct ti_sci_pm_domain {
 	struct ti_sci_genpd_provider *parent;
 	s32 lat_constraint;
 	bool constraint_sent;
+	bool wkup_constraint;
 };
 
 #define genpd_to_ti_sci_pd(gpd) container_of(gpd, struct ti_sci_pm_domain, pd)
@@ -87,6 +88,26 @@  static inline void ti_sci_pd_clear_constraints(struct device *dev)
 
 	pd->lat_constraint = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
 	pd->constraint_sent = false;
+	pd->wkup_constraint = false;
+}
+
+static inline bool ti_sci_pd_check_wkup_constraint(struct device *dev)
+{
+	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;
+	int ret;
+
+	if (device_may_wakeup(dev)) {
+		ret = ti_sci->ops.pm_ops.set_device_constraint(ti_sci, pd->idx,
+							       TISCI_MSG_CONSTRAINT_SET);
+		if (!ret) {
+			pd->wkup_constraint = true;
+			dev_dbg(dev, "ti_sci_pd: ID:%d set device constraint.\n", pd->idx);
+		}
+	}
+
+	return pd->wkup_constraint;
 }
 
 /*
@@ -158,6 +179,8 @@  static int ti_sci_pd_suspend(struct device *dev)
 	}
 	pd->lat_constraint = val;
 
+	ti_sci_pd_check_wkup_constraint(dev);
+
 	return 0;
 }