summaryrefslogtreecommitdiffstats
path: root/include/pm_domain.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/pm_domain.h')
-rw-r--r--include/pm_domain.h167
1 files changed, 144 insertions, 23 deletions
diff --git a/include/pm_domain.h b/include/pm_domain.h
index 6d59587ece..4b7b07b0e4 100644
--- a/include/pm_domain.h
+++ b/include/pm_domain.h
@@ -1,6 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#ifndef _PM_DOMAIN_H
#define _PM_DOMAIN_H
+#include <linux/list.h>
+#include <driver.h>
+#include <of.h>
+
enum gpd_status {
GPD_STATE_ACTIVE = 0, /* PM domain is active */
GPD_STATE_POWER_OFF, /* PM domain is off */
@@ -21,7 +27,87 @@ typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
#ifdef CONFIG_PM_GENERIC_DOMAINS
-int genpd_dev_pm_attach(struct device_d *dev);
+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_runtime_resume_and_get_genpd(struct device *dev);
+
+int pm_genpd_init(struct generic_pm_domain *genpd, void *gov, bool is_off);
+
+int pm_genpd_remove(struct generic_pm_domain *genpd);
+
+int of_genpd_add_provider_simple(struct device_node *np,
+ struct generic_pm_domain *genpd);
+
+struct genpd_onecell_data {
+ struct generic_pm_domain **domains;
+ unsigned int num_domains;
+ genpd_xlate_t xlate;
+};
+
+int of_genpd_add_provider_onecell(struct device_node *np,
+ struct genpd_onecell_data *data);
+
+void of_genpd_del_provider(struct device_node *np);
+
+void pm_genpd_print(void);
+
+#else
+
+static inline void genpd_activate(void)
+{
+}
+
+static inline int pm_genpd_init(struct generic_pm_domain *genpd,
+ void *gov, bool is_off)
+{
+ return -ENOSYS;
+}
+
+static inline int pm_genpd_remove(struct generic_pm_domain *genpd)
+{
+ return -EOPNOTSUPP;
+}
+
+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 pm_runtime_resume_and_get_genpd(struct device *dev)
+{
+ return 0;
+}
+
+static inline int
+of_genpd_add_provider_simple(struct device_node *np,
+ struct generic_pm_domain *genpd)
+{
+ return -ENOTSUPP;
+}
+
+static inline void of_genpd_del_provider(struct device_node *np)
+{
+}
+
+#endif
/**
* dev_pm_domain_attach - Attach a device to its PM domain.
@@ -42,41 +128,76 @@ int genpd_dev_pm_attach(struct device_d *dev);
*
* Returns 0 on successfully attached PM domain or negative error code.
*/
-static inline int dev_pm_domain_attach(struct device_d *dev, bool power_on)
+static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
{
+ if (dev->pm_domain)
+ return 0;
+
return genpd_dev_pm_attach(dev);
}
-int pm_genpd_init(struct generic_pm_domain *genpd, void *gov, bool is_off);
-
-int of_genpd_add_provider_simple(struct device_node *np,
- struct generic_pm_domain *genpd);
-
-#else
-
-static inline int pm_genpd_init(struct generic_pm_domain *genpd,
- void *gov, bool is_off)
+/**
+ * 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)
{
- return -ENOSYS;
+ if (dev->pm_domain)
+ return ERR_PTR(-EEXIST);
+
+ return genpd_dev_pm_attach_by_id(dev, index);
}
-static inline int genpd_dev_pm_attach(struct device_d *dev)
+/**
+ * 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)
{
- return 0;
+ if (dev->pm_domain)
+ return ERR_PTR(-EEXIST);
+
+ return genpd_dev_pm_attach_by_name(dev, name);
}
-static inline int dev_pm_domain_attach(struct device_d *dev, bool power_on)
+static inline void dev_pm_domain_detach(struct device *dev, bool power_off)
{
- return 0;
+ /* Just keep power domain enabled until dev_pm_domain_attach*
+ * start doing reference counting
+ */
}
-static inline int
-of_genpd_add_provider_simple(struct device_node *np,
- struct generic_pm_domain *genpd)
+static inline void pm_runtime_put_genpd(struct device *dev)
{
- return -ENOTSUPP;
+ /* Just keep power domain enabled until pm_runtime_resume_and_get_genpd
+ * starts doing reference counting
+ */
}
-
#endif
-
-#endif \ No newline at end of file