mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 04/19] pmdomain: associate devices with their power domain
Date: Fri, 19 Jan 2024 17:25:55 +0100	[thread overview]
Message-ID: <20240119162610.1014870-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240119162610.1014870-1-a.fatoum@pengutronix.de>

In Linux, there is no public consumer API to enable or disable
a struct generic_pm_domain. Operations are instead performed on regular
struct device, each of which has a reference to a single attached
power domain.

Power domain consumer API in barebox was so far limited to automatically
attaching a single power domain and powering it on prior to function probe,
which is never detached and thus no further consumer API is needed.

To support more complex power domain setups, we adopt here the kernel API
of attaching power domains to devices to enable using struct device
as handles for additional power domain operations.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/base/power.c | 26 +++++++++++++++++++++++++-
 include/driver.h     |  3 +++
 include/pm_domain.h  |  4 ++++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/base/power.c b/drivers/base/power.c
index e927d0f83ff0..4ff7b055c825 100644
--- a/drivers/base/power.c
+++ b/drivers/base/power.c
@@ -10,6 +10,14 @@
 
 static LIST_HEAD(gpd_list);
 
+static inline struct generic_pm_domain *dev_to_genpd(struct device *dev)
+{
+	if (IS_ERR_OR_NULL(dev->pm_domain))
+		return ERR_PTR(-EINVAL);
+
+	return dev->pm_domain;
+}
+
 /**
  * pm_genpd_init - Initialize a generic I/O PM domain object.
  * @genpd: PM domain object to initialize.
@@ -280,6 +288,17 @@ static int genpd_power_on(struct generic_pm_domain *genpd)
 	return 0;
 }
 
+static void genpd_add_device(struct generic_pm_domain *genpd, struct device *dev)
+{
+	dev->pm_domain = genpd;
+}
+
+static void genpd_remove_device(struct generic_pm_domain *genpd,
+			       struct device *dev)
+{
+	dev->pm_domain = NULL;
+}
+
 static int __genpd_dev_pm_attach(struct device *dev, struct device_node *np,
 				 unsigned int index, bool power_on)
 {
@@ -306,8 +325,13 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device_node *np,
 
 	dev_dbg(dev, "adding to PM domain %s\n", pd ? pd->name : "dummy");
 
-	if (power_on)
+	genpd_add_device(pd, dev);
+
+	if (power_on) {
 		ret = genpd_power_on(pd);
+		if (ret < 0)
+			genpd_remove_device(pd, dev);
+	}
 
 	return ret ?: 1;
 }
diff --git a/include/driver.h b/include/driver.h
index 43d002f66dbe..7dfa565b8960 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -19,6 +19,7 @@
 
 struct filep;
 struct bus_type;
+struct generic_pm_domain;
 
 struct platform_device_id {
 	const char *name;
@@ -75,6 +76,8 @@ struct device {
 
 	struct device *parent;   /* our parent, NULL if not present */
 
+	struct generic_pm_domain *pm_domain;	/* attached power domain */
+
 	struct bus_type *bus;
 
 	/*! The parameters for this device. This is used to carry information
diff --git a/include/pm_domain.h b/include/pm_domain.h
index bf122460d0fe..59932ffee0b9 100644
--- a/include/pm_domain.h
+++ b/include/pm_domain.h
@@ -4,6 +4,7 @@
 #define _PM_DOMAIN_H
 
 #include <linux/list.h>
+#include <driver.h>
 #include <of.h>
 
 enum gpd_status {
@@ -93,6 +94,9 @@ of_genpd_add_provider_simple(struct device_node *np,
  */
 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);
 }
 
-- 
2.39.2




  parent reply	other threads:[~2024-01-19 16:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19 16:25 [PATCH 00/19] pmdomain: imx: add i.MX8MP HSIO blk-ctrl driver Ahmad Fatoum
2024-01-19 16:25 ` [PATCH 01/19] drivers: soc: split off powerdomains into new pmdomain directory Ahmad Fatoum
2024-01-19 16:25 ` [PATCH 02/19] pmdomain: use single implementation for dev_pm_domain_attach Ahmad Fatoum
2024-01-19 16:25 ` [PATCH 03/19] pmdomain: power: drop unused parameters for internal functions Ahmad Fatoum
2024-01-19 16:25 ` Ahmad Fatoum [this message]
2024-01-19 16:25 ` [PATCH 05/19] pmdomain: push have_genpd_providers check into __genpd_dev_pm_attach Ahmad Fatoum
2024-01-19 16:25 ` [PATCH 06/19] pmdomain: drop superfluous parameter to __genpd_dev_pm_attach Ahmad Fatoum
2024-01-19 16:25 ` [PATCH 07/19] pmdomain: implement dev_pm_domain_attach_by_id/name Ahmad Fatoum
2024-01-19 16:25 ` [PATCH 08/19] pmdomain: add support for enabling power domains later on Ahmad Fatoum
2024-01-19 16:26 ` [PATCH 09/19] pmdomain: imx: gpcv2: enable COMPILE_TEST build Ahmad Fatoum
2024-01-19 16:26 ` [PATCH 10/19] pmdomain: add stub definition for dev_pm_domain_detach Ahmad Fatoum
2024-01-19 16:26 ` [PATCH 11/19] pmdomain: add stub definition for pm_runtime_put_genpd Ahmad Fatoum
2024-01-19 16:26 ` [PATCH 12/19] pmdomain: implement pm_genpd_remove/of_genpd_del_provider for cleanup Ahmad Fatoum
2024-01-19 16:26 ` [PATCH 13/19] driver: have dev_request_mem_region_err_null warn if resource starts at 0 Ahmad Fatoum
2024-01-19 16:26 ` [PATCH 14/19] include: linux/device.h: implement dev_platform_ioremap_resource Ahmad Fatoum
2024-01-19 16:26 ` [PATCH 15/19] regmap: include missing header from linux/regmap.h Ahmad Fatoum
2024-01-19 16:26 ` [PATCH 16/19] clk: define aliases for clk_bulk_prepare_enable/disable_unprepare Ahmad Fatoum
2024-01-19 16:26 ` [PATCH 17/19] driver: make driver.h header self-contained Ahmad Fatoum
2024-01-19 16:26 ` [PATCH 18/19] pmdomain: imx: add i.MX8MP HSIO blk-ctrl driver Ahmad Fatoum
2024-01-19 16:26 ` [PATCH 19/19] ARM: dts: i.MX8MP: drop barebox,allow-dummy for HSIO blk-ctrl Ahmad Fatoum
2024-01-22 10:12 ` [PATCH 00/19] pmdomain: imx: add i.MX8MP HSIO blk-ctrl driver Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240119162610.1014870-5-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox