Add CPUFreq support for loongson2f
cover Add CPUFreq support for loongson2f
This patchset adds CPUFreq support for loongson2f, 'Cause loongson2f doesn't have a fixed MIPS Timer(relative to cpu frequency), If we enable CPUFreq, the system time will be broken. So, an external Timer is needed, Herein, In Lemote loongson2f family machine, there is a CS5536 MFGPT Timer, in Dexxon Gdium, it use i8253.
This v1 revision have incorporated with the feedbacks from "Dominik Brodowski" and Ralf. And this Thread have replied more feedbacks from Ralf:
http://www.linux-mips.org/archives/linux-mips/2009-11/msg00292.html
Best Regards,
Wu Zhangjin
Wu Zhangjin (3):
[loongson] lemote-2f: add cs5536 MFGPT timer support
MIPS: add basic options for CPUFreq support [loongson] 2f: add CPUFreq support
arch/mips/Kconfig | 3 + arch/mips/include/asm/clock.h | 64 ++++++ .../asm/mach-loongson/cs5536/cs5536_mfgpt.h | 35 +++ arch/mips/include/asm/mach-loongson/loongson.h | 6 +- arch/mips/kernel/Makefile | 2 + arch/mips/kernel/cpu-probe.c | 2 + arch/mips/kernel/cpufreq/Kconfig | 41 ++++ arch/mips/kernel/cpufreq/Makefile | 5 + arch/mips/kernel/cpufreq/loongson2_clock.c | 166 +++++++++++++++ arch/mips/kernel/cpufreq/loongson2_cpufreq.c | 202 ++++++++++++++++++ arch/mips/loongson/Kconfig | 16 ++- arch/mips/loongson/common/cs5536/Makefile | 5 + arch/mips/loongson/common/cs5536/cs5536_mfgpt.c | 217 ++++++++++++++++++++ arch/mips/loongson/common/env.c | 3 + arch/mips/loongson/common/time.c | 3 + 15 files changed, 767 insertions(+), 3 deletions(-) create mode 100644 arch/mips/include/asm/clock.h create mode 100644 arch/mips/include/asm/mach-loongson/cs5536/cs5536_mfgpt.h create mode 100644 arch/mips/kernel/cpufreq/Kconfig create mode 100644 arch/mips/kernel/cpufreq/Makefile create mode 100644 arch/mips/kernel/cpufreq/loongson2_clock.c create mode 100644 arch/mips/kernel/cpufreq/loongson2_cpufreq.c create mode 100644 arch/mips/loongson/common/cs5536/cs5536_mfgpt.c
PATCH 1/3 lemote-2f: add cs5536 MFGPT timer support
When we want to enable CPUFreq support for loongson2f, it need an external timer, this patch add it.
'Cause the frequency of the MIPS Timer is half of the cpu frequency, if we use it with Cpufreq support, the sytem time will become not accuracy.
And we export the mfgpt0 counter disable/enable operations for the coming suspend support to suspend/resume the timer.
--- .../asm/mach-loongson/cs5536/cs5536_mfgpt.h | 35 +++ arch/mips/loongson/Kconfig | 11 + arch/mips/loongson/common/cs5536/Makefile | 5 + arch/mips/loongson/common/cs5536/cs5536_mfgpt.c | 217 ++++++++++++++++++++ arch/mips/loongson/common/time.c | 3 + 5 files changed, 271 insertions(+), 0 deletions(-) create mode 100644 arch/mips/include/asm/mach-loongson/cs5536/cs5536_mfgpt.h create mode 100644 arch/mips/loongson/common/cs5536/cs5536_mfgpt.c
arch/mips/include/asm/mach-loongson/cs5536/cs5536_mfgpt.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* cs5536 mfgpt header file +*/ + +#ifndef _CS5536_MFGPT_H +#define _CS5536_MFGPT_H + +#include <cs5536/cs5536.h> +#include <cs5536/cs5536_pci.h> + +#ifdef CONFIG_CS5536_MFGPT +extern void setup_mfgpt0_timer (void ); +extern void disable_mfgpt0_counter (void ); +extern void enable_mfgpt0_counter (void ); +#else +static inline void __maybe_unused setup_mfgpt0_timer (void ) +{ +} +static inline void __maybe_unused disable_mfgpt0_counter (void ) +{ +} +static inline void __maybe_unused enable_mfgpt0_counter (void ) +{ +} +#endif + +#define MFGPT_TICK_RATE 14318000 +#define COMPARE ((MFGPT_TICK_RATE + HZ/2) / HZ) + +#define MFGPT_BASE mfgpt_base +#define MFGPT0_CMP2 (MFGPT_BASE + 2) +#define MFGPT0_CNT (MFGPT_BASE + 4) +#define MFGPT0_SETUP (MFGPT_BASE + 6) + +#endif /*!_CS5536_MFGPT_H */
arch/mips/loongson/Kconfig +11 -0
@@ -62,6 +62,17 @@ endchoice config CS5536 bool +config CS5536_MFGPT + bool "CS5536 MFGPT Timer" + depends on CS5536 + help + This option enables the mfgpt0 timer of AMD CS5536. + + If you want to enable the Loongson2 CPUFreq Driver, Please enable + this option at first, otherwise, You will get wrong system time. + + If unsure, say Yes. + config LOONGSON_SUSPEND bool default y
arch/mips/loongson/common/cs5536/Makefile +5 -0
@@ -5,4 +5,9 @@ obj-$(CONFIG_CS5536) += cs5536_pci.o cs5536_ide.o cs5536_acc.o cs5536_ohci.o \ cs5536_isa.o cs5536_ehci.o +# +# Enable cs5536 mfgpt Timer +# +obj-$(CONFIG_CS5536_MFGPT) += cs5536_mfgpt.o + EXTRA_CFLAGS += -Werror
arch/mips/loongson/common/cs5536/cs5536_mfgpt.c new file +217 -0
217 lines not on this page · raw message
arch/mips/loongson/common/time.c +3 -0
@@ -14,11 +14,14 @@#include <asm/time.h> #include <loongson.h> +#include <cs5536/cs5536_mfgpt.h> void __init plat_time_init (void ) {/* setup mips r4k timer */ mips_hpt_frequency = cpu_clock_freq /2 ; + +setup_mfgpt0_timer (); }void read_persistent_clock (struct timespec *ts)
Signature · 1 line
1.6.2.1
PATCH 2/3 MIPS: add basic options for CPUFreq support
This patch adds basic options for MIPS CPUFreq support.
Since MIPS Timer's frequency is relative to the processor's frequency, So, MIPS CPUFreq support not only need the processor's CPUFreq support but also need an external timer. otherwise, we will make the system time "mussy".
--- arch/mips/Kconfig | 3 +++ arch/mips/kernel/cpufreq/Kconfig | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-) create mode 100644 arch/mips/kernel/cpufreq/Kconfig
arch/mips/Kconfig +3 -0
@@ -2146,6 +2146,7 @@ config MMU config I8253 bool + select MIPS_EXTERNAL_TIMER config ZONE_DMA32 bool
@@ -2222,6 +2223,8 @@ source "kernel/power/Kconfig" endmenu +source "arch/mips/kernel/cpufreq/Kconfig" + source "net/Kconfig" source "drivers/Kconfig"
arch/mips/kernel/cpufreq/Kconfig new file +27 -0
@@ -0,0 +1,27 @@ +# +# CPU Frequency scaling +# + +config MIPS_EXTERNAL_TIMER + bool + +config MIPS_CPUFREQ + bool + default y + depends on CPU_SUPPORTS_CPUFREQ && MIPS_EXTERNAL_TIMER + +if MIPS_CPUFREQ + +menu "CPU Frequency scaling" + +source "drivers/cpufreq/Kconfig" + +if CPU_FREQ + +comment "CPUFreq processor drivers" + +endif # CPU_FREQ + +endmenu + +endif # MIPS_CPUFREQ
Signature · 1 line
1.6.2.1
PATCH 3/3 2f: add CPUFreq support
Loongson2f add a new capability to dynamicly scale cpu frequency. And when we put it into wait mode via setting the frequency as ZERO, it will wait there until an external interrupt take place, which will help saving power for us.
And as the last patch described, to enable this support, an external timer is needed to avoid getting wrong system time when using the MIPS Timer, 'Cause the MIPS Timer's frequency is half of the cpu frequency, when the cpu frequency is changed, the MIPS Timer will be not accuracy.
This version incorporates the feedback from "Dominik Brodowski <[email protected]>" to register transition notifier before register_driver().
--- arch/mips/include/asm/clock.h | 64 ++++++++ arch/mips/include/asm/mach-loongson/loongson.h | 6 +- arch/mips/kernel/Makefile | 2 + arch/mips/kernel/cpu-probe.c | 2 + arch/mips/kernel/cpufreq/Kconfig | 14 ++ arch/mips/kernel/cpufreq/Makefile | 5 + arch/mips/kernel/cpufreq/loongson2_clock.c | 166 +++++++++++++++++++ arch/mips/kernel/cpufreq/loongson2_cpufreq.c | 202 ++++++++++++++++++++++++ arch/mips/loongson/Kconfig | 5 +- arch/mips/loongson/common/env.c | 3 + 10 files changed, 466 insertions(+), 3 deletions(-) create mode 100644 arch/mips/include/asm/clock.h create mode 100644 arch/mips/kernel/cpufreq/Makefile create mode 100644 arch/mips/kernel/cpufreq/loongson2_clock.c create mode 100644 arch/mips/kernel/cpufreq/loongson2_cpufreq.c
arch/mips/include/asm/clock.h new file +64 -0
@@ -0,0 +1,64 @@ +#ifndef __ASM_MIPS_CLOCK_H +#define __ASM_MIPS_CLOCK_H + +#include <linux/kref.h> +#include <linux/list.h> +#include <linux/seq_file.h> +#include <linux/clk.h> + +extern void (*cpu_wait) (void ); + +struct clk ; + +struct clk_ops { +void (*init) (struct clk *clk); +void (*enable) (struct clk *clk); +void (*disable) (struct clk *clk); +void (*recalc) (struct clk *clk); +int (*set_rate) (struct clk *clk,unsigned long rate,int algo_id); +long (*round_rate) (struct clk *clk,unsigned long rate); +}; + +struct clk { +struct list_head node; +const char *name; +int id; +struct module *owner; + +struct clk *parent; +struct clk_ops *ops; + +struct kref kref; + +unsigned long rate; +unsigned long flags; +}; + +#define CLK_ALWAYS_ENABLED (1 << 0) +#define CLK_RATE_PROPAGATES (1 << 1) + +/* Should be defined by processor-specific code */ +void arch_init_clk_ops (struct clk_ops **,int type); + +int clk_init (void ); + +int __clk_enable (struct clk *); +void __clk_disable (struct clk *); + +void clk_recalc_rate (struct clk *); + +int clk_register (struct clk *); +void clk_unregister (struct clk *); + +/* the exported API, in addition to clk_set_rate */ +/** +* clk_set_rate_ex - set the clock rate for a clock source, with additional parameter +* @clk: clock source +* @rate: desired clock rate in Hz +* @algo_id: algorithm id to be passed down to ops->set_rate +* +* Returns success (0) or negative errno. +*/ +int clk_set_rate_ex (struct clk *clk,unsigned long rate,int algo_id); + +#endif /* __ASM_MIPS_CLOCK_H */
arch/mips/include/asm/mach-loongson/loongson.h +5 -1
@@ -226,8 +226,12 @@ extern void mach_irq_dispatch(unsigned int pending);#define LOONGSON_PCIMAP_WIN (WIN ,ADDR ) \ ((((ADDR)>>26) & LOONGSON_PCIMAP_PCIMAP_LO0) << ((WIN)*6)) -/* Chip Config */ #ifdef CONFIG_CPU_SUPPORTS_CPUFREQ +#include <linux/cpufreq.h> +extern void loongson2_cpu_wait (void ); +extern struct cpufreq_frequency_table loongson2_clockmod_table[]; + +/* Chip Config */ #define LOONGSON_CHIPCFG0 LOONGSON_REG(LOONGSON_REGBASE + 0x80)#endif
arch/mips/kernel/Makefile +2 -0
@@ -91,6 +91,8 @@ CFLAGS_cpu-bugs64.o = $(shell if $(CC) $(KBUILD_CFLAGS) -Wa,-mdaddi -c -o /dev/n obj-$(CONFIG_HAVE_STD_PC_SERIAL_PORT) += 8250-platform.o +obj-$(CONFIG_MIPS_CPUFREQ) += cpufreq/ + EXTRA_CFLAGS += -Werror CPPFLAGS_vmlinux.lds := $(KBUILD_CFLAGS)
arch/mips/kernel/cpu-probe.c +2 -0
@@ -16,6 +16,7 @@#include <linux/ptrace.h> #include <linux/smp.h> #include <linux/stddef.h> +#include <linux/module.h> #include <asm/bugs.h> #include <asm/cpu.h>
@@ -32,6 +33,7 @@* the CPU very much. */ void (*cpu_wait)(void ); +EXPORT_SYMBOL (cpu_wait);static void r3081_wait (void ) {
arch/mips/kernel/cpufreq/Kconfig +14 -0
@@ -20,6 +20,20 @@ if CPU_FREQ comment "CPUFreq processor drivers" +config LOONGSON2_CPUFREQ + tristate "Loongson2 CPUFreq Driver" + select CPU_FREQ_TABLE + depends on MIPS_CPUFREQ + help + This option adds a CPUFreq driver for loongson processors which + support software configurable cpu frequency. + + Loongson2F and it's successors support this feature. + + For details, take a look at <file:Documentation/cpu-freq/>. + + If in doubt, say N. + endif # CPU_FREQ endmenu
arch/mips/kernel/cpufreq/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for the Linux/MIPS cpufreq. +# + +obj-$(CONFIG_LOONGSON2_CPUFREQ) += loongson2_cpufreq.o loongson2_clock.o
arch/mips/kernel/cpufreq/loongson2_clock.c new file +166 -0
166 lines not on this page · raw message
arch/mips/kernel/cpufreq/loongson2_cpufreq.c new file +202 -0
202 lines not on this page · raw message
arch/mips/loongson/Kconfig +3 -2
@@ -34,10 +34,10 @@ config LEMOTE_MACH2F select ARCH_SPARSEMEM_ENABLE select BOARD_SCACHE select BOOT_ELF32 - select CEVT_R4K + select CEVT_R4K if ! MIPS_EXTERNAL_TIMER select CPU_HAS_WB select CS5536 - select CSRC_R4K + select CSRC_R4K if ! MIPS_EXTERNAL_TIMER select DMA_NONCOHERENT select GENERIC_HARDIRQS_NO__DO_IRQ select GENERIC_ISA_DMA_SUPPORT_BROKEN
@@ -65,6 +65,7 @@ config CS5536 config CS5536_MFGPT bool "CS5536 MFGPT Timer" depends on CS5536 + select MIPS_EXTERNAL_TIMER help This option enables the mfgpt0 timer of AMD CS5536.
arch/mips/loongson/common/env.c +3 -0
@@ -17,11 +17,14 @@* Free Software Foundation; either version 2 of the License, or (at your * option) any later version. */ +#include <linux/module.h> +#include <asm/bootinfo.h> #include <loongson.h> unsigned long bus_clock, cpu_clock_freq; +EXPORT_SYMBOL (cpu_clock_freq);unsigned long memsize, highmemsize;/* pmon passes arguments in 32bit pointers */
Signature · 1 line
1.6.2.1
Re: [PATCH v1 3/3] [loongson] 2f: add CPUFreq support
Quoted 7 lines · Wu Zhangjin
Subject: [PATCH v1 3/3] [loongson] 2f: add CPUFreq support
Loongson2f add a new capability to dynamicly scale cpu frequency. And when we put it into wait mode via setting the frequency as ZERO, it will wait there until an external interrupt take place, which will help saving power for us.
Quoted 8 lines
And as the last patch described, to enable this support, an external timer is needed to avoid getting wrong system time when using the MIPS Timer, 'Cause the MIPS Timer's frequency is half of the cpu frequency, when the cpu frequency is changed, the MIPS Timer will be not accuracy.
This version incorporates the feedback from "Dominik Brodowski <[email protected]>" to register transition notifier before
register_driver().
Thanks, queue for 2.6.33.
Ralf
Re: [PATCH v1 2/3] MIPS: add basic options for CPUFreq support
In reply to Wu ZhangjinQuoted 8 lines · Wu Zhangjin
Subject: [PATCH v1 2/3] MIPS: add basic options for CPUFreq support
This patch adds basic options for MIPS CPUFreq support.
Since MIPS Timer's frequency is relative to the processor's frequency, So, MIPS CPUFreq support not only need the processor's CPUFreq support but also need an external timer. otherwise, we will make the system time "mussy".
Thanks, queue for 2.6.33.
Ralf
Re: [PATCH v1 1/3] [loongson] lemote-2f: add cs5536 MFGPT timer support
In reply to Wu ZhangjinQuoted 10 lines · Wu Zhangjin
Subject: [PATCH v1 1/3] [loongson] lemote-2f: add cs5536 MFGPT timer support
When we want to enable CPUFreq support for loongson2f, it need an external timer, this patch add it.
'Cause the frequency of the MIPS Timer is half of the cpu frequency, if we use it with Cpufreq support, the sytem time will become not accuracy.
And we export the mfgpt0 counter disable/enable operations for the coming suspend support to suspend/resume the timer.
Thanks, queue for 2.6.33.
Ralf