diff mbox series

[4/5] cpuidle: psci: Convert PM domain to platform driver

Message ID 20200615152054.6819-5-ulf.hansson@linaro.org
State Superseded
Headers show
Series cpuidle: psci: Various improvements for PSCI PM domains | expand

Commit Message

Ulf Hansson June 15, 2020, 3:20 p.m. UTC
To enable support for deferred probing and to allow implementation of the
->sync_state() callback from subsequent changes, let's convert into a
platform driver.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

---
 drivers/cpuidle/cpuidle-psci-domain.c | 45 +++++++++++++++++----------
 1 file changed, 28 insertions(+), 17 deletions(-)

-- 
2.20.1

Comments

Lina Iyer June 23, 2020, 5:21 p.m. UTC | #1
On Mon, Jun 15 2020 at 09:21 -0600, Ulf Hansson wrote:
>To enable support for deferred probing and to allow implementation of the

>->sync_state() callback from subsequent changes, let's convert into a

>platform driver.

>

>Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

Reviewed-by: Lina Iyer <ilina@codeaurora.org>


>---

> drivers/cpuidle/cpuidle-psci-domain.c | 45 +++++++++++++++++----------

> 1 file changed, 28 insertions(+), 17 deletions(-)

>

>diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c

>index e48e578aaa7d..bf527d2bb4b6 100644

>--- a/drivers/cpuidle/cpuidle-psci-domain.c

>+++ b/drivers/cpuidle/cpuidle-psci-domain.c

>@@ -12,6 +12,7 @@

> #include <linux/cpu.h>

> #include <linux/device.h>

> #include <linux/kernel.h>

>+#include <linux/platform_device.h>

> #include <linux/pm_domain.h>

> #include <linux/pm_runtime.h>

> #include <linux/psci.h>

>@@ -42,8 +43,8 @@ static int psci_pd_power_off(struct generic_pm_domain *pd)

> 	return 0;

> }

>

>-static int __init psci_pd_parse_state_nodes(struct genpd_power_state *states,

>-					int state_count)

>+static int psci_pd_parse_state_nodes(struct genpd_power_state *states,

>+				     int state_count)

> {

> 	int i, ret;

> 	u32 psci_state, *psci_state_buf;

>@@ -72,7 +73,7 @@ static int __init psci_pd_parse_state_nodes(struct genpd_power_state *states,

> 	return ret;

> }

>

>-static int __init psci_pd_parse_states(struct device_node *np,

>+static int psci_pd_parse_states(struct device_node *np,

> 			struct genpd_power_state **states, int *state_count)

> {

> 	int ret;

>@@ -100,7 +101,7 @@ static void psci_pd_free_states(struct genpd_power_state *states,

> 	kfree(states);

> }

>

>-static int __init psci_pd_init(struct device_node *np)

>+static int psci_pd_init(struct device_node *np)

> {

> 	struct generic_pm_domain *pd;

> 	struct psci_pd_provider *pd_provider;

>@@ -167,7 +168,7 @@ static int __init psci_pd_init(struct device_node *np)

> 	return ret;

> }

>

>-static void __init psci_pd_remove(void)

>+static void psci_pd_remove(void)

> {

> 	struct psci_pd_provider *pd_provider, *it;

> 	struct generic_pm_domain *genpd;

>@@ -185,7 +186,7 @@ static void __init psci_pd_remove(void)

> 	}

> }

>

>-static int __init psci_pd_init_topology(struct device_node *np, bool add)

>+static int psci_pd_init_topology(struct device_node *np, bool add)

> {

> 	struct device_node *node;

> 	struct of_phandle_args child, parent;

>@@ -211,24 +212,24 @@ static int __init psci_pd_init_topology(struct device_node *np, bool add)

> 	return 0;

> }

>

>-static int __init psci_pd_add_topology(struct device_node *np)

>+static int psci_pd_add_topology(struct device_node *np)

> {

> 	return psci_pd_init_topology(np, true);

> }

>

>-static void __init psci_pd_remove_topology(struct device_node *np)

>+static void psci_pd_remove_topology(struct device_node *np)

> {

> 	psci_pd_init_topology(np, false);

> }

>

>-static const struct of_device_id psci_of_match[] __initconst = {

>+static const struct of_device_id psci_of_match[] = {

> 	{ .compatible = "arm,psci-1.0" },

> 	{}

> };

>

>-static int __init psci_idle_init_domains(void)

>+static int psci_cpuidle_domain_probe(struct platform_device *pdev)

> {

>-	struct device_node *np = of_find_matching_node(NULL, psci_of_match);

>+	struct device_node *np = pdev->dev.of_node;

> 	struct device_node *node;

> 	int ret = 0, pd_count = 0;

>

>@@ -237,7 +238,7 @@ static int __init psci_idle_init_domains(void)

>

> 	/* Currently limit the hierarchical topology to be used in OSI mode. */

> 	if (!psci_has_osi_support())

>-		goto out;

>+		return 0;

>

> 	/*

> 	 * Parse child nodes for the "#power-domain-cells" property and

>@@ -256,7 +257,7 @@ static int __init psci_idle_init_domains(void)

>

> 	/* Bail out if not using the hierarchical CPU topology. */

> 	if (!pd_count)

>-		goto out;

>+		return 0;

>

> 	/* Link genpd masters/subdomains to model the CPU topology. */

> 	ret = psci_pd_add_topology(np);

>@@ -271,9 +272,8 @@ static int __init psci_idle_init_domains(void)

> 		goto remove_pd;

> 	}

>

>-	of_node_put(np);

> 	pr_info("Initialized CPU PM domain topology\n");

>-	return pd_count;

>+	return 0;

>

> put_node:

> 	of_node_put(node);

>@@ -281,10 +281,21 @@ static int __init psci_idle_init_domains(void)

> 	if (pd_count)

> 		psci_pd_remove();

> 	pr_err("failed to create CPU PM domains ret=%d\n", ret);

>-out:

>-	of_node_put(np);

> 	return ret;

> }

>+

>+static struct platform_driver psci_cpuidle_domain_driver = {

>+	.probe  = psci_cpuidle_domain_probe,

>+	.driver = {

>+		.name = "psci-cpuidle-domain",

>+		.of_match_table = psci_of_match,

>+	},

>+};

>+

>+static int __init psci_idle_init_domains(void)

>+{

>+	return platform_driver_register(&psci_cpuidle_domain_driver);

>+}

> subsys_initcall(psci_idle_init_domains);

>

> struct device *psci_dt_attach_cpu(int cpu)

>-- 

>2.20.1

>
diff mbox series

Patch

diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c
index e48e578aaa7d..bf527d2bb4b6 100644
--- a/drivers/cpuidle/cpuidle-psci-domain.c
+++ b/drivers/cpuidle/cpuidle-psci-domain.c
@@ -12,6 +12,7 @@ 
 #include <linux/cpu.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
+#include <linux/platform_device.h>
 #include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 #include <linux/psci.h>
@@ -42,8 +43,8 @@  static int psci_pd_power_off(struct generic_pm_domain *pd)
 	return 0;
 }
 
-static int __init psci_pd_parse_state_nodes(struct genpd_power_state *states,
-					int state_count)
+static int psci_pd_parse_state_nodes(struct genpd_power_state *states,
+				     int state_count)
 {
 	int i, ret;
 	u32 psci_state, *psci_state_buf;
@@ -72,7 +73,7 @@  static int __init psci_pd_parse_state_nodes(struct genpd_power_state *states,
 	return ret;
 }
 
-static int __init psci_pd_parse_states(struct device_node *np,
+static int psci_pd_parse_states(struct device_node *np,
 			struct genpd_power_state **states, int *state_count)
 {
 	int ret;
@@ -100,7 +101,7 @@  static void psci_pd_free_states(struct genpd_power_state *states,
 	kfree(states);
 }
 
-static int __init psci_pd_init(struct device_node *np)
+static int psci_pd_init(struct device_node *np)
 {
 	struct generic_pm_domain *pd;
 	struct psci_pd_provider *pd_provider;
@@ -167,7 +168,7 @@  static int __init psci_pd_init(struct device_node *np)
 	return ret;
 }
 
-static void __init psci_pd_remove(void)
+static void psci_pd_remove(void)
 {
 	struct psci_pd_provider *pd_provider, *it;
 	struct generic_pm_domain *genpd;
@@ -185,7 +186,7 @@  static void __init psci_pd_remove(void)
 	}
 }
 
-static int __init psci_pd_init_topology(struct device_node *np, bool add)
+static int psci_pd_init_topology(struct device_node *np, bool add)
 {
 	struct device_node *node;
 	struct of_phandle_args child, parent;
@@ -211,24 +212,24 @@  static int __init psci_pd_init_topology(struct device_node *np, bool add)
 	return 0;
 }
 
-static int __init psci_pd_add_topology(struct device_node *np)
+static int psci_pd_add_topology(struct device_node *np)
 {
 	return psci_pd_init_topology(np, true);
 }
 
-static void __init psci_pd_remove_topology(struct device_node *np)
+static void psci_pd_remove_topology(struct device_node *np)
 {
 	psci_pd_init_topology(np, false);
 }
 
-static const struct of_device_id psci_of_match[] __initconst = {
+static const struct of_device_id psci_of_match[] = {
 	{ .compatible = "arm,psci-1.0" },
 	{}
 };
 
-static int __init psci_idle_init_domains(void)
+static int psci_cpuidle_domain_probe(struct platform_device *pdev)
 {
-	struct device_node *np = of_find_matching_node(NULL, psci_of_match);
+	struct device_node *np = pdev->dev.of_node;
 	struct device_node *node;
 	int ret = 0, pd_count = 0;
 
@@ -237,7 +238,7 @@  static int __init psci_idle_init_domains(void)
 
 	/* Currently limit the hierarchical topology to be used in OSI mode. */
 	if (!psci_has_osi_support())
-		goto out;
+		return 0;
 
 	/*
 	 * Parse child nodes for the "#power-domain-cells" property and
@@ -256,7 +257,7 @@  static int __init psci_idle_init_domains(void)
 
 	/* Bail out if not using the hierarchical CPU topology. */
 	if (!pd_count)
-		goto out;
+		return 0;
 
 	/* Link genpd masters/subdomains to model the CPU topology. */
 	ret = psci_pd_add_topology(np);
@@ -271,9 +272,8 @@  static int __init psci_idle_init_domains(void)
 		goto remove_pd;
 	}
 
-	of_node_put(np);
 	pr_info("Initialized CPU PM domain topology\n");
-	return pd_count;
+	return 0;
 
 put_node:
 	of_node_put(node);
@@ -281,10 +281,21 @@  static int __init psci_idle_init_domains(void)
 	if (pd_count)
 		psci_pd_remove();
 	pr_err("failed to create CPU PM domains ret=%d\n", ret);
-out:
-	of_node_put(np);
 	return ret;
 }
+
+static struct platform_driver psci_cpuidle_domain_driver = {
+	.probe  = psci_cpuidle_domain_probe,
+	.driver = {
+		.name = "psci-cpuidle-domain",
+		.of_match_table = psci_of_match,
+	},
+};
+
+static int __init psci_idle_init_domains(void)
+{
+	return platform_driver_register(&psci_cpuidle_domain_driver);
+}
 subsys_initcall(psci_idle_init_domains);
 
 struct device *psci_dt_attach_cpu(int cpu)