Skip to contentSkip to conversation

MIPS: Loongson: Make CPUFreq usable for Loongson-3

PATCH In review Huacai Chen 1 participant 1 message Mar 29, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v9 7/7 MIPS: Loongson: Make CPUFreq usable for Loongson-3

Loongson-3A/3B support frequency scaling. But due to hardware limitation, Loongson-3A's frequency scaling is not independent for each core, we suggest enable Loongson-3A's CPUFreq only when there is one core online. Loongson-3B can adjust frequency independently for each core, so it can be always enabled.

Each package has only one register (ChipConfig or FreqCtrl) to control frequency, so we need spinlocks to protect register access for multi- cores. However, we cannot use spinlock when a core becomes into "wait" status (frequency = 0), so we only enable "wait" when there is one core in a package online.

arch/mips/kernel/smp.c is modified to guarantee udelay_val has the correct value while both CPU hotplug and CPUFreq are enabled.

---
 arch/mips/include/asm/mach-loongson/loongson.h |    1 +
 arch/mips/kernel/smp.c                         |    3 +-
 arch/mips/loongson/Kconfig                     |    1 +
 arch/mips/loongson/common/platform.c           |   13 +-
 arch/mips/loongson/loongson-3/Makefile         |    2 +-
 arch/mips/loongson/loongson-3/clock.c          |  191 +++++++++++++++++++
 drivers/cpufreq/Kconfig                        |   15 ++
 drivers/cpufreq/Makefile                       |    1 +
 drivers/cpufreq/loongson3_cpufreq.c            |  240 ++++++++++++++++++++++++
 9 files changed, 462 insertions(+), 5 deletions(-)
 create mode 100644 arch/mips/loongson/loongson-3/clock.c
 create mode 100644 drivers/cpufreq/loongson3_cpufreq.c
arch/mips/include/asm/mach-loongson/loongson.h +1 -0
index 9783103..ee18a50 100644
@@ -278,6 +278,7 @@ extern u64 loongson_freqctrl[MAX_PACKAGES];
 #ifdef CONFIG_CPU_SUPPORTS_CPUFREQ
 #include <linux/cpufreq.h>
 extern struct cpufreq_frequency_table loongson2_clockmod_table[];
+extern struct cpufreq_frequency_table loongson3_clockmod_table[];
 #endif
 
 /*
arch/mips/kernel/smp.c +2 -1
index 5b020bd..a2d716c 100644
@@ -136,7 +136,8 @@ asmlinkage void start_secondary(void)
 	calibrate_delay();
 	preempt_disable();
 	cpu = smp_processor_id();
-	cpu_data[cpu].udelay_val = loops_per_jiffy;
+	if (!cpu_data[cpu].udelay_val)
+		cpu_data[cpu].udelay_val = loops_per_jiffy;
 
 	cpu_set(cpu, cpu_coherent_mask);
 	notify_cpu_starting(cpu);
arch/mips/loongson/Kconfig +1 -0
index 156de85..58a926a 100644
@@ -69,6 +69,7 @@ config LOONGSON_MACH3X
 	select CSRC_R4K
 	select CEVT_R4K
 	select CPU_HAS_WB
+	select HAVE_CLK
 	select HW_HAS_PCI
 	select ISA
 	select HT_PCI
arch/mips/loongson/common/platform.c +10 -3
index 0ed3832..7dd5ed4 100644
@@ -17,15 +17,22 @@ static struct platform_device loongson2_cpufreq_device = {
 	.id = -1,
 };
 
-static int __init loongson2_cpufreq_init(void)
+static struct platform_device loongson3_cpufreq_device = {
+	.name = "loongson3_cpufreq",
+	.id = -1,
+};
+
+static int __init loongson_cpufreq_init(void)
 {
 	struct cpuinfo_mips *c = &current_cpu_data;
 
 	/* Only 2F revision and it's successors support CPUFreq */
-	if ((c->processor_id & PRID_REV_MASK) >= PRID_REV_LOONGSON2F)
+	if ((c->processor_id & PRID_REV_MASK) == PRID_REV_LOONGSON2F)
 		return platform_device_register(&loongson2_cpufreq_device);
+	if ((c->processor_id & PRID_REV_MASK) >= PRID_REV_LOONGSON3A)
+		return platform_device_register(&loongson3_cpufreq_device);
 
 	return -ENODEV;
 }
 
-arch_initcall(loongson2_cpufreq_init);
+arch_initcall(loongson_cpufreq_init);
arch/mips/loongson/loongson-3/Makefile +1 -1
index 622fead..1be6a0c 100644
@@ -1,7 +1,7 @@
 #
 # Makefile for Loongson-3 family machines
 #
-obj-y			+= irq.o cop2-ex.o platform.o
+obj-y			+= irq.o cop2-ex.o platform.o clock.o
 
 obj-$(CONFIG_SMP)	+= smp.o
 
arch/mips/loongson/loongson-3/clock.c new file +191 -0

191 lines not on this page · raw message

drivers/cpufreq/Kconfig +15 -0
index a171fef..e67abbe 100644
@@ -236,6 +236,7 @@ endif
 if MIPS
 config LOONGSON2_CPUFREQ
 	tristate "Loongson2 CPUFreq Driver"
+	depends on CPU_LOONGSON2
 	help
 	  This option adds a CPUFreq driver for loongson processors which
 	  support software configurable cpu frequency.
@@ -246,8 +247,22 @@ config LOONGSON2_CPUFREQ
 
 	  If in doubt, say N.
 
+config LOONGSON3_CPUFREQ
+	tristate "Loongson3 CPUFreq Driver"
+	depends on CPU_LOONGSON3
+	help
+	  This option adds a CPUFreq driver for loongson processors which
+	  support software configurable cpu frequency.
+
+	  Loongson-3A and it's successors support this feature.
+
+	  For details, take a look at <file:Documentation/cpu-freq/>.
+
+	  If in doubt, say N.
+
 config LOONGSON1_CPUFREQ
 	tristate "Loongson1 CPUFreq Driver"
+	depends on CPU_LOONGSON1
 	help
 	  This option adds a CPUFreq driver for loongson1 processors which
 	  support software configurable cpu frequency.
drivers/cpufreq/Makefile +1 -0
index 82a1821..520b09f 100644
@@ -99,6 +99,7 @@ obj-$(CONFIG_CRIS_MACH_ARTPEC3)		+= cris-artpec3-cpufreq.o
 obj-$(CONFIG_ETRAXFS)			+= cris-etraxfs-cpufreq.o
 obj-$(CONFIG_IA64_ACPI_CPUFREQ)		+= ia64-acpi-cpufreq.o
 obj-$(CONFIG_LOONGSON2_CPUFREQ)		+= loongson2_cpufreq.o
+obj-$(CONFIG_LOONGSON3_CPUFREQ)		+= loongson3_cpufreq.o
 obj-$(CONFIG_LOONGSON1_CPUFREQ)		+= ls1x-cpufreq.o
 obj-$(CONFIG_SH_CPU_FREQ)		+= sh-cpufreq.o
 obj-$(CONFIG_SPARC_US2E_CPUFREQ)	+= sparc-us2e-cpufreq.o
drivers/cpufreq/loongson3_cpufreq.c new file +240 -0

240 lines not on this page · raw message

Signature · 1 line
1.7.7.3