summaryrefslogtreecommitdiffstats
path: root/include/pm_domain.h
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2024-01-19 17:25:58 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-01-22 11:12:02 +0100
commit26c0bb95d2552fd36eb035c127dc1065293d13b6 (patch)
tree2a61bfa90a5e70fbbcd294c69878231a6ee8c162 /include/pm_domain.h
parent7b23b9c96a598633dc18bbf7a03d629bf830449e (diff)
downloadbarebox-26c0bb95d2552fd36eb035c127dc1065293d13b6.tar.gz
barebox-26c0bb95d2552fd36eb035c127dc1065293d13b6.tar.xz
pmdomain: implement dev_pm_domain_attach_by_id/name
In Linux, dev_pm_domain_attach() enables a device's sole power domain, but dev_pm_domain_attach_by_id/name(), attaches the power domain to a virtual device and returns it for use with runtime PM API. Import these two functions into barebox, so drivers can use them to implement more elaborate power up sequences. The power up operation itself follows in a follow-up commit. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240119162610.1014870-8-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/pm_domain.h')
-rw-r--r--include/pm_domain.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/include/pm_domain.h b/include/pm_domain.h
index 59932ffee0..b02af0d46d 100644
--- a/include/pm_domain.h
+++ b/include/pm_domain.h
@@ -31,6 +31,11 @@ void genpd_activate(void);
int genpd_dev_pm_attach(struct device *dev);
+struct device *genpd_dev_pm_attach_by_id(struct device *dev,
+ unsigned int index);
+struct device *genpd_dev_pm_attach_by_name(struct device *dev,
+ const char *name);
+
int pm_genpd_init(struct generic_pm_domain *genpd, void *gov, bool is_off);
int of_genpd_add_provider_simple(struct device_node *np,
@@ -64,6 +69,18 @@ static inline int genpd_dev_pm_attach(struct device *dev)
return 0;
}
+static inline struct device *genpd_dev_pm_attach_by_id(struct device *dev,
+ unsigned int index)
+{
+ return NULL;
+}
+
+static inline struct device *genpd_dev_pm_attach_by_name(struct device *dev,
+ const char *name)
+{
+ return NULL;
+}
+
static inline int
of_genpd_add_provider_simple(struct device_node *np,
struct generic_pm_domain *genpd)
@@ -100,4 +117,55 @@ static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
return genpd_dev_pm_attach(dev);
}
+/**
+ * dev_pm_domain_attach_by_id - Associate a device with one of its PM domains.
+ * @dev: The device used to lookup the PM domain.
+ * @index: The index of the PM domain.
+ *
+ * As @dev may only be attached to a single PM domain, the backend PM domain
+ * provider creates a virtual device to attach instead. If attachment succeeds,
+ * the ->detach() callback in the struct dev_pm_domain are assigned by the
+ * corresponding backend attach function, as to deal with detaching of the
+ * created virtual device.
+ *
+ * This function should typically be invoked by a driver during the probe phase,
+ * in case its device requires power management through multiple PM domains. The
+ * driver may benefit from using the received device, to configure device-links
+ * towards its original device. Depending on the use-case and if needed, the
+ * links may be dynamically changed by the driver, which allows it to control
+ * the power to the PM domains independently from each other.
+ *
+ * Callers must ensure proper synchronization of this function with power
+ * management callbacks.
+ *
+ * Returns the virtual created device when successfully attached to its PM
+ * domain, NULL in case @dev don't need a PM domain, else an ERR_PTR().
+ * Note that, to detach the returned virtual device, the driver shall call
+ * dev_pm_domain_detach() on it, typically during the remove phase.
+ */
+static inline struct device *dev_pm_domain_attach_by_id(struct device *dev,
+ unsigned int index)
+{
+ if (dev->pm_domain)
+ return ERR_PTR(-EEXIST);
+
+ return genpd_dev_pm_attach_by_id(dev, index);
+}
+
+/**
+ * dev_pm_domain_attach_by_name - Associate a device with one of its PM domains.
+ * @dev: The device used to lookup the PM domain.
+ * @name: The name of the PM domain.
+ *
+ * For a detailed function description, see dev_pm_domain_attach_by_id().
+ */
+static inline struct device *dev_pm_domain_attach_by_name(struct device *dev,
+ const char *name)
+{
+ if (dev->pm_domain)
+ return ERR_PTR(-EEXIST);
+
+ return genpd_dev_pm_attach_by_name(dev, name);
+}
+
#endif