Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pmdomain: core: introduce dev_pm_genpd_is_on()

This helper function returns the current power status of a given generic
power domain.

As example, remoteproc/imx_rproc.c can now use this function to check
the power status of the remote core to properly set "attached" or
"offline" modes.

Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Bjorn Andersson <andersson@kernel.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Hiago De Franco <hiago.franco@toradex.com>
Link: https://lore.kernel.org/r/20250629172512.14857-2-hiagofranco@gmail.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Hiago De Franco and committed by
Ulf Hansson
09813cde fcddcb7e

+39
+33
drivers/pmdomain/core.c
··· 770 770 EXPORT_SYMBOL_GPL(dev_pm_genpd_rpm_always_on); 771 771 772 772 /** 773 + * dev_pm_genpd_is_on() - Get device's current power domain status 774 + * 775 + * @dev: Device to get the current power status 776 + * 777 + * This function checks whether the generic power domain associated with the 778 + * given device is on or not by verifying if genpd_status_on equals 779 + * GENPD_STATE_ON. 780 + * 781 + * Note: this function returns the power status of the genpd at the time of the 782 + * call. The power status may change after due to activity from other devices 783 + * sharing the same genpd. Therefore, this information should not be relied for 784 + * long-term decisions about the device power state. 785 + * 786 + * Return: 'true' if the device's power domain is on, 'false' otherwise. 787 + */ 788 + bool dev_pm_genpd_is_on(struct device *dev) 789 + { 790 + struct generic_pm_domain *genpd; 791 + bool is_on; 792 + 793 + genpd = dev_to_genpd_safe(dev); 794 + if (!genpd) 795 + return false; 796 + 797 + genpd_lock(genpd); 798 + is_on = genpd_status_on(genpd); 799 + genpd_unlock(genpd); 800 + 801 + return is_on; 802 + } 803 + EXPORT_SYMBOL_GPL(dev_pm_genpd_is_on); 804 + 805 + /** 773 806 * pm_genpd_inc_rejected() - Adjust the rejected/usage counts for an idle-state. 774 807 * 775 808 * @genpd: The PM domain the idle-state belongs to.
+6
include/linux/pm_domain.h
··· 315 315 int dev_pm_genpd_set_hwmode(struct device *dev, bool enable); 316 316 bool dev_pm_genpd_get_hwmode(struct device *dev); 317 317 int dev_pm_genpd_rpm_always_on(struct device *dev, bool on); 318 + bool dev_pm_genpd_is_on(struct device *dev); 318 319 319 320 extern struct dev_power_governor simple_qos_governor; 320 321 extern struct dev_power_governor pm_domain_always_on_gov; ··· 406 405 static inline int dev_pm_genpd_rpm_always_on(struct device *dev, bool on) 407 406 { 408 407 return -EOPNOTSUPP; 408 + } 409 + 410 + static inline bool dev_pm_genpd_is_on(struct device *dev) 411 + { 412 + return false; 409 413 } 410 414 411 415 #define simple_qos_governor (*(struct dev_power_governor *)(NULL))