[PATCH v2 2/2] clk: qoriq: add cpufreq platform device

2020-04-21 Thread Mian Yousaf Kaukab
Add a platform device for qoirq-cpufreq driver for the compatible
clockgen blocks.

Reviewed-by: Yuantian Tang 
Acked-by: Viresh Kumar 
Signed-off-by: Mian Yousaf Kaukab 
---
v2:
 +Rafael, Stephen, linux-clk
 Add Reviewed-by and Acked-by tags

 drivers/clk/clk-qoriq.c | 30 +++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk-qoriq.c b/drivers/clk/clk-qoriq.c
index d5946f7486d6..374afcab89af 100644
--- a/drivers/clk/clk-qoriq.c
+++ b/drivers/clk/clk-qoriq.c
@@ -95,6 +95,7 @@ struct clockgen {
 };
 
 static struct clockgen clockgen;
+static bool add_cpufreq_dev __initdata;
 
 static void cg_out(struct clockgen *cg, u32 val, u32 __iomem *reg)
 {
@@ -1019,7 +1020,7 @@ static void __init create_muxes(struct clockgen *cg)
}
 }
 
-static void __init clockgen_init(struct device_node *np);
+static void __init _clockgen_init(struct device_node *np, bool legacy);
 
 /*
  * Legacy nodes may get probed before the parent clockgen node.
@@ -1030,7 +1031,7 @@ static void __init clockgen_init(struct device_node *np);
 static void __init legacy_init_clockgen(struct device_node *np)
 {
if (!clockgen.node)
-   clockgen_init(of_get_parent(np));
+   _clockgen_init(of_get_parent(np), true);
 }
 
 /* Legacy node */
@@ -1447,7 +1448,7 @@ static bool __init has_erratum_a4510(void)
 }
 #endif
 
-static void __init clockgen_init(struct device_node *np)
+static void __init _clockgen_init(struct device_node *np, bool legacy)
 {
int i, ret;
bool is_old_ls1021a = false;
@@ -1516,12 +1517,35 @@ static void __init clockgen_init(struct device_node *np)
   __func__, np, ret);
}
 
+   /* Don't create cpufreq device for legacy clockgen blocks */
+   add_cpufreq_dev = !legacy;
+
return;
 err:
iounmap(clockgen.regs);
clockgen.regs = NULL;
 }
 
+static void __init clockgen_init(struct device_node *np)
+{
+   _clockgen_init(np, false);
+}
+
+static int __init clockgen_cpufreq_init(void)
+{
+   struct platform_device *pdev;
+
+   if (add_cpufreq_dev) {
+   pdev = platform_device_register_simple("qoriq-cpufreq", -1,
+   NULL, 0);
+   if (IS_ERR(pdev))
+   pr_err("Couldn't register qoriq-cpufreq err=%ld\n",
+   PTR_ERR(pdev));
+   }
+   return 0;
+}
+device_initcall(clockgen_cpufreq_init);
+
 CLK_OF_DECLARE(qoriq_clockgen_1, "fsl,qoriq-clockgen-1.0", clockgen_init);
 CLK_OF_DECLARE(qoriq_clockgen_2, "fsl,qoriq-clockgen-2.0", clockgen_init);
 CLK_OF_DECLARE(qoriq_clockgen_b4420, "fsl,b4420-clockgen", clockgen_init);
-- 
2.16.4



[PATCH v2 1/2] cpufreq: qoriq: convert to a platform driver

2020-04-21 Thread Mian Yousaf Kaukab
The driver has to be manually loaded if it is built as a module. It
is neither exporting MODULE_DEVICE_TABLE nor MODULE_ALIAS. Moreover,
no platform-device is created (and thus no uevent is sent) for the
clockgen nodes it depends on.

Convert the module to a platform driver with its own alias. Moreover,
drop whitelisted SOCs. Platform device will be created only for the
compatible platforms.

Reviewed-by: Yuantian Tang 
Acked-by: Viresh Kumar 
Signed-off-by: Mian Yousaf Kaukab 
---
v2:
 +Rafael, Stephen, linux-clk
 Add Reviewed-by and Acked-by tags

 drivers/cpufreq/qoriq-cpufreq.c | 76 -
 1 file changed, 29 insertions(+), 47 deletions(-)

diff --git a/drivers/cpufreq/qoriq-cpufreq.c b/drivers/cpufreq/qoriq-cpufreq.c
index 8e436dc75c8b..6b6b20da2bcf 100644
--- a/drivers/cpufreq/qoriq-cpufreq.c
+++ b/drivers/cpufreq/qoriq-cpufreq.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct cpu_data
@@ -29,12 +30,6 @@ struct cpu_data {
struct cpufreq_frequency_table *table;
 };
 
-/*
- * Don't use cpufreq on this SoC -- used when the SoC would have otherwise
- * matched a more generic compatible.
- */
-#define SOC_BLACKLIST  1
-
 /**
  * struct soc_data - SoC specific data
  * @flags: SOC_xxx
@@ -264,64 +259,51 @@ static struct cpufreq_driver qoriq_cpufreq_driver = {
.attr   = cpufreq_generic_attr,
 };
 
-static const struct soc_data blacklist = {
-   .flags = SOC_BLACKLIST,
-};
-
-static const struct of_device_id node_matches[] __initconst = {
+static const struct of_device_id qoriq_cpufreq_blacklist[] = {
/* e6500 cannot use cpufreq due to erratum A-008083 */
-   { .compatible = "fsl,b4420-clockgen",  },
-   { .compatible = "fsl,b4860-clockgen",  },
-   { .compatible = "fsl,t2080-clockgen",  },
-   { .compatible = "fsl,t4240-clockgen",  },
-
-   { .compatible = "fsl,ls1012a-clockgen", },
-   { .compatible = "fsl,ls1021a-clockgen", },
-   { .compatible = "fsl,ls1028a-clockgen", },
-   { .compatible = "fsl,ls1043a-clockgen", },
-   { .compatible = "fsl,ls1046a-clockgen", },
-   { .compatible = "fsl,ls1088a-clockgen", },
-   { .compatible = "fsl,ls2080a-clockgen", },
-   { .compatible = "fsl,lx2160a-clockgen", },
-   { .compatible = "fsl,p4080-clockgen", },
-   { .compatible = "fsl,qoriq-clockgen-1.0", },
-   { .compatible = "fsl,qoriq-clockgen-2.0", },
+   { .compatible = "fsl,b4420-clockgen", },
+   { .compatible = "fsl,b4860-clockgen", },
+   { .compatible = "fsl,t2080-clockgen", },
+   { .compatible = "fsl,t4240-clockgen", },
{}
 };
 
-static int __init qoriq_cpufreq_init(void)
+static int qoriq_cpufreq_probe(struct platform_device *pdev)
 {
int ret;
-   struct device_node  *np;
-   const struct of_device_id *match;
-   const struct soc_data *data;
-
-   np = of_find_matching_node(NULL, node_matches);
-   if (!np)
-   return -ENODEV;
-
-   match = of_match_node(node_matches, np);
-   data = match->data;
-
-   of_node_put(np);
+   struct device_node *np;
 
-   if (data && data->flags & SOC_BLACKLIST)
+   np = of_find_matching_node(NULL, qoriq_cpufreq_blacklist);
+   if (np) {
+   dev_info(>dev, "Disabling due to erratum A-008083");
return -ENODEV;
+   }
 
ret = cpufreq_register_driver(_cpufreq_driver);
-   if (!ret)
-   pr_info("Freescale QorIQ CPU frequency scaling driver\n");
+   if (ret)
+   return ret;
 
-   return ret;
+   dev_info(>dev, "Freescale QorIQ CPU frequency scaling driver\n");
+   return 0;
 }
-module_init(qoriq_cpufreq_init);
 
-static void __exit qoriq_cpufreq_exit(void)
+static int qoriq_cpufreq_remove(struct platform_device *pdev)
 {
cpufreq_unregister_driver(_cpufreq_driver);
+
+   return 0;
 }
-module_exit(qoriq_cpufreq_exit);
 
+static struct platform_driver qoriq_cpufreq_platform_driver = {
+   .driver = {
+   .name = "qoriq-cpufreq",
+   },
+   .probe = qoriq_cpufreq_probe,
+   .remove = qoriq_cpufreq_remove,
+};
+module_platform_driver(qoriq_cpufreq_platform_driver);
+
+MODULE_ALIAS("platform:qoriq-cpufreq");
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Tang Yuantian ");
 MODULE_DESCRIPTION("cpufreq driver for Freescale QorIQ series SoCs");
-- 
2.16.4



[PATCH 1/2] cpufreq: qoriq: convert to a platform driver

2020-04-03 Thread Mian Yousaf Kaukab
The driver has to be manually loaded if it is built as a module. It
is neither exporting MODULE_DEVICE_TABLE nor MODULE_ALIAS. Moreover,
no platform-device is created (and thus no uevent is sent) for the
clockgen nodes it depends on.

Convert the module to a platform driver with its own alias. Moreover,
drop whitelisted SOCs. Platform device will be created only for the
compatible platforms.

Signed-off-by: Mian Yousaf Kaukab 
---
 drivers/cpufreq/qoriq-cpufreq.c | 76 -
 1 file changed, 29 insertions(+), 47 deletions(-)

diff --git a/drivers/cpufreq/qoriq-cpufreq.c b/drivers/cpufreq/qoriq-cpufreq.c
index 8e436dc75c8b..6b6b20da2bcf 100644
--- a/drivers/cpufreq/qoriq-cpufreq.c
+++ b/drivers/cpufreq/qoriq-cpufreq.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct cpu_data
@@ -29,12 +30,6 @@ struct cpu_data {
struct cpufreq_frequency_table *table;
 };
 
-/*
- * Don't use cpufreq on this SoC -- used when the SoC would have otherwise
- * matched a more generic compatible.
- */
-#define SOC_BLACKLIST  1
-
 /**
  * struct soc_data - SoC specific data
  * @flags: SOC_xxx
@@ -264,64 +259,51 @@ static struct cpufreq_driver qoriq_cpufreq_driver = {
.attr   = cpufreq_generic_attr,
 };
 
-static const struct soc_data blacklist = {
-   .flags = SOC_BLACKLIST,
-};
-
-static const struct of_device_id node_matches[] __initconst = {
+static const struct of_device_id qoriq_cpufreq_blacklist[] = {
/* e6500 cannot use cpufreq due to erratum A-008083 */
-   { .compatible = "fsl,b4420-clockgen",  },
-   { .compatible = "fsl,b4860-clockgen",  },
-   { .compatible = "fsl,t2080-clockgen",  },
-   { .compatible = "fsl,t4240-clockgen",  },
-
-   { .compatible = "fsl,ls1012a-clockgen", },
-   { .compatible = "fsl,ls1021a-clockgen", },
-   { .compatible = "fsl,ls1028a-clockgen", },
-   { .compatible = "fsl,ls1043a-clockgen", },
-   { .compatible = "fsl,ls1046a-clockgen", },
-   { .compatible = "fsl,ls1088a-clockgen", },
-   { .compatible = "fsl,ls2080a-clockgen", },
-   { .compatible = "fsl,lx2160a-clockgen", },
-   { .compatible = "fsl,p4080-clockgen", },
-   { .compatible = "fsl,qoriq-clockgen-1.0", },
-   { .compatible = "fsl,qoriq-clockgen-2.0", },
+   { .compatible = "fsl,b4420-clockgen", },
+   { .compatible = "fsl,b4860-clockgen", },
+   { .compatible = "fsl,t2080-clockgen", },
+   { .compatible = "fsl,t4240-clockgen", },
{}
 };
 
-static int __init qoriq_cpufreq_init(void)
+static int qoriq_cpufreq_probe(struct platform_device *pdev)
 {
int ret;
-   struct device_node  *np;
-   const struct of_device_id *match;
-   const struct soc_data *data;
-
-   np = of_find_matching_node(NULL, node_matches);
-   if (!np)
-   return -ENODEV;
-
-   match = of_match_node(node_matches, np);
-   data = match->data;
-
-   of_node_put(np);
+   struct device_node *np;
 
-   if (data && data->flags & SOC_BLACKLIST)
+   np = of_find_matching_node(NULL, qoriq_cpufreq_blacklist);
+   if (np) {
+   dev_info(>dev, "Disabling due to erratum A-008083");
return -ENODEV;
+   }
 
ret = cpufreq_register_driver(_cpufreq_driver);
-   if (!ret)
-   pr_info("Freescale QorIQ CPU frequency scaling driver\n");
+   if (ret)
+   return ret;
 
-   return ret;
+   dev_info(>dev, "Freescale QorIQ CPU frequency scaling driver\n");
+   return 0;
 }
-module_init(qoriq_cpufreq_init);
 
-static void __exit qoriq_cpufreq_exit(void)
+static int qoriq_cpufreq_remove(struct platform_device *pdev)
 {
cpufreq_unregister_driver(_cpufreq_driver);
+
+   return 0;
 }
-module_exit(qoriq_cpufreq_exit);
 
+static struct platform_driver qoriq_cpufreq_platform_driver = {
+   .driver = {
+   .name = "qoriq-cpufreq",
+   },
+   .probe = qoriq_cpufreq_probe,
+   .remove = qoriq_cpufreq_remove,
+};
+module_platform_driver(qoriq_cpufreq_platform_driver);
+
+MODULE_ALIAS("platform:qoriq-cpufreq");
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Tang Yuantian ");
 MODULE_DESCRIPTION("cpufreq driver for Freescale QorIQ series SoCs");
-- 
2.16.4



[PATCH 2/2] clk: qoriq: add cpufreq platform device

2020-04-03 Thread Mian Yousaf Kaukab
Add a platform device for qoirq-cpufreq driver for the compatible
clockgen blocks.

Signed-off-by: Mian Yousaf Kaukab 
---
 drivers/clk/clk-qoriq.c | 30 +++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk-qoriq.c b/drivers/clk/clk-qoriq.c
index d5946f7486d6..374afcab89af 100644
--- a/drivers/clk/clk-qoriq.c
+++ b/drivers/clk/clk-qoriq.c
@@ -95,6 +95,7 @@ struct clockgen {
 };
 
 static struct clockgen clockgen;
+static bool add_cpufreq_dev __initdata;
 
 static void cg_out(struct clockgen *cg, u32 val, u32 __iomem *reg)
 {
@@ -1019,7 +1020,7 @@ static void __init create_muxes(struct clockgen *cg)
}
 }
 
-static void __init clockgen_init(struct device_node *np);
+static void __init _clockgen_init(struct device_node *np, bool legacy);
 
 /*
  * Legacy nodes may get probed before the parent clockgen node.
@@ -1030,7 +1031,7 @@ static void __init clockgen_init(struct device_node *np);
 static void __init legacy_init_clockgen(struct device_node *np)
 {
if (!clockgen.node)
-   clockgen_init(of_get_parent(np));
+   _clockgen_init(of_get_parent(np), true);
 }
 
 /* Legacy node */
@@ -1447,7 +1448,7 @@ static bool __init has_erratum_a4510(void)
 }
 #endif
 
-static void __init clockgen_init(struct device_node *np)
+static void __init _clockgen_init(struct device_node *np, bool legacy)
 {
int i, ret;
bool is_old_ls1021a = false;
@@ -1516,12 +1517,35 @@ static void __init clockgen_init(struct device_node *np)
   __func__, np, ret);
}
 
+   /* Don't create cpufreq device for legacy clockgen blocks */
+   add_cpufreq_dev = !legacy;
+
return;
 err:
iounmap(clockgen.regs);
clockgen.regs = NULL;
 }
 
+static void __init clockgen_init(struct device_node *np)
+{
+   _clockgen_init(np, false);
+}
+
+static int __init clockgen_cpufreq_init(void)
+{
+   struct platform_device *pdev;
+
+   if (add_cpufreq_dev) {
+   pdev = platform_device_register_simple("qoriq-cpufreq", -1,
+   NULL, 0);
+   if (IS_ERR(pdev))
+   pr_err("Couldn't register qoriq-cpufreq err=%ld\n",
+   PTR_ERR(pdev));
+   }
+   return 0;
+}
+device_initcall(clockgen_cpufreq_init);
+
 CLK_OF_DECLARE(qoriq_clockgen_1, "fsl,qoriq-clockgen-1.0", clockgen_init);
 CLK_OF_DECLARE(qoriq_clockgen_2, "fsl,qoriq-clockgen-2.0", clockgen_init);
 CLK_OF_DECLARE(qoriq_clockgen_b4420, "fsl,b4420-clockgen", clockgen_init);
-- 
2.16.4