Skip to content

Commit 09813cd

Browse files
hiagofrancoUlf Hansson
authored andcommitted
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>
1 parent fcddcb7 commit 09813cd

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

drivers/pmdomain/core.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,39 @@ int dev_pm_genpd_rpm_always_on(struct device *dev, bool on)
769769
}
770770
EXPORT_SYMBOL_GPL(dev_pm_genpd_rpm_always_on);
771771

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+
772805
/**
773806
* pm_genpd_inc_rejected() - Adjust the rejected/usage counts for an idle-state.
774807
*

include/linux/pm_domain.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ void dev_pm_genpd_synced_poweroff(struct device *dev);
315315
int dev_pm_genpd_set_hwmode(struct device *dev, bool enable);
316316
bool dev_pm_genpd_get_hwmode(struct device *dev);
317317
int dev_pm_genpd_rpm_always_on(struct device *dev, bool on);
318+
bool dev_pm_genpd_is_on(struct device *dev);
318319

319320
extern struct dev_power_governor simple_qos_governor;
320321
extern struct dev_power_governor pm_domain_always_on_gov;
@@ -407,6 +408,11 @@ static inline int dev_pm_genpd_rpm_always_on(struct device *dev, bool on)
407408
return -EOPNOTSUPP;
408409
}
409410

411+
static inline bool dev_pm_genpd_is_on(struct device *dev)
412+
{
413+
return false;
414+
}
415+
410416
#define simple_qos_governor (*(struct dev_power_governor *)(NULL))
411417
#define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL))
412418
#endif

0 commit comments

Comments
 (0)