Skip to contentSkip to conversation

cpufreq: probe the Integrator cpufreq driver from DT

PATCH Superseded Linus Walleij 2 participants 3 messages Oct 3, 2013 – Oct 10, 2013 CPU frequency scaling framework

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 6/6 cpufreq: probe the Integrator cpufreq driver from DT

This makes the Integrator cpufreq driver probe from the core module device tree node through it's registered platforms device, getting the memory base from the device tree, remapping it and removing dependencies to <mach/platform.h> and <mach/hardware.h> by moving the two affected CM register offsets into the driver.

---
 drivers/cpufreq/integrator-cpufreq.c | 56 ++++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 18 deletions(-)
drivers/cpufreq/integrator-cpufreq.c +38 -18
index f7c99df..9faf0ca 100644
@@ -15,18 +15,19 @@
 #include <linux/smp.h>
 #include <linux/init.h>
 #include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
 
-#include <mach/hardware.h>
-#include <mach/platform.h>
 #include <asm/mach-types.h>
 #include <asm/hardware/icst.h>
 
-static struct cpufreq_driver integrator_driver;
+static void __iomem *cm_base;
+/* The cpufreq driver only use the OSC register */
+#define INTEGRATOR_HDR_OSC_OFFSET       0x08
+#define INTEGRATOR_HDR_LOCK_OFFSET      0x14
 
-#define CM_ID  	__io_address(INTEGRATOR_HDR_ID)
-#define CM_OSC	__io_address(INTEGRATOR_HDR_OSC)
-#define CM_STAT __io_address(INTEGRATOR_HDR_STAT)
-#define CM_LOCK __io_address(INTEGRATOR_HDR_LOCK)
+static struct cpufreq_driver integrator_driver;
 
 static const struct icst_params lclk_params = {
 	.ref		= 24000000,
@@ -100,7 +101,7 @@ static int integrator_set_target(struct cpufreq_policy *policy,
 	BUG_ON(cpu != smp_processor_id());
 
 	/* get current setting */
-	cm_osc = __raw_readl(CM_OSC);
+	cm_osc = __raw_readl(cm_base + INTEGRATOR_HDR_OSC_OFFSET);
 
 	if (machine_is_integrator()) {
 		vco.s = (cm_osc >> 8) & 7;
@@ -128,7 +129,7 @@ static int integrator_set_target(struct cpufreq_policy *policy,
 
 	cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
 
-	cm_osc = __raw_readl(CM_OSC);
+	cm_osc = __raw_readl(cm_base + INTEGRATOR_HDR_OSC_OFFSET);
 
 	if (machine_is_integrator()) {
 		cm_osc &= 0xfffff800;
@@ -138,9 +139,9 @@ static int integrator_set_target(struct cpufreq_policy *policy,
 	}
 	cm_osc |= vco.v;
 
-	__raw_writel(0xa05f, CM_LOCK);
-	__raw_writel(cm_osc, CM_OSC);
-	__raw_writel(0, CM_LOCK);
+	__raw_writel(0xa05f, cm_base + INTEGRATOR_HDR_LOCK_OFFSET);
+	__raw_writel(cm_osc, cm_base + INTEGRATOR_HDR_OSC_OFFSET);
+	__raw_writel(0, cm_base + INTEGRATOR_HDR_LOCK_OFFSET);
 
 	/*
 	 * Restore the CPUs allowed mask.
@@ -165,7 +166,7 @@ static unsigned int integrator_get(unsigned int cpu)
 	BUG_ON(cpu != smp_processor_id());
 
 	/* detect memory etc. */
-	cm_osc = __raw_readl(CM_OSC);
+	cm_osc = __raw_readl(cm_base + INTEGRATOR_HDR_OSC_OFFSET);
 
 	if (machine_is_integrator()) {
 		vco.s = (cm_osc >> 8) & 7;
@@ -202,19 +203,38 @@ static struct cpufreq_driver integrator_driver = {
 	.name		= "integrator",
 };
 
-static int __init integrator_cpu_init(void)
+static int __init integrator_cpufreq_probe(struct platform_device *pdev)
 {
+	struct device_node *np = pdev->dev.of_node;
+
+	cm_base = of_iomap(np, 0);
+	if (!cm_base)
+		return -ENODEV;
 	return cpufreq_register_driver(&integrator_driver);
 }
 
-static void __exit integrator_cpu_exit(void)
+static void __exit integrator_cpufreq_remove(struct platform_device *pdev)
 {
 	cpufreq_unregister_driver(&integrator_driver);
 }
 
+static const struct of_device_id integrator_cpufreq_match[] = {
+	{ .compatible = "arm,core-module-integrator"},
+	{ },
+};
+
+static struct platform_driver integrator_cpufreq_driver = {
+	.driver = {
+		.name = "integrator-cpufreq",
+		.owner = THIS_MODULE,
+		.of_match_table = integrator_cpufreq_match,
+	},
+	.remove = __exit_p(integrator_cpufreq_remove),
+};
+
+module_platform_driver_probe(integrator_cpufreq_driver,
+			     integrator_cpufreq_probe);
+
 MODULE_AUTHOR ("Russell M. King");
 MODULE_DESCRIPTION ("cpufreq driver for ARM Integrator CPUs");
 MODULE_LICENSE ("GPL");
-
-module_init(integrator_cpu_init);
-module_exit(integrator_cpu_exit);
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 6/6 cpufreq: probe the Integrator cpufreq driver from DT

[adding devicetree to Cc]

Hi Linus,

[...]

drivers/cpufreq/integrator-cpufreq.c static struct cpufreq_driver integrator_driver = { · line 213

Quoted 8 lines
drivers/cpufreq/integrator-cpufreq.c +6 -0
+static int __init integrator_cpufreq_probe(struct platform_device *pdev)
 {
+	struct device_node *np = pdev->dev.of_node;
+
+	cm_base = of_iomap(np, 0);
+	if (!cm_base)
+		return -ENODEV;
 	return cpufreq_register_driver(&integrator_driver);

If we fail to register the driver we could unmap cm_base, no?

drivers/cpufreq/integrator-cpufreq.c static struct cpufreq_driver integrator_driver = { · line 218

Quoted 6 lines

}

drivers/cpufreq/integrator-cpufreq.c +1 -1
-static void __exit integrator_cpu_exit(void)
+static void __exit integrator_cpufreq_remove(struct platform_device *pdev)
 {
 	cpufreq_unregister_driver(&integrator_driver);

Unmap here?

drivers/cpufreq/integrator-cpufreq.c static struct cpufreq_driver integrator_driver = { · line 224

Quoted 6 lines

}

drivers/cpufreq/integrator-cpufreq.c +4 -0
+static const struct of_device_id integrator_cpufreq_match[] = {
+	{ .compatible = "arm,core-module-integrator"},
+	{ },
+};

It feels a little scary that this also got handled by some other code in the previous patch. Is no arbitrarion required between the two when accessing the core module registers?

Cheers,
Mark.

#2 lore raw

PATCH 6/6 cpufreq: probe the Integrator cpufreq driver from DT

Quoted 10 lines · Mark Rutland

drivers/cpufreq/integrator-cpufreq.c static struct cpufreq_driver integrator_driver = { · line 213

Quoted 8 lines
drivers/cpufreq/integrator-cpufreq.c +6 -0
+static int __init integrator_cpufreq_probe(struct platform_device *pdev)
 {
+     struct device_node *np = pdev->dev.of_node;
+
+     cm_base = of_iomap(np, 0);
+     if (!cm_base)
+             return -ENODEV;
      return cpufreq_register_driver(&integrator_driver);

If we fail to register the driver we could unmap cm_base, no?

Using devm_* is better so I'll revise it to do this.

Quoted 6 lines

drivers/cpufreq/integrator-cpufreq.c static struct cpufreq_driver integrator_driver = { · line 218

Quoted 4 lines
drivers/cpufreq/integrator-cpufreq.c +1 -1
-static void __exit integrator_cpu_exit(void)
+static void __exit integrator_cpufreq_remove(struct platform_device *pdev)
 {
      cpufreq_unregister_driver(&integrator_driver);

Unmap here?

Dito. Check v2.

Quoted 8 lines

drivers/cpufreq/integrator-cpufreq.c static struct cpufreq_driver integrator_driver = { · line 224

Quoted 4 lines
drivers/cpufreq/integrator-cpufreq.c +4 -0
+static const struct of_device_id integrator_cpufreq_match[] = {
+     { .compatible = "arm,core-module-integrator"},
+     { },
+};

It feels a little scary that this also got handled by some other code in the previous patch. Is no arbitrarion required between the two when accessing the core module registers?

They are using totally different registers, so it should not be an issue. Inside the mach folder there is some arbitration for the register that is actually accessed by several consumers.

Yours,
Linus Walleij